@measured/puck 0.1.4 → 0.1.6

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/index.js ADDED
@@ -0,0 +1,1245 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
37
+ var __esm = (fn, res) => function __init() {
38
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
39
+ };
40
+ var __commonJS = (cb, mod) => function __require() {
41
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
42
+ };
43
+ var __export = (target, all) => {
44
+ for (var name in all)
45
+ __defProp(target, name, { get: all[name], enumerable: true });
46
+ };
47
+ var __copyProps = (to, from, except, desc) => {
48
+ if (from && typeof from === "object" || typeof from === "function") {
49
+ for (let key of __getOwnPropNames(from))
50
+ if (!__hasOwnProp.call(to, key) && key !== except)
51
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
52
+ }
53
+ return to;
54
+ };
55
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
56
+ // If the importer is in node compatibility mode or this is not an ESM
57
+ // file that has been converted to a CommonJS file using a Babel-
58
+ // compatible transform (i.e. "__esModule" has not been set), then set
59
+ // "default" to the CommonJS "module.exports" for node compatibility.
60
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
61
+ mod
62
+ ));
63
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
64
+ var __async = (__this, __arguments, generator) => {
65
+ return new Promise((resolve, reject) => {
66
+ var fulfilled = (value) => {
67
+ try {
68
+ step(generator.next(value));
69
+ } catch (e) {
70
+ reject(e);
71
+ }
72
+ };
73
+ var rejected = (value) => {
74
+ try {
75
+ step(generator.throw(value));
76
+ } catch (e) {
77
+ reject(e);
78
+ }
79
+ };
80
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
81
+ step((generator = generator.apply(__this, __arguments)).next());
82
+ });
83
+ };
84
+
85
+ // ../tsup-config/react-import.js
86
+ var import_react;
87
+ var init_react_import = __esm({
88
+ "../tsup-config/react-import.js"() {
89
+ "use strict";
90
+ import_react = __toESM(require("react"));
91
+ }
92
+ });
93
+
94
+ // ../../node_modules/classnames/index.js
95
+ var require_classnames = __commonJS({
96
+ "../../node_modules/classnames/index.js"(exports, module2) {
97
+ init_react_import();
98
+ (function() {
99
+ "use strict";
100
+ var hasOwn = {}.hasOwnProperty;
101
+ var nativeCodeString = "[native code]";
102
+ function classNames() {
103
+ var classes = [];
104
+ for (var i = 0; i < arguments.length; i++) {
105
+ var arg = arguments[i];
106
+ if (!arg)
107
+ continue;
108
+ var argType = typeof arg;
109
+ if (argType === "string" || argType === "number") {
110
+ classes.push(arg);
111
+ } else if (Array.isArray(arg)) {
112
+ if (arg.length) {
113
+ var inner = classNames.apply(null, arg);
114
+ if (inner) {
115
+ classes.push(inner);
116
+ }
117
+ }
118
+ } else if (argType === "object") {
119
+ if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
120
+ classes.push(arg.toString());
121
+ continue;
122
+ }
123
+ for (var key in arg) {
124
+ if (hasOwn.call(arg, key) && arg[key]) {
125
+ classes.push(key);
126
+ }
127
+ }
128
+ }
129
+ }
130
+ return classes.join(" ");
131
+ }
132
+ if (typeof module2 !== "undefined" && module2.exports) {
133
+ classNames.default = classNames;
134
+ module2.exports = classNames;
135
+ } else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
136
+ define("classnames", [], function() {
137
+ return classNames;
138
+ });
139
+ } else {
140
+ window.classNames = classNames;
141
+ }
142
+ })();
143
+ }
144
+ });
145
+
146
+ // index.ts
147
+ var core_exports = {};
148
+ __export(core_exports, {
149
+ Puck: () => Puck,
150
+ Render: () => Render
151
+ });
152
+ module.exports = __toCommonJS(core_exports);
153
+ init_react_import();
154
+
155
+ // types/Config.tsx
156
+ init_react_import();
157
+
158
+ // components/Puck/index.tsx
159
+ init_react_import();
160
+ var import_react7 = require("react");
161
+ var import_react_beautiful_dnd4 = require("react-beautiful-dnd");
162
+
163
+ // components/DroppableStrictMode/index.tsx
164
+ init_react_import();
165
+ var import_react2 = require("react");
166
+ var import_react_beautiful_dnd = require("react-beautiful-dnd");
167
+ var import_jsx_runtime = require("react/jsx-runtime");
168
+ var DroppableStrictMode = (_a) => {
169
+ var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
170
+ const [enabled, setEnabled] = (0, import_react2.useState)(false);
171
+ (0, import_react2.useEffect)(() => {
172
+ const animation = requestAnimationFrame(() => setEnabled(true));
173
+ return () => {
174
+ cancelAnimationFrame(animation);
175
+ setEnabled(false);
176
+ };
177
+ }, []);
178
+ if (!enabled) {
179
+ return null;
180
+ }
181
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_beautiful_dnd.Droppable, __spreadProps(__spreadValues({}, props), { children }));
182
+ };
183
+ var DroppableStrictMode_default = DroppableStrictMode;
184
+
185
+ // components/DraggableComponent/index.tsx
186
+ init_react_import();
187
+ var import_react_beautiful_dnd2 = require("react-beautiful-dnd");
188
+
189
+ // css-module:/home/runner/work/puck/puck/packages/core/components/DraggableComponent/styles.module.css#css-module
190
+ init_react_import();
191
+ var styles_module_default = { "DraggableComponent": "_DraggableComponent_10y0g_1", "DraggableComponent-contents": "_DraggableComponent-contents_10y0g_5", "DraggableComponent-overlay": "_DraggableComponent-overlay_10y0g_9", "DraggableComponent--isModifierHeld": "_DraggableComponent--isModifierHeld_10y0g_25", "DraggableComponent--isSelected": "_DraggableComponent--isSelected_10y0g_29", "DraggableComponent-actions": "_DraggableComponent-actions_10y0g_34", "DraggableComponent-actionsLabel": "_DraggableComponent-actionsLabel_10y0g_49", "DraggableComponent-action": "_DraggableComponent-action_10y0g_34" };
192
+
193
+ // lib/get-class-name-factory.ts
194
+ init_react_import();
195
+ var import_classnames = __toESM(require_classnames());
196
+ var getClassNameFactory = (rootClass, styles, { baseClass = "" } = {}) => (options = {}) => {
197
+ let descendant = false;
198
+ let modifiers = false;
199
+ if (typeof options === "string") {
200
+ descendant = options;
201
+ } else if (typeof options === "object") {
202
+ modifiers = options;
203
+ }
204
+ if (descendant) {
205
+ return baseClass + styles[`${rootClass}-${descendant}`] || "";
206
+ } else if (modifiers) {
207
+ const prefixedModifiers = {};
208
+ for (let modifier in modifiers) {
209
+ prefixedModifiers[styles[`${rootClass}--${modifier}`]] = modifiers[modifier];
210
+ }
211
+ const c = styles[rootClass];
212
+ return baseClass + (0, import_classnames.default)(__spreadValues({
213
+ [c]: !!c
214
+ }, prefixedModifiers));
215
+ } else {
216
+ return baseClass + styles[rootClass] || "";
217
+ }
218
+ };
219
+ var get_class_name_factory_default = getClassNameFactory;
220
+
221
+ // components/DraggableComponent/index.tsx
222
+ var import_react_feather = require("react-feather");
223
+
224
+ // lib/use-modifier-held.ts
225
+ init_react_import();
226
+ var import_react3 = require("react");
227
+ var useModifierHeld = (modifier) => {
228
+ const [modifierHeld, setModifierHeld] = (0, import_react3.useState)(false);
229
+ function downHandler({ key }) {
230
+ if (key === modifier) {
231
+ setModifierHeld(true);
232
+ }
233
+ }
234
+ function upHandler({ key }) {
235
+ if (key === modifier) {
236
+ setModifierHeld(false);
237
+ }
238
+ }
239
+ (0, import_react3.useEffect)(() => {
240
+ window.addEventListener("keydown", downHandler);
241
+ window.addEventListener("keyup", upHandler);
242
+ return () => {
243
+ window.removeEventListener("keydown", downHandler);
244
+ window.removeEventListener("keyup", upHandler);
245
+ };
246
+ }, []);
247
+ return modifierHeld;
248
+ };
249
+
250
+ // components/DraggableComponent/index.tsx
251
+ var import_jsx_runtime2 = require("react/jsx-runtime");
252
+ var getClassName = get_class_name_factory_default("DraggableComponent", styles_module_default);
253
+ var DraggableComponent = ({
254
+ children,
255
+ id,
256
+ index,
257
+ isSelected = false,
258
+ onClick = () => null,
259
+ onDelete = () => null,
260
+ onDuplicate = () => null,
261
+ debug,
262
+ label
263
+ }) => {
264
+ const isModifierHeld = useModifierHeld("Alt");
265
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_beautiful_dnd2.Draggable, { draggableId: id, index, children: (provided) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
266
+ "div",
267
+ __spreadProps(__spreadValues(__spreadValues({
268
+ ref: provided.innerRef
269
+ }, provided.draggableProps), provided.dragHandleProps), {
270
+ className: getClassName({ isSelected, isModifierHeld }),
271
+ style: __spreadProps(__spreadValues({}, provided.draggableProps.style), {
272
+ cursor: isModifierHeld ? "initial" : "grab"
273
+ }),
274
+ children: [
275
+ debug,
276
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: getClassName("contents"), children }),
277
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: getClassName("overlay"), onClick, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: getClassName("actions"), children: [
278
+ label && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: getClassName("actionsLabel"), children: label }),
279
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { className: getClassName("action"), onClick: onDuplicate, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_feather.Copy, {}) }),
280
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { className: getClassName("action"), onClick: onDelete, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_feather.Trash, {}) })
281
+ ] }) })
282
+ ]
283
+ })
284
+ ) }, id);
285
+ };
286
+
287
+ // components/InputOrGroup/index.tsx
288
+ init_react_import();
289
+
290
+ // components/ExternalInput/index.tsx
291
+ init_react_import();
292
+ var import_react4 = require("react");
293
+
294
+ // css-module:/home/runner/work/puck/puck/packages/core/components/ExternalInput/styles.module.css#css-module
295
+ init_react_import();
296
+ var styles_module_default2 = { "ExternalInput": "_ExternalInput_v316c_1", "ExternalInput-actions": "_ExternalInput-actions_v316c_5", "ExternalInput-button": "_ExternalInput-button_v316c_9", "ExternalInput-detachButton": "_ExternalInput-detachButton_v316c_23", "ExternalInput--hasData": "_ExternalInput--hasData_v316c_30", "ExternalInput-modal": "_ExternalInput-modal_v316c_45", "ExternalInput--modalVisible": "_ExternalInput--modalVisible_v316c_59", "ExternalInput-modalInner": "_ExternalInput-modalInner_v316c_63", "ExternalInput-modalHeading": "_ExternalInput-modalHeading_v316c_74", "ExternalInput-modalTableWrapper": "_ExternalInput-modalTableWrapper_v316c_79" };
297
+
298
+ // components/ExternalInput/index.tsx
299
+ var import_jsx_runtime3 = require("react/jsx-runtime");
300
+ var getClassName2 = get_class_name_factory_default("ExternalInput", styles_module_default2);
301
+ var ExternalInput = ({
302
+ field,
303
+ onChange,
304
+ value = null
305
+ }) => {
306
+ const [data, setData] = (0, import_react4.useState)([]);
307
+ const [isOpen, setOpen] = (0, import_react4.useState)(false);
308
+ const [selectedData, setSelectedData] = (0, import_react4.useState)(value);
309
+ (0, import_react4.useEffect)(() => {
310
+ (() => __async(void 0, null, function* () {
311
+ if (field.adaptor) {
312
+ const listData = yield field.adaptor.fetchList(field.adaptorParams);
313
+ if (listData) {
314
+ setData(listData);
315
+ }
316
+ }
317
+ }))();
318
+ }, [field.adaptor, field.adaptorParams]);
319
+ if (!field.adaptor) {
320
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: "Incorrectly configured" });
321
+ }
322
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
323
+ "div",
324
+ {
325
+ className: getClassName2({
326
+ hasData: !!selectedData,
327
+ modalVisible: isOpen
328
+ }),
329
+ children: [
330
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: getClassName2("actions"), children: [
331
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
332
+ "button",
333
+ {
334
+ onClick: () => setOpen(true),
335
+ className: getClassName2("button"),
336
+ children: selectedData ? selectedData.attributes.title : `Select from ${field.adaptor.name}`
337
+ }
338
+ ),
339
+ selectedData && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
340
+ "button",
341
+ {
342
+ className: getClassName2("detachButton"),
343
+ onClick: () => {
344
+ setSelectedData(null);
345
+ onChange(null);
346
+ },
347
+ children: "Detach"
348
+ }
349
+ )
350
+ ] }),
351
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: getClassName2("modal"), onClick: () => setOpen(false), children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
352
+ "div",
353
+ {
354
+ className: getClassName2("modalInner"),
355
+ onClick: (e) => e.stopPropagation(),
356
+ children: [
357
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h2", { className: getClassName2("modalHeading"), children: "Select content" }),
358
+ data.length ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: getClassName2("modalTableWrapper"), children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("table", { children: [
359
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("tr", { children: Object.keys(data[0].attributes).map((key) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("th", { style: { textAlign: "left" }, children: key }, key)) }) }),
360
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("tbody", { children: data.map((item) => {
361
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
362
+ "tr",
363
+ {
364
+ style: { whiteSpace: "nowrap" },
365
+ onClick: (e) => {
366
+ onChange(item);
367
+ setOpen(false);
368
+ setSelectedData(item);
369
+ },
370
+ children: Object.keys(item.attributes).map((key) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("td", { children: item.attributes[key] }, key))
371
+ },
372
+ item.id
373
+ );
374
+ }) })
375
+ ] }) }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: "No content" })
376
+ ]
377
+ }
378
+ ) })
379
+ ]
380
+ }
381
+ );
382
+ };
383
+
384
+ // css-module:/home/runner/work/puck/puck/packages/core/components/InputOrGroup/styles.module.css#css-module
385
+ init_react_import();
386
+ var styles_module_default3 = { "Input": "_Input_1vwgb_1", "Input-label": "_Input-label_1vwgb_14", "Input-input": "_Input-input_1vwgb_20", "Input--readOnly": "_Input--readOnly_1vwgb_41", "Input-group": "_Input-group_1vwgb_50", "Input-action": "_Input-action_1vwgb_72", "Input-addButton": "_Input-addButton_1vwgb_93", "Input-item": "_Input-item_1vwgb_107", "Input-radioGroup": "_Input-radioGroup_1vwgb_114", "Input-radioGroupItems": "_Input-radioGroupItems_1vwgb_119", "Input-radio": "_Input-radio_1vwgb_114" };
387
+
388
+ // lib/index.ts
389
+ init_react_import();
390
+
391
+ // lib/filter.ts
392
+ init_react_import();
393
+ var filter = (obj, validKeys) => {
394
+ return validKeys.reduce((acc, item) => {
395
+ if (typeof obj[item] !== "undefined") {
396
+ return __spreadProps(__spreadValues({}, acc), { [item]: obj[item] });
397
+ }
398
+ return acc;
399
+ }, {});
400
+ };
401
+
402
+ // lib/reorder.ts
403
+ init_react_import();
404
+ var reorder = (list, startIndex, endIndex) => {
405
+ const result = Array.from(list);
406
+ const [removed] = result.splice(startIndex, 1);
407
+ result.splice(endIndex, 0, removed);
408
+ return result;
409
+ };
410
+
411
+ // lib/replace.ts
412
+ init_react_import();
413
+ var replace = (list, index, newItem) => {
414
+ const result = Array.from(list);
415
+ result.splice(index, 1);
416
+ result.splice(index, 0, newItem);
417
+ return result;
418
+ };
419
+
420
+ // components/InputOrGroup/index.tsx
421
+ var import_react_feather2 = require("react-feather");
422
+ var import_jsx_runtime4 = require("react/jsx-runtime");
423
+ var getClassName3 = get_class_name_factory_default("Input", styles_module_default3);
424
+ var InputOrGroup = ({
425
+ name,
426
+ field,
427
+ value,
428
+ label,
429
+ onChange,
430
+ readOnly
431
+ }) => {
432
+ if (field.type === "group") {
433
+ if (!field.groupFields) {
434
+ return null;
435
+ }
436
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: getClassName3(), children: [
437
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("b", { className: getClassName3("label"), children: label || name }),
438
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: getClassName3("item"), children: [
439
+ Array.isArray(value) ? value.map((item, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("details", { className: getClassName3("group"), children: [
440
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("summary", { children: [
441
+ field.getItemSummary ? field.getItemSummary(item, i) : `Item #${i}`,
442
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
443
+ "button",
444
+ {
445
+ className: getClassName3("action"),
446
+ onClick: () => {
447
+ const existingValue = value || [];
448
+ existingValue.splice(i, 1);
449
+ onChange(existingValue);
450
+ },
451
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_feather2.Trash, {})
452
+ }
453
+ )
454
+ ] }),
455
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("fieldset", { children: Object.keys(field.groupFields).map((fieldName) => {
456
+ const subField = field.groupFields[fieldName];
457
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
458
+ InputOrGroup,
459
+ {
460
+ name: `${name}_${i}_${fieldName}`,
461
+ label: fieldName,
462
+ field: subField,
463
+ value: item[fieldName],
464
+ onChange: (val) => onChange(
465
+ replace(value, i, __spreadProps(__spreadValues({}, item), { [fieldName]: val }))
466
+ )
467
+ },
468
+ `${name}_${i}_${fieldName}`
469
+ );
470
+ }) })
471
+ ] }, `${name}_${i}`)) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", {}),
472
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
473
+ "button",
474
+ {
475
+ className: getClassName3("addButton"),
476
+ onClick: () => {
477
+ const existingValue = value || [];
478
+ onChange([...existingValue, field.defaultItemProps || {}]);
479
+ },
480
+ children: "Add item"
481
+ }
482
+ )
483
+ ] })
484
+ ] });
485
+ }
486
+ if (field.type === "external") {
487
+ if (!field.adaptor) {
488
+ return null;
489
+ }
490
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: getClassName3(""), children: [
491
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: getClassName3("label"), children: name === "_data" ? "External content" : label || name }),
492
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ExternalInput, { field, onChange, value })
493
+ ] });
494
+ }
495
+ if (field.type === "select") {
496
+ if (!field.options) {
497
+ return null;
498
+ }
499
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { className: getClassName3(), children: [
500
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: getClassName3("label"), children: label || name }),
501
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
502
+ "select",
503
+ {
504
+ className: getClassName3("input"),
505
+ onChange: (e) => onChange(e.currentTarget.value),
506
+ value,
507
+ children: field.options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
508
+ "option",
509
+ {
510
+ label: option.label,
511
+ value: option.value
512
+ },
513
+ option.label + option.value
514
+ ))
515
+ }
516
+ )
517
+ ] });
518
+ }
519
+ if (field.type === "textarea") {
520
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { className: getClassName3({ readOnly }), children: [
521
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: getClassName3("label"), children: label || name }),
522
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
523
+ "textarea",
524
+ {
525
+ className: getClassName3("input"),
526
+ autoComplete: "off",
527
+ name,
528
+ value,
529
+ onChange: (e) => onChange(e.currentTarget.value),
530
+ readOnly,
531
+ rows: 5
532
+ }
533
+ )
534
+ ] });
535
+ }
536
+ if (field.type === "radio") {
537
+ if (!field.options) {
538
+ return null;
539
+ }
540
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: getClassName3("radioGroup"), children: [
541
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: getClassName3("label"), children: field.label || name }),
542
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: getClassName3("radioGroupItems"), children: field.options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
543
+ "label",
544
+ {
545
+ className: getClassName3("radio"),
546
+ children: [
547
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
548
+ "input",
549
+ {
550
+ type: "radio",
551
+ value: option.value,
552
+ name,
553
+ onChange: (e) => onChange(e.currentTarget.value),
554
+ readOnly,
555
+ defaultChecked: value === option.value
556
+ }
557
+ ),
558
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { children: option.label || option.value })
559
+ ]
560
+ },
561
+ option.label + option.value
562
+ )) })
563
+ ] });
564
+ }
565
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("label", { className: getClassName3({ readOnly }), children: [
566
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: getClassName3("label"), children: label || name }),
567
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
568
+ "input",
569
+ {
570
+ className: getClassName3("input"),
571
+ autoComplete: "off",
572
+ type: field.type,
573
+ name,
574
+ value,
575
+ onChange: (e) => onChange(e.currentTarget.value),
576
+ readOnly
577
+ }
578
+ )
579
+ ] });
580
+ };
581
+
582
+ // components/ComponentList/index.tsx
583
+ init_react_import();
584
+ var import_react_beautiful_dnd3 = require("react-beautiful-dnd");
585
+
586
+ // css-module:/home/runner/work/puck/puck/packages/core/components/ComponentList/styles.module.css#css-module
587
+ init_react_import();
588
+ var styles_module_default4 = { "ComponentList": "_ComponentList_91nmt_1", "ComponentList-item": "_ComponentList-item_91nmt_9", "ComponentList-itemShadow": "_ComponentList-itemShadow_91nmt_10", "ComponentList-itemIcon": "_ComponentList-itemIcon_91nmt_24" };
589
+
590
+ // components/ComponentList/index.tsx
591
+ var import_react_feather3 = require("react-feather");
592
+ var import_jsx_runtime5 = require("react/jsx-runtime");
593
+ var getClassName4 = get_class_name_factory_default("ComponentList", styles_module_default4);
594
+ var ComponentList = ({ config }) => {
595
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(DroppableStrictMode_default, { droppableId: "component-list", isDropDisabled: true, children: (provided, snapshot) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
596
+ "div",
597
+ __spreadProps(__spreadValues({}, provided.droppableProps), {
598
+ ref: provided.innerRef,
599
+ className: getClassName4(),
600
+ children: Object.keys(config.components).map((componentKey, i) => {
601
+ const componentConfig = config[componentKey];
602
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
603
+ import_react_beautiful_dnd3.Draggable,
604
+ {
605
+ draggableId: componentKey,
606
+ index: i,
607
+ children: (provided2, snapshot2) => {
608
+ var _a;
609
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
610
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
611
+ "div",
612
+ __spreadProps(__spreadValues(__spreadValues({
613
+ ref: provided2.innerRef
614
+ }, provided2.draggableProps), provided2.dragHandleProps), {
615
+ className: getClassName4("item"),
616
+ style: __spreadProps(__spreadValues({}, provided2.draggableProps.style), {
617
+ transform: snapshot2.isDragging ? (_a = provided2.draggableProps.style) == null ? void 0 : _a.transform : "translate(0px, 0px)"
618
+ }),
619
+ children: [
620
+ componentKey,
621
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: getClassName4("itemIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_feather3.Grid, { size: 18 }) })
622
+ ]
623
+ })
624
+ ),
625
+ snapshot2.isDragging && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
626
+ "div",
627
+ {
628
+ className: getClassName4("itemShadow"),
629
+ style: { transform: "none !important" },
630
+ children: [
631
+ componentKey,
632
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: getClassName4("itemIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_feather3.Grid, { size: 18 }) })
633
+ ]
634
+ }
635
+ )
636
+ ] });
637
+ }
638
+ },
639
+ componentKey
640
+ );
641
+ })
642
+ })
643
+ ) });
644
+ };
645
+
646
+ // components/OutlineList/index.tsx
647
+ init_react_import();
648
+
649
+ // css-module:/home/runner/work/puck/puck/packages/core/components/OutlineList/styles.module.css#css-module
650
+ init_react_import();
651
+ var styles_module_default5 = { "OutlineList": "_OutlineList_gor6f_1", "OutlineList-clickableItem": "_OutlineList-clickableItem_gor6f_36" };
652
+
653
+ // components/OutlineList/index.tsx
654
+ var import_jsx_runtime6 = require("react/jsx-runtime");
655
+ var getClassName5 = get_class_name_factory_default("OutlineList", styles_module_default5);
656
+ var OutlineList = ({ children }) => {
657
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ul", { className: getClassName5(), children });
658
+ };
659
+ OutlineList.Clickable = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: getClassName5("clickableItem"), children });
660
+ OutlineList.Item = ({
661
+ children,
662
+ onClick
663
+ }) => {
664
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
665
+ "li",
666
+ {
667
+ className: onClick ? getClassName5("clickableItem") : "",
668
+ onClick,
669
+ children
670
+ }
671
+ );
672
+ };
673
+
674
+ // components/Button/index.ts
675
+ init_react_import();
676
+
677
+ // components/Button/Button.tsx
678
+ init_react_import();
679
+ var import_react5 = require("react");
680
+
681
+ // css-module:/home/runner/work/puck/puck/packages/core/components/Button/Button.module.css#css-module
682
+ init_react_import();
683
+ var Button_module_default = { "Button": "_Button_1bqmn_1", "Button--primary": "_Button--primary_1bqmn_25", "Button--secondary": "_Button--secondary_1bqmn_34", "Button--flush": "_Button--flush_1bqmn_45", "Button--disabled": "_Button--disabled_1bqmn_49", "Button--fullWidth": "_Button--fullWidth_1bqmn_59" };
684
+
685
+ // components/Button/Button.tsx
686
+ var import_react_spinners = require("react-spinners");
687
+ var import_jsx_runtime7 = require("react/jsx-runtime");
688
+ var getClassName6 = get_class_name_factory_default("Button", Button_module_default);
689
+ var Button = ({
690
+ children,
691
+ href,
692
+ onClick,
693
+ variant = "primary",
694
+ type,
695
+ disabled,
696
+ tabIndex,
697
+ newTab,
698
+ fullWidth
699
+ }) => {
700
+ const [loading, setLoading] = (0, import_react5.useState)(false);
701
+ const ElementType = href ? "a" : "button";
702
+ const el = /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
703
+ ElementType,
704
+ {
705
+ className: getClassName6({
706
+ primary: variant === "primary",
707
+ secondary: variant === "secondary",
708
+ disabled,
709
+ fullWidth
710
+ }),
711
+ onClick: (e) => {
712
+ if (!onClick)
713
+ return;
714
+ setLoading(true);
715
+ Promise.resolve(onClick(e)).then(() => {
716
+ setLoading(false);
717
+ });
718
+ },
719
+ type,
720
+ disabled: disabled || loading,
721
+ tabIndex,
722
+ target: newTab ? "_blank" : void 0,
723
+ rel: newTab ? "noreferrer" : void 0,
724
+ href,
725
+ children: [
726
+ children,
727
+ loading && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
728
+ "\xA0\xA0",
729
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react_spinners.ClipLoader, { color: "inherit", size: "14px" })
730
+ ] })
731
+ ]
732
+ }
733
+ );
734
+ return el;
735
+ };
736
+
737
+ // lib/use-placeholder-style.ts
738
+ init_react_import();
739
+ var import_react6 = require("react");
740
+ var usePlaceholderStyle = () => {
741
+ const queryAttr = "data-rbd-drag-handle-draggable-id";
742
+ const [placeholderStyle, setPlaceholderStyle] = (0, import_react6.useState)();
743
+ const onDragUpdate = (update) => {
744
+ if (!update.destination) {
745
+ return;
746
+ }
747
+ const draggableId = update.draggableId;
748
+ const destinationIndex = update.destination.index;
749
+ const domQuery = `[${queryAttr}='${draggableId}']`;
750
+ const draggedDOM = document.querySelector(domQuery);
751
+ if (!draggedDOM) {
752
+ return;
753
+ }
754
+ const targetListElement = document.querySelector("#puck-drop-zone");
755
+ const { clientHeight } = draggedDOM;
756
+ if (!targetListElement) {
757
+ return;
758
+ }
759
+ let clientY = 0;
760
+ if (destinationIndex > 0) {
761
+ const children = Array.from(targetListElement.children).filter((item) => item !== draggedDOM).slice(0, destinationIndex);
762
+ clientY = children.reduce(
763
+ (total, item) => total + item.clientHeight + parseInt(window.getComputedStyle(item).marginTop.replace("px", "")),
764
+ 0
765
+ );
766
+ }
767
+ setPlaceholderStyle({
768
+ position: "absolute",
769
+ top: clientY,
770
+ left: 0,
771
+ height: clientHeight,
772
+ width: "100%"
773
+ });
774
+ };
775
+ return { onDragUpdate, placeholderStyle };
776
+ };
777
+
778
+ // components/SidebarSection/index.tsx
779
+ init_react_import();
780
+
781
+ // css-module:/home/runner/work/puck/puck/packages/core/components/SidebarSection/styles.module.css#css-module
782
+ init_react_import();
783
+ var styles_module_default6 = { "SidebarSection": "_SidebarSection_jsf8x_1", "SidebarSection-content": "_SidebarSection-content_jsf8x_1", "SidebarSection-title": "_SidebarSection-title_jsf8x_6" };
784
+
785
+ // components/Heading/index.tsx
786
+ init_react_import();
787
+
788
+ // css-module:/home/runner/work/puck/puck/packages/core/components/Heading/styles.module.css#css-module
789
+ init_react_import();
790
+ var styles_module_default7 = { "Heading": "_Heading_1y35v_1", "Heading--xxxxl": "_Heading--xxxxl_1y35v_12", "Heading--xxxl": "_Heading--xxxl_1y35v_18", "Heading--xxl": "_Heading--xxl_1y35v_22", "Heading--xl": "_Heading--xl_1y35v_26", "Heading--l": "_Heading--l_1y35v_30", "Heading--m": "_Heading--m_1y35v_34", "Heading--s": "_Heading--s_1y35v_38", "Heading--xs": "_Heading--xs_1y35v_42" };
791
+
792
+ // components/Heading/index.tsx
793
+ var import_jsx_runtime8 = require("react/jsx-runtime");
794
+ var getClassName7 = get_class_name_factory_default("Heading", styles_module_default7);
795
+ var Heading = ({ children, rank, size = "m" }) => {
796
+ const Tag = rank ? `h${rank}` : "span";
797
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
798
+ Tag,
799
+ {
800
+ className: getClassName7({
801
+ [size]: true
802
+ }),
803
+ children
804
+ }
805
+ );
806
+ };
807
+
808
+ // components/SidebarSection/index.tsx
809
+ var import_jsx_runtime9 = require("react/jsx-runtime");
810
+ var getClassName8 = get_class_name_factory_default("SidebarSection", styles_module_default6);
811
+ var SidebarSection = ({
812
+ children,
813
+ title
814
+ }) => {
815
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("details", { className: getClassName8({}), open: true, children: [
816
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("summary", { className: getClassName8("title"), children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Heading, { rank: 2, size: "xs", children: title }) }),
817
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: getClassName8("content"), children })
818
+ ] });
819
+ };
820
+
821
+ // lib/scroll-into-view.ts
822
+ init_react_import();
823
+ var scrollIntoView = (el) => {
824
+ const oldStyle = __spreadValues({}, el.style);
825
+ el.style.scrollMargin = "256px";
826
+ if (el) {
827
+ el == null ? void 0 : el.scrollIntoView({ behavior: "smooth" });
828
+ el.style.scrollMargin = oldStyle.scrollMargin || "";
829
+ }
830
+ };
831
+
832
+ // components/Puck/index.tsx
833
+ var import_jsx_runtime10 = require("react/jsx-runtime");
834
+ var defaultPageFields = {
835
+ title: { type: "text" }
836
+ };
837
+ var PluginRenderer = ({
838
+ children,
839
+ data,
840
+ plugins,
841
+ renderMethod
842
+ }) => {
843
+ return plugins.filter((item) => item[renderMethod]).map((item) => item[renderMethod]).reduce(
844
+ (accChildren, Item) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Item, { data, children: accChildren }),
845
+ children
846
+ );
847
+ };
848
+ function Puck({
849
+ config,
850
+ data: initialData = { content: [], page: { title: "" } },
851
+ onChange,
852
+ onPublish,
853
+ plugins = [],
854
+ renderHeader
855
+ }) {
856
+ var _a, _b;
857
+ const [data, setData] = (0, import_react7.useState)(initialData);
858
+ const [selectedIndex, setSelectedIndex] = (0, import_react7.useState)(null);
859
+ const Page = (0, import_react7.useCallback)(
860
+ (pageProps) => {
861
+ var _a2, _b2;
862
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
863
+ PluginRenderer,
864
+ {
865
+ plugins,
866
+ renderMethod: "renderPage",
867
+ data: pageProps.data,
868
+ children: ((_a2 = config.page) == null ? void 0 : _a2.render) ? (_b2 = config.page) == null ? void 0 : _b2.render(__spreadProps(__spreadValues({}, pageProps), { editMode: true })) : pageProps.children
869
+ }
870
+ );
871
+ },
872
+ [config.page]
873
+ );
874
+ const PageFieldWrapper = (0, import_react7.useCallback)(
875
+ (props) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
876
+ PluginRenderer,
877
+ {
878
+ plugins,
879
+ renderMethod: "renderPageFields",
880
+ data: props.data,
881
+ children: props.children
882
+ }
883
+ ),
884
+ []
885
+ );
886
+ const ComponentFieldWrapper = (0, import_react7.useCallback)(
887
+ (props) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
888
+ PluginRenderer,
889
+ {
890
+ plugins,
891
+ renderMethod: "renderFields",
892
+ data: props.data,
893
+ children: props.children
894
+ }
895
+ ),
896
+ []
897
+ );
898
+ const FieldWrapper = selectedIndex !== null ? ComponentFieldWrapper : PageFieldWrapper;
899
+ const pageFields = ((_a = config.page) == null ? void 0 : _a.fields) || defaultPageFields;
900
+ let fields = selectedIndex !== null ? ((_b = config.components[data.content[selectedIndex].type]) == null ? void 0 : _b.fields) || {} : pageFields;
901
+ (0, import_react7.useEffect)(() => {
902
+ if (onChange)
903
+ onChange(data);
904
+ }, [data]);
905
+ const { onDragUpdate, placeholderStyle } = usePlaceholderStyle();
906
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "puck", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
907
+ import_react_beautiful_dnd4.DragDropContext,
908
+ {
909
+ onDragUpdate,
910
+ onDragEnd: (droppedItem) => {
911
+ if (!droppedItem.destination) {
912
+ console.warn("No destination specified");
913
+ return;
914
+ }
915
+ if (droppedItem.source.droppableId === "component-list") {
916
+ const emptyComponentData = {
917
+ type: droppedItem.draggableId,
918
+ props: __spreadProps(__spreadValues({}, config.components[droppedItem.draggableId].defaultProps || {}), {
919
+ id: `${droppedItem.draggableId}-${(/* @__PURE__ */ new Date()).getTime()}`
920
+ // TODO make random string
921
+ })
922
+ };
923
+ const newData = __spreadValues({}, data);
924
+ newData.content.splice(
925
+ droppedItem.destination.index,
926
+ 0,
927
+ emptyComponentData
928
+ );
929
+ setData(newData);
930
+ setSelectedIndex(droppedItem.destination.index);
931
+ } else {
932
+ setData(__spreadProps(__spreadValues({}, data), {
933
+ content: reorder(
934
+ data.content,
935
+ droppedItem.source.index,
936
+ droppedItem.destination.index
937
+ )
938
+ }));
939
+ setSelectedIndex(null);
940
+ }
941
+ },
942
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
943
+ "div",
944
+ {
945
+ style: {
946
+ display: "grid",
947
+ gridTemplateAreas: '"header header header" "left editor right"',
948
+ gridTemplateColumns: "256px auto 256px",
949
+ gridTemplateRows: "min-content auto",
950
+ height: "100vh",
951
+ position: "fixed",
952
+ top: 0,
953
+ bottom: 0,
954
+ left: 0,
955
+ right: 0
956
+ },
957
+ children: [
958
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
959
+ "header",
960
+ {
961
+ style: {
962
+ background: "var(--puck-color-grey-0)",
963
+ color: "white",
964
+ gridArea: "header",
965
+ borderBottom: "1px solid #cccccc"
966
+ },
967
+ children: renderHeader ? renderHeader({
968
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
969
+ Button,
970
+ {
971
+ onClick: () => {
972
+ onPublish(data);
973
+ },
974
+ children: "Publish"
975
+ }
976
+ ),
977
+ data,
978
+ setData
979
+ }) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
980
+ "div",
981
+ {
982
+ style: {
983
+ display: "flex",
984
+ justifyContent: "flex-end",
985
+ padding: 16
986
+ },
987
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
988
+ Button,
989
+ {
990
+ onClick: () => {
991
+ onPublish(data);
992
+ },
993
+ children: "Publish"
994
+ }
995
+ )
996
+ }
997
+ )
998
+ }
999
+ ),
1000
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
1001
+ "div",
1002
+ {
1003
+ style: {
1004
+ gridArea: "left",
1005
+ background: "var(--puck-color-grey-10)",
1006
+ overflowY: "auto"
1007
+ },
1008
+ children: [
1009
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(SidebarSection, { title: "Components", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ComponentList, { config }) }),
1010
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(SidebarSection, { title: "Outline", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(OutlineList, { children: data.content.map((item, i) => {
1011
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1012
+ OutlineList.Item,
1013
+ {
1014
+ onClick: () => {
1015
+ setSelectedIndex(i);
1016
+ const id = data.content[i].props.id;
1017
+ scrollIntoView(
1018
+ document.querySelector(
1019
+ `[data-rbd-drag-handle-draggable-id="draggable-${id}"]`
1020
+ )
1021
+ );
1022
+ },
1023
+ children: item.type
1024
+ },
1025
+ i
1026
+ );
1027
+ }) }) })
1028
+ ]
1029
+ }
1030
+ ),
1031
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1032
+ "div",
1033
+ {
1034
+ style: {
1035
+ background: "var(--puck-color-grey-8)",
1036
+ padding: 32,
1037
+ overflowY: "auto",
1038
+ gridArea: "editor"
1039
+ },
1040
+ onClick: () => setSelectedIndex(null),
1041
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1042
+ "div",
1043
+ {
1044
+ className: "puck-root",
1045
+ style: {
1046
+ background: "white",
1047
+ borderRadius: 16,
1048
+ overflow: "hidden",
1049
+ zoom: 0.75
1050
+ },
1051
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Page, __spreadProps(__spreadValues({ data }, data.page), { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(DroppableStrictMode_default, { droppableId: "droppable", children: (provided, snapshot) => /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
1052
+ "div",
1053
+ __spreadProps(__spreadValues({}, provided.droppableProps), {
1054
+ ref: provided.innerRef,
1055
+ style: {
1056
+ minHeight: 128,
1057
+ position: "relative",
1058
+ zoom: 1.33
1059
+ },
1060
+ id: "puck-drop-zone",
1061
+ children: [
1062
+ data.content.map((item, i) => {
1063
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1064
+ DraggableComponent,
1065
+ {
1066
+ label: item.type.toString(),
1067
+ id: `draggable-${item.props.id}`,
1068
+ index: i,
1069
+ isSelected: selectedIndex === i,
1070
+ onClick: (e) => {
1071
+ setSelectedIndex(i);
1072
+ e.stopPropagation();
1073
+ },
1074
+ onDelete: (e) => {
1075
+ const newData = __spreadValues({}, data);
1076
+ newData.content.splice(i, 1);
1077
+ setSelectedIndex(null);
1078
+ setData(newData);
1079
+ e.stopPropagation();
1080
+ },
1081
+ onDuplicate: (e) => {
1082
+ const newData = __spreadValues({}, data);
1083
+ const newItem = __spreadProps(__spreadValues({}, newData.content[i]), {
1084
+ props: __spreadProps(__spreadValues({}, newData.content[i].props), {
1085
+ id: `${newData.content[i].type}-${(/* @__PURE__ */ new Date()).getTime()}`
1086
+ })
1087
+ });
1088
+ newData.content.splice(i + 1, 0, newItem);
1089
+ setData(newData);
1090
+ e.stopPropagation();
1091
+ },
1092
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { style: { zoom: 0.75 }, children: config.components[item.type] ? config.components[item.type].render(__spreadProps(__spreadValues(__spreadValues({}, config.components[item.type].defaultProps), item.props), {
1093
+ editMode: true
1094
+ })) : /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { children: [
1095
+ "No configuration for ",
1096
+ item.type
1097
+ ] }) })
1098
+ },
1099
+ item.props.id
1100
+ );
1101
+ }),
1102
+ provided.placeholder,
1103
+ snapshot.isDraggingOver && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1104
+ "div",
1105
+ {
1106
+ style: __spreadProps(__spreadValues({}, placeholderStyle), {
1107
+ background: "var(--puck-color-azure-8)",
1108
+ zIndex: 0
1109
+ })
1110
+ }
1111
+ )
1112
+ ]
1113
+ })
1114
+ ) }) }))
1115
+ }
1116
+ )
1117
+ }
1118
+ ),
1119
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1120
+ "div",
1121
+ {
1122
+ style: {
1123
+ background: "var(--puck-color-grey-10)",
1124
+ overflowY: "auto",
1125
+ gridArea: "right",
1126
+ fontFamily: "var(--puck-font-stack)"
1127
+ },
1128
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(FieldWrapper, { data, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1129
+ SidebarSection,
1130
+ {
1131
+ title: selectedIndex !== null ? data.content[selectedIndex].type : "Page",
1132
+ children: Object.keys(fields).map((fieldName) => {
1133
+ var _a2, _b2, _c, _d;
1134
+ const field = fields[fieldName];
1135
+ const onChange2 = (value) => {
1136
+ let currentProps;
1137
+ let newProps;
1138
+ if (selectedIndex !== null) {
1139
+ currentProps = data.content[selectedIndex].props;
1140
+ } else {
1141
+ currentProps = data.page;
1142
+ }
1143
+ if (fieldName === "_data") {
1144
+ if (!value) {
1145
+ const _a3 = currentProps._meta || {}, { locked } = _a3, _meta = __objRest(_a3, ["locked"]);
1146
+ newProps = __spreadProps(__spreadValues({}, currentProps), {
1147
+ _data: void 0,
1148
+ _meta
1149
+ });
1150
+ } else {
1151
+ const changedFields = filter(
1152
+ // filter out anything not supported by this component
1153
+ value.attributes,
1154
+ // TODO type properly after getting proper state library
1155
+ Object.keys(fields)
1156
+ );
1157
+ newProps = __spreadProps(__spreadValues(__spreadValues({}, currentProps), changedFields), {
1158
+ _data: value,
1159
+ // TODO perf - this is duplicative and will make payload larger
1160
+ _meta: {
1161
+ locked: Object.keys(changedFields)
1162
+ }
1163
+ });
1164
+ }
1165
+ } else {
1166
+ newProps = __spreadProps(__spreadValues({}, currentProps), {
1167
+ [fieldName]: value
1168
+ });
1169
+ }
1170
+ if (selectedIndex !== null) {
1171
+ setData(__spreadProps(__spreadValues({}, data), {
1172
+ content: replace(data.content, selectedIndex, __spreadProps(__spreadValues({}, data.content[selectedIndex]), {
1173
+ props: newProps
1174
+ }))
1175
+ }));
1176
+ } else {
1177
+ setData(__spreadProps(__spreadValues({}, data), { page: newProps }));
1178
+ }
1179
+ };
1180
+ if (selectedIndex !== null) {
1181
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1182
+ InputOrGroup,
1183
+ {
1184
+ field,
1185
+ name: fieldName,
1186
+ label: field.label,
1187
+ readOnly: ((_b2 = (_a2 = data.content[selectedIndex].props._meta) == null ? void 0 : _a2.locked) == null ? void 0 : _b2.indexOf(fieldName)) > -1,
1188
+ value: data.content[selectedIndex].props[fieldName],
1189
+ onChange: onChange2
1190
+ },
1191
+ `${data.content[selectedIndex].props.id}_${fieldName}`
1192
+ );
1193
+ } else {
1194
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1195
+ InputOrGroup,
1196
+ {
1197
+ field,
1198
+ name: fieldName,
1199
+ label: field.label,
1200
+ readOnly: ((_d = (_c = data.page._meta) == null ? void 0 : _c.locked) == null ? void 0 : _d.indexOf(fieldName)) > -1,
1201
+ value: data.page[fieldName],
1202
+ onChange: onChange2
1203
+ },
1204
+ `page_${fieldName}`
1205
+ );
1206
+ }
1207
+ })
1208
+ }
1209
+ ) })
1210
+ }
1211
+ )
1212
+ ]
1213
+ }
1214
+ )
1215
+ }
1216
+ ) });
1217
+ }
1218
+
1219
+ // components/Render/index.tsx
1220
+ init_react_import();
1221
+ var import_jsx_runtime11 = require("react/jsx-runtime");
1222
+ function Render({ config, data }) {
1223
+ const children = data.content.map((item) => {
1224
+ const Component = config.components[item.type].render;
1225
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Component, __spreadValues({}, item.props), item.props.id);
1226
+ });
1227
+ if (config.page) {
1228
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(config.page.render, __spreadProps(__spreadValues({}, data.page), { editMode: false, children }));
1229
+ }
1230
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { children });
1231
+ }
1232
+ // Annotate the CommonJS export names for ESM import in node:
1233
+ 0 && (module.exports = {
1234
+ Puck,
1235
+ Render
1236
+ });
1237
+ /*! Bundled license information:
1238
+
1239
+ classnames/index.js:
1240
+ (*!
1241
+ Copyright (c) 2018 Jed Watson.
1242
+ Licensed under the MIT License (MIT), see
1243
+ http://jedwatson.github.io/classnames
1244
+ *)
1245
+ */