@studiometa/js-toolkit 3.1.1 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Base/Base.d.ts +14 -12
- package/Base/Base.js +17 -16
- package/Base/Base.js.map +2 -2
- package/Base/managers/AbstractManager.d.ts +1 -1
- package/Base/managers/ChildrenManager.d.ts +2 -2
- package/Base/managers/ChildrenManager.js +4 -4
- package/Base/managers/ChildrenManager.js.map +2 -2
- package/Base/managers/EventsManager.d.ts +10 -10
- package/Base/managers/EventsManager.js +10 -10
- package/Base/managers/EventsManager.js.map +1 -1
- package/Base/managers/ResponsiveOptionsManager.d.ts +6 -6
- package/Base/managers/ResponsiveOptionsManager.js +6 -6
- package/Base/managers/ResponsiveOptionsManager.js.map +1 -1
- package/Base/managers/ServicesManager.d.ts +2 -2
- package/Base/managers/ServicesManager.js +2 -2
- package/Base/managers/ServicesManager.js.map +1 -1
- package/Base/utils.d.ts +3 -2
- package/Base/utils.js +7 -5
- package/Base/utils.js.map +2 -2
- package/decorators/index.d.ts +1 -0
- package/decorators/index.js +1 -0
- package/decorators/index.js.map +2 -2
- package/decorators/withBreakpointManager.d.ts +2 -1
- package/decorators/withBreakpointManager.js.map +2 -2
- package/decorators/withBreakpointObserver.d.ts +2 -1
- package/decorators/withBreakpointObserver.js.map +2 -2
- package/decorators/withDrag.d.ts +2 -1
- package/decorators/withDrag.js.map +2 -2
- package/decorators/withExtraConfig.d.ts +2 -1
- package/decorators/withExtraConfig.js.map +2 -2
- package/decorators/withFreezedOptions.d.ts +2 -1
- package/decorators/withFreezedOptions.js.map +2 -2
- package/decorators/withGroup.d.ts +16 -0
- package/decorators/withGroup.js +39 -0
- package/decorators/withGroup.js.map +7 -0
- package/decorators/withIntersectionObserver.d.ts +2 -1
- package/decorators/withIntersectionObserver.js.map +2 -2
- package/decorators/withMountOnMediaQuery.d.ts +2 -1
- package/decorators/withMountOnMediaQuery.js.map +2 -2
- package/decorators/withMountWhenInView.d.ts +2 -1
- package/decorators/withMountWhenInView.js.map +2 -2
- package/decorators/withMountWhenPrefersMotion.d.ts +3 -0
- package/decorators/withMountWhenPrefersMotion.js.map +2 -2
- package/decorators/withMutation.d.ts +2 -1
- package/decorators/withMutation.js.map +2 -2
- package/decorators/withRelativePointer.d.ts +2 -1
- package/decorators/withRelativePointer.js.map +2 -2
- package/decorators/withResponsiveOptions.d.ts +2 -1
- package/decorators/withResponsiveOptions.js.map +2 -2
- package/decorators/withScrolledInView/withScrolledInView.d.ts +2 -1
- package/decorators/withScrolledInView/withScrolledInView.js.map +2 -2
- package/helpers/createApp.d.ts +2 -1
- package/helpers/createApp.js.map +2 -2
- package/helpers/getClosestParent.d.ts +2 -1
- package/helpers/getClosestParent.js.map +2 -2
- package/helpers/getDirectChildren.d.ts +13 -11
- package/helpers/getDirectChildren.js.map +2 -2
- package/helpers/getInstanceFromElement.d.ts +2 -1
- package/helpers/getInstanceFromElement.js +2 -2
- package/helpers/getInstanceFromElement.js.map +2 -2
- package/helpers/importOnInteraction.d.ts +3 -2
- package/helpers/importOnInteraction.js.map +2 -2
- package/helpers/importOnMediaQuery.d.ts +3 -2
- package/helpers/importOnMediaQuery.js.map +2 -2
- package/helpers/importWhenIdle.d.ts +3 -2
- package/helpers/importWhenIdle.js.map +2 -2
- package/helpers/importWhenPrefersMotion.d.ts +3 -2
- package/helpers/importWhenPrefersMotion.js.map +2 -2
- package/helpers/importWhenVisible.d.ts +3 -2
- package/helpers/importWhenVisible.js.map +2 -2
- package/helpers/index.d.ts +1 -0
- package/helpers/index.js +1 -0
- package/helpers/index.js.map +2 -2
- package/helpers/registerComponent.d.ts +10 -0
- package/helpers/registerComponent.js +11 -0
- package/helpers/registerComponent.js.map +7 -0
- package/helpers/utils.d.ts +1 -1
- package/helpers/utils.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +4 -0
- package/index.js.map +2 -2
- package/package.json +1 -1
- package/services/AbstractService.d.ts +1 -1
- package/services/AbstractService.js.map +1 -1
- package/services/DragService.d.ts +3 -2
- package/services/DragService.js +5 -1
- package/services/DragService.js.map +2 -2
- package/services/KeyService.d.ts +2 -1
- package/services/KeyService.js.map +2 -2
- package/services/LoadService.d.ts +2 -1
- package/services/LoadService.js.map +2 -2
- package/services/MutationService.d.ts +2 -1
- package/services/MutationService.js.map +2 -2
- package/services/PointerService.d.ts +2 -1
- package/services/PointerService.js.map +2 -2
- package/services/RafService.d.ts +2 -1
- package/services/RafService.js.map +2 -2
- package/services/ResizeService.d.ts +2 -1
- package/services/ResizeService.js.map +2 -2
- package/services/ScrollService.d.ts +2 -1
- package/services/ScrollService.js.map +2 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/utils/SmartQueue.js.map +1 -1
- package/utils/cache.d.ts +2 -1
- package/utils/cache.js.map +2 -2
- package/utils/collide/boundingRectToCircle.d.ts +3 -2
- package/utils/collide/boundingRectToCircle.js.map +2 -2
- package/utils/collide/collideCircleCircle.d.ts +3 -2
- package/utils/collide/collideCircleCircle.js.map +2 -2
- package/utils/collide/collideCircleRect.d.ts +3 -2
- package/utils/collide/collideCircleRect.js.map +2 -2
- package/utils/collide/collidePointCircle.d.ts +3 -2
- package/utils/collide/collidePointCircle.js.map +2 -2
- package/utils/collide/collidePointRect.d.ts +3 -2
- package/utils/collide/collidePointRect.js.map +2 -2
- package/utils/collide/collideRectRect.d.ts +3 -2
- package/utils/collide/collideRectRect.js.map +2 -2
- package/utils/css/animate.d.ts +2 -1
- package/utils/css/animate.js.map +2 -2
- package/utils/css/classes.d.ts +6 -3
- package/utils/css/classes.js.map +2 -2
- package/utils/css/getOffsetSizes.d.ts +2 -1
- package/utils/css/getOffsetSizes.js.map +2 -2
- package/utils/css/matrix.d.ts +10 -9
- package/utils/css/matrix.js.map +2 -2
- package/utils/css/styles.d.ts +4 -2
- package/utils/css/styles.js.map +2 -2
- package/utils/css/transform.d.ts +2 -1
- package/utils/css/transform.js.map +2 -2
- package/utils/css/transition.d.ts +3 -2
- package/utils/css/transition.js +1 -1
- package/utils/css/transition.js.map +2 -2
- package/utils/debounce.d.ts +5 -4
- package/utils/debounce.js.map +2 -2
- package/utils/dom/createElement.d.ts +24 -1
- package/utils/dom/createElement.js +8 -2
- package/utils/dom/createElement.js.map +2 -2
- package/utils/getComponentResolver.d.ts +1 -1
- package/utils/getComponentResolver.js.map +1 -1
- package/utils/history.d.ts +17 -14
- package/utils/history.js.map +2 -2
- package/utils/is.d.ts +25 -9
- package/utils/is.js.map +2 -2
- package/utils/keyCodes.d.ts +3 -0
- package/utils/keyCodes.js.map +2 -2
- package/utils/loadElement.d.ts +10 -5
- package/utils/loadElement.js.map +2 -2
- package/utils/math/clamp.d.ts +2 -6
- package/utils/math/clamp.js.map +2 -2
- package/utils/math/clamp01.d.ts +2 -4
- package/utils/math/clamp01.js.map +2 -2
- package/utils/math/createEases.d.ts +13 -5
- package/utils/math/createEases.js.map +2 -2
- package/utils/math/createRange.d.ts +2 -1
- package/utils/math/createRange.js.map +2 -2
- package/utils/math/damp.d.ts +7 -6
- package/utils/math/damp.js.map +2 -2
- package/utils/math/ease.d.ts +23 -14
- package/utils/math/ease.js.map +2 -2
- package/utils/math/inertiaFinalValue.d.ts +6 -5
- package/utils/math/inertiaFinalValue.js.map +2 -2
- package/utils/math/lerp.d.ts +6 -5
- package/utils/math/lerp.js.map +2 -2
- package/utils/math/map.d.ts +3 -2
- package/utils/math/map.js.map +2 -2
- package/utils/math/mean.d.ts +3 -0
- package/utils/math/mean.js.map +2 -2
- package/utils/math/round.d.ts +5 -4
- package/utils/math/round.js.map +2 -2
- package/utils/math/smoothTo.d.ts +1 -1
- package/utils/math/smoothTo.js.map +1 -1
- package/utils/math/spring.d.ts +9 -9
- package/utils/math/spring.js.map +1 -1
- package/utils/math/wrap.d.ts +2 -1
- package/utils/math/wrap.js.map +2 -2
- package/utils/memo.d.ts +2 -1
- package/utils/memo.js.map +2 -2
- package/utils/memoize.d.ts +2 -1
- package/utils/memoize.js.map +2 -2
- package/utils/nextFrame.d.ts +2 -1
- package/utils/nextFrame.js.map +2 -2
- package/utils/nextMicrotask.d.ts +2 -1
- package/utils/nextMicrotask.js.map +2 -2
- package/utils/nextTick.d.ts +2 -1
- package/utils/nextTick.js.map +2 -2
- package/utils/noop.d.ts +1 -1
- package/utils/noop.js.map +1 -1
- package/utils/object/getAllProperties.d.ts +1 -1
- package/utils/object/getAllProperties.js.map +1 -1
- package/utils/random.d.ts +11 -8
- package/utils/random.js.map +2 -2
- package/utils/scheduler.d.ts +6 -1
- package/utils/scheduler.js.map +2 -2
- package/utils/scrollTo.d.ts +3 -2
- package/utils/scrollTo.js.map +2 -2
- package/utils/string/changeCase.d.ts +12 -6
- package/utils/string/changeCase.js.map +2 -2
- package/utils/string/endsWith.d.ts +2 -1
- package/utils/string/endsWith.js.map +2 -2
- package/utils/string/startsWith.d.ts +2 -1
- package/utils/string/startsWith.js.map +2 -2
- package/utils/string/withLeadingCharacters.d.ts +5 -4
- package/utils/string/withLeadingCharacters.js.map +2 -2
- package/utils/string/withLeadingSlash.d.ts +3 -2
- package/utils/string/withLeadingSlash.js.map +2 -2
- package/utils/string/withTrailingCharacters.d.ts +5 -4
- package/utils/string/withTrailingCharacters.js.map +2 -2
- package/utils/string/withTrailingSlash.d.ts +3 -2
- package/utils/string/withTrailingSlash.js.map +2 -2
- package/utils/string/withoutLeadingCharacters.d.ts +5 -4
- package/utils/string/withoutLeadingCharacters.js.map +2 -2
- package/utils/string/withoutLeadingCharactersRecursive.d.ts +5 -4
- package/utils/string/withoutLeadingCharactersRecursive.js.map +2 -2
- package/utils/string/withoutLeadingSlash.d.ts +3 -2
- package/utils/string/withoutLeadingSlash.js.map +2 -2
- package/utils/string/withoutTrailingCharacters.d.ts +5 -4
- package/utils/string/withoutTrailingCharacters.js.map +2 -2
- package/utils/string/withoutTrailingCharactersRecursive.d.ts +5 -4
- package/utils/string/withoutTrailingCharactersRecursive.js.map +2 -2
- package/utils/string/withoutTrailingSlash.d.ts +3 -2
- package/utils/string/withoutTrailingSlash.js.map +2 -2
- package/utils/throttle.d.ts +3 -2
- package/utils/throttle.js.map +2 -2
- package/utils/trapFocus.d.ts +4 -2
- package/utils/trapFocus.js.map +2 -2
- package/utils/tween.d.ts +1 -1
- package/utils/tween.js.map +1 -1
|
@@ -10,9 +10,9 @@ export declare class ResponsiveOptionsManager<T> extends OptionsManager<T> {
|
|
|
10
10
|
/**
|
|
11
11
|
* Get an option value.
|
|
12
12
|
*
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* @
|
|
13
|
+
* @param {string} name The option name.
|
|
14
|
+
* @param {ResponsiveOptionObject} config The option configuration.
|
|
15
|
+
* @return {any}
|
|
16
16
|
*/
|
|
17
17
|
get(name: string, config: ResponsiveOptionObject): any;
|
|
18
18
|
/**
|
|
@@ -26,9 +26,9 @@ export declare class ResponsiveOptionsManager<T> extends OptionsManager<T> {
|
|
|
26
26
|
/**
|
|
27
27
|
* Get the currently active responsive name of an option.
|
|
28
28
|
*
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
31
|
-
* @
|
|
29
|
+
* @param {ResponsiveOptionsManager} that
|
|
30
|
+
* @param {string} name The default name of the option.
|
|
31
|
+
* @return {string} The responsive name if one matches the current breakpoint, the default name otherwise.
|
|
32
32
|
*/
|
|
33
33
|
__getResponsiveName(name: string): string;
|
|
34
34
|
}
|
|
@@ -6,9 +6,9 @@ class ResponsiveOptionsManager extends OptionsManager {
|
|
|
6
6
|
/**
|
|
7
7
|
* Get an option value.
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
10
|
-
* @param
|
|
11
|
-
* @
|
|
9
|
+
* @param {string} name The option name.
|
|
10
|
+
* @param {ResponsiveOptionObject} config The option configuration.
|
|
11
|
+
* @return {any}
|
|
12
12
|
*/
|
|
13
13
|
get(name, config) {
|
|
14
14
|
if (!config.responsive) {
|
|
@@ -35,9 +35,9 @@ class ResponsiveOptionsManager extends OptionsManager {
|
|
|
35
35
|
/**
|
|
36
36
|
* Get the currently active responsive name of an option.
|
|
37
37
|
*
|
|
38
|
-
* @param
|
|
39
|
-
* @param
|
|
40
|
-
* @
|
|
38
|
+
* @param {ResponsiveOptionsManager} that
|
|
39
|
+
* @param {string} name The default name of the option.
|
|
40
|
+
* @return {string} The responsive name if one matches the current breakpoint, the default name otherwise.
|
|
41
41
|
*/
|
|
42
42
|
__getResponsiveName(name) {
|
|
43
43
|
const { breakpoint } = useResize().props();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/js-toolkit/Base/managers/ResponsiveOptionsManager.ts"],
|
|
4
|
-
"sourcesContent": ["import { OptionsManager, __getPropertyName } from './OptionsManager.js';\nimport type { OptionObject } from './OptionsManager.js';\nimport { useResize } from '../../services/index.js';\nimport { isDev } from '../../utils/index.js';\nimport { features } from '../features.js';\n\nexport type ResponsiveOptionObject = OptionObject & { responsive?: boolean };\n\n/**\n * Class options to manage options as data attributes on an HTML element.\n */\nexport class ResponsiveOptionsManager<T> extends OptionsManager<T> {\n /**\n * Get an option value.\n *\n * @param
|
|
4
|
+
"sourcesContent": ["import { OptionsManager, __getPropertyName } from './OptionsManager.js';\nimport type { OptionObject } from './OptionsManager.js';\nimport { useResize } from '../../services/index.js';\nimport { isDev } from '../../utils/index.js';\nimport { features } from '../features.js';\n\nexport type ResponsiveOptionObject = OptionObject & { responsive?: boolean };\n\n/**\n * Class options to manage options as data attributes on an HTML element.\n */\nexport class ResponsiveOptionsManager<T> extends OptionsManager<T> {\n /**\n * Get an option value.\n *\n * @param {string} name The option name.\n * @param {ResponsiveOptionObject} config The option configuration.\n * @return {any}\n */\n get(name: string, config: ResponsiveOptionObject) {\n if (!config.responsive) {\n return super.get(name, config);\n }\n\n return super.get(this.__getResponsiveName(name), config);\n }\n\n /**\n * Set an option value.\n *\n * @param {string} name The option name.\n * @param {any} value The new value.\n * @param {ResponsiveOptionObject} config The option configuration.\n */\n set(name: string, value: unknown, config: ResponsiveOptionObject) {\n if (!config.responsive) {\n super.set(name, value, config);\n return;\n }\n\n if (isDev) {\n console.warn(`[${this.__base.$id}]`, 'Responsive options are read-only.');\n }\n }\n\n /**\n * Get the currently active responsive name of an option.\n *\n * @param {ResponsiveOptionsManager} that\n * @param {string} name The default name of the option.\n * @return {string} The responsive name if one matches the current breakpoint, the default name otherwise.\n */\n __getResponsiveName(name: string) {\n const { breakpoint } = useResize().props();\n\n if (!breakpoint) {\n return name;\n }\n\n let responsiveName = name;\n const propertyName = __getPropertyName(name).toLowerCase();\n const regex = new RegExp(`${propertyName}:(.+)$`, 'i');\n const attributes = features.get('attributes');\n const dataOptionRegExp = new RegExp(`^${attributes.option}-`);\n\n for (const optionName of this.__element.getAttributeNames()) {\n if (regex.test(optionName)) {\n const [, breakpoints] = optionName.match(regex);\n const isInBreakpoint = breakpoints.split(':').includes(breakpoint);\n if (isInBreakpoint) {\n responsiveName = optionName.replace(dataOptionRegExp, '');\n }\n }\n }\n\n return responsiveName;\n }\n}\n"],
|
|
5
5
|
"mappings": "AAAA,SAAS,gBAAgB,yBAAyB;AAElD,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AACtB,SAAS,gBAAgB;AAOlB,MAAM,iCAAoC,eAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQjE,IAAI,MAAc,QAAgC;AAChD,QAAI,CAAC,OAAO,YAAY;AACtB,aAAO,MAAM,IAAI,MAAM,MAAM;AAAA,IAC/B;AAEA,WAAO,MAAM,IAAI,KAAK,oBAAoB,IAAI,GAAG,MAAM;AAAA,EACzD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,IAAI,MAAc,OAAgB,QAAgC;AAChE,QAAI,CAAC,OAAO,YAAY;AACtB,YAAM,IAAI,MAAM,OAAO,MAAM;AAC7B;AAAA,IACF;AAEA,QAAI,OAAO;AACT,cAAQ,KAAK,IAAI,KAAK,OAAO,GAAG,KAAK,mCAAmC;AAAA,IAC1E;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,oBAAoB,MAAc;AAChC,UAAM,EAAE,WAAW,IAAI,UAAU,EAAE,MAAM;AAEzC,QAAI,CAAC,YAAY;AACf,aAAO;AAAA,IACT;AAEA,QAAI,iBAAiB;AACrB,UAAM,eAAe,kBAAkB,IAAI,EAAE,YAAY;AACzD,UAAM,QAAQ,IAAI,OAAO,GAAG,YAAY,UAAU,GAAG;AACrD,UAAM,aAAa,SAAS,IAAI,YAAY;AAC5C,UAAM,mBAAmB,IAAI,OAAO,IAAI,WAAW,MAAM,GAAG;AAE5D,eAAW,cAAc,KAAK,UAAU,kBAAkB,GAAG;AAC3D,UAAI,MAAM,KAAK,UAAU,GAAG;AAC1B,cAAM,CAAC,EAAE,WAAW,IAAI,WAAW,MAAM,KAAK;AAC9C,cAAM,iBAAiB,YAAY,MAAM,GAAG,EAAE,SAAS,UAAU;AACjE,YAAI,gBAAgB;AAClB,2BAAiB,WAAW,QAAQ,kBAAkB,EAAE;AAAA,QAC1D;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -40,7 +40,7 @@ export declare class ServicesManager extends AbstractManager<ServiceProps> {
|
|
|
40
40
|
* Init the given service and bind it to the given instance.
|
|
41
41
|
*
|
|
42
42
|
* @param {ServiceNames} service The name of the service.
|
|
43
|
-
* @
|
|
43
|
+
* @return {() => void} A function to unbind the service.
|
|
44
44
|
*/
|
|
45
45
|
enable(service: ServiceNames): () => void;
|
|
46
46
|
/**
|
|
@@ -50,7 +50,7 @@ export declare class ServicesManager extends AbstractManager<ServiceProps> {
|
|
|
50
50
|
/**
|
|
51
51
|
* Disable all services.
|
|
52
52
|
*
|
|
53
|
-
* @
|
|
53
|
+
* @return {void}
|
|
54
54
|
*/
|
|
55
55
|
disableAll(): void;
|
|
56
56
|
/**
|
|
@@ -38,7 +38,7 @@ class ServicesManager extends AbstractManager {
|
|
|
38
38
|
* Init the given service and bind it to the given instance.
|
|
39
39
|
*
|
|
40
40
|
* @param {ServiceNames} service The name of the service.
|
|
41
|
-
* @
|
|
41
|
+
* @return {() => void} A function to unbind the service.
|
|
42
42
|
*/
|
|
43
43
|
enable(service) {
|
|
44
44
|
if (this.has(service)) {
|
|
@@ -63,7 +63,7 @@ class ServicesManager extends AbstractManager {
|
|
|
63
63
|
/**
|
|
64
64
|
* Disable all services.
|
|
65
65
|
*
|
|
66
|
-
* @
|
|
66
|
+
* @return {void}
|
|
67
67
|
*/
|
|
68
68
|
disableAll() {
|
|
69
69
|
for (const serviceName of Object.keys(this.props)) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/js-toolkit/Base/managers/ServicesManager.ts"],
|
|
4
|
-
"sourcesContent": ["import { usePointer, useRaf, useResize, useScroll, useKey } from '../../services/index.js';\nimport type {\n PointerServiceInterface,\n RafServiceInterface,\n ResizeServiceInterface,\n ScrollServiceInterface,\n KeyServiceInterface,\n ServiceInterface,\n} from '../../services/index.js';\nimport { AbstractManager } from './AbstractManager.js';\nimport { noop, isFunction, isDefined, isDev } from '../../utils/index.js';\n\nconst SERVICES_MAP = {\n scrolled: useScroll,\n resized: useResize,\n ticked: useRaf,\n moved: usePointer,\n keyed: useKey,\n};\n\nconst SERVICE_NAMES = Object.keys(SERVICES_MAP);\n\ntype Services = {\n scrolled: ScrollServiceInterface;\n resized: ResizeServiceInterface;\n ticked: RafServiceInterface;\n moved: PointerServiceInterface;\n keyed: KeyServiceInterface;\n} & Record<string, ServiceInterface<unknown>>;\n\ntype ServiceProps = typeof SERVICES_MAP & Record<string, <T>() => ServiceInterface<T>>;\n\ntype ServiceNames = keyof Services;\n\n/**\n * Services management for the Base class.\n *\n * @todo Add support for disabled services on mount when the method is defined.\n */\nexport class ServicesManager extends AbstractManager<ServiceProps> {\n /**\n * Custom props\n * @private\n */\n __props = {\n ...SERVICES_MAP,\n } as ServiceProps;\n\n /**\n * Test if the given service is registered.\n */\n has(service: ServiceNames | string): boolean {\n if (\n !(\n (isFunction(this.__base[service]) ||\n // @ts-ignore\n this.__base.__hasEvent(service)) &&\n this.props[service]\n )\n ) {\n return false;\n }\n\n const { has } = this.props[service]();\n return has(this.__base.$id);\n }\n\n /**\n * Get a service props by name.\n */\n get<S extends ServiceNames | string>(service: S): ReturnType<Services[S]['props']> {\n // @ts-ignore\n return this.props[service]().props();\n }\n\n /**\n * Init the given service and bind it to the given instance.\n *\n * @param {ServiceNames} service The name of the service.\n * @
|
|
4
|
+
"sourcesContent": ["import { usePointer, useRaf, useResize, useScroll, useKey } from '../../services/index.js';\nimport type {\n PointerServiceInterface,\n RafServiceInterface,\n ResizeServiceInterface,\n ScrollServiceInterface,\n KeyServiceInterface,\n ServiceInterface,\n} from '../../services/index.js';\nimport { AbstractManager } from './AbstractManager.js';\nimport { noop, isFunction, isDefined, isDev } from '../../utils/index.js';\n\nconst SERVICES_MAP = {\n scrolled: useScroll,\n resized: useResize,\n ticked: useRaf,\n moved: usePointer,\n keyed: useKey,\n};\n\nconst SERVICE_NAMES = Object.keys(SERVICES_MAP);\n\ntype Services = {\n scrolled: ScrollServiceInterface;\n resized: ResizeServiceInterface;\n ticked: RafServiceInterface;\n moved: PointerServiceInterface;\n keyed: KeyServiceInterface;\n} & Record<string, ServiceInterface<unknown>>;\n\ntype ServiceProps = typeof SERVICES_MAP & Record<string, <T>() => ServiceInterface<T>>;\n\ntype ServiceNames = keyof Services;\n\n/**\n * Services management for the Base class.\n *\n * @todo Add support for disabled services on mount when the method is defined.\n */\nexport class ServicesManager extends AbstractManager<ServiceProps> {\n /**\n * Custom props\n * @private\n */\n __props = {\n ...SERVICES_MAP,\n } as ServiceProps;\n\n /**\n * Test if the given service is registered.\n */\n has(service: ServiceNames | string): boolean {\n if (\n !(\n (isFunction(this.__base[service]) ||\n // @ts-ignore\n this.__base.__hasEvent(service)) &&\n this.props[service]\n )\n ) {\n return false;\n }\n\n const { has } = this.props[service]();\n return has(this.__base.$id);\n }\n\n /**\n * Get a service props by name.\n */\n get<S extends ServiceNames | string>(service: S): ReturnType<Services[S]['props']> {\n // @ts-ignore\n return this.props[service]().props();\n }\n\n /**\n * Init the given service and bind it to the given instance.\n *\n * @param {ServiceNames} service The name of the service.\n * @return {() => void} A function to unbind the service.\n */\n enable(service: ServiceNames): () => void {\n if (this.has(service)) {\n return this.disable.bind(this, service);\n }\n\n if (\n // @ts-ignore\n !(isFunction(this.__base[service]) || this.__base.__hasEvent(service)) ||\n !this.props[service]\n ) {\n return noop;\n }\n const serviceInstance = this.props[service]();\n\n serviceInstance.add(this.__base.$id, (...args) => this.__base.__callMethod(service, ...args));\n\n return this.disable.bind(this, service);\n }\n\n /**\n * Enable all services and return methods to disable them.\n */\n enableAll() {\n return Object.keys(this.props).map((serviceName) => this.enable(serviceName));\n }\n\n /**\n * Disable all services.\n *\n * @return {void}\n */\n disableAll() {\n for (const serviceName of Object.keys(this.props)) {\n this.disable(serviceName);\n }\n }\n\n /**\n * Disable a service.\n */\n disable(service: ServiceNames) {\n if (!this.props[service]) {\n return;\n }\n\n const { remove } = this.props[service]();\n remove(this.__base.$id);\n }\n\n /**\n * Toggle a service.\n */\n toggle(service: ServiceNames, force?: boolean) {\n if (isDefined(force)) {\n if (force && !this.has(service)) {\n this.enable(service);\n }\n\n if (!force && this.has(service)) {\n this.disable(service);\n }\n } else if (this.has(service)) {\n this.disable(service);\n } else {\n this.enable(service);\n }\n }\n\n /**\n * Register a new service to be enabled/disabled.\n *\n * @param {string} name\n * The name of the service hook.\n * @param {<T>(...args:unknown[]) => ServiceInterface<T>} useFunction\n * The `use...` function for the service.\n */\n register(name: string, useFunction: <T>(...args: unknown[]) => ServiceInterface<T>) {\n this.props[name] = useFunction;\n this.__base.__addEmits(name);\n }\n\n /**\n * Unregister a new service to be enabled disabled.\n *\n * @param {string} name\n * The name of the service hook.\n */\n unregister(name: string) {\n if (SERVICE_NAMES.includes(name)) {\n if (isDev) {\n throw new Error(`[ServicesManager] The \\`${name}\\` core service can not be unregistered.`);\n }\n return;\n }\n\n this.__base.__removeEmits(name);\n delete this.props[name];\n }\n}\n"],
|
|
5
5
|
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/Base/utils.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare function getSelector(nameOrSelector: string): string;
|
|
|
14
14
|
* The name or selector to used for this component.
|
|
15
15
|
* @param {HTMLElement|Document} element
|
|
16
16
|
* The root element on which to query the selector, defaults to `document`.
|
|
17
|
-
* @
|
|
17
|
+
* @return {Array<HTMLElement>}
|
|
18
18
|
* A list of elements on which the component should be mounted.
|
|
19
19
|
*/
|
|
20
20
|
export declare function getComponentElements(nameOrSelector: string, element?: HTMLElement | Document): HTMLElement[];
|
|
@@ -32,7 +32,8 @@ export declare function eventIsNative(event: string, element: HTMLElement): bool
|
|
|
32
32
|
export declare function getEventTarget(instance: Base, event: string, config: BaseConfig): Base['$el'];
|
|
33
33
|
/**
|
|
34
34
|
* Get all mounted instances or the ones from a given component.
|
|
35
|
-
|
|
35
|
+
* @link https://js-toolkit.studiometa.dev/api/helpers/getInstances.html
|
|
36
|
+
*/
|
|
36
37
|
export declare function getInstances(): Set<Base>;
|
|
37
38
|
export declare function getInstances<T extends BaseConstructor = BaseConstructor>(ctor: T): Set<InstanceType<T>>;
|
|
38
39
|
export declare function addInstance(instance: Base): void;
|
package/Base/utils.js
CHANGED
|
@@ -57,25 +57,27 @@ function getEventTarget(instance, event, config) {
|
|
|
57
57
|
return instance.$el;
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
|
|
60
|
+
function getInstancesStorage() {
|
|
61
|
+
return globalThis.__js_toolkit_instances__ ??= /* @__PURE__ */ new Set();
|
|
62
|
+
}
|
|
61
63
|
function getInstances(ctor) {
|
|
62
64
|
if (isDefined(ctor)) {
|
|
63
65
|
const filteredInstances = /* @__PURE__ */ new Set();
|
|
64
|
-
for (const instance of
|
|
66
|
+
for (const instance of getInstancesStorage()) {
|
|
65
67
|
if (instance instanceof ctor) {
|
|
66
68
|
filteredInstances.add(instance);
|
|
67
69
|
}
|
|
68
70
|
}
|
|
69
71
|
return filteredInstances;
|
|
70
72
|
} else {
|
|
71
|
-
return new Set(
|
|
73
|
+
return new Set(getInstancesStorage());
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
function addInstance(instance) {
|
|
75
|
-
|
|
77
|
+
getInstancesStorage().add(instance);
|
|
76
78
|
}
|
|
77
79
|
function deleteInstance(instance) {
|
|
78
|
-
|
|
80
|
+
getInstancesStorage().delete(instance);
|
|
79
81
|
}
|
|
80
82
|
export {
|
|
81
83
|
addInstance,
|
package/Base/utils.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/Base/utils.ts"],
|
|
4
|
-
"sourcesContent": ["import { isArray, isDefined, SmartQueue, dashCase } from '../utils/index.js';\nimport type { Base, BaseConfig, BaseConstructor } from './index.js';\nimport { features } from './features.js';\n\nlet queue: SmartQueue;\n\n/**\n * Add a task to the main queue.\n */\nexport function addToQueue(fn: () => unknown) {\n if (features.get('blocking')) {\n fn();\n return;\n }\n\n if (!queue) {\n queue = new SmartQueue();\n }\n\n return queue.add(fn);\n}\n\nconst selectors = new Map();\n\n// Separator used for multi-component declaration in `data-component` attributeS.\nconst separator = ' ';\n\n/**\n * Get the selector for a given component.\n */\nexport function getSelector(nameOrSelector: string): string {\n const { component } = features.get('attributes');\n const prefix = features.get('prefix');\n const key = prefix + component + nameOrSelector;\n\n if (!selectors.has(key)) {\n const parts = [\n // Tag select\n `${prefix}-${dashCase(nameOrSelector)}`,\n // Single selector\n `[${component}=\"${nameOrSelector}\"]`,\n // Selector in the middle of a list of selectors\n `[${component}*=\"${separator}${nameOrSelector}${separator}\"]`,\n // Selector at the end of a list of selectors\n `[${component}$=\"${separator}${nameOrSelector}\"]`,\n // Selector at the beginning of a list of selectors\n `[${component}^=\"${nameOrSelector}${separator}\"]`,\n ];\n selectors.set(key, parts.join(','));\n }\n\n return selectors.get(key);\n}\n\n/**\n * Get a list of elements based on the name of a component.\n *\n * @param {string} nameOrSelector\n * The name or selector to used for this component.\n * @param {HTMLElement|Document} element\n * The root element on which to query the selector, defaults to `document`.\n * @
|
|
5
|
-
"mappings": "AAAA,SAAS,SAAS,WAAW,YAAY,gBAAgB;AAEzD,SAAS,gBAAgB;AAEzB,IAAI;AAKG,SAAS,WAAW,IAAmB;AAC5C,MAAI,SAAS,IAAI,UAAU,GAAG;AAC5B,OAAG;AACH;AAAA,EACF;AAEA,MAAI,CAAC,OAAO;AACV,YAAQ,IAAI,WAAW;AAAA,EACzB;AAEA,SAAO,MAAM,IAAI,EAAE;AACrB;AAEA,MAAM,YAAY,oBAAI,IAAI;AAG1B,MAAM,YAAY;AAKX,SAAS,YAAY,gBAAgC;AAC1D,QAAM,EAAE,UAAU,IAAI,SAAS,IAAI,YAAY;AAC/C,QAAM,SAAS,SAAS,IAAI,QAAQ;AACpC,QAAM,MAAM,SAAS,YAAY;AAEjC,MAAI,CAAC,UAAU,IAAI,GAAG,GAAG;AACvB,UAAM,QAAQ;AAAA;AAAA,MAEZ,GAAG,MAAM,IAAI,SAAS,cAAc,CAAC;AAAA;AAAA,MAErC,IAAI,SAAS,KAAK,cAAc;AAAA;AAAA,MAEhC,IAAI,SAAS,MAAM,SAAS,GAAG,cAAc,GAAG,SAAS;AAAA;AAAA,MAEzD,IAAI,SAAS,MAAM,SAAS,GAAG,cAAc;AAAA;AAAA,MAE7C,IAAI,SAAS,MAAM,cAAc,GAAG,SAAS;AAAA,IAC/C;AACA,cAAU,IAAI,KAAK,MAAM,KAAK,GAAG,CAAC;AAAA,EACpC;AAEA,SAAO,UAAU,IAAI,GAAG;AAC1B;AAYO,SAAS,qBACd,gBACA,UAAkC,UACnB;AACf,QAAM,WAAW,YAAY,cAAc;AAC3C,MAAI,WAAW,CAAC;AAEhB,MAAI;AACF,eAAW,MAAM,KAAK,QAAQ,iBAAiB,QAAQ,CAAC;AAAA,EAE1D,QAAQ;AAAA,EAAC;AAIT,MAAI,SAAS,WAAW,KAAK,eAAe,CAAC,MAAM,eAAe,CAAC,EAAE,YAAY,GAAG;AAClF,eAAW,MAAM,KAAK,QAAQ,iBAAiB,cAAc,CAAC;AAAA,EAChE;AAEA,SAAO;AACT;AAKO,SAAS,uBAAuB,OAAe,QAA6B;AACjF,SAAO,QAAQ,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,KAAK;AAC7D;AAKO,SAAS,cAAc,OAAe,SAA+B;AAC1E,SAAO,UAAU,QAAQ,KAAK,KAAK,EAAE,CAAC;AACxC;AAKO,SAAS,eAAe,UAAgB,OAAe,QAAiC;AAC7F,MAAI,uBAAuB,OAAO,MAAM,KAAK,cAAc,OAAO,SAAS,GAAG,GAAG;AAC/E,WAAO,SAAS;AAAA,EAClB;AACF;
|
|
4
|
+
"sourcesContent": ["import { isArray, isDefined, SmartQueue, dashCase } from '../utils/index.js';\nimport type { Base, BaseConfig, BaseConstructor } from './index.js';\nimport { features } from './features.js';\n\nlet queue: SmartQueue;\n\n/**\n * Add a task to the main queue.\n */\nexport function addToQueue(fn: () => unknown) {\n if (features.get('blocking')) {\n fn();\n return;\n }\n\n if (!queue) {\n queue = new SmartQueue();\n }\n\n return queue.add(fn);\n}\n\nconst selectors = new Map();\n\n// Separator used for multi-component declaration in `data-component` attributeS.\nconst separator = ' ';\n\n/**\n * Get the selector for a given component.\n */\nexport function getSelector(nameOrSelector: string): string {\n const { component } = features.get('attributes');\n const prefix = features.get('prefix');\n const key = prefix + component + nameOrSelector;\n\n if (!selectors.has(key)) {\n const parts = [\n // Tag select\n `${prefix}-${dashCase(nameOrSelector)}`,\n // Single selector\n `[${component}=\"${nameOrSelector}\"]`,\n // Selector in the middle of a list of selectors\n `[${component}*=\"${separator}${nameOrSelector}${separator}\"]`,\n // Selector at the end of a list of selectors\n `[${component}$=\"${separator}${nameOrSelector}\"]`,\n // Selector at the beginning of a list of selectors\n `[${component}^=\"${nameOrSelector}${separator}\"]`,\n ];\n selectors.set(key, parts.join(','));\n }\n\n return selectors.get(key);\n}\n\n/**\n * Get a list of elements based on the name of a component.\n *\n * @param {string} nameOrSelector\n * The name or selector to used for this component.\n * @param {HTMLElement|Document} element\n * The root element on which to query the selector, defaults to `document`.\n * @return {Array<HTMLElement>}\n * A list of elements on which the component should be mounted.\n */\nexport function getComponentElements(\n nameOrSelector: string,\n element: HTMLElement | Document = document,\n): HTMLElement[] {\n const selector = getSelector(nameOrSelector);\n let elements = [];\n\n try {\n elements = Array.from(element.querySelectorAll(selector));\n // eslint-disable-next-line no-empty\n } catch {}\n\n // If no child component found with the default selector, and if the selector does not\n // start with an uppercase letter, matching a component's name, try a classic DOM selector.\n if (elements.length === 0 && nameOrSelector[0] === nameOrSelector[0].toLowerCase()) {\n elements = Array.from(element.querySelectorAll(nameOrSelector));\n }\n\n return elements;\n}\n\n/**\n * Test if an event is defined in the given config.\n */\nexport function eventIsDefinedInConfig(event: string, config: BaseConfig): boolean {\n return isArray(config.emits) && config.emits.includes(event);\n}\n\n/**\n * Test if an event can be used on the given element.\n */\nexport function eventIsNative(event: string, element: HTMLElement): boolean {\n return isDefined(element[`on${event}`]);\n}\n\n/**\n * Get the target of a given event.\n */\nexport function getEventTarget(instance: Base, event: string, config: BaseConfig): Base['$el'] {\n if (eventIsDefinedInConfig(event, config) || eventIsNative(event, instance.$el)) {\n return instance.$el;\n }\n}\n\n/**\n * Get the global instance storage.\n * We attach it to `globalThis` so it can be shared between different\n * instances of the framework.\n */\nfunction getInstancesStorage(): Set<Base> {\n return globalThis.__js_toolkit_instances__ ??= new Set<Base>();\n}\n\n/**\n * Get all mounted instances or the ones from a given component.\n * @link https://js-toolkit.studiometa.dev/api/helpers/getInstances.html\n*/\nexport function getInstances(): Set<Base>;\nexport function getInstances<T extends BaseConstructor = BaseConstructor>(\n ctor: T,\n): Set<InstanceType<T>>;\nexport function getInstances<T extends BaseConstructor = BaseConstructor>(\n ctor?: T,\n): Set<InstanceType<T>> | Set<Base> {\n if (isDefined(ctor)) {\n const filteredInstances = new Set<InstanceType<T>>();\n for (const instance of getInstancesStorage()) {\n if (instance instanceof ctor) {\n filteredInstances.add(instance as InstanceType<T>);\n }\n }\n return filteredInstances;\n } else {\n return new Set(getInstancesStorage());\n }\n}\n\nexport function addInstance(instance: Base) {\n getInstancesStorage().add(instance);\n}\n\nexport function deleteInstance(instance: Base) {\n getInstancesStorage().delete(instance);\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,SAAS,WAAW,YAAY,gBAAgB;AAEzD,SAAS,gBAAgB;AAEzB,IAAI;AAKG,SAAS,WAAW,IAAmB;AAC5C,MAAI,SAAS,IAAI,UAAU,GAAG;AAC5B,OAAG;AACH;AAAA,EACF;AAEA,MAAI,CAAC,OAAO;AACV,YAAQ,IAAI,WAAW;AAAA,EACzB;AAEA,SAAO,MAAM,IAAI,EAAE;AACrB;AAEA,MAAM,YAAY,oBAAI,IAAI;AAG1B,MAAM,YAAY;AAKX,SAAS,YAAY,gBAAgC;AAC1D,QAAM,EAAE,UAAU,IAAI,SAAS,IAAI,YAAY;AAC/C,QAAM,SAAS,SAAS,IAAI,QAAQ;AACpC,QAAM,MAAM,SAAS,YAAY;AAEjC,MAAI,CAAC,UAAU,IAAI,GAAG,GAAG;AACvB,UAAM,QAAQ;AAAA;AAAA,MAEZ,GAAG,MAAM,IAAI,SAAS,cAAc,CAAC;AAAA;AAAA,MAErC,IAAI,SAAS,KAAK,cAAc;AAAA;AAAA,MAEhC,IAAI,SAAS,MAAM,SAAS,GAAG,cAAc,GAAG,SAAS;AAAA;AAAA,MAEzD,IAAI,SAAS,MAAM,SAAS,GAAG,cAAc;AAAA;AAAA,MAE7C,IAAI,SAAS,MAAM,cAAc,GAAG,SAAS;AAAA,IAC/C;AACA,cAAU,IAAI,KAAK,MAAM,KAAK,GAAG,CAAC;AAAA,EACpC;AAEA,SAAO,UAAU,IAAI,GAAG;AAC1B;AAYO,SAAS,qBACd,gBACA,UAAkC,UACnB;AACf,QAAM,WAAW,YAAY,cAAc;AAC3C,MAAI,WAAW,CAAC;AAEhB,MAAI;AACF,eAAW,MAAM,KAAK,QAAQ,iBAAiB,QAAQ,CAAC;AAAA,EAE1D,QAAQ;AAAA,EAAC;AAIT,MAAI,SAAS,WAAW,KAAK,eAAe,CAAC,MAAM,eAAe,CAAC,EAAE,YAAY,GAAG;AAClF,eAAW,MAAM,KAAK,QAAQ,iBAAiB,cAAc,CAAC;AAAA,EAChE;AAEA,SAAO;AACT;AAKO,SAAS,uBAAuB,OAAe,QAA6B;AACjF,SAAO,QAAQ,OAAO,KAAK,KAAK,OAAO,MAAM,SAAS,KAAK;AAC7D;AAKO,SAAS,cAAc,OAAe,SAA+B;AAC1E,SAAO,UAAU,QAAQ,KAAK,KAAK,EAAE,CAAC;AACxC;AAKO,SAAS,eAAe,UAAgB,OAAe,QAAiC;AAC7F,MAAI,uBAAuB,OAAO,MAAM,KAAK,cAAc,OAAO,SAAS,GAAG,GAAG;AAC/E,WAAO,SAAS;AAAA,EAClB;AACF;AAOA,SAAS,sBAAiC;AACxC,SAAO,WAAW,6BAA6B,oBAAI,IAAU;AAC/D;AAUO,SAAS,aACd,MACkC;AAClC,MAAI,UAAU,IAAI,GAAG;AACnB,UAAM,oBAAoB,oBAAI,IAAqB;AACnD,eAAW,YAAY,oBAAoB,GAAG;AAC5C,UAAI,oBAAoB,MAAM;AAC5B,0BAAkB,IAAI,QAA2B;AAAA,MACnD;AAAA,IACF;AACA,WAAO;AAAA,EACT,OAAO;AACL,WAAO,IAAI,IAAI,oBAAoB,CAAC;AAAA,EACtC;AACF;AAEO,SAAS,YAAY,UAAgB;AAC1C,sBAAoB,EAAE,IAAI,QAAQ;AACpC;AAEO,SAAS,eAAe,UAAgB;AAC7C,sBAAoB,EAAE,OAAO,QAAQ;AACvC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/decorators/index.d.ts
CHANGED
package/decorators/index.js
CHANGED
package/decorators/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './withBreakpointManager.js';\nexport * from './withBreakpointObserver.js';\nexport * from './withDrag.js';\nexport * from './withExtraConfig.js';\nexport * from './withFreezedOptions.js';\nexport * from './withIntersectionObserver.js';\nexport * from './withMountOnMediaQuery.js';\nexport * from './withMountWhenInView.js';\nexport * from './withMountWhenPrefersMotion.js';\nexport * from './withMutation.js';\nexport * from './withName.js';\nexport * from './withRelativePointer.js';\nexport * from './withResponsiveOptions.js';\nexport * from './withScrolledInView/index.js';\n"],
|
|
5
|
-
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
4
|
+
"sourcesContent": ["export * from './withBreakpointManager.js';\nexport * from './withBreakpointObserver.js';\nexport * from './withDrag.js';\nexport * from './withExtraConfig.js';\nexport * from './withFreezedOptions.js';\nexport * from './withIntersectionObserver.js';\nexport * from './withMountOnMediaQuery.js';\nexport * from './withMountWhenInView.js';\nexport * from './withMountWhenPrefersMotion.js';\nexport * from './withMutation.js';\nexport * from './withName.js';\nexport * from './withRelativePointer.js';\nexport * from './withResponsiveOptions.js';\nexport * from './withScrolledInView/index.js';\nexport * from './withGroup.js';\n"],
|
|
5
|
+
"mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,5 +2,6 @@ import type { BaseDecorator, BaseInterface } from '../Base/types.js';
|
|
|
2
2
|
import type { Base, BaseConstructor } from '../Base/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* BreakpointManager class.
|
|
5
|
-
|
|
5
|
+
* @link https://js-toolkit.studiometa.dev/api/decorators/withBreakpointManager.html
|
|
6
|
+
*/
|
|
6
7
|
export declare function withBreakpointManager<S extends Base>(BaseClass: typeof Base, breakpoints: Array<[string, BaseConstructor<Base>]>): BaseDecorator<BaseInterface, S>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withBreakpointManager.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseConstructor, BaseProps } from '../Base/index.js';\nimport { useResize } from '../services/index.js';\nimport { isDev, isArray } from '../utils/index.js';\n\n/**\n * Test the breakpoins of the given Base instance and return the hook to call.\n */\nfunction testBreakpoints(breakpoints: Array<[string[], Base]>) {\n const { breakpoint } = useResize().props();\n for (const [breakpointKeys, instance] of breakpoints) {\n if (breakpointKeys.includes(breakpoint) && !instance.$isMounted) {\n setTimeout(() => instance.$mount(), 0);\n } else if (!breakpointKeys.includes(breakpoint) && instance.$isMounted) {\n instance.$destroy();\n }\n }\n}\n\n/**\n * Prepare the components.\n */\nfunction mountComponents(\n instance: Base,\n breakpoints: Array<[string, BaseConstructor]>,\n): Array<[string[], Base]> {\n return breakpoints.map(([bk, ComponentClass]) => {\n const child = new ComponentClass(instance.$el);\n Object.defineProperty(child, '$parent', { get: () => instance.$parent });\n return [bk.split(' '), child];\n });\n}\n\n/**\n * A cache object to hold each Base sub-instances.\n */\nconst instances: WeakMap<Base, Array<[string[], Base]>> = new WeakMap();\n\n/**\n * BreakpointManager class.\n */\nexport function withBreakpointManager<S extends Base>(\n BaseClass: typeof Base,\n breakpoints: Array<[string, BaseConstructor<Base>]>,\n): BaseDecorator<BaseInterface, S> {\n if (!isArray(breakpoints)) {\n if (isDev) {\n throw new Error('[withBreakpointManager] The `breakpoints` parameter must be an array.');\n }\n\n // @ts-ignore\n return BaseClass;\n }\n\n if (breakpoints.length < 2) {\n if (isDev) {\n throw new Error('[withBreakpointManager] You must define at least 2 breakpoints.');\n }\n\n // @ts-ignore\n return BaseClass;\n }\n\n const { add, props } = useResize();\n\n // Do nothing if no breakpoint has been defined.\n // @
|
|
5
|
-
"mappings": "AAEA,SAAS,iBAAiB;AAC1B,SAAS,OAAO,eAAe;AAK/B,SAAS,gBAAgB,aAAsC;AAC7D,QAAM,EAAE,WAAW,IAAI,UAAU,EAAE,MAAM;AACzC,aAAW,CAAC,gBAAgB,QAAQ,KAAK,aAAa;AACpD,QAAI,eAAe,SAAS,UAAU,KAAK,CAAC,SAAS,YAAY;AAC/D,iBAAW,MAAM,SAAS,OAAO,GAAG,CAAC;AAAA,IACvC,WAAW,CAAC,eAAe,SAAS,UAAU,KAAK,SAAS,YAAY;AACtE,eAAS,SAAS;AAAA,IACpB;AAAA,EACF;AACF;AAKA,SAAS,gBACP,UACA,aACyB;AACzB,SAAO,YAAY,IAAI,CAAC,CAAC,IAAI,cAAc,MAAM;AAC/C,UAAM,QAAQ,IAAI,eAAe,SAAS,GAAG;AAC7C,WAAO,eAAe,OAAO,WAAW,EAAE,KAAK,MAAM,SAAS,QAAQ,CAAC;AACvE,WAAO,CAAC,GAAG,MAAM,GAAG,GAAG,KAAK;AAAA,EAC9B,CAAC;AACH;AAKA,MAAM,YAAoD,oBAAI,QAAQ;
|
|
4
|
+
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseConstructor, BaseProps } from '../Base/index.js';\nimport { useResize } from '../services/index.js';\nimport { isDev, isArray } from '../utils/index.js';\n\n/**\n * Test the breakpoins of the given Base instance and return the hook to call.\n */\nfunction testBreakpoints(breakpoints: Array<[string[], Base]>) {\n const { breakpoint } = useResize().props();\n for (const [breakpointKeys, instance] of breakpoints) {\n if (breakpointKeys.includes(breakpoint) && !instance.$isMounted) {\n setTimeout(() => instance.$mount(), 0);\n } else if (!breakpointKeys.includes(breakpoint) && instance.$isMounted) {\n instance.$destroy();\n }\n }\n}\n\n/**\n * Prepare the components.\n */\nfunction mountComponents(\n instance: Base,\n breakpoints: Array<[string, BaseConstructor]>,\n): Array<[string[], Base]> {\n return breakpoints.map(([bk, ComponentClass]) => {\n const child = new ComponentClass(instance.$el);\n Object.defineProperty(child, '$parent', { get: () => instance.$parent });\n return [bk.split(' '), child];\n });\n}\n\n/**\n * A cache object to hold each Base sub-instances.\n */\nconst instances: WeakMap<Base, Array<[string[], Base]>> = new WeakMap();\n\n/**\n * BreakpointManager class.\n * @link https://js-toolkit.studiometa.dev/api/decorators/withBreakpointManager.html\n*/\nexport function withBreakpointManager<S extends Base>(\n BaseClass: typeof Base,\n breakpoints: Array<[string, BaseConstructor<Base>]>,\n): BaseDecorator<BaseInterface, S> {\n if (!isArray(breakpoints)) {\n if (isDev) {\n throw new Error('[withBreakpointManager] The `breakpoints` parameter must be an array.');\n }\n\n // @ts-ignore\n return BaseClass;\n }\n\n if (breakpoints.length < 2) {\n if (isDev) {\n throw new Error('[withBreakpointManager] You must define at least 2 breakpoints.');\n }\n\n // @ts-ignore\n return BaseClass;\n }\n\n const { add, props } = useResize();\n\n // Do nothing if no breakpoint has been defined.\n // @link https://js-toolkit.studiometa.dev/api/services/useResize.html#breakpoint\n if (!props().breakpoint) {\n if (isDev) {\n throw new Error('The `BreakpointManager` class requires breakpoints to be defined.');\n }\n\n // @ts-ignore\n return BaseClass;\n }\n\n /**\n * Class.\n */\n class WithBreakpointManager<T extends BaseProps = BaseProps> extends BaseClass<T> {\n /**\n * Watch for the document resize to test the breakpoints.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n if (!instances.has(this)) {\n instances.set(this, mountComponents(this, breakpoints));\n }\n\n add(`BreakpointManager-${this.$id}`, () => {\n testBreakpoints(instances.get(this));\n });\n }\n\n /**\n * Override the default $mount method to prevent component's from being\n * mounted when they should not.\n */\n async $mount() {\n await super.$mount();\n\n testBreakpoints(instances.get(this));\n\n return this;\n }\n\n /**\n * Destroy all instances when the main one is destroyed.\n */\n async $destroy() {\n const promises = [];\n if (isArray(instances.get(this))) {\n for (const [, instance] of instances.get(this)) {\n promises.push(instance.$destroy());\n }\n }\n\n await Promise.all(promises);\n\n return super.$destroy();\n }\n }\n\n // @ts-ignore\n return WithBreakpointManager;\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,iBAAiB;AAC1B,SAAS,OAAO,eAAe;AAK/B,SAAS,gBAAgB,aAAsC;AAC7D,QAAM,EAAE,WAAW,IAAI,UAAU,EAAE,MAAM;AACzC,aAAW,CAAC,gBAAgB,QAAQ,KAAK,aAAa;AACpD,QAAI,eAAe,SAAS,UAAU,KAAK,CAAC,SAAS,YAAY;AAC/D,iBAAW,MAAM,SAAS,OAAO,GAAG,CAAC;AAAA,IACvC,WAAW,CAAC,eAAe,SAAS,UAAU,KAAK,SAAS,YAAY;AACtE,eAAS,SAAS;AAAA,IACpB;AAAA,EACF;AACF;AAKA,SAAS,gBACP,UACA,aACyB;AACzB,SAAO,YAAY,IAAI,CAAC,CAAC,IAAI,cAAc,MAAM;AAC/C,UAAM,QAAQ,IAAI,eAAe,SAAS,GAAG;AAC7C,WAAO,eAAe,OAAO,WAAW,EAAE,KAAK,MAAM,SAAS,QAAQ,CAAC;AACvE,WAAO,CAAC,GAAG,MAAM,GAAG,GAAG,KAAK;AAAA,EAC9B,CAAC;AACH;AAKA,MAAM,YAAoD,oBAAI,QAAQ;AAM/D,SAAS,sBACd,WACA,aACiC;AACjC,MAAI,CAAC,QAAQ,WAAW,GAAG;AACzB,QAAI,OAAO;AACT,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAGA,WAAO;AAAA,EACT;AAEA,MAAI,YAAY,SAAS,GAAG;AAC1B,QAAI,OAAO;AACT,YAAM,IAAI,MAAM,iEAAiE;AAAA,IACnF;AAGA,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,KAAK,MAAM,IAAI,UAAU;AAIjC,MAAI,CAAC,MAAM,EAAE,YAAY;AACvB,QAAI,OAAO;AACT,YAAM,IAAI,MAAM,mEAAmE;AAAA,IACrF;AAGA,WAAO;AAAA,EACT;AAAA,EAKA,MAAM,8BAA+D,UAAa;AAAA;AAAA;AAAA;AAAA,IAIhF,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,UAAI,CAAC,UAAU,IAAI,IAAI,GAAG;AACxB,kBAAU,IAAI,MAAM,gBAAgB,MAAM,WAAW,CAAC;AAAA,MACxD;AAEA,UAAI,qBAAqB,KAAK,GAAG,IAAI,MAAM;AACzC,wBAAgB,UAAU,IAAI,IAAI,CAAC;AAAA,MACrC,CAAC;AAAA,IACH;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,MAAM,SAAS;AACb,YAAM,MAAM,OAAO;AAEnB,sBAAgB,UAAU,IAAI,IAAI,CAAC;AAEnC,aAAO;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAKA,MAAM,WAAW;AACf,YAAM,WAAW,CAAC;AAClB,UAAI,QAAQ,UAAU,IAAI,IAAI,CAAC,GAAG;AAChC,mBAAW,CAAC,EAAE,QAAQ,KAAK,UAAU,IAAI,IAAI,GAAG;AAC9C,mBAAS,KAAK,SAAS,SAAS,CAAC;AAAA,QACnC;AAAA,MACF;AAEA,YAAM,QAAQ,IAAI,QAAQ;AAE1B,aAAO,MAAM,SAAS;AAAA,IACxB;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -10,5 +10,6 @@ export interface WithBreakpointObserverInterface extends BaseInterface {
|
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
12
|
* BreakpointObserver class.
|
|
13
|
-
|
|
13
|
+
* @link https://js-toolkit.studiometa.dev/api/decorators/withBreakpointObserver.html
|
|
14
|
+
*/
|
|
14
15
|
export declare function withBreakpointObserver<S extends Base>(BaseClass: typeof Base): BaseDecorator<WithBreakpointObserverInterface, S, WithBreakpointObserverProps>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withBreakpointObserver.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport { useResize } from '../services/index.js';\nimport type { ResizeServiceProps } from '../services/index.js';\nimport { isDev, startsWith } from '../utils/index.js';\nimport { features } from '../Base/features.js';\n\nexport interface WithBreakpointObserverProps extends BaseProps {\n $options: {\n activeBreakpoints?: string;\n inactiveBreakpoints?: string;\n };\n}\n\nexport interface WithBreakpointObserverInterface extends BaseInterface {}\n\n/**\n * Test the breakpoins of the given Base instance and return the hook to call.\n *\n * @param
|
|
5
|
-
"mappings": "AAEA,SAAS,iBAAiB;AAE1B,SAAS,OAAO,kBAAkB;AAClC,SAAS,gBAAgB;AAkBzB,SAAS,gBACP,UACA,aAAqB,UAAU,EAAE,MAAM,EAAE,YACjC;AACR,QAAM,EAAE,mBAAmB,oBAAoB,IAAI,SAAS;AAC5D,QAAM,uBACJ,qBAAqB,kBAAkB,MAAM,GAAG,EAAE,SAAS,UAAU;AACvE,QAAM,yBACJ,uBAAuB,oBAAoB,MAAM,GAAG,EAAE,SAAS,UAAU;AAE3E,MACG,qBAAqB,wBACrB,uBAAuB,CAAC,wBACzB;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAQA,SAAS,2BAA2B,UAAsD;AACxF,QAAM,EAAE,mBAAmB,oBAAoB,IAAI,SAAS;AAC5D,SAAO,QAAQ,qBAAqB,mBAAmB;AACzD;AAQA,SAAS,uCAAuC,UAAmD;AACjG,QAAM,EAAE,mBAAmB,qBAAqB,KAAK,IAAI,SAAS;AAClE,MAAI,qBAAqB,qBAAqB;AAC5C,UAAM,IAAI;AAAA,MACR,IAAI,IAAI;AAAA,IACV;AAAA,EACF;AACF;AAKA,SAAS,qBACP,UAC2C;AAC3C,SAAO,CAAC,EAAE,WAAW,MAAM;AACzB,UAAM,SAAS,gBAAgB,UAAU,UAAU;AAGnD,QAAI,WAAW,cAAc,SAAS,YAAY;AAChD,eAAS,MAAM,EAAE;AAAA,IACnB,WAAW,WAAW,YAAY,CAAC,SAAS,YAAY;AACtD,iBAAW,MAAM,SAAS,MAAM,EAAE,GAAG,CAAC;AAAA,IACxC;AAAA,EACF;AACF;AAQA,SAAS,YAAY,KAAK,UAAU;AAClC,MAAI,OAAO;AACT,2CAAuC,QAAQ;AAAA,EACjD;AAEA,QAAM,EAAE,KAAK,KAAK,MAAM,IAAI,UAAU;AAEtC,MAAI,CAAC,IAAI,GAAG,GAAG;AACb,UAAM,WAAW,qBAAqB,QAAQ;AAC9C,QAAI,KAAK,QAAQ;AACjB,aAAS,MAAM,CAAC;AAAA,EAClB;AACF;
|
|
4
|
+
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport { useResize } from '../services/index.js';\nimport type { ResizeServiceProps } from '../services/index.js';\nimport { isDev, startsWith } from '../utils/index.js';\nimport { features } from '../Base/features.js';\n\nexport interface WithBreakpointObserverProps extends BaseProps {\n $options: {\n activeBreakpoints?: string;\n inactiveBreakpoints?: string;\n };\n}\n\nexport interface WithBreakpointObserverInterface extends BaseInterface {}\n\n/**\n * Test the breakpoins of the given Base instance and return the hook to call.\n *\n * @param {Base<WithBreakpointObserverProps>} instance The component's instance.\n * @param {string} [breakpoint] The breakpoint to test.\n * @return {string} The action to trigger.\n */\nfunction testBreakpoints(\n instance: Base<WithBreakpointObserverProps>,\n breakpoint: string = useResize().props().breakpoint,\n): string {\n const { activeBreakpoints, inactiveBreakpoints } = instance.$options;\n const isInActiveBreakpoint =\n activeBreakpoints && activeBreakpoints.split(' ').includes(breakpoint);\n const isInInactiveBreakpoint =\n inactiveBreakpoints && inactiveBreakpoints.split(' ').includes(breakpoint);\n\n if (\n (activeBreakpoints && isInActiveBreakpoint) ||\n (inactiveBreakpoints && !isInInactiveBreakpoint)\n ) {\n return '$mount';\n }\n\n return '$destroy';\n}\n\n/**\n * Test if the given instance is configured for breakpoints.\n *\n * @param {Base<WithBreakpointObserverProps>} instance A Base class instance.\n * @return {boolean} True if configured correctly, false otherwise.\n */\nfunction hasBreakpointConfiguration(instance: Base<WithBreakpointObserverProps>): boolean {\n const { activeBreakpoints, inactiveBreakpoints } = instance.$options;\n return Boolean(activeBreakpoints || inactiveBreakpoints);\n}\n\n/**\n * Test if the given instance has a conflicting configuration for breakpoints.\n *\n * @param {Base<WithBreakpointObserverProps>} instance A Base class instance.\n * @return {void}\n */\nfunction testConflictingBreakpointConfiguration(instance: Base<WithBreakpointObserverProps>): void {\n const { activeBreakpoints, inactiveBreakpoints, name } = instance.$options;\n if (activeBreakpoints && inactiveBreakpoints) {\n throw new Error(\n `[${name}] Incorrect configuration: the \\`activeBreakpoints\\` and \\`inactiveBreakpoints\\` are not compatible.`,\n );\n }\n}\n\n/**\n * Callback triggered when the window is resized.\n */\nfunction createResizeCallback(\n instance: Base<WithBreakpointObserverProps>,\n): (resizeProps: ResizeServiceProps) => void {\n return ({ breakpoint }) => {\n const action = testBreakpoints(instance, breakpoint);\n\n // Always destroy before mounting\n if (action === '$destroy' && instance.$isMounted) {\n instance[action]();\n } else if (action === '$mount' && !instance.$isMounted) {\n setTimeout(() => instance[action](), 0);\n }\n };\n}\n\n/**\n * Add the current instance to the resize service.\n *\n * @param {string} key The key for the resize service callback.\n * @param {Base} instance The instance to observe.\n */\nfunction addToResize(key, instance) {\n if (isDev) {\n testConflictingBreakpointConfiguration(instance);\n }\n\n const { add, has, props } = useResize();\n\n if (!has(key)) {\n const callback = createResizeCallback(instance);\n add(key, callback);\n callback(props());\n }\n}\n\n/**\n * BreakpointObserver class.\n * @link https://js-toolkit.studiometa.dev/api/decorators/withBreakpointObserver.html\n*/\nexport function withBreakpointObserver<S extends Base>(\n BaseClass: typeof Base,\n): BaseDecorator<WithBreakpointObserverInterface, S, WithBreakpointObserverProps> {\n /**\n * Class.\n */\n class WithBreakpointObserver<T extends BaseProps = BaseProps> extends BaseClass<\n T & WithBreakpointObserverProps\n > {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n options: {\n activeBreakpoints: String,\n inactiveBreakpoints: String,\n },\n };\n\n /**\n * Watch for the document resize to test the breakpoints.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n const { remove, props } = useResize();\n const { name } = this.$options;\n\n // Do nothing if no breakpoint has been defined.\n // @link https://js-toolkit.studiometa.dev/api/services/useResize.html#breakpoint\n if (!props().breakpoint) {\n if (isDev) {\n throw new Error(\n `[${name}] The \\`BreakpointObserver\\` class requires breakpoints to be defined.`,\n );\n }\n return;\n }\n\n const key = `BreakpointObserver-${this.$id}`;\n const attributes = features.get('attributes');\n\n // Watch change on the `data-options` attribute to emit the `set:options` event.\n const mutationObserver = new MutationObserver(([mutation]) => {\n if (\n mutation.type === 'attributes' &&\n startsWith(mutation.attributeName, `${attributes.option}-`)\n ) {\n // Stop here silently when no breakpoint configuration given.\n if (!hasBreakpointConfiguration(this)) {\n this.$mount();\n remove(key);\n return;\n }\n\n addToResize(key, this);\n }\n });\n mutationObserver.observe(this.$el, { attributes: true });\n\n // Stop here silently when no breakpoint configuration given.\n if (!hasBreakpointConfiguration(this)) {\n return;\n }\n\n addToResize(key, this);\n }\n\n /**\n * Override the default $mount method to prevent component's from being\n * mounted when they should not.\n */\n async $mount() {\n // Execute normal behavior when no breakpoint configuration given.\n if (!hasBreakpointConfiguration(this)) {\n return super.$mount();\n }\n\n const action = testBreakpoints(this);\n if (action === '$mount') {\n return super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithBreakpointObserver;\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,iBAAiB;AAE1B,SAAS,OAAO,kBAAkB;AAClC,SAAS,gBAAgB;AAkBzB,SAAS,gBACP,UACA,aAAqB,UAAU,EAAE,MAAM,EAAE,YACjC;AACR,QAAM,EAAE,mBAAmB,oBAAoB,IAAI,SAAS;AAC5D,QAAM,uBACJ,qBAAqB,kBAAkB,MAAM,GAAG,EAAE,SAAS,UAAU;AACvE,QAAM,yBACJ,uBAAuB,oBAAoB,MAAM,GAAG,EAAE,SAAS,UAAU;AAE3E,MACG,qBAAqB,wBACrB,uBAAuB,CAAC,wBACzB;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAQA,SAAS,2BAA2B,UAAsD;AACxF,QAAM,EAAE,mBAAmB,oBAAoB,IAAI,SAAS;AAC5D,SAAO,QAAQ,qBAAqB,mBAAmB;AACzD;AAQA,SAAS,uCAAuC,UAAmD;AACjG,QAAM,EAAE,mBAAmB,qBAAqB,KAAK,IAAI,SAAS;AAClE,MAAI,qBAAqB,qBAAqB;AAC5C,UAAM,IAAI;AAAA,MACR,IAAI,IAAI;AAAA,IACV;AAAA,EACF;AACF;AAKA,SAAS,qBACP,UAC2C;AAC3C,SAAO,CAAC,EAAE,WAAW,MAAM;AACzB,UAAM,SAAS,gBAAgB,UAAU,UAAU;AAGnD,QAAI,WAAW,cAAc,SAAS,YAAY;AAChD,eAAS,MAAM,EAAE;AAAA,IACnB,WAAW,WAAW,YAAY,CAAC,SAAS,YAAY;AACtD,iBAAW,MAAM,SAAS,MAAM,EAAE,GAAG,CAAC;AAAA,IACxC;AAAA,EACF;AACF;AAQA,SAAS,YAAY,KAAK,UAAU;AAClC,MAAI,OAAO;AACT,2CAAuC,QAAQ;AAAA,EACjD;AAEA,QAAM,EAAE,KAAK,KAAK,MAAM,IAAI,UAAU;AAEtC,MAAI,CAAC,IAAI,GAAG,GAAG;AACb,UAAM,WAAW,qBAAqB,QAAQ;AAC9C,QAAI,KAAK,QAAQ;AACjB,aAAS,MAAM,CAAC;AAAA,EAClB;AACF;AAMO,SAAS,uBACd,WACgF;AAAA,EAIhF,MAAM,+BAAgE,UAEpE;AAAA;AAAA;AAAA;AAAA,IAIA,OAAO,SAAqB;AAAA,MAC1B,GAAG,UAAU;AAAA,MACb,SAAS;AAAA,QACP,mBAAmB;AAAA,QACnB,qBAAqB;AAAA,MACvB;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,YAAM,EAAE,QAAQ,MAAM,IAAI,UAAU;AACpC,YAAM,EAAE,KAAK,IAAI,KAAK;AAItB,UAAI,CAAC,MAAM,EAAE,YAAY;AACvB,YAAI,OAAO;AACT,gBAAM,IAAI;AAAA,YACR,IAAI,IAAI;AAAA,UACV;AAAA,QACF;AACA;AAAA,MACF;AAEA,YAAM,MAAM,sBAAsB,KAAK,GAAG;AAC1C,YAAM,aAAa,SAAS,IAAI,YAAY;AAG5C,YAAM,mBAAmB,IAAI,iBAAiB,CAAC,CAAC,QAAQ,MAAM;AAC5D,YACE,SAAS,SAAS,gBAClB,WAAW,SAAS,eAAe,GAAG,WAAW,MAAM,GAAG,GAC1D;AAEA,cAAI,CAAC,2BAA2B,IAAI,GAAG;AACrC,iBAAK,OAAO;AACZ,mBAAO,GAAG;AACV;AAAA,UACF;AAEA,sBAAY,KAAK,IAAI;AAAA,QACvB;AAAA,MACF,CAAC;AACD,uBAAiB,QAAQ,KAAK,KAAK,EAAE,YAAY,KAAK,CAAC;AAGvD,UAAI,CAAC,2BAA2B,IAAI,GAAG;AACrC;AAAA,MACF;AAEA,kBAAY,KAAK,IAAI;AAAA,IACvB;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,MAAM,SAAS;AAEb,UAAI,CAAC,2BAA2B,IAAI,GAAG;AACrC,eAAO,MAAM,OAAO;AAAA,MACtB;AAEA,YAAM,SAAS,gBAAgB,IAAI;AACnC,UAAI,WAAW,UAAU;AACvB,eAAO,MAAM,OAAO;AAAA,MACtB;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/decorators/withDrag.d.ts
CHANGED
|
@@ -9,5 +9,6 @@ export interface WithDragInterface extends BaseInterface {
|
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Add dragging capabilities to a component.
|
|
12
|
-
|
|
12
|
+
* @link https://js-toolkit.studiometa.dev/api/decorators/withDrag.html
|
|
13
|
+
*/
|
|
13
14
|
export declare function withDrag<S extends Base>(BaseClass: typeof Base, { target, ...options }?: DragDecoratorOptions): BaseDecorator<BaseInterface, S>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withDrag.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport type { DragServiceOptions, DragServiceProps } from '../services/index.js';\nimport { useDrag } from '../services/index.js';\n\nexport type DragDecoratorOptions = DragServiceOptions & {\n target?: (this: Base, instance: Base) => HTMLElement;\n};\n\nexport interface WithDragInterface extends BaseInterface {\n dragged?(props: DragServiceProps): void;\n}\n\n/**\n * Add dragging capabilities to a component.\n */\nexport function withDrag<S extends Base>(\n BaseClass: typeof Base,\n { target = (instance) => instance.$el, ...options }: DragDecoratorOptions = {},\n): BaseDecorator<BaseInterface, S> {\n /**\n * Class.\n */\n class WithDrag<T extends BaseProps = BaseProps> extends BaseClass<T & WithDragInterface> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n emits: ['dragged'],\n };\n\n /**\n * Class constructor.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n this.$on('mounted', () => {\n this.$services.register(\n 'dragged',\n useDrag.bind(undefined, target.call(this, this), options),\n );\n this.$services.enable('dragged');\n });\n\n this.$on('destroyed', () => {\n this.$services.disable('dragged');\n this.$services.unregister('dragged');\n });\n }\n }\n\n // @ts-ignore\n return WithDrag;\n}\n"],
|
|
5
|
-
"mappings": "AAGA,SAAS,eAAe;
|
|
4
|
+
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport type { DragServiceOptions, DragServiceProps } from '../services/index.js';\nimport { useDrag } from '../services/index.js';\n\nexport type DragDecoratorOptions = DragServiceOptions & {\n target?: (this: Base, instance: Base) => HTMLElement;\n};\n\nexport interface WithDragInterface extends BaseInterface {\n dragged?(props: DragServiceProps): void;\n}\n\n/**\n * Add dragging capabilities to a component.\n * @link https://js-toolkit.studiometa.dev/api/decorators/withDrag.html\n*/\nexport function withDrag<S extends Base>(\n BaseClass: typeof Base,\n { target = (instance) => instance.$el, ...options }: DragDecoratorOptions = {},\n): BaseDecorator<BaseInterface, S> {\n /**\n * Class.\n */\n class WithDrag<T extends BaseProps = BaseProps> extends BaseClass<T & WithDragInterface> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n emits: ['dragged'],\n };\n\n /**\n * Class constructor.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n this.$on('mounted', () => {\n this.$services.register(\n 'dragged',\n useDrag.bind(undefined, target.call(this, this), options),\n );\n this.$services.enable('dragged');\n });\n\n this.$on('destroyed', () => {\n this.$services.disable('dragged');\n this.$services.unregister('dragged');\n });\n }\n }\n\n // @ts-ignore\n return WithDrag;\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,eAAe;AAcjB,SAAS,SACd,WACA,EAAE,SAAS,CAAC,aAAa,SAAS,KAAK,GAAG,QAAQ,IAA0B,CAAC,GAC5C;AAAA,EAIjC,MAAM,iBAAkD,UAAiC;AAAA;AAAA;AAAA;AAAA,IAIvF,OAAO,SAAqB;AAAA,MAC1B,GAAG,UAAU;AAAA,MACb,OAAO,CAAC,SAAS;AAAA,IACnB;AAAA;AAAA;AAAA;AAAA,IAKA,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,WAAK,IAAI,WAAW,MAAM;AACxB,aAAK,UAAU;AAAA,UACb;AAAA,UACA,QAAQ,KAAK,QAAW,OAAO,KAAK,MAAM,IAAI,GAAG,OAAO;AAAA,QAC1D;AACA,aAAK,UAAU,OAAO,SAAS;AAAA,MACjC,CAAC;AAED,WAAK,IAAI,aAAa,MAAM;AAC1B,aAAK,UAAU,QAAQ,SAAS;AAChC,aAAK,UAAU,WAAW,SAAS;AAAA,MACrC,CAAC;AAAA,IACH;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,5 +3,6 @@ import type { BaseDecorator, BaseInterface } from '../Base/types.js';
|
|
|
3
3
|
import type { Base, BaseConfig } from '../Base/index.js';
|
|
4
4
|
/**
|
|
5
5
|
* Extends the configuration of an existing class.
|
|
6
|
-
|
|
6
|
+
* @link https://js-toolkit.studiometa.dev/api/decorators/withExtraConfig.html
|
|
7
|
+
*/
|
|
7
8
|
export declare function withExtraConfig<S extends Base>(BaseClass: typeof Base, config: Partial<BaseConfig>, options?: DeepmergeOptions): BaseDecorator<BaseInterface, S>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withExtraConfig.ts"],
|
|
4
|
-
"sourcesContent": ["import merge from 'deepmerge';\nimport type { Options as DeepmergeOptions } from 'deepmerge';\nimport type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\n\n/**\n * Extends the configuration of an existing class.\n */\nexport function withExtraConfig<S extends Base>(\n BaseClass: typeof Base,\n config: Partial<BaseConfig>,\n options: DeepmergeOptions = {},\n): BaseDecorator<BaseInterface, S> {\n const newConfig = merge(BaseClass.config, config, options);\n\n if (newConfig.name === BaseClass.config.name) {\n newConfig.name = `${BaseClass.config.name}WithExtraConfig`;\n }\n\n /**\n * Class.\n */\n class WithExtraConfig<T extends BaseProps = BaseProps> extends BaseClass<T> {\n /**\n * Config.\n */\n static config: BaseConfig = newConfig;\n }\n\n // @ts-ignore\n return WithExtraConfig;\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,WAAW;
|
|
4
|
+
"sourcesContent": ["import merge from 'deepmerge';\nimport type { Options as DeepmergeOptions } from 'deepmerge';\nimport type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\n\n/**\n * Extends the configuration of an existing class.\n * @link https://js-toolkit.studiometa.dev/api/decorators/withExtraConfig.html\n*/\nexport function withExtraConfig<S extends Base>(\n BaseClass: typeof Base,\n config: Partial<BaseConfig>,\n options: DeepmergeOptions = {},\n): BaseDecorator<BaseInterface, S> {\n const newConfig = merge(BaseClass.config, config, options);\n\n if (newConfig.name === BaseClass.config.name) {\n newConfig.name = `${BaseClass.config.name}WithExtraConfig`;\n }\n\n /**\n * Class.\n */\n class WithExtraConfig<T extends BaseProps = BaseProps> extends BaseClass<T> {\n /**\n * Config.\n */\n static config: BaseConfig = newConfig;\n }\n\n // @ts-ignore\n return WithExtraConfig;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,WAAW;AASX,SAAS,gBACd,WACA,QACA,UAA4B,CAAC,GACI;AACjC,QAAM,YAAY,MAAM,UAAU,QAAQ,QAAQ,OAAO;AAEzD,MAAI,UAAU,SAAS,UAAU,OAAO,MAAM;AAC5C,cAAU,OAAO,GAAG,UAAU,OAAO,IAAI;AAAA,EAC3C;AAAA,EAKA,MAAM,wBAAyD,UAAa;AAAA;AAAA;AAAA;AAAA,IAI1E,OAAO,SAAqB;AAAA,EAC9B;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -5,5 +5,6 @@ export interface WithFreezedOptionsInterface extends BaseInterface {
|
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
7
|
* Freeze the `$options` property to improve performance.
|
|
8
|
-
|
|
8
|
+
* @link https://js-toolkit.studiometa.dev/api/decorators/withFreezedOptions.html
|
|
9
|
+
*/
|
|
9
10
|
export declare function withFreezedOptions<S extends Base>(BaseClass: typeof Base): BaseDecorator<WithFreezedOptionsInterface, S>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withFreezedOptions.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseOptions } from '../Base/index.js';\n\nexport interface WithFreezedOptionsInterface extends BaseInterface {\n readonly $options: Readonly<BaseOptions>;\n}\n\n/**\n * Freeze the `$options` property to improve performance.\n */\nexport function withFreezedOptions<S extends Base>(\n BaseClass: typeof Base,\n): BaseDecorator<WithFreezedOptionsInterface, S> {\n /**\n * Class.\n */\n class WithFreezedOptions<T extends BaseProps = BaseProps> extends BaseClass<T> {\n /**\n * Hold freezed options\n *\n * @private\n */\n __freezedOptions;\n\n /**\n * Lazyly freeze the `$options` property.\n */\n get $options() {\n if (!this.__freezedOptions) {\n Object.defineProperty(this, '__freezedOptions', {\n value: Object.freeze({ ...super.$options }),\n enumerable: false,\n configurable: true,\n });\n }\n\n return this.__freezedOptions;\n }\n }\n\n // @ts-ignore\n return WithFreezedOptions;\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseOptions } from '../Base/index.js';\n\nexport interface WithFreezedOptionsInterface extends BaseInterface {\n readonly $options: Readonly<BaseOptions>;\n}\n\n/**\n * Freeze the `$options` property to improve performance.\n * @link https://js-toolkit.studiometa.dev/api/decorators/withFreezedOptions.html\n*/\nexport function withFreezedOptions<S extends Base>(\n BaseClass: typeof Base,\n): BaseDecorator<WithFreezedOptionsInterface, S> {\n /**\n * Class.\n */\n class WithFreezedOptions<T extends BaseProps = BaseProps> extends BaseClass<T> {\n /**\n * Hold freezed options\n *\n * @private\n */\n __freezedOptions;\n\n /**\n * Lazyly freeze the `$options` property.\n */\n get $options() {\n if (!this.__freezedOptions) {\n Object.defineProperty(this, '__freezedOptions', {\n value: Object.freeze({ ...super.$options }),\n enumerable: false,\n configurable: true,\n });\n }\n\n return this.__freezedOptions;\n }\n }\n\n // @ts-ignore\n return WithFreezedOptions;\n}\n"],
|
|
5
|
+
"mappings": "AAWO,SAAS,mBACd,WAC+C;AAAA,EAI/C,MAAM,2BAA4D,UAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAM7E;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,WAAW;AACb,UAAI,CAAC,KAAK,kBAAkB;AAC1B,eAAO,eAAe,MAAM,oBAAoB;AAAA,UAC9C,OAAO,OAAO,OAAO,EAAE,GAAG,MAAM,SAAS,CAAC;AAAA,UAC1C,YAAY;AAAA,UACZ,cAAc;AAAA,QAChB,CAAC;AAAA,MACH;AAEA,aAAO,KAAK;AAAA,IACd;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { BaseDecorator, BaseInterface } from '../Base/types.js';
|
|
2
|
+
import type { Base, BaseProps } from '../Base/index.js';
|
|
3
|
+
export interface WithGroupProps extends BaseProps {
|
|
4
|
+
$options: {
|
|
5
|
+
group: string;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export interface WithGroupInterface extends BaseInterface {
|
|
9
|
+
get $group(): Set<Base>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Add group features to easily bind multiple components together.
|
|
13
|
+
*
|
|
14
|
+
* @link https://js-toolkit.studiometa.dev/api/decorators/withGroup.html
|
|
15
|
+
*/
|
|
16
|
+
export declare function withGroup<S extends Base = Base>(BaseClass: typeof Base, namespace?: string): BaseDecorator<WithGroupInterface, S, WithGroupProps>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function groups() {
|
|
2
|
+
return globalThis.__JS_TOOLKIT_GROUPS__ ??= /* @__PURE__ */ new Map();
|
|
3
|
+
}
|
|
4
|
+
function withGroup(BaseClass, namespace = "") {
|
|
5
|
+
return class WithGroup extends BaseClass {
|
|
6
|
+
static config = {
|
|
7
|
+
...BaseClass.config,
|
|
8
|
+
options: {
|
|
9
|
+
group: String
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Get the group set.
|
|
14
|
+
*/
|
|
15
|
+
get $group() {
|
|
16
|
+
const group = `${namespace}${this.$options.group}`;
|
|
17
|
+
const instances = groups().get(group) ?? groups().set(group, /* @__PURE__ */ new Set()).get(group);
|
|
18
|
+
for (const instance of instances) {
|
|
19
|
+
if (!instance.$el.isConnected) {
|
|
20
|
+
instances.delete(instance);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return instances;
|
|
24
|
+
}
|
|
25
|
+
constructor(element) {
|
|
26
|
+
super(element);
|
|
27
|
+
this.$on("mounted", () => {
|
|
28
|
+
this.$group.add(this);
|
|
29
|
+
});
|
|
30
|
+
this.$on("destroyed", () => {
|
|
31
|
+
this.$group.delete(this);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
withGroup
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=withGroup.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../packages/js-toolkit/decorators/withGroup.ts"],
|
|
4
|
+
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\n\nexport interface WithGroupProps extends BaseProps {\n $options: {\n group: string;\n };\n}\n\nexport interface WithGroupInterface extends BaseInterface {\n get $group(): Set<Base>;\n}\n\n/**\n * Get global groups map.\n */\nfunction groups<T extends Base = Base>(): Map<string, Set<T>> {\n return (globalThis.__JS_TOOLKIT_GROUPS__ ??= new Map<string, Set<T>>());\n}\n\n/**\n * Add group features to easily bind multiple components together.\n *\n * @link https://js-toolkit.studiometa.dev/api/decorators/withGroup.html\n */\nexport function withGroup<S extends Base = Base>(\n BaseClass: typeof Base,\n namespace = '',\n): BaseDecorator<WithGroupInterface, S, WithGroupProps> {\n // @ts-expect-error Decorators can not be typed.\n return class WithGroup<T extends BaseProps = BaseProps> extends BaseClass<T & WithGroupProps> {\n static config: BaseConfig = {\n ...BaseClass.config,\n options: {\n group: String,\n },\n };\n\n /**\n * Get the group set.\n */\n get $group() {\n const group = `${namespace}${this.$options.group}`;\n const instances = groups<this>().get(group) ?? groups<this>().set(group, new Set()).get(group);\n\n for (const instance of instances) {\n if (!instance.$el.isConnected) {\n instances.delete(instance);\n }\n }\n\n return instances;\n }\n\n constructor(element: HTMLElement) {\n super(element);\n\n this.$on('mounted', () => {\n this.$group.add(this);\n });\n this.$on('destroyed', () => {\n this.$group.delete(this);\n });\n }\n };\n}\n"],
|
|
5
|
+
"mappings": "AAgBA,SAAS,SAAqD;AAC5D,SAAQ,WAAW,0BAA0B,oBAAI,IAAoB;AACvE;AAOO,SAAS,UACd,WACA,YAAY,IAC0C;AAEtD,SAAO,MAAM,kBAAmD,UAA8B;AAAA,IAC5F,OAAO,SAAqB;AAAA,MAC1B,GAAG,UAAU;AAAA,MACb,SAAS;AAAA,QACP,OAAO;AAAA,MACT;AAAA,IACF;AAAA;AAAA;AAAA;AAAA,IAKA,IAAI,SAAS;AACX,YAAM,QAAQ,GAAG,SAAS,GAAG,KAAK,SAAS,KAAK;AAChD,YAAM,YAAY,OAAa,EAAE,IAAI,KAAK,KAAK,OAAa,EAAE,IAAI,OAAO,oBAAI,IAAI,CAAC,EAAE,IAAI,KAAK;AAE7F,iBAAW,YAAY,WAAW;AAChC,YAAI,CAAC,SAAS,IAAI,aAAa;AAC7B,oBAAU,OAAO,QAAQ;AAAA,QAC3B;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,IAEA,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,WAAK,IAAI,WAAW,MAAM;AACxB,aAAK,OAAO,IAAI,IAAI;AAAA,MACtB,CAAC;AACD,WAAK,IAAI,aAAa,MAAM;AAC1B,aAAK,OAAO,OAAO,IAAI;AAAA,MACzB,CAAC;AAAA,IACH;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -12,5 +12,6 @@ export interface WithIntersectionObserverInterface extends BaseInterface {
|
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
14
|
* IntersectionObserver decoration.
|
|
15
|
-
|
|
15
|
+
* @link https://js-toolkit.studiometa.dev/api/decorators/withIntersectionObserver.html
|
|
16
|
+
*/
|
|
16
17
|
export declare function withIntersectionObserver<S extends Base>(BaseClass: typeof Base, defaultOptions?: IntersectionObserverInit): BaseDecorator<WithIntersectionObserverInterface, S, WithIntersectionObserverProps>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withIntersectionObserver.ts"],
|
|
4
|
-
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport { createRange } from '../utils/index.js';\n\nexport interface WithIntersectionObserverProps extends BaseProps {\n $options: {\n intersectionObserver: IntersectionObserverInit;\n };\n $observer: IntersectionObserver;\n intersected(entries: IntersectionObserverEntry[]): void;\n}\n\nexport interface WithIntersectionObserverInterface extends BaseInterface {\n $observer: IntersectionObserver;\n}\n\n/**\n * IntersectionObserver decoration.\n */\nexport function withIntersectionObserver<S extends Base>(\n BaseClass: typeof Base,\n // eslint-disable-next-line unicorn/no-object-as-default-parameter\n defaultOptions: IntersectionObserverInit = { threshold: createRange(0, 1, 0.01) },\n): BaseDecorator<WithIntersectionObserverInterface, S, WithIntersectionObserverProps> {\n /**\n * Class.\n */\n class WithIntersectionObserver<T extends BaseProps = BaseProps> extends BaseClass<\n T & WithIntersectionObserverProps\n > {\n /**\n * Config\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n options: {\n intersectionObserver: Object,\n },\n emits: ['intersected'],\n };\n\n /**\n * Intersection observer instance.\n */\n $observer: IntersectionObserver;\n\n /**\n * Create an observer when the class in instantiated.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n this.$observer = new IntersectionObserver(\n (entries) => {\n this.__callMethod('intersected', entries);\n },\n {\n ...defaultOptions,\n ...(this.$options.intersectionObserver as IntersectionObserverInit),\n },\n );\n\n this.$on('mounted', () => {\n this.$observer.observe(this.$el);\n });\n\n this.$on('destroyed', () => {\n this.$observer.unobserve(this.$el);\n });\n }\n }\n\n // @ts-ignore\n return WithIntersectionObserver;\n}\n"],
|
|
5
|
-
"mappings": "AAEA,SAAS,mBAAmB;
|
|
4
|
+
"sourcesContent": ["import type { BaseDecorator, BaseInterface } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport { createRange } from '../utils/index.js';\n\nexport interface WithIntersectionObserverProps extends BaseProps {\n $options: {\n intersectionObserver: IntersectionObserverInit;\n };\n $observer: IntersectionObserver;\n intersected(entries: IntersectionObserverEntry[]): void;\n}\n\nexport interface WithIntersectionObserverInterface extends BaseInterface {\n $observer: IntersectionObserver;\n}\n\n/**\n * IntersectionObserver decoration.\n * @link https://js-toolkit.studiometa.dev/api/decorators/withIntersectionObserver.html\n*/\nexport function withIntersectionObserver<S extends Base>(\n BaseClass: typeof Base,\n // eslint-disable-next-line unicorn/no-object-as-default-parameter\n defaultOptions: IntersectionObserverInit = { threshold: createRange(0, 1, 0.01) },\n): BaseDecorator<WithIntersectionObserverInterface, S, WithIntersectionObserverProps> {\n /**\n * Class.\n */\n class WithIntersectionObserver<T extends BaseProps = BaseProps> extends BaseClass<\n T & WithIntersectionObserverProps\n > {\n /**\n * Config\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n options: {\n intersectionObserver: Object,\n },\n emits: ['intersected'],\n };\n\n /**\n * Intersection observer instance.\n */\n $observer: IntersectionObserver;\n\n /**\n * Create an observer when the class in instantiated.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n this.$observer = new IntersectionObserver(\n (entries) => {\n this.__callMethod('intersected', entries);\n },\n {\n ...defaultOptions,\n ...(this.$options.intersectionObserver as IntersectionObserverInit),\n },\n );\n\n this.$on('mounted', () => {\n this.$observer.observe(this.$el);\n });\n\n this.$on('destroyed', () => {\n this.$observer.unobserve(this.$el);\n });\n }\n }\n\n // @ts-ignore\n return WithIntersectionObserver;\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,mBAAmB;AAkBrB,SAAS,yBACd,WAEA,iBAA2C,EAAE,WAAW,YAAY,GAAG,GAAG,IAAI,EAAE,GACI;AAAA,EAIpF,MAAM,iCAAkE,UAEtE;AAAA;AAAA;AAAA;AAAA,IAIA,OAAO,SAAqB;AAAA,MAC1B,GAAG,UAAU;AAAA,MACb,SAAS;AAAA,QACP,sBAAsB;AAAA,MACxB;AAAA,MACA,OAAO,CAAC,aAAa;AAAA,IACvB;AAAA;AAAA;AAAA;AAAA,IAKA;AAAA;AAAA;AAAA;AAAA,IAKA,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,WAAK,YAAY,IAAI;AAAA,QACnB,CAAC,YAAY;AACX,eAAK,aAAa,eAAe,OAAO;AAAA,QAC1C;AAAA,QACA;AAAA,UACE,GAAG;AAAA,UACH,GAAI,KAAK,SAAS;AAAA,QACpB;AAAA,MACF;AAEA,WAAK,IAAI,WAAW,MAAM;AACxB,aAAK,UAAU,QAAQ,KAAK,GAAG;AAAA,MACjC,CAAC;AAED,WAAK,IAAI,aAAa,MAAM;AAC1B,aAAK,UAAU,UAAU,KAAK,GAAG;AAAA,MACnC,CAAC;AAAA,IACH;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -14,5 +14,6 @@ export interface withMountOnMediaQueryInterface extends BaseInterface {
|
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
16
|
* IntersectionObserver decoration.
|
|
17
|
-
|
|
17
|
+
* @link https://js-toolkit.studiometa.dev/api/decorators/withMountOnMediaQuery.html
|
|
18
|
+
*/
|
|
18
19
|
export declare function withMountOnMediaQuery<S extends Base = Base>(BaseClass: typeof Base, media: any): BaseDecorator<withMountOnMediaQueryInterface, S, withMountOnMediaQueryProps>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withMountOnMediaQuery.ts"],
|
|
4
|
-
"sourcesContent": ["import { BaseInterface, BaseDecorator } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport { isDev } from '../utils/is.js';\n\nexport interface withMountOnMediaQueryProps extends BaseProps {\n $options: {\n media: string;\n };\n}\n\nexport interface withMountOnMediaQueryInterface extends BaseInterface {\n /**\n * @private\n */\n __matches: boolean;\n $mount(): this;\n}\n\n/**\n * IntersectionObserver decoration.\n */\nexport function withMountOnMediaQuery<S extends Base = Base>(\n BaseClass: typeof Base,\n media,\n): BaseDecorator<withMountOnMediaQueryInterface, S, withMountOnMediaQueryProps> {\n /**\n * Class.\n */\n class WithMountOnMediaQuery<T extends BaseProps = BaseProps> extends BaseClass<\n T & withMountOnMediaQueryProps\n > {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n options: {\n media: String,\n },\n };\n\n /**\n * Is the media query matches?\n *\n * @private\n */\n __matches = false;\n\n /**\n * Listen for media query changes when the class in instantiated.\n *\n * @param {HTMLElement} element The component's root element.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n if (isDev && !this.$options.media && !media) {\n this.$warn(\n 'Missing either \"$options.media\" or \"media\" argument in withMountOnMediaQuery decorator.',\n );\n return;\n }\n\n const mediaQueryList = window.matchMedia(this.$options.media || media);\n\n // Set initial value\n this.__matches = mediaQueryList.matches;\n\n const changeHandler = (event: MediaQueryListEvent) => {\n this.__matches = event.matches;\n\n if (event.matches && !this.$isMounted) {\n this.$mount();\n } else if (this.$isMounted) {\n setTimeout(() => this.$destroy());\n }\n };\n\n // Start listening for changes\n mediaQueryList.addEventListener('change', changeHandler);\n\n this.$on('terminated', () => {\n mediaQueryList.removeEventListener('change', changeHandler);\n });\n }\n\n /**\n * Override the mounting of the component.\n */\n async $mount() {\n if (this.__matches) {\n return super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithMountOnMediaQuery;\n}\n"],
|
|
5
|
-
"mappings": "AAEA,SAAS,aAAa;
|
|
4
|
+
"sourcesContent": ["import { BaseInterface, BaseDecorator } from '../Base/types.js';\nimport type { Base, BaseProps, BaseConfig } from '../Base/index.js';\nimport { isDev } from '../utils/is.js';\n\nexport interface withMountOnMediaQueryProps extends BaseProps {\n $options: {\n media: string;\n };\n}\n\nexport interface withMountOnMediaQueryInterface extends BaseInterface {\n /**\n * @private\n */\n __matches: boolean;\n $mount(): this;\n}\n\n/**\n * IntersectionObserver decoration.\n * @link https://js-toolkit.studiometa.dev/api/decorators/withMountOnMediaQuery.html\n*/\nexport function withMountOnMediaQuery<S extends Base = Base>(\n BaseClass: typeof Base,\n media,\n): BaseDecorator<withMountOnMediaQueryInterface, S, withMountOnMediaQueryProps> {\n /**\n * Class.\n */\n class WithMountOnMediaQuery<T extends BaseProps = BaseProps> extends BaseClass<\n T & withMountOnMediaQueryProps\n > {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...BaseClass.config,\n options: {\n media: String,\n },\n };\n\n /**\n * Is the media query matches?\n *\n * @private\n */\n __matches = false;\n\n /**\n * Listen for media query changes when the class in instantiated.\n *\n * @param {HTMLElement} element The component's root element.\n */\n constructor(element: HTMLElement) {\n super(element);\n\n if (isDev && !this.$options.media && !media) {\n this.$warn(\n 'Missing either \"$options.media\" or \"media\" argument in withMountOnMediaQuery decorator.',\n );\n return;\n }\n\n const mediaQueryList = window.matchMedia(this.$options.media || media);\n\n // Set initial value\n this.__matches = mediaQueryList.matches;\n\n const changeHandler = (event: MediaQueryListEvent) => {\n this.__matches = event.matches;\n\n if (event.matches && !this.$isMounted) {\n this.$mount();\n } else if (this.$isMounted) {\n setTimeout(() => this.$destroy());\n }\n };\n\n // Start listening for changes\n mediaQueryList.addEventListener('change', changeHandler);\n\n this.$on('terminated', () => {\n mediaQueryList.removeEventListener('change', changeHandler);\n });\n }\n\n /**\n * Override the mounting of the component.\n */\n async $mount() {\n if (this.__matches) {\n return super.$mount();\n }\n\n return this;\n }\n }\n\n // @ts-ignore\n return WithMountOnMediaQuery;\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,aAAa;AAoBf,SAAS,sBACd,WACA,OAC8E;AAAA,EAI9E,MAAM,8BAA+D,UAEnE;AAAA;AAAA;AAAA;AAAA,IAIA,OAAO,SAAqB;AAAA,MAC1B,GAAG,UAAU;AAAA,MACb,SAAS;AAAA,QACP,OAAO;AAAA,MACT;AAAA,IACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOZ,YAAY,SAAsB;AAChC,YAAM,OAAO;AAEb,UAAI,SAAS,CAAC,KAAK,SAAS,SAAS,CAAC,OAAO;AAC3C,aAAK;AAAA,UACH;AAAA,QACF;AACA;AAAA,MACF;AAEA,YAAM,iBAAiB,OAAO,WAAW,KAAK,SAAS,SAAS,KAAK;AAGrE,WAAK,YAAY,eAAe;AAEhC,YAAM,gBAAgB,CAAC,UAA+B;AACpD,aAAK,YAAY,MAAM;AAEvB,YAAI,MAAM,WAAW,CAAC,KAAK,YAAY;AACrC,eAAK,OAAO;AAAA,QACd,WAAW,KAAK,YAAY;AAC1B,qBAAW,MAAM,KAAK,SAAS,CAAC;AAAA,QAClC;AAAA,MACF;AAGA,qBAAe,iBAAiB,UAAU,aAAa;AAEvD,WAAK,IAAI,cAAc,MAAM;AAC3B,uBAAe,oBAAoB,UAAU,aAAa;AAAA,MAC5D,CAAC;AAAA,IACH;AAAA;AAAA;AAAA;AAAA,IAKA,MAAM,SAAS;AACb,UAAI,KAAK,WAAW;AAClB,eAAO,MAAM,OAAO;AAAA,MACtB;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -18,5 +18,6 @@ export interface WithMountWhenInViewInterface extends BaseInterface {
|
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* IntersectionObserver decoration.
|
|
21
|
-
|
|
21
|
+
* @link https://js-toolkit.studiometa.dev/api/decorators/withMountWhenInView.html
|
|
22
|
+
*/
|
|
22
23
|
export declare function withMountWhenInView<S extends Base = Base>(BaseClass: typeof Base, defaultOptions?: IntersectionObserverInit): BaseDecorator<WithMountWhenInViewInterface, S, WithMountWhenInViewProps>;
|