@crediblemark/build 0.25.7 → 0.25.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ArrayField-HYHS4HCO.mjs +17 -0
- package/dist/{Editor-GDIQRAYD.mjs → Editor-P3UUWNSZ.mjs} +8 -10
- package/dist/ObjectField-4N5XWAFL.mjs +17 -0
- package/dist/{actions-LaZpJ1KE.d.ts → actions-CKSDxt4l.d.mts} +1 -1
- package/dist/{actions-LaZpJ1KE.d.mts → actions-CKSDxt4l.d.ts} +1 -1
- package/dist/{chunk-J2UWT4L6.mjs → chunk-44PQTFGV.mjs} +5 -7
- package/dist/{chunk-23V3TMNT.mjs → chunk-AZFZRLP7.mjs} +7 -7
- package/dist/{chunk-ETN6FGIH.mjs → chunk-E4F5M5JH.mjs} +1 -1
- package/dist/chunk-HHKM5MBJ.mjs +3163 -0
- package/dist/{chunk-M4S65TWW.mjs → chunk-KN26YZZJ.mjs} +285 -130
- package/dist/{chunk-ERLZ5CJF.mjs → chunk-MWCFPGI6.mjs} +1153 -3236
- package/dist/{chunk-64A37UUC.mjs → chunk-O44M27KT.mjs} +442 -7
- package/dist/{chunk-EDTYTRV5.mjs → chunk-P2AZFZ7Q.mjs} +2 -2
- package/dist/{chunk-GUUI5HW3.mjs → chunk-PFHKXXSV.mjs} +1 -1
- package/dist/{chunk-JERQUUM4.mjs → chunk-S32JZ2HU.mjs} +1 -1
- package/dist/{chunk-35OY5UFR.mjs → chunk-T2LBDQLG.mjs} +7 -7
- package/dist/{chunk-EWOJLVHT.mjs → chunk-XLRMLBFR.mjs} +1 -1
- package/dist/{chunk-BXF2PDCW.mjs → chunk-Z7DDX2XU.mjs} +2 -2
- package/dist/{full-Y52CQK4X.mjs → full-3VRJOFG5.mjs} +6 -8
- package/dist/{index-CD3PszvP.d.mts → index-Ds4Dkkyr.d.mts} +1 -1
- package/dist/{index-Bj2x5pZ7.d.ts → index-DwajIHZf.d.ts} +1 -1
- package/dist/index.css +188 -2
- package/dist/index.d.mts +8 -40
- package/dist/index.d.ts +8 -40
- package/dist/index.js +1224 -567
- package/dist/index.mjs +25 -25
- package/dist/internal.d.mts +2 -2
- package/dist/internal.d.ts +2 -2
- package/dist/internal.mjs +1 -2
- package/dist/{loaded-K43N3OFP.mjs → loaded-C2JGMUXV.mjs} +3 -5
- package/dist/{loaded-MWBOE5CB.mjs → loaded-FJHWTGH6.mjs} +3 -5
- package/dist/{loaded-IWWCJE75.mjs → loaded-NTEK7RT3.mjs} +3 -5
- package/dist/no-external.css +188 -2
- package/dist/no-external.d.mts +4 -4
- package/dist/no-external.d.ts +4 -4
- package/dist/no-external.js +1224 -567
- package/dist/no-external.mjs +25 -25
- package/dist/rsc.css +1420 -0
- package/dist/rsc.d.mts +2 -2
- package/dist/rsc.d.ts +2 -2
- package/dist/rsc.js +10324 -1007
- package/dist/rsc.mjs +20 -3
- package/dist/{walk-tree-BEw6kTXm.d.ts → walk-tree-B_jHFa3L.d.mts} +39 -2
- package/dist/{walk-tree-BO8uRNcW.d.mts → walk-tree-DHMRjk5Z.d.ts} +39 -2
- package/package.json +1 -1
- package/dist/ArrayField-OIQQLS2B.mjs +0 -19
- package/dist/ObjectField-WOW3T2WS.mjs +0 -19
- package/dist/chunk-2RLA42JA.mjs +0 -455
- package/dist/chunk-7LXZOPYT.mjs +0 -445
- package/dist/chunk-SMAWAXVX.mjs +0 -139
|
@@ -0,0 +1,3163 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LoadedRichTextMenu
|
|
3
|
+
} from "./chunk-Z7DDX2XU.mjs";
|
|
4
|
+
import {
|
|
5
|
+
DragIcon,
|
|
6
|
+
createDynamicCollisionDetector,
|
|
7
|
+
setDeep
|
|
8
|
+
} from "./chunk-44PQTFGV.mjs";
|
|
9
|
+
import {
|
|
10
|
+
EditorFallback,
|
|
11
|
+
useContextStore,
|
|
12
|
+
useSafeId
|
|
13
|
+
} from "./chunk-T2LBDQLG.mjs";
|
|
14
|
+
import {
|
|
15
|
+
styles_module_default
|
|
16
|
+
} from "./chunk-ISXFLTBM.mjs";
|
|
17
|
+
import {
|
|
18
|
+
ActionBar,
|
|
19
|
+
Loader
|
|
20
|
+
} from "./chunk-AZFZRLP7.mjs";
|
|
21
|
+
import {
|
|
22
|
+
Copy,
|
|
23
|
+
CornerLeftUp,
|
|
24
|
+
Trash,
|
|
25
|
+
defaultAppState,
|
|
26
|
+
resolveComponentData,
|
|
27
|
+
useAppStore,
|
|
28
|
+
useAppStoreApi
|
|
29
|
+
} from "./chunk-KN26YZZJ.mjs";
|
|
30
|
+
import {
|
|
31
|
+
get_class_name_factory_default
|
|
32
|
+
} from "./chunk-BFHV72KK.mjs";
|
|
33
|
+
import {
|
|
34
|
+
expandNode,
|
|
35
|
+
generateId,
|
|
36
|
+
getItem,
|
|
37
|
+
getZoneId,
|
|
38
|
+
insert,
|
|
39
|
+
mapFields,
|
|
40
|
+
rootAreaId,
|
|
41
|
+
rootDroppableId,
|
|
42
|
+
setupZone,
|
|
43
|
+
toComponent,
|
|
44
|
+
walkAppState,
|
|
45
|
+
walkTree
|
|
46
|
+
} from "./chunk-O44M27KT.mjs";
|
|
47
|
+
|
|
48
|
+
// components/AutoField/fields/SliderField/index.tsx
|
|
49
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
50
|
+
var SliderField = ({
|
|
51
|
+
value,
|
|
52
|
+
onChange,
|
|
53
|
+
min = 0,
|
|
54
|
+
max = 100,
|
|
55
|
+
step = 1,
|
|
56
|
+
unit = "px",
|
|
57
|
+
defaultValue = 0,
|
|
58
|
+
useUnits = true,
|
|
59
|
+
style = {}
|
|
60
|
+
}) => {
|
|
61
|
+
const parseValue = (val) => {
|
|
62
|
+
if (typeof val === "number") return val;
|
|
63
|
+
if (typeof val === "string") return parseFloat(val);
|
|
64
|
+
return 0;
|
|
65
|
+
};
|
|
66
|
+
const inputValue = value !== void 0 && value !== null ? value : defaultValue;
|
|
67
|
+
const numericValue = parseValue(inputValue);
|
|
68
|
+
const extractUnit = (val) => {
|
|
69
|
+
if (!useUnits) return "";
|
|
70
|
+
if (typeof val === "string") {
|
|
71
|
+
const match = val.replace(/[0-9.-]/g, "");
|
|
72
|
+
return match || unit;
|
|
73
|
+
}
|
|
74
|
+
return unit;
|
|
75
|
+
};
|
|
76
|
+
const currentUnit = extractUnit(inputValue);
|
|
77
|
+
const handleChange = (e) => {
|
|
78
|
+
const newVal = parseFloat(e.target.value);
|
|
79
|
+
if (isNaN(newVal)) return;
|
|
80
|
+
if (useUnits) {
|
|
81
|
+
onChange(`${newVal}${currentUnit}`);
|
|
82
|
+
} else {
|
|
83
|
+
onChange(newVal);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const handleUnitChange = (e) => {
|
|
87
|
+
const newUnit = e.target.value;
|
|
88
|
+
onChange(`${numericValue}${newUnit}`);
|
|
89
|
+
};
|
|
90
|
+
return /* @__PURE__ */ jsxs("div", { style: { padding: "0", ...style }, children: [
|
|
91
|
+
/* @__PURE__ */ jsx("style", { dangerouslySetInnerHTML: { __html: `
|
|
92
|
+
.cb-slider-input {
|
|
93
|
+
-webkit-appearance: none;
|
|
94
|
+
width: 100%;
|
|
95
|
+
height: 3px;
|
|
96
|
+
background: var(--cb-border, #e2e8f0);
|
|
97
|
+
border-radius: 2px;
|
|
98
|
+
outline: none;
|
|
99
|
+
margin: 8px 0;
|
|
100
|
+
}
|
|
101
|
+
.cb-slider-input::-webkit-slider-thumb {
|
|
102
|
+
-webkit-appearance: none;
|
|
103
|
+
appearance: none;
|
|
104
|
+
width: 12px;
|
|
105
|
+
height: 12px;
|
|
106
|
+
background: var(--cb-gold, #d97706);
|
|
107
|
+
cursor: pointer;
|
|
108
|
+
border-radius: 50%;
|
|
109
|
+
border: 2px solid var(--cb-bg-surface, #fff);
|
|
110
|
+
box-shadow: 0 1px 2px rgba(0,0,0,0.1);
|
|
111
|
+
transition: all 0.2s ease;
|
|
112
|
+
}
|
|
113
|
+
.cb-slider-input::-webkit-slider-thumb:hover {
|
|
114
|
+
transform: scale(1.15);
|
|
115
|
+
}
|
|
116
|
+
.cb-number-input:focus, .cb-select-input:focus {
|
|
117
|
+
border-color: var(--cb-gold) !important;
|
|
118
|
+
outline: none !important;
|
|
119
|
+
}
|
|
120
|
+
` } }),
|
|
121
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", gap: "6px" }, children: [
|
|
122
|
+
/* @__PURE__ */ jsx(
|
|
123
|
+
"input",
|
|
124
|
+
{
|
|
125
|
+
type: "range",
|
|
126
|
+
min,
|
|
127
|
+
max,
|
|
128
|
+
step,
|
|
129
|
+
value: numericValue,
|
|
130
|
+
onChange: handleChange,
|
|
131
|
+
className: "cb-slider-input",
|
|
132
|
+
style: { flex: 1, cursor: "pointer" }
|
|
133
|
+
}
|
|
134
|
+
),
|
|
135
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "2px" }, children: [
|
|
136
|
+
/* @__PURE__ */ jsx(
|
|
137
|
+
"input",
|
|
138
|
+
{
|
|
139
|
+
type: "number",
|
|
140
|
+
min,
|
|
141
|
+
max,
|
|
142
|
+
step,
|
|
143
|
+
value: numericValue,
|
|
144
|
+
onChange: handleChange,
|
|
145
|
+
className: "cb-number-input",
|
|
146
|
+
style: {
|
|
147
|
+
width: "48px",
|
|
148
|
+
padding: "3px 4px",
|
|
149
|
+
borderRadius: "3px",
|
|
150
|
+
border: "1px solid var(--cb-border, #e2e8f0)",
|
|
151
|
+
background: "var(--cb-bg-base, #f8fafc)",
|
|
152
|
+
color: "var(--cb-silver, #0f172a)",
|
|
153
|
+
fontSize: "10px",
|
|
154
|
+
fontWeight: "500",
|
|
155
|
+
textAlign: "center",
|
|
156
|
+
transition: "all 0.2s ease"
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
),
|
|
160
|
+
useUnits && /* @__PURE__ */ jsxs(
|
|
161
|
+
"select",
|
|
162
|
+
{
|
|
163
|
+
value: currentUnit,
|
|
164
|
+
onChange: handleUnitChange,
|
|
165
|
+
className: "cb-select-input",
|
|
166
|
+
style: {
|
|
167
|
+
width: "42px",
|
|
168
|
+
padding: "2px",
|
|
169
|
+
borderRadius: "3px",
|
|
170
|
+
border: "1px solid var(--cb-border, #e2e8f0)",
|
|
171
|
+
background: "var(--cb-bg-base, #f8fafc)",
|
|
172
|
+
color: "var(--cb-silver, #0f172a)",
|
|
173
|
+
fontSize: "9px",
|
|
174
|
+
fontWeight: "500",
|
|
175
|
+
cursor: "pointer",
|
|
176
|
+
transition: "all 0.2s ease"
|
|
177
|
+
},
|
|
178
|
+
children: [
|
|
179
|
+
/* @__PURE__ */ jsx("option", { value: "px", children: "px" }),
|
|
180
|
+
/* @__PURE__ */ jsx("option", { value: "%", children: "%" }),
|
|
181
|
+
/* @__PURE__ */ jsx("option", { value: "vh", children: "vh" }),
|
|
182
|
+
/* @__PURE__ */ jsx("option", { value: "vw", children: "vw" }),
|
|
183
|
+
/* @__PURE__ */ jsx("option", { value: "em", children: "em" }),
|
|
184
|
+
/* @__PURE__ */ jsx("option", { value: "rem", children: "rem" })
|
|
185
|
+
]
|
|
186
|
+
}
|
|
187
|
+
)
|
|
188
|
+
] })
|
|
189
|
+
] })
|
|
190
|
+
] });
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
// components/AutoField/fields/ResponsiveSliderField/index.tsx
|
|
194
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
195
|
+
var DesktopIcon = () => /* @__PURE__ */ jsxs2("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
196
|
+
/* @__PURE__ */ jsx2("rect", { x: "2", y: "3", width: "20", height: "14", rx: "2", ry: "2" }),
|
|
197
|
+
/* @__PURE__ */ jsx2("line", { x1: "8", y1: "21", x2: "16", y2: "21" }),
|
|
198
|
+
/* @__PURE__ */ jsx2("line", { x1: "12", y1: "17", x2: "12", y2: "21" })
|
|
199
|
+
] });
|
|
200
|
+
var TabletIcon = () => /* @__PURE__ */ jsxs2("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
201
|
+
/* @__PURE__ */ jsx2("rect", { x: "4", y: "2", width: "16", height: "20", rx: "2", ry: "2" }),
|
|
202
|
+
/* @__PURE__ */ jsx2("line", { x1: "12", y1: "18", x2: "12.01", y2: "18" })
|
|
203
|
+
] });
|
|
204
|
+
var MobileIcon = () => /* @__PURE__ */ jsxs2("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
205
|
+
/* @__PURE__ */ jsx2("rect", { x: "5", y: "2", width: "14", height: "20", rx: "2", ry: "2" }),
|
|
206
|
+
/* @__PURE__ */ jsx2("line", { x1: "12", y1: "18", x2: "12.01", y2: "18" })
|
|
207
|
+
] });
|
|
208
|
+
var ResponsiveSliderField = ({
|
|
209
|
+
value = {},
|
|
210
|
+
onChange,
|
|
211
|
+
label,
|
|
212
|
+
unit = "px",
|
|
213
|
+
max = 100,
|
|
214
|
+
min = 0,
|
|
215
|
+
step = 1,
|
|
216
|
+
defaultValue = 0
|
|
217
|
+
}) => {
|
|
218
|
+
const setUi = useAppStore((s) => s.setUi);
|
|
219
|
+
const viewportsState = useAppStore((s) => s.state.ui.viewports);
|
|
220
|
+
const zoomConfig = useAppStore((s) => s.zoomConfig);
|
|
221
|
+
const setZoomConfig = useAppStore((s) => s.setZoomConfig);
|
|
222
|
+
const viewportConfigOptions = useAppStore((s) => s.viewports);
|
|
223
|
+
const getModeFromWidth = (width) => {
|
|
224
|
+
if (width === "100%") return "desktop";
|
|
225
|
+
const w = typeof width === "string" ? parseInt(width) : width;
|
|
226
|
+
if (w <= 480) return "mobile";
|
|
227
|
+
if (w <= 900) return "tablet";
|
|
228
|
+
return "desktop";
|
|
229
|
+
};
|
|
230
|
+
const mode = getModeFromWidth(viewportsState.current.width);
|
|
231
|
+
const changeGlobalViewport = (targetMode) => {
|
|
232
|
+
const targetIcon = targetMode === "mobile" ? "Smartphone" : targetMode === "tablet" ? "Tablet" : "Monitor";
|
|
233
|
+
const matched = viewportConfigOptions.find((v) => v.icon === targetIcon) || viewportConfigOptions.find((v) => {
|
|
234
|
+
if (targetMode === "mobile") return v.width !== "100%" && parseInt(String(v.width)) <= 480;
|
|
235
|
+
if (targetMode === "tablet") return v.width !== "100%" && parseInt(String(v.width)) > 480 && parseInt(String(v.width)) <= 900;
|
|
236
|
+
return v.width === "100%" || parseInt(String(v.width)) > 900;
|
|
237
|
+
}) || viewportConfigOptions[0];
|
|
238
|
+
const isFullWidth = matched.width === "100%";
|
|
239
|
+
const uiViewport = {
|
|
240
|
+
...matched,
|
|
241
|
+
height: matched.height || "auto",
|
|
242
|
+
zoom: isFullWidth ? 1 : zoomConfig.zoom
|
|
243
|
+
};
|
|
244
|
+
if (isFullWidth) {
|
|
245
|
+
setZoomConfig({ ...zoomConfig, zoom: 1 });
|
|
246
|
+
}
|
|
247
|
+
setUi({
|
|
248
|
+
viewports: { ...viewportsState, current: uiViewport }
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
const getCurrentValue = () => {
|
|
252
|
+
const val = value?.[mode];
|
|
253
|
+
if (val !== void 0 && val !== null) {
|
|
254
|
+
return val;
|
|
255
|
+
}
|
|
256
|
+
if (mode === "tablet" && value?.desktop !== void 0) return value.desktop;
|
|
257
|
+
if (mode === "mobile") {
|
|
258
|
+
if (value?.tablet !== void 0) return value.tablet;
|
|
259
|
+
if (value?.desktop !== void 0) return value.desktop;
|
|
260
|
+
}
|
|
261
|
+
if (typeof defaultValue === "number") return defaultValue;
|
|
262
|
+
const def = defaultValue;
|
|
263
|
+
const defVal = def?.[mode];
|
|
264
|
+
if (defVal !== void 0) return defVal;
|
|
265
|
+
if (mode === "tablet" && def?.desktop !== void 0) return def.desktop;
|
|
266
|
+
if (mode === "mobile") {
|
|
267
|
+
if (def?.tablet !== void 0) return def.tablet;
|
|
268
|
+
if (def?.desktop !== void 0) return def.desktop;
|
|
269
|
+
}
|
|
270
|
+
return 0;
|
|
271
|
+
};
|
|
272
|
+
const handleChange = (newVal) => {
|
|
273
|
+
onChange({
|
|
274
|
+
...value,
|
|
275
|
+
[mode]: newVal
|
|
276
|
+
});
|
|
277
|
+
};
|
|
278
|
+
return /* @__PURE__ */ jsxs2("div", { style: { display: "flex", flexDirection: "column", gap: "2px", width: "100%" }, children: [
|
|
279
|
+
label && /* @__PURE__ */ jsx2("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: "2px" }, children: /* @__PURE__ */ jsxs2("label", { style: {
|
|
280
|
+
fontSize: "10px",
|
|
281
|
+
fontWeight: 600,
|
|
282
|
+
color: "var(--cb-silver-muted, #71717a)",
|
|
283
|
+
display: "flex",
|
|
284
|
+
alignItems: "center",
|
|
285
|
+
gap: "4px",
|
|
286
|
+
textTransform: "uppercase",
|
|
287
|
+
letterSpacing: "0.05em"
|
|
288
|
+
}, children: [
|
|
289
|
+
label,
|
|
290
|
+
/* @__PURE__ */ jsxs2("span", { style: { fontSize: "9px", opacity: 0.5, fontWeight: "400" }, children: [
|
|
291
|
+
"(",
|
|
292
|
+
mode,
|
|
293
|
+
")"
|
|
294
|
+
] })
|
|
295
|
+
] }) }),
|
|
296
|
+
/* @__PURE__ */ jsxs2("div", { style: { display: "flex", alignItems: "center", gap: "8px", width: "100%" }, children: [
|
|
297
|
+
/* @__PURE__ */ jsxs2("div", { style: {
|
|
298
|
+
display: "flex",
|
|
299
|
+
backgroundColor: "var(--cb-bg-panel, #f1f5f9)",
|
|
300
|
+
borderRadius: "4px",
|
|
301
|
+
padding: "1px",
|
|
302
|
+
border: "1px solid var(--cb-border, #e2e8f0)",
|
|
303
|
+
flexShrink: 0
|
|
304
|
+
}, children: [
|
|
305
|
+
/* @__PURE__ */ jsx2(
|
|
306
|
+
"button",
|
|
307
|
+
{
|
|
308
|
+
type: "button",
|
|
309
|
+
onClick: () => changeGlobalViewport("desktop"),
|
|
310
|
+
style: {
|
|
311
|
+
padding: "2px 5px",
|
|
312
|
+
border: "none",
|
|
313
|
+
background: mode === "desktop" ? "var(--cb-bg-surface, #fff)" : "transparent",
|
|
314
|
+
boxShadow: mode === "desktop" ? "0 1px 2px rgba(0,0,0,0.05)" : "none",
|
|
315
|
+
borderRadius: "3px",
|
|
316
|
+
cursor: "pointer",
|
|
317
|
+
color: mode === "desktop" ? "var(--cb-gold, #d97706)" : "var(--cb-silver-muted, #a1a1aa)",
|
|
318
|
+
display: "flex",
|
|
319
|
+
alignItems: "center",
|
|
320
|
+
transition: "all 0.1s ease"
|
|
321
|
+
},
|
|
322
|
+
title: "Desktop",
|
|
323
|
+
"aria-label": "Desktop viewport",
|
|
324
|
+
"aria-pressed": mode === "desktop",
|
|
325
|
+
children: /* @__PURE__ */ jsx2(DesktopIcon, {})
|
|
326
|
+
}
|
|
327
|
+
),
|
|
328
|
+
/* @__PURE__ */ jsx2(
|
|
329
|
+
"button",
|
|
330
|
+
{
|
|
331
|
+
type: "button",
|
|
332
|
+
onClick: () => changeGlobalViewport("tablet"),
|
|
333
|
+
style: {
|
|
334
|
+
padding: "2px 5px",
|
|
335
|
+
border: "none",
|
|
336
|
+
background: mode === "tablet" ? "var(--cb-bg-surface, #fff)" : "transparent",
|
|
337
|
+
boxShadow: mode === "tablet" ? "0 1px 2px rgba(0,0,0,0.05)" : "none",
|
|
338
|
+
borderRadius: "3px",
|
|
339
|
+
cursor: "pointer",
|
|
340
|
+
color: mode === "tablet" ? "var(--cb-gold, #d97706)" : "var(--cb-silver-muted, #a1a1aa)",
|
|
341
|
+
display: "flex",
|
|
342
|
+
alignItems: "center",
|
|
343
|
+
transition: "all 0.1s ease"
|
|
344
|
+
},
|
|
345
|
+
title: "Tablet",
|
|
346
|
+
"aria-label": "Tablet viewport",
|
|
347
|
+
"aria-pressed": mode === "tablet",
|
|
348
|
+
children: /* @__PURE__ */ jsx2(TabletIcon, {})
|
|
349
|
+
}
|
|
350
|
+
),
|
|
351
|
+
/* @__PURE__ */ jsx2(
|
|
352
|
+
"button",
|
|
353
|
+
{
|
|
354
|
+
type: "button",
|
|
355
|
+
onClick: () => changeGlobalViewport("mobile"),
|
|
356
|
+
style: {
|
|
357
|
+
padding: "2px 5px",
|
|
358
|
+
border: "none",
|
|
359
|
+
background: mode === "mobile" ? "var(--cb-bg-surface, #fff)" : "transparent",
|
|
360
|
+
boxShadow: mode === "mobile" ? "0 1px 2px rgba(0,0,0,0.05)" : "none",
|
|
361
|
+
borderRadius: "3px",
|
|
362
|
+
cursor: "pointer",
|
|
363
|
+
color: mode === "mobile" ? "var(--cb-gold, #d97706)" : "var(--cb-silver-muted, #a1a1aa)",
|
|
364
|
+
display: "flex",
|
|
365
|
+
alignItems: "center",
|
|
366
|
+
transition: "all 0.1s ease"
|
|
367
|
+
},
|
|
368
|
+
title: "Mobile",
|
|
369
|
+
"aria-label": "Mobile viewport",
|
|
370
|
+
"aria-pressed": mode === "mobile",
|
|
371
|
+
children: /* @__PURE__ */ jsx2(MobileIcon, {})
|
|
372
|
+
}
|
|
373
|
+
)
|
|
374
|
+
] }),
|
|
375
|
+
/* @__PURE__ */ jsx2("div", { style: { flex: 1 }, children: /* @__PURE__ */ jsx2(
|
|
376
|
+
SliderField,
|
|
377
|
+
{
|
|
378
|
+
value: getCurrentValue(),
|
|
379
|
+
onChange: handleChange,
|
|
380
|
+
unit,
|
|
381
|
+
max,
|
|
382
|
+
min,
|
|
383
|
+
step,
|
|
384
|
+
useUnits: false
|
|
385
|
+
}
|
|
386
|
+
) })
|
|
387
|
+
] })
|
|
388
|
+
] });
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
// components/AutoField/fields/ColorPickerField/index.tsx
|
|
392
|
+
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
393
|
+
var ColorPickerField = ({ value, onChange }) => {
|
|
394
|
+
const safeValue = value || "#ffffff";
|
|
395
|
+
return /* @__PURE__ */ jsxs3("div", { style: { padding: "4px 0", display: "flex", gap: "6px", alignItems: "center" }, children: [
|
|
396
|
+
/* @__PURE__ */ jsx3("div", { style: {
|
|
397
|
+
position: "relative",
|
|
398
|
+
width: "28px",
|
|
399
|
+
height: "28px",
|
|
400
|
+
borderRadius: "3px",
|
|
401
|
+
border: "1px solid var(--cb-border, #e2e8f0)",
|
|
402
|
+
overflow: "hidden",
|
|
403
|
+
flexShrink: 0,
|
|
404
|
+
background: "var(--cb-bg-base, #f8fafc)"
|
|
405
|
+
}, children: /* @__PURE__ */ jsx3(
|
|
406
|
+
"input",
|
|
407
|
+
{
|
|
408
|
+
type: "color",
|
|
409
|
+
value: safeValue.startsWith("#") ? safeValue : "#000000",
|
|
410
|
+
onChange: (e) => {
|
|
411
|
+
if (e.target.value !== value) {
|
|
412
|
+
onChange(e.target.value);
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
style: {
|
|
416
|
+
position: "absolute",
|
|
417
|
+
top: "-50%",
|
|
418
|
+
left: "-50%",
|
|
419
|
+
width: "200%",
|
|
420
|
+
height: "200%",
|
|
421
|
+
cursor: "pointer",
|
|
422
|
+
border: "none",
|
|
423
|
+
padding: 0,
|
|
424
|
+
margin: 0
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
) }),
|
|
428
|
+
/* @__PURE__ */ jsx3(
|
|
429
|
+
"input",
|
|
430
|
+
{
|
|
431
|
+
type: "text",
|
|
432
|
+
value: value || "",
|
|
433
|
+
placeholder: "#RRGGBB",
|
|
434
|
+
onChange: (e) => onChange(e.target.value),
|
|
435
|
+
style: {
|
|
436
|
+
flex: 1,
|
|
437
|
+
padding: "4px 8px",
|
|
438
|
+
borderRadius: "3px",
|
|
439
|
+
border: "1px solid var(--cb-border, #e2e8f0)",
|
|
440
|
+
background: "var(--cb-bg-base, #f8fafc)",
|
|
441
|
+
color: "var(--cb-silver, #0f172a)",
|
|
442
|
+
fontSize: "11px",
|
|
443
|
+
fontFamily: "var(--cb-font-mono, 'JetBrains Mono', monospace)",
|
|
444
|
+
fontWeight: "500",
|
|
445
|
+
height: "28px",
|
|
446
|
+
transition: "all 0.1s ease"
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
)
|
|
450
|
+
] });
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
// css-module:/home/runner/work/credbuild/credbuild/components/Drawer/styles.module.css#css-module
|
|
454
|
+
var styles_module_default2 = { "Drawer": "_Drawer_1bd7y_1", "Drawer-draggable": "_Drawer-draggable_1bd7y_7", "Drawer-draggableBg": "_Drawer-draggableBg_1bd7y_11", "DrawerItem-draggable": "_DrawerItem-draggable_1bd7y_21", "DrawerItem--disabled": "_DrawerItem--disabled_1bd7y_34", "DrawerItem": "_DrawerItem_1bd7y_21", "Drawer--isDraggingFrom": "_Drawer--isDraggingFrom_1bd7y_43", "DrawerItem-default": "_DrawerItem-default_1bd7y_44", "DrawerItem-name": "_DrawerItem-name_1bd7y_61" };
|
|
455
|
+
|
|
456
|
+
// components/Drawer/index.tsx
|
|
457
|
+
import { useMemo, useState } from "react";
|
|
458
|
+
|
|
459
|
+
// components/DragDropContext/context.tsx
|
|
460
|
+
import {
|
|
461
|
+
createContext,
|
|
462
|
+
useContext,
|
|
463
|
+
useEffect,
|
|
464
|
+
useId,
|
|
465
|
+
useRef
|
|
466
|
+
} from "react";
|
|
467
|
+
var dragListenerContext = createContext({
|
|
468
|
+
dragListeners: {}
|
|
469
|
+
});
|
|
470
|
+
function useDragListener(type, fn, deps = []) {
|
|
471
|
+
const { setDragListeners } = useContext(dragListenerContext);
|
|
472
|
+
const id = useId();
|
|
473
|
+
const fnRef = useRef(fn);
|
|
474
|
+
useEffect(() => {
|
|
475
|
+
fnRef.current = fn;
|
|
476
|
+
}, [fn]);
|
|
477
|
+
useEffect(() => {
|
|
478
|
+
if (setDragListeners) {
|
|
479
|
+
const wrappedFn = ((...args) => {
|
|
480
|
+
return fnRef.current(...args);
|
|
481
|
+
});
|
|
482
|
+
setDragListeners((old) => ({
|
|
483
|
+
...old,
|
|
484
|
+
[type]: [...old[type] || [], { id, fn: wrappedFn }]
|
|
485
|
+
}));
|
|
486
|
+
return () => {
|
|
487
|
+
setDragListeners((old) => ({
|
|
488
|
+
...old,
|
|
489
|
+
[type]: (old[type] || []).filter((item) => item.id !== id)
|
|
490
|
+
}));
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
}, [type, setDragListeners, id]);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// components/Drawer/index.tsx
|
|
497
|
+
import { useDraggable, useDroppable } from "@dnd-kit/react";
|
|
498
|
+
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
499
|
+
var getClassName = get_class_name_factory_default("Drawer", styles_module_default2);
|
|
500
|
+
var getClassNameItem = get_class_name_factory_default("DrawerItem", styles_module_default2);
|
|
501
|
+
var DrawerItemInner = ({
|
|
502
|
+
children,
|
|
503
|
+
name,
|
|
504
|
+
label,
|
|
505
|
+
dragRef,
|
|
506
|
+
isDragDisabled
|
|
507
|
+
}) => {
|
|
508
|
+
const CustomInner = useMemo(
|
|
509
|
+
() => children || (({ children: children2 }) => /* @__PURE__ */ jsx4("div", { className: getClassNameItem("default"), children: children2 })),
|
|
510
|
+
[children]
|
|
511
|
+
);
|
|
512
|
+
return /* @__PURE__ */ jsx4(
|
|
513
|
+
"div",
|
|
514
|
+
{
|
|
515
|
+
className: getClassNameItem({ disabled: isDragDisabled }),
|
|
516
|
+
ref: dragRef,
|
|
517
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
518
|
+
"data-testid": dragRef ? `drawer-item:${name}` : "",
|
|
519
|
+
"data-credbuild-drawer-item": true,
|
|
520
|
+
children: /* @__PURE__ */ jsx4(CustomInner, { name, children: /* @__PURE__ */ jsx4("div", { className: getClassNameItem("draggableWrapper"), children: /* @__PURE__ */ jsxs4("div", { className: getClassNameItem("draggable"), children: [
|
|
521
|
+
/* @__PURE__ */ jsx4("div", { className: getClassNameItem("name"), children: label ?? name }),
|
|
522
|
+
/* @__PURE__ */ jsx4("div", { className: getClassNameItem("icon"), children: /* @__PURE__ */ jsx4(DragIcon, {}) })
|
|
523
|
+
] }) }) })
|
|
524
|
+
}
|
|
525
|
+
);
|
|
526
|
+
};
|
|
527
|
+
var DrawerItemDraggable = ({
|
|
528
|
+
children,
|
|
529
|
+
name,
|
|
530
|
+
label,
|
|
531
|
+
id,
|
|
532
|
+
isDragDisabled
|
|
533
|
+
}) => {
|
|
534
|
+
const { ref } = useDraggable({
|
|
535
|
+
id,
|
|
536
|
+
data: { componentType: name },
|
|
537
|
+
disabled: isDragDisabled,
|
|
538
|
+
type: "drawer"
|
|
539
|
+
});
|
|
540
|
+
return /* @__PURE__ */ jsxs4("div", { className: getClassName("draggable"), children: [
|
|
541
|
+
/* @__PURE__ */ jsx4("div", { className: getClassName("draggableBg"), children: /* @__PURE__ */ jsx4(DrawerItemInner, { name, label, children }) }),
|
|
542
|
+
/* @__PURE__ */ jsx4("div", { className: getClassName("draggableFg"), children: /* @__PURE__ */ jsx4(
|
|
543
|
+
DrawerItemInner,
|
|
544
|
+
{
|
|
545
|
+
name,
|
|
546
|
+
label,
|
|
547
|
+
dragRef: ref,
|
|
548
|
+
isDragDisabled,
|
|
549
|
+
children
|
|
550
|
+
}
|
|
551
|
+
) })
|
|
552
|
+
] });
|
|
553
|
+
};
|
|
554
|
+
var DrawerItem = ({
|
|
555
|
+
name,
|
|
556
|
+
children,
|
|
557
|
+
id,
|
|
558
|
+
label,
|
|
559
|
+
index,
|
|
560
|
+
isDragDisabled
|
|
561
|
+
}) => {
|
|
562
|
+
const resolvedId = id || name;
|
|
563
|
+
const [dynamicId, setDynamicId] = useState(generateId(resolvedId));
|
|
564
|
+
if (typeof index !== "undefined") {
|
|
565
|
+
console.error(
|
|
566
|
+
"Warning: The `index` prop on Drawer.Item is deprecated and no longer required."
|
|
567
|
+
);
|
|
568
|
+
}
|
|
569
|
+
useDragListener(
|
|
570
|
+
"dragend",
|
|
571
|
+
() => {
|
|
572
|
+
setDynamicId(generateId(resolvedId));
|
|
573
|
+
},
|
|
574
|
+
[resolvedId]
|
|
575
|
+
);
|
|
576
|
+
return /* @__PURE__ */ jsx4("div", { children: /* @__PURE__ */ jsx4(
|
|
577
|
+
DrawerItemDraggable,
|
|
578
|
+
{
|
|
579
|
+
name,
|
|
580
|
+
label,
|
|
581
|
+
id: dynamicId,
|
|
582
|
+
isDragDisabled,
|
|
583
|
+
children
|
|
584
|
+
}
|
|
585
|
+
) }, dynamicId);
|
|
586
|
+
};
|
|
587
|
+
var Drawer = ({
|
|
588
|
+
children,
|
|
589
|
+
droppableId,
|
|
590
|
+
direction
|
|
591
|
+
}) => {
|
|
592
|
+
if (droppableId) {
|
|
593
|
+
console.error(
|
|
594
|
+
"Warning: The `droppableId` prop on Drawer is deprecated and no longer required."
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
if (direction) {
|
|
598
|
+
console.error(
|
|
599
|
+
"Warning: The `direction` prop on Drawer is deprecated and no longer required to achieve multi-directional dragging."
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
const id = useSafeId();
|
|
603
|
+
const { ref } = useDroppable({
|
|
604
|
+
id,
|
|
605
|
+
type: "void",
|
|
606
|
+
collisionPriority: 0
|
|
607
|
+
// Never collide with this, but we use it so NestedDroppablePlugin respects the Drawer
|
|
608
|
+
});
|
|
609
|
+
return /* @__PURE__ */ jsx4(
|
|
610
|
+
"div",
|
|
611
|
+
{
|
|
612
|
+
className: getClassName(),
|
|
613
|
+
ref,
|
|
614
|
+
"data-credbuild-dnd": id,
|
|
615
|
+
"data-credbuild-drawer": true,
|
|
616
|
+
"data-credbuild-dnd-void": true,
|
|
617
|
+
children
|
|
618
|
+
}
|
|
619
|
+
);
|
|
620
|
+
};
|
|
621
|
+
Drawer.Item = DrawerItem;
|
|
622
|
+
|
|
623
|
+
// lib/overlay-portal/index.tsx
|
|
624
|
+
var registerOverlayPortal = (el, opts = {}) => {
|
|
625
|
+
if (!el) return;
|
|
626
|
+
const { disableDrag = false, disableDragOnFocus = true } = opts;
|
|
627
|
+
const stopPropagation = (e) => {
|
|
628
|
+
e.stopPropagation();
|
|
629
|
+
};
|
|
630
|
+
el.addEventListener("mouseover", stopPropagation, {
|
|
631
|
+
capture: true
|
|
632
|
+
});
|
|
633
|
+
const onFocus = () => {
|
|
634
|
+
setTimeout(() => {
|
|
635
|
+
el.addEventListener("pointerdown", stopPropagation, {
|
|
636
|
+
capture: true
|
|
637
|
+
});
|
|
638
|
+
}, 200);
|
|
639
|
+
};
|
|
640
|
+
const onBlur = () => {
|
|
641
|
+
el.removeEventListener("pointerdown", stopPropagation, {
|
|
642
|
+
capture: true
|
|
643
|
+
});
|
|
644
|
+
};
|
|
645
|
+
if (disableDrag) {
|
|
646
|
+
el.addEventListener("pointerdown", stopPropagation, {
|
|
647
|
+
capture: true
|
|
648
|
+
});
|
|
649
|
+
} else if (disableDragOnFocus) {
|
|
650
|
+
el.addEventListener("focus", onFocus, { capture: true });
|
|
651
|
+
el.addEventListener("blur", onBlur, { capture: true });
|
|
652
|
+
}
|
|
653
|
+
el.setAttribute("data-credbuild-overlay-portal", "true");
|
|
654
|
+
return () => {
|
|
655
|
+
el.removeEventListener("mouseover", stopPropagation, {
|
|
656
|
+
capture: true
|
|
657
|
+
});
|
|
658
|
+
if (disableDrag) {
|
|
659
|
+
el.removeEventListener("pointerdown", stopPropagation, {
|
|
660
|
+
capture: true
|
|
661
|
+
});
|
|
662
|
+
} else if (disableDragOnFocus) {
|
|
663
|
+
el.removeEventListener("focus", onFocus, { capture: true });
|
|
664
|
+
el.removeEventListener("blur", onBlur, { capture: true });
|
|
665
|
+
}
|
|
666
|
+
el.removeAttribute("data-credbuild-overlay-portal");
|
|
667
|
+
};
|
|
668
|
+
};
|
|
669
|
+
|
|
670
|
+
// components/DropZone/index.tsx
|
|
671
|
+
import {
|
|
672
|
+
forwardRef as forwardRef2,
|
|
673
|
+
memo as memo4,
|
|
674
|
+
useCallback as useCallback10,
|
|
675
|
+
useContext as useContext5,
|
|
676
|
+
useEffect as useEffect9,
|
|
677
|
+
useMemo as useMemo8,
|
|
678
|
+
useRef as useRef8
|
|
679
|
+
} from "react";
|
|
680
|
+
import DOMPurify2 from "isomorphic-dompurify";
|
|
681
|
+
|
|
682
|
+
// components/DraggableComponent/index.tsx
|
|
683
|
+
import {
|
|
684
|
+
useCallback as useCallback3,
|
|
685
|
+
useContext as useContext2,
|
|
686
|
+
useEffect as useEffect2,
|
|
687
|
+
useLayoutEffect,
|
|
688
|
+
useMemo as useMemo3,
|
|
689
|
+
useRef as useRef2,
|
|
690
|
+
useState as useState2,
|
|
691
|
+
useTransition
|
|
692
|
+
} from "react";
|
|
693
|
+
|
|
694
|
+
// css-module:/home/runner/work/credbuild/credbuild/components/DraggableComponent/styles.module.css#css-module
|
|
695
|
+
var styles_module_default3 = { "DraggableComponent": "_DraggableComponent_yrtpz_1", "DraggableComponent-overlayWrapper": "_DraggableComponent-overlayWrapper_yrtpz_12", "DraggableComponent-overlay": "_DraggableComponent-overlay_yrtpz_12", "DraggableComponent-loadingOverlay": "_DraggableComponent-loadingOverlay_yrtpz_34", "DraggableComponent--hover": "_DraggableComponent--hover_yrtpz_50", "DraggableComponent--isSelected": "_DraggableComponent--isSelected_yrtpz_57", "DraggableComponent-actionsOverlay": "_DraggableComponent-actionsOverlay_yrtpz_71", "DraggableComponent-actions": "_DraggableComponent-actions_yrtpz_71" };
|
|
696
|
+
|
|
697
|
+
// components/DraggableComponent/index.tsx
|
|
698
|
+
import { createPortal } from "react-dom";
|
|
699
|
+
|
|
700
|
+
// components/DropZone/context.tsx
|
|
701
|
+
import {
|
|
702
|
+
createContext as createContext2,
|
|
703
|
+
useCallback,
|
|
704
|
+
useMemo as useMemo2
|
|
705
|
+
} from "react";
|
|
706
|
+
import { createStore } from "zustand";
|
|
707
|
+
import { Fragment, jsx as jsx5 } from "react/jsx-runtime";
|
|
708
|
+
var dropZoneContext = createContext2(null);
|
|
709
|
+
var ZoneStoreContext = createContext2(
|
|
710
|
+
createStore(() => ({
|
|
711
|
+
zoneDepthIndex: {},
|
|
712
|
+
nextZoneDepthIndex: {},
|
|
713
|
+
areaDepthIndex: {},
|
|
714
|
+
nextAreaDepthIndex: {},
|
|
715
|
+
draggedItem: null,
|
|
716
|
+
previewIndex: {},
|
|
717
|
+
enabledIndex: {},
|
|
718
|
+
hoveringComponent: null,
|
|
719
|
+
registerRootVirtualizer: () => {
|
|
720
|
+
},
|
|
721
|
+
unregisterRootVirtualizer: () => {
|
|
722
|
+
},
|
|
723
|
+
scrollToComponent: () => false
|
|
724
|
+
}))
|
|
725
|
+
);
|
|
726
|
+
var ZoneStoreProvider = ({
|
|
727
|
+
children,
|
|
728
|
+
store
|
|
729
|
+
}) => {
|
|
730
|
+
return /* @__PURE__ */ jsx5(ZoneStoreContext.Provider, { value: store, children });
|
|
731
|
+
};
|
|
732
|
+
var DropZoneProvider = ({
|
|
733
|
+
children,
|
|
734
|
+
value
|
|
735
|
+
}) => {
|
|
736
|
+
const dispatch = useAppStore((s) => s.dispatch);
|
|
737
|
+
const registerZone = useCallback(
|
|
738
|
+
(zoneCompound) => {
|
|
739
|
+
dispatch({
|
|
740
|
+
type: "registerZone",
|
|
741
|
+
zone: zoneCompound
|
|
742
|
+
});
|
|
743
|
+
},
|
|
744
|
+
[dispatch]
|
|
745
|
+
);
|
|
746
|
+
const memoValue = useMemo2(
|
|
747
|
+
() => ({
|
|
748
|
+
registerZone,
|
|
749
|
+
...value
|
|
750
|
+
}),
|
|
751
|
+
[value, registerZone]
|
|
752
|
+
);
|
|
753
|
+
return /* @__PURE__ */ jsx5(Fragment, { children: memoValue && /* @__PURE__ */ jsx5(dropZoneContext.Provider, { value: memoValue, children }) });
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
// lib/get-deep-scroll-position.ts
|
|
757
|
+
function getDeepScrollPosition(element) {
|
|
758
|
+
let totalScroll = {
|
|
759
|
+
x: 0,
|
|
760
|
+
y: 0
|
|
761
|
+
};
|
|
762
|
+
let current = element;
|
|
763
|
+
while (current && current !== document.documentElement) {
|
|
764
|
+
const parent = current.parentElement;
|
|
765
|
+
if (parent) {
|
|
766
|
+
totalScroll.x += parent.scrollLeft;
|
|
767
|
+
totalScroll.y += parent.scrollTop;
|
|
768
|
+
}
|
|
769
|
+
current = parent;
|
|
770
|
+
}
|
|
771
|
+
return totalScroll;
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
// components/DraggableComponent/index.tsx
|
|
775
|
+
import { useShallow } from "zustand/react/shallow";
|
|
776
|
+
import { useSortable } from "@dnd-kit/react/sortable";
|
|
777
|
+
|
|
778
|
+
// lib/dnd/use-on-drag-finished.ts
|
|
779
|
+
import { useCallback as useCallback2 } from "react";
|
|
780
|
+
var useOnDragFinished = (cb, _deps = []) => {
|
|
781
|
+
const appStore = useAppStoreApi();
|
|
782
|
+
return useCallback2(() => {
|
|
783
|
+
let dispose = () => {
|
|
784
|
+
};
|
|
785
|
+
const processDragging = (isDragging2) => {
|
|
786
|
+
if (isDragging2) {
|
|
787
|
+
cb(false);
|
|
788
|
+
} else {
|
|
789
|
+
setTimeout(() => {
|
|
790
|
+
cb(true);
|
|
791
|
+
}, 0);
|
|
792
|
+
if (dispose) dispose();
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
const isDragging = appStore.getState().state.ui.isDragging;
|
|
796
|
+
processDragging(isDragging);
|
|
797
|
+
if (isDragging) {
|
|
798
|
+
dispose = appStore.subscribe(
|
|
799
|
+
(s) => s.state.ui.isDragging,
|
|
800
|
+
(isDragging2) => {
|
|
801
|
+
processDragging(isDragging2);
|
|
802
|
+
}
|
|
803
|
+
);
|
|
804
|
+
}
|
|
805
|
+
return dispose;
|
|
806
|
+
}, [appStore, cb]);
|
|
807
|
+
};
|
|
808
|
+
|
|
809
|
+
// lib/assign-refs.ts
|
|
810
|
+
function assignRef(ref, node) {
|
|
811
|
+
if (typeof ref === "function") {
|
|
812
|
+
ref(node);
|
|
813
|
+
} else if (ref && typeof ref === "object" && "current" in ref) {
|
|
814
|
+
ref.current = node;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
function assignRefs(refs, node) {
|
|
818
|
+
refs.forEach((ref) => {
|
|
819
|
+
assignRef(ref, node);
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
// components/DraggableComponent/index.tsx
|
|
824
|
+
import { Fragment as Fragment2, jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
825
|
+
var getClassName2 = get_class_name_factory_default("DraggableComponent", styles_module_default3);
|
|
826
|
+
var DEBUG = false;
|
|
827
|
+
var MEASURE_EVERY_MS = 100;
|
|
828
|
+
var space = 8;
|
|
829
|
+
var actionsOverlayTop = space * 6.5;
|
|
830
|
+
var actionsTop = -(actionsOverlayTop - 8);
|
|
831
|
+
var actionsSide = space;
|
|
832
|
+
var DefaultActionBar = ({
|
|
833
|
+
label,
|
|
834
|
+
children,
|
|
835
|
+
parentAction
|
|
836
|
+
}) => /* @__PURE__ */ jsxs5(ActionBar, { children: [
|
|
837
|
+
/* @__PURE__ */ jsxs5(ActionBar.Group, { children: [
|
|
838
|
+
parentAction,
|
|
839
|
+
label && /* @__PURE__ */ jsx6(ActionBar.Label, { label })
|
|
840
|
+
] }),
|
|
841
|
+
/* @__PURE__ */ jsx6(ActionBar.Group, { children })
|
|
842
|
+
] });
|
|
843
|
+
var DefaultOverlay = ({
|
|
844
|
+
children
|
|
845
|
+
}) => /* @__PURE__ */ jsx6(Fragment2, { children });
|
|
846
|
+
var DraggableComponent = ({
|
|
847
|
+
children,
|
|
848
|
+
depth,
|
|
849
|
+
componentType,
|
|
850
|
+
id,
|
|
851
|
+
index,
|
|
852
|
+
zoneCompound,
|
|
853
|
+
isLoading = false,
|
|
854
|
+
isSelected = false,
|
|
855
|
+
debug,
|
|
856
|
+
label,
|
|
857
|
+
autoDragAxis,
|
|
858
|
+
userDragAxis,
|
|
859
|
+
inDroppableZone = true,
|
|
860
|
+
itemRef
|
|
861
|
+
}) => {
|
|
862
|
+
const zoom = useAppStore(
|
|
863
|
+
(s) => s.selectedItem?.props.id === id ? s.zoomConfig.zoom : 1
|
|
864
|
+
);
|
|
865
|
+
const _experimentalFullScreenCanvas = useAppStore(
|
|
866
|
+
(s) => s._experimentalFullScreenCanvas
|
|
867
|
+
);
|
|
868
|
+
const overrides = useAppStore((s) => s.overrides);
|
|
869
|
+
const dispatch = useAppStore((s) => s.dispatch);
|
|
870
|
+
const appStore = useAppStoreApi();
|
|
871
|
+
const isIframeEnabled = useAppStore((s) => s.iframe.enabled);
|
|
872
|
+
const lastMeasureRef = useRef2(0);
|
|
873
|
+
const ctx = useContext2(dropZoneContext);
|
|
874
|
+
const [localZones, setLocalZones] = useState2({});
|
|
875
|
+
const registerLocalZone = useCallback3(
|
|
876
|
+
(zoneCompound2, active) => {
|
|
877
|
+
ctx?.registerLocalZone?.(zoneCompound2, active);
|
|
878
|
+
setLocalZones((obj) => ({
|
|
879
|
+
...obj,
|
|
880
|
+
[zoneCompound2]: active
|
|
881
|
+
}));
|
|
882
|
+
},
|
|
883
|
+
[setLocalZones, ctx]
|
|
884
|
+
);
|
|
885
|
+
const unregisterLocalZone = useCallback3(
|
|
886
|
+
(zoneCompound2) => {
|
|
887
|
+
ctx?.unregisterLocalZone?.(zoneCompound2);
|
|
888
|
+
setLocalZones((obj) => {
|
|
889
|
+
const newLocalZones = {
|
|
890
|
+
...obj
|
|
891
|
+
};
|
|
892
|
+
delete newLocalZones[zoneCompound2];
|
|
893
|
+
return newLocalZones;
|
|
894
|
+
});
|
|
895
|
+
},
|
|
896
|
+
[setLocalZones, ctx]
|
|
897
|
+
);
|
|
898
|
+
const containsActiveZone = Object.values(localZones).filter(Boolean).length > 0;
|
|
899
|
+
const path = useAppStore(useShallow((s) => s.state.indexes.nodes[id]?.path));
|
|
900
|
+
const permissions = useAppStore(
|
|
901
|
+
useShallow((s) => {
|
|
902
|
+
const item = getItem({ index, zone: zoneCompound }, s.state);
|
|
903
|
+
return s.permissions.getPermissions({ item });
|
|
904
|
+
})
|
|
905
|
+
);
|
|
906
|
+
const zoneStore = useContext2(ZoneStoreContext);
|
|
907
|
+
const [dragAxis, setDragAxis] = useState2(userDragAxis || autoDragAxis);
|
|
908
|
+
const dynamicCollisionDetector = useMemo3(
|
|
909
|
+
() => createDynamicCollisionDetector(dragAxis),
|
|
910
|
+
[dragAxis]
|
|
911
|
+
);
|
|
912
|
+
const {
|
|
913
|
+
ref: sortableRef,
|
|
914
|
+
isDragging: thisIsDragging,
|
|
915
|
+
sortable
|
|
916
|
+
} = useSortable({
|
|
917
|
+
id,
|
|
918
|
+
index,
|
|
919
|
+
group: zoneCompound,
|
|
920
|
+
type: "component",
|
|
921
|
+
data: {
|
|
922
|
+
areaId: ctx?.areaId,
|
|
923
|
+
zone: zoneCompound,
|
|
924
|
+
index,
|
|
925
|
+
componentType,
|
|
926
|
+
containsActiveZone,
|
|
927
|
+
depth,
|
|
928
|
+
path: path || [],
|
|
929
|
+
inDroppableZone
|
|
930
|
+
},
|
|
931
|
+
collisionPriority: depth,
|
|
932
|
+
collisionDetector: dynamicCollisionDetector,
|
|
933
|
+
// "Out of the way" transition from react-beautiful-dnd
|
|
934
|
+
transition: {
|
|
935
|
+
duration: 200,
|
|
936
|
+
easing: "cubic-bezier(0.2, 0, 0, 1)"
|
|
937
|
+
},
|
|
938
|
+
feedback: "clone"
|
|
939
|
+
});
|
|
940
|
+
useEffect2(() => {
|
|
941
|
+
const isEnabled = zoneStore.getState().enabledIndex[zoneCompound];
|
|
942
|
+
sortable.droppable.disabled = !isEnabled;
|
|
943
|
+
sortable.draggable.disabled = !permissions.drag;
|
|
944
|
+
const cleanup = zoneStore.subscribe((s) => {
|
|
945
|
+
sortable.droppable.disabled = !s.enabledIndex[zoneCompound];
|
|
946
|
+
});
|
|
947
|
+
if (ref.current && !permissions.drag) {
|
|
948
|
+
ref.current.setAttribute("data-credbuild-disabled", "");
|
|
949
|
+
return () => {
|
|
950
|
+
ref.current?.removeAttribute("data-credbuild-disabled");
|
|
951
|
+
cleanup();
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
return cleanup;
|
|
955
|
+
}, [permissions.drag, zoneCompound, sortable.draggable, sortable.droppable, zoneStore]);
|
|
956
|
+
const [, setRerender] = useState2(0);
|
|
957
|
+
const ref = useRef2(null);
|
|
958
|
+
const refSetter = useCallback3(
|
|
959
|
+
(el) => {
|
|
960
|
+
sortableRef(el);
|
|
961
|
+
if (ref.current !== el) {
|
|
962
|
+
ref.current = el;
|
|
963
|
+
setRerender((update) => update + 1);
|
|
964
|
+
if (itemRef) {
|
|
965
|
+
assignRefs([itemRef], el);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
},
|
|
969
|
+
[itemRef, sortableRef]
|
|
970
|
+
);
|
|
971
|
+
const [portalEl, setPortalEl] = useState2();
|
|
972
|
+
useEffect2(() => {
|
|
973
|
+
setPortalEl(
|
|
974
|
+
isIframeEnabled ? ref.current?.ownerDocument.body : ref.current?.closest("[data-credbuild-preview]") ?? document.body
|
|
975
|
+
);
|
|
976
|
+
}, [isIframeEnabled]);
|
|
977
|
+
const getStyle = useCallback3(() => {
|
|
978
|
+
if (!ref.current) return;
|
|
979
|
+
const el = ref.current;
|
|
980
|
+
const rect = el.getBoundingClientRect();
|
|
981
|
+
const portalContainerEl = isIframeEnabled ? null : el.closest("[data-credbuild-preview]");
|
|
982
|
+
const targetIsFixed = (() => {
|
|
983
|
+
let node = el;
|
|
984
|
+
while (node && node !== document.documentElement) {
|
|
985
|
+
if (getComputedStyle(node).position === "fixed") {
|
|
986
|
+
return true;
|
|
987
|
+
}
|
|
988
|
+
node = node.parentElement;
|
|
989
|
+
}
|
|
990
|
+
return false;
|
|
991
|
+
})();
|
|
992
|
+
const portalContainerRect = portalContainerEl?.getBoundingClientRect();
|
|
993
|
+
const portalScroll = portalContainerEl ? getDeepScrollPosition(portalContainerEl) : { x: 0, y: 0 };
|
|
994
|
+
const deepScrollPosition = targetIsFixed ? { x: 0, y: 0 } : getDeepScrollPosition(el);
|
|
995
|
+
const scroll = targetIsFixed ? { x: 0, y: 0 } : {
|
|
996
|
+
x: deepScrollPosition.x - portalScroll.x - (portalContainerRect?.left ?? 0),
|
|
997
|
+
y: deepScrollPosition.y - portalScroll.y - (portalContainerRect?.top ?? 0)
|
|
998
|
+
};
|
|
999
|
+
const zoomMultiplier = isIframeEnabled ? 1 : appStore.getState().zoomConfig.zoom;
|
|
1000
|
+
const style2 = {
|
|
1001
|
+
left: `${(rect.left + scroll.x) / zoomMultiplier}px`,
|
|
1002
|
+
top: `${(rect.top + scroll.y) / zoomMultiplier}px`,
|
|
1003
|
+
height: `${rect.height / zoomMultiplier}px`,
|
|
1004
|
+
width: `${rect.width / zoomMultiplier}px`,
|
|
1005
|
+
position: targetIsFixed ? "fixed" : void 0
|
|
1006
|
+
};
|
|
1007
|
+
return style2;
|
|
1008
|
+
}, [isIframeEnabled]);
|
|
1009
|
+
const [style, setStyle] = useState2();
|
|
1010
|
+
const lastRectRef = useRef2(null);
|
|
1011
|
+
const syncRafRef = useRef2(null);
|
|
1012
|
+
const sync = useCallback3(() => {
|
|
1013
|
+
setStyle(getStyle());
|
|
1014
|
+
if (itemRef) {
|
|
1015
|
+
assignRefs([itemRef], ref.current);
|
|
1016
|
+
}
|
|
1017
|
+
}, [getStyle, itemRef]);
|
|
1018
|
+
const scheduleSync = useCallback3(() => {
|
|
1019
|
+
if (syncRafRef.current != null) return;
|
|
1020
|
+
syncRafRef.current = requestAnimationFrame(() => {
|
|
1021
|
+
syncRafRef.current = null;
|
|
1022
|
+
sync();
|
|
1023
|
+
});
|
|
1024
|
+
}, [sync]);
|
|
1025
|
+
useEffect2(() => {
|
|
1026
|
+
return () => {
|
|
1027
|
+
if (syncRafRef.current != null) {
|
|
1028
|
+
cancelAnimationFrame(syncRafRef.current);
|
|
1029
|
+
syncRafRef.current = null;
|
|
1030
|
+
}
|
|
1031
|
+
};
|
|
1032
|
+
}, []);
|
|
1033
|
+
useEffect2(() => {
|
|
1034
|
+
if (ref.current) {
|
|
1035
|
+
const observer = new ResizeObserver(() => {
|
|
1036
|
+
scheduleSync();
|
|
1037
|
+
});
|
|
1038
|
+
observer.observe(ref.current);
|
|
1039
|
+
return () => {
|
|
1040
|
+
observer.disconnect();
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
}, [scheduleSync, itemRef]);
|
|
1044
|
+
const registerNode = useAppStore((s) => s.nodes.registerNode);
|
|
1045
|
+
const unregisterNode = useAppStore((s) => s.nodes.unregisterNode);
|
|
1046
|
+
const hideOverlay = useCallback3(() => {
|
|
1047
|
+
setIsVisible(false);
|
|
1048
|
+
}, []);
|
|
1049
|
+
const showOverlay = useCallback3(() => {
|
|
1050
|
+
setIsVisible(true);
|
|
1051
|
+
}, []);
|
|
1052
|
+
const nodeHandleRef = useRef2({
|
|
1053
|
+
sync: () => null,
|
|
1054
|
+
hideOverlay: () => null,
|
|
1055
|
+
showOverlay: () => null
|
|
1056
|
+
});
|
|
1057
|
+
useLayoutEffect(() => {
|
|
1058
|
+
nodeHandleRef.current.sync = sync;
|
|
1059
|
+
nodeHandleRef.current.hideOverlay = hideOverlay;
|
|
1060
|
+
nodeHandleRef.current.showOverlay = showOverlay;
|
|
1061
|
+
}, [hideOverlay, showOverlay, sync]);
|
|
1062
|
+
useEffect2(() => {
|
|
1063
|
+
registerNode(id, nodeHandleRef.current);
|
|
1064
|
+
return () => {
|
|
1065
|
+
unregisterNode(id);
|
|
1066
|
+
};
|
|
1067
|
+
}, [id, registerNode, unregisterNode]);
|
|
1068
|
+
const CustomActionBar = useMemo3(
|
|
1069
|
+
() => overrides.actionBar || DefaultActionBar,
|
|
1070
|
+
[overrides.actionBar]
|
|
1071
|
+
);
|
|
1072
|
+
const CustomOverlay = useMemo3(
|
|
1073
|
+
() => overrides.componentOverlay || DefaultOverlay,
|
|
1074
|
+
[overrides.componentOverlay]
|
|
1075
|
+
);
|
|
1076
|
+
const onClick = useCallback3(
|
|
1077
|
+
(e) => {
|
|
1078
|
+
const userIsDragging = !!zoneStore.getState().draggedItem;
|
|
1079
|
+
if (userIsDragging) {
|
|
1080
|
+
return;
|
|
1081
|
+
}
|
|
1082
|
+
const el = e.target;
|
|
1083
|
+
if (!el.closest("[data-credbuild-overlay-portal]")) {
|
|
1084
|
+
e.stopPropagation();
|
|
1085
|
+
}
|
|
1086
|
+
if (_experimentalFullScreenCanvas) {
|
|
1087
|
+
dispatch({
|
|
1088
|
+
type: "setUi",
|
|
1089
|
+
ui: {
|
|
1090
|
+
itemSelector: isSelected ? null : { index, zone: zoneCompound }
|
|
1091
|
+
}
|
|
1092
|
+
});
|
|
1093
|
+
} else {
|
|
1094
|
+
dispatch({
|
|
1095
|
+
type: "setUi",
|
|
1096
|
+
ui: {
|
|
1097
|
+
itemSelector: { index, zone: zoneCompound }
|
|
1098
|
+
}
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
},
|
|
1102
|
+
[index, zoneCompound, isSelected, _experimentalFullScreenCanvas, dispatch, zoneStore]
|
|
1103
|
+
);
|
|
1104
|
+
const onSelectParent = useCallback3(() => {
|
|
1105
|
+
const { nodes, zones } = appStore.getState().state.indexes;
|
|
1106
|
+
const node = nodes[id];
|
|
1107
|
+
const parentNode = node?.parentId ? nodes[node?.parentId] : null;
|
|
1108
|
+
if (!parentNode || !node.parentId) {
|
|
1109
|
+
return;
|
|
1110
|
+
}
|
|
1111
|
+
const parentZoneCompound = `${parentNode.parentId}:${parentNode.zone}`;
|
|
1112
|
+
const parentIndex = zones[parentZoneCompound].contentIds.indexOf(
|
|
1113
|
+
node.parentId
|
|
1114
|
+
);
|
|
1115
|
+
dispatch({
|
|
1116
|
+
type: "setUi",
|
|
1117
|
+
ui: {
|
|
1118
|
+
itemSelector: {
|
|
1119
|
+
zone: parentZoneCompound,
|
|
1120
|
+
index: parentIndex
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
});
|
|
1124
|
+
}, [appStore, dispatch, id]);
|
|
1125
|
+
const onDuplicate = useCallback3(() => {
|
|
1126
|
+
dispatch({
|
|
1127
|
+
type: "duplicate",
|
|
1128
|
+
sourceIndex: index,
|
|
1129
|
+
sourceZone: zoneCompound
|
|
1130
|
+
});
|
|
1131
|
+
}, [index, zoneCompound, dispatch]);
|
|
1132
|
+
const onDelete = useCallback3(() => {
|
|
1133
|
+
dispatch({
|
|
1134
|
+
type: "remove",
|
|
1135
|
+
index,
|
|
1136
|
+
zone: zoneCompound
|
|
1137
|
+
});
|
|
1138
|
+
}, [index, zoneCompound, dispatch]);
|
|
1139
|
+
const [hover, setHover] = useState2(false);
|
|
1140
|
+
const indicativeHover = useContextStore(
|
|
1141
|
+
ZoneStoreContext,
|
|
1142
|
+
(s) => s.hoveringComponent === id
|
|
1143
|
+
);
|
|
1144
|
+
useEffect2(() => {
|
|
1145
|
+
if (!ref.current) {
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
const el = ref.current;
|
|
1149
|
+
const _onMouseOver = (e) => {
|
|
1150
|
+
const userIsDragging = !!zoneStore.getState().draggedItem;
|
|
1151
|
+
if (userIsDragging) {
|
|
1152
|
+
if (containsActiveZone) {
|
|
1153
|
+
setHover(true);
|
|
1154
|
+
} else {
|
|
1155
|
+
setHover(false);
|
|
1156
|
+
}
|
|
1157
|
+
} else {
|
|
1158
|
+
setHover(true);
|
|
1159
|
+
}
|
|
1160
|
+
e.stopPropagation();
|
|
1161
|
+
};
|
|
1162
|
+
const _onMouseOut = (e) => {
|
|
1163
|
+
e.stopPropagation();
|
|
1164
|
+
setHover(false);
|
|
1165
|
+
};
|
|
1166
|
+
el.setAttribute("data-credbuild-component", id);
|
|
1167
|
+
el.setAttribute("data-credbuild-dnd", id);
|
|
1168
|
+
el.style.position = "relative";
|
|
1169
|
+
el.addEventListener("click", onClick);
|
|
1170
|
+
el.addEventListener("mouseover", _onMouseOver);
|
|
1171
|
+
el.addEventListener("mouseout", _onMouseOut);
|
|
1172
|
+
return () => {
|
|
1173
|
+
el.removeAttribute("data-credbuild-component");
|
|
1174
|
+
el.removeAttribute("data-credbuild-dnd");
|
|
1175
|
+
el.removeEventListener("click", onClick);
|
|
1176
|
+
el.removeEventListener("mouseover", _onMouseOver);
|
|
1177
|
+
el.removeEventListener("mouseout", _onMouseOut);
|
|
1178
|
+
};
|
|
1179
|
+
}, [
|
|
1180
|
+
ref,
|
|
1181
|
+
// Remount attributes if the element changes
|
|
1182
|
+
onClick,
|
|
1183
|
+
containsActiveZone,
|
|
1184
|
+
zoneCompound,
|
|
1185
|
+
setHover,
|
|
1186
|
+
thisIsDragging,
|
|
1187
|
+
inDroppableZone,
|
|
1188
|
+
zoneStore,
|
|
1189
|
+
id
|
|
1190
|
+
]);
|
|
1191
|
+
const [isVisible, setIsVisible] = useState2(false);
|
|
1192
|
+
const [dragFinished, setDragFinished] = useState2(true);
|
|
1193
|
+
const [_, startTransition] = useTransition();
|
|
1194
|
+
useEffect2(() => {
|
|
1195
|
+
startTransition(() => {
|
|
1196
|
+
if (hover || indicativeHover || isSelected) {
|
|
1197
|
+
scheduleSync();
|
|
1198
|
+
setIsVisible(true);
|
|
1199
|
+
setThisWasDragging(false);
|
|
1200
|
+
} else {
|
|
1201
|
+
setIsVisible(false);
|
|
1202
|
+
}
|
|
1203
|
+
});
|
|
1204
|
+
}, [hover, indicativeHover, isSelected, isIframeEnabled, scheduleSync]);
|
|
1205
|
+
const [thisWasDragging, setThisWasDragging] = useState2(false);
|
|
1206
|
+
const onDragFinished = useOnDragFinished(
|
|
1207
|
+
useCallback3(
|
|
1208
|
+
(finished) => {
|
|
1209
|
+
if (finished) {
|
|
1210
|
+
startTransition(() => {
|
|
1211
|
+
sync();
|
|
1212
|
+
setDragFinished(true);
|
|
1213
|
+
});
|
|
1214
|
+
} else {
|
|
1215
|
+
setDragFinished(false);
|
|
1216
|
+
}
|
|
1217
|
+
},
|
|
1218
|
+
[sync, startTransition]
|
|
1219
|
+
)
|
|
1220
|
+
);
|
|
1221
|
+
useEffect2(() => {
|
|
1222
|
+
if (thisIsDragging) {
|
|
1223
|
+
setThisWasDragging(true);
|
|
1224
|
+
}
|
|
1225
|
+
}, [thisIsDragging]);
|
|
1226
|
+
useEffect2(() => {
|
|
1227
|
+
if (thisWasDragging) return onDragFinished();
|
|
1228
|
+
}, [thisWasDragging, onDragFinished]);
|
|
1229
|
+
useEffect2(() => {
|
|
1230
|
+
if (!dragFinished || !(isSelected || thisIsDragging)) return;
|
|
1231
|
+
const el = ref.current;
|
|
1232
|
+
if (!el) return;
|
|
1233
|
+
const doc = el.ownerDocument;
|
|
1234
|
+
const view = doc.defaultView;
|
|
1235
|
+
if (!view) return;
|
|
1236
|
+
lastMeasureRef.current = 0;
|
|
1237
|
+
scheduleSync();
|
|
1238
|
+
const onScroll = () => scheduleSync();
|
|
1239
|
+
const onResize = () => scheduleSync();
|
|
1240
|
+
doc.addEventListener("scroll", onScroll, true);
|
|
1241
|
+
view.addEventListener("resize", onResize);
|
|
1242
|
+
let frame = 0;
|
|
1243
|
+
const tick = (t) => {
|
|
1244
|
+
if (t - lastMeasureRef.current >= MEASURE_EVERY_MS) {
|
|
1245
|
+
lastMeasureRef.current = t;
|
|
1246
|
+
const node = ref.current;
|
|
1247
|
+
if (node) {
|
|
1248
|
+
const rect = node.getBoundingClientRect();
|
|
1249
|
+
const prev = lastRectRef.current;
|
|
1250
|
+
const changed = !prev || Math.abs(rect.x - prev.x) > 0.5 || Math.abs(rect.y - prev.y) > 0.5 || Math.abs(rect.width - prev.width) > 0.5 || Math.abs(rect.height - prev.height) > 0.5;
|
|
1251
|
+
if (changed) {
|
|
1252
|
+
lastRectRef.current = rect;
|
|
1253
|
+
scheduleSync();
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
frame = requestAnimationFrame(tick);
|
|
1258
|
+
};
|
|
1259
|
+
frame = requestAnimationFrame(tick);
|
|
1260
|
+
return () => {
|
|
1261
|
+
doc.removeEventListener("scroll", onScroll, true);
|
|
1262
|
+
view.removeEventListener("resize", onResize);
|
|
1263
|
+
cancelAnimationFrame(frame);
|
|
1264
|
+
};
|
|
1265
|
+
}, [dragFinished, isSelected, thisIsDragging, scheduleSync]);
|
|
1266
|
+
const syncActionsPosition = useCallback3(
|
|
1267
|
+
(el) => {
|
|
1268
|
+
if (el) {
|
|
1269
|
+
const view = el.ownerDocument.defaultView;
|
|
1270
|
+
if (view) {
|
|
1271
|
+
const rect = el.getBoundingClientRect();
|
|
1272
|
+
const diffLeft = rect.x;
|
|
1273
|
+
const exceedsBoundsLeft = diffLeft < 0;
|
|
1274
|
+
const diffTop = rect.y;
|
|
1275
|
+
const exceedsBoundsTop = diffTop < 0;
|
|
1276
|
+
if (exceedsBoundsLeft) {
|
|
1277
|
+
el.style.transformOrigin = "left top";
|
|
1278
|
+
el.style.left = "0px";
|
|
1279
|
+
}
|
|
1280
|
+
if (exceedsBoundsTop) {
|
|
1281
|
+
el.style.top = "12px";
|
|
1282
|
+
if (!exceedsBoundsLeft) {
|
|
1283
|
+
el.style.transformOrigin = "right top";
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
},
|
|
1289
|
+
[]
|
|
1290
|
+
);
|
|
1291
|
+
useEffect2(() => {
|
|
1292
|
+
if (userDragAxis) {
|
|
1293
|
+
setDragAxis(userDragAxis);
|
|
1294
|
+
return;
|
|
1295
|
+
}
|
|
1296
|
+
if (ref.current) {
|
|
1297
|
+
const computedStyle = window.getComputedStyle(ref.current);
|
|
1298
|
+
if (computedStyle.display === "inline" || computedStyle.display === "inline-block") {
|
|
1299
|
+
setDragAxis("x");
|
|
1300
|
+
return;
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
setDragAxis(autoDragAxis);
|
|
1304
|
+
}, [ref, userDragAxis, autoDragAxis]);
|
|
1305
|
+
const parentAction = useMemo3(
|
|
1306
|
+
() => ctx?.areaId && ctx?.areaId !== "root" && /* @__PURE__ */ jsx6(ActionBar.Action, { onClick: onSelectParent, label: "Select parent", children: /* @__PURE__ */ jsx6(CornerLeftUp, { size: 16 }) }),
|
|
1307
|
+
[ctx?.areaId, onSelectParent]
|
|
1308
|
+
);
|
|
1309
|
+
const nextContextValue = useMemo3(
|
|
1310
|
+
() => ({
|
|
1311
|
+
...ctx,
|
|
1312
|
+
areaId: id,
|
|
1313
|
+
zoneCompound,
|
|
1314
|
+
index,
|
|
1315
|
+
depth: depth + 1,
|
|
1316
|
+
registerLocalZone,
|
|
1317
|
+
unregisterLocalZone
|
|
1318
|
+
}),
|
|
1319
|
+
[
|
|
1320
|
+
ctx,
|
|
1321
|
+
id,
|
|
1322
|
+
zoneCompound,
|
|
1323
|
+
index,
|
|
1324
|
+
depth,
|
|
1325
|
+
registerLocalZone,
|
|
1326
|
+
unregisterLocalZone
|
|
1327
|
+
]
|
|
1328
|
+
);
|
|
1329
|
+
const richText = useAppStore(
|
|
1330
|
+
(s) => s.currentRichText?.inlineComponentId === id ? s.currentRichText : null
|
|
1331
|
+
);
|
|
1332
|
+
const hasNormalActions = permissions.duplicate || permissions.delete;
|
|
1333
|
+
return /* @__PURE__ */ jsxs5(DropZoneProvider, { value: nextContextValue, children: [
|
|
1334
|
+
dragFinished && isVisible && createPortal(
|
|
1335
|
+
/* @__PURE__ */ jsxs5(
|
|
1336
|
+
"div",
|
|
1337
|
+
{
|
|
1338
|
+
className: getClassName2({
|
|
1339
|
+
isSelected,
|
|
1340
|
+
isDragging: thisIsDragging,
|
|
1341
|
+
hover: hover || indicativeHover
|
|
1342
|
+
}),
|
|
1343
|
+
style: { ...style },
|
|
1344
|
+
"data-credbuild-overlay": true,
|
|
1345
|
+
children: [
|
|
1346
|
+
debug,
|
|
1347
|
+
isLoading && /* @__PURE__ */ jsx6("div", { className: getClassName2("loadingOverlay"), children: /* @__PURE__ */ jsx6(Loader, {}) }),
|
|
1348
|
+
/* @__PURE__ */ jsx6(
|
|
1349
|
+
"div",
|
|
1350
|
+
{
|
|
1351
|
+
className: getClassName2("actionsOverlay"),
|
|
1352
|
+
style: {
|
|
1353
|
+
top: actionsOverlayTop / zoom
|
|
1354
|
+
},
|
|
1355
|
+
children: /* @__PURE__ */ jsx6(
|
|
1356
|
+
"div",
|
|
1357
|
+
{
|
|
1358
|
+
className: getClassName2("actions"),
|
|
1359
|
+
style: {
|
|
1360
|
+
transform: `scale(${1 / zoom}`,
|
|
1361
|
+
top: actionsTop / zoom,
|
|
1362
|
+
right: 0,
|
|
1363
|
+
paddingLeft: actionsSide,
|
|
1364
|
+
paddingRight: actionsSide
|
|
1365
|
+
},
|
|
1366
|
+
ref: syncActionsPosition,
|
|
1367
|
+
children: /* @__PURE__ */ jsxs5(
|
|
1368
|
+
CustomActionBar,
|
|
1369
|
+
{
|
|
1370
|
+
parentAction,
|
|
1371
|
+
label: DEBUG ? id : label,
|
|
1372
|
+
children: [
|
|
1373
|
+
richText && /* @__PURE__ */ jsxs5(Fragment2, { children: [
|
|
1374
|
+
/* @__PURE__ */ jsx6(
|
|
1375
|
+
LoadedRichTextMenu,
|
|
1376
|
+
{
|
|
1377
|
+
editor: richText.editor,
|
|
1378
|
+
field: richText.field,
|
|
1379
|
+
inline: true,
|
|
1380
|
+
readOnly: false
|
|
1381
|
+
}
|
|
1382
|
+
),
|
|
1383
|
+
hasNormalActions && /* @__PURE__ */ jsx6(ActionBar.Separator, {})
|
|
1384
|
+
] }),
|
|
1385
|
+
permissions.duplicate && /* @__PURE__ */ jsx6(ActionBar.Action, { onClick: onDuplicate, label: "Duplicate", children: /* @__PURE__ */ jsx6(Copy, { size: 16 }) }),
|
|
1386
|
+
permissions.delete && /* @__PURE__ */ jsx6(ActionBar.Action, { onClick: onDelete, label: "Delete", children: /* @__PURE__ */ jsx6(Trash, { size: 16 }) })
|
|
1387
|
+
]
|
|
1388
|
+
}
|
|
1389
|
+
)
|
|
1390
|
+
}
|
|
1391
|
+
)
|
|
1392
|
+
}
|
|
1393
|
+
),
|
|
1394
|
+
/* @__PURE__ */ jsx6("div", { className: getClassName2("overlayWrapper"), children: /* @__PURE__ */ jsx6(
|
|
1395
|
+
CustomOverlay,
|
|
1396
|
+
{
|
|
1397
|
+
componentId: id,
|
|
1398
|
+
componentType,
|
|
1399
|
+
hover,
|
|
1400
|
+
isSelected,
|
|
1401
|
+
children: /* @__PURE__ */ jsx6("div", { className: getClassName2("overlay") })
|
|
1402
|
+
}
|
|
1403
|
+
) })
|
|
1404
|
+
]
|
|
1405
|
+
}
|
|
1406
|
+
),
|
|
1407
|
+
portalEl || document.body
|
|
1408
|
+
),
|
|
1409
|
+
children(refSetter)
|
|
1410
|
+
] });
|
|
1411
|
+
};
|
|
1412
|
+
|
|
1413
|
+
// css-module:/home/runner/work/credbuild/credbuild/components/DropZone/styles.module.css#css-module
|
|
1414
|
+
var styles_module_default4 = { "DropZone": "_DropZone_1vmgt_1", "DropZone--hasChildren": "_DropZone--hasChildren_1vmgt_11", "DropZone--isAreaSelected": "_DropZone--isAreaSelected_1vmgt_24", "DropZone--hoveringOverArea": "_DropZone--hoveringOverArea_1vmgt_25", "DropZone--isRootZone": "_DropZone--isRootZone_1vmgt_25", "DropZone--isDestination": "_DropZone--isDestination_1vmgt_35", "DropZone-item": "_DropZone-item_1vmgt_47", "DropZone-hitbox": "_DropZone-hitbox_1vmgt_51", "DropZone--isEnabled": "_DropZone--isEnabled_1vmgt_59", "DropZone--isAnimating": "_DropZone--isAnimating_1vmgt_68" };
|
|
1415
|
+
|
|
1416
|
+
// components/DropZone/index.tsx
|
|
1417
|
+
import { useDroppable as useDroppable2 } from "@dnd-kit/react";
|
|
1418
|
+
import { pointerIntersection } from "@dnd-kit/collision";
|
|
1419
|
+
|
|
1420
|
+
// components/DropZone/lib/use-min-empty-height.ts
|
|
1421
|
+
import { useCallback as useCallback4, useEffect as useEffect3, useRef as useRef3, useState as useState3 } from "react";
|
|
1422
|
+
var getNumItems = (appStore, zoneCompound) => appStore.getState().state.indexes.zones[zoneCompound].contentIds.length;
|
|
1423
|
+
var useMinEmptyHeight = ({
|
|
1424
|
+
zoneCompound,
|
|
1425
|
+
userMinEmptyHeight,
|
|
1426
|
+
ref
|
|
1427
|
+
}) => {
|
|
1428
|
+
const appStore = useAppStoreApi();
|
|
1429
|
+
const [prevHeight, setPrevHeight] = useState3(0);
|
|
1430
|
+
const [isAnimating, setIsAnimating] = useState3(false);
|
|
1431
|
+
const { draggedItem, isZone } = useContextStore(ZoneStoreContext, (s) => {
|
|
1432
|
+
return {
|
|
1433
|
+
draggedItem: s.draggedItem?.data.zone === zoneCompound ? s.draggedItem : null,
|
|
1434
|
+
isZone: s.draggedItem?.data.zone === zoneCompound
|
|
1435
|
+
};
|
|
1436
|
+
});
|
|
1437
|
+
const numItems = useRef3(0);
|
|
1438
|
+
const onDragFinished = useOnDragFinished(
|
|
1439
|
+
useCallback4(
|
|
1440
|
+
(finished) => {
|
|
1441
|
+
if (finished) {
|
|
1442
|
+
const newNumItems = getNumItems(appStore, zoneCompound);
|
|
1443
|
+
setPrevHeight(0);
|
|
1444
|
+
if (newNumItems || numItems.current === 0) {
|
|
1445
|
+
setIsAnimating(false);
|
|
1446
|
+
return;
|
|
1447
|
+
}
|
|
1448
|
+
const selectedItem = appStore.getState().selectedItem;
|
|
1449
|
+
const zones = appStore.getState().state.indexes.zones;
|
|
1450
|
+
const nodes = appStore.getState().nodes;
|
|
1451
|
+
nodes.setOverlayVisible(selectedItem?.props.id, false);
|
|
1452
|
+
setTimeout(() => {
|
|
1453
|
+
const contentIds = zones[zoneCompound]?.contentIds || [];
|
|
1454
|
+
nodes.syncNodes(contentIds);
|
|
1455
|
+
if (selectedItem) {
|
|
1456
|
+
setTimeout(() => {
|
|
1457
|
+
nodes.syncNode(selectedItem.props.id);
|
|
1458
|
+
nodes.setOverlayVisible(selectedItem.props.id, true);
|
|
1459
|
+
}, 200);
|
|
1460
|
+
}
|
|
1461
|
+
setIsAnimating(false);
|
|
1462
|
+
}, 100);
|
|
1463
|
+
}
|
|
1464
|
+
},
|
|
1465
|
+
[appStore, zoneCompound]
|
|
1466
|
+
)
|
|
1467
|
+
);
|
|
1468
|
+
useEffect3(() => {
|
|
1469
|
+
if (draggedItem && ref.current) {
|
|
1470
|
+
if (isZone) {
|
|
1471
|
+
const rect = ref.current.getBoundingClientRect();
|
|
1472
|
+
numItems.current = getNumItems(appStore, zoneCompound);
|
|
1473
|
+
setPrevHeight(rect.height);
|
|
1474
|
+
setIsAnimating(true);
|
|
1475
|
+
return onDragFinished();
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
}, [ref, draggedItem, onDragFinished, appStore, isZone, zoneCompound]);
|
|
1479
|
+
const returnedMinHeight = isNaN(Number(userMinEmptyHeight)) ? userMinEmptyHeight : `${userMinEmptyHeight}px`;
|
|
1480
|
+
return [prevHeight ? `${prevHeight}px` : returnedMinHeight, isAnimating];
|
|
1481
|
+
};
|
|
1482
|
+
|
|
1483
|
+
// components/DropZone/lib/use-content-with-preview.ts
|
|
1484
|
+
import { useCallback as useCallback6, useContext as useContext3, useEffect as useEffect4, useState as useState4 } from "react";
|
|
1485
|
+
|
|
1486
|
+
// lib/dnd/use-rendered-callback.ts
|
|
1487
|
+
import { useDragDropManager } from "@dnd-kit/react";
|
|
1488
|
+
import { useCallback as useCallback5 } from "react";
|
|
1489
|
+
function useRenderedCallback(callback, _deps = []) {
|
|
1490
|
+
const manager = useDragDropManager();
|
|
1491
|
+
return useCallback5(
|
|
1492
|
+
async (...args) => {
|
|
1493
|
+
await manager?.renderer.rendering;
|
|
1494
|
+
return callback(...args);
|
|
1495
|
+
},
|
|
1496
|
+
[manager, callback]
|
|
1497
|
+
);
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
// components/DropZone/lib/use-content-with-preview.ts
|
|
1501
|
+
var useContentIdsWithPreview = (contentIds, zoneCompound) => {
|
|
1502
|
+
const zoneStore = useContext3(ZoneStoreContext);
|
|
1503
|
+
const preview = useContextStore(
|
|
1504
|
+
ZoneStoreContext,
|
|
1505
|
+
(s) => s.previewIndex[zoneCompound]
|
|
1506
|
+
);
|
|
1507
|
+
const isDragging = useAppStore((s) => s.state.ui.isDragging);
|
|
1508
|
+
const [contentIdsWithPreview, setContentIdsWithPreview] = useState4(contentIds);
|
|
1509
|
+
const [localPreview, setLocalPreview] = useState4(
|
|
1510
|
+
preview
|
|
1511
|
+
);
|
|
1512
|
+
const updateContent = useRenderedCallback(
|
|
1513
|
+
useCallback6(
|
|
1514
|
+
(contentIds2, preview2, isDragging2, draggedItemId, previewExists) => {
|
|
1515
|
+
if (isDragging2 && !previewExists) {
|
|
1516
|
+
return;
|
|
1517
|
+
}
|
|
1518
|
+
if (preview2) {
|
|
1519
|
+
if (preview2.type === "insert") {
|
|
1520
|
+
setContentIdsWithPreview(
|
|
1521
|
+
insert(
|
|
1522
|
+
contentIds2.filter((id) => id !== preview2.props.id),
|
|
1523
|
+
preview2.index,
|
|
1524
|
+
preview2.props.id
|
|
1525
|
+
)
|
|
1526
|
+
);
|
|
1527
|
+
} else {
|
|
1528
|
+
setContentIdsWithPreview(
|
|
1529
|
+
insert(
|
|
1530
|
+
contentIds2.filter((id) => id !== preview2.props.id),
|
|
1531
|
+
preview2.index,
|
|
1532
|
+
preview2.props.id
|
|
1533
|
+
)
|
|
1534
|
+
);
|
|
1535
|
+
}
|
|
1536
|
+
} else {
|
|
1537
|
+
setContentIdsWithPreview(
|
|
1538
|
+
previewExists ? contentIds2.filter((id) => id !== draggedItemId) : contentIds2
|
|
1539
|
+
);
|
|
1540
|
+
}
|
|
1541
|
+
setLocalPreview(preview2);
|
|
1542
|
+
},
|
|
1543
|
+
[]
|
|
1544
|
+
)
|
|
1545
|
+
);
|
|
1546
|
+
useEffect4(() => {
|
|
1547
|
+
const s = zoneStore.getState();
|
|
1548
|
+
const draggedItemId = s.draggedItem?.id;
|
|
1549
|
+
const previewExists = Object.keys(s.previewIndex || {}).length > 0;
|
|
1550
|
+
updateContent(
|
|
1551
|
+
contentIds,
|
|
1552
|
+
preview,
|
|
1553
|
+
isDragging,
|
|
1554
|
+
draggedItemId,
|
|
1555
|
+
previewExists
|
|
1556
|
+
);
|
|
1557
|
+
}, [contentIds, preview, isDragging, updateContent, zoneStore]);
|
|
1558
|
+
return [contentIdsWithPreview, localPreview];
|
|
1559
|
+
};
|
|
1560
|
+
|
|
1561
|
+
// components/DropZone/lib/use-drag-axis.ts
|
|
1562
|
+
import { useCallback as useCallback7, useEffect as useEffect5, useState as useState5 } from "react";
|
|
1563
|
+
var GRID_DRAG_AXIS = "dynamic";
|
|
1564
|
+
var FLEX_ROW_DRAG_AXIS = "x";
|
|
1565
|
+
var DEFAULT_DRAG_AXIS = "y";
|
|
1566
|
+
var useDragAxis = (ref, collisionAxis) => {
|
|
1567
|
+
const status = useAppStore((s) => s.status);
|
|
1568
|
+
const [dragAxis, setDragAxis] = useState5(
|
|
1569
|
+
collisionAxis || DEFAULT_DRAG_AXIS
|
|
1570
|
+
);
|
|
1571
|
+
const calculateDragAxis = useCallback7(() => {
|
|
1572
|
+
if (ref.current) {
|
|
1573
|
+
const computedStyle = window.getComputedStyle(ref.current);
|
|
1574
|
+
if (computedStyle.display === "grid") {
|
|
1575
|
+
setDragAxis(GRID_DRAG_AXIS);
|
|
1576
|
+
} else if (computedStyle.display === "flex" && computedStyle.flexDirection === "row") {
|
|
1577
|
+
setDragAxis(FLEX_ROW_DRAG_AXIS);
|
|
1578
|
+
} else {
|
|
1579
|
+
setDragAxis(DEFAULT_DRAG_AXIS);
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
}, [ref]);
|
|
1583
|
+
useEffect5(() => {
|
|
1584
|
+
const onViewportChange = () => {
|
|
1585
|
+
calculateDragAxis();
|
|
1586
|
+
};
|
|
1587
|
+
window.addEventListener("viewportchange", onViewportChange);
|
|
1588
|
+
return () => {
|
|
1589
|
+
window.removeEventListener("viewportchange", onViewportChange);
|
|
1590
|
+
};
|
|
1591
|
+
}, [calculateDragAxis]);
|
|
1592
|
+
useEffect5(calculateDragAxis, [status, collisionAxis, calculateDragAxis]);
|
|
1593
|
+
return [dragAxis, calculateDragAxis];
|
|
1594
|
+
};
|
|
1595
|
+
|
|
1596
|
+
// components/DropZone/index.tsx
|
|
1597
|
+
import { useShallow as useShallow3 } from "zustand/react/shallow";
|
|
1598
|
+
|
|
1599
|
+
// components/Render/context.tsx
|
|
1600
|
+
import React2 from "react";
|
|
1601
|
+
var renderContext = React2.createContext({
|
|
1602
|
+
config: { components: {} },
|
|
1603
|
+
data: { root: {}, content: [] },
|
|
1604
|
+
metadata: {}
|
|
1605
|
+
});
|
|
1606
|
+
|
|
1607
|
+
// lib/field-transforms/use-field-transforms.tsx
|
|
1608
|
+
import { useMemo as useMemo4 } from "react";
|
|
1609
|
+
|
|
1610
|
+
// lib/field-transforms/build-mappers.ts
|
|
1611
|
+
function buildMappers(transforms, readOnly, forceReadOnly) {
|
|
1612
|
+
return Object.keys(transforms).reduce((acc, _fieldType) => {
|
|
1613
|
+
const fieldType = _fieldType;
|
|
1614
|
+
return {
|
|
1615
|
+
...acc,
|
|
1616
|
+
[fieldType]: ({
|
|
1617
|
+
parentId,
|
|
1618
|
+
...params
|
|
1619
|
+
}) => {
|
|
1620
|
+
const wildcardPath = params.propPath.replace(/\[\d+\]/g, "[*]");
|
|
1621
|
+
const isReadOnly = readOnly?.[params.propPath] || readOnly?.[wildcardPath] || forceReadOnly || false;
|
|
1622
|
+
const fn = transforms[fieldType];
|
|
1623
|
+
return fn?.({
|
|
1624
|
+
...params,
|
|
1625
|
+
isReadOnly,
|
|
1626
|
+
componentId: parentId
|
|
1627
|
+
});
|
|
1628
|
+
}
|
|
1629
|
+
};
|
|
1630
|
+
}, {});
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
// lib/field-transforms/use-field-transforms.tsx
|
|
1634
|
+
function useFieldTransforms(config, item, transforms, readOnly, forceReadOnly) {
|
|
1635
|
+
const mappers = useMemo4(
|
|
1636
|
+
() => buildMappers(transforms, readOnly, forceReadOnly),
|
|
1637
|
+
[transforms, readOnly, forceReadOnly]
|
|
1638
|
+
);
|
|
1639
|
+
const transformedProps = useMemo4(() => {
|
|
1640
|
+
return mapFields(item, mappers, config).props;
|
|
1641
|
+
}, [config, item, mappers]);
|
|
1642
|
+
const mergedProps = useMemo4(
|
|
1643
|
+
() => ({ ...item.props, ...transformedProps }),
|
|
1644
|
+
[item.props, transformedProps]
|
|
1645
|
+
);
|
|
1646
|
+
return mergedProps;
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
// lib/field-transforms/default-transforms/slot-transform.tsx
|
|
1650
|
+
var getSlotTransform = (renderSlotEdit, renderSlotRender = renderSlotEdit) => ({
|
|
1651
|
+
slot: ({ value: content, propName, field, isReadOnly }) => {
|
|
1652
|
+
const render = isReadOnly ? renderSlotRender : renderSlotEdit;
|
|
1653
|
+
const Slot = (dzProps) => render({
|
|
1654
|
+
allow: field?.type === "slot" ? field.allow : [],
|
|
1655
|
+
disallow: field?.type === "slot" ? field.disallow : [],
|
|
1656
|
+
...dzProps,
|
|
1657
|
+
zone: propName,
|
|
1658
|
+
content
|
|
1659
|
+
});
|
|
1660
|
+
return Slot;
|
|
1661
|
+
}
|
|
1662
|
+
});
|
|
1663
|
+
|
|
1664
|
+
// lib/use-slots.tsx
|
|
1665
|
+
function useSlots(config, item, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
|
|
1666
|
+
return useFieldTransforms(
|
|
1667
|
+
config,
|
|
1668
|
+
item,
|
|
1669
|
+
getSlotTransform(renderSlotEdit, renderSlotRender),
|
|
1670
|
+
readOnly,
|
|
1671
|
+
forceReadOnly
|
|
1672
|
+
);
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
// components/SlotRender/index.tsx
|
|
1676
|
+
import { useShallow as useShallow2 } from "zustand/react/shallow";
|
|
1677
|
+
|
|
1678
|
+
// components/SlotRender/server.tsx
|
|
1679
|
+
import { forwardRef } from "react";
|
|
1680
|
+
|
|
1681
|
+
// components/RichTextEditor/lib/use-richtext-props.tsx
|
|
1682
|
+
import { lazy, Suspense, useMemo as useMemo5 } from "react";
|
|
1683
|
+
|
|
1684
|
+
// components/RichTextEditor/components/RenderFallback.tsx
|
|
1685
|
+
import DOMPurify from "isomorphic-dompurify";
|
|
1686
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
1687
|
+
var getClassName3 = get_class_name_factory_default("RichTextEditor", styles_module_default);
|
|
1688
|
+
function RichTextRenderFallback({ content }) {
|
|
1689
|
+
return /* @__PURE__ */ jsx7("div", { className: getClassName3(), children: /* @__PURE__ */ jsx7(
|
|
1690
|
+
"div",
|
|
1691
|
+
{
|
|
1692
|
+
className: "rich-text",
|
|
1693
|
+
dangerouslySetInnerHTML: { __html: DOMPurify.sanitize(content) }
|
|
1694
|
+
}
|
|
1695
|
+
) });
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
// components/RichTextEditor/lib/mapDeep.ts
|
|
1699
|
+
var mapDeep = (source, path, render) => {
|
|
1700
|
+
if (!source) {
|
|
1701
|
+
return null;
|
|
1702
|
+
}
|
|
1703
|
+
if (path.length === 0) {
|
|
1704
|
+
return render(source);
|
|
1705
|
+
}
|
|
1706
|
+
const [key, ...rest] = path;
|
|
1707
|
+
if (Array.isArray(source)) {
|
|
1708
|
+
return source.map((item) => mapDeep(item, path, render));
|
|
1709
|
+
}
|
|
1710
|
+
return {
|
|
1711
|
+
...source,
|
|
1712
|
+
[key]: mapDeep(source[key], rest, render)
|
|
1713
|
+
};
|
|
1714
|
+
};
|
|
1715
|
+
|
|
1716
|
+
// components/RichTextEditor/lib/use-richtext-props.tsx
|
|
1717
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
1718
|
+
var findAllRichtextKeys = (fields, path = []) => {
|
|
1719
|
+
if (!fields) return [];
|
|
1720
|
+
const result = [];
|
|
1721
|
+
for (const [key, field] of Object.entries(fields)) {
|
|
1722
|
+
const currentPath = [...path, key];
|
|
1723
|
+
if (field.type === "richtext") {
|
|
1724
|
+
result.push({
|
|
1725
|
+
path: currentPath,
|
|
1726
|
+
field
|
|
1727
|
+
});
|
|
1728
|
+
}
|
|
1729
|
+
if (field.type === "array" && "arrayFields" in field) {
|
|
1730
|
+
result.push(...findAllRichtextKeys(field.arrayFields, currentPath));
|
|
1731
|
+
}
|
|
1732
|
+
if (field.type === "object" && "objectFields" in field) {
|
|
1733
|
+
result.push(...findAllRichtextKeys(field.objectFields, currentPath));
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
return result;
|
|
1737
|
+
};
|
|
1738
|
+
function useRichtextProps(fields, props) {
|
|
1739
|
+
const richtextKeys = useMemo5(() => findAllRichtextKeys(fields), [fields]);
|
|
1740
|
+
const richtextProps = useMemo5(() => {
|
|
1741
|
+
if (!richtextKeys?.length) return {};
|
|
1742
|
+
const RichTextRender2 = lazy(
|
|
1743
|
+
() => import("./Render-I6PZ5MEA.mjs").then((m) => ({
|
|
1744
|
+
default: m.RichTextRender
|
|
1745
|
+
}))
|
|
1746
|
+
);
|
|
1747
|
+
let result = { ...props };
|
|
1748
|
+
for (const { path, field } of richtextKeys) {
|
|
1749
|
+
result = mapDeep(result, path, (content) => /* @__PURE__ */ jsx8(
|
|
1750
|
+
Suspense,
|
|
1751
|
+
{
|
|
1752
|
+
fallback: /* @__PURE__ */ jsx8(RichTextRenderFallback, { content }),
|
|
1753
|
+
children: /* @__PURE__ */ jsx8(RichTextRender2, { content, field })
|
|
1754
|
+
},
|
|
1755
|
+
generateId()
|
|
1756
|
+
));
|
|
1757
|
+
}
|
|
1758
|
+
return result;
|
|
1759
|
+
}, [richtextKeys, props]);
|
|
1760
|
+
return richtextProps;
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1763
|
+
// components/SlotRender/server.tsx
|
|
1764
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
1765
|
+
var SlotRenderPure = (props) => /* @__PURE__ */ jsx9(SlotRender, { ...props });
|
|
1766
|
+
var Item = ({
|
|
1767
|
+
config,
|
|
1768
|
+
item,
|
|
1769
|
+
metadata
|
|
1770
|
+
}) => {
|
|
1771
|
+
const Component = config.components[item.type];
|
|
1772
|
+
const props = useSlots(config, item, (slotProps) => /* @__PURE__ */ jsx9(SlotRenderPure, { ...slotProps, config, metadata }));
|
|
1773
|
+
const richtextProps = useRichtextProps(Component.fields, props);
|
|
1774
|
+
return /* @__PURE__ */ jsx9(
|
|
1775
|
+
Component.render,
|
|
1776
|
+
{
|
|
1777
|
+
...props,
|
|
1778
|
+
...richtextProps,
|
|
1779
|
+
credbuild: {
|
|
1780
|
+
...props.credbuild,
|
|
1781
|
+
metadata: metadata || {}
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
);
|
|
1785
|
+
};
|
|
1786
|
+
var SlotRender = forwardRef(
|
|
1787
|
+
function SlotRenderInternal({ className, style, content, config, metadata, as }, ref) {
|
|
1788
|
+
const El = as ?? "div";
|
|
1789
|
+
return /* @__PURE__ */ jsx9(El, { className, style, ref, children: content.map((item) => {
|
|
1790
|
+
if (!config.components[item.type]) {
|
|
1791
|
+
return null;
|
|
1792
|
+
}
|
|
1793
|
+
return /* @__PURE__ */ jsx9(
|
|
1794
|
+
Item,
|
|
1795
|
+
{
|
|
1796
|
+
config,
|
|
1797
|
+
item,
|
|
1798
|
+
metadata
|
|
1799
|
+
},
|
|
1800
|
+
item.props.id
|
|
1801
|
+
);
|
|
1802
|
+
}) });
|
|
1803
|
+
}
|
|
1804
|
+
);
|
|
1805
|
+
|
|
1806
|
+
// components/SlotRender/index.tsx
|
|
1807
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
1808
|
+
var ContextSlotRender = ({
|
|
1809
|
+
componentId,
|
|
1810
|
+
zone
|
|
1811
|
+
}) => {
|
|
1812
|
+
const config = useAppStore((s) => s.config);
|
|
1813
|
+
const metadata = useAppStore((s) => s.metadata);
|
|
1814
|
+
const slotContent = useAppStore(
|
|
1815
|
+
useShallow2((s) => {
|
|
1816
|
+
const indexes = s.state.indexes;
|
|
1817
|
+
const contentIds = indexes.zones[`${componentId}:${zone}`]?.contentIds ?? [];
|
|
1818
|
+
return contentIds.map((contentId) => indexes.nodes[contentId].flatData);
|
|
1819
|
+
})
|
|
1820
|
+
);
|
|
1821
|
+
return /* @__PURE__ */ jsx10(
|
|
1822
|
+
SlotRenderPure,
|
|
1823
|
+
{
|
|
1824
|
+
content: slotContent,
|
|
1825
|
+
zone,
|
|
1826
|
+
config,
|
|
1827
|
+
metadata
|
|
1828
|
+
}
|
|
1829
|
+
);
|
|
1830
|
+
};
|
|
1831
|
+
|
|
1832
|
+
// lib/field-transforms/use-field-transforms-tracked.tsx
|
|
1833
|
+
import { useMemo as useMemo6, useRef as useRef4 } from "react";
|
|
1834
|
+
function useFieldTransformsTracked(config, item, transforms, readOnly, forceReadOnly) {
|
|
1835
|
+
const prevProps = useRef4(null);
|
|
1836
|
+
const prevResult = useRef4(item.props);
|
|
1837
|
+
const mappers = useMemo6(
|
|
1838
|
+
() => buildMappers(transforms, readOnly, forceReadOnly),
|
|
1839
|
+
[transforms, readOnly, forceReadOnly]
|
|
1840
|
+
);
|
|
1841
|
+
const transformedProps = useMemo6(() => {
|
|
1842
|
+
const changedProps = {};
|
|
1843
|
+
const componentConfig = item.type === "root" ? config.root : config.components?.[item.type];
|
|
1844
|
+
let changeIncludesSlot = false;
|
|
1845
|
+
for (const fieldName in item.props) {
|
|
1846
|
+
const fieldType = componentConfig?.fields?.[fieldName]?.type;
|
|
1847
|
+
if (!prevProps.current || item.props[fieldName] !== prevProps.current[fieldName]) {
|
|
1848
|
+
changedProps[fieldName] = item.props[fieldName];
|
|
1849
|
+
if (fieldType === "slot") {
|
|
1850
|
+
changeIncludesSlot = true;
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
changedProps.id = item.props.id;
|
|
1855
|
+
prevProps.current = item.props;
|
|
1856
|
+
const mapped = mapFields(
|
|
1857
|
+
{ ...item, props: changedProps },
|
|
1858
|
+
mappers,
|
|
1859
|
+
config,
|
|
1860
|
+
false,
|
|
1861
|
+
changeIncludesSlot
|
|
1862
|
+
).props;
|
|
1863
|
+
prevResult.current = { ...prevResult.current, ...mapped };
|
|
1864
|
+
return prevResult.current;
|
|
1865
|
+
}, [config, item, mappers]);
|
|
1866
|
+
const mergedProps = useMemo6(
|
|
1867
|
+
() => ({ ...item.props, ...transformedProps }),
|
|
1868
|
+
[item.props, transformedProps]
|
|
1869
|
+
);
|
|
1870
|
+
return mergedProps;
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1873
|
+
// components/InlineTextField/index.tsx
|
|
1874
|
+
import { memo, useEffect as useEffect6, useRef as useRef5, useState as useState6 } from "react";
|
|
1875
|
+
|
|
1876
|
+
// css-module:/home/runner/work/credbuild/credbuild/components/InlineTextField/styles.module.css#css-module
|
|
1877
|
+
var styles_module_default5 = { "InlineTextField": "_InlineTextField_104qp_1" };
|
|
1878
|
+
|
|
1879
|
+
// lib/get-selector-for-id.ts
|
|
1880
|
+
var getSelectorForId = (state, id) => {
|
|
1881
|
+
const node = state.indexes.nodes[id];
|
|
1882
|
+
if (!node) return;
|
|
1883
|
+
const zoneCompound = `${node.parentId}:${node.zone}`;
|
|
1884
|
+
const index = state.indexes.zones[zoneCompound].contentIds.indexOf(id);
|
|
1885
|
+
return { zone: zoneCompound, index };
|
|
1886
|
+
};
|
|
1887
|
+
|
|
1888
|
+
// components/InlineTextField/index.tsx
|
|
1889
|
+
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
1890
|
+
var getClassName4 = get_class_name_factory_default("InlineTextField", styles_module_default5);
|
|
1891
|
+
var InlineTextFieldInternal = ({
|
|
1892
|
+
propPath,
|
|
1893
|
+
componentId,
|
|
1894
|
+
value,
|
|
1895
|
+
isReadOnly,
|
|
1896
|
+
opts = {}
|
|
1897
|
+
}) => {
|
|
1898
|
+
const ref = useRef5(null);
|
|
1899
|
+
const appStoreApi = useAppStoreApi();
|
|
1900
|
+
const disableLineBreaks = opts.disableLineBreaks ?? false;
|
|
1901
|
+
useEffect6(() => {
|
|
1902
|
+
const appStore = appStoreApi.getState();
|
|
1903
|
+
const data = appStore.state.indexes.nodes[componentId].data;
|
|
1904
|
+
const componentConfig = appStore.getComponentConfig(data.type);
|
|
1905
|
+
if (!componentConfig) {
|
|
1906
|
+
throw new Error(
|
|
1907
|
+
`InlineTextField Error: No config defined for ${data.type}`
|
|
1908
|
+
);
|
|
1909
|
+
}
|
|
1910
|
+
if (ref.current) {
|
|
1911
|
+
if (value !== ref.current.innerText) {
|
|
1912
|
+
ref.current.replaceChildren(value);
|
|
1913
|
+
}
|
|
1914
|
+
const cleanupPortal = registerOverlayPortal(ref.current);
|
|
1915
|
+
const handleInput = async (e) => {
|
|
1916
|
+
const appStore2 = appStoreApi.getState();
|
|
1917
|
+
const node = appStore2.state.indexes.nodes[componentId];
|
|
1918
|
+
const zoneCompound = `${node.parentId}:${node.zone}`;
|
|
1919
|
+
const index = appStore2.state.indexes.zones[zoneCompound]?.contentIds.indexOf(
|
|
1920
|
+
componentId
|
|
1921
|
+
);
|
|
1922
|
+
let value2 = e.target.innerText;
|
|
1923
|
+
if (disableLineBreaks) {
|
|
1924
|
+
value2 = value2.replaceAll(/\n/gm, "");
|
|
1925
|
+
}
|
|
1926
|
+
const newProps = setDeep(node.data.props, propPath, value2);
|
|
1927
|
+
const resolvedData = await appStore2.resolveComponentData(
|
|
1928
|
+
{ ...node.data, props: newProps },
|
|
1929
|
+
"replace"
|
|
1930
|
+
);
|
|
1931
|
+
appStore2.dispatch({
|
|
1932
|
+
type: "replace",
|
|
1933
|
+
data: resolvedData.node,
|
|
1934
|
+
destinationIndex: index,
|
|
1935
|
+
destinationZone: zoneCompound
|
|
1936
|
+
});
|
|
1937
|
+
};
|
|
1938
|
+
const el = ref.current;
|
|
1939
|
+
el.addEventListener("input", handleInput);
|
|
1940
|
+
return () => {
|
|
1941
|
+
el.removeEventListener("input", handleInput);
|
|
1942
|
+
cleanupPortal?.();
|
|
1943
|
+
};
|
|
1944
|
+
}
|
|
1945
|
+
}, [appStoreApi, ref, value, disableLineBreaks, componentId, propPath]);
|
|
1946
|
+
const [isHovering, setIsHovering] = useState6(false);
|
|
1947
|
+
const [isFocused, setIsFocused] = useState6(false);
|
|
1948
|
+
return /* @__PURE__ */ jsx11(
|
|
1949
|
+
"span",
|
|
1950
|
+
{
|
|
1951
|
+
className: getClassName4(),
|
|
1952
|
+
ref,
|
|
1953
|
+
contentEditable: isHovering || isFocused ? "plaintext-only" : "false",
|
|
1954
|
+
onClick: (e) => {
|
|
1955
|
+
e.preventDefault();
|
|
1956
|
+
e.stopPropagation();
|
|
1957
|
+
},
|
|
1958
|
+
onClickCapture: (e) => {
|
|
1959
|
+
e.preventDefault();
|
|
1960
|
+
e.stopPropagation();
|
|
1961
|
+
const itemSelector = getSelectorForId(
|
|
1962
|
+
appStoreApi.getState().state,
|
|
1963
|
+
componentId
|
|
1964
|
+
);
|
|
1965
|
+
appStoreApi.getState().setUi({ itemSelector });
|
|
1966
|
+
},
|
|
1967
|
+
onKeyDown: (e) => {
|
|
1968
|
+
e.stopPropagation();
|
|
1969
|
+
if (disableLineBreaks && e.key === "Enter" || isReadOnly) {
|
|
1970
|
+
e.preventDefault();
|
|
1971
|
+
}
|
|
1972
|
+
},
|
|
1973
|
+
onKeyUp: (e) => {
|
|
1974
|
+
e.stopPropagation();
|
|
1975
|
+
e.preventDefault();
|
|
1976
|
+
},
|
|
1977
|
+
onMouseOverCapture: () => setIsHovering(true),
|
|
1978
|
+
onMouseOutCapture: () => setIsHovering(false),
|
|
1979
|
+
onFocus: () => setIsFocused(true),
|
|
1980
|
+
onBlur: () => setIsFocused(false)
|
|
1981
|
+
}
|
|
1982
|
+
);
|
|
1983
|
+
};
|
|
1984
|
+
var InlineTextField = memo(InlineTextFieldInternal);
|
|
1985
|
+
|
|
1986
|
+
// lib/field-transforms/default-transforms/inline-text-transform.tsx
|
|
1987
|
+
import { jsx as jsx12 } from "react/jsx-runtime";
|
|
1988
|
+
var getInlineTextTransform = () => ({
|
|
1989
|
+
text: ({ value, componentId, field, propPath, isReadOnly }) => {
|
|
1990
|
+
if (field.contentEditable) {
|
|
1991
|
+
return /* @__PURE__ */ jsx12(
|
|
1992
|
+
InlineTextField,
|
|
1993
|
+
{
|
|
1994
|
+
propPath,
|
|
1995
|
+
componentId,
|
|
1996
|
+
value,
|
|
1997
|
+
opts: { disableLineBreaks: true },
|
|
1998
|
+
isReadOnly
|
|
1999
|
+
}
|
|
2000
|
+
);
|
|
2001
|
+
}
|
|
2002
|
+
return value;
|
|
2003
|
+
},
|
|
2004
|
+
textarea: ({ value, componentId, field, propPath, isReadOnly }) => {
|
|
2005
|
+
if (field.contentEditable) {
|
|
2006
|
+
return /* @__PURE__ */ jsx12(
|
|
2007
|
+
InlineTextField,
|
|
2008
|
+
{
|
|
2009
|
+
propPath,
|
|
2010
|
+
componentId,
|
|
2011
|
+
value,
|
|
2012
|
+
isReadOnly
|
|
2013
|
+
}
|
|
2014
|
+
);
|
|
2015
|
+
}
|
|
2016
|
+
return value;
|
|
2017
|
+
},
|
|
2018
|
+
custom: ({ value, componentId, field, propPath, isReadOnly }) => {
|
|
2019
|
+
if (field.contentEditable && typeof value === "string") {
|
|
2020
|
+
return /* @__PURE__ */ jsx12(
|
|
2021
|
+
InlineTextField,
|
|
2022
|
+
{
|
|
2023
|
+
propPath,
|
|
2024
|
+
componentId,
|
|
2025
|
+
value,
|
|
2026
|
+
isReadOnly
|
|
2027
|
+
}
|
|
2028
|
+
);
|
|
2029
|
+
}
|
|
2030
|
+
return value;
|
|
2031
|
+
}
|
|
2032
|
+
});
|
|
2033
|
+
|
|
2034
|
+
// lib/field-transforms/default-transforms/rich-text-transform.tsx
|
|
2035
|
+
import {
|
|
2036
|
+
useEffect as useEffect7,
|
|
2037
|
+
useRef as useRef6,
|
|
2038
|
+
useCallback as useCallback8,
|
|
2039
|
+
memo as memo2,
|
|
2040
|
+
lazy as lazy2,
|
|
2041
|
+
Suspense as Suspense2
|
|
2042
|
+
} from "react";
|
|
2043
|
+
import { jsx as jsx13 } from "react/jsx-runtime";
|
|
2044
|
+
var Editor = lazy2(
|
|
2045
|
+
() => import("./Editor-P3UUWNSZ.mjs").then((m) => ({
|
|
2046
|
+
default: m.Editor
|
|
2047
|
+
}))
|
|
2048
|
+
);
|
|
2049
|
+
var RichTextRender = lazy2(
|
|
2050
|
+
() => import("./Render-I6PZ5MEA.mjs").then((m) => ({
|
|
2051
|
+
default: m.RichTextRender
|
|
2052
|
+
}))
|
|
2053
|
+
);
|
|
2054
|
+
var InlineEditorWrapper = memo2(
|
|
2055
|
+
({
|
|
2056
|
+
value,
|
|
2057
|
+
componentId,
|
|
2058
|
+
propPath,
|
|
2059
|
+
field,
|
|
2060
|
+
id
|
|
2061
|
+
}) => {
|
|
2062
|
+
const portalRef = useRef6(null);
|
|
2063
|
+
const appStoreApi = useAppStoreApi();
|
|
2064
|
+
const onClickHandler = (e) => {
|
|
2065
|
+
e.preventDefault();
|
|
2066
|
+
e.stopPropagation();
|
|
2067
|
+
};
|
|
2068
|
+
const onClickCaptureHandler = (e) => {
|
|
2069
|
+
e.preventDefault();
|
|
2070
|
+
e.stopPropagation();
|
|
2071
|
+
const itemSelector = getSelectorForId(
|
|
2072
|
+
appStoreApi.getState().state,
|
|
2073
|
+
componentId
|
|
2074
|
+
);
|
|
2075
|
+
appStoreApi.getState().setUi({ itemSelector });
|
|
2076
|
+
};
|
|
2077
|
+
useEffect7(() => {
|
|
2078
|
+
if (!portalRef.current) return;
|
|
2079
|
+
const cleanup = registerOverlayPortal(portalRef.current, {
|
|
2080
|
+
disableDragOnFocus: true
|
|
2081
|
+
});
|
|
2082
|
+
return () => cleanup?.();
|
|
2083
|
+
}, []);
|
|
2084
|
+
const handleChange = useCallback8(
|
|
2085
|
+
async (content, ui) => {
|
|
2086
|
+
const appStore = appStoreApi.getState();
|
|
2087
|
+
const node = appStore.state.indexes.nodes[componentId];
|
|
2088
|
+
const zoneCompound = `${node.parentId}:${node.zone}`;
|
|
2089
|
+
const index = appStore.state.indexes.zones[zoneCompound]?.contentIds.indexOf(
|
|
2090
|
+
componentId
|
|
2091
|
+
);
|
|
2092
|
+
const newProps = setDeep(node.data.props, propPath, content);
|
|
2093
|
+
const resolvedData = await appStore.resolveComponentData(
|
|
2094
|
+
{ ...node.data, props: newProps },
|
|
2095
|
+
"replace"
|
|
2096
|
+
);
|
|
2097
|
+
appStore.dispatch({
|
|
2098
|
+
type: "replace",
|
|
2099
|
+
data: resolvedData.node,
|
|
2100
|
+
destinationIndex: index,
|
|
2101
|
+
destinationZone: zoneCompound,
|
|
2102
|
+
ui
|
|
2103
|
+
});
|
|
2104
|
+
},
|
|
2105
|
+
[appStoreApi, componentId, propPath]
|
|
2106
|
+
);
|
|
2107
|
+
const handleFocus = useCallback8(
|
|
2108
|
+
(editor) => {
|
|
2109
|
+
appStoreApi.setState({
|
|
2110
|
+
currentRichText: {
|
|
2111
|
+
inlineComponentId: componentId,
|
|
2112
|
+
inline: true,
|
|
2113
|
+
field,
|
|
2114
|
+
editor,
|
|
2115
|
+
id
|
|
2116
|
+
}
|
|
2117
|
+
});
|
|
2118
|
+
},
|
|
2119
|
+
[field, componentId, appStoreApi, id]
|
|
2120
|
+
);
|
|
2121
|
+
if (!field.contentEditable)
|
|
2122
|
+
return /* @__PURE__ */ jsx13(Suspense2, { fallback: /* @__PURE__ */ jsx13(RichTextRenderFallback, { content: value }), children: /* @__PURE__ */ jsx13(RichTextRender, { content: value, field }) });
|
|
2123
|
+
const editorProps = {
|
|
2124
|
+
content: value,
|
|
2125
|
+
onChange: handleChange,
|
|
2126
|
+
field,
|
|
2127
|
+
inline: true,
|
|
2128
|
+
onFocus: handleFocus,
|
|
2129
|
+
id,
|
|
2130
|
+
name: propPath
|
|
2131
|
+
};
|
|
2132
|
+
return /* @__PURE__ */ jsx13(
|
|
2133
|
+
"div",
|
|
2134
|
+
{
|
|
2135
|
+
ref: portalRef,
|
|
2136
|
+
onClick: onClickHandler,
|
|
2137
|
+
onClickCapture: onClickCaptureHandler,
|
|
2138
|
+
children: /* @__PURE__ */ jsx13(Suspense2, { fallback: /* @__PURE__ */ jsx13(EditorFallback, { ...editorProps }), children: /* @__PURE__ */ jsx13(Editor, { ...editorProps }) })
|
|
2139
|
+
}
|
|
2140
|
+
);
|
|
2141
|
+
}
|
|
2142
|
+
);
|
|
2143
|
+
InlineEditorWrapper.displayName = "InlineEditorWrapper";
|
|
2144
|
+
var getRichTextTransform = () => ({
|
|
2145
|
+
richtext: ({ value, componentId, field, propPath, isReadOnly }) => {
|
|
2146
|
+
const { contentEditable = true, tiptap } = field;
|
|
2147
|
+
if (contentEditable === false || isReadOnly) {
|
|
2148
|
+
return /* @__PURE__ */ jsx13(RichTextRender, { content: value, field });
|
|
2149
|
+
}
|
|
2150
|
+
const id = `${componentId}_${field.type}_${propPath}`;
|
|
2151
|
+
return /* @__PURE__ */ jsx13(
|
|
2152
|
+
InlineEditorWrapper,
|
|
2153
|
+
{
|
|
2154
|
+
value,
|
|
2155
|
+
componentId,
|
|
2156
|
+
propPath,
|
|
2157
|
+
field,
|
|
2158
|
+
id
|
|
2159
|
+
},
|
|
2160
|
+
id
|
|
2161
|
+
);
|
|
2162
|
+
}
|
|
2163
|
+
});
|
|
2164
|
+
|
|
2165
|
+
// components/MemoizeComponent/index.tsx
|
|
2166
|
+
import { deepEqual } from "fast-equals";
|
|
2167
|
+
import { memo as memo3 } from "react";
|
|
2168
|
+
|
|
2169
|
+
// lib/shallow-equal.ts
|
|
2170
|
+
function shallowEqual(obj1, obj2, keysToIgnore = []) {
|
|
2171
|
+
if (Object.is(obj1, obj2)) return true;
|
|
2172
|
+
if (typeof obj1 !== "object" || obj1 === null || typeof obj2 !== "object" || obj2 === null) {
|
|
2173
|
+
return false;
|
|
2174
|
+
}
|
|
2175
|
+
if (Object.getPrototypeOf(obj1) !== Object.getPrototypeOf(obj2)) {
|
|
2176
|
+
return false;
|
|
2177
|
+
}
|
|
2178
|
+
const ignore = new Set(keysToIgnore);
|
|
2179
|
+
const keys1 = Object.keys(obj1).filter((k) => !ignore.has(k));
|
|
2180
|
+
const keys2 = Object.keys(obj2).filter((k) => !ignore.has(k));
|
|
2181
|
+
if (keys1.length !== keys2.length) return false;
|
|
2182
|
+
for (let i = 0; i < keys1.length; i++) {
|
|
2183
|
+
const currKey = keys1[i];
|
|
2184
|
+
if (!Object.prototype.hasOwnProperty.call(obj2, currKey)) return false;
|
|
2185
|
+
const val1 = obj1[currKey];
|
|
2186
|
+
const val2 = obj2[currKey];
|
|
2187
|
+
if (!Object.is(val1, val2)) return false;
|
|
2188
|
+
}
|
|
2189
|
+
return true;
|
|
2190
|
+
}
|
|
2191
|
+
|
|
2192
|
+
// components/MemoizeComponent/index.tsx
|
|
2193
|
+
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
2194
|
+
var RenderComponent = ({
|
|
2195
|
+
Component,
|
|
2196
|
+
componentProps: renderProps
|
|
2197
|
+
}) => {
|
|
2198
|
+
return /* @__PURE__ */ jsx14(Component, { ...renderProps });
|
|
2199
|
+
};
|
|
2200
|
+
var MemoizeComponent = memo3(RenderComponent, (prev, next) => {
|
|
2201
|
+
let credbuildEquals = true;
|
|
2202
|
+
if ("credbuild" in prev.componentProps && "credbuild" in next.componentProps) {
|
|
2203
|
+
credbuildEquals = deepEqual(prev.componentProps.credbuild, next.componentProps.credbuild);
|
|
2204
|
+
}
|
|
2205
|
+
return prev.Component === next.Component && shallowEqual(prev.componentProps, next.componentProps, ["credbuild"]) && credbuildEquals;
|
|
2206
|
+
});
|
|
2207
|
+
|
|
2208
|
+
// components/DropZone/VirtualizedDropZone.tsx
|
|
2209
|
+
import {
|
|
2210
|
+
useCallback as useCallback9,
|
|
2211
|
+
useContext as useContext4,
|
|
2212
|
+
useEffect as useEffect8,
|
|
2213
|
+
useMemo as useMemo7,
|
|
2214
|
+
useRef as useRef7
|
|
2215
|
+
} from "react";
|
|
2216
|
+
import {
|
|
2217
|
+
defaultRangeExtractor,
|
|
2218
|
+
elementScroll,
|
|
2219
|
+
observeElementOffset,
|
|
2220
|
+
observeElementRect,
|
|
2221
|
+
observeWindowOffset,
|
|
2222
|
+
observeWindowRect,
|
|
2223
|
+
useVirtualizer,
|
|
2224
|
+
windowScroll
|
|
2225
|
+
} from "@tanstack/react-virtual";
|
|
2226
|
+
|
|
2227
|
+
// lib/get-frame.ts
|
|
2228
|
+
var getFrame = () => {
|
|
2229
|
+
if (typeof window === "undefined") return;
|
|
2230
|
+
let frameEl = document.querySelector("#preview-frame");
|
|
2231
|
+
if (frameEl?.tagName === "IFRAME") {
|
|
2232
|
+
return frameEl.contentDocument || document;
|
|
2233
|
+
}
|
|
2234
|
+
return frameEl?.ownerDocument || document;
|
|
2235
|
+
};
|
|
2236
|
+
|
|
2237
|
+
// components/DropZone/VirtualizedDropZone.tsx
|
|
2238
|
+
import { Fragment as Fragment3, jsx as jsx15 } from "react/jsx-runtime";
|
|
2239
|
+
var ROOT_ZONE_VIRTUALIZATION_OVERSCAN = 5;
|
|
2240
|
+
var DEFAULT_VIRTUALIZED_ITEM_HEIGHT = 320;
|
|
2241
|
+
var measuredItemHeights = /* @__PURE__ */ new Map();
|
|
2242
|
+
var getEstimatedItemHeight = (componentId) => measuredItemHeights.get(componentId) ?? DEFAULT_VIRTUALIZED_ITEM_HEIGHT;
|
|
2243
|
+
var cacheMeasuredItemHeight = (componentId, height) => {
|
|
2244
|
+
if (height <= 0) {
|
|
2245
|
+
return;
|
|
2246
|
+
}
|
|
2247
|
+
measuredItemHeights.set(componentId, height);
|
|
2248
|
+
};
|
|
2249
|
+
var VirtualizedDropZone = ({
|
|
2250
|
+
contentIds,
|
|
2251
|
+
zoneCompound,
|
|
2252
|
+
renderItem
|
|
2253
|
+
}) => {
|
|
2254
|
+
const selectedId = useAppStore((s) => s.selectedItem?.props.id ?? null);
|
|
2255
|
+
const frame = getFrame();
|
|
2256
|
+
const zoneStore = useContext4(ZoneStoreContext);
|
|
2257
|
+
const draggedItemId = useContextStore(ZoneStoreContext, (s) => {
|
|
2258
|
+
const draggedId = s.draggedItem?.id;
|
|
2259
|
+
return draggedId ? String(draggedId) : null;
|
|
2260
|
+
});
|
|
2261
|
+
const dragTargetParentId = useContextStore(ZoneStoreContext, (s) => {
|
|
2262
|
+
if (s.draggedItem?.id) {
|
|
2263
|
+
const parentZone = Object.keys(s.previewIndex ?? {})[0];
|
|
2264
|
+
return parentZone?.split(":")[0];
|
|
2265
|
+
}
|
|
2266
|
+
return null;
|
|
2267
|
+
});
|
|
2268
|
+
const iframeWindow = frame?.defaultView;
|
|
2269
|
+
const measureRefsRef = useRef7(/* @__PURE__ */ new Map());
|
|
2270
|
+
const appStoreApi = useAppStoreApi();
|
|
2271
|
+
const resolveIndex = useCallback9(
|
|
2272
|
+
(targetId) => {
|
|
2273
|
+
if (!targetId || targetId === "root") {
|
|
2274
|
+
return -1;
|
|
2275
|
+
}
|
|
2276
|
+
const directIndex = contentIds.indexOf(targetId);
|
|
2277
|
+
if (directIndex > -1) {
|
|
2278
|
+
return directIndex;
|
|
2279
|
+
}
|
|
2280
|
+
const path = appStoreApi.getState().state.indexes.nodes?.[targetId]?.path ?? [];
|
|
2281
|
+
for (let i = path.length - 1; i >= 0; i -= 1) {
|
|
2282
|
+
const candidateId = path[i]?.split(":")[0];
|
|
2283
|
+
if (!candidateId || candidateId === "root") {
|
|
2284
|
+
continue;
|
|
2285
|
+
}
|
|
2286
|
+
const index = contentIds.indexOf(candidateId);
|
|
2287
|
+
if (index > -1) {
|
|
2288
|
+
return index;
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
return -1;
|
|
2292
|
+
},
|
|
2293
|
+
[appStoreApi, contentIds]
|
|
2294
|
+
);
|
|
2295
|
+
const pinnedIndexes = useMemo7(() => {
|
|
2296
|
+
const nextPinnedIndexes = /* @__PURE__ */ new Set();
|
|
2297
|
+
[selectedId, draggedItemId, dragTargetParentId].forEach((targetId) => {
|
|
2298
|
+
const currentIndex = resolveIndex(targetId);
|
|
2299
|
+
if (currentIndex > -1) {
|
|
2300
|
+
nextPinnedIndexes.add(currentIndex);
|
|
2301
|
+
}
|
|
2302
|
+
});
|
|
2303
|
+
return Array.from(nextPinnedIndexes).sort((a, b) => a - b);
|
|
2304
|
+
}, [dragTargetParentId, draggedItemId, resolveIndex, selectedId]);
|
|
2305
|
+
const rangeExtractor = useCallback9(
|
|
2306
|
+
(range) => {
|
|
2307
|
+
const indexes = defaultRangeExtractor(range);
|
|
2308
|
+
pinnedIndexes.forEach((index) => {
|
|
2309
|
+
if (!indexes.includes(index)) {
|
|
2310
|
+
indexes.push(index);
|
|
2311
|
+
}
|
|
2312
|
+
});
|
|
2313
|
+
indexes.sort((a, b) => a - b);
|
|
2314
|
+
return indexes;
|
|
2315
|
+
},
|
|
2316
|
+
[pinnedIndexes]
|
|
2317
|
+
);
|
|
2318
|
+
const activeOverscan = draggedItemId ? 12 : ROOT_ZONE_VIRTUALIZATION_OVERSCAN;
|
|
2319
|
+
const virtualizer = useVirtualizer({
|
|
2320
|
+
count: contentIds.length,
|
|
2321
|
+
getItemKey: (index) => contentIds[index],
|
|
2322
|
+
estimateSize: (index) => getEstimatedItemHeight(contentIds[index]),
|
|
2323
|
+
getScrollElement: () => iframeWindow ?? null,
|
|
2324
|
+
overscan: activeOverscan,
|
|
2325
|
+
observeElementRect: (instance, cb) => iframeWindow ? observeWindowRect(instance, cb) : observeElementRect(instance, cb),
|
|
2326
|
+
observeElementOffset: (instance, cb) => iframeWindow ? observeWindowOffset(instance, cb) : observeElementOffset(instance, cb),
|
|
2327
|
+
scrollToFn: (offset, options, instance) => iframeWindow ? windowScroll(offset, options, instance) : elementScroll(offset, options, instance),
|
|
2328
|
+
rangeExtractor,
|
|
2329
|
+
initialOffset: () => iframeWindow ? iframeWindow.scrollY : 0
|
|
2330
|
+
});
|
|
2331
|
+
useEffect8(() => {
|
|
2332
|
+
zoneStore.getState().registerRootVirtualizer(zoneCompound, {
|
|
2333
|
+
resolveIndex: (targetId) => resolveIndex(targetId),
|
|
2334
|
+
virtualizer
|
|
2335
|
+
});
|
|
2336
|
+
return () => {
|
|
2337
|
+
zoneStore.getState().unregisterRootVirtualizer(zoneCompound);
|
|
2338
|
+
};
|
|
2339
|
+
}, [resolveIndex, virtualizer, zoneCompound, zoneStore]);
|
|
2340
|
+
const observersRef = useRef7(/* @__PURE__ */ new Map());
|
|
2341
|
+
const getMeasureRef = useCallback9((componentId) => {
|
|
2342
|
+
const cachedRef = measureRefsRef.current.get(componentId);
|
|
2343
|
+
if (cachedRef) {
|
|
2344
|
+
return cachedRef;
|
|
2345
|
+
}
|
|
2346
|
+
const measureRef = (element) => {
|
|
2347
|
+
const existingObserver = observersRef.current.get(componentId);
|
|
2348
|
+
if (existingObserver) {
|
|
2349
|
+
existingObserver.disconnect();
|
|
2350
|
+
observersRef.current.delete(componentId);
|
|
2351
|
+
}
|
|
2352
|
+
if (!element) {
|
|
2353
|
+
return;
|
|
2354
|
+
}
|
|
2355
|
+
const initialHeight = Math.ceil(element.getBoundingClientRect().height);
|
|
2356
|
+
if (initialHeight > 0) {
|
|
2357
|
+
cacheMeasuredItemHeight(componentId, initialHeight);
|
|
2358
|
+
}
|
|
2359
|
+
const observer = new ResizeObserver((entries) => {
|
|
2360
|
+
for (const entry of entries) {
|
|
2361
|
+
const height = Math.ceil(element.getBoundingClientRect().height);
|
|
2362
|
+
if (height > 0) {
|
|
2363
|
+
const cachedHeight = getEstimatedItemHeight(componentId);
|
|
2364
|
+
if (height !== cachedHeight) {
|
|
2365
|
+
cacheMeasuredItemHeight(componentId, height);
|
|
2366
|
+
virtualizer.measure();
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
});
|
|
2371
|
+
observer.observe(element);
|
|
2372
|
+
observersRef.current.set(componentId, observer);
|
|
2373
|
+
};
|
|
2374
|
+
measureRefsRef.current.set(componentId, measureRef);
|
|
2375
|
+
return measureRef;
|
|
2376
|
+
}, [virtualizer]);
|
|
2377
|
+
useEffect8(() => {
|
|
2378
|
+
const validIds = new Set(contentIds);
|
|
2379
|
+
Array.from(measureRefsRef.current.keys()).forEach((componentId) => {
|
|
2380
|
+
if (!validIds.has(componentId)) {
|
|
2381
|
+
measureRefsRef.current.delete(componentId);
|
|
2382
|
+
const observer = observersRef.current.get(componentId);
|
|
2383
|
+
if (observer) {
|
|
2384
|
+
observer.disconnect();
|
|
2385
|
+
observersRef.current.delete(componentId);
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
});
|
|
2389
|
+
}, [contentIds]);
|
|
2390
|
+
useEffect8(() => {
|
|
2391
|
+
return () => {
|
|
2392
|
+
observersRef.current.forEach((observer) => observer.disconnect());
|
|
2393
|
+
observersRef.current.clear();
|
|
2394
|
+
};
|
|
2395
|
+
}, []);
|
|
2396
|
+
const virtualItems = virtualizer.getVirtualItems();
|
|
2397
|
+
const totalSize = virtualizer.getTotalSize();
|
|
2398
|
+
const renderedItems = useMemo7(() => {
|
|
2399
|
+
const items = [];
|
|
2400
|
+
let previousEnd = 0;
|
|
2401
|
+
let previousIndex = -1;
|
|
2402
|
+
virtualItems.forEach((virtualItem) => {
|
|
2403
|
+
if (!virtualItem) return;
|
|
2404
|
+
const componentId = contentIds[virtualItem.index];
|
|
2405
|
+
const gapSize = Math.max(virtualItem.start - previousEnd, 0);
|
|
2406
|
+
if (gapSize > 0) {
|
|
2407
|
+
items.push(
|
|
2408
|
+
/* @__PURE__ */ jsx15(
|
|
2409
|
+
"div",
|
|
2410
|
+
{
|
|
2411
|
+
style: { height: `${gapSize}px` }
|
|
2412
|
+
},
|
|
2413
|
+
`gap:${previousIndex}:${virtualItem.index}`
|
|
2414
|
+
)
|
|
2415
|
+
);
|
|
2416
|
+
}
|
|
2417
|
+
items.push(
|
|
2418
|
+
renderItem({
|
|
2419
|
+
componentId,
|
|
2420
|
+
index: virtualItem.index,
|
|
2421
|
+
measureRef: getMeasureRef(componentId)
|
|
2422
|
+
})
|
|
2423
|
+
);
|
|
2424
|
+
previousEnd = virtualItem.end;
|
|
2425
|
+
previousIndex = virtualItem.index;
|
|
2426
|
+
});
|
|
2427
|
+
const trailingGap = Math.max(totalSize - previousEnd, 0);
|
|
2428
|
+
if (trailingGap > 0) {
|
|
2429
|
+
items.push(
|
|
2430
|
+
/* @__PURE__ */ jsx15(
|
|
2431
|
+
"div",
|
|
2432
|
+
{
|
|
2433
|
+
style: { height: `${trailingGap}px` }
|
|
2434
|
+
},
|
|
2435
|
+
`gap:${previousIndex}:end`
|
|
2436
|
+
)
|
|
2437
|
+
);
|
|
2438
|
+
}
|
|
2439
|
+
return items;
|
|
2440
|
+
}, [totalSize, virtualItems, getMeasureRef, contentIds, renderItem]);
|
|
2441
|
+
return /* @__PURE__ */ jsx15(Fragment3, { children: renderedItems });
|
|
2442
|
+
};
|
|
2443
|
+
|
|
2444
|
+
// components/DropZone/index.tsx
|
|
2445
|
+
import { Fragment as Fragment4, jsx as jsx16, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
2446
|
+
var getClassName5 = get_class_name_factory_default("DropZone", styles_module_default4);
|
|
2447
|
+
var getRandomColor = () => `#${Math.floor(Math.random() * 16777215).toString(16)}`;
|
|
2448
|
+
var RENDER_DEBUG = false;
|
|
2449
|
+
var InsertPreview = ({
|
|
2450
|
+
element,
|
|
2451
|
+
label,
|
|
2452
|
+
override
|
|
2453
|
+
}) => {
|
|
2454
|
+
if (element) {
|
|
2455
|
+
return (
|
|
2456
|
+
// Safe to use this since the HTML is set by the user
|
|
2457
|
+
/* @__PURE__ */ jsx16("div", { dangerouslySetInnerHTML: { __html: DOMPurify2.sanitize(element.outerHTML) } })
|
|
2458
|
+
);
|
|
2459
|
+
}
|
|
2460
|
+
return /* @__PURE__ */ jsx16(DrawerItemInner, { name: label, children: override });
|
|
2461
|
+
};
|
|
2462
|
+
var DropZoneEditPure = (props) => /* @__PURE__ */ jsx16(DropZoneEdit, { ...props });
|
|
2463
|
+
var DropZoneChild = ({
|
|
2464
|
+
zoneCompound,
|
|
2465
|
+
componentId,
|
|
2466
|
+
index,
|
|
2467
|
+
dragAxis,
|
|
2468
|
+
collisionAxis,
|
|
2469
|
+
inDroppableZone,
|
|
2470
|
+
itemRef
|
|
2471
|
+
}) => {
|
|
2472
|
+
const metadata = useAppStore((s) => s.metadata);
|
|
2473
|
+
const ctx = useContext5(dropZoneContext);
|
|
2474
|
+
const { depth = 1 } = ctx ?? {};
|
|
2475
|
+
const zoneStore = useContext5(ZoneStoreContext);
|
|
2476
|
+
const nodeProps = useAppStore(
|
|
2477
|
+
useShallow3((s) => {
|
|
2478
|
+
return s.state.indexes.nodes[componentId]?.flatData.props;
|
|
2479
|
+
})
|
|
2480
|
+
);
|
|
2481
|
+
const nodeType = useAppStore(
|
|
2482
|
+
(s) => s.state.indexes.nodes[componentId]?.data.type
|
|
2483
|
+
);
|
|
2484
|
+
const nodeReadOnly = useAppStore(
|
|
2485
|
+
useShallow3((s) => s.state.indexes.nodes[componentId]?.data.readOnly)
|
|
2486
|
+
);
|
|
2487
|
+
const appStore = useAppStoreApi();
|
|
2488
|
+
const item = useMemo8(() => {
|
|
2489
|
+
if (nodeProps) {
|
|
2490
|
+
const expanded = expandNode({
|
|
2491
|
+
type: nodeType,
|
|
2492
|
+
props: nodeProps
|
|
2493
|
+
});
|
|
2494
|
+
return expanded;
|
|
2495
|
+
}
|
|
2496
|
+
const preview = zoneStore.getState().previewIndex[zoneCompound];
|
|
2497
|
+
if (componentId === preview?.props.id) {
|
|
2498
|
+
return {
|
|
2499
|
+
type: preview.componentType,
|
|
2500
|
+
props: preview.props,
|
|
2501
|
+
previewType: preview.type,
|
|
2502
|
+
element: preview.element
|
|
2503
|
+
};
|
|
2504
|
+
}
|
|
2505
|
+
return null;
|
|
2506
|
+
}, [componentId, zoneCompound, nodeType, nodeProps, zoneStore]);
|
|
2507
|
+
const componentConfig = useAppStore(
|
|
2508
|
+
(s) => item?.type ? s.config.components[item.type] : null
|
|
2509
|
+
);
|
|
2510
|
+
const credbuildProps = useMemo8(
|
|
2511
|
+
() => ({
|
|
2512
|
+
renderDropZone: DropZoneEditPure,
|
|
2513
|
+
isEditing: true,
|
|
2514
|
+
dragRef: null,
|
|
2515
|
+
metadata: { ...metadata, ...componentConfig?.metadata }
|
|
2516
|
+
}),
|
|
2517
|
+
[metadata, componentConfig?.metadata]
|
|
2518
|
+
);
|
|
2519
|
+
const overrides = useAppStore((s) => s.overrides);
|
|
2520
|
+
const isLoading = useAppStore(
|
|
2521
|
+
(s) => s.componentState[componentId]?.loadingCount > 0
|
|
2522
|
+
);
|
|
2523
|
+
const isSelected = useAppStore(
|
|
2524
|
+
(s) => s.selectedItem?.props.id === componentId || false
|
|
2525
|
+
);
|
|
2526
|
+
let label = componentConfig?.label ?? item?.type.toString() ?? "Component";
|
|
2527
|
+
const defaultsProps = useMemo8(
|
|
2528
|
+
() => ({
|
|
2529
|
+
...componentConfig?.defaultProps,
|
|
2530
|
+
...item?.props,
|
|
2531
|
+
credbuild: credbuildProps,
|
|
2532
|
+
editMode: true
|
|
2533
|
+
// DEPRECATED
|
|
2534
|
+
}),
|
|
2535
|
+
[componentConfig?.defaultProps, item?.props, credbuildProps]
|
|
2536
|
+
);
|
|
2537
|
+
const defaultedNode = useMemo8(
|
|
2538
|
+
() => ({ type: item?.type ?? nodeType, props: defaultsProps }),
|
|
2539
|
+
[item?.type, nodeType, defaultsProps]
|
|
2540
|
+
);
|
|
2541
|
+
const config = useAppStore((s) => s.config);
|
|
2542
|
+
const plugins = useAppStore((s) => s.plugins);
|
|
2543
|
+
const userFieldTransforms = useAppStore((s) => s.fieldTransforms);
|
|
2544
|
+
const combinedFieldTransforms = useMemo8(
|
|
2545
|
+
() => ({
|
|
2546
|
+
...getSlotTransform(DropZoneEditPure, (slotProps) => /* @__PURE__ */ jsx16(ContextSlotRender, { componentId, zone: slotProps.zone })),
|
|
2547
|
+
...getInlineTextTransform(),
|
|
2548
|
+
...getRichTextTransform(),
|
|
2549
|
+
...plugins.reduce(
|
|
2550
|
+
(acc, plugin) => ({ ...acc, ...plugin.fieldTransforms }),
|
|
2551
|
+
{}
|
|
2552
|
+
),
|
|
2553
|
+
...userFieldTransforms
|
|
2554
|
+
}),
|
|
2555
|
+
[plugins, userFieldTransforms, componentId]
|
|
2556
|
+
);
|
|
2557
|
+
const transformedProps = useFieldTransformsTracked(
|
|
2558
|
+
config,
|
|
2559
|
+
defaultedNode,
|
|
2560
|
+
combinedFieldTransforms,
|
|
2561
|
+
nodeReadOnly,
|
|
2562
|
+
isLoading
|
|
2563
|
+
);
|
|
2564
|
+
if (!item) return;
|
|
2565
|
+
const Render = componentConfig ? componentConfig.render : () => /* @__PURE__ */ jsxs6("div", { style: { padding: 48, textAlign: "center" }, children: [
|
|
2566
|
+
"No configuration for ",
|
|
2567
|
+
item.type
|
|
2568
|
+
] });
|
|
2569
|
+
let componentType = item.type;
|
|
2570
|
+
const isInserting = "previewType" in item ? item.previewType === "insert" : false;
|
|
2571
|
+
return /* @__PURE__ */ jsx16(
|
|
2572
|
+
DraggableComponent,
|
|
2573
|
+
{
|
|
2574
|
+
id: componentId,
|
|
2575
|
+
componentType,
|
|
2576
|
+
zoneCompound,
|
|
2577
|
+
depth: depth + 1,
|
|
2578
|
+
index,
|
|
2579
|
+
isLoading,
|
|
2580
|
+
isSelected,
|
|
2581
|
+
label,
|
|
2582
|
+
autoDragAxis: dragAxis,
|
|
2583
|
+
userDragAxis: collisionAxis,
|
|
2584
|
+
inDroppableZone,
|
|
2585
|
+
itemRef,
|
|
2586
|
+
children: (dragRef) => {
|
|
2587
|
+
if (componentConfig?.inline && !isInserting) {
|
|
2588
|
+
return /* @__PURE__ */ jsx16(
|
|
2589
|
+
MemoizeComponent,
|
|
2590
|
+
{
|
|
2591
|
+
Component: Render,
|
|
2592
|
+
componentProps: {
|
|
2593
|
+
...transformedProps,
|
|
2594
|
+
credbuild: { ...transformedProps.credbuild, dragRef }
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
);
|
|
2598
|
+
}
|
|
2599
|
+
return /* @__PURE__ */ jsx16("div", { ref: dragRef, children: isInserting ? /* @__PURE__ */ jsx16(
|
|
2600
|
+
InsertPreview,
|
|
2601
|
+
{
|
|
2602
|
+
label,
|
|
2603
|
+
override: overrides.componentItem ?? overrides.drawerItem,
|
|
2604
|
+
element: "element" in item && item.element ? item.element : void 0
|
|
2605
|
+
}
|
|
2606
|
+
) : /* @__PURE__ */ jsx16(
|
|
2607
|
+
MemoizeComponent,
|
|
2608
|
+
{
|
|
2609
|
+
Component: Render,
|
|
2610
|
+
componentProps: transformedProps
|
|
2611
|
+
}
|
|
2612
|
+
) });
|
|
2613
|
+
}
|
|
2614
|
+
}
|
|
2615
|
+
);
|
|
2616
|
+
};
|
|
2617
|
+
var DropZoneChildMemo = memo4(DropZoneChild);
|
|
2618
|
+
var DropZoneEdit = forwardRef2(
|
|
2619
|
+
function DropZoneEditInternal({
|
|
2620
|
+
zone,
|
|
2621
|
+
allow,
|
|
2622
|
+
disallow,
|
|
2623
|
+
style,
|
|
2624
|
+
className,
|
|
2625
|
+
minEmptyHeight: userMinEmptyHeight = "128px",
|
|
2626
|
+
collisionAxis,
|
|
2627
|
+
as
|
|
2628
|
+
}, userRef) {
|
|
2629
|
+
const ctx = useContext5(dropZoneContext);
|
|
2630
|
+
const appStoreApi = useAppStoreApi();
|
|
2631
|
+
const {
|
|
2632
|
+
// These all need setting via context
|
|
2633
|
+
areaId,
|
|
2634
|
+
depth = 0,
|
|
2635
|
+
registerLocalZone,
|
|
2636
|
+
unregisterLocalZone
|
|
2637
|
+
} = ctx ?? {};
|
|
2638
|
+
const path = useAppStore(
|
|
2639
|
+
useShallow3((s) => areaId ? s.state.indexes.nodes[areaId]?.path : null)
|
|
2640
|
+
);
|
|
2641
|
+
let zoneCompound = rootDroppableId;
|
|
2642
|
+
if (areaId) {
|
|
2643
|
+
if (zone !== rootDroppableId) {
|
|
2644
|
+
zoneCompound = `${areaId}:${zone}`;
|
|
2645
|
+
}
|
|
2646
|
+
}
|
|
2647
|
+
const isRootZone = zoneCompound === rootDroppableId || zone === rootDroppableId || areaId === "root";
|
|
2648
|
+
const inNextDeepestArea = useContextStore(
|
|
2649
|
+
ZoneStoreContext,
|
|
2650
|
+
(s) => s.nextAreaDepthIndex[areaId || ""]
|
|
2651
|
+
);
|
|
2652
|
+
const zoneContentIds = useAppStore(
|
|
2653
|
+
useShallow3((s) => {
|
|
2654
|
+
return s.state.indexes.zones[zoneCompound]?.contentIds;
|
|
2655
|
+
})
|
|
2656
|
+
);
|
|
2657
|
+
const zoneType = useAppStore(
|
|
2658
|
+
useShallow3((s) => {
|
|
2659
|
+
return s.state.indexes.zones[zoneCompound]?.type;
|
|
2660
|
+
})
|
|
2661
|
+
);
|
|
2662
|
+
useEffect9(() => {
|
|
2663
|
+
if (!zoneType || zoneType === "dropzone") {
|
|
2664
|
+
if (ctx?.registerZone) {
|
|
2665
|
+
ctx?.registerZone(zoneCompound);
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2668
|
+
}, [zoneType, appStoreApi, ctx, zoneCompound]);
|
|
2669
|
+
useEffect9(() => {
|
|
2670
|
+
if (zoneType === "dropzone") {
|
|
2671
|
+
if (zoneCompound !== rootDroppableId) {
|
|
2672
|
+
console.warn(
|
|
2673
|
+
"DropZones have been deprecated in favor of slot fields and will be removed in a future version of CredBuild. Please see the migration guide: https://www.credbuild.com/docs/guides/migrations/dropzones-to-slots"
|
|
2674
|
+
);
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
}, [zoneType, zoneCompound]);
|
|
2678
|
+
const contentIds = useMemo8(() => {
|
|
2679
|
+
return zoneContentIds || [];
|
|
2680
|
+
}, [zoneContentIds]);
|
|
2681
|
+
const ref = useRef8(null);
|
|
2682
|
+
const acceptsTarget = useCallback10(
|
|
2683
|
+
(componentType) => {
|
|
2684
|
+
if (!componentType) {
|
|
2685
|
+
return true;
|
|
2686
|
+
}
|
|
2687
|
+
if (disallow) {
|
|
2688
|
+
const defaultedAllow = allow || [];
|
|
2689
|
+
const filteredDisallow = (disallow || []).filter(
|
|
2690
|
+
(item) => defaultedAllow.indexOf(item) === -1
|
|
2691
|
+
);
|
|
2692
|
+
if (filteredDisallow.indexOf(componentType) !== -1) {
|
|
2693
|
+
return false;
|
|
2694
|
+
}
|
|
2695
|
+
} else if (allow) {
|
|
2696
|
+
if (allow.indexOf(componentType) === -1) {
|
|
2697
|
+
return false;
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2700
|
+
return true;
|
|
2701
|
+
},
|
|
2702
|
+
[allow, disallow]
|
|
2703
|
+
);
|
|
2704
|
+
const targetAccepted = useContextStore(ZoneStoreContext, (s) => {
|
|
2705
|
+
const draggedComponentType = s.draggedItem?.data.componentType;
|
|
2706
|
+
return acceptsTarget(draggedComponentType);
|
|
2707
|
+
});
|
|
2708
|
+
const hoveringOverArea = inNextDeepestArea || isRootZone;
|
|
2709
|
+
const isEnabled = useContextStore(ZoneStoreContext, (s) => {
|
|
2710
|
+
let _isEnabled = true;
|
|
2711
|
+
const isDeepestZone = s.zoneDepthIndex[zoneCompound] ?? false;
|
|
2712
|
+
_isEnabled = isDeepestZone;
|
|
2713
|
+
if (_isEnabled) {
|
|
2714
|
+
_isEnabled = targetAccepted;
|
|
2715
|
+
}
|
|
2716
|
+
return _isEnabled;
|
|
2717
|
+
});
|
|
2718
|
+
useEffect9(() => {
|
|
2719
|
+
if (registerLocalZone) {
|
|
2720
|
+
registerLocalZone(zoneCompound, targetAccepted || isEnabled);
|
|
2721
|
+
}
|
|
2722
|
+
return () => {
|
|
2723
|
+
if (unregisterLocalZone) {
|
|
2724
|
+
unregisterLocalZone(zoneCompound);
|
|
2725
|
+
}
|
|
2726
|
+
};
|
|
2727
|
+
}, [targetAccepted, isEnabled, zoneCompound, registerLocalZone, unregisterLocalZone]);
|
|
2728
|
+
const [contentIdsWithPreview, preview] = useContentIdsWithPreview(
|
|
2729
|
+
contentIds,
|
|
2730
|
+
zoneCompound
|
|
2731
|
+
);
|
|
2732
|
+
const isDropEnabled = isEnabled && (preview ? contentIdsWithPreview.length === 1 : contentIdsWithPreview.length === 0);
|
|
2733
|
+
const zoneStore = useContext5(ZoneStoreContext);
|
|
2734
|
+
useEffect9(() => {
|
|
2735
|
+
const { enabledIndex } = zoneStore.getState();
|
|
2736
|
+
zoneStore.setState({
|
|
2737
|
+
enabledIndex: { ...enabledIndex, [zoneCompound]: isEnabled }
|
|
2738
|
+
});
|
|
2739
|
+
}, [isEnabled, zoneStore, zoneCompound]);
|
|
2740
|
+
const droppableConfig = {
|
|
2741
|
+
id: zoneCompound,
|
|
2742
|
+
collisionPriority: isEnabled ? depth : 0,
|
|
2743
|
+
disabled: !isDropEnabled,
|
|
2744
|
+
collisionDetector: pointerIntersection,
|
|
2745
|
+
type: "dropzone",
|
|
2746
|
+
data: {
|
|
2747
|
+
areaId,
|
|
2748
|
+
depth,
|
|
2749
|
+
isDroppableTarget: targetAccepted,
|
|
2750
|
+
path: path || []
|
|
2751
|
+
}
|
|
2752
|
+
};
|
|
2753
|
+
const { ref: dropRef } = useDroppable2(droppableConfig);
|
|
2754
|
+
const isAreaSelected = useAppStore(
|
|
2755
|
+
(s) => s?.selectedItem && areaId === s?.selectedItem.props.id
|
|
2756
|
+
);
|
|
2757
|
+
const [dragAxis] = useDragAxis(ref, collisionAxis);
|
|
2758
|
+
const [minEmptyHeight, isAnimating] = useMinEmptyHeight({
|
|
2759
|
+
zoneCompound,
|
|
2760
|
+
userMinEmptyHeight,
|
|
2761
|
+
ref
|
|
2762
|
+
});
|
|
2763
|
+
const setRefs = useCallback10(
|
|
2764
|
+
(node) => {
|
|
2765
|
+
assignRefs([ref, dropRef, userRef], node);
|
|
2766
|
+
},
|
|
2767
|
+
[dropRef, userRef]
|
|
2768
|
+
);
|
|
2769
|
+
const _experimentalVirtualization = useAppStore(
|
|
2770
|
+
(s) => s._experimentalVirtualization
|
|
2771
|
+
);
|
|
2772
|
+
const El = as ?? "div";
|
|
2773
|
+
const isRootAreaZone = (areaId ?? rootAreaId) === rootAreaId && depth === 0;
|
|
2774
|
+
const shouldVirtualizeItems = _experimentalVirtualization && isRootAreaZone;
|
|
2775
|
+
return /* @__PURE__ */ jsx16(
|
|
2776
|
+
El,
|
|
2777
|
+
{
|
|
2778
|
+
className: `${getClassName5({
|
|
2779
|
+
isRootZone,
|
|
2780
|
+
hoveringOverArea,
|
|
2781
|
+
isEnabled,
|
|
2782
|
+
isAreaSelected,
|
|
2783
|
+
hasChildren: contentIds.length > 0,
|
|
2784
|
+
isAnimating
|
|
2785
|
+
})}${className ? ` ${className}` : ""}`,
|
|
2786
|
+
ref: setRefs,
|
|
2787
|
+
"data-testid": `dropzone:${zoneCompound}`,
|
|
2788
|
+
"data-credbuild-dropzone": zoneCompound,
|
|
2789
|
+
style: {
|
|
2790
|
+
...style,
|
|
2791
|
+
"--min-empty-height": minEmptyHeight,
|
|
2792
|
+
backgroundColor: RENDER_DEBUG ? getRandomColor() : style?.backgroundColor
|
|
2793
|
+
},
|
|
2794
|
+
children: shouldVirtualizeItems ? /* @__PURE__ */ jsx16(
|
|
2795
|
+
VirtualizedDropZone,
|
|
2796
|
+
{
|
|
2797
|
+
contentIds: contentIdsWithPreview,
|
|
2798
|
+
zoneCompound,
|
|
2799
|
+
renderItem: (props) => /* @__PURE__ */ jsx16(
|
|
2800
|
+
DropZoneChildMemo,
|
|
2801
|
+
{
|
|
2802
|
+
zoneCompound,
|
|
2803
|
+
componentId: props.componentId,
|
|
2804
|
+
dragAxis,
|
|
2805
|
+
index: props.index,
|
|
2806
|
+
collisionAxis,
|
|
2807
|
+
inDroppableZone: targetAccepted,
|
|
2808
|
+
itemRef: props.measureRef
|
|
2809
|
+
},
|
|
2810
|
+
props.componentId
|
|
2811
|
+
)
|
|
2812
|
+
}
|
|
2813
|
+
) : contentIdsWithPreview.map((componentId, i) => /* @__PURE__ */ jsx16(
|
|
2814
|
+
DropZoneChildMemo,
|
|
2815
|
+
{
|
|
2816
|
+
zoneCompound,
|
|
2817
|
+
componentId,
|
|
2818
|
+
dragAxis,
|
|
2819
|
+
index: i,
|
|
2820
|
+
collisionAxis,
|
|
2821
|
+
inDroppableZone: targetAccepted
|
|
2822
|
+
},
|
|
2823
|
+
componentId
|
|
2824
|
+
))
|
|
2825
|
+
}
|
|
2826
|
+
);
|
|
2827
|
+
}
|
|
2828
|
+
);
|
|
2829
|
+
var DropZoneRenderItem = memo4(({
|
|
2830
|
+
config,
|
|
2831
|
+
item,
|
|
2832
|
+
metadata
|
|
2833
|
+
}) => {
|
|
2834
|
+
const Component = config.components[item.type];
|
|
2835
|
+
const props = useSlots(config, item, (slotProps) => /* @__PURE__ */ jsx16(SlotRenderPure, { ...slotProps, config, metadata }));
|
|
2836
|
+
const nextContextValue = useMemo8(
|
|
2837
|
+
() => ({
|
|
2838
|
+
areaId: props.id,
|
|
2839
|
+
depth: 1
|
|
2840
|
+
}),
|
|
2841
|
+
[props]
|
|
2842
|
+
);
|
|
2843
|
+
const richtextProps = useRichtextProps(Component.fields, props);
|
|
2844
|
+
return /* @__PURE__ */ jsx16(DropZoneProvider, { value: nextContextValue, children: /* @__PURE__ */ jsx16(
|
|
2845
|
+
Component.render,
|
|
2846
|
+
{
|
|
2847
|
+
...props,
|
|
2848
|
+
...richtextProps,
|
|
2849
|
+
credbuild: {
|
|
2850
|
+
...props.credbuild,
|
|
2851
|
+
renderDropZone: DropZoneRenderPure,
|
|
2852
|
+
metadata: { ...metadata, ...Component.metadata }
|
|
2853
|
+
}
|
|
2854
|
+
}
|
|
2855
|
+
) }, props.id);
|
|
2856
|
+
});
|
|
2857
|
+
var DropZoneRenderPure = (props) => /* @__PURE__ */ jsx16(DropZoneRender, { ...props });
|
|
2858
|
+
var DropZoneRender = forwardRef2(
|
|
2859
|
+
function DropZoneRenderInternal({ className, style, zone, as }, ref) {
|
|
2860
|
+
const ctx = useContext5(dropZoneContext);
|
|
2861
|
+
const { areaId = "root" } = ctx || {};
|
|
2862
|
+
const { config, data, metadata } = useContext5(renderContext);
|
|
2863
|
+
let zoneCompound = `${areaId}:${zone}`;
|
|
2864
|
+
const content = useMemo8(() => {
|
|
2865
|
+
if (zoneCompound !== rootDroppableId) {
|
|
2866
|
+
return setupZone(data, zoneCompound).zones[zoneCompound];
|
|
2867
|
+
}
|
|
2868
|
+
return data?.content || [];
|
|
2869
|
+
}, [data, zoneCompound]);
|
|
2870
|
+
useEffect9(() => {
|
|
2871
|
+
if (!content) {
|
|
2872
|
+
if (ctx?.registerZone) {
|
|
2873
|
+
ctx?.registerZone(zoneCompound);
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
}, [content, ctx, zoneCompound]);
|
|
2877
|
+
const El = as ?? "div";
|
|
2878
|
+
if (!data || !config) {
|
|
2879
|
+
return null;
|
|
2880
|
+
}
|
|
2881
|
+
return /* @__PURE__ */ jsx16(El, { className, style, ref, children: content.map((item) => {
|
|
2882
|
+
const Component = config.components[item.type];
|
|
2883
|
+
if (Component) {
|
|
2884
|
+
return /* @__PURE__ */ jsx16(
|
|
2885
|
+
DropZoneRenderItem,
|
|
2886
|
+
{
|
|
2887
|
+
config,
|
|
2888
|
+
item,
|
|
2889
|
+
metadata
|
|
2890
|
+
},
|
|
2891
|
+
item.props.id
|
|
2892
|
+
);
|
|
2893
|
+
}
|
|
2894
|
+
return null;
|
|
2895
|
+
}) });
|
|
2896
|
+
}
|
|
2897
|
+
);
|
|
2898
|
+
var DropZonePure = (props) => /* @__PURE__ */ jsx16(DropZone, { ...props });
|
|
2899
|
+
var DropZone = forwardRef2(
|
|
2900
|
+
function DropZone2(props, ref) {
|
|
2901
|
+
const ctx = useContext5(dropZoneContext);
|
|
2902
|
+
if (ctx?.mode === "edit") {
|
|
2903
|
+
return /* @__PURE__ */ jsx16(Fragment4, { children: /* @__PURE__ */ jsx16(DropZoneEdit, { ...props, ref }) });
|
|
2904
|
+
}
|
|
2905
|
+
return /* @__PURE__ */ jsx16(Fragment4, { children: /* @__PURE__ */ jsx16(DropZoneRender, { ...props, ref }) });
|
|
2906
|
+
}
|
|
2907
|
+
);
|
|
2908
|
+
|
|
2909
|
+
// lib/migrate.ts
|
|
2910
|
+
var migrations = [
|
|
2911
|
+
// Migrate root to root.props
|
|
2912
|
+
(data) => {
|
|
2913
|
+
const rootProps = data.root.props || data.root;
|
|
2914
|
+
if (Object.keys(data.root).length > 0 && !data.root.props) {
|
|
2915
|
+
console.warn(
|
|
2916
|
+
"Migration applied: Root props moved from `root` to `root.props`."
|
|
2917
|
+
);
|
|
2918
|
+
return {
|
|
2919
|
+
...data,
|
|
2920
|
+
root: {
|
|
2921
|
+
props: {
|
|
2922
|
+
...rootProps
|
|
2923
|
+
}
|
|
2924
|
+
}
|
|
2925
|
+
};
|
|
2926
|
+
}
|
|
2927
|
+
return data;
|
|
2928
|
+
},
|
|
2929
|
+
// Migrate zones to slots
|
|
2930
|
+
(data, config, migrationOptions) => {
|
|
2931
|
+
if (!config) return data;
|
|
2932
|
+
console.log("Migrating DropZones to slots...");
|
|
2933
|
+
const updatedItems = {};
|
|
2934
|
+
const appState = { ...defaultAppState, data };
|
|
2935
|
+
const { indexes } = walkAppState(appState, config);
|
|
2936
|
+
const deletedCompounds = [];
|
|
2937
|
+
walkAppState(appState, config, (content, zoneCompound, zoneType) => {
|
|
2938
|
+
if (zoneType === "dropzone") {
|
|
2939
|
+
const [id, slotName] = zoneCompound.split(":");
|
|
2940
|
+
const nodeData = indexes.nodes[id].data;
|
|
2941
|
+
const componentType = nodeData.type;
|
|
2942
|
+
const configForComponent = id === "root" ? config.root : config.components[componentType];
|
|
2943
|
+
if (configForComponent?.fields?.[slotName]?.type === "slot") {
|
|
2944
|
+
updatedItems[id] = {
|
|
2945
|
+
...nodeData,
|
|
2946
|
+
props: {
|
|
2947
|
+
...nodeData.props,
|
|
2948
|
+
...updatedItems[id]?.props,
|
|
2949
|
+
[slotName]: content
|
|
2950
|
+
}
|
|
2951
|
+
};
|
|
2952
|
+
deletedCompounds.push(zoneCompound);
|
|
2953
|
+
}
|
|
2954
|
+
return content;
|
|
2955
|
+
}
|
|
2956
|
+
return content;
|
|
2957
|
+
});
|
|
2958
|
+
const updated = walkAppState(
|
|
2959
|
+
appState,
|
|
2960
|
+
config,
|
|
2961
|
+
(content) => content,
|
|
2962
|
+
(item) => {
|
|
2963
|
+
return updatedItems[item.props.id] ?? item;
|
|
2964
|
+
}
|
|
2965
|
+
);
|
|
2966
|
+
deletedCompounds.forEach((zoneCompound) => {
|
|
2967
|
+
const [_, propName] = zoneCompound.split(":");
|
|
2968
|
+
console.log(
|
|
2969
|
+
`\u2713 Success: Migrated "${zoneCompound}" from DropZone to slot field "${propName}"`
|
|
2970
|
+
);
|
|
2971
|
+
delete updated.data.zones?.[zoneCompound];
|
|
2972
|
+
});
|
|
2973
|
+
if (migrationOptions?.migrateDynamicZonesForComponent) {
|
|
2974
|
+
const unmigratedZonesGrouped = {};
|
|
2975
|
+
Object.keys(updated.data.zones ?? {}).forEach((zoneCompound) => {
|
|
2976
|
+
const [componentId, propName] = zoneCompound.split(":");
|
|
2977
|
+
const content = updated.data.zones?.[zoneCompound];
|
|
2978
|
+
if (!content) {
|
|
2979
|
+
return;
|
|
2980
|
+
}
|
|
2981
|
+
if (!unmigratedZonesGrouped[componentId]) {
|
|
2982
|
+
unmigratedZonesGrouped[componentId] = {};
|
|
2983
|
+
}
|
|
2984
|
+
if (!unmigratedZonesGrouped[componentId][propName]) {
|
|
2985
|
+
unmigratedZonesGrouped[componentId][propName] = content;
|
|
2986
|
+
}
|
|
2987
|
+
});
|
|
2988
|
+
Object.keys(unmigratedZonesGrouped).forEach((componentId) => {
|
|
2989
|
+
updated.data = walkTree(updated.data, config, (content) => {
|
|
2990
|
+
return content.map((child) => {
|
|
2991
|
+
if (child.props.id !== componentId) {
|
|
2992
|
+
return child;
|
|
2993
|
+
}
|
|
2994
|
+
const migrateFn = migrationOptions?.migrateDynamicZonesForComponent?.[child.type];
|
|
2995
|
+
if (!migrateFn) {
|
|
2996
|
+
return child;
|
|
2997
|
+
}
|
|
2998
|
+
const zones = unmigratedZonesGrouped[componentId];
|
|
2999
|
+
const migratedProps = migrateFn(child.props, zones);
|
|
3000
|
+
Object.keys(zones).forEach((propName) => {
|
|
3001
|
+
const zoneCompound = `${componentId}:${propName}`;
|
|
3002
|
+
console.log(`\u2713 Success: Migrated "${zoneCompound}" DropZone`);
|
|
3003
|
+
delete updated.data.zones?.[zoneCompound];
|
|
3004
|
+
});
|
|
3005
|
+
return {
|
|
3006
|
+
...child,
|
|
3007
|
+
props: migratedProps
|
|
3008
|
+
};
|
|
3009
|
+
});
|
|
3010
|
+
});
|
|
3011
|
+
});
|
|
3012
|
+
}
|
|
3013
|
+
Object.keys(updated.data.zones ?? {}).forEach((zoneCompound) => {
|
|
3014
|
+
const [_, propName] = zoneCompound.split(":");
|
|
3015
|
+
throw new Error(
|
|
3016
|
+
`Could not migrate DropZone "${zoneCompound}" to slot field. No slot exists with the name "${propName}".`
|
|
3017
|
+
);
|
|
3018
|
+
});
|
|
3019
|
+
delete updated.data.zones;
|
|
3020
|
+
return updated.data;
|
|
3021
|
+
}
|
|
3022
|
+
];
|
|
3023
|
+
function migrate(data, config, migrationOptions) {
|
|
3024
|
+
return migrations?.reduce(
|
|
3025
|
+
(acc, migration) => migration(acc, config, migrationOptions),
|
|
3026
|
+
data
|
|
3027
|
+
);
|
|
3028
|
+
}
|
|
3029
|
+
|
|
3030
|
+
// lib/data/default-data.ts
|
|
3031
|
+
var defaultData = (data) => ({
|
|
3032
|
+
...data,
|
|
3033
|
+
root: data.root || {},
|
|
3034
|
+
content: data.content || []
|
|
3035
|
+
});
|
|
3036
|
+
|
|
3037
|
+
// lib/transform-props.ts
|
|
3038
|
+
function transformProps(data, propTransforms, config = { components: {} }) {
|
|
3039
|
+
const mapItem = (item) => {
|
|
3040
|
+
if (propTransforms[item.type]) {
|
|
3041
|
+
return {
|
|
3042
|
+
...item,
|
|
3043
|
+
props: {
|
|
3044
|
+
id: item.props.id,
|
|
3045
|
+
...propTransforms[item.type](item.props)
|
|
3046
|
+
}
|
|
3047
|
+
};
|
|
3048
|
+
}
|
|
3049
|
+
return item;
|
|
3050
|
+
};
|
|
3051
|
+
const defaultedData = defaultData(data);
|
|
3052
|
+
const rootProps = defaultedData.root.props || defaultedData.root;
|
|
3053
|
+
let newRoot = { ...defaultedData.root };
|
|
3054
|
+
if (propTransforms["root"]) {
|
|
3055
|
+
newRoot.props = propTransforms["root"](rootProps);
|
|
3056
|
+
}
|
|
3057
|
+
const dataWithUpdatedRoot = { ...defaultedData, root: newRoot };
|
|
3058
|
+
const updatedData = walkTree(
|
|
3059
|
+
dataWithUpdatedRoot,
|
|
3060
|
+
config,
|
|
3061
|
+
(content) => content.map(mapItem)
|
|
3062
|
+
);
|
|
3063
|
+
if (!defaultedData.root.props) {
|
|
3064
|
+
updatedData.root = updatedData.root.props;
|
|
3065
|
+
}
|
|
3066
|
+
return updatedData;
|
|
3067
|
+
}
|
|
3068
|
+
|
|
3069
|
+
// lib/group-zones-by-component.ts
|
|
3070
|
+
var groupZonesByComponent = (data) => {
|
|
3071
|
+
const zoneEntries = Object.entries(data.zones ?? {});
|
|
3072
|
+
return zoneEntries.reduce((acc, [zoneCompound, zoneContent]) => {
|
|
3073
|
+
const [componentId, zoneName] = getZoneId(zoneCompound);
|
|
3074
|
+
if (!componentId.length || !zoneName.length) return acc;
|
|
3075
|
+
if (!acc[componentId]) {
|
|
3076
|
+
acc[componentId] = [];
|
|
3077
|
+
}
|
|
3078
|
+
acc[componentId].push({ zoneCompound, content: zoneContent });
|
|
3079
|
+
return acc;
|
|
3080
|
+
}, {});
|
|
3081
|
+
};
|
|
3082
|
+
|
|
3083
|
+
// lib/resolve-all-data.ts
|
|
3084
|
+
async function resolveAllData(data, config, metadata = {}, onResolveStart, onResolveEnd) {
|
|
3085
|
+
const defaultedData = defaultData(data);
|
|
3086
|
+
const zonesByComponent = groupZonesByComponent(defaultedData);
|
|
3087
|
+
let resolvedZones = {};
|
|
3088
|
+
const resolveNode = async (_node, parent) => {
|
|
3089
|
+
const node = toComponent(_node);
|
|
3090
|
+
onResolveStart?.(node);
|
|
3091
|
+
const resolved = (await resolveComponentData(
|
|
3092
|
+
node,
|
|
3093
|
+
config,
|
|
3094
|
+
metadata,
|
|
3095
|
+
() => {
|
|
3096
|
+
},
|
|
3097
|
+
() => {
|
|
3098
|
+
},
|
|
3099
|
+
"force",
|
|
3100
|
+
parent
|
|
3101
|
+
)).node;
|
|
3102
|
+
const resolvedAsComponent = toComponent(resolved);
|
|
3103
|
+
const resolvedDeepPromise = mapFields(
|
|
3104
|
+
resolved,
|
|
3105
|
+
{
|
|
3106
|
+
slot: ({ value }) => processContent(value, resolvedAsComponent)
|
|
3107
|
+
},
|
|
3108
|
+
config
|
|
3109
|
+
);
|
|
3110
|
+
let resolveZonePromises = [];
|
|
3111
|
+
if (zonesByComponent[resolvedAsComponent.props.id]) {
|
|
3112
|
+
resolveZonePromises = zonesByComponent[resolvedAsComponent.props.id].map(
|
|
3113
|
+
async ({ zoneCompound, content }) => {
|
|
3114
|
+
resolvedZones[zoneCompound] = await processContent(
|
|
3115
|
+
content,
|
|
3116
|
+
resolvedAsComponent
|
|
3117
|
+
);
|
|
3118
|
+
}
|
|
3119
|
+
);
|
|
3120
|
+
}
|
|
3121
|
+
const resolvedDeep = await resolvedDeepPromise;
|
|
3122
|
+
await Promise.all(resolveZonePromises);
|
|
3123
|
+
onResolveEnd?.(toComponent(resolvedDeep));
|
|
3124
|
+
return resolvedDeep;
|
|
3125
|
+
};
|
|
3126
|
+
const processContent = async (content, parent) => {
|
|
3127
|
+
return Promise.all(content.map((item) => resolveNode(item, parent)));
|
|
3128
|
+
};
|
|
3129
|
+
const result = defaultData({});
|
|
3130
|
+
result.root = await resolveNode(defaultedData.root, null);
|
|
3131
|
+
result.content = await processContent(
|
|
3132
|
+
defaultedData.content,
|
|
3133
|
+
toComponent(result.root)
|
|
3134
|
+
);
|
|
3135
|
+
result.zones = resolvedZones;
|
|
3136
|
+
return result;
|
|
3137
|
+
}
|
|
3138
|
+
|
|
3139
|
+
export {
|
|
3140
|
+
SliderField,
|
|
3141
|
+
ResponsiveSliderField,
|
|
3142
|
+
ColorPickerField,
|
|
3143
|
+
dragListenerContext,
|
|
3144
|
+
Drawer,
|
|
3145
|
+
ZoneStoreContext,
|
|
3146
|
+
ZoneStoreProvider,
|
|
3147
|
+
DropZoneProvider,
|
|
3148
|
+
renderContext,
|
|
3149
|
+
useSlots,
|
|
3150
|
+
useRichtextProps,
|
|
3151
|
+
SlotRenderPure,
|
|
3152
|
+
SlotRender,
|
|
3153
|
+
registerOverlayPortal,
|
|
3154
|
+
getSelectorForId,
|
|
3155
|
+
getFrame,
|
|
3156
|
+
DropZoneEditPure,
|
|
3157
|
+
DropZoneRenderPure,
|
|
3158
|
+
DropZonePure,
|
|
3159
|
+
DropZone,
|
|
3160
|
+
migrate,
|
|
3161
|
+
transformProps,
|
|
3162
|
+
resolveAllData
|
|
3163
|
+
};
|