@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.
Files changed (189) hide show
  1. package/dist/connect-studio/helpers.d.ts +5 -0
  2. package/dist/connect-studio/helpers.d.ts.map +1 -0
  3. package/dist/connect-studio/helpers.js +43 -0
  4. package/dist/connect-studio/hmr.d.ts +12 -0
  5. package/dist/connect-studio/hmr.d.ts.map +1 -0
  6. package/dist/connect-studio/hmr.js +8 -0
  7. package/dist/connect-studio/index.d.ts +9 -0
  8. package/dist/connect-studio/index.d.ts.map +1 -0
  9. package/dist/connect-studio/index.js +7 -0
  10. package/dist/connect-studio/server.d.ts +3 -0
  11. package/dist/connect-studio/server.d.ts.map +1 -0
  12. package/dist/connect-studio/server.js +175 -0
  13. package/dist/connect-studio/studio.d.ts +3 -0
  14. package/dist/connect-studio/studio.d.ts.map +1 -0
  15. package/dist/connect-studio/studio.js +65 -0
  16. package/dist/connect-studio/types.d.ts +25 -0
  17. package/dist/connect-studio/types.d.ts.map +1 -0
  18. package/dist/connect-studio/types.js +1 -0
  19. package/dist/connect-studio/vite-plugins/base.d.ts +19 -0
  20. package/dist/connect-studio/vite-plugins/base.d.ts.map +1 -0
  21. package/dist/connect-studio/vite-plugins/base.js +162 -0
  22. package/dist/connect-studio/vite-plugins/external-packages.d.ts +6 -0
  23. package/dist/connect-studio/vite-plugins/external-packages.d.ts.map +1 -0
  24. package/dist/connect-studio/vite-plugins/external-packages.js +74 -0
  25. package/dist/connect-studio/vite-plugins/hmr.d.ts +3 -0
  26. package/dist/connect-studio/vite-plugins/hmr.d.ts.map +1 -0
  27. package/dist/connect-studio/vite-plugins/hmr.js +57 -0
  28. package/dist/connect-studio/vite-plugins/importmap.d.ts +20 -0
  29. package/dist/connect-studio/vite-plugins/importmap.d.ts.map +1 -0
  30. package/dist/connect-studio/vite-plugins/importmap.js +174 -0
  31. package/dist/connect-studio/vite-plugins/studio.d.ts +4 -0
  32. package/dist/connect-studio/vite-plugins/studio.d.ts.map +1 -0
  33. package/dist/connect-studio/vite-plugins/studio.js +112 -0
  34. package/dist/document-model-editor/components/button.d.ts +4 -0
  35. package/dist/document-model-editor/components/button.d.ts.map +1 -0
  36. package/dist/document-model-editor/components/button.js +7 -0
  37. package/dist/document-model-editor/components/code-editors/graphql-editor.d.ts +10 -0
  38. package/dist/document-model-editor/components/code-editors/graphql-editor.d.ts.map +1 -0
  39. package/dist/document-model-editor/components/code-editors/graphql-editor.js +75 -0
  40. package/dist/document-model-editor/components/code-editors/json-editor.d.ts +8 -0
  41. package/dist/document-model-editor/components/code-editors/json-editor.d.ts.map +1 -0
  42. package/dist/document-model-editor/components/code-editors/json-editor.js +43 -0
  43. package/dist/document-model-editor/components/code-editors/utils.d.ts +32 -0
  44. package/dist/document-model-editor/components/code-editors/utils.d.ts.map +1 -0
  45. package/dist/document-model-editor/components/code-editors/utils.js +191 -0
  46. package/dist/document-model-editor/components/divider.d.ts +8 -0
  47. package/dist/document-model-editor/components/divider.d.ts.map +1 -0
  48. package/dist/document-model-editor/components/divider.js +21 -0
  49. package/dist/document-model-editor/components/errors.d.ts +6 -0
  50. package/dist/document-model-editor/components/errors.d.ts.map +1 -0
  51. package/dist/document-model-editor/components/errors.js +4 -0
  52. package/dist/document-model-editor/components/form.d.ts +12 -0
  53. package/dist/document-model-editor/components/form.d.ts.map +1 -0
  54. package/dist/document-model-editor/components/form.js +42 -0
  55. package/dist/document-model-editor/components/input.d.ts +6 -0
  56. package/dist/document-model-editor/components/input.d.ts.map +1 -0
  57. package/dist/document-model-editor/components/input.js +8 -0
  58. package/dist/document-model-editor/components/label.d.ts +6 -0
  59. package/dist/document-model-editor/components/label.d.ts.map +1 -0
  60. package/dist/document-model-editor/components/label.js +9 -0
  61. package/dist/document-model-editor/components/model-metadata-form.d.ts +45 -0
  62. package/dist/document-model-editor/components/model-metadata-form.d.ts.map +1 -0
  63. package/dist/document-model-editor/components/model-metadata-form.js +69 -0
  64. package/dist/document-model-editor/components/module-form.d.ts +10 -0
  65. package/dist/document-model-editor/components/module-form.d.ts.map +1 -0
  66. package/dist/document-model-editor/components/module-form.js +21 -0
  67. package/dist/document-model-editor/components/module.d.ts +21 -0
  68. package/dist/document-model-editor/components/module.d.ts.map +1 -0
  69. package/dist/document-model-editor/components/module.js +9 -0
  70. package/dist/document-model-editor/components/modules.d.ts +19 -0
  71. package/dist/document-model-editor/components/modules.d.ts.map +1 -0
  72. package/dist/document-model-editor/components/modules.js +16 -0
  73. package/dist/document-model-editor/components/operation-description-form.d.ts +9 -0
  74. package/dist/document-model-editor/components/operation-description-form.d.ts.map +1 -0
  75. package/dist/document-model-editor/components/operation-description-form.js +12 -0
  76. package/dist/document-model-editor/components/operation-error-form.d.ts +13 -0
  77. package/dist/document-model-editor/components/operation-error-form.d.ts.map +1 -0
  78. package/dist/document-model-editor/components/operation-error-form.js +39 -0
  79. package/dist/document-model-editor/components/operation-errors.d.ts +10 -0
  80. package/dist/document-model-editor/components/operation-errors.d.ts.map +1 -0
  81. package/dist/document-model-editor/components/operation-errors.js +16 -0
  82. package/dist/document-model-editor/components/operation-form.d.ts +13 -0
  83. package/dist/document-model-editor/components/operation-form.d.ts.map +1 -0
  84. package/dist/document-model-editor/components/operation-form.js +36 -0
  85. package/dist/document-model-editor/components/operation.d.ts +22 -0
  86. package/dist/document-model-editor/components/operation.d.ts.map +1 -0
  87. package/dist/document-model-editor/components/operation.js +21 -0
  88. package/dist/document-model-editor/components/operations.d.ts +17 -0
  89. package/dist/document-model-editor/components/operations.d.ts.map +1 -0
  90. package/dist/document-model-editor/components/operations.js +19 -0
  91. package/dist/document-model-editor/components/state-schemas.d.ts +13 -0
  92. package/dist/document-model-editor/components/state-schemas.d.ts.map +1 -0
  93. package/dist/document-model-editor/components/state-schemas.js +34 -0
  94. package/dist/document-model-editor/components/tabs.d.ts +8 -0
  95. package/dist/document-model-editor/components/tabs.d.ts.map +1 -0
  96. package/dist/document-model-editor/components/tabs.js +12 -0
  97. package/dist/document-model-editor/components/text-area.d.ts +9 -0
  98. package/dist/document-model-editor/components/text-area.d.ts.map +1 -0
  99. package/dist/document-model-editor/components/text-area.js +26 -0
  100. package/dist/document-model-editor/components/text-field.d.ts +21 -0
  101. package/dist/document-model-editor/components/text-field.d.ts.map +1 -0
  102. package/dist/document-model-editor/components/text-field.js +78 -0
  103. package/dist/document-model-editor/constants/documents.d.ts +12 -0
  104. package/dist/document-model-editor/constants/documents.d.ts.map +1 -0
  105. package/dist/document-model-editor/constants/documents.js +16 -0
  106. package/dist/document-model-editor/context/form-context.d.ts +11 -0
  107. package/dist/document-model-editor/context/form-context.d.ts.map +1 -0
  108. package/dist/document-model-editor/context/form-context.js +3 -0
  109. package/dist/document-model-editor/context/schema-context.d.ts +11 -0
  110. package/dist/document-model-editor/context/schema-context.d.ts.map +1 -0
  111. package/dist/document-model-editor/context/schema-context.js +116 -0
  112. package/dist/document-model-editor/document-model-editor.stories.d.ts +48 -0
  113. package/dist/document-model-editor/document-model-editor.stories.d.ts.map +1 -0
  114. package/dist/document-model-editor/document-model-editor.stories.js +252 -0
  115. package/dist/document-model-editor/editor.d.ts +3 -0
  116. package/dist/document-model-editor/editor.d.ts.map +1 -0
  117. package/dist/document-model-editor/editor.js +186 -0
  118. package/dist/document-model-editor/hooks/useFormField.d.ts +13 -0
  119. package/dist/document-model-editor/hooks/useFormField.d.ts.map +1 -0
  120. package/dist/document-model-editor/hooks/useFormField.js +21 -0
  121. package/dist/document-model-editor/index.d.ts +3 -0
  122. package/dist/document-model-editor/index.d.ts.map +1 -0
  123. package/dist/document-model-editor/index.js +2 -0
  124. package/dist/document-model-editor/module.d.ts +4 -0
  125. package/dist/document-model-editor/module.d.ts.map +1 -0
  126. package/dist/document-model-editor/module.js +10 -0
  127. package/dist/document-model-editor/schemas/inputs.d.ts +31 -0
  128. package/dist/document-model-editor/schemas/inputs.d.ts.map +1 -0
  129. package/dist/document-model-editor/schemas/inputs.js +70 -0
  130. package/dist/document-model-editor/schemas/utils.d.ts +3 -0
  131. package/dist/document-model-editor/schemas/utils.d.ts.map +1 -0
  132. package/dist/document-model-editor/schemas/utils.js +2 -0
  133. package/dist/document-model-editor/types/documents.d.ts +27 -0
  134. package/dist/document-model-editor/types/documents.d.ts.map +1 -0
  135. package/dist/document-model-editor/types/documents.js +1 -0
  136. package/dist/document-model-editor/utils/helpers.d.ts +39 -0
  137. package/dist/document-model-editor/utils/helpers.d.ts.map +1 -0
  138. package/dist/document-model-editor/utils/helpers.js +293 -0
  139. package/dist/document-model-editor/utils/linting.d.ts +7 -0
  140. package/dist/document-model-editor/utils/linting.d.ts.map +1 -0
  141. package/dist/document-model-editor/utils/linting.js +47 -0
  142. package/dist/document-model-editor/utils/style.d.ts +3 -0
  143. package/dist/document-model-editor/utils/style.d.ts.map +1 -0
  144. package/dist/document-model-editor/utils/style.js +5 -0
  145. package/dist/editor-utils/components/documentEditor.d.ts +7 -0
  146. package/dist/editor-utils/components/documentEditor.d.ts.map +1 -0
  147. package/dist/editor-utils/components/documentEditor.js +5 -0
  148. package/dist/editor-utils/components/editorToolbar.d.ts +11 -0
  149. package/dist/editor-utils/components/editorToolbar.d.ts.map +1 -0
  150. package/dist/editor-utils/components/editorToolbar.js +5 -0
  151. package/dist/editor-utils/components/editorWorksheet.d.ts +7 -0
  152. package/dist/editor-utils/components/editorWorksheet.d.ts.map +1 -0
  153. package/dist/editor-utils/components/editorWorksheet.js +4 -0
  154. package/dist/editor-utils/components/index.d.ts +9 -0
  155. package/dist/editor-utils/components/index.d.ts.map +1 -0
  156. package/dist/editor-utils/components/index.js +9 -0
  157. package/dist/editor-utils/components/styles.d.ts +40 -0
  158. package/dist/editor-utils/components/styles.d.ts.map +1 -0
  159. package/dist/editor-utils/components/styles.js +78 -0
  160. package/dist/editor-utils/components/stylesVariant.d.ts +40 -0
  161. package/dist/editor-utils/components/stylesVariant.d.ts.map +1 -0
  162. package/dist/editor-utils/components/stylesVariant.js +88 -0
  163. package/dist/editor-utils/components/textInput.d.ts +20 -0
  164. package/dist/editor-utils/components/textInput.d.ts.map +1 -0
  165. package/dist/editor-utils/components/textInput.js +83 -0
  166. package/dist/editor-utils/components/textInputVariant.d.ts +21 -0
  167. package/dist/editor-utils/components/textInputVariant.d.ts.map +1 -0
  168. package/dist/editor-utils/components/textInputVariant.js +92 -0
  169. package/dist/editor-utils/components/toolbarButton.d.ts +7 -0
  170. package/dist/editor-utils/components/toolbarButton.d.ts.map +1 -0
  171. package/dist/editor-utils/components/toolbarButton.js +8 -0
  172. package/dist/editor-utils/hooks/index.d.ts +2 -0
  173. package/dist/editor-utils/hooks/index.d.ts.map +1 -0
  174. package/dist/editor-utils/hooks/index.js +1 -0
  175. package/dist/editor-utils/hooks/useEnsInfo.d.ts +15 -0
  176. package/dist/editor-utils/hooks/useEnsInfo.d.ts.map +1 -0
  177. package/dist/editor-utils/hooks/useEnsInfo.js +63 -0
  178. package/dist/editor-utils/index.d.ts +5 -0
  179. package/dist/editor-utils/index.d.ts.map +1 -0
  180. package/dist/editor-utils/index.js +4 -0
  181. package/dist/editor-utils/reducer.d.ts +3 -0
  182. package/dist/editor-utils/reducer.d.ts.map +1 -0
  183. package/dist/editor-utils/reducer.js +24 -0
  184. package/dist/editor-utils/storybook.d.ts +25 -0
  185. package/dist/editor-utils/storybook.d.ts.map +1 -0
  186. package/dist/editor-utils/storybook.js +118 -0
  187. package/dist/styles.css +786 -0
  188. package/dist/tsconfig.tsbuildinfo +1 -0
  189. package/package.json +102 -0
@@ -0,0 +1,32 @@
1
+ import { Diagnostic } from "@codemirror/lint";
2
+ import { Compartment } from "@codemirror/state";
3
+ import { EditorView } from "@codemirror/view";
4
+ import { GraphQLError, GraphQLSchema } from "graphql";
5
+ export declare function convertGraphQLErrorToDiagnostic(error: GraphQLError): Diagnostic;
6
+ export declare function makeLinter(schema: GraphQLSchema, customLinter?: (doc: string) => Diagnostic[]): import("@codemirror/state").Extension;
7
+ export declare function makeUpdateHandler(readonly: boolean | undefined, timeoutRef: React.MutableRefObject<NodeJS.Timeout | null>, updateDocumentInModel?: (newDoc: string) => void): import("@codemirror/state").Extension;
8
+ export declare function makeFocusHandler(readonly: boolean | undefined, timeoutRef: React.MutableRefObject<NodeJS.Timeout | null>, updateDocumentInModel?: (newDoc: string) => void): import("@codemirror/state").Extension;
9
+ export declare function makePasteHandler(readonly: boolean | undefined, timeoutRef: React.MutableRefObject<NodeJS.Timeout | null>, updateDocumentInModel?: (newDoc: string) => void): import("@codemirror/state").Extension;
10
+ export type EditorConfig = {
11
+ doc: string;
12
+ readonly?: boolean;
13
+ updateDocumentInModel?: (newDoc: string) => void;
14
+ };
15
+ export declare function useEditorRefs(): {
16
+ editorRef: import("react").RefObject<HTMLDivElement>;
17
+ viewRef: import("react").MutableRefObject<EditorView | null>;
18
+ updateListenerCompartment: import("react").MutableRefObject<Compartment>;
19
+ focusHandlerCompartment: import("react").MutableRefObject<Compartment>;
20
+ pasteHandlerCompartment: import("react").MutableRefObject<Compartment>;
21
+ timeoutRef: import("react").MutableRefObject<NodeJS.Timeout | null>;
22
+ };
23
+ export declare function useEditorCleanup(viewRef: React.MutableRefObject<EditorView | null>): void;
24
+ export declare function useHandlerReconfiguration(view: EditorView | null, readonly: boolean | undefined, timeoutRef: React.MutableRefObject<NodeJS.Timeout | null>, updateDocumentInModel: ((newDoc: string) => void) | undefined, compartments: {
25
+ updateListener: Compartment;
26
+ focusHandler: Compartment;
27
+ pasteHandler: Compartment;
28
+ }): void;
29
+ export declare function useDocumentSync(view: EditorView | null, doc: string): void;
30
+ export declare const baseEditorExtensions: import("@codemirror/state").Extension[];
31
+ export declare const baseKeymap: import("@codemirror/view").KeyBinding[];
32
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../document-model-editor/components/code-editors/utils.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,UAAU,EAAoC,MAAM,kBAAkB,CAAC;AAEhF,OAAO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AAE,KAAK,CAAC,gBAAgB,CAAC,UAAU,GAAG,IAAI,CAAC,QAUnD;AAED,wBAAgB,yBAAyB,CACvC,IAAI,EAAE,UAAU,GAAG,IAAI,EACvB,QAAQ,EAAE,OAAO,GAAG,SAAS,EAC7B,UAAU,EAAE,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,EACzD,qBAAqB,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,EAC7D,YAAY,EAAE;IACZ,cAAc,EAAE,WAAW,CAAC;IAC5B,YAAY,EAAE,WAAW,CAAC;IAC1B,YAAY,EAAE,WAAW,CAAC;CAC3B,QAmBF;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,EAAE,GAAG,EAAE,MAAM,QAYnE;AAED,eAAO,MAAM,oBAAoB,yCAmBhC,CAAC;AAEF,eAAO,MAAM,UAAU,yCAStB,CAAC"}
@@ -0,0 +1,191 @@
1
+ import { updateTimeout } from "#document-model-editor/constants/documents";
2
+ import { autocompletion, closeBrackets, closeBracketsKeymap, completionKeymap, } from "@codemirror/autocomplete";
3
+ import { defaultKeymap, history, historyKeymap, indentWithTab, } from "@codemirror/commands";
4
+ import { bracketMatching, defaultHighlightStyle, foldGutter, foldKeymap, indentOnInput, syntaxHighlighting, } from "@codemirror/language";
5
+ import { forceLinting, linter, lintKeymap } from "@codemirror/lint";
6
+ import { highlightSelectionMatches, searchKeymap } from "@codemirror/search";
7
+ import { Compartment, EditorState, Transaction } from "@codemirror/state";
8
+ import { crosshairCursor, drawSelection, dropCursor, EditorView, highlightActiveLine, highlightActiveLineGutter, highlightSpecialChars, lineNumbers, rectangularSelection, } from "@codemirror/view";
9
+ import { filterSchema, isDocumentString } from "@graphql-tools/utils";
10
+ import { GraphQLError, locatedError, parse } from "graphql";
11
+ import { validateSDL } from "graphql/validation/validate.js";
12
+ import { useEffect, useRef } from "react";
13
+ /* Converts a GraphQLError to a Diagnostic
14
+ GraphQLError uses a zero-indexed line and column, but the editor uses a one-indexed line and column
15
+ */
16
+ export function convertGraphQLErrorToDiagnostic(error) {
17
+ return {
18
+ from: error.locations?.[0] ? (error.positions?.[0] ?? 0) : 0,
19
+ to: error.locations?.[0] ? (error.positions?.[0] ?? 0) + 1 : 1,
20
+ severity: "error",
21
+ message: error.message,
22
+ };
23
+ }
24
+ /* Creates a linter that checks the document for errors
25
+ This works in combination with the built-in linting provided by the graphql extension
26
+ We need to recreate this linter when the schema changes or if a custom linter is provided
27
+ It first checks the document for linting errors
28
+ Then it checks if the document is a valid document string
29
+ Then it checks if the document is valid against the schema
30
+ */
31
+ export function makeLinter(schema, customLinter) {
32
+ return linter((view) => {
33
+ const doc = view.state.doc.toString();
34
+ let diagnostics = [];
35
+ if (customLinter) {
36
+ diagnostics = diagnostics.concat(customLinter(doc));
37
+ }
38
+ if (isDocumentString(doc)) {
39
+ try {
40
+ const newDocNode = parse(doc);
41
+ const currentTypeNames = new Set(newDocNode.definitions
42
+ .filter((def) => "name" in def && def.name)
43
+ .map((def) => def.name.value));
44
+ // we need to filter out the existing types in the document from the schema to prevent duplicate type errors in the validation
45
+ const filteredSchema = filterSchema({
46
+ schema,
47
+ typeFilter: (typeName) => !currentTypeNames.has(typeName),
48
+ });
49
+ const errors = validateSDL(newDocNode, filteredSchema)
50
+ .map((error) => locatedError(error, newDocNode))
51
+ .filter((error, index, self) => index ===
52
+ self.findIndex((e) => e.message === error.message &&
53
+ e.locations?.[0]?.line === error.locations?.[0]?.line &&
54
+ e.locations?.[0]?.column === error.locations?.[0]?.column));
55
+ diagnostics = diagnostics.concat(errors.map(convertGraphQLErrorToDiagnostic));
56
+ }
57
+ catch (error) {
58
+ if (error instanceof GraphQLError) {
59
+ diagnostics.push(convertGraphQLErrorToDiagnostic(error));
60
+ }
61
+ }
62
+ }
63
+ return diagnostics;
64
+ });
65
+ }
66
+ export function makeUpdateHandler(readonly, timeoutRef, updateDocumentInModel) {
67
+ return EditorView.updateListener.of((update) => {
68
+ if (!!readonly || !update.docChanged)
69
+ return;
70
+ if (update.transactions.some((tr) => tr.annotation(Transaction.userEvent) === "external"))
71
+ return;
72
+ const newDoc = update.state.doc.toString();
73
+ if (timeoutRef.current) {
74
+ clearTimeout(timeoutRef.current);
75
+ }
76
+ timeoutRef.current = setTimeout(() => {
77
+ updateDocumentInModel?.(newDoc);
78
+ }, updateTimeout);
79
+ });
80
+ }
81
+ export function makeFocusHandler(readonly, timeoutRef, updateDocumentInModel) {
82
+ return EditorView.focusChangeEffect.of((state, focusing) => {
83
+ if (!!readonly || focusing)
84
+ return null;
85
+ if (timeoutRef.current) {
86
+ clearTimeout(timeoutRef.current);
87
+ }
88
+ const newDoc = state.doc.toString();
89
+ updateDocumentInModel?.(newDoc);
90
+ return null;
91
+ });
92
+ }
93
+ export function makePasteHandler(readonly, timeoutRef, updateDocumentInModel) {
94
+ return EditorView.domEventHandlers({
95
+ paste: (event, view) => {
96
+ if (readonly)
97
+ return false;
98
+ const newDoc = view.state.doc.toString();
99
+ if (timeoutRef.current) {
100
+ clearTimeout(timeoutRef.current);
101
+ }
102
+ updateDocumentInModel?.(newDoc);
103
+ forceLinting(view);
104
+ return false;
105
+ },
106
+ });
107
+ }
108
+ export function useEditorRefs() {
109
+ const editorRef = useRef(null);
110
+ const viewRef = useRef(null);
111
+ const updateListenerCompartment = useRef(new Compartment());
112
+ const focusHandlerCompartment = useRef(new Compartment());
113
+ const pasteHandlerCompartment = useRef(new Compartment());
114
+ const timeoutRef = useRef(null);
115
+ return {
116
+ editorRef,
117
+ viewRef,
118
+ updateListenerCompartment,
119
+ focusHandlerCompartment,
120
+ pasteHandlerCompartment,
121
+ timeoutRef,
122
+ };
123
+ }
124
+ export function useEditorCleanup(viewRef) {
125
+ useEffect(() => {
126
+ return () => {
127
+ if (viewRef.current) {
128
+ viewRef.current.destroy();
129
+ viewRef.current = null;
130
+ }
131
+ };
132
+ }, []);
133
+ }
134
+ export function useHandlerReconfiguration(view, readonly, timeoutRef, updateDocumentInModel, compartments) {
135
+ useEffect(() => {
136
+ if (!view)
137
+ return;
138
+ view.dispatch({
139
+ effects: [
140
+ compartments.updateListener.reconfigure(makeUpdateHandler(readonly, timeoutRef, updateDocumentInModel)),
141
+ compartments.focusHandler.reconfigure(makeFocusHandler(readonly, timeoutRef, updateDocumentInModel)),
142
+ compartments.pasteHandler.reconfigure(makePasteHandler(readonly, timeoutRef, updateDocumentInModel)),
143
+ ],
144
+ });
145
+ forceLinting(view);
146
+ }, [readonly, updateDocumentInModel]);
147
+ }
148
+ export function useDocumentSync(view, doc) {
149
+ useEffect(() => {
150
+ if (!view)
151
+ return;
152
+ const currentDoc = view.state.doc.toString();
153
+ if (currentDoc !== doc) {
154
+ view.dispatch({
155
+ changes: { from: 0, to: currentDoc.length, insert: doc },
156
+ annotations: [Transaction.userEvent.of("external")],
157
+ });
158
+ forceLinting(view);
159
+ }
160
+ }, [doc]);
161
+ }
162
+ export const baseEditorExtensions = [
163
+ lineNumbers(),
164
+ highlightActiveLineGutter(),
165
+ highlightSpecialChars(),
166
+ history(),
167
+ foldGutter(),
168
+ drawSelection(),
169
+ dropCursor(),
170
+ EditorState.allowMultipleSelections.of(true),
171
+ indentOnInput(),
172
+ syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
173
+ bracketMatching(),
174
+ closeBrackets(),
175
+ autocompletion(),
176
+ rectangularSelection(),
177
+ crosshairCursor(),
178
+ highlightActiveLine(),
179
+ highlightSelectionMatches(),
180
+ EditorView.lineWrapping,
181
+ ];
182
+ export const baseKeymap = [
183
+ ...closeBracketsKeymap,
184
+ ...defaultKeymap,
185
+ ...searchKeymap,
186
+ ...historyKeymap,
187
+ ...foldKeymap,
188
+ ...completionKeymap,
189
+ ...lintKeymap,
190
+ indentWithTab,
191
+ ];
@@ -0,0 +1,8 @@
1
+ type Props = {
2
+ className?: string;
3
+ size?: "sm" | "md" | "lg";
4
+ margin?: "sm" | "md" | "lg";
5
+ };
6
+ export declare function Divider({ className, size, margin }: Props): import("react/jsx-runtime").JSX.Element;
7
+ export {};
8
+ //# sourceMappingURL=divider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"divider.d.ts","sourceRoot":"","sources":["../../../document-model-editor/components/divider.tsx"],"names":[],"mappings":"AAEA,KAAK,KAAK,GAAG;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IAC1B,MAAM,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;CAC7B,CAAC;AACF,wBAAgB,OAAO,CAAC,EAAE,SAAS,EAAE,IAAW,EAAE,MAAa,EAAE,EAAE,KAAK,2CAkBvE"}
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cn } from "../utils/style.js";
3
+ export function Divider({ className, size = "sm", margin = "md" }) {
4
+ function getSize() {
5
+ if (size === "sm")
6
+ return "h-px";
7
+ if (size === "md")
8
+ return "h-1";
9
+ return "h-1.5";
10
+ }
11
+ function getMargin() {
12
+ if (margin === "sm")
13
+ return "my-4";
14
+ if (margin === "md")
15
+ return "my-6";
16
+ return "my-8";
17
+ }
18
+ const sizeClass = getSize();
19
+ const marginClass = getMargin();
20
+ return (_jsx("div", { className: cn("bg-gray-200", sizeClass, marginClass, className) }));
21
+ }
@@ -0,0 +1,6 @@
1
+ type Props = {
2
+ errors: string;
3
+ };
4
+ export declare function Errors({ errors }: Props): import("react/jsx-runtime").JSX.Element;
5
+ export {};
6
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../document-model-editor/components/errors.tsx"],"names":[],"mappings":"AAAA,KAAK,KAAK,GAAG;IACX,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAgB,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,KAAK,2CAUvC"}
@@ -0,0 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export function Errors({ errors }) {
3
+ return (_jsx("div", { className: "mt-1", children: Array.from(new Set(errors.split("\n"))).map((error) => (_jsx("p", { className: "text-sm font-semibold text-red-900", children: error }, error))) }));
4
+ }
@@ -0,0 +1,12 @@
1
+ import * as React from "react";
2
+ import * as LabelPrimitive from "@radix-ui/react-label";
3
+ import { ControllerProps, FieldPath, FieldValues } from "react-hook-form";
4
+ declare const Form: <TFieldValues extends FieldValues, TContext = any, TTransformedValues extends FieldValues | undefined = undefined>(props: import("react-hook-form").FormProviderProps<TFieldValues, TContext, TTransformedValues>) => React.JSX.Element;
5
+ declare const FormField: <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ ...props }: ControllerProps<TFieldValues, TName>) => import("react/jsx-runtime").JSX.Element;
6
+ declare const FormItem: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
7
+ declare const FormLabel: React.ForwardRefExoticComponent<Omit<LabelPrimitive.LabelProps & React.RefAttributes<HTMLLabelElement>, "ref"> & React.RefAttributes<HTMLLabelElement>>;
8
+ declare const FormControl: React.ForwardRefExoticComponent<Omit<import("@radix-ui/react-slot").SlotProps & React.RefAttributes<HTMLElement>, "ref"> & React.RefAttributes<HTMLElement>>;
9
+ declare const FormDescription: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLParagraphElement> & React.RefAttributes<HTMLParagraphElement>>;
10
+ declare const FormMessage: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLParagraphElement> & React.RefAttributes<HTMLParagraphElement>>;
11
+ export { Form, FormItem, FormLabel, FormControl, FormDescription, FormMessage, FormField, };
12
+ //# sourceMappingURL=form.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../../document-model-editor/components/form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,cAAc,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAEL,eAAe,EACf,SAAS,EACT,WAAW,EAEZ,MAAM,iBAAiB,CAAC;AAMzB,QAAA,MAAM,IAAI,yOAAe,CAAC;AAE1B,QAAA,MAAM,SAAS,GACb,YAAY,SAAS,WAAW,gBAChC,KAAK,SAAS,SAAS,CAAC,YAAY,CAAC,0CAGpC,eAAe,CAAC,YAAY,EAAE,KAAK,CAAC,4CAMtC,CAAC;AAEF,QAAA,MAAM,QAAQ,6GAWZ,CAAC;AAGH,QAAA,MAAM,SAAS,yJAcb,CAAC;AAGH,QAAA,MAAM,WAAW,8JAkBf,CAAC;AAGH,QAAA,MAAM,eAAe,yHAcnB,CAAC;AAGH,QAAA,MAAM,WAAW,yHAqBf,CAAC;AAGH,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,WAAW,EACX,eAAe,EACf,WAAW,EACX,SAAS,GACV,CAAC"}
@@ -0,0 +1,42 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ import { Slot } from "@radix-ui/react-slot";
4
+ import { Controller, FormProvider, } from "react-hook-form";
5
+ import { FormFieldContext, FormItemContext } from "../context/form-context.js";
6
+ import { useFormField } from "../hooks/useFormField.js";
7
+ import { cn } from "../utils/style.js";
8
+ import { Label } from "./label.js";
9
+ const Form = FormProvider;
10
+ const FormField = ({ ...props }) => {
11
+ return (_jsx(FormFieldContext.Provider, { value: { name: props.name }, children: _jsx(Controller, { ...props }) }));
12
+ };
13
+ const FormItem = React.forwardRef(({ className, ...props }, ref) => {
14
+ const id = React.useId();
15
+ return (_jsx(FormItemContext.Provider, { value: { id }, children: _jsx("div", { ref: ref, className: cn("", className), ...props }) }));
16
+ });
17
+ FormItem.displayName = "FormItem";
18
+ const FormLabel = React.forwardRef(({ className, ...props }, ref) => {
19
+ const { error, formItemId } = useFormField();
20
+ return (_jsx(Label, { ref: ref, className: cn(error && "text-destructive", className), htmlFor: formItemId, ...props }));
21
+ });
22
+ FormLabel.displayName = "FormLabel";
23
+ const FormControl = React.forwardRef(({ ...props }, ref) => {
24
+ const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
25
+ return (_jsx(Slot, { ref: ref, id: formItemId, "aria-describedby": !error ? formDescriptionId : `${formDescriptionId} ${formMessageId}`, "aria-invalid": !!error, ...props }));
26
+ });
27
+ FormControl.displayName = "FormControl";
28
+ const FormDescription = React.forwardRef(({ className, ...props }, ref) => {
29
+ const { formDescriptionId } = useFormField();
30
+ return (_jsx("p", { ref: ref, id: formDescriptionId, className: cn("text-[0.8rem] text-gray-600", className), ...props }));
31
+ });
32
+ FormDescription.displayName = "FormDescription";
33
+ const FormMessage = React.forwardRef(({ className, children, ...props }, ref) => {
34
+ const { error, formMessageId } = useFormField();
35
+ const body = error ? String(error.message) : children;
36
+ if (!body) {
37
+ return null;
38
+ }
39
+ return (_jsx("p", { ref: ref, id: formMessageId, className: cn("text-[0.8rem] font-medium text-red-800", className), ...props, children: body }));
40
+ });
41
+ FormMessage.displayName = "FormMessage";
42
+ export { Form, FormItem, FormLabel, FormControl, FormDescription, FormMessage, FormField, };
@@ -0,0 +1,6 @@
1
+ import * as React from "react";
2
+ export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
3
+ }
4
+ declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<HTMLInputElement>>;
5
+ export { Input };
6
+ //# sourceMappingURL=input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../../document-model-editor/components/input.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,MAAM,WAAW,UACf,SAAQ,KAAK,CAAC,mBAAmB,CAAC,gBAAgB,CAAC;CAAG;AAExD,QAAA,MAAM,KAAK,qFAcV,CAAC;AAGF,OAAO,EAAE,KAAK,EAAE,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ import { cn } from "../utils/style.js";
4
+ const Input = React.forwardRef(({ className, type, ...props }, ref) => {
5
+ return (_jsx("input", { type: type, className: cn("flex h-9 w-full rounded-md border border-gray-400 bg-transparent px-3 py-1 text-sm transition-colors hover:bg-gray-100 focus-visible:bg-gray-200 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50", className), ref: ref, ...props }));
6
+ });
7
+ Input.displayName = "Input";
8
+ export { Input };
@@ -0,0 +1,6 @@
1
+ import * as React from "react";
2
+ import * as LabelPrimitive from "@radix-ui/react-label";
3
+ import { type VariantProps } from "class-variance-authority";
4
+ declare const Label: React.ForwardRefExoticComponent<Omit<LabelPrimitive.LabelProps & React.RefAttributes<HTMLLabelElement>, "ref"> & VariantProps<(props?: import("class-variance-authority/types").ClassProp | undefined) => string> & React.RefAttributes<HTMLLabelElement>>;
5
+ export { Label };
6
+ //# sourceMappingURL=label.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"label.d.ts","sourceRoot":"","sources":["../../../document-model-editor/components/label.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,cAAc,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAOlE,QAAA,MAAM,KAAK,4PAUT,CAAC;AAGH,OAAO,EAAE,KAAK,EAAE,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ import * as LabelPrimitive from "@radix-ui/react-label";
4
+ import { cva } from "class-variance-authority";
5
+ import { cn } from "../utils/style.js";
6
+ const labelVariants = cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70");
7
+ const Label = React.forwardRef(({ className, ...props }, ref) => (_jsx(LabelPrimitive.Root, { ref: ref, className: cn(labelVariants(), className), ...props })));
8
+ Label.displayName = LabelPrimitive.Root.displayName;
9
+ export { Label };
@@ -0,0 +1,45 @@
1
+ import { z } from "zod";
2
+ import { Scope } from "../types/documents.js";
3
+ export declare const MetadataFormSchema: z.ZodObject<{
4
+ name: z.ZodString;
5
+ documentType: z.ZodString;
6
+ extension: z.ZodString;
7
+ description: z.ZodString;
8
+ authorName: z.ZodString;
9
+ authorWebsite: z.ZodString;
10
+ }, "strip", z.ZodTypeAny, {
11
+ name: string;
12
+ documentType: string;
13
+ description: string;
14
+ extension: string;
15
+ authorName: string;
16
+ authorWebsite: string;
17
+ }, {
18
+ name: string;
19
+ documentType: string;
20
+ description: string;
21
+ extension: string;
22
+ authorName: string;
23
+ authorWebsite: string;
24
+ }>;
25
+ export type MetadataFormValues = z.infer<typeof MetadataFormSchema>;
26
+ type Props = MetadataFormValues & {
27
+ globalStateSchema: string;
28
+ localStateSchema: string;
29
+ setModelName: (name: string) => void;
30
+ setModelId: (id: string) => void;
31
+ setModelExtension: (extension: string) => void;
32
+ setModelDescription: (description: string) => void;
33
+ setAuthorName: (authorName: string) => void;
34
+ setAuthorWebsite: (authorWebsite: string) => void;
35
+ setStateSchema: (schema: string, scope: Scope) => void;
36
+ };
37
+ export declare function ModelMetadata(props: Props): import("react/jsx-runtime").JSX.Element;
38
+ export declare function ModelNameForm(props: Props): import("react/jsx-runtime").JSX.Element;
39
+ export declare function DocumentTypeForm(props: Props): import("react/jsx-runtime").JSX.Element;
40
+ export declare function ModelExtensionForm(props: Props): import("react/jsx-runtime").JSX.Element;
41
+ export declare function DescriptionForm(props: Props): import("react/jsx-runtime").JSX.Element;
42
+ export declare function AuthorNameForm(props: Props): import("react/jsx-runtime").JSX.Element;
43
+ export declare function AuthorWebsiteForm(props: Props): import("react/jsx-runtime").JSX.Element;
44
+ export {};
45
+ //# sourceMappingURL=model-metadata-form.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-metadata-form.d.ts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EAAE,KAAK,2CAgB7C"}
@@ -0,0 +1,69 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback } from "react";
3
+ import { z } from "zod";
4
+ import { makeInitialSchemaDoc, renameSchemaType, handleModelNameChange, } from "../utils/helpers.js";
5
+ import { TextField } from "./text-field.js";
6
+ export const MetadataFormSchema = z.object({
7
+ name: z.string(),
8
+ documentType: z.string(),
9
+ extension: z.string(),
10
+ description: z.string(),
11
+ authorName: z.string(),
12
+ authorWebsite: z.string(),
13
+ });
14
+ export function ModelMetadata(props) {
15
+ return (_jsxs("div", { children: [_jsx(ModelNameForm, { ...props }), _jsx("div", { className: "flex h-full flex-col gap-4", children: _jsxs("div", { className: "grid flex-1 grid-cols-3 items-start gap-4", children: [_jsxs("div", { className: "col-span-2 flex h-full flex-col gap-4", children: [_jsx("div", { className: "shrink-0", children: _jsx(DocumentTypeForm, { ...props }) }), _jsx("div", { className: "min-h-0 flex-1", children: _jsx(DescriptionForm, { ...props }) })] }), _jsxs("div", { className: "col-span-1 flex flex-col gap-4", children: [_jsx(AuthorNameForm, { ...props }), _jsx(AuthorWebsiteForm, { ...props }), _jsx(ModelExtensionForm, { ...props })] })] }) })] }));
16
+ }
17
+ export function ModelNameForm(props) {
18
+ const { name, globalStateSchema, localStateSchema, setModelName, setStateSchema, } = props;
19
+ const onSubmit = useCallback((newName) => {
20
+ if (name === newName) {
21
+ return;
22
+ }
23
+ setModelName(newName);
24
+ const hasExistingSchema = !!globalStateSchema;
25
+ if (!hasExistingSchema) {
26
+ const initialSchemaDoc = makeInitialSchemaDoc(newName, "global");
27
+ setStateSchema(initialSchemaDoc, "global");
28
+ return;
29
+ }
30
+ const newSchema = renameSchemaType(globalStateSchema, name, newName, "global");
31
+ setStateSchema(newSchema, "global");
32
+ if (localStateSchema) {
33
+ const newLocalStateSchema = renameSchemaType(localStateSchema, name, newName, "local");
34
+ setStateSchema(newLocalStateSchema, "local");
35
+ }
36
+ handleModelNameChange({
37
+ oldName: name,
38
+ newName,
39
+ globalStateSchema,
40
+ localStateSchema,
41
+ setStateSchema,
42
+ });
43
+ }, [name, globalStateSchema, localStateSchema, setStateSchema]);
44
+ return (_jsx(TextField, { name: "name", value: name, onSubmit: onSubmit, placeholder: "Model name", className: "border-none pl-0 text-xl font-bold text-gray-900", required: true, focusOnMount: true }));
45
+ }
46
+ export function DocumentTypeForm(props) {
47
+ const { documentType, setModelId } = props;
48
+ return (_jsx(TextField, { label: "Document Type", name: "powerhouse/document-model", value: documentType, onSubmit: setModelId, placeholder: "Document Type", required: true }));
49
+ }
50
+ export function ModelExtensionForm(props) {
51
+ const { extension, setModelExtension } = props;
52
+ return (_jsx(TextField, { name: "extension", value: extension, onSubmit: setModelExtension, label: "Model Extension", placeholder: "Example .phdm", required: true }));
53
+ }
54
+ export function DescriptionForm(props) {
55
+ const { description, setModelDescription } = props;
56
+ return (_jsx(TextField, { name: "description", label: "Model Description", value: description, onSubmit: setModelDescription, placeholder: "Describe your document to others", allowEmpty: true, className: "h-full" }));
57
+ }
58
+ export function AuthorNameForm(props) {
59
+ const { authorName, setAuthorName } = props;
60
+ return (_jsx(TextField, { name: "authorName", value: authorName, onSubmit: setAuthorName, label: "Author Name", placeholder: "Username or organisation", allowEmpty: true }));
61
+ }
62
+ export function AuthorWebsiteForm(props) {
63
+ const { authorWebsite, setAuthorWebsite } = props;
64
+ return (_jsx(TextField, { name: "authorWebsite", value: authorWebsite, label: "Website URL", onSubmit: (newAuthorWebsite) => {
65
+ if (!!authorWebsite && !newAuthorWebsite)
66
+ return;
67
+ setAuthorWebsite(newAuthorWebsite);
68
+ }, placeholder: "https://www.powerhouse.inc/", allowEmpty: true }));
69
+ }
@@ -0,0 +1,10 @@
1
+ import type { Module } from "document-model";
2
+ type Props = {
3
+ modules?: Module[];
4
+ module?: Module;
5
+ onAddModule: (name: string) => Promise<string | undefined>;
6
+ updateModuleName: (id: string, name: string) => void;
7
+ };
8
+ export declare function ModuleForm({ module, onAddModule, updateModuleName, modules, }: Props): import("react/jsx-runtime").JSX.Element;
9
+ export {};
10
+ //# sourceMappingURL=module-form.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-form.d.ts","sourceRoot":"","sources":["../../../document-model-editor/components/module-form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAI7C,KAAK,KAAK,GAAG;IACX,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC3D,gBAAgB,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACtD,CAAC;AAEF,wBAAgB,UAAU,CAAC,EACzB,MAAM,EACN,WAAW,EACX,gBAAgB,EAChB,OAAY,GACb,EAAE,KAAK,2CA8BP"}
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { toLowercaseSnakeCase } from "../schemas/inputs.js";
3
+ import { TextField } from "./text-field.js";
4
+ export function ModuleForm({ module, onAddModule, updateModuleName, modules = [], }) {
5
+ const isEdit = !!module;
6
+ const moduleNames = modules.map((m) => m.name);
7
+ const handleSubmit = async (name) => {
8
+ const formattedName = toLowercaseSnakeCase(name);
9
+ if (!formattedName.length)
10
+ return;
11
+ if (isEdit) {
12
+ if (formattedName !== module.name) {
13
+ updateModuleName(module.id, formattedName);
14
+ }
15
+ }
16
+ else {
17
+ await onAddModule(formattedName);
18
+ }
19
+ };
20
+ return (_jsx(TextField, { name: "name", label: isEdit ? "Module name" : "Add module", value: module?.name, onSubmit: handleSubmit, placeholder: "Add module", unique: moduleNames, shouldReset: !isEdit, required: true }, module?.id ?? "new"));
21
+ }
@@ -0,0 +1,21 @@
1
+ import type { Module as TModule } from "document-model";
2
+ type Props = {
3
+ module?: TModule;
4
+ modules?: TModule[];
5
+ allOperations: TModule["operations"];
6
+ lastCreatedModuleId: string | null;
7
+ onAddModule: (name: string) => Promise<string | undefined>;
8
+ updateModuleName: (id: string, name: string) => void;
9
+ deleteModule: (id: string) => void;
10
+ updateOperationName: (id: string, name: string) => void;
11
+ deleteOperation: (id: string) => void;
12
+ addOperationAndInitialSchema: (moduleId: string, name: string) => Promise<string | undefined>;
13
+ updateOperationSchema: (id: string, newDoc: string) => void;
14
+ setOperationDescription: (id: string, description: string) => void;
15
+ addOperationError: (operationId: string, errorName: string) => Promise<string | undefined>;
16
+ deleteOperationError: (id: string) => void;
17
+ setOperationErrorName: (operationId: string, errorId: string, name: string) => void;
18
+ };
19
+ export declare function Module(props: Props): import("react/jsx-runtime").JSX.Element;
20
+ export {};
21
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../document-model-editor/components/module.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGxD,KAAK,KAAK,GAAG;IACX,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;IACpB,aAAa,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IACrC,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC3D,gBAAgB,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACrD,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,mBAAmB,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACxD,eAAe,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,4BAA4B,EAAE,CAC5B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,KACT,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACjC,qBAAqB,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5D,uBAAuB,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;IACnE,iBAAiB,EAAE,CACjB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,KACd,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACjC,oBAAoB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,qBAAqB,EAAE,CACrB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,KACT,IAAI,CAAC;CACX,CAAC;AACF,wBAAgB,MAAM,CAAC,KAAK,EAAE,KAAK,2CA+DlC"}
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ModuleForm } from "./module-form.js";
3
+ import { Operations } from "./operations.js";
4
+ export function Module(props) {
5
+ const { module, modules, allOperations, lastCreatedModuleId, onAddModule, updateModuleName, deleteModule, updateOperationName, deleteOperation, addOperationAndInitialSchema, updateOperationSchema, setOperationDescription, addOperationError, deleteOperationError, setOperationErrorName, } = props;
6
+ return (_jsxs("div", { className: "relative rounded-3xl bg-gray-100 p-6", children: [_jsxs("div", { className: "mb-2 w-1/2 pr-6", children: [_jsx(ModuleForm, { modules: modules, module: module, onAddModule: onAddModule, updateModuleName: updateModuleName }), !!module && (_jsx("button", { "aria-label": "Delete module", tabIndex: -1, className: "absolute right-1 top-1 p-2 text-gray-800 transition-colors hover:text-gray-500", onClick: () => {
7
+ deleteModule(module.id);
8
+ }, children: _jsx("svg", { className: "size-6", viewBox: "0 0 24 24", fill: "currentcolor", children: _jsx("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M16.9993 8.51506L15.4844 7L11.9994 10.4852L8.51497 7.00057L7 8.51562L10.4844 12.0003L7.00056 15.4843L8.51552 16.9994L11.9994 13.5153L15.4838 17L16.9988 15.4849L13.5144 12.0003L16.9993 8.51506Z" }) }) }))] }), !!module && (_jsx(Operations, { module: module, allOperations: allOperations, shouldFocusNewOperation: module.id === lastCreatedModuleId, updateOperationName: updateOperationName, deleteOperation: deleteOperation, addOperationAndInitialSchema: addOperationAndInitialSchema, updateOperationSchema: updateOperationSchema, setOperationDescription: setOperationDescription, addOperationError: addOperationError, deleteOperationError: deleteOperationError, setOperationErrorName: setOperationErrorName }))] }));
9
+ }
@@ -0,0 +1,19 @@
1
+ import { Module as TModule } from "document-model";
2
+ type Props = {
3
+ modules: TModule[];
4
+ allOperations: TModule["operations"];
5
+ addModule: (name: string) => Promise<string | undefined>;
6
+ updateModuleName: (id: string, name: string) => void;
7
+ deleteModule: (id: string) => void;
8
+ updateOperationName: (id: string, name: string) => void;
9
+ deleteOperation: (id: string) => void;
10
+ addOperationAndInitialSchema: (moduleId: string, name: string) => Promise<string | undefined>;
11
+ updateOperationSchema: (id: string, newDoc: string) => void;
12
+ setOperationDescription: (id: string, description: string) => void;
13
+ addOperationError: (operationId: string, errorName: string) => Promise<string | undefined>;
14
+ deleteOperationError: (id: string) => void;
15
+ setOperationErrorName: (operationId: string, errorId: string, name: string) => void;
16
+ };
17
+ export declare function Modules({ modules, allOperations, addModule, updateModuleName, deleteModule, updateOperationName, deleteOperation, addOperationAndInitialSchema, updateOperationSchema, setOperationDescription, addOperationError, deleteOperationError, setOperationErrorName, }: Props): import("react/jsx-runtime").JSX.Element;
18
+ export {};
19
+ //# sourceMappingURL=modules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modules.d.ts","sourceRoot":"","sources":["../../../document-model-editor/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