@studiometa/js-toolkit 2.0.0-alpha.1 → 2.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Base/index.d.ts +29 -47
- package/Base/index.js +144 -171
- package/Base/managers/ChildrenManager.d.ts +6 -6
- package/Base/managers/ChildrenManager.js +95 -119
- package/Base/managers/EventsManager.d.ts +9 -9
- package/Base/managers/EventsManager.js +128 -161
- package/Base/managers/OptionsManager.d.ts +50 -5
- package/Base/managers/OptionsManager.js +115 -116
- package/Base/managers/RefsManager.js +62 -73
- package/Base/managers/ServicesManager.d.ts +14 -3
- package/Base/managers/ServicesManager.js +78 -77
- package/Base/utils.js +5 -8
- package/README.md +12 -70
- package/decorators/index.js +1 -2
- package/decorators/withBreakpointManager.d.ts +4 -4
- package/decorators/withBreakpointManager.js +37 -75
- package/decorators/withBreakpointObserver.d.ts +2 -2
- package/decorators/withBreakpointObserver.js +54 -77
- package/decorators/withDrag.d.ts +3 -3
- package/decorators/withDrag.js +17 -41
- package/decorators/withExtraConfig.d.ts +3 -3
- package/decorators/withExtraConfig.js +2 -24
- package/decorators/withIntersectionObserver.d.ts +2 -2
- package/decorators/withIntersectionObserver.js +17 -56
- package/decorators/withMountWhenInView.d.ts +3 -3
- package/decorators/withMountWhenInView.js +23 -51
- package/helpers/createApp.d.ts +3 -3
- package/helpers/createApp.js +10 -12
- package/helpers/importOnInteraction.d.ts +3 -3
- package/helpers/importOnInteraction.js +7 -8
- package/helpers/importWhenIdle.d.ts +3 -3
- package/helpers/importWhenIdle.js +7 -8
- package/helpers/importWhenVisible.d.ts +3 -3
- package/helpers/importWhenVisible.js +9 -16
- package/helpers/index.d.ts +1 -3
- package/helpers/index.js +1 -4
- package/helpers/utils.js +1 -2
- package/index.d.ts +14 -4
- package/index.js +4 -4
- package/index.modern.js +1 -2
- package/index.umd.js +1 -2
- package/package.json +4 -6
- package/services/Service.js +48 -67
- package/services/drag.js +143 -179
- package/services/index.js +1 -2
- package/services/key.js +55 -97
- package/services/load.d.ts +1 -1
- package/services/load.js +21 -50
- package/services/pointer.js +117 -156
- package/services/raf.js +36 -64
- package/services/resize.js +47 -86
- package/services/scroll.js +81 -120
- package/utils/collide/boundingRectToCircle.js +7 -6
- package/utils/collide/collideCircleCircle.js +1 -2
- package/utils/collide/collideCircleRect.js +1 -2
- package/utils/collide/collidePointCircle.js +1 -2
- package/utils/collide/collidePointRect.js +1 -2
- package/utils/collide/collideRectRect.js +1 -2
- package/utils/collide/index.js +1 -2
- package/utils/css/classes.js +2 -3
- package/utils/css/index.js +1 -2
- package/utils/css/matrix.js +1 -2
- package/utils/css/styles.js +3 -8
- package/utils/css/transition.js +67 -140
- package/utils/debounce.js +3 -4
- package/utils/focusTrap.js +4 -5
- package/utils/history.js +13 -20
- package/utils/index.d.ts +2 -1
- package/utils/index.js +2 -2
- package/utils/keyCodes.js +1 -2
- package/utils/math/clamp.js +1 -2
- package/utils/math/clamp01.js +1 -2
- package/utils/math/damp.js +1 -2
- package/utils/math/index.js +1 -2
- package/utils/math/inertiaFinalValue.js +1 -2
- package/utils/math/lerp.js +1 -2
- package/utils/math/map.js +1 -2
- package/utils/math/round.js +1 -2
- package/utils/memoize.d.ts +30 -0
- package/utils/memoize.js +30 -0
- package/utils/nextFrame.js +4 -9
- package/utils/object/autoBind.js +11 -19
- package/utils/object/getAllProperties.js +3 -11
- package/utils/object/index.js +1 -2
- package/utils/object/isObject.js +2 -4
- package/utils/string/index.js +1 -2
- package/utils/string/withLeadingCharacters.js +1 -2
- package/utils/string/withLeadingSlash.js +1 -2
- package/utils/string/withTrailingCharacters.js +1 -2
- package/utils/string/withTrailingSlash.js +1 -2
- package/utils/string/withoutLeadingCharacters.js +1 -2
- package/utils/string/withoutLeadingCharactersRecursive.js +1 -2
- package/utils/string/withoutLeadingSlash.js +1 -2
- package/utils/string/withoutTrailingCharacters.js +1 -2
- package/utils/string/withoutTrailingCharactersRecursive.js +1 -2
- package/utils/string/withoutTrailingSlash.js +1 -2
- package/utils/throttle.js +2 -3
- package/Base/index.js.map +0 -1
- package/Base/managers/ChildrenManager.js.map +0 -1
- package/Base/managers/EventsManager.js.map +0 -1
- package/Base/managers/OptionsManager.js.map +0 -1
- package/Base/managers/RefsManager.js.map +0 -1
- package/Base/managers/ServicesManager.js.map +0 -1
- package/Base/utils.js.map +0 -1
- package/components/Accordion/Accordion.d.ts +0 -83
- package/components/Accordion/Accordion.js +0 -121
- package/components/Accordion/Accordion.js.map +0 -1
- package/components/Accordion/AccordionItem.d.ts +0 -122
- package/components/Accordion/AccordionItem.js +0 -327
- package/components/Accordion/AccordionItem.js.map +0 -1
- package/components/Accordion/index.d.ts +0 -27
- package/components/Accordion/index.js +0 -39
- package/components/Accordion/index.js.map +0 -1
- package/components/Cursor.d.ts +0 -138
- package/components/Cursor.js +0 -167
- package/components/Cursor.js.map +0 -1
- package/components/Draggable.d.ts +0 -49
- package/components/Draggable.js +0 -77
- package/components/Draggable.js.map +0 -1
- package/components/Modal.d.ts +0 -158
- package/components/Modal.js +0 -270
- package/components/Modal.js.map +0 -1
- package/components/Tabs.d.ts +0 -108
- package/components/Tabs.js +0 -195
- package/components/Tabs.js.map +0 -1
- package/components/index.d.ts +0 -6
- package/components/index.js +0 -7
- package/components/index.js.map +0 -1
- package/decorators/index.js.map +0 -1
- package/decorators/withBreakpointManager.js.map +0 -1
- package/decorators/withBreakpointObserver.js.map +0 -1
- package/decorators/withDrag.js.map +0 -1
- package/decorators/withExtraConfig.js.map +0 -1
- package/decorators/withIntersectionObserver.js.map +0 -1
- package/decorators/withMountWhenInView.js.map +0 -1
- package/helpers/createApp.js.map +0 -1
- package/helpers/createBase.d.ts +0 -7
- package/helpers/createBase.js +0 -7
- package/helpers/createBase.js.map +0 -1
- package/helpers/defineComponent.d.ts +0 -11
- package/helpers/defineComponent.js +0 -68
- package/helpers/defineComponent.js.map +0 -1
- package/helpers/importOnInteraction.js.map +0 -1
- package/helpers/importWhenIdle.js.map +0 -1
- package/helpers/importWhenVisible.js.map +0 -1
- package/helpers/index.js.map +0 -1
- package/helpers/utils.js.map +0 -1
- package/index.js.map +0 -1
- package/index.modern.js.map +0 -1
- package/index.umd.js.map +0 -1
- package/services/Service.js.map +0 -1
- package/services/drag.js.map +0 -1
- package/services/index.js.map +0 -1
- package/services/key.js.map +0 -1
- package/services/load.js.map +0 -1
- package/services/pointer.js.map +0 -1
- package/services/raf.js.map +0 -1
- package/services/resize.js.map +0 -1
- package/services/scroll.js.map +0 -1
- package/utils/collide/boundingRectToCircle.js.map +0 -1
- package/utils/collide/collideCircleCircle.js.map +0 -1
- package/utils/collide/collideCircleRect.js.map +0 -1
- package/utils/collide/collidePointCircle.js.map +0 -1
- package/utils/collide/collidePointRect.js.map +0 -1
- package/utils/collide/collideRectRect.js.map +0 -1
- package/utils/collide/index.js.map +0 -1
- package/utils/css/classes.js.map +0 -1
- package/utils/css/index.js.map +0 -1
- package/utils/css/matrix.js.map +0 -1
- package/utils/css/styles.js.map +0 -1
- package/utils/css/transition.js.map +0 -1
- package/utils/debounce.js.map +0 -1
- package/utils/focusTrap.js.map +0 -1
- package/utils/history.js.map +0 -1
- package/utils/index.js.map +0 -1
- package/utils/keyCodes.js.map +0 -1
- package/utils/math/clamp.js.map +0 -1
- package/utils/math/clamp01.js.map +0 -1
- package/utils/math/damp.js.map +0 -1
- package/utils/math/index.js.map +0 -1
- package/utils/math/inertiaFinalValue.js.map +0 -1
- package/utils/math/lerp.js.map +0 -1
- package/utils/math/map.js.map +0 -1
- package/utils/math/round.js.map +0 -1
- package/utils/nextFrame.js.map +0 -1
- package/utils/object/autoBind.js.map +0 -1
- package/utils/object/getAllProperties.js.map +0 -1
- package/utils/object/index.js.map +0 -1
- package/utils/object/isObject.js.map +0 -1
- package/utils/string/index.js.map +0 -1
- package/utils/string/withLeadingCharacters.js.map +0 -1
- package/utils/string/withLeadingSlash.js.map +0 -1
- package/utils/string/withTrailingCharacters.js.map +0 -1
- package/utils/string/withTrailingSlash.js.map +0 -1
- package/utils/string/withoutLeadingCharacters.js.map +0 -1
- package/utils/string/withoutLeadingCharactersRecursive.js.map +0 -1
- package/utils/string/withoutLeadingSlash.js.map +0 -1
- package/utils/string/withoutTrailingCharacters.js.map +0 -1
- package/utils/string/withoutTrailingCharactersRecursive.js.map +0 -1
- package/utils/string/withoutTrailingSlash.js.map +0 -1
- package/utils/throttle.js.map +0 -1
package/Base/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @typedef {typeof Base}
|
|
3
|
-
* @typedef {(Base) => Promise<
|
|
2
|
+
* @typedef {typeof Base} BaseConstructor
|
|
3
|
+
* @typedef {(Base) => Promise<BaseConstructor | { default: BaseConstructor }>} BaseAsyncConstructor
|
|
4
4
|
* @typedef {OptionsManager & { [name:string]: any }} BaseOptions
|
|
5
5
|
* @typedef {{ [name:string]: HTMLElement | HTMLElement[] }} BaseRefs
|
|
6
6
|
* @typedef {{ [nameOrSelector:string]: Base[] | Promise<Base>[] }} BaseChildren
|
|
7
|
-
* @typedef {{ [nameOrSelector:string]:
|
|
7
|
+
* @typedef {{ [nameOrSelector:string]: BaseConstructor | BaseAsyncConstructor }} BaseConfigComponents
|
|
8
8
|
* @typedef {import('./managers/OptionsManager').OptionsSchema} BaseConfigOptions
|
|
9
9
|
* @typedef {import('./managers/ServicesManager.js').ServiceName} ServiceName
|
|
10
10
|
*/
|
|
@@ -18,39 +18,15 @@
|
|
|
18
18
|
* @property {BaseConfigOptions} [options]
|
|
19
19
|
*/
|
|
20
20
|
/**
|
|
21
|
-
* Base class
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```js
|
|
25
|
-
* class Component extends Base {
|
|
26
|
-
* static config = {
|
|
27
|
-
* name: 'Component',
|
|
28
|
-
* log: true,
|
|
29
|
-
* };
|
|
30
|
-
*
|
|
31
|
-
* mounted() {
|
|
32
|
-
* this.$log('Component is mounted!');
|
|
33
|
-
* }
|
|
34
|
-
* }
|
|
35
|
-
*
|
|
36
|
-
* class App extends Base {
|
|
37
|
-
* static config = {
|
|
38
|
-
* name: 'App',
|
|
39
|
-
* components: {
|
|
40
|
-
* Component,
|
|
41
|
-
* },
|
|
42
|
-
* };
|
|
43
|
-
* }
|
|
44
|
-
*
|
|
45
|
-
* new App(document.body).$mount();
|
|
46
|
-
* ```
|
|
21
|
+
* Base class.
|
|
47
22
|
*/
|
|
48
23
|
export default class Base {
|
|
49
24
|
/**
|
|
50
25
|
* This is a Base instance.
|
|
51
26
|
* @type {Boolean}
|
|
27
|
+
* @readonly
|
|
52
28
|
*/
|
|
53
|
-
static $isBase: boolean;
|
|
29
|
+
static readonly $isBase: boolean;
|
|
54
30
|
/**
|
|
55
31
|
* @type {BaseConfig}
|
|
56
32
|
*/
|
|
@@ -89,10 +65,10 @@ export default class Base {
|
|
|
89
65
|
*/
|
|
90
66
|
$isMounted: boolean;
|
|
91
67
|
/**
|
|
92
|
-
* Get
|
|
93
|
-
* @return {
|
|
68
|
+
* Get the root instance of the app.
|
|
69
|
+
* @return {Base}
|
|
94
70
|
*/
|
|
95
|
-
get
|
|
71
|
+
get $root(): Base;
|
|
96
72
|
/**
|
|
97
73
|
* Merge configuration with the parents' configurations.
|
|
98
74
|
*
|
|
@@ -102,41 +78,45 @@ export default class Base {
|
|
|
102
78
|
private get __config();
|
|
103
79
|
/**
|
|
104
80
|
* @type {ServicesManager}
|
|
81
|
+
* @private
|
|
105
82
|
*/
|
|
106
|
-
__services
|
|
83
|
+
private __services;
|
|
107
84
|
/**
|
|
108
|
-
* The instance services.
|
|
109
85
|
* @type {ServicesManager}
|
|
110
86
|
*/
|
|
111
87
|
get $services(): ServicesManager;
|
|
112
88
|
/**
|
|
113
89
|
* @type {RefsManager}
|
|
90
|
+
* @private
|
|
114
91
|
*/
|
|
115
|
-
__refs
|
|
92
|
+
private __refs;
|
|
116
93
|
/**
|
|
117
94
|
* @return {RefsManager}
|
|
118
95
|
*/
|
|
119
96
|
get $refs(): RefsManager;
|
|
120
97
|
/**
|
|
121
98
|
* @type {BaseOptions}
|
|
99
|
+
* @private
|
|
122
100
|
*/
|
|
123
|
-
__options
|
|
101
|
+
private __options;
|
|
124
102
|
/**
|
|
125
103
|
* @return {BaseOptions}
|
|
126
104
|
*/
|
|
127
105
|
get $options(): BaseOptions;
|
|
128
106
|
/**
|
|
129
107
|
* @type {ChildrenManager}
|
|
108
|
+
* @private
|
|
130
109
|
*/
|
|
131
|
-
__children
|
|
110
|
+
private __children;
|
|
132
111
|
/**
|
|
133
112
|
* @return {ChildrenManager}
|
|
134
113
|
*/
|
|
135
114
|
get $children(): ChildrenManager;
|
|
136
115
|
/**
|
|
137
116
|
* @type {EventsManager}
|
|
117
|
+
* @private
|
|
138
118
|
*/
|
|
139
|
-
__events
|
|
119
|
+
private __events;
|
|
140
120
|
/**
|
|
141
121
|
* Small helper to log stuff.
|
|
142
122
|
*
|
|
@@ -151,16 +131,19 @@ export default class Base {
|
|
|
151
131
|
get __debug(): (...args: any) => void;
|
|
152
132
|
/**
|
|
153
133
|
* Trigger the `mounted` callback.
|
|
134
|
+
* @return {this}
|
|
154
135
|
*/
|
|
155
|
-
$mount():
|
|
136
|
+
$mount(): this;
|
|
156
137
|
/**
|
|
157
138
|
* Update the instance children.
|
|
139
|
+
* @return {this}
|
|
158
140
|
*/
|
|
159
|
-
$update():
|
|
141
|
+
$update(): this;
|
|
160
142
|
/**
|
|
161
143
|
* Trigger the `destroyed` callback.
|
|
144
|
+
* @return {this}
|
|
162
145
|
*/
|
|
163
|
-
$destroy():
|
|
146
|
+
$destroy(): this;
|
|
164
147
|
/**
|
|
165
148
|
* Terminate a child instance when it is not needed anymore.
|
|
166
149
|
* @return {void}
|
|
@@ -202,9 +185,9 @@ export default class Base {
|
|
|
202
185
|
*/
|
|
203
186
|
$emit(event: string, ...args: any[]): void;
|
|
204
187
|
}
|
|
205
|
-
export type
|
|
206
|
-
export type
|
|
207
|
-
default:
|
|
188
|
+
export type BaseConstructor = typeof Base;
|
|
189
|
+
export type BaseAsyncConstructor = (Base: any) => Promise<BaseConstructor | {
|
|
190
|
+
default: BaseConstructor;
|
|
208
191
|
}>;
|
|
209
192
|
export type BaseOptions = OptionsManager & {
|
|
210
193
|
[name: string]: any;
|
|
@@ -216,7 +199,7 @@ export type BaseChildren = {
|
|
|
216
199
|
[nameOrSelector: string]: Base[] | Promise<Base>[];
|
|
217
200
|
};
|
|
218
201
|
export type BaseConfigComponents = {
|
|
219
|
-
[nameOrSelector: string]: typeof Base |
|
|
202
|
+
[nameOrSelector: string]: typeof Base | BaseAsyncConstructor;
|
|
220
203
|
};
|
|
221
204
|
export type BaseConfigOptions = import('./managers/OptionsManager').OptionsSchema;
|
|
222
205
|
export type ServiceName = import('./managers/ServicesManager.js').ServiceName;
|
|
@@ -231,5 +214,4 @@ export type BaseConfig = {
|
|
|
231
214
|
import ServicesManager from "./managers/ServicesManager.js";
|
|
232
215
|
import RefsManager from "./managers/RefsManager.js";
|
|
233
216
|
import ChildrenManager from "./managers/ChildrenManager.js";
|
|
234
|
-
import EventsManager from "./managers/EventsManager.js";
|
|
235
217
|
import OptionsManager from "./managers/OptionsManager.js";
|
package/Base/index.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
-
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
-
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
5
2
|
|
|
6
3
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
7
4
|
|
|
8
5
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
9
6
|
|
|
10
|
-
import autoBind from '../utils/object/autoBind.js';
|
|
11
7
|
import { callMethod, getComponentElements } from './utils.js';
|
|
12
8
|
import ChildrenManager from './managers/ChildrenManager.js';
|
|
13
9
|
import RefsManager from './managers/RefsManager.js';
|
|
@@ -16,14 +12,80 @@ import EventsManager from './managers/EventsManager.js';
|
|
|
16
12
|
import OptionsManager from './managers/OptionsManager.js';
|
|
17
13
|
var id = 0;
|
|
18
14
|
|
|
19
|
-
|
|
15
|
+
function noop() {}
|
|
20
16
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
export default class Base {
|
|
18
|
+
get $root() {
|
|
19
|
+
if (!this.$parent) {
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var parent = this.$parent;
|
|
24
|
+
var root = this.$parent;
|
|
25
|
+
|
|
26
|
+
while (parent) {
|
|
27
|
+
if (!parent.$parent) {
|
|
28
|
+
root = parent;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
parent = parent.$parent;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return root;
|
|
35
|
+
}
|
|
24
36
|
|
|
25
|
-
|
|
37
|
+
get __config() {
|
|
38
|
+
var proto = Object.getPrototypeOf(this);
|
|
39
|
+
var {
|
|
40
|
+
config
|
|
41
|
+
} = proto.constructor;
|
|
26
42
|
|
|
43
|
+
while (proto.constructor.config && proto.constructor.$isBase) {
|
|
44
|
+
config = _objectSpread(_objectSpread({}, proto.constructor.config), config);
|
|
45
|
+
|
|
46
|
+
if (proto.constructor.config.options) {
|
|
47
|
+
config.options = _objectSpread(_objectSpread({}, proto.constructor.config.options), config.options);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
proto = Object.getPrototypeOf(proto);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return config;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
get $services() {
|
|
57
|
+
var services = this.__services;
|
|
58
|
+
this.$emit('get:services', services);
|
|
59
|
+
return services;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get $refs() {
|
|
63
|
+
var refs = this.__refs;
|
|
64
|
+
this.$emit('get:refs', refs);
|
|
65
|
+
return refs;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get $options() {
|
|
69
|
+
var options = this.__options;
|
|
70
|
+
this.$emit('get:options', options);
|
|
71
|
+
return options;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
get $children() {
|
|
75
|
+
var children = this.__children;
|
|
76
|
+
this.$emit('get:children', children);
|
|
77
|
+
return children;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
get $log() {
|
|
81
|
+
return this.__options.log ? window.console.log.bind(window, "[".concat(this.__config.name, "]")) : noop;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
get __debug() {
|
|
85
|
+
return this.__options.debug && typeof window.__DEV__ !== 'undefined' && window.__DEV__ ? window.console.log.bind(window, "[debug] [".concat(this.$id, "]")) : noop;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
constructor(element) {
|
|
27
89
|
_defineProperty(this, "$parent", null);
|
|
28
90
|
|
|
29
91
|
_defineProperty(this, "$id", void 0);
|
|
@@ -46,7 +108,9 @@ var Base = function () {
|
|
|
46
108
|
throw new Error('The root element must be defined.');
|
|
47
109
|
}
|
|
48
110
|
|
|
49
|
-
var
|
|
111
|
+
var {
|
|
112
|
+
__config
|
|
113
|
+
} = this;
|
|
50
114
|
|
|
51
115
|
if (!__config) {
|
|
52
116
|
throw new Error('The `config` static property must be defined.');
|
|
@@ -62,9 +126,7 @@ var Base = function () {
|
|
|
62
126
|
|
|
63
127
|
if (!('__base__' in this.$el)) {
|
|
64
128
|
Object.defineProperty(this.$el, '__base__', {
|
|
65
|
-
get:
|
|
66
|
-
return _this;
|
|
67
|
-
},
|
|
129
|
+
get: () => this,
|
|
68
130
|
configurable: true
|
|
69
131
|
});
|
|
70
132
|
}
|
|
@@ -74,191 +136,102 @@ var Base = function () {
|
|
|
74
136
|
this.__events = new EventsManager(element, this);
|
|
75
137
|
this.__children = new ChildrenManager(this, element, __config.components || {}, this.__events);
|
|
76
138
|
this.__refs = new RefsManager(this, element, __config.refs || [], this.__events);
|
|
77
|
-
autoBind(this, {
|
|
78
|
-
exclude: _toConsumableArray(this.__excludeFromAutoBind)
|
|
79
|
-
});
|
|
80
139
|
|
|
81
140
|
this.__debug('constructor', this);
|
|
82
141
|
|
|
83
142
|
return this;
|
|
84
143
|
}
|
|
85
144
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
get: function get() {
|
|
89
|
-
return ['$mount', '$update', '$destroy', '$terminate', '$log', '$on', '$once', '$off', '$emit', 'mounted', 'loaded', 'ticked', 'resized', 'moved', 'keyed', 'scrolled', 'destroyed', 'terminated'];
|
|
90
|
-
}
|
|
91
|
-
}, {
|
|
92
|
-
key: "__config",
|
|
93
|
-
get: function get() {
|
|
94
|
-
var proto = Object.getPrototypeOf(this);
|
|
95
|
-
var config = proto.constructor.config;
|
|
145
|
+
$mount() {
|
|
146
|
+
this.__debug('$mount');
|
|
96
147
|
|
|
97
|
-
|
|
98
|
-
|
|
148
|
+
this.$children.registerAll();
|
|
149
|
+
this.$refs.registerAll();
|
|
99
150
|
|
|
100
|
-
|
|
101
|
-
config.options = _objectSpread(_objectSpread({}, proto.constructor.config.options), config.options);
|
|
102
|
-
}
|
|
151
|
+
this.__events.bindRootElement();
|
|
103
152
|
|
|
104
|
-
|
|
105
|
-
|
|
153
|
+
this.$services.enableAll();
|
|
154
|
+
this.$children.mountAll();
|
|
155
|
+
callMethod(this, 'mounted');
|
|
156
|
+
this.$isMounted = true;
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
106
159
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}, {
|
|
110
|
-
key: "$services",
|
|
111
|
-
get: function get() {
|
|
112
|
-
var services = this.__services;
|
|
113
|
-
this.$emit('get:services', services);
|
|
114
|
-
return services;
|
|
115
|
-
}
|
|
116
|
-
}, {
|
|
117
|
-
key: "$refs",
|
|
118
|
-
get: function get() {
|
|
119
|
-
var refs = this.__refs;
|
|
120
|
-
this.$emit('get:refs', refs);
|
|
121
|
-
return refs;
|
|
122
|
-
}
|
|
123
|
-
}, {
|
|
124
|
-
key: "$options",
|
|
125
|
-
get: function get() {
|
|
126
|
-
var options = this.__options;
|
|
127
|
-
this.$emit('get:options', options);
|
|
128
|
-
return options;
|
|
129
|
-
}
|
|
130
|
-
}, {
|
|
131
|
-
key: "$children",
|
|
132
|
-
get: function get() {
|
|
133
|
-
this.__debug('before:getChildren', this.$el, this.__config.components);
|
|
160
|
+
$update() {
|
|
161
|
+
this.__debug('$update');
|
|
134
162
|
|
|
135
|
-
|
|
136
|
-
|
|
163
|
+
this.$refs.unregisterAll();
|
|
164
|
+
this.$services.disableAll();
|
|
165
|
+
this.$children.registerAll();
|
|
166
|
+
this.$refs.registerAll();
|
|
167
|
+
this.$services.enableAll();
|
|
168
|
+
this.$children.updateAll();
|
|
169
|
+
callMethod(this, 'updated');
|
|
170
|
+
return this;
|
|
171
|
+
}
|
|
137
172
|
|
|
138
|
-
|
|
173
|
+
$destroy() {
|
|
174
|
+
this.__debug('$destroy');
|
|
139
175
|
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
}, {
|
|
143
|
-
key: "$log",
|
|
144
|
-
get: function get() {
|
|
145
|
-
return this.__options.log ? window.console.log.bind(window, "[".concat(this.__config.name, "]")) : noop;
|
|
146
|
-
}
|
|
147
|
-
}, {
|
|
148
|
-
key: "__debug",
|
|
149
|
-
get: function get() {
|
|
150
|
-
return this.__options.debug && typeof window.__DEV__ !== 'undefined' && window.__DEV__ ? window.console.log.bind(window, "[debug] [".concat(this.$id, "]")) : noop;
|
|
151
|
-
}
|
|
152
|
-
}, {
|
|
153
|
-
key: "$mount",
|
|
154
|
-
value: function $mount() {
|
|
155
|
-
this.__debug('$mount');
|
|
176
|
+
this.__events.unbindRootElement();
|
|
156
177
|
|
|
157
|
-
|
|
158
|
-
|
|
178
|
+
this.$refs.unregisterAll();
|
|
179
|
+
this.$services.disableAll();
|
|
180
|
+
this.$children.destroyAll();
|
|
181
|
+
callMethod(this, 'destroyed');
|
|
182
|
+
this.$isMounted = false;
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
159
185
|
|
|
160
|
-
|
|
186
|
+
$terminate() {
|
|
187
|
+
this.__debug('$terminate');
|
|
161
188
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
value: function $update() {
|
|
171
|
-
this.__debug('$update');
|
|
172
|
-
|
|
173
|
-
this.$refs.unregisterAll();
|
|
174
|
-
this.$services.disableAll();
|
|
175
|
-
this.$children.registerAll();
|
|
176
|
-
this.$refs.registerAll();
|
|
177
|
-
this.$services.enableAll();
|
|
178
|
-
this.$children.updateAll();
|
|
179
|
-
callMethod(this, 'updated');
|
|
180
|
-
return this;
|
|
181
|
-
}
|
|
182
|
-
}, {
|
|
183
|
-
key: "$destroy",
|
|
184
|
-
value: function $destroy() {
|
|
185
|
-
this.__debug('$destroy');
|
|
186
|
-
|
|
187
|
-
this.__events.unbindRootElement();
|
|
188
|
-
|
|
189
|
-
this.$refs.unregisterAll();
|
|
190
|
-
this.$services.disableAll();
|
|
191
|
-
this.$children.destroyAll();
|
|
192
|
-
callMethod(this, 'destroyed');
|
|
193
|
-
this.$isMounted = false;
|
|
194
|
-
return this;
|
|
195
|
-
}
|
|
196
|
-
}, {
|
|
197
|
-
key: "$terminate",
|
|
198
|
-
value: function $terminate() {
|
|
199
|
-
this.__debug('$terminate');
|
|
189
|
+
this.$destroy();
|
|
190
|
+
callMethod(this, 'terminated');
|
|
191
|
+
Object.defineProperty(this.$el, '__base__', {
|
|
192
|
+
value: 'terminated',
|
|
193
|
+
configurable: false,
|
|
194
|
+
writable: false
|
|
195
|
+
});
|
|
196
|
+
}
|
|
200
197
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
value: 'terminated',
|
|
205
|
-
configurable: false,
|
|
206
|
-
writable: false
|
|
207
|
-
});
|
|
198
|
+
static $factory(nameOrSelector) {
|
|
199
|
+
if (!nameOrSelector) {
|
|
200
|
+
throw new Error('The $factory method requires a component’s name or selector to be specified.');
|
|
208
201
|
}
|
|
209
|
-
}, {
|
|
210
|
-
key: "$on",
|
|
211
|
-
value: function $on(event, listener, options) {
|
|
212
|
-
var _this2 = this;
|
|
213
202
|
|
|
214
|
-
|
|
203
|
+
return getComponentElements(nameOrSelector).map(el => new this(el).$mount());
|
|
204
|
+
}
|
|
215
205
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
_this2.$off(event, listener, options);
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
}, {
|
|
222
|
-
key: "$off",
|
|
223
|
-
value: function $off(event, listener, options) {
|
|
224
|
-
this.__debug('$off', event, listener);
|
|
206
|
+
$on(event, listener, options) {
|
|
207
|
+
this.__debug('$on', event, listener, options);
|
|
225
208
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
209
|
+
this.$el.addEventListener(event, listener, options);
|
|
210
|
+
return () => {
|
|
211
|
+
this.$off(event, listener, options);
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
$off(event, listener, options) {
|
|
216
|
+
this.__debug('$off', event, listener);
|
|
234
217
|
|
|
235
|
-
|
|
218
|
+
this.$el.removeEventListener(event, listener, options);
|
|
219
|
+
}
|
|
236
220
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
221
|
+
$emit(event) {
|
|
222
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
223
|
+
args[_key - 1] = arguments[_key];
|
|
240
224
|
}
|
|
241
|
-
}], [{
|
|
242
|
-
key: "$factory",
|
|
243
|
-
value: function $factory(nameOrSelector) {
|
|
244
|
-
var _this3 = this;
|
|
245
225
|
|
|
246
|
-
|
|
247
|
-
throw new Error('The $factory method requires a component’s name or selector to be specified.');
|
|
248
|
-
}
|
|
226
|
+
this.__debug('$emit', event, args);
|
|
249
227
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}]);
|
|
228
|
+
this.$el.dispatchEvent(new CustomEvent(event, {
|
|
229
|
+
detail: args
|
|
230
|
+
}));
|
|
231
|
+
}
|
|
255
232
|
|
|
256
|
-
|
|
257
|
-
}();
|
|
233
|
+
}
|
|
258
234
|
|
|
259
235
|
_defineProperty(Base, "$isBase", true);
|
|
260
236
|
|
|
261
|
-
_defineProperty(Base, "config", void 0);
|
|
262
|
-
|
|
263
|
-
export { Base as default };
|
|
264
|
-
//# sourceMappingURL=index.js.map
|
|
237
|
+
_defineProperty(Base, "config", void 0);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef {import('../index.js').default} Base
|
|
3
|
-
* @typedef {import('../index.js').
|
|
4
|
-
* @typedef {import('../index.js').
|
|
3
|
+
* @typedef {import('../index.js').BaseConstructor} BaseConstructor
|
|
4
|
+
* @typedef {import('../index.js').BaseAsyncConstructor} BaseAsyncConstructor
|
|
5
5
|
* @typedef {import('../index.js').BaseConfigComponents} BaseConfigComponents
|
|
6
6
|
* @typedef {import('./EventsManager.js').default} EventsManager
|
|
7
7
|
*/
|
|
@@ -53,7 +53,7 @@ export default class ChildrenManager {
|
|
|
53
53
|
*
|
|
54
54
|
* @param {string} name
|
|
55
55
|
* The name of the child component.
|
|
56
|
-
* @param {
|
|
56
|
+
* @param {BaseConstructor|BaseAsyncConstructor} component
|
|
57
57
|
* A Base class or a Promise for async components.
|
|
58
58
|
* @private
|
|
59
59
|
*/
|
|
@@ -63,7 +63,7 @@ export default class ChildrenManager {
|
|
|
63
63
|
*
|
|
64
64
|
* @param {HTMLElement & { __base__?: Base | 'terminated' }} el
|
|
65
65
|
* The root element of the child component.
|
|
66
|
-
* @param {
|
|
66
|
+
* @param {BaseConstructor|BaseAsyncConstructor} ComponentClass
|
|
67
67
|
* A Base class or a Promise for async components.
|
|
68
68
|
* @param {string} name
|
|
69
69
|
* The name of the child component.
|
|
@@ -102,7 +102,7 @@ export default class ChildrenManager {
|
|
|
102
102
|
private __triggerHook;
|
|
103
103
|
}
|
|
104
104
|
export type Base = import('../index.js').default;
|
|
105
|
-
export type
|
|
106
|
-
export type
|
|
105
|
+
export type BaseConstructor = import('../index.js').BaseConstructor;
|
|
106
|
+
export type BaseAsyncConstructor = import('../index.js').BaseAsyncConstructor;
|
|
107
107
|
export type BaseConfigComponents = import('../index.js').BaseConfigComponents;
|
|
108
108
|
export type EventsManager = import('./EventsManager.js').default;
|