@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.js
CHANGED
|
@@ -1,344 +1,260 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import { getComponentElements } from
|
|
8
|
-
import ChildrenManager from
|
|
9
|
-
import RefsManager from
|
|
10
|
-
import ServicesManager from
|
|
11
|
-
import EventsManager from
|
|
12
|
-
import OptionsManager from
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
+
import { getComponentElements } from "./utils.js";
|
|
8
|
+
import ChildrenManager from "./managers/ChildrenManager.js";
|
|
9
|
+
import RefsManager from "./managers/RefsManager.js";
|
|
10
|
+
import ServicesManager from "./managers/ServicesManager.js";
|
|
11
|
+
import EventsManager from "./managers/EventsManager.js";
|
|
12
|
+
import OptionsManager from "./managers/OptionsManager.js";
|
|
13
|
+
let id = 0;
|
|
14
|
+
const isDev = typeof __DEV__ !== "undefined" && __DEV__;
|
|
15
|
+
function noop() {
|
|
16
|
+
}
|
|
17
|
+
class Base extends EventTarget {
|
|
18
|
+
constructor(element) {
|
|
19
|
+
super();
|
|
20
|
+
__publicField(this, "$parent", null);
|
|
21
|
+
__publicField(this, "$id");
|
|
22
|
+
__publicField(this, "$el");
|
|
23
|
+
__publicField(this, "$isMounted", false);
|
|
24
|
+
__publicField(this, "__eventHandlers", /* @__PURE__ */ new Map());
|
|
25
|
+
__publicField(this, "__services");
|
|
26
|
+
__publicField(this, "__refs");
|
|
27
|
+
__publicField(this, "__options");
|
|
28
|
+
__publicField(this, "__children");
|
|
29
|
+
__publicField(this, "__events");
|
|
30
|
+
if (!element) {
|
|
31
|
+
throw new Error("The root element must be defined.");
|
|
32
|
+
}
|
|
33
|
+
const { __config } = this;
|
|
34
|
+
if (__config.name === "Base") {
|
|
35
|
+
throw new Error("The `config.name` property is required.");
|
|
36
|
+
}
|
|
37
|
+
this.$id = `${__config.name}-${id}`;
|
|
38
|
+
id += 1;
|
|
39
|
+
this.$el = element;
|
|
40
|
+
if (!this.$el.__base__) {
|
|
41
|
+
this.$el.__base__ = /* @__PURE__ */ new WeakMap();
|
|
42
|
+
}
|
|
43
|
+
this.$el.__base__.set(this.__ctor, this);
|
|
44
|
+
this.__options = new OptionsManager(element, __config.options || {}, __config);
|
|
45
|
+
this.__services = new ServicesManager(this);
|
|
46
|
+
this.__events = new EventsManager(element, this);
|
|
47
|
+
this.__children = new ChildrenManager(this, element, __config.components || {}, this.__events);
|
|
48
|
+
this.__refs = new RefsManager(this, element, __config.refs || [], this.__events);
|
|
49
|
+
if (isDev) {
|
|
50
|
+
this.__debug("constructor", this);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
19
53
|
get $root() {
|
|
20
54
|
if (!this.$parent) {
|
|
21
55
|
return this;
|
|
22
56
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var root = this.$parent;
|
|
26
|
-
|
|
57
|
+
let parent = this.$parent;
|
|
58
|
+
let root = this.$parent;
|
|
27
59
|
while (parent) {
|
|
28
60
|
if (!parent.$parent) {
|
|
29
61
|
root = parent;
|
|
30
62
|
}
|
|
31
|
-
|
|
32
63
|
parent = parent.$parent;
|
|
33
64
|
}
|
|
34
|
-
|
|
35
65
|
return root;
|
|
36
66
|
}
|
|
37
|
-
|
|
38
67
|
get __config() {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
config
|
|
42
|
-
} = proto.constructor;
|
|
43
|
-
|
|
68
|
+
let proto = Object.getPrototypeOf(this);
|
|
69
|
+
let { config } = proto.constructor;
|
|
44
70
|
while (proto.constructor.config && proto.constructor.$isBase) {
|
|
45
|
-
config =
|
|
46
|
-
|
|
71
|
+
config = {
|
|
72
|
+
...proto.constructor.config,
|
|
73
|
+
...config
|
|
74
|
+
};
|
|
47
75
|
if (proto.constructor.config.options) {
|
|
48
|
-
config.options =
|
|
76
|
+
config.options = {
|
|
77
|
+
...proto.constructor.config.options,
|
|
78
|
+
...config.options
|
|
79
|
+
};
|
|
49
80
|
}
|
|
50
|
-
|
|
51
81
|
if (proto.constructor.config.emits && config.emits) {
|
|
52
82
|
config.emits = [...proto.constructor.config.emits, ...config.emits];
|
|
53
83
|
}
|
|
54
|
-
|
|
55
84
|
proto = Object.getPrototypeOf(proto);
|
|
56
85
|
}
|
|
57
|
-
|
|
58
86
|
return config;
|
|
59
87
|
}
|
|
60
|
-
|
|
61
88
|
get $services() {
|
|
62
89
|
return this.__services;
|
|
63
90
|
}
|
|
64
|
-
|
|
65
91
|
get $refs() {
|
|
66
92
|
return this.__refs;
|
|
67
93
|
}
|
|
68
|
-
|
|
69
94
|
get $options() {
|
|
70
95
|
return this.__options;
|
|
71
96
|
}
|
|
72
|
-
|
|
73
97
|
get $children() {
|
|
74
98
|
return this.__children;
|
|
75
99
|
}
|
|
76
|
-
|
|
77
100
|
get $log() {
|
|
78
|
-
return this.__options.log ? window.console.log.bind(window,
|
|
101
|
+
return this.__options.log ? window.console.log.bind(window, `[${this.__config.name}]`) : noop;
|
|
79
102
|
}
|
|
80
|
-
|
|
81
103
|
get __debug() {
|
|
82
|
-
return isDev && this.__options.debug ? window.console.log.bind(window,
|
|
104
|
+
return isDev && this.__options.debug ? window.console.log.bind(window, `[debug] [${this.$id}]`) : noop;
|
|
83
105
|
}
|
|
84
|
-
|
|
85
|
-
__callMethod(method) {
|
|
86
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
87
|
-
args[_key - 1] = arguments[_key];
|
|
88
|
-
}
|
|
89
|
-
|
|
106
|
+
__callMethod(method, ...args) {
|
|
90
107
|
if (isDev) {
|
|
91
|
-
this.__debug(
|
|
108
|
+
this.__debug("callMethod", method, ...args);
|
|
92
109
|
}
|
|
93
|
-
|
|
94
110
|
this.$emit(method, ...args);
|
|
95
|
-
|
|
96
|
-
if (typeof this[method] !== 'function') {
|
|
111
|
+
if (typeof this[method] !== "function") {
|
|
97
112
|
return;
|
|
98
113
|
}
|
|
99
|
-
|
|
100
114
|
this[method].call(this, ...args);
|
|
101
|
-
|
|
102
115
|
if (isDev) {
|
|
103
116
|
this.__debug(method, this, ...args);
|
|
104
117
|
}
|
|
105
118
|
}
|
|
106
|
-
|
|
107
119
|
__hasEvent(event) {
|
|
108
|
-
|
|
109
|
-
|
|
120
|
+
const eventHandlers = this.__eventHandlers.get(event);
|
|
110
121
|
return eventHandlers && eventHandlers.size > 0;
|
|
111
122
|
}
|
|
112
|
-
|
|
113
|
-
constructor(element) {
|
|
114
|
-
super();
|
|
115
|
-
|
|
116
|
-
_defineProperty(this, "$parent", null);
|
|
117
|
-
|
|
118
|
-
_defineProperty(this, "$id", void 0);
|
|
119
|
-
|
|
120
|
-
_defineProperty(this, "$el", void 0);
|
|
121
|
-
|
|
122
|
-
_defineProperty(this, "$isMounted", false);
|
|
123
|
-
|
|
124
|
-
_defineProperty(this, "__eventHandlers", new Map());
|
|
125
|
-
|
|
126
|
-
_defineProperty(this, "__services", void 0);
|
|
127
|
-
|
|
128
|
-
_defineProperty(this, "__refs", void 0);
|
|
129
|
-
|
|
130
|
-
_defineProperty(this, "__options", void 0);
|
|
131
|
-
|
|
132
|
-
_defineProperty(this, "__children", void 0);
|
|
133
|
-
|
|
134
|
-
_defineProperty(this, "__events", void 0);
|
|
135
|
-
|
|
136
|
-
if (!element) {
|
|
137
|
-
throw new Error('The root element must be defined.');
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
var {
|
|
141
|
-
__config
|
|
142
|
-
} = this;
|
|
143
|
-
|
|
144
|
-
if (__config.name === 'Base') {
|
|
145
|
-
throw new Error('The `config.name` property is required.');
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
this.$id = "".concat(__config.name, "-").concat(id);
|
|
149
|
-
id += 1;
|
|
150
|
-
this.$el = element;
|
|
151
|
-
|
|
152
|
-
if (!('__base__' in this.$el)) {
|
|
153
|
-
Object.defineProperty(this.$el, '__base__', {
|
|
154
|
-
get: () => this,
|
|
155
|
-
configurable: true
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
this.__options = new OptionsManager(element, __config.options || {}, __config);
|
|
160
|
-
this.__services = new ServicesManager(this);
|
|
161
|
-
this.__events = new EventsManager(element, this);
|
|
162
|
-
this.__children = new ChildrenManager(this, element, __config.components || {}, this.__events);
|
|
163
|
-
this.__refs = new RefsManager(this, element, __config.refs || [], this.__events);
|
|
164
|
-
|
|
165
|
-
if (isDev) {
|
|
166
|
-
this.__debug('constructor', this);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return this;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
123
|
$mount() {
|
|
173
124
|
if (this.$isMounted) {
|
|
174
125
|
return this;
|
|
175
126
|
}
|
|
176
|
-
|
|
177
127
|
this.$isMounted = true;
|
|
178
|
-
|
|
179
128
|
if (isDev) {
|
|
180
|
-
this.__debug(
|
|
129
|
+
this.__debug("$mount");
|
|
181
130
|
}
|
|
182
|
-
|
|
183
131
|
this.$children.registerAll();
|
|
184
132
|
this.$refs.registerAll();
|
|
185
|
-
|
|
186
133
|
this.__events.bindRootElement();
|
|
187
|
-
|
|
188
134
|
this.$services.enableAll();
|
|
189
135
|
this.$children.mountAll();
|
|
190
|
-
|
|
191
|
-
this.__callMethod('mounted');
|
|
192
|
-
|
|
136
|
+
this.__callMethod("mounted");
|
|
193
137
|
return this;
|
|
194
138
|
}
|
|
195
|
-
|
|
196
139
|
$update() {
|
|
197
140
|
if (isDev) {
|
|
198
|
-
this.__debug(
|
|
141
|
+
this.__debug("$update");
|
|
199
142
|
}
|
|
200
|
-
|
|
201
143
|
this.$refs.unregisterAll();
|
|
202
144
|
this.$services.disableAll();
|
|
203
145
|
this.$children.registerAll();
|
|
204
146
|
this.$refs.registerAll();
|
|
205
147
|
this.$services.enableAll();
|
|
206
148
|
this.$children.updateAll();
|
|
207
|
-
|
|
208
|
-
this.__callMethod('updated');
|
|
209
|
-
|
|
149
|
+
this.__callMethod("updated");
|
|
210
150
|
return this;
|
|
211
151
|
}
|
|
212
|
-
|
|
213
152
|
$destroy() {
|
|
214
153
|
if (!this.$isMounted) {
|
|
215
154
|
return this;
|
|
216
155
|
}
|
|
217
|
-
|
|
218
156
|
this.$isMounted = false;
|
|
219
|
-
|
|
220
157
|
if (isDev) {
|
|
221
|
-
this.__debug(
|
|
158
|
+
this.__debug("$destroy");
|
|
222
159
|
}
|
|
223
|
-
|
|
224
160
|
this.__events.unbindRootElement();
|
|
225
|
-
|
|
226
161
|
this.$refs.unregisterAll();
|
|
227
162
|
this.$services.disableAll();
|
|
228
163
|
this.$children.destroyAll();
|
|
229
|
-
|
|
230
|
-
this.__callMethod('destroyed');
|
|
231
|
-
|
|
164
|
+
this.__callMethod("destroyed");
|
|
232
165
|
return this;
|
|
233
166
|
}
|
|
234
|
-
|
|
235
167
|
$terminate() {
|
|
236
168
|
if (isDev) {
|
|
237
|
-
this.__debug(
|
|
169
|
+
this.__debug("$terminate");
|
|
238
170
|
}
|
|
239
|
-
|
|
240
171
|
this.$destroy();
|
|
241
|
-
|
|
242
|
-
this.
|
|
243
|
-
|
|
244
|
-
Object.defineProperty(this.$el, '__base__', {
|
|
245
|
-
value: 'terminated',
|
|
246
|
-
configurable: false,
|
|
247
|
-
writable: false
|
|
248
|
-
});
|
|
172
|
+
this.__callMethod("terminated");
|
|
173
|
+
this.$el.__base__.set(this.__ctor, "terminated");
|
|
249
174
|
}
|
|
250
|
-
|
|
251
175
|
__testEventIsDefined(event) {
|
|
252
176
|
if (!(Array.isArray(this.__config.emits) && this.__config.emits.includes(event))) {
|
|
253
|
-
console.warn(
|
|
177
|
+
console.warn(`[${this.__config.name}]`, `The "${event}" event is missing from the configuration.`);
|
|
254
178
|
}
|
|
255
179
|
}
|
|
256
|
-
|
|
257
180
|
__addEmits(event) {
|
|
258
|
-
|
|
259
|
-
|
|
181
|
+
const ctor = this.__ctor;
|
|
260
182
|
if (Array.isArray(ctor.config.emits)) {
|
|
261
183
|
ctor.config.emits.push(event);
|
|
262
184
|
} else {
|
|
263
185
|
ctor.config.emits = [event];
|
|
264
186
|
}
|
|
265
187
|
}
|
|
266
|
-
|
|
267
188
|
__removeEmits(event) {
|
|
268
|
-
|
|
269
|
-
|
|
189
|
+
const ctor = this.__ctor;
|
|
190
|
+
const index = ctor.config.emits.indexOf(event);
|
|
270
191
|
ctor.config.emits.splice(index, 1);
|
|
271
192
|
}
|
|
272
|
-
|
|
193
|
+
get __ctor() {
|
|
194
|
+
return this.constructor;
|
|
195
|
+
}
|
|
273
196
|
$on(event, listener, options) {
|
|
274
197
|
if (isDev) {
|
|
275
|
-
this.__debug(
|
|
198
|
+
this.__debug("$on", event, listener, options);
|
|
276
199
|
}
|
|
277
|
-
|
|
278
200
|
if (isDev) {
|
|
279
201
|
this.__testEventIsDefined(event);
|
|
280
202
|
}
|
|
281
|
-
|
|
282
|
-
var set = this.__eventHandlers.get(event);
|
|
283
|
-
|
|
203
|
+
let set = this.__eventHandlers.get(event);
|
|
284
204
|
if (!set) {
|
|
285
|
-
set = new Set();
|
|
286
|
-
|
|
205
|
+
set = /* @__PURE__ */ new Set();
|
|
287
206
|
this.__eventHandlers.set(event, set);
|
|
288
207
|
}
|
|
289
|
-
|
|
290
208
|
set.add(listener);
|
|
291
209
|
this.addEventListener(event, listener, options);
|
|
292
210
|
return () => {
|
|
293
211
|
this.$off(event, listener, options);
|
|
294
212
|
};
|
|
295
213
|
}
|
|
296
|
-
|
|
297
214
|
$off(event, listener, options) {
|
|
298
215
|
if (isDev) {
|
|
299
|
-
this.__debug(
|
|
216
|
+
this.__debug("$off", event, listener);
|
|
300
217
|
}
|
|
301
|
-
|
|
302
218
|
if (isDev) {
|
|
303
219
|
this.__testEventIsDefined(event);
|
|
304
220
|
}
|
|
305
|
-
|
|
306
221
|
this.__eventHandlers.get(event).delete(listener);
|
|
307
|
-
|
|
308
222
|
this.removeEventListener(event, listener, options);
|
|
309
223
|
}
|
|
310
|
-
|
|
311
|
-
$emit(event) {
|
|
312
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
313
|
-
args[_key2 - 1] = arguments[_key2];
|
|
314
|
-
}
|
|
315
|
-
|
|
224
|
+
$emit(event, ...args) {
|
|
316
225
|
if (isDev) {
|
|
317
|
-
this.__debug(
|
|
226
|
+
this.__debug("$emit", event, args);
|
|
318
227
|
}
|
|
319
|
-
|
|
320
228
|
if (isDev) {
|
|
321
229
|
this.__testEventIsDefined(event);
|
|
322
230
|
}
|
|
323
|
-
|
|
324
231
|
this.dispatchEvent(new CustomEvent(event, {
|
|
325
232
|
detail: args
|
|
326
233
|
}));
|
|
327
234
|
}
|
|
328
|
-
|
|
329
235
|
static $factory(nameOrSelector) {
|
|
330
236
|
if (!nameOrSelector) {
|
|
331
|
-
throw new Error(
|
|
237
|
+
throw new Error("The $factory method requires a component\u2019s name or selector to be specified.");
|
|
332
238
|
}
|
|
333
|
-
|
|
334
|
-
return getComponentElements(nameOrSelector).map(el => new this(el).$mount());
|
|
239
|
+
return getComponentElements(nameOrSelector).map((el) => new this(el).$mount());
|
|
335
240
|
}
|
|
336
|
-
|
|
337
241
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
242
|
+
__publicField(Base, "$isBase", true);
|
|
243
|
+
__publicField(Base, "config", {
|
|
244
|
+
name: "Base",
|
|
245
|
+
emits: [
|
|
246
|
+
"mounted",
|
|
247
|
+
"updated",
|
|
248
|
+
"destroyed",
|
|
249
|
+
"terminated",
|
|
250
|
+
"ticked",
|
|
251
|
+
"scrolled",
|
|
252
|
+
"resized",
|
|
253
|
+
"moved",
|
|
254
|
+
"loaded",
|
|
255
|
+
"keyed"
|
|
256
|
+
]
|
|
257
|
+
});
|
|
258
|
+
export {
|
|
259
|
+
Base as default
|
|
260
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
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
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
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
|
+
|
|
24
|
+
// packages/js-toolkit/Base/managers/ChildrenManager.js
|
|
25
|
+
var ChildrenManager_exports = {};
|
|
26
|
+
__export(ChildrenManager_exports, {
|
|
27
|
+
default: () => ChildrenManager
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(ChildrenManager_exports);
|
|
30
|
+
var import_utils = require("../utils.cjs");
|
|
31
|
+
var ChildrenManager = class {
|
|
32
|
+
constructor(base, element, components, eventsManager) {
|
|
33
|
+
__publicField(this, "__base");
|
|
34
|
+
__publicField(this, "__element");
|
|
35
|
+
__publicField(this, "__components");
|
|
36
|
+
__publicField(this, "__eventsManager");
|
|
37
|
+
__publicField(this, "__asyncComponentPromises", /* @__PURE__ */ new WeakMap());
|
|
38
|
+
Object.defineProperties(this, {
|
|
39
|
+
__base: {
|
|
40
|
+
enumerable: false,
|
|
41
|
+
writable: false,
|
|
42
|
+
value: base
|
|
43
|
+
},
|
|
44
|
+
__element: {
|
|
45
|
+
enumerable: false,
|
|
46
|
+
writable: false,
|
|
47
|
+
value: element
|
|
48
|
+
},
|
|
49
|
+
__components: {
|
|
50
|
+
enumerable: false,
|
|
51
|
+
writable: false,
|
|
52
|
+
value: components
|
|
53
|
+
},
|
|
54
|
+
__eventsManager: {
|
|
55
|
+
enumerable: false,
|
|
56
|
+
writable: false,
|
|
57
|
+
value: eventsManager
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
get registeredNames() {
|
|
62
|
+
return Object.keys(this).filter((key) => !key.startsWith("__"));
|
|
63
|
+
}
|
|
64
|
+
registerAll() {
|
|
65
|
+
Object.entries(this.__components).forEach(([name, component]) => this.__register(name, component));
|
|
66
|
+
}
|
|
67
|
+
__register(name, component) {
|
|
68
|
+
Object.defineProperty(this, name, {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
configurable: true,
|
|
71
|
+
get: () => {
|
|
72
|
+
const elements = (0, import_utils.getComponentElements)(name, this.__element);
|
|
73
|
+
if (elements.length === 0) {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
return elements.map((element) => this.__getChild(element, component, name)).filter((instance) => instance !== "terminated");
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
__getChild(el, ComponentClass, name) {
|
|
81
|
+
const asyncComponentPromise = this.__asyncComponentPromises.get(ComponentClass);
|
|
82
|
+
if ("$isBase" in ComponentClass || asyncComponentPromise && asyncComponentPromise.status === "resolved") {
|
|
83
|
+
let ctor = ComponentClass;
|
|
84
|
+
if (asyncComponentPromise) {
|
|
85
|
+
ctor = asyncComponentPromise.ctor;
|
|
86
|
+
}
|
|
87
|
+
if (el.__base__ && el.__base__.has(ctor)) {
|
|
88
|
+
return el.__base__.get(ctor);
|
|
89
|
+
}
|
|
90
|
+
const child = new ctor(el);
|
|
91
|
+
Object.defineProperty(child, "$parent", { get: () => this.__base });
|
|
92
|
+
return child;
|
|
93
|
+
}
|
|
94
|
+
const promise = asyncComponentPromise ? asyncComponentPromise.promise : ComponentClass(this.__base);
|
|
95
|
+
if (!asyncComponentPromise) {
|
|
96
|
+
this.__asyncComponentPromises.set(ComponentClass, {
|
|
97
|
+
promise,
|
|
98
|
+
status: "pending",
|
|
99
|
+
ctor: void 0
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return promise.then((module2) => {
|
|
103
|
+
var _a;
|
|
104
|
+
const ctor = (_a = module2.default) != null ? _a : module2;
|
|
105
|
+
this.__asyncComponentPromises.set(ComponentClass, {
|
|
106
|
+
promise,
|
|
107
|
+
status: "resolved",
|
|
108
|
+
ctor
|
|
109
|
+
});
|
|
110
|
+
return this.__getChild(el, ctor, name);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
mountAll() {
|
|
114
|
+
this.__triggerHookForAll("$mount");
|
|
115
|
+
}
|
|
116
|
+
updateAll() {
|
|
117
|
+
this.__triggerHookForAll("$update");
|
|
118
|
+
}
|
|
119
|
+
destroyAll() {
|
|
120
|
+
this.__triggerHookForAll("$destroy");
|
|
121
|
+
}
|
|
122
|
+
__triggerHookForAll(hook) {
|
|
123
|
+
this.registeredNames.forEach((name) => {
|
|
124
|
+
this[name].forEach((instance) => {
|
|
125
|
+
if (instance instanceof Promise) {
|
|
126
|
+
instance.then((resolvedInstance) => this.__triggerHook(hook, resolvedInstance, name));
|
|
127
|
+
} else {
|
|
128
|
+
this.__triggerHook(hook, instance, name);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
__triggerHook(hook, instance, name) {
|
|
134
|
+
if (hook === "$update" && !instance.$isMounted) {
|
|
135
|
+
hook = "$mount";
|
|
136
|
+
}
|
|
137
|
+
if (hook === "$update" || hook === "$destroy") {
|
|
138
|
+
this.__eventsManager.unbindChild(name, instance);
|
|
139
|
+
}
|
|
140
|
+
if (hook === "$update" || hook === "$mount") {
|
|
141
|
+
this.__eventsManager.bindChild(name, instance);
|
|
142
|
+
}
|
|
143
|
+
instance[hook]();
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
if (module.exports.default) module.exports = module.exports.default;
|
|
@@ -41,7 +41,15 @@ export default class ChildrenManager {
|
|
|
41
41
|
*/
|
|
42
42
|
private __eventsManager;
|
|
43
43
|
/**
|
|
44
|
-
*
|
|
44
|
+
* Store async component promises to avoid calling them multiple times and
|
|
45
|
+
* waiting for them when they are already resolved.
|
|
46
|
+
*
|
|
47
|
+
* @private
|
|
48
|
+
* @type {WeakMap<BaseAsyncConstructor, { promise: ReturnType<BaseAsyncConstructor>, status: 'pending'|'resolved', ctor?: BaseConstructor }>}
|
|
49
|
+
*/
|
|
50
|
+
private __asyncComponentPromises;
|
|
51
|
+
/**
|
|
52
|
+
* @returns {string[]}
|
|
45
53
|
*/
|
|
46
54
|
get registeredNames(): string[];
|
|
47
55
|
/**
|
|
@@ -61,13 +69,13 @@ export default class ChildrenManager {
|
|
|
61
69
|
/**
|
|
62
70
|
* Get a child component's instance.
|
|
63
71
|
*
|
|
64
|
-
* @param {HTMLElement & { __base__?: Base
|
|
72
|
+
* @param {HTMLElement & { __base__?: WeakMap<BaseConstructor, Base> }} el
|
|
65
73
|
* The root element of the child component.
|
|
66
74
|
* @param {BaseConstructor|BaseAsyncConstructor} ComponentClass
|
|
67
75
|
* A Base class or a Promise for async components.
|
|
68
76
|
* @param {string} name
|
|
69
77
|
* The name of the child component.
|
|
70
|
-
* @
|
|
78
|
+
* @returns {Base|Promise|'terminated'}
|
|
71
79
|
* A Base instance or a Promise resolving to a Base instance.
|
|
72
80
|
* @private
|
|
73
81
|
*/
|