@gtsx/adapter-vite-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,30 @@
1
+ import type { GTSXConfig } from "@gtsx/core";
2
+ export { transformGTSXComponentBoundaries, transformGTSXReactModule } from "@gtsx/core/react-transform";
3
+ type ViteLikeConfig = {
4
+ root: string;
5
+ };
6
+ type TransformResult = {
7
+ code: string;
8
+ map: null;
9
+ };
10
+ type GTSXViteReactOptions = {
11
+ config?: GTSXConfig;
12
+ projectRoot?: string;
13
+ root?: string;
14
+ tsconfigPath?: string;
15
+ };
16
+ export declare function gtsxViteReact(options?: GTSXViteReactOptions): {
17
+ name: string;
18
+ enforce: "pre";
19
+ config(): {
20
+ optimizeDeps: {
21
+ include: string[];
22
+ exclude: string[];
23
+ };
24
+ };
25
+ configResolved(config: ViteLikeConfig): void;
26
+ resolveId(id: string): "\0virtual:gtsx/project-index" | "\0virtual:gtsx/config" | null;
27
+ load(id: string): TransformResult | null;
28
+ transform(code: string, id: string): TransformResult | null;
29
+ };
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAsB,MAAM,YAAY,CAAA;AAEhE,OAAO,EAAE,gCAAgC,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AAEvG,KAAK,cAAc,GAAG;IACpB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,KAAK,eAAe,GAAG;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,IAAI,CAAA;CACV,CAAA;AAED,KAAK,oBAAoB,GAAG;IAC1B,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB;;;;;;;;;2BAmBrC,cAAc;kBAGvB,MAAM;aAKX,MAAM,GAAG,eAAe,GAAG,IAAI;oBAkBxB,MAAM,MAAM,MAAM,GAAG,eAAe,GAAG,IAAI;EAU9D"}
package/dist/index.js ADDED
@@ -0,0 +1,67 @@
1
+ import { buildGTSXProjectIndex } from "@gtsx/core/project-index";
2
+ import { transformGTSXReactModule } from "@gtsx/core/react-transform";
3
+ import { resolveGTSXConfig } from "@gtsx/core/config-model";
4
+ export { transformGTSXComponentBoundaries, transformGTSXReactModule } from "@gtsx/core/react-transform";
5
+ export function gtsxViteReact(options = {}) {
6
+ let root = options.root ?? process.cwd();
7
+ const resolvedConfig = options.config ? resolveGTSXConfig(options.config) : undefined;
8
+ const virtualProjectIndexId = "virtual:gtsx/project-index";
9
+ const virtualConfigId = "virtual:gtsx/config";
10
+ const resolvedVirtualProjectIndexId = `\0${virtualProjectIndexId}`;
11
+ const resolvedVirtualConfigId = `\0${virtualConfigId}`;
12
+ return {
13
+ name: "@gtsx/adapter-vite-react",
14
+ enforce: "pre",
15
+ config() {
16
+ return {
17
+ optimizeDeps: {
18
+ include: ["react-tracked", "scheduler", "use-context-selector"],
19
+ exclude: ["@gtsx/adapter-vite-react", "typescript", virtualConfigId, virtualProjectIndexId],
20
+ },
21
+ };
22
+ },
23
+ configResolved(config) {
24
+ root = options.root ?? config.root;
25
+ },
26
+ resolveId(id) {
27
+ if (id === virtualProjectIndexId)
28
+ return resolvedVirtualProjectIndexId;
29
+ if (id === virtualConfigId)
30
+ return resolvedVirtualConfigId;
31
+ return null;
32
+ },
33
+ load(id) {
34
+ if (id === resolvedVirtualConfigId) {
35
+ return {
36
+ code: `export default ${JSON.stringify(resolvedConfig ?? defaultResolvedConfig())}\n`,
37
+ map: null,
38
+ };
39
+ }
40
+ if (id !== resolvedVirtualProjectIndexId)
41
+ return null;
42
+ const projectIndex = buildGTSXProjectIndex({
43
+ cwd: root,
44
+ projectRoot: options.projectRoot ?? resolvedConfig?.project.root ?? "src",
45
+ tsconfigPath: options.tsconfigPath ?? resolvedConfig?.project.tsconfig,
46
+ });
47
+ return {
48
+ code: `export default ${JSON.stringify(projectIndex)}\n`,
49
+ map: null,
50
+ };
51
+ },
52
+ transform(code, id) {
53
+ const transformed = transformGTSXReactModule({
54
+ code,
55
+ filePath: id,
56
+ root,
57
+ });
58
+ return transformed ? { code: transformed.code, map: null } : null;
59
+ },
60
+ };
61
+ }
62
+ function defaultResolvedConfig() {
63
+ return resolveGTSXConfig({
64
+ preview: {},
65
+ });
66
+ }
67
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index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QACb,CAAC;QACD,IAAI,CAAC,EAAU;YACb,IAAI,EAAE,KAAK,uBAAuB,EAAE,CAAC;gBACnC,OAAO;oBACL,IAAI,EAAE,kBAAkB,IAAI,CAAC,SAAS,CAAC,cAAc,IAAI,qBAAqB,EAAE,CAAC,IAAI;oBACrF,GAAG,EAAE,IAAI;iBACV,CAAA;YACH,CAAC;YACD,IAAI,EAAE,KAAK,6BAA6B;gBAAE,OAAO,IAAI,CAAA;YACrD,MAAM,YAAY,GAAG,qBAAqB,CAAC;gBACzC,GAAG,EAAE,IAAI;gBACT,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,cAAc,EAAE,OAAO,CAAC,IAAI,IAAI,KAAK;gBACzE,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,cAAc,EAAE,OAAO,CAAC,QAAQ;aACvE,CAAC,CAAA;YACF,OAAO;gBACL,IAAI,EAAE,kBAAkB,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,IAAI;gBACxD,GAAG,EAAE,IAAI;aACV,CAAA;QACH,CAAC;QACD,SAAS,CAAC,IAAY,EAAE,EAAU;YAChC,MAAM,WAAW,GAAG,wBAAwB,CAAC;gBAC3C,IAAI;gBACJ,QAAQ,EAAE,EAAE;gBACZ,IAAI;aACL,CAAC,CAAA;YAEF,OAAO,WAAW,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;QACnE,CAAC;KACF,CAAA;AACH,CAAC;AAED,SAAS,qBAAqB;IAC5B,OAAO,iBAAiB,CAAC;QACvB,OAAO,EAAE,EAAE;KACZ,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { GTSXReactPreviewClient as GTSXVitePreviewClient, isGTSXPreviewComponent, parseGTSXPreviewEntry, readGTSXPreviewRouteParams, } from "@gtsx/preview-react";
2
+ import { type GTSXPreviewComponent, type GTSXPreviewModule } from "@gtsx/preview-react";
3
+ export type { GTSXPreviewCase, GTSXPreviewComponent, GTSXPreviewComponentLoader, GTSXPreviewModule, GTSXPreviewRouteParams, GTSXReactPreviewClientProps as GTSXVitePreviewClientProps, } from "@gtsx/preview-react";
4
+ export type GTSXVitePreviewEntryModules = Record<string, () => Promise<GTSXPreviewModule>>;
5
+ export declare function createGTSXVitePreviewComponentLoader(modules: GTSXVitePreviewEntryModules, options?: {
6
+ projectRoot?: string;
7
+ }): (entry: string) => Promise<GTSXPreviewComponent | undefined>;
8
+ //# sourceMappingURL=preview.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../src/preview.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,IAAI,qBAAqB,EAC/C,sBAAsB,EACtB,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAGL,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,EACvB,MAAM,qBAAqB,CAAA;AAE5B,YAAY,EACV,eAAe,EACf,oBAAoB,EACpB,0BAA0B,EAC1B,iBAAiB,EACjB,sBAAsB,EACtB,2BAA2B,IAAI,0BAA0B,GAC1D,MAAM,qBAAqB,CAAA;AAE5B,MAAM,MAAM,2BAA2B,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAA;AAE1F,wBAAgB,oCAAoC,CAClD,OAAO,EAAE,2BAA2B,EACpC,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAO,GACrC,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,CAY9D"}
@@ -0,0 +1,23 @@
1
+ export { GTSXReactPreviewClient as GTSXVitePreviewClient, isGTSXPreviewComponent, parseGTSXPreviewEntry, readGTSXPreviewRouteParams, } from "@gtsx/preview-react";
2
+ import { isGTSXPreviewComponent, parseGTSXPreviewEntry, } from "@gtsx/preview-react";
3
+ export function createGTSXVitePreviewComponentLoader(modules, options = {}) {
4
+ const projectRoot = normalizeProjectRoot(options.projectRoot ?? "src");
5
+ return async (entry) => {
6
+ const { file, exportName } = parseGTSXPreviewEntry(entry);
7
+ const loader = modules[toModuleKey(file, projectRoot)];
8
+ if (!loader)
9
+ return undefined;
10
+ const moduleValue = await loader();
11
+ const component = moduleValue[exportName];
12
+ return isGTSXPreviewComponent(component) ? component : undefined;
13
+ };
14
+ }
15
+ function normalizeProjectRoot(projectRoot) {
16
+ return projectRoot.replace(/^\.\//, "").replace(/\/$/, "");
17
+ }
18
+ function toModuleKey(entryFile, projectRoot) {
19
+ const prefix = projectRoot === "." ? "" : `${projectRoot}/`;
20
+ const localPath = prefix && entryFile.startsWith(prefix) ? entryFile.slice(prefix.length) : entryFile;
21
+ return localPath.startsWith(".") ? localPath : `./${localPath}`;
22
+ }
23
+ //# sourceMappingURL=preview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview.js","sourceRoot":"","sources":["../src/preview.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,IAAI,qBAAqB,EAC/C,sBAAsB,EACtB,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EACL,sBAAsB,EACtB,qBAAqB,GAGtB,MAAM,qBAAqB,CAAA;AAa5B,MAAM,UAAU,oCAAoC,CAClD,OAAoC,EACpC,UAAoC,EAAE;IAEtC,MAAM,WAAW,GAAG,oBAAoB,CAAC,OAAO,CAAC,WAAW,IAAI,KAAK,CAAC,CAAA;IAEtE,OAAO,KAAK,EAAE,KAAa,EAAE,EAAE;QAC7B,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAA;QACzD,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAA;QACtD,IAAI,CAAC,MAAM;YAAE,OAAO,SAAS,CAAA;QAE7B,MAAM,WAAW,GAAG,MAAM,MAAM,EAAE,CAAA;QAClC,MAAM,SAAS,GAAG,WAAW,CAAC,UAAU,CAAC,CAAA;QACzC,OAAO,sBAAsB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAA;IAClE,CAAC,CAAA;AACH,CAAC;AAED,SAAS,oBAAoB,CAAC,WAAmB;IAC/C,OAAO,WAAW,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAA;AAC5D,CAAC;AAED,SAAS,WAAW,CAAC,SAAiB,EAAE,WAAmB;IACzD,MAAM,MAAM,GAAG,WAAW,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,WAAW,GAAG,CAAA;IAC3D,MAAM,SAAS,GAAG,MAAM,IAAI,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IACrG,OAAO,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAA;AACjE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@gtsx/adapter-vite-react",
3
+ "version": "0.0.1",
4
+ "description": "Vite 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-vite-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
+ "vite",
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
+ },
30
+ "./preview": {
31
+ "types": "./dist/preview.d.ts",
32
+ "import": "./dist/preview.js"
33
+ }
34
+ },
35
+ "files": [
36
+ "dist"
37
+ ],
38
+ "dependencies": {
39
+ "@gtsx/preview-react": "0.0.1"
40
+ },
41
+ "peerDependencies": {
42
+ "react": ">=18",
43
+ "vite": ">=5",
44
+ "@gtsx/core": "0.0.1"
45
+ },
46
+ "scripts": {
47
+ "build": "tsc -p tsconfig.build.json",
48
+ "test": "vitest run",
49
+ "typecheck": "tsc -p tsconfig.json --noEmit"
50
+ }
51
+ }