svelte-ag 1.0.11 → 1.0.13
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/dist/lib/api/form.svelte.js +36 -96
- package/dist/lib/api/query/cache.svelte.js +27 -48
- package/dist/lib/api/query/entrypoint.svelte.js +10 -11
- package/dist/lib/api/query/query.svelte.js +134 -252
- package/dist/lib/api/query/utils.svelte.js +2 -2
- package/dist/lib/bits/internal/arrays.d.ts +1 -1
- package/dist/lib/bits/internal/arrays.d.ts.map +1 -1
- package/dist/lib/bits/internal/arrays.js +34 -39
- package/dist/lib/bits/internal/arrays.test.js +118 -118
- package/dist/lib/bits/internal/box-auto-reset.svelte.js +7 -9
- package/dist/lib/bits/internal/box.svelte.js +10 -11
- package/dist/lib/bits/internal/clamp.test.js +7 -7
- package/dist/lib/bits/internal/create-event-hook.svelte.js +11 -15
- package/dist/lib/bits/internal/create-shared-hook.svelte.js +8 -12
- package/dist/lib/bits/internal/date-time/announcer.d.ts +1 -1
- package/dist/lib/bits/internal/date-time/announcer.js +13 -15
- package/dist/lib/bits/internal/date-time/calendar-helpers.svelte.js +145 -180
- package/dist/lib/bits/internal/date-time/field/helpers.js +61 -78
- package/dist/lib/bits/internal/date-time/field/parts.js +6 -15
- package/dist/lib/bits/internal/date-time/field/segments.d.ts +4 -4
- package/dist/lib/bits/internal/date-time/field/segments.d.ts.map +1 -1
- package/dist/lib/bits/internal/date-time/field/segments.js +15 -15
- package/dist/lib/bits/internal/date-time/formatter.js +26 -39
- package/dist/lib/bits/internal/date-time/placeholders.js +4 -4
- package/dist/lib/bits/internal/date-time/utils.js +21 -33
- package/dist/lib/bits/internal/debounce.js +6 -11
- package/dist/lib/bits/internal/debounce.test.js +47 -134
- package/dist/lib/bits/internal/dom.d.ts +3 -3
- package/dist/lib/bits/internal/dom.d.ts.map +1 -1
- package/dist/lib/bits/internal/dom.js +6 -9
- package/dist/lib/bits/internal/elements.js +1 -2
- package/dist/lib/bits/internal/events.js +21 -30
- package/dist/lib/bits/internal/floating-svelte/floating-utils.svelte.js +9 -10
- package/dist/lib/bits/internal/floating-svelte/use-floating.svelte.js +32 -40
- package/dist/lib/bits/internal/focus.d.ts +5 -5
- package/dist/lib/bits/internal/focus.d.ts.map +1 -1
- package/dist/lib/bits/internal/focus.js +18 -22
- package/dist/lib/bits/internal/get-directional-keys.js +7 -22
- package/dist/lib/bits/internal/get-directional-keys.test.js +12 -12
- package/dist/lib/bits/internal/is.d.ts +1 -1
- package/dist/lib/bits/internal/is.d.ts.map +1 -1
- package/dist/lib/bits/internal/is.js +4 -5
- package/dist/lib/bits/internal/is.test.js +7 -7
- package/dist/lib/bits/internal/kbd-constants.js +40 -40
- package/dist/lib/bits/internal/locale.js +2 -2
- package/dist/lib/bits/internal/math.js +12 -13
- package/dist/lib/bits/internal/math.test.js +20 -20
- package/dist/lib/bits/internal/should-trap-focus.js +1 -2
- package/dist/lib/bits/internal/sleep.js +1 -1
- package/dist/lib/bits/internal/tabbable.js +11 -12
- package/dist/lib/bits/internal/use-after-animations.svelte.js +6 -6
- package/dist/lib/bits/internal/use-arrow-navigation.js +19 -21
- package/dist/lib/bits/internal/use-body-scroll-lock.svelte.d.ts +1 -1
- package/dist/lib/bits/internal/use-body-scroll-lock.svelte.d.ts.map +1 -1
- package/dist/lib/bits/internal/use-body-scroll-lock.svelte.js +36 -40
- package/dist/lib/bits/internal/use-data-typeahead.svelte.d.ts +1 -1
- package/dist/lib/bits/internal/use-data-typeahead.svelte.js +10 -11
- package/dist/lib/bits/internal/use-dom-typeahead.svelte.d.ts +1 -1
- package/dist/lib/bits/internal/use-dom-typeahead.svelte.js +11 -13
- package/dist/lib/bits/internal/use-form-control.svelte.js +2 -2
- package/dist/lib/bits/internal/use-grace-area.svelte.js +47 -60
- package/dist/lib/bits/internal/use-id.js +3 -5
- package/dist/lib/bits/internal/use-resize-observer.svelte.js +5 -5
- package/dist/lib/bits/internal/use-roving-focus.svelte.d.ts +2 -2
- package/dist/lib/bits/internal/use-roving-focus.svelte.js +32 -36
- package/dist/lib/bits/internal/use-size.svelte.d.ts +1 -1
- package/dist/lib/bits/internal/use-size.svelte.js +12 -12
- package/dist/lib/bits/internal/use-state-machine.svelte.js +6 -6
- package/dist/lib/bits/internal/use-timeout-fn.svelte.js +10 -15
- package/dist/lib/components/animated/animated.svelte.d.ts +1 -1
- package/dist/lib/components/animated/animated.svelte.d.ts.map +1 -1
- package/dist/lib/components/carousel/carousel-dots.svelte.d.ts +6 -1
- package/dist/lib/components/carousel/carousel-dots.svelte.d.ts.map +1 -1
- package/dist/lib/components/carousel/carousel-next.svelte.d.ts +21 -1
- package/dist/lib/components/carousel/carousel-next.svelte.d.ts.map +1 -1
- package/dist/lib/components/carousel/carousel-previous.svelte.d.ts +21 -1
- package/dist/lib/components/carousel/carousel-previous.svelte.d.ts.map +1 -1
- package/dist/lib/components/carousel/context.js +4 -7
- package/dist/lib/components/dnd/context.svelte.js +2 -2
- package/dist/lib/components/dnd/default.svelte.js +9 -15
- package/dist/lib/components/dnd/dnd-item.svelte.d.ts +20 -1
- package/dist/lib/components/dnd/dnd-item.svelte.d.ts.map +1 -1
- package/dist/lib/components/dnd/dnd-sortable-context.svelte.d.ts +5 -1
- package/dist/lib/components/dnd/dnd-sortable-context.svelte.d.ts.map +1 -1
- package/dist/lib/components/dnd/dnd-sortable-item.svelte.d.ts +3 -1
- package/dist/lib/components/dnd/dnd-sortable-item.svelte.d.ts.map +1 -1
- package/dist/lib/components/dnd/sortable.svelte.js +26 -29
- package/dist/lib/components/dnd/utils.svelte.d.ts +1 -1
- package/dist/lib/components/dnd/utils.svelte.js +6 -7
- package/dist/lib/components/form/form-message.svelte.d.ts +2 -1
- package/dist/lib/components/form/form-message.svelte.d.ts.map +1 -1
- package/dist/lib/components/gallery/gallery.svelte.d.ts +21 -1
- package/dist/lib/components/gallery/gallery.svelte.d.ts.map +1 -1
- package/dist/lib/components/gallery/utils.js +20 -24
- package/dist/lib/components/safe/safe.svelte.d.ts +1 -1
- package/dist/lib/components/safe/safe.svelte.d.ts.map +1 -1
- package/dist/lib/components/search/combinations/searchPopover.svelte.d.ts +2 -2
- package/dist/lib/components/search/search.svelte.d.ts +1 -1
- package/dist/lib/components/search/search.svelte.d.ts.map +1 -1
- package/dist/lib/components/search/search.svelte.js +135 -228
- package/dist/lib/components/sidebar/constants.js +6 -6
- package/dist/lib/components/sidebar/context.svelte.d.ts +1 -1
- package/dist/lib/components/sidebar/context.svelte.d.ts.map +1 -1
- package/dist/lib/components/sidebar/context.svelte.js +33 -51
- package/dist/lib/components/sidebar/sidebar-input.svelte.d.ts +9 -1
- package/dist/lib/components/sidebar/sidebar-input.svelte.d.ts.map +1 -1
- package/dist/lib/components/sidebar/sidebar-menu-button.svelte.d.ts +2 -2
- package/dist/lib/components/sidebar/sidebar-menu-button.svelte.d.ts.map +1 -1
- package/dist/lib/components/sidebar/sidebar-trigger.svelte.d.ts +7 -1
- package/dist/lib/components/sidebar/sidebar-trigger.svelte.d.ts.map +1 -1
- package/dist/lib/components/utilities/floating-layer/components/floating-layer-arrow.svelte.d.ts +1 -1
- package/dist/lib/components/utilities/floating-layer/components/floating-layer-arrow.svelte.d.ts.map +1 -1
- package/dist/lib/components/utilities/floating-layer/use-floating-layer.svelte.d.ts +18 -18
- package/dist/lib/components/utilities/floating-layer/use-floating-layer.svelte.d.ts.map +1 -1
- package/dist/lib/components/utilities/floating-layer/use-floating-layer.svelte.js +210 -243
- package/dist/lib/utils/asyncDerived.svelte.js +4 -4
- package/dist/lib/utils/bits.d.ts +11 -11
- package/dist/lib/utils/bits.d.ts.map +1 -1
- package/dist/lib/utils/reactive.svelte.js +3 -3
- package/dist/lib/utils/utils.d.ts +2 -2
- package/dist/lib/utils/utils.js +45 -45
- package/dist/lib/vite/vite-plugin-component-source-collector.js +73 -187
- package/dist/routes/+layout.svelte.d.ts +1 -1
- package/package.json +2 -1
|
@@ -1,65 +1,65 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import { arraysAreEqual, backward, chunk, forward, getNextMatch, isValidIndex, next, prev, wrapArray } from './arrays.js';
|
|
3
|
-
describe('arraysAreEqual',
|
|
4
|
-
it('should return true for two empty arrays',
|
|
3
|
+
describe('arraysAreEqual', () => {
|
|
4
|
+
it('should return true for two empty arrays', () => {
|
|
5
5
|
expect(arraysAreEqual([], [])).toBe(true);
|
|
6
6
|
});
|
|
7
|
-
it('should return true for two arrays with the same elements in the same order',
|
|
7
|
+
it('should return true for two arrays with the same elements in the same order', () => {
|
|
8
8
|
expect(arraysAreEqual([1, 2, 3], [1, 2, 3])).toBe(true);
|
|
9
9
|
});
|
|
10
|
-
it('should return false for two arrays with different lengths',
|
|
10
|
+
it('should return false for two arrays with different lengths', () => {
|
|
11
11
|
expect(arraysAreEqual([1, 2, 3], [1, 2])).toBe(false);
|
|
12
12
|
});
|
|
13
|
-
it('should return false for two arrays with different elements',
|
|
13
|
+
it('should return false for two arrays with different elements', () => {
|
|
14
14
|
expect(arraysAreEqual([1, 2, 3], [1, 2, 4])).toBe(false);
|
|
15
15
|
});
|
|
16
|
-
it('should return false for two arrays with elements in different orders',
|
|
16
|
+
it('should return false for two arrays with elements in different orders', () => {
|
|
17
17
|
expect(arraysAreEqual([1, 2, 3], [3, 2, 1])).toBe(false);
|
|
18
18
|
});
|
|
19
|
-
it('should handle arrays with non-primitive values',
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
it('should handle arrays with non-primitive values', () => {
|
|
20
|
+
const obj1 = { foo: 'bar' };
|
|
21
|
+
const obj2 = { foo: 'bar' };
|
|
22
22
|
expect(arraysAreEqual([obj1], [obj2])).toBe(true);
|
|
23
23
|
});
|
|
24
|
-
it('should handle arrays with different non-primitive values',
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
it('should handle arrays with different non-primitive values', () => {
|
|
25
|
+
const obj1 = { foo: 'baz' };
|
|
26
|
+
const obj2 = { foo: 'bar' };
|
|
27
27
|
expect(arraysAreEqual([obj1], [obj2])).toBe(false);
|
|
28
28
|
});
|
|
29
|
-
it('should handle nested arrays',
|
|
29
|
+
it('should handle nested arrays', () => {
|
|
30
30
|
expect(arraysAreEqual([1, [2, 3]], [1, [2, 3]])).toBe(true);
|
|
31
31
|
expect(arraysAreEqual([1, [2, 3]], [1, [3, 2]])).toBe(false);
|
|
32
32
|
});
|
|
33
|
-
it('should handle arrays with different types of elements',
|
|
33
|
+
it('should handle arrays with different types of elements', () => {
|
|
34
34
|
expect(arraysAreEqual([1, '2', true], [1, '2', true])).toBe(true);
|
|
35
35
|
expect(arraysAreEqual([1, '2', true], [1, 2, true])).toBe(false);
|
|
36
36
|
});
|
|
37
|
-
it('should handle sparse arrays',
|
|
37
|
+
it('should handle sparse arrays', () => {
|
|
38
38
|
// eslint-disable-next-line no-sparse-arrays
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
const arr1 = [1, , 3];
|
|
40
|
+
const arr2 = [1, undefined, 3];
|
|
41
41
|
expect(arraysAreEqual(arr1, arr2)).toBe(true);
|
|
42
42
|
});
|
|
43
|
-
it('should handle NaN values',
|
|
43
|
+
it('should handle NaN values', () => {
|
|
44
44
|
expect(arraysAreEqual([Number.NaN], [Number.NaN])).toBe(true);
|
|
45
45
|
});
|
|
46
46
|
});
|
|
47
|
-
describe('chunk',
|
|
48
|
-
it('should return an empty array when given an empty array',
|
|
47
|
+
describe('chunk', () => {
|
|
48
|
+
it('should return an empty array when given an empty array', () => {
|
|
49
49
|
expect(chunk([], 2)).toEqual([]);
|
|
50
50
|
});
|
|
51
|
-
it('should return an array with one chunk when size is greater than or equal to array length',
|
|
51
|
+
it('should return an array with one chunk when size is greater than or equal to array length', () => {
|
|
52
52
|
expect(chunk([1, 2, 3], 3)).toEqual([[1, 2, 3]]);
|
|
53
53
|
expect(chunk([1, 2, 3], 4)).toEqual([[1, 2, 3]]);
|
|
54
54
|
});
|
|
55
|
-
it('should chunk the array into arrays of the specified size',
|
|
55
|
+
it('should chunk the array into arrays of the specified size', () => {
|
|
56
56
|
expect(chunk([1, 2, 3, 4], 2)).toEqual([
|
|
57
57
|
[1, 2],
|
|
58
58
|
[3, 4]
|
|
59
59
|
]);
|
|
60
60
|
expect(chunk([1, 2, 3, 4, 5], 2)).toEqual([[1, 2], [3, 4], [5]]);
|
|
61
61
|
});
|
|
62
|
-
it('should work with arrays containing different types',
|
|
62
|
+
it('should work with arrays containing different types', () => {
|
|
63
63
|
expect(chunk(['a', 'b', 'c', 'd'], 2)).toEqual([
|
|
64
64
|
['a', 'b'],
|
|
65
65
|
['c', 'd']
|
|
@@ -69,275 +69,275 @@ describe('chunk', function () {
|
|
|
69
69
|
[true, null]
|
|
70
70
|
]);
|
|
71
71
|
});
|
|
72
|
-
it('should handle negative or zero size',
|
|
72
|
+
it('should handle negative or zero size', () => {
|
|
73
73
|
expect(chunk([1, 2, 3, 4], 0)).toEqual([]);
|
|
74
74
|
expect(chunk([1, 2, 3, 4], -1)).toEqual([]);
|
|
75
75
|
});
|
|
76
76
|
});
|
|
77
|
-
describe('isValidIndex',
|
|
78
|
-
it('should return true for valid indices',
|
|
79
|
-
|
|
77
|
+
describe('isValidIndex', () => {
|
|
78
|
+
it('should return true for valid indices', () => {
|
|
79
|
+
const arr = [1, 2, 3, 4, 5];
|
|
80
80
|
expect(isValidIndex(0, arr)).toBe(true);
|
|
81
81
|
expect(isValidIndex(2, arr)).toBe(true);
|
|
82
82
|
expect(isValidIndex(4, arr)).toBe(true);
|
|
83
83
|
});
|
|
84
|
-
it('should return false for indices outside the array bounds',
|
|
85
|
-
|
|
84
|
+
it('should return false for indices outside the array bounds', () => {
|
|
85
|
+
const arr = [1, 2, 3, 4, 5];
|
|
86
86
|
expect(isValidIndex(-1, arr)).toBe(false);
|
|
87
87
|
expect(isValidIndex(5, arr)).toBe(false);
|
|
88
88
|
expect(isValidIndex(10, arr)).toBe(false);
|
|
89
89
|
});
|
|
90
|
-
it('should return false for negative indices',
|
|
91
|
-
|
|
90
|
+
it('should return false for negative indices', () => {
|
|
91
|
+
const arr = [1, 2, 3, 4, 5];
|
|
92
92
|
expect(isValidIndex(-1, arr)).toBe(false);
|
|
93
93
|
expect(isValidIndex(-5, arr)).toBe(false);
|
|
94
94
|
});
|
|
95
|
-
it('should return true for an empty array and index 0',
|
|
96
|
-
|
|
95
|
+
it('should return true for an empty array and index 0', () => {
|
|
96
|
+
const arr = [];
|
|
97
97
|
expect(isValidIndex(0, arr)).toBe(false);
|
|
98
98
|
});
|
|
99
|
-
it('should work with arrays of different types',
|
|
100
|
-
|
|
99
|
+
it('should work with arrays of different types', () => {
|
|
100
|
+
const arr = ['a', 'b', 'c', 'd'];
|
|
101
101
|
expect(isValidIndex(0, arr)).toBe(true);
|
|
102
102
|
expect(isValidIndex(3, arr)).toBe(true);
|
|
103
103
|
expect(isValidIndex(4, arr)).toBe(false);
|
|
104
104
|
});
|
|
105
105
|
});
|
|
106
|
-
describe('next',
|
|
107
|
-
|
|
108
|
-
it('returns the next element in the array',
|
|
106
|
+
describe('next', () => {
|
|
107
|
+
const testArray = ['a', 'b', 'c', 'd'];
|
|
108
|
+
it('returns the next element in the array', () => {
|
|
109
109
|
expect(next(testArray, 0)).toBe('b');
|
|
110
110
|
expect(next(testArray, 1)).toBe('c');
|
|
111
111
|
expect(next(testArray, 2)).toBe('d');
|
|
112
112
|
});
|
|
113
|
-
it('loops to the beginning of the array when reaching the end (default behavior)',
|
|
113
|
+
it('loops to the beginning of the array when reaching the end (default behavior)', () => {
|
|
114
114
|
expect(next(testArray, 3)).toBe('a');
|
|
115
115
|
});
|
|
116
|
-
it('returns undefined when loop is false and at the end of the array',
|
|
116
|
+
it('returns undefined when loop is false and at the end of the array', () => {
|
|
117
117
|
expect(next(testArray, 3, false)).toBeUndefined();
|
|
118
118
|
});
|
|
119
|
-
it('works with arrays of different types',
|
|
120
|
-
|
|
119
|
+
it('works with arrays of different types', () => {
|
|
120
|
+
const numberArray = [1, 2, 3, 4];
|
|
121
121
|
expect(next(numberArray, 1)).toBe(3);
|
|
122
|
-
|
|
122
|
+
const objectArray = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
123
123
|
expect(next(objectArray, 0)).toEqual({ id: 2 });
|
|
124
124
|
});
|
|
125
|
-
it('handles arrays with one element',
|
|
126
|
-
|
|
125
|
+
it('handles arrays with one element', () => {
|
|
126
|
+
const singleElementArray = ['solo'];
|
|
127
127
|
expect(next(singleElementArray, 0)).toEqual('solo');
|
|
128
128
|
expect(next(singleElementArray, 0, false)).toEqual('solo');
|
|
129
129
|
});
|
|
130
|
-
it('returns undefined for empty arrays',
|
|
131
|
-
|
|
130
|
+
it('returns undefined for empty arrays', () => {
|
|
131
|
+
const emptyArray = [];
|
|
132
132
|
expect(next(emptyArray, 0)).toBeUndefined();
|
|
133
133
|
});
|
|
134
|
-
it('returns undefined for out-of-bounds indices',
|
|
134
|
+
it('returns undefined for out-of-bounds indices', () => {
|
|
135
135
|
expect(next(testArray, 4)).toBeUndefined();
|
|
136
136
|
expect(next(testArray, -1)).toBeUndefined();
|
|
137
137
|
});
|
|
138
|
-
it('returns undefined for negative indices',
|
|
138
|
+
it('returns undefined for negative indices', () => {
|
|
139
139
|
expect(next(testArray, -1)).toBeUndefined();
|
|
140
140
|
});
|
|
141
|
-
it('returns undefined for indices equal to or greater than array length',
|
|
141
|
+
it('returns undefined for indices equal to or greater than array length', () => {
|
|
142
142
|
expect(next(testArray, 4)).toBeUndefined();
|
|
143
143
|
expect(next(testArray, 5)).toBeUndefined();
|
|
144
144
|
});
|
|
145
145
|
});
|
|
146
|
-
describe('prev',
|
|
147
|
-
|
|
148
|
-
it('returns the previous element in the array',
|
|
146
|
+
describe('prev', () => {
|
|
147
|
+
const testArray = ['a', 'b', 'c', 'd'];
|
|
148
|
+
it('returns the previous element in the array', () => {
|
|
149
149
|
expect(prev(testArray, 1)).toBe('a');
|
|
150
150
|
expect(prev(testArray, 2)).toBe('b');
|
|
151
151
|
expect(prev(testArray, 3)).toBe('c');
|
|
152
152
|
});
|
|
153
|
-
it('loops to the end of the array when at the beginning (default behavior)',
|
|
153
|
+
it('loops to the end of the array when at the beginning (default behavior)', () => {
|
|
154
154
|
expect(prev(testArray, 0)).toBe('d');
|
|
155
155
|
});
|
|
156
|
-
it('returns undefined when loop is false and at the beginning of the array',
|
|
156
|
+
it('returns undefined when loop is false and at the beginning of the array', () => {
|
|
157
157
|
expect(prev(testArray, 0, false)).toBeUndefined();
|
|
158
158
|
});
|
|
159
|
-
it('works with arrays of different types',
|
|
160
|
-
|
|
159
|
+
it('works with arrays of different types', () => {
|
|
160
|
+
const numberArray = [1, 2, 3, 4];
|
|
161
161
|
expect(prev(numberArray, 2)).toBe(2);
|
|
162
|
-
|
|
162
|
+
const objectArray = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
163
163
|
expect(prev(objectArray, 1)).toEqual({ id: 1 });
|
|
164
164
|
});
|
|
165
|
-
it('handles arrays with one element',
|
|
166
|
-
|
|
165
|
+
it('handles arrays with one element', () => {
|
|
166
|
+
const singleElementArray = ['solo'];
|
|
167
167
|
expect(prev(singleElementArray, 0)).toBe('solo');
|
|
168
168
|
expect(prev(singleElementArray, 0, false)).toBe('solo');
|
|
169
169
|
});
|
|
170
|
-
it('returns undefined for empty arrays',
|
|
171
|
-
|
|
170
|
+
it('returns undefined for empty arrays', () => {
|
|
171
|
+
const emptyArray = [];
|
|
172
172
|
expect(prev(emptyArray, 0)).toBeUndefined();
|
|
173
173
|
});
|
|
174
|
-
it('returns undefined for out-of-bounds indices',
|
|
174
|
+
it('returns undefined for out-of-bounds indices', () => {
|
|
175
175
|
expect(prev(testArray, 4)).toBeUndefined();
|
|
176
176
|
expect(prev(testArray, -1)).toBeUndefined();
|
|
177
177
|
});
|
|
178
|
-
it('returns undefined for negative indices',
|
|
178
|
+
it('returns undefined for negative indices', () => {
|
|
179
179
|
expect(prev(testArray, -1)).toBeUndefined();
|
|
180
180
|
});
|
|
181
|
-
it('returns undefined for indices equal to or greater than array length',
|
|
181
|
+
it('returns undefined for indices equal to or greater than array length', () => {
|
|
182
182
|
expect(prev(testArray, 4)).toBeUndefined();
|
|
183
183
|
expect(prev(testArray, 5)).toBeUndefined();
|
|
184
184
|
});
|
|
185
|
-
it('returns undefined for indices other than 0 in single-element arrays',
|
|
186
|
-
|
|
185
|
+
it('returns undefined for indices other than 0 in single-element arrays', () => {
|
|
186
|
+
const singleElementArray = ['solo'];
|
|
187
187
|
expect(prev(singleElementArray, 1)).toBeUndefined();
|
|
188
188
|
expect(prev(singleElementArray, -1)).toBeUndefined();
|
|
189
189
|
});
|
|
190
190
|
});
|
|
191
|
-
describe('forward function',
|
|
192
|
-
|
|
193
|
-
it('returns the element at the target index when within bounds',
|
|
191
|
+
describe('forward function', () => {
|
|
192
|
+
const testArray = ['a', 'b', 'c', 'd', 'e'];
|
|
193
|
+
it('returns the element at the target index when within bounds', () => {
|
|
194
194
|
expect(forward(testArray, 0, 2)).toBe('c');
|
|
195
195
|
expect(forward(testArray, 1, 1)).toBe('c');
|
|
196
196
|
expect(forward(testArray, 2, 2)).toBe('e');
|
|
197
197
|
});
|
|
198
|
-
it('wraps around the array when looping is enabled and target index is out of bounds',
|
|
198
|
+
it('wraps around the array when looping is enabled and target index is out of bounds', () => {
|
|
199
199
|
expect(forward(testArray, 3, 2)).toBe('a');
|
|
200
200
|
expect(forward(testArray, 4, 1)).toBe('a');
|
|
201
201
|
expect(forward(testArray, 0, 5)).toBe('a');
|
|
202
202
|
expect(forward(testArray, 0, 7)).toBe('c');
|
|
203
203
|
});
|
|
204
|
-
it('returns the first or last element when looping is disabled and target index is out of bounds',
|
|
204
|
+
it('returns the first or last element when looping is disabled and target index is out of bounds', () => {
|
|
205
205
|
expect(forward(testArray, 3, 2, false)).toBe('e');
|
|
206
206
|
expect(forward(testArray, 4, 1, false)).toBe('e');
|
|
207
207
|
expect(forward(testArray, 0, 5, false)).toBe('e');
|
|
208
208
|
expect(forward(testArray, 2, -3, false)).toBe('a');
|
|
209
209
|
});
|
|
210
|
-
it('handles zero increment',
|
|
210
|
+
it('handles zero increment', () => {
|
|
211
211
|
expect(forward(testArray, 2, 0)).toBe('c');
|
|
212
212
|
expect(forward(testArray, 4, 0)).toBe('e');
|
|
213
213
|
});
|
|
214
|
-
it('works with arrays of different types',
|
|
215
|
-
|
|
214
|
+
it('works with arrays of different types', () => {
|
|
215
|
+
const numberArray = [1, 2, 3, 4, 5];
|
|
216
216
|
expect(forward(numberArray, 1, 2)).toBe(4);
|
|
217
|
-
|
|
217
|
+
const objectArray = [{ id: 1 }, { id: 2 }, { id: 3 }];
|
|
218
218
|
expect(forward(objectArray, 0, 1)).toEqual({ id: 2 });
|
|
219
219
|
});
|
|
220
|
-
it('handles single-element arrays',
|
|
221
|
-
|
|
220
|
+
it('handles single-element arrays', () => {
|
|
221
|
+
const singleElementArray = ['solo'];
|
|
222
222
|
expect(forward(singleElementArray, 0, 1)).toBe('solo');
|
|
223
223
|
expect(forward(singleElementArray, 0, 5)).toBe('solo');
|
|
224
224
|
expect(forward(singleElementArray, 0, -1)).toBe('solo');
|
|
225
225
|
});
|
|
226
|
-
it('handles negative increments',
|
|
226
|
+
it('handles negative increments', () => {
|
|
227
227
|
expect(forward(testArray, 3, -1)).toBe('c');
|
|
228
228
|
expect(forward(testArray, 4, -2)).toBe('c');
|
|
229
229
|
expect(forward(testArray, 1, -1)).toBe('a'); // Correctly wraps to the end
|
|
230
230
|
expect(forward(testArray, 0, -1)).toBe('e'); // Wraps to the last element
|
|
231
231
|
});
|
|
232
|
-
it('handles negative increments with looping disabled',
|
|
232
|
+
it('handles negative increments with looping disabled', () => {
|
|
233
233
|
expect(forward(testArray, 3, -1, false)).toBe('c');
|
|
234
234
|
expect(forward(testArray, 4, -2, false)).toBe('c');
|
|
235
235
|
expect(forward(testArray, 1, -2, false)).toBe('a'); // Returns first element
|
|
236
236
|
expect(forward(testArray, 4, -5, false)).toBe('a'); // Returns first element
|
|
237
237
|
});
|
|
238
|
-
it('returns undefined for empty arrays',
|
|
239
|
-
|
|
238
|
+
it('returns undefined for empty arrays', () => {
|
|
239
|
+
const emptyArray = [];
|
|
240
240
|
expect(forward(emptyArray, 0, 1)).toBeUndefined();
|
|
241
241
|
});
|
|
242
|
-
it('returns undefined for out-of-bounds initial indices',
|
|
242
|
+
it('returns undefined for out-of-bounds initial indices', () => {
|
|
243
243
|
expect(forward(testArray, -1, 1)).toBeUndefined();
|
|
244
244
|
expect(forward(testArray, 5, 1)).toBeUndefined();
|
|
245
245
|
});
|
|
246
|
-
it('handles large positive and negative increments',
|
|
246
|
+
it('handles large positive and negative increments', () => {
|
|
247
247
|
expect(forward(testArray, 0, 15)).toBe('a'); // Loops around 3 times
|
|
248
248
|
expect(forward(testArray, 0, -15)).toBe('a'); // Loops around -3 times
|
|
249
249
|
expect(forward(testArray, 0, 15, false)).toBe('e');
|
|
250
250
|
expect(forward(testArray, 0, -15, false)).toBe('a');
|
|
251
251
|
});
|
|
252
252
|
});
|
|
253
|
-
describe('backward function',
|
|
254
|
-
|
|
255
|
-
it('should return the correct element when moving backward',
|
|
253
|
+
describe('backward function', () => {
|
|
254
|
+
const testArray = [1, 2, 3, 4, 5];
|
|
255
|
+
it('should return the correct element when moving backward', () => {
|
|
256
256
|
expect(backward(testArray, 2, 1)).toBe(2);
|
|
257
257
|
expect(backward(testArray, 4, 2)).toBe(3);
|
|
258
258
|
});
|
|
259
|
-
it('should wrap around the array when looping is enabled',
|
|
259
|
+
it('should wrap around the array when looping is enabled', () => {
|
|
260
260
|
expect(backward(testArray, 0, 1)).toBe(5);
|
|
261
261
|
expect(backward(testArray, 1, 3)).toBe(4);
|
|
262
262
|
});
|
|
263
|
-
it('should clamp to array bounds when looping is disabled',
|
|
263
|
+
it('should clamp to array bounds when looping is disabled', () => {
|
|
264
264
|
expect(backward(testArray, 0, 1, false)).toBe(1);
|
|
265
265
|
expect(backward(testArray, 1, 3, false)).toBe(1);
|
|
266
266
|
});
|
|
267
|
-
it('should handle negative decrements (moving forward)',
|
|
267
|
+
it('should handle negative decrements (moving forward)', () => {
|
|
268
268
|
expect(backward(testArray, 2, -1)).toBe(4);
|
|
269
269
|
expect(backward(testArray, 4, -2)).toBe(2);
|
|
270
270
|
});
|
|
271
|
-
it('should return undefined for empty arrays',
|
|
271
|
+
it('should return undefined for empty arrays', () => {
|
|
272
272
|
expect(backward([], 0, 1)).toBeUndefined();
|
|
273
273
|
});
|
|
274
|
-
it('should return undefined for out-of-bounds initial indices',
|
|
274
|
+
it('should return undefined for out-of-bounds initial indices', () => {
|
|
275
275
|
expect(backward(testArray, -1, 1)).toBeUndefined();
|
|
276
276
|
expect(backward(testArray, 5, 1)).toBeUndefined();
|
|
277
277
|
});
|
|
278
|
-
it('should handle large decrements',
|
|
278
|
+
it('should handle large decrements', () => {
|
|
279
279
|
expect(backward(testArray, 4, 10)).toBe(5);
|
|
280
280
|
expect(backward(testArray, 4, 11)).toBe(4);
|
|
281
281
|
});
|
|
282
282
|
});
|
|
283
|
-
describe('getNextMatch',
|
|
284
|
-
|
|
285
|
-
it('should return the first match when no current match is provided',
|
|
283
|
+
describe('getNextMatch', () => {
|
|
284
|
+
const values = ['apple', 'banana', 'cherry', 'date', 'elderberry'];
|
|
285
|
+
it('should return the first match when no current match is provided', () => {
|
|
286
286
|
expect(getNextMatch(values, 'b')).toBe('banana');
|
|
287
287
|
});
|
|
288
|
-
it('should return the next match when a current match is provided',
|
|
288
|
+
it('should return the next match when a current match is provided', () => {
|
|
289
289
|
expect(getNextMatch(values, 'c', 'cherry')).toBe(undefined);
|
|
290
290
|
expect(getNextMatch(values, 'c', 'banana')).toBe('cherry');
|
|
291
291
|
});
|
|
292
|
-
it('should handle repeated characters in search',
|
|
292
|
+
it('should handle repeated characters in search', () => {
|
|
293
293
|
expect(getNextMatch(values, 'aaa', 'apple')).toBe(undefined);
|
|
294
294
|
expect(getNextMatch(values, 'aaa', 'banana')).toBe('apple');
|
|
295
295
|
});
|
|
296
|
-
it('should wrap around the array when reaching the end',
|
|
296
|
+
it('should wrap around the array when reaching the end', () => {
|
|
297
297
|
expect(getNextMatch(values, 'd', 'date')).toBe(undefined);
|
|
298
298
|
expect(getNextMatch(values, 'a', 'elderberry')).toBe('apple');
|
|
299
299
|
});
|
|
300
|
-
it('should be case-insensitive',
|
|
300
|
+
it('should be case-insensitive', () => {
|
|
301
301
|
expect(getNextMatch(values, 'B', 'apple')).toBe('banana');
|
|
302
302
|
expect(getNextMatch(values, 'cH', 'banana')).toBe('cherry');
|
|
303
303
|
});
|
|
304
|
-
it('should handle empty search string',
|
|
304
|
+
it('should handle empty search string', () => {
|
|
305
305
|
expect(getNextMatch(values, '', 'banana')).toBe(undefined);
|
|
306
306
|
});
|
|
307
|
-
it('should handle empty values array',
|
|
307
|
+
it('should handle empty values array', () => {
|
|
308
308
|
expect(getNextMatch([], 'a')).toBe(undefined);
|
|
309
309
|
});
|
|
310
|
-
it('should exclude current match when search is a single character',
|
|
310
|
+
it('should exclude current match when search is a single character', () => {
|
|
311
311
|
expect(getNextMatch(values, 'a', 'apple')).toBe(undefined);
|
|
312
312
|
expect(getNextMatch(values, 'b', 'banana')).toBe(undefined);
|
|
313
313
|
});
|
|
314
|
-
it('should not exclude current match when search is multiple characters',
|
|
314
|
+
it('should not exclude current match when search is multiple characters', () => {
|
|
315
315
|
expect(getNextMatch(values, 'ap', 'apple')).toBe(undefined);
|
|
316
316
|
expect(getNextMatch(values, 'ba', 'banana')).toBe(undefined);
|
|
317
317
|
});
|
|
318
|
-
it('should handle values with common prefixes',
|
|
319
|
-
|
|
318
|
+
it('should handle values with common prefixes', () => {
|
|
319
|
+
const prefixValues = ['prefix1', 'prefix2', 'prefix3', 'other'];
|
|
320
320
|
expect(getNextMatch(prefixValues, 'pre', 'prefix1')).toBe(undefined);
|
|
321
321
|
expect(getNextMatch(prefixValues, 'pre', 'prefix2')).toBe(undefined);
|
|
322
322
|
expect(getNextMatch(prefixValues, 'pre', 'prefix3')).toBe(undefined);
|
|
323
323
|
expect(getNextMatch(prefixValues, 'pre', 'other')).toBe('prefix1');
|
|
324
324
|
});
|
|
325
|
-
it('should cycle through values with common prefixes using single character search',
|
|
326
|
-
|
|
325
|
+
it('should cycle through values with common prefixes using single character search', () => {
|
|
326
|
+
const prefixValues = ['prefix1', 'prefix2', 'prefix3', 'other'];
|
|
327
327
|
expect(getNextMatch(prefixValues, 'p', 'other')).toBe('prefix1');
|
|
328
328
|
expect(getNextMatch(prefixValues, 'p', 'prefix1')).toBe('prefix2');
|
|
329
329
|
expect(getNextMatch(prefixValues, 'p', 'prefix2')).toBe('prefix3');
|
|
330
330
|
expect(getNextMatch(prefixValues, 'p', 'prefix3')).toBe('prefix1');
|
|
331
331
|
});
|
|
332
|
-
it('should handle single character search with prefixed values',
|
|
333
|
-
|
|
332
|
+
it('should handle single character search with prefixed values', () => {
|
|
333
|
+
const prefixValues = ['prefix1', 'prefix2', 'prefix3', 'other'];
|
|
334
334
|
expect(getNextMatch(prefixValues, 'p')).toBe('prefix1');
|
|
335
335
|
expect(getNextMatch(prefixValues, 'p', 'prefix1')).toBe('prefix2');
|
|
336
336
|
expect(getNextMatch(prefixValues, 'o')).toBe('other');
|
|
337
337
|
expect(getNextMatch(prefixValues, 'o', 'other')).toBe(undefined);
|
|
338
338
|
});
|
|
339
|
-
it('should handle search with spaces',
|
|
340
|
-
|
|
339
|
+
it('should handle search with spaces', () => {
|
|
340
|
+
const spaceValues = ['apple pie', 'banana split', 'banana bread', 'cherry tart'];
|
|
341
341
|
expect(getNextMatch(spaceValues, 'b')).toBe('banana split');
|
|
342
342
|
expect(getNextMatch(spaceValues, 'banana ')).toBe('banana split');
|
|
343
343
|
expect(getNextMatch(spaceValues, 'banana b')).toBe('banana bread');
|
|
@@ -347,20 +347,20 @@ describe('getNextMatch', function () {
|
|
|
347
347
|
expect(getNextMatch(spaceValues, 'apple p')).toBe('apple pie');
|
|
348
348
|
});
|
|
349
349
|
});
|
|
350
|
-
describe('wrapArray',
|
|
351
|
-
it('should wrap the array starting from the given index',
|
|
350
|
+
describe('wrapArray', () => {
|
|
351
|
+
it('should wrap the array starting from the given index', () => {
|
|
352
352
|
expect(wrapArray(['a', 'b', 'c', 'd'], 2)).toEqual(['c', 'd', 'a', 'b']);
|
|
353
353
|
});
|
|
354
|
-
it('should handle start index 0 (no wrapping)',
|
|
354
|
+
it('should handle start index 0 (no wrapping)', () => {
|
|
355
355
|
expect(wrapArray([1, 2, 3, 4, 5], 0)).toEqual([1, 2, 3, 4, 5]);
|
|
356
356
|
});
|
|
357
|
-
it('should wrap correctly with start index equal to array length',
|
|
357
|
+
it('should wrap correctly with start index equal to array length', () => {
|
|
358
358
|
expect(wrapArray(['x', 'y', 'z'], 3)).toEqual(['x', 'y', 'z']);
|
|
359
359
|
});
|
|
360
|
-
it('should work with empty array',
|
|
360
|
+
it('should work with empty array', () => {
|
|
361
361
|
expect(wrapArray([], 2)).toEqual([]);
|
|
362
362
|
});
|
|
363
|
-
it('should work with array of different types',
|
|
363
|
+
it('should work with array of different types', () => {
|
|
364
364
|
expect(wrapArray([true, 42, 'test'], 1)).toEqual([42, 'test', true]);
|
|
365
365
|
});
|
|
366
366
|
});
|
|
@@ -6,24 +6,22 @@ import { noop } from './noop.js';
|
|
|
6
6
|
* @param defaultValue The value which will be set.
|
|
7
7
|
* @param afterMs A zero-or-greater delay in milliseconds.
|
|
8
8
|
*/
|
|
9
|
-
export function boxAutoReset(defaultValue, afterMs, onChange) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var timeout = null;
|
|
13
|
-
var value = $state(defaultValue);
|
|
9
|
+
export function boxAutoReset(defaultValue, afterMs = 10000, onChange = noop) {
|
|
10
|
+
let timeout = null;
|
|
11
|
+
let value = $state(defaultValue);
|
|
14
12
|
function resetAfter() {
|
|
15
|
-
return window.setTimeout(
|
|
13
|
+
return window.setTimeout(() => {
|
|
16
14
|
value = defaultValue;
|
|
17
15
|
onChange(defaultValue);
|
|
18
16
|
}, afterMs);
|
|
19
17
|
}
|
|
20
|
-
$effect(
|
|
21
|
-
return
|
|
18
|
+
$effect(() => {
|
|
19
|
+
return () => {
|
|
22
20
|
if (timeout)
|
|
23
21
|
clearTimeout(timeout);
|
|
24
22
|
};
|
|
25
23
|
});
|
|
26
|
-
return box.with(
|
|
24
|
+
return box.with(() => value, (v) => {
|
|
27
25
|
value = v;
|
|
28
26
|
onChange(v);
|
|
29
27
|
if (timeout)
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import { untrack } from 'svelte';
|
|
2
|
-
export function watch(box, callback, options) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
$effect.pre(function () {
|
|
2
|
+
export function watch(box, callback, options = {}) {
|
|
3
|
+
let prev = $state(box.current);
|
|
4
|
+
let ranOnce = false;
|
|
5
|
+
const watchEffect = $effect.root(() => {
|
|
6
|
+
$effect.pre(() => {
|
|
8
7
|
if (prev === box.current || !options.immediate)
|
|
9
8
|
return;
|
|
10
9
|
if (options.once && ranOnce)
|
|
11
10
|
return;
|
|
12
|
-
callback(box.current, untrack(
|
|
13
|
-
untrack(
|
|
11
|
+
callback(box.current, untrack(() => prev));
|
|
12
|
+
untrack(() => (prev = box.current));
|
|
14
13
|
ranOnce = true;
|
|
15
14
|
});
|
|
16
|
-
$effect(
|
|
15
|
+
$effect(() => {
|
|
17
16
|
if (prev === box.current || options.immediate)
|
|
18
17
|
return;
|
|
19
18
|
if (options.once && ranOnce)
|
|
20
19
|
return;
|
|
21
|
-
callback(box.current, untrack(
|
|
22
|
-
untrack(
|
|
20
|
+
callback(box.current, untrack(() => prev));
|
|
21
|
+
untrack(() => (prev = box.current));
|
|
23
22
|
ranOnce = true;
|
|
24
23
|
});
|
|
25
24
|
});
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
2
|
import { clamp } from './clamp.js';
|
|
3
|
-
describe('clamp',
|
|
4
|
-
it('should return the number if it is within the range',
|
|
3
|
+
describe('clamp', () => {
|
|
4
|
+
it('should return the number if it is within the range', () => {
|
|
5
5
|
expect(clamp(5, 0, 10)).toBe(5);
|
|
6
6
|
expect(clamp(0, 0, 10)).toBe(0);
|
|
7
7
|
expect(clamp(10, 0, 10)).toBe(10);
|
|
8
8
|
});
|
|
9
|
-
it('should return the minimum value if the number is below the range',
|
|
9
|
+
it('should return the minimum value if the number is below the range', () => {
|
|
10
10
|
expect(clamp(-5, 0, 10)).toBe(0);
|
|
11
11
|
expect(clamp(-10, -5, 5)).toBe(-5);
|
|
12
12
|
});
|
|
13
|
-
it('should return the maximum value if the number is above the range',
|
|
13
|
+
it('should return the maximum value if the number is above the range', () => {
|
|
14
14
|
expect(clamp(15, 0, 10)).toBe(10);
|
|
15
15
|
expect(clamp(20, -5, 5)).toBe(5);
|
|
16
16
|
});
|
|
17
|
-
it('should handle equal minimum and maximum values',
|
|
17
|
+
it('should handle equal minimum and maximum values', () => {
|
|
18
18
|
expect(clamp(5, 10, 10)).toBe(10);
|
|
19
19
|
expect(clamp(15, 10, 10)).toBe(10);
|
|
20
20
|
});
|
|
21
|
-
it('should handle negative minimum and maximum values',
|
|
21
|
+
it('should handle negative minimum and maximum values', () => {
|
|
22
22
|
expect(clamp(-15, -20, -10)).toBe(-15);
|
|
23
23
|
expect(clamp(-25, -20, -10)).toBe(-20);
|
|
24
24
|
expect(clamp(-5, -20, -10)).toBe(-10);
|
|
25
25
|
});
|
|
26
|
-
it('should handle decimal values',
|
|
26
|
+
it('should handle decimal values', () => {
|
|
27
27
|
expect(clamp(3.5, 1.2, 7.8)).toBe(3.5);
|
|
28
28
|
expect(clamp(0.5, 1.2, 7.8)).toBe(1.2);
|
|
29
29
|
expect(clamp(9.5, 1.2, 7.8)).toBe(7.8);
|
|
@@ -1,33 +1,29 @@
|
|
|
1
1
|
import { executeCallbacks } from 'svelte-toolbelt';
|
|
2
2
|
export function createEventHook() {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const callbacks = new Set();
|
|
4
|
+
const callbacksToDispose = [];
|
|
5
5
|
function off(cb) {
|
|
6
6
|
callbacks.delete(cb);
|
|
7
7
|
}
|
|
8
8
|
function on(cb) {
|
|
9
9
|
callbacks.add(cb);
|
|
10
|
-
|
|
10
|
+
const offFn = () => off(cb);
|
|
11
11
|
callbacksToDispose.push(offFn);
|
|
12
12
|
return { off: offFn };
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
args[_i] = arguments[_i];
|
|
18
|
-
}
|
|
19
|
-
return Promise.all(Array.from(callbacks).map(function (cb) {
|
|
20
|
-
return Promise.resolve(cb.apply(void 0, args));
|
|
14
|
+
const trigger = (...args) => {
|
|
15
|
+
return Promise.all(Array.from(callbacks).map((cb) => {
|
|
16
|
+
return Promise.resolve(cb(...args));
|
|
21
17
|
}));
|
|
22
18
|
};
|
|
23
|
-
$effect(
|
|
24
|
-
return
|
|
19
|
+
$effect(() => {
|
|
20
|
+
return () => {
|
|
25
21
|
executeCallbacks(callbacksToDispose);
|
|
26
22
|
};
|
|
27
23
|
});
|
|
28
24
|
return {
|
|
29
|
-
on
|
|
30
|
-
off
|
|
31
|
-
trigger
|
|
25
|
+
on,
|
|
26
|
+
off,
|
|
27
|
+
trigger
|
|
32
28
|
};
|
|
33
29
|
}
|