@powerhousedao/builder-tools 0.2.0
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/connect-studio/helpers.d.ts +5 -0
- package/dist/connect-studio/helpers.d.ts.map +1 -0
- package/dist/connect-studio/helpers.js +43 -0
- package/dist/connect-studio/hmr.d.ts +12 -0
- package/dist/connect-studio/hmr.d.ts.map +1 -0
- package/dist/connect-studio/hmr.js +8 -0
- package/dist/connect-studio/index.d.ts +9 -0
- package/dist/connect-studio/index.d.ts.map +1 -0
- package/dist/connect-studio/index.js +7 -0
- package/dist/connect-studio/server.d.ts +3 -0
- package/dist/connect-studio/server.d.ts.map +1 -0
- package/dist/connect-studio/server.js +175 -0
- package/dist/connect-studio/studio.d.ts +3 -0
- package/dist/connect-studio/studio.d.ts.map +1 -0
- package/dist/connect-studio/studio.js +65 -0
- package/dist/connect-studio/types.d.ts +25 -0
- package/dist/connect-studio/types.d.ts.map +1 -0
- package/dist/connect-studio/types.js +1 -0
- package/dist/connect-studio/vite-plugins/base.d.ts +19 -0
- package/dist/connect-studio/vite-plugins/base.d.ts.map +1 -0
- package/dist/connect-studio/vite-plugins/base.js +162 -0
- package/dist/connect-studio/vite-plugins/external-packages.d.ts +6 -0
- package/dist/connect-studio/vite-plugins/external-packages.d.ts.map +1 -0
- package/dist/connect-studio/vite-plugins/external-packages.js +74 -0
- package/dist/connect-studio/vite-plugins/hmr.d.ts +3 -0
- package/dist/connect-studio/vite-plugins/hmr.d.ts.map +1 -0
- package/dist/connect-studio/vite-plugins/hmr.js +57 -0
- package/dist/connect-studio/vite-plugins/importmap.d.ts +20 -0
- package/dist/connect-studio/vite-plugins/importmap.d.ts.map +1 -0
- package/dist/connect-studio/vite-plugins/importmap.js +174 -0
- package/dist/connect-studio/vite-plugins/studio.d.ts +4 -0
- package/dist/connect-studio/vite-plugins/studio.d.ts.map +1 -0
- package/dist/connect-studio/vite-plugins/studio.js +112 -0
- package/dist/document-model-editor/components/button.d.ts +4 -0
- package/dist/document-model-editor/components/button.d.ts.map +1 -0
- package/dist/document-model-editor/components/button.js +7 -0
- package/dist/document-model-editor/components/code-editors/graphql-editor.d.ts +10 -0
- package/dist/document-model-editor/components/code-editors/graphql-editor.d.ts.map +1 -0
- package/dist/document-model-editor/components/code-editors/graphql-editor.js +75 -0
- package/dist/document-model-editor/components/code-editors/json-editor.d.ts +8 -0
- package/dist/document-model-editor/components/code-editors/json-editor.d.ts.map +1 -0
- package/dist/document-model-editor/components/code-editors/json-editor.js +43 -0
- package/dist/document-model-editor/components/code-editors/utils.d.ts +32 -0
- package/dist/document-model-editor/components/code-editors/utils.d.ts.map +1 -0
- package/dist/document-model-editor/components/code-editors/utils.js +191 -0
- package/dist/document-model-editor/components/divider.d.ts +8 -0
- package/dist/document-model-editor/components/divider.d.ts.map +1 -0
- package/dist/document-model-editor/components/divider.js +21 -0
- package/dist/document-model-editor/components/errors.d.ts +6 -0
- package/dist/document-model-editor/components/errors.d.ts.map +1 -0
- package/dist/document-model-editor/components/errors.js +4 -0
- package/dist/document-model-editor/components/form.d.ts +12 -0
- package/dist/document-model-editor/components/form.d.ts.map +1 -0
- package/dist/document-model-editor/components/form.js +42 -0
- package/dist/document-model-editor/components/input.d.ts +6 -0
- package/dist/document-model-editor/components/input.d.ts.map +1 -0
- package/dist/document-model-editor/components/input.js +8 -0
- package/dist/document-model-editor/components/label.d.ts +6 -0
- package/dist/document-model-editor/components/label.d.ts.map +1 -0
- package/dist/document-model-editor/components/label.js +9 -0
- package/dist/document-model-editor/components/model-metadata-form.d.ts +45 -0
- package/dist/document-model-editor/components/model-metadata-form.d.ts.map +1 -0
- package/dist/document-model-editor/components/model-metadata-form.js +69 -0
- package/dist/document-model-editor/components/module-form.d.ts +10 -0
- package/dist/document-model-editor/components/module-form.d.ts.map +1 -0
- package/dist/document-model-editor/components/module-form.js +21 -0
- package/dist/document-model-editor/components/module.d.ts +21 -0
- package/dist/document-model-editor/components/module.d.ts.map +1 -0
- package/dist/document-model-editor/components/module.js +9 -0
- package/dist/document-model-editor/components/modules.d.ts +19 -0
- package/dist/document-model-editor/components/modules.d.ts.map +1 -0
- package/dist/document-model-editor/components/modules.js +16 -0
- package/dist/document-model-editor/components/operation-description-form.d.ts +9 -0
- package/dist/document-model-editor/components/operation-description-form.d.ts.map +1 -0
- package/dist/document-model-editor/components/operation-description-form.js +12 -0
- package/dist/document-model-editor/components/operation-error-form.d.ts +13 -0
- package/dist/document-model-editor/components/operation-error-form.d.ts.map +1 -0
- package/dist/document-model-editor/components/operation-error-form.js +39 -0
- package/dist/document-model-editor/components/operation-errors.d.ts +10 -0
- package/dist/document-model-editor/components/operation-errors.d.ts.map +1 -0
- package/dist/document-model-editor/components/operation-errors.js +16 -0
- package/dist/document-model-editor/components/operation-form.d.ts +13 -0
- package/dist/document-model-editor/components/operation-form.d.ts.map +1 -0
- package/dist/document-model-editor/components/operation-form.js +36 -0
- package/dist/document-model-editor/components/operation.d.ts +22 -0
- package/dist/document-model-editor/components/operation.d.ts.map +1 -0
- package/dist/document-model-editor/components/operation.js +21 -0
- package/dist/document-model-editor/components/operations.d.ts +17 -0
- package/dist/document-model-editor/components/operations.d.ts.map +1 -0
- package/dist/document-model-editor/components/operations.js +19 -0
- package/dist/document-model-editor/components/state-schemas.d.ts +13 -0
- package/dist/document-model-editor/components/state-schemas.d.ts.map +1 -0
- package/dist/document-model-editor/components/state-schemas.js +34 -0
- package/dist/document-model-editor/components/tabs.d.ts +8 -0
- package/dist/document-model-editor/components/tabs.d.ts.map +1 -0
- package/dist/document-model-editor/components/tabs.js +12 -0
- package/dist/document-model-editor/components/text-area.d.ts +9 -0
- package/dist/document-model-editor/components/text-area.d.ts.map +1 -0
- package/dist/document-model-editor/components/text-area.js +26 -0
- package/dist/document-model-editor/components/text-field.d.ts +21 -0
- package/dist/document-model-editor/components/text-field.d.ts.map +1 -0
- package/dist/document-model-editor/components/text-field.js +78 -0
- package/dist/document-model-editor/constants/documents.d.ts +12 -0
- package/dist/document-model-editor/constants/documents.d.ts.map +1 -0
- package/dist/document-model-editor/constants/documents.js +16 -0
- package/dist/document-model-editor/context/form-context.d.ts +11 -0
- package/dist/document-model-editor/context/form-context.d.ts.map +1 -0
- package/dist/document-model-editor/context/form-context.js +3 -0
- package/dist/document-model-editor/context/schema-context.d.ts +11 -0
- package/dist/document-model-editor/context/schema-context.d.ts.map +1 -0
- package/dist/document-model-editor/context/schema-context.js +116 -0
- package/dist/document-model-editor/document-model-editor.stories.d.ts +48 -0
- package/dist/document-model-editor/document-model-editor.stories.d.ts.map +1 -0
- package/dist/document-model-editor/document-model-editor.stories.js +252 -0
- package/dist/document-model-editor/editor.d.ts +3 -0
- package/dist/document-model-editor/editor.d.ts.map +1 -0
- package/dist/document-model-editor/editor.js +186 -0
- package/dist/document-model-editor/hooks/useFormField.d.ts +13 -0
- package/dist/document-model-editor/hooks/useFormField.d.ts.map +1 -0
- package/dist/document-model-editor/hooks/useFormField.js +21 -0
- package/dist/document-model-editor/index.d.ts +3 -0
- package/dist/document-model-editor/index.d.ts.map +1 -0
- package/dist/document-model-editor/index.js +2 -0
- package/dist/document-model-editor/module.d.ts +4 -0
- package/dist/document-model-editor/module.d.ts.map +1 -0
- package/dist/document-model-editor/module.js +10 -0
- package/dist/document-model-editor/schemas/inputs.d.ts +31 -0
- package/dist/document-model-editor/schemas/inputs.d.ts.map +1 -0
- package/dist/document-model-editor/schemas/inputs.js +70 -0
- package/dist/document-model-editor/schemas/utils.d.ts +3 -0
- package/dist/document-model-editor/schemas/utils.d.ts.map +1 -0
- package/dist/document-model-editor/schemas/utils.js +2 -0
- package/dist/document-model-editor/types/documents.d.ts +27 -0
- package/dist/document-model-editor/types/documents.d.ts.map +1 -0
- package/dist/document-model-editor/types/documents.js +1 -0
- package/dist/document-model-editor/utils/helpers.d.ts +39 -0
- package/dist/document-model-editor/utils/helpers.d.ts.map +1 -0
- package/dist/document-model-editor/utils/helpers.js +293 -0
- package/dist/document-model-editor/utils/linting.d.ts +7 -0
- package/dist/document-model-editor/utils/linting.d.ts.map +1 -0
- package/dist/document-model-editor/utils/linting.js +47 -0
- package/dist/document-model-editor/utils/style.d.ts +3 -0
- package/dist/document-model-editor/utils/style.d.ts.map +1 -0
- package/dist/document-model-editor/utils/style.js +5 -0
- package/dist/editor-utils/components/documentEditor.d.ts +7 -0
- package/dist/editor-utils/components/documentEditor.d.ts.map +1 -0
- package/dist/editor-utils/components/documentEditor.js +5 -0
- package/dist/editor-utils/components/editorToolbar.d.ts +11 -0
- package/dist/editor-utils/components/editorToolbar.d.ts.map +1 -0
- package/dist/editor-utils/components/editorToolbar.js +5 -0
- package/dist/editor-utils/components/editorWorksheet.d.ts +7 -0
- package/dist/editor-utils/components/editorWorksheet.d.ts.map +1 -0
- package/dist/editor-utils/components/editorWorksheet.js +4 -0
- package/dist/editor-utils/components/index.d.ts +9 -0
- package/dist/editor-utils/components/index.d.ts.map +1 -0
- package/dist/editor-utils/components/index.js +9 -0
- package/dist/editor-utils/components/styles.d.ts +40 -0
- package/dist/editor-utils/components/styles.d.ts.map +1 -0
- package/dist/editor-utils/components/styles.js +78 -0
- package/dist/editor-utils/components/stylesVariant.d.ts +40 -0
- package/dist/editor-utils/components/stylesVariant.d.ts.map +1 -0
- package/dist/editor-utils/components/stylesVariant.js +88 -0
- package/dist/editor-utils/components/textInput.d.ts +20 -0
- package/dist/editor-utils/components/textInput.d.ts.map +1 -0
- package/dist/editor-utils/components/textInput.js +83 -0
- package/dist/editor-utils/components/textInputVariant.d.ts +21 -0
- package/dist/editor-utils/components/textInputVariant.d.ts.map +1 -0
- package/dist/editor-utils/components/textInputVariant.js +92 -0
- package/dist/editor-utils/components/toolbarButton.d.ts +7 -0
- package/dist/editor-utils/components/toolbarButton.d.ts.map +1 -0
- package/dist/editor-utils/components/toolbarButton.js +8 -0
- package/dist/editor-utils/hooks/index.d.ts +2 -0
- package/dist/editor-utils/hooks/index.d.ts.map +1 -0
- package/dist/editor-utils/hooks/index.js +1 -0
- package/dist/editor-utils/hooks/useEnsInfo.d.ts +15 -0
- package/dist/editor-utils/hooks/useEnsInfo.d.ts.map +1 -0
- package/dist/editor-utils/hooks/useEnsInfo.js +63 -0
- package/dist/editor-utils/index.d.ts +5 -0
- package/dist/editor-utils/index.d.ts.map +1 -0
- package/dist/editor-utils/index.js +4 -0
- package/dist/editor-utils/reducer.d.ts +3 -0
- package/dist/editor-utils/reducer.d.ts.map +1 -0
- package/dist/editor-utils/reducer.js +24 -0
- package/dist/editor-utils/storybook.d.ts +25 -0
- package/dist/editor-utils/storybook.d.ts.map +1 -0
- package/dist/editor-utils/storybook.js +118 -0
- package/dist/styles.css +786 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +102 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { getConfig } from "@powerhousedao/config/powerhouse";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { normalizePath } from "vite";
|
|
5
|
+
import { viteIgnoreStaticImport, viteReplaceImports } from "./base.js";
|
|
6
|
+
// TODO use config path?
|
|
7
|
+
const __dirname = join(process.cwd(), ".ph/");
|
|
8
|
+
// import.meta.dirname || dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
export const EXTERNAL_PACKAGES_IMPORT = "PH:EXTERNAL_PACKAGES";
|
|
10
|
+
export const IMPORT_SCRIPT_FILE = normalizePath(join(__dirname, "external-packages.js"));
|
|
11
|
+
export function generateImportScript(packages) {
|
|
12
|
+
const targetDir = dirname(IMPORT_SCRIPT_FILE);
|
|
13
|
+
// create file if it doesn't exist, also create path if it doesn't exist (recursive)
|
|
14
|
+
if (!fs.existsSync(targetDir)) {
|
|
15
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
16
|
+
}
|
|
17
|
+
const imports = [];
|
|
18
|
+
const moduleNames = [];
|
|
19
|
+
let counter = 0;
|
|
20
|
+
for (const packageName of packages) {
|
|
21
|
+
const moduleName = `module${counter}`;
|
|
22
|
+
moduleNames.push(moduleName);
|
|
23
|
+
imports.push(`import * as ${moduleName} from '${packageName}';`);
|
|
24
|
+
counter++;
|
|
25
|
+
}
|
|
26
|
+
const exportStatement = `export default [
|
|
27
|
+
${moduleNames
|
|
28
|
+
.map((name, index) => `{
|
|
29
|
+
id: "${packages[index]}",
|
|
30
|
+
...${name},
|
|
31
|
+
}`)
|
|
32
|
+
.join(",\n")}
|
|
33
|
+
];`;
|
|
34
|
+
const fileContent = `${imports.join("\n")}\n\n${exportStatement}`;
|
|
35
|
+
fs.writeFileSync(IMPORT_SCRIPT_FILE, fileContent);
|
|
36
|
+
return IMPORT_SCRIPT_FILE;
|
|
37
|
+
}
|
|
38
|
+
export const viteLoadExternalPackages = (packages, hmr = false) => {
|
|
39
|
+
if (!packages?.length && !hmr) {
|
|
40
|
+
return viteIgnoreStaticImport([EXTERNAL_PACKAGES_IMPORT]);
|
|
41
|
+
}
|
|
42
|
+
generateImportScript(packages ?? []);
|
|
43
|
+
process.env.LOAD_EXTERNAL_PACKAGES = "true";
|
|
44
|
+
return [
|
|
45
|
+
viteReplaceImports({ [EXTERNAL_PACKAGES_IMPORT]: IMPORT_SCRIPT_FILE }),
|
|
46
|
+
hmr && {
|
|
47
|
+
name: "vite-plugin-studio-external-packages",
|
|
48
|
+
handleHotUpdate({ file, server, modules }) {
|
|
49
|
+
if (file.endsWith("powerhouse.config.json")) {
|
|
50
|
+
const config = getConfig(file);
|
|
51
|
+
generateImportScript(config.packages?.map((p) => p.packageName) ?? []);
|
|
52
|
+
config.packages?.forEach((pkg) => console.log("-> Loading package:", pkg.packageName));
|
|
53
|
+
const module = server.moduleGraph.getModuleById(IMPORT_SCRIPT_FILE);
|
|
54
|
+
if (module) {
|
|
55
|
+
server.moduleGraph.invalidateModule(module);
|
|
56
|
+
return [module].concat(...module.importers.values());
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else if (file === IMPORT_SCRIPT_FILE) {
|
|
60
|
+
modules
|
|
61
|
+
.filter((module) => module.id === IMPORT_SCRIPT_FILE)
|
|
62
|
+
.forEach((module) => {
|
|
63
|
+
server.ws.send("studio:external-packages-updated", {
|
|
64
|
+
url: module.url,
|
|
65
|
+
timestamp: module.lastHMRTimestamp,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
return modules;
|
|
69
|
+
}
|
|
70
|
+
return modules;
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmr.d.ts","sourceRoot":"","sources":["../../../connect-studio/vite-plugins/hmr.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,YAAY,EAAiB,MAAM,MAAM,CAAC;AAGlE,eAAO,MAAM,iBAAiB,gBAAiB,MAAM,KAAG,YAYvD,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { exec } from "node:child_process";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { normalizePath } from "vite";
|
|
4
|
+
import { HMR_MODULE_IMPORT, viteReplaceImports } from "./base.js";
|
|
5
|
+
export const viteLoadHMRModule = (connectPath) => {
|
|
6
|
+
return [
|
|
7
|
+
viteReplaceImports({
|
|
8
|
+
[HMR_MODULE_IMPORT]: normalizePath(join(connectPath, "hmr.js")),
|
|
9
|
+
}),
|
|
10
|
+
{
|
|
11
|
+
name: "vite-plugin-studio-hmr-module",
|
|
12
|
+
configureServer(server) {
|
|
13
|
+
handleExternalPackageEvents(server);
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
];
|
|
17
|
+
};
|
|
18
|
+
const handleExternalPackageEvents = (server) => {
|
|
19
|
+
server.ws.on("studio:add-external-package", (data, client) => {
|
|
20
|
+
const { name } = data;
|
|
21
|
+
const installProcess = exec(`ph install ${name}`, {
|
|
22
|
+
cwd: process.cwd(),
|
|
23
|
+
}, (error) => {
|
|
24
|
+
if (error) {
|
|
25
|
+
console.error(`\t[${name}]: ${error.message}`);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
server.ws.send("studio:external-package-added", {
|
|
29
|
+
name,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
installProcess.stdout?.on("data", (data) => {
|
|
34
|
+
console.log(`\t[${name}]: ${data.toString().trim()}`);
|
|
35
|
+
});
|
|
36
|
+
console.log("Installing external package:", name);
|
|
37
|
+
});
|
|
38
|
+
server.ws.on("studio:remove-external-package", (data, client) => {
|
|
39
|
+
const { name } = data;
|
|
40
|
+
const uninstallProcess = exec(`ph uninstall ${name}`, {
|
|
41
|
+
cwd: process.cwd(),
|
|
42
|
+
}, (error) => {
|
|
43
|
+
if (error) {
|
|
44
|
+
console.error(`\t[${name}]: ${error.message}`);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
server.ws.send("studio:external-package-removed", {
|
|
48
|
+
name,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
uninstallProcess.stdout?.on("data", (data) => {
|
|
53
|
+
console.log(`\t[${name}]: ${data.toString().trim()}`);
|
|
54
|
+
});
|
|
55
|
+
console.log("Removing external package:", name);
|
|
56
|
+
});
|
|
57
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PluginOption } from "vite";
|
|
2
|
+
export type Provider = "node_modules" | "esm.sh";
|
|
3
|
+
/**
|
|
4
|
+
* Vite plugin to bundle or copy dependencies and inject an import map into `index.html`.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} outputDir - The directory where the modules should be placed.
|
|
7
|
+
* @param {(string | { name: string; provider: string })[]} dependencies -
|
|
8
|
+
* List of dependencies to process. Can be:
|
|
9
|
+
* - A string (dependency is copied as is).
|
|
10
|
+
* - An object `{ name, provide }` where:
|
|
11
|
+
* - `name` (string): The module name.
|
|
12
|
+
* - `provider` (string): Where to retrieve the module bundle. Defaults to node_modules.
|
|
13
|
+
*
|
|
14
|
+
* @returns {Plugin} A Vite plugin that processes dependencies and injects an import map.
|
|
15
|
+
*/
|
|
16
|
+
export declare function generateImportMapPlugin(outputDir: string, dependencies: (string | {
|
|
17
|
+
name: string;
|
|
18
|
+
provider: Provider;
|
|
19
|
+
})[]): PluginOption;
|
|
20
|
+
//# sourceMappingURL=importmap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importmap.d.ts","sourceRoot":"","sources":["../../../connect-studio/vite-plugins/importmap.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AAGpC,MAAM,MAAM,QAAQ,GAAG,cAAc,GAAG,QAAQ,CAAC;AA+MjD;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,CAAC,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,CAAC,EAAE,GAC9D,YAAY,CAUd"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { build } from "esbuild";
|
|
2
|
+
import fg from "fast-glob";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import { builtinModules } from "node:module";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { exports } from "resolve.exports";
|
|
7
|
+
import { findPackageJson } from "./base.js";
|
|
8
|
+
const nodeModules = builtinModules.concat(builtinModules.map((m) => `node:${m}`));
|
|
9
|
+
/**
|
|
10
|
+
* Resolves glob exports like `"./*": "./dist/*.js"` and `"./utils/*": "./dist/utils/*.js"`
|
|
11
|
+
* into actual file mappings.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} exportName - The export pattern (e.g., `"./*"` or `"./utils/*"`).
|
|
14
|
+
* @param {string} exportPath - The actual path pattern (e.g., `"./dist/*.js"`).
|
|
15
|
+
* @param {string} srcPath - The package root directory where the exports are located.
|
|
16
|
+
* @returns {Promise<Record<string, string>>} - A mapping of export names to resolved paths.
|
|
17
|
+
*/
|
|
18
|
+
async function resolveGlobExport(exportName, exportPath, srcPath) {
|
|
19
|
+
const resolvedExports = new Map();
|
|
20
|
+
const hasGloblExport = exportName.endsWith("/*");
|
|
21
|
+
const globPath = hasGloblExport
|
|
22
|
+
? exportPath.replace("*", "**/*")
|
|
23
|
+
: exportPath;
|
|
24
|
+
const distPath = exportPath.substring(0, exportPath.lastIndexOf("/*"));
|
|
25
|
+
const resolvedSrcPath = hasGloblExport
|
|
26
|
+
? path.join(srcPath.replace("*", ""), distPath)
|
|
27
|
+
: srcPath;
|
|
28
|
+
const files = await fg(path.join(srcPath, globPath));
|
|
29
|
+
for (const file of files) {
|
|
30
|
+
const relativeSrcFilePath = path.relative(resolvedSrcPath, file); // Relative to the dist folder
|
|
31
|
+
const exportFilePath = path.relative(srcPath, file); // Relative to package root
|
|
32
|
+
const exportKey = relativeSrcFilePath.replace(path.extname(file), ""); // Remove .js extension
|
|
33
|
+
const mappedExport = exportName.replace("*", exportKey); // Replace glob `*` with actual name
|
|
34
|
+
resolvedExports.set(mappedExport, {
|
|
35
|
+
export: `./${relativeSrcFilePath}`,
|
|
36
|
+
file: exportFilePath,
|
|
37
|
+
}); // Final mapped entry
|
|
38
|
+
}
|
|
39
|
+
return resolvedExports;
|
|
40
|
+
}
|
|
41
|
+
async function addExportToMap(exportName, exportPath, srcPath, map) {
|
|
42
|
+
if (exportName.includes("*")) {
|
|
43
|
+
const exports = await resolveGlobExport(exportName, exportPath, srcPath);
|
|
44
|
+
exports.forEach((value, key) => map.set(key, value));
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
map.set(exportName, { export: exportPath, file: exportPath });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function getPackageExports(name, packageJson, srcPath) {
|
|
51
|
+
const entries = new Map();
|
|
52
|
+
const mainExport = exports(packageJson, ".", {
|
|
53
|
+
browser: true,
|
|
54
|
+
});
|
|
55
|
+
if (mainExport) {
|
|
56
|
+
for (const entry of mainExport) {
|
|
57
|
+
await addExportToMap(".", entry, srcPath, entries);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!packageJson.exports) {
|
|
61
|
+
return entries;
|
|
62
|
+
}
|
|
63
|
+
if (typeof packageJson.exports === "string") {
|
|
64
|
+
await addExportToMap(name, packageJson.exports, srcPath, entries);
|
|
65
|
+
return entries;
|
|
66
|
+
}
|
|
67
|
+
for (const [key, entry] of Object.entries(packageJson.exports)) {
|
|
68
|
+
if (typeof entry === "string") {
|
|
69
|
+
await addExportToMap(key, entry, srcPath, entries);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
const exportEntry = exports(packageJson, key, {
|
|
73
|
+
browser: true,
|
|
74
|
+
});
|
|
75
|
+
const exportResult = exportEntry?.at(0);
|
|
76
|
+
if (exportResult) {
|
|
77
|
+
await addExportToMap(key, exportResult, srcPath, entries);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
console.warn(`No browser exports found for ${name}/${key}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return entries;
|
|
85
|
+
}
|
|
86
|
+
function importFromEsmSh(name) {
|
|
87
|
+
return {
|
|
88
|
+
[name]: `https://esm.sh/${name}`,
|
|
89
|
+
[`${name}/`]: `https://esm.sh/${name}/`,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
async function importFromNodeModules(name, modulesDir, importMapDeps) {
|
|
93
|
+
console.log(`Bundling dependency: ${name}`);
|
|
94
|
+
const importMap = {};
|
|
95
|
+
const { packageJson, path: srcPath } = await findPackageJson(name);
|
|
96
|
+
const entries = await getPackageExports(name, packageJson, srcPath);
|
|
97
|
+
if (!entries.size) {
|
|
98
|
+
throw new Error(`No browser exports found for ${name}`);
|
|
99
|
+
}
|
|
100
|
+
const indexFile = entries.get("")?.export || "index";
|
|
101
|
+
const fileName = path.basename(entries.get("")?.export || "index", path.extname(indexFile));
|
|
102
|
+
const outputPath = path.join(modulesDir, name);
|
|
103
|
+
// Bundle and tree-shake only dependencies (exclude the actual library code)
|
|
104
|
+
await build({
|
|
105
|
+
entryPoints: Array.from(entries.values()).map((value) => path.join(srcPath, value.file)),
|
|
106
|
+
outdir: outputPath,
|
|
107
|
+
bundle: true,
|
|
108
|
+
format: "esm",
|
|
109
|
+
platform: "browser",
|
|
110
|
+
target: "esnext",
|
|
111
|
+
splitting: true,
|
|
112
|
+
external: nodeModules.concat(Array.from(importMapDeps)), // Exclude dependencies already in import map
|
|
113
|
+
sourcemap: true,
|
|
114
|
+
minify: false,
|
|
115
|
+
});
|
|
116
|
+
// Add entry to import map
|
|
117
|
+
importMap[name] = `./modules/${name}/${fileName}.js`;
|
|
118
|
+
entries.forEach((entry, key) => {
|
|
119
|
+
importMap[path.join(name, key)] =
|
|
120
|
+
`./modules/${path.join(name, entry.export)}`;
|
|
121
|
+
});
|
|
122
|
+
return importMap;
|
|
123
|
+
}
|
|
124
|
+
async function generateImportMap(outputDir, dependencies) {
|
|
125
|
+
const modulesDir = path.join(outputDir, "/modules");
|
|
126
|
+
await fs.mkdir(modulesDir, { recursive: true });
|
|
127
|
+
const importMapDeps = new Set(dependencies.map((dep) => (typeof dep === "string" ? dep : dep.name)));
|
|
128
|
+
let importMap = {};
|
|
129
|
+
for (const dependency of dependencies) {
|
|
130
|
+
const name = typeof dependency === "string" ? dependency : dependency.name;
|
|
131
|
+
const provider = typeof dependency === "string" ? "node_modules" : dependency.provider;
|
|
132
|
+
if (provider === "esm.sh") {
|
|
133
|
+
const imports = importFromEsmSh(name);
|
|
134
|
+
importMap = { ...importMap, ...imports };
|
|
135
|
+
}
|
|
136
|
+
else if (provider.toString() === "node_modules") {
|
|
137
|
+
const imports = await importFromNodeModules(name, modulesDir, importMapDeps);
|
|
138
|
+
importMap = { ...importMap, ...imports };
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
throw new Error(`Unsupported provider: ${provider}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const indexPath = path.join(outputDir, "index.html");
|
|
145
|
+
let html = await fs.readFile(indexPath, "utf-8");
|
|
146
|
+
const importMapScript = `<script type="importmap">${JSON.stringify({ imports: importMap }, null, 2)}</script>`;
|
|
147
|
+
html = html.replace("</head>", `${importMapScript}\n</head>`);
|
|
148
|
+
await fs.writeFile(indexPath, html, "utf-8");
|
|
149
|
+
console.log("✅ Import map added to index.html");
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Vite plugin to bundle or copy dependencies and inject an import map into `index.html`.
|
|
153
|
+
*
|
|
154
|
+
* @param {string} outputDir - The directory where the modules should be placed.
|
|
155
|
+
* @param {(string | { name: string; provider: string })[]} dependencies -
|
|
156
|
+
* List of dependencies to process. Can be:
|
|
157
|
+
* - A string (dependency is copied as is).
|
|
158
|
+
* - An object `{ name, provide }` where:
|
|
159
|
+
* - `name` (string): The module name.
|
|
160
|
+
* - `provider` (string): Where to retrieve the module bundle. Defaults to node_modules.
|
|
161
|
+
*
|
|
162
|
+
* @returns {Plugin} A Vite plugin that processes dependencies and injects an import map.
|
|
163
|
+
*/
|
|
164
|
+
export function generateImportMapPlugin(outputDir, dependencies) {
|
|
165
|
+
return {
|
|
166
|
+
name: "vite-plugin-importmap",
|
|
167
|
+
async closeBundle() {
|
|
168
|
+
await generateImportMap(outputDir, dependencies);
|
|
169
|
+
},
|
|
170
|
+
async configureServer() {
|
|
171
|
+
await generateImportMap(outputDir, dependencies);
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { PluginOption, ViteDevServer } from "vite";
|
|
2
|
+
export declare function watchLocalFiles(server: ViteDevServer, documentModelsPath?: string, editorsPath?: string): void;
|
|
3
|
+
export declare function viteConnectDevStudioPlugin(enabled: boolean | undefined, connectPath: string, env?: Record<string, string>): PluginOption[];
|
|
4
|
+
//# sourceMappingURL=studio.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"studio.d.ts","sourceRoot":"","sources":["../../../connect-studio/vite-plugins/studio.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAanD,wBAAgB,eAAe,CAC7B,MAAM,EAAE,aAAa,EACrB,kBAAkB,CAAC,EAAE,MAAM,EAC3B,WAAW,CAAC,EAAE,MAAM,QA8DrB;AAED,wBAAgB,0BAA0B,CACxC,OAAO,qBAAQ,EACf,WAAW,EAAE,MAAM,EACnB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC3B,YAAY,EAAE,CAoEhB"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { externalIds, getStudioConfig, HMR_MODULE_IMPORT, LOCAL_DOCUMENT_EDITORS_IMPORT, LOCAL_DOCUMENT_MODELS_IMPORT, STUDIO_IMPORTS, viteIgnoreStaticImport, viteReplaceImports, } from "./base.js";
|
|
5
|
+
import { viteLoadHMRModule } from "./hmr.js";
|
|
6
|
+
export function watchLocalFiles(server, documentModelsPath, editorsPath) {
|
|
7
|
+
const debounce = (callback, delay = 100) => {
|
|
8
|
+
let timeout;
|
|
9
|
+
return function () {
|
|
10
|
+
clearTimeout(timeout);
|
|
11
|
+
timeout = setTimeout(() => {
|
|
12
|
+
callback();
|
|
13
|
+
}, delay);
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
const refreshModelsWithDebounce = debounce(() => {
|
|
17
|
+
console.log(`Local document models changed, reloading Connect...`);
|
|
18
|
+
server.ws.send({
|
|
19
|
+
type: "full-reload",
|
|
20
|
+
path: "*",
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
const refreshEditorsWithDebounce = debounce(() => {
|
|
24
|
+
console.log(`Local document editors changed, reloading Connect...`);
|
|
25
|
+
server.ws.send({
|
|
26
|
+
type: "full-reload",
|
|
27
|
+
path: "*",
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
if (documentModelsPath) {
|
|
31
|
+
// Use fs to watch the file and trigger a server reload when it changes
|
|
32
|
+
console.log(`Watching local document models at '${documentModelsPath}'...`);
|
|
33
|
+
try {
|
|
34
|
+
fs.watch(documentModelsPath, {
|
|
35
|
+
recursive: true,
|
|
36
|
+
}, (event, filename) => {
|
|
37
|
+
refreshModelsWithDebounce();
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
console.error("Error watching local document models", e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (editorsPath) {
|
|
45
|
+
console.log(`Watching local document editors at '${editorsPath}'...`);
|
|
46
|
+
try {
|
|
47
|
+
fs.watch(editorsPath, {
|
|
48
|
+
recursive: true,
|
|
49
|
+
}, (event, filename) => {
|
|
50
|
+
refreshEditorsWithDebounce();
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
console.error("Error watching local document models", e);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export function viteConnectDevStudioPlugin(enabled = false, connectPath, env) {
|
|
59
|
+
const studioConfig = getStudioConfig(env);
|
|
60
|
+
const localDocumentModelsPath = studioConfig[LOCAL_DOCUMENT_MODELS_IMPORT];
|
|
61
|
+
const localDocumentEditorsPath = studioConfig[LOCAL_DOCUMENT_EDITORS_IMPORT];
|
|
62
|
+
return [
|
|
63
|
+
enabled &&
|
|
64
|
+
viteIgnoreStaticImport([
|
|
65
|
+
"react",
|
|
66
|
+
"react-dom",
|
|
67
|
+
"@powerhousedao/reactor-browser",
|
|
68
|
+
]),
|
|
69
|
+
localDocumentModelsPath
|
|
70
|
+
? viteReplaceImports({
|
|
71
|
+
[LOCAL_DOCUMENT_MODELS_IMPORT]: localDocumentModelsPath,
|
|
72
|
+
})
|
|
73
|
+
: viteIgnoreStaticImport([LOCAL_DOCUMENT_MODELS_IMPORT]),
|
|
74
|
+
localDocumentEditorsPath
|
|
75
|
+
? viteReplaceImports({
|
|
76
|
+
[LOCAL_DOCUMENT_EDITORS_IMPORT]: localDocumentEditorsPath,
|
|
77
|
+
})
|
|
78
|
+
: viteIgnoreStaticImport([LOCAL_DOCUMENT_EDITORS_IMPORT]),
|
|
79
|
+
enabled
|
|
80
|
+
? viteLoadHMRModule(connectPath)
|
|
81
|
+
: viteIgnoreStaticImport([HMR_MODULE_IMPORT]),
|
|
82
|
+
{
|
|
83
|
+
name: "vite-plugin-connect-dev-studio",
|
|
84
|
+
enforce: "pre",
|
|
85
|
+
config(config) {
|
|
86
|
+
if (!config.build) {
|
|
87
|
+
config.build = {};
|
|
88
|
+
}
|
|
89
|
+
if (!config.build.rollupOptions) {
|
|
90
|
+
config.build.rollupOptions = {};
|
|
91
|
+
}
|
|
92
|
+
if (!Array.isArray(config.build.rollupOptions.external)) {
|
|
93
|
+
config.build.rollupOptions.external = [];
|
|
94
|
+
}
|
|
95
|
+
const buildStudioExternals = enabled
|
|
96
|
+
? [...externalIds, ...STUDIO_IMPORTS]
|
|
97
|
+
: STUDIO_IMPORTS;
|
|
98
|
+
config.build.rollupOptions.external.push(...buildStudioExternals);
|
|
99
|
+
},
|
|
100
|
+
closeBundle() {
|
|
101
|
+
if (!enabled) {
|
|
102
|
+
fs.copyFileSync(fileURLToPath(import.meta.resolve("../hmr.js")), join(connectPath, "hmr.js"));
|
|
103
|
+
// Copy the .env file to the dist folder
|
|
104
|
+
fs.copyFileSync(join(connectPath, "../.env"), join(connectPath, ".env"));
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
configureServer(server) {
|
|
108
|
+
watchLocalFiles(server, localDocumentModelsPath, localDocumentEditorsPath);
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
];
|
|
112
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const Button: import("react").ForwardRefExoticComponent<Omit<Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
|
|
2
|
+
ref?: ((instance: HTMLButtonElement | null) => void | import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | import("react").RefObject<HTMLButtonElement> | null | undefined;
|
|
3
|
+
}, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
|
|
4
|
+
//# sourceMappingURL=button.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../../document-model-editor/components/button.tsx"],"names":[],"mappings":"AAKA,eAAO,MAAM,MAAM;;6DAYjB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import { cn } from "../utils/style.js";
|
|
4
|
+
export const Button = forwardRef((props, ref) => {
|
|
5
|
+
const { className, ...rest } = props;
|
|
6
|
+
return (_jsx("button", { ref: ref, ...rest, className: cn("h-10 whitespace-nowrap rounded-md border border-gray-200 bg-gray-50 px-4 py-2 text-sm font-medium text-gray-800 transition-colors hover:bg-gray-100 hover:text-gray-900 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50", className) }));
|
|
7
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Diagnostic } from "@codemirror/lint";
|
|
2
|
+
type Props = {
|
|
3
|
+
doc: string;
|
|
4
|
+
readonly?: boolean;
|
|
5
|
+
updateDocumentInModel?: (newDoc: string) => void;
|
|
6
|
+
customLinter?: (doc: string) => Diagnostic[];
|
|
7
|
+
};
|
|
8
|
+
export declare const GraphqlEditor: import("react").NamedExoticComponent<Props>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=graphql-editor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-editor.d.ts","sourceRoot":"","sources":["../../../../document-model-editor/components/code-editors/graphql-editor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAgB,MAAM,kBAAkB,CAAC;AAqB5D,KAAK,KAAK,GAAG;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qBAAqB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,UAAU,EAAE,CAAC;CAC9C,CAAC;AAEF,eAAO,MAAM,aAAa,6CA0FxB,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forceLinting } from "@codemirror/lint";
|
|
3
|
+
import { Compartment, EditorState } from "@codemirror/state";
|
|
4
|
+
import { EditorView, keymap } from "@codemirror/view";
|
|
5
|
+
import { getSchema, graphql } from "cm6-graphql";
|
|
6
|
+
import { buildSchema, printSchema } from "graphql";
|
|
7
|
+
import { memo, useEffect, useRef } from "react";
|
|
8
|
+
import { ayuLight } from "thememirror";
|
|
9
|
+
import { useSchemaContext } from "../../context/schema-context.js";
|
|
10
|
+
import { baseEditorExtensions, baseKeymap, makeFocusHandler, makeLinter, makePasteHandler, makeUpdateHandler, useDocumentSync, useEditorCleanup, useEditorRefs, useHandlerReconfiguration, } from "./utils.js";
|
|
11
|
+
export const GraphqlEditor = memo(function GraphqlEditor(props) {
|
|
12
|
+
const { doc, readonly = false, updateDocumentInModel, customLinter } = props;
|
|
13
|
+
const { editorRef, viewRef, updateListenerCompartment, focusHandlerCompartment, pasteHandlerCompartment, timeoutRef, } = useEditorRefs();
|
|
14
|
+
// GraphQL-specific refs
|
|
15
|
+
const graphqlCompartment = useRef(new Compartment());
|
|
16
|
+
const linterCompartment = useRef(new Compartment());
|
|
17
|
+
const sharedSchema = useSchemaContext();
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!viewRef.current) {
|
|
20
|
+
const schema = buildSchema(sharedSchema);
|
|
21
|
+
viewRef.current = new EditorView({
|
|
22
|
+
state: EditorState.create({
|
|
23
|
+
doc,
|
|
24
|
+
extensions: [
|
|
25
|
+
...baseEditorExtensions,
|
|
26
|
+
keymap.of(baseKeymap),
|
|
27
|
+
ayuLight,
|
|
28
|
+
graphqlCompartment.current.of(graphql(schema)),
|
|
29
|
+
linterCompartment.current.of(makeLinter(schema, customLinter)),
|
|
30
|
+
updateListenerCompartment.current.of(makeUpdateHandler(readonly, timeoutRef, updateDocumentInModel)),
|
|
31
|
+
focusHandlerCompartment.current.of(makeFocusHandler(readonly, timeoutRef, updateDocumentInModel)),
|
|
32
|
+
pasteHandlerCompartment.current.of(makePasteHandler(readonly, timeoutRef, updateDocumentInModel)),
|
|
33
|
+
EditorState.readOnly.of(readonly),
|
|
34
|
+
],
|
|
35
|
+
}),
|
|
36
|
+
parent: editorRef.current,
|
|
37
|
+
});
|
|
38
|
+
forceLinting(viewRef.current);
|
|
39
|
+
}
|
|
40
|
+
}, []);
|
|
41
|
+
useEditorCleanup(viewRef);
|
|
42
|
+
/* GraphQL-specific: Reconfigures the editor when the schema changes */
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
const view = viewRef.current;
|
|
45
|
+
if (!view)
|
|
46
|
+
return;
|
|
47
|
+
// @ts-expect-error
|
|
48
|
+
const existingSchema = getSchema(view.state);
|
|
49
|
+
const existingSchemaString = existingSchema
|
|
50
|
+
? printSchema(existingSchema)
|
|
51
|
+
: null;
|
|
52
|
+
if (!existingSchema || existingSchemaString !== sharedSchema) {
|
|
53
|
+
try {
|
|
54
|
+
const newSchema = buildSchema(sharedSchema);
|
|
55
|
+
view.dispatch({
|
|
56
|
+
effects: [
|
|
57
|
+
graphqlCompartment.current.reconfigure(graphql(newSchema)),
|
|
58
|
+
linterCompartment.current.reconfigure(makeLinter(newSchema, customLinter)),
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
forceLinting(view);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
console.debug("in schema update", error);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}, [sharedSchema, customLinter]);
|
|
68
|
+
useHandlerReconfiguration(viewRef.current, readonly, timeoutRef, updateDocumentInModel, {
|
|
69
|
+
updateListener: updateListenerCompartment.current,
|
|
70
|
+
focusHandler: focusHandlerCompartment.current,
|
|
71
|
+
pasteHandler: pasteHandlerCompartment.current,
|
|
72
|
+
});
|
|
73
|
+
useDocumentSync(viewRef.current, doc);
|
|
74
|
+
return _jsx("div", { ref: editorRef });
|
|
75
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-editor.d.ts","sourceRoot":"","sources":["../../../../document-model-editor/components/code-editors/json-editor.tsx"],"names":[],"mappings":"AAkBA,KAAK,KAAK,GAAG;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,qBAAqB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CAClD,CAAC;AAEF,eAAO,MAAM,UAAU,6CA0DrB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { linter, forceLinting } from "@codemirror/lint";
|
|
3
|
+
import { EditorState } from "@codemirror/state";
|
|
4
|
+
import { EditorView, keymap } from "@codemirror/view";
|
|
5
|
+
import { memo, useEffect } from "react";
|
|
6
|
+
import { ayuLight } from "thememirror";
|
|
7
|
+
import { json, jsonLanguage, jsonParseLinter } from "@codemirror/lang-json";
|
|
8
|
+
import { useEditorRefs, baseEditorExtensions, baseKeymap, makeUpdateHandler, makeFocusHandler, makePasteHandler, useEditorCleanup, useHandlerReconfiguration, useDocumentSync, } from "./utils.js";
|
|
9
|
+
export const JSONEditor = memo(function JSONEditor(props) {
|
|
10
|
+
const { doc, readonly = false, updateDocumentInModel } = props;
|
|
11
|
+
const { editorRef, viewRef, updateListenerCompartment, focusHandlerCompartment, pasteHandlerCompartment, timeoutRef, } = useEditorRefs();
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!viewRef.current) {
|
|
14
|
+
viewRef.current = new EditorView({
|
|
15
|
+
state: EditorState.create({
|
|
16
|
+
doc,
|
|
17
|
+
extensions: [
|
|
18
|
+
...baseEditorExtensions,
|
|
19
|
+
keymap.of(baseKeymap),
|
|
20
|
+
ayuLight,
|
|
21
|
+
jsonLanguage,
|
|
22
|
+
json(),
|
|
23
|
+
linter(jsonParseLinter()),
|
|
24
|
+
updateListenerCompartment.current.of(makeUpdateHandler(readonly, timeoutRef, updateDocumentInModel)),
|
|
25
|
+
focusHandlerCompartment.current.of(makeFocusHandler(readonly, timeoutRef, updateDocumentInModel)),
|
|
26
|
+
pasteHandlerCompartment.current.of(makePasteHandler(readonly, timeoutRef, updateDocumentInModel)),
|
|
27
|
+
EditorState.readOnly.of(readonly),
|
|
28
|
+
],
|
|
29
|
+
}),
|
|
30
|
+
parent: editorRef.current,
|
|
31
|
+
});
|
|
32
|
+
forceLinting(viewRef.current);
|
|
33
|
+
}
|
|
34
|
+
}, []);
|
|
35
|
+
useEditorCleanup(viewRef);
|
|
36
|
+
useHandlerReconfiguration(viewRef.current, readonly, timeoutRef, updateDocumentInModel, {
|
|
37
|
+
updateListener: updateListenerCompartment.current,
|
|
38
|
+
focusHandler: focusHandlerCompartment.current,
|
|
39
|
+
pasteHandler: pasteHandlerCompartment.current,
|
|
40
|
+
});
|
|
41
|
+
useDocumentSync(viewRef.current, doc);
|
|
42
|
+
return _jsx("div", { ref: editorRef });
|
|
43
|
+
});
|