@cmssy/react 0.17.1 → 0.18.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 +17 -3
- package/dist/client.js +17 -3
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -145,6 +145,18 @@ function collectRects() {
|
|
|
145
145
|
}
|
|
146
146
|
return rects;
|
|
147
147
|
}
|
|
148
|
+
function findBlockEl(blockId) {
|
|
149
|
+
if (typeof document === "undefined") return null;
|
|
150
|
+
const escaped = typeof CSS !== "undefined" && typeof CSS.escape === "function" ? CSS.escape(blockId) : blockId.replace(/["\\]/g, "\\$&");
|
|
151
|
+
try {
|
|
152
|
+
return document.querySelector(`[data-block-id="${escaped}"]`);
|
|
153
|
+
} catch {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function prefersReducedMotion() {
|
|
158
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
159
|
+
}
|
|
148
160
|
function collectLayoutBlocks(rects, pageIds) {
|
|
149
161
|
const out = [];
|
|
150
162
|
if (typeof document === "undefined") return out;
|
|
@@ -253,6 +265,10 @@ function useEditBridge(page, config) {
|
|
|
253
265
|
} else if (message.type === "cmssy:select") {
|
|
254
266
|
setSelected(message.blockId);
|
|
255
267
|
selectedIdRef.current = message.blockId;
|
|
268
|
+
findBlockEl(message.blockId)?.scrollIntoView({
|
|
269
|
+
behavior: prefersReducedMotion() ? "auto" : "smooth",
|
|
270
|
+
block: "nearest"
|
|
271
|
+
});
|
|
256
272
|
} else if (message.type === "cmssy:insert") {
|
|
257
273
|
setInserted((prev) => {
|
|
258
274
|
const next = prev.filter((b) => b.blockId !== message.blockId);
|
|
@@ -305,9 +321,7 @@ function useEditBridge(page, config) {
|
|
|
305
321
|
boundsRaf = 0;
|
|
306
322
|
const id = selectedIdRef.current;
|
|
307
323
|
if (!id) return;
|
|
308
|
-
const el =
|
|
309
|
-
`[data-block-id="${id.replace(/["\\]/g, "\\$&")}"]`
|
|
310
|
-
);
|
|
324
|
+
const el = findBlockEl(id);
|
|
311
325
|
if (!el) return;
|
|
312
326
|
const r = el.getBoundingClientRect();
|
|
313
327
|
try {
|
package/dist/client.js
CHANGED
|
@@ -143,6 +143,18 @@ function collectRects() {
|
|
|
143
143
|
}
|
|
144
144
|
return rects;
|
|
145
145
|
}
|
|
146
|
+
function findBlockEl(blockId) {
|
|
147
|
+
if (typeof document === "undefined") return null;
|
|
148
|
+
const escaped = typeof CSS !== "undefined" && typeof CSS.escape === "function" ? CSS.escape(blockId) : blockId.replace(/["\\]/g, "\\$&");
|
|
149
|
+
try {
|
|
150
|
+
return document.querySelector(`[data-block-id="${escaped}"]`);
|
|
151
|
+
} catch {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function prefersReducedMotion() {
|
|
156
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
157
|
+
}
|
|
146
158
|
function collectLayoutBlocks(rects, pageIds) {
|
|
147
159
|
const out = [];
|
|
148
160
|
if (typeof document === "undefined") return out;
|
|
@@ -251,6 +263,10 @@ function useEditBridge(page, config) {
|
|
|
251
263
|
} else if (message.type === "cmssy:select") {
|
|
252
264
|
setSelected(message.blockId);
|
|
253
265
|
selectedIdRef.current = message.blockId;
|
|
266
|
+
findBlockEl(message.blockId)?.scrollIntoView({
|
|
267
|
+
behavior: prefersReducedMotion() ? "auto" : "smooth",
|
|
268
|
+
block: "nearest"
|
|
269
|
+
});
|
|
254
270
|
} else if (message.type === "cmssy:insert") {
|
|
255
271
|
setInserted((prev) => {
|
|
256
272
|
const next = prev.filter((b) => b.blockId !== message.blockId);
|
|
@@ -303,9 +319,7 @@ function useEditBridge(page, config) {
|
|
|
303
319
|
boundsRaf = 0;
|
|
304
320
|
const id = selectedIdRef.current;
|
|
305
321
|
if (!id) return;
|
|
306
|
-
const el =
|
|
307
|
-
`[data-block-id="${id.replace(/["\\]/g, "\\$&")}"]`
|
|
308
|
-
);
|
|
322
|
+
const el = findBlockEl(id);
|
|
309
323
|
if (!el) return;
|
|
310
324
|
const r = el.getBoundingClientRect();
|
|
311
325
|
try {
|