@studiometa/js-toolkit 2.4.4-alpha.3 → 2.4.4-alpha.4

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 (73) hide show
  1. package/Base/index.cjs +1 -1
  2. package/Base/index.d.ts +16 -18
  3. package/Base/index.js +1 -1
  4. package/Base/managers/AbstractManager.d.ts +2 -2
  5. package/Base/managers/ChildrenManager.cjs +2 -4
  6. package/Base/managers/ChildrenManager.d.ts +2 -10
  7. package/Base/managers/ChildrenManager.js +1 -3
  8. package/Base/managers/EventsManager.cjs +3 -3
  9. package/Base/managers/EventsManager.d.ts +9 -15
  10. package/Base/managers/EventsManager.js +2 -2
  11. package/Base/managers/OptionsManager.d.ts +2 -2
  12. package/Base/managers/ServicesManager.d.ts +1 -1
  13. package/Base/utils.cjs +1 -1
  14. package/Base/utils.d.ts +5 -21
  15. package/decorators/index.cjs +2 -0
  16. package/decorators/index.d.ts +1 -0
  17. package/decorators/index.js +4 -2
  18. package/decorators/withBreakpointManager.cjs +3 -2
  19. package/decorators/withBreakpointManager.d.ts +2 -56
  20. package/decorators/withBreakpointManager.js +3 -2
  21. package/decorators/withBreakpointObserver.cjs +6 -4
  22. package/decorators/withBreakpointObserver.d.ts +71 -16
  23. package/decorators/withBreakpointObserver.js +6 -4
  24. package/decorators/withDrag.cjs +5 -4
  25. package/decorators/withDrag.d.ts +58 -16
  26. package/decorators/withDrag.js +5 -4
  27. package/decorators/withExtraConfig.cjs +4 -3
  28. package/decorators/withExtraConfig.d.ts +60 -17
  29. package/decorators/withExtraConfig.js +4 -3
  30. package/decorators/withFreezedOptions.cjs +3 -2
  31. package/decorators/withFreezedOptions.d.ts +68 -16
  32. package/decorators/withFreezedOptions.js +3 -2
  33. package/decorators/withIntersectionObserver.cjs +6 -4
  34. package/decorators/withIntersectionObserver.d.ts +64 -17
  35. package/decorators/withIntersectionObserver.js +6 -4
  36. package/decorators/withMountWhenInView.cjs +10 -5
  37. package/decorators/withMountWhenInView.d.ts +71 -16
  38. package/decorators/withMountWhenInView.js +10 -5
  39. package/decorators/withResponsiveOptions.cjs +3 -2
  40. package/decorators/withResponsiveOptions.d.ts +65 -17
  41. package/decorators/withResponsiveOptions.js +3 -2
  42. package/decorators/withScrolledInView.cjs +5 -4
  43. package/decorators/withScrolledInView.d.ts +222 -55
  44. package/decorators/withScrolledInView.js +5 -4
  45. package/decorators/withType.cjs +28 -0
  46. package/decorators/withType.d.ts +5 -0
  47. package/decorators/withType.js +6 -0
  48. package/decorators/withVue2.cjs +7 -4
  49. package/decorators/withVue2.d.ts +61 -17
  50. package/decorators/withVue2.js +7 -4
  51. package/helpers/createApp.cjs +1 -1
  52. package/helpers/createApp.d.ts +2 -10
  53. package/helpers/getDirectChildren.cjs +5 -5
  54. package/helpers/getDirectChildren.d.ts +3 -6
  55. package/helpers/getDirectChildren.js +4 -4
  56. package/helpers/getInstanceFromElement.cjs +3 -4
  57. package/helpers/getInstanceFromElement.d.ts +2 -11
  58. package/helpers/getInstanceFromElement.js +2 -3
  59. package/helpers/importOnInteraction.cjs +1 -1
  60. package/helpers/importOnInteraction.d.ts +5 -10
  61. package/helpers/importWhenIdle.cjs +3 -5
  62. package/helpers/importWhenIdle.d.ts +7 -10
  63. package/helpers/importWhenIdle.js +2 -4
  64. package/helpers/importWhenVisible.cjs +1 -1
  65. package/helpers/importWhenVisible.d.ts +2 -7
  66. package/helpers/index.cjs +1 -1
  67. package/helpers/index.d.ts +6 -6
  68. package/helpers/utils.cjs +1 -1
  69. package/helpers/utils.d.ts +1 -1
  70. package/index.cjs +2 -8
  71. package/index.d.ts +1 -1
  72. package/index.js +2 -2
  73. package/package.json +1 -1
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // packages/js-toolkit/helpers/getDirectChildren.js
19
+ // packages/js-toolkit/helpers/getDirectChildren.ts
20
20
  var getDirectChildren_exports = {};
21
21
  __export(getDirectChildren_exports, {
22
22
  getDirectChildren: () => getDirectChildren,
@@ -33,12 +33,12 @@ function getDirectChildren(parentInstance, parentName, childrenName) {
33
33
  if (!(0, import_utils.isArray)(nestedParents) || nestedParents.length <= 0) {
34
34
  return children;
35
35
  }
36
- return children.filter((child) => {
37
- return nestedParents.every((nestedParent) => {
36
+ return [...children].filter(
37
+ (child) => [...nestedParents].every((nestedParent) => {
38
38
  const nestedChildren = nestedParent.$children[childrenName];
39
39
  return (0, import_utils.isArray)(nestedChildren) ? !nestedChildren.includes(child) : true;
40
- });
41
- });
40
+ })
41
+ );
42
42
  }
43
43
  function isDirectChild(parentInstance, parentName, childrenName, childInstance) {
44
44
  return getDirectChildren(parentInstance, parentName, childrenName).includes(childInstance);
@@ -1,6 +1,4 @@
1
- /**
2
- * @typedef {import('../Base/index.js').default} Base
3
- */
1
+ import { Base } from '../Base/index.js';
4
2
  /**
5
3
  * Get direct children from a parent when working with nested components.
6
4
  *
@@ -10,7 +8,7 @@
10
8
  * @param {string} childrenName
11
9
  * @returns {T[]}
12
10
  */
13
- export function getDirectChildren<T extends import("../Base/index.js").default<import("../Base/index.js").BaseTypeParameter>>(parentInstance: Base, parentName: string, childrenName: string): T[];
11
+ export declare function getDirectChildren<T extends Base = Base>(parentInstance: Base, parentName: string, childrenName: string): T[];
14
12
  /**
15
13
  * Test if a component instance is a direct child from the given component.
16
14
  *
@@ -20,5 +18,4 @@ export function getDirectChildren<T extends import("../Base/index.js").default<i
20
18
  * @param {Base} childInstance
21
19
  * @returns {boolean}
22
20
  */
23
- export function isDirectChild(parentInstance: Base, parentName: string, childrenName: string, childInstance: Base): boolean;
24
- export type Base = import('../Base/index.js').default;
21
+ export declare function isDirectChild(parentInstance: any, parentName: any, childrenName: any, childInstance: any): boolean;
@@ -8,12 +8,12 @@ function getDirectChildren(parentInstance, parentName, childrenName) {
8
8
  if (!isArray(nestedParents) || nestedParents.length <= 0) {
9
9
  return children;
10
10
  }
11
- return children.filter((child) => {
12
- return nestedParents.every((nestedParent) => {
11
+ return [...children].filter(
12
+ (child) => [...nestedParents].every((nestedParent) => {
13
13
  const nestedChildren = nestedParent.$children[childrenName];
14
14
  return isArray(nestedChildren) ? !nestedChildren.includes(child) : true;
15
- });
16
- });
15
+ })
16
+ );
17
17
  }
18
18
  function isDirectChild(parentInstance, parentName, childrenName, childInstance) {
19
19
  return getDirectChildren(parentInstance, parentName, childrenName).includes(childInstance);
@@ -16,17 +16,16 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // packages/js-toolkit/helpers/getInstanceFromElement.js
19
+ // packages/js-toolkit/helpers/getInstanceFromElement.ts
20
20
  var getInstanceFromElement_exports = {};
21
21
  __export(getInstanceFromElement_exports, {
22
22
  default: () => getInstanceFromElement
23
23
  });
24
24
  module.exports = __toCommonJS(getInstanceFromElement_exports);
25
25
  function getInstanceFromElement(element, Constructor) {
26
- var _a;
27
- if (!element.__base__) {
26
+ if (!element.__base__ || !element.__base__.has(Constructor)) {
28
27
  return null;
29
28
  }
30
- return (_a = element.__base__.get(Constructor)) != null ? _a : null;
29
+ return element.__base__.get(Constructor);
31
30
  }
32
31
  if (module.exports.default) module.exports = module.exports.default;
@@ -1,14 +1,5 @@
1
- /**
2
- * @typedef {import('../Base/index.js').BaseConstructor} BaseConstructor
3
- */
1
+ import type { BaseConstructor, BaseEl } from '../Base/index.js';
4
2
  /**
5
3
  * Get a component instance from a DOM element.
6
- * @template {BaseConstructor} T
7
- * @param {HTMLElement & { __base__?: WeakMap<T, InstanceType<T>> }} element
8
- * @param {T} Constructor
9
- * @returns {null|InstanceType<T>}
10
4
  */
11
- export default function getInstanceFromElement<T extends typeof import("../Base/index.js").default>(element: HTMLElement & {
12
- __base__?: WeakMap<T, InstanceType<T>>;
13
- }, Constructor: T): InstanceType<T>;
14
- export type BaseConstructor = import('../Base/index.js').BaseConstructor;
5
+ export default function getInstanceFromElement<T extends BaseConstructor>(element: BaseEl, Constructor: T): InstanceType<T> | null;
@@ -1,9 +1,8 @@
1
1
  function getInstanceFromElement(element, Constructor) {
2
- var _a;
3
- if (!element.__base__) {
2
+ if (!element.__base__ || !element.__base__.has(Constructor)) {
4
3
  return null;
5
4
  }
6
- return (_a = element.__base__.get(Constructor)) != null ? _a : null;
5
+ return element.__base__.get(Constructor);
7
6
  }
8
7
  export {
9
8
  getInstanceFromElement as default
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // packages/js-toolkit/helpers/importOnInteraction.js
19
+ // packages/js-toolkit/helpers/importOnInteraction.ts
20
20
  var importOnInteraction_exports = {};
21
21
  __export(importOnInteraction_exports, {
22
22
  default: () => importOnInteraction
@@ -1,11 +1,8 @@
1
- /**
2
- * @typedef {import('../Base/index.js').BaseConstructor} BaseConstructor
3
- * @typedef {import('../Base/index.js').default} Base
4
- */
1
+ import type { Base, BaseConstructor } from '../Base/index.js';
5
2
  /**
6
3
  * Import a component on an interaction.
7
4
  *
8
- * @template {BaseConstructor} T
5
+ * @template {BaseConstructor} [T=BaseConstructor]
9
6
  * @param {() => Promise<T|{default:T}>} fn
10
7
  * The import function.
11
8
  * @param {string|HTMLElement|HTMLElement[]} nameOrSelectorOrElement
@@ -14,10 +11,8 @@
14
11
  * The events to listen to to trigger the import.
15
12
  * @param {Base} [parent]
16
13
  * The parent component.
17
- * @returns {Promise<T>}
14
+ * @returns {Promise<InstanceType<T>>}
18
15
  */
19
- export default function importOnInteraction<T extends typeof import("../Base/index.js").default>(fn: () => Promise<T | {
16
+ export default function importOnInteraction<T extends BaseConstructor = BaseConstructor>(fn: () => Promise<T | {
20
17
  default: T;
21
- }>, nameOrSelectorOrElement: string | HTMLElement | HTMLElement[], events: string | string[], parent?: Base): Promise<T>;
22
- export type BaseConstructor = import('../Base/index.js').BaseConstructor;
23
- export type Base = import('../Base/index.js').default;
18
+ }>, nameOrSelectorOrElement: string | HTMLElement | HTMLElement[], events: string | string[], parent: Base): Promise<T>;
@@ -16,13 +16,13 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // packages/js-toolkit/helpers/importWhenIdle.js
19
+ // packages/js-toolkit/helpers/importWhenIdle.ts
20
20
  var importWhenIdle_exports = {};
21
21
  __export(importWhenIdle_exports, {
22
22
  default: () => importWhenIdle
23
23
  });
24
24
  module.exports = __toCommonJS(importWhenIdle_exports);
25
- function importWhenIdle(fn, options) {
25
+ function importWhenIdle(fn, { timeout = 1 } = {}) {
26
26
  let ResolvedClass;
27
27
  const resolver = (resolve) => {
28
28
  fn().then((module2) => {
@@ -31,8 +31,6 @@ function importWhenIdle(fn, options) {
31
31
  });
32
32
  };
33
33
  return new Promise((resolve) => {
34
- var _a;
35
- const timeout = (_a = options == null ? void 0 : options.timeout) != null ? _a : 1;
36
34
  if (!("requestIdleCallback" in window)) {
37
35
  setTimeout(() => {
38
36
  resolver(resolve);
@@ -44,7 +42,7 @@ function importWhenIdle(fn, options) {
44
42
  resolver(resolve);
45
43
  }, 0);
46
44
  },
47
- { timeout: options == null ? void 0 : options.timeout }
45
+ { timeout }
48
46
  );
49
47
  }
50
48
  });
@@ -1,7 +1,7 @@
1
- /**
2
- * @typedef {import('../Base/index.js').BaseConstructor} BaseConstructor
3
- * @typedef {{ timeout?: number }} ImportWhenIdleOptions
4
- */
1
+ import type { BaseConstructor } from '../Base/index.js';
2
+ declare type ImportWhenIdleOptions = {
3
+ timeout?: number;
4
+ };
5
5
  /**
6
6
  * Import a component when user is idle.
7
7
  *
@@ -12,10 +12,7 @@
12
12
  * The time to wait before triggering the callback if never idle.
13
13
  * @returns {Promise<T>}
14
14
  */
15
- export default function importWhenIdle<T extends typeof import("../Base/index.js").default>(fn: () => Promise<T | {
15
+ export default function importWhenIdle<T extends BaseConstructor = BaseConstructor>(fn: () => Promise<T | {
16
16
  default: T;
17
- }>, options?: ImportWhenIdleOptions): Promise<T>;
18
- export type BaseConstructor = import('../Base/index.js').BaseConstructor;
19
- export type ImportWhenIdleOptions = {
20
- timeout?: number;
21
- };
17
+ }>, { timeout }?: ImportWhenIdleOptions): Promise<T>;
18
+ export {};
@@ -1,4 +1,4 @@
1
- function importWhenIdle(fn, options) {
1
+ function importWhenIdle(fn, { timeout = 1 } = {}) {
2
2
  let ResolvedClass;
3
3
  const resolver = (resolve) => {
4
4
  fn().then((module) => {
@@ -7,8 +7,6 @@ function importWhenIdle(fn, options) {
7
7
  });
8
8
  };
9
9
  return new Promise((resolve) => {
10
- var _a;
11
- const timeout = (_a = options == null ? void 0 : options.timeout) != null ? _a : 1;
12
10
  if (!("requestIdleCallback" in window)) {
13
11
  setTimeout(() => {
14
12
  resolver(resolve);
@@ -20,7 +18,7 @@ function importWhenIdle(fn, options) {
20
18
  resolver(resolve);
21
19
  }, 0);
22
20
  },
23
- { timeout: options == null ? void 0 : options.timeout }
21
+ { timeout }
24
22
  );
25
23
  }
26
24
  });
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // packages/js-toolkit/helpers/importWhenVisible.js
19
+ // packages/js-toolkit/helpers/importWhenVisible.ts
20
20
  var importWhenVisible_exports = {};
21
21
  __export(importWhenVisible_exports, {
22
22
  default: () => importWhenVisible
@@ -1,7 +1,4 @@
1
- /**
2
- * @typedef {import('../Base/index.js').default} Base
3
- * @typedef {import('../Base/index.js').BaseConstructor} BaseConstructor
4
- */
1
+ import type { Base, BaseConstructor } from '../Base/index.js';
5
2
  /**
6
3
  * Import a component when it is visible.
7
4
  *
@@ -16,8 +13,6 @@
16
13
  * Options for the `IntersectionObserver` instance.
17
14
  * @returns {Promise<T>}
18
15
  */
19
- export default function importWhenVisible<T extends typeof import("../Base/index.js").default>(fn: () => Promise<T | {
16
+ export default function importWhenVisible<T extends BaseConstructor = BaseConstructor>(fn: () => Promise<T | {
20
17
  default: T;
21
18
  }>, nameOrSelectorOrElement: string | HTMLElement | HTMLElement[], parent?: Base, observerOptions?: IntersectionObserverInit): Promise<T>;
22
- export type Base = import('../Base/index.js').default;
23
- export type BaseConstructor = import('../Base/index.js').BaseConstructor;
package/helpers/index.cjs CHANGED
@@ -23,7 +23,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
23
  ));
24
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
25
 
26
- // packages/js-toolkit/helpers/index.js
26
+ // packages/js-toolkit/helpers/index.ts
27
27
  var helpers_exports = {};
28
28
  __export(helpers_exports, {
29
29
  createApp: () => import_createApp.default,
@@ -1,6 +1,6 @@
1
- export { default as createApp } from "./createApp.js";
2
- export * from "./getDirectChildren.js";
3
- export { default as getInstanceFromElement } from "./getInstanceFromElement.js";
4
- export { default as importOnInteraction } from "./importOnInteraction.js";
5
- export { default as importWhenIdle } from "./importWhenIdle.js";
6
- export { default as importWhenVisible } from "./importWhenVisible.js";
1
+ export { default as createApp } from './createApp.js';
2
+ export * from './getDirectChildren.js';
3
+ export { default as getInstanceFromElement } from './getInstanceFromElement.js';
4
+ export { default as importOnInteraction } from './importOnInteraction.js';
5
+ export { default as importWhenIdle } from './importWhenIdle.js';
6
+ export { default as importWhenVisible } from './importWhenVisible.js';
package/helpers/utils.cjs CHANGED
@@ -16,7 +16,7 @@ var __copyProps = (to, from, except, desc) => {
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
 
19
- // packages/js-toolkit/helpers/utils.js
19
+ // packages/js-toolkit/helpers/utils.ts
20
20
  var utils_exports = {};
21
21
  __export(utils_exports, {
22
22
  getTargetElements: () => getTargetElements
@@ -7,4 +7,4 @@
7
7
  * The optional context to use to query for elements.
8
8
  * @returns {HTMLElement[]} A normalized list of elements.
9
9
  */
10
- export function getTargetElements(nameOrSelectorOrElement: string | HTMLElement | HTMLElement[], context?: HTMLElement): HTMLElement[];
10
+ export declare function getTargetElements(nameOrSelectorOrElement: string | HTMLElement | HTMLElement[], context: HTMLElement): HTMLElement[];
package/index.cjs CHANGED
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -17,19 +15,15 @@ var __copyProps = (to, from, except, desc) => {
17
15
  return to;
18
16
  };
19
17
  var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
- mod
23
- ));
24
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
19
 
26
20
  // packages/js-toolkit/index.ts
27
21
  var js_toolkit_exports = {};
28
22
  __export(js_toolkit_exports, {
29
- Base: () => import_Base.default
23
+ Base: () => import_Base.Base
30
24
  });
31
25
  module.exports = __toCommonJS(js_toolkit_exports);
32
- var import_Base = __toESM(require("./Base/index.cjs"), 1);
26
+ var import_Base = require("./Base/index.cjs");
33
27
  __reExport(js_toolkit_exports, require("./decorators/index.cjs"), module.exports);
34
28
  __reExport(js_toolkit_exports, require("./helpers/index.cjs"), module.exports);
35
29
  __reExport(js_toolkit_exports, require("./services/index.cjs"), module.exports);
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { default as Base } from './Base/index.js';
1
+ export { 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';
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { default as default2 } from "./Base/index.js";
1
+ import { 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
5
  export {
6
- default2 as Base
6
+ Base
7
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@studiometa/js-toolkit",
3
- "version": "2.4.4-alpha.3",
3
+ "version": "2.4.4-alpha.4",
4
4
  "description": "A set of useful little bits of JavaScript to boost your project! 🚀",
5
5
  "publishConfig": {
6
6
  "access": "public"