preact-intlayer 8.4.3 → 8.4.5

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.
Files changed (254) hide show
  1. package/dist/cjs/IntlayerNode.cjs +16 -1
  2. package/dist/cjs/IntlayerNode.cjs.map +1 -1
  3. package/dist/cjs/UI/ContentSelector.cjs +96 -1
  4. package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
  5. package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -0
  6. package/dist/cjs/client/IntlayerProvider.cjs +88 -1
  7. package/dist/cjs/client/IntlayerProvider.cjs.map +1 -0
  8. package/dist/cjs/client/format/index.cjs +18 -1
  9. package/dist/cjs/client/format/useCompact.cjs +27 -1
  10. package/dist/cjs/client/format/useCompact.cjs.map +1 -1
  11. package/dist/cjs/client/format/useCurrency.cjs +41 -1
  12. package/dist/cjs/client/format/useCurrency.cjs.map +1 -1
  13. package/dist/cjs/client/format/useDate.cjs +43 -1
  14. package/dist/cjs/client/format/useDate.cjs.map +1 -1
  15. package/dist/cjs/client/format/useIntl.cjs +33 -1
  16. package/dist/cjs/client/format/useIntl.cjs.map +1 -1
  17. package/dist/cjs/client/format/useList.cjs +38 -1
  18. package/dist/cjs/client/format/useList.cjs.map +1 -1
  19. package/dist/cjs/client/format/useNumber.cjs +39 -1
  20. package/dist/cjs/client/format/useNumber.cjs.map +1 -1
  21. package/dist/cjs/client/format/usePercentage.cjs +35 -1
  22. package/dist/cjs/client/format/usePercentage.cjs.map +1 -1
  23. package/dist/cjs/client/format/useRelativeTime.cjs +35 -1
  24. package/dist/cjs/client/format/useRelativeTime.cjs.map +1 -1
  25. package/dist/cjs/client/format/useUnit.cjs +34 -1
  26. package/dist/cjs/client/format/useUnit.cjs.map +1 -1
  27. package/dist/cjs/client/index.cjs +32 -1
  28. package/dist/cjs/client/t.cjs +19 -1
  29. package/dist/cjs/client/t.cjs.map +1 -1
  30. package/dist/cjs/client/useContent.cjs +19 -1
  31. package/dist/cjs/client/useContent.cjs.map +1 -1
  32. package/dist/cjs/client/useDictionary.cjs +25 -1
  33. package/dist/cjs/client/useDictionary.cjs.map +1 -1
  34. package/dist/cjs/client/useDictionaryAsync.cjs +22 -1
  35. package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
  36. package/dist/cjs/client/useDictionaryDynamic.cjs +21 -1
  37. package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
  38. package/dist/cjs/client/useIntlayer.cjs +40 -1
  39. package/dist/cjs/client/useIntlayer.cjs.map +1 -1
  40. package/dist/cjs/client/useLoadDynamic.cjs +27 -1
  41. package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
  42. package/dist/cjs/client/useLocale.cjs +54 -1
  43. package/dist/cjs/client/useLocale.cjs.map +1 -1
  44. package/dist/cjs/client/useLocaleBase.cjs +24 -1
  45. package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
  46. package/dist/cjs/client/useLocaleStorage.cjs +59 -1
  47. package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
  48. package/dist/cjs/client/useTraduction.cjs +35 -1
  49. package/dist/cjs/client/useTraduction.cjs.map +1 -1
  50. package/dist/cjs/editor/ContentSelector.cjs +24 -1
  51. package/dist/cjs/editor/ContentSelector.cjs.map +1 -1
  52. package/dist/cjs/editor/EditorProvider.cjs +12 -1
  53. package/dist/cjs/editor/EditorProvider.cjs.map +1 -0
  54. package/dist/cjs/editor/useEditor.cjs +38 -1
  55. package/dist/cjs/editor/useEditor.cjs.map +1 -0
  56. package/dist/cjs/getDictionary.cjs +10 -1
  57. package/dist/cjs/getDictionary.cjs.map +1 -1
  58. package/dist/cjs/getIntlayer.cjs +10 -1
  59. package/dist/cjs/getIntlayer.cjs.map +1 -1
  60. package/dist/cjs/html/HTMLProvider.cjs +17 -1
  61. package/dist/cjs/html/HTMLProvider.cjs.map +1 -1
  62. package/dist/cjs/html/HTMLRenderer.cjs +54 -1
  63. package/dist/cjs/html/HTMLRenderer.cjs.map +1 -1
  64. package/dist/cjs/html/index.cjs +10 -1
  65. package/dist/cjs/index.cjs +57 -1
  66. package/dist/cjs/markdown/MarkdownProvider.cjs +54 -1
  67. package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -1
  68. package/dist/cjs/markdown/MarkdownRenderer.cjs +77 -1
  69. package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
  70. package/dist/cjs/markdown/MarkdownRendererPlugin.cjs +26 -1
  71. package/dist/cjs/markdown/MarkdownRendererPlugin.cjs.map +1 -1
  72. package/dist/cjs/markdown/compiler.cjs +24 -1
  73. package/dist/cjs/markdown/compiler.cjs.map +1 -1
  74. package/dist/cjs/markdown/index.cjs +23 -1
  75. package/dist/cjs/markdown/runtime.cjs +18 -1
  76. package/dist/cjs/markdown/runtime.cjs.map +1 -1
  77. package/dist/cjs/plugins.cjs +222 -1
  78. package/dist/cjs/plugins.cjs.map +1 -1
  79. package/dist/cjs/preactElement/renderPreactElement.cjs +42 -1
  80. package/dist/cjs/preactElement/renderPreactElement.cjs.map +1 -1
  81. package/dist/esm/IntlayerNode.mjs +14 -1
  82. package/dist/esm/IntlayerNode.mjs.map +1 -1
  83. package/dist/esm/UI/ContentSelector.mjs +94 -1
  84. package/dist/esm/UI/ContentSelector.mjs.map +1 -1
  85. package/dist/esm/client/IntlayerProvider.mjs +82 -1
  86. package/dist/esm/client/IntlayerProvider.mjs.map +1 -0
  87. package/dist/esm/client/format/index.mjs +10 -1
  88. package/dist/esm/client/format/useCompact.mjs +25 -1
  89. package/dist/esm/client/format/useCompact.mjs.map +1 -1
  90. package/dist/esm/client/format/useCurrency.mjs +39 -1
  91. package/dist/esm/client/format/useCurrency.mjs.map +1 -1
  92. package/dist/esm/client/format/useDate.mjs +41 -1
  93. package/dist/esm/client/format/useDate.mjs.map +1 -1
  94. package/dist/esm/client/format/useIntl.mjs +31 -1
  95. package/dist/esm/client/format/useIntl.mjs.map +1 -1
  96. package/dist/esm/client/format/useList.mjs +36 -1
  97. package/dist/esm/client/format/useList.mjs.map +1 -1
  98. package/dist/esm/client/format/useNumber.mjs +37 -1
  99. package/dist/esm/client/format/useNumber.mjs.map +1 -1
  100. package/dist/esm/client/format/usePercentage.mjs +33 -1
  101. package/dist/esm/client/format/usePercentage.mjs.map +1 -1
  102. package/dist/esm/client/format/useRelativeTime.mjs +33 -1
  103. package/dist/esm/client/format/useRelativeTime.mjs.map +1 -1
  104. package/dist/esm/client/format/useUnit.mjs +32 -1
  105. package/dist/esm/client/format/useUnit.mjs.map +1 -1
  106. package/dist/esm/client/index.mjs +13 -1
  107. package/dist/esm/client/t.mjs +17 -1
  108. package/dist/esm/client/t.mjs.map +1 -1
  109. package/dist/esm/client/useContent.mjs +18 -1
  110. package/dist/esm/client/useContent.mjs.map +1 -1
  111. package/dist/esm/client/useDictionary.mjs +23 -1
  112. package/dist/esm/client/useDictionary.mjs.map +1 -1
  113. package/dist/esm/client/useDictionaryAsync.mjs +19 -1
  114. package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
  115. package/dist/esm/client/useDictionaryDynamic.mjs +19 -1
  116. package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
  117. package/dist/esm/client/useIntlayer.mjs +38 -1
  118. package/dist/esm/client/useIntlayer.mjs.map +1 -1
  119. package/dist/esm/client/useLoadDynamic.mjs +25 -1
  120. package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
  121. package/dist/esm/client/useLocale.mjs +51 -1
  122. package/dist/esm/client/useLocale.mjs.map +1 -1
  123. package/dist/esm/client/useLocaleBase.mjs +21 -1
  124. package/dist/esm/client/useLocaleBase.mjs.map +1 -1
  125. package/dist/esm/client/useLocaleStorage.mjs +52 -1
  126. package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
  127. package/dist/esm/client/useTraduction.mjs +33 -1
  128. package/dist/esm/client/useTraduction.mjs.map +1 -1
  129. package/dist/esm/editor/ContentSelector.mjs +22 -1
  130. package/dist/esm/editor/ContentSelector.mjs.map +1 -1
  131. package/dist/esm/editor/EditorProvider.mjs +11 -1
  132. package/dist/esm/editor/EditorProvider.mjs.map +1 -0
  133. package/dist/esm/editor/useEditor.mjs +36 -1
  134. package/dist/esm/editor/useEditor.mjs.map +1 -0
  135. package/dist/esm/getDictionary.mjs +8 -1
  136. package/dist/esm/getDictionary.mjs.map +1 -1
  137. package/dist/esm/getIntlayer.mjs +8 -1
  138. package/dist/esm/getIntlayer.mjs.map +1 -1
  139. package/dist/esm/html/HTMLProvider.mjs +14 -1
  140. package/dist/esm/html/HTMLProvider.mjs.map +1 -1
  141. package/dist/esm/html/HTMLRenderer.mjs +49 -1
  142. package/dist/esm/html/HTMLRenderer.mjs.map +1 -1
  143. package/dist/esm/html/index.mjs +4 -1
  144. package/dist/esm/index.mjs +22 -1
  145. package/dist/esm/markdown/MarkdownProvider.mjs +51 -1
  146. package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -1
  147. package/dist/esm/markdown/MarkdownRenderer.mjs +73 -1
  148. package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
  149. package/dist/esm/markdown/MarkdownRendererPlugin.mjs +23 -1
  150. package/dist/esm/markdown/MarkdownRendererPlugin.mjs.map +1 -1
  151. package/dist/esm/markdown/compiler.mjs +17 -1
  152. package/dist/esm/markdown/compiler.mjs.map +1 -1
  153. package/dist/esm/markdown/index.mjs +7 -1
  154. package/dist/esm/markdown/runtime.mjs +15 -1
  155. package/dist/esm/markdown/runtime.mjs.map +1 -1
  156. package/dist/esm/plugins.mjs +212 -1
  157. package/dist/esm/plugins.mjs.map +1 -1
  158. package/dist/esm/preactElement/renderPreactElement.mjs +40 -1
  159. package/dist/esm/preactElement/renderPreactElement.mjs.map +1 -1
  160. package/dist/types/IntlayerNode.d.ts +23 -2
  161. package/dist/types/IntlayerNode.d.ts.map +1 -0
  162. package/dist/types/client/IntlayerProvider.d.ts +53 -2
  163. package/dist/types/client/IntlayerProvider.d.ts.map +1 -0
  164. package/dist/types/client/format/useIntl.d.ts +26 -2
  165. package/dist/types/client/format/useIntl.d.ts.map +1 -0
  166. package/dist/types/client/index.d.ts +11 -11
  167. package/dist/types/client/t.d.ts +13 -2
  168. package/dist/types/client/t.d.ts.map +1 -0
  169. package/dist/types/client/useDictionary.d.ts +16 -2
  170. package/dist/types/client/useDictionary.d.ts.map +1 -0
  171. package/dist/types/client/useDictionaryAsync.d.ts +13 -2
  172. package/dist/types/client/useDictionaryAsync.d.ts.map +1 -0
  173. package/dist/types/client/useDictionaryDynamic.d.ts +16 -2
  174. package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -0
  175. package/dist/types/client/useIntlayer.d.ts +28 -2
  176. package/dist/types/client/useIntlayer.d.ts.map +1 -0
  177. package/dist/types/client/useLoadDynamic.d.ts +5 -2
  178. package/dist/types/client/useLoadDynamic.d.ts.map +1 -0
  179. package/dist/types/client/useLocale.d.ts +43 -2
  180. package/dist/types/client/useLocale.d.ts.map +1 -0
  181. package/dist/types/client/useLocaleBase.d.ts +16 -2
  182. package/dist/types/client/useLocaleBase.d.ts.map +1 -0
  183. package/dist/types/client/useLocaleStorage.d.ts +45 -2
  184. package/dist/types/client/useLocaleStorage.d.ts.map +1 -0
  185. package/dist/types/getDictionary.d.ts +1 -1
  186. package/dist/types/getIntlayer.d.ts +1 -1
  187. package/dist/types/html/HTMLProvider.d.ts +18 -2
  188. package/dist/types/html/HTMLProvider.d.ts.map +1 -0
  189. package/dist/types/html/HTMLRenderer.d.ts +61 -2
  190. package/dist/types/html/HTMLRenderer.d.ts.map +1 -0
  191. package/dist/types/html/index.d.ts +2 -2
  192. package/dist/types/html/types.d.ts +38 -2
  193. package/dist/types/html/types.d.ts.map +1 -0
  194. package/dist/types/index.d.ts +19 -19
  195. package/dist/types/markdown/MarkdownProvider.d.ts +52 -2
  196. package/dist/types/markdown/MarkdownProvider.d.ts.map +1 -0
  197. package/dist/types/markdown/MarkdownRenderer.d.ts +61 -2
  198. package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -0
  199. package/dist/types/markdown/MarkdownRendererPlugin.d.ts +23 -2
  200. package/dist/types/markdown/MarkdownRendererPlugin.d.ts.map +1 -0
  201. package/dist/types/markdown/compiler.d.ts +14 -2
  202. package/dist/types/markdown/compiler.d.ts.map +1 -0
  203. package/dist/types/markdown/index.d.ts +5 -5
  204. package/dist/types/markdown/runtime.d.ts +10 -2
  205. package/dist/types/markdown/runtime.d.ts.map +1 -0
  206. package/dist/types/plugins.d.ts +96 -2
  207. package/dist/types/plugins.d.ts.map +1 -0
  208. package/package.json +7 -7
  209. package/dist/cjs/IntlayerProvider-sM1gzsx7.cjs +0 -2
  210. package/dist/cjs/IntlayerProvider-sM1gzsx7.cjs.map +0 -1
  211. package/dist/esm/IntlayerProvider-ClOcEK3A.mjs +0 -2
  212. package/dist/esm/IntlayerProvider-ClOcEK3A.mjs.map +0 -1
  213. package/dist/types/HTMLProvider-8sO8DU8H.d.ts +0 -18
  214. package/dist/types/HTMLProvider-8sO8DU8H.d.ts.map +0 -1
  215. package/dist/types/HTMLRenderer-NNa_9oMD.d.ts +0 -61
  216. package/dist/types/HTMLRenderer-NNa_9oMD.d.ts.map +0 -1
  217. package/dist/types/IntlayerNode-CIzFHYnC.d.ts +0 -23
  218. package/dist/types/IntlayerNode-CIzFHYnC.d.ts.map +0 -1
  219. package/dist/types/IntlayerProvider-aV596OL4.d.ts +0 -53
  220. package/dist/types/IntlayerProvider-aV596OL4.d.ts.map +0 -1
  221. package/dist/types/MarkdownProvider-chUIO05u.d.ts +0 -52
  222. package/dist/types/MarkdownProvider-chUIO05u.d.ts.map +0 -1
  223. package/dist/types/MarkdownRenderer-BMhuurZW.d.ts +0 -61
  224. package/dist/types/MarkdownRenderer-BMhuurZW.d.ts.map +0 -1
  225. package/dist/types/MarkdownRendererPlugin-DFRVdHCA.d.ts +0 -23
  226. package/dist/types/MarkdownRendererPlugin-DFRVdHCA.d.ts.map +0 -1
  227. package/dist/types/compiler-BB0gAVbe.d.ts +0 -14
  228. package/dist/types/compiler-BB0gAVbe.d.ts.map +0 -1
  229. package/dist/types/plugins-D6OB94dO.d.ts +0 -95
  230. package/dist/types/plugins-D6OB94dO.d.ts.map +0 -1
  231. package/dist/types/runtime-BMHAtT-R.d.ts +0 -10
  232. package/dist/types/runtime-BMHAtT-R.d.ts.map +0 -1
  233. package/dist/types/t-CalXqnSB.d.ts +0 -13
  234. package/dist/types/t-CalXqnSB.d.ts.map +0 -1
  235. package/dist/types/types-B3Kzdco6.d.ts +0 -38
  236. package/dist/types/types-B3Kzdco6.d.ts.map +0 -1
  237. package/dist/types/useDictionary-cjQAc1l1.d.ts +0 -16
  238. package/dist/types/useDictionary-cjQAc1l1.d.ts.map +0 -1
  239. package/dist/types/useDictionaryAsync-CDCcBnXn.d.ts +0 -13
  240. package/dist/types/useDictionaryAsync-CDCcBnXn.d.ts.map +0 -1
  241. package/dist/types/useDictionaryDynamic-BQgaM0vp.d.ts +0 -16
  242. package/dist/types/useDictionaryDynamic-BQgaM0vp.d.ts.map +0 -1
  243. package/dist/types/useIntl-DfzrSGu4.d.ts +0 -26
  244. package/dist/types/useIntl-DfzrSGu4.d.ts.map +0 -1
  245. package/dist/types/useIntlayer-BINmW9T1.d.ts +0 -28
  246. package/dist/types/useIntlayer-BINmW9T1.d.ts.map +0 -1
  247. package/dist/types/useLoadDynamic-DFXHehpF.d.ts +0 -5
  248. package/dist/types/useLoadDynamic-DFXHehpF.d.ts.map +0 -1
  249. package/dist/types/useLocale-BDQ4yLc5.d.ts +0 -43
  250. package/dist/types/useLocale-BDQ4yLc5.d.ts.map +0 -1
  251. package/dist/types/useLocaleBase-1L1RLyXD.d.ts +0 -16
  252. package/dist/types/useLocaleBase-1L1RLyXD.d.ts.map +0 -1
  253. package/dist/types/useLocaleStorage-BwH9gqN5.d.ts +0 -45
  254. package/dist/types/useLocaleStorage-BwH9gqN5.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"renderPreactElement.cjs","names":[],"sources":["../../../src/preactElement/renderPreactElement.ts"],"sourcesContent":["import { type ComponentChild, createElement, type VNode } from 'preact';\n\n// This function recursively creates Preact elements from a given JSON-like structure\nexport const renderPreactElement = (element: VNode<any>): any => {\n if (element === null || typeof element !== 'object') {\n return element;\n }\n\n const convertChildrenAsArray = (\n element: VNode<{ children?: ComponentChild | ComponentChild[] }>\n ): VNode<{ children?: ComponentChild | ComponentChild[] }> => {\n const children = element.props?.children;\n\n if (Array.isArray(children)) {\n const childrenResult: ComponentChild[] = children.map((child) =>\n renderPreactElement(child as VNode<any>)\n );\n\n return {\n ...element,\n props: { ...element.props, children: childrenResult },\n };\n } else if (typeof children !== 'undefined' && children !== null) {\n const renderedChild = renderPreactElement(children as VNode<any>);\n return {\n ...element,\n props: { ...element.props, children: [renderedChild] },\n };\n }\n\n return {\n ...element,\n props: { ...element.props, children: [] },\n };\n };\n\n const fixedElement = convertChildrenAsArray(\n element as VNode<{ children?: ComponentChild | ComponentChild[] }>\n );\n\n const { type, props } = fixedElement;\n\n // Create and return the Preact element\n return createElement(\n (type as any) ?? 'span',\n props as any,\n ...(props.children as ComponentChild[])\n );\n};\n"],"mappings":"uIAGA,MAAa,EAAuB,GAA6B,CAC/D,GAAwB,OAAO,GAAY,WAAvC,EACF,OAAO,EAmCT,GAAM,CAAE,OAAM,UA/BZ,GAC4D,CAC5D,IAAM,EAAW,EAAQ,OAAO,SAEhC,GAAI,MAAM,QAAQ,EAAS,CAAE,CAC3B,IAAM,EAAmC,EAAS,IAAK,GACrD,EAAoB,EAAoB,CACzC,CAED,MAAO,CACL,GAAG,EACH,MAAO,CAAE,GAAG,EAAQ,MAAO,SAAU,EAAgB,CACtD,SACe,GAAyC,KAAM,CAC/D,IAAM,EAAgB,EAAoB,EAAuB,CACjE,MAAO,CACL,GAAG,EACH,MAAO,CAAE,GAAG,EAAQ,MAAO,SAAU,CAAC,EAAc,CAAE,CACvD,CAGH,MAAO,CACL,GAAG,EACH,MAAO,CAAE,GAAG,EAAQ,MAAO,SAAU,EAAE,CAAE,CAC1C,GAID,EACD,CAKD,OAAA,EAAA,EAAA,eACG,GAAgB,OACjB,EACA,GAAI,EAAM,SACX"}
1
+ {"version":3,"file":"renderPreactElement.cjs","names":[],"sources":["../../../src/preactElement/renderPreactElement.ts"],"sourcesContent":["import { type ComponentChild, createElement, type VNode } from 'preact';\n\n// This function recursively creates Preact elements from a given JSON-like structure\nexport const renderPreactElement = (element: VNode<any>): any => {\n if (element === null || typeof element !== 'object') {\n return element;\n }\n\n const convertChildrenAsArray = (\n element: VNode<{ children?: ComponentChild | ComponentChild[] }>\n ): VNode<{ children?: ComponentChild | ComponentChild[] }> => {\n const children = element.props?.children;\n\n if (Array.isArray(children)) {\n const childrenResult: ComponentChild[] = children.map((child) =>\n renderPreactElement(child as VNode<any>)\n );\n\n return {\n ...element,\n props: { ...element.props, children: childrenResult },\n };\n } else if (typeof children !== 'undefined' && children !== null) {\n const renderedChild = renderPreactElement(children as VNode<any>);\n return {\n ...element,\n props: { ...element.props, children: [renderedChild] },\n };\n }\n\n return {\n ...element,\n props: { ...element.props, children: [] },\n };\n };\n\n const fixedElement = convertChildrenAsArray(\n element as VNode<{ children?: ComponentChild | ComponentChild[] }>\n );\n\n const { type, props } = fixedElement;\n\n // Create and return the Preact element\n return createElement(\n (type as any) ?? 'span',\n props as any,\n ...(props.children as ComponentChild[])\n );\n};\n"],"mappings":";;;;;AAGA,MAAa,uBAAuB,YAA6B;AAC/D,KAAI,YAAY,QAAQ,OAAO,YAAY,SACzC,QAAO;CAGT,MAAM,0BACJ,YAC4D;EAC5D,MAAM,WAAW,QAAQ,OAAO;AAEhC,MAAI,MAAM,QAAQ,SAAS,EAAE;GAC3B,MAAM,iBAAmC,SAAS,KAAK,UACrD,oBAAoB,MAAoB,CACzC;AAED,UAAO;IACL,GAAG;IACH,OAAO;KAAE,GAAG,QAAQ;KAAO,UAAU;KAAgB;IACtD;aACQ,OAAO,aAAa,eAAe,aAAa,MAAM;GAC/D,MAAM,gBAAgB,oBAAoB,SAAuB;AACjE,UAAO;IACL,GAAG;IACH,OAAO;KAAE,GAAG,QAAQ;KAAO,UAAU,CAAC,cAAc;KAAE;IACvD;;AAGH,SAAO;GACL,GAAG;GACH,OAAO;IAAE,GAAG,QAAQ;IAAO,UAAU,EAAE;IAAE;GAC1C;;CAOH,MAAM,EAAE,MAAM,UAJO,uBACnB,QACD;AAKD,kCACG,QAAgB,QACjB,OACA,GAAI,MAAM,SACX"}
@@ -1,2 +1,15 @@
1
- import{Fragment as e,h as t,isValidElement as n}from"preact";const r=({children:r,value:i,additionalProps:a})=>{let o=n(r)?r:t(e,{},r);return new Proxy(o,{get(e,t,n){return t===`value`?i:a&&Object.keys(a).includes(t)?a[t]:Reflect.get(e,t,n)}})};export{r as renderIntlayerNode};
1
+ import { Fragment, h, isValidElement } from "preact";
2
+
3
+ //#region src/IntlayerNode.tsx
4
+ const renderIntlayerNode = ({ children, value, additionalProps }) => {
5
+ const element = isValidElement(children) ? children : h(Fragment, {}, children);
6
+ return new Proxy(element, { get(target, prop, receiver) {
7
+ if (prop === "value") return value;
8
+ if (additionalProps && Object.keys(additionalProps).includes(prop)) return additionalProps[prop];
9
+ return Reflect.get(target, prop, receiver);
10
+ } });
11
+ };
12
+
13
+ //#endregion
14
+ export { renderIntlayerNode };
2
15
  //# sourceMappingURL=IntlayerNode.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"IntlayerNode.mjs","names":[],"sources":["../../src/IntlayerNode.tsx"],"sourcesContent":["import type { NodeProps } from '@intlayer/core/interpreter';\nimport type { ResolvedEditor } from '@intlayer/types/module_augmentation';\nimport {\n type ComponentChildren,\n Fragment,\n h,\n isValidElement,\n type VNode,\n} from 'preact';\n\nexport type IntlayerNode<\n T = NodeProps['children'],\n AdditionalProps = {},\n> = ResolvedEditor<T, VNode> & {\n value: T;\n} & AdditionalProps;\n\ntype RenderIntlayerNodeProps<T> = {\n value: T;\n children: ComponentChildren;\n additionalProps?: { [key: string]: any };\n};\n\nexport const renderIntlayerNode = <\n T extends number | string | boolean | undefined | null,\n>({\n children,\n value,\n additionalProps,\n}: RenderIntlayerNodeProps<T>): IntlayerNode<T> => {\n // If children is not a valid VNode, wrap it in a fragment\n const element: VNode<any> = isValidElement(children)\n ? children\n : h(Fragment, {}, children);\n\n // Return a Proxy that pretends to be the original element\n // but also has a .value getter.\n return new Proxy(element as VNode, {\n get(target, prop, receiver) {\n if (prop === 'value') {\n return value;\n }\n\n if (\n additionalProps &&\n Object.keys(additionalProps).includes(prop as string)\n ) {\n return additionalProps[prop as keyof typeof additionalProps];\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as IntlayerNode<T>;\n};\n"],"mappings":"6DAuBA,MAAa,GAEX,CACA,WACA,QACA,qBACiD,CAEjD,IAAM,EAAsB,EAAe,EAAS,CAChD,EACA,EAAE,EAAU,EAAE,CAAE,EAAS,CAI7B,OAAO,IAAI,MAAM,EAAkB,CACjC,IAAI,EAAQ,EAAM,EAAU,CAY1B,OAXI,IAAS,QACJ,EAIP,GACA,OAAO,KAAK,EAAgB,CAAC,SAAS,EAAe,CAE9C,EAAgB,GAGlB,QAAQ,IAAI,EAAQ,EAAM,EAAS,EAE7C,CAAC"}
1
+ {"version":3,"file":"IntlayerNode.mjs","names":[],"sources":["../../src/IntlayerNode.tsx"],"sourcesContent":["import type { NodeProps } from '@intlayer/core/interpreter';\nimport type { ResolvedEditor } from '@intlayer/types/module_augmentation';\nimport {\n type ComponentChildren,\n Fragment,\n h,\n isValidElement,\n type VNode,\n} from 'preact';\n\nexport type IntlayerNode<\n T = NodeProps['children'],\n AdditionalProps = {},\n> = ResolvedEditor<T, VNode> & {\n value: T;\n} & AdditionalProps;\n\ntype RenderIntlayerNodeProps<T> = {\n value: T;\n children: ComponentChildren;\n additionalProps?: { [key: string]: any };\n};\n\nexport const renderIntlayerNode = <\n T extends number | string | boolean | undefined | null,\n>({\n children,\n value,\n additionalProps,\n}: RenderIntlayerNodeProps<T>): IntlayerNode<T> => {\n // If children is not a valid VNode, wrap it in a fragment\n const element: VNode<any> = isValidElement(children)\n ? children\n : h(Fragment, {}, children);\n\n // Return a Proxy that pretends to be the original element\n // but also has a .value getter.\n return new Proxy(element as VNode, {\n get(target, prop, receiver) {\n if (prop === 'value') {\n return value;\n }\n\n if (\n additionalProps &&\n Object.keys(additionalProps).includes(prop as string)\n ) {\n return additionalProps[prop as keyof typeof additionalProps];\n }\n\n return Reflect.get(target, prop, receiver);\n },\n }) as IntlayerNode<T>;\n};\n"],"mappings":";;;AAuBA,MAAa,sBAEX,EACA,UACA,OACA,sBACiD;CAEjD,MAAM,UAAsB,eAAe,SAAS,GAChD,WACA,EAAE,UAAU,EAAE,EAAE,SAAS;AAI7B,QAAO,IAAI,MAAM,SAAkB,EACjC,IAAI,QAAQ,MAAM,UAAU;AAC1B,MAAI,SAAS,QACX,QAAO;AAGT,MACE,mBACA,OAAO,KAAK,gBAAgB,CAAC,SAAS,KAAe,CAErD,QAAO,gBAAgB;AAGzB,SAAO,QAAQ,IAAI,QAAQ,MAAM,SAAS;IAE7C,CAAC"}
@@ -1,2 +1,95 @@
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};
1
+ import { useCallback, useEffect, useRef, useState } from "preact/hooks";
2
+ import { jsx } from "preact/jsx-runtime";
3
+
4
+ //#region src/UI/ContentSelector.tsx
5
+ const DEFAULT_PRESS_DETECT_DURATION = 250;
6
+ const ContentSelector = ({ children, onPress: onSelect, onHover, onUnhover, onClickOutside: onUnselect, pressDuration = DEFAULT_PRESS_DETECT_DURATION, isSelecting: isSelectingProp, ...props }) => {
7
+ const divRef = useRef(null);
8
+ const [isHovered, setIsHovered] = useState(false);
9
+ const [isSelectingState, setIsSelectingState] = useState(isSelectingProp);
10
+ const pressTimerRef = useRef(null);
11
+ const isChildrenString = typeof children === "string";
12
+ const handleOnLongPress = () => {
13
+ setIsSelectingState(true);
14
+ onSelect();
15
+ };
16
+ const startPressTimer = () => {
17
+ pressTimerRef.current = setTimeout(() => {
18
+ handleOnLongPress();
19
+ }, pressDuration);
20
+ };
21
+ const clearPressTimer = () => {
22
+ if (pressTimerRef.current) {
23
+ clearTimeout(pressTimerRef.current);
24
+ pressTimerRef.current = null;
25
+ }
26
+ };
27
+ const handleMouseDown = () => {
28
+ clearPressTimer();
29
+ startPressTimer();
30
+ };
31
+ const handleMouseEnter = () => {
32
+ setIsHovered(true);
33
+ onHover?.();
34
+ };
35
+ const handleMouseUp = () => {
36
+ if (isHovered) {
37
+ setIsHovered(false);
38
+ onUnhover?.();
39
+ }
40
+ clearPressTimer();
41
+ };
42
+ const handleClickOutside = useCallback((event) => {
43
+ if (divRef.current && !divRef.current.contains(event.target)) {
44
+ setIsSelectingState(false);
45
+ onUnselect?.();
46
+ }
47
+ }, [onUnselect]);
48
+ useEffect(() => {
49
+ document.addEventListener("mousedown", handleClickOutside);
50
+ return () => {
51
+ document.removeEventListener("mousedown", handleClickOutside);
52
+ };
53
+ }, [handleClickOutside]);
54
+ const handleOnClick = (e) => {
55
+ if (isSelectingState) {
56
+ e.preventDefault();
57
+ e.stopPropagation();
58
+ }
59
+ };
60
+ const handleOnBlur = () => {
61
+ setIsSelectingState(false);
62
+ };
63
+ return /* @__PURE__ */ jsx("span", {
64
+ style: {
65
+ display: isChildrenString ? "inline" : "inline-block",
66
+ cursor: "pointer",
67
+ userSelect: "none",
68
+ borderRadius: "0.375rem",
69
+ outlineWidth: "2px",
70
+ outlineOffset: "4px",
71
+ outlineStyle: "solid",
72
+ outlineColor: isSelectingProp || isSelectingState || isHovered ? "inherit" : "transparent",
73
+ transition: "all 100ms 50ms ease-in-out"
74
+ },
75
+ role: "button",
76
+ tabIndex: 0,
77
+ onKeyUp: () => null,
78
+ onClick: handleOnClick,
79
+ onMouseDown: handleMouseDown,
80
+ onMouseUp: handleMouseUp,
81
+ onMouseLeave: handleMouseUp,
82
+ onTouchStart: handleMouseDown,
83
+ onTouchEnd: handleMouseUp,
84
+ onTouchCancel: handleMouseUp,
85
+ onBlur: handleOnBlur,
86
+ onMouseEnter: handleMouseEnter,
87
+ ref: divRef,
88
+ ...props,
89
+ children
90
+ });
91
+ };
92
+
93
+ //#endregion
94
+ export { ContentSelector };
2
95
  //# sourceMappingURL=ContentSelector.mjs.map
@@ -1 +1 @@
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
+ {"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":";;;;AAGA,MAAM,gCAAgC;AAWtC,MAAa,mBAA8D,EACzE,UACA,SAAS,UACT,SACA,WACA,gBAAgB,YAChB,gBAAgB,+BAChB,aAAa,iBACb,GAAG,YACC;CACJ,MAAM,SAAS,OAAuB,KAAK;CAC3C,MAAM,CAAC,WAAW,gBAAgB,SAAS,MAAM;CACjD,MAAM,CAAC,kBAAkB,uBAAuB,SAAS,gBAAgB;CACzE,MAAM,gBAAgB,OAA6C,KAAK;CACxE,MAAM,mBAAmB,OAAO,aAAa;CAE7C,MAAM,0BAA0B;AAC9B,sBAAoB,KAAK;AACzB,YAAU;;CAGZ,MAAM,wBAAwB;AAC5B,gBAAc,UAAU,iBAAiB;AACvC,sBAAmB;KAClB,cAAc;;CAGnB,MAAM,wBAAwB;AAC5B,MAAI,cAAc,SAAS;AACzB,gBAAa,cAAc,QAAQ;AACnC,iBAAc,UAAU;;;CAI5B,MAAM,wBAAwB;AAC5B,mBAAiB;AACjB,mBAAiB;;CAGnB,MAAM,yBAAyB;AAC7B,eAAa,KAAK;AAClB,aAAW;;CAGb,MAAM,sBAAsB;AAC1B,MAAI,WAAW;AACb,gBAAa,MAAM;AACnB,gBAAa;;AAEf,mBAAiB;;CAInB,MAAM,qBAAqB,aACxB,UAAsB;AACrB,MAAI,OAAO,WAAW,CAAC,OAAO,QAAQ,SAAS,MAAM,OAAe,EAAE;AACpE,uBAAoB,MAAM;AAC1B,iBAAc;;IAGlB,CAAC,WAAW,CACb;AAED,iBAAgB;AAEd,WAAS,iBAAiB,aAAa,mBAAmB;AAE1D,eAAa;AAEX,YAAS,oBAAoB,aAAa,mBAAmB;;IAG9D,CAAC,mBAAmB,CAAC;CAExB,MAAM,iBAAwD,MAAM;AAClE,MAAI,kBAAkB;AACpB,KAAE,gBAAgB;AAClB,KAAE,iBAAiB;;;CAIvB,MAAM,qBAAqB;AAEzB,sBAAoB,MAAM;;AAG5B,QACE,oBAAC,QAAD;EACE,OAAO;GACL,SAAS,mBAAmB,WAAW;GACvC,QAAQ;GACR,YAAY;GACZ,cAAc;GACd,cAAc;GACd,eAAe;GACf,cAAc;GACd,cACE,mBAAmB,oBAAoB,YACnC,YACA;GACN,YAAY;GACb;EACD,MAAK;EACL,UAAU;EACV,eAAe;EACf,SAAS;EACT,aAAa;EACb,WAAW;EACX,cAAc;EACd,cAAc;EACd,YAAY;EACZ,eAAe;EACf,QAAQ;EACR,cAAc;EACd,KAAK;EACL,GAAI;EAEH;EACI"}
@@ -1 +1,82 @@
1
- import{i as e,n as t,r as n,t as r}from"../IntlayerProvider-ClOcEK3A.mjs";export{r as IntlayerClientContext,t as IntlayerProvider,n as IntlayerProviderContent,e as useIntlayerContext};
1
+ import { EditorProvider } from "../editor/EditorProvider.mjs";
2
+ import { localeInStorage, setLocaleInStorage } from "./useLocaleStorage.mjs";
3
+ import configuration from "@intlayer/config/built";
4
+ import { createContext } from "preact";
5
+ import { useContext, useEffect, useState } from "preact/hooks";
6
+ import { jsx, jsxs } from "preact/jsx-runtime";
7
+ import { localeResolver } from "@intlayer/core/localization";
8
+
9
+ //#region src/client/IntlayerProvider.tsx
10
+ /**
11
+ * Context that store the current locale on the client side
12
+ */
13
+ const IntlayerClientContext = createContext({
14
+ locale: localeInStorage ?? configuration?.internationalization?.defaultLocale,
15
+ setLocale: () => null
16
+ });
17
+ /**
18
+ * Hook that provides the current locale
19
+ */
20
+ const useIntlayerContext = () => useContext(IntlayerClientContext);
21
+ /**
22
+ * Provider that store the current locale on the client side
23
+ */
24
+ const IntlayerProviderContent = ({ locale: localeProp, defaultLocale: defaultLocaleProp, children, setLocale: setLocaleProp, isCookieEnabled }) => {
25
+ const { internationalization } = configuration ?? {};
26
+ const { defaultLocale: defaultLocaleConfig, locales: availableLocales } = internationalization ?? {};
27
+ const [currentLocale, setCurrentLocale] = useState(localeProp ?? localeInStorage ?? defaultLocaleProp ?? defaultLocaleConfig);
28
+ useEffect(() => {
29
+ if (localeProp && localeProp !== currentLocale) setCurrentLocale(localeProp);
30
+ }, [
31
+ localeProp,
32
+ currentLocale,
33
+ setCurrentLocale
34
+ ]);
35
+ const setLocaleBase = (newLocale) => {
36
+ if (currentLocale.toString() === newLocale.toString()) return;
37
+ if (!availableLocales?.map(String).includes(newLocale)) {
38
+ console.error(`Locale ${newLocale} is not available`);
39
+ return;
40
+ }
41
+ setCurrentLocale(newLocale);
42
+ setLocaleInStorage(newLocale, isCookieEnabled ?? true);
43
+ };
44
+ const setLocale = setLocaleProp ?? setLocaleBase;
45
+ const resolvedLocale = localeResolver(localeProp ?? currentLocale);
46
+ return /* @__PURE__ */ jsx(IntlayerClientContext.Provider, {
47
+ value: {
48
+ locale: resolvedLocale,
49
+ setLocale,
50
+ isCookieEnabled
51
+ },
52
+ children
53
+ });
54
+ };
55
+ /**
56
+ * Main provider for Intlayer in Preact applications.
57
+ *
58
+ * It provides the Intlayer context to your application, allowing the use
59
+ * of hooks like `useIntlayer` and `useLocale`.
60
+ *
61
+ * @param props - The provider props.
62
+ * @returns The provider component.
63
+ *
64
+ * @example
65
+ * ```tsx
66
+ * import { IntlayerProvider } from 'preact-intlayer';
67
+ *
68
+ * const App = () => (
69
+ * <IntlayerProvider>
70
+ * <MyComponent />
71
+ * </IntlayerProvider>
72
+ * );
73
+ * ```
74
+ */
75
+ const IntlayerProvider = ({ children, ...props }) => /* @__PURE__ */ jsxs(IntlayerProviderContent, {
76
+ ...props,
77
+ children: [/* @__PURE__ */ jsx(EditorProvider, {}), children]
78
+ });
79
+
80
+ //#endregion
81
+ export { IntlayerClientContext, IntlayerProvider, IntlayerProviderContent, useIntlayerContext };
82
+ //# sourceMappingURL=IntlayerProvider.mjs.map
@@ -0,0 +1 @@
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 type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport {\n type ComponentChild,\n createContext,\n type FunctionComponent,\n} from 'preact';\nimport { useContext, useEffect, useState } from 'preact/hooks';\nimport { EditorProvider } from '../editor/EditorProvider';\nimport { localeInStorage, setLocaleInStorage } from './useLocaleStorage';\n\ntype IntlayerValue = {\n locale: LocalesValues;\n setLocale: (newLocale: LocalesValues) => void;\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});\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 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 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] = useState<LocalesValues>(\n defaultLocale as LocalesValues\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 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 children,\n ...props\n}) => (\n <IntlayerProviderContent {...props}>\n <EditorProvider />\n {children}\n </IntlayerProviderContent>\n);\n"],"mappings":";;;;;;;;;;;;AAqBA,MAAa,wBAAwB,cAA6B;CAChE,QAAQ,mBAAmB,eAAe,sBAAsB;CAChE,iBAAiB;CAClB,CAAC;;;;AAKF,MAAa,2BAA2B,WAAW,sBAAsB;;;;AAazE,MAAa,2BAER,EACH,QAAQ,YACR,eAAe,mBACf,UACA,WAAW,eACX,sBACI;CACJ,MAAM,EAAE,yBAAyB,iBAAiB,EAAE;CACpD,MAAM,EAAE,eAAe,qBAAqB,SAAS,qBACnD,wBAAwB,EAAE;CAK5B,MAAM,CAAC,eAAe,oBAAoB,SAFxC,cAAc,mBAAmB,qBAAqB,oBAIvD;AAED,iBAAgB;AACd,MAAI,cAAc,eAAe,cAC/B,kBAAiB,WAAW;IAE7B;EAAC;EAAY;EAAe;EAAiB,CAAC;CAEjD,MAAM,iBAAiB,cAA6B;AAClD,MAAI,cAAc,UAAU,KAAK,UAAU,UAAU,CAAE;AAEvD,MAAI,CAAC,kBAAkB,IAAI,OAAO,CAAC,SAAS,UAAU,EAAE;AACtD,WAAQ,MAAM,UAAU,UAAU,mBAAmB;AACrD;;AAGF,mBAAiB,UAAU;AAC3B,qBAAmB,WAAW,mBAAmB,KAAK;;CAGxD,MAAM,YAAY,iBAAiB;CAEnC,MAAM,iBAAiB,eAAe,cAAc,cAAc;AAElE,QACE,oBAAC,sBAAsB,UAAvB;EACE,OAAO;GACL,QAAQ;GACR;GACA;GACD;EAEA;EAC8B;;;;;;;;;;;;;;;;;;;;;;AAwBrC,MAAa,oBAA8D,EACzE,UACA,GAAG,YAEH,qBAAC,yBAAD;CAAyB,GAAI;WAA7B,CACE,oBAAC,gBAAD,EAAkB,GACjB,SACuB"}
@@ -1 +1,10 @@
1
- import{useUnit as e}from"./useUnit.mjs";import{useDate as t}from"./useDate.mjs";import{useNumber as n}from"./useNumber.mjs";import{useRelativeTime as r}from"./useRelativeTime.mjs";import{useCompact as i}from"./useCompact.mjs";import{useList as a}from"./useList.mjs";import{usePercentage as o}from"./usePercentage.mjs";import{useCurrency as s}from"./useCurrency.mjs";export{i as useCompact,s as useCurrency,t as useDate,a as useList,n as useNumber,o as usePercentage,r as useRelativeTime,e as useUnit};
1
+ import { useUnit } from "./useUnit.mjs";
2
+ import { useDate } from "./useDate.mjs";
3
+ import { useNumber } from "./useNumber.mjs";
4
+ import { useRelativeTime } from "./useRelativeTime.mjs";
5
+ import { useCompact } from "./useCompact.mjs";
6
+ import { useList } from "./useList.mjs";
7
+ import { usePercentage } from "./usePercentage.mjs";
8
+ import { useCurrency } from "./useCurrency.mjs";
9
+
10
+ export { useCompact, useCurrency, useDate, useList, useNumber, usePercentage, useRelativeTime, useUnit };
@@ -1,2 +1,26 @@
1
- import{t as e}from"../../IntlayerProvider-ClOcEK3A.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};
1
+ import { IntlayerClientContext } from "../IntlayerProvider.mjs";
2
+ import { useCallback, useContext } from "preact/hooks";
3
+ import { compact } from "@intlayer/core/formatters";
4
+
5
+ //#region src/client/format/useCompact.ts
6
+ /**
7
+ * React client hook that provides a compact number formatter
8
+ * bound to the current application locale.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * const formatCompact = useCompact();
13
+ * formatCompact(1500); // "1.5K"
14
+ * ```
15
+ */
16
+ const useCompact = () => {
17
+ const { locale } = useContext(IntlayerClientContext);
18
+ return useCallback((...args) => compact(args[0], {
19
+ ...args[1],
20
+ locale: args[1]?.locale ?? locale
21
+ }), [locale]);
22
+ };
23
+
24
+ //#endregion
25
+ export { useCompact };
2
26
  //# sourceMappingURL=useCompact.mjs.map
@@ -1 +1 @@
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":"uKAcA,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
+ {"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":";;;;;;;;;;;;;;;AAcA,MAAa,mBAAmB;CAC9B,MAAM,EAAE,WAAW,WAAW,sBAAsB;AAEpD,QAAO,aACJ,GAAG,SACF,QAAQ,KAAK,IAAI;EACf,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC,EACJ,CAAC,OAAO,CACT"}
@@ -1,2 +1,40 @@
1
- import{t as e}from"../../IntlayerProvider-ClOcEK3A.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};
1
+ import { IntlayerClientContext } from "../IntlayerProvider.mjs";
2
+ import { useCallback, useContext } from "preact/hooks";
3
+ import { currency } from "@intlayer/core/formatters";
4
+
5
+ //#region src/client/format/useCurrency.ts
6
+ /**
7
+ * React client hook that provides a currency formatter
8
+ * bound to the current application locale.
9
+ *
10
+ * @returns {(value: string | number, options?: CurrencyProps) => string}
11
+ * A function to format numbers into localized currency strings.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * const formatCurrency = useCurrency();
16
+ *
17
+ * formatCurrency(1500, { currency: "USD" });
18
+ * // "$1,500.00"
19
+ *
20
+ * formatCurrency(1500, { currency: "EUR", locale: "de-DE" });
21
+ * // "1.500,00 €"
22
+ *
23
+ * formatCurrency(9876543.21, {
24
+ * currency: "JPY",
25
+ * fractionDigits: 0,
26
+ * });
27
+ * // "¥9,876,543"
28
+ * ```
29
+ */
30
+ const useCurrency = () => {
31
+ const { locale } = useContext(IntlayerClientContext);
32
+ return useCallback((...args) => currency(args[0], {
33
+ ...args[1],
34
+ locale: args[1]?.locale ?? locale
35
+ }), [locale]);
36
+ };
37
+
38
+ //#endregion
39
+ export { useCurrency };
2
40
  //# sourceMappingURL=useCurrency.mjs.map
@@ -1 +1 @@
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":"wKA4BA,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
+ {"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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAa,oBAAoB;CAC/B,MAAM,EAAE,WAAW,WAAW,sBAAsB;AAEpD,QAAO,aACJ,GAAG,SACF,SAAS,KAAK,IAAI;EAChB,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC,EACJ,CAAC,OAAO,CACT"}
@@ -1,2 +1,42 @@
1
- import{t as e}from"../../IntlayerProvider-ClOcEK3A.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};
1
+ import { IntlayerClientContext } from "../IntlayerProvider.mjs";
2
+ import { useContext } from "preact/hooks";
3
+ import { date } from "@intlayer/core/formatters";
4
+
5
+ //#region src/client/format/useDate.ts
6
+ /**
7
+ * React client hook that provides a localized date/time formatter
8
+ * bound to the current application locale.
9
+ *
10
+ * @returns {(date: Date | string | number, options?: DateProps) => string}
11
+ * A function to format dates or timestamps into localized date/time strings.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * const formatDate = useDate();
16
+ *
17
+ * formatDate(new Date("2025-01-01"));
18
+ * // "Jan 1, 2025"
19
+ *
20
+ * formatDate("2025-01-01T15:30:00Z", {
21
+ * dateStyle: "full",
22
+ * timeStyle: "short",
23
+ * });
24
+ * // "Wednesday, January 1, 2025 at 3:30 PM"
25
+ *
26
+ * formatDate(1735689600000, { locale: "fr-FR", dateStyle: "long" });
27
+ * // "1 janvier 2025"
28
+ * ```
29
+ *
30
+ * @see createDate
31
+ */
32
+ const useDate = () => {
33
+ const { locale } = useContext(IntlayerClientContext);
34
+ return (...args) => date(args[0], {
35
+ ...args[1],
36
+ locale: args[1]?.locale ?? locale
37
+ });
38
+ };
39
+
40
+ //#endregion
41
+ export { useDate };
2
42
  //# sourceMappingURL=useDate.mjs.map
@@ -1 +1 @@
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":"mJA8BA,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
+ {"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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,MAAa,gBAAgB;CAC3B,MAAM,EAAE,WAAW,WAAW,sBAAsB;AAEpD,SAAQ,GAAG,SACT,KAAK,KAAK,IAAI;EACZ,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC"}
@@ -1,2 +1,32 @@
1
- import{t as e}from"../../IntlayerProvider-ClOcEK3A.mjs";import{useContext as t,useMemo as n}from"preact/hooks";import{bindIntl as r}from"@intlayer/core/formatters";const i=i=>{let{locale:a}=t(e),o=i??a;return n(()=>r(o),[o])};export{i as useIntl};
1
+ import { IntlayerClientContext } from "../IntlayerProvider.mjs";
2
+ import { useContext, useMemo } from "preact/hooks";
3
+ import { bindIntl } from "@intlayer/core/formatters";
4
+
5
+ //#region src/client/format/useIntl.ts
6
+ /**
7
+ * Preact client hook that provides a locale-bound `Intl` object.
8
+ *
9
+ * It acts exactly like the native `Intl` object, but acts as a proxy to:
10
+ * 1. Inject the current locale automatically if none is provided.
11
+ * 2. Use the performance-optimized `CachedIntl` under the hood.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * const intl = useIntl(); // uses context locale
16
+ *
17
+ * // Standard API, but no need to pass locale as the first argument
18
+ * const formatted = new intl.NumberFormat({
19
+ * style: 'currency',
20
+ * currency: 'USD'
21
+ * }).format(123.45);
22
+ * ```
23
+ */
24
+ const useIntl = (locale) => {
25
+ const { locale: contextLocale } = useContext(IntlayerClientContext);
26
+ const currentLocale = locale ?? contextLocale;
27
+ return useMemo(() => bindIntl(currentLocale), [currentLocale]);
28
+ };
29
+
30
+ //#endregion
31
+ export { useIntl };
2
32
  //# sourceMappingURL=useIntl.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useIntl.mjs","names":[],"sources":["../../../../src/client/format/useIntl.ts"],"sourcesContent":["import { bindIntl, type WrappedIntl } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * Preact client hook that provides a locale-bound `Intl` object.\n *\n * It acts exactly like the native `Intl` object, but acts as a proxy to:\n * 1. Inject the current locale automatically if none is provided.\n * 2. Use the performance-optimized `CachedIntl` under the hood.\n *\n * @example\n * ```tsx\n * const intl = useIntl(); // uses context locale\n *\n * // Standard API, but no need to pass locale as the first argument\n * const formatted = new intl.NumberFormat({\n * style: 'currency',\n * currency: 'USD'\n * }).format(123.45);\n * ```\n */\nexport const useIntl = (locale?: LocalesValues) => {\n const { locale: contextLocale } = useContext(IntlayerClientContext);\n const currentLocale = locale ?? contextLocale;\n\n return useMemo<WrappedIntl>(() => bindIntl(currentLocale), [currentLocale]);\n};\n"],"mappings":"oKAuBA,MAAa,EAAW,GAA2B,CACjD,GAAM,CAAE,OAAQ,GAAkB,EAAW,EAAsB,CAC7D,EAAgB,GAAU,EAEhC,OAAO,MAA2B,EAAS,EAAc,CAAE,CAAC,EAAc,CAAC"}
1
+ {"version":3,"file":"useIntl.mjs","names":[],"sources":["../../../../src/client/format/useIntl.ts"],"sourcesContent":["import { bindIntl, type WrappedIntl } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'preact/hooks';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * Preact client hook that provides a locale-bound `Intl` object.\n *\n * It acts exactly like the native `Intl` object, but acts as a proxy to:\n * 1. Inject the current locale automatically if none is provided.\n * 2. Use the performance-optimized `CachedIntl` under the hood.\n *\n * @example\n * ```tsx\n * const intl = useIntl(); // uses context locale\n *\n * // Standard API, but no need to pass locale as the first argument\n * const formatted = new intl.NumberFormat({\n * style: 'currency',\n * currency: 'USD'\n * }).format(123.45);\n * ```\n */\nexport const useIntl = (locale?: LocalesValues) => {\n const { locale: contextLocale } = useContext(IntlayerClientContext);\n const currentLocale = locale ?? contextLocale;\n\n return useMemo<WrappedIntl>(() => bindIntl(currentLocale), [currentLocale]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,WAAW,WAA2B;CACjD,MAAM,EAAE,QAAQ,kBAAkB,WAAW,sBAAsB;CACnE,MAAM,gBAAgB,UAAU;AAEhC,QAAO,cAA2B,SAAS,cAAc,EAAE,CAAC,cAAc,CAAC"}
@@ -1,2 +1,37 @@
1
- import{t as e}from"../../IntlayerProvider-ClOcEK3A.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};
1
+ import { IntlayerClientContext } from "../IntlayerProvider.mjs";
2
+ import { useCallback, useContext } from "preact/hooks";
3
+ import { list } from "@intlayer/core/formatters";
4
+
5
+ //#region src/client/format/useList.ts
6
+ /**
7
+ * React client hook that provides a list formatter
8
+ * bound to the current application locale.
9
+ *
10
+ * @returns {(values: (string | number)[], options?: ListProps) => string}
11
+ * A function to format arrays into localized list strings.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * const formatList = useList();
16
+ *
17
+ * formatList(['apple', 'banana', 'orange']);
18
+ * // "apple, banana, and orange"
19
+ *
20
+ * formatList(['red', 'green', 'blue'], { type: 'disjunction' });
21
+ * // "red, green, or blue"
22
+ *
23
+ * formatList([1, 2, 3], { type: 'unit', locale: 'de-DE' });
24
+ * // "1, 2 und 3"
25
+ * ```
26
+ */
27
+ const useList = () => {
28
+ const { locale } = useContext(IntlayerClientContext);
29
+ return useCallback((...args) => list(args[0], {
30
+ ...args[1],
31
+ locale: args[1]?.locale ?? locale
32
+ }), [locale]);
33
+ };
34
+
35
+ //#endregion
36
+ export { useList };
2
37
  //# sourceMappingURL=useList.mjs.map
@@ -1 +1 @@
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":"oKAyBA,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
+ {"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":";;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,MAAa,gBAAgB;CAC3B,MAAM,EAAE,WAAW,WAAW,sBAAsB;AAEpD,QAAO,aACJ,GAAG,SACF,KAAK,KAAK,IAAI;EACZ,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC,EACJ,CAAC,OAAO,CACT"}
@@ -1,2 +1,38 @@
1
- import{t as e}from"../../IntlayerProvider-ClOcEK3A.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};
1
+ import { IntlayerClientContext } from "../IntlayerProvider.mjs";
2
+ import { useCallback, useContext } from "preact/hooks";
3
+ import { number } from "@intlayer/core/formatters";
4
+
5
+ //#region src/client/format/useNumber.ts
6
+ /**
7
+ * React client hook that provides a localized number formatter.
8
+ *
9
+ * Uses the current locale from {@link useLocaleBase} and returns
10
+ * a function that can be used to format numbers consistently
11
+ * according to the user's locale.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * const formatNumber = useNumber();
16
+ *
17
+ * formatNumber(12345);
18
+ * // e.g. "12,345" (en-US)
19
+ * // e.g. "12 345" (fr-FR)
20
+ *
21
+ * formatNumber(0.75, { style: "percent" });
22
+ * // e.g. "75%"
23
+ * ```
24
+ *
25
+ * @returns {(value: string | number, options?: import("../createNumber").NumberProps) => string}
26
+ * A number formatting function bound to the active locale.
27
+ */
28
+ const useNumber = () => {
29
+ const { locale } = useContext(IntlayerClientContext);
30
+ return useCallback((...args) => number(args[0], {
31
+ ...args[1],
32
+ locale: args[1]?.locale ?? locale
33
+ }), [locale]);
34
+ };
35
+
36
+ //#endregion
37
+ export { useNumber };
2
38
  //# sourceMappingURL=useNumber.mjs.map
@@ -1 +1 @@
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":"sKA0BA,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
+ {"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":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,kBAAkB;CAC7B,MAAM,EAAE,WAAW,WAAW,sBAAsB;AAEpD,QAAO,aACJ,GAAG,SACF,OAAO,KAAK,IAAI;EACd,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC,EACJ,CAAC,OAAO,CACT"}
@@ -1,2 +1,34 @@
1
- import{t as e}from"../../IntlayerProvider-ClOcEK3A.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};
1
+ import { IntlayerClientContext } from "../IntlayerProvider.mjs";
2
+ import { useCallback, useContext } from "preact/hooks";
3
+ import { percentage } from "@intlayer/core/formatters";
4
+
5
+ //#region src/client/format/usePercentage.ts
6
+ /**
7
+ * React hook to provide a percentage formatter function
8
+ * based on the current application locale.
9
+ *
10
+ * This hook retrieves the active locale using {@link useLocaleBase}
11
+ * and memoizes a `createPercentage` instance for that locale.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * const formatPercentage = usePercentage();
16
+ *
17
+ * const result = formatPercentage(0.875, { maximumFractionDigits: 1 });
18
+ * // "87.5%" (depending on locale)
19
+ * ```
20
+ *
21
+ * @returns {(value: string | number, options?: Omit<PercentageOptions, "value">) => string}
22
+ * A function that formats numbers or numeric strings into localized percentages.
23
+ */
24
+ const usePercentage = () => {
25
+ const { locale } = useContext(IntlayerClientContext);
26
+ return useCallback((...args) => percentage(args[0], {
27
+ ...args[1],
28
+ locale: args[1]?.locale ?? locale
29
+ }), [locale]);
30
+ };
31
+
32
+ //#endregion
33
+ export { usePercentage };
2
34
  //# sourceMappingURL=usePercentage.mjs.map