@uniformdev/canvas-react 19.178.0 → 19.178.2-alpha.25
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 +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.esm.js +53 -36
- package/dist/index.js +63 -43
- package/dist/index.mjs +53 -36
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -357,6 +357,14 @@ type UniformRichTextProps = {
|
|
|
357
357
|
* for rendering a rich text node
|
|
358
358
|
*/
|
|
359
359
|
resolveRichTextRenderer?: RenderRichTextComponentResolver;
|
|
360
|
+
/**
|
|
361
|
+
* Sets the value to show in Canvas editor when the parameter value is empty.
|
|
362
|
+
* Can be a static string, or a function to generate the placeholder out of parameter info.
|
|
363
|
+
* @default undefined
|
|
364
|
+
*/
|
|
365
|
+
placeholder?: string | ((parameter: {
|
|
366
|
+
id: string;
|
|
367
|
+
}) => string | undefined);
|
|
360
368
|
} & Omit<React$1.HTMLAttributes<HTMLDivElement>, 'children'>;
|
|
361
369
|
/**
|
|
362
370
|
* Adds rendering support for Uniform Rich Text parameters
|
|
@@ -374,6 +382,14 @@ declare const UniformRichText: React$1.ForwardRefExoticComponent<{
|
|
|
374
382
|
* for rendering a rich text node
|
|
375
383
|
*/
|
|
376
384
|
resolveRichTextRenderer?: RenderRichTextComponentResolver | undefined;
|
|
385
|
+
/**
|
|
386
|
+
* Sets the value to show in Canvas editor when the parameter value is empty.
|
|
387
|
+
* Can be a static string, or a function to generate the placeholder out of parameter info.
|
|
388
|
+
* @default undefined
|
|
389
|
+
*/
|
|
390
|
+
placeholder?: string | ((parameter: {
|
|
391
|
+
id: string;
|
|
392
|
+
}) => string | undefined) | undefined;
|
|
377
393
|
} & Omit<React$1.HTMLAttributes<HTMLDivElement>, "children"> & React$1.RefAttributes<unknown>>;
|
|
378
394
|
|
|
379
395
|
type UniformRichTextNodeProps = {
|
package/dist/index.d.ts
CHANGED
|
@@ -357,6 +357,14 @@ type UniformRichTextProps = {
|
|
|
357
357
|
* for rendering a rich text node
|
|
358
358
|
*/
|
|
359
359
|
resolveRichTextRenderer?: RenderRichTextComponentResolver;
|
|
360
|
+
/**
|
|
361
|
+
* Sets the value to show in Canvas editor when the parameter value is empty.
|
|
362
|
+
* Can be a static string, or a function to generate the placeholder out of parameter info.
|
|
363
|
+
* @default undefined
|
|
364
|
+
*/
|
|
365
|
+
placeholder?: string | ((parameter: {
|
|
366
|
+
id: string;
|
|
367
|
+
}) => string | undefined);
|
|
360
368
|
} & Omit<React$1.HTMLAttributes<HTMLDivElement>, 'children'>;
|
|
361
369
|
/**
|
|
362
370
|
* Adds rendering support for Uniform Rich Text parameters
|
|
@@ -374,6 +382,14 @@ declare const UniformRichText: React$1.ForwardRefExoticComponent<{
|
|
|
374
382
|
* for rendering a rich text node
|
|
375
383
|
*/
|
|
376
384
|
resolveRichTextRenderer?: RenderRichTextComponentResolver | undefined;
|
|
385
|
+
/**
|
|
386
|
+
* Sets the value to show in Canvas editor when the parameter value is empty.
|
|
387
|
+
* Can be a static string, or a function to generate the placeholder out of parameter info.
|
|
388
|
+
* @default undefined
|
|
389
|
+
*/
|
|
390
|
+
placeholder?: string | ((parameter: {
|
|
391
|
+
id: string;
|
|
392
|
+
}) => string | undefined) | undefined;
|
|
377
393
|
} & Omit<React$1.HTMLAttributes<HTMLDivElement>, "children"> & React$1.RefAttributes<unknown>>;
|
|
378
394
|
|
|
379
395
|
type UniformRichTextNodeProps = {
|
package/dist/index.esm.js
CHANGED
|
@@ -690,15 +690,12 @@ import {
|
|
|
690
690
|
ATTRIBUTE_PARAMETER_ID,
|
|
691
691
|
ATTRIBUTE_PARAMETER_TYPE
|
|
692
692
|
} from "@uniformdev/canvas";
|
|
693
|
-
import {
|
|
694
|
-
|
|
695
|
-
isRichTextValueConsideredEmpty
|
|
696
|
-
} from "@uniformdev/richtext";
|
|
697
|
-
import React18, { useMemo as useMemo5 } from "react";
|
|
693
|
+
import { isRichTextValue, isRichTextValueConsideredEmpty } from "@uniformdev/richtext";
|
|
694
|
+
import React19 from "react";
|
|
698
695
|
|
|
699
696
|
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
700
697
|
import { isRichTextNode } from "@uniformdev/richtext";
|
|
701
|
-
import
|
|
698
|
+
import React18 from "react";
|
|
702
699
|
|
|
703
700
|
// src/components/UniformRichText/nodes/HeadingRichTextNode.tsx
|
|
704
701
|
import React9 from "react";
|
|
@@ -752,19 +749,28 @@ var ParagraphRichTextNode = ({ children, node }) => {
|
|
|
752
749
|
);
|
|
753
750
|
};
|
|
754
751
|
|
|
755
|
-
// src/components/UniformRichText/nodes/
|
|
752
|
+
// src/components/UniformRichText/nodes/TableCellRichTextNode.tsx
|
|
753
|
+
import { getRichTextTagFromTableCellHeaderState } from "@uniformdev/richtext";
|
|
756
754
|
import React15 from "react";
|
|
755
|
+
var TableCellRichTextNode = ({ children, node }) => {
|
|
756
|
+
const { headerState } = node;
|
|
757
|
+
const TableCellTag = getRichTextTagFromTableCellHeaderState(headerState);
|
|
758
|
+
return /* @__PURE__ */ React15.createElement(TableCellTag, null, children);
|
|
759
|
+
};
|
|
760
|
+
|
|
761
|
+
// src/components/UniformRichText/nodes/TabRichTextNode.tsx
|
|
762
|
+
import React16 from "react";
|
|
757
763
|
var TabRichTextNode = () => {
|
|
758
|
-
return /* @__PURE__ */
|
|
764
|
+
return /* @__PURE__ */ React16.createElement(React16.Fragment, null, " ");
|
|
759
765
|
};
|
|
760
766
|
|
|
761
767
|
// src/components/UniformRichText/nodes/TextRichTextNode.tsx
|
|
762
768
|
import { getRichTextTagsFromTextFormat } from "@uniformdev/richtext";
|
|
763
|
-
import
|
|
769
|
+
import React17 from "react";
|
|
764
770
|
var TextRichTextNode = ({ node }) => {
|
|
765
771
|
const { text, format } = node;
|
|
766
772
|
const tags = getRichTextTagsFromTextFormat(format);
|
|
767
|
-
return /* @__PURE__ */
|
|
773
|
+
return /* @__PURE__ */ React17.createElement(React17.Fragment, null, tags.length > 0 ? tags.reduceRight((children, Tag) => /* @__PURE__ */ React17.createElement(Tag, null, children), text) : text);
|
|
768
774
|
};
|
|
769
775
|
|
|
770
776
|
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
@@ -778,8 +784,8 @@ function UniformRichTextNode({ node, ...props }) {
|
|
|
778
784
|
if (!NodeRenderer) {
|
|
779
785
|
return null;
|
|
780
786
|
}
|
|
781
|
-
const children = node.children ? node.children.map((childNode, i) => /* @__PURE__ */
|
|
782
|
-
return /* @__PURE__ */
|
|
787
|
+
const children = node.children ? node.children.map((childNode, i) => /* @__PURE__ */ React18.createElement(UniformRichTextNode, { ...props, key: i, node: childNode })) : null;
|
|
788
|
+
return /* @__PURE__ */ React18.createElement(NodeRenderer, { node }, children);
|
|
783
789
|
}
|
|
784
790
|
var rendererMap = /* @__PURE__ */ new Map([
|
|
785
791
|
["heading", HeadingRichTextNode],
|
|
@@ -788,48 +794,59 @@ var rendererMap = /* @__PURE__ */ new Map([
|
|
|
788
794
|
["list", ListRichTextNode],
|
|
789
795
|
["listitem", ListItemRichTextNode],
|
|
790
796
|
["paragraph", ParagraphRichTextNode],
|
|
791
|
-
["quote", ({ children }) => /* @__PURE__ */
|
|
797
|
+
["quote", ({ children }) => /* @__PURE__ */ React18.createElement("blockquote", null, children)],
|
|
792
798
|
[
|
|
793
799
|
"code",
|
|
794
|
-
({ children }) => /* @__PURE__ */
|
|
800
|
+
({ children }) => /* @__PURE__ */ React18.createElement("pre", null, /* @__PURE__ */ React18.createElement("code", null, children))
|
|
795
801
|
],
|
|
796
|
-
["root", ({ children }) => /* @__PURE__ */
|
|
802
|
+
["root", ({ children }) => /* @__PURE__ */ React18.createElement(React18.Fragment, null, children)],
|
|
797
803
|
["text", TextRichTextNode],
|
|
798
|
-
["tab", TabRichTextNode]
|
|
804
|
+
["tab", TabRichTextNode],
|
|
805
|
+
[
|
|
806
|
+
"table",
|
|
807
|
+
({ children }) => /* @__PURE__ */ React18.createElement("table", null, /* @__PURE__ */ React18.createElement("tbody", null, children))
|
|
808
|
+
],
|
|
809
|
+
["tablerow", ({ children }) => /* @__PURE__ */ React18.createElement("tr", null, children)],
|
|
810
|
+
["tablecell", TableCellRichTextNode]
|
|
799
811
|
]);
|
|
800
812
|
var resolveRichTextDefaultRenderer = (node) => {
|
|
801
813
|
return rendererMap.get(node.type);
|
|
802
814
|
};
|
|
803
815
|
|
|
804
816
|
// src/components/UniformRichText/UniformRichText.tsx
|
|
805
|
-
var UniformRichText =
|
|
806
|
-
|
|
807
|
-
const
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
817
|
+
var UniformRichText = React19.forwardRef(function UniformRichText2({ parameterId, resolveRichTextRenderer, as: Tag = "div", placeholder, ...props }, ref) {
|
|
818
|
+
var _a;
|
|
819
|
+
const { data: componentData, contextualEditingDefaultPlaceholder } = useUniformCurrentComponent();
|
|
820
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
821
|
+
const parameter = (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
822
|
+
if (!parameter) {
|
|
823
|
+
return null;
|
|
824
|
+
}
|
|
825
|
+
const placeholderProp = placeholder != null ? placeholder : contextualEditingDefaultPlaceholder;
|
|
826
|
+
const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: parameterId }) : placeholderProp;
|
|
827
|
+
const value = parameter.value;
|
|
828
|
+
if (!value || !isRichTextValue(value)) return null;
|
|
829
|
+
if (!isContextualEditing && isRichTextValueConsideredEmpty(value)) return null;
|
|
830
|
+
return Tag === null ? /* @__PURE__ */ React19.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ React19.createElement(
|
|
814
831
|
Tag,
|
|
815
832
|
{
|
|
816
833
|
ref,
|
|
817
834
|
...props,
|
|
818
|
-
...{
|
|
835
|
+
...isContextualEditing ? {
|
|
819
836
|
[ATTRIBUTE_COMPONENT_ID]: componentData == null ? void 0 : componentData._id,
|
|
820
837
|
[ATTRIBUTE_PARAMETER_ID]: parameterId,
|
|
821
838
|
[ATTRIBUTE_PARAMETER_TYPE]: "richText"
|
|
822
|
-
}
|
|
839
|
+
} : {}
|
|
823
840
|
},
|
|
824
|
-
/* @__PURE__ */
|
|
841
|
+
isRichTextValueConsideredEmpty(value) ? /* @__PURE__ */ React19.createElement("p", null, /* @__PURE__ */ React19.createElement("i", null, computedPlaceholder)) : /* @__PURE__ */ React19.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer })
|
|
825
842
|
);
|
|
826
843
|
});
|
|
827
844
|
|
|
828
845
|
// src/components/UniformText.tsx
|
|
829
|
-
import
|
|
846
|
+
import React21, { useState as useState2 } from "react";
|
|
830
847
|
|
|
831
848
|
// src/components/PureUniformText.tsx
|
|
832
|
-
import
|
|
849
|
+
import React20 from "react";
|
|
833
850
|
var PureUniformText = ({
|
|
834
851
|
as: Tag = "span",
|
|
835
852
|
parameterId,
|
|
@@ -848,10 +865,10 @@ var PureUniformText = ({
|
|
|
848
865
|
return null;
|
|
849
866
|
}
|
|
850
867
|
if (!isContextualEditing) {
|
|
851
|
-
return /* @__PURE__ */
|
|
868
|
+
return /* @__PURE__ */ React20.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
852
869
|
}
|
|
853
870
|
const computedPlaceholder = typeof placeholder === "function" ? placeholder({ id: parameterId }) : placeholder;
|
|
854
|
-
return /* @__PURE__ */
|
|
871
|
+
return /* @__PURE__ */ React20.createElement(
|
|
855
872
|
Tag,
|
|
856
873
|
{
|
|
857
874
|
...props,
|
|
@@ -889,7 +906,7 @@ var UniformText = ({
|
|
|
889
906
|
}
|
|
890
907
|
const placeholderProp = placeholder != null ? placeholder : contextualEditingDefaultPlaceholder;
|
|
891
908
|
const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: parameterId }) : placeholderProp;
|
|
892
|
-
return /* @__PURE__ */
|
|
909
|
+
return /* @__PURE__ */ React21.createElement(
|
|
893
910
|
PureUniformText,
|
|
894
911
|
{
|
|
895
912
|
...props,
|
|
@@ -967,7 +984,7 @@ import {
|
|
|
967
984
|
createCanvasChannel as createCanvasChannel2,
|
|
968
985
|
isUpdateContextualEditingStateInternalMessage
|
|
969
986
|
} from "@uniformdev/canvas";
|
|
970
|
-
import { useEffect as useEffect3, useMemo as
|
|
987
|
+
import { useEffect as useEffect3, useMemo as useMemo5, useState as useState3 } from "react";
|
|
971
988
|
var useUniformContextualEditingState = ({
|
|
972
989
|
global = false
|
|
973
990
|
} = {}) => {
|
|
@@ -977,7 +994,7 @@ var useUniformContextualEditingState = ({
|
|
|
977
994
|
const [previewMode, setPreviewMode] = useState3(
|
|
978
995
|
isContextualEditing ? "editor" : void 0
|
|
979
996
|
);
|
|
980
|
-
const channel =
|
|
997
|
+
const channel = useMemo5(() => {
|
|
981
998
|
if (!isContextualEditing) {
|
|
982
999
|
return;
|
|
983
1000
|
}
|
|
@@ -1011,7 +1028,7 @@ var useUniformContextualEditingState = ({
|
|
|
1011
1028
|
unsubscribe();
|
|
1012
1029
|
};
|
|
1013
1030
|
}, [global, channel, componentData == null ? void 0 : componentData._id, setSelectedComponentReference, setPreviewMode]);
|
|
1014
|
-
return
|
|
1031
|
+
return useMemo5(
|
|
1015
1032
|
() => ({
|
|
1016
1033
|
isContextualEditing,
|
|
1017
1034
|
selectedComponentReference,
|
package/dist/index.js
CHANGED
|
@@ -718,12 +718,12 @@ var UniformPlayground = ({
|
|
|
718
718
|
|
|
719
719
|
// src/components/UniformRichText/UniformRichText.tsx
|
|
720
720
|
var import_canvas11 = require("@uniformdev/canvas");
|
|
721
|
-
var
|
|
722
|
-
var
|
|
721
|
+
var import_richtext6 = require("@uniformdev/richtext");
|
|
722
|
+
var import_react21 = __toESM(require("react"));
|
|
723
723
|
|
|
724
724
|
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
725
|
-
var
|
|
726
|
-
var
|
|
725
|
+
var import_richtext5 = require("@uniformdev/richtext");
|
|
726
|
+
var import_react20 = __toESM(require("react"));
|
|
727
727
|
|
|
728
728
|
// src/components/UniformRichText/nodes/HeadingRichTextNode.tsx
|
|
729
729
|
var import_react11 = __toESM(require("react"));
|
|
@@ -777,25 +777,34 @@ var ParagraphRichTextNode = ({ children, node }) => {
|
|
|
777
777
|
);
|
|
778
778
|
};
|
|
779
779
|
|
|
780
|
-
// src/components/UniformRichText/nodes/
|
|
780
|
+
// src/components/UniformRichText/nodes/TableCellRichTextNode.tsx
|
|
781
|
+
var import_richtext3 = require("@uniformdev/richtext");
|
|
781
782
|
var import_react17 = __toESM(require("react"));
|
|
783
|
+
var TableCellRichTextNode = ({ children, node }) => {
|
|
784
|
+
const { headerState } = node;
|
|
785
|
+
const TableCellTag = (0, import_richtext3.getRichTextTagFromTableCellHeaderState)(headerState);
|
|
786
|
+
return /* @__PURE__ */ import_react17.default.createElement(TableCellTag, null, children);
|
|
787
|
+
};
|
|
788
|
+
|
|
789
|
+
// src/components/UniformRichText/nodes/TabRichTextNode.tsx
|
|
790
|
+
var import_react18 = __toESM(require("react"));
|
|
782
791
|
var TabRichTextNode = () => {
|
|
783
|
-
return /* @__PURE__ */
|
|
792
|
+
return /* @__PURE__ */ import_react18.default.createElement(import_react18.default.Fragment, null, " ");
|
|
784
793
|
};
|
|
785
794
|
|
|
786
795
|
// src/components/UniformRichText/nodes/TextRichTextNode.tsx
|
|
787
|
-
var
|
|
788
|
-
var
|
|
796
|
+
var import_richtext4 = require("@uniformdev/richtext");
|
|
797
|
+
var import_react19 = __toESM(require("react"));
|
|
789
798
|
var TextRichTextNode = ({ node }) => {
|
|
790
799
|
const { text, format } = node;
|
|
791
|
-
const tags = (0,
|
|
792
|
-
return /* @__PURE__ */
|
|
800
|
+
const tags = (0, import_richtext4.getRichTextTagsFromTextFormat)(format);
|
|
801
|
+
return /* @__PURE__ */ import_react19.default.createElement(import_react19.default.Fragment, null, tags.length > 0 ? tags.reduceRight((children, Tag) => /* @__PURE__ */ import_react19.default.createElement(Tag, null, children), text) : text);
|
|
793
802
|
};
|
|
794
803
|
|
|
795
804
|
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
796
805
|
function UniformRichTextNode({ node, ...props }) {
|
|
797
806
|
var _a;
|
|
798
|
-
if (!(0,
|
|
807
|
+
if (!(0, import_richtext5.isRichTextNode)(node)) return null;
|
|
799
808
|
let NodeRenderer = (_a = props.resolveRichTextRenderer) == null ? void 0 : _a.call(props, node);
|
|
800
809
|
if (typeof NodeRenderer === "undefined") {
|
|
801
810
|
NodeRenderer = resolveRichTextDefaultRenderer(node);
|
|
@@ -803,8 +812,8 @@ function UniformRichTextNode({ node, ...props }) {
|
|
|
803
812
|
if (!NodeRenderer) {
|
|
804
813
|
return null;
|
|
805
814
|
}
|
|
806
|
-
const children = node.children ? node.children.map((childNode, i) => /* @__PURE__ */
|
|
807
|
-
return /* @__PURE__ */
|
|
815
|
+
const children = node.children ? node.children.map((childNode, i) => /* @__PURE__ */ import_react20.default.createElement(UniformRichTextNode, { ...props, key: i, node: childNode })) : null;
|
|
816
|
+
return /* @__PURE__ */ import_react20.default.createElement(NodeRenderer, { node }, children);
|
|
808
817
|
}
|
|
809
818
|
var rendererMap = /* @__PURE__ */ new Map([
|
|
810
819
|
["heading", HeadingRichTextNode],
|
|
@@ -813,48 +822,59 @@ var rendererMap = /* @__PURE__ */ new Map([
|
|
|
813
822
|
["list", ListRichTextNode],
|
|
814
823
|
["listitem", ListItemRichTextNode],
|
|
815
824
|
["paragraph", ParagraphRichTextNode],
|
|
816
|
-
["quote", ({ children }) => /* @__PURE__ */
|
|
825
|
+
["quote", ({ children }) => /* @__PURE__ */ import_react20.default.createElement("blockquote", null, children)],
|
|
817
826
|
[
|
|
818
827
|
"code",
|
|
819
|
-
({ children }) => /* @__PURE__ */
|
|
828
|
+
({ children }) => /* @__PURE__ */ import_react20.default.createElement("pre", null, /* @__PURE__ */ import_react20.default.createElement("code", null, children))
|
|
820
829
|
],
|
|
821
|
-
["root", ({ children }) => /* @__PURE__ */
|
|
830
|
+
["root", ({ children }) => /* @__PURE__ */ import_react20.default.createElement(import_react20.default.Fragment, null, children)],
|
|
822
831
|
["text", TextRichTextNode],
|
|
823
|
-
["tab", TabRichTextNode]
|
|
832
|
+
["tab", TabRichTextNode],
|
|
833
|
+
[
|
|
834
|
+
"table",
|
|
835
|
+
({ children }) => /* @__PURE__ */ import_react20.default.createElement("table", null, /* @__PURE__ */ import_react20.default.createElement("tbody", null, children))
|
|
836
|
+
],
|
|
837
|
+
["tablerow", ({ children }) => /* @__PURE__ */ import_react20.default.createElement("tr", null, children)],
|
|
838
|
+
["tablecell", TableCellRichTextNode]
|
|
824
839
|
]);
|
|
825
840
|
var resolveRichTextDefaultRenderer = (node) => {
|
|
826
841
|
return rendererMap.get(node.type);
|
|
827
842
|
};
|
|
828
843
|
|
|
829
844
|
// src/components/UniformRichText/UniformRichText.tsx
|
|
830
|
-
var UniformRichText =
|
|
831
|
-
|
|
832
|
-
const
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
845
|
+
var UniformRichText = import_react21.default.forwardRef(function UniformRichText2({ parameterId, resolveRichTextRenderer, as: Tag = "div", placeholder, ...props }, ref) {
|
|
846
|
+
var _a;
|
|
847
|
+
const { data: componentData, contextualEditingDefaultPlaceholder } = useUniformCurrentComponent();
|
|
848
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
849
|
+
const parameter = (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
850
|
+
if (!parameter) {
|
|
851
|
+
return null;
|
|
852
|
+
}
|
|
853
|
+
const placeholderProp = placeholder != null ? placeholder : contextualEditingDefaultPlaceholder;
|
|
854
|
+
const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: parameterId }) : placeholderProp;
|
|
855
|
+
const value = parameter.value;
|
|
856
|
+
if (!value || !(0, import_richtext6.isRichTextValue)(value)) return null;
|
|
857
|
+
if (!isContextualEditing && (0, import_richtext6.isRichTextValueConsideredEmpty)(value)) return null;
|
|
858
|
+
return Tag === null ? /* @__PURE__ */ import_react21.default.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ import_react21.default.createElement(
|
|
839
859
|
Tag,
|
|
840
860
|
{
|
|
841
861
|
ref,
|
|
842
862
|
...props,
|
|
843
|
-
...{
|
|
863
|
+
...isContextualEditing ? {
|
|
844
864
|
[import_canvas11.ATTRIBUTE_COMPONENT_ID]: componentData == null ? void 0 : componentData._id,
|
|
845
865
|
[import_canvas11.ATTRIBUTE_PARAMETER_ID]: parameterId,
|
|
846
866
|
[import_canvas11.ATTRIBUTE_PARAMETER_TYPE]: "richText"
|
|
847
|
-
}
|
|
867
|
+
} : {}
|
|
848
868
|
},
|
|
849
|
-
/* @__PURE__ */
|
|
869
|
+
(0, import_richtext6.isRichTextValueConsideredEmpty)(value) ? /* @__PURE__ */ import_react21.default.createElement("p", null, /* @__PURE__ */ import_react21.default.createElement("i", null, computedPlaceholder)) : /* @__PURE__ */ import_react21.default.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer })
|
|
850
870
|
);
|
|
851
871
|
});
|
|
852
872
|
|
|
853
873
|
// src/components/UniformText.tsx
|
|
854
|
-
var
|
|
874
|
+
var import_react23 = __toESM(require("react"));
|
|
855
875
|
|
|
856
876
|
// src/components/PureUniformText.tsx
|
|
857
|
-
var
|
|
877
|
+
var import_react22 = __toESM(require("react"));
|
|
858
878
|
var PureUniformText = ({
|
|
859
879
|
as: Tag = "span",
|
|
860
880
|
parameterId,
|
|
@@ -873,10 +893,10 @@ var PureUniformText = ({
|
|
|
873
893
|
return null;
|
|
874
894
|
}
|
|
875
895
|
if (!isContextualEditing) {
|
|
876
|
-
return /* @__PURE__ */
|
|
896
|
+
return /* @__PURE__ */ import_react22.default.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
877
897
|
}
|
|
878
898
|
const computedPlaceholder = typeof placeholder === "function" ? placeholder({ id: parameterId }) : placeholder;
|
|
879
|
-
return /* @__PURE__ */
|
|
899
|
+
return /* @__PURE__ */ import_react22.default.createElement(
|
|
880
900
|
Tag,
|
|
881
901
|
{
|
|
882
902
|
...props,
|
|
@@ -905,7 +925,7 @@ var UniformText = ({
|
|
|
905
925
|
var _a, _b, _c;
|
|
906
926
|
const { data: componentData, contextualEditingDefaultPlaceholder } = useUniformCurrentComponent();
|
|
907
927
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
908
|
-
const [isFocused, setIsFocused] = (0,
|
|
928
|
+
const [isFocused, setIsFocused] = (0, import_react23.useState)(false);
|
|
909
929
|
const parameter = (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
910
930
|
const isEditable = (_c = (_b = parameter == null ? void 0 : parameter._contextualEditing) == null ? void 0 : _b.isEditable) != null ? _c : false;
|
|
911
931
|
const shouldSkipCustomRendering = isFocused && isEditable;
|
|
@@ -914,7 +934,7 @@ var UniformText = ({
|
|
|
914
934
|
}
|
|
915
935
|
const placeholderProp = placeholder != null ? placeholder : contextualEditingDefaultPlaceholder;
|
|
916
936
|
const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: parameterId }) : placeholderProp;
|
|
917
|
-
return /* @__PURE__ */
|
|
937
|
+
return /* @__PURE__ */ import_react23.default.createElement(
|
|
918
938
|
PureUniformText,
|
|
919
939
|
{
|
|
920
940
|
...props,
|
|
@@ -947,14 +967,14 @@ var getParameterAttributes = (options) => {
|
|
|
947
967
|
|
|
948
968
|
// src/hooks/useCompositionEventEffect.ts
|
|
949
969
|
var import_canvas13 = require("@uniformdev/canvas");
|
|
950
|
-
var
|
|
970
|
+
var import_react24 = require("react");
|
|
951
971
|
function useCompositionEventEffect({
|
|
952
972
|
enabled,
|
|
953
973
|
projectId,
|
|
954
974
|
compositionId,
|
|
955
975
|
effect
|
|
956
976
|
}) {
|
|
957
|
-
(0,
|
|
977
|
+
(0, import_react24.useEffect)(() => {
|
|
958
978
|
if (!enabled || !compositionId || !projectId) {
|
|
959
979
|
return;
|
|
960
980
|
}
|
|
@@ -983,17 +1003,17 @@ function useCompositionEventEffect({
|
|
|
983
1003
|
|
|
984
1004
|
// src/hooks/useUniformContextualEditingState.ts
|
|
985
1005
|
var import_canvas14 = require("@uniformdev/canvas");
|
|
986
|
-
var
|
|
1006
|
+
var import_react25 = require("react");
|
|
987
1007
|
var useUniformContextualEditingState = ({
|
|
988
1008
|
global = false
|
|
989
1009
|
} = {}) => {
|
|
990
1010
|
const { isContextualEditing } = useUniformCurrentComposition();
|
|
991
1011
|
const { data: componentData } = useUniformCurrentComponent();
|
|
992
|
-
const [selectedComponentReference, setSelectedComponentReference] = (0,
|
|
993
|
-
const [previewMode, setPreviewMode] = (0,
|
|
1012
|
+
const [selectedComponentReference, setSelectedComponentReference] = (0, import_react25.useState)();
|
|
1013
|
+
const [previewMode, setPreviewMode] = (0, import_react25.useState)(
|
|
994
1014
|
isContextualEditing ? "editor" : void 0
|
|
995
1015
|
);
|
|
996
|
-
const channel = (0,
|
|
1016
|
+
const channel = (0, import_react25.useMemo)(() => {
|
|
997
1017
|
if (!isContextualEditing) {
|
|
998
1018
|
return;
|
|
999
1019
|
}
|
|
@@ -1003,7 +1023,7 @@ var useUniformContextualEditingState = ({
|
|
|
1003
1023
|
});
|
|
1004
1024
|
return channel2;
|
|
1005
1025
|
}, [isContextualEditing]);
|
|
1006
|
-
(0,
|
|
1026
|
+
(0, import_react25.useEffect)(() => {
|
|
1007
1027
|
var _a, _b;
|
|
1008
1028
|
if (!channel) {
|
|
1009
1029
|
return;
|
|
@@ -1027,7 +1047,7 @@ var useUniformContextualEditingState = ({
|
|
|
1027
1047
|
unsubscribe();
|
|
1028
1048
|
};
|
|
1029
1049
|
}, [global, channel, componentData == null ? void 0 : componentData._id, setSelectedComponentReference, setPreviewMode]);
|
|
1030
|
-
return (0,
|
|
1050
|
+
return (0, import_react25.useMemo)(
|
|
1031
1051
|
() => ({
|
|
1032
1052
|
isContextualEditing,
|
|
1033
1053
|
selectedComponentReference,
|
package/dist/index.mjs
CHANGED
|
@@ -690,15 +690,12 @@ import {
|
|
|
690
690
|
ATTRIBUTE_PARAMETER_ID,
|
|
691
691
|
ATTRIBUTE_PARAMETER_TYPE
|
|
692
692
|
} from "@uniformdev/canvas";
|
|
693
|
-
import {
|
|
694
|
-
|
|
695
|
-
isRichTextValueConsideredEmpty
|
|
696
|
-
} from "@uniformdev/richtext";
|
|
697
|
-
import React18, { useMemo as useMemo5 } from "react";
|
|
693
|
+
import { isRichTextValue, isRichTextValueConsideredEmpty } from "@uniformdev/richtext";
|
|
694
|
+
import React19 from "react";
|
|
698
695
|
|
|
699
696
|
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
700
697
|
import { isRichTextNode } from "@uniformdev/richtext";
|
|
701
|
-
import
|
|
698
|
+
import React18 from "react";
|
|
702
699
|
|
|
703
700
|
// src/components/UniformRichText/nodes/HeadingRichTextNode.tsx
|
|
704
701
|
import React9 from "react";
|
|
@@ -752,19 +749,28 @@ var ParagraphRichTextNode = ({ children, node }) => {
|
|
|
752
749
|
);
|
|
753
750
|
};
|
|
754
751
|
|
|
755
|
-
// src/components/UniformRichText/nodes/
|
|
752
|
+
// src/components/UniformRichText/nodes/TableCellRichTextNode.tsx
|
|
753
|
+
import { getRichTextTagFromTableCellHeaderState } from "@uniformdev/richtext";
|
|
756
754
|
import React15 from "react";
|
|
755
|
+
var TableCellRichTextNode = ({ children, node }) => {
|
|
756
|
+
const { headerState } = node;
|
|
757
|
+
const TableCellTag = getRichTextTagFromTableCellHeaderState(headerState);
|
|
758
|
+
return /* @__PURE__ */ React15.createElement(TableCellTag, null, children);
|
|
759
|
+
};
|
|
760
|
+
|
|
761
|
+
// src/components/UniformRichText/nodes/TabRichTextNode.tsx
|
|
762
|
+
import React16 from "react";
|
|
757
763
|
var TabRichTextNode = () => {
|
|
758
|
-
return /* @__PURE__ */
|
|
764
|
+
return /* @__PURE__ */ React16.createElement(React16.Fragment, null, " ");
|
|
759
765
|
};
|
|
760
766
|
|
|
761
767
|
// src/components/UniformRichText/nodes/TextRichTextNode.tsx
|
|
762
768
|
import { getRichTextTagsFromTextFormat } from "@uniformdev/richtext";
|
|
763
|
-
import
|
|
769
|
+
import React17 from "react";
|
|
764
770
|
var TextRichTextNode = ({ node }) => {
|
|
765
771
|
const { text, format } = node;
|
|
766
772
|
const tags = getRichTextTagsFromTextFormat(format);
|
|
767
|
-
return /* @__PURE__ */
|
|
773
|
+
return /* @__PURE__ */ React17.createElement(React17.Fragment, null, tags.length > 0 ? tags.reduceRight((children, Tag) => /* @__PURE__ */ React17.createElement(Tag, null, children), text) : text);
|
|
768
774
|
};
|
|
769
775
|
|
|
770
776
|
// src/components/UniformRichText/UniformRichTextNode.tsx
|
|
@@ -778,8 +784,8 @@ function UniformRichTextNode({ node, ...props }) {
|
|
|
778
784
|
if (!NodeRenderer) {
|
|
779
785
|
return null;
|
|
780
786
|
}
|
|
781
|
-
const children = node.children ? node.children.map((childNode, i) => /* @__PURE__ */
|
|
782
|
-
return /* @__PURE__ */
|
|
787
|
+
const children = node.children ? node.children.map((childNode, i) => /* @__PURE__ */ React18.createElement(UniformRichTextNode, { ...props, key: i, node: childNode })) : null;
|
|
788
|
+
return /* @__PURE__ */ React18.createElement(NodeRenderer, { node }, children);
|
|
783
789
|
}
|
|
784
790
|
var rendererMap = /* @__PURE__ */ new Map([
|
|
785
791
|
["heading", HeadingRichTextNode],
|
|
@@ -788,48 +794,59 @@ var rendererMap = /* @__PURE__ */ new Map([
|
|
|
788
794
|
["list", ListRichTextNode],
|
|
789
795
|
["listitem", ListItemRichTextNode],
|
|
790
796
|
["paragraph", ParagraphRichTextNode],
|
|
791
|
-
["quote", ({ children }) => /* @__PURE__ */
|
|
797
|
+
["quote", ({ children }) => /* @__PURE__ */ React18.createElement("blockquote", null, children)],
|
|
792
798
|
[
|
|
793
799
|
"code",
|
|
794
|
-
({ children }) => /* @__PURE__ */
|
|
800
|
+
({ children }) => /* @__PURE__ */ React18.createElement("pre", null, /* @__PURE__ */ React18.createElement("code", null, children))
|
|
795
801
|
],
|
|
796
|
-
["root", ({ children }) => /* @__PURE__ */
|
|
802
|
+
["root", ({ children }) => /* @__PURE__ */ React18.createElement(React18.Fragment, null, children)],
|
|
797
803
|
["text", TextRichTextNode],
|
|
798
|
-
["tab", TabRichTextNode]
|
|
804
|
+
["tab", TabRichTextNode],
|
|
805
|
+
[
|
|
806
|
+
"table",
|
|
807
|
+
({ children }) => /* @__PURE__ */ React18.createElement("table", null, /* @__PURE__ */ React18.createElement("tbody", null, children))
|
|
808
|
+
],
|
|
809
|
+
["tablerow", ({ children }) => /* @__PURE__ */ React18.createElement("tr", null, children)],
|
|
810
|
+
["tablecell", TableCellRichTextNode]
|
|
799
811
|
]);
|
|
800
812
|
var resolveRichTextDefaultRenderer = (node) => {
|
|
801
813
|
return rendererMap.get(node.type);
|
|
802
814
|
};
|
|
803
815
|
|
|
804
816
|
// src/components/UniformRichText/UniformRichText.tsx
|
|
805
|
-
var UniformRichText =
|
|
806
|
-
|
|
807
|
-
const
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
817
|
+
var UniformRichText = React19.forwardRef(function UniformRichText2({ parameterId, resolveRichTextRenderer, as: Tag = "div", placeholder, ...props }, ref) {
|
|
818
|
+
var _a;
|
|
819
|
+
const { data: componentData, contextualEditingDefaultPlaceholder } = useUniformCurrentComponent();
|
|
820
|
+
const { isContextualEditing } = useUniformCurrentComposition();
|
|
821
|
+
const parameter = (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
|
|
822
|
+
if (!parameter) {
|
|
823
|
+
return null;
|
|
824
|
+
}
|
|
825
|
+
const placeholderProp = placeholder != null ? placeholder : contextualEditingDefaultPlaceholder;
|
|
826
|
+
const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: parameterId }) : placeholderProp;
|
|
827
|
+
const value = parameter.value;
|
|
828
|
+
if (!value || !isRichTextValue(value)) return null;
|
|
829
|
+
if (!isContextualEditing && isRichTextValueConsideredEmpty(value)) return null;
|
|
830
|
+
return Tag === null ? /* @__PURE__ */ React19.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ React19.createElement(
|
|
814
831
|
Tag,
|
|
815
832
|
{
|
|
816
833
|
ref,
|
|
817
834
|
...props,
|
|
818
|
-
...{
|
|
835
|
+
...isContextualEditing ? {
|
|
819
836
|
[ATTRIBUTE_COMPONENT_ID]: componentData == null ? void 0 : componentData._id,
|
|
820
837
|
[ATTRIBUTE_PARAMETER_ID]: parameterId,
|
|
821
838
|
[ATTRIBUTE_PARAMETER_TYPE]: "richText"
|
|
822
|
-
}
|
|
839
|
+
} : {}
|
|
823
840
|
},
|
|
824
|
-
/* @__PURE__ */
|
|
841
|
+
isRichTextValueConsideredEmpty(value) ? /* @__PURE__ */ React19.createElement("p", null, /* @__PURE__ */ React19.createElement("i", null, computedPlaceholder)) : /* @__PURE__ */ React19.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer })
|
|
825
842
|
);
|
|
826
843
|
});
|
|
827
844
|
|
|
828
845
|
// src/components/UniformText.tsx
|
|
829
|
-
import
|
|
846
|
+
import React21, { useState as useState2 } from "react";
|
|
830
847
|
|
|
831
848
|
// src/components/PureUniformText.tsx
|
|
832
|
-
import
|
|
849
|
+
import React20 from "react";
|
|
833
850
|
var PureUniformText = ({
|
|
834
851
|
as: Tag = "span",
|
|
835
852
|
parameterId,
|
|
@@ -848,10 +865,10 @@ var PureUniformText = ({
|
|
|
848
865
|
return null;
|
|
849
866
|
}
|
|
850
867
|
if (!isContextualEditing) {
|
|
851
|
-
return /* @__PURE__ */
|
|
868
|
+
return /* @__PURE__ */ React20.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
|
|
852
869
|
}
|
|
853
870
|
const computedPlaceholder = typeof placeholder === "function" ? placeholder({ id: parameterId }) : placeholder;
|
|
854
|
-
return /* @__PURE__ */
|
|
871
|
+
return /* @__PURE__ */ React20.createElement(
|
|
855
872
|
Tag,
|
|
856
873
|
{
|
|
857
874
|
...props,
|
|
@@ -889,7 +906,7 @@ var UniformText = ({
|
|
|
889
906
|
}
|
|
890
907
|
const placeholderProp = placeholder != null ? placeholder : contextualEditingDefaultPlaceholder;
|
|
891
908
|
const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: parameterId }) : placeholderProp;
|
|
892
|
-
return /* @__PURE__ */
|
|
909
|
+
return /* @__PURE__ */ React21.createElement(
|
|
893
910
|
PureUniformText,
|
|
894
911
|
{
|
|
895
912
|
...props,
|
|
@@ -967,7 +984,7 @@ import {
|
|
|
967
984
|
createCanvasChannel as createCanvasChannel2,
|
|
968
985
|
isUpdateContextualEditingStateInternalMessage
|
|
969
986
|
} from "@uniformdev/canvas";
|
|
970
|
-
import { useEffect as useEffect3, useMemo as
|
|
987
|
+
import { useEffect as useEffect3, useMemo as useMemo5, useState as useState3 } from "react";
|
|
971
988
|
var useUniformContextualEditingState = ({
|
|
972
989
|
global = false
|
|
973
990
|
} = {}) => {
|
|
@@ -977,7 +994,7 @@ var useUniformContextualEditingState = ({
|
|
|
977
994
|
const [previewMode, setPreviewMode] = useState3(
|
|
978
995
|
isContextualEditing ? "editor" : void 0
|
|
979
996
|
);
|
|
980
|
-
const channel =
|
|
997
|
+
const channel = useMemo5(() => {
|
|
981
998
|
if (!isContextualEditing) {
|
|
982
999
|
return;
|
|
983
1000
|
}
|
|
@@ -1011,7 +1028,7 @@ var useUniformContextualEditingState = ({
|
|
|
1011
1028
|
unsubscribe();
|
|
1012
1029
|
};
|
|
1013
1030
|
}, [global, channel, componentData == null ? void 0 : componentData._id, setSelectedComponentReference, setPreviewMode]);
|
|
1014
|
-
return
|
|
1031
|
+
return useMemo5(
|
|
1015
1032
|
() => ({
|
|
1016
1033
|
isContextualEditing,
|
|
1017
1034
|
selectedComponentReference,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-react",
|
|
3
|
-
"version": "19.178.
|
|
3
|
+
"version": "19.178.2-alpha.25+0f7f53f560",
|
|
4
4
|
"description": "React SDK for Uniform Canvas",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"document": "api-extractor run --local"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@uniformdev/canvas": "19.178.
|
|
49
|
-
"@uniformdev/context": "19.178.
|
|
50
|
-
"@uniformdev/context-react": "19.178.
|
|
51
|
-
"@uniformdev/richtext": "19.178.
|
|
48
|
+
"@uniformdev/canvas": "19.178.2-alpha.25+0f7f53f560",
|
|
49
|
+
"@uniformdev/context": "19.178.2-alpha.25+0f7f53f560",
|
|
50
|
+
"@uniformdev/context-react": "19.178.2-alpha.25+0f7f53f560",
|
|
51
|
+
"@uniformdev/richtext": "19.178.2-alpha.25+0f7f53f560"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"immer": ">= 10",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"publishConfig": {
|
|
68
68
|
"access": "public"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "0f7f53f56071a59cee38bf83c9f3bae541846de2"
|
|
71
71
|
}
|