@intlayer/next-i18next 8.12.5-canary.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/README.md +330 -0
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/cjs/appWithTranslation.cjs +31 -0
- package/dist/cjs/appWithTranslation.cjs.map +1 -0
- package/dist/cjs/index.cjs +69 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/compareUrls.cjs +39 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/compareUrls.cjs.map +1 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/components/ContentSelector.cjs +161 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/components/ContentSelector.cjs.map +1 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/components/ContentSelectorWrapper.cjs +269 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/components/ContentSelectorWrapper.cjs.map +1 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/components/EditedContent.cjs +161 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/components/EditedContent.cjs.map +1 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/components/IntlayerEditorElement.cjs +88 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/components/IntlayerEditorElement.cjs.map +1 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/components/defineIntlayerElements.cjs +27 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/components/defineIntlayerElements.cjs.map +1 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/core/CrossFrameMessenger.cjs +80 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/core/CrossFrameMessenger.cjs.map +1 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/core/CrossFrameStateManager.cjs +75 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/core/CrossFrameStateManager.cjs.map +1 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/core/EditorStateManager.cjs +383 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/core/EditorStateManager.cjs.map +1 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/core/IframeClickInterceptor.cjs +45 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/core/IframeClickInterceptor.cjs.map +1 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/core/UrlStateManager.cjs +59 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/core/UrlStateManager.cjs.map +1 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/core/editedContentBus.cjs +36 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/core/editedContentBus.cjs.map +1 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/core/focusedContentBus.cjs +42 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/core/focusedContentBus.cjs.map +1 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/core/globalManager.cjs +82 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/core/globalManager.cjs.map +1 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/core/initEditorClient.cjs +55 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/core/initEditorClient.cjs.map +1 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/index.cjs +19 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/isEnabled.cjs +9 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/isEnabled.cjs.map +1 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/mergeIframeClick.cjs +22 -0
- package/dist/cjs/packages/@intlayer/editor/dist/esm/mergeIframeClick.cjs.map +1 -0
- package/dist/cjs/packages/@intlayer/unmerged-dictionaries-entry/dist/esm/index.cjs +32 -0
- package/dist/cjs/packages/@intlayer/unmerged-dictionaries-entry/dist/esm/index.cjs.map +1 -0
- package/dist/cjs/packages/react-intlayer/dist/esm/client/IntlayerContext.cjs +25 -0
- package/dist/cjs/packages/react-intlayer/dist/esm/client/IntlayerContext.cjs.map +1 -0
- package/dist/cjs/packages/react-intlayer/dist/esm/client/IntlayerProvider.cjs +78 -0
- package/dist/cjs/packages/react-intlayer/dist/esm/client/IntlayerProvider.cjs.map +1 -0
- package/dist/cjs/packages/react-intlayer/dist/esm/client/useLocaleStorage.cjs +24 -0
- package/dist/cjs/packages/react-intlayer/dist/esm/client/useLocaleStorage.cjs.map +1 -0
- package/dist/cjs/packages/react-intlayer/dist/esm/editor/EditorProvider.cjs +11 -0
- package/dist/cjs/packages/react-intlayer/dist/esm/editor/EditorProvider.cjs.map +1 -0
- package/dist/cjs/packages/react-intlayer/dist/esm/editor/useEditor.cjs +39 -0
- package/dist/cjs/packages/react-intlayer/dist/esm/editor/useEditor.cjs.map +1 -0
- package/dist/cjs/plugin/index.cjs +170 -0
- package/dist/cjs/plugin/index.cjs.map +1 -0
- package/dist/cjs/serverSideTranslations.cjs +46 -0
- package/dist/cjs/serverSideTranslations.cjs.map +1 -0
- package/dist/esm/_virtual/_rolldown/runtime.mjs +8 -0
- package/dist/esm/appWithTranslation.mjs +29 -0
- package/dist/esm/appWithTranslation.mjs.map +1 -0
- package/dist/esm/index.mjs +11 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/compareUrls.mjs +38 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/compareUrls.mjs.map +1 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/components/ContentSelector.mjs +160 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/components/ContentSelector.mjs.map +1 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/components/ContentSelectorWrapper.mjs +266 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/components/ContentSelectorWrapper.mjs.map +1 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/components/EditedContent.mjs +159 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/components/EditedContent.mjs.map +1 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/components/IntlayerEditorElement.mjs +88 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/components/IntlayerEditorElement.mjs.map +1 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/components/defineIntlayerElements.mjs +26 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/components/defineIntlayerElements.mjs.map +1 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/core/CrossFrameMessenger.mjs +80 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/core/CrossFrameMessenger.mjs.map +1 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/core/CrossFrameStateManager.mjs +74 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/core/CrossFrameStateManager.mjs.map +1 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/core/EditorStateManager.mjs +381 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/core/EditorStateManager.mjs.map +1 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/core/IframeClickInterceptor.mjs +45 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/core/IframeClickInterceptor.mjs.map +1 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/core/UrlStateManager.mjs +58 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/core/UrlStateManager.mjs.map +1 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/core/editedContentBus.mjs +33 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/core/editedContentBus.mjs.map +1 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/core/focusedContentBus.mjs +39 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/core/focusedContentBus.mjs.map +1 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/core/globalManager.mjs +79 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/core/globalManager.mjs.map +1 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/core/initEditorClient.mjs +52 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/core/initEditorClient.mjs.map +1 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/index.mjs +18 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/isEnabled.mjs +8 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/isEnabled.mjs.map +1 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/mergeIframeClick.mjs +21 -0
- package/dist/esm/packages/@intlayer/editor/dist/esm/mergeIframeClick.mjs.map +1 -0
- package/dist/esm/packages/@intlayer/unmerged-dictionaries-entry/dist/esm/index.browser.mjs +6 -0
- package/dist/esm/packages/@intlayer/unmerged-dictionaries-entry/dist/esm/index.browser.mjs.map +1 -0
- package/dist/esm/packages/react-intlayer/dist/esm/client/IntlayerContext.mjs +23 -0
- package/dist/esm/packages/react-intlayer/dist/esm/client/IntlayerContext.mjs.map +1 -0
- package/dist/esm/packages/react-intlayer/dist/esm/client/IntlayerProvider.mjs +77 -0
- package/dist/esm/packages/react-intlayer/dist/esm/client/IntlayerProvider.mjs.map +1 -0
- package/dist/esm/packages/react-intlayer/dist/esm/client/useLocaleStorage.mjs +22 -0
- package/dist/esm/packages/react-intlayer/dist/esm/client/useLocaleStorage.mjs.map +1 -0
- package/dist/esm/packages/react-intlayer/dist/esm/editor/EditorProvider.mjs +11 -0
- package/dist/esm/packages/react-intlayer/dist/esm/editor/EditorProvider.mjs.map +1 -0
- package/dist/esm/packages/react-intlayer/dist/esm/editor/useEditor.mjs +38 -0
- package/dist/esm/packages/react-intlayer/dist/esm/editor/useEditor.mjs.map +1 -0
- package/dist/esm/plugin/index.mjs +165 -0
- package/dist/esm/plugin/index.mjs.map +1 -0
- package/dist/esm/serverSideTranslations.mjs +44 -0
- package/dist/esm/serverSideTranslations.mjs.map +1 -0
- package/dist/types/appWithTranslation.d.ts +18 -0
- package/dist/types/appWithTranslation.d.ts.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/plugin/index.d.ts +23 -0
- package/dist/types/plugin/index.d.ts.map +1 -0
- package/dist/types/serverSideTranslations.d.ts +33 -0
- package/dist/types/serverSideTranslations.d.ts.map +1 -0
- package/package.json +116 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { getGlobalEditorManager, onGlobalEditorManagerChange } from "../core/globalManager.mjs";
|
|
2
|
+
import * as NodeTypes from "@intlayer/types/nodeType";
|
|
3
|
+
import { isSameKeyPath } from "@intlayer/core/utils";
|
|
4
|
+
|
|
5
|
+
//#region ../../packages/@intlayer/editor/dist/esm/components/ContentSelectorWrapper.mjs
|
|
6
|
+
const _HTMLElement = typeof HTMLElement !== "undefined" ? HTMLElement : class {};
|
|
7
|
+
/**
|
|
8
|
+
* <intlayer-content-selector-wrapper>
|
|
9
|
+
*
|
|
10
|
+
* Framework-agnostic web component that wraps content with the Intlayer editor
|
|
11
|
+
* selection UI. It replaces the per-framework ContentSelectorWrapper components
|
|
12
|
+
* (Vue, Svelte, Solid, Preact).
|
|
13
|
+
*
|
|
14
|
+
* It reads from the global EditorStateManager singleton (set by initEditorClient)
|
|
15
|
+
* and conditionally renders <intlayer-content-selector> around its slot content
|
|
16
|
+
* when the editor is active and the app is running inside an iframe.
|
|
17
|
+
*
|
|
18
|
+
* @attr {string} key-path - JSON-serialized KeyPath[] for this content node
|
|
19
|
+
* @attr {string} dictionary-key - The dictionary key owning this content node
|
|
20
|
+
*/
|
|
21
|
+
var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
|
|
22
|
+
_keyPathJson = "[]";
|
|
23
|
+
_dictionaryKey = "";
|
|
24
|
+
_editorEnabled = false;
|
|
25
|
+
_isInIframe = false;
|
|
26
|
+
_isSelected = false;
|
|
27
|
+
_editedValue = void 0;
|
|
28
|
+
_renderState = null;
|
|
29
|
+
_selector = null;
|
|
30
|
+
_unsubManager = null;
|
|
31
|
+
_unsubEnabled = null;
|
|
32
|
+
_unsubFocused = null;
|
|
33
|
+
_unsubEditedContent = null;
|
|
34
|
+
static get observedAttributes() {
|
|
35
|
+
return ["key-path", "dictionary-key"];
|
|
36
|
+
}
|
|
37
|
+
get keyPathJson() {
|
|
38
|
+
return this._keyPathJson;
|
|
39
|
+
}
|
|
40
|
+
set keyPathJson(v) {
|
|
41
|
+
this._keyPathJson = v;
|
|
42
|
+
const manager = getGlobalEditorManager();
|
|
43
|
+
if (manager) this._updateEditedValue(manager);
|
|
44
|
+
}
|
|
45
|
+
get dictionaryKey() {
|
|
46
|
+
return this._dictionaryKey;
|
|
47
|
+
}
|
|
48
|
+
set dictionaryKey(v) {
|
|
49
|
+
this._dictionaryKey = v;
|
|
50
|
+
const manager = getGlobalEditorManager();
|
|
51
|
+
if (manager) this._updateEditedValue(manager);
|
|
52
|
+
}
|
|
53
|
+
constructor() {
|
|
54
|
+
super();
|
|
55
|
+
const shadow = this.attachShadow({ mode: "open" });
|
|
56
|
+
const style = document.createElement("style");
|
|
57
|
+
style.textContent = ":host { display: contents; }";
|
|
58
|
+
shadow.appendChild(style);
|
|
59
|
+
}
|
|
60
|
+
attributeChangedCallback(name, _oldVal, newVal) {
|
|
61
|
+
if (name === "key-path") {
|
|
62
|
+
this._keyPathJson = newVal ?? "[]";
|
|
63
|
+
const manager = getGlobalEditorManager();
|
|
64
|
+
if (manager) this._updateEditedValue(manager);
|
|
65
|
+
} else if (name === "dictionary-key") {
|
|
66
|
+
this._dictionaryKey = newVal ?? "";
|
|
67
|
+
const manager = getGlobalEditorManager();
|
|
68
|
+
if (manager) this._updateEditedValue(manager);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
connectedCallback() {
|
|
72
|
+
if (typeof window !== "undefined") this._isInIframe = window.self !== window.top;
|
|
73
|
+
this._subscribeToManager();
|
|
74
|
+
this._render();
|
|
75
|
+
}
|
|
76
|
+
disconnectedCallback() {
|
|
77
|
+
this._teardown();
|
|
78
|
+
}
|
|
79
|
+
_teardown() {
|
|
80
|
+
this._unsubManager?.();
|
|
81
|
+
this._unsubEnabled?.();
|
|
82
|
+
this._unsubFocused?.();
|
|
83
|
+
this._unsubEditedContent?.();
|
|
84
|
+
this._unsubManager = null;
|
|
85
|
+
this._unsubEnabled = null;
|
|
86
|
+
this._unsubFocused = null;
|
|
87
|
+
this._unsubEditedContent = null;
|
|
88
|
+
}
|
|
89
|
+
_getRawKeyPath() {
|
|
90
|
+
try {
|
|
91
|
+
return JSON.parse(this._keyPathJson);
|
|
92
|
+
} catch {
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
_getFilteredKeyPath() {
|
|
97
|
+
return this._getRawKeyPath().filter((keyPath) => keyPath.type !== NodeTypes.TRANSLATION);
|
|
98
|
+
}
|
|
99
|
+
_updateEditedValue(manager) {
|
|
100
|
+
const filteredKeyPath = this._getFilteredKeyPath();
|
|
101
|
+
if (!this._dictionaryKey || filteredKeyPath.length === 0) {
|
|
102
|
+
this._editedValue = void 0;
|
|
103
|
+
this._render();
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const rawKeyPath = this._getRawKeyPath();
|
|
107
|
+
const lastStepType = rawKeyPath[rawKeyPath.length - 1]?.type;
|
|
108
|
+
if (lastStepType === NodeTypes.MARKDOWN || lastStepType === NodeTypes.HTML || lastStepType === NodeTypes.INSERTION || lastStepType === NodeTypes.FILE) {
|
|
109
|
+
this._editedValue = void 0;
|
|
110
|
+
this._render();
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
let value = manager.getContentValue(this._dictionaryKey, filteredKeyPath);
|
|
114
|
+
if (value !== null && value !== void 0 && typeof value === "object" && value.nodeType === NodeTypes.TRANSLATION) {
|
|
115
|
+
const locale = manager.currentLocale.value;
|
|
116
|
+
value = locale ? value[NodeTypes.TRANSLATION][locale] : void 0;
|
|
117
|
+
}
|
|
118
|
+
this._editedValue = value;
|
|
119
|
+
this._render();
|
|
120
|
+
}
|
|
121
|
+
_updateIsSelected(focusedContent) {
|
|
122
|
+
if (!focusedContent) {
|
|
123
|
+
this._isSelected = false;
|
|
124
|
+
this._updateSelectorAttr();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const keyPath = this._getFilteredKeyPath();
|
|
128
|
+
const wasSelected = this._isSelected;
|
|
129
|
+
this._isSelected = focusedContent.dictionaryKey === this._dictionaryKey && (focusedContent.keyPath?.length ?? 0) > 0 && isSameKeyPath(focusedContent.keyPath ?? [], keyPath);
|
|
130
|
+
this._updateSelectorAttr();
|
|
131
|
+
if (this._isSelected && !wasSelected) this._scrollIntoViewIfNeeded();
|
|
132
|
+
}
|
|
133
|
+
_scrollIntoViewIfNeeded() {
|
|
134
|
+
try {
|
|
135
|
+
let rect;
|
|
136
|
+
if (this._selector) {
|
|
137
|
+
const innerWrapper = this._selector.shadowRoot?.querySelector(".wrapper");
|
|
138
|
+
if (innerWrapper) {
|
|
139
|
+
const r = innerWrapper.getBoundingClientRect();
|
|
140
|
+
if (r.width > 0 || r.height > 0) rect = r;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (!rect && this.childNodes.length > 0) {
|
|
144
|
+
const range = document.createRange();
|
|
145
|
+
range.selectNodeContents(this);
|
|
146
|
+
const r = range.getBoundingClientRect();
|
|
147
|
+
if (r.width > 0 || r.height > 0) rect = r;
|
|
148
|
+
}
|
|
149
|
+
if (!rect) rect = this.getBoundingClientRect();
|
|
150
|
+
const viewportHeight = window.innerHeight || document.documentElement.clientHeight;
|
|
151
|
+
const viewportWidth = window.innerWidth || document.documentElement.clientWidth;
|
|
152
|
+
if (!(rect.width > 0 && rect.height > 0 && rect.bottom > 0 && rect.right > 0 && rect.top < viewportHeight && rect.left < viewportWidth)) {
|
|
153
|
+
const scrollY = window.scrollY ?? document.documentElement.scrollTop;
|
|
154
|
+
const targetScrollY = rect.top + scrollY - viewportHeight * .25;
|
|
155
|
+
window.scrollTo({
|
|
156
|
+
top: Math.max(0, targetScrollY),
|
|
157
|
+
behavior: "smooth"
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
} catch {}
|
|
161
|
+
}
|
|
162
|
+
_updateSelectorAttr() {
|
|
163
|
+
if (!this._selector) return;
|
|
164
|
+
if (this._isSelected) this._selector.setAttribute("is-selecting", "");
|
|
165
|
+
else this._selector.removeAttribute("is-selecting");
|
|
166
|
+
}
|
|
167
|
+
_subscribeToManager() {
|
|
168
|
+
const manager = getGlobalEditorManager();
|
|
169
|
+
if (manager) this._setupManagerSubscriptions(manager);
|
|
170
|
+
this._unsubManager = onGlobalEditorManagerChange((m) => {
|
|
171
|
+
this._unsubEnabled?.();
|
|
172
|
+
this._unsubFocused?.();
|
|
173
|
+
this._unsubEditedContent?.();
|
|
174
|
+
this._unsubEnabled = null;
|
|
175
|
+
this._unsubFocused = null;
|
|
176
|
+
this._unsubEditedContent = null;
|
|
177
|
+
if (m) this._setupManagerSubscriptions(m);
|
|
178
|
+
else {
|
|
179
|
+
this._editorEnabled = false;
|
|
180
|
+
this._isSelected = false;
|
|
181
|
+
this._editedValue = void 0;
|
|
182
|
+
this._render();
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
_setupManagerSubscriptions(manager) {
|
|
187
|
+
this._editorEnabled = manager.editorEnabled.value ?? false;
|
|
188
|
+
this._updateIsSelected(manager.focusedContent.value);
|
|
189
|
+
this._updateEditedValue(manager);
|
|
190
|
+
const handleEnabledChange = (e) => {
|
|
191
|
+
this._editorEnabled = e.detail;
|
|
192
|
+
this._render();
|
|
193
|
+
};
|
|
194
|
+
const handleFocusedChange = (e) => {
|
|
195
|
+
this._updateIsSelected(e.detail);
|
|
196
|
+
};
|
|
197
|
+
const handleEditedContentChange = () => {
|
|
198
|
+
this._updateEditedValue(manager);
|
|
199
|
+
};
|
|
200
|
+
manager.editorEnabled.addEventListener("change", handleEnabledChange);
|
|
201
|
+
manager.focusedContent.addEventListener("change", handleFocusedChange);
|
|
202
|
+
manager.editedContent.addEventListener("change", handleEditedContentChange);
|
|
203
|
+
this._unsubEnabled = () => manager.editorEnabled.removeEventListener("change", handleEnabledChange);
|
|
204
|
+
this._unsubFocused = () => manager.focusedContent.removeEventListener("change", handleFocusedChange);
|
|
205
|
+
this._unsubEditedContent = () => manager.editedContent.removeEventListener("change", handleEditedContentChange);
|
|
206
|
+
}
|
|
207
|
+
_handlePress(e) {
|
|
208
|
+
e.stopPropagation();
|
|
209
|
+
const manager = getGlobalEditorManager();
|
|
210
|
+
if (!manager) return;
|
|
211
|
+
manager.focusedContent.set({
|
|
212
|
+
dictionaryKey: this._dictionaryKey,
|
|
213
|
+
keyPath: this._getFilteredKeyPath()
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
_handleHover(e) {
|
|
217
|
+
e.stopPropagation();
|
|
218
|
+
getGlobalEditorManager()?.messenger.send(`INTLAYER_HOVERED_CONTENT_CHANGED/post`, {
|
|
219
|
+
dictionaryKey: this._dictionaryKey,
|
|
220
|
+
keyPath: this._getFilteredKeyPath()
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
_handleUnhover(e) {
|
|
224
|
+
e.stopPropagation();
|
|
225
|
+
getGlobalEditorManager()?.messenger.send(`INTLAYER_HOVERED_CONTENT_CHANGED/post`, null);
|
|
226
|
+
}
|
|
227
|
+
_render() {
|
|
228
|
+
const useWrapper = this._isInIframe && this._editorEnabled;
|
|
229
|
+
const editedValue = this._editedValue;
|
|
230
|
+
const newState = !useWrapper ? "simple" : typeof editedValue === "string" || typeof editedValue === "number" || typeof editedValue === "boolean" ? "wrapped-text" : "wrapped-slot";
|
|
231
|
+
if (this._renderState !== newState) {
|
|
232
|
+
this._rebuildContent(newState);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
if (newState !== "simple" && this._selector) {
|
|
236
|
+
this._updateSelectorAttr();
|
|
237
|
+
if (newState === "wrapped-text" && this._selector.firstChild?.nodeType === Node.TEXT_NODE) this._selector.firstChild.data = String(editedValue);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
_rebuildContent(state) {
|
|
241
|
+
const shadow = this.shadowRoot;
|
|
242
|
+
while (shadow.childNodes.length > 1) shadow.removeChild(shadow.lastChild);
|
|
243
|
+
this._selector = null;
|
|
244
|
+
if (state === "simple") shadow.appendChild(document.createElement("slot"));
|
|
245
|
+
else {
|
|
246
|
+
const selector = document.createElement("intlayer-content-selector");
|
|
247
|
+
this._selector = selector;
|
|
248
|
+
if (this._isSelected) selector.setAttribute("is-selecting", "");
|
|
249
|
+
selector.addEventListener("intlayer:press", (e) => this._handlePress(e));
|
|
250
|
+
selector.addEventListener("intlayer:hover", (e) => this._handleHover(e));
|
|
251
|
+
selector.addEventListener("intlayer:unhover", (e) => this._handleUnhover(e));
|
|
252
|
+
if (state === "wrapped-text") selector.appendChild(document.createTextNode(String(this._editedValue)));
|
|
253
|
+
else selector.appendChild(document.createElement("slot"));
|
|
254
|
+
shadow.appendChild(selector);
|
|
255
|
+
}
|
|
256
|
+
this._renderState = state;
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
const defineIntlayerContentSelectorWrapper = () => {
|
|
260
|
+
if (typeof customElements === "undefined") return;
|
|
261
|
+
if (!customElements.get("intlayer-content-selector-wrapper")) customElements.define("intlayer-content-selector-wrapper", IntlayerContentSelectorWrapperElement);
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
//#endregion
|
|
265
|
+
export { IntlayerContentSelectorWrapperElement, defineIntlayerContentSelectorWrapper };
|
|
266
|
+
//# sourceMappingURL=ContentSelectorWrapper.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentSelectorWrapper.mjs","names":[],"sources":["../../../../../../../../../../packages/@intlayer/editor/dist/esm/components/ContentSelectorWrapper.mjs"],"sourcesContent":["import { MessageKey } from \"../messageKey.mjs\";\nimport { getGlobalEditorManager, onGlobalEditorManagerChange } from \"../core/globalManager.mjs\";\nimport { isSameKeyPath } from \"@intlayer/core/utils\";\nimport * as NodeTypes from \"@intlayer/types/nodeType\";\n\n//#region src/components/ContentSelectorWrapper.ts\nconst _HTMLElement = typeof HTMLElement !== \"undefined\" ? HTMLElement : class {};\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*/\nvar IntlayerContentSelectorWrapperElement = class extends _HTMLElement {\n\t_keyPathJson = \"[]\";\n\t_dictionaryKey = \"\";\n\t_editorEnabled = false;\n\t_isInIframe = false;\n\t_isSelected = false;\n\t_editedValue = void 0;\n\t_renderState = null;\n\t_selector = null;\n\t_unsubManager = null;\n\t_unsubEnabled = null;\n\t_unsubFocused = null;\n\t_unsubEditedContent = null;\n\tstatic get observedAttributes() {\n\t\treturn [\"key-path\", \"dictionary-key\"];\n\t}\n\tget keyPathJson() {\n\t\treturn this._keyPathJson;\n\t}\n\tset keyPathJson(v) {\n\t\tthis._keyPathJson = v;\n\t\tconst manager = getGlobalEditorManager();\n\t\tif (manager) this._updateEditedValue(manager);\n\t}\n\tget dictionaryKey() {\n\t\treturn this._dictionaryKey;\n\t}\n\tset dictionaryKey(v) {\n\t\tthis._dictionaryKey = v;\n\t\tconst manager = getGlobalEditorManager();\n\t\tif (manager) this._updateEditedValue(manager);\n\t}\n\tconstructor() {\n\t\tsuper();\n\t\tconst shadow = this.attachShadow({ mode: \"open\" });\n\t\tconst style = document.createElement(\"style\");\n\t\tstyle.textContent = \":host { display: contents; }\";\n\t\tshadow.appendChild(style);\n\t}\n\tattributeChangedCallback(name, _oldVal, newVal) {\n\t\tif (name === \"key-path\") {\n\t\t\tthis._keyPathJson = newVal ?? \"[]\";\n\t\t\tconst manager = getGlobalEditorManager();\n\t\t\tif (manager) this._updateEditedValue(manager);\n\t\t} else if (name === \"dictionary-key\") {\n\t\t\tthis._dictionaryKey = newVal ?? \"\";\n\t\t\tconst manager = getGlobalEditorManager();\n\t\t\tif (manager) this._updateEditedValue(manager);\n\t\t}\n\t}\n\tconnectedCallback() {\n\t\tif (typeof window !== \"undefined\") this._isInIframe = window.self !== window.top;\n\t\tthis._subscribeToManager();\n\t\tthis._render();\n\t}\n\tdisconnectedCallback() {\n\t\tthis._teardown();\n\t}\n\t_teardown() {\n\t\tthis._unsubManager?.();\n\t\tthis._unsubEnabled?.();\n\t\tthis._unsubFocused?.();\n\t\tthis._unsubEditedContent?.();\n\t\tthis._unsubManager = null;\n\t\tthis._unsubEnabled = null;\n\t\tthis._unsubFocused = null;\n\t\tthis._unsubEditedContent = null;\n\t}\n\t_getRawKeyPath() {\n\t\ttry {\n\t\t\treturn JSON.parse(this._keyPathJson);\n\t\t} catch {\n\t\t\treturn [];\n\t\t}\n\t}\n\t_getFilteredKeyPath() {\n\t\treturn this._getRawKeyPath().filter((keyPath) => keyPath.type !== NodeTypes.TRANSLATION);\n\t}\n\t_updateEditedValue(manager) {\n\t\tconst filteredKeyPath = this._getFilteredKeyPath();\n\t\tif (!this._dictionaryKey || filteredKeyPath.length === 0) {\n\t\t\tthis._editedValue = void 0;\n\t\t\tthis._render();\n\t\t\treturn;\n\t\t}\n\t\tconst rawKeyPath = this._getRawKeyPath();\n\t\tconst lastStepType = rawKeyPath[rawKeyPath.length - 1]?.type;\n\t\tif (lastStepType === NodeTypes.MARKDOWN || lastStepType === NodeTypes.HTML || lastStepType === NodeTypes.INSERTION || lastStepType === NodeTypes.FILE) {\n\t\t\tthis._editedValue = void 0;\n\t\t\tthis._render();\n\t\t\treturn;\n\t\t}\n\t\tlet value = manager.getContentValue(this._dictionaryKey, filteredKeyPath);\n\t\tif (value !== null && value !== void 0 && typeof value === \"object\" && value.nodeType === NodeTypes.TRANSLATION) {\n\t\t\tconst locale = manager.currentLocale.value;\n\t\t\tvalue = locale ? value[NodeTypes.TRANSLATION][locale] : void 0;\n\t\t}\n\t\tthis._editedValue = value;\n\t\tthis._render();\n\t}\n\t_updateIsSelected(focusedContent) {\n\t\tif (!focusedContent) {\n\t\t\tthis._isSelected = false;\n\t\t\tthis._updateSelectorAttr();\n\t\t\treturn;\n\t\t}\n\t\tconst keyPath = this._getFilteredKeyPath();\n\t\tconst wasSelected = this._isSelected;\n\t\tthis._isSelected = focusedContent.dictionaryKey === this._dictionaryKey && (focusedContent.keyPath?.length ?? 0) > 0 && isSameKeyPath(focusedContent.keyPath ?? [], keyPath);\n\t\tthis._updateSelectorAttr();\n\t\tif (this._isSelected && !wasSelected) this._scrollIntoViewIfNeeded();\n\t}\n\t_scrollIntoViewIfNeeded() {\n\t\ttry {\n\t\t\tlet rect;\n\t\t\tif (this._selector) {\n\t\t\t\tconst innerWrapper = this._selector.shadowRoot?.querySelector(\".wrapper\");\n\t\t\t\tif (innerWrapper) {\n\t\t\t\t\tconst r = innerWrapper.getBoundingClientRect();\n\t\t\t\t\tif (r.width > 0 || r.height > 0) rect = r;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!rect && this.childNodes.length > 0) {\n\t\t\t\tconst range = document.createRange();\n\t\t\t\trange.selectNodeContents(this);\n\t\t\t\tconst r = range.getBoundingClientRect();\n\t\t\t\tif (r.width > 0 || r.height > 0) rect = r;\n\t\t\t}\n\t\t\tif (!rect) rect = this.getBoundingClientRect();\n\t\t\tconst viewportHeight = window.innerHeight || document.documentElement.clientHeight;\n\t\t\tconst viewportWidth = window.innerWidth || document.documentElement.clientWidth;\n\t\t\tif (!(rect.width > 0 && rect.height > 0 && rect.bottom > 0 && rect.right > 0 && rect.top < viewportHeight && rect.left < viewportWidth)) {\n\t\t\t\tconst scrollY = window.scrollY ?? document.documentElement.scrollTop;\n\t\t\t\tconst targetScrollY = rect.top + scrollY - viewportHeight * .25;\n\t\t\t\twindow.scrollTo({\n\t\t\t\t\ttop: Math.max(0, targetScrollY),\n\t\t\t\t\tbehavior: \"smooth\"\n\t\t\t\t});\n\t\t\t}\n\t\t} catch {}\n\t}\n\t_updateSelectorAttr() {\n\t\tif (!this._selector) return;\n\t\tif (this._isSelected) this._selector.setAttribute(\"is-selecting\", \"\");\n\t\telse this._selector.removeAttribute(\"is-selecting\");\n\t}\n\t_subscribeToManager() {\n\t\tconst manager = getGlobalEditorManager();\n\t\tif (manager) this._setupManagerSubscriptions(manager);\n\t\tthis._unsubManager = onGlobalEditorManagerChange((m) => {\n\t\t\tthis._unsubEnabled?.();\n\t\t\tthis._unsubFocused?.();\n\t\t\tthis._unsubEditedContent?.();\n\t\t\tthis._unsubEnabled = null;\n\t\t\tthis._unsubFocused = null;\n\t\t\tthis._unsubEditedContent = null;\n\t\t\tif (m) this._setupManagerSubscriptions(m);\n\t\t\telse {\n\t\t\t\tthis._editorEnabled = false;\n\t\t\t\tthis._isSelected = false;\n\t\t\t\tthis._editedValue = void 0;\n\t\t\t\tthis._render();\n\t\t\t}\n\t\t});\n\t}\n\t_setupManagerSubscriptions(manager) {\n\t\tthis._editorEnabled = manager.editorEnabled.value ?? false;\n\t\tthis._updateIsSelected(manager.focusedContent.value);\n\t\tthis._updateEditedValue(manager);\n\t\tconst handleEnabledChange = (e) => {\n\t\t\tthis._editorEnabled = e.detail;\n\t\t\tthis._render();\n\t\t};\n\t\tconst handleFocusedChange = (e) => {\n\t\t\tthis._updateIsSelected(e.detail);\n\t\t};\n\t\tconst handleEditedContentChange = () => {\n\t\t\tthis._updateEditedValue(manager);\n\t\t};\n\t\tmanager.editorEnabled.addEventListener(\"change\", handleEnabledChange);\n\t\tmanager.focusedContent.addEventListener(\"change\", handleFocusedChange);\n\t\tmanager.editedContent.addEventListener(\"change\", handleEditedContentChange);\n\t\tthis._unsubEnabled = () => manager.editorEnabled.removeEventListener(\"change\", handleEnabledChange);\n\t\tthis._unsubFocused = () => manager.focusedContent.removeEventListener(\"change\", handleFocusedChange);\n\t\tthis._unsubEditedContent = () => manager.editedContent.removeEventListener(\"change\", handleEditedContentChange);\n\t}\n\t_handlePress(e) {\n\t\te.stopPropagation();\n\t\tconst manager = getGlobalEditorManager();\n\t\tif (!manager) return;\n\t\tmanager.focusedContent.set({\n\t\t\tdictionaryKey: this._dictionaryKey,\n\t\t\tkeyPath: this._getFilteredKeyPath()\n\t\t});\n\t}\n\t_handleHover(e) {\n\t\te.stopPropagation();\n\t\tgetGlobalEditorManager()?.messenger.send(`${\"INTLAYER_HOVERED_CONTENT_CHANGED\"}/post`, {\n\t\t\tdictionaryKey: this._dictionaryKey,\n\t\t\tkeyPath: this._getFilteredKeyPath()\n\t\t});\n\t}\n\t_handleUnhover(e) {\n\t\te.stopPropagation();\n\t\tgetGlobalEditorManager()?.messenger.send(`${\"INTLAYER_HOVERED_CONTENT_CHANGED\"}/post`, null);\n\t}\n\t_render() {\n\t\tconst useWrapper = this._isInIframe && this._editorEnabled;\n\t\tconst editedValue = this._editedValue;\n\t\tconst newState = !useWrapper ? \"simple\" : typeof editedValue === \"string\" || typeof editedValue === \"number\" || typeof editedValue === \"boolean\" ? \"wrapped-text\" : \"wrapped-slot\";\n\t\tif (this._renderState !== newState) {\n\t\t\tthis._rebuildContent(newState);\n\t\t\treturn;\n\t\t}\n\t\tif (newState !== \"simple\" && this._selector) {\n\t\t\tthis._updateSelectorAttr();\n\t\t\tif (newState === \"wrapped-text\" && this._selector.firstChild?.nodeType === Node.TEXT_NODE) this._selector.firstChild.data = String(editedValue);\n\t\t}\n\t}\n\t_rebuildContent(state) {\n\t\tconst shadow = this.shadowRoot;\n\t\twhile (shadow.childNodes.length > 1) shadow.removeChild(shadow.lastChild);\n\t\tthis._selector = null;\n\t\tif (state === \"simple\") shadow.appendChild(document.createElement(\"slot\"));\n\t\telse {\n\t\t\tconst selector = document.createElement(\"intlayer-content-selector\");\n\t\t\tthis._selector = selector;\n\t\t\tif (this._isSelected) selector.setAttribute(\"is-selecting\", \"\");\n\t\t\tselector.addEventListener(\"intlayer:press\", (e) => this._handlePress(e));\n\t\t\tselector.addEventListener(\"intlayer:hover\", (e) => this._handleHover(e));\n\t\t\tselector.addEventListener(\"intlayer:unhover\", (e) => this._handleUnhover(e));\n\t\t\tif (state === \"wrapped-text\") selector.appendChild(document.createTextNode(String(this._editedValue)));\n\t\t\telse selector.appendChild(document.createElement(\"slot\"));\n\t\t\tshadow.appendChild(selector);\n\t\t}\n\t\tthis._renderState = state;\n\t}\n};\nconst defineIntlayerContentSelectorWrapper = () => {\n\tif (typeof customElements === \"undefined\") return;\n\tif (!customElements.get(\"intlayer-content-selector-wrapper\")) customElements.define(\"intlayer-content-selector-wrapper\", IntlayerContentSelectorWrapperElement);\n};\n\n//#endregion\nexport { IntlayerContentSelectorWrapperElement, defineIntlayerContentSelectorWrapper };\n//# sourceMappingURL=ContentSelectorWrapper.mjs.map"],"mappings":";;;;;AAMA,MAAM,eAAe,OAAO,gBAAgB,cAAc,cAAc,MAAM;;;;;;;;;;;;;;;AAe9E,IAAI,wCAAwC,cAAc,aAAa;CACtE,eAAe;CACf,iBAAiB;CACjB,iBAAiB;CACjB,cAAc;CACd,cAAc;CACd,eAAe,KAAK;CACpB,eAAe;CACf,YAAY;CACZ,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;CAChB,sBAAsB;CACtB,WAAW,qBAAqB;AAC/B,SAAO,CAAC,YAAY,iBAAiB;;CAEtC,IAAI,cAAc;AACjB,SAAO,KAAK;;CAEb,IAAI,YAAY,GAAG;AAClB,OAAK,eAAe;EACpB,MAAM,UAAU,wBAAwB;AACxC,MAAI,QAAS,MAAK,mBAAmB,QAAQ;;CAE9C,IAAI,gBAAgB;AACnB,SAAO,KAAK;;CAEb,IAAI,cAAc,GAAG;AACpB,OAAK,iBAAiB;EACtB,MAAM,UAAU,wBAAwB;AACxC,MAAI,QAAS,MAAK,mBAAmB,QAAQ;;CAE9C,cAAc;AACb,SAAO;EACP,MAAM,SAAS,KAAK,aAAa,EAAE,MAAM,QAAQ,CAAC;EAClD,MAAM,QAAQ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,mBAAmB,MAAM,KAAK,aAAa,EAAE,CAAC;AACxE,YAAS,iBAAiB,mBAAmB,MAAM,KAAK,aAAa,EAAE,CAAC;AACxE,YAAS,iBAAiB,qBAAqB,MAAM,KAAK,eAAe,EAAE,CAAC;AAC5E,OAAI,UAAU,eAAgB,UAAS,YAAY,SAAS,eAAe,OAAO,KAAK,aAAa,CAAC,CAAC;OACjG,UAAS,YAAY,SAAS,cAAc,OAAO,CAAC;AACzD,UAAO,YAAY,SAAS;;AAE7B,OAAK,eAAe;;;AAGtB,MAAM,6CAA6C;AAClD,KAAI,OAAO,mBAAmB,YAAa;AAC3C,KAAI,CAAC,eAAe,IAAI,oCAAoC,CAAE,gBAAe,OAAO,qCAAqC,sCAAsC"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { getGlobalEditorManager, onGlobalEditorManagerChange } from "../core/globalManager.mjs";
|
|
2
|
+
import { getBasePlugins, getContent } from "@intlayer/core/interpreter";
|
|
3
|
+
|
|
4
|
+
//#region ../../packages/@intlayer/editor/dist/esm/components/EditedContent.mjs
|
|
5
|
+
const _HTMLElement = typeof HTMLElement !== "undefined" ? HTMLElement : class {};
|
|
6
|
+
/**
|
|
7
|
+
* <intlayer-edited-content>
|
|
8
|
+
*
|
|
9
|
+
* Framework-agnostic web component that displays edited content from the Intlayer
|
|
10
|
+
* editor. When the editor has an edited value for the given dictionary key and
|
|
11
|
+
* key path, it renders the edited value; otherwise it renders the original
|
|
12
|
+
* content via a slot.
|
|
13
|
+
*
|
|
14
|
+
* Always wraps content in <intlayer-content-selector-wrapper> for selection UI.
|
|
15
|
+
*
|
|
16
|
+
* @attr {string} dictionary-key - The dictionary key owning this content node
|
|
17
|
+
* @attr {string} key-path - JSON-serialized KeyPath[] for this content node
|
|
18
|
+
* @attr {string} locale - The current locale string
|
|
19
|
+
*/
|
|
20
|
+
var IntlayerEditedContentElement = class extends _HTMLElement {
|
|
21
|
+
_dictionaryKey = "";
|
|
22
|
+
_keyPathJson = "[]";
|
|
23
|
+
_locale = "";
|
|
24
|
+
_editedText = null;
|
|
25
|
+
_unsubManager = null;
|
|
26
|
+
_unsubEditedContent = null;
|
|
27
|
+
_selectorWrapper;
|
|
28
|
+
_slot;
|
|
29
|
+
static get observedAttributes() {
|
|
30
|
+
return [
|
|
31
|
+
"dictionary-key",
|
|
32
|
+
"key-path",
|
|
33
|
+
"locale"
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
get dictionaryKey() {
|
|
37
|
+
return this._dictionaryKey;
|
|
38
|
+
}
|
|
39
|
+
set dictionaryKey(v) {
|
|
40
|
+
this._dictionaryKey = v;
|
|
41
|
+
this._selectorWrapper.setAttribute("dictionary-key", v);
|
|
42
|
+
}
|
|
43
|
+
get keyPathJson() {
|
|
44
|
+
return this._keyPathJson;
|
|
45
|
+
}
|
|
46
|
+
set keyPathJson(v) {
|
|
47
|
+
this._keyPathJson = v;
|
|
48
|
+
this._selectorWrapper.setAttribute("key-path", v);
|
|
49
|
+
}
|
|
50
|
+
get locale() {
|
|
51
|
+
return this._locale;
|
|
52
|
+
}
|
|
53
|
+
set locale(v) {
|
|
54
|
+
this._locale = v;
|
|
55
|
+
}
|
|
56
|
+
constructor() {
|
|
57
|
+
super();
|
|
58
|
+
const shadow = this.attachShadow({ mode: "open" });
|
|
59
|
+
const style = document.createElement("style");
|
|
60
|
+
style.textContent = ":host { display: contents; }";
|
|
61
|
+
shadow.appendChild(style);
|
|
62
|
+
this._selectorWrapper = document.createElement("intlayer-content-selector-wrapper");
|
|
63
|
+
this._slot = document.createElement("slot");
|
|
64
|
+
this._selectorWrapper.appendChild(this._slot);
|
|
65
|
+
shadow.appendChild(this._selectorWrapper);
|
|
66
|
+
}
|
|
67
|
+
attributeChangedCallback(name, _oldVal, newVal) {
|
|
68
|
+
const val = newVal ?? "";
|
|
69
|
+
if (name === "dictionary-key") {
|
|
70
|
+
this._dictionaryKey = val;
|
|
71
|
+
this._selectorWrapper.setAttribute("dictionary-key", val);
|
|
72
|
+
} else if (name === "key-path") {
|
|
73
|
+
this._keyPathJson = val || "[]";
|
|
74
|
+
this._selectorWrapper.setAttribute("key-path", this._keyPathJson);
|
|
75
|
+
} else if (name === "locale") this._locale = val;
|
|
76
|
+
}
|
|
77
|
+
connectedCallback() {
|
|
78
|
+
this._subscribeToManager();
|
|
79
|
+
}
|
|
80
|
+
disconnectedCallback() {
|
|
81
|
+
this._teardown();
|
|
82
|
+
}
|
|
83
|
+
_teardown() {
|
|
84
|
+
this._unsubManager?.();
|
|
85
|
+
this._unsubEditedContent?.();
|
|
86
|
+
this._unsubManager = null;
|
|
87
|
+
this._unsubEditedContent = null;
|
|
88
|
+
}
|
|
89
|
+
_getKeyPath() {
|
|
90
|
+
try {
|
|
91
|
+
return JSON.parse(this._keyPathJson);
|
|
92
|
+
} catch {
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
_render() {
|
|
97
|
+
while (this._selectorWrapper.firstChild) this._selectorWrapper.removeChild(this._selectorWrapper.firstChild);
|
|
98
|
+
if (this._editedText !== null) this._selectorWrapper.appendChild(document.createTextNode(this._editedText));
|
|
99
|
+
else this._selectorWrapper.appendChild(this._slot);
|
|
100
|
+
}
|
|
101
|
+
_resolveEditedText(manager) {
|
|
102
|
+
const keyPath = this._getKeyPath();
|
|
103
|
+
const editedValue = manager.getContentValue(this._dictionaryKey, keyPath);
|
|
104
|
+
if (editedValue === void 0 || editedValue === null) {
|
|
105
|
+
this._editedText = null;
|
|
106
|
+
this._render();
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (typeof editedValue === "string" || typeof editedValue === "number") {
|
|
110
|
+
this._editedText = String(editedValue);
|
|
111
|
+
this._render();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (typeof editedValue === "object") {
|
|
115
|
+
const locale = this._locale || void 0;
|
|
116
|
+
const transformed = getContent(editedValue, {
|
|
117
|
+
locale,
|
|
118
|
+
dictionaryKey: this._dictionaryKey,
|
|
119
|
+
keyPath
|
|
120
|
+
}, getBasePlugins(locale));
|
|
121
|
+
if (typeof transformed === "string" || typeof transformed === "number") this._editedText = String(transformed);
|
|
122
|
+
else {
|
|
123
|
+
console.error(`[intlayer-edited-content] Incorrect edited content format. Expected string. Value: ${JSON.stringify(transformed)}`);
|
|
124
|
+
this._editedText = null;
|
|
125
|
+
}
|
|
126
|
+
this._render();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
this._editedText = null;
|
|
130
|
+
this._render();
|
|
131
|
+
}
|
|
132
|
+
_setupManagerSubscriptions(manager) {
|
|
133
|
+
this._resolveEditedText(manager);
|
|
134
|
+
const handleChange = () => this._resolveEditedText(manager);
|
|
135
|
+
manager.editedContent.addEventListener("change", handleChange);
|
|
136
|
+
this._unsubEditedContent = () => manager.editedContent.removeEventListener("change", handleChange);
|
|
137
|
+
}
|
|
138
|
+
_subscribeToManager() {
|
|
139
|
+
const manager = getGlobalEditorManager();
|
|
140
|
+
if (manager) this._setupManagerSubscriptions(manager);
|
|
141
|
+
this._unsubManager = onGlobalEditorManagerChange((m) => {
|
|
142
|
+
this._unsubEditedContent?.();
|
|
143
|
+
this._unsubEditedContent = null;
|
|
144
|
+
if (m) this._setupManagerSubscriptions(m);
|
|
145
|
+
else {
|
|
146
|
+
this._editedText = null;
|
|
147
|
+
this._render();
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
const defineIntlayerEditedContent = () => {
|
|
153
|
+
if (typeof customElements === "undefined") return;
|
|
154
|
+
if (!customElements.get("intlayer-edited-content")) customElements.define("intlayer-edited-content", IntlayerEditedContentElement);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
//#endregion
|
|
158
|
+
export { IntlayerEditedContentElement, defineIntlayerEditedContent };
|
|
159
|
+
//# sourceMappingURL=EditedContent.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EditedContent.mjs","names":[],"sources":["../../../../../../../../../../packages/@intlayer/editor/dist/esm/components/EditedContent.mjs"],"sourcesContent":["import { getGlobalEditorManager, onGlobalEditorManagerChange } from \"../core/globalManager.mjs\";\nimport { getBasePlugins, getContent } from \"@intlayer/core/interpreter\";\n\n//#region src/components/EditedContent.ts\nconst _HTMLElement = typeof HTMLElement !== \"undefined\" ? HTMLElement : class {};\n/**\n* <intlayer-edited-content>\n*\n* Framework-agnostic web component that displays edited content from the Intlayer\n* editor. When the editor has an edited value for the given dictionary key and\n* key path, it renders the edited value; otherwise it renders the original\n* content via a slot.\n*\n* Always wraps content in <intlayer-content-selector-wrapper> for selection UI.\n*\n* @attr {string} dictionary-key - The dictionary key owning this content node\n* @attr {string} key-path - JSON-serialized KeyPath[] for this content node\n* @attr {string} locale - The current locale string\n*/\nvar IntlayerEditedContentElement = class extends _HTMLElement {\n\t_dictionaryKey = \"\";\n\t_keyPathJson = \"[]\";\n\t_locale = \"\";\n\t_editedText = null;\n\t_unsubManager = null;\n\t_unsubEditedContent = null;\n\t_selectorWrapper;\n\t_slot;\n\tstatic get observedAttributes() {\n\t\treturn [\n\t\t\t\"dictionary-key\",\n\t\t\t\"key-path\",\n\t\t\t\"locale\"\n\t\t];\n\t}\n\tget dictionaryKey() {\n\t\treturn this._dictionaryKey;\n\t}\n\tset dictionaryKey(v) {\n\t\tthis._dictionaryKey = v;\n\t\tthis._selectorWrapper.setAttribute(\"dictionary-key\", v);\n\t}\n\tget keyPathJson() {\n\t\treturn this._keyPathJson;\n\t}\n\tset keyPathJson(v) {\n\t\tthis._keyPathJson = v;\n\t\tthis._selectorWrapper.setAttribute(\"key-path\", v);\n\t}\n\tget locale() {\n\t\treturn this._locale;\n\t}\n\tset locale(v) {\n\t\tthis._locale = v;\n\t}\n\tconstructor() {\n\t\tsuper();\n\t\tconst shadow = this.attachShadow({ mode: \"open\" });\n\t\tconst style = document.createElement(\"style\");\n\t\tstyle.textContent = \":host { display: contents; }\";\n\t\tshadow.appendChild(style);\n\t\tthis._selectorWrapper = document.createElement(\"intlayer-content-selector-wrapper\");\n\t\tthis._slot = document.createElement(\"slot\");\n\t\tthis._selectorWrapper.appendChild(this._slot);\n\t\tshadow.appendChild(this._selectorWrapper);\n\t}\n\tattributeChangedCallback(name, _oldVal, newVal) {\n\t\tconst val = newVal ?? \"\";\n\t\tif (name === \"dictionary-key\") {\n\t\t\tthis._dictionaryKey = val;\n\t\t\tthis._selectorWrapper.setAttribute(\"dictionary-key\", val);\n\t\t} else if (name === \"key-path\") {\n\t\t\tthis._keyPathJson = val || \"[]\";\n\t\t\tthis._selectorWrapper.setAttribute(\"key-path\", this._keyPathJson);\n\t\t} else if (name === \"locale\") this._locale = val;\n\t}\n\tconnectedCallback() {\n\t\tthis._subscribeToManager();\n\t}\n\tdisconnectedCallback() {\n\t\tthis._teardown();\n\t}\n\t_teardown() {\n\t\tthis._unsubManager?.();\n\t\tthis._unsubEditedContent?.();\n\t\tthis._unsubManager = null;\n\t\tthis._unsubEditedContent = null;\n\t}\n\t_getKeyPath() {\n\t\ttry {\n\t\t\treturn JSON.parse(this._keyPathJson);\n\t\t} catch {\n\t\t\treturn [];\n\t\t}\n\t}\n\t_render() {\n\t\twhile (this._selectorWrapper.firstChild) this._selectorWrapper.removeChild(this._selectorWrapper.firstChild);\n\t\tif (this._editedText !== null) this._selectorWrapper.appendChild(document.createTextNode(this._editedText));\n\t\telse this._selectorWrapper.appendChild(this._slot);\n\t}\n\t_resolveEditedText(manager) {\n\t\tconst keyPath = this._getKeyPath();\n\t\tconst editedValue = manager.getContentValue(this._dictionaryKey, keyPath);\n\t\tif (editedValue === void 0 || editedValue === null) {\n\t\t\tthis._editedText = null;\n\t\t\tthis._render();\n\t\t\treturn;\n\t\t}\n\t\tif (typeof editedValue === \"string\" || typeof editedValue === \"number\") {\n\t\t\tthis._editedText = String(editedValue);\n\t\t\tthis._render();\n\t\t\treturn;\n\t\t}\n\t\tif (typeof editedValue === \"object\") {\n\t\t\tconst locale = this._locale || void 0;\n\t\t\tconst transformed = getContent(editedValue, {\n\t\t\t\tlocale,\n\t\t\t\tdictionaryKey: this._dictionaryKey,\n\t\t\t\tkeyPath\n\t\t\t}, getBasePlugins(locale));\n\t\t\tif (typeof transformed === \"string\" || typeof transformed === \"number\") this._editedText = String(transformed);\n\t\t\telse {\n\t\t\t\tconsole.error(`[intlayer-edited-content] Incorrect edited content format. Expected string. Value: ${JSON.stringify(transformed)}`);\n\t\t\t\tthis._editedText = null;\n\t\t\t}\n\t\t\tthis._render();\n\t\t\treturn;\n\t\t}\n\t\tthis._editedText = null;\n\t\tthis._render();\n\t}\n\t_setupManagerSubscriptions(manager) {\n\t\tthis._resolveEditedText(manager);\n\t\tconst handleChange = () => this._resolveEditedText(manager);\n\t\tmanager.editedContent.addEventListener(\"change\", handleChange);\n\t\tthis._unsubEditedContent = () => manager.editedContent.removeEventListener(\"change\", handleChange);\n\t}\n\t_subscribeToManager() {\n\t\tconst manager = getGlobalEditorManager();\n\t\tif (manager) this._setupManagerSubscriptions(manager);\n\t\tthis._unsubManager = onGlobalEditorManagerChange((m) => {\n\t\t\tthis._unsubEditedContent?.();\n\t\t\tthis._unsubEditedContent = null;\n\t\t\tif (m) this._setupManagerSubscriptions(m);\n\t\t\telse {\n\t\t\t\tthis._editedText = null;\n\t\t\t\tthis._render();\n\t\t\t}\n\t\t});\n\t}\n};\nconst defineIntlayerEditedContent = () => {\n\tif (typeof customElements === \"undefined\") return;\n\tif (!customElements.get(\"intlayer-edited-content\")) customElements.define(\"intlayer-edited-content\", IntlayerEditedContentElement);\n};\n\n//#endregion\nexport { IntlayerEditedContentElement, defineIntlayerEditedContent };\n//# sourceMappingURL=EditedContent.mjs.map"],"mappings":";;;;AAIA,MAAM,eAAe,OAAO,gBAAgB,cAAc,cAAc,MAAM;;;;;;;;;;;;;;;AAe9E,IAAI,+BAA+B,cAAc,aAAa;CAC7D,iBAAiB;CACjB,eAAe;CACf,UAAU;CACV,cAAc;CACd,gBAAgB;CAChB,sBAA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3B,OAAI,EAAG,MAAK,2BAA2B,EAAE;QACpC;AACJ,SAAK,cAAc;AACnB,SAAK,SAAS;;IAEd;;;AAGJ,MAAM,oCAAoC;AACzC,KAAI,OAAO,mBAAmB,YAAa;AAC3C,KAAI,CAAC,eAAe,IAAI,0BAA0B,CAAE,gBAAe,OAAO,2BAA2B,6BAA6B"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { getGlobalEditorManager, onGlobalEditorManagerChange } from "../core/globalManager.mjs";
|
|
2
|
+
import { initEditorClient, stopEditorClient } from "../core/initEditorClient.mjs";
|
|
3
|
+
|
|
4
|
+
//#region ../../packages/@intlayer/editor/dist/esm/components/IntlayerEditorElement.mjs
|
|
5
|
+
const _HTMLElement = typeof HTMLElement !== "undefined" ? HTMLElement : class {};
|
|
6
|
+
/**
|
|
7
|
+
* <intlayer-editor>
|
|
8
|
+
*
|
|
9
|
+
* A framework-agnostic web component that manages the Intlayer editor singleton
|
|
10
|
+
* lifecycle and keeps the current locale in sync with the EditorStateManager.
|
|
11
|
+
*
|
|
12
|
+
* Drop this element once at the root of your application to activate the editor.
|
|
13
|
+
* It renders no UI.
|
|
14
|
+
*
|
|
15
|
+
* @prop {IntlayerConfig} configuration - The Intlayer config (required; set as JS property, not attribute)
|
|
16
|
+
* @prop {string} locale - The active application locale (attribute/property)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Svelte
|
|
20
|
+
* <intlayer-editor .configuration={config} locale={$locale} />
|
|
21
|
+
*
|
|
22
|
+
* // Vue
|
|
23
|
+
* <intlayer-editor :configuration="config" :locale="currentLocale" />
|
|
24
|
+
*/
|
|
25
|
+
var IntlayerEditorElement = class extends _HTMLElement {
|
|
26
|
+
_configuration = void 0;
|
|
27
|
+
_locale = void 0;
|
|
28
|
+
_initialized = false;
|
|
29
|
+
_unsubManager = null;
|
|
30
|
+
static get observedAttributes() {
|
|
31
|
+
return ["locale"];
|
|
32
|
+
}
|
|
33
|
+
get configuration() {
|
|
34
|
+
return this._configuration;
|
|
35
|
+
}
|
|
36
|
+
set configuration(v) {
|
|
37
|
+
this._configuration = v;
|
|
38
|
+
if (!this._initialized) this._init();
|
|
39
|
+
}
|
|
40
|
+
get locale() {
|
|
41
|
+
return this._locale;
|
|
42
|
+
}
|
|
43
|
+
set locale(v) {
|
|
44
|
+
this._locale = v;
|
|
45
|
+
if (v && this._initialized) this._syncLocale(v);
|
|
46
|
+
}
|
|
47
|
+
attributeChangedCallback(name, _oldVal, newVal) {
|
|
48
|
+
if (name === "locale" && newVal !== null) {
|
|
49
|
+
this._locale = newVal;
|
|
50
|
+
if (this._initialized) this._syncLocale(newVal);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
connectedCallback() {
|
|
54
|
+
this._init();
|
|
55
|
+
}
|
|
56
|
+
disconnectedCallback() {
|
|
57
|
+
this._unsubManager?.();
|
|
58
|
+
this._unsubManager = null;
|
|
59
|
+
if (this._initialized) {
|
|
60
|
+
stopEditorClient();
|
|
61
|
+
this._initialized = false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
_init() {
|
|
65
|
+
if (this._initialized) return;
|
|
66
|
+
initEditorClient();
|
|
67
|
+
this._initialized = true;
|
|
68
|
+
if (this._locale) this._syncLocale(this._locale);
|
|
69
|
+
}
|
|
70
|
+
_syncLocale(locale) {
|
|
71
|
+
const manager = getGlobalEditorManager();
|
|
72
|
+
if (manager) manager.currentLocale.set(locale);
|
|
73
|
+
else {
|
|
74
|
+
this._unsubManager?.();
|
|
75
|
+
this._unsubManager = onGlobalEditorManagerChange((m) => {
|
|
76
|
+
if (m) {
|
|
77
|
+
this._unsubManager?.();
|
|
78
|
+
this._unsubManager = null;
|
|
79
|
+
m.currentLocale.set(locale);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
export { IntlayerEditorElement };
|
|
88
|
+
//# sourceMappingURL=IntlayerEditorElement.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntlayerEditorElement.mjs","names":[],"sources":["../../../../../../../../../../packages/@intlayer/editor/dist/esm/components/IntlayerEditorElement.mjs"],"sourcesContent":["import { getGlobalEditorManager, onGlobalEditorManagerChange } from \"../core/globalManager.mjs\";\nimport { initEditorClient, stopEditorClient } from \"../core/initEditorClient.mjs\";\n\n//#region src/components/IntlayerEditorElement.ts\nconst _HTMLElement = typeof HTMLElement !== \"undefined\" ? HTMLElement : class {};\n/**\n* <intlayer-editor>\n*\n* A framework-agnostic web component that manages the Intlayer editor singleton\n* lifecycle and keeps the current locale in sync with the EditorStateManager.\n*\n* Drop this element once at the root of your application to activate the editor.\n* It renders no UI.\n*\n* @prop {IntlayerConfig} configuration - The Intlayer config (required; set as JS property, not attribute)\n* @prop {string} locale - The active application locale (attribute/property)\n*\n* @example\n* // Svelte\n* <intlayer-editor .configuration={config} locale={$locale} />\n*\n* // Vue\n* <intlayer-editor :configuration=\"config\" :locale=\"currentLocale\" />\n*/\nvar IntlayerEditorElement = class extends _HTMLElement {\n\t_configuration = void 0;\n\t_locale = void 0;\n\t_initialized = false;\n\t_unsubManager = null;\n\tstatic get observedAttributes() {\n\t\treturn [\"locale\"];\n\t}\n\tget configuration() {\n\t\treturn this._configuration;\n\t}\n\tset configuration(v) {\n\t\tthis._configuration = v;\n\t\tif (!this._initialized) this._init();\n\t}\n\tget locale() {\n\t\treturn this._locale;\n\t}\n\tset locale(v) {\n\t\tthis._locale = v;\n\t\tif (v && this._initialized) this._syncLocale(v);\n\t}\n\tattributeChangedCallback(name, _oldVal, newVal) {\n\t\tif (name === \"locale\" && newVal !== null) {\n\t\t\tthis._locale = newVal;\n\t\t\tif (this._initialized) this._syncLocale(newVal);\n\t\t}\n\t}\n\tconnectedCallback() {\n\t\tthis._init();\n\t}\n\tdisconnectedCallback() {\n\t\tthis._unsubManager?.();\n\t\tthis._unsubManager = null;\n\t\tif (this._initialized) {\n\t\t\tstopEditorClient();\n\t\t\tthis._initialized = false;\n\t\t}\n\t}\n\t_init() {\n\t\tif (this._initialized) return;\n\t\tinitEditorClient();\n\t\tthis._initialized = true;\n\t\tif (this._locale) this._syncLocale(this._locale);\n\t}\n\t_syncLocale(locale) {\n\t\tconst manager = getGlobalEditorManager();\n\t\tif (manager) manager.currentLocale.set(locale);\n\t\telse {\n\t\t\tthis._unsubManager?.();\n\t\t\tthis._unsubManager = onGlobalEditorManagerChange((m) => {\n\t\t\t\tif (m) {\n\t\t\t\t\tthis._unsubManager?.();\n\t\t\t\t\tthis._unsubManager = null;\n\t\t\t\t\tm.currentLocale.set(locale);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n};\n\n//#endregion\nexport { IntlayerEditorElement };\n//# sourceMappingURL=IntlayerEditorElement.mjs.map"],"mappings":";;;;AAIA,MAAM,eAAe,OAAO,gBAAgB,cAAc,cAAc,MAAM;;;;;;;;;;;;;;;;;;;;AAoB9E,IAAI,wBAAwB,cAAc,aAAa;CACtD,iBAAiB,KAAK;CACtB,UAAU,KAAK;CACf,eAAe;CACf,gBAAgB;CAChB,WAAW,qBAAqB;AAC/B,SAAO,CAAC,SAAS;;CAElB,IAAI,gBAAgB;AACnB,SAAO,KAAK;;CAEb,IAAI,cAAc,GAAG;AACpB,OAAK,iBAAiB;AACtB,MAAI,CAAC,KAAK,aAAc,MAAK,OAAO;;CAErC,IAAI,SAAS;AACZ,SAAO,KAAK;;CAEb,IAAI,OAAO,GAAG;AACb,OAAK,UAAU;AACf,MAAI,KAAK,KAAK,aAAc,MAAK,YAAY,EAAE;;CAEhD,yBAAyB,MAAM,SAAS,QAAQ;AAC/C,MAAI,SAAS,YAAY,WAAW,MAAM;AACzC,QAAK,UAAU;AACf,OAAI,KAAK,aAAc,MAAK,YAAY,OAAO;;;CAGjD,oBAAoB;AACnB,OAAK,OAAO;;CAEb,uBAAuB;AACtB,OAAK,iBAAiB;AACtB,OAAK,gBAAgB;AACrB,MAAI,KAAK,cAAc;AACtB,qBAAkB;AAClB,QAAK,eAAe;;;CAGtB,QAAQ;AACP,MAAI,KAAK,aAAc;AACvB,oBAAkB;AAClB,OAAK,eAAe;AACpB,MAAI,KAAK,QAAS,MAAK,YAAY,KAAK,QAAQ;;CAEjD,YAAY,QAAQ;EACnB,MAAM,UAAU,wBAAwB;AACxC,MAAI,QAAS,SAAQ,cAAc,IAAI,OAAO;OACzC;AACJ,QAAK,iBAAiB;AACtB,QAAK,gBAAgB,6BAA6B,MAAM;AACvD,QAAI,GAAG;AACN,UAAK,iBAAiB;AACtB,UAAK,gBAAgB;AACrB,OAAE,cAAc,IAAI,OAAO;;KAE3B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IntlayerContentSelectorElement } from "./ContentSelector.mjs";
|
|
2
|
+
import { defineIntlayerContentSelectorWrapper } from "./ContentSelectorWrapper.mjs";
|
|
3
|
+
import { defineIntlayerEditedContent } from "./EditedContent.mjs";
|
|
4
|
+
import { IntlayerEditorElement } from "./IntlayerEditorElement.mjs";
|
|
5
|
+
|
|
6
|
+
//#region ../../packages/@intlayer/editor/dist/esm/components/defineIntlayerElements.mjs
|
|
7
|
+
const defineIntlayerEditorElement = () => {
|
|
8
|
+
if (typeof customElements === "undefined") return;
|
|
9
|
+
if (!customElements.get("intlayer-editor")) customElements.define("intlayer-editor", IntlayerEditorElement);
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Register all Intlayer custom elements.
|
|
13
|
+
* Call this once at application startup (inside IntlayerEditorProvider or similar).
|
|
14
|
+
* Safe to call multiple times — only registers elements that are not yet defined.
|
|
15
|
+
*/
|
|
16
|
+
const defineIntlayerElements = () => {
|
|
17
|
+
if (typeof customElements === "undefined") return;
|
|
18
|
+
if (!customElements.get("intlayer-content-selector")) customElements.define("intlayer-content-selector", IntlayerContentSelectorElement);
|
|
19
|
+
defineIntlayerContentSelectorWrapper();
|
|
20
|
+
defineIntlayerEditedContent();
|
|
21
|
+
defineIntlayerEditorElement();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { defineIntlayerEditorElement, defineIntlayerElements };
|
|
26
|
+
//# sourceMappingURL=defineIntlayerElements.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineIntlayerElements.mjs","names":[],"sources":["../../../../../../../../../../packages/@intlayer/editor/dist/esm/components/defineIntlayerElements.mjs"],"sourcesContent":["import { IntlayerContentSelectorElement } from \"./ContentSelector.mjs\";\nimport { defineIntlayerContentSelectorWrapper } from \"./ContentSelectorWrapper.mjs\";\nimport { defineIntlayerEditedContent } from \"./EditedContent.mjs\";\nimport { IntlayerEditorElement } from \"./IntlayerEditorElement.mjs\";\n\n//#region src/components/defineIntlayerElements.ts\nconst defineIntlayerEditorElement = () => {\n\tif (typeof customElements === \"undefined\") return;\n\tif (!customElements.get(\"intlayer-editor\")) customElements.define(\"intlayer-editor\", IntlayerEditorElement);\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*/\nconst defineIntlayerElements = () => {\n\tif (typeof customElements === \"undefined\") return;\n\tif (!customElements.get(\"intlayer-content-selector\")) customElements.define(\"intlayer-content-selector\", IntlayerContentSelectorElement);\n\tdefineIntlayerContentSelectorWrapper();\n\tdefineIntlayerEditedContent();\n\tdefineIntlayerEditorElement();\n};\n\n//#endregion\nexport { defineIntlayerEditorElement, defineIntlayerElements };\n//# sourceMappingURL=defineIntlayerElements.mjs.map"],"mappings":";;;;;;AAMA,MAAM,oCAAoC;AACzC,KAAI,OAAO,mBAAmB,YAAa;AAC3C,KAAI,CAAC,eAAe,IAAI,kBAAkB,CAAE,gBAAe,OAAO,mBAAmB,sBAAsB;;;;;;;AAO5G,MAAM,+BAA+B;AACpC,KAAI,OAAO,mBAAmB,YAAa;AAC3C,KAAI,CAAC,eAAe,IAAI,4BAA4B,CAAE,gBAAe,OAAO,6BAA6B,+BAA+B;AACxI,uCAAsC;AACtC,8BAA6B;AAC7B,8BAA6B"}
|