@uniformdev/canvas-react 19.167.2-alpha.3 → 19.169.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +51 -11
- package/dist/index.js +157 -117
- package/dist/index.mjs +51 -11
- package/package.json +8 -6
package/dist/index.esm.js
CHANGED
|
@@ -233,6 +233,45 @@ var PureContextualEditingComponentWrapper = ({
|
|
|
233
233
|
// src/components/UniformComposition.tsx
|
|
234
234
|
import React4, { createContext, useContext } from "react";
|
|
235
235
|
|
|
236
|
+
// src/hooks/useClientConditionsComposition.ts
|
|
237
|
+
import { evaluateWalkTreeVisibility, walkNodeTree } from "@uniformdev/canvas";
|
|
238
|
+
import { produce } from "immer";
|
|
239
|
+
import { useMemo as useMemo2 } from "react";
|
|
240
|
+
|
|
241
|
+
// src/hooks/useClientVisibilityRules.ts
|
|
242
|
+
import { createQuirksVisibilityRule } from "@uniformdev/canvas";
|
|
243
|
+
import { useQuirks } from "@uniformdev/context-react";
|
|
244
|
+
import { useMemo } from "react";
|
|
245
|
+
function useClientVisibilityRules() {
|
|
246
|
+
const quirks = useQuirks({ throwOnMissingProvider: false });
|
|
247
|
+
return useMemo(() => {
|
|
248
|
+
return {
|
|
249
|
+
...createQuirksVisibilityRule(quirks)
|
|
250
|
+
};
|
|
251
|
+
}, [quirks]);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// src/hooks/useClientConditionsComposition.ts
|
|
255
|
+
function useClientConditionsComposition(data) {
|
|
256
|
+
const rules = useClientVisibilityRules();
|
|
257
|
+
const preprocessedValue = useMemo2(() => {
|
|
258
|
+
if (!data) {
|
|
259
|
+
return data;
|
|
260
|
+
}
|
|
261
|
+
try {
|
|
262
|
+
return produce(data, (draft) => {
|
|
263
|
+
walkNodeTree(draft, (context) => {
|
|
264
|
+
evaluateWalkTreeVisibility({ context, rules, showIndeterminate: false });
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
} catch (e) {
|
|
268
|
+
console.error("Error evaluating visibility rules:", e.stack);
|
|
269
|
+
return data;
|
|
270
|
+
}
|
|
271
|
+
}, [data, rules]);
|
|
272
|
+
return preprocessedValue;
|
|
273
|
+
}
|
|
274
|
+
|
|
236
275
|
// src/hooks/useUniformContextualEditing.ts
|
|
237
276
|
import {
|
|
238
277
|
createCanvasChannel,
|
|
@@ -243,7 +282,7 @@ import {
|
|
|
243
282
|
isAllowedReferrer,
|
|
244
283
|
isUpdateCompositionInternalMessage
|
|
245
284
|
} from "@uniformdev/canvas";
|
|
246
|
-
import { useEffect, useMemo, useRef, useState } from "react";
|
|
285
|
+
import { useEffect, useMemo as useMemo3, useRef, useState } from "react";
|
|
247
286
|
var registeredCompositionIds = /* @__PURE__ */ new Set();
|
|
248
287
|
var useUniformContextualEditing = ({
|
|
249
288
|
initialCompositionValue,
|
|
@@ -251,7 +290,7 @@ var useUniformContextualEditing = ({
|
|
|
251
290
|
}) => {
|
|
252
291
|
const [contextualComposition, setContextualComposition] = useState();
|
|
253
292
|
const latestEventTimeStamp = useRef();
|
|
254
|
-
const channel =
|
|
293
|
+
const channel = useMemo3(() => {
|
|
255
294
|
var _a;
|
|
256
295
|
if (!isInContextEditingMode()) {
|
|
257
296
|
return;
|
|
@@ -341,8 +380,9 @@ function UniformComposition({
|
|
|
341
380
|
contextualEditingEnhancer,
|
|
342
381
|
contextualEditingDefaultPlaceholder
|
|
343
382
|
}) {
|
|
383
|
+
const ruledComposition = useClientConditionsComposition(data);
|
|
344
384
|
const { composition, isContextualEditing } = useUniformContextualEditing({
|
|
345
|
-
initialCompositionValue:
|
|
385
|
+
initialCompositionValue: ruledComposition,
|
|
346
386
|
enhance: contextualEditingEnhancer
|
|
347
387
|
});
|
|
348
388
|
return /* @__PURE__ */ React4.createElement(
|
|
@@ -605,7 +645,7 @@ function resolveChildren({
|
|
|
605
645
|
|
|
606
646
|
// src/components/UniformPlayground.tsx
|
|
607
647
|
import { EMPTY_COMPOSITION as EMPTY_COMPOSITION4 } from "@uniformdev/canvas";
|
|
608
|
-
import React8, { useMemo as
|
|
648
|
+
import React8, { useMemo as useMemo4 } from "react";
|
|
609
649
|
var UniformPlayground = ({
|
|
610
650
|
resolveRenderer,
|
|
611
651
|
decorators = [],
|
|
@@ -617,7 +657,7 @@ var UniformPlayground = ({
|
|
|
617
657
|
initialCompositionValue: EMPTY_COMPOSITION4,
|
|
618
658
|
enhance: contextualEditingEnhancer
|
|
619
659
|
});
|
|
620
|
-
const renderedComponent =
|
|
660
|
+
const renderedComponent = useMemo4(() => {
|
|
621
661
|
if (!composition) {
|
|
622
662
|
return null;
|
|
623
663
|
}
|
|
@@ -654,7 +694,7 @@ import {
|
|
|
654
694
|
isRichTextValue,
|
|
655
695
|
isRichTextValueConsideredEmpty
|
|
656
696
|
} from "@uniformdev/richtext";
|
|
657
|
-
import React18, { useMemo as
|
|
697
|
+
import React18, { useMemo as useMemo5 } from "react";
|
|
658
698
|
|
|
659
699
|
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
660
700
|
import { isRichTextNode } from "@uniformdev/richtext";
|
|
@@ -764,11 +804,11 @@ var resolveRichTextDefaultRenderer = (node) => {
|
|
|
764
804
|
// src/components/UniformRichText/UniformRichText.tsx
|
|
765
805
|
var UniformRichText = React18.forwardRef(function UniformRichText2({ parameterId, resolveRichTextRenderer, as: Tag = "div", ...props }, ref) {
|
|
766
806
|
const { data: componentData } = useUniformCurrentComponent();
|
|
767
|
-
const parameter =
|
|
807
|
+
const parameter = useMemo5(() => {
|
|
768
808
|
var _a;
|
|
769
809
|
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
770
810
|
}, [componentData, parameterId]);
|
|
771
|
-
const value =
|
|
811
|
+
const value = useMemo5(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
772
812
|
if (!value || !isRichTextValue(value) || isRichTextValueConsideredEmpty(value)) return null;
|
|
773
813
|
return Tag === null ? /* @__PURE__ */ React18.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ React18.createElement(
|
|
774
814
|
Tag,
|
|
@@ -927,7 +967,7 @@ import {
|
|
|
927
967
|
createCanvasChannel as createCanvasChannel2,
|
|
928
968
|
isUpdateContextualEditingStateInternalMessage
|
|
929
969
|
} from "@uniformdev/canvas";
|
|
930
|
-
import { useEffect as useEffect3, useMemo as
|
|
970
|
+
import { useEffect as useEffect3, useMemo as useMemo6, useState as useState3 } from "react";
|
|
931
971
|
var useUniformContextualEditingState = ({
|
|
932
972
|
global = false
|
|
933
973
|
} = {}) => {
|
|
@@ -937,7 +977,7 @@ var useUniformContextualEditingState = ({
|
|
|
937
977
|
const [previewMode, setPreviewMode] = useState3(
|
|
938
978
|
isContextualEditing ? "editor" : void 0
|
|
939
979
|
);
|
|
940
|
-
const channel =
|
|
980
|
+
const channel = useMemo6(() => {
|
|
941
981
|
if (!isContextualEditing) {
|
|
942
982
|
return;
|
|
943
983
|
}
|
|
@@ -971,7 +1011,7 @@ var useUniformContextualEditingState = ({
|
|
|
971
1011
|
unsubscribe();
|
|
972
1012
|
};
|
|
973
1013
|
}, [global, channel, componentData == null ? void 0 : componentData._id, setSelectedComponentReference, setPreviewMode]);
|
|
974
|
-
return
|
|
1014
|
+
return useMemo6(
|
|
975
1015
|
() => ({
|
|
976
1016
|
isContextualEditing,
|
|
977
1017
|
selectedComponentReference,
|
package/dist/index.js
CHANGED
|
@@ -46,7 +46,7 @@ __export(src_exports, {
|
|
|
46
46
|
convertComponentToProps: () => convertComponentToProps,
|
|
47
47
|
createComponentStore: () => createComponentStore,
|
|
48
48
|
createComponentStoreResolver: () => createComponentStoreResolver,
|
|
49
|
-
createUniformApiEnhancer: () =>
|
|
49
|
+
createUniformApiEnhancer: () => import_canvas6.createUniformApiEnhancer,
|
|
50
50
|
getParameterAttributes: () => getParameterAttributes,
|
|
51
51
|
registerUniformComponent: () => registerUniformComponent,
|
|
52
52
|
useCompositionEventEffect: () => useCompositionEventEffect,
|
|
@@ -131,9 +131,9 @@ registerUniformComponent({ type: "${componentType}", component: ${proposedFileNa
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
// src/components/UniformComponent.tsx
|
|
134
|
-
var
|
|
135
|
-
var
|
|
136
|
-
var
|
|
134
|
+
var import_canvas9 = require("@uniformdev/canvas");
|
|
135
|
+
var import_context_react3 = require("@uniformdev/context-react");
|
|
136
|
+
var import_react9 = __toESM(require("react"));
|
|
137
137
|
|
|
138
138
|
// src/helpers/convertComponentToProps.ts
|
|
139
139
|
function convertComponentToProps(component) {
|
|
@@ -192,8 +192,8 @@ var componentStoreResolver = createComponentStoreResolver({
|
|
|
192
192
|
});
|
|
193
193
|
|
|
194
194
|
// src/components/UniformSlot.tsx
|
|
195
|
-
var
|
|
196
|
-
var
|
|
195
|
+
var import_canvas8 = require("@uniformdev/canvas");
|
|
196
|
+
var import_react8 = __toESM(require("react"));
|
|
197
197
|
|
|
198
198
|
// src/defaultSystemComponentResolver.tsx
|
|
199
199
|
var import_canvas2 = require("@uniformdev/canvas");
|
|
@@ -234,8 +234,8 @@ var defaultSystemComponentResolver = {
|
|
|
234
234
|
};
|
|
235
235
|
|
|
236
236
|
// src/components/ContextualEditingComponentWrapper.tsx
|
|
237
|
-
var
|
|
238
|
-
var
|
|
237
|
+
var import_canvas7 = require("@uniformdev/canvas");
|
|
238
|
+
var import_react7 = __toESM(require("react"));
|
|
239
239
|
|
|
240
240
|
// src/components/PureContextualEditingComponentWrapper.tsx
|
|
241
241
|
var import_canvas3 = require("@uniformdev/canvas");
|
|
@@ -271,31 +271,70 @@ var PureContextualEditingComponentWrapper = ({
|
|
|
271
271
|
};
|
|
272
272
|
|
|
273
273
|
// src/components/UniformComposition.tsx
|
|
274
|
-
var
|
|
274
|
+
var import_react6 = __toESM(require("react"));
|
|
275
275
|
|
|
276
|
-
// src/hooks/
|
|
276
|
+
// src/hooks/useClientConditionsComposition.ts
|
|
277
|
+
var import_canvas5 = require("@uniformdev/canvas");
|
|
278
|
+
var import_immer = require("immer");
|
|
279
|
+
var import_react4 = require("react");
|
|
280
|
+
|
|
281
|
+
// src/hooks/useClientVisibilityRules.ts
|
|
277
282
|
var import_canvas4 = require("@uniformdev/canvas");
|
|
283
|
+
var import_context_react2 = require("@uniformdev/context-react");
|
|
278
284
|
var import_react3 = require("react");
|
|
285
|
+
function useClientVisibilityRules() {
|
|
286
|
+
const quirks = (0, import_context_react2.useQuirks)({ throwOnMissingProvider: false });
|
|
287
|
+
return (0, import_react3.useMemo)(() => {
|
|
288
|
+
return {
|
|
289
|
+
...(0, import_canvas4.createQuirksVisibilityRule)(quirks)
|
|
290
|
+
};
|
|
291
|
+
}, [quirks]);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// src/hooks/useClientConditionsComposition.ts
|
|
295
|
+
function useClientConditionsComposition(data) {
|
|
296
|
+
const rules = useClientVisibilityRules();
|
|
297
|
+
const preprocessedValue = (0, import_react4.useMemo)(() => {
|
|
298
|
+
if (!data) {
|
|
299
|
+
return data;
|
|
300
|
+
}
|
|
301
|
+
try {
|
|
302
|
+
return (0, import_immer.produce)(data, (draft) => {
|
|
303
|
+
(0, import_canvas5.walkNodeTree)(draft, (context) => {
|
|
304
|
+
(0, import_canvas5.evaluateWalkTreeVisibility)({ context, rules, showIndeterminate: false });
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
} catch (e) {
|
|
308
|
+
console.error("Error evaluating visibility rules:", e.stack);
|
|
309
|
+
return data;
|
|
310
|
+
}
|
|
311
|
+
}, [data, rules]);
|
|
312
|
+
return preprocessedValue;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// src/hooks/useUniformContextualEditing.ts
|
|
316
|
+
var import_canvas6 = require("@uniformdev/canvas");
|
|
317
|
+
var import_react5 = require("react");
|
|
279
318
|
var registeredCompositionIds = /* @__PURE__ */ new Set();
|
|
280
319
|
var useUniformContextualEditing = ({
|
|
281
320
|
initialCompositionValue,
|
|
282
321
|
enhance = (message) => message.composition
|
|
283
322
|
}) => {
|
|
284
|
-
const [contextualComposition, setContextualComposition] = (0,
|
|
285
|
-
const latestEventTimeStamp = (0,
|
|
286
|
-
const channel = (0,
|
|
323
|
+
const [contextualComposition, setContextualComposition] = (0, import_react5.useState)();
|
|
324
|
+
const latestEventTimeStamp = (0, import_react5.useRef)();
|
|
325
|
+
const channel = (0, import_react5.useMemo)(() => {
|
|
287
326
|
var _a;
|
|
288
327
|
if (!isInContextEditingMode()) {
|
|
289
328
|
return;
|
|
290
329
|
}
|
|
291
|
-
const channel2 = (0,
|
|
330
|
+
const channel2 = (0, import_canvas6.createCanvasChannel)({
|
|
292
331
|
broadcastTo: [(_a = window.opener) != null ? _a : window.top],
|
|
293
332
|
listenTo: [window]
|
|
294
333
|
});
|
|
295
334
|
return channel2;
|
|
296
335
|
}, []);
|
|
297
|
-
(0,
|
|
298
|
-
if ((contextualComposition == null ? void 0 : contextualComposition._id) && (initialCompositionValue == null ? void 0 : initialCompositionValue._id) !==
|
|
336
|
+
(0, import_react5.useEffect)(() => {
|
|
337
|
+
if ((contextualComposition == null ? void 0 : contextualComposition._id) && (initialCompositionValue == null ? void 0 : initialCompositionValue._id) !== import_canvas6.EMPTY_COMPOSITION._id && (initialCompositionValue == null ? void 0 : initialCompositionValue._id) !== (contextualComposition == null ? void 0 : contextualComposition._id)) {
|
|
299
338
|
setContextualComposition(void 0);
|
|
300
339
|
return;
|
|
301
340
|
}
|
|
@@ -303,7 +342,7 @@ var useUniformContextualEditing = ({
|
|
|
303
342
|
return;
|
|
304
343
|
}
|
|
305
344
|
const unsubscribeFromCompositionUpdates = channel.on("update-composition-internal", async (message) => {
|
|
306
|
-
if (!(0,
|
|
345
|
+
if (!(0, import_canvas6.isUpdateCompositionInternalMessage)(message)) {
|
|
307
346
|
return;
|
|
308
347
|
}
|
|
309
348
|
if (latestEventTimeStamp.current && message.eventTimestamp && message.eventTimestamp <= latestEventTimeStamp.current) {
|
|
@@ -319,11 +358,11 @@ var useUniformContextualEditing = ({
|
|
|
319
358
|
registeredCompositionIds.delete(initialCompositionValue == null ? void 0 : initialCompositionValue._id);
|
|
320
359
|
};
|
|
321
360
|
}, [channel, enhance, initialCompositionValue == null ? void 0 : initialCompositionValue._id, contextualComposition == null ? void 0 : contextualComposition._id]);
|
|
322
|
-
(0,
|
|
361
|
+
(0, import_react5.useEffect)(() => {
|
|
323
362
|
if (!isInContextEditingMode()) {
|
|
324
363
|
return;
|
|
325
364
|
}
|
|
326
|
-
const existingScript = document.getElementById(
|
|
365
|
+
const existingScript = document.getElementById(import_canvas6.IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID);
|
|
327
366
|
if (existingScript) {
|
|
328
367
|
return;
|
|
329
368
|
}
|
|
@@ -333,7 +372,7 @@ var useUniformContextualEditing = ({
|
|
|
333
372
|
version: 2
|
|
334
373
|
};
|
|
335
374
|
const script = document.createElement("script");
|
|
336
|
-
script.id =
|
|
375
|
+
script.id = import_canvas6.IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID;
|
|
337
376
|
script.src = getCanvasInContextEmbedScriptUrl();
|
|
338
377
|
script.async = true;
|
|
339
378
|
document.head.appendChild(script);
|
|
@@ -352,18 +391,18 @@ function isInContextEditingMode() {
|
|
|
352
391
|
return false;
|
|
353
392
|
}
|
|
354
393
|
const isOpenedByInContextEditor = new URLSearchParams(window.location.search).has(
|
|
355
|
-
|
|
394
|
+
import_canvas6.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM
|
|
356
395
|
);
|
|
357
|
-
return isOpenedByInContextEditor && (0,
|
|
396
|
+
return isOpenedByInContextEditor && (0, import_canvas6.isAllowedReferrer)(window.document.referrer);
|
|
358
397
|
}
|
|
359
398
|
|
|
360
399
|
// src/components/UniformComposition.tsx
|
|
361
|
-
var UniformCompositionContext = (0,
|
|
400
|
+
var UniformCompositionContext = (0, import_react6.createContext)({
|
|
362
401
|
data: void 0,
|
|
363
402
|
isContextualEditing: false
|
|
364
403
|
});
|
|
365
404
|
function useUniformCurrentComposition() {
|
|
366
|
-
return (0,
|
|
405
|
+
return (0, import_react6.useContext)(UniformCompositionContext);
|
|
367
406
|
}
|
|
368
407
|
function UniformComposition({
|
|
369
408
|
data,
|
|
@@ -373,16 +412,17 @@ function UniformComposition({
|
|
|
373
412
|
contextualEditingEnhancer,
|
|
374
413
|
contextualEditingDefaultPlaceholder
|
|
375
414
|
}) {
|
|
415
|
+
const ruledComposition = useClientConditionsComposition(data);
|
|
376
416
|
const { composition, isContextualEditing } = useUniformContextualEditing({
|
|
377
|
-
initialCompositionValue:
|
|
417
|
+
initialCompositionValue: ruledComposition,
|
|
378
418
|
enhance: contextualEditingEnhancer
|
|
379
419
|
});
|
|
380
|
-
return /* @__PURE__ */
|
|
420
|
+
return /* @__PURE__ */ import_react6.default.createElement(
|
|
381
421
|
UniformCompositionContext.Provider,
|
|
382
422
|
{
|
|
383
423
|
value: { data: composition, behaviorTracking, resolveRenderer, isContextualEditing }
|
|
384
424
|
},
|
|
385
|
-
/* @__PURE__ */
|
|
425
|
+
/* @__PURE__ */ import_react6.default.createElement(ContextualEditingComponentWrapper, { component: composition }, /* @__PURE__ */ import_react6.default.createElement(
|
|
386
426
|
UniformComponent,
|
|
387
427
|
{
|
|
388
428
|
data: composition,
|
|
@@ -406,16 +446,16 @@ function ContextualEditingComponentWrapper({
|
|
|
406
446
|
children
|
|
407
447
|
}) {
|
|
408
448
|
var _a;
|
|
409
|
-
const isPlaceholder = (0,
|
|
449
|
+
const isPlaceholder = (0, import_canvas7.isComponentPlaceholderId)(component == null ? void 0 : component._id);
|
|
410
450
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
411
451
|
const isReadOnly = ((_a = component == null ? void 0 : component._contextualEditing) == null ? void 0 : _a.isEditable) ? void 0 : "true";
|
|
412
452
|
if (!isContextualEditing) {
|
|
413
|
-
return /* @__PURE__ */
|
|
453
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react7.default.Fragment, null, children);
|
|
414
454
|
}
|
|
415
455
|
if (isPlaceholder && emptyPlaceholder === null) {
|
|
416
456
|
return null;
|
|
417
457
|
}
|
|
418
|
-
return /* @__PURE__ */
|
|
458
|
+
return /* @__PURE__ */ import_react7.default.createElement(
|
|
419
459
|
PureContextualEditingComponentWrapper,
|
|
420
460
|
{
|
|
421
461
|
isPlaceholder,
|
|
@@ -445,7 +485,7 @@ function UniformSlot({
|
|
|
445
485
|
}
|
|
446
486
|
const slot = (_a = parentData.slots) == null ? void 0 : _a[name];
|
|
447
487
|
if (!slot || !Array.isArray(slot)) {
|
|
448
|
-
if (process.env.NODE_ENV === "development" && parentData.type !==
|
|
488
|
+
if (process.env.NODE_ENV === "development" && parentData.type !== import_canvas8.EMPTY_COMPOSITION.type) {
|
|
449
489
|
console.warn(
|
|
450
490
|
`[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:`,
|
|
451
491
|
parentData
|
|
@@ -466,13 +506,13 @@ function UniformSlot({
|
|
|
466
506
|
emptyPlaceholder
|
|
467
507
|
});
|
|
468
508
|
const elements = children ? children({ child, component, key: `wrapped-inner-${index}` }) : child;
|
|
469
|
-
return
|
|
509
|
+
return import_react8.default.createElement(import_react8.default.Fragment, { key: index }, elements);
|
|
470
510
|
});
|
|
471
511
|
if (!wrapperComponent) {
|
|
472
|
-
return
|
|
512
|
+
return import_react8.default.createElement(import_react8.default.Fragment, void 0, finalChildren);
|
|
473
513
|
}
|
|
474
514
|
const Wrapper = wrapperComponent;
|
|
475
|
-
return /* @__PURE__ */
|
|
515
|
+
return /* @__PURE__ */ import_react8.default.createElement(Wrapper, { items: finalChildren, slotName: name });
|
|
476
516
|
}
|
|
477
517
|
function renderComponent({
|
|
478
518
|
component,
|
|
@@ -485,7 +525,7 @@ function renderComponent({
|
|
|
485
525
|
emptyPlaceholder
|
|
486
526
|
}) {
|
|
487
527
|
const RenderComponent = resolveRenderer == null ? void 0 : resolveRenderer(component);
|
|
488
|
-
if (component.type ===
|
|
528
|
+
if (component.type === import_canvas8.CANVAS_TEST_TYPE) {
|
|
489
529
|
const testComponent = defaultSystemComponentResolver.test(
|
|
490
530
|
component,
|
|
491
531
|
key,
|
|
@@ -496,15 +536,15 @@ function renderComponent({
|
|
|
496
536
|
resolveRenderer,
|
|
497
537
|
key: key2,
|
|
498
538
|
parentComponent: component,
|
|
499
|
-
slotName:
|
|
500
|
-
slotChildrenCount: (_a = component == null ? void 0 : component.slots) == null ? void 0 : _a[
|
|
501
|
-
indexInSlot: (_b = component == null ? void 0 : component.slots) == null ? void 0 : _b[
|
|
539
|
+
slotName: import_canvas8.CANVAS_TEST_SLOT,
|
|
540
|
+
slotChildrenCount: (_a = component == null ? void 0 : component.slots) == null ? void 0 : _a[import_canvas8.CANVAS_TEST_SLOT].length,
|
|
541
|
+
indexInSlot: (_b = component == null ? void 0 : component.slots) == null ? void 0 : _b[import_canvas8.CANVAS_TEST_SLOT].findIndex(
|
|
502
542
|
({ _id }) => variantComponent._id === _id
|
|
503
543
|
)
|
|
504
544
|
});
|
|
505
545
|
}
|
|
506
546
|
);
|
|
507
|
-
return /* @__PURE__ */
|
|
547
|
+
return /* @__PURE__ */ import_react8.default.createElement(
|
|
508
548
|
ContextualEditingComponentWrapper,
|
|
509
549
|
{
|
|
510
550
|
component,
|
|
@@ -516,7 +556,7 @@ function renderComponent({
|
|
|
516
556
|
},
|
|
517
557
|
testComponent
|
|
518
558
|
);
|
|
519
|
-
} else if (component.type ===
|
|
559
|
+
} else if (component.type === import_canvas8.CANVAS_PERSONALIZE_TYPE) {
|
|
520
560
|
const personalizationComponent = defaultSystemComponentResolver.personalization(
|
|
521
561
|
component,
|
|
522
562
|
key,
|
|
@@ -527,15 +567,15 @@ function renderComponent({
|
|
|
527
567
|
resolveRenderer,
|
|
528
568
|
key: key2,
|
|
529
569
|
parentComponent: component,
|
|
530
|
-
slotName:
|
|
531
|
-
slotChildrenCount: (_a = component == null ? void 0 : component.slots) == null ? void 0 : _a[
|
|
532
|
-
indexInSlot: (_b = component == null ? void 0 : component.slots) == null ? void 0 : _b[
|
|
570
|
+
slotName: import_canvas8.CANVAS_PERSONALIZE_SLOT,
|
|
571
|
+
slotChildrenCount: (_a = component == null ? void 0 : component.slots) == null ? void 0 : _a[import_canvas8.CANVAS_PERSONALIZE_SLOT].length,
|
|
572
|
+
indexInSlot: (_b = component == null ? void 0 : component.slots) == null ? void 0 : _b[import_canvas8.CANVAS_PERSONALIZE_SLOT].findIndex(
|
|
533
573
|
({ _id }) => variantComponent._id === _id
|
|
534
574
|
)
|
|
535
575
|
});
|
|
536
576
|
}
|
|
537
577
|
);
|
|
538
|
-
return /* @__PURE__ */
|
|
578
|
+
return /* @__PURE__ */ import_react8.default.createElement(
|
|
539
579
|
ContextualEditingComponentWrapper,
|
|
540
580
|
{
|
|
541
581
|
component,
|
|
@@ -549,7 +589,7 @@ function renderComponent({
|
|
|
549
589
|
);
|
|
550
590
|
} else if (RenderComponent) {
|
|
551
591
|
const props = convertComponentToProps(component);
|
|
552
|
-
return /* @__PURE__ */
|
|
592
|
+
return /* @__PURE__ */ import_react8.default.createElement(UniformComponent, { key, data: component, resolveRenderer }, /* @__PURE__ */ import_react8.default.createElement(
|
|
553
593
|
ContextualEditingComponentWrapper,
|
|
554
594
|
{
|
|
555
595
|
component,
|
|
@@ -559,7 +599,7 @@ function renderComponent({
|
|
|
559
599
|
slotChildrenCount,
|
|
560
600
|
emptyPlaceholder
|
|
561
601
|
},
|
|
562
|
-
/* @__PURE__ */
|
|
602
|
+
/* @__PURE__ */ import_react8.default.createElement(RenderComponent, { ...props })
|
|
563
603
|
));
|
|
564
604
|
} else if (process.env.NODE_ENV !== "production") {
|
|
565
605
|
console.warn(
|
|
@@ -572,9 +612,9 @@ function renderComponent({
|
|
|
572
612
|
}
|
|
573
613
|
|
|
574
614
|
// src/components/UniformComponent.tsx
|
|
575
|
-
var UniformComponentContext = (0,
|
|
615
|
+
var UniformComponentContext = (0, import_react9.createContext)({});
|
|
576
616
|
function useUniformCurrentComponent() {
|
|
577
|
-
return (0,
|
|
617
|
+
return (0, import_react9.useContext)(UniformComponentContext);
|
|
578
618
|
}
|
|
579
619
|
function UniformComponent({
|
|
580
620
|
data,
|
|
@@ -585,7 +625,7 @@ function UniformComponent({
|
|
|
585
625
|
}) {
|
|
586
626
|
var _a, _b, _c;
|
|
587
627
|
const parentData = useUniformCurrentComponent();
|
|
588
|
-
const contextContextProviderPresent = (0,
|
|
628
|
+
const contextContextProviderPresent = (0, import_context_react3.useUniformContext)({ throwOnMissingProvider: false }) !== void 0;
|
|
589
629
|
if (!data) {
|
|
590
630
|
if (process.env.NODE_ENV === "development") {
|
|
591
631
|
console.warn(`[canvas-dev] UniformComponent was rendered with no data, nothing will be output.`);
|
|
@@ -598,17 +638,17 @@ function UniformComponent({
|
|
|
598
638
|
behaviorTracking: (_a = behaviorTracking != null ? behaviorTracking : parentData == null ? void 0 : parentData.behaviorTracking) != null ? _a : "onView",
|
|
599
639
|
contextualEditingDefaultPlaceholder: contextualEditingDefaultPlaceholder != null ? contextualEditingDefaultPlaceholder : parentData.contextualEditingDefaultPlaceholder
|
|
600
640
|
};
|
|
601
|
-
const enrichmentTags = (_c = (_b = data.parameters) == null ? void 0 : _b[
|
|
602
|
-
const TrackComponent = contextValue.behaviorTracking === "onLoad" ?
|
|
641
|
+
const enrichmentTags = (_c = (_b = data.parameters) == null ? void 0 : _b[import_canvas9.CANVAS_ENRICHMENT_TAG_PARAM]) == null ? void 0 : _c.value;
|
|
642
|
+
const TrackComponent = contextValue.behaviorTracking === "onLoad" ? import_context_react3.TrackFragment : import_context_react3.Track;
|
|
603
643
|
const resolvedChildren = resolveChildren({
|
|
604
644
|
children,
|
|
605
645
|
data,
|
|
606
646
|
hasParentLayout: Boolean(parentData.data),
|
|
607
647
|
resolveRenderer: contextValue.resolveRenderer
|
|
608
648
|
});
|
|
609
|
-
return /* @__PURE__ */
|
|
649
|
+
return /* @__PURE__ */ import_react9.default.createElement(UniformComponentContext.Provider, { value: contextValue }, contextContextProviderPresent ? (
|
|
610
650
|
/* auto-track behavior signals when in a Canvas context */
|
|
611
|
-
/* @__PURE__ */
|
|
651
|
+
/* @__PURE__ */ import_react9.default.createElement(TrackComponent, { behavior: enrichmentTags }, resolvedChildren)
|
|
612
652
|
) : resolvedChildren);
|
|
613
653
|
}
|
|
614
654
|
function resolveChildren({
|
|
@@ -621,14 +661,14 @@ function resolveChildren({
|
|
|
621
661
|
if (!children && !hasParentLayout) {
|
|
622
662
|
const topLevelComponent = resolveRenderer({ type: data.type });
|
|
623
663
|
if (topLevelComponent) {
|
|
624
|
-
children =
|
|
664
|
+
children = import_react9.default.createElement(topLevelComponent, convertComponentToProps(data));
|
|
625
665
|
} else {
|
|
626
666
|
if (Object.keys((_a = data.slots) != null ? _a : {}).length > 1 && process.env.NODE_ENV === "development") {
|
|
627
667
|
console.warn(
|
|
628
668
|
`[canvas-dev] All the slots in component '${data.type}' are rendered in no particular order. Use '<UniformSlot name={slotName} />' to reliably render the slots.`
|
|
629
669
|
);
|
|
630
670
|
}
|
|
631
|
-
children = Object.keys(data.slots || {}).map((slotName) => /* @__PURE__ */
|
|
671
|
+
children = Object.keys(data.slots || {}).map((slotName) => /* @__PURE__ */ import_react9.default.createElement(UniformSlot, { key: slotName, name: slotName }));
|
|
632
672
|
}
|
|
633
673
|
}
|
|
634
674
|
const renderChildren = typeof children === "function" ? children(convertComponentToProps(data)) : children;
|
|
@@ -636,8 +676,8 @@ function resolveChildren({
|
|
|
636
676
|
}
|
|
637
677
|
|
|
638
678
|
// src/components/UniformPlayground.tsx
|
|
639
|
-
var
|
|
640
|
-
var
|
|
679
|
+
var import_canvas10 = require("@uniformdev/canvas");
|
|
680
|
+
var import_react10 = __toESM(require("react"));
|
|
641
681
|
var UniformPlayground = ({
|
|
642
682
|
resolveRenderer,
|
|
643
683
|
decorators = [],
|
|
@@ -646,14 +686,14 @@ var UniformPlayground = ({
|
|
|
646
686
|
contextualEditingDefaultPlaceholder
|
|
647
687
|
}) => {
|
|
648
688
|
const { composition, isContextualEditing } = useUniformContextualEditing({
|
|
649
|
-
initialCompositionValue:
|
|
689
|
+
initialCompositionValue: import_canvas10.EMPTY_COMPOSITION,
|
|
650
690
|
enhance: contextualEditingEnhancer
|
|
651
691
|
});
|
|
652
|
-
const renderedComponent = (0,
|
|
692
|
+
const renderedComponent = (0, import_react10.useMemo)(() => {
|
|
653
693
|
if (!composition) {
|
|
654
694
|
return null;
|
|
655
695
|
}
|
|
656
|
-
let component = /* @__PURE__ */
|
|
696
|
+
let component = /* @__PURE__ */ import_react10.default.createElement(ContextualEditingComponentWrapper, { component: composition }, /* @__PURE__ */ import_react10.default.createElement(
|
|
657
697
|
UniformComponent,
|
|
658
698
|
{
|
|
659
699
|
data: composition,
|
|
@@ -663,11 +703,11 @@ var UniformPlayground = ({
|
|
|
663
703
|
}
|
|
664
704
|
));
|
|
665
705
|
decorators.forEach((Decorator) => {
|
|
666
|
-
component = /* @__PURE__ */
|
|
706
|
+
component = /* @__PURE__ */ import_react10.default.createElement(Decorator, { data: composition }, component);
|
|
667
707
|
});
|
|
668
708
|
return component;
|
|
669
709
|
}, [resolveRenderer, decorators, composition, behaviorTracking, contextualEditingDefaultPlaceholder]);
|
|
670
|
-
return /* @__PURE__ */
|
|
710
|
+
return /* @__PURE__ */ import_react10.default.createElement(
|
|
671
711
|
UniformCompositionContext.Provider,
|
|
672
712
|
{
|
|
673
713
|
value: { data: composition, behaviorTracking, resolveRenderer, isContextualEditing }
|
|
@@ -677,57 +717,57 @@ var UniformPlayground = ({
|
|
|
677
717
|
};
|
|
678
718
|
|
|
679
719
|
// src/components/UniformRichText/UniformRichText.tsx
|
|
680
|
-
var
|
|
720
|
+
var import_canvas11 = require("@uniformdev/canvas");
|
|
681
721
|
var import_richtext5 = require("@uniformdev/richtext");
|
|
682
|
-
var
|
|
722
|
+
var import_react20 = __toESM(require("react"));
|
|
683
723
|
|
|
684
724
|
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
685
725
|
var import_richtext4 = require("@uniformdev/richtext");
|
|
686
|
-
var
|
|
726
|
+
var import_react19 = __toESM(require("react"));
|
|
687
727
|
|
|
688
728
|
// src/components/UniformRichText/nodes/HeadingRichTextNode.tsx
|
|
689
|
-
var
|
|
729
|
+
var import_react11 = __toESM(require("react"));
|
|
690
730
|
var HeadingRichTextNode = ({ children, node }) => {
|
|
691
731
|
const { tag } = node;
|
|
692
732
|
const HTag = tag != null ? tag : "h1";
|
|
693
|
-
return /* @__PURE__ */
|
|
733
|
+
return /* @__PURE__ */ import_react11.default.createElement(HTag, null, children);
|
|
694
734
|
};
|
|
695
735
|
|
|
696
736
|
// src/components/UniformRichText/nodes/LinebreakRichTextNode.tsx
|
|
697
|
-
var
|
|
737
|
+
var import_react12 = __toESM(require("react"));
|
|
698
738
|
var LinebreakRichTextNode = () => {
|
|
699
|
-
return /* @__PURE__ */
|
|
739
|
+
return /* @__PURE__ */ import_react12.default.createElement("br", null);
|
|
700
740
|
};
|
|
701
741
|
|
|
702
742
|
// src/components/UniformRichText/nodes/LinkRichTextNode.tsx
|
|
703
743
|
var import_richtext = require("@uniformdev/richtext");
|
|
704
|
-
var
|
|
744
|
+
var import_react13 = __toESM(require("react"));
|
|
705
745
|
var LinkRichTextNode = ({ children, node }) => {
|
|
706
746
|
const { link } = node;
|
|
707
|
-
return /* @__PURE__ */
|
|
747
|
+
return /* @__PURE__ */ import_react13.default.createElement("a", { href: (0, import_richtext.linkParamValueToHref)(link) }, children);
|
|
708
748
|
};
|
|
709
749
|
|
|
710
750
|
// src/components/UniformRichText/nodes/ListItemRichTextNode.tsx
|
|
711
|
-
var
|
|
751
|
+
var import_react14 = __toESM(require("react"));
|
|
712
752
|
var ListItemRichTextNode = ({ children, node }) => {
|
|
713
753
|
const { value } = node;
|
|
714
|
-
return /* @__PURE__ */
|
|
754
|
+
return /* @__PURE__ */ import_react14.default.createElement("li", { value: Number.isFinite(value) && value > 0 ? value : void 0 }, children);
|
|
715
755
|
};
|
|
716
756
|
|
|
717
757
|
// src/components/UniformRichText/nodes/ListRichTextNode.tsx
|
|
718
|
-
var
|
|
758
|
+
var import_react15 = __toESM(require("react"));
|
|
719
759
|
var ListRichTextNode = ({ children, node }) => {
|
|
720
760
|
const { tag, start } = node;
|
|
721
761
|
const ListTag = tag != null ? tag : "ul";
|
|
722
|
-
return /* @__PURE__ */
|
|
762
|
+
return /* @__PURE__ */ import_react15.default.createElement(ListTag, { start: Number.isFinite(start) && start > 0 ? start : void 0 }, children);
|
|
723
763
|
};
|
|
724
764
|
|
|
725
765
|
// src/components/UniformRichText/nodes/ParagraphRichTextNode.tsx
|
|
726
766
|
var import_richtext2 = require("@uniformdev/richtext");
|
|
727
|
-
var
|
|
767
|
+
var import_react16 = __toESM(require("react"));
|
|
728
768
|
var ParagraphRichTextNode = ({ children, node }) => {
|
|
729
769
|
const { format, direction } = node;
|
|
730
|
-
return /* @__PURE__ */
|
|
770
|
+
return /* @__PURE__ */ import_react16.default.createElement(
|
|
731
771
|
"p",
|
|
732
772
|
{
|
|
733
773
|
dir: (0, import_richtext2.isPureDirection)(direction) ? direction : void 0,
|
|
@@ -738,18 +778,18 @@ var ParagraphRichTextNode = ({ children, node }) => {
|
|
|
738
778
|
};
|
|
739
779
|
|
|
740
780
|
// src/components/UniformRichText/nodes/TabRichTextNode.tsx
|
|
741
|
-
var
|
|
781
|
+
var import_react17 = __toESM(require("react"));
|
|
742
782
|
var TabRichTextNode = () => {
|
|
743
|
-
return /* @__PURE__ */
|
|
783
|
+
return /* @__PURE__ */ import_react17.default.createElement(import_react17.default.Fragment, null, " ");
|
|
744
784
|
};
|
|
745
785
|
|
|
746
786
|
// src/components/UniformRichText/nodes/TextRichTextNode.tsx
|
|
747
787
|
var import_richtext3 = require("@uniformdev/richtext");
|
|
748
|
-
var
|
|
788
|
+
var import_react18 = __toESM(require("react"));
|
|
749
789
|
var TextRichTextNode = ({ node }) => {
|
|
750
790
|
const { text, format } = node;
|
|
751
791
|
const tags = (0, import_richtext3.getRichTextTagsFromTextFormat)(format);
|
|
752
|
-
return /* @__PURE__ */
|
|
792
|
+
return /* @__PURE__ */ import_react18.default.createElement(import_react18.default.Fragment, null, tags.length > 0 ? tags.reduceRight((children, Tag) => /* @__PURE__ */ import_react18.default.createElement(Tag, null, children), text) : text);
|
|
753
793
|
};
|
|
754
794
|
|
|
755
795
|
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
@@ -763,8 +803,8 @@ function UniformRichTextNode({ node, ...props }) {
|
|
|
763
803
|
if (!NodeRenderer) {
|
|
764
804
|
return null;
|
|
765
805
|
}
|
|
766
|
-
const children = node.children ? node.children.map((childNode, i) => /* @__PURE__ */
|
|
767
|
-
return /* @__PURE__ */
|
|
806
|
+
const children = node.children ? node.children.map((childNode, i) => /* @__PURE__ */ import_react19.default.createElement(UniformRichTextNode, { ...props, key: i, node: childNode })) : null;
|
|
807
|
+
return /* @__PURE__ */ import_react19.default.createElement(NodeRenderer, { node }, children);
|
|
768
808
|
}
|
|
769
809
|
var rendererMap = /* @__PURE__ */ new Map([
|
|
770
810
|
["heading", HeadingRichTextNode],
|
|
@@ -773,12 +813,12 @@ var rendererMap = /* @__PURE__ */ new Map([
|
|
|
773
813
|
["list", ListRichTextNode],
|
|
774
814
|
["listitem", ListItemRichTextNode],
|
|
775
815
|
["paragraph", ParagraphRichTextNode],
|
|
776
|
-
["quote", ({ children }) => /* @__PURE__ */
|
|
816
|
+
["quote", ({ children }) => /* @__PURE__ */ import_react19.default.createElement("blockquote", null, children)],
|
|
777
817
|
[
|
|
778
818
|
"code",
|
|
779
|
-
({ children }) => /* @__PURE__ */
|
|
819
|
+
({ children }) => /* @__PURE__ */ import_react19.default.createElement("pre", null, /* @__PURE__ */ import_react19.default.createElement("code", null, children))
|
|
780
820
|
],
|
|
781
|
-
["root", ({ children }) => /* @__PURE__ */
|
|
821
|
+
["root", ({ children }) => /* @__PURE__ */ import_react19.default.createElement(import_react19.default.Fragment, null, children)],
|
|
782
822
|
["text", TextRichTextNode],
|
|
783
823
|
["tab", TabRichTextNode]
|
|
784
824
|
]);
|
|
@@ -787,34 +827,34 @@ var resolveRichTextDefaultRenderer = (node) => {
|
|
|
787
827
|
};
|
|
788
828
|
|
|
789
829
|
// src/components/UniformRichText/UniformRichText.tsx
|
|
790
|
-
var UniformRichText =
|
|
830
|
+
var UniformRichText = import_react20.default.forwardRef(function UniformRichText2({ parameterId, resolveRichTextRenderer, as: Tag = "div", ...props }, ref) {
|
|
791
831
|
const { data: componentData } = useUniformCurrentComponent();
|
|
792
|
-
const parameter = (0,
|
|
832
|
+
const parameter = (0, import_react20.useMemo)(() => {
|
|
793
833
|
var _a;
|
|
794
834
|
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
795
835
|
}, [componentData, parameterId]);
|
|
796
|
-
const value = (0,
|
|
836
|
+
const value = (0, import_react20.useMemo)(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
797
837
|
if (!value || !(0, import_richtext5.isRichTextValue)(value) || (0, import_richtext5.isRichTextValueConsideredEmpty)(value)) return null;
|
|
798
|
-
return Tag === null ? /* @__PURE__ */
|
|
838
|
+
return Tag === null ? /* @__PURE__ */ import_react20.default.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ import_react20.default.createElement(
|
|
799
839
|
Tag,
|
|
800
840
|
{
|
|
801
841
|
ref,
|
|
802
842
|
...props,
|
|
803
843
|
...{
|
|
804
|
-
[
|
|
805
|
-
[
|
|
806
|
-
[
|
|
844
|
+
[import_canvas11.ATTRIBUTE_COMPONENT_ID]: componentData == null ? void 0 : componentData._id,
|
|
845
|
+
[import_canvas11.ATTRIBUTE_PARAMETER_ID]: parameterId,
|
|
846
|
+
[import_canvas11.ATTRIBUTE_PARAMETER_TYPE]: "richText"
|
|
807
847
|
}
|
|
808
848
|
},
|
|
809
|
-
/* @__PURE__ */
|
|
849
|
+
/* @__PURE__ */ import_react20.default.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer })
|
|
810
850
|
);
|
|
811
851
|
});
|
|
812
852
|
|
|
813
853
|
// src/components/UniformText.tsx
|
|
814
|
-
var
|
|
854
|
+
var import_react22 = __toESM(require("react"));
|
|
815
855
|
|
|
816
856
|
// src/components/PureUniformText.tsx
|
|
817
|
-
var
|
|
857
|
+
var import_react21 = __toESM(require("react"));
|
|
818
858
|
var PureUniformText = ({
|
|
819
859
|
as: Tag = "span",
|
|
820
860
|
parameterId,
|
|
@@ -833,10 +873,10 @@ var PureUniformText = ({
|
|
|
833
873
|
return null;
|
|
834
874
|
}
|
|
835
875
|
if (!isContextualEditing) {
|
|
836
|
-
return /* @__PURE__ */
|
|
876
|
+
return /* @__PURE__ */ import_react21.default.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
837
877
|
}
|
|
838
878
|
const computedPlaceholder = typeof placeholder === "function" ? placeholder({ id: parameterId }) : placeholder;
|
|
839
|
-
return /* @__PURE__ */
|
|
879
|
+
return /* @__PURE__ */ import_react21.default.createElement(
|
|
840
880
|
Tag,
|
|
841
881
|
{
|
|
842
882
|
...props,
|
|
@@ -865,7 +905,7 @@ var UniformText = ({
|
|
|
865
905
|
var _a, _b, _c;
|
|
866
906
|
const { data: componentData, contextualEditingDefaultPlaceholder } = useUniformCurrentComponent();
|
|
867
907
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
868
|
-
const [isFocused, setIsFocused] = (0,
|
|
908
|
+
const [isFocused, setIsFocused] = (0, import_react22.useState)(false);
|
|
869
909
|
const parameter = (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
870
910
|
const isEditable = (_c = (_b = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _b.isEditable) != null ? _c : false;
|
|
871
911
|
const shouldSkipCustomRendering = isFocused && isEditable;
|
|
@@ -874,7 +914,7 @@ var UniformText = ({
|
|
|
874
914
|
}
|
|
875
915
|
const placeholderProp = placeholder != null ? placeholder : contextualEditingDefaultPlaceholder;
|
|
876
916
|
const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: parameterId }) : placeholderProp;
|
|
877
|
-
return /* @__PURE__ */
|
|
917
|
+
return /* @__PURE__ */ import_react22.default.createElement(
|
|
878
918
|
PureUniformText,
|
|
879
919
|
{
|
|
880
920
|
...props,
|
|
@@ -897,35 +937,35 @@ var UniformText = ({
|
|
|
897
937
|
};
|
|
898
938
|
|
|
899
939
|
// src/helpers/getParameterAttributes.ts
|
|
900
|
-
var
|
|
940
|
+
var import_canvas12 = require("@uniformdev/canvas");
|
|
901
941
|
var getParameterAttributes = (options) => {
|
|
902
942
|
return {
|
|
903
|
-
...(0,
|
|
943
|
+
...(0, import_canvas12.getParameterAttributes)(options),
|
|
904
944
|
suppressContentEditableWarning: true
|
|
905
945
|
};
|
|
906
946
|
};
|
|
907
947
|
|
|
908
948
|
// src/hooks/useCompositionEventEffect.ts
|
|
909
|
-
var
|
|
910
|
-
var
|
|
949
|
+
var import_canvas13 = require("@uniformdev/canvas");
|
|
950
|
+
var import_react23 = require("react");
|
|
911
951
|
function useCompositionEventEffect({
|
|
912
952
|
enabled,
|
|
913
953
|
projectId,
|
|
914
954
|
compositionId,
|
|
915
955
|
effect
|
|
916
956
|
}) {
|
|
917
|
-
(0,
|
|
957
|
+
(0, import_react23.useEffect)(() => {
|
|
918
958
|
if (!enabled || !compositionId || !projectId) {
|
|
919
959
|
return;
|
|
920
960
|
}
|
|
921
961
|
let goodbye = void 0;
|
|
922
962
|
const loadEffect = async () => {
|
|
923
|
-
const eventBus = await (0,
|
|
963
|
+
const eventBus = await (0, import_canvas13.createEventBus)();
|
|
924
964
|
if (eventBus) {
|
|
925
|
-
goodbye = (0,
|
|
965
|
+
goodbye = (0, import_canvas13.subscribeToComposition)({
|
|
926
966
|
eventBus,
|
|
927
967
|
compositionId,
|
|
928
|
-
compositionState:
|
|
968
|
+
compositionState: import_canvas13.CANVAS_DRAFT_STATE,
|
|
929
969
|
projectId,
|
|
930
970
|
callback: effect,
|
|
931
971
|
event: "updated"
|
|
@@ -942,28 +982,28 @@ function useCompositionEventEffect({
|
|
|
942
982
|
}
|
|
943
983
|
|
|
944
984
|
// src/hooks/useUniformContextualEditingState.ts
|
|
945
|
-
var
|
|
946
|
-
var
|
|
985
|
+
var import_canvas14 = require("@uniformdev/canvas");
|
|
986
|
+
var import_react24 = require("react");
|
|
947
987
|
var useUniformContextualEditingState = ({
|
|
948
988
|
global = false
|
|
949
989
|
} = {}) => {
|
|
950
990
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
951
991
|
const { data: componentData } = useUniformCurrentComponent();
|
|
952
|
-
const [selectedComponentReference, setSelectedComponentReference] = (0,
|
|
953
|
-
const [previewMode, setPreviewMode] = (0,
|
|
992
|
+
const [selectedComponentReference, setSelectedComponentReference] = (0, import_react24.useState)();
|
|
993
|
+
const [previewMode, setPreviewMode] = (0, import_react24.useState)(
|
|
954
994
|
isContextualEditing ? "editor" : void 0
|
|
955
995
|
);
|
|
956
|
-
const channel = (0,
|
|
996
|
+
const channel = (0, import_react24.useMemo)(() => {
|
|
957
997
|
if (!isContextualEditing) {
|
|
958
998
|
return;
|
|
959
999
|
}
|
|
960
|
-
const channel2 = (0,
|
|
1000
|
+
const channel2 = (0, import_canvas14.createCanvasChannel)({
|
|
961
1001
|
broadcastTo: [window],
|
|
962
1002
|
listenTo: [window]
|
|
963
1003
|
});
|
|
964
1004
|
return channel2;
|
|
965
1005
|
}, [isContextualEditing]);
|
|
966
|
-
(0,
|
|
1006
|
+
(0, import_react24.useEffect)(() => {
|
|
967
1007
|
var _a, _b;
|
|
968
1008
|
if (!channel) {
|
|
969
1009
|
return;
|
|
@@ -973,7 +1013,7 @@ var useUniformContextualEditingState = ({
|
|
|
973
1013
|
}
|
|
974
1014
|
const unsubscribe = channel.on("update-contextual-editing-state-internal", async (message) => {
|
|
975
1015
|
var _a2;
|
|
976
|
-
if (!(0,
|
|
1016
|
+
if (!(0, import_canvas14.isUpdateContextualEditingStateInternalMessage)(message)) {
|
|
977
1017
|
return;
|
|
978
1018
|
}
|
|
979
1019
|
setPreviewMode(message.state.previewMode);
|
|
@@ -987,7 +1027,7 @@ var useUniformContextualEditingState = ({
|
|
|
987
1027
|
unsubscribe();
|
|
988
1028
|
};
|
|
989
1029
|
}, [global, channel, componentData == null ? void 0 : componentData._id, setSelectedComponentReference, setPreviewMode]);
|
|
990
|
-
return (0,
|
|
1030
|
+
return (0, import_react24.useMemo)(
|
|
991
1031
|
() => ({
|
|
992
1032
|
isContextualEditing,
|
|
993
1033
|
selectedComponentReference,
|
package/dist/index.mjs
CHANGED
|
@@ -233,6 +233,45 @@ var PureContextualEditingComponentWrapper = ({
|
|
|
233
233
|
// src/components/UniformComposition.tsx
|
|
234
234
|
import React4, { createContext, useContext } from "react";
|
|
235
235
|
|
|
236
|
+
// src/hooks/useClientConditionsComposition.ts
|
|
237
|
+
import { evaluateWalkTreeVisibility, walkNodeTree } from "@uniformdev/canvas";
|
|
238
|
+
import { produce } from "immer";
|
|
239
|
+
import { useMemo as useMemo2 } from "react";
|
|
240
|
+
|
|
241
|
+
// src/hooks/useClientVisibilityRules.ts
|
|
242
|
+
import { createQuirksVisibilityRule } from "@uniformdev/canvas";
|
|
243
|
+
import { useQuirks } from "@uniformdev/context-react";
|
|
244
|
+
import { useMemo } from "react";
|
|
245
|
+
function useClientVisibilityRules() {
|
|
246
|
+
const quirks = useQuirks({ throwOnMissingProvider: false });
|
|
247
|
+
return useMemo(() => {
|
|
248
|
+
return {
|
|
249
|
+
...createQuirksVisibilityRule(quirks)
|
|
250
|
+
};
|
|
251
|
+
}, [quirks]);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// src/hooks/useClientConditionsComposition.ts
|
|
255
|
+
function useClientConditionsComposition(data) {
|
|
256
|
+
const rules = useClientVisibilityRules();
|
|
257
|
+
const preprocessedValue = useMemo2(() => {
|
|
258
|
+
if (!data) {
|
|
259
|
+
return data;
|
|
260
|
+
}
|
|
261
|
+
try {
|
|
262
|
+
return produce(data, (draft) => {
|
|
263
|
+
walkNodeTree(draft, (context) => {
|
|
264
|
+
evaluateWalkTreeVisibility({ context, rules, showIndeterminate: false });
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
} catch (e) {
|
|
268
|
+
console.error("Error evaluating visibility rules:", e.stack);
|
|
269
|
+
return data;
|
|
270
|
+
}
|
|
271
|
+
}, [data, rules]);
|
|
272
|
+
return preprocessedValue;
|
|
273
|
+
}
|
|
274
|
+
|
|
236
275
|
// src/hooks/useUniformContextualEditing.ts
|
|
237
276
|
import {
|
|
238
277
|
createCanvasChannel,
|
|
@@ -243,7 +282,7 @@ import {
|
|
|
243
282
|
isAllowedReferrer,
|
|
244
283
|
isUpdateCompositionInternalMessage
|
|
245
284
|
} from "@uniformdev/canvas";
|
|
246
|
-
import { useEffect, useMemo, useRef, useState } from "react";
|
|
285
|
+
import { useEffect, useMemo as useMemo3, useRef, useState } from "react";
|
|
247
286
|
var registeredCompositionIds = /* @__PURE__ */ new Set();
|
|
248
287
|
var useUniformContextualEditing = ({
|
|
249
288
|
initialCompositionValue,
|
|
@@ -251,7 +290,7 @@ var useUniformContextualEditing = ({
|
|
|
251
290
|
}) => {
|
|
252
291
|
const [contextualComposition, setContextualComposition] = useState();
|
|
253
292
|
const latestEventTimeStamp = useRef();
|
|
254
|
-
const channel =
|
|
293
|
+
const channel = useMemo3(() => {
|
|
255
294
|
var _a;
|
|
256
295
|
if (!isInContextEditingMode()) {
|
|
257
296
|
return;
|
|
@@ -341,8 +380,9 @@ function UniformComposition({
|
|
|
341
380
|
contextualEditingEnhancer,
|
|
342
381
|
contextualEditingDefaultPlaceholder
|
|
343
382
|
}) {
|
|
383
|
+
const ruledComposition = useClientConditionsComposition(data);
|
|
344
384
|
const { composition, isContextualEditing } = useUniformContextualEditing({
|
|
345
|
-
initialCompositionValue:
|
|
385
|
+
initialCompositionValue: ruledComposition,
|
|
346
386
|
enhance: contextualEditingEnhancer
|
|
347
387
|
});
|
|
348
388
|
return /* @__PURE__ */ React4.createElement(
|
|
@@ -605,7 +645,7 @@ function resolveChildren({
|
|
|
605
645
|
|
|
606
646
|
// src/components/UniformPlayground.tsx
|
|
607
647
|
import { EMPTY_COMPOSITION as EMPTY_COMPOSITION4 } from "@uniformdev/canvas";
|
|
608
|
-
import React8, { useMemo as
|
|
648
|
+
import React8, { useMemo as useMemo4 } from "react";
|
|
609
649
|
var UniformPlayground = ({
|
|
610
650
|
resolveRenderer,
|
|
611
651
|
decorators = [],
|
|
@@ -617,7 +657,7 @@ var UniformPlayground = ({
|
|
|
617
657
|
initialCompositionValue: EMPTY_COMPOSITION4,
|
|
618
658
|
enhance: contextualEditingEnhancer
|
|
619
659
|
});
|
|
620
|
-
const renderedComponent =
|
|
660
|
+
const renderedComponent = useMemo4(() => {
|
|
621
661
|
if (!composition) {
|
|
622
662
|
return null;
|
|
623
663
|
}
|
|
@@ -654,7 +694,7 @@ import {
|
|
|
654
694
|
isRichTextValue,
|
|
655
695
|
isRichTextValueConsideredEmpty
|
|
656
696
|
} from "@uniformdev/richtext";
|
|
657
|
-
import React18, { useMemo as
|
|
697
|
+
import React18, { useMemo as useMemo5 } from "react";
|
|
658
698
|
|
|
659
699
|
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
660
700
|
import { isRichTextNode } from "@uniformdev/richtext";
|
|
@@ -764,11 +804,11 @@ var resolveRichTextDefaultRenderer = (node) => {
|
|
|
764
804
|
// src/components/UniformRichText/UniformRichText.tsx
|
|
765
805
|
var UniformRichText = React18.forwardRef(function UniformRichText2({ parameterId, resolveRichTextRenderer, as: Tag = "div", ...props }, ref) {
|
|
766
806
|
const { data: componentData } = useUniformCurrentComponent();
|
|
767
|
-
const parameter =
|
|
807
|
+
const parameter = useMemo5(() => {
|
|
768
808
|
var _a;
|
|
769
809
|
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
770
810
|
}, [componentData, parameterId]);
|
|
771
|
-
const value =
|
|
811
|
+
const value = useMemo5(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
772
812
|
if (!value || !isRichTextValue(value) || isRichTextValueConsideredEmpty(value)) return null;
|
|
773
813
|
return Tag === null ? /* @__PURE__ */ React18.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ React18.createElement(
|
|
774
814
|
Tag,
|
|
@@ -927,7 +967,7 @@ import {
|
|
|
927
967
|
createCanvasChannel as createCanvasChannel2,
|
|
928
968
|
isUpdateContextualEditingStateInternalMessage
|
|
929
969
|
} from "@uniformdev/canvas";
|
|
930
|
-
import { useEffect as useEffect3, useMemo as
|
|
970
|
+
import { useEffect as useEffect3, useMemo as useMemo6, useState as useState3 } from "react";
|
|
931
971
|
var useUniformContextualEditingState = ({
|
|
932
972
|
global = false
|
|
933
973
|
} = {}) => {
|
|
@@ -937,7 +977,7 @@ var useUniformContextualEditingState = ({
|
|
|
937
977
|
const [previewMode, setPreviewMode] = useState3(
|
|
938
978
|
isContextualEditing ? "editor" : void 0
|
|
939
979
|
);
|
|
940
|
-
const channel =
|
|
980
|
+
const channel = useMemo6(() => {
|
|
941
981
|
if (!isContextualEditing) {
|
|
942
982
|
return;
|
|
943
983
|
}
|
|
@@ -971,7 +1011,7 @@ var useUniformContextualEditingState = ({
|
|
|
971
1011
|
unsubscribe();
|
|
972
1012
|
};
|
|
973
1013
|
}, [global, channel, componentData == null ? void 0 : componentData._id, setSelectedComponentReference, setPreviewMode]);
|
|
974
|
-
return
|
|
1014
|
+
return useMemo6(
|
|
975
1015
|
() => ({
|
|
976
1016
|
isContextualEditing,
|
|
977
1017
|
selectedComponentReference,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-react",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.169.0",
|
|
4
4
|
"description": "React SDK for Uniform Canvas",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -45,17 +45,19 @@
|
|
|
45
45
|
"document": "api-extractor run --local"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@uniformdev/canvas": "19.
|
|
49
|
-
"@uniformdev/context": "19.
|
|
50
|
-
"@uniformdev/context-react": "19.
|
|
51
|
-
"@uniformdev/richtext": "19.
|
|
48
|
+
"@uniformdev/canvas": "19.169.0",
|
|
49
|
+
"@uniformdev/context": "19.169.0",
|
|
50
|
+
"@uniformdev/context-react": "19.169.0",
|
|
51
|
+
"@uniformdev/richtext": "19.169.0"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
+
"immer": ">= 10",
|
|
54
55
|
"react": ">= 16 || 17 || 18",
|
|
55
56
|
"react-dom": ">=16"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
58
59
|
"@types/react": "18.2.40",
|
|
60
|
+
"immer": "10.1.1",
|
|
59
61
|
"react": "18.2.0",
|
|
60
62
|
"react-dom": "18.2.0"
|
|
61
63
|
},
|
|
@@ -65,5 +67,5 @@
|
|
|
65
67
|
"publishConfig": {
|
|
66
68
|
"access": "public"
|
|
67
69
|
},
|
|
68
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "78f454f7178dfac0480403a9728c430b7697a724"
|
|
69
71
|
}
|