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