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