preact-intlayer 8.3.3 → 8.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/UI/ContentSelector.cjs +1 -1
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
- package/dist/cjs/client/IntlayerProvider.cjs +1 -1
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/format/useCompact.cjs +1 -1
- package/dist/cjs/client/format/useCompact.cjs.map +1 -1
- package/dist/cjs/client/format/useCurrency.cjs +1 -1
- package/dist/cjs/client/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/client/format/useDate.cjs +1 -1
- package/dist/cjs/client/format/useDate.cjs.map +1 -1
- package/dist/cjs/client/format/useList.cjs +1 -1
- package/dist/cjs/client/format/useList.cjs.map +1 -1
- package/dist/cjs/client/format/useNumber.cjs +1 -1
- package/dist/cjs/client/format/useNumber.cjs.map +1 -1
- package/dist/cjs/client/format/usePercentage.cjs +1 -1
- package/dist/cjs/client/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/client/format/useRelativeTime.cjs +1 -1
- package/dist/cjs/client/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/client/format/useUnit.cjs +1 -1
- package/dist/cjs/client/format/useUnit.cjs.map +1 -1
- package/dist/cjs/client/t.cjs +1 -1
- package/dist/cjs/client/t.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +1 -1
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +1 -1
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +1 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleBase.cjs +1 -1
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
- package/dist/cjs/editor/CommunicatorContext.cjs +1 -1
- package/dist/cjs/editor/CommunicatorContext.cjs.map +1 -1
- package/dist/cjs/editor/ConfigurationContext.cjs +1 -1
- package/dist/cjs/editor/ConfigurationContext.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +1 -1
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/editor/DictionariesRecordContext.cjs +1 -1
- package/dist/cjs/editor/DictionariesRecordContext.cjs.map +1 -1
- package/dist/cjs/editor/EditedContentContext.cjs +1 -1
- package/dist/cjs/editor/EditedContentContext.cjs.map +1 -1
- package/dist/cjs/editor/EditorEnabledContext.cjs +1 -1
- package/dist/cjs/editor/EditorEnabledContext.cjs.map +1 -1
- package/dist/cjs/editor/EditorProvider.cjs +1 -1
- package/dist/cjs/editor/EditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/EditorStateContext.cjs +2 -0
- package/dist/cjs/editor/EditorStateContext.cjs.map +1 -0
- package/dist/cjs/editor/FocusDictionaryContext.cjs +1 -1
- package/dist/cjs/editor/FocusDictionaryContext.cjs.map +1 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +1 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/index.cjs +1 -1
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs +1 -1
- package/dist/cjs/editor/useCrossFrameMessageListener.cjs.map +1 -1
- package/dist/cjs/editor/useCrossFrameState.cjs +1 -1
- package/dist/cjs/editor/useCrossFrameState.cjs.map +1 -1
- package/dist/cjs/editor/useCrossURLPathState.cjs +1 -1
- package/dist/cjs/editor/useCrossURLPathState.cjs.map +1 -1
- package/dist/cjs/editor/useEditedContentRenderer.cjs +1 -1
- package/dist/cjs/editor/useEditedContentRenderer.cjs.map +1 -1
- package/dist/cjs/editor/useIframeClickInterceptor.cjs +1 -1
- package/dist/cjs/editor/useIframeClickInterceptor.cjs.map +1 -1
- package/dist/cjs/html/HTMLProvider.cjs +1 -1
- package/dist/cjs/html/HTMLProvider.cjs.map +1 -1
- package/dist/esm/UI/ContentSelector.mjs +1 -1
- package/dist/esm/UI/ContentSelector.mjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.mjs +1 -1
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/format/useCompact.mjs +1 -1
- package/dist/esm/client/format/useCompact.mjs.map +1 -1
- package/dist/esm/client/format/useCurrency.mjs +1 -1
- package/dist/esm/client/format/useCurrency.mjs.map +1 -1
- package/dist/esm/client/format/useDate.mjs +1 -1
- package/dist/esm/client/format/useDate.mjs.map +1 -1
- package/dist/esm/client/format/useList.mjs +1 -1
- package/dist/esm/client/format/useList.mjs.map +1 -1
- package/dist/esm/client/format/useNumber.mjs +1 -1
- package/dist/esm/client/format/useNumber.mjs.map +1 -1
- package/dist/esm/client/format/usePercentage.mjs +1 -1
- package/dist/esm/client/format/usePercentage.mjs.map +1 -1
- package/dist/esm/client/format/useRelativeTime.mjs +1 -1
- package/dist/esm/client/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/client/format/useUnit.mjs +1 -1
- package/dist/esm/client/format/useUnit.mjs.map +1 -1
- package/dist/esm/client/t.mjs +1 -1
- package/dist/esm/client/t.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +1 -1
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +1 -1
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +1 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.mjs +1 -1
- package/dist/esm/client/useLocaleBase.mjs.map +1 -1
- package/dist/esm/editor/CommunicatorContext.mjs +1 -1
- package/dist/esm/editor/CommunicatorContext.mjs.map +1 -1
- package/dist/esm/editor/ConfigurationContext.mjs +1 -1
- package/dist/esm/editor/ConfigurationContext.mjs.map +1 -1
- package/dist/esm/editor/ContentSelectorWrapper.mjs +1 -1
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/editor/DictionariesRecordContext.mjs +1 -1
- package/dist/esm/editor/DictionariesRecordContext.mjs.map +1 -1
- package/dist/esm/editor/EditedContentContext.mjs +1 -1
- package/dist/esm/editor/EditedContentContext.mjs.map +1 -1
- package/dist/esm/editor/EditorEnabledContext.mjs +1 -1
- package/dist/esm/editor/EditorEnabledContext.mjs.map +1 -1
- package/dist/esm/editor/EditorProvider.mjs +1 -1
- package/dist/esm/editor/EditorProvider.mjs.map +1 -1
- package/dist/esm/editor/EditorStateContext.mjs +2 -0
- package/dist/esm/editor/EditorStateContext.mjs.map +1 -0
- package/dist/esm/editor/FocusDictionaryContext.mjs +1 -1
- package/dist/esm/editor/FocusDictionaryContext.mjs.map +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
- package/dist/esm/editor/index.mjs +1 -1
- package/dist/esm/editor/useCrossFrameMessageListener.mjs +1 -1
- package/dist/esm/editor/useCrossFrameMessageListener.mjs.map +1 -1
- package/dist/esm/editor/useCrossFrameState.mjs +1 -1
- package/dist/esm/editor/useCrossFrameState.mjs.map +1 -1
- package/dist/esm/editor/useCrossURLPathState.mjs +1 -1
- package/dist/esm/editor/useCrossURLPathState.mjs.map +1 -1
- package/dist/esm/editor/useEditedContentRenderer.mjs +1 -1
- package/dist/esm/editor/useEditedContentRenderer.mjs.map +1 -1
- package/dist/esm/editor/useIframeClickInterceptor.mjs +1 -1
- package/dist/esm/editor/useIframeClickInterceptor.mjs.map +1 -1
- package/dist/esm/html/HTMLProvider.mjs +1 -1
- package/dist/esm/html/HTMLProvider.mjs.map +1 -1
- package/dist/types/UI/ContentSelector.d.ts.map +1 -1
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -1
- package/dist/types/client/format/useCompact.d.ts.map +1 -1
- package/dist/types/client/format/useCurrency.d.ts.map +1 -1
- package/dist/types/client/format/useDate.d.ts.map +1 -1
- package/dist/types/client/format/useList.d.ts.map +1 -1
- package/dist/types/client/format/useNumber.d.ts.map +1 -1
- package/dist/types/client/format/usePercentage.d.ts.map +1 -1
- package/dist/types/client/format/useRelativeTime.d.ts.map +1 -1
- package/dist/types/client/format/useUnit.d.ts.map +1 -1
- package/dist/types/client/t.d.ts.map +1 -1
- package/dist/types/client/useDictionary.d.ts.map +1 -1
- package/dist/types/client/useDictionaryAsync.d.ts.map +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/client/useIntlayer.d.ts.map +1 -1
- package/dist/types/client/useLocale.d.ts.map +1 -1
- package/dist/types/client/useLocaleBase.d.ts.map +1 -1
- package/dist/types/editor/CommunicatorContext.d.ts +4 -10
- package/dist/types/editor/CommunicatorContext.d.ts.map +1 -1
- package/dist/types/editor/ConfigurationContext.d.ts +2 -6
- package/dist/types/editor/ConfigurationContext.d.ts.map +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
- package/dist/types/editor/DictionariesRecordContext.d.ts +7 -11
- package/dist/types/editor/DictionariesRecordContext.d.ts.map +1 -1
- package/dist/types/editor/EditedContentContext.d.ts +25 -28
- package/dist/types/editor/EditedContentContext.d.ts.map +1 -1
- package/dist/types/editor/EditorEnabledContext.d.ts +4 -8
- package/dist/types/editor/EditorEnabledContext.d.ts.map +1 -1
- package/dist/types/editor/EditorProvider.d.ts +18 -6
- package/dist/types/editor/EditorProvider.d.ts.map +1 -1
- package/dist/types/editor/EditorStateContext.d.ts +12 -0
- package/dist/types/editor/EditorStateContext.d.ts.map +1 -0
- package/dist/types/editor/FocusDictionaryContext.d.ts +7 -16
- package/dist/types/editor/FocusDictionaryContext.d.ts.map +1 -1
- package/dist/types/editor/IntlayerEditorProvider.d.ts.map +1 -1
- package/dist/types/editor/index.d.ts +2 -1
- package/dist/types/editor/useCrossFrameMessageListener.d.ts +0 -16
- package/dist/types/editor/useCrossFrameMessageListener.d.ts.map +1 -1
- package/dist/types/editor/useCrossFrameState.d.ts +0 -21
- package/dist/types/editor/useCrossFrameState.d.ts.map +1 -1
- package/dist/types/editor/useCrossURLPathState.d.ts +2 -4
- package/dist/types/editor/useCrossURLPathState.d.ts.map +1 -1
- package/dist/types/editor/useEditedContentRenderer.d.ts.map +1 -1
- package/dist/types/editor/useIframeClickInterceptor.d.ts +1 -1
- package/dist/types/editor/useIframeClickInterceptor.d.ts.map +1 -1
- package/dist/types/html/HTMLProvider.d.ts.map +1 -1
- package/package.json +8 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorEnabledContext.cjs","names":["
|
|
1
|
+
{"version":3,"file":"EditorEnabledContext.cjs","names":["useEditorStateManager","MessageKey"],"sources":["../../../src/editor/EditorEnabledContext.tsx"],"sourcesContent":["import { MessageKey } from '@intlayer/editor';\nimport { useEffect, useState } from 'preact/hooks';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type EditorEnabledStateProps = {\n enabled: boolean;\n};\n\nexport const useEditorEnabled = (): EditorEnabledStateProps => {\n const manager = useEditorStateManager();\n const [enabled, setEnabled] = useState<boolean>(\n manager.editorEnabled.value ?? false\n );\n\n useEffect(() => {\n const handler = (e: Event) =>\n setEnabled((e as CustomEvent<boolean>).detail);\n manager.editorEnabled.addEventListener('change', handler);\n return () => manager.editorEnabled.removeEventListener('change', handler);\n }, [manager]);\n\n return { enabled };\n};\n\nexport const useEditorEnabledState = () => {\n const { enabled } = useEditorEnabled();\n const manager = useEditorStateManager();\n return [\n enabled,\n (value: boolean) => manager.editorEnabled.set(value),\n ] as const;\n};\n\nexport const useGetEditorEnabledState = () => {\n const manager = useEditorStateManager();\n return () => {\n manager.messenger.send(`${MessageKey.INTLAYER_EDITOR_ENABLED}/get`);\n };\n};\n\nexport const usePostEditorEnabledState = () => {\n const manager = useEditorStateManager();\n return () => manager.editorEnabled.postCurrentValue();\n};\n"],"mappings":"wNAQA,MAAa,MAAkD,CAC7D,IAAM,EAAUA,EAAAA,uBAAuB,CACjC,CAAC,EAAS,IAAA,EAAA,EAAA,UACd,EAAQ,cAAc,OAAS,GAChC,CASD,OAPA,EAAA,EAAA,eAAgB,CACd,IAAM,EAAW,GACf,EAAY,EAA2B,OAAO,CAEhD,OADA,EAAQ,cAAc,iBAAiB,SAAU,EAAQ,KAC5C,EAAQ,cAAc,oBAAoB,SAAU,EAAQ,EACxE,CAAC,EAAQ,CAAC,CAEN,CAAE,UAAS,EAGP,MAA8B,CACzC,GAAM,CAAE,WAAY,GAAkB,CAChC,EAAUA,EAAAA,uBAAuB,CACvC,MAAO,CACL,EACC,GAAmB,EAAQ,cAAc,IAAI,EAAM,CACrD,EAGU,MAAiC,CAC5C,IAAM,EAAUA,EAAAA,uBAAuB,CACvC,UAAa,CACX,EAAQ,UAAU,KAAK,GAAGC,EAAAA,WAAW,wBAAwB,MAAM,GAI1D,MAAkC,CAC7C,IAAM,EAAUD,EAAAA,uBAAuB,CACvC,UAAa,EAAQ,cAAc,kBAAkB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`./EditorStateContext.cjs`),n=require(`./EditorEnabledContext.cjs`);let r=require(`@intlayer/config/built`);r=e.__toESM(r);let i=require(`@intlayer/editor`),a=require(`preact/hooks`),o=require(`preact/jsx-runtime`);const{editor:s}=r.default??{},c=()=>({allowedOrigins:[s?.applicationURL,s?.editorURL,s?.cmsURL].filter(Boolean),postMessageFn:(e,t)=>{typeof window>`u`||window.self!==window.top&&(window.parent?.postMessage(e,t),window.postMessage(e,t))}}),l=({children:e,fallback:t})=>{let{enabled:r}=n.useEditorEnabled();return r?e:t},u=({children:e,fallback:t})=>{let[n,r]=(0,a.useState)(!1);return(0,a.useEffect)(()=>{r(window.self!==window.top)},[]),n?e:t},d=({children:e,mode:n=`client`,configuration:s,postMessage:d,allowedOrigins:f})=>{let p=(0,a.useRef)(null);p.current||=new i.EditorStateManager({mode:n,messenger:d||f?{allowedOrigins:f??[`*`],postMessageFn:d?e=>d(e):c().postMessageFn}:c(),configuration:s??r.default});let m=p.current;return(0,a.useEffect)(()=>((0,i.defineIntlayerElements)(),m.start(),()=>m.stop()),[m]),(0,o.jsx)(t.EditorStateProvider,{manager:m,children:n===`editor`?e:(0,o.jsx)(u,{fallback:e,children:(0,o.jsx)(l,{fallback:e,children:e})})})};exports.EditorProvider=d;
|
|
2
2
|
//# sourceMappingURL=EditorProvider.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorProvider.cjs","names":["
|
|
1
|
+
{"version":3,"file":"EditorProvider.cjs","names":["configuration","useEditorEnabled","EditorStateManager","EditorStateProvider"],"sources":["../../../src/editor/EditorProvider.tsx"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {\n defineIntlayerElements,\n EditorStateManager,\n type MessengerConfig,\n} from '@intlayer/editor';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { ComponentChildren, FunctionComponent } from 'preact';\nimport { useEffect, useRef, useState } from 'preact/hooks';\nimport { useEditorEnabled } from './EditorEnabledContext';\nimport { EditorStateProvider } from './EditorStateContext';\n\nconst { editor } = configuration ?? {};\n\nconst buildDefaultMessengerConfig = (): MessengerConfig => ({\n allowedOrigins: [\n editor?.applicationURL,\n editor?.editorURL,\n editor?.cmsURL,\n ].filter(Boolean) as string[],\n postMessageFn: (payload, origin) => {\n if (typeof window === 'undefined') return;\n const isInIframe = window.self !== window.top;\n if (!isInIframe) return;\n window.parent?.postMessage(payload, origin);\n window.postMessage(payload, origin);\n },\n});\n\ntype FallbackProps = {\n fallback: ComponentChildren;\n children?: ComponentChildren;\n};\n\nconst EditorEnabledCheckRenderer: FunctionComponent<FallbackProps> = ({\n children,\n fallback,\n}) => {\n const { enabled } = useEditorEnabled();\n return enabled ? children : fallback;\n};\n\nconst IframeCheckRenderer: FunctionComponent<FallbackProps> = ({\n children,\n fallback,\n}) => {\n const [isInIframe, setIsInIframe] = useState(false);\n\n useEffect(() => {\n setIsInIframe(window.self !== window.top);\n }, []);\n\n return isInIframe ? children : fallback;\n};\n\nexport type EditorProviderProps = {\n mode?: 'editor' | 'client';\n configuration?: IntlayerConfig;\n postMessage?: (data: any) => void;\n allowedOrigins?: string[];\n children?: ComponentChildren;\n};\n\nexport const EditorProvider: FunctionComponent<EditorProviderProps> = ({\n children,\n mode = 'client',\n configuration: configProp,\n postMessage: customPostMessage,\n allowedOrigins: customAllowedOrigins,\n}) => {\n const managerRef = useRef<EditorStateManager | null>(null);\n if (!managerRef.current) {\n const messengerConfig: MessengerConfig =\n customPostMessage || customAllowedOrigins\n ? {\n allowedOrigins: customAllowedOrigins ?? ['*'],\n postMessageFn: customPostMessage\n ? (payload) => customPostMessage(payload)\n : buildDefaultMessengerConfig().postMessageFn,\n }\n : buildDefaultMessengerConfig();\n managerRef.current = new EditorStateManager({\n mode,\n messenger: messengerConfig,\n configuration: configProp ?? configuration,\n });\n }\n const manager = managerRef.current;\n\n useEffect(() => {\n defineIntlayerElements();\n manager.start();\n return () => manager.stop();\n }, [manager]);\n\n const content =\n mode === 'editor' ? (\n children\n ) : (\n <IframeCheckRenderer fallback={children}>\n <EditorEnabledCheckRenderer fallback={children}>\n {children}\n </EditorEnabledCheckRenderer>\n </IframeCheckRenderer>\n );\n\n return <EditorStateProvider manager={manager}>{content}</EditorStateProvider>;\n};\n\n// Backward-compat types\nexport type CommunicatorProviderProps = {\n postMessage?: (data: any) => void;\n allowedOrigins?: string[];\n};\nexport type ConfigurationProviderProps = { configuration?: IntlayerConfig };\n"],"mappings":"yVAYA,KAAM,CAAE,UAAWA,EAAAA,SAAiB,EAAE,CAEhC,OAAsD,CAC1D,eAAgB,CACd,GAAQ,eACR,GAAQ,UACR,GAAQ,OACT,CAAC,OAAO,QAAQ,CACjB,eAAgB,EAAS,IAAW,CAC9B,OAAO,OAAW,KACH,OAAO,OAAS,OAAO,MAE1C,OAAO,QAAQ,YAAY,EAAS,EAAO,CAC3C,OAAO,YAAY,EAAS,EAAO,GAEtC,EAOK,GAAgE,CACpE,WACA,cACI,CACJ,GAAM,CAAE,WAAYC,EAAAA,kBAAkB,CACtC,OAAO,EAAU,EAAW,GAGxB,GAAyD,CAC7D,WACA,cACI,CACJ,GAAM,CAAC,EAAY,IAAA,EAAA,EAAA,UAA0B,GAAM,CAMnD,OAJA,EAAA,EAAA,eAAgB,CACd,EAAc,OAAO,OAAS,OAAO,IAAI,EACxC,EAAE,CAAC,CAEC,EAAa,EAAW,GAWpB,GAA0D,CACrE,WACA,OAAO,SACP,cAAe,EACf,YAAa,EACb,eAAgB,KACZ,CACJ,IAAM,GAAA,EAAA,EAAA,QAA+C,KAAK,CAC1D,AAUE,EAAW,UAAU,IAAIC,EAAAA,mBAAmB,CAC1C,OACA,UAVA,GAAqB,EACjB,CACE,eAAgB,GAAwB,CAAC,IAAI,CAC7C,cAAe,EACV,GAAY,EAAkB,EAAQ,CACvC,GAA6B,CAAC,cACnC,CACD,GAA6B,CAIjC,cAAe,GAAcF,EAAAA,QAC9B,CAAC,CAEJ,IAAM,EAAU,EAAW,QAmB3B,OAjBA,EAAA,EAAA,iBACE,EAAA,EAAA,yBAAwB,CACxB,EAAQ,OAAO,KACF,EAAQ,MAAM,EAC1B,CAAC,EAAQ,CAAC,EAaN,EAAA,EAAA,KAACG,EAAAA,oBAAD,CAA8B,mBAVnC,IAAS,SACP,GAEA,EAAA,EAAA,KAAC,EAAD,CAAqB,SAAU,YAC7B,EAAA,EAAA,KAAC,EAAD,CAA4B,SAAU,EACnC,WAC0B,CAAA,CACT,CAAA,CAGmD,CAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`preact`),t=require(`preact/hooks`),n=require(`preact/jsx-runtime`);const r=(0,e.createContext)(null),i=({manager:e,children:t})=>(0,n.jsx)(r.Provider,{value:e,children:t}),a=()=>{let e=(0,t.useContext)(r);if(!e)throw Error(`useEditorStateManager: no EditorStateProvider found`);return e};exports.EditorStateProvider=i,exports.useEditorStateManager=a;
|
|
2
|
+
//# sourceMappingURL=EditorStateContext.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EditorStateContext.cjs","names":[],"sources":["../../../src/editor/EditorStateContext.tsx"],"sourcesContent":["import type { EditorStateManager } from '@intlayer/editor';\nimport {\n type ComponentChildren,\n createContext,\n type FunctionComponent,\n} from 'preact';\nimport { useContext } from 'preact/hooks';\n\nconst EditorStateContext = createContext<EditorStateManager | null>(null);\n\nexport const EditorStateProvider: FunctionComponent<{\n manager: EditorStateManager;\n children?: ComponentChildren;\n}> = ({ manager, children }) => (\n <EditorStateContext.Provider value={manager}>\n {children}\n </EditorStateContext.Provider>\n);\n\nexport const useEditorStateManager = (): EditorStateManager => {\n const ctx = useContext(EditorStateContext);\n if (!ctx)\n throw new Error('useEditorStateManager: no EditorStateProvider found');\n return ctx;\n};\n"],"mappings":"kMAQA,MAAM,GAAA,EAAA,EAAA,eAA8D,KAAK,CAE5D,GAGP,CAAE,UAAS,eACf,EAAA,EAAA,KAAC,EAAmB,SAApB,CAA6B,MAAO,EACjC,WAC2B,CAAA,CAGnB,MAAkD,CAC7D,IAAM,GAAA,EAAA,EAAA,YAAiB,EAAmB,CAC1C,GAAI,CAAC,EACH,MAAU,MAAM,sDAAsD,CACxE,OAAO"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./EditorStateContext.cjs`);let t=require(`preact/hooks`);const n=()=>{let n=e.useEditorStateManager(),[r,i]=(0,t.useState)(n.focusedContent.value??null);return(0,t.useEffect)(()=>{let e=e=>i(e.detail);return n.focusedContent.addEventListener(`change`,e),()=>n.focusedContent.removeEventListener(`change`,e)},[n]),{focusedContent:r,setFocusedContent:e=>n.focusedContent.set(e),setFocusedContentKeyPath:e=>n.setFocusedContentKeyPath(e)}},r=()=>{let{setFocusedContent:e,setFocusedContentKeyPath:t}=n();return{setFocusedContent:e,setFocusedContentKeyPath:t}};exports.useFocusDictionary=n,exports.useFocusDictionaryActions=r;
|
|
2
2
|
//# sourceMappingURL=FocusDictionaryContext.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusDictionaryContext.cjs","names":["
|
|
1
|
+
{"version":3,"file":"FocusDictionaryContext.cjs","names":["useEditorStateManager"],"sources":["../../../src/editor/FocusDictionaryContext.tsx"],"sourcesContent":["import type { FileContent } from '@intlayer/editor';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport { useEffect, useState } from 'preact/hooks';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type { FileContent };\n\nexport const useFocusDictionary = () => {\n const manager = useEditorStateManager();\n const [focusedContent, setFocusedContentState] = useState<FileContent | null>(\n manager.focusedContent.value ?? null\n );\n\n useEffect(() => {\n const handler = (e: Event) =>\n setFocusedContentState((e as CustomEvent<FileContent | null>).detail);\n manager.focusedContent.addEventListener('change', handler);\n return () => manager.focusedContent.removeEventListener('change', handler);\n }, [manager]);\n\n return {\n focusedContent,\n setFocusedContent: (value: FileContent | null) =>\n manager.focusedContent.set(value),\n setFocusedContentKeyPath: (keyPath: KeyPath[]) =>\n manager.setFocusedContentKeyPath(keyPath),\n };\n};\n\nexport const useFocusDictionaryActions = () => {\n const { setFocusedContent, setFocusedContentKeyPath } = useFocusDictionary();\n return { setFocusedContent, setFocusedContentKeyPath };\n};\n"],"mappings":"0LAOA,MAAa,MAA2B,CACtC,IAAM,EAAUA,EAAAA,uBAAuB,CACjC,CAAC,EAAgB,IAAA,EAAA,EAAA,UACrB,EAAQ,eAAe,OAAS,KACjC,CASD,OAPA,EAAA,EAAA,eAAgB,CACd,IAAM,EAAW,GACf,EAAwB,EAAsC,OAAO,CAEvE,OADA,EAAQ,eAAe,iBAAiB,SAAU,EAAQ,KAC7C,EAAQ,eAAe,oBAAoB,SAAU,EAAQ,EACzE,CAAC,EAAQ,CAAC,CAEN,CACL,iBACA,kBAAoB,GAClB,EAAQ,eAAe,IAAI,EAAM,CACnC,yBAA2B,GACzB,EAAQ,yBAAyB,EAAQ,CAC5C,EAGU,MAAkC,CAC7C,GAAM,CAAE,oBAAmB,4BAA6B,GAAoB,CAC5E,MAAO,CAAE,oBAAmB,2BAA0B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./EditorProvider.cjs`);let t=require(`preact/jsx-runtime`);const n=({children:n})=>(0,t.jsx)(e.EditorProvider,{mode:`client`,children:n});exports.IntlayerEditorProvider=n;
|
|
2
2
|
//# sourceMappingURL=IntlayerEditorProvider.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerEditorProvider.cjs","names":["
|
|
1
|
+
{"version":3,"file":"IntlayerEditorProvider.cjs","names":["EditorProvider"],"sources":["../../../src/editor/IntlayerEditorProvider.tsx"],"sourcesContent":["import type { ComponentChildren, FunctionComponent } from 'preact';\nimport { EditorProvider } from './EditorProvider';\n\nexport const IntlayerEditorProvider: FunctionComponent<{\n children?: ComponentChildren;\n}> = ({ children }) => (\n <EditorProvider mode=\"client\">{children}</EditorProvider>\n);\n"],"mappings":"4LAGA,MAAa,GAEP,CAAE,eACN,EAAA,EAAA,KAACA,EAAAA,eAAD,CAAgB,KAAK,SAAU,WAA0B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./ContentSelectorWrapper.cjs`);exports.ContentSelectorRenderer=e.
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./EditorStateContext.cjs`),t=require(`./ContentSelectorWrapper.cjs`);exports.ContentSelectorRenderer=t.ContentSelectorRenderer,exports.EditorStateProvider=e.EditorStateProvider,exports.useEditorStateManager=e.useEditorStateManager;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./EditorStateContext.cjs`);let t=require(`preact/hooks`);const n=(n,r,i)=>{let a=e.useEditorStateManager();return(0,t.useEffect)(()=>{if(r)return a.messenger.subscribe(n,r)},[a,n,i]),e=>a.messenger.send(n,e)};exports.useCrossFrameMessageListener=n;
|
|
2
2
|
//# sourceMappingURL=useCrossFrameMessageListener.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrossFrameMessageListener.cjs","names":["
|
|
1
|
+
{"version":3,"file":"useCrossFrameMessageListener.cjs","names":["useEditorStateManager"],"sources":["../../../src/editor/useCrossFrameMessageListener.tsx"],"sourcesContent":["import type { MessageKey } from '@intlayer/editor';\nimport { useEffect } from 'preact/hooks';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport const useCrossFrameMessageListener = <S,>(\n key: `${MessageKey}` | `${MessageKey}/post` | `${MessageKey}/get`,\n onEventTriggered?: (data: S) => void,\n revalidator?: any\n) => {\n const manager = useEditorStateManager();\n\n useEffect(() => {\n if (!onEventTriggered) return;\n return manager.messenger.subscribe<S>(key, onEventTriggered);\n }, [manager, key, revalidator]);\n\n return (data?: S) => manager.messenger.send(key, data);\n};\n"],"mappings":"0LAIA,MAAa,GACX,EACA,EACA,IACG,CACH,IAAM,EAAUA,EAAAA,uBAAuB,CAOvC,OALA,EAAA,EAAA,eAAgB,CACT,KACL,OAAO,EAAQ,UAAU,UAAa,EAAK,EAAiB,EAC3D,CAAC,EAAS,EAAK,EAAY,CAAC,CAEvB,GAAa,EAAQ,UAAU,KAAK,EAAK,EAAK"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./EditorStateContext.cjs`);let t=require(`@intlayer/editor`),n=require(`preact/hooks`);const r=(r,i,a)=>{let o=e.useEditorStateManager(),s=typeof i==`function`?i():i,[c,l]=(0,n.useState)(s),u=(0,n.useRef)(null);return(0,n.useEffect)(()=>{let{emit:e=!0,receive:n=!0}=a??{},i=new t.CrossFrameStateManager(r,o.messenger,{emit:e,receive:n,initialValue:s});u.current=i;let c=e=>{l(e.detail)};return i.addEventListener(`change`,c),i.start(),()=>{i.removeEventListener(`change`,c),i.stop(),u.current=null}},[r,o.messenger,a?.emit,a?.receive]),[c,e=>{l(t=>{let n=typeof e==`function`?e(t):e;return u.current?.set(n),n})},()=>u.current?.postCurrentValue()]};exports.useCrossFrameState=r;
|
|
2
2
|
//# sourceMappingURL=useCrossFrameState.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrossFrameState.cjs","names":["
|
|
1
|
+
{"version":3,"file":"useCrossFrameState.cjs","names":["useEditorStateManager","CrossFrameStateManager"],"sources":["../../../src/editor/useCrossFrameState.tsx"],"sourcesContent":["import { CrossFrameStateManager, type MessageKey } from '@intlayer/editor';\nimport {\n type Dispatch,\n type StateUpdater,\n useEffect,\n useRef,\n useState,\n} from 'preact/hooks';\nimport { useEditorStateManager } from './EditorStateContext';\n\nexport type CrossFrameStateOptions = {\n emit?: boolean;\n receive?: boolean;\n};\n\nexport type SetStateAction<S> = S | ((prevState: S) => S);\nexport type CrossFrameStateUpdater<S> = (value: SetStateAction<S>) => void;\n\nexport const useCrossFrameState = <S,>(\n key: `${MessageKey}`,\n initialState?: S | (() => S),\n options?: CrossFrameStateOptions\n): [S, CrossFrameStateUpdater<S>, () => void] => {\n const manager = useEditorStateManager();\n\n const resolvedInitial =\n typeof initialState === 'function'\n ? (initialState as () => S)()\n : initialState;\n\n const [value, setValueState] = useState<S>(resolvedInitial as S);\n const stateManagerRef = useRef<CrossFrameStateManager<S> | null>(null);\n\n useEffect(() => {\n const { emit = true, receive = true } = options ?? {};\n const stateManager = new CrossFrameStateManager<S>(key, manager.messenger, {\n emit,\n receive,\n initialValue: resolvedInitial,\n });\n stateManagerRef.current = stateManager;\n\n const handler = (e: Event) => {\n setValueState((e as CustomEvent<S>).detail);\n };\n stateManager.addEventListener('change', handler);\n stateManager.start();\n\n return () => {\n stateManager.removeEventListener('change', handler);\n stateManager.stop();\n stateManagerRef.current = null;\n };\n }, [key, manager.messenger, options?.emit, options?.receive]);\n\n const setValue: CrossFrameStateUpdater<S> = (valueOrUpdater) => {\n setValueState((prev) => {\n const newValue =\n typeof valueOrUpdater === 'function'\n ? (valueOrUpdater as (prev: S) => S)(prev)\n : valueOrUpdater;\n stateManagerRef.current?.set(newValue);\n return newValue;\n });\n };\n\n const postState = () => stateManagerRef.current?.postCurrentValue();\n\n return [value, setValue, postState];\n};\n"],"mappings":"wNAkBA,MAAa,GACX,EACA,EACA,IAC+C,CAC/C,IAAM,EAAUA,EAAAA,uBAAuB,CAEjC,EACJ,OAAO,GAAiB,WACnB,GAA0B,CAC3B,EAEA,CAAC,EAAO,IAAA,EAAA,EAAA,UAA6B,EAAqB,CAC1D,GAAA,EAAA,EAAA,QAA2D,KAAK,CAqCtE,OAnCA,EAAA,EAAA,eAAgB,CACd,GAAM,CAAE,OAAO,GAAM,UAAU,IAAS,GAAW,EAAE,CAC/C,EAAe,IAAIC,EAAAA,uBAA0B,EAAK,EAAQ,UAAW,CACzE,OACA,UACA,aAAc,EACf,CAAC,CACF,EAAgB,QAAU,EAE1B,IAAM,EAAW,GAAa,CAC5B,EAAe,EAAqB,OAAO,EAK7C,OAHA,EAAa,iBAAiB,SAAU,EAAQ,CAChD,EAAa,OAAO,KAEP,CACX,EAAa,oBAAoB,SAAU,EAAQ,CACnD,EAAa,MAAM,CACnB,EAAgB,QAAU,OAE3B,CAAC,EAAK,EAAQ,UAAW,GAAS,KAAM,GAAS,QAAQ,CAAC,CAetD,CAAC,EAbqC,GAAmB,CAC9D,EAAe,GAAS,CACtB,IAAM,EACJ,OAAO,GAAmB,WACrB,EAAkC,EAAK,CACxC,EAEN,OADA,EAAgB,SAAS,IAAI,EAAS,CAC/B,GACP,MAGoB,EAAgB,SAAS,kBAAkB,CAEhC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=()=>{},t=()=>{};exports.useCrossURLPathSetter=e,exports.useCrossURLPathState=t;
|
|
2
2
|
//# sourceMappingURL=useCrossURLPathState.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCrossURLPathState.cjs","names":[
|
|
1
|
+
{"version":3,"file":"useCrossURLPathState.cjs","names":[],"sources":["../../../src/editor/useCrossURLPathState.tsx"],"sourcesContent":["// UrlStateManager is started by EditorStateManager.start() in client mode.\n// Nothing extra needed here.\nexport const useCrossURLPathSetter = () => {\n // No-op: managed by EditorStateManager\n};\n\nexport const useCrossURLPathState = () => {\n // No-op: managed by EditorStateManager\n};\n"],"mappings":"mEAEA,MAAa,MAA8B,GAI9B,MAA6B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./EditedContentContext.cjs`);let t=require(`@intlayer/core/interpreter`);const n=({dictionaryKey:t,keyPath:n,children:r})=>{let i=e.useEditedContentActions();return i?i.getEditedContentValue(t,n)??r:r},r=e=>{let r=n(e);if(typeof r==`object`){let n=(0,t.getContent)(r,{...e,locale:e.locale},(0,t.getBasePlugins)(e.locale));return typeof n==`string`?n:(console.error(`Incorrect edited content format. Content type: ${typeof n}. Expected string. Value ${JSON.stringify(n)}`),e.children)}return r};exports.EditedContentRenderer=r,exports.useEditedContentRenderer=n;
|
|
2
2
|
//# sourceMappingURL=useEditedContentRenderer.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditedContentRenderer.cjs","names":["useEditedContentActions"],"sources":["../../../src/editor/useEditedContentRenderer.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useEditedContentRenderer.cjs","names":["useEditedContentActions"],"sources":["../../../src/editor/useEditedContentRenderer.tsx"],"sourcesContent":["import { getBasePlugins, getContent } from '@intlayer/core/interpreter';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { FunctionalComponent } from 'preact';\nimport { useEditedContentActions } from './EditedContentContext';\n\ntype EditedContentRendererProps = {\n dictionaryKey: Dictionary['key'];\n keyPath: KeyPath[];\n children: string;\n locale?: Locale;\n};\n\nexport const useEditedContentRenderer = ({\n dictionaryKey,\n keyPath,\n children,\n}: EditedContentRendererProps) => {\n const editedContentContext = useEditedContentActions();\n\n if (editedContentContext) {\n const editedValue = editedContentContext.getEditedContentValue(\n dictionaryKey,\n keyPath\n ) as string;\n\n const value = editedValue ?? children;\n\n return value;\n }\n\n return children;\n};\n\nexport const EditedContentRenderer: FunctionalComponent<\n EditedContentRendererProps\n> = (props) => {\n const content = useEditedContentRenderer(props);\n\n if (typeof content === 'object') {\n const transformedEditedContent = getContent(\n content,\n { ...props, locale: props.locale },\n getBasePlugins(props.locale)\n );\n\n if (typeof transformedEditedContent !== 'string') {\n console.error(\n `Incorrect edited content format. Content type: ${typeof transformedEditedContent}. Expected string. Value ${JSON.stringify(transformedEditedContent)}`\n );\n\n return props.children;\n }\n\n return transformedEditedContent;\n }\n\n return content;\n};\n"],"mappings":"0MAcA,MAAa,GAA4B,CACvC,gBACA,UACA,cACgC,CAChC,IAAM,EAAuBA,EAAAA,yBAAyB,CAatD,OAXI,EACkB,EAAqB,sBACvC,EACA,EACD,EAE4B,EAKxB,GAGI,EAER,GAAU,CACb,IAAM,EAAU,EAAyB,EAAM,CAE/C,GAAI,OAAO,GAAY,SAAU,CAC/B,IAAM,GAAA,EAAA,EAAA,YACJ,EACA,CAAE,GAAG,EAAO,OAAQ,EAAM,OAAQ,EAAA,EAAA,EAAA,gBACnB,EAAM,OAAO,CAC7B,CAUD,OARI,OAAO,GAA6B,SAQjC,GAPL,QAAQ,MACN,kDAAkD,OAAO,EAAyB,2BAA2B,KAAK,UAAU,EAAyB,GACtJ,CAEM,EAAM,UAMjB,OAAO"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./useCrossFrameMessageListener.cjs`);let t=require(`@intlayer/editor`);const n=()=>{e.useCrossFrameMessageListener(t.MessageKey.INTLAYER_IFRAME_CLICKED)},r=()=>{e.useCrossFrameMessageListener(t.MessageKey.INTLAYER_IFRAME_CLICKED,t.mergeIframeClick)};exports.useIframeClickInterceptor=n,exports.useIframeClickMerger=r;
|
|
2
2
|
//# sourceMappingURL=useIframeClickInterceptor.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIframeClickInterceptor.cjs","names":["
|
|
1
|
+
{"version":3,"file":"useIframeClickInterceptor.cjs","names":["MessageKey","mergeIframeClick"],"sources":["../../../src/editor/useIframeClickInterceptor.tsx"],"sourcesContent":["import { MessageKey, mergeIframeClick } from '@intlayer/editor';\nimport { useCrossFrameMessageListener } from './useCrossFrameMessageListener';\n\nexport const useIframeClickInterceptor = () => {\n useCrossFrameMessageListener<undefined>(MessageKey.INTLAYER_IFRAME_CLICKED);\n};\n\nexport const useIframeClickMerger = () => {\n useCrossFrameMessageListener<MessageEvent>(\n MessageKey.INTLAYER_IFRAME_CLICKED,\n mergeIframeClick\n );\n};\n"],"mappings":"wMAGA,MAAa,MAAkC,CAC7C,EAAA,6BAAwCA,EAAAA,WAAW,wBAAwB,EAGhE,MAA6B,CACxC,EAAA,6BACEA,EAAAA,WAAW,wBACXC,EAAAA,iBACD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);let e=require(`preact`),t=require(`preact/hooks`),n=require(`preact/jsx-runtime`);const r=(0,e.createContext)(void 0),i=()=>(0,t.useContext)(r),a=({children:e,components:t})=>(0,n.jsx)(r.Provider,{value:{components:t},children:e});exports.HTMLProvider=a,exports.useHTMLContext=i;
|
|
2
2
|
//# sourceMappingURL=HTMLProvider.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HTMLProvider.cjs","names":[],"sources":["../../../src/html/HTMLProvider.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"HTMLProvider.cjs","names":[],"sources":["../../../src/html/HTMLProvider.tsx"],"sourcesContent":["import {\n createContext,\n type FunctionalComponent,\n type RenderableProps,\n} from 'preact';\nimport { useContext } from 'preact/hooks';\nimport type { HTMLComponents } from './types';\n\ntype HTMLContextValue = {\n components?: HTMLComponents<'permissive', {}>;\n};\n\ntype HTMLProviderProps = RenderableProps<{\n /**\n * Component overrides for HTML tags.\n */\n components?: HTMLComponents<'permissive', {}>;\n}>;\n\nconst HTMLContext = createContext<HTMLContextValue | undefined>(undefined);\n\nexport const useHTMLContext = () => useContext(HTMLContext);\n\nexport const HTMLProvider: FunctionalComponent<HTMLProviderProps> = ({\n children,\n components,\n}) => (\n <HTMLContext.Provider value={{ components }}>{children}</HTMLContext.Provider>\n);\n"],"mappings":"kMAmBA,MAAM,GAAA,EAAA,EAAA,eAA0D,IAAA,GAAU,CAE7D,OAAA,EAAA,EAAA,YAAkC,EAAY,CAE9C,GAAwD,CACnE,WACA,iBAEA,EAAA,EAAA,KAAC,EAAY,SAAb,CAAsB,MAAO,CAAE,aAAY,CAAG,WAAgC,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{useCallback as e,useEffect as t,useRef as n,useState as r}from"preact/hooks";import{jsx as i}from"preact/jsx-runtime";const a=({children:a,onPress:o,onHover:s,onUnhover:c,onClickOutside:l,pressDuration:u=250,isSelecting:d,...f})=>{let p=n(null),[m,h]=r(!1),[g,_]=r(d),v=n(null),y=typeof a==`string`,b=()=>{_(!0),o()},x=()=>{v.current=setTimeout(()=>{b()},u)},S=()=>{v.current&&=(clearTimeout(v.current),null)},C=()=>{S(),x()},w=()=>{h(!0),s?.()},T=()=>{m&&(h(!1),c?.()),S()},E=e(e=>{p.current&&!p.current.contains(e.target)&&(_(!1),l?.())},[l]);return t(()=>(document.addEventListener(`mousedown`,E),()=>{document.removeEventListener(`mousedown`,E)}),[E]),i(`span`,{style:{display:y?`inline`:`inline-block`,cursor:`pointer`,userSelect:`none`,borderRadius:`0.375rem`,outlineWidth:`2px`,outlineOffset:`4px`,outlineStyle:`solid`,outlineColor:d||g||m?`inherit`:`transparent`,transition:`all 100ms 50ms ease-in-out`},role:`button`,tabIndex:0,onKeyUp:()=>null,onClick:e=>{g&&(e.preventDefault(),e.stopPropagation())},onMouseDown:C,onMouseUp:T,onMouseLeave:T,onTouchStart:C,onTouchEnd:T,onTouchCancel:T,onBlur:()=>{_(!1)},onMouseEnter:w,ref:p,...f,children:a})};export{a as ContentSelector};
|
|
2
2
|
//# sourceMappingURL=ContentSelector.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSelector.mjs","names":[],"sources":["../../../src/UI/ContentSelector.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"ContentSelector.mjs","names":[],"sources":["../../../src/UI/ContentSelector.tsx"],"sourcesContent":["import type { FunctionalComponent, JSX } from 'preact';\nimport { useCallback, useEffect, useRef, useState } from 'preact/hooks';\n\nconst DEFAULT_PRESS_DETECT_DURATION = 250;\n\ntype ContentSelectorProps = {\n onPress: () => void;\n onHover?: () => void;\n onUnhover?: () => void;\n onClickOutside?: () => void;\n pressDuration?: number;\n isSelecting?: boolean;\n} & Omit<JSX.HTMLAttributes<HTMLDivElement>, 'content'>;\n\nexport const ContentSelector: FunctionalComponent<ContentSelectorProps> = ({\n children,\n onPress: onSelect,\n onHover,\n onUnhover,\n onClickOutside: onUnselect,\n pressDuration = DEFAULT_PRESS_DETECT_DURATION,\n isSelecting: isSelectingProp,\n ...props\n}) => {\n const divRef = useRef<HTMLDivElement>(null);\n const [isHovered, setIsHovered] = useState(false);\n const [isSelectingState, setIsSelectingState] = useState(isSelectingProp);\n const pressTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const isChildrenString = typeof children === 'string';\n\n const handleOnLongPress = () => {\n setIsSelectingState(true);\n onSelect();\n };\n\n const startPressTimer = () => {\n pressTimerRef.current = setTimeout(() => {\n handleOnLongPress();\n }, pressDuration);\n };\n\n const clearPressTimer = () => {\n if (pressTimerRef.current) {\n clearTimeout(pressTimerRef.current);\n pressTimerRef.current = null;\n }\n };\n\n const handleMouseDown = () => {\n clearPressTimer(); // Ensure any previous timer is cleared\n startPressTimer();\n };\n\n const handleMouseEnter = () => {\n setIsHovered(true);\n onHover?.();\n };\n\n const handleMouseUp = () => {\n if (isHovered) {\n setIsHovered(false);\n onUnhover?.();\n }\n clearPressTimer();\n };\n\n // Use useCallback to ensure the function identity remains stable\n const handleClickOutside = useCallback(\n (event: MouseEvent) => {\n if (divRef.current && !divRef.current.contains(event.target as Node)) {\n setIsSelectingState(false);\n onUnselect?.();\n }\n },\n [onUnselect]\n );\n\n useEffect(() => {\n // Attach click outside listener\n document.addEventListener('mousedown', handleClickOutside);\n\n return () => {\n // Cleanup\n document.removeEventListener('mousedown', handleClickOutside);\n // clearPressTimer(); // Ensure to clear the timer when component unmounts\n };\n }, [handleClickOutside]);\n\n const handleOnClick: JSX.MouseEventHandler<HTMLDivElement> = (e) => {\n if (isSelectingState) {\n e.preventDefault();\n e.stopPropagation();\n }\n };\n\n const handleOnBlur = () => {\n // Stop editing when the element loses focus\n setIsSelectingState(false);\n };\n\n return (\n <span\n style={{\n display: isChildrenString ? 'inline' : 'inline-block',\n cursor: 'pointer',\n userSelect: 'none',\n borderRadius: '0.375rem',\n outlineWidth: '2px',\n outlineOffset: '4px',\n outlineStyle: 'solid',\n outlineColor:\n isSelectingProp || isSelectingState || isHovered\n ? 'inherit'\n : 'transparent',\n transition: 'all 100ms 50ms ease-in-out',\n }}\n role=\"button\"\n tabIndex={0}\n onKeyUp={() => null}\n onClick={handleOnClick}\n onMouseDown={handleMouseDown}\n onMouseUp={handleMouseUp}\n onMouseLeave={handleMouseUp}\n onTouchStart={handleMouseDown}\n onTouchEnd={handleMouseUp}\n onTouchCancel={handleMouseUp}\n onBlur={handleOnBlur}\n onMouseEnter={handleMouseEnter}\n ref={divRef}\n {...props}\n >\n {children}\n </span>\n );\n};\n"],"mappings":"6HAGA,MAWa,GAA8D,CACzE,WACA,QAAS,EACT,UACA,YACA,eAAgB,EAChB,gBAAgB,IAChB,YAAa,EACb,GAAG,KACC,CACJ,IAAM,EAAS,EAAuB,KAAK,CACrC,CAAC,EAAW,GAAgB,EAAS,GAAM,CAC3C,CAAC,EAAkB,GAAuB,EAAS,EAAgB,CACnE,EAAgB,EAA6C,KAAK,CAClE,EAAmB,OAAO,GAAa,SAEvC,MAA0B,CAC9B,EAAoB,GAAK,CACzB,GAAU,EAGN,MAAwB,CAC5B,EAAc,QAAU,eAAiB,CACvC,GAAmB,EAClB,EAAc,EAGb,MAAwB,CAC5B,AAEE,EAAc,WADd,aAAa,EAAc,QAAQ,CACX,OAItB,MAAwB,CAC5B,GAAiB,CACjB,GAAiB,EAGb,MAAyB,CAC7B,EAAa,GAAK,CAClB,KAAW,EAGP,MAAsB,CACtB,IACF,EAAa,GAAM,CACnB,KAAa,EAEf,GAAiB,EAIb,EAAqB,EACxB,GAAsB,CACjB,EAAO,SAAW,CAAC,EAAO,QAAQ,SAAS,EAAM,OAAe,GAClE,EAAoB,GAAM,CAC1B,KAAc,GAGlB,CAAC,EAAW,CACb,CAyBD,OAvBA,OAEE,SAAS,iBAAiB,YAAa,EAAmB,KAE7C,CAEX,SAAS,oBAAoB,YAAa,EAAmB,GAG9D,CAAC,EAAmB,CAAC,CAetB,EAAC,OAAD,CACE,MAAO,CACL,QAAS,EAAmB,SAAW,eACvC,OAAQ,UACR,WAAY,OACZ,aAAc,WACd,aAAc,MACd,cAAe,MACf,aAAc,QACd,aACE,GAAmB,GAAoB,EACnC,UACA,cACN,WAAY,6BACb,CACD,KAAK,SACL,SAAU,EACV,YAAe,KACf,QA/B0D,GAAM,CAC9D,IACF,EAAE,gBAAgB,CAClB,EAAE,iBAAiB,GA6BnB,YAAa,EACb,UAAW,EACX,aAAc,EACd,aAAc,EACd,WAAY,EACZ,cAAe,EACf,WA/BuB,CAEzB,EAAoB,GAAM,EA8BxB,aAAc,EACd,IAAK,EACL,GAAI,EAEH,WACI,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{IntlayerEditorProvider as e}from"../editor/IntlayerEditorProvider.mjs";import{useCrossFrameState as t}from"../editor/useCrossFrameState.mjs";import{localeInStorage as n,setLocaleInStorage as r}from"./useLocaleStorage.mjs";import i from"@intlayer/config/built";import{createContext as a}from"preact";import{MessageKey as o}from"@intlayer/editor";import{useContext as s,useEffect as c}from"preact/hooks";import{localeResolver as l}from"@intlayer/core/localization";import{jsx as u}from"preact/jsx-runtime";const d=a({locale:n??i?.internationalization?.defaultLocale,setLocale:()=>null,disableEditor:!1}),f=()=>s(d),p=({locale:e,defaultLocale:a,children:s,setLocale:f,disableEditor:p,isCookieEnabled:m})=>{let{internationalization:h}=i??{},{defaultLocale:g,locales:_}=h??{},v=e??n??a??g,[y,b]=t(o.INTLAYER_CURRENT_LOCALE,v);c(()=>{e&&e!==y&&b(e)},[e,y,b]);let x=f??(e=>{if(y.toString()!==e.toString()){if(!_?.map(String).includes(e)){console.error(`Locale ${e} is not available`);return}b(e),r(e,m??!0)}}),S=l(e??y);return u(d.Provider,{value:{locale:S,setLocale:x,disableEditor:p,isCookieEnabled:m},children:s})},m=t=>u(e,{children:u(p,{...t})});export{d as IntlayerClientContext,m as IntlayerProvider,p as IntlayerProviderContent,f as useIntlayerContext};
|
|
2
2
|
//# sourceMappingURL=IntlayerProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerProvider.mjs","names":[],"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"IntlayerProvider.mjs","names":[],"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { localeResolver } from '@intlayer/core/localization';\nimport { MessageKey } from '@intlayer/editor';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport {\n type ComponentChild,\n createContext,\n type FunctionComponent,\n} from 'preact';\nimport { useContext, useEffect } from 'preact/hooks';\nimport { IntlayerEditorProvider } from '../editor/IntlayerEditorProvider';\nimport { useCrossFrameState } from '../editor/useCrossFrameState';\nimport { localeInStorage, setLocaleInStorage } from './useLocaleStorage';\n\ntype IntlayerValue = {\n locale: LocalesValues;\n setLocale: (newLocale: LocalesValues) => void;\n disableEditor?: boolean;\n isCookieEnabled?: boolean;\n};\n\n/**\n * Context that store the current locale on the client side\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeInStorage ?? configuration?.internationalization?.defaultLocale,\n setLocale: () => null,\n disableEditor: false,\n});\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\nexport type IntlayerProviderProps = {\n children?: ComponentChild;\n locale?: LocalesValues;\n defaultLocale?: LocalesValues;\n setLocale?: (locale: LocalesValues) => void;\n disableEditor?: boolean;\n isCookieEnabled?: boolean;\n};\n\n/**\n * Provider that store the current locale on the client side\n */\nexport const IntlayerProviderContent: FunctionComponent<\n IntlayerProviderProps\n> = ({\n locale: localeProp,\n defaultLocale: defaultLocaleProp,\n children,\n setLocale: setLocaleProp,\n disableEditor,\n isCookieEnabled,\n}) => {\n const { internationalization } = configuration ?? {};\n const { defaultLocale: defaultLocaleConfig, locales: availableLocales } =\n internationalization ?? {};\n\n const defaultLocale =\n localeProp ?? localeInStorage ?? defaultLocaleProp ?? defaultLocaleConfig;\n\n const [currentLocale, setCurrentLocale] = useCrossFrameState(\n MessageKey.INTLAYER_CURRENT_LOCALE,\n defaultLocale\n );\n\n useEffect(() => {\n if (localeProp && localeProp !== currentLocale) {\n setCurrentLocale(localeProp);\n }\n }, [localeProp, currentLocale, setCurrentLocale]);\n\n const setLocaleBase = (newLocale: LocalesValues) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales?.map(String).includes(newLocale)) {\n console.error(`Locale ${newLocale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale); // Update state\n setLocaleInStorage(newLocale, isCookieEnabled ?? true); // Optionally set cookie for persistence\n };\n\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n const resolvedLocale = localeResolver(localeProp ?? currentLocale);\n\n return (\n <IntlayerClientContext.Provider\n value={{\n locale: resolvedLocale,\n setLocale,\n disableEditor,\n isCookieEnabled,\n }}\n >\n {children}\n </IntlayerClientContext.Provider>\n );\n};\n\n/**\n * Main provider for Intlayer in Preact applications.\n *\n * It provides the Intlayer context to your application, allowing the use\n * of hooks like `useIntlayer` and `useLocale`.\n *\n * @param props - The provider props.\n * @returns The provider component.\n *\n * @example\n * ```tsx\n * import { IntlayerProvider } from 'preact-intlayer';\n *\n * const App = () => (\n * <IntlayerProvider>\n * <MyComponent />\n * </IntlayerProvider>\n * );\n * ```\n */\nexport const IntlayerProvider: FunctionComponent<IntlayerProviderProps> = (\n props\n) => (\n <IntlayerEditorProvider>\n <IntlayerProviderContent {...props} />\n </IntlayerEditorProvider>\n);\n"],"mappings":"+fAwBA,MAAa,EAAwB,EAA6B,CAChE,OAAQ,GAAmB,GAAe,sBAAsB,cAChE,cAAiB,KACjB,cAAe,GAChB,CAAC,CAKW,MAA2B,EAAW,EAAsB,CAc5D,GAER,CACH,OAAQ,EACR,cAAe,EACf,WACA,UAAW,EACX,gBACA,qBACI,CACJ,GAAM,CAAE,wBAAyB,GAAiB,EAAE,CAC9C,CAAE,cAAe,EAAqB,QAAS,GACnD,GAAwB,EAAE,CAEtB,EACJ,GAAc,GAAmB,GAAqB,EAElD,CAAC,EAAe,GAAoB,EACxC,EAAW,wBACX,EACD,CAED,MAAgB,CACV,GAAc,IAAe,GAC/B,EAAiB,EAAW,EAE7B,CAAC,EAAY,EAAe,EAAiB,CAAC,CAcjD,IAAM,EAAY,IAZK,GAA6B,CAC9C,KAAc,UAAU,GAAK,EAAU,UAAU,CAErD,IAAI,CAAC,GAAkB,IAAI,OAAO,CAAC,SAAS,EAAU,CAAE,CACtD,QAAQ,MAAM,UAAU,EAAU,mBAAmB,CACrD,OAGF,EAAiB,EAAU,CAC3B,EAAmB,EAAW,GAAmB,GAAK,IAKlD,EAAiB,EAAe,GAAc,EAAc,CAElE,OACE,EAAC,EAAsB,SAAvB,CACE,MAAO,CACL,OAAQ,EACR,YACA,gBACA,kBACD,CAEA,WAC8B,CAAA,EAwBxB,EACX,GAEA,EAAC,EAAD,CAAA,SACE,EAAC,EAAD,CAAyB,GAAI,EAAS,CAAA,CACf,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{IntlayerClientContext as e}from"../IntlayerProvider.mjs";import{useCallback as t,useContext as n}from"preact/hooks";import{compact as r}from"@intlayer/core/formatters";const i=()=>{let{locale:i}=n(e);return t((...e)=>r(e[0],{...e[1],locale:e[1]?.locale??i}),[i])};export{i as useCompact};
|
|
2
2
|
//# sourceMappingURL=useCompact.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCompact.mjs","names":[],"sources":["../../../../src/client/format/useCompact.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useCompact.mjs","names":[],"sources":["../../../../src/client/format/useCompact.ts"],"sourcesContent":["import { compact } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a compact number formatter\n * bound to the current application locale.\n *\n * @example\n * ```tsx\n * const formatCompact = useCompact();\n * formatCompact(1500); // \"1.5K\"\n * ```\n */\nexport const useCompact = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof compact>) =>\n compact(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"+KAcA,MAAa,MAAmB,CAC9B,GAAM,CAAE,UAAW,EAAW,EAAsB,CAEpD,OAAO,GACJ,GAAG,IACF,EAAQ,EAAK,GAAI,CACf,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC,CACJ,CAAC,EAAO,CACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{IntlayerClientContext as e}from"../IntlayerProvider.mjs";import{useCallback as t,useContext as n}from"preact/hooks";import{currency as r}from"@intlayer/core/formatters";const i=()=>{let{locale:i}=n(e);return t((...e)=>r(e[0],{...e[1],locale:e[1]?.locale??i}),[i])};export{i as useCurrency};
|
|
2
2
|
//# sourceMappingURL=useCurrency.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCurrency.mjs","names":[],"sources":["../../../../src/client/format/useCurrency.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useCurrency.mjs","names":[],"sources":["../../../../src/client/format/useCurrency.ts"],"sourcesContent":["import { currency } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a currency formatter\n * bound to the current application locale.\n *\n * @returns {(value: string | number, options?: CurrencyProps) => string}\n * A function to format numbers into localized currency strings.\n *\n * @example\n * ```tsx\n * const formatCurrency = useCurrency();\n *\n * formatCurrency(1500, { currency: \"USD\" });\n * // \"$1,500.00\"\n *\n * formatCurrency(1500, { currency: \"EUR\", locale: \"de-DE\" });\n * // \"1.500,00 €\"\n *\n * formatCurrency(9876543.21, {\n * currency: \"JPY\",\n * fractionDigits: 0,\n * });\n * // \"¥9,876,543\"\n * ```\n */\nexport const useCurrency = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof currency>) =>\n currency(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"gLA4BA,MAAa,MAAoB,CAC/B,GAAM,CAAE,UAAW,EAAW,EAAsB,CAEpD,OAAO,GACJ,GAAG,IACF,EAAS,EAAK,GAAI,CAChB,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC,CACJ,CAAC,EAAO,CACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{IntlayerClientContext as e}from"../IntlayerProvider.mjs";import{useContext as t}from"preact/hooks";import{date as n}from"@intlayer/core/formatters";const r=()=>{let{locale:r}=t(e);return(...e)=>n(e[0],{...e[1],locale:e[1]?.locale??r})};export{r as useDate};
|
|
2
2
|
//# sourceMappingURL=useDate.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDate.mjs","names":[],"sources":["../../../../src/client/format/useDate.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useDate.mjs","names":[],"sources":["../../../../src/client/format/useDate.ts"],"sourcesContent":["import { date } from '@intlayer/core/formatters';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a localized date/time formatter\n * bound to the current application locale.\n *\n * @returns {(date: Date | string | number, options?: DateProps) => string}\n * A function to format dates or timestamps into localized date/time strings.\n *\n * @example\n * ```tsx\n * const formatDate = useDate();\n *\n * formatDate(new Date(\"2025-01-01\"));\n * // \"Jan 1, 2025\"\n *\n * formatDate(\"2025-01-01T15:30:00Z\", {\n * dateStyle: \"full\",\n * timeStyle: \"short\",\n * });\n * // \"Wednesday, January 1, 2025 at 3:30 PM\"\n *\n * formatDate(1735689600000, { locale: \"fr-FR\", dateStyle: \"long\" });\n * // \"1 janvier 2025\"\n * ```\n *\n * @see createDate\n */\nexport const useDate = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return (...args: Parameters<typeof date>) =>\n date(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":"2JA8BA,MAAa,MAAgB,CAC3B,GAAM,CAAE,UAAW,EAAW,EAAsB,CAEpD,OAAQ,GAAG,IACT,EAAK,EAAK,GAAI,CACZ,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{IntlayerClientContext as e}from"../IntlayerProvider.mjs";import{useCallback as t,useContext as n}from"preact/hooks";import{list as r}from"@intlayer/core/formatters";const i=()=>{let{locale:i}=n(e);return t((...e)=>r(e[0],{...e[1],locale:e[1]?.locale??i}),[i])};export{i as useList};
|
|
2
2
|
//# sourceMappingURL=useList.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useList.mjs","names":[],"sources":["../../../../src/client/format/useList.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useList.mjs","names":[],"sources":["../../../../src/client/format/useList.ts"],"sourcesContent":["import { list } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a list formatter\n * bound to the current application locale.\n *\n * @returns {(values: (string | number)[], options?: ListProps) => string}\n * A function to format arrays into localized list strings.\n *\n * @example\n * ```tsx\n * const formatList = useList();\n *\n * formatList(['apple', 'banana', 'orange']);\n * // \"apple, banana, and orange\"\n *\n * formatList(['red', 'green', 'blue'], { type: 'disjunction' });\n * // \"red, green, or blue\"\n *\n * formatList([1, 2, 3], { type: 'unit', locale: 'de-DE' });\n * // \"1, 2 und 3\"\n * ```\n */\nexport const useList = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof list>) =>\n list(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"4KAyBA,MAAa,MAAgB,CAC3B,GAAM,CAAE,UAAW,EAAW,EAAsB,CAEpD,OAAO,GACJ,GAAG,IACF,EAAK,EAAK,GAAI,CACZ,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC,CACJ,CAAC,EAAO,CACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{IntlayerClientContext as e}from"../IntlayerProvider.mjs";import{useCallback as t,useContext as n}from"preact/hooks";import{number as r}from"@intlayer/core/formatters";const i=()=>{let{locale:i}=n(e);return t((...e)=>r(e[0],{...e[1],locale:e[1]?.locale??i}),[i])};export{i as useNumber};
|
|
2
2
|
//# sourceMappingURL=useNumber.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNumber.mjs","names":[],"sources":["../../../../src/client/format/useNumber.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useNumber.mjs","names":[],"sources":["../../../../src/client/format/useNumber.ts"],"sourcesContent":["import { number } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a localized number formatter.\n *\n * Uses the current locale from {@link useLocaleBase} and returns\n * a function that can be used to format numbers consistently\n * according to the user's locale.\n *\n * @example\n * ```tsx\n * const formatNumber = useNumber();\n *\n * formatNumber(12345);\n * // e.g. \"12,345\" (en-US)\n * // e.g. \"12 345\" (fr-FR)\n *\n * formatNumber(0.75, { style: \"percent\" });\n * // e.g. \"75%\"\n * ```\n *\n * @returns {(value: string | number, options?: import(\"../createNumber\").NumberProps) => string}\n * A number formatting function bound to the active locale.\n */\nexport const useNumber = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof number>) =>\n number(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"8KA0BA,MAAa,MAAkB,CAC7B,GAAM,CAAE,UAAW,EAAW,EAAsB,CAEpD,OAAO,GACJ,GAAG,IACF,EAAO,EAAK,GAAI,CACd,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC,CACJ,CAAC,EAAO,CACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{IntlayerClientContext as e}from"../IntlayerProvider.mjs";import{useCallback as t,useContext as n}from"preact/hooks";import{percentage as r}from"@intlayer/core/formatters";const i=()=>{let{locale:i}=n(e);return t((...e)=>r(e[0],{...e[1],locale:e[1]?.locale??i}),[i])};export{i as usePercentage};
|
|
2
2
|
//# sourceMappingURL=usePercentage.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePercentage.mjs","names":[],"sources":["../../../../src/client/format/usePercentage.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"usePercentage.mjs","names":[],"sources":["../../../../src/client/format/usePercentage.ts"],"sourcesContent":["import { percentage } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React hook to provide a percentage formatter function\n * based on the current application locale.\n *\n * This hook retrieves the active locale using {@link useLocaleBase}\n * and memoizes a `createPercentage` instance for that locale.\n *\n * @example\n * ```tsx\n * const formatPercentage = usePercentage();\n *\n * const result = formatPercentage(0.875, { maximumFractionDigits: 1 });\n * // \"87.5%\" (depending on locale)\n * ```\n *\n * @returns {(value: string | number, options?: Omit<PercentageOptions, \"value\">) => string}\n * A function that formats numbers or numeric strings into localized percentages.\n */\nexport const usePercentage = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof percentage>) =>\n percentage(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"kLAsBA,MAAa,MAAsB,CACjC,GAAM,CAAE,UAAW,EAAW,EAAsB,CAEpD,OAAO,GACJ,GAAG,IACF,EAAW,EAAK,GAAI,CAClB,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC,CACJ,CAAC,EAAO,CACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{IntlayerClientContext as e}from"../IntlayerProvider.mjs";import{useCallback as t,useContext as n}from"preact/hooks";import{relativeTime as r}from"@intlayer/core/formatters";const i=()=>{let{locale:i}=n(e);return t((...e)=>r(e[0],e[1],{...e[2],locale:e[2]?.locale??i}),[i])};export{i as useRelativeTime};
|
|
2
2
|
//# sourceMappingURL=useRelativeTime.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRelativeTime.mjs","names":[],"sources":["../../../../src/client/format/useRelativeTime.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useRelativeTime.mjs","names":[],"sources":["../../../../src/client/format/useRelativeTime.ts"],"sourcesContent":["import { relativeTime } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * Client-side React hook for accessing a localized relative time formatter.\n *\n * This hook:\n * - Reads the current locale from {@link useLocaleBase}.\n * - Creates a new relative time formatter with {@link createRelativeTime}.\n * - Returns a function that can format time differences into localized strings.\n *\n * Example:\n * ```tsx\n * const relativeTime = useRelativeTime();\n * const formatted = relativeTime(new Date(\"2024-08-01\"), new Date());\n * // e.g., \"2 weeks ago\"\n * ```\n *\n * @returns {ReturnType<typeof createRelativeTime>} A relative time formatting function\n * bound to the current client locale.\n */\nexport const useRelativeTime = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof relativeTime>) =>\n relativeTime(args[0], args[1], {\n ...args[2],\n locale: args[2]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"oLAsBA,MAAa,MAAwB,CACnC,GAAM,CAAE,UAAW,EAAW,EAAsB,CAEpD,OAAO,GACJ,GAAG,IACF,EAAa,EAAK,GAAI,EAAK,GAAI,CAC7B,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC,CACJ,CAAC,EAAO,CACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{IntlayerClientContext as e}from"../IntlayerProvider.mjs";import{useCallback as t,useContext as n}from"preact/hooks";import{units as r}from"@intlayer/core/formatters";const i=()=>{let{locale:i}=n(e);return t((...e)=>r(e[0],{...e[1],locale:e[1]?.locale??i}),[i])};export{i as useUnit};
|
|
2
2
|
//# sourceMappingURL=useUnit.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUnit.mjs","names":[],"sources":["../../../../src/client/format/useUnit.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useUnit.mjs","names":[],"sources":["../../../../src/client/format/useUnit.ts"],"sourcesContent":["import { units } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React hook that provides a unit formatting function\n * based on the current locale from {@link useLocaleBase}.\n *\n * This hook wraps {@link createUnit} to return a formatter\n * that can convert values into human-readable localized units\n * (e.g., \"10 km\", \"5 lbs\").\n *\n * @example\n * ```tsx\n * const formatUnit = useUnit();\n * const distance = formatUnit(10, { unit: \"kilometer\" });\n * // \"10 km\" (depending on locale)\n * ```\n *\n * @returns {Function} A unit formatting function that accepts a value and optional formatting options.\n */\nexport const useUnit = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof units>) =>\n units(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"6KAqBA,MAAa,MAAgB,CAC3B,GAAM,CAAE,UAAW,EAAW,EAAsB,CAEpD,OAAO,GACJ,GAAG,IACF,EAAM,EAAK,GAAI,CACb,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC,CACJ,CAAC,EAAO,CACT"}
|
package/dist/esm/client/t.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{IntlayerClientContext as e}from"./IntlayerProvider.mjs";import{getTranslation as t}from"@intlayer/core/interpreter";import{useContext as n}from"preact/hooks";const r=(r,i)=>{let{locale:a}=n(e);return t(r,i??a)};export{r as t};
|
|
2
2
|
//# sourceMappingURL=t.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"t.mjs","names":[],"sources":["../../../src/client/t.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"t.mjs","names":[],"sources":["../../../src/client/t.ts"],"sourcesContent":["import { getTranslation } from '@intlayer/core/interpreter';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { useContext } from 'preact/hooks';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, this function returns the translation of the provided multilang content.\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const t = <Content = string>(\n multilangContent: StrictModeLocaleMap<Content>,\n locale?: Locale\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":"qKAWA,MAAa,GACX,EACA,IACG,CACH,GAAM,CAAE,OAAQ,GAAkB,EAAW,EAAsB,CAGnE,OAAO,EAAwB,EAFV,GAAU,EAE+B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{IntlayerClientContext as e}from"./IntlayerProvider.mjs";import{getDictionary as t}from"../getDictionary.mjs";import{useContext as n,useMemo as r}from"preact/hooks";const i=(i,a)=>{let{locale:o}=n(e);return r(()=>t(i,a??o),[i.key,o,a])};export{i as useDictionary};
|
|
2
2
|
//# sourceMappingURL=useDictionary.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? currentLocale;\n\n return getDictionary<T, L>(dictionary, localeTarget as L);\n }, [dictionary.key, currentLocale, locale]);\n};\n"],"mappings":"2KAcA,MAAa,GAIX,EACA,IACG,CACH,GAAM,CAAE,OAAQ,GAAkB,EAAW,EAAsB,CAEnE,OAAO,MAGE,EAAoB,EAFN,GAAU,EAE0B,CACxD,CAAC,EAAW,IAAK,EAAe,EAAO,CAAC"}
|