@paroicms/list-field-plugin 0.26.1 → 0.28.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.
@@ -1 +1,110 @@
1
- import{delegateEvents as v,template as p,addEventListener as k,effect as h,setAttribute as w,use as b,insert as m,createComponent as L}from"https://esm.sh/solid-js@1.9.7/web";import{createMemo as V,onMount as x,Index as O,createRoot as P,createSignal as g}from"https://esm.sh/solid-js@1.9.7";function _(e){return typeof e=="object"&&e!==null&&"j"in e}const S={en:{en:"English",fr:"French",es:"Spanish",de:"German",it:"Italian",pt:"Portuguese"},fr:{en:"Anglais",fr:"Français",es:"Espagnol",de:"Allemand",it:"Italien",pt:"Portugais"},es:{en:"Inglés",fr:"Francés",es:"Español",de:"Alemán",it:"Italiano",pt:"Portugués"},de:{en:"Englisch",fr:"Französisch",es:"Spanisch",de:"Deutsch",it:"Italienisch",pt:"Portugiesisch"},it:{en:"Inglese",fr:"Francese",es:"Spagnolo",de:"Tedesco",it:"Italiano",pt:"Portoghese"},pt:{en:"Inglês",fr:"Francês",es:"Espanhol",de:"Alemão",it:"Italiano",pt:"Português"}},F=Object.keys(S);function C(e,{pluginLanguages:n,siteLanguages:t=[]}){if(n.includes(e)||F.includes(e)&&n.includes(e))return e;const s=t.find((i=>F.includes(i)&&n.includes(i)));return s||(n.includes("en")?"en":n[0]??"en")}const j=e=>e!=null&&(e=Object.getPrototypeOf(e),e===Array.prototype||e===Object.prototype);function E(e,n,t){for(const[s,i]of Object.entries(n)){const l=`${t}.${s}`;e[l]=i,j(i)&&E(e,i,l)}}function D(e){const n={...e};for(const[t,s]of Object.entries(e))j(s)&&E(n,s,t);return n}const T=e=>e;function B(e,n=T){return(t,...s)=>{t[0]==="."&&(t=t.slice(1));const i=e()?.[t];switch(typeof i){case"function":return i(...s);case"string":return n(i,s[0]);default:return i}}}const M={placeholder:"Bearbeiten…",emptyList:"Keine Elemente gefunden"},N={ListField:M},R={placeholder:"Edit…",emptyList:"No items found"},z={ListField:R},G={placeholder:"Editar…",emptyList:"Lista vacía"},J={ListField:G},K={placeholder:"Éditer…",emptyList:"Liste vide"},U={ListField:K},H={placeholder:"Modifica…",emptyList:"Nessun elemento trovato"},Q={ListField:H},W={placeholder:"Editar…",emptyList:"Nenhum item encontrado"},X={ListField:W},y={en:z,fr:U,es:J,de:N,it:Q,pt:X};function A(e,n){const t=V((()=>{const i=e(),l=Object.keys(y),o=C(i,{pluginLanguages:l,siteLanguages:n});return D(y[o])}));return{t:B(t)}}var Y=p('<div class=LFInputField><input class=LFInputField-input type=text><button type=button class="pi pi-trash LFInputField-delete LFIconBtn">');function Z({language:e,value:n,handleDelete:t,onChange:s}){const{t:i}=A(e);let l;return x((()=>{l?.focus()})),(()=>{var u=Y(),o=u.firstChild,d=o.nextSibling;o.$$input=a=>s(a.currentTarget.value);var r=l;return typeof r=="function"?b(r,o):l=o,k(d,"click",t,!0),h((()=>w(o,"placeholder",i("ListField.placeholder")))),h((()=>o.value=n())),u})()}v(["input","click"]);var q=p("<ul class=LFList>"),ee=p("<div class=LFList-empty>"),te=p("<li class=LFListItem>");function ne(e){const{t:n}=A(e.language);let t;return(()=>{var s=q(),i=t;return typeof i=="function"?b(i,s):t=s,m(s,L(O,{get each(){return e.values()},get fallback(){return(()=>{var l=ee();return m(l,(()=>n("ListField.emptyList"))),l})()},children:(l,u)=>(()=>{var o=te();return m(o,L(Z,{onChange:d=>{e.updateValue(u,d)},value:l,get language(){return e.language},handleDelete:()=>e.handleDelete(u)})),o})()})),s})()}var se=p('<div class=LFApp><button type=button class="pi pi-plus LFIconBtn LFApp-addItemBtn">');function ie(e){const{language:n,list:t,setList:s,itemIndexes:i}=e,l=()=>{s([...t(),""],[...i(),i().length])},u=r=>{const a=[...t()];a.splice(r,1);const c=[...i()];c.splice(r,1),s(a,c)},o=(r,a)=>{const c=[...t()];c[r]=a,s(c,i())},d=(r,a)=>{const c=[...i()];c.splice(a,0,c.splice(r,1)[0]),s(t(),c)};return(()=>{var r=se(),a=r.firstChild;return m(r,L(ne,{changeOrder:d,updateValue:o,handleDelete:u,language:n,values:t}),a),a.$$click=l,r})()}v(["click"]);const ae={create:oe,init:le};function le({pluginBaseUrl:e}){const n=`${e}/admin-ui-plugin.css`,t=document.createElement("link");t.rel="stylesheet",t.href=n,document.head.appendChild(t)}function oe(e){const{fieldType:n,initialValue:t}=e;if(n.dataType!=="json")throw new Error(`field type '${n.name}' is incompatible with list-field plugin, needs data type 'json'`);if(t!==void 0&&!_(t))throw new Error(`field type '${n.name}' is incompatible, should be a json, got '${typeof t}'`);const s=I(t);return P((i=>{const[l,u]=g(s),[o,d]=g($(s)),[r,a]=g(e.language);return{element:L(ie,{language:r,list:l,setList:(c,f)=>{u(c),d(f),e.setModifiedValue({j:c})},itemIndexes:o}),setLanguage:a,setValue:c=>{const f=I(c);u(f),d($(f))},getValue:()=>({j:l}),dispose:i}}))}function $(e){return e.map(((n,t)=>t))}function I(e){return _(e)&&Array.isArray(e.j)?e.j:[]}export{ae as default};
1
+ function ht(r){return typeof r=="object"&&r!==null&&"j"in r}const _t={en:{en:"English",fr:"French",es:"Spanish",de:"German",it:"Italian",pt:"Portuguese"},fr:{en:"Anglais",fr:"Français",es:"Espagnol",de:"Allemand",it:"Italien",pt:"Portugais"},es:{en:"Inglés",fr:"Francés",es:"Español",de:"Alemán",it:"Italiano",pt:"Portugués"},de:{en:"Englisch",fr:"Französisch",es:"Spanisch",de:"Deutsch",it:"Italienisch",pt:"Portugiesisch"},it:{en:"Inglese",fr:"Francese",es:"Spagnolo",de:"Tedesco",it:"Italiano",pt:"Portoghese"},pt:{en:"Inglês",fr:"Francês",es:"Espanhol",de:"Alemão",it:"Italiano",pt:"Português"}},K=Object.keys(_t);function vt(r,{pluginLanguages:t,siteLanguages:e=[]}){if(t.includes(r)||K.includes(r)&&t.includes(r))return r;const s=e.find(i=>K.includes(i)&&t.includes(i));return s||(t.includes("en")?"en":t[0]??"en")}
2
+ /**
3
+ * @license
4
+ * Copyright 2019 Google LLC
5
+ * SPDX-License-Identifier: BSD-3-Clause
6
+ */const H=globalThis,D=H.ShadowRoot&&(H.ShadyCSS===void 0||H.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,z=Symbol(),J=new WeakMap;let dt=class{constructor(t,e,s){if(this._$cssResult$=!0,s!==z)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(D&&t===void 0){const s=e!==void 0&&e.length===1;s&&(t=J.get(e)),t===void 0&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),s&&J.set(e,t))}return t}toString(){return this.cssText}};const yt=r=>new dt(typeof r=="string"?r:r+"",void 0,z),ct=(r,...t)=>{const e=r.length===1?r[0]:t.reduce((s,i,n)=>s+(o=>{if(o._$cssResult$===!0)return o.cssText;if(typeof o=="number")return o;throw Error("Value passed to 'css' function must be a 'css' function result: "+o+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+r[n+1],r[0]);return new dt(e,r,z)},At=(r,t)=>{if(D)r.adoptedStyleSheets=t.map(e=>e instanceof CSSStyleSheet?e:e.styleSheet);else for(const e of t){const s=document.createElement("style"),i=H.litNonce;i!==void 0&&s.setAttribute("nonce",i),s.textContent=e.cssText,r.appendChild(s)}},Z=D?r=>r:r=>r instanceof CSSStyleSheet?(t=>{let e="";for(const s of t.cssRules)e+=s.cssText;return yt(e)})(r):r;
7
+ /**
8
+ * @license
9
+ * Copyright 2017 Google LLC
10
+ * SPDX-License-Identifier: BSD-3-Clause
11
+ */const{is:bt,defineProperty:Et,getOwnPropertyDescriptor:xt,getOwnPropertyNames:St,getOwnPropertySymbols:wt,getPrototypeOf:Ct}=Object,k=globalThis,G=k.trustedTypes,Pt=G?G.emptyScript:"",Ut=k.reactiveElementPolyfillSupport,L=(r,t)=>r,j={toAttribute(r,t){switch(t){case Boolean:r=r?Pt:null;break;case Object:case Array:r=r==null?r:JSON.stringify(r)}return r},fromAttribute(r,t){let e=r;switch(t){case Boolean:e=r!==null;break;case Number:e=r===null?null:Number(r);break;case Object:case Array:try{e=JSON.parse(r)}catch{e=null}}return e}},pt=(r,t)=>!bt(r,t),Q={attribute:!0,type:String,converter:j,reflect:!1,useDefault:!1,hasChanged:pt};Symbol.metadata??=Symbol("metadata"),k.litPropertyMetadata??=new WeakMap;let x=class extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,e=Q){if(e.state&&(e.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(t)&&((e=Object.create(e)).wrapped=!0),this.elementProperties.set(t,e),!e.noAccessor){const s=Symbol(),i=this.getPropertyDescriptor(t,s,e);i!==void 0&&Et(this.prototype,t,i)}}static getPropertyDescriptor(t,e,s){const{get:i,set:n}=xt(this.prototype,t)??{get(){return this[e]},set(o){this[e]=o}};return{get:i,set(o){const a=i?.call(this);n?.call(this,o),this.requestUpdate(t,a,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??Q}static _$Ei(){if(this.hasOwnProperty(L("elementProperties")))return;const t=Ct(this);t.finalize(),t.l!==void 0&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(L("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(L("properties"))){const e=this.properties,s=[...St(e),...wt(e)];for(const i of s)this.createProperty(i,e[i])}const t=this[Symbol.metadata];if(t!==null){const e=litPropertyMetadata.get(t);if(e!==void 0)for(const[s,i]of e)this.elementProperties.set(s,i)}this._$Eh=new Map;for(const[e,s]of this.elementProperties){const i=this._$Eu(e,s);i!==void 0&&this._$Eh.set(i,e)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const s=new Set(t.flat(1/0).reverse());for(const i of s)e.unshift(Z(i))}else t!==void 0&&e.push(Z(t));return e}static _$Eu(t,e){const s=e.attribute;return s===!1?void 0:typeof s=="string"?s:typeof t=="string"?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise(t=>this.enableUpdating=t),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach(t=>t(this))}addController(t){(this._$EO??=new Set).add(t),this.renderRoot!==void 0&&this.isConnected&&t.hostConnected?.()}removeController(t){this._$EO?.delete(t)}_$E_(){const t=new Map,e=this.constructor.elementProperties;for(const s of e.keys())this.hasOwnProperty(s)&&(t.set(s,this[s]),delete this[s]);t.size>0&&(this._$Ep=t)}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return At(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach(t=>t.hostConnected?.())}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach(t=>t.hostDisconnected?.())}attributeChangedCallback(t,e,s){this._$AK(t,s)}_$ET(t,e){const s=this.constructor.elementProperties.get(t),i=this.constructor._$Eu(t,s);if(i!==void 0&&s.reflect===!0){const n=(s.converter?.toAttribute!==void 0?s.converter:j).toAttribute(e,s.type);this._$Em=t,n==null?this.removeAttribute(i):this.setAttribute(i,n),this._$Em=null}}_$AK(t,e){const s=this.constructor,i=s._$Eh.get(t);if(i!==void 0&&this._$Em!==i){const n=s.getPropertyOptions(i),o=typeof n.converter=="function"?{fromAttribute:n.converter}:n.converter?.fromAttribute!==void 0?n.converter:j;this._$Em=i;const a=o.fromAttribute(e,n.type);this[i]=a??this._$Ej?.get(i)??a,this._$Em=null}}requestUpdate(t,e,s){if(t!==void 0){const i=this.constructor,n=this[t];if(s??=i.getPropertyOptions(t),!((s.hasChanged??pt)(n,e)||s.useDefault&&s.reflect&&n===this._$Ej?.get(t)&&!this.hasAttribute(i._$Eu(t,s))))return;this.C(t,e,s)}this.isUpdatePending===!1&&(this._$ES=this._$EP())}C(t,e,{useDefault:s,reflect:i,wrapped:n},o){s&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,o??e??this[t]),n!==!0||o!==void 0)||(this._$AL.has(t)||(this.hasUpdated||s||(e=void 0),this._$AL.set(t,e)),i===!0&&this._$Em!==t&&(this._$Eq??=new Set).add(t))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(e){Promise.reject(e)}const t=this.scheduleUpdate();return t!=null&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[i,n]of this._$Ep)this[i]=n;this._$Ep=void 0}const s=this.constructor.elementProperties;if(s.size>0)for(const[i,n]of s){const{wrapped:o}=n,a=this[i];o!==!0||this._$AL.has(i)||a===void 0||this.C(i,void 0,n,a)}}let t=!1;const e=this._$AL;try{t=this.shouldUpdate(e),t?(this.willUpdate(e),this._$EO?.forEach(s=>s.hostUpdate?.()),this.update(e)):this._$EM()}catch(s){throw t=!1,this._$EM(),s}t&&this._$AE(e)}willUpdate(t){}_$AE(t){this._$EO?.forEach(e=>e.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return!0}update(t){this._$Eq&&=this._$Eq.forEach(e=>this._$ET(e,this[e])),this._$EM()}updated(t){}firstUpdated(t){}};x.elementStyles=[],x.shadowRootOptions={mode:"open"},x[L("elementProperties")]=new Map,x[L("finalized")]=new Map,Ut?.({ReactiveElement:x}),(k.reactiveElementVersions??=[]).push("2.1.1");
12
+ /**
13
+ * @license
14
+ * Copyright 2017 Google LLC
15
+ * SPDX-License-Identifier: BSD-3-Clause
16
+ */const q=globalThis,O=q.trustedTypes,X=O?O.createPolicy("lit-html",{createHTML:r=>r}):void 0,ut="$lit$",g=`lit$${Math.random().toFixed(9).slice(2)}$`,ft="?"+g,Lt=`<${ft}>`,b=document,I=()=>b.createComment(""),M=r=>r===null||typeof r!="object"&&typeof r!="function",V=Array.isArray,It=r=>V(r)||typeof r?.[Symbol.iterator]=="function",B=`[ \t\n\f\r]`,P=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,tt=/-->/g,et=/>/g,_=RegExp(`>|${B}(?:([^\\s"'>=/]+)(${B}*=${B}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),st=/'/g,it=/"/g,$t=/^(?:script|style|textarea|title)$/i,Mt=r=>(t,...e)=>({_$litType$:r,strings:t,values:e}),y=Mt(1),E=Symbol.for("lit-noChange"),$=Symbol.for("lit-nothing"),rt=new WeakMap,A=b.createTreeWalker(b,129);function mt(r,t){if(!V(r)||!r.hasOwnProperty("raw"))throw Error("invalid template strings array");return X!==void 0?X.createHTML(t):t}const Tt=(r,t)=>{const e=r.length-1,s=[];let i,n=t===2?"<svg>":t===3?"<math>":"",o=P;for(let a=0;a<e;a++){const l=r[a];let d,u,h=-1,p=0;for(;p<l.length&&(o.lastIndex=p,u=o.exec(l),u!==null);)p=o.lastIndex,o===P?u[1]==="!--"?o=tt:u[1]!==void 0?o=et:u[2]!==void 0?($t.test(u[2])&&(i=RegExp("</"+u[2],"g")),o=_):u[3]!==void 0&&(o=_):o===_?u[0]===">"?(o=i??P,h=-1):u[1]===void 0?h=-2:(h=o.lastIndex-u[2].length,d=u[1],o=u[3]===void 0?_:u[3]==='"'?it:st):o===it||o===st?o=_:o===tt||o===et?o=P:(o=_,i=void 0);const c=o===_&&r[a+1].startsWith("/>")?" ":"";n+=o===P?l+Lt:h>=0?(s.push(d),l.slice(0,h)+ut+l.slice(h)+g+c):l+g+(h===-2?a:c)}return[mt(r,n+(r[e]||"<?>")+(t===2?"</svg>":t===3?"</math>":"")),s]};class T{constructor({strings:t,_$litType$:e},s){let i;this.parts=[];let n=0,o=0;const a=t.length-1,l=this.parts,[d,u]=Tt(t,e);if(this.el=T.createElement(d,s),A.currentNode=this.el.content,e===2||e===3){const h=this.el.content.firstChild;h.replaceWith(...h.childNodes)}for(;(i=A.nextNode())!==null&&l.length<a;){if(i.nodeType===1){if(i.hasAttributes())for(const h of i.getAttributeNames())if(h.endsWith(ut)){const p=u[o++],c=i.getAttribute(h).split(g),f=/([.?@])?(.*)/.exec(p);l.push({type:1,index:n,name:f[2],strings:c,ctor:f[1]==="."?Ot:f[1]==="?"?kt:f[1]==="@"?Rt:R}),i.removeAttribute(h)}else h.startsWith(g)&&(l.push({type:6,index:n}),i.removeAttribute(h));if($t.test(i.tagName)){const h=i.textContent.split(g),p=h.length-1;if(p>0){i.textContent=O?O.emptyScript:"";for(let c=0;c<p;c++)i.append(h[c],I()),A.nextNode(),l.push({type:2,index:++n});i.append(h[p],I())}}}else if(i.nodeType===8)if(i.data===ft)l.push({type:2,index:n});else{let h=-1;for(;(h=i.data.indexOf(g,h+1))!==-1;)l.push({type:7,index:n}),h+=g.length-1}n++}}static createElement(t,e){const s=b.createElement("template");return s.innerHTML=t,s}}function w(r,t,e=r,s){if(t===E)return t;let i=s!==void 0?e._$Co?.[s]:e._$Cl;const n=M(t)?void 0:t._$litDirective$;return i?.constructor!==n&&(i?._$AO?.(!1),n===void 0?i=void 0:(i=new n(r),i._$AT(r,e,s)),s!==void 0?(e._$Co??=[])[s]=i:e._$Cl=i),i!==void 0&&(t=w(r,i._$AS(r,t.values),i,s)),t}let Ht=class{constructor(t,e){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:e},parts:s}=this._$AD,i=(t?.creationScope??b).importNode(e,!0);A.currentNode=i;let n=A.nextNode(),o=0,a=0,l=s[0];for(;l!==void 0;){if(o===l.index){let d;l.type===2?d=new C(n,n.nextSibling,this,t):l.type===1?d=new l.ctor(n,l.name,l.strings,this,t):l.type===6&&(d=new Nt(n,this,t)),this._$AV.push(d),l=s[++a]}o!==l?.index&&(n=A.nextNode(),o++)}return A.currentNode=b,i}p(t){let e=0;for(const s of this._$AV)s!==void 0&&(s.strings!==void 0?(s._$AI(t,s,e),e+=s.strings.length-2):s._$AI(t[e])),e++}};class C{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,e,s,i){this.type=2,this._$AH=$,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=s,this.options=i,this._$Cv=i?.isConnected??!0}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return e!==void 0&&t?.nodeType===11&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=w(this,t,e),M(t)?t===$||t==null||t===""?(this._$AH!==$&&this._$AR(),this._$AH=$):t!==this._$AH&&t!==E&&this._(t):t._$litType$!==void 0?this.$(t):t.nodeType!==void 0?this.T(t):It(t)?this.k(t):this._(t)}O(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t))}_(t){this._$AH!==$&&M(this._$AH)?this._$AA.nextSibling.data=t:this.T(b.createTextNode(t)),this._$AH=t}$(t){const{values:e,_$litType$:s}=t,i=typeof s=="number"?this._$AC(t):(s.el===void 0&&(s.el=T.createElement(mt(s.h,s.h[0]),this.options)),s);if(this._$AH?._$AD===i)this._$AH.p(e);else{const n=new Ht(i,this),o=n.u(this.options);n.p(e),this.T(o),this._$AH=n}}_$AC(t){let e=rt.get(t.strings);return e===void 0&&rt.set(t.strings,e=new T(t)),e}k(t){V(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let s,i=0;for(const n of t)i===e.length?e.push(s=new C(this.O(I()),this.O(I()),this,this.options)):s=e[i],s._$AI(n),i++;i<e.length&&(this._$AR(s&&s._$AB.nextSibling,i),e.length=i)}_$AR(t=this._$AA.nextSibling,e){for(this._$AP?.(!1,!0,e);t!==this._$AB;){const s=t.nextSibling;t.remove(),t=s}}setConnected(t){this._$AM===void 0&&(this._$Cv=t,this._$AP?.(t))}}class R{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,e,s,i,n){this.type=1,this._$AH=$,this._$AN=void 0,this.element=t,this.name=e,this._$AM=i,this.options=n,s.length>2||s[0]!==""||s[1]!==""?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=$}_$AI(t,e=this,s,i){const n=this.strings;let o=!1;if(n===void 0)t=w(this,t,e,0),o=!M(t)||t!==this._$AH&&t!==E,o&&(this._$AH=t);else{const a=t;let l,d;for(t=n[0],l=0;l<n.length-1;l++)d=w(this,a[s+l],e,l),d===E&&(d=this._$AH[l]),o||=!M(d)||d!==this._$AH[l],d===$?t=$:t!==$&&(t+=(d??"")+n[l+1]),this._$AH[l]=d}o&&!i&&this.j(t)}j(t){t===$?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}}class Ot extends R{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===$?void 0:t}}class kt extends R{constructor(){super(...arguments),this.type=4}j(t){this.element.toggleAttribute(this.name,!!t&&t!==$)}}class Rt extends R{constructor(t,e,s,i,n){super(t,e,s,i,n),this.type=5}_$AI(t,e=this){if((t=w(this,t,e,0)??$)===E)return;const s=this._$AH,i=t===$&&s!==$||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,n=t!==$&&(s===$||i);i&&this.element.removeEventListener(this.name,this,s),n&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){typeof this._$AH=="function"?this._$AH.call(this.options?.host??this.element,t):this._$AH.handleEvent(t)}}class Nt{constructor(t,e,s){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=s}get _$AU(){return this._$AM._$AU}_$AI(t){w(this,t)}}const Bt={I:C},Ft=q.litHtmlPolyfillSupport;Ft?.(T,C),(q.litHtmlVersions??=[]).push("3.3.1");const jt=(r,t,e)=>{const s=e?.renderBefore??t;let i=s._$litPart$;if(i===void 0){const n=e?.renderBefore??null;s._$litPart$=i=new C(t.insertBefore(I(),n),n,void 0,e??{})}return i._$AI(r),i};
17
+ /**
18
+ * @license
19
+ * Copyright 2017 Google LLC
20
+ * SPDX-License-Identifier: BSD-3-Clause
21
+ */const W=globalThis;let S=class extends x{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=jt(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return E}};S._$litElement$=!0,S.finalized=!0,W.litElementHydrateSupport?.({LitElement:S});const Dt=W.litElementPolyfillSupport;Dt?.({LitElement:S});(W.litElementVersions??=[]).push("4.2.1");
22
+ /**
23
+ * @license
24
+ * Copyright 2017 Google LLC
25
+ * SPDX-License-Identifier: BSD-3-Clause
26
+ */const zt={CHILD:2},qt=r=>(...t)=>({_$litDirective$:r,values:t});class Vt{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,s){this._$Ct=t,this._$AM=e,this._$Ci=s}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}}
27
+ /**
28
+ * @license
29
+ * Copyright 2020 Google LLC
30
+ * SPDX-License-Identifier: BSD-3-Clause
31
+ */const{I:Wt}=Bt,nt=()=>document.createComment(""),U=(r,t,e)=>{const s=r._$AA.parentNode,i=t===void 0?r._$AB:t._$AA;if(e===void 0){const n=s.insertBefore(nt(),i),o=s.insertBefore(nt(),i);e=new Wt(n,o,r,r.options)}else{const n=e._$AB.nextSibling,o=e._$AM,a=o!==r;if(a){let l;e._$AQ?.(r),e._$AM=r,e._$AP!==void 0&&(l=r._$AU)!==o._$AU&&e._$AP(l)}if(n!==i||a){let l=e._$AA;for(;l!==n;){const d=l.nextSibling;s.insertBefore(l,i),l=d}}}return e},v=(r,t,e=r)=>(r._$AI(t,e),r),Yt={},Kt=(r,t=Yt)=>r._$AH=t,Jt=r=>r._$AH,F=r=>{r._$AR(),r._$AA.remove()};
32
+ /**
33
+ * @license
34
+ * Copyright 2017 Google LLC
35
+ * SPDX-License-Identifier: BSD-3-Clause
36
+ */const ot=(r,t,e)=>{const s=new Map;for(let i=t;i<=e;i++)s.set(r[i],i);return s},Zt=qt(class extends Vt{constructor(r){if(super(r),r.type!==zt.CHILD)throw Error("repeat() can only be used in text expressions")}dt(r,t,e){let s;e===void 0?e=t:t!==void 0&&(s=t);const i=[],n=[];let o=0;for(const a of r)i[o]=s?s(a,o):o,n[o]=e(a,o),o++;return{values:n,keys:i}}render(r,t,e){return this.dt(r,t,e).values}update(r,[t,e,s]){const i=Jt(r),{values:n,keys:o}=this.dt(t,e,s);if(!Array.isArray(i))return this.ut=o,n;const a=this.ut??=[],l=[];let d,u,h=0,p=i.length-1,c=0,f=n.length-1;for(;h<=p&&c<=f;)if(i[h]===null)h++;else if(i[p]===null)p--;else if(a[h]===o[c])l[c]=v(i[h],n[c]),h++,c++;else if(a[p]===o[f])l[f]=v(i[p],n[f]),p--,f--;else if(a[h]===o[f])l[f]=v(i[h],n[f]),U(r,l[f+1],i[h]),h++,f--;else if(a[p]===o[c])l[c]=v(i[p],n[c]),U(r,i[h],i[p]),p--,c++;else if(d===void 0&&(d=ot(o,c,f),u=ot(a,h,p)),d.has(a[h]))if(d.has(a[p])){const m=u.get(o[c]),N=m!==void 0?i[m]:null;if(N===null){const Y=U(r,i[h]);v(Y,n[c]),l[c]=Y}else l[c]=v(N,n[c]),U(r,i[h],N),i[m]=null;c++}else F(i[p]),p--;else F(i[h]),h++;for(;c<=f;){const m=U(r,l[f+1]);v(m,n[c]),l[c++]=m}for(;h<=p;){const m=i[h++];m!==null&&F(m)}return this.ut=o,Kt(r,l),E}}),Gt={placeholder:"Bearbeiten…",emptyList:"Keine Elemente gefunden"},Qt={ListField:Gt},Xt={placeholder:"Edit…",emptyList:"No items found"},te={ListField:Xt},ee={placeholder:"Editar…",emptyList:"Lista vacía"},se={ListField:ee},ie={placeholder:"Éditer…",emptyList:"Liste vide"},re={ListField:ie},ne={placeholder:"Modifica…",emptyList:"Nessun elemento trovato"},oe={ListField:ne},le={placeholder:"Editar…",emptyList:"Nenhum item encontrado"},ae={ListField:le},lt={en:te,fr:re,es:se,de:Qt,it:oe,pt:ae};class he{_ctx;constructor(t){this._ctx={language:"",dict:{}},this.setLanguage(t)}setLanguage(t,e){const s=Object.keys(lt),i=vt(t,{pluginLanguages:s,siteLanguages:e}),n=i,o={};gt(lt[n],"",o),this._ctx={language:i,dict:o}}t(t){return this._ctx.dict[t]??t}}function gt(r,t,e){for(const s in r){const i=r[s],n=t?`${t}.${s}`:s;i&&typeof i=="object"&&!Array.isArray(i)?gt(i,n,e):typeof i=="string"&&(e[n]=i)}}class de extends S{static properties={value:{type:String},placeholder:{type:String},disabled:{type:Boolean,reflect:!0}};static styles=ct`
37
+ :host { display: contents; }
38
+ input { flex: 1; border: none; outline: none; font: inherit; background: transparent; }
39
+ `;value="";placeholder="";disabled=!1;focus(){this.renderRoot.querySelector("input")?.focus()}render(){return y`<input
40
+ class="input"
41
+ .value=${this.value}
42
+ ?disabled=${this.disabled}
43
+ @input=${this.#t}
44
+ placeholder=${this.placeholder}
45
+ aria-disabled=${this.disabled?"true":"false"}
46
+ tabindex=${this.disabled?-1:0}
47
+ />`}#t(t){if(!t.currentTarget||this.disabled)return;const e=t.currentTarget.value;this.value=e,this.dispatchEvent(new CustomEvent("value-changed",{detail:{value:e},bubbles:!0,composed:!0}))}}customElements.define("pcms-list-field-item-text",de);class ce extends S{static properties={language:{type:String}};static styles=ct`
48
+ :host {
49
+ display: block;
50
+ font: inherit;
51
+ --pcms-lf-gap: 0.5rem;
52
+ --pcms-lf-border-color: #d0d7de;
53
+ --pcms-lf-border-radius: 4px;
54
+ --pcms-lf-handle-color: #666;
55
+ --pcms-lf-handle-color-hover: #111;
56
+ --pcms-lf-item-bg: #fff;
57
+ --pcms-lf-item-bg-drag: #f5f7fa;
58
+ }
59
+ .root { display: flex; flex-direction: column; gap: var(--pcms-lf-gap); }
60
+ .list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--pcms-lf-gap); }
61
+ .item { display: flex; align-items: stretch; gap: 0.25rem; background: var(--pcms-lf-item-bg); border: 1px solid var(--pcms-lf-border-color); border-radius: var(--pcms-lf-border-radius); padding: 0.25rem 0.5rem; position: relative; min-height: 2.25rem; box-sizing: border-box; }
62
+ .item.dragging { background: var(--pcms-lf-item-bg-drag); box-shadow: 0 2px 6px rgba(0,0,0,0.15); z-index: 10; }
63
+ .item.source-collapsed { height: 0 !important; padding: 0 !important; border: 0 !important; margin: 0 !important; min-height: 0 !important; overflow: hidden; }
64
+ .drag-ghost { position: fixed; pointer-events: none; box-sizing: border-box; background: var(--pcms-lf-item-bg-drag); border: 1px solid var(--pcms-lf-border-color); border-radius: var(--pcms-lf-border-radius); padding: 0.25rem 0.5rem; display: flex; gap: 0.25rem; align-items: stretch; box-shadow: 0 4px 10px rgba(0,0,0,0.2); opacity: 0.95; }
65
+ .handle { cursor: grab; display: flex; align-items: center; padding: 0 0.25rem; user-select: none; color: var(--pcms-lf-handle-color); }
66
+ .handle:active { cursor: grabbing; }
67
+ .handle:hover { color: var(--pcms-lf-handle-color-hover); }
68
+ .input { flex: 1; border: none; outline: none; font: inherit; background: transparent; }
69
+ .deleteBtn, .addBtn { border: 1px solid var(--pcms-lf-border-color); background: #fafbfc; border-radius: var(--pcms-lf-border-radius); cursor: pointer; width: 2rem; height: 2rem; display: flex; align-items: center; justify-content: center; font-size: 0.85rem; }
70
+ .deleteBtn:hover { background: #ffeaea; }
71
+ .addBtn { align-self: flex-start; }
72
+ .empty { font-size: 0.85rem; color: #777; padding: 0.25rem 0.5rem; }
73
+ .placeholder { height: 2.25rem; border: 1px dashed var(--pcms-lf-border-color); border-radius: var(--pcms-lf-border-radius); }
74
+ `;#t=[];#a=0;get items(){return this.#t.map(t=>t.value)}set items(t){const e=Array.isArray(t)?t:[],s=[];for(let i=0;i<e.length;++i){const n=this.#t[i];s.push({id:n?.id??String(this.#a++),value:String(e[i])})}this.#t=s,this.requestUpdate("items")}language="en";#e;#s;#r=0;#n=new he("en");#h=0;#d=0;#i=null;#o;willUpdate(){this.#n.setLanguage(this.language)}render(){return y`<div class="root">
75
+ <ul class="list">
76
+ ${this.items.length?this.#f():y`<div class="empty">${this.#n.t("ListField.emptyList")}</div>`}
77
+ </ul>
78
+ <button type="button" class="addBtn" @click=${()=>this.#u()} aria-label="add">+</button>
79
+ </div>`}destroy(){}async#u(){this.#t=[...this.#t,{id:String(this.#a++),value:""}],this.requestUpdate("items"),this.#l(),await this.updateComplete;const t=this.renderRoot.querySelectorAll("pcms-list-field-item-text");t[t.length-1]?.focus?.()}#l(){this.dispatchEvent(new CustomEvent("items-changed",{detail:{items:[...this.items]},bubbles:!0,composed:!0}))}#f(){const t=this.#e,e=this.#s,s=this.#t,i=Zt(s,a=>a.id,(a,l)=>{const d=l===t,u=d&&e!==void 0&&e!==t,h=d&&!u?`transform: translateY(${this.#r}px);`:"";return y`
80
+ ${t!==void 0&&e!==void 0&&e===l&&e!==t?y`<li class="placeholder" data-placeholder="true"></li>`:null}
81
+ <li
82
+ class="item ${d?"dragging":""} ${u?"source-collapsed":""}"
83
+ style=${h}
84
+ aria-grabbed=${d?"true":"false"}
85
+ data-entry-id=${a.id}
86
+ >
87
+ <button
88
+ type="button"
89
+ class="handle"
90
+ @pointerdown=${c=>this.#g(c,l)}
91
+ title="move"
92
+ aria-label="move"
93
+ tabindex="-1"
94
+ >⇳</button>
95
+ <pcms-list-field-item-text
96
+ .value=${a.value}
97
+ .placeholder=${this.#n.t("ListField.placeholder")}
98
+ @value-changed=${c=>this.#$(a.id,c.detail.value)}
99
+ ></pcms-list-field-item-text>
100
+ <button
101
+ type="button"
102
+ class="deleteBtn"
103
+ @click=${()=>this.#m(l)}
104
+ aria-label="delete"
105
+ >🗑</button>
106
+ </li>`}),n=t!==void 0&&e!==void 0&&e===s.length&&e!==t?y`<li class="placeholder" data-placeholder="true"></li>`:null,o=t!==void 0&&this.#i&&e!==void 0&&e!==t?(()=>{const a=this.#i;if(!a)return null;const l=a.top+this.#r;return y`<div class="drag-ghost" style=${`top:${l}px;left:${a.left}px;width:${a.width}px;`}>
107
+ <button type="button" class="handle" title="move" aria-label="move" tabindex="-1">⇳</button>
108
+ <pcms-list-field-item-text .value=${this.#t[t].value} .placeholder=${this.#n.t("ListField.placeholder")} disabled aria-hidden="true"></pcms-list-field-item-text>
109
+ <button type="button" class="deleteBtn" aria-hidden="true" tabindex="-1">🗑</button>
110
+ </div>`})():null;return[i,n,o]}#$(t,e){const s=this.#t.findIndex(o=>o.id===t);if(s===-1)return;const i=e.trim();if(this.#t[s].value===i)return;const n=[...this.#t];n[s]={...n[s],value:i},this.#t=n,this.requestUpdate("items"),this.#l()}async#m(t){const e=[...this.#t];e.splice(t,1),this.#t=e,this.requestUpdate("items"),this.#l(),await this.updateComplete;const s=this.renderRoot.querySelectorAll("pcms-list-field-item-text");if(!s.length)return;const i=Math.min(t,s.length-1);s[i]?.focus?.()}#g(t,e){const s=t.currentTarget;this.#o=s,this.#e=e,this.#s=void 0,this.#d=t.clientY;const i=s.closest("li.item")||void 0;if(i){const n=i.getBoundingClientRect();this.#i={top:n.top,left:n.left,width:n.width,height:n.height}}else this.#i=null;s.setPointerCapture(t.pointerId),s.addEventListener("pointermove",this.#c),s.addEventListener("pointerup",this.#p,{once:!0}),s.addEventListener("pointercancel",this.#v,{once:!0})}#c=t=>{if(this.#e===void 0)return;const e=t.clientY-this.#d;this.#r=e,cancelAnimationFrame(this.#h),this.#h=requestAnimationFrame(()=>{this.#_(t.clientY),this.requestUpdate()})};#_(t){if(this.#e===void 0)return;const e=this.renderRoot.querySelector("ul.list");if(!e)return;const s=Array.from(e.querySelectorAll("li.item")),i=this.#e;if(!s[i])return;const n=[];for(let d=0;d<s.length;++d)d!==i&&n.push({el:s[d],fullIndex:d});let o=n.length;for(let d=0;d<n.length;++d){const{el:u}=n[d],h=u.getBoundingClientRect(),p=h.top+h.height/2;if(t<p){o=d;break}}let a;o===n.length?a=s.length:a=n[o].fullIndex;let l=a;i<a&&(l=a-1),l===i?this.#s=void 0:this.#s=a}#p=()=>{if(this.#e===void 0)return;const t=this.#e,e=this.#s;if(e!==void 0){let s=e;if(t<e&&(s=e-1),s<0&&(s=0),t!==s){const i=[...this.#t],[n]=i.splice(t,1);i.splice(s,0,n),this.#t=i,this.requestUpdate("items"),this.#l()}}this.#e=void 0,this.#s=void 0,this.#r=0,this.#i=null,this.#o&&(this.#o.removeEventListener("pointermove",this.#c),this.#o=void 0),this.requestUpdate()};#v=()=>{this.#p()}}customElements.define("pcms-list-field",ce);const _e={create:ue,init:pe};function pe({pluginBaseUrl:r}){const t=`${r}/admin-ui-plugin.css`,e=document.createElement("link");e.rel="stylesheet",e.href=t,document.head.appendChild(e)}function ue(r){const{fieldType:t,initialValue:e}=r;if(t.dataType!=="json")throw new Error(`field type '${t.name}' is incompatible with list-field plugin, needs data type 'json'`);if(e!==void 0&&!ht(e))throw new Error(`field type '${t.name}' is incompatible, should be a json, got '${typeof e}'`);const s=document.createElement("pcms-list-field");return s.items=at(e),s.language=r.language,s.addEventListener("items-changed",i=>{const n=i.detail;r.setModifiedValue({j:n.items})}),{element:s,setLanguage:i=>{s.language=i},setValue:i=>{s.items=at(i)},getValue:()=>({j:[...s.items]}),dispose:()=>s.destroy()}}function at(r){return ht(r)&&Array.isArray(r.j)?r.j.map(t=>String(t)):[]}export{_e as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paroicms/list-field-plugin",
3
- "version": "0.26.1",
3
+ "version": "0.28.0",
4
4
  "description": "List field plugin for ParoiCMS",
5
5
  "keywords": [
6
6
  "paroicms",
@@ -25,7 +25,7 @@
25
25
  "clear": "rimraf backend/dist/* admin-ui-plugin/dist/*"
26
26
  },
27
27
  "dependencies": {
28
- "@paroicms/script-lib": "0.3.1",
28
+ "@paroicms/script-lib": "0.3.2",
29
29
  "arktype": "~2.1.20"
30
30
  },
31
31
  "peerDependencies": {
@@ -33,8 +33,8 @@
33
33
  "@paroicms/public-server-lib": "0"
34
34
  },
35
35
  "devDependencies": {
36
- "@paroicms/public-anywhere-lib": "0.36.1",
37
- "@paroicms/public-server-lib": "0.46.1",
36
+ "@paroicms/public-anywhere-lib": "0.37.0",
37
+ "@paroicms/public-server-lib": "0.47.0",
38
38
  "@types/node": "~24.0.1",
39
39
  "rimraf": "~6.0.1",
40
40
  "typescript": "~5.9.2"
@@ -1,5 +1,5 @@
1
1
  {
2
- "ParoiCMSSiteSchemaFormatVersion": "9",
2
+ "ParoiCMSSiteSchemaFormatVersion": "10",
3
3
  "languages": ["en", "fr", "es", "de", "it", "pt"],
4
4
  "fieldTypes": [
5
5
  {