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
package/dist/ui/tabs/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Array, Effect, Match as M, Option, Schema as S, String, pipe, } from 'effect';
|
|
1
|
+
import { Array, Effect, Function, Match as M, Option, Schema as S, String, pipe, } from 'effect';
|
|
2
2
|
import * as Command from '../../command/index.js';
|
|
3
3
|
import * as Dom from '../../dom/index.js';
|
|
4
|
-
import {
|
|
4
|
+
import { childAttributes, defineView, html, } from '../../html/index.js';
|
|
5
5
|
import { m } from '../../message/index.js';
|
|
6
6
|
import { evo } from '../../struct/index.js';
|
|
7
7
|
import { keyToIndex } from '../keyboard.js';
|
|
@@ -20,13 +20,24 @@ export const Model = S.Struct({
|
|
|
20
20
|
});
|
|
21
21
|
// MESSAGE
|
|
22
22
|
/** Sent when a tab is selected via click or keyboard. Updates both the active and focused indices. */
|
|
23
|
-
export const
|
|
23
|
+
export const SelectedTab = m('SelectedTab', {
|
|
24
|
+
index: S.Number,
|
|
25
|
+
value: S.String,
|
|
26
|
+
});
|
|
24
27
|
/** Sent when a tab receives keyboard focus in `Manual` mode without being activated. */
|
|
25
|
-
export const
|
|
28
|
+
export const FocusedTab = m('FocusedTab', { index: S.Number });
|
|
26
29
|
/** Sent when the focus-tab command completes. */
|
|
27
30
|
export const CompletedFocusTab = m('CompletedFocusTab');
|
|
28
31
|
/** Union of all messages the tabs component can produce. */
|
|
29
|
-
export const Message = S.Union([
|
|
32
|
+
export const Message = S.Union([SelectedTab, FocusedTab, CompletedFocusTab]);
|
|
33
|
+
// OUT MESSAGE
|
|
34
|
+
/** Sent to the parent when a tab is committed via click or keyboard. Carries both the tab's value (typed as `Value` via `Ui.Tabs.create<Value>()`) and its index. Generic at the type level; the schema stores `value: string` and the factory's fenced cast types it as `Value`. */
|
|
35
|
+
export const Selected = m('Selected', {
|
|
36
|
+
value: S.String,
|
|
37
|
+
index: S.Number,
|
|
38
|
+
});
|
|
39
|
+
/** Union of out-messages the tabs component can produce. Surfaced as the third element of `update`'s return tuple and pattern-matched by the parent. */
|
|
40
|
+
export const OutMessage = S.Union([Selected]);
|
|
30
41
|
/** Creates an initial tabs model from a config. Defaults to first tab and automatic activation. */
|
|
31
42
|
export const init = (config) => {
|
|
32
43
|
const activeIndex = config.activeIndex ?? 0;
|
|
@@ -39,34 +50,45 @@ export const init = (config) => {
|
|
|
39
50
|
};
|
|
40
51
|
// UPDATE
|
|
41
52
|
const tabId = (id, index) => `${id}-tab-${index}`;
|
|
53
|
+
const tabPanelId = (id, index) => `${id}-panel-${index}`;
|
|
42
54
|
/** Moves focus to the tab at the given index. */
|
|
43
55
|
export const FocusTab = Command.define('FocusTab', { id: S.String, index: S.Number }, CompletedFocusTab)(({ id, index }) => Dom.focus(`#${tabId(id, index)}`).pipe(Effect.ignore, Effect.as(CompletedFocusTab())));
|
|
44
|
-
/** Processes a tabs message and returns the next model and
|
|
56
|
+
/** Processes a tabs message and returns the next model, commands, and an optional OutMessage. `Selected` fires when a tab is committed via click or keyboard. */
|
|
45
57
|
export const update = (model, message) => M.value(message).pipe(M.withReturnType(), M.tagsExhaustive({
|
|
46
|
-
|
|
58
|
+
SelectedTab: ({ index, value }) => [
|
|
47
59
|
evo(model, {
|
|
48
60
|
activeIndex: () => index,
|
|
49
61
|
focusedIndex: () => index,
|
|
50
62
|
}),
|
|
51
63
|
[FocusTab({ id: model.id, index })],
|
|
64
|
+
Option.some(Selected({ value, index })),
|
|
52
65
|
],
|
|
53
|
-
|
|
66
|
+
FocusedTab: ({ index }) => [
|
|
54
67
|
evo(model, { focusedIndex: () => index }),
|
|
55
68
|
[FocusTab({ id: model.id, index })],
|
|
69
|
+
Option.none(),
|
|
56
70
|
],
|
|
57
|
-
CompletedFocusTab: () => [model, []],
|
|
71
|
+
CompletedFocusTab: () => [model, [], Option.none()],
|
|
58
72
|
}));
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
73
|
+
/** Programmatically selects a tab. Emits a `Selected` OutMessage. */
|
|
74
|
+
export const selectTab = (model, value, index) => update(model, SelectedTab({ index, value }));
|
|
75
|
+
/** Reflects an externally-sourced active tab onto the model without
|
|
76
|
+
* emitting an OutMessage or running the focus command. Use this to mirror
|
|
77
|
+
* external truth (a deep link, restored storage) onto the active tab.
|
|
78
|
+
* Contrast with `selectTab`, which represents a user or programmatic
|
|
79
|
+
* *choice*: it focuses the tab and emits `Selected`. Takes the tab `value`
|
|
80
|
+
* plus the `options` list (mirroring `RadioGroup.select`) because Tabs
|
|
81
|
+
* stores the active *index* internally, so the value is resolved to an
|
|
82
|
+
* index. A value not present in `options` is a no-op. Returns the model
|
|
83
|
+
* directly because it produces no commands and no OutMessage. */
|
|
84
|
+
export const reflectSelectedTab = Function.dual(3, (model, value, options) => pipe(options, Array.findFirstIndex(option => option === value), Option.match({
|
|
85
|
+
onNone: () => model,
|
|
86
|
+
onSome: index => evo(model, { activeIndex: () => index, focusedIndex: () => index }),
|
|
87
|
+
})));
|
|
88
|
+
const internalView = defineView((model, viewInputs) => {
|
|
65
89
|
const h = html();
|
|
66
|
-
const {
|
|
67
|
-
const
|
|
68
|
-
? onTabSelected(index)
|
|
69
|
-
: toParentMessage(TabSelected({ index }));
|
|
90
|
+
const { id, activationMode, focusedIndex, activeIndex } = model;
|
|
91
|
+
const { tabs, ariaLabel, toView, isTabDisabled, orientation = 'Horizontal', } = viewInputs;
|
|
70
92
|
const isDisabled = (index) => !!isTabDisabled &&
|
|
71
93
|
pipe(tabs, Array.get(index), Option.exists(tab => isTabDisabled(tab, index)));
|
|
72
94
|
const { nextKey, previousKey } = M.value(orientation).pipe(M.when('Horizontal', () => ({
|
|
@@ -77,15 +99,15 @@ export const view = (config) => {
|
|
|
77
99
|
previousKey: 'ArrowUp',
|
|
78
100
|
})), M.exhaustive);
|
|
79
101
|
const resolveKeyIndex = keyToIndex(nextKey, previousKey, tabs.length, focusedIndex, isDisabled);
|
|
80
|
-
const
|
|
81
|
-
const
|
|
102
|
+
const tabSelectedAt = (index) => pipe(tabs, Array.get(index), Option.map(value => SelectedTab({ index, value })));
|
|
103
|
+
const handleAutomaticKeyDown = (key) => M.value(key).pipe(M.whenOr(nextKey, previousKey, 'Home', 'End', 'PageUp', 'PageDown', () => tabSelectedAt(resolveKeyIndex(key))), M.whenOr('Enter', ' ', () => tabSelectedAt(focusedIndex)), M.orElse(() => Option.none()));
|
|
104
|
+
const handleManualKeyDown = (key) => M.value(key).pipe(M.whenOr(nextKey, previousKey, 'Home', 'End', 'PageUp', 'PageDown', () => Option.some(FocusedTab({ index: resolveKeyIndex(key) }))), M.whenOr('Enter', ' ', () => tabSelectedAt(focusedIndex)), M.orElse(() => Option.none()));
|
|
82
105
|
const handleKeyDown = (key) => M.value(activationMode).pipe(M.when('Automatic', () => handleAutomaticKeyDown(key)), M.when('Manual', () => handleManualKeyDown(key)), M.exhaustive);
|
|
83
|
-
const
|
|
84
|
-
const isActive = index ===
|
|
106
|
+
const tabInfos = Array.map(tabs, (value, index) => {
|
|
107
|
+
const isActive = index === activeIndex;
|
|
85
108
|
const isFocused = index === focusedIndex;
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
return h.keyed(tabElement)(tabId(id, index), [
|
|
109
|
+
const isTabDisabledNow = isDisabled(index);
|
|
110
|
+
const tabAttributes = [
|
|
89
111
|
h.Id(tabId(id, index)),
|
|
90
112
|
h.Role('tab'),
|
|
91
113
|
h.Type('button'),
|
|
@@ -93,74 +115,70 @@ export const view = (config) => {
|
|
|
93
115
|
h.AriaControls(tabPanelId(id, index)),
|
|
94
116
|
h.Tabindex(isFocused ? 0 : -1),
|
|
95
117
|
...(isActive ? [h.DataAttribute('selected', '')] : []),
|
|
96
|
-
...(
|
|
118
|
+
...(isTabDisabledNow
|
|
97
119
|
? [
|
|
98
120
|
h.Disabled(true),
|
|
99
121
|
h.AriaDisabled(true),
|
|
100
122
|
h.DataAttribute('disabled', ''),
|
|
101
123
|
]
|
|
102
|
-
: [h.OnClick(
|
|
124
|
+
: [h.OnClick(SelectedTab({ index, value }))]),
|
|
103
125
|
h.OnKeyDownPreventDefault(handleKeyDown),
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
: []),
|
|
107
|
-
...(tabConfig.buttonAttributes ?? []),
|
|
108
|
-
], [tabConfig.buttonContent]);
|
|
109
|
-
});
|
|
110
|
-
const allPanels = Array.map(tabs, (tab, index) => {
|
|
111
|
-
const isActive = index === model.activeIndex;
|
|
112
|
-
const panelConfig = tabToConfig(tab, { isActive });
|
|
113
|
-
return h.keyed(panelElement)(tabPanelId(id, index), [
|
|
126
|
+
];
|
|
127
|
+
const panelAttributes = [
|
|
114
128
|
h.Id(tabPanelId(id, index)),
|
|
115
129
|
h.Role('tabpanel'),
|
|
116
130
|
h.AriaLabelledBy(tabId(id, index)),
|
|
117
131
|
h.Tabindex(isActive ? 0 : -1),
|
|
118
|
-
h.Hidden(!isActive),
|
|
119
132
|
...(isActive ? [h.DataAttribute('selected', '')] : []),
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
133
|
+
];
|
|
134
|
+
return {
|
|
135
|
+
value,
|
|
136
|
+
index,
|
|
137
|
+
isActive,
|
|
138
|
+
isFocused,
|
|
139
|
+
isDisabled: isTabDisabledNow,
|
|
140
|
+
tab: childAttributes(tabAttributes),
|
|
141
|
+
panel: childAttributes(panelAttributes),
|
|
142
|
+
};
|
|
126
143
|
});
|
|
127
|
-
const
|
|
128
|
-
onNone: () => h.empty,
|
|
129
|
-
onSome: tab => {
|
|
130
|
-
const activeConfig = tabToConfig(tab, { isActive: true });
|
|
131
|
-
return h.keyed(panelElement)(tabPanelId(id, model.activeIndex), [
|
|
132
|
-
h.Id(tabPanelId(id, model.activeIndex)),
|
|
133
|
-
h.Role('tabpanel'),
|
|
134
|
-
h.AriaLabelledBy(tabId(id, model.activeIndex)),
|
|
135
|
-
h.Tabindex(0),
|
|
136
|
-
h.DataAttribute('selected', ''),
|
|
137
|
-
...(activeConfig.panelClassName
|
|
138
|
-
? [h.Class(activeConfig.panelClassName)]
|
|
139
|
-
: []),
|
|
140
|
-
...(activeConfig.panelAttributes ?? []),
|
|
141
|
-
], [activeConfig.panelContent]);
|
|
142
|
-
},
|
|
143
|
-
}));
|
|
144
|
-
const tabPanels = persistPanels ? allPanels : [activePanelOnly];
|
|
145
|
-
const resolvedTabListAttributes = [
|
|
144
|
+
const tablistAttributes = [
|
|
146
145
|
h.Role('tablist'),
|
|
147
146
|
h.AriaOrientation(String.toLowerCase(orientation)),
|
|
148
|
-
h.AriaLabel(
|
|
149
|
-
...(tabListClassName ? [h.Class(tabListClassName)] : []),
|
|
150
|
-
...tabListAttributes,
|
|
147
|
+
h.AriaLabel(ariaLabel),
|
|
151
148
|
];
|
|
152
|
-
return
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
149
|
+
return toView({
|
|
150
|
+
tablist: childAttributes(tablistAttributes),
|
|
151
|
+
tabs: tabInfos,
|
|
152
|
+
activeIndex,
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
/** Pairs the tabs `view`, `update`, and `selectTab` behind a single
|
|
156
|
+
* Value-typed entry point. Declare once at module scope so consumers
|
|
157
|
+
* receive `tab.value: Value` in `toView` without an `as` cast:
|
|
158
|
+
*
|
|
159
|
+
* ```ts
|
|
160
|
+
* const DemoTabs = Ui.Tabs.create<DemoTab>()
|
|
161
|
+
*
|
|
162
|
+
* // In view:
|
|
163
|
+
* h.submodel({ view: DemoTabs.view, ... })
|
|
164
|
+
*
|
|
165
|
+
* // In update:
|
|
166
|
+
* const [next, commands] = DemoTabs.update(model, message)
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* The internal view stays typed `ReadonlyArray<string>`; consumers can
|
|
170
|
+
* pass a `ReadonlyArray<MyUnion>` (assignable) and the fenced cast inside
|
|
171
|
+
* `create` types `TabInfo.value` as `MyUnion`. */
|
|
172
|
+
export const create = () => {
|
|
173
|
+
const cast = (result) =>
|
|
174
|
+
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions */
|
|
175
|
+
result;
|
|
176
|
+
return {
|
|
177
|
+
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions */
|
|
178
|
+
view: internalView,
|
|
179
|
+
update: (model, message) => cast(update(model, message)),
|
|
180
|
+
selectTab: (model, value, index) => cast(selectTab(model, value, index)),
|
|
181
|
+
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions */
|
|
182
|
+
reflectSelectedTab: reflectSelectedTab,
|
|
183
|
+
};
|
|
166
184
|
};
|
package/dist/ui/tabs/public.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { init,
|
|
2
|
-
export type { Orientation, ActivationMode, InitConfig,
|
|
1
|
+
export { init, create, Model, Message, OutMessage, Selected, SelectedTab, FocusedTab, CompletedFocusTab, FocusTab, } from './index.js';
|
|
2
|
+
export type { Orientation, ActivationMode, InitConfig, ViewInputs, RenderInfo, TabInfo, } from './index.js';
|
|
3
3
|
//# sourceMappingURL=public.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../../src/ui/tabs/public.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,MAAM,EACN,
|
|
1
|
+
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../../../src/ui/tabs/public.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,MAAM,EACN,KAAK,EACL,OAAO,EACP,UAAU,EACV,QAAQ,EACR,WAAW,EACX,UAAU,EACV,iBAAiB,EACjB,QAAQ,GACT,MAAM,YAAY,CAAA;AAEnB,YAAY,EACV,WAAW,EACX,cAAc,EACd,UAAU,EACV,UAAU,EACV,UAAU,EACV,OAAO,GACR,MAAM,YAAY,CAAA"}
|
package/dist/ui/tabs/public.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { init,
|
|
1
|
+
export { init, create, Model, Message, OutMessage, Selected, SelectedTab, FocusedTab, CompletedFocusTab, FocusTab, } from './index.js';
|