@easepick/base-plugin
Advanced tools
Comparing version 1.0.0-beta.5 to 1.0.0
@@ -1,68 +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) { | ||
this.options = { | ||
...this.options, | ||
...(picker.options[this['getName']()] || {}), | ||
}; | ||
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){if(this.options={...this.options,...e.options[this.getName()]||{}},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 t=this.camelCaseToKebab(this.getName());this.picker.ui.container.classList.add(t),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.0.0-beta.4 | ||
* Version: 1.0.0-beta.5 | ||
* https://easepick.com/ | ||
@@ -10,79 +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) { | ||
this.options = { | ||
...this.options, | ||
...(picker.options[this['getName']()] || {}), | ||
}; | ||
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,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((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){if(this.options={...this.options,...e.options[this.getName()]||{}},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()}},Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "@easepick/base-plugin", | ||
"description": "Base plugin for easepick.", | ||
"version": "1.0.0-beta.5", | ||
"version": "1.0.0", | ||
"main": "dist/index.umd.js", | ||
@@ -9,3 +9,3 @@ "module": "dist/index.esm.js", | ||
"dependencies": { | ||
"@easepick/core": "^1.0.0-beta.0" | ||
"@easepick/core": "^1.0.0" | ||
}, | ||
@@ -12,0 +12,0 @@ "author": { |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
4694
74
Updated@easepick/core@^1.0.0