@uniformdev/canvas-next-rsc-client 19.203.0 → 19.204.0

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
@@ -6,7 +6,7 @@ import * as react from 'react';
6
6
  import { PropsWithChildren } from 'react';
7
7
  import * as _uniformdev_canvas_next_rsc_shared from '@uniformdev/canvas-next-rsc-shared';
8
8
  import { AppDirectoryContextState, PersonalizeProps, ComponentProps, TestProps, CreateUniformContextOptions, AppDirectoryContext } from '@uniformdev/canvas-next-rsc-shared';
9
- import { VisibilityParameterValue } from '@uniformdev/canvas';
9
+ import { VisibilityParameterValue, ComponentInstance, UpdateContextualEditingStateInternalMessage } from '@uniformdev/canvas';
10
10
 
11
11
  type ClientContextComponentProps = {
12
12
  /**
@@ -91,4 +91,22 @@ declare const useUniformContext: () => {
91
91
  context: AppDirectoryContext | undefined;
92
92
  };
93
93
 
94
- export { type ClientContextComponent, type ClientContextComponentProps, ClientContextPersonalizationTransfer, ClientContextTestTransfer, ClientContextUpdate, ClientContextualEditingComponentWrapper, ContextUpdateTransferClient, type CreateClientUniformContextOptions, DefaultUniformClientContext, PersonalizeClient, type PersonalizeClientProps, TestClient, UniformScript, VisibilityRulesWrapperClient, createClientUniformContext, useInitUniformContext, useQuirks, useScores, useUniformContext };
94
+ type UseUniformContextualEditingStateProps = {
95
+ /**
96
+ * When not set, the hook will return the global contextual state no matter where its used.
97
+ * When set, it will return only the state relevant to the component passed.
98
+ * @default undefined
99
+ **/
100
+ scope?: ComponentInstance;
101
+ };
102
+ type UseUniformContextualEditingStateReturnType = {
103
+ /**
104
+ * A reference to the currently selected component in Canvas editor.
105
+ * Returns `undefined` if the selected component is not part of the current React component.
106
+ * Set the `scope` option a component instance to limit the scope of selected compponents.
107
+ */
108
+ selectedComponentReference: UpdateContextualEditingStateInternalMessage['state']['selectedComponentReference'];
109
+ };
110
+ declare const useUniformContextualEditingState: ({ scope, }?: UseUniformContextualEditingStateProps) => UseUniformContextualEditingStateReturnType;
111
+
112
+ export { type ClientContextComponent, type ClientContextComponentProps, ClientContextPersonalizationTransfer, ClientContextTestTransfer, ClientContextUpdate, ClientContextualEditingComponentWrapper, ContextUpdateTransferClient, type CreateClientUniformContextOptions, DefaultUniformClientContext, PersonalizeClient, type PersonalizeClientProps, TestClient, UniformScript, type UseUniformContextualEditingStateProps, type UseUniformContextualEditingStateReturnType, VisibilityRulesWrapperClient, createClientUniformContext, useInitUniformContext, useQuirks, useScores, useUniformContext, useUniformContextualEditingState };
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ import * as react from 'react';
6
6
  import { PropsWithChildren } from 'react';
7
7
  import * as _uniformdev_canvas_next_rsc_shared from '@uniformdev/canvas-next-rsc-shared';
8
8
  import { AppDirectoryContextState, PersonalizeProps, ComponentProps, TestProps, CreateUniformContextOptions, AppDirectoryContext } from '@uniformdev/canvas-next-rsc-shared';
9
- import { VisibilityParameterValue } from '@uniformdev/canvas';
9
+ import { VisibilityParameterValue, ComponentInstance, UpdateContextualEditingStateInternalMessage } from '@uniformdev/canvas';
10
10
 
11
11
  type ClientContextComponentProps = {
12
12
  /**
@@ -91,4 +91,22 @@ declare const useUniformContext: () => {
91
91
  context: AppDirectoryContext | undefined;
92
92
  };
93
93
 
94
- export { type ClientContextComponent, type ClientContextComponentProps, ClientContextPersonalizationTransfer, ClientContextTestTransfer, ClientContextUpdate, ClientContextualEditingComponentWrapper, ContextUpdateTransferClient, type CreateClientUniformContextOptions, DefaultUniformClientContext, PersonalizeClient, type PersonalizeClientProps, TestClient, UniformScript, VisibilityRulesWrapperClient, createClientUniformContext, useInitUniformContext, useQuirks, useScores, useUniformContext };
94
+ type UseUniformContextualEditingStateProps = {
95
+ /**
96
+ * When not set, the hook will return the global contextual state no matter where its used.
97
+ * When set, it will return only the state relevant to the component passed.
98
+ * @default undefined
99
+ **/
100
+ scope?: ComponentInstance;
101
+ };
102
+ type UseUniformContextualEditingStateReturnType = {
103
+ /**
104
+ * A reference to the currently selected component in Canvas editor.
105
+ * Returns `undefined` if the selected component is not part of the current React component.
106
+ * Set the `scope` option a component instance to limit the scope of selected compponents.
107
+ */
108
+ selectedComponentReference: UpdateContextualEditingStateInternalMessage['state']['selectedComponentReference'];
109
+ };
110
+ declare const useUniformContextualEditingState: ({ scope, }?: UseUniformContextualEditingStateProps) => UseUniformContextualEditingStateReturnType;
111
+
112
+ export { type ClientContextComponent, type ClientContextComponentProps, ClientContextPersonalizationTransfer, ClientContextTestTransfer, ClientContextUpdate, ClientContextualEditingComponentWrapper, ContextUpdateTransferClient, type CreateClientUniformContextOptions, DefaultUniformClientContext, PersonalizeClient, type PersonalizeClientProps, TestClient, UniformScript, type UseUniformContextualEditingStateProps, type UseUniformContextualEditingStateReturnType, VisibilityRulesWrapperClient, createClientUniformContext, useInitUniformContext, useQuirks, useScores, useUniformContext, useUniformContextualEditingState };
package/dist/index.esm.js CHANGED
@@ -1137,6 +1137,47 @@ function useScores() {
1137
1137
  }, [context]);
1138
1138
  return scores;
1139
1139
  }
1140
+
1141
+ // src/hooks/useUniformContextualEditingState.ts
1142
+ import {
1143
+ createCanvasChannel as createCanvasChannel2,
1144
+ isUpdateContextualEditingStateInternalMessage
1145
+ } from "@uniformdev/canvas";
1146
+ import { useEffect as useEffect12, useMemo as useMemo4, useState as useState10 } from "react";
1147
+ var useUniformContextualEditingState = ({
1148
+ scope
1149
+ } = {}) => {
1150
+ const [selectedComponentReference, setSelectedComponentReference] = useState10();
1151
+ const channel = useMemo4(() => {
1152
+ const channel2 = createCanvasChannel2({
1153
+ broadcastTo: [window],
1154
+ listenTo: [window]
1155
+ });
1156
+ return channel2;
1157
+ }, []);
1158
+ useEffect12(() => {
1159
+ if (!channel) {
1160
+ return;
1161
+ }
1162
+ const unsubscribe = channel.on("update-contextual-editing-state-internal", async (message) => {
1163
+ var _a;
1164
+ if (!isUpdateContextualEditingStateInternalMessage(message)) {
1165
+ return;
1166
+ }
1167
+ if (!!scope && (scope == null ? void 0 : scope._id) !== ((_a = message.state.selectedComponentReference) == null ? void 0 : _a.parentId)) {
1168
+ setSelectedComponentReference(void 0);
1169
+ return;
1170
+ }
1171
+ setSelectedComponentReference(message.state.selectedComponentReference);
1172
+ });
1173
+ return () => {
1174
+ unsubscribe();
1175
+ };
1176
+ }, [scope, channel]);
1177
+ return {
1178
+ selectedComponentReference
1179
+ };
1180
+ };
1140
1181
  export {
1141
1182
  ClientContextPersonalizationTransfer,
1142
1183
  ClientContextTestTransfer,
@@ -1152,7 +1193,8 @@ export {
1152
1193
  useInitUniformContext,
1153
1194
  useQuirks,
1154
1195
  useScores,
1155
- useUniformContext
1196
+ useUniformContext,
1197
+ useUniformContextualEditingState
1156
1198
  };
1157
1199
  /*! Bundled license information:
1158
1200
 
package/dist/index.js CHANGED
@@ -237,7 +237,8 @@ __export(src_exports, {
237
237
  useInitUniformContext: () => useInitUniformContext,
238
238
  useQuirks: () => useQuirks,
239
239
  useScores: () => useScores,
240
- useUniformContext: () => useUniformContext
240
+ useUniformContext: () => useUniformContext,
241
+ useUniformContextualEditingState: () => useUniformContextualEditingState
241
242
  });
242
243
  module.exports = __toCommonJS(src_exports);
243
244
 
@@ -1155,6 +1156,44 @@ function useScores() {
1155
1156
  }, [context]);
1156
1157
  return scores;
1157
1158
  }
1159
+
1160
+ // src/hooks/useUniformContextualEditingState.ts
1161
+ var import_canvas6 = require("@uniformdev/canvas");
1162
+ var import_react14 = require("react");
1163
+ var useUniformContextualEditingState = ({
1164
+ scope
1165
+ } = {}) => {
1166
+ const [selectedComponentReference, setSelectedComponentReference] = (0, import_react14.useState)();
1167
+ const channel = (0, import_react14.useMemo)(() => {
1168
+ const channel2 = (0, import_canvas6.createCanvasChannel)({
1169
+ broadcastTo: [window],
1170
+ listenTo: [window]
1171
+ });
1172
+ return channel2;
1173
+ }, []);
1174
+ (0, import_react14.useEffect)(() => {
1175
+ if (!channel) {
1176
+ return;
1177
+ }
1178
+ const unsubscribe = channel.on("update-contextual-editing-state-internal", async (message) => {
1179
+ var _a;
1180
+ if (!(0, import_canvas6.isUpdateContextualEditingStateInternalMessage)(message)) {
1181
+ return;
1182
+ }
1183
+ if (!!scope && (scope == null ? void 0 : scope._id) !== ((_a = message.state.selectedComponentReference) == null ? void 0 : _a.parentId)) {
1184
+ setSelectedComponentReference(void 0);
1185
+ return;
1186
+ }
1187
+ setSelectedComponentReference(message.state.selectedComponentReference);
1188
+ });
1189
+ return () => {
1190
+ unsubscribe();
1191
+ };
1192
+ }, [scope, channel]);
1193
+ return {
1194
+ selectedComponentReference
1195
+ };
1196
+ };
1158
1197
  // Annotate the CommonJS export names for ESM import in node:
1159
1198
  0 && (module.exports = {
1160
1199
  ClientContextPersonalizationTransfer,
@@ -1171,7 +1210,8 @@ function useScores() {
1171
1210
  useInitUniformContext,
1172
1211
  useQuirks,
1173
1212
  useScores,
1174
- useUniformContext
1213
+ useUniformContext,
1214
+ useUniformContextualEditingState
1175
1215
  });
1176
1216
  /*! Bundled license information:
1177
1217
 
package/dist/index.mjs CHANGED
@@ -1137,6 +1137,47 @@ function useScores() {
1137
1137
  }, [context]);
1138
1138
  return scores;
1139
1139
  }
1140
+
1141
+ // src/hooks/useUniformContextualEditingState.ts
1142
+ import {
1143
+ createCanvasChannel as createCanvasChannel2,
1144
+ isUpdateContextualEditingStateInternalMessage
1145
+ } from "@uniformdev/canvas";
1146
+ import { useEffect as useEffect12, useMemo as useMemo4, useState as useState10 } from "react";
1147
+ var useUniformContextualEditingState = ({
1148
+ scope
1149
+ } = {}) => {
1150
+ const [selectedComponentReference, setSelectedComponentReference] = useState10();
1151
+ const channel = useMemo4(() => {
1152
+ const channel2 = createCanvasChannel2({
1153
+ broadcastTo: [window],
1154
+ listenTo: [window]
1155
+ });
1156
+ return channel2;
1157
+ }, []);
1158
+ useEffect12(() => {
1159
+ if (!channel) {
1160
+ return;
1161
+ }
1162
+ const unsubscribe = channel.on("update-contextual-editing-state-internal", async (message) => {
1163
+ var _a;
1164
+ if (!isUpdateContextualEditingStateInternalMessage(message)) {
1165
+ return;
1166
+ }
1167
+ if (!!scope && (scope == null ? void 0 : scope._id) !== ((_a = message.state.selectedComponentReference) == null ? void 0 : _a.parentId)) {
1168
+ setSelectedComponentReference(void 0);
1169
+ return;
1170
+ }
1171
+ setSelectedComponentReference(message.state.selectedComponentReference);
1172
+ });
1173
+ return () => {
1174
+ unsubscribe();
1175
+ };
1176
+ }, [scope, channel]);
1177
+ return {
1178
+ selectedComponentReference
1179
+ };
1180
+ };
1140
1181
  export {
1141
1182
  ClientContextPersonalizationTransfer,
1142
1183
  ClientContextTestTransfer,
@@ -1152,7 +1193,8 @@ export {
1152
1193
  useInitUniformContext,
1153
1194
  useQuirks,
1154
1195
  useScores,
1155
- useUniformContext
1196
+ useUniformContext,
1197
+ useUniformContextualEditingState
1156
1198
  };
1157
1199
  /*! Bundled license information:
1158
1200
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-next-rsc-client",
3
- "version": "19.203.0",
3
+ "version": "19.204.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "scripts": {
6
6
  "build": "tsup",
@@ -32,9 +32,9 @@
32
32
  "react-dom": "18.3.1"
33
33
  },
34
34
  "dependencies": {
35
- "@uniformdev/canvas": "19.203.0",
36
- "@uniformdev/canvas-next-rsc-shared": "^19.203.0",
37
- "@uniformdev/canvas-react": "^19.203.0"
35
+ "@uniformdev/canvas": "19.204.0",
36
+ "@uniformdev/canvas-next-rsc-shared": "^19.204.0",
37
+ "@uniformdev/canvas-react": "^19.204.0"
38
38
  },
39
39
  "engines": {
40
40
  "node": ">=16.14.0"
@@ -47,5 +47,5 @@
47
47
  "publishConfig": {
48
48
  "access": "public"
49
49
  },
50
- "gitHead": "fd2dc597c7909df1e00d9a0eb307ffac2ff72991"
50
+ "gitHead": "526d22d188132e5d47dc117808be6ead40532cb1"
51
51
  }