From 0abdc9dd61a0d37a950b2a09a32f3f9bcee2aae5 Mon Sep 17 00:00:00 2001 From: Niels Boogaard Date: Mon, 25 Nov 2019 13:47:30 +0100 Subject: [PATCH] Added check whether callback is specified, and published version 1.0.1 --- dist/filepond-plugin-manage-metadata.esm.js | 18 ++++++++++++------ ...filepond-plugin-manage-metadata.esm.min.js | 2 +- dist/filepond-plugin-manage-metadata.js | 19 +++++++++++++------ dist/filepond-plugin-manage-metadata.min.js | 2 +- index.html | 6 +----- package.json | 2 +- src/js/index.js | 6 +++++- 7 files changed, 34 insertions(+), 21 deletions(-) diff --git a/dist/filepond-plugin-manage-metadata.esm.js b/dist/filepond-plugin-manage-metadata.esm.js index 7487a73..25d2fb7 100644 --- a/dist/filepond-plugin-manage-metadata.esm.js +++ b/dist/filepond-plugin-manage-metadata.esm.js @@ -63,12 +63,18 @@ const plugin = fpAPI => { ); const onManageMetadata = root.query('GET_ON_MANAGE_METADATA'); - registerManageMetadataComponent( - item, - root.element, - labelButtonManageMetadata, - onManageMetadata - ); + if (onManageMetadata) { + registerManageMetadataComponent( + item, + root.element, + labelButtonManageMetadata, + onManageMetadata + ); + } else { + console.error( + "No 'onManageMetadata' callback method specified for FilePondPluginManageMetadata! See https://github.com/nielsboogaard/filepond-plugin-manage-metadata for more instructions." + ); + } }; // start writing diff --git a/dist/filepond-plugin-manage-metadata.esm.min.js b/dist/filepond-plugin-manage-metadata.esm.min.js index ecb4cfb..b4da821 100644 --- a/dist/filepond-plugin-manage-metadata.esm.min.js +++ b/dist/filepond-plugin-manage-metadata.esm.min.js @@ -6,4 +6,4 @@ /* eslint-disable */ -const e=e=>{let t=document.createElement("span");return t.className="filepond--edit-icon",t.title=e,t},t=t=>{const{addFilter:n,utils:o}=t,{Type:i,createRoute:d}=o;return n("CREATE_VIEW",t=>{const{is:n,view:o,query:i}=t;if(!n("file"))return;o.registerWriter(d({DID_LOAD_ITEM:({root:t,props:n})=>{const{id:o}=n,d=i("GET_ITEM",o);if(!d||d.archived)return;const r=t.query("GET_LABEL_BUTTON_MANAGE_METADATA"),a=t.query("GET_ON_MANAGE_METADATA");((t,n,o,i)=>{const d=n.querySelector(".filepond--file-info-main"),r=e(o);d.prepend(r),r.addEventListener("click",()=>i(t))})(d,t.element,r,a)}},({root:e,props:t})=>{const{id:n}=t;i("GET_ITEM",n);e.rect.element.hidden}))}),{options:{labelButtonManageMetadata:["Edit metadata",i.STRING],onManageMetadata:[null,i.FUNCTION]}}};"undefined"!=typeof window&&void 0!==window.document&&document.dispatchEvent(new CustomEvent("FilePond:pluginloaded",{detail:t}));export default t; +const e=e=>{let t=document.createElement("span");return t.className="filepond--edit-icon",t.title=e,t},t=t=>{const{addFilter:n,utils:o}=t,{Type:a,createRoute:i}=o;return n("CREATE_VIEW",t=>{const{is:n,view:o,query:a}=t;if(!n("file"))return;o.registerWriter(i({DID_LOAD_ITEM:({root:t,props:n})=>{const{id:o}=n,i=a("GET_ITEM",o);if(!i||i.archived)return;const d=t.query("GET_LABEL_BUTTON_MANAGE_METADATA"),r=t.query("GET_ON_MANAGE_METADATA");r?((t,n,o,a)=>{const i=n.querySelector(".filepond--file-info-main"),d=e(o);i.prepend(d),d.addEventListener("click",()=>a(t))})(i,t.element,d,r):console.error("No 'onManageMetadata' callback method specified for FilePondPluginManageMetadata! See https://github.com/nielsboogaard/filepond-plugin-manage-metadata for more instructions.")}},({root:e,props:t})=>{const{id:n}=t;a("GET_ITEM",n);e.rect.element.hidden}))}),{options:{labelButtonManageMetadata:["Edit metadata",a.STRING],onManageMetadata:[null,a.FUNCTION]}}};"undefined"!=typeof window&&void 0!==window.document&&document.dispatchEvent(new CustomEvent("FilePond:pluginloaded",{detail:t}));export default t; diff --git a/dist/filepond-plugin-manage-metadata.js b/dist/filepond-plugin-manage-metadata.js index 0a11952..fcf7f1d 100644 --- a/dist/filepond-plugin-manage-metadata.js +++ b/dist/filepond-plugin-manage-metadata.js @@ -69,12 +69,19 @@ 'GET_LABEL_BUTTON_MANAGE_METADATA' ); const onManageMetadata = root.query('GET_ON_MANAGE_METADATA'); - registerManageMetadataComponent( - item, - root.element, - labelButtonManageMetadata, - onManageMetadata - ); + + if (onManageMetadata) { + registerManageMetadataComponent( + item, + root.element, + labelButtonManageMetadata, + onManageMetadata + ); + } else { + console.error( + "No 'onManageMetadata' callback method specified for FilePondPluginManageMetadata! See https://github.com/nielsboogaard/filepond-plugin-manage-metadata for more instructions." + ); + } }; // start writing view.registerWriter( diff --git a/dist/filepond-plugin-manage-metadata.min.js b/dist/filepond-plugin-manage-metadata.min.js index e331258..6c89235 100644 --- a/dist/filepond-plugin-manage-metadata.min.js +++ b/dist/filepond-plugin-manage-metadata.min.js @@ -6,4 +6,4 @@ /* eslint-disable */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).FilePondPluginManageMetadata=t()}(this,(function(){"use strict";const e=e=>{let t=document.createElement("span");return t.className="filepond--edit-icon",t.title=e,t},t=t=>{const{addFilter:n,utils:o}=t,{Type:i,createRoute:d}=o;return n("CREATE_VIEW",t=>{const{is:n,view:o,query:i}=t;if(!n("file"))return;o.registerWriter(d({DID_LOAD_ITEM:({root:t,props:n})=>{const{id:o}=n,d=i("GET_ITEM",o);if(!d||d.archived)return;const r=t.query("GET_LABEL_BUTTON_MANAGE_METADATA"),a=t.query("GET_ON_MANAGE_METADATA");((t,n,o,i)=>{const d=n.querySelector(".filepond--file-info-main"),r=e(o);d.prepend(r),r.addEventListener("click",()=>i(t))})(d,t.element,r,a)}},({root:e,props:t})=>{const{id:n}=t;i("GET_ITEM",n);e.rect.element.hidden}))}),{options:{labelButtonManageMetadata:["Edit metadata",i.STRING],onManageMetadata:[null,i.FUNCTION]}}};return"undefined"!=typeof window&&void 0!==window.document&&document.dispatchEvent(new CustomEvent("FilePond:pluginloaded",{detail:t})),t})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).FilePondPluginManageMetadata=t()}(this,(function(){"use strict";const e=e=>{let t=document.createElement("span");return t.className="filepond--edit-icon",t.title=e,t},t=t=>{const{addFilter:n,utils:o}=t,{Type:i,createRoute:a}=o;return n("CREATE_VIEW",t=>{const{is:n,view:o,query:i}=t;if(!n("file"))return;o.registerWriter(a({DID_LOAD_ITEM:({root:t,props:n})=>{const{id:o}=n,a=i("GET_ITEM",o);if(!a||a.archived)return;const d=t.query("GET_LABEL_BUTTON_MANAGE_METADATA"),r=t.query("GET_ON_MANAGE_METADATA");r?((t,n,o,i)=>{const a=n.querySelector(".filepond--file-info-main"),d=e(o);a.prepend(d),d.addEventListener("click",()=>i(t))})(a,t.element,d,r):console.error("No 'onManageMetadata' callback method specified for FilePondPluginManageMetadata! See https://github.com/nielsboogaard/filepond-plugin-manage-metadata for more instructions.")}},({root:e,props:t})=>{const{id:n}=t;i("GET_ITEM",n);e.rect.element.hidden}))}),{options:{labelButtonManageMetadata:["Edit metadata",i.STRING],onManageMetadata:[null,i.FUNCTION]}}};return"undefined"!=typeof window&&void 0!==window.document&&document.dispatchEvent(new CustomEvent("FilePond:pluginloaded",{detail:t})),t})); diff --git a/index.html b/index.html index eec6ed4..9612d28 100644 --- a/index.html +++ b/index.html @@ -54,11 +54,7 @@

Manage Metadata plugin for FilePond demo

FilePond.registerPlugin(FilePondPluginManageMetadata); // Create the FilePond instance - const pond = FilePond.create(inputElement, { - onManageMetadata: function(item) { - console.log('onManageMetadata hook called', item); - } - }); + const pond = FilePond.create(inputElement); pond.addFile('./nature.jpg'); } diff --git a/package.json b/package.json index 674f5c9..c152153 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "filepond-plugin-manage-metadata", - "version": "1.0.0", + "version": "1.0.1", "description": "Manage Metadata Plugin for FilePond", "license": "MIT", "author": { diff --git a/src/js/index.js b/src/js/index.js index 000bbf5..3aa3461 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -31,7 +31,11 @@ const plugin = fpAPI => { const labelButtonManageMetadata = root.query('GET_LABEL_BUTTON_MANAGE_METADATA'); const onManageMetadata = root.query('GET_ON_MANAGE_METADATA'); - registerManageMetadataComponent(item, root.element, labelButtonManageMetadata, onManageMetadata); + if (onManageMetadata) { + registerManageMetadataComponent(item, root.element, labelButtonManageMetadata, onManageMetadata); + } else { + console.error("No 'onManageMetadata' callback method specified for FilePondPluginManageMetadata! See https://github.com/nielsboogaard/filepond-plugin-manage-metadata for more instructions."); + } }; // start writing