@uniformdev/canvas-react 19.69.0 → 19.71.1-alpha.103
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/PureUniformText-METroz2Q.d.mts +41 -0
- package/dist/PureUniformText-METroz2Q.d.ts +41 -0
- package/dist/core.d.mts +14 -39
- package/dist/core.d.ts +14 -39
- package/dist/core.js +41 -5
- package/dist/core.mjs +43 -3
- package/dist/index.d.mts +19 -6
- package/dist/index.d.ts +19 -6
- package/dist/index.esm.js +111 -72
- package/dist/index.js +165 -128
- package/dist/index.mjs +111 -72
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
"use strict";
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
@@ -45,7 +46,7 @@ __export(src_exports, {
|
|
|
45
46
|
convertComponentToProps: () => convertComponentToProps,
|
|
46
47
|
createComponentStore: () => createComponentStore,
|
|
47
48
|
createComponentStoreResolver: () => createComponentStoreResolver,
|
|
48
|
-
createUniformApiEnhancer: () =>
|
|
49
|
+
createUniformApiEnhancer: () => import_canvas4.createUniformApiEnhancer,
|
|
49
50
|
getParameterAttributes: () => getParameterAttributes,
|
|
50
51
|
registerUniformComponent: () => registerUniformComponent,
|
|
51
52
|
useCompositionEventEffect: () => useCompositionEventEffect,
|
|
@@ -127,9 +128,9 @@ registerUniformComponent({ type: "${componentType}", component: ${proposedFileNa
|
|
|
127
128
|
}
|
|
128
129
|
|
|
129
130
|
// src/components/UniformComponent.tsx
|
|
130
|
-
var
|
|
131
|
+
var import_canvas7 = require("@uniformdev/canvas");
|
|
131
132
|
var import_context_react2 = require("@uniformdev/context-react");
|
|
132
|
-
var
|
|
133
|
+
var import_react7 = __toESM(require("react"));
|
|
133
134
|
|
|
134
135
|
// src/helpers/convertComponentToProps.ts
|
|
135
136
|
function convertComponentToProps(component) {
|
|
@@ -187,8 +188,8 @@ var componentStoreResolver = createComponentStoreResolver({
|
|
|
187
188
|
});
|
|
188
189
|
|
|
189
190
|
// src/components/UniformSlot.tsx
|
|
190
|
-
var
|
|
191
|
-
var
|
|
191
|
+
var import_canvas6 = require("@uniformdev/canvas");
|
|
192
|
+
var import_react6 = __toESM(require("react"));
|
|
192
193
|
|
|
193
194
|
// src/defaultSystemComponentResolver.tsx
|
|
194
195
|
var import_canvas2 = require("@uniformdev/canvas");
|
|
@@ -229,34 +230,67 @@ var defaultSystemComponentResolver = {
|
|
|
229
230
|
};
|
|
230
231
|
|
|
231
232
|
// src/components/ContextualEditingComponentWrapper.tsx
|
|
232
|
-
var
|
|
233
|
-
var
|
|
233
|
+
var import_canvas5 = require("@uniformdev/canvas");
|
|
234
|
+
var import_react5 = __toESM(require("react"));
|
|
235
|
+
|
|
236
|
+
// src/components/PureContextualEditingComponentWrapper.tsx
|
|
237
|
+
var import_canvas3 = require("@uniformdev/canvas");
|
|
238
|
+
var import_react2 = __toESM(require("react"));
|
|
239
|
+
var PureContextualEditingComponentWrapper = ({
|
|
240
|
+
children,
|
|
241
|
+
isPlaceholder,
|
|
242
|
+
parentComponent,
|
|
243
|
+
component,
|
|
244
|
+
slotName,
|
|
245
|
+
indexInSlot,
|
|
246
|
+
slotChildrenCount,
|
|
247
|
+
isReadOnly
|
|
248
|
+
}) => {
|
|
249
|
+
var _a, _b, _c, _d;
|
|
250
|
+
return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, /* @__PURE__ */ import_react2.default.createElement(
|
|
251
|
+
"script",
|
|
252
|
+
{
|
|
253
|
+
"data-role": import_canvas3.IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
|
254
|
+
"data-parent-id": parentComponent == null ? void 0 : parentComponent._id,
|
|
255
|
+
"data-parent-type": parentComponent == null ? void 0 : parentComponent.type,
|
|
256
|
+
"data-component-id": component == null ? void 0 : component._id,
|
|
257
|
+
"data-slot-name": slotName != null ? slotName : "",
|
|
258
|
+
"data-component-index": indexInSlot != null ? indexInSlot : "",
|
|
259
|
+
"data-total-components": slotChildrenCount != null ? slotChildrenCount : "",
|
|
260
|
+
"data-component-name": component == null ? void 0 : component.type,
|
|
261
|
+
"data-is-placeholder": isPlaceholder ? "true" : void 0,
|
|
262
|
+
"data-is-localized": ((_a = component == null ? void 0 : component.parameters) == null ? void 0 : _a[import_canvas3.CANVAS_LOCALE_TAG_PARAM]) ? "true" : void 0,
|
|
263
|
+
"data-component-title": (_d = (_c = (_b = component == null ? void 0 : component.parameters) == null ? void 0 : _b.title) == null ? void 0 : _c.value) != null ? _d : "",
|
|
264
|
+
"data-is-readonly": isReadOnly
|
|
265
|
+
}
|
|
266
|
+
), children, /* @__PURE__ */ import_react2.default.createElement("script", { "data-role": import_canvas3.IN_CONTEXT_EDITOR_COMPONENT_END_ROLE }));
|
|
267
|
+
};
|
|
234
268
|
|
|
235
269
|
// src/components/UniformComposition.tsx
|
|
236
|
-
var
|
|
270
|
+
var import_react4 = __toESM(require("react"));
|
|
237
271
|
|
|
238
272
|
// src/hooks/useUniformContextualEditing.ts
|
|
239
|
-
var
|
|
240
|
-
var
|
|
273
|
+
var import_canvas4 = require("@uniformdev/canvas");
|
|
274
|
+
var import_react3 = require("react");
|
|
241
275
|
var registeredCompositionIds = /* @__PURE__ */ new Set();
|
|
242
276
|
var useUniformContextualEditing = ({
|
|
243
277
|
initialCompositionValue,
|
|
244
278
|
enhance = (message) => message.composition
|
|
245
279
|
}) => {
|
|
246
|
-
const [contextualComposition, setContextualComposition] = (0,
|
|
247
|
-
const channel = (0,
|
|
280
|
+
const [contextualComposition, setContextualComposition] = (0, import_react3.useState)();
|
|
281
|
+
const channel = (0, import_react3.useMemo)(() => {
|
|
248
282
|
var _a;
|
|
249
283
|
if (!isInContextEditingMode()) {
|
|
250
284
|
return;
|
|
251
285
|
}
|
|
252
|
-
const channel2 = (0,
|
|
286
|
+
const channel2 = (0, import_canvas4.createCanvasChannel)({
|
|
253
287
|
broadcastTo: [(_a = window.opener) != null ? _a : window.top],
|
|
254
288
|
listenTo: [window]
|
|
255
289
|
});
|
|
256
290
|
return channel2;
|
|
257
291
|
}, []);
|
|
258
|
-
(0,
|
|
259
|
-
if ((contextualComposition == null ? void 0 : contextualComposition._id) && (initialCompositionValue == null ? void 0 : initialCompositionValue._id) !==
|
|
292
|
+
(0, import_react3.useEffect)(() => {
|
|
293
|
+
if ((contextualComposition == null ? void 0 : contextualComposition._id) && (initialCompositionValue == null ? void 0 : initialCompositionValue._id) !== import_canvas4.EMPTY_COMPOSITION._id && (initialCompositionValue == null ? void 0 : initialCompositionValue._id) !== (contextualComposition == null ? void 0 : contextualComposition._id)) {
|
|
260
294
|
setContextualComposition(void 0);
|
|
261
295
|
return;
|
|
262
296
|
}
|
|
@@ -264,7 +298,7 @@ var useUniformContextualEditing = ({
|
|
|
264
298
|
return;
|
|
265
299
|
}
|
|
266
300
|
const unsubscribeFromCompositionUpdates = channel.on("update-composition-internal", async (message) => {
|
|
267
|
-
if (!(0,
|
|
301
|
+
if (!(0, import_canvas4.isUpdateCompositionInternalMessage)(message)) {
|
|
268
302
|
return;
|
|
269
303
|
}
|
|
270
304
|
const enhancedComposition = await enhance(message);
|
|
@@ -276,11 +310,11 @@ var useUniformContextualEditing = ({
|
|
|
276
310
|
registeredCompositionIds.delete(initialCompositionValue == null ? void 0 : initialCompositionValue._id);
|
|
277
311
|
};
|
|
278
312
|
}, [channel, enhance, initialCompositionValue == null ? void 0 : initialCompositionValue._id, contextualComposition == null ? void 0 : contextualComposition._id]);
|
|
279
|
-
(0,
|
|
313
|
+
(0, import_react3.useEffect)(() => {
|
|
280
314
|
if (!isInContextEditingMode()) {
|
|
281
315
|
return;
|
|
282
316
|
}
|
|
283
|
-
const existingScript = document.getElementById(
|
|
317
|
+
const existingScript = document.getElementById(import_canvas4.IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID);
|
|
284
318
|
if (existingScript) {
|
|
285
319
|
return;
|
|
286
320
|
}
|
|
@@ -290,13 +324,13 @@ var useUniformContextualEditing = ({
|
|
|
290
324
|
version: 2
|
|
291
325
|
};
|
|
292
326
|
const script = document.createElement("script");
|
|
293
|
-
script.id =
|
|
327
|
+
script.id = import_canvas4.IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID;
|
|
294
328
|
script.src = getCanvasInContextEmbedScriptUrl();
|
|
295
329
|
script.async = true;
|
|
296
330
|
document.head.appendChild(script);
|
|
297
331
|
}, [initialCompositionValue == null ? void 0 : initialCompositionValue._id]);
|
|
298
332
|
return {
|
|
299
|
-
composition: contextualComposition
|
|
333
|
+
composition: contextualComposition ? contextualComposition : initialCompositionValue,
|
|
300
334
|
isContextualEditing: Boolean(contextualComposition)
|
|
301
335
|
};
|
|
302
336
|
};
|
|
@@ -309,18 +343,18 @@ function isInContextEditingMode() {
|
|
|
309
343
|
return false;
|
|
310
344
|
}
|
|
311
345
|
const isOpenedByInContextEditor = new URLSearchParams(window.location.search).has(
|
|
312
|
-
|
|
346
|
+
import_canvas4.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM
|
|
313
347
|
);
|
|
314
|
-
return isOpenedByInContextEditor && (0,
|
|
348
|
+
return isOpenedByInContextEditor && (0, import_canvas4.isAllowedReferrer)(window.document.referrer);
|
|
315
349
|
}
|
|
316
350
|
|
|
317
351
|
// src/components/UniformComposition.tsx
|
|
318
|
-
var UniformCompositionContext = (0,
|
|
352
|
+
var UniformCompositionContext = (0, import_react4.createContext)({
|
|
319
353
|
data: void 0,
|
|
320
354
|
isContextualEditing: false
|
|
321
355
|
});
|
|
322
356
|
function useUniformCurrentComposition() {
|
|
323
|
-
return (0,
|
|
357
|
+
return (0, import_react4.useContext)(UniformCompositionContext);
|
|
324
358
|
}
|
|
325
359
|
function UniformComposition({
|
|
326
360
|
data,
|
|
@@ -334,12 +368,12 @@ function UniformComposition({
|
|
|
334
368
|
initialCompositionValue: data,
|
|
335
369
|
enhance: contextualEditingEnhancer
|
|
336
370
|
});
|
|
337
|
-
return /* @__PURE__ */
|
|
371
|
+
return /* @__PURE__ */ import_react4.default.createElement(
|
|
338
372
|
UniformCompositionContext.Provider,
|
|
339
373
|
{
|
|
340
374
|
value: { data: composition, behaviorTracking, resolveRenderer, isContextualEditing }
|
|
341
375
|
},
|
|
342
|
-
/* @__PURE__ */
|
|
376
|
+
/* @__PURE__ */ import_react4.default.createElement(ContextualEditingComponentWrapper, { component: composition }, /* @__PURE__ */ import_react4.default.createElement(
|
|
343
377
|
UniformComponent,
|
|
344
378
|
{
|
|
345
379
|
data: composition,
|
|
@@ -362,27 +396,30 @@ function ContextualEditingComponentWrapper({
|
|
|
362
396
|
emptyPlaceholder,
|
|
363
397
|
children
|
|
364
398
|
}) {
|
|
365
|
-
var _a
|
|
366
|
-
const isPlaceholder = (0,
|
|
399
|
+
var _a;
|
|
400
|
+
const isPlaceholder = (0, import_canvas5.isComponentPlaceholderId)(component == null ? void 0 : component._id);
|
|
367
401
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
368
402
|
const isReadOnly = ((_a = component == null ? void 0 : component._contextualEditing) == null ? void 0 : _a.isEditable) ? void 0 : "true";
|
|
369
|
-
|
|
370
|
-
|
|
403
|
+
if (!isContextualEditing) {
|
|
404
|
+
return /* @__PURE__ */ import_react5.default.createElement(import_react5.default.Fragment, null, children);
|
|
405
|
+
}
|
|
406
|
+
if (isPlaceholder && emptyPlaceholder === null) {
|
|
407
|
+
return null;
|
|
408
|
+
}
|
|
409
|
+
return /* @__PURE__ */ import_react5.default.createElement(
|
|
410
|
+
PureContextualEditingComponentWrapper,
|
|
371
411
|
{
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
"data-is-readonly": isReadOnly
|
|
384
|
-
}
|
|
385
|
-
), isPlaceholder && emptyPlaceholder !== void 0 ? emptyPlaceholder : children, /* @__PURE__ */ import_react4.default.createElement("script", { "data-role": import_canvas4.IN_CONTEXT_EDITOR_COMPONENT_END_ROLE }));
|
|
412
|
+
isPlaceholder,
|
|
413
|
+
parentComponent,
|
|
414
|
+
component,
|
|
415
|
+
slotName,
|
|
416
|
+
indexInSlot,
|
|
417
|
+
slotChildrenCount,
|
|
418
|
+
isReadOnly
|
|
419
|
+
},
|
|
420
|
+
isContextualEditing && /* @__PURE__ */ import_react5.default.createElement(import_react5.default.Fragment, null),
|
|
421
|
+
isPlaceholder && emptyPlaceholder !== void 0 ? emptyPlaceholder : children
|
|
422
|
+
);
|
|
386
423
|
}
|
|
387
424
|
|
|
388
425
|
// src/components/UniformSlot.tsx
|
|
@@ -400,7 +437,7 @@ function UniformSlot({
|
|
|
400
437
|
}
|
|
401
438
|
const slot = (_a = parentData.slots) == null ? void 0 : _a[name];
|
|
402
439
|
if (!slot || !Array.isArray(slot)) {
|
|
403
|
-
if (process.env.NODE_ENV === "development" && parentData.type !==
|
|
440
|
+
if (process.env.NODE_ENV === "development" && parentData.type !== import_canvas6.EMPTY_COMPOSITION.type) {
|
|
404
441
|
console.warn(
|
|
405
442
|
`[canvas-dev] slot '${name}' was rendered, but it was not defined on its component. This is expected if the slot is optional, otherwise it may indicate a typo. Component:`,
|
|
406
443
|
parentData
|
|
@@ -421,13 +458,13 @@ function UniformSlot({
|
|
|
421
458
|
emptyPlaceholder
|
|
422
459
|
});
|
|
423
460
|
const elements = children ? children({ child, component, key: `wrapped-inner-${index}` }) : child;
|
|
424
|
-
return
|
|
461
|
+
return import_react6.default.createElement(import_react6.default.Fragment, { key: index }, elements);
|
|
425
462
|
});
|
|
426
463
|
if (!wrapperComponent) {
|
|
427
|
-
return
|
|
464
|
+
return import_react6.default.createElement(import_react6.default.Fragment, void 0, finalChildren);
|
|
428
465
|
}
|
|
429
466
|
const Wrapper = wrapperComponent;
|
|
430
|
-
return /* @__PURE__ */
|
|
467
|
+
return /* @__PURE__ */ import_react6.default.createElement(Wrapper, { items: finalChildren, slotName: name });
|
|
431
468
|
}
|
|
432
469
|
function renderComponent({
|
|
433
470
|
component,
|
|
@@ -440,7 +477,7 @@ function renderComponent({
|
|
|
440
477
|
emptyPlaceholder
|
|
441
478
|
}) {
|
|
442
479
|
const RenderComponent = resolveRenderer == null ? void 0 : resolveRenderer(component);
|
|
443
|
-
if (component.type ===
|
|
480
|
+
if (component.type === import_canvas6.CANVAS_TEST_TYPE) {
|
|
444
481
|
const testComponent = defaultSystemComponentResolver.test(
|
|
445
482
|
component,
|
|
446
483
|
key,
|
|
@@ -451,15 +488,15 @@ function renderComponent({
|
|
|
451
488
|
resolveRenderer,
|
|
452
489
|
key: key2,
|
|
453
490
|
parentComponent: component,
|
|
454
|
-
slotName:
|
|
455
|
-
slotChildrenCount: (_a = component == null ? void 0 : component.slots) == null ? void 0 : _a[
|
|
456
|
-
indexInSlot: (_b = component == null ? void 0 : component.slots) == null ? void 0 : _b[
|
|
491
|
+
slotName: import_canvas6.CANVAS_TEST_SLOT,
|
|
492
|
+
slotChildrenCount: (_a = component == null ? void 0 : component.slots) == null ? void 0 : _a[import_canvas6.CANVAS_TEST_SLOT].length,
|
|
493
|
+
indexInSlot: (_b = component == null ? void 0 : component.slots) == null ? void 0 : _b[import_canvas6.CANVAS_TEST_SLOT].findIndex(
|
|
457
494
|
({ _id }) => variantComponent._id === _id
|
|
458
495
|
)
|
|
459
496
|
});
|
|
460
497
|
}
|
|
461
498
|
);
|
|
462
|
-
return /* @__PURE__ */
|
|
499
|
+
return /* @__PURE__ */ import_react6.default.createElement(
|
|
463
500
|
ContextualEditingComponentWrapper,
|
|
464
501
|
{
|
|
465
502
|
component,
|
|
@@ -471,7 +508,7 @@ function renderComponent({
|
|
|
471
508
|
},
|
|
472
509
|
testComponent
|
|
473
510
|
);
|
|
474
|
-
} else if (component.type ===
|
|
511
|
+
} else if (component.type === import_canvas6.CANVAS_PERSONALIZE_TYPE) {
|
|
475
512
|
const personalizationComponent = defaultSystemComponentResolver.personalization(
|
|
476
513
|
component,
|
|
477
514
|
key,
|
|
@@ -482,15 +519,15 @@ function renderComponent({
|
|
|
482
519
|
resolveRenderer,
|
|
483
520
|
key: key2,
|
|
484
521
|
parentComponent: component,
|
|
485
|
-
slotName:
|
|
486
|
-
slotChildrenCount: (_a = component == null ? void 0 : component.slots) == null ? void 0 : _a[
|
|
487
|
-
indexInSlot: (_b = component == null ? void 0 : component.slots) == null ? void 0 : _b[
|
|
522
|
+
slotName: import_canvas6.CANVAS_PERSONALIZE_SLOT,
|
|
523
|
+
slotChildrenCount: (_a = component == null ? void 0 : component.slots) == null ? void 0 : _a[import_canvas6.CANVAS_PERSONALIZE_SLOT].length,
|
|
524
|
+
indexInSlot: (_b = component == null ? void 0 : component.slots) == null ? void 0 : _b[import_canvas6.CANVAS_PERSONALIZE_SLOT].findIndex(
|
|
488
525
|
({ _id }) => variantComponent._id === _id
|
|
489
526
|
)
|
|
490
527
|
});
|
|
491
528
|
}
|
|
492
529
|
);
|
|
493
|
-
return /* @__PURE__ */
|
|
530
|
+
return /* @__PURE__ */ import_react6.default.createElement(
|
|
494
531
|
ContextualEditingComponentWrapper,
|
|
495
532
|
{
|
|
496
533
|
component,
|
|
@@ -504,7 +541,7 @@ function renderComponent({
|
|
|
504
541
|
);
|
|
505
542
|
} else if (RenderComponent) {
|
|
506
543
|
const props = convertComponentToProps(component);
|
|
507
|
-
return /* @__PURE__ */
|
|
544
|
+
return /* @__PURE__ */ import_react6.default.createElement(UniformComponent, { key, data: component, resolveRenderer }, /* @__PURE__ */ import_react6.default.createElement(
|
|
508
545
|
ContextualEditingComponentWrapper,
|
|
509
546
|
{
|
|
510
547
|
component,
|
|
@@ -514,7 +551,7 @@ function renderComponent({
|
|
|
514
551
|
slotChildrenCount,
|
|
515
552
|
emptyPlaceholder
|
|
516
553
|
},
|
|
517
|
-
/* @__PURE__ */
|
|
554
|
+
/* @__PURE__ */ import_react6.default.createElement(RenderComponent, { ...props })
|
|
518
555
|
));
|
|
519
556
|
} else if (process.env.NODE_ENV !== "production") {
|
|
520
557
|
console.warn(
|
|
@@ -527,9 +564,9 @@ function renderComponent({
|
|
|
527
564
|
}
|
|
528
565
|
|
|
529
566
|
// src/components/UniformComponent.tsx
|
|
530
|
-
var UniformComponentContext = (0,
|
|
567
|
+
var UniformComponentContext = (0, import_react7.createContext)({});
|
|
531
568
|
function useUniformCurrentComponent() {
|
|
532
|
-
return (0,
|
|
569
|
+
return (0, import_react7.useContext)(UniformComponentContext);
|
|
533
570
|
}
|
|
534
571
|
function UniformComponent({
|
|
535
572
|
data,
|
|
@@ -553,7 +590,7 @@ function UniformComponent({
|
|
|
553
590
|
behaviorTracking: (_a = behaviorTracking != null ? behaviorTracking : parentData == null ? void 0 : parentData.behaviorTracking) != null ? _a : "onView",
|
|
554
591
|
contextualEditingDefaultPlaceholder: contextualEditingDefaultPlaceholder != null ? contextualEditingDefaultPlaceholder : parentData.contextualEditingDefaultPlaceholder
|
|
555
592
|
};
|
|
556
|
-
const enrichmentTags = (_c = (_b = data.parameters) == null ? void 0 : _b[
|
|
593
|
+
const enrichmentTags = (_c = (_b = data.parameters) == null ? void 0 : _b[import_canvas7.CANVAS_ENRICHMENT_TAG_PARAM]) == null ? void 0 : _c.value;
|
|
557
594
|
const TrackComponent = contextValue.behaviorTracking === "onLoad" ? import_context_react2.TrackFragment : import_context_react2.Track;
|
|
558
595
|
const resolvedChildren = resolveChildren({
|
|
559
596
|
children,
|
|
@@ -561,9 +598,9 @@ function UniformComponent({
|
|
|
561
598
|
hasParentLayout: Boolean(parentData.data),
|
|
562
599
|
resolveRenderer: contextValue.resolveRenderer
|
|
563
600
|
});
|
|
564
|
-
return /* @__PURE__ */
|
|
601
|
+
return /* @__PURE__ */ import_react7.default.createElement(UniformComponentContext.Provider, { value: contextValue }, contextContextProviderPresent ? (
|
|
565
602
|
/* auto-track behavior signals when in a Canvas context */
|
|
566
|
-
/* @__PURE__ */
|
|
603
|
+
/* @__PURE__ */ import_react7.default.createElement(TrackComponent, { behavior: enrichmentTags }, resolvedChildren)
|
|
567
604
|
) : resolvedChildren);
|
|
568
605
|
}
|
|
569
606
|
function resolveChildren({
|
|
@@ -576,14 +613,14 @@ function resolveChildren({
|
|
|
576
613
|
if (!children && !hasParentLayout) {
|
|
577
614
|
const topLevelComponent = resolveRenderer({ type: data.type });
|
|
578
615
|
if (topLevelComponent) {
|
|
579
|
-
children =
|
|
616
|
+
children = import_react7.default.createElement(topLevelComponent, convertComponentToProps(data));
|
|
580
617
|
} else {
|
|
581
618
|
if (Object.keys((_a = data.slots) != null ? _a : {}).length > 1 && process.env.NODE_ENV === "development") {
|
|
582
619
|
console.warn(
|
|
583
620
|
`[canvas-dev] All the slots in component '${data.type}' are rendered in no particular order. Use '<UniformSlot name={slotName} />' to reliably render the slots.`
|
|
584
621
|
);
|
|
585
622
|
}
|
|
586
|
-
children = Object.keys(data.slots || {}).map((slotName) => /* @__PURE__ */
|
|
623
|
+
children = Object.keys(data.slots || {}).map((slotName) => /* @__PURE__ */ import_react7.default.createElement(UniformSlot, { key: slotName, name: slotName }));
|
|
587
624
|
}
|
|
588
625
|
}
|
|
589
626
|
const renderChildren = typeof children === "function" ? children(convertComponentToProps(data)) : children;
|
|
@@ -591,8 +628,8 @@ function resolveChildren({
|
|
|
591
628
|
}
|
|
592
629
|
|
|
593
630
|
// src/components/UniformPlayground.tsx
|
|
594
|
-
var
|
|
595
|
-
var
|
|
631
|
+
var import_canvas8 = require("@uniformdev/canvas");
|
|
632
|
+
var import_react8 = __toESM(require("react"));
|
|
596
633
|
var UniformPlayground = ({
|
|
597
634
|
resolveRenderer,
|
|
598
635
|
decorators = [],
|
|
@@ -602,14 +639,14 @@ var UniformPlayground = ({
|
|
|
602
639
|
children
|
|
603
640
|
}) => {
|
|
604
641
|
const { composition, isContextualEditing } = useUniformContextualEditing({
|
|
605
|
-
initialCompositionValue:
|
|
642
|
+
initialCompositionValue: import_canvas8.EMPTY_COMPOSITION,
|
|
606
643
|
enhance: contextualEditingEnhancer
|
|
607
644
|
});
|
|
608
|
-
const renderedComponent = (0,
|
|
645
|
+
const renderedComponent = (0, import_react8.useMemo)(() => {
|
|
609
646
|
if (!composition) {
|
|
610
647
|
return null;
|
|
611
648
|
}
|
|
612
|
-
let component = /* @__PURE__ */
|
|
649
|
+
let component = /* @__PURE__ */ import_react8.default.createElement(ContextualEditingComponentWrapper, { component: composition }, /* @__PURE__ */ import_react8.default.createElement(
|
|
613
650
|
UniformComponent,
|
|
614
651
|
{
|
|
615
652
|
data: composition,
|
|
@@ -620,7 +657,7 @@ var UniformPlayground = ({
|
|
|
620
657
|
children
|
|
621
658
|
));
|
|
622
659
|
decorators.forEach((Decorator) => {
|
|
623
|
-
component = /* @__PURE__ */
|
|
660
|
+
component = /* @__PURE__ */ import_react8.default.createElement(Decorator, { data: composition }, component);
|
|
624
661
|
});
|
|
625
662
|
return component;
|
|
626
663
|
}, [
|
|
@@ -631,7 +668,7 @@ var UniformPlayground = ({
|
|
|
631
668
|
behaviorTracking,
|
|
632
669
|
contextualEditingDefaultPlaceholder
|
|
633
670
|
]);
|
|
634
|
-
return /* @__PURE__ */
|
|
671
|
+
return /* @__PURE__ */ import_react8.default.createElement(
|
|
635
672
|
UniformCompositionContext.Provider,
|
|
636
673
|
{
|
|
637
674
|
value: { data: composition, behaviorTracking, resolveRenderer, isContextualEditing }
|
|
@@ -641,57 +678,57 @@ var UniformPlayground = ({
|
|
|
641
678
|
};
|
|
642
679
|
|
|
643
680
|
// src/components/UniformRichText/UniformRichText.tsx
|
|
644
|
-
var
|
|
681
|
+
var import_canvas9 = require("@uniformdev/canvas");
|
|
645
682
|
var import_richtext5 = require("@uniformdev/richtext");
|
|
646
|
-
var
|
|
683
|
+
var import_react18 = __toESM(require("react"));
|
|
647
684
|
|
|
648
685
|
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
649
686
|
var import_richtext4 = require("@uniformdev/richtext");
|
|
650
|
-
var
|
|
687
|
+
var import_react17 = __toESM(require("react"));
|
|
651
688
|
|
|
652
689
|
// src/components/UniformRichText/nodes/HeadingRichTextNode.tsx
|
|
653
|
-
var
|
|
690
|
+
var import_react9 = __toESM(require("react"));
|
|
654
691
|
var HeadingRichTextNode = ({ children, node }) => {
|
|
655
692
|
const { tag } = node;
|
|
656
693
|
const HTag = tag != null ? tag : "h1";
|
|
657
|
-
return /* @__PURE__ */
|
|
694
|
+
return /* @__PURE__ */ import_react9.default.createElement(HTag, null, children);
|
|
658
695
|
};
|
|
659
696
|
|
|
660
697
|
// src/components/UniformRichText/nodes/LinebreakRichTextNode.tsx
|
|
661
|
-
var
|
|
698
|
+
var import_react10 = __toESM(require("react"));
|
|
662
699
|
var LinebreakRichTextNode = () => {
|
|
663
|
-
return /* @__PURE__ */
|
|
700
|
+
return /* @__PURE__ */ import_react10.default.createElement("br", null);
|
|
664
701
|
};
|
|
665
702
|
|
|
666
703
|
// src/components/UniformRichText/nodes/LinkRichTextNode.tsx
|
|
667
704
|
var import_richtext = require("@uniformdev/richtext");
|
|
668
|
-
var
|
|
705
|
+
var import_react11 = __toESM(require("react"));
|
|
669
706
|
var LinkRichTextNode = ({ children, node }) => {
|
|
670
707
|
const { link } = node;
|
|
671
|
-
return /* @__PURE__ */
|
|
708
|
+
return /* @__PURE__ */ import_react11.default.createElement("a", { href: (0, import_richtext.linkParamValueToHref)(link) }, children);
|
|
672
709
|
};
|
|
673
710
|
|
|
674
711
|
// src/components/UniformRichText/nodes/ListItemRichTextNode.tsx
|
|
675
|
-
var
|
|
712
|
+
var import_react12 = __toESM(require("react"));
|
|
676
713
|
var ListItemRichTextNode = ({ children, node }) => {
|
|
677
714
|
const { value } = node;
|
|
678
|
-
return /* @__PURE__ */
|
|
715
|
+
return /* @__PURE__ */ import_react12.default.createElement("li", { value: Number.isFinite(value) && value > 0 ? value : void 0 }, children);
|
|
679
716
|
};
|
|
680
717
|
|
|
681
718
|
// src/components/UniformRichText/nodes/ListRichTextNode.tsx
|
|
682
|
-
var
|
|
719
|
+
var import_react13 = __toESM(require("react"));
|
|
683
720
|
var ListRichTextNode = ({ children, node }) => {
|
|
684
721
|
const { tag, start } = node;
|
|
685
722
|
const ListTag = tag != null ? tag : "ul";
|
|
686
|
-
return /* @__PURE__ */
|
|
723
|
+
return /* @__PURE__ */ import_react13.default.createElement(ListTag, { start: Number.isFinite(start) && start > 0 ? start : void 0 }, children);
|
|
687
724
|
};
|
|
688
725
|
|
|
689
726
|
// src/components/UniformRichText/nodes/ParagraphRichTextNode.tsx
|
|
690
727
|
var import_richtext2 = require("@uniformdev/richtext");
|
|
691
|
-
var
|
|
728
|
+
var import_react14 = __toESM(require("react"));
|
|
692
729
|
var ParagraphRichTextNode = ({ children, node }) => {
|
|
693
730
|
const { format, direction } = node;
|
|
694
|
-
return /* @__PURE__ */
|
|
731
|
+
return /* @__PURE__ */ import_react14.default.createElement(
|
|
695
732
|
"p",
|
|
696
733
|
{
|
|
697
734
|
dir: (0, import_richtext2.isPureDirection)(direction) ? direction : void 0,
|
|
@@ -702,18 +739,18 @@ var ParagraphRichTextNode = ({ children, node }) => {
|
|
|
702
739
|
};
|
|
703
740
|
|
|
704
741
|
// src/components/UniformRichText/nodes/TabRichTextNode.tsx
|
|
705
|
-
var
|
|
742
|
+
var import_react15 = __toESM(require("react"));
|
|
706
743
|
var TabRichTextNode = () => {
|
|
707
|
-
return /* @__PURE__ */
|
|
744
|
+
return /* @__PURE__ */ import_react15.default.createElement(import_react15.default.Fragment, null, " ");
|
|
708
745
|
};
|
|
709
746
|
|
|
710
747
|
// src/components/UniformRichText/nodes/TextRichTextNode.tsx
|
|
711
748
|
var import_richtext3 = require("@uniformdev/richtext");
|
|
712
|
-
var
|
|
749
|
+
var import_react16 = __toESM(require("react"));
|
|
713
750
|
var TextRichTextNode = ({ node }) => {
|
|
714
751
|
const { text, format } = node;
|
|
715
752
|
const tags = (0, import_richtext3.getRichTextTagsFromTextFormat)(format);
|
|
716
|
-
return /* @__PURE__ */
|
|
753
|
+
return /* @__PURE__ */ import_react16.default.createElement(import_react16.default.Fragment, null, tags.length > 0 ? tags.reduceRight((children, Tag) => /* @__PURE__ */ import_react16.default.createElement(Tag, null, children), text) : text);
|
|
717
754
|
};
|
|
718
755
|
|
|
719
756
|
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
@@ -728,8 +765,8 @@ function UniformRichTextNode({ node, ...props }) {
|
|
|
728
765
|
if (!NodeRenderer) {
|
|
729
766
|
return null;
|
|
730
767
|
}
|
|
731
|
-
const children = node.children ? node.children.map((childNode, i) => /* @__PURE__ */
|
|
732
|
-
return /* @__PURE__ */
|
|
768
|
+
const children = node.children ? node.children.map((childNode, i) => /* @__PURE__ */ import_react17.default.createElement(UniformRichTextNode, { ...props, key: i, node: childNode })) : null;
|
|
769
|
+
return /* @__PURE__ */ import_react17.default.createElement(NodeRenderer, { node }, children);
|
|
733
770
|
}
|
|
734
771
|
var rendererMap = /* @__PURE__ */ new Map([
|
|
735
772
|
["heading", HeadingRichTextNode],
|
|
@@ -738,12 +775,12 @@ var rendererMap = /* @__PURE__ */ new Map([
|
|
|
738
775
|
["list", ListRichTextNode],
|
|
739
776
|
["listitem", ListItemRichTextNode],
|
|
740
777
|
["paragraph", ParagraphRichTextNode],
|
|
741
|
-
["quote", ({ children }) => /* @__PURE__ */
|
|
778
|
+
["quote", ({ children }) => /* @__PURE__ */ import_react17.default.createElement("blockquote", null, children)],
|
|
742
779
|
[
|
|
743
780
|
"code",
|
|
744
|
-
({ children }) => /* @__PURE__ */
|
|
781
|
+
({ children }) => /* @__PURE__ */ import_react17.default.createElement("pre", null, /* @__PURE__ */ import_react17.default.createElement("code", null, children))
|
|
745
782
|
],
|
|
746
|
-
["root", ({ children }) => /* @__PURE__ */
|
|
783
|
+
["root", ({ children }) => /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, children)],
|
|
747
784
|
["text", TextRichTextNode],
|
|
748
785
|
["tab", TabRichTextNode]
|
|
749
786
|
]);
|
|
@@ -752,35 +789,35 @@ var resolveRichTextDefaultRenderer = (node) => {
|
|
|
752
789
|
};
|
|
753
790
|
|
|
754
791
|
// src/components/UniformRichText/UniformRichText.tsx
|
|
755
|
-
var UniformRichText =
|
|
792
|
+
var UniformRichText = import_react18.default.forwardRef(function UniformRichText2({ parameterId, resolveRichTextRenderer, as: Tag = "div", ...props }, ref) {
|
|
756
793
|
const { data: componentData } = useUniformCurrentComponent();
|
|
757
|
-
const parameter = (0,
|
|
794
|
+
const parameter = (0, import_react18.useMemo)(() => {
|
|
758
795
|
var _a;
|
|
759
796
|
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
760
797
|
}, [componentData, parameterId]);
|
|
761
|
-
const value = (0,
|
|
798
|
+
const value = (0, import_react18.useMemo)(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
762
799
|
if (!value || !(0, import_richtext5.isRichTextValue)(value) || (0, import_richtext5.isRichTextValueConsideredEmpty)(value))
|
|
763
800
|
return null;
|
|
764
|
-
return Tag === null ? /* @__PURE__ */
|
|
801
|
+
return Tag === null ? /* @__PURE__ */ import_react18.default.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ import_react18.default.createElement(
|
|
765
802
|
Tag,
|
|
766
803
|
{
|
|
767
804
|
ref,
|
|
768
805
|
...props,
|
|
769
806
|
...{
|
|
770
|
-
[
|
|
771
|
-
[
|
|
772
|
-
[
|
|
807
|
+
[import_canvas9.ATTRIBUTE_COMPONENT_ID]: componentData == null ? void 0 : componentData._id,
|
|
808
|
+
[import_canvas9.ATTRIBUTE_PARAMETER_ID]: parameterId,
|
|
809
|
+
[import_canvas9.ATTRIBUTE_PARAMETER_TYPE]: "richText"
|
|
773
810
|
}
|
|
774
811
|
},
|
|
775
|
-
/* @__PURE__ */
|
|
812
|
+
/* @__PURE__ */ import_react18.default.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer })
|
|
776
813
|
);
|
|
777
814
|
});
|
|
778
815
|
|
|
779
816
|
// src/components/UniformText.tsx
|
|
780
|
-
var
|
|
817
|
+
var import_react20 = __toESM(require("react"));
|
|
781
818
|
|
|
782
819
|
// src/components/PureUniformText.tsx
|
|
783
|
-
var
|
|
820
|
+
var import_react19 = __toESM(require("react"));
|
|
784
821
|
var PureUniformText = ({
|
|
785
822
|
as: Tag = "span",
|
|
786
823
|
parameterId,
|
|
@@ -799,10 +836,10 @@ var PureUniformText = ({
|
|
|
799
836
|
return null;
|
|
800
837
|
}
|
|
801
838
|
if (!isContextualEditing) {
|
|
802
|
-
return /* @__PURE__ */
|
|
839
|
+
return /* @__PURE__ */ import_react19.default.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
803
840
|
}
|
|
804
841
|
const computedPlaceholder = typeof placeholder === "function" ? placeholder({ id: parameterId }) : placeholder;
|
|
805
|
-
return /* @__PURE__ */
|
|
842
|
+
return /* @__PURE__ */ import_react19.default.createElement(
|
|
806
843
|
Tag,
|
|
807
844
|
{
|
|
808
845
|
...props,
|
|
@@ -831,7 +868,7 @@ var UniformText = ({
|
|
|
831
868
|
var _a, _b, _c;
|
|
832
869
|
const { data: componentData, contextualEditingDefaultPlaceholder } = useUniformCurrentComponent();
|
|
833
870
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
834
|
-
const [isFocused, setIsFocused] = (0,
|
|
871
|
+
const [isFocused, setIsFocused] = (0, import_react20.useState)(false);
|
|
835
872
|
const parameter = (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
836
873
|
const isEditable = (_c = (_b = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _b.isEditable) != null ? _c : false;
|
|
837
874
|
const shouldSkipCustomRendering = isFocused && isEditable;
|
|
@@ -840,7 +877,7 @@ var UniformText = ({
|
|
|
840
877
|
}
|
|
841
878
|
const placeholderProp = placeholder != null ? placeholder : contextualEditingDefaultPlaceholder;
|
|
842
879
|
const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: parameterId }) : placeholderProp;
|
|
843
|
-
return /* @__PURE__ */
|
|
880
|
+
return /* @__PURE__ */ import_react20.default.createElement(
|
|
844
881
|
PureUniformText,
|
|
845
882
|
{
|
|
846
883
|
...props,
|
|
@@ -863,35 +900,35 @@ var UniformText = ({
|
|
|
863
900
|
};
|
|
864
901
|
|
|
865
902
|
// src/helpers/getParameterAttributes.ts
|
|
866
|
-
var
|
|
903
|
+
var import_canvas10 = require("@uniformdev/canvas");
|
|
867
904
|
var getParameterAttributes = (options) => {
|
|
868
905
|
return {
|
|
869
|
-
...(0,
|
|
906
|
+
...(0, import_canvas10.getParameterAttributes)(options),
|
|
870
907
|
suppressContentEditableWarning: true
|
|
871
908
|
};
|
|
872
909
|
};
|
|
873
910
|
|
|
874
911
|
// src/hooks/useCompositionEventEffect.ts
|
|
875
|
-
var
|
|
876
|
-
var
|
|
912
|
+
var import_canvas11 = require("@uniformdev/canvas");
|
|
913
|
+
var import_react21 = require("react");
|
|
877
914
|
function useCompositionEventEffect({
|
|
878
915
|
enabled,
|
|
879
916
|
projectId,
|
|
880
917
|
compositionId,
|
|
881
918
|
effect
|
|
882
919
|
}) {
|
|
883
|
-
(0,
|
|
920
|
+
(0, import_react21.useEffect)(() => {
|
|
884
921
|
if (!enabled || !compositionId || !projectId) {
|
|
885
922
|
return;
|
|
886
923
|
}
|
|
887
924
|
let goodbye = void 0;
|
|
888
925
|
const loadEffect = async () => {
|
|
889
|
-
const eventBus = await (0,
|
|
926
|
+
const eventBus = await (0, import_canvas11.createEventBus)();
|
|
890
927
|
if (eventBus) {
|
|
891
|
-
goodbye = (0,
|
|
928
|
+
goodbye = (0, import_canvas11.subscribeToComposition)({
|
|
892
929
|
eventBus,
|
|
893
930
|
compositionId,
|
|
894
|
-
compositionState:
|
|
931
|
+
compositionState: import_canvas11.CANVAS_DRAFT_STATE,
|
|
895
932
|
projectId,
|
|
896
933
|
callback: effect,
|
|
897
934
|
event: "updated"
|
|
@@ -908,31 +945,31 @@ function useCompositionEventEffect({
|
|
|
908
945
|
}
|
|
909
946
|
|
|
910
947
|
// src/hooks/useUniformContextualEditingState.ts
|
|
911
|
-
var
|
|
912
|
-
var
|
|
948
|
+
var import_canvas12 = require("@uniformdev/canvas");
|
|
949
|
+
var import_react22 = require("react");
|
|
913
950
|
var useUniformContextualEditingState = ({
|
|
914
951
|
global = false
|
|
915
952
|
} = {}) => {
|
|
916
953
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
917
954
|
const { data: componentData } = useUniformCurrentComponent();
|
|
918
|
-
const [selectedComponentReference, setSelectedComponentReference] = (0,
|
|
919
|
-
const channel = (0,
|
|
955
|
+
const [selectedComponentReference, setSelectedComponentReference] = (0, import_react22.useState)();
|
|
956
|
+
const channel = (0, import_react22.useMemo)(() => {
|
|
920
957
|
if (!isContextualEditing) {
|
|
921
958
|
return;
|
|
922
959
|
}
|
|
923
|
-
const channel2 = (0,
|
|
960
|
+
const channel2 = (0, import_canvas12.createCanvasChannel)({
|
|
924
961
|
broadcastTo: [window],
|
|
925
962
|
listenTo: [window]
|
|
926
963
|
});
|
|
927
964
|
return channel2;
|
|
928
965
|
}, [isContextualEditing]);
|
|
929
|
-
(0,
|
|
966
|
+
(0, import_react22.useEffect)(() => {
|
|
930
967
|
if (!channel) {
|
|
931
968
|
return;
|
|
932
969
|
}
|
|
933
970
|
const unsubscribe = channel.on("update-contextual-editing-state-internal", async (message) => {
|
|
934
971
|
var _a;
|
|
935
|
-
if (!(0,
|
|
972
|
+
if (!(0, import_canvas12.isUpdateContextualEditingStateInternalMessage)(message)) {
|
|
936
973
|
return;
|
|
937
974
|
}
|
|
938
975
|
if (!global && (componentData == null ? void 0 : componentData._id) !== ((_a = message.state.selectedComponentReference) == null ? void 0 : _a.parentId)) {
|
|
@@ -945,7 +982,7 @@ var useUniformContextualEditingState = ({
|
|
|
945
982
|
unsubscribe();
|
|
946
983
|
};
|
|
947
984
|
}, [global, channel, componentData == null ? void 0 : componentData._id, setSelectedComponentReference]);
|
|
948
|
-
return (0,
|
|
985
|
+
return (0, import_react22.useMemo)(
|
|
949
986
|
() => ({
|
|
950
987
|
isContextualEditing,
|
|
951
988
|
selectedComponentReference
|