@uniformdev/canvas-react 19.0.0 → 19.1.1-alpha.1
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 +28 -2
- package/dist/index.esm.js +91 -8
- package/dist/index.js +91 -8
- package/dist/index.mjs +91 -8
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -80,7 +80,7 @@ type UseUniformContextualEditingProps = {
|
|
|
80
80
|
* A function to enhance the composition after receiving it from Canvas editor.
|
|
81
81
|
* 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.
|
|
82
82
|
*/
|
|
83
|
-
enhance?: (composition: UpdateCompositionMessage) => RootComponentInstance | Promise<RootComponentInstance>;
|
|
83
|
+
enhance?: ({ composition, hash, }: Pick<UpdateCompositionMessage, 'composition' | 'hash'>) => RootComponentInstance | Promise<RootComponentInstance>;
|
|
84
84
|
};
|
|
85
85
|
/**
|
|
86
86
|
* Adds contextual editing capability to a Uniform app.
|
|
@@ -253,6 +253,32 @@ type UniformSlotProps<TSlotNames extends string> = {
|
|
|
253
253
|
/** Renders a named Slot within a Composition. */
|
|
254
254
|
declare function UniformSlot<TSlotNames extends string = string>({ name, resolveRenderer, children, emptyPlaceholder, }: UniformSlotProps<TSlotNames>): JSX.Element | null;
|
|
255
255
|
|
|
256
|
+
type ParameterTextValue = string | undefined;
|
|
257
|
+
type UniformTextProps = {
|
|
258
|
+
/**
|
|
259
|
+
* The name of the HTML tag to render.
|
|
260
|
+
* @default "span"
|
|
261
|
+
*/
|
|
262
|
+
as?: React$1.ElementType;
|
|
263
|
+
/** The ID of the parameter. */
|
|
264
|
+
parameterId: string;
|
|
265
|
+
/**
|
|
266
|
+
* When set to true, it adds `whiteSpace: 'pre-wrap'` to the styles of the root element to allow the rendering of line breaks.
|
|
267
|
+
* @default false
|
|
268
|
+
*/
|
|
269
|
+
isMultiline?: boolean;
|
|
270
|
+
/**
|
|
271
|
+
* A function to customize the rendering of the parameter value. Useful to format the value before rendering it.
|
|
272
|
+
* @default "(value) => value"
|
|
273
|
+
*/
|
|
274
|
+
render?: (value: ParameterTextValue) => React$1.ReactNode;
|
|
275
|
+
} & Omit<React$1.HTMLAttributes<HTMLSpanElement>, 'children'>;
|
|
276
|
+
/**
|
|
277
|
+
* Adds inline editing capability to text parameters
|
|
278
|
+
* @deprecated This component is unstable, and not ready for production usage.
|
|
279
|
+
**/
|
|
280
|
+
declare const UniformText: ({ as: Tag, parameterId, isMultiline, render, ...props }: UniformTextProps) => JSX.Element | null;
|
|
281
|
+
|
|
256
282
|
type UseCompositionEventEffectOptions = Omit<Partial<SubscribeToCompositionOptions>, 'callback'> & {
|
|
257
283
|
enabled: boolean;
|
|
258
284
|
effect: () => void;
|
|
@@ -276,4 +302,4 @@ declare const createComponentStoreResolver: (options: {
|
|
|
276
302
|
defaultComponent?: React$1.ComponentType<ComponentProps<any>>;
|
|
277
303
|
}) => RenderComponentResolver;
|
|
278
304
|
|
|
279
|
-
export { ComponentProps, ComponentStore, DefaultNotImplementedComponent, NOT_IMPLEMENTED_COMPONENT, RenderComponentResolver, SystemRenderConfig, SystemRenderFunction, UniformComponent, UniformComponentContextValue, UniformComponentProps, UniformComposition, UniformCompositionProps, UniformSlot, UniformSlotProps, UseCompositionEventEffectOptions, UseUniformContextualEditingProps, componentStore, componentStoreResolver, createComponentStore, createComponentStoreResolver, registerUniformComponent, useCompositionEventEffect, useUniformContextualEditing, useUniformCurrentComponent, useUniformCurrentComposition };
|
|
305
|
+
export { ComponentProps, ComponentStore, DefaultNotImplementedComponent, NOT_IMPLEMENTED_COMPONENT, RenderComponentResolver, SystemRenderConfig, SystemRenderFunction, UniformComponent, UniformComponentContextValue, UniformComponentProps, UniformComposition, UniformCompositionProps, UniformSlot, UniformSlotProps, UniformText, UniformTextProps, UseCompositionEventEffectOptions, UseUniformContextualEditingProps, componentStore, componentStoreResolver, createComponentStore, createComponentStoreResolver, registerUniformComponent, useCompositionEventEffect, useUniformContextualEditing, useUniformCurrentComponent, useUniformCurrentComposition };
|
package/dist/index.esm.js
CHANGED
|
@@ -98,7 +98,8 @@ import {
|
|
|
98
98
|
CANVAS_PERSONALIZE_SLOT,
|
|
99
99
|
CANVAS_PERSONALIZE_TYPE,
|
|
100
100
|
CANVAS_TEST_SLOT,
|
|
101
|
-
CANVAS_TEST_TYPE
|
|
101
|
+
CANVAS_TEST_TYPE,
|
|
102
|
+
EMPTY_COMPOSITION as EMPTY_COMPOSITION2
|
|
102
103
|
} from "@uniformdev/canvas";
|
|
103
104
|
import React5 from "react";
|
|
104
105
|
|
|
@@ -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 registeredCompositionIds = /* @__PURE__ */ new Set();
|
|
@@ -190,8 +191,8 @@ var useUniformContextualEditing = ({
|
|
|
190
191
|
if (!channel || registeredCompositionIds.has(initialCompositionValue == null ? void 0 : initialCompositionValue._id)) {
|
|
191
192
|
return;
|
|
192
193
|
}
|
|
193
|
-
const unsubscribeFromCompositionUpdates = channel.on("update-composition", async (message) => {
|
|
194
|
-
if (!
|
|
194
|
+
const unsubscribeFromCompositionUpdates = channel.on("update-composition-internal", async (message) => {
|
|
195
|
+
if (!isUpdateCompositionInternalMessage(message)) {
|
|
195
196
|
return;
|
|
196
197
|
}
|
|
197
198
|
const enhancedComposition = await enhance(message);
|
|
@@ -293,7 +294,7 @@ function ContextualEditingComponentWrapper({
|
|
|
293
294
|
var _a, _b, _c, _d;
|
|
294
295
|
const isPlaceholder = (component == null ? void 0 : component._id) === PLACEHOLDER_ID;
|
|
295
296
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
296
|
-
return !isContextualEditing ? /* @__PURE__ */ React4.createElement(React4.Fragment, null, children) : /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(
|
|
297
|
+
return !isContextualEditing ? /* @__PURE__ */ React4.createElement(React4.Fragment, null, children) : isPlaceholder && emptyPlaceholder === null ? null : /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(
|
|
297
298
|
"script",
|
|
298
299
|
{
|
|
299
300
|
"data-role": IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
|
@@ -325,7 +326,7 @@ function UniformSlot({
|
|
|
325
326
|
}
|
|
326
327
|
const slot = (_a = parentData.slots) == null ? void 0 : _a[name];
|
|
327
328
|
if (!slot || !Array.isArray(slot)) {
|
|
328
|
-
if (process.env.NODE_ENV === "development") {
|
|
329
|
+
if (process.env.NODE_ENV === "development" && parentData.type !== EMPTY_COMPOSITION2.type) {
|
|
329
330
|
console.warn(
|
|
330
331
|
`[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:`,
|
|
331
332
|
parentData
|
|
@@ -365,7 +366,7 @@ function renderComponent({
|
|
|
365
366
|
}) {
|
|
366
367
|
const RenderComponent = resolveRenderer == null ? void 0 : resolveRenderer(component);
|
|
367
368
|
if (component.type === CANVAS_TEST_TYPE) {
|
|
368
|
-
|
|
369
|
+
const testComponent = resolveSystem.test(
|
|
369
370
|
component,
|
|
370
371
|
key,
|
|
371
372
|
(variantComponent, key2) => {
|
|
@@ -384,8 +385,20 @@ function renderComponent({
|
|
|
384
385
|
});
|
|
385
386
|
}
|
|
386
387
|
);
|
|
388
|
+
return /* @__PURE__ */ React5.createElement(
|
|
389
|
+
ContextualEditingComponentWrapper,
|
|
390
|
+
{
|
|
391
|
+
component,
|
|
392
|
+
parentComponent,
|
|
393
|
+
slotName,
|
|
394
|
+
indexInSlot,
|
|
395
|
+
slotChildrenCount,
|
|
396
|
+
emptyPlaceholder
|
|
397
|
+
},
|
|
398
|
+
testComponent
|
|
399
|
+
);
|
|
387
400
|
} else if (component.type === CANVAS_PERSONALIZE_TYPE) {
|
|
388
|
-
|
|
401
|
+
const personalizationComponent = resolveSystem.personalization(
|
|
389
402
|
component,
|
|
390
403
|
key,
|
|
391
404
|
(variantComponent, key2) => {
|
|
@@ -404,6 +417,18 @@ function renderComponent({
|
|
|
404
417
|
});
|
|
405
418
|
}
|
|
406
419
|
);
|
|
420
|
+
return /* @__PURE__ */ React5.createElement(
|
|
421
|
+
ContextualEditingComponentWrapper,
|
|
422
|
+
{
|
|
423
|
+
component,
|
|
424
|
+
parentComponent,
|
|
425
|
+
slotName,
|
|
426
|
+
indexInSlot,
|
|
427
|
+
slotChildrenCount,
|
|
428
|
+
emptyPlaceholder
|
|
429
|
+
},
|
|
430
|
+
personalizationComponent
|
|
431
|
+
);
|
|
407
432
|
} else if (RenderComponent) {
|
|
408
433
|
const props = convertComponentToProps(component);
|
|
409
434
|
return /* @__PURE__ */ React5.createElement(UniformComponent, { key, data: component, resolveRenderer }, /* @__PURE__ */ React5.createElement(
|
|
@@ -490,6 +515,63 @@ function resolveChildren({
|
|
|
490
515
|
return renderChildren;
|
|
491
516
|
}
|
|
492
517
|
|
|
518
|
+
// src/components/UniformText.tsx
|
|
519
|
+
import React7, { useCallback, useMemo as useMemo2, useRef, useState as useState2 } from "react";
|
|
520
|
+
var UniformText = ({
|
|
521
|
+
as: Tag = "span",
|
|
522
|
+
parameterId,
|
|
523
|
+
isMultiline = false,
|
|
524
|
+
render = (value) => value,
|
|
525
|
+
...props
|
|
526
|
+
}) => {
|
|
527
|
+
const { data: componentData } = useUniformCurrentComponent();
|
|
528
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
529
|
+
const elementRef = useRef(null);
|
|
530
|
+
const [isFocused, setIsFocused] = useState2(false);
|
|
531
|
+
const parameter = useMemo2(() => {
|
|
532
|
+
var _a;
|
|
533
|
+
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
534
|
+
}, [componentData, parameterId]);
|
|
535
|
+
const value = useMemo2(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
536
|
+
const isEditable = useMemo2(() => {
|
|
537
|
+
var _a, _b;
|
|
538
|
+
return (_b = (_a = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _a.isEditable) != null ? _b : false;
|
|
539
|
+
}, [parameter]);
|
|
540
|
+
const handleOnFocus = useCallback(() => {
|
|
541
|
+
setIsFocused(true);
|
|
542
|
+
}, [setIsFocused]);
|
|
543
|
+
const handleOnBlur = useCallback(() => {
|
|
544
|
+
setIsFocused(false);
|
|
545
|
+
}, [setIsFocused]);
|
|
546
|
+
const shouldSkipCustomRendering = useMemo2(() => isFocused && isEditable, [isFocused, isEditable]);
|
|
547
|
+
if (!parameter) {
|
|
548
|
+
console.warn(
|
|
549
|
+
`UniformText: The parameterId "${parameterId}" was not found in the component of type "${componentData == null ? void 0 : componentData.type}"`
|
|
550
|
+
);
|
|
551
|
+
return null;
|
|
552
|
+
}
|
|
553
|
+
if (!isContextualEditing) {
|
|
554
|
+
return /* @__PURE__ */ React7.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
555
|
+
}
|
|
556
|
+
return /* @__PURE__ */ React7.createElement(
|
|
557
|
+
Tag,
|
|
558
|
+
{
|
|
559
|
+
...props,
|
|
560
|
+
ref: elementRef,
|
|
561
|
+
"data-uniform-component-id": componentData == null ? void 0 : componentData._id,
|
|
562
|
+
"data-uniform-parameter-id": parameterId,
|
|
563
|
+
"data-uniform-parameter-type": "text",
|
|
564
|
+
"data-uniform-is-multiline": isMultiline,
|
|
565
|
+
style: isMultiline ? { whiteSpace: "pre-wrap" } : {},
|
|
566
|
+
contentEditable: isEditable,
|
|
567
|
+
suppressContentEditableWarning: true,
|
|
568
|
+
onFocus: handleOnFocus,
|
|
569
|
+
onBlur: handleOnBlur
|
|
570
|
+
},
|
|
571
|
+
shouldSkipCustomRendering ? value : render(value)
|
|
572
|
+
);
|
|
573
|
+
};
|
|
574
|
+
|
|
493
575
|
// src/hooks/useCompositionEventEffect.ts
|
|
494
576
|
import {
|
|
495
577
|
CANVAS_DRAFT_STATE,
|
|
@@ -535,6 +617,7 @@ export {
|
|
|
535
617
|
UniformComponent,
|
|
536
618
|
UniformComposition,
|
|
537
619
|
UniformSlot,
|
|
620
|
+
UniformText,
|
|
538
621
|
componentStore,
|
|
539
622
|
componentStoreResolver,
|
|
540
623
|
createComponentStore,
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,7 @@ __export(src_exports, {
|
|
|
35
35
|
UniformComponent: () => UniformComponent,
|
|
36
36
|
UniformComposition: () => UniformComposition,
|
|
37
37
|
UniformSlot: () => UniformSlot,
|
|
38
|
+
UniformText: () => UniformText,
|
|
38
39
|
componentStore: () => componentStore,
|
|
39
40
|
componentStoreResolver: () => componentStoreResolver,
|
|
40
41
|
createComponentStore: () => createComponentStore,
|
|
@@ -218,8 +219,8 @@ var useUniformContextualEditing = ({
|
|
|
218
219
|
if (!channel || registeredCompositionIds.has(initialCompositionValue == null ? void 0 : initialCompositionValue._id)) {
|
|
219
220
|
return;
|
|
220
221
|
}
|
|
221
|
-
const unsubscribeFromCompositionUpdates = channel.on("update-composition", async (message) => {
|
|
222
|
-
if (!(0, import_canvas3.
|
|
222
|
+
const unsubscribeFromCompositionUpdates = channel.on("update-composition-internal", async (message) => {
|
|
223
|
+
if (!(0, import_canvas3.isUpdateCompositionInternalMessage)(message)) {
|
|
223
224
|
return;
|
|
224
225
|
}
|
|
225
226
|
const enhancedComposition = await enhance(message);
|
|
@@ -321,7 +322,7 @@ function ContextualEditingComponentWrapper({
|
|
|
321
322
|
var _a, _b, _c, _d;
|
|
322
323
|
const isPlaceholder = (component == null ? void 0 : component._id) === import_canvas4.PLACEHOLDER_ID;
|
|
323
324
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
324
|
-
return !isContextualEditing ? /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, children) : /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, /* @__PURE__ */ import_react4.default.createElement(
|
|
325
|
+
return !isContextualEditing ? /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, children) : isPlaceholder && emptyPlaceholder === null ? null : /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, /* @__PURE__ */ import_react4.default.createElement(
|
|
325
326
|
"script",
|
|
326
327
|
{
|
|
327
328
|
"data-role": import_canvas4.IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
|
@@ -353,7 +354,7 @@ function UniformSlot({
|
|
|
353
354
|
}
|
|
354
355
|
const slot = (_a = parentData.slots) == null ? void 0 : _a[name];
|
|
355
356
|
if (!slot || !Array.isArray(slot)) {
|
|
356
|
-
if (process.env.NODE_ENV === "development") {
|
|
357
|
+
if (process.env.NODE_ENV === "development" && parentData.type !== import_canvas5.EMPTY_COMPOSITION.type) {
|
|
357
358
|
console.warn(
|
|
358
359
|
`[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:`,
|
|
359
360
|
parentData
|
|
@@ -393,7 +394,7 @@ function renderComponent({
|
|
|
393
394
|
}) {
|
|
394
395
|
const RenderComponent = resolveRenderer == null ? void 0 : resolveRenderer(component);
|
|
395
396
|
if (component.type === import_canvas5.CANVAS_TEST_TYPE) {
|
|
396
|
-
|
|
397
|
+
const testComponent = resolveSystem.test(
|
|
397
398
|
component,
|
|
398
399
|
key,
|
|
399
400
|
(variantComponent, key2) => {
|
|
@@ -412,8 +413,20 @@ function renderComponent({
|
|
|
412
413
|
});
|
|
413
414
|
}
|
|
414
415
|
);
|
|
416
|
+
return /* @__PURE__ */ import_react5.default.createElement(
|
|
417
|
+
ContextualEditingComponentWrapper,
|
|
418
|
+
{
|
|
419
|
+
component,
|
|
420
|
+
parentComponent,
|
|
421
|
+
slotName,
|
|
422
|
+
indexInSlot,
|
|
423
|
+
slotChildrenCount,
|
|
424
|
+
emptyPlaceholder
|
|
425
|
+
},
|
|
426
|
+
testComponent
|
|
427
|
+
);
|
|
415
428
|
} else if (component.type === import_canvas5.CANVAS_PERSONALIZE_TYPE) {
|
|
416
|
-
|
|
429
|
+
const personalizationComponent = resolveSystem.personalization(
|
|
417
430
|
component,
|
|
418
431
|
key,
|
|
419
432
|
(variantComponent, key2) => {
|
|
@@ -432,6 +445,18 @@ function renderComponent({
|
|
|
432
445
|
});
|
|
433
446
|
}
|
|
434
447
|
);
|
|
448
|
+
return /* @__PURE__ */ import_react5.default.createElement(
|
|
449
|
+
ContextualEditingComponentWrapper,
|
|
450
|
+
{
|
|
451
|
+
component,
|
|
452
|
+
parentComponent,
|
|
453
|
+
slotName,
|
|
454
|
+
indexInSlot,
|
|
455
|
+
slotChildrenCount,
|
|
456
|
+
emptyPlaceholder
|
|
457
|
+
},
|
|
458
|
+
personalizationComponent
|
|
459
|
+
);
|
|
435
460
|
} else if (RenderComponent) {
|
|
436
461
|
const props = convertComponentToProps(component);
|
|
437
462
|
return /* @__PURE__ */ import_react5.default.createElement(UniformComponent, { key, data: component, resolveRenderer }, /* @__PURE__ */ import_react5.default.createElement(
|
|
@@ -518,16 +543,73 @@ function resolveChildren({
|
|
|
518
543
|
return renderChildren;
|
|
519
544
|
}
|
|
520
545
|
|
|
546
|
+
// src/components/UniformText.tsx
|
|
547
|
+
var import_react7 = __toESM(require("react"));
|
|
548
|
+
var UniformText = ({
|
|
549
|
+
as: Tag = "span",
|
|
550
|
+
parameterId,
|
|
551
|
+
isMultiline = false,
|
|
552
|
+
render = (value) => value,
|
|
553
|
+
...props
|
|
554
|
+
}) => {
|
|
555
|
+
const { data: componentData } = useUniformCurrentComponent();
|
|
556
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
557
|
+
const elementRef = (0, import_react7.useRef)(null);
|
|
558
|
+
const [isFocused, setIsFocused] = (0, import_react7.useState)(false);
|
|
559
|
+
const parameter = (0, import_react7.useMemo)(() => {
|
|
560
|
+
var _a;
|
|
561
|
+
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
562
|
+
}, [componentData, parameterId]);
|
|
563
|
+
const value = (0, import_react7.useMemo)(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
564
|
+
const isEditable = (0, import_react7.useMemo)(() => {
|
|
565
|
+
var _a, _b;
|
|
566
|
+
return (_b = (_a = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _a.isEditable) != null ? _b : false;
|
|
567
|
+
}, [parameter]);
|
|
568
|
+
const handleOnFocus = (0, import_react7.useCallback)(() => {
|
|
569
|
+
setIsFocused(true);
|
|
570
|
+
}, [setIsFocused]);
|
|
571
|
+
const handleOnBlur = (0, import_react7.useCallback)(() => {
|
|
572
|
+
setIsFocused(false);
|
|
573
|
+
}, [setIsFocused]);
|
|
574
|
+
const shouldSkipCustomRendering = (0, import_react7.useMemo)(() => isFocused && isEditable, [isFocused, isEditable]);
|
|
575
|
+
if (!parameter) {
|
|
576
|
+
console.warn(
|
|
577
|
+
`UniformText: The parameterId "${parameterId}" was not found in the component of type "${componentData == null ? void 0 : componentData.type}"`
|
|
578
|
+
);
|
|
579
|
+
return null;
|
|
580
|
+
}
|
|
581
|
+
if (!isContextualEditing) {
|
|
582
|
+
return /* @__PURE__ */ import_react7.default.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
583
|
+
}
|
|
584
|
+
return /* @__PURE__ */ import_react7.default.createElement(
|
|
585
|
+
Tag,
|
|
586
|
+
{
|
|
587
|
+
...props,
|
|
588
|
+
ref: elementRef,
|
|
589
|
+
"data-uniform-component-id": componentData == null ? void 0 : componentData._id,
|
|
590
|
+
"data-uniform-parameter-id": parameterId,
|
|
591
|
+
"data-uniform-parameter-type": "text",
|
|
592
|
+
"data-uniform-is-multiline": isMultiline,
|
|
593
|
+
style: isMultiline ? { whiteSpace: "pre-wrap" } : {},
|
|
594
|
+
contentEditable: isEditable,
|
|
595
|
+
suppressContentEditableWarning: true,
|
|
596
|
+
onFocus: handleOnFocus,
|
|
597
|
+
onBlur: handleOnBlur
|
|
598
|
+
},
|
|
599
|
+
shouldSkipCustomRendering ? value : render(value)
|
|
600
|
+
);
|
|
601
|
+
};
|
|
602
|
+
|
|
521
603
|
// src/hooks/useCompositionEventEffect.ts
|
|
522
604
|
var import_canvas7 = require("@uniformdev/canvas");
|
|
523
|
-
var
|
|
605
|
+
var import_react8 = require("react");
|
|
524
606
|
function useCompositionEventEffect({
|
|
525
607
|
enabled,
|
|
526
608
|
projectId,
|
|
527
609
|
compositionId,
|
|
528
610
|
effect
|
|
529
611
|
}) {
|
|
530
|
-
(0,
|
|
612
|
+
(0, import_react8.useEffect)(() => {
|
|
531
613
|
if (!enabled || !compositionId || !projectId) {
|
|
532
614
|
return;
|
|
533
615
|
}
|
|
@@ -560,6 +642,7 @@ function useCompositionEventEffect({
|
|
|
560
642
|
UniformComponent,
|
|
561
643
|
UniformComposition,
|
|
562
644
|
UniformSlot,
|
|
645
|
+
UniformText,
|
|
563
646
|
componentStore,
|
|
564
647
|
componentStoreResolver,
|
|
565
648
|
createComponentStore,
|
package/dist/index.mjs
CHANGED
|
@@ -98,7 +98,8 @@ import {
|
|
|
98
98
|
CANVAS_PERSONALIZE_SLOT,
|
|
99
99
|
CANVAS_PERSONALIZE_TYPE,
|
|
100
100
|
CANVAS_TEST_SLOT,
|
|
101
|
-
CANVAS_TEST_TYPE
|
|
101
|
+
CANVAS_TEST_TYPE,
|
|
102
|
+
EMPTY_COMPOSITION as EMPTY_COMPOSITION2
|
|
102
103
|
} from "@uniformdev/canvas";
|
|
103
104
|
import React5 from "react";
|
|
104
105
|
|
|
@@ -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 registeredCompositionIds = /* @__PURE__ */ new Set();
|
|
@@ -190,8 +191,8 @@ var useUniformContextualEditing = ({
|
|
|
190
191
|
if (!channel || registeredCompositionIds.has(initialCompositionValue == null ? void 0 : initialCompositionValue._id)) {
|
|
191
192
|
return;
|
|
192
193
|
}
|
|
193
|
-
const unsubscribeFromCompositionUpdates = channel.on("update-composition", async (message) => {
|
|
194
|
-
if (!
|
|
194
|
+
const unsubscribeFromCompositionUpdates = channel.on("update-composition-internal", async (message) => {
|
|
195
|
+
if (!isUpdateCompositionInternalMessage(message)) {
|
|
195
196
|
return;
|
|
196
197
|
}
|
|
197
198
|
const enhancedComposition = await enhance(message);
|
|
@@ -293,7 +294,7 @@ function ContextualEditingComponentWrapper({
|
|
|
293
294
|
var _a, _b, _c, _d;
|
|
294
295
|
const isPlaceholder = (component == null ? void 0 : component._id) === PLACEHOLDER_ID;
|
|
295
296
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
296
|
-
return !isContextualEditing ? /* @__PURE__ */ React4.createElement(React4.Fragment, null, children) : /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(
|
|
297
|
+
return !isContextualEditing ? /* @__PURE__ */ React4.createElement(React4.Fragment, null, children) : isPlaceholder && emptyPlaceholder === null ? null : /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(
|
|
297
298
|
"script",
|
|
298
299
|
{
|
|
299
300
|
"data-role": IN_CONTEXT_EDITOR_COMPONENT_START_ROLE,
|
|
@@ -325,7 +326,7 @@ function UniformSlot({
|
|
|
325
326
|
}
|
|
326
327
|
const slot = (_a = parentData.slots) == null ? void 0 : _a[name];
|
|
327
328
|
if (!slot || !Array.isArray(slot)) {
|
|
328
|
-
if (process.env.NODE_ENV === "development") {
|
|
329
|
+
if (process.env.NODE_ENV === "development" && parentData.type !== EMPTY_COMPOSITION2.type) {
|
|
329
330
|
console.warn(
|
|
330
331
|
`[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:`,
|
|
331
332
|
parentData
|
|
@@ -365,7 +366,7 @@ function renderComponent({
|
|
|
365
366
|
}) {
|
|
366
367
|
const RenderComponent = resolveRenderer == null ? void 0 : resolveRenderer(component);
|
|
367
368
|
if (component.type === CANVAS_TEST_TYPE) {
|
|
368
|
-
|
|
369
|
+
const testComponent = resolveSystem.test(
|
|
369
370
|
component,
|
|
370
371
|
key,
|
|
371
372
|
(variantComponent, key2) => {
|
|
@@ -384,8 +385,20 @@ function renderComponent({
|
|
|
384
385
|
});
|
|
385
386
|
}
|
|
386
387
|
);
|
|
388
|
+
return /* @__PURE__ */ React5.createElement(
|
|
389
|
+
ContextualEditingComponentWrapper,
|
|
390
|
+
{
|
|
391
|
+
component,
|
|
392
|
+
parentComponent,
|
|
393
|
+
slotName,
|
|
394
|
+
indexInSlot,
|
|
395
|
+
slotChildrenCount,
|
|
396
|
+
emptyPlaceholder
|
|
397
|
+
},
|
|
398
|
+
testComponent
|
|
399
|
+
);
|
|
387
400
|
} else if (component.type === CANVAS_PERSONALIZE_TYPE) {
|
|
388
|
-
|
|
401
|
+
const personalizationComponent = resolveSystem.personalization(
|
|
389
402
|
component,
|
|
390
403
|
key,
|
|
391
404
|
(variantComponent, key2) => {
|
|
@@ -404,6 +417,18 @@ function renderComponent({
|
|
|
404
417
|
});
|
|
405
418
|
}
|
|
406
419
|
);
|
|
420
|
+
return /* @__PURE__ */ React5.createElement(
|
|
421
|
+
ContextualEditingComponentWrapper,
|
|
422
|
+
{
|
|
423
|
+
component,
|
|
424
|
+
parentComponent,
|
|
425
|
+
slotName,
|
|
426
|
+
indexInSlot,
|
|
427
|
+
slotChildrenCount,
|
|
428
|
+
emptyPlaceholder
|
|
429
|
+
},
|
|
430
|
+
personalizationComponent
|
|
431
|
+
);
|
|
407
432
|
} else if (RenderComponent) {
|
|
408
433
|
const props = convertComponentToProps(component);
|
|
409
434
|
return /* @__PURE__ */ React5.createElement(UniformComponent, { key, data: component, resolveRenderer }, /* @__PURE__ */ React5.createElement(
|
|
@@ -490,6 +515,63 @@ function resolveChildren({
|
|
|
490
515
|
return renderChildren;
|
|
491
516
|
}
|
|
492
517
|
|
|
518
|
+
// src/components/UniformText.tsx
|
|
519
|
+
import React7, { useCallback, useMemo as useMemo2, useRef, useState as useState2 } from "react";
|
|
520
|
+
var UniformText = ({
|
|
521
|
+
as: Tag = "span",
|
|
522
|
+
parameterId,
|
|
523
|
+
isMultiline = false,
|
|
524
|
+
render = (value) => value,
|
|
525
|
+
...props
|
|
526
|
+
}) => {
|
|
527
|
+
const { data: componentData } = useUniformCurrentComponent();
|
|
528
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
529
|
+
const elementRef = useRef(null);
|
|
530
|
+
const [isFocused, setIsFocused] = useState2(false);
|
|
531
|
+
const parameter = useMemo2(() => {
|
|
532
|
+
var _a;
|
|
533
|
+
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
534
|
+
}, [componentData, parameterId]);
|
|
535
|
+
const value = useMemo2(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
536
|
+
const isEditable = useMemo2(() => {
|
|
537
|
+
var _a, _b;
|
|
538
|
+
return (_b = (_a = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _a.isEditable) != null ? _b : false;
|
|
539
|
+
}, [parameter]);
|
|
540
|
+
const handleOnFocus = useCallback(() => {
|
|
541
|
+
setIsFocused(true);
|
|
542
|
+
}, [setIsFocused]);
|
|
543
|
+
const handleOnBlur = useCallback(() => {
|
|
544
|
+
setIsFocused(false);
|
|
545
|
+
}, [setIsFocused]);
|
|
546
|
+
const shouldSkipCustomRendering = useMemo2(() => isFocused && isEditable, [isFocused, isEditable]);
|
|
547
|
+
if (!parameter) {
|
|
548
|
+
console.warn(
|
|
549
|
+
`UniformText: The parameterId "${parameterId}" was not found in the component of type "${componentData == null ? void 0 : componentData.type}"`
|
|
550
|
+
);
|
|
551
|
+
return null;
|
|
552
|
+
}
|
|
553
|
+
if (!isContextualEditing) {
|
|
554
|
+
return /* @__PURE__ */ React7.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
555
|
+
}
|
|
556
|
+
return /* @__PURE__ */ React7.createElement(
|
|
557
|
+
Tag,
|
|
558
|
+
{
|
|
559
|
+
...props,
|
|
560
|
+
ref: elementRef,
|
|
561
|
+
"data-uniform-component-id": componentData == null ? void 0 : componentData._id,
|
|
562
|
+
"data-uniform-parameter-id": parameterId,
|
|
563
|
+
"data-uniform-parameter-type": "text",
|
|
564
|
+
"data-uniform-is-multiline": isMultiline,
|
|
565
|
+
style: isMultiline ? { whiteSpace: "pre-wrap" } : {},
|
|
566
|
+
contentEditable: isEditable,
|
|
567
|
+
suppressContentEditableWarning: true,
|
|
568
|
+
onFocus: handleOnFocus,
|
|
569
|
+
onBlur: handleOnBlur
|
|
570
|
+
},
|
|
571
|
+
shouldSkipCustomRendering ? value : render(value)
|
|
572
|
+
);
|
|
573
|
+
};
|
|
574
|
+
|
|
493
575
|
// src/hooks/useCompositionEventEffect.ts
|
|
494
576
|
import {
|
|
495
577
|
CANVAS_DRAFT_STATE,
|
|
@@ -535,6 +617,7 @@ export {
|
|
|
535
617
|
UniformComponent,
|
|
536
618
|
UniformComposition,
|
|
537
619
|
UniformSlot,
|
|
620
|
+
UniformText,
|
|
538
621
|
componentStore,
|
|
539
622
|
componentStoreResolver,
|
|
540
623
|
createComponentStore,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-react",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.1.1-alpha.1+3ec68fe9d",
|
|
4
4
|
"description": "React SDK for Uniform Canvas",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,16 +24,16 @@
|
|
|
24
24
|
"document": "api-extractor run --local"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@uniformdev/canvas": "19.
|
|
28
|
-
"@uniformdev/context": "19.
|
|
29
|
-
"@uniformdev/context-react": "19.
|
|
27
|
+
"@uniformdev/canvas": "19.1.1-alpha.1+3ec68fe9d",
|
|
28
|
+
"@uniformdev/context": "19.1.1-alpha.1+3ec68fe9d",
|
|
29
|
+
"@uniformdev/context-react": "19.1.1-alpha.1+3ec68fe9d"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"react": ">= 16 || 17 || 18",
|
|
33
33
|
"react-dom": ">=16"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/react": "18.0.
|
|
36
|
+
"@types/react": "18.0.37",
|
|
37
37
|
"react": "18.2.0",
|
|
38
38
|
"react-dom": "18.2.0"
|
|
39
39
|
},
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "3ec68fe9d54c7128e57cc8a5c8116fe968f65865"
|
|
47
47
|
}
|