From b6e49ab6c6c0189d43d33d6a5f1d9e0e17fb848c Mon Sep 17 00:00:00 2001 From: Luca Stefano Sartori Date: Thu, 25 Apr 2019 01:45:46 +0200 Subject: [PATCH 1/2] Corrected yarn command --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cd33ef6..1276b84 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,12 @@ Manage your Symfony Form collection simply with vanilla JS ## Install ``` -yarn install @a2lix/symfony-collection or npm install @a2lix/symfony-collection +yarn add @a2lix/symfony-collection +``` +or +``` +npm install @a2lix/symfony-collection ``` - ## How to From 51c9f3a166bb9d140e5b69f7b37ad2203f8cd632 Mon Sep 17 00:00:00 2001 From: Luca Stefano Sartori Date: Thu, 25 Apr 2019 02:52:21 +0200 Subject: [PATCH 2/2] It is now possible to import --- README.md | 11 ++++++++++- dist/a2lix_sf_collection.min.js | 2 +- src/a2lix_sf_collection.js | 4 +++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1276b84..0d6f023 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ Manage your Symfony Form collection simply with vanilla JS ## Install +As first thing you need to pull the package using yarn or npm + ``` yarn add @a2lix/symfony-collection ``` @@ -15,9 +17,16 @@ or npm install @a2lix/symfony-collection ``` +Then you can either import it in your files using ES6 +``` +import a2lix_lib from '@a2lix/symfony-collection/src/a2lix_sf_collection'; +``` + +or symlink/copy/move it in a folder and reference it directly in a `script` tag + ## How to -After loading the dist version of **a2lix_sf_collection.min.js** file, init a2lix_lib.sfCollection, optionnaly with custom configuration. +After you loaded the dist version of **a2lix_sf_collection.min.js** file or imported through ES6 method, init a2lix_lib.sfCollection, optionnaly with custom configuration. Default configuration: diff --git a/dist/a2lix_sf_collection.min.js b/dist/a2lix_sf_collection.min.js index d1ad356..3eca8a6 100644 --- a/dist/a2lix_sf_collection.min.js +++ b/dist/a2lix_sf_collection.min.js @@ -1 +1 @@ -"use strict";const a2lix_lib={};a2lix_lib.sfCollection=(()=>{const t=(t={})=>{if(!("content"in document.createElement("template"))){console.error("HTML template will not working...");return}const{collectionsSelector:n="form div[data-prototype]",manageRemoveEntry:r=true}=t;const a=document.querySelectorAll(n);if(!a.length){return}a.forEach(t=>{e(t,r)})};const e=(t,e=false)=>{t.setAttribute("data-entry-index",t.children.length);n(t);if(e){r(t)}t.addEventListener("click",t=>a(t,e))};const n=t=>{const e=t.getAttribute("data-entry-label")||"";const n=i(`Add ${e}`,"add","btn btn-primary btn-sm mt-2");t.appendChild(n)};const r=t=>{const e=i("Remove","remove","btn btn-danger btn-sm");const n=[...t.children].filter(t=>!t.hasAttribute("data-entry-action")).forEach(t=>{t.appendChild(e.cloneNode(true))})};const a=(t,e)=>{if(!t.target.hasAttribute("data-entry-action")){return}switch(t.target.getAttribute("data-entry-action")){case"add":o(t.currentTarget,t.target,e);break;case"remove":c(t.currentTarget,t.target);break}};const o=(t,e,n)=>{const r=t.getAttribute("data-entry-index");t.setAttribute("data-entry-index",+r+1);const a=t.getAttribute("data-prototype"),o=s(a,r);if(n){const t=i("Remove","remove","btn btn-danger btn-sm");o.firstChild.appendChild(t)}e.parentElement.insertBefore(o,e)};const c=(t,e)=>{e.parentElement.remove()};const i=(t,e,n="btn")=>{const r=document.createElement("button");r.type="button";r.textContent=t;r.className=n;r.dataset.entryAction=e;return r};const s=(t,e)=>{const n=document.createElement("template");const r=t.replace(/__name__label__/g,`!New! ${e}`).replace(/__name__/g,e);n.innerHTML=r.trim();return n.content};return{init:t}})(); \ No newline at end of file +"use strict";const a2lix_lib={};a2lix_lib.sfCollection=(()=>{const t=(t={})=>{if(!("content"in document.createElement("template"))){console.error("HTML template will not working...");return}const{collectionsSelector:n="form div[data-prototype]",manageRemoveEntry:r=true}=t;const a=document.querySelectorAll(n);if(!a.length){return}a.forEach(t=>{e(t,r)})};const e=(t,e=false)=>{t.setAttribute("data-entry-index",t.children.length);n(t);if(e){r(t)}t.addEventListener("click",t=>a(t,e))};const n=t=>{const e=t.getAttribute("data-entry-label")||"";const n=i(`Add ${e}`,"add","btn btn-primary btn-sm mt-2");t.appendChild(n)};const r=t=>{const e=i("Remove","remove","btn btn-danger btn-sm");const n=[...t.children].filter(t=>!t.hasAttribute("data-entry-action")).forEach(t=>{t.appendChild(e.cloneNode(true))})};const a=(t,e)=>{if(!t.target.hasAttribute("data-entry-action")){return}switch(t.target.getAttribute("data-entry-action")){case"add":o(t.currentTarget,t.target,e);break;case"remove":c(t.currentTarget,t.target);break}};const o=(t,e,n)=>{const r=t.getAttribute("data-entry-index");t.setAttribute("data-entry-index",+r+1);const a=t.getAttribute("data-prototype"),o=l(a,r);if(n){const t=i("Remove","remove","btn btn-danger btn-sm");o.firstChild.appendChild(t)}e.parentElement.insertBefore(o,e)};const c=(t,e)=>{e.parentElement.remove()};const i=(t,e,n="btn")=>{const r=document.createElement("button");r.type="button";r.textContent=t;r.className=n;r.dataset.entryAction=e;return r};const l=(t,e)=>{const n=document.createElement("template");const r=t.replace(/__name__label__/g,`!New! ${e}`).replace(/__name__/g,e);n.innerHTML=r.trim();return n.content};return{init:t}})();export default a2lix_lib; \ No newline at end of file diff --git a/src/a2lix_sf_collection.js b/src/a2lix_sf_collection.js index cde0c1e..a99905b 100644 --- a/src/a2lix_sf_collection.js +++ b/src/a2lix_sf_collection.js @@ -137,4 +137,6 @@ a2lix_lib.sfCollection = (() => { return { init } -})() +})(); + +export default a2lix_lib;