@arkcit/engine 0.3.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 (42) hide show
  1. package/README.md +68 -0
  2. package/dist/UIEngine.d.ts +6 -0
  3. package/dist/UIEngine.js +3235 -0
  4. package/dist/bindings.d.ts +8 -0
  5. package/dist/bindings.js +146 -0
  6. package/dist/components/index.d.ts +17 -0
  7. package/dist/components/index.js +143 -0
  8. package/dist/core/index.d.ts +4 -0
  9. package/dist/core/index.js +9 -0
  10. package/dist/form/engineFormValidation.d.ts +2 -0
  11. package/dist/form/engineFormValidation.js +241 -0
  12. package/dist/form.d.ts +67 -0
  13. package/dist/form.js +241 -0
  14. package/dist/index.d.ts +15 -0
  15. package/dist/index.js +3336 -0
  16. package/dist/layout.d.ts +6 -0
  17. package/dist/layout.js +82 -0
  18. package/dist/preview/index.d.ts +63 -0
  19. package/dist/preview/index.js +1514 -0
  20. package/dist/react-web/index.d.ts +8 -0
  21. package/dist/react-web/index.js +3246 -0
  22. package/dist/registry.d.ts +2 -0
  23. package/dist/registry.js +0 -0
  24. package/dist/render-layer/index.d.ts +1 -0
  25. package/dist/render-layer/index.js +13 -0
  26. package/dist/renderStudioForm-CPQEzvT7.d.ts +75 -0
  27. package/dist/renderers/index.d.ts +8 -0
  28. package/dist/renderers/index.js +1570 -0
  29. package/dist/runtime/index.d.ts +1 -0
  30. package/dist/runtime/index.js +0 -0
  31. package/dist/schema/index.d.ts +1 -0
  32. package/dist/schema/index.js +0 -0
  33. package/dist/studio-bridge/index.d.ts +501 -0
  34. package/dist/studio-bridge/index.js +2840 -0
  35. package/dist/studioProps.d.ts +8 -0
  36. package/dist/studioProps.js +97 -0
  37. package/dist/types-9TZ2lQDP.d.ts +60 -0
  38. package/dist/types-CyAE6ZLH.d.ts +19 -0
  39. package/dist/types.d.ts +16 -0
  40. package/dist/types.js +0 -0
  41. package/dist/wizardEditingHandlers-D50tR-6n.d.ts +163 -0
  42. package/package.json +160 -0
@@ -0,0 +1,3235 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+
21
+ // src/react-web/engine/ReactWebEngineRoot.tsx
22
+ import { ReactWebEngineRoot as ReactWebEngineRootImpl } from "@arkcit/engine-react";
23
+
24
+ // src/studio-bridge/inline/InlineTextEditor.tsx
25
+ import { jsx } from "react/jsx-runtime";
26
+ var InlineTextEditor = ({
27
+ editing,
28
+ onChange,
29
+ onCancel,
30
+ onCommit
31
+ }) => editing.multiline ? /* @__PURE__ */ jsx(
32
+ "textarea",
33
+ {
34
+ className: "absolute z-[260] h-full w-full resize-none rounded-md border border-primary/70 bg-background/95 px-2 py-1 text-sm text-foreground outline-none ring-0 cursor-text shadow-lg",
35
+ style: editing.editorStyle,
36
+ value: editing.value,
37
+ autoFocus: true,
38
+ "aria-label": "Inline text editor",
39
+ onChange: (event) => onChange(event.target.value),
40
+ onBlur: onCommit,
41
+ onKeyDown: (event) => {
42
+ if (event.key === "Escape") {
43
+ event.preventDefault();
44
+ onCancel();
45
+ return;
46
+ }
47
+ if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
48
+ event.preventDefault();
49
+ onCommit();
50
+ }
51
+ }
52
+ }
53
+ ) : /* @__PURE__ */ jsx(
54
+ "input",
55
+ {
56
+ className: "absolute z-[260] h-full w-full rounded-md border border-primary/70 bg-background/95 px-2 text-sm text-foreground outline-none ring-0 cursor-text shadow-lg",
57
+ style: editing.editorStyle,
58
+ value: editing.value,
59
+ autoFocus: true,
60
+ "aria-label": "Inline text editor",
61
+ onChange: (event) => onChange(event.target.value),
62
+ onBlur: onCommit,
63
+ onKeyDown: (event) => {
64
+ if (event.key === "Escape") {
65
+ event.preventDefault();
66
+ onCancel();
67
+ return;
68
+ }
69
+ if (event.key === "Enter") {
70
+ event.preventDefault();
71
+ onCommit();
72
+ }
73
+ }
74
+ }
75
+ );
76
+
77
+ // src/studio-bridge/nodes/StudioNodeWrapper.tsx
78
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
79
+ var StudioNodeWrapper = ({
80
+ nodeId,
81
+ wrapperClassName = "",
82
+ cursorClassName = "",
83
+ isSelected,
84
+ allowResizeHandle = true,
85
+ style,
86
+ onClick,
87
+ onDoubleClick,
88
+ onTouchStart,
89
+ onTouchMove,
90
+ onTouchEnd,
91
+ showResizeHandle,
92
+ onResizeMouseDown,
93
+ isInlineEditing,
94
+ preserveContentWhileInlineEditing = false,
95
+ children,
96
+ inlineEditor
97
+ }) => /* @__PURE__ */ jsxs(
98
+ "div",
99
+ {
100
+ "data-node-id": nodeId,
101
+ className: [
102
+ "relative block w-fit min-w-0 max-w-full rounded-md border border-transparent transition-colors",
103
+ wrapperClassName,
104
+ cursorClassName,
105
+ isSelected ? "border-dashed border-primary/60 bg-primary/5" : ""
106
+ ].filter(Boolean).join(" "),
107
+ style: __spreadValues({
108
+ position: "relative"
109
+ }, style != null ? style : {}),
110
+ onTouchStart,
111
+ onTouchMove,
112
+ onTouchEnd,
113
+ onClick,
114
+ onDoubleClick,
115
+ children: [
116
+ allowResizeHandle && showResizeHandle && onResizeMouseDown ? /* @__PURE__ */ jsx2(
117
+ "button",
118
+ {
119
+ type: "button",
120
+ className: "absolute -right-2 -top-2 z-20 inline-flex h-7 w-7 cursor-nwse-resize items-center justify-center rounded-md border border-primary bg-primary text-xs text-primary-foreground shadow-sm transition-colors hover:bg-primary-hover hover:border-primary-hover",
121
+ "aria-label": "Resize node",
122
+ onMouseDown: onResizeMouseDown,
123
+ children: "\u2922"
124
+ }
125
+ ) : null,
126
+ /* @__PURE__ */ jsx2(
127
+ "div",
128
+ {
129
+ className: isInlineEditing && !preserveContentWhileInlineEditing ? "pointer-events-none opacity-0" : void 0,
130
+ children
131
+ }
132
+ ),
133
+ isInlineEditing ? inlineEditor : null
134
+ ]
135
+ },
136
+ nodeId
137
+ );
138
+
139
+ // src/react-web/engine/NodeErrorBoundary.tsx
140
+ import { NodeErrorBoundary } from "@arkcit/engine-react";
141
+
142
+ // src/studio-bridge/inline/forceFullWidth.ts
143
+ var shouldForceStudioNodeFullWidth = ({
144
+ widthPct,
145
+ nodeType,
146
+ isStudioRendererContext,
147
+ colSpan
148
+ }) => widthPct === null && (nodeType === "Container" || nodeType === "Grid" || colSpan !== void 0 || isStudioRendererContext && (nodeType === "Form" || nodeType === "FormWizard"));
149
+
150
+ // src/studio-bridge/inline/inlineText.ts
151
+ var getEditableTextValue = ({
152
+ node,
153
+ nodeProps,
154
+ propName,
155
+ runtime,
156
+ resolveTranslationValue
157
+ }) => {
158
+ var _a;
159
+ let value = nodeProps[propName];
160
+ if (node.type === "FormField" && (propName === "label" || propName === "name")) {
161
+ const fieldObject = nodeProps.field && typeof nodeProps.field === "object" && !Array.isArray(nodeProps.field) ? nodeProps.field : null;
162
+ if (value === void 0 && fieldObject) {
163
+ value = fieldObject[propName];
164
+ }
165
+ }
166
+ if (typeof value === "string") return { value, mode: "primitive" };
167
+ if (typeof value === "number" || typeof value === "boolean") {
168
+ return { value: String(value), mode: "primitive" };
169
+ }
170
+ if (value && typeof value === "object") {
171
+ if ("$t" in value && typeof value.$t === "string") {
172
+ const translationValue = value;
173
+ const resolvedValue = resolveTranslationValue(translationValue, runtime);
174
+ return {
175
+ value: typeof resolvedValue === "string" ? resolvedValue : (_a = translationValue.defaultValue) != null ? _a : translationValue.$t,
176
+ mode: "translation"
177
+ };
178
+ }
179
+ try {
180
+ return {
181
+ value: JSON.stringify(value, null, 2),
182
+ mode: "json"
183
+ };
184
+ } catch (e) {
185
+ return null;
186
+ }
187
+ }
188
+ return null;
189
+ };
190
+ var selectCandidateInlineProp = ({
191
+ node,
192
+ isWizardStepNode,
193
+ orderedEditableTextProps,
194
+ getTextValue
195
+ }) => {
196
+ var _a, _b;
197
+ if (node.type === "FormField") {
198
+ if (getTextValue("label")) return "label";
199
+ if (getTextValue("name")) return "name";
200
+ }
201
+ if (node.type === "Button") {
202
+ if (getTextValue("children")) return "children";
203
+ }
204
+ if (node.type === "Form") {
205
+ if (getTextValue("title")) return "title";
206
+ }
207
+ if (isWizardStepNode) {
208
+ if (getTextValue("title")) return "title";
209
+ if (getTextValue("description")) return "description";
210
+ }
211
+ const blockedTypes = /* @__PURE__ */ new Set(["Form", "FormWizard", "Accordion", "ExpandablePanel"]);
212
+ if (node.type === "Cover") {
213
+ const coverTextProps = ["eyebrow", "title", "subtitle", "description", "children"];
214
+ return (_a = coverTextProps.find((propName) => getTextValue(propName) !== null)) != null ? _a : null;
215
+ }
216
+ const sourceProps = blockedTypes.has(node.type) ? [] : orderedEditableTextProps;
217
+ return (_b = sourceProps.find((propName) => getTextValue(propName) !== null)) != null ? _b : null;
218
+ };
219
+ var selectEffectiveInlineProp = ({
220
+ node,
221
+ isWizardStepNode,
222
+ hasRenderableChildren,
223
+ childrenInlineEntry,
224
+ candidateInlineProp
225
+ }) => {
226
+ if (isWizardStepNode) return candidateInlineProp;
227
+ if (node.type === "FormField") return candidateInlineProp;
228
+ if (node.type === "ScrollReveal") {
229
+ if (hasRenderableChildren) return null;
230
+ return childrenInlineEntry ? "children" : null;
231
+ }
232
+ if (node.type === "Cover") return candidateInlineProp;
233
+ if (node.type === "Dropdown" || node.type === "Tooltip" || node.type === "Popin" || node.type === "Drawer") {
234
+ return candidateInlineProp;
235
+ }
236
+ if (hasRenderableChildren) {
237
+ return childrenInlineEntry ? "children" : null;
238
+ }
239
+ return candidateInlineProp;
240
+ };
241
+
242
+ // src/studio-bridge/inline/inlineEditing.ts
243
+ var getValueAtPropPath = (source, propPath) => propPath.split(".").filter(Boolean).reduce((current, segment) => {
244
+ if (!current || typeof current !== "object" || Array.isArray(current)) return void 0;
245
+ return current[segment];
246
+ }, source);
247
+ var computeInlineEditorStyle = ({
248
+ wrapperElement,
249
+ targetElementForEditor
250
+ }) => {
251
+ if (!targetElementForEditor) return { inset: 0 };
252
+ const wrapperRect = wrapperElement.getBoundingClientRect();
253
+ const targetRect = targetElementForEditor.getBoundingClientRect();
254
+ return {
255
+ top: Math.max(0, targetRect.top - wrapperRect.top - 2),
256
+ left: Math.max(0, targetRect.left - wrapperRect.left - 2),
257
+ width: Math.max(48, targetRect.width + 4),
258
+ height: Math.max(32, targetRect.height + 4)
259
+ };
260
+ };
261
+ var shouldUseMultilineInlineEditor = ({
262
+ mode,
263
+ value
264
+ }) => mode === "json" || value.length > 64;
265
+ var applyInlineEditingValue = ({
266
+ editingState,
267
+ rawValue,
268
+ schemaNodes,
269
+ onInlineTextEdit,
270
+ findNodeById: findNodeById2
271
+ }) => {
272
+ var _a;
273
+ if (!onInlineTextEdit) return;
274
+ const isFormFieldLabelOrName = editingState.propName === "label" || editingState.propName === "name";
275
+ const applyFormFieldValue = (nextValue) => {
276
+ var _a2;
277
+ const targetNode2 = findNodeById2(editingState.nodeId, schemaNodes);
278
+ const targetProps2 = (_a2 = targetNode2 == null ? void 0 : targetNode2.props) != null ? _a2 : {};
279
+ const currentField = targetProps2.field && typeof targetProps2.field === "object" && !Array.isArray(targetProps2.field) ? targetProps2.field : {};
280
+ if ((targetNode2 == null ? void 0 : targetNode2.type) === "FormField" && isFormFieldLabelOrName) {
281
+ onInlineTextEdit(editingState.nodeId, "field", __spreadProps(__spreadValues({}, currentField), {
282
+ [editingState.propName]: nextValue
283
+ }));
284
+ }
285
+ };
286
+ const targetNode = findNodeById2(editingState.nodeId, schemaNodes);
287
+ const targetProps = (_a = targetNode == null ? void 0 : targetNode.props) != null ? _a : {};
288
+ const currentValue = getValueAtPropPath(targetProps, editingState.propName);
289
+ if (editingState.mode === "translation" && currentValue && typeof currentValue === "object" && !Array.isArray(currentValue) && typeof currentValue.$t === "string") {
290
+ onInlineTextEdit(editingState.nodeId, editingState.propName, __spreadProps(__spreadValues({}, currentValue), {
291
+ $t: rawValue,
292
+ defaultValue: rawValue
293
+ }));
294
+ return;
295
+ }
296
+ if (editingState.mode === "json") {
297
+ try {
298
+ const parsed = JSON.parse(rawValue);
299
+ applyFormFieldValue(parsed);
300
+ onInlineTextEdit(editingState.nodeId, editingState.propName, parsed);
301
+ return;
302
+ } catch (e) {
303
+ applyFormFieldValue(rawValue);
304
+ onInlineTextEdit(editingState.nodeId, editingState.propName, rawValue);
305
+ return;
306
+ }
307
+ }
308
+ const trimmed = rawValue.trim();
309
+ if (trimmed.startsWith("{") && trimmed.endsWith("}") || trimmed.startsWith("[") && trimmed.endsWith("]")) {
310
+ try {
311
+ const parsed = JSON.parse(trimmed);
312
+ applyFormFieldValue(parsed);
313
+ onInlineTextEdit(editingState.nodeId, editingState.propName, parsed);
314
+ return;
315
+ } catch (e) {
316
+ }
317
+ }
318
+ applyFormFieldValue(rawValue);
319
+ onInlineTextEdit(editingState.nodeId, editingState.propName, rawValue);
320
+ };
321
+
322
+ // src/studio-bridge/inline/inlineEditorOpening.ts
323
+ var openInlineEditorFromDoubleClick = ({
324
+ event,
325
+ nodeId,
326
+ nodeType,
327
+ effectiveCandidateInlineProp,
328
+ getTextValue,
329
+ setInlineEditing
330
+ }) => {
331
+ var _a;
332
+ const targetElement = event.target;
333
+ const targetInlineProp = (_a = targetElement == null ? void 0 : targetElement.closest("[data-inline-prop]")) == null ? void 0 : _a.getAttribute("data-inline-prop");
334
+ const chosenProp = nodeType === "Cover" && targetInlineProp ? targetInlineProp : targetInlineProp && targetInlineProp !== "children" ? targetInlineProp : effectiveCandidateInlineProp;
335
+ if (!chosenProp) return false;
336
+ const initialEntry = getTextValue(chosenProp);
337
+ if (initialEntry === null) return false;
338
+ const targetElementForEditor = targetInlineProp ? targetElement == null ? void 0 : targetElement.closest("[data-inline-prop]") : null;
339
+ const wrapperElement = event.currentTarget;
340
+ const editorStyle = computeInlineEditorStyle({
341
+ wrapperElement,
342
+ targetElementForEditor
343
+ });
344
+ event.preventDefault();
345
+ event.stopPropagation();
346
+ setInlineEditing({
347
+ nodeId,
348
+ propName: chosenProp,
349
+ value: initialEntry.value,
350
+ multiline: shouldUseMultilineInlineEditor({
351
+ mode: initialEntry.mode,
352
+ value: initialEntry.value
353
+ }),
354
+ mode: initialEntry.mode,
355
+ editorStyle
356
+ });
357
+ return true;
358
+ };
359
+
360
+ // src/studio-bridge/inline/resolveInlineEditingTarget.ts
361
+ var INLINE_TECHNICAL_TEXT_PROPS = /* @__PURE__ */ new Set(["className", "rootMargin"]);
362
+ var PREFERRED_INLINE_TEXT_PROPS = [
363
+ "children",
364
+ "label",
365
+ "title",
366
+ "description",
367
+ "placeholder",
368
+ "name",
369
+ "text"
370
+ ];
371
+ var resolveInlineEditingTarget = ({
372
+ node,
373
+ nodeProps,
374
+ runtime,
375
+ editableTextProps,
376
+ resolveTranslationValue
377
+ }) => {
378
+ var _a, _b, _c, _d, _e;
379
+ const isWizardStepNode = node.type === "Container" && String((_a = nodeProps.cardSection) != null ? _a : "") !== "header" && String((_b = nodeProps.cardSection) != null ? _b : "") !== "body" && String((_c = nodeProps.cardSection) != null ? _c : "") !== "footer" && (nodeProps.layout && typeof nodeProps.layout === "object" && !Array.isArray(nodeProps.layout) ? Boolean(nodeProps.layout.wizardStep) : false);
380
+ const canResolveInlineText = isWizardStepNode || editableTextProps.length > 0;
381
+ const orderedEditableTextProps = canResolveInlineText ? [
382
+ ...PREFERRED_INLINE_TEXT_PROPS.filter((prop) => editableTextProps.includes(prop)),
383
+ ...editableTextProps.filter(
384
+ (prop) => !PREFERRED_INLINE_TEXT_PROPS.includes(prop) && !INLINE_TECHNICAL_TEXT_PROPS.has(prop)
385
+ )
386
+ ] : [];
387
+ const getTextValue = canResolveInlineText ? (propName) => getEditableTextValue({
388
+ node,
389
+ nodeProps,
390
+ propName,
391
+ runtime,
392
+ resolveTranslationValue
393
+ }) : () => null;
394
+ const candidateInlineProp = canResolveInlineText ? selectCandidateInlineProp({
395
+ node,
396
+ isWizardStepNode,
397
+ orderedEditableTextProps,
398
+ getTextValue
399
+ }) : null;
400
+ const effectiveCandidateInlineProp = canResolveInlineText ? selectEffectiveInlineProp({
401
+ node,
402
+ isWizardStepNode,
403
+ hasRenderableChildren: ((_e = (_d = node.children) == null ? void 0 : _d.length) != null ? _e : 0) > 0,
404
+ childrenInlineEntry: getTextValue("children"),
405
+ candidateInlineProp
406
+ }) : null;
407
+ return {
408
+ canResolveInlineText,
409
+ isWizardStepNode,
410
+ orderedEditableTextProps,
411
+ getTextValue,
412
+ effectiveCandidateInlineProp
413
+ };
414
+ };
415
+
416
+ // src/studio-bridge/interactions/studioClick.ts
417
+ var isInteractiveSelectionTarget = ({
418
+ targetElement,
419
+ nodeType,
420
+ isFormInteractiveTarget
421
+ }) => isFormInteractiveTarget(targetElement) && nodeType !== "Button" && nodeType !== "Link";
422
+ var resolveButtonOverlayTarget = ({
423
+ clickEvent,
424
+ boundTargetNodeId,
425
+ overlayCandidates
426
+ }) => {
427
+ var _a, _b, _c;
428
+ const actionLabel = clickEvent && typeof clickEvent === "object" ? "id" in clickEvent ? String((_a = clickEvent.id) != null ? _a : "") : "type" in clickEvent ? String((_b = clickEvent.type) != null ? _b : "") : "" : "";
429
+ const payload = clickEvent && typeof clickEvent === "object" && "payload" in clickEvent && clickEvent.payload && typeof clickEvent.payload === "object" ? clickEvent.payload : null;
430
+ const requestedTargetNodeId = String((_c = payload == null ? void 0 : payload.targetNodeId) != null ? _c : boundTargetNodeId).trim();
431
+ const targetNodeId = requestedTargetNodeId || (overlayCandidates.length === 1 ? overlayCandidates[0] : "");
432
+ return {
433
+ actionLabel,
434
+ payload,
435
+ targetNodeId
436
+ };
437
+ };
438
+ var buildNormalizedActionRef = ({
439
+ clickEvent,
440
+ payload,
441
+ targetNodeId
442
+ }) => {
443
+ const basePayload = payload && typeof payload === "object" ? payload : {};
444
+ const normalizedPayload = targetNodeId && !("targetNodeId" in basePayload) ? __spreadProps(__spreadValues({}, basePayload), { targetNodeId }) : basePayload;
445
+ return clickEvent && typeof clickEvent === "object" && "id" in clickEvent ? __spreadProps(__spreadValues({}, clickEvent), { payload: normalizedPayload }) : clickEvent && typeof clickEvent === "object" && "type" in clickEvent ? __spreadProps(__spreadValues({}, clickEvent), { payload: normalizedPayload }) : clickEvent;
446
+ };
447
+ var syncOverlayStateFromAction = ({
448
+ targetNodeId,
449
+ actionLabel,
450
+ runtime,
451
+ onInlineTextEdit,
452
+ findNodeById: findNodeById2,
453
+ schemaNodes
454
+ }) => {
455
+ if (!targetNodeId || !onInlineTextEdit) return;
456
+ const targetNode = findNodeById2(targetNodeId, schemaNodes);
457
+ if (!targetNode) return;
458
+ const overlaysRaw = runtime.get("overlays.byNodeId");
459
+ const overlaysByNodeId = overlaysRaw && typeof overlaysRaw === "object" ? overlaysRaw : {};
460
+ if (!actionLabel) {
461
+ if (targetNode.type === "Popin") {
462
+ onInlineTextEdit(targetNodeId, "displayedPopin", true);
463
+ } else if (targetNode.type === "Drawer") {
464
+ onInlineTextEdit(targetNodeId, "open", true);
465
+ }
466
+ runtime.dispatch({
467
+ id: "overlay.open",
468
+ payload: { targetNodeId }
469
+ });
470
+ return;
471
+ }
472
+ if (targetNode.type === "Popin") {
473
+ if (actionLabel === "overlay.open") {
474
+ onInlineTextEdit(targetNodeId, "displayedPopin", true);
475
+ } else if (actionLabel === "overlay.close") {
476
+ onInlineTextEdit(targetNodeId, "displayedPopin", false);
477
+ } else if (actionLabel === "overlay.toggle") {
478
+ const current = Boolean(overlaysByNodeId[targetNodeId]);
479
+ onInlineTextEdit(targetNodeId, "displayedPopin", !current);
480
+ }
481
+ }
482
+ if (targetNode.type === "Drawer") {
483
+ if (actionLabel === "overlay.open") {
484
+ onInlineTextEdit(targetNodeId, "open", true);
485
+ } else if (actionLabel === "overlay.close") {
486
+ onInlineTextEdit(targetNodeId, "open", false);
487
+ } else if (actionLabel === "overlay.toggle") {
488
+ const current = Boolean(overlaysByNodeId[targetNodeId]);
489
+ onInlineTextEdit(targetNodeId, "open", !current);
490
+ }
491
+ }
492
+ };
493
+ var resolveClickedNodeId = ({
494
+ targetElement,
495
+ fallbackNodeId
496
+ }) => {
497
+ var _a;
498
+ const closestNode = targetElement == null ? void 0 : targetElement.closest("[data-node-id]");
499
+ return (_a = closestNode == null ? void 0 : closestNode.dataset.nodeId) != null ? _a : fallbackNodeId;
500
+ };
501
+
502
+ // src/studio-bridge/nodes/studioNodeEditing.ts
503
+ var suppressStudioClickUntil = 0;
504
+ var shouldSuppressStudioClick = () => Date.now() <= suppressStudioClickUntil;
505
+
506
+ // src/utils/schemaTraversal.ts
507
+ var findNodeById = (nodeId, nodes) => {
508
+ var _a;
509
+ for (const candidate of nodes) {
510
+ if (candidate.id === nodeId) return candidate;
511
+ const nested = findNodeById(nodeId, (_a = candidate.children) != null ? _a : []);
512
+ if (nested) return nested;
513
+ }
514
+ return null;
515
+ };
516
+ var buildAncestorTypeMembership = (nodes, ancestorTypes) => {
517
+ const lookup = Object.fromEntries(
518
+ ancestorTypes.map((type) => [type, /* @__PURE__ */ new Set()])
519
+ );
520
+ const walk = (items, lineage = []) => {
521
+ var _a;
522
+ for (const item of items) {
523
+ for (const ancestorType of ancestorTypes) {
524
+ if (lineage.includes(ancestorType)) {
525
+ lookup[ancestorType].add(item.id);
526
+ }
527
+ }
528
+ if ((_a = item.children) == null ? void 0 : _a.length) {
529
+ walk(item.children, [...lineage, item.type]);
530
+ }
531
+ }
532
+ };
533
+ walk(nodes);
534
+ return lookup;
535
+ };
536
+ var collectOverlayNodeIds = (nodes) => {
537
+ const ids = [];
538
+ const walk = (items) => {
539
+ var _a;
540
+ for (const item of items) {
541
+ if (item.type === "Popin" || item.type === "Drawer") ids.push(item.id);
542
+ if ((_a = item.children) == null ? void 0 : _a.length) walk(item.children);
543
+ }
544
+ };
545
+ walk(nodes);
546
+ return ids;
547
+ };
548
+
549
+ // src/studio-bridge/interactions/resizeStudio.ts
550
+ var computeMouseResizeSize = ({
551
+ state,
552
+ clientX,
553
+ clientY,
554
+ minWidthPct,
555
+ minHeightPct,
556
+ minHeightPx
557
+ }) => {
558
+ const deltaX = clientX - state.startX;
559
+ const deltaY = clientY - state.startY;
560
+ const nextWidth = state.startWidthPct + deltaX / state.containerWidth * 100;
561
+ const nextHeight = state.startHeightPct + deltaY / state.containerHeight * 100;
562
+ const nextHeightPx = state.startHeightPx + deltaY;
563
+ return {
564
+ widthPct: Math.max(minWidthPct, Math.min(100, Number(nextWidth.toFixed(2)))),
565
+ heightPct: Math.max(minHeightPct, Math.min(100, Number(nextHeight.toFixed(2)))),
566
+ heightPx: Math.max(minHeightPx, Number(nextHeightPx.toFixed(0)))
567
+ };
568
+ };
569
+ var computePinchResizeSize = ({
570
+ state,
571
+ distance,
572
+ minWidthPct,
573
+ minHeightPct
574
+ }) => {
575
+ if (!state.startDistance) return null;
576
+ const scale = distance / state.startDistance;
577
+ const nextWidth = state.startWidthPct * scale;
578
+ const nextHeight = state.startHeightPct * scale;
579
+ return {
580
+ widthPct: Math.max(minWidthPct, Math.min(100, Number(nextWidth.toFixed(2)))),
581
+ heightPct: Math.max(minHeightPct, Math.min(100, Number(nextHeight.toFixed(2))))
582
+ };
583
+ };
584
+ var createMouseResizeState = ({
585
+ nodeId,
586
+ clientX,
587
+ clientY,
588
+ widthPct,
589
+ heightPct,
590
+ heightPx,
591
+ elementRect,
592
+ parentRect,
593
+ minHeightPx
594
+ }) => ({
595
+ nodeId,
596
+ startX: clientX,
597
+ startY: clientY,
598
+ startWidthPct: widthPct != null ? widthPct : elementRect.width / Math.max(parentRect.width, 1) * 100,
599
+ startHeightPct: heightPct != null ? heightPct : elementRect.height / Math.max(parentRect.height, 1) * 100,
600
+ startHeightPx: heightPx != null ? heightPx : Math.max(minHeightPx, elementRect.height),
601
+ containerWidth: Math.max(parentRect.width, 1),
602
+ containerHeight: Math.max(parentRect.height, 1)
603
+ });
604
+ var createPinchResizeState = ({
605
+ nodeId,
606
+ widthPct,
607
+ heightPct,
608
+ distance
609
+ }) => ({
610
+ nodeId,
611
+ startDistance: distance,
612
+ startWidthPct: widthPct != null ? widthPct : 100,
613
+ startHeightPct: heightPct != null ? heightPct : 100
614
+ });
615
+
616
+ // src/studio-bridge/nodes/nodeWrapperHandlers.ts
617
+ var createTouchResizeHandlers = ({
618
+ node,
619
+ widthPct,
620
+ heightPct,
621
+ onNodeResize,
622
+ onNodeResizeStart,
623
+ onNodeResizeEnd,
624
+ pinchStateRef,
625
+ minWidthPct,
626
+ minHeightPct
627
+ }) => ({
628
+ onTouchStart: (event) => {
629
+ if (!onNodeResize) return;
630
+ if (event.touches.length < 2) return;
631
+ onNodeResizeStart == null ? void 0 : onNodeResizeStart(node.id);
632
+ const [firstTouch, secondTouch] = [event.touches[0], event.touches[1]];
633
+ const dx = secondTouch.clientX - firstTouch.clientX;
634
+ const dy = secondTouch.clientY - firstTouch.clientY;
635
+ const distance = Math.hypot(dx, dy);
636
+ pinchStateRef.current = createPinchResizeState({
637
+ nodeId: node.id,
638
+ widthPct,
639
+ heightPct,
640
+ distance
641
+ });
642
+ },
643
+ onTouchMove: (event) => {
644
+ if (!onNodeResize) return;
645
+ const state = pinchStateRef.current;
646
+ if (!state || state.nodeId !== node.id) return;
647
+ if (event.touches.length < 2) return;
648
+ const [firstTouch, secondTouch] = [event.touches[0], event.touches[1]];
649
+ const dx = secondTouch.clientX - firstTouch.clientX;
650
+ const dy = secondTouch.clientY - firstTouch.clientY;
651
+ const distance = Math.hypot(dx, dy);
652
+ const nextSize = computePinchResizeSize({
653
+ state,
654
+ distance,
655
+ minWidthPct,
656
+ minHeightPct
657
+ });
658
+ if (!nextSize) return;
659
+ pinchStateRef.current = __spreadProps(__spreadValues({}, state), {
660
+ lastSize: nextSize
661
+ });
662
+ onNodeResize(node.id, nextSize);
663
+ },
664
+ onTouchEnd: () => {
665
+ const state = pinchStateRef.current;
666
+ if (state == null ? void 0 : state.lastSize) {
667
+ onNodeResizeEnd == null ? void 0 : onNodeResizeEnd(node.id, state.lastSize);
668
+ }
669
+ pinchStateRef.current = null;
670
+ }
671
+ });
672
+ var createMouseResizeHandler = ({
673
+ node,
674
+ widthPct,
675
+ heightPct,
676
+ heightPx,
677
+ onNodeResize,
678
+ onNodeResizeStart,
679
+ resizeStateRef,
680
+ minHeightPx
681
+ }) => onNodeResize ? (event) => {
682
+ event.preventDefault();
683
+ event.stopPropagation();
684
+ const element = event.currentTarget.closest("[data-node-id]");
685
+ if (!element) return;
686
+ const parent = element.parentElement;
687
+ if (!parent) return;
688
+ const parentRect = parent.getBoundingClientRect();
689
+ const elementRect = element.getBoundingClientRect();
690
+ onNodeResizeStart == null ? void 0 : onNodeResizeStart(node.id);
691
+ resizeStateRef.current = createMouseResizeState({
692
+ nodeId: node.id,
693
+ clientX: event.clientX,
694
+ clientY: event.clientY,
695
+ widthPct,
696
+ heightPct,
697
+ heightPx,
698
+ elementRect,
699
+ parentRect,
700
+ minHeightPx
701
+ });
702
+ } : void 0;
703
+ var createStudioNodeClickHandler = ({
704
+ node,
705
+ nodeProps,
706
+ schemaNodes,
707
+ runtime,
708
+ onNodeClick,
709
+ onInlineTextEdit,
710
+ isInlineEditingNode,
711
+ enableEventOnClick,
712
+ isFormInteractiveTarget
713
+ }) => (event) => {
714
+ var _a, _b;
715
+ if (shouldSuppressStudioClick()) {
716
+ event.preventDefault();
717
+ event.stopPropagation();
718
+ return;
719
+ }
720
+ if (!onNodeClick) return;
721
+ if (isInlineEditingNode) return;
722
+ const targetElement = event.target;
723
+ if (node.type === "Button" && enableEventOnClick && Boolean(targetElement == null ? void 0 : targetElement.closest("button"))) {
724
+ const clickEvent = (_a = node.events) == null ? void 0 : _a.onClick;
725
+ const boundTargetNodeId = String((_b = nodeProps.buttonTargetNodeId) != null ? _b : "").trim();
726
+ const overlayCandidates = collectOverlayNodeIds(schemaNodes);
727
+ const { actionLabel, payload, targetNodeId } = resolveButtonOverlayTarget({
728
+ clickEvent,
729
+ boundTargetNodeId,
730
+ overlayCandidates
731
+ });
732
+ if (clickEvent) {
733
+ const normalizedActionRef = buildNormalizedActionRef({
734
+ clickEvent,
735
+ payload,
736
+ targetNodeId
737
+ });
738
+ runtime.dispatch(normalizedActionRef);
739
+ }
740
+ syncOverlayStateFromAction({
741
+ targetNodeId,
742
+ actionLabel: clickEvent ? actionLabel : "",
743
+ runtime,
744
+ onInlineTextEdit,
745
+ findNodeById,
746
+ schemaNodes
747
+ });
748
+ event.stopPropagation();
749
+ return;
750
+ }
751
+ if (isInteractiveSelectionTarget({
752
+ targetElement,
753
+ nodeType: node.type,
754
+ isFormInteractiveTarget
755
+ })) {
756
+ event.stopPropagation();
757
+ return;
758
+ }
759
+ const clickedNodeId = resolveClickedNodeId({
760
+ targetElement,
761
+ fallbackNodeId: node.id
762
+ });
763
+ if (clickedNodeId && clickedNodeId !== node.id) {
764
+ event.stopPropagation();
765
+ onNodeClick(clickedNodeId);
766
+ return;
767
+ }
768
+ event.stopPropagation();
769
+ onNodeClick(node.id);
770
+ };
771
+ var createStudioNodeDoubleClickHandler = ({
772
+ node,
773
+ onInlineTextEdit,
774
+ effectiveCandidateInlineProp,
775
+ getTextValue,
776
+ setInlineEditing
777
+ }) => (event) => {
778
+ if (!onInlineTextEdit) return;
779
+ openInlineEditorFromDoubleClick({
780
+ event,
781
+ nodeId: node.id,
782
+ nodeType: node.type,
783
+ effectiveCandidateInlineProp,
784
+ getTextValue,
785
+ setInlineEditing
786
+ });
787
+ };
788
+
789
+ // src/studio-bridge/nodes/nodeWrapperStudio.tsx
790
+ import { jsx as jsx3 } from "react/jsx-runtime";
791
+ var getNodeWrapperPresentation = ({
792
+ isOpenStudioOverlayNode,
793
+ wrapperClassName,
794
+ widthPct,
795
+ shouldForceFullWidth
796
+ }) => {
797
+ const wrapperStyle = isOpenStudioOverlayNode ? {
798
+ position: "absolute",
799
+ inset: 0,
800
+ width: "100%",
801
+ height: "100%"
802
+ } : widthPct !== null || shouldForceFullWidth ? { width: `${widthPct != null ? widthPct : 100}%` } : void 0;
803
+ const overlayWrapperClassName = isOpenStudioOverlayNode ? [wrapperClassName, "absolute inset-0 h-full w-full"].filter(Boolean).join(" ") : wrapperClassName;
804
+ return {
805
+ wrapperStyle,
806
+ overlayWrapperClassName,
807
+ requiresPlainWrapper: Boolean(overlayWrapperClassName) || Boolean(wrapperStyle)
808
+ };
809
+ };
810
+ var getStudioNodeInteractionState = ({
811
+ node,
812
+ selectedNodeId,
813
+ effectiveCandidateInlineProp,
814
+ isInlineEditingNode,
815
+ isOpenStudioOverlayNode,
816
+ isInsideForm,
817
+ isInsideFormWizard,
818
+ isInsideStepForm,
819
+ inlinePropName
820
+ }) => {
821
+ var _a, _b, _c;
822
+ const nodeLayoutRecord = node.props && typeof node.props === "object" && !Array.isArray(node.props) && node.props.layout && typeof node.props.layout === "object" && !Array.isArray(node.props.layout) ? node.props.layout : {};
823
+ const isSelected = selectedNodeId === node.id;
824
+ const isFormFieldNode = node.type === "FormField" && String((_a = nodeLayoutRecord.formRole) != null ? _a : "field").trim() === "field";
825
+ const isTitleLikeInternalNode = String((_b = nodeLayoutRecord.formRole) != null ? _b : "").trim() === "title" || String((_c = nodeLayoutRecord.wizardStepRole) != null ? _c : "").trim() === "title" || ["H1", "H2", "H3", "H4", "H5", "H6"].includes(node.type);
826
+ const isActionButtonLikeNode = node.type === "Button" && (isInsideForm || isInsideFormWizard || isInsideStepForm);
827
+ const studioFormFieldWrapperClassName = isFormFieldNode ? "rounded-lg border-dashed border-sky-400/70 bg-sky-500/5 p-2 hover:border-sky-500 hover:bg-sky-500/10" : "";
828
+ const allowNodeHandles = (() => {
829
+ if (isInsideForm) return isFormFieldNode;
830
+ if (isInsideFormWizard || isInsideStepForm) {
831
+ if (isTitleLikeInternalNode) return false;
832
+ if (isActionButtonLikeNode) return false;
833
+ return true;
834
+ }
835
+ return true;
836
+ })();
837
+ return {
838
+ isSelected,
839
+ allowNodeHandles,
840
+ studioFormFieldWrapperClassName,
841
+ cursorClassName: effectiveCandidateInlineProp ? "cursor-text" : "cursor-pointer",
842
+ preserveContentWhileInlineEditing: isInlineEditingNode && isOpenStudioOverlayNode && (inlinePropName === "title" || inlinePropName === "closeText")
843
+ };
844
+ };
845
+ var renderPlainWrappedNode = ({
846
+ nodeId,
847
+ overlayWrapperClassName,
848
+ wrapperStyle,
849
+ nodeContent
850
+ }) => /* @__PURE__ */ jsx3(
851
+ "div",
852
+ {
853
+ "data-node-id": nodeId,
854
+ className: ["relative min-w-0 max-w-full flex-none", overlayWrapperClassName].filter(Boolean).join(" "),
855
+ style: wrapperStyle,
856
+ children: nodeContent
857
+ },
858
+ nodeId
859
+ );
860
+
861
+ // src/render-layer/renderDirectives.ts
862
+ var RENDER_BINDING_PROP_NAMES = /* @__PURE__ */ new Set([
863
+ "bindingEnabled",
864
+ "valueBindingKey",
865
+ "optionsBindingKey",
866
+ "useBindingData",
867
+ "entitiesBindingKey",
868
+ "videoBindingKey",
869
+ "mapBindingKey",
870
+ "productBindingKey",
871
+ "useTranslationKeys",
872
+ "tagContentTranslationKey",
873
+ "tagContentTranslationValue",
874
+ "hrefTranslationKey",
875
+ "hrefTranslationValue",
876
+ "mediaSource",
877
+ "mediaSrc",
878
+ "mediaAlt",
879
+ "rowsBindingKey",
880
+ "columnsBindingKey"
881
+ ]);
882
+ var STUDIO_INTERNAL_PROP_NAMES = /* @__PURE__ */ new Set([
883
+ ...RENDER_BINDING_PROP_NAMES
884
+ ]);
885
+ var getRenderBindingProps = (props) => {
886
+ if (!props || typeof props !== "object" || Array.isArray(props)) {
887
+ return {};
888
+ }
889
+ const source = props;
890
+ const embedded = source.__studio && typeof source.__studio === "object" && !Array.isArray(source.__studio) ? source.__studio : {};
891
+ const legacy = Array.from(RENDER_BINDING_PROP_NAMES).reduce(
892
+ (accumulator, key) => {
893
+ if (source[key] !== void 0) {
894
+ accumulator[key] = source[key];
895
+ }
896
+ return accumulator;
897
+ },
898
+ {}
899
+ );
900
+ return Array.from(RENDER_BINDING_PROP_NAMES).reduce((accumulator, key) => {
901
+ if (legacy[key] !== void 0) {
902
+ accumulator[key] = legacy[key];
903
+ } else if (embedded[key] !== void 0) {
904
+ accumulator[key] = embedded[key];
905
+ }
906
+ return accumulator;
907
+ }, {});
908
+ };
909
+ var omitStudioProps = (props) => {
910
+ const next = __spreadValues({}, props);
911
+ delete next.__studio;
912
+ for (const propName of STUDIO_INTERNAL_PROP_NAMES) {
913
+ delete next[propName];
914
+ }
915
+ return next;
916
+ };
917
+
918
+ // src/utils/renderChildren.tsx
919
+ import { normalizeRenderableChild, toBoolean } from "@arkcit/engine-react";
920
+
921
+ // src/studio-bridge/overlay/overlayStudio.ts
922
+ var toBoolean2 = (value) => {
923
+ if (typeof value === "boolean") return value;
924
+ if (typeof value === "string") return value.toLowerCase() === "true";
925
+ return Boolean(value);
926
+ };
927
+ var readOverlayState = (runtime) => {
928
+ const overlaysRaw = runtime.get("overlays.byNodeId");
929
+ return overlaysRaw && typeof overlaysRaw === "object" ? overlaysRaw : {};
930
+ };
931
+ var applyStudioOverlayComponentProps = ({
932
+ node,
933
+ componentProps,
934
+ runtime,
935
+ overlaysByNodeId,
936
+ renderBindingProps,
937
+ resolvedChildContent,
938
+ onInlineTextEdit,
939
+ isStudioRendererContext,
940
+ dropdownOpenByNodeId,
941
+ setDropdownOpenByNodeId
942
+ }) => {
943
+ if (node.type === "Popin") {
944
+ const bindingEnabled = toBoolean2(renderBindingProps.bindingEnabled);
945
+ const rawOverlayOpen = overlaysByNodeId[node.id];
946
+ const fallbackOpen = Boolean(componentProps.displayedPopin);
947
+ const isOpen = bindingEnabled ? typeof rawOverlayOpen === "boolean" ? rawOverlayOpen : fallbackOpen : fallbackOpen;
948
+ componentProps.displayedPopin = isOpen;
949
+ componentProps.setDisplayedPopin = (next) => {
950
+ const nextOpen = typeof next === "function" ? next(isOpen) : next;
951
+ onInlineTextEdit == null ? void 0 : onInlineTextEdit(node.id, "displayedPopin", nextOpen);
952
+ if (bindingEnabled) {
953
+ runtime.dispatch({
954
+ id: nextOpen ? "overlay.open" : "overlay.close",
955
+ payload: { targetNodeId: node.id }
956
+ });
957
+ }
958
+ };
959
+ componentProps.children = resolvedChildContent !== null ? resolvedChildContent : normalizeRenderableChild(componentProps.children);
960
+ }
961
+ if (node.type === "Drawer") {
962
+ const bindingEnabled = toBoolean2(renderBindingProps.bindingEnabled);
963
+ const rawOverlayOpen = overlaysByNodeId[node.id];
964
+ const fallbackOpen = Boolean(componentProps.open);
965
+ const isOpen = bindingEnabled ? typeof rawOverlayOpen === "boolean" ? rawOverlayOpen : fallbackOpen : fallbackOpen;
966
+ componentProps.open = isOpen;
967
+ componentProps.onClose = () => {
968
+ onInlineTextEdit == null ? void 0 : onInlineTextEdit(node.id, "open", false);
969
+ if (bindingEnabled) {
970
+ runtime.dispatch({
971
+ id: "overlay.close",
972
+ payload: { targetNodeId: node.id }
973
+ });
974
+ }
975
+ };
976
+ componentProps.children = resolvedChildContent !== null ? resolvedChildContent : normalizeRenderableChild(componentProps.children);
977
+ }
978
+ if (node.type === "Dropdown") {
979
+ const fallbackOpen = Boolean(componentProps.open);
980
+ const isOpen = isStudioRendererContext && node.id in dropdownOpenByNodeId ? Boolean(dropdownOpenByNodeId[node.id]) : fallbackOpen;
981
+ componentProps.open = isOpen;
982
+ componentProps.onOpenChange = (nextOpen) => {
983
+ setDropdownOpenByNodeId((previous) => __spreadProps(__spreadValues({}, previous), {
984
+ [node.id]: Boolean(nextOpen)
985
+ }));
986
+ onInlineTextEdit == null ? void 0 : onInlineTextEdit(node.id, "open", Boolean(nextOpen));
987
+ };
988
+ if (resolvedChildContent !== null) {
989
+ componentProps.children = resolvedChildContent;
990
+ }
991
+ }
992
+ if (node.type === "Tooltip") {
993
+ componentProps.children = resolvedChildContent !== null ? resolvedChildContent : normalizeRenderableChild(componentProps.children);
994
+ }
995
+ };
996
+ var getOpenStudioOverlayState = ({
997
+ node,
998
+ nodeProps,
999
+ overlaysByNodeId
1000
+ }) => {
1001
+ const renderBindingProps = getRenderBindingProps(nodeProps);
1002
+ const bindingEnabled = toBoolean2(renderBindingProps.bindingEnabled);
1003
+ return Boolean(
1004
+ node.type === "Popin" && Boolean(bindingEnabled ? overlaysByNodeId[node.id] : nodeProps.displayedPopin) || node.type === "Drawer" && Boolean(bindingEnabled ? overlaysByNodeId[node.id] : nodeProps.open)
1005
+ );
1006
+ };
1007
+
1008
+ // src/studio-bridge/overlay/renderNodeFrame.tsx
1009
+ import { createPortal } from "react-dom";
1010
+ import { jsx as jsx4 } from "react/jsx-runtime";
1011
+ var renderNodeFrame = ({
1012
+ node,
1013
+ nodeProps,
1014
+ nodeContent,
1015
+ selectedNodeId,
1016
+ onNodeClick,
1017
+ onInlineTextEdit,
1018
+ onNodeResize,
1019
+ onNodeResizeStart,
1020
+ onNodeResizeEnd,
1021
+ widthPct,
1022
+ heightPct,
1023
+ heightPx,
1024
+ wrapperClassName,
1025
+ isOpenStudioOverlayNode,
1026
+ shouldForceFullWidth,
1027
+ effectiveCandidateInlineProp,
1028
+ inlineEditing,
1029
+ isInlineEditingNode,
1030
+ ancestorTypeMembership,
1031
+ schemaNodes,
1032
+ runtime,
1033
+ enableEventOnClick,
1034
+ isFormInteractiveTarget,
1035
+ getTextValue,
1036
+ setInlineEditing,
1037
+ inlineEditor,
1038
+ NodeWrapper,
1039
+ overlaysByNodeId,
1040
+ getOpenStudioOverlayState: getOpenStudioOverlayState2,
1041
+ resizeStateRef,
1042
+ pinchStateRef,
1043
+ minWidthPct,
1044
+ minHeightPct,
1045
+ minHeightPx,
1046
+ overlayRootId
1047
+ }) => {
1048
+ var _a;
1049
+ const { wrapperStyle, overlayWrapperClassName, requiresPlainWrapper } = getNodeWrapperPresentation({
1050
+ isOpenStudioOverlayNode,
1051
+ wrapperClassName,
1052
+ widthPct,
1053
+ shouldForceFullWidth
1054
+ });
1055
+ if (!onNodeClick && !selectedNodeId) {
1056
+ if (!requiresPlainWrapper) return nodeContent;
1057
+ return renderPlainWrappedNode({
1058
+ nodeId: node.id,
1059
+ overlayWrapperClassName,
1060
+ wrapperStyle,
1061
+ nodeContent
1062
+ });
1063
+ }
1064
+ const {
1065
+ isSelected,
1066
+ allowNodeHandles,
1067
+ studioFormFieldWrapperClassName,
1068
+ cursorClassName,
1069
+ preserveContentWhileInlineEditing
1070
+ } = getStudioNodeInteractionState({
1071
+ node,
1072
+ selectedNodeId,
1073
+ effectiveCandidateInlineProp,
1074
+ isInlineEditingNode,
1075
+ isOpenStudioOverlayNode,
1076
+ isInsideForm: ancestorTypeMembership.Form.has(node.id),
1077
+ isInsideFormWizard: ancestorTypeMembership.FormWizard.has(node.id),
1078
+ isInsideStepForm: ancestorTypeMembership.StepForm.has(node.id),
1079
+ inlinePropName: inlineEditing == null ? void 0 : inlineEditing.propName
1080
+ });
1081
+ const touchResizeHandlers = createTouchResizeHandlers({
1082
+ node,
1083
+ widthPct,
1084
+ heightPct,
1085
+ onNodeResize,
1086
+ onNodeResizeStart,
1087
+ onNodeResizeEnd,
1088
+ pinchStateRef,
1089
+ minWidthPct,
1090
+ minHeightPct
1091
+ });
1092
+ const onResizeMouseDown = createMouseResizeHandler({
1093
+ node,
1094
+ widthPct,
1095
+ heightPct,
1096
+ heightPx,
1097
+ onNodeResize,
1098
+ onNodeResizeStart,
1099
+ resizeStateRef,
1100
+ minHeightPx
1101
+ });
1102
+ const onClick = createStudioNodeClickHandler({
1103
+ node,
1104
+ nodeProps,
1105
+ schemaNodes,
1106
+ runtime,
1107
+ onNodeClick,
1108
+ onInlineTextEdit,
1109
+ isInlineEditingNode,
1110
+ enableEventOnClick,
1111
+ isFormInteractiveTarget
1112
+ });
1113
+ const onDoubleClick = createStudioNodeDoubleClickHandler({
1114
+ node,
1115
+ onInlineTextEdit,
1116
+ effectiveCandidateInlineProp,
1117
+ getTextValue,
1118
+ setInlineEditing
1119
+ });
1120
+ const wrappedNode = /* @__PURE__ */ jsx4(
1121
+ NodeWrapper,
1122
+ {
1123
+ nodeId: node.id,
1124
+ wrapperClassName: [overlayWrapperClassName, studioFormFieldWrapperClassName].filter(Boolean).join(" "),
1125
+ cursorClassName: onNodeClick ? cursorClassName : "",
1126
+ isSelected,
1127
+ allowDragHandle: allowNodeHandles,
1128
+ allowResizeHandle: allowNodeHandles,
1129
+ style: wrapperStyle,
1130
+ onTouchStart: touchResizeHandlers.onTouchStart,
1131
+ onTouchMove: touchResizeHandlers.onTouchMove,
1132
+ onTouchEnd: touchResizeHandlers.onTouchEnd,
1133
+ onClick,
1134
+ onDoubleClick,
1135
+ showResizeHandle: isSelected && Boolean(onNodeResize) && allowNodeHandles,
1136
+ onResizeMouseDown,
1137
+ isInlineEditing: isInlineEditingNode,
1138
+ preserveContentWhileInlineEditing,
1139
+ inlineEditor,
1140
+ children: nodeContent
1141
+ }
1142
+ );
1143
+ if (getOpenStudioOverlayState2({
1144
+ node,
1145
+ nodeProps,
1146
+ overlaysByNodeId
1147
+ })) {
1148
+ const overlayRoot = (_a = globalThis.document) == null ? void 0 : _a.getElementById(overlayRootId);
1149
+ if (overlayRoot) {
1150
+ return createPortal(wrappedNode, overlayRoot);
1151
+ }
1152
+ }
1153
+ return wrappedNode;
1154
+ };
1155
+
1156
+ // src/studio-bridge/preview-form/previewFormRenderer.tsx
1157
+ import React from "react";
1158
+
1159
+ // src/form/engineFormValidation.ts
1160
+ var EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
1161
+ var isEmptyValue = (value) => {
1162
+ if (value == null) return true;
1163
+ if (typeof value === "string") return value.trim().length === 0;
1164
+ if (Array.isArray(value)) return value.length === 0;
1165
+ return false;
1166
+ };
1167
+ var toNumber = (value) => {
1168
+ if (typeof value === "number" && Number.isFinite(value)) return value;
1169
+ if (typeof value === "string") {
1170
+ const parsed = Number(value);
1171
+ return Number.isFinite(parsed) ? parsed : null;
1172
+ }
1173
+ return null;
1174
+ };
1175
+ var defaultDeclarativeValidatorRegistry = {
1176
+ required: (value) => isEmptyValue(value) ? { code: "required" } : null,
1177
+ minLength: (value, params) => {
1178
+ var _a;
1179
+ if (isEmptyValue(value)) return null;
1180
+ const min = toNumber((_a = params == null ? void 0 : params.min) != null ? _a : params == null ? void 0 : params.value);
1181
+ if (min == null) return null;
1182
+ return String(value).length < min ? { code: "minLength", params: { min } } : null;
1183
+ },
1184
+ maxLength: (value, params) => {
1185
+ var _a;
1186
+ if (isEmptyValue(value)) return null;
1187
+ const max = toNumber((_a = params == null ? void 0 : params.max) != null ? _a : params == null ? void 0 : params.value);
1188
+ if (max == null) return null;
1189
+ return String(value).length > max ? { code: "maxLength", params: { max } } : null;
1190
+ },
1191
+ email: (value) => {
1192
+ if (isEmptyValue(value)) return null;
1193
+ return EMAIL_REGEX.test(String(value)) ? null : { code: "email" };
1194
+ },
1195
+ pattern: (value, params) => {
1196
+ var _a, _b;
1197
+ if (isEmptyValue(value)) return null;
1198
+ const rawPattern = String((_b = (_a = params == null ? void 0 : params.pattern) != null ? _a : params == null ? void 0 : params.value) != null ? _b : "").trim();
1199
+ if (!rawPattern) return null;
1200
+ try {
1201
+ const regex = new RegExp(rawPattern);
1202
+ return regex.test(String(value)) ? null : { code: "pattern", params: { pattern: rawPattern } };
1203
+ } catch (e) {
1204
+ return { code: "pattern" };
1205
+ }
1206
+ }
1207
+ };
1208
+ var buildLegacyValidators = (field) => {
1209
+ var _a, _b, _c;
1210
+ const validators = [];
1211
+ if (field.required) {
1212
+ validators.push({
1213
+ id: `${String((_a = field.name) != null ? _a : "field")}:required`,
1214
+ type: "required",
1215
+ stopOnFailure: true
1216
+ });
1217
+ }
1218
+ if (String((_b = field.pattern) != null ? _b : "").trim()) {
1219
+ validators.push({
1220
+ id: `${String((_c = field.name) != null ? _c : "field")}:pattern`,
1221
+ type: "pattern",
1222
+ params: { pattern: String(field.pattern) }
1223
+ });
1224
+ }
1225
+ return validators;
1226
+ };
1227
+ var normalizeValidators = (field, options) => {
1228
+ const explicit = Array.isArray(field.validators) ? field.validators : [];
1229
+ if (explicit.length > 0) return explicit;
1230
+ if (!(options == null ? void 0 : options.useLegacyFieldConstraints)) return [];
1231
+ return buildLegacyValidators(field);
1232
+ };
1233
+ var toIssueArray = (issue) => {
1234
+ if (!issue) return [];
1235
+ return Array.isArray(issue) ? issue : [issue];
1236
+ };
1237
+ var validateFieldWithConfig = (field, value, values, config, registry) => {
1238
+ if (config.enabled === false) return [];
1239
+ const validate = registry[config.type];
1240
+ if (!validate) return [];
1241
+ const baseIssues = toIssueArray(
1242
+ validate(value, config.params, {
1243
+ field,
1244
+ values
1245
+ })
1246
+ );
1247
+ return baseIssues.map((baseIssue) => {
1248
+ var _a, _b, _c, _d, _e;
1249
+ return {
1250
+ field: String((_a = field.name) != null ? _a : ""),
1251
+ validatorId: config.id || baseIssue.validatorId,
1252
+ code: baseIssue.code,
1253
+ messageKey: (_b = baseIssue.messageKey) != null ? _b : config.messageKey,
1254
+ message: (_c = baseIssue.message) != null ? _c : config.message,
1255
+ params: __spreadValues(__spreadValues({}, (_d = config.params) != null ? _d : {}), (_e = baseIssue.params) != null ? _e : {})
1256
+ };
1257
+ });
1258
+ };
1259
+ var resolveIssueMessage = (issue, t) => {
1260
+ const defaultMessageByCode = () => {
1261
+ var _a, _b, _c, _d, _e, _f;
1262
+ switch (issue.code) {
1263
+ case "required":
1264
+ return "This field is required";
1265
+ case "email":
1266
+ return "Invalid email address";
1267
+ case "pattern":
1268
+ return "Invalid format";
1269
+ case "minLength": {
1270
+ const min = (_c = (_a = issue.params) == null ? void 0 : _a.min) != null ? _c : (_b = issue.params) == null ? void 0 : _b.value;
1271
+ return min != null ? `Minimum ${String(min)} characters` : "Value is too short";
1272
+ }
1273
+ case "maxLength": {
1274
+ const max = (_f = (_d = issue.params) == null ? void 0 : _d.max) != null ? _f : (_e = issue.params) == null ? void 0 : _e.value;
1275
+ return max != null ? `Maximum ${String(max)} characters` : "Value is too long";
1276
+ }
1277
+ default:
1278
+ return void 0;
1279
+ }
1280
+ };
1281
+ if (issue.messageKey && t) {
1282
+ const translated = t(issue.messageKey, issue.params);
1283
+ if (typeof translated === "string" && translated.trim().length > 0) {
1284
+ return translated;
1285
+ }
1286
+ }
1287
+ if (issue.message && issue.message.trim().length > 0) return issue.message;
1288
+ if (issue.messageKey && issue.messageKey.trim().length > 0) return issue.messageKey;
1289
+ return defaultMessageByCode();
1290
+ };
1291
+ var validateFormValues = (fields, values, options) => {
1292
+ var _a;
1293
+ const mergedRegistry = __spreadValues(__spreadValues({}, defaultDeclarativeValidatorRegistry), (_a = options == null ? void 0 : options.registry) != null ? _a : {});
1294
+ const issues = [];
1295
+ fields.forEach((field) => {
1296
+ var _a2;
1297
+ const fieldName = String((_a2 = field.name) != null ? _a2 : "").trim();
1298
+ if (!fieldName) return;
1299
+ const fieldValue = values[fieldName];
1300
+ const validators = normalizeValidators(field, options);
1301
+ if (validators.length === 0) return;
1302
+ for (const validatorConfig of validators) {
1303
+ const fieldIssues = validateFieldWithConfig(
1304
+ field,
1305
+ fieldValue,
1306
+ values,
1307
+ validatorConfig,
1308
+ mergedRegistry
1309
+ );
1310
+ if (fieldIssues.length > 0) {
1311
+ issues.push(...fieldIssues);
1312
+ if (validatorConfig.stopOnFailure) break;
1313
+ }
1314
+ }
1315
+ });
1316
+ const errors = {};
1317
+ issues.forEach((issue) => {
1318
+ if (errors[issue.field]) return;
1319
+ errors[issue.field] = resolveIssueMessage(issue, options == null ? void 0 : options.t);
1320
+ });
1321
+ return { issues, errors };
1322
+ };
1323
+
1324
+ // src/utils/formStudio.ts
1325
+ var getLayoutRecord = (props) => {
1326
+ if (!props) return {};
1327
+ const layout = props.layout;
1328
+ if (!layout || typeof layout !== "object" || Array.isArray(layout)) {
1329
+ return {};
1330
+ }
1331
+ return layout;
1332
+ };
1333
+ var normalizeStudioFormChild = (child) => {
1334
+ var _a, _b, _c, _d, _e;
1335
+ const childProps = (_a = child.props) != null ? _a : {};
1336
+ const childLayout = getLayoutRecord(childProps);
1337
+ if (child.type === "__studio_form_field") {
1338
+ return __spreadProps(__spreadValues({}, child), {
1339
+ type: "FormField",
1340
+ props: __spreadProps(__spreadValues({}, childProps), {
1341
+ layout: __spreadProps(__spreadValues({}, childLayout), {
1342
+ formRole: "field"
1343
+ })
1344
+ })
1345
+ });
1346
+ }
1347
+ if (child.type === "__studio_form_title") {
1348
+ return __spreadProps(__spreadValues({}, child), {
1349
+ type: "Text",
1350
+ props: __spreadProps(__spreadValues({}, childProps), {
1351
+ layout: __spreadProps(__spreadValues({}, childLayout), {
1352
+ formRole: "title"
1353
+ })
1354
+ })
1355
+ });
1356
+ }
1357
+ if (child.type === "__studio_form_submit") {
1358
+ return __spreadProps(__spreadValues({}, child), {
1359
+ type: "Button",
1360
+ props: __spreadProps(__spreadValues({}, childProps), {
1361
+ intent: String((_b = childProps.intent) != null ? _b : "primary"),
1362
+ variant: String((_c = childProps.variant) != null ? _c : "solid"),
1363
+ layout: __spreadProps(__spreadValues({}, childLayout), {
1364
+ formRole: "submit"
1365
+ })
1366
+ })
1367
+ });
1368
+ }
1369
+ if (child.type === "__studio_form_reset") {
1370
+ return __spreadProps(__spreadValues({}, child), {
1371
+ type: "Button",
1372
+ props: __spreadProps(__spreadValues({}, childProps), {
1373
+ intent: String((_d = childProps.intent) != null ? _d : "neutral"),
1374
+ variant: String((_e = childProps.variant) != null ? _e : "outline"),
1375
+ layout: __spreadProps(__spreadValues({}, childLayout), {
1376
+ formRole: "reset"
1377
+ })
1378
+ })
1379
+ });
1380
+ }
1381
+ return child;
1382
+ };
1383
+ var getStudioFormChildRole = (child) => {
1384
+ var _a, _b;
1385
+ if (child.type === "__studio_form_field") return "field";
1386
+ if (child.type === "__studio_form_title") return "title";
1387
+ if (child.type === "__studio_form_submit") return "submit";
1388
+ if (child.type === "__studio_form_reset") return "reset";
1389
+ const layout = getLayoutRecord(
1390
+ (_a = child.props) != null ? _a : {}
1391
+ );
1392
+ return String((_b = layout.formRole) != null ? _b : "").trim();
1393
+ };
1394
+ var buildFormFieldConfig = (rawProps, nestedField = {}) => {
1395
+ var _a, _b, _c, _d;
1396
+ const fieldName = String((_b = (_a = rawProps.name) != null ? _a : nestedField.name) != null ? _b : "").trim();
1397
+ return __spreadProps(__spreadValues(__spreadValues({}, nestedField), rawProps), {
1398
+ name: fieldName,
1399
+ label: String((_d = (_c = rawProps.label) != null ? _c : nestedField.label) != null ? _d : fieldName)
1400
+ });
1401
+ };
1402
+ var buildWizardFieldConfig = (rawProps, nestedField) => {
1403
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
1404
+ const name = String((_b = (_a = rawProps.name) != null ? _a : nestedField.name) != null ? _b : "").trim();
1405
+ return {
1406
+ name,
1407
+ label: String((_d = (_c = rawProps.label) != null ? _c : nestedField.label) != null ? _d : name || "Field"),
1408
+ type: (_e = rawProps.type) != null ? _e : nestedField.type,
1409
+ required: Boolean((_g = (_f = rawProps.required) != null ? _f : nestedField.required) != null ? _g : false),
1410
+ pattern: rawProps.pattern != null ? String(rawProps.pattern) : nestedField.pattern != null ? String(nestedField.pattern) : void 0,
1411
+ placeholder: (_h = rawProps.placeholder) != null ? _h : nestedField.placeholder,
1412
+ validators: Array.isArray(rawProps.validators) && rawProps.validators.length > 0 ? rawProps.validators : Array.isArray(nestedField.validators) && nestedField.validators.length > 0 ? nestedField.validators : void 0,
1413
+ options: (_i = rawProps.options) != null ? _i : nestedField.options,
1414
+ helperText: (_j = rawProps.helperText) != null ? _j : nestedField.helperText,
1415
+ defaultValue: (_k = rawProps.defaultValue) != null ? _k : nestedField.defaultValue,
1416
+ rows: (_l = rawProps.rows) != null ? _l : nestedField.rows,
1417
+ accept: (_m = rawProps.accept) != null ? _m : nestedField.accept
1418
+ };
1419
+ };
1420
+
1421
+ // src/layout/nodeLayout.ts
1422
+ var toPositiveNumber = (value) => {
1423
+ const numeric = Number(value);
1424
+ if (!Number.isFinite(numeric) || numeric <= 0) return void 0;
1425
+ return numeric;
1426
+ };
1427
+ var toColSpan = (value) => {
1428
+ const numeric = Number(value);
1429
+ if (!Number.isInteger(numeric) || numeric < 1 || numeric > 12) return void 0;
1430
+ return numeric;
1431
+ };
1432
+ var toCardSection = (value) => {
1433
+ if (value === "header" || value === "body" || value === "footer") return value;
1434
+ return void 0;
1435
+ };
1436
+ var readNodeLayout = (props) => {
1437
+ var _a, _b, _c, _d, _e, _f, _g;
1438
+ if (!props) return {};
1439
+ const rawLayout = props.layout && typeof props.layout === "object" && !Array.isArray(props.layout) ? props.layout : {};
1440
+ return {
1441
+ widthPct: toPositiveNumber((_a = rawLayout.widthPct) != null ? _a : props.__studioWidthPct),
1442
+ heightPct: toPositiveNumber((_b = rawLayout.heightPct) != null ? _b : props.__studioHeightPct),
1443
+ heightPx: toPositiveNumber((_c = rawLayout.heightPx) != null ? _c : props.__studioHeightPx),
1444
+ colSpan: toColSpan((_d = rawLayout.colSpan) != null ? _d : props.__studioColSpan),
1445
+ wrapperClassName: String(
1446
+ (_f = (_e = rawLayout.wrapperClassName) != null ? _e : props.__studioWrapperClassName) != null ? _f : ""
1447
+ ).trim(),
1448
+ cardSection: toCardSection((_g = rawLayout.cardSection) != null ? _g : props.__studioCardSection)
1449
+ };
1450
+ };
1451
+
1452
+ // src/studio-bridge/preview-form/previewFormState.ts
1453
+ var resolveStudioFormNextValues = ({
1454
+ formValues,
1455
+ fieldName,
1456
+ nextValue
1457
+ }) => __spreadProps(__spreadValues({}, formValues), {
1458
+ [fieldName]: nextValue
1459
+ });
1460
+ var resolveStudioFormResetValues = (normalizedFormFields) => normalizedFormFields.reduce((accumulator, field) => {
1461
+ var _a, _b;
1462
+ const fieldName = String((_a = field.name) != null ? _a : "").trim();
1463
+ if (!fieldName) return accumulator;
1464
+ accumulator[fieldName] = (_b = field.defaultValue) != null ? _b : "";
1465
+ return accumulator;
1466
+ }, {});
1467
+ var patchStudioFormFieldNode = ({
1468
+ child,
1469
+ formValues,
1470
+ formErrors,
1471
+ formDict,
1472
+ formLoaderType,
1473
+ fieldOnChange
1474
+ }) => {
1475
+ var _a, _b, _c;
1476
+ const rawChildProps = (_a = child.props) != null ? _a : {};
1477
+ const childLayout = readNodeLayout(rawChildProps);
1478
+ const rawLayout = rawChildProps.layout && typeof rawChildProps.layout === "object" && !Array.isArray(rawChildProps.layout) ? __spreadValues({}, rawChildProps.layout) : {};
1479
+ const existingWrapperClassName = String((_b = rawLayout.wrapperClassName) != null ? _b : "").trim();
1480
+ rawLayout.wrapperClassName = [existingWrapperClassName, "w-full", "max-w-full"].filter(Boolean).join(" ");
1481
+ delete rawLayout.widthPct;
1482
+ delete rawLayout.heightPct;
1483
+ delete rawLayout.heightPx;
1484
+ const fieldBasis = childLayout.widthPct !== null ? `${childLayout.widthPct}%` : "100%";
1485
+ const nestedField = rawChildProps.field && typeof rawChildProps.field === "object" && !Array.isArray(rawChildProps.field) ? rawChildProps.field : {};
1486
+ const fieldConfig = buildFormFieldConfig(rawChildProps, nestedField);
1487
+ const fieldName = String((_c = fieldConfig.name) != null ? _c : "").trim();
1488
+ const value = fieldName && fieldName in formValues ? formValues[fieldName] : rawChildProps.defaultValue;
1489
+ const patchedFieldNode = __spreadProps(__spreadValues({}, child), {
1490
+ props: __spreadValues(__spreadProps(__spreadValues({}, rawChildProps), {
1491
+ layout: rawLayout,
1492
+ field: fieldConfig,
1493
+ value,
1494
+ error: fieldName ? formErrors[fieldName] : void 0,
1495
+ onChange: fieldOnChange,
1496
+ dict: formDict
1497
+ }), formLoaderType !== void 0 ? { loaderType: formLoaderType } : {})
1498
+ });
1499
+ return {
1500
+ patchedFieldNode,
1501
+ fieldBasis
1502
+ };
1503
+ };
1504
+
1505
+ // src/studio-bridge/preview-form/previewFormStructure.ts
1506
+ var DEFAULT_FORM_DICT = {
1507
+ submit: "Submit",
1508
+ reset: "Reset",
1509
+ loading: "Loading...",
1510
+ success: "Saved",
1511
+ search: "Search...",
1512
+ noResultToShow: "No result"
1513
+ };
1514
+ var resolveStudioFormStructure = ({
1515
+ componentProps,
1516
+ visibleChildren
1517
+ }) => {
1518
+ const normalizedChildren = visibleChildren.map((child) => normalizeStudioFormChild(child));
1519
+ const titleNode = normalizedChildren.find((child) => getStudioFormChildRole(child) === "title");
1520
+ const fieldNodes = normalizedChildren.filter((child) => getStudioFormChildRole(child) === "field");
1521
+ const submitNode = normalizedChildren.find((child) => getStudioFormChildRole(child) === "submit");
1522
+ const resetNode = normalizedChildren.find((child) => getStudioFormChildRole(child) === "reset");
1523
+ const externalChildren = normalizedChildren.filter((child) => {
1524
+ const role = getStudioFormChildRole(child);
1525
+ return role !== "title" && role !== "field" && role !== "submit" && role !== "reset";
1526
+ });
1527
+ const formValues = componentProps.values && typeof componentProps.values === "object" && !Array.isArray(componentProps.values) ? componentProps.values : {};
1528
+ const formErrors = componentProps.errors && typeof componentProps.errors === "object" && !Array.isArray(componentProps.errors) ? componentProps.errors : {};
1529
+ const formDict = componentProps.dict && typeof componentProps.dict === "object" && !Array.isArray(componentProps.dict) ? componentProps.dict : DEFAULT_FORM_DICT;
1530
+ const normalizedFormFields = fieldNodes.map((child) => {
1531
+ var _a;
1532
+ const rawChildProps = (_a = child.props) != null ? _a : {};
1533
+ const nestedField = rawChildProps.field && typeof rawChildProps.field === "object" && !Array.isArray(rawChildProps.field) ? rawChildProps.field : {};
1534
+ return buildFormFieldConfig(rawChildProps, nestedField);
1535
+ }).filter((field) => {
1536
+ var _a;
1537
+ return String((_a = field.name) != null ? _a : "").trim().length > 0;
1538
+ });
1539
+ return {
1540
+ normalizedChildren,
1541
+ titleNode,
1542
+ fieldNodes,
1543
+ submitNode,
1544
+ resetNode,
1545
+ externalChildren,
1546
+ normalizedFormFields,
1547
+ formValues,
1548
+ formErrors,
1549
+ formDict,
1550
+ formLoaderType: componentProps.loaderType
1551
+ };
1552
+ };
1553
+
1554
+ // src/studio-bridge/preview-form/previewFormRenderer.tsx
1555
+ import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
1556
+ var materializePreviewForm = ({
1557
+ node,
1558
+ componentProps,
1559
+ visibleChildren,
1560
+ runtime,
1561
+ onInlineTextEdit,
1562
+ captureFieldFocus,
1563
+ renderSafeNode: renderSafeNode2
1564
+ }) => {
1565
+ var _a, _b, _c, _d, _e, _f, _g;
1566
+ const {
1567
+ titleNode,
1568
+ fieldNodes,
1569
+ submitNode,
1570
+ resetNode,
1571
+ externalChildren,
1572
+ normalizedFormFields,
1573
+ formValues,
1574
+ formErrors,
1575
+ formDict,
1576
+ formLoaderType
1577
+ } = resolveStudioFormStructure({
1578
+ componentProps,
1579
+ visibleChildren
1580
+ });
1581
+ if (!(fieldNodes.length > 0 || titleNode || submitNode || resetNode)) {
1582
+ return null;
1583
+ }
1584
+ const validateAndSetErrors = (nextValues) => {
1585
+ const validation = validateFormValues(normalizedFormFields, nextValues, {
1586
+ t: runtime.t,
1587
+ useLegacyFieldConstraints: true
1588
+ });
1589
+ onInlineTextEdit == null ? void 0 : onInlineTextEdit(node.id, "errors", validation.errors);
1590
+ return validation;
1591
+ };
1592
+ const fieldOnChange = (event) => {
1593
+ var _a2;
1594
+ captureFieldFocus(event.target);
1595
+ const fieldName = String((_a2 = event.target.name) != null ? _a2 : "").trim();
1596
+ if (!fieldName) return;
1597
+ const target = event.target;
1598
+ const nextValue = target.type === "checkbox" ? Boolean(target.checked) : event.target.value;
1599
+ const nextValues = resolveStudioFormNextValues({
1600
+ formValues,
1601
+ fieldName,
1602
+ nextValue
1603
+ });
1604
+ onInlineTextEdit == null ? void 0 : onInlineTextEdit(node.id, "values", nextValues);
1605
+ validateAndSetErrors(nextValues);
1606
+ };
1607
+ const openInlineEditorForFormDictProp = (propName, fallbackValue) => {
1608
+ onInlineTextEdit == null ? void 0 : onInlineTextEdit(node.id, propName, fallbackValue);
1609
+ };
1610
+ const openInlineEditorForFormNodeProp = (targetNodeId, fallbackValue) => {
1611
+ onInlineTextEdit == null ? void 0 : onInlineTextEdit(targetNodeId, "children", fallbackValue);
1612
+ };
1613
+ return /* @__PURE__ */ jsxs2("div", { className: "mx-auto mt-10 w-full min-w-0 rounded-2xl border border-border bg-background p-6 shadow-sm", children: [
1614
+ titleNode ? /* @__PURE__ */ jsx5("div", { className: "mb-6 text-center", children: renderSafeNode2(__spreadProps(__spreadValues({}, titleNode), {
1615
+ type: "H3",
1616
+ props: __spreadProps(__spreadValues({}, (_a = titleNode.props) != null ? _a : {}), {
1617
+ className: "text-center text-2xl font-semibold text-foreground",
1618
+ layout: __spreadProps(__spreadValues({}, getLayoutRecord(
1619
+ (_b = titleNode.props) != null ? _b : {}
1620
+ )), {
1621
+ formRole: "title"
1622
+ })
1623
+ })
1624
+ })) }) : /* @__PURE__ */ jsx5("h3", { className: "mb-6 text-center text-2xl font-semibold text-foreground", children: String((_c = componentProps.title) != null ? _c : "Form") }),
1625
+ /* @__PURE__ */ jsxs2(
1626
+ "form",
1627
+ {
1628
+ className: "flex flex-wrap items-start gap-x-3 gap-y-3",
1629
+ role: "form",
1630
+ onSubmit: (event) => {
1631
+ event.preventDefault();
1632
+ const validation = validateAndSetErrors(formValues);
1633
+ if (Object.keys(validation.errors).length > 0) return;
1634
+ },
1635
+ children: [
1636
+ fieldNodes.map((child) => {
1637
+ const { patchedFieldNode, fieldBasis } = patchStudioFormFieldNode({
1638
+ child,
1639
+ formValues,
1640
+ formErrors,
1641
+ formDict,
1642
+ formLoaderType,
1643
+ fieldOnChange
1644
+ });
1645
+ return /* @__PURE__ */ jsx5("div", { className: "contents", children: /* @__PURE__ */ jsx5("div", { style: { flex: `0 0 ${fieldBasis}`, maxWidth: fieldBasis }, children: /* @__PURE__ */ jsx5("div", { className: "min-w-0", children: renderSafeNode2(patchedFieldNode) }) }) }, child.id);
1646
+ }),
1647
+ submitNode || resetNode ? /* @__PURE__ */ jsxs2("div", { className: "basis-full flex flex-wrap justify-end gap-3 py-4", children: [
1648
+ submitNode ? renderSafeNode2(__spreadProps(__spreadValues({}, submitNode), {
1649
+ props: __spreadProps(__spreadValues({}, (_d = submitNode.props) != null ? _d : {}), {
1650
+ type: "submit",
1651
+ onDoubleClick: (event) => {
1652
+ var _a2, _b2, _c2;
1653
+ event.preventDefault();
1654
+ event.stopPropagation();
1655
+ openInlineEditorForFormNodeProp(
1656
+ submitNode.id,
1657
+ String(
1658
+ (_c2 = (_b2 = (_a2 = submitNode.props) == null ? void 0 : _a2.children) != null ? _b2 : formDict.submit) != null ? _c2 : "Submit"
1659
+ )
1660
+ );
1661
+ }
1662
+ })
1663
+ })) : null,
1664
+ resetNode ? renderSafeNode2(__spreadProps(__spreadValues({}, resetNode), {
1665
+ props: __spreadProps(__spreadValues({}, (_e = resetNode.props) != null ? _e : {}), {
1666
+ type: "button",
1667
+ onClick: () => {
1668
+ const resetValues = resolveStudioFormResetValues(normalizedFormFields);
1669
+ onInlineTextEdit == null ? void 0 : onInlineTextEdit(node.id, "values", resetValues);
1670
+ onInlineTextEdit == null ? void 0 : onInlineTextEdit(node.id, "errors", {});
1671
+ },
1672
+ onDoubleClick: (event) => {
1673
+ var _a2, _b2, _c2;
1674
+ event.preventDefault();
1675
+ event.stopPropagation();
1676
+ openInlineEditorForFormNodeProp(
1677
+ resetNode.id,
1678
+ String(
1679
+ (_c2 = (_b2 = (_a2 = resetNode.props) == null ? void 0 : _a2.children) != null ? _b2 : formDict.reset) != null ? _c2 : "Reset"
1680
+ )
1681
+ );
1682
+ }
1683
+ })
1684
+ })) : null
1685
+ ] }) : componentProps.onSubmit || componentProps.onReset ? /* @__PURE__ */ jsxs2("div", { className: "basis-full flex flex-wrap justify-end gap-3 py-4", children: [
1686
+ componentProps.onSubmit ? /* @__PURE__ */ jsx5(
1687
+ "button",
1688
+ {
1689
+ type: "submit",
1690
+ className: "inline-flex items-center justify-center rounded-md border border-primary bg-primary px-4 py-2 text-sm font-medium text-primary-foreground",
1691
+ onDoubleClick: (event) => {
1692
+ var _a2;
1693
+ event.preventDefault();
1694
+ event.stopPropagation();
1695
+ openInlineEditorForFormDictProp("dict.submit", String((_a2 = formDict.submit) != null ? _a2 : "Submit"));
1696
+ },
1697
+ children: String((_f = formDict.submit) != null ? _f : "Submit")
1698
+ }
1699
+ ) : null,
1700
+ componentProps.onReset ? /* @__PURE__ */ jsx5(
1701
+ "button",
1702
+ {
1703
+ type: "button",
1704
+ className: "inline-flex items-center justify-center rounded-md border border-border bg-background px-4 py-2 text-sm font-medium text-foreground",
1705
+ onClick: () => {
1706
+ const resetValues = resolveStudioFormResetValues(normalizedFormFields);
1707
+ onInlineTextEdit == null ? void 0 : onInlineTextEdit(node.id, "values", resetValues);
1708
+ onInlineTextEdit == null ? void 0 : onInlineTextEdit(node.id, "errors", {});
1709
+ },
1710
+ onDoubleClick: (event) => {
1711
+ var _a2;
1712
+ event.preventDefault();
1713
+ event.stopPropagation();
1714
+ openInlineEditorForFormDictProp("dict.reset", String((_a2 = formDict.reset) != null ? _a2 : "Reset"));
1715
+ },
1716
+ children: String((_g = formDict.reset) != null ? _g : "Reset")
1717
+ }
1718
+ ) : null
1719
+ ] }) : null,
1720
+ externalChildren.map((child) => /* @__PURE__ */ jsx5(React.Fragment, { children: renderSafeNode2(child) }, child.id))
1721
+ ]
1722
+ }
1723
+ )
1724
+ ] });
1725
+ };
1726
+
1727
+ // src/utils/navigationStudio.tsx
1728
+ import {
1729
+ buildAccordionItems,
1730
+ buildExpandablePanelChildren
1731
+ } from "@arkcit/engine-react";
1732
+
1733
+ // src/runtime/bindings.ts
1734
+ var DANGEROUS_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
1735
+ var MISSING_TRANSLATION_FALLBACK = "Lorem ipsum dolor sit amet. (fallback)";
1736
+ var MISSING_REF_FALLBACK = "Lorem ipsum dolor sit amet. (fallback)";
1737
+ var isPlainObject = (value) => {
1738
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
1739
+ const prototype = Object.getPrototypeOf(value);
1740
+ return prototype === Object.prototype || prototype === null;
1741
+ };
1742
+ var isReactElementLike = (value) => isPlainObject(value) && typeof value.$$typeof === "symbol" && "props" in value;
1743
+ var isTranslationValue = (value) => isPlainObject(value) && typeof value.$t === "string";
1744
+ var isRefValue = (value) => isPlainObject(value) && typeof value.$ref === "string";
1745
+ var isExprValue = (value) => isPlainObject(value) && typeof value.$expr === "string";
1746
+ var parseStructuredString = (value) => {
1747
+ if (typeof value !== "string") return value;
1748
+ const trimmed = value.trim();
1749
+ if (!trimmed.startsWith("{") || !trimmed.endsWith("}")) return value;
1750
+ try {
1751
+ const parsed = JSON.parse(trimmed);
1752
+ if (!isPlainObject(parsed)) return value;
1753
+ if ((typeof parsed.$ref === "string" || typeof parsed.$t === "string") && Object.keys(parsed).length >= 1) {
1754
+ return parsed;
1755
+ }
1756
+ return value;
1757
+ } catch (e) {
1758
+ return value;
1759
+ }
1760
+ };
1761
+ var resolveUIValue = (value, runtime) => {
1762
+ const normalizedValue = parseStructuredString(value);
1763
+ if (isTranslationValue(normalizedValue)) {
1764
+ const fallback = typeof normalizedValue.defaultValue === "string" && normalizedValue.defaultValue.trim() ? normalizedValue.defaultValue : normalizedValue.$t;
1765
+ if (!runtime.t) return fallback || MISSING_TRANSLATION_FALLBACK;
1766
+ const translated = runtime.t(normalizedValue.$t, normalizedValue.values);
1767
+ if (typeof translated !== "string") return fallback || MISSING_TRANSLATION_FALLBACK;
1768
+ if (!translated.trim()) return fallback || MISSING_TRANSLATION_FALLBACK;
1769
+ if (translated === normalizedValue.$t) return fallback || MISSING_TRANSLATION_FALLBACK;
1770
+ return translated;
1771
+ }
1772
+ if (isRefValue(normalizedValue)) {
1773
+ const resolved = runtime.get(normalizedValue.$ref);
1774
+ if (resolved == null) return MISSING_REF_FALLBACK;
1775
+ if (typeof resolved === "string" && !resolved.trim()) return MISSING_REF_FALLBACK;
1776
+ return resolved;
1777
+ }
1778
+ if (isExprValue(normalizedValue)) {
1779
+ return void 0;
1780
+ }
1781
+ if (Array.isArray(normalizedValue)) {
1782
+ return normalizedValue.map((item) => resolveUIValue(item, runtime));
1783
+ }
1784
+ if (isReactElementLike(normalizedValue)) {
1785
+ return normalizedValue;
1786
+ }
1787
+ if (isPlainObject(normalizedValue)) {
1788
+ const next = {};
1789
+ Object.entries(normalizedValue).forEach(([key, childValue]) => {
1790
+ if (DANGEROUS_KEYS.has(key)) return;
1791
+ next[key] = resolveUIValue(childValue, runtime);
1792
+ });
1793
+ return next;
1794
+ }
1795
+ return normalizedValue;
1796
+ };
1797
+
1798
+ // src/studio-bridge/preview-navigation/previewTabs.ts
1799
+ var normalizeStudioTabsProps = (props) => {
1800
+ var _a;
1801
+ const rawTabs = Array.isArray(props.tabs) ? props.tabs : [];
1802
+ const tabs = rawTabs.length ? rawTabs.map((tab, index) => {
1803
+ var _a2, _b, _c;
1804
+ const rawTab = tab && typeof tab === "object" && !Array.isArray(tab) ? tab : {};
1805
+ const id = String((_a2 = rawTab.id) != null ? _a2 : `tab-${index + 1}`);
1806
+ const title = (_c = (_b = rawTab.title) != null ? _b : rawTab.label) != null ? _c : `Tab ${index + 1}`;
1807
+ return __spreadProps(__spreadValues({}, rawTab), {
1808
+ id,
1809
+ title,
1810
+ label: title
1811
+ });
1812
+ }) : [
1813
+ {
1814
+ id: "overview",
1815
+ title: "Overview",
1816
+ label: "Overview",
1817
+ content: "Overview content"
1818
+ }
1819
+ ];
1820
+ const rawDict = props.dict && typeof props.dict === "object" && !Array.isArray(props.dict) ? props.dict : {};
1821
+ const rawUrlSync = props.urlSync && typeof props.urlSync === "object" && !Array.isArray(props.urlSync) ? props.urlSync : null;
1822
+ const rawNavigation = (rawUrlSync == null ? void 0 : rawUrlSync.navigation) && typeof rawUrlSync.navigation === "object" && !Array.isArray(rawUrlSync.navigation) ? rawUrlSync.navigation : null;
1823
+ const normalizedUrlSync = rawNavigation && typeof rawNavigation.getSearch === "function" && typeof rawNavigation.replaceSearch === "function" ? __spreadProps(__spreadValues({}, rawUrlSync), {
1824
+ navigation: rawNavigation
1825
+ }) : void 0;
1826
+ return __spreadProps(__spreadValues({}, props), {
1827
+ tabs,
1828
+ dict: __spreadProps(__spreadValues({}, rawDict), {
1829
+ noContentYet: typeof rawDict.noContentYet === "string" && rawDict.noContentYet.trim().length > 0 ? rawDict.noContentYet : "No content yet"
1830
+ }),
1831
+ defaultActive: typeof props.defaultActive === "string" && props.defaultActive.trim().length > 0 ? props.defaultActive : String((_a = tabs[0].id) != null ? _a : "overview"),
1832
+ keepMounted: typeof props.keepMounted === "boolean" ? props.keepMounted : true,
1833
+ urlSync: normalizedUrlSync
1834
+ });
1835
+ };
1836
+ var resolveStudioTabsContent = ({
1837
+ tabItems,
1838
+ rawChildren,
1839
+ runtime,
1840
+ renderChild,
1841
+ normalizeRenderableChild: normalizeRenderableChild2
1842
+ }) => {
1843
+ const childrenByTabId = /* @__PURE__ */ new Map();
1844
+ const unassignedChildren = [];
1845
+ rawChildren.forEach((child) => {
1846
+ var _a, _b, _c;
1847
+ const childProps = (_a = child.props) != null ? _a : {};
1848
+ const rawLayout = childProps.layout && typeof childProps.layout === "object" && !Array.isArray(childProps.layout) ? childProps.layout : {};
1849
+ const tabIdFromLayout = (_b = rawLayout.tabId) != null ? _b : childProps.__studioTabId;
1850
+ const resolvedTabId = resolveUIValue(tabIdFromLayout, runtime);
1851
+ const normalizedTabId = String(resolvedTabId != null ? resolvedTabId : "").trim();
1852
+ if (!normalizedTabId) {
1853
+ unassignedChildren.push(child);
1854
+ return;
1855
+ }
1856
+ const existing = (_c = childrenByTabId.get(normalizedTabId)) != null ? _c : [];
1857
+ existing.push(child);
1858
+ childrenByTabId.set(normalizedTabId, existing);
1859
+ });
1860
+ return tabItems.map((item, index) => {
1861
+ var _a, _b, _c, _d;
1862
+ const rawId = (_a = item.id) != null ? _a : `tab-${index + 1}`;
1863
+ const resolvedId = resolveUIValue(rawId, runtime);
1864
+ const normalizedId = String(
1865
+ resolvedId == null || String(resolvedId).trim().length === 0 ? rawId : resolvedId
1866
+ );
1867
+ const rawTitle = (_b = item.title) != null ? _b : item.label;
1868
+ const resolvedTitle = resolveUIValue(rawTitle, runtime);
1869
+ const normalizedTitle = (_c = resolvedTitle != null ? resolvedTitle : rawTitle) != null ? _c : `Tab ${index + 1}`;
1870
+ const mappedChildren = (_d = childrenByTabId.get(normalizedId)) != null ? _d : [];
1871
+ const fallbackChildren = index === 0 ? unassignedChildren : [];
1872
+ const contentNodes = [...mappedChildren, ...fallbackChildren];
1873
+ const contentFromChildren = contentNodes.length > 0 ? contentNodes.length === 1 ? renderChild(contentNodes[0]) : contentNodes.map((child) => renderChild(child)) : null;
1874
+ return __spreadProps(__spreadValues({}, item), {
1875
+ id: normalizedId,
1876
+ title: normalizedTitle,
1877
+ label: normalizedTitle,
1878
+ content: contentFromChildren != null ? contentFromChildren : normalizeRenderableChild2(item.content)
1879
+ });
1880
+ });
1881
+ };
1882
+ var resolveStudioTabsProps = ({
1883
+ componentProps,
1884
+ tabItems,
1885
+ rawChildren,
1886
+ runtime,
1887
+ renderChild,
1888
+ normalizeRenderableChild: normalizeRenderableChild2
1889
+ }) => {
1890
+ const normalizedProps = normalizeStudioTabsProps(componentProps);
1891
+ const resolvedTabs = resolveStudioTabsContent({
1892
+ tabItems: Array.isArray(normalizedProps.tabs) ? normalizedProps.tabs : tabItems,
1893
+ rawChildren,
1894
+ runtime,
1895
+ renderChild,
1896
+ normalizeRenderableChild: normalizeRenderableChild2
1897
+ });
1898
+ return {
1899
+ normalizedProps,
1900
+ resolvedTabs
1901
+ };
1902
+ };
1903
+
1904
+ // src/studio-bridge/preview-navigation/previewNavigationState.ts
1905
+ var findContainingNodeId = (targetNodeId, candidates, idResolver) => {
1906
+ const containsNode = (candidate) => {
1907
+ var _a;
1908
+ if (candidate.id === targetNodeId) return true;
1909
+ return ((_a = candidate.children) != null ? _a : []).some((nested) => containsNode(nested));
1910
+ };
1911
+ for (const candidate of candidates) {
1912
+ if (containsNode(candidate)) {
1913
+ return idResolver(candidate);
1914
+ }
1915
+ }
1916
+ return null;
1917
+ };
1918
+ var resolveAccordionOpenIds = ({
1919
+ itemIds,
1920
+ persistedOpenIds,
1921
+ selectedItemId,
1922
+ allowMultiple
1923
+ }) => {
1924
+ let effectiveOpenIds = persistedOpenIds.filter((id) => itemIds.includes(id));
1925
+ if (selectedItemId) {
1926
+ effectiveOpenIds = allowMultiple ? Array.from(/* @__PURE__ */ new Set([...effectiveOpenIds, selectedItemId])) : [selectedItemId];
1927
+ } else if (effectiveOpenIds.length === 0 && itemIds[0]) {
1928
+ effectiveOpenIds = [itemIds[0]];
1929
+ }
1930
+ return effectiveOpenIds;
1931
+ };
1932
+ var resolveStudioAccordionState = ({
1933
+ nodeId,
1934
+ accordionChildren,
1935
+ itemIds,
1936
+ selectedNodeId,
1937
+ accordionOpenIdsByNodeId,
1938
+ allowMultiple
1939
+ }) => {
1940
+ var _a;
1941
+ const validItemIds = new Set(itemIds);
1942
+ const persistedOpenIds = ((_a = accordionOpenIdsByNodeId[nodeId]) != null ? _a : []).filter(
1943
+ (id) => validItemIds.has(id)
1944
+ );
1945
+ const selectedItemId = selectedNodeId != null ? findContainingNodeId(
1946
+ selectedNodeId,
1947
+ accordionChildren,
1948
+ (candidate) => {
1949
+ var _a2, _b;
1950
+ return String((_b = ((_a2 = candidate.props) != null ? _a2 : {}).id) != null ? _b : candidate.id);
1951
+ }
1952
+ ) : null;
1953
+ const effectiveOpenIds = resolveAccordionOpenIds({
1954
+ itemIds,
1955
+ persistedOpenIds,
1956
+ selectedItemId,
1957
+ allowMultiple
1958
+ });
1959
+ return {
1960
+ validItemIds,
1961
+ effectiveOpenIds
1962
+ };
1963
+ };
1964
+ var resolveStudioExpandablePanelState = ({
1965
+ nodeId,
1966
+ expandablePanelOpenByNodeId
1967
+ }) => {
1968
+ var _a;
1969
+ return {
1970
+ controlledOpen: (_a = expandablePanelOpenByNodeId[nodeId]) != null ? _a : true,
1971
+ defaultOpen: true,
1972
+ disableAnimation: true
1973
+ };
1974
+ };
1975
+
1976
+ // src/studio-bridge/preview-navigation/previewNavigationConfigurators.tsx
1977
+ var configurePreviewAccordion = ({
1978
+ node,
1979
+ componentProps,
1980
+ accordionChildren,
1981
+ selectedNodeId,
1982
+ accordionOpenIdsByNodeId,
1983
+ setAccordionOpenIdsByNodeId,
1984
+ renderSafeNode: renderSafeNode2
1985
+ }) => {
1986
+ const items = buildAccordionItems(accordionChildren, renderSafeNode2);
1987
+ componentProps.items = items;
1988
+ const { validItemIds, effectiveOpenIds } = resolveStudioAccordionState({
1989
+ nodeId: node.id,
1990
+ accordionChildren,
1991
+ itemIds: items.map((item) => item.id),
1992
+ selectedNodeId,
1993
+ accordionOpenIdsByNodeId,
1994
+ allowMultiple: Boolean(componentProps.allowMultiple)
1995
+ });
1996
+ componentProps.openIds = effectiveOpenIds;
1997
+ componentProps.defaultOpenIds = effectiveOpenIds;
1998
+ componentProps.onOpenIdsChange = (nextOpenIds) => {
1999
+ setAccordionOpenIdsByNodeId((previous) => __spreadProps(__spreadValues({}, previous), {
2000
+ [node.id]: nextOpenIds.filter((id) => validItemIds.has(id))
2001
+ }));
2002
+ };
2003
+ };
2004
+ var configurePreviewExpandablePanel = ({
2005
+ node,
2006
+ componentProps,
2007
+ panelChildren,
2008
+ expandablePanelOpenByNodeId,
2009
+ setExpandablePanelOpenByNodeId,
2010
+ renderSafeNode: renderSafeNode2
2011
+ }) => {
2012
+ const { controlledOpen, defaultOpen, disableAnimation } = resolveStudioExpandablePanelState({
2013
+ nodeId: node.id,
2014
+ expandablePanelOpenByNodeId
2015
+ });
2016
+ componentProps.open = controlledOpen;
2017
+ componentProps.defaultOpen = defaultOpen;
2018
+ componentProps.disableAnimation = disableAnimation;
2019
+ componentProps.onOpenChange = (nextOpen) => {
2020
+ setExpandablePanelOpenByNodeId((previous) => __spreadProps(__spreadValues({}, previous), {
2021
+ [node.id]: Boolean(nextOpen)
2022
+ }));
2023
+ };
2024
+ const panelContent = buildExpandablePanelChildren(panelChildren, renderSafeNode2);
2025
+ if (panelContent) {
2026
+ componentProps.children = panelContent;
2027
+ }
2028
+ };
2029
+ var configurePreviewTabs = ({
2030
+ componentProps,
2031
+ tabItems,
2032
+ rawChildren,
2033
+ runtime,
2034
+ renderSafeNode: renderSafeNode2,
2035
+ normalizeRenderableChild: normalizeRenderableChild2
2036
+ }) => {
2037
+ const { normalizedProps, resolvedTabs } = resolveStudioTabsProps({
2038
+ componentProps,
2039
+ tabItems,
2040
+ rawChildren,
2041
+ runtime,
2042
+ renderChild: renderSafeNode2,
2043
+ normalizeRenderableChild: normalizeRenderableChild2
2044
+ });
2045
+ Object.assign(componentProps, normalizedProps);
2046
+ componentProps.tabs = resolvedTabs;
2047
+ delete componentProps.children;
2048
+ };
2049
+
2050
+ // src/studio-bridge/preview-wizard/previewWizardMaterialization.ts
2051
+ import React2 from "react";
2052
+
2053
+ // src/studio-bridge/preview-wizard/previewWizardFormState.ts
2054
+ var resolveStudioWizardNextValues = ({
2055
+ rawWizardValues,
2056
+ fieldName,
2057
+ nextValue
2058
+ }) => __spreadProps(__spreadValues({}, rawWizardValues), {
2059
+ [fieldName]: nextValue
2060
+ });
2061
+ var resolveStudioWizardActiveStepFields = ({
2062
+ stepId,
2063
+ stepIdToNode
2064
+ }) => {
2065
+ var _a;
2066
+ const activeStepNode = stepIdToNode[stepId];
2067
+ return ((_a = activeStepNode == null ? void 0 : activeStepNode.children) != null ? _a : []).filter((child) => child.type === "FormField").map((child) => {
2068
+ var _a2;
2069
+ const childProps = (_a2 = child.props) != null ? _a2 : {};
2070
+ const childFieldObj = childProps.field && typeof childProps.field === "object" && !Array.isArray(childProps.field) ? childProps.field : {};
2071
+ return buildWizardFieldConfig(childProps, childFieldObj);
2072
+ }).filter((field) => {
2073
+ var _a2;
2074
+ return String((_a2 = field.name) != null ? _a2 : "").trim().length > 0;
2075
+ });
2076
+ };
2077
+ var resolveStudioWizardNextErrors = ({
2078
+ currentWizardErrors,
2079
+ activeStepFields,
2080
+ nextValues,
2081
+ runtime
2082
+ }) => {
2083
+ const validation = validateFormValues(activeStepFields, nextValues, {
2084
+ t: runtime.t,
2085
+ useLegacyFieldConstraints: true
2086
+ });
2087
+ const activeStepFieldNames = new Set(
2088
+ activeStepFields.map((field) => {
2089
+ var _a;
2090
+ return String((_a = field.name) != null ? _a : "").trim();
2091
+ }).filter(Boolean)
2092
+ );
2093
+ const nextErrors = Object.entries(currentWizardErrors).reduce(
2094
+ (accumulator, [key, value]) => {
2095
+ if (activeStepFieldNames.has(key)) return accumulator;
2096
+ accumulator[key] = value;
2097
+ return accumulator;
2098
+ },
2099
+ {}
2100
+ );
2101
+ Object.entries(validation.errors).forEach(([key, value]) => {
2102
+ if (!value) return;
2103
+ nextErrors[key] = value;
2104
+ });
2105
+ return nextErrors;
2106
+ };
2107
+ var patchStudioWizardFieldNode = ({
2108
+ nested,
2109
+ rawWizardValues,
2110
+ currentWizardErrors,
2111
+ fieldOnChange
2112
+ }) => {
2113
+ var _a, _b, _c, _d, _e;
2114
+ const nestedProps = (_a = nested.props) != null ? _a : {};
2115
+ const fieldObj = nestedProps.field && typeof nestedProps.field === "object" && !Array.isArray(nestedProps.field) ? nestedProps.field : {};
2116
+ const fieldName = String((_c = (_b = nestedProps.name) != null ? _b : fieldObj.name) != null ? _c : "").trim();
2117
+ const fieldConfig = __spreadProps(__spreadValues(__spreadValues({}, fieldObj), nestedProps), {
2118
+ name: fieldName,
2119
+ label: String((_e = (_d = nestedProps.label) != null ? _d : fieldObj.label) != null ? _e : fieldName || "Field")
2120
+ });
2121
+ const patchedNode = __spreadProps(__spreadValues({}, nested), {
2122
+ props: __spreadProps(__spreadValues({}, nestedProps), {
2123
+ layout: (() => {
2124
+ var _a2;
2125
+ const rawLayout = nestedProps.layout && typeof nestedProps.layout === "object" && !Array.isArray(nestedProps.layout) ? __spreadValues({}, nestedProps.layout) : {};
2126
+ const existingWrapperClassName = String((_a2 = rawLayout.wrapperClassName) != null ? _a2 : "").trim();
2127
+ rawLayout.wrapperClassName = [existingWrapperClassName, "w-full", "max-w-full"].filter(Boolean).join(" ");
2128
+ delete rawLayout.widthPct;
2129
+ delete rawLayout.heightPct;
2130
+ delete rawLayout.heightPx;
2131
+ return rawLayout;
2132
+ })(),
2133
+ field: fieldConfig,
2134
+ value: fieldName ? rawWizardValues[fieldName] : void 0,
2135
+ error: fieldName ? currentWizardErrors[fieldName] : void 0,
2136
+ onChange: fieldOnChange
2137
+ })
2138
+ });
2139
+ const nestedLayout = readNodeLayout(nestedProps);
2140
+ const fieldBasis = nestedLayout.widthPct !== null ? `${nestedLayout.widthPct}%` : "100%";
2141
+ return {
2142
+ patchedNode,
2143
+ fieldBasis
2144
+ };
2145
+ };
2146
+
2147
+ // src/studio-bridge/preview-wizard/previewWizardMaterialization.ts
2148
+ var renderStudioWizardStepContent = ({
2149
+ step,
2150
+ nodeId,
2151
+ existingFormConfig,
2152
+ rawWizardValues,
2153
+ stepIdToNode,
2154
+ runtime,
2155
+ renderSafeNode: renderSafeNode2,
2156
+ captureFieldFocus,
2157
+ onInlineTextEdit
2158
+ }) => {
2159
+ if (step.contentType === "content") {
2160
+ if (step.contentNode) {
2161
+ return renderSafeNode2(step.contentNode);
2162
+ }
2163
+ return step.contentValue;
2164
+ }
2165
+ if (step.stepRenderableContent.length === 0) {
2166
+ return step.contentValue;
2167
+ }
2168
+ return React2.createElement(
2169
+ "div",
2170
+ { className: "flex flex-wrap items-start gap-x-3 gap-y-3" },
2171
+ step.stepRenderableContent.map((nested) => {
2172
+ if (nested.type !== "FormField") {
2173
+ return React2.createElement(
2174
+ "div",
2175
+ { key: nested.id, className: "basis-full" },
2176
+ renderSafeNode2(nested)
2177
+ );
2178
+ }
2179
+ const currentWizardErrors = existingFormConfig.errors && typeof existingFormConfig.errors === "object" && !Array.isArray(existingFormConfig.errors) ? existingFormConfig.errors : {};
2180
+ const { patchedNode, fieldBasis } = patchStudioWizardFieldNode({
2181
+ nested,
2182
+ rawWizardValues,
2183
+ currentWizardErrors,
2184
+ fieldOnChange: (event) => {
2185
+ var _a;
2186
+ captureFieldFocus(event.target);
2187
+ const nextFieldName = String((_a = event.target.name) != null ? _a : "").trim();
2188
+ if (!nextFieldName) return;
2189
+ const target = event.target;
2190
+ const nextValue = target.type === "checkbox" ? Boolean(target.checked) : event.target.value;
2191
+ const nextValues = resolveStudioWizardNextValues({
2192
+ rawWizardValues,
2193
+ fieldName: nextFieldName,
2194
+ nextValue
2195
+ });
2196
+ const activeStepFields = resolveStudioWizardActiveStepFields({
2197
+ stepId: step.id,
2198
+ stepIdToNode
2199
+ });
2200
+ const nextErrors = resolveStudioWizardNextErrors({
2201
+ currentWizardErrors,
2202
+ activeStepFields,
2203
+ nextValues,
2204
+ runtime
2205
+ });
2206
+ onInlineTextEdit == null ? void 0 : onInlineTextEdit(nodeId, "form.values", nextValues);
2207
+ onInlineTextEdit == null ? void 0 : onInlineTextEdit(nodeId, "form.errors", nextErrors);
2208
+ }
2209
+ });
2210
+ return React2.createElement(
2211
+ "div",
2212
+ {
2213
+ key: nested.id,
2214
+ className: "min-w-0",
2215
+ style: { flex: `0 0 ${fieldBasis}`, maxWidth: fieldBasis }
2216
+ },
2217
+ renderSafeNode2(patchedNode)
2218
+ );
2219
+ })
2220
+ );
2221
+ };
2222
+ var materializeStudioWizardSteps = ({
2223
+ nodeId,
2224
+ currentSteps,
2225
+ existingFormConfig,
2226
+ rawWizardValues,
2227
+ stepIdToNode,
2228
+ runtime,
2229
+ renderSafeNode: renderSafeNode2,
2230
+ captureFieldFocus,
2231
+ onInlineTextEdit
2232
+ }) => currentSteps.map((step) => ({
2233
+ id: step.id,
2234
+ title: step.title,
2235
+ description: step.description,
2236
+ titleNode: step.titleNode ? renderSafeNode2(step.titleNode) : void 0,
2237
+ descriptionNode: step.descriptionNode ? renderSafeNode2(step.descriptionNode) : void 0,
2238
+ isValid: step.isValid,
2239
+ content: renderStudioWizardStepContent({
2240
+ step,
2241
+ nodeId,
2242
+ currentSteps,
2243
+ existingFormConfig,
2244
+ rawWizardValues,
2245
+ stepIdToNode,
2246
+ runtime,
2247
+ renderSafeNode: renderSafeNode2,
2248
+ captureFieldFocus,
2249
+ onInlineTextEdit
2250
+ })
2251
+ }));
2252
+
2253
+ // src/studio-bridge/preview-wizard/wizardEditingHandlers.ts
2254
+ var findWizardStepRoleNode = (stepNode, role) => {
2255
+ var _a;
2256
+ const nestedChildren = Array.isArray(stepNode.children) ? stepNode.children : [];
2257
+ return (_a = nestedChildren.find((child) => {
2258
+ var _a2, _b;
2259
+ const childProps = (_a2 = child.props) != null ? _a2 : {};
2260
+ return String((_b = getLayoutRecord(childProps).wizardStepRole) != null ? _b : "").trim() === role;
2261
+ })) != null ? _a : null;
2262
+ };
2263
+ var createStudioWizardOnStepChange = ({
2264
+ nodeId,
2265
+ stepIdToNode,
2266
+ setWizardActiveStepByNodeId,
2267
+ existingOnStepChange,
2268
+ onNodeClick
2269
+ }) => {
2270
+ return (stepId) => {
2271
+ setWizardActiveStepByNodeId((previous) => {
2272
+ if (previous[nodeId] === stepId) return previous;
2273
+ return __spreadProps(__spreadValues({}, previous), {
2274
+ [nodeId]: stepId
2275
+ });
2276
+ });
2277
+ if (typeof existingOnStepChange === "function") {
2278
+ existingOnStepChange(stepId);
2279
+ }
2280
+ const stepNode = stepIdToNode[stepId];
2281
+ if (stepNode && onNodeClick) {
2282
+ onNodeClick(stepNode.id);
2283
+ }
2284
+ };
2285
+ };
2286
+ var attachStudioWizardEditingHandlers = ({
2287
+ studioConfig,
2288
+ node,
2289
+ stepIdToNode,
2290
+ openInlineEditorForNodeProp
2291
+ }) => {
2292
+ studioConfig.onStepTitleDoubleClick = (stepId) => {
2293
+ var _a, _b, _c, _d, _e;
2294
+ const stepNode = stepIdToNode[stepId];
2295
+ if (!stepNode) return;
2296
+ const stepProps = (_a = stepNode.props) != null ? _a : {};
2297
+ const titleNode = findWizardStepRoleNode(stepNode, "title");
2298
+ if (titleNode) {
2299
+ const titleNodeProps = (_b = titleNode.props) != null ? _b : {};
2300
+ openInlineEditorForNodeProp(
2301
+ titleNode.id,
2302
+ "children",
2303
+ (_d = (_c = titleNodeProps.children) != null ? _c : stepProps.title) != null ? _d : stepId
2304
+ );
2305
+ return;
2306
+ }
2307
+ openInlineEditorForNodeProp(stepNode.id, "title", (_e = stepProps.title) != null ? _e : stepId);
2308
+ };
2309
+ studioConfig.onStepDescriptionDoubleClick = (stepId) => {
2310
+ var _a, _b, _c, _d, _e;
2311
+ const stepNode = stepIdToNode[stepId];
2312
+ if (!stepNode) return;
2313
+ const stepProps = (_a = stepNode.props) != null ? _a : {};
2314
+ const descriptionNode = findWizardStepRoleNode(stepNode, "description");
2315
+ if (descriptionNode) {
2316
+ const descriptionNodeProps = (_b = descriptionNode.props) != null ? _b : {};
2317
+ openInlineEditorForNodeProp(
2318
+ descriptionNode.id,
2319
+ "children",
2320
+ (_d = (_c = descriptionNodeProps.children) != null ? _c : stepProps.description) != null ? _d : ""
2321
+ );
2322
+ return;
2323
+ }
2324
+ openInlineEditorForNodeProp(stepNode.id, "description", (_e = stepProps.description) != null ? _e : "");
2325
+ };
2326
+ studioConfig.onBackLabelDoubleClick = () => {
2327
+ var _a, _b, _c;
2328
+ return openInlineEditorForNodeProp(
2329
+ node.id,
2330
+ "labels.back",
2331
+ (_c = (_b = (_a = node.props) == null ? void 0 : _a.labels) == null ? void 0 : _b.back) != null ? _c : "Back"
2332
+ );
2333
+ };
2334
+ studioConfig.onNextLabelDoubleClick = () => {
2335
+ var _a, _b, _c;
2336
+ return openInlineEditorForNodeProp(
2337
+ node.id,
2338
+ "labels.next",
2339
+ (_c = (_b = (_a = node.props) == null ? void 0 : _a.labels) == null ? void 0 : _b.next) != null ? _c : "Next"
2340
+ );
2341
+ };
2342
+ studioConfig.onFinishLabelDoubleClick = () => {
2343
+ var _a, _b, _c;
2344
+ return openInlineEditorForNodeProp(
2345
+ node.id,
2346
+ "labels.finish",
2347
+ (_c = (_b = (_a = node.props) == null ? void 0 : _a.labels) == null ? void 0 : _b.finish) != null ? _c : "Finish"
2348
+ );
2349
+ };
2350
+ return studioConfig;
2351
+ };
2352
+
2353
+ // src/utils/wizardStudio.ts
2354
+ var getWizardStepRole = (node) => {
2355
+ var _a, _b;
2356
+ const props = (_a = node.props) != null ? _a : {};
2357
+ const layout = getLayoutRecord(props);
2358
+ return String((_b = layout.wizardStepRole) != null ? _b : "").trim();
2359
+ };
2360
+ var getWizardRenderableChildren = (nodes) => nodes.filter((nested) => {
2361
+ const stepRole = getWizardStepRole(nested);
2362
+ return stepRole !== "title" && stepRole !== "description";
2363
+ });
2364
+ var findSelectedWizardStepId = (stepChildren, selectedNodeId) => {
2365
+ var _a, _b, _c;
2366
+ if (!selectedNodeId) return null;
2367
+ const selectedStep = stepChildren.find((stepChild) => {
2368
+ var _a2;
2369
+ if (stepChild.id === selectedNodeId) return true;
2370
+ return ((_a2 = stepChild.children) != null ? _a2 : []).some((nested) => {
2371
+ const stepRole = getWizardStepRole(nested);
2372
+ return nested.id === selectedNodeId && (stepRole === "title" || stepRole === "description");
2373
+ });
2374
+ });
2375
+ if (!selectedStep) return null;
2376
+ const stepProps = (_a = selectedStep.props) != null ? _a : {};
2377
+ return String((_c = (_b = stepProps.id) != null ? _b : selectedStep.id) != null ? _c : "").trim() || null;
2378
+ };
2379
+ var buildFieldsByStep = (stepIdToNode, currentSteps) => currentSteps.reduce((accumulator, step) => {
2380
+ var _a, _b;
2381
+ const stepId = String((_a = step.id) != null ? _a : "").trim();
2382
+ if (!stepId) return accumulator;
2383
+ const stepNode = stepIdToNode[stepId];
2384
+ const stepRenderableChildren = getWizardRenderableChildren((_b = stepNode == null ? void 0 : stepNode.children) != null ? _b : []);
2385
+ const fields = stepRenderableChildren.filter((nested) => nested.type === "FormField").map((nested) => {
2386
+ var _a2;
2387
+ const nestedProps = (_a2 = nested.props) != null ? _a2 : {};
2388
+ const nestedField = nestedProps.field && typeof nestedProps.field === "object" && !Array.isArray(nestedProps.field) ? nestedProps.field : {};
2389
+ return buildWizardFieldConfig(nestedProps, nestedField);
2390
+ }).filter((field) => {
2391
+ var _a2;
2392
+ return String((_a2 = field.name) != null ? _a2 : "").trim().length > 0;
2393
+ });
2394
+ accumulator[stepId] = fields;
2395
+ return accumulator;
2396
+ }, {});
2397
+ var resolveActiveWizardStepId = ({
2398
+ selectedStepId,
2399
+ stepIds,
2400
+ activeStepFromProps,
2401
+ activeStepFromMemory
2402
+ }) => {
2403
+ var _a;
2404
+ if (selectedStepId && stepIds.includes(selectedStepId)) return selectedStepId;
2405
+ if (activeStepFromProps && stepIds.includes(activeStepFromProps)) {
2406
+ return activeStepFromProps;
2407
+ }
2408
+ if (activeStepFromMemory && stepIds.includes(activeStepFromMemory)) {
2409
+ return activeStepFromMemory;
2410
+ }
2411
+ return (_a = stepIds[0]) != null ? _a : "";
2412
+ };
2413
+ var validateWizardStepFields = ({
2414
+ stepRenderableContent,
2415
+ values,
2416
+ runtime
2417
+ }) => {
2418
+ const normalizedFields = stepRenderableContent.filter((nested) => nested.type === "FormField").map((nested) => {
2419
+ var _a;
2420
+ const nestedProps = (_a = nested.props) != null ? _a : {};
2421
+ const fieldObject = nestedProps.field && typeof nestedProps.field === "object" && !Array.isArray(nestedProps.field) ? nestedProps.field : {};
2422
+ return buildWizardFieldConfig(nestedProps, fieldObject);
2423
+ });
2424
+ const filteredFields = normalizedFields.filter((field) => field.name.length > 0);
2425
+ const validation = validateFormValues(filteredFields, values, {
2426
+ t: runtime.t,
2427
+ useLegacyFieldConstraints: true
2428
+ });
2429
+ return validation.issues.length === 0;
2430
+ };
2431
+
2432
+ // src/studio-bridge/preview-wizard/previewWizardStructure.ts
2433
+ var resolveStudioWizardStructure = ({
2434
+ node,
2435
+ componentProps,
2436
+ selectedNodeId,
2437
+ wizardActiveStepByNodeId,
2438
+ runtime,
2439
+ internalStudioNodeTypes
2440
+ }) => {
2441
+ var _a, _b, _c, _d, _e, _f;
2442
+ const existingFormConfig = componentProps.form && typeof componentProps.form === "object" && !Array.isArray(componentProps.form) ? __spreadValues({}, componentProps.form) : {};
2443
+ const existingStudioConfig = componentProps.studio && typeof componentProps.studio === "object" && !Array.isArray(componentProps.studio) ? __spreadValues({}, componentProps.studio) : {};
2444
+ const stepChildren = ((_a = node.children) != null ? _a : []).filter((child) => {
2445
+ var _a2;
2446
+ const childProps = (_a2 = child.props) != null ? _a2 : {};
2447
+ const layout = getLayoutRecord(childProps);
2448
+ const isWizardStepFlag = layout.wizardStep === true;
2449
+ const isSupportedStepType = child.type === "Container" || child.type === "StepForm";
2450
+ return isSupportedStepType && isWizardStepFlag;
2451
+ });
2452
+ const stepIdToNode = stepChildren.reduce(
2453
+ (accumulator, stepChild) => {
2454
+ var _a2, _b2, _c2;
2455
+ const stepProps = (_a2 = stepChild.props) != null ? _a2 : {};
2456
+ const stepId = String((_b2 = stepProps.id) != null ? _b2 : "").trim();
2457
+ const fallbackId = String((_c2 = stepChild.id) != null ? _c2 : "").trim();
2458
+ if (stepId) accumulator[stepId] = stepChild;
2459
+ if (fallbackId) accumulator[fallbackId] = stepChild;
2460
+ return accumulator;
2461
+ },
2462
+ {}
2463
+ );
2464
+ const selectedStepId = findSelectedWizardStepId(stepChildren, selectedNodeId);
2465
+ const rawWizardValues = existingFormConfig.values && typeof existingFormConfig.values === "object" && !Array.isArray(existingFormConfig.values) ? existingFormConfig.values : {};
2466
+ const currentSteps = stepChildren.map((stepChild) => {
2467
+ var _a2, _b2, _c2, _d2, _e2, _f2, _g, _h, _i, _j, _k;
2468
+ const stepProps = (_a2 = stepChild.props) != null ? _a2 : {};
2469
+ const stepId = String((_b2 = stepProps.id) != null ? _b2 : "").trim() || stepChild.id;
2470
+ const stepContent = ((_c2 = stepChild.children) != null ? _c2 : []).filter(
2471
+ (nested) => !internalStudioNodeTypes.has(nested.type)
2472
+ );
2473
+ const stepTitleNode = stepContent.find(
2474
+ (nested) => {
2475
+ var _a3, _b3;
2476
+ return String(
2477
+ (_b3 = getLayoutRecord((_a3 = nested.props) != null ? _a3 : {}).wizardStepRole) != null ? _b3 : ""
2478
+ ).trim() === "title";
2479
+ }
2480
+ );
2481
+ const stepDescriptionNode = stepContent.find(
2482
+ (nested) => {
2483
+ var _a3, _b3;
2484
+ return String(
2485
+ (_b3 = getLayoutRecord((_a3 = nested.props) != null ? _a3 : {}).wizardStepRole) != null ? _b3 : ""
2486
+ ).trim() === "description";
2487
+ }
2488
+ );
2489
+ const stepTitleNodeValue = (_d2 = stepTitleNode == null ? void 0 : stepTitleNode.props) == null ? void 0 : _d2.children;
2490
+ const stepDescriptionNodeValue = (_e2 = stepDescriptionNode == null ? void 0 : stepDescriptionNode.props) == null ? void 0 : _e2.children;
2491
+ const title = resolveUIValue((_f2 = stepTitleNodeValue != null ? stepTitleNodeValue : stepProps.title) != null ? _f2 : stepId, runtime);
2492
+ const description = resolveUIValue((_g = stepDescriptionNodeValue != null ? stepDescriptionNodeValue : stepProps.description) != null ? _g : "", runtime);
2493
+ const rawContentType = String((_h = stepProps.contentType) != null ? _h : "content");
2494
+ const stepRenderableContent = getWizardRenderableChildren(stepContent);
2495
+ const hasFieldChildren = stepRenderableContent.some((nested) => {
2496
+ var _a3, _b3;
2497
+ if (nested.type !== "FormField") return false;
2498
+ const nestedProps = (_a3 = nested.props) != null ? _a3 : {};
2499
+ return String((_b3 = getLayoutRecord(nestedProps).formRole) != null ? _b3 : "field").trim() === "field";
2500
+ });
2501
+ const contentType = hasFieldChildren ? "form" : rawContentType;
2502
+ const isValid = !hasFieldChildren ? stepProps.isValid !== false : validateWizardStepFields({
2503
+ stepRenderableContent,
2504
+ values: rawWizardValues,
2505
+ runtime
2506
+ });
2507
+ const explicitContentNode = stepRenderableContent.find(
2508
+ (nested) => {
2509
+ var _a3;
2510
+ return getLayoutRecord((_a3 = nested.props) != null ? _a3 : {}).wizardContent === true;
2511
+ }
2512
+ );
2513
+ const contentNode = explicitContentNode != null ? explicitContentNode : contentType === "content" ? stepRenderableContent[0] : void 0;
2514
+ return {
2515
+ id: stepId,
2516
+ title,
2517
+ description,
2518
+ titleNode: stepTitleNode,
2519
+ descriptionNode: stepDescriptionNode,
2520
+ contentNode,
2521
+ isValid,
2522
+ contentType,
2523
+ stepRenderableContent,
2524
+ contentValue: contentType === "content" ? resolveUIValue(
2525
+ (_k = (_j = (_i = contentNode == null ? void 0 : contentNode.props) == null ? void 0 : _i.children) != null ? _j : stepProps.content) != null ? _k : title,
2526
+ runtime
2527
+ ) : null
2528
+ };
2529
+ });
2530
+ const normalizedFieldsByStep = buildFieldsByStep(
2531
+ stepIdToNode,
2532
+ currentSteps
2533
+ );
2534
+ const stepIds = currentSteps.map((step) => step.id).filter(Boolean);
2535
+ const activeStepFromMemory = String((_b = wizardActiveStepByNodeId[node.id]) != null ? _b : "").trim();
2536
+ const activeStepFromProps = String(
2537
+ (_f = (_e = (_c = node.props) == null ? void 0 : _c.activeStepId) != null ? _e : (_d = node.props) == null ? void 0 : _d.initialStepId) != null ? _f : ""
2538
+ ).trim();
2539
+ const resolvedActiveStepId = resolveActiveWizardStepId({
2540
+ selectedStepId,
2541
+ stepIds,
2542
+ activeStepFromProps,
2543
+ activeStepFromMemory
2544
+ });
2545
+ return {
2546
+ stepChildren,
2547
+ stepIdToNode,
2548
+ selectedStepId,
2549
+ currentSteps,
2550
+ normalizedFieldsByStep,
2551
+ resolvedActiveStepId,
2552
+ existingFormConfig,
2553
+ existingStudioConfig
2554
+ };
2555
+ };
2556
+
2557
+ // src/studio-bridge/preview-wizard/previewWizardConfigurator.ts
2558
+ var configurePreviewFormWizard = ({
2559
+ node,
2560
+ componentProps,
2561
+ isStudioRendererContext,
2562
+ selectedNodeId,
2563
+ wizardActiveStepByNodeId,
2564
+ runtime,
2565
+ setWizardActiveStepByNodeId,
2566
+ onNodeClick,
2567
+ onInlineTextEdit,
2568
+ renderSafeNode: renderSafeNode2,
2569
+ captureFieldFocus,
2570
+ openInlineEditorForNodeProp,
2571
+ internalStudioNodeTypes
2572
+ }) => {
2573
+ var _a;
2574
+ if (isStudioRendererContext) {
2575
+ const existingClassName = String((_a = componentProps.className) != null ? _a : "").trim();
2576
+ componentProps.className = [
2577
+ existingClassName,
2578
+ "w-full",
2579
+ "[&_[data-step-form-wrapper]>section]:max-w-full",
2580
+ "[&_[data-step-form-wrapper]>section]:mx-0"
2581
+ ].filter(Boolean).join(" ");
2582
+ }
2583
+ const {
2584
+ existingFormConfig,
2585
+ existingStudioConfig,
2586
+ currentSteps,
2587
+ normalizedFieldsByStep,
2588
+ resolvedActiveStepId,
2589
+ stepIdToNode
2590
+ } = resolveStudioWizardStructure({
2591
+ node,
2592
+ componentProps,
2593
+ selectedNodeId,
2594
+ wizardActiveStepByNodeId,
2595
+ runtime,
2596
+ internalStudioNodeTypes
2597
+ });
2598
+ const rawWizardValues = existingFormConfig.values && typeof existingFormConfig.values === "object" && !Array.isArray(existingFormConfig.values) ? existingFormConfig.values : {};
2599
+ const materializedSteps = materializeStudioWizardSteps({
2600
+ nodeId: node.id,
2601
+ currentSteps,
2602
+ existingFormConfig,
2603
+ rawWizardValues,
2604
+ stepIdToNode,
2605
+ runtime,
2606
+ renderSafeNode: renderSafeNode2,
2607
+ captureFieldFocus,
2608
+ onInlineTextEdit
2609
+ });
2610
+ if (materializedSteps.length > 0) {
2611
+ componentProps.steps = materializedSteps;
2612
+ }
2613
+ existingFormConfig.fieldsByStep = normalizedFieldsByStep;
2614
+ if (resolvedActiveStepId) {
2615
+ componentProps.activeStepId = resolvedActiveStepId;
2616
+ }
2617
+ componentProps.onStepChange = createStudioWizardOnStepChange({
2618
+ nodeId: node.id,
2619
+ stepIdToNode,
2620
+ setWizardActiveStepByNodeId,
2621
+ existingOnStepChange: componentProps.onStepChange,
2622
+ onNodeClick
2623
+ });
2624
+ attachStudioWizardEditingHandlers({
2625
+ studioConfig: existingStudioConfig,
2626
+ node,
2627
+ stepIdToNode,
2628
+ openInlineEditorForNodeProp
2629
+ });
2630
+ componentProps.form = isStudioRendererContext ? void 0 : existingFormConfig;
2631
+ componentProps.studio = existingStudioConfig;
2632
+ };
2633
+
2634
+ // src/utils/nodeResetToken.ts
2635
+ import { buildNodeResetToken } from "@arkcit/engine-react";
2636
+
2637
+ // src/studio-bridge/overlay/renderSafeNode.tsx
2638
+ import { jsx as jsx6 } from "react/jsx-runtime";
2639
+ var FallbackInlineTextEditor = ({
2640
+ editing,
2641
+ onChange,
2642
+ onCancel,
2643
+ onCommit
2644
+ }) => editing.multiline ? /* @__PURE__ */ jsx6(
2645
+ "textarea",
2646
+ {
2647
+ style: editing.editorStyle,
2648
+ value: editing.value,
2649
+ autoFocus: true,
2650
+ "aria-label": "Inline text editor",
2651
+ onChange: (event) => onChange(event.target.value),
2652
+ onBlur: onCommit,
2653
+ onKeyDown: (event) => {
2654
+ if (event.key === "Escape") {
2655
+ event.preventDefault();
2656
+ onCancel();
2657
+ return;
2658
+ }
2659
+ if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
2660
+ event.preventDefault();
2661
+ onCommit();
2662
+ }
2663
+ }
2664
+ }
2665
+ ) : /* @__PURE__ */ jsx6(
2666
+ "input",
2667
+ {
2668
+ style: editing.editorStyle,
2669
+ value: editing.value,
2670
+ autoFocus: true,
2671
+ "aria-label": "Inline text editor",
2672
+ onChange: (event) => onChange(event.target.value),
2673
+ onBlur: onCommit,
2674
+ onKeyDown: (event) => {
2675
+ if (event.key === "Escape") {
2676
+ event.preventDefault();
2677
+ onCancel();
2678
+ return;
2679
+ }
2680
+ if (event.key === "Enter") {
2681
+ event.preventDefault();
2682
+ onCommit();
2683
+ }
2684
+ }
2685
+ }
2686
+ );
2687
+ var renderSafeNode = ({
2688
+ node,
2689
+ registry,
2690
+ runtime,
2691
+ schemaNodes,
2692
+ renderNode,
2693
+ isStudioRendererContext,
2694
+ overlaysByNodeId,
2695
+ selectedNodeId,
2696
+ onNodeClick,
2697
+ onInlineTextEdit,
2698
+ onNodeResize,
2699
+ onNodeResizeStart,
2700
+ onNodeResizeEnd,
2701
+ inlineEditing,
2702
+ setInlineEditing,
2703
+ ancestorTypeMembership,
2704
+ resizeStateRef,
2705
+ pinchStateRef,
2706
+ minWidthPct,
2707
+ minHeightPct,
2708
+ minHeightPx,
2709
+ overlayRootId,
2710
+ NodeWrapper,
2711
+ InlineTextEditorComponent,
2712
+ isFormInteractiveTarget
2713
+ }) => {
2714
+ var _a, _b, _c, _d, _e, _f, _g;
2715
+ const nodeProps = (_a = node.props) != null ? _a : {};
2716
+ const nodeLayout = readNodeLayout(nodeProps);
2717
+ const wrapperClassName = (_b = nodeLayout.wrapperClassName) != null ? _b : "";
2718
+ const resetToken = buildNodeResetToken(node);
2719
+ const widthPct = (_c = nodeLayout.widthPct) != null ? _c : null;
2720
+ const heightPct = (_d = nodeLayout.heightPct) != null ? _d : null;
2721
+ const heightPx = (_e = nodeLayout.heightPx) != null ? _e : null;
2722
+ const isOpenStudioOverlayNode = isStudioRendererContext && getOpenStudioOverlayState({
2723
+ node,
2724
+ nodeProps,
2725
+ overlaysByNodeId
2726
+ });
2727
+ const shouldForceFullWidth = shouldForceStudioNodeFullWidth({
2728
+ widthPct,
2729
+ nodeType: node.type,
2730
+ isStudioRendererContext,
2731
+ colSpan: nodeLayout.colSpan
2732
+ });
2733
+ const enableEventOnClick = toBoolean(nodeProps.buttonEnableEventOnClick);
2734
+ const nodeRegistryMeta = (_f = registry[node.type]) == null ? void 0 : _f.meta;
2735
+ const editableTextProps = ((_g = nodeRegistryMeta == null ? void 0 : nodeRegistryMeta.editableTextProps) != null ? _g : []).filter(
2736
+ (propName) => propName !== "className"
2737
+ );
2738
+ const { getTextValue, effectiveCandidateInlineProp } = resolveInlineEditingTarget({
2739
+ node,
2740
+ nodeProps,
2741
+ runtime,
2742
+ editableTextProps,
2743
+ resolveTranslationValue: resolveUIValue
2744
+ });
2745
+ const isInlineEditingNode = (inlineEditing == null ? void 0 : inlineEditing.nodeId) === node.id;
2746
+ const nodeContent = /* @__PURE__ */ jsx6(NodeErrorBoundary, { nodeId: node.id, nodeType: node.type, resetToken, children: renderNode(node, { widthPct, heightPct, heightPx }) }, node.id);
2747
+ const commitInlineEditing = () => {
2748
+ if (!inlineEditing) return;
2749
+ applyInlineEditingValue({
2750
+ editingState: inlineEditing,
2751
+ rawValue: inlineEditing.value,
2752
+ schemaNodes,
2753
+ onInlineTextEdit,
2754
+ findNodeById
2755
+ });
2756
+ setInlineEditing(null);
2757
+ };
2758
+ const InlineEditorComponent = InlineTextEditorComponent != null ? InlineTextEditorComponent : FallbackInlineTextEditor;
2759
+ const inlineEditor = isInlineEditingNode && inlineEditing ? /* @__PURE__ */ jsx6(
2760
+ InlineEditorComponent,
2761
+ {
2762
+ editing: inlineEditing,
2763
+ onChange: (value) => setInlineEditing((previous) => {
2764
+ if (!previous) return previous;
2765
+ return __spreadProps(__spreadValues({}, previous), {
2766
+ value
2767
+ });
2768
+ }),
2769
+ onCancel: () => setInlineEditing(null),
2770
+ onCommit: commitInlineEditing
2771
+ }
2772
+ ) : null;
2773
+ return renderNodeFrame({
2774
+ node,
2775
+ nodeProps,
2776
+ nodeContent,
2777
+ selectedNodeId,
2778
+ onNodeClick,
2779
+ onInlineTextEdit,
2780
+ onNodeResize,
2781
+ onNodeResizeStart,
2782
+ onNodeResizeEnd,
2783
+ widthPct,
2784
+ heightPct,
2785
+ heightPx,
2786
+ wrapperClassName,
2787
+ isOpenStudioOverlayNode,
2788
+ shouldForceFullWidth,
2789
+ effectiveCandidateInlineProp,
2790
+ inlineEditing,
2791
+ isInlineEditingNode,
2792
+ ancestorTypeMembership,
2793
+ schemaNodes,
2794
+ runtime,
2795
+ enableEventOnClick,
2796
+ isFormInteractiveTarget,
2797
+ getTextValue,
2798
+ setInlineEditing,
2799
+ inlineEditor,
2800
+ NodeWrapper,
2801
+ overlaysByNodeId,
2802
+ getOpenStudioOverlayState,
2803
+ resizeStateRef,
2804
+ pinchStateRef,
2805
+ minWidthPct,
2806
+ minHeightPct,
2807
+ minHeightPx,
2808
+ overlayRootId
2809
+ });
2810
+ };
2811
+
2812
+ // src/react-web/hooks/useUIEngineEffects.ts
2813
+ import { useUIEngineEffects as useUIEngineEffectsImpl } from "@arkcit/engine-react";
2814
+
2815
+ // src/renderers/preview/renderStudioForm.tsx
2816
+ var renderStudioForm = materializePreviewForm;
2817
+
2818
+ // src/renderers/preview/configureStudioFormWizard.tsx
2819
+ var configureStudioFormWizard = configurePreviewFormWizard;
2820
+
2821
+ // src/renderers/studio/configureStudioNavigation.tsx
2822
+ var configureStudioAccordion = configurePreviewAccordion;
2823
+ var configureStudioExpandablePanel = configurePreviewExpandablePanel;
2824
+ var configureStudioTabs = configurePreviewTabs;
2825
+
2826
+ // src/utils/contentStudio.tsx
2827
+ import {
2828
+ buildCoverContent,
2829
+ buildCoverMedia,
2830
+ buildScrollRevealChildren
2831
+ } from "@arkcit/engine-react";
2832
+
2833
+ // src/utils/dataBinding.ts
2834
+ var applyRowsAndColumnsBinding = ({
2835
+ componentProps,
2836
+ runtime,
2837
+ rowsBindingKey,
2838
+ columnsBindingKey
2839
+ }) => {
2840
+ if (rowsBindingKey && columnsBindingKey) {
2841
+ const boundRows = runtime.get(rowsBindingKey);
2842
+ if (Array.isArray(boundRows)) {
2843
+ componentProps.rows = boundRows;
2844
+ }
2845
+ const boundColumns = runtime.get(columnsBindingKey);
2846
+ if (Array.isArray(boundColumns)) {
2847
+ componentProps.columns = boundColumns;
2848
+ }
2849
+ }
2850
+ };
2851
+ var filterRowsByRuntimeQuery = ({
2852
+ nodeId,
2853
+ componentProps,
2854
+ runtime
2855
+ }) => {
2856
+ var _a, _b;
2857
+ const tableQueriesRaw = runtime.get("table.queriesByNodeId");
2858
+ const tableQueries = tableQueriesRaw && typeof tableQueriesRaw === "object" ? tableQueriesRaw : {};
2859
+ const queryRaw = String((_b = (_a = tableQueries[nodeId]) != null ? _a : tableQueries.__all__) != null ? _b : "").trim().toLowerCase();
2860
+ if (queryRaw.length === 0) return;
2861
+ const rows = Array.isArray(componentProps.rows) ? componentProps.rows : [];
2862
+ const columns = Array.isArray(componentProps.columns) ? componentProps.columns : [];
2863
+ const filteredRows = rows.filter((row) => {
2864
+ if (columns.length > 0) {
2865
+ return columns.some((column) => {
2866
+ var _a2, _b2;
2867
+ const key = String((_a2 = column.key) != null ? _a2 : "").trim();
2868
+ if (!key) return false;
2869
+ return String((_b2 = row[key]) != null ? _b2 : "").toLowerCase().includes(queryRaw);
2870
+ });
2871
+ }
2872
+ return Object.values(row).some(
2873
+ (value) => String(value != null ? value : "").toLowerCase().includes(queryRaw)
2874
+ );
2875
+ });
2876
+ componentProps.rows = filteredRows;
2877
+ };
2878
+ var applyObjectBinding = ({
2879
+ componentProps,
2880
+ runtime,
2881
+ bindingKey
2882
+ }) => {
2883
+ if (!bindingKey) return;
2884
+ const boundObject = runtime.get(bindingKey);
2885
+ if (boundObject && typeof boundObject === "object" && !Array.isArray(boundObject)) {
2886
+ Object.assign(componentProps, boundObject);
2887
+ }
2888
+ };
2889
+ var applyDecodeTranslationBinding = ({
2890
+ componentProps,
2891
+ runtime,
2892
+ tagContentTranslationKey,
2893
+ tagContentTranslationValue,
2894
+ hrefTranslationKey,
2895
+ hrefTranslationValue
2896
+ }) => {
2897
+ if (tagContentTranslationKey) {
2898
+ componentProps.tagContent = runtime.t ? runtime.t(tagContentTranslationKey, { value: tagContentTranslationValue }) : tagContentTranslationValue || tagContentTranslationKey;
2899
+ }
2900
+ if (hrefTranslationKey) {
2901
+ componentProps.href = runtime.t ? runtime.t(hrefTranslationKey, { value: hrefTranslationValue }) : hrefTranslationValue || hrefTranslationKey;
2902
+ }
2903
+ };
2904
+
2905
+ // src/utils/fieldFocus.ts
2906
+ var capturePendingFieldFocus = (target) => {
2907
+ if (!(target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement)) {
2908
+ return null;
2909
+ }
2910
+ return {
2911
+ id: target.id || null,
2912
+ name: target.name || null,
2913
+ selectionStart: target.selectionStart,
2914
+ selectionEnd: target.selectionEnd
2915
+ };
2916
+ };
2917
+ var escapeCss = (value) => typeof CSS !== "undefined" && typeof CSS.escape === "function" ? CSS.escape(value) : value.replace(/([\\.#:[\\],>+~*'"()])/g, "\\$1");
2918
+ var restorePendingFieldFocus = (pending) => {
2919
+ var _a;
2920
+ if (!pending) return false;
2921
+ let target = null;
2922
+ if (pending.id) {
2923
+ target = document.getElementById(pending.id);
2924
+ }
2925
+ if (!target && pending.name) {
2926
+ target = document.querySelector(
2927
+ `[name="${escapeCss(pending.name)}"]`
2928
+ );
2929
+ }
2930
+ if (!target) return false;
2931
+ target.focus({ preventScroll: true });
2932
+ if ("setSelectionRange" in target && typeof target.setSelectionRange === "function" && pending.selectionStart !== null) {
2933
+ const start = pending.selectionStart;
2934
+ const end = (_a = pending.selectionEnd) != null ? _a : start;
2935
+ try {
2936
+ target.setSelectionRange(start, end);
2937
+ } catch (e) {
2938
+ }
2939
+ }
2940
+ return true;
2941
+ };
2942
+
2943
+ // src/react-web/hooks/useUIEngineEffects.ts
2944
+ var useUIEngineEffects = ({
2945
+ schema,
2946
+ runtime,
2947
+ onNodeResize,
2948
+ onNodeResizeEnd,
2949
+ resizeStateRef,
2950
+ pendingFieldFocusRef,
2951
+ setVersion,
2952
+ minWidthPct,
2953
+ minHeightPct,
2954
+ minHeightPx
2955
+ }) => {
2956
+ return useUIEngineEffectsImpl({
2957
+ schema,
2958
+ runtime,
2959
+ onNodeResize,
2960
+ onNodeResizeEnd,
2961
+ resizeStateRef,
2962
+ pendingFieldFocusRef,
2963
+ setVersion,
2964
+ minWidthPct,
2965
+ minHeightPct,
2966
+ minHeightPx,
2967
+ dependencies: {
2968
+ buildAncestorTypeMembership,
2969
+ readOverlayState,
2970
+ capturePendingFieldFocus,
2971
+ restorePendingFieldFocus: (pending) => restorePendingFieldFocus(pending),
2972
+ computeMouseResizeSize: (args) => computeMouseResizeSize(__spreadProps(__spreadValues({}, args), {
2973
+ state: args.state
2974
+ }))
2975
+ }
2976
+ });
2977
+ };
2978
+
2979
+ // src/react-web/applyContentComposition.tsx
2980
+ import { applyContentComposition as applyContentCompositionImpl } from "@arkcit/engine-react";
2981
+
2982
+ // src/react-web/resolveContentCompositionPlan.ts
2983
+ import { resolveContentCompositionPlan } from "@arkcit/engine-render-layer";
2984
+
2985
+ // src/react-web/applyContentComposition.tsx
2986
+ var applyContentComposition = ({
2987
+ node,
2988
+ componentProps,
2989
+ isStudioRendererContext,
2990
+ internalStudioNodeTypes,
2991
+ schemaNodes,
2992
+ onInlineTextEdit,
2993
+ captureFieldFocus,
2994
+ renderSafeNode: renderSafeNode2,
2995
+ normalizeRenderableChild: normalizeRenderableChild2,
2996
+ findNodeById: findNodeById2,
2997
+ runtime,
2998
+ plans: providedPlans
2999
+ }) => {
3000
+ return applyContentCompositionImpl({
3001
+ node,
3002
+ componentProps,
3003
+ isStudioRendererContext,
3004
+ internalStudioNodeTypes,
3005
+ schemaNodes,
3006
+ onInlineTextEdit,
3007
+ captureFieldFocus,
3008
+ renderSafeNode: renderSafeNode2,
3009
+ normalizeRenderableChild: normalizeRenderableChild2,
3010
+ findNodeById: findNodeById2,
3011
+ runtime,
3012
+ plans: providedPlans,
3013
+ dependencies: {
3014
+ resolveContentCompositionPlan,
3015
+ renderStudioForm,
3016
+ buildScrollRevealChildren: (args) => buildScrollRevealChildren(__spreadProps(__spreadValues({}, args), {
3017
+ rawChildren: args.rawChildren
3018
+ }))
3019
+ }
3020
+ });
3021
+ };
3022
+
3023
+ // src/react-web/applyNavigationComposition.tsx
3024
+ import { applyNavigationComposition as applyNavigationCompositionImpl } from "@arkcit/engine-react";
3025
+
3026
+ // src/react-web/resolveNavigationCompositionPlan.ts
3027
+ import { resolveNavigationCompositionPlan } from "@arkcit/engine-render-layer";
3028
+
3029
+ // src/react-web/applyNavigationComposition.tsx
3030
+ var applyNavigationComposition = ({
3031
+ node,
3032
+ componentProps,
3033
+ isStudioRendererContext,
3034
+ selectedNodeId,
3035
+ wizardActiveStepByNodeId,
3036
+ accordionOpenIdsByNodeId,
3037
+ expandablePanelOpenByNodeId,
3038
+ runtime,
3039
+ setWizardActiveStepByNodeId,
3040
+ setAccordionOpenIdsByNodeId,
3041
+ setExpandablePanelOpenByNodeId,
3042
+ onNodeClick,
3043
+ onInlineTextEdit,
3044
+ renderSafeNode: renderSafeNode2,
3045
+ normalizeRenderableChild: normalizeRenderableChild2,
3046
+ captureFieldFocus,
3047
+ setInlineEditing,
3048
+ internalStudioNodeTypes,
3049
+ plans: providedPlans
3050
+ }) => {
3051
+ return applyNavigationCompositionImpl({
3052
+ node,
3053
+ componentProps,
3054
+ isStudioRendererContext,
3055
+ selectedNodeId,
3056
+ wizardActiveStepByNodeId,
3057
+ accordionOpenIdsByNodeId,
3058
+ expandablePanelOpenByNodeId,
3059
+ runtime,
3060
+ setWizardActiveStepByNodeId,
3061
+ setAccordionOpenIdsByNodeId,
3062
+ setExpandablePanelOpenByNodeId,
3063
+ onNodeClick,
3064
+ onInlineTextEdit,
3065
+ renderSafeNode: renderSafeNode2,
3066
+ normalizeRenderableChild: normalizeRenderableChild2,
3067
+ captureFieldFocus,
3068
+ setInlineEditing,
3069
+ internalStudioNodeTypes,
3070
+ plans: providedPlans,
3071
+ dependencies: {
3072
+ resolveNavigationCompositionPlan,
3073
+ createInlineEditingState,
3074
+ configureStudioFormWizard,
3075
+ configureStudioAccordion,
3076
+ configureStudioExpandablePanel,
3077
+ configureStudioTabs: (args) => configureStudioTabs(__spreadProps(__spreadValues({}, args), {
3078
+ rawChildren: normalizeNavigationChildren(args.rawChildren)
3079
+ }))
3080
+ }
3081
+ });
3082
+ };
3083
+
3084
+ // src/react-web/applyRenderDirectives.ts
3085
+ import { applyRenderDirectives as applyRenderDirectivesImpl } from "@arkcit/engine-react";
3086
+
3087
+ // src/react-web/resolveRenderDirectivePlan.ts
3088
+ import { resolveRenderDirectivePlan } from "@arkcit/engine-render-layer";
3089
+
3090
+ // src/react-web/applyRenderDirectives.ts
3091
+ var applyRenderDirectives = ({
3092
+ node,
3093
+ componentProps,
3094
+ renderBindingProps,
3095
+ runtime,
3096
+ plans: providedPlans
3097
+ }) => {
3098
+ return applyRenderDirectivesImpl({
3099
+ node,
3100
+ componentProps,
3101
+ renderBindingProps,
3102
+ runtime,
3103
+ plans: providedPlans,
3104
+ dependencies: {
3105
+ resolveRenderDirectivePlan,
3106
+ applyRowsAndColumnsBinding,
3107
+ filterRowsByRuntimeQuery,
3108
+ buildCoverMedia: (args) => buildCoverMedia({
3109
+ mediaSource: args.mediaSource,
3110
+ mediaSrc: args.mediaSrc,
3111
+ mediaAlt: args.mediaAlt
3112
+ }),
3113
+ applyObjectBinding,
3114
+ applyDecodeTranslationBinding: (args) => {
3115
+ var _a, _b, _c, _d;
3116
+ return applyDecodeTranslationBinding({
3117
+ componentProps: args.componentProps,
3118
+ runtime,
3119
+ tagContentTranslationKey: (_a = args.tagContentTranslationKey) != null ? _a : "",
3120
+ tagContentTranslationValue: (_b = args.tagContentTranslationValue) != null ? _b : "",
3121
+ hrefTranslationKey: (_c = args.hrefTranslationKey) != null ? _c : "",
3122
+ hrefTranslationValue: (_d = args.hrefTranslationValue) != null ? _d : ""
3123
+ });
3124
+ }
3125
+ }
3126
+ });
3127
+ };
3128
+
3129
+ // src/react-web/finalizeRenderedNode.tsx
3130
+ import { finalizeRenderedNode as finalizeRenderedNodeImpl } from "@arkcit/engine-react";
3131
+
3132
+ // src/react-web/resolveFinalRenderPlan.ts
3133
+ import { resolveFinalRenderPlan } from "@arkcit/engine-render-layer";
3134
+
3135
+ // src/react-web/finalizeRenderedNode.tsx
3136
+ var finalizeRenderedNode = ({
3137
+ node,
3138
+ children,
3139
+ componentProps,
3140
+ registryComponent,
3141
+ runtime,
3142
+ isStudioRendererContext,
3143
+ studioSizing,
3144
+ plans: providedPlans
3145
+ }) => {
3146
+ return finalizeRenderedNodeImpl({
3147
+ node,
3148
+ children,
3149
+ componentProps,
3150
+ registryComponent,
3151
+ runtime,
3152
+ isStudioRendererContext,
3153
+ studioSizing,
3154
+ plans: providedPlans,
3155
+ dependencies: {
3156
+ resolveFinalRenderPlan,
3157
+ omitStudioProps
3158
+ }
3159
+ });
3160
+ };
3161
+
3162
+ // src/react-web/renderReactNodeDependencies.ts
3163
+ var createRenderReactNodeDependencies = () => ({
3164
+ applyStudioOverlayComponentProps,
3165
+ applyContentComposition,
3166
+ applyRenderDirectives,
3167
+ applyNavigationComposition,
3168
+ finalizeRenderedNode,
3169
+ normalizeRenderableChild,
3170
+ findNodeById
3171
+ });
3172
+ var createInlineEditingState = (targetNodeId, propName, rawValue) => {
3173
+ let mode = "primitive";
3174
+ let value = "";
3175
+ if (typeof rawValue === "string") {
3176
+ value = rawValue;
3177
+ } else if (typeof rawValue === "number" || typeof rawValue === "boolean") {
3178
+ value = String(rawValue);
3179
+ } else if (rawValue && typeof rawValue === "object") {
3180
+ if (!Array.isArray(rawValue) && typeof rawValue.$t === "string") {
3181
+ const translationValue = rawValue;
3182
+ mode = "translation";
3183
+ value = translationValue.$t;
3184
+ } else {
3185
+ mode = "json";
3186
+ try {
3187
+ value = JSON.stringify(rawValue, null, 2);
3188
+ } catch (e) {
3189
+ value = "";
3190
+ }
3191
+ }
3192
+ }
3193
+ return {
3194
+ nodeId: targetNodeId,
3195
+ propName,
3196
+ value,
3197
+ multiline: mode === "json" || value.length > 64,
3198
+ mode
3199
+ };
3200
+ };
3201
+ var normalizeNavigationChildren = (rawChildren) => Array.isArray(rawChildren) ? rawChildren : [];
3202
+
3203
+ // src/react-web/engine/rootDependencies.ts
3204
+ var createReactWebEngineRootDependencies = () => ({
3205
+ useUIEngineEffects: (args) => useUIEngineEffects(__spreadProps(__spreadValues({}, args), {
3206
+ resizeStateRef: args.resizeStateRef,
3207
+ pendingFieldFocusRef: args.pendingFieldFocusRef
3208
+ })),
3209
+ renderSafeNode: (args) => renderSafeNode(__spreadProps(__spreadValues({}, args), {
3210
+ resizeStateRef: args.resizeStateRef,
3211
+ pinchStateRef: args.pinchStateRef
3212
+ })),
3213
+ InlineTextEditor,
3214
+ StudioNodeWrapper,
3215
+ renderReactNodeDependencies: createRenderReactNodeDependencies()
3216
+ });
3217
+
3218
+ // src/react-web/engine/ReactWebEngineRoot.tsx
3219
+ import { jsx as jsx7 } from "react/jsx-runtime";
3220
+ var ReactWebEngineRoot = (props) => {
3221
+ return /* @__PURE__ */ jsx7(
3222
+ ReactWebEngineRootImpl,
3223
+ __spreadProps(__spreadValues({}, props), {
3224
+ dependencies: createReactWebEngineRootDependencies()
3225
+ })
3226
+ );
3227
+ };
3228
+
3229
+ // src/engine/UIEngine.tsx
3230
+ import { jsx as jsx8 } from "react/jsx-runtime";
3231
+ var UIEngine = (props) => /* @__PURE__ */ jsx8(ReactWebEngineRoot, __spreadValues({}, props));
3232
+ var UIEngine_default = UIEngine;
3233
+ export {
3234
+ UIEngine_default as default
3235
+ };