From 824016d22d827c885dcb684c1ec02296d3e2bacd Mon Sep 17 00:00:00 2001 From: David ALLIX Date: Mon, 2 Jan 2023 13:01:20 +0100 Subject: [PATCH] Fix --- dist/a2lix_sf_collection.min.js | 2 +- package-lock.json | 4 ++-- package.json | 2 +- src/a2lix_sf_collection.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dist/a2lix_sf_collection.min.js b/dist/a2lix_sf_collection.min.js index 1582b6a..ecdadb7 100644 --- a/dist/a2lix_sf_collection.min.js +++ b/dist/a2lix_sf_collection.min.js @@ -1 +1 @@ -"use strict";const d={};d.sfCollection=(()=>{let m;(n=>(n.ADD="add",n.REMOVE="remove"))(m||={});const o={collectionsSelector:"div[data-prototype]",entry:{add:{enabled:!0,prototype:``,class:"btn btn-primary btn-sm mt-2",label:"Add",customFn:null,onBeforeFn:null,onAfterFn:null},remove:{enabled:!0,prototype:``,class:"btn btn-danger btn-sm mt-2",label:"Remove",customFn:null,onAfterFn:null}}},c=(e=o)=>{if(!("content"in document.createElement("template"))){console.error("HTML template will not working...");return}const t={...o,...e,entry:{add:{...o.entry.add,...e.entry?.add||{}},remove:{...o.entry.remove,...e.entry?.remove||{}}}};l(document.querySelectorAll(t.collectionsSelector),t)},l=(e,t)=>{e.length&&e.forEach(n=>{y(n,t)})},y=(e,t)=>{e.setAttribute("data-entry-index",e.children.length+""),(e.getAttribute("data-entry-add-enabled")??t.entry.add.enabled)&&u(e,t.entry.add),(e.getAttribute("data-entry-remove-enabled")??t.entry.remove.enabled)&&p(e,t.entry.remove),e.addEventListener("click",n=>b(n,t))},u=(e,t)=>{const n=(e.getAttribute("data-entry-add-prototype")??t.prototype).replace(/__class__/g,e.getAttribute("data-entry-add-class")??t.class).replace(/__label__/g,e.getAttribute("data-entry-add-label")??t.label);e.appendChild(a(n))},p=(e,t)=>{const n=i(e,t);Array.from(e.children).filter(r=>!r.hasAttribute("data-entry-action")).forEach(r=>{r.appendChild(n.cloneNode(!0))})},i=(e,t)=>{const n=(e.getAttribute("data-entry-remove-prototype")??t.prototype).replace(/__class__/g,e.getAttribute("data-entry-remove-class")??t.class).replace(/__label__/g,e.getAttribute("data-entry-remove-label")??t.label);return a(n)},b=(e,t)=>{if(!e.target.hasAttribute("data-entry-action"))return;e.preventDefault(),e.stopPropagation();const n=e.currentTarget.closest(t.collectionsSelector);switch(e.target.getAttribute("data-entry-action")){case"add":C(n,e.target,t);break;case"remove":E(n,e.target,t);break}},C=(e,t,n)=>{const r=g(e,n);if(n.entry.add.customFn){n.entry.add.customFn(e,t,r,n);return}_(e,t,r,n)},E=(e,t,n)=>{if(n.entry.remove.customFn){n.entry.remove.customFn(e,t,n);return}f(e,t,n)},g=(e,t)=>{const n=e.getAttribute("data-entry-index")??0;e.setAttribute("data-entry-index",+n+1+"");const r=e.getAttribute("data-prototype-name")??"__name__",A=e.getAttribute("data-prototype").replace(new RegExp(`${r}label__`,"g"),`!New! ${n}`).replace(new RegExp(r,"g"),n+""),s=a(A);return(e.getAttribute("data-entry-remove-enabled")??t.entry.remove.enabled)&&s.firstChild.appendChild(i(e,t.entry.remove)),s},_=(e,t,n,r)=>{r.entry.add.onBeforeFn?.(e,t,n),t.parentElement.insertBefore(n,t),l(t.previousSibling.querySelectorAll(r.collectionsSelector),r),r.entry.add.onAfterFn?.(e,t)},f=(e,t,n)=>{t.parentElement.remove(),n.entry.remove.onAfterFn?.(e,t)},a=e=>{const t=document.createElement("template");return t.innerHTML=e.trim(),t.content};return{init:c}})();export default d; +"use strict";const d={};d.sfCollection=(()=>{let m;(n=>(n.ADD="add",n.REMOVE="remove"))(m||={});const o={collectionsSelector:"div[data-prototype]",entry:{add:{enabled:!0,prototype:``,class:"btn btn-primary btn-sm mt-2",label:"Add",customFn:null,onBeforeFn:null,onAfterFn:null},remove:{enabled:!0,prototype:``,class:"btn btn-danger btn-sm mt-2",label:"Remove",customFn:null,onAfterFn:null}}},c=(e=o)=>{if(!("content"in document.createElement("template"))){console.error("HTML template will not working...");return}const t={...o,...e,entry:{add:{...o.entry.add,...e.entry?.add||{}},remove:{...o.entry.remove,...e.entry?.remove||{}}}};l(document.querySelectorAll(t.collectionsSelector),t)},l=(e,t)=>{e.length&&e.forEach(n=>{y(n,t)})},y=(e,t)=>{e.setAttribute("data-entry-index",e.children.length+""),(e.getAttribute("data-entry-add-enabled")??t.entry.add.enabled)&&u(e,t.entry.add),(e.getAttribute("data-entry-remove-enabled")??t.entry.remove.enabled)&&p(e,t.entry.remove),e.addEventListener("click",n=>b(n,t))},u=(e,t)=>{const n=(e.getAttribute("data-entry-add-prototype")??t.prototype).replace(/__class__/g,e.getAttribute("data-entry-add-class")??t.class).replace(/__label__/g,e.getAttribute("data-entry-add-label")??t.label);e.appendChild(a(n))},p=(e,t)=>{const n=i(e,t);Array.from(e.children).filter(r=>!r.hasAttribute("data-entry-action")).forEach(r=>{r.appendChild(n.cloneNode(!0))})},i=(e,t)=>{const n=(e.getAttribute("data-entry-remove-prototype")??t.prototype).replace(/__class__/g,e.getAttribute("data-entry-remove-class")??t.class).replace(/__label__/g,e.getAttribute("data-entry-remove-label")??t.label);return a(n)},b=(e,t)=>{if(!e.target.hasAttribute("data-entry-action"))return;e.preventDefault(),e.stopPropagation();const n=e.currentTarget.closest(t.collectionsSelector);switch(e.target.getAttribute("data-entry-action")){case"add":C(n,e.target,t);break;case"remove":E(n,e.target,t);break}},C=(e,t,n)=>{const r=g(e,n);if(n.entry.add.customFn){n.entry.add.customFn(e,t,r,n);return}_(e,t,r,n)},E=(e,t,n)=>{if(n.entry.remove.customFn){n.entry.remove.customFn(e,t,n);return}f(e,t,n)},g=(e,t)=>{const n=e.getAttribute("data-entry-index")??0;e.setAttribute("data-entry-index",+n+1+"");const r=e.getAttribute("data-prototype-name")??"__name__",A=e.getAttribute("data-prototype").replace(new RegExp(`${r}label__`,"g"),`!New! ${n}`).replace(new RegExp(r,"g"),n+""),s=a(A);return(e.getAttribute("data-entry-remove-enabled")??t.entry.remove.enabled)&&s.firstChild.appendChild(i(e,t.entry.remove)),s},_=(e,t,n,r)=>{r.entry.add.onBeforeFn?.(e,t,n),t.parentElement.insertBefore(n,t),l(t.previousElementSibling.querySelectorAll(r.collectionsSelector),r),r.entry.add.onAfterFn?.(e,t)},f=(e,t,n)=>{t.parentElement.remove(),n.entry.remove.onAfterFn?.(e,t)},a=e=>{const t=document.createElement("template");return t.innerHTML=e.trim(),t.content};return{init:c}})();export default d; diff --git a/package-lock.json b/package-lock.json index 50b45c6..9451ab6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@a2lix/symfony-collection", - "version": "0.6.0", + "version": "0.6.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@a2lix/symfony-collection", - "version": "0.6.0", + "version": "0.6.1", "license": "MIT", "devDependencies": { "esbuild": "^0.16.12", diff --git a/package.json b/package.json index 880a67a..4e16ce2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@a2lix/symfony-collection", - "version": "0.6.0", + "version": "0.6.1", "description": "Manage your Symfony Form collection simply with vanilla JS", "main": "src/a2lix_sf_collection.ts", "repository": { diff --git a/src/a2lix_sf_collection.ts b/src/a2lix_sf_collection.ts index aabf86d..54ebe4e 100644 --- a/src/a2lix_sf_collection.ts +++ b/src/a2lix_sf_collection.ts @@ -295,7 +295,7 @@ a2lix_lib.sfCollection = (() => { entryAddElt.parentElement!.insertBefore(templateContentEntry, entryAddElt) proceedCollectionElts( - (entryAddElt.previousSibling as Element).querySelectorAll( + entryAddElt.previousElementSibling!.querySelectorAll( cfg.collectionsSelector ), cfg