defuss 2.0.9 → 2.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,63 +1,174 @@
1
1
  'use strict';
2
2
 
3
- var dom = require('./dom-CEo2EcJv.cjs');
3
+ var dom = require('./dom-CZ_THi-B.cjs');
4
4
  require('defuss-runtime');
5
5
 
6
6
  const inDevMode = true;
7
7
 
8
8
  const VARIABLE_REGEX = /{([^}]*)}/g;
9
- const interpolate = (template, replacements) => template.replace(VARIABLE_REGEX, (_, key) => replacements[key] || `{${key}}`);
9
+ const DOUBLE_BRACE_REGEX = /\{\{([^}]*)\}\}/g;
10
+ const interpolate = (template, replacements) => {
11
+ let result = template.replace(DOUBLE_BRACE_REGEX, (match, key) => {
12
+ const replacement = replacements[key];
13
+ if (replacement !== void 0) {
14
+ return `{${replacement}}`;
15
+ }
16
+ return match;
17
+ });
18
+ result = result.replace(VARIABLE_REGEX, (match, key) => {
19
+ const replacement = replacements[key];
20
+ if (replacement !== void 0) {
21
+ return replacement;
22
+ }
23
+ return match;
24
+ });
25
+ return result;
26
+ };
10
27
  const createI18n = () => {
11
28
  const translationsStore = dom.createStore({});
12
29
  let language = "en";
13
30
  const onLanguageChangeCallbacks = [];
14
- return {
15
- language,
31
+ const api = {
32
+ get language() {
33
+ return language;
34
+ },
16
35
  changeLanguage(newLanguage) {
17
- language = newLanguage;
18
- onLanguageChangeCallbacks.forEach((callback) => callback(newLanguage));
36
+ console.log(
37
+ "i18n changeLanguage called:",
38
+ newLanguage,
39
+ "callbacks:",
40
+ onLanguageChangeCallbacks.length
41
+ );
42
+ if (newLanguage !== language) {
43
+ language = newLanguage;
44
+ onLanguageChangeCallbacks.forEach((callback) => {
45
+ console.log("i18n calling callback for language change");
46
+ callback(newLanguage);
47
+ });
48
+ }
19
49
  },
20
50
  // example usage of the t function with placeholders:
21
51
  // const translatedString = t('greeting', { name: 'John', age: '30' }, 'common');
22
52
  // this would replace placeholders {name} and {age} in the translation string with 'John' and '30' respectively.
23
53
  t(path, replacements = {}) {
24
- const template = translationsStore.get(`${language}.${path}`) || path;
54
+ const languageData = translationsStore.get(language);
55
+ if (!languageData) {
56
+ return path;
57
+ }
58
+ let template = languageData[path];
59
+ if (template === void 0) {
60
+ const pathParts = path.split(".");
61
+ let current = languageData;
62
+ for (const part of pathParts) {
63
+ current = current?.[part];
64
+ if (current === void 0) {
65
+ break;
66
+ }
67
+ }
68
+ template = current;
69
+ }
70
+ if (template === void 0) {
71
+ return path;
72
+ }
25
73
  if (typeof template !== "string") {
26
- return template;
74
+ return path;
27
75
  }
28
76
  return interpolate(template, replacements);
29
77
  },
30
78
  load(newLanguage, namespaceTranslations) {
79
+ console.log(
80
+ "i18n load called:",
81
+ newLanguage,
82
+ "translations:",
83
+ namespaceTranslations,
84
+ "callbacks:",
85
+ onLanguageChangeCallbacks.length
86
+ );
31
87
  translationsStore.set(newLanguage, {
32
88
  ...translationsStore.get(newLanguage),
33
89
  ...namespaceTranslations
34
90
  });
91
+ if (newLanguage === language) {
92
+ onLanguageChangeCallbacks.forEach((callback) => {
93
+ console.log("i18n calling callback for load");
94
+ callback(language);
95
+ });
96
+ }
35
97
  },
36
98
  subscribe(onLanguageChange) {
99
+ console.log(
100
+ "i18n subscribe called, total callbacks will be:",
101
+ onLanguageChangeCallbacks.length + 1
102
+ );
37
103
  onLanguageChangeCallbacks.push(onLanguageChange);
38
- return () => {
39
- const index = onLanguageChangeCallbacks.indexOf(onLanguageChange);
40
- if (index >= 0) onLanguageChangeCallbacks.splice(index, 1);
41
- };
104
+ return () => api.unsubscribe(onLanguageChange);
105
+ },
106
+ unsubscribe(onLanguageChange) {
107
+ const index = onLanguageChangeCallbacks.indexOf(onLanguageChange);
108
+ console.log(
109
+ "i18n unsubscribe called, index:",
110
+ index,
111
+ "total callbacks before:",
112
+ onLanguageChangeCallbacks.length
113
+ );
114
+ if (index >= 0) onLanguageChangeCallbacks.splice(index, 1);
42
115
  }
43
116
  };
117
+ return api;
44
118
  };
45
119
  const i18n = createI18n();
46
120
 
47
- const Trans = ({ path, replacements, tag, ...attrs }) => {
48
- const ref = {};
49
- i18n.subscribe(() => {
50
- const value = i18n.t(path, replacements);
51
- console.log("new val", value);
52
- });
121
+ const Trans = ({
122
+ key,
123
+ values,
124
+ tag,
125
+ ref,
126
+ ...attrs
127
+ }) => {
128
+ const _ref = ref || {};
129
+ const updateContent = () => {
130
+ console.log("Trans updateContent called for key:", key);
131
+ const value = i18n.t(key, values);
132
+ console.log("Trans updateContent: computed value:", value);
133
+ if (_ref.current) {
134
+ console.log(
135
+ "Trans updateContent: updating DOM element",
136
+ _ref.current.innerText
137
+ );
138
+ dom.$(_ref.current).update(value);
139
+ } else {
140
+ console.log("Trans updateContent: _ref.current is null/undefined");
141
+ }
142
+ };
143
+ _ref.updateValues = (newValues) => {
144
+ console.log("Trans updateValues called with:", newValues);
145
+ values = newValues;
146
+ updateContent();
147
+ };
148
+ const onMount = () => {
149
+ console.log("Trans onMount called for key:", key);
150
+ i18n.subscribe(updateContent);
151
+ };
152
+ const onUnmount = () => {
153
+ console.log("Trans onUnmount called for key:", key);
154
+ i18n.unsubscribe(updateContent);
155
+ };
156
+ console.log(
157
+ "Trans component creating for key:",
158
+ key,
159
+ "with initial value:",
160
+ i18n.t(key, values)
161
+ );
53
162
  return {
54
- tag: tag || "span",
163
+ type: tag || "span",
55
164
  attributes: {
56
- ref,
57
- ...attrs
165
+ ref: _ref,
166
+ ...attrs,
167
+ onMount,
168
+ onUnmount
58
169
  },
59
170
  // initially render
60
- children: i18n.t(path, replacements)
171
+ children: i18n.t(key, values)
61
172
  };
62
173
  };
63
174
 
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { T as PersistenceProviderType, U as PersistenceProviderOptions, W as PersistenceProviderImpl, h as VNode, g as VNodeAttributes, R as RenderInput, G as Globals, N as NodeType, s as Props, n as VNodeChild, f as Ref } from './index-Zbp2D6Fm.js';
1
+ import { T as PersistenceProviderType, U as PersistenceProviderOptions, W as PersistenceProviderImpl, h as VNode, g as VNodeAttributes, R as RenderInput, G as Globals, N as NodeType, f as Ref, s as Props, n as VNodeChild } from './index-Zbp2D6Fm.js';
2
2
  export { a7 as $, A as AllHTMLElements, C as CSSProperties, X as Call, a0 as CallChainImpl, a1 as CallChainImplThenable, p as Children, ao as DOMPropValue, a5 as Dequery, ap as DequeryOptions, ar as DequerySyncMethodReturnType, am as Dimensions, D as DomAbstractionImpl, aq as ElementCreationOptions, F as FontFaceProperties, ak as FormFieldValue, al as FormKeyValues, I as Fragment, K as KeyFrameProperties, av as Listener, at as MemoryStorage, as as MiddlewareFn, P as ParentElementInput, b as ParentElementInputAsync, an as Position, d as RefUpdateFn, e as RefUpdateRenderFn, c as RefUpdateRenderFnInput, q as RenderNodeInput, a as RenderResult, r as RenderResultNode, aw as Store, S as SyncRenderInput, y as SyncRenderResult, V as VAttributes, o as VNodeChildren, j as VNodeKey, m as VNodeRef, l as VNodeRefCallback, k as VNodeRefObject, i as VNodeType, au as WebStorage, Y as addNonChainedReturnCallNames, ac as createCall, ad as createGetterSetterCall, t as createInPlaceErrorMessageVNode, Q as createRef, ax as createStore, ae as createSubChain, a4 as delayedAutoStart, a6 as dequery, $ as emptyImpl, a3 as getAllFormValues, aa as getDefaultDequeryOptions, Z as getNonChainedReturnCallNames, x as getRenderer, E as globalScopeDomApis, w as handleLifecycleEventsForOnMount, a8 as isDequery, a9 as isDequeryOptionsObject, H as isJSX, _ as isNonChainedReturnCall, O as isRef, u as jsx, L as jsxDEV, J as jsxs, ab as mapArrayIndexAccess, v as observeUnmount, B as renderIsomorphicAsync, z as renderIsomorphicSync, ah as renderNode, ai as resolveNodes, ag as runWithTimeGuard, a2 as scrollHelper, af as subChainForNextAwait, aj as traverse, M as updateDom } from './index-Zbp2D6Fm.js';
3
3
  import * as CSS from 'csstype';
4
4
  export { CSS };
@@ -71,20 +71,25 @@ interface I18nStore {
71
71
  changeLanguage: (language: string) => void;
72
72
  t: (path: string, options?: Record<string, string>) => string;
73
73
  load: (language: string, translations: TranslationObject) => void;
74
- subscribe: (onLanguageChange: OnLanguageChangeListener) => void;
74
+ subscribe: (onLanguageChange: OnLanguageChangeListener) => () => void;
75
+ unsubscribe: (onLanguageChange: OnLanguageChangeListener) => void;
75
76
  }
76
77
  declare const createI18n: () => I18nStore;
77
78
  declare const i18n: I18nStore;
78
79
 
80
+ interface TransRef extends Ref<string, HTMLElement> {
81
+ updateValues: (values: Replacements) => void;
82
+ }
79
83
  interface TransProps extends Props {
80
- path: string;
84
+ key: string;
85
+ ref?: TransRef;
81
86
  tag?: string;
82
- replacements?: Replacements;
87
+ values?: Replacements;
83
88
  class?: string;
84
89
  className?: string;
85
90
  style?: string;
86
91
  }
87
- declare const Trans: ({ path, replacements, tag, ...attrs }: TransProps) => VNodeChild;
92
+ declare const Trans: ({ key, values, tag, ref, ...attrs }: TransProps) => VNodeChild;
88
93
 
89
94
  type OnHandleRouteChangeFn = (newRoute: string, oldRoute: string) => void;
90
95
  type OnRouteChangeFn = (cb: OnHandleRouteChangeFn) => void;
@@ -210,4 +215,4 @@ declare const Suspense: ({ fallback, ref, children, class: _class, className, id
210
215
  children: VNode<VNodeAttributes>[];
211
216
  };
212
217
 
213
- export { Async, type AsyncProps, type AsyncState, type AsyncStateRef, Globals, type I18nStore, NodeType, type OnHandleRouteChangeFn, type OnLanguageChangeListener, type OnRouteChangeFn, PersistenceProviderImpl, PersistenceProviderOptions, PersistenceProviderType, Props, Redirect, type RedirectProps, Ref, RenderInput, type Replacements, Route, type RouteHandler, type RouteParams, type RouteProps, type RouteRegistration, type RouteRequest, Router, type RouterConfig, RouterSlot, RouterSlotId, type RouterSlotProps, type RouterStrategy, Suspense, type TokenizedPath, Trans, type TransProps, type TranslationObject, type Translations, VNode, VNodeAttributes, VNodeChild, type ValidChild, addElementEvent, areDomNodesEqual, checkElementVisibility, clearElementEvents, createI18n, domNodeToVNode, getEventMap, getMimeType, htmlStringToVNodes, i18n, inDevMode, isHTML, isMarkup, isSVG, matchRouteRegistrations, parseDOM, processAllFormElements, removeElementEvent, renderMarkup, replaceDomWithVdom, setupRouter, tokenizePath, updateDomWithVdom, waitForDOM, webstorage };
218
+ export { Async, type AsyncProps, type AsyncState, type AsyncStateRef, Globals, type I18nStore, NodeType, type OnHandleRouteChangeFn, type OnLanguageChangeListener, type OnRouteChangeFn, PersistenceProviderImpl, PersistenceProviderOptions, PersistenceProviderType, Props, Redirect, type RedirectProps, Ref, RenderInput, type Replacements, Route, type RouteHandler, type RouteParams, type RouteProps, type RouteRegistration, type RouteRequest, Router, type RouterConfig, RouterSlot, RouterSlotId, type RouterSlotProps, type RouterStrategy, Suspense, type TokenizedPath, Trans, type TransProps, type TransRef, type TranslationObject, type Translations, VNode, VNodeAttributes, VNodeChild, type ValidChild, addElementEvent, areDomNodesEqual, checkElementVisibility, clearElementEvents, createI18n, domNodeToVNode, getEventMap, getMimeType, htmlStringToVNodes, i18n, inDevMode, isHTML, isMarkup, isSVG, matchRouteRegistrations, parseDOM, processAllFormElements, removeElementEvent, renderMarkup, replaceDomWithVdom, setupRouter, tokenizePath, updateDomWithVdom, waitForDOM, webstorage };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { T as PersistenceProviderType, U as PersistenceProviderOptions, W as PersistenceProviderImpl, h as VNode, g as VNodeAttributes, R as RenderInput, G as Globals, N as NodeType, s as Props, n as VNodeChild, f as Ref } from './index-Zbp2D6Fm.js';
1
+ import { T as PersistenceProviderType, U as PersistenceProviderOptions, W as PersistenceProviderImpl, h as VNode, g as VNodeAttributes, R as RenderInput, G as Globals, N as NodeType, f as Ref, s as Props, n as VNodeChild } from './index-Zbp2D6Fm.js';
2
2
  export { a7 as $, A as AllHTMLElements, C as CSSProperties, X as Call, a0 as CallChainImpl, a1 as CallChainImplThenable, p as Children, ao as DOMPropValue, a5 as Dequery, ap as DequeryOptions, ar as DequerySyncMethodReturnType, am as Dimensions, D as DomAbstractionImpl, aq as ElementCreationOptions, F as FontFaceProperties, ak as FormFieldValue, al as FormKeyValues, I as Fragment, K as KeyFrameProperties, av as Listener, at as MemoryStorage, as as MiddlewareFn, P as ParentElementInput, b as ParentElementInputAsync, an as Position, d as RefUpdateFn, e as RefUpdateRenderFn, c as RefUpdateRenderFnInput, q as RenderNodeInput, a as RenderResult, r as RenderResultNode, aw as Store, S as SyncRenderInput, y as SyncRenderResult, V as VAttributes, o as VNodeChildren, j as VNodeKey, m as VNodeRef, l as VNodeRefCallback, k as VNodeRefObject, i as VNodeType, au as WebStorage, Y as addNonChainedReturnCallNames, ac as createCall, ad as createGetterSetterCall, t as createInPlaceErrorMessageVNode, Q as createRef, ax as createStore, ae as createSubChain, a4 as delayedAutoStart, a6 as dequery, $ as emptyImpl, a3 as getAllFormValues, aa as getDefaultDequeryOptions, Z as getNonChainedReturnCallNames, x as getRenderer, E as globalScopeDomApis, w as handleLifecycleEventsForOnMount, a8 as isDequery, a9 as isDequeryOptionsObject, H as isJSX, _ as isNonChainedReturnCall, O as isRef, u as jsx, L as jsxDEV, J as jsxs, ab as mapArrayIndexAccess, v as observeUnmount, B as renderIsomorphicAsync, z as renderIsomorphicSync, ah as renderNode, ai as resolveNodes, ag as runWithTimeGuard, a2 as scrollHelper, af as subChainForNextAwait, aj as traverse, M as updateDom } from './index-Zbp2D6Fm.js';
3
3
  import * as CSS from 'csstype';
4
4
  export { CSS };
@@ -71,20 +71,25 @@ interface I18nStore {
71
71
  changeLanguage: (language: string) => void;
72
72
  t: (path: string, options?: Record<string, string>) => string;
73
73
  load: (language: string, translations: TranslationObject) => void;
74
- subscribe: (onLanguageChange: OnLanguageChangeListener) => void;
74
+ subscribe: (onLanguageChange: OnLanguageChangeListener) => () => void;
75
+ unsubscribe: (onLanguageChange: OnLanguageChangeListener) => void;
75
76
  }
76
77
  declare const createI18n: () => I18nStore;
77
78
  declare const i18n: I18nStore;
78
79
 
80
+ interface TransRef extends Ref<string, HTMLElement> {
81
+ updateValues: (values: Replacements) => void;
82
+ }
79
83
  interface TransProps extends Props {
80
- path: string;
84
+ key: string;
85
+ ref?: TransRef;
81
86
  tag?: string;
82
- replacements?: Replacements;
87
+ values?: Replacements;
83
88
  class?: string;
84
89
  className?: string;
85
90
  style?: string;
86
91
  }
87
- declare const Trans: ({ path, replacements, tag, ...attrs }: TransProps) => VNodeChild;
92
+ declare const Trans: ({ key, values, tag, ref, ...attrs }: TransProps) => VNodeChild;
88
93
 
89
94
  type OnHandleRouteChangeFn = (newRoute: string, oldRoute: string) => void;
90
95
  type OnRouteChangeFn = (cb: OnHandleRouteChangeFn) => void;
@@ -210,4 +215,4 @@ declare const Suspense: ({ fallback, ref, children, class: _class, className, id
210
215
  children: VNode<VNodeAttributes>[];
211
216
  };
212
217
 
213
- export { Async, type AsyncProps, type AsyncState, type AsyncStateRef, Globals, type I18nStore, NodeType, type OnHandleRouteChangeFn, type OnLanguageChangeListener, type OnRouteChangeFn, PersistenceProviderImpl, PersistenceProviderOptions, PersistenceProviderType, Props, Redirect, type RedirectProps, Ref, RenderInput, type Replacements, Route, type RouteHandler, type RouteParams, type RouteProps, type RouteRegistration, type RouteRequest, Router, type RouterConfig, RouterSlot, RouterSlotId, type RouterSlotProps, type RouterStrategy, Suspense, type TokenizedPath, Trans, type TransProps, type TranslationObject, type Translations, VNode, VNodeAttributes, VNodeChild, type ValidChild, addElementEvent, areDomNodesEqual, checkElementVisibility, clearElementEvents, createI18n, domNodeToVNode, getEventMap, getMimeType, htmlStringToVNodes, i18n, inDevMode, isHTML, isMarkup, isSVG, matchRouteRegistrations, parseDOM, processAllFormElements, removeElementEvent, renderMarkup, replaceDomWithVdom, setupRouter, tokenizePath, updateDomWithVdom, waitForDOM, webstorage };
218
+ export { Async, type AsyncProps, type AsyncState, type AsyncStateRef, Globals, type I18nStore, NodeType, type OnHandleRouteChangeFn, type OnLanguageChangeListener, type OnRouteChangeFn, PersistenceProviderImpl, PersistenceProviderOptions, PersistenceProviderType, Props, Redirect, type RedirectProps, Ref, RenderInput, type Replacements, Route, type RouteHandler, type RouteParams, type RouteProps, type RouteRegistration, type RouteRequest, Router, type RouterConfig, RouterSlot, RouterSlotId, type RouterSlotProps, type RouterStrategy, Suspense, type TokenizedPath, Trans, type TransProps, type TransRef, type TranslationObject, type Translations, VNode, VNodeAttributes, VNodeChild, type ValidChild, addElementEvent, areDomNodesEqual, checkElementVisibility, clearElementEvents, createI18n, domNodeToVNode, getEventMap, getMimeType, htmlStringToVNodes, i18n, inDevMode, isHTML, isMarkup, isSVG, matchRouteRegistrations, parseDOM, processAllFormElements, removeElementEvent, renderMarkup, replaceDomWithVdom, setupRouter, tokenizePath, updateDomWithVdom, waitForDOM, webstorage };
package/dist/index.mjs CHANGED
@@ -1,62 +1,173 @@
1
- import { l as createStore, m as isServer, k as createRef, $, f as isRef } from './dom-C_AZUcA2.mjs';
2
- export { J as Call, O as CallChainImpl, P as CallChainImplThenable, F as Fragment, D as addElementEvent, K as addNonChainedReturnCallNames, n as areDomNodesEqual, B as checkElementVisibility, G as clearElementEvents, Y as createCall, Z as createGetterSetterCall, c as createInPlaceErrorMessageVNode, _ as createSubChain, S as delayedAutoStart, T as dequery, H as domNodeToVNode, N as emptyImpl, R as getAllFormValues, W as getDefaultDequeryOptions, C as getEventMap, z as getMimeType, L as getNonChainedReturnCallNames, g as getRenderer, b as globalScopeDomApis, h as handleLifecycleEventsForOnMount, I as htmlStringToVNodes, U as isDequery, V as isDequeryOptionsObject, v as isHTML, i as isJSX, x as isMarkup, M as isNonChainedReturnCall, t as isSVG, j as jsx, e as jsxDEV, d as jsxs, X as mapArrayIndexAccess, o as observeUnmount, s as parseDOM, A as processAllFormElements, E as removeElementEvent, a as renderIsomorphicAsync, r as renderIsomorphicSync, y as renderMarkup, a2 as renderNode, q as replaceDomWithVdom, a3 as resolveNodes, a1 as runWithTimeGuard, Q as scrollHelper, a0 as subChainForNextAwait, a4 as traverse, u as updateDom, p as updateDomWithVdom, w as waitForDOM, a5 as webstorage } from './dom-C_AZUcA2.mjs';
1
+ import { l as createStore, $, m as isServer, k as createRef, f as isRef } from './dom-BODEuMW4.mjs';
2
+ export { J as Call, O as CallChainImpl, P as CallChainImplThenable, F as Fragment, D as addElementEvent, K as addNonChainedReturnCallNames, n as areDomNodesEqual, B as checkElementVisibility, G as clearElementEvents, Y as createCall, Z as createGetterSetterCall, c as createInPlaceErrorMessageVNode, _ as createSubChain, S as delayedAutoStart, T as dequery, H as domNodeToVNode, N as emptyImpl, R as getAllFormValues, W as getDefaultDequeryOptions, C as getEventMap, z as getMimeType, L as getNonChainedReturnCallNames, g as getRenderer, b as globalScopeDomApis, h as handleLifecycleEventsForOnMount, I as htmlStringToVNodes, U as isDequery, V as isDequeryOptionsObject, v as isHTML, i as isJSX, x as isMarkup, M as isNonChainedReturnCall, t as isSVG, j as jsx, e as jsxDEV, d as jsxs, X as mapArrayIndexAccess, o as observeUnmount, s as parseDOM, A as processAllFormElements, E as removeElementEvent, a as renderIsomorphicAsync, r as renderIsomorphicSync, y as renderMarkup, a2 as renderNode, q as replaceDomWithVdom, a3 as resolveNodes, a1 as runWithTimeGuard, Q as scrollHelper, a0 as subChainForNextAwait, a4 as traverse, u as updateDom, p as updateDomWithVdom, w as waitForDOM, a5 as webstorage } from './dom-BODEuMW4.mjs';
3
3
  import 'defuss-runtime';
4
4
 
5
5
  const inDevMode = true;
6
6
 
7
7
  const VARIABLE_REGEX = /{([^}]*)}/g;
8
- const interpolate = (template, replacements) => template.replace(VARIABLE_REGEX, (_, key) => replacements[key] || `{${key}}`);
8
+ const DOUBLE_BRACE_REGEX = /\{\{([^}]*)\}\}/g;
9
+ const interpolate = (template, replacements) => {
10
+ let result = template.replace(DOUBLE_BRACE_REGEX, (match, key) => {
11
+ const replacement = replacements[key];
12
+ if (replacement !== void 0) {
13
+ return `{${replacement}}`;
14
+ }
15
+ return match;
16
+ });
17
+ result = result.replace(VARIABLE_REGEX, (match, key) => {
18
+ const replacement = replacements[key];
19
+ if (replacement !== void 0) {
20
+ return replacement;
21
+ }
22
+ return match;
23
+ });
24
+ return result;
25
+ };
9
26
  const createI18n = () => {
10
27
  const translationsStore = createStore({});
11
28
  let language = "en";
12
29
  const onLanguageChangeCallbacks = [];
13
- return {
14
- language,
30
+ const api = {
31
+ get language() {
32
+ return language;
33
+ },
15
34
  changeLanguage(newLanguage) {
16
- language = newLanguage;
17
- onLanguageChangeCallbacks.forEach((callback) => callback(newLanguage));
35
+ console.log(
36
+ "i18n changeLanguage called:",
37
+ newLanguage,
38
+ "callbacks:",
39
+ onLanguageChangeCallbacks.length
40
+ );
41
+ if (newLanguage !== language) {
42
+ language = newLanguage;
43
+ onLanguageChangeCallbacks.forEach((callback) => {
44
+ console.log("i18n calling callback for language change");
45
+ callback(newLanguage);
46
+ });
47
+ }
18
48
  },
19
49
  // example usage of the t function with placeholders:
20
50
  // const translatedString = t('greeting', { name: 'John', age: '30' }, 'common');
21
51
  // this would replace placeholders {name} and {age} in the translation string with 'John' and '30' respectively.
22
52
  t(path, replacements = {}) {
23
- const template = translationsStore.get(`${language}.${path}`) || path;
53
+ const languageData = translationsStore.get(language);
54
+ if (!languageData) {
55
+ return path;
56
+ }
57
+ let template = languageData[path];
58
+ if (template === void 0) {
59
+ const pathParts = path.split(".");
60
+ let current = languageData;
61
+ for (const part of pathParts) {
62
+ current = current?.[part];
63
+ if (current === void 0) {
64
+ break;
65
+ }
66
+ }
67
+ template = current;
68
+ }
69
+ if (template === void 0) {
70
+ return path;
71
+ }
24
72
  if (typeof template !== "string") {
25
- return template;
73
+ return path;
26
74
  }
27
75
  return interpolate(template, replacements);
28
76
  },
29
77
  load(newLanguage, namespaceTranslations) {
78
+ console.log(
79
+ "i18n load called:",
80
+ newLanguage,
81
+ "translations:",
82
+ namespaceTranslations,
83
+ "callbacks:",
84
+ onLanguageChangeCallbacks.length
85
+ );
30
86
  translationsStore.set(newLanguage, {
31
87
  ...translationsStore.get(newLanguage),
32
88
  ...namespaceTranslations
33
89
  });
90
+ if (newLanguage === language) {
91
+ onLanguageChangeCallbacks.forEach((callback) => {
92
+ console.log("i18n calling callback for load");
93
+ callback(language);
94
+ });
95
+ }
34
96
  },
35
97
  subscribe(onLanguageChange) {
98
+ console.log(
99
+ "i18n subscribe called, total callbacks will be:",
100
+ onLanguageChangeCallbacks.length + 1
101
+ );
36
102
  onLanguageChangeCallbacks.push(onLanguageChange);
37
- return () => {
38
- const index = onLanguageChangeCallbacks.indexOf(onLanguageChange);
39
- if (index >= 0) onLanguageChangeCallbacks.splice(index, 1);
40
- };
103
+ return () => api.unsubscribe(onLanguageChange);
104
+ },
105
+ unsubscribe(onLanguageChange) {
106
+ const index = onLanguageChangeCallbacks.indexOf(onLanguageChange);
107
+ console.log(
108
+ "i18n unsubscribe called, index:",
109
+ index,
110
+ "total callbacks before:",
111
+ onLanguageChangeCallbacks.length
112
+ );
113
+ if (index >= 0) onLanguageChangeCallbacks.splice(index, 1);
41
114
  }
42
115
  };
116
+ return api;
43
117
  };
44
118
  const i18n = createI18n();
45
119
 
46
- const Trans = ({ path, replacements, tag, ...attrs }) => {
47
- const ref = {};
48
- i18n.subscribe(() => {
49
- const value = i18n.t(path, replacements);
50
- console.log("new val", value);
51
- });
120
+ const Trans = ({
121
+ key,
122
+ values,
123
+ tag,
124
+ ref,
125
+ ...attrs
126
+ }) => {
127
+ const _ref = ref || {};
128
+ const updateContent = () => {
129
+ console.log("Trans updateContent called for key:", key);
130
+ const value = i18n.t(key, values);
131
+ console.log("Trans updateContent: computed value:", value);
132
+ if (_ref.current) {
133
+ console.log(
134
+ "Trans updateContent: updating DOM element",
135
+ _ref.current.innerText
136
+ );
137
+ $(_ref.current).update(value);
138
+ } else {
139
+ console.log("Trans updateContent: _ref.current is null/undefined");
140
+ }
141
+ };
142
+ _ref.updateValues = (newValues) => {
143
+ console.log("Trans updateValues called with:", newValues);
144
+ values = newValues;
145
+ updateContent();
146
+ };
147
+ const onMount = () => {
148
+ console.log("Trans onMount called for key:", key);
149
+ i18n.subscribe(updateContent);
150
+ };
151
+ const onUnmount = () => {
152
+ console.log("Trans onUnmount called for key:", key);
153
+ i18n.unsubscribe(updateContent);
154
+ };
155
+ console.log(
156
+ "Trans component creating for key:",
157
+ key,
158
+ "with initial value:",
159
+ i18n.t(key, values)
160
+ );
52
161
  return {
53
- tag: tag || "span",
162
+ type: tag || "span",
54
163
  attributes: {
55
- ref,
56
- ...attrs
164
+ ref: _ref,
165
+ ...attrs,
166
+ onMount,
167
+ onUnmount
57
168
  },
58
169
  // initially render
59
- children: i18n.t(path, replacements)
170
+ children: i18n.t(key, values)
60
171
  };
61
172
  };
62
173
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var dom = require('../dom-CEo2EcJv.cjs');
3
+ var dom = require('../dom-CZ_THi-B.cjs');
4
4
  require('defuss-runtime');
5
5
 
6
6
  const renderSync = (virtualNode, parentDomElement = document.documentElement) => {
@@ -57,6 +57,7 @@ const hydrate = (nodes, parentElements, debug) => {
57
57
  }
58
58
  }
59
59
  if (vnode?.attributes?.onMount) {
60
+ console.log("hydrate onMount", vnode.attributes.onMount);
60
61
  vnode.attributes.onMount(element);
61
62
  }
62
63
  if (vnode?.attributes?.onUnmount) {
@@ -1,5 +1,5 @@
1
- import { b as globalScopeDomApis, r as renderIsomorphicSync, a as renderIsomorphicAsync, o as observeUnmount } from '../dom-C_AZUcA2.mjs';
2
- export { F as Fragment, c as createInPlaceErrorMessageVNode, k as createRef, g as getRenderer, h as handleLifecycleEventsForOnMount, i as isJSX, f as isRef, j as jsx, e as jsxDEV, d as jsxs, u as updateDom } from '../dom-C_AZUcA2.mjs';
1
+ import { b as globalScopeDomApis, r as renderIsomorphicSync, a as renderIsomorphicAsync, o as observeUnmount } from '../dom-BODEuMW4.mjs';
2
+ export { F as Fragment, c as createInPlaceErrorMessageVNode, k as createRef, g as getRenderer, h as handleLifecycleEventsForOnMount, i as isJSX, f as isRef, j as jsx, e as jsxDEV, d as jsxs, u as updateDom } from '../dom-BODEuMW4.mjs';
3
3
  import 'defuss-runtime';
4
4
 
5
5
  const renderSync = (virtualNode, parentDomElement = document.documentElement) => {
@@ -56,6 +56,7 @@ const hydrate = (nodes, parentElements, debug) => {
56
56
  }
57
57
  }
58
58
  if (vnode?.attributes?.onMount) {
59
+ console.log("hydrate onMount", vnode.attributes.onMount);
59
60
  vnode.attributes.onMount(element);
60
61
  }
61
62
  if (vnode?.attributes?.onUnmount) {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var dom = require('../dom-CEo2EcJv.cjs');
3
+ var dom = require('../dom-CZ_THi-B.cjs');
4
4
  require('defuss-runtime');
5
5
 
6
6
 
@@ -1,2 +1,2 @@
1
- export { F as Fragment, c as createInPlaceErrorMessageVNode, k as createRef, g as getRenderer, b as globalScopeDomApis, h as handleLifecycleEventsForOnMount, i as isJSX, f as isRef, j as jsx, e as jsxDEV, d as jsxs, o as observeUnmount, a as renderIsomorphicAsync, r as renderIsomorphicSync, u as updateDom } from '../dom-C_AZUcA2.mjs';
1
+ export { F as Fragment, c as createInPlaceErrorMessageVNode, k as createRef, g as getRenderer, b as globalScopeDomApis, h as handleLifecycleEventsForOnMount, i as isJSX, f as isRef, j as jsx, e as jsxDEV, d as jsxs, o as observeUnmount, a as renderIsomorphicAsync, r as renderIsomorphicSync, u as updateDom } from '../dom-BODEuMW4.mjs';
2
2
  import 'defuss-runtime';
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var HappyDom = require('happy-dom');
4
- var dom = require('../dom-CEo2EcJv.cjs');
4
+ var dom = require('../dom-CZ_THi-B.cjs');
5
5
  var serializeHtml = require('w3c-xmlserializer');
6
6
  require('defuss-runtime');
7
7
 
@@ -1,6 +1,6 @@
1
1
  import * as HappyDom from 'happy-dom';
2
- import { r as renderIsomorphicSync, a as renderIsomorphicAsync, b as globalScopeDomApis } from '../dom-C_AZUcA2.mjs';
3
- export { F as Fragment, c as createInPlaceErrorMessageVNode, k as createRef, g as getRenderer, h as handleLifecycleEventsForOnMount, i as isJSX, f as isRef, j as jsx, e as jsxDEV, d as jsxs, o as observeUnmount, u as updateDom } from '../dom-C_AZUcA2.mjs';
2
+ import { r as renderIsomorphicSync, a as renderIsomorphicAsync, b as globalScopeDomApis } from '../dom-BODEuMW4.mjs';
3
+ export { F as Fragment, c as createInPlaceErrorMessageVNode, k as createRef, g as getRenderer, h as handleLifecycleEventsForOnMount, i as isJSX, f as isRef, j as jsx, e as jsxDEV, d as jsxs, o as observeUnmount, u as updateDom } from '../dom-BODEuMW4.mjs';
4
4
  import serializeHtml from 'w3c-xmlserializer';
5
5
  import 'defuss-runtime';
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "defuss",
3
- "version": "2.0.9",
3
+ "version": "2.0.11",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"