@studiometa/js-toolkit 1.7.2 → 2.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Base/index.d.ts +217 -0
- package/Base/index.js +237 -0
- package/Base/managers/ChildrenManager.d.ts +108 -0
- package/Base/managers/ChildrenManager.js +124 -0
- package/Base/managers/EventsManager.d.ts +190 -0
- package/Base/managers/EventsManager.js +195 -0
- package/Base/managers/OptionsManager.d.ts +120 -0
- package/Base/managers/OptionsManager.js +180 -0
- package/Base/managers/RefsManager.d.ts +84 -0
- package/Base/managers/RefsManager.js +83 -0
- package/{abstracts/Base/classes/Services.d.ts → Base/managers/ServicesManager.d.ts} +22 -7
- package/Base/managers/ServicesManager.js +115 -0
- package/{abstracts/Base → Base}/utils.d.ts +0 -30
- package/Base/utils.js +43 -0
- package/README.md +12 -70
- package/decorators/index.js +1 -2
- package/decorators/withBreakpointManager.d.ts +5 -5
- package/decorators/withBreakpointManager.js +41 -79
- package/decorators/withBreakpointObserver.d.ts +4 -4
- package/decorators/withBreakpointObserver.js +54 -77
- package/decorators/withDrag.d.ts +6 -6
- package/decorators/withDrag.js +17 -41
- package/decorators/withExtraConfig.d.ts +6 -6
- package/decorators/withExtraConfig.js +2 -24
- package/decorators/withIntersectionObserver.d.ts +4 -4
- package/decorators/withIntersectionObserver.js +17 -60
- package/decorators/withMountWhenInView.d.ts +8 -8
- package/decorators/withMountWhenInView.js +23 -51
- package/helpers/createApp.d.ts +4 -4
- package/helpers/createApp.js +10 -12
- package/helpers/importOnInteraction.d.ts +6 -6
- package/helpers/importOnInteraction.js +7 -8
- package/helpers/importWhenIdle.d.ts +4 -4
- package/helpers/importWhenIdle.js +7 -8
- package/helpers/importWhenVisible.d.ts +6 -6
- package/helpers/importWhenVisible.js +9 -16
- package/helpers/index.d.ts +1 -3
- package/helpers/index.js +1 -4
- package/helpers/utils.js +2 -3
- package/index.d.ts +19 -5
- package/index.js +5 -6
- package/index.modern.js +1 -3230
- package/index.umd.js +1 -3586
- package/package.json +3 -6
- package/{abstracts → services}/Service.d.ts +0 -0
- package/services/Service.js +63 -0
- package/services/drag.js +144 -180
- package/services/index.js +1 -2
- package/services/key.js +56 -98
- package/services/load.d.ts +1 -1
- package/services/load.js +22 -51
- package/services/pointer.js +118 -157
- package/services/raf.js +37 -65
- package/services/resize.js +46 -98
- package/services/scroll.js +81 -120
- package/utils/collide/boundingRectToCircle.js +7 -6
- package/utils/collide/collideCircleCircle.js +1 -2
- package/utils/collide/collideCircleRect.js +1 -2
- package/utils/collide/collidePointCircle.js +1 -2
- package/utils/collide/collidePointRect.js +1 -2
- package/utils/collide/collideRectRect.js +1 -2
- package/utils/collide/index.js +1 -2
- package/utils/css/classes.js +2 -3
- package/utils/css/index.js +1 -2
- package/utils/css/matrix.js +1 -2
- package/utils/css/styles.js +3 -8
- package/utils/css/transition.js +67 -140
- package/utils/debounce.js +3 -4
- package/utils/focusTrap.js +4 -5
- package/utils/history.js +12 -19
- package/utils/index.d.ts +2 -1
- package/utils/index.js +2 -2
- package/utils/keyCodes.js +1 -2
- package/utils/math/clamp.js +1 -2
- package/utils/math/clamp01.js +1 -2
- package/utils/math/damp.js +1 -2
- package/utils/math/index.js +1 -2
- package/utils/math/inertiaFinalValue.js +1 -2
- package/utils/math/lerp.js +1 -2
- package/utils/math/map.js +1 -2
- package/utils/math/round.js +1 -2
- package/utils/memoize.d.ts +30 -0
- package/utils/memoize.js +30 -0
- package/utils/nextFrame.js +4 -9
- package/utils/object/autoBind.js +11 -19
- package/utils/object/getAllProperties.d.ts +6 -3
- package/utils/object/getAllProperties.js +10 -8
- package/utils/object/index.js +1 -2
- package/utils/object/isObject.js +2 -4
- package/utils/string/index.js +1 -2
- package/utils/string/withLeadingCharacters.js +1 -2
- package/utils/string/withLeadingSlash.js +1 -2
- package/utils/string/withTrailingCharacters.js +1 -2
- package/utils/string/withTrailingSlash.js +1 -2
- package/utils/string/withoutLeadingCharacters.js +1 -2
- package/utils/string/withoutLeadingCharactersRecursive.js +1 -2
- package/utils/string/withoutLeadingSlash.js +1 -2
- package/utils/string/withoutTrailingCharacters.js +1 -2
- package/utils/string/withoutTrailingCharactersRecursive.js +1 -2
- package/utils/string/withoutTrailingSlash.js +1 -2
- package/utils/throttle.js +2 -3
- package/abstracts/Base/children.d.ts +0 -16
- package/abstracts/Base/children.js +0 -66
- package/abstracts/Base/children.js.map +0 -1
- package/abstracts/Base/classes/Options.d.ts +0 -37
- package/abstracts/Base/classes/Options.js +0 -182
- package/abstracts/Base/classes/Options.js.map +0 -1
- package/abstracts/Base/classes/Services.js +0 -120
- package/abstracts/Base/classes/Services.js.map +0 -1
- package/abstracts/Base/components.d.ts +0 -22
- package/abstracts/Base/components.js +0 -67
- package/abstracts/Base/components.js.map +0 -1
- package/abstracts/Base/events.d.ts +0 -8
- package/abstracts/Base/events.js +0 -185
- package/abstracts/Base/events.js.map +0 -1
- package/abstracts/Base/index.d.ts +0 -176
- package/abstracts/Base/index.js +0 -215
- package/abstracts/Base/index.js.map +0 -1
- package/abstracts/Base/options.d.ts +0 -17
- package/abstracts/Base/options.js +0 -112
- package/abstracts/Base/options.js.map +0 -1
- package/abstracts/Base/refs.d.ts +0 -30
- package/abstracts/Base/refs.js +0 -60
- package/abstracts/Base/refs.js.map +0 -1
- package/abstracts/Base/utils.js +0 -102
- package/abstracts/Base/utils.js.map +0 -1
- package/abstracts/EventManager.d.ts +0 -41
- package/abstracts/EventManager.js +0 -88
- package/abstracts/EventManager.js.map +0 -1
- package/abstracts/Service.js +0 -82
- package/abstracts/Service.js.map +0 -1
- package/abstracts/index.d.ts +0 -4
- package/abstracts/index.js +0 -5
- package/abstracts/index.js.map +0 -1
- package/components/Accordion/Accordion.d.ts +0 -83
- package/components/Accordion/Accordion.js +0 -121
- package/components/Accordion/Accordion.js.map +0 -1
- package/components/Accordion/AccordionItem.d.ts +0 -122
- package/components/Accordion/AccordionItem.js +0 -327
- package/components/Accordion/AccordionItem.js.map +0 -1
- package/components/Accordion/index.d.ts +0 -27
- package/components/Accordion/index.js +0 -39
- package/components/Accordion/index.js.map +0 -1
- package/components/Cursor.d.ts +0 -138
- package/components/Cursor.js +0 -167
- package/components/Cursor.js.map +0 -1
- package/components/Draggable.d.ts +0 -49
- package/components/Draggable.js +0 -77
- package/components/Draggable.js.map +0 -1
- package/components/Modal.d.ts +0 -158
- package/components/Modal.js +0 -270
- package/components/Modal.js.map +0 -1
- package/components/Tabs.d.ts +0 -108
- package/components/Tabs.js +0 -195
- package/components/Tabs.js.map +0 -1
- package/components/index.d.ts +0 -6
- package/components/index.js +0 -7
- package/components/index.js.map +0 -1
- package/decorators/index.js.map +0 -1
- package/decorators/withBreakpointManager.js.map +0 -1
- package/decorators/withBreakpointObserver.js.map +0 -1
- package/decorators/withDrag.js.map +0 -1
- package/decorators/withExtraConfig.js.map +0 -1
- package/decorators/withIntersectionObserver.js.map +0 -1
- package/decorators/withMountWhenInView.js.map +0 -1
- package/full.d.ts +0 -10
- package/full.js +0 -12
- package/full.js.map +0 -1
- package/full.modern.js +0 -7523
- package/full.modern.js.map +0 -1
- package/full.umd.js +0 -8277
- package/full.umd.js.map +0 -1
- package/helpers/createApp.js.map +0 -1
- package/helpers/createBase.d.ts +0 -7
- package/helpers/createBase.js +0 -7
- package/helpers/createBase.js.map +0 -1
- package/helpers/defineComponent.d.ts +0 -11
- package/helpers/defineComponent.js +0 -68
- package/helpers/defineComponent.js.map +0 -1
- package/helpers/importOnInteraction.js.map +0 -1
- package/helpers/importWhenIdle.js.map +0 -1
- package/helpers/importWhenVisible.js.map +0 -1
- package/helpers/index.js.map +0 -1
- package/helpers/utils.js.map +0 -1
- package/index.js.map +0 -1
- package/index.modern.js.map +0 -1
- package/index.umd.js.map +0 -1
- package/services/drag.js.map +0 -1
- package/services/index.js.map +0 -1
- package/services/key.js.map +0 -1
- package/services/load.js.map +0 -1
- package/services/pointer.js.map +0 -1
- package/services/raf.js.map +0 -1
- package/services/resize.js.map +0 -1
- package/services/scroll.js.map +0 -1
- package/utils/collide/boundingRectToCircle.js.map +0 -1
- package/utils/collide/collideCircleCircle.js.map +0 -1
- package/utils/collide/collideCircleRect.js.map +0 -1
- package/utils/collide/collidePointCircle.js.map +0 -1
- package/utils/collide/collidePointRect.js.map +0 -1
- package/utils/collide/collideRectRect.js.map +0 -1
- package/utils/collide/index.js.map +0 -1
- package/utils/css/classes.js.map +0 -1
- package/utils/css/index.js.map +0 -1
- package/utils/css/matrix.js.map +0 -1
- package/utils/css/styles.js.map +0 -1
- package/utils/css/transition.js.map +0 -1
- package/utils/debounce.js.map +0 -1
- package/utils/focusTrap.js.map +0 -1
- package/utils/history.js.map +0 -1
- package/utils/index.js.map +0 -1
- package/utils/keyCodes.js.map +0 -1
- package/utils/math/clamp.js.map +0 -1
- package/utils/math/clamp01.js.map +0 -1
- package/utils/math/damp.js.map +0 -1
- package/utils/math/index.js.map +0 -1
- package/utils/math/inertiaFinalValue.js.map +0 -1
- package/utils/math/lerp.js.map +0 -1
- package/utils/math/map.js.map +0 -1
- package/utils/math/round.js.map +0 -1
- package/utils/nextFrame.js.map +0 -1
- package/utils/object/autoBind.js.map +0 -1
- package/utils/object/getAllProperties.js.map +0 -1
- package/utils/object/index.js.map +0 -1
- package/utils/object/isObject.js.map +0 -1
- package/utils/string/index.js.map +0 -1
- package/utils/string/withLeadingCharacters.js.map +0 -1
- package/utils/string/withLeadingSlash.js.map +0 -1
- package/utils/string/withTrailingCharacters.js.map +0 -1
- package/utils/string/withTrailingSlash.js.map +0 -1
- package/utils/string/withoutLeadingCharacters.js.map +0 -1
- package/utils/string/withoutLeadingCharactersRecursive.js.map +0 -1
- package/utils/string/withoutLeadingSlash.js.map +0 -1
- package/utils/string/withoutTrailingCharacters.js.map +0 -1
- package/utils/string/withoutTrailingCharactersRecursive.js.map +0 -1
- package/utils/string/withoutTrailingSlash.js.map +0 -1
- package/utils/throttle.js.map +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import withoutTrailingCharacters from './withoutTrailingCharacters.js';
|
|
2
2
|
export default function withTrailingCharacters(string, characters) {
|
|
3
3
|
return "".concat(withoutTrailingCharacters(string, characters)).concat(characters);
|
|
4
|
-
}
|
|
5
|
-
//# sourceMappingURL=withTrailingCharacters.js.map
|
|
4
|
+
}
|
package/utils/throttle.js
CHANGED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get child components.
|
|
3
|
-
* @param {Base} instance The component's instance.
|
|
4
|
-
* @param {HTMLElement} element The component's root element
|
|
5
|
-
* @param {BaseConfigComponents} components The children components' classes
|
|
6
|
-
* @return {null|Object} Returns `null` if no child components are defined or an object of all child component instances
|
|
7
|
-
*/
|
|
8
|
-
export function getChildren(instance: Base, element: HTMLElement, components: BaseConfigComponents): null | any;
|
|
9
|
-
declare namespace _default {
|
|
10
|
-
export { getChildren };
|
|
11
|
-
}
|
|
12
|
-
export default _default;
|
|
13
|
-
export type Base = import('./index.js').default;
|
|
14
|
-
export type BaseComponent = import('./index.js').BaseComponent;
|
|
15
|
-
export type BaseAsyncComponent = import('./index.js').BaseAsyncComponent;
|
|
16
|
-
export type BaseConfigComponents = import('./index.js').BaseConfigComponents;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
import { debug, getComponentElements } from './utils.js';
|
|
3
|
-
|
|
4
|
-
function getChild(el, ComponentClass, parent) {
|
|
5
|
-
if (el.__base__) {
|
|
6
|
-
return el.__base__;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
if ('$isBase' in ComponentClass) {
|
|
10
|
-
var child = new ComponentClass(el);
|
|
11
|
-
Object.defineProperty(child, '$parent', {
|
|
12
|
-
get: function get() {
|
|
13
|
-
return parent;
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
return child;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return ComponentClass(parent).then(function (module) {
|
|
20
|
-
var _module$default;
|
|
21
|
-
|
|
22
|
-
return getChild(el, (_module$default = module.default) !== null && _module$default !== void 0 ? _module$default : module, parent);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function getChildren(instance, element, components) {
|
|
27
|
-
if (__DEV__) {
|
|
28
|
-
debug(instance, 'before:getChildren', element, components);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
var children = Object.entries(components).reduce(function (acc, _ref) {
|
|
32
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
33
|
-
name = _ref2[0],
|
|
34
|
-
ComponentClass = _ref2[1];
|
|
35
|
-
|
|
36
|
-
Object.defineProperty(acc, name, {
|
|
37
|
-
get: function get() {
|
|
38
|
-
var elements = getComponentElements(name, element);
|
|
39
|
-
|
|
40
|
-
if (elements.length === 0) {
|
|
41
|
-
return [];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return elements.map(function (el) {
|
|
45
|
-
return getChild(el, ComponentClass, instance);
|
|
46
|
-
}).filter(function (el) {
|
|
47
|
-
return el !== 'terminated';
|
|
48
|
-
});
|
|
49
|
-
},
|
|
50
|
-
enumerable: true,
|
|
51
|
-
configurable: true
|
|
52
|
-
});
|
|
53
|
-
return acc;
|
|
54
|
-
}, {});
|
|
55
|
-
instance.$emit('get:children', children);
|
|
56
|
-
|
|
57
|
-
if (__DEV__) {
|
|
58
|
-
debug(instance, 'after:getChildren', children);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return children;
|
|
62
|
-
}
|
|
63
|
-
export default {
|
|
64
|
-
getChildren: getChildren
|
|
65
|
-
};
|
|
66
|
-
//# sourceMappingURL=children.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../packages/js-toolkit/abstracts/Base/children.js"],"names":["debug","getComponentElements","getChild","el","ComponentClass","parent","__base__","child","Object","defineProperty","get","then","module","default","getChildren","instance","element","components","__DEV__","children","entries","reduce","acc","name","elements","length","map","filter","enumerable","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,CAAxB,EAA2B;AACzB,iBAAO,EAAP;AACD;;AAED,eACED,QAAQ,CACLE,GADH,CACO,UAACvB,EAAD;AAAA,iBAAQD,QAAQ,CAACC,EAAD,EAAKC,cAAL,EAAqBW,QAArB,CAAhB;AAAA,SADP,EAIGY,MAJH,CAIU,UAACxB,EAAD;AAAA,iBAAQA,EAAE,KAAK,YAAf;AAAA,SAJV,CADF;AAOD,OAf8B;AAgB/ByB,MAAAA,UAAU,EAAE,IAhBmB;AAiB/BC,MAAAA,YAAY,EAAE;AAjBiB,KAAjC;AAoBA,WAAOP,GAAP;AACD,GAtBgB,EAsBd,EAtBc,CAAjB;AAwBAP,EAAAA,QAAQ,CAACe,KAAT,CAAe,cAAf,EAA+BX,QAA/B;;AACA,MAAID,OAAJ,EAAa;AACXlB,IAAAA,KAAK,CAACe,QAAD,EAAW,mBAAX,EAAgCI,QAAhC,CAAL;AACD;;AACD,SAAOA,QAAP;AACD;AAED,eAAe;AACbL,EAAAA,WAAW,EAAXA;AADa,CAAf","sourcesContent":["import { debug, getComponentElements } from './utils.js';\n\n/**\n * @typedef {import('./index.js').default} Base\n * @typedef {import('./index.js').BaseComponent} BaseComponent\n * @typedef {import('./index.js').BaseAsyncComponent} BaseAsyncComponent\n * @typedef {import('./index.js').BaseConfigComponents} BaseConfigComponents\n */\n\n/**\n * Get a child component.\n *\n * @param {HTMLElement & { __base__?: Base | 'terminated' }} el\n * The root element of the child component.\n * @param {BaseComponent|BaseAsyncComponent} ComponentClass\n * A Base class or a Promise for async components.\n * @param {Base} parent\n * The parent component instance.\n * @return {Base|Promise|'terminated'}\n * A Base instance or a Promise resolving to a Base instance.\n */\nfunction getChild(el, ComponentClass, parent) {\n // Return existing instance if it exists\n if (el.__base__) {\n return el.__base__;\n }\n\n // Return a new instance if the component class is a child of the Base class\n if ('$isBase' in ComponentClass) {\n const child = new ComponentClass(el);\n Object.defineProperty(child, '$parent', { get: () => parent });\n return child;\n }\n\n // Resolve async components\n return ComponentClass(parent).then((module) => {\n // @ts-ignore\n return getChild(el, module.default ?? module, parent);\n });\n}\n\n/**\n * Get child components.\n * @param {Base} instance The component's instance.\n * @param {HTMLElement} element The component's root element\n * @param {BaseConfigComponents} components The children components' classes\n * @return {null|Object} Returns `null` if no child components are defined or an object of all child component instances\n */\nexport function getChildren(instance, element, components) {\n if (__DEV__) {\n debug(instance, 'before:getChildren', element, components);\n }\n const children = Object.entries(components).reduce((acc, [name, ComponentClass]) => {\n Object.defineProperty(acc, name, {\n get() {\n const elements = getComponentElements(name, element);\n\n if (elements.length === 0) {\n return [];\n }\n\n return (\n elements\n .map((el) => getChild(el, ComponentClass, instance))\n // Filter out terminated children\n // @ts-ignore\n .filter((el) => el !== 'terminated')\n );\n },\n enumerable: true,\n configurable: true,\n });\n\n return acc;\n }, {});\n\n instance.$emit('get:children', children);\n if (__DEV__) {\n debug(instance, 'after:getChildren', children);\n }\n return children;\n}\n\nexport default {\n getChildren,\n};\n"],"file":"children.js"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Class options to manage options as data attributes on an HTML element.
|
|
3
|
-
* @augments {OptionsInterface}
|
|
4
|
-
*/
|
|
5
|
-
export default class Options {
|
|
6
|
-
/** @type {Array} List of allowed types. */
|
|
7
|
-
static types: any[];
|
|
8
|
-
/**
|
|
9
|
-
* Class constructor.
|
|
10
|
-
*
|
|
11
|
-
* @param {HTMLElement} element The HTML element storing the options.
|
|
12
|
-
* @param {OptionsSchema} schema A Base class config.
|
|
13
|
-
*/
|
|
14
|
-
constructor(element: HTMLElement, schema: OptionsSchema);
|
|
15
|
-
/**
|
|
16
|
-
* Get an option value.
|
|
17
|
-
*
|
|
18
|
-
* @param {String} name The option name.
|
|
19
|
-
* @param {ArrayConstructor|ObjectConstructor|StringConstructor|NumberConstructor|BooleanConstructor} type The option data's type.
|
|
20
|
-
* @param {any} defaultValue The default value for this option.
|
|
21
|
-
*/
|
|
22
|
-
get(name: string, type: ArrayConstructor | ObjectConstructor | StringConstructor | NumberConstructor | BooleanConstructor, defaultValue: any): any;
|
|
23
|
-
/**
|
|
24
|
-
* Set an option value.
|
|
25
|
-
*
|
|
26
|
-
* @param {String} name The option name.
|
|
27
|
-
* @param {ArrayConstructor|ObjectConstructor|StringConstructor|NumberConstructor|BooleanConstructor} type The option data's type.
|
|
28
|
-
* @param {any} value The new value for this option.
|
|
29
|
-
*/
|
|
30
|
-
set(name: string, type: ArrayConstructor | ObjectConstructor | StringConstructor | NumberConstructor | BooleanConstructor, value: any, defaultValue: any): void;
|
|
31
|
-
#private;
|
|
32
|
-
}
|
|
33
|
-
export type OptionType = StringConstructor | NumberConstructor | BooleanConstructor | ArrayConstructor | ObjectConstructor;
|
|
34
|
-
export type OptionsSchema = OptionsSchema;
|
|
35
|
-
export type OptionsInterface = {
|
|
36
|
-
[optionName: string]: any;
|
|
37
|
-
};
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
5
|
-
import _classPrivateFieldGet from "@babel/runtime/helpers/classPrivateFieldGet";
|
|
6
|
-
import _classPrivateFieldSet from "@babel/runtime/helpers/classPrivateFieldSet";
|
|
7
|
-
import deepmerge from 'deepmerge';
|
|
8
|
-
import { noCase } from 'no-case';
|
|
9
|
-
import mem from 'mem';
|
|
10
|
-
import isObject from '../../../utils/object/isObject.js';
|
|
11
|
-
|
|
12
|
-
function getAttributeName(name) {
|
|
13
|
-
return "data-option-".concat(noCase(name, {
|
|
14
|
-
delimiter: '-'
|
|
15
|
-
}));
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
var memoizedGetAttributeName = mem(getAttributeName);
|
|
19
|
-
|
|
20
|
-
var _element = new WeakMap();
|
|
21
|
-
|
|
22
|
-
var _values = new WeakMap();
|
|
23
|
-
|
|
24
|
-
var _defaultValues = new WeakMap();
|
|
25
|
-
|
|
26
|
-
var Options = function () {
|
|
27
|
-
function Options(element, schema) {
|
|
28
|
-
var _this = this;
|
|
29
|
-
|
|
30
|
-
_classCallCheck(this, Options);
|
|
31
|
-
|
|
32
|
-
_element.set(this, {
|
|
33
|
-
writable: true,
|
|
34
|
-
value: void 0
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
_values.set(this, {
|
|
38
|
-
writable: true,
|
|
39
|
-
value: {}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
_defaultValues.set(this, {
|
|
43
|
-
writable: true,
|
|
44
|
-
value: {
|
|
45
|
-
String: '',
|
|
46
|
-
Number: 0,
|
|
47
|
-
Boolean: false,
|
|
48
|
-
Array: function Array() {
|
|
49
|
-
return [];
|
|
50
|
-
},
|
|
51
|
-
Object: function Object() {
|
|
52
|
-
return {};
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
_classPrivateFieldSet(this, _element, element);
|
|
58
|
-
|
|
59
|
-
Object.entries(schema).forEach(function (_ref) {
|
|
60
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
61
|
-
name = _ref2[0],
|
|
62
|
-
config = _ref2[1];
|
|
63
|
-
|
|
64
|
-
var isObjectConfig = !Options.types.includes(config);
|
|
65
|
-
var type = isObjectConfig ? config.type : config;
|
|
66
|
-
|
|
67
|
-
if (!Options.types.includes(type)) {
|
|
68
|
-
throw new Error("The \"".concat(name, "\" option has an invalid type. The allowed types are: String, Number, Boolean, Array and Object."));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
var defaultValue = isObjectConfig ? config.default : _classPrivateFieldGet(_this, _defaultValues)[type.name];
|
|
72
|
-
|
|
73
|
-
if ((type === Array || type === Object) && typeof defaultValue !== 'function') {
|
|
74
|
-
throw new Error("The default value for options of type \"".concat(type.name, "\" must be returned by a function."));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
Object.defineProperty(_this, name, {
|
|
78
|
-
get: function get() {
|
|
79
|
-
return this.get(name, type, defaultValue);
|
|
80
|
-
},
|
|
81
|
-
set: function set(value) {
|
|
82
|
-
this.set(name, type, value, defaultValue);
|
|
83
|
-
},
|
|
84
|
-
enumerable: true
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
return this;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
_createClass(Options, [{
|
|
91
|
-
key: "get",
|
|
92
|
-
value: function get(name, type, defaultValue) {
|
|
93
|
-
var _this2 = this;
|
|
94
|
-
|
|
95
|
-
var attributeName = memoizedGetAttributeName(name);
|
|
96
|
-
|
|
97
|
-
var hasAttribute = _classPrivateFieldGet(this, _element).hasAttribute(attributeName);
|
|
98
|
-
|
|
99
|
-
if (type === Boolean) {
|
|
100
|
-
if (defaultValue) {
|
|
101
|
-
var negatedAttributeName = memoizedGetAttributeName("no-".concat(name));
|
|
102
|
-
|
|
103
|
-
var hasNegatedAttribute = _classPrivateFieldGet(this, _element).hasAttribute(negatedAttributeName);
|
|
104
|
-
|
|
105
|
-
return !hasNegatedAttribute;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return hasAttribute || defaultValue;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
var value = _classPrivateFieldGet(this, _element).getAttribute(attributeName);
|
|
112
|
-
|
|
113
|
-
if (type === Number) {
|
|
114
|
-
return hasAttribute ? Number(value) : defaultValue;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (type === Array || type === Object) {
|
|
118
|
-
var val = deepmerge(defaultValue(), hasAttribute ? JSON.parse(value) : _classPrivateFieldGet(this, _defaultValues)[type.name]());
|
|
119
|
-
|
|
120
|
-
if (!_classPrivateFieldGet(this, _values)[name]) {
|
|
121
|
-
_classPrivateFieldGet(this, _values)[name] = val;
|
|
122
|
-
} else if (val !== _classPrivateFieldGet(this, _values)[name]) {
|
|
123
|
-
setTimeout(function () {
|
|
124
|
-
_classPrivateFieldGet(_this2, _element).setAttribute(attributeName, JSON.stringify(_classPrivateFieldGet(_this2, _values)[name]));
|
|
125
|
-
}, 0);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return _classPrivateFieldGet(this, _values)[name];
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return hasAttribute ? value : defaultValue;
|
|
132
|
-
}
|
|
133
|
-
}, {
|
|
134
|
-
key: "set",
|
|
135
|
-
value: function set(name, type, value, defaultValue) {
|
|
136
|
-
var attributeName = memoizedGetAttributeName(name);
|
|
137
|
-
|
|
138
|
-
if (value.constructor.name !== type.name) {
|
|
139
|
-
var val = Array.isArray(value) || isObject(value) ? JSON.stringify(value) : value;
|
|
140
|
-
throw new TypeError("The \"".concat(val, "\" value for the \"").concat(name, "\" option must be of type \"").concat(type.name, "\""));
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
switch (type) {
|
|
144
|
-
case Boolean:
|
|
145
|
-
if (defaultValue) {
|
|
146
|
-
var negatedAttributeName = memoizedGetAttributeName("no-".concat(name));
|
|
147
|
-
|
|
148
|
-
if (value) {
|
|
149
|
-
_classPrivateFieldGet(this, _element).removeAttribute(negatedAttributeName);
|
|
150
|
-
} else {
|
|
151
|
-
_classPrivateFieldGet(this, _element).setAttribute(negatedAttributeName, '');
|
|
152
|
-
}
|
|
153
|
-
} else if (value) {
|
|
154
|
-
_classPrivateFieldGet(this, _element).setAttribute(attributeName, '');
|
|
155
|
-
} else {
|
|
156
|
-
_classPrivateFieldGet(this, _element).removeAttribute(attributeName);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
break;
|
|
160
|
-
|
|
161
|
-
case Array:
|
|
162
|
-
case Object:
|
|
163
|
-
_classPrivateFieldGet(this, _values)[name] = value;
|
|
164
|
-
|
|
165
|
-
_classPrivateFieldGet(this, _element).setAttribute(attributeName, JSON.stringify(value));
|
|
166
|
-
|
|
167
|
-
break;
|
|
168
|
-
|
|
169
|
-
default:
|
|
170
|
-
_classPrivateFieldGet(this, _element).setAttribute(attributeName, value);
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}]);
|
|
175
|
-
|
|
176
|
-
return Options;
|
|
177
|
-
}();
|
|
178
|
-
|
|
179
|
-
_defineProperty(Options, "types", [String, Number, Boolean, Array, Object]);
|
|
180
|
-
|
|
181
|
-
export { Options as default };
|
|
182
|
-
//# sourceMappingURL=Options.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../packages/js-toolkit/abstracts/Base/classes/Options.js"],"names":["deepmerge","noCase","mem","isObject","getAttributeName","name","delimiter","memoizedGetAttributeName","Options","element","schema","String","Number","Boolean","Array","Object","entries","forEach","config","isObjectConfig","types","includes","type","Error","defaultValue","default","defineProperty","get","set","value","enumerable","attributeName","hasAttribute","negatedAttributeName","hasNegatedAttribute","getAttribute","val","JSON","parse","setTimeout","setAttribute","stringify","constructor","isArray","TypeError","removeAttribute"],"mappings":";;;;;;AAAA,OAAOA,SAAP,MAAsB,WAAtB;AACA,SAASC,MAAT,QAAuB,SAAvB;AACA,OAAOC,GAAP,MAAgB,KAAhB;AACA,OAAOC,QAAP,MAAqB,mCAArB;;AAYA,SAASC,gBAAT,CAA0BC,IAA1B,EAAgC;AAC9B,+BAAsBJ,MAAM,CAACI,IAAD,EAAO;AAAEC,IAAAA,SAAS,EAAE;AAAb,GAAP,CAA5B;AACD;;AAED,IAAMC,wBAAwB,GAAGL,GAAG,CAACE,gBAAD,CAApC;;;;;;;;IAMqBI,O;AA4BnB,mBAAYC,OAAZ,EAAqBC,MAArB,EAA6B;AAAA;;AAAA;;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA,aAvBnB;AAuBmB;;AAAA;AAAA;AAAA,aAdZ;AACfC,QAAAA,MAAM,EAAE,EADO;AAEfC,QAAAA,MAAM,EAAE,CAFO;AAGfC,QAAAA,OAAO,EAAE,KAHM;AAIfC,Q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tBJ;AAwBD;;;;;;gBAhKkBrB,O,WAQJ,CAACG,MAAD,EAASC,MAAT,EAAiBC,OAAjB,EAA0BC,KAA1B,EAAiCC,MAAjC,C;;SARIP,O","sourcesContent":["import deepmerge from 'deepmerge';\nimport { noCase } from 'no-case';\nimport mem from 'mem';\nimport isObject from '../../../utils/object/isObject.js';\n\n/**\n * @typedef {StringConstructor|NumberConstructor|BooleanConstructor|ArrayConstructor|ObjectConstructor} OptionType\n * @typedef {{ [name:string]: OptionType | { type: OptionType, default: String|Number|Boolean|(() => Array|Object)} }} OptionsSchema\n * @typedef {{ [optionName:string]: any }} OptionsInterface\n */\n\n/**\n * Get the attribute name based on the given option name.\n * @param {String} name The option name.\n */\nfunction getAttributeName(name) {\n return `data-option-${noCase(name, { delimiter: '-' })}`;\n}\n\nconst memoizedGetAttributeName = mem(getAttributeName);\n\n/**\n * Class options to manage options as data attributes on an HTML element.\n * @augments {OptionsInterface}\n */\nexport default class Options {\n /** @type {HTMLElement} The HTML element holding the options attributes. */\n #element;\n\n /** @type {Object} An object to store Array and Object values for reference. */\n #values = {};\n\n /** @type {Array} List of allowed types. */\n static types = [String, Number, Boolean, Array, Object];\n\n /**\n * The default values to return for each available type.\n * @type {Object}\n */\n #defaultValues = {\n String: '',\n Number: 0,\n Boolean: false,\n Array: () => [],\n Object: () => ({}),\n };\n\n /**\n * Class constructor.\n *\n * @param {HTMLElement} element The HTML element storing the options.\n * @param {OptionsSchema} schema A Base class config.\n */\n constructor(element, schema) {\n this.#element = element;\n\n Object.entries(schema).forEach(([name, config]) => {\n const isObjectConfig = !Options.types.includes(config);\n /** @type {OptionType} */\n // @ts-ignore\n const type = isObjectConfig ? config.type : config;\n\n if (!Options.types.includes(type)) {\n throw new Error(\n `The \"${name}\" option has an invalid type. The allowed types are: String, Number, Boolean, Array and Object.`\n );\n }\n\n // @ts-ignore\n const defaultValue = isObjectConfig ? config.default : this.#defaultValues[type.name];\n\n if ((type === Array || type === Object) && typeof defaultValue !== 'function') {\n throw new Error(\n `The default value for options of type \"${type.name}\" must be returned by a function.`\n );\n }\n\n Object.defineProperty(this, name, {\n get() {\n return this.get(name, type, defaultValue);\n },\n set(value) {\n this.set(name, type, value, defaultValue);\n },\n enumerable: true,\n });\n });\n\n return this;\n }\n\n /**\n * Get an option value.\n *\n * @param {String} name The option name.\n * @param {ArrayConstructor|ObjectConstructor|StringConstructor|NumberConstructor|BooleanConstructor} type The option data's type.\n * @param {any} defaultValue The default value for this option.\n */\n get(name, type, defaultValue) {\n const attributeName = memoizedGetAttributeName(name);\n const hasAttribute = this.#element.hasAttribute(attributeName);\n\n if (type === Boolean) {\n if (defaultValue) {\n const negatedAttributeName = memoizedGetAttributeName(`no-${name}`);\n const hasNegatedAttribute = this.#element.hasAttribute(negatedAttributeName);\n\n return !hasNegatedAttribute;\n }\n\n return hasAttribute || defaultValue;\n }\n\n const value = this.#element.getAttribute(attributeName);\n\n if (type === Number) {\n return hasAttribute ? Number(value) : defaultValue;\n }\n\n if (type === Array || type === Object) {\n const val = deepmerge(\n defaultValue(),\n hasAttribute ? JSON.parse(value) : this.#defaultValues[type.name]()\n );\n\n if (!this.#values[name]) {\n this.#values[name] = val;\n } else if (val !== this.#values[name]) {\n // When getting the value, wait for the next loop to update the data attribute\n // with the new value. This is a simple trick to avoid using a Proxy to watch\n // for any deep changes on an array or object. It should not break anything as\n // the original value is read once from the data attribute and is then read from\n // the private property `#values`.\n setTimeout(() => {\n this.#element.setAttribute(attributeName, JSON.stringify(this.#values[name]));\n }, 0);\n }\n\n return this.#values[name];\n }\n\n return hasAttribute ? value : defaultValue;\n }\n\n /**\n * Set an option value.\n *\n * @param {String} name The option name.\n * @param {ArrayConstructor|ObjectConstructor|StringConstructor|NumberConstructor|BooleanConstructor} type The option data's type.\n * @param {any} value The new value for this option.\n */\n set(name, type, value, defaultValue) {\n const attributeName = memoizedGetAttributeName(name);\n\n if (value.constructor.name !== type.name) {\n const val = Array.isArray(value) || isObject(value) ? JSON.stringify(value) : value;\n throw new TypeError(\n `The \"${val}\" value for the \"${name}\" option must be of type \"${type.name}\"`\n );\n }\n\n switch (type) {\n case Boolean:\n if (defaultValue) {\n const negatedAttributeName = memoizedGetAttributeName(`no-${name}`);\n\n if (value) {\n this.#element.removeAttribute(negatedAttributeName);\n } else {\n this.#element.setAttribute(negatedAttributeName, '');\n }\n } else if (value) {\n this.#element.setAttribute(attributeName, '');\n } else {\n this.#element.removeAttribute(attributeName);\n }\n break;\n case Array:\n case Object:\n this.#values[name] = value;\n this.#element.setAttribute(attributeName, JSON.stringify(value));\n break;\n default:\n this.#element.setAttribute(attributeName, value);\n }\n }\n}\n"],"file":"Options.js"}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
-
import _classPrivateFieldGet from "@babel/runtime/helpers/classPrivateFieldGet";
|
|
4
|
-
import _classPrivateFieldSet from "@babel/runtime/helpers/classPrivateFieldSet";
|
|
5
|
-
import usePointer from '../../../services/pointer.js';
|
|
6
|
-
import useRaf from '../../../services/raf.js';
|
|
7
|
-
import useResize from '../../../services/resize.js';
|
|
8
|
-
import useScroll from '../../../services/scroll.js';
|
|
9
|
-
import useKey from '../../../services/key.js';
|
|
10
|
-
import useLoad from '../../../services/load.js';
|
|
11
|
-
import { hasMethod, callMethod } from '../utils.js';
|
|
12
|
-
var SERVICES_MAP = {
|
|
13
|
-
scrolled: useScroll,
|
|
14
|
-
resized: useResize,
|
|
15
|
-
ticked: useRaf,
|
|
16
|
-
moved: usePointer,
|
|
17
|
-
keyed: useKey,
|
|
18
|
-
loaded: useLoad
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
var _base = new WeakMap();
|
|
22
|
-
|
|
23
|
-
var Services = function () {
|
|
24
|
-
function Services(instance) {
|
|
25
|
-
_classCallCheck(this, Services);
|
|
26
|
-
|
|
27
|
-
_base.set(this, {
|
|
28
|
-
writable: true,
|
|
29
|
-
value: void 0
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
_classPrivateFieldSet(this, _base, instance);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
_createClass(Services, [{
|
|
36
|
-
key: "has",
|
|
37
|
-
value: function has(service) {
|
|
38
|
-
if (!hasMethod(_classPrivateFieldGet(this, _base), service) && !SERVICES_MAP[service]) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
var _SERVICES_MAP$service = SERVICES_MAP[service](),
|
|
43
|
-
has = _SERVICES_MAP$service.has;
|
|
44
|
-
|
|
45
|
-
return has(_classPrivateFieldGet(this, _base).$id);
|
|
46
|
-
}
|
|
47
|
-
}, {
|
|
48
|
-
key: "enable",
|
|
49
|
-
value: function enable(service) {
|
|
50
|
-
if (this.has(service)) {
|
|
51
|
-
return this.disable.bind(this, service);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (!hasMethod(_classPrivateFieldGet(this, _base), service) || !SERVICES_MAP[service]) {
|
|
55
|
-
return function noop() {};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
var _SERVICES_MAP$service2 = SERVICES_MAP[service](),
|
|
59
|
-
add = _SERVICES_MAP$service2.add;
|
|
60
|
-
|
|
61
|
-
var self = this;
|
|
62
|
-
|
|
63
|
-
function serviceHandler() {
|
|
64
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
65
|
-
args[_key] = arguments[_key];
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
callMethod.apply(void 0, [_classPrivateFieldGet(self, _base), service].concat(args));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
add(_classPrivateFieldGet(this, _base).$id, serviceHandler);
|
|
72
|
-
return this.disable.bind(this, service);
|
|
73
|
-
}
|
|
74
|
-
}, {
|
|
75
|
-
key: "enableAll",
|
|
76
|
-
value: function enableAll() {
|
|
77
|
-
var _this = this;
|
|
78
|
-
|
|
79
|
-
return Object.keys(SERVICES_MAP).map(function (serviceName) {
|
|
80
|
-
return _this.enable(serviceName);
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}, {
|
|
84
|
-
key: "disableAll",
|
|
85
|
-
value: function disableAll() {
|
|
86
|
-
var _this2 = this;
|
|
87
|
-
|
|
88
|
-
Object.keys(SERVICES_MAP).forEach(function (serviceName) {
|
|
89
|
-
_this2.disable(serviceName);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}, {
|
|
93
|
-
key: "disable",
|
|
94
|
-
value: function disable(service) {
|
|
95
|
-
if (!SERVICES_MAP[service]) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
var _SERVICES_MAP$service3 = SERVICES_MAP[service](),
|
|
100
|
-
remove = _SERVICES_MAP$service3.remove;
|
|
101
|
-
|
|
102
|
-
remove(_classPrivateFieldGet(this, _base).$id);
|
|
103
|
-
}
|
|
104
|
-
}, {
|
|
105
|
-
key: "register",
|
|
106
|
-
value: function register(name, useFunction) {
|
|
107
|
-
SERVICES_MAP[name] = useFunction;
|
|
108
|
-
}
|
|
109
|
-
}, {
|
|
110
|
-
key: "unregister",
|
|
111
|
-
value: function unregister(name) {
|
|
112
|
-
delete SERVICES_MAP[name];
|
|
113
|
-
}
|
|
114
|
-
}]);
|
|
115
|
-
|
|
116
|
-
return Services;
|
|
117
|
-
}();
|
|
118
|
-
|
|
119
|
-
export { Services as default };
|
|
120
|
-
//# sourceMappingURL=Services.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../packages/js-toolkit/abstracts/Base/classes/Services.js"],"names":["usePointer","useRaf","useResize","useScroll","useKey","useLoad","hasMethod","callMethod","SERVICES_MAP","scrolled","resized","ticked","moved","keyed","loaded","Services","instance","service","has","$id","disable","bind","noop","add","self","serviceHandler","args","Object","keys","map","serviceName","enable","forEach","remove","name","useFunction"],"mappings":";;;;AAAA,OAAOA,U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,GAAR,0BAAQA,GAAR;;AACA,UAAMC,IAAI,GAAG,IAAb;;AAKA,eAASC,cAAT,GAAiC;AAAA,0CAANC,IAAM;AAANA,UAAAA,IAAM;AAAA;;AAC/BnB,QAAAA,UAAU,MAAV,gCAAWiB,IAAX,UAAuBP,OAAvB,SAAmCS,IAAnC;AACD;;AAEDH,MAAAA,GAAG,CAAC,mCAAWJ,GAAZ,EAAiBM,cAAjB,CAAH;AAEA,aAAO,KAAKL,OAAL,CAAaC,IAAb,CAAkB,IAAlB,EAAwBJ,OAAxB,CAAP;AACD;;;WAOD,qBAAY;AAAA;;AACV,aAAOU,MAAM,CAACC,IAAP,CAAYpB,YAAZ,EAA0BqB,GAA1B,CAEL,UAACC,WAAD;AAAA,eAAiB,KAAI,CAACC,MAAL,CAAYD,WAAZ,CAAjB;AAAA,OAFK,CAAP;AAID;;;WAOD,sBAAa;AAAA;;AACXH,MAAAA,MAAM,CAACC,IAAP,CAAYpB,YAAZ,EAA0BwB,OAA1B,CAEE,UAACF,WAAD,EAAiB;AACf,QAAA,MAAI,CAACV,OAAL,CAAaU,WAAb;AACD,OAJH;AAMD;;;WAQD,iBAAQb,OAAR,EAAiB;AACf,UAAI,CAACT,YAAY,CAACS,OAAD,CAAjB,EAA4B;AAC1B;AACD;;AAED,mCAAmBT,YAAY,CAACS,OAAD,CAAZ,EAAnB;AAAA,UAAQgB,MAAR,0BAAQA,MAAR;;AACAA,MAAAA,MAAM,CAAC,mCAAWd,GAAZ,CAAN;AACD;;;WAQD,kBAASe,IAAT,EAAeC,WAAf,EAA4B;AAC1B3B,MAAAA,YAAY,CAAC0B,IAAD,CAAZ,GAAqBC,WAArB;AACD;;;WAOD,oBAAWD,IAAX,EAAiB;AACf,aAAO1B,YAAY,CAAC0B,IAAD,CAAnB;AACD;;;;;;SAnHkBnB,Q","sourcesContent":["import usePointer from '../../../services/pointer.js';\nimport useRaf from '../../../services/raf.js';\nimport useResize from '../../../services/resize.js';\nimport useScroll from '../../../services/scroll.js';\nimport useKey from '../../../services/key.js';\nimport useLoad from '../../../services/load.js';\nimport { hasMethod, callMethod } from '../utils.js';\n\n/**\n * @typedef {import('../index').default} Base\n * @typedef {import('../../../services').ServiceInterface} ServiceInterface\n */\n\n/**\n * @type {Record<string, () => ServiceInterface>}\n */\nconst SERVICES_MAP = {\n scrolled: useScroll,\n resized: useResize,\n ticked: useRaf,\n moved: usePointer,\n keyed: useKey,\n loaded: useLoad,\n};\n\n/**\n * @typedef {keyof SERVICES_MAP} ServiceName\n */\n\n/**\n * Services management for the Base class.\n */\nexport default class Services {\n /** @type {Base} */\n #base;\n\n /**\n * Class constructor.\n * @param {Base} instance The Base instance.\n */\n constructor(instance) {\n this.#base = instance;\n }\n\n /**\n * Test if the given service is registered.\n *\n * @param {ServiceName} service The name of the service.\n * @return {Boolean}\n */\n has(service) {\n if (!hasMethod(this.#base, service) && !SERVICES_MAP[service]) {\n return false;\n }\n\n const { has } = SERVICES_MAP[service]();\n return has(this.#base.$id);\n }\n\n /**\n * Init the given service and bind it to the given instance.\n *\n * @param {ServiceName} service The name of the service.\n * @return {() => void} A function to unbind the service.\n */\n enable(service) {\n if (this.has(service)) {\n return this.disable.bind(this, service);\n }\n\n if (!hasMethod(this.#base, service) || !SERVICES_MAP[service]) {\n return function noop() {};\n }\n\n const { add } = SERVICES_MAP[service]();\n const self = this;\n\n /**\n * @param {any[]} args\n */\n function serviceHandler(...args) {\n callMethod(self.#base, service, ...args);\n }\n\n add(this.#base.$id, serviceHandler);\n\n return this.disable.bind(this, service);\n }\n\n /**\n * Enable all services and return methods to disable them.\n *\n * @return {Function[]}\n */\n enableAll() {\n return Object.keys(SERVICES_MAP).map(\n /** @param {ServiceName} serviceName */\n (serviceName) => this.enable(serviceName)\n );\n }\n\n /**\n * Disable all services.\n *\n * @return {void}\n */\n disableAll() {\n Object.keys(SERVICES_MAP).forEach(\n /** @param {ServiceName} serviceName */\n (serviceName) => {\n this.disable(serviceName);\n }\n );\n }\n\n /**\n * Disable a service.\n *\n * @param {String} service The name of the service.\n * @return {void}\n */\n disable(service) {\n if (!SERVICES_MAP[service]) {\n return;\n }\n\n const { remove } = SERVICES_MAP[service]();\n remove(this.#base.$id);\n }\n\n /**\n * Register a new service to be enabled/disabled.\n *\n * @param {string} name The name of the service hook.\n * @param {() => ServiceInterface} useFunction The `use...` function for the service.\n */\n register(name, useFunction) {\n SERVICES_MAP[name] = useFunction;\n }\n\n /**\n * Unregister a new service to be enabled disabled.\n *\n * @param {string} name The name of the service hooK\n */\n unregister(name) {\n delete SERVICES_MAP[name];\n }\n}\n"],"file":"Services.js"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Mount children components of a given instance.
|
|
3
|
-
*
|
|
4
|
-
* @param {Base} instance The parent component's instance.
|
|
5
|
-
* @return {void}
|
|
6
|
-
*/
|
|
7
|
-
export function mountComponents(instance: Base): void;
|
|
8
|
-
/**
|
|
9
|
-
* Mount or updte children components of the given instance.
|
|
10
|
-
*
|
|
11
|
-
* @param {Base} instance The parent component's instance.
|
|
12
|
-
* @return {void}
|
|
13
|
-
*/
|
|
14
|
-
export function mountOrUpdateComponents(instance: Base): void;
|
|
15
|
-
/**
|
|
16
|
-
* Destroy children components of a given instance.
|
|
17
|
-
*
|
|
18
|
-
* @param {Base} instance The parent component's instance.
|
|
19
|
-
* @return {void}
|
|
20
|
-
*/
|
|
21
|
-
export function destroyComponents(instance: Base): void;
|
|
22
|
-
export type Base = import('./index.js').default;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { debug } from './utils.js';
|
|
2
|
-
|
|
3
|
-
function mountComponent(component) {
|
|
4
|
-
if (component instanceof Promise) {
|
|
5
|
-
component.then(function (instance) {
|
|
6
|
-
return instance.$mount();
|
|
7
|
-
});
|
|
8
|
-
} else {
|
|
9
|
-
component.$mount();
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function mountComponents(instance) {
|
|
14
|
-
if (__DEV__) {
|
|
15
|
-
debug(instance, 'mountComponents', instance.$children);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
Object.values(instance.$children).forEach(function ($child) {
|
|
19
|
-
if (__DEV__) {
|
|
20
|
-
debug(instance, 'mountComponent', $child);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
$child.forEach(mountComponent);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function mountOrUpdateComponent(component) {
|
|
28
|
-
if (component instanceof Promise) {
|
|
29
|
-
component.then(function (instance) {
|
|
30
|
-
return instance.$isMounted ? instance.$update() : instance.$mount();
|
|
31
|
-
});
|
|
32
|
-
} else {
|
|
33
|
-
var method = component.$isMounted ? '$update' : '$mount';
|
|
34
|
-
component[method]();
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function mountOrUpdateComponents(instance) {
|
|
39
|
-
if (__DEV__) {
|
|
40
|
-
debug(instance, 'mountComponents', instance.$children);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
Object.values(instance.$children).forEach(function ($child) {
|
|
44
|
-
$child.forEach(mountOrUpdateComponent);
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function destroyComponent(component) {
|
|
49
|
-
if (component instanceof Promise) {
|
|
50
|
-
component.then(function (instance) {
|
|
51
|
-
return instance.$destroy();
|
|
52
|
-
});
|
|
53
|
-
} else {
|
|
54
|
-
component.$destroy();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function destroyComponents(instance) {
|
|
59
|
-
if (__DEV__) {
|
|
60
|
-
debug(instance, 'destroyComponents', instance.$children);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
Object.values(instance.$children).forEach(function ($child) {
|
|
64
|
-
$child.forEach(destroyComponent);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
//# sourceMappingURL=components.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../packages/js-toolkit/abstracts/Base/components.js"],"names":["debug","mountComponent","component","Promise","then","instance","$mount","mountComponents","__DEV__","$children","Object","values","forEach","$child","mountOrUpdateComponent","$isMounted","$update","method","mountOrUpdateComponents","destroyComponent","$destroy","destroyComponents"],"mappings":"AAAA,SAASA,KAAT,QAAsB,YAAtB;;AAYA,SAASC,cAAT,CAAwBC,SAAxB,EAAmC;AACjC,MAAIA,SAAS,YAAYC,OAAzB,EAAkC;AAChCD,IAAAA,SAAS,CAACE,IAAV,CAAe,UAACC,QAAD;AAAA,aAAcA,QAAQ,CAACC,MAAT,EAAd;AAAA,KAAf;AACD,GAFD,MAEO;AACLJ,IAAAA,SAAS,CAACI,MAAV;AACD;AACF;;AAQD,OAAO,SAASC,eAAT,CAAyBF,QAAzB,EAAmC;AACxC,MAAIG,OAAJ,EAAa;AACXR,IAAAA,KAAK,CAACK,QAAD,EAAW,iBAAX,EAA8BA,QAAQ,CAACI,SAAvC,CAAL;AACD;;AAEDC,EAAAA,MAAM,CAACC,MAAP,CAAcN,QAAQ,CAACI,SAAvB,EAAkCG,OAAlC,CAA0C,UAACC,MAAD,EAAY;AACpD,QAAIL,OAAJ,EAAa;AACXR,MAAAA,KAAK,CAACK,QAAD,EAAW,gBAAX,EAA6BQ,MAA7B,CAAL;AACD;;AACDA,IAAAA,MAAM,CAACD,OAAP,CAAeX,cAAf;AACD,GALD;AAMD;;AAQD,SAASa,sBAAT,CAAgCZ,SAAhC,EAA2C;AACzC,MAAIA,SAAS,YAAYC,OAAzB,EAAkC;AAChCD,IAAAA,SAAS,CAACE,IAAV,CAAe,UAACC,QAAD;AAAA,aAAeA,QAAQ,CAACU,UAAT,GAAsBV,QAAQ,CAACW,OAAT,EAAtB,GAA2CX,QAAQ,CAACC,MAAT,EAA1D;AAAA,KAAf;AACD,GAFD,MAEO;AACL,QAAMW,MAAM,GAAGf,SAAS,CAACa,UAAV,GAAuB,SAAvB,GAAmC,QAAlD;AACAb,IAAAA,SAAS,CAACe,MAAD,CAAT;AACD;AACF;;AAQD,OAAO,SAASC,uBAAT,CAAiCb,QAAjC,EAA2C;AAChD,MAAIG,OAAJ,EAAa;AACXR,IAAAA,KAAK,CAACK,QAAD,EAAW,iBAAX,EAA8BA,QAAQ,CAACI,SAAvC,CAAL;AACD;;AAEDC,EAAAA,MAAM,CAACC,MAAP,CAAcN,QAAQ,CAACI,SAAvB,EAAkCG,OAAlC,CAA0C,UAACC,MAAD,EAAY;AACpDA,IAAAA,MAAM,CAACD,OAAP,CAAeE,sBAAf;AACD,GAFD;AAGD;;AAQD,SAASK,gBAAT,CAA0BjB,SAA1B,EAAqC;AACnC,MAAIA,SAAS,YAAYC,OAAzB,EAAkC;AAChCD,IAAAA,SAAS,CAACE,IAAV,CAAe,UAACC,QAAD;AAAA,aAAcA,QAAQ,CAACe,QAAT,EAAd;AAAA,KAAf;AACD,GAFD,MAEO;AACLlB,IAAAA,SAAS,CAACkB,QAAV;AACD;AACF;;AAQD,OAAO,SAASC,iBAAT,CAA2BhB,QAA3B,EAAqC;AAC1C,MAAIG,OAAJ,EAAa;AACXR,IAAAA,KAAK,CAACK,QAAD,EAAW,mBAAX,EAAgCA,QAAQ,CAACI,SAAzC,CAAL;AACD;;AAEDC,EAAAA,MAAM,CAACC,MAAP,CAAcN,QAAQ,CAACI,SAAvB,EAAkCG,OAAlC,CAIE,UAACC,MAAD,EAAY;AACVA,IAAAA,MAAM,CAACD,OAAP,CAAeO,gBAAf;AACD,GANH;AAQD","sourcesContent":["import { debug } from './utils.js';\n\n/**\n * @typedef {import('./index.js').default} Base\n */\n\n/**\n * Mount a given component which might be async.\n *\n * @param {Base|Promise<Base>} component The component to mount.\n * @return {void}\n */\nfunction mountComponent(component) {\n if (component instanceof Promise) {\n component.then((instance) => instance.$mount());\n } else {\n component.$mount();\n }\n}\n\n/**\n * Mount children components of a given instance.\n *\n * @param {Base} instance The parent component's instance.\n * @return {void}\n */\nexport function mountComponents(instance) {\n if (__DEV__) {\n debug(instance, 'mountComponents', instance.$children);\n }\n\n Object.values(instance.$children).forEach(($child) => {\n if (__DEV__) {\n debug(instance, 'mountComponent', $child);\n }\n $child.forEach(mountComponent);\n });\n}\n\n/**\n * Mount or update the given component.\n *\n * @param {Base|Promise<Base>} component [description]\n * @return {void}\n */\nfunction mountOrUpdateComponent(component) {\n if (component instanceof Promise) {\n component.then((instance) => (instance.$isMounted ? instance.$update() : instance.$mount()));\n } else {\n const method = component.$isMounted ? '$update' : '$mount';\n component[method]();\n }\n}\n\n/**\n * Mount or updte children components of the given instance.\n *\n * @param {Base} instance The parent component's instance.\n * @return {void}\n */\nexport function mountOrUpdateComponents(instance) {\n if (__DEV__) {\n debug(instance, 'mountComponents', instance.$children);\n }\n\n Object.values(instance.$children).forEach(($child) => {\n $child.forEach(mountOrUpdateComponent);\n });\n}\n\n/**\n * Destroy a given component which might be async.\n *\n * @param {Base|Promise} component The component to destroy.\n * @return {void}\n */\nfunction destroyComponent(component) {\n if (component instanceof Promise) {\n component.then((instance) => instance.$destroy());\n } else {\n component.$destroy();\n }\n}\n\n/**\n * Destroy children components of a given instance.\n *\n * @param {Base} instance The parent component's instance.\n * @return {void}\n */\nexport function destroyComponents(instance) {\n if (__DEV__) {\n debug(instance, 'destroyComponents', instance.$children);\n }\n\n Object.values(instance.$children).forEach(\n /**\n * @param {Array<Base>} $child\n */\n ($child) => {\n $child.forEach(destroyComponent);\n }\n );\n}\n"],"file":"components.js"}
|