@bleedingdev/modern-js-boundary-debugger 0.0.0 → 3.9.0-ultramodern.5
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/LICENSE +21 -0
- package/dist/cjs/boundary-debugger/index.js +317 -0
- package/dist/esm/boundary-debugger/index.mjs +277 -0
- package/dist/esm-node/boundary-debugger/index.mjs +278 -0
- package/dist/types/boundary-debugger/index.d.ts +28 -0
- package/package.json +58 -7
- package/rslib.config.mts +4 -0
- package/rstest.config.mts +36 -0
- package/src/boundary-debugger/index.tsx +427 -0
- package/tests/boundary-debugger/browser.test.ts +252 -0
- package/tests/boundary-debugger/client.test.tsx +297 -0
- package/tests/boundary-debugger/index.test.tsx +63 -0
- package/tsconfig.json +10 -0
- package/README.md +0 -3
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useMemo, useState } from "react";
|
|
4
|
+
const defaultStorageKey = 'modernjs:boundary-debugger:enabled';
|
|
5
|
+
const queryParamName = 'modern-boundaries';
|
|
6
|
+
const boundarySelector = '[data-modern-boundary-id]';
|
|
7
|
+
const defaultLabels = {
|
|
8
|
+
cs: {
|
|
9
|
+
toggle: 'zobrazit hranice týmů'
|
|
10
|
+
},
|
|
11
|
+
en: {
|
|
12
|
+
toggle: 'show team boundaries'
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
const palette = [
|
|
16
|
+
'#ff5a5f',
|
|
17
|
+
'#30e27a',
|
|
18
|
+
'#f6cf45',
|
|
19
|
+
'#7c8cff',
|
|
20
|
+
'#29b6f6'
|
|
21
|
+
];
|
|
22
|
+
const readStoredEnabled = (storageKey, fallback)=>{
|
|
23
|
+
if ("u" < typeof window) return fallback;
|
|
24
|
+
try {
|
|
25
|
+
const stored = window.localStorage.getItem(storageKey);
|
|
26
|
+
return null === stored ? fallback : 'true' === stored;
|
|
27
|
+
} catch {
|
|
28
|
+
return fallback;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const writeStoredEnabled = (storageKey, enabled)=>{
|
|
32
|
+
if ("u" < typeof window) return;
|
|
33
|
+
try {
|
|
34
|
+
window.localStorage.setItem(storageKey, String(enabled));
|
|
35
|
+
} catch {}
|
|
36
|
+
};
|
|
37
|
+
const parseEnabledOverride = (value)=>{
|
|
38
|
+
if (null === value) return;
|
|
39
|
+
const normalized = value.toLowerCase();
|
|
40
|
+
if ('1' === normalized || 'true' === normalized) return true;
|
|
41
|
+
if ('0' === normalized || 'false' === normalized) return false;
|
|
42
|
+
};
|
|
43
|
+
const readQueryEnabledOverride = ()=>{
|
|
44
|
+
if ("u" < typeof window) return;
|
|
45
|
+
try {
|
|
46
|
+
return parseEnabledOverride(new URLSearchParams(window.location.search).get(queryParamName));
|
|
47
|
+
} catch {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const detectLanguage = ()=>{
|
|
52
|
+
if ("u" < typeof document) return 'en';
|
|
53
|
+
const htmlLanguage = document.documentElement.lang;
|
|
54
|
+
if ('' !== htmlLanguage) return htmlLanguage.split('-')[0] || 'en';
|
|
55
|
+
if ("u" < typeof window) return 'en';
|
|
56
|
+
return window.location.pathname.split('/').filter(Boolean)[0] || 'en';
|
|
57
|
+
};
|
|
58
|
+
const hashBoundaryId = (id)=>{
|
|
59
|
+
let hash = 0;
|
|
60
|
+
for(let index = 0; index < id.length; index++)hash = 31 * hash + id.charCodeAt(index) >>> 0;
|
|
61
|
+
return hash;
|
|
62
|
+
};
|
|
63
|
+
const formatRectKey = (rect)=>[
|
|
64
|
+
Math.round(100 * rect.left) / 100,
|
|
65
|
+
Math.round(100 * rect.top) / 100,
|
|
66
|
+
Math.round(100 * rect.width) / 100,
|
|
67
|
+
Math.round(100 * rect.height) / 100
|
|
68
|
+
].join(':');
|
|
69
|
+
const getBoundaryId = (element)=>element.dataset.modernBoundaryId ?? element.dataset.mfRemote ?? element.getAttribute('data-mf-remote') ?? void 0;
|
|
70
|
+
const collectBoundaryElements = (legacySelector)=>{
|
|
71
|
+
const elements = new Set();
|
|
72
|
+
for (const element of document.querySelectorAll(boundarySelector))elements.add(element);
|
|
73
|
+
if (void 0 === legacySelector || '' === legacySelector) return Array.from(elements);
|
|
74
|
+
try {
|
|
75
|
+
for (const element of document.querySelectorAll(legacySelector))elements.add(element);
|
|
76
|
+
} catch {}
|
|
77
|
+
return Array.from(elements);
|
|
78
|
+
};
|
|
79
|
+
function BoundaryDebugger({ controlMode = 'visible', enabledByDefault = false, labels = defaultLabels, legacySelector, metadata, storageKey = defaultStorageKey }) {
|
|
80
|
+
const [mounted, setMounted] = useState(false);
|
|
81
|
+
const [enabled, setEnabled] = useState(false);
|
|
82
|
+
const [boxes, setBoxes] = useState([]);
|
|
83
|
+
const boundaries = useMemo(()=>new Map(metadata.boundaries.map((entry, index)=>[
|
|
84
|
+
entry.mfName,
|
|
85
|
+
{
|
|
86
|
+
...entry,
|
|
87
|
+
color: entry.color ?? palette[index % palette.length],
|
|
88
|
+
label: entry.label ?? entry.appId
|
|
89
|
+
}
|
|
90
|
+
])), [
|
|
91
|
+
metadata
|
|
92
|
+
]);
|
|
93
|
+
const language = mounted ? detectLanguage() : 'en';
|
|
94
|
+
const toggleLabel = labels[language]?.toggle ?? labels.en?.toggle ?? defaultLabels.en?.toggle ?? 'show team boundaries';
|
|
95
|
+
useEffect(()=>{
|
|
96
|
+
setMounted(true);
|
|
97
|
+
const queryOverride = readQueryEnabledOverride();
|
|
98
|
+
setEnabled(queryOverride ?? readStoredEnabled(storageKey, enabledByDefault));
|
|
99
|
+
}, [
|
|
100
|
+
enabledByDefault,
|
|
101
|
+
storageKey
|
|
102
|
+
]);
|
|
103
|
+
useEffect(()=>{
|
|
104
|
+
if (!mounted) return;
|
|
105
|
+
writeStoredEnabled(storageKey, enabled);
|
|
106
|
+
}, [
|
|
107
|
+
enabled,
|
|
108
|
+
mounted,
|
|
109
|
+
storageKey
|
|
110
|
+
]);
|
|
111
|
+
useEffect(()=>{
|
|
112
|
+
if (!enabled) return void setBoxes([]);
|
|
113
|
+
let resizeObserver;
|
|
114
|
+
const observedElements = new Set();
|
|
115
|
+
const observeBoundaryElements = (elements)=>{
|
|
116
|
+
if (void 0 === resizeObserver) return;
|
|
117
|
+
for (const element of elements)if (!observedElements.has(element)) {
|
|
118
|
+
observedElements.add(element);
|
|
119
|
+
resizeObserver.observe(element);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const readBoxes = ()=>{
|
|
123
|
+
const elements = collectBoundaryElements(legacySelector);
|
|
124
|
+
observeBoundaryElements(elements);
|
|
125
|
+
const seenBoxes = new Set();
|
|
126
|
+
const nextBoxes = elements.map((element)=>{
|
|
127
|
+
const boundaryId = getBoundaryId(element);
|
|
128
|
+
if (void 0 === boundaryId || '' === boundaryId) return;
|
|
129
|
+
const rect = element.getBoundingClientRect();
|
|
130
|
+
if (rect.width <= 0 || rect.height <= 0) return;
|
|
131
|
+
const rectKey = formatRectKey(rect);
|
|
132
|
+
const boxKey = `${boundaryId}:${rectKey}`;
|
|
133
|
+
if (seenBoxes.has(boxKey)) return;
|
|
134
|
+
seenBoxes.add(boxKey);
|
|
135
|
+
const boundary = boundaries.get(boundaryId);
|
|
136
|
+
const color = boundary?.color ?? palette[hashBoundaryId(boundaryId) % palette.length];
|
|
137
|
+
const label = boundary?.label ?? boundary?.appId ?? boundaryId;
|
|
138
|
+
const expose = element.dataset.modernMfExpose;
|
|
139
|
+
const detail = void 0 !== expose && '' !== expose && expose !== label && expose !== boundaryId ? expose : void 0;
|
|
140
|
+
const box = {
|
|
141
|
+
color,
|
|
142
|
+
height: rect.height,
|
|
143
|
+
id: boxKey,
|
|
144
|
+
label,
|
|
145
|
+
left: rect.left,
|
|
146
|
+
top: rect.top,
|
|
147
|
+
width: rect.width
|
|
148
|
+
};
|
|
149
|
+
if (void 0 !== detail) box.detail = detail;
|
|
150
|
+
return box;
|
|
151
|
+
}).filter((box)=>void 0 !== box);
|
|
152
|
+
setBoxes(nextBoxes);
|
|
153
|
+
};
|
|
154
|
+
resizeObserver = "u" < typeof ResizeObserver ? void 0 : new ResizeObserver(readBoxes);
|
|
155
|
+
readBoxes();
|
|
156
|
+
const mutationObserver = new MutationObserver(readBoxes);
|
|
157
|
+
mutationObserver.observe(document.body, {
|
|
158
|
+
childList: true,
|
|
159
|
+
subtree: true
|
|
160
|
+
});
|
|
161
|
+
window.addEventListener('resize', readBoxes);
|
|
162
|
+
window.addEventListener('scroll', readBoxes, true);
|
|
163
|
+
return ()=>{
|
|
164
|
+
mutationObserver.disconnect();
|
|
165
|
+
resizeObserver?.disconnect();
|
|
166
|
+
window.removeEventListener('resize', readBoxes);
|
|
167
|
+
window.removeEventListener('scroll', readBoxes, true);
|
|
168
|
+
};
|
|
169
|
+
}, [
|
|
170
|
+
boundaries,
|
|
171
|
+
enabled,
|
|
172
|
+
legacySelector
|
|
173
|
+
]);
|
|
174
|
+
if (!mounted) return null;
|
|
175
|
+
const shouldRenderToggle = 'visible' === controlMode || 'hidden-when-off' === controlMode && enabled;
|
|
176
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
177
|
+
children: [
|
|
178
|
+
shouldRenderToggle ? /*#__PURE__*/ jsxs("label", {
|
|
179
|
+
style: {
|
|
180
|
+
alignItems: 'center',
|
|
181
|
+
background: 'rgba(255, 255, 255, 0.96)',
|
|
182
|
+
border: '1px solid rgba(0, 0, 0, 0.1)',
|
|
183
|
+
borderRadius: 10,
|
|
184
|
+
boxShadow: '0 10px 28px rgba(0, 0, 0, 0.14)',
|
|
185
|
+
color: '#111827',
|
|
186
|
+
display: 'flex',
|
|
187
|
+
font: '600 13px/1.2 system-ui, sans-serif',
|
|
188
|
+
gap: 8,
|
|
189
|
+
left: 'max(12px, env(safe-area-inset-left))',
|
|
190
|
+
maxWidth: 'calc(100vw - 24px)',
|
|
191
|
+
padding: '9px 11px',
|
|
192
|
+
position: 'fixed',
|
|
193
|
+
top: 'max(12px, env(safe-area-inset-top))',
|
|
194
|
+
zIndex: 2147483000
|
|
195
|
+
},
|
|
196
|
+
children: [
|
|
197
|
+
/*#__PURE__*/ jsx("input", {
|
|
198
|
+
checked: enabled,
|
|
199
|
+
onChange: (event)=>setEnabled(event.currentTarget.checked),
|
|
200
|
+
type: "checkbox"
|
|
201
|
+
}),
|
|
202
|
+
/*#__PURE__*/ jsx("span", {
|
|
203
|
+
children: toggleLabel
|
|
204
|
+
})
|
|
205
|
+
]
|
|
206
|
+
}) : null,
|
|
207
|
+
enabled ? /*#__PURE__*/ jsx("div", {
|
|
208
|
+
"aria-hidden": "true",
|
|
209
|
+
children: boxes.map((box)=>/*#__PURE__*/ jsx("div", {
|
|
210
|
+
"data-modern-boundary-overlay": "",
|
|
211
|
+
"data-modern-boundary-overlay-id": box.id,
|
|
212
|
+
"data-modern-boundary-overlay-label": box.label,
|
|
213
|
+
style: {
|
|
214
|
+
border: `2px solid ${box.color}`,
|
|
215
|
+
borderRadius: 8,
|
|
216
|
+
boxSizing: 'border-box',
|
|
217
|
+
boxShadow: `0 0 0 1px rgba(255,255,255,.72), 0 6px 20px color-mix(in srgb, ${box.color} 20%, transparent)`,
|
|
218
|
+
height: box.height,
|
|
219
|
+
left: box.left,
|
|
220
|
+
pointerEvents: 'none',
|
|
221
|
+
position: 'fixed',
|
|
222
|
+
top: box.top,
|
|
223
|
+
width: box.width,
|
|
224
|
+
zIndex: 2147482999
|
|
225
|
+
},
|
|
226
|
+
children: /*#__PURE__*/ jsxs("span", {
|
|
227
|
+
style: {
|
|
228
|
+
background: box.color,
|
|
229
|
+
borderRadius: 999,
|
|
230
|
+
color: '#111827',
|
|
231
|
+
display: 'grid',
|
|
232
|
+
font: '800 11px/1.1 system-ui, sans-serif',
|
|
233
|
+
gap: 3,
|
|
234
|
+
maxWidth: 'min(280px, calc(100vw - 24px))',
|
|
235
|
+
padding: '5px 8px',
|
|
236
|
+
position: 'absolute',
|
|
237
|
+
right: 4,
|
|
238
|
+
top: 4,
|
|
239
|
+
whiteSpace: 'nowrap'
|
|
240
|
+
},
|
|
241
|
+
children: [
|
|
242
|
+
/*#__PURE__*/ jsx("span", {
|
|
243
|
+
children: box.label
|
|
244
|
+
}),
|
|
245
|
+
void 0 !== box.detail && '' !== box.detail ? /*#__PURE__*/ jsx("span", {
|
|
246
|
+
style: {
|
|
247
|
+
font: '700 10px/1.1 system-ui, sans-serif',
|
|
248
|
+
opacity: 0.82,
|
|
249
|
+
overflow: 'hidden',
|
|
250
|
+
textOverflow: 'ellipsis'
|
|
251
|
+
},
|
|
252
|
+
children: box.detail
|
|
253
|
+
}) : null
|
|
254
|
+
]
|
|
255
|
+
})
|
|
256
|
+
}, box.id))
|
|
257
|
+
}) : null
|
|
258
|
+
]
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
const ultramodernBoundaryDebuggerPlugin = (options)=>({
|
|
262
|
+
name: '@modern-js/runtime/boundary-debugger',
|
|
263
|
+
setup: (api)=>{
|
|
264
|
+
api.wrapRoot((App)=>(props)=>/*#__PURE__*/ jsxs(Fragment, {
|
|
265
|
+
children: [
|
|
266
|
+
/*#__PURE__*/ jsx(App, {
|
|
267
|
+
...props
|
|
268
|
+
}),
|
|
269
|
+
/*#__PURE__*/ jsx(BoundaryDebugger, {
|
|
270
|
+
...options
|
|
271
|
+
})
|
|
272
|
+
]
|
|
273
|
+
}));
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
const boundary_debugger = ultramodernBoundaryDebuggerPlugin;
|
|
277
|
+
export default boundary_debugger;
|
|
278
|
+
export { ultramodernBoundaryDebuggerPlugin };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { RuntimePlugin } from '@modern-js/plugin';
|
|
2
|
+
export type BoundaryDebugEntry = {
|
|
3
|
+
appId: string;
|
|
4
|
+
color?: string;
|
|
5
|
+
label?: string;
|
|
6
|
+
mfName: string;
|
|
7
|
+
ownerTeam?: string;
|
|
8
|
+
packageName?: string;
|
|
9
|
+
role?: 'host' | 'vertical';
|
|
10
|
+
};
|
|
11
|
+
export type BoundaryDebugMetadata = {
|
|
12
|
+
appId: string;
|
|
13
|
+
boundaries: BoundaryDebugEntry[];
|
|
14
|
+
schemaVersion: 1;
|
|
15
|
+
};
|
|
16
|
+
export type BoundaryDebuggerControlMode = 'visible' | 'hidden-when-off' | 'hidden';
|
|
17
|
+
export type BoundaryDebuggerPluginOptions = {
|
|
18
|
+
controlMode?: BoundaryDebuggerControlMode;
|
|
19
|
+
enabledByDefault?: boolean;
|
|
20
|
+
labels?: Record<string, {
|
|
21
|
+
toggle: string;
|
|
22
|
+
}>;
|
|
23
|
+
legacySelector?: string;
|
|
24
|
+
metadata: BoundaryDebugMetadata;
|
|
25
|
+
storageKey?: string;
|
|
26
|
+
};
|
|
27
|
+
export declare const ultramodernBoundaryDebuggerPlugin: (options: BoundaryDebuggerPluginOptions) => RuntimePlugin<{}>;
|
|
28
|
+
export default ultramodernBoundaryDebuggerPlugin;
|
package/package.json
CHANGED
|
@@ -1,16 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bleedingdev/modern-js-boundary-debugger",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"description": "Fork-owned browser boundary instrumentation registered through the native Modern.js runtime plugin API.",
|
|
4
|
+
"homepage": "https://github.com/BleedingDev/ultramodern.js#readme",
|
|
5
|
+
"bugs": {
|
|
6
|
+
"url": "https://github.com/BleedingDev/ultramodern.js/issues"
|
|
7
|
+
},
|
|
6
8
|
"repository": {
|
|
7
9
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/BleedingDev/ultramodern.js.git"
|
|
10
|
+
"url": "git+https://github.com/BleedingDev/ultramodern.js.git",
|
|
11
|
+
"directory": "packages/runtime/boundary-debugger"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"version": "3.9.0-ultramodern.5",
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=26.7.0"
|
|
17
|
+
},
|
|
18
|
+
"types": "./dist/types/boundary-debugger/index.d.ts",
|
|
19
|
+
"main": "./dist/cjs/boundary-debugger/index.js",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/types/boundary-debugger/index.d.ts",
|
|
23
|
+
"node": {
|
|
24
|
+
"import": "./dist/esm-node/boundary-debugger/index.mjs",
|
|
25
|
+
"require": "./dist/cjs/boundary-debugger/index.js"
|
|
26
|
+
},
|
|
27
|
+
"default": "./dist/esm/boundary-debugger/index.mjs"
|
|
28
|
+
}
|
|
9
29
|
},
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
|
|
30
|
+
"typesVersions": {
|
|
31
|
+
"*": {
|
|
32
|
+
".": [
|
|
33
|
+
"./dist/types/boundary-debugger/index.d.ts",
|
|
34
|
+
"./src/boundary-debugger/index.tsx"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.9.0-ultramodern.5"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@rslib/core": "1.0.0",
|
|
43
|
+
"@scripts/rstest-config": "2.66.0",
|
|
44
|
+
"@testing-library/dom": "^10.4.1",
|
|
45
|
+
"@testing-library/react": "^16.3.3",
|
|
46
|
+
"@types/node": "^26.4.1",
|
|
47
|
+
"@types/react": "^19.2.18",
|
|
48
|
+
"@types/react-dom": "^19.2.7",
|
|
49
|
+
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
|
50
|
+
"esbuild": "^0.28.2",
|
|
51
|
+
"react": "^19.2.8",
|
|
52
|
+
"react-dom": "^19.2.8",
|
|
53
|
+
"typescript": "^7.0.2"
|
|
54
|
+
},
|
|
55
|
+
"sideEffects": false,
|
|
13
56
|
"publishConfig": {
|
|
14
57
|
"access": "public"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"react": "^19.2.8"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"dev": "rslib build --watch",
|
|
64
|
+
"build": "rslib build",
|
|
65
|
+
"test": "rstest"
|
|
15
66
|
}
|
|
16
67
|
}
|
package/rslib.config.mts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ProjectConfig } from '@rstest/core';
|
|
2
|
+
import { withTestPreset } from '@scripts/rstest-config';
|
|
3
|
+
|
|
4
|
+
const commonConfig: ProjectConfig = {
|
|
5
|
+
root: __dirname,
|
|
6
|
+
globals: true,
|
|
7
|
+
setupFiles: ['@scripts/rstest-config/setup.ts'],
|
|
8
|
+
tools: {
|
|
9
|
+
swc: {
|
|
10
|
+
jsc: {
|
|
11
|
+
transform: {
|
|
12
|
+
react: {
|
|
13
|
+
runtime: 'automatic',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default {
|
|
22
|
+
projects: [
|
|
23
|
+
withTestPreset({
|
|
24
|
+
name: 'boundary-debugger-node',
|
|
25
|
+
testEnvironment: 'node',
|
|
26
|
+
exclude: ['tests/boundary-debugger/client.test.tsx'],
|
|
27
|
+
extends: commonConfig,
|
|
28
|
+
}),
|
|
29
|
+
withTestPreset({
|
|
30
|
+
name: 'boundary-debugger-client',
|
|
31
|
+
testEnvironment: 'happy-dom',
|
|
32
|
+
include: ['tests/boundary-debugger/client.test.tsx'],
|
|
33
|
+
extends: commonConfig,
|
|
34
|
+
}),
|
|
35
|
+
],
|
|
36
|
+
};
|