svelte-intlayer 8.3.4 → 8.4.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/client/setupIntlayer.svelte.d.ts +2 -2
- package/dist/client/setupIntlayer.svelte.js +11 -9
- package/dist/editor/ContentSelector.svelte +7 -119
- package/dist/editor/ContentSelector.svelte.d.ts +3 -7
- package/dist/editor/useEditor.d.ts +9 -0
- package/dist/editor/useEditor.js +28 -16
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/markdown/MarkdownMetadataWithSelector.svelte +3 -3
- package/dist/markdown/MarkdownWithSelector.svelte +3 -3
- package/dist/plugins.js +2 -2
- package/dist/renderIntlayerNode.test.js +1 -1
- package/package.json +6 -6
- package/dist/editor/ContentSelectorWrapper.svelte +0 -61
- package/dist/editor/ContentSelectorWrapper.svelte.d.ts +0 -31
- package/dist/editor/communicator.d.ts +0 -7
- package/dist/editor/communicator.js +0 -59
- package/dist/editor/dictionariesRecord.d.ts +0 -5
- package/dist/editor/dictionariesRecord.js +0 -11
- package/dist/editor/editorEnabled.d.ts +0 -5
- package/dist/editor/editorEnabled.js +0 -11
- package/dist/editor/focusDictionary.d.ts +0 -10
- package/dist/editor/focusDictionary.js +0 -15
- package/dist/editor/index.d.ts +0 -10
- package/dist/editor/index.js +0 -10
- package/dist/editor/useCrossFrameMessageListener.d.ts +0 -2
- package/dist/editor/useCrossFrameMessageListener.js +0 -17
- package/dist/editor/useCrossFrameState.d.ts +0 -7
- package/dist/editor/useCrossFrameState.js +0 -30
- package/dist/editor/useIframeClickInterceptor.d.ts +0 -2
- package/dist/editor/useIframeClickInterceptor.js +0 -8
|
@@ -16,7 +16,7 @@ import type { LocalesValues } from '@intlayer/types/module_augmentation';
|
|
|
16
16
|
* </script>
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
|
-
export declare const setupIntlayer: (initialLocale
|
|
20
|
-
readonly locale:
|
|
19
|
+
export declare const setupIntlayer: (initialLocale?: LocalesValues) => {
|
|
20
|
+
readonly locale: "id" | "cy" | "hr" | "th" | "tr" | "tt" | "mi" | "mn" | "ms" | "af" | "af-ZA" | "ar" | "ar-AE" | "ar-BH" | "ar-DZ" | "ar-EG" | "ar-IQ" | "ar-JO" | "ar-KW" | "ar-LB" | "ar-LY" | "ar-MA" | "ar-OM" | "ar-QA" | "ar-SA" | "ar-SY" | "ar-TN" | "ar-YE" | "az" | "az-AZ" | "be" | "be-BY" | "bg" | "bg-BG" | "bs" | "bs-BA" | "ca" | "ca-ES" | "cs" | "cs-CZ" | "cy-GB" | "da" | "da-DK" | "de" | "de-AT" | "de-CH" | "de-DE" | "de-LI" | "de-LU" | "dv" | "dv-MV" | "el" | "el-GR" | "en" | "en-AU" | "en-BZ" | "en-CA" | "en-CB" | "en-GB" | "en-IE" | "en-JM" | "en-NZ" | "en-PH" | "en-TT" | "en-US" | "en-ZA" | "en-ZW" | "eo" | "es" | "es-AR" | "es-BO" | "es-CL" | "es-CO" | "es-CR" | "es-DO" | "es-EC" | "es-ES" | "es-GT" | "es-HN" | "es-MX" | "es-NI" | "es-PA" | "es-PE" | "es-PR" | "es-PY" | "es-SV" | "es-UY" | "es-VE" | "et" | "et-EE" | "eu" | "eu-ES" | "fa" | "fa-IR" | "fi" | "fi-FI" | "fo" | "fo-FO" | "fr" | "fr-BE" | "fr-CA" | "fr-CH" | "fr-FR" | "fr-LU" | "fr-MC" | "ga" | "ga-IE" | "gd" | "gd-GB" | "gl" | "gl-ES" | "gu" | "gu-IN" | "he" | "he-IL" | "hi" | "hi-IN" | "hr-BA" | "hr-HR" | "hu" | "hu-HU" | "hy" | "hy-AM" | "id-ID" | "is" | "is-IS" | "it" | "it-CH" | "it-IT" | "ja" | "ja-JP" | "ka" | "ka-GE" | "kk" | "kk-KZ" | "kn" | "kn-IN" | "ko" | "ko-KR" | "kok" | "kok-IN" | "ku" | "ku-TR" | "ky" | "ky-KG" | "lt" | "lt-LT" | "lv" | "lv-LV" | "mi-NZ" | "mk" | "mk-MK" | "mn-MN" | "mr" | "mr-IN" | "ms-BN" | "ms-MY" | "mt" | "mt-MT" | "ml" | "ml-IN" | "no" | "nb" | "nb-NO" | "nl" | "nl-BE" | "nl-NL" | "nn" | "nn-NO" | "ns" | "ns-ZA" | "pa" | "pa-IN" | "pl" | "pl-PL" | "ps" | "ps-AR" | "pt" | "pt-BR" | "pt-PT" | "qu" | "qu-BO" | "qu-EC" | "qu-PE" | "ro" | "ro-RO" | "ro-MD" | "rm" | "rm-CH" | "ru" | "ru-RU" | "ru-MD" | "sa" | "sa-IN" | "se" | "se-FI" | "se-NO" | "se-SE" | "hsb" | "hsb-DE" | "dsb" | "dsb-DE" | "sk" | "sk-SK" | "sl" | "sl-SI" | "sq" | "sq-AL" | "sr" | "sr-BA" | "sr-SP" | "sv" | "sv-FI" | "sv-SE" | "sw" | "sw-KE" | "syr" | "syr-SY" | "ta" | "ta-IN" | "te" | "te-IN" | "th-TH" | "tl" | "tl-PH" | "tn" | "tn-ZA" | "tr-TR" | "tt-RU" | "ts" | "uk" | "uk-UA" | "ur" | "ur-PK" | "uz" | "uz-UZ" | "vi" | "vi-VN" | "ve" | "ve-ZA" | "xh" | "xh-ZA" | "zh" | "zh-Hans" | "zh-CN" | "zh-HK" | "zh-MO" | "zh-SG" | "zh-Hant" | "zu" | "zu-ZA" | "bn" | "bn-BD" | "bn-IN" | "bn-MM" | "my" | "my-MM" | "km" | "km-KH" | "lo" | "lo-LA" | "yo" | "yo-NG" | "yi" | "yi-001" | "am" | "am-ET" | "ne" | "ne-NP" | "si" | "si-LK" | "sr-Cyrl" | "sr-RS" | "en-IN" | "en-SG" | "en-HK" | "en-NG" | "en-PK" | "en-MY" | "en-BW" | "en-KE" | "en-TZ" | "en-GH" | "en-UG" | "es-CU" | "es-US" | "pt-GW" | "pt-MZ" | "pt-ST" | "pt-CV" | "pt-TL" | "pt-MO" | "zh-TW" | "ar-MR" | "ar-PS" | "ar-SD" | "ar-DJ" | "ar-SO" | "ar-TD" | "ar-KM" | "mg-MG" | (string & {});
|
|
21
21
|
setLocale: (newLocale: LocalesValues) => void;
|
|
22
22
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import configuration from '@intlayer/config/built';
|
|
1
2
|
import { useEditor } from '../editor/useEditor';
|
|
2
|
-
// Assuming setIntlayerContext exports a specific key or symbol
|
|
3
3
|
import { setIntlayerContext } from './intlayerContext';
|
|
4
|
+
import { intlayerStore } from './intlayerStore';
|
|
4
5
|
/**
|
|
5
6
|
* Setups Intlayer in your Svelte application.
|
|
6
7
|
*
|
|
@@ -19,24 +20,25 @@ import { setIntlayerContext } from './intlayerContext';
|
|
|
19
20
|
* ```
|
|
20
21
|
*/
|
|
21
22
|
export const setupIntlayer = (initialLocale) => {
|
|
22
|
-
// 1. Initialize your side effects
|
|
23
|
-
// Note: If these need to run only in the browser, wrap them in $effect or onMount
|
|
24
|
-
// inside your side-effect logic if they aren't already safe.
|
|
25
23
|
useEditor();
|
|
26
|
-
//
|
|
24
|
+
// Create Reactive State (Svelte 5)
|
|
27
25
|
// We make the locale a "rune" so updates propagate
|
|
28
26
|
let locale = $state(initialLocale);
|
|
29
|
-
//
|
|
27
|
+
// Keep intlayerStore in sync so useEditor can subscribe to it
|
|
28
|
+
if (initialLocale) {
|
|
29
|
+
intlayerStore.setLocale(initialLocale);
|
|
30
|
+
}
|
|
31
|
+
// Define the Context Object
|
|
30
32
|
const contextValue = {
|
|
31
33
|
get locale() {
|
|
32
|
-
return locale;
|
|
34
|
+
return locale ?? configuration.internationalization.defaultLocale;
|
|
33
35
|
},
|
|
34
36
|
setLocale: (newLocale) => {
|
|
35
37
|
locale = newLocale;
|
|
38
|
+
intlayerStore.setLocale(newLocale);
|
|
36
39
|
},
|
|
37
40
|
};
|
|
38
|
-
//
|
|
39
|
-
// setIntlayerContext internal logic usually wraps setContext(KEY, value)
|
|
41
|
+
// Set the Context
|
|
40
42
|
setIntlayerContext(contextValue);
|
|
41
43
|
// Return the state if you need it immediately in the layout
|
|
42
44
|
return contextValue;
|
|
@@ -1,125 +1,13 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import type { NodeProps } from '@intlayer/core/interpreter';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export let onClickOutside: (() => void) | undefined = undefined;
|
|
7
|
-
// biome-ignore lint/style/useConst: Svelte props need let
|
|
8
|
-
export let pressDuration = 250;
|
|
9
|
-
// biome-ignore lint/style/useConst: Svelte props need let
|
|
10
|
-
export let isSelecting = false;
|
|
11
|
-
|
|
12
|
-
// Event props
|
|
13
|
-
// biome-ignore lint/style/useConst: Svelte props need let
|
|
14
|
-
export let onPress: (() => void) | undefined = undefined;
|
|
15
|
-
// biome-ignore lint/style/useConst: Svelte props need let
|
|
16
|
-
export let onUnhover: (() => void) | undefined = undefined;
|
|
17
|
-
// biome-ignore lint/style/useConst: Svelte props need let
|
|
18
|
-
export let onHover: (() => void) | undefined = undefined;
|
|
19
|
-
// biome-ignore lint/style/useConst: Svelte props need let
|
|
20
|
-
export let onClick: ((event: MouseEvent) => void) | undefined = undefined;
|
|
21
|
-
|
|
22
|
-
// biome-ignore lint/style/useConst: don't transform to const
|
|
23
|
-
let containerRef: HTMLElement | null = null;
|
|
24
|
-
let isHovered = false;
|
|
25
|
-
let isSelectingState = isSelecting;
|
|
26
|
-
let pressTimerRef: ReturnType<typeof setTimeout> | null = null;
|
|
27
|
-
|
|
28
|
-
$: currentIsSelecting = isSelecting || isSelectingState;
|
|
29
|
-
|
|
30
|
-
const handleOnLongPress = () => {
|
|
31
|
-
isSelectingState = true;
|
|
32
|
-
onPress?.();
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const startPressTimer = () => {
|
|
36
|
-
pressTimerRef = setTimeout(() => {
|
|
37
|
-
handleOnLongPress();
|
|
38
|
-
}, pressDuration);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const clearPressTimer = () => {
|
|
42
|
-
if (pressTimerRef) {
|
|
43
|
-
clearTimeout(pressTimerRef);
|
|
44
|
-
pressTimerRef = null;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const handleMouseDown = () => {
|
|
49
|
-
clearPressTimer();
|
|
50
|
-
startPressTimer();
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
const handleMouseUp = () => {
|
|
54
|
-
if (isHovered) {
|
|
55
|
-
isHovered = false;
|
|
56
|
-
onUnhover?.();
|
|
57
|
-
}
|
|
58
|
-
clearPressTimer();
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const handleMouseLeave = () => {
|
|
62
|
-
if (isHovered) {
|
|
63
|
-
isHovered = false;
|
|
64
|
-
onUnhover?.();
|
|
65
|
-
}
|
|
66
|
-
clearPressTimer();
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const handleClickOutside = (event: MouseEvent) => {
|
|
70
|
-
if (containerRef && !containerRef.contains(event.target as Node)) {
|
|
71
|
-
isSelectingState = false;
|
|
72
|
-
if (onClickOutside) onClickOutside();
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const handleClick = (e: MouseEvent) => {
|
|
77
|
-
if (currentIsSelecting) {
|
|
78
|
-
e.preventDefault();
|
|
79
|
-
e.stopPropagation();
|
|
80
|
-
} else {
|
|
81
|
-
onClick?.(e);
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
onMount(() => {
|
|
86
|
-
document.addEventListener('mousedown', handleClickOutside);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
onDestroy(() => {
|
|
90
|
-
if (typeof document !== 'undefined') {
|
|
91
|
-
document.removeEventListener('mousedown', handleClickOutside);
|
|
92
|
-
}
|
|
93
|
-
clearPressTimer();
|
|
94
|
-
});
|
|
4
|
+
export let dictionaryKey: NodeProps['dictionaryKey'];
|
|
5
|
+
export let keyPath: NodeProps['keyPath'];
|
|
95
6
|
</script>
|
|
96
7
|
|
|
97
|
-
<
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
tabindex="0"
|
|
101
|
-
onclick={handleClick}
|
|
102
|
-
onkeydown={() => {}}
|
|
103
|
-
onmousedown={handleMouseDown}
|
|
104
|
-
onmouseup={handleMouseUp}
|
|
105
|
-
onmouseleave={handleMouseLeave}
|
|
106
|
-
ontouchstart={handleMouseDown}
|
|
107
|
-
ontouchend={handleMouseUp}
|
|
108
|
-
ontouchcancel={handleMouseLeave}
|
|
109
|
-
onmouseenter={() => {
|
|
110
|
-
isHovered = true;
|
|
111
|
-
onHover?.();
|
|
112
|
-
}}
|
|
113
|
-
style={`display: inline-block;
|
|
114
|
-
cursor: pointer;
|
|
115
|
-
user-select: none;
|
|
116
|
-
border-radius: 0.375rem;
|
|
117
|
-
outline-width: 2px;
|
|
118
|
-
outline-offset: 4px;
|
|
119
|
-
outline-style: solid;
|
|
120
|
-
outline-color: ${currentIsSelecting || isHovered ? 'inherit' : 'transparent'};
|
|
121
|
-
transition: all 100ms 50ms ease-in-out;
|
|
122
|
-
`}
|
|
8
|
+
<intlayer-content-selector-wrapper
|
|
9
|
+
key-path={JSON.stringify(keyPath)}
|
|
10
|
+
dictionary-key={dictionaryKey}
|
|
123
11
|
>
|
|
124
12
|
<slot />
|
|
125
|
-
</
|
|
13
|
+
</intlayer-content-selector-wrapper>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { NodeProps } from '@intlayer/core/interpreter';
|
|
1
2
|
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
2
3
|
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
4
|
$$bindings?: Bindings;
|
|
@@ -17,13 +18,8 @@ type $$__sveltets_2_PropsWithChildren<Props, Slots> = Props & (Slots extends {
|
|
|
17
18
|
children?: any;
|
|
18
19
|
} : {});
|
|
19
20
|
declare const ContentSelector: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
isSelecting?: boolean;
|
|
23
|
-
onPress?: (() => void) | undefined;
|
|
24
|
-
onUnhover?: (() => void) | undefined;
|
|
25
|
-
onHover?: (() => void) | undefined;
|
|
26
|
-
onClick?: ((event: MouseEvent) => void) | undefined;
|
|
21
|
+
dictionaryKey: NodeProps["dictionaryKey"];
|
|
22
|
+
keyPath: NodeProps["keyPath"];
|
|
27
23
|
}, {
|
|
28
24
|
default: {};
|
|
29
25
|
}>, {
|
|
@@ -1 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initialises the Intlayer editor client singleton when the editor is enabled.
|
|
3
|
+
* Syncs the current locale from intlayerStore into the editor manager so the
|
|
4
|
+
* editor always knows which locale the app is displaying.
|
|
5
|
+
*
|
|
6
|
+
* setupIntlayer keeps intlayerStore in sync whenever setLocale is called, so
|
|
7
|
+
* subscribing to the store gives us reactive locale updates without needing
|
|
8
|
+
* direct access to the Svelte 5 rune state.
|
|
9
|
+
*/
|
|
1
10
|
export declare const useEditor: () => void;
|
package/dist/editor/useEditor.js
CHANGED
|
@@ -1,22 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isEnabled } from '@intlayer/editor/isEnabled';
|
|
2
2
|
import { onDestroy, onMount } from 'svelte';
|
|
3
|
-
import {
|
|
3
|
+
import { intlayerStore } from '../client/intlayerStore';
|
|
4
|
+
/**
|
|
5
|
+
* Initialises the Intlayer editor client singleton when the editor is enabled.
|
|
6
|
+
* Syncs the current locale from intlayerStore into the editor manager so the
|
|
7
|
+
* editor always knows which locale the app is displaying.
|
|
8
|
+
*
|
|
9
|
+
* setupIntlayer keeps intlayerStore in sync whenever setLocale is called, so
|
|
10
|
+
* subscribing to the store gives us reactive locale updates without needing
|
|
11
|
+
* direct access to the Svelte 5 rune state.
|
|
12
|
+
*/
|
|
4
13
|
export const useEditor = () => {
|
|
5
|
-
if (
|
|
14
|
+
if (!isEnabled)
|
|
6
15
|
return;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
16
|
+
let unsubscribeLocale = null;
|
|
17
|
+
onMount(() => {
|
|
18
|
+
import('@intlayer/editor').then(({ initEditorClient }) => {
|
|
19
|
+
const manager = initEditorClient();
|
|
20
|
+
// Subscribe immediately — Svelte stores call the subscriber with the
|
|
21
|
+
// current value on subscription, so the initial locale is set right away.
|
|
22
|
+
unsubscribeLocale = intlayerStore.subscribe(({ locale }) => {
|
|
23
|
+
if (locale)
|
|
24
|
+
manager.currentLocale.set(locale);
|
|
25
|
+
});
|
|
12
26
|
});
|
|
13
|
-
|
|
14
|
-
|
|
27
|
+
});
|
|
28
|
+
onDestroy(() => {
|
|
29
|
+
unsubscribeLocale?.();
|
|
30
|
+
import('@intlayer/editor').then(({ stopEditorClient }) => {
|
|
31
|
+
stopEditorClient();
|
|
15
32
|
});
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
// Outside component context - start immediately
|
|
19
|
-
defineIntlayerElements();
|
|
20
|
-
manager.start();
|
|
21
|
-
}
|
|
33
|
+
});
|
|
22
34
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ export * from './getIntlayer';
|
|
|
10
10
|
export * from './html';
|
|
11
11
|
export * from './markdown';
|
|
12
12
|
export * from './plugins';
|
|
13
|
-
import { useEditor } from './editor';
|
|
14
13
|
import { setHTMLContext } from './html';
|
|
15
14
|
import { setMarkdownContext } from './markdown';
|
|
16
|
-
export {
|
|
15
|
+
export { setHTMLContext as setIntlayerHTML, setMarkdownContext as setIntlayerMarkdown, };
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,6 @@ export * from './getIntlayer';
|
|
|
4
4
|
export * from './html';
|
|
5
5
|
export * from './markdown';
|
|
6
6
|
export * from './plugins';
|
|
7
|
-
import { useEditor } from './editor';
|
|
8
7
|
import { setHTMLContext } from './html';
|
|
9
8
|
import { setMarkdownContext } from './markdown';
|
|
10
|
-
export {
|
|
9
|
+
export { setHTMLContext as setIntlayerHTML, setMarkdownContext as setIntlayerMarkdown, };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { KeyPath } from '@intlayer/types/keyPath';
|
|
3
|
-
import
|
|
3
|
+
import ContentSelector from '../editor/ContentSelector.svelte';
|
|
4
4
|
import MarkdownMetadataRenderer from './MarkdownMetadataRenderer.svelte';
|
|
5
5
|
|
|
6
6
|
export let dictionaryKey: string;
|
|
@@ -9,13 +9,13 @@ export let value: string;
|
|
|
9
9
|
export let metadataKeyPath: KeyPath[];
|
|
10
10
|
</script>
|
|
11
11
|
|
|
12
|
-
<
|
|
12
|
+
<ContentSelector {dictionaryKey} {keyPath}>
|
|
13
13
|
<MarkdownMetadataRenderer
|
|
14
14
|
{dictionaryKey}
|
|
15
15
|
{keyPath}
|
|
16
16
|
{value}
|
|
17
17
|
{metadataKeyPath}
|
|
18
18
|
/>
|
|
19
|
-
</
|
|
19
|
+
</ContentSelector>
|
|
20
20
|
|
|
21
21
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { KeyPath } from '@intlayer/types/keyPath';
|
|
3
|
-
import
|
|
3
|
+
import ContentSelector from '../editor/ContentSelector.svelte';
|
|
4
4
|
import MarkdownRenderer from './MarkdownRenderer.svelte';
|
|
5
5
|
|
|
6
6
|
export let dictionaryKey: string;
|
|
@@ -10,8 +10,8 @@ export let value: string;
|
|
|
10
10
|
$: overrides = { ...$$restProps };
|
|
11
11
|
</script>
|
|
12
12
|
|
|
13
|
-
<
|
|
13
|
+
<ContentSelector {dictionaryKey} {keyPath}>
|
|
14
14
|
<MarkdownRenderer {value} {overrides} />
|
|
15
|
-
</
|
|
15
|
+
</ContentSelector>
|
|
16
16
|
|
|
17
17
|
|
package/dist/plugins.js
CHANGED
|
@@ -3,7 +3,7 @@ import { conditionPlugin, enumerationPlugin, filePlugin, genderPlugin, getHTML,
|
|
|
3
3
|
import { compile, getMarkdownMetadata } from '@intlayer/core/markdown';
|
|
4
4
|
import { HTML_TAGS, } from '@intlayer/core/transpiler';
|
|
5
5
|
import { NodeType } from '@intlayer/types/nodeType';
|
|
6
|
-
import {
|
|
6
|
+
import { default as ContentSelector } from './editor/ContentSelector.svelte';
|
|
7
7
|
import MarkdownMetadataWithSelector from './markdown/MarkdownMetadataWithSelector.svelte';
|
|
8
8
|
import MarkdownWithSelector from './markdown/MarkdownWithSelector.svelte';
|
|
9
9
|
import { svelteHtmlRuntime } from './markdown/runtime';
|
|
@@ -20,7 +20,7 @@ export const intlayerNodePlugins = {
|
|
|
20
20
|
transform: (node, { children, ...rest }) => renderIntlayerNode({
|
|
21
21
|
value: children ?? node,
|
|
22
22
|
component: configuration?.editor.enabled
|
|
23
|
-
?
|
|
23
|
+
? ContentSelector
|
|
24
24
|
: (children ?? node),
|
|
25
25
|
props: rest,
|
|
26
26
|
}),
|
|
@@ -10,7 +10,7 @@ vi.mock('./IntlayerNodeWrapper.svelte', () => ({
|
|
|
10
10
|
}));
|
|
11
11
|
// Mock the editor module (exports Svelte components).
|
|
12
12
|
vi.mock('./editor', () => ({
|
|
13
|
-
|
|
13
|
+
ContentSelector: () => null,
|
|
14
14
|
}));
|
|
15
15
|
// Mock Svelte markdown components.
|
|
16
16
|
vi.mock('./markdown/MarkdownMetadataWithSelector.svelte', () => ({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-intlayer",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.0",
|
|
4
4
|
"description": "Easily internationalize i18n your Svelte applications with type-safe multilingual content management.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"intlayer",
|
|
@@ -72,11 +72,11 @@
|
|
|
72
72
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@intlayer/api": "8.
|
|
76
|
-
"@intlayer/config": "8.
|
|
77
|
-
"@intlayer/core": "8.
|
|
78
|
-
"@intlayer/editor": "8.
|
|
79
|
-
"@intlayer/types": "8.
|
|
75
|
+
"@intlayer/api": "8.4.0",
|
|
76
|
+
"@intlayer/config": "8.4.0",
|
|
77
|
+
"@intlayer/core": "8.4.0",
|
|
78
|
+
"@intlayer/editor": "8.4.0",
|
|
79
|
+
"@intlayer/types": "8.4.0"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@sveltejs/adapter-auto": "7.0.1",
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import type { NodeProps } from '@intlayer/core/interpreter';
|
|
3
|
-
import { isSameKeyPath } from '@intlayer/core/utils';
|
|
4
|
-
import { defineIntlayerElements, MessageKey } from '@intlayer/editor';
|
|
5
|
-
import { NodeType } from '@intlayer/types/nodeType';
|
|
6
|
-
import { onMount } from 'svelte';
|
|
7
|
-
import { getEditorStateManager } from './communicator';
|
|
8
|
-
import { useEditorEnabled } from './editorEnabled';
|
|
9
|
-
import { useFocusDictionary } from './focusDictionary';
|
|
10
|
-
import { useEditor } from './useEditor';
|
|
11
|
-
|
|
12
|
-
export let dictionaryKey: NodeProps['dictionaryKey'];
|
|
13
|
-
export let keyPath: NodeProps['keyPath'];
|
|
14
|
-
|
|
15
|
-
const manager = getEditorStateManager();
|
|
16
|
-
const { focusedContent, setFocusedContent } = useFocusDictionary();
|
|
17
|
-
const { enabled } = useEditorEnabled();
|
|
18
|
-
|
|
19
|
-
useEditor();
|
|
20
|
-
|
|
21
|
-
onMount(() => defineIntlayerElements());
|
|
22
|
-
|
|
23
|
-
$: filteredKeyPath = keyPath.filter((key) => key.type !== NodeType.Translation);
|
|
24
|
-
|
|
25
|
-
$: isSelected =
|
|
26
|
-
$focusedContent?.dictionaryKey === dictionaryKey &&
|
|
27
|
-
($focusedContent?.keyPath?.length ?? 0) > 0 &&
|
|
28
|
-
isSameKeyPath($focusedContent?.keyPath ?? [], filteredKeyPath);
|
|
29
|
-
|
|
30
|
-
const handlePress = () => {
|
|
31
|
-
setFocusedContent({ dictionaryKey, keyPath: filteredKeyPath });
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const handleHover = () => {
|
|
35
|
-
manager.messenger.send(
|
|
36
|
-
`${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,
|
|
37
|
-
{ dictionaryKey, keyPath: filteredKeyPath }
|
|
38
|
-
);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const handleUnhover = () => {
|
|
42
|
-
manager.messenger.send(
|
|
43
|
-
`${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,
|
|
44
|
-
null
|
|
45
|
-
);
|
|
46
|
-
};
|
|
47
|
-
</script>
|
|
48
|
-
|
|
49
|
-
{#if $enabled}
|
|
50
|
-
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
51
|
-
<intlayer-content-selector
|
|
52
|
-
is-selecting={isSelected || undefined}
|
|
53
|
-
on:intlayer:press={handlePress}
|
|
54
|
-
on:intlayer:hover={handleHover}
|
|
55
|
-
on:intlayer:unhover={handleUnhover}
|
|
56
|
-
>
|
|
57
|
-
<slot />
|
|
58
|
-
</intlayer-content-selector>
|
|
59
|
-
{:else}
|
|
60
|
-
<slot />
|
|
61
|
-
{/if}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { NodeProps } from '@intlayer/core/interpreter';
|
|
2
|
-
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
3
|
-
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
|
-
$$bindings?: Bindings;
|
|
5
|
-
} & Exports;
|
|
6
|
-
(internal: unknown, props: Props & {
|
|
7
|
-
$$events?: Events;
|
|
8
|
-
$$slots?: Slots;
|
|
9
|
-
}): Exports & {
|
|
10
|
-
$set?: any;
|
|
11
|
-
$on?: any;
|
|
12
|
-
};
|
|
13
|
-
z_$$bindings?: Bindings;
|
|
14
|
-
}
|
|
15
|
-
type $$__sveltets_2_PropsWithChildren<Props, Slots> = Props & (Slots extends {
|
|
16
|
-
default: any;
|
|
17
|
-
} ? Props extends Record<string, never> ? any : {
|
|
18
|
-
children?: any;
|
|
19
|
-
} : {});
|
|
20
|
-
declare const ContentSelectorWrapper: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<{
|
|
21
|
-
dictionaryKey: NodeProps["dictionaryKey"];
|
|
22
|
-
keyPath: NodeProps["keyPath"];
|
|
23
|
-
}, {
|
|
24
|
-
default: {};
|
|
25
|
-
}>, {
|
|
26
|
-
[evt: string]: CustomEvent<any>;
|
|
27
|
-
}, {
|
|
28
|
-
default: {};
|
|
29
|
-
}, {}, string>;
|
|
30
|
-
type ContentSelectorWrapper = InstanceType<typeof ContentSelectorWrapper>;
|
|
31
|
-
export default ContentSelectorWrapper;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { EditorStateManager } from '@intlayer/editor';
|
|
2
|
-
export declare const createEditorStateManager: () => EditorStateManager;
|
|
3
|
-
export declare const getEditorStateManager: () => EditorStateManager;
|
|
4
|
-
export declare const useCommunicator: () => {
|
|
5
|
-
postMessage: (data: any) => void;
|
|
6
|
-
senderId: string;
|
|
7
|
-
};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import configuration from '@intlayer/config/built';
|
|
2
|
-
import { EditorStateManager } from '@intlayer/editor';
|
|
3
|
-
import { getContext, setContext } from 'svelte';
|
|
4
|
-
const { editor } = configuration ?? {};
|
|
5
|
-
const buildDefaultMessengerConfig = () => ({
|
|
6
|
-
allowedOrigins: [
|
|
7
|
-
editor?.applicationURL,
|
|
8
|
-
editor?.editorURL,
|
|
9
|
-
editor?.cmsURL,
|
|
10
|
-
].filter(Boolean),
|
|
11
|
-
postMessageFn: (payload, origin) => {
|
|
12
|
-
if (typeof window === 'undefined')
|
|
13
|
-
return;
|
|
14
|
-
const isInIframe = window.self !== window.top;
|
|
15
|
-
if (!isInIframe)
|
|
16
|
-
return;
|
|
17
|
-
window.parent?.postMessage(payload, origin);
|
|
18
|
-
window.postMessage(payload, origin);
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
const MANAGER_KEY = Symbol('INTLAYER_EDITOR_STATE_MANAGER');
|
|
22
|
-
let globalManager = null;
|
|
23
|
-
export const createEditorStateManager = () => {
|
|
24
|
-
const manager = new EditorStateManager({
|
|
25
|
-
mode: 'client',
|
|
26
|
-
messenger: buildDefaultMessengerConfig(),
|
|
27
|
-
configuration,
|
|
28
|
-
});
|
|
29
|
-
try {
|
|
30
|
-
setContext(MANAGER_KEY, manager);
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
// Outside component context
|
|
34
|
-
}
|
|
35
|
-
globalManager = manager;
|
|
36
|
-
return manager;
|
|
37
|
-
};
|
|
38
|
-
export const getEditorStateManager = () => {
|
|
39
|
-
try {
|
|
40
|
-
const ctx = getContext(MANAGER_KEY);
|
|
41
|
-
if (ctx)
|
|
42
|
-
return ctx;
|
|
43
|
-
}
|
|
44
|
-
catch {
|
|
45
|
-
// Outside component context
|
|
46
|
-
}
|
|
47
|
-
if (!globalManager) {
|
|
48
|
-
return createEditorStateManager();
|
|
49
|
-
}
|
|
50
|
-
return globalManager;
|
|
51
|
-
};
|
|
52
|
-
// Backward-compat alias
|
|
53
|
-
export const useCommunicator = () => {
|
|
54
|
-
const manager = getEditorStateManager();
|
|
55
|
-
return {
|
|
56
|
-
postMessage: (data) => manager.messenger.send(data.type, data.data),
|
|
57
|
-
senderId: manager.messenger.senderId,
|
|
58
|
-
};
|
|
59
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { readable } from 'svelte/store';
|
|
2
|
-
import { getEditorStateManager } from './communicator';
|
|
3
|
-
export const useDictionariesRecord = () => {
|
|
4
|
-
const manager = getEditorStateManager();
|
|
5
|
-
const dictionariesRecord = readable(manager.localeDictionaries.value ?? {}, (set) => {
|
|
6
|
-
const handler = (e) => set(e.detail ?? {});
|
|
7
|
-
manager.localeDictionaries.addEventListener('change', handler);
|
|
8
|
-
return () => manager.localeDictionaries.removeEventListener('change', handler);
|
|
9
|
-
});
|
|
10
|
-
return { dictionariesRecord };
|
|
11
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { readable } from 'svelte/store';
|
|
2
|
-
import { getEditorStateManager } from './communicator';
|
|
3
|
-
export const useEditorEnabled = () => {
|
|
4
|
-
const manager = getEditorStateManager();
|
|
5
|
-
const enabled = readable(manager.editorEnabled.value ?? false, (set) => {
|
|
6
|
-
const handler = (e) => set(e.detail);
|
|
7
|
-
manager.editorEnabled.addEventListener('change', handler);
|
|
8
|
-
return () => manager.editorEnabled.removeEventListener('change', handler);
|
|
9
|
-
});
|
|
10
|
-
return { enabled };
|
|
11
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { FileContent } from '@intlayer/editor';
|
|
2
|
-
import type { KeyPath } from '@intlayer/types/keyPath';
|
|
3
|
-
import { readable } from 'svelte/store';
|
|
4
|
-
export type { FileContent };
|
|
5
|
-
export type FocusDictionaryStateProps = {
|
|
6
|
-
focusedContent: ReturnType<typeof readable<FileContent | null>>;
|
|
7
|
-
setFocusedContent: (content: FileContent | null) => void;
|
|
8
|
-
setFocusedContentKeyPath: (keyPath: KeyPath[]) => void;
|
|
9
|
-
};
|
|
10
|
-
export declare const useFocusDictionary: () => FocusDictionaryStateProps;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { readable } from 'svelte/store';
|
|
2
|
-
import { getEditorStateManager } from './communicator';
|
|
3
|
-
export const useFocusDictionary = () => {
|
|
4
|
-
const manager = getEditorStateManager();
|
|
5
|
-
const focusedContent = readable(manager.focusedContent.value ?? null, (set) => {
|
|
6
|
-
const handler = (e) => set(e.detail);
|
|
7
|
-
manager.focusedContent.addEventListener('change', handler);
|
|
8
|
-
return () => manager.focusedContent.removeEventListener('change', handler);
|
|
9
|
-
});
|
|
10
|
-
return {
|
|
11
|
-
focusedContent,
|
|
12
|
-
setFocusedContent: (content) => manager.focusedContent.set(content),
|
|
13
|
-
setFocusedContentKeyPath: (keyPath) => manager.setFocusedContentKeyPath(keyPath),
|
|
14
|
-
};
|
|
15
|
-
};
|
package/dist/editor/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { default as ContentSelector } from './ContentSelector.svelte';
|
|
2
|
-
export { default as ContentSelectorWrapper } from './ContentSelectorWrapper.svelte';
|
|
3
|
-
export * from './communicator';
|
|
4
|
-
export * from './dictionariesRecord';
|
|
5
|
-
export * from './editorEnabled';
|
|
6
|
-
export * from './focusDictionary';
|
|
7
|
-
export * from './useCrossFrameMessageListener';
|
|
8
|
-
export * from './useCrossFrameState';
|
|
9
|
-
export * from './useEditor';
|
|
10
|
-
export * from './useIframeClickInterceptor';
|
package/dist/editor/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { default as ContentSelector } from './ContentSelector.svelte';
|
|
2
|
-
export { default as ContentSelectorWrapper } from './ContentSelectorWrapper.svelte';
|
|
3
|
-
export * from './communicator';
|
|
4
|
-
export * from './dictionariesRecord';
|
|
5
|
-
export * from './editorEnabled';
|
|
6
|
-
export * from './focusDictionary';
|
|
7
|
-
export * from './useCrossFrameMessageListener';
|
|
8
|
-
export * from './useCrossFrameState';
|
|
9
|
-
export * from './useEditor';
|
|
10
|
-
export * from './useIframeClickInterceptor';
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { onDestroy } from 'svelte';
|
|
2
|
-
import { getEditorStateManager } from './communicator';
|
|
3
|
-
export const useCrossFrameMessageListener = (key, onEventTriggered, autoCleanup = true) => {
|
|
4
|
-
const manager = getEditorStateManager();
|
|
5
|
-
if (onEventTriggered) {
|
|
6
|
-
const unsub = manager.messenger.subscribe(key, onEventTriggered);
|
|
7
|
-
if (autoCleanup) {
|
|
8
|
-
try {
|
|
9
|
-
onDestroy(unsub);
|
|
10
|
-
}
|
|
11
|
-
catch {
|
|
12
|
-
// Outside component context
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return (data) => manager.messenger.send(key, data);
|
|
17
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type MessageKey } from '@intlayer/editor';
|
|
2
|
-
import { writable } from 'svelte/store';
|
|
3
|
-
export type CrossFrameStateOptions = {
|
|
4
|
-
emit?: boolean;
|
|
5
|
-
receive?: boolean;
|
|
6
|
-
};
|
|
7
|
-
export declare const useCrossFrameState: <S>(key: `${MessageKey}`, initialState?: S, options?: CrossFrameStateOptions) => [ReturnType<typeof writable<S | undefined>>, (value: S) => void];
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { CrossFrameStateManager } from '@intlayer/editor';
|
|
2
|
-
import { onDestroy } from 'svelte';
|
|
3
|
-
import { writable } from 'svelte/store';
|
|
4
|
-
import { getEditorStateManager } from './communicator';
|
|
5
|
-
export const useCrossFrameState = (key, initialState, options = { emit: true, receive: true }) => {
|
|
6
|
-
const manager = getEditorStateManager();
|
|
7
|
-
const { emit = true, receive = true } = options;
|
|
8
|
-
const stateManager = new CrossFrameStateManager(key, manager.messenger, {
|
|
9
|
-
emit,
|
|
10
|
-
receive,
|
|
11
|
-
initialValue: initialState,
|
|
12
|
-
});
|
|
13
|
-
stateManager.start();
|
|
14
|
-
const store = writable(stateManager.value);
|
|
15
|
-
const handler = (e) => store.set(e.detail);
|
|
16
|
-
stateManager.addEventListener('change', handler);
|
|
17
|
-
try {
|
|
18
|
-
onDestroy(() => {
|
|
19
|
-
stateManager.removeEventListener('change', handler);
|
|
20
|
-
stateManager.stop();
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
catch {
|
|
24
|
-
// Outside component context
|
|
25
|
-
}
|
|
26
|
-
const setState = (value) => {
|
|
27
|
-
stateManager.set(value);
|
|
28
|
-
};
|
|
29
|
-
return [store, setState];
|
|
30
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { MessageKey, mergeIframeClick } from '@intlayer/editor';
|
|
2
|
-
import { useCrossFrameMessageListener } from './useCrossFrameMessageListener';
|
|
3
|
-
export const useIframeClickInterceptor = () => {
|
|
4
|
-
useCrossFrameMessageListener(MessageKey.INTLAYER_IFRAME_CLICKED);
|
|
5
|
-
};
|
|
6
|
-
export const useIframeClickMerger = () => {
|
|
7
|
-
useCrossFrameMessageListener(MessageKey.INTLAYER_IFRAME_CLICKED, mergeIframeClick);
|
|
8
|
-
};
|