@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,116 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createDefaultRules, isDocumentString } from "@graphql-tools/utils";
|
|
3
|
+
import { buildASTSchema, buildSchema, Kind, parse, printSchema, validate, } from "graphql";
|
|
4
|
+
import { createContext, useContext, useEffect, useState } from "react";
|
|
5
|
+
import { hiddenQueryTypeDefDoc, initialSchema, typeDefsDoc, } from "../constants/documents.js";
|
|
6
|
+
/* Required to make the schema "count" as an actual schema */
|
|
7
|
+
const hiddenQueryTypeDefinitions = parse(hiddenQueryTypeDefDoc).definitions;
|
|
8
|
+
/* Scalar definitions from the Powerhouse standard library */
|
|
9
|
+
const standardLibCustomScalarDefinitions = parse(typeDefsDoc).definitions;
|
|
10
|
+
/* These are always included when updating the shared schema, because they do not change */
|
|
11
|
+
const alwaysIncludedDefinitions = [
|
|
12
|
+
...hiddenQueryTypeDefinitions,
|
|
13
|
+
...standardLibCustomScalarDefinitions,
|
|
14
|
+
];
|
|
15
|
+
/* We use almost all of the standard graphql rules, but not the ExecutableDefinitionsRule because our schemas are not intended to be executed */
|
|
16
|
+
const rules = createDefaultRules().filter((rule) => rule.name !== "ExecutableDefinitionsRule");
|
|
17
|
+
/*
|
|
18
|
+
Makes one SDL string from all of the definitions in the state and operation schemas
|
|
19
|
+
Uses try catch to prevent errors from breaking the editor
|
|
20
|
+
*/
|
|
21
|
+
function makeSharedSchemaSdl(existingSchemaSdl, globalStateSchemaSdl, localStateSchemaSdl, operationSchemasSdl) {
|
|
22
|
+
try {
|
|
23
|
+
const existingSchema = buildSchema(existingSchemaSdl);
|
|
24
|
+
const sdls = [
|
|
25
|
+
globalStateSchemaSdl,
|
|
26
|
+
localStateSchemaSdl,
|
|
27
|
+
operationSchemasSdl,
|
|
28
|
+
].filter(Boolean);
|
|
29
|
+
const asts = sdls
|
|
30
|
+
.map((sdl) => (sdl ? safeParseSdl(sdl) : null))
|
|
31
|
+
.filter((ast) => ast !== null);
|
|
32
|
+
const documentNode = makeSafeDocumentNode(existingSchema, asts);
|
|
33
|
+
const schemaSdl = printSchema(buildASTSchema(documentNode));
|
|
34
|
+
return schemaSdl;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.debug("in make shared schema", error);
|
|
38
|
+
return existingSchemaSdl;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/*
|
|
42
|
+
Combines all of the definitions in the state and operation schemas into one document node
|
|
43
|
+
Uses try catch to prevent errors from breaking the editor
|
|
44
|
+
*/
|
|
45
|
+
function makeSafeDocumentNode(schema, asts) {
|
|
46
|
+
try {
|
|
47
|
+
const definitions = [...alwaysIncludedDefinitions];
|
|
48
|
+
for (const ast of asts) {
|
|
49
|
+
for (const definition of ast.definitions) {
|
|
50
|
+
const definitionDocumentNode = {
|
|
51
|
+
kind: Kind.DOCUMENT,
|
|
52
|
+
definitions: [definition],
|
|
53
|
+
};
|
|
54
|
+
if (safeValidateAst(schema, definitionDocumentNode)) {
|
|
55
|
+
definitions.push(definition);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const documentNode = {
|
|
60
|
+
kind: Kind.DOCUMENT,
|
|
61
|
+
definitions,
|
|
62
|
+
};
|
|
63
|
+
return documentNode;
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
console.debug("in make safe document node", error);
|
|
67
|
+
return {
|
|
68
|
+
kind: Kind.DOCUMENT,
|
|
69
|
+
definitions: alwaysIncludedDefinitions,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/*
|
|
74
|
+
Validates an ast against the schema
|
|
75
|
+
Uses try catch to prevent errors from breaking the editor
|
|
76
|
+
*/
|
|
77
|
+
function safeValidateAst(schema, ast) {
|
|
78
|
+
try {
|
|
79
|
+
const errors = validate(schema, ast, rules);
|
|
80
|
+
return !errors.length;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
console.debug("in safe validate", error);
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/*
|
|
88
|
+
Parses an SDL string into an ast
|
|
89
|
+
Uses try catch abd checks if the SDL is a valid document string to prevent errors from breaking the editor
|
|
90
|
+
*/
|
|
91
|
+
function safeParseSdl(sdl) {
|
|
92
|
+
try {
|
|
93
|
+
if (!sdl || !isDocumentString(sdl))
|
|
94
|
+
return null;
|
|
95
|
+
return parse(sdl);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export const SchemaContext = createContext(printSchema(initialSchema));
|
|
102
|
+
/*
|
|
103
|
+
Provides the shared schema to the editor
|
|
104
|
+
We use the sdl string form to make memoization easier
|
|
105
|
+
*/
|
|
106
|
+
export function SchemaContextProvider(props) {
|
|
107
|
+
const { children, globalStateSchemaSdl, localStateSchemaSdl, operationSchemasSdl, } = props;
|
|
108
|
+
const [sharedSchemaSdl, setSharedSchemaSdl] = useState(() => makeSharedSchemaSdl(printSchema(initialSchema), globalStateSchemaSdl, localStateSchemaSdl, operationSchemasSdl));
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
setSharedSchemaSdl((prev) => makeSharedSchemaSdl(prev, globalStateSchemaSdl, localStateSchemaSdl, operationSchemasSdl));
|
|
111
|
+
}, [globalStateSchemaSdl, localStateSchemaSdl, operationSchemasSdl]);
|
|
112
|
+
return (_jsx(SchemaContext.Provider, { value: sharedSchemaSdl, children: children }));
|
|
113
|
+
}
|
|
114
|
+
export function useSchemaContext() {
|
|
115
|
+
return useContext(SchemaContext);
|
|
116
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Meta } from "@storybook/react";
|
|
2
|
+
import { DocumentModelEditor } from "./editor.js";
|
|
3
|
+
declare const Empty: import("@storybook/types").StoryAnnotations<import("@storybook/react").ReactRenderer, import("document-model").EditorProps<import("document-model").DocumentModelDocument> & Partial<{
|
|
4
|
+
isAllowedToCreateDocuments: boolean;
|
|
5
|
+
isAllowedToEditDocuments: boolean;
|
|
6
|
+
canUndo: boolean;
|
|
7
|
+
canRedo: boolean;
|
|
8
|
+
onSwitchboardLinkClick: (() => void) | undefined;
|
|
9
|
+
onExport: () => void;
|
|
10
|
+
onClose: () => void;
|
|
11
|
+
onShowRevisionHistory: () => void;
|
|
12
|
+
simulateBackgroundUpdates?: {
|
|
13
|
+
backgroundUpdateRate: number;
|
|
14
|
+
backgroundUpdateActions: ((document: import("document-model").DocumentModelDocument) => import("document-model").DocumentModelAction)[];
|
|
15
|
+
} | undefined;
|
|
16
|
+
}>>;
|
|
17
|
+
declare const WithData: import("@storybook/types").StoryAnnotations<import("@storybook/react").ReactRenderer, import("document-model").EditorProps<import("document-model").DocumentModelDocument> & Partial<{
|
|
18
|
+
isAllowedToCreateDocuments: boolean;
|
|
19
|
+
isAllowedToEditDocuments: boolean;
|
|
20
|
+
canUndo: boolean;
|
|
21
|
+
canRedo: boolean;
|
|
22
|
+
onSwitchboardLinkClick: (() => void) | undefined;
|
|
23
|
+
onExport: () => void;
|
|
24
|
+
onClose: () => void;
|
|
25
|
+
onShowRevisionHistory: () => void;
|
|
26
|
+
simulateBackgroundUpdates?: {
|
|
27
|
+
backgroundUpdateRate: number;
|
|
28
|
+
backgroundUpdateActions: ((document: import("document-model").DocumentModelDocument) => import("document-model").DocumentModelAction)[];
|
|
29
|
+
} | undefined;
|
|
30
|
+
}>>;
|
|
31
|
+
declare const WithBackgroundUpdates: import("@storybook/types").StoryAnnotations<import("@storybook/react").ReactRenderer, import("document-model").EditorProps<import("document-model").DocumentModelDocument> & Partial<{
|
|
32
|
+
isAllowedToCreateDocuments: boolean;
|
|
33
|
+
isAllowedToEditDocuments: boolean;
|
|
34
|
+
canUndo: boolean;
|
|
35
|
+
canRedo: boolean;
|
|
36
|
+
onSwitchboardLinkClick: (() => void) | undefined;
|
|
37
|
+
onExport: () => void;
|
|
38
|
+
onClose: () => void;
|
|
39
|
+
onShowRevisionHistory: () => void;
|
|
40
|
+
simulateBackgroundUpdates?: {
|
|
41
|
+
backgroundUpdateRate: number;
|
|
42
|
+
backgroundUpdateActions: ((document: import("document-model").DocumentModelDocument) => import("document-model").DocumentModelAction)[];
|
|
43
|
+
} | undefined;
|
|
44
|
+
}>>;
|
|
45
|
+
declare const _default: Meta<typeof DocumentModelEditor>;
|
|
46
|
+
export default _default;
|
|
47
|
+
export { Empty, WithBackgroundUpdates, WithData };
|
|
48
|
+
//# sourceMappingURL=document-model-editor.stories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-model-editor.stories.d.ts","sourceRoot":"","sources":["../../document-model-editor/document-model-editor.stories.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAMxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,QAAA,MAAmC,KAAK;;;;;;;;;;;;;GAIvC,CAAC;AAEF,QAAA,MAA6B,QAAQ;;;;;;;;;;;;;GAoGpC,CAAC;AAEF,QAAA,MAA6B,qBAAqB;;;;;;;;;;;;;GA+KjD,CAAC;wBAEuD,IAAI,CAC3D,OAAO,mBAAmB,CAC3B;AAFD,wBAEE;AAEF,OAAO,EAAE,KAAK,EAAE,qBAAqB,EAAE,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { createDocumentStory } from "#editor-utils/storybook";
|
|
2
|
+
import { documentModelCreateExtendedState, documentModelReducer, } from "document-model";
|
|
3
|
+
import { v7 as uuidv7 } from "uuid";
|
|
4
|
+
import { DocumentModelEditor } from "./editor.js";
|
|
5
|
+
const { meta, CreateDocumentStory: Empty } = createDocumentStory(DocumentModelEditor, documentModelReducer, documentModelCreateExtendedState());
|
|
6
|
+
const { CreateDocumentStory: WithData } = createDocumentStory(DocumentModelEditor, documentModelReducer, documentModelCreateExtendedState({
|
|
7
|
+
state: {
|
|
8
|
+
global: {
|
|
9
|
+
id: "test type",
|
|
10
|
+
name: "test",
|
|
11
|
+
extension: ".test.ph",
|
|
12
|
+
description: "test description",
|
|
13
|
+
author: {
|
|
14
|
+
name: "test user",
|
|
15
|
+
website: "https://test.com",
|
|
16
|
+
},
|
|
17
|
+
specifications: [
|
|
18
|
+
{
|
|
19
|
+
version: 1,
|
|
20
|
+
changeLog: [],
|
|
21
|
+
state: {
|
|
22
|
+
global: {
|
|
23
|
+
schema: 'type TestState {\n "Add your global state fields here"\n _placeholder: String\n something: Int\n another: Boolean\n}',
|
|
24
|
+
initialValue: '{\n "_placeholder": "",\n "something": 0,\n "another": false\n}',
|
|
25
|
+
examples: [],
|
|
26
|
+
},
|
|
27
|
+
local: {
|
|
28
|
+
schema: 'type TestLocalState {\n "Add your local state fields here"\n _placeholder: String\n test: String\n another: Int\n}',
|
|
29
|
+
initialValue: '{\n "_placeholder": "",\n "test": "",\n "another": 0\n}',
|
|
30
|
+
examples: [],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
modules: [
|
|
34
|
+
{
|
|
35
|
+
id: "TuKeTdrcoKwzZe0ZJQCrWLr4pGw=",
|
|
36
|
+
name: "test_module",
|
|
37
|
+
description: "",
|
|
38
|
+
operations: [
|
|
39
|
+
{
|
|
40
|
+
id: "NEYEmynbmVnx5ZlESaoVx18pl38=",
|
|
41
|
+
name: "TEST_OPERATION",
|
|
42
|
+
description: "test operation description",
|
|
43
|
+
schema: 'input TestOperationInput {\n "Add your inputs here"\n _placeholder: String\n test: TestInput\n}\n\ninput TestInput {\n test: String\n}',
|
|
44
|
+
template: "",
|
|
45
|
+
reducer: "",
|
|
46
|
+
errors: [
|
|
47
|
+
{
|
|
48
|
+
id: "FwZyM4KAxRO+GurVuSRxgaENKSk=",
|
|
49
|
+
name: "TestException",
|
|
50
|
+
code: "",
|
|
51
|
+
description: "",
|
|
52
|
+
template: "",
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
examples: [],
|
|
56
|
+
scope: "global",
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "Uix/waNZU0L0Q6bryt7QFnf3aoA=",
|
|
62
|
+
name: "another_test_module",
|
|
63
|
+
description: "",
|
|
64
|
+
operations: [
|
|
65
|
+
{
|
|
66
|
+
id: "iDXCKGVaDPPCyTVxv8vQ2h7SVvw=",
|
|
67
|
+
name: "ANOTHER_TEST_OPERATION",
|
|
68
|
+
description: "another description",
|
|
69
|
+
schema: 'input AnotherTestOperationInput {\n "Add your inputs here"\n _placeholder: String\n test: Int\n}',
|
|
70
|
+
template: "",
|
|
71
|
+
reducer: "",
|
|
72
|
+
errors: [],
|
|
73
|
+
examples: [],
|
|
74
|
+
scope: "global",
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: "N2Flem5MW4dnLd0y21si2J0ZA9E=",
|
|
78
|
+
name: "ONE_MORE_OPERATION",
|
|
79
|
+
description: "one more description",
|
|
80
|
+
schema: 'input OneMoreOperationInput {\n "Add your inputs here"\n _placeholder: String\n}',
|
|
81
|
+
template: "",
|
|
82
|
+
reducer: "",
|
|
83
|
+
errors: [],
|
|
84
|
+
examples: [],
|
|
85
|
+
scope: "global",
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
local: {},
|
|
94
|
+
},
|
|
95
|
+
}));
|
|
96
|
+
const { CreateDocumentStory: WithBackgroundUpdates } = createDocumentStory(DocumentModelEditor, documentModelReducer, documentModelCreateExtendedState({
|
|
97
|
+
state: {
|
|
98
|
+
global: {
|
|
99
|
+
id: "test type",
|
|
100
|
+
name: "test",
|
|
101
|
+
extension: ".test.ph",
|
|
102
|
+
description: "test description",
|
|
103
|
+
author: {
|
|
104
|
+
name: "test user",
|
|
105
|
+
website: "https://test.com",
|
|
106
|
+
},
|
|
107
|
+
specifications: [
|
|
108
|
+
{
|
|
109
|
+
version: 1,
|
|
110
|
+
changeLog: [],
|
|
111
|
+
state: {
|
|
112
|
+
global: {
|
|
113
|
+
schema: 'type TestState {\n "Add your global state fields here"\n _placeholder: String\n something: Int\n another: Boolean\n}',
|
|
114
|
+
initialValue: '{\n "_placeholder": "",\n "something": 0,\n "another": false\n}',
|
|
115
|
+
examples: [],
|
|
116
|
+
},
|
|
117
|
+
local: {
|
|
118
|
+
schema: 'type TestLocalState {\n "Add your local state fields here"\n _placeholder: String\n test: String\n another: Int\n}',
|
|
119
|
+
initialValue: '{\n "_placeholder": "",\n "test": "",\n "another": 0\n}',
|
|
120
|
+
examples: [],
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
modules: [
|
|
124
|
+
{
|
|
125
|
+
id: "TuKeTdrcoKwzZe0ZJQCrWLr4pGw=",
|
|
126
|
+
name: "test_module",
|
|
127
|
+
description: "",
|
|
128
|
+
operations: [
|
|
129
|
+
{
|
|
130
|
+
id: "NEYEmynbmVnx5ZlESaoVx18pl38=",
|
|
131
|
+
name: "TEST_OPERATION",
|
|
132
|
+
description: "test operation description",
|
|
133
|
+
schema: 'input TestOperationInput {\n "Add your inputs here"\n _placeholder: String\n test: TestInput\n}\n\ninput TestInput {\n test: String\n}',
|
|
134
|
+
template: "",
|
|
135
|
+
reducer: "",
|
|
136
|
+
errors: [
|
|
137
|
+
{
|
|
138
|
+
id: "FwZyM4KAxRO+GurVuSRxgaENKSk=",
|
|
139
|
+
name: "TestException",
|
|
140
|
+
code: "",
|
|
141
|
+
description: "",
|
|
142
|
+
template: "",
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
examples: [],
|
|
146
|
+
scope: "global",
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
id: "Uix/waNZU0L0Q6bryt7QFnf3aoA=",
|
|
152
|
+
name: "another_test_module",
|
|
153
|
+
description: "",
|
|
154
|
+
operations: [
|
|
155
|
+
{
|
|
156
|
+
id: "iDXCKGVaDPPCyTVxv8vQ2h7SVvw=",
|
|
157
|
+
name: "ANOTHER_TEST_OPERATION",
|
|
158
|
+
description: "another description",
|
|
159
|
+
schema: 'input AnotherTestOperationInput {\n "Add your inputs here"\n _placeholder: String\n test: Int\n}',
|
|
160
|
+
template: "",
|
|
161
|
+
reducer: "",
|
|
162
|
+
errors: [],
|
|
163
|
+
examples: [],
|
|
164
|
+
scope: "global",
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
id: "N2Flem5MW4dnLd0y21si2J0ZA9E=",
|
|
168
|
+
name: "ONE_MORE_OPERATION",
|
|
169
|
+
description: "one more description",
|
|
170
|
+
schema: 'input OneMoreOperationInput {\n "Add your inputs here"\n _placeholder: String\n}',
|
|
171
|
+
template: "",
|
|
172
|
+
reducer: "",
|
|
173
|
+
errors: [],
|
|
174
|
+
examples: [],
|
|
175
|
+
scope: "global",
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
},
|
|
183
|
+
local: {},
|
|
184
|
+
},
|
|
185
|
+
}), {
|
|
186
|
+
simulateBackgroundUpdates: {
|
|
187
|
+
backgroundUpdateRate: 1000,
|
|
188
|
+
backgroundUpdateActions: [
|
|
189
|
+
(document) => {
|
|
190
|
+
const id = uuidv7().split("-").at(-1);
|
|
191
|
+
const oldStateSchema = document.state.global.specifications[0].state.global.schema;
|
|
192
|
+
const newTypeDef = `
|
|
193
|
+
type TestDefinition${id} {
|
|
194
|
+
test: String
|
|
195
|
+
}`;
|
|
196
|
+
const newStateSchema = `${oldStateSchema}\n${newTypeDef}`;
|
|
197
|
+
return {
|
|
198
|
+
type: "SET_STATE_SCHEMA",
|
|
199
|
+
input: {
|
|
200
|
+
schema: newStateSchema,
|
|
201
|
+
scope: "global",
|
|
202
|
+
},
|
|
203
|
+
scope: "global",
|
|
204
|
+
};
|
|
205
|
+
},
|
|
206
|
+
(document) => {
|
|
207
|
+
const id = uuidv7().split("-").at(-1);
|
|
208
|
+
const oldStateSchema = document.state.global.specifications[0].state.local.schema;
|
|
209
|
+
const newTypeDef = `
|
|
210
|
+
type TestLocalDefinition${id} {
|
|
211
|
+
test: String
|
|
212
|
+
}`;
|
|
213
|
+
const newStateSchema = `${oldStateSchema}\n${newTypeDef}`;
|
|
214
|
+
return {
|
|
215
|
+
type: "SET_STATE_SCHEMA",
|
|
216
|
+
input: {
|
|
217
|
+
schema: newStateSchema,
|
|
218
|
+
scope: "local",
|
|
219
|
+
},
|
|
220
|
+
scope: "global",
|
|
221
|
+
};
|
|
222
|
+
},
|
|
223
|
+
(document) => {
|
|
224
|
+
const moduleIndex = document.state.global.specifications[0].modules.length + 1;
|
|
225
|
+
return {
|
|
226
|
+
type: "ADD_MODULE",
|
|
227
|
+
input: {
|
|
228
|
+
id: uuidv7(),
|
|
229
|
+
name: `test_module_${moduleIndex}`,
|
|
230
|
+
},
|
|
231
|
+
scope: "global",
|
|
232
|
+
};
|
|
233
|
+
},
|
|
234
|
+
(document) => {
|
|
235
|
+
const modules = document.state.global.specifications[0].modules;
|
|
236
|
+
const module = modules[0];
|
|
237
|
+
const operationIndex = module.operations.length + 1;
|
|
238
|
+
return {
|
|
239
|
+
type: "ADD_OPERATION",
|
|
240
|
+
input: {
|
|
241
|
+
id: uuidv7(),
|
|
242
|
+
name: `test_operation_${operationIndex}`,
|
|
243
|
+
moduleId: module.id,
|
|
244
|
+
},
|
|
245
|
+
scope: "global",
|
|
246
|
+
};
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
export default { ...meta, title: "Document Model 2" };
|
|
252
|
+
export { Empty, WithBackgroundUpdates, WithData };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../../document-model-editor/editor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAOL,qBAAqB,EACrB,WAAW,EAeZ,MAAM,gBAAgB,CAAC;AAcxB,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,CAAC,qBAAqB,CAAC,2CAqX5E"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { addModule, addOperation, addOperationError, deleteModule, deleteOperation, deleteOperationError, hashKey, setAuthorName, setAuthorWebsite, setInitialState, setModelDescription, setModelExtension, setModelId, setModelName, setModuleName, setOperationDescription, setOperationErrorName, setOperationName, setOperationSchema, setStateSchema, } from "document-model";
|
|
3
|
+
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
4
|
+
import { Divider } from "./components/divider.js";
|
|
5
|
+
import { ModelMetadata } from "./components/model-metadata-form.js";
|
|
6
|
+
import { Modules } from "./components/modules.js";
|
|
7
|
+
import { StateSchemas } from "./components/state-schemas.js";
|
|
8
|
+
import { SchemaContextProvider } from "./context/schema-context.js";
|
|
9
|
+
import { compareStringsWithoutWhitespace, initializeModelSchema, makeOperationInitialDoc, } from "./utils/helpers.js";
|
|
10
|
+
export function DocumentModelEditor(props) {
|
|
11
|
+
const { document, documentNodeName, dispatch } = props;
|
|
12
|
+
const { name: modelName, id: documentType, extension, description, author: { name: authorName, website: authorWebsite }, } = useMemo(() => document.state.global, [document.state.global]);
|
|
13
|
+
const { state: { global: { schema: globalStateSchema, initialValue: globalStateInitialValue, }, local: { schema: localStateSchema, initialValue: localStateInitialValue }, }, modules, } = useMemo(() => document.state.global.specifications[0], [document.state.global.specifications[0]]);
|
|
14
|
+
const operations = useMemo(() => modules.flatMap((module) => module.operations), [modules]);
|
|
15
|
+
const shouldSetInitialName = useRef(!modelName && !!documentNodeName && operations.length === 0);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!shouldSetInitialName.current || !documentNodeName)
|
|
18
|
+
return;
|
|
19
|
+
dispatch(setModelName({ name: documentNodeName }));
|
|
20
|
+
// Initialize schema if it's the first time setting the name
|
|
21
|
+
initializeModelSchema({
|
|
22
|
+
modelName: documentNodeName,
|
|
23
|
+
setStateSchema: (schema, scope) => {
|
|
24
|
+
dispatch(setStateSchema({ schema, scope }));
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
shouldSetInitialName.current = false;
|
|
28
|
+
}, [documentNodeName]);
|
|
29
|
+
const operationSchemasSdl = useMemo(() => operations.flatMap((operation) => operation.schema ?? []).join("\n"), [operations]);
|
|
30
|
+
const handleSetModelId = useCallback((id) => {
|
|
31
|
+
if (compareStringsWithoutWhitespace(id, documentType))
|
|
32
|
+
return;
|
|
33
|
+
dispatch(setModelId({ id }));
|
|
34
|
+
}, [documentType]);
|
|
35
|
+
const handleSetModelDescription = useCallback((newDescription) => {
|
|
36
|
+
if (compareStringsWithoutWhitespace(newDescription, description))
|
|
37
|
+
return;
|
|
38
|
+
dispatch(setModelDescription({ description: newDescription }));
|
|
39
|
+
}, [description]);
|
|
40
|
+
const handleSetModelExtension = useCallback((newExtension) => {
|
|
41
|
+
if (compareStringsWithoutWhitespace(newExtension, extension))
|
|
42
|
+
return;
|
|
43
|
+
dispatch(setModelExtension({ extension: newExtension }));
|
|
44
|
+
}, [extension]);
|
|
45
|
+
const handleSetModelName = useCallback((newName) => {
|
|
46
|
+
if (compareStringsWithoutWhitespace(newName, modelName))
|
|
47
|
+
return;
|
|
48
|
+
dispatch(setModelName({ name: newName }));
|
|
49
|
+
}, [modelName]);
|
|
50
|
+
const handleSetAuthorName = useCallback((newAuthorName) => {
|
|
51
|
+
if (compareStringsWithoutWhitespace(newAuthorName, authorName))
|
|
52
|
+
return;
|
|
53
|
+
dispatch(setAuthorName({ authorName: newAuthorName }));
|
|
54
|
+
}, [authorName]);
|
|
55
|
+
const handleSetAuthorWebsite = useCallback((newAuthorWebsite) => {
|
|
56
|
+
if (compareStringsWithoutWhitespace(newAuthorWebsite, authorWebsite ?? ""))
|
|
57
|
+
return;
|
|
58
|
+
dispatch(setAuthorWebsite({ authorWebsite: newAuthorWebsite }));
|
|
59
|
+
}, [authorWebsite]);
|
|
60
|
+
const handleSetStateSchema = useCallback((newSchema, scope) => {
|
|
61
|
+
const oldSchema = scope === "global" ? globalStateSchema : localStateSchema;
|
|
62
|
+
if (compareStringsWithoutWhitespace(newSchema, oldSchema))
|
|
63
|
+
return;
|
|
64
|
+
dispatch(setStateSchema({ schema: newSchema, scope }));
|
|
65
|
+
}, [globalStateSchema, localStateSchema]);
|
|
66
|
+
const handleSetInitialState = useCallback((newInitialValue, scope) => {
|
|
67
|
+
const oldInitialValue = scope === "global" ? globalStateInitialValue : localStateInitialValue;
|
|
68
|
+
if (compareStringsWithoutWhitespace(newInitialValue, oldInitialValue))
|
|
69
|
+
return;
|
|
70
|
+
dispatch(setInitialState({ initialValue: newInitialValue, scope }));
|
|
71
|
+
}, [globalStateInitialValue, localStateInitialValue]);
|
|
72
|
+
const handleAddModule = useCallback((name) => {
|
|
73
|
+
return new Promise((resolve) => {
|
|
74
|
+
try {
|
|
75
|
+
if (modules.some((module) => compareStringsWithoutWhitespace(module.name, name))) {
|
|
76
|
+
resolve(undefined);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const id = hashKey();
|
|
80
|
+
dispatch(addModule({ id, name }));
|
|
81
|
+
resolve(id);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
console.error("Failed to add module:", error);
|
|
85
|
+
resolve(undefined);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}, [modules]);
|
|
89
|
+
const handleSetModuleName = useCallback((id, name) => {
|
|
90
|
+
if (modules.some((module) => compareStringsWithoutWhitespace(module.name, name)))
|
|
91
|
+
return;
|
|
92
|
+
dispatch(setModuleName({ id, name }));
|
|
93
|
+
}, [modules]);
|
|
94
|
+
const handleDeleteModule = useCallback((id) => dispatch(deleteModule({ id })), []);
|
|
95
|
+
const handleAddOperation = useCallback((moduleId, name) => {
|
|
96
|
+
return new Promise((resolve) => {
|
|
97
|
+
try {
|
|
98
|
+
const moduleOperationNames = modules
|
|
99
|
+
.find((module) => module.id === moduleId)
|
|
100
|
+
?.operations.map((operation) => operation.name)
|
|
101
|
+
.filter(Boolean) ?? [];
|
|
102
|
+
if (moduleOperationNames.some((opName) => compareStringsWithoutWhitespace(opName, name))) {
|
|
103
|
+
resolve(undefined);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const id = hashKey();
|
|
107
|
+
dispatch(addOperation({ id, moduleId, name }));
|
|
108
|
+
resolve(id);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
console.error("Failed to add operation:", error);
|
|
112
|
+
resolve(undefined);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}, [modules]);
|
|
116
|
+
const handleSetOperationName = useCallback((id, name) => {
|
|
117
|
+
const operationModule = modules.find((module) => module.operations.some((operation) => operation.id === id));
|
|
118
|
+
const operationNames = operationModule?.operations
|
|
119
|
+
.map((operation) => operation.name)
|
|
120
|
+
.filter(Boolean) ?? [];
|
|
121
|
+
if (operationNames.some((opName) => compareStringsWithoutWhitespace(opName, name)))
|
|
122
|
+
return;
|
|
123
|
+
dispatch(setOperationName({ id, name }));
|
|
124
|
+
}, [modules]);
|
|
125
|
+
const handleSetOperationSchema = useCallback((id, newSchema) => {
|
|
126
|
+
const operation = operations.find((operation) => operation.id === id);
|
|
127
|
+
if (operation?.schema &&
|
|
128
|
+
compareStringsWithoutWhitespace(newSchema, operation.schema))
|
|
129
|
+
return;
|
|
130
|
+
dispatch(setOperationSchema({ id, schema: newSchema }));
|
|
131
|
+
}, [operations]);
|
|
132
|
+
const handleSetOperationDescription = useCallback((id, newDescription) => {
|
|
133
|
+
const operationDescription = operations.find((operation) => operation.id === id)?.description ?? "";
|
|
134
|
+
if (compareStringsWithoutWhitespace(operationDescription, newDescription))
|
|
135
|
+
return;
|
|
136
|
+
dispatch(setOperationDescription({ id, description: newDescription }));
|
|
137
|
+
}, [operations]);
|
|
138
|
+
const handleDeleteOperation = useCallback((id) => dispatch(deleteOperation({ id })), []);
|
|
139
|
+
const handleAddOperationError = useCallback((operationId, errorName) => {
|
|
140
|
+
return new Promise((resolve) => {
|
|
141
|
+
try {
|
|
142
|
+
const operation = operations.find((operation) => operation.id === operationId);
|
|
143
|
+
const operationErrorNames = operation?.errors.map((error) => error.name).filter(Boolean) ?? [];
|
|
144
|
+
if (operationErrorNames.some((name) => compareStringsWithoutWhitespace(name, errorName))) {
|
|
145
|
+
resolve(undefined);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const id = hashKey();
|
|
149
|
+
dispatch(addOperationError({ id, operationId, errorName }));
|
|
150
|
+
resolve(id);
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
console.error("Failed to add operation error:", error);
|
|
154
|
+
resolve(undefined);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}, [operations]);
|
|
158
|
+
const handleDeleteOperationError = useCallback((id) => dispatch(deleteOperationError({ id })), []);
|
|
159
|
+
const handleSetOperationErrorName = useCallback((operationId, errorId, errorName) => {
|
|
160
|
+
const operation = operations.find((operation) => operation.id === operationId);
|
|
161
|
+
const operationErrorNames = operation?.errors.map((error) => error.name).filter(Boolean) ?? [];
|
|
162
|
+
if (operationErrorNames.some((name) => compareStringsWithoutWhitespace(name, errorName)))
|
|
163
|
+
return;
|
|
164
|
+
dispatch(setOperationErrorName({ id: errorId, errorName }));
|
|
165
|
+
}, [operations]);
|
|
166
|
+
const addOperationAndInitialSchema = useCallback(async (moduleId, name) => {
|
|
167
|
+
try {
|
|
168
|
+
const id = await handleAddOperation(moduleId, name);
|
|
169
|
+
if (!id)
|
|
170
|
+
return undefined;
|
|
171
|
+
try {
|
|
172
|
+
handleSetOperationSchema(id, makeOperationInitialDoc(name));
|
|
173
|
+
return id;
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
console.error("Failed to update operation schema:", error);
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
console.error("Failed to add operation and schema:", error);
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
}, [handleAddOperation, handleSetOperationSchema]);
|
|
185
|
+
return (_jsx("main", { className: "min-h-dvh bg-gray-50", children: _jsx(SchemaContextProvider, { globalStateSchemaSdl: globalStateSchema, localStateSchemaSdl: localStateSchema, operationSchemasSdl: operationSchemasSdl, children: _jsxs("div", { className: "mx-auto max-w-6xl px-4 pt-8", children: [_jsx(ModelMetadata, { name: modelName, documentType: documentType, extension: extension, description: description, authorName: authorName, authorWebsite: authorWebsite ?? "", globalStateSchema: globalStateSchema, localStateSchema: localStateSchema, setModelId: handleSetModelId, setModelDescription: handleSetModelDescription, setModelExtension: handleSetModelExtension, setModelName: handleSetModelName, setAuthorName: handleSetAuthorName, setAuthorWebsite: handleSetAuthorWebsite, setStateSchema: handleSetStateSchema }), _jsx(Divider, {}), _jsxs("div", { children: [_jsx(StateSchemas, { modelName: modelName, globalStateSchema: globalStateSchema, globalStateInitialValue: globalStateInitialValue, localStateSchema: localStateSchema, localStateInitialValue: localStateInitialValue, setStateSchema: handleSetStateSchema, setInitialState: handleSetInitialState }), _jsx(Divider, {}), _jsx("h3", { className: "mb-6 text-lg", children: "Global Operations" }), _jsx(Modules, { modules: modules, allOperations: operations, addModule: handleAddModule, updateModuleName: handleSetModuleName, deleteModule: handleDeleteModule, updateOperationName: handleSetOperationName, updateOperationSchema: handleSetOperationSchema, setOperationDescription: handleSetOperationDescription, deleteOperation: handleDeleteOperation, addOperationError: handleAddOperationError, deleteOperationError: handleDeleteOperationError, setOperationErrorName: handleSetOperationErrorName, addOperationAndInitialSchema: addOperationAndInitialSchema })] })] }) }) }));
|
|
186
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const useFormField: () => {
|
|
2
|
+
invalid: boolean;
|
|
3
|
+
isDirty: boolean;
|
|
4
|
+
isTouched: boolean;
|
|
5
|
+
isValidating: boolean;
|
|
6
|
+
error?: import("react-hook-form").FieldError;
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
formItemId: string;
|
|
10
|
+
formDescriptionId: string;
|
|
11
|
+
formMessageId: string;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=useFormField.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormField.d.ts","sourceRoot":"","sources":["../../../document-model-editor/hooks/useFormField.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,YAAY;;;;;;;;;;;CAqBxB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useFormContext } from "react-hook-form";
|
|
3
|
+
import { FormFieldContext, FormItemContext } from "../context/form-context.js";
|
|
4
|
+
export const useFormField = () => {
|
|
5
|
+
const fieldContext = React.useContext(FormFieldContext);
|
|
6
|
+
const itemContext = React.useContext(FormItemContext);
|
|
7
|
+
const { getFieldState, formState } = useFormContext();
|
|
8
|
+
const fieldState = getFieldState(fieldContext.name, formState);
|
|
9
|
+
if (!fieldContext) {
|
|
10
|
+
throw new Error("useFormField should be used within <FormField>");
|
|
11
|
+
}
|
|
12
|
+
const { id } = itemContext;
|
|
13
|
+
return {
|
|
14
|
+
id,
|
|
15
|
+
name: fieldContext.name,
|
|
16
|
+
formItemId: `${id}-form-item`,
|
|
17
|
+
formDescriptionId: `${id}-form-item-description`,
|
|
18
|
+
formMessageId: `${id}-form-item-message`,
|
|
19
|
+
...fieldState,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../document-model-editor/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC"}
|