@studiometa/js-toolkit 2.2.3 → 2.3.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 +60 -68
- package/Base/index.d.ts +0 -8
- package/Base/index.js +67 -81
- package/Base/managers/AbstractManager.cjs +5 -10
- package/Base/managers/AbstractManager.js +5 -11
- package/Base/managers/ChildrenManager.cjs +2 -11
- package/Base/managers/ChildrenManager.js +2 -12
- package/Base/managers/EventsManager.cjs +61 -67
- package/Base/managers/EventsManager.js +61 -68
- package/Base/managers/OptionsManager.cjs +26 -27
- package/Base/managers/OptionsManager.js +26 -28
- package/Base/managers/RefsManager.cjs +9 -7
- package/Base/managers/RefsManager.js +9 -7
- package/Base/managers/ResponsiveOptionsManager.cjs +4 -1
- package/Base/managers/ResponsiveOptionsManager.js +4 -1
- package/Base/managers/ServicesManager.cjs +6 -11
- package/Base/managers/ServicesManager.js +7 -13
- package/Base/utils.cjs +23 -1
- package/Base/utils.d.ts +25 -0
- package/Base/utils.js +23 -1
- package/decorators/withBreakpointManager.cjs +15 -5
- package/decorators/withBreakpointManager.js +15 -5
- package/decorators/withBreakpointObserver.cjs +19 -18
- package/decorators/withBreakpointObserver.js +19 -19
- package/decorators/withDrag.cjs +6 -11
- package/decorators/withDrag.js +6 -12
- package/decorators/withExtraConfig.cjs +3 -8
- package/decorators/withExtraConfig.js +3 -9
- package/decorators/withFreezedOptions.cjs +1 -9
- package/decorators/withFreezedOptions.js +1 -10
- package/decorators/withIntersectionObserver.cjs +11 -16
- package/decorators/withIntersectionObserver.js +11 -17
- package/decorators/withMountWhenInView.cjs +12 -17
- package/decorators/withMountWhenInView.js +12 -18
- package/decorators/withScrolledInView.cjs +30 -35
- package/decorators/withScrolledInView.js +30 -36
- package/decorators/withVue2.cjs +20 -18
- package/decorators/withVue2.js +20 -19
- package/helpers/getInstanceFromElement.cjs +1 -2
- package/helpers/getInstanceFromElement.js +1 -2
- package/helpers/importOnInteraction.cjs +3 -2
- package/helpers/importOnInteraction.js +3 -2
- package/helpers/importWhenIdle.cjs +2 -3
- package/helpers/importWhenIdle.js +2 -3
- package/helpers/importWhenVisible.cjs +3 -2
- package/helpers/importWhenVisible.js +3 -2
- package/helpers/utils.cjs +3 -2
- package/helpers/utils.js +3 -2
- package/package.json +4 -1
- package/services/key.cjs +1 -1
- package/services/key.js +1 -1
- package/services/pointer.cjs +2 -3
- package/services/pointer.js +2 -3
- package/services/raf.cjs +2 -5
- package/services/raf.js +1 -1
- package/utils/css/animate.cjs +33 -98
- package/utils/css/animate.d.ts +4 -16
- package/utils/css/animate.js +31 -96
- package/utils/css/classes.cjs +2 -1
- package/utils/css/classes.js +2 -1
- package/utils/css/matrix.cjs +1 -2
- package/utils/css/matrix.js +1 -2
- package/utils/css/styles.cjs +2 -5
- package/utils/css/styles.js +1 -1
- package/utils/css/transform.cjs +14 -18
- package/utils/css/transform.js +2 -3
- package/utils/css/transition.cjs +7 -10
- package/utils/css/transition.js +7 -11
- package/utils/focusTrap.cjs +2 -1
- package/utils/focusTrap.js +2 -1
- package/utils/{isFunction.cjs → has.cjs} +7 -7
- package/utils/has.d.ts +6 -0
- package/utils/has.js +6 -0
- package/utils/history.cjs +5 -7
- package/utils/history.js +4 -3
- package/utils/index.cjs +5 -5
- package/utils/index.d.ts +3 -2
- package/utils/index.js +5 -5
- package/utils/{isDefined.cjs → is.cjs} +20 -8
- package/utils/is.d.ts +8 -0
- package/utils/is.js +18 -0
- package/utils/math/inertiaFinalValue.cjs +5 -3
- package/utils/math/inertiaFinalValue.js +2 -3
- package/utils/nextFrame.cjs +5 -3
- package/utils/nextFrame.js +5 -3
- package/utils/nextMicrotask.cjs +2 -1
- package/utils/nextMicrotask.js +2 -1
- package/utils/nextTick.cjs +2 -1
- package/utils/nextTick.js +2 -1
- package/utils/object/autoBind.cjs +3 -2
- package/utils/object/autoBind.js +3 -2
- package/utils/object/getAllProperties.cjs +2 -1
- package/utils/object/getAllProperties.js +2 -1
- package/utils/object/index.cjs +1 -3
- package/utils/object/index.d.ts +0 -1
- package/utils/object/index.js +1 -3
- package/utils/tween.cjs +113 -0
- package/utils/tween.d.ts +25 -0
- package/utils/tween.js +88 -0
- package/utils/isDefined.d.ts +0 -7
- package/utils/isDefined.js +0 -6
- package/utils/isFunction.d.ts +0 -7
- package/utils/isFunction.js +0 -6
- package/utils/object/isObject.cjs +0 -28
- package/utils/object/isObject.d.ts +0 -7
- package/utils/object/isObject.js +0 -6
package/Base/index.cjs
CHANGED
|
@@ -36,9 +36,8 @@ var import_RefsManager = __toESM(require("./managers/RefsManager.cjs"), 1);
|
|
|
36
36
|
var import_ServicesManager = __toESM(require("./managers/ServicesManager.cjs"), 1);
|
|
37
37
|
var import_EventsManager = __toESM(require("./managers/EventsManager.cjs"), 1);
|
|
38
38
|
var import_OptionsManager = __toESM(require("./managers/OptionsManager.cjs"), 1);
|
|
39
|
-
var
|
|
39
|
+
var import_utils2 = require("../utils/index.cjs");
|
|
40
40
|
var id = 0;
|
|
41
|
-
var isDev = typeof __DEV__ !== "undefined" && __DEV__;
|
|
42
41
|
function createAndTestManagers(instance) {
|
|
43
42
|
[
|
|
44
43
|
{
|
|
@@ -68,43 +67,17 @@ function createAndTestManagers(instance) {
|
|
|
68
67
|
}
|
|
69
68
|
].forEach(({ prop, constructorName, constructor }) => {
|
|
70
69
|
instance[prop] = new instance.__managers[constructorName](instance);
|
|
71
|
-
if (!(instance[prop] instanceof constructor)) {
|
|
70
|
+
if (import_utils2.isDev && !(instance[prop] instanceof constructor)) {
|
|
72
71
|
throw new Error(`The \`$managers.${constructorName}\` must extend the \`${constructorName}\` class.`);
|
|
73
72
|
}
|
|
74
73
|
});
|
|
75
74
|
}
|
|
76
75
|
var Base = class extends EventTarget {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
__publicField(this, "$isMounted", false);
|
|
83
|
-
__publicField(this, "__eventHandlers", /* @__PURE__ */ new Map());
|
|
84
|
-
__publicField(this, "__services");
|
|
85
|
-
__publicField(this, "__refs");
|
|
86
|
-
__publicField(this, "__options");
|
|
87
|
-
__publicField(this, "__children");
|
|
88
|
-
__publicField(this, "__events");
|
|
89
|
-
if (!element) {
|
|
90
|
-
throw new Error("The root element must be defined.");
|
|
91
|
-
}
|
|
92
|
-
const { __config } = this;
|
|
93
|
-
if (__config.name === "Base") {
|
|
94
|
-
throw new Error("The `config.name` property is required.");
|
|
95
|
-
}
|
|
96
|
-
this.$id = `${__config.name}-${id}`;
|
|
97
|
-
id += 1;
|
|
98
|
-
this.$el = element;
|
|
99
|
-
if (!this.$el.__base__) {
|
|
100
|
-
this.$el.__base__ = /* @__PURE__ */ new WeakMap();
|
|
101
|
-
}
|
|
102
|
-
this.$el.__base__.set(this.__ctor, this);
|
|
103
|
-
createAndTestManagers(this);
|
|
104
|
-
if (isDev) {
|
|
105
|
-
this.__debug("constructor", this);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
76
|
+
$parent = null;
|
|
77
|
+
$id;
|
|
78
|
+
$el;
|
|
79
|
+
$isMounted = false;
|
|
80
|
+
__eventHandlers = /* @__PURE__ */ new Map();
|
|
108
81
|
get $root() {
|
|
109
82
|
if (!this.$parent) {
|
|
110
83
|
return this;
|
|
@@ -120,7 +93,6 @@ var Base = class extends EventTarget {
|
|
|
120
93
|
return root;
|
|
121
94
|
}
|
|
122
95
|
get __config() {
|
|
123
|
-
var _a, _b, _c;
|
|
124
96
|
let proto = Object.getPrototypeOf(this);
|
|
125
97
|
let { config } = proto.constructor;
|
|
126
98
|
while (proto.constructor.config && proto.constructor.$isBase) {
|
|
@@ -133,28 +105,33 @@ var Base = class extends EventTarget {
|
|
|
133
105
|
}
|
|
134
106
|
proto = Object.getPrototypeOf(proto);
|
|
135
107
|
}
|
|
136
|
-
config.options =
|
|
137
|
-
config.refs =
|
|
138
|
-
config.components =
|
|
108
|
+
config.options = config.options ?? {};
|
|
109
|
+
config.refs = config.refs ?? [];
|
|
110
|
+
config.components = config.components ?? {};
|
|
139
111
|
return config;
|
|
140
112
|
}
|
|
113
|
+
__services;
|
|
141
114
|
get $services() {
|
|
142
115
|
return this.__services;
|
|
143
116
|
}
|
|
117
|
+
__refs;
|
|
144
118
|
get $refs() {
|
|
145
119
|
return this.__refs;
|
|
146
120
|
}
|
|
121
|
+
__options;
|
|
147
122
|
get $options() {
|
|
148
123
|
return this.__options;
|
|
149
124
|
}
|
|
125
|
+
__children;
|
|
150
126
|
get $children() {
|
|
151
127
|
return this.__children;
|
|
152
128
|
}
|
|
129
|
+
__events;
|
|
153
130
|
get $log() {
|
|
154
|
-
return this.__options.log ? window.console.log.bind(window, `[${this.__config.name}]`) :
|
|
131
|
+
return this.__options.log ? window.console.log.bind(window, `[${this.__config.name}]`) : import_utils2.noop;
|
|
155
132
|
}
|
|
156
133
|
get __debug() {
|
|
157
|
-
return isDev && this.__options.debug ? window.console.log.bind(window, `[debug] [${this.$id}]`) :
|
|
134
|
+
return import_utils2.isDev && this.__options.debug ? window.console.log.bind(window, `[debug] [${this.$id}]`) : import_utils2.noop;
|
|
158
135
|
}
|
|
159
136
|
get __managers() {
|
|
160
137
|
return {
|
|
@@ -166,14 +143,14 @@ var Base = class extends EventTarget {
|
|
|
166
143
|
};
|
|
167
144
|
}
|
|
168
145
|
__callMethod(method, ...args) {
|
|
169
|
-
if (isDev) {
|
|
146
|
+
if (import_utils2.isDev) {
|
|
170
147
|
this.__debug("callMethod", method, ...args);
|
|
171
148
|
}
|
|
172
149
|
this.$emit(method, ...args);
|
|
173
|
-
if (
|
|
150
|
+
if (!(0, import_utils2.isFunction)(this[method])) {
|
|
174
151
|
return null;
|
|
175
152
|
}
|
|
176
|
-
if (isDev) {
|
|
153
|
+
if (import_utils2.isDev) {
|
|
177
154
|
this.__debug(method, this, ...args);
|
|
178
155
|
}
|
|
179
156
|
return this[method].call(this, ...args);
|
|
@@ -182,13 +159,40 @@ var Base = class extends EventTarget {
|
|
|
182
159
|
const eventHandlers = this.__eventHandlers.get(event);
|
|
183
160
|
return eventHandlers && eventHandlers.size > 0;
|
|
184
161
|
}
|
|
162
|
+
constructor(element) {
|
|
163
|
+
super();
|
|
164
|
+
if (!element) {
|
|
165
|
+
if (import_utils2.isDev) {
|
|
166
|
+
throw new Error("The root element must be defined.");
|
|
167
|
+
}
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const { __config } = this;
|
|
171
|
+
if (__config.name === "Base") {
|
|
172
|
+
if (import_utils2.isDev) {
|
|
173
|
+
throw new Error("The `config.name` property is required.");
|
|
174
|
+
}
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
this.$id = `${__config.name}-${id}`;
|
|
178
|
+
id += 1;
|
|
179
|
+
this.$el = element;
|
|
180
|
+
if (!this.$el.__base__) {
|
|
181
|
+
this.$el.__base__ = /* @__PURE__ */ new WeakMap();
|
|
182
|
+
}
|
|
183
|
+
this.$el.__base__.set(this.__ctor, this);
|
|
184
|
+
createAndTestManagers(this);
|
|
185
|
+
if (import_utils2.isDev) {
|
|
186
|
+
this.__debug("constructor", this);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
185
189
|
$mount() {
|
|
186
190
|
if (this.$isMounted) {
|
|
187
191
|
return this;
|
|
188
192
|
}
|
|
189
193
|
this.$emit("before-mounted");
|
|
190
194
|
this.$isMounted = true;
|
|
191
|
-
if (isDev) {
|
|
195
|
+
if (import_utils2.isDev) {
|
|
192
196
|
this.__debug("$mount");
|
|
193
197
|
}
|
|
194
198
|
this.$children.registerAll();
|
|
@@ -200,7 +204,7 @@ var Base = class extends EventTarget {
|
|
|
200
204
|
return this;
|
|
201
205
|
}
|
|
202
206
|
$update() {
|
|
203
|
-
if (isDev) {
|
|
207
|
+
if (import_utils2.isDev) {
|
|
204
208
|
this.__debug("$update");
|
|
205
209
|
}
|
|
206
210
|
this.$refs.unregisterAll();
|
|
@@ -217,7 +221,7 @@ var Base = class extends EventTarget {
|
|
|
217
221
|
return this;
|
|
218
222
|
}
|
|
219
223
|
this.$isMounted = false;
|
|
220
|
-
if (isDev) {
|
|
224
|
+
if (import_utils2.isDev) {
|
|
221
225
|
this.__debug("$destroy");
|
|
222
226
|
}
|
|
223
227
|
this.__events.unbindRootElement();
|
|
@@ -228,21 +232,16 @@ var Base = class extends EventTarget {
|
|
|
228
232
|
return this;
|
|
229
233
|
}
|
|
230
234
|
$terminate() {
|
|
231
|
-
if (isDev) {
|
|
235
|
+
if (import_utils2.isDev) {
|
|
232
236
|
this.__debug("$terminate");
|
|
233
237
|
}
|
|
234
238
|
this.$destroy();
|
|
235
239
|
this.__callMethod("terminated");
|
|
236
240
|
this.$el.__base__.set(this.__ctor, "terminated");
|
|
237
241
|
}
|
|
238
|
-
__testEventIsDefined(event) {
|
|
239
|
-
if (!(Array.isArray(this.__config.emits) && this.__config.emits.includes(event))) {
|
|
240
|
-
console.warn(`[${this.__config.name}]`, `The "${event}" event is missing from the configuration.`);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
242
|
__addEmits(event) {
|
|
244
243
|
const ctor = this.__ctor;
|
|
245
|
-
if (
|
|
244
|
+
if ((0, import_utils2.isArray)(ctor.config.emits)) {
|
|
246
245
|
ctor.config.emits.push(event);
|
|
247
246
|
} else {
|
|
248
247
|
ctor.config.emits = [event];
|
|
@@ -257,44 +256,37 @@ var Base = class extends EventTarget {
|
|
|
257
256
|
return this.constructor;
|
|
258
257
|
}
|
|
259
258
|
$on(event, listener, options) {
|
|
260
|
-
if (isDev) {
|
|
259
|
+
if (import_utils2.isDev) {
|
|
261
260
|
this.__debug("$on", event, listener, options);
|
|
262
261
|
}
|
|
263
|
-
if (isDev) {
|
|
264
|
-
this.__testEventIsDefined(event);
|
|
265
|
-
}
|
|
266
262
|
let set = this.__eventHandlers.get(event);
|
|
267
263
|
if (!set) {
|
|
268
264
|
set = /* @__PURE__ */ new Set();
|
|
269
265
|
this.__eventHandlers.set(event, set);
|
|
270
266
|
}
|
|
271
267
|
set.add(listener);
|
|
272
|
-
|
|
268
|
+
const target = (0, import_utils.getEventTarget)(this, event, this.__config);
|
|
269
|
+
target.addEventListener(event, listener, options);
|
|
273
270
|
return () => {
|
|
274
271
|
this.$off(event, listener, options);
|
|
275
272
|
};
|
|
276
273
|
}
|
|
277
274
|
$off(event, listener, options) {
|
|
278
|
-
if (isDev) {
|
|
275
|
+
if (import_utils2.isDev) {
|
|
279
276
|
this.__debug("$off", event, listener);
|
|
280
277
|
}
|
|
281
|
-
if (isDev) {
|
|
282
|
-
this.__testEventIsDefined(event);
|
|
283
|
-
}
|
|
284
278
|
this.__eventHandlers.get(event).delete(listener);
|
|
285
|
-
|
|
279
|
+
const target = (0, import_utils.getEventTarget)(this, event, this.__config);
|
|
280
|
+
target.removeEventListener(event, listener, options);
|
|
286
281
|
}
|
|
287
282
|
$emit(event, ...args) {
|
|
288
|
-
if (isDev) {
|
|
283
|
+
if (import_utils2.isDev) {
|
|
289
284
|
this.__debug("$emit", event, args);
|
|
290
285
|
}
|
|
291
|
-
if (isDev) {
|
|
292
|
-
this.__testEventIsDefined(event);
|
|
293
|
-
}
|
|
294
286
|
this.dispatchEvent(new CustomEvent(event, { detail: args }));
|
|
295
287
|
}
|
|
296
288
|
static $factory(nameOrSelector) {
|
|
297
|
-
if (!nameOrSelector) {
|
|
289
|
+
if (import_utils2.isDev && !nameOrSelector) {
|
|
298
290
|
throw new Error("The $factory method requires a component\u2019s name or selector to be specified.");
|
|
299
291
|
}
|
|
300
292
|
return (0, import_utils.getComponentElements)(nameOrSelector).map((el) => new this(el).$mount());
|
package/Base/index.d.ts
CHANGED
|
@@ -191,14 +191,6 @@ export default class Base extends EventTarget {
|
|
|
191
191
|
* @returns {void}
|
|
192
192
|
*/
|
|
193
193
|
$terminate(): void;
|
|
194
|
-
/**
|
|
195
|
-
* Test if the given event is configured and warn otherwise.
|
|
196
|
-
*
|
|
197
|
-
* @private
|
|
198
|
-
* @param {string} event The event name.
|
|
199
|
-
* @returns {void}
|
|
200
|
-
*/
|
|
201
|
-
private __testEventIsDefined;
|
|
202
194
|
/**
|
|
203
195
|
* Add an emitted event.
|
|
204
196
|
*
|
package/Base/index.js
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => {
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
7
|
-
import { getComponentElements } from "./utils.js";
|
|
1
|
+
import { getComponentElements, getEventTarget } from "./utils.js";
|
|
8
2
|
import ChildrenManager from "./managers/ChildrenManager.js";
|
|
9
3
|
import RefsManager from "./managers/RefsManager.js";
|
|
10
4
|
import ServicesManager from "./managers/ServicesManager.js";
|
|
11
5
|
import EventsManager from "./managers/EventsManager.js";
|
|
12
6
|
import OptionsManager from "./managers/OptionsManager.js";
|
|
13
|
-
import { noop } from "../utils/
|
|
7
|
+
import { noop, isDev, isFunction, isArray } from "../utils/index.js";
|
|
14
8
|
let id = 0;
|
|
15
|
-
const isDev = typeof __DEV__ !== "undefined" && __DEV__;
|
|
16
9
|
function createAndTestManagers(instance) {
|
|
17
10
|
[
|
|
18
11
|
{
|
|
@@ -42,43 +35,18 @@ function createAndTestManagers(instance) {
|
|
|
42
35
|
}
|
|
43
36
|
].forEach(({ prop, constructorName, constructor }) => {
|
|
44
37
|
instance[prop] = new instance.__managers[constructorName](instance);
|
|
45
|
-
if (!(instance[prop] instanceof constructor)) {
|
|
38
|
+
if (isDev && !(instance[prop] instanceof constructor)) {
|
|
46
39
|
throw new Error(`The \`$managers.${constructorName}\` must extend the \`${constructorName}\` class.`);
|
|
47
40
|
}
|
|
48
41
|
});
|
|
49
42
|
}
|
|
50
43
|
class Base extends EventTarget {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
__publicField(this, "__eventHandlers", /* @__PURE__ */ new Map());
|
|
58
|
-
__publicField(this, "__services");
|
|
59
|
-
__publicField(this, "__refs");
|
|
60
|
-
__publicField(this, "__options");
|
|
61
|
-
__publicField(this, "__children");
|
|
62
|
-
__publicField(this, "__events");
|
|
63
|
-
if (!element) {
|
|
64
|
-
throw new Error("The root element must be defined.");
|
|
65
|
-
}
|
|
66
|
-
const { __config } = this;
|
|
67
|
-
if (__config.name === "Base") {
|
|
68
|
-
throw new Error("The `config.name` property is required.");
|
|
69
|
-
}
|
|
70
|
-
this.$id = `${__config.name}-${id}`;
|
|
71
|
-
id += 1;
|
|
72
|
-
this.$el = element;
|
|
73
|
-
if (!this.$el.__base__) {
|
|
74
|
-
this.$el.__base__ = /* @__PURE__ */ new WeakMap();
|
|
75
|
-
}
|
|
76
|
-
this.$el.__base__.set(this.__ctor, this);
|
|
77
|
-
createAndTestManagers(this);
|
|
78
|
-
if (isDev) {
|
|
79
|
-
this.__debug("constructor", this);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
44
|
+
static $isBase = true;
|
|
45
|
+
$parent = null;
|
|
46
|
+
$id;
|
|
47
|
+
$el;
|
|
48
|
+
$isMounted = false;
|
|
49
|
+
__eventHandlers = /* @__PURE__ */ new Map();
|
|
82
50
|
get $root() {
|
|
83
51
|
if (!this.$parent) {
|
|
84
52
|
return this;
|
|
@@ -94,7 +62,6 @@ class Base extends EventTarget {
|
|
|
94
62
|
return root;
|
|
95
63
|
}
|
|
96
64
|
get __config() {
|
|
97
|
-
var _a, _b, _c;
|
|
98
65
|
let proto = Object.getPrototypeOf(this);
|
|
99
66
|
let { config } = proto.constructor;
|
|
100
67
|
while (proto.constructor.config && proto.constructor.$isBase) {
|
|
@@ -107,23 +74,44 @@ class Base extends EventTarget {
|
|
|
107
74
|
}
|
|
108
75
|
proto = Object.getPrototypeOf(proto);
|
|
109
76
|
}
|
|
110
|
-
config.options =
|
|
111
|
-
config.refs =
|
|
112
|
-
config.components =
|
|
77
|
+
config.options = config.options ?? {};
|
|
78
|
+
config.refs = config.refs ?? [];
|
|
79
|
+
config.components = config.components ?? {};
|
|
113
80
|
return config;
|
|
114
81
|
}
|
|
82
|
+
static config = {
|
|
83
|
+
name: "Base",
|
|
84
|
+
emits: [
|
|
85
|
+
"before-mounted",
|
|
86
|
+
"mounted",
|
|
87
|
+
"updated",
|
|
88
|
+
"destroyed",
|
|
89
|
+
"terminated",
|
|
90
|
+
"ticked",
|
|
91
|
+
"scrolled",
|
|
92
|
+
"resized",
|
|
93
|
+
"moved",
|
|
94
|
+
"loaded",
|
|
95
|
+
"keyed"
|
|
96
|
+
]
|
|
97
|
+
};
|
|
98
|
+
__services;
|
|
115
99
|
get $services() {
|
|
116
100
|
return this.__services;
|
|
117
101
|
}
|
|
102
|
+
__refs;
|
|
118
103
|
get $refs() {
|
|
119
104
|
return this.__refs;
|
|
120
105
|
}
|
|
106
|
+
__options;
|
|
121
107
|
get $options() {
|
|
122
108
|
return this.__options;
|
|
123
109
|
}
|
|
110
|
+
__children;
|
|
124
111
|
get $children() {
|
|
125
112
|
return this.__children;
|
|
126
113
|
}
|
|
114
|
+
__events;
|
|
127
115
|
get $log() {
|
|
128
116
|
return this.__options.log ? window.console.log.bind(window, `[${this.__config.name}]`) : noop;
|
|
129
117
|
}
|
|
@@ -144,7 +132,7 @@ class Base extends EventTarget {
|
|
|
144
132
|
this.__debug("callMethod", method, ...args);
|
|
145
133
|
}
|
|
146
134
|
this.$emit(method, ...args);
|
|
147
|
-
if (
|
|
135
|
+
if (!isFunction(this[method])) {
|
|
148
136
|
return null;
|
|
149
137
|
}
|
|
150
138
|
if (isDev) {
|
|
@@ -156,6 +144,33 @@ class Base extends EventTarget {
|
|
|
156
144
|
const eventHandlers = this.__eventHandlers.get(event);
|
|
157
145
|
return eventHandlers && eventHandlers.size > 0;
|
|
158
146
|
}
|
|
147
|
+
constructor(element) {
|
|
148
|
+
super();
|
|
149
|
+
if (!element) {
|
|
150
|
+
if (isDev) {
|
|
151
|
+
throw new Error("The root element must be defined.");
|
|
152
|
+
}
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const { __config } = this;
|
|
156
|
+
if (__config.name === "Base") {
|
|
157
|
+
if (isDev) {
|
|
158
|
+
throw new Error("The `config.name` property is required.");
|
|
159
|
+
}
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
this.$id = `${__config.name}-${id}`;
|
|
163
|
+
id += 1;
|
|
164
|
+
this.$el = element;
|
|
165
|
+
if (!this.$el.__base__) {
|
|
166
|
+
this.$el.__base__ = /* @__PURE__ */ new WeakMap();
|
|
167
|
+
}
|
|
168
|
+
this.$el.__base__.set(this.__ctor, this);
|
|
169
|
+
createAndTestManagers(this);
|
|
170
|
+
if (isDev) {
|
|
171
|
+
this.__debug("constructor", this);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
159
174
|
$mount() {
|
|
160
175
|
if (this.$isMounted) {
|
|
161
176
|
return this;
|
|
@@ -209,14 +224,9 @@ class Base extends EventTarget {
|
|
|
209
224
|
this.__callMethod("terminated");
|
|
210
225
|
this.$el.__base__.set(this.__ctor, "terminated");
|
|
211
226
|
}
|
|
212
|
-
__testEventIsDefined(event) {
|
|
213
|
-
if (!(Array.isArray(this.__config.emits) && this.__config.emits.includes(event))) {
|
|
214
|
-
console.warn(`[${this.__config.name}]`, `The "${event}" event is missing from the configuration.`);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
227
|
__addEmits(event) {
|
|
218
228
|
const ctor = this.__ctor;
|
|
219
|
-
if (
|
|
229
|
+
if (isArray(ctor.config.emits)) {
|
|
220
230
|
ctor.config.emits.push(event);
|
|
221
231
|
} else {
|
|
222
232
|
ctor.config.emits = [event];
|
|
@@ -234,16 +244,14 @@ class Base extends EventTarget {
|
|
|
234
244
|
if (isDev) {
|
|
235
245
|
this.__debug("$on", event, listener, options);
|
|
236
246
|
}
|
|
237
|
-
if (isDev) {
|
|
238
|
-
this.__testEventIsDefined(event);
|
|
239
|
-
}
|
|
240
247
|
let set = this.__eventHandlers.get(event);
|
|
241
248
|
if (!set) {
|
|
242
249
|
set = /* @__PURE__ */ new Set();
|
|
243
250
|
this.__eventHandlers.set(event, set);
|
|
244
251
|
}
|
|
245
252
|
set.add(listener);
|
|
246
|
-
this
|
|
253
|
+
const target = getEventTarget(this, event, this.__config);
|
|
254
|
+
target.addEventListener(event, listener, options);
|
|
247
255
|
return () => {
|
|
248
256
|
this.$off(event, listener, options);
|
|
249
257
|
};
|
|
@@ -252,45 +260,23 @@ class Base extends EventTarget {
|
|
|
252
260
|
if (isDev) {
|
|
253
261
|
this.__debug("$off", event, listener);
|
|
254
262
|
}
|
|
255
|
-
if (isDev) {
|
|
256
|
-
this.__testEventIsDefined(event);
|
|
257
|
-
}
|
|
258
263
|
this.__eventHandlers.get(event).delete(listener);
|
|
259
|
-
this
|
|
264
|
+
const target = getEventTarget(this, event, this.__config);
|
|
265
|
+
target.removeEventListener(event, listener, options);
|
|
260
266
|
}
|
|
261
267
|
$emit(event, ...args) {
|
|
262
268
|
if (isDev) {
|
|
263
269
|
this.__debug("$emit", event, args);
|
|
264
270
|
}
|
|
265
|
-
if (isDev) {
|
|
266
|
-
this.__testEventIsDefined(event);
|
|
267
|
-
}
|
|
268
271
|
this.dispatchEvent(new CustomEvent(event, { detail: args }));
|
|
269
272
|
}
|
|
270
273
|
static $factory(nameOrSelector) {
|
|
271
|
-
if (!nameOrSelector) {
|
|
274
|
+
if (isDev && !nameOrSelector) {
|
|
272
275
|
throw new Error("The $factory method requires a component\u2019s name or selector to be specified.");
|
|
273
276
|
}
|
|
274
277
|
return getComponentElements(nameOrSelector).map((el) => new this(el).$mount());
|
|
275
278
|
}
|
|
276
279
|
}
|
|
277
|
-
__publicField(Base, "$isBase", true);
|
|
278
|
-
__publicField(Base, "config", {
|
|
279
|
-
name: "Base",
|
|
280
|
-
emits: [
|
|
281
|
-
"before-mounted",
|
|
282
|
-
"mounted",
|
|
283
|
-
"updated",
|
|
284
|
-
"destroyed",
|
|
285
|
-
"terminated",
|
|
286
|
-
"ticked",
|
|
287
|
-
"scrolled",
|
|
288
|
-
"resized",
|
|
289
|
-
"moved",
|
|
290
|
-
"loaded",
|
|
291
|
-
"keyed"
|
|
292
|
-
]
|
|
293
|
-
});
|
|
294
280
|
export {
|
|
295
281
|
Base as default
|
|
296
282
|
};
|
|
@@ -2,7 +2,6 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
5
|
var __export = (target, all) => {
|
|
7
6
|
for (var name in all)
|
|
8
7
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -16,10 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
15
|
return to;
|
|
17
16
|
};
|
|
18
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var __publicField = (obj, key, value) => {
|
|
20
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
-
return value;
|
|
22
|
-
};
|
|
23
18
|
|
|
24
19
|
// packages/js-toolkit/Base/managers/AbstractManager.js
|
|
25
20
|
var AbstractManager_exports = {};
|
|
@@ -28,11 +23,7 @@ __export(AbstractManager_exports, {
|
|
|
28
23
|
});
|
|
29
24
|
module.exports = __toCommonJS(AbstractManager_exports);
|
|
30
25
|
var AbstractManager = class {
|
|
31
|
-
|
|
32
|
-
__publicField(this, "__base");
|
|
33
|
-
this.__base = base;
|
|
34
|
-
this.__hideProperties(["__base"]);
|
|
35
|
-
}
|
|
26
|
+
__base;
|
|
36
27
|
get __element() {
|
|
37
28
|
return this.__base.$el;
|
|
38
29
|
}
|
|
@@ -42,6 +33,10 @@ var AbstractManager = class {
|
|
|
42
33
|
get __eventsManager() {
|
|
43
34
|
return this.__base.__events;
|
|
44
35
|
}
|
|
36
|
+
constructor(base) {
|
|
37
|
+
this.__base = base;
|
|
38
|
+
this.__hideProperties(["__base"]);
|
|
39
|
+
}
|
|
45
40
|
__hideProperties(properties) {
|
|
46
41
|
Object.defineProperties(this, Object.fromEntries(properties.map((property) => [
|
|
47
42
|
property,
|
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => {
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
7
1
|
class AbstractManager {
|
|
8
|
-
|
|
9
|
-
__publicField(this, "__base");
|
|
10
|
-
this.__base = base;
|
|
11
|
-
this.__hideProperties(["__base"]);
|
|
12
|
-
}
|
|
2
|
+
__base;
|
|
13
3
|
get __element() {
|
|
14
4
|
return this.__base.$el;
|
|
15
5
|
}
|
|
@@ -19,6 +9,10 @@ class AbstractManager {
|
|
|
19
9
|
get __eventsManager() {
|
|
20
10
|
return this.__base.__events;
|
|
21
11
|
}
|
|
12
|
+
constructor(base) {
|
|
13
|
+
this.__base = base;
|
|
14
|
+
this.__hideProperties(["__base"]);
|
|
15
|
+
}
|
|
22
16
|
__hideProperties(properties) {
|
|
23
17
|
Object.defineProperties(this, Object.fromEntries(properties.map((property) => [
|
|
24
18
|
property,
|
|
@@ -4,7 +4,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
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
7
|
var __export = (target, all) => {
|
|
9
8
|
for (var name in all)
|
|
10
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -19,10 +18,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
19
18
|
};
|
|
20
19
|
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
20
|
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
21
|
|
|
27
22
|
// packages/js-toolkit/Base/managers/ChildrenManager.js
|
|
28
23
|
var ChildrenManager_exports = {};
|
|
@@ -55,8 +50,7 @@ function __getChild(that, el, ComponentClass, name) {
|
|
|
55
50
|
});
|
|
56
51
|
}
|
|
57
52
|
return promise.then((module2) => {
|
|
58
|
-
|
|
59
|
-
const ctor = (_a = module2.default) != null ? _a : module2;
|
|
53
|
+
const ctor = module2.default ?? module2;
|
|
60
54
|
that.__asyncComponentPromises.set(ComponentClass, {
|
|
61
55
|
promise,
|
|
62
56
|
status: "resolved",
|
|
@@ -102,10 +96,7 @@ function __triggerHookForAll(that, hook) {
|
|
|
102
96
|
});
|
|
103
97
|
}
|
|
104
98
|
var ChildrenManager = class extends import_AbstractManager.default {
|
|
105
|
-
|
|
106
|
-
super(...arguments);
|
|
107
|
-
__publicField(this, "__asyncComponentPromises", /* @__PURE__ */ new WeakMap());
|
|
108
|
-
}
|
|
99
|
+
__asyncComponentPromises = /* @__PURE__ */ new WeakMap();
|
|
109
100
|
get registeredNames() {
|
|
110
101
|
return Object.keys(this).filter((key) => !key.startsWith("__"));
|
|
111
102
|
}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => {
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
7
1
|
import AbstractManager from "./AbstractManager.js";
|
|
8
2
|
import { getComponentElements } from "../utils.js";
|
|
9
3
|
function __getChild(that, el, ComponentClass, name) {
|
|
@@ -29,8 +23,7 @@ function __getChild(that, el, ComponentClass, name) {
|
|
|
29
23
|
});
|
|
30
24
|
}
|
|
31
25
|
return promise.then((module) => {
|
|
32
|
-
|
|
33
|
-
const ctor = (_a = module.default) != null ? _a : module;
|
|
26
|
+
const ctor = module.default ?? module;
|
|
34
27
|
that.__asyncComponentPromises.set(ComponentClass, {
|
|
35
28
|
promise,
|
|
36
29
|
status: "resolved",
|
|
@@ -76,10 +69,7 @@ function __triggerHookForAll(that, hook) {
|
|
|
76
69
|
});
|
|
77
70
|
}
|
|
78
71
|
class ChildrenManager extends AbstractManager {
|
|
79
|
-
|
|
80
|
-
super(...arguments);
|
|
81
|
-
__publicField(this, "__asyncComponentPromises", /* @__PURE__ */ new WeakMap());
|
|
82
|
-
}
|
|
72
|
+
__asyncComponentPromises = /* @__PURE__ */ new WeakMap();
|
|
83
73
|
get registeredNames() {
|
|
84
74
|
return Object.keys(this).filter((key) => !key.startsWith("__"));
|
|
85
75
|
}
|