@cancia/toolbar 0.5.1 → 0.5.2

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.
@@ -1,4 +1,4 @@
1
- "use strict";var Cancia=(()=>{var wi=Object.defineProperty;var Nm=Object.getOwnPropertyDescriptor;var Am=Object.getOwnPropertyNames;var Rm=Object.prototype.hasOwnProperty;var ue=(e,n)=>{for(var i in n)wi(e,i,{get:n[i],enumerable:!0})},Mm=(e,n,i,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of Am(n))!Rm.call(e,t)&&t!==i&&wi(e,t,{get:()=>n[t],enumerable:!(o=Nm(n,t))||o.enumerable});return e};var Fm=e=>Mm(wi({},"__esModule",{value:!0}),e);var Zh={};ue(Zh,{clearSession:()=>Ql,destroy:()=>zn,getValue:()=>de,init:()=>Xl,onPendingChange:()=>ce});var z={config:null,cmsData:{},pending:new Map,activeLang:"",editMode:!1,sessionToken:"",onLogout:null,schemas:{},activeListLocale:""};function Vm(e,n){return`${e}.${n}`}function de(e,n){let i=`${e}.${n}`,o=z.pending.get(i);return o?o.value:z.cmsData[i]!==void 0?z.cmsData[i]:""}function Ye(e,n,i){let o=Vm(e,n);z.pending.set(o,{key:e,lang:n,value:i})}function Jm(e){if(!e)return{label:"",href:""};let n=e.trim();if(n.startsWith("{"))try{let i=JSON.parse(n);if(i&&typeof i=="object")return{label:String(i.label??""),href:String(i.href??"")}}catch{}return{label:e,href:""}}function Nt(){document.querySelectorAll("[data-cms]").forEach(e=>{if(e.dataset.cmsList!==void 0)return;let n=e.dataset.cms;if(!n)return;let i=z.cmsData[`${n}.${z.activeLang}`];if(i!==void 0){if(e.tagName==="IMG"){e.src=i;return}if(e.dataset.cmsType==="link"||e.tagName==="A"){let o=Jm(i);o.href&&e.tagName==="A"&&e.setAttribute("href",o.href);let t=e.querySelectorAll("[data-cms-label]");t.length>0?t.forEach(r=>r.textContent=o.label):e.childElementCount===0&&(e.textContent=o.label);return}if(e.childElementCount>0){console.warn(`Cancia: skipping overlay for "${n}" \u2014 element has child elements (textContent would destroy them).`);return}e.textContent=i}})}function eu(){for(let[e,{key:n,lang:i}]of z.pending){let o=z.cmsData[e]??"";document.querySelectorAll(`[data-cms="${n}"]`).forEach(t=>{t.tagName==="IMG"?t.src=o:t.textContent=o})}z.pending.clear()}function pe(){let e={"Content-Type":"application/json"};return z.sessionToken&&(e.Authorization=`Bearer ${z.sessionToken}`),e}function tu(){return typeof location<"u"?location.pathname:""}function Sn(){let e=tu();return e?`&route=${encodeURIComponent(e)}`:""}async function nu(){let{apiUrl:e,site:n}=z.config,i=await fetch(`${e}/api/cancia/content?site=${encodeURIComponent(n)}`,{headers:pe()});if(!i.ok)throw new Error(`Cancia: failed to fetch content (${i.status})`);return i.json()}async function Bm(e,n,i){let{apiUrl:o,site:t}=z.config,r=await fetch(`${o}/api/cancia/save`,{method:"POST",headers:pe(),body:JSON.stringify({key:e,lang:n,value:i,site:t,route:tu()})});if(!r.ok)throw new Error(`Cancia: failed to save (${r.status})`)}function ru(e){return e instanceof Error&&e.message.includes("(401)")}function In(e,n){return new Promise((i,o)=>{let{apiUrl:t,site:r}=z.config,a=new FormData;a.append("file",e),a.append("site",r);let c=new XMLHttpRequest;c.open("POST",`${t}/api/cancia/upload`),z.sessionToken&&c.setRequestHeader("Authorization",`Bearer ${z.sessionToken}`),c.upload.addEventListener("progress",l=>{l.lengthComputable&&n?.(Math.round(l.loaded/l.total*100))}),c.addEventListener("load",()=>{if(c.status>=200&&c.status<300)try{i(JSON.parse(c.responseText).url)}catch{o(new Error("Cancia: invalid upload response"))}else o(new Error(`Cancia: failed to upload image (${c.status})`))}),c.addEventListener("error",()=>o(new Error("Cancia: upload network error"))),c.send(a)})}async function iu(){let{apiUrl:e,site:n}=z.config,i=await fetch(`${e}/api/cancia/publish`,{method:"POST",headers:pe(),body:JSON.stringify({site:n})});if(!i.ok)throw new Error(`Cancia: publish failed (${i.status})`)}async function ou(){let{apiUrl:e}=z.config,n=await fetch(`${e}/api/cancia/schemas`,{headers:pe()});if(!n.ok)throw new Error(`Cancia: failed to fetch schemas (${n.status})`);return(await n.json()).schemas}function En(e){return e?`&locale=${encodeURIComponent(e)}`:""}async function Tn(e,n){let{apiUrl:i,site:o}=z.config,t=await fetch(`${i}/api/cancia/lists/${encodeURIComponent(e)}?site=${encodeURIComponent(o)}${En(n)}`,{headers:pe()});if(!t.ok)throw new Error(`Cancia: failed to fetch list "${e}" (${t.status})`);return(await t.json()).entries}async function au(e){let{apiUrl:n,site:i}=z.config,o=await fetch(`${n}/api/cancia/lists/${encodeURIComponent(e)}/_translations?site=${encodeURIComponent(i)}`,{headers:pe()});if(!o.ok)throw new Error(`Cancia: failed to fetch translations (${o.status})`);return(await o.json()).translations}async function cu(e,n,i,o){let{apiUrl:t,site:r}=z.config,a=await fetch(`${t}/api/cancia/lists/${encodeURIComponent(e)}?site=${encodeURIComponent(r)}${En(i)}${Sn()}`,{method:"POST",headers:pe(),body:JSON.stringify({data:n,id:o})});if(!a.ok){let l=await a.json().catch(()=>({}));throw new Error(l.error??`Cancia: failed to create entry (${a.status})`)}return(await a.json()).entry}async function su(e,n,i,o,t){let{apiUrl:r,site:a}=z.config,c=await fetch(`${r}/api/cancia/lists/${encodeURIComponent(e)}/${encodeURIComponent(n)}?site=${encodeURIComponent(a)}${En(t)}${Sn()}`,{method:"PATCH",headers:pe(),body:JSON.stringify({data:i,_rev:o})});if(!c.ok){let s=await c.json().catch(()=>({})),u=s.error??`Cancia: failed to update entry (${c.status})`;throw Object.assign(new Error(u),{code:s.code})}return(await c.json()).entry}async function lu(e,n,i){let{apiUrl:o,site:t}=z.config,r=await fetch(`${o}/api/cancia/lists/${encodeURIComponent(e)}/${encodeURIComponent(n)}?site=${encodeURIComponent(t)}${En(i)}${Sn()}`,{method:"DELETE",headers:pe()});if(!r.ok)throw new Error(`Cancia: failed to delete entry (${r.status})`)}async function uu(e,n){let{apiUrl:i,site:o}=z.config,t=await fetch(`${i}/api/cancia/lists/${encodeURIComponent(e)}/reorder?site=${encodeURIComponent(o)}${Sn()}`,{method:"POST",headers:pe(),body:JSON.stringify({ids:n})});if(!t.ok)throw new Error(`Cancia: failed to reorder list (${t.status})`)}async function zi(){let e=Array.from(z.pending.values()),n=await Promise.allSettled(e.map(({key:o,lang:t,value:r})=>Bm(o,t,r)));n.forEach((o,t)=>{if(o.status==="fulfilled"){let{key:r,lang:a}=e[t];z.pending.delete(`${r}.${a}`)}});let i=n.filter(o=>o.status==="rejected").length;if(i>0)throw new Error(`Cancia: ${i} save(s) failed`)}var jn="[data-cms], [data-cms-list]",Pn=null,Se=null,Si=[],Qe=null,oe=null,ae=null,du=!1;function pu(){return z.config?.accentColor??"#6366f1"}function hu(e){return e.dataset.cmsType==="image"?"image":e.dataset.cmsType==="link"?"link":e.tagName==="IMG"?"image":e.tagName==="A"?"link":"text"}function bu(e){return e.dataset.cmsList?"list":"field"}function Hm(){if(du)return;du=!0;let e=document.createElement("style");e.textContent=`
1
+ "use strict";var Cancia=(()=>{var wi=Object.defineProperty;var Nm=Object.getOwnPropertyDescriptor;var Am=Object.getOwnPropertyNames;var Rm=Object.prototype.hasOwnProperty;var ue=(e,n)=>{for(var i in n)wi(e,i,{get:n[i],enumerable:!0})},Mm=(e,n,i,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of Am(n))!Rm.call(e,t)&&t!==i&&wi(e,t,{get:()=>n[t],enumerable:!(o=Nm(n,t))||o.enumerable});return e};var Fm=e=>Mm(wi({},"__esModule",{value:!0}),e);var Zh={};ue(Zh,{clearSession:()=>Ql,destroy:()=>zn,getValue:()=>de,init:()=>Xl,onPendingChange:()=>ce});var z={config:null,cmsData:{},pending:new Map,activeLang:"",editMode:!1,sessionToken:"",onLogout:null,schemas:{},activeListLocale:""};function Vm(e,n){return`${e}.${n}`}function de(e,n){let i=`${e}.${n}`,o=z.pending.get(i);return o?o.value:z.cmsData[i]!==void 0?z.cmsData[i]:""}function Ye(e,n,i){let o=Vm(e,n);z.pending.set(o,{key:e,lang:n,value:i})}function Jm(e){if(!e)return{label:"",href:""};let n=e.trim();if(n.startsWith("{"))try{let i=JSON.parse(n);if(i&&typeof i=="object")return{label:String(i.label??""),href:String(i.href??"")}}catch{}return{label:e,href:""}}function Nt(){document.querySelectorAll("[data-cms]").forEach(e=>{if(e.dataset.cmsList!==void 0)return;let n=e.dataset.cms;if(!n)return;let i=z.cmsData[`${n}.${z.activeLang}`];if(i!==void 0){if(e.tagName==="IMG"){e.src=i;return}if(e.dataset.cmsType==="link"){let o=Jm(i);o.href&&e.tagName==="A"&&e.setAttribute("href",o.href);let t=e.querySelectorAll("[data-cms-label]");t.length>0?t.forEach(r=>r.textContent=o.label):e.childElementCount===0&&(e.textContent=o.label);return}if(e.childElementCount>0){console.warn(`Cancia: skipping overlay for "${n}" \u2014 element has child elements (textContent would destroy them).`);return}e.textContent=i}})}function eu(){for(let[e,{key:n,lang:i}]of z.pending){let o=z.cmsData[e]??"";document.querySelectorAll(`[data-cms="${n}"]`).forEach(t=>{t.tagName==="IMG"?t.src=o:t.textContent=o})}z.pending.clear()}function pe(){let e={"Content-Type":"application/json"};return z.sessionToken&&(e.Authorization=`Bearer ${z.sessionToken}`),e}function tu(){return typeof location<"u"?location.pathname:""}function Sn(){let e=tu();return e?`&route=${encodeURIComponent(e)}`:""}async function nu(){let{apiUrl:e,site:n}=z.config,i=await fetch(`${e}/api/cancia/content?site=${encodeURIComponent(n)}`,{headers:pe()});if(!i.ok)throw new Error(`Cancia: failed to fetch content (${i.status})`);return i.json()}async function Bm(e,n,i){let{apiUrl:o,site:t}=z.config,r=await fetch(`${o}/api/cancia/save`,{method:"POST",headers:pe(),body:JSON.stringify({key:e,lang:n,value:i,site:t,route:tu()})});if(!r.ok)throw new Error(`Cancia: failed to save (${r.status})`)}function ru(e){return e instanceof Error&&e.message.includes("(401)")}function In(e,n){return new Promise((i,o)=>{let{apiUrl:t,site:r}=z.config,a=new FormData;a.append("file",e),a.append("site",r);let c=new XMLHttpRequest;c.open("POST",`${t}/api/cancia/upload`),z.sessionToken&&c.setRequestHeader("Authorization",`Bearer ${z.sessionToken}`),c.upload.addEventListener("progress",l=>{l.lengthComputable&&n?.(Math.round(l.loaded/l.total*100))}),c.addEventListener("load",()=>{if(c.status>=200&&c.status<300)try{i(JSON.parse(c.responseText).url)}catch{o(new Error("Cancia: invalid upload response"))}else o(new Error(`Cancia: failed to upload image (${c.status})`))}),c.addEventListener("error",()=>o(new Error("Cancia: upload network error"))),c.send(a)})}async function iu(){let{apiUrl:e,site:n}=z.config,i=await fetch(`${e}/api/cancia/publish`,{method:"POST",headers:pe(),body:JSON.stringify({site:n})});if(!i.ok)throw new Error(`Cancia: publish failed (${i.status})`)}async function ou(){let{apiUrl:e}=z.config,n=await fetch(`${e}/api/cancia/schemas`,{headers:pe()});if(!n.ok)throw new Error(`Cancia: failed to fetch schemas (${n.status})`);return(await n.json()).schemas}function En(e){return e?`&locale=${encodeURIComponent(e)}`:""}async function Tn(e,n){let{apiUrl:i,site:o}=z.config,t=await fetch(`${i}/api/cancia/lists/${encodeURIComponent(e)}?site=${encodeURIComponent(o)}${En(n)}`,{headers:pe()});if(!t.ok)throw new Error(`Cancia: failed to fetch list "${e}" (${t.status})`);return(await t.json()).entries}async function au(e){let{apiUrl:n,site:i}=z.config,o=await fetch(`${n}/api/cancia/lists/${encodeURIComponent(e)}/_translations?site=${encodeURIComponent(i)}`,{headers:pe()});if(!o.ok)throw new Error(`Cancia: failed to fetch translations (${o.status})`);return(await o.json()).translations}async function cu(e,n,i,o){let{apiUrl:t,site:r}=z.config,a=await fetch(`${t}/api/cancia/lists/${encodeURIComponent(e)}?site=${encodeURIComponent(r)}${En(i)}${Sn()}`,{method:"POST",headers:pe(),body:JSON.stringify({data:n,id:o})});if(!a.ok){let l=await a.json().catch(()=>({}));throw new Error(l.error??`Cancia: failed to create entry (${a.status})`)}return(await a.json()).entry}async function su(e,n,i,o,t){let{apiUrl:r,site:a}=z.config,c=await fetch(`${r}/api/cancia/lists/${encodeURIComponent(e)}/${encodeURIComponent(n)}?site=${encodeURIComponent(a)}${En(t)}${Sn()}`,{method:"PATCH",headers:pe(),body:JSON.stringify({data:i,_rev:o})});if(!c.ok){let s=await c.json().catch(()=>({})),u=s.error??`Cancia: failed to update entry (${c.status})`;throw Object.assign(new Error(u),{code:s.code})}return(await c.json()).entry}async function lu(e,n,i){let{apiUrl:o,site:t}=z.config,r=await fetch(`${o}/api/cancia/lists/${encodeURIComponent(e)}/${encodeURIComponent(n)}?site=${encodeURIComponent(t)}${En(i)}${Sn()}`,{method:"DELETE",headers:pe()});if(!r.ok)throw new Error(`Cancia: failed to delete entry (${r.status})`)}async function uu(e,n){let{apiUrl:i,site:o}=z.config,t=await fetch(`${i}/api/cancia/lists/${encodeURIComponent(e)}/reorder?site=${encodeURIComponent(o)}${Sn()}`,{method:"POST",headers:pe(),body:JSON.stringify({ids:n})});if(!t.ok)throw new Error(`Cancia: failed to reorder list (${t.status})`)}async function zi(){let e=Array.from(z.pending.values()),n=await Promise.allSettled(e.map(({key:o,lang:t,value:r})=>Bm(o,t,r)));n.forEach((o,t)=>{if(o.status==="fulfilled"){let{key:r,lang:a}=e[t];z.pending.delete(`${r}.${a}`)}});let i=n.filter(o=>o.status==="rejected").length;if(i>0)throw new Error(`Cancia: ${i} save(s) failed`)}var jn="[data-cms], [data-cms-list]",Pn=null,Se=null,Si=[],Qe=null,oe=null,ae=null,du=!1;function pu(){return z.config?.accentColor??"#6366f1"}function hu(e){return e.dataset.cmsType==="image"?"image":e.dataset.cmsType==="link"?"link":e.tagName==="IMG"?"image":"text"}function bu(e){return e.dataset.cmsList?"list":"field"}function Hm(){if(du)return;du=!0;let e=document.createElement("style");e.textContent=`
2
2
  @keyframes cancia-highlight-in {
3
3
  from { opacity: 0; transform: scale(0.98); }
4
4
  to { opacity: 1; transform: scale(1); }
package/dist/cancia.js CHANGED
@@ -53,7 +53,7 @@ function applyOverlay() {
53
53
  el.src = savedValue;
54
54
  return;
55
55
  }
56
- if (el.dataset.cmsType === "link" || el.tagName === "A") {
56
+ if (el.dataset.cmsType === "link") {
57
57
  const link = parseLinkOverlay(savedValue);
58
58
  if (link.href && el.tagName === "A") el.setAttribute("href", link.href);
59
59
  const labelEls = el.querySelectorAll("[data-cms-label]");
@@ -258,7 +258,6 @@ function fieldType(el) {
258
258
  if (el.dataset.cmsType === "image") return "image";
259
259
  if (el.dataset.cmsType === "link") return "link";
260
260
  if (el.tagName === "IMG") return "image";
261
- if (el.tagName === "A") return "link";
262
261
  return "text";
263
262
  }
264
263
  function elementMode(el) {