@gtsx/adapter-next-react 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 tuoxiansp
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,8 @@
1
+ import { installGTSXNextDevIndicatorCleanup } from "./dev-indicator-cleanup.js";
2
+ export type GTSXNextDevIndicatorCleanupProps = {
3
+ pathPrefix?: string;
4
+ };
5
+ export declare function GTSXNextDevIndicatorCleanup(props: GTSXNextDevIndicatorCleanupProps): null;
6
+ export declare function ensureGTSXNextDevIndicatorCleanup(pathPrefix?: string): void;
7
+ export { installGTSXNextDevIndicatorCleanup };
8
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,kCAAkC,EAAE,MAAM,4BAA4B,CAAA;AAE/E,MAAM,MAAM,gCAAgC,GAAG;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAMD,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,gCAAgC,QAGlF;AAED,wBAAgB,iCAAiC,CAAC,UAAU,SAAU,GAAG,IAAI,CAK5E;AAED,OAAO,EAAE,kCAAkC,EAAE,CAAA"}
package/dist/client.js ADDED
@@ -0,0 +1,16 @@
1
+ "use client";
2
+ import { installGTSXNextDevIndicatorCleanup } from "./dev-indicator-cleanup.js";
3
+ const installedPathPrefixes = new Set();
4
+ ensureGTSXNextDevIndicatorCleanup();
5
+ export function GTSXNextDevIndicatorCleanup(props) {
6
+ ensureGTSXNextDevIndicatorCleanup(props.pathPrefix);
7
+ return null;
8
+ }
9
+ export function ensureGTSXNextDevIndicatorCleanup(pathPrefix = "/gtsx") {
10
+ if (installedPathPrefixes.has(pathPrefix))
11
+ return;
12
+ installedPathPrefixes.add(pathPrefix);
13
+ installGTSXNextDevIndicatorCleanup({ pathPrefix });
14
+ }
15
+ export { installGTSXNextDevIndicatorCleanup };
16
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,kCAAkC,EAAE,MAAM,4BAA4B,CAAA;AAM/E,MAAM,qBAAqB,GAAG,IAAI,GAAG,EAAU,CAAA;AAE/C,iCAAiC,EAAE,CAAA;AAEnC,MAAM,UAAU,2BAA2B,CAAC,KAAuC;IACjF,iCAAiC,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;IACnD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAM,UAAU,iCAAiC,CAAC,UAAU,GAAG,OAAO;IACpE,IAAI,qBAAqB,CAAC,GAAG,CAAC,UAAU,CAAC;QAAE,OAAM;IAEjD,qBAAqB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;IACrC,kCAAkC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAA;AACpD,CAAC;AAED,OAAO,EAAE,kCAAkC,EAAE,CAAA"}
@@ -0,0 +1,14 @@
1
+ export declare const nextDevIndicatorSelectors: readonly ["#devtools-indicator", "[data-nextjs-toast][id=\"devtools-indicator\"]", "#data-devtools-indicator", "#panel-route", "[data-nextjs-devtools]", "[data-nextjs-devtool]"];
2
+ export type GTSXNextDevIndicatorCleanupOptions = {
3
+ document?: Document;
4
+ location?: Pick<Location, "pathname">;
5
+ pathPrefix?: string;
6
+ };
7
+ export declare function installGTSXNextDevIndicatorCleanup(options?: GTSXNextDevIndicatorCleanupOptions): () => void;
8
+ export declare function isGTSXNextPreviewPath(pathname: string, pathPrefix?: string): boolean;
9
+ export declare function cleanupNextDevIndicator(documentValue: Document): void;
10
+ export declare function restoreNextDevIndicator(documentValue: Document): void;
11
+ export declare function syncNextDevIndicatorCleanup(documentValue: Document, options?: GTSXNextDevIndicatorCleanupOptions): void;
12
+ export declare function hideNextDevIndicatorInRoot(root: Document | ShadowRoot): boolean;
13
+ export declare function createNextDevIndicatorCleanupCss(): string;
14
+ //# sourceMappingURL=dev-indicator-cleanup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-indicator-cleanup.d.ts","sourceRoot":"","sources":["../src/dev-indicator-cleanup.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,yBAAyB,mLAO5B,CAAA;AAEV,MAAM,MAAM,kCAAkC,GAAG;IAC/C,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;IACrC,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,wBAAgB,kCAAkC,CAAC,OAAO,GAAE,kCAAuC,GAAG,MAAM,IAAI,CAe/G;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,SAAU,GAAG,OAAO,CAGrF;AAED,wBAAgB,uBAAuB,CAAC,aAAa,EAAE,QAAQ,GAAG,IAAI,CAQrE;AAED,wBAAgB,uBAAuB,CAAC,aAAa,EAAE,QAAQ,GAAG,IAAI,CAMrE;AAED,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,QAAQ,EACvB,OAAO,GAAE,kCAAuC,GAC/C,IAAI,CAQN;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,QAAQ,GAAG,UAAU,GAAG,OAAO,CAE/E;AAED,wBAAgB,gCAAgC,IAAI,MAAM,CAEzD"}
@@ -0,0 +1,89 @@
1
+ const cleanupStyleElementId = "gtsx-next-dev-indicator-cleanup";
2
+ export const nextDevIndicatorSelectors = [
3
+ "#devtools-indicator",
4
+ '[data-nextjs-toast][id="devtools-indicator"]',
5
+ "#data-devtools-indicator",
6
+ "#panel-route",
7
+ "[data-nextjs-devtools]",
8
+ "[data-nextjs-devtool]",
9
+ ];
10
+ export function installGTSXNextDevIndicatorCleanup(options = {}) {
11
+ const documentValue = options.document ?? globalThis.document;
12
+ if (!documentValue)
13
+ return () => { };
14
+ const syncCleanup = () => syncNextDevIndicatorCleanup(documentValue, options);
15
+ const observer = createCleanupMutationObserver(documentValue, syncCleanup);
16
+ const interval = globalThis.setInterval(syncCleanup, 250);
17
+ syncCleanup();
18
+ return () => {
19
+ observer?.disconnect();
20
+ globalThis.clearInterval(interval);
21
+ restoreNextDevIndicator(documentValue);
22
+ };
23
+ }
24
+ export function isGTSXNextPreviewPath(pathname, pathPrefix = "/gtsx") {
25
+ const normalizedPrefix = pathPrefix.endsWith("/") ? pathPrefix.slice(0, -1) : pathPrefix;
26
+ return pathname === normalizedPrefix || pathname.startsWith(`${normalizedPrefix}/`);
27
+ }
28
+ export function cleanupNextDevIndicator(documentValue) {
29
+ hideNextDevIndicatorInRoot(documentValue);
30
+ for (const portal of documentValue.querySelectorAll("nextjs-portal")) {
31
+ const shadowRoot = portal.shadowRoot;
32
+ if (!shadowRoot)
33
+ continue;
34
+ hideNextDevIndicatorInRoot(shadowRoot);
35
+ }
36
+ }
37
+ export function restoreNextDevIndicator(documentValue) {
38
+ removeDevIndicatorCleanupStyle(documentValue);
39
+ for (const portal of documentValue.querySelectorAll("nextjs-portal")) {
40
+ const shadowRoot = portal.shadowRoot;
41
+ if (shadowRoot)
42
+ removeDevIndicatorCleanupStyle(shadowRoot);
43
+ }
44
+ }
45
+ export function syncNextDevIndicatorCleanup(documentValue, options = {}) {
46
+ const locationValue = options.location ?? documentValue.defaultView?.location ?? globalThis.location;
47
+ if (isGTSXNextPreviewPath(locationValue?.pathname ?? "", options.pathPrefix)) {
48
+ cleanupNextDevIndicator(documentValue);
49
+ }
50
+ else {
51
+ restoreNextDevIndicator(documentValue);
52
+ }
53
+ }
54
+ export function hideNextDevIndicatorInRoot(root) {
55
+ return injectDevIndicatorCleanupStyle(root);
56
+ }
57
+ export function createNextDevIndicatorCleanupCss() {
58
+ return `${nextDevIndicatorSelectors.join(",")} { display: none !important; pointer-events: none !important; }`;
59
+ }
60
+ function injectDevIndicatorCleanupStyle(root) {
61
+ if (root.getElementById(cleanupStyleElementId))
62
+ return false;
63
+ const styleContainer = styleRootFor(root);
64
+ if (!styleContainer)
65
+ return false;
66
+ const ownerDocument = "createElement" in root ? root : root.ownerDocument;
67
+ const styleElement = ownerDocument.createElement("style");
68
+ styleElement.id = cleanupStyleElementId;
69
+ styleElement.textContent = createNextDevIndicatorCleanupCss();
70
+ styleContainer.appendChild(styleElement);
71
+ return true;
72
+ }
73
+ function removeDevIndicatorCleanupStyle(root) {
74
+ root.getElementById(cleanupStyleElementId)?.remove();
75
+ }
76
+ function styleRootFor(root) {
77
+ return "head" in root ? root.head : root;
78
+ }
79
+ function createCleanupMutationObserver(documentValue, cleanup) {
80
+ if (typeof MutationObserver === "undefined")
81
+ return undefined;
82
+ const observer = new MutationObserver(cleanup);
83
+ observer.observe(documentValue.documentElement, {
84
+ childList: true,
85
+ subtree: true,
86
+ });
87
+ return observer;
88
+ }
89
+ //# sourceMappingURL=dev-indicator-cleanup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-indicator-cleanup.js","sourceRoot":"","sources":["../src/dev-indicator-cleanup.ts"],"names":[],"mappings":"AAIA,MAAM,qBAAqB,GAAG,iCAAiC,CAAA;AAE/D,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,qBAAqB;IACrB,8CAA8C;IAC9C,0BAA0B;IAC1B,cAAc;IACd,wBAAwB;IACxB,uBAAuB;CACf,CAAA;AAQV,MAAM,UAAU,kCAAkC,CAAC,UAA8C,EAAE;IACjG,MAAM,aAAa,GAAG,OAAO,CAAC,QAAQ,IAAI,UAAU,CAAC,QAAQ,CAAA;IAC7D,IAAI,CAAC,aAAa;QAAE,OAAO,GAAG,EAAE,GAAE,CAAC,CAAA;IAEnC,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,2BAA2B,CAAC,aAAa,EAAE,OAAO,CAAC,CAAA;IAC7E,MAAM,QAAQ,GAAG,6BAA6B,CAAC,aAAa,EAAE,WAAW,CAAC,CAAA;IAC1E,MAAM,QAAQ,GAAG,UAAU,CAAC,WAAW,CAAC,WAAW,EAAE,GAAG,CAAC,CAAA;IAEzD,WAAW,EAAE,CAAA;IAEb,OAAO,GAAG,EAAE;QACV,QAAQ,EAAE,UAAU,EAAE,CAAA;QACtB,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;QAClC,uBAAuB,CAAC,aAAa,CAAC,CAAA;IACxC,CAAC,CAAA;AACH,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,QAAgB,EAAE,UAAU,GAAG,OAAO;IAC1E,MAAM,gBAAgB,GAAG,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CA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@ -0,0 +1,21 @@
1
+ import type { GTSXConfig } from "@gtsx/core";
2
+ type NextWebpackConfig = (config: any, context: any) => any;
3
+ type NextConfigLike = {
4
+ webpack?: NextWebpackConfig | null;
5
+ turbopack?: any;
6
+ [key: string]: any;
7
+ };
8
+ type GTSXNextReactOptions = {
9
+ config?: GTSXConfig;
10
+ previewEntries?: false | GTSXNextPreviewEntriesOptions;
11
+ projectRoot?: string;
12
+ root?: string;
13
+ };
14
+ type GTSXNextPreviewEntriesOptions = {
15
+ moduleId?: string;
16
+ outputFile?: string;
17
+ projectRoot?: string;
18
+ };
19
+ export declare function gtsxNextReact(options?: GTSXNextReactOptions): <Config extends NextConfigLike>(nextConfig?: Config) => Config & NextConfigLike;
20
+ export {};
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAmB5C,KAAK,iBAAiB,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,KAAK,GAAG,CAAA;AAS3D,KAAK,cAAc,GAAG;IACpB,OAAO,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAA;IAClC,SAAS,CAAC,EAAE,GAAG,CAAA;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB,CAAA;AAED,KAAK,oBAAoB,GAAG;IAC1B,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,cAAc,CAAC,EAAE,KAAK,GAAG,6BAA6B,CAAA;IACtD,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAED,KAAK,6BAA6B,GAAG;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAYD,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,IAM5B,MAAM,SAAS,cAAc,EAAE,aAAY,MAAqB,KAAG,MAAM,GAAG,cAAc,CAgC7H"}
package/dist/index.js ADDED
@@ -0,0 +1,159 @@
1
+ import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import { dirname, relative, resolve, sep } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { resolveGTSXConfig } from "@gtsx/core/config-model";
6
+ const defaultPreviewEntriesModuleId = "@gtsx/adapter-next-react/preview-entries";
7
+ const defaultPreviewEntriesOutputFile = ".gtsx/preview-entries.ts";
8
+ const ignoredPreviewEntryDirs = new Set(["node_modules", "dist", ".next", ".git", ".gtsx"]);
9
+ export function gtsxNextReact(options = {}) {
10
+ const root = options.root ?? process.cwd();
11
+ const loaderPath = resolve(dirname(fileURLToPath(import.meta.url)), "../loader.cjs");
12
+ const transformPath = resolveGTSXReactTransform(root);
13
+ const previewEntries = resolvePreviewEntriesOptions(root, options);
14
+ return function withGTSXNextReact(nextConfig = {}) {
15
+ const userWebpack = nextConfig.webpack;
16
+ writeGTSXNextPreviewEntries(root, previewEntries);
17
+ return {
18
+ ...nextConfig,
19
+ webpack(config, context) {
20
+ writeGTSXNextPreviewEntries(root, previewEntries);
21
+ const resolvedConfig = (typeof userWebpack === "function" ? userWebpack(config, context) : config);
22
+ resolvedConfig.module ??= {};
23
+ resolvedConfig.module.rules ??= [];
24
+ resolvedConfig.resolve ??= {};
25
+ resolvedConfig.resolve.alias = {
26
+ ...(resolvedConfig.resolve.alias ?? {}),
27
+ ...(previewEntries ? { [previewEntries.moduleId]: previewEntries.outputPath } : {}),
28
+ };
29
+ resolvedConfig.module.rules.unshift({
30
+ test: /\.g\.tsx$/,
31
+ enforce: "pre",
32
+ use: [{ loader: loaderPath, options: { root, transformPath } }],
33
+ });
34
+ return resolvedConfig;
35
+ },
36
+ turbopack: withGTSXTurbopackConfig(nextConfig.turbopack, loaderPath, root, transformPath, previewEntries),
37
+ };
38
+ };
39
+ }
40
+ function withGTSXTurbopackConfig(turbopack, loaderPath, root, transformPath, previewEntries) {
41
+ const gtsxRule = {
42
+ loaders: [{ loader: loaderPath, options: { root, transformPath } }],
43
+ as: "*.tsx",
44
+ };
45
+ const rules = turbopack?.rules ?? {};
46
+ return {
47
+ ...turbopack,
48
+ resolveAlias: {
49
+ ...(turbopack?.resolveAlias ?? {}),
50
+ ...(previewEntries ? { [previewEntries.moduleId]: toTurbopackResolveAliasPath(root, previewEntries.outputPath) } : {}),
51
+ },
52
+ rules: {
53
+ ...rules,
54
+ "*.g.tsx": prependRule(gtsxRule, rules["*.g.tsx"]),
55
+ },
56
+ };
57
+ }
58
+ function prependRule(rule, existing) {
59
+ if (!existing)
60
+ return rule;
61
+ return Array.isArray(existing) ? [rule, ...existing] : [rule, existing];
62
+ }
63
+ function resolveGTSXReactTransform(root) {
64
+ return createRequire(import.meta.url).resolve("@gtsx/core/react-transform", {
65
+ paths: [root, process.cwd()],
66
+ });
67
+ }
68
+ function resolvePreviewEntriesOptions(root, options) {
69
+ if (options.previewEntries === false)
70
+ return undefined;
71
+ const previewEntries = typeof options.previewEntries === "object" ? options.previewEntries : {};
72
+ const resolvedConfig = options.config ? resolveGTSXConfig(options.config) : undefined;
73
+ return {
74
+ moduleId: previewEntries.moduleId ?? defaultPreviewEntriesModuleId,
75
+ outputPath: resolve(root, previewEntries.outputFile ?? defaultPreviewEntriesOutputFile),
76
+ projectRoot: previewEntries.projectRoot ?? options.projectRoot ?? resolvedConfig?.project.root ?? "src",
77
+ };
78
+ }
79
+ function writeGTSXNextPreviewEntries(root, options) {
80
+ if (!options || !existsSync(root))
81
+ return;
82
+ const files = discoverGTSXPreviewFiles(root, options.projectRoot);
83
+ const code = createGTSXNextPreviewEntriesModule(root, options.outputPath, files);
84
+ const current = readFileIfExists(options.outputPath);
85
+ if (current === code)
86
+ return;
87
+ mkdirSync(dirname(options.outputPath), { recursive: true });
88
+ writeFileSync(options.outputPath, code);
89
+ }
90
+ function discoverGTSXPreviewFiles(root, projectRoot) {
91
+ const directory = resolve(root, projectRoot);
92
+ if (!existsSync(directory))
93
+ return [];
94
+ const files = [];
95
+ walk(directory);
96
+ return files.map((filePath) => relative(root, filePath).split(sep).join("/")).sort((left, right) => left.localeCompare(right));
97
+ function walk(currentDirectory) {
98
+ for (const dirent of readdirSync(currentDirectory, { withFileTypes: true })) {
99
+ if (dirent.isDirectory()) {
100
+ if (!ignoredPreviewEntryDirs.has(dirent.name)) {
101
+ walk(resolve(currentDirectory, dirent.name));
102
+ }
103
+ continue;
104
+ }
105
+ if (dirent.isFile() && dirent.name.endsWith(".g.tsx")) {
106
+ files.push(resolve(currentDirectory, dirent.name));
107
+ }
108
+ }
109
+ }
110
+ }
111
+ function createGTSXNextPreviewEntriesModule(root, outputPath, files) {
112
+ const entries = files.map((filePath) => {
113
+ const absoluteFilePath = resolve(root, filePath);
114
+ return ` ${JSON.stringify(filePath)}: () => import(${JSON.stringify(toGeneratedImportSpecifier(outputPath, absoluteFilePath))}),`;
115
+ });
116
+ return `import type { GTSXPreviewComponent } from "@gtsx/adapter-next-react/preview"
117
+
118
+ export type GTSXPreviewModule = Record<string, unknown>
119
+ export type GTSXPreviewEntryLoader = () => Promise<GTSXPreviewModule>
120
+ export type GTSXPreviewEntryLoaders = Record<string, GTSXPreviewEntryLoader>
121
+
122
+ export const gtsxPreviewEntryLoaders = {
123
+ ${entries.join("\n")}
124
+ } satisfies GTSXPreviewEntryLoaders
125
+
126
+ export async function loadGTSXPreviewComponent(entry: string): Promise<GTSXPreviewComponent | undefined> {
127
+ const { file, exportName } = parseGTSXPreviewEntry(entry)
128
+ const loader = (gtsxPreviewEntryLoaders as GTSXPreviewEntryLoaders)[file]
129
+ if (!loader) return undefined
130
+
131
+ const moduleValue = await loader()
132
+ const component = moduleValue[exportName]
133
+ return typeof component === "function" ? (component as GTSXPreviewComponent) : undefined
134
+ }
135
+
136
+ export function parseGTSXPreviewEntry(entry: string): { file: string; exportName: string } {
137
+ const [file, exportName] = entry.split("#", 2)
138
+ return { file, exportName: exportName || "default" }
139
+ }
140
+ `;
141
+ }
142
+ function toGeneratedImportSpecifier(outputPath, absoluteFilePath) {
143
+ const extensionless = absoluteFilePath.replace(/\.tsx$/, "");
144
+ const relativePath = relative(dirname(outputPath), extensionless).split(sep).join("/");
145
+ return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
146
+ }
147
+ function toTurbopackResolveAliasPath(root, outputPath) {
148
+ const relativePath = relative(root, outputPath).split(sep).join("/");
149
+ return relativePath.startsWith("./") || relativePath.startsWith("../") ? relativePath : `./${relativePath}`;
150
+ }
151
+ function readFileIfExists(path) {
152
+ try {
153
+ return readFileSync(path, "utf8");
154
+ }
155
+ catch {
156
+ return undefined;
157
+ }
158
+ }
159
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACzF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAsD3D,MAAM,6BAA6B,GAAG,0CAA0C,CAAA;AAChF,MAAM,+BAA+B,GAAG,0BAA0B,CAAA;AAClE,MAAM,uBAAuB,GAAG,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;AAE3F,MAAM,UAAU,aAAa,CAAC,UAAgC,EAAE;IA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CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACpE,OAAO,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,YAAY,EAAE,CAAA;AAC7G,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAY;IACpC,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { GTSXPreviewComponent } from "@gtsx/preview-react";
2
+ export type GTSXPreviewModule = Record<string, unknown>;
3
+ export type GTSXPreviewEntryLoader = () => Promise<GTSXPreviewModule>;
4
+ export type GTSXPreviewEntryLoaders = Record<string, GTSXPreviewEntryLoader>;
5
+ export declare const gtsxPreviewEntryLoaders: {};
6
+ export declare function loadGTSXPreviewComponent(_entry: string): Promise<GTSXPreviewComponent | undefined>;
7
+ export declare function parseGTSXPreviewEntry(entry: string): {
8
+ file: string;
9
+ exportName: string;
10
+ };
11
+ //# sourceMappingURL=preview-entries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview-entries.d.ts","sourceRoot":"","sources":["../src/preview-entries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAE/D,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AACvD,MAAM,MAAM,sBAAsB,GAAG,MAAM,OAAO,CAAC,iBAAiB,CAAC,CAAA;AACrE,MAAM,MAAM,uBAAuB,GAAG,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAA;AAE5E,eAAO,MAAM,uBAAuB,IAAuC,CAAA;AAE3E,wBAAsB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAExG;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAGzF"}
@@ -0,0 +1,9 @@
1
+ export const gtsxPreviewEntryLoaders = {};
2
+ export async function loadGTSXPreviewComponent(_entry) {
3
+ return undefined;
4
+ }
5
+ export function parseGTSXPreviewEntry(entry) {
6
+ const [file, exportName] = entry.split("#", 2);
7
+ return { file, exportName: exportName || "default" };
8
+ }
9
+ //# sourceMappingURL=preview-entries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview-entries.js","sourceRoot":"","sources":["../src/preview-entries.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAoC,CAAA;AAE3E,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,MAAc;IAC3D,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,KAAa;IACjD,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;IAC9C,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,IAAI,SAAS,EAAE,CAAA;AACtD,CAAC"}
@@ -0,0 +1,29 @@
1
+ export type GTSXNextPreviewSearchParams = Record<string, string | string[] | undefined> | URLSearchParams | undefined;
2
+ export type GTSXNextPreviewRouteProps = {
3
+ caseName?: string | null;
4
+ caseOverrides?: Map<string, string>;
5
+ chrome?: string | null;
6
+ entry?: string | null;
7
+ pool?: string | null;
8
+ sessionId?: string | null;
9
+ staticMode?: boolean;
10
+ };
11
+ export type GTSXNextPreviewSsrScriptProps = {
12
+ dangerouslySetInnerHTML: {
13
+ __html: string;
14
+ };
15
+ id: string;
16
+ strategy: "beforeInteractive";
17
+ };
18
+ /** @deprecated Use gtsxPreviewSsrBootstrapScriptId from gtsx/preview-protocol. */
19
+ export declare const gtsxNextPreviewPoolMailboxScriptId = "gtsx-preview-ssr-bootstrap";
20
+ /** @deprecated Use GTSX_PREVIEW_SSR_BOOTSTRAP_SCRIPT from gtsx/preview-protocol. */
21
+ export declare const GTSX_NEXT_PREVIEW_POOL_MAILBOX_SCRIPT = "(() => {\n if (window.__gtsxPreviewPrehydrationMailboxInstalled) return;\n window.__gtsxPreviewPrehydrationMailboxInstalled = true;\n const render = (target) => {\n window.__gtsxPreviewPendingRenderTarget = target;\n if (target && target.sessionId) {\n window.parent.postMessage({ type: \"gtsx:render-accepted\", protocolVersion: 1, sessionId: target.sessionId }, \"*\");\n }\n window.dispatchEvent(new CustomEvent(\"gtsx:preview-render-target\", { detail: target }));\n };\n window.__gtsxPreviewRenderTargetMailbox = { render };\n window.addEventListener(\"message\", (event) => {\n const message = event.data;\n if (!message || message.type !== \"gtsx:render\" || message.protocolVersion !== 1 || !message.target) return;\n render(message.target);\n });\n window.setTimeout(() => {\n window.parent.postMessage({ type: \"gtsx:pool-ready\", protocolVersion: 1 }, \"*\");\n }, 0);\n})();";
22
+ export declare function readGTSXNextPreviewProps(searchParams: GTSXNextPreviewSearchParams): GTSXNextPreviewRouteProps;
23
+ export declare function createGTSXNextPreviewSsrScripts(routeProps: Pick<GTSXNextPreviewRouteProps, "pool">): GTSXNextPreviewSsrScriptProps[];
24
+ export declare function shouldInstallGTSXNextPreviewSsrScripts(routeProps: Pick<GTSXNextPreviewRouteProps, "pool">): boolean;
25
+ /** @deprecated Use createGTSXNextPreviewSsrScripts. */
26
+ export declare function createGTSXNextPreviewPoolMailboxScriptProps(): GTSXNextPreviewSsrScriptProps;
27
+ /** @deprecated Use shouldInstallGTSXNextPreviewSsrScripts. */
28
+ export declare function shouldInstallGTSXNextPreviewPoolMailbox(routeProps: Pick<GTSXNextPreviewRouteProps, "pool">): boolean;
29
+ //# sourceMapp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AA6B,CAE3F;AAED,8DAA8D;AAC9D,wBAAgB,uCAAuC,CAAC,UAAU,EAAE,IAAI,CAAC,yBAAyB,EAAE,MAAM,CAAC,GAAG,OAAO,CAEpH"}
@@ -0,0 +1,66 @@
1
+ import { GTSX_PREVIEW_SSR_BOOTSTRAP_SCRIPT, gtsxPreviewSsrBootstrapScriptId } from "@gtsx/core/preview-protocol";
2
+ /** @deprecated Use gtsxPreviewSsrBootstrapScriptId from gtsx/preview-protocol. */
3
+ export const gtsxNextPreviewPoolMailboxScriptId = gtsxPreviewSsrBootstrapScriptId;
4
+ /** @deprecated Use GTSX_PREVIEW_SSR_BOOTSTRAP_SCRIPT from gtsx/preview-protocol. */
5
+ export const GTSX_NEXT_PREVIEW_POOL_MAILBOX_SCRIPT = GTSX_PREVIEW_SSR_BOOTSTRAP_SCRIPT;
6
+ export function readGTSXNextPreviewProps(searchParams) {
7
+ const params = searchParams instanceof URLSearchParams ? searchParams : searchParamsFromNextRecord(searchParams);
8
+ return {
9
+ caseName: params.get("case"),
10
+ caseOverrides: readGTSXPreviewCaseOverrides(params),
11
+ chrome: params.get("chrome"),
12
+ entry: params.get("entry"),
13
+ pool: params.get("pool"),
14
+ sessionId: params.get("sessionId"),
15
+ staticMode: params.get("static") === "1",
16
+ };
17
+ }
18
+ export function createGTSXNextPreviewSsrScripts(routeProps) {
19
+ if (!shouldInstallGTSXNextPreviewSsrScripts(routeProps))
20
+ return [];
21
+ return [createGTSXNextPreviewSsrBootstrapScript()];
22
+ }
23
+ export function shouldInstallGTSXNextPreviewSsrScripts(routeProps) {
24
+ return routeProps.pool === "1";
25
+ }
26
+ function createGTSXNextPreviewSsrBootstrapScript() {
27
+ return {
28
+ dangerouslySetInnerHTML: {
29
+ __html: GTSX_PREVIEW_SSR_BOOTSTRAP_SCRIPT,
30
+ },
31
+ id: gtsxPreviewSsrBootstrapScriptId,
32
+ strategy: "beforeInteractive",
33
+ };
34
+ }
35
+ /** @deprecated Use createGTSXNextPreviewSsrScripts. */
36
+ export function createGTSXNextPreviewPoolMailboxScriptProps() {
37
+ return createGTSXNextPreviewSsrBootstrapScript();
38
+ }
39
+ /** @deprecated Use shouldInstallGTSXNextPreviewSsrScripts. */
40
+ export function shouldInstallGTSXNextPreviewPoolMailbox(routeProps) {
41
+ return shouldInstallGTSXNextPreviewSsrScripts(routeProps);
42
+ }
43
+ function searchParamsFromNextRecord(searchParams) {
44
+ const params = new URLSearchParams();
45
+ for (const [key, value] of Object.entries(searchParams ?? {})) {
46
+ if (Array.isArray(value)) {
47
+ for (const item of value)
48
+ params.append(key, item);
49
+ }
50
+ else if (value !== undefined) {
51
+ params.set(key, value);
52
+ }
53
+ }
54
+ return params;
55
+ }
56
+ function readGTSXPreviewCaseOverrides(params) {
57
+ const overrides = new Map();
58
+ for (const value of params.getAll("gcase")) {
59
+ const separatorIndex = value.lastIndexOf(":");
60
+ if (separatorIndex > 0) {
61
+ overrides.set(value.slice(0, separatorIndex), value.slice(separatorIndex + 1));
62
+ }
63
+ }
64
+ return overrides;
65
+ }
66
+ //# sourceMappingURL=preview-route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview-route.js","sourceRoot":"","sources":["../src/preview-route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,+BAA+B,EAAE,MAAM,6BAA6B,CAAA;AAoBhH,kFAAkF;AAClF,MAAM,CAAC,MAAM,kCAAkC,GAAG,+BAA+B,CAAA;AAEjF,oFAAoF;AACpF,MAAM,CAAC,MAAM,qCAAqC,GAAG,iCAAiC,CAAA;AAEtF,MAAM,UAAU,wBAAwB,CAAC,YAAyC;IAChF,MAAM,MAAM,GAAG,YAAY,YAAY,eAAe,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,0BAA0B,CAAC,YAAY,CAAC,CAAA;IAEhH,OAAO;QACL,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC;QAC5B,aAAa,EAAE,4BAA4B,CAAC,MAAM,CA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AAE,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;QACpD,CAAC;aAAM,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YAC/B,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QACxB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAED,SAAS,4BAA4B,CAAC,MAAuB;IAC3D,MAAM,SAAS,GAAG,IAAI,GAAG,EAAkB,CAAA;IAC3C,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3C,MAAM,cAAc,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;QAC7C,IAAI,cAAc,GAAG,CAAC,EAAE,CAAC;YACvB,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC,CAAA;QAChF,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { type GTSXReactPreviewClientProps } from "@gtsx/preview-react";
2
+ export type { GTSXPreviewCase, GTSXPreviewComponent, GTSXPreviewModule } from "@gtsx/preview-react";
3
+ export type GTSXNextPreviewClientProps = Omit<GTSXReactPreviewClientProps, "loadComponent">;
4
+ export declare function GTSXNextPreviewClient(props: GTSXNextPreviewClientProps): import("react/jsx-runtime").JSX.Element;
5
+ //# sourceMappingURL=preview.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../src/preview.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA0B,KAAK,2BAA2B,EAAE,MAAM,qBAAqB,CAAA;AAG9F,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAEnG,MAAM,MAAM,0BAA0B,GAAG,IAAI,CAAC,2BAA2B,EAAE,eAAe,CAAC,CAAA;AAE3F,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,0BAA0B,2CAEtE"}
@@ -0,0 +1,8 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { GTSXReactPreviewClient } from "@gtsx/preview-react";
4
+ import { loadGTSXPreviewComponent } from "@gtsx/adapter-next-react/preview-entries";
5
+ export function GTSXNextPreviewClient(props) {
6
+ return _jsx(GTSXReactPreviewClient, { ...props, loadComponent: loadGTSXPreviewComponent });
7
+ }
8
+ //# sourceMappingURL=preview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview.js","sourceRoot":"","sources":["../src/preview.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EAAE,sBAAsB,EAAoC,MAAM,qBAAqB,CAAA;AAC9F,OAAO,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAA;AAMnF,MAAM,UAAU,qBAAqB,CAAC,KAAiC;IACrE,OAAO,KAAC,sBAAsB,OAAK,KAAK,EAAE,aAAa,EAAE,wBAAwB,GAAI,CAAA;AACvF,CAAC"}
package/index.cjs ADDED
@@ -0,0 +1,179 @@
1
+ "use strict"
2
+
3
+ const { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } = require("node:fs")
4
+ const { dirname, relative, resolve, sep } = require("node:path")
5
+
6
+ const defaultPreviewEntriesModuleId = "@gtsx/adapter-next-react/preview-entries"
7
+ const defaultPreviewEntriesOutputFile = ".gtsx/preview-entries.ts"
8
+ const ignoredPreviewEntryDirs = new Set(["node_modules", "dist", ".next", ".git", ".gtsx"])
9
+
10
+ function gtsxNextReact(options = {}) {
11
+ const root = options.root ?? process.cwd()
12
+ const loaderPath = resolve(__dirname, "loader.cjs")
13
+ const transformPath = require.resolve("@gtsx/core/react-transform", {
14
+ paths: [root, process.cwd()],
15
+ })
16
+ const previewEntries = resolvePreviewEntriesOptions(root, options)
17
+
18
+ return function withGTSXNextReact(nextConfig = {}) {
19
+ const userWebpack = nextConfig.webpack
20
+ writeGTSXNextPreviewEntries(root, previewEntries)
21
+
22
+ return {
23
+ ...nextConfig,
24
+ webpack(config, context) {
25
+ writeGTSXNextPreviewEntries(root, previewEntries)
26
+ const resolvedConfig = typeof userWebpack === "function" ? userWebpack(config, context) : config
27
+ resolvedConfig.module ??= {}
28
+ resolvedConfig.module.rules ??= []
29
+ resolvedConfig.resolve ??= {}
30
+ resolvedConfig.resolve.alias = {
31
+ ...(resolvedConfig.resolve.alias ?? {}),
32
+ ...(previewEntries ? { [previewEntries.moduleId]: previewEntries.outputPath } : {}),
33
+ }
34
+ resolvedConfig.module.rules.unshift({
35
+ test: /\.g\.tsx$/,
36
+ enforce: "pre",
37
+ use: [{ loader: loaderPath, options: { root, transformPath } }],
38
+ })
39
+ return resolvedConfig
40
+ },
41
+ turbopack: withGTSXTurbopackConfig(
42
+ nextConfig.turbopack,
43
+ loaderPath,
44
+ root,
45
+ transformPath,
46
+ previewEntries,
47
+ ),
48
+ }
49
+ }
50
+ }
51
+
52
+ function withGTSXTurbopackConfig(turbopack, loaderPath, root, transformPath, previewEntries) {
53
+ const gtsxRule = {
54
+ loaders: [{ loader: loaderPath, options: { root, transformPath } }],
55
+ as: "*.tsx",
56
+ }
57
+ const rules = turbopack?.rules ?? {}
58
+
59
+ return {
60
+ ...turbopack,
61
+ resolveAlias: {
62
+ ...(turbopack?.resolveAlias ?? {}),
63
+ ...(previewEntries ? { [previewEntries.moduleId]: toTurbopackResolveAliasPath(root, previewEntries.outputPath) } : {}),
64
+ },
65
+ rules: {
66
+ ...rules,
67
+ "*.g.tsx": prependRule(gtsxRule, rules["*.g.tsx"]),
68
+ },
69
+ }
70
+ }
71
+
72
+ function prependRule(rule, existing) {
73
+ if (!existing) return rule
74
+ return Array.isArray(existing) ? [rule, ...existing] : [rule, existing]
75
+ }
76
+
77
+ function resolvePreviewEntriesOptions(root, options) {
78
+ if (options.previewEntries === false) return undefined
79
+
80
+ const previewEntries = typeof options.previewEntries === "object" ? options.previewEntries : {}
81
+ const configuredProjectRoot = options.config?.project?.root
82
+ return {
83
+ moduleId: previewEntries.moduleId ?? defaultPreviewEntriesModuleId,
84
+ outputPath: resolve(root, previewEntries.outputFile ?? defaultPreviewEntriesOutputFile),
85
+ projectRoot: previewEntries.projectRoot ?? options.projectRoot ?? configuredProjectRoot ?? "src",
86
+ }
87
+ }
88
+
89
+ function writeGTSXNextPreviewEntries(root, options) {
90
+ if (!options || !existsSync(root)) return
91
+
92
+ const files = discoverGTSXPreviewFiles(root, options.projectRoot)
93
+ const code = createGTSXNextPreviewEntriesModule(root, options.outputPath, files)
94
+ const current = readFileIfExists(options.outputPath)
95
+ if (current === code) return
96
+
97
+ mkdirSync(dirname(options.outputPath), { recursive: true })
98
+ writeFileSync(options.outputPath, code)
99
+ }
100
+
101
+ function discoverGTSXPreviewFiles(root, projectRoot) {
102
+ const directory = resolve(root, projectRoot)
103
+ if (!existsSync(directory)) return []
104
+
105
+ const files = []
106
+ walk(directory)
107
+ return files.map((filePath) => relative(root, filePath).split(sep).join("/")).sort((left, right) => left.localeCompare(right))
108
+
109
+ function walk(currentDirectory) {
110
+ for (const dirent of readdirSync(currentDirectory, { withFileTypes: true })) {
111
+ if (dirent.isDirectory()) {
112
+ if (!ignoredPreviewEntryDirs.has(dirent.name)) {
113
+ walk(resolve(currentDirectory, dirent.name))
114
+ }
115
+ continue
116
+ }
117
+
118
+ if (dirent.isFile() && dirent.name.endsWith(".g.tsx")) {
119
+ files.push(resolve(currentDirectory, dirent.name))
120
+ }
121
+ }
122
+ }
123
+ }
124
+
125
+ function createGTSXNextPreviewEntriesModule(root, outputPath, files) {
126
+ const entries = files.map((filePath) => {
127
+ const absoluteFilePath = resolve(root, filePath)
128
+ return ` ${JSON.stringify(filePath)}: () => import(${JSON.stringify(toGeneratedImportSpecifier(outputPath, absoluteFilePath))}),`
129
+ })
130
+
131
+ return `import type { GTSXPreviewComponent } from "@gtsx/adapter-next-react/preview"
132
+
133
+ export type GTSXPreviewModule = Record<string, unknown>
134
+ export type GTSXPreviewEntryLoader = () => Promise<GTSXPreviewModule>
135
+ export type GTSXPreviewEntryLoaders = Record<string, GTSXPreviewEntryLoader>
136
+
137
+ export const gtsxPreviewEntryLoaders = {
138
+ ${entries.join("\n")}
139
+ } satisfies GTSXPreviewEntryLoaders
140
+
141
+ export async function loadGTSXPreviewComponent(entry: string): Promise<GTSXPreviewComponent | undefined> {
142
+ const { file, exportName } = parseGTSXPreviewEntry(entry)
143
+ const loader = (gtsxPreviewEntryLoaders as GTSXPreviewEntryLoaders)[file]
144
+ if (!loader) return undefined
145
+
146
+ const moduleValue = await loader()
147
+ const component = moduleValue[exportName]
148
+ return typeof component === "function" ? (component as GTSXPreviewComponent) : undefined
149
+ }
150
+
151
+ export function parseGTSXPreviewEntry(entry: string): { file: string; exportName: string } {
152
+ const [file, exportName] = entry.split("#", 2)
153
+ return { file, exportName: exportName || "default" }
154
+ }
155
+ `
156
+ }
157
+
158
+ function toGeneratedImportSpecifier(outputPath, absoluteFilePath) {
159
+ const extensionless = absoluteFilePath.replace(/\.tsx$/, "")
160
+ const relativePath = relative(dirname(outputPath), extensionless).split(sep).join("/")
161
+ return relativePath.startsWith(".") ? relativePath : `./${relativePath}`
162
+ }
163
+
164
+ function toTurbopackResolveAliasPath(root, outputPath) {
165
+ const relativePath = relative(root, outputPath).split(sep).join("/")
166
+ return relativePath.startsWith("./") || relativePath.startsWith("../") ? relativePath : `./${relativePath}`
167
+ }
168
+
169
+ function readFileIfExists(path) {
170
+ try {
171
+ return readFileSync(path, "utf8")
172
+ } catch {
173
+ return undefined
174
+ }
175
+ }
176
+
177
+ module.exports = {
178
+ gtsxNextReact,
179
+ }
package/loader.cjs ADDED
@@ -0,0 +1,38 @@
1
+ "use strict"
2
+
3
+ const { pathToFileURL } = require("node:url")
4
+
5
+ module.exports = function gtsxNextReactLoader(source, inputSourceMap) {
6
+ const callback = this.async()
7
+ const options = readLoaderOptions(this)
8
+ const root = typeof options.root === "string" ? options.root : process.cwd()
9
+ const transformModule = typeof options.transformPath === "string" ? pathToFileURL(options.transformPath).href : "@gtsx/core/react-transform"
10
+ const filePath = this.resourcePath
11
+ const code = Buffer.isBuffer(source) ? source.toString("utf8") : String(source)
12
+
13
+ import(transformModule).then(
14
+ ({ transformGTSXReactModule }) => {
15
+ const transformed = transformGTSXReactModule({
16
+ code,
17
+ filePath,
18
+ root,
19
+ })
20
+ callback(null, transformed?.code ?? code, inputSourceMap)
21
+ },
22
+ (error) => {
23
+ callback(error)
24
+ },
25
+ )
26
+ }
27
+
28
+ function readLoaderOptions(context) {
29
+ if (typeof context.getOptions === "function") {
30
+ return context.getOptions() ?? {}
31
+ }
32
+
33
+ if (!context.query || typeof context.query !== "object") {
34
+ return {}
35
+ }
36
+
37
+ return context.query
38
+ }
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@gtsx/adapter-next-react",
3
+ "version": "0.0.1",
4
+ "description": "Next.js React adapter for GTSX component preview integration.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/tuoxiansp/gtsx.git",
10
+ "directory": "packages/adapter-next-react"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/tuoxiansp/gtsx/issues"
14
+ },
15
+ "homepage": "https://github.com/tuoxiansp/gtsx#readme",
16
+ "keywords": [
17
+ "gtsx",
18
+ "nextjs",
19
+ "react",
20
+ "component-preview"
21
+ ],
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js",
29
+ "require": "./index.cjs",
30
+ "default": "./dist/index.js"
31
+ },
32
+ "./client": {
33
+ "types": "./dist/client.d.ts",
34
+ "import": "./dist/client.js",
35
+ "default": "./dist/client.js"
36
+ },
37
+ "./preview-entries": {
38
+ "types": "./dist/preview-entries.d.ts",
39
+ "import": "./dist/preview-entries.js",
40
+ "default": "./dist/preview-entries.js"
41
+ },
42
+ "./preview": {
43
+ "types": "./dist/preview.d.ts",
44
+ "import": "./dist/preview.js",
45
+ "default": "./dist/preview.js"
46
+ },
47
+ "./preview-route": {
48
+ "types": "./dist/preview-route.d.ts",
49
+ "import": "./dist/preview-route.js",
50
+ "default": "./dist/preview-route.js"
51
+ },
52
+ "./loader": "./loader.cjs"
53
+ },
54
+ "files": [
55
+ "dist",
56
+ "index.cjs",
57
+ "loader.cjs"
58
+ ],
59
+ "dependencies": {
60
+ "@gtsx/preview-react": "0.0.1"
61
+ },
62
+ "peerDependencies": {
63
+ "next": ">=13",
64
+ "react": ">=18",
65
+ "@gtsx/core": "0.0.1"
66
+ },
67
+ "scripts": {
68
+ "build": "tsc -p tsconfig.build.json",
69
+ "test": "vitest run",
70
+ "typecheck": "tsc -p tsconfig.json --noEmit"
71
+ }
72
+ }