@cmssy/react 12.7.0 → 12.8.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 +34 -9
- package/dist/client.js +34 -9
- package/package.json +2 -2
package/dist/client.cjs
CHANGED
|
@@ -67,7 +67,9 @@ function resolveShortcutAction(event, isMac, isTyping) {
|
|
|
67
67
|
|
|
68
68
|
// src/bridge/invisible-blocks.ts
|
|
69
69
|
var TRANSPARENT = 0.01;
|
|
70
|
-
var
|
|
70
|
+
var VISIBLE_TEXT_FRACTION = 0.5;
|
|
71
|
+
var MEDIA = "img,svg,video,canvas,picture,iframe";
|
|
72
|
+
var UNPAINTED_TEXT = /* @__PURE__ */ new Set(["SCRIPT", "STYLE", "TEMPLATE", "NOSCRIPT"]);
|
|
71
73
|
function effectiveOpacity(node) {
|
|
72
74
|
let value = 1;
|
|
73
75
|
let current = node;
|
|
@@ -82,21 +84,38 @@ function effectiveOpacity(node) {
|
|
|
82
84
|
}
|
|
83
85
|
return value;
|
|
84
86
|
}
|
|
85
|
-
function
|
|
86
|
-
if (el.matches(PAINTS_WITHOUT_TEXT)) return true;
|
|
87
|
+
function holdsText(el) {
|
|
87
88
|
for (const node of el.childNodes) {
|
|
88
89
|
if (node.nodeType === 3 && node.textContent?.trim()) return true;
|
|
89
90
|
}
|
|
90
91
|
return false;
|
|
91
92
|
}
|
|
93
|
+
function collectCopy(block) {
|
|
94
|
+
const copy = [];
|
|
95
|
+
const keep = (el) => {
|
|
96
|
+
if (UNPAINTED_TEXT.has(el.tagName)) return;
|
|
97
|
+
if (el.closest("svg")) return;
|
|
98
|
+
if (holdsText(el)) copy.push(el);
|
|
99
|
+
};
|
|
100
|
+
keep(block);
|
|
101
|
+
for (const el of block.querySelectorAll("*")) keep(el);
|
|
102
|
+
return copy;
|
|
103
|
+
}
|
|
104
|
+
function collectMedia(block) {
|
|
105
|
+
const media = [];
|
|
106
|
+
if (block.matches(MEDIA)) media.push(block);
|
|
107
|
+
for (const el of block.querySelectorAll(MEDIA)) media.push(el);
|
|
108
|
+
return media;
|
|
109
|
+
}
|
|
92
110
|
function isBlockPainted(block) {
|
|
93
|
-
const
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
|
|
111
|
+
const copy = collectCopy(block);
|
|
112
|
+
if (copy.length > 0) {
|
|
113
|
+
const visible2 = copy.filter((el) => effectiveOpacity(el) > TRANSPARENT);
|
|
114
|
+
return visible2.length >= copy.length * VISIBLE_TEXT_FRACTION;
|
|
97
115
|
}
|
|
98
|
-
|
|
99
|
-
|
|
116
|
+
const media = collectMedia(block);
|
|
117
|
+
if (media.length === 0) return true;
|
|
118
|
+
return media.some((el) => effectiveOpacity(el) > TRANSPARENT);
|
|
100
119
|
}
|
|
101
120
|
|
|
102
121
|
// src/bridge/use-invisible-blocks.ts
|
|
@@ -204,6 +223,10 @@ function findBlockEl(blockId) {
|
|
|
204
223
|
return null;
|
|
205
224
|
}
|
|
206
225
|
}
|
|
226
|
+
function announceResize() {
|
|
227
|
+
if (typeof window === "undefined") return;
|
|
228
|
+
window.dispatchEvent(new Event("resize"));
|
|
229
|
+
}
|
|
207
230
|
function canDetectInvisibleBlocks() {
|
|
208
231
|
return typeof document !== "undefined" && typeof IntersectionObserver !== "undefined";
|
|
209
232
|
}
|
|
@@ -356,6 +379,8 @@ function useEditBridge(page, config) {
|
|
|
356
379
|
setRemoved(
|
|
357
380
|
(prev) => prev.includes(message.blockId) ? prev : [...prev, message.blockId]
|
|
358
381
|
);
|
|
382
|
+
} else if (message.type === "cmssy:viewport") {
|
|
383
|
+
announceResize();
|
|
359
384
|
} else if (message.type === "cmssy:parent-ready") {
|
|
360
385
|
sendReady();
|
|
361
386
|
}
|
package/dist/client.js
CHANGED
|
@@ -65,7 +65,9 @@ function resolveShortcutAction(event, isMac, isTyping) {
|
|
|
65
65
|
|
|
66
66
|
// src/bridge/invisible-blocks.ts
|
|
67
67
|
var TRANSPARENT = 0.01;
|
|
68
|
-
var
|
|
68
|
+
var VISIBLE_TEXT_FRACTION = 0.5;
|
|
69
|
+
var MEDIA = "img,svg,video,canvas,picture,iframe";
|
|
70
|
+
var UNPAINTED_TEXT = /* @__PURE__ */ new Set(["SCRIPT", "STYLE", "TEMPLATE", "NOSCRIPT"]);
|
|
69
71
|
function effectiveOpacity(node) {
|
|
70
72
|
let value = 1;
|
|
71
73
|
let current = node;
|
|
@@ -80,21 +82,38 @@ function effectiveOpacity(node) {
|
|
|
80
82
|
}
|
|
81
83
|
return value;
|
|
82
84
|
}
|
|
83
|
-
function
|
|
84
|
-
if (el.matches(PAINTS_WITHOUT_TEXT)) return true;
|
|
85
|
+
function holdsText(el) {
|
|
85
86
|
for (const node of el.childNodes) {
|
|
86
87
|
if (node.nodeType === 3 && node.textContent?.trim()) return true;
|
|
87
88
|
}
|
|
88
89
|
return false;
|
|
89
90
|
}
|
|
91
|
+
function collectCopy(block) {
|
|
92
|
+
const copy = [];
|
|
93
|
+
const keep = (el) => {
|
|
94
|
+
if (UNPAINTED_TEXT.has(el.tagName)) return;
|
|
95
|
+
if (el.closest("svg")) return;
|
|
96
|
+
if (holdsText(el)) copy.push(el);
|
|
97
|
+
};
|
|
98
|
+
keep(block);
|
|
99
|
+
for (const el of block.querySelectorAll("*")) keep(el);
|
|
100
|
+
return copy;
|
|
101
|
+
}
|
|
102
|
+
function collectMedia(block) {
|
|
103
|
+
const media = [];
|
|
104
|
+
if (block.matches(MEDIA)) media.push(block);
|
|
105
|
+
for (const el of block.querySelectorAll(MEDIA)) media.push(el);
|
|
106
|
+
return media;
|
|
107
|
+
}
|
|
90
108
|
function isBlockPainted(block) {
|
|
91
|
-
const
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
|
|
109
|
+
const copy = collectCopy(block);
|
|
110
|
+
if (copy.length > 0) {
|
|
111
|
+
const visible2 = copy.filter((el) => effectiveOpacity(el) > TRANSPARENT);
|
|
112
|
+
return visible2.length >= copy.length * VISIBLE_TEXT_FRACTION;
|
|
95
113
|
}
|
|
96
|
-
|
|
97
|
-
|
|
114
|
+
const media = collectMedia(block);
|
|
115
|
+
if (media.length === 0) return true;
|
|
116
|
+
return media.some((el) => effectiveOpacity(el) > TRANSPARENT);
|
|
98
117
|
}
|
|
99
118
|
|
|
100
119
|
// src/bridge/use-invisible-blocks.ts
|
|
@@ -202,6 +221,10 @@ function findBlockEl(blockId) {
|
|
|
202
221
|
return null;
|
|
203
222
|
}
|
|
204
223
|
}
|
|
224
|
+
function announceResize() {
|
|
225
|
+
if (typeof window === "undefined") return;
|
|
226
|
+
window.dispatchEvent(new Event("resize"));
|
|
227
|
+
}
|
|
205
228
|
function canDetectInvisibleBlocks() {
|
|
206
229
|
return typeof document !== "undefined" && typeof IntersectionObserver !== "undefined";
|
|
207
230
|
}
|
|
@@ -354,6 +377,8 @@ function useEditBridge(page, config) {
|
|
|
354
377
|
setRemoved(
|
|
355
378
|
(prev) => prev.includes(message.blockId) ? prev : [...prev, message.blockId]
|
|
356
379
|
);
|
|
380
|
+
} else if (message.type === "cmssy:viewport") {
|
|
381
|
+
announceResize();
|
|
357
382
|
} else if (message.type === "cmssy:parent-ready") {
|
|
358
383
|
sendReady();
|
|
359
384
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmssy/react",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.8.0",
|
|
4
4
|
"description": "React blocks, renderers, data client and editor bridge for cmssy headless sites",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cmssy",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
},
|
|
98
98
|
"dependencies": {
|
|
99
99
|
"@cmssy/types": "0.35.0",
|
|
100
|
-
"@cmssy/core": "12.
|
|
100
|
+
"@cmssy/core": "12.8.0"
|
|
101
101
|
},
|
|
102
102
|
"scripts": {
|
|
103
103
|
"build": "tsup",
|