@intlayer/editor 9.5.11 → 9.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/ContentSelector.cjs +0 -4
- package/dist/cjs/components/ContentSelector.cjs.map +1 -1
- package/dist/cjs/components/ContentSelectorWrapper.cjs +72 -76
- package/dist/cjs/components/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/components/index.cjs +0 -6
- package/dist/cjs/core/EditorStateManager.cjs +32 -75
- package/dist/cjs/core/EditorStateManager.cjs.map +1 -1
- package/dist/cjs/core/IframeClickInterceptor.cjs +15 -9
- package/dist/cjs/core/IframeClickInterceptor.cjs.map +1 -1
- package/dist/cjs/core/index.cjs +3 -10
- package/dist/cjs/core/initEditorClient.cjs +1 -2
- package/dist/cjs/core/initEditorClient.cjs.map +1 -1
- package/dist/cjs/core/sharedWindowState.cjs +49 -0
- package/dist/cjs/core/sharedWindowState.cjs.map +1 -0
- package/dist/cjs/index.cjs +4 -21
- package/dist/esm/components/ContentSelector.mjs +0 -4
- package/dist/esm/components/ContentSelector.mjs.map +1 -1
- package/dist/esm/components/ContentSelectorWrapper.mjs +72 -76
- package/dist/esm/components/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/components/index.mjs +1 -3
- package/dist/esm/core/EditorStateManager.mjs +32 -75
- package/dist/esm/core/EditorStateManager.mjs.map +1 -1
- package/dist/esm/core/IframeClickInterceptor.mjs +15 -9
- package/dist/esm/core/IframeClickInterceptor.mjs.map +1 -1
- package/dist/esm/core/index.mjs +3 -4
- package/dist/esm/core/initEditorClient.mjs +2 -2
- package/dist/esm/core/initEditorClient.mjs.map +1 -1
- package/dist/esm/core/sharedWindowState.mjs +48 -0
- package/dist/esm/core/sharedWindowState.mjs.map +1 -0
- package/dist/esm/index.mjs +4 -9
- package/dist/types/components/ContentSelector.d.ts.map +1 -1
- package/dist/types/components/ContentSelectorWrapper.d.ts +12 -9
- package/dist/types/components/ContentSelectorWrapper.d.ts.map +1 -1
- package/dist/types/components/index.d.ts +1 -3
- package/dist/types/core/EditorStateManager.d.ts +7 -13
- package/dist/types/core/EditorStateManager.d.ts.map +1 -1
- package/dist/types/core/IframeClickInterceptor.d.ts +3 -7
- package/dist/types/core/IframeClickInterceptor.d.ts.map +1 -1
- package/dist/types/core/index.d.ts +3 -4
- package/dist/types/core/initEditorClient.d.ts +0 -2
- package/dist/types/core/initEditorClient.d.ts.map +1 -1
- package/dist/types/core/sharedWindowState.d.ts +18 -0
- package/dist/types/core/sharedWindowState.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -9
- package/package.json +6 -6
- package/dist/cjs/components/EditedContent.cjs +0 -161
- package/dist/cjs/components/EditedContent.cjs.map +0 -1
- package/dist/cjs/components/IntlayerEditor.cjs +0 -94
- package/dist/cjs/components/IntlayerEditor.cjs.map +0 -1
- package/dist/cjs/core/editedContentBus.cjs +0 -36
- package/dist/cjs/core/editedContentBus.cjs.map +0 -1
- package/dist/cjs/core/focusedContentBus.cjs +0 -42
- package/dist/cjs/core/focusedContentBus.cjs.map +0 -1
- package/dist/cjs/mergeIframeClick.cjs +0 -22
- package/dist/cjs/mergeIframeClick.cjs.map +0 -1
- package/dist/esm/components/EditedContent.mjs +0 -159
- package/dist/esm/components/EditedContent.mjs.map +0 -1
- package/dist/esm/components/IntlayerEditor.mjs +0 -92
- package/dist/esm/components/IntlayerEditor.mjs.map +0 -1
- package/dist/esm/core/editedContentBus.mjs +0 -33
- package/dist/esm/core/editedContentBus.mjs.map +0 -1
- package/dist/esm/core/focusedContentBus.mjs +0 -39
- package/dist/esm/core/focusedContentBus.mjs.map +0 -1
- package/dist/esm/mergeIframeClick.mjs +0 -21
- package/dist/esm/mergeIframeClick.mjs.map +0 -1
- package/dist/types/components/EditedContent.d.ts +0 -49
- package/dist/types/components/EditedContent.d.ts.map +0 -1
- package/dist/types/components/IntlayerEditor.d.ts +0 -44
- package/dist/types/components/IntlayerEditor.d.ts.map +0 -1
- package/dist/types/core/editedContentBus.d.ts +0 -7
- package/dist/types/core/editedContentBus.d.ts.map +0 -1
- package/dist/types/core/focusedContentBus.d.ts +0 -7
- package/dist/types/core/focusedContentBus.d.ts.map +0 -1
- package/dist/types/mergeIframeClick.d.ts +0 -4
- package/dist/types/mergeIframeClick.d.ts.map +0 -1
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_components_ContentSelectorWrapper = require('./ContentSelectorWrapper.cjs');
|
|
3
|
-
const require_components_EditedContent = require('./EditedContent.cjs');
|
|
4
|
-
const require_components_IntlayerEditor = require('./IntlayerEditor.cjs');
|
|
5
3
|
|
|
6
4
|
//#region src/components/ContentSelector.ts
|
|
7
5
|
const DEFAULT_PRESS_DURATION = 250;
|
|
@@ -168,8 +166,6 @@ const defineIntlayerElements = () => {
|
|
|
168
166
|
if (typeof customElements === "undefined") return;
|
|
169
167
|
if (!customElements.get("intlayer-content-selector")) customElements.define("intlayer-content-selector", IntlayerContentSelectorElement);
|
|
170
168
|
require_components_ContentSelectorWrapper.defineIntlayerContentSelectorWrapper();
|
|
171
|
-
require_components_EditedContent.defineIntlayerEditedContent();
|
|
172
|
-
require_components_IntlayerEditor.defineIntlayerEditorElement();
|
|
173
169
|
};
|
|
174
170
|
|
|
175
171
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSelector.cjs","names":[],"sources":["../../../src/components/ContentSelector.ts"],"sourcesContent":["import { defineIntlayerContentSelectorWrapper } from './ContentSelectorWrapper';\
|
|
1
|
+
{"version":3,"file":"ContentSelector.cjs","names":[],"sources":["../../../src/components/ContentSelector.ts"],"sourcesContent":["import { defineIntlayerContentSelectorWrapper } from './ContentSelectorWrapper';\n\nconst DEFAULT_PRESS_DURATION = 250;\n\nconst STYLES = `\n :host {\n display: contents;\n }\n\n .wrapper {\n display: inline-block;\n cursor: pointer;\n user-select: none;\n border-radius: 0.375rem;\n outline-width: 2px;\n outline-offset: 4px;\n outline-style: solid;\n outline-color: transparent;\n transition: all 100ms 50ms ease-in-out;\n }\n\n .wrapper[data-active] {\n outline-color: inherit;\n }\n`;\n\nconst _HTMLElement =\n typeof HTMLElement !== 'undefined'\n ? HTMLElement\n : (class {} as unknown as typeof HTMLElement);\n\n/**\n * <intlayer-content-selector>\n *\n * A framework-agnostic web component that wraps content with Intlayer editor\n * selection UI (hover outline, long-press to select, click-outside to deselect).\n *\n * @fires intlayer:press - Fired after a long press (pressDuration ms). Bubbles.\n * @fires intlayer:hover - Fired on mouseenter. Bubbles.\n * @fires intlayer:unhover - Fired on mouseleave / mouseup. Bubbles.\n * @fires intlayer:click-outside - Fired when a click occurs outside the element. Bubbles.\n *\n * @prop {boolean} isSelecting - Whether this element is currently selected (external state)\n * @prop {number} pressDuration - Long-press threshold in ms. Default: 250\n */\nexport class IntlayerContentSelectorElement extends _HTMLElement {\n private _isSelecting = false;\n private _pressDuration = DEFAULT_PRESS_DURATION;\n private _isHovered = false;\n private _isSelectingState = false;\n private _wrapper: HTMLSpanElement;\n private _pressTimer: ReturnType<typeof setTimeout> | null = null;\n private _clickOutsideHandler: ((e: MouseEvent) => void) | null = null;\n\n static get observedAttributes(): string[] {\n return ['is-selecting', 'press-duration'];\n }\n\n get isSelecting(): boolean {\n return this._isSelecting;\n }\n set isSelecting(v: boolean) {\n this._isSelecting = v;\n this._updateActiveState();\n }\n\n get pressDuration(): number {\n return this._pressDuration;\n }\n set pressDuration(v: number) {\n this._pressDuration = v;\n }\n\n constructor() {\n super();\n const shadow = this.attachShadow({ mode: 'open' });\n\n const style = document.createElement('style');\n style.textContent = STYLES;\n shadow.appendChild(style);\n\n const wrapper = document.createElement('span');\n wrapper.className = 'wrapper';\n wrapper.setAttribute('role', 'button');\n wrapper.setAttribute('tabindex', '0');\n wrapper.appendChild(document.createElement('slot'));\n shadow.appendChild(wrapper);\n this._wrapper = wrapper;\n\n wrapper.addEventListener('mousedown', () => this._handleMouseDown());\n wrapper.addEventListener('mouseup', () => this._handleMouseUpOrLeave());\n wrapper.addEventListener('mouseleave', () => this._handleMouseUpOrLeave());\n wrapper.addEventListener('mouseenter', () => this._handleMouseEnter());\n wrapper.addEventListener('click', (e) => this._handleClick(e));\n wrapper.addEventListener('touchstart', () => this._handleMouseDown());\n wrapper.addEventListener('touchend', () => this._handleMouseUpOrLeave());\n wrapper.addEventListener('touchcancel', () => this._handleMouseUpOrLeave());\n wrapper.addEventListener('blur', () => this._handleBlur());\n }\n\n attributeChangedCallback(\n name: string,\n _oldVal: string | null,\n newVal: string | null\n ): void {\n if (name === 'is-selecting') {\n this._isSelecting = newVal !== null;\n this._updateActiveState();\n } else if (name === 'press-duration') {\n this._pressDuration =\n newVal !== null ? parseInt(newVal, 10) : DEFAULT_PRESS_DURATION;\n }\n }\n\n connectedCallback(): void {\n this._clickOutsideHandler = (e: MouseEvent) => {\n // composedPath() pierces shadow boundaries\n if (!e.composedPath().includes(this)) {\n this._isSelectingState = false;\n this._dispatch('intlayer:click-outside');\n this._updateActiveState();\n }\n };\n document.addEventListener('mousedown', this._clickOutsideHandler);\n }\n\n disconnectedCallback(): void {\n if (this._clickOutsideHandler) {\n document.removeEventListener('mousedown', this._clickOutsideHandler);\n this._clickOutsideHandler = null;\n }\n this._clearPressTimer();\n }\n\n private _updateActiveState(): void {\n const isActive =\n this._isSelecting || this._isSelectingState || this._isHovered;\n if (isActive) {\n this._wrapper.setAttribute('data-active', '');\n } else {\n this._wrapper.removeAttribute('data-active');\n }\n }\n\n private _clearPressTimer(): void {\n if (this._pressTimer !== null) {\n clearTimeout(this._pressTimer);\n this._pressTimer = null;\n }\n }\n\n private _dispatch(eventName: string): void {\n this.dispatchEvent(\n new CustomEvent(eventName, { bubbles: true, composed: true })\n );\n }\n\n private _handleMouseDown(): void {\n this._clearPressTimer();\n this._pressTimer = setTimeout(() => {\n this._isSelectingState = true;\n this._updateActiveState();\n this._dispatch('intlayer:press');\n }, this._pressDuration);\n }\n\n private _handleMouseEnter(): void {\n this._isHovered = true;\n this._updateActiveState();\n this._dispatch('intlayer:hover');\n }\n\n private _handleMouseUpOrLeave(): void {\n if (this._isHovered) {\n this._isHovered = false;\n this._dispatch('intlayer:unhover');\n }\n this._clearPressTimer();\n this._updateActiveState();\n }\n\n private _handleClick(e: MouseEvent): void {\n if (this._isSelecting || this._isSelectingState) {\n e.preventDefault();\n e.stopPropagation();\n }\n }\n\n private _handleBlur(): void {\n this._isSelectingState = false;\n this._updateActiveState();\n }\n}\n\n/**\n * Register all Intlayer custom elements.\n * Call this once at application startup (inside IntlayerEditorProvider or similar).\n * Safe to call multiple times — only registers elements that are not yet defined.\n */\nexport const defineIntlayerElements = (): void => {\n if (typeof customElements === 'undefined') return;\n if (!customElements.get('intlayer-content-selector')) {\n customElements.define(\n 'intlayer-content-selector',\n IntlayerContentSelectorElement\n );\n }\n defineIntlayerContentSelectorWrapper();\n};\n"],"mappings":";;;;AAEA,MAAM,yBAAyB;AAE/B,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;AAsBf,MAAM,eACJ,OAAO,gBAAgB,cACnB,cACC,MAAM,CAAC;;;;;;;;;;;;;;;AAgBd,IAAa,iCAAb,cAAoD,aAAa;CAC/D,AAAQ,eAAe;CACvB,AAAQ,iBAAiB;CACzB,AAAQ,aAAa;CACrB,AAAQ,oBAAoB;CAC5B,AAAQ;CACR,AAAQ,cAAoD;CAC5D,AAAQ,uBAAyD;CAEjE,WAAW,qBAA+B;EACxC,OAAO,CAAC,gBAAgB,gBAAgB;CAC1C;CAEA,IAAI,cAAuB;EACzB,OAAO,KAAK;CACd;CACA,IAAI,YAAY,GAAY;EAC1B,KAAK,eAAe;EACpB,KAAK,mBAAmB;CAC1B;CAEA,IAAI,gBAAwB;EAC1B,OAAO,KAAK;CACd;CACA,IAAI,cAAc,GAAW;EAC3B,KAAK,iBAAiB;CACxB;CAEA,cAAc;EACZ,MAAM;EACN,MAAM,SAAS,KAAK,aAAa,E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,36 @@ let _intlayer_types_nodeType = require("@intlayer/types/nodeType");
|
|
|
7
7
|
_intlayer_types_nodeType = require_runtime.__toESM(_intlayer_types_nodeType);
|
|
8
8
|
|
|
9
9
|
//#region src/components/ContentSelectorWrapper.ts
|
|
10
|
+
/**
|
|
11
|
+
* Share of the viewport height left above content scrolled into view (30vh),
|
|
12
|
+
* keeping it clear of fixed navbars.
|
|
13
|
+
*/
|
|
14
|
+
const SCROLL_TOP_OFFSET_RATIO = .3;
|
|
15
|
+
/** Parent in the flattened tree, crossing shadow roots up to their host. */
|
|
16
|
+
const getComposedParent = (element) => element.parentElement ?? element.getRootNode().host ?? null;
|
|
17
|
+
/** Vertical translation applied to an element, by `transform` or `translate`. */
|
|
18
|
+
const getTranslateY = (style) => {
|
|
19
|
+
const transformOffset = style.transform && style.transform !== "none" ? new DOMMatrixReadOnly(style.transform).m42 : 0;
|
|
20
|
+
const translateOffset = Number.parseFloat(style.translate?.split(" ")[1] ?? "");
|
|
21
|
+
return transformOffset + (Number.isNaN(translateOffset) ? 0 : translateOffset);
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Vertical offset the element will lose once its reveal animations end.
|
|
25
|
+
*
|
|
26
|
+
* Scroll-reveal effects (`whileInView`, AOS…) keep off-screen content
|
|
27
|
+
* transparent and shifted until it enters the viewport, then slide it into
|
|
28
|
+
* place: measuring it as-is would scroll too far by that shift. Only
|
|
29
|
+
* translucent ancestors are counted, so permanent transforms (centering…)
|
|
30
|
+
* stay part of the position.
|
|
31
|
+
*/
|
|
32
|
+
const getPendingRevealOffset = (element) => {
|
|
33
|
+
let offset = 0;
|
|
34
|
+
for (let ancestor = element; ancestor; ancestor = getComposedParent(ancestor)) {
|
|
35
|
+
const style = getComputedStyle(ancestor);
|
|
36
|
+
if (Number.parseFloat(style.opacity) < 1) offset += getTranslateY(style);
|
|
37
|
+
}
|
|
38
|
+
return offset;
|
|
39
|
+
};
|
|
10
40
|
const _HTMLElement = typeof HTMLElement !== "undefined" ? HTMLElement : class {};
|
|
11
41
|
/**
|
|
12
42
|
* <intlayer-content-selector-wrapper>
|
|
@@ -32,28 +62,11 @@ var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
|
|
|
32
62
|
_renderState = null;
|
|
33
63
|
_selector = null;
|
|
34
64
|
_unsubManager = null;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
_unsubEditedContent = null;
|
|
65
|
+
/** Removes the listeners attached to the current manager's states */
|
|
66
|
+
_unsubManagerState = null;
|
|
38
67
|
static get observedAttributes() {
|
|
39
68
|
return ["key-path", "dictionary-key"];
|
|
40
69
|
}
|
|
41
|
-
get keyPathJson() {
|
|
42
|
-
return this._keyPathJson;
|
|
43
|
-
}
|
|
44
|
-
set keyPathJson(v) {
|
|
45
|
-
this._keyPathJson = v;
|
|
46
|
-
const manager = require_core_globalManager.getGlobalEditorManager();
|
|
47
|
-
if (manager) this._updateEditedValue(manager);
|
|
48
|
-
}
|
|
49
|
-
get dictionaryKey() {
|
|
50
|
-
return this._dictionaryKey;
|
|
51
|
-
}
|
|
52
|
-
set dictionaryKey(v) {
|
|
53
|
-
this._dictionaryKey = v;
|
|
54
|
-
const manager = require_core_globalManager.getGlobalEditorManager();
|
|
55
|
-
if (manager) this._updateEditedValue(manager);
|
|
56
|
-
}
|
|
57
70
|
constructor() {
|
|
58
71
|
super();
|
|
59
72
|
const shadow = this.attachShadow({ mode: "open" });
|
|
@@ -61,16 +74,11 @@ var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
|
|
|
61
74
|
style.textContent = ":host { display: contents; }";
|
|
62
75
|
shadow.appendChild(style);
|
|
63
76
|
}
|
|
64
|
-
attributeChangedCallback(name,
|
|
65
|
-
if (name === "key-path")
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
} else if (name === "dictionary-key") {
|
|
70
|
-
this._dictionaryKey = newVal ?? "";
|
|
71
|
-
const manager = require_core_globalManager.getGlobalEditorManager();
|
|
72
|
-
if (manager) this._updateEditedValue(manager);
|
|
73
|
-
}
|
|
77
|
+
attributeChangedCallback(name, _oldValue, newValue) {
|
|
78
|
+
if (name === "key-path") this._keyPathJson = newValue ?? "[]";
|
|
79
|
+
else this._dictionaryKey = newValue ?? "";
|
|
80
|
+
const manager = require_core_globalManager.getGlobalEditorManager();
|
|
81
|
+
if (manager) this._updateEditedValue(manager);
|
|
74
82
|
}
|
|
75
83
|
connectedCallback() {
|
|
76
84
|
if (typeof window !== "undefined") this._isInIframe = window.self !== window.top;
|
|
@@ -78,17 +86,10 @@ var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
|
|
|
78
86
|
this._render();
|
|
79
87
|
}
|
|
80
88
|
disconnectedCallback() {
|
|
81
|
-
this._teardown();
|
|
82
|
-
}
|
|
83
|
-
_teardown() {
|
|
84
89
|
this._unsubManager?.();
|
|
85
|
-
this._unsubEnabled?.();
|
|
86
|
-
this._unsubFocused?.();
|
|
87
|
-
this._unsubEditedContent?.();
|
|
88
90
|
this._unsubManager = null;
|
|
89
|
-
this.
|
|
90
|
-
this.
|
|
91
|
-
this._unsubEditedContent = null;
|
|
91
|
+
this._unsubManagerState?.();
|
|
92
|
+
this._unsubManagerState = null;
|
|
92
93
|
}
|
|
93
94
|
_getRawKeyPath() {
|
|
94
95
|
try {
|
|
@@ -134,34 +135,31 @@ var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
|
|
|
134
135
|
this._updateSelectorAttr();
|
|
135
136
|
if (this._isSelected && !wasSelected) this._scrollIntoViewIfNeeded();
|
|
136
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Scrolls the selected content to 30vh, unless it is already fully visible
|
|
140
|
+
* in this frame's viewport.
|
|
141
|
+
*/
|
|
137
142
|
_scrollIntoViewIfNeeded() {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const targetScrollY = rect.top + scrollY - viewportHeight * .25;
|
|
159
|
-
window.scrollTo({
|
|
160
|
-
top: Math.max(0, targetScrollY),
|
|
161
|
-
behavior: "smooth"
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
} catch {}
|
|
143
|
+
const target = this._selector?.shadowRoot?.querySelector(".wrapper");
|
|
144
|
+
if (!target) return;
|
|
145
|
+
const rect = target.getBoundingClientRect();
|
|
146
|
+
const top = rect.top - getPendingRevealOffset(target);
|
|
147
|
+
const bottom = top + rect.height;
|
|
148
|
+
if (top >= 0 && bottom <= window.innerHeight && !this._isCoveredAt((rect.left + rect.right) / 2, top + 1)) return;
|
|
149
|
+
window.scrollBy({
|
|
150
|
+
top: top - window.innerHeight * SCROLL_TOP_OFFSET_RATIO,
|
|
151
|
+
behavior: "smooth"
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Whether another element (a fixed navbar, a sticky header…) is painted over
|
|
156
|
+
* this content at the given viewport point.
|
|
157
|
+
*/
|
|
158
|
+
_isCoveredAt(x, y) {
|
|
159
|
+
const root = this.getRootNode();
|
|
160
|
+
if (typeof root.elementFromPoint !== "function") return false;
|
|
161
|
+
const topElement = root.elementFromPoint(x, y);
|
|
162
|
+
return Boolean(topElement) && !this.contains(topElement);
|
|
165
163
|
}
|
|
166
164
|
_updateSelectorAttr() {
|
|
167
165
|
if (!this._selector) return;
|
|
@@ -171,14 +169,10 @@ var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
|
|
|
171
169
|
_subscribeToManager() {
|
|
172
170
|
const manager = require_core_globalManager.getGlobalEditorManager();
|
|
173
171
|
if (manager) this._setupManagerSubscriptions(manager);
|
|
174
|
-
this._unsubManager = require_core_globalManager.onGlobalEditorManagerChange((
|
|
175
|
-
this.
|
|
176
|
-
this.
|
|
177
|
-
this.
|
|
178
|
-
this._unsubEnabled = null;
|
|
179
|
-
this._unsubFocused = null;
|
|
180
|
-
this._unsubEditedContent = null;
|
|
181
|
-
if (m) this._setupManagerSubscriptions(m);
|
|
172
|
+
this._unsubManager = require_core_globalManager.onGlobalEditorManagerChange((nextManager) => {
|
|
173
|
+
this._unsubManagerState?.();
|
|
174
|
+
this._unsubManagerState = null;
|
|
175
|
+
if (nextManager) this._setupManagerSubscriptions(nextManager);
|
|
182
176
|
else {
|
|
183
177
|
this._editorEnabled = false;
|
|
184
178
|
this._isSelected = false;
|
|
@@ -204,9 +198,11 @@ var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
|
|
|
204
198
|
manager.editorEnabled.addEventListener("change", handleEnabledChange);
|
|
205
199
|
manager.focusedContent.addEventListener("change", handleFocusedChange);
|
|
206
200
|
manager.editedContent.addEventListener("change", handleEditedContentChange);
|
|
207
|
-
this.
|
|
208
|
-
|
|
209
|
-
|
|
201
|
+
this._unsubManagerState = () => {
|
|
202
|
+
manager.editorEnabled.removeEventListener("change", handleEnabledChange);
|
|
203
|
+
manager.focusedContent.removeEventListener("change", handleFocusedChange);
|
|
204
|
+
manager.editedContent.removeEventListener("change", handleEditedContentChange);
|
|
205
|
+
};
|
|
210
206
|
}
|
|
211
207
|
_handlePress(e) {
|
|
212
208
|
e.stopPropagation();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSelectorWrapper.cjs","names":["getGlobalEditorManager","NodeTypes","node","isSameKeyPath","onGlobalEditorManagerChange"],"sources":["../../../src/components/ContentSelectorWrapper.ts"],"sourcesContent":["import { isSameKeyPath } from '@intlayer/core/utils';\n\nimport type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { TypedNodeModel } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type {\n EditorStateManager,\n FileContent,\n} from '../core/EditorStateManager';\nimport {\n getGlobalEditorManager,\n onGlobalEditorManagerChange,\n} from '../core/globalManager';\nimport { MessageKey } from '../messageKey';\n\ntype RenderState = 'simple' | 'wrapped-slot' | 'wrapped-text';\n\nconst _HTMLElement =\n typeof HTMLElement !== 'undefined'\n ? HTMLElement\n : (class {} as unknown as typeof HTMLElement);\n\n/**\n * <intlayer-content-selector-wrapper>\n *\n * Framework-agnostic web component that wraps content with the Intlayer editor\n * selection UI. It replaces the per-framework ContentSelectorWrapper components\n * (Vue, Svelte, Solid, Preact).\n *\n * It reads from the global EditorStateManager singleton (set by initEditorClient)\n * and conditionally renders <intlayer-content-selector> around its slot content\n * when the editor is active and the app is running inside an iframe.\n *\n * @attr {string} key-path - JSON-serialized KeyPath[] for this content node\n * @attr {string} dictionary-key - The dictionary key owning this content node\n */\nexport class IntlayerContentSelectorWrapperElement extends _HTMLElement {\n private _keyPathJson = '[]';\n private _dictionaryKey = '';\n private _editorEnabled = false;\n private _isInIframe = false;\n private _isSelected = false;\n private _editedValue: ContentNode | undefined = undefined;\n\n private _renderState: RenderState | null = null;\n private _selector: HTMLElement | null = null;\n\n private _unsubManager: (() => void) | null = null;\n private _unsubEnabled: (() => void) | null = null;\n private _unsubFocused: (() => void) | null = null;\n private _unsubEditedContent: (() => void) | null = null;\n\n static get observedAttributes(): string[] {\n return ['key-path', 'dictionary-key'];\n }\n\n get keyPathJson(): string {\n return this._keyPathJson;\n }\n set keyPathJson(v: string) {\n this._keyPathJson = v;\n const manager = getGlobalEditorManager();\n if (manager) this._updateEditedValue(manager);\n }\n\n get dictionaryKey(): string {\n return this._dictionaryKey;\n }\n set dictionaryKey(v: string) {\n this._dictionaryKey = v;\n const manager = getGlobalEditorManager();\n if (manager) this._updateEditedValue(manager);\n }\n\n constructor() {\n super();\n const shadow = this.attachShadow({ mode: 'open' });\n const style = document.createElement('style');\n style.textContent = ':host { display: contents; }';\n shadow.appendChild(style);\n }\n\n attributeChangedCallback(\n name: string,\n _oldVal: string | null,\n newVal: string | null\n ): void {\n if (name === 'key-path') {\n this._keyPathJson = newVal ?? '[]';\n const manager = getGlobalEditorManager();\n if (manager) this._updateEditedValue(manager);\n } else if (name === 'dictionary-key') {\n this._dictionaryKey = newVal ?? '';\n const manager = getGlobalEditorManager();\n if (manager) this._updateEditedValue(manager);\n }\n }\n\n connectedCallback(): void {\n if (typeof window !== 'undefined') {\n this._isInIframe = window.self !== window.top;\n }\n this._subscribeToManager();\n this._render();\n }\n\n disconnectedCallback(): void {\n this._teardown();\n }\n\n private _teardown(): void {\n this._unsubManager?.();\n this._unsubEnabled?.();\n this._unsubFocused?.();\n this._unsubEditedContent?.();\n this._unsubManager = null;\n this._unsubEnabled = null;\n this._unsubFocused = null;\n this._unsubEditedContent = null;\n }\n\n private _getRawKeyPath(): KeyPath[] {\n try {\n return JSON.parse(this._keyPathJson) as KeyPath[];\n } catch {\n return [];\n }\n }\n\n private _getFilteredKeyPath(): KeyPath[] {\n return this._getRawKeyPath().filter(\n (keyPath) => keyPath.type !== NodeTypes.TRANSLATION\n );\n }\n\n private _updateEditedValue(manager: EditorStateManager): void {\n const filteredKeyPath = this._getFilteredKeyPath();\n if (!this._dictionaryKey || filteredKeyPath.length === 0) {\n this._editedValue = undefined;\n this._render();\n return;\n }\n\n // Node types whose display requires framework-level rendering (markdown,\n // HTML, insertion, file): do not override the slot — the framework handles\n // those. Only plain / translated strings can be substituted here.\n const rawKeyPath = this._getRawKeyPath();\n const lastStepType = rawKeyPath[rawKeyPath.length - 1]?.type;\n if (\n lastStepType === NodeTypes.MARKDOWN ||\n lastStepType === NodeTypes.HTML ||\n lastStepType === NodeTypes.INSERTION ||\n lastStepType === NodeTypes.FILE\n ) {\n this._editedValue = undefined;\n this._render();\n return;\n }\n\n let value = manager.getContentValue(this._dictionaryKey, filteredKeyPath);\n\n // getContentNodeByKeyPath resolves translation nodes only at intermediate\n // steps, not the final leaf. Resolve manually when the returned value is\n // still a translation object (happens when Translation steps are filtered\n // out and the leaf IS the translation object).\n if (\n value !== null &&\n value !== undefined &&\n typeof value === 'object' &&\n (value as { nodeType?: unknown }).nodeType === NodeTypes.TRANSLATION\n ) {\n const locale = manager.currentLocale.value as string | undefined;\n // TypedNodeModel<Translation, …> structurally satisfies TypedNode<BaseNode>\n // (both have nodeType), so this narrowing cast is sound.\n const node = value as TypedNodeModel<\n typeof NodeTypes.TRANSLATION,\n Record<string, ContentNode>\n >;\n value = locale ? node[NodeTypes.TRANSLATION][locale] : undefined;\n }\n\n this._editedValue = value;\n this._render();\n }\n\n private _updateIsSelected(\n focusedContent: FileContent | null | undefined\n ): void {\n if (!focusedContent) {\n this._isSelected = false;\n this._updateSelectorAttr();\n return;\n }\n const keyPath = this._getFilteredKeyPath();\n const wasSelected = this._isSelected;\n this._isSelected =\n focusedContent.dictionaryKey === this._dictionaryKey &&\n (focusedContent.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent.keyPath ?? [], keyPath);\n this._updateSelectorAttr();\n\n // Scroll into view when this element becomes selected and is not already\n // visible in the iframe viewport. This covers the case where the editor\n // focuses a content block that is off-screen in the client app.\n if (this._isSelected && !wasSelected) {\n this._scrollIntoViewIfNeeded();\n }\n }\n\n private _scrollIntoViewIfNeeded(): void {\n try {\n let rect: DOMRect | undefined;\n\n // Primary: the .wrapper span inside the selector's open shadow DOM has a\n // real CSS box (display:inline-block) for both wrapped-text and wrapped-slot.\n // This is the only reliable source for simple-string nodes where this host's\n // light DOM is empty and this.getBoundingClientRect() returns zeros.\n if (this._selector) {\n const innerWrapper = this._selector.shadowRoot?.querySelector(\n '.wrapper'\n ) as HTMLElement | null;\n if (innerWrapper) {\n const r = innerWrapper.getBoundingClientRect();\n if (r.width > 0 || r.height > 0) rect = r;\n }\n }\n\n // Fallback: range over light-DOM children for wrapped-slot nodes rendered\n // by a framework (React/markdown) before _selector is available.\n if (!rect && this.childNodes.length > 0) {\n const range = document.createRange();\n\n range.selectNodeContents(this);\n\n const r = range.getBoundingClientRect();\n\n if (r.width > 0 || r.height > 0) rect = r;\n }\n\n if (!rect) {\n rect = this.getBoundingClientRect();\n }\n\n const viewportHeight =\n window.innerHeight || document.documentElement.clientHeight;\n const viewportWidth =\n window.innerWidth || document.documentElement.clientWidth;\n\n const isVisible =\n rect.width > 0 &&\n rect.height > 0 &&\n rect.bottom > 0 &&\n rect.right > 0 &&\n rect.top < viewportHeight &&\n rect.left < viewportWidth;\n\n if (!isVisible) {\n // Scroll so the element lands at 25 % from the top of the viewport.\n const scrollY = window.scrollY ?? document.documentElement.scrollTop;\n const targetScrollY = rect.top + scrollY - viewportHeight * 0.25;\n window.scrollTo({\n top: Math.max(0, targetScrollY),\n behavior: 'smooth',\n });\n }\n } catch {\n // scroll APIs may not be available in all environments\n }\n }\n\n private _updateSelectorAttr(): void {\n if (!this._selector) return;\n if (this._isSelected) {\n this._selector.setAttribute('is-selecting', '');\n } else {\n this._selector.removeAttribute('is-selecting');\n }\n }\n\n private _subscribeToManager(): void {\n const manager = getGlobalEditorManager();\n if (manager) {\n this._setupManagerSubscriptions(manager);\n }\n // Keep listening for manager changes (handles stop + re-init cycles)\n this._unsubManager = onGlobalEditorManagerChange((m) => {\n this._unsubEnabled?.();\n this._unsubFocused?.();\n this._unsubEditedContent?.();\n this._unsubEnabled = null;\n this._unsubFocused = null;\n this._unsubEditedContent = null;\n if (m) {\n this._setupManagerSubscriptions(m);\n } else {\n this._editorEnabled = false;\n this._isSelected = false;\n this._editedValue = undefined;\n this._render();\n }\n });\n }\n\n private _setupManagerSubscriptions(manager: EditorStateManager): void {\n this._editorEnabled = manager.editorEnabled.value ?? false;\n this._updateIsSelected(manager.focusedContent.value);\n this._updateEditedValue(manager);\n\n const handleEnabledChange = (e: Event) => {\n this._editorEnabled = (e as CustomEvent<boolean>).detail;\n this._render();\n };\n const handleFocusedChange = (e: Event) => {\n this._updateIsSelected((e as CustomEvent<FileContent | null>).detail);\n };\n const handleEditedContentChange = () => {\n this._updateEditedValue(manager);\n };\n\n manager.editorEnabled.addEventListener('change', handleEnabledChange);\n manager.focusedContent.addEventListener('change', handleFocusedChange);\n manager.editedContent.addEventListener('change', handleEditedContentChange);\n\n this._unsubEnabled = () =>\n manager.editorEnabled.removeEventListener('change', handleEnabledChange);\n this._unsubFocused = () =>\n manager.focusedContent.removeEventListener('change', handleFocusedChange);\n this._unsubEditedContent = () =>\n manager.editedContent.removeEventListener(\n 'change',\n handleEditedContentChange\n );\n }\n\n private _handlePress(e: Event): void {\n // Stop propagation so nested wrappers don't also fire (composed + bubbles)\n e.stopPropagation();\n const manager = getGlobalEditorManager();\n if (!manager) return;\n manager.focusedContent.set({\n dictionaryKey: this._dictionaryKey,\n keyPath: this._getFilteredKeyPath(),\n });\n }\n\n private _handleHover(e: Event): void {\n e.stopPropagation();\n getGlobalEditorManager()?.messenger.send(\n `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n {\n dictionaryKey: this._dictionaryKey,\n keyPath: this._getFilteredKeyPath(),\n }\n );\n }\n\n private _handleUnhover(e: Event): void {\n e.stopPropagation();\n getGlobalEditorManager()?.messenger.send(\n `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n null\n );\n }\n\n private _render(): void {\n const useWrapper = this._isInIframe && this._editorEnabled;\n const editedValue = this._editedValue;\n const isSimpleValue =\n typeof editedValue === 'string' ||\n typeof editedValue === 'number' ||\n typeof editedValue === 'boolean';\n\n const newState: RenderState = !useWrapper\n ? 'simple'\n : isSimpleValue\n ? 'wrapped-text'\n : 'wrapped-slot';\n\n if (this._renderState !== newState) {\n this._rebuildContent(newState);\n return;\n }\n\n // Structure unchanged — update only dynamic parts\n if (newState !== 'simple' && this._selector) {\n this._updateSelectorAttr();\n if (\n newState === 'wrapped-text' &&\n this._selector.firstChild?.nodeType === Node.TEXT_NODE\n ) {\n (this._selector.firstChild as Text).data = String(editedValue);\n }\n }\n }\n\n private _rebuildContent(state: RenderState): void {\n const shadow = this.shadowRoot!;\n // Remove all nodes except the style element (first child)\n while (shadow.childNodes.length > 1) {\n shadow.removeChild(shadow.lastChild!);\n }\n this._selector = null;\n\n if (state === 'simple') {\n shadow.appendChild(document.createElement('slot'));\n } else {\n const selector = document.createElement('intlayer-content-selector');\n this._selector = selector;\n if (this._isSelected) selector.setAttribute('is-selecting', '');\n selector.addEventListener('intlayer:press', (e) => this._handlePress(e));\n selector.addEventListener('intlayer:hover', (e) => this._handleHover(e));\n selector.addEventListener('intlayer:unhover', (e) =>\n this._handleUnhover(e)\n );\n\n if (state === 'wrapped-text') {\n selector.appendChild(\n document.createTextNode(String(this._editedValue))\n );\n } else {\n selector.appendChild(document.createElement('slot'));\n }\n shadow.appendChild(selector);\n }\n\n this._renderState = state;\n }\n}\n\nexport const defineIntlayerContentSelectorWrapper = (): void => {\n if (typeof customElements === 'undefined') return;\n\n if (!customElements.get('intlayer-content-selector-wrapper')) {\n customElements.define(\n 'intlayer-content-selector-wrapper',\n IntlayerContentSelectorWrapperElement\n );\n }\n};\n"],"mappings":";;;;;;;;;AAkBA,MAAM,eACJ,OAAO,gBAAgB,cACnB,cACC,MAAM,CAAC;;;;;;;;;;;;;;;AAgBd,IAAa,wCAAb,cAA2D,aAAa;CACtE,AAAQ,eAAe;CACvB,AAAQ,iBAAiB;CACzB,AAAQ,iBAAiB;CACzB,AAAQ,cAAc;CACtB,AAAQ,cAAc;CACtB,AAAQ,eAAwC;CAEhD,AAAQ,eAAmC;CAC3C,AAAQ,YAAgC;CAExC,AAAQ,gBAAqC;CAC7C,AAAQ,gBAAqC;CAC7C,AAAQ,gBAAqC;CAC7C,AAAQ,sBAA2C;CAEnD,WAAW,qBAA+B;EACxC,OAAO,CAAC,YAAY,gBAAgB;CACtC;CAEA,IAAI,cAAsB;EACxB,OAAO,KAAK;CACd;CACA,IAAI,YAAY,GAAW;EACzB,KAAK,eAAe;EACpB,MAAM,UAAUA,kDAAuB;EACvC,IAAI,SAAS,KAAK,mBAAmB,OAAO;CAC9C;CAEA,IAAI,gBAAwB;EAC1B,OAAO,KAAK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IAAI,aAAa,YAAY,KAAK,WAAW;GAC3C,KAAK,oBAAoB;GACzB,IACE,aAAa,kBACb,KAAK,UAAU,YAAY,aAAa,KAAK,WAE7C,AAAC,KAAK,UAAU,WAAoB,OAAO,OAAO,WAAW;EAEjE;CACF;CAEA,AAAQ,gBAAgB,OAA0B;EAChD,MAAM,SAAS,KAAK;EAEpB,OAAO,OAAO,WAAW,SAAS,GAChC,OAAO,YAAY,OAAO,SAAU;EAEtC,KAAK,YAAY;EAEjB,IAAI,UAAU,UACZ,OAAO,YAAY,SAAS,cAAc,MAAM,CAAC;OAC5C;GACL,MAAM,WAAW,SAAS,cAAc,2BAA2B;GACnE,KAAK,YAAY;GACjB,IAAI,KAAK,aAAa,SAAS,aAAa,gBAAgB,EAAE;GAC9D,SAAS,iBAAiB,mBAAmB,MAAM,KAAK,aAAa,CAAC,CAAC;GACvE,SAAS,iBAAiB,mBAAmB,MAAM,KAAK,aAAa,CAAC,CAAC;GACvE,SAAS,iBAAiB,qBAAqB,MAC7C,KAAK,eAAe,CAAC,CACvB;GAEA,IAAI,UAAU,gBACZ,SAAS,YACP,SAAS,eAAe,OAAO,KAAK,YAAY,CAAC,CACnD;QAEA,SAAS,YAAY,SAAS,cAAc,MAAM,CAAC;GAErD,OAAO,YAAY,QAAQ;EAC7B;EAEA,KAAK,eAAe;CACtB;AACF;AAEA,MAAa,6CAAmD;CAC9D,IAAI,OAAO,mBAAmB,aAAa;CAE3C,IAAI,CAAC,eAAe,IAAI,mCAAmC,GACzD,eAAe,OACb,qCACA,qCACF;AAEJ"}
|
|
1
|
+
{"version":3,"file":"ContentSelectorWrapper.cjs","names":["getGlobalEditorManager","NodeTypes","node","isSameKeyPath","onGlobalEditorManagerChange"],"sources":["../../../src/components/ContentSelectorWrapper.ts"],"sourcesContent":["import { isSameKeyPath } from '@intlayer/core/utils';\n\nimport type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { TypedNodeModel } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type {\n EditorStateManager,\n FileContent,\n} from '../core/EditorStateManager';\nimport {\n getGlobalEditorManager,\n onGlobalEditorManagerChange,\n} from '../core/globalManager';\nimport { MessageKey } from '../messageKey';\n\ntype RenderState = 'simple' | 'wrapped-slot' | 'wrapped-text';\n\n/**\n * Share of the viewport height left above content scrolled into view (30vh),\n * keeping it clear of fixed navbars.\n */\nconst SCROLL_TOP_OFFSET_RATIO = 0.3;\n\n/** Parent in the flattened tree, crossing shadow roots up to their host. */\nconst getComposedParent = (element: Element): Element | null =>\n element.parentElement ??\n ((element.getRootNode() as ShadowRoot).host as Element | undefined) ??\n null;\n\n/** Vertical translation applied to an element, by `transform` or `translate`. */\nconst getTranslateY = (style: CSSStyleDeclaration): number => {\n const transformOffset =\n style.transform && style.transform !== 'none'\n ? new DOMMatrixReadOnly(style.transform).m42\n : 0;\n // `translate: <x> <y>` — a single value only moves along x\n const translateOffset = Number.parseFloat(\n style.translate?.split(' ')[1] ?? ''\n );\n\n return (\n transformOffset + (Number.isNaN(translateOffset) ? 0 : translateOffset)\n );\n};\n\n/**\n * Vertical offset the element will lose once its reveal animations end.\n *\n * Scroll-reveal effects (`whileInView`, AOS…) keep off-screen content\n * transparent and shifted until it enters the viewport, then slide it into\n * place: measuring it as-is would scroll too far by that shift. Only\n * translucent ancestors are counted, so permanent transforms (centering…)\n * stay part of the position.\n */\nconst getPendingRevealOffset = (element: Element): number => {\n let offset = 0;\n\n for (\n let ancestor: Element | null = element;\n ancestor;\n ancestor = getComposedParent(ancestor)\n ) {\n const style = getComputedStyle(ancestor);\n\n if (Number.parseFloat(style.opacity) < 1) offset += getTranslateY(style);\n }\n\n return offset;\n};\n\nconst _HTMLElement =\n typeof HTMLElement !== 'undefined'\n ? HTMLElement\n : (class {} as unknown as typeof HTMLElement);\n\n/**\n * <intlayer-content-selector-wrapper>\n *\n * Framework-agnostic web component that wraps content with the Intlayer editor\n * selection UI. It replaces the per-framework ContentSelectorWrapper components\n * (Vue, Svelte, Solid, Preact).\n *\n * It reads from the global EditorStateManager singleton (set by initEditorClient)\n * and conditionally renders <intlayer-content-selector> around its slot content\n * when the editor is active and the app is running inside an iframe.\n *\n * @attr {string} key-path - JSON-serialized KeyPath[] for this content node\n * @attr {string} dictionary-key - The dictionary key owning this content node\n */\nexport class IntlayerContentSelectorWrapperElement extends _HTMLElement {\n private _keyPathJson = '[]';\n private _dictionaryKey = '';\n private _editorEnabled = false;\n private _isInIframe = false;\n private _isSelected = false;\n private _editedValue: ContentNode | undefined = undefined;\n\n private _renderState: RenderState | null = null;\n private _selector: HTMLElement | null = null;\n\n private _unsubManager: (() => void) | null = null;\n /** Removes the listeners attached to the current manager's states */\n private _unsubManagerState: (() => void) | null = null;\n\n static get observedAttributes(): string[] {\n return ['key-path', 'dictionary-key'];\n }\n\n constructor() {\n super();\n const shadow = this.attachShadow({ mode: 'open' });\n const style = document.createElement('style');\n style.textContent = ':host { display: contents; }';\n shadow.appendChild(style);\n }\n\n attributeChangedCallback(\n name: string,\n _oldValue: string | null,\n newValue: string | null\n ): void {\n if (name === 'key-path') {\n this._keyPathJson = newValue ?? '[]';\n } else {\n this._dictionaryKey = newValue ?? '';\n }\n\n const manager = getGlobalEditorManager();\n if (manager) this._updateEditedValue(manager);\n }\n\n connectedCallback(): void {\n if (typeof window !== 'undefined') {\n this._isInIframe = window.self !== window.top;\n }\n this._subscribeToManager();\n this._render();\n }\n\n disconnectedCallback(): void {\n this._unsubManager?.();\n this._unsubManager = null;\n this._unsubManagerState?.();\n this._unsubManagerState = null;\n }\n\n private _getRawKeyPath(): KeyPath[] {\n try {\n return JSON.parse(this._keyPathJson) as KeyPath[];\n } catch {\n return [];\n }\n }\n\n private _getFilteredKeyPath(): KeyPath[] {\n return this._getRawKeyPath().filter(\n (keyPath) => keyPath.type !== NodeTypes.TRANSLATION\n );\n }\n\n private _updateEditedValue(manager: EditorStateManager): void {\n const filteredKeyPath = this._getFilteredKeyPath();\n if (!this._dictionaryKey || filteredKeyPath.length === 0) {\n this._editedValue = undefined;\n this._render();\n return;\n }\n\n // Node types whose display requires framework-level rendering (markdown,\n // HTML, insertion, file): do not override the slot — the framework handles\n // those. Only plain / translated strings can be substituted here.\n const rawKeyPath = this._getRawKeyPath();\n const lastStepType = rawKeyPath[rawKeyPath.length - 1]?.type;\n if (\n lastStepType === NodeTypes.MARKDOWN ||\n lastStepType === NodeTypes.HTML ||\n lastStepType === NodeTypes.INSERTION ||\n lastStepType === NodeTypes.FILE\n ) {\n this._editedValue = undefined;\n this._render();\n return;\n }\n\n let value = manager.getContentValue(this._dictionaryKey, filteredKeyPath);\n\n // getContentNodeByKeyPath resolves translation nodes only at intermediate\n // steps, not the final leaf. Resolve manually when the returned value is\n // still a translation object (happens when Translation steps are filtered\n // out and the leaf IS the translation object).\n if (\n value !== null &&\n value !== undefined &&\n typeof value === 'object' &&\n (value as { nodeType?: unknown }).nodeType === NodeTypes.TRANSLATION\n ) {\n const locale = manager.currentLocale.value as string | undefined;\n // TypedNodeModel<Translation, …> structurally satisfies TypedNode<BaseNode>\n // (both have nodeType), so this narrowing cast is sound.\n const node = value as TypedNodeModel<\n typeof NodeTypes.TRANSLATION,\n Record<string, ContentNode>\n >;\n value = locale ? node[NodeTypes.TRANSLATION][locale] : undefined;\n }\n\n this._editedValue = value;\n this._render();\n }\n\n private _updateIsSelected(\n focusedContent: FileContent | null | undefined\n ): void {\n if (!focusedContent) {\n this._isSelected = false;\n this._updateSelectorAttr();\n return;\n }\n const keyPath = this._getFilteredKeyPath();\n const wasSelected = this._isSelected;\n this._isSelected =\n focusedContent.dictionaryKey === this._dictionaryKey &&\n (focusedContent.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent.keyPath ?? [], keyPath);\n this._updateSelectorAttr();\n\n // Reveal content the editor focuses while it is off-screen in the app\n if (this._isSelected && !wasSelected) {\n this._scrollIntoViewIfNeeded();\n }\n }\n\n /**\n * Scrolls the selected content to 30vh, unless it is already fully visible\n * in this frame's viewport.\n */\n private _scrollIntoViewIfNeeded(): void {\n // `.wrapper` is the only real box: this host and the selector are\n // `display: contents`. No selector means the editor UI is inactive.\n const target = this._selector?.shadowRoot?.querySelector('.wrapper');\n if (!target) return;\n\n const rect = target.getBoundingClientRect();\n // Where the content settles once revealed\n const top = rect.top - getPendingRevealOffset(target);\n const bottom = top + rect.height;\n\n const isFullyVisible = top >= 0 && bottom <= window.innerHeight;\n if (\n isFullyVisible &&\n !this._isCoveredAt((rect.left + rect.right) / 2, top + 1)\n ) {\n return;\n }\n\n window.scrollBy({\n top: top - window.innerHeight * SCROLL_TOP_OFFSET_RATIO,\n behavior: 'smooth',\n });\n }\n\n /**\n * Whether another element (a fixed navbar, a sticky header…) is painted over\n * this content at the given viewport point.\n */\n private _isCoveredAt(x: number, y: number): boolean {\n // Query from this element's own root so apps rendered in a shadow root\n // (Lit…) don't get their outer host back\n const root = this.getRootNode() as Document | ShadowRoot;\n if (typeof root.elementFromPoint !== 'function') return false;\n\n const topElement = root.elementFromPoint(x, y);\n\n return Boolean(topElement) && !this.contains(topElement);\n }\n\n private _updateSelectorAttr(): void {\n if (!this._selector) return;\n if (this._isSelected) {\n this._selector.setAttribute('is-selecting', '');\n } else {\n this._selector.removeAttribute('is-selecting');\n }\n }\n\n private _subscribeToManager(): void {\n const manager = getGlobalEditorManager();\n if (manager) {\n this._setupManagerSubscriptions(manager);\n }\n // Keep listening for manager changes (handles stop + re-init cycles)\n this._unsubManager = onGlobalEditorManagerChange((nextManager) => {\n this._unsubManagerState?.();\n this._unsubManagerState = null;\n if (nextManager) {\n this._setupManagerSubscriptions(nextManager);\n } else {\n this._editorEnabled = false;\n this._isSelected = false;\n this._editedValue = undefined;\n this._render();\n }\n });\n }\n\n private _setupManagerSubscriptions(manager: EditorStateManager): void {\n this._editorEnabled = manager.editorEnabled.value ?? false;\n this._updateIsSelected(manager.focusedContent.value);\n this._updateEditedValue(manager);\n\n const handleEnabledChange = (e: Event) => {\n this._editorEnabled = (e as CustomEvent<boolean>).detail;\n this._render();\n };\n const handleFocusedChange = (e: Event) => {\n this._updateIsSelected((e as CustomEvent<FileContent | null>).detail);\n };\n const handleEditedContentChange = () => {\n this._updateEditedValue(manager);\n };\n\n manager.editorEnabled.addEventListener('change', handleEnabledChange);\n manager.focusedContent.addEventListener('change', handleFocusedChange);\n manager.editedContent.addEventListener('change', handleEditedContentChange);\n\n this._unsubManagerState = () => {\n manager.editorEnabled.removeEventListener('change', handleEnabledChange);\n manager.focusedContent.removeEventListener('change', handleFocusedChange);\n manager.editedContent.removeEventListener(\n 'change',\n handleEditedContentChange\n );\n };\n }\n\n private _handlePress(e: Event): void {\n // Stop propagation so nested wrappers don't also fire (composed + bubbles)\n e.stopPropagation();\n const manager = getGlobalEditorManager();\n if (!manager) return;\n manager.focusedContent.set({\n dictionaryKey: this._dictionaryKey,\n keyPath: this._getFilteredKeyPath(),\n });\n }\n\n private _handleHover(e: Event): void {\n e.stopPropagation();\n getGlobalEditorManager()?.messenger.send(\n `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n {\n dictionaryKey: this._dictionaryKey,\n keyPath: this._getFilteredKeyPath(),\n }\n );\n }\n\n private _handleUnhover(e: Event): void {\n e.stopPropagation();\n getGlobalEditorManager()?.messenger.send(\n `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n null\n );\n }\n\n private _render(): void {\n const useWrapper = this._isInIframe && this._editorEnabled;\n const editedValue = this._editedValue;\n const isSimpleValue =\n typeof editedValue === 'string' ||\n typeof editedValue === 'number' ||\n typeof editedValue === 'boolean';\n\n const newState: RenderState = !useWrapper\n ? 'simple'\n : isSimpleValue\n ? 'wrapped-text'\n : 'wrapped-slot';\n\n if (this._renderState !== newState) {\n this._rebuildContent(newState);\n return;\n }\n\n // Structure unchanged — update only dynamic parts\n if (newState !== 'simple' && this._selector) {\n this._updateSelectorAttr();\n if (\n newState === 'wrapped-text' &&\n this._selector.firstChild?.nodeType === Node.TEXT_NODE\n ) {\n (this._selector.firstChild as Text).data = String(editedValue);\n }\n }\n }\n\n private _rebuildContent(state: RenderState): void {\n const shadow = this.shadowRoot!;\n // Remove all nodes except the style element (first child)\n while (shadow.childNodes.length > 1) {\n shadow.removeChild(shadow.lastChild!);\n }\n this._selector = null;\n\n if (state === 'simple') {\n shadow.appendChild(document.createElement('slot'));\n } else {\n const selector = document.createElement('intlayer-content-selector');\n this._selector = selector;\n if (this._isSelected) selector.setAttribute('is-selecting', '');\n selector.addEventListener('intlayer:press', (e) => this._handlePress(e));\n selector.addEventListener('intlayer:hover', (e) => this._handleHover(e));\n selector.addEventListener('intlayer:unhover', (e) =>\n this._handleUnhover(e)\n );\n\n if (state === 'wrapped-text') {\n selector.appendChild(\n document.createTextNode(String(this._editedValue))\n );\n } else {\n selector.appendChild(document.createElement('slot'));\n }\n shadow.appendChild(selector);\n }\n\n this._renderState = state;\n }\n}\n\nexport const defineIntlayerContentSelectorWrapper = (): void => {\n if (typeof customElements === 'undefined') return;\n\n if (!customElements.get('intlayer-content-selector-wrapper')) {\n customElements.define(\n 'intlayer-content-selector-wrapper',\n IntlayerContentSelectorWrapperElement\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;AAsBA,MAAM,0BAA0B;;AAGhC,MAAM,qBAAqB,YACzB,QAAQ,iBACN,QAAQ,YAAY,CAAC,CAAgB,QACvC;;AAGF,MAAM,iBAAiB,UAAuC;CAC5D,MAAM,kBACJ,MAAM,aAAa,MAAM,cAAc,SACnC,IAAI,kBAAkB,MAAM,SAAS,CAAC,CAAC,MACvC;CAEN,MAAM,kBAAkB,OAAO,WAC7B,MAAM,WAAW,MAAM,GAAG,CAAC,CAAC,MAAM,EACpC;CAEA,OACE,mBAAmB,OAAO,MAAM,eAAe,IAAI,IAAI;AAE3D;;;;;;;;;;AAWA,MAAM,0BAA0B,YAA6B;CAC3D,IAAI,SAAS;CAEb,KACE,IAAI,WAA2B,SAC/B,UACA,WAAW,kB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EAEpB,OAAO,OAAO,WAAW,SAAS,GAChC,OAAO,YAAY,OAAO,SAAU;EAEtC,KAAK,YAAY;EAEjB,IAAI,UAAU,UACZ,OAAO,YAAY,SAAS,cAAc,MAAM,CAAC;OAC5C;GACL,MAAM,WAAW,SAAS,cAAc,2BAA2B;GACnE,KAAK,YAAY;GACjB,IAAI,KAAK,aAAa,SAAS,aAAa,gBAAgB,EAAE;GAC9D,SAAS,iBAAiB,mBAAmB,MAAM,KAAK,aAAa,CAAC,CAAC;GACvE,SAAS,iBAAiB,mBAAmB,MAAM,KAAK,aAAa,CAAC,CAAC;GACvE,SAAS,iBAAiB,qBAAqB,MAC7C,KAAK,eAAe,CAAC,CACvB;GAEA,IAAI,UAAU,gBACZ,SAAS,YACP,SAAS,eAAe,OAAO,KAAK,YAAY,CAAC,CACnD;QAEA,SAAS,YAAY,SAAS,cAAc,MAAM,CAAC;GAErD,OAAO,YAAY,QAAQ;EAC7B;EAEA,KAAK,eAAe;CACtB;AACF;AAEA,MAAa,6CAAmD;CAC9D,IAAI,OAAO,mBAAmB,aAAa;CAE3C,IAAI,CAAC,eAAe,IAAI,mCAAmC,GACzD,eAAe,OACb,qCACA,qCACF;AAEJ"}
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_components_ContentSelectorWrapper = require('./ContentSelectorWrapper.cjs');
|
|
3
|
-
const require_components_EditedContent = require('./EditedContent.cjs');
|
|
4
|
-
const require_components_IntlayerEditor = require('./IntlayerEditor.cjs');
|
|
5
3
|
const require_components_ContentSelector = require('./ContentSelector.cjs');
|
|
6
4
|
|
|
7
5
|
exports.IntlayerContentSelectorElement = require_components_ContentSelector.IntlayerContentSelectorElement;
|
|
8
6
|
exports.IntlayerContentSelectorWrapperElement = require_components_ContentSelectorWrapper.IntlayerContentSelectorWrapperElement;
|
|
9
|
-
exports.IntlayerEditedContentElement = require_components_EditedContent.IntlayerEditedContentElement;
|
|
10
|
-
exports.IntlayerEditorElement = require_components_IntlayerEditor.IntlayerEditorElement;
|
|
11
7
|
exports.defineIntlayerContentSelectorWrapper = require_components_ContentSelectorWrapper.defineIntlayerContentSelectorWrapper;
|
|
12
|
-
exports.defineIntlayerEditedContent = require_components_EditedContent.defineIntlayerEditedContent;
|
|
13
|
-
exports.defineIntlayerEditorElement = require_components_IntlayerEditor.defineIntlayerEditorElement;
|
|
14
8
|
exports.defineIntlayerElements = require_components_ContentSelector.defineIntlayerElements;
|
|
@@ -3,15 +3,16 @@ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
|
3
3
|
const require_messageKey = require('../messageKey.cjs');
|
|
4
4
|
const require_core_CrossFrameMessenger = require('./CrossFrameMessenger.cjs');
|
|
5
5
|
const require_core_CrossFrameStateManager = require('./CrossFrameStateManager.cjs');
|
|
6
|
-
const require_core_editedContentBus = require('./editedContentBus.cjs');
|
|
7
|
-
const require_core_focusedContentBus = require('./focusedContentBus.cjs');
|
|
8
6
|
const require_core_IframeClickInterceptor = require('./IframeClickInterceptor.cjs');
|
|
7
|
+
const require_core_sharedWindowState = require('./sharedWindowState.cjs');
|
|
9
8
|
const require_core_UrlStateManager = require('./UrlStateManager.cjs');
|
|
10
9
|
let _intlayer_types_nodeType = require("@intlayer/types/nodeType");
|
|
11
10
|
_intlayer_types_nodeType = require_runtime.__toESM(_intlayer_types_nodeType);
|
|
12
11
|
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
13
12
|
|
|
14
13
|
//#region src/core/EditorStateManager.ts
|
|
14
|
+
const sharedEditedContent = require_core_sharedWindowState.createSharedWindowState("edited_content");
|
|
15
|
+
const sharedFocusedContent = require_core_sharedWindowState.createSharedWindowState("focused_content");
|
|
15
16
|
/**
|
|
16
17
|
* EditorStateManager is the single entry point for all Intlayer editor state.
|
|
17
18
|
* It is framework-agnostic: instantiate one instance at the root of the application
|
|
@@ -39,12 +40,7 @@ var EditorStateManager = class {
|
|
|
39
40
|
_displayedKeysObserver = null;
|
|
40
41
|
_displayedKeysTimer = null;
|
|
41
42
|
_displayedKeysListeners = [];
|
|
42
|
-
|
|
43
|
-
_unsubGlobalEditedContent = null;
|
|
44
|
-
_editedContentBusHandler = null;
|
|
45
|
-
_focusedContentFromBus = false;
|
|
46
|
-
_unsubGlobalFocusedContent = null;
|
|
47
|
-
_focusedContentBusHandler = null;
|
|
43
|
+
_stopSharedStateSyncs = [];
|
|
48
44
|
constructor(config) {
|
|
49
45
|
this._mode = config.mode;
|
|
50
46
|
this._configuration = config.configuration;
|
|
@@ -87,8 +83,7 @@ var EditorStateManager = class {
|
|
|
87
83
|
this.configuration.start();
|
|
88
84
|
this.currentLocale.start();
|
|
89
85
|
this.displayedDictionaryKeys.start();
|
|
90
|
-
this.
|
|
91
|
-
this._startFocusedContentBusSync();
|
|
86
|
+
this._stopSharedStateSyncs = [this._syncWithSharedState(this.editedContent, sharedEditedContent, (content) => Object.keys(content).length > 0), this._syncWithSharedState(this.focusedContent, sharedFocusedContent)];
|
|
92
87
|
if (this._mode === "client") {
|
|
93
88
|
this._urlManager.start();
|
|
94
89
|
this._iframeInterceptor.startInterceptor();
|
|
@@ -117,8 +112,8 @@ var EditorStateManager = class {
|
|
|
117
112
|
this.currentLocale.stop();
|
|
118
113
|
this.displayedDictionaryKeys.stop();
|
|
119
114
|
this._stopDisplayedDictionariesTracking();
|
|
120
|
-
this.
|
|
121
|
-
this.
|
|
115
|
+
for (const stopSync of this._stopSharedStateSyncs) stopSync();
|
|
116
|
+
this._stopSharedStateSyncs = [];
|
|
122
117
|
this._urlManager.stop();
|
|
123
118
|
this._iframeInterceptor.stopInterceptor();
|
|
124
119
|
this._iframeInterceptor.stopMerger();
|
|
@@ -130,6 +125,7 @@ var EditorStateManager = class {
|
|
|
130
125
|
pingClient() {
|
|
131
126
|
if (this._mode !== "editor") return;
|
|
132
127
|
this.messenger.send("INTLAYER_ARE_YOU_THERE");
|
|
128
|
+
this.messenger.send(`${"INTLAYER_EDITOR_ENABLED"}/post`, true);
|
|
133
129
|
}
|
|
134
130
|
setFocusedContentKeyPath(keyPath) {
|
|
135
131
|
const filtered = keyPath.filter((key) => key.type !== _intlayer_types_nodeType.TRANSLATION);
|
|
@@ -225,17 +221,8 @@ var EditorStateManager = class {
|
|
|
225
221
|
});
|
|
226
222
|
}
|
|
227
223
|
restoreContent(localDictionaryId) {
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
this.editedContent.set(updated);
|
|
231
|
-
}
|
|
232
|
-
clearContent(localDictionaryId) {
|
|
233
|
-
const filtered = { ...this.editedContent.value ?? {} };
|
|
234
|
-
delete filtered[localDictionaryId];
|
|
235
|
-
this.editedContent.set(filtered);
|
|
236
|
-
}
|
|
237
|
-
clearAllContent() {
|
|
238
|
-
this.editedContent.set({});
|
|
224
|
+
const { [localDictionaryId]: _restored, ...remainingContent } = this.editedContent.value ?? {};
|
|
225
|
+
this.editedContent.set(remainingContent);
|
|
239
226
|
}
|
|
240
227
|
getContentValue(localDictionaryIdOrKey, keyPath) {
|
|
241
228
|
const edited = this.editedContent.value;
|
|
@@ -254,61 +241,31 @@ var EditorStateManager = class {
|
|
|
254
241
|
if (node) return node;
|
|
255
242
|
}
|
|
256
243
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
244
|
+
/**
|
|
245
|
+
* Mirrors a state with the managers of the same window, seeding it with the
|
|
246
|
+
* shared value when there is one. Returns a function stopping the sync.
|
|
247
|
+
*/
|
|
248
|
+
_syncWithSharedState(state, sharedState, shouldSeed = () => true) {
|
|
249
|
+
let isApplyingSharedValue = false;
|
|
250
|
+
const applySharedValue = (value) => {
|
|
251
|
+
isApplyingSharedValue = true;
|
|
252
|
+
state.set(value);
|
|
253
|
+
isApplyingSharedValue = false;
|
|
262
254
|
};
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
this._editedContentFromBus = true;
|
|
267
|
-
this.editedContent.set(content);
|
|
268
|
-
this._editedContentFromBus = false;
|
|
269
|
-
});
|
|
270
|
-
const existing = require_core_editedContentBus.getGlobalEditedContent();
|
|
271
|
-
if (Object.keys(existing).length > 0) {
|
|
272
|
-
this._editedContentFromBus = true;
|
|
273
|
-
this.editedContent.set(existing);
|
|
274
|
-
this._editedContentFromBus = false;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
_stopEditedContentBusSync() {
|
|
278
|
-
if (this._editedContentBusHandler) {
|
|
279
|
-
this.editedContent.removeEventListener("change", this._editedContentBusHandler);
|
|
280
|
-
this._editedContentBusHandler = null;
|
|
281
|
-
}
|
|
282
|
-
this._unsubGlobalEditedContent?.();
|
|
283
|
-
this._unsubGlobalEditedContent = null;
|
|
284
|
-
}
|
|
285
|
-
_startFocusedContentBusSync() {
|
|
286
|
-
this._focusedContentBusHandler = (e) => {
|
|
287
|
-
if (this._focusedContentFromBus) return;
|
|
288
|
-
const content = e.detail;
|
|
289
|
-
require_core_focusedContentBus.setGlobalFocusedContent(content, this.messenger.senderId);
|
|
255
|
+
const publishLocalChange = (event) => {
|
|
256
|
+
if (isApplyingSharedValue) return;
|
|
257
|
+
sharedState.set(event.detail, this.messenger.senderId);
|
|
290
258
|
};
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
if (sourceId
|
|
294
|
-
this._focusedContentFromBus = true;
|
|
295
|
-
this.focusedContent.set(content);
|
|
296
|
-
this._focusedContentFromBus = false;
|
|
259
|
+
state.addEventListener("change", publishLocalChange);
|
|
260
|
+
const unsubscribeShared = sharedState.subscribe((value, sourceId) => {
|
|
261
|
+
if (sourceId !== this.messenger.senderId) applySharedValue(value);
|
|
297
262
|
});
|
|
298
|
-
const
|
|
299
|
-
if (
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
_stopFocusedContentBusSync() {
|
|
306
|
-
if (this._focusedContentBusHandler) {
|
|
307
|
-
this.focusedContent.removeEventListener("change", this._focusedContentBusHandler);
|
|
308
|
-
this._focusedContentBusHandler = null;
|
|
309
|
-
}
|
|
310
|
-
this._unsubGlobalFocusedContent?.();
|
|
311
|
-
this._unsubGlobalFocusedContent = null;
|
|
263
|
+
const sharedValue = sharedState.get();
|
|
264
|
+
if (sharedValue !== void 0 && shouldSeed(sharedValue)) applySharedValue(sharedValue);
|
|
265
|
+
return () => {
|
|
266
|
+
state.removeEventListener("change", publishLocalChange);
|
|
267
|
+
unsubscribeShared();
|
|
268
|
+
};
|
|
312
269
|
}
|
|
313
270
|
_scanDisplayedDictionaryKeys() {
|
|
314
271
|
if (typeof document === "undefined") return;
|