@easepick/base-plugin
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -1,86 +0,1 @@ | ||
class BasePlugin { | ||
picker; | ||
options; | ||
priority = 0; | ||
dependencies = []; | ||
/** | ||
* - Called automatically via PluginManager.initialize() or PluginManager.addInstance() - | ||
* Add plugin to the picker | ||
* | ||
* @param picker | ||
*/ | ||
attach(picker) { | ||
const pluginName = this['getName'](); | ||
const optionsOriginal = { ...this.options }; | ||
this.options = { | ||
...this.options, | ||
...(picker.options[pluginName] || {}), | ||
}; | ||
// copy deep object options | ||
for (const objName of Object.keys(optionsOriginal)) { | ||
if (optionsOriginal[objName] !== null | ||
&& typeof optionsOriginal[objName] === 'object' | ||
&& Object.keys(optionsOriginal[objName]).length | ||
&& pluginName in picker.options | ||
&& objName in picker.options[pluginName]) { | ||
const optionValue = { ...picker.options[pluginName][objName] }; | ||
if (optionValue !== null | ||
&& typeof optionValue === 'object' | ||
&& Object.keys(optionValue).length | ||
&& Object.keys(optionValue).every(opt => Object.keys(optionsOriginal[objName]).includes(opt))) { | ||
this.options[objName] = { ...optionsOriginal[objName], ...optionValue }; | ||
} | ||
} | ||
} | ||
this.picker = picker; | ||
if (this.dependenciesNotFound()) { | ||
const deps = this.dependencies.filter(x => !this.pluginsAsStringArray().includes(x)); | ||
console.warn(`${this['getName']()}: required dependencies (${deps.join(', ')}).`); | ||
return; | ||
} | ||
const pluginClass = this.camelCaseToKebab(this['getName']()); | ||
this.picker.ui.container.classList.add(pluginClass); | ||
this['onAttach'](); | ||
} | ||
/** | ||
* - Called automatically via PluginManager.removeInstance() - | ||
* Remove plugin from the picker | ||
*/ | ||
detach() { | ||
const pluginClass = this.camelCaseToKebab(this['getName']()); | ||
this.picker.ui.container.classList.remove(pluginClass); | ||
if (typeof this['onDetach'] === 'function') { | ||
this['onDetach'](); | ||
} | ||
} | ||
/** | ||
* Check dependencies for plugin | ||
* | ||
* @returns Boolean | ||
*/ | ||
dependenciesNotFound() { | ||
return this.dependencies.length | ||
&& !this.dependencies.every(v => this.pluginsAsStringArray().includes(v)); | ||
} | ||
/** | ||
* Return plugins list as string array | ||
* | ||
* @returns [] | ||
*/ | ||
pluginsAsStringArray() { | ||
return this.picker.options.plugins | ||
.map(x => typeof x === 'function' ? (new x).getName() : x); | ||
} | ||
/** | ||
* Return camelCase in kebab-case | ||
* Eg.: `userName` -> `user-name` | ||
* | ||
* @param str | ||
* @returns String | ||
*/ | ||
camelCaseToKebab(str) { | ||
return str.replace(/([a-zA-Z])(?=[A-Z])/g, '$1-').toLowerCase(); | ||
} | ||
} | ||
export { BasePlugin }; | ||
class e{picker;options;priority=0;dependencies=[];attach(e){const t=this.getName(),s={...this.options};this.options={...this.options,...e.options[t]||{}};for(const i of Object.keys(s))if(null!==s[i]&&"object"==typeof s[i]&&Object.keys(s[i]).length&&t in e.options&&i in e.options[t]){const n={...e.options[t][i]};null!==n&&"object"==typeof n&&Object.keys(n).length&&Object.keys(n).every((e=>Object.keys(s[i]).includes(e)))&&(this.options[i]={...s[i],...n})}if(this.picker=e,this.dependenciesNotFound()){const e=this.dependencies.filter((e=>!this.pluginsAsStringArray().includes(e)));return void console.warn(`${this.getName()}: required dependencies (${e.join(", ")}).`)}const i=this.camelCaseToKebab(this.getName());this.picker.ui.container.classList.add(i),this.onAttach()}detach(){const e=this.camelCaseToKebab(this.getName());this.picker.ui.container.classList.remove(e),"function"==typeof this.onDetach&&this.onDetach()}dependenciesNotFound(){return this.dependencies.length&&!this.dependencies.every((e=>this.pluginsAsStringArray().includes(e)))}pluginsAsStringArray(){return this.picker.options.plugins.map((e=>"function"==typeof e?(new e).getName():e))}camelCaseToKebab(e){return e.replace(/([a-zA-Z])(?=[A-Z])/g,"$1-").toLowerCase()}}export{e as BasePlugin}; |
/** | ||
* @license | ||
* Package: @easepick/base-plugin | ||
* Version: 1.1.0 | ||
* Version: 1.1.3 | ||
* https://easepick.com/ | ||
@@ -10,97 +10,2 @@ * Copyright 2022 Rinat G. | ||
*/ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.easepick = global.easepick || {})); | ||
})(this, (function (exports) { 'use strict'; | ||
class BasePlugin { | ||
picker; | ||
options; | ||
priority = 0; | ||
dependencies = []; | ||
/** | ||
* - Called automatically via PluginManager.initialize() or PluginManager.addInstance() - | ||
* Add plugin to the picker | ||
* | ||
* @param picker | ||
*/ | ||
attach(picker) { | ||
const pluginName = this['getName'](); | ||
const optionsOriginal = { ...this.options }; | ||
this.options = { | ||
...this.options, | ||
...(picker.options[pluginName] || {}), | ||
}; | ||
// copy deep object options | ||
for (const objName of Object.keys(optionsOriginal)) { | ||
if (optionsOriginal[objName] !== null | ||
&& typeof optionsOriginal[objName] === 'object' | ||
&& Object.keys(optionsOriginal[objName]).length | ||
&& pluginName in picker.options | ||
&& objName in picker.options[pluginName]) { | ||
const optionValue = { ...picker.options[pluginName][objName] }; | ||
if (optionValue !== null | ||
&& typeof optionValue === 'object' | ||
&& Object.keys(optionValue).length | ||
&& Object.keys(optionValue).every(opt => Object.keys(optionsOriginal[objName]).includes(opt))) { | ||
this.options[objName] = { ...optionsOriginal[objName], ...optionValue }; | ||
} | ||
} | ||
} | ||
this.picker = picker; | ||
if (this.dependenciesNotFound()) { | ||
const deps = this.dependencies.filter(x => !this.pluginsAsStringArray().includes(x)); | ||
console.warn(`${this['getName']()}: required dependencies (${deps.join(', ')}).`); | ||
return; | ||
} | ||
const pluginClass = this.camelCaseToKebab(this['getName']()); | ||
this.picker.ui.container.classList.add(pluginClass); | ||
this['onAttach'](); | ||
} | ||
/** | ||
* - Called automatically via PluginManager.removeInstance() - | ||
* Remove plugin from the picker | ||
*/ | ||
detach() { | ||
const pluginClass = this.camelCaseToKebab(this['getName']()); | ||
this.picker.ui.container.classList.remove(pluginClass); | ||
if (typeof this['onDetach'] === 'function') { | ||
this['onDetach'](); | ||
} | ||
} | ||
/** | ||
* Check dependencies for plugin | ||
* | ||
* @returns Boolean | ||
*/ | ||
dependenciesNotFound() { | ||
return this.dependencies.length | ||
&& !this.dependencies.every(v => this.pluginsAsStringArray().includes(v)); | ||
} | ||
/** | ||
* Return plugins list as string array | ||
* | ||
* @returns [] | ||
*/ | ||
pluginsAsStringArray() { | ||
return this.picker.options.plugins | ||
.map(x => typeof x === 'function' ? (new x).getName() : x); | ||
} | ||
/** | ||
* Return camelCase in kebab-case | ||
* Eg.: `userName` -> `user-name` | ||
* | ||
* @param str | ||
* @returns String | ||
*/ | ||
camelCaseToKebab(str) { | ||
return str.replace(/([a-zA-Z])(?=[A-Z])/g, '$1-').toLowerCase(); | ||
} | ||
} | ||
exports.BasePlugin = BasePlugin; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).easepick=e.easepick||{})}(this,(function(e){"use strict";e.BasePlugin=class{picker;options;priority=0;dependencies=[];attach(e){const t=this.getName(),i={...this.options};this.options={...this.options,...e.options[t]||{}};for(const s of Object.keys(i))if(null!==i[s]&&"object"==typeof i[s]&&Object.keys(i[s]).length&&t in e.options&&s in e.options[t]){const n={...e.options[t][s]};null!==n&&"object"==typeof n&&Object.keys(n).length&&Object.keys(n).every((e=>Object.keys(i[s]).includes(e)))&&(this.options[s]={...i[s],...n})}if(this.picker=e,this.dependenciesNotFound()){const e=this.dependencies.filter((e=>!this.pluginsAsStringArray().includes(e)));return void console.warn(`${this.getName()}: required dependencies (${e.join(", ")}).`)}const s=this.camelCaseToKebab(this.getName());this.picker.ui.container.classList.add(s),this.onAttach()}detach(){const e=this.camelCaseToKebab(this.getName());this.picker.ui.container.classList.remove(e),"function"==typeof this.onDetach&&this.onDetach()}dependenciesNotFound(){return this.dependencies.length&&!this.dependencies.every((e=>this.pluginsAsStringArray().includes(e)))}pluginsAsStringArray(){return this.picker.options.plugins.map((e=>"function"==typeof e?(new e).getName():e))}camelCaseToKebab(e){return e.replace(/([a-zA-Z])(?=[A-Z])/g,"$1-").toLowerCase()}},Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "@easepick/base-plugin", | ||
"description": "Base plugin for easepick.", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"main": "dist/index.umd.js", | ||
@@ -6,0 +6,0 @@ "module": "dist/index.esm.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5353
76