foldkit 0.100.1 → 0.102.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 +3 -2
- package/dist/canvas/view.d.ts +1 -1
- package/dist/canvas/view.d.ts.map +1 -1
- package/dist/canvas/view.js +5 -5
- package/dist/command/index.d.ts +71 -0
- package/dist/command/index.d.ts.map +1 -1
- package/dist/command/index.js +34 -1
- package/dist/command/public.d.ts +1 -1
- package/dist/command/public.d.ts.map +1 -1
- package/dist/command/public.js +1 -1
- package/dist/devTools/overlay.d.ts.map +1 -1
- package/dist/devTools/overlay.js +156 -149
- package/dist/dom/dom.d.ts +8 -11
- package/dist/dom/dom.d.ts.map +1 -1
- package/dist/dom/dom.js +8 -11
- package/dist/dom/elementMovement.d.ts +1 -3
- package/dist/dom/elementMovement.d.ts.map +1 -1
- package/dist/dom/elementMovement.js +1 -3
- package/dist/dom/inert.d.ts +2 -4
- package/dist/dom/inert.d.ts.map +1 -1
- package/dist/dom/inert.js +2 -4
- package/dist/dom/scrollLock.d.ts +2 -2
- package/dist/dom/scrollLock.js +2 -2
- package/dist/dom/waitForAnimation.d.ts +1 -1
- package/dist/dom/waitForAnimation.js +1 -1
- package/dist/html/boundary.d.ts +98 -0
- package/dist/html/boundary.d.ts.map +1 -0
- package/dist/html/boundary.js +176 -0
- package/dist/html/childAttribute.d.ts +44 -0
- package/dist/html/childAttribute.d.ts.map +1 -0
- package/dist/html/childAttribute.js +34 -0
- package/dist/html/index.d.ts +70 -23
- package/dist/html/index.d.ts.map +1 -1
- package/dist/html/index.js +639 -575
- package/dist/html/lazy.d.ts +12 -7
- package/dist/html/lazy.d.ts.map +1 -1
- package/dist/html/lazy.js +30 -11
- package/dist/html/public.d.ts +2 -2
- package/dist/html/public.d.ts.map +1 -1
- package/dist/html/public.js +1 -1
- package/dist/html/runtimeSingleton.d.ts +72 -0
- package/dist/html/runtimeSingleton.d.ts.map +1 -0
- package/dist/html/runtimeSingleton.js +112 -0
- package/dist/html/submodel.d.ts +98 -0
- package/dist/html/submodel.d.ts.map +1 -0
- package/dist/html/submodel.js +190 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/render/render.d.ts +1 -1
- package/dist/render/render.js +1 -1
- package/dist/runtime/messagePriority.d.ts +5 -1
- package/dist/runtime/messagePriority.d.ts.map +1 -1
- package/dist/runtime/messagePriority.js +25 -4
- package/dist/runtime/runtime.d.ts +11 -11
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +118 -63
- package/dist/runtime/subscription.d.ts +139 -19
- package/dist/runtime/subscription.d.ts.map +1 -1
- package/dist/runtime/subscription.js +90 -9
- package/dist/submodel/public.d.ts +4 -0
- package/dist/submodel/public.d.ts.map +1 -0
- package/dist/submodel/public.js +1 -0
- package/dist/submodel/submodel.d.ts +32 -0
- package/dist/submodel/submodel.d.ts.map +1 -0
- package/dist/submodel/submodel.js +1 -0
- package/dist/subscription/animationFrame.d.ts +23 -26
- package/dist/subscription/animationFrame.d.ts.map +1 -1
- package/dist/subscription/animationFrame.js +17 -18
- package/dist/subscription/public.d.ts +2 -2
- package/dist/subscription/public.d.ts.map +1 -1
- package/dist/subscription/public.js +1 -1
- package/dist/test/apps/disabledButton.d.ts +4 -5
- package/dist/test/apps/disabledButton.d.ts.map +1 -1
- package/dist/test/apps/disabledButton.js +16 -16
- package/dist/test/scene.d.ts +8 -8
- package/dist/test/scene.d.ts.map +1 -1
- package/dist/test/scene.js +25 -13
- package/dist/test/story.d.ts +15 -8
- package/dist/test/story.d.ts.map +1 -1
- package/dist/test/story.js +21 -9
- package/dist/ui/animation/index.d.ts +30 -14
- package/dist/ui/animation/index.d.ts.map +1 -1
- package/dist/ui/animation/index.js +9 -19
- package/dist/ui/animation/public.d.ts +2 -2
- package/dist/ui/animation/public.d.ts.map +1 -1
- package/dist/ui/animation/public.js +1 -1
- package/dist/ui/calendar/index.d.ts +199 -84
- package/dist/ui/calendar/index.d.ts.map +1 -1
- package/dist/ui/calendar/index.js +129 -140
- package/dist/ui/calendar/public.d.ts +2 -2
- package/dist/ui/calendar/public.d.ts.map +1 -1
- package/dist/ui/calendar/public.js +1 -1
- package/dist/ui/checkbox/index.d.ts +93 -21
- package/dist/ui/checkbox/index.d.ts.map +1 -1
- package/dist/ui/checkbox/index.js +62 -33
- package/dist/ui/checkbox/public.d.ts +2 -2
- package/dist/ui/checkbox/public.d.ts.map +1 -1
- package/dist/ui/checkbox/public.js +1 -1
- package/dist/ui/combobox/multi.d.ts +35 -91
- package/dist/ui/combobox/multi.d.ts.map +1 -1
- package/dist/ui/combobox/multi.js +34 -17
- package/dist/ui/combobox/multiPublic.d.ts +2 -2
- package/dist/ui/combobox/multiPublic.d.ts.map +1 -1
- package/dist/ui/combobox/multiPublic.js +1 -1
- package/dist/ui/combobox/public.d.ts +3 -3
- package/dist/ui/combobox/public.d.ts.map +1 -1
- package/dist/ui/combobox/public.js +2 -2
- package/dist/ui/combobox/shared.d.ts +56 -31
- package/dist/ui/combobox/shared.d.ts.map +1 -1
- package/dist/ui/combobox/shared.js +333 -322
- package/dist/ui/combobox/single.d.ts +46 -93
- package/dist/ui/combobox/single.d.ts.map +1 -1
- package/dist/ui/combobox/single.js +44 -17
- package/dist/ui/datePicker/index.d.ts +256 -48
- package/dist/ui/datePicker/index.d.ts.map +1 -1
- package/dist/ui/datePicker/index.js +149 -104
- package/dist/ui/datePicker/public.d.ts +2 -2
- package/dist/ui/datePicker/public.d.ts.map +1 -1
- package/dist/ui/datePicker/public.js +1 -1
- package/dist/ui/dialog/index.d.ts +95 -39
- package/dist/ui/dialog/index.d.ts.map +1 -1
- package/dist/ui/dialog/index.js +71 -62
- package/dist/ui/dialog/public.d.ts +2 -2
- package/dist/ui/dialog/public.d.ts.map +1 -1
- package/dist/ui/dialog/public.js +1 -1
- package/dist/ui/disclosure/index.d.ts +71 -31
- package/dist/ui/disclosure/index.d.ts.map +1 -1
- package/dist/ui/disclosure/index.js +57 -62
- package/dist/ui/disclosure/public.d.ts +2 -2
- package/dist/ui/disclosure/public.d.ts.map +1 -1
- package/dist/ui/disclosure/public.js +1 -1
- package/dist/ui/dragAndDrop/index.d.ts +385 -103
- package/dist/ui/dragAndDrop/index.d.ts.map +1 -1
- package/dist/ui/dragAndDrop/index.js +26 -31
- package/dist/ui/dragAndDrop/public.d.ts +1 -1
- package/dist/ui/dragAndDrop/public.d.ts.map +1 -1
- package/dist/ui/dragAndDrop/public.js +1 -1
- package/dist/ui/fileDrop/index.d.ts +42 -46
- package/dist/ui/fileDrop/index.d.ts.map +1 -1
- package/dist/ui/fileDrop/index.js +30 -46
- package/dist/ui/fileDrop/public.d.ts +2 -2
- package/dist/ui/fileDrop/public.d.ts.map +1 -1
- package/dist/ui/fileDrop/public.js +1 -1
- package/dist/ui/listbox/multi.d.ts +39 -84
- package/dist/ui/listbox/multi.d.ts.map +1 -1
- package/dist/ui/listbox/multi.js +38 -20
- package/dist/ui/listbox/multiPublic.d.ts +2 -2
- package/dist/ui/listbox/multiPublic.d.ts.map +1 -1
- package/dist/ui/listbox/multiPublic.js +1 -1
- package/dist/ui/listbox/public.d.ts +3 -3
- package/dist/ui/listbox/public.d.ts.map +1 -1
- package/dist/ui/listbox/public.js +2 -2
- package/dist/ui/listbox/shared.d.ts +71 -30
- package/dist/ui/listbox/shared.d.ts.map +1 -1
- package/dist/ui/listbox/shared.js +319 -296
- package/dist/ui/listbox/single.d.ts +57 -85
- package/dist/ui/listbox/single.d.ts.map +1 -1
- package/dist/ui/listbox/single.js +48 -24
- package/dist/ui/menu/index.d.ts +80 -36
- package/dist/ui/menu/index.d.ts.map +1 -1
- package/dist/ui/menu/index.js +117 -86
- package/dist/ui/menu/public.d.ts +2 -2
- package/dist/ui/menu/public.d.ts.map +1 -1
- package/dist/ui/menu/public.js +1 -1
- package/dist/ui/popover/index.d.ts +117 -44
- package/dist/ui/popover/index.d.ts.map +1 -1
- package/dist/ui/popover/index.js +88 -101
- package/dist/ui/popover/public.d.ts +2 -2
- package/dist/ui/popover/public.d.ts.map +1 -1
- package/dist/ui/popover/public.js +1 -1
- package/dist/ui/radioGroup/index.d.ts +122 -45
- package/dist/ui/radioGroup/index.d.ts.map +1 -1
- package/dist/ui/radioGroup/index.js +111 -72
- package/dist/ui/radioGroup/public.d.ts +2 -2
- package/dist/ui/radioGroup/public.d.ts.map +1 -1
- package/dist/ui/radioGroup/public.js +1 -1
- package/dist/ui/slider/index.d.ts +247 -103
- package/dist/ui/slider/index.d.ts.map +1 -1
- package/dist/ui/slider/index.js +52 -68
- package/dist/ui/slider/public.d.ts +2 -2
- package/dist/ui/slider/public.d.ts.map +1 -1
- package/dist/ui/slider/public.js +1 -1
- package/dist/ui/switch/index.d.ts +74 -21
- package/dist/ui/switch/index.d.ts.map +1 -1
- package/dist/ui/switch/index.js +62 -33
- package/dist/ui/switch/public.d.ts +2 -2
- package/dist/ui/switch/public.d.ts.map +1 -1
- package/dist/ui/switch/public.js +1 -1
- package/dist/ui/tabs/index.d.ts +107 -45
- package/dist/ui/tabs/index.d.ts.map +1 -1
- package/dist/ui/tabs/index.js +99 -81
- package/dist/ui/tabs/public.d.ts +2 -2
- package/dist/ui/tabs/public.d.ts.map +1 -1
- package/dist/ui/tabs/public.js +1 -1
- package/dist/ui/toast/index.d.ts +93 -109
- package/dist/ui/toast/index.d.ts.map +1 -1
- package/dist/ui/toast/index.js +16 -29
- package/dist/ui/toast/schema.d.ts +15 -4
- package/dist/ui/toast/schema.d.ts.map +1 -1
- package/dist/ui/toast/schema.js +11 -4
- package/dist/ui/toast/update.d.ts +36 -18
- package/dist/ui/toast/update.d.ts.map +1 -1
- package/dist/ui/toast/update.js +33 -14
- package/dist/ui/tooltip/index.d.ts +94 -42
- package/dist/ui/tooltip/index.d.ts.map +1 -1
- package/dist/ui/tooltip/index.js +64 -73
- package/dist/ui/tooltip/public.d.ts +2 -2
- package/dist/ui/tooltip/public.d.ts.map +1 -1
- package/dist/ui/tooltip/public.js +1 -1
- package/dist/ui/virtualList/index.d.ts +63 -80
- package/dist/ui/virtualList/index.d.ts.map +1 -1
- package/dist/ui/virtualList/index.js +22 -49
- package/dist/ui/virtualList/public.d.ts +2 -2
- package/dist/ui/virtualList/public.d.ts.map +1 -1
- package/dist/ui/virtualList/public.js +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Option, Schema as S } from 'effect';
|
|
1
|
+
import { Option, Schema as S, Stream } from 'effect';
|
|
2
2
|
import type { Command } from '../../command/index.js';
|
|
3
|
-
import { type
|
|
3
|
+
import { type ChildAttribute, type Html } from '../../html/index.js';
|
|
4
|
+
import type { Reflect } from '../../submodel/submodel.js';
|
|
4
5
|
/** Schema for the slider component's state. Tracks the current value, the
|
|
5
6
|
* range (min/max/step), and the active drag phase. */
|
|
6
7
|
export declare const Model: S.Struct<{
|
|
@@ -51,15 +52,16 @@ export type MovedDragPointer = typeof MovedDragPointer.Type;
|
|
|
51
52
|
export type ReleasedDragPointer = typeof ReleasedDragPointer.Type;
|
|
52
53
|
export type CancelledDrag = typeof CancelledDrag.Type;
|
|
53
54
|
export type PressedKeyboardNavigation = typeof PressedKeyboardNavigation.Type;
|
|
54
|
-
/** Emitted when the slider value changes. The parent
|
|
55
|
-
*
|
|
55
|
+
/** Emitted when the slider value changes. The parent can handle this to
|
|
56
|
+
* update its own state or dispatch its own Commands, for example to run
|
|
57
|
+
* validation or trigger a downstream Command. */
|
|
56
58
|
export declare const ChangedValue: import("../../schema/index.js").CallableTaggedStruct<"ChangedValue", {
|
|
57
59
|
value: S.Number;
|
|
58
60
|
}>;
|
|
59
61
|
/** Union of all out-messages the slider component can emit to its parent. */
|
|
60
|
-
export declare const OutMessage: import("../../schema/index.js").CallableTaggedStruct<"ChangedValue", {
|
|
62
|
+
export declare const OutMessage: S.Union<readonly [import("../../schema/index.js").CallableTaggedStruct<"ChangedValue", {
|
|
61
63
|
value: S.Number;
|
|
62
|
-
}>;
|
|
64
|
+
}>]>;
|
|
63
65
|
export type OutMessage = typeof OutMessage.Type;
|
|
64
66
|
/** Configuration for creating a slider model with `init`. */
|
|
65
67
|
export type InitConfig = Readonly<{
|
|
@@ -83,76 +85,251 @@ type UpdateReturn = readonly [
|
|
|
83
85
|
/** Processes a slider message and returns the next model, commands, and an
|
|
84
86
|
* optional out-message for the parent. */
|
|
85
87
|
export declare const update: (model: Model, message: Message) => UpdateReturn;
|
|
86
|
-
/**
|
|
87
|
-
* new range. Use this when min/max derive from
|
|
88
|
-
* bounded buffer whose first/last index shifts over
|
|
89
|
-
* this runs even while the user is Dragging: a
|
|
90
|
-
* cannot leave the value out of bounds. */
|
|
91
|
-
export declare const
|
|
88
|
+
/** Reflects an externally-driven range onto the slider. Snaps and clamps the
|
|
89
|
+
* current value into the new range. Use this when min/max derive from
|
|
90
|
+
* external state (e.g. a bounded buffer whose first/last index shifts over
|
|
91
|
+
* time). Unlike `reflectValue`, this runs even while the user is Dragging: a
|
|
92
|
+
* structural range change cannot leave the value out of bounds. */
|
|
93
|
+
export declare const reflectRange: Reflect<Model, Readonly<{
|
|
92
94
|
min: number;
|
|
93
95
|
max: number;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
*
|
|
97
|
-
* Does not emit `ChangedValue`; use when the value is being driven by
|
|
96
|
+
}>>;
|
|
97
|
+
/** Reflects an externally-driven value onto the slider, snapped and clamped
|
|
98
|
+
* into range; a no-op while the user is dragging, since drag state owns the
|
|
99
|
+
* value. Does not emit `ChangedValue`; use when the value is being driven by
|
|
98
100
|
* external state rather than user input. */
|
|
99
|
-
export declare const
|
|
100
|
-
/** Schema describing the subscription dependencies for slider drag. */
|
|
101
|
-
export declare const SubscriptionDependencies: S.Struct<{
|
|
102
|
-
readonly dragPointer: S.Struct<{
|
|
103
|
-
readonly dragActivity: S.Literals<readonly ["Idle", "Active"]>;
|
|
104
|
-
readonly id: S.String;
|
|
105
|
-
readonly min: S.Number;
|
|
106
|
-
readonly max: S.Number;
|
|
107
|
-
}>;
|
|
108
|
-
readonly dragEscape: S.Struct<{
|
|
109
|
-
readonly dragActivity: S.Literals<readonly ["Idle", "Active"]>;
|
|
110
|
-
}>;
|
|
111
|
-
}>;
|
|
101
|
+
export declare const reflectValue: Reflect<Model, number>;
|
|
112
102
|
/** Builds slider drag subscriptions, looking up the track
|
|
113
103
|
* element through the supplied root resolver. Use this when the slider is
|
|
114
104
|
* rendered inside a Shadow DOM. The root is read lazily so consumers can
|
|
115
105
|
* resolve it at subscription time. */
|
|
116
|
-
export declare const subscriptionsForRoot: (getTrackRoot: () => Document | ShadowRoot) =>
|
|
117
|
-
readonly
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
readonly
|
|
106
|
+
export declare const subscriptionsForRoot: (getTrackRoot: () => Document | ShadowRoot) => {
|
|
107
|
+
readonly dragPointer: {
|
|
108
|
+
readonly dependenciesSchema: S.Schema<{
|
|
109
|
+
readonly dragActivity: "Idle" | "Active";
|
|
110
|
+
readonly id: string;
|
|
111
|
+
readonly min: number;
|
|
112
|
+
readonly max: number;
|
|
113
|
+
}> & {
|
|
114
|
+
readonly fields: S.Struct.Fields;
|
|
115
|
+
};
|
|
116
|
+
readonly modelToDependencies: (model: {
|
|
117
|
+
readonly id: string;
|
|
118
|
+
readonly value: number;
|
|
119
|
+
readonly min: number;
|
|
120
|
+
readonly max: number;
|
|
121
|
+
readonly step: number;
|
|
122
|
+
readonly dragState: {
|
|
123
|
+
readonly _tag: "Idle";
|
|
124
|
+
} | {
|
|
125
|
+
readonly _tag: "Dragging";
|
|
126
|
+
readonly originValue: number;
|
|
127
|
+
};
|
|
128
|
+
}) => {
|
|
129
|
+
readonly dragActivity: "Idle" | "Active";
|
|
130
|
+
readonly id: string;
|
|
131
|
+
readonly min: number;
|
|
132
|
+
readonly max: number;
|
|
133
|
+
};
|
|
134
|
+
readonly keepAliveEquivalence?: never;
|
|
135
|
+
readonly dependenciesToStream: (dependencies: {
|
|
136
|
+
readonly dragActivity: "Idle" | "Active";
|
|
137
|
+
readonly id: string;
|
|
138
|
+
readonly min: number;
|
|
139
|
+
readonly max: number;
|
|
140
|
+
}) => Stream.Stream<{
|
|
141
|
+
readonly _tag: "PressedThumb";
|
|
142
|
+
} | {
|
|
143
|
+
readonly _tag: "PressedPointer";
|
|
144
|
+
readonly value: number;
|
|
145
|
+
} | {
|
|
146
|
+
readonly _tag: "MovedDragPointer";
|
|
147
|
+
readonly value: number;
|
|
148
|
+
} | {
|
|
149
|
+
readonly _tag: "ReleasedDragPointer";
|
|
150
|
+
} | {
|
|
151
|
+
readonly _tag: "CancelledDrag";
|
|
152
|
+
} | {
|
|
153
|
+
readonly _tag: "PressedKeyboardNavigation";
|
|
154
|
+
readonly direction: "Max" | "Min" | "StepDecrement" | "StepIncrement" | "PageDecrement" | "PageIncrement";
|
|
155
|
+
}, never, never>;
|
|
156
|
+
} & {
|
|
157
|
+
readonly __subscription: never;
|
|
127
158
|
};
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
159
|
+
readonly dragEscape: {
|
|
160
|
+
readonly dependenciesSchema: S.Schema<{
|
|
161
|
+
readonly dragActivity: "Idle" | "Active";
|
|
162
|
+
}> & {
|
|
163
|
+
readonly fields: S.Struct.Fields;
|
|
164
|
+
};
|
|
165
|
+
readonly modelToDependencies: (model: {
|
|
166
|
+
readonly id: string;
|
|
167
|
+
readonly value: number;
|
|
168
|
+
readonly min: number;
|
|
169
|
+
readonly max: number;
|
|
170
|
+
readonly step: number;
|
|
171
|
+
readonly dragState: {
|
|
172
|
+
readonly _tag: "Idle";
|
|
173
|
+
} | {
|
|
174
|
+
readonly _tag: "Dragging";
|
|
175
|
+
readonly originValue: number;
|
|
176
|
+
};
|
|
177
|
+
}) => {
|
|
178
|
+
readonly dragActivity: "Idle" | "Active";
|
|
179
|
+
};
|
|
180
|
+
readonly keepAliveEquivalence?: never;
|
|
181
|
+
readonly dependenciesToStream: (dependencies: {
|
|
182
|
+
readonly dragActivity: "Idle" | "Active";
|
|
183
|
+
}) => Stream.Stream<{
|
|
184
|
+
readonly _tag: "PressedThumb";
|
|
185
|
+
} | {
|
|
186
|
+
readonly _tag: "PressedPointer";
|
|
187
|
+
readonly value: number;
|
|
188
|
+
} | {
|
|
189
|
+
readonly _tag: "MovedDragPointer";
|
|
190
|
+
readonly value: number;
|
|
191
|
+
} | {
|
|
192
|
+
readonly _tag: "ReleasedDragPointer";
|
|
193
|
+
} | {
|
|
194
|
+
readonly _tag: "CancelledDrag";
|
|
195
|
+
} | {
|
|
196
|
+
readonly _tag: "PressedKeyboardNavigation";
|
|
197
|
+
readonly direction: "Max" | "Min" | "StepDecrement" | "StepIncrement" | "PageDecrement" | "PageIncrement";
|
|
198
|
+
}, never, never>;
|
|
199
|
+
} & {
|
|
200
|
+
readonly __subscription: never;
|
|
201
|
+
};
|
|
202
|
+
};
|
|
154
203
|
/** Default drag subscriptions, with the track looked up via `document`. */
|
|
155
|
-
export declare const subscriptions:
|
|
204
|
+
export declare const subscriptions: {
|
|
205
|
+
readonly dragPointer: {
|
|
206
|
+
readonly dependenciesSchema: S.Schema<{
|
|
207
|
+
readonly dragActivity: "Idle" | "Active";
|
|
208
|
+
readonly id: string;
|
|
209
|
+
readonly min: number;
|
|
210
|
+
readonly max: number;
|
|
211
|
+
}> & {
|
|
212
|
+
readonly fields: S.Struct.Fields;
|
|
213
|
+
};
|
|
214
|
+
readonly modelToDependencies: (model: {
|
|
215
|
+
readonly id: string;
|
|
216
|
+
readonly value: number;
|
|
217
|
+
readonly min: number;
|
|
218
|
+
readonly max: number;
|
|
219
|
+
readonly step: number;
|
|
220
|
+
readonly dragState: {
|
|
221
|
+
readonly _tag: "Idle";
|
|
222
|
+
} | {
|
|
223
|
+
readonly _tag: "Dragging";
|
|
224
|
+
readonly originValue: number;
|
|
225
|
+
};
|
|
226
|
+
}) => {
|
|
227
|
+
readonly dragActivity: "Idle" | "Active";
|
|
228
|
+
readonly id: string;
|
|
229
|
+
readonly min: number;
|
|
230
|
+
readonly max: number;
|
|
231
|
+
};
|
|
232
|
+
readonly keepAliveEquivalence?: never;
|
|
233
|
+
readonly dependenciesToStream: (dependencies: {
|
|
234
|
+
readonly dragActivity: "Idle" | "Active";
|
|
235
|
+
readonly id: string;
|
|
236
|
+
readonly min: number;
|
|
237
|
+
readonly max: number;
|
|
238
|
+
}) => Stream.Stream<{
|
|
239
|
+
readonly _tag: "PressedThumb";
|
|
240
|
+
} | {
|
|
241
|
+
readonly _tag: "PressedPointer";
|
|
242
|
+
readonly value: number;
|
|
243
|
+
} | {
|
|
244
|
+
readonly _tag: "MovedDragPointer";
|
|
245
|
+
readonly value: number;
|
|
246
|
+
} | {
|
|
247
|
+
readonly _tag: "ReleasedDragPointer";
|
|
248
|
+
} | {
|
|
249
|
+
readonly _tag: "CancelledDrag";
|
|
250
|
+
} | {
|
|
251
|
+
readonly _tag: "PressedKeyboardNavigation";
|
|
252
|
+
readonly direction: "Max" | "Min" | "StepDecrement" | "StepIncrement" | "PageDecrement" | "PageIncrement";
|
|
253
|
+
}, never, never>;
|
|
254
|
+
} & {
|
|
255
|
+
readonly __subscription: never;
|
|
256
|
+
};
|
|
257
|
+
readonly dragEscape: {
|
|
258
|
+
readonly dependenciesSchema: S.Schema<{
|
|
259
|
+
readonly dragActivity: "Idle" | "Active";
|
|
260
|
+
}> & {
|
|
261
|
+
readonly fields: S.Struct.Fields;
|
|
262
|
+
};
|
|
263
|
+
readonly modelToDependencies: (model: {
|
|
264
|
+
readonly id: string;
|
|
265
|
+
readonly value: number;
|
|
266
|
+
readonly min: number;
|
|
267
|
+
readonly max: number;
|
|
268
|
+
readonly step: number;
|
|
269
|
+
readonly dragState: {
|
|
270
|
+
readonly _tag: "Idle";
|
|
271
|
+
} | {
|
|
272
|
+
readonly _tag: "Dragging";
|
|
273
|
+
readonly originValue: number;
|
|
274
|
+
};
|
|
275
|
+
}) => {
|
|
276
|
+
readonly dragActivity: "Idle" | "Active";
|
|
277
|
+
};
|
|
278
|
+
readonly keepAliveEquivalence?: never;
|
|
279
|
+
readonly dependenciesToStream: (dependencies: {
|
|
280
|
+
readonly dragActivity: "Idle" | "Active";
|
|
281
|
+
}) => Stream.Stream<{
|
|
282
|
+
readonly _tag: "PressedThumb";
|
|
283
|
+
} | {
|
|
284
|
+
readonly _tag: "PressedPointer";
|
|
285
|
+
readonly value: number;
|
|
286
|
+
} | {
|
|
287
|
+
readonly _tag: "MovedDragPointer";
|
|
288
|
+
readonly value: number;
|
|
289
|
+
} | {
|
|
290
|
+
readonly _tag: "ReleasedDragPointer";
|
|
291
|
+
} | {
|
|
292
|
+
readonly _tag: "CancelledDrag";
|
|
293
|
+
} | {
|
|
294
|
+
readonly _tag: "PressedKeyboardNavigation";
|
|
295
|
+
readonly direction: "Max" | "Min" | "StepDecrement" | "StepIncrement" | "PageDecrement" | "PageIncrement";
|
|
296
|
+
}, never, never>;
|
|
297
|
+
} & {
|
|
298
|
+
readonly __subscription: never;
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
/** Attribute groups the slider component provides to the consumer's `toView`
|
|
302
|
+
* callback. Each bundle carries the boundary's captured dispatch, so the
|
|
303
|
+
* consumer can spread it directly into element attributes without manual
|
|
304
|
+
* Message wrapping. */
|
|
305
|
+
export type SliderAttributes = Readonly<{
|
|
306
|
+
root: ReadonlyArray<ChildAttribute>;
|
|
307
|
+
track: ReadonlyArray<ChildAttribute>;
|
|
308
|
+
filledTrack: ReadonlyArray<ChildAttribute>;
|
|
309
|
+
thumb: ReadonlyArray<ChildAttribute>;
|
|
310
|
+
label: ReadonlyArray<ChildAttribute>;
|
|
311
|
+
hiddenInput: ReadonlyArray<ChildAttribute>;
|
|
312
|
+
}>;
|
|
313
|
+
/** Per-render view inputs passed to `view` via `h.submodel`'s `viewInputs` field. */
|
|
314
|
+
export type ViewInputs = Readonly<{
|
|
315
|
+
toView: (attributes: SliderAttributes) => Html;
|
|
316
|
+
ariaLabel?: string;
|
|
317
|
+
ariaLabelledBy?: string;
|
|
318
|
+
formatValue?: (value: number) => string;
|
|
319
|
+
isDisabled?: boolean;
|
|
320
|
+
name?: string;
|
|
321
|
+
/** Resolves the root that holds the slider track when looking it up by its
|
|
322
|
+
* `data-slider-track-id` attribute. Defaults to `document`. Provide a
|
|
323
|
+
* ShadowRoot when rendering the slider inside a shadow tree so pointer
|
|
324
|
+
* events on the track can map clientX into a value. */
|
|
325
|
+
getTrackRoot?: () => Document | ShadowRoot;
|
|
326
|
+
}>;
|
|
327
|
+
/** Renders an accessible slider by building ARIA attribute groups and
|
|
328
|
+
* delegating layout to the consumer's `toView` callback. Follows the
|
|
329
|
+
* WAI-ARIA slider pattern: role="slider" on the thumb, aria-valuemin /
|
|
330
|
+
* aria-valuemax / aria-valuenow, keyboard navigation by step / page / home /
|
|
331
|
+
* end. Pointer drag is handled by the component's drag subscriptions. */
|
|
332
|
+
export declare const view: import("../../html/submodel.js").SubmodelView<{
|
|
156
333
|
readonly id: string;
|
|
157
334
|
readonly value: number;
|
|
158
335
|
readonly min: number;
|
|
@@ -179,32 +356,8 @@ export declare const subscriptions: import("../../runtime/subscription.js").Subs
|
|
|
179
356
|
} | {
|
|
180
357
|
readonly _tag: "PressedKeyboardNavigation";
|
|
181
358
|
readonly direction: "Max" | "Min" | "StepDecrement" | "StepIncrement" | "PageDecrement" | "PageIncrement";
|
|
182
|
-
},
|
|
183
|
-
|
|
184
|
-
readonly dragActivity: S.Literals<readonly ["Idle", "Active"]>;
|
|
185
|
-
readonly id: S.String;
|
|
186
|
-
readonly min: S.Number;
|
|
187
|
-
readonly max: S.Number;
|
|
188
|
-
}>;
|
|
189
|
-
readonly dragEscape: S.Struct<{
|
|
190
|
-
readonly dragActivity: S.Literals<readonly ["Idle", "Active"]>;
|
|
191
|
-
}>;
|
|
192
|
-
}>, never>;
|
|
193
|
-
/** Attribute groups the slider component provides to the consumer's `toView`
|
|
194
|
-
* callback. */
|
|
195
|
-
export type SliderAttributes<ParentMessage> = Readonly<{
|
|
196
|
-
root: ReadonlyArray<Attribute<ParentMessage>>;
|
|
197
|
-
track: ReadonlyArray<Attribute<ParentMessage>>;
|
|
198
|
-
filledTrack: ReadonlyArray<Attribute<ParentMessage>>;
|
|
199
|
-
thumb: ReadonlyArray<Attribute<ParentMessage>>;
|
|
200
|
-
label: ReadonlyArray<Attribute<ParentMessage>>;
|
|
201
|
-
hiddenInput: ReadonlyArray<Attribute<ParentMessage>>;
|
|
202
|
-
}>;
|
|
203
|
-
/** Configuration for rendering a slider with `view`. */
|
|
204
|
-
export type ViewConfig<ParentMessage> = Readonly<{
|
|
205
|
-
model: Model;
|
|
206
|
-
toParentMessage: (message: PressedThumb | PressedPointer | MovedDragPointer | ReleasedDragPointer | CancelledDrag | PressedKeyboardNavigation) => ParentMessage;
|
|
207
|
-
toView: (attributes: SliderAttributes<ParentMessage>) => Html;
|
|
359
|
+
}, Readonly<{
|
|
360
|
+
toView: (attributes: SliderAttributes) => Html;
|
|
208
361
|
ariaLabel?: string;
|
|
209
362
|
ariaLabelledBy?: string;
|
|
210
363
|
formatValue?: (value: number) => string;
|
|
@@ -215,15 +368,6 @@ export type ViewConfig<ParentMessage> = Readonly<{
|
|
|
215
368
|
* ShadowRoot when rendering the slider inside a shadow tree so pointer
|
|
216
369
|
* events on the track can map clientX into a value. */
|
|
217
370
|
getTrackRoot?: () => Document | ShadowRoot;
|
|
218
|
-
}
|
|
219
|
-
/** Renders an accessible slider by building ARIA attribute groups and
|
|
220
|
-
* delegating layout to the consumer's `toView` callback. Follows the
|
|
221
|
-
* WAI-ARIA slider pattern — role="slider" on the thumb, aria-valuemin /
|
|
222
|
-
* aria-valuemax / aria-valuenow, keyboard navigation by step / page / home /
|
|
223
|
-
* end. Pointer drag is handled by the component's drag subscriptions. */
|
|
224
|
-
export declare const view: <ParentMessage>(config: ViewConfig<ParentMessage>) => Html;
|
|
225
|
-
/** Creates a memoized slider view. Static config is captured in a closure;
|
|
226
|
-
* only `model` and `toParentMessage` are compared per render via `createLazy`. */
|
|
227
|
-
export declare const lazy: <ParentMessage>(staticConfig: Omit<ViewConfig<ParentMessage>, "model" | "toParentMessage">) => ((model: Model, toParentMessage: ViewConfig<ParentMessage>["toParentMessage"]) => Html);
|
|
371
|
+
}>>;
|
|
228
372
|
export {};
|
|
229
373
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/slider/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/slider/index.ts"],"names":[],"mappings":"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"}
|
package/dist/ui/slider/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Effect, Equal, Match as M, Option, Schema as S, Stream, String as String_, pipe, } from 'effect';
|
|
2
|
-
import {
|
|
1
|
+
import { Effect, Equal, Function, Match as M, Option, Schema as S, Stream, String as String_, pipe, } from 'effect';
|
|
2
|
+
import { childAttributes, defineView, html, } from '../../html/index.js';
|
|
3
3
|
import { m } from '../../message/index.js';
|
|
4
|
-
import
|
|
4
|
+
import * as Subscription from '../../runtime/subscription.js';
|
|
5
5
|
import { ts } from '../../schema/index.js';
|
|
6
6
|
import { evo } from '../../struct/index.js';
|
|
7
7
|
// MODEL
|
|
@@ -53,11 +53,12 @@ export const Message = S.Union([
|
|
|
53
53
|
PressedKeyboardNavigation,
|
|
54
54
|
]);
|
|
55
55
|
// OUT MESSAGE
|
|
56
|
-
/** Emitted when the slider value changes. The parent
|
|
57
|
-
*
|
|
58
|
-
|
|
56
|
+
/** Emitted when the slider value changes. The parent can handle this to
|
|
57
|
+
* update its own state or dispatch its own Commands, for example to run
|
|
58
|
+
* validation or trigger a downstream Command. */
|
|
59
|
+
export const ChangedValue = m('ChangedValue', { value: S.Number });
|
|
59
60
|
/** Union of all out-messages the slider component can emit to its parent. */
|
|
60
|
-
export const OutMessage = ChangedValue;
|
|
61
|
+
export const OutMessage = S.Union([ChangedValue]);
|
|
61
62
|
/** Creates an initial slider model from a config. The initial value is
|
|
62
63
|
* snapped to the step and clamped into range. */
|
|
63
64
|
export const init = (config) => ({
|
|
@@ -129,13 +130,13 @@ export const update = (model, message) => M.value(message).pipe(withUpdateReturn
|
|
|
129
130
|
// off-center on a non-zero-width thumb.
|
|
130
131
|
PressedPointer: ({ value }) => M.value(model.dragState).pipe(withUpdateReturn, M.tag('Dragging', () => [model, [], Option.none()]), M.orElse(() => {
|
|
131
132
|
const snapped = snapAndClamp(value, model.min, model.max, model.step);
|
|
132
|
-
const [modelWithValue, commands,
|
|
133
|
+
const [modelWithValue, commands, maybeOutMessage] = withValue(model, snapped, []);
|
|
133
134
|
return [
|
|
134
135
|
evo(modelWithValue, {
|
|
135
136
|
dragState: () => Dragging({ originValue: model.value }),
|
|
136
137
|
}),
|
|
137
138
|
commands,
|
|
138
|
-
|
|
139
|
+
maybeOutMessage,
|
|
139
140
|
];
|
|
140
141
|
})),
|
|
141
142
|
MovedDragPointer: ({ value }) => M.value(model.dragState).pipe(withUpdateReturn, M.tag('Dragging', () => withValue(model, snapAndClamp(value, model.min, model.max, model.step), [])), M.orElse(() => [model, [], Option.none()])),
|
|
@@ -152,23 +153,23 @@ export const update = (model, message) => M.value(message).pipe(withUpdateReturn
|
|
|
152
153
|
}), M.orElse(() => [model, [], Option.none()])),
|
|
153
154
|
PressedKeyboardNavigation: ({ direction }) => withValue(model, nextValueForDirection(model, direction), []),
|
|
154
155
|
}));
|
|
155
|
-
/**
|
|
156
|
-
* new range. Use this when min/max derive from
|
|
157
|
-
* bounded buffer whose first/last index shifts over
|
|
158
|
-
* this runs even while the user is Dragging: a
|
|
159
|
-
* cannot leave the value out of bounds. */
|
|
160
|
-
export const
|
|
156
|
+
/** Reflects an externally-driven range onto the slider. Snaps and clamps the
|
|
157
|
+
* current value into the new range. Use this when min/max derive from
|
|
158
|
+
* external state (e.g. a bounded buffer whose first/last index shifts over
|
|
159
|
+
* time). Unlike `reflectValue`, this runs even while the user is Dragging: a
|
|
160
|
+
* structural range change cannot leave the value out of bounds. */
|
|
161
|
+
export const reflectRange = Function.dual(2, (model, range) => evo(model, {
|
|
161
162
|
min: () => range.min,
|
|
162
163
|
max: () => range.max,
|
|
163
164
|
value: current => snapAndClamp(current, range.min, range.max, model.step),
|
|
164
|
-
});
|
|
165
|
-
/**
|
|
166
|
-
*
|
|
167
|
-
* Does not emit `ChangedValue`; use when the value is being driven by
|
|
165
|
+
}));
|
|
166
|
+
/** Reflects an externally-driven value onto the slider, snapped and clamped
|
|
167
|
+
* into range; a no-op while the user is dragging, since drag state owns the
|
|
168
|
+
* value. Does not emit `ChangedValue`; use when the value is being driven by
|
|
168
169
|
* external state rather than user input. */
|
|
169
|
-
export const
|
|
170
|
+
export const reflectValue = Function.dual(2, (model, value) => M.value(model.dragState).pipe(M.withReturnType(), M.tag('Dragging', () => model), M.orElse(() => evo(model, {
|
|
170
171
|
value: () => snapAndClamp(value, model.min, model.max, model.step),
|
|
171
|
-
})));
|
|
172
|
+
}))));
|
|
172
173
|
// SUBSCRIPTION
|
|
173
174
|
const DragActivity = S.Literals(['Idle', 'Active']);
|
|
174
175
|
const dragActivityFromModel = (model) => M.value(model.dragState).pipe(M.withReturnType(), M.tag('Dragging', () => 'Active'), M.orElse(() => 'Idle'));
|
|
@@ -183,24 +184,17 @@ const valueFromClientX = (clientX, trackElement_, min, max) => {
|
|
|
183
184
|
return min + fraction * (max - min);
|
|
184
185
|
}
|
|
185
186
|
};
|
|
186
|
-
/** Schema describing the subscription dependencies for slider drag. */
|
|
187
|
-
export const SubscriptionDependencies = S.Struct({
|
|
188
|
-
dragPointer: S.Struct({
|
|
189
|
-
dragActivity: DragActivity,
|
|
190
|
-
id: S.String,
|
|
191
|
-
min: S.Number,
|
|
192
|
-
max: S.Number,
|
|
193
|
-
}),
|
|
194
|
-
dragEscape: S.Struct({
|
|
195
|
-
dragActivity: DragActivity,
|
|
196
|
-
}),
|
|
197
|
-
});
|
|
198
187
|
/** Builds slider drag subscriptions, looking up the track
|
|
199
188
|
* element through the supplied root resolver. Use this when the slider is
|
|
200
189
|
* rendered inside a Shadow DOM. The root is read lazily so consumers can
|
|
201
190
|
* resolve it at subscription time. */
|
|
202
|
-
export const subscriptionsForRoot = (getTrackRoot) =>
|
|
203
|
-
dragPointer: {
|
|
191
|
+
export const subscriptionsForRoot = (getTrackRoot) => Subscription.make()(entry => ({
|
|
192
|
+
dragPointer: entry({
|
|
193
|
+
dragActivity: DragActivity,
|
|
194
|
+
id: S.String,
|
|
195
|
+
min: S.Number,
|
|
196
|
+
max: S.Number,
|
|
197
|
+
}, {
|
|
204
198
|
modelToDependencies: model => ({
|
|
205
199
|
dragActivity: dragActivityFromModel(model),
|
|
206
200
|
id: model.id,
|
|
@@ -227,14 +221,14 @@ export const subscriptionsForRoot = (getTrackRoot) => makeSubscriptions(Subscrip
|
|
|
227
221
|
})).pipe(Effect.flatMap(() => Effect.never)));
|
|
228
222
|
return Stream.when(Stream.merge(pointerEvents, documentDragStyles), Effect.sync(() => dragActivity === 'Active'));
|
|
229
223
|
},
|
|
230
|
-
},
|
|
231
|
-
dragEscape: {
|
|
224
|
+
}),
|
|
225
|
+
dragEscape: entry({ dragActivity: DragActivity }, {
|
|
232
226
|
modelToDependencies: model => ({
|
|
233
227
|
dragActivity: dragActivityFromModel(model),
|
|
234
228
|
}),
|
|
235
229
|
dependenciesToStream: ({ dragActivity }) => Stream.when(Stream.fromEventListener(document, 'keydown').pipe(Stream.filter(({ key }) => key === 'Escape'), Stream.map(() => CancelledDrag())), Effect.sync(() => dragActivity === 'Active')),
|
|
236
|
-
},
|
|
237
|
-
});
|
|
230
|
+
}),
|
|
231
|
+
}));
|
|
238
232
|
/** Default drag subscriptions, with the track looked up via `document`. */
|
|
239
233
|
export const subscriptions = subscriptionsForRoot(() => document);
|
|
240
234
|
// VIEW
|
|
@@ -244,21 +238,21 @@ const keyToDirection = (key) => M.value(key).pipe(M.withReturnType(), M.whenOr('
|
|
|
244
238
|
const percentString = (fraction) => `${Math.round(fraction * 10000) / 100}%`;
|
|
245
239
|
/** Renders an accessible slider by building ARIA attribute groups and
|
|
246
240
|
* delegating layout to the consumer's `toView` callback. Follows the
|
|
247
|
-
* WAI-ARIA slider pattern
|
|
241
|
+
* WAI-ARIA slider pattern: role="slider" on the thumb, aria-valuemin /
|
|
248
242
|
* aria-valuemax / aria-valuenow, keyboard navigation by step / page / home /
|
|
249
243
|
* end. Pointer drag is handled by the component's drag subscriptions. */
|
|
250
|
-
export const view = (
|
|
244
|
+
export const view = defineView((model, viewInputs) => {
|
|
251
245
|
const h = html();
|
|
252
|
-
const {
|
|
246
|
+
const { formatValue, isDisabled = false, name, getTrackRoot = () => document, } = viewInputs;
|
|
253
247
|
const { id, value, min, max } = model;
|
|
254
248
|
const isDragging = model.dragState._tag === 'Dragging';
|
|
255
249
|
const fraction = fractionOfValue(model);
|
|
256
|
-
const handleKeyDown = (key) => Option.map(keyToDirection(key), direction =>
|
|
257
|
-
const pointerAtClientX = (clientX) => Option.map(trackElement(id, getTrackRoot()), element =>
|
|
250
|
+
const handleKeyDown = (key) => Option.map(keyToDirection(key), direction => PressedKeyboardNavigation({ direction }));
|
|
251
|
+
const pointerAtClientX = (clientX) => Option.map(trackElement(id, getTrackRoot()), element => PressedPointer({
|
|
258
252
|
value: valueFromClientX(clientX, element, min, max),
|
|
259
|
-
}))
|
|
253
|
+
}));
|
|
260
254
|
const trackPointerHandler = (_pointerType, button, _screenX, _screenY, _timeStamp, clientX) => pipe(button, Option.liftPredicate(Equal.equals(LEFT_MOUSE_BUTTON)), Option.flatMap(() => pointerAtClientX(clientX)));
|
|
261
|
-
const thumbPointerHandler = (_pointerType, button) => pipe(button, Option.liftPredicate(Equal.equals(LEFT_MOUSE_BUTTON)), Option.map(() =>
|
|
255
|
+
const thumbPointerHandler = (_pointerType, button) => pipe(button, Option.liftPredicate(Equal.equals(LEFT_MOUSE_BUTTON)), Option.map(() => PressedThumb()));
|
|
262
256
|
const stateAttributes = [
|
|
263
257
|
...(isDragging ? [h.DataAttribute('dragging', '')] : []),
|
|
264
258
|
...(isDisabled ? [h.DataAttribute('disabled', '')] : []),
|
|
@@ -289,11 +283,11 @@ export const view = (config) => {
|
|
|
289
283
|
...stateAttributes,
|
|
290
284
|
];
|
|
291
285
|
const resolveThumbLabel = () => {
|
|
292
|
-
if (
|
|
293
|
-
return [h.AriaLabel(
|
|
286
|
+
if (viewInputs.ariaLabel !== undefined) {
|
|
287
|
+
return [h.AriaLabel(viewInputs.ariaLabel)];
|
|
294
288
|
}
|
|
295
|
-
else if (
|
|
296
|
-
return [h.AriaLabelledBy(
|
|
289
|
+
else if (viewInputs.ariaLabelledBy !== undefined) {
|
|
290
|
+
return [h.AriaLabelledBy(viewInputs.ariaLabelledBy)];
|
|
297
291
|
}
|
|
298
292
|
else {
|
|
299
293
|
return [h.AriaLabelledBy(labelId(id))];
|
|
@@ -331,22 +325,12 @@ export const view = (config) => {
|
|
|
331
325
|
const hiddenInputAttributes = name !== undefined
|
|
332
326
|
? [h.Type('hidden'), h.Name(name), h.Value(value.toString())]
|
|
333
327
|
: [];
|
|
334
|
-
return
|
|
335
|
-
root: rootAttributes,
|
|
336
|
-
track: trackAttributes,
|
|
337
|
-
filledTrack: filledTrackAttributes,
|
|
338
|
-
thumb: thumbAttributes,
|
|
339
|
-
label: labelAttributes,
|
|
340
|
-
hiddenInput: hiddenInputAttributes,
|
|
328
|
+
return viewInputs.toView({
|
|
329
|
+
root: childAttributes(rootAttributes),
|
|
330
|
+
track: childAttributes(trackAttributes),
|
|
331
|
+
filledTrack: childAttributes(filledTrackAttributes),
|
|
332
|
+
thumb: childAttributes(thumbAttributes),
|
|
333
|
+
label: childAttributes(labelAttributes),
|
|
334
|
+
hiddenInput: childAttributes(hiddenInputAttributes),
|
|
341
335
|
});
|
|
342
|
-
};
|
|
343
|
-
/** Creates a memoized slider view. Static config is captured in a closure;
|
|
344
|
-
* only `model` and `toParentMessage` are compared per render via `createLazy`. */
|
|
345
|
-
export const lazy = (staticConfig) => {
|
|
346
|
-
const lazyView = createLazy();
|
|
347
|
-
return (model, toParentMessage) => lazyView((currentModel, currentToParentMessage) => view({
|
|
348
|
-
...staticConfig,
|
|
349
|
-
model: currentModel,
|
|
350
|
-
toParentMessage: currentToParentMessage,
|
|
351
|
-
}), [model, toParentMessage]);
|
|
352
|
-
};
|
|
336
|
+
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { init, update,
|
|
2
|
-
export type { InitConfig,
|
|
1
|
+
export { init, update, reflectRange, reflectValue, view, subscriptions, subscriptionsForRoot, fractionOfValue, Model, Message, OutMessage, } from './index.js';
|
|
2
|
+
export type { InitConfig, ViewInputs, SliderAttributes, PressedThumb, PressedPointer, MovedDragPointer, ReleasedDragPointer, CancelledDrag, PressedKeyboardNavigation, } from './index.js';
|
|
3
3
|
//# sourceMappingURL=public.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../../src/ui/slider/public.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,MAAM,EACN,
|
|
1
|
+
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../../src/ui/slider/public.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,IAAI,EACJ,aAAa,EACb,oBAAoB,EACpB,eAAe,EACf,KAAK,EACL,OAAO,EACP,UAAU,GACX,MAAM,YAAY,CAAA;AAEnB,YAAY,EACV,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,EACb,yBAAyB,GAC1B,MAAM,YAAY,CAAA"}
|
package/dist/ui/slider/public.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { init, update,
|
|
1
|
+
export { init, update, reflectRange, reflectValue, view, subscriptions, subscriptionsForRoot, fractionOfValue, Model, Message, OutMessage, } from './index.js';
|