@foldkit/ui 0.112.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/LICENSE +21 -0
- package/README.md +67 -0
- package/dist/anchor.d.ts +38 -0
- package/dist/anchor.d.ts.map +1 -0
- package/dist/anchor.js +142 -0
- package/dist/animation/index.d.ts +49 -0
- package/dist/animation/index.d.ts.map +1 -0
- package/dist/animation/index.js +75 -0
- package/dist/animation/public.d.ts +3 -0
- package/dist/animation/public.d.ts.map +1 -0
- package/dist/animation/public.js +1 -0
- package/dist/animation/schema.d.ts +43 -0
- package/dist/animation/schema.d.ts.map +1 -0
- package/dist/animation/schema.js +41 -0
- package/dist/animation/update.d.ts +24 -0
- package/dist/animation/update.d.ts.map +1 -0
- package/dist/animation/update.js +67 -0
- package/dist/button/index.d.ts +17 -0
- package/dist/button/index.d.ts.map +1 -0
- package/dist/button/index.js +22 -0
- package/dist/button/public.d.ts +3 -0
- package/dist/button/public.d.ts.map +1 -0
- package/dist/button/public.js +1 -0
- package/dist/calendar/index.d.ts +462 -0
- package/dist/calendar/index.d.ts.map +1 -0
- package/dist/calendar/index.js +825 -0
- package/dist/calendar/public.d.ts +3 -0
- package/dist/calendar/public.d.ts.map +1 -0
- package/dist/calendar/public.js +1 -0
- package/dist/checkbox/index.d.ts +119 -0
- package/dist/checkbox/index.d.ts.map +1 -0
- package/dist/checkbox/index.js +111 -0
- package/dist/checkbox/public.d.ts +3 -0
- package/dist/checkbox/public.d.ts.map +1 -0
- package/dist/checkbox/public.js +1 -0
- package/dist/combobox/multi.d.ts +183 -0
- package/dist/combobox/multi.d.ts.map +1 -0
- package/dist/combobox/multi.js +81 -0
- package/dist/combobox/multiPublic.d.ts +3 -0
- package/dist/combobox/multiPublic.d.ts.map +1 -0
- package/dist/combobox/multiPublic.js +1 -0
- package/dist/combobox/public.d.ts +7 -0
- package/dist/combobox/public.d.ts.map +1 -0
- package/dist/combobox/public.js +3 -0
- package/dist/combobox/shared.d.ts +423 -0
- package/dist/combobox/shared.d.ts.map +1 -0
- package/dist/combobox/shared.js +708 -0
- package/dist/combobox/single.d.ts +198 -0
- package/dist/combobox/single.d.ts.map +1 -0
- package/dist/combobox/single.js +106 -0
- package/dist/datePicker/index.d.ts +457 -0
- package/dist/datePicker/index.d.ts.map +1 -0
- package/dist/datePicker/index.js +318 -0
- package/dist/datePicker/public.d.ts +3 -0
- package/dist/datePicker/public.d.ts.map +1 -0
- package/dist/datePicker/public.js +1 -0
- package/dist/dialog/index.d.ts +160 -0
- package/dist/dialog/index.d.ts.map +1 -0
- package/dist/dialog/index.js +211 -0
- package/dist/dialog/public.d.ts +3 -0
- package/dist/dialog/public.d.ts.map +1 -0
- package/dist/dialog/public.js +1 -0
- package/dist/disclosure/index.d.ts +110 -0
- package/dist/disclosure/index.d.ts.map +1 -0
- package/dist/disclosure/index.js +111 -0
- package/dist/disclosure/public.d.ts +3 -0
- package/dist/disclosure/public.d.ts.map +1 -0
- package/dist/disclosure/public.js +1 -0
- package/dist/dragAndDrop/index.d.ts +540 -0
- package/dist/dragAndDrop/index.d.ts.map +1 -0
- package/dist/dragAndDrop/index.js +535 -0
- package/dist/dragAndDrop/public.d.ts +3 -0
- package/dist/dragAndDrop/public.d.ts.map +1 -0
- package/dist/dragAndDrop/public.js +1 -0
- package/dist/fieldset/index.d.ts +21 -0
- package/dist/fieldset/index.d.ts.map +1 -0
- package/dist/fieldset/index.js +25 -0
- package/dist/fieldset/public.d.ts +3 -0
- package/dist/fieldset/public.d.ts.map +1 -0
- package/dist/fieldset/public.js +1 -0
- package/dist/fileDrop/index.d.ts +109 -0
- package/dist/fileDrop/index.d.ts.map +1 -0
- package/dist/fileDrop/index.js +127 -0
- package/dist/fileDrop/public.d.ts +3 -0
- package/dist/fileDrop/public.d.ts.map +1 -0
- package/dist/fileDrop/public.js +1 -0
- package/dist/group.d.ts +8 -0
- package/dist/group.d.ts.map +1 -0
- package/dist/group.js +13 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/input/index.d.ts +26 -0
- package/dist/input/index.d.ts.map +1 -0
- package/dist/input/index.js +43 -0
- package/dist/input/public.d.ts +3 -0
- package/dist/input/public.d.ts.map +1 -0
- package/dist/input/public.js +1 -0
- package/dist/internal/optionExtensions.d.ts +6 -0
- package/dist/internal/optionExtensions.d.ts.map +1 -0
- package/dist/internal/optionExtensions.js +2 -0
- package/dist/keyboard.d.ts +6 -0
- package/dist/keyboard.d.ts.map +1 -0
- package/dist/keyboard.js +9 -0
- package/dist/listbox/multi.d.ts +189 -0
- package/dist/listbox/multi.d.ts.map +1 -0
- package/dist/listbox/multi.js +65 -0
- package/dist/listbox/multiPublic.d.ts +3 -0
- package/dist/listbox/multiPublic.d.ts.map +1 -0
- package/dist/listbox/multiPublic.js +1 -0
- package/dist/listbox/public.d.ts +7 -0
- package/dist/listbox/public.d.ts.map +1 -0
- package/dist/listbox/public.js +3 -0
- package/dist/listbox/shared.d.ts +432 -0
- package/dist/listbox/shared.d.ts.map +1 -0
- package/dist/listbox/shared.js +670 -0
- package/dist/listbox/single.d.ts +207 -0
- package/dist/listbox/single.d.ts.map +1 -0
- package/dist/listbox/single.js +73 -0
- package/dist/menu/index.d.ts +368 -0
- package/dist/menu/index.d.ts.map +1 -0
- package/dist/menu/index.js +682 -0
- package/dist/menu/public.d.ts +4 -0
- package/dist/menu/public.d.ts.map +1 -0
- package/dist/menu/public.js +1 -0
- package/dist/popover/index.d.ts +267 -0
- package/dist/popover/index.d.ts.map +1 -0
- package/dist/popover/index.js +346 -0
- package/dist/popover/public.d.ts +4 -0
- package/dist/popover/public.d.ts.map +1 -0
- package/dist/popover/public.js +1 -0
- package/dist/radioGroup/index.d.ts +169 -0
- package/dist/radioGroup/index.d.ts.map +1 -0
- package/dist/radioGroup/index.js +197 -0
- package/dist/radioGroup/public.d.ts +3 -0
- package/dist/radioGroup/public.d.ts.map +1 -0
- package/dist/radioGroup/public.js +1 -0
- package/dist/select/index.d.ts +24 -0
- package/dist/select/index.d.ts.map +1 -0
- package/dist/select/index.js +40 -0
- package/dist/select/public.d.ts +3 -0
- package/dist/select/public.d.ts.map +1 -0
- package/dist/select/public.js +1 -0
- package/dist/slider/index.d.ts +318 -0
- package/dist/slider/index.d.ts.map +1 -0
- package/dist/slider/index.js +337 -0
- package/dist/slider/public.d.ts +3 -0
- package/dist/slider/public.d.ts.map +1 -0
- package/dist/slider/public.js +1 -0
- package/dist/switch/index.d.ts +99 -0
- package/dist/switch/index.d.ts.map +1 -0
- package/dist/switch/index.js +107 -0
- package/dist/switch/public.d.ts +3 -0
- package/dist/switch/public.d.ts.map +1 -0
- package/dist/switch/public.js +1 -0
- package/dist/tabs/index.d.ts +155 -0
- package/dist/tabs/index.d.ts.map +1 -0
- package/dist/tabs/index.js +185 -0
- package/dist/tabs/public.d.ts +3 -0
- package/dist/tabs/public.d.ts.map +1 -0
- package/dist/tabs/public.js +1 -0
- package/dist/test/apps/disabledButton.d.ts +38 -0
- package/dist/test/apps/disabledButton.d.ts.map +1 -0
- package/dist/test/apps/disabledButton.js +71 -0
- package/dist/textarea/index.d.ts +26 -0
- package/dist/textarea/index.d.ts.map +1 -0
- package/dist/textarea/index.js +44 -0
- package/dist/textarea/public.d.ts +3 -0
- package/dist/textarea/public.d.ts.map +1 -0
- package/dist/textarea/public.js +1 -0
- package/dist/toast/index.d.ts +608 -0
- package/dist/toast/index.d.ts.map +1 -0
- package/dist/toast/index.js +146 -0
- package/dist/toast/public.d.ts +4 -0
- package/dist/toast/public.d.ts.map +1 -0
- package/dist/toast/public.js +1 -0
- package/dist/toast/schema.d.ts +154 -0
- package/dist/toast/schema.d.ts.map +1 -0
- package/dist/toast/schema.js +93 -0
- package/dist/toast/update.d.ts +510 -0
- package/dist/toast/update.d.ts.map +1 -0
- package/dist/toast/update.js +225 -0
- package/dist/tooltip/index.d.ts +170 -0
- package/dist/tooltip/index.d.ts.map +1 -0
- package/dist/tooltip/index.js +253 -0
- package/dist/tooltip/public.d.ts +4 -0
- package/dist/tooltip/public.d.ts.map +1 -0
- package/dist/tooltip/public.js +1 -0
- package/dist/typeahead.d.ts +4 -0
- package/dist/typeahead.d.ts.map +1 -0
- package/dist/typeahead.js +14 -0
- package/dist/virtualList/index.d.ts +203 -0
- package/dist/virtualList/index.d.ts.map +1 -0
- package/dist/virtualList/index.js +392 -0
- package/dist/virtualList/public.d.ts +3 -0
- package/dist/virtualList/public.d.ts.map +1 -0
- package/dist/virtualList/public.js +1 -0
- package/dist/vitest-setup.d.ts +2 -0
- package/dist/vitest-setup.d.ts.map +1 -0
- package/dist/vitest-setup.js +2 -0
- package/package.json +161 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Option, Schema as S } from 'effect';
|
|
2
|
+
import * as Command from 'foldkit/command';
|
|
3
|
+
import { type ChildAttribute, type Html } from 'foldkit/html';
|
|
4
|
+
/** Schema for the file-drop component's state.
|
|
5
|
+
*
|
|
6
|
+
* `isDragOver` controls the `data-drag-over` attribute on the root while a
|
|
7
|
+
* drag is hovering. The html layer's `OnDragEnter`/`OnDragLeave` handlers
|
|
8
|
+
* track the per-element active state internally so transitions between
|
|
9
|
+
* children of the zone do not flicker the boolean off-and-on. */
|
|
10
|
+
export declare const Model: S.Struct<{
|
|
11
|
+
readonly id: S.String;
|
|
12
|
+
readonly isDragOver: S.Boolean;
|
|
13
|
+
}>;
|
|
14
|
+
export type Model = typeof Model.Type;
|
|
15
|
+
/** Sent when a drag enters the drop zone. Flips `isDragOver` to true so
|
|
16
|
+
* the consumer's styling can highlight the zone. */
|
|
17
|
+
export declare const EnteredDragZone: import("foldkit/schema").CallableTaggedStruct<"EnteredDragZone", {}>;
|
|
18
|
+
/** Sent when a drag leaves the drop zone without dropping. Flips
|
|
19
|
+
* `isDragOver` back to false. */
|
|
20
|
+
export declare const LeftDragZone: import("foldkit/schema").CallableTaggedStruct<"LeftDragZone", {}>;
|
|
21
|
+
/** Sent when the user drops files on the zone or selects them via the
|
|
22
|
+
* hidden `<input type="file">`. Carries a non-empty list of `File`
|
|
23
|
+
* objects, resets `isDragOver`, and emits `ReceivedFiles` as an
|
|
24
|
+
* OutMessage. */
|
|
25
|
+
export declare const DroppedFiles: import("foldkit/schema").CallableTaggedStruct<"DroppedFiles", {
|
|
26
|
+
files: S.NonEmptyArray<S.Schema<File>>;
|
|
27
|
+
}>;
|
|
28
|
+
/** Sent when a drop or input-change event fires without any files,
|
|
29
|
+
* typically a drag of non-file data (text, URLs, images from another
|
|
30
|
+
* page). Resets `isDragOver` and emits `RejectedNonFiles` as an
|
|
31
|
+
* OutMessage so the consumer can surface a message (e.g. "Only files are
|
|
32
|
+
* accepted"). */
|
|
33
|
+
export declare const DroppedNonFiles: import("foldkit/schema").CallableTaggedStruct<"DroppedNonFiles", {}>;
|
|
34
|
+
/** Union of all messages the file-drop component can produce. */
|
|
35
|
+
export declare const Message: S.Union<readonly [import("foldkit/schema").CallableTaggedStruct<"EnteredDragZone", {}>, import("foldkit/schema").CallableTaggedStruct<"LeftDragZone", {}>, import("foldkit/schema").CallableTaggedStruct<"DroppedFiles", {
|
|
36
|
+
files: S.NonEmptyArray<S.Schema<File>>;
|
|
37
|
+
}>, import("foldkit/schema").CallableTaggedStruct<"DroppedNonFiles", {}>]>;
|
|
38
|
+
export type Message = typeof Message.Type;
|
|
39
|
+
/** Emitted when files arrive via drop or input-change. The consumer's
|
|
40
|
+
* parent update handles this to process the files (validate, upload,
|
|
41
|
+
* store in Model, etc.). The files list is non-empty. */
|
|
42
|
+
export declare const ReceivedFiles: import("foldkit/schema").CallableTaggedStruct<"ReceivedFiles", {
|
|
43
|
+
files: S.NonEmptyArray<S.Schema<File>>;
|
|
44
|
+
}>;
|
|
45
|
+
/** Emitted when a drop or input-change event produces no files. The
|
|
46
|
+
* consumer's parent update handles this to surface a message (e.g. "Only
|
|
47
|
+
* files are accepted"). */
|
|
48
|
+
export declare const RejectedNonFiles: import("foldkit/schema").CallableTaggedStruct<"RejectedNonFiles", {}>;
|
|
49
|
+
/** The file-drop component's OutMessages: `ReceivedFiles` on the happy
|
|
50
|
+
* path and `RejectedNonFiles` when a drop event fires without files. */
|
|
51
|
+
export declare const OutMessage: S.Union<readonly [import("foldkit/schema").CallableTaggedStruct<"ReceivedFiles", {
|
|
52
|
+
files: S.NonEmptyArray<S.Schema<File>>;
|
|
53
|
+
}>, import("foldkit/schema").CallableTaggedStruct<"RejectedNonFiles", {}>]>;
|
|
54
|
+
export type OutMessage = typeof OutMessage.Type;
|
|
55
|
+
/** Configuration for creating a file-drop model with `init`. */
|
|
56
|
+
export type InitConfig = Readonly<{
|
|
57
|
+
id: string;
|
|
58
|
+
}>;
|
|
59
|
+
/** Creates an initial file-drop model. Drag state starts cleared. */
|
|
60
|
+
export declare const init: (config: InitConfig) => Model;
|
|
61
|
+
type UpdateReturn = readonly [
|
|
62
|
+
Model,
|
|
63
|
+
ReadonlyArray<Command.Command<Message>>,
|
|
64
|
+
Option.Option<OutMessage>
|
|
65
|
+
];
|
|
66
|
+
/** Processes a file-drop message and returns the next model, commands,
|
|
67
|
+
* and optional OutMessage. */
|
|
68
|
+
export declare const update: (model: Model, message: Message) => UpdateReturn;
|
|
69
|
+
/** Attribute groups the file-drop component provides to the consumer's
|
|
70
|
+
* `toView` callback. */
|
|
71
|
+
export type FileDropAttributes = Readonly<{
|
|
72
|
+
/** Attributes for the outer drop zone element (typically a `<label>`):
|
|
73
|
+
* drag-and-drop handlers, `data-drag-over` while a drag hovers, and
|
|
74
|
+
* `data-disabled` when disabled. */
|
|
75
|
+
root: ReadonlyArray<ChildAttribute>;
|
|
76
|
+
/** Attributes for a hidden `<input type="file">` nested inside the
|
|
77
|
+
* root: file-change handler, `type`, `id`, `multiple`, `accept`, and
|
|
78
|
+
* `sr-only` class. */
|
|
79
|
+
input: ReadonlyArray<ChildAttribute>;
|
|
80
|
+
}>;
|
|
81
|
+
/** Per-render view inputs passed to `view` via `h.submodel`'s `viewInputs` field. */
|
|
82
|
+
export type ViewInputs = Readonly<{
|
|
83
|
+
toView: (attributes: FileDropAttributes) => Html;
|
|
84
|
+
accept?: ReadonlyArray<string>;
|
|
85
|
+
multiple?: boolean;
|
|
86
|
+
isDisabled?: boolean;
|
|
87
|
+
}>;
|
|
88
|
+
/** Renders an accessible file-drop zone by publishing attribute groups
|
|
89
|
+
* for a `<label>`-wrapped hidden file input. */
|
|
90
|
+
export declare const view: import("foldkit/submodel").View<{
|
|
91
|
+
readonly id: string;
|
|
92
|
+
readonly isDragOver: boolean;
|
|
93
|
+
}, {
|
|
94
|
+
readonly _tag: "EnteredDragZone";
|
|
95
|
+
} | {
|
|
96
|
+
readonly _tag: "LeftDragZone";
|
|
97
|
+
} | {
|
|
98
|
+
readonly _tag: "DroppedFiles";
|
|
99
|
+
readonly files: readonly [File, ...File[]];
|
|
100
|
+
} | {
|
|
101
|
+
readonly _tag: "DroppedNonFiles";
|
|
102
|
+
}, Readonly<{
|
|
103
|
+
toView: (attributes: FileDropAttributes) => Html;
|
|
104
|
+
accept?: ReadonlyArray<string>;
|
|
105
|
+
multiple?: boolean;
|
|
106
|
+
isDisabled?: boolean;
|
|
107
|
+
}>>;
|
|
108
|
+
export {};
|
|
109
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fileDrop/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,MAAM,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAA;AAC/D,OAAO,KAAK,OAAO,MAAM,iBAAiB,CAAA;AAE1C,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,IAAI,EAGV,MAAM,cAAc,CAAA;AAOrB;;;;;iEAKiE;AACjE,eAAO,MAAM,KAAK;;;EAGhB,CAAA;AACF,MAAM,MAAM,KAAK,GAAG,OAAO,KAAK,CAAC,IAAI,CAAA;AAIrC;oDACoD;AACpD,eAAO,MAAM,eAAe,sEAAuB,CAAA;AACnD;iCACiC;AACjC,eAAO,MAAM,YAAY,mEAAoB,CAAA;AAC7C;;;iBAGiB;AACjB,eAAO,MAAM,YAAY;;EAEvB,CAAA;AACF;;;;iBAIiB;AACjB,eAAO,MAAM,eAAe,sEAAuB,CAAA;AAEnD,iEAAiE;AACjE,eAAO,MAAM,OAAO;;0EAKlB,CAAA;AACF,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,IAAI,CAAA;AAIzC;;yDAEyD;AACzD,eAAO,MAAM,aAAa;;EAExB,CAAA;AAEF;;2BAE2B;AAC3B,eAAO,MAAM,gBAAgB,uEAAwB,CAAA;AAErD;wEACwE;AACxE,eAAO,MAAM,UAAU;;2EAA6C,CAAA;AACpE,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC,IAAI,CAAA;AAI/C,gEAAgE;AAChE,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC;IAChC,EAAE,EAAE,MAAM,CAAA;CACX,CAAC,CAAA;AAEF,qEAAqE;AACrE,eAAO,MAAM,IAAI,GAAI,QAAQ,UAAU,KAAG,KAGxC,CAAA;AAIF,KAAK,YAAY,GAAG,SAAS;IAC3B,KAAK;IACL,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;CAC1B,CAAA;AAED;8BAC8B;AAC9B,eAAO,MAAM,MAAM,GAAI,OAAO,KAAK,EAAE,SAAS,OAAO,KAAG,YAyBrD,CAAA;AAIH;yBACyB;AACzB,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IACxC;;yCAEqC;IACrC,IAAI,EAAE,aAAa,CAAC,cAAc,CAAC,CAAA;IACnC;;2BAEuB;IACvB,KAAK,EAAE,aAAa,CAAC,cAAc,CAAC,CAAA;CACrC,CAAC,CAAA;AAEF,qFAAqF;AACrF,MAAM,MAAM,UAAU,GAAG,QAAQ,CAAC;IAChC,MAAM,EAAE,CAAC,UAAU,EAAE,kBAAkB,KAAK,IAAI,CAAA;IAChD,MAAM,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IAC9B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB,CAAC,CAAA;AAQF;iDACiD;AACjD,eAAO,MAAM,IAAI;;;;;;;;;;;;;YAdP,CAAC,UAAU,EAAE,kBAAkB,KAAK,IAAI;aACvC,aAAa,CAAC,MAAM,CAAC;eACnB,OAAO;iBACL,OAAO;GAmDrB,CAAA"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Array, Match as M, Option, Schema as S } from 'effect';
|
|
2
|
+
import * as File from 'foldkit/file';
|
|
3
|
+
import { childAttributes, html, } from 'foldkit/html';
|
|
4
|
+
import { m } from 'foldkit/message';
|
|
5
|
+
import { evo } from 'foldkit/struct';
|
|
6
|
+
import { defineView } from 'foldkit/submodel';
|
|
7
|
+
// MODEL
|
|
8
|
+
/** Schema for the file-drop component's state.
|
|
9
|
+
*
|
|
10
|
+
* `isDragOver` controls the `data-drag-over` attribute on the root while a
|
|
11
|
+
* drag is hovering. The html layer's `OnDragEnter`/`OnDragLeave` handlers
|
|
12
|
+
* track the per-element active state internally so transitions between
|
|
13
|
+
* children of the zone do not flicker the boolean off-and-on. */
|
|
14
|
+
export const Model = S.Struct({
|
|
15
|
+
id: S.String,
|
|
16
|
+
isDragOver: S.Boolean,
|
|
17
|
+
});
|
|
18
|
+
// MESSAGE
|
|
19
|
+
/** Sent when a drag enters the drop zone. Flips `isDragOver` to true so
|
|
20
|
+
* the consumer's styling can highlight the zone. */
|
|
21
|
+
export const EnteredDragZone = m('EnteredDragZone');
|
|
22
|
+
/** Sent when a drag leaves the drop zone without dropping. Flips
|
|
23
|
+
* `isDragOver` back to false. */
|
|
24
|
+
export const LeftDragZone = m('LeftDragZone');
|
|
25
|
+
/** Sent when the user drops files on the zone or selects them via the
|
|
26
|
+
* hidden `<input type="file">`. Carries a non-empty list of `File`
|
|
27
|
+
* objects, resets `isDragOver`, and emits `ReceivedFiles` as an
|
|
28
|
+
* OutMessage. */
|
|
29
|
+
export const DroppedFiles = m('DroppedFiles', {
|
|
30
|
+
files: S.NonEmptyArray(File.File),
|
|
31
|
+
});
|
|
32
|
+
/** Sent when a drop or input-change event fires without any files,
|
|
33
|
+
* typically a drag of non-file data (text, URLs, images from another
|
|
34
|
+
* page). Resets `isDragOver` and emits `RejectedNonFiles` as an
|
|
35
|
+
* OutMessage so the consumer can surface a message (e.g. "Only files are
|
|
36
|
+
* accepted"). */
|
|
37
|
+
export const DroppedNonFiles = m('DroppedNonFiles');
|
|
38
|
+
/** Union of all messages the file-drop component can produce. */
|
|
39
|
+
export const Message = S.Union([
|
|
40
|
+
EnteredDragZone,
|
|
41
|
+
LeftDragZone,
|
|
42
|
+
DroppedFiles,
|
|
43
|
+
DroppedNonFiles,
|
|
44
|
+
]);
|
|
45
|
+
// OUT MESSAGE
|
|
46
|
+
/** Emitted when files arrive via drop or input-change. The consumer's
|
|
47
|
+
* parent update handles this to process the files (validate, upload,
|
|
48
|
+
* store in Model, etc.). The files list is non-empty. */
|
|
49
|
+
export const ReceivedFiles = m('ReceivedFiles', {
|
|
50
|
+
files: S.NonEmptyArray(File.File),
|
|
51
|
+
});
|
|
52
|
+
/** Emitted when a drop or input-change event produces no files. The
|
|
53
|
+
* consumer's parent update handles this to surface a message (e.g. "Only
|
|
54
|
+
* files are accepted"). */
|
|
55
|
+
export const RejectedNonFiles = m('RejectedNonFiles');
|
|
56
|
+
/** The file-drop component's OutMessages: `ReceivedFiles` on the happy
|
|
57
|
+
* path and `RejectedNonFiles` when a drop event fires without files. */
|
|
58
|
+
export const OutMessage = S.Union([ReceivedFiles, RejectedNonFiles]);
|
|
59
|
+
/** Creates an initial file-drop model. Drag state starts cleared. */
|
|
60
|
+
export const init = (config) => ({
|
|
61
|
+
id: config.id,
|
|
62
|
+
isDragOver: false,
|
|
63
|
+
});
|
|
64
|
+
/** Processes a file-drop message and returns the next model, commands,
|
|
65
|
+
* and optional OutMessage. */
|
|
66
|
+
export const update = (model, message) => M.value(message).pipe(M.withReturnType(), M.tagsExhaustive({
|
|
67
|
+
EnteredDragZone: () => [
|
|
68
|
+
evo(model, { isDragOver: () => true }),
|
|
69
|
+
[],
|
|
70
|
+
Option.none(),
|
|
71
|
+
],
|
|
72
|
+
LeftDragZone: () => [
|
|
73
|
+
evo(model, { isDragOver: () => false }),
|
|
74
|
+
[],
|
|
75
|
+
Option.none(),
|
|
76
|
+
],
|
|
77
|
+
DroppedFiles: ({ files }) => [
|
|
78
|
+
evo(model, { isDragOver: () => false }),
|
|
79
|
+
[],
|
|
80
|
+
Option.some(ReceivedFiles({ files })),
|
|
81
|
+
],
|
|
82
|
+
DroppedNonFiles: () => [
|
|
83
|
+
evo(model, { isDragOver: () => false }),
|
|
84
|
+
[],
|
|
85
|
+
Option.some(RejectedNonFiles()),
|
|
86
|
+
],
|
|
87
|
+
}));
|
|
88
|
+
const dispatchDroppedFiles = (files) => Array.match(files, {
|
|
89
|
+
onEmpty: () => DroppedNonFiles(),
|
|
90
|
+
onNonEmpty: nonEmptyFiles => DroppedFiles({ files: [...nonEmptyFiles] }),
|
|
91
|
+
});
|
|
92
|
+
/** Renders an accessible file-drop zone by publishing attribute groups
|
|
93
|
+
* for a `<label>`-wrapped hidden file input. */
|
|
94
|
+
export const view = defineView((model, viewInputs) => {
|
|
95
|
+
const h = html();
|
|
96
|
+
const { id, isDragOver } = model;
|
|
97
|
+
const { toView, accept, multiple = false, isDisabled = false } = viewInputs;
|
|
98
|
+
const stateAttributes = [
|
|
99
|
+
...(isDragOver ? [h.DataAttribute('drag-over', '')] : []),
|
|
100
|
+
...(isDisabled ? [h.DataAttribute('disabled', '')] : []),
|
|
101
|
+
];
|
|
102
|
+
const rootAttributes = isDisabled
|
|
103
|
+
? stateAttributes
|
|
104
|
+
: [
|
|
105
|
+
...stateAttributes,
|
|
106
|
+
h.OnDragEnter(EnteredDragZone()),
|
|
107
|
+
h.OnDragLeave(LeftDragZone()),
|
|
108
|
+
h.AllowDrop(),
|
|
109
|
+
h.OnDropFiles(dispatchDroppedFiles),
|
|
110
|
+
];
|
|
111
|
+
const inputAttributes = [
|
|
112
|
+
h.Id(id),
|
|
113
|
+
h.Type('file'),
|
|
114
|
+
h.Class('sr-only'),
|
|
115
|
+
...(multiple ? [h.Multiple(true)] : []),
|
|
116
|
+
...(accept !== undefined && accept.length > 0
|
|
117
|
+
? [h.Accept(accept.join(','))]
|
|
118
|
+
: []),
|
|
119
|
+
...(isDisabled
|
|
120
|
+
? [h.Disabled(true)]
|
|
121
|
+
: [h.OnFileChange(dispatchDroppedFiles)]),
|
|
122
|
+
];
|
|
123
|
+
return toView({
|
|
124
|
+
root: childAttributes(rootAttributes),
|
|
125
|
+
input: childAttributes(inputAttributes),
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { init, update, view, Model, Message, OutMessage, ReceivedFiles, EnteredDragZone, LeftDragZone, DroppedFiles, DroppedNonFiles, RejectedNonFiles, } from './index.js';
|
|
2
|
+
export type { InitConfig, ViewInputs, FileDropAttributes } from './index.js';
|
|
3
|
+
//# sourceMappingURL=public.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../src/fileDrop/public.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,KAAK,EACL,OAAO,EACP,UAAU,EACV,aAAa,EACb,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,gBAAgB,GACjB,MAAM,YAAY,CAAA;AAEnB,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { init, update, view, Model, Message, OutMessage, ReceivedFiles, EnteredDragZone, LeftDragZone, DroppedFiles, DroppedNonFiles, RejectedNonFiles, } from './index.js';
|
package/dist/group.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** A contiguous segment of items sharing the same group key. */
|
|
2
|
+
export type Segment<A> = Readonly<{
|
|
3
|
+
key: string;
|
|
4
|
+
items: ReadonlyArray<A>;
|
|
5
|
+
}>;
|
|
6
|
+
/** Groups items into contiguous segments by a key function. Adjacent items with the same key are collected into a single segment. */
|
|
7
|
+
export declare const groupContiguous: <A>(items: ReadonlyArray<A>, toKey: (item: A, index: number) => string) => ReadonlyArray<Segment<A>>;
|
|
8
|
+
//# sourceMappingURL=group.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../src/group.ts"],"names":[],"mappings":"AAEA,gEAAgE;AAChE,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,QAAQ,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC,CAAA;AAE3E,qIAAqI;AACrI,eAAO,MAAM,eAAe,GAAI,CAAC,EAC/B,OAAO,aAAa,CAAC,CAAC,CAAC,EACvB,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,KACxC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAW1B,CAAA"}
|
package/dist/group.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Array } from 'effect';
|
|
2
|
+
/** Groups items into contiguous segments by a key function. Adjacent items with the same key are collected into a single segment. */
|
|
3
|
+
export const groupContiguous = (items, toKey) => {
|
|
4
|
+
const tagged = Array.map(items, (item, index) => ({
|
|
5
|
+
key: toKey(item, index),
|
|
6
|
+
item,
|
|
7
|
+
}));
|
|
8
|
+
return Array.chop(tagged, nonEmpty => {
|
|
9
|
+
const key = Array.headNonEmpty(nonEmpty).key;
|
|
10
|
+
const [matching, rest] = Array.span(nonEmpty, tagged => tagged.key === key);
|
|
11
|
+
return [{ key, items: Array.map(matching, ({ item }) => item) }, rest];
|
|
12
|
+
});
|
|
13
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export * as Animation from './animation/public.js';
|
|
2
|
+
export * as Button from './button/public.js';
|
|
3
|
+
export * as Calendar from './calendar/public.js';
|
|
4
|
+
export * as DatePicker from './datePicker/public.js';
|
|
5
|
+
export * as Checkbox from './checkbox/public.js';
|
|
6
|
+
export * as Combobox from './combobox/public.js';
|
|
7
|
+
export * as Dialog from './dialog/public.js';
|
|
8
|
+
export * as DragAndDrop from './dragAndDrop/public.js';
|
|
9
|
+
export * as Disclosure from './disclosure/public.js';
|
|
10
|
+
export * as Fieldset from './fieldset/public.js';
|
|
11
|
+
export * as FileDrop from './fileDrop/public.js';
|
|
12
|
+
export * as Input from './input/public.js';
|
|
13
|
+
export * as Listbox from './listbox/public.js';
|
|
14
|
+
export * as Menu from './menu/public.js';
|
|
15
|
+
export * as Popover from './popover/public.js';
|
|
16
|
+
export * as RadioGroup from './radioGroup/public.js';
|
|
17
|
+
export * as Select from './select/public.js';
|
|
18
|
+
export * as Slider from './slider/public.js';
|
|
19
|
+
export * as Switch from './switch/public.js';
|
|
20
|
+
export * as Textarea from './textarea/public.js';
|
|
21
|
+
export * as Tabs from './tabs/public.js';
|
|
22
|
+
export * as Toast from './toast/public.js';
|
|
23
|
+
export * as Tooltip from './tooltip/public.js';
|
|
24
|
+
export * as VirtualList from './virtualList/public.js';
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAA;AAClD,OAAO,KAAK,MAAM,MAAM,oBAAoB,CAAA;AAC5C,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAA;AAChD,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAA;AACpD,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAA;AAChD,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAA;AAChD,OAAO,KAAK,MAAM,MAAM,oBAAoB,CAAA;AAC5C,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAA;AACtD,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAA;AACpD,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAA;AAChD,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAA;AAChD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAA;AAC1C,OAAO,KAAK,OAAO,MAAM,qBAAqB,CAAA;AAC9C,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAA;AACxC,OAAO,KAAK,OAAO,MAAM,qBAAqB,CAAA;AAC9C,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAA;AACpD,OAAO,KAAK,MAAM,MAAM,oBAAoB,CAAA;AAC5C,OAAO,KAAK,MAAM,MAAM,oBAAoB,CAAA;AAC5C,OAAO,KAAK,MAAM,MAAM,oBAAoB,CAAA;AAC5C,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAA;AAChD,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAA;AACxC,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAA;AAC1C,OAAO,KAAK,OAAO,MAAM,qBAAqB,CAAA;AAC9C,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export * as Animation from './animation/public.js';
|
|
2
|
+
export * as Button from './button/public.js';
|
|
3
|
+
export * as Calendar from './calendar/public.js';
|
|
4
|
+
export * as DatePicker from './datePicker/public.js';
|
|
5
|
+
export * as Checkbox from './checkbox/public.js';
|
|
6
|
+
export * as Combobox from './combobox/public.js';
|
|
7
|
+
export * as Dialog from './dialog/public.js';
|
|
8
|
+
export * as DragAndDrop from './dragAndDrop/public.js';
|
|
9
|
+
export * as Disclosure from './disclosure/public.js';
|
|
10
|
+
export * as Fieldset from './fieldset/public.js';
|
|
11
|
+
export * as FileDrop from './fileDrop/public.js';
|
|
12
|
+
export * as Input from './input/public.js';
|
|
13
|
+
export * as Listbox from './listbox/public.js';
|
|
14
|
+
export * as Menu from './menu/public.js';
|
|
15
|
+
export * as Popover from './popover/public.js';
|
|
16
|
+
export * as RadioGroup from './radioGroup/public.js';
|
|
17
|
+
export * as Select from './select/public.js';
|
|
18
|
+
export * as Slider from './slider/public.js';
|
|
19
|
+
export * as Switch from './switch/public.js';
|
|
20
|
+
export * as Textarea from './textarea/public.js';
|
|
21
|
+
export * as Tabs from './tabs/public.js';
|
|
22
|
+
export * as Toast from './toast/public.js';
|
|
23
|
+
export * as Tooltip from './tooltip/public.js';
|
|
24
|
+
export * as VirtualList from './virtualList/public.js';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Attribute } from 'foldkit/html';
|
|
2
|
+
import type { Html } from 'foldkit/html';
|
|
3
|
+
/** Attribute groups the input component provides to the consumer's `toView` callback. */
|
|
4
|
+
export type InputAttributes<ParentMessage> = Readonly<{
|
|
5
|
+
input: ReadonlyArray<Attribute<ParentMessage>>;
|
|
6
|
+
label: ReadonlyArray<Attribute<ParentMessage>>;
|
|
7
|
+
description: ReadonlyArray<Attribute<ParentMessage>>;
|
|
8
|
+
}>;
|
|
9
|
+
/** Configuration for rendering an input with `view`. */
|
|
10
|
+
export type ViewConfig<ParentMessage> = Readonly<{
|
|
11
|
+
id: string;
|
|
12
|
+
toView: (attributes: InputAttributes<ParentMessage>) => Html;
|
|
13
|
+
onInput?: (value: string) => ParentMessage;
|
|
14
|
+
value?: string;
|
|
15
|
+
isDisabled?: boolean;
|
|
16
|
+
isInvalid?: boolean;
|
|
17
|
+
isAutofocus?: boolean;
|
|
18
|
+
name?: string;
|
|
19
|
+
type?: string;
|
|
20
|
+
placeholder?: string;
|
|
21
|
+
}>;
|
|
22
|
+
/** Generates the description element ID from the input's base ID. */
|
|
23
|
+
export declare const descriptionId: (id: string) => string;
|
|
24
|
+
/** Renders an accessible input by building ARIA attribute groups and delegating layout to the consumer's `toView` callback. */
|
|
25
|
+
export declare const view: <ParentMessage>(config: ViewConfig<ParentMessage>) => Html;
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/input/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAIxC,yFAAyF;AACzF,MAAM,MAAM,eAAe,CAAC,aAAa,IAAI,QAAQ,CAAC;IACpD,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAA;IAC9C,KAAK,EAAE,aAAa,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAA;IAC9C,WAAW,EAAE,aAAa,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAA;CACrD,CAAC,CAAA;AAEF,wDAAwD;AACxD,MAAM,MAAM,UAAU,CAAC,aAAa,IAAI,QAAQ,CAAC;IAC/C,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,CAAC,UAAU,EAAE,eAAe,CAAC,aAAa,CAAC,KAAK,IAAI,CAAA;IAC5D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,aAAa,CAAA;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAC,CAAA;AAEF,qEAAqE;AACrE,eAAO,MAAM,aAAa,GAAI,IAAI,MAAM,KAAG,MAA6B,CAAA;AAExE,+HAA+H;AAC/H,eAAO,MAAM,IAAI,GAAI,aAAa,EAChC,QAAQ,UAAU,CAAC,aAAa,CAAC,KAChC,IA6DF,CAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Predicate } from 'effect';
|
|
2
|
+
import { html } from 'foldkit/html';
|
|
3
|
+
/** Generates the description element ID from the input's base ID. */
|
|
4
|
+
export const descriptionId = (id) => `${id}-description`;
|
|
5
|
+
/** Renders an accessible input by building ARIA attribute groups and delegating layout to the consumer's `toView` callback. */
|
|
6
|
+
export const view = (config) => {
|
|
7
|
+
const h = html();
|
|
8
|
+
const { toView, id, onInput, value, isDisabled = false, isInvalid = false, isAutofocus = false, name, type = 'text', placeholder, } = config;
|
|
9
|
+
const disabledAttributes = isDisabled
|
|
10
|
+
? [h.AriaDisabled(true), h.Disabled(true), h.DataAttribute('disabled', '')]
|
|
11
|
+
: [];
|
|
12
|
+
const invalidAttributes = isInvalid
|
|
13
|
+
? [h.AriaInvalid(true), h.DataAttribute('invalid', '')]
|
|
14
|
+
: [];
|
|
15
|
+
const inputAttributes = Predicate.isNotUndefined(onInput) && !isDisabled ? [h.OnInput(onInput)] : [];
|
|
16
|
+
const valueAttributes = Predicate.isNotUndefined(value)
|
|
17
|
+
? [h.Value(value)]
|
|
18
|
+
: [];
|
|
19
|
+
const autofocusAttributes = isAutofocus ? [h.Autofocus(true)] : [];
|
|
20
|
+
const nameAttributes = Predicate.isNotUndefined(name) ? [h.Name(name)] : [];
|
|
21
|
+
const placeholderAttributes = Predicate.isNotUndefined(placeholder)
|
|
22
|
+
? [h.Placeholder(placeholder)]
|
|
23
|
+
: [];
|
|
24
|
+
const allInputAttributes = [
|
|
25
|
+
h.Id(id),
|
|
26
|
+
h.Type(type),
|
|
27
|
+
h.AriaDescribedBy(descriptionId(id)),
|
|
28
|
+
...disabledAttributes,
|
|
29
|
+
...invalidAttributes,
|
|
30
|
+
...inputAttributes,
|
|
31
|
+
...valueAttributes,
|
|
32
|
+
...autofocusAttributes,
|
|
33
|
+
...nameAttributes,
|
|
34
|
+
...placeholderAttributes,
|
|
35
|
+
];
|
|
36
|
+
const labelAttributes = [h.For(id)];
|
|
37
|
+
const descriptionAttributes = [h.Id(descriptionId(id))];
|
|
38
|
+
return toView({
|
|
39
|
+
input: allInputAttributes,
|
|
40
|
+
label: labelAttributes,
|
|
41
|
+
description: descriptionAttributes,
|
|
42
|
+
});
|
|
43
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../src/input/public.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAEhD,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { view, descriptionId } from './index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optionExtensions.d.ts","sourceRoot":"","sources":["../../src/internal/optionExtensions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEzC,eAAO,MAAM,IAAI,EAAE;IACjB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IACvD,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;CAKpD,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Whether a keyboard event key is a single printable character (not a named key like "Enter" or "ArrowDown"). */
|
|
2
|
+
export declare const isPrintableKey: (key: string) => boolean;
|
|
3
|
+
export declare const wrapIndex: (index: number, length: number) => number;
|
|
4
|
+
export declare const findFirstEnabledIndex: (itemCount: number, focusedIndex: number, isDisabled: (index: number) => boolean) => (startIndex: number, direction: 1 | -1) => number;
|
|
5
|
+
export declare const keyToIndex: (nextKey: string, previousKey: string, itemCount: number, focusedIndex: number, isDisabled: (index: number) => boolean) => ((key: string) => number);
|
|
6
|
+
//# sourceMappingURL=keyboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../src/keyboard.ts"],"names":[],"mappings":"AAEA,kHAAkH;AAClH,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,KAAG,OAA2B,CAAA;AAExE,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,EAAE,QAAQ,MAAM,KAAG,MACpB,CAAA;AAEtC,eAAO,MAAM,qBAAqB,GAE9B,WAAW,MAAM,EACjB,cAAc,MAAM,EACpB,YAAY,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,MAEvC,YAAY,MAAM,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,KAAG,MAMtC,CAAA;AAEL,eAAO,MAAM,UAAU,GACrB,SAAS,MAAM,EACf,aAAa,MAAM,EACnB,WAAW,MAAM,EACjB,cAAc,MAAM,EACpB,YAAY,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,KACrC,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAW1B,CAAA"}
|
package/dist/keyboard.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Array, Match as M, Option, Predicate, pipe } from 'effect';
|
|
2
|
+
/** Whether a keyboard event key is a single printable character (not a named key like "Enter" or "ArrowDown"). */
|
|
3
|
+
export const isPrintableKey = (key) => key.length === 1;
|
|
4
|
+
export const wrapIndex = (index, length) => ((index % length) + length) % length;
|
|
5
|
+
export const findFirstEnabledIndex = (itemCount, focusedIndex, isDisabled) => (startIndex, direction) => pipe(itemCount, Array.makeBy(step => wrapIndex(startIndex + step * direction, itemCount)), Array.findFirst(Predicate.not(isDisabled)), Option.getOrElse(() => focusedIndex));
|
|
6
|
+
export const keyToIndex = (nextKey, previousKey, itemCount, focusedIndex, isDisabled) => {
|
|
7
|
+
const find = findFirstEnabledIndex(itemCount, focusedIndex, isDisabled);
|
|
8
|
+
return (key) => M.value(key).pipe(M.when(nextKey, () => find(focusedIndex + 1, 1)), M.when(previousKey, () => find(focusedIndex - 1, -1)), M.whenOr('Home', 'PageUp', () => find(0, 1)), M.whenOr('End', 'PageDown', () => find(itemCount - 1, -1)), M.orElse(() => focusedIndex));
|
|
9
|
+
};
|