@preprio/toolkit 0.6.0-alpha.8 → 1.0.0-rc.1
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 +111 -1363
- package/dist/astro/index.cjs +1555 -182
- package/dist/astro/index.d.cts +201 -1
- package/dist/astro/index.d.ts +201 -1
- package/dist/astro/index.js +1557 -29
- package/dist/{chunk-ATPB7GEC.js → chunk-33GWVTRJ.js} +1 -1
- package/dist/chunk-A2J7R4LR.js +256 -0
- package/dist/{chunk-T7ESBVBI.js → chunk-DSJ22P6J.js} +6 -1
- package/dist/chunk-KM2GME62.js +1255 -0
- package/dist/chunk-UTKH7DOI.js +58 -0
- package/dist/chunk-V7MCHPE7.js +85 -0
- package/dist/{chunk-2QGUP7VQ.js → chunk-WBMN4L7G.js} +1680 -579
- package/dist/chunk-Y7JWV7WV.js +374 -0
- package/dist/codegen/index.cjs +82 -0
- package/dist/codegen/index.d.cts +70 -0
- package/dist/codegen/index.d.ts +70 -0
- package/dist/codegen/index.js +64 -0
- package/dist/index.cjs +3729 -553
- package/dist/index.d.cts +403 -19
- package/dist/index.d.ts +403 -19
- package/dist/index.js +345 -24
- package/dist/live-preview-HCBNBC6C.js +19 -0
- package/dist/nextjs/components.cjs +1872 -729
- package/dist/nextjs/components.d.cts +5 -51
- package/dist/nextjs/components.d.ts +5 -51
- package/dist/nextjs/components.js +8 -274
- package/dist/nextjs/index.cjs +1228 -181
- package/dist/nextjs/index.d.cts +247 -92
- package/dist/nextjs/index.d.ts +247 -92
- package/dist/nextjs/index.js +1629 -111
- package/dist/nextjs/live-action.cjs +298 -0
- package/dist/nextjs/live-action.d.cts +12 -0
- package/dist/nextjs/live-action.d.ts +12 -0
- package/dist/nextjs/live-action.js +68 -0
- package/dist/nextjs/live.cjs +2010 -0
- package/dist/nextjs/live.d.cts +54 -0
- package/dist/nextjs/live.d.ts +54 -0
- package/dist/nextjs/live.js +287 -0
- package/dist/nuxt/chunk-5RBZPRQN.js +350 -0
- package/dist/nuxt/chunk-LUKVPOJ2.js +32 -0
- package/dist/nuxt/index.cjs +15 -16
- package/dist/nuxt/index.d.cts +167 -6
- package/dist/nuxt/index.d.ts +167 -6
- package/dist/nuxt/index.js +402 -15
- package/dist/nuxt/live-preview-KO4IKWTX.js +1234 -0
- package/dist/nuxt/live.cjs +1928 -0
- package/dist/nuxt/live.d.cts +45 -0
- package/dist/nuxt/live.d.ts +45 -0
- package/dist/nuxt/live.js +216 -0
- package/dist/{types-BYH9XqmN.d.cts → pixel-DqU7NvgW.d.cts} +102 -5
- package/dist/{types-BYH9XqmN.d.ts → pixel-DqU7NvgW.d.ts} +102 -5
- package/dist/react/components.cjs +1865 -480
- package/dist/react/components.d.cts +43 -8
- package/dist/react/components.d.ts +43 -8
- package/dist/react/components.js +1865 -480
- package/dist/sveltekit/chunk-5RBZPRQN.js +350 -0
- package/dist/sveltekit/chunk-LUKVPOJ2.js +32 -0
- package/dist/sveltekit/index.cjs +15 -16
- package/dist/sveltekit/index.d.cts +111 -10
- package/dist/sveltekit/index.d.ts +111 -10
- package/dist/sveltekit/index.js +398 -15
- package/dist/sveltekit/live-preview-KO4IKWTX.js +1234 -0
- package/dist/sveltekit/live.cjs +1940 -0
- package/dist/sveltekit/live.d.cts +61 -0
- package/dist/sveltekit/live.d.ts +61 -0
- package/dist/sveltekit/live.js +220 -0
- package/package.json +132 -71
- package/src/astro/PreprToolbar.astro +7 -1
- package/src/astro/PreprTrackingPixel.astro +2 -4
- package/src/nuxt/PreprToolbar.vue +12 -1
- package/src/nuxt/PreprTrackingPixel.vue +2 -4
- package/src/sveltekit/PreprToolbar.svelte +17 -2
- package/src/sveltekit/PreprTrackingPixel.svelte +2 -4
- package/dist/astro/chunk-R2YPGDVU.js +0 -173
- package/dist/astro/graphql.cjs +0 -1078
- package/dist/astro/graphql.d.cts +0 -300
- package/dist/astro/graphql.d.ts +0 -300
- package/dist/astro/graphql.js +0 -984
- package/dist/astro/index-XT_z-RYT.d.cts +0 -130
- package/dist/astro/index-XT_z-RYT.d.ts +0 -130
- package/dist/chunk-3NCEVJJ3.js +0 -10
- package/dist/chunk-OY7OKO6Q.js +0 -499
- package/dist/chunk-S5RWVMDJ.js +0 -148
- package/dist/graphql/codegen.cjs +0 -557
- package/dist/graphql/codegen.d.cts +0 -23
- package/dist/graphql/codegen.d.ts +0 -23
- package/dist/graphql/codegen.js +0 -99
- package/dist/graphql.cjs +0 -1020
- package/dist/graphql.d.cts +0 -335
- package/dist/graphql.d.ts +0 -335
- package/dist/graphql.js +0 -448
- package/dist/nextjs/chunk-O2SBSBDG.js +0 -549
- package/dist/nextjs/graphql.cjs +0 -1811
- package/dist/nextjs/graphql.d.cts +0 -498
- package/dist/nextjs/graphql.d.ts +0 -498
- package/dist/nextjs/graphql.js +0 -1397
- package/dist/nextjs/server-BL-sqZvu.d.cts +0 -156
- package/dist/nextjs/server-BL-sqZvu.d.ts +0 -156
- package/dist/nuxt/chunk-SX3MSVPK.js +0 -417
- package/dist/nuxt/graphql.cjs +0 -1085
- package/dist/nuxt/graphql.d.cts +0 -297
- package/dist/nuxt/graphql.d.ts +0 -297
- package/dist/nuxt/graphql.js +0 -985
- package/dist/nuxt/server-8v6OHbsw.d.cts +0 -158
- package/dist/nuxt/server-8v6OHbsw.d.ts +0 -158
- package/dist/pixel-DwW7cXJm.d.cts +0 -49
- package/dist/pixel-DwW7cXJm.d.ts +0 -49
- package/dist/server-Brr1UgtW.d.ts +0 -59
- package/dist/server-DJuS3YU0.d.cts +0 -59
- package/dist/sveltekit/chunk-UOASSHZO.js +0 -413
- package/dist/sveltekit/graphql.cjs +0 -1091
- package/dist/sveltekit/graphql.d.cts +0 -302
- package/dist/sveltekit/graphql.d.ts +0 -302
- package/dist/sveltekit/graphql.js +0 -991
- package/dist/sveltekit/server-CO847mEV.d.cts +0 -98
- package/dist/sveltekit/server-CO847mEV.d.ts +0 -98
package/dist/react/components.js
CHANGED
|
@@ -12,6 +12,20 @@ var PARAM_SEGMENT = "prepr_preview_segment";
|
|
|
12
12
|
var PARAM_VARIANT = "prepr_preview_ab";
|
|
13
13
|
var PARAM_HIDE_BAR = "prepr_hide_bar";
|
|
14
14
|
var ONE_YEAR_SECONDS = 60 * 60 * 24 * 365;
|
|
15
|
+
var ATTR_ENCODED = "data-prepr-encoded";
|
|
16
|
+
var ATTR_ID = "data-prepr-id";
|
|
17
|
+
var ATTR_FIELD = "data-prepr-field";
|
|
18
|
+
var ATTR_LOCALE = "data-prepr-locale";
|
|
19
|
+
var ATTR_HREF = "data-prepr-href";
|
|
20
|
+
var ENCODED_SELECTOR = `[${ATTR_ENCODED}]`;
|
|
21
|
+
var TOOLBAR_TAG = "prepr-toolbar";
|
|
22
|
+
var SEGMENT_ALL_OTHER_USERS = "all_other_users";
|
|
23
|
+
var EVENT_INIT = "prepr:initVE";
|
|
24
|
+
var EVENT_REFERENCES = "prepr:references";
|
|
25
|
+
var EVENT_GET_SCROLL_POSITION = "prepr:getScrollPosition";
|
|
26
|
+
var EVENT_SCROLL_TO_FIELD = "prepr:scrollToField";
|
|
27
|
+
var EVENT_ALLOW_NAVIGATION = "prepr:allowNavigation";
|
|
28
|
+
var EVENT_ITEM_CHANGED = "prepr:itemChanged";
|
|
15
29
|
|
|
16
30
|
// src/core/cookies.ts
|
|
17
31
|
function getCookie(name) {
|
|
@@ -19,7 +33,11 @@ function getCookie(name) {
|
|
|
19
33
|
const match = document.cookie.split("; ").find((row) => row.startsWith(`${name}=`));
|
|
20
34
|
if (!match) return null;
|
|
21
35
|
const value = match.slice(name.length + 1);
|
|
22
|
-
|
|
36
|
+
try {
|
|
37
|
+
return decodeURIComponent(value);
|
|
38
|
+
} catch {
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
23
41
|
}
|
|
24
42
|
function setCookie(name, value, options = {}) {
|
|
25
43
|
if (typeof document === "undefined") return;
|
|
@@ -71,6 +89,40 @@ var ALL_FEATURES_ENABLED = Object.freeze({
|
|
|
71
89
|
editMode: true
|
|
72
90
|
});
|
|
73
91
|
|
|
92
|
+
// src/core/locales/de.json
|
|
93
|
+
var de_default = {
|
|
94
|
+
common: {
|
|
95
|
+
viewingAs: "Ansicht als:",
|
|
96
|
+
user: "Benutzer",
|
|
97
|
+
off: "Aus",
|
|
98
|
+
on: "An",
|
|
99
|
+
reset: "Zur\xFCcksetzen",
|
|
100
|
+
toolbar: "Symbolleiste"
|
|
101
|
+
},
|
|
102
|
+
adaptiveContent: {
|
|
103
|
+
adaptiveContent: "Adaptive Inhalte",
|
|
104
|
+
enablePreview: "Vorschaumodus",
|
|
105
|
+
segment: "Segment",
|
|
106
|
+
ABVariant: "A/B-Variante",
|
|
107
|
+
chooseSegment: "Segment w\xE4hlen",
|
|
108
|
+
searchSegments: "Segmente suchen",
|
|
109
|
+
none: "Keine Segmente",
|
|
110
|
+
allOtherUsers: "Alle anderen Benutzer",
|
|
111
|
+
offDescription: "Die Website als echter Benutzer ansehen (Cookies verwenden)",
|
|
112
|
+
onDescription: "Mit der Symbolleiste Segmente und A/B-Varianten simulieren"
|
|
113
|
+
},
|
|
114
|
+
editingTools: {
|
|
115
|
+
editingTools: "Bearbeitungswerkzeuge",
|
|
116
|
+
editMode: "Bearbeitungsmodus",
|
|
117
|
+
ariaCloseEditMode: "Bearbeitungsmodus schlie\xDFen"
|
|
118
|
+
},
|
|
119
|
+
visualEditor: {
|
|
120
|
+
edit: "Bearbeiten",
|
|
121
|
+
otherItem: "anderes Element",
|
|
122
|
+
linkedItem: "verkn\xFCpftes Element"
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
74
126
|
// src/core/locales/en.json
|
|
75
127
|
var en_default = {
|
|
76
128
|
common: {
|
|
@@ -97,6 +149,45 @@ var en_default = {
|
|
|
97
149
|
editingTools: "Editing tools",
|
|
98
150
|
editMode: "Edit mode",
|
|
99
151
|
ariaCloseEditMode: "Close edit mode"
|
|
152
|
+
},
|
|
153
|
+
visualEditor: {
|
|
154
|
+
edit: "Edit",
|
|
155
|
+
otherItem: "other item",
|
|
156
|
+
linkedItem: "linked item"
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// src/core/locales/fr.json
|
|
161
|
+
var fr_default = {
|
|
162
|
+
common: {
|
|
163
|
+
viewingAs: "Affichage en tant que :",
|
|
164
|
+
user: "Utilisateur",
|
|
165
|
+
off: "D\xE9sactiv\xE9",
|
|
166
|
+
on: "Activ\xE9",
|
|
167
|
+
reset: "R\xE9initialiser",
|
|
168
|
+
toolbar: "Barre d'outils"
|
|
169
|
+
},
|
|
170
|
+
adaptiveContent: {
|
|
171
|
+
adaptiveContent: "Contenu adaptatif",
|
|
172
|
+
enablePreview: "Mode aper\xE7u",
|
|
173
|
+
segment: "Segment",
|
|
174
|
+
ABVariant: "Variante A/B",
|
|
175
|
+
chooseSegment: "Choisir un segment",
|
|
176
|
+
searchSegments: "Rechercher des segments",
|
|
177
|
+
none: "Aucun segment",
|
|
178
|
+
allOtherUsers: "Tous les autres utilisateurs",
|
|
179
|
+
offDescription: "Voir le site comme un vrai utilisateur (utiliser les cookies)",
|
|
180
|
+
onDescription: "Utilisez la barre d'outils pour simuler des segments et des variantes A/B"
|
|
181
|
+
},
|
|
182
|
+
editingTools: {
|
|
183
|
+
editingTools: "Outils d'\xE9dition",
|
|
184
|
+
editMode: "Mode \xE9dition",
|
|
185
|
+
ariaCloseEditMode: "Fermer le mode \xE9dition"
|
|
186
|
+
},
|
|
187
|
+
visualEditor: {
|
|
188
|
+
edit: "Modifier",
|
|
189
|
+
otherItem: "autre \xE9l\xE9ment",
|
|
190
|
+
linkedItem: "\xE9l\xE9ment li\xE9"
|
|
100
191
|
}
|
|
101
192
|
};
|
|
102
193
|
|
|
@@ -126,13 +217,20 @@ var nl_default = {
|
|
|
126
217
|
editingTools: "Editing Tools",
|
|
127
218
|
editMode: "Edit mode",
|
|
128
219
|
ariaCloseEditMode: "Edit mode sluiten"
|
|
220
|
+
},
|
|
221
|
+
visualEditor: {
|
|
222
|
+
edit: "Bewerken",
|
|
223
|
+
otherItem: "ander item",
|
|
224
|
+
linkedItem: "gekoppeld item"
|
|
129
225
|
}
|
|
130
226
|
};
|
|
131
227
|
|
|
132
228
|
// src/core/i18n.ts
|
|
133
229
|
var dictionaries = {
|
|
134
230
|
en: en_default,
|
|
135
|
-
nl: nl_default
|
|
231
|
+
nl: nl_default,
|
|
232
|
+
fr: fr_default,
|
|
233
|
+
de: de_default
|
|
136
234
|
};
|
|
137
235
|
var LOCALES = Object.keys(dictionaries);
|
|
138
236
|
function isLocale(value) {
|
|
@@ -161,10 +259,27 @@ function t(key, locale, vars) {
|
|
|
161
259
|
return key;
|
|
162
260
|
}
|
|
163
261
|
|
|
262
|
+
// src/core/shared-state.ts
|
|
263
|
+
var KEY = /* @__PURE__ */ Symbol.for("@preprio/toolkit:shared-state");
|
|
264
|
+
function initialState() {
|
|
265
|
+
return {
|
|
266
|
+
trustedParentOrigin: null,
|
|
267
|
+
debugEnabled: void 0,
|
|
268
|
+
strictMode: false,
|
|
269
|
+
liveAnnouncedStrict: void 0
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function sharedState() {
|
|
273
|
+
const scope = globalThis;
|
|
274
|
+
return scope[KEY] ?? (scope[KEY] = initialState());
|
|
275
|
+
}
|
|
276
|
+
|
|
164
277
|
// src/core/utils.ts
|
|
165
|
-
var trustedParentOrigin = null;
|
|
166
278
|
function setTrustedParentOrigin(origin) {
|
|
167
|
-
trustedParentOrigin = origin;
|
|
279
|
+
sharedState().trustedParentOrigin = origin;
|
|
280
|
+
}
|
|
281
|
+
function getTrustedParentOrigin() {
|
|
282
|
+
return sharedState().trustedParentOrigin;
|
|
168
283
|
}
|
|
169
284
|
function sendPreprEvent(event, data, options) {
|
|
170
285
|
if (typeof window !== "undefined") {
|
|
@@ -177,6 +292,7 @@ function sendPreprEvent(event, data, options) {
|
|
|
177
292
|
new CustomEvent("prepr_preview_bar", { detail: message })
|
|
178
293
|
);
|
|
179
294
|
if (window.parent && window.parent !== window) {
|
|
295
|
+
const trustedParentOrigin = getTrustedParentOrigin();
|
|
180
296
|
if (trustedParentOrigin) {
|
|
181
297
|
window.parent.postMessage(message, trustedParentOrigin);
|
|
182
298
|
} else if (options?.allowUntrustedTarget) {
|
|
@@ -192,13 +308,13 @@ var DebugLogger = class {
|
|
|
192
308
|
...options
|
|
193
309
|
};
|
|
194
310
|
}
|
|
195
|
-
// A local `enabled` wins; otherwise defer to the
|
|
311
|
+
// A local `enabled` wins; otherwise defer to the shared flag so scoped
|
|
196
312
|
// loggers created before initDebugLogger() still pick up the setting.
|
|
197
313
|
isEnabled() {
|
|
198
314
|
if (this.options.enabled !== void 0) {
|
|
199
315
|
return this.options.enabled;
|
|
200
316
|
}
|
|
201
|
-
return
|
|
317
|
+
return sharedState().debugEnabled ?? false;
|
|
202
318
|
}
|
|
203
319
|
log(message, ...args) {
|
|
204
320
|
if (!this.isEnabled()) return;
|
|
@@ -210,66 +326,62 @@ var DebugLogger = class {
|
|
|
210
326
|
const prefix = this.options.prefix;
|
|
211
327
|
console.warn(`${prefix} ${message}`, ...args);
|
|
212
328
|
}
|
|
213
|
-
error(message, ...args) {
|
|
214
|
-
if (!this.isEnabled()) return;
|
|
215
|
-
const prefix = this.options.prefix;
|
|
216
|
-
console.error(`${prefix} ${message}`, ...args);
|
|
217
|
-
}
|
|
218
329
|
};
|
|
219
|
-
var globalDebugLogger = null;
|
|
220
330
|
function initDebugLogger(enabled = false) {
|
|
221
|
-
|
|
331
|
+
sharedState().debugEnabled = enabled;
|
|
222
332
|
}
|
|
223
333
|
function createScopedLogger(scopeName) {
|
|
224
334
|
return new DebugLogger({
|
|
225
335
|
prefix: `[Prepr][${scopeName}]`
|
|
226
336
|
});
|
|
227
337
|
}
|
|
228
|
-
function throttle(func, delay) {
|
|
229
|
-
let timeoutId = null;
|
|
230
|
-
let lastExecTime = 0;
|
|
231
|
-
const throttledFunc = ((...args) => {
|
|
232
|
-
const currentTime = Date.now();
|
|
233
|
-
const timeSinceLastExec = currentTime - lastExecTime;
|
|
234
|
-
if (timeSinceLastExec >= delay) {
|
|
235
|
-
func(...args);
|
|
236
|
-
lastExecTime = currentTime;
|
|
237
|
-
} else {
|
|
238
|
-
if (timeoutId) {
|
|
239
|
-
clearTimeout(timeoutId);
|
|
240
|
-
}
|
|
241
|
-
timeoutId = setTimeout(() => {
|
|
242
|
-
func(...args);
|
|
243
|
-
lastExecTime = Date.now();
|
|
244
|
-
timeoutId = null;
|
|
245
|
-
}, delay - timeSinceLastExec);
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
throttledFunc.cancel = () => {
|
|
249
|
-
if (timeoutId) {
|
|
250
|
-
clearTimeout(timeoutId);
|
|
251
|
-
timeoutId = null;
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
return throttledFunc;
|
|
255
|
-
}
|
|
256
|
-
function createElementCache(query, ttl = 1e3) {
|
|
257
|
-
let cache = null;
|
|
258
|
-
let lastCacheTime = 0;
|
|
259
|
-
return () => {
|
|
260
|
-
const now = Date.now();
|
|
261
|
-
if (!cache || now - lastCacheTime > ttl) {
|
|
262
|
-
cache = document.querySelectorAll(query);
|
|
263
|
-
lastCacheTime = now;
|
|
264
|
-
}
|
|
265
|
-
return cache;
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
338
|
|
|
269
339
|
// src/core/iframe-bridge.ts
|
|
340
|
+
var debug = createScopedLogger("iframe-bridge");
|
|
341
|
+
var MAX_REFERENCES = 500;
|
|
342
|
+
var MAX_HREF_LENGTH = 8192;
|
|
343
|
+
var MAX_ASSETS = 500;
|
|
344
|
+
var MAX_ASSET_KEY_LENGTH = 2048;
|
|
345
|
+
var MAX_ASSET_FIELD_LENGTH = 512;
|
|
346
|
+
function parseIds(value) {
|
|
347
|
+
if (!Array.isArray(value)) return void 0;
|
|
348
|
+
return value.slice(0, MAX_REFERENCES).filter((id) => typeof id === "string" && id.length > 0);
|
|
349
|
+
}
|
|
350
|
+
function parseReferences(value) {
|
|
351
|
+
if (!Array.isArray(value)) return void 0;
|
|
352
|
+
const list = [];
|
|
353
|
+
for (const entry of value.slice(0, MAX_REFERENCES)) {
|
|
354
|
+
const id = entry?.id;
|
|
355
|
+
const field = entry?.field;
|
|
356
|
+
if (typeof id === "string" && id && typeof field === "string" && field) {
|
|
357
|
+
list.push({ id, field });
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return list;
|
|
361
|
+
}
|
|
362
|
+
function boundedString(value, max) {
|
|
363
|
+
return typeof value === "string" && value && value.length <= max ? value : void 0;
|
|
364
|
+
}
|
|
365
|
+
function parseAssets(value) {
|
|
366
|
+
if (!Array.isArray(value)) return void 0;
|
|
367
|
+
const list = [];
|
|
368
|
+
for (const entry of value.slice(0, MAX_ASSETS)) {
|
|
369
|
+
if (!entry || typeof entry !== "object") continue;
|
|
370
|
+
const raw = entry;
|
|
371
|
+
const key = boundedString(raw.key, MAX_ASSET_KEY_LENGTH);
|
|
372
|
+
const field = boundedString(raw.field, MAX_ASSET_FIELD_LENGTH);
|
|
373
|
+
if (!key || !field) continue;
|
|
374
|
+
const entryId = boundedString(raw.entryId, MAX_ASSET_FIELD_LENGTH);
|
|
375
|
+
list.push(entryId ? { key, field, entryId } : { key, field });
|
|
376
|
+
}
|
|
377
|
+
return list;
|
|
378
|
+
}
|
|
270
379
|
var EDITOR_BASE_DOMAIN = "prepr.io";
|
|
271
380
|
function isAllowedEditorOrigin(origin, allowed) {
|
|
272
|
-
if (allowed)
|
|
381
|
+
if (allowed) {
|
|
382
|
+
if (allowed.includes("*")) return origin !== "null";
|
|
383
|
+
return allowed.includes(origin);
|
|
384
|
+
}
|
|
273
385
|
let url;
|
|
274
386
|
try {
|
|
275
387
|
url = new URL(origin);
|
|
@@ -284,6 +396,12 @@ function isAllowedEditorOrigin(origin, allowed) {
|
|
|
284
396
|
}
|
|
285
397
|
function createIframeBridge(store, options = {}) {
|
|
286
398
|
const allowedOrigins = options.allowedEditorOrigins;
|
|
399
|
+
const onScrollToField = options.onScrollToField;
|
|
400
|
+
const onHandshake = options.onHandshake;
|
|
401
|
+
const onReferences = options.onReferences;
|
|
402
|
+
const onAssets = options.onAssets;
|
|
403
|
+
const onAllowNavigation = options.onAllowNavigation;
|
|
404
|
+
const onItemChanged = options.onItemChanged;
|
|
287
405
|
let parentOrigin = null;
|
|
288
406
|
const onKeyDown = (event) => {
|
|
289
407
|
const key = event.key.toLowerCase();
|
|
@@ -291,9 +409,13 @@ function createIframeBridge(store, options = {}) {
|
|
|
291
409
|
if (blocked) event.preventDefault();
|
|
292
410
|
};
|
|
293
411
|
const onMessage = (evt) => {
|
|
412
|
+
if (evt.source !== window.parent) return;
|
|
294
413
|
const data = evt?.data;
|
|
295
|
-
if (data?.event ===
|
|
296
|
-
if (!isAllowedEditorOrigin(evt.origin, allowedOrigins))
|
|
414
|
+
if (data?.event === EVENT_INIT && !parentOrigin) {
|
|
415
|
+
if (!isAllowedEditorOrigin(evt.origin, allowedOrigins)) {
|
|
416
|
+
debug.warn("ignored editor handshake from origin", evt.origin);
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
297
419
|
parentOrigin = evt.origin;
|
|
298
420
|
setTrustedParentOrigin(parentOrigin);
|
|
299
421
|
if (data.scrollPosition != null) {
|
|
@@ -301,12 +423,84 @@ function createIframeBridge(store, options = {}) {
|
|
|
301
423
|
setTimeout(() => window.scrollTo(0, top), 1);
|
|
302
424
|
}
|
|
303
425
|
store?.set({ previewMode: true, editMode: data.editMode ?? true });
|
|
426
|
+
const itemId = typeof data.itemId === "string" && data.itemId ? data.itemId : void 0;
|
|
427
|
+
const referencedIds = parseReferences(data.referencedIds);
|
|
428
|
+
const componentIds = parseIds(data.componentIds);
|
|
429
|
+
const uiLocale = isLocale(data.uiLocale) ? data.uiLocale : void 0;
|
|
430
|
+
const navigationGuard = data.navigationGuard === true;
|
|
431
|
+
const assets = parseAssets(data.assets);
|
|
432
|
+
try {
|
|
433
|
+
onHandshake?.({
|
|
434
|
+
...itemId && { itemId },
|
|
435
|
+
...referencedIds && { referencedIds },
|
|
436
|
+
...componentIds && { componentIds },
|
|
437
|
+
...uiLocale && { uiLocale },
|
|
438
|
+
...navigationGuard && { navigationGuard },
|
|
439
|
+
...assets && { assets }
|
|
440
|
+
});
|
|
441
|
+
} catch (error) {
|
|
442
|
+
debug.warn("handshake handler failed", error);
|
|
443
|
+
}
|
|
304
444
|
}
|
|
305
445
|
if (!parentOrigin || evt.origin !== parentOrigin) return;
|
|
306
|
-
if (data?.event ===
|
|
446
|
+
if (data?.event === EVENT_REFERENCES) {
|
|
447
|
+
const assets = parseAssets(data.assets);
|
|
448
|
+
if (assets) {
|
|
449
|
+
try {
|
|
450
|
+
onAssets?.(assets);
|
|
451
|
+
} catch (error) {
|
|
452
|
+
debug.warn("assets handler failed", error);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
const referencedIds = parseReferences(data.referencedIds);
|
|
456
|
+
if (!referencedIds) return;
|
|
457
|
+
try {
|
|
458
|
+
onReferences?.(referencedIds, parseIds(data.componentIds));
|
|
459
|
+
} catch (error) {
|
|
460
|
+
debug.warn("references handler failed", error);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
if (data?.event === EVENT_GET_SCROLL_POSITION) {
|
|
307
464
|
const currentScrollY = window.scrollY || document.documentElement.scrollTop;
|
|
308
465
|
sendPreprEvent("getScrollPosition", { value: currentScrollY });
|
|
309
466
|
}
|
|
467
|
+
if (data?.event === EVENT_SCROLL_TO_FIELD) {
|
|
468
|
+
if (typeof data.field !== "string" || !data.field) return;
|
|
469
|
+
if (data.id !== void 0 && typeof data.id !== "string") return;
|
|
470
|
+
const block = typeof data.block === "number" && Number.isInteger(data.block) ? data.block : void 0;
|
|
471
|
+
const entryId = typeof data.entryId === "string" && data.entryId ? data.entryId : void 0;
|
|
472
|
+
const fieldById = typeof data.fieldById === "string" && data.fieldById ? data.fieldById : void 0;
|
|
473
|
+
try {
|
|
474
|
+
onScrollToField?.({
|
|
475
|
+
field: data.field,
|
|
476
|
+
id: data.id,
|
|
477
|
+
block,
|
|
478
|
+
entryId,
|
|
479
|
+
fieldById
|
|
480
|
+
});
|
|
481
|
+
} catch (error) {
|
|
482
|
+
debug.warn("scrollToField handler failed", error);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
if (data?.event === EVENT_ALLOW_NAVIGATION) {
|
|
486
|
+
const href = data.href;
|
|
487
|
+
if (typeof href !== "string" || !href || href.length > MAX_HREF_LENGTH) {
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
try {
|
|
491
|
+
onAllowNavigation?.(href);
|
|
492
|
+
} catch (error) {
|
|
493
|
+
debug.warn("allowNavigation handler failed", error);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
if (data?.event === EVENT_ITEM_CHANGED) {
|
|
497
|
+
if (typeof data.itemId !== "string" || !data.itemId) return;
|
|
498
|
+
try {
|
|
499
|
+
onItemChanged?.(data.itemId);
|
|
500
|
+
} catch (error) {
|
|
501
|
+
debug.warn("itemChanged handler failed", error);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
310
504
|
};
|
|
311
505
|
return {
|
|
312
506
|
start() {
|
|
@@ -331,7 +525,7 @@ import { vercelStegaSplit } from "@vercel/stega";
|
|
|
331
525
|
|
|
332
526
|
// src/core/stega/clean.ts
|
|
333
527
|
import { vercelStegaClean, vercelStegaDecode } from "@vercel/stega";
|
|
334
|
-
var
|
|
528
|
+
var debug2 = createScopedLogger("stega:clean");
|
|
335
529
|
function decodeStega(str) {
|
|
336
530
|
if (!str) return null;
|
|
337
531
|
try {
|
|
@@ -340,7 +534,7 @@ function decodeStega(str) {
|
|
|
340
534
|
return decoded;
|
|
341
535
|
}
|
|
342
536
|
} catch (error) {
|
|
343
|
-
|
|
537
|
+
debug2.log("error decoding stega data", error);
|
|
344
538
|
const match = str.match(/{"origin.*?}/);
|
|
345
539
|
if (match) {
|
|
346
540
|
try {
|
|
@@ -349,7 +543,7 @@ function decodeStega(str) {
|
|
|
349
543
|
return decodedMatch;
|
|
350
544
|
}
|
|
351
545
|
} catch (innerError) {
|
|
352
|
-
|
|
546
|
+
debug2.log("error decoding stega regex match", innerError);
|
|
353
547
|
}
|
|
354
548
|
}
|
|
355
549
|
}
|
|
@@ -358,6 +552,7 @@ function decodeStega(str) {
|
|
|
358
552
|
|
|
359
553
|
// src/core/stega/dom.ts
|
|
360
554
|
var IGNORED_ANCESTORS = "script, style, noscript";
|
|
555
|
+
var AUTO_ENTRY_ATTR = "data-prepr-entry-auto";
|
|
361
556
|
function isIgnoredTextNode(node) {
|
|
362
557
|
if (node.parentElement?.closest(IGNORED_ANCESTORS)) return true;
|
|
363
558
|
return !node.textContent?.trim();
|
|
@@ -385,64 +580,90 @@ function isRenderedElement(element) {
|
|
|
385
580
|
if (!style) return true;
|
|
386
581
|
return style.visibility !== "hidden" && style.display !== "none";
|
|
387
582
|
}
|
|
583
|
+
function parseEditHref(href) {
|
|
584
|
+
try {
|
|
585
|
+
const url = new URL(href, window.location.origin);
|
|
586
|
+
return {
|
|
587
|
+
id: url.pathname.split("/").pop() || void 0,
|
|
588
|
+
field: url.searchParams.get("field") || void 0,
|
|
589
|
+
locale: url.searchParams.get("locale") || void 0,
|
|
590
|
+
// Added by the toolkit's `annotateEditLinks`, not by Prepr.
|
|
591
|
+
entry: url.searchParams.get("entry") || void 0
|
|
592
|
+
};
|
|
593
|
+
} catch {
|
|
594
|
+
return {};
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
function setOrRemove(element, name, value) {
|
|
598
|
+
if (value) {
|
|
599
|
+
element.setAttribute(name, value);
|
|
600
|
+
} else {
|
|
601
|
+
element.removeAttribute(name);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
388
604
|
function tagEncodedElement(element, decoded) {
|
|
389
|
-
element
|
|
390
|
-
element.setAttribute("
|
|
605
|
+
if (isSiteTagged(element)) return false;
|
|
606
|
+
element.setAttribute(ATTR_ENCODED, "");
|
|
607
|
+
element.setAttribute(ATTR_HREF, decoded.href);
|
|
391
608
|
element.setAttribute("data-prepr-origin", decoded.origin);
|
|
609
|
+
const { id, field, locale, entry } = parseEditHref(decoded.href);
|
|
610
|
+
setOrRemove(element, ATTR_ID, id);
|
|
611
|
+
const fieldHint = element.getAttribute("data-prepr-edit-target")?.trim() || void 0;
|
|
612
|
+
setOrRemove(element, ATTR_FIELD, field ?? fieldHint);
|
|
613
|
+
setOrRemove(element, ATTR_LOCALE, locale);
|
|
614
|
+
const siteEntry = element.hasAttribute("data-prepr-entry-id") && !element.hasAttribute(AUTO_ENTRY_ATTR);
|
|
615
|
+
if (!siteEntry) {
|
|
616
|
+
setOrRemove(element, "data-prepr-entry-id", entry);
|
|
617
|
+
setOrRemove(element, AUTO_ENTRY_ATTR, entry && "true");
|
|
618
|
+
}
|
|
619
|
+
return true;
|
|
620
|
+
}
|
|
621
|
+
function isSiteTagged(element) {
|
|
622
|
+
return element.hasAttribute(ATTR_ENCODED) && !element.hasAttribute(ATTR_HREF);
|
|
623
|
+
}
|
|
624
|
+
function readEditPayload(element) {
|
|
625
|
+
return {
|
|
626
|
+
href: element.getAttribute(ATTR_HREF) ?? "",
|
|
627
|
+
origin: element.getAttribute("data-prepr-origin") ?? "",
|
|
628
|
+
id: element.getAttribute(ATTR_ID) ?? void 0,
|
|
629
|
+
field: element.getAttribute(ATTR_FIELD) ?? void 0,
|
|
630
|
+
locale: element.getAttribute(ATTR_LOCALE) ?? void 0,
|
|
631
|
+
entryId: element.getAttribute("data-prepr-entry-id") || void 0
|
|
632
|
+
};
|
|
392
633
|
}
|
|
393
634
|
|
|
394
635
|
// src/core/stega/auto-clean.ts
|
|
395
|
-
var
|
|
396
|
-
var
|
|
636
|
+
var debug3 = createScopedLogger("stega:auto-clean");
|
|
637
|
+
var cleanedNodes = /* @__PURE__ */ new WeakMap();
|
|
397
638
|
function createStegaAutoClean(options) {
|
|
398
639
|
const stripText = options?.enabled ?? true;
|
|
399
640
|
let observer = null;
|
|
400
641
|
let processing = false;
|
|
401
|
-
let cleaned = /* @__PURE__ */ new WeakMap();
|
|
402
642
|
let pendingHidden = /* @__PURE__ */ new Set();
|
|
403
643
|
let pendingDirty = /* @__PURE__ */ new Set();
|
|
404
644
|
let debounceTimeout = null;
|
|
405
|
-
const isHydrated = options?.isHydrated;
|
|
406
|
-
let pendingHydration = /* @__PURE__ */ new Set();
|
|
407
|
-
let hydrationTimeout = null;
|
|
408
|
-
function retryPendingHydration() {
|
|
409
|
-
hydrationTimeout = null;
|
|
410
|
-
processing = true;
|
|
411
|
-
const batch = [...pendingHydration];
|
|
412
|
-
pendingHydration.clear();
|
|
413
|
-
batch.forEach((textNode) => {
|
|
414
|
-
if (textNode.isConnected) cleanTextNode(textNode);
|
|
415
|
-
});
|
|
416
|
-
processing = false;
|
|
417
|
-
}
|
|
418
645
|
function cleanTextNode(textNode) {
|
|
419
646
|
if (isIgnoredTextNode(textNode)) return false;
|
|
420
|
-
if (isHydrated && !isHydrated(textNode)) {
|
|
421
|
-
pendingHydration.add(textNode);
|
|
422
|
-
hydrationTimeout ?? (hydrationTimeout = setTimeout(
|
|
423
|
-
retryPendingHydration,
|
|
424
|
-
HYDRATION_RETRY_MS
|
|
425
|
-
));
|
|
426
|
-
return false;
|
|
427
|
-
}
|
|
428
647
|
const textContent = textNode.textContent;
|
|
429
|
-
const info =
|
|
648
|
+
const info = cleanedNodes.get(textNode);
|
|
430
649
|
const settled = stripText ? info?.cleaned : info?.original;
|
|
431
650
|
if (info && textContent === settled) {
|
|
432
651
|
if (!info.decoded) return false;
|
|
433
652
|
const shown = resolveEditTarget(textNode);
|
|
434
|
-
if (!shown)
|
|
653
|
+
if (!shown) {
|
|
654
|
+
pendingHidden.add(textNode);
|
|
655
|
+
return false;
|
|
656
|
+
}
|
|
435
657
|
pendingHidden.delete(textNode);
|
|
436
|
-
if (shown.hasAttribute(
|
|
437
|
-
tagEncodedElement(shown, info.decoded);
|
|
438
|
-
return true;
|
|
658
|
+
if (shown.hasAttribute(ATTR_ENCODED)) return false;
|
|
659
|
+
return tagEncodedElement(shown, info.decoded);
|
|
439
660
|
}
|
|
440
661
|
try {
|
|
441
662
|
const { cleaned: stripped, encoded } = vercelStegaSplit(textContent);
|
|
442
663
|
if (!encoded || stripped === textContent) return false;
|
|
443
664
|
const decoded = decodeStega(textContent);
|
|
444
665
|
if (!decoded?.href && !stripText) return false;
|
|
445
|
-
|
|
666
|
+
cleanedNodes.set(textNode, {
|
|
446
667
|
original: textContent,
|
|
447
668
|
cleaned: stripped,
|
|
448
669
|
decoded: decoded?.href ? decoded : null
|
|
@@ -452,12 +673,11 @@ function createStegaAutoClean(options) {
|
|
|
452
673
|
const target = resolveEditTarget(textNode);
|
|
453
674
|
if (target) {
|
|
454
675
|
pendingHidden.delete(textNode);
|
|
455
|
-
tagEncodedElement(target, decoded);
|
|
456
|
-
return true;
|
|
676
|
+
return tagEncodedElement(target, decoded);
|
|
457
677
|
}
|
|
458
678
|
pendingHidden.add(textNode);
|
|
459
679
|
} catch (error) {
|
|
460
|
-
|
|
680
|
+
debug3.log("error cleaning text node", error);
|
|
461
681
|
}
|
|
462
682
|
return false;
|
|
463
683
|
}
|
|
@@ -484,7 +704,7 @@ function createStegaAutoClean(options) {
|
|
|
484
704
|
}
|
|
485
705
|
if (mutation.type === "characterData" && mutation.target.nodeType === Node.TEXT_NODE) {
|
|
486
706
|
const textNode = mutation.target;
|
|
487
|
-
const info =
|
|
707
|
+
const info = cleanedNodes.get(textNode);
|
|
488
708
|
const text = textNode.textContent ?? "";
|
|
489
709
|
const settled = stripText ? info?.cleaned : info?.original;
|
|
490
710
|
if (text !== settled && vercelStegaSplit(text).encoded) {
|
|
@@ -527,7 +747,16 @@ function createStegaAutoClean(options) {
|
|
|
527
747
|
retryPendingHidden();
|
|
528
748
|
}, 50);
|
|
529
749
|
}
|
|
750
|
+
let resizeTimeout = null;
|
|
751
|
+
function handleResize() {
|
|
752
|
+
if (pendingHidden.size === 0 || resizeTimeout) return;
|
|
753
|
+
resizeTimeout = setTimeout(() => {
|
|
754
|
+
resizeTimeout = null;
|
|
755
|
+
retryPendingHidden();
|
|
756
|
+
}, 100);
|
|
757
|
+
}
|
|
530
758
|
function setupObserver() {
|
|
759
|
+
window.addEventListener("resize", handleResize, { passive: true });
|
|
531
760
|
observer = new MutationObserver(handleMutations);
|
|
532
761
|
observer.observe(document.body, {
|
|
533
762
|
childList: true,
|
|
@@ -543,40 +772,471 @@ function createStegaAutoClean(options) {
|
|
|
543
772
|
if (observer || typeof window === "undefined") return;
|
|
544
773
|
scanAndClean();
|
|
545
774
|
setupObserver();
|
|
546
|
-
|
|
775
|
+
debug3.log("stega auto-clean started");
|
|
547
776
|
}
|
|
548
777
|
function stop() {
|
|
549
778
|
if (debounceTimeout) {
|
|
550
779
|
clearTimeout(debounceTimeout);
|
|
551
780
|
debounceTimeout = null;
|
|
552
781
|
}
|
|
553
|
-
if (
|
|
554
|
-
clearTimeout(
|
|
555
|
-
|
|
782
|
+
if (resizeTimeout) {
|
|
783
|
+
clearTimeout(resizeTimeout);
|
|
784
|
+
resizeTimeout = null;
|
|
556
785
|
}
|
|
557
786
|
if (observer) {
|
|
558
787
|
observer.disconnect();
|
|
559
788
|
observer = null;
|
|
789
|
+
window.removeEventListener("resize", handleResize);
|
|
560
790
|
}
|
|
561
|
-
cleaned = /* @__PURE__ */ new WeakMap();
|
|
562
791
|
pendingHidden = /* @__PURE__ */ new Set();
|
|
563
792
|
pendingDirty = /* @__PURE__ */ new Set();
|
|
564
|
-
|
|
565
|
-
debug2.log("stega auto-clean stopped");
|
|
793
|
+
debug3.log("stega auto-clean stopped");
|
|
566
794
|
}
|
|
567
795
|
return { start, stop };
|
|
568
796
|
}
|
|
569
797
|
|
|
798
|
+
// src/core/visual-editor/overlay.ts
|
|
799
|
+
var HOST_TAG = "prepr-visual-editor";
|
|
800
|
+
var SCROLL_SETTLE_MS = 120;
|
|
801
|
+
var LABEL_SPACE_PX = 22;
|
|
802
|
+
var BOX_PADDING_PX = 3;
|
|
803
|
+
var LABEL_MARGIN_PX = 4;
|
|
804
|
+
var PROBE_POINTS = [
|
|
805
|
+
[0.5, 0.5],
|
|
806
|
+
[0.15, 0.2],
|
|
807
|
+
[0.85, 0.2],
|
|
808
|
+
[0.15, 0.8],
|
|
809
|
+
[0.85, 0.8]
|
|
810
|
+
];
|
|
811
|
+
function overlapsBox(area, rect) {
|
|
812
|
+
return area.left < rect.right + BOX_PADDING_PX && area.right > rect.left - BOX_PADDING_PX && area.top < rect.bottom + BOX_PADDING_PX && area.bottom > rect.top - BOX_PADDING_PX;
|
|
813
|
+
}
|
|
814
|
+
function overlaps(a2, b2) {
|
|
815
|
+
return a2.left < b2.right && b2.left < a2.right && a2.top < b2.bottom && b2.top < a2.bottom;
|
|
816
|
+
}
|
|
817
|
+
function coverOf(hit, target, x2, y2) {
|
|
818
|
+
let cover = hit.getBoundingClientRect();
|
|
819
|
+
for (let el = hit.parentElement; el && !el.contains(target) && el !== document.body; el = el.parentElement) {
|
|
820
|
+
const r2 = el.getBoundingClientRect();
|
|
821
|
+
if (x2 < r2.left || x2 >= r2.right || y2 < r2.top || y2 >= r2.bottom) break;
|
|
822
|
+
cover = r2;
|
|
823
|
+
}
|
|
824
|
+
return cover;
|
|
825
|
+
}
|
|
826
|
+
function mergeAreas(areas) {
|
|
827
|
+
const merged = areas.slice();
|
|
828
|
+
for (let i2 = 0; i2 < merged.length; i2++) {
|
|
829
|
+
for (let j2 = i2 + 1; j2 < merged.length; j2++) {
|
|
830
|
+
if (!overlaps(merged[i2], merged[j2])) continue;
|
|
831
|
+
merged[i2] = {
|
|
832
|
+
left: Math.min(merged[i2].left, merged[j2].left),
|
|
833
|
+
top: Math.min(merged[i2].top, merged[j2].top),
|
|
834
|
+
right: Math.max(merged[i2].right, merged[j2].right),
|
|
835
|
+
bottom: Math.max(merged[i2].bottom, merged[j2].bottom)
|
|
836
|
+
};
|
|
837
|
+
merged.splice(j2, 1);
|
|
838
|
+
j2 = i2;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
return merged;
|
|
842
|
+
}
|
|
843
|
+
function findCovers(target, rect) {
|
|
844
|
+
const width = window.innerWidth;
|
|
845
|
+
const height = window.innerHeight;
|
|
846
|
+
const covers = [];
|
|
847
|
+
const seen = /* @__PURE__ */ new Set();
|
|
848
|
+
let probed = false;
|
|
849
|
+
let reached = false;
|
|
850
|
+
for (const [fx, fy] of PROBE_POINTS) {
|
|
851
|
+
const x2 = rect.left + rect.width * fx;
|
|
852
|
+
const y2 = rect.top + rect.height * fy;
|
|
853
|
+
if (x2 < 0 || y2 < 0 || x2 >= width || y2 >= height) continue;
|
|
854
|
+
probed = true;
|
|
855
|
+
const hit = document.elementFromPoint(x2, y2);
|
|
856
|
+
if (!hit || hit === target || target.contains(hit)) {
|
|
857
|
+
reached = true;
|
|
858
|
+
continue;
|
|
859
|
+
}
|
|
860
|
+
if (seen.has(hit)) continue;
|
|
861
|
+
seen.add(hit);
|
|
862
|
+
if (covers.some(
|
|
863
|
+
(c2) => x2 >= c2.left && x2 < c2.right && y2 >= c2.top && y2 < c2.bottom
|
|
864
|
+
)) {
|
|
865
|
+
continue;
|
|
866
|
+
}
|
|
867
|
+
covers.push(coverOf(hit, target, x2, y2));
|
|
868
|
+
}
|
|
869
|
+
if (!probed) return [];
|
|
870
|
+
return reached ? mergeAreas(covers) : null;
|
|
871
|
+
}
|
|
872
|
+
function clipPath(x2, y2, covers) {
|
|
873
|
+
const far = 1e5;
|
|
874
|
+
const points = [
|
|
875
|
+
`${-far}px ${-far}px`,
|
|
876
|
+
`${far}px ${-far}px`,
|
|
877
|
+
`${far}px ${far}px`,
|
|
878
|
+
`${-far}px ${far}px`,
|
|
879
|
+
`${-far}px ${-far}px`
|
|
880
|
+
];
|
|
881
|
+
for (const c2 of covers) {
|
|
882
|
+
const l2 = c2.left - x2;
|
|
883
|
+
const t3 = c2.top - y2;
|
|
884
|
+
const r2 = c2.right - x2;
|
|
885
|
+
const b2 = c2.bottom - y2;
|
|
886
|
+
points.push(
|
|
887
|
+
`${l2}px ${t3}px`,
|
|
888
|
+
`${r2}px ${t3}px`,
|
|
889
|
+
`${r2}px ${b2}px`,
|
|
890
|
+
`${l2}px ${b2}px`,
|
|
891
|
+
`${l2}px ${t3}px`,
|
|
892
|
+
`${-far}px ${-far}px`
|
|
893
|
+
);
|
|
894
|
+
}
|
|
895
|
+
return `polygon(evenodd, ${points.join(", ")})`;
|
|
896
|
+
}
|
|
897
|
+
var STYLES = `
|
|
898
|
+
:host {
|
|
899
|
+
all: initial;
|
|
900
|
+
position: fixed;
|
|
901
|
+
inset: 0;
|
|
902
|
+
pointer-events: none;
|
|
903
|
+
z-index: 2147483646;
|
|
904
|
+
contain: strict;
|
|
905
|
+
}
|
|
906
|
+
.box {
|
|
907
|
+
position: absolute;
|
|
908
|
+
top: 0;
|
|
909
|
+
left: 0;
|
|
910
|
+
box-sizing: border-box;
|
|
911
|
+
border-radius: 6px;
|
|
912
|
+
opacity: 0;
|
|
913
|
+
will-change: transform, width, height;
|
|
914
|
+
transition:
|
|
915
|
+
transform 180ms cubic-bezier(0.2, 0.8, 0.2, 1),
|
|
916
|
+
width 180ms cubic-bezier(0.2, 0.8, 0.2, 1),
|
|
917
|
+
height 180ms cubic-bezier(0.2, 0.8, 0.2, 1),
|
|
918
|
+
opacity 140ms ease;
|
|
919
|
+
}
|
|
920
|
+
.box[data-visible] { opacity: 1; }
|
|
921
|
+
.box[data-instant], :host([data-scrolling]) .box {
|
|
922
|
+
transition: opacity 140ms ease;
|
|
923
|
+
}
|
|
924
|
+
.hover {
|
|
925
|
+
border: 1.5px solid rgba(79, 70, 229, 0.9);
|
|
926
|
+
background: rgba(79, 70, 229, 0.06);
|
|
927
|
+
}
|
|
928
|
+
.selected {
|
|
929
|
+
border: 2px solid #4f46e5;
|
|
930
|
+
box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.18);
|
|
931
|
+
}
|
|
932
|
+
.label {
|
|
933
|
+
position: absolute;
|
|
934
|
+
left: -2px;
|
|
935
|
+
bottom: 100%;
|
|
936
|
+
margin-bottom: 4px;
|
|
937
|
+
padding: 3px 7px;
|
|
938
|
+
border-radius: 5px;
|
|
939
|
+
background: #4f46e5;
|
|
940
|
+
color: #fff;
|
|
941
|
+
font: 500 11px/1.3 ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
|
|
942
|
+
letter-spacing: 0.01em;
|
|
943
|
+
white-space: nowrap;
|
|
944
|
+
display: flex;
|
|
945
|
+
max-width: 240px;
|
|
946
|
+
box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
|
|
947
|
+
}
|
|
948
|
+
.text {
|
|
949
|
+
min-width: 0;
|
|
950
|
+
overflow: hidden;
|
|
951
|
+
text-overflow: ellipsis;
|
|
952
|
+
}
|
|
953
|
+
.hover .label { background: rgba(79, 70, 229, 0.92); }
|
|
954
|
+
/* Content of another item than the one open in the editor: still clickable,
|
|
955
|
+
but visibly not part of the item being edited. */
|
|
956
|
+
.hover[data-item-kind='other'] {
|
|
957
|
+
border: 1.5px dashed #a5b4fc;
|
|
958
|
+
background: rgba(100, 116, 139, 0.05);
|
|
959
|
+
}
|
|
960
|
+
.hover[data-item-kind='other'] .label { background: #64748b; }
|
|
961
|
+
.hover[data-item-kind='referenced'] {
|
|
962
|
+
border: 1.5px solid #a5b4fc;
|
|
963
|
+
background: rgba(79, 70, 229, 0.03);
|
|
964
|
+
}
|
|
965
|
+
.hover[data-item-kind='referenced'] .label { background: #818cf8; }
|
|
966
|
+
.box[data-label-covered] .label { visibility: hidden; }
|
|
967
|
+
.box[data-label-inside] .label {
|
|
968
|
+
bottom: auto;
|
|
969
|
+
top: 2px;
|
|
970
|
+
left: 2px;
|
|
971
|
+
margin: 0;
|
|
972
|
+
}
|
|
973
|
+
/* A clickable hover label (edit mode on the live site). Only while shown, so
|
|
974
|
+
a fading box never leaves an invisible click target behind. */
|
|
975
|
+
:host([data-label-action]) .hover[data-visible] .label {
|
|
976
|
+
pointer-events: auto;
|
|
977
|
+
cursor: pointer;
|
|
978
|
+
}
|
|
979
|
+
:host([data-label-action]) .hover .label::after {
|
|
980
|
+
content: '\\2197';
|
|
981
|
+
margin-left: 5px;
|
|
982
|
+
}
|
|
983
|
+
:host([data-label-action]) .hover .label:hover { background: #4338ca; }
|
|
984
|
+
/* Bridges the gap between the label and its element, so the pointer can
|
|
985
|
+
travel from one to the other without the hover ending on the way. */
|
|
986
|
+
:host([data-label-action]) .hover .label::before {
|
|
987
|
+
content: '';
|
|
988
|
+
position: absolute;
|
|
989
|
+
left: 0;
|
|
990
|
+
right: 0;
|
|
991
|
+
top: 100%;
|
|
992
|
+
height: ${LABEL_MARGIN_PX + BOX_PADDING_PX + 2}px;
|
|
993
|
+
}
|
|
994
|
+
@media (prefers-reduced-motion: reduce) {
|
|
995
|
+
.box { transition: opacity 80ms linear; }
|
|
996
|
+
}
|
|
997
|
+
`;
|
|
998
|
+
var VisualEditorOverlay = class {
|
|
999
|
+
constructor(options = {}) {
|
|
1000
|
+
this.host = null;
|
|
1001
|
+
this.hoverBox = null;
|
|
1002
|
+
this.selectedBox = null;
|
|
1003
|
+
this.frame = null;
|
|
1004
|
+
this.scrollTimeout = null;
|
|
1005
|
+
this.resizeObserver = null;
|
|
1006
|
+
this.onLabelClick = options.onLabelClick;
|
|
1007
|
+
}
|
|
1008
|
+
mount() {
|
|
1009
|
+
if (this.host) return;
|
|
1010
|
+
const host = document.createElement(HOST_TAG);
|
|
1011
|
+
const shadow = host.attachShadow({ mode: "open" });
|
|
1012
|
+
const style = document.createElement("style");
|
|
1013
|
+
style.textContent = STYLES;
|
|
1014
|
+
shadow.appendChild(style);
|
|
1015
|
+
this.hoverBox = this.createBox(shadow, "hover");
|
|
1016
|
+
this.selectedBox = this.createBox(shadow, "selected");
|
|
1017
|
+
const onLabelClick = this.onLabelClick;
|
|
1018
|
+
if (onLabelClick) {
|
|
1019
|
+
host.setAttribute("data-label-action", "");
|
|
1020
|
+
const hoverBox = this.hoverBox;
|
|
1021
|
+
hoverBox.label.addEventListener("click", () => {
|
|
1022
|
+
if (hoverBox.target) onLabelClick(hoverBox.target);
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
document.documentElement.appendChild(host);
|
|
1026
|
+
this.host = host;
|
|
1027
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
1028
|
+
this.resizeObserver = new ResizeObserver(() => this.schedule());
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
unmount() {
|
|
1032
|
+
if (this.frame !== null) cancelAnimationFrame(this.frame);
|
|
1033
|
+
if (this.scrollTimeout) clearTimeout(this.scrollTimeout);
|
|
1034
|
+
this.frame = null;
|
|
1035
|
+
this.scrollTimeout = null;
|
|
1036
|
+
this.resizeObserver?.disconnect();
|
|
1037
|
+
this.resizeObserver = null;
|
|
1038
|
+
this.host?.remove();
|
|
1039
|
+
this.host = null;
|
|
1040
|
+
this.hoverBox = null;
|
|
1041
|
+
this.selectedBox = null;
|
|
1042
|
+
}
|
|
1043
|
+
/**
|
|
1044
|
+
* Whether a pointer event target is this chrome: events from inside the
|
|
1045
|
+
* shadow root reach the page retargeted to its host.
|
|
1046
|
+
*/
|
|
1047
|
+
owns(node) {
|
|
1048
|
+
return node !== null && node === this.host;
|
|
1049
|
+
}
|
|
1050
|
+
getHoverTarget() {
|
|
1051
|
+
return this.hoverBox?.target ?? null;
|
|
1052
|
+
}
|
|
1053
|
+
getSelectedTarget() {
|
|
1054
|
+
return this.selectedBox?.target ?? null;
|
|
1055
|
+
}
|
|
1056
|
+
setHover(target, label, options = {}) {
|
|
1057
|
+
if (target) {
|
|
1058
|
+
this.hoverBox?.root.setAttribute(
|
|
1059
|
+
"data-item-kind",
|
|
1060
|
+
options.kind ?? "current"
|
|
1061
|
+
);
|
|
1062
|
+
}
|
|
1063
|
+
this.retarget(this.hoverBox, target, label);
|
|
1064
|
+
}
|
|
1065
|
+
setSelected(target, label) {
|
|
1066
|
+
this.retarget(this.selectedBox, target, label);
|
|
1067
|
+
}
|
|
1068
|
+
/** Call on every scroll; positions follow in the next frame, untransitioned. */
|
|
1069
|
+
onScroll() {
|
|
1070
|
+
if (!this.host) return;
|
|
1071
|
+
this.host.setAttribute("data-scrolling", "");
|
|
1072
|
+
if (this.scrollTimeout) clearTimeout(this.scrollTimeout);
|
|
1073
|
+
this.scrollTimeout = setTimeout(() => {
|
|
1074
|
+
this.host?.removeAttribute("data-scrolling");
|
|
1075
|
+
this.scrollTimeout = null;
|
|
1076
|
+
}, SCROLL_SETTLE_MS);
|
|
1077
|
+
this.schedule();
|
|
1078
|
+
}
|
|
1079
|
+
/** Re-measure both boxes in the next animation frame. */
|
|
1080
|
+
schedule() {
|
|
1081
|
+
if (this.frame !== null || !this.host) return;
|
|
1082
|
+
this.frame = requestAnimationFrame(() => {
|
|
1083
|
+
this.frame = null;
|
|
1084
|
+
this.render();
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
createBox(shadow, kind) {
|
|
1088
|
+
const root = document.createElement("div");
|
|
1089
|
+
root.className = `box ${kind}`;
|
|
1090
|
+
const label = document.createElement("div");
|
|
1091
|
+
label.className = "label";
|
|
1092
|
+
const text = document.createElement("span");
|
|
1093
|
+
text.className = "text";
|
|
1094
|
+
label.appendChild(text);
|
|
1095
|
+
root.appendChild(label);
|
|
1096
|
+
shadow.appendChild(root);
|
|
1097
|
+
return { root, label, text, target: null };
|
|
1098
|
+
}
|
|
1099
|
+
retarget(box, target, label) {
|
|
1100
|
+
if (!box || box.target === target) return;
|
|
1101
|
+
const previous = box.target;
|
|
1102
|
+
if (previous) this.resizeObserver?.unobserve(previous);
|
|
1103
|
+
box.target = target;
|
|
1104
|
+
if (target) {
|
|
1105
|
+
this.resizeObserver?.observe(target);
|
|
1106
|
+
box.text.textContent = label;
|
|
1107
|
+
if (!box.root.hasAttribute("data-visible")) {
|
|
1108
|
+
box.root.setAttribute("data-instant", "");
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
this.schedule();
|
|
1112
|
+
}
|
|
1113
|
+
render() {
|
|
1114
|
+
const hover = this.hoverBox ? this.measure(this.hoverBox) : null;
|
|
1115
|
+
const selected = this.selectedBox ? this.measure(this.selectedBox) : null;
|
|
1116
|
+
if (this.hoverBox) this.paint(this.hoverBox, hover, selected);
|
|
1117
|
+
if (this.selectedBox) this.paint(this.selectedBox, selected, hover);
|
|
1118
|
+
}
|
|
1119
|
+
measure(box) {
|
|
1120
|
+
const target = box.target;
|
|
1121
|
+
if (!target) return null;
|
|
1122
|
+
if (!target.isConnected) {
|
|
1123
|
+
this.resizeObserver?.unobserve(target);
|
|
1124
|
+
box.target = null;
|
|
1125
|
+
return null;
|
|
1126
|
+
}
|
|
1127
|
+
const rect = target.getBoundingClientRect();
|
|
1128
|
+
if (rect.width === 0 && rect.height === 0) return null;
|
|
1129
|
+
const covers = findCovers(target, rect);
|
|
1130
|
+
if (!covers) return null;
|
|
1131
|
+
return {
|
|
1132
|
+
rect,
|
|
1133
|
+
covers,
|
|
1134
|
+
labelWidth: covers.length ? box.label.offsetWidth : 0,
|
|
1135
|
+
labelHeight: covers.length ? box.label.offsetHeight : 0
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
paint(box, measurement, other = null) {
|
|
1139
|
+
const root = box.root;
|
|
1140
|
+
if (!measurement) {
|
|
1141
|
+
root.removeAttribute("data-visible");
|
|
1142
|
+
return;
|
|
1143
|
+
}
|
|
1144
|
+
const { rect, covers } = measurement;
|
|
1145
|
+
const x2 = rect.left - BOX_PADDING_PX;
|
|
1146
|
+
const y2 = rect.top - BOX_PADDING_PX;
|
|
1147
|
+
const labelAbove = {
|
|
1148
|
+
left: x2 - 2,
|
|
1149
|
+
top: y2 - LABEL_SPACE_PX,
|
|
1150
|
+
right: x2 - 2 + (measurement.labelWidth || Math.min(240, rect.width)),
|
|
1151
|
+
bottom: y2
|
|
1152
|
+
};
|
|
1153
|
+
const labelInside = y2 < LABEL_SPACE_PX || other !== null && other.rect !== rect && overlapsBox(labelAbove, other.rect);
|
|
1154
|
+
root.style.transform = `translate3d(${x2}px, ${y2}px, 0)`;
|
|
1155
|
+
root.style.width = `${rect.width + BOX_PADDING_PX * 2}px`;
|
|
1156
|
+
root.style.height = `${rect.height + BOX_PADDING_PX * 2}px`;
|
|
1157
|
+
root.toggleAttribute("data-label-inside", labelInside);
|
|
1158
|
+
root.style.clipPath = covers.length ? clipPath(x2, y2, covers) : "";
|
|
1159
|
+
const labelLeft = labelInside ? x2 + 2 : x2 - 2;
|
|
1160
|
+
const labelTop = labelInside ? y2 + 2 : y2 - LABEL_MARGIN_PX - measurement.labelHeight;
|
|
1161
|
+
const label = {
|
|
1162
|
+
left: labelLeft,
|
|
1163
|
+
top: labelTop,
|
|
1164
|
+
right: labelLeft + measurement.labelWidth,
|
|
1165
|
+
bottom: labelTop + measurement.labelHeight
|
|
1166
|
+
};
|
|
1167
|
+
root.toggleAttribute(
|
|
1168
|
+
"data-label-covered",
|
|
1169
|
+
covers.some((c2) => overlaps(c2, label))
|
|
1170
|
+
);
|
|
1171
|
+
if (root.hasAttribute("data-instant")) {
|
|
1172
|
+
root.setAttribute("data-visible", "");
|
|
1173
|
+
requestAnimationFrame(() => root.removeAttribute("data-instant"));
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1176
|
+
root.setAttribute("data-visible", "");
|
|
1177
|
+
}
|
|
1178
|
+
};
|
|
1179
|
+
|
|
1180
|
+
// src/core/visual-editor/field-path.ts
|
|
1181
|
+
var INDEX_SEGMENT = /^\d+$/;
|
|
1182
|
+
var WORD_SEPARATORS = /[_-]+/g;
|
|
1183
|
+
function normalizeFieldPath(path) {
|
|
1184
|
+
return path.split(".").map(
|
|
1185
|
+
(segment) => INDEX_SEGMENT.test(segment) ? String(Number.parseInt(segment, 10)) : segment
|
|
1186
|
+
).join(".");
|
|
1187
|
+
}
|
|
1188
|
+
var GENERIC_LEAVES = /* @__PURE__ */ new Set(["value", "text", "body", "content", "label"]);
|
|
1189
|
+
function humanize(name) {
|
|
1190
|
+
const words = name.replace(WORD_SEPARATORS, " ").trim();
|
|
1191
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
1192
|
+
}
|
|
1193
|
+
function fieldLabel(path, locale = "en") {
|
|
1194
|
+
if (!path) return t("visualEditor.edit", locale);
|
|
1195
|
+
const segments = path.split(".").filter((s2) => s2 && s2 !== "items" && !INDEX_SEGMENT.test(s2));
|
|
1196
|
+
const name = segments[segments.length - 1];
|
|
1197
|
+
if (!name) return t("visualEditor.edit", locale);
|
|
1198
|
+
const parent = segments[segments.length - 2];
|
|
1199
|
+
if (parent && GENERIC_LEAVES.has(name)) {
|
|
1200
|
+
return `${humanize(parent)} \u203A ${humanize(name)}`;
|
|
1201
|
+
}
|
|
1202
|
+
return humanize(name);
|
|
1203
|
+
}
|
|
1204
|
+
function findFieldElement(lookup) {
|
|
1205
|
+
if (!lookup.field) return null;
|
|
1206
|
+
const candidates = document.querySelectorAll(ENCODED_SELECTOR);
|
|
1207
|
+
if (lookup.entryId) {
|
|
1208
|
+
for (const candidate of candidates) {
|
|
1209
|
+
if (candidate.getAttribute("data-prepr-entry-id") === lookup.entryId) {
|
|
1210
|
+
return candidate;
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
for (const path of [lookup.field, lookup.fieldById]) {
|
|
1215
|
+
if (!path) continue;
|
|
1216
|
+
const wanted = normalizeFieldPath(path);
|
|
1217
|
+
for (const candidate of candidates) {
|
|
1218
|
+
const field = candidate.getAttribute(ATTR_FIELD);
|
|
1219
|
+
if (!field || normalizeFieldPath(field) !== wanted) continue;
|
|
1220
|
+
if (lookup.id && candidate.getAttribute(ATTR_ID) !== lookup.id) {
|
|
1221
|
+
continue;
|
|
1222
|
+
}
|
|
1223
|
+
return candidate;
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
return null;
|
|
1227
|
+
}
|
|
1228
|
+
|
|
570
1229
|
// src/core/stega/elements.ts
|
|
571
|
-
var
|
|
1230
|
+
var debug4 = createScopedLogger("stega:elements");
|
|
572
1231
|
var StegaElements = class {
|
|
573
1232
|
constructor(decode = decodeStega) {
|
|
574
1233
|
this.observer = null;
|
|
1234
|
+
this.rescanTimer = null;
|
|
575
1235
|
this.decode = decode;
|
|
576
1236
|
}
|
|
577
1237
|
getElements() {
|
|
578
1238
|
if (!this.elements) {
|
|
579
|
-
this.elements = document.querySelectorAll(
|
|
1239
|
+
this.elements = document.querySelectorAll(ENCODED_SELECTOR);
|
|
580
1240
|
}
|
|
581
1241
|
return this.elements;
|
|
582
1242
|
}
|
|
@@ -585,7 +1245,7 @@ var StegaElements = class {
|
|
|
585
1245
|
const decoded = this.decode(node.textContent);
|
|
586
1246
|
if (!decoded?.href) return false;
|
|
587
1247
|
const target = resolveEditTarget(node);
|
|
588
|
-
if (!target || target.hasAttribute(
|
|
1248
|
+
if (!target || target.hasAttribute(ATTR_ENCODED)) return false;
|
|
589
1249
|
tagEncodedElement(target, decoded);
|
|
590
1250
|
return true;
|
|
591
1251
|
}
|
|
@@ -603,7 +1263,7 @@ var StegaElements = class {
|
|
|
603
1263
|
*/
|
|
604
1264
|
scanDocument(skipIfTagged = false) {
|
|
605
1265
|
if (skipIfTagged) {
|
|
606
|
-
const existing = document.querySelectorAll(
|
|
1266
|
+
const existing = document.querySelectorAll(ENCODED_SELECTOR);
|
|
607
1267
|
if (existing.length > 0) {
|
|
608
1268
|
this.elements = existing;
|
|
609
1269
|
return;
|
|
@@ -613,16 +1273,13 @@ var StegaElements = class {
|
|
|
613
1273
|
walkTextNodes(document.body, (textNode) => {
|
|
614
1274
|
if (this.tagFromTextNode(textNode)) encodedCount++;
|
|
615
1275
|
});
|
|
616
|
-
|
|
617
|
-
this.elements = document.querySelectorAll(
|
|
1276
|
+
debug4.log("document scan complete, encoded", encodedCount, "elements");
|
|
1277
|
+
this.elements = document.querySelectorAll(ENCODED_SELECTOR);
|
|
618
1278
|
}
|
|
619
1279
|
/** `onUpdate` fires after each debounced batch, for refreshing derived state. */
|
|
620
1280
|
setupMutationObserver(onUpdate) {
|
|
621
|
-
|
|
622
|
-
this.observer.disconnect();
|
|
623
|
-
}
|
|
1281
|
+
this.disconnectObserver();
|
|
624
1282
|
let pending = [];
|
|
625
|
-
let debounceTimeout = null;
|
|
626
1283
|
const processMutations = () => {
|
|
627
1284
|
const addedNodes = /* @__PURE__ */ new Set();
|
|
628
1285
|
pending.forEach((mutation) => {
|
|
@@ -638,13 +1295,13 @@ var StegaElements = class {
|
|
|
638
1295
|
if (node.isConnected) this.scanNode(node);
|
|
639
1296
|
});
|
|
640
1297
|
pending = [];
|
|
641
|
-
this.elements = document.querySelectorAll(
|
|
1298
|
+
this.elements = document.querySelectorAll(ENCODED_SELECTOR);
|
|
642
1299
|
onUpdate?.();
|
|
643
1300
|
};
|
|
644
1301
|
this.observer = new MutationObserver((mutations) => {
|
|
645
1302
|
pending.push(...mutations);
|
|
646
|
-
if (
|
|
647
|
-
|
|
1303
|
+
if (this.rescanTimer) clearTimeout(this.rescanTimer);
|
|
1304
|
+
this.rescanTimer = setTimeout(processMutations, 100);
|
|
648
1305
|
});
|
|
649
1306
|
this.observer.observe(document.body, {
|
|
650
1307
|
childList: true,
|
|
@@ -656,231 +1313,27 @@ var StegaElements = class {
|
|
|
656
1313
|
attributeFilter: ["class", "style", "hidden", "open", "aria-expanded"]
|
|
657
1314
|
});
|
|
658
1315
|
}
|
|
659
|
-
/**
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
this.observer = null;
|
|
667
|
-
}
|
|
668
|
-
document.querySelectorAll("[data-prepr-encoded]").forEach((element) => {
|
|
669
|
-
element.removeAttribute("data-prepr-encoded");
|
|
670
|
-
element.removeAttribute("data-prepr-href");
|
|
671
|
-
element.removeAttribute("data-prepr-origin");
|
|
672
|
-
element.classList.remove("prepr-overlay-active");
|
|
673
|
-
});
|
|
1316
|
+
/**
|
|
1317
|
+
* Stops watching for new content. Tags stay on their elements: the page's
|
|
1318
|
+
* stega characters are stripped once they are read, so a tag removed here
|
|
1319
|
+
* could never be rebuilt when edit mode is turned back on.
|
|
1320
|
+
*/
|
|
1321
|
+
disconnect() {
|
|
1322
|
+
this.disconnectObserver();
|
|
674
1323
|
this.elements = void 0;
|
|
675
1324
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
var StegaOverlay = class {
|
|
681
|
-
constructor(onEdit) {
|
|
682
|
-
this.overlay = null;
|
|
683
|
-
this.tooltip = null;
|
|
684
|
-
this.hideTimeout = null;
|
|
685
|
-
this.currentElement = null;
|
|
686
|
-
this.onEdit = onEdit;
|
|
687
|
-
}
|
|
688
|
-
create() {
|
|
689
|
-
const overlay = document.createElement("div");
|
|
690
|
-
overlay.className = "prepr-overlay";
|
|
691
|
-
overlay.style.display = "none";
|
|
692
|
-
const tooltip = document.createElement("div");
|
|
693
|
-
tooltip.className = "prepr-tooltip";
|
|
694
|
-
tooltip.style.display = "none";
|
|
695
|
-
document.body.appendChild(overlay);
|
|
696
|
-
document.body.appendChild(tooltip);
|
|
697
|
-
this.overlay = overlay;
|
|
698
|
-
this.tooltip = tooltip;
|
|
699
|
-
return { overlay, tooltip };
|
|
700
|
-
}
|
|
701
|
-
getTooltip() {
|
|
702
|
-
return this.tooltip;
|
|
703
|
-
}
|
|
704
|
-
hasCurrentElement() {
|
|
705
|
-
return this.currentElement !== null;
|
|
706
|
-
}
|
|
707
|
-
clearHideTimeout() {
|
|
708
|
-
if (this.hideTimeout) {
|
|
709
|
-
clearTimeout(this.hideTimeout);
|
|
710
|
-
this.hideTimeout = null;
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
show(element) {
|
|
714
|
-
if (!this.overlay || !this.tooltip) return;
|
|
715
|
-
this.clearHideTimeout();
|
|
716
|
-
if (this.currentElement && this.currentElement !== element) {
|
|
717
|
-
this.currentElement.classList.remove("prepr-overlay-active");
|
|
718
|
-
}
|
|
719
|
-
const rect = element.getBoundingClientRect();
|
|
720
|
-
const href = element.getAttribute("data-prepr-href");
|
|
721
|
-
const origin = element.getAttribute("data-prepr-origin");
|
|
722
|
-
const id = element.getAttribute("data-prepr-id") ?? void 0;
|
|
723
|
-
const field = element.getAttribute("data-prepr-field") ?? void 0;
|
|
724
|
-
debug4.log("showing overlay", { href, origin });
|
|
725
|
-
const overlay = this.overlay;
|
|
726
|
-
overlay.style.display = "block";
|
|
727
|
-
overlay.style.top = `${rect.top + window.scrollY - 2}px`;
|
|
728
|
-
overlay.style.left = `${rect.left + window.scrollX - 4}px`;
|
|
729
|
-
overlay.style.width = `${rect.width + 8}px`;
|
|
730
|
-
overlay.style.height = `${rect.height + 4}px`;
|
|
731
|
-
const tooltip = this.tooltip;
|
|
732
|
-
if (href && origin) {
|
|
733
|
-
const MIN_WIDTH_FOR_TEXT = 80;
|
|
734
|
-
const isCompact = rect.width < MIN_WIDTH_FOR_TEXT;
|
|
735
|
-
tooltip.textContent = isCompact ? "\u2197" : `${origin} \u2197`;
|
|
736
|
-
tooltip.style.display = "block";
|
|
737
|
-
tooltip.style.minWidth = isCompact ? "auto" : "80px";
|
|
738
|
-
requestAnimationFrame(() => {
|
|
739
|
-
let top = rect.top + window.scrollY - tooltip.clientHeight - 2;
|
|
740
|
-
let left = rect.right + 4 - tooltip.clientWidth;
|
|
741
|
-
const minTop = window.scrollY + 4;
|
|
742
|
-
const maxTop = window.scrollY + window.innerHeight - tooltip.clientHeight - 4;
|
|
743
|
-
const minLeft = window.scrollX + 4;
|
|
744
|
-
const maxLeft = window.scrollX + window.innerWidth - tooltip.clientWidth - 4;
|
|
745
|
-
const below = top < minTop;
|
|
746
|
-
if (below) {
|
|
747
|
-
top = rect.bottom + window.scrollY + 2;
|
|
748
|
-
}
|
|
749
|
-
top = Math.max(minTop, Math.min(top, maxTop));
|
|
750
|
-
left = Math.max(minLeft, Math.min(left, maxLeft));
|
|
751
|
-
tooltip.dataset.preprPlacement = below ? "below" : "above";
|
|
752
|
-
tooltip.style.top = `${top}px`;
|
|
753
|
-
tooltip.style.left = `${left}px`;
|
|
754
|
-
});
|
|
755
|
-
tooltip.onclick = () => {
|
|
756
|
-
this.onEdit({ href, origin, id, field });
|
|
757
|
-
};
|
|
758
|
-
}
|
|
759
|
-
this.currentElement = element;
|
|
760
|
-
element.classList.add("prepr-overlay-active");
|
|
761
|
-
}
|
|
762
|
-
hideImmediate() {
|
|
763
|
-
this.clearHideTimeout();
|
|
764
|
-
if (this.overlay) this.overlay.style.display = "none";
|
|
765
|
-
if (this.tooltip) this.tooltip.style.display = "none";
|
|
766
|
-
if (this.currentElement) {
|
|
767
|
-
this.currentElement.classList.remove("prepr-overlay-active");
|
|
768
|
-
this.currentElement = null;
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
hide() {
|
|
772
|
-
if (!this.overlay || !this.tooltip) return;
|
|
773
|
-
this.clearHideTimeout();
|
|
774
|
-
this.hideTimeout = setTimeout(() => this.hideImmediate(), 100);
|
|
775
|
-
}
|
|
776
|
-
cleanup() {
|
|
777
|
-
this.clearHideTimeout();
|
|
778
|
-
if (this.overlay) {
|
|
779
|
-
this.overlay.style.display = "none";
|
|
780
|
-
this.overlay.parentNode?.removeChild(this.overlay);
|
|
781
|
-
this.overlay = null;
|
|
782
|
-
}
|
|
783
|
-
if (this.tooltip) {
|
|
784
|
-
this.tooltip.style.display = "none";
|
|
785
|
-
this.tooltip.parentNode?.removeChild(this.tooltip);
|
|
786
|
-
this.tooltip = null;
|
|
787
|
-
}
|
|
788
|
-
if (this.currentElement) {
|
|
789
|
-
this.currentElement.classList.remove("prepr-overlay-active");
|
|
790
|
-
this.currentElement = null;
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
};
|
|
794
|
-
|
|
795
|
-
// src/core/stega/proximity.ts
|
|
796
|
-
var debug5 = createScopedLogger("stega:proximity");
|
|
797
|
-
var StegaProximity = class {
|
|
798
|
-
constructor() {
|
|
799
|
-
this.highlighted = /* @__PURE__ */ new Set();
|
|
800
|
-
this.visible = /* @__PURE__ */ new Set();
|
|
1325
|
+
// A rescan already scheduled must not run after the observer stopped: it
|
|
1326
|
+
// would tag elements and call `onUpdate` on a controller that was shut down.
|
|
1327
|
+
disconnectObserver() {
|
|
1328
|
+
this.observer?.disconnect();
|
|
801
1329
|
this.observer = null;
|
|
802
|
-
this.
|
|
803
|
-
|
|
804
|
-
200
|
|
805
|
-
);
|
|
806
|
-
}
|
|
807
|
-
/** Call after the encoded element set changes — rebuilds the observer. */
|
|
808
|
-
refreshObserving() {
|
|
809
|
-
try {
|
|
810
|
-
if (typeof IntersectionObserver === "undefined") return;
|
|
811
|
-
if (this.observer) {
|
|
812
|
-
this.observer.disconnect();
|
|
813
|
-
this.observer = null;
|
|
814
|
-
}
|
|
815
|
-
this.visible = /* @__PURE__ */ new Set();
|
|
816
|
-
this.observer = new IntersectionObserver(
|
|
817
|
-
(entries) => {
|
|
818
|
-
entries.forEach((entry) => {
|
|
819
|
-
const el = entry.target;
|
|
820
|
-
if (entry.isIntersecting) {
|
|
821
|
-
this.visible.add(el);
|
|
822
|
-
} else {
|
|
823
|
-
this.visible.delete(el);
|
|
824
|
-
}
|
|
825
|
-
});
|
|
826
|
-
},
|
|
827
|
-
{ root: null, rootMargin: "0px", threshold: 0 }
|
|
828
|
-
);
|
|
829
|
-
const nodes = this.getEncodedElements();
|
|
830
|
-
nodes.forEach((el) => this.observer.observe(el));
|
|
831
|
-
debug5.log("observing", nodes.length, "encoded elements");
|
|
832
|
-
} catch (error) {
|
|
833
|
-
debug5.log("error setting up IntersectionObserver", error);
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
stopObserving() {
|
|
837
|
-
if (this.observer) {
|
|
838
|
-
this.observer.disconnect();
|
|
839
|
-
this.observer = null;
|
|
840
|
-
this.visible.clear();
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
updateElementGradients(cursorX, cursorY) {
|
|
844
|
-
const candidates = this.visible.size > 0 ? Array.from(this.visible) : Array.from(this.getEncodedElements());
|
|
845
|
-
const newHighlighted = /* @__PURE__ */ new Set();
|
|
846
|
-
candidates.forEach((element) => {
|
|
847
|
-
const rect = element.getBoundingClientRect();
|
|
848
|
-
const distance = Math.min(
|
|
849
|
-
Math.abs(cursorX - rect.left),
|
|
850
|
-
Math.abs(cursorX - rect.right),
|
|
851
|
-
Math.abs(cursorY - rect.top),
|
|
852
|
-
Math.abs(cursorY - rect.bottom)
|
|
853
|
-
);
|
|
854
|
-
if (distance < 150) {
|
|
855
|
-
const relativeX = cursorX - rect.left;
|
|
856
|
-
const relativeY = cursorY - rect.top;
|
|
857
|
-
element.style.setProperty("--cursor-x", `${relativeX}px`);
|
|
858
|
-
element.style.setProperty("--cursor-y", `${relativeY}px`);
|
|
859
|
-
const baseGradientSize = Math.max(
|
|
860
|
-
150,
|
|
861
|
-
Math.max(rect.width, rect.height) * 1.1
|
|
862
|
-
);
|
|
863
|
-
const distanceScale = Math.max(0, (400 - distance) / 400);
|
|
864
|
-
const gradientSize = baseGradientSize * distanceScale;
|
|
865
|
-
element.style.setProperty("--gradient-size", `${gradientSize}px`);
|
|
866
|
-
element.classList.add("prepr-proximity-highlight");
|
|
867
|
-
newHighlighted.add(element);
|
|
868
|
-
} else {
|
|
869
|
-
element.classList.remove("prepr-proximity-highlight");
|
|
870
|
-
}
|
|
871
|
-
});
|
|
872
|
-
this.highlighted = newHighlighted;
|
|
873
|
-
}
|
|
874
|
-
clearAllHighlights() {
|
|
875
|
-
this.highlighted.forEach(
|
|
876
|
-
(element) => element.classList.remove("prepr-proximity-highlight")
|
|
877
|
-
);
|
|
878
|
-
this.highlighted.clear();
|
|
1330
|
+
if (this.rescanTimer) clearTimeout(this.rescanTimer);
|
|
1331
|
+
this.rescanTimer = null;
|
|
879
1332
|
}
|
|
880
1333
|
};
|
|
881
1334
|
|
|
882
1335
|
// src/core/stega/stega.generated.ts
|
|
883
|
-
var STEGA_STYLES = '
|
|
1336
|
+
var STEGA_STYLES = '@property --prepr-presence{syntax:"<number>";inherits:true;initial-value:1}[data-prepr-encoded]{outline:1px dashed rgb(79 70 229/calc(.3 * var(--prepr-presence,1)));outline-offset:2px}';
|
|
884
1337
|
|
|
885
1338
|
// src/core/stega/styles.ts
|
|
886
1339
|
var STEGA_STYLE_MARKER = "data-prepr-stega";
|
|
@@ -900,45 +1353,79 @@ function removeStegaStyles() {
|
|
|
900
1353
|
}
|
|
901
1354
|
|
|
902
1355
|
// src/core/stega/scan.ts
|
|
903
|
-
var
|
|
904
|
-
var
|
|
1356
|
+
var debug5 = createScopedLogger("stega:scan");
|
|
1357
|
+
var PRESENCE_FADE_MS = 400;
|
|
1358
|
+
var EDITOR_MODE_STYLES = `${ENCODED_SELECTOR}{cursor:pointer}`;
|
|
1359
|
+
function fadeInPresence() {
|
|
1360
|
+
const root = document.documentElement;
|
|
1361
|
+
if (typeof root.animate !== "function") return;
|
|
1362
|
+
if (window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) return;
|
|
1363
|
+
root.animate(
|
|
1364
|
+
{ "--prepr-presence": ["0", "1"] },
|
|
1365
|
+
{ duration: PRESENCE_FADE_MS, easing: "ease-out" }
|
|
1366
|
+
);
|
|
1367
|
+
}
|
|
905
1368
|
function createStegaController(opts) {
|
|
906
1369
|
const tooltipEnabled = opts.tooltip ?? true;
|
|
907
|
-
const
|
|
908
|
-
const proximity = new StegaProximity();
|
|
1370
|
+
const locale = opts.locale ?? "en";
|
|
909
1371
|
const elements = new StegaElements();
|
|
1372
|
+
const overlay = new VisualEditorOverlay({
|
|
1373
|
+
onLabelClick: (target) => opts.onEdit(readEditPayload(target))
|
|
1374
|
+
});
|
|
910
1375
|
let initialized = false;
|
|
911
|
-
let
|
|
912
|
-
|
|
913
|
-
|
|
1376
|
+
let pointerFrame = null;
|
|
1377
|
+
let pointerTarget = null;
|
|
1378
|
+
let pointerX = 0;
|
|
1379
|
+
let pointerY = 0;
|
|
1380
|
+
let hitTestPending = false;
|
|
1381
|
+
const updateHover = () => {
|
|
1382
|
+
pointerFrame = null;
|
|
1383
|
+
if (hitTestPending) {
|
|
1384
|
+
hitTestPending = false;
|
|
1385
|
+
pointerTarget = document.elementFromPoint(pointerX, pointerY);
|
|
1386
|
+
}
|
|
1387
|
+
if (overlay.owns(pointerTarget)) return;
|
|
1388
|
+
const encoded = pointerTarget instanceof Element ? pointerTarget.closest(ENCODED_SELECTOR) : null;
|
|
1389
|
+
overlay.setHover(
|
|
1390
|
+
encoded,
|
|
1391
|
+
encoded ? fieldLabel(encoded.getAttribute(ATTR_FIELD), locale) : ""
|
|
1392
|
+
);
|
|
914
1393
|
};
|
|
915
|
-
const
|
|
916
|
-
if (
|
|
917
|
-
|
|
1394
|
+
const scheduleHover = () => {
|
|
1395
|
+
if (pointerFrame === null) {
|
|
1396
|
+
pointerFrame = requestAnimationFrame(updateHover);
|
|
918
1397
|
}
|
|
919
1398
|
};
|
|
1399
|
+
const handlePointer = (e2) => {
|
|
1400
|
+
pointerTarget = e2.target;
|
|
1401
|
+
pointerX = e2.clientX;
|
|
1402
|
+
pointerY = e2.clientY;
|
|
1403
|
+
hitTestPending = false;
|
|
1404
|
+
scheduleHover();
|
|
1405
|
+
};
|
|
1406
|
+
const handlePointerLeave = () => {
|
|
1407
|
+
pointerTarget = null;
|
|
1408
|
+
hitTestPending = false;
|
|
1409
|
+
overlay.setHover(null, "");
|
|
1410
|
+
};
|
|
920
1411
|
const handleScroll = () => {
|
|
921
|
-
overlay.
|
|
922
|
-
|
|
1412
|
+
overlay.onScroll();
|
|
1413
|
+
if (pointerTarget === null) return;
|
|
1414
|
+
hitTestPending = true;
|
|
1415
|
+
scheduleHover();
|
|
923
1416
|
};
|
|
1417
|
+
const handleResize = () => overlay.schedule();
|
|
924
1418
|
const handleClick = (e2) => {
|
|
925
1419
|
const target = e2.target;
|
|
926
|
-
const encoded = target?.closest(
|
|
927
|
-
"[data-prepr-encoded]"
|
|
928
|
-
);
|
|
1420
|
+
const encoded = target?.closest(ENCODED_SELECTOR);
|
|
929
1421
|
if (!encoded) return;
|
|
930
1422
|
e2.preventDefault();
|
|
931
1423
|
e2.stopPropagation();
|
|
932
|
-
opts.onEdit(
|
|
933
|
-
href: encoded.getAttribute("data-prepr-href") ?? "",
|
|
934
|
-
origin: encoded.getAttribute("data-prepr-origin") ?? "",
|
|
935
|
-
id: encoded.getAttribute("data-prepr-id") ?? void 0,
|
|
936
|
-
field: encoded.getAttribute("data-prepr-field") ?? void 0
|
|
937
|
-
});
|
|
1424
|
+
opts.onEdit(readEditPayload(encoded));
|
|
938
1425
|
};
|
|
939
1426
|
const start = () => {
|
|
940
1427
|
if (initialized) {
|
|
941
|
-
|
|
1428
|
+
debug5.log("already initialized, skipping setup");
|
|
942
1429
|
return;
|
|
943
1430
|
}
|
|
944
1431
|
if (!tooltipEnabled) {
|
|
@@ -948,71 +1435,92 @@ function createStegaController(opts) {
|
|
|
948
1435
|
});
|
|
949
1436
|
document.addEventListener("click", handleClick, { capture: true });
|
|
950
1437
|
initialized = true;
|
|
951
|
-
|
|
1438
|
+
debug5.log("stega controller started (headless)");
|
|
952
1439
|
return;
|
|
953
1440
|
}
|
|
954
1441
|
injectStegaStyles();
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
tooltip.addEventListener("mouseleave", handleTooltipMouseLeave);
|
|
1442
|
+
fadeInPresence();
|
|
1443
|
+
overlay.mount();
|
|
958
1444
|
elements.scanDocument(true);
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
const target = mouseEvent.target;
|
|
964
|
-
if (!target) return;
|
|
965
|
-
if (target.closest(".prepr-tooltip")) return;
|
|
966
|
-
proximity.updateElementGradients(mouseEvent.clientX, mouseEvent.clientY);
|
|
967
|
-
const encoded = target.closest("[data-prepr-encoded]");
|
|
968
|
-
if (encoded) {
|
|
969
|
-
overlay.show(encoded);
|
|
970
|
-
} else {
|
|
971
|
-
overlay.hide();
|
|
972
|
-
}
|
|
973
|
-
}, 16);
|
|
974
|
-
document.addEventListener("mousemove", throttledMouseMove, {
|
|
975
|
-
passive: true
|
|
1445
|
+
elements.setupMutationObserver(() => {
|
|
1446
|
+
if (pointerTarget === null) return;
|
|
1447
|
+
hitTestPending = true;
|
|
1448
|
+
scheduleHover();
|
|
976
1449
|
});
|
|
1450
|
+
document.addEventListener("pointermove", handlePointer, { passive: true });
|
|
1451
|
+
document.addEventListener("pointerdown", handlePointer, { passive: true });
|
|
1452
|
+
document.documentElement.addEventListener(
|
|
1453
|
+
"pointerleave",
|
|
1454
|
+
handlePointerLeave
|
|
1455
|
+
);
|
|
977
1456
|
window.addEventListener("scroll", handleScroll, {
|
|
978
1457
|
capture: true,
|
|
979
1458
|
passive: true
|
|
980
1459
|
});
|
|
1460
|
+
window.addEventListener("resize", handleResize, { passive: true });
|
|
981
1461
|
initialized = true;
|
|
982
|
-
|
|
1462
|
+
debug5.log("stega controller started");
|
|
983
1463
|
};
|
|
984
1464
|
const stop = () => {
|
|
985
1465
|
if (!initialized) return;
|
|
1466
|
+
initialized = false;
|
|
986
1467
|
if (!tooltipEnabled) {
|
|
987
1468
|
document.removeEventListener("click", handleClick, { capture: true });
|
|
988
|
-
elements.
|
|
1469
|
+
elements.disconnect();
|
|
989
1470
|
removeStegaStyles();
|
|
990
|
-
|
|
991
|
-
debug6.log("stega controller stopped (editor mode)");
|
|
1471
|
+
debug5.log("stega controller stopped (headless)");
|
|
992
1472
|
return;
|
|
993
1473
|
}
|
|
994
|
-
if (
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
1474
|
+
if (pointerFrame !== null) cancelAnimationFrame(pointerFrame);
|
|
1475
|
+
pointerFrame = null;
|
|
1476
|
+
pointerTarget = null;
|
|
1477
|
+
hitTestPending = false;
|
|
1478
|
+
document.removeEventListener("pointermove", handlePointer);
|
|
1479
|
+
document.removeEventListener("pointerdown", handlePointer);
|
|
1480
|
+
document.documentElement.removeEventListener(
|
|
1481
|
+
"pointerleave",
|
|
1482
|
+
handlePointerLeave
|
|
1483
|
+
);
|
|
999
1484
|
window.removeEventListener("scroll", handleScroll, { capture: true });
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
tooltip.removeEventListener("mouseleave", handleTooltipMouseLeave);
|
|
1004
|
-
}
|
|
1005
|
-
overlay.cleanup();
|
|
1006
|
-
proximity.clearAllHighlights();
|
|
1007
|
-
proximity.stopObserving();
|
|
1008
|
-
elements.cleanup();
|
|
1485
|
+
window.removeEventListener("resize", handleResize);
|
|
1486
|
+
overlay.unmount();
|
|
1487
|
+
elements.disconnect();
|
|
1009
1488
|
removeStegaStyles();
|
|
1010
|
-
|
|
1011
|
-
debug6.log("stega controller stopped");
|
|
1489
|
+
debug5.log("stega controller stopped");
|
|
1012
1490
|
};
|
|
1013
1491
|
return { start, stop };
|
|
1014
1492
|
}
|
|
1015
1493
|
|
|
1494
|
+
// src/core/stega/scroll-to-field.ts
|
|
1495
|
+
var debug6 = createScopedLogger("stega:scroll");
|
|
1496
|
+
var FLASH_DURATION_MS = 1200;
|
|
1497
|
+
var flashTimeout = null;
|
|
1498
|
+
function scrollToField(request) {
|
|
1499
|
+
const { field, id } = request;
|
|
1500
|
+
if (!field) return false;
|
|
1501
|
+
const candidates = document.querySelectorAll(ENCODED_SELECTOR);
|
|
1502
|
+
let target = null;
|
|
1503
|
+
for (const candidate of candidates) {
|
|
1504
|
+
if (candidate.getAttribute(ATTR_FIELD) !== field) continue;
|
|
1505
|
+
if (id && candidate.getAttribute(ATTR_ID) !== id) continue;
|
|
1506
|
+
target = candidate;
|
|
1507
|
+
break;
|
|
1508
|
+
}
|
|
1509
|
+
if (!target) {
|
|
1510
|
+
debug6.log("no element found for field", field);
|
|
1511
|
+
return false;
|
|
1512
|
+
}
|
|
1513
|
+
target.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
1514
|
+
if (flashTimeout) clearTimeout(flashTimeout);
|
|
1515
|
+
document.querySelectorAll(".prepr-overlay-active").forEach((el) => el.classList.remove("prepr-overlay-active"));
|
|
1516
|
+
target.classList.add("prepr-overlay-active");
|
|
1517
|
+
flashTimeout = setTimeout(() => {
|
|
1518
|
+
target.classList.remove("prepr-overlay-active");
|
|
1519
|
+
flashTimeout = null;
|
|
1520
|
+
}, FLASH_DURATION_MS);
|
|
1521
|
+
return true;
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1016
1524
|
// src/core/store.ts
|
|
1017
1525
|
var DEFAULT_STATE = {
|
|
1018
1526
|
locale: "en",
|
|
@@ -1147,7 +1655,7 @@ function splitPath(full) {
|
|
|
1147
1655
|
return [full.slice(0, index), full.slice(index + 1)];
|
|
1148
1656
|
}
|
|
1149
1657
|
|
|
1150
|
-
// ../../node_modules/.pnpm/preact@10.29.
|
|
1658
|
+
// ../../node_modules/.pnpm/preact@10.29.8/node_modules/preact/dist/preact.mjs
|
|
1151
1659
|
var n;
|
|
1152
1660
|
var l;
|
|
1153
1661
|
var u;
|
|
@@ -1218,8 +1726,8 @@ function H() {
|
|
|
1218
1726
|
}
|
|
1219
1727
|
}
|
|
1220
1728
|
function L(n2, l2, u3, t3, i2, r2, o2, e2, f3, c2, a2) {
|
|
1221
|
-
var s2, h2, p2, v2, y2, _2, g2
|
|
1222
|
-
for (f3 = T(u3, l2,
|
|
1729
|
+
var s2, h2, p2, v2, y2, _2, g2 = t3 && t3.__k || w, m2 = l2.length;
|
|
1730
|
+
for (f3 = T(u3, l2, g2, f3, m2), s2 = 0; s2 < m2; s2++) null != (p2 = u3.__k[s2]) && (h2 = -1 != p2.__i && g2[p2.__i] || d, p2.__i = s2, _2 = q(n2, p2, h2, i2, r2, o2, e2, f3, c2, a2), v2 = p2.__e, p2.ref && h2.ref != p2.ref && (h2.ref && J(h2.ref, null, p2), a2.push(p2.ref, p2.__c || v2, p2)), null == y2 && null != v2 && (y2 = v2), 4 & p2.__u ? (f3 = j(p2, f3, n2), h2.__e && (h2.__e = null)) : "function" == typeof p2.type && void 0 !== _2 ? f3 = _2 : v2 && (f3 = v2.nextSibling), p2.__u &= -7);
|
|
1223
1731
|
return u3.__e = y2, f3;
|
|
1224
1732
|
}
|
|
1225
1733
|
function T(n2, l2, u3, t3, i2) {
|
|
@@ -1228,13 +1736,13 @@ function T(n2, l2, u3, t3, i2) {
|
|
|
1228
1736
|
if (s2) for (r2 = 0; r2 < a2; r2++) null != (e2 = u3[r2]) && 0 == (2 & e2.__u) && (e2.__e == t3 && (t3 = $(e2)), K(e2, e2));
|
|
1229
1737
|
return t3;
|
|
1230
1738
|
}
|
|
1231
|
-
function j(n2, l2, u3
|
|
1232
|
-
var
|
|
1739
|
+
function j(n2, l2, u3) {
|
|
1740
|
+
var t3, i2;
|
|
1233
1741
|
if ("function" == typeof n2.type) {
|
|
1234
|
-
for (
|
|
1742
|
+
for (t3 = n2.__k, i2 = 0; t3 && i2 < t3.length; i2++) t3[i2] && (t3[i2].__ = n2, l2 = j(t3[i2], l2, u3));
|
|
1235
1743
|
return l2;
|
|
1236
1744
|
}
|
|
1237
|
-
n2.__e != l2 && (
|
|
1745
|
+
n2.__e != l2 && (l2 && n2.type && !l2.parentNode && (l2 = $(n2)), l2 = u3.insertBefore(n2.__e, l2 || null));
|
|
1238
1746
|
do {
|
|
1239
1747
|
l2 = l2 && l2.nextSibling;
|
|
1240
1748
|
} while (null != l2 && 8 == l2.nodeType);
|
|
@@ -1280,35 +1788,35 @@ function V(n2) {
|
|
|
1280
1788
|
};
|
|
1281
1789
|
}
|
|
1282
1790
|
function q(n2, u3, t3, i2, r2, o2, e2, f3, c2, a2) {
|
|
1283
|
-
var s2, h2, p2, v2, y2, d2, _2, k2, x2, M,
|
|
1791
|
+
var s2, h2, p2, v2, y2, d2, _2, k2, x2, M, I2, P2, A2, H2, T2, j2, F = u3.type;
|
|
1284
1792
|
if (void 0 !== u3.constructor) return null;
|
|
1285
1793
|
128 & t3.__u && (c2 = !!(32 & t3.__u), o2 = [f3 = u3.__e = t3.__e]), (s2 = l.__b) && s2(u3);
|
|
1286
|
-
n: if ("function" == typeof
|
|
1794
|
+
n: if ("function" == typeof F) {
|
|
1287
1795
|
h2 = e2.length;
|
|
1288
1796
|
try {
|
|
1289
|
-
if (x2 = u3.props, M =
|
|
1797
|
+
if (x2 = u3.props, M = F.prototype && F.prototype.render, I2 = (s2 = F.contextType) && i2[s2.__c], P2 = s2 ? I2 ? I2.props.value : s2.__ : i2, t3.__c ? k2 = (p2 = u3.__c = t3.__c).__ = p2.__E : (M ? u3.__c = p2 = new F(x2, P2) : (u3.__c = p2 = new C(x2, P2), p2.constructor = F, p2.render = Q), I2 && I2.sub(p2), p2.state || (p2.state = {}), p2.__n = i2, v2 = p2.__d = true, p2.__h = [], p2._sb = []), M && null == p2.__s && (p2.__s = p2.state), M && null != F.getDerivedStateFromProps && (p2.__s == p2.state && (p2.__s = m({}, p2.__s)), m(p2.__s, F.getDerivedStateFromProps(x2, p2.__s))), y2 = p2.props, d2 = p2.state, p2.__v = u3, v2) M && null == F.getDerivedStateFromProps && null != p2.componentWillMount && p2.componentWillMount(), M && null != p2.componentDidMount && p2.__h.push(p2.componentDidMount);
|
|
1290
1798
|
else {
|
|
1291
|
-
if (M && null ==
|
|
1799
|
+
if (M && null == F.getDerivedStateFromProps && x2 !== y2 && null != p2.componentWillReceiveProps && p2.componentWillReceiveProps(x2, P2), u3.__v == t3.__v || !p2.__e && null != p2.shouldComponentUpdate && false === p2.shouldComponentUpdate(x2, p2.__s, P2)) {
|
|
1292
1800
|
u3.__v != t3.__v && (p2.props = x2, p2.state = p2.__s, p2.__d = false), u3.__e = t3.__e, u3.__k = t3.__k, u3.__k.some(function(n3) {
|
|
1293
1801
|
n3 && (n3.__ = u3);
|
|
1294
|
-
}), w.push.apply(p2.__h, p2._sb), p2._sb = [], p2.__h.length && e2.push(p2);
|
|
1802
|
+
}), w.push.apply(p2.__h, p2._sb), p2._sb = [], p2.__h.length && e2.push(p2), f3 = $(t3);
|
|
1295
1803
|
break n;
|
|
1296
1804
|
}
|
|
1297
|
-
null != p2.componentWillUpdate && p2.componentWillUpdate(x2, p2.__s,
|
|
1805
|
+
null != p2.componentWillUpdate && p2.componentWillUpdate(x2, p2.__s, P2), M && null != p2.componentDidUpdate && p2.__h.push(function() {
|
|
1298
1806
|
p2.componentDidUpdate(y2, d2, _2);
|
|
1299
1807
|
});
|
|
1300
1808
|
}
|
|
1301
|
-
if (p2.context =
|
|
1809
|
+
if (p2.context = P2, p2.props = x2, p2.__P = n2, p2.__e = false, A2 = l.__r, H2 = 0, M) p2.state = p2.__s, p2.__d = false, A2 && A2(u3), s2 = p2.render(p2.props, p2.state, p2.context), w.push.apply(p2.__h, p2._sb), p2._sb = [];
|
|
1302
1810
|
else do {
|
|
1303
|
-
p2.__d = false,
|
|
1304
|
-
} while (p2.__d && ++
|
|
1305
|
-
p2.state = p2.__s, null != p2.getChildContext && (i2 = m(m({}, i2), p2.getChildContext())), M && !v2 && null != p2.getSnapshotBeforeUpdate && (_2 = p2.getSnapshotBeforeUpdate(y2, d2)),
|
|
1811
|
+
p2.__d = false, A2 && A2(u3), s2 = p2.render(p2.props, p2.state, p2.context), p2.state = p2.__s;
|
|
1812
|
+
} while (p2.__d && ++H2 < 25);
|
|
1813
|
+
p2.state = p2.__s, null != p2.getChildContext && (i2 = m(m({}, i2), p2.getChildContext())), M && !v2 && null != p2.getSnapshotBeforeUpdate && (_2 = p2.getSnapshotBeforeUpdate(y2, d2)), T2 = null != s2 && s2.type === S && null == s2.key ? E(s2.props.children) : s2, f3 = L(n2, g(T2) ? T2 : [T2], u3, t3, i2, r2, o2, e2, f3, c2, a2), p2.base = u3.__e, u3.__u &= -161, p2.__h.length && e2.push(p2), k2 && (p2.__E = p2.__ = null);
|
|
1306
1814
|
} catch (n3) {
|
|
1307
1815
|
if (e2.length = h2, u3.__v = null, c2 || null != o2) {
|
|
1308
1816
|
if (n3.then) {
|
|
1309
1817
|
for (u3.__u |= c2 ? 160 : 128; f3 && 8 == f3.nodeType && f3.nextSibling; ) f3 = f3.nextSibling;
|
|
1310
1818
|
null != o2 && (o2[o2.indexOf(f3)] = null), u3.__e = f3;
|
|
1311
|
-
} else if (null != o2) for (
|
|
1819
|
+
} else if (null != o2) for (j2 = o2.length; j2--; ) b(o2[j2]);
|
|
1312
1820
|
} else u3.__e = t3.__e;
|
|
1313
1821
|
null == u3.__k && (u3.__k = t3.__k || []), n3.then || B(u3), l.__e(n3, u3, t3);
|
|
1314
1822
|
}
|
|
@@ -1429,9 +1937,9 @@ var CLOSE_ICON_SVG = `<svg width="10" height="10" viewBox="0 0 10 10" fill="none
|
|
|
1429
1937
|
</svg>`;
|
|
1430
1938
|
|
|
1431
1939
|
// src/core/ui/toolbar.generated.ts
|
|
1432
|
-
var TOOLBAR_CSS = ":host{--prepr-primary:#4338ca;--prepr-bg:#eef2ff;--prepr-text:#1f2937;--prepr-radius:8px;--prepr-shadow:0px 0px 40px 0px #1f29373d;--prepr-z-index:10000;--prepr-primary-50:#eef2ff;--prepr-primary-100:#e0e7ff;--prepr-primary-800:#3730a3;--prepr-indigo-600:#4f46e5;--prepr-indigo-50:#eef2ff;--prepr-indigo-700:#4338ca;--prepr-secondary-400:#fb923c;--prepr-secondary-500:#f97316;--prepr-gray-100:#f3f4f6;--prepr-gray-200:#e5e7eb;--prepr-gray-300:#d1d5db;--prepr-gray-400:#9ca3af;--prepr-gray-500:#6b7280;--prepr-gray-700:#374151;--prepr-gray-800:#1f2937;--prepr-gray-900:#111827;--prepr-shadow-sm:0px 0px 12px 0px #c3c3c3cc;color:var(--prepr-text);box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif;font-size:14px;line-height:1.5}:host *,:host :before,:host :after,*,:before,:after{box-sizing:border-box}button{font-family:inherit;font-size:inherit;margin:0}.prepr-regular-text{font-size:.875rem;font-weight:500;line-height:1.5}.prepr-backdrop{z-index:calc(var(--prepr-z-index) - 1);opacity:0;pointer-events:none;background:#0000001a;transition:opacity .2s ease-in-out;position:fixed;top:0;bottom:0;left:0;right:0}.prepr-backdrop[data-open=true]{opacity:1;pointer-events:auto;animation:.2s ease-in-out prepr-fade-in}.prepr-container{z-index:var(--prepr-z-index);justify-content:flex-end;align-items:center;display:flex;position:fixed;top:calc(50% - 64px);right:0}.prepr-toggle-holder{padding:.5rem}.prepr-toggle{cursor:pointer;background:var(--prepr-primary);color:#fff;border:none;border-radius:9999px;justify-content:center;align-items:center;width:2.25rem;height:2.25rem;display:flex}.prepr-toggle>span{display:flex}.prepr-toggle svg{color:#fff}.prepr-panel{z-index:var(--prepr-z-index);opacity:0;pointer-events:none;justify-content:flex-end;padding:.75rem;transition:opacity .2s ease-in-out;display:flex;position:fixed;top:50%;right:0;transform:translateY(-50%)}.prepr-panel[data-open=true]{opacity:1;pointer-events:auto;animation:.2s ease-in-out prepr-fade-in}.prepr-content{box-shadow:var(--prepr-shadow);border-radius:var(--prepr-radius);background:var(--prepr-bg);flex-direction:column;gap:2.5rem;width:100%;padding:1.5rem;display:flex}@media (min-width:640px){.prepr-panel{margin-right:4rem;padding:0}.prepr-content{width:502px;padding:2.5rem}}.prepr-header{justify-content:space-between;align-items:center;gap:.5rem;display:flex}.prepr-header-left{align-items:flex-start;gap:.75rem;display:flex}.prepr-badge{background:var(--prepr-primary-100);height:1.5rem;color:var(--prepr-primary);border-radius:4px;align-items:center;padding:.25rem .75rem;font-size:.875rem;display:flex}.prepr-header-close{cursor:pointer;background:var(--prepr-primary-100);width:2rem;height:2rem;color:var(--prepr-gray-700);border:none;border-radius:6px;justify-content:center;align-items:center;display:flex}.prepr-section{flex-direction:column;gap:.5rem;display:flex}.prepr-section-label{color:var(--prepr-gray-400);font-size:.875rem}.prepr-row{flex-wrap:wrap;justify-content:space-between;align-items:center;gap:.5rem 1.5rem;display:flex}.prepr-row-title{color:var(--prepr-gray-800);margin:0;font-size:1rem;font-weight:600}.prepr-radiogroup{border-radius:var(--prepr-radius);border:1px solid var(--prepr-gray-300);background:#fff;align-items:center;gap:.25rem;height:2.5rem;padding:.25rem;display:flex}.prepr-radiogroup[data-disabled=true]{cursor:not-allowed;opacity:.5}.prepr-radiogroup[data-disabled=true] .prepr-radio{pointer-events:none}.prepr-radio{cursor:pointer;white-space:nowrap;text-align:center;height:2rem;color:var(--prepr-gray-900);background:0 0;border:none;border-radius:6px;justify-content:center;align-items:center;padding:.5rem 1.125rem;font-size:.875rem;font-weight:500;transition:all .2s ease-in-out;display:flex}.prepr-radio[data-checked=true]{background:var(--prepr-indigo-600);color:#fff;box-shadow:var(--prepr-shadow-sm)}.prepr-radio[data-checked=true][data-off=true]{background:var(--prepr-gray-800);color:#fff}.prepr-radio-variant{width:82px}.prepr-listbox{position:relative}.prepr-segment-button{border-radius:var(--prepr-radius);border:1px solid var(--prepr-gray-300);width:240px;height:2.5rem;color:var(--prepr-gray-500);cursor:pointer;background:#fff;flex-shrink:0;align-items:center;gap:.5rem;padding:0 .5rem;font-size:.875rem;font-weight:500;display:flex;overflow:hidden}@media (min-width:768px){.prepr-segment-button{padding:0 1rem}}.prepr-segment-button:disabled{cursor:not-allowed;background:var(--prepr-gray-200);color:var(--prepr-gray-400)}.prepr-segment-button[aria-expanded=true]{border-bottom-color:#fff;border-bottom-right-radius:0;border-bottom-left-radius:0}.prepr-segment-label{white-space:nowrap;text-overflow:ellipsis;text-align:left;width:100%;margin-right:auto;overflow:hidden}.prepr-segment-caret{color:var(--prepr-gray-800);display:flex}.prepr-options{z-index:calc(var(--prepr-z-index) + 1);border-left:1px solid var(--prepr-gray-300);border-right:1px solid var(--prepr-gray-300);border-bottom:1px solid var(--prepr-gray-300);-ms-overflow-style:none;scrollbar-width:none;background:#fff;border-radius:0 0 6px 6px;width:240px;max-height:300px;margin:0;padding:0;list-style:none;position:absolute;top:100%;left:0;overflow-y:auto;box-shadow:0 20px 25px -5px #0000001a,0 8px 10px -6px #0000001a}.prepr-options::-webkit-scrollbar{display:none}.prepr-options[hidden]{display:none}.prepr-option-search{background:#fff;padding:.5rem;position
|
|
1940
|
+
var TOOLBAR_CSS = ":host{--prepr-primary:#4338ca;--prepr-bg:#eef2ff;--prepr-text:#1f2937;--prepr-radius:8px;--prepr-shadow:0px 0px 40px 0px #1f29373d;--prepr-z-index:10000;--prepr-primary-50:#eef2ff;--prepr-primary-100:#e0e7ff;--prepr-primary-800:#3730a3;--prepr-indigo-600:#4f46e5;--prepr-indigo-50:#eef2ff;--prepr-indigo-700:#4338ca;--prepr-secondary-400:#fb923c;--prepr-secondary-500:#f97316;--prepr-gray-100:#f3f4f6;--prepr-gray-200:#e5e7eb;--prepr-gray-300:#d1d5db;--prepr-gray-400:#9ca3af;--prepr-gray-500:#6b7280;--prepr-gray-700:#374151;--prepr-gray-800:#1f2937;--prepr-gray-900:#111827;--prepr-shadow-sm:0px 0px 12px 0px #c3c3c3cc;color:var(--prepr-text);box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif;font-size:14px;line-height:1.5}:host *,:host :before,:host :after,*,:before,:after{box-sizing:border-box}button{font-family:inherit;font-size:inherit;margin:0}.prepr-regular-text{font-size:.875rem;font-weight:500;line-height:1.5}.prepr-backdrop{z-index:calc(var(--prepr-z-index) - 1);opacity:0;pointer-events:none;background:#0000001a;transition:opacity .2s ease-in-out;position:fixed;top:0;bottom:0;left:0;right:0}.prepr-backdrop[data-open=true]{opacity:1;pointer-events:auto;animation:.2s ease-in-out prepr-fade-in}.prepr-container{z-index:var(--prepr-z-index);justify-content:flex-end;align-items:center;display:flex;position:fixed;top:calc(50% - 64px);right:0}.prepr-toggle-holder{padding:.5rem}.prepr-toggle{cursor:pointer;background:var(--prepr-primary);color:#fff;border:none;border-radius:9999px;justify-content:center;align-items:center;width:2.25rem;height:2.25rem;display:flex}.prepr-toggle>span{display:flex}.prepr-toggle svg{color:#fff}.prepr-panel{z-index:var(--prepr-z-index);opacity:0;pointer-events:none;justify-content:flex-end;padding:.75rem;transition:opacity .2s ease-in-out;display:flex;position:fixed;top:50%;right:0;transform:translateY(-50%)}.prepr-panel[data-open=true]{opacity:1;pointer-events:auto;animation:.2s ease-in-out prepr-fade-in}.prepr-content{box-shadow:var(--prepr-shadow);border-radius:var(--prepr-radius);background:var(--prepr-bg);flex-direction:column;gap:2.5rem;width:100%;padding:1.5rem;display:flex}@media (min-width:640px){.prepr-panel{margin-right:4rem;padding:0}.prepr-content{width:502px;padding:2.5rem}}.prepr-header{justify-content:space-between;align-items:center;gap:.5rem;display:flex}.prepr-header-left{align-items:flex-start;gap:.75rem;display:flex}.prepr-badge{background:var(--prepr-primary-100);height:1.5rem;color:var(--prepr-primary);border-radius:4px;align-items:center;padding:.25rem .75rem;font-size:.875rem;display:flex}.prepr-header-close{cursor:pointer;background:var(--prepr-primary-100);width:2rem;height:2rem;color:var(--prepr-gray-700);border:none;border-radius:6px;justify-content:center;align-items:center;display:flex}.prepr-section{flex-direction:column;gap:.5rem;display:flex}.prepr-section-label{color:var(--prepr-gray-400);font-size:.875rem}.prepr-row{flex-wrap:wrap;justify-content:space-between;align-items:center;gap:.5rem 1.5rem;display:flex}.prepr-row-title{color:var(--prepr-gray-800);margin:0;font-size:1rem;font-weight:600}.prepr-radiogroup{border-radius:var(--prepr-radius);border:1px solid var(--prepr-gray-300);background:#fff;align-items:center;gap:.25rem;height:2.5rem;padding:.25rem;display:flex}.prepr-radiogroup[data-disabled=true]{cursor:not-allowed;opacity:.5}.prepr-radiogroup[data-disabled=true] .prepr-radio{pointer-events:none}.prepr-radio{cursor:pointer;white-space:nowrap;text-align:center;height:2rem;color:var(--prepr-gray-900);background:0 0;border:none;border-radius:6px;justify-content:center;align-items:center;padding:.5rem 1.125rem;font-size:.875rem;font-weight:500;transition:all .2s ease-in-out;display:flex}.prepr-radio[data-checked=true]{background:var(--prepr-indigo-600);color:#fff;box-shadow:var(--prepr-shadow-sm)}.prepr-radio[data-checked=true][data-off=true]{background:var(--prepr-gray-800);color:#fff}.prepr-radio-variant{width:82px}.prepr-listbox{position:relative}.prepr-segment-button{border-radius:var(--prepr-radius);border:1px solid var(--prepr-gray-300);width:240px;height:2.5rem;color:var(--prepr-gray-500);cursor:pointer;background:#fff;flex-shrink:0;align-items:center;gap:.5rem;padding:0 .5rem;font-size:.875rem;font-weight:500;display:flex;overflow:hidden}@media (min-width:768px){.prepr-segment-button{padding:0 1rem}}.prepr-segment-button:disabled{cursor:not-allowed;background:var(--prepr-gray-200);color:var(--prepr-gray-400)}.prepr-segment-button[aria-expanded=true]{border-bottom-color:#fff;border-bottom-right-radius:0;border-bottom-left-radius:0}.prepr-segment-label{white-space:nowrap;text-overflow:ellipsis;text-align:left;width:100%;margin-right:auto;overflow:hidden}.prepr-segment-caret{color:var(--prepr-gray-800);display:flex}.prepr-options{z-index:calc(var(--prepr-z-index) + 1);border-left:1px solid var(--prepr-gray-300);border-right:1px solid var(--prepr-gray-300);border-bottom:1px solid var(--prepr-gray-300);-ms-overflow-style:none;scrollbar-width:none;background:#fff;border-radius:0 0 6px 6px;width:240px;max-height:300px;margin:0;padding:0;list-style:none;position:absolute;top:100%;left:0;overflow-y:auto;box-shadow:0 20px 25px -5px #0000001a,0 8px 10px -6px #0000001a}.prepr-options::-webkit-scrollbar{display:none}.prepr-options[hidden]{display:none}.prepr-option-search{background:#fff;padding:.5rem;position:sticky;top:0}.prepr-segment-search{border:1px solid var(--prepr-gray-300);border-radius:var(--prepr-radius);width:100%;height:2rem;font:inherit;color:var(--prepr-gray-900);box-sizing:border-box;background:#fff;padding:0 .5rem;font-size:.875rem}@media (pointer:coarse){.prepr-segment-search{font-size:16px}}.prepr-segment-search::placeholder{color:var(--prepr-gray-400)}.prepr-segment-search:focus{border-color:var(--prepr-gray-400);outline:none}.prepr-option{cursor:pointer;width:100%;color:var(--prepr-gray-900);background:#fff;align-items:center;padding:.5rem 1rem;font-size:.875rem;font-weight:500;display:flex}.prepr-option:hover{background:var(--prepr-gray-100)}.prepr-option[aria-selected=true]{background:var(--prepr-indigo-50);color:var(--prepr-indigo-700)}.prepr-option-label{white-space:nowrap;text-overflow:ellipsis;text-align:left;width:100%;margin-right:auto;overflow:hidden}.prepr-reset{background:var(--prepr-secondary-400);color:#fff;cursor:pointer;border:none;border-radius:6px;justify-content:center;align-items:center;gap:.5rem;width:100%;height:2.5rem;padding:.5rem .75rem;font-size:.875rem;font-weight:500;display:flex}.prepr-reset:hover:not(:disabled){background:var(--prepr-secondary-500)}.prepr-reset:disabled{background:var(--prepr-gray-400);color:var(--prepr-gray-500);cursor:not-allowed}@media (min-width:768px){.prepr-reset{width:108px}}.prepr-indicators{z-index:var(--prepr-z-index);gap:.75rem;display:flex;position:fixed;bottom:1.5rem;right:1.5rem}.prepr-status-pill{background:var(--prepr-primary);color:#fff;cursor:pointer;border:none;border-radius:9999px;align-items:center;gap:.5rem;padding:.5rem 1rem;font-size:.75rem;font-weight:500;transition:background-color .15s;display:flex;box-shadow:0 10px 15px -3px #0000001a,0 4px 6px -4px #0000001a}.prepr-status-pill[data-interactive=false]{cursor:default;opacity:1;color:#fff}.prepr-status-pill[data-interactive=true]:hover{background:var(--prepr-primary-800)}.prepr-status-pill[hidden]{display:none}.prepr-status-viewing{color:#fff9;font-size:10px}.prepr-status-segment{text-overflow:ellipsis;white-space:nowrap;max-width:120px;display:inline-block;overflow:hidden}.prepr-status-variant{text-overflow:ellipsis;white-space:nowrap;background:#fff3;border-radius:4px;max-width:80px;padding:0 .5rem;display:inline-block;overflow:hidden}.prepr-status-x{color:#fff;width:.75rem;height:.75rem}.prepr-close-edit-pill{background:var(--prepr-primary-50);color:var(--prepr-gray-800);cursor:pointer;border:none;border-radius:9999px;align-items:center;gap:.5rem;padding:.5rem 1rem;font-size:.75rem;font-weight:500;transition:background-color .15s;display:flex;box-shadow:0 10px 15px -3px #0000001a,0 4px 6px -4px #0000001a}.prepr-close-edit-pill:hover{background:var(--prepr-primary-100)}.prepr-close-edit-pill[hidden]{display:none}.prepr-close-edit-x{width:1rem;height:1rem;color:var(--prepr-gray-500);transition:color .15s}.prepr-close-edit-pill:hover .prepr-close-edit-x{color:var(--prepr-gray-700)}.prepr-tip{z-index:calc(var(--prepr-z-index) + 2);overflow-wrap:break-word;background:var(--prepr-gray-900);color:#fff;pointer-events:none;border-radius:6px;width:auto;max-width:min(420px,100vw - 16px);padding:.5rem .75rem;font-size:.75rem;font-weight:500;position:fixed;box-shadow:0 20px 25px -5px #0000001a,0 8px 10px -6px #0000001a}.prepr-tip-arrow{border-left:6px solid #0000;border-right:6px solid #0000;border-top:6px solid var(--prepr-gray-900);width:0;height:0;position:absolute;top:100%;transform:translate(-50%)}[hidden]{display:none!important}@keyframes prepr-fade-in{0%{opacity:0}to{opacity:1}}";
|
|
1433
1941
|
|
|
1434
|
-
// ../../node_modules/.pnpm/preact@10.29.
|
|
1942
|
+
// ../../node_modules/.pnpm/preact@10.29.8/node_modules/preact/jsx-runtime/dist/jsxRuntime.mjs
|
|
1435
1943
|
var f2 = 0;
|
|
1436
1944
|
function u2(e2, t3, n2, o2, i2, u3) {
|
|
1437
1945
|
t3 || (t3 = {});
|
|
@@ -1678,7 +2186,7 @@ function StatusPill({
|
|
|
1678
2186
|
handlers
|
|
1679
2187
|
}) {
|
|
1680
2188
|
const { features } = state;
|
|
1681
|
-
const defaultSegmentName = state.segments.find((s2) => s2._id ===
|
|
2189
|
+
const defaultSegmentName = state.segments.find((s2) => s2._id === SEGMENT_ALL_OTHER_USERS)?.name ?? t3("adaptiveContent.allOtherUsers");
|
|
1682
2190
|
let segmentLabel;
|
|
1683
2191
|
if (!state.previewMode || !features.segments) {
|
|
1684
2192
|
segmentLabel = t3("common.user");
|
|
@@ -1859,7 +2367,6 @@ function Panel({
|
|
|
1859
2367
|
}
|
|
1860
2368
|
|
|
1861
2369
|
// src/core/ui/toolbar-element.ts
|
|
1862
|
-
var TAG_NAME = "prepr-toolbar";
|
|
1863
2370
|
var HTMLElementBase = typeof HTMLElement === "undefined" ? class {
|
|
1864
2371
|
} : HTMLElement;
|
|
1865
2372
|
var PreprToolbarElement = class extends HTMLElementBase {
|
|
@@ -1933,6 +2440,13 @@ var PreprToolbarElement = class extends HTMLElementBase {
|
|
|
1933
2440
|
document.addEventListener("mousedown", this.onDocumentMouseDown);
|
|
1934
2441
|
this.renderPanel(store.get());
|
|
1935
2442
|
}
|
|
2443
|
+
/**
|
|
2444
|
+
* Re-wires a toolbar that was detached and attached again, e.g. when a
|
|
2445
|
+
* framework replaces `<body>` on navigation and the element is moved back.
|
|
2446
|
+
*/
|
|
2447
|
+
connectedCallback() {
|
|
2448
|
+
if (this.store && !this.unsubscribe) this.connect(this.store, this.t);
|
|
2449
|
+
}
|
|
1936
2450
|
disconnectedCallback() {
|
|
1937
2451
|
this.unsubscribe?.();
|
|
1938
2452
|
this.unsubscribe = null;
|
|
@@ -2119,13 +2633,845 @@ var PreprToolbarElement = class extends HTMLElementBase {
|
|
|
2119
2633
|
};
|
|
2120
2634
|
function definePreprToolbar() {
|
|
2121
2635
|
if (typeof customElements === "undefined") return;
|
|
2122
|
-
if (!customElements.get(
|
|
2123
|
-
customElements.define(
|
|
2636
|
+
if (!customElements.get(TOOLBAR_TAG)) {
|
|
2637
|
+
customElements.define(TOOLBAR_TAG, PreprToolbarElement);
|
|
2124
2638
|
}
|
|
2125
2639
|
}
|
|
2126
2640
|
|
|
2641
|
+
// src/core/visual-editor/asset-images.ts
|
|
2642
|
+
var MAX_URL_LENGTH = 4096;
|
|
2643
|
+
var MIN_KEY_SEGMENTS = 2;
|
|
2644
|
+
var TRANSFORM_OPTION = /^[a-z]{1,3}_[\w.-]*$/i;
|
|
2645
|
+
var FORMAT_PLACEHOLDER = "{format}";
|
|
2646
|
+
var PROXY_PARAMS = ["url", "href", "src", "image"];
|
|
2647
|
+
var ABSOLUTE_HTTP = /^https?:\/\//i;
|
|
2648
|
+
var SOURCE_URL_ATTRIBUTES = ["src", "data-src"];
|
|
2649
|
+
var SOURCE_SET_ATTRIBUTES = ["srcset", "data-srcset"];
|
|
2650
|
+
var ASSET_ATTR = "data-prepr-asset";
|
|
2651
|
+
var REMOVED_ATTR = "data-prepr-removed";
|
|
2652
|
+
var ASSET_SOURCE_ATTRIBUTES = [
|
|
2653
|
+
...SOURCE_URL_ATTRIBUTES,
|
|
2654
|
+
...SOURCE_SET_ATTRIBUTES
|
|
2655
|
+
];
|
|
2656
|
+
var TAG_ATTRIBUTES = [
|
|
2657
|
+
ATTR_ENCODED,
|
|
2658
|
+
ATTR_ID,
|
|
2659
|
+
ATTR_FIELD,
|
|
2660
|
+
"data-prepr-entry-id",
|
|
2661
|
+
ASSET_ATTR,
|
|
2662
|
+
REMOVED_ATTR
|
|
2663
|
+
];
|
|
2664
|
+
function decodeSegment(segment) {
|
|
2665
|
+
try {
|
|
2666
|
+
return decodeURIComponent(segment);
|
|
2667
|
+
} catch {
|
|
2668
|
+
return segment;
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
function isTransformSegment(segment) {
|
|
2672
|
+
return segment === FORMAT_PLACEHOLDER || segment.split(",").every((option) => TRANSFORM_OPTION.test(option));
|
|
2673
|
+
}
|
|
2674
|
+
function assetKey(url, depth = 0) {
|
|
2675
|
+
if (!url || url.length > MAX_URL_LENGTH) return null;
|
|
2676
|
+
let parsed;
|
|
2677
|
+
try {
|
|
2678
|
+
parsed = new URL(url, "https://base.invalid");
|
|
2679
|
+
} catch {
|
|
2680
|
+
return null;
|
|
2681
|
+
}
|
|
2682
|
+
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") return null;
|
|
2683
|
+
if (depth === 0) {
|
|
2684
|
+
for (const name of PROXY_PARAMS) {
|
|
2685
|
+
const inner = parsed.searchParams.get(name);
|
|
2686
|
+
if (inner && ABSOLUTE_HTTP.test(inner)) return assetKey(inner, 1);
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2689
|
+
const segments = parsed.pathname.split("/").filter(Boolean).map(decodeSegment);
|
|
2690
|
+
const file = segments.pop();
|
|
2691
|
+
if (!file) return null;
|
|
2692
|
+
const kept = segments.filter((segment) => !isTransformSegment(segment));
|
|
2693
|
+
kept.push(file);
|
|
2694
|
+
return kept.length >= MIN_KEY_SEGMENTS ? kept.join("/") : null;
|
|
2695
|
+
}
|
|
2696
|
+
function srcsetUrls(srcset) {
|
|
2697
|
+
const urls = [];
|
|
2698
|
+
let expectUrl = true;
|
|
2699
|
+
for (const token of srcset.split(/\s+/)) {
|
|
2700
|
+
if (!token) continue;
|
|
2701
|
+
if (!expectUrl) {
|
|
2702
|
+
const comma = token.indexOf(",");
|
|
2703
|
+
if (comma === -1) continue;
|
|
2704
|
+
expectUrl = true;
|
|
2705
|
+
const rest = token.slice(comma + 1);
|
|
2706
|
+
if (!rest) continue;
|
|
2707
|
+
urls.push(rest.replace(/,+$/, ""));
|
|
2708
|
+
expectUrl = rest.endsWith(",");
|
|
2709
|
+
continue;
|
|
2710
|
+
}
|
|
2711
|
+
const url = token.replace(/^,+|,+$/g, "");
|
|
2712
|
+
if (url) urls.push(url);
|
|
2713
|
+
expectUrl = token.endsWith(",");
|
|
2714
|
+
}
|
|
2715
|
+
return urls;
|
|
2716
|
+
}
|
|
2717
|
+
function createAssetIndex(assets) {
|
|
2718
|
+
const index = /* @__PURE__ */ new Map();
|
|
2719
|
+
for (const asset of assets) {
|
|
2720
|
+
const key = assetKey(asset.key);
|
|
2721
|
+
if (key && !index.has(key)) index.set(key, asset);
|
|
2722
|
+
}
|
|
2723
|
+
return index;
|
|
2724
|
+
}
|
|
2725
|
+
function urlsOf(img) {
|
|
2726
|
+
const urls = [];
|
|
2727
|
+
const collect = (el) => {
|
|
2728
|
+
for (const name of SOURCE_URL_ATTRIBUTES) {
|
|
2729
|
+
const value = el.getAttribute(name);
|
|
2730
|
+
if (value) urls.push(value);
|
|
2731
|
+
}
|
|
2732
|
+
for (const name of SOURCE_SET_ATTRIBUTES) {
|
|
2733
|
+
const value = el.getAttribute(name);
|
|
2734
|
+
if (value) urls.push(...srcsetUrls(value));
|
|
2735
|
+
}
|
|
2736
|
+
};
|
|
2737
|
+
collect(img);
|
|
2738
|
+
const picture = img.parentElement;
|
|
2739
|
+
if (picture?.tagName === "PICTURE") {
|
|
2740
|
+
for (const source of picture.children) {
|
|
2741
|
+
if (source.tagName === "SOURCE") collect(source);
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2744
|
+
return urls;
|
|
2745
|
+
}
|
|
2746
|
+
function matchAsset(img, index, keys) {
|
|
2747
|
+
for (const url of urlsOf(img)) {
|
|
2748
|
+
let key = keys.get(url);
|
|
2749
|
+
if (key === void 0) {
|
|
2750
|
+
key = assetKey(url);
|
|
2751
|
+
keys.set(url, key);
|
|
2752
|
+
}
|
|
2753
|
+
const asset = key ? index.get(key) : void 0;
|
|
2754
|
+
if (asset) return asset;
|
|
2755
|
+
}
|
|
2756
|
+
return void 0;
|
|
2757
|
+
}
|
|
2758
|
+
function setIfChanged(el, name, value) {
|
|
2759
|
+
if (value === null) {
|
|
2760
|
+
if (el.hasAttribute(name)) el.removeAttribute(name);
|
|
2761
|
+
} else if (el.getAttribute(name) !== value) {
|
|
2762
|
+
el.setAttribute(name, value);
|
|
2763
|
+
}
|
|
2764
|
+
}
|
|
2765
|
+
function untagAssetImage(img) {
|
|
2766
|
+
for (const name of TAG_ATTRIBUTES) img.removeAttribute(name);
|
|
2767
|
+
}
|
|
2768
|
+
var TEXT_FIELD_SELECTOR = `${ENCODED_SELECTOR}:not([${ASSET_ATTR}])`;
|
|
2769
|
+
function besideOtherItem(img, isCurrentItem) {
|
|
2770
|
+
for (let block = img.parentElement; block && block !== document.body; block = block.parentElement) {
|
|
2771
|
+
const texts = block.querySelectorAll(TEXT_FIELD_SELECTOR);
|
|
2772
|
+
if (texts.length === 0) continue;
|
|
2773
|
+
for (const text of texts) {
|
|
2774
|
+
if (isCurrentItem(text)) return false;
|
|
2775
|
+
}
|
|
2776
|
+
return true;
|
|
2777
|
+
}
|
|
2778
|
+
return false;
|
|
2779
|
+
}
|
|
2780
|
+
function tagAssetImages(index, itemId, keys, options = {}) {
|
|
2781
|
+
const { isCurrentItem, removed } = options;
|
|
2782
|
+
let showsRemoved = false;
|
|
2783
|
+
for (const img of document.getElementsByTagName("img")) {
|
|
2784
|
+
const ours = img.hasAttribute(ASSET_ATTR);
|
|
2785
|
+
let match = index.size ? matchAsset(img, index, keys) : void 0;
|
|
2786
|
+
let isRemoved = false;
|
|
2787
|
+
if (!match && removed?.size) {
|
|
2788
|
+
match = matchAsset(img, removed, keys);
|
|
2789
|
+
isRemoved = match !== void 0;
|
|
2790
|
+
}
|
|
2791
|
+
if (!ours && img.hasAttribute(ATTR_ENCODED)) {
|
|
2792
|
+
const mark = isRemoved && (!isCurrentItem || isCurrentItem(img));
|
|
2793
|
+
setIfChanged(img, REMOVED_ATTR, mark ? "" : null);
|
|
2794
|
+
showsRemoved || (showsRemoved = mark);
|
|
2795
|
+
continue;
|
|
2796
|
+
}
|
|
2797
|
+
const asset = match && isCurrentItem && besideOtherItem(img, isCurrentItem) ? void 0 : match;
|
|
2798
|
+
if (!asset) {
|
|
2799
|
+
if (ours) untagAssetImage(img);
|
|
2800
|
+
continue;
|
|
2801
|
+
}
|
|
2802
|
+
setIfChanged(img, ATTR_ENCODED, "");
|
|
2803
|
+
setIfChanged(img, ASSET_ATTR, "");
|
|
2804
|
+
setIfChanged(img, ATTR_ID, itemId);
|
|
2805
|
+
setIfChanged(img, ATTR_FIELD, asset.field);
|
|
2806
|
+
setIfChanged(img, "data-prepr-entry-id", asset.entryId ?? null);
|
|
2807
|
+
setIfChanged(img, REMOVED_ATTR, isRemoved ? "" : null);
|
|
2808
|
+
showsRemoved || (showsRemoved = isRemoved);
|
|
2809
|
+
}
|
|
2810
|
+
return showsRemoved;
|
|
2811
|
+
}
|
|
2812
|
+
function untagAssetImages() {
|
|
2813
|
+
document.querySelectorAll(`img[${ASSET_ATTR}]`).forEach(untagAssetImage);
|
|
2814
|
+
document.querySelectorAll(`img[${REMOVED_ATTR}]`).forEach((img) => img.removeAttribute(REMOVED_ATTR));
|
|
2815
|
+
}
|
|
2816
|
+
|
|
2817
|
+
// src/core/visual-editor/item-scope.ts
|
|
2818
|
+
var REFERENCE_ATTR = "data-prepr-reference";
|
|
2819
|
+
var REFERENCE_SELECTOR = `[${REFERENCE_ATTR}]`;
|
|
2820
|
+
var OTHER_ITEM_ATTR = "data-prepr-other-item";
|
|
2821
|
+
var OTHER_ITEM_SELECTOR = `[${OTHER_ITEM_ATTR}="on"],[${OTHER_ITEM_ATTR}="off"]`;
|
|
2822
|
+
var CHROME_SELECTOR = "header, footer, nav, [role=banner], [role=contentinfo], [role=navigation]";
|
|
2823
|
+
var SECTIONING_SELECTOR = "article, aside, main, nav, section";
|
|
2824
|
+
var PLAIN_HEADER_FOOTER = "header:not([role]), footer:not([role])";
|
|
2825
|
+
function createItemScope() {
|
|
2826
|
+
let currentItemId = null;
|
|
2827
|
+
let references = null;
|
|
2828
|
+
let ownComponents = /* @__PURE__ */ new Set();
|
|
2829
|
+
const isCurrentItem = (el) => {
|
|
2830
|
+
if (currentItemId === null) return true;
|
|
2831
|
+
const id = el.getAttribute(ATTR_ID);
|
|
2832
|
+
return !id || id === currentItemId || ownComponents.has(id);
|
|
2833
|
+
};
|
|
2834
|
+
const linkedIdOf = (el) => {
|
|
2835
|
+
if (!references) return null;
|
|
2836
|
+
const id = el.getAttribute(ATTR_ID) ?? "";
|
|
2837
|
+
if (references.has(id)) return id;
|
|
2838
|
+
let container = el.closest(REFERENCE_SELECTOR);
|
|
2839
|
+
while (container) {
|
|
2840
|
+
const linked = container.getAttribute(REFERENCE_ATTR) ?? "";
|
|
2841
|
+
if (references.has(linked)) return linked;
|
|
2842
|
+
container = container.parentElement?.closest(REFERENCE_SELECTOR) ?? null;
|
|
2843
|
+
}
|
|
2844
|
+
return null;
|
|
2845
|
+
};
|
|
2846
|
+
const inSiteChrome = (el) => {
|
|
2847
|
+
let chrome = el.closest(CHROME_SELECTOR);
|
|
2848
|
+
while (chrome) {
|
|
2849
|
+
if (!chrome.matches(PLAIN_HEADER_FOOTER) || !chrome.parentElement?.closest(SECTIONING_SELECTOR)) {
|
|
2850
|
+
return true;
|
|
2851
|
+
}
|
|
2852
|
+
chrome = chrome.parentElement?.closest(CHROME_SELECTOR) ?? null;
|
|
2853
|
+
}
|
|
2854
|
+
return false;
|
|
2855
|
+
};
|
|
2856
|
+
const showsOtherItem = (el) => {
|
|
2857
|
+
const choice = el.closest(OTHER_ITEM_SELECTOR);
|
|
2858
|
+
if (choice) return choice.getAttribute(OTHER_ITEM_ATTR) === "on";
|
|
2859
|
+
return !inSiteChrome(el);
|
|
2860
|
+
};
|
|
2861
|
+
const itemKind = (el) => {
|
|
2862
|
+
if (isCurrentItem(el)) return "current";
|
|
2863
|
+
if (!references) return "other";
|
|
2864
|
+
if (linkedIdOf(el)) return "referenced";
|
|
2865
|
+
return showsOtherItem(el) ? "other" : null;
|
|
2866
|
+
};
|
|
2867
|
+
const referenceFieldOf = (el) => {
|
|
2868
|
+
const linked = linkedIdOf(el);
|
|
2869
|
+
return linked ? references?.get(linked) : void 0;
|
|
2870
|
+
};
|
|
2871
|
+
return {
|
|
2872
|
+
currentItemId: () => currentItemId,
|
|
2873
|
+
setCurrentItem(itemId) {
|
|
2874
|
+
currentItemId = itemId;
|
|
2875
|
+
},
|
|
2876
|
+
setComponents(componentIds) {
|
|
2877
|
+
ownComponents = new Set(componentIds);
|
|
2878
|
+
},
|
|
2879
|
+
setReferences(list) {
|
|
2880
|
+
references = /* @__PURE__ */ new Map();
|
|
2881
|
+
for (const { id, field } of list) {
|
|
2882
|
+
if (!references.has(id)) references.set(id, field);
|
|
2883
|
+
}
|
|
2884
|
+
},
|
|
2885
|
+
isCurrentItem,
|
|
2886
|
+
linkedIdOf,
|
|
2887
|
+
itemKind,
|
|
2888
|
+
referenceFieldOf
|
|
2889
|
+
};
|
|
2890
|
+
}
|
|
2891
|
+
|
|
2892
|
+
// src/core/visual-editor/list-items.ts
|
|
2893
|
+
function listItemIn(encoded, target) {
|
|
2894
|
+
if (!(target instanceof Element)) return null;
|
|
2895
|
+
const li = target.closest("li");
|
|
2896
|
+
if (!li || !encoded.contains(li) || !li.parentElement) return null;
|
|
2897
|
+
const items = Array.from(li.parentElement.children).filter(
|
|
2898
|
+
(child) => child.tagName === "LI"
|
|
2899
|
+
);
|
|
2900
|
+
return { element: li, index: items.indexOf(li) };
|
|
2901
|
+
}
|
|
2902
|
+
function nthListItem(encoded, block) {
|
|
2903
|
+
const list = encoded.querySelector("ul, ol");
|
|
2904
|
+
if (!list) return null;
|
|
2905
|
+
const items = Array.from(list.children).filter(
|
|
2906
|
+
(child) => child.tagName === "LI"
|
|
2907
|
+
);
|
|
2908
|
+
return items[block] ?? null;
|
|
2909
|
+
}
|
|
2910
|
+
|
|
2911
|
+
// src/core/visual-editor/navigation-guard.ts
|
|
2912
|
+
var debug7 = createScopedLogger("navigation-guard");
|
|
2913
|
+
var trimSlash = (path) => path.length > 1 && path.endsWith("/") ? path.slice(0, -1) : path;
|
|
2914
|
+
function resolve(url) {
|
|
2915
|
+
try {
|
|
2916
|
+
return new URL(url, document.baseURI);
|
|
2917
|
+
} catch {
|
|
2918
|
+
return null;
|
|
2919
|
+
}
|
|
2920
|
+
}
|
|
2921
|
+
function leavesPage(url) {
|
|
2922
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return false;
|
|
2923
|
+
const here = window.location;
|
|
2924
|
+
return url.origin !== here.origin || trimSlash(url.pathname) !== trimSlash(here.pathname);
|
|
2925
|
+
}
|
|
2926
|
+
function leavingLinkHref(target) {
|
|
2927
|
+
if (!(target instanceof Element)) return null;
|
|
2928
|
+
const link = target.closest("a[href]");
|
|
2929
|
+
if (!link || link.hasAttribute("download")) return null;
|
|
2930
|
+
const linkTarget = link.getAttribute("target");
|
|
2931
|
+
if (linkTarget && linkTarget !== "_self") return null;
|
|
2932
|
+
const href = link.getAttribute("href") ?? "";
|
|
2933
|
+
if (href.startsWith("#")) return null;
|
|
2934
|
+
const url = resolve(href);
|
|
2935
|
+
return url && leavesPage(url) ? url.href : null;
|
|
2936
|
+
}
|
|
2937
|
+
function submitterAttr(submitter, attr) {
|
|
2938
|
+
if (!submitter?.hasAttribute(attr)) return null;
|
|
2939
|
+
if (attr === "formaction") return submitter.formAction;
|
|
2940
|
+
if (attr === "formmethod") return submitter.formMethod;
|
|
2941
|
+
return submitter.formTarget;
|
|
2942
|
+
}
|
|
2943
|
+
function submissionUrl(form, submitter) {
|
|
2944
|
+
const method = (submitterAttr(submitter, "formmethod") ?? form.method).toLowerCase();
|
|
2945
|
+
if (method === "dialog") return null;
|
|
2946
|
+
const target = submitterAttr(submitter, "formtarget") ?? form.target;
|
|
2947
|
+
if (target && target !== "_self") return null;
|
|
2948
|
+
const url = resolve(
|
|
2949
|
+
submitterAttr(submitter, "formaction") ?? (form.action || location.href)
|
|
2950
|
+
);
|
|
2951
|
+
if (!url) return null;
|
|
2952
|
+
if (method === "get") {
|
|
2953
|
+
let data;
|
|
2954
|
+
try {
|
|
2955
|
+
data = new FormData(form, submitter);
|
|
2956
|
+
} catch {
|
|
2957
|
+
data = new FormData(form);
|
|
2958
|
+
}
|
|
2959
|
+
const query = new URLSearchParams();
|
|
2960
|
+
data.forEach((value, key) => {
|
|
2961
|
+
query.append(key, typeof value === "string" ? value : value.name);
|
|
2962
|
+
});
|
|
2963
|
+
url.search = query.toString();
|
|
2964
|
+
}
|
|
2965
|
+
return url;
|
|
2966
|
+
}
|
|
2967
|
+
function createNavigationGuard(opts) {
|
|
2968
|
+
let active = false;
|
|
2969
|
+
let permitted = null;
|
|
2970
|
+
let pendingForm = null;
|
|
2971
|
+
let originalPush = null;
|
|
2972
|
+
let guardedPush = null;
|
|
2973
|
+
const isPermitted = (url) => permitted === url.href;
|
|
2974
|
+
const guarding = () => active && opts.showsEditedContent();
|
|
2975
|
+
const report = (href) => {
|
|
2976
|
+
debug7.log("blocked navigation to", href);
|
|
2977
|
+
opts.onBlocked(href);
|
|
2978
|
+
};
|
|
2979
|
+
const onSubmit = (e2) => {
|
|
2980
|
+
if (e2.defaultPrevented || !(e2.target instanceof HTMLFormElement)) return;
|
|
2981
|
+
if (!guarding()) return;
|
|
2982
|
+
const submitter = e2.submitter ?? null;
|
|
2983
|
+
const url = submissionUrl(e2.target, submitter);
|
|
2984
|
+
if (!url || !leavesPage(url) || isPermitted(url)) return;
|
|
2985
|
+
e2.preventDefault();
|
|
2986
|
+
pendingForm = { form: e2.target, submitter, href: url.href };
|
|
2987
|
+
report(url.href);
|
|
2988
|
+
};
|
|
2989
|
+
const onNavigate = (event) => {
|
|
2990
|
+
const e2 = event;
|
|
2991
|
+
if (e2.navigationType === "traverse" || e2.navigationType === "reload") {
|
|
2992
|
+
return;
|
|
2993
|
+
}
|
|
2994
|
+
if (!e2.cancelable || e2.hashChange || e2.downloadRequest !== null) return;
|
|
2995
|
+
if (!guarding()) return;
|
|
2996
|
+
if (e2.navigationType === "replace" && e2.destination.sameDocument) return;
|
|
2997
|
+
const url = resolve(e2.destination.url);
|
|
2998
|
+
if (!url || !leavesPage(url) || isPermitted(url)) return;
|
|
2999
|
+
e2.preventDefault();
|
|
3000
|
+
report(url.href);
|
|
3001
|
+
if (e2.destination.sameDocument) window.location.reload();
|
|
3002
|
+
};
|
|
3003
|
+
const navigation = () => window.navigation;
|
|
3004
|
+
function installPushGuard() {
|
|
3005
|
+
const original = history.pushState;
|
|
3006
|
+
const guard = function(data, unused, url) {
|
|
3007
|
+
if (guarding() && guardedPush === guard && url != null) {
|
|
3008
|
+
const target = resolve(url);
|
|
3009
|
+
if (target && leavesPage(target) && !isPermitted(target)) {
|
|
3010
|
+
report(target.href);
|
|
3011
|
+
window.location.reload();
|
|
3012
|
+
return;
|
|
3013
|
+
}
|
|
3014
|
+
}
|
|
3015
|
+
return original.call(this, data, unused, url);
|
|
3016
|
+
};
|
|
3017
|
+
originalPush = original;
|
|
3018
|
+
guardedPush = guard;
|
|
3019
|
+
history.pushState = guard;
|
|
3020
|
+
}
|
|
3021
|
+
function uninstallPushGuard() {
|
|
3022
|
+
if (history.pushState === guardedPush && originalPush) {
|
|
3023
|
+
history.pushState = originalPush;
|
|
3024
|
+
}
|
|
3025
|
+
originalPush = null;
|
|
3026
|
+
guardedPush = null;
|
|
3027
|
+
}
|
|
3028
|
+
return {
|
|
3029
|
+
start() {
|
|
3030
|
+
if (active) return;
|
|
3031
|
+
active = true;
|
|
3032
|
+
installPushGuard();
|
|
3033
|
+
window.addEventListener("submit", onSubmit);
|
|
3034
|
+
navigation()?.addEventListener("navigate", onNavigate);
|
|
3035
|
+
},
|
|
3036
|
+
stop() {
|
|
3037
|
+
if (!active) return;
|
|
3038
|
+
active = false;
|
|
3039
|
+
uninstallPushGuard();
|
|
3040
|
+
window.removeEventListener("submit", onSubmit);
|
|
3041
|
+
navigation()?.removeEventListener("navigate", onNavigate);
|
|
3042
|
+
pendingForm = null;
|
|
3043
|
+
},
|
|
3044
|
+
isActive: guarding,
|
|
3045
|
+
block(href) {
|
|
3046
|
+
report(href);
|
|
3047
|
+
},
|
|
3048
|
+
permit(href) {
|
|
3049
|
+
permitted = resolve(href)?.href ?? null;
|
|
3050
|
+
},
|
|
3051
|
+
allow(href) {
|
|
3052
|
+
const url = resolve(href);
|
|
3053
|
+
if (!url || url.protocol !== "http:" && url.protocol !== "https:") {
|
|
3054
|
+
debug7.warn("ignored navigation to unsupported URL");
|
|
3055
|
+
return;
|
|
3056
|
+
}
|
|
3057
|
+
permitted = url.href;
|
|
3058
|
+
const form = pendingForm;
|
|
3059
|
+
pendingForm = null;
|
|
3060
|
+
if (form && form.href === url.href && form.form.isConnected) {
|
|
3061
|
+
try {
|
|
3062
|
+
form.form.requestSubmit(form.submitter ?? void 0);
|
|
3063
|
+
} catch {
|
|
3064
|
+
form.form.requestSubmit();
|
|
3065
|
+
}
|
|
3066
|
+
return;
|
|
3067
|
+
}
|
|
3068
|
+
window.location.assign(url.href);
|
|
3069
|
+
}
|
|
3070
|
+
};
|
|
3071
|
+
}
|
|
3072
|
+
|
|
3073
|
+
// src/core/visual-editor/index.ts
|
|
3074
|
+
var debug8 = createScopedLogger("visual-editor");
|
|
3075
|
+
var CURSOR_STYLE_MARKER = "data-prepr-visual-editor";
|
|
3076
|
+
var REMOVED_STYLES = `img[${REMOVED_ATTR}]{opacity:.2!important;transition:opacity .2s ease}@media (prefers-reduced-motion:reduce){img[${REMOVED_ATTR}]{transition:none}}`;
|
|
3077
|
+
var CURSOR_STYLES = `${ENCODED_SELECTOR}{cursor:pointer}html[data-prepr-ve-suspended] ${ENCODED_SELECTOR}{cursor:auto}${REMOVED_STYLES}`;
|
|
3078
|
+
var SUSPENDED_ATTR = "data-prepr-ve-suspended";
|
|
3079
|
+
var FIND_RETRY_MS = 150;
|
|
3080
|
+
var FIND_RETRIES = 6;
|
|
3081
|
+
var MAX_CACHED_KEYS = 2e3;
|
|
3082
|
+
var SAVED_FADE_MS = 1e4;
|
|
3083
|
+
var LAYOUT_MUTATIONS = {
|
|
3084
|
+
childList: true,
|
|
3085
|
+
subtree: true,
|
|
3086
|
+
characterData: true,
|
|
3087
|
+
attributes: true,
|
|
3088
|
+
attributeFilter: [
|
|
3089
|
+
"class",
|
|
3090
|
+
"style",
|
|
3091
|
+
"hidden",
|
|
3092
|
+
"open",
|
|
3093
|
+
ATTR_ENCODED,
|
|
3094
|
+
// An image swapped by a carousel or lazy loader can show another asset.
|
|
3095
|
+
...ASSET_SOURCE_ATTRIBUTES
|
|
3096
|
+
]
|
|
3097
|
+
};
|
|
3098
|
+
function scrollIntoFrame(el) {
|
|
3099
|
+
const rect = el.getBoundingClientRect();
|
|
3100
|
+
const offset = Math.max(0, (window.innerHeight - rect.height) / 2);
|
|
3101
|
+
window.scrollTo({
|
|
3102
|
+
top: Math.max(0, window.scrollY + rect.top - offset),
|
|
3103
|
+
behavior: "smooth"
|
|
3104
|
+
});
|
|
3105
|
+
}
|
|
3106
|
+
var isVisible = (el) => typeof el.checkVisibility === "function" ? el.checkVisibility() : el.getClientRects().length > 0;
|
|
3107
|
+
function createVisualEditor(opts) {
|
|
3108
|
+
const overlay = new VisualEditorOverlay();
|
|
3109
|
+
let running = false;
|
|
3110
|
+
const scope = createItemScope();
|
|
3111
|
+
const { isCurrentItem, itemKind, linkedIdOf, referenceFieldOf } = scope;
|
|
3112
|
+
let locale = opts.locale ?? "en";
|
|
3113
|
+
let suspended = false;
|
|
3114
|
+
let pointerFrame = null;
|
|
3115
|
+
let lastPointerTarget = null;
|
|
3116
|
+
let lastPointerX = 0;
|
|
3117
|
+
let lastPointerY = 0;
|
|
3118
|
+
let mutationFrame = null;
|
|
3119
|
+
let mutationObserver = null;
|
|
3120
|
+
let selection = null;
|
|
3121
|
+
let findTimeout = null;
|
|
3122
|
+
let settlePendingFind = null;
|
|
3123
|
+
let guardEnabled = false;
|
|
3124
|
+
let assetIndex = /* @__PURE__ */ new Map();
|
|
3125
|
+
const assetKeys = /* @__PURE__ */ new Map();
|
|
3126
|
+
const removedAssets = /* @__PURE__ */ new Map();
|
|
3127
|
+
let saved = false;
|
|
3128
|
+
let savedTimeout = null;
|
|
3129
|
+
const guard = createNavigationGuard({
|
|
3130
|
+
onBlocked: (href) => opts.onNavigationBlocked?.(href),
|
|
3131
|
+
showsEditedContent: () => showsEditedContent()
|
|
3132
|
+
});
|
|
3133
|
+
const encodedFrom = (node) => node instanceof Element ? node.closest(ENCODED_SELECTOR) : null;
|
|
3134
|
+
const labelFor = (el) => fieldLabel(el.getAttribute(ATTR_FIELD), locale);
|
|
3135
|
+
const showsEditedContent = () => {
|
|
3136
|
+
for (const el of document.querySelectorAll(ENCODED_SELECTOR)) {
|
|
3137
|
+
if (isCurrentItem(el) && isVisible(el)) return true;
|
|
3138
|
+
}
|
|
3139
|
+
return false;
|
|
3140
|
+
};
|
|
3141
|
+
const hoverLabel = (el, kind) => {
|
|
3142
|
+
if (kind === "other") {
|
|
3143
|
+
return `${labelFor(el)} \xB7 ${t("visualEditor.otherItem", locale)}`;
|
|
3144
|
+
}
|
|
3145
|
+
if (kind === "referenced") {
|
|
3146
|
+
const via = referenceFieldOf(el);
|
|
3147
|
+
const prefix = via ? `${fieldLabel(via, locale)} \u203A ` : "";
|
|
3148
|
+
return `${prefix}${labelFor(el)} \xB7 ${t("visualEditor.linkedItem", locale)}`;
|
|
3149
|
+
}
|
|
3150
|
+
return labelFor(el);
|
|
3151
|
+
};
|
|
3152
|
+
const setSuspended = (value) => {
|
|
3153
|
+
if (suspended === value) return;
|
|
3154
|
+
suspended = value;
|
|
3155
|
+
document.documentElement.toggleAttribute(SUSPENDED_ATTR, value);
|
|
3156
|
+
if (value) overlay.setHover(null, "");
|
|
3157
|
+
};
|
|
3158
|
+
const updateHover = () => {
|
|
3159
|
+
pointerFrame = null;
|
|
3160
|
+
overlay.schedule();
|
|
3161
|
+
if (suspended) return;
|
|
3162
|
+
const encoded = encodedFrom(lastPointerTarget);
|
|
3163
|
+
const target = encoded === overlay.getSelectedTarget() ? null : encoded;
|
|
3164
|
+
if (!target) {
|
|
3165
|
+
overlay.setHover(null, "");
|
|
3166
|
+
return;
|
|
3167
|
+
}
|
|
3168
|
+
const kind = itemKind(target);
|
|
3169
|
+
if (!kind) {
|
|
3170
|
+
overlay.setHover(null, "");
|
|
3171
|
+
return;
|
|
3172
|
+
}
|
|
3173
|
+
overlay.setHover(target, hoverLabel(target, kind), { kind });
|
|
3174
|
+
};
|
|
3175
|
+
const handlePointerMove = (e2) => {
|
|
3176
|
+
setSuspended(e2.altKey);
|
|
3177
|
+
lastPointerTarget = e2.target;
|
|
3178
|
+
lastPointerX = e2.clientX;
|
|
3179
|
+
lastPointerY = e2.clientY;
|
|
3180
|
+
if (pointerFrame === null) {
|
|
3181
|
+
pointerFrame = requestAnimationFrame(updateHover);
|
|
3182
|
+
}
|
|
3183
|
+
};
|
|
3184
|
+
const handlePointerLeave = () => {
|
|
3185
|
+
lastPointerTarget = null;
|
|
3186
|
+
overlay.setHover(null, "");
|
|
3187
|
+
};
|
|
3188
|
+
const handleClick = (e2) => {
|
|
3189
|
+
if (e2.altKey) {
|
|
3190
|
+
const href = leavingLinkHref(e2.target);
|
|
3191
|
+
if (href && guard.isActive()) guard.permit(href);
|
|
3192
|
+
return;
|
|
3193
|
+
}
|
|
3194
|
+
const encoded = encodedFrom(e2.target);
|
|
3195
|
+
const kind = encoded ? itemKind(encoded) : null;
|
|
3196
|
+
if (!encoded || !kind) {
|
|
3197
|
+
clearSelection();
|
|
3198
|
+
if (e2.ctrlKey || e2.metaKey || e2.shiftKey || !showsEditedContent()) return;
|
|
3199
|
+
const href = leavingLinkHref(e2.target);
|
|
3200
|
+
if (!href) return;
|
|
3201
|
+
e2.preventDefault();
|
|
3202
|
+
if (guard.isActive()) {
|
|
3203
|
+
e2.stopPropagation();
|
|
3204
|
+
guard.block(href);
|
|
3205
|
+
}
|
|
3206
|
+
return;
|
|
3207
|
+
}
|
|
3208
|
+
if (kind === "other" && (e2.ctrlKey || e2.metaKey || e2.shiftKey)) return;
|
|
3209
|
+
e2.preventDefault();
|
|
3210
|
+
e2.stopPropagation();
|
|
3211
|
+
const item = listItemIn(encoded, e2.target);
|
|
3212
|
+
if (kind === "current")
|
|
3213
|
+
select(item?.element ?? encoded, encoded, item?.index);
|
|
3214
|
+
const referenceField = kind === "referenced" ? referenceFieldOf(encoded) : void 0;
|
|
3215
|
+
const linkedId = kind === "referenced" ? linkedIdOf(encoded) : null;
|
|
3216
|
+
const linkHref = kind === "other" ? leavingLinkHref(e2.target) : null;
|
|
3217
|
+
opts.onEdit({
|
|
3218
|
+
...readEditPayload(encoded),
|
|
3219
|
+
...linkedId && { id: linkedId },
|
|
3220
|
+
...item && { block: item.index },
|
|
3221
|
+
...referenceField && { referenceField },
|
|
3222
|
+
...linkHref && { linkHref }
|
|
3223
|
+
});
|
|
3224
|
+
};
|
|
3225
|
+
const handleKey = (e2) => {
|
|
3226
|
+
if (e2.key === "Alt") setSuspended(e2.type === "keydown");
|
|
3227
|
+
if (e2.type === "keydown" && e2.key === "Escape") {
|
|
3228
|
+
clearSelection();
|
|
3229
|
+
}
|
|
3230
|
+
};
|
|
3231
|
+
const handleBlur = () => setSuspended(false);
|
|
3232
|
+
const handleScroll = () => overlay.onScroll();
|
|
3233
|
+
const handleResize = () => overlay.schedule();
|
|
3234
|
+
const handleSettled = () => overlay.schedule();
|
|
3235
|
+
function select(el, field, block) {
|
|
3236
|
+
const entryId = field.getAttribute("data-prepr-entry-id");
|
|
3237
|
+
selection = {
|
|
3238
|
+
lookup: {
|
|
3239
|
+
field: field.getAttribute(ATTR_FIELD) ?? "",
|
|
3240
|
+
id: field.getAttribute(ATTR_ID) ?? void 0,
|
|
3241
|
+
...entryId && { entryId },
|
|
3242
|
+
...block !== void 0 && { block }
|
|
3243
|
+
},
|
|
3244
|
+
label: field
|
|
3245
|
+
};
|
|
3246
|
+
overlay.setSelected(el, labelFor(field));
|
|
3247
|
+
if (overlay.getHoverTarget() === el) overlay.setHover(null, "");
|
|
3248
|
+
}
|
|
3249
|
+
function clearSelection() {
|
|
3250
|
+
selection = null;
|
|
3251
|
+
overlay.setSelected(null, "");
|
|
3252
|
+
}
|
|
3253
|
+
function reselect() {
|
|
3254
|
+
if (!selection) return;
|
|
3255
|
+
const current = overlay.getSelectedTarget();
|
|
3256
|
+
if (current?.isConnected && selection.label.isConnected) return;
|
|
3257
|
+
const found = findFieldElement(selection.lookup);
|
|
3258
|
+
if (!found || !isCurrentItem(found)) {
|
|
3259
|
+
overlay.setSelected(null, "");
|
|
3260
|
+
return;
|
|
3261
|
+
}
|
|
3262
|
+
const { block } = selection.lookup;
|
|
3263
|
+
const el = block !== void 0 ? nthListItem(found, block) ?? found : found;
|
|
3264
|
+
select(el, found, block);
|
|
3265
|
+
}
|
|
3266
|
+
const hasAssets = () => assetIndex.size > 0 || removedAssets.size > 0;
|
|
3267
|
+
function tagAssets() {
|
|
3268
|
+
if (assetKeys.size > MAX_CACHED_KEYS) assetKeys.clear();
|
|
3269
|
+
const showsRemoved = tagAssetImages(
|
|
3270
|
+
assetIndex,
|
|
3271
|
+
scope.currentItemId(),
|
|
3272
|
+
assetKeys,
|
|
3273
|
+
{
|
|
3274
|
+
isCurrentItem: (el) => isCurrentItem(el),
|
|
3275
|
+
removed: removedAssets
|
|
3276
|
+
}
|
|
3277
|
+
);
|
|
3278
|
+
if (saved && !showsRemoved) forgetRemoved();
|
|
3279
|
+
}
|
|
3280
|
+
function forgetRemoved() {
|
|
3281
|
+
saved = false;
|
|
3282
|
+
if (savedTimeout) clearTimeout(savedTimeout);
|
|
3283
|
+
savedTimeout = null;
|
|
3284
|
+
if (!removedAssets.size) return;
|
|
3285
|
+
removedAssets.clear();
|
|
3286
|
+
if (running) tagAssets();
|
|
3287
|
+
}
|
|
3288
|
+
function itemSaved() {
|
|
3289
|
+
if (!removedAssets.size) return;
|
|
3290
|
+
saved = true;
|
|
3291
|
+
if (savedTimeout) clearTimeout(savedTimeout);
|
|
3292
|
+
savedTimeout = setTimeout(forgetRemoved, SAVED_FADE_MS);
|
|
3293
|
+
}
|
|
3294
|
+
const handleLayoutFrame = () => {
|
|
3295
|
+
mutationFrame = null;
|
|
3296
|
+
if (hasAssets()) tagAssets();
|
|
3297
|
+
reselect();
|
|
3298
|
+
const hovered = overlay.getHoverTarget();
|
|
3299
|
+
if (hovered && !hovered.isConnected) {
|
|
3300
|
+
lastPointerTarget = document.elementFromPoint(lastPointerX, lastPointerY);
|
|
3301
|
+
updateHover();
|
|
3302
|
+
return;
|
|
3303
|
+
}
|
|
3304
|
+
overlay.schedule();
|
|
3305
|
+
};
|
|
3306
|
+
const handleMutations = () => {
|
|
3307
|
+
if (mutationFrame !== null) return;
|
|
3308
|
+
if (!selection && !overlay.getHoverTarget() && !hasAssets()) return;
|
|
3309
|
+
mutationFrame = requestAnimationFrame(handleLayoutFrame);
|
|
3310
|
+
};
|
|
3311
|
+
function injectCursorStyles() {
|
|
3312
|
+
if (document.querySelector(`style[${CURSOR_STYLE_MARKER}]`)) return;
|
|
3313
|
+
const style = document.createElement("style");
|
|
3314
|
+
style.setAttribute(CURSOR_STYLE_MARKER, "");
|
|
3315
|
+
style.textContent = CURSOR_STYLES;
|
|
3316
|
+
document.head.appendChild(style);
|
|
3317
|
+
}
|
|
3318
|
+
function start() {
|
|
3319
|
+
if (running) return;
|
|
3320
|
+
running = true;
|
|
3321
|
+
overlay.mount();
|
|
3322
|
+
injectCursorStyles();
|
|
3323
|
+
document.addEventListener("pointermove", handlePointerMove, {
|
|
3324
|
+
passive: true
|
|
3325
|
+
});
|
|
3326
|
+
document.documentElement.addEventListener(
|
|
3327
|
+
"pointerleave",
|
|
3328
|
+
handlePointerLeave
|
|
3329
|
+
);
|
|
3330
|
+
document.addEventListener("click", handleClick, { capture: true });
|
|
3331
|
+
window.addEventListener("keydown", handleKey);
|
|
3332
|
+
window.addEventListener("keyup", handleKey);
|
|
3333
|
+
window.addEventListener("blur", handleBlur);
|
|
3334
|
+
window.addEventListener("scroll", handleScroll, {
|
|
3335
|
+
capture: true,
|
|
3336
|
+
passive: true
|
|
3337
|
+
});
|
|
3338
|
+
window.addEventListener("resize", handleResize, { passive: true });
|
|
3339
|
+
document.addEventListener("transitionend", handleSettled, {
|
|
3340
|
+
capture: true,
|
|
3341
|
+
passive: true
|
|
3342
|
+
});
|
|
3343
|
+
document.addEventListener("animationend", handleSettled, {
|
|
3344
|
+
capture: true,
|
|
3345
|
+
passive: true
|
|
3346
|
+
});
|
|
3347
|
+
mutationObserver = new MutationObserver(handleMutations);
|
|
3348
|
+
mutationObserver.observe(document.body, LAYOUT_MUTATIONS);
|
|
3349
|
+
if (hasAssets()) tagAssets();
|
|
3350
|
+
syncGuard();
|
|
3351
|
+
debug8.log("visual editor started");
|
|
3352
|
+
}
|
|
3353
|
+
function stop() {
|
|
3354
|
+
if (!running) return;
|
|
3355
|
+
running = false;
|
|
3356
|
+
if (pointerFrame !== null) cancelAnimationFrame(pointerFrame);
|
|
3357
|
+
if (mutationFrame !== null) cancelAnimationFrame(mutationFrame);
|
|
3358
|
+
mutationObserver?.disconnect();
|
|
3359
|
+
mutationObserver = null;
|
|
3360
|
+
cancelFind();
|
|
3361
|
+
pointerFrame = null;
|
|
3362
|
+
mutationFrame = null;
|
|
3363
|
+
selection = null;
|
|
3364
|
+
lastPointerTarget = null;
|
|
3365
|
+
setSuspended(false);
|
|
3366
|
+
document.removeEventListener("pointermove", handlePointerMove);
|
|
3367
|
+
document.documentElement.removeEventListener(
|
|
3368
|
+
"pointerleave",
|
|
3369
|
+
handlePointerLeave
|
|
3370
|
+
);
|
|
3371
|
+
document.removeEventListener("click", handleClick, { capture: true });
|
|
3372
|
+
window.removeEventListener("keydown", handleKey);
|
|
3373
|
+
window.removeEventListener("keyup", handleKey);
|
|
3374
|
+
window.removeEventListener("blur", handleBlur);
|
|
3375
|
+
window.removeEventListener("scroll", handleScroll, { capture: true });
|
|
3376
|
+
window.removeEventListener("resize", handleResize);
|
|
3377
|
+
document.removeEventListener("transitionend", handleSettled, {
|
|
3378
|
+
capture: true
|
|
3379
|
+
});
|
|
3380
|
+
document.removeEventListener("animationend", handleSettled, {
|
|
3381
|
+
capture: true
|
|
3382
|
+
});
|
|
3383
|
+
document.querySelectorAll(`style[${CURSOR_STYLE_MARKER}]`).forEach((node) => node.remove());
|
|
3384
|
+
overlay.unmount();
|
|
3385
|
+
untagAssetImages();
|
|
3386
|
+
guard.stop();
|
|
3387
|
+
debug8.log("visual editor stopped");
|
|
3388
|
+
}
|
|
3389
|
+
function cancelFind() {
|
|
3390
|
+
if (findTimeout) clearTimeout(findTimeout);
|
|
3391
|
+
findTimeout = null;
|
|
3392
|
+
settlePendingFind?.();
|
|
3393
|
+
settlePendingFind = null;
|
|
3394
|
+
}
|
|
3395
|
+
function focusField(lookup) {
|
|
3396
|
+
cancelFind();
|
|
3397
|
+
return new Promise((resolve2) => {
|
|
3398
|
+
let attempt = 0;
|
|
3399
|
+
const finish = (found) => {
|
|
3400
|
+
settlePendingFind = null;
|
|
3401
|
+
resolve2(found);
|
|
3402
|
+
};
|
|
3403
|
+
settlePendingFind = () => resolve2(false);
|
|
3404
|
+
const tryFind = () => {
|
|
3405
|
+
findTimeout = null;
|
|
3406
|
+
const found = findFieldElement(lookup);
|
|
3407
|
+
if (found) {
|
|
3408
|
+
const el = lookup.block !== void 0 ? nthListItem(found, lookup.block) ?? found : found;
|
|
3409
|
+
scrollIntoFrame(el);
|
|
3410
|
+
if (running && isCurrentItem(found)) select(el, found, lookup.block);
|
|
3411
|
+
finish(true);
|
|
3412
|
+
return;
|
|
3413
|
+
}
|
|
3414
|
+
if (++attempt >= FIND_RETRIES) {
|
|
3415
|
+
debug8.log("no element renders field", lookup.field);
|
|
3416
|
+
finish(false);
|
|
3417
|
+
return;
|
|
3418
|
+
}
|
|
3419
|
+
findTimeout = setTimeout(tryFind, FIND_RETRY_MS);
|
|
3420
|
+
};
|
|
3421
|
+
tryFind();
|
|
3422
|
+
});
|
|
3423
|
+
}
|
|
3424
|
+
function setCurrentItem(itemId, referenceList, componentIds) {
|
|
3425
|
+
if (itemId !== scope.currentItemId()) forgetRemoved();
|
|
3426
|
+
scope.setCurrentItem(itemId);
|
|
3427
|
+
if (referenceList) setReferences(referenceList, componentIds);
|
|
3428
|
+
else if (componentIds) scope.setComponents(componentIds);
|
|
3429
|
+
if (running && hasAssets()) tagAssets();
|
|
3430
|
+
const selected = overlay.getSelectedTarget();
|
|
3431
|
+
const owner = selected ? encodedFrom(selected) : null;
|
|
3432
|
+
if (owner && !isCurrentItem(owner)) clearSelection();
|
|
3433
|
+
}
|
|
3434
|
+
function setAssets(assets) {
|
|
3435
|
+
const hadAssets = hasAssets();
|
|
3436
|
+
const next = createAssetIndex(assets);
|
|
3437
|
+
for (const [key, asset] of assetIndex) {
|
|
3438
|
+
if (!next.has(key)) removedAssets.set(key, asset);
|
|
3439
|
+
}
|
|
3440
|
+
for (const key of next.keys()) removedAssets.delete(key);
|
|
3441
|
+
assetIndex = next;
|
|
3442
|
+
if (running && (hadAssets || hasAssets())) tagAssets();
|
|
3443
|
+
}
|
|
3444
|
+
function setReferences(referenceList, componentIds) {
|
|
3445
|
+
if (componentIds) scope.setComponents(componentIds);
|
|
3446
|
+
scope.setReferences(referenceList);
|
|
3447
|
+
}
|
|
3448
|
+
function setLocale(value) {
|
|
3449
|
+
locale = value;
|
|
3450
|
+
}
|
|
3451
|
+
function syncGuard() {
|
|
3452
|
+
if (running && guardEnabled) guard.start();
|
|
3453
|
+
else guard.stop();
|
|
3454
|
+
}
|
|
3455
|
+
function setNavigationGuard(enabled) {
|
|
3456
|
+
guardEnabled = enabled;
|
|
3457
|
+
syncGuard();
|
|
3458
|
+
}
|
|
3459
|
+
return {
|
|
3460
|
+
start,
|
|
3461
|
+
stop,
|
|
3462
|
+
setCurrentItem,
|
|
3463
|
+
setReferences,
|
|
3464
|
+
setAssets,
|
|
3465
|
+
itemSaved,
|
|
3466
|
+
setLocale,
|
|
3467
|
+
focusField,
|
|
3468
|
+
setNavigationGuard,
|
|
3469
|
+
allowNavigation: (href) => guard.allow(href)
|
|
3470
|
+
};
|
|
3471
|
+
}
|
|
3472
|
+
|
|
2127
3473
|
// src/core/create-preview.ts
|
|
2128
|
-
var
|
|
3474
|
+
var debug9 = createScopedLogger("create-preview");
|
|
2129
3475
|
var controllerStores = /* @__PURE__ */ new WeakMap();
|
|
2130
3476
|
function defaultNavigation() {
|
|
2131
3477
|
return {
|
|
@@ -2141,8 +3487,14 @@ function safeEditUrl(href) {
|
|
|
2141
3487
|
return null;
|
|
2142
3488
|
}
|
|
2143
3489
|
}
|
|
2144
|
-
function buildSegments(data) {
|
|
2145
|
-
return [
|
|
3490
|
+
function buildSegments(data, locale) {
|
|
3491
|
+
return [
|
|
3492
|
+
{
|
|
3493
|
+
_id: SEGMENT_ALL_OTHER_USERS,
|
|
3494
|
+
name: t("adaptiveContent.allOtherUsers", locale)
|
|
3495
|
+
},
|
|
3496
|
+
...data
|
|
3497
|
+
];
|
|
2146
3498
|
}
|
|
2147
3499
|
function resolveLocale(options) {
|
|
2148
3500
|
const explicit = options?.locale;
|
|
@@ -2163,11 +3515,23 @@ function createPreprPreview(opts = {}) {
|
|
|
2163
3515
|
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
2164
3516
|
return noop();
|
|
2165
3517
|
}
|
|
3518
|
+
if (options?.strictMode) {
|
|
3519
|
+
const shared = sharedState();
|
|
3520
|
+
shared.strictMode = true;
|
|
3521
|
+
if (shared.liveAnnouncedStrict === false) {
|
|
3522
|
+
sendPreprEvent(
|
|
3523
|
+
"live_ready",
|
|
3524
|
+
{ strictMode: true },
|
|
3525
|
+
{ allowUntrustedTarget: true }
|
|
3526
|
+
);
|
|
3527
|
+
shared.liveAnnouncedStrict = true;
|
|
3528
|
+
}
|
|
3529
|
+
}
|
|
2166
3530
|
const isIframe = window.parent !== window;
|
|
2167
3531
|
const search = new URLSearchParams(window.location.search);
|
|
2168
3532
|
const hideBar = search.get(PARAM_HIDE_BAR) === "true";
|
|
2169
3533
|
if (hideBar) {
|
|
2170
|
-
|
|
3534
|
+
debug9.log(`${PARAM_HIDE_BAR}=true \u2014 no visible toolbar`);
|
|
2171
3535
|
}
|
|
2172
3536
|
const mountUi = (options?.ui ?? true) && !isIframe && !hideBar;
|
|
2173
3537
|
const locale = resolveLocale(options);
|
|
@@ -2181,7 +3545,7 @@ function createPreprPreview(opts = {}) {
|
|
|
2181
3545
|
const store = createToolbarStore({
|
|
2182
3546
|
locale,
|
|
2183
3547
|
features,
|
|
2184
|
-
segments: features.segments ? buildSegments(props?.segments ?? props?.data ?? []) : [],
|
|
3548
|
+
segments: features.segments ? buildSegments(props?.segments ?? props?.data ?? [], locale) : [],
|
|
2185
3549
|
selectedSegment: features.segments ? props?.activeSegment ?? cookieSegment ?? null : null,
|
|
2186
3550
|
selectedVariant,
|
|
2187
3551
|
previewMode,
|
|
@@ -2191,39 +3555,55 @@ function createPreprPreview(opts = {}) {
|
|
|
2191
3555
|
let el = null;
|
|
2192
3556
|
if (mountUi) {
|
|
2193
3557
|
definePreprToolbar();
|
|
2194
|
-
el = document.createElement(
|
|
3558
|
+
el = document.createElement(TOOLBAR_TAG);
|
|
2195
3559
|
document.body.appendChild(el);
|
|
2196
3560
|
el.connect(store, (key) => t(key, locale));
|
|
2197
3561
|
}
|
|
2198
3562
|
const editingEnabled = features.editMode || isIframe;
|
|
2199
|
-
const
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
3563
|
+
const onEdit = ({
|
|
3564
|
+
href,
|
|
3565
|
+
id,
|
|
3566
|
+
field,
|
|
3567
|
+
locale: contentLocale,
|
|
3568
|
+
block,
|
|
3569
|
+
entryId,
|
|
3570
|
+
referenceField,
|
|
3571
|
+
linkHref
|
|
3572
|
+
}) => {
|
|
3573
|
+
const safeHref = href ? safeEditUrl(href) : null;
|
|
3574
|
+
if (href && !safeHref) {
|
|
3575
|
+
debug9.warn("ignored edit request with unsupported href scheme");
|
|
3576
|
+
return;
|
|
3577
|
+
}
|
|
3578
|
+
if (isIframe) {
|
|
3579
|
+
sendPreprEvent("field_edit_requested", {
|
|
3580
|
+
id,
|
|
3581
|
+
field,
|
|
3582
|
+
locale: contentLocale,
|
|
3583
|
+
...block !== void 0 && { block },
|
|
3584
|
+
...entryId && { entryId },
|
|
3585
|
+
...referenceField && { referenceField },
|
|
3586
|
+
...linkHref && { linkHref }
|
|
3587
|
+
});
|
|
3588
|
+
} else if (safeHref) {
|
|
3589
|
+
window.open(safeHref, "_blank", "noopener,noreferrer");
|
|
2222
3590
|
}
|
|
3591
|
+
};
|
|
3592
|
+
const visualEditor = isIframe ? createVisualEditor({
|
|
3593
|
+
onEdit,
|
|
3594
|
+
locale,
|
|
3595
|
+
onNavigationBlocked: (href) => sendPreprEvent("navigation_blocked", { href })
|
|
3596
|
+
}) : null;
|
|
3597
|
+
const stega = visualEditor ?? createStegaController({
|
|
3598
|
+
// The edit-mode marks and hover label are chrome, so they follow the
|
|
3599
|
+
// same decision as the bar: unwanted in a headless preview that asked
|
|
3600
|
+
// for no UI.
|
|
3601
|
+
tooltip: mountUi,
|
|
3602
|
+
onEdit,
|
|
3603
|
+
locale
|
|
2223
3604
|
});
|
|
2224
3605
|
const autoClean = createStegaAutoClean({
|
|
2225
|
-
enabled: options?.autoClean
|
|
2226
|
-
isHydrated: opts.isHydrated
|
|
3606
|
+
enabled: options?.autoClean
|
|
2227
3607
|
});
|
|
2228
3608
|
autoClean.start();
|
|
2229
3609
|
const handleChange = createChangeHandler({
|
|
@@ -2242,7 +3622,36 @@ function createPreprPreview(opts = {}) {
|
|
|
2242
3622
|
handleChange(before, state);
|
|
2243
3623
|
});
|
|
2244
3624
|
const bridge = createIframeBridge(store, {
|
|
2245
|
-
allowedEditorOrigins: options?.allowedEditorOrigins
|
|
3625
|
+
allowedEditorOrigins: options?.allowedEditorOrigins,
|
|
3626
|
+
onHandshake: ({
|
|
3627
|
+
itemId,
|
|
3628
|
+
referencedIds,
|
|
3629
|
+
componentIds,
|
|
3630
|
+
uiLocale,
|
|
3631
|
+
navigationGuard,
|
|
3632
|
+
assets
|
|
3633
|
+
}) => {
|
|
3634
|
+
if (uiLocale) visualEditor?.setLocale(uiLocale);
|
|
3635
|
+
visualEditor?.setCurrentItem(itemId ?? null, referencedIds, componentIds);
|
|
3636
|
+
visualEditor?.setNavigationGuard(navigationGuard === true);
|
|
3637
|
+
if (assets) visualEditor?.setAssets(assets);
|
|
3638
|
+
},
|
|
3639
|
+
onAssets: (assets) => visualEditor?.setAssets(assets),
|
|
3640
|
+
onAllowNavigation: (href) => visualEditor?.allowNavigation(href),
|
|
3641
|
+
onItemChanged: () => visualEditor?.itemSaved(),
|
|
3642
|
+
onReferences: (referencedIds, componentIds) => visualEditor?.setReferences(referencedIds, componentIds),
|
|
3643
|
+
// The editor selecting a field scrolls the matching element into view. The
|
|
3644
|
+
// lookup relies on the attributes the stega scan writes, so it finds
|
|
3645
|
+
// nothing until encoded content has been tagged.
|
|
3646
|
+
onScrollToField: ({ field, id, block, entryId, fieldById }) => {
|
|
3647
|
+
if (visualEditor) {
|
|
3648
|
+
void visualEditor.focusField({ field, id, block, entryId, fieldById });
|
|
3649
|
+
return;
|
|
3650
|
+
}
|
|
3651
|
+
if (!scrollToField({ field, id })) {
|
|
3652
|
+
debug9.log("no element on this page renders field", field);
|
|
3653
|
+
}
|
|
3654
|
+
}
|
|
2246
3655
|
});
|
|
2247
3656
|
sendPreprEvent(
|
|
2248
3657
|
"getScrollPosition",
|
|
@@ -2262,34 +3671,15 @@ function createPreprPreview(opts = {}) {
|
|
|
2262
3671
|
bridge.stop();
|
|
2263
3672
|
}
|
|
2264
3673
|
el?.remove();
|
|
2265
|
-
|
|
3674
|
+
debug9.log("preview destroyed");
|
|
2266
3675
|
}
|
|
2267
3676
|
const controller = { destroy };
|
|
2268
3677
|
controllerStores.set(controller, store);
|
|
2269
3678
|
return controller;
|
|
2270
3679
|
}
|
|
2271
3680
|
|
|
2272
|
-
// src/react/hydration.ts
|
|
2273
|
-
var PROPS_KEY_PREFIX = "__reactProps$";
|
|
2274
|
-
function reactProps(element) {
|
|
2275
|
-
for (const key of Object.keys(element)) {
|
|
2276
|
-
if (key.startsWith(PROPS_KEY_PREFIX)) {
|
|
2277
|
-
return element[key];
|
|
2278
|
-
}
|
|
2279
|
-
}
|
|
2280
|
-
return void 0;
|
|
2281
|
-
}
|
|
2282
|
-
function isReactHydrated(text) {
|
|
2283
|
-
for (let el = text.parentElement; el; el = el.parentElement) {
|
|
2284
|
-
const props = reactProps(el);
|
|
2285
|
-
if (!props) continue;
|
|
2286
|
-
return el === text.parentElement || props.dangerouslySetInnerHTML != null;
|
|
2287
|
-
}
|
|
2288
|
-
return true;
|
|
2289
|
-
}
|
|
2290
|
-
|
|
2291
3681
|
// src/version.ts
|
|
2292
|
-
var VERSION = "0.
|
|
3682
|
+
var VERSION = "1.0.0-rc.1";
|
|
2293
3683
|
|
|
2294
3684
|
// src/core/pixel.ts
|
|
2295
3685
|
var PIXEL_SCRIPT_URL = "https://cdn.tracking.prepr.io/js/prepr.min.js";
|
|
@@ -2337,12 +3727,7 @@ function PreprPreview({
|
|
|
2337
3727
|
...props
|
|
2338
3728
|
}) {
|
|
2339
3729
|
useEffect(() => {
|
|
2340
|
-
const preview = createPreprPreview({
|
|
2341
|
-
props,
|
|
2342
|
-
options,
|
|
2343
|
-
navigation,
|
|
2344
|
-
isHydrated: isReactHydrated
|
|
2345
|
-
});
|
|
3730
|
+
const preview = createPreprPreview({ props, options, navigation });
|
|
2346
3731
|
return () => preview.destroy();
|
|
2347
3732
|
}, []);
|
|
2348
3733
|
return null;
|