@studiometa/js-toolkit 2.0.0-beta.8 → 2.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Base/index.cjs +285 -0
- package/Base/index.d.ts +11 -2
- package/Base/index.js +114 -197
- package/Base/managers/ChildrenManager.cjs +146 -0
- package/Base/managers/ChildrenManager.d.ts +9 -1
- package/Base/managers/ChildrenManager.js +60 -59
- package/Base/managers/EventsManager.cjs +183 -0
- package/Base/managers/EventsManager.js +72 -112
- package/Base/managers/OptionsManager.cjs +174 -0
- package/Base/managers/OptionsManager.d.ts +9 -5
- package/Base/managers/OptionsManager.js +60 -90
- package/Base/managers/RefsManager.cjs +99 -0
- package/Base/managers/RefsManager.js +30 -35
- package/Base/managers/ServicesManager.cjs +131 -0
- package/Base/managers/ServicesManager.js +39 -67
- package/Base/utils.cjs +41 -0
- package/Base/utils.js +12 -11
- package/README.md +13 -70
- package/decorators/index.cjs +45 -0
- package/decorators/index.d.ts +9 -9
- package/decorators/index.js +20 -9
- package/decorators/withBreakpointManager.cjs +85 -0
- package/decorators/withBreakpointManager.js +18 -39
- package/decorators/withBreakpointObserver.cjs +115 -0
- package/decorators/withBreakpointObserver.js +44 -86
- package/decorators/withDrag.cjs +53 -0
- package/decorators/withDrag.js +24 -26
- package/decorators/withExtraConfig.cjs +43 -0
- package/decorators/withExtraConfig.js +17 -12
- package/decorators/withFreezedOptions.cjs +37 -0
- package/decorators/withFreezedOptions.d.ts +14 -0
- package/decorators/withFreezedOptions.js +15 -0
- package/decorators/withIntersectionObserver.cjs +62 -0
- package/decorators/withIntersectionObserver.js +29 -32
- package/decorators/withMountWhenInView.cjs +69 -0
- package/decorators/withMountWhenInView.js +31 -52
- package/decorators/withScrolledInView.cjs +114 -0
- package/decorators/withScrolledInView.d.ts +2 -1
- package/decorators/withScrolledInView.js +35 -39
- package/decorators/withVue2.cjs +61 -0
- package/decorators/withVue2.js +27 -32
- package/helpers/createApp.cjs +52 -0
- package/helpers/createApp.d.ts +2 -2
- package/helpers/createApp.js +12 -12
- package/helpers/importOnInteraction.cjs +52 -0
- package/helpers/importOnInteraction.js +17 -18
- package/helpers/importWhenIdle.cjs +49 -0
- package/helpers/importWhenIdle.js +14 -17
- package/helpers/importWhenVisible.cjs +50 -0
- package/helpers/importWhenVisible.js +16 -18
- package/helpers/index.cjs +35 -0
- package/helpers/index.d.ts +4 -5
- package/helpers/index.js +10 -5
- package/helpers/utils.cjs +35 -0
- package/helpers/utils.js +7 -6
- package/index.cjs +33 -0
- package/index.d.ts +4 -21
- package/index.js +7 -5
- package/package.json +14 -4
- package/services/Service.cjs +76 -0
- package/services/Service.js +19 -32
- package/services/drag.cjs +213 -0
- package/services/drag.d.ts +1 -0
- package/services/drag.js +64 -68
- package/services/index.cjs +41 -0
- package/services/index.d.ts +7 -8
- package/services/index.js +16 -8
- package/services/key.cjs +104 -0
- package/services/key.js +28 -36
- package/services/load.cjs +72 -0
- package/services/load.js +17 -19
- package/services/pointer.cjs +162 -0
- package/services/pointer.js +43 -60
- package/services/raf.cjs +83 -0
- package/services/raf.js +20 -28
- package/services/resize.cjs +108 -0
- package/services/resize.js +33 -42
- package/services/scroll.cjs +131 -0
- package/services/scroll.js +26 -35
- package/utils/collide/boundingRectToCircle.cjs +34 -0
- package/utils/collide/boundingRectToCircle.d.ts +1 -1
- package/utils/collide/boundingRectToCircle.js +7 -10
- package/utils/collide/collideCircleCircle.cjs +34 -0
- package/utils/collide/collideCircleCircle.js +8 -7
- package/utils/collide/collideCircleRect.cjs +46 -0
- package/utils/collide/collideCircleRect.js +10 -12
- package/utils/collide/collidePointCircle.cjs +31 -0
- package/utils/collide/collidePointCircle.js +8 -5
- package/utils/collide/collidePointRect.cjs +28 -0
- package/utils/collide/collidePointRect.js +5 -2
- package/utils/collide/collideRectRect.cjs +28 -0
- package/utils/collide/collideRectRect.js +5 -2
- package/utils/collide/index.cjs +39 -0
- package/utils/collide/index.d.ts +6 -7
- package/utils/collide/index.js +14 -7
- package/utils/css/classes.cjs +47 -0
- package/utils/css/classes.d.ts +10 -9
- package/utils/css/classes.js +18 -14
- package/utils/css/index.cjs +38 -0
- package/utils/css/index.d.ts +4 -5
- package/utils/css/index.js +13 -5
- package/utils/css/matrix.cjs +30 -0
- package/utils/css/matrix.js +7 -5
- package/utils/css/styles.cjs +44 -0
- package/utils/css/styles.d.ts +6 -18
- package/utils/css/styles.js +12 -12
- package/utils/css/transition.cjs +120 -0
- package/utils/css/transition.d.ts +15 -9
- package/utils/css/transition.js +70 -119
- package/utils/debounce.cjs +34 -0
- package/utils/debounce.js +7 -9
- package/utils/focusTrap.cjs +82 -0
- package/utils/focusTrap.js +30 -21
- package/utils/history.cjs +89 -0
- package/utils/history.js +28 -57
- package/utils/index.cjs +54 -0
- package/utils/index.d.ts +14 -35
- package/utils/index.js +32 -17
- package/utils/keyCodes.cjs +35 -0
- package/utils/keyCodes.js +5 -2
- package/utils/math/clamp.cjs +28 -0
- package/utils/math/clamp.js +5 -2
- package/utils/math/clamp01.cjs +32 -0
- package/utils/math/clamp01.js +6 -3
- package/utils/math/damp.cjs +28 -0
- package/utils/math/damp.js +5 -4
- package/utils/math/ease.cjs +88 -0
- package/utils/math/ease.d.ts +78 -0
- package/utils/math/ease.js +66 -0
- package/utils/math/index.cjs +43 -0
- package/utils/math/index.d.ts +8 -8
- package/utils/math/index.js +17 -8
- package/utils/math/inertiaFinalValue.cjs +37 -0
- package/utils/math/inertiaFinalValue.js +8 -10
- package/utils/math/lerp.cjs +28 -0
- package/utils/math/lerp.js +5 -2
- package/utils/math/map.cjs +28 -0
- package/utils/math/map.js +5 -2
- package/utils/math/round.cjs +28 -0
- package/utils/math/round.js +5 -3
- package/utils/memoize.cjs +43 -0
- package/utils/memoize.js +10 -19
- package/utils/nextFrame.cjs +38 -0
- package/utils/nextFrame.d.ts +4 -3
- package/utils/nextFrame.js +13 -10
- package/utils/nextMicrotask.cjs +28 -0
- package/utils/nextMicrotask.d.ts +8 -0
- package/utils/nextMicrotask.js +6 -0
- package/utils/nextTick.cjs +30 -0
- package/utils/nextTick.d.ts +8 -0
- package/utils/nextTick.js +8 -0
- package/utils/object/autoBind.cjs +49 -0
- package/utils/object/autoBind.js +12 -22
- package/utils/object/getAllProperties.cjs +37 -0
- package/utils/object/getAllProperties.js +10 -13
- package/utils/object/index.cjs +33 -0
- package/utils/object/index.d.ts +3 -4
- package/utils/object/index.js +8 -4
- package/utils/object/isObject.cjs +28 -0
- package/utils/object/isObject.js +6 -3
- package/utils/scrollTo.cjs +80 -0
- package/utils/scrollTo.js +20 -40
- package/utils/string/index.cjs +47 -0
- package/utils/string/index.d.ts +10 -11
- package/utils/string/index.js +22 -11
- package/utils/string/withLeadingCharacters.cjs +32 -0
- package/utils/string/withLeadingCharacters.js +7 -4
- package/utils/string/withLeadingSlash.cjs +32 -0
- package/utils/string/withLeadingSlash.js +7 -4
- package/utils/string/withTrailingCharacters.cjs +32 -0
- package/utils/string/withTrailingCharacters.js +7 -4
- package/utils/string/withTrailingSlash.cjs +32 -0
- package/utils/string/withTrailingSlash.js +7 -4
- package/utils/string/withoutLeadingCharacters.cjs +28 -0
- package/utils/string/withoutLeadingCharacters.js +6 -3
- package/utils/string/withoutLeadingCharactersRecursive.cjs +37 -0
- package/utils/string/withoutLeadingCharactersRecursive.js +8 -7
- package/utils/string/withoutLeadingSlash.cjs +32 -0
- package/utils/string/withoutLeadingSlash.js +7 -4
- package/utils/string/withoutTrailingCharacters.cjs +28 -0
- package/utils/string/withoutTrailingCharacters.js +6 -3
- package/utils/string/withoutTrailingCharactersRecursive.cjs +37 -0
- package/utils/string/withoutTrailingCharactersRecursive.js +8 -7
- package/utils/string/withoutTrailingSlash.cjs +32 -0
- package/utils/string/withoutTrailingSlash.js +7 -4
- package/utils/throttle.cjs +36 -0
- package/utils/throttle.js +9 -9
- package/index.modern.js +0 -1
- package/index.umd.js +0 -1
package/utils/css/transition.js
CHANGED
|
@@ -1,145 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
import * as
|
|
10
|
-
|
|
11
|
-
var cache = new WeakMap();
|
|
12
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import nextFrame from "../nextFrame.js";
|
|
8
|
+
import * as classes from "./classes.js";
|
|
9
|
+
import * as styles from "./styles.js";
|
|
10
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
13
11
|
class Transition {
|
|
14
12
|
constructor(element) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
_defineProperty(this, "transitionEndHandler", null);
|
|
18
|
-
|
|
13
|
+
__publicField(this, "isTransitioning", false);
|
|
14
|
+
__publicField(this, "transitionEndHandler", null);
|
|
19
15
|
cache.set(element, this);
|
|
20
16
|
}
|
|
21
|
-
|
|
22
17
|
static getInstance(element) {
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
let instance = cache.get(element);
|
|
25
19
|
if (!instance) {
|
|
26
20
|
instance = new this(element);
|
|
27
21
|
}
|
|
28
|
-
|
|
29
22
|
return instance;
|
|
30
23
|
}
|
|
31
|
-
|
|
32
24
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (typeof classesOrStyles === 'string') {
|
|
38
|
-
classes[method](element, classesOrStyles, method);
|
|
25
|
+
function setClassesOrStyles(element, classesOrStyles, method = "add") {
|
|
26
|
+
if (typeof classesOrStyles === "string" || Array.isArray(classesOrStyles)) {
|
|
27
|
+
classes[method](element, classesOrStyles);
|
|
39
28
|
} else {
|
|
40
|
-
styles[method](element, classesOrStyles
|
|
29
|
+
styles[method](element, classesOrStyles);
|
|
41
30
|
}
|
|
42
31
|
}
|
|
43
|
-
|
|
44
32
|
function testTransition(element) {
|
|
45
|
-
if (typeof window ===
|
|
33
|
+
if (typeof window === "undefined") {
|
|
46
34
|
return false;
|
|
47
35
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
transitionDuration
|
|
51
|
-
} = window.getComputedStyle(element);
|
|
52
|
-
return !!transitionDuration && transitionDuration !== '0s';
|
|
36
|
+
const { transitionDuration } = window.getComputedStyle(element);
|
|
37
|
+
return !!transitionDuration && transitionDuration !== "0s";
|
|
53
38
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
39
|
+
async function start(element, classesOrStyles) {
|
|
40
|
+
const trs = Transition.getInstance(element);
|
|
41
|
+
trs.isTransitioning = true;
|
|
42
|
+
setClassesOrStyles(element, classesOrStyles.from);
|
|
43
|
+
await nextFrame();
|
|
44
|
+
setClassesOrStyles(element, classesOrStyles.active);
|
|
45
|
+
await nextFrame();
|
|
57
46
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return _next.apply(this, arguments);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function _next() {
|
|
76
|
-
_next = _asyncToGenerator(function* (element, classesOrStyles) {
|
|
77
|
-
var hasTransition = testTransition(element);
|
|
78
|
-
return new Promise(function () {
|
|
79
|
-
var _ref = _asyncToGenerator(function* (resolve) {
|
|
80
|
-
if (hasTransition) {
|
|
81
|
-
var trs = Transition.getInstance(element);
|
|
82
|
-
trs.transitionEndHandler = resolve;
|
|
83
|
-
element.addEventListener('transitionend', trs.transitionEndHandler, false);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
setClassesOrStyles(element, classesOrStyles.from, 'remove');
|
|
87
|
-
setClassesOrStyles(element, classesOrStyles.to);
|
|
88
|
-
yield nextFrame();
|
|
89
|
-
|
|
90
|
-
if (!hasTransition) {
|
|
91
|
-
resolve();
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
return function (_x7) {
|
|
96
|
-
return _ref.apply(this, arguments);
|
|
97
|
-
};
|
|
98
|
-
}());
|
|
47
|
+
async function next(element, classesOrStyles) {
|
|
48
|
+
const hasTransition = testTransition(element);
|
|
49
|
+
return new Promise(async (resolve) => {
|
|
50
|
+
if (hasTransition) {
|
|
51
|
+
const trs = Transition.getInstance(element);
|
|
52
|
+
trs.transitionEndHandler = resolve;
|
|
53
|
+
element.addEventListener("transitionend", trs.transitionEndHandler, false);
|
|
54
|
+
}
|
|
55
|
+
setClassesOrStyles(element, classesOrStyles.from, "remove");
|
|
56
|
+
setClassesOrStyles(element, classesOrStyles.to);
|
|
57
|
+
await nextFrame();
|
|
58
|
+
if (!hasTransition) {
|
|
59
|
+
resolve();
|
|
60
|
+
}
|
|
99
61
|
});
|
|
100
|
-
return _next.apply(this, arguments);
|
|
101
62
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (mode === 'remove') {
|
|
109
|
-
setClassesOrStyles(element, classesOrStyles.to, 'remove');
|
|
63
|
+
function end(element, classesOrStyles, mode = "remove") {
|
|
64
|
+
const trs = Transition.getInstance(element);
|
|
65
|
+
element.removeEventListener("transitionend", trs.transitionEndHandler, false);
|
|
66
|
+
if (mode === "remove") {
|
|
67
|
+
setClassesOrStyles(element, classesOrStyles.to, "remove");
|
|
110
68
|
}
|
|
111
|
-
|
|
112
|
-
setClassesOrStyles(element, classesOrStyles.active, 'remove');
|
|
69
|
+
setClassesOrStyles(element, classesOrStyles.active, "remove");
|
|
113
70
|
trs.isTransitioning = false;
|
|
114
71
|
trs.transitionEndHandler = null;
|
|
115
72
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
73
|
+
async function transition(element, name, endMode = "remove") {
|
|
74
|
+
const classesOrStyles = typeof name === "string" ? {
|
|
75
|
+
from: `${name}-from`,
|
|
76
|
+
active: `${name}-active`,
|
|
77
|
+
to: `${name}-to`
|
|
78
|
+
} : {
|
|
79
|
+
from: "",
|
|
80
|
+
active: "",
|
|
81
|
+
to: "",
|
|
82
|
+
...name
|
|
83
|
+
};
|
|
84
|
+
const trs = Transition.getInstance(element);
|
|
85
|
+
if (trs.isTransitioning) {
|
|
86
|
+
end(element, classesOrStyles);
|
|
87
|
+
}
|
|
88
|
+
await start(element, classesOrStyles);
|
|
89
|
+
await next(element, classesOrStyles);
|
|
90
|
+
end(element, classesOrStyles, endMode);
|
|
91
|
+
return Promise.resolve();
|
|
119
92
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
var classesOrStyles = typeof name === 'string' ? {
|
|
125
|
-
from: "".concat(name, "-from"),
|
|
126
|
-
active: "".concat(name, "-active"),
|
|
127
|
-
to: "".concat(name, "-to")
|
|
128
|
-
} : _objectSpread({
|
|
129
|
-
from: '',
|
|
130
|
-
active: '',
|
|
131
|
-
to: ''
|
|
132
|
-
}, name);
|
|
133
|
-
var trs = Transition.getInstance(element);
|
|
134
|
-
|
|
135
|
-
if (trs.isTransitioning) {
|
|
136
|
-
end(element, classesOrStyles);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
yield start(element, classesOrStyles);
|
|
140
|
-
yield next(element, classesOrStyles);
|
|
141
|
-
end(element, classesOrStyles, endMode);
|
|
142
|
-
return Promise.resolve();
|
|
143
|
-
});
|
|
144
|
-
return _transition.apply(this, arguments);
|
|
145
|
-
}
|
|
93
|
+
export {
|
|
94
|
+
transition as default,
|
|
95
|
+
setClassesOrStyles
|
|
96
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/js-toolkit/utils/debounce.js
|
|
20
|
+
var debounce_exports = {};
|
|
21
|
+
__export(debounce_exports, {
|
|
22
|
+
default: () => debounce
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(debounce_exports);
|
|
25
|
+
function debounce(fn, delay = 300) {
|
|
26
|
+
let timeout;
|
|
27
|
+
return function debounced(...args) {
|
|
28
|
+
clearTimeout(timeout);
|
|
29
|
+
timeout = setTimeout(() => {
|
|
30
|
+
fn(...args);
|
|
31
|
+
}, delay);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (module.exports.default) module.exports = module.exports.default;
|
package/utils/debounce.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return function debounced() {
|
|
5
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
6
|
-
args[_key] = arguments[_key];
|
|
7
|
-
}
|
|
8
|
-
|
|
1
|
+
function debounce(fn, delay = 300) {
|
|
2
|
+
let timeout;
|
|
3
|
+
return function debounced(...args) {
|
|
9
4
|
clearTimeout(timeout);
|
|
10
5
|
timeout = setTimeout(() => {
|
|
11
6
|
fn(...args);
|
|
12
7
|
}, delay);
|
|
13
8
|
};
|
|
14
|
-
}
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
debounce as default
|
|
12
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// packages/js-toolkit/utils/focusTrap.js
|
|
23
|
+
var focusTrap_exports = {};
|
|
24
|
+
__export(focusTrap_exports, {
|
|
25
|
+
default: () => useFocusTrap,
|
|
26
|
+
saveActiveElement: () => saveActiveElement,
|
|
27
|
+
trap: () => trap,
|
|
28
|
+
untrap: () => untrap
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(focusTrap_exports);
|
|
31
|
+
var import_keyCodes = __toESM(require("./keyCodes.cjs"), 1);
|
|
32
|
+
var FOCUSABLE_ELEMENTS = [
|
|
33
|
+
'a[href]:not([tabindex^="-"]):not([inert])',
|
|
34
|
+
'area[href]:not([tabindex^="-"]):not([inert])',
|
|
35
|
+
"input:not([disabled]):not([inert])",
|
|
36
|
+
"select:not([disabled]):not([inert])",
|
|
37
|
+
"textarea:not([disabled]):not([inert])",
|
|
38
|
+
"button:not([disabled]):not([inert])",
|
|
39
|
+
'iframe:not([tabindex^="-"]):not([inert])',
|
|
40
|
+
'audio:not([tabindex^="-"]):not([inert])',
|
|
41
|
+
'video:not([tabindex^="-"]):not([inert])',
|
|
42
|
+
'[contenteditable]:not([tabindex^="-"]):not([inert])',
|
|
43
|
+
'[tabindex]:not([tabindex^="-"]):not([inert])'
|
|
44
|
+
];
|
|
45
|
+
var focusedBefore;
|
|
46
|
+
function saveActiveElement() {
|
|
47
|
+
focusedBefore = document.activeElement;
|
|
48
|
+
}
|
|
49
|
+
function trap(element, event) {
|
|
50
|
+
if (event.keyCode !== import_keyCodes.default.TAB) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (!focusedBefore) {
|
|
54
|
+
focusedBefore = document.activeElement;
|
|
55
|
+
}
|
|
56
|
+
const focusableChildren = Array.from(element.querySelectorAll(FOCUSABLE_ELEMENTS.join(", ")));
|
|
57
|
+
const focusedItemIndex = document.activeElement instanceof HTMLElement ? focusableChildren.indexOf(document.activeElement) : -1;
|
|
58
|
+
if (!focusableChildren.length) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (focusedItemIndex < 0) {
|
|
62
|
+
focusableChildren[0].focus();
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
}
|
|
65
|
+
if (event.shiftKey && focusedItemIndex === 0) {
|
|
66
|
+
focusableChildren[focusableChildren.length - 1].focus();
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
} else if (!event.shiftKey && focusedItemIndex === focusableChildren.length - 1) {
|
|
69
|
+
focusableChildren[0].focus();
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function untrap() {
|
|
74
|
+
if (focusedBefore && typeof focusedBefore.focus === "function") {
|
|
75
|
+
focusedBefore.focus();
|
|
76
|
+
focusedBefore = null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function useFocusTrap() {
|
|
80
|
+
return { trap, untrap, saveActiveElement };
|
|
81
|
+
}
|
|
82
|
+
if (module.exports.default) module.exports = module.exports.default;
|
package/utils/focusTrap.js
CHANGED
|
@@ -1,30 +1,37 @@
|
|
|
1
|
-
import keyCodes from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import keyCodes from "./keyCodes.js";
|
|
2
|
+
const FOCUSABLE_ELEMENTS = [
|
|
3
|
+
'a[href]:not([tabindex^="-"]):not([inert])',
|
|
4
|
+
'area[href]:not([tabindex^="-"]):not([inert])',
|
|
5
|
+
"input:not([disabled]):not([inert])",
|
|
6
|
+
"select:not([disabled]):not([inert])",
|
|
7
|
+
"textarea:not([disabled]):not([inert])",
|
|
8
|
+
"button:not([disabled]):not([inert])",
|
|
9
|
+
'iframe:not([tabindex^="-"]):not([inert])',
|
|
10
|
+
'audio:not([tabindex^="-"]):not([inert])',
|
|
11
|
+
'video:not([tabindex^="-"]):not([inert])',
|
|
12
|
+
'[contenteditable]:not([tabindex^="-"]):not([inert])',
|
|
13
|
+
'[tabindex]:not([tabindex^="-"]):not([inert])'
|
|
14
|
+
];
|
|
15
|
+
let focusedBefore;
|
|
16
|
+
function saveActiveElement() {
|
|
5
17
|
focusedBefore = document.activeElement;
|
|
6
18
|
}
|
|
7
|
-
|
|
19
|
+
function trap(element, event) {
|
|
8
20
|
if (event.keyCode !== keyCodes.TAB) {
|
|
9
21
|
return;
|
|
10
22
|
}
|
|
11
|
-
|
|
12
23
|
if (!focusedBefore) {
|
|
13
24
|
focusedBefore = document.activeElement;
|
|
14
25
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var focusedItemIndex = document.activeElement instanceof HTMLElement ? focusableChildren.indexOf(document.activeElement) : -1;
|
|
18
|
-
|
|
26
|
+
const focusableChildren = Array.from(element.querySelectorAll(FOCUSABLE_ELEMENTS.join(", ")));
|
|
27
|
+
const focusedItemIndex = document.activeElement instanceof HTMLElement ? focusableChildren.indexOf(document.activeElement) : -1;
|
|
19
28
|
if (!focusableChildren.length) {
|
|
20
29
|
return;
|
|
21
30
|
}
|
|
22
|
-
|
|
23
31
|
if (focusedItemIndex < 0) {
|
|
24
32
|
focusableChildren[0].focus();
|
|
25
33
|
event.preventDefault();
|
|
26
34
|
}
|
|
27
|
-
|
|
28
35
|
if (event.shiftKey && focusedItemIndex === 0) {
|
|
29
36
|
focusableChildren[focusableChildren.length - 1].focus();
|
|
30
37
|
event.preventDefault();
|
|
@@ -33,16 +40,18 @@ export function trap(element, event) {
|
|
|
33
40
|
event.preventDefault();
|
|
34
41
|
}
|
|
35
42
|
}
|
|
36
|
-
|
|
37
|
-
if (focusedBefore && typeof focusedBefore.focus ===
|
|
43
|
+
function untrap() {
|
|
44
|
+
if (focusedBefore && typeof focusedBefore.focus === "function") {
|
|
38
45
|
focusedBefore.focus();
|
|
39
46
|
focusedBefore = null;
|
|
40
47
|
}
|
|
41
48
|
}
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
function useFocusTrap() {
|
|
50
|
+
return { trap, untrap, saveActiveElement };
|
|
51
|
+
}
|
|
52
|
+
export {
|
|
53
|
+
useFocusTrap as default,
|
|
54
|
+
saveActiveElement,
|
|
55
|
+
trap,
|
|
56
|
+
untrap
|
|
57
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
|
|
22
|
+
// packages/js-toolkit/utils/history.js
|
|
23
|
+
var history_exports = {};
|
|
24
|
+
__export(history_exports, {
|
|
25
|
+
objectToURLSearchParams: () => objectToURLSearchParams,
|
|
26
|
+
push: () => push,
|
|
27
|
+
replace: () => replace
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(history_exports);
|
|
30
|
+
var import_isObject = __toESM(require("./object/isObject.cjs"), 1);
|
|
31
|
+
function updateUrlSearchParam(params, name, value) {
|
|
32
|
+
if (value === "" || value === null || value === void 0) {
|
|
33
|
+
if (params.has(name)) {
|
|
34
|
+
params.delete(name);
|
|
35
|
+
}
|
|
36
|
+
return params;
|
|
37
|
+
}
|
|
38
|
+
if (Array.isArray(value)) {
|
|
39
|
+
value.forEach((val, index) => {
|
|
40
|
+
const arrayName = `${name}[${index}]`;
|
|
41
|
+
updateUrlSearchParam(params, arrayName, val);
|
|
42
|
+
});
|
|
43
|
+
return params;
|
|
44
|
+
}
|
|
45
|
+
if ((0, import_isObject.default)(value)) {
|
|
46
|
+
Object.entries(value).forEach(([key, val]) => {
|
|
47
|
+
const objectName = `${name}[${key}]`;
|
|
48
|
+
updateUrlSearchParam(params, objectName, val);
|
|
49
|
+
});
|
|
50
|
+
return params;
|
|
51
|
+
}
|
|
52
|
+
params.set(name, value);
|
|
53
|
+
return params;
|
|
54
|
+
}
|
|
55
|
+
function objectToURLSearchParams(obj, defaultSearch = typeof window === "undefined" ? "" : window.location.search) {
|
|
56
|
+
return Object.entries(obj).reduce((urlSearchParams, [name, value]) => updateUrlSearchParam(urlSearchParams, name, value), new URLSearchParams(defaultSearch));
|
|
57
|
+
}
|
|
58
|
+
function updateHistory(mode, options, data = {}, title = "") {
|
|
59
|
+
if (!window.history) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const { path, search, hash } = {
|
|
63
|
+
path: window.location.pathname,
|
|
64
|
+
search: new URLSearchParams(window.location.search),
|
|
65
|
+
hash: window.location.hash,
|
|
66
|
+
...options
|
|
67
|
+
};
|
|
68
|
+
let url = path;
|
|
69
|
+
const mergedSearch = search instanceof URLSearchParams ? search : objectToURLSearchParams(search);
|
|
70
|
+
if (mergedSearch.toString()) {
|
|
71
|
+
url += `?${mergedSearch.toString()}`;
|
|
72
|
+
}
|
|
73
|
+
if (hash) {
|
|
74
|
+
if (hash.startsWith("#")) {
|
|
75
|
+
url += hash;
|
|
76
|
+
} else {
|
|
77
|
+
url += `#${hash}`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const method = `${mode}State`;
|
|
81
|
+
window.history[method](data, title, url);
|
|
82
|
+
}
|
|
83
|
+
function push(options, data = {}, title = "") {
|
|
84
|
+
updateHistory("push", options, data, title);
|
|
85
|
+
}
|
|
86
|
+
function replace(options, data = {}, title = "") {
|
|
87
|
+
updateHistory("replace", options, data, title);
|
|
88
|
+
}
|
|
89
|
+
if (module.exports.default) module.exports = module.exports.default;
|
package/utils/history.js
CHANGED
|
@@ -1,93 +1,64 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
-
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
-
|
|
7
|
-
import isObject from './object/isObject.js';
|
|
8
|
-
|
|
1
|
+
import isObject from "./object/isObject.js";
|
|
9
2
|
function updateUrlSearchParam(params, name, value) {
|
|
10
|
-
if (value ===
|
|
3
|
+
if (value === "" || value === null || value === void 0) {
|
|
11
4
|
if (params.has(name)) {
|
|
12
5
|
params.delete(name);
|
|
13
6
|
}
|
|
14
|
-
|
|
15
7
|
return params;
|
|
16
8
|
}
|
|
17
|
-
|
|
18
9
|
if (Array.isArray(value)) {
|
|
19
10
|
value.forEach((val, index) => {
|
|
20
|
-
|
|
11
|
+
const arrayName = `${name}[${index}]`;
|
|
21
12
|
updateUrlSearchParam(params, arrayName, val);
|
|
22
13
|
});
|
|
23
14
|
return params;
|
|
24
15
|
}
|
|
25
|
-
|
|
26
16
|
if (isObject(value)) {
|
|
27
|
-
Object.entries(value).forEach(
|
|
28
|
-
|
|
29
|
-
var objectName = "".concat(name, "[").concat(key, "]");
|
|
17
|
+
Object.entries(value).forEach(([key, val]) => {
|
|
18
|
+
const objectName = `${name}[${key}]`;
|
|
30
19
|
updateUrlSearchParam(params, objectName, val);
|
|
31
20
|
});
|
|
32
21
|
return params;
|
|
33
22
|
}
|
|
34
|
-
|
|
35
23
|
params.set(name, value);
|
|
36
24
|
return params;
|
|
37
25
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var defaultSearch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : typeof window === 'undefined' ? '' : window.location.search;
|
|
41
|
-
return Object.entries(obj).reduce((urlSearchParams, _ref2) => {
|
|
42
|
-
var [name, value] = _ref2;
|
|
43
|
-
return updateUrlSearchParam(urlSearchParams, name, value);
|
|
44
|
-
}, new URLSearchParams(defaultSearch));
|
|
26
|
+
function objectToURLSearchParams(obj, defaultSearch = typeof window === "undefined" ? "" : window.location.search) {
|
|
27
|
+
return Object.entries(obj).reduce((urlSearchParams, [name, value]) => updateUrlSearchParam(urlSearchParams, name, value), new URLSearchParams(defaultSearch));
|
|
45
28
|
}
|
|
46
|
-
|
|
47
|
-
function updateHistory(mode, options) {
|
|
48
|
-
var data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
49
|
-
var title = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
|
|
50
|
-
|
|
29
|
+
function updateHistory(mode, options, data = {}, title = "") {
|
|
51
30
|
if (!window.history) {
|
|
52
31
|
return;
|
|
53
32
|
}
|
|
54
|
-
|
|
55
|
-
var {
|
|
56
|
-
path,
|
|
57
|
-
search,
|
|
58
|
-
hash
|
|
59
|
-
} = _objectSpread({
|
|
33
|
+
const { path, search, hash } = {
|
|
60
34
|
path: window.location.pathname,
|
|
61
35
|
search: new URLSearchParams(window.location.search),
|
|
62
|
-
hash: window.location.hash
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
36
|
+
hash: window.location.hash,
|
|
37
|
+
...options
|
|
38
|
+
};
|
|
39
|
+
let url = path;
|
|
40
|
+
const mergedSearch = search instanceof URLSearchParams ? search : objectToURLSearchParams(search);
|
|
68
41
|
if (mergedSearch.toString()) {
|
|
69
|
-
url +=
|
|
42
|
+
url += `?${mergedSearch.toString()}`;
|
|
70
43
|
}
|
|
71
|
-
|
|
72
44
|
if (hash) {
|
|
73
|
-
if (hash.startsWith(
|
|
45
|
+
if (hash.startsWith("#")) {
|
|
74
46
|
url += hash;
|
|
75
47
|
} else {
|
|
76
|
-
url +=
|
|
48
|
+
url += `#${hash}`;
|
|
77
49
|
}
|
|
78
50
|
}
|
|
79
|
-
|
|
80
|
-
var method = "".concat(mode, "State");
|
|
51
|
+
const method = `${mode}State`;
|
|
81
52
|
window.history[method](data, title, url);
|
|
82
53
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
86
|
-
var title = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
87
|
-
updateHistory('push', options, data, title);
|
|
54
|
+
function push(options, data = {}, title = "") {
|
|
55
|
+
updateHistory("push", options, data, title);
|
|
88
56
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
57
|
+
function replace(options, data = {}, title = "") {
|
|
58
|
+
updateHistory("replace", options, data, title);
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
objectToURLSearchParams,
|
|
62
|
+
push,
|
|
63
|
+
replace
|
|
64
|
+
};
|