@uniformdev/canvas-react 19.21.0 → 19.22.1-alpha.8

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,4 +1,5 @@
1
1
  import React$1, { Key, ReactNode, PropsWithChildren } from 'react';
2
+ import * as _uniformdev_canvas from '@uniformdev/canvas';
2
3
  import { ComponentInstance, RootComponentInstance, UpdateCompositionMessage, SubscribeToCompositionOptions } from '@uniformdev/canvas';
3
4
  export { createUniformApiEnhancer } from '@uniformdev/canvas';
4
5
  import { RichTextNode } from '@uniformdev/richtext';
@@ -353,6 +354,24 @@ type UseCompositionEventEffectOptions = Omit<Partial<SubscribeToCompositionOptio
353
354
  /** Hook to manage a subscription to a realtime event on a composition */
354
355
  declare function useCompositionEventEffect({ enabled, projectId, compositionId, effect, }: UseCompositionEventEffectOptions): void;
355
356
 
357
+ type UseUniformContextualEditingStateProps = {
358
+ /**
359
+ * When set to true, the hook will return the global contextual state no matter where its used.
360
+ * When set to false, it will return only the state relevant to the current component (determined using `useUniformCurrentComponent`).
361
+ * @default false
362
+ **/
363
+ global?: boolean;
364
+ };
365
+ /**
366
+ * Returns the state of contextual editing, when the app is open inside Canvas Editor.
367
+ * This hook can be used to improve the editing experience of your team.
368
+ * For example: You can use `selectedComponentReference` to control which element to show inside a carousel or an accordion.
369
+ */
370
+ declare const useUniformContextualEditingState: ({ global, }?: UseUniformContextualEditingStateProps) => {
371
+ isContextualEditing: boolean;
372
+ selectedComponentReference: Omit<_uniformdev_canvas.ContextualEditingComponentReference, "elements"> | undefined;
373
+ };
374
+
356
375
  declare const componentStore: ComponentStore;
357
376
  declare const registerUniformComponent: ({ type, variantId, component, }: {
358
377
  type: string;
@@ -369,4 +388,4 @@ declare const createComponentStoreResolver: (options: {
369
388
  defaultComponent?: React$1.ComponentType<ComponentProps<any>>;
370
389
  }) => RenderComponentResolver;
371
390
 
372
- 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, componentStore, componentStoreResolver, createComponentStore, createComponentStoreResolver, getParameterAttributes, registerUniformComponent, useCompositionEventEffect, useUniformContextualEditing, useUniformCurrentComponent, useUniformCurrentComposition };
391
+ 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 };
package/dist/index.esm.js CHANGED
@@ -791,6 +791,53 @@ function useCompositionEventEffect({
791
791
  };
792
792
  }, [compositionId, enabled, projectId, effect]);
793
793
  }
794
+
795
+ // src/hooks/useUniformContextualEditingState.ts
796
+ import {
797
+ createCanvasChannel as createCanvasChannel2,
798
+ isUpdateContextualEditingStateInternalMessage
799
+ } from "@uniformdev/canvas";
800
+ import { useEffect as useEffect3, useMemo as useMemo4, useState as useState3 } from "react";
801
+ var useUniformContextualEditingState = ({
802
+ global = false
803
+ } = {}) => {
804
+ const { isContextualEditing } = useUniformCurrentComposition();
805
+ const { data: componentData } = useUniformCurrentComponent();
806
+ const [selectedComponentReference, setSelectedComponentReference] = useState3();
807
+ const channel = useMemo4(() => {
808
+ if (!isContextualEditing) {
809
+ return;
810
+ }
811
+ const channel2 = createCanvasChannel2({
812
+ broadcastTo: [window],
813
+ listenTo: [window]
814
+ });
815
+ return channel2;
816
+ }, [isContextualEditing]);
817
+ useEffect3(() => {
818
+ if (!channel) {
819
+ return;
820
+ }
821
+ const unsubscribe = channel.on("update-contextual-editing-state-internal", async (message) => {
822
+ var _a;
823
+ if (!isUpdateContextualEditingStateInternalMessage(message)) {
824
+ return;
825
+ }
826
+ if (!global && (componentData == null ? void 0 : componentData._id) !== ((_a = message.state.selectedComponentReference) == null ? void 0 : _a.parentId)) {
827
+ setSelectedComponentReference(void 0);
828
+ return;
829
+ }
830
+ setSelectedComponentReference(message.state.selectedComponentReference);
831
+ });
832
+ return () => {
833
+ unsubscribe();
834
+ };
835
+ }, [global, channel, componentData == null ? void 0 : componentData._id]);
836
+ return {
837
+ isContextualEditing,
838
+ selectedComponentReference
839
+ };
840
+ };
794
841
  export {
795
842
  DefaultNotImplementedComponent,
796
843
  NOT_IMPLEMENTED_COMPONENT,
@@ -809,6 +856,7 @@ export {
809
856
  registerUniformComponent,
810
857
  useCompositionEventEffect,
811
858
  useUniformContextualEditing,
859
+ useUniformContextualEditingState,
812
860
  useUniformCurrentComponent,
813
861
  useUniformCurrentComposition
814
862
  };
package/dist/index.js CHANGED
@@ -47,6 +47,7 @@ __export(src_exports, {
47
47
  registerUniformComponent: () => registerUniformComponent,
48
48
  useCompositionEventEffect: () => useCompositionEventEffect,
49
49
  useUniformContextualEditing: () => useUniformContextualEditing,
50
+ useUniformContextualEditingState: () => useUniformContextualEditingState,
50
51
  useUniformCurrentComponent: () => useUniformCurrentComponent,
51
52
  useUniformCurrentComposition: () => useUniformCurrentComposition
52
53
  });
@@ -818,6 +819,50 @@ function useCompositionEventEffect({
818
819
  };
819
820
  }, [compositionId, enabled, projectId, effect]);
820
821
  }
822
+
823
+ // src/hooks/useUniformContextualEditingState.ts
824
+ var import_canvas8 = require("@uniformdev/canvas");
825
+ var import_react19 = require("react");
826
+ var useUniformContextualEditingState = ({
827
+ global = false
828
+ } = {}) => {
829
+ const { isContextualEditing } = useUniformCurrentComposition();
830
+ const { data: componentData } = useUniformCurrentComponent();
831
+ const [selectedComponentReference, setSelectedComponentReference] = (0, import_react19.useState)();
832
+ const channel = (0, import_react19.useMemo)(() => {
833
+ if (!isContextualEditing) {
834
+ return;
835
+ }
836
+ const channel2 = (0, import_canvas8.createCanvasChannel)({
837
+ broadcastTo: [window],
838
+ listenTo: [window]
839
+ });
840
+ return channel2;
841
+ }, [isContextualEditing]);
842
+ (0, import_react19.useEffect)(() => {
843
+ if (!channel) {
844
+ return;
845
+ }
846
+ const unsubscribe = channel.on("update-contextual-editing-state-internal", async (message) => {
847
+ var _a;
848
+ if (!(0, import_canvas8.isUpdateContextualEditingStateInternalMessage)(message)) {
849
+ return;
850
+ }
851
+ if (!global && (componentData == null ? void 0 : componentData._id) !== ((_a = message.state.selectedComponentReference) == null ? void 0 : _a.parentId)) {
852
+ setSelectedComponentReference(void 0);
853
+ return;
854
+ }
855
+ setSelectedComponentReference(message.state.selectedComponentReference);
856
+ });
857
+ return () => {
858
+ unsubscribe();
859
+ };
860
+ }, [global, channel, componentData == null ? void 0 : componentData._id]);
861
+ return {
862
+ isContextualEditing,
863
+ selectedComponentReference
864
+ };
865
+ };
821
866
  // Annotate the CommonJS export names for ESM import in node:
822
867
  0 && (module.exports = {
823
868
  DefaultNotImplementedComponent,
@@ -837,6 +882,7 @@ function useCompositionEventEffect({
837
882
  registerUniformComponent,
838
883
  useCompositionEventEffect,
839
884
  useUniformContextualEditing,
885
+ useUniformContextualEditingState,
840
886
  useUniformCurrentComponent,
841
887
  useUniformCurrentComposition
842
888
  });
package/dist/index.mjs CHANGED
@@ -791,6 +791,53 @@ function useCompositionEventEffect({
791
791
  };
792
792
  }, [compositionId, enabled, projectId, effect]);
793
793
  }
794
+
795
+ // src/hooks/useUniformContextualEditingState.ts
796
+ import {
797
+ createCanvasChannel as createCanvasChannel2,
798
+ isUpdateContextualEditingStateInternalMessage
799
+ } from "@uniformdev/canvas";
800
+ import { useEffect as useEffect3, useMemo as useMemo4, useState as useState3 } from "react";
801
+ var useUniformContextualEditingState = ({
802
+ global = false
803
+ } = {}) => {
804
+ const { isContextualEditing } = useUniformCurrentComposition();
805
+ const { data: componentData } = useUniformCurrentComponent();
806
+ const [selectedComponentReference, setSelectedComponentReference] = useState3();
807
+ const channel = useMemo4(() => {
808
+ if (!isContextualEditing) {
809
+ return;
810
+ }
811
+ const channel2 = createCanvasChannel2({
812
+ broadcastTo: [window],
813
+ listenTo: [window]
814
+ });
815
+ return channel2;
816
+ }, [isContextualEditing]);
817
+ useEffect3(() => {
818
+ if (!channel) {
819
+ return;
820
+ }
821
+ const unsubscribe = channel.on("update-contextual-editing-state-internal", async (message) => {
822
+ var _a;
823
+ if (!isUpdateContextualEditingStateInternalMessage(message)) {
824
+ return;
825
+ }
826
+ if (!global && (componentData == null ? void 0 : componentData._id) !== ((_a = message.state.selectedComponentReference) == null ? void 0 : _a.parentId)) {
827
+ setSelectedComponentReference(void 0);
828
+ return;
829
+ }
830
+ setSelectedComponentReference(message.state.selectedComponentReference);
831
+ });
832
+ return () => {
833
+ unsubscribe();
834
+ };
835
+ }, [global, channel, componentData == null ? void 0 : componentData._id]);
836
+ return {
837
+ isContextualEditing,
838
+ selectedComponentReference
839
+ };
840
+ };
794
841
  export {
795
842
  DefaultNotImplementedComponent,
796
843
  NOT_IMPLEMENTED_COMPONENT,
@@ -809,6 +856,7 @@ export {
809
856
  registerUniformComponent,
810
857
  useCompositionEventEffect,
811
858
  useUniformContextualEditing,
859
+ useUniformContextualEditingState,
812
860
  useUniformCurrentComponent,
813
861
  useUniformCurrentComposition
814
862
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-react",
3
- "version": "19.21.0",
3
+ "version": "19.22.1-alpha.8+a8f730b12",
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.21.0",
28
- "@uniformdev/context": "19.21.0",
29
- "@uniformdev/context-react": "19.21.0",
30
- "@uniformdev/richtext": "19.21.0"
27
+ "@uniformdev/canvas": "19.22.1-alpha.8+a8f730b12",
28
+ "@uniformdev/context": "19.22.1-alpha.8+a8f730b12",
29
+ "@uniformdev/context-react": "19.22.1-alpha.8+a8f730b12",
30
+ "@uniformdev/richtext": "19.22.1-alpha.8+a8f730b12"
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": "3db4c0f1c775a5cf9677c6df294322cfbf79611e"
47
+ "gitHead": "a8f730b12035a4d7c2e6a704d3777ff12df52ffc"
48
48
  }