@holo-js/adapter-next 0.5.1 → 0.5.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/.holo-build-fingerprint +1 -1
- package/dist/{chunk-7LOU63WN.mjs → chunk-755YLPDP.mjs} +2 -0
- package/dist/client.d.ts +2 -16
- package/dist/client.mjs +2 -102
- package/dist/config.mjs +2 -12
- package/dist/internal/request-validation-flash.browser.d.ts +5 -0
- package/dist/internal/request-validation-flash.browser.mjs +26 -0
- package/dist/internal/request-validation-flash.d.ts +9 -0
- package/dist/internal/request-validation-flash.mjs +33 -0
- package/dist/internal/use-form.d.ts +15 -0
- package/dist/internal/use-form.mjs +107 -0
- package/dist/internal/use-validation-errors.d.ts +10 -0
- package/dist/internal/use-validation-errors.mjs +122 -0
- package/dist/runtime.mjs +4 -4
- package/package.json +24 -15
- package/dist/chunk-2JUQOM3L.mjs +0 -17
- package/dist/internal/validation-errors.d.ts +0 -10
- package/dist/internal/validation-errors.mjs +0 -68
- package/dist/internal/validation-layout.d.ts +0 -8
- package/dist/internal/validation-layout.mjs +0 -21
- package/dist/layout-loader.d.ts +0 -17
- package/dist/layout-loader.mjs +0 -69
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
3ea9037da21ddc3c03bcd3a9105f0feab1f647d3112428cbcc09c81578afcd45
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/validation-flash.ts
|
|
2
2
|
var VALIDATION_FLASH_COOKIE = "holo_form_failure";
|
|
3
|
+
var VALIDATION_FLASH_ELEMENT_ID = "__holo_validation_flash";
|
|
3
4
|
var MAX_FLASH_COOKIE_BYTES = 3800;
|
|
4
5
|
function isMessages(value) {
|
|
5
6
|
return Array.isArray(value) && value.every((message) => typeof message === "string");
|
|
@@ -43,6 +44,7 @@ function serializeValidationFlash(flash) {
|
|
|
43
44
|
|
|
44
45
|
export {
|
|
45
46
|
VALIDATION_FLASH_COOKIE,
|
|
47
|
+
VALIDATION_FLASH_ELEMENT_ID,
|
|
46
48
|
parseValidationFlash,
|
|
47
49
|
validationFlashPage,
|
|
48
50
|
serializeValidationFlash
|
package/dist/client.d.ts
CHANGED
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { UseFormOptions, ClientSubmitContext, ClientSubmitResult, UseFormResult, InferFormFieldTree } from '@holo-js/forms/internal/client';
|
|
1
|
+
export { adapterNextClientInternals, useForm } from '@holo-js/adapter-next/internal/use-form';
|
|
2
|
+
export { useValidationErrors } from '@holo-js/adapter-next/internal/use-validation-errors';
|
|
4
3
|
export { ClientCsrfOptions, ClientSubmitContext, ClientSubmitResult, FormFieldState, FormFieldTree, FormRequestCredentials, UseFormOptions, UseFormResult, ValidateOnMode } from '@holo-js/forms/internal/client';
|
|
5
|
-
export { useValidationErrors } from '@holo-js/adapter-next/internal/validation-errors';
|
|
6
|
-
|
|
7
|
-
declare function isNextRedirectError(error: unknown): boolean;
|
|
8
|
-
declare function createSubmitterBridge<TData, TSuccess>(optionsRef: {
|
|
9
|
-
current: UseFormOptions<TData, TSuccess> | undefined;
|
|
10
|
-
}, onHttpError: (error: Error) => void): (context: ClientSubmitContext<TData>) => Promise<ClientSubmitResult<TData, TSuccess> | void> | ClientSubmitResult<TData, TSuccess> | void;
|
|
11
|
-
declare function useForm<TSchema extends ValidationSchema, TSuccess = unknown>(schemaDefinition: TSchema, options?: UseFormOptions<InferFormData<TSchema>, TSuccess>): UseFormResult<InferFormData<TSchema>, TSuccess, InferFormFieldTree<TSchema>>;
|
|
12
|
-
declare const adapterNextClientInternals: {
|
|
13
|
-
isNextRedirectError: typeof isNextRedirectError;
|
|
14
|
-
createSubmitterBridge: typeof createSubmitterBridge;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export { adapterNextClientInternals, useForm };
|
package/dist/client.mjs
CHANGED
|
@@ -1,108 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
createNextRenderableError,
|
|
4
|
-
normalizeNextClientHttpError,
|
|
5
|
-
renderNextClientHttpErrorPage
|
|
6
|
-
} from "./chunk-PLFHK46L.mjs";
|
|
7
2
|
|
|
8
3
|
// src/client.ts
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
createFormClient,
|
|
12
|
-
markClientSubmitControlFlowError
|
|
13
|
-
} from "@holo-js/forms/internal/client";
|
|
14
|
-
import { useValidationErrors } from "@holo-js/adapter-next/internal/validation-errors";
|
|
15
|
-
function isPlainObject(value) {
|
|
16
|
-
return !!value && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !(value instanceof Blob);
|
|
17
|
-
}
|
|
18
|
-
function areEqual(left, right) {
|
|
19
|
-
if (Object.is(left, right)) {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
if (left instanceof Date && right instanceof Date) {
|
|
23
|
-
return left.getTime() === right.getTime();
|
|
24
|
-
}
|
|
25
|
-
if (left instanceof Blob || right instanceof Blob) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
if (Array.isArray(left) && Array.isArray(right)) {
|
|
29
|
-
return left.length === right.length && left.every((value, index) => areEqual(value, right[index]));
|
|
30
|
-
}
|
|
31
|
-
if (isPlainObject(left) && isPlainObject(right)) {
|
|
32
|
-
const leftKeys = Object.keys(left);
|
|
33
|
-
const rightKeys = Object.keys(right);
|
|
34
|
-
return leftKeys.length === rightKeys.length && leftKeys.every((key) => key in right && areEqual(left[key], right[key]));
|
|
35
|
-
}
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
function areOptionsEqual(left, right) {
|
|
39
|
-
return left.action === right.action && left.method === right.method && left.credentials === right.credentials && left.csrf?.endpoint === right.csrf?.endpoint && left.validateOn === right.validateOn && Boolean(left.submitter) === Boolean(right.submitter) && areEqual(left.initialValues, right.initialValues) && areEqual(left.initialState, right.initialState);
|
|
40
|
-
}
|
|
41
|
-
function isNextRedirectError(error) {
|
|
42
|
-
if (!error || typeof error !== "object" && typeof error !== "function" || !("digest" in error)) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
return typeof error.digest === "string" && error.digest.startsWith("NEXT_REDIRECT");
|
|
46
|
-
}
|
|
47
|
-
function createSubmitterBridge(optionsRef, onHttpError) {
|
|
48
|
-
return async (context) => {
|
|
49
|
-
const submitter = optionsRef.current?.submitter;
|
|
50
|
-
if (!submitter) {
|
|
51
|
-
throw new TypeError("Expected submitter to be defined.");
|
|
52
|
-
}
|
|
53
|
-
try {
|
|
54
|
-
return await submitter(context);
|
|
55
|
-
} catch (error) {
|
|
56
|
-
if (isNextRedirectError(error)) {
|
|
57
|
-
throw markClientSubmitControlFlowError(error);
|
|
58
|
-
}
|
|
59
|
-
const httpError = normalizeNextClientHttpError(error);
|
|
60
|
-
if (httpError) {
|
|
61
|
-
renderNextClientHttpErrorPage(httpError);
|
|
62
|
-
onHttpError(createNextRenderableError(httpError));
|
|
63
|
-
}
|
|
64
|
-
throw error;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
function useForm(schemaDefinition, options = {}) {
|
|
69
|
-
const formRef = useRef(void 0);
|
|
70
|
-
const previousSchemaRef = useRef(void 0);
|
|
71
|
-
const previousOptionsRef = useRef(void 0);
|
|
72
|
-
const latestOptionsRef = useRef(void 0);
|
|
73
|
-
const submitterBridgeRef = useRef(void 0);
|
|
74
|
-
const [httpError, setHttpError] = useState(void 0);
|
|
75
|
-
const [, setVersion] = useState(0);
|
|
76
|
-
if (httpError) {
|
|
77
|
-
throw httpError;
|
|
78
|
-
}
|
|
79
|
-
latestOptionsRef.current = options;
|
|
80
|
-
if (options.submitter && !submitterBridgeRef.current) {
|
|
81
|
-
submitterBridgeRef.current = createSubmitterBridge(latestOptionsRef, setHttpError);
|
|
82
|
-
}
|
|
83
|
-
const resolvedOptions = options.submitter ? {
|
|
84
|
-
...options,
|
|
85
|
-
submitter: submitterBridgeRef.current
|
|
86
|
-
} : options;
|
|
87
|
-
if (!formRef.current || previousSchemaRef.current !== schemaDefinition) {
|
|
88
|
-
formRef.current = createFormClient(schemaDefinition, resolvedOptions);
|
|
89
|
-
previousSchemaRef.current = schemaDefinition;
|
|
90
|
-
previousOptionsRef.current = options;
|
|
91
|
-
} else {
|
|
92
|
-
const previousOptions = previousOptionsRef.current;
|
|
93
|
-
if (!areOptionsEqual(previousOptions, options)) {
|
|
94
|
-
formRef.current = createFormClient(schemaDefinition, resolvedOptions);
|
|
95
|
-
previousOptionsRef.current = options;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const form = formRef.current;
|
|
99
|
-
useEffect(() => form.subscribe(() => setVersion((version) => version + 1)), [form]);
|
|
100
|
-
return form;
|
|
101
|
-
}
|
|
102
|
-
var adapterNextClientInternals = {
|
|
103
|
-
isNextRedirectError,
|
|
104
|
-
createSubmitterBridge
|
|
105
|
-
};
|
|
4
|
+
import { adapterNextClientInternals, useForm } from "@holo-js/adapter-next/internal/use-form";
|
|
5
|
+
import { useValidationErrors } from "@holo-js/adapter-next/internal/use-validation-errors";
|
|
106
6
|
export {
|
|
107
7
|
adapterNextClientInternals,
|
|
108
8
|
useForm,
|
package/dist/config.mjs
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DEFAULT_PAGE_EXTENSIONS,
|
|
3
|
-
appLayoutPathPattern
|
|
4
|
-
} from "./chunk-2JUQOM3L.mjs";
|
|
5
|
-
|
|
6
1
|
// src/config.ts
|
|
7
2
|
import { assertRealtimeDefinitionTree, resolveRealtimeDefinitionDirectories } from "@holo-js/adapter-shared/realtime-directories";
|
|
8
3
|
import { existsSync, readFileSync, realpathSync } from "fs";
|
|
@@ -215,9 +210,6 @@ function withHolo(nextConfig = {}) {
|
|
|
215
210
|
const validationLoader = fileURLToPath(new URL("./validation-loader.mjs", import.meta.url));
|
|
216
211
|
const routeLoader = fileURLToPath(new URL("./route-loader.mjs", import.meta.url));
|
|
217
212
|
const serverActionLoader = fileURLToPath(new URL("./server-action-loader.mjs", import.meta.url));
|
|
218
|
-
const pageExtensions = nextConfig.pageExtensions ?? DEFAULT_PAGE_EXTENSIONS;
|
|
219
|
-
const appLayoutFile = appLayoutPathPattern(pageExtensions);
|
|
220
|
-
const layoutLoader = fileURLToPath(new URL("./layout-loader.mjs", import.meta.url));
|
|
221
213
|
const realtimeDefinitionLoader = fileURLToPath(new URL("./realtime-definition-loader.mjs", import.meta.url));
|
|
222
214
|
const realtimeDirectoryPatterns = hasRealtime ? resolveRealtimeDefinitionPatterns(nextConfig, process.cwd()) : { absolute: [], turbopackRelative: [] };
|
|
223
215
|
const mergedTurbopack = {
|
|
@@ -228,8 +220,7 @@ function withHolo(nextConfig = {}) {
|
|
|
228
220
|
...existingTurbopack.rules?.["*"] ? [existingTurbopack.rules["*"]].flat() : [],
|
|
229
221
|
{ condition: { all: ["browser", { not: "foreign" }, { path: /\.[cm]?[jt]sx?$/ }] }, loaders: [validationLoader] },
|
|
230
222
|
{ condition: { all: [{ not: "browser" }, { not: "foreign" }, { path: /(?:^|[\\/])app[\\/].*[\\/]route\.[cm]?[jt]s$/ }] }, loaders: [routeLoader] },
|
|
231
|
-
{ condition: { all: [{ not: "browser" }, { not: "foreign" }, { path: /\.[cm]?[jt]sx?$/ }, { content: USE_SERVER_DIRECTIVE }] }, loaders: [serverActionLoader] }
|
|
232
|
-
{ condition: { all: [{ not: "browser" }, { not: "foreign" }, { path: appLayoutFile }] }, loaders: [{ loader: layoutLoader, options: { pageExtensions, bundler: "turbopack" } }] }
|
|
223
|
+
{ condition: { all: [{ not: "browser" }, { not: "foreign" }, { path: /\.[cm]?[jt]sx?$/ }, { content: USE_SERVER_DIRECTIVE }] }, loaders: [serverActionLoader] }
|
|
233
224
|
],
|
|
234
225
|
...hasRealtime ? {
|
|
235
226
|
"*.{ts,tsx,js,jsx,mts,mjs,cts,cjs}": [
|
|
@@ -278,8 +269,7 @@ function withHolo(nextConfig = {}) {
|
|
|
278
269
|
...hasRealtime ? [createRealtimeDefinitionWebpackRule(realtimeDefinitionLoader, context.isServer, realtimeDirectoryPatterns.absolute)] : [],
|
|
279
270
|
...!context.isServer ? [{ test: /\.[cm]?[jt]sx?$/, exclude: /node_modules/, use: [{ loader: validationLoader }] }] : [],
|
|
280
271
|
...context.isServer ? [{ test: /[\\/]app[\\/].*[\\/]route\.[cm]?[jt]s$/, exclude: /node_modules/, use: [{ loader: routeLoader }] }] : [],
|
|
281
|
-
...context.isServer ? [{ test: /\.[cm]?[jt]sx?$/, exclude: /node_modules/, use: [{ loader: serverActionLoader }] }] : []
|
|
282
|
-
...context.isServer ? [{ test: appLayoutFile, issuerLayer: "rsc", exclude: /node_modules/, use: [{ loader: layoutLoader, options: { pageExtensions, bundler: "webpack" } }] }] : []
|
|
272
|
+
...context.isServer ? [{ test: /\.[cm]?[jt]sx?$/, exclude: /node_modules/, use: [{ loader: serverActionLoader }] }] : []
|
|
283
273
|
];
|
|
284
274
|
return nextWebpackConfig;
|
|
285
275
|
},
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
VALIDATION_FLASH_ELEMENT_ID
|
|
3
|
+
} from "../chunk-755YLPDP.mjs";
|
|
4
|
+
|
|
5
|
+
// src/request-validation-flash.browser.ts
|
|
6
|
+
var hydrationFlash;
|
|
7
|
+
function readHydrationFlash() {
|
|
8
|
+
const text = globalThis.document?.getElementById(VALIDATION_FLASH_ELEMENT_ID)?.textContent;
|
|
9
|
+
if (!text) return "";
|
|
10
|
+
try {
|
|
11
|
+
const flash = JSON.parse(text);
|
|
12
|
+
return typeof flash === "string" ? flash : "";
|
|
13
|
+
} catch {
|
|
14
|
+
return "";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function documentValidationFlash() {
|
|
18
|
+
return hydrationFlash ??= readHydrationFlash();
|
|
19
|
+
}
|
|
20
|
+
function useRequestValidationFlash() {
|
|
21
|
+
return documentValidationFlash();
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
documentValidationFlash,
|
|
25
|
+
useRequestValidationFlash
|
|
26
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The server render has no document; see useRequestValidationFlash(). */
|
|
2
|
+
declare function documentValidationFlash(): string;
|
|
3
|
+
/**
|
|
4
|
+
* The flash a form posted without JavaScript left for this server render. The render writes
|
|
5
|
+
* it into the page once, so the browser hydrates with the same errors.
|
|
6
|
+
*/
|
|
7
|
+
declare function useRequestValidationFlash(): string;
|
|
8
|
+
|
|
9
|
+
export { documentValidationFlash, useRequestValidationFlash };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
renderedValidationFlash
|
|
3
|
+
} from "../chunk-ZPWXXNMV.mjs";
|
|
4
|
+
import {
|
|
5
|
+
VALIDATION_FLASH_ELEMENT_ID
|
|
6
|
+
} from "../chunk-755YLPDP.mjs";
|
|
7
|
+
|
|
8
|
+
// src/request-validation-flash.ts
|
|
9
|
+
import { createElement } from "react";
|
|
10
|
+
import { useServerInsertedHTML } from "next/navigation.js";
|
|
11
|
+
import { workUnitAsyncStorage } from "next/dist/server/app-render/work-unit-async-storage.external.js";
|
|
12
|
+
var writtenRequests = /* @__PURE__ */ new WeakSet();
|
|
13
|
+
function documentValidationFlash() {
|
|
14
|
+
return "";
|
|
15
|
+
}
|
|
16
|
+
function useRequestValidationFlash() {
|
|
17
|
+
const request = workUnitAsyncStorage.getStore();
|
|
18
|
+
const flash = renderedValidationFlash(request) ?? "";
|
|
19
|
+
useServerInsertedHTML(() => {
|
|
20
|
+
if (!flash || !request || writtenRequests.has(request)) return null;
|
|
21
|
+
writtenRequests.add(request);
|
|
22
|
+
return createElement("script", {
|
|
23
|
+
id: VALIDATION_FLASH_ELEMENT_ID,
|
|
24
|
+
type: "application/json",
|
|
25
|
+
dangerouslySetInnerHTML: { __html: JSON.stringify(flash).replace(/</g, "\\u003c") }
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
return flash;
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
documentValidationFlash,
|
|
32
|
+
useRequestValidationFlash
|
|
33
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { InferFormData } from '@holo-js/forms';
|
|
2
|
+
import { ValidationSchema } from '@holo-js/validation';
|
|
3
|
+
import { UseFormOptions, ClientSubmitContext, ClientSubmitResult, UseFormResult, InferFormFieldTree } from '@holo-js/forms/internal/client';
|
|
4
|
+
|
|
5
|
+
declare function isNextRedirectError(error: unknown): boolean;
|
|
6
|
+
declare function createSubmitterBridge<TData, TSuccess>(optionsRef: {
|
|
7
|
+
current: UseFormOptions<TData, TSuccess> | undefined;
|
|
8
|
+
}, onHttpError: (error: Error) => void): (context: ClientSubmitContext<TData>) => Promise<ClientSubmitResult<TData, TSuccess> | void> | ClientSubmitResult<TData, TSuccess> | void;
|
|
9
|
+
declare function useForm<TSchema extends ValidationSchema, TSuccess = unknown>(schemaDefinition: TSchema, options?: UseFormOptions<InferFormData<TSchema>, TSuccess>): UseFormResult<InferFormData<TSchema>, TSuccess, InferFormFieldTree<TSchema>>;
|
|
10
|
+
declare const adapterNextClientInternals: {
|
|
11
|
+
isNextRedirectError: typeof isNextRedirectError;
|
|
12
|
+
createSubmitterBridge: typeof createSubmitterBridge;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { adapterNextClientInternals, useForm };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createNextRenderableError,
|
|
3
|
+
normalizeNextClientHttpError,
|
|
4
|
+
renderNextClientHttpErrorPage
|
|
5
|
+
} from "../chunk-PLFHK46L.mjs";
|
|
6
|
+
|
|
7
|
+
// src/use-form.ts
|
|
8
|
+
import { useEffect, useRef, useState } from "react";
|
|
9
|
+
import {
|
|
10
|
+
createFormClient,
|
|
11
|
+
markClientSubmitControlFlowError
|
|
12
|
+
} from "@holo-js/forms/internal/client";
|
|
13
|
+
function isPlainObject(value) {
|
|
14
|
+
return !!value && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !(value instanceof Blob);
|
|
15
|
+
}
|
|
16
|
+
function areEqual(left, right) {
|
|
17
|
+
if (Object.is(left, right)) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
if (left instanceof Date && right instanceof Date) {
|
|
21
|
+
return left.getTime() === right.getTime();
|
|
22
|
+
}
|
|
23
|
+
if (left instanceof Blob || right instanceof Blob) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (Array.isArray(left) && Array.isArray(right)) {
|
|
27
|
+
return left.length === right.length && left.every((value, index) => areEqual(value, right[index]));
|
|
28
|
+
}
|
|
29
|
+
if (isPlainObject(left) && isPlainObject(right)) {
|
|
30
|
+
const leftKeys = Object.keys(left);
|
|
31
|
+
const rightKeys = Object.keys(right);
|
|
32
|
+
return leftKeys.length === rightKeys.length && leftKeys.every((key) => key in right && areEqual(left[key], right[key]));
|
|
33
|
+
}
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
function areOptionsEqual(left, right) {
|
|
37
|
+
return left.action === right.action && left.method === right.method && left.credentials === right.credentials && left.csrf?.endpoint === right.csrf?.endpoint && left.validateOn === right.validateOn && Boolean(left.submitter) === Boolean(right.submitter) && areEqual(left.initialValues, right.initialValues) && areEqual(left.initialState, right.initialState);
|
|
38
|
+
}
|
|
39
|
+
function isNextRedirectError(error) {
|
|
40
|
+
if (!error || typeof error !== "object" && typeof error !== "function" || !("digest" in error)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return typeof error.digest === "string" && error.digest.startsWith("NEXT_REDIRECT");
|
|
44
|
+
}
|
|
45
|
+
function createSubmitterBridge(optionsRef, onHttpError) {
|
|
46
|
+
return async (context) => {
|
|
47
|
+
const submitter = optionsRef.current?.submitter;
|
|
48
|
+
if (!submitter) {
|
|
49
|
+
throw new TypeError("Expected submitter to be defined.");
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
return await submitter(context);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (isNextRedirectError(error)) {
|
|
55
|
+
throw markClientSubmitControlFlowError(error);
|
|
56
|
+
}
|
|
57
|
+
const httpError = normalizeNextClientHttpError(error);
|
|
58
|
+
if (httpError) {
|
|
59
|
+
renderNextClientHttpErrorPage(httpError);
|
|
60
|
+
onHttpError(createNextRenderableError(httpError));
|
|
61
|
+
}
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function useForm(schemaDefinition, options = {}) {
|
|
67
|
+
const formRef = useRef(void 0);
|
|
68
|
+
const previousSchemaRef = useRef(void 0);
|
|
69
|
+
const previousOptionsRef = useRef(void 0);
|
|
70
|
+
const latestOptionsRef = useRef(void 0);
|
|
71
|
+
const submitterBridgeRef = useRef(void 0);
|
|
72
|
+
const [httpError, setHttpError] = useState(void 0);
|
|
73
|
+
const [, setVersion] = useState(0);
|
|
74
|
+
if (httpError) {
|
|
75
|
+
throw httpError;
|
|
76
|
+
}
|
|
77
|
+
latestOptionsRef.current = options;
|
|
78
|
+
if (options.submitter && !submitterBridgeRef.current) {
|
|
79
|
+
submitterBridgeRef.current = createSubmitterBridge(latestOptionsRef, setHttpError);
|
|
80
|
+
}
|
|
81
|
+
const resolvedOptions = options.submitter ? {
|
|
82
|
+
...options,
|
|
83
|
+
submitter: submitterBridgeRef.current
|
|
84
|
+
} : options;
|
|
85
|
+
if (!formRef.current || previousSchemaRef.current !== schemaDefinition) {
|
|
86
|
+
formRef.current = createFormClient(schemaDefinition, resolvedOptions);
|
|
87
|
+
previousSchemaRef.current = schemaDefinition;
|
|
88
|
+
previousOptionsRef.current = options;
|
|
89
|
+
} else {
|
|
90
|
+
const previousOptions = previousOptionsRef.current;
|
|
91
|
+
if (!areOptionsEqual(previousOptions, options)) {
|
|
92
|
+
formRef.current = createFormClient(schemaDefinition, resolvedOptions);
|
|
93
|
+
previousOptionsRef.current = options;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const form = formRef.current;
|
|
97
|
+
useEffect(() => form.subscribe(() => setVersion((version) => version + 1)), [form]);
|
|
98
|
+
return form;
|
|
99
|
+
}
|
|
100
|
+
var adapterNextClientInternals = {
|
|
101
|
+
isNextRedirectError,
|
|
102
|
+
createSubmitterBridge
|
|
103
|
+
};
|
|
104
|
+
export {
|
|
105
|
+
adapterNextClientInternals,
|
|
106
|
+
useForm
|
|
107
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ValidationErrorBag } from '@holo-js/validation';
|
|
2
|
+
|
|
3
|
+
/** Runs when a page first loads the hook. */
|
|
4
|
+
declare function startDocument(): void;
|
|
5
|
+
declare function useValidationErrors<TData = Record<string, unknown>>(bag?: string): ValidationErrorBag<TData>;
|
|
6
|
+
declare const adapterNextValidationErrorsInternals: {
|
|
7
|
+
startDocument: typeof startDocument;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { adapterNextValidationErrorsInternals, useValidationErrors };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
VALIDATION_FLASH_COOKIE,
|
|
3
|
+
parseValidationFlash,
|
|
4
|
+
validationFlashPage
|
|
5
|
+
} from "../chunk-755YLPDP.mjs";
|
|
6
|
+
|
|
7
|
+
// src/use-validation-errors.ts
|
|
8
|
+
import { useContext, useEffect, useMemo, useSyncExternalStore } from "react";
|
|
9
|
+
import { usePathname } from "next/navigation.js";
|
|
10
|
+
import { LayoutRouterContext } from "next/dist/shared/lib/app-router-context.shared-runtime.js";
|
|
11
|
+
import { DEFAULT_VALIDATION_BAG, createErrorBag } from "@holo-js/validation/internal/error-bag";
|
|
12
|
+
import { documentValidationFlash, useRequestValidationFlash } from "@holo-js/adapter-next/internal/request-validation-flash";
|
|
13
|
+
var SEEN = "~";
|
|
14
|
+
var shown = "";
|
|
15
|
+
var shownPath;
|
|
16
|
+
var shownLocation;
|
|
17
|
+
var mountedCalls = 0;
|
|
18
|
+
var navigationEvents = false;
|
|
19
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
20
|
+
function browserDocument() {
|
|
21
|
+
return globalThis.document;
|
|
22
|
+
}
|
|
23
|
+
function locationPath() {
|
|
24
|
+
return globalThis.location?.pathname;
|
|
25
|
+
}
|
|
26
|
+
function rawFlashCookie() {
|
|
27
|
+
const prefix = `${VALIDATION_FLASH_COOKIE}=`;
|
|
28
|
+
return browserDocument()?.cookie.split(";").map((part) => part.trim()).find((part) => part.startsWith(prefix))?.slice(prefix.length) ?? "";
|
|
29
|
+
}
|
|
30
|
+
function readFlashCookie() {
|
|
31
|
+
const raw = rawFlashCookie();
|
|
32
|
+
const seen = raw.startsWith(SEEN);
|
|
33
|
+
try {
|
|
34
|
+
return { flash: decodeURIComponent(seen ? raw.slice(SEEN.length) : raw), seen };
|
|
35
|
+
} catch {
|
|
36
|
+
return { flash: "", seen };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function markFlashCookieSeen() {
|
|
40
|
+
const document = browserDocument();
|
|
41
|
+
const raw = rawFlashCookie();
|
|
42
|
+
if (!document || !raw || raw.startsWith(SEEN)) return;
|
|
43
|
+
const secure = globalThis.location?.protocol === "https:" ? "; Secure" : "";
|
|
44
|
+
document.cookie = `${VALIDATION_FLASH_COOKIE}=${SEEN}${raw}; Path=/; SameSite=Lax${secure}`;
|
|
45
|
+
}
|
|
46
|
+
function clearFlashCookie() {
|
|
47
|
+
const document = browserDocument();
|
|
48
|
+
if (document) document.cookie = `${VALIDATION_FLASH_COOKIE}=; Max-Age=0; Path=/; SameSite=Lax`;
|
|
49
|
+
}
|
|
50
|
+
function forget() {
|
|
51
|
+
shownPath = void 0;
|
|
52
|
+
shownLocation = void 0;
|
|
53
|
+
clearFlashCookie();
|
|
54
|
+
show("");
|
|
55
|
+
}
|
|
56
|
+
function subscribe(listener) {
|
|
57
|
+
listeners.add(listener);
|
|
58
|
+
return () => listeners.delete(listener);
|
|
59
|
+
}
|
|
60
|
+
function show(flash) {
|
|
61
|
+
if (shown === flash) return;
|
|
62
|
+
shown = flash;
|
|
63
|
+
for (const listener of listeners) listener();
|
|
64
|
+
}
|
|
65
|
+
function startDocument() {
|
|
66
|
+
if (!browserDocument()) return;
|
|
67
|
+
shown = documentValidationFlash();
|
|
68
|
+
shownPath = void 0;
|
|
69
|
+
shownLocation = void 0;
|
|
70
|
+
const cookie = readFlashCookie();
|
|
71
|
+
if (cookie.seen) clearFlashCookie();
|
|
72
|
+
else if (shown && cookie.flash === shown) markFlashCookieSeen();
|
|
73
|
+
const navigation = globalThis.navigation;
|
|
74
|
+
navigationEvents = Boolean(navigation);
|
|
75
|
+
navigation?.addEventListener("currententrychange", () => {
|
|
76
|
+
const url = navigation.currentEntry?.url;
|
|
77
|
+
if (shownLocation !== void 0 && url && new URL(url).pathname !== shownLocation) forget();
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
startDocument();
|
|
81
|
+
function readableValidationFlash(value) {
|
|
82
|
+
const flash = parseValidationFlash(value);
|
|
83
|
+
if (!flash) return void 0;
|
|
84
|
+
try {
|
|
85
|
+
createErrorBag(flash.errors);
|
|
86
|
+
return flash;
|
|
87
|
+
} catch {
|
|
88
|
+
return void 0;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function useValidationErrors(bag = DEFAULT_VALIDATION_BAG) {
|
|
92
|
+
const pathname = usePathname();
|
|
93
|
+
useContext(LayoutRouterContext);
|
|
94
|
+
const requestFlash = useRequestValidationFlash();
|
|
95
|
+
const value = useSyncExternalStore(subscribe, () => shown, () => requestFlash);
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
mountedCalls++;
|
|
98
|
+
return () => {
|
|
99
|
+
mountedCalls--;
|
|
100
|
+
setTimeout(() => {
|
|
101
|
+
if (mountedCalls === 0 && shownPath !== void 0 && !navigationEvents) forget();
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
}, []);
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (shownPath !== void 0 && shownPath !== pathname) clearFlashCookie();
|
|
107
|
+
shownPath = pathname;
|
|
108
|
+
shownLocation = locationPath();
|
|
109
|
+
const cookie = readFlashCookie();
|
|
110
|
+
if (cookie.flash && !cookie.seen) markFlashCookieSeen();
|
|
111
|
+
show(cookie.flash);
|
|
112
|
+
});
|
|
113
|
+
const flash = useMemo(() => readableValidationFlash(value), [value]);
|
|
114
|
+
return createErrorBag(flash?.bag === bag && flash.page === validationFlashPage(pathname) ? flash.errors : {});
|
|
115
|
+
}
|
|
116
|
+
var adapterNextValidationErrorsInternals = {
|
|
117
|
+
startDocument
|
|
118
|
+
};
|
|
119
|
+
export {
|
|
120
|
+
adapterNextValidationErrorsInternals,
|
|
121
|
+
useValidationErrors
|
|
122
|
+
};
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
rememberRenderedValidationFlash
|
|
3
|
+
} from "./chunk-ZPWXXNMV.mjs";
|
|
1
4
|
import {
|
|
2
5
|
VALIDATION_FLASH_COOKIE,
|
|
3
6
|
serializeValidationFlash,
|
|
4
7
|
validationFlashPage
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import {
|
|
7
|
-
rememberRenderedValidationFlash
|
|
8
|
-
} from "./chunk-ZPWXXNMV.mjs";
|
|
8
|
+
} from "./chunk-755YLPDP.mjs";
|
|
9
9
|
|
|
10
10
|
// src/runtime.ts
|
|
11
11
|
import { AsyncLocalStorage } from "async_hooks";
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holo-js/adapter-next",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "Holo-JS Framework - Next.js adapter",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
6
7
|
"license": "MIT",
|
|
7
8
|
"repository": {
|
|
8
9
|
"type": "git",
|
|
@@ -25,15 +26,23 @@
|
|
|
25
26
|
"import": "./dist/client.mjs",
|
|
26
27
|
"default": "./dist/client.mjs"
|
|
27
28
|
},
|
|
28
|
-
"./internal/
|
|
29
|
-
"types": "./dist/internal/
|
|
30
|
-
"import": "./dist/internal/
|
|
31
|
-
"default": "./dist/internal/
|
|
29
|
+
"./internal/use-form": {
|
|
30
|
+
"types": "./dist/internal/use-form.d.ts",
|
|
31
|
+
"import": "./dist/internal/use-form.mjs",
|
|
32
|
+
"default": "./dist/internal/use-form.mjs"
|
|
32
33
|
},
|
|
33
|
-
"./internal/validation-
|
|
34
|
-
"types": "./dist/internal/validation-
|
|
35
|
-
"
|
|
36
|
-
"
|
|
34
|
+
"./internal/request-validation-flash": {
|
|
35
|
+
"types": "./dist/internal/request-validation-flash.d.ts",
|
|
36
|
+
"edge-light": "./dist/internal/request-validation-flash.mjs",
|
|
37
|
+
"worker": "./dist/internal/request-validation-flash.mjs",
|
|
38
|
+
"browser": "./dist/internal/request-validation-flash.browser.mjs",
|
|
39
|
+
"import": "./dist/internal/request-validation-flash.mjs",
|
|
40
|
+
"default": "./dist/internal/request-validation-flash.mjs"
|
|
41
|
+
},
|
|
42
|
+
"./internal/use-validation-errors": {
|
|
43
|
+
"types": "./dist/internal/use-validation-errors.d.ts",
|
|
44
|
+
"import": "./dist/internal/use-validation-errors.mjs",
|
|
45
|
+
"default": "./dist/internal/use-validation-errors.mjs"
|
|
37
46
|
},
|
|
38
47
|
"./realtime": {
|
|
39
48
|
"types": "./dist/realtime.d.ts",
|
|
@@ -59,11 +68,11 @@
|
|
|
59
68
|
"test": "vitest --run"
|
|
60
69
|
},
|
|
61
70
|
"dependencies": {
|
|
62
|
-
"@holo-js/adapter-shared": "^0.5.
|
|
63
|
-
"@holo-js/config": "^0.5.
|
|
64
|
-
"@holo-js/core": "^0.5.
|
|
65
|
-
"@holo-js/kernel": "^0.5.
|
|
66
|
-
"@holo-js/validation": "^0.5.
|
|
71
|
+
"@holo-js/adapter-shared": "^0.5.2",
|
|
72
|
+
"@holo-js/config": "^0.5.2",
|
|
73
|
+
"@holo-js/core": "^0.5.2",
|
|
74
|
+
"@holo-js/kernel": "^0.5.2",
|
|
75
|
+
"@holo-js/validation": "^0.5.2"
|
|
67
76
|
},
|
|
68
77
|
"peerDependencies": {
|
|
69
78
|
"@holo-js/forms": ">=0.4.0",
|
|
@@ -80,7 +89,7 @@
|
|
|
80
89
|
}
|
|
81
90
|
},
|
|
82
91
|
"devDependencies": {
|
|
83
|
-
"@holo-js/realtime": "^0.5.
|
|
92
|
+
"@holo-js/realtime": "^0.5.2",
|
|
84
93
|
"@jridgewell/trace-mapping": "^0.3.31",
|
|
85
94
|
"@types/node": "^22.20.5",
|
|
86
95
|
"next": "^16.4.3",
|
package/dist/chunk-2JUQOM3L.mjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// src/app-layout-files.ts
|
|
2
|
-
var DEFAULT_PAGE_EXTENSIONS = ["tsx", "ts", "jsx", "js"];
|
|
3
|
-
function extensionsPattern(pageExtensions) {
|
|
4
|
-
return pageExtensions.map((extension) => extension.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
|
|
5
|
-
}
|
|
6
|
-
function layoutFileNamePattern(pageExtensions) {
|
|
7
|
-
return new RegExp(`^layout\\.(?:${extensionsPattern(pageExtensions)})$`);
|
|
8
|
-
}
|
|
9
|
-
function appLayoutPathPattern(pageExtensions) {
|
|
10
|
-
return new RegExp(`(?:^|[\\\\/])app[\\\\/](?:.*[\\\\/])?layout\\.(?:${extensionsPattern(pageExtensions)})$`);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export {
|
|
14
|
-
DEFAULT_PAGE_EXTENSIONS,
|
|
15
|
-
layoutFileNamePattern,
|
|
16
|
-
appLayoutPathPattern
|
|
17
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { ValidationErrorBag } from '@holo-js/validation';
|
|
3
|
-
|
|
4
|
-
declare function HoloValidationErrorsProvider({ initial, children }: {
|
|
5
|
-
readonly initial?: string;
|
|
6
|
-
readonly children?: ReactNode;
|
|
7
|
-
}): ReactNode;
|
|
8
|
-
declare function useValidationErrors<TData = Record<string, unknown>>(bag?: string): ValidationErrorBag<TData>;
|
|
9
|
-
|
|
10
|
-
export { HoloValidationErrorsProvider, useValidationErrors };
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {
|
|
3
|
-
VALIDATION_FLASH_COOKIE,
|
|
4
|
-
parseValidationFlash,
|
|
5
|
-
validationFlashPage
|
|
6
|
-
} from "../chunk-7LOU63WN.mjs";
|
|
7
|
-
|
|
8
|
-
// src/validation-errors.ts
|
|
9
|
-
import { createContext, createElement, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
10
|
-
import { usePathname } from "next/navigation.js";
|
|
11
|
-
import { DEFAULT_VALIDATION_BAG, createErrorBag } from "@holo-js/validation";
|
|
12
|
-
var ValidationFlashContext = createContext(void 0);
|
|
13
|
-
function browserDocument() {
|
|
14
|
-
return globalThis.document;
|
|
15
|
-
}
|
|
16
|
-
function readFlashCookie() {
|
|
17
|
-
const prefix = `${VALIDATION_FLASH_COOKIE}=`;
|
|
18
|
-
const cookie = browserDocument()?.cookie.split(";").map((part) => part.trim()).find((part) => part.startsWith(prefix));
|
|
19
|
-
if (!cookie) return "";
|
|
20
|
-
try {
|
|
21
|
-
return decodeURIComponent(cookie.slice(prefix.length));
|
|
22
|
-
} catch {
|
|
23
|
-
return "";
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
function readableValidationFlash(value) {
|
|
27
|
-
const flash = parseValidationFlash(value);
|
|
28
|
-
if (!flash) return void 0;
|
|
29
|
-
try {
|
|
30
|
-
createErrorBag(flash.errors);
|
|
31
|
-
return flash;
|
|
32
|
-
} catch {
|
|
33
|
-
return void 0;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
function clearFlashCookie() {
|
|
37
|
-
const document = browserDocument();
|
|
38
|
-
if (document) document.cookie = `${VALIDATION_FLASH_COOKIE}=; Max-Age=0; Path=/; SameSite=Lax`;
|
|
39
|
-
}
|
|
40
|
-
function HoloValidationErrorsProvider({ initial = "", children }) {
|
|
41
|
-
const pathname = usePathname();
|
|
42
|
-
const [flash, setFlash] = useState(initial);
|
|
43
|
-
const mounted = useRef(false);
|
|
44
|
-
const shownPath = useRef(pathname);
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
if (!mounted.current) {
|
|
47
|
-
mounted.current = true;
|
|
48
|
-
if (!initial) clearFlashCookie();
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
if (shownPath.current !== pathname) {
|
|
52
|
-
shownPath.current = pathname;
|
|
53
|
-
clearFlashCookie();
|
|
54
|
-
}
|
|
55
|
-
setFlash(readFlashCookie());
|
|
56
|
-
});
|
|
57
|
-
const value = useMemo(() => readableValidationFlash(flash), [flash]);
|
|
58
|
-
return createElement(ValidationFlashContext.Provider, { value }, children);
|
|
59
|
-
}
|
|
60
|
-
function useValidationErrors(bag = DEFAULT_VALIDATION_BAG) {
|
|
61
|
-
const flash = useContext(ValidationFlashContext);
|
|
62
|
-
const pathname = usePathname();
|
|
63
|
-
return createErrorBag(flash?.bag === bag && flash.page === validationFlashPage(pathname) ? flash.errors : {});
|
|
64
|
-
}
|
|
65
|
-
export {
|
|
66
|
-
HoloValidationErrorsProvider,
|
|
67
|
-
useValidationErrors
|
|
68
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ReactNode, ReactElement } from 'react';
|
|
2
|
-
|
|
3
|
-
declare function validationErrorsLayout<TProps extends object>(layout: (props: TProps) => ReactNode | Promise<ReactNode>): (props: TProps) => ReactElement;
|
|
4
|
-
declare const adapterNextLayoutInternals: {
|
|
5
|
-
validationErrorsLayout: typeof validationErrorsLayout;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export { adapterNextLayoutInternals };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
renderedValidationFlash
|
|
3
|
-
} from "../chunk-ZPWXXNMV.mjs";
|
|
4
|
-
|
|
5
|
-
// src/validation-layout.ts
|
|
6
|
-
import { createElement } from "react";
|
|
7
|
-
import { workUnitAsyncStorage } from "next/dist/server/app-render/work-unit-async-storage.external.js";
|
|
8
|
-
import { HoloValidationErrorsProvider } from "@holo-js/adapter-next/internal/validation-errors";
|
|
9
|
-
function validationErrorsLayout(layout) {
|
|
10
|
-
return (props) => createElement(
|
|
11
|
-
HoloValidationErrorsProvider,
|
|
12
|
-
{ initial: renderedValidationFlash(workUnitAsyncStorage.getStore()) },
|
|
13
|
-
createElement(layout, props)
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
var adapterNextLayoutInternals = {
|
|
17
|
-
validationErrorsLayout
|
|
18
|
-
};
|
|
19
|
-
export {
|
|
20
|
-
adapterNextLayoutInternals
|
|
21
|
-
};
|
package/dist/layout-loader.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { NextModuleInputSourceMap } from '@holo-js/adapter-shared/build';
|
|
2
|
-
import { M as ModuleTransformLoaderContext } from './module-transform-loader-B5slbWAk.js';
|
|
3
|
-
|
|
4
|
-
type NextBundler = 'turbopack' | 'webpack';
|
|
5
|
-
type LayoutLoaderContext = ModuleTransformLoaderContext & {
|
|
6
|
-
readonly resourceQuery?: string;
|
|
7
|
-
readonly rootContext?: string;
|
|
8
|
-
addDependency?(file: string): void;
|
|
9
|
-
addMissingDependency?(file: string): void;
|
|
10
|
-
getOptions?(): {
|
|
11
|
-
readonly pageExtensions?: readonly string[];
|
|
12
|
-
readonly bundler?: NextBundler;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
declare function layoutLoader(this: LayoutLoaderContext, source: string, inputMap?: NextModuleInputSourceMap | null): string | undefined;
|
|
16
|
-
|
|
17
|
-
export { layoutLoader as default };
|
package/dist/layout-loader.mjs
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DEFAULT_PAGE_EXTENSIONS,
|
|
3
|
-
layoutFileNamePattern
|
|
4
|
-
} from "./chunk-2JUQOM3L.mjs";
|
|
5
|
-
import {
|
|
6
|
-
runModuleTransform
|
|
7
|
-
} from "./chunk-RFEFJPTI.mjs";
|
|
8
|
-
|
|
9
|
-
// src/layout-loader.ts
|
|
10
|
-
import { createHash } from "crypto";
|
|
11
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
12
|
-
import { basename, dirname, join, relative, sep } from "path";
|
|
13
|
-
import { transformNextRootLayout } from "@holo-js/adapter-shared/build";
|
|
14
|
-
var CLIENT_LAYOUT_QUERY = "?holo-client-layout";
|
|
15
|
-
function appDirectory(projectRoot) {
|
|
16
|
-
const rootAppDirectory = join(projectRoot, "app");
|
|
17
|
-
return existsSync(rootAppDirectory) ? rootAppDirectory : join(projectRoot, "src", "app");
|
|
18
|
-
}
|
|
19
|
-
function isInside(directory, parent) {
|
|
20
|
-
const path = relative(parent, directory);
|
|
21
|
-
return path === "" || !path.startsWith("..") && !path.startsWith(sep);
|
|
22
|
-
}
|
|
23
|
-
function hasLayout(directory, pageExtensions, dependencies) {
|
|
24
|
-
let found = false;
|
|
25
|
-
for (const extension of pageExtensions) {
|
|
26
|
-
const candidate = join(directory, `layout.${extension}`);
|
|
27
|
-
if (existsSync(candidate)) {
|
|
28
|
-
dependencies.existing(candidate);
|
|
29
|
-
found = true;
|
|
30
|
-
} else {
|
|
31
|
-
dependencies.missing(candidate);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return found;
|
|
35
|
-
}
|
|
36
|
-
function isRootLayout(file, projectRoot, pageExtensions, dependencies) {
|
|
37
|
-
const app = appDirectory(projectRoot);
|
|
38
|
-
if (!layoutFileNamePattern(pageExtensions).test(basename(file)) || !isInside(dirname(file), app)) return false;
|
|
39
|
-
for (let directory = dirname(dirname(file)); isInside(directory, app); directory = dirname(directory)) {
|
|
40
|
-
if (hasLayout(directory, pageExtensions, dependencies)) return false;
|
|
41
|
-
}
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
function writeClientLayoutEntry(layout, projectRoot) {
|
|
45
|
-
const name = createHash("sha256").update(relative(projectRoot, layout)).digest("hex").slice(0, 16);
|
|
46
|
-
const entry = join(projectRoot, ".holo-js", "generated", "next", "client-layouts", `${name}.tsx`);
|
|
47
|
-
const source = [`'use client'`, `export * from ${JSON.stringify(layout)}`, `export { default } from ${JSON.stringify(layout)}`, ""].join("\n");
|
|
48
|
-
if (!existsSync(entry) || readFileSync(entry, "utf8") !== source) {
|
|
49
|
-
mkdirSync(dirname(entry), { recursive: true });
|
|
50
|
-
writeFileSync(entry, source);
|
|
51
|
-
}
|
|
52
|
-
return entry;
|
|
53
|
-
}
|
|
54
|
-
function layoutLoader(source, inputMap) {
|
|
55
|
-
const options = this.getOptions?.();
|
|
56
|
-
const projectRoot = this.rootContext ?? process.cwd();
|
|
57
|
-
const dependencies = { existing: (file) => this.addDependency?.(file), missing: (file) => this.addMissingDependency?.(file) };
|
|
58
|
-
const wrapsLayout = this.resourceQuery !== CLIENT_LAYOUT_QUERY && isRootLayout(this.resourcePath, projectRoot, options?.pageExtensions ?? DEFAULT_PAGE_EXTENSIONS, dependencies);
|
|
59
|
-
const clientLayoutRequest = () => {
|
|
60
|
-
if (options?.bundler !== "webpack") return `./${basename(this.resourcePath)}${CLIENT_LAYOUT_QUERY}`;
|
|
61
|
-
const entry = writeClientLayoutEntry(this.resourcePath, projectRoot);
|
|
62
|
-
this.addDependency?.(entry);
|
|
63
|
-
return entry;
|
|
64
|
-
};
|
|
65
|
-
return runModuleTransform(this, (code, filename, map) => wrapsLayout ? transformNextRootLayout(code, filename, clientLayoutRequest, map) : void 0, source, inputMap);
|
|
66
|
-
}
|
|
67
|
-
export {
|
|
68
|
-
layoutLoader as default
|
|
69
|
-
};
|