Git Product home page Git Product logo

tommertom / svelte-ionic-app Goto Github PK

View Code? Open in Web Editor NEW
717.0 18.0 60.0 33.85 MB

Ionic UI showcase app - try Ionic UI and directly go to API or source code (Svelte, Angular, Vue, Vanilla and React)

Home Page: https://ionic-svelte.firebaseapp.com

License: MIT License

JavaScript 28.39% TypeScript 7.38% HTML 0.28% Svelte 61.41% CSS 2.53% Batchfile 0.01%
angular vue ionic ionic-framework svelte sveltekit vite pwa vanilla-js

svelte-ionic-app's Introduction

Ionic SvelteKit


IonicSvelte


A library to include Ionic in your Svelte and SvelteKit app


Download as PWA

Click the PWA Launch button to see this app live in action - and install as PWA on your desktop or mobile!

All Contributors PRs Welcome MIT license Forks Forks Forks

NPM library to go along with the Ionic Svelte integration demonstrated at https://ionic-svelte.firebaseapp.com.

How to get started - npm create ionic-svelte-app@latest

On the CLI just type npm create ionic-svelte-app@latest to spin a SvelteKit project from the CLI. This will do all the lifting for you to create a SvelteKit SPA app.

Show me Ionic!

A showcase app for all Ionic UI elements, Supercharged by SvelteKit can be found at https://ionic-svelte.firebaseapp.com. This also has a handy tool to show the source code for Svelte - and even Angular, VanillaJS, Vue, React and stencil!

And the code on how to use the components - repo at https://github.com/Tommertom/svelte-ionic-app/tree/main/demo-app

How to get started - manual import of ionic-svelte library

Start a new SvelteKit project (or Svelte with Vite, even though I prefer Kit). Skip this part if you already have a project

npm create svelte@latest my-app
cd my-app
npm install

We need adapter static + ssr=false, because Ionic package cannot run in SSR=true.

I am chosing to deploy via adapter-static (to Firebase hosting), but if you deploy to Cloudflare, Vercel or Netflify you can opt to do differently. I checked with Vercel and that works still very well.

adapter: adapter({
			pages: 'build',
			assets: 'build',
			fallback: 'index.html',
			precompress: false
		})
  • Pages that use Ionic need to have ssr disabled in their layout files (if not earlier present in parent layout). Kit example: src/routes/+layout.ts and add export const ssr = false;

Integration of Ionic

<script lang="ts">
	import { setupIonicBase } from 'ionic-svelte';

	/* Theme variables */
	import '../theme/variables.css';

	/* load and register all components - you can also import separately to code split */
    import 'ionic-svelte/components/all';

	/* run base configuration code from ionic/core */
	setupIonicBase();
</script>

<ion-app>
   <slot />
</ion-app>

And then start working on the content of the app in +page.svelte:

	Hi there <ion-button>test</ion-button>

If you get a 500 internal error-error then likely SSR is not disabled. Making a SvelteKit app a real SPA really requires two steps - adapter static and ssr=false

Starterfiles on github: https://github.com/Tommertom/svelte-ionic-app/tree/main/starterfiles Use these files as reference to see how to do the final steps integrating Ionic in your svelte project.

Code for this library - https://github.com/Tommertom/svelte-ionic-app

Ionic-svelte on NPMjs- https://www.npmjs.com/package/ionic-svelte

Code Splitting to reduce bundle size

In order to reduce bundle size or limit the size of individual chunks, you can replace the import in main layout file. Example: if you replace the line import 'ionic-svelte/components/all'; with imports like below. This can reduce the bundle for that chunk drastically. The import of all will result to at least an 800kb chunk (80 components), so it is worth it to change this.

Next you can choose to load specific components only where you use them.

Please note, you only need to import a component only once, as the import registers the webcomponent globally. So this saves you lots of imports, reducing the bundle as well (compared to tree-shaking).

And never forget to at least import 'ionic-svelte/components/ion-app'; - as this one is in the main layout.

	import 'ionic-svelte/components/ion-app';
	import 'ionic-svelte/components/ion-card';
	import 'ionic-svelte/components/ion-card-title';
	import 'ionic-svelte/components/ion-card-subtitle';
	import 'ionic-svelte/components/ion-card-header';
	import 'ionic-svelte/components/ion-card-content';
	import 'ionic-svelte/components/ion-chip';
	import 'ionic-svelte/components/ion-button';

How to use components

Ionic components are webcomponents, so appear in your template just like other dom elements. They don't need ECMA imports like import {IonCard} from '....

<ion-card>
Here content
</ion-card>

So you can also apply css classes to them, also when wanting to tweak UI via the shadow dom/web-parts.

Special components

Due to router issues and overlays, there are three special compontents included that override/replace the ionic standard webcomponents:

  • IonTabs - fixing some default selected tabs as well as fixing compatibility with the router
  • IonPage - wrapping the page and providing the ion-lifecycle hooks. And implementing a basic animation
  • IonNav - supporting IonNav

To be imported from the package: import { IonTab } from 'ionic-svelte'; etc..

See HOWTOs on how to implement tabs and nav. For Page - just check https://ionic-svelte.firebaseapp.com/

https://github.com/Tommertom/ionic-svelte-tabs-howto

https://github.com/Tommertom/ionic-svelte-nav-howto

Typesafety and type-ahead support

The package provides typings for all webcomponents. These can be included in your IDE by adding the following to your the compilerOptions section in tsconfig.json:

		"typeRoots": [
			"./node_modules/ionic-svelte"
		],
		"types": [
			"ionic-svelte"
		]

Sample tsconfig.json:

{
	"extends": "./.svelte-kit/tsconfig.json",
	"compilerOptions": {
		"allowJs": true,
		"checkJs": true,
		"esModuleInterop": true,
		"forceConsistentCasingInFileNames": true,
		"resolveJsonModule": true,
		"skipLibCheck": true,
		"sourceMap": true,
		"strict": true,
		"typeRoots": [
			"./node_modules/ionic-svelte"
		],
		"types": [
			"ionic-svelte"
		]
	}
}

How to contribute?

Would you like to contribute to this project? Great!

First and foremost - share you feedback!!!!!

And if you want to do more - what is there to do:

  • EASY - fix typos (also great for your Github online profile - there are many), add examples for components
  • MEDIUM - fix some minor bugs ( e.g. SvelteSpring), improve layout of pages (e.g. SvelteTransition)
  • HARD - look at the open issues below

When you do a PR, make sure you explain what you did and why!

Issues - help needed/workaround provided

  • Ion Back Button - requires default-href to show in toolbar (page transitions need to add can-go-back class)

  • IonTabs needs to manually call the select method of ion-tabs to ensure the selectedTab prop is really acted upon. Issue known: ionic-team/ionic-framework#20060. Gives a brief undesireable view on the wrong tab. Might need to look into the angular/react/vue way as these packages don't have this issue. Probably tabs is wired up in the router.

  • Gestures: Need a timeout to get proper style value even though I am using onMount??

  • Ion Footer in Modal looks not ok - need to test in inline modal as well.

  • bind:value does not seem to work on input and other form elements, so a click handler is needed - which is cumbersome - sveltejs/svelte#892 - so probably not solvable without support by Ionic or Svelte - or we need to create wrappers for all elements - which is quite some work and you will be required to manually import all elements you use per page (like with Vue and React) - which seems a drag to me?

SvelteKit form actions make the usage of bind:value even obsolete. So that is the go-to way route anyway - https://kit.svelte.dev/docs/form-actions

Please note - if you use a library such as https://svelte-forms-lib-sapper-docs.vercel.app/introduction together with Yup schemas https://github.com/jquense/yup, the bind:value-issue actually becomes less relevant as you will have the library handle the events and you will use the observables to manage validation and final values to use for further processing. See https://blog.logrocket.com/form-validation-in-svelte/ for nice examples.

  • Some styles are reported as unused - related to md and ios options for webcomponents? Or need to be discarded. Probably issue with webcomponents and the nature of Ionic being sensitive to md or ios style (as part of its config). Or the way Svelte/vite checks for unused css.

  • Add IonPage, IonTabs and IonBackButton are not part of the default export - these are svelte components, so index.ts cannot handle these (?)

  • Ion Icons implementation only uses icon-property syntax. Name/md/ios will not function

  • In some cases IonPage clips the content enclosed - then you need to remove main tags in IonPage

  • Routerlink, href and similar props on components like ion-item do not work properly, but I wonder if support is needed

  • Menucontroller does not see the menu by default - you need to register the menu item manually - extra function added to help you with that (registerMenu(menu-id:string)) - <ion-menu {side} content-id="main" menu-id="mainmenu">see Menu.svelte with working example

  • Nav component - works nicely, but implementation might be dirty (leaking DOM elements?). ion-nav-link not implemented.

  • ItemSliding sometimes does not catch the gesture - known issue - needs fix in @ionic/core

  • Many "File not found errors" on css.map files in the demo app. I frankly don't really mind these. Maybe it is easy to get rid of these, but for now, I leave it.

Check https://github.com/Tommertom/svelte-ionic-app/issues for most recent overview of issues.

Things not being implemented

ion-router-link, ion-router,ion-route, ion-route-redirect and ion-router-outlet - these are imho obsolete because of usage of the router in this project. But tell me if I am wrong here!

ion-nav-link - not sure why not, but haven't used it yet in a project. Maybe my bad. What do you think?

Star History

Star History Chart

Acknowledgements

Logo by Brett Peary: https://brettpeary.com/

Ionic UI code: https://github.com/ionic-team/ionic-docs/tree/main/static/demos/api

README inspiration: https://github.com/gitpoint/git-point/blob/master/README.md

PWA logo: https://github.com/webmaxru/progressive-web-apps-logo

Borat logo: https://sapper.svelte.dev/

Raymondboswel's repo: https://github.com/raymondboswel/ionic-svelte-example

svelte-ionic-app's People

Contributors

androothechen avatar b-d-m-p avatar briznad avatar dependabot[bot] avatar dysfunc avatar irshad avatar jakobrosenberg avatar mibzman avatar mramericanmike avatar samal-rasmussen avatar shiv19 avatar theonlytails avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

svelte-ionic-app's Issues

svelte-custom-elements

@Tommertom with this module deprecated, what is the alternative implementation that doesn't use svelte-custom-elements in the services/IonicController.js file. Also will this be updated for Ionic 5. I am interested in using this for mobile app

How to build for mobile native platforms?

I tried to build a "Hello World" app for Android, but the Ionic CLI is telling me I need a custom build script.

Is there an example or some boilerplate to work with here? I haven't been able to find anything.

What is the process required to build this app for mobile native platforms such as Android and iOS?

Thanks

Errors running menu demo

When running the menu demo I get the following error:

The requested module '/src/lib/ionic/svelte/index.ts' does not provide an export named 'getIonicMenu'

Other demos work as expected :D

Ionic 7

What's the status of migrating to Ionic 7? Is there any valid reason to do this now?

Error when following setup instructions: Unexpected token 'export'

When setting up the project as described in the repo, I followed the instructions several times to make sure I didn't mess anything up. Running Xubuntu 22.04.1 LTS.

(node:1660088) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
Unexpected token 'export'
/home/user/code/ionic/sveltekit-ionic-3/node_modules/@ionic/core/components/index.js:4
export { setAssetPath, setPlatformOptions } from '@stencil/core/internal/client';
^^^^^^

SyntaxError: Unexpected token 'export'
    at Object.compileFunction (node:vm:360:18)
    at wrapSafe (node:internal/modules/cjs/loader:1088:15)
    at Module._compile (node:internal/modules/cjs/loader:1123:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
Unexpected token 'export'
/home/ser/code/ionic/sveltekit-ionic-3/node_modules/@ionic/core/components/index.js:4
export { setAssetPath, setPlatformOptions } from '@stencil/core/internal/client';
^^^^^^

SyntaxError: Unexpected token 'export'
    at Object.compileFunction (node:vm:360:18)
    at wrapSafe (node:internal/modules/cjs/loader:1088:15)
    at Module._compile (node:internal/modules/cjs/loader:1123:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:530:24)

Cloning your repo, then doing npm i and npm run dev works just fine.

The minorest of issues: Wrong cursor

On desktop it doesn't give me the hand-cursor (๐Ÿ‘†) when hovering over the menu items on the left but the "select text"-one (I) instead. An unforgivable mistake, but other than that great project!

Dark Mode?

The standard Ionic apps can toggle between light and dark mode. Is there any way to enable that functionality here?

Errors while trying to run npm run dev

I'm trying to run npm run dev but I'm getting errors unfortunately.

First I get a runtime error in the browser console saying: localhost/:1 Uncaught TypeError: Failed to resolve module specifier "@sveltech/routify/tmp/routes"

In package.json I can see that @sveltech/routify is set to version "next", which npmjs.com says is version 1.1.1-1. That is a rather old version, so I tried updating it and that fixed it. Both 1.8.0 and .1.9.1 worked.

But the I get a new error (hooray?): localhost/:1 Uncaught (in promise) TypeError: Failed to resolve module specifier "@ionic/core".

I've tried fixing this by installing @ionic/core via npm. npm install --save --save-exact @ionic/[email protected]

Doing so gets me this error, which has me stumped:

index.mjs:41 Uncaught (in promise) TypeError: Cannot read property 'subscribe' of undefined
    at subscribe (index.mjs:41)
    at get_store_value (index.mjs:46)
    at onComponentLoaded (Route.svelte:72)

Error when starting a new project with `ionic-svelte-app@latest`

When using the new installer, I have been given the following error:

Need to install the following packages:
  [email protected]
Ok to proceed? (y) y

create-ionic-svelte-app version 0.0.6

Welcome to Ionic Svelte 

This is BETA software; expect bugs and missing features.

Problems? Open an issue on https://github.com/Tommertom/svelte-ionic-npm/issues if none exists already.

โœ” Name for your new project: โ€ฆ ionic-svelte-hello
โœ” Add type checking with TypeScript? โ€บ Yes, using TypeScript syntax
โœ” Add ESLint for code linting? โ€ฆ No / Yes (NOTE: I picked 'Yes')
โœ” Add Prettier for code formatting? โ€ฆ No / Yes (NOTE: I picked 'Yes') 
โœ” Add Playwright for browser testing? โ€ฆ No / Yes (NOTE: I picked 'Yes')
โœ” Add Vitest for unit testing? โ€ฆ No / Yes (NOTE: I picked 'Yes')
โœ” Add Ionicons? โ€ฆ No / Yes (NOTE: I picked 'Yes')
Working: Creating base Svelte Kit install supercharged with Ionic.
Working: Installing project dependencies svelte-preprocess,@sveltejs/adapter-static
An error has occurred trying to install packages with your package manager, please send us the following text onto our Github or Discord:
 npm WARN deprecated [email protected]: Please use @jridgewell/sourcemap-codec instead

EDIT: I added the NOTE: sections to indicate my choices.

EDIT 2: The error also occurs when selecting No to all the choices.

EDIT 3: More info that may be helpful: Running fully-updated Ubuntu Linux 22.04.1 LTS, using npm LTS installed via asdf

What are the advantages of routify vs. window.location.href?

I'm very new to Svelte (but loving the simplicity and speed of it so far). Can you tell me, though, what the advantages are of using routify vs. standard html routing for something like [..fallback].svelte?

<script lang="ts">
  import { goto } from "@roxi/routify";
  $goto("/");
</script>

vs.

<script lang="ts">
window.location.href="/";
</script>

Nagivation forwards animation

Awesome job; love it!

Any idea how we can get forwards navigation animations working?

Also; how do we deploy to web?

feature request: suggest naming conventions

When I create a new project, it let me name my project with dashes. Later on, this throws an Invalid App ID, forcing me to re-name.

It would be nice if Name for your new project: a name could trigger a "some-name" is an Invalid App ID due to {reason}, are you sure? yes / Different Name loop.

Easier may just be adding a hint to the Name for your new project: -> Name (alphanum and underscores) for your new project.

Below is creating a project with a dash:

~/dev โฏ npm create ionic-svelte-app@latest                                                  
Need to install the following packages:
  [email protected]
Ok to proceed? (y) y

create-ionic-svelte-app version 0.0.29

Welcome to Ionic Svelte 

This script will install a SvelteKit project using their SvelteKit create script. 
And then adds Ionic power to it - Ionic Elements, Ionicons (optional) and CapacitorJS (optiona
l)

- Ionicons - free package of icons to use in your app
- CapacitorJs - deploy you app as Android/iOS/Electron app, and use its plugin ecosystem to bu
ild cross-platform experience, also supporting PWA!

This is BETA software; expect bugs and missing features.

Problems? Open an issue on https://github.com/Tommertom/svelte-ionic-npm/issues.

โœ” Name for your new project: โ€ฆ some-name
โœ” Add type checking with TypeScript? โ€บ Yes, using TypeScript syntax
โœ” Add ESLint for code linting? โ€ฆ No / Yes
โœ” Add Prettier for code formatting? โ€ฆ No / Yes
โœ” Add Playwright for browser testing? โ€ฆ No / Yes
โœ” Add Vitest for unit testing? โ€ฆ No / Yes
โœ” Add Ionicons? โ€ฆ No / Yes
โœ” Add Capacitor for native (mobile) deployements? โ€ฆ No / Yes
Working: Creating base Svelte Kit install supercharged with Ionic.
Working: Installing project dependencies svelte-preprocess,@sveltejs/adapter-static,vite@4,@ca
pacitor/cli
Working: Adding @ionic/[email protected],ionic-svelte,@capacitor/core,ionicons
Working: Removing @sveltejs/adapter-auto
Working: Writing configs and default files

Your project is ready!
โœ” Typescript
  Inside Svelte components, use <script lang="ts">
โœ” ESLint
  https://github.com/sveltejs/eslint-plugin-svelte3
โœ” Prettier
  https://prettier.io/docs/en/options.html
  https://github.com/sveltejs/prettier-plugin-svelte#options
โœ” Playwright
  https://playwright.dev
โœ” Vitest
  https://vitest.dev
โœ” Capacitor
  https://capacitorjs.com/docs/getting-started
  Please note - the project is configured with HMR - remove server entry in capacitor.config.j
son for final build
โœ” Ionicons
  https://ionicsvelte.firebaseapp.com/components/Icon

Install community-maintained integrations:
  https://github.com/svelte-add/svelte-adders

Capacitor configuration - see: capacitor.config.json|ts
  App name some-name
  Package name some-name.ionic.io
  Vite dev server url http://192.168.137.1:5173/

Next steps:
  1: cd some-name
  2: npm i @capacitor/android and/or @capacitor/ios
  3: npx cap add android and/or ios
  4: npm run build to fill the build directory
  5: npx cap sync sync the build into the target folder
  6: npx cap open android or ios to open the project and mark as trusted
  7: npm run dev -- --open

To close the dev server, hit Ctrl-C

Use the -hmr flag after your npx cap run/open/sync commands to use HMR together with npm run d
ev

Stuck? Visit us at Ionic's discord https://discordapp.com/channels/520266681499779082/10493885
01629681675

Need some help or found an issue with this installer? Visit us on Github https://github.com/To
mmertom/svelte-ionic-npm
~/dev โฏ cd some-name 
~/dev/some-name โฏ npm i @capacitor/ios   

added 1 package, and audited 295 packages in 609ms

50 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
~/dev/some-name โฏ npx cap add ios                                                           
[error] Invalid App ID "some-name.ionic.io". Must be in Java package form with no dashes (ex:
        com.example.

Create an independent components package

Hi ๐Ÿ‘‹๐Ÿป

I would like to be able to install the different components from a single package to install, and not to copy and paste the components manually.

Would it be possible to create a specific package for the components please?

NPM failure

NPM 8.1.4

Installation died with an error, unless I did this first:

npm install -g agentkeepalive --save

The error message:

npm ERR! code ERR_SOCKET_TIMEOUT
npm ERR! network Socket timeout
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network 
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/username/.npm/_logs/2022-02-08T15_06_10_986Z-debug.log

PWA config

Good I've been trying to understand for a couple of hours, what configuration should I do with vite to have PWA.

For example to your demo example, if I wanted to have it in PWA, would I have to add code or just some configuration?
Thank you very much and great job.

edit: I think what I don't understand is how to use the service worker, because I don't see it in your code and I don't know where you are calling it.

Bug - can only use one ion-content

When having a page with ion-content and doing a modal with another ion-content, the view will be totally messed up.

So need to look into ion-content - is there something like framework overlay needed or so?

If that is the case, a custom IonContent.svelte will be needed....

swipe to go back capacitor demo - ios may not work

maybe this isn't the right repo to open an issue on, but do you have a demo of swipe to go back working in a capacitor + ionic + sveltekit mobile app? It works fine on PWA/browser but doesn't seem to work on a capacitor native app

Ionic Page transition - how to implement in router?

For page transitions Ionic has this really cool transition which is more than just a single page fly-in - what is happening now.

It looks into the various elements of the incoming component and gives them specific transitions. Like the header-title, the default back-button and the page itself. Also the outoging component gets this special treatment as a whole and for its elements.

For now I have been able to pin down this transition in their code. And here an example link to the transition in ios: https://github.com/ionic-team/ionic-framework/blob/main/core/src/utils/transition/ios.transition.ts

The function responsible for adding the transitions to the dom elements seems to be :


   const transition = (
      enteringEl: HTMLElement,
      leavingEl: HTMLElement,
      direction: any, // TODO types
      showGoBack: boolean,
      progressAnimation: boolean,
      animationBuilder?: AnimationBuilder
    ) => {

(taken from the vue implementation -and I need to check how it relates to the ios.transitions.ts)

The API requires the enteringElement and the leaving element, besides a directions. The showGoBack is related to the BackButton mostly shown top left or top right corner. animationBuilder is I believe a customer animation and the boolean I don't know, but probably not of big interest for now?

So, the question is how to hook this up in Routify. Maybe through the helpers you have? But I also think/fear/believe a more deeper connection might be needed.

Looking for help on how to achieve this.

ion-icon url

I create app with npm create svelte@latest my-app and installed via npm.
All other components working but icons not working. Getting the fallowing error in console:
Uncaught TypeError: Failed to construct 'URL': Invalid base URL

Ionic 5 upgrade

Ionic 5 is out, creating some breaking changes in the API for controllers as well as ionicons.

Replace goto with redirect throw

Replace goto's with

// src/routes/+page.ts
import type { PageLoad } from "./$types";
import { redirect } from "@sveltejs/kit";

export const load = (() => {
  throw redirect(301, "/components/Slides");
}) satisfies PageLoad;

As this navigates faster

Usage without SvelteKit is currently broken (feature request)

Hey, first of all thanks for your wonderful project!

I've tried setting it up with Routify instead of SvelteKit and found out that ionic-svelte/components/IonTabs.svelte depends on SvelteKit's $app/stores and $app/navigation implementation. This wouldn't be a problem but the main ionic-svelte/index.ts module imports it, which causes Vite to fail bundling it:

[plugin:vite:import-analysis] Failed to resolve import "$app/stores" from "node_modules/.pnpm/[email protected]/node_modules/ionic-svelte/components/IonTabs.svelte?v=331c4727". Does the file exist?

The workaround I've arrived at is to add a shim:

  1. In vite.config.js, set resolve.alias.$app to path.resolve(__dirname, "src", "lib", "sveltekit-shim")

  2. In src/lib/sveltekit-shim, add following files:

    // navigation.ts
    export function goto(): never {
      throw new Error("Not implemented");
    }
    // stores.ts
    export const page = {
      subscribe: () => {
        throw new Error("not implemented");
      },
    };

(I've tried reimplemening a subset of SvelteKit's API, but seeing that legacy tabs implementation is available that's not really necessary)

Perhaps a better solution would be to just remove the IonTabs import from index.ts altogether, and update docs to guide to import it like:

import { IonTabs } from "ionic-svelte/components/IonTabs.svelte";

Add bind:value to ion-input

Adding the bind:input property to <ion-input> would dramatically simplify the code. Where should I look to try to create a PR for this?

"ion-item-sliding" not working

The <ion-item-sliding> Ionic element does not work. Items are displayed statically, but do not react to sliding gestures, making them effectively static list items. No errors are thrown and it does not prevent the app from compiling.

Bug: Showing modal via modalController breaks in Ionic 7

Strangely the popover via controller does work.

And the code in ionic-svelte should be somehow the same.... need to inspect the Ionic7 code for this.

So adding a warning that you should be using inline modal - which is preferred anyway, in order to support styling.

What about "clearOnEdit" for password inputs ?

Hey. Im reed the docs of ionic about ion-input and find some interesting unexpected behaviors for this type of components. input of type "password" being cleared every time after focus loose by default. this behavior in ionic-svelte has the same point. I was try use "clearOnEdit=false" and other variations, but without success. Did you have any idea or i miss something ?

Issues in NPM package - link to old repo

https://github.com/Tommertom/svelte-ionic-npm/issues

9 known issues with the ionic-svelte integration:

  • how to import without typescript
  • ion-nav-link component
  • ion-back-button needs explicit href to show
  • ion-nav multiple push does not work
  • ion-footer on modal does not look pretty (with controller)
  • real ionic transitions on ionpage
  • bind:value does not work - (svelte & custom component issue)
  • item-sliding does not slide (ionic/core solution needed)
  • no ionViewWillLeave in IonPage (needed svelte hook not exposed for library authors)

Navigation

The state of navigation in this project seems a bit unclear at the moment:

On one hand, there's SvelteKit's routing, however, this doesn't give you a native-like experience with stacks, transitions, and gestures. It looks like the answer to that is IonPage, but all it currently does is a rudimentary swipe animation that doesn't even work on the way out.

And then there's IonNav/navController, which seems to be more connected with Ionic, but decouples routes from SvelteKit.

How can one achieve smooth native-like transitions and history, especially when working with stacked drawers and tab views?

`vite build` fails with error

When I run vite build the build fails with the following error:

[vite-plugin-pwa:build] Missing "./preload-helper" export in "vite" package
error during build:
Error: Missing "./preload-helper" export in "vite" package

Live reload requires ctrl-F5?

After code changes, I need to hit ctrl-f5 to reload, as Chrome gives an error (GET http://localhost:5000/bundle/main.js net::ERR_ABORTED 404 (Not Found)) on automatic live-reload

SuperForms support - typescript issue with constraints

Superforms works nicely. Just if you want to spread the constraints, the typescript will throw a fit...

And you need to use your own change handler to change the value, as bind:value does not work with webcomponents in Svelte.

(below code is Ionic 6 and does not handle the styling for error/helper in ion-input....so incomplete)

<script lang="ts">
	import { z } from 'zod';

	import { superForm } from 'sveltekit-superforms/client';
	import SuperDebug from 'sveltekit-superforms/client/SuperDebug.svelte';

	const schema = z.object({
		id: z.number().int().positive().default(Date.now()),
		name: z.string().min(2).default('Hello world!'),
		email: z.string().email()
	});

	const data = {
		id: Date.now(),
		name: 'x',
		email: '[email protected]'
	};

	const { form, errors, message, constraints, enhance, delayed } = superForm(data, {
		SPA: true,
		validators: schema,
		onUpdate: ({ form, cancel }) => {
			console.log('onUpdate', form, cancel);
		},
		onError({ result, message }) {
			console.log('onError', result, message);
			message.set(result.error.message);
		}
	});

	function handleChange(ev) {
		console.log('.');
		$form.name = ev.detail.value;

		// $form.name = 'x' + Date.now();
	}
</script>

<ion-card>
	<ion-card-header>
		<ion-card-subtitle>Great success!!</ion-card-subtitle>
		<ion-card-title>Welcome to your app!</ion-card-title>
	</ion-card-header>

	<ion-card-content>
		Thank you for using this starter. Click buttons below to open these guides (will open in new
		window). Don't forget to open DevTools to see this app in mobile mode. Happy coding!!!

		<SuperDebug data={$form} />

		{#if $message}<h3>{$message}</h3>{/if}
		{$errors.name}
	</ion-card-content>
	<form method="POST" use:enhance>
		<input type="hidden" name="id" bind:value={$form.id} />
		<ion-item>
			<ion-label position="stacked"> Name </ion-label>
			<ion-input
				name="name"
				type="text"
				value={$form.name}
				on:ionInput={handleChange}
				data-invalid={$errors.name} />
			<ion-note slot="helper">
				Here you may enter your first name - or something else
				{#if $errors.name}
					<span class="invalid">{$errors.name}</span>
				{/if}
			</ion-note>
			<ion-note slot="error">Please type more characters...</ion-note>
		</ion-item>
		<ion-item>
			<ion-label position="stacked">
				Email
				<ion-text color="danger">*</ion-text>
			</ion-label>
			<ion-input name="name" type="email" value={$form.email} />
			<ion-note slot="helper">Here you may enter your first name - or something else</ion-note>
			<ion-note slot="error">Please type more characters...</ion-note>
		</ion-item>
		<button>Submit</button>
	</form>
</ion-card>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.