@studiometa/js-toolkit 2.0.1 → 2.2.0-alpha.1

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.
Files changed (66) hide show
  1. package/Base/index.cjs +55 -18
  2. package/Base/index.d.ts +23 -1
  3. package/Base/index.js +55 -18
  4. package/Base/managers/AbstractManager.cjs +56 -0
  5. package/Base/managers/AbstractManager.d.ts +44 -0
  6. package/Base/managers/AbstractManager.js +35 -0
  7. package/Base/managers/ChildrenManager.cjs +79 -100
  8. package/Base/managers/ChildrenManager.d.ts +7 -82
  9. package/Base/managers/ChildrenManager.js +76 -100
  10. package/Base/managers/EventsManager.cjs +75 -99
  11. package/Base/managers/EventsManager.d.ts +31 -100
  12. package/Base/managers/EventsManager.js +75 -99
  13. package/Base/managers/OptionsManager.cjs +65 -78
  14. package/Base/managers/OptionsManager.d.ts +37 -79
  15. package/Base/managers/OptionsManager.js +66 -79
  16. package/Base/managers/RefsManager.cjs +44 -68
  17. package/Base/managers/RefsManager.d.ts +10 -64
  18. package/Base/managers/RefsManager.js +41 -69
  19. package/Base/managers/ResponsiveOptionsManager.cjs +62 -0
  20. package/Base/managers/ResponsiveOptionsManager.d.ts +26 -0
  21. package/Base/managers/ResponsiveOptionsManager.js +37 -0
  22. package/Base/managers/ServicesManager.cjs +5 -11
  23. package/Base/managers/ServicesManager.d.ts +2 -11
  24. package/Base/managers/ServicesManager.js +5 -11
  25. package/decorators/index.cjs +2 -0
  26. package/decorators/index.d.ts +1 -0
  27. package/decorators/index.js +6 -4
  28. package/decorators/withResponsiveOptions.cjs +39 -0
  29. package/decorators/withResponsiveOptions.d.ts +8 -0
  30. package/decorators/withResponsiveOptions.js +14 -0
  31. package/decorators/withScrolledInView.cjs +66 -23
  32. package/decorators/withScrolledInView.d.ts +4 -2
  33. package/decorators/withScrolledInView.js +67 -24
  34. package/package.json +2 -1
  35. package/services/Service.cjs +2 -2
  36. package/services/Service.d.ts +9 -1
  37. package/services/Service.js +2 -2
  38. package/services/raf.cjs +16 -0
  39. package/services/raf.js +16 -0
  40. package/utils/css/animate.cjs +207 -0
  41. package/utils/css/animate.d.ts +57 -0
  42. package/utils/css/animate.js +182 -0
  43. package/utils/css/getOffsetSizes.cjs +47 -0
  44. package/utils/css/getOffsetSizes.d.ts +15 -0
  45. package/utils/css/getOffsetSizes.js +25 -0
  46. package/utils/css/index.cjs +6 -0
  47. package/utils/css/index.d.ts +3 -0
  48. package/utils/css/index.js +9 -4
  49. package/utils/css/transform.cjs +91 -0
  50. package/utils/css/transform.d.ts +43 -0
  51. package/utils/css/transform.js +66 -0
  52. package/utils/index.cjs +5 -0
  53. package/utils/index.d.ts +3 -0
  54. package/utils/index.js +5 -0
  55. package/utils/isDefined.cjs +28 -0
  56. package/utils/isDefined.d.ts +7 -0
  57. package/utils/isDefined.js +6 -0
  58. package/utils/isFunction.cjs +28 -0
  59. package/utils/isFunction.d.ts +7 -0
  60. package/utils/isFunction.js +6 -0
  61. package/utils/math/index.cjs +2 -0
  62. package/utils/math/index.d.ts +1 -0
  63. package/utils/math/index.js +2 -0
  64. package/utils/scheduler.cjs +73 -0
  65. package/utils/scheduler.d.ts +19 -0
  66. package/utils/scheduler.js +51 -0
@@ -1,66 +1,24 @@
1
1
  /**
2
- * @typedef {import('deepmerge').Options} DeepmergeOptions
3
- * @typedef {import('../index.js').BaseConfig} BaseConfig
4
- * @typedef {StringConstructor|NumberConstructor|BooleanConstructor|ArrayConstructor|ObjectConstructor} OptionType
5
- * @typedef {{type: OptionType, default: string | number | boolean | (() => Array | Object), merge?: boolean | DeepmergeOptions}} OptionObject
6
- * @typedef {OptionType | OptionObject} OptionValue
7
- * @typedef {{ [name:string]: OptionValue }} OptionsSchema
8
- * @typedef {{ [optionName:string]: any }} OptionsInterface
2
+ * Get a property name.
3
+ *
4
+ * @param {string} name
5
+ * @param {string} [prefix]
6
+ * @returns {string}
7
+ * @protected
9
8
  */
9
+ export function __getPropertyName(name: string, prefix?: string): string;
10
10
  /**
11
11
  * Class options to manage options as data attributes on an HTML element.
12
12
  *
13
13
  * @todo Use `MutationObserver` to update values? Might be more performant.
14
- * @augments {OptionsInterface}
15
14
  */
16
- export default class OptionsManager {
17
- /**
18
- * List of allowed types.
19
- * @type {Array}
20
- * @private
21
- */
22
- private static types;
23
- /**
24
- * Property name cache.
25
- * @type {Map}
26
- * @private
27
- */
28
- private static __propertyNameCache;
29
- /**
30
- * Get a property name.
31
- *
32
- * @param {string} name
33
- * @param {string} [prefix]
34
- * @returns {string}
35
- * @private
36
- */
37
- private static __getPropertyName;
38
- /**
39
- * Class constructor.
40
- *
41
- * @param {HTMLElement} element The HTML element storing the options.
42
- * @param {OptionsSchema} schema A Base class config options.
43
- * @param {BaseConfig} baseConfig A Base class config.
44
- */
45
- constructor(element: HTMLElement, schema: OptionsSchema, baseConfig: BaseConfig);
46
- /**
47
- * The HTML element holding the options attributes.
48
- * @type {HTMLElement}
49
- * @private
50
- */
51
- private __element;
15
+ export default class OptionsManager extends AbstractManager {
52
16
  /**
53
17
  * An object to store Array and Object values for reference.
54
18
  * @type {Object}
55
19
  * @private
56
20
  */
57
21
  private __values;
58
- /**
59
- * The default values to return for each available type.
60
- * @type {Object}
61
- * @private
62
- */
63
- private __defaultValues;
64
22
  /**
65
23
  * Default value for the name property.
66
24
  * @type {string}
@@ -76,54 +34,54 @@ export default class OptionsManager {
76
34
  * @type {boolean}
77
35
  */
78
36
  log: boolean;
79
- /**
80
- * Register an option.
81
- *
82
- * @param {string} name
83
- * @param {OptionValue} config
84
- * @returns {void}
85
- * @private
86
- */
87
- private __register;
88
37
  /**
89
38
  * Get an option value.
90
39
  *
91
40
  * @param {string} name The option name.
92
- * @param {OptionType} type The option data's type.
93
- * @param {any} defaultValue The default value for this option.
94
- * @param {boolean|DeepmergeOptions} [merge] Wether to merge the value with the default or not.
41
+ * @param {OptionObject} config The option config.
95
42
  * @returns {any}
96
43
  */
97
- get(name: string, type: OptionType, defaultValue: any, merge?: boolean | DeepmergeOptions): any;
44
+ get(name: string, config: OptionObject): any;
98
45
  /**
99
46
  * Set an option value.
100
47
  *
101
48
  * @param {string} name The option name.
102
- * @param {OptionType} type The option data's type.
103
49
  * @param {any} value The new value for this option.
104
- * @param {any} defaultValue The default value for this option.
105
- */
106
- set(name: string, type: OptionType, value: any, defaultValue: any): void;
107
- /**
108
- * Test if the element has a given property.
109
- *
110
- * @param {string} prop
111
- * @returns {boolean}
50
+ * @param {OptionObject} config The option config.
112
51
  */
113
- __hasProperty(prop: string): boolean;
52
+ set(name: string, value: any, config: OptionObject): void;
114
53
  }
115
54
  export type DeepmergeOptions = import('deepmerge').Options;
55
+ export type Base = import('../index.js').default;
116
56
  export type BaseConfig = import('../index.js').BaseConfig;
117
57
  export type OptionType = StringConstructor | NumberConstructor | BooleanConstructor | ArrayConstructor | ObjectConstructor;
118
- export type OptionObject = {
119
- type: OptionType;
120
- default: string | number | boolean | (() => any[] | any);
121
- merge?: boolean | DeepmergeOptions;
58
+ export type ArrayOption = {
59
+ type: ArrayConstructor;
60
+ default?: () => any[];
61
+ merge?: boolean;
62
+ };
63
+ export type ObjectOption = {
64
+ type: ObjectConstructor;
65
+ default?: () => any;
66
+ merge?: boolean;
67
+ };
68
+ export type StringOption = {
69
+ type: StringConstructor;
70
+ default?: string;
71
+ };
72
+ export type NumberOption = {
73
+ type: NumberConstructor;
74
+ default?: number;
75
+ };
76
+ export type BooleanOption = {
77
+ type: BooleanConstructor;
78
+ default?: boolean;
122
79
  };
123
- export type OptionValue = OptionType | OptionObject;
80
+ export type OptionObject = ArrayOption | ObjectOption | StringOption | NumberOption | BooleanOption;
124
81
  export type OptionsSchema = {
125
- [name: string]: OptionValue;
82
+ [name: string]: OptionType | OptionObject;
126
83
  };
127
84
  export type OptionsInterface = {
128
85
  [optionName: string]: any;
129
86
  };
87
+ import AbstractManager from "./AbstractManager.js";
@@ -5,80 +5,79 @@ var __publicField = (obj, key, value) => {
5
5
  return value;
6
6
  };
7
7
  import deepmerge from "deepmerge";
8
+ import AbstractManager from "./AbstractManager.js";
8
9
  import isObject from "../../utils/object/isObject.js";
9
- const _OptionsManager = class {
10
- constructor(element, schema, baseConfig) {
11
- __publicField(this, "__element");
10
+ const types = /* @__PURE__ */ new Set([String, Number, Boolean, Array, Object]);
11
+ const __defaultValues = {
12
+ String: "",
13
+ Number: 0,
14
+ Boolean: false,
15
+ Array: () => [],
16
+ Object: () => ({})
17
+ };
18
+ function __hasProperty(that, prop) {
19
+ return typeof that.__element.dataset[prop] !== "undefined";
20
+ }
21
+ const __propertyNameCache = /* @__PURE__ */ new Map();
22
+ function __getPropertyName(name, prefix = "") {
23
+ const key = name + prefix;
24
+ if (__propertyNameCache.has(key)) {
25
+ return __propertyNameCache.get(key);
26
+ }
27
+ const propertyName = `option${prefix}${name.replace(/^\w/, (c) => c.toUpperCase())}`;
28
+ __propertyNameCache.set(key, propertyName);
29
+ return propertyName;
30
+ }
31
+ function __register(that, name, config) {
32
+ var _a;
33
+ if (!types.has(config.type)) {
34
+ throw new Error(`The "${name}" option has an invalid type. The allowed types are: String, Number, Boolean, Array and Object.`);
35
+ }
36
+ config.default = (_a = config.default) != null ? _a : __defaultValues[config.type.name];
37
+ if ((config.type === Array || config.type === Object) && typeof config.default !== "function") {
38
+ throw new Error(`The default value for options of type "${config.type.name}" must be returned by a function.`);
39
+ }
40
+ Object.defineProperty(that, name, {
41
+ get: () => {
42
+ return that.get(name, config);
43
+ },
44
+ set: (value) => {
45
+ that.set(name, value, config);
46
+ },
47
+ enumerable: true
48
+ });
49
+ }
50
+ class OptionsManager extends AbstractManager {
51
+ constructor(base) {
52
+ super(base);
12
53
  __publicField(this, "__values", {});
13
- __publicField(this, "__defaultValues", {
14
- String: "",
15
- Number: 0,
16
- Boolean: false,
17
- Array: () => [],
18
- Object: () => ({})
19
- });
20
54
  __publicField(this, "name", "Base");
21
55
  __publicField(this, "debug", false);
22
56
  __publicField(this, "log", false);
23
57
  var _a, _b;
24
- Object.defineProperties(this, {
25
- __element: {
26
- enumerable: false,
27
- writable: false,
28
- value: element
29
- },
30
- __values: {
31
- enumerable: false,
32
- writable: false,
33
- value: this.__values
34
- },
35
- __defaultValues: {
36
- enumerable: false,
37
- writable: false,
38
- value: this.__defaultValues
39
- }
40
- });
41
- this.name = baseConfig.name;
58
+ this.__hideProperties(["__values", "__defaultValues"]);
59
+ const schema = this.__config.options || {};
60
+ this.name = this.__config.name;
42
61
  schema.debug = {
43
62
  type: Boolean,
44
- default: (_a = baseConfig.debug) != null ? _a : false
63
+ default: (_a = this.__config.debug) != null ? _a : false
45
64
  };
46
65
  schema.log = {
47
66
  type: Boolean,
48
- default: (_b = baseConfig.log) != null ? _b : false
67
+ default: (_b = this.__config.log) != null ? _b : false
49
68
  };
50
69
  Object.entries(schema).forEach(([name, config]) => {
51
- this.__register(name, config);
70
+ __register(this, name, types.has(config) ? { type: config } : config);
52
71
  });
53
72
  }
54
- __register(name, config) {
55
- const isObjectConfig = typeof config === "object";
56
- const hasDefaultValue = !_OptionsManager.types.includes(config);
57
- const type = isObjectConfig ? config.type : config;
58
- if (!_OptionsManager.types.includes(type)) {
59
- throw new Error(`The "${name}" option has an invalid type. The allowed types are: String, Number, Boolean, Array and Object.`);
60
- }
61
- const defaultValue = hasDefaultValue ? config.default : this.__defaultValues[type.name];
62
- if ((type === Array || type === Object) && typeof defaultValue !== "function") {
63
- throw new Error(`The default value for options of type "${type.name}" must be returned by a function.`);
64
- }
65
- Object.defineProperty(this, name, {
66
- get: () => {
67
- return this.get(name, type, defaultValue, isObjectConfig ? config.merge : void 0);
68
- },
69
- set: (value) => {
70
- this.set(name, type, value, defaultValue);
71
- },
72
- enumerable: true
73
- });
74
- }
75
- get(name, type, defaultValue, merge) {
76
- const propertyName = _OptionsManager.__getPropertyName(name);
77
- const hasProperty = this.__hasProperty(propertyName);
73
+ get(name, config) {
74
+ const { type, default: defaultValue } = config;
75
+ const propertyName = __getPropertyName(name);
76
+ const hasProperty = __hasProperty(this, propertyName);
78
77
  if (type === Boolean) {
79
78
  if (defaultValue) {
80
- const negatedPropertyName = _OptionsManager.__getPropertyName(name, "No");
81
- const hasNegatedProperty = this.__hasProperty(negatedPropertyName);
79
+ const negatedPropertyName = __getPropertyName(name, "No");
80
+ const hasNegatedProperty = __hasProperty(this, negatedPropertyName);
82
81
  return !hasNegatedProperty;
83
82
  }
84
83
  return hasProperty || defaultValue;
@@ -88,10 +87,11 @@ const _OptionsManager = class {
88
87
  return hasProperty ? Number(value) : defaultValue;
89
88
  }
90
89
  if (type === Array || type === Object) {
90
+ config = type === Array ? config : config;
91
91
  if (!this.__values[name]) {
92
- let val = hasProperty ? JSON.parse(value) : defaultValue();
93
- if (typeof merge !== "undefined") {
94
- val = typeof merge === "boolean" ? deepmerge(defaultValue(), val) : deepmerge(defaultValue(), val, merge);
92
+ let val = hasProperty ? JSON.parse(value) : config.default();
93
+ if (typeof config.merge !== "undefined") {
94
+ val = typeof config.merge === "boolean" ? deepmerge(config.default(), val) : deepmerge(config.default(), val, config.merge);
95
95
  }
96
96
  this.__values[name] = val;
97
97
  }
@@ -99,8 +99,9 @@ const _OptionsManager = class {
99
99
  }
100
100
  return hasProperty ? value : defaultValue;
101
101
  }
102
- set(name, type, value, defaultValue) {
103
- const propertyName = _OptionsManager.__getPropertyName(name);
102
+ set(name, value, config) {
103
+ const { type, default: defaultValue } = config;
104
+ const propertyName = __getPropertyName(name);
104
105
  if (value.constructor.name !== type.name) {
105
106
  const val = Array.isArray(value) || isObject(value) ? JSON.stringify(value) : value;
106
107
  throw new TypeError(`The "${val}" value for the "${name}" option must be of type "${type.name}"`);
@@ -108,7 +109,7 @@ const _OptionsManager = class {
108
109
  switch (type) {
109
110
  case Boolean:
110
111
  if (defaultValue) {
111
- const negatedPropertyName = _OptionsManager.__getPropertyName(name, "No");
112
+ const negatedPropertyName = __getPropertyName(name, "No");
112
113
  if (value) {
113
114
  delete this.__element.dataset[negatedPropertyName];
114
115
  } else {
@@ -128,22 +129,8 @@ const _OptionsManager = class {
128
129
  this.__element.dataset[propertyName] = value;
129
130
  }
130
131
  }
131
- __hasProperty(prop) {
132
- return typeof this.__element.dataset[prop] !== "undefined";
133
- }
134
- static __getPropertyName(name, prefix = "") {
135
- const key = name + prefix;
136
- if (_OptionsManager.__propertyNameCache.has(key)) {
137
- return _OptionsManager.__propertyNameCache.get(key);
138
- }
139
- const propertyName = `option${prefix}${name.replace(/^\w/, (c) => c.toUpperCase())}`;
140
- _OptionsManager.__propertyNameCache.set(key, propertyName);
141
- return propertyName;
142
- }
143
- };
144
- let OptionsManager = _OptionsManager;
145
- __publicField(OptionsManager, "types", [String, Number, Boolean, Array, Object]);
146
- __publicField(OptionsManager, "__propertyNameCache", /* @__PURE__ */ new Map());
132
+ }
147
133
  export {
134
+ __getPropertyName,
148
135
  OptionsManager as default
149
136
  };
@@ -1,8 +1,9 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  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
7
  var __export = (target, all) => {
7
8
  for (var name in all)
8
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -15,85 +16,60 @@ var __copyProps = (to, from, except, desc) => {
15
16
  }
16
17
  return to;
17
18
  };
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));
18
20
  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
21
 
24
22
  // packages/js-toolkit/Base/managers/RefsManager.js
25
23
  var RefsManager_exports = {};
26
24
  __export(RefsManager_exports, {
27
- default: () => RefsManager
25
+ default: () => RefsManager,
26
+ normalizeRefName: () => normalizeRefName
28
27
  });
29
28
  module.exports = __toCommonJS(RefsManager_exports);
30
- var RefsManager = class {
31
- constructor(base, element, refs, eventsManager) {
32
- __publicField(this, "__element");
33
- __publicField(this, "__refs");
34
- __publicField(this, "__base");
35
- __publicField(this, "__eventsManager");
36
- Object.defineProperties(this, {
37
- __element: {
38
- enumerable: false,
39
- writable: false,
40
- value: element
41
- },
42
- __refs: {
43
- enumerable: false,
44
- writable: false,
45
- value: refs
46
- },
47
- __base: {
48
- enumerable: false,
49
- writable: false,
50
- value: base
51
- },
52
- __eventsManager: {
53
- enumerable: false,
54
- writable: false,
55
- value: eventsManager
56
- }
57
- });
58
- }
59
- registerAll() {
60
- this.__refs.forEach((refName) => this.__register(refName));
29
+ var import_AbstractManager = __toESM(require("./AbstractManager.cjs"), 1);
30
+ function normalizeRefName(name) {
31
+ return name.endsWith("[]") ? name.replace(/\[\]$/, "") : name;
32
+ }
33
+ function __filterRefsBelongingToInstance(that, ref) {
34
+ let ancestor = ref.parentElement;
35
+ while (ancestor && ancestor.dataset.component === void 0) {
36
+ ancestor = ancestor.parentElement;
61
37
  }
62
- unregisterAll() {
63
- this.__refs.forEach((refName) => this.__unregister(refName));
38
+ return ancestor === null || ancestor === that.__element;
39
+ }
40
+ function __register(that, refName) {
41
+ const isMultiple = refName.endsWith("[]");
42
+ const propName = normalizeRefName(refName);
43
+ const refs = Array.from(that.__element.querySelectorAll(`[data-ref="${refName}"]`)).filter((ref) => __filterRefsBelongingToInstance(that, ref));
44
+ if (!isMultiple && refs.length > 1) {
45
+ console.warn(`[${that.__base.$options.name}]`, `The "${refName}" ref has been found multiple times.`, "Did you forgot to add the `[]` suffix to its name?");
64
46
  }
65
- __register(refName) {
66
- const isMultiple = refName.endsWith("[]");
67
- const propName = RefsManager.normalizeRefName(refName);
68
- const refs = Array.from(this.__element.querySelectorAll(`[data-ref="${refName}"]`)).filter((ref) => this.__filterRefsBelongingToInstance(ref));
69
- if (!isMultiple && refs.length > 1) {
70
- console.warn(`[${this.__base.$options.name}]`, `The "${refName}" ref has been found multiple times.`, "Did you forgot to add the `[]` suffix to its name?");
71
- }
72
- if (!isMultiple && refs.length <= 1 && refs[0] === void 0) {
73
- console.warn(`[${this.__base.$options.name}]`, `The "${refName}" ref is missing.`, `Is there an \`[data-ref="${refName}"]\` element in the component's scope?`);
74
- return;
75
- }
76
- this.__eventsManager.bindRef(refName, refs);
77
- Object.defineProperty(this, propName, {
78
- value: isMultiple || refs.length > 1 ? refs : refs[0],
79
- enumerable: true,
80
- configurable: true
81
- });
47
+ if (!isMultiple && refs.length <= 1 && refs[0] === void 0) {
48
+ console.warn(`[${that.__base.$options.name}]`, `The "${refName}" ref is missing.`, `Is there an \`[data-ref="${refName}"]\` element in the component's scope?`);
49
+ return;
82
50
  }
83
- __unregister(refName) {
84
- const propName = RefsManager.normalizeRefName(refName);
85
- const refs = Array.isArray(this[propName]) ? this[propName] : [this[propName]];
86
- this.__eventsManager.unbindRef(refName, refs);
51
+ that.__eventsManager.bindRef(refName, refs);
52
+ Object.defineProperty(that, propName, {
53
+ value: isMultiple || refs.length > 1 ? refs : refs[0],
54
+ enumerable: true,
55
+ configurable: true
56
+ });
57
+ }
58
+ function __unregister(that, refName) {
59
+ const propName = normalizeRefName(refName);
60
+ const refs = Array.isArray(that[propName]) ? that[propName] : [that[propName]];
61
+ that.__eventsManager.unbindRef(refName, refs);
62
+ }
63
+ var RefsManager = class extends import_AbstractManager.default {
64
+ get __refs() {
65
+ var _a;
66
+ return (_a = this.__config.refs) != null ? _a : [];
87
67
  }
88
- static normalizeRefName(name) {
89
- return name.endsWith("[]") ? name.replace(/\[\]$/, "") : name;
68
+ registerAll() {
69
+ this.__refs.forEach((refName) => __register(this, refName));
90
70
  }
91
- __filterRefsBelongingToInstance(ref) {
92
- let ancestor = ref.parentElement;
93
- while (ancestor && ancestor.dataset.component === void 0) {
94
- ancestor = ancestor.parentElement;
95
- }
96
- return ancestor === null || ancestor === this.__element;
71
+ unregisterAll() {
72
+ this.__refs.forEach((refName) => __unregister(this, refName));
97
73
  }
98
74
  };
99
75
  if (module.exports.default) module.exports = module.exports.default;
@@ -1,52 +1,21 @@
1
1
  /**
2
- * @typedef {import('../index.js').default} Base
3
- * @typedef {import('./EventsManager.js').default} EventsManager
2
+ * Normalize the name of ref.
3
+ *
4
+ * @param {string} name The original name.
5
+ * @returns {string} The normalized name.
4
6
  */
7
+ export function normalizeRefName(name: string): string;
5
8
  /**
6
9
  * Refs Manager
7
10
  *
8
11
  * @todo Use `MutationObserver` to automatically update refs?
9
12
  */
10
- export default class RefsManager {
11
- /**
12
- * Normalize the name of ref.
13
- *
14
- * @param {string} name The original name.
15
- * @returns {string} The normalized name.
16
- */
17
- static normalizeRefName(name: string): string;
18
- /**
19
- * Class constructor.
20
- *
21
- * @param {Base} base
22
- * The base instance tied to this manager.
23
- * @param {HTMLElement} element
24
- * The root element of a Base component.
25
- * @param {string[]} refs
26
- * The list of refs of this component.
27
- * @param {EventsManager} eventsManager
28
- */
29
- constructor(base: Base, element: HTMLElement, refs: string[], eventsManager: EventsManager);
30
- /**
31
- * @type {HTMLElement}
32
- * @private
33
- */
34
- private __element;
35
- /**
36
- * @type {string[]}
37
- * @private
38
- */
39
- private __refs;
13
+ export default class RefsManager extends AbstractManager {
40
14
  /**
41
- * @type {Base}
42
- * @private
15
+ * Get refs configuration.
16
+ * @returns {string[]}
43
17
  */
44
- private __base;
45
- /**
46
- * @type {EventsManager}
47
- * @private
48
- */
49
- private __eventsManager;
18
+ get __refs(): string[];
50
19
  /**
51
20
  * Register all refs.
52
21
  *
@@ -59,28 +28,5 @@ export default class RefsManager {
59
28
  * @returns {void}
60
29
  */
61
30
  unregisterAll(): void;
62
- /**
63
- * Register one ref.
64
- *
65
- * @param {string} refName The ref name.
66
- * @private
67
- */
68
- private __register;
69
- /**
70
- * Unregister one ref.
71
- *
72
- * @param {string} refName The ref name.
73
- * @private
74
- */
75
- private __unregister;
76
- /**
77
- * Filter refs belonging to the related Base instance.
78
- *
79
- * @param {HTMLElement} ref The ref to test.
80
- * @returns {boolean}
81
- * @private
82
- */
83
- private __filterRefsBelongingToInstance;
84
31
  }
85
- export type Base = import('../index.js').default;
86
- export type EventsManager = import('./EventsManager.js').default;
32
+ import AbstractManager from "./AbstractManager.js";