@base44-preview/vite-plugin 0.2.22-pr.36.db00ef7 → 0.2.22-pr.37.466ee63
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/injections/utils.d.ts +0 -6
- package/dist/injections/utils.d.ts.map +1 -1
- package/dist/injections/utils.js +0 -25
- package/dist/injections/utils.js.map +1 -1
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.d.ts +25 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.js +78 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/core.js.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.d.ts +4 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.js +4 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/index.js.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.d.ts +9 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.js +26 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/styles.js.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.d.ts +10 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.js +60 -0
- package/dist/injections/visual-edit-agent/capabilities/inline-editing/validation.js.map +1 -0
- package/dist/injections/visual-edit-agent/constants.d.ts +10 -0
- package/dist/injections/visual-edit-agent/constants.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/constants.js +10 -0
- package/dist/injections/visual-edit-agent/constants.js.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/click-handlers.d.ts +10 -0
- package/dist/injections/visual-edit-agent/handlers/click-handlers.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/click-handlers.js +109 -0
- package/dist/injections/visual-edit-agent/handlers/click-handlers.js.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/hover-handlers.d.ts +14 -0
- package/dist/injections/visual-edit-agent/handlers/hover-handlers.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/hover-handlers.js +64 -0
- package/dist/injections/visual-edit-agent/handlers/hover-handlers.js.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.d.ts +14 -0
- package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.js +99 -0
- package/dist/injections/visual-edit-agent/handlers/inline-edit-handlers.js.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/message-handlers.d.ts +26 -0
- package/dist/injections/visual-edit-agent/handlers/message-handlers.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/message-handlers.js +145 -0
- package/dist/injections/visual-edit-agent/handlers/message-handlers.js.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.d.ts +7 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.js +42 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.js.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.d.ts +11 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.js +33 -0
- package/dist/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.js.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/messages/types.d.ts +86 -0
- package/dist/injections/visual-edit-agent/handlers/messages/types.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/handlers/messages/types.js +28 -0
- package/dist/injections/visual-edit-agent/handlers/messages/types.js.map +1 -0
- package/dist/injections/visual-edit-agent/index.d.ts +5 -0
- package/dist/injections/visual-edit-agent/index.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/index.js +100 -0
- package/dist/injections/visual-edit-agent/index.js.map +1 -0
- package/dist/injections/visual-edit-agent/state/agent-state.d.ts +17 -0
- package/dist/injections/visual-edit-agent/state/agent-state.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/state/agent-state.js +18 -0
- package/dist/injections/visual-edit-agent/state/agent-state.js.map +1 -0
- package/dist/injections/visual-edit-agent/ui/overlay.d.ts +26 -0
- package/dist/injections/visual-edit-agent/ui/overlay.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/ui/overlay.js +103 -0
- package/dist/injections/visual-edit-agent/ui/overlay.js.map +1 -0
- package/dist/injections/visual-edit-agent/utils/dom-utils.d.ts +14 -0
- package/dist/injections/visual-edit-agent/utils/dom-utils.d.ts.map +1 -0
- package/dist/injections/visual-edit-agent/utils/dom-utils.js +34 -0
- package/dist/injections/visual-edit-agent/utils/dom-utils.js.map +1 -0
- package/dist/injections/visual-edit-agent.d.ts +1 -1
- package/dist/injections/visual-edit-agent.d.ts.map +1 -1
- package/dist/injections/visual-edit-agent.js +1 -474
- package/dist/injections/visual-edit-agent.js.map +1 -1
- package/dist/statics/index.mjs +5 -1
- package/dist/statics/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/injections/utils.ts +0 -34
- package/src/injections/visual-edit-agent/README.md +222 -0
- package/src/injections/visual-edit-agent/capabilities/inline-editing/core.ts +100 -0
- package/src/injections/visual-edit-agent/capabilities/inline-editing/index.ts +10 -0
- package/src/injections/visual-edit-agent/capabilities/inline-editing/styles.ts +26 -0
- package/src/injections/visual-edit-agent/capabilities/inline-editing/validation.ts +67 -0
- package/src/injections/visual-edit-agent/constants.ts +9 -0
- package/src/injections/visual-edit-agent/handlers/click-handlers.ts +135 -0
- package/src/injections/visual-edit-agent/handlers/hover-handlers.ts +78 -0
- package/src/injections/visual-edit-agent/handlers/inline-edit-handlers.ts +130 -0
- package/src/injections/visual-edit-agent/handlers/message-handlers.ts +191 -0
- package/src/injections/visual-edit-agent/handlers/messages/toggle-inline-edit-mode.ts +51 -0
- package/src/injections/visual-edit-agent/handlers/messages/toggle-visual-edit-mode.ts +41 -0
- package/src/injections/visual-edit-agent/handlers/messages/types.ts +112 -0
- package/src/injections/visual-edit-agent/index.ts +116 -0
- package/src/injections/visual-edit-agent/state/agent-state.ts +31 -0
- package/src/injections/visual-edit-agent/ui/overlay.ts +125 -0
- package/src/injections/visual-edit-agent/utils/dom-utils.ts +39 -0
- package/src/injections/visual-edit-agent.ts +1 -577
- package/dist/injections/layer-dropdown/consts.d.ts +0 -15
- package/dist/injections/layer-dropdown/consts.d.ts.map +0 -1
- package/dist/injections/layer-dropdown/consts.js +0 -36
- package/dist/injections/layer-dropdown/consts.js.map +0 -1
- package/dist/injections/layer-dropdown/controller.d.ts +0 -4
- package/dist/injections/layer-dropdown/controller.d.ts.map +0 -1
- package/dist/injections/layer-dropdown/controller.js +0 -85
- package/dist/injections/layer-dropdown/controller.js.map +0 -1
- package/dist/injections/layer-dropdown/dropdown-ui.d.ts +0 -13
- package/dist/injections/layer-dropdown/dropdown-ui.d.ts.map +0 -1
- package/dist/injections/layer-dropdown/dropdown-ui.js +0 -158
- package/dist/injections/layer-dropdown/dropdown-ui.js.map +0 -1
- package/dist/injections/layer-dropdown/types.d.ts +0 -21
- package/dist/injections/layer-dropdown/types.d.ts.map +0 -1
- package/dist/injections/layer-dropdown/types.js +0 -3
- package/dist/injections/layer-dropdown/types.js.map +0 -1
- package/dist/injections/layer-dropdown/utils.d.ts +0 -23
- package/dist/injections/layer-dropdown/utils.d.ts.map +0 -1
- package/dist/injections/layer-dropdown/utils.js +0 -119
- package/dist/injections/layer-dropdown/utils.js.map +0 -1
- package/src/injections/layer-dropdown/consts.ts +0 -44
- package/src/injections/layer-dropdown/controller.ts +0 -105
- package/src/injections/layer-dropdown/dropdown-ui.ts +0 -221
- package/src/injections/layer-dropdown/types.ts +0 -24
- package/src/injections/layer-dropdown/utils.ts +0 -148
|
@@ -1,221 +0,0 @@
|
|
|
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
|
-
LABEL_CHEVRON,
|
|
12
|
-
LAYER_DROPDOWN_ATTR,
|
|
13
|
-
} from "./consts.js";
|
|
14
|
-
import { applyStyles, getLayerDisplayName } from "./utils.js";
|
|
15
|
-
import type { LayerInfo, OnLayerSelect, OnLayerHover, OnLayerHoverEnd } from "./types.js";
|
|
16
|
-
|
|
17
|
-
let activeDropdown: HTMLDivElement | null = null;
|
|
18
|
-
let outsideMousedownHandler: ((e: MouseEvent) => void) | null = null;
|
|
19
|
-
let activeOnHoverEnd: OnLayerHoverEnd | null = null;
|
|
20
|
-
let activeKeydownHandler: ((e: KeyboardEvent) => void) | null = null;
|
|
21
|
-
|
|
22
|
-
function createDropdownItem(
|
|
23
|
-
layer: LayerInfo,
|
|
24
|
-
isActive: boolean,
|
|
25
|
-
onSelect: OnLayerSelect,
|
|
26
|
-
onHover?: OnLayerHover,
|
|
27
|
-
onHoverEnd?: OnLayerHoverEnd
|
|
28
|
-
): HTMLDivElement {
|
|
29
|
-
const item = document.createElement("div");
|
|
30
|
-
item.textContent = getLayerDisplayName(layer);
|
|
31
|
-
applyStyles(item, DROPDOWN_ITEM_BASE_STYLES);
|
|
32
|
-
|
|
33
|
-
const depth = layer.depth ?? 0;
|
|
34
|
-
if (depth > 0) {
|
|
35
|
-
item.style.paddingLeft = `${12 + depth * DEPTH_INDENT_PX}px`;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (isActive) {
|
|
39
|
-
item.style.color = DROPDOWN_ITEM_ACTIVE_COLOR;
|
|
40
|
-
item.style.backgroundColor = DROPDOWN_ITEM_ACTIVE_BG;
|
|
41
|
-
item.style.fontWeight = DROPDOWN_ITEM_ACTIVE_FONT_WEIGHT;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
item.addEventListener("mouseenter", () => {
|
|
45
|
-
if (!isActive) item.style.backgroundColor = DROPDOWN_ITEM_HOVER_BG;
|
|
46
|
-
if (onHover) onHover(layer);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
item.addEventListener("mouseleave", () => {
|
|
50
|
-
if (!isActive) item.style.backgroundColor = "transparent";
|
|
51
|
-
if (onHoverEnd) onHoverEnd();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
item.addEventListener("click", (e: MouseEvent) => {
|
|
55
|
-
e.stopPropagation();
|
|
56
|
-
e.preventDefault();
|
|
57
|
-
onSelect(layer);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
return item;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/** Create the dropdown DOM element with layer items */
|
|
64
|
-
export function createDropdownElement(
|
|
65
|
-
layers: LayerInfo[],
|
|
66
|
-
currentSelectorId: string | null,
|
|
67
|
-
onSelect: OnLayerSelect,
|
|
68
|
-
onHover?: OnLayerHover,
|
|
69
|
-
onHoverEnd?: OnLayerHoverEnd
|
|
70
|
-
): HTMLDivElement {
|
|
71
|
-
const container = document.createElement("div");
|
|
72
|
-
container.setAttribute(LAYER_DROPDOWN_ATTR, "true");
|
|
73
|
-
applyStyles(container, DROPDOWN_CONTAINER_STYLES);
|
|
74
|
-
|
|
75
|
-
layers.forEach((layer) => {
|
|
76
|
-
const isActive = layer.selectorId === currentSelectorId;
|
|
77
|
-
container.appendChild(createDropdownItem(layer, isActive, onSelect, onHover, onHoverEnd));
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
return container;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** Add chevron indicator and pointer-events to the label */
|
|
84
|
-
export function enhanceLabelWithChevron(label: HTMLDivElement): void {
|
|
85
|
-
if (label.textContent?.includes(LABEL_CHEVRON)) return;
|
|
86
|
-
|
|
87
|
-
label.textContent = label.textContent + LABEL_CHEVRON;
|
|
88
|
-
label.style.cursor = "pointer";
|
|
89
|
-
label.style.userSelect = "none";
|
|
90
|
-
label.style.pointerEvents = "auto";
|
|
91
|
-
label.setAttribute(LAYER_DROPDOWN_ATTR, "true");
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function setupKeyboardNavigation(
|
|
95
|
-
dropdown: HTMLDivElement,
|
|
96
|
-
layers: LayerInfo[],
|
|
97
|
-
currentSelectorId: string | null,
|
|
98
|
-
onSelect: OnLayerSelect,
|
|
99
|
-
onHover?: OnLayerHover,
|
|
100
|
-
onHoverEnd?: OnLayerHoverEnd
|
|
101
|
-
): void {
|
|
102
|
-
const items = Array.from(dropdown.children) as HTMLDivElement[];
|
|
103
|
-
let focusedIndex = layers.findIndex((l) => l.selectorId === currentSelectorId);
|
|
104
|
-
|
|
105
|
-
const setFocusedItem = (index: number) => {
|
|
106
|
-
if (focusedIndex >= 0 && focusedIndex < items.length) {
|
|
107
|
-
const prev = items[focusedIndex]!;
|
|
108
|
-
if (prev.style.color !== DROPDOWN_ITEM_ACTIVE_COLOR) {
|
|
109
|
-
prev.style.backgroundColor = "transparent";
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
focusedIndex = index;
|
|
113
|
-
if (focusedIndex >= 0 && focusedIndex < items.length) {
|
|
114
|
-
const cur = items[focusedIndex]!;
|
|
115
|
-
if (cur.style.color !== DROPDOWN_ITEM_ACTIVE_COLOR) {
|
|
116
|
-
cur.style.backgroundColor = DROPDOWN_ITEM_HOVER_BG;
|
|
117
|
-
}
|
|
118
|
-
cur.scrollIntoView({ block: "nearest" });
|
|
119
|
-
if (onHover) onHover(layers[focusedIndex]!);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
activeKeydownHandler = (e: KeyboardEvent) => {
|
|
124
|
-
if (e.key === "ArrowDown") {
|
|
125
|
-
e.preventDefault();
|
|
126
|
-
e.stopPropagation();
|
|
127
|
-
setFocusedItem(focusedIndex < items.length - 1 ? focusedIndex + 1 : 0);
|
|
128
|
-
} else if (e.key === "ArrowUp") {
|
|
129
|
-
e.preventDefault();
|
|
130
|
-
e.stopPropagation();
|
|
131
|
-
setFocusedItem(focusedIndex > 0 ? focusedIndex - 1 : items.length - 1);
|
|
132
|
-
} else if (e.key === "Enter" && focusedIndex >= 0) {
|
|
133
|
-
e.preventDefault();
|
|
134
|
-
e.stopPropagation();
|
|
135
|
-
if (onHoverEnd) onHoverEnd();
|
|
136
|
-
onSelect(layers[focusedIndex]!);
|
|
137
|
-
closeDropdown();
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
document.addEventListener("keydown", activeKeydownHandler, true);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function setupOutsideClickHandler(
|
|
144
|
-
dropdown: HTMLDivElement,
|
|
145
|
-
label: HTMLDivElement
|
|
146
|
-
): void {
|
|
147
|
-
setTimeout(() => {
|
|
148
|
-
outsideMousedownHandler = (e: MouseEvent) => {
|
|
149
|
-
const target = e.target as Node;
|
|
150
|
-
if (!dropdown.contains(target) && target !== label) {
|
|
151
|
-
closeDropdown();
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
document.addEventListener("mousedown", outsideMousedownHandler, true);
|
|
155
|
-
}, 0);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/** Show the dropdown below the label element */
|
|
159
|
-
export function showDropdown(
|
|
160
|
-
label: HTMLDivElement,
|
|
161
|
-
layers: LayerInfo[],
|
|
162
|
-
currentSelectorId: string | null,
|
|
163
|
-
onSelect: OnLayerSelect,
|
|
164
|
-
onHover?: OnLayerHover,
|
|
165
|
-
onHoverEnd?: OnLayerHoverEnd
|
|
166
|
-
): void {
|
|
167
|
-
closeDropdown();
|
|
168
|
-
|
|
169
|
-
const dropdown = createDropdownElement(
|
|
170
|
-
layers,
|
|
171
|
-
currentSelectorId,
|
|
172
|
-
(layer) => {
|
|
173
|
-
if (onHoverEnd) onHoverEnd();
|
|
174
|
-
onSelect(layer);
|
|
175
|
-
closeDropdown();
|
|
176
|
-
},
|
|
177
|
-
onHover,
|
|
178
|
-
onHoverEnd
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
const overlay = label.parentElement;
|
|
182
|
-
if (!overlay) return;
|
|
183
|
-
|
|
184
|
-
dropdown.style.top = `${label.offsetTop + label.offsetHeight + 2}px`;
|
|
185
|
-
dropdown.style.left = `${label.offsetLeft}px`;
|
|
186
|
-
|
|
187
|
-
overlay.appendChild(dropdown);
|
|
188
|
-
activeDropdown = dropdown;
|
|
189
|
-
activeOnHoverEnd = onHoverEnd ?? null;
|
|
190
|
-
|
|
191
|
-
setupKeyboardNavigation(dropdown, layers, currentSelectorId, onSelect, onHover, onHoverEnd);
|
|
192
|
-
setupOutsideClickHandler(dropdown, label);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/** Close the active dropdown and clean up listeners */
|
|
196
|
-
export function closeDropdown(): void {
|
|
197
|
-
if (activeOnHoverEnd) {
|
|
198
|
-
activeOnHoverEnd();
|
|
199
|
-
activeOnHoverEnd = null;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (activeDropdown && activeDropdown.parentNode) {
|
|
203
|
-
activeDropdown.remove();
|
|
204
|
-
}
|
|
205
|
-
activeDropdown = null;
|
|
206
|
-
|
|
207
|
-
if (outsideMousedownHandler) {
|
|
208
|
-
document.removeEventListener("mousedown", outsideMousedownHandler, true);
|
|
209
|
-
outsideMousedownHandler = null;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (activeKeydownHandler) {
|
|
213
|
-
document.removeEventListener("keydown", activeKeydownHandler, true);
|
|
214
|
-
activeKeydownHandler = null;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/** Check if a dropdown is currently visible */
|
|
219
|
-
export function isDropdownOpen(): boolean {
|
|
220
|
-
return activeDropdown !== null;
|
|
221
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
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 LayerControllerDeps {
|
|
15
|
-
createPreviewOverlay: (element: Element) => HTMLDivElement;
|
|
16
|
-
getSelectedElementId: () => string | null;
|
|
17
|
-
selectElement: (element: Element) => HTMLDivElement | undefined;
|
|
18
|
-
onDeselect: () => void;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface LayerController {
|
|
22
|
-
attachToOverlay: (overlay: HTMLDivElement | undefined, element: Element) => void;
|
|
23
|
-
cleanup: () => void;
|
|
24
|
-
}
|
|
@@ -1,148 +0,0 @@
|
|
|
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
|
-
Object.assign(element.style, styles);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** Display name for a layer — just the real tag name */
|
|
14
|
-
export function getLayerDisplayName(layer: LayerInfo): string {
|
|
15
|
-
return layer.tagName;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Collect instrumented descendants up to `maxDepth` instrumented nesting levels.
|
|
20
|
-
* Non-instrumented wrappers are walked through without counting toward depth.
|
|
21
|
-
* Results are in DOM order.
|
|
22
|
-
*/
|
|
23
|
-
export function getInstrumentedDescendants(
|
|
24
|
-
parent: Element,
|
|
25
|
-
maxDepth: number
|
|
26
|
-
): LayerInfo[] {
|
|
27
|
-
const result: LayerInfo[] = [];
|
|
28
|
-
|
|
29
|
-
function walk(el: Element, instrDepth: number): void {
|
|
30
|
-
if (instrDepth > maxDepth) return;
|
|
31
|
-
for (let i = 0; i < el.children.length; i++) {
|
|
32
|
-
const child = el.children[i]!;
|
|
33
|
-
if (isInstrumentedElement(child)) {
|
|
34
|
-
result.push({
|
|
35
|
-
element: child,
|
|
36
|
-
tagName: child.tagName.toLowerCase(),
|
|
37
|
-
selectorId: getElementSelectorId(child),
|
|
38
|
-
});
|
|
39
|
-
walk(child, instrDepth + 1);
|
|
40
|
-
} else {
|
|
41
|
-
walk(child, instrDepth);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
walk(parent, 1);
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function toLayerInfo(element: Element, depth?: number): LayerInfo {
|
|
51
|
-
const info: LayerInfo = {
|
|
52
|
-
element,
|
|
53
|
-
tagName: element.tagName.toLowerCase(),
|
|
54
|
-
selectorId: getElementSelectorId(element),
|
|
55
|
-
};
|
|
56
|
-
if (depth !== undefined) info.depth = depth;
|
|
57
|
-
return info;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Collect instrumented ancestors from selected element up to MAX_PARENT_DEPTH (outermost first). */
|
|
61
|
-
function collectInstrumentedParents(selectedElement: Element): LayerInfo[] {
|
|
62
|
-
const parents: LayerInfo[] = [];
|
|
63
|
-
let current = selectedElement.parentElement;
|
|
64
|
-
while (
|
|
65
|
-
current &&
|
|
66
|
-
current !== document.documentElement &&
|
|
67
|
-
current !== document.body &&
|
|
68
|
-
parents.length < MAX_PARENT_DEPTH
|
|
69
|
-
) {
|
|
70
|
-
if (isInstrumentedElement(current)) {
|
|
71
|
-
parents.push(toLayerInfo(current));
|
|
72
|
-
}
|
|
73
|
-
current = current.parentElement;
|
|
74
|
-
}
|
|
75
|
-
parents.reverse();
|
|
76
|
-
return parents;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** Append parents to chain with depth 0, 1, …; returns depth of selected (parents.length). */
|
|
80
|
-
function appendParentsWithDepth(chain: LayerInfo[], parents: LayerInfo[]): number {
|
|
81
|
-
parents.forEach((p, i) => {
|
|
82
|
-
chain.push({ ...p, depth: i });
|
|
83
|
-
});
|
|
84
|
-
return parents.length;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/** Append selected element and its descendants at the given depth. */
|
|
88
|
-
function appendSelfAndDescendants(
|
|
89
|
-
chain: LayerInfo[],
|
|
90
|
-
selectedElement: Element,
|
|
91
|
-
selfDepth: number
|
|
92
|
-
): void {
|
|
93
|
-
chain.push(toLayerInfo(selectedElement, selfDepth));
|
|
94
|
-
const descendants = getInstrumentedDescendants(
|
|
95
|
-
selectedElement,
|
|
96
|
-
MAX_CHILD_DEPTH
|
|
97
|
-
);
|
|
98
|
-
assignDescendantDepths(selectedElement, descendants, selfDepth + 1);
|
|
99
|
-
chain.push(...descendants);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Build the layer chain for the dropdown:
|
|
104
|
-
*
|
|
105
|
-
* Parents – up to MAX_PARENT_DEPTH instrumented ancestors, outer → inner.
|
|
106
|
-
* Current – the selected element.
|
|
107
|
-
* Children – instrumented descendants within MAX_CHILD_DEPTH levels, DOM order.
|
|
108
|
-
*
|
|
109
|
-
* Each item carries a `depth` for visual indentation.
|
|
110
|
-
*/
|
|
111
|
-
export function buildLayerChain(selectedElement: Element): LayerInfo[] {
|
|
112
|
-
const parents = collectInstrumentedParents(selectedElement);
|
|
113
|
-
const chain: LayerInfo[] = [];
|
|
114
|
-
const selfDepth = appendParentsWithDepth(chain, parents);
|
|
115
|
-
|
|
116
|
-
appendSelfAndDescendants(chain, selectedElement, selfDepth);
|
|
117
|
-
|
|
118
|
-
return chain;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Walk the DOM tree again to assign correct visual depth to each descendant.
|
|
123
|
-
* This avoids storing depth during collection and keeps the API simple.
|
|
124
|
-
*/
|
|
125
|
-
function assignDescendantDepths(
|
|
126
|
-
root: Element,
|
|
127
|
-
descendants: LayerInfo[],
|
|
128
|
-
startDepth: number
|
|
129
|
-
): void {
|
|
130
|
-
// Build a set for O(1) lookup
|
|
131
|
-
const descSet = new Set(descendants.map((d) => d.element));
|
|
132
|
-
// Map element → LayerInfo for mutation
|
|
133
|
-
const descMap = new Map(descendants.map((d) => [d.element, d]));
|
|
134
|
-
|
|
135
|
-
function walk(el: Element, instrDepth: number): void {
|
|
136
|
-
for (let i = 0; i < el.children.length; i++) {
|
|
137
|
-
const child = el.children[i]!;
|
|
138
|
-
if (descSet.has(child)) {
|
|
139
|
-
descMap.get(child)!.depth = startDepth + instrDepth - 1;
|
|
140
|
-
walk(child, instrDepth + 1);
|
|
141
|
-
} else {
|
|
142
|
-
walk(child, instrDepth);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
walk(root, 1);
|
|
148
|
-
}
|