@powerhousedao/powerhouse-vetra-packages 6.2.3-dev.5 → 6.2.3-dev.50

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 (117) hide show
  1. package/dist/browser/assets/{entry-5_Eh4a2Z.js → entry-E7pSm84X.js} +111 -7
  2. package/dist/browser/assets/{projection-entry-5PVbP10h.js → projection-entry-UE4mfnXc.js} +99 -21
  3. package/dist/browser/document-models/index.js +2 -1
  4. package/dist/browser/{documents-J_l59mSV.js → documents-CRzouuNR.js} +631 -752
  5. package/dist/browser/documents-CRzouuNR.js.map +1 -0
  6. package/dist/browser/editor-C7KBR_ar.js +4676 -0
  7. package/dist/browser/editor-C7KBR_ar.js.map +1 -0
  8. package/dist/browser/{editor-Cbl_EDjI.js → editor-CiR6XQBO.js} +4 -5
  9. package/dist/browser/{editor-Cbl_EDjI.js.map → editor-CiR6XQBO.js.map} +1 -1
  10. package/dist/browser/editors/document-model-editor/module.js +1 -1
  11. package/dist/browser/editors/document-model-editor/module.js.map +1 -1
  12. package/dist/browser/editors/generic-drive-explorer/index.js +81 -65
  13. package/dist/browser/editors/generic-drive-explorer/index.js.map +1 -1
  14. package/dist/browser/editors/generic-drive-explorer/module.js +1 -1
  15. package/dist/browser/editors/generic-drive-explorer/module.js.map +1 -1
  16. package/dist/browser/folder-view-DSgXN79D.js +4409 -0
  17. package/dist/browser/folder-view-DSgXN79D.js.map +1 -0
  18. package/dist/browser/{graphql-editor-BcL3-Zha.js → graphql-editor-Cgi5UOrF.js} +98 -88
  19. package/dist/browser/graphql-editor-Cgi5UOrF.js.map +1 -0
  20. package/dist/{node/hooks-D0DcS3MV.mjs → browser/hooks-eQxBX7g4.js} +824 -444
  21. package/dist/browser/{hooks-KKcNp2X0.js.map → hooks-eQxBX7g4.js.map} +1 -1
  22. package/dist/browser/index.js +137 -34
  23. package/dist/browser/index.js.map +1 -1
  24. package/dist/browser/{json-editor-DHXQRIN5.js → json-editor-DfRD-pfk.js} +8 -9
  25. package/dist/browser/{json-editor-DHXQRIN5.js.map → json-editor-DfRD-pfk.js.map} +1 -1
  26. package/dist/browser/{parser-CkF6Qt8V.js → parser-DtbeHA3H.js} +7 -6
  27. package/dist/browser/{parser-CkF6Qt8V.js.map → parser-DtbeHA3H.js.map} +1 -1
  28. package/dist/browser/rolldown-runtime-DC62tzP2.js +33 -0
  29. package/dist/browser/src-CrUksCLW-B2dkRdgq.js +5254 -0
  30. package/dist/browser/src-CrUksCLW-B2dkRdgq.js.map +1 -0
  31. package/dist/browser/state-schemas-B5Bk_l1s.js +696 -0
  32. package/dist/browser/state-schemas-B5Bk_l1s.js.map +1 -0
  33. package/dist/browser/tslib.es6-Cno80yFJ.js +32 -0
  34. package/dist/browser/tslib.es6-Cno80yFJ.js.map +1 -0
  35. package/dist/node/document-models/index.mjs +2 -1
  36. package/dist/node/documents-D70S9PZL.mjs +17 -0
  37. package/dist/node/documents-D70S9PZL.mjs.map +1 -0
  38. package/dist/node/editor-96sMeumV.mjs +4597 -0
  39. package/dist/node/editor-96sMeumV.mjs.map +1 -0
  40. package/dist/node/{editor-DG1q4Y55.mjs → editor-wqvKwcO5.mjs} +4 -5
  41. package/dist/node/{editor-DG1q4Y55.mjs.map → editor-wqvKwcO5.mjs.map} +1 -1
  42. package/dist/node/editors/document-model-editor/module.mjs +1 -1
  43. package/dist/node/editors/document-model-editor/module.mjs.map +1 -1
  44. package/dist/node/editors/generic-drive-explorer/index.mjs +26 -21
  45. package/dist/node/editors/generic-drive-explorer/index.mjs.map +1 -1
  46. package/dist/node/editors/generic-drive-explorer/module.mjs +1 -1
  47. package/dist/node/editors/generic-drive-explorer/module.mjs.map +1 -1
  48. package/dist/node/folder-view-ktfv2Cvw.mjs +4409 -0
  49. package/dist/node/folder-view-ktfv2Cvw.mjs.map +1 -0
  50. package/dist/node/{graphql-BfAoPeWM.mjs → graphql-Dp4j7rmx.mjs} +50 -49
  51. package/dist/node/{graphql-BfAoPeWM.mjs.map → graphql-Dp4j7rmx.mjs.map} +1 -1
  52. package/dist/node/{graphql-editor-B-XIb6az.mjs → graphql-editor-CBJXEY_C.mjs} +77 -63
  53. package/dist/node/graphql-editor-CBJXEY_C.mjs.map +1 -0
  54. package/dist/{browser/hooks-KKcNp2X0.js → node/hooks-C2b46djt.mjs} +824 -444
  55. package/dist/node/{hooks-D0DcS3MV.mjs.map → hooks-C2b46djt.mjs.map} +1 -1
  56. package/dist/node/index.mjs +158 -35
  57. package/dist/node/index.mjs.map +1 -1
  58. package/dist/node/{json-editor-DB0vi6tV.mjs → json-editor-DaqHARBD.mjs} +8 -9
  59. package/dist/node/{json-editor-DB0vi6tV.mjs.map → json-editor-DaqHARBD.mjs.map} +1 -1
  60. package/dist/node/{schema-context-DL8jhi_d.mjs → schema-context-CojjnSE6.mjs} +6 -5
  61. package/dist/node/schema-context-CojjnSE6.mjs.map +1 -0
  62. package/dist/node/src-CrUksCLW-TvF37aMo.mjs +5935 -0
  63. package/dist/node/src-CrUksCLW-TvF37aMo.mjs.map +1 -0
  64. package/dist/node/state-schemas-BHuo0GPl.mjs +698 -0
  65. package/dist/node/state-schemas-BHuo0GPl.mjs.map +1 -0
  66. package/dist/node/{main-B1tRsYOp.mjs → tslib.es6-VORZjfk3.mjs} +40 -202
  67. package/dist/node/tslib.es6-VORZjfk3.mjs.map +1 -0
  68. package/package.json +12 -11
  69. package/dist/browser/button-CuO8Gh3v.js +0 -696
  70. package/dist/browser/button-CuO8Gh3v.js.map +0 -1
  71. package/dist/browser/connect-BtHSAuSc.js +0 -14328
  72. package/dist/browser/connect-BtHSAuSc.js.map +0 -1
  73. package/dist/browser/dist-B4FWbuEM.js +0 -4148
  74. package/dist/browser/dist-B4FWbuEM.js.map +0 -1
  75. package/dist/browser/dist-BAJ5nRDl.js +0 -2711
  76. package/dist/browser/dist-BAJ5nRDl.js.map +0 -1
  77. package/dist/browser/dist-D69hfRZN.js +0 -4641
  78. package/dist/browser/dist-D69hfRZN.js.map +0 -1
  79. package/dist/browser/document-drive-BEXJ-rHp.js +0 -8277
  80. package/dist/browser/document-drive-BEXJ-rHp.js.map +0 -1
  81. package/dist/browser/documents-J_l59mSV.js.map +0 -1
  82. package/dist/browser/editor-mNThkZOv.js +0 -1809
  83. package/dist/browser/editor-mNThkZOv.js.map +0 -1
  84. package/dist/browser/folder-view-D8AkN1Oj.js +0 -232
  85. package/dist/browser/folder-view-D8AkN1Oj.js.map +0 -1
  86. package/dist/browser/graphql-editor-BcL3-Zha.js.map +0 -1
  87. package/dist/browser/lib-ewnRj2dJ.js +0 -209
  88. package/dist/browser/lib-ewnRj2dJ.js.map +0 -1
  89. package/dist/browser/printer-CEYr4JOg.js +0 -604
  90. package/dist/browser/printer-CEYr4JOg.js.map +0 -1
  91. package/dist/browser/schema-context-ZyeclQwy.js +0 -69
  92. package/dist/browser/schema-context-ZyeclQwy.js.map +0 -1
  93. package/dist/browser/state-schemas-C4F8lReN.js +0 -298
  94. package/dist/browser/state-schemas-C4F8lReN.js.map +0 -1
  95. package/dist/node/button-Da7CxMn7.mjs +0 -678
  96. package/dist/node/button-Da7CxMn7.mjs.map +0 -1
  97. package/dist/node/connect-B6IQsY6u.mjs +0 -15022
  98. package/dist/node/connect-B6IQsY6u.mjs.map +0 -1
  99. package/dist/node/dist-CzYOpeXN.mjs +0 -2711
  100. package/dist/node/dist-CzYOpeXN.mjs.map +0 -1
  101. package/dist/node/dist-DT7jI9ol.mjs +0 -4148
  102. package/dist/node/dist-DT7jI9ol.mjs.map +0 -1
  103. package/dist/node/dist-hd-KLWy7.mjs +0 -4649
  104. package/dist/node/dist-hd-KLWy7.mjs.map +0 -1
  105. package/dist/node/document-drive-CkV9NvD7.mjs +0 -8294
  106. package/dist/node/document-drive-CkV9NvD7.mjs.map +0 -1
  107. package/dist/node/documents-DCf53bzO.mjs +0 -747
  108. package/dist/node/documents-DCf53bzO.mjs.map +0 -1
  109. package/dist/node/editor-C93fdI28.mjs +0 -1809
  110. package/dist/node/editor-C93fdI28.mjs.map +0 -1
  111. package/dist/node/folder-view-BGabHV7H.mjs +0 -232
  112. package/dist/node/folder-view-BGabHV7H.mjs.map +0 -1
  113. package/dist/node/graphql-editor-B-XIb6az.mjs.map +0 -1
  114. package/dist/node/main-B1tRsYOp.mjs.map +0 -1
  115. package/dist/node/schema-context-DL8jhi_d.mjs.map +0 -1
  116. package/dist/node/state-schemas-BGsgtEG1.mjs +0 -299
  117. package/dist/node/state-schemas-BGsgtEG1.mjs.map +0 -1
@@ -1,1809 +0,0 @@
1
- import { E as $ZodError, T as parseAsync, a as snakeCase, h as object, n as constantCase, p as literal, r as pascalCase, v as string, w as parse, x as url, y as union } from "./dist-B4FWbuEM.js";
2
- import { $ as setModuleName, F as deleteModule, I as deleteOperation, J as setInitialState, K as setAuthorName, L as deleteOperationError, Q as setModelName, W as releaseNewVersion, X as setModelExtension, Y as setModelDescription, Z as setModelId, at as setStateSchema, b as addOperationError, ft as generateId, it as setOperationSchema, nt as setOperationErrorName, q as setAuthorWebsite, rt as setOperationName, tt as setOperationDescription, v as addModule, y as addOperation } from "./document-drive-BEXJ-rHp.js";
3
- import { c as Kind, t as parse$1 } from "./parser-CkF6Qt8V.js";
4
- import { t as print } from "./printer-CEYr4JOg.js";
5
- import { a as compareStringsWithoutWhitespace, c as isEmptyOperationSchema, f as makeOperationInitialDoc, l as makeEmptyOperationSchema, m as renameSchemaType, n as ensureValidOperationSchemaInputName, o as handleModelNameChange, s as initializeModelSchema, t as Button, u as makeInitialSchemaDoc } from "./button-CuO8Gh3v.js";
6
- import { _ as Modal, a as DocumentToolbar, b as Primitive, c as ModalButton, d as FormProvider, f as appendErrors, g as useFormContext, h as useForm, m as set, p as get, r as ConnectSelect, u as Controller, x as Slot } from "./connect-BtHSAuSc.js";
7
- import { w as twMerge } from "./dist-BAJ5nRDl.js";
8
- import { j as usePHToast, v as useSetPHDocumentEditorConfig, x as useSelectedDocumentOfType } from "./dist-D69hfRZN.js";
9
- import { t as SchemaContextProvider } from "./schema-context-ZyeclQwy.js";
10
- import * as React$1 from "react";
11
- import React, { Suspense, forwardRef, lazy, useCallback, useEffect, useId, useImperativeHandle, useRef, useState } from "react";
12
- import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
13
- //#region ../../node_modules/.pnpm/clsx@2.0.0/node_modules/clsx/dist/clsx.mjs
14
- function r$1(e) {
15
- var t, f, n = "";
16
- if ("string" == typeof e || "number" == typeof e) n += e;
17
- else if ("object" == typeof e) if (Array.isArray(e)) for (t = 0; t < e.length; t++) e[t] && (f = r$1(e[t])) && (n && (n += " "), n += f);
18
- else for (t in e) e[t] && (n && (n += " "), n += t);
19
- return n;
20
- }
21
- function clsx() {
22
- for (var e, t, f = 0, n = ""; f < arguments.length;) (e = arguments[f++]) && (t = r$1(e)) && (n && (n += " "), n += t);
23
- return n;
24
- }
25
- //#endregion
26
- //#region ../../node_modules/.pnpm/class-variance-authority@0.7.0/node_modules/class-variance-authority/dist/index.mjs
27
- const falsyToString = (value) => typeof value === "boolean" ? "".concat(value) : value === 0 ? "0" : value;
28
- const cx = clsx;
29
- const cva = (base, config) => {
30
- return (props) => {
31
- var ref;
32
- if ((config === null || config === void 0 ? void 0 : config.variants) == null) return cx(base, props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
33
- const { variants, defaultVariants } = config;
34
- const getVariantClassNames = Object.keys(variants).map((variant) => {
35
- const variantProp = props === null || props === void 0 ? void 0 : props[variant];
36
- const defaultVariantProp = defaultVariants === null || defaultVariants === void 0 ? void 0 : defaultVariants[variant];
37
- if (variantProp === null) return null;
38
- const variantKey = falsyToString(variantProp) || falsyToString(defaultVariantProp);
39
- return variants[variant][variantKey];
40
- });
41
- const propsWithoutUndefined = props && Object.entries(props).reduce((acc, param) => {
42
- let [key, value] = param;
43
- if (value === void 0) return acc;
44
- acc[key] = value;
45
- return acc;
46
- }, {});
47
- return cx(base, getVariantClassNames, config === null || config === void 0 ? void 0 : (ref = config.compoundVariants) === null || ref === void 0 ? void 0 : ref.reduce((acc, param1) => {
48
- let { class: cvClass, className: cvClassName, ...compoundVariantOptions } = param1;
49
- return Object.entries(compoundVariantOptions).every((param) => {
50
- let [key, value] = param;
51
- return Array.isArray(value) ? value.includes({
52
- ...defaultVariants,
53
- ...propsWithoutUndefined
54
- }[key]) : {
55
- ...defaultVariants,
56
- ...propsWithoutUndefined
57
- }[key] === value;
58
- }) ? [
59
- ...acc,
60
- cvClass,
61
- cvClassName
62
- ] : acc;
63
- }, []), props === null || props === void 0 ? void 0 : props.class, props === null || props === void 0 ? void 0 : props.className);
64
- };
65
- };
66
- //#endregion
67
- //#region editors/document-model-editor/components/divider.tsx
68
- function Divider({ className, size = "sm", margin = "md" }) {
69
- function getSize() {
70
- if (size === "sm") return "h-px";
71
- if (size === "md") return "h-1";
72
- return "h-1.5";
73
- }
74
- function getMargin() {
75
- if (margin === "sm") return "my-4";
76
- if (margin === "md") return "my-6";
77
- return "my-8";
78
- }
79
- return /* @__PURE__ */ jsx("div", { className: twMerge("bg-secondary", getSize(), getMargin(), className) });
80
- }
81
- //#endregion
82
- //#region ../../node_modules/.pnpm/@hookform+resolvers@5.2.2_react-hook-form@7.71.2_react@19.2.6_/node_modules/@hookform/resolvers/dist/resolvers.mjs
83
- const r = (t, r, o) => {
84
- if (t && "reportValidity" in t) {
85
- const s = get(o, r);
86
- t.setCustomValidity(s && s.message || ""), t.reportValidity();
87
- }
88
- }, o = (e, t) => {
89
- for (const o in t.fields) {
90
- const s = t.fields[o];
91
- s && s.ref && "reportValidity" in s.ref ? r(s.ref, o, e) : s && s.refs && s.refs.forEach((t) => r(t, o, e));
92
- }
93
- }, s$1 = (r, s) => {
94
- s.shouldUseNativeValidation && o(r, s);
95
- const n = {};
96
- for (const o in r) {
97
- const f = get(s.fields, o), c = Object.assign(r[o] || {}, { ref: f && f.ref });
98
- if (i$1(s.names || Object.keys(r), o)) {
99
- const r = Object.assign({}, get(n, o));
100
- set(r, "root", c), set(n, o, r);
101
- } else set(n, o, c);
102
- }
103
- return n;
104
- }, i$1 = (e, t) => {
105
- const r = n(t);
106
- return e.some((e) => n(e).match(`^${r}\\.\\d+`));
107
- };
108
- function n(e) {
109
- return e.replace(/\]|\[/g, "");
110
- }
111
- //#endregion
112
- //#region ../../node_modules/.pnpm/@hookform+resolvers@5.2.2_react-hook-form@7.71.2_react@19.2.6_/node_modules/@hookform/resolvers/zod/dist/zod.mjs
113
- function t(r, e) {
114
- try {
115
- var o = r();
116
- } catch (r) {
117
- return e(r);
118
- }
119
- return o && o.then ? o.then(void 0, e) : o;
120
- }
121
- function s(r, e) {
122
- for (var n = {}; r.length;) {
123
- var t = r[0], s = t.code, i = t.message, a = t.path.join(".");
124
- if (!n[a]) if ("unionErrors" in t) {
125
- var u = t.unionErrors[0].errors[0];
126
- n[a] = {
127
- message: u.message,
128
- type: u.code
129
- };
130
- } else n[a] = {
131
- message: i,
132
- type: s
133
- };
134
- if ("unionErrors" in t && t.unionErrors.forEach(function(e) {
135
- return e.errors.forEach(function(e) {
136
- return r.push(e);
137
- });
138
- }), e) {
139
- var c = n[a].types, f = c && c[t.code];
140
- n[a] = appendErrors(a, e, n, s, f ? [].concat(f, t.message) : t.message);
141
- }
142
- r.shift();
143
- }
144
- return n;
145
- }
146
- function i(r, e) {
147
- for (var n = {}; r.length;) {
148
- var t = r[0], s = t.code, i = t.message, a = t.path.join(".");
149
- if (!n[a]) if ("invalid_union" === t.code && t.errors.length > 0) {
150
- var u = t.errors[0][0];
151
- n[a] = {
152
- message: u.message,
153
- type: u.code
154
- };
155
- } else n[a] = {
156
- message: i,
157
- type: s
158
- };
159
- if ("invalid_union" === t.code && t.errors.forEach(function(e) {
160
- return e.forEach(function(e) {
161
- return r.push(e);
162
- });
163
- }), e) {
164
- var c = n[a].types, f = c && c[t.code];
165
- n[a] = appendErrors(a, e, n, s, f ? [].concat(f, t.message) : t.message);
166
- }
167
- r.shift();
168
- }
169
- return n;
170
- }
171
- function a(o$1, a, u) {
172
- if (void 0 === u && (u = {}), function(r) {
173
- return "_def" in r && "object" == typeof r._def && "typeName" in r._def;
174
- }(o$1)) return function(n, i, c) {
175
- try {
176
- return Promise.resolve(t(function() {
177
- return Promise.resolve(o$1["sync" === u.mode ? "parse" : "parseAsync"](n, a)).then(function(e) {
178
- return c.shouldUseNativeValidation && o({}, c), {
179
- errors: {},
180
- values: u.raw ? Object.assign({}, n) : e
181
- };
182
- });
183
- }, function(r) {
184
- if (function(r) {
185
- return Array.isArray(null == r ? void 0 : r.issues);
186
- }(r)) return {
187
- values: {},
188
- errors: s$1(s(r.errors, !c.shouldUseNativeValidation && "all" === c.criteriaMode), c)
189
- };
190
- throw r;
191
- }));
192
- } catch (r) {
193
- return Promise.reject(r);
194
- }
195
- };
196
- if (function(r) {
197
- return "_zod" in r && "object" == typeof r._zod;
198
- }(o$1)) return function(s, c, f) {
199
- try {
200
- return Promise.resolve(t(function() {
201
- return Promise.resolve(("sync" === u.mode ? parse : parseAsync)(o$1, s, a)).then(function(e) {
202
- return f.shouldUseNativeValidation && o({}, f), {
203
- errors: {},
204
- values: u.raw ? Object.assign({}, s) : e
205
- };
206
- });
207
- }, function(r) {
208
- if (function(r) {
209
- return r instanceof $ZodError;
210
- }(r)) return {
211
- values: {},
212
- errors: s$1(i(r.issues, !f.shouldUseNativeValidation && "all" === f.criteriaMode), f)
213
- };
214
- throw r;
215
- }));
216
- } catch (r) {
217
- return Promise.reject(r);
218
- }
219
- };
220
- throw new Error("Invalid input: not a Zod schema");
221
- }
222
- //#endregion
223
- //#region editors/document-model-editor/schemas/inputs.ts
224
- const isUppercase = (value) => !/\p{Ll}/u.test(value);
225
- const isLowercase = (value) => !/\p{Lu}/u.test(value);
226
- function createNameSchema(options = {}) {
227
- const { required = false, allowEmpty = false, unique = [] } = options;
228
- const baseSchema = allowEmpty ? string() : string().min(1);
229
- const uniqueRefinement = baseSchema.refine((value) => {
230
- if (!value && allowEmpty) return true;
231
- return !unique.map((n) => n.toLowerCase()).includes(value.replace(/^\s+|\s+$/g, "_").toLowerCase());
232
- }, { message: "Item with this name already exists" });
233
- if (!required) return unique.length > 0 ? string().optional().refine((value) => {
234
- if (value === void 0) return true;
235
- if (!value && allowEmpty) return true;
236
- return !unique.map((n) => n.toLowerCase()).includes(value.replace(/^\s+|\s+$/g, "_").toLowerCase());
237
- }, { message: "Item with this name already exists" }) : string().optional();
238
- return unique.length > 0 ? uniqueRefinement : baseSchema;
239
- }
240
- function createConstantCaseSchema(options = {}) {
241
- return createNameSchema(options).transform((value) => value ? value.toUpperCase() : value).refine((value) => !value || isUppercase(value), { message: "Must be uppercase" });
242
- }
243
- function createLowercaseSnakeCaseSchema(options = {}) {
244
- return createNameSchema(options).transform((value) => value ? value.toLowerCase() : value).refine((value) => !value || isLowercase(value), { message: "Must be lowercase" });
245
- }
246
- function toLowercaseSnakeCase(value, options = {}) {
247
- return createLowercaseSnakeCaseSchema(options).parse(snakeCase(value));
248
- }
249
- function toConstantCase(value, options = {}) {
250
- return createConstantCaseSchema(options).parse(constantCase(value));
251
- }
252
- object({
253
- name: createNameSchema({ allowEmpty: true }),
254
- website: union([url(), literal("")]).optional().default("")
255
- }).default({
256
- name: "",
257
- website: ""
258
- });
259
- //#endregion
260
- //#region editors/document-model-editor/context/form-context.ts
261
- const FormFieldContext = React.createContext({});
262
- const FormItemContext = React.createContext({});
263
- //#endregion
264
- //#region editors/document-model-editor/hooks/useFormField.ts
265
- const useFormField = () => {
266
- const fieldContext = React.useContext(FormFieldContext);
267
- const itemContext = React.useContext(FormItemContext);
268
- const { getFieldState, formState } = useFormContext();
269
- const fieldState = getFieldState(fieldContext.name, formState);
270
- if (!fieldContext) throw new Error("useFormField should be used within <FormField>");
271
- const { id } = itemContext;
272
- return {
273
- id,
274
- name: fieldContext.name,
275
- formItemId: `${id}-form-item`,
276
- formDescriptionId: `${id}-form-item-description`,
277
- formMessageId: `${id}-form-item-message`,
278
- ...fieldState
279
- };
280
- };
281
- //#endregion
282
- //#region ../../node_modules/.pnpm/@radix-ui+react-label@2.1.8_@types+react-dom@19.2.3_@types+react@19.2.14__@types+react@_8d35ec453e0b59eefe06771bb1432577/node_modules/@radix-ui/react-label/dist/index.mjs
283
- var NAME = "Label";
284
- var Label$1 = React$1.forwardRef((props, forwardedRef) => {
285
- return /* @__PURE__ */ jsx(Primitive.label, {
286
- ...props,
287
- ref: forwardedRef,
288
- onMouseDown: (event) => {
289
- if (event.target.closest("button, input, select, textarea")) return;
290
- props.onMouseDown?.(event);
291
- if (!event.defaultPrevented && event.detail > 1) event.preventDefault();
292
- }
293
- });
294
- });
295
- Label$1.displayName = NAME;
296
- var Root = Label$1;
297
- //#endregion
298
- //#region editors/document-model-editor/components/label.tsx
299
- const labelVariants = cva("text-sm leading-none font-medium peer-disabled:disabled-effect");
300
- const Label = React$1.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(Root, {
301
- ref,
302
- className: twMerge(labelVariants(), className),
303
- ...props
304
- }));
305
- Label.displayName = Root.displayName;
306
- //#endregion
307
- //#region editors/document-model-editor/components/form.tsx
308
- const Form = FormProvider;
309
- const FormField = ({ ...props }) => {
310
- return /* @__PURE__ */ jsx(FormFieldContext.Provider, {
311
- value: { name: props.name },
312
- children: /* @__PURE__ */ jsx(Controller, { ...props })
313
- });
314
- };
315
- const FormItem = React$1.forwardRef(({ className, ...props }, ref) => {
316
- const id = React$1.useId();
317
- return /* @__PURE__ */ jsx(FormItemContext.Provider, {
318
- value: { id },
319
- children: /* @__PURE__ */ jsx("div", {
320
- ref,
321
- className,
322
- ...props
323
- })
324
- });
325
- });
326
- FormItem.displayName = "FormItem";
327
- const FormLabel = React$1.forwardRef(({ className, ...props }, ref) => {
328
- const { error, formItemId } = useFormField();
329
- return /* @__PURE__ */ jsx(Label, {
330
- ref,
331
- className: twMerge(error && "text-destructive", className),
332
- htmlFor: formItemId,
333
- ...props
334
- });
335
- });
336
- FormLabel.displayName = "FormLabel";
337
- const FormControl = React$1.forwardRef(({ ...props }, ref) => {
338
- const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
339
- return /* @__PURE__ */ jsx(Slot, {
340
- ref,
341
- id: formItemId,
342
- "aria-describedby": !error ? formDescriptionId : `${formDescriptionId} ${formMessageId}`,
343
- "aria-invalid": !!error,
344
- ...props
345
- });
346
- });
347
- FormControl.displayName = "FormControl";
348
- const FormDescription = React$1.forwardRef(({ className, ...props }, ref) => {
349
- const { formDescriptionId } = useFormField();
350
- return /* @__PURE__ */ jsx("p", {
351
- ref,
352
- id: formDescriptionId,
353
- className: twMerge("text-sm text-foreground", className),
354
- ...props
355
- });
356
- });
357
- FormDescription.displayName = "FormDescription";
358
- const FormMessage = React$1.forwardRef(({ className, children, ...props }, ref) => {
359
- const { error, formMessageId } = useFormField();
360
- const body = error ? String(error.message) : children;
361
- if (!body) return null;
362
- return /* @__PURE__ */ jsx("p", {
363
- ref,
364
- id: formMessageId,
365
- className: twMerge("text-sm font-medium text-destructive", className),
366
- ...props,
367
- children: body
368
- });
369
- });
370
- FormMessage.displayName = "FormMessage";
371
- //#endregion
372
- //#region editors/document-model-editor/components/text-area.tsx
373
- const Textarea = forwardRef(({ className, ...props }, ref) => {
374
- const textareaRef = useRef(null);
375
- const adjustHeight = useCallback((textarea) => {
376
- textarea.style.height = "auto";
377
- const newHeight = Math.max(textarea.scrollHeight, textarea.offsetHeight);
378
- textarea.style.height = `${newHeight}px`;
379
- }, []);
380
- const handleInput = useCallback((e) => {
381
- adjustHeight(e.currentTarget);
382
- }, [adjustHeight]);
383
- React$1.useEffect(() => {
384
- if (textareaRef.current) adjustHeight(textareaRef.current);
385
- }, [adjustHeight]);
386
- useImperativeHandle(ref, () => ({
387
- focus: () => textareaRef.current?.focus(),
388
- element: textareaRef.current
389
- }));
390
- return /* @__PURE__ */ jsx("textarea", {
391
- ...props,
392
- className: twMerge("min-h-10 w-full resize-none rounded-md border border-border bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus-visible:outline-none disabled:disabled-effect", className),
393
- ref: textareaRef,
394
- onInput: handleInput
395
- });
396
- });
397
- Textarea.displayName = "Textarea";
398
- //#endregion
399
- //#region editors/document-model-editor/components/text-field.tsx
400
- const TextField = forwardRef(({ name, value, onSubmit, label, placeholder, unique, className = "", rows = 1, focusOnMount = false, required = false, allowEmpty = false, shouldReset = false, onChange }, ref) => {
401
- const textareaRef = useRef(null);
402
- const id = useId();
403
- useEffect(() => {
404
- if (focusOnMount && textareaRef.current) textareaRef.current.focus();
405
- }, [focusOnMount]);
406
- const form = useForm({
407
- resolver: a(object({ [name]: createNameSchema({
408
- required,
409
- allowEmpty,
410
- unique
411
- }) })),
412
- defaultValues: { [name]: value ?? "" }
413
- });
414
- const handleSubmit = useCallback((values) => {
415
- const newValue = values[name];
416
- if (newValue === void 0 || value === newValue) return;
417
- onSubmit(newValue);
418
- if (shouldReset) form.reset({ [name]: "" });
419
- }, [
420
- name,
421
- value,
422
- onSubmit,
423
- form,
424
- shouldReset
425
- ]);
426
- const handleBlur = useCallback(async () => {
427
- const currentValue = form.getValues()[name] ?? "";
428
- if (value === null || value === void 0) {
429
- if (!currentValue || currentValue.trim() === "") return;
430
- }
431
- if (compareStringsWithoutWhitespace(currentValue, value ?? "")) return;
432
- try {
433
- await form.trigger();
434
- if (form.formState.isValid) await form.handleSubmit(handleSubmit)();
435
- } catch (_e) {}
436
- }, [
437
- form,
438
- handleSubmit,
439
- name,
440
- value
441
- ]);
442
- const onEnterKeyDown = useCallback((e) => {
443
- if (e.key === "Enter") {
444
- e.preventDefault();
445
- e.target.blur();
446
- }
447
- }, []);
448
- const handleChange = useCallback((e) => {
449
- const newValue = e.target.value;
450
- onChange?.(newValue);
451
- }, [onChange]);
452
- useImperativeHandle(ref, () => ({ focus: () => textareaRef.current?.focus() }));
453
- useEffect(() => {
454
- form.reset({ [name]: value ?? "" });
455
- }, [
456
- form,
457
- name,
458
- value
459
- ]);
460
- return /* @__PURE__ */ jsx(Form, {
461
- ...form,
462
- children: /* @__PURE__ */ jsx(FormField, {
463
- control: form.control,
464
- name,
465
- render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, {
466
- className: "grid h-full grid-rows-[auto,1fr] gap-2 overflow-visible",
467
- children: [
468
- !!label && /* @__PURE__ */ jsx(FormLabel, {
469
- htmlFor: name,
470
- className: "text-sm font-medium text-foreground",
471
- children: label
472
- }),
473
- /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Textarea, {
474
- ...field,
475
- id,
476
- name,
477
- ref: (node) => {
478
- if (node) {
479
- field.ref(node.element);
480
- textareaRef.current = node;
481
- }
482
- },
483
- placeholder,
484
- onBlur: () => void handleBlur(),
485
- onChange: (e) => {
486
- field.onChange(e);
487
- handleChange(e);
488
- },
489
- onKeyDown: onEnterKeyDown,
490
- rows,
491
- className
492
- }) }),
493
- /* @__PURE__ */ jsx(FormMessage, {})
494
- ]
495
- })
496
- })
497
- });
498
- });
499
- TextField.displayName = "TextField";
500
- object({
501
- name: string(),
502
- documentType: string(),
503
- extension: string().optional().default(""),
504
- description: string(),
505
- authorName: string(),
506
- authorWebsite: string()
507
- });
508
- function ModelMetadata(props) {
509
- return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(ModelNameForm, { ...props }), /* @__PURE__ */ jsx("div", {
510
- className: "flex h-full flex-col gap-4",
511
- children: /* @__PURE__ */ jsxs("div", {
512
- className: "grid flex-1 grid-cols-3 items-start gap-4",
513
- children: [/* @__PURE__ */ jsxs("div", {
514
- className: "col-span-2 flex h-full flex-col gap-4",
515
- children: [/* @__PURE__ */ jsx("div", {
516
- className: "shrink-0",
517
- children: /* @__PURE__ */ jsx(DocumentTypeForm, { ...props })
518
- }), /* @__PURE__ */ jsx("div", {
519
- className: "min-h-0 flex-1",
520
- children: /* @__PURE__ */ jsx(DescriptionForm, { ...props })
521
- })]
522
- }), /* @__PURE__ */ jsxs("div", {
523
- className: "col-span-1 flex flex-col gap-4",
524
- children: [
525
- /* @__PURE__ */ jsx(AuthorNameForm, { ...props }),
526
- /* @__PURE__ */ jsx(AuthorWebsiteForm, { ...props }),
527
- /* @__PURE__ */ jsx(ModelExtensionForm, { ...props })
528
- ]
529
- })]
530
- })
531
- })] });
532
- }
533
- function ModelNameForm(props) {
534
- const { name, globalStateSchema, localStateSchema, setModelName, setStateSchema } = props;
535
- return /* @__PURE__ */ jsx(TextField, {
536
- name: "name",
537
- value: name,
538
- onSubmit: useCallback((newName) => {
539
- if (name === newName) return;
540
- setModelName(newName);
541
- if (!!!globalStateSchema) {
542
- setStateSchema(makeInitialSchemaDoc(newName, "global"), "global");
543
- return;
544
- }
545
- setStateSchema(renameSchemaType(globalStateSchema, name, newName, "global"), "global");
546
- if (localStateSchema) setStateSchema(renameSchemaType(localStateSchema, name, newName, "local"), "local");
547
- handleModelNameChange({
548
- oldName: name,
549
- newName,
550
- globalStateSchema,
551
- localStateSchema,
552
- setStateSchema
553
- });
554
- }, [
555
- name,
556
- globalStateSchema,
557
- localStateSchema,
558
- setStateSchema,
559
- setModelName
560
- ]),
561
- placeholder: "Model name",
562
- className: "border-none pl-0 text-xl font-bold text-foreground",
563
- required: true,
564
- focusOnMount: true
565
- });
566
- }
567
- function DocumentTypeForm(props) {
568
- const { documentType, setModelId } = props;
569
- return /* @__PURE__ */ jsx(TextField, {
570
- label: "Document Type *",
571
- name: "powerhouse/document-model",
572
- value: documentType,
573
- onSubmit: setModelId,
574
- placeholder: "Document Type",
575
- required: true
576
- });
577
- }
578
- function ModelExtensionForm(props) {
579
- const { extension, setModelExtension } = props;
580
- return /* @__PURE__ */ jsx(TextField, {
581
- name: "extension",
582
- value: extension,
583
- onSubmit: setModelExtension,
584
- label: "Model Extension",
585
- placeholder: "Example .phdm",
586
- allowEmpty: true
587
- });
588
- }
589
- function DescriptionForm(props) {
590
- const { description, setModelDescription } = props;
591
- return /* @__PURE__ */ jsx(TextField, {
592
- name: "description",
593
- label: "Model Description",
594
- value: description,
595
- onSubmit: setModelDescription,
596
- placeholder: "Describe your document to others",
597
- allowEmpty: true,
598
- className: "h-full"
599
- });
600
- }
601
- function AuthorNameForm(props) {
602
- const { authorName, setAuthorName } = props;
603
- return /* @__PURE__ */ jsx(TextField, {
604
- name: "authorName",
605
- value: authorName,
606
- onSubmit: setAuthorName,
607
- label: "Author Name",
608
- placeholder: "Username or organisation",
609
- allowEmpty: true
610
- });
611
- }
612
- function AuthorWebsiteForm(props) {
613
- const { authorWebsite, setAuthorWebsite } = props;
614
- return /* @__PURE__ */ jsx(TextField, {
615
- name: "authorWebsite",
616
- value: authorWebsite,
617
- label: "Website URL",
618
- onSubmit: (newAuthorWebsite) => {
619
- if (!!authorWebsite && !newAuthorWebsite) return;
620
- setAuthorWebsite(newAuthorWebsite);
621
- },
622
- placeholder: "https://www.powerhouse.inc/",
623
- allowEmpty: true
624
- });
625
- }
626
- //#endregion
627
- //#region editors/document-model-editor/components/module-form.tsx
628
- function ModuleForm({ module, onAddModule, updateModuleName, modules = [] }) {
629
- const isEdit = !!module;
630
- const moduleNames = modules.map((m) => m.name);
631
- const handleSubmit = async (name) => {
632
- const formattedName = toLowercaseSnakeCase(name);
633
- if (!formattedName.length) return;
634
- if (isEdit) {
635
- if (formattedName !== module.name) updateModuleName(module.id, formattedName);
636
- } else await onAddModule(formattedName);
637
- };
638
- return /* @__PURE__ */ jsx(TextField, {
639
- name: "name",
640
- label: isEdit ? "Module name *" : "Add module *",
641
- value: module?.name,
642
- onSubmit: (name) => void handleSubmit(name),
643
- placeholder: "Add module",
644
- unique: moduleNames,
645
- shouldReset: !isEdit,
646
- required: true
647
- }, module?.id ?? "new");
648
- }
649
- //#endregion
650
- //#region editors/document-model-editor/components/operation-form.tsx
651
- function OperationForm({ operation, module, focusOnMount, allOperationNames, onAddOperationAndInitialSchema, updateOperationName, deleteOperation }) {
652
- const isEdit = !!operation;
653
- const handleSubmit = async (name) => {
654
- if (isEdit && name === "") {
655
- deleteOperation(operation.id);
656
- return;
657
- }
658
- const formattedName = toConstantCase(name);
659
- if (isEdit) {
660
- if (formattedName !== operation.name) updateOperationName(operation.id, formattedName);
661
- } else await onAddOperationAndInitialSchema(module.id, formattedName);
662
- };
663
- const handleChange = (value) => {
664
- if (isEdit && value === "") deleteOperation(operation.id);
665
- };
666
- return /* @__PURE__ */ jsx(TextField, {
667
- name: "name",
668
- value: operation?.name,
669
- label: isEdit ? "Operation name *" : "Add operation *",
670
- onSubmit: (name) => void handleSubmit(name),
671
- onChange: handleChange,
672
- placeholder: "Add operation",
673
- required: !isEdit,
674
- allowEmpty: !isEdit,
675
- shouldReset: !isEdit,
676
- focusOnMount,
677
- unique: allOperationNames
678
- });
679
- }
680
- //#endregion
681
- //#region editors/document-model-editor/components/operation-description-form.tsx
682
- function OperationDescriptionForm({ operation, focusOnMount, setOperationDescription }) {
683
- const textFieldRef = useRef(null);
684
- useEffect(() => {
685
- if (focusOnMount && textFieldRef.current) textFieldRef.current.focus();
686
- }, [focusOnMount]);
687
- return /* @__PURE__ */ jsx(TextField, {
688
- ref: textFieldRef,
689
- name: "description",
690
- value: operation.description,
691
- onSubmit: (newDescription) => setOperationDescription(operation.id, newDescription),
692
- label: "Operation description",
693
- allowEmpty: true,
694
- placeholder: "Operation Description"
695
- });
696
- }
697
- //#endregion
698
- //#region editors/document-model-editor/components/operation-error-form.tsx
699
- function OperationErrorForm({ operation, error, focusOnMount, onSubmit, onAddOperationError, deleteOperationError, setOperationErrorName }) {
700
- const textFieldRef = useRef(null);
701
- const isEdit = !!error;
702
- const allOperationErrorNames = operation.errors.map((o) => o.name).filter((n) => n !== null);
703
- const handleSubmit = (name) => {
704
- if (isEdit && name === "") {
705
- deleteOperationError(error.id);
706
- return;
707
- }
708
- const formattedName = pascalCase(name);
709
- if (isEdit) setOperationErrorName(operation.id, error.id, formattedName);
710
- else onAddOperationError(operation.id, formattedName);
711
- onSubmit?.();
712
- };
713
- const handleChange = (value) => {
714
- if (isEdit && value === "") deleteOperationError(error.id);
715
- };
716
- return /* @__PURE__ */ jsx(TextField, {
717
- ref: textFieldRef,
718
- name: "name",
719
- value: error?.name,
720
- onSubmit: handleSubmit,
721
- onChange: handleChange,
722
- placeholder: "Add exception",
723
- required: !isEdit,
724
- allowEmpty: !isEdit,
725
- shouldReset: !isEdit,
726
- unique: allOperationErrorNames,
727
- focusOnMount
728
- });
729
- }
730
- //#endregion
731
- //#region editors/document-model-editor/components/operation-errors.tsx
732
- function OperationErrors({ operation, addOperationError, deleteOperationError, setOperationErrorName }) {
733
- const addErrorFormId = useId();
734
- const [shouldFocusAddForm, setShouldFocusAddForm] = useState(false);
735
- const onAddOperationError = useCallback(async (operationId, error) => {
736
- const errorId = await addOperationError(operationId, error);
737
- if (errorId) setShouldFocusAddForm(true);
738
- return errorId;
739
- }, [addOperationError, setShouldFocusAddForm]);
740
- const onAddOperationErrorSubmit = useCallback(() => setShouldFocusAddForm(false), [setShouldFocusAddForm]);
741
- return /* @__PURE__ */ jsxs("ul", {
742
- className: "ml-4 list-disc",
743
- children: [operation.errors.map((error) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(OperationErrorForm, {
744
- error,
745
- operation,
746
- onAddOperationError,
747
- deleteOperationError,
748
- setOperationErrorName
749
- }) }, error.id)), /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(OperationErrorForm, {
750
- operation,
751
- onAddOperationError,
752
- deleteOperationError,
753
- setOperationErrorName,
754
- focusOnMount: shouldFocusAddForm,
755
- onSubmit: onAddOperationErrorSubmit
756
- }, `${addErrorFormId}-${shouldFocusAddForm}`) })]
757
- });
758
- }
759
- //#endregion
760
- //#region editors/document-model-editor/components/operation.tsx
761
- const GraphqlEditor = lazy(() => import("./graphql-editor-BcL3-Zha.js"));
762
- function Operation(props) {
763
- const { operation, module, allOperationNames, lastCreatedOperationId, onAddOperationAndInitialSchema, updateOperationName, deleteOperation, updateOperationSchema, setOperationDescription, addOperationError, deleteOperationError, setOperationErrorName, toggleNoInputRequired } = props;
764
- const noInputRequired = isEmptyOperationSchema(operation.schema);
765
- const handleToggleNoInput = useCallback((checked) => toggleNoInputRequired(operation.id, checked), [operation.id, toggleNoInputRequired]);
766
- const handleUpdateDocument = useCallback((newDoc) => updateOperationSchema(operation.id, newDoc), [operation.id, updateOperationSchema]);
767
- const customLinter = useCallback((doc) => operation.name ? ensureValidOperationSchemaInputName(doc, operation.name) : [], [operation.name]);
768
- return /* @__PURE__ */ jsxs("div", {
769
- className: "mt-4 grid grid-cols-2 gap-x-12",
770
- style: {
771
- gridTemplateAreas: `
772
- "left editor"
773
- "errors editor"
774
- `,
775
- gridTemplateRows: "auto 1fr"
776
- },
777
- children: [
778
- /* @__PURE__ */ jsxs("div", {
779
- className: "flex flex-col gap-2",
780
- style: { gridArea: "left" },
781
- children: [/* @__PURE__ */ jsx(OperationForm, {
782
- operation,
783
- onAddOperationAndInitialSchema,
784
- updateOperationName,
785
- deleteOperation,
786
- module,
787
- allOperationNames
788
- }), /* @__PURE__ */ jsx(OperationDescriptionForm, {
789
- operation,
790
- focusOnMount: operation.id === lastCreatedOperationId,
791
- setOperationDescription
792
- })]
793
- }),
794
- /* @__PURE__ */ jsxs("div", {
795
- className: "relative top-8",
796
- style: { gridArea: "editor" },
797
- children: [/* @__PURE__ */ jsxs("label", {
798
- className: "mb-2 flex cursor-pointer items-center gap-2",
799
- children: [/* @__PURE__ */ jsx("input", {
800
- type: "checkbox",
801
- checked: noInputRequired,
802
- onChange: (e) => handleToggleNoInput(e.target.checked),
803
- className: "size-4 rounded-sm border-border"
804
- }), /* @__PURE__ */ jsx("span", {
805
- className: "text-sm text-foreground",
806
- children: "Operation with no inputs"
807
- })]
808
- }), !noInputRequired && /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(GraphqlEditor, {
809
- doc: operation.schema ?? "",
810
- updateDocumentInModel: handleUpdateDocument,
811
- customLinter
812
- }) })]
813
- }),
814
- /* @__PURE__ */ jsxs("div", {
815
- style: { gridArea: "errors" },
816
- children: [/* @__PURE__ */ jsx("h3", {
817
- className: "my-2 text-sm font-medium text-foreground",
818
- children: "Reducer Exceptions"
819
- }), /* @__PURE__ */ jsx(OperationErrors, {
820
- operation,
821
- addOperationError,
822
- deleteOperationError,
823
- setOperationErrorName
824
- })]
825
- })
826
- ]
827
- });
828
- }
829
- //#endregion
830
- //#region editors/document-model-editor/components/operations.tsx
831
- function Operations({ module, allOperations, shouldFocusNewOperation, updateOperationName, deleteOperation, addOperationAndInitialSchema, addOperationError, deleteOperationError, setOperationErrorName, updateOperationSchema, setOperationDescription, toggleNoInputRequired }) {
832
- const [lastCreatedOperationId, setLastCreatedOperationId] = useState(null);
833
- const addOperationFormId = useId();
834
- const allOperationNames = allOperations.map((o) => o.name).filter((n) => n !== null);
835
- const onAddOperationAndInitialSchema = useCallback(async (moduleId, name) => {
836
- const operationId = await addOperationAndInitialSchema(moduleId, name);
837
- if (operationId) setLastCreatedOperationId(operationId);
838
- return operationId;
839
- }, [addOperationAndInitialSchema, setLastCreatedOperationId]);
840
- return /* @__PURE__ */ jsxs("div", { children: [module.operations.map((operation) => /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Operation, {
841
- operation,
842
- module,
843
- lastCreatedOperationId,
844
- allOperationNames,
845
- addOperationError,
846
- deleteOperationError,
847
- setOperationErrorName,
848
- onAddOperationAndInitialSchema,
849
- updateOperationName,
850
- deleteOperation,
851
- updateOperationSchema,
852
- setOperationDescription,
853
- toggleNoInputRequired
854
- }) }, operation.id)), /* @__PURE__ */ jsx("div", {
855
- className: "mt-6 w-1/2 pr-6",
856
- children: /* @__PURE__ */ jsx(OperationForm, {
857
- onAddOperationAndInitialSchema,
858
- updateOperationName,
859
- deleteOperation,
860
- module,
861
- allOperationNames,
862
- focusOnMount: shouldFocusNewOperation
863
- }, addOperationFormId)
864
- })] });
865
- }
866
- //#endregion
867
- //#region editors/document-model-editor/components/module.tsx
868
- function Module(props) {
869
- const { module, modules, allOperations, lastCreatedModuleId, onAddModule, updateModuleName, deleteModule, updateOperationName, deleteOperation, addOperationAndInitialSchema, updateOperationSchema, setOperationDescription, addOperationError, deleteOperationError, setOperationErrorName, toggleNoInputRequired } = props;
870
- return /* @__PURE__ */ jsxs("div", {
871
- className: "relative rounded-3xl bg-muted p-6",
872
- children: [/* @__PURE__ */ jsxs("div", {
873
- className: "mb-2 w-1/2 pr-6",
874
- children: [/* @__PURE__ */ jsx(ModuleForm, {
875
- modules,
876
- module,
877
- onAddModule,
878
- updateModuleName
879
- }), !!module && /* @__PURE__ */ jsx("button", {
880
- "aria-label": "Delete module",
881
- tabIndex: -1,
882
- className: "absolute top-1 right-1 p-2 text-foreground transition-colors hover:hover-effect",
883
- onClick: () => {
884
- deleteModule(module.id);
885
- },
886
- children: /* @__PURE__ */ jsx("svg", {
887
- className: "size-6",
888
- viewBox: "0 0 24 24",
889
- fill: "currentcolor",
890
- children: /* @__PURE__ */ jsx("path", {
891
- fillRule: "evenodd",
892
- clipRule: "evenodd",
893
- 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"
894
- })
895
- })
896
- })]
897
- }), !!module && /* @__PURE__ */ jsx(Operations, {
898
- module,
899
- allOperations,
900
- shouldFocusNewOperation: module.id === lastCreatedModuleId,
901
- updateOperationName,
902
- deleteOperation,
903
- addOperationAndInitialSchema,
904
- updateOperationSchema,
905
- setOperationDescription,
906
- addOperationError,
907
- deleteOperationError,
908
- setOperationErrorName,
909
- toggleNoInputRequired
910
- })]
911
- });
912
- }
913
- //#endregion
914
- //#region editors/document-model-editor/components/modules.tsx
915
- function Modules({ modules, allOperations, addModule, updateModuleName, deleteModule, updateOperationName, deleteOperation, addOperationAndInitialSchema, updateOperationSchema, setOperationDescription, addOperationError, deleteOperationError, setOperationErrorName, toggleNoInputRequired }) {
916
- const [lastCreatedModuleId, setLastCreatedModuleId] = useState(null);
917
- const focusTrapRef = useRef(null);
918
- const onAddModule = useCallback(async (name) => {
919
- const moduleId = await addModule(name);
920
- if (moduleId) {
921
- setLastCreatedModuleId(moduleId);
922
- focusTrapRef.current?.focus();
923
- }
924
- return moduleId;
925
- }, [addModule, setLastCreatedModuleId]);
926
- return /* @__PURE__ */ jsxs("div", {
927
- className: "flex flex-col gap-2",
928
- children: [
929
- modules.map((module) => /* @__PURE__ */ jsx(Module, {
930
- module,
931
- modules,
932
- allOperations,
933
- lastCreatedModuleId,
934
- onAddModule,
935
- updateModuleName,
936
- deleteModule,
937
- updateOperationName,
938
- deleteOperation,
939
- addOperationAndInitialSchema,
940
- updateOperationSchema,
941
- setOperationDescription,
942
- addOperationError,
943
- deleteOperationError,
944
- setOperationErrorName,
945
- toggleNoInputRequired
946
- }, module.id)),
947
- /* @__PURE__ */ jsx(Module, {
948
- modules,
949
- allOperations,
950
- lastCreatedModuleId,
951
- onAddModule,
952
- updateModuleName,
953
- deleteModule,
954
- updateOperationName,
955
- deleteOperation,
956
- addOperationAndInitialSchema,
957
- updateOperationSchema,
958
- setOperationDescription,
959
- addOperationError,
960
- deleteOperationError,
961
- setOperationErrorName,
962
- toggleNoInputRequired
963
- }, "add-module"),
964
- /* @__PURE__ */ jsx("div", {
965
- ref: focusTrapRef,
966
- tabIndex: 0,
967
- className: "size-0 overflow-hidden",
968
- "aria-hidden": "true"
969
- })
970
- ]
971
- });
972
- }
973
- //#endregion
974
- //#region editors/document-model-editor/components/version-controls.tsx
975
- const compactButtonStyle$1 = "min-h-0 min-w-0 flex-none rounded-lg px-6 py-1.5 text-sm whitespace-nowrap";
976
- function VersionControls(props) {
977
- const { specifications, viewedVersion, onViewVersion, onReleaseNewVersion } = props;
978
- const [showReleaseModal, setShowReleaseModal] = useState(false);
979
- const latestVersion = specifications[specifications.length - 1].version;
980
- const nextVersion = latestVersion + 1;
981
- return /* @__PURE__ */ jsxs("div", {
982
- className: "mb-4 flex items-center justify-between gap-4",
983
- children: [
984
- /* @__PURE__ */ jsxs("div", {
985
- className: "flex items-center gap-2",
986
- children: [/* @__PURE__ */ jsxs("span", {
987
- className: "rounded-md bg-muted px-2 py-0.5 font-mono text-xs text-foreground",
988
- "data-testid": "model-version-badge",
989
- children: ["Version ", viewedVersion]
990
- }), specifications.length >= 2 && /* @__PURE__ */ jsx("div", {
991
- "aria-label": "Document model version",
992
- "data-testid": "model-version-switcher",
993
- children: /* @__PURE__ */ jsx(ConnectSelect, {
994
- absolutePositionMenu: true,
995
- containerClassName: "z-10 [&_svg]:size-4",
996
- id: "model-version-switcher",
997
- itemClassName: "gap-1 px-2 py-1 font-mono text-xs leading-none [&_p:empty]:hidden",
998
- items: specifications.map((spec) => ({
999
- value: String(spec.version),
1000
- displayValue: /* @__PURE__ */ jsx("span", {
1001
- className: "normal-case",
1002
- children: spec.version === latestVersion ? `v${spec.version} (latest)` : `v${spec.version} (frozen)`
1003
- })
1004
- })),
1005
- listClassName: "border border-t-0 border-border shadow-md",
1006
- menuClassName: "min-w-0 pr-1.5",
1007
- onChange: (value) => {
1008
- const version = Number(value);
1009
- onViewVersion(version === latestVersion ? "latest" : version);
1010
- },
1011
- value: String(viewedVersion)
1012
- })
1013
- })]
1014
- }),
1015
- /* @__PURE__ */ jsx(Button, {
1016
- className: "inline-flex h-8 items-center justify-center py-0",
1017
- "data-testid": "release-new-version-button",
1018
- onClick: () => setShowReleaseModal(true),
1019
- type: "button",
1020
- children: "Release new version"
1021
- }),
1022
- /* @__PURE__ */ jsx(Modal, {
1023
- open: showReleaseModal,
1024
- onOpenChange: (status) => {
1025
- if (!status) setShowReleaseModal(false);
1026
- },
1027
- children: /* @__PURE__ */ jsxs("div", {
1028
- className: "w-[440px] p-6",
1029
- children: [
1030
- /* @__PURE__ */ jsxs("div", {
1031
- className: "pb-2 text-2xl font-bold text-foreground",
1032
- children: ["Release version ", nextVersion]
1033
- }),
1034
- /* @__PURE__ */ jsxs("div", {
1035
- className: "my-4 rounded-md bg-background p-4 text-left text-sm text-foreground",
1036
- children: [/* @__PURE__ */ jsxs("p", { children: [
1037
- "Version ",
1038
- latestVersion,
1039
- " will be frozen as-is. Version",
1040
- " ",
1041
- nextVersion,
1042
- " starts as an identical copy, and all further edits apply to version ",
1043
- nextVersion,
1044
- "."
1045
- ] }), /* @__PURE__ */ jsxs("p", {
1046
- className: "mt-3",
1047
- children: [
1048
- "Existing version ",
1049
- latestVersion,
1050
- " documents will be upgradeable once you define the migration."
1051
- ]
1052
- })]
1053
- }),
1054
- /* @__PURE__ */ jsxs("div", {
1055
- className: "mt-4 flex justify-between gap-3",
1056
- children: [/* @__PURE__ */ jsx(ModalButton, {
1057
- className: compactButtonStyle$1,
1058
- onClick: () => setShowReleaseModal(false),
1059
- variant: "cancel",
1060
- children: "Cancel"
1061
- }), /* @__PURE__ */ jsxs(ModalButton, {
1062
- className: compactButtonStyle$1,
1063
- "data-testid": "confirm-release-button",
1064
- onClick: () => {
1065
- setShowReleaseModal(false);
1066
- onReleaseNewVersion();
1067
- },
1068
- variant: "confirm",
1069
- children: ["Release version ", nextVersion]
1070
- })]
1071
- })
1072
- ]
1073
- })
1074
- })
1075
- ]
1076
- });
1077
- }
1078
- function FrozenVersionBanner(props) {
1079
- const { viewedVersion, latestVersion } = props;
1080
- return /* @__PURE__ */ jsxs("div", {
1081
- className: "mb-4 rounded-md border border-border bg-muted p-3 text-sm text-foreground",
1082
- "data-testid": "frozen-version-banner",
1083
- children: [
1084
- "Version ",
1085
- viewedVersion,
1086
- " is frozen. You're viewing it read-only. Edits go to version ",
1087
- latestVersion,
1088
- "."
1089
- ]
1090
- });
1091
- }
1092
- //#endregion
1093
- //#region editors/document-model-editor/components/version-advisory-modal.tsx
1094
- const compactButtonStyle = "min-h-0 min-w-0 flex-none rounded-lg px-4 py-1.5 text-sm whitespace-nowrap";
1095
- function FieldDiffList(props) {
1096
- const { label, fields } = props;
1097
- if (fields.length === 0) return null;
1098
- return /* @__PURE__ */ jsxs("div", {
1099
- className: "mt-3",
1100
- children: [/* @__PURE__ */ jsx("p", {
1101
- className: "mb-1.5",
1102
- children: label
1103
- }), /* @__PURE__ */ jsx("div", {
1104
- className: "flex flex-col items-start gap-1",
1105
- children: fields.map((field) => /* @__PURE__ */ jsx("span", {
1106
- className: "rounded-md bg-muted px-2 py-0.5 font-mono text-xs text-foreground",
1107
- children: field
1108
- }, field))
1109
- })]
1110
- });
1111
- }
1112
- function VersionAdvisoryModal(props) {
1113
- const { prompt, onReleaseFirst, onKeepEditing, onCancel } = props;
1114
- if (!prompt) return null;
1115
- const { version, reason, diff } = prompt;
1116
- const nextVersion = version + 1;
1117
- return /* @__PURE__ */ jsx(Modal, {
1118
- open: true,
1119
- onOpenChange: (status) => {
1120
- if (!status) onCancel();
1121
- },
1122
- children: /* @__PURE__ */ jsxs("div", {
1123
- className: "w-[440px] p-6",
1124
- "data-testid": "version-advisory-modal",
1125
- children: [
1126
- /* @__PURE__ */ jsxs("div", {
1127
- className: "pb-2 text-2xl font-bold text-foreground",
1128
- children: [
1129
- "Is version ",
1130
- version,
1131
- " of this model already in use?"
1132
- ]
1133
- }),
1134
- /* @__PURE__ */ jsxs("div", {
1135
- className: "my-4 rounded-md bg-background p-4 text-left text-sm text-foreground",
1136
- children: [
1137
- /* @__PURE__ */ jsxs("p", { children: [
1138
- reason,
1139
- " Documents that were already created with version ",
1140
- version,
1141
- " ",
1142
- "may stop working correctly."
1143
- ] }),
1144
- diff && /* @__PURE__ */ jsxs(Fragment$1, { children: [
1145
- /* @__PURE__ */ jsx(FieldDiffList, {
1146
- fields: diff.addedFields,
1147
- label: "New fields:"
1148
- }),
1149
- /* @__PURE__ */ jsx(FieldDiffList, {
1150
- fields: diff.removedFields,
1151
- label: "Removed fields:"
1152
- }),
1153
- /* @__PURE__ */ jsx(FieldDiffList, {
1154
- fields: diff.changedFields,
1155
- label: "Changed fields:"
1156
- })
1157
- ] }),
1158
- /* @__PURE__ */ jsxs("p", {
1159
- className: "mt-3",
1160
- children: [
1161
- "If others are already using version ",
1162
- version,
1163
- ", release version",
1164
- " ",
1165
- nextVersion,
1166
- " first. Your change will go into version ",
1167
- nextVersion,
1168
- ", and existing documents can be updated safely."
1169
- ]
1170
- })
1171
- ]
1172
- }),
1173
- /* @__PURE__ */ jsxs("div", {
1174
- className: "mt-4 flex flex-col gap-2",
1175
- children: [/* @__PURE__ */ jsx(ModalButton, {
1176
- className: compactButtonStyle,
1177
- "data-testid": "advisory-release-first",
1178
- onClick: onReleaseFirst,
1179
- variant: "confirm",
1180
- children: `It's in use — release v${nextVersion} first`
1181
- }), /* @__PURE__ */ jsxs(ModalButton, {
1182
- className: compactButtonStyle,
1183
- "data-testid": "advisory-keep-editing",
1184
- onClick: onKeepEditing,
1185
- variant: "cancel",
1186
- children: ["Still in development — keep editing v", version]
1187
- })]
1188
- })
1189
- ]
1190
- })
1191
- });
1192
- }
1193
- //#endregion
1194
- //#region editors/document-model-editor/config.ts
1195
- const editorConfig = { isExternalControlsEnabled: false };
1196
- //#endregion
1197
- //#region editors/document-model-editor/hooks/useDocumentModelDocument.ts
1198
- function useSelectedDocumentModelDocument() {
1199
- return useSelectedDocumentOfType("powerhouse/document-model");
1200
- }
1201
- //#endregion
1202
- //#region editors/document-model-editor/utils/change-classification.ts
1203
- function isShapeTypeNode(node) {
1204
- return node.kind === Kind.OBJECT_TYPE_DEFINITION || node.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION || node.kind === Kind.ENUM_TYPE_DEFINITION;
1205
- }
1206
- function collectTypeFields(doc) {
1207
- const types = /* @__PURE__ */ new Map();
1208
- for (const definition of doc.definitions) {
1209
- if (!isShapeTypeNode(definition)) continue;
1210
- const fields = /* @__PURE__ */ new Map();
1211
- if (definition.kind === Kind.ENUM_TYPE_DEFINITION) for (const value of definition.values ?? []) fields.set(value.name.value, "value");
1212
- else for (const field of definition.fields ?? []) fields.set(field.name.value, print(field.type));
1213
- types.set(definition.name.value, fields);
1214
- }
1215
- return types;
1216
- }
1217
- function escapeRegExp(value) {
1218
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1219
- }
1220
- function replaceTypeName(printedType, oldName, newName) {
1221
- return printedType.replace(new RegExp(`\\b${escapeRegExp(oldName)}\\b`, "g"), newName);
1222
- }
1223
- function typeSignature(name, fields) {
1224
- return [...fields.entries()].map(([field, type]) => `${field}:${replaceTypeName(type, name, "__SELF__")}`).sort().join("|");
1225
- }
1226
- function detectTypeRenames(oldTypes, newTypes) {
1227
- const renames = /* @__PURE__ */ new Map();
1228
- const removed = [...oldTypes.keys()].filter((name) => !newTypes.has(name));
1229
- const added = new Set([...newTypes.keys()].filter((name) => !oldTypes.has(name)));
1230
- for (const oldName of removed) {
1231
- const oldSignature = typeSignature(oldName, oldTypes.get(oldName));
1232
- for (const newName of added) if (typeSignature(newName, newTypes.get(newName)) === oldSignature) {
1233
- renames.set(oldName, newName);
1234
- added.delete(newName);
1235
- break;
1236
- }
1237
- }
1238
- return renames;
1239
- }
1240
- function flattenFields(types, renames) {
1241
- const fields = /* @__PURE__ */ new Map();
1242
- for (const [typeName, typeFields] of types) {
1243
- const resolvedTypeName = renames.get(typeName) ?? typeName;
1244
- for (const [fieldName, printedType] of typeFields) {
1245
- let resolvedType = printedType;
1246
- for (const [oldName, newName] of renames) resolvedType = replaceTypeName(resolvedType, oldName, newName);
1247
- fields.set(`${resolvedTypeName}.${fieldName}`, resolvedType);
1248
- }
1249
- }
1250
- return fields;
1251
- }
1252
- function hasShapeChange(diff) {
1253
- return diff.addedFields.length > 0 || diff.removedFields.length > 0 || diff.changedFields.length > 0;
1254
- }
1255
- function diffSdlShapes(oldSdl, newSdl) {
1256
- const empty = {
1257
- addedFields: [],
1258
- removedFields: [],
1259
- changedFields: []
1260
- };
1261
- let oldDoc;
1262
- let newDoc;
1263
- try {
1264
- oldDoc = parse$1(oldSdl);
1265
- newDoc = parse$1(newSdl);
1266
- } catch {
1267
- return empty;
1268
- }
1269
- const oldTypes = collectTypeFields(oldDoc);
1270
- const newTypes = collectTypeFields(newDoc);
1271
- const oldFields = flattenFields(oldTypes, detectTypeRenames(oldTypes, newTypes));
1272
- const newFields = flattenFields(newTypes, /* @__PURE__ */ new Map());
1273
- const diff = {
1274
- addedFields: [],
1275
- removedFields: [],
1276
- changedFields: []
1277
- };
1278
- for (const [key, newType] of newFields) {
1279
- const oldType = oldFields.get(key);
1280
- if (oldType === void 0) diff.addedFields.push(key);
1281
- else if (oldType !== newType) diff.changedFields.push(`${key}: ${oldType} → ${newType}`);
1282
- }
1283
- for (const key of oldFields.keys()) if (!newFields.has(key)) diff.removedFields.push(key);
1284
- return diff;
1285
- }
1286
- const SAFE = { kind: "safe" };
1287
- function isBlank(value) {
1288
- return !value || !value.trim() || value.trim() === "{}";
1289
- }
1290
- /**
1291
- * True for a blank SDL, or an SDL whose types contain nothing but the
1292
- * `_placeholder` field the editor seeds new state/operation schemas with
1293
- * (see `makeInitialSchemaDoc` / `makeOperationInitialDoc` in ./helpers.ts).
1294
- * Replacing a placeholder-only schema with real fields is a user's first
1295
- * edit on a brand-new model, not a version-relevant change.
1296
- */
1297
- function isPlaceholderOnlySchema(sdl) {
1298
- if (isBlank(sdl)) return true;
1299
- let doc;
1300
- try {
1301
- doc = parse$1(sdl);
1302
- } catch {
1303
- return false;
1304
- }
1305
- return [...collectTypeFields(doc).values()].every((fields) => fields.size === 0 || fields.size === 1 && fields.has("_placeholder"));
1306
- }
1307
- function findOperation(spec, operationId) {
1308
- for (const module of spec.modules) {
1309
- const operation = module.operations.find((op) => op.id === operationId);
1310
- if (operation) return operation;
1311
- }
1312
- }
1313
- function addedSinceLastRelease(operationId, previousSpec) {
1314
- return previousSpec !== void 0 && !findOperation(previousSpec, operationId);
1315
- }
1316
- function classifySetStateSchema(input, latestSpec) {
1317
- const currentSchema = input.scope === "local" ? latestSpec.state.local.schema : latestSpec.state.global.schema;
1318
- if (isPlaceholderOnlySchema(currentSchema)) return SAFE;
1319
- const diff = diffSdlShapes(currentSchema, input.schema);
1320
- if (!hasShapeChange(diff)) return SAFE;
1321
- return {
1322
- kind: "version-relevant",
1323
- reason: input.scope === "local" ? `You're changing the local fields that version ${latestSpec.version} documents store.` : `You're changing the fields that version ${latestSpec.version} documents store.`,
1324
- diff
1325
- };
1326
- }
1327
- /**
1328
- * The editor pre-fills a fresh model's initial value from the placeholder
1329
- * schema, so a value that is blank or carries only the `_placeholder` key is
1330
- * still being initialized rather than changed.
1331
- */
1332
- function isPlaceholderOnlyInitialValue(value) {
1333
- if (isBlank(value)) return true;
1334
- let parsed;
1335
- try {
1336
- parsed = JSON.parse(value);
1337
- } catch {
1338
- return false;
1339
- }
1340
- if (typeof parsed !== "object" || parsed === null) return false;
1341
- return Object.keys(parsed).every((key) => key === "_placeholder");
1342
- }
1343
- function classifySetInitialState(input, latestSpec) {
1344
- const currentValue = input.scope === "local" ? latestSpec.state.local.initialValue : latestSpec.state.global.initialValue;
1345
- if (isPlaceholderOnlyInitialValue(currentValue)) return SAFE;
1346
- if (compareStringsWithoutWhitespace(currentValue, input.initialValue)) return SAFE;
1347
- return {
1348
- kind: "version-relevant",
1349
- reason: `You're changing the starting content that version ${latestSpec.version} documents are built on.`
1350
- };
1351
- }
1352
- function classifyOperationChange(action, operationId, latestSpec, previousSpec) {
1353
- if (addedSinceLastRelease(operationId, previousSpec)) return SAFE;
1354
- const operation = findOperation(latestSpec, operationId);
1355
- if (!operation) return SAFE;
1356
- const operationLabel = operation.name || "an operation";
1357
- switch (action.type) {
1358
- case "DELETE_OPERATION": return {
1359
- kind: "version-relevant",
1360
- reason: `You're removing the "${operationLabel}" operation from version ${latestSpec.version}.`
1361
- };
1362
- case "SET_OPERATION_NAME":
1363
- if (isBlank(operation.name)) return SAFE;
1364
- return {
1365
- kind: "version-relevant",
1366
- reason: `You're renaming the "${operationLabel}" operation in version ${latestSpec.version}.`
1367
- };
1368
- case "SET_OPERATION_SCHEMA": {
1369
- if (isPlaceholderOnlySchema(operation.schema ?? "")) return SAFE;
1370
- if (isBlank(action.input.schema)) return {
1371
- kind: "version-relevant",
1372
- reason: `You're changing the information that the "${operationLabel}" operation accepts in version ${latestSpec.version}.`
1373
- };
1374
- const diff = diffSdlShapes(operation.schema ?? "", action.input.schema ?? "");
1375
- if (!hasShapeChange(diff)) return SAFE;
1376
- return {
1377
- kind: "version-relevant",
1378
- reason: `You're changing the information that the "${operationLabel}" operation accepts in version ${latestSpec.version}.`,
1379
- diff
1380
- };
1381
- }
1382
- default: return SAFE;
1383
- }
1384
- }
1385
- function classifyDeleteModule(moduleId, latestSpec, previousSpec) {
1386
- const module = latestSpec.modules.find((candidate) => candidate.id === moduleId);
1387
- if (!module || module.operations.length === 0) return SAFE;
1388
- if (module.operations.every((operation) => addedSinceLastRelease(operation.id, previousSpec))) return SAFE;
1389
- return {
1390
- kind: "version-relevant",
1391
- reason: `You're removing the "${module.name}" module and all of its operations from version ${latestSpec.version}.`
1392
- };
1393
- }
1394
- /**
1395
- * Classifies a document-model action as version-relevant (would break
1396
- * documents created with the current version) or safe. `previousSpec` is the
1397
- * last released specification, used to exempt operations added since the
1398
- * release.
1399
- */
1400
- function classifyDocumentModelAction(action, latestSpec, previousSpec) {
1401
- switch (action.type) {
1402
- case "SET_STATE_SCHEMA": return classifySetStateSchema(action.input, latestSpec);
1403
- case "SET_INITIAL_STATE": return classifySetInitialState(action.input, latestSpec);
1404
- case "DELETE_OPERATION":
1405
- case "SET_OPERATION_NAME":
1406
- case "SET_OPERATION_SCHEMA": return classifyOperationChange(action, action.input.id, latestSpec, previousSpec);
1407
- case "DELETE_MODULE": return classifyDeleteModule(action.input.id, latestSpec, previousSpec);
1408
- default: return SAFE;
1409
- }
1410
- }
1411
- /**
1412
- * Pure decision core of the version advisory: given the actions about to be
1413
- * dispatched, decide whether to dispatch immediately or prompt the user.
1414
- */
1415
- function decideDispatch(actions, latestSpec, previousSpec, hasSessionChoice) {
1416
- if (hasSessionChoice) return { kind: "dispatch" };
1417
- for (const action of actions) {
1418
- const classification = classifyDocumentModelAction(action, latestSpec, previousSpec);
1419
- if (classification.kind === "version-relevant") return {
1420
- kind: "prompt",
1421
- reason: classification.reason,
1422
- diff: classification.diff
1423
- };
1424
- }
1425
- return { kind: "dispatch" };
1426
- }
1427
- //#endregion
1428
- //#region editors/document-model-editor/hooks/useVersionAdvisory.ts
1429
- /**
1430
- * Versions the user has confirmed as "still in development" (or that were
1431
- * just created via an explicit release) for this browser session. Keyed by
1432
- * `${documentId}:${version}`. Deliberately in-memory: a publisher returning
1433
- * in a later session is asked again, which is when the reminder matters.
1434
- */
1435
- const sessionVersionChoices = /* @__PURE__ */ new Set();
1436
- function useVersionAdvisory(args) {
1437
- const { documentId, latestSpec, previousSpec, dispatch, onReleaseError } = args;
1438
- const [prompt, setPrompt] = useState(void 0);
1439
- const pendingRef = useRef(void 0);
1440
- const choiceKey = `${documentId}:${latestSpec.version}`;
1441
- const guardedDispatch = (...dispatchArgs) => {
1442
- const [action] = dispatchArgs;
1443
- const decision = decideDispatch((Array.isArray(action) ? action : [action]).filter((candidate) => candidate !== void 0), latestSpec, previousSpec, sessionVersionChoices.has(choiceKey));
1444
- if (decision.kind === "dispatch") {
1445
- dispatch(...dispatchArgs);
1446
- return;
1447
- }
1448
- pendingRef.current = dispatchArgs;
1449
- setPrompt({
1450
- version: latestSpec.version,
1451
- reason: decision.reason,
1452
- diff: decision.diff
1453
- });
1454
- };
1455
- const flushPending = () => {
1456
- const pending = pendingRef.current;
1457
- pendingRef.current = void 0;
1458
- if (pending) dispatch(...pending);
1459
- };
1460
- const releaseFirst = () => {
1461
- setPrompt(void 0);
1462
- if (!pendingRef.current) return;
1463
- dispatch(releaseNewVersion(), (errors) => {
1464
- if (errors.length > 0) {
1465
- pendingRef.current = void 0;
1466
- onReleaseError?.(errors[0].message);
1467
- }
1468
- }, () => {
1469
- if (!pendingRef.current) return;
1470
- sessionVersionChoices.add(`${documentId}:${latestSpec.version + 1}`);
1471
- flushPending();
1472
- });
1473
- };
1474
- const keepEditing = () => {
1475
- sessionVersionChoices.add(choiceKey);
1476
- setPrompt(void 0);
1477
- flushPending();
1478
- };
1479
- const cancelAdvisory = () => {
1480
- pendingRef.current = void 0;
1481
- setPrompt(void 0);
1482
- };
1483
- const markVersionInDevelopment = (version) => {
1484
- sessionVersionChoices.add(`${documentId}:${version}`);
1485
- };
1486
- return {
1487
- guardedDispatch,
1488
- prompt,
1489
- releaseFirst,
1490
- keepEditing,
1491
- cancelAdvisory,
1492
- markVersionInDevelopment
1493
- };
1494
- }
1495
- //#endregion
1496
- //#region editors/document-model-editor/editor.tsx
1497
- const StateSchemas = lazy(() => import("./state-schemas-C4F8lReN.js"));
1498
- const noopSetStateSchema = () => void 0;
1499
- const noopSetInitialState = () => void 0;
1500
- function Editor() {
1501
- useSetPHDocumentEditorConfig(editorConfig);
1502
- const toast = usePHToast();
1503
- const [document, dispatch] = useSelectedDocumentModelDocument();
1504
- const [scope, setScope] = useState("global");
1505
- const documentNodeName = document.header.name;
1506
- const { name: modelName, id: documentType, extension, description, author: { name: authorName, website: authorWebsite } } = document.state.global;
1507
- const specifications = document.state.global.specifications;
1508
- const latestSpec = specifications[specifications.length - 1];
1509
- const previousSpec = specifications.length >= 2 ? specifications[specifications.length - 2] : void 0;
1510
- const [viewedVersion, setViewedVersion] = useState("latest");
1511
- const viewedSpec = viewedVersion === "latest" ? latestSpec : specifications.find((spec) => spec.version === viewedVersion) ?? latestSpec;
1512
- const isViewingFrozenVersion = viewedSpec.version !== latestSpec.version;
1513
- const { state: { global: { schema: globalStateSchema, initialValue: globalStateInitialValue }, local: { schema: localStateSchema, initialValue: localStateInitialValue } }, modules } = viewedSpec;
1514
- const operations = modules.flatMap((module) => module.operations);
1515
- const { state: { global: { schema: latestGlobalStateSchema, initialValue: latestGlobalStateInitialValue }, local: { schema: latestLocalStateSchema, initialValue: latestLocalStateInitialValue } }, modules: latestModules } = latestSpec;
1516
- const latestOperations = latestModules.flatMap((module) => module.operations);
1517
- const shouldSetInitialName = useRef(!modelName && !!documentNodeName && latestOperations.length === 0);
1518
- useEffect(() => {
1519
- if (!shouldSetInitialName.current || !documentNodeName) return;
1520
- const initialSchemaDoc = initializeModelSchema(documentNodeName);
1521
- dispatch([setModelName({ name: documentNodeName }), setStateSchema({
1522
- schema: initialSchemaDoc,
1523
- scope: "global"
1524
- })]);
1525
- shouldSetInitialName.current = false;
1526
- }, [documentNodeName, dispatch]);
1527
- const { guardedDispatch, prompt, releaseFirst, keepEditing, cancelAdvisory, markVersionInDevelopment } = useVersionAdvisory({
1528
- documentId: document.header.id,
1529
- latestSpec,
1530
- previousSpec,
1531
- dispatch,
1532
- onReleaseError: (message) => {
1533
- if (toast) toast(message, { type: "connect-warning" });
1534
- }
1535
- });
1536
- const handleReleaseNewVersion = () => {
1537
- const nextVersion = latestSpec.version + 1;
1538
- dispatch(releaseNewVersion(), (errors) => {
1539
- if (errors.length > 0 && toast) toast(errors[0].message, { type: "connect-warning" });
1540
- }, () => {
1541
- markVersionInDevelopment(nextVersion);
1542
- setViewedVersion("latest");
1543
- });
1544
- };
1545
- const operationSchemasSdl = operations.flatMap((operation) => operation.schema ?? []).join("\n");
1546
- const handleSetModelId = (id) => {
1547
- if (compareStringsWithoutWhitespace(id, documentType)) return;
1548
- guardedDispatch([setModelId({ id })]);
1549
- };
1550
- const handleSetModelDescription = (newDescription) => {
1551
- if (compareStringsWithoutWhitespace(newDescription, description)) return;
1552
- guardedDispatch(setModelDescription({ description: newDescription }));
1553
- };
1554
- const handleSetModelExtension = (newExtension) => {
1555
- if (compareStringsWithoutWhitespace(newExtension, extension)) return;
1556
- guardedDispatch(setModelExtension({ extension: newExtension }));
1557
- };
1558
- const handleSetModelName = (newName) => {
1559
- if (compareStringsWithoutWhitespace(newName, modelName)) return;
1560
- guardedDispatch(setModelName({ name: newName }));
1561
- };
1562
- const handleSetAuthorName = (newAuthorName) => {
1563
- if (compareStringsWithoutWhitespace(newAuthorName, authorName)) return;
1564
- guardedDispatch(setAuthorName({ authorName: newAuthorName }));
1565
- };
1566
- const handleSetAuthorWebsite = (newAuthorWebsite) => {
1567
- if (compareStringsWithoutWhitespace(newAuthorWebsite, authorWebsite ?? "")) return;
1568
- guardedDispatch(setAuthorWebsite({ authorWebsite: newAuthorWebsite }));
1569
- };
1570
- const handleSetStateSchema = (newSchema, scope) => {
1571
- if (compareStringsWithoutWhitespace(newSchema, scope === "global" ? latestGlobalStateSchema : latestLocalStateSchema)) return;
1572
- guardedDispatch(setStateSchema({
1573
- schema: newSchema,
1574
- scope
1575
- }));
1576
- };
1577
- const handleSetInitialState = (newInitialValue, scope) => {
1578
- if (compareStringsWithoutWhitespace(newInitialValue, scope === "global" ? latestGlobalStateInitialValue : latestLocalStateInitialValue)) return;
1579
- guardedDispatch(setInitialState({
1580
- initialValue: newInitialValue,
1581
- scope
1582
- }));
1583
- };
1584
- const handleAddModule = (name) => {
1585
- return new Promise((resolve) => {
1586
- try {
1587
- if (latestModules.some((module) => compareStringsWithoutWhitespace(module.name, name))) {
1588
- resolve(void 0);
1589
- return;
1590
- }
1591
- const id = generateId();
1592
- guardedDispatch(addModule({
1593
- id,
1594
- name
1595
- }));
1596
- resolve(id);
1597
- } catch (error) {
1598
- console.error("Failed to add module:", error);
1599
- resolve(void 0);
1600
- }
1601
- });
1602
- };
1603
- const handleSetModuleName = (id, name) => {
1604
- if (latestModules.some((module) => compareStringsWithoutWhitespace(module.name, name))) return;
1605
- guardedDispatch(setModuleName({
1606
- id,
1607
- name
1608
- }));
1609
- };
1610
- const handleDeleteModule = (id) => {
1611
- guardedDispatch(deleteModule({ id }));
1612
- };
1613
- const handleAddOperation = (moduleId, name) => {
1614
- return new Promise((resolve) => {
1615
- const id = generateId();
1616
- guardedDispatch(addOperation({
1617
- id,
1618
- moduleId,
1619
- name,
1620
- scope
1621
- }), (errors) => {
1622
- if (errors.length > 0) {
1623
- if (toast) toast(errors[0].message, { type: "connect-warning" });
1624
- resolve(void 0);
1625
- } else resolve(id);
1626
- }, () => resolve(id));
1627
- });
1628
- };
1629
- const handleSetOperationName = (id, name) => {
1630
- guardedDispatch(setOperationName({
1631
- id,
1632
- name
1633
- }), (errors) => {
1634
- if (errors.length > 0 && toast) toast(errors[0].message, { type: "connect-warning" });
1635
- });
1636
- };
1637
- const handleSetOperationSchema = (id, newSchema) => {
1638
- const operation = latestOperations.find((operation) => operation.id === id);
1639
- if (operation?.schema && compareStringsWithoutWhitespace(newSchema, operation.schema)) return;
1640
- guardedDispatch(setOperationSchema({
1641
- id,
1642
- schema: newSchema
1643
- }));
1644
- };
1645
- const handleToggleNoInputRequired = (id, noInputRequired) => {
1646
- const operation = latestOperations.find((op) => op.id === id);
1647
- if (!operation?.name) return;
1648
- if (noInputRequired) guardedDispatch(setOperationSchema({
1649
- id,
1650
- schema: makeEmptyOperationSchema(operation.name)
1651
- }));
1652
- else guardedDispatch(setOperationSchema({
1653
- id,
1654
- schema: makeOperationInitialDoc(operation.name)
1655
- }));
1656
- };
1657
- const handleSetOperationDescription = (id, newDescription) => {
1658
- if (compareStringsWithoutWhitespace(latestOperations.find((operation) => operation.id === id)?.description ?? "", newDescription)) return;
1659
- guardedDispatch(setOperationDescription({
1660
- id,
1661
- description: newDescription
1662
- }));
1663
- };
1664
- const handleDeleteOperation = (id) => {
1665
- guardedDispatch(deleteOperation({ id }));
1666
- };
1667
- const handleAddOperationError = (operationId, errorName) => {
1668
- return new Promise((resolve) => {
1669
- try {
1670
- if ((latestOperations.find((operation) => operation.id === operationId)?.errors.map((error) => error.name).filter(Boolean) ?? []).some((name) => compareStringsWithoutWhitespace(name, errorName))) {
1671
- resolve(void 0);
1672
- return;
1673
- }
1674
- const id = generateId();
1675
- guardedDispatch(addOperationError({
1676
- id,
1677
- operationId,
1678
- errorName,
1679
- errorCode: pascalCase(errorName)
1680
- }));
1681
- resolve(id);
1682
- } catch (error) {
1683
- console.error("Failed to add operation error:", error);
1684
- resolve(void 0);
1685
- }
1686
- });
1687
- };
1688
- const handleDeleteOperationError = (id) => {
1689
- guardedDispatch(deleteOperationError({ id }));
1690
- };
1691
- const handleSetOperationErrorName = (operationId, errorId, errorName) => {
1692
- if ((latestOperations.find((operation) => operation.id === operationId)?.errors.map((error) => error.name).filter(Boolean) ?? []).some((name) => compareStringsWithoutWhitespace(name, errorName))) return;
1693
- guardedDispatch(setOperationErrorName({
1694
- id: errorId,
1695
- errorName
1696
- }));
1697
- };
1698
- const addOperationAndInitialSchema = async (moduleId, name) => {
1699
- try {
1700
- const id = await handleAddOperation(moduleId, name);
1701
- if (!id) return void 0;
1702
- try {
1703
- handleSetOperationSchema(id, makeOperationInitialDoc(name));
1704
- return id;
1705
- } catch (error) {
1706
- console.error("Failed to update operation schema:", error);
1707
- return;
1708
- }
1709
- } catch (error) {
1710
- console.error("Failed to add operation and schema:", error);
1711
- return;
1712
- }
1713
- };
1714
- return /* @__PURE__ */ jsxs("main", {
1715
- className: "min-h-dvh bg-background p-6",
1716
- children: [
1717
- /* @__PURE__ */ jsx(DocumentToolbar, {}),
1718
- /* @__PURE__ */ jsx(SchemaContextProvider, {
1719
- globalStateSchemaSdl: globalStateSchema,
1720
- localStateSchemaSdl: localStateSchema,
1721
- operationSchemasSdl,
1722
- children: /* @__PURE__ */ jsxs("div", {
1723
- className: "mx-auto max-w-6xl px-4 pt-8",
1724
- children: [
1725
- /* @__PURE__ */ jsx(VersionControls, {
1726
- specifications,
1727
- viewedVersion: viewedSpec.version,
1728
- onViewVersion: setViewedVersion,
1729
- onReleaseNewVersion: handleReleaseNewVersion
1730
- }),
1731
- /* @__PURE__ */ jsx(ModelMetadata, {
1732
- name: modelName,
1733
- documentType,
1734
- extension,
1735
- description,
1736
- authorName,
1737
- authorWebsite: authorWebsite ?? "",
1738
- globalStateSchema: latestGlobalStateSchema,
1739
- localStateSchema: latestLocalStateSchema,
1740
- setModelId: handleSetModelId,
1741
- setModelDescription: handleSetModelDescription,
1742
- setModelExtension: handleSetModelExtension,
1743
- setModelName: handleSetModelName,
1744
- setAuthorName: handleSetAuthorName,
1745
- setAuthorWebsite: handleSetAuthorWebsite,
1746
- setStateSchema: handleSetStateSchema
1747
- }),
1748
- /* @__PURE__ */ jsx(Divider, {}),
1749
- isViewingFrozenVersion && /* @__PURE__ */ jsx(FrozenVersionBanner, {
1750
- latestVersion: latestSpec.version,
1751
- viewedVersion: viewedSpec.version
1752
- }),
1753
- /* @__PURE__ */ jsxs("div", {
1754
- className: isViewingFrozenVersion ? "pointer-events-none opacity-80 select-none" : void 0,
1755
- inert: isViewingFrozenVersion || void 0,
1756
- children: [
1757
- /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(StateSchemas, {
1758
- modelName,
1759
- globalStateSchema,
1760
- globalStateInitialValue,
1761
- localStateSchema,
1762
- localStateInitialValue,
1763
- setStateSchema: isViewingFrozenVersion ? noopSetStateSchema : handleSetStateSchema,
1764
- setInitialState: isViewingFrozenVersion ? noopSetInitialState : handleSetInitialState,
1765
- currentScope: scope,
1766
- onScopeChange: setScope
1767
- }) }),
1768
- /* @__PURE__ */ jsx(Divider, {}),
1769
- /* @__PURE__ */ jsxs("h3", {
1770
- className: "mb-6 text-lg text-foreground capitalize",
1771
- children: [scope, " Operations"]
1772
- }),
1773
- /* @__PURE__ */ jsx(Modules, {
1774
- modules: modules.map((module) => ({
1775
- ...module,
1776
- operations: module.operations.filter((op) => op.scope === scope)
1777
- })),
1778
- allOperations: operations,
1779
- addModule: handleAddModule,
1780
- updateModuleName: handleSetModuleName,
1781
- deleteModule: handleDeleteModule,
1782
- updateOperationName: handleSetOperationName,
1783
- updateOperationSchema: handleSetOperationSchema,
1784
- setOperationDescription: handleSetOperationDescription,
1785
- deleteOperation: handleDeleteOperation,
1786
- addOperationError: handleAddOperationError,
1787
- deleteOperationError: handleDeleteOperationError,
1788
- setOperationErrorName: handleSetOperationErrorName,
1789
- addOperationAndInitialSchema,
1790
- toggleNoInputRequired: handleToggleNoInputRequired
1791
- })
1792
- ]
1793
- })
1794
- ]
1795
- })
1796
- }),
1797
- /* @__PURE__ */ jsx(VersionAdvisoryModal, {
1798
- prompt,
1799
- onReleaseFirst: releaseFirst,
1800
- onKeepEditing: keepEditing,
1801
- onCancel: cancelAdvisory
1802
- })
1803
- ]
1804
- });
1805
- }
1806
- //#endregion
1807
- export { Editor as default };
1808
-
1809
- //# sourceMappingURL=editor-mNThkZOv.js.map