angular-intlayer 8.5.0 → 8.5.1

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 (142) hide show
  1. package/dist/cjs/@intlayer/editor/src/isEnabled.cjs +1 -1
  2. package/dist/cjs/@intlayer/editor/src/isEnabled.cjs.map +1 -1
  3. package/dist/cjs/UI/IntlayerNode.component.cjs +53 -0
  4. package/dist/cjs/UI/IntlayerNode.component.cjs.map +1 -0
  5. package/dist/cjs/UI/index.cjs +9 -0
  6. package/dist/cjs/client/index.cjs +4 -10
  7. package/dist/cjs/client/installIntlayer.cjs +19 -48
  8. package/dist/cjs/client/installIntlayer.cjs.map +1 -1
  9. package/dist/cjs/client/intlayerToken.cjs +36 -0
  10. package/dist/cjs/client/intlayerToken.cjs.map +1 -0
  11. package/dist/cjs/client/useDictionary.cjs +2 -2
  12. package/dist/cjs/client/useDictionary.cjs.map +1 -1
  13. package/dist/cjs/client/useDictionaryAsync.cjs +2 -2
  14. package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
  15. package/dist/cjs/client/useDictionaryDynamic.cjs +2 -2
  16. package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
  17. package/dist/cjs/client/useIntlayer.cjs +2 -2
  18. package/dist/cjs/client/useIntlayer.cjs.map +1 -1
  19. package/dist/cjs/client/useLocale.cjs +2 -2
  20. package/dist/cjs/client/useLocale.cjs.map +1 -1
  21. package/dist/cjs/editor/EditorProvider.component.cjs +27 -0
  22. package/dist/cjs/editor/EditorProvider.component.cjs.map +1 -0
  23. package/dist/cjs/editor/index.cjs +19 -0
  24. package/dist/cjs/editor/useEditor.cjs +47 -12
  25. package/dist/cjs/editor/useEditor.cjs.map +1 -1
  26. package/dist/cjs/format/index.cjs +20 -0
  27. package/dist/cjs/format/useCompact.cjs +18 -0
  28. package/dist/cjs/format/useCompact.cjs.map +1 -0
  29. package/dist/cjs/format/useCurrency.cjs +18 -0
  30. package/dist/cjs/format/useCurrency.cjs.map +1 -0
  31. package/dist/cjs/format/useDate.cjs +28 -0
  32. package/dist/cjs/format/useDate.cjs.map +1 -0
  33. package/dist/cjs/format/useIntl.cjs +20 -0
  34. package/dist/cjs/format/useIntl.cjs.map +1 -0
  35. package/dist/cjs/format/useList.cjs +18 -0
  36. package/dist/cjs/format/useList.cjs.map +1 -0
  37. package/dist/cjs/format/useNumber.cjs +21 -0
  38. package/dist/cjs/format/useNumber.cjs.map +1 -0
  39. package/dist/cjs/format/usePercentage.cjs +18 -0
  40. package/dist/cjs/format/usePercentage.cjs.map +1 -0
  41. package/dist/cjs/format/useRelativeTime.cjs +18 -0
  42. package/dist/cjs/format/useRelativeTime.cjs.map +1 -0
  43. package/dist/cjs/format/useUnit.cjs +18 -0
  44. package/dist/cjs/format/useUnit.cjs.map +1 -0
  45. package/dist/cjs/index.cjs +7 -6
  46. package/dist/cjs/renderIntlayerNode.cjs +2 -1
  47. package/dist/cjs/renderIntlayerNode.cjs.map +1 -1
  48. package/dist/esm/@intlayer/editor/src/isEnabled.mjs +1 -1
  49. package/dist/esm/@intlayer/editor/src/isEnabled.mjs.map +1 -1
  50. package/dist/esm/UI/IntlayerNode.component.mjs +46 -0
  51. package/dist/esm/UI/IntlayerNode.component.mjs.map +1 -0
  52. package/dist/esm/UI/index.mjs +3 -0
  53. package/dist/esm/client/index.mjs +3 -3
  54. package/dist/esm/client/installIntlayer.mjs +15 -37
  55. package/dist/esm/client/installIntlayer.mjs.map +1 -1
  56. package/dist/esm/client/intlayerToken.mjs +31 -0
  57. package/dist/esm/client/intlayerToken.mjs.map +1 -0
  58. package/dist/esm/client/useDictionary.mjs +1 -1
  59. package/dist/esm/client/useDictionary.mjs.map +1 -1
  60. package/dist/esm/client/useDictionaryAsync.mjs +1 -1
  61. package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
  62. package/dist/esm/client/useDictionaryDynamic.mjs +1 -1
  63. package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
  64. package/dist/esm/client/useIntlayer.mjs +1 -1
  65. package/dist/esm/client/useIntlayer.mjs.map +1 -1
  66. package/dist/esm/client/useLocale.mjs +1 -1
  67. package/dist/esm/editor/EditorProvider.component.mjs +20 -0
  68. package/dist/esm/editor/EditorProvider.component.mjs.map +1 -0
  69. package/dist/esm/editor/index.mjs +5 -0
  70. package/dist/esm/editor/useEditor.mjs +48 -14
  71. package/dist/esm/editor/useEditor.mjs.map +1 -1
  72. package/dist/esm/format/index.mjs +11 -0
  73. package/dist/esm/format/useCompact.mjs +16 -0
  74. package/dist/esm/format/useCompact.mjs.map +1 -0
  75. package/dist/esm/format/useCurrency.mjs +16 -0
  76. package/dist/esm/format/useCurrency.mjs.map +1 -0
  77. package/dist/esm/format/useDate.mjs +26 -0
  78. package/dist/esm/format/useDate.mjs.map +1 -0
  79. package/dist/esm/format/useIntl.mjs +18 -0
  80. package/dist/esm/format/useIntl.mjs.map +1 -0
  81. package/dist/esm/format/useList.mjs +16 -0
  82. package/dist/esm/format/useList.mjs.map +1 -0
  83. package/dist/esm/format/useNumber.mjs +19 -0
  84. package/dist/esm/format/useNumber.mjs.map +1 -0
  85. package/dist/esm/format/usePercentage.mjs +16 -0
  86. package/dist/esm/format/usePercentage.mjs.map +1 -0
  87. package/dist/esm/format/useRelativeTime.mjs +16 -0
  88. package/dist/esm/format/useRelativeTime.mjs.map +1 -0
  89. package/dist/esm/format/useUnit.mjs +16 -0
  90. package/dist/esm/format/useUnit.mjs.map +1 -0
  91. package/dist/esm/index.mjs +4 -3
  92. package/dist/esm/renderIntlayerNode.mjs +2 -1
  93. package/dist/esm/renderIntlayerNode.mjs.map +1 -1
  94. package/dist/types/UI/IntlayerNode.component.d.ts +27 -0
  95. package/dist/types/UI/IntlayerNode.component.d.ts.map +1 -0
  96. package/dist/types/UI/index.d.ts +2 -0
  97. package/dist/types/client/index.d.ts +3 -3
  98. package/dist/types/client/installIntlayer.d.ts +10 -21
  99. package/dist/types/client/installIntlayer.d.ts.map +1 -1
  100. package/dist/types/client/intlayerToken.d.ts +19 -0
  101. package/dist/types/client/intlayerToken.d.ts.map +1 -0
  102. package/dist/types/client/useDictionaryAsync.d.ts.map +1 -1
  103. package/dist/types/client/useDictionaryDynamic.d.ts +2 -2
  104. package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
  105. package/dist/types/client/useIntlayer.d.ts.map +1 -1
  106. package/dist/types/client/useLocale.d.ts +3 -3
  107. package/dist/types/client/useLocaleStorage.d.ts +5 -5
  108. package/dist/types/client/useLocaleStorage.d.ts.map +1 -1
  109. package/dist/types/editor/EditorProvider.component.d.ts +33 -0
  110. package/dist/types/editor/EditorProvider.component.d.ts.map +1 -0
  111. package/dist/types/editor/index.d.ts +4 -0
  112. package/dist/types/editor/useEditor.d.ts +35 -2
  113. package/dist/types/editor/useEditor.d.ts.map +1 -1
  114. package/dist/types/format/index.d.ts +10 -0
  115. package/dist/types/format/useCompact.d.ts +10 -0
  116. package/dist/types/format/useCompact.d.ts.map +1 -0
  117. package/dist/types/format/useCurrency.d.ts +10 -0
  118. package/dist/types/format/useCurrency.d.ts.map +1 -0
  119. package/dist/types/format/useDate.d.ts +14 -0
  120. package/dist/types/format/useDate.d.ts.map +1 -0
  121. package/dist/types/format/useIntl.d.ts +12 -0
  122. package/dist/types/format/useIntl.d.ts.map +1 -0
  123. package/dist/types/format/useList.d.ts +14 -0
  124. package/dist/types/format/useList.d.ts.map +1 -0
  125. package/dist/types/format/useNumber.d.ts +13 -0
  126. package/dist/types/format/useNumber.d.ts.map +1 -0
  127. package/dist/types/format/usePercentage.d.ts +10 -0
  128. package/dist/types/format/usePercentage.d.ts.map +1 -0
  129. package/dist/types/format/useRelativeTime.d.ts +11 -0
  130. package/dist/types/format/useRelativeTime.d.ts.map +1 -0
  131. package/dist/types/format/useUnit.d.ts +10 -0
  132. package/dist/types/format/useUnit.d.ts.map +1 -0
  133. package/dist/types/index.d.ts +4 -3
  134. package/dist/types/index.d.ts.map +1 -1
  135. package/dist/types/intlayer/dist/types/index.d.ts +4 -0
  136. package/package.json +32 -8
  137. package/dist/cjs/client/useIntl.cjs +0 -41
  138. package/dist/cjs/client/useIntl.cjs.map +0 -1
  139. package/dist/esm/client/useIntl.mjs +0 -39
  140. package/dist/esm/client/useIntl.mjs.map +0 -1
  141. package/dist/types/client/useIntl.d.ts +0 -33
  142. package/dist/types/client/useIntl.d.ts.map +0 -1
@@ -3,7 +3,7 @@ let _intlayer_config_built = require("@intlayer/config/built");
3
3
  _intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
4
4
 
5
5
  //#region ../@intlayer/editor/src/isEnabled.ts
6
- const isEnabled = process.env.INTLAYER_EDITOR_ENABLED !== "false" && _intlayer_config_built.default.editor?.enabled && typeof window !== "undefined" && window.self !== window.top;
6
+ const isEnabled = process.env["INTLAYER_EDITOR_ENABLED"] !== "false" && _intlayer_config_built.default.editor?.enabled && typeof window !== "undefined" && window.self !== window.top;
7
7
 
8
8
  //#endregion
9
9
  exports.isEnabled = isEnabled;
@@ -1 +1 @@
1
- {"version":3,"file":"isEnabled.cjs","names":["configuration"],"sources":["../../../../../../@intlayer/editor/src/isEnabled.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\n\nexport const isEnabled =\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' && // Allow purging a build time using bundler + env var\n configuration.editor?.enabled && // Editor enabled in config\n typeof window !== 'undefined' && // Client side\n window.self !== window.top; // Is in iframe\n"],"mappings":";;;;;AAEA,MAAa,YACX,QAAQ,IAAI,4BAA4B,WACxCA,+BAAc,QAAQ,WACtB,OAAO,WAAW,eAClB,OAAO,SAAS,OAAO"}
1
+ {"version":3,"file":"isEnabled.cjs","names":["configuration"],"sources":["../../../../../../@intlayer/editor/src/isEnabled.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\n\nexport const isEnabled =\n process.env['INTLAYER_EDITOR_ENABLED'] !== 'false' && // Allow purging a build time using bundler + env var // Keep env['INTLAYER_EDITOR_ENABLED'] syntax for angular to treat it as\n configuration.editor?.enabled && // Editor enabled in config\n typeof window !== 'undefined' && // Client side\n window.self !== window.top; // Is in iframe\n"],"mappings":";;;;;AAEA,MAAa,YACX,QAAQ,IAAI,+BAA+B,WAC3CA,+BAAc,QAAQ,WACtB,OAAO,WAAW,eAClB,OAAO,SAAS,OAAO"}
@@ -0,0 +1,53 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ const require_decorateMetadata = require('../_virtual/_@oxc-project_runtime@0.115.0/helpers/decorateMetadata.cjs');
4
+ const require_decorate = require('../_virtual/_@oxc-project_runtime@0.115.0/helpers/decorate.cjs');
5
+ let _angular_core = require("@angular/core");
6
+
7
+ //#region src/UI/IntlayerNode.component.ts
8
+ let IntlayerNodeComponent = class IntlayerNodeComponent {
9
+ node;
10
+ vcr = (0, _angular_core.inject)(_angular_core.ViewContainerRef);
11
+ elRef = (0, _angular_core.inject)(_angular_core.ElementRef);
12
+ cdr = (0, _angular_core.inject)(_angular_core.ChangeDetectorRef);
13
+ ngOnChanges(changes) {
14
+ if (changes["node"]) this.render();
15
+ }
16
+ render() {
17
+ this.vcr.clear();
18
+ const host = this.elRef.nativeElement;
19
+ host.childNodes.forEach((n) => {
20
+ if (n.nodeType === Node.TEXT_NODE) n.parentNode?.removeChild(n);
21
+ });
22
+ if (!this.node) return;
23
+ const nodeInfo = typeof this.node?.children === "function" ? this.node.children() : this.node;
24
+ if (nodeInfo?.component && typeof nodeInfo.component !== "string") {
25
+ const componentRef = this.vcr.createComponent(nodeInfo.component);
26
+ if (nodeInfo.props) for (const [key, value] of Object.entries(nodeInfo.props)) componentRef.instance[key] = value;
27
+ if (nodeInfo.children) {
28
+ const content = nodeInfo.children;
29
+ if (typeof content === "string" || typeof content === "number") componentRef.location.nativeElement.appendChild(document.createTextNode(String(content)));
30
+ }
31
+ this.cdr.markForCheck();
32
+ } else {
33
+ const text = this.node?.value ?? this.node?.toString?.() ?? String(this.node);
34
+ host.appendChild(document.createTextNode(text));
35
+ }
36
+ }
37
+ };
38
+ require_decorate.__decorate([(0, _angular_core.Input)(), require_decorateMetadata.__decorateMetadata("design:type", Object)], IntlayerNodeComponent.prototype, "node", void 0);
39
+ IntlayerNodeComponent = require_decorate.__decorate([(0, _angular_core.Component)({
40
+ selector: "intlayer-node",
41
+ standalone: true,
42
+ template: `<ng-container #anchor></ng-container>`,
43
+ styles: [`:host { display: contents; }`]
44
+ })], IntlayerNodeComponent);
45
+
46
+ //#endregion
47
+ Object.defineProperty(exports, 'IntlayerNodeComponent', {
48
+ enumerable: true,
49
+ get: function () {
50
+ return IntlayerNodeComponent;
51
+ }
52
+ });
53
+ //# sourceMappingURL=IntlayerNode.component.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntlayerNode.component.cjs","names":["ViewContainerRef","ElementRef","ChangeDetectorRef"],"sources":["../../../src/UI/IntlayerNode.component.ts"],"sourcesContent":["import {\n ChangeDetectorRef,\n Component,\n ElementRef,\n Input,\n inject,\n type OnChanges,\n type SimpleChanges,\n type Type,\n ViewContainerRef,\n} from '@angular/core';\n\n/**\n * A transparent host element that renders Intlayer content nodes.\n *\n * `display: contents` makes the `<intlayer-node>` element invisible in the\n * layout — its children appear as if they were direct children of the parent,\n * so placing this component inside `<h1>`, `<p>`, etc. does not break the\n * document structure.\n *\n * ### Usage\n * ```html\n * <h1><intlayer-node [node]=\"content().title\"></intlayer-node></h1>\n * ```\n */\n@Component({\n selector: 'intlayer-node',\n standalone: true,\n // The ng-content slot is the anchor point for ViewContainerRef.\n // Wrapping text renders directly inside this host thanks to display:contents.\n template: `<ng-container #anchor></ng-container>`,\n // display:contents collapses the host box so it is layout-transparent.\n styles: [`:host { display: contents; }`],\n})\nexport class IntlayerNodeComponent implements OnChanges {\n @Input() node: any;\n\n private vcr = inject(ViewContainerRef);\n private elRef = inject<ElementRef<HTMLElement>>(ElementRef);\n private cdr = inject(ChangeDetectorRef);\n\n ngOnChanges(changes: SimpleChanges): void {\n if (changes['node']) {\n this.render();\n }\n }\n\n private render() {\n // Clear previously created views / text nodes\n this.vcr.clear();\n const host = this.elRef.nativeElement;\n // Remove any raw text nodes we injected directly on previous renders\n host.childNodes.forEach((n) => {\n if (n.nodeType === Node.TEXT_NODE) n.parentNode?.removeChild(n);\n });\n\n if (!this.node) return;\n\n // The node returned by the Angular plugin is a Proxy whose `.children`\n // property is a function returning component info (editor on) or the raw\n // value (editor off).\n const nodeInfo =\n typeof this.node?.children === 'function'\n ? this.node.children()\n : this.node;\n\n if (nodeInfo?.component && typeof nodeInfo.component !== 'string') {\n // ── Editor enabled path: create the ContentSelectorWrapper component ──\n const componentRef = this.vcr.createComponent(\n nodeInfo.component as Type<any>\n );\n\n if (nodeInfo.props) {\n for (const [key, value] of Object.entries(nodeInfo.props)) {\n (componentRef.instance as any)[key] = value;\n }\n }\n\n if (nodeInfo.children) {\n const content = nodeInfo.children;\n if (typeof content === 'string' || typeof content === 'number') {\n componentRef.location.nativeElement.appendChild(\n document.createTextNode(String(content))\n );\n }\n }\n\n this.cdr.markForCheck();\n } else {\n // ── Editor disabled path: render plain text inside the host ──────────\n const text =\n this.node?.value ?? this.node?.toString?.() ?? String(this.node);\n // Append a text node directly inside the host element.\n // Because the host has `display: contents`, this text is layout-wise a\n // direct child of the surrounding element (e.g. <h1>).\n host.appendChild(document.createTextNode(text));\n }\n }\n}\n"],"mappings":";;;;;;;AAkCO,kCAAM,sBAA2C;CACtD,AAAS;CAET,AAAQ,gCAAaA,+BAAiB;CACtC,AAAQ,kCAAwCC,yBAAW;CAC3D,AAAQ,gCAAaC,gCAAkB;CAEvC,YAAY,SAA8B;AACxC,MAAI,QAAQ,QACV,MAAK,QAAQ;;CAIjB,AAAQ,SAAS;AAEf,OAAK,IAAI,OAAO;EAChB,MAAM,OAAO,KAAK,MAAM;AAExB,OAAK,WAAW,SAAS,MAAM;AAC7B,OAAI,EAAE,aAAa,KAAK,UAAW,GAAE,YAAY,YAAY,EAAE;IAC/D;AAEF,MAAI,CAAC,KAAK,KAAM;EAKhB,MAAM,WACJ,OAAO,KAAK,MAAM,aAAa,aAC3B,KAAK,KAAK,UAAU,GACpB,KAAK;AAEX,MAAI,UAAU,aAAa,OAAO,SAAS,cAAc,UAAU;GAEjE,MAAM,eAAe,KAAK,IAAI,gBAC5B,SAAS,UACV;AAED,OAAI,SAAS,MACX,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,SAAS,MAAM,CACvD,CAAC,aAAa,SAAiB,OAAO;AAI1C,OAAI,SAAS,UAAU;IACrB,MAAM,UAAU,SAAS;AACzB,QAAI,OAAO,YAAY,YAAY,OAAO,YAAY,SACpD,cAAa,SAAS,cAAc,YAClC,SAAS,eAAe,OAAO,QAAQ,CAAC,CACzC;;AAIL,QAAK,IAAI,cAAc;SAClB;GAEL,MAAM,OACJ,KAAK,MAAM,SAAS,KAAK,MAAM,YAAY,IAAI,OAAO,KAAK,KAAK;AAIlE,QAAK,YAAY,SAAS,eAAe,KAAK,CAAC;;;;uDA5D3C;kFAVC;CACT,UAAU;CACV,YAAY;CAGZ,UAAU;CAEV,QAAQ,CAAC,+BAA+B;CACzC,CAAC"}
@@ -0,0 +1,9 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_UI_IntlayerNode_component = require('./IntlayerNode.component.cjs');
3
+
4
+ Object.defineProperty(exports, 'IntlayerNodeComponent', {
5
+ enumerable: true,
6
+ get: function () {
7
+ return require_UI_IntlayerNode_component.IntlayerNodeComponent;
8
+ }
9
+ });
@@ -1,28 +1,22 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_client_intlayerToken = require('./intlayerToken.cjs');
2
3
  const require_client_installIntlayer = require('./installIntlayer.cjs');
3
4
  const require_client_useDictionary = require('./useDictionary.cjs');
4
5
  const require_client_useDictionaryAsync = require('./useDictionaryAsync.cjs');
5
6
  const require_client_useLoadDynamic = require('./useLoadDynamic.cjs');
6
7
  const require_client_useDictionaryDynamic = require('./useDictionaryDynamic.cjs');
7
- const require_client_useIntl = require('./useIntl.cjs');
8
8
  const require_client_useIntlayer = require('./useIntlayer.cjs');
9
9
  const require_client_useLocale = require('./useLocale.cjs');
10
10
 
11
- exports.INTLAYER_TOKEN = require_client_installIntlayer.INTLAYER_TOKEN;
12
- Object.defineProperty(exports, 'IntlayerProvider', {
13
- enumerable: true,
14
- get: function () {
15
- return require_client_installIntlayer.IntlayerProvider;
16
- }
17
- });
18
- exports.createIntlayerClient = require_client_installIntlayer.createIntlayerClient;
11
+ exports.INTLAYER_TOKEN = require_client_intlayerToken.INTLAYER_TOKEN;
12
+ exports.IntlayerProvider = require_client_intlayerToken.IntlayerProvider;
13
+ exports.createIntlayerClient = require_client_intlayerToken.createIntlayerClient;
19
14
  exports.installIntlayer = require_client_installIntlayer.installIntlayer;
20
15
  exports.isUpdatableNode = require_client_useIntlayer.isUpdatableNode;
21
16
  exports.provideIntlayer = require_client_installIntlayer.provideIntlayer;
22
17
  exports.useDictionary = require_client_useDictionary.useDictionary;
23
18
  exports.useDictionaryAsync = require_client_useDictionaryAsync.useDictionaryAsync;
24
19
  exports.useDictionaryDynamic = require_client_useDictionaryDynamic.useDictionaryDynamic;
25
- exports.useIntl = require_client_useIntl.useIntl;
26
20
  exports.useIntlayer = require_client_useIntlayer.useIntlayer;
27
21
  exports.useLoadDynamic = require_client_useLoadDynamic.useLoadDynamic;
28
22
  exports.useLocale = require_client_useLocale.useLocale;
@@ -1,44 +1,19 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- const require_decorate = require('../_virtual/_@oxc-project_runtime@0.115.0/helpers/decorate.cjs');
4
- let _intlayer_config_built = require("@intlayer/config/built");
5
- _intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
6
- let _angular_core = require("@angular/core");
2
+ const require_client_intlayerToken = require('./intlayerToken.cjs');
3
+ const require_editor_useEditor = require('../editor/useEditor.cjs');
7
4
 
8
5
  //#region src/client/installIntlayer.ts
9
- const INTLAYER_TOKEN = new _angular_core.InjectionToken("intlayer");
10
- /**
11
- * Singleton instance
12
- */
13
- let instance = null;
14
- let IntlayerProvider = class IntlayerProvider {
15
- isCookieEnabled = (0, _angular_core.signal)(true);
16
- _locale = (0, _angular_core.signal)(_intlayer_config_built.default.internationalization?.defaultLocale);
17
- locale = this._locale.asReadonly();
18
- setLocale = (locale) => {
19
- this._locale.set(locale);
20
- };
21
- };
22
- IntlayerProvider = require_decorate.__decorate([(0, _angular_core.Injectable)({ providedIn: "root" })], IntlayerProvider);
23
- /**
24
- * Create and return a single IntlayerProvider instance
25
- */
26
- const createIntlayerClient = (locale, isCookieEnabled = true) => {
27
- if (instance) return instance;
28
- instance = new IntlayerProvider();
29
- if (locale) instance.setLocale(locale);
30
- instance.isCookieEnabled.set(isCookieEnabled);
31
- return instance;
32
- };
33
6
  /**
34
7
  * Provides Intlayer to your Angular application.
35
8
  *
36
- * This function should be used in your application's provider list (e.g., in `app.config.ts`)
37
- * to initialize the Intlayer service.
9
+ * Registers the Intlayer locale token **and** automatically starts the Intlayer
10
+ * editor client (when the editor is enabled) via `provideAppInitializer`.
11
+ *
12
+ * This is the recommended way to set up Intlayer in `app.config.ts`.
38
13
  *
39
14
  * @param locale - Initial locale to use.
40
15
  * @param isCookieEnabled - Whether to store the locale in cookies.
41
- * @returns A provider configuration for Intlayer.
16
+ * @returns An array of Angular providers for Intlayer.
42
17
  *
43
18
  * @example
44
19
  * ```ts
@@ -47,32 +22,28 @@ const createIntlayerClient = (locale, isCookieEnabled = true) => {
47
22
  * import { provideIntlayer } from 'angular-intlayer';
48
23
  *
49
24
  * export const appConfig: ApplicationConfig = {
50
- * providers: [
51
- * provideIntlayer({ locale: 'en' }),
52
- * ],
25
+ * providers: [provideIntlayer()],
53
26
  * };
54
27
  * ```
55
28
  */
56
- const provideIntlayer = (locale, isCookieEnabled = true) => ({
57
- provide: INTLAYER_TOKEN,
58
- useValue: installIntlayer(locale, isCookieEnabled)
59
- });
29
+ const provideIntlayer = (locale, isCookieEnabled = true) => {
30
+ const client = installIntlayer(locale, isCookieEnabled);
31
+ return [{
32
+ provide: require_client_intlayerToken.INTLAYER_TOKEN,
33
+ useValue: client
34
+ }, require_editor_useEditor.provideIntlayerEditor(client)];
35
+ };
60
36
  /**
61
37
  * Helper to install the Intlayer provider.
62
38
  */
63
39
  const installIntlayer = (locale, isCookieEnabled = true) => {
64
- return createIntlayerClient(locale, isCookieEnabled);
40
+ return require_client_intlayerToken.createIntlayerClient(locale, isCookieEnabled);
65
41
  };
66
42
 
67
43
  //#endregion
68
- exports.INTLAYER_TOKEN = INTLAYER_TOKEN;
69
- Object.defineProperty(exports, 'IntlayerProvider', {
70
- enumerable: true,
71
- get: function () {
72
- return IntlayerProvider;
73
- }
74
- });
75
- exports.createIntlayerClient = createIntlayerClient;
44
+ exports.INTLAYER_TOKEN = require_client_intlayerToken.INTLAYER_TOKEN;
45
+ exports.IntlayerProvider = require_client_intlayerToken.IntlayerProvider;
46
+ exports.createIntlayerClient = require_client_intlayerToken.createIntlayerClient;
76
47
  exports.installIntlayer = installIntlayer;
77
48
  exports.provideIntlayer = provideIntlayer;
78
49
  //# sourceMappingURL=installIntlayer.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"installIntlayer.cjs","names":["InjectionToken","configuration"],"sources":["../../../src/client/installIntlayer.ts"],"sourcesContent":["import { Injectable, InjectionToken, type Signal, signal } from '@angular/core';\nimport configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nexport const INTLAYER_TOKEN = new InjectionToken<IntlayerProvider>('intlayer');\n\n/**\n * Singleton instance\n */\nlet instance: IntlayerProvider | null = null;\n\n@Injectable({\n providedIn: 'root',\n})\nexport class IntlayerProvider {\n isCookieEnabled = signal(true);\n private _locale = signal<LocalesValues>(\n configuration.internationalization?.defaultLocale as LocalesValues\n );\n\n readonly locale: Signal<LocalesValues> = this._locale.asReadonly();\n\n setLocale = (locale: LocalesValues) => {\n this._locale.set(locale);\n };\n}\n\n/**\n * Create and return a single IntlayerProvider instance\n */\nexport const createIntlayerClient = (\n locale?: LocalesValues,\n isCookieEnabled = true\n): IntlayerProvider => {\n if (instance) return instance;\n\n instance = new IntlayerProvider();\n\n if (locale) {\n instance.setLocale(locale);\n }\n instance.isCookieEnabled.set(isCookieEnabled);\n\n return instance;\n};\n\n/**\n * Provides Intlayer to your Angular application.\n *\n * This function should be used in your application's provider list (e.g., in `app.config.ts`)\n * to initialize the Intlayer service.\n *\n * @param locale - Initial locale to use.\n * @param isCookieEnabled - Whether to store the locale in cookies.\n * @returns A provider configuration for Intlayer.\n *\n * @example\n * ```ts\n * // app.config.ts\n * import { ApplicationConfig } from '@angular/core';\n * import { provideIntlayer } from 'angular-intlayer';\n *\n * export const appConfig: ApplicationConfig = {\n * providers: [\n * provideIntlayer({ locale: 'en' }),\n * ],\n * };\n * ```\n */\nexport const provideIntlayer = (\n locale?: LocalesValues,\n isCookieEnabled = true\n) => ({\n provide: INTLAYER_TOKEN,\n useValue: installIntlayer(locale, isCookieEnabled),\n});\n\n/**\n * Helper to install the Intlayer provider.\n */\nexport const installIntlayer = (\n locale?: LocalesValues,\n isCookieEnabled = true\n) => {\n const client = createIntlayerClient(locale, isCookieEnabled);\n\n // Note: Angular editor installation will be handled differently\n // installIntlayerEditor();\n\n return client;\n};\n"],"mappings":";;;;;;;;AAIA,MAAa,iBAAiB,IAAIA,6BAAiC,WAAW;;;;AAK9E,IAAI,WAAoC;AAKjC,6BAAM,iBAAiB;CAC5B,4CAAyB,KAAK;CAC9B,AAAQ,oCACNC,+BAAc,sBAAsB,cACrC;CAED,AAAS,SAAgC,KAAK,QAAQ,YAAY;CAElE,aAAa,WAA0B;AACrC,OAAK,QAAQ,IAAI,OAAO;;;8EAZhB,EACV,YAAY,QACb,CAAC;;;;AAiBF,MAAa,wBACX,QACA,kBAAkB,SACG;AACrB,KAAI,SAAU,QAAO;AAErB,YAAW,IAAI,kBAAkB;AAEjC,KAAI,OACF,UAAS,UAAU,OAAO;AAE5B,UAAS,gBAAgB,IAAI,gBAAgB;AAE7C,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;AA0BT,MAAa,mBACX,QACA,kBAAkB,UACd;CACJ,SAAS;CACT,UAAU,gBAAgB,QAAQ,gBAAgB;CACnD;;;;AAKD,MAAa,mBACX,QACA,kBAAkB,SACf;AAMH,QALe,qBAAqB,QAAQ,gBAAgB"}
1
+ {"version":3,"file":"installIntlayer.cjs","names":["INTLAYER_TOKEN","provideIntlayerEditor","createIntlayerClient"],"sources":["../../../src/client/installIntlayer.ts"],"sourcesContent":["import type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { provideIntlayerEditor } from '../editor/useEditor';\nimport {\n createIntlayerClient,\n INTLAYER_TOKEN,\n IntlayerProvider,\n} from './intlayerToken';\n\nexport { createIntlayerClient, INTLAYER_TOKEN, IntlayerProvider };\n\n/**\n * Provides Intlayer to your Angular application.\n *\n * Registers the Intlayer locale token **and** automatically starts the Intlayer\n * editor client (when the editor is enabled) via `provideAppInitializer`.\n *\n * This is the recommended way to set up Intlayer in `app.config.ts`.\n *\n * @param locale - Initial locale to use.\n * @param isCookieEnabled - Whether to store the locale in cookies.\n * @returns An array of Angular providers for Intlayer.\n *\n * @example\n * ```ts\n * // app.config.ts\n * import { ApplicationConfig } from '@angular/core';\n * import { provideIntlayer } from 'angular-intlayer';\n *\n * export const appConfig: ApplicationConfig = {\n * providers: [provideIntlayer()],\n * };\n * ```\n */\nexport const provideIntlayer = (\n locale?: LocalesValues,\n isCookieEnabled = true\n) => {\n const client = installIntlayer(locale, isCookieEnabled);\n\n return [\n { provide: INTLAYER_TOKEN, useValue: client },\n provideIntlayerEditor(client),\n ];\n};\n\n/**\n * Helper to install the Intlayer provider.\n */\nexport const installIntlayer = (\n locale?: LocalesValues,\n isCookieEnabled = true\n) => {\n return createIntlayerClient(locale, isCookieEnabled);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,mBACX,QACA,kBAAkB,SACf;CACH,MAAM,SAAS,gBAAgB,QAAQ,gBAAgB;AAEvD,QAAO,CACL;EAAE,SAASA;EAAgB,UAAU;EAAQ,EAC7CC,+CAAsB,OAAO,CAC9B;;;;;AAMH,MAAa,mBACX,QACA,kBAAkB,SACf;AACH,QAAOC,kDAAqB,QAAQ,gBAAgB"}
@@ -0,0 +1,36 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ let _intlayer_config_built = require("@intlayer/config/built");
4
+ _intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
5
+ let _angular_core = require("@angular/core");
6
+
7
+ //#region src/client/intlayerToken.ts
8
+ var IntlayerProvider = class {
9
+ isCookieEnabled = (0, _angular_core.signal)(true);
10
+ _locale = (0, _angular_core.signal)(_intlayer_config_built.default.internationalization?.defaultLocale);
11
+ locale = this._locale.asReadonly();
12
+ setLocale = (locale) => {
13
+ this._locale.set(locale);
14
+ };
15
+ };
16
+ const INTLAYER_TOKEN = new _angular_core.InjectionToken("intlayer");
17
+ /**
18
+ * Singleton instance
19
+ */
20
+ let instance = null;
21
+ /**
22
+ * Create and return a single IntlayerProvider instance
23
+ */
24
+ const createIntlayerClient = (locale, isCookieEnabled = true) => {
25
+ if (instance) return instance;
26
+ instance = new IntlayerProvider();
27
+ if (locale) instance.setLocale(locale);
28
+ instance.isCookieEnabled.set(isCookieEnabled);
29
+ return instance;
30
+ };
31
+
32
+ //#endregion
33
+ exports.INTLAYER_TOKEN = INTLAYER_TOKEN;
34
+ exports.IntlayerProvider = IntlayerProvider;
35
+ exports.createIntlayerClient = createIntlayerClient;
36
+ //# sourceMappingURL=intlayerToken.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intlayerToken.cjs","names":["configuration","InjectionToken"],"sources":["../../../src/client/intlayerToken.ts"],"sourcesContent":["import { InjectionToken, type Signal, signal } from '@angular/core';\nimport configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\n\nexport class IntlayerProvider {\n isCookieEnabled = signal(true);\n private _locale = signal<LocalesValues>(\n configuration.internationalization?.defaultLocale as LocalesValues\n );\n\n readonly locale: Signal<LocalesValues> = this._locale.asReadonly();\n\n setLocale = (locale: LocalesValues) => {\n this._locale.set(locale);\n };\n}\n\nexport const INTLAYER_TOKEN = new InjectionToken<IntlayerProvider>('intlayer');\n\n/**\n * Singleton instance\n */\nlet instance: IntlayerProvider | null = null;\n\n/**\n * Create and return a single IntlayerProvider instance\n */\nexport const createIntlayerClient = (\n locale?: LocalesValues,\n isCookieEnabled = true\n): IntlayerProvider => {\n if (instance) return instance;\n\n instance = new IntlayerProvider();\n\n if (locale) {\n instance.setLocale(locale);\n }\n instance.isCookieEnabled.set(isCookieEnabled);\n\n return instance;\n};\n"],"mappings":";;;;;;;AAIA,IAAa,mBAAb,MAA8B;CAC5B,4CAAyB,KAAK;CAC9B,AAAQ,oCACNA,+BAAc,sBAAsB,cACrC;CAED,AAAS,SAAgC,KAAK,QAAQ,YAAY;CAElE,aAAa,WAA0B;AACrC,OAAK,QAAQ,IAAI,OAAO;;;AAI5B,MAAa,iBAAiB,IAAIC,6BAAiC,WAAW;;;;AAK9E,IAAI,WAAoC;;;;AAKxC,MAAa,wBACX,QACA,kBAAkB,SACG;AACrB,KAAI,SAAU,QAAO;AAErB,YAAW,IAAI,kBAAkB;AAEjC,KAAI,OACF,UAAS,UAAU,OAAO;AAE5B,UAAS,gBAAgB,IAAI,gBAAgB;AAE7C,QAAO"}
@@ -1,12 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
3
  const require_getDictionary = require('../getDictionary.cjs');
4
- const require_client_installIntlayer = require('./installIntlayer.cjs');
4
+ const require_client_intlayerToken = require('./intlayerToken.cjs');
5
5
  let _angular_core = require("@angular/core");
6
6
 
7
7
  //#region src/client/useDictionary.ts
8
8
  const useDictionary = (dictionary, locale) => {
9
- const intlayer = (0, _angular_core.inject)(require_client_installIntlayer.INTLAYER_TOKEN);
9
+ const intlayer = (0, _angular_core.inject)(require_client_intlayerToken.INTLAYER_TOKEN);
10
10
  const localeTarget = (0, _angular_core.computed)(() => locale ?? intlayer?.locale());
11
11
  return (0, _angular_core.computed)(() => require_getDictionary.getDictionary(dictionary, localeTarget()));
12
12
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useDictionary.cjs","names":["INTLAYER_TOKEN","getDictionary"],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\n\nexport const useDictionary = <T extends Dictionary>(\n dictionary: T,\n locale?: LocalesValues\n): Signal<DeepTransformContent<T['content']>> => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n const localeTarget = computed(() => locale ?? intlayer?.locale());\n\n /** a *stable* reactive dictionary object */\n const content = computed(() =>\n getDictionary<T, LocalesValues>(dictionary, localeTarget())\n );\n\n return content; // all consumers keep full reactivity\n};\n"],"mappings":";;;;;;;AAOA,MAAa,iBACX,YACA,WAC+C;CAC/C,MAAM,qCAAoCA,8CAAe;CAEzD,MAAM,iDAA8B,UAAU,UAAU,QAAQ,CAAC;AAOjE,0CAHEC,oCAAgC,YAAY,cAAc,CAAC,CAC5D"}
1
+ {"version":3,"file":"useDictionary.cjs","names":["INTLAYER_TOKEN","getDictionary"],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport type { DeepTransformContent } from '../plugins';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\n\nexport const useDictionary = <T extends Dictionary>(\n dictionary: T,\n locale?: LocalesValues\n): Signal<DeepTransformContent<T['content']>> => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n const localeTarget = computed(() => locale ?? intlayer?.locale());\n\n /** a *stable* reactive dictionary object */\n const content = computed(\n () => getDictionary<T, LocalesValues>(dictionary, localeTarget()) as any\n );\n\n return content; // all consumers keep full reactivity\n};\n"],"mappings":";;;;;;;AAOA,MAAa,iBACX,YACA,WAC+C;CAC/C,MAAM,qCAAoCA,4CAAe;CAEzD,MAAM,iDAA8B,UAAU,UAAU,QAAQ,CAAC;AAOjE,0CAHQC,oCAAgC,YAAY,cAAc,CAAC,CAClE"}
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
  const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
5
- const require_client_installIntlayer = require('./installIntlayer.cjs');
5
+ const require_client_intlayerToken = require('./intlayerToken.cjs');
6
6
  const require_client_useDictionary = require('./useDictionary.cjs');
7
7
  let _intlayer_config_built = require("@intlayer/config/built");
8
8
  _intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
@@ -15,7 +15,7 @@ let _angular_core = require("@angular/core");
15
15
  * If the locale is not provided, it will use the locale from the client context
16
16
  */
17
17
  const useDictionaryAsync = async (dictionaryPromise, locale) => {
18
- const intlayer = (0, _angular_core.inject)(require_client_installIntlayer.INTLAYER_TOKEN);
18
+ const intlayer = (0, _angular_core.inject)(require_client_intlayerToken.INTLAYER_TOKEN);
19
19
  const localeTarget = (0, _angular_core.computed)(() => locale ?? intlayer?.locale() ?? _intlayer_config_built.default?.internationalization.defaultLocale);
20
20
  return require_client_useDictionary.useDictionary(await dictionaryPromise[localeTarget()]?.(), localeTarget());
21
21
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useDictionaryAsync.cjs","names":["INTLAYER_TOKEN","configuration","useDictionary"],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["'use client';\n\nimport { computed, inject } from '@angular/core';\nimport configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { LocalesValues, StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\nimport { useDictionary } from './useDictionary';\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 useDictionaryAsync = async <T extends Dictionary>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: LocalesValues\n) => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n const localeTarget = computed(\n () =>\n locale ??\n intlayer?.locale() ??\n configuration?.internationalization.defaultLocale\n );\n\n const dictionary = await dictionaryPromise[localeTarget()]?.();\n\n return useDictionary(dictionary, localeTarget() as any);\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAcA,MAAa,qBAAqB,OAChC,mBACA,WACG;CACH,MAAM,qCAAoCA,8CAAe;CAEzD,MAAM,iDAEF,UACA,UAAU,QAAQ,IAClBC,gCAAe,qBAAqB,cACvC;AAID,QAAOC,2CAFY,MAAM,kBAAkB,cAAc,KAAK,EAE7B,cAAc,CAAQ"}
1
+ {"version":3,"file":"useDictionaryAsync.cjs","names":["INTLAYER_TOKEN","configuration","useDictionary"],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["'use client';\n\nimport { computed, inject } from '@angular/core';\nimport configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\nimport { useDictionary } from './useDictionary';\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 useDictionaryAsync = async <T extends Dictionary>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: LocalesValues\n) => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n const localeTarget = computed(\n () =>\n locale ??\n intlayer?.locale() ??\n configuration?.internationalization.defaultLocale\n );\n\n const dictionary = await (dictionaryPromise as any)[localeTarget()]?.();\n\n return useDictionary(dictionary, localeTarget() as any);\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAiBA,MAAa,qBAAqB,OAChC,mBACA,WACG;CACH,MAAM,qCAAoCA,4CAAe;CAEzD,MAAM,iDAEF,UACA,UAAU,QAAQ,IAClBC,gCAAe,qBAAqB,cACvC;AAID,QAAOC,2CAFY,MAAO,kBAA0B,cAAc,KAAK,EAEtC,cAAc,CAAQ"}
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
  const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
5
- const require_client_installIntlayer = require('./installIntlayer.cjs');
5
+ const require_client_intlayerToken = require('./intlayerToken.cjs');
6
6
  const require_client_useDictionary = require('./useDictionary.cjs');
7
7
  const require_client_useLoadDynamic = require('./useLoadDynamic.cjs');
8
8
  let _intlayer_config_built = require("@intlayer/config/built");
@@ -16,7 +16,7 @@ let _angular_core = require("@angular/core");
16
16
  * If the locale is not provided, it will use the locale from the client context
17
17
  */
18
18
  const useDictionaryDynamic = (dictionaryPromise, key, locale) => {
19
- const intlayer = (0, _angular_core.inject)(require_client_installIntlayer.INTLAYER_TOKEN);
19
+ const intlayer = (0, _angular_core.inject)(require_client_intlayerToken.INTLAYER_TOKEN);
20
20
  const localeTarget = (0, _angular_core.computed)(() => locale ?? intlayer?.locale() ?? _intlayer_config_built.default?.internationalization.defaultLocale);
21
21
  return require_client_useDictionary.useDictionary(require_client_useLoadDynamic.useLoadDynamic(`${String(key)}.${localeTarget()}`, dictionaryPromise[localeTarget()]?.()), localeTarget());
22
22
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useDictionaryDynamic.cjs","names":["INTLAYER_TOKEN","configuration","useDictionary","useLoadDynamic"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport { computed, inject } from '@angular/core';\nimport configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type { DictionaryKeys, LocalesValues, StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\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 useDictionaryDynamic = <\n T extends Dictionary,\n K extends DictionaryKeys,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n locale?: LocalesValues\n) => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n const localeTarget = computed(\n () =>\n locale ??\n intlayer?.locale() ??\n configuration?.internationalization.defaultLocale\n );\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget()}`,\n dictionaryPromise[localeTarget()]?.()\n ) as T;\n\n return useDictionary(dictionary, localeTarget() as any);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAeA,MAAa,wBAIX,mBACA,KACA,WACG;CACH,MAAM,qCAAoCA,8CAAe;CAEzD,MAAM,iDAEF,UACA,UAAU,QAAQ,IAClBC,gCAAe,qBAAqB,cACvC;AAOD,QAAOC,2CALYC,6CACjB,GAAG,OAAO,IAAI,CAAC,GAAG,cAAc,IAChC,kBAAkB,cAAc,KAAK,CACtC,EAEgC,cAAc,CAAQ"}
1
+ {"version":3,"file":"useDictionaryDynamic.cjs","names":["INTLAYER_TOKEN","configuration","useDictionary","useLoadDynamic"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport { computed, inject } from '@angular/core';\nimport configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DictionaryKeys,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\nimport { useDictionary } from './useDictionary';\nimport { useLoadDynamic } from './useLoadDynamic';\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 useDictionaryDynamic = <\n T extends Dictionary,\n K extends DictionaryKeys,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: K,\n locale?: LocalesValues\n) => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n const localeTarget = computed(\n () =>\n locale ??\n intlayer?.locale() ??\n configuration?.internationalization.defaultLocale\n );\n\n const dictionary = useLoadDynamic<T>(\n `${String(key)}.${localeTarget()}`,\n (dictionaryPromise as any)[localeTarget()]?.()\n ) as T;\n\n return useDictionary(dictionary, localeTarget() as any);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAmBA,MAAa,wBAIX,mBACA,KACA,WACG;CACH,MAAM,qCAAoCA,4CAAe;CAEzD,MAAM,iDAEF,UACA,UAAU,QAAQ,IAClBC,gCAAe,qBAAqB,cACvC;AAOD,QAAOC,2CALYC,6CACjB,GAAG,OAAO,IAAI,CAAC,GAAG,cAAc,IAC/B,kBAA0B,cAAc,KAAK,CAC/C,EAEgC,cAAc,CAAQ"}
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
3
  const require_getIntlayer = require('../getIntlayer.cjs');
4
- const require_client_installIntlayer = require('./installIntlayer.cjs');
4
+ const require_client_intlayerToken = require('./intlayerToken.cjs');
5
5
  let _angular_core = require("@angular/core");
6
6
 
7
7
  //#region src/client/useIntlayer.ts
@@ -33,7 +33,7 @@ const isUpdatableNode = (val) => !!val && typeof val === "object" && typeof val.
33
33
  * ```
34
34
  */
35
35
  const useIntlayer = (key, locale) => {
36
- const intlayer = (0, _angular_core.inject)(require_client_installIntlayer.INTLAYER_TOKEN);
36
+ const intlayer = (0, _angular_core.inject)(require_client_intlayerToken.INTLAYER_TOKEN);
37
37
  /** which locale should we use right now? */
38
38
  const localeTarget = (0, _angular_core.computed)(() => locale ?? intlayer.locale());
39
39
  return (0, _angular_core.computed)(() => require_getIntlayer.getIntlayer(key, localeTarget()));
@@ -1 +1 @@
1
- {"version":3,"file":"useIntlayer.cjs","names":["INTLAYER_TOKEN","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport type { DictionaryKeys, DictionaryRegistryContent, LocalesValues } from '@intlayer/types/module_augmentation';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\n\n/** guard utility - true only for objects generated by `renderIntlayerNode()` */\nexport const isUpdatableNode = (\n val: unknown\n): val is { __update: (n: unknown) => void } =>\n !!val &&\n typeof val === 'object' &&\n typeof (val as any).__update === 'function';\n\n/**\n * Angular hook that picks one dictionary by its key and returns its reactive content.\n *\n * It utilizes Angular signals to provide deep reactivity, ensuring your components\n * update automatically when the locale changes.\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param locale - Optional locale to override the current context locale.\n * @returns The transformed dictionary content.\n *\n * @example\n * ```ts\n * import { Component } from '@angular/core';\n * import { useIntlayer } from 'angular-intlayer';\n *\n * @Component({\n * standalone: true,\n * selector: 'app-my-component',\n * template: `<div>{{ content().myField.value }}</div>`,\n * })\n * export class MyComponent {\n * content = useIntlayer('my-dictionary-key');\n * }\n * ```\n */\nexport const useIntlayer = <T extends DictionaryKeys, L extends LocalesValues>(\n key: T,\n locale?: LocalesValues\n): Signal<DeepTransformContent<DictionaryRegistryContent<T>>> => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN)!;\n\n /** which locale should we use right now? */\n const localeTarget = computed(() => locale ?? intlayer.locale());\n\n /** a *stable* reactive dictionary object */\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const content = computed(() => getIntlayer<T, L>(key, localeTarget() as L));\n\n return content; // all consumers keep full reactivity\n};\n"],"mappings":";;;;;;;;AAOA,MAAa,mBACX,QAEA,CAAC,CAAC,OACF,OAAO,QAAQ,YACf,OAAQ,IAAY,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BnC,MAAa,eACX,KACA,WAC+D;CAC/D,MAAM,qCAAoCA,8CAAe;;CAGzD,MAAM,iDAA8B,UAAU,SAAS,QAAQ,CAAC;AAMhE,0CAF+BC,gCAAkB,KAAK,cAAc,CAAM,CAAC"}
1
+ {"version":3,"file":"useIntlayer.cjs","names":["INTLAYER_TOKEN","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["import { computed, inject, type Signal } from '@angular/core';\nimport type {\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayer } from '../getIntlayer';\nimport type { DeepTransformContent } from '../plugins';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\n\n/** guard utility - true only for objects generated by `renderIntlayerNode()` */\nexport const isUpdatableNode = (\n val: unknown\n): val is { __update: (n: unknown) => void } =>\n !!val &&\n typeof val === 'object' &&\n typeof (val as any).__update === 'function';\n\n/**\n * Angular hook that picks one dictionary by its key and returns its reactive content.\n *\n * It utilizes Angular signals to provide deep reactivity, ensuring your components\n * update automatically when the locale changes.\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param locale - Optional locale to override the current context locale.\n * @returns The transformed dictionary content.\n *\n * @example\n * ```ts\n * import { Component } from '@angular/core';\n * import { useIntlayer } from 'angular-intlayer';\n *\n * @Component({\n * standalone: true,\n * selector: 'app-my-component',\n * template: `<div>{{ content().myField.value }}</div>`,\n * })\n * export class MyComponent {\n * content = useIntlayer('my-dictionary-key');\n * }\n * ```\n */\nexport const useIntlayer = <T extends DictionaryKeys, L extends LocalesValues>(\n key: T,\n locale?: LocalesValues\n): Signal<DeepTransformContent<DictionaryRegistryContent<T>>> => {\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN)!;\n\n /** which locale should we use right now? */\n const localeTarget = computed(() => locale ?? intlayer.locale());\n\n /** a *stable* reactive dictionary object */\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const content = computed(\n () => getIntlayer<T, L>(key, localeTarget() as L) as any\n );\n\n return content; // all consumers keep full reactivity\n};\n"],"mappings":";;;;;;;;AAWA,MAAa,mBACX,QAEA,CAAC,CAAC,OACF,OAAO,QAAQ,YACf,OAAQ,IAAY,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BnC,MAAa,eACX,KACA,WAC+D;CAC/D,MAAM,qCAAoCA,4CAAe;;CAGzD,MAAM,iDAA8B,UAAU,SAAS,QAAQ,CAAC;AAQhE,0CAHQC,gCAAkB,KAAK,cAAc,CAAM,CAClD"}
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- const require_client_installIntlayer = require('./installIntlayer.cjs');
3
+ const require_client_intlayerToken = require('./intlayerToken.cjs');
4
4
  const require_client_useLocaleStorage = require('./useLocaleStorage.cjs');
5
5
  let _intlayer_config_built = require("@intlayer/config/built");
6
6
  _intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
@@ -36,7 +36,7 @@ let _angular_core = require("@angular/core");
36
36
  */
37
37
  const useLocale = ({ isCookieEnabled, onLocaleChange } = {}) => {
38
38
  const { defaultLocale, locales: availableLocales } = _intlayer_config_built.default?.internationalization ?? {};
39
- const intlayer = (0, _angular_core.inject)(require_client_installIntlayer.INTLAYER_TOKEN);
39
+ const intlayer = (0, _angular_core.inject)(require_client_intlayerToken.INTLAYER_TOKEN);
40
40
  const locale = (0, _angular_core.computed)(() => intlayer?.locale() ?? defaultLocale);
41
41
  const isCookieEnabledContext = (0, _angular_core.computed)(() => intlayer?.isCookieEnabled() ?? true);
42
42
  const setLocale = (newLocale) => {
@@ -1 +1 @@
1
- {"version":3,"file":"useLocale.cjs","names":["configuration","INTLAYER_TOKEN"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import { computed, inject } from '@angular/core';\nimport configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype useLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: LocalesValues) => void;\n};\n\n/**\n * Angular hook to manage the current locale and related functions.\n *\n * @param props - Optional configuration for locale management.\n * @returns An object containing the current locale (signal), default locale, available locales, and a function to update the locale.\n *\n * @example\n * ```ts\n * import { Component } from '@angular/core';\n * import { useLocale } from 'angular-intlayer';\n *\n * @Component({\n * standalone: true,\n * selector: 'app-locale-switcher',\n * template: `\n * <select [value]=\"locale()\" (change)=\"setLocale($any($event.target).value)\">\n * @for (loc of availableLocales; track loc) {\n * <option [value]=\"loc\">{{ loc }}</option>\n * }\n * </select>\n * `,\n * })\n * export class LocaleSwitcher {\n * const { locale, setLocale, availableLocales } = useLocale();\n * }\n * ```\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: useLocaleProps = {}) => {\n const { defaultLocale, locales: availableLocales } =\n configuration?.internationalization ?? {};\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n // Create a reactive reference for the locale\n const locale = computed(() => intlayer?.locale() ?? defaultLocale);\n const isCookieEnabledContext = computed(\n () => intlayer?.isCookieEnabled() ?? true\n );\n\n const setLocale = (newLocale: LocalesValues) => {\n if (!availableLocales?.map(String).includes(newLocale)) {\n console.error(`Locale ${newLocale} is not available`);\n return;\n }\n\n if (intlayer) {\n intlayer.setLocale(newLocale);\n }\n setLocaleInStorage(\n newLocale,\n isCookieEnabled ?? isCookieEnabledContext() ?? true\n );\n onLocaleChange?.(newLocale);\n };\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,aAAa,EACxB,iBACA,mBACkB,EAAE,KAAK;CACzB,MAAM,EAAE,eAAe,SAAS,qBAC9BA,gCAAe,wBAAwB,EAAE;CAC3C,MAAM,qCAAoCC,8CAAe;CAGzD,MAAM,2CAAwB,UAAU,QAAQ,IAAI,cAAc;CAClE,MAAM,2DACE,UAAU,iBAAiB,IAAI,KACtC;CAED,MAAM,aAAa,cAA6B;AAC9C,MAAI,CAAC,kBAAkB,IAAI,OAAO,CAAC,SAAS,UAAU,EAAE;AACtD,WAAQ,MAAM,UAAU,UAAU,mBAAmB;AACrD;;AAGF,MAAI,SACF,UAAS,UAAU,UAAU;AAE/B,qDACE,WACA,mBAAmB,wBAAwB,IAAI,KAChD;AACD,mBAAiB,UAAU;;AAG7B,QAAO;EACL;EACA;EACA;EACA;EACD"}
1
+ {"version":3,"file":"useLocale.cjs","names":["configuration","INTLAYER_TOKEN"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["import { computed, inject } from '@angular/core';\nimport configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from './installIntlayer';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype useLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: LocalesValues) => void;\n};\n\n/**\n * Angular hook to manage the current locale and related functions.\n *\n * @param props - Optional configuration for locale management.\n * @returns An object containing the current locale (signal), default locale, available locales, and a function to update the locale.\n *\n * @example\n * ```ts\n * import { Component } from '@angular/core';\n * import { useLocale } from 'angular-intlayer';\n *\n * @Component({\n * standalone: true,\n * selector: 'app-locale-switcher',\n * template: `\n * <select [value]=\"locale()\" (change)=\"setLocale($any($event.target).value)\">\n * @for (loc of availableLocales; track loc) {\n * <option [value]=\"loc\">{{ loc }}</option>\n * }\n * </select>\n * `,\n * })\n * export class LocaleSwitcher {\n * const { locale, setLocale, availableLocales } = useLocale();\n * }\n * ```\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: useLocaleProps = {}) => {\n const { defaultLocale, locales: availableLocales } =\n configuration?.internationalization ?? {};\n const intlayer = inject<IntlayerProvider>(INTLAYER_TOKEN);\n\n // Create a reactive reference for the locale\n const locale = computed(() => intlayer?.locale() ?? defaultLocale);\n const isCookieEnabledContext = computed(\n () => intlayer?.isCookieEnabled() ?? true\n );\n\n const setLocale = (newLocale: LocalesValues) => {\n if (!availableLocales?.map(String).includes(newLocale)) {\n console.error(`Locale ${newLocale} is not available`);\n return;\n }\n\n if (intlayer) {\n intlayer.setLocale(newLocale);\n }\n setLocaleInStorage(\n newLocale,\n isCookieEnabled ?? isCookieEnabledContext() ?? true\n );\n onLocaleChange?.(newLocale);\n };\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,aAAa,EACxB,iBACA,mBACkB,EAAE,KAAK;CACzB,MAAM,EAAE,eAAe,SAAS,qBAC9BA,gCAAe,wBAAwB,EAAE;CAC3C,MAAM,qCAAoCC,4CAAe;CAGzD,MAAM,2CAAwB,UAAU,QAAQ,IAAI,cAAc;CAClE,MAAM,2DACE,UAAU,iBAAiB,IAAI,KACtC;CAED,MAAM,aAAa,cAA6B;AAC9C,MAAI,CAAC,kBAAkB,IAAI,OAAO,CAAC,SAAS,UAAU,EAAE;AACtD,WAAQ,MAAM,UAAU,UAAU,mBAAmB;AACrD;;AAGF,MAAI,SACF,UAAS,UAAU,UAAU;AAE/B,qDACE,WACA,mBAAmB,wBAAwB,IAAI,KAChD;AACD,mBAAiB,UAAU;;AAG7B,QAAO;EACL;EACA;EACA;EACA;EACD"}
@@ -0,0 +1,27 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ const require_decorateMetadata = require('../_virtual/_@oxc-project_runtime@0.115.0/helpers/decorateMetadata.cjs');
4
+ const require_decorate = require('../_virtual/_@oxc-project_runtime@0.115.0/helpers/decorate.cjs');
5
+ const require_editor_useEditor = require('./useEditor.cjs');
6
+ let _angular_core = require("@angular/core");
7
+
8
+ //#region src/editor/EditorProvider.component.ts
9
+ let EditorProviderComponent = class EditorProviderComponent {
10
+ constructor() {
11
+ require_editor_useEditor.useEditor();
12
+ }
13
+ };
14
+ EditorProviderComponent = require_decorate.__decorate([(0, _angular_core.Component)({
15
+ selector: "intlayer-editor-provider",
16
+ standalone: true,
17
+ template: `<ng-content />`
18
+ }), require_decorateMetadata.__decorateMetadata("design:paramtypes", [])], EditorProviderComponent);
19
+
20
+ //#endregion
21
+ Object.defineProperty(exports, 'EditorProviderComponent', {
22
+ enumerable: true,
23
+ get: function () {
24
+ return EditorProviderComponent;
25
+ }
26
+ });
27
+ //# sourceMappingURL=EditorProvider.component.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EditorProvider.component.cjs","names":[],"sources":["../../../src/editor/EditorProvider.component.ts"],"sourcesContent":["import { Component } from '@angular/core';\nimport { useEditor } from './useEditor';\n\n/**\n * Drop-in Angular equivalent of React's `EditorProvider`.\n *\n * Wrap your root component (or any subtree) with this component to automatically\n * start the Intlayer editor client. The editor will be started on mount and\n * stopped when this component is destroyed.\n *\n * @example\n * ```html\n * <!-- app.component.html -->\n * <intlayer-editor-provider>\n * <router-outlet />\n * </intlayer-editor-provider>\n * ```\n *\n * ```ts\n * // app.component.ts\n * import { EditorProviderComponent } from 'angular-intlayer';\n *\n * @Component({\n * imports: [EditorProviderComponent],\n * …\n * })\n * export class AppComponent {}\n * ```\n */\n@Component({\n selector: 'intlayer-editor-provider',\n standalone: true,\n template: `<ng-content />`,\n})\nexport class EditorProviderComponent {\n constructor() {\n useEditor();\n }\n}\n"],"mappings":";;;;;;;;AAkCO,oCAAM,wBAAwB;CACnC,cAAc;AACZ,sCAAW;;;oFAPJ;CACT,UAAU;CACV,YAAY;CACZ,UAAU;CACX,CAAC"}
@@ -0,0 +1,19 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_editor_ContentSelector_component = require('./ContentSelector.component.cjs');
3
+ const require_editor_useEditor = require('./useEditor.cjs');
4
+ const require_editor_EditorProvider_component = require('./EditorProvider.component.cjs');
5
+
6
+ Object.defineProperty(exports, 'ContentSelectorWrapperComponent', {
7
+ enumerable: true,
8
+ get: function () {
9
+ return require_editor_ContentSelector_component.ContentSelectorWrapperComponent;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, 'EditorProviderComponent', {
13
+ enumerable: true,
14
+ get: function () {
15
+ return require_editor_EditorProvider_component.EditorProviderComponent;
16
+ }
17
+ });
18
+ exports.provideIntlayerEditor = require_editor_useEditor.provideIntlayerEditor;
19
+ exports.useEditor = require_editor_useEditor.useEditor;
@@ -1,32 +1,67 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- const require_client_installIntlayer = require('../client/installIntlayer.cjs');
3
+ const require_client_intlayerToken = require('../client/intlayerToken.cjs');
4
4
  let _angular_core = require("@angular/core");
5
5
  let _intlayer_editor_isEnabled = require("@intlayer/editor/isEnabled");
6
6
 
7
7
  //#region src/editor/useEditor.ts
8
- const useEditor = () => {
9
- if (process.env.INTLAYER_EDITOR_ENABLED === "false" || !_intlayer_editor_isEnabled.isEnabled) return;
8
+ /**
9
+ * Initialises the Intlayer editor client singleton when the editor is enabled.
10
+ * Syncs the current locale from the provided Intlayer client into the editor
11
+ * manager so the editor always knows which locale the app is displaying.
12
+ *
13
+ * Must be called inside an Angular injection context (e.g. a component
14
+ * constructor, `provideAppInitializer`, or `runInInjectionContext`).
15
+ *
16
+ * @param client - The IntlayerProvider instance to sync locale from.
17
+ * When omitted the function injects `INTLAYER_TOKEN` from the DI tree,
18
+ * so it still works when called directly from a component.
19
+ */
20
+ const useEditor = (client) => {
21
+ if (!_intlayer_editor_isEnabled.isEnabled) return;
10
22
  const destroyRef = (0, _angular_core.inject)(_angular_core.DestroyRef, { optional: true });
11
- const client = (0, _angular_core.inject)(require_client_installIntlayer.INTLAYER_TOKEN, { optional: true });
12
23
  const injector = (0, _angular_core.inject)(_angular_core.Injector);
24
+ const resolvedClient = client ?? (0, _angular_core.inject)(require_client_intlayerToken.INTLAYER_TOKEN, { optional: true });
25
+ const manager = (0, _angular_core.signal)(null);
26
+ let stopped = false;
13
27
  import("@intlayer/editor").then(({ initEditorClient }) => {
14
- const manager = initEditorClient();
15
- if (client) {
16
- const effectRef = (0, _angular_core.runInInjectionContext)(injector, () => (0, _angular_core.effect)(() => {
17
- const locale = client.locale();
18
- if (locale) manager.currentLocale.set(locale);
19
- }));
20
- destroyRef?.onDestroy(() => effectRef.destroy());
21
- }
28
+ if (stopped) return;
29
+ manager.set(initEditorClient());
22
30
  });
31
+ const effectRef = (0, _angular_core.runInInjectionContext)(injector, () => (0, _angular_core.effect)(() => {
32
+ const m = manager();
33
+ const locale = resolvedClient?.locale();
34
+ if (m && locale) m.currentLocale.set(locale);
35
+ }));
23
36
  destroyRef?.onDestroy(() => {
37
+ stopped = true;
38
+ effectRef.destroy();
39
+ manager.set(null);
24
40
  import("@intlayer/editor").then(({ stopEditorClient }) => {
25
41
  stopEditorClient();
26
42
  });
27
43
  });
28
44
  };
45
+ /**
46
+ * Angular provider that wires `useEditor` into the application initialisation
47
+ * phase via `provideAppInitializer`.
48
+ *
49
+ * `provideIntlayer()` already calls this internally, so you only need this
50
+ * function when you want to manage providers individually.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * // app.config.ts
55
+ * import { provideIntlayer, provideIntlayerEditor } from 'angular-intlayer';
56
+ *
57
+ * export const appConfig: ApplicationConfig = {
58
+ * providers: [provideIntlayer(), provideIntlayerEditor()],
59
+ * };
60
+ * ```
61
+ */
62
+ const provideIntlayerEditor = (client) => (0, _angular_core.provideAppInitializer)(() => useEditor(client));
29
63
 
30
64
  //#endregion
65
+ exports.provideIntlayerEditor = provideIntlayerEditor;
31
66
  exports.useEditor = useEditor;
32
67
  //# sourceMappingURL=useEditor.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useEditor.cjs","names":["isEnabled","DestroyRef","INTLAYER_TOKEN","Injector"],"sources":["../../../src/editor/useEditor.ts"],"sourcesContent":["import {\n DestroyRef,\n effect,\n Injector,\n inject,\n runInInjectionContext,\n} from '@angular/core';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { INTLAYER_TOKEN, type IntlayerProvider } from '../client';\n\nexport const useEditor = () => {\n if (process.env.INTLAYER_EDITOR_ENABLED === 'false' || !isEnabled) return;\n\n const destroyRef = inject(DestroyRef, { optional: true });\n const client = inject<IntlayerProvider>(INTLAYER_TOKEN, {\n optional: true,\n } as any);\n const injector = inject(Injector);\n\n import('@intlayer/editor').then(({ initEditorClient }) => {\n const manager = initEditorClient();\n\n if (client) {\n const effectRef = runInInjectionContext(injector, () =>\n effect(() => {\n const locale = client.locale();\n if (locale) manager.currentLocale.set(locale as Locale);\n })\n );\n destroyRef?.onDestroy(() => effectRef.destroy());\n }\n });\n\n destroyRef?.onDestroy(() => {\n import('@intlayer/editor').then(({ stopEditorClient }) => {\n stopEditorClient();\n });\n });\n};\n"],"mappings":";;;;;;;AAWA,MAAa,kBAAkB;AAC7B,KAAI,QAAQ,IAAI,4BAA4B,WAAW,CAACA,qCAAW;CAEnE,MAAM,uCAAoBC,0BAAY,EAAE,UAAU,MAAM,CAAC;CACzD,MAAM,mCAAkCC,+CAAgB,EACtD,UAAU,MACX,CAAQ;CACT,MAAM,qCAAkBC,uBAAS;AAEjC,QAAO,oBAAoB,MAAM,EAAE,uBAAuB;EACxD,MAAM,UAAU,kBAAkB;AAElC,MAAI,QAAQ;GACV,MAAM,qDAAkC,gDACzB;IACX,MAAM,SAAS,OAAO,QAAQ;AAC9B,QAAI,OAAQ,SAAQ,cAAc,IAAI,OAAiB;KACvD,CACH;AACD,eAAY,gBAAgB,UAAU,SAAS,CAAC;;GAElD;AAEF,aAAY,gBAAgB;AAC1B,SAAO,oBAAoB,MAAM,EAAE,uBAAuB;AACxD,qBAAkB;IAClB;GACF"}
1
+ {"version":3,"file":"useEditor.cjs","names":["isEnabled","DestroyRef","Injector","INTLAYER_TOKEN"],"sources":["../../../src/editor/useEditor.ts"],"sourcesContent":["import {\n DestroyRef,\n effect,\n Injector,\n inject,\n provideAppInitializer,\n runInInjectionContext,\n signal,\n} from '@angular/core';\nimport type { EditorStateManager } from '@intlayer/editor';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { Locale } from '@intlayer/types/allLocales';\n// Import from the standalone token file to avoid a circular dependency:\n// installIntlayer.ts → useEditor.ts → ../client → installIntlayer.ts\nimport { INTLAYER_TOKEN, type IntlayerProvider } from '../client/intlayerToken';\n\n/**\n * Initialises the Intlayer editor client singleton when the editor is enabled.\n * Syncs the current locale from the provided Intlayer client into the editor\n * manager so the editor always knows which locale the app is displaying.\n *\n * Must be called inside an Angular injection context (e.g. a component\n * constructor, `provideAppInitializer`, or `runInInjectionContext`).\n *\n * @param client - The IntlayerProvider instance to sync locale from.\n * When omitted the function injects `INTLAYER_TOKEN` from the DI tree,\n * so it still works when called directly from a component.\n */\nexport const useEditor = (client?: IntlayerProvider | null): void => {\n if (!isEnabled) return;\n\n const destroyRef = inject(DestroyRef, { optional: true });\n const injector = inject(Injector);\n\n // Resolve the client: use the passed-in reference or fall back to injection.\n const resolvedClient =\n client ??\n inject<IntlayerProvider>(INTLAYER_TOKEN, { optional: true } as any);\n\n // `manager` signal is set once the async import resolves.\n // Using a signal lets an `effect()` react to it becoming available.\n const manager = signal<EditorStateManager | null>(null);\n\n // Guard: prevents the async callback from acting after the view is destroyed.\n let stopped = false;\n\n // Initialise the editor client\n import('@intlayer/editor').then(({ initEditorClient }) => {\n if (stopped) return;\n manager.set(initEditorClient());\n });\n\n // Keep the editor locale in sync with the Angular locale signal\n const effectRef = runInInjectionContext(injector, () =>\n effect(() => {\n const m = manager();\n const locale = resolvedClient?.locale();\n if (m && locale) m.currentLocale.set(locale as Locale);\n })\n );\n\n // Tear down on destroy\n destroyRef?.onDestroy(() => {\n stopped = true;\n effectRef.destroy();\n manager.set(null);\n import('@intlayer/editor').then(({ stopEditorClient }) => {\n stopEditorClient();\n });\n });\n};\n\n/**\n * Angular provider that wires `useEditor` into the application initialisation\n * phase via `provideAppInitializer`.\n *\n * `provideIntlayer()` already calls this internally, so you only need this\n * function when you want to manage providers individually.\n *\n * @example\n * ```ts\n * // app.config.ts\n * import { provideIntlayer, provideIntlayerEditor } from 'angular-intlayer';\n *\n * export const appConfig: ApplicationConfig = {\n * providers: [provideIntlayer(), provideIntlayerEditor()],\n * };\n * ```\n */\nexport const provideIntlayerEditor = (client?: IntlayerProvider | null) =>\n provideAppInitializer(() => useEditor(client));\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA4BA,MAAa,aAAa,WAA2C;AACnE,KAAI,CAACA,qCAAW;CAEhB,MAAM,uCAAoBC,0BAAY,EAAE,UAAU,MAAM,CAAC;CACzD,MAAM,qCAAkBC,uBAAS;CAGjC,MAAM,iBACJ,oCACyBC,6CAAgB,EAAE,UAAU,MAAM,CAAQ;CAIrE,MAAM,oCAA4C,KAAK;CAGvD,IAAI,UAAU;AAGd,QAAO,oBAAoB,MAAM,EAAE,uBAAuB;AACxD,MAAI,QAAS;AACb,UAAQ,IAAI,kBAAkB,CAAC;GAC/B;CAGF,MAAM,qDAAkC,gDACzB;EACX,MAAM,IAAI,SAAS;EACnB,MAAM,SAAS,gBAAgB,QAAQ;AACvC,MAAI,KAAK,OAAQ,GAAE,cAAc,IAAI,OAAiB;GACtD,CACH;AAGD,aAAY,gBAAgB;AAC1B,YAAU;AACV,YAAU,SAAS;AACnB,UAAQ,IAAI,KAAK;AACjB,SAAO,oBAAoB,MAAM,EAAE,uBAAuB;AACxD,qBAAkB;IAClB;GACF;;;;;;;;;;;;;;;;;;;AAoBJ,MAAa,yBAAyB,0DACR,UAAU,OAAO,CAAC"}