@studiometa/js-toolkit 2.11.2 → 3.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Base/Base.d.ts +2 -2
- package/Base/Base.js +142 -79
- package/Base/Base.js.map +2 -2
- package/Base/features.d.ts +10 -2
- package/Base/features.js +23 -1
- package/Base/features.js.map +2 -2
- package/Base/managers/AbstractManager.d.ts +3 -3
- package/Base/managers/AbstractManager.js +21 -0
- package/Base/managers/AbstractManager.js.map +1 -1
- package/Base/managers/ActionManager.d.ts +4 -0
- package/Base/managers/ActionManager.js +10 -0
- package/Base/managers/ActionManager.js.map +7 -0
- package/Base/managers/ChildrenManager.d.ts +1 -1
- package/Base/managers/ChildrenManager.js +41 -8
- package/Base/managers/ChildrenManager.js.map +2 -2
- package/Base/managers/EventsManager.js +88 -7
- package/Base/managers/EventsManager.js.map +2 -2
- package/Base/managers/OptionsManager.js +25 -2
- package/Base/managers/OptionsManager.js.map +2 -2
- package/Base/managers/RefsManager.js +27 -6
- package/Base/managers/RefsManager.js.map +2 -2
- package/Base/managers/ResponsiveOptionsManager.js +22 -6
- package/Base/managers/ResponsiveOptionsManager.js.map +2 -2
- package/Base/managers/ServicesManager.d.ts +2 -4
- package/Base/managers/ServicesManager.js +56 -7
- package/Base/managers/ServicesManager.js.map +2 -2
- package/Base/utils.js +5 -1
- package/Base/utils.js.map +2 -2
- package/decorators/index.d.ts +0 -1
- package/decorators/index.js +0 -1
- package/decorators/index.js.map +2 -2
- package/decorators/withBreakpointManager.js +14 -4
- package/decorators/withBreakpointManager.js.map +2 -2
- package/decorators/withBreakpointObserver.js +13 -3
- package/decorators/withBreakpointObserver.js.map +2 -2
- package/decorators/withDrag.js +6 -0
- package/decorators/withDrag.js.map +1 -1
- package/decorators/withExtraConfig.js +3 -0
- package/decorators/withExtraConfig.js.map +1 -1
- package/decorators/withFreezedOptions.js +8 -0
- package/decorators/withFreezedOptions.js.map +1 -1
- package/decorators/withIntersectionObserver.js +10 -1
- package/decorators/withIntersectionObserver.js.map +2 -2
- package/decorators/withMountOnMediaQuery.js +17 -1
- package/decorators/withMountOnMediaQuery.js.map +2 -2
- package/decorators/withMountWhenInView.js +22 -1
- package/decorators/withMountWhenInView.js.map +2 -2
- package/decorators/withRelativePointer.js +6 -0
- package/decorators/withRelativePointer.js.map +1 -1
- package/decorators/withResponsiveOptions.js +3 -0
- package/decorators/withResponsiveOptions.js.map +1 -1
- package/decorators/withScrolledInView/utils.d.ts +12 -1
- package/decorators/withScrolledInView/utils.js +7 -7
- package/decorators/withScrolledInView/utils.js.map +2 -2
- package/decorators/withScrolledInView/withScrolledInView.js +13 -35
- package/decorators/withScrolledInView/withScrolledInView.js.map +2 -2
- package/helpers/createApp.d.ts +2 -1
- package/helpers/createApp.js +2 -2
- package/helpers/createApp.js.map +2 -2
- package/helpers/getDirectChildren.js.map +1 -1
- package/helpers/importOnInteraction.js +4 -4
- package/helpers/importOnInteraction.js.map +2 -2
- package/helpers/importWhenVisible.js +2 -1
- package/helpers/importWhenVisible.js.map +2 -2
- package/package.json +2 -10
- package/services/drag.js +8 -8
- package/services/drag.js.map +2 -2
- package/services/index.d.ts +1 -1
- package/services/index.js.map +2 -2
- package/services/key.js +2 -2
- package/services/key.js.map +2 -2
- package/services/load.js +3 -0
- package/services/load.js.map +1 -1
- package/services/pointer.d.ts +1 -1
- package/services/pointer.js +7 -7
- package/services/pointer.js.map +2 -2
- package/services/raf.js +4 -6
- package/services/raf.js.map +2 -2
- package/services/resize.d.ts +7 -6
- package/services/resize.js +19 -26
- package/services/resize.js.map +2 -2
- package/services/scroll.js +8 -8
- package/services/scroll.js.map +2 -2
- package/services/service.js +2 -2
- package/services/service.js.map +2 -2
- package/utils/Queue.js +30 -0
- package/utils/Queue.js.map +1 -1
- package/utils/SmartQueue.d.ts +1 -1
- package/utils/SmartQueue.js +13 -1
- package/utils/SmartQueue.js.map +2 -2
- package/utils/collide/collidePointRect.js +4 -1
- package/utils/collide/collidePointRect.js.map +1 -1
- package/utils/collide/collideRectRect.js +4 -1
- package/utils/collide/collideRectRect.js.map +1 -1
- package/utils/css/animate.d.ts +33 -15
- package/utils/css/animate.js +80 -34
- package/utils/css/animate.js.map +2 -2
- package/utils/css/classes.js +2 -3
- package/utils/css/classes.js.map +2 -2
- package/utils/css/getOffsetSizes.js +2 -2
- package/utils/css/getOffsetSizes.js.map +1 -1
- package/utils/css/index.d.ts +2 -1
- package/utils/css/index.js +4 -4
- package/utils/css/index.js.map +2 -2
- package/utils/css/matrix.d.ts +1 -1
- package/utils/css/matrix.js.map +2 -2
- package/utils/css/styles.js +2 -2
- package/utils/css/styles.js.map +2 -2
- package/utils/css/transform.d.ts +1 -1
- package/utils/css/transform.js +1 -1
- package/utils/css/transform.js.map +2 -2
- package/utils/css/transition.js +15 -0
- package/utils/css/transition.js.map +1 -1
- package/utils/css/utils.d.ts +1 -1
- package/utils/css/utils.js +1 -1
- package/utils/css/utils.js.map +2 -2
- package/utils/history.js +6 -5
- package/utils/history.js.map +2 -2
- package/utils/index.d.ts +5 -4
- package/utils/index.js +16 -16
- package/utils/index.js.map +2 -2
- package/utils/is.d.ts +12 -0
- package/utils/is.js +17 -0
- package/utils/is.js.map +2 -2
- package/utils/math/ease.d.ts +1 -0
- package/utils/math/ease.js +2 -0
- package/utils/math/ease.js.map +2 -2
- package/utils/math/index.d.ts +4 -3
- package/utils/math/index.js +5 -3
- package/utils/math/index.js.map +2 -2
- package/utils/math/mean.d.ts +1 -0
- package/utils/math/mean.js +17 -0
- package/utils/math/mean.js.map +7 -0
- package/utils/nextFrame.d.ts +4 -22
- package/utils/nextFrame.js +3 -10
- package/utils/nextFrame.js.map +2 -2
- package/utils/nextMicrotask.d.ts +4 -1
- package/utils/nextMicrotask.js +3 -3
- package/utils/nextMicrotask.js.map +2 -2
- package/utils/nextTick.d.ts +4 -1
- package/utils/nextTick.js +3 -3
- package/utils/nextTick.js.map +2 -2
- package/utils/random.d.ts +15 -0
- package/utils/random.js +15 -0
- package/utils/random.js.map +7 -0
- package/utils/scheduler.js +4 -4
- package/utils/scheduler.js.map +2 -2
- package/utils/scrollTo.d.ts +30 -6
- package/utils/scrollTo.js +97 -43
- package/utils/scrollTo.js.map +2 -2
- package/utils/string/endsWith.d.ts +8 -0
- package/utils/string/endsWith.js +13 -0
- package/utils/string/endsWith.js.map +7 -0
- package/utils/string/index.d.ts +2 -0
- package/utils/string/index.js +2 -0
- package/utils/string/index.js.map +2 -2
- package/utils/string/startsWith.d.ts +8 -0
- package/utils/string/startsWith.js +13 -0
- package/utils/string/startsWith.js.map +7 -0
- package/utils/string/withLeadingCharacters.js.map +1 -1
- package/utils/string/withTrailingCharacters.js.map +1 -1
- package/utils/string/withoutLeadingCharacters.js.map +1 -1
- package/utils/string/withoutLeadingCharactersRecursive.js.map +1 -1
- package/utils/string/withoutTrailingCharacters.js.map +1 -1
- package/utils/string/withoutTrailingCharactersRecursive.js.map +1 -1
- package/utils/{focusTrap.d.ts → trapFocus.d.ts} +2 -10
- package/utils/{focusTrap.js → trapFocus.js} +5 -9
- package/utils/trapFocus.js.map +7 -0
- package/utils/tween.d.ts +59 -10
- package/utils/tween.js +24 -18
- package/utils/tween.js.map +2 -2
- package/Base/Base.cjs +0 -325
- package/Base/Base.cjs.map +0 -7
- package/Base/features.cjs +0 -27
- package/Base/features.cjs.map +0 -7
- package/Base/index.cjs +0 -21
- package/Base/index.cjs.map +0 -7
- package/Base/managers/AbstractManager.cjs +0 -57
- package/Base/managers/AbstractManager.cjs.map +0 -7
- package/Base/managers/ChildrenManager.cjs +0 -123
- package/Base/managers/ChildrenManager.cjs.map +0 -7
- package/Base/managers/EventsManager.cjs +0 -220
- package/Base/managers/EventsManager.cjs.map +0 -7
- package/Base/managers/OptionsManager.cjs +0 -171
- package/Base/managers/OptionsManager.cjs.map +0 -7
- package/Base/managers/RefsManager.cjs +0 -104
- package/Base/managers/RefsManager.cjs.map +0 -7
- package/Base/managers/ResponsiveOptionsManager.cjs +0 -63
- package/Base/managers/ResponsiveOptionsManager.cjs.map +0 -7
- package/Base/managers/ServicesManager.cjs +0 -111
- package/Base/managers/ServicesManager.cjs.map +0 -7
- package/Base/managers/index.cjs +0 -39
- package/Base/managers/index.cjs.map +0 -7
- package/Base/types.cjs +0 -19
- package/Base/types.cjs.map +0 -7
- package/Base/utils.cjs +0 -91
- package/Base/utils.cjs.map +0 -7
- package/decorators/index.cjs +0 -33
- package/decorators/index.cjs.map +0 -7
- package/decorators/withBreakpointManager.cjs +0 -92
- package/decorators/withBreakpointManager.cjs.map +0 -7
- package/decorators/withBreakpointObserver.cjs +0 -118
- package/decorators/withBreakpointObserver.cjs.map +0 -7
- package/decorators/withDrag.cjs +0 -50
- package/decorators/withDrag.cjs.map +0 -7
- package/decorators/withExtraConfig.cjs +0 -43
- package/decorators/withExtraConfig.cjs.map +0 -7
- package/decorators/withFreezedOptions.cjs +0 -42
- package/decorators/withFreezedOptions.cjs.map +0 -7
- package/decorators/withIntersectionObserver.cjs +0 -62
- package/decorators/withIntersectionObserver.cjs.map +0 -7
- package/decorators/withMountOnMediaQuery.cjs +0 -70
- package/decorators/withMountOnMediaQuery.cjs.map +0 -7
- package/decorators/withMountWhenInView.cjs +0 -71
- package/decorators/withMountWhenInView.cjs.map +0 -7
- package/decorators/withMountWhenPrefersMotion.cjs +0 -30
- package/decorators/withMountWhenPrefersMotion.cjs.map +0 -7
- package/decorators/withRelativePointer.cjs +0 -50
- package/decorators/withRelativePointer.cjs.map +0 -7
- package/decorators/withResponsiveOptions.cjs +0 -38
- package/decorators/withResponsiveOptions.cjs.map +0 -7
- package/decorators/withScrolledInView/index.cjs +0 -22
- package/decorators/withScrolledInView/index.cjs.map +0 -7
- package/decorators/withScrolledInView/types.cjs +0 -19
- package/decorators/withScrolledInView/types.cjs.map +0 -7
- package/decorators/withScrolledInView/utils.cjs +0 -99
- package/decorators/withScrolledInView/utils.cjs.map +0 -7
- package/decorators/withScrolledInView/withScrolledInView.cjs +0 -216
- package/decorators/withScrolledInView/withScrolledInView.cjs.map +0 -7
- package/decorators/withVue2.cjs +0 -65
- package/decorators/withVue2.cjs.map +0 -7
- package/decorators/withVue2.d.ts +0 -16
- package/decorators/withVue2.js +0 -43
- package/decorators/withVue2.js.map +0 -7
- package/helpers/createApp.cjs +0 -58
- package/helpers/createApp.cjs.map +0 -7
- package/helpers/getClosestParent.cjs +0 -41
- package/helpers/getClosestParent.cjs.map +0 -7
- package/helpers/getDirectChildren.cjs +0 -47
- package/helpers/getDirectChildren.cjs.map +0 -7
- package/helpers/getInstanceFromElement.cjs +0 -32
- package/helpers/getInstanceFromElement.cjs.map +0 -7
- package/helpers/importOnInteraction.cjs +0 -48
- package/helpers/importOnInteraction.cjs.map +0 -7
- package/helpers/importOnMediaQuery.cjs +0 -44
- package/helpers/importOnMediaQuery.cjs.map +0 -7
- package/helpers/importWhenIdle.cjs +0 -46
- package/helpers/importWhenIdle.cjs.map +0 -7
- package/helpers/importWhenPrefersMotion.cjs +0 -36
- package/helpers/importWhenPrefersMotion.cjs.map +0 -7
- package/helpers/importWhenVisible.cjs +0 -43
- package/helpers/importWhenVisible.cjs.map +0 -7
- package/helpers/index.cjs +0 -49
- package/helpers/index.cjs.map +0 -7
- package/helpers/utils.cjs +0 -37
- package/helpers/utils.cjs.map +0 -7
- package/index.cjs +0 -31
- package/index.cjs.map +0 -7
- package/services/drag.cjs +0 -227
- package/services/drag.cjs.map +0 -7
- package/services/index.cjs +0 -47
- package/services/index.cjs.map +0 -7
- package/services/key.cjs +0 -93
- package/services/key.cjs.map +0 -7
- package/services/load.cjs +0 -57
- package/services/load.cjs.map +0 -7
- package/services/pointer.cjs +0 -145
- package/services/pointer.cjs.map +0 -7
- package/services/raf.cjs +0 -80
- package/services/raf.cjs.map +0 -7
- package/services/resize.cjs +0 -103
- package/services/resize.cjs.map +0 -7
- package/services/scroll.cjs +0 -115
- package/services/scroll.cjs.map +0 -7
- package/services/service.cjs +0 -69
- package/services/service.cjs.map +0 -7
- package/utils/Queue.cjs +0 -63
- package/utils/Queue.cjs.map +0 -7
- package/utils/SmartQueue.cjs +0 -57
- package/utils/SmartQueue.cjs.map +0 -7
- package/utils/collide/boundingRectToCircle.cjs +0 -36
- package/utils/collide/boundingRectToCircle.cjs.map +0 -7
- package/utils/collide/collideCircleCircle.cjs +0 -35
- package/utils/collide/collideCircleCircle.cjs.map +0 -7
- package/utils/collide/collideCircleRect.cjs +0 -47
- package/utils/collide/collideCircleRect.cjs.map +0 -7
- package/utils/collide/collidePointCircle.cjs +0 -32
- package/utils/collide/collidePointCircle.cjs.map +0 -7
- package/utils/collide/collidePointRect.cjs +0 -29
- package/utils/collide/collidePointRect.cjs.map +0 -7
- package/utils/collide/collideRectRect.cjs +0 -29
- package/utils/collide/collideRectRect.cjs.map +0 -7
- package/utils/collide/index.cjs +0 -43
- package/utils/collide/index.cjs.map +0 -7
- package/utils/css/animate.cjs +0 -193
- package/utils/css/animate.cjs.map +0 -7
- package/utils/css/classes.cjs +0 -52
- package/utils/css/classes.cjs.map +0 -7
- package/utils/css/getOffsetSizes.cjs +0 -48
- package/utils/css/getOffsetSizes.cjs.map +0 -7
- package/utils/css/index.cjs +0 -48
- package/utils/css/index.cjs.map +0 -7
- package/utils/css/matrix.cjs +0 -30
- package/utils/css/matrix.cjs.map +0 -7
- package/utils/css/styles.cjs +0 -45
- package/utils/css/styles.cjs.map +0 -7
- package/utils/css/transform.cjs +0 -91
- package/utils/css/transform.cjs.map +0 -7
- package/utils/css/transition.cjs +0 -126
- package/utils/css/transition.cjs.map +0 -7
- package/utils/css/utils.cjs +0 -32
- package/utils/css/utils.cjs.map +0 -7
- package/utils/debounce.cjs +0 -35
- package/utils/debounce.cjs.map +0 -7
- package/utils/dom/ancestors.cjs +0 -37
- package/utils/dom/ancestors.cjs.map +0 -7
- package/utils/dom/index.cjs +0 -21
- package/utils/dom/index.cjs.map +0 -7
- package/utils/focusTrap.cjs +0 -89
- package/utils/focusTrap.cjs.map +0 -7
- package/utils/focusTrap.js.map +0 -7
- package/utils/getComponentResolver.cjs +0 -38
- package/utils/getComponentResolver.cjs.map +0 -7
- package/utils/has.cjs +0 -29
- package/utils/has.cjs.map +0 -7
- package/utils/history.cjs +0 -91
- package/utils/history.cjs.map +0 -7
- package/utils/index.cjs +0 -72
- package/utils/index.cjs.map +0 -7
- package/utils/is.cjs +0 -41
- package/utils/is.cjs.map +0 -7
- package/utils/keyCodes.cjs +0 -36
- package/utils/keyCodes.cjs.map +0 -7
- package/utils/math/clamp.cjs +0 -29
- package/utils/math/clamp.cjs.map +0 -7
- package/utils/math/clamp01.cjs +0 -36
- package/utils/math/clamp01.cjs.map +0 -7
- package/utils/math/createEases.cjs +0 -33
- package/utils/math/createEases.cjs.map +0 -7
- package/utils/math/damp.cjs +0 -29
- package/utils/math/damp.cjs.map +0 -7
- package/utils/math/ease.cjs +0 -82
- package/utils/math/ease.cjs.map +0 -7
- package/utils/math/index.cjs +0 -50
- package/utils/math/index.cjs.map +0 -7
- package/utils/math/inertiaFinalValue.cjs +0 -43
- package/utils/math/inertiaFinalValue.cjs.map +0 -7
- package/utils/math/lerp.cjs +0 -29
- package/utils/math/lerp.cjs.map +0 -7
- package/utils/math/map.cjs +0 -29
- package/utils/math/map.cjs.map +0 -7
- package/utils/math/round.cjs +0 -29
- package/utils/math/round.cjs.map +0 -7
- package/utils/memoize.cjs +0 -48
- package/utils/memoize.cjs.map +0 -7
- package/utils/nextFrame.cjs +0 -41
- package/utils/nextFrame.cjs.map +0 -7
- package/utils/nextMicrotask.cjs +0 -30
- package/utils/nextMicrotask.cjs.map +0 -7
- package/utils/nextTick.cjs +0 -31
- package/utils/nextTick.cjs.map +0 -7
- package/utils/noop.cjs +0 -32
- package/utils/noop.cjs.map +0 -7
- package/utils/object/autoBind.cjs +0 -54
- package/utils/object/autoBind.cjs.map +0 -7
- package/utils/object/autoBind.d.ts +0 -14
- package/utils/object/autoBind.js +0 -26
- package/utils/object/autoBind.js.map +0 -7
- package/utils/object/getAllProperties.cjs +0 -39
- package/utils/object/getAllProperties.cjs.map +0 -7
- package/utils/object/index.cjs +0 -35
- package/utils/object/index.cjs.map +0 -7
- package/utils/object/index.d.ts +0 -2
- package/utils/object/index.js +0 -7
- package/utils/object/index.js.map +0 -7
- package/utils/scheduler.cjs +0 -75
- package/utils/scheduler.cjs.map +0 -7
- package/utils/scrollTo.cjs +0 -84
- package/utils/scrollTo.cjs.map +0 -7
- package/utils/string/index.cjs +0 -51
- package/utils/string/index.cjs.map +0 -7
- package/utils/string/withLeadingCharacters.cjs +0 -36
- package/utils/string/withLeadingCharacters.cjs.map +0 -7
- package/utils/string/withLeadingSlash.cjs +0 -36
- package/utils/string/withLeadingSlash.cjs.map +0 -7
- package/utils/string/withTrailingCharacters.cjs +0 -36
- package/utils/string/withTrailingCharacters.cjs.map +0 -7
- package/utils/string/withTrailingSlash.cjs +0 -36
- package/utils/string/withTrailingSlash.cjs.map +0 -7
- package/utils/string/withoutLeadingCharacters.cjs +0 -29
- package/utils/string/withoutLeadingCharacters.cjs.map +0 -7
- package/utils/string/withoutLeadingCharactersRecursive.cjs +0 -41
- package/utils/string/withoutLeadingCharactersRecursive.cjs.map +0 -7
- package/utils/string/withoutLeadingSlash.cjs +0 -36
- package/utils/string/withoutLeadingSlash.cjs.map +0 -7
- package/utils/string/withoutTrailingCharacters.cjs +0 -29
- package/utils/string/withoutTrailingCharacters.cjs.map +0 -7
- package/utils/string/withoutTrailingCharactersRecursive.cjs +0 -41
- package/utils/string/withoutTrailingCharactersRecursive.cjs.map +0 -7
- package/utils/string/withoutTrailingSlash.cjs +0 -36
- package/utils/string/withoutTrailingSlash.cjs.map +0 -7
- package/utils/throttle.cjs +0 -37
- package/utils/throttle.cjs.map +0 -7
- package/utils/tween.cjs +0 -118
- package/utils/tween.cjs.map +0 -7
- package/utils/wait.cjs +0 -31
- package/utils/wait.cjs.map +0 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../packages/js-toolkit/Base/managers/RefsManager.ts"],
|
|
4
|
-
"sourcesContent": ["import { AbstractManager } from './AbstractManager.js';\nimport {
|
|
5
|
-
"mappings": "AAAA,SAAS,uBAAuB;AAChC,
|
|
4
|
+
"sourcesContent": ["import { AbstractManager } from './AbstractManager.js';\nimport {\n isDev,\n isArray,\n isDefined,\n getAncestorWhereUntil,\n endsWith,\n startsWith,\n} from '../../utils/index.js';\n\nconst NORMALIZE_REF_NAME_REGEX = /\\[\\]$/;\nconst NAMESPACED_REF_REGEX = /^(.*\\.)/;\nconst normalizedRefNamesCache = new Map();\n\n/**\n * Normalize the name of ref.\n */\nexport function normalizeRefName(name: string) {\n if (normalizedRefNamesCache.has(name)) {\n return normalizedRefNamesCache.get(name);\n }\n\n let normalizedName = name;\n\n if (endsWith(name, '[]')) {\n normalizedName = normalizedName.replace(NORMALIZE_REF_NAME_REGEX, '');\n }\n\n if (normalizedName.includes('.')) {\n return normalizedName.replace(NAMESPACED_REF_REGEX, '');\n }\n\n normalizedRefNamesCache.set(name, normalizedName);\n return normalizedName;\n}\n\n/**\n * Filter refs belonging to the related Base instance.\n */\nfunction refBelongToInstance(ref: HTMLElement, rootElement: HTMLElement, name: string) {\n const isPrefixed = startsWith(ref.dataset.ref, name);\n const firstComponentAncestor = getAncestorWhereUntil(\n ref,\n (el) =>\n el &&\n (isPrefixed ? el.dataset.component === name && el : isDefined(el.dataset.component)) &&\n el !== rootElement,\n (el) => el === rootElement,\n );\n\n return firstComponentAncestor === rootElement;\n}\n\n/**\n * Register one ref.\n *\n * @param {RefsManager} that\n * @param {string} refName The ref name.\n * @private\n */\nfunction __register(that: RefsManager, refName: string) {\n const isMultiple = endsWith(refName, '[]');\n const propName = normalizeRefName(refName);\n const { name } = that.__base.$options;\n\n const refs = Array.from(\n that.__element.querySelectorAll<HTMLElement>(\n `[data-ref=\"${refName}\"],[data-ref=\"${name}.${refName}\"]`,\n ),\n ).filter((ref) => refBelongToInstance(ref, that.__element, name));\n\n if (isDev && !isMultiple && refs.length > 1) {\n console.warn(\n // @ts-ignore\n `[${that.__base.$options.name}]`,\n `The \"${refName}\" ref has been found multiple times.`,\n 'Did you forgot to add the `[]` suffix to its name?',\n );\n }\n\n if (!isMultiple && refs.length <= 1 && !isDefined(refs[0])) {\n if (isDev) {\n console.warn(\n // @ts-ignore\n `[${that.__base.$options.name}]`,\n `The \"${refName}\" ref is missing.`,\n `Is there an \\`[data-ref=\"${refName}\"]\\` element in the component's scope?`,\n );\n }\n\n return;\n }\n\n that.__eventsManager.bindRef(refName, refs);\n\n Object.defineProperty(that, propName, {\n // @todo remove usage of non-multiple refs as array\n value: isMultiple || refs.length > 1 ? refs : refs[0],\n enumerable: true,\n configurable: true,\n });\n}\n\n/**\n * Unregister one ref.\n */\nfunction __unregister(that: RefsManager, refName: string) {\n const propName = normalizeRefName(refName);\n const refs = isArray(that[propName]) ? that[propName] : [that[propName]];\n that.__eventsManager.unbindRef(refName, refs);\n}\n\n/**\n * Refs Manager\n *\n * @todo Use `MutationObserver` to automatically update refs?\n */\nexport class RefsManager extends AbstractManager {\n /**\n * Get refs configuration.\n */\n get __refs() {\n return this.__config.refs ?? [];\n }\n\n /**\n * Register all refs.\n */\n registerAll() {\n for (const refName of this.__refs) __register(this, refName);\n }\n\n /**\n * Unregister all refs.\n */\n unregisterAll() {\n for (const refName of this.__refs) __unregister(this, refName);\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,MAAM,2BAA2B;AACjC,MAAM,uBAAuB;AAC7B,MAAM,0BAA0B,oBAAI,IAAI;AAKjC,SAAS,iBAAiB,MAAc;AAC7C,MAAI,wBAAwB,IAAI,IAAI,GAAG;AACrC,WAAO,wBAAwB,IAAI,IAAI;AAAA,EACzC;AAEA,MAAI,iBAAiB;AAErB,MAAI,SAAS,MAAM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A;AAAA,EACF;AAEA,OAAK,gBAAgB,QAAQ,SAAS,IAAI;AAE1C,SAAO,eAAe,MAAM,UAAU;AAAA;AAAA,IAEpC,OAAO,cAAc,KAAK,SAAS,IAAI,OAAO,KAAK,CAAC;AAAA,IACpD,YAAY;AAAA,IACZ,cAAc;AAAA,EAChB,CAAC;AACH;AAKA,SAAS,aAAa,MAAmB,SAAiB;AACxD,QAAM,WAAW,iBAAiB,OAAO;AACzC,QAAM,OAAO,QAAQ,KAAK,QAAQ,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,QAAQ,CAAC;AACvE,OAAK,gBAAgB,UAAU,SAAS,IAAI;AAC9C;AAOO,MAAM,oBAAoB,gBAAgB;AAAA;AAAA;AAAA;AAAA,EAI/C,IAAI,SAAS;AACX,WAAO,KAAK,SAAS,QAAQ,CAAC;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA,EAKA,cAAc;AACZ,eAAW,WAAW,KAAK;AAAQ,iBAAW,MAAM,OAAO;AAAA,EAC7D;AAAA;AAAA;AAAA;AAAA,EAKA,gBAAgB;AACd,eAAW,WAAW,KAAK;AAAQ,mBAAa,MAAM,OAAO;AAAA,EAC/D;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -9,22 +9,38 @@ function __getResponsiveName(that, name) {
|
|
|
9
9
|
let responsiveName = name;
|
|
10
10
|
const propertyName = __getPropertyName(name);
|
|
11
11
|
const regex = new RegExp(`${propertyName}:(.+)$`);
|
|
12
|
-
Object.keys(that.__element.dataset)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
for (const optionName of Object.keys(that.__element.dataset)) {
|
|
13
|
+
if (regex.test(optionName)) {
|
|
14
|
+
const [, breakpoints] = optionName.match(regex);
|
|
15
|
+
const isInBreakpoint = breakpoints.split(":").includes(breakpoint);
|
|
16
|
+
if (isInBreakpoint) {
|
|
17
|
+
responsiveName = optionName.replace(/^option/, "");
|
|
18
|
+
}
|
|
17
19
|
}
|
|
18
|
-
}
|
|
20
|
+
}
|
|
19
21
|
return responsiveName;
|
|
20
22
|
}
|
|
21
23
|
class ResponsiveOptionsManager extends OptionsManager {
|
|
24
|
+
/**
|
|
25
|
+
* Get an option value.
|
|
26
|
+
*
|
|
27
|
+
* @param {string} name The option name.
|
|
28
|
+
* @param {ResponsiveOptionObject} config The option configuration.
|
|
29
|
+
* @returns {any}
|
|
30
|
+
*/
|
|
22
31
|
get(name, config) {
|
|
23
32
|
if (!config.responsive) {
|
|
24
33
|
return super.get(name, config);
|
|
25
34
|
}
|
|
26
35
|
return super.get(__getResponsiveName(this, name), config);
|
|
27
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Set an option value.
|
|
39
|
+
*
|
|
40
|
+
* @param {string} name The option name.
|
|
41
|
+
* @param {any} value The new value.
|
|
42
|
+
* @param {ResponsiveOptionObject} config The option configuration.
|
|
43
|
+
*/
|
|
28
44
|
set(name, value, config) {
|
|
29
45
|
if (!config.responsive) {
|
|
30
46
|
super.set(name, value, config);
|
|
@@ -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';\n\nexport type ResponsiveOptionObject = OptionObject & { responsive?: boolean };\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 * @returns {string} The responsive name if one matches the current breakpoint, the default name otherwise.\n */\nfunction __getResponsiveName(that: ResponsiveOptionsManager, 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);\n const regex = new RegExp(`${propertyName}:(.+)$`);\n\n Object.keys(that.__element.dataset)\n
|
|
5
|
-
"mappings": "AAAA,SAAS,gBAAgB,yBAAyB;AAElD,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AAWtB,SAAS,oBAAoB,MAAgC,MAAc;AACzE,QAAM,EAAE,WAAW,IAAI,UAAU,EAAE,MAAM;AAEzC,MAAI,CAAC,YAAY;AACf,WAAO;AAAA,EACT;AAEA,MAAI,iBAAiB;AACrB,QAAM,eAAe,kBAAkB,IAAI;AAC3C,QAAM,QAAQ,IAAI,OAAO,GAAG,
|
|
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';\n\nexport type ResponsiveOptionObject = OptionObject & { responsive?: boolean };\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 * @returns {string} The responsive name if one matches the current breakpoint, the default name otherwise.\n */\nfunction __getResponsiveName(that: ResponsiveOptionsManager, 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);\n const regex = new RegExp(`${propertyName}:(.+)$`);\n\n for (const optionName of Object.keys(that.__element.dataset)) {\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(/^option/, '');\n }\n }\n }\n\n return responsiveName;\n}\n\n/**\n * Class options to manage options as data attributes on an HTML element.\n */\nexport class ResponsiveOptionsManager extends OptionsManager {\n /**\n * Get an option value.\n *\n * @param {string} name The option name.\n * @param {ResponsiveOptionObject} config The option configuration.\n * @returns {any}\n */\n get(name: string, config: ResponsiveOptionObject) {\n if (!config.responsive) {\n return super.get(name, config);\n }\n\n return super.get(__getResponsiveName(this, 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.__config.name}]`, 'Responsive options are read-only.');\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,gBAAgB,yBAAyB;AAElD,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AAWtB,SAAS,oBAAoB,MAAgC,MAAc;AACzE,QAAM,EAAE,WAAW,IAAI,UAAU,EAAE,MAAM;AAEzC,MAAI,CAAC,YAAY;AACf,WAAO;AAAA,EACT;AAEA,MAAI,iBAAiB;AACrB,QAAM,eAAe,kBAAkB,IAAI;AAC3C,QAAM,QAAQ,IAAI,OAAO,GAAG,YAAY,QAAQ;AAEhD,aAAW,cAAc,OAAO,KAAK,KAAK,UAAU,OAAO,GAAG;AAC5D,QAAI,MAAM,KAAK,UAAU,GAAG;AAC1B,YAAM,CAAC,EAAE,WAAW,IAAI,WAAW,MAAM,KAAK;AAC9C,YAAM,iBAAiB,YAAY,MAAM,GAAG,EAAE,SAAS,UAAU;AACjE,UAAI,gBAAgB;AAClB,yBAAiB,WAAW,QAAQ,WAAW,EAAE;AAAA,MACnD;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAKO,MAAM,iCAAiC,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQ3D,IAAI,MAAc,QAAgC;AAChD,QAAI,CAAC,OAAO,YAAY;AACtB,aAAO,MAAM,IAAI,MAAM,MAAM;AAAA,IAC/B;AAEA,WAAO,MAAM,IAAI,oBAAoB,MAAM,IAAI,GAAG,MAAM;AAAA,EAC1D;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,SAAS,IAAI,KAAK,mCAAmC;AAAA,IAC7E;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { usePointer, useRaf, useResize, useScroll, useKey
|
|
2
|
-
import type { PointerServiceInterface, RafServiceInterface, ResizeServiceInterface, ScrollServiceInterface, KeyServiceInterface,
|
|
1
|
+
import { usePointer, useRaf, useResize, useScroll, useKey } from '../../services/index.js';
|
|
2
|
+
import type { PointerServiceInterface, RafServiceInterface, ResizeServiceInterface, ScrollServiceInterface, KeyServiceInterface, ServiceInterface } from '../../services/index.js';
|
|
3
3
|
import { AbstractManager } from './AbstractManager.js';
|
|
4
4
|
type Services = {
|
|
5
5
|
scrolled: ScrollServiceInterface;
|
|
@@ -7,7 +7,6 @@ type Services = {
|
|
|
7
7
|
ticked: RafServiceInterface;
|
|
8
8
|
moved: PointerServiceInterface;
|
|
9
9
|
keyed: KeyServiceInterface;
|
|
10
|
-
loaded: LoadServiceInterface;
|
|
11
10
|
} & Record<string, ServiceInterface<unknown>>;
|
|
12
11
|
type ServiceNames = keyof Services;
|
|
13
12
|
/**
|
|
@@ -29,7 +28,6 @@ export declare class ServicesManager extends AbstractManager {
|
|
|
29
28
|
ticked: typeof useRaf;
|
|
30
29
|
moved: typeof usePointer;
|
|
31
30
|
keyed: typeof useKey;
|
|
32
|
-
loaded: typeof useLoad;
|
|
33
31
|
};
|
|
34
32
|
/**
|
|
35
33
|
* Test if the given service is registered.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { usePointer, useRaf, useResize, useScroll, useKey
|
|
1
|
+
import { usePointer, useRaf, useResize, useScroll, useKey } from "../../services/index.js";
|
|
2
2
|
import { AbstractManager } from "./AbstractManager.js";
|
|
3
3
|
import { noop, isFunction, isDefined, isDev } from "../../utils/index.js";
|
|
4
4
|
const SERVICES_MAP = {
|
|
@@ -6,47 +6,79 @@ const SERVICES_MAP = {
|
|
|
6
6
|
resized: useResize,
|
|
7
7
|
ticked: useRaf,
|
|
8
8
|
moved: usePointer,
|
|
9
|
-
keyed: useKey
|
|
10
|
-
loaded: useLoad
|
|
9
|
+
keyed: useKey
|
|
11
10
|
};
|
|
12
11
|
const SERVICE_NAMES = Object.keys(SERVICES_MAP);
|
|
13
12
|
class ServicesManager extends AbstractManager {
|
|
13
|
+
/**
|
|
14
|
+
* Holder for custom services.
|
|
15
|
+
*/
|
|
14
16
|
__customServices = {};
|
|
17
|
+
/**
|
|
18
|
+
* Get registered services.
|
|
19
|
+
*/
|
|
15
20
|
get __services() {
|
|
16
21
|
return {
|
|
17
22
|
...this.__customServices,
|
|
18
23
|
...SERVICES_MAP
|
|
19
24
|
};
|
|
20
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Test if the given service is registered.
|
|
28
|
+
*/
|
|
21
29
|
has(service) {
|
|
22
|
-
if (!((isFunction(this.__base[service]) ||
|
|
30
|
+
if (!((isFunction(this.__base[service]) || // @ts-ignore
|
|
31
|
+
this.__base.__hasEvent(service)) && this.__services[service])) {
|
|
23
32
|
return false;
|
|
24
33
|
}
|
|
25
34
|
const { has } = this.__services[service]();
|
|
26
35
|
return has(this.__base.$id);
|
|
27
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Get a service props by name.
|
|
39
|
+
*/
|
|
28
40
|
get(service) {
|
|
29
41
|
return this.__services[service]().props();
|
|
30
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Init the given service and bind it to the given instance.
|
|
45
|
+
*
|
|
46
|
+
* @param {ServiceNames} service The name of the service.
|
|
47
|
+
* @returns {() => void} A function to unbind the service.
|
|
48
|
+
*/
|
|
31
49
|
enable(service) {
|
|
32
50
|
if (this.has(service)) {
|
|
33
51
|
return this.disable.bind(this, service);
|
|
34
52
|
}
|
|
35
|
-
if (
|
|
53
|
+
if (
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
!(isFunction(this.__base[service]) || this.__base.__hasEvent(service)) || !this.__services[service]
|
|
56
|
+
) {
|
|
36
57
|
return noop;
|
|
37
58
|
}
|
|
38
59
|
const serviceInstance = this.__services[service]();
|
|
39
60
|
serviceInstance.add(this.__base.$id, (...args) => this.__base.__callMethod(service, ...args));
|
|
40
61
|
return this.disable.bind(this, service);
|
|
41
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Enable all services and return methods to disable them.
|
|
65
|
+
*/
|
|
42
66
|
enableAll() {
|
|
43
67
|
return Object.keys(this.__services).map((serviceName) => this.enable(serviceName));
|
|
44
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Disable all services.
|
|
71
|
+
*
|
|
72
|
+
* @returns {void}
|
|
73
|
+
*/
|
|
45
74
|
disableAll() {
|
|
46
|
-
Object.keys(this.__services)
|
|
75
|
+
for (const serviceName of Object.keys(this.__services)) {
|
|
47
76
|
this.disable(serviceName);
|
|
48
|
-
}
|
|
77
|
+
}
|
|
49
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Disable a service.
|
|
81
|
+
*/
|
|
50
82
|
disable(service) {
|
|
51
83
|
if (!this.__services[service]) {
|
|
52
84
|
return;
|
|
@@ -54,6 +86,9 @@ class ServicesManager extends AbstractManager {
|
|
|
54
86
|
const { remove } = this.__services[service]();
|
|
55
87
|
remove(this.__base.$id);
|
|
56
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Toggle a service.
|
|
91
|
+
*/
|
|
57
92
|
toggle(service, force) {
|
|
58
93
|
if (isDefined(force)) {
|
|
59
94
|
if (force && !this.has(service)) {
|
|
@@ -68,10 +103,24 @@ class ServicesManager extends AbstractManager {
|
|
|
68
103
|
this.enable(service);
|
|
69
104
|
}
|
|
70
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Register a new service to be enabled/disabled.
|
|
108
|
+
*
|
|
109
|
+
* @param {string} name
|
|
110
|
+
* The name of the service hook.
|
|
111
|
+
* @param {<T>(...args:unknown[]) => ServiceInterface<T>} useFunction
|
|
112
|
+
* The `use...` function for the service.
|
|
113
|
+
*/
|
|
71
114
|
register(name, useFunction) {
|
|
72
115
|
this.__customServices[name] = useFunction;
|
|
73
116
|
this.__base.__addEmits(name);
|
|
74
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Unregister a new service to be enabled disabled.
|
|
120
|
+
*
|
|
121
|
+
* @param {string} name
|
|
122
|
+
* The name of the service hook.
|
|
123
|
+
*/
|
|
75
124
|
unregister(name) {
|
|
76
125
|
if (SERVICE_NAMES.includes(name)) {
|
|
77
126
|
if (isDev) {
|
|
@@ -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
|
|
5
|
-
"mappings": "AAAA,SAAS,YAAY,QAAQ,WAAW,WAAW,
|
|
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 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 {\n /**\n * Holder for custom services.\n */\n __customServices: Record<string, <T>() => ServiceInterface<T>> = {};\n\n /**\n * Get registered services.\n */\n get __services() {\n return {\n ...this.__customServices,\n ...SERVICES_MAP,\n };\n }\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.__services[service]\n )\n ) {\n return false;\n }\n\n const { has } = this.__services[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.__services[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 * @returns {() => 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.__services[service]\n ) {\n return noop;\n }\n const serviceInstance = this.__services[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.__services).map((serviceName) => this.enable(serviceName));\n }\n\n /**\n * Disable all services.\n *\n * @returns {void}\n */\n disableAll() {\n for (const serviceName of Object.keys(this.__services)) {\n this.disable(serviceName);\n }\n }\n\n /**\n * Disable a service.\n */\n disable(service: ServiceNames) {\n if (!this.__services[service]) {\n return;\n }\n\n const { remove } = this.__services[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.__customServices[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.__customServices[name];\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,YAAY,QAAQ,WAAW,WAAW,cAAc;AASjE,SAAS,uBAAuB;AAChC,SAAS,MAAM,YAAY,WAAW,aAAa;AAEnD,MAAM,eAAe;AAAA,EACnB,UAAU;AAAA,EACV,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,OAAO;AACT;AAEA,MAAM,gBAAgB,OAAO,KAAK,YAAY;AAiBvC,MAAM,wBAAwB,gBAAgB;AAAA;AAAA;AAAA;AAAA,EAInD,mBAAiE,CAAC;AAAA;AAAA;AAAA;AAAA,EAKlE,IAAI,aAAa;AACf,WAAO;AAAA,MACL,GAAG,KAAK;AAAA,MACR,GAAG;AAAA,IACL;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,SAAyC;AAC3C,QACE,GACG,WAAW,KAAK,OAAO,OAAO,CAAC;AAAA,IAE9B,KAAK,OAAO,WAAW,OAAO,MAChC,KAAK,WAAW,OAAO,IAEzB;AACA,aAAO;AAAA,IACT;AAEA,UAAM,EAAE,IAAI,IAAI,KAAK,WAAW,OAAO,EAAE;AACzC,WAAO,IAAI,KAAK,OAAO,GAAG;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA,EAKA,IAAqC,SAA8C;AAEjF,WAAO,KAAK,WAAW,OAAO,EAAE,EAAE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AAQ,OAAO;AAAA,MACtB;AAAA,IACF,WAAW,KAAK,IAAI,OAAO,GAAG;AAC5B,WAAK,QAAQ,OAAO;AAAA,IACtB,OAAO;AACL,WAAK,OAAO,OAAO;AAAA,IACrB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,SAAS,MAAc,aAA6D;AAClF,SAAK,iBAAiB,IAAI,IAAI;AAC9B,SAAK,OAAO,WAAW,IAAI;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,WAAW,MAAc;AACvB,QAAI,cAAc,SAAS,IAAI,GAAG;AAChC,UAAI,OAAO;AACT,cAAM,IAAI,MAAM,2BAA2B,IAAI,0CAA0C;AAAA,MAC3F;AACA;AAAA,IACF;AAEA,SAAK,OAAO,cAAc,IAAI;AAC9B,WAAO,KAAK,iBAAiB,IAAI;AAAA,EACnC;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/Base/utils.js
CHANGED
|
@@ -16,9 +16,13 @@ const separator = " ";
|
|
|
16
16
|
function getSelector(nameOrSelector) {
|
|
17
17
|
if (!selectors.has(nameOrSelector)) {
|
|
18
18
|
const parts = [
|
|
19
|
+
// Single selector
|
|
19
20
|
`[data-component="${nameOrSelector}"]`,
|
|
21
|
+
// Selector in the middle of a list of selectors
|
|
20
22
|
`[data-component*="${separator}${nameOrSelector}${separator}"]`,
|
|
23
|
+
// Selector at the end of a list of selectors
|
|
21
24
|
`[data-component$="${separator}${nameOrSelector}"]`,
|
|
25
|
+
// Selector at the beginning of a list of selectors
|
|
22
26
|
`[data-component^="${nameOrSelector}${separator}"]`
|
|
23
27
|
];
|
|
24
28
|
selectors.set(nameOrSelector, parts.join(","));
|
|
@@ -32,7 +36,7 @@ function getComponentElements(nameOrSelector, element = document) {
|
|
|
32
36
|
elements = Array.from(element.querySelectorAll(selector));
|
|
33
37
|
} catch {
|
|
34
38
|
}
|
|
35
|
-
if (elements.length === 0) {
|
|
39
|
+
if (elements.length === 0 && nameOrSelector[0] === nameOrSelector[0].toLowerCase()) {
|
|
36
40
|
elements = Array.from(element.querySelectorAll(nameOrSelector));
|
|
37
41
|
}
|
|
38
42
|
return elements;
|
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, isDev, SmartQueue } from '../utils/index.js';\nimport type { Base, BaseConfig } 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): void {\n if (!features.get('asyncChildren')) {\n fn();\n return;\n }\n\n if (!queue) {\n queue = new SmartQueue();\n }\n\n 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 */\nfunction getSelector(nameOrSelector: string): string {\n if (!selectors.has(nameOrSelector)) {\n const parts = [\n // Single selector\n `[data-component=\"${nameOrSelector}\"]`,\n // Selector in the middle of a list of selectors\n `[data-component*=\"${separator}${nameOrSelector}${separator}\"]`,\n // Selector at the end of a list of selectors\n `[data-component$=\"${separator}${nameOrSelector}\"]`,\n // Selector at the beginning of a list of selectors\n `[data-component^=\"${nameOrSelector}${separator}\"]`,\n ];\n selectors.set(nameOrSelector, parts.join(','));\n }\n\n return selectors.get(nameOrSelector);\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 * @returns {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, try a classic DOM selector
|
|
5
|
-
"mappings": "AAAA,SAAS,SAAS,WAAW,OAAO,kBAAkB;AAEtD,SAAS,gBAAgB;AAEzB,IAAI;AAKG,SAAS,WAAW,IAAyB;AAClD,MAAI,CAAC,SAAS,IAAI,eAAe,GAAG;AAClC,OAAG;AACH;AAAA,EACF;AAEA,MAAI,CAAC,OAAO;AACV,YAAQ,IAAI,WAAW;AAAA,EACzB;AAEA,QAAM,IAAI,EAAE;AACd;AAEA,MAAM,YAAY,oBAAI,IAAI;AAG1B,MAAM,YAAY;AAKlB,SAAS,YAAY,gBAAgC;AACnD,MAAI,CAAC,UAAU,IAAI,cAAc,GAAG;AAClC,UAAM,QAAQ;AAAA,MAEZ,oBAAoB;AAAA,
|
|
4
|
+
"sourcesContent": ["import { isArray, isDefined, isDev, SmartQueue } from '../utils/index.js';\nimport type { Base, BaseConfig } 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): void {\n if (!features.get('asyncChildren')) {\n fn();\n return;\n }\n\n if (!queue) {\n queue = new SmartQueue();\n }\n\n 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 */\nfunction getSelector(nameOrSelector: string): string {\n if (!selectors.has(nameOrSelector)) {\n const parts = [\n // Single selector\n `[data-component=\"${nameOrSelector}\"]`,\n // Selector in the middle of a list of selectors\n `[data-component*=\"${separator}${nameOrSelector}${separator}\"]`,\n // Selector at the end of a list of selectors\n `[data-component$=\"${separator}${nameOrSelector}\"]`,\n // Selector at the beginning of a list of selectors\n `[data-component^=\"${nameOrSelector}${separator}\"]`,\n ];\n selectors.set(nameOrSelector, parts.join(','));\n }\n\n return selectors.get(nameOrSelector);\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 * @returns {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 *\n * @todo Return false in v3 if event is not defined or not native to prevent adding a listener.\n */\nexport function getEventTarget(\n instance: Base,\n event: string,\n config: BaseConfig,\n): Base | Base['$el'] {\n if (eventIsDefinedInConfig(event, config)) {\n return instance;\n }\n\n if (eventIsNative(event, instance.$el)) {\n return instance.$el;\n }\n\n if (isDev) {\n console.warn(\n `[${config.name}]`,\n `The \"${event}\" event is missing from the configuration and is not a native`,\n `event for the root element of type \\`${instance.$el.constructor.name}\\`.`,\n );\n }\n\n // @todo v3 return false or null\n return instance;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,SAAS,WAAW,OAAO,kBAAkB;AAEtD,SAAS,gBAAgB;AAEzB,IAAI;AAKG,SAAS,WAAW,IAAyB;AAClD,MAAI,CAAC,SAAS,IAAI,eAAe,GAAG;AAClC,OAAG;AACH;AAAA,EACF;AAEA,MAAI,CAAC,OAAO;AAC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A,MACN,IAAI,OAAO,IAAI;AAAA,MACf,QAAQ,KAAK;AAAA,MACb,wCAAwC,SAAS,IAAI,YAAY,IAAI;AAAA,IACvE;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
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 './withRelativePointer.js';\nexport * from './withResponsiveOptions.js';\nexport * from './withScrolledInView/index.js';\
|
|
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;
|
|
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 './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;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,13 +2,13 @@ import { useResize } from "../services/index.js";
|
|
|
2
2
|
import { isDev, isArray } from "../utils/index.js";
|
|
3
3
|
function testBreakpoints(breakpoints) {
|
|
4
4
|
const { breakpoint } = useResize().props();
|
|
5
|
-
|
|
5
|
+
for (const [breakpointKeys, instance] of breakpoints) {
|
|
6
6
|
if (breakpointKeys.includes(breakpoint) && !instance.$isMounted) {
|
|
7
7
|
setTimeout(() => instance.$mount(), 0);
|
|
8
8
|
} else if (!breakpointKeys.includes(breakpoint) && instance.$isMounted) {
|
|
9
9
|
instance.$destroy();
|
|
10
10
|
}
|
|
11
|
-
}
|
|
11
|
+
}
|
|
12
12
|
}
|
|
13
13
|
function mountComponents(instance, breakpoints) {
|
|
14
14
|
return breakpoints.map(([bk, ComponentClass]) => {
|
|
@@ -39,6 +39,9 @@ function withBreakpointManager(BaseClass, breakpoints) {
|
|
|
39
39
|
return BaseClass;
|
|
40
40
|
}
|
|
41
41
|
class WithBreakpointManager extends BaseClass {
|
|
42
|
+
/**
|
|
43
|
+
* Watch for the document resize to test the breakpoints.
|
|
44
|
+
*/
|
|
42
45
|
constructor(element) {
|
|
43
46
|
super(element);
|
|
44
47
|
if (!instances.has(this)) {
|
|
@@ -48,16 +51,23 @@ function withBreakpointManager(BaseClass, breakpoints) {
|
|
|
48
51
|
testBreakpoints(instances.get(this));
|
|
49
52
|
});
|
|
50
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Override the default $mount method to prevent component's from being
|
|
56
|
+
* mounted when they should not.
|
|
57
|
+
*/
|
|
51
58
|
$mount() {
|
|
52
59
|
super.$mount();
|
|
53
60
|
testBreakpoints(instances.get(this));
|
|
54
61
|
return this;
|
|
55
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Destroy all instances when the main one is destroyed.
|
|
65
|
+
*/
|
|
56
66
|
$destroy() {
|
|
57
67
|
if (isArray(instances.get(this))) {
|
|
58
|
-
|
|
68
|
+
for (const [, instance] of instances.get(this)) {
|
|
59
69
|
instance.$destroy();
|
|
60
|
-
}
|
|
70
|
+
}
|
|
61
71
|
}
|
|
62
72
|
return super.$destroy();
|
|
63
73
|
}
|
|
@@ -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
|
|
5
|
-
"mappings": "AAEA,SAAS,iBAAiB;AAC1B,SAAS,OAAO,eAAe;AAK/B,SAAS,gBAAgB,aAAsC;AAC7D,QAAM,EAAE,WAAW,IAAI,UAAU,EAAE,MAAM;AACzC,
|
|
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 // @see https://js-toolkit.meta.fr/services/resize.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 $mount(): this {\n 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 $destroy(): this {\n if (isArray(instances.get(this))) {\n for (const [, instance] of instances.get(this)) {\n instance.$destroy();\n }\n }\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,QA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AI,qBAAqB,KAAK,GAAG,IAAI,MAAM;AACzC,wBAAgB,UAAU,IAAI,IAAI,CAAC;AAAA,MACrC,CAAC;AAAA,IACH;AAAA;AAAA;AAAA;AAAA;AAAA,IAMA,SAAe;AACb,YAAM,OAAO;AAEb,sBAAgB,UAAU,IAAI,IAAI,CAAC;AAEnC,aAAO;AAAA,IACT;AAAA;AAAA;AAAA;AAAA,IAKA,WAAiB;AACf,UAAI,QAAQ,UAAU,IAAI,IAAI,CAAC,GAAG;AAChC,mBAAW,CAAC,EAAE,QAAQ,KAAK,UAAU,IAAI,IAAI,GAAG;AAC9C,mBAAS,SAAS;AAAA,QACpB;AAAA,MACF;AAEA,aAAO,MAAM,SAAS;AAAA,IACxB;AAAA,EACF;AAGA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useResize } from "../services/index.js";
|
|
2
|
-
import { isDev } from "../utils/index.js";
|
|
2
|
+
import { isDev, startsWith } from "../utils/index.js";
|
|
3
3
|
function testBreakpoints(instance, breakpoint = useResize().props().breakpoint) {
|
|
4
4
|
const { activeBreakpoints, inactiveBreakpoints } = instance.$options;
|
|
5
5
|
const isInActiveBreakpoint = activeBreakpoints && activeBreakpoints.split(" ").includes(breakpoint);
|
|
@@ -39,15 +39,21 @@ function addToResize(key, instance) {
|
|
|
39
39
|
}
|
|
40
40
|
function withBreakpointObserver(BaseClass) {
|
|
41
41
|
class WithBreakpointObserver extends BaseClass {
|
|
42
|
+
/**
|
|
43
|
+
* Config.
|
|
44
|
+
*/
|
|
42
45
|
static config = {
|
|
43
46
|
...BaseClass.config,
|
|
44
47
|
name: `${BaseClass.config.name}WithBreakpointObserver`,
|
|
45
48
|
options: {
|
|
46
|
-
...BaseClass.config?.options
|
|
49
|
+
...BaseClass.config?.options,
|
|
47
50
|
activeBreakpoints: String,
|
|
48
51
|
inactiveBreakpoints: String
|
|
49
52
|
}
|
|
50
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* Watch for the document resize to test the breakpoints.
|
|
56
|
+
*/
|
|
51
57
|
constructor(element) {
|
|
52
58
|
super(element);
|
|
53
59
|
const { remove, props } = useResize();
|
|
@@ -62,7 +68,7 @@ function withBreakpointObserver(BaseClass) {
|
|
|
62
68
|
}
|
|
63
69
|
const key = `BreakpointObserver-${this.$id}`;
|
|
64
70
|
const mutationObserver = new MutationObserver(([mutation]) => {
|
|
65
|
-
if (mutation.type === "attributes" && (mutation.attributeName === "data-options" || mutation.attributeName
|
|
71
|
+
if (mutation.type === "attributes" && (mutation.attributeName === "data-options" || startsWith(mutation.attributeName, "data-option-"))) {
|
|
66
72
|
if (!hasBreakpointConfiguration(this)) {
|
|
67
73
|
this.$mount();
|
|
68
74
|
remove(key);
|
|
@@ -77,6 +83,10 @@ function withBreakpointObserver(BaseClass) {
|
|
|
77
83
|
}
|
|
78
84
|
addToResize(key, this);
|
|
79
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Override the default $mount method to prevent component's from being
|
|
88
|
+
* mounted when they should not.
|
|
89
|
+
*/
|
|
80
90
|
$mount() {
|
|
81
91
|
if (!hasBreakpointConfiguration(this)) {
|
|
82
92
|
return super.$mount();
|
|
@@ -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 { isDev } from '../utils/index.js';\n\nexport interface WithBreakpointObserverProps extends BaseProps {\n $options: {\n activeBreakpoints?: string;\n inactiveBreakpoints?: string;\n };\n}\n\nexport interface WithBreakpointObserverInterface extends BaseInterface {\n $mount(): this;\n}\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 * @returns {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 * @returns {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 * @returns {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 * 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 } = useResize();\n\n if (!has(key)) {\n add(key, ({ 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/**\n * BreakpointObserver class.\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 name: `${BaseClass.config.name}WithBreakpointObserver`,\n options: {\n ...
|
|
5
|
-
"mappings": "AAEA,SAAS,iBAAiB;AAC1B,SAAS,
|
|
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 { isDev, startsWith } from '../utils/index.js';\n\nexport interface WithBreakpointObserverProps extends BaseProps {\n $options: {\n activeBreakpoints?: string;\n inactiveBreakpoints?: string;\n };\n}\n\nexport interface WithBreakpointObserverInterface extends BaseInterface {\n $mount(): this;\n}\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 * @returns {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 * @returns {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 * @returns {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 * 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 } = useResize();\n\n if (!has(key)) {\n add(key, ({ 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/**\n * BreakpointObserver class.\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 name: `${BaseClass.config.name}WithBreakpointObserver`,\n options: {\n ...BaseClass.config?.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 // @see https://js-toolkit.meta.fr/services/resize.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\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 (mutation.attributeName === 'data-options' ||\n startsWith(mutation.attributeName, 'data-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 $mount(): this {\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;AAC1B,SAAS,OAAO,kBAAkB;AAoBlC,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,mB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AACA;AAAA,MACF;AAEA,YAAM,MAAM,sBAAsB,KAAK,GAAG;AAG1C,YAAM,mBAAmB,IAAI,iBAAiB,CAAC,CAAC,QAAQ,MAAM;AAC5D,YACE,SAAS,SAAS,iBACjB,SAAS,kBAAkB,kBAC1B,WAAW,SAAS,eAAe,cAAc,IACnD;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,SAAe;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.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { useDrag } from "../services/index.js";
|
|
2
2
|
function withDrag(BaseClass, { target = (instance) => instance.$el, ...options } = {}) {
|
|
3
3
|
class WithDrag extends BaseClass {
|
|
4
|
+
/**
|
|
5
|
+
* Config.
|
|
6
|
+
*/
|
|
4
7
|
static config = {
|
|
5
8
|
name: `${BaseClass.config.name}WithDrag`,
|
|
6
9
|
emits: ["dragged"]
|
|
7
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Class constructor.
|
|
13
|
+
*/
|
|
8
14
|
constructor(element) {
|
|
9
15
|
super(element);
|
|
10
16
|
this.$on("mounted", () => {
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withDrag.ts"],
|
|
4
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/drag.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 name: `${BaseClass.config.name}WithDrag`,\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;AAajB,SAAS,SACd,WACA,EAAE,SAAS,CAAC,aAAa,SAAS,
|
|
5
|
+
"mappings": "AAGA,SAAS,eAAe;AAajB,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,MAAM,GAAG,UAAU,OAAO,IAAI;AAAA,MAC9B,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
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../packages/js-toolkit/decorators/withExtraConfig.ts"],
|
|
4
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;AAQX,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;AAAA,
|
|
5
|
+
"mappings": "AAAA,OAAO,WAAW;AAQX,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
|
}
|