@uniformdev/canvas-react 19.135.1-alpha.10 → 19.135.1-alpha.11

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.mjs CHANGED
@@ -233,6 +233,50 @@ var PureContextualEditingComponentWrapper = ({
233
233
  // src/components/UniformComposition.tsx
234
234
  import React4, { createContext, useContext } from "react";
235
235
 
236
+ // src/hooks/useClientConditionsComposition.ts
237
+ import {
238
+ evaluateWalkTreeNodeVisibility,
239
+ evaluateWalkTreePropertyCriteria,
240
+ walkNodeTree
241
+ } from "@uniformdev/canvas";
242
+ import { produce } from "immer";
243
+ import { useMemo as useMemo2 } from "react";
244
+
245
+ // src/hooks/useClientVisibilityRules.ts
246
+ import { createQuirksVisibilityRule } from "@uniformdev/canvas";
247
+ import { useQuirks } from "@uniformdev/context-react";
248
+ import { useMemo } from "react";
249
+ function useClientVisibilityRules() {
250
+ const quirks = useQuirks({ throwOnMissingProvider: false });
251
+ return useMemo(() => {
252
+ return {
253
+ ...createQuirksVisibilityRule(quirks)
254
+ };
255
+ }, [quirks]);
256
+ }
257
+
258
+ // src/hooks/useClientConditionsComposition.ts
259
+ function useClientConditionsComposition(data) {
260
+ const rules = useClientVisibilityRules();
261
+ const preprocessedValue = useMemo2(() => {
262
+ if (!data) {
263
+ return data;
264
+ }
265
+ try {
266
+ return produce(data, (draft) => {
267
+ walkNodeTree(draft, (context) => {
268
+ evaluateWalkTreeNodeVisibility({ context, rules, showIndeterminate: false });
269
+ evaluateWalkTreePropertyCriteria({ node: context.node, rules, keepIndeterminate: false });
270
+ });
271
+ });
272
+ } catch (e) {
273
+ console.error("Error evaluating visibility rules:", e.stack);
274
+ return data;
275
+ }
276
+ }, [data, rules]);
277
+ return preprocessedValue;
278
+ }
279
+
236
280
  // src/hooks/useUniformContextualEditing.ts
237
281
  import {
238
282
  createCanvasChannel,
@@ -243,7 +287,7 @@ import {
243
287
  isAllowedReferrer,
244
288
  isUpdateCompositionInternalMessage
245
289
  } from "@uniformdev/canvas";
246
- import { useEffect, useMemo, useRef, useState } from "react";
290
+ import { useEffect, useMemo as useMemo3, useRef, useState } from "react";
247
291
  var registeredCompositionIds = /* @__PURE__ */ new Set();
248
292
  var useUniformContextualEditing = ({
249
293
  initialCompositionValue,
@@ -251,7 +295,7 @@ var useUniformContextualEditing = ({
251
295
  }) => {
252
296
  const [contextualComposition, setContextualComposition] = useState();
253
297
  const latestEventTimeStamp = useRef();
254
- const channel = useMemo(() => {
298
+ const channel = useMemo3(() => {
255
299
  var _a;
256
300
  if (!isInContextEditingMode()) {
257
301
  return;
@@ -341,8 +385,9 @@ function UniformComposition({
341
385
  contextualEditingEnhancer,
342
386
  contextualEditingDefaultPlaceholder
343
387
  }) {
388
+ const ruledComposition = useClientConditionsComposition(data);
344
389
  const { composition, isContextualEditing } = useUniformContextualEditing({
345
- initialCompositionValue: data,
390
+ initialCompositionValue: ruledComposition,
346
391
  enhance: contextualEditingEnhancer
347
392
  });
348
393
  return /* @__PURE__ */ React4.createElement(
@@ -605,20 +650,19 @@ function resolveChildren({
605
650
 
606
651
  // src/components/UniformPlayground.tsx
607
652
  import { EMPTY_COMPOSITION as EMPTY_COMPOSITION4 } from "@uniformdev/canvas";
608
- import React8, { useMemo as useMemo2 } from "react";
653
+ import React8, { useMemo as useMemo4 } from "react";
609
654
  var UniformPlayground = ({
610
655
  resolveRenderer,
611
656
  decorators = [],
612
657
  contextualEditingEnhancer,
613
658
  behaviorTracking,
614
- contextualEditingDefaultPlaceholder,
615
- children
659
+ contextualEditingDefaultPlaceholder
616
660
  }) => {
617
661
  const { composition, isContextualEditing } = useUniformContextualEditing({
618
662
  initialCompositionValue: EMPTY_COMPOSITION4,
619
663
  enhance: contextualEditingEnhancer
620
664
  });
621
- const renderedComponent = useMemo2(() => {
665
+ const renderedComponent = useMemo4(() => {
622
666
  if (!composition) {
623
667
  return null;
624
668
  }
@@ -629,21 +673,13 @@ var UniformPlayground = ({
629
673
  behaviorTracking,
630
674
  resolveRenderer,
631
675
  contextualEditingDefaultPlaceholder
632
- },
633
- children
676
+ }
634
677
  ));
635
678
  decorators.forEach((Decorator) => {
636
679
  component = /* @__PURE__ */ React8.createElement(Decorator, { data: composition }, component);
637
680
  });
638
681
  return component;
639
- }, [
640
- children,
641
- resolveRenderer,
642
- decorators,
643
- composition,
644
- behaviorTracking,
645
- contextualEditingDefaultPlaceholder
646
- ]);
682
+ }, [resolveRenderer, decorators, composition, behaviorTracking, contextualEditingDefaultPlaceholder]);
647
683
  return /* @__PURE__ */ React8.createElement(
648
684
  UniformCompositionContext.Provider,
649
685
  {
@@ -659,15 +695,12 @@ import {
659
695
  ATTRIBUTE_PARAMETER_ID,
660
696
  ATTRIBUTE_PARAMETER_TYPE
661
697
  } from "@uniformdev/canvas";
662
- import {
663
- isRichTextValue,
664
- isRichTextValueConsideredEmpty
665
- } from "@uniformdev/richtext";
666
- import React18, { useMemo as useMemo3 } from "react";
698
+ import { isRichTextValue, isRichTextValueConsideredEmpty } from "@uniformdev/richtext";
699
+ import React19 from "react";
667
700
 
668
701
  // src/components/UniformRichText/UniformRichTextNode.tsx
669
702
  import { isRichTextNode } from "@uniformdev/richtext";
670
- import React17 from "react";
703
+ import React18 from "react";
671
704
 
672
705
  // src/components/UniformRichText/nodes/HeadingRichTextNode.tsx
673
706
  import React9 from "react";
@@ -721,26 +754,34 @@ var ParagraphRichTextNode = ({ children, node }) => {
721
754
  );
722
755
  };
723
756
 
724
- // src/components/UniformRichText/nodes/TabRichTextNode.tsx
757
+ // src/components/UniformRichText/nodes/TableCellRichTextNode.tsx
758
+ import { getRichTextTagFromTableCellHeaderState } from "@uniformdev/richtext";
725
759
  import React15 from "react";
760
+ var TableCellRichTextNode = ({ children, node }) => {
761
+ const { headerState } = node;
762
+ const TableCellTag = getRichTextTagFromTableCellHeaderState(headerState);
763
+ return /* @__PURE__ */ React15.createElement(TableCellTag, null, children);
764
+ };
765
+
766
+ // src/components/UniformRichText/nodes/TabRichTextNode.tsx
767
+ import React16 from "react";
726
768
  var TabRichTextNode = () => {
727
- return /* @__PURE__ */ React15.createElement(React15.Fragment, null, " ");
769
+ return /* @__PURE__ */ React16.createElement(React16.Fragment, null, " ");
728
770
  };
729
771
 
730
772
  // src/components/UniformRichText/nodes/TextRichTextNode.tsx
731
773
  import { getRichTextTagsFromTextFormat } from "@uniformdev/richtext";
732
- import React16 from "react";
774
+ import React17 from "react";
733
775
  var TextRichTextNode = ({ node }) => {
734
776
  const { text, format } = node;
735
777
  const tags = getRichTextTagsFromTextFormat(format);
736
- return /* @__PURE__ */ React16.createElement(React16.Fragment, null, tags.length > 0 ? tags.reduceRight((children, Tag) => /* @__PURE__ */ React16.createElement(Tag, null, children), text) : text);
778
+ return /* @__PURE__ */ React17.createElement(React17.Fragment, null, tags.length > 0 ? tags.reduceRight((children, Tag) => /* @__PURE__ */ React17.createElement(Tag, null, children), text) : text);
737
779
  };
738
780
 
739
781
  // src/components/UniformRichText/UniformRichTextNode.tsx
740
782
  function UniformRichTextNode({ node, ...props }) {
741
783
  var _a;
742
- if (!isRichTextNode(node))
743
- return null;
784
+ if (!isRichTextNode(node)) return null;
744
785
  let NodeRenderer = (_a = props.resolveRichTextRenderer) == null ? void 0 : _a.call(props, node);
745
786
  if (typeof NodeRenderer === "undefined") {
746
787
  NodeRenderer = resolveRichTextDefaultRenderer(node);
@@ -748,8 +789,8 @@ function UniformRichTextNode({ node, ...props }) {
748
789
  if (!NodeRenderer) {
749
790
  return null;
750
791
  }
751
- const children = node.children ? node.children.map((childNode, i) => /* @__PURE__ */ React17.createElement(UniformRichTextNode, { ...props, key: i, node: childNode })) : null;
752
- return /* @__PURE__ */ React17.createElement(NodeRenderer, { node }, children);
792
+ const children = node.children ? node.children.map((childNode, i) => /* @__PURE__ */ React18.createElement(UniformRichTextNode, { ...props, key: i, node: childNode })) : null;
793
+ return /* @__PURE__ */ React18.createElement(NodeRenderer, { node }, children);
753
794
  }
754
795
  var rendererMap = /* @__PURE__ */ new Map([
755
796
  ["heading", HeadingRichTextNode],
@@ -758,49 +799,59 @@ var rendererMap = /* @__PURE__ */ new Map([
758
799
  ["list", ListRichTextNode],
759
800
  ["listitem", ListItemRichTextNode],
760
801
  ["paragraph", ParagraphRichTextNode],
761
- ["quote", ({ children }) => /* @__PURE__ */ React17.createElement("blockquote", null, children)],
802
+ ["quote", ({ children }) => /* @__PURE__ */ React18.createElement("blockquote", null, children)],
762
803
  [
763
804
  "code",
764
- ({ children }) => /* @__PURE__ */ React17.createElement("pre", null, /* @__PURE__ */ React17.createElement("code", null, children))
805
+ ({ children }) => /* @__PURE__ */ React18.createElement("pre", null, /* @__PURE__ */ React18.createElement("code", null, children))
765
806
  ],
766
- ["root", ({ children }) => /* @__PURE__ */ React17.createElement(React17.Fragment, null, children)],
807
+ ["root", ({ children }) => /* @__PURE__ */ React18.createElement(React18.Fragment, null, children)],
767
808
  ["text", TextRichTextNode],
768
- ["tab", TabRichTextNode]
809
+ ["tab", TabRichTextNode],
810
+ [
811
+ "table",
812
+ ({ children }) => /* @__PURE__ */ React18.createElement("table", null, /* @__PURE__ */ React18.createElement("tbody", null, children))
813
+ ],
814
+ ["tablerow", ({ children }) => /* @__PURE__ */ React18.createElement("tr", null, children)],
815
+ ["tablecell", TableCellRichTextNode]
769
816
  ]);
770
817
  var resolveRichTextDefaultRenderer = (node) => {
771
818
  return rendererMap.get(node.type);
772
819
  };
773
820
 
774
821
  // src/components/UniformRichText/UniformRichText.tsx
775
- var UniformRichText = React18.forwardRef(function UniformRichText2({ parameterId, resolveRichTextRenderer, as: Tag = "div", ...props }, ref) {
776
- const { data: componentData } = useUniformCurrentComponent();
777
- const parameter = useMemo3(() => {
778
- var _a;
779
- return (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
780
- }, [componentData, parameterId]);
781
- const value = useMemo3(() => parameter == null ? void 0 : parameter.value, [parameter]);
782
- if (!value || !isRichTextValue(value) || isRichTextValueConsideredEmpty(value))
822
+ var UniformRichText = React19.forwardRef(function UniformRichText2({ parameterId, resolveRichTextRenderer, as: Tag = "div", placeholder, ...props }, ref) {
823
+ var _a;
824
+ const { data: componentData, contextualEditingDefaultPlaceholder } = useUniformCurrentComponent();
825
+ const { isContextualEditing } = useUniformCurrentComposition();
826
+ const parameter = (_a = componentData == null ? void 0 : componentData.parameters) == null ? void 0 : _a[parameterId];
827
+ if (!parameter) {
783
828
  return null;
784
- return Tag === null ? /* @__PURE__ */ React18.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ React18.createElement(
829
+ }
830
+ const placeholderProp = placeholder != null ? placeholder : contextualEditingDefaultPlaceholder;
831
+ const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: parameterId }) : placeholderProp;
832
+ const value = parameter.value;
833
+ if (!value || !isRichTextValue(value)) return null;
834
+ if (!isContextualEditing && isRichTextValueConsideredEmpty(value)) return null;
835
+ return Tag === null ? /* @__PURE__ */ React19.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer }) : /* @__PURE__ */ React19.createElement(
785
836
  Tag,
786
837
  {
787
838
  ref,
788
839
  ...props,
789
- ...{
840
+ ...isContextualEditing ? {
790
841
  [ATTRIBUTE_COMPONENT_ID]: componentData == null ? void 0 : componentData._id,
791
842
  [ATTRIBUTE_PARAMETER_ID]: parameterId,
792
843
  [ATTRIBUTE_PARAMETER_TYPE]: "richText"
793
- }
844
+ } : {}
794
845
  },
795
- /* @__PURE__ */ React18.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer })
846
+ isRichTextValueConsideredEmpty(value) ? /* @__PURE__ */ React19.createElement("p", null, /* @__PURE__ */ React19.createElement("i", null, computedPlaceholder)) : /* @__PURE__ */ React19.createElement(UniformRichTextNode, { node: value.root, resolveRichTextRenderer })
796
847
  );
797
848
  });
798
849
 
799
850
  // src/components/UniformText.tsx
800
- import React20, { useState as useState2 } from "react";
851
+ import React21, { useState as useState2 } from "react";
801
852
 
802
853
  // src/components/PureUniformText.tsx
803
- import React19 from "react";
854
+ import React20 from "react";
804
855
  var PureUniformText = ({
805
856
  as: Tag = "span",
806
857
  parameterId,
@@ -819,10 +870,10 @@ var PureUniformText = ({
819
870
  return null;
820
871
  }
821
872
  if (!isContextualEditing) {
822
- return /* @__PURE__ */ React19.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
873
+ return /* @__PURE__ */ React20.createElement(Tag, { style: isMultiline ? { whiteSpace: "pre-wrap" } : {}, ...props }, render(value));
823
874
  }
824
875
  const computedPlaceholder = typeof placeholder === "function" ? placeholder({ id: parameterId }) : placeholder;
825
- return /* @__PURE__ */ React19.createElement(
876
+ return /* @__PURE__ */ React20.createElement(
826
877
  Tag,
827
878
  {
828
879
  ...props,
@@ -860,7 +911,7 @@ var UniformText = ({
860
911
  }
861
912
  const placeholderProp = placeholder != null ? placeholder : contextualEditingDefaultPlaceholder;
862
913
  const computedPlaceholder = typeof placeholderProp === "function" ? placeholderProp({ id: parameterId }) : placeholderProp;
863
- return /* @__PURE__ */ React20.createElement(
914
+ return /* @__PURE__ */ React21.createElement(
864
915
  PureUniformText,
865
916
  {
866
917
  ...props,
@@ -938,7 +989,7 @@ import {
938
989
  createCanvasChannel as createCanvasChannel2,
939
990
  isUpdateContextualEditingStateInternalMessage
940
991
  } from "@uniformdev/canvas";
941
- import { useEffect as useEffect3, useMemo as useMemo4, useState as useState3 } from "react";
992
+ import { useEffect as useEffect3, useMemo as useMemo5, useState as useState3 } from "react";
942
993
  var useUniformContextualEditingState = ({
943
994
  global = false
944
995
  } = {}) => {
@@ -948,7 +999,7 @@ var useUniformContextualEditingState = ({
948
999
  const [previewMode, setPreviewMode] = useState3(
949
1000
  isContextualEditing ? "editor" : void 0
950
1001
  );
951
- const channel = useMemo4(() => {
1002
+ const channel = useMemo5(() => {
952
1003
  if (!isContextualEditing) {
953
1004
  return;
954
1005
  }
@@ -982,7 +1033,7 @@ var useUniformContextualEditingState = ({
982
1033
  unsubscribe();
983
1034
  };
984
1035
  }, [global, channel, componentData == null ? void 0 : componentData._id, setSelectedComponentReference, setPreviewMode]);
985
- return useMemo4(
1036
+ return useMemo5(
986
1037
  () => ({
987
1038
  isContextualEditing,
988
1039
  selectedComponentReference,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-react",
3
- "version": "19.135.1-alpha.10+261b728b6b",
3
+ "version": "19.135.1-alpha.11+9f52e6cfd6",
4
4
  "description": "React SDK for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -45,19 +45,21 @@
45
45
  "document": "api-extractor run --local"
46
46
  },
47
47
  "dependencies": {
48
- "@uniformdev/canvas": "19.135.1-alpha.10+261b728b6b",
49
- "@uniformdev/context": "19.135.1-alpha.10+261b728b6b",
50
- "@uniformdev/context-react": "19.135.1-alpha.10+261b728b6b",
51
- "@uniformdev/richtext": "19.135.1-alpha.10+261b728b6b"
48
+ "@uniformdev/canvas": "19.135.1-alpha.11+9f52e6cfd6",
49
+ "@uniformdev/context": "19.135.1-alpha.11+9f52e6cfd6",
50
+ "@uniformdev/context-react": "19.135.1-alpha.11+9f52e6cfd6",
51
+ "@uniformdev/richtext": "19.135.1-alpha.11+9f52e6cfd6"
52
52
  },
53
53
  "peerDependencies": {
54
+ "immer": ">= 10",
54
55
  "react": ">= 16 || 17 || 18",
55
56
  "react-dom": ">=16"
56
57
  },
57
58
  "devDependencies": {
58
- "@types/react": "18.2.40",
59
- "react": "18.2.0",
60
- "react-dom": "18.2.0"
59
+ "@types/react": "18.3.3",
60
+ "immer": "10.1.1",
61
+ "react": "18.3.1",
62
+ "react-dom": "18.3.1"
61
63
  },
62
64
  "files": [
63
65
  "/dist"
@@ -65,5 +67,5 @@
65
67
  "publishConfig": {
66
68
  "access": "public"
67
69
  },
68
- "gitHead": "261b728b6bc036ca8260861715632078b3eb27ca"
70
+ "gitHead": "9f52e6cfd6e562e9c759735ba2a44378388a2a82"
69
71
  }