@inertiajs/svelte 3.0.0-beta.3 → 3.0.0-beta.4

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.
@@ -17,7 +17,7 @@
17
17
  import { router } from '@inertiajs/core'
18
18
  import Render, { h, type RenderProps } from './Render.svelte'
19
19
  import { setPage } from '../page.svelte'
20
- import { resetLayoutProps } from '../layoutProps.svelte'
20
+ import { resetLayoutProps, storeState } from '../layoutProps.svelte'
21
21
 
22
22
  interface Props {
23
23
  initialComponent: InertiaAppProps['initialComponent']
@@ -98,7 +98,18 @@
98
98
  return (component.layout as LayoutResolver)(h, child)
99
99
  }
100
100
 
101
- const effectiveLayout = (component.layout ?? defaultLayout?.(page.component, page)) as LayoutType | undefined
101
+ let effectiveLayout: LayoutType | undefined
102
+ const layoutValue = component.layout
103
+
104
+ if (
105
+ typeof layoutValue === 'function' &&
106
+ (layoutValue as Function).length <= 1 &&
107
+ typeof (layoutValue as Function).prototype === 'undefined'
108
+ ) {
109
+ effectiveLayout = (layoutValue as Function)(page.props) as LayoutType | undefined
110
+ } else {
111
+ effectiveLayout = (layoutValue ?? defaultLayout?.(page.component, page)) as LayoutType | undefined
112
+ }
102
113
 
103
114
  return effectiveLayout ? resolveLayout(effectiveLayout, child, page.props, key, !!component.layout) : child
104
115
  }
@@ -117,9 +128,21 @@
117
128
  const layouts = normalizeLayouts(layout, isComponent, isFromPage ? isRenderFunction : undefined)
118
129
 
119
130
  if (layouts.length > 0) {
131
+ const dynamicProps = isServer ? { shared: {}, named: {} } : { shared: storeState.shared, named: storeState.named }
132
+
120
133
  return layouts.reduceRight((child, layout) => {
121
134
  return {
122
- ...h(layout.component, { ...pageProps, ...layout.props }, [child], key),
135
+ ...h(
136
+ layout.component,
137
+ {
138
+ ...pageProps,
139
+ ...layout.props,
140
+ ...dynamicProps.shared,
141
+ ...(layout.name ? dynamicProps.named[layout.name] || {} : {}),
142
+ },
143
+ [child],
144
+ key,
145
+ ),
123
146
  name: layout.name,
124
147
  }
125
148
  }, child)
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import { isSameUrlWithoutQueryOrHash, router } from '@inertiajs/core'
3
- import { get } from 'lodash-es'
3
+ import { get } from 'es-toolkit/compat'
4
4
  import { page } from '../index'
5
5
 
6
6
  interface Props {
@@ -16,7 +16,7 @@
16
16
  UseFormUtils,
17
17
  } from '@inertiajs/core'
18
18
  import { type NamedInputEvent, type ValidationConfig, type Validator } from 'laravel-precognition'
19
- import { isEqual } from 'lodash-es'
19
+ import { isEqual } from 'es-toolkit'
20
20
  import { onMount } from 'svelte'
21
21
  import { setFormContext } from './formContext'
22
22
  import useForm from '../useForm.svelte'
@@ -9,6 +9,7 @@
9
9
  useInfiniteScroll,
10
10
  } from '@inertiajs/core'
11
11
  import { onDestroy, onMount } from 'svelte'
12
+ import { usePage } from '../page.svelte'
12
13
 
13
14
  interface Props {
14
15
  data: InfiniteScrollComponentBaseProps['data']
@@ -57,11 +58,13 @@
57
58
  let itemsElementRef: HTMLElement = $state(null!)
58
59
  let startElementRef: HTMLElement = $state(null!)
59
60
  let endElementRef: HTMLElement = $state(null!)
61
+ const scrollProp = usePage().scrollProps?.[data]
62
+
60
63
  let loadingPrevious = $state(false)
61
64
  let loadingNext = $state(false)
62
65
  let requestCount = $state(0)
63
- let hasPreviousPage = $state(false)
64
- let hasNextPage = $state(false)
66
+ let hasPreviousPage = $state(!!scrollProp?.previousPage)
67
+ let hasNextPage = $state(!!scrollProp?.nextPage)
65
68
 
66
69
  let infiniteScrollInstance: UseInfiniteScrollProps = $state(null!)
67
70
 
@@ -39,23 +39,9 @@
39
39
 
40
40
  <script lang="ts">
41
41
  import Render from './Render.svelte'
42
- import { setContext } from 'svelte'
43
- import { LAYOUT_CONTEXT_KEY } from '../layoutProps.svelte'
44
42
 
45
43
  // svelte-ignore state_referenced_locally
46
- const { component, props = {}, children = [], key = null, name }: RenderProps = $props()
47
-
48
- // svelte-ignore state_referenced_locally
49
- if (children.length > 0) {
50
- setContext(LAYOUT_CONTEXT_KEY, {
51
- get staticProps() {
52
- return props
53
- },
54
- get name() {
55
- return name
56
- },
57
- })
58
- }
44
+ const { component, props = {}, children = [], key = null }: RenderProps = $props()
59
45
  </script>
60
46
 
61
47
  {#if component}
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import { router, type ReloadOptions } from '@inertiajs/core'
3
- import { get } from 'lodash-es'
3
+ import { get } from 'es-toolkit/compat'
4
4
  import { usePage } from '../page.svelte'
5
5
 
6
6
  interface Props {
package/dist/index.d.ts CHANGED
@@ -8,10 +8,10 @@ export { default as InfiniteScroll } from './components/InfiniteScroll.svelte';
8
8
  export { default as Link } from './components/Link.svelte';
9
9
  export { default as WhenVisible } from './components/WhenVisible.svelte';
10
10
  export { default as createInertiaApp } from './createInertiaApp';
11
- export { resetLayoutProps, setLayoutProps, setLayoutPropsFor, useLayoutProps } from './layoutProps.svelte';
11
+ export { resetLayoutProps, setLayoutProps, setLayoutPropsFor } from './layoutProps.svelte';
12
12
  export { default as inertia } from './link';
13
13
  export { default as page, usePage } from './page.svelte';
14
- export { type ResolvedComponent, type SvelteInertiaAppConfig } from './types';
14
+ export { type LayoutCallback, type ResolvedComponent, type SvelteInertiaAppConfig } from './types';
15
15
  export { default as useForm, type InertiaForm, type InertiaFormProps, type InertiaPrecognitiveForm, } from './useForm.svelte';
16
16
  export { default as useHttp } from './useHttp.svelte';
17
17
  export { default as usePoll } from './usePoll';
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ export { default as InfiniteScroll } from './components/InfiniteScroll.svelte';
9
9
  export { default as Link } from './components/Link.svelte';
10
10
  export { default as WhenVisible } from './components/WhenVisible.svelte';
11
11
  export { default as createInertiaApp } from './createInertiaApp';
12
- export { resetLayoutProps, setLayoutProps, setLayoutPropsFor, useLayoutProps } from './layoutProps.svelte';
12
+ export { resetLayoutProps, setLayoutProps, setLayoutPropsFor } from './layoutProps.svelte';
13
13
  export { default as inertia } from './link';
14
14
  export { default as page, usePage } from './page.svelte';
15
15
  export {} from './types';
@@ -1,5 +1,8 @@
1
- export declare function setLayoutProps(props: Record<string, unknown>): void;
2
- export declare function setLayoutPropsFor(name: string, props: Record<string, unknown>): void;
1
+ import { type LayoutProps, type NamedLayoutProps } from '@inertiajs/core';
2
+ export declare const storeState: {
3
+ shared: Record<string, unknown>;
4
+ named: Record<string, Record<string, unknown>>;
5
+ };
6
+ export declare function setLayoutProps(props: Partial<LayoutProps>): void;
7
+ export declare function setLayoutPropsFor<K extends keyof NamedLayoutProps>(name: K, props: Partial<NamedLayoutProps[K]>): void;
3
8
  export declare function resetLayoutProps(): void;
4
- export declare const LAYOUT_CONTEXT_KEY: unique symbol;
5
- export declare function useLayoutProps<T extends Record<string, unknown>>(defaults: T): T;
@@ -1,7 +1,6 @@
1
- import { createLayoutPropsStore, mergeLayoutProps } from '@inertiajs/core';
2
- import { getContext } from 'svelte';
1
+ import { createLayoutPropsStore } from '@inertiajs/core';
3
2
  const store = createLayoutPropsStore();
4
- const storeState = $state({
3
+ export const storeState = $state({
5
4
  shared: {},
6
5
  named: {},
7
6
  });
@@ -18,19 +17,7 @@ export function setLayoutPropsFor(name, props) {
18
17
  }
19
18
  export function resetLayoutProps() {
20
19
  store.reset();
21
- }
22
- export const LAYOUT_CONTEXT_KEY = Symbol('inertia-layout');
23
- export function useLayoutProps(defaults) {
24
- const context = getContext(LAYOUT_CONTEXT_KEY);
25
- const resolve = () => {
26
- const staticProps = context?.staticProps ?? {};
27
- const name = context?.name;
28
- const dynamicProps = name ? { ...storeState.shared, ...(storeState.named[name] ?? {}) } : storeState.shared;
29
- return mergeLayoutProps(defaults, staticProps, dynamicProps);
30
- };
31
- const state = $state(resolve());
32
- $effect.pre(() => {
33
- Object.assign(state, resolve());
34
- });
35
- return state;
20
+ const snapshot = store.get();
21
+ storeState.shared = snapshot.shared;
22
+ storeState.named = snapshot.named;
36
23
  }
package/dist/types.d.ts CHANGED
@@ -3,13 +3,14 @@ import type { Component } from 'svelte';
3
3
  import type { RenderFunction, RenderProps } from './components/Render.svelte';
4
4
  export type ComponentResolver = (name: string, page?: Page<SharedPageProps>) => ResolvedComponent | Promise<ResolvedComponent>;
5
5
  export type LayoutResolver = (h: RenderFunction, page: RenderProps) => RenderProps;
6
+ export type LayoutCallback = (props: SharedPageProps) => unknown;
6
7
  export type LayoutTuple = [Component, Record<string, unknown>?];
7
8
  export type LayoutObject = {
8
9
  component: Component;
9
10
  props?: Record<string, unknown>;
10
11
  };
11
12
  export type NamedLayouts = Record<string, Component | LayoutTuple | LayoutObject>;
12
- export type LayoutType = LayoutResolver | Component | Component[] | LayoutTuple | LayoutObject | NamedLayouts | (Component | LayoutTuple | LayoutObject)[];
13
+ export type LayoutType = LayoutResolver | LayoutCallback | Component | Component[] | LayoutTuple | LayoutObject | NamedLayouts | (Component | LayoutTuple | LayoutObject)[];
13
14
  export type ResolvedComponent = {
14
15
  default: Component;
15
16
  layout?: LayoutType;
@@ -1,5 +1,5 @@
1
1
  import { router, UseFormUtils } from '@inertiajs/core';
2
- import { cloneDeep } from 'lodash-es';
2
+ import { cloneDeep } from 'es-toolkit';
3
3
  import useFormState, {} from './useFormState.svelte';
4
4
  let reservedFormKeys = null;
5
5
  let bootstrapping = false;
@@ -1,6 +1,7 @@
1
1
  import { router, UseFormUtils } from '@inertiajs/core';
2
+ import { cloneDeep, isEqual } from 'es-toolkit';
3
+ import { get, has, set } from 'es-toolkit/compat';
2
4
  import { createValidator, resolveName, toSimpleValidationErrors } from 'laravel-precognition';
3
- import { cloneDeep, get, has, isEqual, set } from 'lodash-es';
4
5
  import { config } from '.';
5
6
  export default function useFormState(options) {
6
7
  const { data: dataOption, rememberKey, precognitionEndpoint: initialPrecognitionEndpoint } = options;
@@ -21,12 +21,12 @@ export interface UseHttpProps<TForm extends object, TResponse = unknown> {
21
21
  resetAndClearErrors<K extends FormDataKeys<TForm>>(...fields: K[]): this;
22
22
  setError<K extends FormDataKeys<TForm>>(field: K, value: ErrorValue): this;
23
23
  setError(errors: FormDataErrors<TForm>): this;
24
- submit(...args: UseHttpSubmitArguments<TResponse, TForm>): Promise<TResponse>;
25
- get(url: string, options?: UseHttpSubmitOptions<TResponse, TForm>): Promise<TResponse>;
26
- post(url: string, options?: UseHttpSubmitOptions<TResponse, TForm>): Promise<TResponse>;
27
- put(url: string, options?: UseHttpSubmitOptions<TResponse, TForm>): Promise<TResponse>;
28
- patch(url: string, options?: UseHttpSubmitOptions<TResponse, TForm>): Promise<TResponse>;
29
- delete(url: string, options?: UseHttpSubmitOptions<TResponse, TForm>): Promise<TResponse>;
24
+ submit<R = TResponse>(...args: UseHttpSubmitArguments<R, TForm>): Promise<R>;
25
+ get<R = TResponse>(url: string, options?: UseHttpSubmitOptions<R, TForm>): Promise<R>;
26
+ post<R = TResponse>(url: string, options?: UseHttpSubmitOptions<R, TForm>): Promise<R>;
27
+ put<R = TResponse>(url: string, options?: UseHttpSubmitOptions<R, TForm>): Promise<R>;
28
+ patch<R = TResponse>(url: string, options?: UseHttpSubmitOptions<R, TForm>): Promise<R>;
29
+ delete<R = TResponse>(url: string, options?: UseHttpSubmitOptions<R, TForm>): Promise<R>;
30
30
  cancel(): void;
31
31
  dontRemember<K extends FormDataKeys<TForm>>(...fields: K[]): this;
32
32
  optimistic(callback: (currentData: TForm) => Partial<TForm>): this;
@@ -1,6 +1,6 @@
1
1
  import { hasFiles, http, HttpCancelledError, HttpResponseError, mergeDataIntoQueryString, objectToFormData, UseFormUtils, } from '@inertiajs/core';
2
+ import { cloneDeep } from 'es-toolkit';
2
3
  import { toSimpleValidationErrors } from 'laravel-precognition';
3
- import { cloneDeep } from 'lodash-es';
4
4
  import useFormState, {} from './useFormState.svelte';
5
5
  export default function useHttp(...args) {
6
6
  const { rememberKey, data, precognitionEndpoint } = UseFormUtils.parseUseFormArguments(...args);
@@ -72,7 +72,7 @@ export default function useHttp(...args) {
72
72
  options.onProgress?.(event);
73
73
  },
74
74
  });
75
- const responseData = JSON.parse(response.data);
75
+ const responseData = (response.data ? JSON.parse(response.data) : null);
76
76
  if (response.status >= 200 && response.status < 300) {
77
77
  markAsSuccessful();
78
78
  setFormState('response', responseData);
@@ -1,5 +1,5 @@
1
1
  import { router } from '@inertiajs/core';
2
- import { cloneDeep } from 'lodash-es';
2
+ import { cloneDeep } from 'es-toolkit';
3
3
  export default function useRemember(initialState, key) {
4
4
  const restored = router.restore(key);
5
5
  const state = $state(restored !== undefined ? cloneDeep(restored) : initialState);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inertiajs/svelte",
3
- "version": "3.0.0-beta.3",
3
+ "version": "3.0.0-beta.4",
4
4
  "license": "MIT",
5
5
  "description": "The Svelte adapter for Inertia.js",
6
6
  "contributors": [
@@ -53,10 +53,9 @@
53
53
  "svelte": "^5.0.0"
54
54
  },
55
55
  "dependencies": {
56
- "@types/lodash-es": "^4.17.12",
57
- "laravel-precognition": "2.0.0-beta.3",
58
- "lodash-es": "^4.17.23",
59
- "@inertiajs/core": "3.0.0-beta.3"
56
+ "es-toolkit": "^1.33.0",
57
+ "laravel-precognition": "2.0.0-beta.5",
58
+ "@inertiajs/core": "3.0.0-beta.4"
60
59
  },
61
60
  "scripts": {
62
61
  "build": "pnpm package && svelte-check --tsconfig ./tsconfig.json && publint",
@@ -64,7 +63,7 @@
64
63
  "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
65
64
  "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
66
65
  "dev": "pnpm package --watch",
67
- "es2020-check": "pnpm build:with-deps && es-check es2020 \"dist/**/*.js\" --checkFeatures --module --noCache --verbose",
66
+ "es2022-check": "pnpm build:with-deps && es-check es2022 \"dist/**/*.js\" --checkFeatures --module --noCache --verbose",
68
67
  "package": "svelte-kit sync && svelte-package --input src"
69
68
  }
70
69
  }