@studiometa/js-toolkit 2.0.0-beta.9 → 2.0.0
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.cjs +284 -0
- package/Base/index.d.ts +36 -28
- package/Base/index.js +113 -197
- package/Base/managers/ChildrenManager.cjs +146 -0
- package/Base/managers/ChildrenManager.d.ts +11 -3
- package/Base/managers/ChildrenManager.js +60 -59
- package/Base/managers/EventsManager.cjs +183 -0
- package/Base/managers/EventsManager.d.ts +13 -20
- package/Base/managers/EventsManager.js +72 -112
- package/Base/managers/OptionsManager.cjs +173 -0
- package/Base/managers/OptionsManager.d.ts +20 -13
- package/Base/managers/OptionsManager.js +60 -91
- package/Base/managers/RefsManager.cjs +99 -0
- package/Base/managers/RefsManager.d.ts +4 -4
- package/Base/managers/RefsManager.js +28 -38
- package/Base/managers/ServicesManager.cjs +134 -0
- package/Base/managers/ServicesManager.d.ts +14 -8
- package/Base/managers/ServicesManager.js +42 -67
- package/Base/utils.cjs +41 -0
- package/Base/utils.d.ts +4 -4
- package/Base/utils.js +12 -11
- package/decorators/index.cjs +45 -0
- package/decorators/index.d.ts +1 -0
- package/decorators/index.js +20 -8
- package/decorators/withBreakpointManager.cjs +84 -0
- package/decorators/withBreakpointManager.d.ts +2 -2
- package/decorators/withBreakpointManager.js +18 -40
- package/decorators/withBreakpointObserver.cjs +114 -0
- package/decorators/withBreakpointObserver.d.ts +1 -1
- package/decorators/withBreakpointObserver.js +45 -88
- package/decorators/withDrag.cjs +53 -0
- package/decorators/withDrag.d.ts +1 -1
- package/decorators/withDrag.js +24 -26
- package/decorators/withExtraConfig.cjs +43 -0
- package/decorators/withExtraConfig.d.ts +1 -1
- package/decorators/withExtraConfig.js +17 -12
- package/decorators/withFreezedOptions.cjs +37 -0
- package/decorators/withFreezedOptions.d.ts +14 -0
- package/decorators/withFreezedOptions.js +15 -0
- package/decorators/withIntersectionObserver.cjs +61 -0
- package/decorators/withIntersectionObserver.d.ts +1 -1
- package/decorators/withIntersectionObserver.js +29 -33
- package/decorators/withMountWhenInView.cjs +68 -0
- package/decorators/withMountWhenInView.d.ts +1 -1
- package/decorators/withMountWhenInView.js +31 -53
- package/decorators/withScrolledInView.cjs +114 -0
- package/decorators/withScrolledInView.d.ts +1 -1
- package/decorators/withScrolledInView.js +35 -39
- package/decorators/withVue2.cjs +61 -0
- package/decorators/withVue2.js +27 -32
- package/helpers/createApp.cjs +52 -0
- package/helpers/createApp.d.ts +3 -26
- package/helpers/createApp.js +12 -12
- package/helpers/getInstanceFromElement.cjs +32 -0
- package/helpers/getInstanceFromElement.d.ts +14 -0
- package/helpers/getInstanceFromElement.js +10 -0
- package/helpers/importOnInteraction.cjs +52 -0
- package/helpers/importOnInteraction.d.ts +3 -5
- package/helpers/importOnInteraction.js +17 -18
- package/helpers/importWhenIdle.cjs +49 -0
- package/helpers/importWhenIdle.d.ts +3 -5
- package/helpers/importWhenIdle.js +14 -17
- package/helpers/importWhenVisible.cjs +50 -0
- package/helpers/importWhenVisible.d.ts +4 -6
- package/helpers/importWhenVisible.js +16 -18
- package/helpers/index.cjs +37 -0
- package/helpers/index.d.ts +1 -0
- package/helpers/index.js +12 -4
- package/helpers/utils.cjs +35 -0
- package/helpers/utils.d.ts +3 -4
- package/helpers/utils.js +7 -6
- package/index.cjs +33 -0
- package/index.js +7 -4
- package/package.json +14 -4
- package/services/Service.cjs +76 -0
- package/services/Service.d.ts +9 -9
- package/services/Service.js +19 -32
- package/services/drag.cjs +212 -0
- package/services/drag.d.ts +3 -2
- package/services/drag.js +64 -69
- package/services/index.cjs +41 -0
- package/services/index.js +16 -7
- package/services/key.cjs +104 -0
- package/services/key.d.ts +1 -1
- package/services/key.js +28 -36
- package/services/load.cjs +72 -0
- package/services/load.d.ts +1 -1
- package/services/load.js +17 -19
- package/services/pointer.cjs +162 -0
- package/services/pointer.d.ts +1 -1
- package/services/pointer.js +43 -60
- package/services/raf.cjs +83 -0
- package/services/raf.d.ts +1 -1
- package/services/raf.js +20 -28
- package/services/resize.cjs +108 -0
- package/services/resize.d.ts +1 -1
- package/services/resize.js +33 -42
- package/services/scroll.cjs +131 -0
- package/services/scroll.d.ts +1 -1
- package/services/scroll.js +26 -35
- package/utils/collide/boundingRectToCircle.cjs +34 -0
- package/utils/collide/boundingRectToCircle.d.ts +6 -6
- package/utils/collide/boundingRectToCircle.js +7 -10
- package/utils/collide/collideCircleCircle.cjs +34 -0
- package/utils/collide/collideCircleCircle.d.ts +4 -4
- package/utils/collide/collideCircleCircle.js +8 -7
- package/utils/collide/collideCircleRect.cjs +46 -0
- package/utils/collide/collideCircleRect.d.ts +8 -8
- package/utils/collide/collideCircleRect.js +10 -12
- package/utils/collide/collidePointCircle.cjs +31 -0
- package/utils/collide/collidePointCircle.d.ts +6 -6
- package/utils/collide/collidePointCircle.js +8 -5
- package/utils/collide/collidePointRect.cjs +28 -0
- package/utils/collide/collidePointRect.d.ts +7 -7
- package/utils/collide/collidePointRect.js +5 -2
- package/utils/collide/collideRectRect.cjs +28 -0
- package/utils/collide/collideRectRect.d.ts +5 -5
- package/utils/collide/collideRectRect.js +5 -2
- package/utils/collide/index.cjs +39 -0
- package/utils/collide/index.js +14 -6
- package/utils/css/classes.cjs +47 -0
- package/utils/css/classes.d.ts +13 -12
- package/utils/css/classes.js +19 -15
- package/utils/css/index.cjs +38 -0
- package/utils/css/index.d.ts +2 -2
- package/utils/css/index.js +13 -6
- package/utils/css/matrix.cjs +30 -0
- package/utils/css/matrix.d.ts +14 -15
- package/utils/css/matrix.js +7 -5
- package/utils/css/styles.cjs +44 -0
- package/utils/css/styles.d.ts +8 -20
- package/utils/css/styles.js +12 -12
- package/utils/css/transition.cjs +120 -0
- package/utils/css/transition.d.ts +15 -9
- package/utils/css/transition.js +70 -119
- package/utils/debounce.cjs +34 -0
- package/utils/debounce.d.ts +4 -4
- package/utils/debounce.js +7 -9
- package/utils/focusTrap.cjs +82 -0
- package/utils/focusTrap.d.ts +1 -0
- package/utils/focusTrap.js +31 -22
- package/utils/history.cjs +89 -0
- package/utils/history.d.ts +13 -11
- package/utils/history.js +28 -57
- package/utils/index.cjs +54 -0
- package/utils/index.d.ts +4 -1
- package/utils/index.js +32 -11
- package/utils/keyCodes.cjs +35 -0
- package/utils/keyCodes.js +5 -2
- package/utils/math/clamp.cjs +28 -0
- package/utils/math/clamp.d.ts +1 -1
- package/utils/math/clamp.js +5 -2
- package/utils/math/clamp01.cjs +32 -0
- package/utils/math/clamp01.d.ts +1 -1
- package/utils/math/clamp01.js +6 -3
- package/utils/math/damp.cjs +28 -0
- package/utils/math/damp.d.ts +6 -6
- package/utils/math/damp.js +5 -4
- package/utils/math/ease.cjs +88 -0
- package/utils/math/ease.d.ts +7 -7
- package/utils/math/ease.js +50 -25
- package/utils/math/index.cjs +43 -0
- package/utils/math/index.js +17 -8
- package/utils/math/inertiaFinalValue.cjs +37 -0
- package/utils/math/inertiaFinalValue.d.ts +5 -5
- package/utils/math/inertiaFinalValue.js +8 -10
- package/utils/math/lerp.cjs +28 -0
- package/utils/math/lerp.d.ts +4 -4
- package/utils/math/lerp.js +5 -2
- package/utils/math/map.cjs +28 -0
- package/utils/math/map.d.ts +6 -6
- package/utils/math/map.js +5 -2
- package/utils/math/round.cjs +28 -0
- package/utils/math/round.d.ts +4 -4
- package/utils/math/round.js +5 -3
- package/utils/memoize.cjs +43 -0
- package/utils/memoize.d.ts +1 -1
- package/utils/memoize.js +10 -19
- package/utils/nextFrame.cjs +38 -0
- package/utils/nextFrame.d.ts +6 -6
- package/utils/nextFrame.js +13 -10
- package/utils/nextMicrotask.cjs +28 -0
- package/utils/nextMicrotask.d.ts +8 -0
- package/utils/nextMicrotask.js +6 -0
- package/utils/nextTick.cjs +30 -0
- package/utils/nextTick.d.ts +8 -0
- package/utils/nextTick.js +8 -0
- package/utils/object/autoBind.cjs +49 -0
- package/utils/object/autoBind.d.ts +3 -3
- package/utils/object/autoBind.js +12 -22
- package/utils/object/getAllProperties.cjs +37 -0
- package/utils/object/getAllProperties.d.ts +3 -3
- package/utils/object/getAllProperties.js +10 -13
- package/utils/object/index.cjs +33 -0
- package/utils/object/index.js +8 -3
- package/utils/object/isObject.cjs +28 -0
- package/utils/object/isObject.d.ts +1 -1
- package/utils/object/isObject.js +6 -3
- package/utils/scrollTo.cjs +80 -0
- package/utils/scrollTo.d.ts +1 -1
- package/utils/scrollTo.js +20 -40
- package/utils/string/index.cjs +47 -0
- package/utils/string/index.js +22 -10
- package/utils/string/withLeadingCharacters.cjs +32 -0
- package/utils/string/withLeadingCharacters.d.ts +3 -2
- package/utils/string/withLeadingCharacters.js +7 -4
- package/utils/string/withLeadingSlash.cjs +32 -0
- package/utils/string/withLeadingSlash.d.ts +1 -1
- package/utils/string/withLeadingSlash.js +7 -4
- package/utils/string/withTrailingCharacters.cjs +32 -0
- package/utils/string/withTrailingCharacters.d.ts +3 -2
- package/utils/string/withTrailingCharacters.js +7 -4
- package/utils/string/withTrailingSlash.cjs +32 -0
- package/utils/string/withTrailingSlash.d.ts +1 -1
- package/utils/string/withTrailingSlash.js +7 -4
- package/utils/string/withoutLeadingCharacters.cjs +28 -0
- package/utils/string/withoutLeadingCharacters.d.ts +3 -2
- package/utils/string/withoutLeadingCharacters.js +6 -3
- package/utils/string/withoutLeadingCharactersRecursive.cjs +37 -0
- package/utils/string/withoutLeadingCharactersRecursive.d.ts +3 -2
- package/utils/string/withoutLeadingCharactersRecursive.js +8 -7
- package/utils/string/withoutLeadingSlash.cjs +32 -0
- package/utils/string/withoutLeadingSlash.d.ts +1 -1
- package/utils/string/withoutLeadingSlash.js +7 -4
- package/utils/string/withoutTrailingCharacters.cjs +28 -0
- package/utils/string/withoutTrailingCharacters.d.ts +3 -2
- package/utils/string/withoutTrailingCharacters.js +6 -3
- package/utils/string/withoutTrailingCharactersRecursive.cjs +37 -0
- package/utils/string/withoutTrailingCharactersRecursive.d.ts +3 -2
- package/utils/string/withoutTrailingCharactersRecursive.js +8 -7
- package/utils/string/withoutTrailingSlash.cjs +32 -0
- package/utils/string/withoutTrailingSlash.d.ts +1 -1
- package/utils/string/withoutTrailingSlash.js +7 -4
- package/utils/throttle.cjs +36 -0
- package/utils/throttle.d.ts +3 -3
- package/utils/throttle.js +9 -9
- package/index.modern.js +0 -1
- package/index.umd.js +0 -1
package/Base/index.cjs
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var __publicField = (obj, key, value) => {
|
|
23
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
24
|
+
return value;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// packages/js-toolkit/Base/index.js
|
|
28
|
+
var Base_exports = {};
|
|
29
|
+
__export(Base_exports, {
|
|
30
|
+
default: () => Base
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(Base_exports);
|
|
33
|
+
var import_utils = require("./utils.cjs");
|
|
34
|
+
var import_ChildrenManager = __toESM(require("./managers/ChildrenManager.cjs"), 1);
|
|
35
|
+
var import_RefsManager = __toESM(require("./managers/RefsManager.cjs"), 1);
|
|
36
|
+
var import_ServicesManager = __toESM(require("./managers/ServicesManager.cjs"), 1);
|
|
37
|
+
var import_EventsManager = __toESM(require("./managers/EventsManager.cjs"), 1);
|
|
38
|
+
var import_OptionsManager = __toESM(require("./managers/OptionsManager.cjs"), 1);
|
|
39
|
+
var id = 0;
|
|
40
|
+
var isDev = typeof __DEV__ !== "undefined" && __DEV__;
|
|
41
|
+
function noop() {
|
|
42
|
+
}
|
|
43
|
+
var Base = class extends EventTarget {
|
|
44
|
+
constructor(element) {
|
|
45
|
+
super();
|
|
46
|
+
__publicField(this, "$parent", null);
|
|
47
|
+
__publicField(this, "$id");
|
|
48
|
+
__publicField(this, "$el");
|
|
49
|
+
__publicField(this, "$isMounted", false);
|
|
50
|
+
__publicField(this, "__eventHandlers", /* @__PURE__ */ new Map());
|
|
51
|
+
__publicField(this, "__services");
|
|
52
|
+
__publicField(this, "__refs");
|
|
53
|
+
__publicField(this, "__options");
|
|
54
|
+
__publicField(this, "__children");
|
|
55
|
+
__publicField(this, "__events");
|
|
56
|
+
if (!element) {
|
|
57
|
+
throw new Error("The root element must be defined.");
|
|
58
|
+
}
|
|
59
|
+
const { __config } = this;
|
|
60
|
+
if (__config.name === "Base") {
|
|
61
|
+
throw new Error("The `config.name` property is required.");
|
|
62
|
+
}
|
|
63
|
+
this.$id = `${__config.name}-${id}`;
|
|
64
|
+
id += 1;
|
|
65
|
+
this.$el = element;
|
|
66
|
+
if (!this.$el.__base__) {
|
|
67
|
+
this.$el.__base__ = /* @__PURE__ */ new WeakMap();
|
|
68
|
+
}
|
|
69
|
+
this.$el.__base__.set(this.__ctor, this);
|
|
70
|
+
this.__options = new import_OptionsManager.default(element, __config.options || {}, __config);
|
|
71
|
+
this.__services = new import_ServicesManager.default(this);
|
|
72
|
+
this.__events = new import_EventsManager.default(element, this);
|
|
73
|
+
this.__children = new import_ChildrenManager.default(this, element, __config.components || {}, this.__events);
|
|
74
|
+
this.__refs = new import_RefsManager.default(this, element, __config.refs || [], this.__events);
|
|
75
|
+
if (isDev) {
|
|
76
|
+
this.__debug("constructor", this);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
get $root() {
|
|
80
|
+
if (!this.$parent) {
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
let parent = this.$parent;
|
|
84
|
+
let root = this.$parent;
|
|
85
|
+
while (parent) {
|
|
86
|
+
if (!parent.$parent) {
|
|
87
|
+
root = parent;
|
|
88
|
+
}
|
|
89
|
+
parent = parent.$parent;
|
|
90
|
+
}
|
|
91
|
+
return root;
|
|
92
|
+
}
|
|
93
|
+
get __config() {
|
|
94
|
+
let proto = Object.getPrototypeOf(this);
|
|
95
|
+
let { config } = proto.constructor;
|
|
96
|
+
while (proto.constructor.config && proto.constructor.$isBase) {
|
|
97
|
+
config = {
|
|
98
|
+
...proto.constructor.config,
|
|
99
|
+
...config
|
|
100
|
+
};
|
|
101
|
+
if (proto.constructor.config.options) {
|
|
102
|
+
config.options = {
|
|
103
|
+
...proto.constructor.config.options,
|
|
104
|
+
...config.options
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (proto.constructor.config.emits && config.emits) {
|
|
108
|
+
config.emits = [...proto.constructor.config.emits, ...config.emits];
|
|
109
|
+
}
|
|
110
|
+
proto = Object.getPrototypeOf(proto);
|
|
111
|
+
}
|
|
112
|
+
return config;
|
|
113
|
+
}
|
|
114
|
+
get $services() {
|
|
115
|
+
return this.__services;
|
|
116
|
+
}
|
|
117
|
+
get $refs() {
|
|
118
|
+
return this.__refs;
|
|
119
|
+
}
|
|
120
|
+
get $options() {
|
|
121
|
+
return this.__options;
|
|
122
|
+
}
|
|
123
|
+
get $children() {
|
|
124
|
+
return this.__children;
|
|
125
|
+
}
|
|
126
|
+
get $log() {
|
|
127
|
+
return this.__options.log ? window.console.log.bind(window, `[${this.__config.name}]`) : noop;
|
|
128
|
+
}
|
|
129
|
+
get __debug() {
|
|
130
|
+
return isDev && this.__options.debug ? window.console.log.bind(window, `[debug] [${this.$id}]`) : noop;
|
|
131
|
+
}
|
|
132
|
+
__callMethod(method, ...args) {
|
|
133
|
+
if (isDev) {
|
|
134
|
+
this.__debug("callMethod", method, ...args);
|
|
135
|
+
}
|
|
136
|
+
this.$emit(method, ...args);
|
|
137
|
+
if (typeof this[method] !== "function") {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
this[method].call(this, ...args);
|
|
141
|
+
if (isDev) {
|
|
142
|
+
this.__debug(method, this, ...args);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
__hasEvent(event) {
|
|
146
|
+
const eventHandlers = this.__eventHandlers.get(event);
|
|
147
|
+
return eventHandlers && eventHandlers.size > 0;
|
|
148
|
+
}
|
|
149
|
+
$mount() {
|
|
150
|
+
if (this.$isMounted) {
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
this.$isMounted = true;
|
|
154
|
+
if (isDev) {
|
|
155
|
+
this.__debug("$mount");
|
|
156
|
+
}
|
|
157
|
+
this.$children.registerAll();
|
|
158
|
+
this.$refs.registerAll();
|
|
159
|
+
this.__events.bindRootElement();
|
|
160
|
+
this.$services.enableAll();
|
|
161
|
+
this.$children.mountAll();
|
|
162
|
+
this.__callMethod("mounted");
|
|
163
|
+
return this;
|
|
164
|
+
}
|
|
165
|
+
$update() {
|
|
166
|
+
if (isDev) {
|
|
167
|
+
this.__debug("$update");
|
|
168
|
+
}
|
|
169
|
+
this.$refs.unregisterAll();
|
|
170
|
+
this.$services.disableAll();
|
|
171
|
+
this.$children.registerAll();
|
|
172
|
+
this.$refs.registerAll();
|
|
173
|
+
this.$services.enableAll();
|
|
174
|
+
this.$children.updateAll();
|
|
175
|
+
this.__callMethod("updated");
|
|
176
|
+
return this;
|
|
177
|
+
}
|
|
178
|
+
$destroy() {
|
|
179
|
+
if (!this.$isMounted) {
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
this.$isMounted = false;
|
|
183
|
+
if (isDev) {
|
|
184
|
+
this.__debug("$destroy");
|
|
185
|
+
}
|
|
186
|
+
this.__events.unbindRootElement();
|
|
187
|
+
this.$refs.unregisterAll();
|
|
188
|
+
this.$services.disableAll();
|
|
189
|
+
this.$children.destroyAll();
|
|
190
|
+
this.__callMethod("destroyed");
|
|
191
|
+
return this;
|
|
192
|
+
}
|
|
193
|
+
$terminate() {
|
|
194
|
+
if (isDev) {
|
|
195
|
+
this.__debug("$terminate");
|
|
196
|
+
}
|
|
197
|
+
this.$destroy();
|
|
198
|
+
this.__callMethod("terminated");
|
|
199
|
+
this.$el.__base__.set(this.__ctor, "terminated");
|
|
200
|
+
}
|
|
201
|
+
__testEventIsDefined(event) {
|
|
202
|
+
if (!(Array.isArray(this.__config.emits) && this.__config.emits.includes(event))) {
|
|
203
|
+
console.warn(`[${this.__config.name}]`, `The "${event}" event is missing from the configuration.`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
__addEmits(event) {
|
|
207
|
+
const ctor = this.__ctor;
|
|
208
|
+
if (Array.isArray(ctor.config.emits)) {
|
|
209
|
+
ctor.config.emits.push(event);
|
|
210
|
+
} else {
|
|
211
|
+
ctor.config.emits = [event];
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
__removeEmits(event) {
|
|
215
|
+
const ctor = this.__ctor;
|
|
216
|
+
const index = ctor.config.emits.indexOf(event);
|
|
217
|
+
ctor.config.emits.splice(index, 1);
|
|
218
|
+
}
|
|
219
|
+
get __ctor() {
|
|
220
|
+
return this.constructor;
|
|
221
|
+
}
|
|
222
|
+
$on(event, listener, options) {
|
|
223
|
+
if (isDev) {
|
|
224
|
+
this.__debug("$on", event, listener, options);
|
|
225
|
+
}
|
|
226
|
+
if (isDev) {
|
|
227
|
+
this.__testEventIsDefined(event);
|
|
228
|
+
}
|
|
229
|
+
let set = this.__eventHandlers.get(event);
|
|
230
|
+
if (!set) {
|
|
231
|
+
set = /* @__PURE__ */ new Set();
|
|
232
|
+
this.__eventHandlers.set(event, set);
|
|
233
|
+
}
|
|
234
|
+
set.add(listener);
|
|
235
|
+
this.addEventListener(event, listener, options);
|
|
236
|
+
return () => {
|
|
237
|
+
this.$off(event, listener, options);
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
$off(event, listener, options) {
|
|
241
|
+
if (isDev) {
|
|
242
|
+
this.__debug("$off", event, listener);
|
|
243
|
+
}
|
|
244
|
+
if (isDev) {
|
|
245
|
+
this.__testEventIsDefined(event);
|
|
246
|
+
}
|
|
247
|
+
this.__eventHandlers.get(event).delete(listener);
|
|
248
|
+
this.removeEventListener(event, listener, options);
|
|
249
|
+
}
|
|
250
|
+
$emit(event, ...args) {
|
|
251
|
+
if (isDev) {
|
|
252
|
+
this.__debug("$emit", event, args);
|
|
253
|
+
}
|
|
254
|
+
if (isDev) {
|
|
255
|
+
this.__testEventIsDefined(event);
|
|
256
|
+
}
|
|
257
|
+
this.dispatchEvent(new CustomEvent(event, {
|
|
258
|
+
detail: args
|
|
259
|
+
}));
|
|
260
|
+
}
|
|
261
|
+
static $factory(nameOrSelector) {
|
|
262
|
+
if (!nameOrSelector) {
|
|
263
|
+
throw new Error("The $factory method requires a component\u2019s name or selector to be specified.");
|
|
264
|
+
}
|
|
265
|
+
return (0, import_utils.getComponentElements)(nameOrSelector).map((el) => new this(el).$mount());
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
__publicField(Base, "$isBase", true);
|
|
269
|
+
__publicField(Base, "config", {
|
|
270
|
+
name: "Base",
|
|
271
|
+
emits: [
|
|
272
|
+
"mounted",
|
|
273
|
+
"updated",
|
|
274
|
+
"destroyed",
|
|
275
|
+
"terminated",
|
|
276
|
+
"ticked",
|
|
277
|
+
"scrolled",
|
|
278
|
+
"resized",
|
|
279
|
+
"moved",
|
|
280
|
+
"loaded",
|
|
281
|
+
"keyed"
|
|
282
|
+
]
|
|
283
|
+
});
|
|
284
|
+
if (module.exports.default) module.exports = module.exports.default;
|
package/Base/index.d.ts
CHANGED
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
*/
|
|
11
11
|
/**
|
|
12
12
|
* @typedef {Object} BaseConfig
|
|
13
|
-
* @property {
|
|
14
|
-
* @property {
|
|
15
|
-
* @property {
|
|
16
|
-
* @property {
|
|
17
|
-
* @property {
|
|
13
|
+
* @property {string} name
|
|
14
|
+
* @property {boolean} [debug]
|
|
15
|
+
* @property {boolean} [log]
|
|
16
|
+
* @property {string[]} [refs]
|
|
17
|
+
* @property {string[]} [emits]
|
|
18
18
|
* @property {BaseConfigComponents} [components]
|
|
19
19
|
* @property {BaseConfigOptions} [options]
|
|
20
20
|
*/
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
export default class Base extends EventTarget {
|
|
25
25
|
/**
|
|
26
26
|
* This is a Base instance.
|
|
27
|
-
* @type {
|
|
27
|
+
* @type {boolean}
|
|
28
28
|
* @readonly
|
|
29
29
|
*/
|
|
30
30
|
static readonly $isBase: boolean;
|
|
@@ -35,8 +35,8 @@ export default class Base extends EventTarget {
|
|
|
35
35
|
/**
|
|
36
36
|
* Factory method to generate multiple instance of the class.
|
|
37
37
|
*
|
|
38
|
-
* @param {
|
|
39
|
-
* @
|
|
38
|
+
* @param {string} nameOrSelector The selector on which to mount each instance.
|
|
39
|
+
* @returns {Array<Base>} A list of the created instance.
|
|
40
40
|
*/
|
|
41
41
|
static $factory(nameOrSelector: string): Array<Base>;
|
|
42
42
|
/**
|
|
@@ -57,12 +57,14 @@ export default class Base extends EventTarget {
|
|
|
57
57
|
$id: string;
|
|
58
58
|
/**
|
|
59
59
|
* The root element.
|
|
60
|
-
* @type {HTMLElement}
|
|
60
|
+
* @type {HTMLElement & { __base__?: WeakMap<BaseConstructor, Base | 'terminated'> }}
|
|
61
61
|
*/
|
|
62
|
-
$el: HTMLElement
|
|
62
|
+
$el: HTMLElement & {
|
|
63
|
+
__base__?: WeakMap<BaseConstructor, Base | 'terminated'>;
|
|
64
|
+
};
|
|
63
65
|
/**
|
|
64
66
|
* The state of the component.
|
|
65
|
-
* @type {
|
|
67
|
+
* @type {boolean}
|
|
66
68
|
*/
|
|
67
69
|
$isMounted: boolean;
|
|
68
70
|
/**
|
|
@@ -74,13 +76,13 @@ export default class Base extends EventTarget {
|
|
|
74
76
|
private __eventHandlers;
|
|
75
77
|
/**
|
|
76
78
|
* Get the root instance of the app.
|
|
77
|
-
* @
|
|
79
|
+
* @returns {Base}
|
|
78
80
|
*/
|
|
79
81
|
get $root(): Base;
|
|
80
82
|
/**
|
|
81
83
|
* Merge configuration with the parents' configurations.
|
|
82
84
|
*
|
|
83
|
-
* @
|
|
85
|
+
* @returns {BaseConfig}
|
|
84
86
|
* @private
|
|
85
87
|
*/
|
|
86
88
|
private get __config();
|
|
@@ -99,7 +101,7 @@ export default class Base extends EventTarget {
|
|
|
99
101
|
*/
|
|
100
102
|
private __refs;
|
|
101
103
|
/**
|
|
102
|
-
* @
|
|
104
|
+
* @returns {RefsManager}
|
|
103
105
|
*/
|
|
104
106
|
get $refs(): RefsManager;
|
|
105
107
|
/**
|
|
@@ -108,7 +110,7 @@ export default class Base extends EventTarget {
|
|
|
108
110
|
*/
|
|
109
111
|
private __options;
|
|
110
112
|
/**
|
|
111
|
-
* @
|
|
113
|
+
* @returns {BaseOptions}
|
|
112
114
|
*/
|
|
113
115
|
get $options(): BaseOptions;
|
|
114
116
|
/**
|
|
@@ -117,7 +119,7 @@ export default class Base extends EventTarget {
|
|
|
117
119
|
*/
|
|
118
120
|
private __children;
|
|
119
121
|
/**
|
|
120
|
-
* @
|
|
122
|
+
* @returns {ChildrenManager}
|
|
121
123
|
*/
|
|
122
124
|
get $children(): ChildrenManager;
|
|
123
125
|
/**
|
|
@@ -128,14 +130,14 @@ export default class Base extends EventTarget {
|
|
|
128
130
|
/**
|
|
129
131
|
* Small helper to log stuff.
|
|
130
132
|
*
|
|
131
|
-
* @
|
|
133
|
+
* @returns {(...args: any) => void}
|
|
132
134
|
*/
|
|
133
135
|
get $log(): (...args: any) => void;
|
|
134
136
|
/**
|
|
135
137
|
* Small helper to debug information.
|
|
136
138
|
*
|
|
137
139
|
* @private
|
|
138
|
-
* @
|
|
140
|
+
* @returns {(...args:any) => void}
|
|
139
141
|
*/
|
|
140
142
|
private get __debug();
|
|
141
143
|
/**
|
|
@@ -144,7 +146,7 @@ export default class Base extends EventTarget {
|
|
|
144
146
|
* @private
|
|
145
147
|
* @param {string} method
|
|
146
148
|
* @param {any[]} args
|
|
147
|
-
* @
|
|
149
|
+
* @returns {void}
|
|
148
150
|
*/
|
|
149
151
|
private __callMethod;
|
|
150
152
|
/**
|
|
@@ -152,27 +154,27 @@ export default class Base extends EventTarget {
|
|
|
152
154
|
*
|
|
153
155
|
* @private
|
|
154
156
|
* @param {string} event The event's name.
|
|
155
|
-
* @
|
|
157
|
+
* @returns {boolean} Wether the given event has been bound or not.
|
|
156
158
|
*/
|
|
157
159
|
private __hasEvent;
|
|
158
160
|
/**
|
|
159
161
|
* Trigger the `mounted` callback.
|
|
160
|
-
* @
|
|
162
|
+
* @returns {this}
|
|
161
163
|
*/
|
|
162
164
|
$mount(): this;
|
|
163
165
|
/**
|
|
164
166
|
* Update the instance children.
|
|
165
|
-
* @
|
|
167
|
+
* @returns {this}
|
|
166
168
|
*/
|
|
167
169
|
$update(): this;
|
|
168
170
|
/**
|
|
169
171
|
* Trigger the `destroyed` callback.
|
|
170
|
-
* @
|
|
172
|
+
* @returns {this}
|
|
171
173
|
*/
|
|
172
174
|
$destroy(): this;
|
|
173
175
|
/**
|
|
174
176
|
* Terminate a child instance when it is not needed anymore.
|
|
175
|
-
* @
|
|
177
|
+
* @returns {void}
|
|
176
178
|
*/
|
|
177
179
|
$terminate(): void;
|
|
178
180
|
/**
|
|
@@ -199,6 +201,13 @@ export default class Base extends EventTarget {
|
|
|
199
201
|
* @returns {void}
|
|
200
202
|
*/
|
|
201
203
|
private __removeEmits;
|
|
204
|
+
/**
|
|
205
|
+
* Get the instance constructor.
|
|
206
|
+
*
|
|
207
|
+
* @private
|
|
208
|
+
* @returns {BaseConstructor}
|
|
209
|
+
*/
|
|
210
|
+
private get __ctor();
|
|
202
211
|
/**
|
|
203
212
|
* Bind a listener function to an event.
|
|
204
213
|
*
|
|
@@ -208,7 +217,7 @@ export default class Base extends EventTarget {
|
|
|
208
217
|
* Function to be called.
|
|
209
218
|
* @param {boolean|AddEventListenerOptions} [options]
|
|
210
219
|
* Options for the `removeEventListener` method.
|
|
211
|
-
* @
|
|
220
|
+
* @returns {() => void}
|
|
212
221
|
* A function to unbind the listener.
|
|
213
222
|
*/
|
|
214
223
|
$on(event: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): () => void;
|
|
@@ -221,8 +230,7 @@ export default class Base extends EventTarget {
|
|
|
221
230
|
* Function to be removed.
|
|
222
231
|
* @param {boolean|EventListenerOptions} [options]
|
|
223
232
|
* Options for the `removeEventListener` method.
|
|
224
|
-
*
|
|
225
|
-
* @return {void}
|
|
233
|
+
* @returns {void}
|
|
226
234
|
*/
|
|
227
235
|
$off(event: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
|
|
228
236
|
/**
|
|
@@ -231,7 +239,7 @@ export default class Base extends EventTarget {
|
|
|
231
239
|
* @param {string} event
|
|
232
240
|
* Name of the event.
|
|
233
241
|
* @param {any[]} args The arguments to apply to the functions bound to this event.
|
|
234
|
-
* @
|
|
242
|
+
* @returns {void}
|
|
235
243
|
*/
|
|
236
244
|
$emit(event: string, ...args: any[]): void;
|
|
237
245
|
}
|