@uniformdev/canvas-react 19.142.0 → 19.142.2-alpha.1

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import React$1, { Key, ReactNode, PropsWithChildren } from 'react';
2
- import { ComponentInstance, RootComponentInstance, UpdateCompositionMessage, getParameterAttributes as getParameterAttributes$1, SubscribeToCompositionOptions } from '@uniformdev/canvas';
2
+ import { ComponentInstance, RootComponentInstance, UpdateCompositionMessage, getParameterAttributes as getParameterAttributes$1, SubscribeToCompositionOptions, UpdateContextualEditingStateInternalMessage } from '@uniformdev/canvas';
3
3
  export { GetParameterAttributesProps, createUniformApiEnhancer } from '@uniformdev/canvas';
4
4
  import { P as PureUniformTextProps } from './PureUniformText-B3GAm6Dc.mjs';
5
5
  import { RichTextNode } from '@uniformdev/richtext';
@@ -128,7 +128,7 @@ declare const useUniformContextualEditing: ({ initialCompositionValue, enhance,
128
128
  isSearchHit?: boolean | undefined;
129
129
  queryStrings?: {
130
130
  name: string;
131
- value: string;
131
+ value?: string | undefined;
132
132
  helpText?: string | undefined;
133
133
  }[] | undefined;
134
134
  previewValue?: string | undefined;
@@ -442,26 +442,31 @@ type UseUniformContextualEditingStateProps = {
442
442
  **/
443
443
  global?: boolean;
444
444
  };
445
+ type UseUniformContextualEditingStateReturnType = {
446
+ /**
447
+ * Returns `true` when the app is rendered inside Canvas editor. Regardless of which preview mode is currently selected ("editor" or "preview").
448
+ */
449
+ isContextualEditing: boolean;
450
+ /**
451
+ * A reference to the currently selected component in Canvas editor.
452
+ * Returns `undefined` if the selected component is not part of the current React component.
453
+ * Set the `global` option to `true` to get a reference of the selected component anywhere in the composition tree.
454
+ */
455
+ selectedComponentReference: UpdateContextualEditingStateInternalMessage['state']['selectedComponentReference'];
456
+ /**
457
+ * Returns the current preview mode in Canvas editor ("editor" or "preview").
458
+ * Returns `undefined` when the app is not rendered inside Canvas editor.
459
+ * Learn more about the preview modes: https://docs.uniform.app/docs/guides/composition/visual-editing#editing-and-preview-mode
460
+ * @deprecated this is an experimental property, it might receive breaking changes in minor releases ⚠️
461
+ */
462
+ previewMode: UpdateContextualEditingStateInternalMessage['state']['previewMode'] | undefined;
463
+ };
445
464
  /**
446
465
  * Returns the state of contextual editing, when the app is open inside Canvas Editor.
447
466
  * This hook can be used to improve the editing experience of your team.
448
467
  * For example: You can use `selectedComponentReference` to control which element to show inside a carousel or an accordion.
449
468
  */
450
- declare const useUniformContextualEditingState: ({ global, }?: UseUniformContextualEditingStateProps) => {
451
- isContextualEditing: boolean;
452
- selectedComponentReference: {
453
- id: string;
454
- slotName?: string | undefined;
455
- componentIndex?: number | undefined;
456
- totalComponents?: number | undefined;
457
- componentName?: string | undefined;
458
- componentTitle?: string | undefined;
459
- parentId?: string | undefined;
460
- parentType?: string | undefined;
461
- isLocalized?: boolean | undefined;
462
- isReadOnly?: boolean | undefined;
463
- } | undefined;
464
- };
469
+ declare const useUniformContextualEditingState: ({ global, }?: UseUniformContextualEditingStateProps) => UseUniformContextualEditingStateReturnType;
465
470
 
466
471
  declare const componentStore: ComponentStore;
467
472
  declare const registerUniformComponent: ({ type, variantId, component, }: {
@@ -479,4 +484,4 @@ declare const createComponentStoreResolver: (options: {
479
484
  defaultComponent?: React$1.ComponentType<ComponentProps<any>>;
480
485
  }) => RenderComponentResolver;
481
486
 
482
- export { type ComponentProps, type ComponentStore, type CustomSlotChildRenderFunc, DefaultNotImplementedComponent, NOT_IMPLEMENTED_COMPONENT, type RenderComponentResolver, type RenderRichTextComponentResolver, type RichTextComponentProps, type RichTextRendererComponent, type SystemRenderConfig, type SystemRenderFunction, UniformComponent, type UniformComponentContextValue, type UniformComponentProps, UniformComposition, UniformCompositionContext, type UniformCompositionProps, UniformPlayground, type UniformPlaygroundDecorator, type UniformPlaygroundProps, UniformRichText, UniformRichTextNode, type UniformRichTextNodeProps, type UniformRichTextProps, UniformSlot, type UniformSlotProps, type UniformSlotWrapperComponentProps, UniformText, type UniformTextProps, type UseCompositionEventEffectOptions, type UseUniformContextualEditingProps, type UseUniformContextualEditingStateProps, componentStore, componentStoreResolver, convertComponentToProps, createComponentStore, createComponentStoreResolver, getParameterAttributes, registerUniformComponent, useCompositionEventEffect, useUniformContextualEditing, useUniformContextualEditingState, useUniformCurrentComponent, useUniformCurrentComposition };
487
+ export { type ComponentProps, type ComponentStore, type CustomSlotChildRenderFunc, DefaultNotImplementedComponent, NOT_IMPLEMENTED_COMPONENT, type RenderComponentResolver, type RenderRichTextComponentResolver, type RichTextComponentProps, type RichTextRendererComponent, type SystemRenderConfig, type SystemRenderFunction, UniformComponent, type UniformComponentContextValue, type UniformComponentProps, UniformComposition, UniformCompositionContext, type UniformCompositionProps, UniformPlayground, type UniformPlaygroundDecorator, type UniformPlaygroundProps, UniformRichText, UniformRichTextNode, type UniformRichTextNodeProps, type UniformRichTextProps, UniformSlot, type UniformSlotProps, type UniformSlotWrapperComponentProps, UniformText, type UniformTextProps, type UseCompositionEventEffectOptions, type UseUniformContextualEditingProps, type UseUniformContextualEditingStateProps, type UseUniformContextualEditingStateReturnType, componentStore, componentStoreResolver, convertComponentToProps, createComponentStore, createComponentStoreResolver, getParameterAttributes, registerUniformComponent, useCompositionEventEffect, useUniformContextualEditing, useUniformContextualEditingState, useUniformCurrentComponent, useUniformCurrentComposition };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React$1, { Key, ReactNode, PropsWithChildren } from 'react';
2
- import { ComponentInstance, RootComponentInstance, UpdateCompositionMessage, getParameterAttributes as getParameterAttributes$1, SubscribeToCompositionOptions } from '@uniformdev/canvas';
2
+ import { ComponentInstance, RootComponentInstance, UpdateCompositionMessage, getParameterAttributes as getParameterAttributes$1, SubscribeToCompositionOptions, UpdateContextualEditingStateInternalMessage } from '@uniformdev/canvas';
3
3
  export { GetParameterAttributesProps, createUniformApiEnhancer } from '@uniformdev/canvas';
4
4
  import { P as PureUniformTextProps } from './PureUniformText-B3GAm6Dc.js';
5
5
  import { RichTextNode } from '@uniformdev/richtext';
@@ -128,7 +128,7 @@ declare const useUniformContextualEditing: ({ initialCompositionValue, enhance,
128
128
  isSearchHit?: boolean | undefined;
129
129
  queryStrings?: {
130
130
  name: string;
131
- value: string;
131
+ value?: string | undefined;
132
132
  helpText?: string | undefined;
133
133
  }[] | undefined;
134
134
  previewValue?: string | undefined;
@@ -442,26 +442,31 @@ type UseUniformContextualEditingStateProps = {
442
442
  **/
443
443
  global?: boolean;
444
444
  };
445
+ type UseUniformContextualEditingStateReturnType = {
446
+ /**
447
+ * Returns `true` when the app is rendered inside Canvas editor. Regardless of which preview mode is currently selected ("editor" or "preview").
448
+ */
449
+ isContextualEditing: boolean;
450
+ /**
451
+ * A reference to the currently selected component in Canvas editor.
452
+ * Returns `undefined` if the selected component is not part of the current React component.
453
+ * Set the `global` option to `true` to get a reference of the selected component anywhere in the composition tree.
454
+ */
455
+ selectedComponentReference: UpdateContextualEditingStateInternalMessage['state']['selectedComponentReference'];
456
+ /**
457
+ * Returns the current preview mode in Canvas editor ("editor" or "preview").
458
+ * Returns `undefined` when the app is not rendered inside Canvas editor.
459
+ * Learn more about the preview modes: https://docs.uniform.app/docs/guides/composition/visual-editing#editing-and-preview-mode
460
+ * @deprecated this is an experimental property, it might receive breaking changes in minor releases ⚠️
461
+ */
462
+ previewMode: UpdateContextualEditingStateInternalMessage['state']['previewMode'] | undefined;
463
+ };
445
464
  /**
446
465
  * Returns the state of contextual editing, when the app is open inside Canvas Editor.
447
466
  * This hook can be used to improve the editing experience of your team.
448
467
  * For example: You can use `selectedComponentReference` to control which element to show inside a carousel or an accordion.
449
468
  */
450
- declare const useUniformContextualEditingState: ({ global, }?: UseUniformContextualEditingStateProps) => {
451
- isContextualEditing: boolean;
452
- selectedComponentReference: {
453
- id: string;
454
- slotName?: string | undefined;
455
- componentIndex?: number | undefined;
456
- totalComponents?: number | undefined;
457
- componentName?: string | undefined;
458
- componentTitle?: string | undefined;
459
- parentId?: string | undefined;
460
- parentType?: string | undefined;
461
- isLocalized?: boolean | undefined;
462
- isReadOnly?: boolean | undefined;
463
- } | undefined;
464
- };
469
+ declare const useUniformContextualEditingState: ({ global, }?: UseUniformContextualEditingStateProps) => UseUniformContextualEditingStateReturnType;
465
470
 
466
471
  declare const componentStore: ComponentStore;
467
472
  declare const registerUniformComponent: ({ type, variantId, component, }: {
@@ -479,4 +484,4 @@ declare const createComponentStoreResolver: (options: {
479
484
  defaultComponent?: React$1.ComponentType<ComponentProps<any>>;
480
485
  }) => RenderComponentResolver;
481
486
 
482
- export { type ComponentProps, type ComponentStore, type CustomSlotChildRenderFunc, DefaultNotImplementedComponent, NOT_IMPLEMENTED_COMPONENT, type RenderComponentResolver, type RenderRichTextComponentResolver, type RichTextComponentProps, type RichTextRendererComponent, type SystemRenderConfig, type SystemRenderFunction, UniformComponent, type UniformComponentContextValue, type UniformComponentProps, UniformComposition, UniformCompositionContext, type UniformCompositionProps, UniformPlayground, type UniformPlaygroundDecorator, type UniformPlaygroundProps, UniformRichText, UniformRichTextNode, type UniformRichTextNodeProps, type UniformRichTextProps, UniformSlot, type UniformSlotProps, type UniformSlotWrapperComponentProps, UniformText, type UniformTextProps, type UseCompositionEventEffectOptions, type UseUniformContextualEditingProps, type UseUniformContextualEditingStateProps, componentStore, componentStoreResolver, convertComponentToProps, createComponentStore, createComponentStoreResolver, getParameterAttributes, registerUniformComponent, useCompositionEventEffect, useUniformContextualEditing, useUniformContextualEditingState, useUniformCurrentComponent, useUniformCurrentComposition };
487
+ export { type ComponentProps, type ComponentStore, type CustomSlotChildRenderFunc, DefaultNotImplementedComponent, NOT_IMPLEMENTED_COMPONENT, type RenderComponentResolver, type RenderRichTextComponentResolver, type RichTextComponentProps, type RichTextRendererComponent, type SystemRenderConfig, type SystemRenderFunction, UniformComponent, type UniformComponentContextValue, type UniformComponentProps, UniformComposition, UniformCompositionContext, type UniformCompositionProps, UniformPlayground, type UniformPlaygroundDecorator, type UniformPlaygroundProps, UniformRichText, UniformRichTextNode, type UniformRichTextNodeProps, type UniformRichTextProps, UniformSlot, type UniformSlotProps, type UniformSlotWrapperComponentProps, UniformText, type UniformTextProps, type UseCompositionEventEffectOptions, type UseUniformContextualEditingProps, type UseUniformContextualEditingStateProps, type UseUniformContextualEditingStateReturnType, componentStore, componentStoreResolver, convertComponentToProps, createComponentStore, createComponentStoreResolver, getParameterAttributes, registerUniformComponent, useCompositionEventEffect, useUniformContextualEditing, useUniformContextualEditingState, useUniformCurrentComponent, useUniformCurrentComposition };
package/dist/index.esm.js CHANGED
@@ -940,6 +940,9 @@ var useUniformContextualEditingState = ({
940
940
  const { isContextualEditing } = useUniformCurrentComposition();
941
941
  const { data: componentData } = useUniformCurrentComponent();
942
942
  const [selectedComponentReference, setSelectedComponentReference] = useState3();
943
+ const [previewMode, setPreviewMode] = useState3(
944
+ isContextualEditing ? "editor" : void 0
945
+ );
943
946
  const channel = useMemo4(() => {
944
947
  if (!isContextualEditing) {
945
948
  return;
@@ -951,15 +954,20 @@ var useUniformContextualEditingState = ({
951
954
  return channel2;
952
955
  }, [isContextualEditing]);
953
956
  useEffect3(() => {
957
+ var _a, _b;
954
958
  if (!channel) {
955
959
  return;
956
960
  }
961
+ if (typeof window !== "undefined") {
962
+ setPreviewMode((_b = (_a = window.__UNIFORM_CONTEXTUAL_EDITING__) == null ? void 0 : _a.state) == null ? void 0 : _b.previewMode);
963
+ }
957
964
  const unsubscribe = channel.on("update-contextual-editing-state-internal", async (message) => {
958
- var _a;
965
+ var _a2;
959
966
  if (!isUpdateContextualEditingStateInternalMessage(message)) {
960
967
  return;
961
968
  }
962
- if (!global && (componentData == null ? void 0 : componentData._id) !== ((_a = message.state.selectedComponentReference) == null ? void 0 : _a.parentId)) {
969
+ setPreviewMode(message.state.previewMode);
970
+ if (!global && (componentData == null ? void 0 : componentData._id) !== ((_a2 = message.state.selectedComponentReference) == null ? void 0 : _a2.parentId)) {
963
971
  setSelectedComponentReference(void 0);
964
972
  return;
965
973
  }
@@ -968,13 +976,14 @@ var useUniformContextualEditingState = ({
968
976
  return () => {
969
977
  unsubscribe();
970
978
  };
971
- }, [global, channel, componentData == null ? void 0 : componentData._id, setSelectedComponentReference]);
979
+ }, [global, channel, componentData == null ? void 0 : componentData._id, setSelectedComponentReference, setPreviewMode]);
972
980
  return useMemo4(
973
981
  () => ({
974
982
  isContextualEditing,
975
- selectedComponentReference
983
+ selectedComponentReference,
984
+ previewMode
976
985
  }),
977
- [isContextualEditing, selectedComponentReference]
986
+ [isContextualEditing, selectedComponentReference, previewMode]
978
987
  );
979
988
  };
980
989
  export {
package/dist/index.js CHANGED
@@ -956,6 +956,9 @@ var useUniformContextualEditingState = ({
956
956
  const { isContextualEditing } = useUniformCurrentComposition();
957
957
  const { data: componentData } = useUniformCurrentComponent();
958
958
  const [selectedComponentReference, setSelectedComponentReference] = (0, import_react22.useState)();
959
+ const [previewMode, setPreviewMode] = (0, import_react22.useState)(
960
+ isContextualEditing ? "editor" : void 0
961
+ );
959
962
  const channel = (0, import_react22.useMemo)(() => {
960
963
  if (!isContextualEditing) {
961
964
  return;
@@ -967,15 +970,20 @@ var useUniformContextualEditingState = ({
967
970
  return channel2;
968
971
  }, [isContextualEditing]);
969
972
  (0, import_react22.useEffect)(() => {
973
+ var _a, _b;
970
974
  if (!channel) {
971
975
  return;
972
976
  }
977
+ if (typeof window !== "undefined") {
978
+ setPreviewMode((_b = (_a = window.__UNIFORM_CONTEXTUAL_EDITING__) == null ? void 0 : _a.state) == null ? void 0 : _b.previewMode);
979
+ }
973
980
  const unsubscribe = channel.on("update-contextual-editing-state-internal", async (message) => {
974
- var _a;
981
+ var _a2;
975
982
  if (!(0, import_canvas12.isUpdateContextualEditingStateInternalMessage)(message)) {
976
983
  return;
977
984
  }
978
- if (!global && (componentData == null ? void 0 : componentData._id) !== ((_a = message.state.selectedComponentReference) == null ? void 0 : _a.parentId)) {
985
+ setPreviewMode(message.state.previewMode);
986
+ if (!global && (componentData == null ? void 0 : componentData._id) !== ((_a2 = message.state.selectedComponentReference) == null ? void 0 : _a2.parentId)) {
979
987
  setSelectedComponentReference(void 0);
980
988
  return;
981
989
  }
@@ -984,13 +992,14 @@ var useUniformContextualEditingState = ({
984
992
  return () => {
985
993
  unsubscribe();
986
994
  };
987
- }, [global, channel, componentData == null ? void 0 : componentData._id, setSelectedComponentReference]);
995
+ }, [global, channel, componentData == null ? void 0 : componentData._id, setSelectedComponentReference, setPreviewMode]);
988
996
  return (0, import_react22.useMemo)(
989
997
  () => ({
990
998
  isContextualEditing,
991
- selectedComponentReference
999
+ selectedComponentReference,
1000
+ previewMode
992
1001
  }),
993
- [isContextualEditing, selectedComponentReference]
1002
+ [isContextualEditing, selectedComponentReference, previewMode]
994
1003
  );
995
1004
  };
996
1005
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.mjs CHANGED
@@ -940,6 +940,9 @@ var useUniformContextualEditingState = ({
940
940
  const { isContextualEditing } = useUniformCurrentComposition();
941
941
  const { data: componentData } = useUniformCurrentComponent();
942
942
  const [selectedComponentReference, setSelectedComponentReference] = useState3();
943
+ const [previewMode, setPreviewMode] = useState3(
944
+ isContextualEditing ? "editor" : void 0
945
+ );
943
946
  const channel = useMemo4(() => {
944
947
  if (!isContextualEditing) {
945
948
  return;
@@ -951,15 +954,20 @@ var useUniformContextualEditingState = ({
951
954
  return channel2;
952
955
  }, [isContextualEditing]);
953
956
  useEffect3(() => {
957
+ var _a, _b;
954
958
  if (!channel) {
955
959
  return;
956
960
  }
961
+ if (typeof window !== "undefined") {
962
+ setPreviewMode((_b = (_a = window.__UNIFORM_CONTEXTUAL_EDITING__) == null ? void 0 : _a.state) == null ? void 0 : _b.previewMode);
963
+ }
957
964
  const unsubscribe = channel.on("update-contextual-editing-state-internal", async (message) => {
958
- var _a;
965
+ var _a2;
959
966
  if (!isUpdateContextualEditingStateInternalMessage(message)) {
960
967
  return;
961
968
  }
962
- if (!global && (componentData == null ? void 0 : componentData._id) !== ((_a = message.state.selectedComponentReference) == null ? void 0 : _a.parentId)) {
969
+ setPreviewMode(message.state.previewMode);
970
+ if (!global && (componentData == null ? void 0 : componentData._id) !== ((_a2 = message.state.selectedComponentReference) == null ? void 0 : _a2.parentId)) {
963
971
  setSelectedComponentReference(void 0);
964
972
  return;
965
973
  }
@@ -968,13 +976,14 @@ var useUniformContextualEditingState = ({
968
976
  return () => {
969
977
  unsubscribe();
970
978
  };
971
- }, [global, channel, componentData == null ? void 0 : componentData._id, setSelectedComponentReference]);
979
+ }, [global, channel, componentData == null ? void 0 : componentData._id, setSelectedComponentReference, setPreviewMode]);
972
980
  return useMemo4(
973
981
  () => ({
974
982
  isContextualEditing,
975
- selectedComponentReference
983
+ selectedComponentReference,
984
+ previewMode
976
985
  }),
977
- [isContextualEditing, selectedComponentReference]
986
+ [isContextualEditing, selectedComponentReference, previewMode]
978
987
  );
979
988
  };
980
989
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-react",
3
- "version": "19.142.0",
3
+ "version": "19.142.2-alpha.1+7fbfb0bb72",
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.142.0",
49
- "@uniformdev/context": "19.142.0",
50
- "@uniformdev/context-react": "19.142.0",
51
- "@uniformdev/richtext": "19.142.0"
48
+ "@uniformdev/canvas": "19.142.2-alpha.1+7fbfb0bb72",
49
+ "@uniformdev/context": "19.142.2-alpha.1+7fbfb0bb72",
50
+ "@uniformdev/context-react": "19.142.2-alpha.1+7fbfb0bb72",
51
+ "@uniformdev/richtext": "19.142.2-alpha.1+7fbfb0bb72"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "react": ">= 16 || 17 || 18",
@@ -65,5 +65,5 @@
65
65
  "publishConfig": {
66
66
  "access": "public"
67
67
  },
68
- "gitHead": "468077a132e42dbe08f94ab1784c787000d29458"
68
+ "gitHead": "7fbfb0bb725ad5a8609e6df42871267a87796a02"
69
69
  }