@inertia-solid/solid 0.1.1 → 0.1.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.
- package/dist/Form.jsx +2 -1
- package/dist/Head.js +4 -2
- package/dist/Link.d.ts +2 -1
- package/dist/Link.jsx +4 -3
- package/dist/WhenVisible.d.ts +1 -1
- package/dist/createInertiaApp.js +3 -2
- package/dist/types.d.ts +1 -4
- package/dist/useForm.js +0 -35
- package/dist/usePoll.js +4 -2
- package/package.json +5 -3
package/dist/Form.jsx
CHANGED
|
@@ -11,7 +11,7 @@ const formOnlyProps = new Set([
|
|
|
11
11
|
'options', 'onStart', 'onProgress', 'onFinish', 'onBefore', 'onCancel', 'onSuccess', 'onError', 'onHttpException',
|
|
12
12
|
'onNetworkError', 'onFlash', 'onCancelToken', 'onSubmitComplete', 'disableWhileProcessing', 'cancelOnUnmount',
|
|
13
13
|
'resetOnError', 'resetOnSuccess', 'setDefaultsOnSuccess', 'invalidateCacheTags', 'validateFiles',
|
|
14
|
-
'validationTimeout', 'withAllErrors', 'component', 'instant', 'children', 'ref',
|
|
14
|
+
'validationTimeout', 'withAllErrors', 'component', 'instant', 'children', 'ref', 'onBeforeUpdate',
|
|
15
15
|
]);
|
|
16
16
|
const fieldEvents = ['input', 'change', 'reset'];
|
|
17
17
|
/**
|
|
@@ -99,6 +99,7 @@ function FormImpl(props) {
|
|
|
99
99
|
optimistic: props.optimistic ? (pageProps) => props.optimistic?.(pageProps, data) : undefined,
|
|
100
100
|
onCancelToken: props.onCancelToken,
|
|
101
101
|
onBefore: props.onBefore,
|
|
102
|
+
onBeforeUpdate: props.onBeforeUpdate,
|
|
102
103
|
onStart: props.onStart,
|
|
103
104
|
onProgress: props.onProgress,
|
|
104
105
|
onFinish: props.onFinish,
|
package/dist/Head.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { insert, resolveSSRNode } from '@solidjs/web';
|
|
2
2
|
import { escape } from 'es-toolkit/compat';
|
|
3
|
-
import { createEffect, createRoot, createSignal, getOwner, isHydrating, onSettled, runWithOwner, useContext, } from 'solid-js';
|
|
3
|
+
import { createEffect, createRoot, createSignal, getOwner, isHydrating, onCleanup, onSettled, runWithOwner, useContext, } from 'solid-js';
|
|
4
4
|
import HeadContext from './HeadContext';
|
|
5
5
|
const titleTag = (title) => `<title data-inertia="">${escape(title)}</title>`;
|
|
6
6
|
/** Each element child as the tag string core's head manager diffs, keyed by `head-key`. */
|
|
@@ -70,6 +70,9 @@ export default function Head(props) {
|
|
|
70
70
|
if (typeof window === 'undefined') {
|
|
71
71
|
provider.update(serializeOnServer(props));
|
|
72
72
|
}
|
|
73
|
+
else {
|
|
74
|
+
onCleanup(provider.disconnect);
|
|
75
|
+
}
|
|
73
76
|
// The children render into a detached element once Head settles. A settle inside the root hydration pass mounts
|
|
74
77
|
// in a microtask, after hydrate() returns, as the server rendered no children under Head's path for their
|
|
75
78
|
// templates to claim. Waiting for the whole hydration phase would let core's head manager remove the server's
|
|
@@ -91,7 +94,6 @@ export default function Head(props) {
|
|
|
91
94
|
});
|
|
92
95
|
return () => {
|
|
93
96
|
observer.disconnect();
|
|
94
|
-
provider.disconnect();
|
|
95
97
|
dispose();
|
|
96
98
|
};
|
|
97
99
|
}));
|
package/dist/Link.d.ts
CHANGED
|
@@ -7,7 +7,8 @@ interface BaseInertiaLinkProps extends LinkComponentBaseProps {
|
|
|
7
7
|
ref?: (el: HTMLElement) => void;
|
|
8
8
|
children?: JSX.Element;
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
type AnchorAttributes = JSX.AnchorHTMLAttributes<HTMLElement>;
|
|
11
|
+
export type InertiaLinkProps = BaseInertiaLinkProps & Omit<AnchorAttributes, keyof BaseInertiaLinkProps> & Omit<JSX.ButtonHTMLAttributes<HTMLElement>, keyof AnchorAttributes | keyof BaseInertiaLinkProps>;
|
|
11
12
|
/**
|
|
12
13
|
* A visit link. It renders `a`, or `button` for a non-GET method, and intercepts plain clicks to visit through the
|
|
13
14
|
* router. Props are read where they are used, so a prop that changes after mount takes effect on the next event.
|
package/dist/Link.jsx
CHANGED
|
@@ -7,6 +7,7 @@ const linkOnlyProps = new Set([
|
|
|
7
7
|
'except', 'headers', 'queryStringArrayFormat', 'async', 'viewTransition', 'instant', 'pageProps', 'prefetch',
|
|
8
8
|
'cacheFor', 'cacheTags', 'onClick', 'children', 'onCancelToken', 'onBefore', 'onStart', 'onProgress', 'onFinish',
|
|
9
9
|
'onCancel', 'onSuccess', 'onError', 'onHttpException', 'onNetworkError', 'onFlash', 'onPrefetching', 'onPrefetched',
|
|
10
|
+
'onBeforeUpdate',
|
|
10
11
|
]);
|
|
11
12
|
const toModes = (prefetch) => {
|
|
12
13
|
if (prefetch === true) {
|
|
@@ -73,6 +74,7 @@ export default function Link(props) {
|
|
|
73
74
|
viewTransition: props.viewTransition ?? false,
|
|
74
75
|
onCancelToken: props.onCancelToken,
|
|
75
76
|
onBefore: props.onBefore,
|
|
77
|
+
onBeforeUpdate: props.onBeforeUpdate,
|
|
76
78
|
onStart: (pending) => {
|
|
77
79
|
setVisitsInFlight((count) => count + 1);
|
|
78
80
|
props.onStart?.(pending);
|
|
@@ -91,9 +93,8 @@ export default function Link(props) {
|
|
|
91
93
|
});
|
|
92
94
|
// With only `click` to prefetch, the response is meant for the visit that follows, so it is not cached.
|
|
93
95
|
const cacheFor = () => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return given;
|
|
96
|
+
if (props.cacheFor !== undefined) {
|
|
97
|
+
return props.cacheFor;
|
|
97
98
|
}
|
|
98
99
|
return modes().length === 1 && modes()[0] === 'click' ? 0 : config.get('prefetch.cacheFor');
|
|
99
100
|
};
|
package/dist/WhenVisible.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface WhenVisibleSlotProps {
|
|
|
8
8
|
export interface WhenVisibleProps {
|
|
9
9
|
/** Plain children, or a render function receiving `{ fetching }`. */
|
|
10
10
|
children: Slot<WhenVisibleSlotProps>;
|
|
11
|
-
fallback
|
|
11
|
+
fallback?: JSX.Element | (() => JSX.Element);
|
|
12
12
|
data?: string | string[];
|
|
13
13
|
params?: ReloadOptions;
|
|
14
14
|
buffer?: number;
|
package/dist/createInertiaApp.js
CHANGED
|
@@ -7,6 +7,7 @@ export default async function createInertiaApp({ id = 'app', resolve, setup, tit
|
|
|
7
7
|
if (nonce) {
|
|
8
8
|
config.set('nonce', nonce);
|
|
9
9
|
}
|
|
10
|
+
const scriptNonce = config.get('nonce');
|
|
10
11
|
if (http) {
|
|
11
12
|
httpModule.setClient(http);
|
|
12
13
|
}
|
|
@@ -35,9 +36,9 @@ export default async function createInertiaApp({ id = 'app', resolve, setup, tit
|
|
|
35
36
|
? setup({ el: null, App, props })
|
|
36
37
|
: withApp
|
|
37
38
|
? withApp(app, { ssr: true, page })
|
|
38
|
-
: app(), { nonce });
|
|
39
|
+
: app(), { nonce: scriptNonce });
|
|
39
40
|
// `hydrate` needs Solid's bootstrap (`_$HY`) in the document before the app script runs
|
|
40
|
-
return { head: [generateHydrationScript({ nonce }), ...head], body: buildSSRBody(id, page, html) };
|
|
41
|
+
return { head: [generateHydrationScript({ nonce: scriptNonce }), ...head], body: buildSSRBody(id, page, html) };
|
|
41
42
|
};
|
|
42
43
|
if (isServer) {
|
|
43
44
|
// The Vite plugin's SSR transform calls createInertiaApp without a page and renders later
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { LayoutCallbackReturn, SharedPageProps } from '@inertiajs/core';
|
|
2
|
-
import type { JSX } from '@solidjs/web';
|
|
3
2
|
import type { Component } from 'solid-js';
|
|
4
3
|
/** Any component. A layout takes `children`; a page takes its props. */
|
|
5
4
|
export type RenderComponent = Component<never>;
|
|
@@ -17,9 +16,7 @@ export type RenderFunction = {
|
|
|
17
16
|
(component: RenderComponent, props?: Record<string, unknown>, children?: RenderNode[], key?: number | null): RenderNode;
|
|
18
17
|
(component: RenderComponent, children?: RenderNode[], key?: number | null): RenderNode;
|
|
19
18
|
};
|
|
20
|
-
type Layout =
|
|
21
|
-
children: JSX.Element;
|
|
22
|
-
}>;
|
|
19
|
+
type Layout = RenderComponent;
|
|
23
20
|
/** Picks persistent layouts from the shared page props. */
|
|
24
21
|
export type LayoutCallback = (props: SharedPageProps) => LayoutCallbackReturn<Layout>;
|
|
25
22
|
/** `(h, page) => h(Layout, [page])`. Nest with `h(Outer, [h(Inner, [page])])`. */
|
package/dist/useForm.js
CHANGED
|
@@ -1,44 +1,9 @@
|
|
|
1
1
|
import { router, UseFormUtils, } from '@inertiajs/core';
|
|
2
|
-
import { createRoot, runWithOwner } from 'solid-js';
|
|
3
2
|
import useFormState from './useFormState';
|
|
4
3
|
/** Every verb is `submit(verb, url, options)`. */
|
|
5
4
|
const verbs = ['get', 'post', 'put', 'patch', 'delete', 'query'];
|
|
6
|
-
let reservedFormKeys = null;
|
|
7
|
-
let bootstrapping = false;
|
|
8
|
-
/** Logs an error for data keys that name a form member, as the Vue and Svelte adapters do. */
|
|
9
|
-
function validateFormDataKeys(data) {
|
|
10
|
-
if (bootstrapping) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
if (reservedFormKeys === null) {
|
|
14
|
-
bootstrapping = true;
|
|
15
|
-
try {
|
|
16
|
-
// A detached root takes no hydration id, so the one-off probe cannot shift the ids of the component that runs it
|
|
17
|
-
reservedFormKeys = runWithOwner(null, () => createRoot((dispose) => {
|
|
18
|
-
const keys = new Set(Object.keys(useForm({})));
|
|
19
|
-
dispose();
|
|
20
|
-
return keys;
|
|
21
|
-
}));
|
|
22
|
-
}
|
|
23
|
-
catch {
|
|
24
|
-
// Solid dev can throw when the first useForm runs inside a computation; skip validation for this call and retry on the next
|
|
25
|
-
}
|
|
26
|
-
finally {
|
|
27
|
-
bootstrapping = false;
|
|
28
|
-
}
|
|
29
|
-
if (reservedFormKeys === null) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const conflicts = Object.keys(data).filter((key) => reservedFormKeys.has(key));
|
|
34
|
-
if (conflicts.length > 0) {
|
|
35
|
-
console.error(`[Inertia] useForm() data contains field(s) that conflict with form properties: ${conflicts.map((k) => `"${k}"`).join(', ')}. ` +
|
|
36
|
-
`These fields will be overwritten by form methods/properties. Please rename these fields.`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
5
|
export default function useForm(...args) {
|
|
40
6
|
const { rememberKey, data, precognitionEndpoint } = UseFormUtils.parseUseFormArguments(...args);
|
|
41
|
-
validateFormDataKeys(typeof data === 'function' ? data() : data);
|
|
42
7
|
const state = useFormState({ data, rememberKey, precognitionEndpoint });
|
|
43
8
|
let cancelToken = null;
|
|
44
9
|
let pendingOptimistic = null;
|
package/dist/usePoll.js
CHANGED
|
@@ -5,8 +5,8 @@ import { createSignal, onSettled } from 'solid-js';
|
|
|
5
5
|
* called for each poll, so it can read the current state.
|
|
6
6
|
*/
|
|
7
7
|
export default function usePoll(interval, requestOptions = {}, options = { autoStart: true }) {
|
|
8
|
-
|
|
9
|
-
const [polling, setPolling] = createSignal(autoStart);
|
|
8
|
+
let autoStart = options.autoStart ?? true;
|
|
9
|
+
const [polling, setPolling] = createSignal(autoStart, { ownedWrite: true });
|
|
10
10
|
let poll;
|
|
11
11
|
onSettled(() => {
|
|
12
12
|
poll = router.poll(interval, requestOptions, { ...options, autoStart });
|
|
@@ -14,10 +14,12 @@ export default function usePoll(interval, requestOptions = {}, options = { autoS
|
|
|
14
14
|
});
|
|
15
15
|
return {
|
|
16
16
|
start() {
|
|
17
|
+
autoStart = true;
|
|
17
18
|
poll?.start();
|
|
18
19
|
setPolling(true);
|
|
19
20
|
},
|
|
20
21
|
stop() {
|
|
22
|
+
autoStart = false;
|
|
21
23
|
poll?.stop();
|
|
22
24
|
setPolling(false);
|
|
23
25
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inertia-solid/solid",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Inertia.js v3 client adapter for Solid 2.0.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -34,11 +34,13 @@
|
|
|
34
34
|
},
|
|
35
35
|
"./server": {
|
|
36
36
|
"types": "./dist/server.d.ts",
|
|
37
|
-
"solid": "./dist/server.js"
|
|
37
|
+
"solid": "./dist/server.js",
|
|
38
|
+
"import": "./dist/server.js"
|
|
38
39
|
},
|
|
39
40
|
"./echo": {
|
|
40
41
|
"types": "./dist/echo.d.ts",
|
|
41
|
-
"solid": "./dist/echo.js"
|
|
42
|
+
"solid": "./dist/echo.js",
|
|
43
|
+
"import": "./dist/echo.js"
|
|
42
44
|
}
|
|
43
45
|
},
|
|
44
46
|
"publishConfig": {
|