foldkit 0.17.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -16
- package/dist/effectExtensions/optionExtensions.d.ts +4 -0
- package/dist/effectExtensions/optionExtensions.d.ts.map +1 -1
- package/dist/effectExtensions/optionExtensions.js +2 -1
- package/dist/fieldValidation/index.d.ts +8 -8
- package/dist/fieldValidation/index.d.ts.map +1 -1
- package/dist/fieldValidation/index.js +9 -8
- package/dist/html/index.d.ts +57 -1
- package/dist/html/index.d.ts.map +1 -1
- package/dist/html/index.js +69 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/message/index.d.ts +2 -0
- package/dist/message/index.d.ts.map +1 -0
- package/dist/message/index.js +1 -0
- package/dist/message/public.d.ts +2 -0
- package/dist/message/public.d.ts.map +1 -0
- package/dist/message/public.js +1 -0
- package/dist/route/index.d.ts +1 -0
- package/dist/route/index.d.ts.map +1 -1
- package/dist/route/index.js +1 -0
- package/dist/route/parser.js +17 -17
- package/dist/route/public.d.ts +1 -1
- package/dist/route/public.d.ts.map +1 -1
- package/dist/route/public.js +1 -1
- package/dist/runtime/browserListeners.d.ts.map +1 -1
- package/dist/runtime/browserListeners.js +2 -2
- package/dist/runtime/runtime.d.ts +1 -1
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +8 -8
- package/dist/runtime/urlRequest.d.ts +4 -4
- package/dist/runtime/urlRequest.d.ts.map +1 -1
- package/dist/runtime/urlRequest.js +3 -2
- package/dist/schema/index.d.ts +44 -10
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +19 -15
- package/dist/schema/public.d.ts +1 -0
- package/dist/schema/public.d.ts.map +1 -1
- package/dist/task/dom.d.ts +59 -0
- package/dist/task/dom.d.ts.map +1 -0
- package/dist/task/dom.js +113 -0
- package/dist/task/index.d.ts +6 -85
- package/dist/task/index.d.ts.map +1 -1
- package/dist/task/index.js +6 -131
- package/dist/task/inert.d.ts +25 -0
- package/dist/task/inert.d.ts.map +1 -0
- package/dist/task/inert.js +88 -0
- package/dist/task/public.d.ts +1 -1
- package/dist/task/public.d.ts.map +1 -1
- package/dist/task/public.js +1 -1
- package/dist/task/random.d.ts +12 -0
- package/dist/task/random.d.ts.map +1 -0
- package/dist/task/random.js +11 -0
- package/dist/task/scrollLock.d.ts +24 -0
- package/dist/task/scrollLock.d.ts.map +1 -0
- package/dist/task/scrollLock.js +48 -0
- package/dist/task/time.d.ts +42 -0
- package/dist/task/time.d.ts.map +1 -0
- package/dist/task/time.js +54 -0
- package/dist/task/timing.d.ts +36 -0
- package/dist/task/timing.d.ts.map +1 -0
- package/dist/task/timing.js +55 -0
- package/dist/ui/dialog/index.d.ts +4 -4
- package/dist/ui/dialog/index.d.ts.map +1 -1
- package/dist/ui/dialog/index.js +8 -8
- package/dist/ui/disclosure/index.d.ts +4 -4
- package/dist/ui/disclosure/index.d.ts.map +1 -1
- package/dist/ui/disclosure/index.js +8 -8
- package/dist/ui/index.d.ts +1 -0
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +1 -0
- package/dist/ui/keyboard.d.ts +4 -0
- package/dist/ui/keyboard.d.ts.map +1 -0
- package/dist/ui/keyboard.js +7 -0
- package/dist/ui/menu/index.d.ts +189 -0
- package/dist/ui/menu/index.d.ts.map +1 -0
- package/dist/ui/menu/index.js +502 -0
- package/dist/ui/menu/public.d.ts +3 -0
- package/dist/ui/menu/public.d.ts.map +1 -0
- package/dist/ui/menu/public.js +1 -0
- package/dist/ui/tabs/index.d.ts +8 -10
- package/dist/ui/tabs/index.d.ts.map +1 -1
- package/dist/ui/tabs/index.js +17 -28
- package/dist/url/index.d.ts +1 -1
- package/dist/url/index.js +4 -4
- package/package.json +14 -1
package/dist/task/index.d.ts
CHANGED
|
@@ -1,86 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* ```typescript
|
|
8
|
-
* Task.getTime(utc => GotTime.make({ utc }))
|
|
9
|
-
* ```
|
|
10
|
-
*/
|
|
11
|
-
export declare const getTime: <Message>(f: (utc: DateTime.Utc) => Message) => Effect.Effect<Message>;
|
|
12
|
-
/**
|
|
13
|
-
* Creates a command that gets the system timezone and passes it to a message constructor.
|
|
14
|
-
* This is similar to Elm's `Task.perform` with `Time.here`.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* Task.getTimeZone(zone => GotTimeZone.make({ zone }))
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export declare const getTimeZone: <Message>(f: (zone: DateTime.TimeZone) => Message) => Effect.Effect<Message>;
|
|
22
|
-
/**
|
|
23
|
-
* Creates a command that gets the current time in the system timezone and passes it to a message constructor.
|
|
24
|
-
* This combines both time and timezone in a single task.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* Task.getZonedTime(zoned => GotTime.make({ zoned }))
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export declare const getZonedTime: <Message>(f: (zoned: DateTime.Zoned) => Message) => Effect.Effect<Message>;
|
|
32
|
-
/**
|
|
33
|
-
* Creates a command that gets the current time in a specific timezone and passes it to a message constructor.
|
|
34
|
-
* If the timezone is invalid, the effect will fail with an error string.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* Task.getZonedTimeIn('America/New_York', zoned => GotNYTime.make({ zoned }))
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export declare const getZonedTimeIn: <Message>(zoneId: string, f: (zoned: DateTime.Zoned) => Message) => Effect.Effect<Message, string>;
|
|
42
|
-
/**
|
|
43
|
-
* Creates a command that focuses an element by selector and passes the result to a message constructor.
|
|
44
|
-
* Returns true if the element was found and focused, false otherwise.
|
|
45
|
-
* Uses requestAnimationFrame to ensure the DOM tree is updated and nodes exist before attempting to focus.
|
|
46
|
-
* This follows the same approach as Elm's Browser.Dom.focus.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```typescript
|
|
50
|
-
* Task.focus('#email-input', success => InputFocused.make({ success }))
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
export declare const focus: <Message>(selector: string, f: (success: boolean) => Message) => Effect.Effect<Message>;
|
|
54
|
-
/**
|
|
55
|
-
* Creates a command that opens a dialog element as a modal using `showModal()`.
|
|
56
|
-
* Returns true if the element was found and opened, false otherwise.
|
|
57
|
-
* Uses requestAnimationFrame to ensure the DOM tree is updated and nodes exist before attempting to show.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
* Task.showModal('#my-dialog', success => ModalOpened.make({ success }))
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
export declare const showModal: <Message>(selector: string, f: (success: boolean) => Message) => Effect.Effect<Message>;
|
|
65
|
-
/**
|
|
66
|
-
* Creates a command that closes a dialog element using `.close()`.
|
|
67
|
-
* Returns true if the element was found and closed, false otherwise.
|
|
68
|
-
* Uses requestAnimationFrame to ensure the DOM tree is updated and nodes exist before attempting to close.
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* Task.closeModal('#my-dialog', success => ModalClosed.make({ success }))
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
export declare const closeModal: <Message>(selector: string, f: (success: boolean) => Message) => Effect.Effect<Message>;
|
|
76
|
-
/**
|
|
77
|
-
* Creates a command that generates a random integer between min (inclusive) and max (exclusive)
|
|
78
|
-
* and passes it to a message constructor.
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```typescript
|
|
82
|
-
* Task.randomInt(0, 100, value => GotRandom.make({ value }))
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
export declare const randomInt: <Message>(min: number, max: number, f: (value: number) => Message) => Effect.Effect<Message>;
|
|
1
|
+
export { getTime, getTimeZone, getZonedTime, getZonedTimeIn } from './time';
|
|
2
|
+
export { focus, showModal, closeModal, clickElement, scrollIntoView, } from './dom';
|
|
3
|
+
export { delay, nextFrame, waitForTransitions } from './timing';
|
|
4
|
+
export { randomInt } from './random';
|
|
5
|
+
export { lockScroll, unlockScroll } from './scrollLock';
|
|
6
|
+
export { inertOthers, restoreInert } from './inert';
|
|
86
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/task/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/task/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/task/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;AAC3E,OAAO,EACL,KAAK,EACL,SAAS,EACT,UAAU,EACV,YAAY,EACZ,cAAc,GACf,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AACvD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA"}
|
package/dist/task/index.js
CHANGED
|
@@ -1,131 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* ```typescript
|
|
8
|
-
* Task.getTime(utc => GotTime.make({ utc }))
|
|
9
|
-
* ```
|
|
10
|
-
*/
|
|
11
|
-
export const getTime = (f) => Effect.map(DateTime.now, f);
|
|
12
|
-
/**
|
|
13
|
-
* Creates a command that gets the system timezone and passes it to a message constructor.
|
|
14
|
-
* This is similar to Elm's `Task.perform` with `Time.here`.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* Task.getTimeZone(zone => GotTimeZone.make({ zone }))
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export const getTimeZone = (f) => Effect.sync(() => f(DateTime.zoneMakeLocal()));
|
|
22
|
-
/**
|
|
23
|
-
* Creates a command that gets the current time in the system timezone and passes it to a message constructor.
|
|
24
|
-
* This combines both time and timezone in a single task.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* Task.getZonedTime(zoned => GotTime.make({ zoned }))
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export const getZonedTime = (f) => Effect.gen(function* () {
|
|
32
|
-
const utc = yield* DateTime.now;
|
|
33
|
-
const zone = DateTime.zoneMakeLocal();
|
|
34
|
-
const zoned = DateTime.setZone(utc, zone);
|
|
35
|
-
return f(zoned);
|
|
36
|
-
});
|
|
37
|
-
/**
|
|
38
|
-
* Creates a command that gets the current time in a specific timezone and passes it to a message constructor.
|
|
39
|
-
* If the timezone is invalid, the effect will fail with an error string.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```typescript
|
|
43
|
-
* Task.getZonedTimeIn('America/New_York', zoned => GotNYTime.make({ zoned }))
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
export const getZonedTimeIn = (zoneId, f) => Effect.gen(function* () {
|
|
47
|
-
const utc = yield* DateTime.now;
|
|
48
|
-
const maybeZone = DateTime.zoneMakeNamed(zoneId);
|
|
49
|
-
if (Option.isNone(maybeZone)) {
|
|
50
|
-
return yield* Effect.fail(`Invalid timezone: ${zoneId}`);
|
|
51
|
-
}
|
|
52
|
-
const zoned = DateTime.setZone(utc, maybeZone.value);
|
|
53
|
-
return f(zoned);
|
|
54
|
-
});
|
|
55
|
-
/**
|
|
56
|
-
* Creates a command that focuses an element by selector and passes the result to a message constructor.
|
|
57
|
-
* Returns true if the element was found and focused, false otherwise.
|
|
58
|
-
* Uses requestAnimationFrame to ensure the DOM tree is updated and nodes exist before attempting to focus.
|
|
59
|
-
* This follows the same approach as Elm's Browser.Dom.focus.
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```typescript
|
|
63
|
-
* Task.focus('#email-input', success => InputFocused.make({ success }))
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
export const focus = (selector, f) => Effect.async((resume) => {
|
|
67
|
-
requestAnimationFrame(() => {
|
|
68
|
-
const element = document.querySelector(selector);
|
|
69
|
-
if (element instanceof HTMLElement) {
|
|
70
|
-
element.focus();
|
|
71
|
-
resume(Effect.succeed(f(true)));
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
resume(Effect.succeed(f(false)));
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
/**
|
|
79
|
-
* Creates a command that opens a dialog element as a modal using `showModal()`.
|
|
80
|
-
* Returns true if the element was found and opened, false otherwise.
|
|
81
|
-
* Uses requestAnimationFrame to ensure the DOM tree is updated and nodes exist before attempting to show.
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* ```typescript
|
|
85
|
-
* Task.showModal('#my-dialog', success => ModalOpened.make({ success }))
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
export const showModal = (selector, f) => Effect.async((resume) => {
|
|
89
|
-
requestAnimationFrame(() => {
|
|
90
|
-
const element = document.querySelector(selector);
|
|
91
|
-
if (element instanceof HTMLDialogElement) {
|
|
92
|
-
element.showModal();
|
|
93
|
-
resume(Effect.succeed(f(true)));
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
resume(Effect.succeed(f(false)));
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
/**
|
|
101
|
-
* Creates a command that closes a dialog element using `.close()`.
|
|
102
|
-
* Returns true if the element was found and closed, false otherwise.
|
|
103
|
-
* Uses requestAnimationFrame to ensure the DOM tree is updated and nodes exist before attempting to close.
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* ```typescript
|
|
107
|
-
* Task.closeModal('#my-dialog', success => ModalClosed.make({ success }))
|
|
108
|
-
* ```
|
|
109
|
-
*/
|
|
110
|
-
export const closeModal = (selector, f) => Effect.async((resume) => {
|
|
111
|
-
requestAnimationFrame(() => {
|
|
112
|
-
const element = document.querySelector(selector);
|
|
113
|
-
if (element instanceof HTMLDialogElement) {
|
|
114
|
-
element.close();
|
|
115
|
-
resume(Effect.succeed(f(true)));
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
resume(Effect.succeed(f(false)));
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
/**
|
|
123
|
-
* Creates a command that generates a random integer between min (inclusive) and max (exclusive)
|
|
124
|
-
* and passes it to a message constructor.
|
|
125
|
-
*
|
|
126
|
-
* @example
|
|
127
|
-
* ```typescript
|
|
128
|
-
* Task.randomInt(0, 100, value => GotRandom.make({ value }))
|
|
129
|
-
* ```
|
|
130
|
-
*/
|
|
131
|
-
export const randomInt = (min, max, f) => Effect.sync(() => f(Math.floor(Math.random() * (max - min)) + min));
|
|
1
|
+
export { getTime, getTimeZone, getZonedTime, getZonedTimeIn } from './time';
|
|
2
|
+
export { focus, showModal, closeModal, clickElement, scrollIntoView, } from './dom';
|
|
3
|
+
export { delay, nextFrame, waitForTransitions } from './timing';
|
|
4
|
+
export { randomInt } from './random';
|
|
5
|
+
export { lockScroll, unlockScroll } from './scrollLock';
|
|
6
|
+
export { inertOthers, restoreInert } from './inert';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a command that marks all DOM elements outside the given selectors as
|
|
4
|
+
* `inert` and `aria-hidden="true"`. Walks each allowed element up to
|
|
5
|
+
* `document.body`, marking siblings that don't contain an allowed element.
|
|
6
|
+
* Uses reference counting so nested calls are safe.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* Task.inertOthers('my-menu', ['#menu-button', '#menu-items'], () => NoOp())
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare const inertOthers: <Message>(id: string, allowedSelectors: ReadonlyArray<string>, f: () => Message) => Effect.Effect<Message>;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a command that restores all elements previously marked inert by
|
|
16
|
+
* `inertOthers` for the given ID. Safe to call without a preceding
|
|
17
|
+
* `inertOthers` — acts as a no-op in that case.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* Task.restoreInert('my-menu', () => NoOp())
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare const restoreInert: <Message>(id: string, f: () => Message) => Effect.Effect<Message>;
|
|
25
|
+
//# sourceMappingURL=inert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inert.d.ts","sourceRoot":"","sources":["../../src/task/inert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,MAAM,EAAmC,MAAM,QAAQ,CAAA;AAoFvE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,EACjC,IAAI,MAAM,EACV,kBAAkB,aAAa,CAAC,MAAM,CAAC,EACvC,GAAG,MAAM,OAAO,KACf,MAAM,CAAC,MAAM,CAAC,OAAO,CAepB,CAAA;AAEJ;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,EAClC,IAAI,MAAM,EACV,GAAG,MAAM,OAAO,KACf,MAAM,CAAC,MAAM,CAAC,OAAO,CAUpB,CAAA"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Array, Effect, Number, Option, Predicate, pipe } from 'effect';
|
|
2
|
+
const inertState = {
|
|
3
|
+
originals: new Map(),
|
|
4
|
+
counts: new Map(),
|
|
5
|
+
cleanups: new Map(),
|
|
6
|
+
};
|
|
7
|
+
const markInert = (element) => {
|
|
8
|
+
const count = inertState.counts.get(element) ?? 0;
|
|
9
|
+
inertState.counts.set(element, Number.increment(count));
|
|
10
|
+
if (count === 0) {
|
|
11
|
+
inertState.originals.set(element, {
|
|
12
|
+
ariaHidden: element.getAttribute('aria-hidden'),
|
|
13
|
+
inert: element.inert,
|
|
14
|
+
});
|
|
15
|
+
element.setAttribute('aria-hidden', 'true');
|
|
16
|
+
element.inert = true;
|
|
17
|
+
}
|
|
18
|
+
return () => markNotInert(element);
|
|
19
|
+
};
|
|
20
|
+
const markNotInert = (element) => {
|
|
21
|
+
const count = inertState.counts.get(element) ?? 1;
|
|
22
|
+
if (count === 1) {
|
|
23
|
+
const original = inertState.originals.get(element);
|
|
24
|
+
if (original) {
|
|
25
|
+
if (Predicate.isNull(original.ariaHidden)) {
|
|
26
|
+
element.removeAttribute('aria-hidden');
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
element.setAttribute('aria-hidden', original.ariaHidden);
|
|
30
|
+
}
|
|
31
|
+
element.inert = original.inert;
|
|
32
|
+
inertState.originals.delete(element);
|
|
33
|
+
}
|
|
34
|
+
inertState.counts.delete(element);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
inertState.counts.set(element, Number.decrement(count));
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const resolveElements = (selectors) => Array.filterMap(selectors, selector => {
|
|
41
|
+
const element = document.querySelector(selector);
|
|
42
|
+
return element instanceof HTMLElement ? Option.some(element) : Option.none();
|
|
43
|
+
});
|
|
44
|
+
const ancestorsUpToBody = (element) => Array.unfold(element.parentElement, current => Predicate.isNotNull(current)
|
|
45
|
+
? Option.some([
|
|
46
|
+
current,
|
|
47
|
+
current === document.body ? null : current.parentElement,
|
|
48
|
+
])
|
|
49
|
+
: Option.none());
|
|
50
|
+
const inertableSiblings = (parent, allowedElements) => pipe(parent.children, Array.fromIterable, Array.filterMap(child => child instanceof HTMLElement &&
|
|
51
|
+
!Array.some(allowedElements, allowed => child.contains(allowed))
|
|
52
|
+
? Option.some(child)
|
|
53
|
+
: Option.none()));
|
|
54
|
+
/**
|
|
55
|
+
* Creates a command that marks all DOM elements outside the given selectors as
|
|
56
|
+
* `inert` and `aria-hidden="true"`. Walks each allowed element up to
|
|
57
|
+
* `document.body`, marking siblings that don't contain an allowed element.
|
|
58
|
+
* Uses reference counting so nested calls are safe.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* Task.inertOthers('my-menu', ['#menu-button', '#menu-items'], () => NoOp())
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export const inertOthers = (id, allowedSelectors, f) => Effect.sync(() => {
|
|
66
|
+
const allowedElements = resolveElements(allowedSelectors);
|
|
67
|
+
const cleanupFunctions = pipe(allowedElements, Array.flatMap(ancestorsUpToBody), Array.flatMap(ancestor => Array.map(inertableSiblings(ancestor, allowedElements), markInert)));
|
|
68
|
+
inertState.cleanups.set(id, cleanupFunctions);
|
|
69
|
+
return f();
|
|
70
|
+
});
|
|
71
|
+
/**
|
|
72
|
+
* Creates a command that restores all elements previously marked inert by
|
|
73
|
+
* `inertOthers` for the given ID. Safe to call without a preceding
|
|
74
|
+
* `inertOthers` — acts as a no-op in that case.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* Task.restoreInert('my-menu', () => NoOp())
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export const restoreInert = (id, f) => Effect.sync(() => {
|
|
82
|
+
const cleanupFunctions = inertState.cleanups.get(id);
|
|
83
|
+
if (cleanupFunctions) {
|
|
84
|
+
Array.forEach(cleanupFunctions, cleanup => cleanup());
|
|
85
|
+
inertState.cleanups.delete(id);
|
|
86
|
+
}
|
|
87
|
+
return f();
|
|
88
|
+
});
|
package/dist/task/public.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { getTime, getTimeZone, getZonedTime, getZonedTimeIn, focus, randomInt, } from './index';
|
|
1
|
+
export { getTime, getTimeZone, getZonedTime, getZonedTimeIn, focus, showModal, closeModal, clickElement, delay, scrollIntoView, randomInt, nextFrame, waitForTransitions, } from './index';
|
|
2
2
|
//# sourceMappingURL=public.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../src/task/public.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,WAAW,EACX,YAAY,EACZ,cAAc,EACd,KAAK,EACL,SAAS,
|
|
1
|
+
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../src/task/public.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,WAAW,EACX,YAAY,EACZ,cAAc,EACd,KAAK,EACL,SAAS,EACT,UAAU,EACV,YAAY,EACZ,KAAK,EACL,cAAc,EACd,SAAS,EACT,SAAS,EACT,kBAAkB,GACnB,MAAM,SAAS,CAAA"}
|
package/dist/task/public.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { getTime, getTimeZone, getZonedTime, getZonedTimeIn, focus, randomInt, } from './index';
|
|
1
|
+
export { getTime, getTimeZone, getZonedTime, getZonedTimeIn, focus, showModal, closeModal, clickElement, delay, scrollIntoView, randomInt, nextFrame, waitForTransitions, } from './index';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a command that generates a random integer between min (inclusive) and max (exclusive)
|
|
4
|
+
* and passes it to a message constructor.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* Task.randomInt(0, 100, value => GotRandom({ value }))
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare const randomInt: <Message>(min: number, max: number, f: (value: number) => Message) => Effect.Effect<Message>;
|
|
12
|
+
//# sourceMappingURL=random.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../src/task/random.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,EAC/B,KAAK,MAAM,EACX,KAAK,MAAM,EACX,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,KAC5B,MAAM,CAAC,MAAM,CAAC,OAAO,CAC6C,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a command that generates a random integer between min (inclusive) and max (exclusive)
|
|
4
|
+
* and passes it to a message constructor.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* Task.randomInt(0, 100, value => GotRandom({ value }))
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export const randomInt = (min, max, f) => Effect.sync(() => f(Math.floor(Math.random() * (max - min)) + min));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a command that locks page scroll by setting `overflow: hidden` on the
|
|
4
|
+
* document element. Compensates for scrollbar width with padding to prevent layout
|
|
5
|
+
* shift. Uses reference counting so nested locks are safe — the page only unlocks
|
|
6
|
+
* when every lock has been released.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* Task.lockScroll(() => NoOp())
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare const lockScroll: <Message>(f: () => Message) => Effect.Effect<Message>;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a command that releases one scroll lock. When the last lock is released,
|
|
16
|
+
* restores the original `overflow` and `padding-right` on the document element.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* Task.unlockScroll(() => NoOp())
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const unlockScroll: <Message>(f: () => Message) => Effect.Effect<Message>;
|
|
24
|
+
//# sourceMappingURL=scrollLock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrollLock.d.ts","sourceRoot":"","sources":["../../src/task/scrollLock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAA;AAQvC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,EAAE,GAAG,MAAM,OAAO,KAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAqBxE,CAAA;AAEJ;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,EAClC,GAAG,MAAM,OAAO,KACf,MAAM,CAAC,MAAM,CAAC,OAAO,CAapB,CAAA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Effect, Number } from 'effect';
|
|
2
|
+
const scrollLockState = {
|
|
3
|
+
count: 0,
|
|
4
|
+
overflow: '',
|
|
5
|
+
paddingRight: '',
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Creates a command that locks page scroll by setting `overflow: hidden` on the
|
|
9
|
+
* document element. Compensates for scrollbar width with padding to prevent layout
|
|
10
|
+
* shift. Uses reference counting so nested locks are safe — the page only unlocks
|
|
11
|
+
* when every lock has been released.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* Task.lockScroll(() => NoOp())
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export const lockScroll = (f) => Effect.sync(() => {
|
|
19
|
+
const { documentElement, documentElement: { style }, } = document;
|
|
20
|
+
if (scrollLockState.count === 0) {
|
|
21
|
+
scrollLockState.overflow = style.overflow;
|
|
22
|
+
scrollLockState.paddingRight = style.paddingRight;
|
|
23
|
+
const scrollbarWidth = window.innerWidth - documentElement.clientWidth;
|
|
24
|
+
style.overflow = 'hidden';
|
|
25
|
+
style.paddingRight =
|
|
26
|
+
scrollbarWidth > 0 ? `${scrollbarWidth}px` : style.paddingRight;
|
|
27
|
+
}
|
|
28
|
+
scrollLockState.count++;
|
|
29
|
+
return f();
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Creates a command that releases one scroll lock. When the last lock is released,
|
|
33
|
+
* restores the original `overflow` and `padding-right` on the document element.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* Task.unlockScroll(() => NoOp())
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export const unlockScroll = (f) => Effect.sync(() => {
|
|
41
|
+
scrollLockState.count = Math.max(0, Number.decrement(scrollLockState.count));
|
|
42
|
+
if (scrollLockState.count === 0) {
|
|
43
|
+
const { documentElement: { style }, } = document;
|
|
44
|
+
style.overflow = scrollLockState.overflow;
|
|
45
|
+
style.paddingRight = scrollLockState.paddingRight;
|
|
46
|
+
}
|
|
47
|
+
return f();
|
|
48
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { DateTime, Effect } from 'effect';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a command that gets the current UTC time and passes it to a message constructor.
|
|
4
|
+
* This is similar to Elm's `Task.perform` with `Time.now`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* Task.getTime(utc => GotTime({ utc }))
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare const getTime: <Message>(f: (utc: DateTime.Utc) => Message) => Effect.Effect<Message>;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a command that gets the system timezone and passes it to a message constructor.
|
|
14
|
+
* This is similar to Elm's `Task.perform` with `Time.here`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* Task.getTimeZone(zone => GotTimeZone({ zone }))
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const getTimeZone: <Message>(f: (zone: DateTime.TimeZone) => Message) => Effect.Effect<Message>;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a command that gets the current time in the system timezone and passes it to a message constructor.
|
|
24
|
+
* This combines both time and timezone in a single task.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* Task.getZonedTime(zoned => GotTime({ zoned }))
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const getZonedTime: <Message>(f: (zoned: DateTime.Zoned) => Message) => Effect.Effect<Message>;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a command that gets the current time in a specific timezone and passes it to a message constructor.
|
|
34
|
+
* If the timezone is invalid, the effect will fail with an error string.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* Task.getZonedTimeIn('America/New_York', zoned => GotNYTime({ zoned }))
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare const getZonedTimeIn: <Message>(zoneId: string, f: (zoned: DateTime.Zoned) => Message) => Effect.Effect<Message, string>;
|
|
42
|
+
//# sourceMappingURL=time.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/task/time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAA;AAEjD;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,GAAI,OAAO,EAC7B,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,KAAK,OAAO,KAChC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAgC,CAAA;AAExD;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,EACjC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,KAAK,OAAO,KACtC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAmD,CAAA;AAE3E;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,EAClC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,KAAK,OAAO,KACpC,MAAM,CAAC,MAAM,CAAC,OAAO,CAMpB,CAAA;AAEJ;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,EACpC,QAAQ,MAAM,EACd,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,KAAK,KAAK,OAAO,KACpC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAS5B,CAAA"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { DateTime, Effect, Option } from 'effect';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a command that gets the current UTC time and passes it to a message constructor.
|
|
4
|
+
* This is similar to Elm's `Task.perform` with `Time.now`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* Task.getTime(utc => GotTime({ utc }))
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export const getTime = (f) => Effect.map(DateTime.now, f);
|
|
12
|
+
/**
|
|
13
|
+
* Creates a command that gets the system timezone and passes it to a message constructor.
|
|
14
|
+
* This is similar to Elm's `Task.perform` with `Time.here`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* Task.getTimeZone(zone => GotTimeZone({ zone }))
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export const getTimeZone = (f) => Effect.sync(() => f(DateTime.zoneMakeLocal()));
|
|
22
|
+
/**
|
|
23
|
+
* Creates a command that gets the current time in the system timezone and passes it to a message constructor.
|
|
24
|
+
* This combines both time and timezone in a single task.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* Task.getZonedTime(zoned => GotTime({ zoned }))
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export const getZonedTime = (f) => Effect.gen(function* () {
|
|
32
|
+
const utc = yield* DateTime.now;
|
|
33
|
+
const zone = DateTime.zoneMakeLocal();
|
|
34
|
+
const zoned = DateTime.setZone(utc, zone);
|
|
35
|
+
return f(zoned);
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Creates a command that gets the current time in a specific timezone and passes it to a message constructor.
|
|
39
|
+
* If the timezone is invalid, the effect will fail with an error string.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* Task.getZonedTimeIn('America/New_York', zoned => GotNYTime({ zoned }))
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export const getZonedTimeIn = (zoneId, f) => Effect.gen(function* () {
|
|
47
|
+
const utc = yield* DateTime.now;
|
|
48
|
+
const maybeZone = DateTime.zoneMakeNamed(zoneId);
|
|
49
|
+
if (Option.isNone(maybeZone)) {
|
|
50
|
+
return yield* Effect.fail(`Invalid timezone: ${zoneId}`);
|
|
51
|
+
}
|
|
52
|
+
const zoned = DateTime.setZone(utc, maybeZone.value);
|
|
53
|
+
return f(zoned);
|
|
54
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Duration, Effect } from 'effect';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a command that resolves to a message after a delay.
|
|
4
|
+
* Useful for debouncing, such as clearing a typeahead search query.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* Task.delay(350, () => ClearedSearch({ version: model.searchVersion }))
|
|
9
|
+
* Task.delay(Duration.seconds(1), () => TimedOut())
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const delay: <Message>(duration: Duration.DurationInput, f: () => Message) => Effect.Effect<Message>;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a command that resolves to a message after two animation frames,
|
|
15
|
+
* ensuring the browser has painted the current state before proceeding.
|
|
16
|
+
* Used for CSS transition orchestration — the double-rAF guarantees the "from"
|
|
17
|
+
* state is visible before transitioning to the "to" state.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* Task.nextFrame(() => TransitionFrameAdvanced())
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare const nextFrame: <Message>(f: () => Message) => Effect.Effect<Message>;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a command that waits for all CSS transitions on the element matching the selector
|
|
27
|
+
* to complete, then resolves to a message. Uses the Web Animations API for reliable detection.
|
|
28
|
+
* Falls back to resolving immediately if the element is missing or has no active transitions.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* Task.waitForTransitions('#menu-items', () => TransitionEnded())
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const waitForTransitions: <Message>(selector: string, f: () => Message) => Effect.Effect<Message>;
|
|
36
|
+
//# sourceMappingURL=timing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timing.d.ts","sourceRoot":"","sources":["../../src/task/timing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEzC;;;;;;;;;GASG;AACH,eAAO,MAAM,KAAK,GAAI,OAAO,EAC3B,UAAU,QAAQ,CAAC,aAAa,EAChC,GAAG,MAAM,OAAO,KACf,MAAM,CAAC,MAAM,CAAC,OAAO,CAIpB,CAAA;AAEJ;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,EAAE,GAAG,MAAM,OAAO,KAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAOvE,CAAA;AAEJ;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,GAAI,OAAO,EACxC,UAAU,MAAM,EAChB,GAAG,MAAM,OAAO,KACf,MAAM,CAAC,MAAM,CAAC,OAAO,CAgBpB,CAAA"}
|