@inertiajs/svelte 1.3.0-beta.1 → 1.3.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,14 +2,13 @@
2
2
  import store, {} from "../store";
3
3
  $: props = resolveProps($store);
4
4
  function resolveProps({ component, page, key = null }) {
5
- if (!component?.default || !page) return null;
6
5
  const child = h(component.default, page.props, [], key);
7
6
  const layout = component.layout;
8
7
  return layout ? resolveLayout(layout, child, page.props, key) : child;
9
8
  }
10
9
  function resolveLayout(layout, child, pageProps, key) {
11
10
  if (Array.isArray(layout)) {
12
- return layout.concat(child).reverse().reduce((child2, layout2) => h(layout2, pageProps, [child2], key));
11
+ return layout.slice().reverse().reduce((currentRender, layoutComponent) => h(layoutComponent, pageProps, [currentRender], key), child);
13
12
  }
14
13
  return h(layout, pageProps, child ? [child] : [], key);
15
14
  }
@@ -1,5 +1,4 @@
1
- <script>import { beforeUpdate } from "svelte";
2
- import { inertia } from "../index";
1
+ <script>import { inertia } from "../index";
3
2
  export let href;
4
3
  export let as = "a";
5
4
  export let data = {};
@@ -11,17 +10,11 @@ export let only = [];
11
10
  export let except = [];
12
11
  export let headers = {};
13
12
  export let queryStringArrayFormat = "brackets";
14
- beforeUpdate(() => {
15
- if (as === "a" && method.toLowerCase() !== "get") {
16
- console.warn(
17
- `Creating POST/PUT/PATCH/DELETE <a> links is discouraged as it causes "Open Link in New Tab/Window" accessibility issues.
18
-
19
- Please specify a more appropriate element using the "as" attribute. For example:
20
-
21
- <Link href="${href}" method="${method}" as="button">...</Link>`
22
- );
23
- }
24
- });
13
+ $: asProp = method !== "get" ? "button" : as.toLowerCase();
14
+ $: elProps = {
15
+ a: { href },
16
+ button: { type: "button" }
17
+ }[asProp] || {};
25
18
  </script>
26
19
 
27
20
  <!-- svelte-ignore a11y-no-static-element-interactions -->
@@ -39,8 +32,8 @@ Please specify a more appropriate element using the "as" attribute. For example:
39
32
  headers,
40
33
  queryStringArrayFormat,
41
34
  }}
42
- {...as === 'a' ? { href } : {}}
43
35
  {...$$restProps}
36
+ {...elProps}
44
37
  on:focus
45
38
  on:blur
46
39
  on:click
@@ -1,11 +1,11 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import type { Method, PreserveStateOption, RequestPayload } from '@inertiajs/core';
2
+ import type { FormDataConvertible, Method, PreserveStateOption } from '@inertiajs/core';
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  [x: string]: any;
6
6
  href: string;
7
7
  as?: keyof HTMLElementTagNameMap | undefined;
8
- data?: RequestPayload | undefined;
8
+ data?: Record<string, FormDataConvertible> | undefined;
9
9
  method?: Method | undefined;
10
10
  replace?: boolean | undefined;
11
11
  preserveScroll?: PreserveStateOption | undefined;
@@ -5,7 +5,7 @@ import type { ComponentResolver } from './types';
5
5
  interface CreateInertiaAppProps {
6
6
  id?: string;
7
7
  resolve: ComponentResolver;
8
- setup: (props: {
8
+ setup?: (props: {
9
9
  el: Element;
10
10
  App: ComponentType<App>;
11
11
  props: {
@@ -1,6 +1,6 @@
1
1
  import { router, setupProgress } from '@inertiajs/core';
2
2
  import escape from 'html-escape';
3
- import { VERSION } from 'svelte/compiler';
3
+ import { version as SVELTE_VERSION } from 'svelte/package.json';
4
4
  import App from './components/App.svelte';
5
5
  import store from './store';
6
6
  export default async function createInertiaApp({ id = 'app', resolve, setup, progress = {}, page, }) {
@@ -16,7 +16,7 @@ export default async function createInertiaApp({ id = 'app', resolve, setup, pro
16
16
  });
17
17
  });
18
18
  if (isServer) {
19
- const isSvelte5 = VERSION.startsWith('5');
19
+ const isSvelte5 = SVELTE_VERSION.startsWith('5');
20
20
  const { html, head, css } = await (async () => {
21
21
  if (isSvelte5) {
22
22
  const { render } = await dynamicImport('svelte/server');
package/dist/index.d.ts CHANGED
@@ -4,4 +4,5 @@ export { default as createInertiaApp } from './createInertiaApp';
4
4
  export { default as inertia } from './link';
5
5
  export { default as page } from './page';
6
6
  export { default as remember } from './remember';
7
+ export { type ResolvedComponent } from './types';
7
8
  export { default as useForm, type InertiaForm, type InertiaFormProps } from './useForm';
package/dist/index.js CHANGED
@@ -4,4 +4,5 @@ export { default as createInertiaApp } from './createInertiaApp';
4
4
  export { default as inertia } from './link';
5
5
  export { default as page } from './page';
6
6
  export { default as remember } from './remember';
7
+ export {} from './types';
7
8
  export { default as useForm } from './useForm';
package/dist/link.d.ts CHANGED
@@ -1,10 +1,20 @@
1
- import { type VisitOptions } from '@inertiajs/core';
2
- import type { Action } from 'svelte/action';
1
+ import { type FormDataConvertible, type GlobalEventsMap, type VisitOptions } from '@inertiajs/core';
2
+ import type { CancelTokenSource } from 'axios';
3
+ import type { ActionReturn } from 'svelte/action';
3
4
  interface ActionElement extends HTMLElement {
4
5
  href?: string;
5
6
  }
6
- type ActionParameters = VisitOptions & {
7
+ type ActionParameters = Omit<VisitOptions, 'data'> & {
7
8
  href?: string;
9
+ data?: Record<string, FormDataConvertible>;
8
10
  };
9
- declare const link: Action<ActionElement, ActionParameters>;
11
+ type SelectedEventKeys = 'start' | 'progress' | 'finish' | 'before' | 'cancel' | 'success' | 'error';
12
+ type SelectedGlobalEventsMap = Pick<GlobalEventsMap, SelectedEventKeys>;
13
+ type ActionAttributes = {
14
+ [K in keyof SelectedGlobalEventsMap as `on:${K}` | `on${K}`]?: (event: CustomEvent<SelectedGlobalEventsMap[K]['details']>) => void;
15
+ } & {
16
+ 'on:cancel-token'?: (event: CustomEvent<CancelTokenSource>) => void;
17
+ oncanceltoken?: (event: CustomEvent<CancelTokenSource>) => void;
18
+ };
19
+ declare function link(node: ActionElement, options?: ActionParameters): ActionReturn<ActionParameters, ActionAttributes>;
10
20
  export default link;
package/dist/link.js CHANGED
@@ -1,5 +1,5 @@
1
- import { mergeDataIntoQueryString, router, shouldIntercept } from '@inertiajs/core';
2
- const link = (node, options = {}) => {
1
+ import { mergeDataIntoQueryString, router, shouldIntercept, } from '@inertiajs/core';
2
+ function link(node, options = {}) {
3
3
  const [href, data] = hrefAndData(options);
4
4
  node.href = href;
5
5
  options.data = data;
@@ -16,8 +16,8 @@ const link = (node, options = {}) => {
16
16
  if (shouldIntercept(event)) {
17
17
  event.preventDefault();
18
18
  router.visit(node.href, {
19
- onCancelToken: () => fireEvent('cancel-token'),
20
- onBefore: (visit) => fireEvent('before', { detail: { visit } }),
19
+ onCancelToken: (token) => fireEvent('cancel-token', { detail: { token } }),
20
+ onBefore: (visit) => fireEvent('before', { cancelable: true, detail: { visit } }),
21
21
  onStart: (visit) => fireEvent('start', { detail: { visit } }),
22
22
  onProgress: (progress) => fireEvent('progress', { detail: { progress } }),
23
23
  onFinish: (visit) => fireEvent('finish', { detail: { visit } }),
@@ -39,5 +39,5 @@ const link = (node, options = {}) => {
39
39
  node.removeEventListener('click', visit);
40
40
  },
41
41
  };
42
- };
42
+ }
43
43
  export default link;
package/dist/page.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const page: import("svelte/store").Readable<import("@inertiajs/core").Page<import("@inertiajs/core").PageProps> | null>;
1
+ declare const page: import("svelte/store").Readable<import("@inertiajs/core").Page<import("@inertiajs/core").PageProps>>;
2
2
  export default page;
package/dist/store.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { Page } from '@inertiajs/core';
2
2
  import type { ResolvedComponent } from './types';
3
3
  export interface InertiaStore {
4
- component: ResolvedComponent | null;
5
- page: Page | null;
4
+ component: ResolvedComponent;
5
+ page: Page;
6
6
  key: number | null;
7
7
  }
8
8
  declare const store: import("svelte/store").Writable<InertiaStore>;
package/dist/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { ComponentType } from 'svelte';
2
2
  export type ComponentResolver = (name: string) => ResolvedComponent | Promise<ResolvedComponent>;
3
+ export type LayoutType = ComponentType | ComponentType[];
3
4
  export type ResolvedComponent = {
4
- default?: ComponentType;
5
- layout?: ComponentType;
5
+ default: ComponentType;
6
+ layout?: LayoutType;
6
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inertiajs/svelte",
3
- "version": "1.3.0-beta.1",
3
+ "version": "1.3.0-beta.2",
4
4
  "license": "MIT",
5
5
  "description": "The Svelte adapter for Inertia.js",
6
6
  "contributors": [
@@ -43,7 +43,7 @@
43
43
  "svelte": "^3.20.0 || ^4.0.0 || ^5.0.0 || ^5.0.0-next.244"
44
44
  },
45
45
  "dependencies": {
46
- "@inertiajs/core": "1.3.0-beta.1",
46
+ "@inertiajs/core": "1.3.0-beta.2",
47
47
  "html-escape": "^2.0.0",
48
48
  "lodash": "^4.5.0"
49
49
  },