@focus-reactive/payload-plugin-visual-editing 1.0.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 +264 -0
- package/dist/admin/VisualEditingBridgeProvider.d.ts +4 -0
- package/dist/admin/VisualEditingBridgeProvider.js +144 -0
- package/dist/admin/VisualEditingBridgeProvider.js.map +1 -0
- package/dist/admin/expandAndFocus.d.ts +6 -0
- package/dist/admin/expandAndFocus.js +356 -0
- package/dist/admin/expandAndFocus.js.map +1 -0
- package/dist/admin/index.d.ts +1 -0
- package/dist/admin/index.js +3 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/admin/parseFieldPath.d.ts +4 -0
- package/dist/admin/parseFieldPath.js +25 -0
- package/dist/admin/parseFieldPath.js.map +1 -0
- package/dist/admin/resolveContainerChain.d.ts +30 -0
- package/dist/admin/resolveContainerChain.js +171 -0
- package/dist/admin/resolveContainerChain.js.map +1 -0
- package/dist/client/VisualEditingOverlay.d.ts +4 -0
- package/dist/client/VisualEditingOverlay.js +30 -0
- package/dist/client/VisualEditingOverlay.js.map +1 -0
- package/dist/client/VisualEditingProvider.d.ts +23 -0
- package/dist/client/VisualEditingProvider.js +68 -0
- package/dist/client/VisualEditingProvider.js.map +1 -0
- package/dist/client/VisualEditingToggle.d.ts +1 -0
- package/dist/client/VisualEditingToggle.js +163 -0
- package/dist/client/VisualEditingToggle.js.map +1 -0
- package/dist/client/buildAdminEditUrl.d.ts +7 -0
- package/dist/client/buildAdminEditUrl.js +9 -0
- package/dist/client/buildAdminEditUrl.js.map +1 -0
- package/dist/client/index.d.ts +11 -0
- package/dist/client/index.js +13 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/overlay/constants.d.ts +9 -0
- package/dist/client/overlay/constants.js +49 -0
- package/dist/client/overlay/constants.js.map +1 -0
- package/dist/client/overlay/createOverlay.d.ts +11 -0
- package/dist/client/overlay/createOverlay.js +80 -0
- package/dist/client/overlay/createOverlay.js.map +1 -0
- package/dist/client/overlay/editBadge.d.ts +21 -0
- package/dist/client/overlay/editBadge.js +99 -0
- package/dist/client/overlay/editBadge.js.map +1 -0
- package/dist/client/overlay/hoverController.d.ts +14 -0
- package/dist/client/overlay/hoverController.js +137 -0
- package/dist/client/overlay/hoverController.js.map +1 -0
- package/dist/client/overlay/markerExtractor.d.ts +8 -0
- package/dist/client/overlay/markerExtractor.js +47 -0
- package/dist/client/overlay/markerExtractor.js.map +1 -0
- package/dist/client/overlay/mutationPipeline.d.ts +10 -0
- package/dist/client/overlay/mutationPipeline.js +78 -0
- package/dist/client/overlay/mutationPipeline.js.map +1 -0
- package/dist/client/overlay/stegaBookkeeper.d.ts +11 -0
- package/dist/client/overlay/stegaBookkeeper.js +36 -0
- package/dist/client/overlay/stegaBookkeeper.js.map +1 -0
- package/dist/client/overlay/stegaScanner.d.ts +11 -0
- package/dist/client/overlay/stegaScanner.js +54 -0
- package/dist/client/overlay/stegaScanner.js.map +1 -0
- package/dist/client/overlay/targetRegistry.d.ts +34 -0
- package/dist/client/overlay/targetRegistry.js +70 -0
- package/dist/client/overlay/targetRegistry.js.map +1 -0
- package/dist/client/overlay/targetSelector.d.ts +2 -0
- package/dist/client/overlay/targetSelector.js +67 -0
- package/dist/client/overlay/targetSelector.js.map +1 -0
- package/dist/client/overlayClickHandler.d.ts +7 -0
- package/dist/client/overlayClickHandler.js +24 -0
- package/dist/client/overlayClickHandler.js.map +1 -0
- package/dist/client/useVisualEditingOverlay.d.ts +4 -0
- package/dist/client/useVisualEditingOverlay.js +21 -0
- package/dist/client/useVisualEditingOverlay.js.map +1 -0
- package/dist/client/withVisualEditingPath.d.ts +9 -0
- package/dist/client/withVisualEditingPath.js +17 -0
- package/dist/client/withVisualEditingPath.js.map +1 -0
- package/dist/constants.d.ts +16 -0
- package/dist/constants.js +15 -0
- package/dist/constants.js.map +1 -0
- package/dist/excludeValues.d.ts +6 -0
- package/dist/excludeValues.js +24 -0
- package/dist/excludeValues.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +107 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/afterOperationHook.d.ts +10 -0
- package/dist/internal/afterOperationHook.js +28 -0
- package/dist/internal/afterOperationHook.js.map +1 -0
- package/dist/internal/afterReadHook.d.ts +2 -0
- package/dist/internal/afterReadHook.js +16 -0
- package/dist/internal/afterReadHook.js.map +1 -0
- package/dist/internal/beforeOperationHook.d.ts +4 -0
- package/dist/internal/beforeOperationHook.js +16 -0
- package/dist/internal/beforeOperationHook.js.map +1 -0
- package/dist/internal/buildFieldSchema.d.ts +3 -0
- package/dist/internal/buildFieldSchema.js +67 -0
- package/dist/internal/buildFieldSchema.js.map +1 -0
- package/dist/internal/encodeStega.d.ts +7 -0
- package/dist/internal/encodeStega.js +171 -0
- package/dist/internal/encodeStega.js.map +1 -0
- package/dist/internal/enrichWithPathMeta.d.ts +4 -0
- package/dist/internal/enrichWithPathMeta.js +76 -0
- package/dist/internal/enrichWithPathMeta.js.map +1 -0
- package/dist/internal/filterEditableFields.d.ts +2 -0
- package/dist/internal/filterEditableFields.js +88 -0
- package/dist/internal/filterEditableFields.js.map +1 -0
- package/dist/internal/gate.d.ts +2 -0
- package/dist/internal/gate.js +15 -0
- package/dist/internal/gate.js.map +1 -0
- package/dist/internal/globalAfterReadHook.d.ts +10 -0
- package/dist/internal/globalAfterReadHook.js +19 -0
- package/dist/internal/globalAfterReadHook.js.map +1 -0
- package/dist/internal/markTerminalUploads.d.ts +13 -0
- package/dist/internal/markTerminalUploads.js +79 -0
- package/dist/internal/markTerminalUploads.js.map +1 -0
- package/dist/internal/schemaCache.d.ts +10 -0
- package/dist/internal/schemaCache.js +29 -0
- package/dist/internal/schemaCache.js.map +1 -0
- package/dist/internal/shared.d.ts +32 -0
- package/dist/internal/shared.js +55 -0
- package/dist/internal/shared.js.map +1 -0
- package/dist/internal/stripStegaHook.d.ts +2 -0
- package/dist/internal/stripStegaHook.js +29 -0
- package/dist/internal/stripStegaHook.js.map +1 -0
- package/package.json +105 -0
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
const FOCUS_SELECTOR = '[data-lexical-editor="true"], input:not([type="hidden"]), textarea';
|
|
2
|
+
const SWEEP_STYLE_ID = "ve-sweep-styles";
|
|
3
|
+
const POLL_INTERVAL_MS = 60;
|
|
4
|
+
const STEP_BUDGET_MS = 1500;
|
|
5
|
+
const POST_SCROLL_DELAY_MS = 500;
|
|
6
|
+
const REVEAL_TOTAL_MS = 1800;
|
|
7
|
+
// Focus-reveal accent. HSL so alpha variants share a stable hue/sat/lightness
|
|
8
|
+
// — swap the three numbers to re-theme the whole reveal (ring, corners, sweep,
|
|
9
|
+
// reduced-motion fallback) in one place.
|
|
10
|
+
// Current: electric cyan (≈ #22d3ee).
|
|
11
|
+
const FOCUS_HSL = {
|
|
12
|
+
h: 189,
|
|
13
|
+
s: 85,
|
|
14
|
+
l: 53
|
|
15
|
+
};
|
|
16
|
+
const focusColor = (alpha)=>`hsla(${FOCUS_HSL.h}, ${FOCUS_HSL.s}%, ${FOCUS_HSL.l}%, ${alpha})`;
|
|
17
|
+
const ensureSweepStyles = ()=>{
|
|
18
|
+
// oxlint-disable-next-line unicorn/prefer-query-selector -- ids are not guaranteed to be valid CSS selectors
|
|
19
|
+
if (document.getElementById(SWEEP_STYLE_ID)) return;
|
|
20
|
+
const style = document.createElement("style");
|
|
21
|
+
style.id = SWEEP_STYLE_ID;
|
|
22
|
+
// Viewport-fixed ornament anchored to the field's bounding rect via RAF. Not
|
|
23
|
+
// injected into the field's subtree: adding `position: relative; overflow: hidden`
|
|
24
|
+
// to arbitrary Payload field wrappers breaks Lexical's sticky toolbar positioning.
|
|
25
|
+
// Layers: corner brackets (reticle), ring (pulsing border + glow halo), sweep (gradient pass).
|
|
26
|
+
style.textContent = `
|
|
27
|
+
@keyframes ve-focus-corner-in {
|
|
28
|
+
0% { transform: scale(1.35); opacity: 0; }
|
|
29
|
+
60% { opacity: 1; }
|
|
30
|
+
100% { transform: scale(1); opacity: 1; }
|
|
31
|
+
}
|
|
32
|
+
@keyframes ve-focus-ring-pulse {
|
|
33
|
+
0% { box-shadow: 0 0 0 0 ${focusColor(0.55)}, 0 0 0 0 ${focusColor(0.22)}; border-color: ${focusColor(0.95)}; }
|
|
34
|
+
50% { box-shadow: 0 0 0 4px ${focusColor(0.3)}, 0 0 0 14px ${focusColor(0.06)}; border-color: ${focusColor(0.95)}; }
|
|
35
|
+
100% { box-shadow: 0 0 0 0 ${focusColor(0)}, 0 0 0 0 ${focusColor(0)}; border-color: ${focusColor(0)}; }
|
|
36
|
+
}
|
|
37
|
+
@keyframes ve-focus-sweep {
|
|
38
|
+
0% { transform: translateY(-100%); opacity: 0; }
|
|
39
|
+
18% { opacity: 1; }
|
|
40
|
+
100% { transform: translateY(100%); opacity: 0; }
|
|
41
|
+
}
|
|
42
|
+
@keyframes ve-focus-fadeout {
|
|
43
|
+
to { opacity: 0; }
|
|
44
|
+
}
|
|
45
|
+
.ve-sweep-wrap {
|
|
46
|
+
pointer-events: none;
|
|
47
|
+
position: fixed;
|
|
48
|
+
z-index: 9999;
|
|
49
|
+
}
|
|
50
|
+
.ve-sweep-ring {
|
|
51
|
+
position: absolute;
|
|
52
|
+
inset: -2px;
|
|
53
|
+
border: 2px solid transparent;
|
|
54
|
+
border-radius: 6px;
|
|
55
|
+
animation: ve-focus-ring-pulse 0.7s cubic-bezier(0.4, 0, 0.2, 1) 120ms 2 forwards;
|
|
56
|
+
}
|
|
57
|
+
.ve-sweep-corner {
|
|
58
|
+
position: absolute;
|
|
59
|
+
width: 14px;
|
|
60
|
+
height: 14px;
|
|
61
|
+
border-color: ${focusColor(0.95)};
|
|
62
|
+
border-style: solid;
|
|
63
|
+
border-width: 0;
|
|
64
|
+
animation:
|
|
65
|
+
ve-focus-corner-in 260ms cubic-bezier(0.2, 0.8, 0.2, 1) 0ms both,
|
|
66
|
+
ve-focus-fadeout 300ms ease 1400ms forwards;
|
|
67
|
+
}
|
|
68
|
+
.ve-sweep-corner.tl { top: -4px; left: -4px; border-width: 2px 0 0 2px; border-top-left-radius: 4px; }
|
|
69
|
+
.ve-sweep-corner.tr { top: -4px; right: -4px; border-width: 2px 2px 0 0; border-top-right-radius: 4px; }
|
|
70
|
+
.ve-sweep-corner.bl { bottom: -4px; left: -4px; border-width: 0 0 2px 2px; border-bottom-left-radius: 4px; }
|
|
71
|
+
.ve-sweep-corner.br { bottom: -4px; right: -4px; border-width: 0 2px 2px 0; border-bottom-right-radius: 4px; }
|
|
72
|
+
.ve-sweep-clip {
|
|
73
|
+
position: absolute;
|
|
74
|
+
inset: 0;
|
|
75
|
+
overflow: hidden;
|
|
76
|
+
border-radius: 4px;
|
|
77
|
+
}
|
|
78
|
+
.ve-sweep-overlay {
|
|
79
|
+
position: absolute;
|
|
80
|
+
inset: 0;
|
|
81
|
+
background: linear-gradient(
|
|
82
|
+
to bottom,
|
|
83
|
+
transparent 0%,
|
|
84
|
+
${focusColor(0.06)} 22%,
|
|
85
|
+
${focusColor(0.22)} 50%,
|
|
86
|
+
${focusColor(0.06)} 78%,
|
|
87
|
+
transparent 100%
|
|
88
|
+
);
|
|
89
|
+
animation: ve-focus-sweep 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
|
|
90
|
+
}
|
|
91
|
+
@media (prefers-reduced-motion: reduce) {
|
|
92
|
+
.ve-sweep-ring { animation: none; border-color: ${focusColor(0.9)}; box-shadow: 0 0 0 2px ${focusColor(0.22)}, 0 0 0 6px ${focusColor(0.08)}; }
|
|
93
|
+
.ve-sweep-corner { animation: ve-focus-fadeout 300ms ease 1400ms forwards; }
|
|
94
|
+
.ve-sweep-overlay { animation: none; opacity: 0; }
|
|
95
|
+
}
|
|
96
|
+
`;
|
|
97
|
+
document.head.append(style);
|
|
98
|
+
};
|
|
99
|
+
const SWEEP_DECORATION_PAD = 24;
|
|
100
|
+
export const playSweep = (el)=>{
|
|
101
|
+
ensureSweepStyles();
|
|
102
|
+
const wrap = document.createElement("div");
|
|
103
|
+
wrap.className = "ve-sweep-wrap";
|
|
104
|
+
const docHeader = document.querySelector(".doc-controls");
|
|
105
|
+
const ring = document.createElement("div");
|
|
106
|
+
ring.className = "ve-sweep-ring";
|
|
107
|
+
const corners = [
|
|
108
|
+
"tl",
|
|
109
|
+
"tr",
|
|
110
|
+
"bl",
|
|
111
|
+
"br"
|
|
112
|
+
].map((pos)=>{
|
|
113
|
+
const corner = document.createElement("div");
|
|
114
|
+
corner.className = `ve-sweep-corner ${pos}`;
|
|
115
|
+
return corner;
|
|
116
|
+
});
|
|
117
|
+
const clip = document.createElement("div");
|
|
118
|
+
clip.className = "ve-sweep-clip";
|
|
119
|
+
const overlay = document.createElement("div");
|
|
120
|
+
overlay.className = "ve-sweep-overlay";
|
|
121
|
+
clip.append(overlay);
|
|
122
|
+
wrap.append(ring, ...corners, clip);
|
|
123
|
+
document.body.append(wrap);
|
|
124
|
+
// Track the field's current rect for the full reveal. If the browser's smooth-scroll
|
|
125
|
+
// is still running when the reveal starts, or the layout shifts mid-animation, the
|
|
126
|
+
// wrap stays anchored to the field instead of drifting off.
|
|
127
|
+
let rafId = 0;
|
|
128
|
+
const pad = SWEEP_DECORATION_PAD;
|
|
129
|
+
const track = ()=>{
|
|
130
|
+
const rect = el.getBoundingClientRect();
|
|
131
|
+
wrap.style.top = `${rect.top}px`;
|
|
132
|
+
wrap.style.left = `${rect.left}px`;
|
|
133
|
+
wrap.style.width = `${rect.width}px`;
|
|
134
|
+
wrap.style.height = `${rect.height}px`;
|
|
135
|
+
const headerBottom = docHeader?.getBoundingClientRect().bottom ?? 0;
|
|
136
|
+
const topClip = Math.max(headerBottom - rect.top, -pad);
|
|
137
|
+
wrap.style.clipPath = `polygon(${-pad}px ${topClip}px, calc(100% + ${pad}px) ${topClip}px, calc(100% + ${pad}px) calc(100% + ${pad}px), ${-pad}px calc(100% + ${pad}px))`;
|
|
138
|
+
rafId = requestAnimationFrame(track);
|
|
139
|
+
};
|
|
140
|
+
track();
|
|
141
|
+
setTimeout(()=>{
|
|
142
|
+
cancelAnimationFrame(rafId);
|
|
143
|
+
wrap.remove();
|
|
144
|
+
}, REVEAL_TOTAL_MS);
|
|
145
|
+
};
|
|
146
|
+
// Lexical rich-text wrappers don't carry the `field-<path>` id — only a
|
|
147
|
+
// `<label htmlFor="field-<path>">` pointing inside. Everything else Payload
|
|
148
|
+
// renders exposes the id on an element (input, select, textarea, group wrapper).
|
|
149
|
+
export const findFieldElement = (fieldId)=>{
|
|
150
|
+
// oxlint-disable-next-line unicorn/prefer-query-selector -- ids are not guaranteed to be valid CSS selectors
|
|
151
|
+
const direct = document.getElementById(fieldId);
|
|
152
|
+
if (direct) return direct;
|
|
153
|
+
const label = document.querySelector(`label[for="${fieldId}"]`);
|
|
154
|
+
const wrapper = label?.closest(".field-type");
|
|
155
|
+
return wrapper ?? null;
|
|
156
|
+
};
|
|
157
|
+
// Payload lazily renders groups that are below the viewport — their inner fields
|
|
158
|
+
// (including the `*-row-<n>` containers the `row` instruction waits on) don't
|
|
159
|
+
// exist in the DOM until the group is scrolled near. Before waiting, walk up
|
|
160
|
+
// the path and scroll the deepest already-mounted ancestor into view so the
|
|
161
|
+
// virtualized subtree hydrates. Safe to call repeatedly; does nothing when the
|
|
162
|
+
// full field id is already present.
|
|
163
|
+
export const scrollNearestAncestorIntoView = (fieldId)=>{
|
|
164
|
+
if (!fieldId.startsWith("field-")) return;
|
|
165
|
+
const segments = fieldId.slice("field-".length).split("__");
|
|
166
|
+
for(let i = segments.length; i > 0; i--){
|
|
167
|
+
// oxlint-disable-next-line unicorn/prefer-query-selector -- ids are not guaranteed to be valid CSS selectors
|
|
168
|
+
const el = document.getElementById(`field-${segments.slice(0, i).join("__")}`);
|
|
169
|
+
if (el && typeof el.scrollIntoView === "function") {
|
|
170
|
+
el.scrollIntoView({
|
|
171
|
+
behavior: "auto",
|
|
172
|
+
block: "center"
|
|
173
|
+
});
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
const waitFor = (predicate, budgetMs)=>{
|
|
179
|
+
return new Promise((resolve)=>{
|
|
180
|
+
const deadline = Date.now() + budgetMs;
|
|
181
|
+
const tick = ()=>{
|
|
182
|
+
if (predicate()) return resolve(true);
|
|
183
|
+
if (Date.now() >= deadline) return resolve(false);
|
|
184
|
+
setTimeout(tick, POLL_INTERVAL_MS);
|
|
185
|
+
};
|
|
186
|
+
tick();
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
// Payload's Collapsible uses its `path` as the id suffix — see
|
|
190
|
+
// @payloadcms/ui/dist/fields/Collapsible/index.js:52.
|
|
191
|
+
const collapsibleDomId = (path)=>`field-collapsible-${path.replace(/\./g, "__")}`;
|
|
192
|
+
// Tab buttons can exist at multiple nesting levels (top-level tabs, plus any
|
|
193
|
+
// nested tabs fields inside blocks). A raw `querySelectorAll` at document scope
|
|
194
|
+
// would match all of them, and `buttons[instruction.tabIndex]` would pick the
|
|
195
|
+
// wrong one for any chain step past the top level. The executor narrows the
|
|
196
|
+
// search scope as it descends — each row instruction sets the next scope to
|
|
197
|
+
// the row's container so subsequent tab/collapsible lookups stay inside it.
|
|
198
|
+
const runInstruction = async (instruction, scope)=>{
|
|
199
|
+
switch(instruction.kind){
|
|
200
|
+
case "tab":
|
|
201
|
+
{
|
|
202
|
+
const getButton = ()=>{
|
|
203
|
+
const buttons = scope.querySelectorAll(".tabs-field__tab-button");
|
|
204
|
+
return buttons[instruction.tabIndex] ?? null;
|
|
205
|
+
};
|
|
206
|
+
const isActive = ()=>getButton()?.classList.contains("tabs-field__tab-button--active") ?? false;
|
|
207
|
+
const ready = await waitFor(()=>getButton() !== null, STEP_BUDGET_MS);
|
|
208
|
+
if (!ready) return {
|
|
209
|
+
ok: false,
|
|
210
|
+
nextScope: scope
|
|
211
|
+
};
|
|
212
|
+
if (!isActive()) getButton().click();
|
|
213
|
+
const activated = await waitFor(isActive, STEP_BUDGET_MS);
|
|
214
|
+
return {
|
|
215
|
+
ok: activated,
|
|
216
|
+
nextScope: scope
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
case "collapsible":
|
|
220
|
+
{
|
|
221
|
+
// Collapsible ids are globally unique in the DOM — resolve at document scope.
|
|
222
|
+
const id = collapsibleDomId(instruction.path);
|
|
223
|
+
// oxlint-disable-next-line unicorn/prefer-query-selector -- ids are not guaranteed to be valid CSS selectors
|
|
224
|
+
const ready = await waitFor(()=>document.getElementById(id) !== null, STEP_BUDGET_MS);
|
|
225
|
+
if (!ready) return {
|
|
226
|
+
ok: false,
|
|
227
|
+
nextScope: scope
|
|
228
|
+
};
|
|
229
|
+
// oxlint-disable-next-line unicorn/prefer-query-selector -- ids are not guaranteed to be valid CSS selectors
|
|
230
|
+
const wrapper = document.getElementById(id);
|
|
231
|
+
const toggle = wrapper.querySelector(".collapsible__toggle");
|
|
232
|
+
if (!toggle) return {
|
|
233
|
+
ok: true,
|
|
234
|
+
nextScope: wrapper
|
|
235
|
+
};
|
|
236
|
+
if (toggle.classList.contains("collapsible__toggle--collapsed")) {
|
|
237
|
+
toggle.click();
|
|
238
|
+
const opened = await waitFor(()=>!toggle.classList.contains("collapsible__toggle--collapsed"), STEP_BUDGET_MS);
|
|
239
|
+
return {
|
|
240
|
+
ok: opened,
|
|
241
|
+
nextScope: wrapper
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
ok: true,
|
|
246
|
+
nextScope: wrapper
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
case "row":
|
|
250
|
+
{
|
|
251
|
+
// `rowContainerId` mirrors the path shape (`a-b-c-row-<n>`). Derive the
|
|
252
|
+
// parent array's field id and scroll it into view to force Payload to
|
|
253
|
+
// hydrate the virtualized rows before we wait for the row container.
|
|
254
|
+
const parentArrayFieldId = `field-${instruction.rowContainerId.replace(/-row-\d+$/, "").replace(/-/g, "__")}`;
|
|
255
|
+
scrollNearestAncestorIntoView(parentArrayFieldId);
|
|
256
|
+
const ready = await waitFor(// oxlint-disable-next-line unicorn/prefer-query-selector -- ids are not guaranteed to be valid CSS selectors
|
|
257
|
+
()=>document.getElementById(instruction.rowContainerId) !== null, STEP_BUDGET_MS);
|
|
258
|
+
if (!ready) return {
|
|
259
|
+
ok: false,
|
|
260
|
+
nextScope: scope
|
|
261
|
+
};
|
|
262
|
+
// oxlint-disable-next-line unicorn/prefer-query-selector -- ids are not guaranteed to be valid CSS selectors
|
|
263
|
+
const row = document.getElementById(instruction.rowContainerId);
|
|
264
|
+
const toggle = row.querySelector(".collapsible__toggle");
|
|
265
|
+
if (!toggle) return {
|
|
266
|
+
ok: true,
|
|
267
|
+
nextScope: row
|
|
268
|
+
};
|
|
269
|
+
if (toggle.classList.contains("collapsible__toggle--collapsed")) {
|
|
270
|
+
toggle.click();
|
|
271
|
+
const opened = await waitFor(()=>!toggle.classList.contains("collapsible__toggle--collapsed"), STEP_BUDGET_MS);
|
|
272
|
+
return {
|
|
273
|
+
ok: opened,
|
|
274
|
+
nextScope: row
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
return {
|
|
278
|
+
ok: true,
|
|
279
|
+
nextScope: row
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
export const applyContainerChain = async (chain)=>{
|
|
285
|
+
let scope = document;
|
|
286
|
+
for (const instruction of chain){
|
|
287
|
+
const result = await runInstruction(instruction, scope);
|
|
288
|
+
if (!result.ok) return false;
|
|
289
|
+
scope = result.nextScope;
|
|
290
|
+
}
|
|
291
|
+
return true;
|
|
292
|
+
};
|
|
293
|
+
// `scrollIntoView({block: 'center'})` beats a precomputed `scrollBy` delta here:
|
|
294
|
+
// the browser tracks the element's live rect across the smooth-scroll animation,
|
|
295
|
+
// so virtualized fields hydrating mid-scroll (RenderIfInViewport firing as we
|
|
296
|
+
// pass its rootMargin) can't leave us off-target. `.focus({preventScroll: true})`
|
|
297
|
+
// suppresses the browser's default "scroll focusable into nearest view" that
|
|
298
|
+
// would otherwise race our centering call. After POST_SCROLL_DELAY_MS the
|
|
299
|
+
// initial scroll should be settled — if additional virtualization shifted the
|
|
300
|
+
// field out of view we re-center once more.
|
|
301
|
+
const focusAndSweep = (fieldEl)=>{
|
|
302
|
+
if (typeof fieldEl.scrollIntoView === "function") {
|
|
303
|
+
fieldEl.scrollIntoView({
|
|
304
|
+
behavior: "smooth",
|
|
305
|
+
block: "center"
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
setTimeout(()=>{
|
|
309
|
+
let sweepTarget = fieldEl;
|
|
310
|
+
if (fieldEl.matches(FOCUS_SELECTOR)) {
|
|
311
|
+
fieldEl.focus({
|
|
312
|
+
preventScroll: true
|
|
313
|
+
});
|
|
314
|
+
const wrapper = fieldEl.closest(".field-type");
|
|
315
|
+
if (wrapper) sweepTarget = wrapper;
|
|
316
|
+
} else {
|
|
317
|
+
const focusable = fieldEl.querySelector(FOCUS_SELECTOR);
|
|
318
|
+
focusable?.focus({
|
|
319
|
+
preventScroll: true
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
if (typeof fieldEl.scrollIntoView === "function") {
|
|
323
|
+
const rect = fieldEl.getBoundingClientRect();
|
|
324
|
+
const viewportHeight = window.innerHeight;
|
|
325
|
+
// Re-center only when the field is outside the viewport — don't
|
|
326
|
+
// re-scroll a centered field whose intrinsic height exceeds the
|
|
327
|
+
// viewport (rect.top < 0 AND rect.bottom > viewportHeight is the
|
|
328
|
+
// correctly-centered state for tall fields).
|
|
329
|
+
const outOfView = rect.bottom <= 0 || rect.top >= viewportHeight;
|
|
330
|
+
if (outOfView) {
|
|
331
|
+
fieldEl.scrollIntoView({
|
|
332
|
+
behavior: "smooth",
|
|
333
|
+
block: "center"
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
playSweep(sweepTarget);
|
|
338
|
+
}, POST_SCROLL_DELAY_MS);
|
|
339
|
+
};
|
|
340
|
+
// Soft-fails on each step: if a chain step times out we still attempt the
|
|
341
|
+
// scroll/focus so the user lands near the target (chain partially works,
|
|
342
|
+
// field visible via ancestor scroll).
|
|
343
|
+
export const expandAndFocus = async (chain, fieldId)=>{
|
|
344
|
+
await applyContainerChain(chain);
|
|
345
|
+
if (!fieldId) return;
|
|
346
|
+
// After the chain opens the tab/collapsible, the target may still live inside
|
|
347
|
+
// a virtualized group — kick off a scroll to the nearest existing ancestor
|
|
348
|
+
// before polling so Payload hydrates the subtree.
|
|
349
|
+
scrollNearestAncestorIntoView(fieldId);
|
|
350
|
+
const ready = await waitFor(()=>findFieldElement(fieldId) !== null, STEP_BUDGET_MS);
|
|
351
|
+
if (!ready) return;
|
|
352
|
+
const fieldEl = findFieldElement(fieldId);
|
|
353
|
+
if (fieldEl) focusAndSweep(fieldEl);
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
//# sourceMappingURL=expandAndFocus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/admin/expandAndFocus.ts"],"sourcesContent":["import type { ContainerInstruction } from \"./resolveContainerChain.js\";\n\nconst FOCUS_SELECTOR = '[data-lexical-editor=\"true\"], input:not([type=\"hidden\"]), textarea';\n\nconst SWEEP_STYLE_ID = \"ve-sweep-styles\";\nconst POLL_INTERVAL_MS = 60;\nconst STEP_BUDGET_MS = 1500;\nconst POST_SCROLL_DELAY_MS = 500;\n\nconst REVEAL_TOTAL_MS = 1800;\n\n// Focus-reveal accent. HSL so alpha variants share a stable hue/sat/lightness\n// — swap the three numbers to re-theme the whole reveal (ring, corners, sweep,\n// reduced-motion fallback) in one place.\n// Current: electric cyan (≈ #22d3ee).\nconst FOCUS_HSL = { h: 189, s: 85, l: 53 } as const;\nconst focusColor = (alpha: number): string =>\n `hsla(${FOCUS_HSL.h}, ${FOCUS_HSL.s}%, ${FOCUS_HSL.l}%, ${alpha})`;\n\nconst ensureSweepStyles = (): void => {\n // oxlint-disable-next-line unicorn/prefer-query-selector -- ids are not guaranteed to be valid CSS selectors\n if (document.getElementById(SWEEP_STYLE_ID)) return;\n const style = document.createElement(\"style\");\n style.id = SWEEP_STYLE_ID;\n // Viewport-fixed ornament anchored to the field's bounding rect via RAF. Not\n // injected into the field's subtree: adding `position: relative; overflow: hidden`\n // to arbitrary Payload field wrappers breaks Lexical's sticky toolbar positioning.\n // Layers: corner brackets (reticle), ring (pulsing border + glow halo), sweep (gradient pass).\n style.textContent = `\n\t\t@keyframes ve-focus-corner-in {\n\t\t\t0% { transform: scale(1.35); opacity: 0; }\n\t\t\t60% { opacity: 1; }\n\t\t\t100% { transform: scale(1); opacity: 1; }\n\t\t}\n\t\t@keyframes ve-focus-ring-pulse {\n\t\t\t0% { box-shadow: 0 0 0 0 ${focusColor(0.55)}, 0 0 0 0 ${focusColor(0.22)}; border-color: ${focusColor(0.95)}; }\n\t\t\t50% { box-shadow: 0 0 0 4px ${focusColor(0.3)}, 0 0 0 14px ${focusColor(0.06)}; border-color: ${focusColor(0.95)}; }\n\t\t\t100% { box-shadow: 0 0 0 0 ${focusColor(0)}, 0 0 0 0 ${focusColor(0)}; border-color: ${focusColor(0)}; }\n\t\t}\n\t\t@keyframes ve-focus-sweep {\n\t\t\t0% { transform: translateY(-100%); opacity: 0; }\n\t\t\t18% { opacity: 1; }\n\t\t\t100% { transform: translateY(100%); opacity: 0; }\n\t\t}\n\t\t@keyframes ve-focus-fadeout {\n\t\t\tto { opacity: 0; }\n\t\t}\n\t\t.ve-sweep-wrap {\n\t\t\tpointer-events: none;\n\t\t\tposition: fixed;\n\t\t\tz-index: 9999;\n\t\t}\n\t\t.ve-sweep-ring {\n\t\t\tposition: absolute;\n\t\t\tinset: -2px;\n\t\t\tborder: 2px solid transparent;\n\t\t\tborder-radius: 6px;\n\t\t\tanimation: ve-focus-ring-pulse 0.7s cubic-bezier(0.4, 0, 0.2, 1) 120ms 2 forwards;\n\t\t}\n\t\t.ve-sweep-corner {\n\t\t\tposition: absolute;\n\t\t\twidth: 14px;\n\t\t\theight: 14px;\n\t\t\tborder-color: ${focusColor(0.95)};\n\t\t\tborder-style: solid;\n\t\t\tborder-width: 0;\n\t\t\tanimation:\n\t\t\t\tve-focus-corner-in 260ms cubic-bezier(0.2, 0.8, 0.2, 1) 0ms both,\n\t\t\t\tve-focus-fadeout 300ms ease 1400ms forwards;\n\t\t}\n\t\t.ve-sweep-corner.tl { top: -4px; left: -4px; border-width: 2px 0 0 2px; border-top-left-radius: 4px; }\n\t\t.ve-sweep-corner.tr { top: -4px; right: -4px; border-width: 2px 2px 0 0; border-top-right-radius: 4px; }\n\t\t.ve-sweep-corner.bl { bottom: -4px; left: -4px; border-width: 0 0 2px 2px; border-bottom-left-radius: 4px; }\n\t\t.ve-sweep-corner.br { bottom: -4px; right: -4px; border-width: 0 2px 2px 0; border-bottom-right-radius: 4px; }\n\t\t.ve-sweep-clip {\n\t\t\tposition: absolute;\n\t\t\tinset: 0;\n\t\t\toverflow: hidden;\n\t\t\tborder-radius: 4px;\n\t\t}\n\t\t.ve-sweep-overlay {\n\t\t\tposition: absolute;\n\t\t\tinset: 0;\n\t\t\tbackground: linear-gradient(\n\t\t\t\tto bottom,\n\t\t\t\ttransparent 0%,\n\t\t\t\t${focusColor(0.06)} 22%,\n\t\t\t\t${focusColor(0.22)} 50%,\n\t\t\t\t${focusColor(0.06)} 78%,\n\t\t\t\ttransparent 100%\n\t\t\t);\n\t\t\tanimation: ve-focus-sweep 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;\n\t\t}\n\t\t@media (prefers-reduced-motion: reduce) {\n\t\t\t.ve-sweep-ring { animation: none; border-color: ${focusColor(0.9)}; box-shadow: 0 0 0 2px ${focusColor(0.22)}, 0 0 0 6px ${focusColor(0.08)}; }\n\t\t\t.ve-sweep-corner { animation: ve-focus-fadeout 300ms ease 1400ms forwards; }\n\t\t\t.ve-sweep-overlay { animation: none; opacity: 0; }\n\t\t}\n\t`;\n document.head.append(style);\n};\n\nconst SWEEP_DECORATION_PAD = 24;\n\nexport const playSweep = (el: HTMLElement): void => {\n ensureSweepStyles();\n const wrap = document.createElement(\"div\");\n wrap.className = \"ve-sweep-wrap\";\n\n const docHeader = document.querySelector<HTMLElement>(\".doc-controls\");\n\n const ring = document.createElement(\"div\");\n ring.className = \"ve-sweep-ring\";\n\n const corners = ([\"tl\", \"tr\", \"bl\", \"br\"] as const).map((pos) => {\n const corner = document.createElement(\"div\");\n corner.className = `ve-sweep-corner ${pos}`;\n return corner;\n });\n\n const clip = document.createElement(\"div\");\n clip.className = \"ve-sweep-clip\";\n const overlay = document.createElement(\"div\");\n overlay.className = \"ve-sweep-overlay\";\n clip.append(overlay);\n\n wrap.append(ring, ...corners, clip);\n document.body.append(wrap);\n\n // Track the field's current rect for the full reveal. If the browser's smooth-scroll\n // is still running when the reveal starts, or the layout shifts mid-animation, the\n // wrap stays anchored to the field instead of drifting off.\n let rafId = 0;\n const pad = SWEEP_DECORATION_PAD;\n const track = () => {\n const rect = el.getBoundingClientRect();\n wrap.style.top = `${rect.top}px`;\n wrap.style.left = `${rect.left}px`;\n wrap.style.width = `${rect.width}px`;\n wrap.style.height = `${rect.height}px`;\n\n const headerBottom = docHeader?.getBoundingClientRect().bottom ?? 0;\n const topClip = Math.max(headerBottom - rect.top, -pad);\n wrap.style.clipPath = `polygon(${-pad}px ${topClip}px, calc(100% + ${pad}px) ${topClip}px, calc(100% + ${pad}px) calc(100% + ${pad}px), ${-pad}px calc(100% + ${pad}px))`;\n\n rafId = requestAnimationFrame(track);\n };\n track();\n\n setTimeout(() => {\n cancelAnimationFrame(rafId);\n wrap.remove();\n }, REVEAL_TOTAL_MS);\n};\n\n// Lexical rich-text wrappers don't carry the `field-<path>` id — only a\n// `<label htmlFor=\"field-<path>\">` pointing inside. Everything else Payload\n// renders exposes the id on an element (input, select, textarea, group wrapper).\nexport const findFieldElement = (fieldId: string): HTMLElement | null => {\n // oxlint-disable-next-line unicorn/prefer-query-selector -- ids are not guaranteed to be valid CSS selectors\n const direct = document.getElementById(fieldId);\n if (direct) return direct;\n const label = document.querySelector<HTMLElement>(`label[for=\"${fieldId}\"]`);\n const wrapper = label?.closest<HTMLElement>(\".field-type\");\n return wrapper ?? null;\n};\n\n// Payload lazily renders groups that are below the viewport — their inner fields\n// (including the `*-row-<n>` containers the `row` instruction waits on) don't\n// exist in the DOM until the group is scrolled near. Before waiting, walk up\n// the path and scroll the deepest already-mounted ancestor into view so the\n// virtualized subtree hydrates. Safe to call repeatedly; does nothing when the\n// full field id is already present.\nexport const scrollNearestAncestorIntoView = (fieldId: string): void => {\n if (!fieldId.startsWith(\"field-\")) return;\n const segments = fieldId.slice(\"field-\".length).split(\"__\");\n for (let i = segments.length; i > 0; i--) {\n // oxlint-disable-next-line unicorn/prefer-query-selector -- ids are not guaranteed to be valid CSS selectors\n const el = document.getElementById(`field-${segments.slice(0, i).join(\"__\")}`);\n if (el && typeof el.scrollIntoView === \"function\") {\n el.scrollIntoView({ behavior: \"auto\", block: \"center\" });\n return;\n }\n }\n};\n\nconst waitFor = (predicate: () => boolean, budgetMs: number): Promise<boolean> => {\n return new Promise((resolve) => {\n const deadline = Date.now() + budgetMs;\n const tick = () => {\n if (predicate()) return resolve(true);\n if (Date.now() >= deadline) return resolve(false);\n setTimeout(tick, POLL_INTERVAL_MS);\n };\n tick();\n });\n};\n\n// Payload's Collapsible uses its `path` as the id suffix — see\n// @payloadcms/ui/dist/fields/Collapsible/index.js:52.\nconst collapsibleDomId = (path: string): string => `field-collapsible-${path.replace(/\\./g, \"__\")}`;\n\n// Tab buttons can exist at multiple nesting levels (top-level tabs, plus any\n// nested tabs fields inside blocks). A raw `querySelectorAll` at document scope\n// would match all of them, and `buttons[instruction.tabIndex]` would pick the\n// wrong one for any chain step past the top level. The executor narrows the\n// search scope as it descends — each row instruction sets the next scope to\n// the row's container so subsequent tab/collapsible lookups stay inside it.\nconst runInstruction = async (\n instruction: ContainerInstruction,\n scope: ParentNode\n): Promise<{ ok: boolean; nextScope: ParentNode }> => {\n switch (instruction.kind) {\n case \"tab\": {\n const getButton = (): HTMLButtonElement | null => {\n const buttons = scope.querySelectorAll<HTMLButtonElement>(\".tabs-field__tab-button\");\n return buttons[instruction.tabIndex] ?? null;\n };\n const isActive = () =>\n getButton()?.classList.contains(\"tabs-field__tab-button--active\") ?? false;\n\n const ready = await waitFor(() => getButton() !== null, STEP_BUDGET_MS);\n if (!ready) return { ok: false, nextScope: scope };\n if (!isActive()) getButton()!.click();\n const activated = await waitFor(isActive, STEP_BUDGET_MS);\n return { ok: activated, nextScope: scope };\n }\n case \"collapsible\": {\n // Collapsible ids are globally unique in the DOM — resolve at document scope.\n const id = collapsibleDomId(instruction.path);\n // oxlint-disable-next-line unicorn/prefer-query-selector -- ids are not guaranteed to be valid CSS selectors\n const ready = await waitFor(() => document.getElementById(id) !== null, STEP_BUDGET_MS);\n if (!ready) return { ok: false, nextScope: scope };\n // oxlint-disable-next-line unicorn/prefer-query-selector -- ids are not guaranteed to be valid CSS selectors\n const wrapper = document.getElementById(id)!;\n const toggle = wrapper.querySelector<HTMLButtonElement>(\".collapsible__toggle\");\n if (!toggle) return { ok: true, nextScope: wrapper };\n if (toggle.classList.contains(\"collapsible__toggle--collapsed\")) {\n toggle.click();\n const opened = await waitFor(\n () => !toggle.classList.contains(\"collapsible__toggle--collapsed\"),\n STEP_BUDGET_MS\n );\n return { ok: opened, nextScope: wrapper };\n }\n return { ok: true, nextScope: wrapper };\n }\n case \"row\": {\n // `rowContainerId` mirrors the path shape (`a-b-c-row-<n>`). Derive the\n // parent array's field id and scroll it into view to force Payload to\n // hydrate the virtualized rows before we wait for the row container.\n const parentArrayFieldId = `field-${instruction.rowContainerId\n .replace(/-row-\\d+$/, \"\")\n .replace(/-/g, \"__\")}`;\n scrollNearestAncestorIntoView(parentArrayFieldId);\n const ready = await waitFor(\n // oxlint-disable-next-line unicorn/prefer-query-selector -- ids are not guaranteed to be valid CSS selectors\n () => document.getElementById(instruction.rowContainerId) !== null,\n STEP_BUDGET_MS\n );\n if (!ready) return { ok: false, nextScope: scope };\n // oxlint-disable-next-line unicorn/prefer-query-selector -- ids are not guaranteed to be valid CSS selectors\n const row = document.getElementById(instruction.rowContainerId)!;\n const toggle = row.querySelector<HTMLButtonElement>(\".collapsible__toggle\");\n if (!toggle) return { ok: true, nextScope: row };\n if (toggle.classList.contains(\"collapsible__toggle--collapsed\")) {\n toggle.click();\n const opened = await waitFor(\n () => !toggle.classList.contains(\"collapsible__toggle--collapsed\"),\n STEP_BUDGET_MS\n );\n return { ok: opened, nextScope: row };\n }\n return { ok: true, nextScope: row };\n }\n }\n};\n\nexport const applyContainerChain = async (\n chain: readonly ContainerInstruction[]\n): Promise<boolean> => {\n let scope: ParentNode = document;\n for (const instruction of chain) {\n const result = await runInstruction(instruction, scope);\n if (!result.ok) return false;\n scope = result.nextScope;\n }\n return true;\n};\n\n// `scrollIntoView({block: 'center'})` beats a precomputed `scrollBy` delta here:\n// the browser tracks the element's live rect across the smooth-scroll animation,\n// so virtualized fields hydrating mid-scroll (RenderIfInViewport firing as we\n// pass its rootMargin) can't leave us off-target. `.focus({preventScroll: true})`\n// suppresses the browser's default \"scroll focusable into nearest view\" that\n// would otherwise race our centering call. After POST_SCROLL_DELAY_MS the\n// initial scroll should be settled — if additional virtualization shifted the\n// field out of view we re-center once more.\nconst focusAndSweep = (fieldEl: HTMLElement): void => {\n if (typeof fieldEl.scrollIntoView === \"function\") {\n fieldEl.scrollIntoView({ behavior: \"smooth\", block: \"center\" });\n }\n\n setTimeout(() => {\n let sweepTarget: HTMLElement = fieldEl;\n if (fieldEl.matches(FOCUS_SELECTOR)) {\n fieldEl.focus({ preventScroll: true });\n const wrapper = fieldEl.closest<HTMLElement>(\".field-type\");\n if (wrapper) sweepTarget = wrapper;\n } else {\n const focusable = fieldEl.querySelector<HTMLElement>(FOCUS_SELECTOR);\n focusable?.focus({ preventScroll: true });\n }\n if (typeof fieldEl.scrollIntoView === \"function\") {\n const rect = fieldEl.getBoundingClientRect();\n const viewportHeight = window.innerHeight;\n // Re-center only when the field is outside the viewport — don't\n // re-scroll a centered field whose intrinsic height exceeds the\n // viewport (rect.top < 0 AND rect.bottom > viewportHeight is the\n // correctly-centered state for tall fields).\n const outOfView = rect.bottom <= 0 || rect.top >= viewportHeight;\n if (outOfView) {\n fieldEl.scrollIntoView({ behavior: \"smooth\", block: \"center\" });\n }\n }\n playSweep(sweepTarget);\n }, POST_SCROLL_DELAY_MS);\n};\n\n// Soft-fails on each step: if a chain step times out we still attempt the\n// scroll/focus so the user lands near the target (chain partially works,\n// field visible via ancestor scroll).\nexport const expandAndFocus = async (\n chain: readonly ContainerInstruction[],\n fieldId: string | null\n): Promise<void> => {\n await applyContainerChain(chain);\n if (!fieldId) return;\n // After the chain opens the tab/collapsible, the target may still live inside\n // a virtualized group — kick off a scroll to the nearest existing ancestor\n // before polling so Payload hydrates the subtree.\n scrollNearestAncestorIntoView(fieldId);\n const ready = await waitFor(() => findFieldElement(fieldId) !== null, STEP_BUDGET_MS);\n if (!ready) return;\n const fieldEl = findFieldElement(fieldId);\n if (fieldEl) focusAndSweep(fieldEl);\n};\n"],"names":["FOCUS_SELECTOR","SWEEP_STYLE_ID","POLL_INTERVAL_MS","STEP_BUDGET_MS","POST_SCROLL_DELAY_MS","REVEAL_TOTAL_MS","FOCUS_HSL","h","s","l","focusColor","alpha","ensureSweepStyles","document","getElementById","style","createElement","id","textContent","head","append","SWEEP_DECORATION_PAD","playSweep","el","wrap","className","docHeader","querySelector","ring","corners","map","pos","corner","clip","overlay","body","rafId","pad","track","rect","getBoundingClientRect","top","left","width","height","headerBottom","bottom","topClip","Math","max","clipPath","requestAnimationFrame","setTimeout","cancelAnimationFrame","remove","findFieldElement","fieldId","direct","label","wrapper","closest","scrollNearestAncestorIntoView","startsWith","segments","slice","length","split","i","join","scrollIntoView","behavior","block","waitFor","predicate","budgetMs","Promise","resolve","deadline","Date","now","tick","collapsibleDomId","path","replace","runInstruction","instruction","scope","kind","getButton","buttons","querySelectorAll","tabIndex","isActive","classList","contains","ready","ok","nextScope","click","activated","toggle","opened","parentArrayFieldId","rowContainerId","row","applyContainerChain","chain","result","focusAndSweep","fieldEl","sweepTarget","matches","focus","preventScroll","focusable","viewportHeight","window","innerHeight","outOfView","expandAndFocus"],"mappings":"AAEA,MAAMA,iBAAiB;AAEvB,MAAMC,iBAAiB;AACvB,MAAMC,mBAAmB;AACzB,MAAMC,iBAAiB;AACvB,MAAMC,uBAAuB;AAE7B,MAAMC,kBAAkB;AAExB,8EAA8E;AAC9E,+EAA+E;AAC/E,yCAAyC;AACzC,sCAAsC;AACtC,MAAMC,YAAY;IAAEC,GAAG;IAAKC,GAAG;IAAIC,GAAG;AAAG;AACzC,MAAMC,aAAa,CAACC,QAClB,CAAC,KAAK,EAAEL,UAAUC,CAAC,CAAC,EAAE,EAAED,UAAUE,CAAC,CAAC,GAAG,EAAEF,UAAUG,CAAC,CAAC,GAAG,EAAEE,MAAM,CAAC,CAAC;AAEpE,MAAMC,oBAAoB;IACxB,6GAA6G;IAC7G,IAAIC,SAASC,cAAc,CAACb,iBAAiB;IAC7C,MAAMc,QAAQF,SAASG,aAAa,CAAC;IACrCD,MAAME,EAAE,GAAGhB;IACX,6EAA6E;IAC7E,mFAAmF;IACnF,mFAAmF;IACnF,+FAA+F;IAC/Fc,MAAMG,WAAW,GAAG,CAAC;;;;;;;8BAOO,EAAER,WAAW,MAAM,UAAU,EAAEA,WAAW,MAAM,gBAAgB,EAAEA,WAAW,MAAM;gCACjF,EAAEA,WAAW,KAAK,aAAa,EAAEA,WAAW,MAAM,gBAAgB,EAAEA,WAAW,MAAM;8BACvF,EAAEA,WAAW,GAAG,UAAU,EAAEA,WAAW,GAAG,gBAAgB,EAAEA,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0BvF,EAAEA,WAAW,MAAM;;;;;;;;;;;;;;;;;;;;;;;IAuBhC,EAAEA,WAAW,MAAM;IACnB,EAAEA,WAAW,MAAM;IACnB,EAAEA,WAAW,MAAM;;;;;;mDAM4B,EAAEA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E,QAAQrE,qBAAqB;YAC1C,MAAM2E,iBAAiBC,OAAOC,WAAW;YACzC,gEAAgE;YAChE,gEAAgE;YAChE,iEAAiE;YACjE,6CAA6C;YAC7C,MAAMC,YAAY/E,KAAKO,MAAM,IAAI,KAAKP,KAAKE,GAAG,IAAI0E;YAClD,IAAIG,WAAW;gBACbT,QAAQxC,cAAc,CAAC;oBAAEC,UAAU;oBAAUC,OAAO;gBAAS;YAC/D;QACF;QACAjD,UAAUwF;IACZ,GAAG1G;AACL;AAEA,0EAA0E;AAC1E,yEAAyE;AACzE,sCAAsC;AACtC,OAAO,MAAMmH,iBAAiB,OAC5Bb,OACAlD;IAEA,MAAMiD,oBAAoBC;IAC1B,IAAI,CAAClD,SAAS;IACd,8EAA8E;IAC9E,2EAA2E;IAC3E,kDAAkD;IAClDK,8BAA8BL;IAC9B,MAAMuC,QAAQ,MAAMvB,QAAQ,IAAMjB,iBAAiBC,aAAa,MAAMrD;IACtE,IAAI,CAAC4F,OAAO;IACZ,MAAMc,UAAUtD,iBAAiBC;IACjC,IAAIqD,SAASD,cAAcC;AAC7B,EAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { VisualEditingBridgeProvider } from "./VisualEditingBridgeProvider.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/admin/index.ts"],"sourcesContent":["export { VisualEditingBridgeProvider } from \"./VisualEditingBridgeProvider.js\";\n"],"names":["VisualEditingBridgeProvider"],"mappings":"AAAA,SAASA,2BAA2B,QAAQ,mCAAmC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Payload's form DOM conventions:
|
|
2
|
+
// - Each array/block row container has id `<arrayName>-row-<index>` at top level,
|
|
3
|
+
// and `<arrayName>-<index>-<subName>-row-<subIndex>` for nested array rows.
|
|
4
|
+
// - Each leaf field wrapper has id `field-<path-with-__-separator>`.
|
|
5
|
+
// A stega path ending in a numeric segment targets a block/row itself, not a
|
|
6
|
+
// specific leaf field — so `fieldId` is null in that case.
|
|
7
|
+
export const parseFieldPath = (fieldPath)=>{
|
|
8
|
+
const parts = fieldPath.split(".");
|
|
9
|
+
const rowIds = [];
|
|
10
|
+
for(let i = 0; i < parts.length; i++){
|
|
11
|
+
if (!Number.isNaN(Number.parseInt(parts[i], 10))) {
|
|
12
|
+
const prefix = parts.slice(0, i).join("-");
|
|
13
|
+
rowIds.push(`${prefix}-row-${parts[i]}`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const lastPart = parts[parts.length - 1];
|
|
17
|
+
const endsWithIndex = !Number.isNaN(Number.parseInt(lastPart, 10));
|
|
18
|
+
const fieldId = endsWithIndex ? null : `field-${fieldPath.replace(/\./g, "__")}`;
|
|
19
|
+
return {
|
|
20
|
+
rowIds,
|
|
21
|
+
fieldId
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=parseFieldPath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/admin/parseFieldPath.ts"],"sourcesContent":["// Payload's form DOM conventions:\n// - Each array/block row container has id `<arrayName>-row-<index>` at top level,\n// and `<arrayName>-<index>-<subName>-row-<subIndex>` for nested array rows.\n// - Each leaf field wrapper has id `field-<path-with-__-separator>`.\n// A stega path ending in a numeric segment targets a block/row itself, not a\n// specific leaf field — so `fieldId` is null in that case.\nexport const parseFieldPath = (\n fieldPath: string\n): {\n rowIds: string[];\n fieldId: string | null;\n} => {\n const parts = fieldPath.split(\".\");\n const rowIds: string[] = [];\n\n for (let i = 0; i < parts.length; i++) {\n if (!Number.isNaN(Number.parseInt(parts[i]!, 10))) {\n const prefix = parts.slice(0, i).join(\"-\");\n rowIds.push(`${prefix}-row-${parts[i]}`);\n }\n }\n\n const lastPart = parts[parts.length - 1]!;\n const endsWithIndex = !Number.isNaN(Number.parseInt(lastPart, 10));\n const fieldId = endsWithIndex ? null : `field-${fieldPath.replace(/\\./g, \"__\")}`;\n\n return { rowIds, fieldId };\n};\n"],"names":["parseFieldPath","fieldPath","parts","split","rowIds","i","length","Number","isNaN","parseInt","prefix","slice","join","push","lastPart","endsWithIndex","fieldId","replace"],"mappings":"AAAA,kCAAkC;AAClC,oFAAoF;AACpF,gFAAgF;AAChF,uEAAuE;AACvE,6EAA6E;AAC7E,2DAA2D;AAC3D,OAAO,MAAMA,iBAAiB,CAC5BC;IAKA,MAAMC,QAAQD,UAAUE,KAAK,CAAC;IAC9B,MAAMC,SAAmB,EAAE;IAE3B,IAAK,IAAIC,IAAI,GAAGA,IAAIH,MAAMI,MAAM,EAAED,IAAK;QACrC,IAAI,CAACE,OAAOC,KAAK,CAACD,OAAOE,QAAQ,CAACP,KAAK,CAACG,EAAE,EAAG,MAAM;YACjD,MAAMK,SAASR,MAAMS,KAAK,CAAC,GAAGN,GAAGO,IAAI,CAAC;YACtCR,OAAOS,IAAI,CAAC,CAAC,EAAEH,OAAO,KAAK,EAAER,KAAK,CAACG,EAAE,CAAC,CAAC;QACzC;IACF;IAEA,MAAMS,WAAWZ,KAAK,CAACA,MAAMI,MAAM,GAAG,EAAE;IACxC,MAAMS,gBAAgB,CAACR,OAAOC,KAAK,CAACD,OAAOE,QAAQ,CAACK,UAAU;IAC9D,MAAME,UAAUD,gBAAgB,OAAO,CAAC,MAAM,EAAEd,UAAUgB,OAAO,CAAC,OAAO,MAAM,CAAC;IAEhF,OAAO;QAAEb;QAAQY;IAAQ;AAC3B,EAAE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type ResolverField = {
|
|
2
|
+
type: string;
|
|
3
|
+
name?: string;
|
|
4
|
+
fields?: ResolverField[];
|
|
5
|
+
tabs?: ResolverTab[];
|
|
6
|
+
blocks?: ResolverBlock[];
|
|
7
|
+
};
|
|
8
|
+
export type ResolverTab = {
|
|
9
|
+
name?: string;
|
|
10
|
+
fields: ResolverField[];
|
|
11
|
+
};
|
|
12
|
+
export type ResolverBlock = {
|
|
13
|
+
slug?: string;
|
|
14
|
+
fields: ResolverField[];
|
|
15
|
+
};
|
|
16
|
+
export type ContainerInstruction = {
|
|
17
|
+
kind: "tab";
|
|
18
|
+
tabIndex: number;
|
|
19
|
+
} | {
|
|
20
|
+
kind: "collapsible";
|
|
21
|
+
path: string;
|
|
22
|
+
} | {
|
|
23
|
+
kind: "row";
|
|
24
|
+
rowContainerId: string;
|
|
25
|
+
};
|
|
26
|
+
export type ResolvedPath = {
|
|
27
|
+
chain: ContainerInstruction[];
|
|
28
|
+
fieldId: string | null;
|
|
29
|
+
};
|
|
30
|
+
export declare const resolveContainerChain: (path: string, fields: readonly ResolverField[]) => ResolvedPath | null;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// Resolves a data path (e.g. `translation.forms.privacyPolicy` or `layout.2.heading`)
|
|
2
|
+
// against the raw Payload fields config into an ordered chain of DOM operations
|
|
3
|
+
// needed to make the target field visible before focus.
|
|
4
|
+
//
|
|
5
|
+
// Three instruction kinds — see `executor` in expandAndFocus.ts:
|
|
6
|
+
// - tab → click the tabs-field button at `tabIndex` (scope narrowed by
|
|
7
|
+
// earlier row/collapsible instructions)
|
|
8
|
+
// - collapsible → click the toggle inside `#field-collapsible-<path__>`
|
|
9
|
+
// - row → click the toggle inside `#<rowContainerId>`
|
|
10
|
+
//
|
|
11
|
+
// Collapsible DOM ids use Payload's `path` (see `getFieldPaths.js`), which is
|
|
12
|
+
// the data-shape path with `_index-<N-M-...>` segments for unnamed ancestors.
|
|
13
|
+
// Unnamed containers inside other unnamed containers *accumulate* indices with
|
|
14
|
+
// hyphens, e.g. an unnamed group at index 0 containing a collapsible at index
|
|
15
|
+
// 12 becomes `_index-0-12`, not `_index-0._index-12`. We track this via the
|
|
16
|
+
// `indexStack`, which resets at every named descent and extends at every
|
|
17
|
+
// unnamed descent.
|
|
18
|
+
export const resolveContainerChain = (path, fields)=>{
|
|
19
|
+
if (!path) return null;
|
|
20
|
+
const segments = path.split(".");
|
|
21
|
+
const chain = walkFields(fields, segments, 0, "", []);
|
|
22
|
+
if (chain === null) return null;
|
|
23
|
+
const last = segments[segments.length - 1];
|
|
24
|
+
const fieldId = /^\d+$/.test(last) ? null : `field-${path.replace(/\./g, "__")}`;
|
|
25
|
+
return {
|
|
26
|
+
chain,
|
|
27
|
+
fieldId
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
// `dataPath` is the path up to the current named ancestor (drops all `_index`).
|
|
31
|
+
// `indexStack` accumulates positions inside unnamed ancestors since the last
|
|
32
|
+
// named descent — matches Payload's `parentIndexPath` + trailing `index`.
|
|
33
|
+
const walkFields = (fields, segments, segIndex, dataPath, indexStack)=>{
|
|
34
|
+
if (segIndex >= segments.length) return [];
|
|
35
|
+
const segment = segments[segIndex];
|
|
36
|
+
for(let i = 0; i < fields.length; i++){
|
|
37
|
+
const field = fields[i];
|
|
38
|
+
const result = descendInto(field, i, segment, segments, segIndex, dataPath, indexStack);
|
|
39
|
+
if (result !== null) return result;
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
};
|
|
43
|
+
// Payload's path for an unnamed container: `<named-ancestor-path>._index-<idx-stack>`.
|
|
44
|
+
const unnamedPath = (dataPath, indexStack, index)=>{
|
|
45
|
+
const suffix = `_index-${[
|
|
46
|
+
...indexStack,
|
|
47
|
+
index
|
|
48
|
+
].join("-")}`;
|
|
49
|
+
return dataPath ? `${dataPath}.${suffix}` : suffix;
|
|
50
|
+
};
|
|
51
|
+
const descendInto = (field, i, segment, segments, segIndex, dataPath, indexStack)=>{
|
|
52
|
+
switch(field.type){
|
|
53
|
+
case "row":
|
|
54
|
+
{
|
|
55
|
+
if (!field.fields) return null;
|
|
56
|
+
// Transparent. Extend indexStack so nested collapsible paths stay aligned with Payload.
|
|
57
|
+
return walkFields(field.fields, segments, segIndex, dataPath, [
|
|
58
|
+
...indexStack,
|
|
59
|
+
i
|
|
60
|
+
]);
|
|
61
|
+
}
|
|
62
|
+
case "collapsible":
|
|
63
|
+
{
|
|
64
|
+
if (!field.fields) return null;
|
|
65
|
+
const sub = walkFields(field.fields, segments, segIndex, dataPath, [
|
|
66
|
+
...indexStack,
|
|
67
|
+
i
|
|
68
|
+
]);
|
|
69
|
+
if (sub === null) return null;
|
|
70
|
+
return [
|
|
71
|
+
{
|
|
72
|
+
kind: "collapsible",
|
|
73
|
+
path: unnamedPath(dataPath, indexStack, i)
|
|
74
|
+
},
|
|
75
|
+
...sub
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
case "tabs":
|
|
79
|
+
{
|
|
80
|
+
if (!field.tabs) return null;
|
|
81
|
+
// The tabs field itself occupies an index slot among its siblings. If the
|
|
82
|
+
// match lives inside an unnamed tab, that tab's index also extends the
|
|
83
|
+
// stack. Named tabs reset everything.
|
|
84
|
+
for(let t = 0; t < field.tabs.length; t++){
|
|
85
|
+
const tab = field.tabs[t];
|
|
86
|
+
let advance;
|
|
87
|
+
let nextDataPath;
|
|
88
|
+
let nextIndexStack;
|
|
89
|
+
if (tab.name) {
|
|
90
|
+
if (tab.name !== segment) continue;
|
|
91
|
+
advance = 1;
|
|
92
|
+
nextDataPath = dataPath ? `${dataPath}.${tab.name}` : tab.name;
|
|
93
|
+
nextIndexStack = [];
|
|
94
|
+
} else {
|
|
95
|
+
advance = 0;
|
|
96
|
+
nextDataPath = dataPath;
|
|
97
|
+
nextIndexStack = [
|
|
98
|
+
...indexStack,
|
|
99
|
+
i,
|
|
100
|
+
t
|
|
101
|
+
];
|
|
102
|
+
}
|
|
103
|
+
const sub = walkFields(tab.fields, segments, segIndex + advance, nextDataPath, nextIndexStack);
|
|
104
|
+
if (sub === null) continue;
|
|
105
|
+
return [
|
|
106
|
+
{
|
|
107
|
+
kind: "tab",
|
|
108
|
+
tabIndex: t
|
|
109
|
+
},
|
|
110
|
+
...sub
|
|
111
|
+
];
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
case "group":
|
|
116
|
+
{
|
|
117
|
+
if (!field.fields) return null;
|
|
118
|
+
if (!field.name) {
|
|
119
|
+
return walkFields(field.fields, segments, segIndex, dataPath, [
|
|
120
|
+
...indexStack,
|
|
121
|
+
i
|
|
122
|
+
]);
|
|
123
|
+
}
|
|
124
|
+
if (field.name !== segment) return null;
|
|
125
|
+
const nextData = dataPath ? `${dataPath}.${field.name}` : field.name;
|
|
126
|
+
return walkFields(field.fields, segments, segIndex + 1, nextData, []);
|
|
127
|
+
}
|
|
128
|
+
case "array":
|
|
129
|
+
case "blocks":
|
|
130
|
+
{
|
|
131
|
+
if (field.name !== segment) return null;
|
|
132
|
+
const nextData = dataPath ? `${dataPath}.${field.name}` : field.name;
|
|
133
|
+
if (segIndex + 1 >= segments.length) return [];
|
|
134
|
+
const rawIndex = segments[segIndex + 1];
|
|
135
|
+
if (!/^\d+$/.test(rawIndex)) return null;
|
|
136
|
+
const rowContainerId = `${nextData.replace(/\./g, "-")}-row-${rawIndex}`;
|
|
137
|
+
const rowInstruction = {
|
|
138
|
+
kind: "row",
|
|
139
|
+
rowContainerId
|
|
140
|
+
};
|
|
141
|
+
const descendedData = `${nextData}.${rawIndex}`;
|
|
142
|
+
if (segIndex + 2 >= segments.length) return [
|
|
143
|
+
rowInstruction
|
|
144
|
+
];
|
|
145
|
+
if (field.type === "array") {
|
|
146
|
+
if (!field.fields) return null;
|
|
147
|
+
const sub = walkFields(field.fields, segments, segIndex + 2, descendedData, []);
|
|
148
|
+
return sub === null ? null : [
|
|
149
|
+
rowInstruction,
|
|
150
|
+
...sub
|
|
151
|
+
];
|
|
152
|
+
}
|
|
153
|
+
if (!field.blocks) return null;
|
|
154
|
+
for (const block of field.blocks){
|
|
155
|
+
const sub = walkFields(block.fields, segments, segIndex + 2, descendedData, []);
|
|
156
|
+
if (sub !== null) return [
|
|
157
|
+
rowInstruction,
|
|
158
|
+
...sub
|
|
159
|
+
];
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
default:
|
|
164
|
+
{
|
|
165
|
+
if (field.name === segment && segIndex === segments.length - 1) return [];
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
//# sourceMappingURL=resolveContainerChain.js.map
|