@strapi/content-manager 5.22.0 → 5.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/components/LeftMenu.js +13 -15
- package/dist/admin/components/LeftMenu.js.map +1 -1
- package/dist/admin/components/LeftMenu.mjs +14 -16
- package/dist/admin/components/LeftMenu.mjs.map +1 -1
- package/dist/admin/components/Widgets.js +15 -7
- package/dist/admin/components/Widgets.js.map +1 -1
- package/dist/admin/components/Widgets.mjs +15 -7
- package/dist/admin/components/Widgets.mjs.map +1 -1
- package/dist/admin/pages/EditView/EditViewPage.js +11 -16
- package/dist/admin/pages/EditView/EditViewPage.js.map +1 -1
- package/dist/admin/pages/EditView/EditViewPage.mjs +12 -17
- package/dist/admin/pages/EditView/EditViewPage.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/Blocker.js +18 -0
- package/dist/admin/pages/EditView/components/Blocker.js.map +1 -0
- package/dist/admin/pages/EditView/components/Blocker.mjs +16 -0
- package/dist/admin/pages/EditView/components/Blocker.mjs.map +1 -0
- package/dist/admin/pages/EditView/components/DocumentActions.js +16 -1
- package/dist/admin/pages/EditView/components/DocumentActions.js.map +1 -1
- package/dist/admin/pages/EditView/components/DocumentActions.mjs +17 -2
- package/dist/admin/pages/EditView/components/DocumentActions.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/InputRenderer.js +15 -5
- package/dist/admin/pages/EditView/components/InputRenderer.js.map +1 -1
- package/dist/admin/pages/EditView/components/InputRenderer.mjs +15 -5
- package/dist/admin/pages/EditView/components/InputRenderer.mjs.map +1 -1
- package/dist/admin/pages/EditView/utils/data.js +26 -7
- package/dist/admin/pages/EditView/utils/data.js.map +1 -1
- package/dist/admin/pages/EditView/utils/data.mjs +26 -7
- package/dist/admin/pages/EditView/utils/data.mjs.map +1 -1
- package/dist/admin/pages/ListView/ListViewPage.js +6 -2
- package/dist/admin/pages/ListView/ListViewPage.js.map +1 -1
- package/dist/admin/pages/ListView/ListViewPage.mjs +6 -2
- package/dist/admin/pages/ListView/ListViewPage.mjs.map +1 -1
- package/dist/admin/preview/components/InputPopover.js +73 -0
- package/dist/admin/preview/components/InputPopover.js.map +1 -0
- package/dist/admin/preview/components/InputPopover.mjs +70 -0
- package/dist/admin/preview/components/InputPopover.mjs.map +1 -0
- package/dist/admin/preview/hooks/usePreviewInputManager.js +67 -0
- package/dist/admin/preview/hooks/usePreviewInputManager.js.map +1 -0
- package/dist/admin/preview/hooks/usePreviewInputManager.mjs +46 -0
- package/dist/admin/preview/hooks/usePreviewInputManager.mjs.map +1 -0
- package/dist/admin/preview/pages/Preview.js +119 -118
- package/dist/admin/preview/pages/Preview.js.map +1 -1
- package/dist/admin/preview/pages/Preview.mjs +120 -119
- package/dist/admin/preview/pages/Preview.mjs.map +1 -1
- package/dist/admin/preview/utils/constants.js +2 -1
- package/dist/admin/preview/utils/constants.js.map +1 -1
- package/dist/admin/preview/utils/constants.mjs +2 -2
- package/dist/admin/preview/utils/constants.mjs.map +1 -1
- package/dist/admin/preview/utils/getSendMessage.js +22 -0
- package/dist/admin/preview/utils/getSendMessage.js.map +1 -0
- package/dist/admin/preview/utils/getSendMessage.mjs +20 -0
- package/dist/admin/preview/utils/getSendMessage.mjs.map +1 -0
- package/dist/admin/preview/utils/previewScript.js +272 -4
- package/dist/admin/preview/utils/previewScript.js.map +1 -1
- package/dist/admin/preview/utils/previewScript.mjs +272 -4
- package/dist/admin/preview/utils/previewScript.mjs.map +1 -1
- package/dist/admin/services/documents.js +0 -1
- package/dist/admin/services/documents.js.map +1 -1
- package/dist/admin/services/documents.mjs +0 -1
- package/dist/admin/services/documents.mjs.map +1 -1
- package/dist/admin/src/pages/EditView/components/Blocker.d.ts +5 -0
- package/dist/admin/src/pages/EditView/components/InputRenderer.d.ts +1 -1
- package/dist/admin/src/preview/components/InputPopover.d.ts +6 -0
- package/dist/admin/src/preview/hooks/usePreviewInputManager.d.ts +4 -0
- package/dist/admin/src/preview/pages/Preview.d.ts +8 -0
- package/dist/admin/src/preview/utils/constants.d.ts +4 -1
- package/dist/admin/src/preview/utils/getSendMessage.d.ts +11 -0
- package/dist/admin/src/preview/utils/previewScript.d.ts +7 -1
- package/dist/admin/translations/en.json.js +1 -0
- package/dist/admin/translations/en.json.js.map +1 -1
- package/dist/admin/translations/en.json.mjs +1 -0
- package/dist/admin/translations/en.json.mjs.map +1 -1
- package/dist/admin/translations/es.json.js +1 -0
- package/dist/admin/translations/es.json.js.map +1 -1
- package/dist/admin/translations/es.json.mjs +1 -0
- package/dist/admin/translations/es.json.mjs.map +1 -1
- package/dist/admin/translations/fr.json.js +1 -0
- package/dist/admin/translations/fr.json.js.map +1 -1
- package/dist/admin/translations/fr.json.mjs +1 -0
- package/dist/admin/translations/fr.json.mjs.map +1 -1
- package/dist/server/homepage/services/homepage.js +2 -2
- package/dist/server/homepage/services/homepage.js.map +1 -1
- package/dist/server/homepage/services/homepage.mjs +2 -2
- package/dist/server/homepage/services/homepage.mjs.map +1 -1
- package/dist/server/src/homepage/services/homepage.d.ts.map +1 -1
- package/package.json +5 -5
@@ -7,7 +7,7 @@ const scriptResponse = previewScript.previewScript(false);
|
|
7
7
|
* These events can be changed safely. They're used by the content manager admin on one side, and by
|
8
8
|
* the preview script on the other. We own both ends, and they're not documented to users, so we can
|
9
9
|
* do what we want with them.
|
10
|
-
*/ scriptResponse.INTERNAL_EVENTS;
|
10
|
+
*/ const INTERNAL_EVENTS = scriptResponse.INTERNAL_EVENTS;
|
11
11
|
/**
|
12
12
|
* These events are documented to users, and will be hardcoded in their frontends.
|
13
13
|
* Changing any of these would be a breaking change.
|
@@ -17,5 +17,6 @@ const scriptResponse = previewScript.previewScript(false);
|
|
17
17
|
STRAPI_SCRIPT: 'strapiScript'
|
18
18
|
};
|
19
19
|
|
20
|
+
exports.INTERNAL_EVENTS = INTERNAL_EVENTS;
|
20
21
|
exports.PUBLIC_EVENTS = PUBLIC_EVENTS;
|
21
22
|
//# sourceMappingURL=constants.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../../../../admin/src/preview/utils/constants.ts"],"sourcesContent":["import { previewScript } from './previewScript';\n\nconst scriptResponse = previewScript(false);\n\n/**\n * These events can be changed safely. They're used by the content manager admin on one side, and by\n * the preview script on the other. We own both ends, and they're not documented to users, so we can\n * do what we want with them.\n */\nexport const INTERNAL_EVENTS = scriptResponse!.INTERNAL_EVENTS;\n\n/**\n * These events are documented to users, and will be hardcoded in their frontends.\n * Changing any of these would be a breaking change.\n */\nexport const PUBLIC_EVENTS = {\n PREVIEW_READY: 'previewReady',\n STRAPI_UPDATE: 'strapiUpdate',\n STRAPI_SCRIPT: 'strapiScript',\n} as const;\n"],"names":["scriptResponse","previewScript","INTERNAL_EVENTS","PUBLIC_EVENTS","PREVIEW_READY","STRAPI_UPDATE","STRAPI_SCRIPT"],"mappings":";;;;AAEA,MAAMA,iBAAiBC,2BAAc,CAAA,KAAA,CAAA;AAErC;;;;AAIC,
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../../admin/src/preview/utils/constants.ts"],"sourcesContent":["import { previewScript } from './previewScript';\n\nconst scriptResponse = previewScript(false);\n\n/**\n * These events can be changed safely. They're used by the content manager admin on one side, and by\n * the preview script on the other. We own both ends, and they're not documented to users, so we can\n * do what we want with them.\n */\nexport const INTERNAL_EVENTS = scriptResponse!.INTERNAL_EVENTS;\n\n/**\n * These events are documented to users, and will be hardcoded in their frontends.\n * Changing any of these would be a breaking change.\n */\nexport const PUBLIC_EVENTS = {\n PREVIEW_READY: 'previewReady',\n STRAPI_UPDATE: 'strapiUpdate',\n STRAPI_SCRIPT: 'strapiScript',\n} as const;\n"],"names":["scriptResponse","previewScript","INTERNAL_EVENTS","PUBLIC_EVENTS","PREVIEW_READY","STRAPI_UPDATE","STRAPI_SCRIPT"],"mappings":";;;;AAEA,MAAMA,iBAAiBC,2BAAc,CAAA,KAAA,CAAA;AAErC;;;;AAIC,IACM,MAAMC,eAAkBF,GAAAA,cAAAA,CAAgBE;AAE/C;;;UAIaC,aAAgB,GAAA;IAC3BC,aAAe,EAAA,cAAA;IACfC,aAAe,EAAA,cAAA;IACfC,aAAe,EAAA;AACjB;;;;;"}
|
@@ -5,7 +5,7 @@ const scriptResponse = previewScript(false);
|
|
5
5
|
* These events can be changed safely. They're used by the content manager admin on one side, and by
|
6
6
|
* the preview script on the other. We own both ends, and they're not documented to users, so we can
|
7
7
|
* do what we want with them.
|
8
|
-
*/ scriptResponse.INTERNAL_EVENTS;
|
8
|
+
*/ const INTERNAL_EVENTS = scriptResponse.INTERNAL_EVENTS;
|
9
9
|
/**
|
10
10
|
* These events are documented to users, and will be hardcoded in their frontends.
|
11
11
|
* Changing any of these would be a breaking change.
|
@@ -15,5 +15,5 @@ const scriptResponse = previewScript(false);
|
|
15
15
|
STRAPI_SCRIPT: 'strapiScript'
|
16
16
|
};
|
17
17
|
|
18
|
-
export { PUBLIC_EVENTS };
|
18
|
+
export { INTERNAL_EVENTS, PUBLIC_EVENTS };
|
19
19
|
//# sourceMappingURL=constants.mjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"constants.mjs","sources":["../../../../admin/src/preview/utils/constants.ts"],"sourcesContent":["import { previewScript } from './previewScript';\n\nconst scriptResponse = previewScript(false);\n\n/**\n * These events can be changed safely. They're used by the content manager admin on one side, and by\n * the preview script on the other. We own both ends, and they're not documented to users, so we can\n * do what we want with them.\n */\nexport const INTERNAL_EVENTS = scriptResponse!.INTERNAL_EVENTS;\n\n/**\n * These events are documented to users, and will be hardcoded in their frontends.\n * Changing any of these would be a breaking change.\n */\nexport const PUBLIC_EVENTS = {\n PREVIEW_READY: 'previewReady',\n STRAPI_UPDATE: 'strapiUpdate',\n STRAPI_SCRIPT: 'strapiScript',\n} as const;\n"],"names":["scriptResponse","previewScript","INTERNAL_EVENTS","PUBLIC_EVENTS","PREVIEW_READY","STRAPI_UPDATE","STRAPI_SCRIPT"],"mappings":";;AAEA,MAAMA,iBAAiBC,aAAc,CAAA,KAAA,CAAA;AAErC;;;;AAIC,
|
1
|
+
{"version":3,"file":"constants.mjs","sources":["../../../../admin/src/preview/utils/constants.ts"],"sourcesContent":["import { previewScript } from './previewScript';\n\nconst scriptResponse = previewScript(false);\n\n/**\n * These events can be changed safely. They're used by the content manager admin on one side, and by\n * the preview script on the other. We own both ends, and they're not documented to users, so we can\n * do what we want with them.\n */\nexport const INTERNAL_EVENTS = scriptResponse!.INTERNAL_EVENTS;\n\n/**\n * These events are documented to users, and will be hardcoded in their frontends.\n * Changing any of these would be a breaking change.\n */\nexport const PUBLIC_EVENTS = {\n PREVIEW_READY: 'previewReady',\n STRAPI_UPDATE: 'strapiUpdate',\n STRAPI_SCRIPT: 'strapiScript',\n} as const;\n"],"names":["scriptResponse","previewScript","INTERNAL_EVENTS","PUBLIC_EVENTS","PREVIEW_READY","STRAPI_UPDATE","STRAPI_SCRIPT"],"mappings":";;AAEA,MAAMA,iBAAiBC,aAAc,CAAA,KAAA,CAAA;AAErC;;;;AAIC,IACM,MAAMC,eAAkBF,GAAAA,cAAAA,CAAgBE;AAE/C;;;UAIaC,aAAgB,GAAA;IAC3BC,aAAe,EAAA,cAAA;IACfC,aAAe,EAAA,cAAA;IACfC,aAAe,EAAA;AACjB;;;;"}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* A function factory so we can generate a new sendMessage everytime we need one.
|
5
|
+
* We can't store and reuse a single sendMessage because it needs to have a stable identity
|
6
|
+
* as it used in a useEffect function. And we can't rely on useCallback because we need the
|
7
|
+
* up-to-date iframe ref, and this would make it stale (refs don't trigger callback reevaluations).
|
8
|
+
*/ function getSendMessage(iframe) {
|
9
|
+
return (type, payload)=>{
|
10
|
+
if (!iframe?.current) return;
|
11
|
+
const { origin } = new URL(iframe.current.src);
|
12
|
+
iframe.current.contentWindow?.postMessage({
|
13
|
+
type,
|
14
|
+
...payload !== undefined && {
|
15
|
+
payload
|
16
|
+
}
|
17
|
+
}, origin);
|
18
|
+
};
|
19
|
+
}
|
20
|
+
|
21
|
+
exports.getSendMessage = getSendMessage;
|
22
|
+
//# sourceMappingURL=getSendMessage.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"getSendMessage.js","sources":["../../../../admin/src/preview/utils/getSendMessage.ts"],"sourcesContent":["import type { INTERNAL_EVENTS, PUBLIC_EVENTS } from './constants';\n\ntype MessageType =\n | (typeof INTERNAL_EVENTS)[keyof typeof INTERNAL_EVENTS]\n | (typeof PUBLIC_EVENTS)[keyof typeof PUBLIC_EVENTS];\n\n/**\n * A function factory so we can generate a new sendMessage everytime we need one.\n * We can't store and reuse a single sendMessage because it needs to have a stable identity\n * as it used in a useEffect function. And we can't rely on useCallback because we need the\n * up-to-date iframe ref, and this would make it stale (refs don't trigger callback reevaluations).\n */\nexport function getSendMessage(iframe: React.RefObject<HTMLIFrameElement> | undefined) {\n return (type: MessageType, payload?: unknown) => {\n if (!iframe?.current) return;\n\n const { origin } = new URL(iframe.current.src);\n\n iframe.current.contentWindow?.postMessage(\n {\n type,\n ...(payload !== undefined && { payload }),\n },\n origin\n );\n };\n}\n"],"names":["getSendMessage","iframe","type","payload","current","origin","URL","src","contentWindow","postMessage","undefined"],"mappings":";;AAMA;;;;;IAMO,SAASA,cAAAA,CAAeC,MAAsD,EAAA;AACnF,IAAA,OAAO,CAACC,IAAmBC,EAAAA,OAAAA,GAAAA;QACzB,IAAI,CAACF,QAAQG,OAAS,EAAA;QAEtB,MAAM,EAAEC,MAAM,EAAE,GAAG,IAAIC,GAAIL,CAAAA,MAAAA,CAAOG,OAAO,CAACG,GAAG,CAAA;AAE7CN,QAAAA,MAAAA,CAAOG,OAAO,CAACI,aAAa,EAAEC,WAC5B,CAAA;AACEP,YAAAA,IAAAA;AACA,YAAA,GAAIC,YAAYO,SAAa,IAAA;AAAEP,gBAAAA;;SAEjCE,EAAAA,MAAAA,CAAAA;AAEJ,KAAA;AACF;;;;"}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
/**
|
2
|
+
* A function factory so we can generate a new sendMessage everytime we need one.
|
3
|
+
* We can't store and reuse a single sendMessage because it needs to have a stable identity
|
4
|
+
* as it used in a useEffect function. And we can't rely on useCallback because we need the
|
5
|
+
* up-to-date iframe ref, and this would make it stale (refs don't trigger callback reevaluations).
|
6
|
+
*/ function getSendMessage(iframe) {
|
7
|
+
return (type, payload)=>{
|
8
|
+
if (!iframe?.current) return;
|
9
|
+
const { origin } = new URL(iframe.current.src);
|
10
|
+
iframe.current.contentWindow?.postMessage({
|
11
|
+
type,
|
12
|
+
...payload !== undefined && {
|
13
|
+
payload
|
14
|
+
}
|
15
|
+
}, origin);
|
16
|
+
};
|
17
|
+
}
|
18
|
+
|
19
|
+
export { getSendMessage };
|
20
|
+
//# sourceMappingURL=getSendMessage.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"getSendMessage.mjs","sources":["../../../../admin/src/preview/utils/getSendMessage.ts"],"sourcesContent":["import type { INTERNAL_EVENTS, PUBLIC_EVENTS } from './constants';\n\ntype MessageType =\n | (typeof INTERNAL_EVENTS)[keyof typeof INTERNAL_EVENTS]\n | (typeof PUBLIC_EVENTS)[keyof typeof PUBLIC_EVENTS];\n\n/**\n * A function factory so we can generate a new sendMessage everytime we need one.\n * We can't store and reuse a single sendMessage because it needs to have a stable identity\n * as it used in a useEffect function. And we can't rely on useCallback because we need the\n * up-to-date iframe ref, and this would make it stale (refs don't trigger callback reevaluations).\n */\nexport function getSendMessage(iframe: React.RefObject<HTMLIFrameElement> | undefined) {\n return (type: MessageType, payload?: unknown) => {\n if (!iframe?.current) return;\n\n const { origin } = new URL(iframe.current.src);\n\n iframe.current.contentWindow?.postMessage(\n {\n type,\n ...(payload !== undefined && { payload }),\n },\n origin\n );\n };\n}\n"],"names":["getSendMessage","iframe","type","payload","current","origin","URL","src","contentWindow","postMessage","undefined"],"mappings":"AAMA;;;;;IAMO,SAASA,cAAAA,CAAeC,MAAsD,EAAA;AACnF,IAAA,OAAO,CAACC,IAAmBC,EAAAA,OAAAA,GAAAA;QACzB,IAAI,CAACF,QAAQG,OAAS,EAAA;QAEtB,MAAM,EAAEC,MAAM,EAAE,GAAG,IAAIC,GAAIL,CAAAA,MAAAA,CAAOG,OAAO,CAACG,GAAG,CAAA;AAE7CN,QAAAA,MAAAA,CAAOG,OAAO,CAACI,aAAa,EAAEC,WAC5B,CAAA;AACEP,YAAAA,IAAAA;AACA,YAAA,GAAIC,YAAYO,SAAa,IAAA;AAAEP,gBAAAA;;SAEjCE,EAAAA,MAAAA,CAAAA;AAEJ,KAAA;AACF;;;;"}
|
@@ -7,8 +7,18 @@
|
|
7
7
|
* It's why many functions are defined within previewScript, it's the only way to avoid going full spaghetti.
|
8
8
|
* To get a better overview of everything previewScript does, go to the orchestration part at its end.
|
9
9
|
*/ const previewScript = (shouldRun = true)=>{
|
10
|
+
/* -----------------------------------------------------------------------------------------------
|
11
|
+
* Params
|
12
|
+
* ---------------------------------------------------------------------------------------------*/ const HIGHLIGHT_PADDING = 2; // in pixels
|
13
|
+
const HIGHLIGHT_HOVER_COLOR = window.STRAPI_HIGHLIGHT_HOVER_COLOR ?? '#4945ff'; // dark primary500
|
14
|
+
const HIGHLIGHT_ACTIVE_COLOR = window.STRAPI_HIGHLIGHT_ACTIVE_COLOR ?? '#7b79ff'; // dark primary600
|
15
|
+
const SOURCE_ATTRIBUTE = 'data-strapi-source';
|
16
|
+
const OVERLAY_ID = 'strapi-preview-overlay';
|
10
17
|
const INTERNAL_EVENTS = {
|
11
|
-
|
18
|
+
STRAPI_FIELD_FOCUS: 'strapiFieldFocus',
|
19
|
+
STRAPI_FIELD_BLUR: 'strapiFieldBlur',
|
20
|
+
STRAPI_FIELD_CHANGE: 'strapiFieldChange',
|
21
|
+
STRAPI_FIELD_FOCUS_INTENT: 'strapiFieldFocusIntent'
|
12
22
|
};
|
13
23
|
/**
|
14
24
|
* Calling the function in no-run mode lets us retrieve the constants from other files and keep
|
@@ -19,9 +29,267 @@
|
|
19
29
|
INTERNAL_EVENTS
|
20
30
|
};
|
21
31
|
}
|
22
|
-
|
23
|
-
|
24
|
-
|
32
|
+
/* -----------------------------------------------------------------------------------------------
|
33
|
+
* Utils
|
34
|
+
* ---------------------------------------------------------------------------------------------*/ const sendMessage = (type, payload)=>{
|
35
|
+
window.parent.postMessage({
|
36
|
+
type,
|
37
|
+
payload
|
38
|
+
}, '*');
|
39
|
+
};
|
40
|
+
/* -----------------------------------------------------------------------------------------------
|
41
|
+
* Functionality pieces
|
42
|
+
* ---------------------------------------------------------------------------------------------*/ const createOverlaySystem = ()=>{
|
43
|
+
// Clean up before creating a new overlay so we can safely call previewScript multiple times
|
44
|
+
window.__strapi_previewCleanup?.();
|
45
|
+
document.getElementById(OVERLAY_ID)?.remove();
|
46
|
+
const overlay = document.createElement('div');
|
47
|
+
overlay.id = OVERLAY_ID;
|
48
|
+
overlay.style.cssText = `
|
49
|
+
position: fixed;
|
50
|
+
top: 0;
|
51
|
+
left: 0;
|
52
|
+
width: 100%;
|
53
|
+
height: 100%;
|
54
|
+
pointer-events: none;
|
55
|
+
z-index: 9999;
|
56
|
+
`;
|
57
|
+
window.document.body.appendChild(overlay);
|
58
|
+
return overlay;
|
59
|
+
};
|
60
|
+
const createHighlightManager = (overlay)=>{
|
61
|
+
const elements = window.document.querySelectorAll(`[${SOURCE_ATTRIBUTE}]`);
|
62
|
+
const eventListeners = [];
|
63
|
+
const highlights = [];
|
64
|
+
const focusedHighlights = [];
|
65
|
+
let focusedField = null;
|
66
|
+
const drawHighlight = (target, highlight)=>{
|
67
|
+
if (!highlight) return;
|
68
|
+
const rect = target.getBoundingClientRect();
|
69
|
+
highlight.style.width = `${rect.width + HIGHLIGHT_PADDING * 2}px`;
|
70
|
+
highlight.style.height = `${rect.height + HIGHLIGHT_PADDING * 2}px`;
|
71
|
+
highlight.style.transform = `translate(${rect.left - HIGHLIGHT_PADDING}px, ${rect.top - HIGHLIGHT_PADDING}px)`;
|
72
|
+
};
|
73
|
+
const updateAllHighlights = ()=>{
|
74
|
+
highlights.forEach((highlight, index)=>{
|
75
|
+
const element = elements[index];
|
76
|
+
if (element && highlight) {
|
77
|
+
drawHighlight(element, highlight);
|
78
|
+
}
|
79
|
+
});
|
80
|
+
};
|
81
|
+
elements.forEach((element)=>{
|
82
|
+
if (element instanceof HTMLElement) {
|
83
|
+
const highlight = document.createElement('div');
|
84
|
+
highlight.style.cssText = `
|
85
|
+
position: absolute;
|
86
|
+
outline: 2px solid transparent;
|
87
|
+
pointer-events: none;
|
88
|
+
border-radius: 2px;
|
89
|
+
background-color: transparent;
|
90
|
+
will-change: transform;
|
91
|
+
transition: outline-color 0.1s ease-in-out;
|
92
|
+
`;
|
93
|
+
// Move hover detection to the underlying element
|
94
|
+
const mouseEnterHandler = ()=>{
|
95
|
+
if (!highlightManager.focusedHighlights.includes(highlight)) {
|
96
|
+
highlight.style.outlineColor = HIGHLIGHT_HOVER_COLOR;
|
97
|
+
}
|
98
|
+
};
|
99
|
+
const mouseLeaveHandler = ()=>{
|
100
|
+
if (!highlightManager.focusedHighlights.includes(highlight)) {
|
101
|
+
highlight.style.outlineColor = 'transparent';
|
102
|
+
}
|
103
|
+
};
|
104
|
+
const doubleClickHandler = ()=>{
|
105
|
+
const sourceAttribute = element.getAttribute(SOURCE_ATTRIBUTE);
|
106
|
+
if (sourceAttribute) {
|
107
|
+
const rect = element.getBoundingClientRect();
|
108
|
+
sendMessage(INTERNAL_EVENTS.STRAPI_FIELD_FOCUS_INTENT, {
|
109
|
+
path: sourceAttribute,
|
110
|
+
position: {
|
111
|
+
top: rect.top,
|
112
|
+
left: rect.left,
|
113
|
+
right: rect.right,
|
114
|
+
bottom: rect.bottom,
|
115
|
+
width: rect.width,
|
116
|
+
height: rect.height
|
117
|
+
}
|
118
|
+
});
|
119
|
+
}
|
120
|
+
};
|
121
|
+
const mouseDownHandler = (event)=>{
|
122
|
+
// Prevent default multi click to select behavior
|
123
|
+
if (event.detail >= 2) {
|
124
|
+
event.preventDefault();
|
125
|
+
}
|
126
|
+
};
|
127
|
+
element.addEventListener('mouseenter', mouseEnterHandler);
|
128
|
+
element.addEventListener('mouseleave', mouseLeaveHandler);
|
129
|
+
element.addEventListener('dblclick', doubleClickHandler);
|
130
|
+
element.addEventListener('mousedown', mouseDownHandler);
|
131
|
+
// Store event listeners for cleanup
|
132
|
+
eventListeners.push({
|
133
|
+
element,
|
134
|
+
type: 'mouseenter',
|
135
|
+
handler: mouseEnterHandler
|
136
|
+
}, {
|
137
|
+
element,
|
138
|
+
type: 'mouseleave',
|
139
|
+
handler: mouseLeaveHandler
|
140
|
+
}, {
|
141
|
+
element,
|
142
|
+
type: 'dblclick',
|
143
|
+
handler: doubleClickHandler
|
144
|
+
}, {
|
145
|
+
element,
|
146
|
+
type: 'mousedown',
|
147
|
+
handler: mouseDownHandler
|
148
|
+
});
|
149
|
+
highlights.push(highlight);
|
150
|
+
overlay.appendChild(highlight);
|
151
|
+
drawHighlight(element, highlight);
|
152
|
+
}
|
153
|
+
});
|
154
|
+
return {
|
155
|
+
elements,
|
156
|
+
updateAllHighlights,
|
157
|
+
eventListeners,
|
158
|
+
highlights,
|
159
|
+
focusedHighlights,
|
160
|
+
setFocusedField: (field)=>{
|
161
|
+
focusedField = field;
|
162
|
+
},
|
163
|
+
getFocusedField: ()=>focusedField
|
164
|
+
};
|
165
|
+
};
|
166
|
+
const setupObservers = (highlightManager)=>{
|
167
|
+
const resizeObserver = new ResizeObserver(()=>{
|
168
|
+
highlightManager.updateAllHighlights();
|
169
|
+
});
|
170
|
+
highlightManager.elements.forEach((element)=>{
|
171
|
+
resizeObserver.observe(element);
|
172
|
+
});
|
173
|
+
resizeObserver.observe(document.documentElement);
|
174
|
+
const updateOnScroll = ()=>{
|
175
|
+
highlightManager.updateAllHighlights();
|
176
|
+
};
|
177
|
+
const scrollableElements = new Set();
|
178
|
+
scrollableElements.add(window);
|
179
|
+
// Find all scrollable ancestors for all tracked elements
|
180
|
+
highlightManager.elements.forEach((element)=>{
|
181
|
+
let parent = element.parentElement;
|
182
|
+
while(parent){
|
183
|
+
const computedStyle = window.getComputedStyle(parent);
|
184
|
+
const overflow = computedStyle.overflow + computedStyle.overflowX + computedStyle.overflowY;
|
185
|
+
if (overflow.includes('scroll') || overflow.includes('auto')) {
|
186
|
+
scrollableElements.add(parent);
|
187
|
+
}
|
188
|
+
parent = parent.parentElement;
|
189
|
+
}
|
190
|
+
});
|
191
|
+
// Add scroll listeners to all scrollable elements
|
192
|
+
scrollableElements.forEach((element)=>{
|
193
|
+
if (element === window) {
|
194
|
+
window.addEventListener('scroll', updateOnScroll);
|
195
|
+
window.addEventListener('resize', updateOnScroll);
|
196
|
+
} else {
|
197
|
+
element.addEventListener('scroll', updateOnScroll);
|
198
|
+
}
|
199
|
+
});
|
200
|
+
return {
|
201
|
+
resizeObserver,
|
202
|
+
updateOnScroll,
|
203
|
+
scrollableElements
|
204
|
+
};
|
205
|
+
};
|
206
|
+
const setupEventHandlers = (highlightManager)=>{
|
207
|
+
const handleMessage = (event)=>{
|
208
|
+
if (!event.data?.type) return;
|
209
|
+
// The user typed in an input, reflect the change in the preview
|
210
|
+
if (event.data.type === INTERNAL_EVENTS.STRAPI_FIELD_CHANGE) {
|
211
|
+
const { field, value } = event.data.payload;
|
212
|
+
if (!field) return;
|
213
|
+
const matchingElements = document.querySelectorAll(`[${SOURCE_ATTRIBUTE}="${field}"]`);
|
214
|
+
matchingElements.forEach((element)=>{
|
215
|
+
if (element instanceof HTMLElement) {
|
216
|
+
element.textContent = value || '';
|
217
|
+
}
|
218
|
+
});
|
219
|
+
return;
|
220
|
+
}
|
221
|
+
// The user focused a new input, update the highlights in the preview
|
222
|
+
if (event.data.type === INTERNAL_EVENTS.STRAPI_FIELD_FOCUS) {
|
223
|
+
const { field } = event.data.payload;
|
224
|
+
if (!field) return;
|
225
|
+
// Clear existing focused highlights
|
226
|
+
highlightManager.focusedHighlights.forEach((highlight)=>{
|
227
|
+
highlight.style.outlineColor = 'transparent';
|
228
|
+
});
|
229
|
+
highlightManager.focusedHighlights.length = 0;
|
230
|
+
// Set new focused field and highlight matching elements
|
231
|
+
highlightManager.setFocusedField(field);
|
232
|
+
const matchingElements = document.querySelectorAll(`[${SOURCE_ATTRIBUTE}="${field}"]`);
|
233
|
+
matchingElements.forEach((element)=>{
|
234
|
+
const highlight = highlightManager.highlights[Array.from(highlightManager.elements).indexOf(element)];
|
235
|
+
if (highlight) {
|
236
|
+
highlight.style.outlineColor = HIGHLIGHT_ACTIVE_COLOR;
|
237
|
+
highlight.style.outlineWidth = '3px';
|
238
|
+
highlightManager.focusedHighlights.push(highlight);
|
239
|
+
}
|
240
|
+
});
|
241
|
+
return;
|
242
|
+
}
|
243
|
+
// The user is no longer focusing an input, remove the highlights
|
244
|
+
if (event.data.type === INTERNAL_EVENTS.STRAPI_FIELD_BLUR) {
|
245
|
+
const { field } = event.data.payload;
|
246
|
+
if (field !== highlightManager.getFocusedField()) return;
|
247
|
+
highlightManager.focusedHighlights.forEach((highlight)=>{
|
248
|
+
highlight.style.outlineColor = 'transparent';
|
249
|
+
highlight.style.outlineWidth = '2px';
|
250
|
+
});
|
251
|
+
highlightManager.focusedHighlights.length = 0;
|
252
|
+
highlightManager.setFocusedField(null);
|
253
|
+
}
|
254
|
+
};
|
255
|
+
window.addEventListener('message', handleMessage);
|
256
|
+
// Add the message handler to the cleanup list
|
257
|
+
const messageEventListener = {
|
258
|
+
element: window,
|
259
|
+
type: 'message',
|
260
|
+
handler: handleMessage
|
261
|
+
};
|
262
|
+
return [
|
263
|
+
...highlightManager.eventListeners,
|
264
|
+
messageEventListener
|
265
|
+
];
|
266
|
+
};
|
267
|
+
const createCleanupSystem = (overlay, observers, eventHandlers)=>{
|
268
|
+
window.__strapi_previewCleanup = ()=>{
|
269
|
+
observers.resizeObserver.disconnect();
|
270
|
+
// Remove all scroll listeners
|
271
|
+
observers.scrollableElements.forEach((element)=>{
|
272
|
+
if (element === window) {
|
273
|
+
window.removeEventListener('scroll', observers.updateOnScroll);
|
274
|
+
window.removeEventListener('resize', observers.updateOnScroll);
|
275
|
+
} else {
|
276
|
+
element.removeEventListener('scroll', observers.updateOnScroll);
|
277
|
+
}
|
278
|
+
});
|
279
|
+
// Remove highlight event listeners
|
280
|
+
eventHandlers.forEach(({ element, type, handler })=>{
|
281
|
+
element.removeEventListener(type, handler);
|
282
|
+
});
|
283
|
+
overlay.remove();
|
284
|
+
};
|
285
|
+
};
|
286
|
+
/* -----------------------------------------------------------------------------------------------
|
287
|
+
* Orchestration
|
288
|
+
* ---------------------------------------------------------------------------------------------*/ const overlay = createOverlaySystem();
|
289
|
+
const highlightManager = createHighlightManager(overlay);
|
290
|
+
const observers = setupObservers(highlightManager);
|
291
|
+
const eventHandlers = setupEventHandlers(highlightManager);
|
292
|
+
createCleanupSystem(overlay, observers, eventHandlers);
|
25
293
|
};
|
26
294
|
|
27
295
|
exports.previewScript = previewScript;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"previewScript.js","sources":["../../../../admin/src/preview/utils/previewScript.ts"],"sourcesContent":["// NOTE: This override is for the properties on _user's site_, it's not about Strapi Admin.\ndeclare global {\n interface Window {}\n}\n\n/**\n * previewScript will be injected into the preview iframe after being stringified.\n * Therefore it CANNOT use any imports, or refer to any variables outside of its own scope.\n * It's why many functions are defined within previewScript, it's the only way to avoid going full spaghetti.\n * To get a better overview of everything previewScript does, go to the orchestration part at its end.\n */\nconst previewScript = (shouldRun = true) => {\n const INTERNAL_EVENTS = {\n DUMMY_EVENT: 'dummyEvent',\n } as const;\n\n /**\n * Calling the function in no-run mode lets us retrieve the constants from other files and keep\n * a single source of truth for them. It's the only way to do this because this script can't\n * refer to any variables outside of its own scope, because it's stringified before it's run.\n */\n if (!shouldRun) {\n return { INTERNAL_EVENTS };\n }\n\n // Live Preview logic will go here.\n // eslint-disable-next-line no-console\n console.log('Preview script running');\n};\n\nexport { previewScript };\n"],"names":["previewScript","shouldRun","INTERNAL_EVENTS","DUMMY_EVENT","console","log"],"mappings":";;AAAA;AAKA;;;;;AAKC,IACKA,MAAAA,aAAAA,GAAgB,CAACC,SAAAA,GAAY,IAAI,GAAA;AACrC,IAAA,MAAMC,eAAkB,GAAA;QACtBC,WAAa,EAAA;AACf,KAAA;AAEA;;;;MAKA,IAAI,CAACF,SAAW,EAAA;QACd,OAAO;AAAEC,YAAAA;AAAgB,SAAA;AAC3B;;;AAIAE,IAAAA,OAAAA,CAAQC,GAAG,CAAC,wBAAA,CAAA;AACd;;;;"}
|
1
|
+
{"version":3,"file":"previewScript.js","sources":["../../../../admin/src/preview/utils/previewScript.ts"],"sourcesContent":["// NOTE: This override is for the properties on _user's site_, it's not about Strapi Admin.\ndeclare global {\n interface Window {\n __strapi_previewCleanup?: () => void;\n STRAPI_HIGHLIGHT_HOVER_COLOR?: string;\n STRAPI_HIGHLIGHT_ACTIVE_COLOR?: string;\n }\n}\n\n/**\n * previewScript will be injected into the preview iframe after being stringified.\n * Therefore it CANNOT use any imports, or refer to any variables outside of its own scope.\n * It's why many functions are defined within previewScript, it's the only way to avoid going full spaghetti.\n * To get a better overview of everything previewScript does, go to the orchestration part at its end.\n */\nconst previewScript = (shouldRun = true) => {\n /* -----------------------------------------------------------------------------------------------\n * Params\n * ---------------------------------------------------------------------------------------------*/\n const HIGHLIGHT_PADDING = 2; // in pixels\n const HIGHLIGHT_HOVER_COLOR = window.STRAPI_HIGHLIGHT_HOVER_COLOR ?? '#4945ff'; // dark primary500\n const HIGHLIGHT_ACTIVE_COLOR = window.STRAPI_HIGHLIGHT_ACTIVE_COLOR ?? '#7b79ff'; // dark primary600\n\n const SOURCE_ATTRIBUTE = 'data-strapi-source';\n const OVERLAY_ID = 'strapi-preview-overlay';\n const INTERNAL_EVENTS = {\n STRAPI_FIELD_FOCUS: 'strapiFieldFocus',\n STRAPI_FIELD_BLUR: 'strapiFieldBlur',\n STRAPI_FIELD_CHANGE: 'strapiFieldChange',\n STRAPI_FIELD_FOCUS_INTENT: 'strapiFieldFocusIntent',\n } as const;\n\n /**\n * Calling the function in no-run mode lets us retrieve the constants from other files and keep\n * a single source of truth for them. It's the only way to do this because this script can't\n * refer to any variables outside of its own scope, because it's stringified before it's run.\n */\n if (!shouldRun) {\n return { INTERNAL_EVENTS };\n }\n\n /* -----------------------------------------------------------------------------------------------\n * Utils\n * ---------------------------------------------------------------------------------------------*/\n\n const sendMessage = (\n type: (typeof INTERNAL_EVENTS)[keyof typeof INTERNAL_EVENTS],\n payload: unknown\n ) => {\n window.parent.postMessage({ type, payload }, '*');\n };\n\n /* -----------------------------------------------------------------------------------------------\n * Functionality pieces\n * ---------------------------------------------------------------------------------------------*/\n\n const createOverlaySystem = () => {\n // Clean up before creating a new overlay so we can safely call previewScript multiple times\n window.__strapi_previewCleanup?.();\n document.getElementById(OVERLAY_ID)?.remove();\n\n const overlay = document.createElement('div');\n overlay.id = OVERLAY_ID;\n overlay.style.cssText = `\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n pointer-events: none;\n z-index: 9999;\n `;\n\n window.document.body.appendChild(overlay);\n return overlay;\n };\n\n type EventListenersList = Array<{\n element: HTMLElement | Window;\n type: keyof HTMLElementEventMap | 'message';\n handler: EventListener;\n }>;\n\n const createHighlightManager = (overlay: HTMLElement) => {\n const elements = window.document.querySelectorAll(`[${SOURCE_ATTRIBUTE}]`);\n const eventListeners: EventListenersList = [];\n const highlights: HTMLElement[] = [];\n const focusedHighlights: HTMLElement[] = [];\n let focusedField: string | null = null;\n\n const drawHighlight = (target: Element, highlight: HTMLElement) => {\n if (!highlight) return;\n\n const rect = target.getBoundingClientRect();\n highlight.style.width = `${rect.width + HIGHLIGHT_PADDING * 2}px`;\n highlight.style.height = `${rect.height + HIGHLIGHT_PADDING * 2}px`;\n highlight.style.transform = `translate(${rect.left - HIGHLIGHT_PADDING}px, ${rect.top - HIGHLIGHT_PADDING}px)`;\n };\n\n const updateAllHighlights = () => {\n highlights.forEach((highlight, index) => {\n const element = elements[index];\n if (element && highlight) {\n drawHighlight(element, highlight);\n }\n });\n };\n\n elements.forEach((element) => {\n if (element instanceof HTMLElement) {\n const highlight = document.createElement('div');\n highlight.style.cssText = `\n position: absolute;\n outline: 2px solid transparent;\n pointer-events: none;\n border-radius: 2px;\n background-color: transparent;\n will-change: transform;\n transition: outline-color 0.1s ease-in-out;\n `;\n\n // Move hover detection to the underlying element\n const mouseEnterHandler = () => {\n if (!highlightManager.focusedHighlights.includes(highlight)) {\n highlight.style.outlineColor = HIGHLIGHT_HOVER_COLOR;\n }\n };\n const mouseLeaveHandler = () => {\n if (!highlightManager.focusedHighlights.includes(highlight)) {\n highlight.style.outlineColor = 'transparent';\n }\n };\n const doubleClickHandler = () => {\n const sourceAttribute = element.getAttribute(SOURCE_ATTRIBUTE);\n if (sourceAttribute) {\n const rect = element.getBoundingClientRect();\n sendMessage(INTERNAL_EVENTS.STRAPI_FIELD_FOCUS_INTENT, {\n path: sourceAttribute,\n position: {\n top: rect.top,\n left: rect.left,\n right: rect.right,\n bottom: rect.bottom,\n width: rect.width,\n height: rect.height,\n },\n });\n }\n };\n const mouseDownHandler = (event: MouseEvent) => {\n // Prevent default multi click to select behavior\n if (event.detail >= 2) {\n event.preventDefault();\n }\n };\n\n element.addEventListener('mouseenter', mouseEnterHandler);\n element.addEventListener('mouseleave', mouseLeaveHandler);\n element.addEventListener('dblclick', doubleClickHandler);\n element.addEventListener('mousedown', mouseDownHandler);\n\n // Store event listeners for cleanup\n eventListeners.push(\n { element, type: 'mouseenter', handler: mouseEnterHandler },\n { element, type: 'mouseleave', handler: mouseLeaveHandler },\n { element, type: 'dblclick', handler: doubleClickHandler },\n { element, type: 'mousedown', handler: mouseDownHandler as EventListener }\n );\n\n highlights.push(highlight);\n overlay.appendChild(highlight);\n\n drawHighlight(element, highlight);\n }\n });\n\n return {\n elements,\n updateAllHighlights,\n eventListeners,\n highlights,\n focusedHighlights,\n setFocusedField: (field: string | null) => {\n focusedField = field;\n },\n getFocusedField: () => focusedField,\n };\n };\n\n type HighlightManager = ReturnType<typeof createHighlightManager>;\n\n const setupObservers = (highlightManager: HighlightManager) => {\n const resizeObserver = new ResizeObserver(() => {\n highlightManager.updateAllHighlights();\n });\n\n highlightManager.elements.forEach((element: Element) => {\n resizeObserver.observe(element);\n });\n\n resizeObserver.observe(document.documentElement);\n\n const updateOnScroll = () => {\n highlightManager.updateAllHighlights();\n };\n\n const scrollableElements = new Set<Element | Window>();\n scrollableElements.add(window);\n\n // Find all scrollable ancestors for all tracked elements\n highlightManager.elements.forEach((element) => {\n let parent = element.parentElement;\n while (parent) {\n const computedStyle = window.getComputedStyle(parent);\n const overflow = computedStyle.overflow + computedStyle.overflowX + computedStyle.overflowY;\n\n if (overflow.includes('scroll') || overflow.includes('auto')) {\n scrollableElements.add(parent);\n }\n\n parent = parent.parentElement;\n }\n });\n\n // Add scroll listeners to all scrollable elements\n scrollableElements.forEach((element) => {\n if (element === window) {\n window.addEventListener('scroll', updateOnScroll);\n window.addEventListener('resize', updateOnScroll);\n } else {\n element.addEventListener('scroll', updateOnScroll);\n }\n });\n\n return {\n resizeObserver,\n updateOnScroll,\n scrollableElements,\n };\n };\n\n const setupEventHandlers = (highlightManager: HighlightManager) => {\n const handleMessage = (event: MessageEvent) => {\n if (!event.data?.type) return;\n\n // The user typed in an input, reflect the change in the preview\n if (event.data.type === INTERNAL_EVENTS.STRAPI_FIELD_CHANGE) {\n const { field, value } = event.data.payload;\n if (!field) return;\n\n const matchingElements = document.querySelectorAll(`[${SOURCE_ATTRIBUTE}=\"${field}\"]`);\n matchingElements.forEach((element) => {\n if (element instanceof HTMLElement) {\n element.textContent = value || '';\n }\n });\n return;\n }\n\n // The user focused a new input, update the highlights in the preview\n if (event.data.type === INTERNAL_EVENTS.STRAPI_FIELD_FOCUS) {\n const { field } = event.data.payload;\n if (!field) return;\n\n // Clear existing focused highlights\n highlightManager.focusedHighlights.forEach((highlight: HTMLElement) => {\n highlight.style.outlineColor = 'transparent';\n });\n highlightManager.focusedHighlights.length = 0;\n\n // Set new focused field and highlight matching elements\n highlightManager.setFocusedField(field);\n const matchingElements = document.querySelectorAll(`[${SOURCE_ATTRIBUTE}=\"${field}\"]`);\n matchingElements.forEach((element) => {\n const highlight =\n highlightManager.highlights[Array.from(highlightManager.elements).indexOf(element)];\n if (highlight) {\n highlight.style.outlineColor = HIGHLIGHT_ACTIVE_COLOR;\n highlight.style.outlineWidth = '3px';\n highlightManager.focusedHighlights.push(highlight);\n }\n });\n return;\n }\n\n // The user is no longer focusing an input, remove the highlights\n if (event.data.type === INTERNAL_EVENTS.STRAPI_FIELD_BLUR) {\n const { field } = event.data.payload;\n if (field !== highlightManager.getFocusedField()) return;\n\n highlightManager.focusedHighlights.forEach((highlight: HTMLElement) => {\n highlight.style.outlineColor = 'transparent';\n highlight.style.outlineWidth = '2px';\n });\n highlightManager.focusedHighlights.length = 0;\n highlightManager.setFocusedField(null);\n }\n };\n\n window.addEventListener('message', handleMessage);\n\n // Add the message handler to the cleanup list\n const messageEventListener = {\n element: window,\n type: 'message' as keyof HTMLElementEventMap,\n handler: handleMessage as EventListener,\n };\n\n return [...highlightManager.eventListeners, messageEventListener];\n };\n\n const createCleanupSystem = (\n overlay: HTMLElement,\n observers: ReturnType<typeof setupObservers>,\n eventHandlers: EventListenersList\n ) => {\n window.__strapi_previewCleanup = () => {\n observers.resizeObserver.disconnect();\n\n // Remove all scroll listeners\n observers.scrollableElements.forEach((element) => {\n if (element === window) {\n window.removeEventListener('scroll', observers.updateOnScroll);\n window.removeEventListener('resize', observers.updateOnScroll);\n } else {\n (element as Element).removeEventListener('scroll', observers.updateOnScroll);\n }\n });\n\n // Remove highlight event listeners\n eventHandlers.forEach(({ element, type, handler }) => {\n element.removeEventListener(type, handler);\n });\n\n overlay.remove();\n };\n };\n\n /* -----------------------------------------------------------------------------------------------\n * Orchestration\n * ---------------------------------------------------------------------------------------------*/\n\n const overlay = createOverlaySystem();\n const highlightManager = createHighlightManager(overlay);\n const observers = setupObservers(highlightManager);\n const eventHandlers = setupEventHandlers(highlightManager);\n createCleanupSystem(overlay, observers, eventHandlers);\n};\n\nexport { previewScript };\n"],"names":["previewScript","shouldRun","HIGHLIGHT_PADDING","HIGHLIGHT_HOVER_COLOR","window","STRAPI_HIGHLIGHT_HOVER_COLOR","HIGHLIGHT_ACTIVE_COLOR","STRAPI_HIGHLIGHT_ACTIVE_COLOR","SOURCE_ATTRIBUTE","OVERLAY_ID","INTERNAL_EVENTS","STRAPI_FIELD_FOCUS","STRAPI_FIELD_BLUR","STRAPI_FIELD_CHANGE","STRAPI_FIELD_FOCUS_INTENT","sendMessage","type","payload","parent","postMessage","createOverlaySystem","__strapi_previewCleanup","document","getElementById","remove","overlay","createElement","id","style","cssText","body","appendChild","createHighlightManager","elements","querySelectorAll","eventListeners","highlights","focusedHighlights","focusedField","drawHighlight","target","highlight","rect","getBoundingClientRect","width","height","transform","left","top","updateAllHighlights","forEach","index","element","HTMLElement","mouseEnterHandler","highlightManager","includes","outlineColor","mouseLeaveHandler","doubleClickHandler","sourceAttribute","getAttribute","path","position","right","bottom","mouseDownHandler","event","detail","preventDefault","addEventListener","push","handler","setFocusedField","field","getFocusedField","setupObservers","resizeObserver","ResizeObserver","observe","documentElement","updateOnScroll","scrollableElements","Set","add","parentElement","computedStyle","getComputedStyle","overflow","overflowX","overflowY","setupEventHandlers","handleMessage","data","value","matchingElements","textContent","length","Array","from","indexOf","outlineWidth","messageEventListener","createCleanupSystem","observers","eventHandlers","disconnect","removeEventListener"],"mappings":";;AAAA;AASA;;;;;AAKC,IACKA,MAAAA,aAAAA,GAAgB,CAACC,SAAAA,GAAY,IAAI,GAAA;AACrC;;qGAGA,MAAMC,iBAAoB,GAAA,CAAA,CAAA;AAC1B,IAAA,MAAMC,qBAAwBC,GAAAA,MAAAA,CAAOC,4BAA4B,IAAI;AACrE,IAAA,MAAMC,sBAAyBF,GAAAA,MAAAA,CAAOG,6BAA6B,IAAI;AAEvE,IAAA,M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