svelte-intlayer 7.1.8 → 7.1.9
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/IntlayerNodeWrapper.svelte +10 -0
- package/dist/IntlayerNodeWrapper.svelte.d.ts +22 -0
- package/dist/client/IntlayerProvider.svelte +24 -0
- package/dist/client/IntlayerProvider.svelte.d.ts +30 -0
- package/dist/{types/client → client}/getBrowserLocale.d.ts +1 -1
- package/dist/client/getBrowserLocale.js +17 -0
- package/dist/client/index.js +12 -0
- package/dist/{types/client → client}/intlayerContext.d.ts +1 -1
- package/dist/client/intlayerContext.js +8 -0
- package/dist/client/intlayerStore.d.ts +11 -0
- package/dist/client/intlayerStore.js +19 -0
- package/dist/{types/client → client}/useDictionary.d.ts +3 -3
- package/dist/client/useDictionary.js +18 -0
- package/dist/{types/client → client}/useDictionaryAsync.d.ts +2 -2
- package/dist/client/useDictionaryAsync.js +38 -0
- package/dist/{types/client → client}/useDictionaryDynamic.d.ts +2 -2
- package/dist/client/useDictionaryDynamic.js +38 -0
- package/dist/{types/client → client}/useIntlayer.d.ts +3 -3
- package/dist/client/useIntlayer.js +18 -0
- package/dist/{types/client → client}/useLocale.d.ts +4 -4
- package/dist/client/useLocale.js +33 -0
- package/dist/client/useLocaleStorage.d.ts +39 -0
- package/dist/client/useLocaleStorage.js +52 -0
- package/dist/editor/ContentSelector.svelte +125 -0
- package/dist/editor/ContentSelector.svelte.d.ts +35 -0
- package/dist/editor/ContentSelectorWrapper.svelte +69 -0
- package/dist/editor/ContentSelectorWrapper.svelte.d.ts +31 -0
- package/dist/{types/editor → editor}/communicator.d.ts +1 -1
- package/dist/editor/communicator.js +54 -0
- package/dist/{types/editor → editor}/dictionariesRecord.d.ts +2 -2
- package/dist/editor/dictionariesRecord.js +16 -0
- package/dist/{types/editor → editor}/editorEnabled.d.ts +1 -1
- package/dist/editor/editorEnabled.js +41 -0
- package/dist/{types/editor → editor}/focusDictionary.d.ts +2 -2
- package/dist/editor/focusDictionary.js +22 -0
- package/dist/editor/index.js +9 -0
- package/dist/{types/editor → editor}/useCrossFrameMessageListener.d.ts +1 -1
- package/dist/editor/useCrossFrameMessageListener.js +65 -0
- package/dist/{types/editor → editor}/useCrossFrameState.d.ts +2 -2
- package/dist/editor/useCrossFrameState.js +82 -0
- package/dist/editor/useEditor.js +46 -0
- package/dist/editor/useIframeClickInterceptor.js +29 -0
- package/dist/{types/getDictionary.d.ts → getDictionary.d.ts} +3 -3
- package/dist/getDictionary.js +18 -0
- package/dist/{types/getIntlayer.d.ts → getIntlayer.d.ts} +3 -3
- package/dist/getIntlayer.js +18 -0
- package/dist/{types/index.d.ts → index.d.ts} +3 -3
- package/dist/index.js +7 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +6 -0
- package/dist/markdown/MarkdownMetadataRenderer.svelte +21 -0
- package/dist/markdown/MarkdownMetadataRenderer.svelte.d.ts +25 -0
- package/dist/markdown/MarkdownMetadataWithSelector.svelte +21 -0
- package/dist/markdown/MarkdownMetadataWithSelector.svelte.d.ts +24 -0
- package/dist/markdown/MarkdownProvider.svelte +9 -0
- package/dist/markdown/MarkdownProvider.svelte.d.ts +29 -0
- package/dist/markdown/MarkdownRenderer.svelte +11 -0
- package/dist/markdown/MarkdownRenderer.svelte.d.ts +20 -0
- package/dist/markdown/MarkdownWithSelector.svelte +15 -0
- package/dist/markdown/MarkdownWithSelector.svelte.d.ts +23 -0
- package/dist/markdown/context.js +10 -0
- package/dist/markdown/index.js +4 -0
- package/dist/{types/plugins.d.ts → plugins.d.ts} +3 -3
- package/dist/plugins.js +87 -0
- package/dist/renderIntlayerNode.js +44 -0
- package/dist/setIntlayerMarkdown.d.ts +1 -0
- package/dist/setIntlayerMarkdown.js +2 -0
- package/package.json +22 -30
- package/dist/ContentSelectorWrapper-Ct4vOl_g.js +0 -163
- package/dist/ContentSelectorWrapper-DMEqv3vE.cjs +0 -10
- package/dist/MarkdownRenderer-BFrmuaFN.js +0 -47
- package/dist/MarkdownRenderer-DyK7SeHa.cjs +0 -1
- package/dist/cjs/client/getBrowserLocale.cjs +0 -1
- package/dist/cjs/client/index.cjs +0 -1
- package/dist/cjs/client/intlayerContext.cjs +0 -1
- package/dist/cjs/client/intlayerStore.cjs +0 -1
- package/dist/cjs/client/useDictionary.cjs +0 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +0 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +0 -1
- package/dist/cjs/client/useIntlayer.cjs +0 -1
- package/dist/cjs/client/useLocale.cjs +0 -1
- package/dist/cjs/client/useLocaleStorage.cjs +0 -1
- package/dist/cjs/editor/communicator.cjs +0 -1
- package/dist/cjs/editor/dictionariesRecord.cjs +0 -1
- package/dist/cjs/editor/editorEnabled.cjs +0 -1
- package/dist/cjs/editor/focusDictionary.cjs +0 -1
- package/dist/cjs/editor/index.cjs +0 -1
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs +0 -1
- package/dist/cjs/editor/useCrossFrameState.cjs +0 -1
- package/dist/cjs/editor/useEditor.cjs +0 -1
- package/dist/cjs/editor/useIframeClickInterceptor.cjs +0 -1
- package/dist/cjs/getDictionary.cjs +0 -1
- package/dist/cjs/getIntlayer.cjs +0 -1
- package/dist/cjs/index.cjs +0 -1
- package/dist/cjs/markdown/context.cjs +0 -1
- package/dist/cjs/markdown/index.cjs +0 -1
- package/dist/cjs/plugins.cjs +0 -1
- package/dist/cjs/renderIntlayerNode.cjs +0 -1
- package/dist/cjs/setIntlayerMarkdown.cjs +0 -1
- package/dist/esm/client/getBrowserLocale.mjs +0 -9
- package/dist/esm/client/index.mjs +0 -19
- package/dist/esm/client/intlayerContext.mjs +0 -8
- package/dist/esm/client/intlayerStore.mjs +0 -16
- package/dist/esm/client/useDictionary.mjs +0 -14
- package/dist/esm/client/useDictionaryAsync.mjs +0 -27
- package/dist/esm/client/useDictionaryDynamic.mjs +0 -27
- package/dist/esm/client/useIntlayer.mjs +0 -14
- package/dist/esm/client/useLocale.mjs +0 -33
- package/dist/esm/client/useLocaleStorage.mjs +0 -29
- package/dist/esm/editor/communicator.mjs +0 -31
- package/dist/esm/editor/dictionariesRecord.mjs +0 -20
- package/dist/esm/editor/editorEnabled.mjs +0 -28
- package/dist/esm/editor/focusDictionary.mjs +0 -21
- package/dist/esm/editor/index.mjs +0 -23
- package/dist/esm/editor/useCrossFrameMessageListener.mjs +0 -37
- package/dist/esm/editor/useCrossFrameState.mjs +0 -53
- package/dist/esm/editor/useEditor.mjs +0 -38
- package/dist/esm/editor/useIframeClickInterceptor.mjs +0 -26
- package/dist/esm/getDictionary.mjs +0 -18
- package/dist/esm/getIntlayer.mjs +0 -14
- package/dist/esm/index.mjs +0 -37
- package/dist/esm/markdown/context.mjs +0 -11
- package/dist/esm/markdown/index.mjs +0 -21
- package/dist/esm/plugins.mjs +0 -133
- package/dist/esm/renderIntlayerNode.mjs +0 -51
- package/dist/esm/setIntlayerMarkdown.mjs +0 -5
- package/dist/types/IntlayerNodeWrapper.svelte.d.ts +0 -1
- package/dist/types/client/intlayerStore.d.ts +0 -11
- package/dist/types/client/useLocaleStorage.d.ts +0 -39
- package/dist/types/editor/ContentSelector.svelte.d.ts +0 -1
- package/dist/types/editor/ContentSelectorWrapper.svelte.d.ts +0 -1
- package/dist/types/markdown/MarkdownMetadataRenderer.svelte.d.ts +0 -1
- package/dist/types/markdown/MarkdownMetadataWithSelector.svelte.d.ts +0 -1
- package/dist/types/markdown/MarkdownProvider.svelte.d.ts +0 -1
- package/dist/types/markdown/MarkdownRenderer.svelte.d.ts +0 -1
- package/dist/types/markdown/MarkdownWithSelector.svelte.d.ts +0 -1
- package/dist/types/setIntlayerMarkdown.d.ts +0 -1
- /package/dist/{types/client → client}/index.d.ts +0 -0
- /package/dist/{types/editor → editor}/index.d.ts +0 -0
- /package/dist/{types/editor → editor}/useEditor.d.ts +0 -0
- /package/dist/{types/editor → editor}/useIframeClickInterceptor.d.ts +0 -0
- /package/dist/{types/markdown → markdown}/context.d.ts +0 -0
- /package/dist/{types/markdown → markdown}/index.d.ts +0 -0
- /package/dist/{types/renderIntlayerNode.d.ts → renderIntlayerNode.d.ts} +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
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
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
|
+
$$bindings?: Bindings;
|
|
4
|
+
} & Exports;
|
|
5
|
+
(internal: unknown, props: Props & {
|
|
6
|
+
$$events?: Events;
|
|
7
|
+
$$slots?: Slots;
|
|
8
|
+
}): Exports & {
|
|
9
|
+
$set?: any;
|
|
10
|
+
$on?: any;
|
|
11
|
+
};
|
|
12
|
+
z_$$bindings?: Bindings;
|
|
13
|
+
}
|
|
14
|
+
declare const IntlayerNodeWrapper: $$__sveltets_2_IsomorphicComponent<{
|
|
15
|
+
Renderer: any;
|
|
16
|
+
rendererProps: Record<string, any>;
|
|
17
|
+
value: any;
|
|
18
|
+
}, {
|
|
19
|
+
[evt: string]: CustomEvent<any>;
|
|
20
|
+
}, {}, {}, string>;
|
|
21
|
+
type IntlayerNodeWrapper = InstanceType<typeof IntlayerNodeWrapper>;
|
|
22
|
+
export default IntlayerNodeWrapper;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { LocalesValues } from '@intlayer/types';
|
|
3
|
+
import { createCommunicator } from '../editor/communicator';
|
|
4
|
+
import { createEditorEnabledClient } from '../editor/editorEnabled';
|
|
5
|
+
import { createFocusDictionaryClient } from '../editor/focusDictionary';
|
|
6
|
+
import { useEditor } from '../editor/useEditor';
|
|
7
|
+
import { setIntlayerContext } from './intlayerContext';
|
|
8
|
+
|
|
9
|
+
export let locale: LocalesValues;
|
|
10
|
+
|
|
11
|
+
createCommunicator();
|
|
12
|
+
createEditorEnabledClient();
|
|
13
|
+
createFocusDictionaryClient();
|
|
14
|
+
|
|
15
|
+
useEditor();
|
|
16
|
+
|
|
17
|
+
setIntlayerContext({
|
|
18
|
+
locale,
|
|
19
|
+
setLocale: () => {},
|
|
20
|
+
});
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<slot />
|
|
24
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { LocalesValues } from '@intlayer/types';
|
|
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 IntlayerProvider: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<{
|
|
21
|
+
locale: LocalesValues;
|
|
22
|
+
}, {
|
|
23
|
+
default: {};
|
|
24
|
+
}>, {
|
|
25
|
+
[evt: string]: CustomEvent<any>;
|
|
26
|
+
}, {
|
|
27
|
+
default: {};
|
|
28
|
+
}, {}, string>;
|
|
29
|
+
type IntlayerProvider = InstanceType<typeof IntlayerProvider>;
|
|
30
|
+
export default IntlayerProvider;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets the user's preferred locale from browser settings
|
|
3
|
+
* @returns The detected browser locale or 'en' as fallback
|
|
4
|
+
*/
|
|
5
|
+
export const getBrowserLocale = () => {
|
|
6
|
+
if (typeof navigator === 'undefined') {
|
|
7
|
+
return 'en';
|
|
8
|
+
}
|
|
9
|
+
// Get the first preferred language
|
|
10
|
+
const browserLocale = navigator.language || navigator.languages?.[0];
|
|
11
|
+
if (!browserLocale) {
|
|
12
|
+
return 'en';
|
|
13
|
+
}
|
|
14
|
+
// Extract language code (e.g., 'en-US' -> 'en')
|
|
15
|
+
const languageCode = browserLocale.split('-')[0];
|
|
16
|
+
return (languageCode || 'en');
|
|
17
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Export all client-side functionality for Svelte applications
|
|
2
|
+
// Locale management
|
|
3
|
+
export { getBrowserLocale } from './getBrowserLocale';
|
|
4
|
+
// Context and providers
|
|
5
|
+
export { getIntlayerContext, setIntlayerContext } from './intlayerContext';
|
|
6
|
+
export { intlayerStore } from './intlayerStore';
|
|
7
|
+
// Core hooks
|
|
8
|
+
export { useDictionary } from './useDictionary';
|
|
9
|
+
export { useDictionaryAsync } from './useDictionaryAsync';
|
|
10
|
+
export { useDictionaryDynamic } from './useDictionaryDynamic';
|
|
11
|
+
export { useIntlayer } from './useIntlayer';
|
|
12
|
+
export { useLocale } from './useLocale';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { getContext, setContext } from 'svelte';
|
|
2
|
+
const INTLAYER_CONTEXT_KEY = Symbol('intlayer');
|
|
3
|
+
export const setIntlayerContext = (context) => {
|
|
4
|
+
setContext(INTLAYER_CONTEXT_KEY, context);
|
|
5
|
+
};
|
|
6
|
+
export const getIntlayerContext = () => {
|
|
7
|
+
return getContext(INTLAYER_CONTEXT_KEY);
|
|
8
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Locale, LocalesValues } from '@intlayer/types';
|
|
2
|
+
import { type Readable } from 'svelte/store';
|
|
3
|
+
export interface IntlayerStoreType {
|
|
4
|
+
locale: Locale;
|
|
5
|
+
}
|
|
6
|
+
export declare const intlayerStore: {
|
|
7
|
+
subscribe: (this: void, run: import("svelte/store").Subscriber<IntlayerStoreType>, invalidate?: () => void) => import("svelte/store").Unsubscriber;
|
|
8
|
+
setLocale: (locale: LocalesValues) => void;
|
|
9
|
+
getLocale: () => Readable<Locale>;
|
|
10
|
+
reset: () => void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import configuration from '@intlayer/config/built';
|
|
2
|
+
import { derived, writable } from 'svelte/store';
|
|
3
|
+
const defaultLocale = configuration.internationalization
|
|
4
|
+
?.defaultLocale;
|
|
5
|
+
// Create the main intlayer store
|
|
6
|
+
const createIntlayerStore = () => {
|
|
7
|
+
const { subscribe, set, update } = writable({
|
|
8
|
+
locale: defaultLocale, // Default locale
|
|
9
|
+
});
|
|
10
|
+
return {
|
|
11
|
+
subscribe,
|
|
12
|
+
setLocale: (locale) => update((store) => ({ ...store, locale: locale })),
|
|
13
|
+
getLocale: () => derived({ subscribe }, ($store) => $store.locale),
|
|
14
|
+
reset: () => set({
|
|
15
|
+
locale: defaultLocale,
|
|
16
|
+
}),
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
export const intlayerStore = createIntlayerStore();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Dictionary, LocalesValues } from '@intlayer/types';
|
|
2
|
-
import { Readable } from 'svelte/store';
|
|
3
|
-
import { DeepTransformContent } from '../plugins';
|
|
1
|
+
import type { Dictionary, LocalesValues } from '@intlayer/types';
|
|
2
|
+
import { type Readable } from 'svelte/store';
|
|
3
|
+
import type { DeepTransformContent } from '../plugins';
|
|
4
4
|
/**
|
|
5
5
|
* Svelte hook that transforms a dictionary and returns reactive content
|
|
6
6
|
* @param dictionary The dictionary to transform
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { derived } from 'svelte/store';
|
|
2
|
+
import { getDictionary } from '../getDictionary';
|
|
3
|
+
import { getIntlayerContext } from './intlayerContext';
|
|
4
|
+
import { intlayerStore } from './intlayerStore';
|
|
5
|
+
/**
|
|
6
|
+
* Svelte hook that transforms a dictionary and returns reactive content
|
|
7
|
+
* @param dictionary The dictionary to transform
|
|
8
|
+
* @param locale The target locale (optional, uses context or store locale)
|
|
9
|
+
* @returns Reactive store with transformed dictionary content
|
|
10
|
+
*/
|
|
11
|
+
export const useDictionary = (dictionary, locale) => {
|
|
12
|
+
const context = getIntlayerContext();
|
|
13
|
+
// Create a derived store that reactively updates when locale changes
|
|
14
|
+
return derived([intlayerStore], ([$store]) => {
|
|
15
|
+
const targetLocale = locale ?? context?.locale ?? $store.locale;
|
|
16
|
+
return getDictionary(dictionary, targetLocale);
|
|
17
|
+
});
|
|
18
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Dictionary, LocalesValues, StrictModeLocaleMap } from '@intlayer/types';
|
|
2
|
-
import { Readable } from 'svelte/store';
|
|
1
|
+
import type { Dictionary, LocalesValues, StrictModeLocaleMap } from '@intlayer/types';
|
|
2
|
+
import { type Readable } from 'svelte/store';
|
|
3
3
|
/**
|
|
4
4
|
* Svelte hook for handling dynamic dictionary loading
|
|
5
5
|
* @param dictionaryPromise Promise-based dictionary content
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { derived, writable } from 'svelte/store';
|
|
2
|
+
import { getIntlayerContext } from './intlayerContext';
|
|
3
|
+
import { intlayerStore } from './intlayerStore';
|
|
4
|
+
/**
|
|
5
|
+
* Svelte hook for handling dynamic dictionary loading
|
|
6
|
+
* @param dictionaryPromise Promise-based dictionary content
|
|
7
|
+
* @param key Dictionary key for caching
|
|
8
|
+
* @param locale Target locale (optional)
|
|
9
|
+
* @returns Reactive store with loaded dictionary content
|
|
10
|
+
*/
|
|
11
|
+
export const useDictionaryAsync = async (dictionaryPromise, locale) => {
|
|
12
|
+
const context = getIntlayerContext();
|
|
13
|
+
const dictionaryStore = writable(null);
|
|
14
|
+
// Create a derived store that loads the dictionary when locale changes
|
|
15
|
+
return derived([intlayerStore], ([$store]) => {
|
|
16
|
+
const targetLocale = locale ?? context?.locale ?? $store.locale;
|
|
17
|
+
// Load dictionary for the target locale asynchronously
|
|
18
|
+
const loadDictionary = async () => {
|
|
19
|
+
try {
|
|
20
|
+
const dictionaryLoader = dictionaryPromise[targetLocale];
|
|
21
|
+
if (dictionaryLoader) {
|
|
22
|
+
const loadedDictionary = await dictionaryLoader();
|
|
23
|
+
dictionaryStore.set(loadedDictionary);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
dictionaryStore.set(null);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error(`Failed to load dictionary for key: ${String(targetLocale)}`, error);
|
|
31
|
+
dictionaryStore.set(null);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
loadDictionary();
|
|
35
|
+
// Return the current state, actual loading happens asynchronously
|
|
36
|
+
return null;
|
|
37
|
+
});
|
|
38
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Dictionary, DictionaryKeys, LocalesValues, StrictModeLocaleMap } from '@intlayer/types';
|
|
2
|
-
import { Readable } from 'svelte/store';
|
|
1
|
+
import type { Dictionary, DictionaryKeys, LocalesValues, StrictModeLocaleMap } from '@intlayer/types';
|
|
2
|
+
import { type Readable } from 'svelte/store';
|
|
3
3
|
/**
|
|
4
4
|
* Svelte hook for handling dynamic dictionary loading
|
|
5
5
|
* @param dictionaryPromise Promise-based dictionary content
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { derived, writable } from 'svelte/store';
|
|
2
|
+
import { getIntlayerContext } from './intlayerContext';
|
|
3
|
+
import { intlayerStore } from './intlayerStore';
|
|
4
|
+
/**
|
|
5
|
+
* Svelte hook for handling dynamic dictionary loading
|
|
6
|
+
* @param dictionaryPromise Promise-based dictionary content
|
|
7
|
+
* @param key Dictionary key for caching
|
|
8
|
+
* @param locale Target locale (optional)
|
|
9
|
+
* @returns Reactive store with loaded dictionary content
|
|
10
|
+
*/
|
|
11
|
+
export const useDictionaryDynamic = (dictionaryPromise, key, locale) => {
|
|
12
|
+
const context = getIntlayerContext();
|
|
13
|
+
const dictionaryStore = writable(null);
|
|
14
|
+
// Create a derived store that loads the dictionary when locale changes
|
|
15
|
+
return derived([intlayerStore], ([$store]) => {
|
|
16
|
+
const targetLocale = locale ?? context?.locale ?? $store.locale;
|
|
17
|
+
// Load dictionary for the target locale asynchronously
|
|
18
|
+
const loadDictionary = async () => {
|
|
19
|
+
try {
|
|
20
|
+
const dictionaryLoader = dictionaryPromise[targetLocale];
|
|
21
|
+
if (dictionaryLoader) {
|
|
22
|
+
const loadedDictionary = await dictionaryLoader();
|
|
23
|
+
dictionaryStore.set(loadedDictionary);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
dictionaryStore.set(null);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error(`Failed to load dictionary for key: ${String(key)}`, error);
|
|
31
|
+
dictionaryStore.set(null);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
loadDictionary();
|
|
35
|
+
// Return the current state, actual loading happens asynchronously
|
|
36
|
+
return null;
|
|
37
|
+
});
|
|
38
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DictionaryKeys, DictionaryRegistryContent, LocalesValues } from '@intlayer/types';
|
|
2
|
-
import { Readable } from 'svelte/store';
|
|
3
|
-
import { DeepTransformContent } from '../plugins';
|
|
1
|
+
import type { DictionaryKeys, DictionaryRegistryContent, LocalesValues } from '@intlayer/types';
|
|
2
|
+
import { type Readable } from 'svelte/store';
|
|
3
|
+
import type { DeepTransformContent } from '../plugins';
|
|
4
4
|
/**
|
|
5
5
|
* Svelte hook that picks one dictionary by its key and returns reactive content
|
|
6
6
|
* @param key The dictionary key to retrieve
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { derived } from 'svelte/store';
|
|
2
|
+
import { getIntlayer } from '../getIntlayer';
|
|
3
|
+
import { getIntlayerContext } from './intlayerContext';
|
|
4
|
+
import { intlayerStore } from './intlayerStore';
|
|
5
|
+
/**
|
|
6
|
+
* Svelte hook that picks one dictionary by its key and returns reactive content
|
|
7
|
+
* @param key The dictionary key to retrieve
|
|
8
|
+
* @param locale The target locale (optional, uses context or store locale)
|
|
9
|
+
* @returns Reactive store with transformed dictionary content
|
|
10
|
+
*/
|
|
11
|
+
export const useIntlayer = (key, locale) => {
|
|
12
|
+
const context = getIntlayerContext();
|
|
13
|
+
// Create a derived store that reactively updates when locale changes
|
|
14
|
+
return derived([intlayerStore], ([$store]) => {
|
|
15
|
+
const targetLocale = locale ?? context?.locale ?? $store.locale;
|
|
16
|
+
return getIntlayer(key, targetLocale);
|
|
17
|
+
});
|
|
18
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LocalesValues } from '@intlayer/types';
|
|
1
|
+
import type { LocalesValues } from '@intlayer/types';
|
|
2
2
|
type useLocaleProps = {
|
|
3
3
|
isCookieEnabled?: boolean;
|
|
4
4
|
onLocaleChange?: (locale: LocalesValues) => void;
|
|
@@ -8,9 +8,9 @@ type useLocaleProps = {
|
|
|
8
8
|
* @returns Readable store with current locale and setter function
|
|
9
9
|
*/
|
|
10
10
|
export declare const useLocale: ({ isCookieEnabled, onLocaleChange, }?: useLocaleProps) => {
|
|
11
|
-
locale: import(
|
|
11
|
+
locale: import("svelte/store").Readable<LocalesValues>;
|
|
12
12
|
setLocale: (locale: LocalesValues) => void;
|
|
13
|
-
defaultLocale: import(
|
|
14
|
-
availableLocales: import(
|
|
13
|
+
defaultLocale: import("@intlayer/types").Locale;
|
|
14
|
+
availableLocales: import("@intlayer/types").Locale[];
|
|
15
15
|
};
|
|
16
16
|
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import configuration from '@intlayer/config/built';
|
|
2
|
+
import { derived } from 'svelte/store';
|
|
3
|
+
import { getIntlayerContext } from './intlayerContext';
|
|
4
|
+
import { intlayerStore } from './intlayerStore';
|
|
5
|
+
import { setLocaleInStorage } from './useLocaleStorage';
|
|
6
|
+
/**
|
|
7
|
+
* Hook to get and set the current locale in Svelte applications
|
|
8
|
+
* @returns Readable store with current locale and setter function
|
|
9
|
+
*/
|
|
10
|
+
export const useLocale = ({ isCookieEnabled, onLocaleChange, } = {}) => {
|
|
11
|
+
const context = getIntlayerContext();
|
|
12
|
+
const { defaultLocale, locales: availableLocales } = configuration?.internationalization ?? {};
|
|
13
|
+
if (context) {
|
|
14
|
+
// Use context if available
|
|
15
|
+
return {
|
|
16
|
+
locale: derived([intlayerStore], ([$store]) => context.locale ?? $store.locale),
|
|
17
|
+
setLocale: (locale) => {
|
|
18
|
+
context.setLocale(locale);
|
|
19
|
+
setLocaleInStorage(locale, isCookieEnabled ?? context?.isCookieEnabled ?? true);
|
|
20
|
+
onLocaleChange?.(locale);
|
|
21
|
+
},
|
|
22
|
+
defaultLocale,
|
|
23
|
+
availableLocales,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
// Fallback to global store
|
|
27
|
+
return {
|
|
28
|
+
locale: intlayerStore.getLocale(),
|
|
29
|
+
setLocale: intlayerStore.setLocale,
|
|
30
|
+
defaultLocale,
|
|
31
|
+
availableLocales,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { LocalesValues } from '@intlayer/types';
|
|
2
|
+
/**
|
|
3
|
+
* Get the locale cookie
|
|
4
|
+
*/
|
|
5
|
+
export declare const localeInStorage: import("@intlayer/types").Locale | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* @deprecated Use localeInStorage instead
|
|
8
|
+
*
|
|
9
|
+
* Get the locale cookie
|
|
10
|
+
*/
|
|
11
|
+
export declare const localeCookie: import("@intlayer/types").Locale | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Set the locale cookie
|
|
14
|
+
*/
|
|
15
|
+
export declare const setLocaleInStorage: (locale: LocalesValues, isCookieEnabled: boolean) => void;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated Use setLocaleInStorage instead
|
|
18
|
+
*
|
|
19
|
+
* Set the locale cookie
|
|
20
|
+
*/
|
|
21
|
+
export declare const setLocaleCookie: (locale: LocalesValues, isCookieEnabled: boolean) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Composable that provides the locale storage and a function to set it
|
|
24
|
+
*/
|
|
25
|
+
export declare const useLocaleStorage: (isCookieEnabled?: boolean) => {
|
|
26
|
+
localeStorage: import("svelte/store").Readable<"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" | "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" | "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" | "nb" | "nb-NO" | "nl" | "nl-BE" | "nl-NL" | "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" | "ru" | "ru-RU" | "sa" | "sa-IN" | "se" | "se-FI" | "se-NO" | "se-SE" | "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" | "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" | "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">;
|
|
27
|
+
setLocaleStorage: (locale: LocalesValues) => void;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated Use useLocaleStorage instead
|
|
31
|
+
*
|
|
32
|
+
* For GDPR compliance, use useLocaleStorage instead
|
|
33
|
+
*
|
|
34
|
+
* Composable that provides the locale cookie and a function to set it
|
|
35
|
+
*/
|
|
36
|
+
export declare const useLocaleCookie: (isCookieEnabled?: boolean) => {
|
|
37
|
+
localeCookie: import("svelte/store").Readable<"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" | "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" | "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" | "nb" | "nb-NO" | "nl" | "nl-BE" | "nl-NL" | "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" | "ru" | "ru-RU" | "sa" | "sa-IN" | "se" | "se-FI" | "se-NO" | "se-SE" | "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" | "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" | "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">;
|
|
38
|
+
setLocaleCookie: (locale: LocalesValues) => void;
|
|
39
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { getLocaleFromStorage, LocaleStorage, localeStorageOptions, setLocaleInStorage as setLocaleInStorageCore, } from '@intlayer/core';
|
|
2
|
+
import { readable } from 'svelte/store';
|
|
3
|
+
/**
|
|
4
|
+
* Get the locale cookie
|
|
5
|
+
*/
|
|
6
|
+
export const localeInStorage = getLocaleFromStorage(localeStorageOptions);
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use localeInStorage instead
|
|
9
|
+
*
|
|
10
|
+
* Get the locale cookie
|
|
11
|
+
*/
|
|
12
|
+
export const localeCookie = localeInStorage;
|
|
13
|
+
/**
|
|
14
|
+
* Set the locale cookie
|
|
15
|
+
*/
|
|
16
|
+
export const setLocaleInStorage = (locale, isCookieEnabled) => setLocaleInStorageCore(locale, {
|
|
17
|
+
...localeStorageOptions,
|
|
18
|
+
isCookieEnabled,
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Use setLocaleInStorage instead
|
|
22
|
+
*
|
|
23
|
+
* Set the locale cookie
|
|
24
|
+
*/
|
|
25
|
+
export const setLocaleCookie = setLocaleInStorage;
|
|
26
|
+
/**
|
|
27
|
+
* Composable that provides the locale storage and a function to set it
|
|
28
|
+
*/
|
|
29
|
+
export const useLocaleStorage = (isCookieEnabled) => {
|
|
30
|
+
const storage = LocaleStorage({
|
|
31
|
+
...localeStorageOptions,
|
|
32
|
+
isCookieEnabled,
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
localeStorage: readable(storage.getLocale()),
|
|
36
|
+
setLocaleStorage: storage.setLocale,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Use useLocaleStorage instead
|
|
41
|
+
*
|
|
42
|
+
* For GDPR compliance, use useLocaleStorage instead
|
|
43
|
+
*
|
|
44
|
+
* Composable that provides the locale cookie and a function to set it
|
|
45
|
+
*/
|
|
46
|
+
export const useLocaleCookie = (isCookieEnabled) => {
|
|
47
|
+
const storage = useLocaleStorage(isCookieEnabled);
|
|
48
|
+
return {
|
|
49
|
+
localeCookie: storage.localeStorage,
|
|
50
|
+
setLocaleCookie: storage.setLocaleStorage,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onDestroy, onMount } from 'svelte';
|
|
3
|
+
|
|
4
|
+
// Props
|
|
5
|
+
// biome-ignore lint/style/useConst: Svelte props need let
|
|
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
|
+
});
|
|
95
|
+
</script>
|
|
96
|
+
|
|
97
|
+
<span
|
|
98
|
+
bind:this={containerRef}
|
|
99
|
+
role="button"
|
|
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
|
+
`}
|
|
123
|
+
>
|
|
124
|
+
<slot />
|
|
125
|
+
</span>
|