@i18n-micro/core 1.3.11 → 1.3.13
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/devtools-entry.d.ts +1 -0
- package/dist/devtools.cjs +1 -0
- package/dist/devtools.d.cts +55 -0
- package/dist/devtools.d.ts +55 -0
- package/dist/devtools.mjs +159 -0
- package/package.json +17 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { buildInspectorState, buildInspectorTree, countTranslationKeys, decodeInspectorPath, encodeInspectorPath, flattenTranslationNode, getByInspectorPath, parseInspectorNodeId, type BuildInspectorTreeOptions, type I18nDevtoolsInspectorNode, type I18nDevtoolsStateSnapshot, } from './devtools';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k={label:"Active",textColor:16777215,backgroundColor:4372611,tooltip:"Current locale and route context"},A="root",m="active",g="locale|",f="chunk|",i="key|",d=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);function T(e){return typeof e=="string"?JSON.stringify(e):e===null?"null":e===void 0?"undefined":typeof e=="object"?Array.isArray(e)?`[Array(${e.length})]`:"{…}":String(e)}function h(e,t,n,o){return e===n&&t===o?[k]:void 0}function $(e,t){const n=`${t}:`,o=new Set;for(const c of e.translations.keys())c.startsWith(n)&&o.add(c.slice(n.length)||"index");return[...o].sort()}function _(e,t){const n=new Set(t.map(o=>o.code));for(const o of e.translations.keys()){const c=o.split(":")[0];c&&n.add(c)}return[...n].sort()}function b(e){return e.map(t=>encodeURIComponent(t)).join("/")}function v(e){return e?e.split("/").map(t=>decodeURIComponent(t)):[]}function N(e,t){let n=e;for(const o of t){if(!d(n)||!Object.prototype.hasOwnProperty.call(n,o))return;n=n[o]}return n}function C(e){if(!e||e===A)return{kind:"root"};if(e===m)return{kind:"active"};if(e.startsWith(g))return{kind:"locale",locale:e.slice(g.length)};if(e.startsWith(f)){const[t="",n="index"]=e.slice(f.length).split("|");return{kind:"chunk",locale:t,routeName:n}}if(e.startsWith(i)){const t=e.slice(i.length).split("|"),n=t[0]??"",o=t[1]??"index",c=t.slice(2).join("|");return{kind:"key",locale:n,routeName:o,path:c,segments:v(c)}}return{kind:"root"}}function y(e,t,n){return{...n,id:`${i}${e}|${t}|${n.id.slice(i.length)}`}}function u(e,t=[]){const n=t.length===0?e:N(e,t);return d(n)?Object.keys(n).filter(o=>o!=="__proto__").map(o=>{const c=[...t,o],r=n[o],a=d(r);return{id:`${i}${b(c)}`,label:a?o:`${o}: ${T(r)}`,children:a?[]:void 0}}).sort((o,c)=>o.label.localeCompare(c.label)):[]}function L(e){const t=C(e.nodeId),n=e.activeLocale,o=e.activeRouteName||"index";if(t.kind==="root"){const c=_(e.storage,e.configuredLocales),r=[{id:m,label:`Active (${n}:${o})`,tags:[k]}];for(const a of c){const l=e.configuredLocales.find(s=>s.code===a),p=$(e.storage,a);r.push({id:`${g}${a}`,label:l?.displayName?`${a} (${l.displayName})`:a,tags:a===n?[{...k,tooltip:"Active locale"}]:void 0});for(const s of p)r.push({id:`${f}${a}|${s}`,label:`${a}:${s}`,tags:h(a,s,n,o)})}return r}if(t.kind==="active")return u(e.activeTranslations??{}).map(c=>y(n,o,c));if(t.kind==="locale"&&t.locale){const c=t.locale;return $(e.storage,c).map(r=>({id:`${f}${c}|${r}`,label:r,children:[],tags:h(c,r,n,o)}))}if(t.kind==="chunk"&&t.locale){const c=t.locale,r=t.routeName||"index",a=e.storage.translations.get(`${c}:${r}`);return u(a??{}).map(l=>y(c,r,l))}if(t.kind==="key"&&t.locale){const c=t.locale,r=t.routeName||"index",a=e.storage.translations.get(`${c}:${r}`),l=t.segments??[],s=n===c&&o===r?e.activeTranslations??a??{}:a??{};return u(s,l).map(I=>y(c,r,I))}return[]}function P(e){return{Context:[{key:"locale",value:e.locale},{key:"routeName",value:e.routeName},{key:"strategy",value:e.strategy??"—"},{key:"defaultLocale",value:e.defaultLocale??"—"},{key:"fallbackLocale",value:e.fallbackLocale??"—"},{key:"cachedChunks",value:e.cachedChunks}],Locales:e.locales.map(t=>({key:t.code,value:t.displayName??t.code,editable:!1}))}}function x(e){if(!e||typeof e!="object")return 0;const t=new Set,n=(o,c="")=>{for(const r of Object.keys(o)){if(r==="__proto__")continue;const a=c?`${c}.${r}`:r;t.add(a);const l=o[r];d(l)&&n(l,a)}};return n(e),t.size}exports.buildInspectorState=P;exports.buildInspectorTree=L;exports.countTranslationKeys=x;exports.decodeInspectorPath=v;exports.encodeInspectorPath=b;exports.flattenTranslationNode=u;exports.getByInspectorPath=N;exports.parseInspectorNodeId=C;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Locale, Translations } from '@i18n-micro/types';
|
|
2
|
+
import { TranslationStorage } from './translation';
|
|
3
|
+
export interface I18nDevtoolsInspectorNode {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
children?: I18nDevtoolsInspectorNode[];
|
|
7
|
+
tags?: Array<{
|
|
8
|
+
label: string;
|
|
9
|
+
textColor: number;
|
|
10
|
+
backgroundColor: number;
|
|
11
|
+
tooltip?: string;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
export interface I18nDevtoolsStateSnapshot {
|
|
15
|
+
locale: string;
|
|
16
|
+
routeName: string;
|
|
17
|
+
strategy?: string;
|
|
18
|
+
defaultLocale?: string;
|
|
19
|
+
fallbackLocale?: string;
|
|
20
|
+
cachedChunks: number;
|
|
21
|
+
locales: Array<{
|
|
22
|
+
code: string;
|
|
23
|
+
displayName?: string;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
27
|
+
export interface BuildInspectorTreeOptions {
|
|
28
|
+
nodeId: string;
|
|
29
|
+
storage: TranslationStorage;
|
|
30
|
+
configuredLocales: Locale[];
|
|
31
|
+
activeLocale: string;
|
|
32
|
+
activeRouteName: string;
|
|
33
|
+
activeTranslations?: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Encode path segments so a literal key `"a.b"` and nested path `a → b` get distinct node IDs.
|
|
37
|
+
*/
|
|
38
|
+
export declare function encodeInspectorPath(segments: string[]): string;
|
|
39
|
+
export declare function decodeInspectorPath(encoded: string): string[];
|
|
40
|
+
export declare function getByInspectorPath(obj: Record<string, unknown>, segments: string[]): unknown;
|
|
41
|
+
export declare function parseInspectorNodeId(nodeId: string): {
|
|
42
|
+
kind: 'root' | 'active' | 'locale' | 'chunk' | 'key';
|
|
43
|
+
locale?: string;
|
|
44
|
+
routeName?: string;
|
|
45
|
+
path?: string;
|
|
46
|
+
segments?: string[];
|
|
47
|
+
};
|
|
48
|
+
export declare function flattenTranslationNode(obj: Record<string, unknown>, parentSegments?: string[]): I18nDevtoolsInspectorNode[];
|
|
49
|
+
export declare function buildInspectorTree(options: BuildInspectorTreeOptions): I18nDevtoolsInspectorNode[];
|
|
50
|
+
export declare function buildInspectorState(snapshot: I18nDevtoolsStateSnapshot): Record<string, Array<{
|
|
51
|
+
key: string;
|
|
52
|
+
value: unknown;
|
|
53
|
+
editable?: boolean;
|
|
54
|
+
}>>;
|
|
55
|
+
export declare function countTranslationKeys(translations: Translations | Record<string, unknown> | undefined): number;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Locale, Translations } from '@i18n-micro/types';
|
|
2
|
+
import { TranslationStorage } from './translation';
|
|
3
|
+
export interface I18nDevtoolsInspectorNode {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
children?: I18nDevtoolsInspectorNode[];
|
|
7
|
+
tags?: Array<{
|
|
8
|
+
label: string;
|
|
9
|
+
textColor: number;
|
|
10
|
+
backgroundColor: number;
|
|
11
|
+
tooltip?: string;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
export interface I18nDevtoolsStateSnapshot {
|
|
15
|
+
locale: string;
|
|
16
|
+
routeName: string;
|
|
17
|
+
strategy?: string;
|
|
18
|
+
defaultLocale?: string;
|
|
19
|
+
fallbackLocale?: string;
|
|
20
|
+
cachedChunks: number;
|
|
21
|
+
locales: Array<{
|
|
22
|
+
code: string;
|
|
23
|
+
displayName?: string;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
27
|
+
export interface BuildInspectorTreeOptions {
|
|
28
|
+
nodeId: string;
|
|
29
|
+
storage: TranslationStorage;
|
|
30
|
+
configuredLocales: Locale[];
|
|
31
|
+
activeLocale: string;
|
|
32
|
+
activeRouteName: string;
|
|
33
|
+
activeTranslations?: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Encode path segments so a literal key `"a.b"` and nested path `a → b` get distinct node IDs.
|
|
37
|
+
*/
|
|
38
|
+
export declare function encodeInspectorPath(segments: string[]): string;
|
|
39
|
+
export declare function decodeInspectorPath(encoded: string): string[];
|
|
40
|
+
export declare function getByInspectorPath(obj: Record<string, unknown>, segments: string[]): unknown;
|
|
41
|
+
export declare function parseInspectorNodeId(nodeId: string): {
|
|
42
|
+
kind: 'root' | 'active' | 'locale' | 'chunk' | 'key';
|
|
43
|
+
locale?: string;
|
|
44
|
+
routeName?: string;
|
|
45
|
+
path?: string;
|
|
46
|
+
segments?: string[];
|
|
47
|
+
};
|
|
48
|
+
export declare function flattenTranslationNode(obj: Record<string, unknown>, parentSegments?: string[]): I18nDevtoolsInspectorNode[];
|
|
49
|
+
export declare function buildInspectorTree(options: BuildInspectorTreeOptions): I18nDevtoolsInspectorNode[];
|
|
50
|
+
export declare function buildInspectorState(snapshot: I18nDevtoolsStateSnapshot): Record<string, Array<{
|
|
51
|
+
key: string;
|
|
52
|
+
value: unknown;
|
|
53
|
+
editable?: boolean;
|
|
54
|
+
}>>;
|
|
55
|
+
export declare function countTranslationKeys(translations: Translations | Record<string, unknown> | undefined): number;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
const y = {
|
|
2
|
+
label: "Active",
|
|
3
|
+
textColor: 16777215,
|
|
4
|
+
backgroundColor: 4372611,
|
|
5
|
+
tooltip: "Current locale and route context"
|
|
6
|
+
}, b = "root", p = "active", g = "locale|", u = "chunk|", s = "key|", f = (e) => e !== null && typeof e == "object" && !Array.isArray(e);
|
|
7
|
+
function N(e) {
|
|
8
|
+
return typeof e == "string" ? JSON.stringify(e) : e === null ? "null" : e === void 0 ? "undefined" : typeof e == "object" ? Array.isArray(e) ? `[Array(${e.length})]` : "{…}" : String(e);
|
|
9
|
+
}
|
|
10
|
+
function m(e, t, n, o) {
|
|
11
|
+
return e === n && t === o ? [y] : void 0;
|
|
12
|
+
}
|
|
13
|
+
function h(e, t) {
|
|
14
|
+
const n = `${t}:`, o = /* @__PURE__ */ new Set();
|
|
15
|
+
for (const c of e.translations.keys())
|
|
16
|
+
c.startsWith(n) && o.add(c.slice(n.length) || "index");
|
|
17
|
+
return [...o].sort();
|
|
18
|
+
}
|
|
19
|
+
function C(e, t) {
|
|
20
|
+
const n = new Set(t.map((o) => o.code));
|
|
21
|
+
for (const o of e.translations.keys()) {
|
|
22
|
+
const c = o.split(":")[0];
|
|
23
|
+
c && n.add(c);
|
|
24
|
+
}
|
|
25
|
+
return [...n].sort();
|
|
26
|
+
}
|
|
27
|
+
function A(e) {
|
|
28
|
+
return e.map((t) => encodeURIComponent(t)).join("/");
|
|
29
|
+
}
|
|
30
|
+
function _(e) {
|
|
31
|
+
return e ? e.split("/").map((t) => decodeURIComponent(t)) : [];
|
|
32
|
+
}
|
|
33
|
+
function x(e, t) {
|
|
34
|
+
let n = e;
|
|
35
|
+
for (const o of t) {
|
|
36
|
+
if (!f(n) || !Object.prototype.hasOwnProperty.call(n, o)) return;
|
|
37
|
+
n = n[o];
|
|
38
|
+
}
|
|
39
|
+
return n;
|
|
40
|
+
}
|
|
41
|
+
function L(e) {
|
|
42
|
+
if (!e || e === b) return { kind: "root" };
|
|
43
|
+
if (e === p) return { kind: "active" };
|
|
44
|
+
if (e.startsWith(g))
|
|
45
|
+
return { kind: "locale", locale: e.slice(g.length) };
|
|
46
|
+
if (e.startsWith(u)) {
|
|
47
|
+
const [t = "", n = "index"] = e.slice(u.length).split("|");
|
|
48
|
+
return { kind: "chunk", locale: t, routeName: n };
|
|
49
|
+
}
|
|
50
|
+
if (e.startsWith(s)) {
|
|
51
|
+
const t = e.slice(s.length).split("|"), n = t[0] ?? "", o = t[1] ?? "index", c = t.slice(2).join("|");
|
|
52
|
+
return { kind: "key", locale: n, routeName: o, path: c, segments: _(c) };
|
|
53
|
+
}
|
|
54
|
+
return { kind: "root" };
|
|
55
|
+
}
|
|
56
|
+
function d(e, t, n) {
|
|
57
|
+
return {
|
|
58
|
+
...n,
|
|
59
|
+
id: `${s}${e}|${t}|${n.id.slice(s.length)}`
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function k(e, t = []) {
|
|
63
|
+
const n = t.length === 0 ? e : x(e, t);
|
|
64
|
+
return f(n) ? Object.keys(n).filter((o) => o !== "__proto__").map((o) => {
|
|
65
|
+
const c = [...t, o], r = n[o], a = f(r);
|
|
66
|
+
return {
|
|
67
|
+
id: `${s}${A(c)}`,
|
|
68
|
+
label: a ? o : `${o}: ${N(r)}`,
|
|
69
|
+
children: a ? [] : void 0
|
|
70
|
+
};
|
|
71
|
+
}).sort((o, c) => o.label.localeCompare(c.label)) : [];
|
|
72
|
+
}
|
|
73
|
+
function O(e) {
|
|
74
|
+
const t = L(e.nodeId), n = e.activeLocale, o = e.activeRouteName || "index";
|
|
75
|
+
if (t.kind === "root") {
|
|
76
|
+
const c = C(e.storage, e.configuredLocales), r = [
|
|
77
|
+
{
|
|
78
|
+
id: p,
|
|
79
|
+
label: `Active (${n}:${o})`,
|
|
80
|
+
tags: [y]
|
|
81
|
+
}
|
|
82
|
+
];
|
|
83
|
+
for (const a of c) {
|
|
84
|
+
const l = e.configuredLocales.find((i) => i.code === a), $ = h(e.storage, a);
|
|
85
|
+
r.push({
|
|
86
|
+
id: `${g}${a}`,
|
|
87
|
+
label: l?.displayName ? `${a} (${l.displayName})` : a,
|
|
88
|
+
tags: a === n ? [{ ...y, tooltip: "Active locale" }] : void 0
|
|
89
|
+
});
|
|
90
|
+
for (const i of $)
|
|
91
|
+
r.push({
|
|
92
|
+
id: `${u}${a}|${i}`,
|
|
93
|
+
label: `${a}:${i}`,
|
|
94
|
+
tags: m(a, i, n, o)
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return r;
|
|
98
|
+
}
|
|
99
|
+
if (t.kind === "active")
|
|
100
|
+
return k(e.activeTranslations ?? {}).map((c) => d(n, o, c));
|
|
101
|
+
if (t.kind === "locale" && t.locale) {
|
|
102
|
+
const c = t.locale;
|
|
103
|
+
return h(e.storage, c).map((r) => ({
|
|
104
|
+
id: `${u}${c}|${r}`,
|
|
105
|
+
label: r,
|
|
106
|
+
children: [],
|
|
107
|
+
tags: m(c, r, n, o)
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
if (t.kind === "chunk" && t.locale) {
|
|
111
|
+
const c = t.locale, r = t.routeName || "index", a = e.storage.translations.get(`${c}:${r}`);
|
|
112
|
+
return k(a ?? {}).map((l) => d(c, r, l));
|
|
113
|
+
}
|
|
114
|
+
if (t.kind === "key" && t.locale) {
|
|
115
|
+
const c = t.locale, r = t.routeName || "index", a = e.storage.translations.get(`${c}:${r}`), l = t.segments ?? [], i = n === c && o === r ? e.activeTranslations ?? a ?? {} : a ?? {};
|
|
116
|
+
return k(i, l).map((v) => d(c, r, v));
|
|
117
|
+
}
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
function T(e) {
|
|
121
|
+
return {
|
|
122
|
+
Context: [
|
|
123
|
+
{ key: "locale", value: e.locale },
|
|
124
|
+
{ key: "routeName", value: e.routeName },
|
|
125
|
+
{ key: "strategy", value: e.strategy ?? "—" },
|
|
126
|
+
{ key: "defaultLocale", value: e.defaultLocale ?? "—" },
|
|
127
|
+
{ key: "fallbackLocale", value: e.fallbackLocale ?? "—" },
|
|
128
|
+
{ key: "cachedChunks", value: e.cachedChunks }
|
|
129
|
+
],
|
|
130
|
+
Locales: e.locales.map((t) => ({
|
|
131
|
+
key: t.code,
|
|
132
|
+
value: t.displayName ?? t.code,
|
|
133
|
+
editable: !1
|
|
134
|
+
}))
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function E(e) {
|
|
138
|
+
if (!e || typeof e != "object") return 0;
|
|
139
|
+
const t = /* @__PURE__ */ new Set(), n = (o, c = "") => {
|
|
140
|
+
for (const r of Object.keys(o)) {
|
|
141
|
+
if (r === "__proto__") continue;
|
|
142
|
+
const a = c ? `${c}.${r}` : r;
|
|
143
|
+
t.add(a);
|
|
144
|
+
const l = o[r];
|
|
145
|
+
f(l) && n(l, a);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
return n(e), t.size;
|
|
149
|
+
}
|
|
150
|
+
export {
|
|
151
|
+
T as buildInspectorState,
|
|
152
|
+
O as buildInspectorTree,
|
|
153
|
+
E as countTranslationKeys,
|
|
154
|
+
_ as decodeInspectorPath,
|
|
155
|
+
A as encodeInspectorPath,
|
|
156
|
+
k as flattenTranslationNode,
|
|
157
|
+
x as getByInspectorPath,
|
|
158
|
+
L as parseInspectorNodeId
|
|
159
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@i18n-micro/core",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.13",
|
|
4
4
|
"description": "Core utilities for translations, formatting, and locale routing in Nuxt I18n Micro.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"formatting",
|
|
@@ -64,13 +64,28 @@
|
|
|
64
64
|
},
|
|
65
65
|
"default": "./dist/helpers.mjs"
|
|
66
66
|
},
|
|
67
|
+
"./devtools": {
|
|
68
|
+
"production": {
|
|
69
|
+
"types": "./dist/devtools.d.ts",
|
|
70
|
+
"default": "./dist/devtools.mjs"
|
|
71
|
+
},
|
|
72
|
+
"import": {
|
|
73
|
+
"types": "./dist/devtools.d.ts",
|
|
74
|
+
"default": "./dist/devtools.mjs"
|
|
75
|
+
},
|
|
76
|
+
"require": {
|
|
77
|
+
"types": "./dist/devtools.d.cts",
|
|
78
|
+
"default": "./dist/devtools.cjs"
|
|
79
|
+
},
|
|
80
|
+
"default": "./dist/devtools.mjs"
|
|
81
|
+
},
|
|
67
82
|
"./package.json": "./package.json"
|
|
68
83
|
},
|
|
69
84
|
"publishConfig": {
|
|
70
85
|
"access": "public"
|
|
71
86
|
},
|
|
72
87
|
"dependencies": {
|
|
73
|
-
"@i18n-micro/types": "^1.2.
|
|
88
|
+
"@i18n-micro/types": "^1.2.11"
|
|
74
89
|
},
|
|
75
90
|
"devDependencies": {
|
|
76
91
|
"publint": "^0.3.17",
|