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