@uniformdev/canvas-react 19.33.1-alpha.10 → 19.33.1-alpha.15

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  import React$1, { Key, ReactNode, PropsWithChildren } from 'react';
2
2
  import * as _uniformdev_canvas from '@uniformdev/canvas';
3
- import { ComponentInstance, RootComponentInstance, UpdateCompositionMessage, SubscribeToCompositionOptions } from '@uniformdev/canvas';
4
- export { createUniformApiEnhancer } from '@uniformdev/canvas';
3
+ import { ComponentInstance, RootComponentInstance, UpdateCompositionMessage, getParameterAttributes as getParameterAttributes$1, SubscribeToCompositionOptions } from '@uniformdev/canvas';
4
+ export { GetParameterAttributesProps, createUniformApiEnhancer } from '@uniformdev/canvas';
5
5
  import { RichTextNode } from '@uniformdev/richtext';
6
6
 
7
7
  /**
@@ -41,6 +41,40 @@ type ComponentStore = {
41
41
  **/
42
42
  declare function DefaultNotImplementedComponent(props: ComponentProps): React$1.JSX.Element | null;
43
43
 
44
+ type ParameterTextValue = string | undefined;
45
+ type UniformTextProps = {
46
+ /**
47
+ * The name of the HTML tag to render.
48
+ * @default "span"
49
+ */
50
+ as?: React$1.ElementType;
51
+ /** The ID of the parameter. */
52
+ parameterId: string;
53
+ /**
54
+ * When set to true, it adds `whiteSpace: 'pre-wrap'` to the styles of the root element to allow the rendering of line breaks.
55
+ * @default false
56
+ */
57
+ isMultiline?: boolean;
58
+ /**
59
+ * Sets the value to show in Canvas editor when the parameter value is empty.
60
+ * Can be a static string, or a function to generate the placeholder out of parameter info.
61
+ * @default undefined
62
+ */
63
+ placeholder?: string | ((parameter: {
64
+ id: string;
65
+ }) => string | undefined);
66
+ /**
67
+ * A function to customize the rendering of the parameter value. Useful to format the value before rendering it.
68
+ * @default "(value) => value"
69
+ */
70
+ render?: (value: ParameterTextValue) => React$1.ReactNode;
71
+ } & Omit<React$1.HTMLAttributes<HTMLSpanElement>, 'children' | 'placeholder'>;
72
+ /**
73
+ * Adds inline editing capability to text parameters
74
+ * @deprecated This component is unstable, and not ready for production usage.
75
+ **/
76
+ declare const UniformText: ({ as: Tag, parameterId, isMultiline, placeholder, render, ...props }: UniformTextProps) => React$1.JSX.Element | null;
77
+
44
78
  type UniformComponentProps<TRenderProps = unknown> = {
45
79
  /** The data of the component instance */
46
80
  data?: ComponentInstance | RootComponentInstance;
@@ -59,11 +93,16 @@ type UniformComponentProps<TRenderProps = unknown> = {
59
93
  * Default: onView
60
94
  */
61
95
  behaviorTracking?: 'onLoad' | 'onView';
96
+ /**
97
+ * The default placeholder to pass to the parameter component that support inline editing (such as UniformText).
98
+ */
99
+ contextualEditingDefaultPlaceholder?: UniformTextProps['placeholder'];
62
100
  };
63
101
  type UniformComponentContextValue = {
64
102
  data?: UniformComponentProps['data'];
65
103
  resolveRenderer?: UniformComponentProps['resolveRenderer'];
66
104
  behaviorTracking?: UniformComponentProps['behaviorTracking'];
105
+ contextualEditingDefaultPlaceholder?: UniformComponentProps['contextualEditingDefaultPlaceholder'];
67
106
  };
68
107
  /**
69
108
  * Gets the data of the closest `<UniformComponent />` ancestor.
@@ -74,7 +113,7 @@ declare function useUniformCurrentComponent(): UniformComponentContextValue;
74
113
  * Note that the actual rendering happens inside `<UniformSlot />`, this component only provides the services needed to achieve that.
75
114
  * This component is used internally by `<UniformComposition />`, which you should use in most cases.
76
115
  */
77
- declare function UniformComponent<TRenderProps = unknown>({ data, resolveRenderer, children, behaviorTracking, }: UniformComponentProps<TRenderProps>): React$1.JSX.Element | null;
116
+ declare function UniformComponent<TRenderProps = unknown>({ data, resolveRenderer, children, behaviorTracking, contextualEditingDefaultPlaceholder, }: UniformComponentProps<TRenderProps>): React$1.JSX.Element | null;
78
117
 
79
118
  type UseUniformContextualEditingProps = {
80
119
  initialCompositionValue?: RootComponentInstance;
@@ -228,7 +267,7 @@ declare function useUniformCurrentComposition(): UniformCompositionContextValue;
228
267
  * It renders the full tree of components, and provides some services to the children, such as `useUniformCurrentComposition`.
229
268
  * It also takes care of enabling [Contextual Editing](https://docs.uniform.app/capabilities/composition/contextual-editing).
230
269
  */
231
- declare function UniformComposition<TRenderProps = unknown>({ data, behaviorTracking, children, resolveRenderer, contextualEditingEnhancer, }: UniformCompositionProps<TRenderProps>): React$1.JSX.Element;
270
+ declare function UniformComposition<TRenderProps = unknown>({ data, behaviorTracking, children, resolveRenderer, contextualEditingEnhancer, contextualEditingDefaultPlaceholder, }: UniformCompositionProps<TRenderProps>): React$1.JSX.Element;
232
271
 
233
272
  type RichTextComponentProps<TNode extends RichTextNode = RichTextNode> = {
234
273
  node: TNode;
@@ -306,62 +345,12 @@ type UniformSlotProps<TSlotNames extends string> = {
306
345
  /** Renders a named Slot within a Composition. */
307
346
  declare function UniformSlot<TSlotNames extends string = string>({ name, resolveRenderer, children, emptyPlaceholder, }: UniformSlotProps<TSlotNames>): JSX.Element | null;
308
347
 
309
- type ParameterTextValue = string | undefined;
310
- type UniformTextProps = {
311
- /**
312
- * The name of the HTML tag to render.
313
- * @default "span"
314
- */
315
- as?: React$1.ElementType;
316
- /** The ID of the parameter. */
317
- parameterId: string;
318
- /**
319
- * When set to true, it adds `whiteSpace: 'pre-wrap'` to the styles of the root element to allow the rendering of line breaks.
320
- * @default false
321
- */
322
- isMultiline?: boolean;
323
- /**
324
- * Sets the value to show in Canvas editor when the parameter value is empty.
325
- * @default undefined
326
- */
327
- placeholder?: string;
328
- /**
329
- * A function to customize the rendering of the parameter value. Useful to format the value before rendering it.
330
- * @default "(value) => value"
331
- */
332
- render?: (value: ParameterTextValue) => React$1.ReactNode;
333
- } & Omit<React$1.HTMLAttributes<HTMLSpanElement>, 'children'>;
334
- /**
335
- * Adds inline editing capability to text parameters
336
- * @deprecated This component is unstable, and not ready for production usage.
337
- **/
338
- declare const UniformText: ({ as: Tag, parameterId, isMultiline, placeholder, render, ...props }: UniformTextProps) => React$1.JSX.Element | null;
339
-
340
- type GetParameterAttributesProps = {
341
- /** The public Id of the parameter */
342
- id: string;
343
- /** The component object where this parameter is used */
344
- component: ComponentInstance;
345
- /**
346
- * Sets the value to show in Canvas editor when the parameter value is empty.
347
- * @default undefined
348
- */
349
- placeholder?: string;
350
- };
351
348
  /**
352
349
  * Returns the attributes needed to annotate a Uniform parameter for inline editing.
353
350
  * Supports only text parameters at the moment.
354
351
  * @deprecated Unstable, and not ready for production usage.
355
352
  **/
356
- declare const getParameterAttributes: ({ id, component, placeholder }: GetParameterAttributesProps) => {
357
- 'data-uniform-component-id': string | undefined;
358
- 'data-uniform-parameter-id': string;
359
- 'data-uniform-parameter-value': {};
360
- 'data-uniform-parameter-type': string | undefined;
361
- 'data-uniform-placeholder': string | undefined;
362
- contentEditable: boolean;
363
- suppressContentEditableWarning: boolean;
364
- };
353
+ declare const getParameterAttributes: typeof getParameterAttributes$1;
365
354
 
366
355
  type UseCompositionEventEffectOptions = Omit<Partial<SubscribeToCompositionOptions>, 'callback'> & {
367
356
  enabled: boolean;
@@ -404,4 +393,4 @@ declare const createComponentStoreResolver: (options: {
404
393
  defaultComponent?: React$1.ComponentType<ComponentProps<any>>;
405
394
  }) => RenderComponentResolver;
406
395
 
407
- export { ComponentProps, ComponentStore, DefaultNotImplementedComponent, GetParameterAttributesProps, NOT_IMPLEMENTED_COMPONENT, RenderComponentResolver, RenderRichTextComponentResolver, RichTextComponentProps, RichTextRendererComponent, SystemRenderConfig, SystemRenderFunction, UniformComponent, UniformComponentContextValue, UniformComponentProps, UniformComposition, UniformCompositionProps, UniformRichText, UniformRichTextNode, UniformRichTextNodeProps, UniformRichTextProps, UniformSlot, UniformSlotProps, UniformText, UniformTextProps, UseCompositionEventEffectOptions, UseUniformContextualEditingProps, UseUniformContextualEditingStateProps, componentStore, componentStoreResolver, createComponentStore, createComponentStoreResolver, getParameterAttributes, registerUniformComponent, useCompositionEventEffect, useUniformContextualEditing, useUniformContextualEditingState, useUniformCurrentComponent, useUniformCurrentComposition };
396
+ export { ComponentProps, ComponentStore, DefaultNotImplementedComponent, NOT_IMPLEMENTED_COMPONENT, RenderComponentResolver, RenderRichTextComponentResolver, RichTextComponentProps, RichTextRendererComponent, SystemRenderConfig, SystemRenderFunction, UniformComponent, UniformComponentContextValue, UniformComponentProps, UniformComposition, UniformCompositionProps, UniformRichText, UniformRichTextNode, UniformRichTextNodeProps, UniformRichTextProps, UniformSlot, UniformSlotProps, UniformText, UniformTextProps, UseCompositionEventEffectOptions, UseUniformContextualEditingProps, UseUniformContextualEditingStateProps, componentStore, componentStoreResolver, createComponentStore, createComponentStoreResolver, getParameterAttributes, registerUniformComponent, useCompositionEventEffect, useUniformContextualEditing, useUniformContextualEditingState, useUniformCurrentComponent, useUniformCurrentComposition };
package/dist/index.esm.js CHANGED
@@ -295,7 +295,8 @@ function UniformComposition({
295
295
  behaviorTracking = "onView",
296
296
  children,
297
297
  resolveRenderer,
298
- contextualEditingEnhancer
298
+ contextualEditingEnhancer,
299
+ contextualEditingDefaultPlaceholder
299
300
  }) {
300
301
  const { composition, isContextualEditing } = useUniformContextualEditing({
301
302
  initialCompositionValue: data,
@@ -311,7 +312,8 @@ function UniformComposition({
311
312
  {
312
313
  data: composition,
313
314
  behaviorTracking,
314
- resolveRenderer
315
+ resolveRenderer,
316
+ contextualEditingDefaultPlaceholder
315
317
  },
316
318
  children
317
319
  ))
@@ -499,7 +501,8 @@ function UniformComponent({
499
501
  data,
500
502
  resolveRenderer,
501
503
  children,
502
- behaviorTracking
504
+ behaviorTracking,
505
+ contextualEditingDefaultPlaceholder
503
506
  }) {
504
507
  var _a, _b, _c;
505
508
  const parentData = useUniformCurrentComponent();
@@ -513,7 +516,8 @@ function UniformComponent({
513
516
  const contextValue = {
514
517
  data,
515
518
  resolveRenderer: resolveRenderer || parentData.resolveRenderer || componentStoreResolver,
516
- behaviorTracking: (_a = behaviorTracking != null ? behaviorTracking : parentData == null ? void 0 : parentData.behaviorTracking) != null ? _a : "onView"
519
+ behaviorTracking: (_a = behaviorTracking != null ? behaviorTracking : parentData == null ? void 0 : parentData.behaviorTracking) != null ? _a : "onView",
520
+ contextualEditingDefaultPlaceholder: contextualEditingDefaultPlaceholder != null ? contextualEditingDefaultPlaceholder : parentData.contextualEditingDefaultPlaceholder
517
521
  };
518
522
  const enrichmentTags = (_c = (_b = data.parameters) == null ? void 0 : _b[CANVAS_ENRICHMENT_TAG_PARAM]) == null ? void 0 : _c.value;
519
523
  const TrackComponent = contextValue.behaviorTracking === "onLoad" ? TrackFragment : Track;
@@ -688,25 +692,23 @@ var UniformText = ({
688
692
  render = (value) => value,
689
693
  ...props
690
694
  }) => {
691
- const { data: componentData } = useUniformCurrentComponent();
695
+ var _a, _b;
696
+ const { data: componentData, contextualEditingDefaultPlaceholder } = useUniformCurrentComponent();
692
697
  const { isContextualEditing } = useUniformCurrentComposition();
693
698
  const [isFocused, setIsFocused] = useState2(false);
694
699
  const parameter = useMemo3(() => {
695
- var _a;
696
- return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
700
+ var _a2;
701
+ return (_a2 = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a2[parameterId];
697
702
  }, [componentData, parameterId]);
698
- const value = useMemo3(() => parameter == null ? void 0 : parameter.value, [parameter]);
699
- const isEditable = useMemo3(() => {
700
- var _a, _b;
701
- return (_b = (_a = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _a.isEditable) != null ? _b : false;
702
- }, [parameter]);
703
+ const value = parameter == null ? void 0 : parameter.value;
704
+ const isEditable = (_b = (_a = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _a.isEditable) != null ? _b : false;
705
+ const shouldSkipCustomRendering = isFocused && isEditable;
703
706
  const handleOnFocus = useCallback(() => {
704
707
  setIsFocused(true);
705
708
  }, [setIsFocused]);
706
709
  const handleOnBlur = useCallback(() => {
707
710
  setIsFocused(false);
708
711
  }, [setIsFocused]);
709
- const shouldSkipCustomRendering = useMemo3(() => isFocused && isEditable, [isFocused, isEditable]);
710
712
  if (!parameter) {
711
713
  console.warn(
712
714
  `UniformText: The parameterId "${parameterId}" was not found in the component of type "${componentData == null ? void 0 : componentData.type}"`
@@ -716,19 +718,20 @@ var UniformText = ({
716
718
  if (!isContextualEditing) {
717
719
  return /* @__PURE__ */ React17.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
718
720
  }
721
+ const placeholderProp = placeholder != null ? placeholder : contextualEditingDefaultPlaceholder;
722
+ const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: parameterId }) : placeholderProp;
719
723
  return /* @__PURE__ */ React17.createElement(
720
724
  Tag,
721
725
  {
722
726
  ...props,
723
- "data-uniform-component-id": componentData == null ? void 0 : componentData._id,
724
- "data-uniform-parameter-id": parameterId,
725
- "data-uniform-parameter-value": value != null ? value : "",
727
+ ...getParameterAttributes({
728
+ component: componentData,
729
+ id: parameterId,
730
+ isMultiline
731
+ }),
726
732
  "data-uniform-parameter-type": "text",
727
- "data-uniform-is-multiline": isMultiline,
728
- "data-uniform-placeholder": placeholder,
733
+ "data-uniform-placeholder": computedPlaceholder,
729
734
  style: isMultiline ? { whiteSpace: "pre-wrap" } : {},
730
- contentEditable: isEditable,
731
- suppressContentEditableWarning: true,
732
735
  onFocus: handleOnFocus,
733
736
  onBlur: handleOnBlur
734
737
  },
@@ -737,20 +740,12 @@ var UniformText = ({
737
740
  };
738
741
 
739
742
  // src/helpers/getParameterAttributes.ts
740
- var getParameterAttributes = ({ id, component, placeholder }) => {
741
- var _a, _b, _c;
742
- const componentId = component == null ? void 0 : component._id;
743
- const parameter = (_a = component == null ? void 0 : component.parameters) == null ? void 0 : _a[id];
744
- const value = parameter == null ? void 0 : parameter.value;
745
- const type = parameter == null ? void 0 : parameter.type;
746
- const isEditable = (_c = (_b = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _b.isEditable) != null ? _c : false;
743
+ import {
744
+ getParameterAttributes as defaultGetParameterAttributes
745
+ } from "@uniformdev/canvas";
746
+ var getParameterAttributes = (options) => {
747
747
  return {
748
- "data-uniform-component-id": componentId,
749
- "data-uniform-parameter-id": id,
750
- "data-uniform-parameter-value": value != null ? value : "",
751
- "data-uniform-parameter-type": type,
752
- "data-uniform-placeholder": placeholder,
753
- contentEditable: isEditable,
748
+ ...defaultGetParameterAttributes(options),
754
749
  suppressContentEditableWarning: true
755
750
  };
756
751
  };
package/dist/index.js CHANGED
@@ -327,7 +327,8 @@ function UniformComposition({
327
327
  behaviorTracking = "onView",
328
328
  children,
329
329
  resolveRenderer,
330
- contextualEditingEnhancer
330
+ contextualEditingEnhancer,
331
+ contextualEditingDefaultPlaceholder
331
332
  }) {
332
333
  const { composition, isContextualEditing } = useUniformContextualEditing({
333
334
  initialCompositionValue: data,
@@ -343,7 +344,8 @@ function UniformComposition({
343
344
  {
344
345
  data: composition,
345
346
  behaviorTracking,
346
- resolveRenderer
347
+ resolveRenderer,
348
+ contextualEditingDefaultPlaceholder
347
349
  },
348
350
  children
349
351
  ))
@@ -531,7 +533,8 @@ function UniformComponent({
531
533
  data,
532
534
  resolveRenderer,
533
535
  children,
534
- behaviorTracking
536
+ behaviorTracking,
537
+ contextualEditingDefaultPlaceholder
535
538
  }) {
536
539
  var _a, _b, _c;
537
540
  const parentData = useUniformCurrentComponent();
@@ -545,7 +548,8 @@ function UniformComponent({
545
548
  const contextValue = {
546
549
  data,
547
550
  resolveRenderer: resolveRenderer || parentData.resolveRenderer || componentStoreResolver,
548
- behaviorTracking: (_a = behaviorTracking != null ? behaviorTracking : parentData == null ? void 0 : parentData.behaviorTracking) != null ? _a : "onView"
551
+ behaviorTracking: (_a = behaviorTracking != null ? behaviorTracking : parentData == null ? void 0 : parentData.behaviorTracking) != null ? _a : "onView",
552
+ contextualEditingDefaultPlaceholder: contextualEditingDefaultPlaceholder != null ? contextualEditingDefaultPlaceholder : parentData.contextualEditingDefaultPlaceholder
549
553
  };
550
554
  const enrichmentTags = (_c = (_b = data.parameters) == null ? void 0 : _b[import_canvas6.CANVAS_ENRICHMENT_TAG_PARAM]) == null ? void 0 : _c.value;
551
555
  const TrackComponent = contextValue.behaviorTracking === "onLoad" ? import_context_react2.TrackFragment : import_context_react2.Track;
@@ -717,25 +721,23 @@ var UniformText = ({
717
721
  render = (value) => value,
718
722
  ...props
719
723
  }) => {
720
- const { data: componentData } = useUniformCurrentComponent();
724
+ var _a, _b;
725
+ const { data: componentData, contextualEditingDefaultPlaceholder } = useUniformCurrentComponent();
721
726
  const { isContextualEditing } = useUniformCurrentComposition();
722
727
  const [isFocused, setIsFocused] = (0, import_react17.useState)(false);
723
728
  const parameter = (0, import_react17.useMemo)(() => {
724
- var _a;
725
- return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
729
+ var _a2;
730
+ return (_a2 = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a2[parameterId];
726
731
  }, [componentData, parameterId]);
727
- const value = (0, import_react17.useMemo)(() => parameter == null ? void 0 : parameter.value, [parameter]);
728
- const isEditable = (0, import_react17.useMemo)(() => {
729
- var _a, _b;
730
- return (_b = (_a = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _a.isEditable) != null ? _b : false;
731
- }, [parameter]);
732
+ const value = parameter == null ? void 0 : parameter.value;
733
+ const isEditable = (_b = (_a = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _a.isEditable) != null ? _b : false;
734
+ const shouldSkipCustomRendering = isFocused && isEditable;
732
735
  const handleOnFocus = (0, import_react17.useCallback)(() => {
733
736
  setIsFocused(true);
734
737
  }, [setIsFocused]);
735
738
  const handleOnBlur = (0, import_react17.useCallback)(() => {
736
739
  setIsFocused(false);
737
740
  }, [setIsFocused]);
738
- const shouldSkipCustomRendering = (0, import_react17.useMemo)(() => isFocused && isEditable, [isFocused, isEditable]);
739
741
  if (!parameter) {
740
742
  console.warn(
741
743
  `UniformText: The parameterId "${parameterId}" was not found in the component of type "${componentData == null ? void 0 : componentData.type}"`
@@ -745,19 +747,20 @@ var UniformText = ({
745
747
  if (!isContextualEditing) {
746
748
  return /* @__PURE__ */ import_react17.default.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
747
749
  }
750
+ const placeholderProp = placeholder != null ? placeholder : contextualEditingDefaultPlaceholder;
751
+ const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: parameterId }) : placeholderProp;
748
752
  return /* @__PURE__ */ import_react17.default.createElement(
749
753
  Tag,
750
754
  {
751
755
  ...props,
752
- "data-uniform-component-id": componentData == null ? void 0 : componentData._id,
753
- "data-uniform-parameter-id": parameterId,
754
- "data-uniform-parameter-value": value != null ? value : "",
756
+ ...getParameterAttributes({
757
+ component: componentData,
758
+ id: parameterId,
759
+ isMultiline
760
+ }),
755
761
  "data-uniform-parameter-type": "text",
756
- "data-uniform-is-multiline": isMultiline,
757
- "data-uniform-placeholder": placeholder,
762
+ "data-uniform-placeholder": computedPlaceholder,
758
763
  style: isMultiline ? { whiteSpace: "pre-wrap" } : {},
759
- contentEditable: isEditable,
760
- suppressContentEditableWarning: true,
761
764
  onFocus: handleOnFocus,
762
765
  onBlur: handleOnBlur
763
766
  },
@@ -766,26 +769,16 @@ var UniformText = ({
766
769
  };
767
770
 
768
771
  // src/helpers/getParameterAttributes.ts
769
- var getParameterAttributes = ({ id, component, placeholder }) => {
770
- var _a, _b, _c;
771
- const componentId = component == null ? void 0 : component._id;
772
- const parameter = (_a = component == null ? void 0 : component.parameters) == null ? void 0 : _a[id];
773
- const value = parameter == null ? void 0 : parameter.value;
774
- const type = parameter == null ? void 0 : parameter.type;
775
- const isEditable = (_c = (_b = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _b.isEditable) != null ? _c : false;
772
+ var import_canvas7 = require("@uniformdev/canvas");
773
+ var getParameterAttributes = (options) => {
776
774
  return {
777
- "data-uniform-component-id": componentId,
778
- "data-uniform-parameter-id": id,
779
- "data-uniform-parameter-value": value != null ? value : "",
780
- "data-uniform-parameter-type": type,
781
- "data-uniform-placeholder": placeholder,
782
- contentEditable: isEditable,
775
+ ...(0, import_canvas7.getParameterAttributes)(options),
783
776
  suppressContentEditableWarning: true
784
777
  };
785
778
  };
786
779
 
787
780
  // src/hooks/useCompositionEventEffect.ts
788
- var import_canvas7 = require("@uniformdev/canvas");
781
+ var import_canvas8 = require("@uniformdev/canvas");
789
782
  var import_react18 = require("react");
790
783
  function useCompositionEventEffect({
791
784
  enabled,
@@ -799,12 +792,12 @@ function useCompositionEventEffect({
799
792
  }
800
793
  let goodbye = void 0;
801
794
  const loadEffect = async () => {
802
- const eventBus = await (0, import_canvas7.createEventBus)();
795
+ const eventBus = await (0, import_canvas8.createEventBus)();
803
796
  if (eventBus) {
804
- goodbye = (0, import_canvas7.subscribeToComposition)({
797
+ goodbye = (0, import_canvas8.subscribeToComposition)({
805
798
  eventBus,
806
799
  compositionId,
807
- compositionState: import_canvas7.CANVAS_DRAFT_STATE,
800
+ compositionState: import_canvas8.CANVAS_DRAFT_STATE,
808
801
  projectId,
809
802
  callback: effect,
810
803
  event: "updated"
@@ -821,7 +814,7 @@ function useCompositionEventEffect({
821
814
  }
822
815
 
823
816
  // src/hooks/useUniformContextualEditingState.ts
824
- var import_canvas8 = require("@uniformdev/canvas");
817
+ var import_canvas9 = require("@uniformdev/canvas");
825
818
  var import_react19 = require("react");
826
819
  var useUniformContextualEditingState = ({
827
820
  global = false
@@ -833,7 +826,7 @@ var useUniformContextualEditingState = ({
833
826
  if (!isContextualEditing) {
834
827
  return;
835
828
  }
836
- const channel2 = (0, import_canvas8.createCanvasChannel)({
829
+ const channel2 = (0, import_canvas9.createCanvasChannel)({
837
830
  broadcastTo: [window],
838
831
  listenTo: [window]
839
832
  });
@@ -845,7 +838,7 @@ var useUniformContextualEditingState = ({
845
838
  }
846
839
  const unsubscribe = channel.on("update-contextual-editing-state-internal", async (message) => {
847
840
  var _a;
848
- if (!(0, import_canvas8.isUpdateContextualEditingStateInternalMessage)(message)) {
841
+ if (!(0, import_canvas9.isUpdateContextualEditingStateInternalMessage)(message)) {
849
842
  return;
850
843
  }
851
844
  if (!global && (componentData == null ? void 0 : componentData._id) !== ((_a = message.state.selectedComponentReference) == null ? void 0 : _a.parentId)) {
package/dist/index.mjs CHANGED
@@ -295,7 +295,8 @@ function UniformComposition({
295
295
  behaviorTracking = "onView",
296
296
  children,
297
297
  resolveRenderer,
298
- contextualEditingEnhancer
298
+ contextualEditingEnhancer,
299
+ contextualEditingDefaultPlaceholder
299
300
  }) {
300
301
  const { composition, isContextualEditing } = useUniformContextualEditing({
301
302
  initialCompositionValue: data,
@@ -311,7 +312,8 @@ function UniformComposition({
311
312
  {
312
313
  data: composition,
313
314
  behaviorTracking,
314
- resolveRenderer
315
+ resolveRenderer,
316
+ contextualEditingDefaultPlaceholder
315
317
  },
316
318
  children
317
319
  ))
@@ -499,7 +501,8 @@ function UniformComponent({
499
501
  data,
500
502
  resolveRenderer,
501
503
  children,
502
- behaviorTracking
504
+ behaviorTracking,
505
+ contextualEditingDefaultPlaceholder
503
506
  }) {
504
507
  var _a, _b, _c;
505
508
  const parentData = useUniformCurrentComponent();
@@ -513,7 +516,8 @@ function UniformComponent({
513
516
  const contextValue = {
514
517
  data,
515
518
  resolveRenderer: resolveRenderer || parentData.resolveRenderer || componentStoreResolver,
516
- behaviorTracking: (_a = behaviorTracking != null ? behaviorTracking : parentData == null ? void 0 : parentData.behaviorTracking) != null ? _a : "onView"
519
+ behaviorTracking: (_a = behaviorTracking != null ? behaviorTracking : parentData == null ? void 0 : parentData.behaviorTracking) != null ? _a : "onView",
520
+ contextualEditingDefaultPlaceholder: contextualEditingDefaultPlaceholder != null ? contextualEditingDefaultPlaceholder : parentData.contextualEditingDefaultPlaceholder
517
521
  };
518
522
  const enrichmentTags = (_c = (_b = data.parameters) == null ? void 0 : _b[CANVAS_ENRICHMENT_TAG_PARAM]) == null ? void 0 : _c.value;
519
523
  const TrackComponent = contextValue.behaviorTracking === "onLoad" ? TrackFragment : Track;
@@ -688,25 +692,23 @@ var UniformText = ({
688
692
  render = (value) => value,
689
693
  ...props
690
694
  }) => {
691
- const { data: componentData } = useUniformCurrentComponent();
695
+ var _a, _b;
696
+ const { data: componentData, contextualEditingDefaultPlaceholder } = useUniformCurrentComponent();
692
697
  const { isContextualEditing } = useUniformCurrentComposition();
693
698
  const [isFocused, setIsFocused] = useState2(false);
694
699
  const parameter = useMemo3(() => {
695
- var _a;
696
- return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
700
+ var _a2;
701
+ return (_a2 = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a2[parameterId];
697
702
  }, [componentData, parameterId]);
698
- const value = useMemo3(() => parameter == null ? void 0 : parameter.value, [parameter]);
699
- const isEditable = useMemo3(() => {
700
- var _a, _b;
701
- return (_b = (_a = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _a.isEditable) != null ? _b : false;
702
- }, [parameter]);
703
+ const value = parameter == null ? void 0 : parameter.value;
704
+ const isEditable = (_b = (_a = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _a.isEditable) != null ? _b : false;
705
+ const shouldSkipCustomRendering = isFocused && isEditable;
703
706
  const handleOnFocus = useCallback(() => {
704
707
  setIsFocused(true);
705
708
  }, [setIsFocused]);
706
709
  const handleOnBlur = useCallback(() => {
707
710
  setIsFocused(false);
708
711
  }, [setIsFocused]);
709
- const shouldSkipCustomRendering = useMemo3(() => isFocused && isEditable, [isFocused, isEditable]);
710
712
  if (!parameter) {
711
713
  console.warn(
712
714
  `UniformText: The parameterId "${parameterId}" was not found in the component of type "${componentData == null ? void 0 : componentData.type}"`
@@ -716,19 +718,20 @@ var UniformText = ({
716
718
  if (!isContextualEditing) {
717
719
  return /* @__PURE__ */ React17.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
718
720
  }
721
+ const placeholderProp = placeholder != null ? placeholder : contextualEditingDefaultPlaceholder;
722
+ const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: parameterId }) : placeholderProp;
719
723
  return /* @__PURE__ */ React17.createElement(
720
724
  Tag,
721
725
  {
722
726
  ...props,
723
- "data-uniform-component-id": componentData == null ? void 0 : componentData._id,
724
- "data-uniform-parameter-id": parameterId,
725
- "data-uniform-parameter-value": value != null ? value : "",
727
+ ...getParameterAttributes({
728
+ component: componentData,
729
+ id: parameterId,
730
+ isMultiline
731
+ }),
726
732
  "data-uniform-parameter-type": "text",
727
- "data-uniform-is-multiline": isMultiline,
728
- "data-uniform-placeholder": placeholder,
733
+ "data-uniform-placeholder": computedPlaceholder,
729
734
  style: isMultiline ? { whiteSpace: "pre-wrap" } : {},
730
- contentEditable: isEditable,
731
- suppressContentEditableWarning: true,
732
735
  onFocus: handleOnFocus,
733
736
  onBlur: handleOnBlur
734
737
  },
@@ -737,20 +740,12 @@ var UniformText = ({
737
740
  };
738
741
 
739
742
  // src/helpers/getParameterAttributes.ts
740
- var getParameterAttributes = ({ id, component, placeholder }) => {
741
- var _a, _b, _c;
742
- const componentId = component == null ? void 0 : component._id;
743
- const parameter = (_a = component == null ? void 0 : component.parameters) == null ? void 0 : _a[id];
744
- const value = parameter == null ? void 0 : parameter.value;
745
- const type = parameter == null ? void 0 : parameter.type;
746
- const isEditable = (_c = (_b = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _b.isEditable) != null ? _c : false;
743
+ import {
744
+ getParameterAttributes as defaultGetParameterAttributes
745
+ } from "@uniformdev/canvas";
746
+ var getParameterAttributes = (options) => {
747
747
  return {
748
- "data-uniform-component-id": componentId,
749
- "data-uniform-parameter-id": id,
750
- "data-uniform-parameter-value": value != null ? value : "",
751
- "data-uniform-parameter-type": type,
752
- "data-uniform-placeholder": placeholder,
753
- contentEditable: isEditable,
748
+ ...defaultGetParameterAttributes(options),
754
749
  suppressContentEditableWarning: true
755
750
  };
756
751
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-react",
3
- "version": "19.33.1-alpha.10+468c89c72",
3
+ "version": "19.33.1-alpha.15+31348a1dd",
4
4
  "description": "React SDK for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -24,10 +24,10 @@
24
24
  "document": "api-extractor run --local"
25
25
  },
26
26
  "dependencies": {
27
- "@uniformdev/canvas": "19.33.1-alpha.10+468c89c72",
28
- "@uniformdev/context": "19.33.1-alpha.10+468c89c72",
29
- "@uniformdev/context-react": "19.33.1-alpha.10+468c89c72",
30
- "@uniformdev/richtext": "19.33.1-alpha.10+468c89c72"
27
+ "@uniformdev/canvas": "19.33.1-alpha.15+31348a1dd",
28
+ "@uniformdev/context": "19.33.1-alpha.15+31348a1dd",
29
+ "@uniformdev/context-react": "19.33.1-alpha.15+31348a1dd",
30
+ "@uniformdev/richtext": "19.33.1-alpha.15+31348a1dd"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "react": ">= 16 || 17 || 18",
@@ -44,5 +44,5 @@
44
44
  "publishConfig": {
45
45
  "access": "public"
46
46
  },
47
- "gitHead": "468c89c7236b39c598fc7fcce5b318d23a1fbd55"
47
+ "gitHead": "31348a1dd87271a9316b89ce924f634a5307f9ce"
48
48
  }