@cmssy/react 9.3.0 → 9.5.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/client.cjs CHANGED
@@ -116,6 +116,15 @@ function useEditBridge(page, config) {
116
116
  "[cmssy] editorOrigin '*' disables origin checks - dev only, do not use in production"
117
117
  );
118
118
  }
119
+ const postSafe = (message) => {
120
+ try {
121
+ core.postToEditor(window.parent, postTarget, message);
122
+ } catch (error) {
123
+ if (typeof console !== "undefined") {
124
+ console.debug("[cmssy] post to editor failed", message.type, error);
125
+ }
126
+ }
127
+ };
119
128
  const sendReady = () => {
120
129
  try {
121
130
  const rects = collectRects();
@@ -204,20 +213,24 @@ function useEditBridge(page, config) {
204
213
  const target = event.target;
205
214
  const el = target?.closest?.("[data-block-id]");
206
215
  const id = el?.getAttribute("data-block-id");
207
- if (!id || !el) return;
216
+ if (!id || !el) {
217
+ if (!selectedIdRef.current) return;
218
+ if (target?.closest?.("a[href],button")) return;
219
+ selectedIdRef.current = null;
220
+ setSelected(null);
221
+ postSafe({ type: "cmssy:deselect" });
222
+ return;
223
+ }
208
224
  selectedIdRef.current = id;
209
225
  if (target?.closest?.("a[href]")) event.preventDefault();
210
226
  const r = el.getBoundingClientRect();
211
227
  const layoutPosition = el.getAttribute("data-layout-position");
212
- try {
213
- core.postToEditor(window.parent, postTarget, {
214
- type: "cmssy:click",
215
- blockId: id,
216
- rect: { x: r.x, y: r.y, width: r.width, height: r.height },
217
- ...layoutPosition !== null ? { layoutPosition } : {}
218
- });
219
- } catch {
220
- }
228
+ postSafe({
229
+ type: "cmssy:click",
230
+ blockId: id,
231
+ rect: { x: r.x, y: r.y, width: r.width, height: r.height },
232
+ ...layoutPosition !== null ? { layoutPosition } : {}
233
+ });
221
234
  };
222
235
  let boundsRaf = 0;
223
236
  let boundsPending = false;
@@ -232,14 +245,11 @@ function useEditBridge(page, config) {
232
245
  const el = findBlockEl(id);
233
246
  if (!el) return;
234
247
  const r = el.getBoundingClientRect();
235
- try {
236
- core.postToEditor(window.parent, postTarget, {
237
- type: "cmssy:bounds",
238
- blockId: id,
239
- rect: { x: r.x, y: r.y, width: r.width, height: r.height }
240
- });
241
- } catch {
242
- }
248
+ postSafe({
249
+ type: "cmssy:bounds",
250
+ blockId: id,
251
+ rect: { x: r.x, y: r.y, width: r.width, height: r.height }
252
+ });
243
253
  });
244
254
  };
245
255
  window.addEventListener("message", handler);
package/dist/client.js CHANGED
@@ -115,6 +115,15 @@ function useEditBridge(page, config) {
115
115
  "[cmssy] editorOrigin '*' disables origin checks - dev only, do not use in production"
116
116
  );
117
117
  }
118
+ const postSafe = (message) => {
119
+ try {
120
+ postToEditor(window.parent, postTarget, message);
121
+ } catch (error) {
122
+ if (typeof console !== "undefined") {
123
+ console.debug("[cmssy] post to editor failed", message.type, error);
124
+ }
125
+ }
126
+ };
118
127
  const sendReady = () => {
119
128
  try {
120
129
  const rects = collectRects();
@@ -203,20 +212,24 @@ function useEditBridge(page, config) {
203
212
  const target = event.target;
204
213
  const el = target?.closest?.("[data-block-id]");
205
214
  const id = el?.getAttribute("data-block-id");
206
- if (!id || !el) return;
215
+ if (!id || !el) {
216
+ if (!selectedIdRef.current) return;
217
+ if (target?.closest?.("a[href],button")) return;
218
+ selectedIdRef.current = null;
219
+ setSelected(null);
220
+ postSafe({ type: "cmssy:deselect" });
221
+ return;
222
+ }
207
223
  selectedIdRef.current = id;
208
224
  if (target?.closest?.("a[href]")) event.preventDefault();
209
225
  const r = el.getBoundingClientRect();
210
226
  const layoutPosition = el.getAttribute("data-layout-position");
211
- try {
212
- postToEditor(window.parent, postTarget, {
213
- type: "cmssy:click",
214
- blockId: id,
215
- rect: { x: r.x, y: r.y, width: r.width, height: r.height },
216
- ...layoutPosition !== null ? { layoutPosition } : {}
217
- });
218
- } catch {
219
- }
227
+ postSafe({
228
+ type: "cmssy:click",
229
+ blockId: id,
230
+ rect: { x: r.x, y: r.y, width: r.width, height: r.height },
231
+ ...layoutPosition !== null ? { layoutPosition } : {}
232
+ });
220
233
  };
221
234
  let boundsRaf = 0;
222
235
  let boundsPending = false;
@@ -231,14 +244,11 @@ function useEditBridge(page, config) {
231
244
  const el = findBlockEl(id);
232
245
  if (!el) return;
233
246
  const r = el.getBoundingClientRect();
234
- try {
235
- postToEditor(window.parent, postTarget, {
236
- type: "cmssy:bounds",
237
- blockId: id,
238
- rect: { x: r.x, y: r.y, width: r.width, height: r.height }
239
- });
240
- } catch {
241
- }
247
+ postSafe({
248
+ type: "cmssy:bounds",
249
+ blockId: id,
250
+ rect: { x: r.x, y: r.y, width: r.width, height: r.height }
251
+ });
242
252
  });
243
253
  };
244
254
  window.addEventListener("message", handler);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/react",
3
- "version": "9.3.0",
3
+ "version": "9.5.0",
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.28.0",
65
- "@cmssy/core": "9.3.0"
65
+ "@cmssy/core": "9.5.0"
66
66
  },
67
67
  "scripts": {
68
68
  "build": "tsup",