@studiometa/js-toolkit 2.4.2 → 2.4.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @typedef {typeof Base} BaseConstructor
3
3
  * @typedef {(Base) => Promise<BaseConstructor | { default: BaseConstructor }>} BaseAsyncConstructor
4
- * @typedef {OptionsManager & { [name:string]: any }} BaseOptions
4
+ * @typedef {{ [name:string]: any }} BaseOptions
5
5
  * @typedef {{ [name:string]: HTMLElement | HTMLElement[] }} BaseRefs
6
6
  * @typedef {{ [nameOrSelector:string]: Base[] | Promise<Base>[] }} BaseChildren
7
7
  * @typedef {{ [nameOrSelector:string]: BaseConstructor | BaseAsyncConstructor }} BaseConfigComponents
@@ -18,6 +18,14 @@
18
18
  * @property {BaseConfigComponents} [components]
19
19
  * @property {BaseConfigOptions} [options]
20
20
  */
21
+ /**
22
+ * @typedef {{
23
+ * $el?: HTMLElement,
24
+ * $options?: BaseOptions,
25
+ * $refs?: BaseRefs,
26
+ * $children?: { [name:string]: Base | Promise<Base> },
27
+ * }} BaseTypeParameter
28
+ */
21
29
  /**
22
30
  * @typedef {Object} Managers
23
31
  * @property {typeof ChildrenManager} ChildrenManager
@@ -28,12 +36,15 @@
28
36
  */
29
37
  /**
30
38
  * Base class.
31
- * @template {{ $options: BaseOptions, $refs: BaseRefs, $children: BaseChildren }} BaseInterface
39
+ * @template {BaseTypeParameter} [BaseInterface={ $el: HTMLElement, $options: BaseOptions, $refs: BaseRefs, $children: { [name:string]: Base | Promise<Base> } }]
32
40
  */
33
- export default class Base<BaseInterface extends {
41
+ export default class Base<BaseInterface extends BaseTypeParameter = {
42
+ $el: HTMLElement;
34
43
  $options: BaseOptions;
35
44
  $refs: BaseRefs;
36
- $children: BaseChildren;
45
+ $children: {
46
+ [name: string]: Base<any> | Promise<Base<any>>;
47
+ };
37
48
  }> extends EventTarget {
38
49
  /**
39
50
  * This is a Base instance.
@@ -51,7 +62,7 @@ export default class Base<BaseInterface extends {
51
62
  * @param {string} nameOrSelector The selector on which to mount each instance.
52
63
  * @returns {Array<Base>} A list of the created instance.
53
64
  */
54
- static $factory(nameOrSelector: string): Array<Base<any>>;
65
+ static $factory(nameOrSelector: string): Array<Base>;
55
66
  /**
56
67
  * Class constructor where all the magic takes place.
57
68
  *
@@ -62,7 +73,7 @@ export default class Base<BaseInterface extends {
62
73
  * The instance parent.
63
74
  * @type {Base}
64
75
  */
65
- $parent: Base<any>;
76
+ $parent: Base;
66
77
  /**
67
78
  * The instance id.
68
79
  * @type {string}
@@ -70,10 +81,10 @@ export default class Base<BaseInterface extends {
70
81
  $id: string;
71
82
  /**
72
83
  * The root element.
73
- * @type {HTMLElement & { __base__?: WeakMap<BaseConstructor, Base | 'terminated'> }}
84
+ * @type {BaseInterface['$el'] & HTMLElement & { __base__?: WeakMap<BaseConstructor, Base | 'terminated'> }}
74
85
  */
75
- $el: HTMLElement & {
76
- __base__?: WeakMap<BaseConstructor, Base<any> | 'terminated'>;
86
+ $el: BaseInterface['$el'] & HTMLElement & {
87
+ __base__?: WeakMap<BaseConstructor, Base | 'terminated'>;
77
88
  };
78
89
  /**
79
90
  * The state of the component.
@@ -91,7 +102,14 @@ export default class Base<BaseInterface extends {
91
102
  * Get the root instance of the app.
92
103
  * @returns {Base}
93
104
  */
94
- get $root(): Base<any>;
105
+ get $root(): Base<{
106
+ $el: HTMLElement;
107
+ $options: BaseOptions;
108
+ $refs: BaseRefs;
109
+ $children: {
110
+ [name: string]: Base<any> | Promise<Base<any>>;
111
+ };
112
+ }>;
95
113
  /**
96
114
  * Merge configuration with the parents' configurations.
97
115
  *
@@ -109,34 +127,32 @@ export default class Base<BaseInterface extends {
109
127
  */
110
128
  get $services(): ServicesManager;
111
129
  /**
112
- * @type {RefsManager & { [key in keyof BaseInterface['$refs']]: BaseInterface['$refs'][key] }}
130
+ * @type {RefsManager & { [key in keyof BaseInterface['$refs']]: BaseInterface['$refs'][key] } & BaseRefs}
113
131
  * @private
114
132
  */
115
133
  private __refs;
116
134
  /**
117
- * @returns {RefsManager & { [key in keyof BaseInterface['$refs']]: BaseInterface['$refs'][key] }}
135
+ * @returns {RefsManager & { [key in keyof BaseInterface['$refs']]: BaseInterface['$refs'][key] } & BaseRefs}
118
136
  */
119
- get $refs(): RefsManager & (BaseInterface["$refs"] extends infer T ? { [key in keyof T]: BaseInterface["$refs"][key]; } : never);
137
+ get $refs(): RefsManager & (BaseInterface["$refs"] extends infer T ? { [key in keyof T]: BaseInterface["$refs"][key]; } : never) & BaseRefs;
120
138
  /**
121
- * @type {BaseOptions & { [key in keyof BaseInterface['$options']]: BaseInterface['$options'][key] }}
139
+ * @type {OptionsManager & { [key in keyof BaseInterface['$options']]: BaseInterface['$options'][key] } & BaseOptions}
122
140
  * @private
123
141
  */
124
142
  private __options;
125
143
  /**
126
- * @returns {BaseOptions & { [key in keyof BaseInterface['$options']]: BaseInterface['$options'][key] }}
144
+ * @returns {OptionsManager & { [key in keyof BaseInterface['$options']]: BaseInterface['$options'][key] } & BaseOptions}
127
145
  */
128
- get $options(): OptionsManager & {
129
- [name: string]: any;
130
- } & (BaseInterface["$options"] extends infer T_1 ? { [key_1 in keyof T_1]: BaseInterface["$options"][key_1]; } : never);
146
+ get $options(): OptionsManager & (BaseInterface["$options"] extends infer T_1 ? { [key_1 in keyof T_1]: BaseInterface["$options"][key_1]; } : never) & BaseOptions;
131
147
  /**
132
- * @type {ChildrenManager & { [key in keyof BaseInterface['$children']]: Array<BaseInterface['$children'][key]> }}
148
+ * @type {ChildrenManager & { [key in keyof BaseInterface['$children']]: Array<BaseInterface['$children'][key]> } & BaseChildren}
133
149
  * @private
134
150
  */
135
151
  private __children;
136
152
  /**
137
- * @returns {ChildrenManager & { [key in keyof BaseInterface['$children']]: Array<BaseInterface['$children'][key]> }}
153
+ * @returns {ChildrenManager & { [key in keyof BaseInterface['$children']]: Array<BaseInterface['$children'][key]> } & BaseChildren}
138
154
  */
139
- get $children(): ChildrenManager & (BaseInterface["$children"] extends infer T_2 ? { [key_2 in keyof T_2]: BaseInterface["$children"][key_2][]; } : never);
155
+ get $children(): ChildrenManager & (BaseInterface["$children"] extends infer T_2 ? { [key_2 in keyof T_2]: BaseInterface["$children"][key_2][]; } : never) & BaseChildren;
140
156
  /**
141
157
  * @type {EventsManager}
142
158
  * @private
@@ -260,13 +276,29 @@ export type BaseConstructor = typeof Base;
260
276
  export type BaseAsyncConstructor = (Base: any) => Promise<BaseConstructor | {
261
277
  default: BaseConstructor;
262
278
  }>;
263
- export type BaseOptions = OptionsManager & {
279
+ export type BaseOptions = {
264
280
  [name: string]: any;
265
281
  };
266
282
  export type BaseRefs = {
267
283
  [name: string]: HTMLElement | HTMLElement[];
268
284
  };
269
- export type BaseChildren = BaseChildren;
285
+ export type BaseChildren = {
286
+ [nameOrSelector: string]: Base<{
287
+ $el: HTMLElement;
288
+ $options: BaseOptions;
289
+ $refs: BaseRefs;
290
+ $children: {
291
+ [name: string]: Base<any> | Promise<Base<any>>;
292
+ };
293
+ }>[] | Promise<Base<{
294
+ $el: HTMLElement;
295
+ $options: BaseOptions;
296
+ $refs: BaseRefs;
297
+ $children: {
298
+ [name: string]: Base<any> | Promise<Base<any>>;
299
+ };
300
+ }>>[];
301
+ };
270
302
  export type BaseConfigComponents = {
271
303
  [nameOrSelector: string]: typeof Base | BaseAsyncConstructor;
272
304
  };
@@ -281,6 +313,28 @@ export type BaseConfig = {
281
313
  components?: BaseConfigComponents;
282
314
  options?: BaseConfigOptions;
283
315
  };
316
+ export type BaseTypeParameter = {
317
+ $el?: HTMLElement;
318
+ $options?: BaseOptions;
319
+ $refs?: BaseRefs;
320
+ $children?: {
321
+ [name: string]: Base<{
322
+ $el: HTMLElement;
323
+ $options: BaseOptions;
324
+ $refs: BaseRefs;
325
+ $children: {
326
+ [name: string]: Base<any> | Promise<Base<any>>;
327
+ };
328
+ }> | Promise<Base<{
329
+ $el: HTMLElement;
330
+ $options: BaseOptions;
331
+ $refs: BaseRefs;
332
+ $children: {
333
+ [name: string]: Base<any> | Promise<Base<any>>;
334
+ };
335
+ }>>;
336
+ };
337
+ };
284
338
  export type Managers = {
285
339
  ChildrenManager: typeof ChildrenManager;
286
340
  EventsManager: typeof EventsManager;
@@ -12,11 +12,11 @@ export default class AbstractManager {
12
12
  *
13
13
  * @param {Base} base
14
14
  */
15
- constructor(base: import("../index.js").default<any>);
15
+ constructor(base: Base);
16
16
  /**
17
17
  * @type {Base}
18
18
  */
19
- __base: import("../index.js").default<any>;
19
+ __base: Base;
20
20
  /**
21
21
  * Get the base instance root element.
22
22
  * @returns {HTMLElement}
@@ -39,6 +39,6 @@ export default class AbstractManager {
39
39
  */
40
40
  __hideProperties(properties: string[]): void;
41
41
  }
42
- export type Base = import("../index.js").default<any>;
42
+ export type Base = import('../index.js').default;
43
43
  export type BaseConfig = import('../index.js').BaseConfig;
44
44
  export type EventsManager = import('./EventsManager.js').default;
@@ -34,7 +34,7 @@ export default class ChildrenManager extends AbstractManager {
34
34
  */
35
35
  destroyAll(): void;
36
36
  }
37
- export type Base = import("../index.js").default<any>;
37
+ export type Base = import('../index.js').default;
38
38
  export type BaseConstructor = import('../index.js').BaseConstructor;
39
39
  export type BaseAsyncConstructor = import('../index.js').BaseAsyncConstructor;
40
40
  export type BaseConfigComponents = import('../index.js').BaseConfigComponents;
@@ -83,7 +83,7 @@ export default class EventsManager extends AbstractManager {
83
83
  * A base instance.
84
84
  * @returns {void}
85
85
  */
86
- bindChild(name: string, instance: import("../index.js").default<any>): void;
86
+ bindChild(name: string, instance: Base): void;
87
87
  /**
88
88
  * Unbind event methods to the given child instance.
89
89
  *
@@ -93,7 +93,7 @@ export default class EventsManager extends AbstractManager {
93
93
  * A base instance.
94
94
  * @returns {void}
95
95
  */
96
- unbindChild(name: string, instance: import("../index.js").default<any>): void;
96
+ unbindChild(name: string, instance: Base): void;
97
97
  /**
98
98
  * Bind event methods on the root element.
99
99
  *
@@ -107,6 +107,6 @@ export default class EventsManager extends AbstractManager {
107
107
  */
108
108
  unbindRootElement(): void;
109
109
  }
110
- export type Base = import("../index.js").default<any>;
110
+ export type Base = import('../index.js').default;
111
111
  export type ChildrenManager = import('./ChildrenManager.js').default;
112
112
  import AbstractManager from "./AbstractManager.js";
@@ -52,7 +52,7 @@ export default class OptionsManager extends AbstractManager {
52
52
  set(name: string, value: any, config: OptionObject): void;
53
53
  }
54
54
  export type DeepmergeOptions = import('deepmerge').Options;
55
- export type Base = import("../index.js").default<any>;
55
+ export type Base = import('../index.js').default;
56
56
  export type BaseConfig = import('../index.js').BaseConfig;
57
57
  export type OptionType = StringConstructor | NumberConstructor | BooleanConstructor | ArrayConstructor | ObjectConstructor;
58
58
  export type ArrayOption = {
@@ -79,7 +79,7 @@ export default class ServicesManager extends AbstractManager {
79
79
  */
80
80
  unregister(name: string): void;
81
81
  }
82
- export type Base = import("../index").default<any>;
82
+ export type Base = import('../index').default;
83
83
  export type BaseConstructor = import('../index').BaseConstructor;
84
84
  export type ServiceInterface = import('../../services').ServiceInterface<any>;
85
85
  export type Services = typeof SERVICES_MAP & Record<string, () => ServiceInterface>;
package/Base/utils.d.ts CHANGED
@@ -36,5 +36,5 @@ export function eventIsNative(event: string, element: HTMLElement): boolean;
36
36
  * @param {import('./index.js').BaseConfig} config
37
37
  * @returns {Base|Base['$el']}
38
38
  */
39
- export function getEventTarget(instance: import("./index.js").default<any>, event: string, config: import('./index.js').BaseConfig): import("./index.js").default<any> | import("./index.js").default<any>['$el'];
40
- export type Base = import("./index.js").default<any>;
39
+ export function getEventTarget(instance: Base, event: string, config: import('./index.js').BaseConfig): Base | Base['$el'];
40
+ export type Base = import('./index.js').default;
@@ -6,5 +6,5 @@
6
6
  * @returns {T}
7
7
  */
8
8
  export default function withBreakpointManager<T extends typeof import("../Base").default>(BaseClass: T, breakpoints: Array<[string, BaseConstructor]>): T;
9
- export type Base = import("../Base").default<any>;
9
+ export type Base = import('../Base').default;
10
10
  export type BaseConstructor = import('../Base').BaseConstructor;
@@ -6,7 +6,7 @@
6
6
  * @returns {T}
7
7
  */
8
8
  export default function withBreakpointObserver<T extends typeof import("../Base").default>(BaseClass: T): T;
9
- export type Base = import("../Base").default<any>;
9
+ export type Base = import('../Base').default;
10
10
  export type BaseConstructor = import('../Base').BaseConstructor;
11
11
  export type WithBreakpointObserverOptions = {
12
12
  activeBreakpoints?: string;
@@ -15,7 +15,16 @@
15
15
  * @returns {T}
16
16
  */
17
17
  export default function withDrag<T extends typeof import("../Base").default>(BaseClass: T, { target, ...options }?: DragDecoratorOptions): T;
18
- export type Base = import("../Base").default<any>;
18
+ export type Base = import('../Base').default;
19
19
  export type BaseConstructor = import('../Base').BaseConstructor;
20
20
  export type DragServiceOptions = import('../services/drag').DragServiceOptions;
21
- export type DragDecoratorOptions = DragDecoratorOptions;
21
+ export type DragDecoratorOptions = import("../services/drag.js").DragServiceOptions & {
22
+ target?: (this: import("../Base").default<{
23
+ $el: HTMLElement;
24
+ $options: import("../Base").BaseOptions;
25
+ $refs: import("../Base").BaseRefs;
26
+ $children: {
27
+ [name: string]: import("../Base").default<any> | Promise<import("../Base").default<any>>;
28
+ };
29
+ }>, Base: any) => HTMLElement;
30
+ };
@@ -11,7 +11,7 @@ export default function withIntersectionObserver<T extends typeof import("../Bas
11
11
  $observer: IntersectionObserver;
12
12
  };
13
13
  };
14
- export type Base = import("../Base").default<any>;
14
+ export type Base = import('../Base').default;
15
15
  export type BaseConstructor = import('../Base').BaseConstructor;
16
16
  export type WithIntersectionObserverOptions = {
17
17
  intersectionObserver: any;
@@ -21,7 +21,7 @@
21
21
  * @returns {T}
22
22
  */
23
23
  export default function withMountWhenInView<T extends typeof import("../Base").default>(BaseClass: T, defaultOptions?: IntersectionObserverInit): T;
24
- export type Base = import("../Base").default<any>;
24
+ export type Base = import('../Base').default;
25
25
  export type BaseOptions = import('../Base').BaseOptions;
26
26
  export type BaseConstructor = import('../Base').BaseConstructor;
27
27
  export type WithMountWhenInViewOptions = {
@@ -9,7 +9,7 @@
9
9
  export default function withScrolledInView<T extends typeof import("../Base").default>(BaseClass: T, options?: IntersectionObserverInit & {
10
10
  useOffsetSizes?: boolean;
11
11
  }): T;
12
- export type Base = import("../Base").default<any>;
12
+ export type Base = import('../Base').default;
13
13
  export type BaseConstructor = import('../Base').BaseConstructor;
14
14
  export type BaseConfig = import('../Base').BaseConfig;
15
15
  export type ScrollInViewProps = {
@@ -1,6 +1,6 @@
1
1
  declare function _default<T extends typeof import("../Base").default>(BaseClass: T, Vue: import('vue').VueConstructor): T;
2
2
  export default _default;
3
- export type Base = import("../Base").default<any>;
3
+ export type Base = import('../Base').default;
4
4
  export type BaseConstructor = import('../Base').BaseConstructor;
5
5
  export type WithVue2Refs = {
6
6
  vue: HTMLElement;
@@ -8,9 +8,16 @@
8
8
  * @param {Base} parentInstance
9
9
  * @param {string} parentName
10
10
  * @param {string} childrenName
11
- * @returns {Array<T>}
11
+ * @returns {T[]}
12
12
  */
13
- export function getDirectChildren<T extends import("../Base/index.js").default<any>>(parentInstance: import("../Base/index.js").default<any>, parentName: string, childrenName: string): T[];
13
+ export function getDirectChildren<T extends import("../Base/index.js").default<{
14
+ $el: HTMLElement;
15
+ $options: import("../Base/index.js").BaseOptions;
16
+ $refs: import("../Base/index.js").BaseRefs;
17
+ $children: {
18
+ [name: string]: import("../Base/index.js").default<any> | Promise<import("../Base/index.js").default<any>>;
19
+ };
20
+ }>>(parentInstance: Base, parentName: string, childrenName: string): T[];
14
21
  /**
15
22
  * Test if a component instance is a direct child from the given component.
16
23
  *
@@ -20,5 +27,5 @@ export function getDirectChildren<T extends import("../Base/index.js").default<a
20
27
  * @param {Base} childInstance
21
28
  * @returns {boolean}
22
29
  */
23
- export function isDirectChild(parentInstance: import("../Base/index.js").default<any>, parentName: string, childrenName: string, childInstance: import("../Base/index.js").default<any>): boolean;
24
- export type Base = import("../Base/index.js").default<any>;
30
+ export function isDirectChild(parentInstance: Base, parentName: string, childrenName: string, childInstance: Base): boolean;
31
+ export type Base = import('../Base/index.js').default;
@@ -18,6 +18,6 @@
18
18
  */
19
19
  export default function importOnInteraction<T extends typeof import("../Base/index.js").default>(fn: () => Promise<T | {
20
20
  default: T;
21
- }>, nameOrSelectorOrElement: string | HTMLElement | HTMLElement[], events: string | string[], parent?: import("../Base/index.js").default<any>): Promise<T>;
21
+ }>, nameOrSelectorOrElement: string | HTMLElement | HTMLElement[], events: string | string[], parent?: Base): Promise<T>;
22
22
  export type BaseConstructor = import('../Base/index.js').BaseConstructor;
23
- export type Base = import("../Base/index.js").default<any>;
23
+ export type Base = import('../Base/index.js').default;
@@ -18,6 +18,6 @@
18
18
  */
19
19
  export default function importWhenVisible<T extends typeof import("../Base/index.js").default>(fn: () => Promise<T | {
20
20
  default: T;
21
- }>, nameOrSelectorOrElement: string | HTMLElement | HTMLElement[], parent?: import("../Base/index.js").default<any>, observerOptions?: IntersectionObserverInit): Promise<T>;
22
- export type Base = import("../Base/index.js").default<any>;
21
+ }>, nameOrSelectorOrElement: string | HTMLElement | HTMLElement[], parent?: Base, observerOptions?: IntersectionObserverInit): Promise<T>;
22
+ export type Base = import('../Base/index.js').default;
23
23
  export type BaseConstructor = import('../Base/index.js').BaseConstructor;
package/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export { default as Base } from "./Base/index.js";
2
2
  export * from "./decorators/index.js";
3
3
  export * from "./helpers/index.js";
4
4
  export * from "./services/index.js";
5
+ export type BaseTypeParameter = import('./Base/index.js').BaseTypeParameter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@studiometa/js-toolkit",
3
- "version": "2.4.2",
3
+ "version": "2.4.3",
4
4
  "description": "A set of useful little bits of JavaScript to boost your project! 🚀",
5
5
  "publishConfig": {
6
6
  "access": "public"