@cmssy/react 9.7.0 → 9.7.2

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/client.cjs CHANGED
@@ -94,6 +94,8 @@ function useEditBridge(page, config) {
94
94
  const [order, setOrder] = react.useState(null);
95
95
  const [removed, setRemoved] = react.useState([]);
96
96
  const selectedIdRef = react.useRef(null);
97
+ const postSafeRef = react.useRef(() => {
98
+ });
97
99
  const { id: pageId, blocks } = page;
98
100
  const blocksKey = blocks.map((b) => `${b.id}:${b.type}`).join("|");
99
101
  react.useEffect(() => {
@@ -209,6 +211,7 @@ function useEditBridge(page, config) {
209
211
  sendReady();
210
212
  }
211
213
  };
214
+ postSafeRef.current = postSafe;
212
215
  const onClick = (event) => {
213
216
  const target = event.target;
214
217
  const el = target?.closest?.("[data-block-id]");
@@ -222,7 +225,10 @@ function useEditBridge(page, config) {
222
225
  return;
223
226
  }
224
227
  selectedIdRef.current = id;
225
- if (target?.closest?.("a[href]")) event.preventDefault();
228
+ if (target?.closest?.("a[href]")) {
229
+ event.preventDefault();
230
+ event.stopPropagation();
231
+ }
226
232
  const r = el.getBoundingClientRect();
227
233
  const layoutPosition = el.getAttribute("data-layout-position");
228
234
  postSafe({
@@ -253,7 +259,7 @@ function useEditBridge(page, config) {
253
259
  });
254
260
  };
255
261
  window.addEventListener("message", handler);
256
- document.addEventListener("click", onClick);
262
+ document.addEventListener("click", onClick, { capture: true });
257
263
  window.addEventListener("scroll", emitSelectedBounds, {
258
264
  capture: true,
259
265
  passive: true
@@ -263,13 +269,26 @@ function useEditBridge(page, config) {
263
269
  return () => {
264
270
  if (boundsRaf) cancelAnimationFrame(boundsRaf);
265
271
  window.removeEventListener("message", handler);
266
- document.removeEventListener("click", onClick);
272
+ document.removeEventListener("click", onClick, { capture: true });
267
273
  window.removeEventListener("scroll", emitSelectedBounds, {
268
274
  capture: true
269
275
  });
270
276
  window.removeEventListener("resize", emitSelectedBounds);
271
277
  };
272
278
  }, [config.editorOrigin, pageId, blocksKey]);
279
+ react.useEffect(() => {
280
+ if (typeof window === "undefined" || window.parent === window) return;
281
+ const notifySelectionGone = () => {
282
+ if (!selectedIdRef.current) return;
283
+ selectedIdRef.current = null;
284
+ postSafeRef.current({ type: "cmssy:deselect" });
285
+ };
286
+ window.addEventListener("pagehide", notifySelectionGone);
287
+ return () => {
288
+ window.removeEventListener("pagehide", notifySelectionGone);
289
+ notifySelectionGone();
290
+ };
291
+ }, []);
273
292
  return {
274
293
  patches,
275
294
  patchesStyle,
@@ -571,7 +590,7 @@ function CmssyBlock({
571
590
  }
572
591
  const base = resolvedContent ? { ...resolvedContent } : core.getBlockContentForLanguage(block.content, locale, defaultLocale);
573
592
  const content = patchedContent ? { ...base, ...patchedContent } : base;
574
- if (schema) core.normalizeRelationContent(content, schema);
593
+ if (schema) core.normalizeRelationContent(content, schema, resolvedContent);
575
594
  const style = patchedStyle ? { ...core.asBucket(block.style), ...patchedStyle } : core.asBucket(block.style);
576
595
  const advanced = patchedAdvanced ? { ...core.asBucket(block.advanced), ...patchedAdvanced } : core.asBucket(block.advanced);
577
596
  return wrap(
package/dist/client.js CHANGED
@@ -93,6 +93,8 @@ function useEditBridge(page, config) {
93
93
  const [order, setOrder] = useState(null);
94
94
  const [removed, setRemoved] = useState([]);
95
95
  const selectedIdRef = useRef(null);
96
+ const postSafeRef = useRef(() => {
97
+ });
96
98
  const { id: pageId, blocks } = page;
97
99
  const blocksKey = blocks.map((b) => `${b.id}:${b.type}`).join("|");
98
100
  useEffect(() => {
@@ -208,6 +210,7 @@ function useEditBridge(page, config) {
208
210
  sendReady();
209
211
  }
210
212
  };
213
+ postSafeRef.current = postSafe;
211
214
  const onClick = (event) => {
212
215
  const target = event.target;
213
216
  const el = target?.closest?.("[data-block-id]");
@@ -221,7 +224,10 @@ function useEditBridge(page, config) {
221
224
  return;
222
225
  }
223
226
  selectedIdRef.current = id;
224
- if (target?.closest?.("a[href]")) event.preventDefault();
227
+ if (target?.closest?.("a[href]")) {
228
+ event.preventDefault();
229
+ event.stopPropagation();
230
+ }
225
231
  const r = el.getBoundingClientRect();
226
232
  const layoutPosition = el.getAttribute("data-layout-position");
227
233
  postSafe({
@@ -252,7 +258,7 @@ function useEditBridge(page, config) {
252
258
  });
253
259
  };
254
260
  window.addEventListener("message", handler);
255
- document.addEventListener("click", onClick);
261
+ document.addEventListener("click", onClick, { capture: true });
256
262
  window.addEventListener("scroll", emitSelectedBounds, {
257
263
  capture: true,
258
264
  passive: true
@@ -262,13 +268,26 @@ function useEditBridge(page, config) {
262
268
  return () => {
263
269
  if (boundsRaf) cancelAnimationFrame(boundsRaf);
264
270
  window.removeEventListener("message", handler);
265
- document.removeEventListener("click", onClick);
271
+ document.removeEventListener("click", onClick, { capture: true });
266
272
  window.removeEventListener("scroll", emitSelectedBounds, {
267
273
  capture: true
268
274
  });
269
275
  window.removeEventListener("resize", emitSelectedBounds);
270
276
  };
271
277
  }, [config.editorOrigin, pageId, blocksKey]);
278
+ useEffect(() => {
279
+ if (typeof window === "undefined" || window.parent === window) return;
280
+ const notifySelectionGone = () => {
281
+ if (!selectedIdRef.current) return;
282
+ selectedIdRef.current = null;
283
+ postSafeRef.current({ type: "cmssy:deselect" });
284
+ };
285
+ window.addEventListener("pagehide", notifySelectionGone);
286
+ return () => {
287
+ window.removeEventListener("pagehide", notifySelectionGone);
288
+ notifySelectionGone();
289
+ };
290
+ }, []);
272
291
  return {
273
292
  patches,
274
293
  patchesStyle,
@@ -570,7 +589,7 @@ function CmssyBlock({
570
589
  }
571
590
  const base = resolvedContent ? { ...resolvedContent } : getBlockContentForLanguage(block.content, locale, defaultLocale);
572
591
  const content = patchedContent ? { ...base, ...patchedContent } : base;
573
- if (schema) normalizeRelationContent(content, schema);
592
+ if (schema) normalizeRelationContent(content, schema, resolvedContent);
574
593
  const style = patchedStyle ? { ...asBucket(block.style), ...patchedStyle } : asBucket(block.style);
575
594
  const advanced = patchedAdvanced ? { ...asBucket(block.advanced), ...patchedAdvanced } : asBucket(block.advanced);
576
595
  return wrap(
package/dist/index.cjs CHANGED
@@ -500,7 +500,7 @@ function CmssyBlock({
500
500
  }
501
501
  const base = resolvedContent ? { ...resolvedContent } : core.getBlockContentForLanguage(block.content, locale, defaultLocale);
502
502
  const content = patchedContent ? { ...base, ...patchedContent } : base;
503
- if (schema) core.normalizeRelationContent(content, schema);
503
+ if (schema) core.normalizeRelationContent(content, schema, resolvedContent);
504
504
  const style = patchedStyle ? { ...core.asBucket(block.style), ...patchedStyle } : core.asBucket(block.style);
505
505
  const advanced = patchedAdvanced ? { ...core.asBucket(block.advanced), ...patchedAdvanced } : core.asBucket(block.advanced);
506
506
  return wrap(
package/dist/index.js CHANGED
@@ -499,7 +499,7 @@ function CmssyBlock({
499
499
  }
500
500
  const base = resolvedContent ? { ...resolvedContent } : getBlockContentForLanguage(block.content, locale, defaultLocale);
501
501
  const content = patchedContent ? { ...base, ...patchedContent } : base;
502
- if (schema) normalizeRelationContent(content, schema);
502
+ if (schema) normalizeRelationContent(content, schema, resolvedContent);
503
503
  const style = patchedStyle ? { ...asBucket(block.style), ...patchedStyle } : asBucket(block.style);
504
504
  const advanced = patchedAdvanced ? { ...asBucket(block.advanced), ...patchedAdvanced } : asBucket(block.advanced);
505
505
  return wrap(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/react",
3
- "version": "9.7.0",
3
+ "version": "9.7.2",
4
4
  "description": "React blocks, renderers, data client and editor bridge for cmssy headless sites",
5
5
  "keywords": [
6
6
  "cmssy",
@@ -62,7 +62,7 @@
62
62
  },
63
63
  "dependencies": {
64
64
  "@cmssy/types": "0.29.0",
65
- "@cmssy/core": "9.7.0"
65
+ "@cmssy/core": "9.7.2"
66
66
  },
67
67
  "scripts": {
68
68
  "build": "tsup",