@uniformdev/canvas-react 18.34.1-alpha.57 → 18.35.1-alpha.16
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.d.ts +24 -2
- package/dist/index.esm.js +81 -6
- package/dist/index.js +83 -7
- package/dist/index.mjs +81 -6
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -199,7 +199,7 @@ type UseUniformContextualEditingProps = {
|
|
|
199
199
|
* A function to enhance the composition after receiving it from Canvas editor.
|
|
200
200
|
* WARNING: This enhancer will run on the client side. Make sure you're not exposing any secrets. You can use `createApiEnhancer` to create an enhancer based on an API route.
|
|
201
201
|
*/
|
|
202
|
-
enhance?: (composition: UpdateCompositionMessage) => RootComponentInstance | Promise<RootComponentInstance>;
|
|
202
|
+
enhance?: ({ composition, hash, }: Pick<UpdateCompositionMessage, 'composition' | 'hash'>) => RootComponentInstance | Promise<RootComponentInstance>;
|
|
203
203
|
};
|
|
204
204
|
/**
|
|
205
205
|
* Adds contextual editing capability to a Uniform app.
|
|
@@ -504,6 +504,28 @@ type SlotProps<TSlotNames extends string> = UniformSlotProps<TSlotNames>;
|
|
|
504
504
|
/** @deprecated use `UniformSlot` instead */
|
|
505
505
|
declare const Slot: typeof UniformSlot;
|
|
506
506
|
|
|
507
|
+
type ParameterTextValue = string | undefined;
|
|
508
|
+
type UniformTextProps = {
|
|
509
|
+
/**
|
|
510
|
+
* The name of the HTML tag to render.
|
|
511
|
+
* @default "span"
|
|
512
|
+
*/
|
|
513
|
+
as?: React$1.ElementType;
|
|
514
|
+
/** The ID of the parameter. */
|
|
515
|
+
parameterId: string;
|
|
516
|
+
/**
|
|
517
|
+
* When set to true, it adds `whiteSpace: 'pre-wrap'` to the styles of the root element to allow the rendering of line breaks.
|
|
518
|
+
* @default false
|
|
519
|
+
*/
|
|
520
|
+
isMultiline?: boolean;
|
|
521
|
+
/**
|
|
522
|
+
* A function to customize the rendering of the parameter value. Useful to format the value before rendering it.
|
|
523
|
+
* @default "(value) => value"
|
|
524
|
+
*/
|
|
525
|
+
render?: (value: ParameterTextValue) => React$1.ReactNode;
|
|
526
|
+
} & Omit<React$1.HTMLAttributes<HTMLSpanElement>, 'children'>;
|
|
527
|
+
declare const UniformText: ({ as: Tag, parameterId, isMultiline, render, ...props }: UniformTextProps) => JSX.Element;
|
|
528
|
+
|
|
507
529
|
type UseCompositionEventEffectOptions = Omit<Partial<SubscribeToCompositionOptions>, 'callback'> & {
|
|
508
530
|
enabled: boolean;
|
|
509
531
|
effect: () => void;
|
|
@@ -527,4 +549,4 @@ declare const createComponentStoreResolver: (options: {
|
|
|
527
549
|
defaultComponent?: React$1.ComponentType<ComponentProps<any>>;
|
|
528
550
|
}) => RenderComponentResolver;
|
|
529
551
|
|
|
530
|
-
export { ComponentProps, ComponentStore, Composition, CompositionProps, DefaultNotImplementedComponent, NOT_IMPLEMENTED_COMPONENT, RenderComponentResolver, Slot, SlotProps, SystemRenderConfig, SystemRenderFunction, UniformComponent, UniformComponentContextValue, UniformComponentProps, UniformComposition, UniformCompositionProps, UniformSlot, UniformSlotProps, UseCompositionEventEffectOptions, UseContextualEditingProps, UseUniformContextualEditingProps, componentStore, componentStoreResolver, createApiEnhancer, createComponentStore, createComponentStoreResolver, registerUniformComponent, useComposition, useCompositionEventEffect, useContextualEditing, useUniformContextualEditing, useUniformCurrentComponent, useUniformCurrentComposition };
|
|
552
|
+
export { ComponentProps, ComponentStore, Composition, CompositionProps, DefaultNotImplementedComponent, NOT_IMPLEMENTED_COMPONENT, RenderComponentResolver, Slot, SlotProps, SystemRenderConfig, SystemRenderFunction, UniformComponent, UniformComponentContextValue, UniformComponentProps, UniformComposition, UniformCompositionProps, UniformSlot, UniformSlotProps, UniformText, UniformTextProps, UseCompositionEventEffectOptions, UseContextualEditingProps, UseUniformContextualEditingProps, componentStore, componentStoreResolver, createApiEnhancer, createComponentStore, createComponentStoreResolver, registerUniformComponent, useComposition, useCompositionEventEffect, useContextualEditing, useUniformContextualEditing, useUniformCurrentComponent, useUniformCurrentComposition };
|
package/dist/index.esm.js
CHANGED
|
@@ -64,7 +64,8 @@ var createComponentStore = () => {
|
|
|
64
64
|
components.set(getTypeWithVariant(type, variantId), component);
|
|
65
65
|
},
|
|
66
66
|
get: (type, variantId) => {
|
|
67
|
-
|
|
67
|
+
var _a;
|
|
68
|
+
return (_a = components.get(getTypeWithVariant(type, variantId))) != null ? _a : components.get(getTypeWithVariant(type));
|
|
68
69
|
}
|
|
69
70
|
};
|
|
70
71
|
};
|
|
@@ -162,7 +163,7 @@ import {
|
|
|
162
163
|
EMPTY_COMPOSITION,
|
|
163
164
|
IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
|
|
164
165
|
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
|
|
165
|
-
|
|
166
|
+
isUpdateCompositionInternalMessage
|
|
166
167
|
} from "@uniformdev/canvas";
|
|
167
168
|
import { useEffect, useMemo, useState } from "react";
|
|
168
169
|
var createApiEnhancer = createUniformApiEnhancer;
|
|
@@ -191,8 +192,8 @@ var useUniformContextualEditing = ({
|
|
|
191
192
|
if (!channel || registeredCompositionIds.has(initialCompositionValue == null ? void 0 : initialCompositionValue._id)) {
|
|
192
193
|
return;
|
|
193
194
|
}
|
|
194
|
-
const unsubscribeFromCompositionUpdates = channel.on("update-composition", async (message) => {
|
|
195
|
-
if (!
|
|
195
|
+
const unsubscribeFromCompositionUpdates = channel.on("update-composition-internal", async (message) => {
|
|
196
|
+
if (!isUpdateCompositionInternalMessage(message)) {
|
|
196
197
|
return;
|
|
197
198
|
}
|
|
198
199
|
const enhancedComposition = await enhance(message);
|
|
@@ -369,7 +370,7 @@ function renderComponent({
|
|
|
369
370
|
}) {
|
|
370
371
|
const RenderComponent = resolveRenderer == null ? void 0 : resolveRenderer(component);
|
|
371
372
|
if (component.type === CANVAS_TEST_TYPE) {
|
|
372
|
-
|
|
373
|
+
const testComponent = resolveSystem.test(
|
|
373
374
|
component,
|
|
374
375
|
key,
|
|
375
376
|
(variantComponent, key2) => {
|
|
@@ -388,8 +389,20 @@ function renderComponent({
|
|
|
388
389
|
});
|
|
389
390
|
}
|
|
390
391
|
);
|
|
392
|
+
return /* @__PURE__ */ React5.createElement(
|
|
393
|
+
ContextualEditingComponentWrapper,
|
|
394
|
+
{
|
|
395
|
+
component,
|
|
396
|
+
parentComponent,
|
|
397
|
+
slotName,
|
|
398
|
+
indexInSlot,
|
|
399
|
+
slotChildrenCount,
|
|
400
|
+
emptyPlaceholder
|
|
401
|
+
},
|
|
402
|
+
testComponent
|
|
403
|
+
);
|
|
391
404
|
} else if (component.type === CANVAS_PERSONALIZE_TYPE) {
|
|
392
|
-
|
|
405
|
+
const personalizationComponent = resolveSystem.personalization(
|
|
393
406
|
component,
|
|
394
407
|
key,
|
|
395
408
|
(variantComponent, key2) => {
|
|
@@ -408,6 +421,18 @@ function renderComponent({
|
|
|
408
421
|
});
|
|
409
422
|
}
|
|
410
423
|
);
|
|
424
|
+
return /* @__PURE__ */ React5.createElement(
|
|
425
|
+
ContextualEditingComponentWrapper,
|
|
426
|
+
{
|
|
427
|
+
component,
|
|
428
|
+
parentComponent,
|
|
429
|
+
slotName,
|
|
430
|
+
indexInSlot,
|
|
431
|
+
slotChildrenCount,
|
|
432
|
+
emptyPlaceholder
|
|
433
|
+
},
|
|
434
|
+
personalizationComponent
|
|
435
|
+
);
|
|
411
436
|
} else if (RenderComponent) {
|
|
412
437
|
const props = convertComponentToProps(component);
|
|
413
438
|
return /* @__PURE__ */ React5.createElement(UniformComponent, { key, data: component, resolveRenderer }, /* @__PURE__ */ React5.createElement(
|
|
@@ -495,6 +520,55 @@ function resolveChildren({
|
|
|
495
520
|
return renderChildren;
|
|
496
521
|
}
|
|
497
522
|
|
|
523
|
+
// src/components/UniformText.tsx
|
|
524
|
+
import React7, { useCallback, useMemo as useMemo2, useRef, useState as useState2 } from "react";
|
|
525
|
+
var UniformText = ({
|
|
526
|
+
as: Tag = "span",
|
|
527
|
+
parameterId,
|
|
528
|
+
isMultiline = false,
|
|
529
|
+
render = (value) => value,
|
|
530
|
+
...props
|
|
531
|
+
}) => {
|
|
532
|
+
const { data: componentData } = useUniformCurrentComponent();
|
|
533
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
534
|
+
const elementRef = useRef(null);
|
|
535
|
+
const [isFocused, setIsFocused] = useState2(false);
|
|
536
|
+
const value = useMemo2(() => {
|
|
537
|
+
var _a;
|
|
538
|
+
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId].value;
|
|
539
|
+
}, [componentData, parameterId]);
|
|
540
|
+
const isEditable = useMemo2(() => {
|
|
541
|
+
var _a, _b, _c;
|
|
542
|
+
return (_c = (_b = ((_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId])._contextualEditing) == null ? void 0 : _b.isEditable) != null ? _c : false;
|
|
543
|
+
}, [componentData, parameterId]);
|
|
544
|
+
const handleOnFocus = useCallback(() => {
|
|
545
|
+
setIsFocused(true);
|
|
546
|
+
}, [setIsFocused]);
|
|
547
|
+
const handleOnBlur = useCallback(() => {
|
|
548
|
+
setIsFocused(false);
|
|
549
|
+
}, [setIsFocused]);
|
|
550
|
+
const shouldSkipCustomRendering = useMemo2(() => isFocused && isEditable, [isFocused, isEditable]);
|
|
551
|
+
if (!isContextualEditing) {
|
|
552
|
+
return /* @__PURE__ */ React7.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
553
|
+
}
|
|
554
|
+
return /* @__PURE__ */ React7.createElement(
|
|
555
|
+
Tag,
|
|
556
|
+
{
|
|
557
|
+
...props,
|
|
558
|
+
ref: elementRef,
|
|
559
|
+
"data-uniform-component-id": componentData == null ? void 0 : componentData._id,
|
|
560
|
+
"data-uniform-parameter-id": parameterId,
|
|
561
|
+
"data-uniform-parameter-type": "text",
|
|
562
|
+
style: isMultiline ? { whiteSpace: "pre-wrap" } : {},
|
|
563
|
+
contentEditable: isEditable,
|
|
564
|
+
suppressContentEditableWarning: true,
|
|
565
|
+
onFocus: handleOnFocus,
|
|
566
|
+
onBlur: handleOnBlur
|
|
567
|
+
},
|
|
568
|
+
shouldSkipCustomRendering ? value : render(value)
|
|
569
|
+
);
|
|
570
|
+
};
|
|
571
|
+
|
|
498
572
|
// src/hooks/useCompositionEventEffect.ts
|
|
499
573
|
import {
|
|
500
574
|
CANVAS_DRAFT_STATE,
|
|
@@ -542,6 +616,7 @@ export {
|
|
|
542
616
|
UniformComponent,
|
|
543
617
|
UniformComposition,
|
|
544
618
|
UniformSlot,
|
|
619
|
+
UniformText,
|
|
545
620
|
componentStore,
|
|
546
621
|
componentStoreResolver,
|
|
547
622
|
createApiEnhancer,
|
package/dist/index.js
CHANGED
|
@@ -37,6 +37,7 @@ __export(src_exports, {
|
|
|
37
37
|
UniformComponent: () => UniformComponent,
|
|
38
38
|
UniformComposition: () => UniformComposition,
|
|
39
39
|
UniformSlot: () => UniformSlot,
|
|
40
|
+
UniformText: () => UniformText,
|
|
40
41
|
componentStore: () => componentStore,
|
|
41
42
|
componentStoreResolver: () => componentStoreResolver,
|
|
42
43
|
createApiEnhancer: () => createApiEnhancer,
|
|
@@ -117,7 +118,8 @@ var createComponentStore = () => {
|
|
|
117
118
|
components.set(getTypeWithVariant(type, variantId), component);
|
|
118
119
|
},
|
|
119
120
|
get: (type, variantId) => {
|
|
120
|
-
|
|
121
|
+
var _a;
|
|
122
|
+
return (_a = components.get(getTypeWithVariant(type, variantId))) != null ? _a : components.get(getTypeWithVariant(type));
|
|
121
123
|
}
|
|
122
124
|
};
|
|
123
125
|
};
|
|
@@ -224,8 +226,8 @@ var useUniformContextualEditing = ({
|
|
|
224
226
|
if (!channel || registeredCompositionIds.has(initialCompositionValue == null ? void 0 : initialCompositionValue._id)) {
|
|
225
227
|
return;
|
|
226
228
|
}
|
|
227
|
-
const unsubscribeFromCompositionUpdates = channel.on("update-composition", async (message) => {
|
|
228
|
-
if (!(0, import_canvas3.
|
|
229
|
+
const unsubscribeFromCompositionUpdates = channel.on("update-composition-internal", async (message) => {
|
|
230
|
+
if (!(0, import_canvas3.isUpdateCompositionInternalMessage)(message)) {
|
|
229
231
|
return;
|
|
230
232
|
}
|
|
231
233
|
const enhancedComposition = await enhance(message);
|
|
@@ -402,7 +404,7 @@ function renderComponent({
|
|
|
402
404
|
}) {
|
|
403
405
|
const RenderComponent = resolveRenderer == null ? void 0 : resolveRenderer(component);
|
|
404
406
|
if (component.type === import_canvas5.CANVAS_TEST_TYPE) {
|
|
405
|
-
|
|
407
|
+
const testComponent = resolveSystem.test(
|
|
406
408
|
component,
|
|
407
409
|
key,
|
|
408
410
|
(variantComponent, key2) => {
|
|
@@ -421,8 +423,20 @@ function renderComponent({
|
|
|
421
423
|
});
|
|
422
424
|
}
|
|
423
425
|
);
|
|
426
|
+
return /* @__PURE__ */ import_react5.default.createElement(
|
|
427
|
+
ContextualEditingComponentWrapper,
|
|
428
|
+
{
|
|
429
|
+
component,
|
|
430
|
+
parentComponent,
|
|
431
|
+
slotName,
|
|
432
|
+
indexInSlot,
|
|
433
|
+
slotChildrenCount,
|
|
434
|
+
emptyPlaceholder
|
|
435
|
+
},
|
|
436
|
+
testComponent
|
|
437
|
+
);
|
|
424
438
|
} else if (component.type === import_canvas5.CANVAS_PERSONALIZE_TYPE) {
|
|
425
|
-
|
|
439
|
+
const personalizationComponent = resolveSystem.personalization(
|
|
426
440
|
component,
|
|
427
441
|
key,
|
|
428
442
|
(variantComponent, key2) => {
|
|
@@ -441,6 +455,18 @@ function renderComponent({
|
|
|
441
455
|
});
|
|
442
456
|
}
|
|
443
457
|
);
|
|
458
|
+
return /* @__PURE__ */ import_react5.default.createElement(
|
|
459
|
+
ContextualEditingComponentWrapper,
|
|
460
|
+
{
|
|
461
|
+
component,
|
|
462
|
+
parentComponent,
|
|
463
|
+
slotName,
|
|
464
|
+
indexInSlot,
|
|
465
|
+
slotChildrenCount,
|
|
466
|
+
emptyPlaceholder
|
|
467
|
+
},
|
|
468
|
+
personalizationComponent
|
|
469
|
+
);
|
|
444
470
|
} else if (RenderComponent) {
|
|
445
471
|
const props = convertComponentToProps(component);
|
|
446
472
|
return /* @__PURE__ */ import_react5.default.createElement(UniformComponent, { key, data: component, resolveRenderer }, /* @__PURE__ */ import_react5.default.createElement(
|
|
@@ -528,16 +554,65 @@ function resolveChildren({
|
|
|
528
554
|
return renderChildren;
|
|
529
555
|
}
|
|
530
556
|
|
|
557
|
+
// src/components/UniformText.tsx
|
|
558
|
+
var import_react7 = __toESM(require("react"));
|
|
559
|
+
var UniformText = ({
|
|
560
|
+
as: Tag = "span",
|
|
561
|
+
parameterId,
|
|
562
|
+
isMultiline = false,
|
|
563
|
+
render = (value) => value,
|
|
564
|
+
...props
|
|
565
|
+
}) => {
|
|
566
|
+
const { data: componentData } = useUniformCurrentComponent();
|
|
567
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
568
|
+
const elementRef = (0, import_react7.useRef)(null);
|
|
569
|
+
const [isFocused, setIsFocused] = (0, import_react7.useState)(false);
|
|
570
|
+
const value = (0, import_react7.useMemo)(() => {
|
|
571
|
+
var _a;
|
|
572
|
+
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId].value;
|
|
573
|
+
}, [componentData, parameterId]);
|
|
574
|
+
const isEditable = (0, import_react7.useMemo)(() => {
|
|
575
|
+
var _a, _b, _c;
|
|
576
|
+
return (_c = (_b = ((_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId])._contextualEditing) == null ? void 0 : _b.isEditable) != null ? _c : false;
|
|
577
|
+
}, [componentData, parameterId]);
|
|
578
|
+
const handleOnFocus = (0, import_react7.useCallback)(() => {
|
|
579
|
+
setIsFocused(true);
|
|
580
|
+
}, [setIsFocused]);
|
|
581
|
+
const handleOnBlur = (0, import_react7.useCallback)(() => {
|
|
582
|
+
setIsFocused(false);
|
|
583
|
+
}, [setIsFocused]);
|
|
584
|
+
const shouldSkipCustomRendering = (0, import_react7.useMemo)(() => isFocused && isEditable, [isFocused, isEditable]);
|
|
585
|
+
if (!isContextualEditing) {
|
|
586
|
+
return /* @__PURE__ */ import_react7.default.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
587
|
+
}
|
|
588
|
+
return /* @__PURE__ */ import_react7.default.createElement(
|
|
589
|
+
Tag,
|
|
590
|
+
{
|
|
591
|
+
...props,
|
|
592
|
+
ref: elementRef,
|
|
593
|
+
"data-uniform-component-id": componentData == null ? void 0 : componentData._id,
|
|
594
|
+
"data-uniform-parameter-id": parameterId,
|
|
595
|
+
"data-uniform-parameter-type": "text",
|
|
596
|
+
style: isMultiline ? { whiteSpace: "pre-wrap" } : {},
|
|
597
|
+
contentEditable: isEditable,
|
|
598
|
+
suppressContentEditableWarning: true,
|
|
599
|
+
onFocus: handleOnFocus,
|
|
600
|
+
onBlur: handleOnBlur
|
|
601
|
+
},
|
|
602
|
+
shouldSkipCustomRendering ? value : render(value)
|
|
603
|
+
);
|
|
604
|
+
};
|
|
605
|
+
|
|
531
606
|
// src/hooks/useCompositionEventEffect.ts
|
|
532
607
|
var import_canvas7 = require("@uniformdev/canvas");
|
|
533
|
-
var
|
|
608
|
+
var import_react8 = require("react");
|
|
534
609
|
function useCompositionEventEffect({
|
|
535
610
|
enabled,
|
|
536
611
|
projectId,
|
|
537
612
|
compositionId,
|
|
538
613
|
effect
|
|
539
614
|
}) {
|
|
540
|
-
(0,
|
|
615
|
+
(0, import_react8.useEffect)(() => {
|
|
541
616
|
if (!enabled || !compositionId || !projectId) {
|
|
542
617
|
return;
|
|
543
618
|
}
|
|
@@ -572,6 +647,7 @@ function useCompositionEventEffect({
|
|
|
572
647
|
UniformComponent,
|
|
573
648
|
UniformComposition,
|
|
574
649
|
UniformSlot,
|
|
650
|
+
UniformText,
|
|
575
651
|
componentStore,
|
|
576
652
|
componentStoreResolver,
|
|
577
653
|
createApiEnhancer,
|
package/dist/index.mjs
CHANGED
|
@@ -64,7 +64,8 @@ var createComponentStore = () => {
|
|
|
64
64
|
components.set(getTypeWithVariant(type, variantId), component);
|
|
65
65
|
},
|
|
66
66
|
get: (type, variantId) => {
|
|
67
|
-
|
|
67
|
+
var _a;
|
|
68
|
+
return (_a = components.get(getTypeWithVariant(type, variantId))) != null ? _a : components.get(getTypeWithVariant(type));
|
|
68
69
|
}
|
|
69
70
|
};
|
|
70
71
|
};
|
|
@@ -162,7 +163,7 @@ import {
|
|
|
162
163
|
EMPTY_COMPOSITION,
|
|
163
164
|
IN_CONTEXT_EDITOR_EMBED_SCRIPT_ID,
|
|
164
165
|
IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
|
|
165
|
-
|
|
166
|
+
isUpdateCompositionInternalMessage
|
|
166
167
|
} from "@uniformdev/canvas";
|
|
167
168
|
import { useEffect, useMemo, useState } from "react";
|
|
168
169
|
var createApiEnhancer = createUniformApiEnhancer;
|
|
@@ -191,8 +192,8 @@ var useUniformContextualEditing = ({
|
|
|
191
192
|
if (!channel || registeredCompositionIds.has(initialCompositionValue == null ? void 0 : initialCompositionValue._id)) {
|
|
192
193
|
return;
|
|
193
194
|
}
|
|
194
|
-
const unsubscribeFromCompositionUpdates = channel.on("update-composition", async (message) => {
|
|
195
|
-
if (!
|
|
195
|
+
const unsubscribeFromCompositionUpdates = channel.on("update-composition-internal", async (message) => {
|
|
196
|
+
if (!isUpdateCompositionInternalMessage(message)) {
|
|
196
197
|
return;
|
|
197
198
|
}
|
|
198
199
|
const enhancedComposition = await enhance(message);
|
|
@@ -369,7 +370,7 @@ function renderComponent({
|
|
|
369
370
|
}) {
|
|
370
371
|
const RenderComponent = resolveRenderer == null ? void 0 : resolveRenderer(component);
|
|
371
372
|
if (component.type === CANVAS_TEST_TYPE) {
|
|
372
|
-
|
|
373
|
+
const testComponent = resolveSystem.test(
|
|
373
374
|
component,
|
|
374
375
|
key,
|
|
375
376
|
(variantComponent, key2) => {
|
|
@@ -388,8 +389,20 @@ function renderComponent({
|
|
|
388
389
|
});
|
|
389
390
|
}
|
|
390
391
|
);
|
|
392
|
+
return /* @__PURE__ */ React5.createElement(
|
|
393
|
+
ContextualEditingComponentWrapper,
|
|
394
|
+
{
|
|
395
|
+
component,
|
|
396
|
+
parentComponent,
|
|
397
|
+
slotName,
|
|
398
|
+
indexInSlot,
|
|
399
|
+
slotChildrenCount,
|
|
400
|
+
emptyPlaceholder
|
|
401
|
+
},
|
|
402
|
+
testComponent
|
|
403
|
+
);
|
|
391
404
|
} else if (component.type === CANVAS_PERSONALIZE_TYPE) {
|
|
392
|
-
|
|
405
|
+
const personalizationComponent = resolveSystem.personalization(
|
|
393
406
|
component,
|
|
394
407
|
key,
|
|
395
408
|
(variantComponent, key2) => {
|
|
@@ -408,6 +421,18 @@ function renderComponent({
|
|
|
408
421
|
});
|
|
409
422
|
}
|
|
410
423
|
);
|
|
424
|
+
return /* @__PURE__ */ React5.createElement(
|
|
425
|
+
ContextualEditingComponentWrapper,
|
|
426
|
+
{
|
|
427
|
+
component,
|
|
428
|
+
parentComponent,
|
|
429
|
+
slotName,
|
|
430
|
+
indexInSlot,
|
|
431
|
+
slotChildrenCount,
|
|
432
|
+
emptyPlaceholder
|
|
433
|
+
},
|
|
434
|
+
personalizationComponent
|
|
435
|
+
);
|
|
411
436
|
} else if (RenderComponent) {
|
|
412
437
|
const props = convertComponentToProps(component);
|
|
413
438
|
return /* @__PURE__ */ React5.createElement(UniformComponent, { key, data: component, resolveRenderer }, /* @__PURE__ */ React5.createElement(
|
|
@@ -495,6 +520,55 @@ function resolveChildren({
|
|
|
495
520
|
return renderChildren;
|
|
496
521
|
}
|
|
497
522
|
|
|
523
|
+
// src/components/UniformText.tsx
|
|
524
|
+
import React7, { useCallback, useMemo as useMemo2, useRef, useState as useState2 } from "react";
|
|
525
|
+
var UniformText = ({
|
|
526
|
+
as: Tag = "span",
|
|
527
|
+
parameterId,
|
|
528
|
+
isMultiline = false,
|
|
529
|
+
render = (value) => value,
|
|
530
|
+
...props
|
|
531
|
+
}) => {
|
|
532
|
+
const { data: componentData } = useUniformCurrentComponent();
|
|
533
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
534
|
+
const elementRef = useRef(null);
|
|
535
|
+
const [isFocused, setIsFocused] = useState2(false);
|
|
536
|
+
const value = useMemo2(() => {
|
|
537
|
+
var _a;
|
|
538
|
+
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId].value;
|
|
539
|
+
}, [componentData, parameterId]);
|
|
540
|
+
const isEditable = useMemo2(() => {
|
|
541
|
+
var _a, _b, _c;
|
|
542
|
+
return (_c = (_b = ((_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId])._contextualEditing) == null ? void 0 : _b.isEditable) != null ? _c : false;
|
|
543
|
+
}, [componentData, parameterId]);
|
|
544
|
+
const handleOnFocus = useCallback(() => {
|
|
545
|
+
setIsFocused(true);
|
|
546
|
+
}, [setIsFocused]);
|
|
547
|
+
const handleOnBlur = useCallback(() => {
|
|
548
|
+
setIsFocused(false);
|
|
549
|
+
}, [setIsFocused]);
|
|
550
|
+
const shouldSkipCustomRendering = useMemo2(() => isFocused && isEditable, [isFocused, isEditable]);
|
|
551
|
+
if (!isContextualEditing) {
|
|
552
|
+
return /* @__PURE__ */ React7.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
553
|
+
}
|
|
554
|
+
return /* @__PURE__ */ React7.createElement(
|
|
555
|
+
Tag,
|
|
556
|
+
{
|
|
557
|
+
...props,
|
|
558
|
+
ref: elementRef,
|
|
559
|
+
"data-uniform-component-id": componentData == null ? void 0 : componentData._id,
|
|
560
|
+
"data-uniform-parameter-id": parameterId,
|
|
561
|
+
"data-uniform-parameter-type": "text",
|
|
562
|
+
style: isMultiline ? { whiteSpace: "pre-wrap" } : {},
|
|
563
|
+
contentEditable: isEditable,
|
|
564
|
+
suppressContentEditableWarning: true,
|
|
565
|
+
onFocus: handleOnFocus,
|
|
566
|
+
onBlur: handleOnBlur
|
|
567
|
+
},
|
|
568
|
+
shouldSkipCustomRendering ? value : render(value)
|
|
569
|
+
);
|
|
570
|
+
};
|
|
571
|
+
|
|
498
572
|
// src/hooks/useCompositionEventEffect.ts
|
|
499
573
|
import {
|
|
500
574
|
CANVAS_DRAFT_STATE,
|
|
@@ -542,6 +616,7 @@ export {
|
|
|
542
616
|
UniformComponent,
|
|
543
617
|
UniformComposition,
|
|
544
618
|
UniformSlot,
|
|
619
|
+
UniformText,
|
|
545
620
|
componentStore,
|
|
546
621
|
componentStoreResolver,
|
|
547
622
|
createApiEnhancer,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-react",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.35.1-alpha.16+3d99d8fd6",
|
|
4
4
|
"description": "React SDK for Uniform Canvas",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"document": "api-extractor run --local"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@uniformdev/canvas": "18.
|
|
28
|
-
"@uniformdev/context": "18.
|
|
29
|
-
"@uniformdev/context-react": "18.
|
|
27
|
+
"@uniformdev/canvas": "18.35.1-alpha.16+3d99d8fd6",
|
|
28
|
+
"@uniformdev/context": "18.35.1-alpha.16+3d99d8fd6",
|
|
29
|
+
"@uniformdev/context-react": "18.35.1-alpha.16+3d99d8fd6"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"react": ">= 16 || 17 || 18",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "3d99d8fd68048310f8f6dc56a1d18e61c35c9765"
|
|
47
47
|
}
|