@depup/base44__vite-plugin 1.0.4-depup.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/README.md +34 -0
- package/changes.json +22 -0
- package/compat/agents.cjs +13 -0
- package/compat/base44Client.cjs +6 -0
- package/compat/entities.cjs +25 -0
- package/compat/functions.cjs +9 -0
- package/compat/integrations.cjs +9 -0
- package/dist/ErrorOverlay.d.ts +12 -0
- package/dist/ErrorOverlay.d.ts.map +1 -0
- package/dist/ErrorOverlay.js +51 -0
- package/dist/ErrorOverlay.js.map +1 -0
- package/dist/bridge.d.ts +8 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.js +8 -0
- package/dist/bridge.js.map +1 -0
- package/dist/capabilities/inline-edit/controller.d.ts +3 -0
- package/dist/capabilities/inline-edit/controller.d.ts.map +1 -0
- package/dist/capabilities/inline-edit/controller.js +203 -0
- package/dist/capabilities/inline-edit/controller.js.map +1 -0
- package/dist/capabilities/inline-edit/dom-utils.d.ts +7 -0
- package/dist/capabilities/inline-edit/dom-utils.d.ts.map +1 -0
- package/dist/capabilities/inline-edit/dom-utils.js +59 -0
- package/dist/capabilities/inline-edit/dom-utils.js.map +1 -0
- package/dist/capabilities/inline-edit/index.d.ts +3 -0
- package/dist/capabilities/inline-edit/index.d.ts.map +1 -0
- package/dist/capabilities/inline-edit/index.js +2 -0
- package/dist/capabilities/inline-edit/index.js.map +1 -0
- package/dist/capabilities/inline-edit/types.d.ts +29 -0
- package/dist/capabilities/inline-edit/types.d.ts.map +1 -0
- package/dist/capabilities/inline-edit/types.js +2 -0
- package/dist/capabilities/inline-edit/types.js.map +1 -0
- package/dist/consts.d.ts +11 -0
- package/dist/consts.d.ts.map +1 -0
- package/dist/consts.js +11 -0
- package/dist/consts.js.map +1 -0
- package/dist/error-overlay-plugin.d.ts +3 -0
- package/dist/error-overlay-plugin.d.ts.map +1 -0
- package/dist/error-overlay-plugin.js +15 -0
- package/dist/error-overlay-plugin.js.map +1 -0
- package/dist/html-injections-plugin.d.ts +8 -0
- package/dist/html-injections-plugin.d.ts.map +1 -0
- package/dist/html-injections-plugin.js +132 -0
- package/dist/html-injections-plugin.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +158 -0
- package/dist/index.js.map +1 -0
- package/dist/injections/layer-dropdown/consts.d.ts +20 -0
- package/dist/injections/layer-dropdown/consts.d.ts.map +1 -0
- package/dist/injections/layer-dropdown/consts.js +41 -0
- package/dist/injections/layer-dropdown/consts.js.map +1 -0
- package/dist/injections/layer-dropdown/controller.d.ts +4 -0
- package/dist/injections/layer-dropdown/controller.d.ts.map +1 -0
- package/dist/injections/layer-dropdown/controller.js +88 -0
- package/dist/injections/layer-dropdown/controller.js.map +1 -0
- package/dist/injections/layer-dropdown/dropdown-ui.d.ts +13 -0
- package/dist/injections/layer-dropdown/dropdown-ui.d.ts.map +1 -0
- package/dist/injections/layer-dropdown/dropdown-ui.js +186 -0
- package/dist/injections/layer-dropdown/dropdown-ui.js.map +1 -0
- package/dist/injections/layer-dropdown/types.d.ts +26 -0
- package/dist/injections/layer-dropdown/types.d.ts.map +1 -0
- package/dist/injections/layer-dropdown/types.js +3 -0
- package/dist/injections/layer-dropdown/types.js.map +1 -0
- package/dist/injections/layer-dropdown/utils.d.ts +25 -0
- package/dist/injections/layer-dropdown/utils.d.ts.map +1 -0
- package/dist/injections/layer-dropdown/utils.js +143 -0
- package/dist/injections/layer-dropdown/utils.js.map +1 -0
- package/dist/injections/navigation-notifier.d.ts +2 -0
- package/dist/injections/navigation-notifier.d.ts.map +1 -0
- package/dist/injections/navigation-notifier.js +34 -0
- package/dist/injections/navigation-notifier.js.map +1 -0
- package/dist/injections/sandbox-hmr-notifier.d.ts +2 -0
- package/dist/injections/sandbox-hmr-notifier.d.ts.map +1 -0
- package/dist/injections/sandbox-hmr-notifier.js +10 -0
- package/dist/injections/sandbox-hmr-notifier.js.map +1 -0
- package/dist/injections/sandbox-mount-observer.d.ts +2 -0
- package/dist/injections/sandbox-mount-observer.d.ts.map +1 -0
- package/dist/injections/sandbox-mount-observer.js +18 -0
- package/dist/injections/sandbox-mount-observer.js.map +1 -0
- package/dist/injections/unhandled-errors-handlers.d.ts +2 -0
- package/dist/injections/unhandled-errors-handlers.d.ts.map +1 -0
- package/dist/injections/unhandled-errors-handlers.js +93 -0
- package/dist/injections/unhandled-errors-handlers.js.map +1 -0
- package/dist/injections/utils.d.ts +65 -0
- package/dist/injections/utils.d.ts.map +1 -0
- package/dist/injections/utils.js +186 -0
- package/dist/injections/utils.js.map +1 -0
- package/dist/injections/visual-edit-agent.d.ts +2 -0
- package/dist/injections/visual-edit-agent.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent.js +583 -0
- package/dist/injections/visual-edit-agent.js.map +1 -0
- package/dist/jsx-processor.d.ts +17 -0
- package/dist/jsx-processor.d.ts.map +1 -0
- package/dist/jsx-processor.js +129 -0
- package/dist/jsx-processor.js.map +1 -0
- package/dist/jsx-utils.d.ts +16 -0
- package/dist/jsx-utils.d.ts.map +1 -0
- package/dist/jsx-utils.js +98 -0
- package/dist/jsx-utils.js.map +1 -0
- package/dist/processors/collection-id-processor.d.ts +20 -0
- package/dist/processors/collection-id-processor.d.ts.map +1 -0
- package/dist/processors/collection-id-processor.js +182 -0
- package/dist/processors/collection-id-processor.js.map +1 -0
- package/dist/processors/collection-item-field-processor.d.ts +39 -0
- package/dist/processors/collection-item-field-processor.d.ts.map +1 -0
- package/dist/processors/collection-item-field-processor.js +289 -0
- package/dist/processors/collection-item-field-processor.js.map +1 -0
- package/dist/processors/collection-item-id-processor.d.ts +12 -0
- package/dist/processors/collection-item-id-processor.d.ts.map +1 -0
- package/dist/processors/collection-item-id-processor.js +50 -0
- package/dist/processors/collection-item-id-processor.js.map +1 -0
- package/dist/processors/static-array-processor.d.ts +28 -0
- package/dist/processors/static-array-processor.d.ts.map +1 -0
- package/dist/processors/static-array-processor.js +173 -0
- package/dist/processors/static-array-processor.js.map +1 -0
- package/dist/processors/utils/collection-tracing-utils.d.ts +36 -0
- package/dist/processors/utils/collection-tracing-utils.d.ts.map +1 -0
- package/dist/processors/utils/collection-tracing-utils.js +390 -0
- package/dist/processors/utils/collection-tracing-utils.js.map +1 -0
- package/dist/processors/utils/shared-utils.d.ts +96 -0
- package/dist/processors/utils/shared-utils.d.ts.map +1 -0
- package/dist/processors/utils/shared-utils.js +600 -0
- package/dist/processors/utils/shared-utils.js.map +1 -0
- package/dist/statics/index.mjs +16 -0
- package/dist/statics/index.mjs.map +1 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +22 -0
- package/dist/utils.js.map +1 -0
- package/dist/visual-edit-plugin.d.ts +3 -0
- package/dist/visual-edit-plugin.d.ts.map +1 -0
- package/dist/visual-edit-plugin.js +100 -0
- package/dist/visual-edit-plugin.js.map +1 -0
- package/package.json +75 -0
- package/src/ErrorOverlay.ts +71 -0
- package/src/bridge.ts +8 -0
- package/src/capabilities/inline-edit/controller.ts +254 -0
- package/src/capabilities/inline-edit/dom-utils.ts +58 -0
- package/src/capabilities/inline-edit/index.ts +2 -0
- package/src/capabilities/inline-edit/types.ts +35 -0
- package/src/consts.ts +11 -0
- package/src/error-overlay-plugin.ts +19 -0
- package/src/html-injections-plugin.ts +166 -0
- package/src/index.ts +225 -0
- package/src/injections/layer-dropdown/LAYERS.md +258 -0
- package/src/injections/layer-dropdown/consts.ts +51 -0
- package/src/injections/layer-dropdown/controller.ts +109 -0
- package/src/injections/layer-dropdown/dropdown-ui.ts +242 -0
- package/src/injections/layer-dropdown/types.ts +30 -0
- package/src/injections/layer-dropdown/utils.ts +175 -0
- package/src/injections/navigation-notifier.ts +43 -0
- package/src/injections/sandbox-hmr-notifier.ts +8 -0
- package/src/injections/sandbox-mount-observer.ts +25 -0
- package/src/injections/unhandled-errors-handlers.ts +114 -0
- package/src/injections/utils.ts +208 -0
- package/src/injections/visual-edit-agent.ts +706 -0
- package/src/jsx-processor.ts +169 -0
- package/src/jsx-utils.ts +131 -0
- package/src/processors/collection-id-processor.ts +261 -0
- package/src/processors/collection-item-field-processor.ts +439 -0
- package/src/processors/collection-item-id-processor.ts +69 -0
- package/src/processors/static-array-processor.ts +260 -0
- package/src/processors/utils/collection-tracing-utils.ts +507 -0
- package/src/processors/utils/shared-utils.ts +785 -0
- package/src/utils.ts +27 -0
- package/src/visual-edit-plugin.md +358 -0
- package/src/visual-edit-plugin.ts +110 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/** Dropdown UI component for layer navigation */
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
DROPDOWN_CONTAINER_STYLES,
|
|
5
|
+
DROPDOWN_ITEM_BASE_STYLES,
|
|
6
|
+
DROPDOWN_ITEM_ACTIVE_COLOR,
|
|
7
|
+
DROPDOWN_ITEM_ACTIVE_BG,
|
|
8
|
+
DROPDOWN_ITEM_ACTIVE_FONT_WEIGHT,
|
|
9
|
+
DROPDOWN_ITEM_HOVER_BG,
|
|
10
|
+
DEPTH_INDENT_PX,
|
|
11
|
+
BASE_PADDING_PX,
|
|
12
|
+
CHEVRON_COLLAPSED,
|
|
13
|
+
CHEVRON_EXPANDED,
|
|
14
|
+
CHEVRON_ATTR,
|
|
15
|
+
LAYER_DROPDOWN_ATTR,
|
|
16
|
+
} from "./consts.js";
|
|
17
|
+
import { applyStyles, getLayerDisplayName } from "./utils.js";
|
|
18
|
+
import type { LayerInfo, DropdownCallbacks } from "./types.js";
|
|
19
|
+
import { PLUGIN_ELEMENT_ATTR } from "../utils.js";
|
|
20
|
+
|
|
21
|
+
let activeDropdown: HTMLDivElement | null = null;
|
|
22
|
+
let activeLabel: HTMLDivElement | null = null;
|
|
23
|
+
let outsideMousedownHandler: ((e: MouseEvent) => void) | null = null;
|
|
24
|
+
let activeOnHoverEnd: (() => void) | null = null;
|
|
25
|
+
let activeKeydownHandler: ((e: KeyboardEvent) => void) | null = null;
|
|
26
|
+
|
|
27
|
+
function createDropdownItem(
|
|
28
|
+
layer: LayerInfo,
|
|
29
|
+
isActive: boolean,
|
|
30
|
+
{ onSelect, onHover, onHoverEnd }: DropdownCallbacks
|
|
31
|
+
): HTMLDivElement {
|
|
32
|
+
const item = document.createElement("div");
|
|
33
|
+
item.textContent = getLayerDisplayName(layer);
|
|
34
|
+
applyStyles(item, DROPDOWN_ITEM_BASE_STYLES);
|
|
35
|
+
|
|
36
|
+
const depth = layer.depth ?? 0;
|
|
37
|
+
if (depth > 0) {
|
|
38
|
+
item.style.paddingLeft = `${BASE_PADDING_PX + depth * DEPTH_INDENT_PX}px`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (isActive) {
|
|
42
|
+
item.style.color = DROPDOWN_ITEM_ACTIVE_COLOR;
|
|
43
|
+
item.style.backgroundColor = DROPDOWN_ITEM_ACTIVE_BG;
|
|
44
|
+
item.style.fontWeight = DROPDOWN_ITEM_ACTIVE_FONT_WEIGHT;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
item.addEventListener("mouseenter", () => {
|
|
48
|
+
if (!isActive) item.style.backgroundColor = DROPDOWN_ITEM_HOVER_BG;
|
|
49
|
+
if (onHover) onHover(layer);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
item.addEventListener("mouseleave", () => {
|
|
53
|
+
if (!isActive) item.style.backgroundColor = "transparent";
|
|
54
|
+
if (onHoverEnd) onHoverEnd();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
item.addEventListener("click", (e: MouseEvent) => {
|
|
58
|
+
e.stopPropagation();
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
onSelect(layer);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return item;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Create the dropdown DOM element with layer items */
|
|
67
|
+
export function createDropdownElement(
|
|
68
|
+
layers: LayerInfo[],
|
|
69
|
+
currentElement: Element | null,
|
|
70
|
+
callbacks: DropdownCallbacks
|
|
71
|
+
): HTMLDivElement {
|
|
72
|
+
const container = document.createElement("div");
|
|
73
|
+
container.setAttribute(LAYER_DROPDOWN_ATTR, "true");
|
|
74
|
+
container.setAttribute(PLUGIN_ELEMENT_ATTR, "true");
|
|
75
|
+
applyStyles(container, DROPDOWN_CONTAINER_STYLES);
|
|
76
|
+
|
|
77
|
+
layers.forEach((layer) => {
|
|
78
|
+
const isActive = layer.element === currentElement;
|
|
79
|
+
container.appendChild(createDropdownItem(layer, isActive, callbacks));
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return container;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Add chevron indicator and pointer-events to the label */
|
|
86
|
+
export function enhanceLabelWithChevron(label: HTMLDivElement): void {
|
|
87
|
+
if (label.querySelector(`[${CHEVRON_ATTR}]`)) return;
|
|
88
|
+
|
|
89
|
+
const chevron = document.createElement("span");
|
|
90
|
+
chevron.setAttribute(CHEVRON_ATTR, "true");
|
|
91
|
+
chevron.style.display = "inline-flex";
|
|
92
|
+
chevron.innerHTML = CHEVRON_COLLAPSED;
|
|
93
|
+
label.appendChild(chevron);
|
|
94
|
+
|
|
95
|
+
label.style.display = "inline-flex";
|
|
96
|
+
label.style.alignItems = "center";
|
|
97
|
+
label.style.cursor = "pointer";
|
|
98
|
+
label.style.userSelect = "none";
|
|
99
|
+
label.style.whiteSpace = "nowrap";
|
|
100
|
+
label.style.pointerEvents = "auto";
|
|
101
|
+
label.setAttribute(LAYER_DROPDOWN_ATTR, "true");
|
|
102
|
+
label.setAttribute(PLUGIN_ELEMENT_ATTR, "true");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function setupKeyboardNavigation(
|
|
106
|
+
dropdown: HTMLDivElement,
|
|
107
|
+
layers: LayerInfo[],
|
|
108
|
+
currentElement: Element | null,
|
|
109
|
+
{ onSelect, onHover, onHoverEnd }: DropdownCallbacks
|
|
110
|
+
): void {
|
|
111
|
+
const items = Array.from(dropdown.children) as HTMLDivElement[];
|
|
112
|
+
let focusedIndex = layers.findIndex((l) => l.element === currentElement);
|
|
113
|
+
|
|
114
|
+
const setFocusedItem = (index: number) => {
|
|
115
|
+
if (focusedIndex >= 0 && focusedIndex < items.length) {
|
|
116
|
+
const prev = items[focusedIndex]!;
|
|
117
|
+
if (prev.style.color !== DROPDOWN_ITEM_ACTIVE_COLOR) {
|
|
118
|
+
prev.style.backgroundColor = "transparent";
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
focusedIndex = index;
|
|
122
|
+
if (focusedIndex >= 0 && focusedIndex < items.length) {
|
|
123
|
+
const cur = items[focusedIndex]!;
|
|
124
|
+
if (cur.style.color !== DROPDOWN_ITEM_ACTIVE_COLOR) {
|
|
125
|
+
cur.style.backgroundColor = DROPDOWN_ITEM_HOVER_BG;
|
|
126
|
+
}
|
|
127
|
+
cur.scrollIntoView({ block: "nearest" });
|
|
128
|
+
if (onHover && focusedIndex >= 0 && focusedIndex < layers.length) {
|
|
129
|
+
onHover(layers[focusedIndex]!);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
activeKeydownHandler = (e: KeyboardEvent) => {
|
|
135
|
+
if (e.key === "ArrowDown") {
|
|
136
|
+
e.preventDefault();
|
|
137
|
+
e.stopPropagation();
|
|
138
|
+
setFocusedItem(focusedIndex < items.length - 1 ? focusedIndex + 1 : 0);
|
|
139
|
+
} else if (e.key === "ArrowUp") {
|
|
140
|
+
e.preventDefault();
|
|
141
|
+
e.stopPropagation();
|
|
142
|
+
setFocusedItem(focusedIndex > 0 ? focusedIndex - 1 : items.length - 1);
|
|
143
|
+
} else if (e.key === "Enter" && focusedIndex >= 0 && focusedIndex < layers.length) {
|
|
144
|
+
e.preventDefault();
|
|
145
|
+
e.stopPropagation();
|
|
146
|
+
if (onHoverEnd) onHoverEnd();
|
|
147
|
+
onSelect(layers[focusedIndex]!);
|
|
148
|
+
closeDropdown();
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
document.addEventListener("keydown", activeKeydownHandler, true);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function setupOutsideClickHandler(
|
|
155
|
+
dropdown: HTMLDivElement,
|
|
156
|
+
label: HTMLDivElement
|
|
157
|
+
): void {
|
|
158
|
+
let skipFirst = true;
|
|
159
|
+
outsideMousedownHandler = (e: MouseEvent) => {
|
|
160
|
+
if (skipFirst) { skipFirst = false; return; }
|
|
161
|
+
const target = e.target as Node;
|
|
162
|
+
if (!dropdown.contains(target) && target !== label) {
|
|
163
|
+
closeDropdown();
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
document.addEventListener("mousedown", outsideMousedownHandler, true);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Show the dropdown below the label element */
|
|
170
|
+
export function showDropdown(
|
|
171
|
+
label: HTMLDivElement,
|
|
172
|
+
layers: LayerInfo[],
|
|
173
|
+
currentElement: Element | null,
|
|
174
|
+
callbacks: DropdownCallbacks
|
|
175
|
+
): void {
|
|
176
|
+
closeDropdown();
|
|
177
|
+
|
|
178
|
+
const dropdown = createDropdownElement(
|
|
179
|
+
layers,
|
|
180
|
+
currentElement,
|
|
181
|
+
{
|
|
182
|
+
...callbacks,
|
|
183
|
+
onSelect: (layer) => {
|
|
184
|
+
if (callbacks.onHoverEnd) callbacks.onHoverEnd();
|
|
185
|
+
callbacks.onSelect(layer);
|
|
186
|
+
closeDropdown();
|
|
187
|
+
},
|
|
188
|
+
}
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
const overlay = label.parentElement;
|
|
192
|
+
if (!overlay) return;
|
|
193
|
+
|
|
194
|
+
dropdown.style.top = `${label.offsetTop + label.offsetHeight + 2}px`;
|
|
195
|
+
dropdown.style.left = `${label.offsetLeft}px`;
|
|
196
|
+
|
|
197
|
+
overlay.appendChild(dropdown);
|
|
198
|
+
activeDropdown = dropdown;
|
|
199
|
+
activeLabel = label;
|
|
200
|
+
const chevronEl = label.querySelector(`[${CHEVRON_ATTR}]`);
|
|
201
|
+
if (chevronEl) {
|
|
202
|
+
chevronEl.innerHTML = CHEVRON_EXPANDED;
|
|
203
|
+
}
|
|
204
|
+
activeOnHoverEnd = callbacks.onHoverEnd ?? null;
|
|
205
|
+
|
|
206
|
+
setupKeyboardNavigation(dropdown, layers, currentElement, callbacks);
|
|
207
|
+
setupOutsideClickHandler(dropdown, label);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Close the active dropdown and clean up listeners */
|
|
211
|
+
export function closeDropdown(): void {
|
|
212
|
+
const chevronEl = activeLabel?.querySelector(`[${CHEVRON_ATTR}]`);
|
|
213
|
+
if (chevronEl) {
|
|
214
|
+
chevronEl.innerHTML = CHEVRON_COLLAPSED;
|
|
215
|
+
}
|
|
216
|
+
activeLabel = null;
|
|
217
|
+
|
|
218
|
+
if (activeOnHoverEnd) {
|
|
219
|
+
activeOnHoverEnd();
|
|
220
|
+
activeOnHoverEnd = null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (activeDropdown && activeDropdown.parentNode) {
|
|
224
|
+
activeDropdown.remove();
|
|
225
|
+
}
|
|
226
|
+
activeDropdown = null;
|
|
227
|
+
|
|
228
|
+
if (outsideMousedownHandler) {
|
|
229
|
+
document.removeEventListener("mousedown", outsideMousedownHandler, true);
|
|
230
|
+
outsideMousedownHandler = null;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (activeKeydownHandler) {
|
|
234
|
+
document.removeEventListener("keydown", activeKeydownHandler, true);
|
|
235
|
+
activeKeydownHandler = null;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Check if a dropdown is currently visible */
|
|
240
|
+
export function isDropdownOpen(): boolean {
|
|
241
|
+
return activeDropdown !== null;
|
|
242
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Shared types for the layer-dropdown module */
|
|
2
|
+
|
|
3
|
+
export interface LayerInfo {
|
|
4
|
+
element: Element;
|
|
5
|
+
tagName: string;
|
|
6
|
+
selectorId: string | null;
|
|
7
|
+
depth?: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type OnLayerSelect = (layer: LayerInfo) => void;
|
|
11
|
+
export type OnLayerHover = (layer: LayerInfo) => void;
|
|
12
|
+
export type OnLayerHoverEnd = () => void;
|
|
13
|
+
|
|
14
|
+
export interface DropdownCallbacks {
|
|
15
|
+
onSelect: OnLayerSelect;
|
|
16
|
+
onHover?: OnLayerHover;
|
|
17
|
+
onHoverEnd?: OnLayerHoverEnd;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface LayerControllerConfig {
|
|
21
|
+
createPreviewOverlay: (element: Element) => HTMLDivElement;
|
|
22
|
+
getSelectedElementId: () => string | null;
|
|
23
|
+
selectElement: (element: Element) => HTMLDivElement | undefined;
|
|
24
|
+
onDeselect: () => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface LayerController {
|
|
28
|
+
attachToOverlay: (overlay: HTMLDivElement | undefined, element: Element) => void;
|
|
29
|
+
cleanup: () => void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/** DOM utilities for the layer-dropdown module */
|
|
2
|
+
|
|
3
|
+
import { isInstrumentedElement, getElementSelectorId } from "../utils.js";
|
|
4
|
+
import { MAX_PARENT_DEPTH, MAX_CHILD_DEPTH } from "./consts.js";
|
|
5
|
+
|
|
6
|
+
import type { LayerInfo } from "./types.js";
|
|
7
|
+
|
|
8
|
+
/** Apply a style map to an element */
|
|
9
|
+
export function applyStyles(element: HTMLElement, styles: Record<string, string>): void {
|
|
10
|
+
for (const key of Object.keys(styles)) {
|
|
11
|
+
element.style.setProperty(
|
|
12
|
+
key.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`),
|
|
13
|
+
styles[key]!
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Display name for a layer — just the real tag name */
|
|
19
|
+
export function getLayerDisplayName(layer: LayerInfo): string {
|
|
20
|
+
return layer.tagName;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function toLayerInfo(element: Element, depth?: number): LayerInfo {
|
|
24
|
+
const info: LayerInfo = {
|
|
25
|
+
element,
|
|
26
|
+
tagName: element.tagName.toLowerCase(),
|
|
27
|
+
selectorId: getElementSelectorId(element),
|
|
28
|
+
};
|
|
29
|
+
if (depth !== undefined) info.depth = depth;
|
|
30
|
+
return info;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Collect instrumented descendants up to `maxDepth` instrumented nesting levels.
|
|
35
|
+
* Non-instrumented wrappers are walked through without counting toward depth.
|
|
36
|
+
* Results are in DOM order.
|
|
37
|
+
* When `startDepth` is provided, assigns `depth` to each item during collection.
|
|
38
|
+
*/
|
|
39
|
+
export function getInstrumentedDescendants(
|
|
40
|
+
parent: Element,
|
|
41
|
+
maxDepth: number,
|
|
42
|
+
startDepth?: number
|
|
43
|
+
): LayerInfo[] {
|
|
44
|
+
const result: LayerInfo[] = [];
|
|
45
|
+
|
|
46
|
+
function walk(el: Element, instrDepth: number): void {
|
|
47
|
+
if (instrDepth > maxDepth) return;
|
|
48
|
+
for (let i = 0; i < el.children.length; i++) {
|
|
49
|
+
const child = el.children[i]!;
|
|
50
|
+
if (isInstrumentedElement(child)) {
|
|
51
|
+
const info: LayerInfo = {
|
|
52
|
+
element: child,
|
|
53
|
+
tagName: child.tagName.toLowerCase(),
|
|
54
|
+
selectorId: getElementSelectorId(child),
|
|
55
|
+
};
|
|
56
|
+
if (startDepth !== undefined) {
|
|
57
|
+
info.depth = startDepth + instrDepth - 1;
|
|
58
|
+
}
|
|
59
|
+
result.push(info);
|
|
60
|
+
walk(child, instrDepth + 1);
|
|
61
|
+
} else {
|
|
62
|
+
walk(child, instrDepth);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
walk(parent, 1);
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Collect instrumented ancestors from selected element up to MAX_PARENT_DEPTH (outermost first). */
|
|
72
|
+
function collectInstrumentedParents(selectedElement: Element): LayerInfo[] {
|
|
73
|
+
const parents: LayerInfo[] = [];
|
|
74
|
+
let current = selectedElement.parentElement;
|
|
75
|
+
while (
|
|
76
|
+
current &&
|
|
77
|
+
current !== document.documentElement &&
|
|
78
|
+
current !== document.body &&
|
|
79
|
+
parents.length < MAX_PARENT_DEPTH
|
|
80
|
+
) {
|
|
81
|
+
if (isInstrumentedElement(current)) {
|
|
82
|
+
parents.push(toLayerInfo(current));
|
|
83
|
+
}
|
|
84
|
+
current = current.parentElement;
|
|
85
|
+
}
|
|
86
|
+
parents.reverse();
|
|
87
|
+
return parents;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Add parents to chain with depth 0, 1, …; returns depth of selected (parents.length). */
|
|
91
|
+
function addParentsToChain(chain: LayerInfo[], parents: LayerInfo[]): number {
|
|
92
|
+
parents.forEach((p, i) => {
|
|
93
|
+
chain.push({ ...p, depth: i });
|
|
94
|
+
});
|
|
95
|
+
return parents.length;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Add selected element and its descendants at the given depth. */
|
|
99
|
+
function addSelfAndDescendantsToChain(
|
|
100
|
+
chain: LayerInfo[],
|
|
101
|
+
selectedElement: Element,
|
|
102
|
+
selfDepth: number
|
|
103
|
+
): void {
|
|
104
|
+
chain.push(toLayerInfo(selectedElement, selfDepth));
|
|
105
|
+
const descendants = getInstrumentedDescendants(
|
|
106
|
+
selectedElement,
|
|
107
|
+
MAX_CHILD_DEPTH,
|
|
108
|
+
selfDepth + 1
|
|
109
|
+
);
|
|
110
|
+
chain.push(...descendants);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Get the innermost instrumented parent's DOM element, or null if none. */
|
|
114
|
+
function getImmediateInstrParent(parents: LayerInfo[]): Element | null {
|
|
115
|
+
return parents.at(-1)?.element ?? null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Collect instrumented siblings of the selected element from its parent (DOM order). */
|
|
119
|
+
function collectSiblings(parent: Element, selectedElement: Element): LayerInfo[] {
|
|
120
|
+
const siblings = getInstrumentedDescendants(parent, 1);
|
|
121
|
+
if (!siblings.some((s) => s.element === selectedElement)) {
|
|
122
|
+
siblings.push(toLayerInfo(selectedElement));
|
|
123
|
+
}
|
|
124
|
+
return siblings;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Add siblings at selfDepth, expanding children only for the selected element. */
|
|
128
|
+
function appendSiblingsWithSelected(
|
|
129
|
+
chain: LayerInfo[],
|
|
130
|
+
siblings: LayerInfo[],
|
|
131
|
+
selectedElement: Element,
|
|
132
|
+
selfDepth: number
|
|
133
|
+
): void {
|
|
134
|
+
const selectedSelectorId = getElementSelectorId(selectedElement);
|
|
135
|
+
const seen = new Set<string>();
|
|
136
|
+
for (const sibling of siblings) {
|
|
137
|
+
if (sibling.element === selectedElement) {
|
|
138
|
+
addSelfAndDescendantsToChain(chain, selectedElement, selfDepth);
|
|
139
|
+
if (selectedSelectorId) seen.add(selectedSelectorId);
|
|
140
|
+
} else {
|
|
141
|
+
const id = sibling.selectorId;
|
|
142
|
+
if (id != null) {
|
|
143
|
+
if (id === selectedSelectorId || seen.has(id)) continue;
|
|
144
|
+
seen.add(id);
|
|
145
|
+
}
|
|
146
|
+
chain.push({ ...sibling, depth: selfDepth });
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Build the layer chain for the dropdown:
|
|
153
|
+
*
|
|
154
|
+
* Parents – up to MAX_PARENT_DEPTH instrumented ancestors, outer → inner.
|
|
155
|
+
* Siblings – instrumented children of the immediate parent, at the same depth.
|
|
156
|
+
* Current – the selected element (highlighted), with children expanded.
|
|
157
|
+
* Children – instrumented descendants within MAX_CHILD_DEPTH levels, DOM order.
|
|
158
|
+
*
|
|
159
|
+
* Each item carries a `depth` for visual indentation.
|
|
160
|
+
*/
|
|
161
|
+
export function buildLayerChain(selectedElement: Element): LayerInfo[] {
|
|
162
|
+
const parents = collectInstrumentedParents(selectedElement);
|
|
163
|
+
const chain: LayerInfo[] = [];
|
|
164
|
+
const selfDepth = addParentsToChain(chain, parents);
|
|
165
|
+
|
|
166
|
+
const instrParent = getImmediateInstrParent(parents);
|
|
167
|
+
if (instrParent) {
|
|
168
|
+
const siblings = collectSiblings(instrParent, selectedElement);
|
|
169
|
+
appendSiblingsWithSelected(chain, siblings, selectedElement, selfDepth);
|
|
170
|
+
} else {
|
|
171
|
+
addSelfAndDescendantsToChain(chain, selectedElement, selfDepth);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return chain;
|
|
175
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
if (window.self !== window.top) {
|
|
2
|
+
let lastUrl = window.location.href;
|
|
3
|
+
|
|
4
|
+
function notifyNavigation() {
|
|
5
|
+
const currentUrl = window.location.href;
|
|
6
|
+
if (currentUrl !== lastUrl) {
|
|
7
|
+
lastUrl = currentUrl;
|
|
8
|
+
window.parent?.postMessage(
|
|
9
|
+
{
|
|
10
|
+
type: "app_changed_url",
|
|
11
|
+
url: currentUrl,
|
|
12
|
+
},
|
|
13
|
+
"*"
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Intercept history.pushState
|
|
19
|
+
const originalPushState = history.pushState.bind(history);
|
|
20
|
+
history.pushState = function (...args) {
|
|
21
|
+
originalPushState(...args);
|
|
22
|
+
notifyNavigation();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// Intercept history.replaceState
|
|
26
|
+
const originalReplaceState = history.replaceState.bind(history);
|
|
27
|
+
history.replaceState = function (...args) {
|
|
28
|
+
originalReplaceState(...args);
|
|
29
|
+
notifyNavigation();
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Handle browser back/forward navigation
|
|
33
|
+
window.addEventListener("popstate", notifyNavigation);
|
|
34
|
+
|
|
35
|
+
// Notify initial URL on load
|
|
36
|
+
window.parent?.postMessage(
|
|
37
|
+
{
|
|
38
|
+
type: "app_changed_url",
|
|
39
|
+
url: window.location.href,
|
|
40
|
+
},
|
|
41
|
+
"*"
|
|
42
|
+
);
|
|
43
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
if (import.meta.hot) {
|
|
2
|
+
import.meta.hot.on("vite:beforeUpdate", () => {
|
|
3
|
+
window.parent?.postMessage({ type: "sandbox:beforeUpdate" }, "*");
|
|
4
|
+
});
|
|
5
|
+
import.meta.hot.on("vite:afterUpdate", () => {
|
|
6
|
+
window.parent?.postMessage({ type: "sandbox:afterUpdate" }, "*");
|
|
7
|
+
});
|
|
8
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
if (window.self !== window.top) {
|
|
3
|
+
const observer = new MutationObserver((mutations) => {
|
|
4
|
+
const nodesAdded = mutations.some(
|
|
5
|
+
(mutation) => mutation.addedNodes.length > 0
|
|
6
|
+
);
|
|
7
|
+
const nodesRemoved = mutations.some(
|
|
8
|
+
(mutation) => mutation.removedNodes.length > 0
|
|
9
|
+
);
|
|
10
|
+
if (nodesAdded || nodesRemoved) {
|
|
11
|
+
const foundElmWithDataAttribute =
|
|
12
|
+
document.body.querySelectorAll(
|
|
13
|
+
"[data-source-location], [data-dynamic-content]"
|
|
14
|
+
).length > 0;
|
|
15
|
+
|
|
16
|
+
if (foundElmWithDataAttribute) {
|
|
17
|
+
window.parent?.postMessage({ type: "sandbox:onMounted" }, "*");
|
|
18
|
+
} else {
|
|
19
|
+
window.parent?.postMessage({ type: "sandbox:onUnmounted" }, "*");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
25
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
|
|
3
|
+
window.removeEventListener("unhandledrejection", handleUnhandledRejection);
|
|
4
|
+
window.removeEventListener("error", handleWindowError);
|
|
5
|
+
|
|
6
|
+
window.addEventListener("unhandledrejection", handleUnhandledRejection);
|
|
7
|
+
window.addEventListener("error", handleWindowError);
|
|
8
|
+
|
|
9
|
+
let shouldPropagateErrors = true;
|
|
10
|
+
let suppressionTimer: ReturnType<typeof setTimeout> | null = null;
|
|
11
|
+
let hadSuppressedErrors = false;
|
|
12
|
+
|
|
13
|
+
if (import.meta.hot) {
|
|
14
|
+
import.meta.hot.on("vite:beforeUpdate", () => {
|
|
15
|
+
shouldPropagateErrors = false;
|
|
16
|
+
hadSuppressedErrors = false;
|
|
17
|
+
|
|
18
|
+
if (suppressionTimer) {
|
|
19
|
+
clearTimeout(suppressionTimer);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
suppressionTimer = setTimeout(() => {
|
|
23
|
+
shouldPropagateErrors = true;
|
|
24
|
+
suppressionTimer = null;
|
|
25
|
+
hadSuppressedErrors = false;
|
|
26
|
+
// No vite:afterUpdate after timeout — treat the stuck update as an error
|
|
27
|
+
window.parent?.postMessage({ type: "sandbox:hmrErrorsSuppressed" }, "*");
|
|
28
|
+
}, import.meta.env.VITE_HMR_ERROR_SUPPRESSION_DELAY ?? 10000);
|
|
29
|
+
});
|
|
30
|
+
import.meta.hot.on("vite:afterUpdate", () => {
|
|
31
|
+
shouldPropagateErrors = true;
|
|
32
|
+
if (suppressionTimer) {
|
|
33
|
+
clearTimeout(suppressionTimer);
|
|
34
|
+
suppressionTimer = null;
|
|
35
|
+
}
|
|
36
|
+
if (hadSuppressedErrors) {
|
|
37
|
+
window.parent?.postMessage({ type: "sandbox:hmrErrorsSuppressed" }, "*");
|
|
38
|
+
hadSuppressedErrors = false;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
import.meta.hot.on("vite:beforeFullReload", () => {
|
|
42
|
+
shouldPropagateErrors = false;
|
|
43
|
+
hadSuppressedErrors = false;
|
|
44
|
+
if (suppressionTimer) {
|
|
45
|
+
clearTimeout(suppressionTimer);
|
|
46
|
+
suppressionTimer = null;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function onAppError({
|
|
52
|
+
title,
|
|
53
|
+
details,
|
|
54
|
+
componentName,
|
|
55
|
+
originalError,
|
|
56
|
+
}: {
|
|
57
|
+
title: string;
|
|
58
|
+
details: string;
|
|
59
|
+
componentName: string;
|
|
60
|
+
originalError: any;
|
|
61
|
+
}) {
|
|
62
|
+
if (originalError?.response?.status === 402) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (!shouldPropagateErrors) {
|
|
66
|
+
hadSuppressedErrors = true;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
window.parent?.postMessage(
|
|
70
|
+
{
|
|
71
|
+
type: "app_error",
|
|
72
|
+
error: {
|
|
73
|
+
title: title.toString(),
|
|
74
|
+
details: details?.toString(),
|
|
75
|
+
componentName: componentName?.toString(),
|
|
76
|
+
stack: originalError?.stack?.toString(),
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
"*"
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function handleUnhandledRejection(event: any) {
|
|
84
|
+
const stack = event.reason.stack;
|
|
85
|
+
// extract function name from "at X (eval" where x is the function name
|
|
86
|
+
const functionName = stack.match(/at\s+(\w+)\s+\(eval/)?.[1];
|
|
87
|
+
const msg = functionName
|
|
88
|
+
? `Error in ${functionName}: ${event.reason.toString()}`
|
|
89
|
+
: event.reason.toString();
|
|
90
|
+
onAppError({
|
|
91
|
+
title: msg,
|
|
92
|
+
details: event.reason.toString(),
|
|
93
|
+
componentName: functionName,
|
|
94
|
+
originalError: event.reason,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function handleWindowError(event: any) {
|
|
99
|
+
const stack = event.error?.stack;
|
|
100
|
+
let functionName = stack.match(/at\s+(\w+)\s+\(eval/)?.[1];
|
|
101
|
+
if (functionName === "eval") {
|
|
102
|
+
functionName = null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const msg = functionName
|
|
106
|
+
? `in ${functionName}: ${event.error.toString()}`
|
|
107
|
+
: event.error.toString();
|
|
108
|
+
onAppError({
|
|
109
|
+
title: msg,
|
|
110
|
+
details: event.error.toString(),
|
|
111
|
+
componentName: functionName,
|
|
112
|
+
originalError: event.error,
|
|
113
|
+
});
|
|
114
|
+
}
|