@localess/client 3.0.1-dev.20260412201733 → 3.0.1-dev.20260413071348
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.js +1 -1
- package/dist/index.mjs +23 -4
- package/dist/sync.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=`\x1B[0m`,t=`\x1B[34m`,n=()=>typeof window<`u`,r=()=>typeof window>`u`,i=()=>n()&&window.self!==window.top,a=class{set(e,t){}get(e){}has(e){return!1}},o=class{cache=new Map;constructor(e=3e5){this.ttlMs=e}set(e,t){this.cache.set(e,{value:t,expiresAt:Date.now()+this.ttlMs})}get(e){let t=this.cache.get(e);if(t){if(Date.now()>t.expiresAt){this.cache.delete(e);return}return t.value}}has(e){return this.get(e)!==void 0}},s=`${t}[Localess:Client]${e}`;function c(e){e.debug&&console.log(s,`Client Options : `,e);let t=e.origin.replace(/\/+$/,``),n={redirect:`follow`,headers:{"Content-Type":`application/json`,Accept:`application/json`,"X-Localess-Agent":`Localess-JS-Client`,"X-Localess-Agent-Version":`0.9.0`}},r=e.cacheTTL===!1?new a:new o(e.cacheTTL);return{async getLinks(i){e.debug&&console.log(s,`getLinks() params : `,JSON.stringify(i));let a=``;i?.kind&&(a=`&kind=${i.kind}`);let o=``;i?.parentSlug&&(o=`&parentSlug=${i.parentSlug}`);let c=``;i?.excludeChildren&&(c=`&excludeChildren=${i.excludeChildren}`);let l=`${t}/api/v1/spaces/${e.spaceId}/links?token=${e.token}${a}${o}${c}`;if(e.debug&&console.log(s,`getLinks fetch url : `,l),r.has(l))return e.debug&&console.log(s,`getLinks cache hit`),r.get(l);try{let t=await fetch(l,n);e.debug&&console.log(s,`getLinks status : `,t.status);let i=await t.json();return r.set(l,i),i}catch(e){return console.error(s,`getLinks error : `,e),{}}},async getContentBySlug(i,a){e.debug&&(console.log(s,`getContentBySlug() slug : `,i),console.log(s,`getContentBySlug() params : `,JSON.stringify(a)));let o=``;e?.version&&e.version==`draft`&&(o=`&version=${e.version}`),a?.version&&a.version==`draft`&&(o=`&version=${a.version}`);let c=a?.locale?`&locale=${a.locale}`:``,l=a?.resolveReference?`&resolveReference=${a.resolveReference}`:``,u=a?.resolveLink?`&resolveLink=${a.resolveLink}`:``,d=`${t}/api/v1/spaces/${e.spaceId}/contents/slugs/${i}?token=${e.token}${o}${c}${l}${u}`;if(e.debug&&console.log(s,`getContentBySlug fetch url : `,d),r.has(d))return e.debug&&console.log(s,`getContentBySlug cache hit`),r.get(d);try{let t=await fetch(d,n);e.debug&&console.log(s,`getContentBySlug status : `,t.status);let i=await t.json();return r.set(d,i),i}catch(e){return console.error(s,`getContentBySlug error : `,e),{}}},async getContentById(i,a){e.debug&&(console.log(s,`getContentById() id : `,i),console.log(s,`getContentById() params : `,JSON.stringify(a)));let o=``;e?.version&&e.version==`draft`&&(o=`&version=${e.version}`),a?.version&&a.version==`draft`&&(o=`&version=${a.version}`);let c=a?.locale?`&locale=${a.locale}`:``,l=a?.resolveReference?`&resolveReference=${a.resolveReference}`:``,u=a?.resolveLink?`&resolveLink=${a.resolveLink}`:``,d=`${t}/api/v1/spaces/${e.spaceId}/contents/${i}?token=${e.token}${o}${c}${l}${u}`;if(e.debug&&console.log(s,`getContentById fetch url : `,d),r.has(d))return e.debug&&console.log(s,`getContentById cache hit`),r.get(d);try{let t=await fetch(d,n);e.debug&&console.log(s,`getContentById status : `,t.status);let i=await t.json();return r.set(d,i),i}catch(e){return console.error(s,`getContentById error : `,e),{}}},async getTranslations(i){e.debug&&console.log(s,`getTranslations() locale : `,i);let a=`${t}/api/v1/spaces/${e.spaceId}/translations/${i}?token=${e.token}`;if(e.debug&&console.log(s,`getTranslations fetch url : `,a),r.has(a))return e.debug&&console.log(s,`getTranslations cache hit`),r.get(a);try{let t=await fetch(a,n);e.debug&&console.log(s,`getTranslations status : `,t.status);let i=await t.json();return r.set(a,i),i}catch(e){return console.error(s,`getTranslations error : `,e),{}}},syncScriptUrl(){return`${t}/scripts/sync-v1.js`},assetLink(n){return typeof n==`string`?`${t}/api/v1/spaces/${e.spaceId}/assets/${n}`:`${t}/api/v1/spaces/${e.spaceId}/assets/${n.uri}`}}}function l(e){return{"data-ll-id":e._id,"data-ll-schema":e._schema}}function u(e){return{"data-ll-field":e}}var d=`localess-js-sync`;function f(e,t=!1){if(r()
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=`\x1B[0m`,t=`\x1B[34m`,n=()=>typeof window<`u`,r=()=>typeof window>`u`,i=()=>n()&&window.self!==window.top,a=class{set(e,t){}get(e){}has(e){return!1}},o=class{cache=new Map;constructor(e=3e5){this.ttlMs=e}set(e,t){this.cache.set(e,{value:t,expiresAt:Date.now()+this.ttlMs})}get(e){let t=this.cache.get(e);if(t){if(Date.now()>t.expiresAt){this.cache.delete(e);return}return t.value}}has(e){return this.get(e)!==void 0}},s=`${t}[Localess:Client]${e}`;function c(e){e.debug&&console.log(s,`Client Options : `,e);let t=e.origin.replace(/\/+$/,``),n={redirect:`follow`,headers:{"Content-Type":`application/json`,Accept:`application/json`,"X-Localess-Agent":`Localess-JS-Client`,"X-Localess-Agent-Version":`0.9.0`}},r=e.cacheTTL===!1?new a:new o(e.cacheTTL);return{async getLinks(i){e.debug&&console.log(s,`getLinks() params : `,JSON.stringify(i));let a=``;i?.kind&&(a=`&kind=${i.kind}`);let o=``;i?.parentSlug&&(o=`&parentSlug=${i.parentSlug}`);let c=``;i?.excludeChildren&&(c=`&excludeChildren=${i.excludeChildren}`);let l=`${t}/api/v1/spaces/${e.spaceId}/links?token=${e.token}${a}${o}${c}`;if(e.debug&&console.log(s,`getLinks fetch url : `,l),r.has(l))return e.debug&&console.log(s,`getLinks cache hit`),r.get(l);try{let t=await fetch(l,n);e.debug&&console.log(s,`getLinks status : `,t.status);let i=await t.json();return r.set(l,i),i}catch(e){return console.error(s,`getLinks error : `,e),{}}},async getContentBySlug(i,a){e.debug&&(console.log(s,`getContentBySlug() slug : `,i),console.log(s,`getContentBySlug() params : `,JSON.stringify(a)));let o=``;e?.version&&e.version==`draft`&&(o=`&version=${e.version}`),a?.version&&a.version==`draft`&&(o=`&version=${a.version}`);let c=a?.locale?`&locale=${a.locale}`:``,l=a?.resolveReference?`&resolveReference=${a.resolveReference}`:``,u=a?.resolveLink?`&resolveLink=${a.resolveLink}`:``,d=`${t}/api/v1/spaces/${e.spaceId}/contents/slugs/${i}?token=${e.token}${o}${c}${l}${u}`;if(e.debug&&console.log(s,`getContentBySlug fetch url : `,d),r.has(d))return e.debug&&console.log(s,`getContentBySlug cache hit`),r.get(d);try{let t=await fetch(d,n);e.debug&&console.log(s,`getContentBySlug status : `,t.status);let i=await t.json();return r.set(d,i),i}catch(e){return console.error(s,`getContentBySlug error : `,e),{}}},async getContentById(i,a){e.debug&&(console.log(s,`getContentById() id : `,i),console.log(s,`getContentById() params : `,JSON.stringify(a)));let o=``;e?.version&&e.version==`draft`&&(o=`&version=${e.version}`),a?.version&&a.version==`draft`&&(o=`&version=${a.version}`);let c=a?.locale?`&locale=${a.locale}`:``,l=a?.resolveReference?`&resolveReference=${a.resolveReference}`:``,u=a?.resolveLink?`&resolveLink=${a.resolveLink}`:``,d=`${t}/api/v1/spaces/${e.spaceId}/contents/${i}?token=${e.token}${o}${c}${l}${u}`;if(e.debug&&console.log(s,`getContentById fetch url : `,d),r.has(d))return e.debug&&console.log(s,`getContentById cache hit`),r.get(d);try{let t=await fetch(d,n);e.debug&&console.log(s,`getContentById status : `,t.status);let i=await t.json();return r.set(d,i),i}catch(e){return console.error(s,`getContentById error : `,e),{}}},async getTranslations(i){e.debug&&console.log(s,`getTranslations() locale : `,i);let a=`${t}/api/v1/spaces/${e.spaceId}/translations/${i}?token=${e.token}`;if(e.debug&&console.log(s,`getTranslations fetch url : `,a),r.has(a))return e.debug&&console.log(s,`getTranslations cache hit`),r.get(a);try{let t=await fetch(a,n);e.debug&&console.log(s,`getTranslations status : `,t.status);let i=await t.json();return r.set(a,i),i}catch(e){return console.error(s,`getTranslations error : `,e),{}}},syncScriptUrl(){return`${t}/scripts/sync-v1.js`},assetLink(n){return typeof n==`string`?`${t}/api/v1/spaces/${e.spaceId}/assets/${n}`:`${t}/api/v1/spaces/${e.spaceId}/assets/${n.uri}`}}}function l(e){return{"data-ll-id":e._id,"data-ll-schema":e._schema}}function u(e){return{"data-ll-field":e}}var d=`localess-js-sync`;async function f(e,t=!1){return new Promise((t,n)=>{if(r()){n(void 0);return}if(!i()){console.warn(`Localess Sync is loaded only in Visual Editor.`),n(void 0);return}if(window.localess!==void 0){n(void 0);return}if(document.getElementById(d)){n(void 0);return}let a=document.createElement(`script`);a.id=d,a.type=`text/javascript`,a.src=`${e}/scripts/sync-v1.js`,a.async=!0,a.onerror=e=>n(e),a.onload=e=>{console.info(`Localess Sync Script loaded`),t()},document.head.appendChild(a)})}exports.isBrowser=n,exports.isIframe=i,exports.isServer=r,exports.loadLocalessSync=f,exports.localessClient=c,exports.localessEditable=l,exports.localessEditableField=u;
|
package/dist/index.mjs
CHANGED
|
@@ -126,10 +126,29 @@ function u(e) {
|
|
|
126
126
|
//#endregion
|
|
127
127
|
//#region src/sync.ts
|
|
128
128
|
var d = "localess-js-sync";
|
|
129
|
-
function f(e, t = !1) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
async function f(e, t = !1) {
|
|
130
|
+
return new Promise((t, n) => {
|
|
131
|
+
if (r()) {
|
|
132
|
+
n(void 0);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (!i()) {
|
|
136
|
+
console.warn("Localess Sync is loaded only in Visual Editor."), n(void 0);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (window.localess !== void 0) {
|
|
140
|
+
n(void 0);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (document.getElementById(d)) {
|
|
144
|
+
n(void 0);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
let a = document.createElement("script");
|
|
148
|
+
a.id = d, a.type = "text/javascript", a.src = `${e}/scripts/sync-v1.js`, a.async = !0, a.onerror = (e) => n(e), a.onload = (e) => {
|
|
149
|
+
console.info("Localess Sync Script loaded"), t();
|
|
150
|
+
}, document.head.appendChild(a);
|
|
151
|
+
});
|
|
133
152
|
}
|
|
134
153
|
//#endregion
|
|
135
154
|
export { n as isBrowser, i as isIframe, r as isServer, f as loadLocalessSync, c as localessClient, l as localessEditable, u as localessEditableField };
|
package/dist/sync.d.ts
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* @param {string} origin A fully qualified domain name with protocol (http/https) and port.
|
|
4
4
|
* @param {boolean} force Force Script Injection even if the application is not in Visual Editor.
|
|
5
5
|
*/
|
|
6
|
-
export declare function loadLocalessSync(origin: string, force?: boolean): void
|
|
6
|
+
export declare function loadLocalessSync(origin: string, force?: boolean): Promise<void>;
|