@uniformdev/canvas-react 19.35.1 → 19.35.3-alpha.82
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.mts +396 -0
- package/dist/index.d.ts +45 -56
- package/dist/index.esm.js +102 -90
- package/dist/index.js +126 -118
- package/dist/index.mjs +102 -90
- package/package.json +6 -6
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;
|
|
@@ -553,11 +557,61 @@ function resolveChildren({
|
|
|
553
557
|
}
|
|
554
558
|
|
|
555
559
|
// src/components/UniformRichText/UniformRichText.tsx
|
|
560
|
+
import {
|
|
561
|
+
getParameterAttributes
|
|
562
|
+
} from "@uniformdev/canvas";
|
|
556
563
|
import {
|
|
557
564
|
isRichTextValue,
|
|
558
565
|
isRichTextValueConsideredEmpty
|
|
559
566
|
} from "@uniformdev/richtext";
|
|
560
|
-
import React16, { useMemo as
|
|
567
|
+
import React16, { useMemo as useMemo3 } from "react";
|
|
568
|
+
|
|
569
|
+
// src/hooks/useUniformContextualEditingState.ts
|
|
570
|
+
import {
|
|
571
|
+
createCanvasChannel as createCanvasChannel2,
|
|
572
|
+
isUpdateContextualEditingStateInternalMessage
|
|
573
|
+
} from "@uniformdev/canvas";
|
|
574
|
+
import { useEffect as useEffect2, useMemo as useMemo2, useState as useState2 } from "react";
|
|
575
|
+
var useUniformContextualEditingState = ({
|
|
576
|
+
global = false
|
|
577
|
+
} = {}) => {
|
|
578
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
579
|
+
const { data: componentData } = useUniformCurrentComponent();
|
|
580
|
+
const [selectedComponentReference, setSelectedComponentReference] = useState2();
|
|
581
|
+
const channel = useMemo2(() => {
|
|
582
|
+
if (!isContextualEditing) {
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
const channel2 = createCanvasChannel2({
|
|
586
|
+
broadcastTo: [window],
|
|
587
|
+
listenTo: [window]
|
|
588
|
+
});
|
|
589
|
+
return channel2;
|
|
590
|
+
}, [isContextualEditing]);
|
|
591
|
+
useEffect2(() => {
|
|
592
|
+
if (!channel) {
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
const unsubscribe = channel.on("update-contextual-editing-state-internal", async (message) => {
|
|
596
|
+
var _a;
|
|
597
|
+
if (!isUpdateContextualEditingStateInternalMessage(message)) {
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
if (!global && (componentData == null ? void 0 : componentData._id) !== ((_a = message.state.selectedComponentReference) == null ? void 0 : _a.parentId)) {
|
|
601
|
+
setSelectedComponentReference(void 0);
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
setSelectedComponentReference(message.state.selectedComponentReference);
|
|
605
|
+
});
|
|
606
|
+
return () => {
|
|
607
|
+
unsubscribe();
|
|
608
|
+
};
|
|
609
|
+
}, [global, channel, componentData == null ? void 0 : componentData._id]);
|
|
610
|
+
return {
|
|
611
|
+
isContextualEditing,
|
|
612
|
+
selectedComponentReference
|
|
613
|
+
};
|
|
614
|
+
};
|
|
561
615
|
|
|
562
616
|
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
563
617
|
import { isRichTextNode } from "@uniformdev/richtext";
|
|
@@ -668,18 +722,32 @@ var resolveRichTextDefaultRenderer = (node) => {
|
|
|
668
722
|
// src/components/UniformRichText/UniformRichText.tsx
|
|
669
723
|
var UniformRichText = React16.forwardRef(function UniformRichText2({ parameterId, resolveRichTextRenderer, as: Tag = "div", ...props }, ref) {
|
|
670
724
|
const { data: componentData } = useUniformCurrentComponent();
|
|
671
|
-
const
|
|
725
|
+
const { selectedComponentReference } = useUniformContextualEditingState({ global: true });
|
|
726
|
+
const parameter = useMemo3(() => {
|
|
672
727
|
var _a;
|
|
673
728
|
return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
674
729
|
}, [componentData, parameterId]);
|
|
675
|
-
const value =
|
|
730
|
+
const value = useMemo3(() => parameter == null ? void 0 : parameter.value, [parameter]);
|
|
676
731
|
if (!value || !isRichTextValue(value) || isRichTextValueConsideredEmpty(value))
|
|
677
732
|
return null;
|
|
678
|
-
return Tag === null ? /* @__PURE__ */ React16.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ React16.createElement(
|
|
733
|
+
return Tag === null ? /* @__PURE__ */ React16.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ React16.createElement(
|
|
734
|
+
Tag,
|
|
735
|
+
{
|
|
736
|
+
ref,
|
|
737
|
+
...props,
|
|
738
|
+
...getParameterAttributes({
|
|
739
|
+
component: componentData,
|
|
740
|
+
id: parameterId
|
|
741
|
+
}),
|
|
742
|
+
tabIndex: 0,
|
|
743
|
+
"data-uniform-selected-parameter": (selectedComponentReference == null ? void 0 : selectedComponentReference.id) === parameterId && selectedComponentReference.parentId === (componentData == null ? void 0 : componentData._id)
|
|
744
|
+
},
|
|
745
|
+
/* @__PURE__ */ React16.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer })
|
|
746
|
+
);
|
|
679
747
|
});
|
|
680
748
|
|
|
681
749
|
// src/components/UniformText.tsx
|
|
682
|
-
import React17, { useCallback, useMemo as
|
|
750
|
+
import React17, { useCallback, useMemo as useMemo4, useState as useState3 } from "react";
|
|
683
751
|
var UniformText = ({
|
|
684
752
|
as: Tag = "span",
|
|
685
753
|
parameterId,
|
|
@@ -688,25 +756,23 @@ var UniformText = ({
|
|
|
688
756
|
render = (value) => value,
|
|
689
757
|
...props
|
|
690
758
|
}) => {
|
|
691
|
-
|
|
759
|
+
var _a, _b;
|
|
760
|
+
const { data: componentData, contextualEditingDefaultPlaceholder } = useUniformCurrentComponent();
|
|
692
761
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
693
|
-
const [isFocused, setIsFocused] =
|
|
694
|
-
const parameter =
|
|
695
|
-
var
|
|
696
|
-
return (
|
|
762
|
+
const [isFocused, setIsFocused] = useState3(false);
|
|
763
|
+
const parameter = useMemo4(() => {
|
|
764
|
+
var _a2;
|
|
765
|
+
return (_a2 = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a2[parameterId];
|
|
697
766
|
}, [componentData, parameterId]);
|
|
698
|
-
const value =
|
|
699
|
-
const isEditable =
|
|
700
|
-
|
|
701
|
-
return (_b = (_a = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _a.isEditable) != null ? _b : false;
|
|
702
|
-
}, [parameter]);
|
|
767
|
+
const value = parameter == null ? void 0 : parameter.value;
|
|
768
|
+
const isEditable = (_b = (_a = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _a.isEditable) != null ? _b : false;
|
|
769
|
+
const shouldSkipCustomRendering = isFocused && isEditable;
|
|
703
770
|
const handleOnFocus = useCallback(() => {
|
|
704
771
|
setIsFocused(true);
|
|
705
772
|
}, [setIsFocused]);
|
|
706
773
|
const handleOnBlur = useCallback(() => {
|
|
707
774
|
setIsFocused(false);
|
|
708
775
|
}, [setIsFocused]);
|
|
709
|
-
const shouldSkipCustomRendering = useMemo3(() => isFocused && isEditable, [isFocused, isEditable]);
|
|
710
776
|
if (!parameter) {
|
|
711
777
|
console.warn(
|
|
712
778
|
`UniformText: The parameterId "${parameterId}" was not found in the component of type "${componentData == null ? void 0 : componentData.type}"`
|
|
@@ -716,19 +782,20 @@ var UniformText = ({
|
|
|
716
782
|
if (!isContextualEditing) {
|
|
717
783
|
return /* @__PURE__ */ React17.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
718
784
|
}
|
|
785
|
+
const placeholderProp = placeholder != null ? placeholder : contextualEditingDefaultPlaceholder;
|
|
786
|
+
const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: parameterId }) : placeholderProp;
|
|
719
787
|
return /* @__PURE__ */ React17.createElement(
|
|
720
788
|
Tag,
|
|
721
789
|
{
|
|
722
790
|
...props,
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
791
|
+
...getParameterAttributes2({
|
|
792
|
+
component: componentData,
|
|
793
|
+
id: parameterId,
|
|
794
|
+
isMultiline
|
|
795
|
+
}),
|
|
726
796
|
"data-uniform-parameter-type": "text",
|
|
727
|
-
"data-uniform-
|
|
728
|
-
"data-uniform-placeholder": placeholder,
|
|
797
|
+
"data-uniform-placeholder": computedPlaceholder,
|
|
729
798
|
style: isMultiline ? { whiteSpace: "pre-wrap" } : {},
|
|
730
|
-
contentEditable: isEditable,
|
|
731
|
-
suppressContentEditableWarning: true,
|
|
732
799
|
onFocus: handleOnFocus,
|
|
733
800
|
onBlur: handleOnBlur
|
|
734
801
|
},
|
|
@@ -737,20 +804,12 @@ var UniformText = ({
|
|
|
737
804
|
};
|
|
738
805
|
|
|
739
806
|
// src/helpers/getParameterAttributes.ts
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
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;
|
|
807
|
+
import {
|
|
808
|
+
getParameterAttributes as defaultGetParameterAttributes
|
|
809
|
+
} from "@uniformdev/canvas";
|
|
810
|
+
var getParameterAttributes2 = (options) => {
|
|
747
811
|
return {
|
|
748
|
-
|
|
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,
|
|
812
|
+
...defaultGetParameterAttributes(options),
|
|
754
813
|
suppressContentEditableWarning: true
|
|
755
814
|
};
|
|
756
815
|
};
|
|
@@ -761,14 +820,14 @@ import {
|
|
|
761
820
|
createEventBus,
|
|
762
821
|
subscribeToComposition
|
|
763
822
|
} from "@uniformdev/canvas";
|
|
764
|
-
import { useEffect as
|
|
823
|
+
import { useEffect as useEffect3 } from "react";
|
|
765
824
|
function useCompositionEventEffect({
|
|
766
825
|
enabled,
|
|
767
826
|
projectId,
|
|
768
827
|
compositionId,
|
|
769
828
|
effect
|
|
770
829
|
}) {
|
|
771
|
-
|
|
830
|
+
useEffect3(() => {
|
|
772
831
|
if (!enabled || !compositionId || !projectId) {
|
|
773
832
|
return;
|
|
774
833
|
}
|
|
@@ -794,53 +853,6 @@ function useCompositionEventEffect({
|
|
|
794
853
|
};
|
|
795
854
|
}, [compositionId, enabled, projectId, effect]);
|
|
796
855
|
}
|
|
797
|
-
|
|
798
|
-
// src/hooks/useUniformContextualEditingState.ts
|
|
799
|
-
import {
|
|
800
|
-
createCanvasChannel as createCanvasChannel2,
|
|
801
|
-
isUpdateContextualEditingStateInternalMessage
|
|
802
|
-
} from "@uniformdev/canvas";
|
|
803
|
-
import { useEffect as useEffect3, useMemo as useMemo4, useState as useState3 } from "react";
|
|
804
|
-
var useUniformContextualEditingState = ({
|
|
805
|
-
global = false
|
|
806
|
-
} = {}) => {
|
|
807
|
-
const { isContextualEditing } = useUniformCurrentComposition();
|
|
808
|
-
const { data: componentData } = useUniformCurrentComponent();
|
|
809
|
-
const [selectedComponentReference, setSelectedComponentReference] = useState3();
|
|
810
|
-
const channel = useMemo4(() => {
|
|
811
|
-
if (!isContextualEditing) {
|
|
812
|
-
return;
|
|
813
|
-
}
|
|
814
|
-
const channel2 = createCanvasChannel2({
|
|
815
|
-
broadcastTo: [window],
|
|
816
|
-
listenTo: [window]
|
|
817
|
-
});
|
|
818
|
-
return channel2;
|
|
819
|
-
}, [isContextualEditing]);
|
|
820
|
-
useEffect3(() => {
|
|
821
|
-
if (!channel) {
|
|
822
|
-
return;
|
|
823
|
-
}
|
|
824
|
-
const unsubscribe = channel.on("update-contextual-editing-state-internal", async (message) => {
|
|
825
|
-
var _a;
|
|
826
|
-
if (!isUpdateContextualEditingStateInternalMessage(message)) {
|
|
827
|
-
return;
|
|
828
|
-
}
|
|
829
|
-
if (!global && (componentData == null ? void 0 : componentData._id) !== ((_a = message.state.selectedComponentReference) == null ? void 0 : _a.parentId)) {
|
|
830
|
-
setSelectedComponentReference(void 0);
|
|
831
|
-
return;
|
|
832
|
-
}
|
|
833
|
-
setSelectedComponentReference(message.state.selectedComponentReference);
|
|
834
|
-
});
|
|
835
|
-
return () => {
|
|
836
|
-
unsubscribe();
|
|
837
|
-
};
|
|
838
|
-
}, [global, channel, componentData == null ? void 0 : componentData._id]);
|
|
839
|
-
return {
|
|
840
|
-
isContextualEditing,
|
|
841
|
-
selectedComponentReference
|
|
842
|
-
};
|
|
843
|
-
};
|
|
844
856
|
export {
|
|
845
857
|
DefaultNotImplementedComponent,
|
|
846
858
|
NOT_IMPLEMENTED_COMPONENT,
|
|
@@ -855,7 +867,7 @@ export {
|
|
|
855
867
|
createComponentStore,
|
|
856
868
|
createComponentStoreResolver,
|
|
857
869
|
createUniformApiEnhancer,
|
|
858
|
-
getParameterAttributes,
|
|
870
|
+
getParameterAttributes2 as getParameterAttributes,
|
|
859
871
|
registerUniformComponent,
|
|
860
872
|
useCompositionEventEffect,
|
|
861
873
|
useUniformContextualEditing,
|