vue-intlayer 9.6.0 → 9.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/devtools/editDictionaryContent.cjs +1 -0
- package/dist/cjs/devtools/editorServer.cjs +1 -0
- package/dist/cjs/devtools/formatDictionaryForInspector.cjs +1 -1
- package/dist/cjs/devtools/index.cjs +1 -1
- package/dist/cjs/editor/useEditor.cjs +1 -1
- package/dist/cjs/format/useCompact.cjs +1 -1
- package/dist/cjs/format/useCurrency.cjs +1 -1
- package/dist/cjs/format/useDate.cjs +1 -1
- package/dist/cjs/format/useIntl.cjs +1 -1
- package/dist/cjs/format/useList.cjs +1 -1
- package/dist/cjs/format/useNumber.cjs +1 -1
- package/dist/cjs/format/usePercentage.cjs +1 -1
- package/dist/cjs/format/useRelativeTime.cjs +1 -1
- package/dist/cjs/format/useUnit.cjs +1 -1
- package/dist/cjs/plugins.cjs +1 -1
- package/dist/esm/devtools/editDictionaryContent.mjs +29 -0
- package/dist/esm/devtools/editorServer.mjs +21 -0
- package/dist/esm/devtools/formatDictionaryForInspector.mjs +40 -18
- package/dist/esm/devtools/index.mjs +144 -45
- package/dist/esm/editor/useEditor.mjs +29 -26
- package/dist/esm/format/useCompact.mjs +2 -2
- package/dist/esm/format/useCurrency.mjs +2 -2
- package/dist/esm/format/useDate.mjs +2 -2
- package/dist/esm/format/useIntl.mjs +2 -2
- package/dist/esm/format/useList.mjs +2 -2
- package/dist/esm/format/useNumber.mjs +2 -2
- package/dist/esm/format/usePercentage.mjs +2 -2
- package/dist/esm/format/useRelativeTime.mjs +2 -2
- package/dist/esm/format/useUnit.mjs +2 -2
- package/dist/rolldown-runtime-BocRIvOZ.js +1 -0
- package/dist/types/devtools/editDictionaryContent.d.ts +47 -0
- package/dist/types/devtools/editorServer.d.ts +26 -0
- package/dist/types/devtools/formatDictionaryForInspector.d.ts +20 -0
- package/dist/types/devtools/index.d.ts +7 -0
- package/package.json +12 -12
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../rolldown-runtime-BocRIvOZ.js"),t=require("./formatDictionaryForInspector.cjs");let n=require("@intlayer/types/nodeType");n=e.t(n);let r=require("@intlayer/core/dictionaryManipulator");var i=e=>typeof e==`object`&&!!e&&!Array.isArray(e),a=(e,t)=>{let a=(0,r.getContentNodeByKeyPath)(e.content,t);return typeof a==`string`?`plain-string`:i(a)&&a.nodeType===n.TRANSLATION&&i(a[n.TRANSLATION])&&Object.values(a[n.TRANSLATION]).every(e=>typeof e==`string`)?`translation`:null},o=(e,t=`Translations`)=>{let[n,r,...i]=e[0]===t?e.slice(1):e;return!n||i.length>0?null:r?{label:n,locale:r}:{label:n}},s=(e,r)=>{let i=t.listInspectorEntries(e).find(({label:e})=>e===r.label);return i?r.locale?[...i.keyPath,{type:n.TRANSLATION,key:r.locale}]:i.keyPath:null},c=(e,t,n)=>{if(typeof(0,r.getContentNodeByKeyPath)(e.content,t)!=`string`)return null;let i=(0,r.editDictionaryByKeyPath)(structuredClone(e.content),t,n);return{...e,content:i}};exports.applyDictionaryEdit=c,exports.getEditKeyPath=s,exports.getEditability=a,exports.parseEditPath=o;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@intlayer/api/editor");var t=()=>{let t=(0,e.getEditorAPI)({credentials:`omit`}),n=!1;return{isOnline:()=>n,fetchUnmergedDictionaries:async()=>{try{let e=await t.getDictionaries();return n=!0,e}catch{return n=!1,null}},writeDictionary:async e=>{await t.writeDictionary({dictionary:e})}}};exports.createEditorServerSession=t;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../rolldown-runtime-BocRIvOZ.js");let t=require("@intlayer/types/nodeType");t=e.t(t);var n=`(root)`,r=e=>typeof e==`object`&&!!e&&!Array.isArray(e),i=e=>r(e)&&e.nodeType===t.TRANSLATION&&r(e.translation),a=e=>{if(typeof e==`string`)return e;try{return JSON.stringify(e)??String(e)}catch{return String(e)}},o=e=>e.length===0?n:e.map(({key:e})=>{let t=String(e);return t.includes(`.`)?JSON.stringify(t):t}).join(`.`),s=(e,n,c)=>{let l=o(n);if(i(e)){c.push({label:l,keyPath:n,value:e.translation});return}if(r(e)&&typeof e.nodeType==`string`){c.push({label:l,keyPath:n,value:a(e[e.nodeType])});return}if(Array.isArray(e)){e.forEach((e,r)=>{s(e,[...n,{type:t.ARRAY,key:r}],c)});return}if(r(e)){for(let[r,i]of Object.entries(e))s(i,[...n,{type:t.OBJECT,key:r}],c);return}n.length>0&&c.push({label:l,keyPath:n,value:a(e)})},c=e=>{let t=[];return s(e.content,[],t),t},l=e=>Object.fromEntries(c(e).map(({label:e,value:t})=>[e,t]));exports.ROOT_PATH=n,exports.formatDictionaryForInspector=l,exports.listInspectorEntries=c;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/useLocaleStorage.cjs"),t=require("../client/installIntlayer.cjs"),n=require("./formatDictionaryForInspector.cjs"),r=require("./buildLocalesInspectorNode.cjs");let
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/useLocaleStorage.cjs"),t=require("../client/installIntlayer.cjs"),n=require("./formatDictionaryForInspector.cjs"),r=require("./editDictionaryContent.cjs"),i=require("./editorServer.cjs"),a=require("./buildLocalesInspectorNode.cjs");let o=require("@intlayer/config/built"),s=require("vue"),c=require("@intlayer/dictionaries-entry"),l=require("@vue/devtools-api");var u=`intlayer`,d=`intlayer-dictionaries-inspector`,f=`intlayer-editor-offline`,{defaultLocale:p,locales:m}=o.internationalization??{},h=l.setupDevtoolsPlugin,g=e=>e.localId??e.key,_=(e,t)=>Object.values(e).flat().find(e=>g(e)===t),v=e=>e.locale??e.filePath?.split(`/`).pop()??`declaration`,y=o=>{h({id:u,label:`Intlayer`,packageName:`vue-intlayer`,homepage:`https://intlayer.org`,componentStateTypes:[u],app:o},o=>{let l=i.createEditorServerSession();l.fetchUnmergedDictionaries().then(e=>{e&&o.sendInspectorTree(d)}),o.addInspector({id:d,label:`Intlayer`,icon:`language`,treeFilterPlaceholder:`Search dictionaries`,nodeActions:[{icon:`check`,tooltip:`Set as current locale`,action:n=>{if(!a.isLocaleNodeId(n))return;let r=a.getLocaleFromNodeId(n);if(!m?.map(String).includes(r)){console.error(`Locale ${r} is not available`);return}let i=t.createIntlayerClient();i.setLocale(r),e.setLocaleInStorage(r,i.isCookieEnabled??!0),o.sendInspectorTree(d),o.sendInspectorState(d)}}]}),(0,s.watch)(()=>t.createIntlayerClient().locale.value,()=>{o.sendInspectorTree(d),o.sendInspectorState(d)}),o.on.getInspectorTree(async e=>{if(e.inspectorId!==`intlayer-dictionaries-inspector`)return;let n=t.createIntlayerClient().locale.value??p,r=await l.fetchUnmergedDictionaries();if(r){e.rootNodes=[...Object.entries(r).flatMap(([e,t])=>t.map(n=>({id:g(n),label:t.length>1?`${e} (${v(n)})`:e,tags:[{label:`editable`,textColor:16777215,backgroundColor:4372611}]}))),a.buildLocalesInspectorNode(n)];return}let i=(0,c.getDictionaries)(),o=Object.keys(i);e.rootNodes=[...o.length===0?[{id:`intlayer-no-dictionaries`,label:`No dictionaries loaded. Add an Intlayer build plugin (e.g. vite-intlayer) to generate them.`}]:o.map(e=>({id:e,label:e})),{id:f,label:`Enable live editing (editor server)`},a.buildLocalesInspectorNode(n)]}),o.on.getInspectorState(async e=>{if(e.inspectorId!==`intlayer-dictionaries-inspector`)return;let i=t.createIntlayerClient().locale.value??p;if(e.nodeId===`intlayer-locales`){e.state={Locales:(m??[]).map(e=>({key:e,value:e===i?`current`:``,editable:!1}))};return}if(a.isLocaleNodeId(e.nodeId)){let t=a.getLocaleFromNodeId(e.nodeId);e.state={Locale:[{key:`locale`,value:t,editable:!1},{key:`current`,value:t===i,editable:!1}]};return}if(e.nodeId===`intlayer-editor-offline`){e.state={"Live editing":[{key:`status`,value:`Intlayer editor server not detected`,editable:!1},{key:`enable it`,value:"Set `editor.enabled: true` in intlayer.config, run `npx intlayer editor start`, then reopen this panel",editable:!1},{key:`edits`,value:`Edits are written back to your .content source files`,editable:!1}]};return}let o=await l.fetchUnmergedDictionaries(),s=o?_(o,e.nodeId):void 0;if(s){e.state={Translations:n.listInspectorEntries(s).map(({label:e,keyPath:t,value:n})=>({key:e,value:n,editable:r.getEditability(s,t)!==null})),Metadata:[{key:`key`,value:s.key,editable:!1},{key:`title`,value:s.title??``,editable:!1},{key:`description`,value:s.description??``,editable:!1},{key:`file`,value:s.filePath??``,editable:!1}]};return}let u=(0,c.getDictionaries)()[e.nodeId];if(!u){e.state={};return}let d=n.formatDictionaryForInspector(u);e.state={Translations:Object.entries(d).map(([e,t])=>({key:e,value:t,editable:!1})),Metadata:[{key:`key`,value:u.key,editable:!1},{key:`title`,value:u.title??``,editable:!1},{key:`description`,value:u.description??``,editable:!1}]}});let u=Promise.resolve();o.on.editInspectorState(e=>{if(e.inspectorId!==`intlayer-dictionaries-inspector`||e.state.remove)return;let t=r.parseEditPath(e.path),n=e.state.value;if(t&&typeof n==`string`)return u=u.catch(()=>{}).then(async()=>{let i=await l.fetchUnmergedDictionaries();if(!i)return;let a=_(i,e.nodeId);if(!a)return;let s=r.getEditKeyPath(a,t);if(!s)return;let c=r.applyDictionaryEdit(a,s,n);if(c)try{await l.writeDictionary(c)}catch(e){console.error(`[intlayer] Failed to save the dictionary through the editor server:`,e)}finally{o.sendInspectorState(d)}}),u})})};exports.EDITOR_OFFLINE_NODE_ID=f,exports.INTLAYER_DEVTOOLS_PLUGIN_ID=u,exports.INTLAYER_DICTIONARIES_INSPECTOR_ID=d,exports.enableIntlayerDevtools=y;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/installIntlayer.cjs");let
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/useLocaleStorage.cjs"),t=require("../client/installIntlayer.cjs");let n=require("vue"),r=require("@intlayer/editor/isEnabled");var i=t=>{let r=t?.locale,i=null,a=null,o=!1;return import(`@intlayer/editor`).then(({initEditorClient:s})=>{if(o)return;let c=s();r&&(i=(0,n.watchEffect)(()=>{let e=r.value;e&&c.currentLocale.set(e)})),a=c.onLocaleChangeRequested(n=>{t?.setLocale(n),e.setLocaleInStorage(n,!0)})}).catch(()=>{}),()=>{o=!0,i?.(),a?.(),import(`@intlayer/editor`).then(({stopEditorClient:e})=>{e()}).catch(()=>{})}},a=e=>{if(process.env.INTLAYER_EDITOR_ENABLED===`false`||!r.isEnabled)return;if(e){let n=null;e.mixin({inject:{_intlayerClient:{from:t.INTLAYER_SYMBOL,default:null}},mounted(){if(this.$parent!==null)return;let e=this._intlayerClient;n=i(e)},unmounted(){this.$parent===null&&n?.()}});return}let a=(0,n.inject)(t.INTLAYER_SYMBOL),o=null;(0,n.onMounted)(()=>{o=i(a)}),(0,n.onUnmounted)(()=>{o?.()})};exports.useEditor=a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/installIntlayer.cjs");let t=require("vue"),n=require("@intlayer/core/formatters");var r=()=>{let r=(0,t.inject)(e.INTLAYER_SYMBOL);return(0,t.computed)(()=>{let e=r
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/installIntlayer.cjs");let t=require("vue"),n=require("@intlayer/core/formatters");var r=()=>{let r=(0,t.inject)(e.INTLAYER_SYMBOL,null);return(0,t.computed)(()=>{let e=r?.locale.value;return(...t)=>(0,n.compact)(t[0],{...t[1],locale:t[1]?.locale??e})})};exports.useCompact=r;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/installIntlayer.cjs");let t=require("vue"),n=require("@intlayer/core/formatters");var r=()=>{let r=(0,t.inject)(e.INTLAYER_SYMBOL);return(0,t.computed)(()=>{let e=r
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/installIntlayer.cjs");let t=require("vue"),n=require("@intlayer/core/formatters");var r=()=>{let r=(0,t.inject)(e.INTLAYER_SYMBOL,null);return(0,t.computed)(()=>{let e=r?.locale.value;return(...t)=>(0,n.currency)(t[0],{...t[1],locale:t[1]?.locale??e})})};exports.useCurrency=r;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/installIntlayer.cjs");let t=require("vue"),n=require("@intlayer/core/formatters");var r=()=>{let r=(0,t.inject)(e.INTLAYER_SYMBOL);return(0,t.computed)(()=>{let e=r
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/installIntlayer.cjs");let t=require("vue"),n=require("@intlayer/core/formatters");var r=()=>{let r=(0,t.inject)(e.INTLAYER_SYMBOL,null);return(0,t.computed)(()=>{let e=r?.locale.value;return(...t)=>{let r=typeof t[1]==`string`?{...n.presets[t[1]],locale:e}:{...t[1],locale:t[1]?.locale??e};return(0,n.date)(t[0],r)}})};exports.useDate=r;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/installIntlayer.cjs");let t=require("vue"),n=require("@intlayer/core/utils");var r=r=>{let i=(0,t.inject)(e.INTLAYER_SYMBOL);return(0,t.computed)(()=>{let e=r??i
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/installIntlayer.cjs");let t=require("vue"),n=require("@intlayer/core/utils");var r=r=>{let i=(0,t.inject)(e.INTLAYER_SYMBOL,null);return(0,t.computed)(()=>{let e=r??i?.locale.value;return(0,n.bindIntl)(e)})};exports.useIntl=r;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/installIntlayer.cjs");let t=require("vue"),n=require("@intlayer/core/formatters");var r=()=>{let r=(0,t.inject)(e.INTLAYER_SYMBOL);return(0,t.computed)(()=>{let e=r
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/installIntlayer.cjs");let t=require("vue"),n=require("@intlayer/core/formatters");var r=()=>{let r=(0,t.inject)(e.INTLAYER_SYMBOL,null);return(0,t.computed)(()=>{let e=r?.locale.value;return(...t)=>(0,n.list)(t[0],{...t[1],locale:t[1]?.locale??e})})};exports.useList=r;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/installIntlayer.cjs");let t=require("vue"),n=require("@intlayer/core/formatters");var r=()=>{let r=(0,t.inject)(e.INTLAYER_SYMBOL);return(0,t.computed)(()=>{let e=r
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/installIntlayer.cjs");let t=require("vue"),n=require("@intlayer/core/formatters");var r=()=>{let r=(0,t.inject)(e.INTLAYER_SYMBOL,null);return(0,t.computed)(()=>{let e=r?.locale.value;return(...t)=>(0,n.number)(t[0],{...t[1],locale:t[1]?.locale??e})})};exports.useNumber=r;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/installIntlayer.cjs");let t=require("vue"),n=require("@intlayer/core/formatters");var r=()=>{let r=(0,t.inject)(e.INTLAYER_SYMBOL);return(0,t.computed)(()=>{let e=r
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/installIntlayer.cjs");let t=require("vue"),n=require("@intlayer/core/formatters");var r=()=>{let r=(0,t.inject)(e.INTLAYER_SYMBOL,null);return(0,t.computed)(()=>{let e=r?.locale.value;return(...t)=>(0,n.percentage)(t[0],{...t[1],locale:t[1]?.locale??e})})};exports.usePercentage=r;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/installIntlayer.cjs");let t=require("vue"),n=require("@intlayer/core/formatters");var r=()=>{let r=(0,t.inject)(e.INTLAYER_SYMBOL);return(0,t.computed)(()=>{let e=r
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/installIntlayer.cjs");let t=require("vue"),n=require("@intlayer/core/formatters");var r=()=>{let r=(0,t.inject)(e.INTLAYER_SYMBOL,null);return(0,t.computed)(()=>{let e=r?.locale.value;return(...t)=>(0,n.relativeTime)(t[0],t[1],{...t[2],locale:t[2]?.locale??e})})};exports.useRelativeTime=r;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/installIntlayer.cjs");let t=require("vue"),n=require("@intlayer/core/formatters");var r=()=>{let r=(0,t.inject)(e.INTLAYER_SYMBOL);return(0,t.computed)(()=>{let e=r
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../client/installIntlayer.cjs");let t=require("vue"),n=require("@intlayer/core/formatters");var r=()=>{let r=(0,t.inject)(e.INTLAYER_SYMBOL,null);return(0,t.computed)(()=>{let e=r?.locale.value;return(...t)=>(0,n.units)(t[0],{...t[1],locale:t[1]?.locale??e})})};exports.useUnit=r;
|
package/dist/cjs/plugins.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../rolldown-runtime-BocRIvOZ.js"),t=require("./analytics/exposureSink.cjs"),n=require("./html/HTMLRenderer.cjs"),r=require("./markdown/installIntlayerMarkdown.cjs"),i=require("./renderIntlayerNode.cjs");let a=require("@intlayer/core/interpreter"),o=require("@intlayer/config/built"),s=require("@intlayer/core/markdown"),c=require("@intlayer/types/nodeType");c=e.t(c);let l=require("vue");var u=process.env.INTLAYER_EDITOR_ENABLED===`false`?null:(0,l.defineAsyncComponent)(()=>Promise.resolve().then(()=>require("./editor/ContentSelector.cjs"))),d={id:`intlayer-node-plugin`,canHandle:e=>typeof e==`bigint`||typeof e==`string`||typeof e==`number`,transform:(e,n)=>{let{children:r,dictionaryKey:a,keyPath:s}=n;process.env.INTLAYER_ANALYTICS_ENABLED!==`false`&&t.reportExposure({dictionaryKey:a,keyPath:s,locale:n.locale,nodeType:`text`});let c=e=>i.renderIntlayerNode({value:e,children:process.env.INTLAYER_EDITOR_ENABLED!==`false`&&o.editor.enabled?()=>(0,l.h)(u,{dictionaryKey:a,keyPath:s},{default:()=>typeof e==`function`?e():e}):e}),d=c(r);if(typeof r!=`function`)return d;let f=(...e)=>{let t=r(...e);return c(t)};Object.setPrototypeOf(f,Object.getPrototypeOf(d));for(let e of Object.getOwnPropertyNames(d)){let t=Object.getOwnPropertyDescriptor(d,e);t&&Object.defineProperty(f,e,t)}for(let e of Object.getOwnPropertySymbols(d)){let t=Object.getOwnPropertyDescriptor(d,e);t&&Object.defineProperty(f,e,t)}return(0,l.markRaw)(f)}},f=(e,t)=>{let n=new Map,r={};for(let[e,i]of Object.entries(t))typeof i==`string`||typeof i==`number`?r[e]=i:(n.set(e,i),r[e]=`__VNODE_${e}__`);let i=(0,a.splitInsertionTemplate)(e,r);if(n.size>0){let e=[];if(i.isSimple){let t=i.parts,r=0;for(let[i]of n){let a=`__VNODE_${i}__`,o=t.indexOf(a);o!==-1&&(o>r&&e.push(t.substring(r,o)),e.push(n.get(i)),r=o+a.length)}return r<t.length&&e.push(t.substring(r)),(0,l.h)(l.Fragment,null,...e)}return i.parts.forEach(t=>{if(typeof t==`string`){let r=t;for(let[t]of n){let i=`__VNODE_${t}__`,a=r.indexOf(i);a!==-1&&(a>0&&e.push(r.substring(0,a)),e.push(n.get(t)),r=r.substring(a+i.length))}r.length>0&&e.push(r)}else e.push(t)}),(0,l.h)(l.Fragment,null,...e)}return i.isSimple?i.parts:(0,l.h)(l.Fragment,null,i.parts)},p=process.env.INTLAYER_NODE_TYPE_INSERTION===`false`?a.fallbackPlugin:{id:`insertion-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===c.INSERTION,transform:(e,t,n)=>{let r=[...t.keyPath,{type:c.INSERTION}],i=e[c.INSERTION],o={id:`insertion-string-plugin`,canHandle:e=>typeof e==`string`||(0,a.isInterpolableWrapperNode)(e),transform:(e,n,r)=>{if((0,a.isInterpolableWrapperNode)(e))return i=>(0,a.transformInterpolableNode)(e,i,n,t.plugins,r);let i=r(e,{...n,children:e,plugins:[...(t.plugins??[]).filter(e=>e.id!==`intlayer-node-plugin`)]});return e=>{let a=f(i,e);return r(a,{...n,plugins:t.plugins,children:a})}}},s=n(i,{...t,children:i,keyPath:r,plugins:[o,...t.plugins??[]]});return(0,a.resolveInsertedSelector)(i,s)}},m=process.env.INTLAYER_NODE_TYPE_MARKDOWN===`false`?a.fallbackPlugin:{id:`markdown-string-plugin`,canHandle:e=>typeof e==`string`,transform:(e,t,n)=>{let{plugins:a,...c}=t,d=n((0,s.getMarkdownMetadata)(e)??{},{plugins:[{id:`markdown-metadata-plugin`,canHandle:e=>typeof e==`string`||typeof e==`number`||typeof e==`boolean`||!e,transform:(t,n)=>i.renderIntlayerNode({...n,value:t,children:e})}],dictionaryKey:c.dictionaryKey,keyPath:[]}),f=n=>i.renderIntlayerNode({...t,value:e,children:()=>{let{renderMarkdown:t,components:i}=r.useMarkdown(),a=t(e,void 0,{...i??{},...n??{}});return process.env.INTLAYER_EDITOR_ENABLED!==`false`&&o.editor.enabled?(0,l.h)(u,{dictionaryKey:c.dictionaryKey,keyPath:c.keyPath},{default:()=>a}):a},additionalProps:{metadata:d,use:e=>f(e)}});return f()}},h=process.env.INTLAYER_NODE_TYPE_MARKDOWN===`false`?a.fallbackPlugin:{id:`markdown-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===c.MARKDOWN,transform:(e,t,n)=>{let r=[...t.keyPath,{type:c.MARKDOWN}],i=e[c.MARKDOWN];return n(i,{...t,children:i,keyPath:r,plugins:[m,...t.plugins??[]]})}},g=process.env.INTLAYER_NODE_TYPE_HTML===`false`?a.fallbackPlugin:{id:`html-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===c.HTML,transform:(e,t)=>{let r=e[c.HTML];e.tags;let a=(e={})=>{let s=n.renderHTML(r,{components:e});return i.renderIntlayerNode({...t,value:r,children:process.env.INTLAYER_EDITOR_ENABLED!==`false`&&o.editor.enabled?()=>(0,l.h)(u,{dictionaryKey:t.dictionaryKey,keyPath:t.keyPath,...e},{default:()=>s}):s,additionalProps:{use:e=>a(e)}})};return a()}},_=new Map,v=(e,t=!0)=>{let n=(0,a.resolveInterpreterLocale)(e),r=`${n}_${t}`;if(_.has(r))return _.get(r);let i=[d,(0,a.translationPlugin)(n,t?o.internationalization.defaultLocale:void 0),a.enumerationPlugin,(0,a.pluralPlugin)(n),a.conditionPlugin,(0,a.nestedPlugin)(n),a.filePlugin,a.genderPlugin,a.selectPlugin,p,h,g].filter(e=>e!==a.fallbackPlugin);return _.set(r,i),i};exports.getPlugins=v,exports.htmlPlugin=g,exports.insertionPlugin=p,exports.intlayerNodePlugins=d,exports.markdownPlugin=h,exports.markdownStringPlugin=m;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { listInspectorEntries as e } from "./formatDictionaryForInspector.mjs";
|
|
2
|
+
import * as t from "@intlayer/types/nodeType";
|
|
3
|
+
import { editDictionaryByKeyPath as n, getContentNodeByKeyPath as r } from "@intlayer/core/dictionaryManipulator";
|
|
4
|
+
//#region src/devtools/editDictionaryContent.ts
|
|
5
|
+
var i = (e) => typeof e == "object" && !!e && !Array.isArray(e), a = (e, n) => {
|
|
6
|
+
let a = r(e.content, n);
|
|
7
|
+
return typeof a == "string" ? "plain-string" : i(a) && a.nodeType === t.TRANSLATION && i(a[t.TRANSLATION]) && Object.values(a[t.TRANSLATION]).every((e) => typeof e == "string") ? "translation" : null;
|
|
8
|
+
}, o = (e, t = "Translations") => {
|
|
9
|
+
let [n, r, ...i] = e[0] === t ? e.slice(1) : e;
|
|
10
|
+
return !n || i.length > 0 ? null : r ? {
|
|
11
|
+
label: n,
|
|
12
|
+
locale: r
|
|
13
|
+
} : { label: n };
|
|
14
|
+
}, s = (n, r) => {
|
|
15
|
+
let i = e(n).find(({ label: e }) => e === r.label);
|
|
16
|
+
return i ? r.locale ? [...i.keyPath, {
|
|
17
|
+
type: t.TRANSLATION,
|
|
18
|
+
key: r.locale
|
|
19
|
+
}] : i.keyPath : null;
|
|
20
|
+
}, c = (e, t, i) => {
|
|
21
|
+
if (typeof r(e.content, t) != "string") return null;
|
|
22
|
+
let a = n(structuredClone(e.content), t, i);
|
|
23
|
+
return {
|
|
24
|
+
...e,
|
|
25
|
+
content: a
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
29
|
+
export { c as applyDictionaryEdit, s as getEditKeyPath, a as getEditability, o as parseEditPath };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getEditorAPI as e } from "@intlayer/api/editor";
|
|
2
|
+
//#region src/devtools/editorServer.ts
|
|
3
|
+
var t = () => {
|
|
4
|
+
let t = e({ credentials: "omit" }), n = !1;
|
|
5
|
+
return {
|
|
6
|
+
isOnline: () => n,
|
|
7
|
+
fetchUnmergedDictionaries: async () => {
|
|
8
|
+
try {
|
|
9
|
+
let e = await t.getDictionaries();
|
|
10
|
+
return n = !0, e;
|
|
11
|
+
} catch {
|
|
12
|
+
return n = !1, null;
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
writeDictionary: async (e) => {
|
|
16
|
+
await t.writeDictionary({ dictionary: e });
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { t as createEditorServerSession };
|
|
@@ -1,35 +1,57 @@
|
|
|
1
|
+
import * as e from "@intlayer/types/nodeType";
|
|
1
2
|
//#region src/devtools/formatDictionaryForInspector.ts
|
|
2
|
-
var
|
|
3
|
+
var t = "(root)", n = (e) => typeof e == "object" && !!e && !Array.isArray(e), r = (t) => n(t) && t.nodeType === e.TRANSLATION && n(t.translation), i = (e) => {
|
|
3
4
|
if (typeof e == "string") return e;
|
|
4
5
|
try {
|
|
5
6
|
return JSON.stringify(e) ?? String(e);
|
|
6
7
|
} catch {
|
|
7
8
|
return String(e);
|
|
8
9
|
}
|
|
9
|
-
},
|
|
10
|
-
let
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
}, a = (e) => e.length === 0 ? t : e.map(({ key: e }) => {
|
|
11
|
+
let t = String(e);
|
|
12
|
+
return t.includes(".") ? JSON.stringify(t) : t;
|
|
13
|
+
}).join("."), o = (t, s, c) => {
|
|
14
|
+
let l = a(s);
|
|
15
|
+
if (r(t)) {
|
|
16
|
+
c.push({
|
|
17
|
+
label: l,
|
|
18
|
+
keyPath: s,
|
|
19
|
+
value: t.translation
|
|
20
|
+
});
|
|
13
21
|
return;
|
|
14
22
|
}
|
|
15
|
-
if (
|
|
16
|
-
|
|
23
|
+
if (n(t) && typeof t.nodeType == "string") {
|
|
24
|
+
c.push({
|
|
25
|
+
label: l,
|
|
26
|
+
keyPath: s,
|
|
27
|
+
value: i(t[t.nodeType])
|
|
28
|
+
});
|
|
17
29
|
return;
|
|
18
30
|
}
|
|
19
|
-
if (Array.isArray(
|
|
20
|
-
|
|
21
|
-
|
|
31
|
+
if (Array.isArray(t)) {
|
|
32
|
+
t.forEach((t, n) => {
|
|
33
|
+
o(t, [...s, {
|
|
34
|
+
type: e.ARRAY,
|
|
35
|
+
key: n
|
|
36
|
+
}], c);
|
|
22
37
|
});
|
|
23
38
|
return;
|
|
24
39
|
}
|
|
25
|
-
if (
|
|
26
|
-
for (let [
|
|
40
|
+
if (n(t)) {
|
|
41
|
+
for (let [n, r] of Object.entries(t)) o(r, [...s, {
|
|
42
|
+
type: e.OBJECT,
|
|
43
|
+
key: n
|
|
44
|
+
}], c);
|
|
27
45
|
return;
|
|
28
46
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
47
|
+
s.length > 0 && c.push({
|
|
48
|
+
label: l,
|
|
49
|
+
keyPath: s,
|
|
50
|
+
value: i(t)
|
|
51
|
+
});
|
|
52
|
+
}, s = (e) => {
|
|
53
|
+
let t = [];
|
|
54
|
+
return o(e.content, [], t), t;
|
|
55
|
+
}, c = (e) => Object.fromEntries(s(e).map(({ label: e, value: t }) => [e, t]));
|
|
34
56
|
//#endregion
|
|
35
|
-
export {
|
|
57
|
+
export { t as ROOT_PATH, c as formatDictionaryForInspector, s as listInspectorEntries };
|
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
import { setLocaleInStorage as e } from "../client/useLocaleStorage.mjs";
|
|
2
2
|
import { createIntlayerClient as t } from "../client/installIntlayer.mjs";
|
|
3
|
-
import { formatDictionaryForInspector as n } from "./formatDictionaryForInspector.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
3
|
+
import { formatDictionaryForInspector as n, listInspectorEntries as r } from "./formatDictionaryForInspector.mjs";
|
|
4
|
+
import { applyDictionaryEdit as i, getEditKeyPath as a, getEditability as o, parseEditPath as s } from "./editDictionaryContent.mjs";
|
|
5
|
+
import { createEditorServerSession as c } from "./editorServer.mjs";
|
|
6
|
+
import { buildLocalesInspectorNode as l, getLocaleFromNodeId as u, isLocaleNodeId as d } from "./buildLocalesInspectorNode.mjs";
|
|
7
|
+
import { internationalization as f } from "@intlayer/config/built";
|
|
8
|
+
import { watch as p } from "vue";
|
|
9
|
+
import { getDictionaries as m } from "@intlayer/dictionaries-entry";
|
|
10
|
+
import { setupDevtoolsPlugin as h } from "@vue/devtools-api";
|
|
9
11
|
//#region src/devtools/index.ts
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
id:
|
|
12
|
+
var g = "intlayer", _ = "intlayer-dictionaries-inspector", v = "intlayer-editor-offline", { defaultLocale: y, locales: b } = f ?? {}, x = h, S = (e) => e.localId ?? e.key, C = (e, t) => Object.values(e).flat().find((e) => S(e) === t), w = (e) => e.locale ?? e.filePath?.split("/").pop() ?? "declaration", T = (f) => {
|
|
13
|
+
x({
|
|
14
|
+
id: g,
|
|
13
15
|
label: "Intlayer",
|
|
14
16
|
packageName: "vue-intlayer",
|
|
15
17
|
homepage: "https://intlayer.org",
|
|
16
|
-
componentStateTypes: [
|
|
17
|
-
app:
|
|
18
|
-
}, (
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
componentStateTypes: [g],
|
|
19
|
+
app: f
|
|
20
|
+
}, (f) => {
|
|
21
|
+
let h = c();
|
|
22
|
+
h.fetchUnmergedDictionaries().then((e) => {
|
|
23
|
+
e && f.sendInspectorTree(_);
|
|
24
|
+
}), f.addInspector({
|
|
25
|
+
id: _,
|
|
21
26
|
label: "Intlayer",
|
|
22
27
|
icon: "language",
|
|
23
28
|
treeFilterPlaceholder: "Search dictionaries",
|
|
@@ -25,60 +30,133 @@ var u = "intlayer", d = "intlayer-dictionaries-inspector", { defaultLocale: f, l
|
|
|
25
30
|
icon: "check",
|
|
26
31
|
tooltip: "Set as current locale",
|
|
27
32
|
action: (n) => {
|
|
28
|
-
if (!
|
|
29
|
-
let r =
|
|
30
|
-
if (!
|
|
33
|
+
if (!d(n)) return;
|
|
34
|
+
let r = u(n);
|
|
35
|
+
if (!b?.map(String).includes(r)) {
|
|
31
36
|
console.error(`Locale ${r} is not available`);
|
|
32
37
|
return;
|
|
33
38
|
}
|
|
34
|
-
let
|
|
35
|
-
|
|
39
|
+
let i = t();
|
|
40
|
+
i.setLocale(r), e(r, i.isCookieEnabled ?? !0), f.sendInspectorTree(_), f.sendInspectorState(_);
|
|
36
41
|
}
|
|
37
42
|
}]
|
|
38
|
-
}),
|
|
39
|
-
|
|
40
|
-
}),
|
|
43
|
+
}), p(() => t().locale.value, () => {
|
|
44
|
+
f.sendInspectorTree(_), f.sendInspectorState(_);
|
|
45
|
+
}), f.on.getInspectorTree(async (e) => {
|
|
41
46
|
if (e.inspectorId !== "intlayer-dictionaries-inspector") return;
|
|
42
|
-
let n =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
let n = t().locale.value ?? y, r = await h.fetchUnmergedDictionaries();
|
|
48
|
+
if (r) {
|
|
49
|
+
e.rootNodes = [...Object.entries(r).flatMap(([e, t]) => t.map((n) => ({
|
|
50
|
+
id: S(n),
|
|
51
|
+
label: t.length > 1 ? `${e} (${w(n)})` : e,
|
|
52
|
+
tags: [{
|
|
53
|
+
label: "editable",
|
|
54
|
+
textColor: 16777215,
|
|
55
|
+
backgroundColor: 4372611
|
|
56
|
+
}]
|
|
57
|
+
}))), l(n)];
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
let i = m(), a = Object.keys(i);
|
|
61
|
+
e.rootNodes = [
|
|
62
|
+
...a.length === 0 ? [{
|
|
63
|
+
id: "intlayer-no-dictionaries",
|
|
64
|
+
label: "No dictionaries loaded. Add an Intlayer build plugin (e.g. vite-intlayer) to generate them."
|
|
65
|
+
}] : a.map((e) => ({
|
|
66
|
+
id: e,
|
|
67
|
+
label: e
|
|
68
|
+
})),
|
|
69
|
+
{
|
|
70
|
+
id: v,
|
|
71
|
+
label: "Enable live editing (editor server)"
|
|
72
|
+
},
|
|
73
|
+
l(n)
|
|
74
|
+
];
|
|
75
|
+
}), f.on.getInspectorState(async (e) => {
|
|
51
76
|
if (e.inspectorId !== "intlayer-dictionaries-inspector") return;
|
|
52
|
-
let
|
|
77
|
+
let i = t().locale.value ?? y;
|
|
53
78
|
if (e.nodeId === "intlayer-locales") {
|
|
54
|
-
e.state = { Locales: (
|
|
79
|
+
e.state = { Locales: (b ?? []).map((e) => ({
|
|
55
80
|
key: e,
|
|
56
|
-
value: e ===
|
|
81
|
+
value: e === i ? "current" : "",
|
|
57
82
|
editable: !1
|
|
58
83
|
})) };
|
|
59
84
|
return;
|
|
60
85
|
}
|
|
61
|
-
if (
|
|
62
|
-
let t =
|
|
86
|
+
if (d(e.nodeId)) {
|
|
87
|
+
let t = u(e.nodeId);
|
|
63
88
|
e.state = { Locale: [{
|
|
64
89
|
key: "locale",
|
|
65
90
|
value: t,
|
|
66
91
|
editable: !1
|
|
67
92
|
}, {
|
|
68
93
|
key: "current",
|
|
69
|
-
value: t ===
|
|
94
|
+
value: t === i,
|
|
70
95
|
editable: !1
|
|
71
96
|
}] };
|
|
72
97
|
return;
|
|
73
98
|
}
|
|
74
|
-
|
|
75
|
-
|
|
99
|
+
if (e.nodeId === "intlayer-editor-offline") {
|
|
100
|
+
e.state = { "Live editing": [
|
|
101
|
+
{
|
|
102
|
+
key: "status",
|
|
103
|
+
value: "Intlayer editor server not detected",
|
|
104
|
+
editable: !1
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
key: "enable it",
|
|
108
|
+
value: "Set `editor.enabled: true` in intlayer.config, run `npx intlayer editor start`, then reopen this panel",
|
|
109
|
+
editable: !1
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
key: "edits",
|
|
113
|
+
value: "Edits are written back to your .content source files",
|
|
114
|
+
editable: !1
|
|
115
|
+
}
|
|
116
|
+
] };
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
let a = await h.fetchUnmergedDictionaries(), s = a ? C(a, e.nodeId) : void 0;
|
|
120
|
+
if (s) {
|
|
121
|
+
e.state = {
|
|
122
|
+
Translations: r(s).map(({ label: e, keyPath: t, value: n }) => ({
|
|
123
|
+
key: e,
|
|
124
|
+
value: n,
|
|
125
|
+
editable: o(s, t) !== null
|
|
126
|
+
})),
|
|
127
|
+
Metadata: [
|
|
128
|
+
{
|
|
129
|
+
key: "key",
|
|
130
|
+
value: s.key,
|
|
131
|
+
editable: !1
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
key: "title",
|
|
135
|
+
value: s.title ?? "",
|
|
136
|
+
editable: !1
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
key: "description",
|
|
140
|
+
value: s.description ?? "",
|
|
141
|
+
editable: !1
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
key: "file",
|
|
145
|
+
value: s.filePath ?? "",
|
|
146
|
+
editable: !1
|
|
147
|
+
}
|
|
148
|
+
]
|
|
149
|
+
};
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
let c = m()[e.nodeId];
|
|
153
|
+
if (!c) {
|
|
76
154
|
e.state = {};
|
|
77
155
|
return;
|
|
78
156
|
}
|
|
79
|
-
let
|
|
157
|
+
let l = n(c);
|
|
80
158
|
e.state = {
|
|
81
|
-
Translations: Object.entries(
|
|
159
|
+
Translations: Object.entries(l).map(([e, t]) => ({
|
|
82
160
|
key: e,
|
|
83
161
|
value: t,
|
|
84
162
|
editable: !1
|
|
@@ -86,23 +164,44 @@ var u = "intlayer", d = "intlayer-dictionaries-inspector", { defaultLocale: f, l
|
|
|
86
164
|
Metadata: [
|
|
87
165
|
{
|
|
88
166
|
key: "key",
|
|
89
|
-
value:
|
|
167
|
+
value: c.key,
|
|
90
168
|
editable: !1
|
|
91
169
|
},
|
|
92
170
|
{
|
|
93
171
|
key: "title",
|
|
94
|
-
value:
|
|
172
|
+
value: c.title ?? "",
|
|
95
173
|
editable: !1
|
|
96
174
|
},
|
|
97
175
|
{
|
|
98
176
|
key: "description",
|
|
99
|
-
value:
|
|
177
|
+
value: c.description ?? "",
|
|
100
178
|
editable: !1
|
|
101
179
|
}
|
|
102
180
|
]
|
|
103
181
|
};
|
|
104
182
|
});
|
|
183
|
+
let g = Promise.resolve();
|
|
184
|
+
f.on.editInspectorState((e) => {
|
|
185
|
+
if (e.inspectorId !== "intlayer-dictionaries-inspector" || e.state.remove) return;
|
|
186
|
+
let t = s(e.path), n = e.state.value;
|
|
187
|
+
if (t && typeof n == "string") return g = g.catch(() => {}).then(async () => {
|
|
188
|
+
let r = await h.fetchUnmergedDictionaries();
|
|
189
|
+
if (!r) return;
|
|
190
|
+
let o = C(r, e.nodeId);
|
|
191
|
+
if (!o) return;
|
|
192
|
+
let s = a(o, t);
|
|
193
|
+
if (!s) return;
|
|
194
|
+
let c = i(o, s, n);
|
|
195
|
+
if (c) try {
|
|
196
|
+
await h.writeDictionary(c);
|
|
197
|
+
} catch (e) {
|
|
198
|
+
console.error("[intlayer] Failed to save the dictionary through the editor server:", e);
|
|
199
|
+
} finally {
|
|
200
|
+
f.sendInspectorState(_);
|
|
201
|
+
}
|
|
202
|
+
}), g;
|
|
203
|
+
});
|
|
105
204
|
});
|
|
106
205
|
};
|
|
107
206
|
//#endregion
|
|
108
|
-
export {
|
|
207
|
+
export { v as EDITOR_OFFLINE_NODE_ID, g as INTLAYER_DEVTOOLS_PLUGIN_ID, _ as INTLAYER_DICTIONARIES_INSPECTOR_ID, T as enableIntlayerDevtools };
|
|
@@ -1,47 +1,50 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { setLocaleInStorage as e } from "../client/useLocaleStorage.mjs";
|
|
2
|
+
import { INTLAYER_SYMBOL as t } from "../client/installIntlayer.mjs";
|
|
3
|
+
import { inject as n, onMounted as r, onUnmounted as i, watchEffect as a } from "vue";
|
|
4
|
+
import { isEnabled as o } from "@intlayer/editor/isEnabled";
|
|
4
5
|
//#region src/editor/useEditor.ts
|
|
5
|
-
var
|
|
6
|
-
let t = null,
|
|
7
|
-
return import("@intlayer/editor").then(({ initEditorClient:
|
|
8
|
-
if (
|
|
9
|
-
let
|
|
10
|
-
|
|
11
|
-
let
|
|
12
|
-
|
|
13
|
-
}))
|
|
6
|
+
var s = (t) => {
|
|
7
|
+
let n = t?.locale, r = null, i = null, o = !1;
|
|
8
|
+
return import("@intlayer/editor").then(({ initEditorClient: s }) => {
|
|
9
|
+
if (o) return;
|
|
10
|
+
let c = s();
|
|
11
|
+
n && (r = a(() => {
|
|
12
|
+
let e = n.value;
|
|
13
|
+
e && c.currentLocale.set(e);
|
|
14
|
+
})), i = c.onLocaleChangeRequested((n) => {
|
|
15
|
+
t?.setLocale(n), e(n, !0);
|
|
16
|
+
});
|
|
14
17
|
}).catch(() => {}), () => {
|
|
15
|
-
|
|
18
|
+
o = !0, r?.(), i?.(), import("@intlayer/editor").then(({ stopEditorClient: e }) => {
|
|
16
19
|
e();
|
|
17
20
|
}).catch(() => {});
|
|
18
21
|
};
|
|
19
|
-
},
|
|
20
|
-
if (process.env.INTLAYER_EDITOR_ENABLED === "false" || !
|
|
21
|
-
if (
|
|
22
|
-
let
|
|
23
|
-
|
|
22
|
+
}, c = (e) => {
|
|
23
|
+
if (process.env.INTLAYER_EDITOR_ENABLED === "false" || !o) return;
|
|
24
|
+
if (e) {
|
|
25
|
+
let n = null;
|
|
26
|
+
e.mixin({
|
|
24
27
|
inject: { _intlayerClient: {
|
|
25
|
-
from:
|
|
28
|
+
from: t,
|
|
26
29
|
default: null
|
|
27
30
|
} },
|
|
28
31
|
mounted() {
|
|
29
32
|
if (this.$parent !== null) return;
|
|
30
33
|
let e = this._intlayerClient;
|
|
31
|
-
|
|
34
|
+
n = s(e);
|
|
32
35
|
},
|
|
33
36
|
unmounted() {
|
|
34
|
-
this.$parent === null &&
|
|
37
|
+
this.$parent === null && n?.();
|
|
35
38
|
}
|
|
36
39
|
});
|
|
37
40
|
return;
|
|
38
41
|
}
|
|
39
|
-
let
|
|
40
|
-
|
|
41
|
-
c =
|
|
42
|
-
}),
|
|
42
|
+
let a = n(t), c = null;
|
|
43
|
+
r(() => {
|
|
44
|
+
c = s(a);
|
|
45
|
+
}), i(() => {
|
|
43
46
|
c?.();
|
|
44
47
|
});
|
|
45
48
|
};
|
|
46
49
|
//#endregion
|
|
47
|
-
export {
|
|
50
|
+
export { c as useEditor };
|
|
@@ -3,9 +3,9 @@ import { computed as t, inject as n } from "vue";
|
|
|
3
3
|
import { compact as r } from "@intlayer/core/formatters";
|
|
4
4
|
//#region src/format/useCompact.ts
|
|
5
5
|
var i = () => {
|
|
6
|
-
let i = n(e);
|
|
6
|
+
let i = n(e, null);
|
|
7
7
|
return t(() => {
|
|
8
|
-
let e = i
|
|
8
|
+
let e = i?.locale.value;
|
|
9
9
|
return (...t) => r(t[0], {
|
|
10
10
|
...t[1],
|
|
11
11
|
locale: t[1]?.locale ?? e
|
|
@@ -3,9 +3,9 @@ import { computed as t, inject as n } from "vue";
|
|
|
3
3
|
import { currency as r } from "@intlayer/core/formatters";
|
|
4
4
|
//#region src/format/useCurrency.ts
|
|
5
5
|
var i = () => {
|
|
6
|
-
let i = n(e);
|
|
6
|
+
let i = n(e, null);
|
|
7
7
|
return t(() => {
|
|
8
|
-
let e = i
|
|
8
|
+
let e = i?.locale.value;
|
|
9
9
|
return (...t) => r(t[0], {
|
|
10
10
|
...t[1],
|
|
11
11
|
locale: t[1]?.locale ?? e
|
|
@@ -3,9 +3,9 @@ import { computed as t, inject as n } from "vue";
|
|
|
3
3
|
import { date as r, presets as i } from "@intlayer/core/formatters";
|
|
4
4
|
//#region src/format/useDate.ts
|
|
5
5
|
var a = () => {
|
|
6
|
-
let a = n(e);
|
|
6
|
+
let a = n(e, null);
|
|
7
7
|
return t(() => {
|
|
8
|
-
let e = a
|
|
8
|
+
let e = a?.locale.value;
|
|
9
9
|
return (...t) => {
|
|
10
10
|
let n = typeof t[1] == "string" ? {
|
|
11
11
|
...i[t[1]],
|
|
@@ -3,9 +3,9 @@ import { computed as t, inject as n } from "vue";
|
|
|
3
3
|
import { bindIntl as r } from "@intlayer/core/utils";
|
|
4
4
|
//#region src/format/useIntl.ts
|
|
5
5
|
var i = (i) => {
|
|
6
|
-
let a = n(e);
|
|
6
|
+
let a = n(e, null);
|
|
7
7
|
return t(() => {
|
|
8
|
-
let e = i ?? a
|
|
8
|
+
let e = i ?? a?.locale.value;
|
|
9
9
|
return r(e);
|
|
10
10
|
});
|
|
11
11
|
};
|
|
@@ -3,9 +3,9 @@ import { computed as t, inject as n } from "vue";
|
|
|
3
3
|
import { list as r } from "@intlayer/core/formatters";
|
|
4
4
|
//#region src/format/useList.ts
|
|
5
5
|
var i = () => {
|
|
6
|
-
let i = n(e);
|
|
6
|
+
let i = n(e, null);
|
|
7
7
|
return t(() => {
|
|
8
|
-
let e = i
|
|
8
|
+
let e = i?.locale.value;
|
|
9
9
|
return (...t) => r(t[0], {
|
|
10
10
|
...t[1],
|
|
11
11
|
locale: t[1]?.locale ?? e
|
|
@@ -3,9 +3,9 @@ import { computed as t, inject as n } from "vue";
|
|
|
3
3
|
import { number as r } from "@intlayer/core/formatters";
|
|
4
4
|
//#region src/format/useNumber.ts
|
|
5
5
|
var i = () => {
|
|
6
|
-
let i = n(e);
|
|
6
|
+
let i = n(e, null);
|
|
7
7
|
return t(() => {
|
|
8
|
-
let e = i
|
|
8
|
+
let e = i?.locale.value;
|
|
9
9
|
return (...t) => r(t[0], {
|
|
10
10
|
...t[1],
|
|
11
11
|
locale: t[1]?.locale ?? e
|
|
@@ -3,9 +3,9 @@ import { computed as t, inject as n } from "vue";
|
|
|
3
3
|
import { percentage as r } from "@intlayer/core/formatters";
|
|
4
4
|
//#region src/format/usePercentage.ts
|
|
5
5
|
var i = () => {
|
|
6
|
-
let i = n(e);
|
|
6
|
+
let i = n(e, null);
|
|
7
7
|
return t(() => {
|
|
8
|
-
let e = i
|
|
8
|
+
let e = i?.locale.value;
|
|
9
9
|
return (...t) => r(t[0], {
|
|
10
10
|
...t[1],
|
|
11
11
|
locale: t[1]?.locale ?? e
|
|
@@ -3,9 +3,9 @@ import { computed as t, inject as n } from "vue";
|
|
|
3
3
|
import { relativeTime as r } from "@intlayer/core/formatters";
|
|
4
4
|
//#region src/format/useRelativeTime.ts
|
|
5
5
|
var i = () => {
|
|
6
|
-
let i = n(e);
|
|
6
|
+
let i = n(e, null);
|
|
7
7
|
return t(() => {
|
|
8
|
-
let e = i
|
|
8
|
+
let e = i?.locale.value;
|
|
9
9
|
return (...t) => r(t[0], t[1], {
|
|
10
10
|
...t[2],
|
|
11
11
|
locale: t[2]?.locale ?? e
|
|
@@ -3,9 +3,9 @@ import { computed as t, inject as n } from "vue";
|
|
|
3
3
|
import { units as r } from "@intlayer/core/formatters";
|
|
4
4
|
//#region src/format/useUnit.ts
|
|
5
5
|
var i = () => {
|
|
6
|
-
let i = n(e);
|
|
6
|
+
let i = n(e, null);
|
|
7
7
|
return t(() => {
|
|
8
|
-
let e = i
|
|
8
|
+
let e = i?.locale.value;
|
|
9
9
|
return (...t) => r(t[0], {
|
|
10
10
|
...t[1],
|
|
11
11
|
locale: t[1]?.locale ?? e
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return s}});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Dictionary } from '@intlayer/types/dictionary';
|
|
2
|
+
import { KeyPath } from '@intlayer/types/keyPath';
|
|
3
|
+
/**
|
|
4
|
+
* Edit coming from the devtools inspector: the label of the edited row, plus
|
|
5
|
+
* the locale when a single locale of a translation row was edited.
|
|
6
|
+
*/
|
|
7
|
+
export type InspectorEdit = {
|
|
8
|
+
label: string;
|
|
9
|
+
locale?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Editability of an inspector row: a translation node editable per locale,
|
|
13
|
+
* or a plain string leaf editable as a whole.
|
|
14
|
+
*/
|
|
15
|
+
export type Editability = 'translation' | 'plain-string';
|
|
16
|
+
/**
|
|
17
|
+
* Tell whether the node at `keyPath` can be edited from the devtools
|
|
18
|
+
* inspector: plain string leaves are editable as a whole, and translation
|
|
19
|
+
* nodes are editable per locale when every locale holds a plain string.
|
|
20
|
+
* Rich nodes (markdown, html, insertion…), numbers and nested structures stay
|
|
21
|
+
* read-only.
|
|
22
|
+
*/
|
|
23
|
+
export declare const getEditability: (dictionary: Dictionary, keyPath: KeyPath[]) => Editability | null;
|
|
24
|
+
/**
|
|
25
|
+
* Parse the `path` array of an `editInspectorState` payload.
|
|
26
|
+
*
|
|
27
|
+
* The devtools frontend builds the path from the edited state entry: the row
|
|
28
|
+
* label is always a single segment (even when it contains dots), optionally
|
|
29
|
+
* followed by the locale key. The leading section name is stripped
|
|
30
|
+
* defensively — some devtools frontends include it.
|
|
31
|
+
*
|
|
32
|
+
* Returns `null` for paths that do not address a single value.
|
|
33
|
+
*/
|
|
34
|
+
export declare const parseEditPath: (path: string[], sectionName?: string) => InspectorEdit | null;
|
|
35
|
+
/**
|
|
36
|
+
* Resolve an inspector edit to the `KeyPath` of the edited string: the row
|
|
37
|
+
* key path, extended with the locale for a translation edit. Returns `null`
|
|
38
|
+
* when no row of `dictionary` carries the edited label.
|
|
39
|
+
*/
|
|
40
|
+
export declare const getEditKeyPath: (dictionary: Dictionary, edit: InspectorEdit) => KeyPath[] | null;
|
|
41
|
+
/**
|
|
42
|
+
* Replace the string at `keyPath` and return the updated declaration, ready
|
|
43
|
+
* to be sent back to the editor server. The input dictionary is never
|
|
44
|
+
* mutated. Returns `null` when `keyPath` does not address an existing string
|
|
45
|
+
* (missing locale, rich node, number…), so an edit never creates a node.
|
|
46
|
+
*/
|
|
47
|
+
export declare const applyDictionaryEdit: (dictionary: Dictionary, keyPath: KeyPath[], newValue: string) => Dictionary | null;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Dictionary } from '@intlayer/types/dictionary';
|
|
2
|
+
/**
|
|
3
|
+
* Unmerged dictionaries as returned by the editor server: one array of
|
|
4
|
+
* declarations per dictionary key. Declared locally — rather than importing
|
|
5
|
+
* `GetEditorDictionariesResult` from `intlayer-editor` — to keep the
|
|
6
|
+
* published types of vue-intlayer free of a dependency on the editor package.
|
|
7
|
+
*/
|
|
8
|
+
export type UnmergedDictionaries = Record<string, Dictionary[]>;
|
|
9
|
+
export type EditorServerSession = {
|
|
10
|
+
/** Whether the last fetch reached the editor server. */
|
|
11
|
+
isOnline: () => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Fetch the unmerged dictionaries from the editor server, or `null` when
|
|
14
|
+
* the server is unreachable (`npx intlayer editor start` not running).
|
|
15
|
+
*/
|
|
16
|
+
fetchUnmergedDictionaries: () => Promise<UnmergedDictionaries | null>;
|
|
17
|
+
/**
|
|
18
|
+
* Write a full declaration back to its source file through the editor
|
|
19
|
+
* server (`POST /api/dictionary`). The declaration must carry the `localId`
|
|
20
|
+
* (and `filePath`) it was fetched with, so the server can locate the source
|
|
21
|
+
* file. The server rebuilds the unmerged dictionaries before answering, so
|
|
22
|
+
* a fetch after the returned promise resolves reflects the write.
|
|
23
|
+
*/
|
|
24
|
+
writeDictionary: (dictionary: Dictionary) => Promise<void>;
|
|
25
|
+
};
|
|
26
|
+
export declare const createEditorServerSession: () => EditorServerSession;
|
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
import { Dictionary } from '@intlayer/types/dictionary';
|
|
2
|
+
import { KeyPath } from '@intlayer/types/keyPath';
|
|
2
3
|
/**
|
|
3
4
|
* Flattened representation of a dictionary content for the devtools
|
|
4
5
|
* inspector: each leaf path maps to its per-locale translations, or to a
|
|
5
6
|
* stringified fallback for non-translation content.
|
|
6
7
|
*/
|
|
7
8
|
export type FlattenedDictionary = Record<string, Record<string, string> | string>;
|
|
9
|
+
/**
|
|
10
|
+
* One inspector row: the displayed label, the `KeyPath` addressing the node
|
|
11
|
+
* in the dictionary content, and the displayed value.
|
|
12
|
+
*/
|
|
13
|
+
export type InspectorEntry = {
|
|
14
|
+
label: string;
|
|
15
|
+
keyPath: KeyPath[];
|
|
16
|
+
value: Record<string, string> | string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Label used for a typed node sitting at the root of the dictionary content.
|
|
20
|
+
*/
|
|
21
|
+
export declare const ROOT_PATH = "(root)";
|
|
22
|
+
/**
|
|
23
|
+
* Recursively list the inspector rows of a dictionary content, each one
|
|
24
|
+
* carrying the `KeyPath` of its node so edits can target it with the core
|
|
25
|
+
* `dictionaryManipulator` helpers.
|
|
26
|
+
*/
|
|
27
|
+
export declare const listInspectorEntries: (dictionary: Dictionary) => InspectorEntry[];
|
|
8
28
|
/**
|
|
9
29
|
* Recursively flatten a dictionary content into leaf-path entries.
|
|
10
30
|
* Translation nodes are exposed as their locale-to-string map; any other
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { App } from 'vue';
|
|
2
2
|
export declare const INTLAYER_DEVTOOLS_PLUGIN_ID = "intlayer";
|
|
3
3
|
export declare const INTLAYER_DICTIONARIES_INSPECTOR_ID = "intlayer-dictionaries-inspector";
|
|
4
|
+
export declare const EDITOR_OFFLINE_NODE_ID = "intlayer-editor-offline";
|
|
4
5
|
/**
|
|
5
6
|
* Register the Intlayer plugin in Vue Devtools with an inspector listing
|
|
6
7
|
* the loaded dictionaries and their translations, plus a "Locales" group
|
|
7
8
|
* node allowing to switch the current locale of the app.
|
|
8
9
|
*
|
|
10
|
+
* When the Intlayer editor server is running (`npx intlayer editor start`),
|
|
11
|
+
* the inspector lists the unmerged dictionary declarations fetched from it
|
|
12
|
+
* and plain-text values become editable: edits are written back to the source
|
|
13
|
+
* content files through the editor server. Without the server, the inspector
|
|
14
|
+
* falls back to a read-only view of the loaded (merged) dictionaries.
|
|
15
|
+
*
|
|
9
16
|
* Lazy-loaded by `installIntlayer`; safe to call only in a browser
|
|
10
17
|
* environment where the devtools hook may exist — `setupDevtoolsPlugin`
|
|
11
18
|
* no-ops when Vue Devtools is not installed.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-intlayer",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.7.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Easily internationalize i18n your Vue applications with type-safe multilingual content management.",
|
|
6
6
|
"keywords": [
|
|
@@ -103,16 +103,16 @@
|
|
|
103
103
|
"typecheck": "vue-tsc --noEmit --project tsconfig.types.json"
|
|
104
104
|
},
|
|
105
105
|
"dependencies": {
|
|
106
|
-
"@intlayer/api": "9.
|
|
107
|
-
"@intlayer/config": "9.
|
|
108
|
-
"@intlayer/core": "9.
|
|
109
|
-
"@intlayer/dictionaries-entry": "9.
|
|
110
|
-
"@intlayer/editor": "9.
|
|
111
|
-
"@intlayer/types": "9.
|
|
106
|
+
"@intlayer/api": "9.7.0",
|
|
107
|
+
"@intlayer/config": "9.7.0",
|
|
108
|
+
"@intlayer/core": "9.7.0",
|
|
109
|
+
"@intlayer/dictionaries-entry": "9.7.0",
|
|
110
|
+
"@intlayer/editor": "9.7.0",
|
|
111
|
+
"@intlayer/types": "9.7.0",
|
|
112
112
|
"@vue/devtools-api": "^6.6.4"
|
|
113
113
|
},
|
|
114
114
|
"devDependencies": {
|
|
115
|
-
"@types/node": "^
|
|
115
|
+
"@types/node": "^26",
|
|
116
116
|
"@utils/ts-config": "1.0.4",
|
|
117
117
|
"@utils/ts-config-types": "1.0.4",
|
|
118
118
|
"@utils/tsdown-config": "1.0.4",
|
|
@@ -122,13 +122,13 @@
|
|
|
122
122
|
"rimraf": "6.1.3",
|
|
123
123
|
"tsdown": "0.23.0",
|
|
124
124
|
"typescript": "7.0.2",
|
|
125
|
-
"vite": "8.3.
|
|
126
|
-
"vite-plugin-dts": "5.1.
|
|
125
|
+
"vite": "8.3.3",
|
|
126
|
+
"vite-plugin-dts": "5.1.2",
|
|
127
127
|
"vitest": "5.0.3",
|
|
128
128
|
"vue-tsc": "3.3.9"
|
|
129
129
|
},
|
|
130
130
|
"peerDependencies": {
|
|
131
|
-
"intlayer": "9.
|
|
131
|
+
"intlayer": "9.7.0",
|
|
132
132
|
"vue": ">=3.0.0"
|
|
133
133
|
},
|
|
134
134
|
"peerDependenciesMeta": {
|
|
@@ -137,7 +137,7 @@
|
|
|
137
137
|
}
|
|
138
138
|
},
|
|
139
139
|
"optionalDependencies": {
|
|
140
|
-
"@intlayer/analytics": "9.
|
|
140
|
+
"@intlayer/analytics": "9.7.0"
|
|
141
141
|
},
|
|
142
142
|
"engines": {
|
|
143
143
|
"node": ">=14.18"
|