@syware/jlib 0.7.0 → 0.8.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/dist/all.js +2 -2
- package/dist/atoms/jl-select.d.ts +8 -7
- package/dist/atoms/jl-select.js +11 -6
- package/dist/index.js +2 -2
- package/dist/lib/attributes.d.ts +9 -0
- package/dist/lib/attributes.js +10 -1
- package/dist/lib/nav-tree.d.ts +2 -2
- package/dist/lib/palette.d.ts +2 -2
- package/dist/lib/table.d.ts +19 -6
- package/dist/lib/table.js +42 -7
- package/dist/lib/texts.d.ts +2 -0
- package/dist/lib/texts.js +2 -0
- package/dist/molecules/jl-chip-group.d.ts +7 -6
- package/dist/molecules/jl-chip-group.js +6 -4
- package/dist/molecules/jl-menu.d.ts +8 -4
- package/dist/molecules/jl-menu.js +8 -1
- package/dist/molecules/jl-radio-group.d.ts +8 -7
- package/dist/molecules/jl-radio-group.js +10 -6
- package/dist/molecules/jl-segmented.d.ts +8 -7
- package/dist/molecules/jl-segmented.js +10 -5
- package/dist/organisms/jl-command-palette.d.ts +6 -4
- package/dist/organisms/jl-command-palette.js +2 -0
- package/dist/organisms/jl-side-nav.d.ts +8 -7
- package/dist/organisms/jl-side-nav.js +9 -4
- package/dist/organisms/jl-tab-bar.d.ts +8 -7
- package/dist/organisms/jl-tab-bar.js +10 -4
- package/dist/organisms/jl-table.css_raw.js +1 -1
- package/dist/organisms/jl-table.d.ts +54 -16
- package/dist/organisms/jl-table.js +218 -37
- package/dist/types/jl-chip-group.types.d.ts +3 -3
- package/dist/types/jl-command-palette.types.d.ts +10 -6
- package/dist/types/jl-menu.types.d.ts +4 -4
- package/dist/types/jl-radio-group.types.d.ts +6 -3
- package/dist/types/jl-segmented.types.d.ts +6 -3
- package/dist/types/jl-select.types.d.ts +6 -3
- package/dist/types/jl-side-nav.types.d.ts +9 -6
- package/dist/types/jl-tab-bar.types.d.ts +6 -3
- package/dist/types/jl-table.types.d.ts +34 -8
- package/package.json +2 -2
package/dist/all.js
CHANGED
|
@@ -77,7 +77,7 @@ import { JlNavbar } from "./organisms/jl-navbar.js";
|
|
|
77
77
|
import { JlPageHeader } from "./organisms/jl-page-header.js";
|
|
78
78
|
import { JlSideNav } from "./organisms/jl-side-nav.js";
|
|
79
79
|
import { JlTabBar } from "./organisms/jl-tab-bar.js";
|
|
80
|
-
import { JlTable, TABLE_SORT_DIRECTIONS } from "./organisms/jl-table.js";
|
|
80
|
+
import { JlTable, TABLE_EXPANSIONS, TABLE_SORT_DIRECTIONS } from "./organisms/jl-table.js";
|
|
81
81
|
import { JlToaster, TOASTER_PLACEMENTS, download, downloadTexts, toast } from "./organisms/jl-toaster.js";
|
|
82
82
|
import { JlTree } from "./organisms/jl-tree.js";
|
|
83
83
|
import { JlAppShell } from "./templates/jl-app-shell.js";
|
|
@@ -87,4 +87,4 @@ import { JlSplitView, SPLIT_ORIENTATIONS, SPLIT_PANES } from "./templates/jl-spl
|
|
|
87
87
|
// src/all.ts
|
|
88
88
|
registerIcons(COMMON_ICONS);
|
|
89
89
|
define(JlAccordion, JlAccordionItem, JlAccountButton, JlAlert, JlAppIcon, JlAppShell, JlAuthLayout, JlAvatar, JlAvatarGroup, JlBadge, JlBreadcrumb, JlButton, JlCalendar, JlCard, JlCheckbox, JlChip, JlChipGroup, JlCodeBlock, JlCombobox, JlCommandPalette, JlConfirm, JlCopyButton, JlDatePicker, JlDialog, JlDivider, JlDrawer, JlEmpty, JlFacts, JlField, JlFileDrop, JlFlow, JlIcon, JlInput, JlInputList, JlKbd, JlLink, JlListItem, JlLoadMore, JlLoadState, JlMenu, JlNavbar, JlNumberInput, JlPage, JlPageHeader, JlPagination, JlPopover, JlProgress, JlProgressRing, JlRadioGroup, JlRating, JlSearch, JlSearchButton, JlSegmented, JlSelect, JlSideNav, JlSkeleton, JlSlider, JlSpinner, JlSplitView, JlStat, JlSteps, JlSwitch, JlTabBar, JlTable, JlTabPanel, JlTabs, JlTagInput, JlTextarea, JlTimeline, JlToast, JlToaster, JlTooltip, JlTree);
|
|
90
|
-
export { ACCORDION_VARIANTS, AVATAR_SHAPES, AVATAR_SIZES, AVATAR_STATUSES, BASE_STYLES, BUTTON_TYPES, BUTTON_VARIANTS, CARD_PADDINGS, CHIP_SIZES, CODE_LANGUAGES, COMMON_ICONS, CONFIRM_TONES, CONTROL_SIZES, CONTROL_STYLES, DEFAULT_TEXTS, DIALOG_SIZES, DIVIDER_ALIGNS, DRAWER_PLACEMENTS, DRAWER_SIZES, EMPTY_SIZES, FACTS_ORIENTATIONS, FIELD_ORIENTATIONS, FLOATING_STYLES, INPUT_TYPES, JlAccordion, JlAccordionItem, JlAccountButton, JlAlert, JlAppIcon, JlAppShell, JlAuthLayout, JlAvatar, JlAvatarGroup, JlBadge, JlBreadcrumb, JlButton, JlCalendar, JlCard, JlCheckbox, JlChip, JlChipGroup, JlCodeBlock, JlCombobox, JlCommandPalette, JlConfirm, JlCopyButton, JlDatePicker, JlDialog, JlDivider, JlDrawer, JlElement, JlEmpty, JlFacts, JlField, JlFileDrop, JlFlow, JlFormControl, JlIcon, JlInput, JlInputList, JlKbd, JlLink, JlListItem, JlLoadMore, JlLoadState, JlMenu, JlNavbar, JlNumberInput, JlPage, JlPageHeader, JlPagination, JlPopover, JlProgress, JlProgressRing, JlRadioGroup, JlRating, JlSearch, JlSearchButton, JlSegmented, JlSelect, JlSideNav, JlSkeleton, JlSlider, JlSpinner, JlSplitView, JlStat, JlSteps, JlSwitch, JlTabBar, JlTabPanel, JlTable, JlTabs, JlTagInput, JlTextarea, JlTimeline, JlToast, JlToaster, JlTooltip, JlTree, LINK_VARIANTS, LOAD_SKELETONS, LOAD_STATES, PAGE_WIDTHS, PLACEMENTS, PROGRESS_SIZES, PROGRESS_TONES, RADIO_GROUP_ORIENTATIONS, RADIO_GROUP_VARIANTS, SKELETON_SHAPES, SPLIT_ORIENTATIONS, SPLIT_PANES, STAT_TRENDS, STEPS_ORIENTATIONS, SWITCH_SIZES, TABLE_SORT_DIRECTIONS, TAB_VARIANTS, TOASTER_PLACEMENTS, TOAST_TONES, TOKEN_STYLES, TONES, TONE_ICONS, TONE_ICON_FILLED, adoptTokens, cellOf, clampedNumber, computePosition, confirmDialog, define, download, downloadTexts, followAnchor, formatDuration, formatRelativeTime, guardLeave, hasIcon, iconElement, iconNames, jlText, jsonOf, oneOf, placeFloating, registerIcons, setFavicon, setTexts, toast };
|
|
90
|
+
export { ACCORDION_VARIANTS, AVATAR_SHAPES, AVATAR_SIZES, AVATAR_STATUSES, BASE_STYLES, BUTTON_TYPES, BUTTON_VARIANTS, CARD_PADDINGS, CHIP_SIZES, CODE_LANGUAGES, COMMON_ICONS, CONFIRM_TONES, CONTROL_SIZES, CONTROL_STYLES, DEFAULT_TEXTS, DIALOG_SIZES, DIVIDER_ALIGNS, DRAWER_PLACEMENTS, DRAWER_SIZES, EMPTY_SIZES, FACTS_ORIENTATIONS, FIELD_ORIENTATIONS, FLOATING_STYLES, INPUT_TYPES, JlAccordion, JlAccordionItem, JlAccountButton, JlAlert, JlAppIcon, JlAppShell, JlAuthLayout, JlAvatar, JlAvatarGroup, JlBadge, JlBreadcrumb, JlButton, JlCalendar, JlCard, JlCheckbox, JlChip, JlChipGroup, JlCodeBlock, JlCombobox, JlCommandPalette, JlConfirm, JlCopyButton, JlDatePicker, JlDialog, JlDivider, JlDrawer, JlElement, JlEmpty, JlFacts, JlField, JlFileDrop, JlFlow, JlFormControl, JlIcon, JlInput, JlInputList, JlKbd, JlLink, JlListItem, JlLoadMore, JlLoadState, JlMenu, JlNavbar, JlNumberInput, JlPage, JlPageHeader, JlPagination, JlPopover, JlProgress, JlProgressRing, JlRadioGroup, JlRating, JlSearch, JlSearchButton, JlSegmented, JlSelect, JlSideNav, JlSkeleton, JlSlider, JlSpinner, JlSplitView, JlStat, JlSteps, JlSwitch, JlTabBar, JlTabPanel, JlTable, JlTabs, JlTagInput, JlTextarea, JlTimeline, JlToast, JlToaster, JlTooltip, JlTree, LINK_VARIANTS, LOAD_SKELETONS, LOAD_STATES, PAGE_WIDTHS, PLACEMENTS, PROGRESS_SIZES, PROGRESS_TONES, RADIO_GROUP_ORIENTATIONS, RADIO_GROUP_VARIANTS, SKELETON_SHAPES, SPLIT_ORIENTATIONS, SPLIT_PANES, STAT_TRENDS, STEPS_ORIENTATIONS, SWITCH_SIZES, TABLE_EXPANSIONS, TABLE_SORT_DIRECTIONS, TAB_VARIANTS, TOASTER_PLACEMENTS, TOAST_TONES, TOKEN_STYLES, TONES, TONE_ICONS, TONE_ICON_FILLED, adoptTokens, cellOf, clampedNumber, computePosition, confirmDialog, define, download, downloadTexts, followAnchor, formatDuration, formatRelativeTime, guardLeave, hasIcon, iconElement, iconNames, jlText, jsonOf, oneOf, placeFloating, registerIcons, setFavicon, setTexts, toast };
|
|
@@ -4,22 +4,23 @@ import type { ControlSize } from '../types/options.types';
|
|
|
4
4
|
/**
|
|
5
5
|
* A choice among a list, on the browser's own `<select>`: its list opens the way the platform does it on a touch
|
|
6
6
|
* screen, and with a mouse looks like the combobox's where the browser lets the page draw it (customizable select).
|
|
7
|
-
* The choices come from `options` (JSON) or from `<option>` and `<optgroup>` elements written inside it.
|
|
7
|
+
* The choices come from `options` (JSON) or from `<option>` and `<optgroup>` elements written inside it. Typed by its
|
|
8
|
+
* values, `JlSelect<'eur' | 'chf'>` takes options of those values and gives `change` one of them.
|
|
8
9
|
*/
|
|
9
|
-
export declare class JlSelect extends JlFormControl {
|
|
10
|
+
export declare class JlSelect<Value extends string = string> extends JlFormControl {
|
|
10
11
|
static readonly selector = "jl-select";
|
|
11
12
|
readonly events: Readonly<import("@jadis/core").UseEventsHandler<{
|
|
12
|
-
change:
|
|
13
|
+
change: Value;
|
|
13
14
|
}>>;
|
|
14
15
|
/** The choices; an option with a `group` goes under that heading. Empty: the `<option>` children are used. */
|
|
15
16
|
readonly options: Readonly<Readonly<{
|
|
16
|
-
get(): SelectOption[];
|
|
17
|
-
set(setter: SelectOption[] | ((prevState: SelectOption[]) => SelectOption[])): void;
|
|
17
|
+
get(): SelectOption<Value>[];
|
|
18
|
+
set(setter: SelectOption<Value>[] | ((prevState: SelectOption<Value>[]) => SelectOption<Value>[])): void;
|
|
18
19
|
}>>;
|
|
19
20
|
/** The chosen value. One that no option has is kept, as an option of its own, rather than replaced. */
|
|
20
21
|
readonly value: Readonly<Readonly<{
|
|
21
|
-
get():
|
|
22
|
-
set(setter:
|
|
22
|
+
get(): "" | Value;
|
|
23
|
+
set(setter: "" | Value | ((prevState: "" | Value) => "" | Value)): void;
|
|
23
24
|
}>>;
|
|
24
25
|
/** Shown while nothing is chosen; it cannot be picked back from the list. */
|
|
25
26
|
readonly placeholder: Readonly<Readonly<{
|
package/dist/atoms/jl-select.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BASE_STYLES, CONTROL_STYLES, FLOATING_STYLES } from "../styles/shared.js";
|
|
2
2
|
import { JlFormControl } from "../base/jl-form-control.js";
|
|
3
|
-
import { jsonOf, oneOf } from "../lib/attributes.js";
|
|
3
|
+
import { asValue, jsonOf, oneOf, textOf } from "../lib/attributes.js";
|
|
4
4
|
import { registerIcons } from "../lib/icons.js";
|
|
5
5
|
import { CONTROL_SIZES } from "../lib/options.js";
|
|
6
6
|
import { JlIcon } from "./jl-icon.js";
|
|
@@ -31,7 +31,8 @@ var groupNodes = (group) => {
|
|
|
31
31
|
/**
|
|
32
32
|
* A choice among a list, on the browser's own `<select>`: its list opens the way the platform does it on a touch
|
|
33
33
|
* screen, and with a mouse looks like the combobox's where the browser lets the page draw it (customizable select).
|
|
34
|
-
* The choices come from `options` (JSON) or from `<option>` and `<optgroup>` elements written inside it.
|
|
34
|
+
* The choices come from `options` (JSON) or from `<option>` and `<optgroup>` elements written inside it. Typed by its
|
|
35
|
+
* values, `JlSelect<'eur' | 'chf'>` takes options of those values and gives `change` one of them.
|
|
35
36
|
*/
|
|
36
37
|
var JlSelect = class extends JlFormControl {
|
|
37
38
|
static selector = "jl-select";
|
|
@@ -42,7 +43,10 @@ var JlSelect = class extends JlFormControl {
|
|
|
42
43
|
parse: jsonOf([])
|
|
43
44
|
});
|
|
44
45
|
/** The chosen value. One that no option has is kept, as an option of its own, rather than replaced. */
|
|
45
|
-
value = this.useChange(NO_VALUE, () => this.renderOptions(), {
|
|
46
|
+
value = this.useChange(NO_VALUE, () => this.renderOptions(), {
|
|
47
|
+
attribute: "value",
|
|
48
|
+
parse: textOf(NO_VALUE)
|
|
49
|
+
});
|
|
46
50
|
/** Shown while nothing is chosen; it cannot be picked back from the list. */
|
|
47
51
|
placeholder = this.useChange("", () => this.renderOptions(), { attribute: "placeholder" });
|
|
48
52
|
size = this.useChange("md", (value) => this.reflect("size", value), {
|
|
@@ -87,13 +91,14 @@ var JlSelect = class extends JlFormControl {
|
|
|
87
91
|
onConnect() {
|
|
88
92
|
const native = this._refs.native;
|
|
89
93
|
this.on(native, "change", () => {
|
|
90
|
-
|
|
91
|
-
this.
|
|
94
|
+
const value = asValue(native.value);
|
|
95
|
+
this.value.set(value);
|
|
96
|
+
this.events.emit("change", value);
|
|
92
97
|
});
|
|
93
98
|
this.renderOptions();
|
|
94
99
|
}
|
|
95
100
|
resetValue() {
|
|
96
|
-
this.value.set(this.getAttribute("value")
|
|
101
|
+
this.value.set(textOf(NO_VALUE)(this.getAttribute("value")));
|
|
97
102
|
}
|
|
98
103
|
/** The browser calls it for a disabled fieldset and for the element's own disabled attribute, even before render. */
|
|
99
104
|
setDisabledByForm(disabled) {
|
package/dist/index.js
CHANGED
|
@@ -77,11 +77,11 @@ import { JlNavbar } from "./organisms/jl-navbar.js";
|
|
|
77
77
|
import { JlPageHeader } from "./organisms/jl-page-header.js";
|
|
78
78
|
import { JlSideNav } from "./organisms/jl-side-nav.js";
|
|
79
79
|
import { JlTabBar } from "./organisms/jl-tab-bar.js";
|
|
80
|
-
import { JlTable, TABLE_SORT_DIRECTIONS } from "./organisms/jl-table.js";
|
|
80
|
+
import { JlTable, TABLE_EXPANSIONS, TABLE_SORT_DIRECTIONS } from "./organisms/jl-table.js";
|
|
81
81
|
import { JlToaster, TOASTER_PLACEMENTS, download, downloadTexts, toast } from "./organisms/jl-toaster.js";
|
|
82
82
|
import { JlTree } from "./organisms/jl-tree.js";
|
|
83
83
|
import { JlAppShell } from "./templates/jl-app-shell.js";
|
|
84
84
|
import { JlAuthLayout } from "./templates/jl-auth-layout.js";
|
|
85
85
|
import { JlPage, PAGE_WIDTHS } from "./templates/jl-page.js";
|
|
86
86
|
import { JlSplitView, SPLIT_ORIENTATIONS, SPLIT_PANES } from "./templates/jl-split-view.js";
|
|
87
|
-
export { ACCORDION_VARIANTS, AVATAR_SHAPES, AVATAR_SIZES, AVATAR_STATUSES, BASE_STYLES, BUTTON_TYPES, BUTTON_VARIANTS, CARD_PADDINGS, CHIP_SIZES, CODE_LANGUAGES, COMMON_ICONS, CONFIRM_TONES, CONTROL_SIZES, CONTROL_STYLES, DEFAULT_TEXTS, DIALOG_SIZES, DIVIDER_ALIGNS, DRAWER_PLACEMENTS, DRAWER_SIZES, EMPTY_SIZES, FACTS_ORIENTATIONS, FIELD_ORIENTATIONS, FLOATING_STYLES, INPUT_TYPES, JlAccordion, JlAccordionItem, JlAccountButton, JlAlert, JlAppIcon, JlAppShell, JlAuthLayout, JlAvatar, JlAvatarGroup, JlBadge, JlBreadcrumb, JlButton, JlCalendar, JlCard, JlCheckbox, JlChip, JlChipGroup, JlCodeBlock, JlCombobox, JlCommandPalette, JlConfirm, JlCopyButton, JlDatePicker, JlDialog, JlDivider, JlDrawer, JlElement, JlEmpty, JlFacts, JlField, JlFileDrop, JlFlow, JlFormControl, JlIcon, JlInput, JlInputList, JlKbd, JlLink, JlListItem, JlLoadMore, JlLoadState, JlMenu, JlNavbar, JlNumberInput, JlPage, JlPageHeader, JlPagination, JlPopover, JlProgress, JlProgressRing, JlRadioGroup, JlRating, JlSearch, JlSearchButton, JlSegmented, JlSelect, JlSideNav, JlSkeleton, JlSlider, JlSpinner, JlSplitView, JlStat, JlSteps, JlSwitch, JlTabBar, JlTabPanel, JlTable, JlTabs, JlTagInput, JlTextarea, JlTimeline, JlToast, JlToaster, JlTooltip, JlTree, LINK_VARIANTS, LOAD_SKELETONS, LOAD_STATES, PAGE_WIDTHS, PLACEMENTS, PROGRESS_SIZES, PROGRESS_TONES, RADIO_GROUP_ORIENTATIONS, RADIO_GROUP_VARIANTS, SKELETON_SHAPES, SPLIT_ORIENTATIONS, SPLIT_PANES, STAT_TRENDS, STEPS_ORIENTATIONS, SWITCH_SIZES, TABLE_SORT_DIRECTIONS, TAB_VARIANTS, TOASTER_PLACEMENTS, TOAST_TONES, TOKEN_STYLES, TONES, TONE_ICONS, TONE_ICON_FILLED, adoptTokens, cellOf, clampedNumber, computePosition, confirmDialog, define, download, downloadTexts, followAnchor, formatDuration, formatRelativeTime, guardLeave, hasIcon, iconElement, iconNames, jlText, jsonOf, oneOf, placeFloating, registerIcons, setFavicon, setTexts, toast };
|
|
87
|
+
export { ACCORDION_VARIANTS, AVATAR_SHAPES, AVATAR_SIZES, AVATAR_STATUSES, BASE_STYLES, BUTTON_TYPES, BUTTON_VARIANTS, CARD_PADDINGS, CHIP_SIZES, CODE_LANGUAGES, COMMON_ICONS, CONFIRM_TONES, CONTROL_SIZES, CONTROL_STYLES, DEFAULT_TEXTS, DIALOG_SIZES, DIVIDER_ALIGNS, DRAWER_PLACEMENTS, DRAWER_SIZES, EMPTY_SIZES, FACTS_ORIENTATIONS, FIELD_ORIENTATIONS, FLOATING_STYLES, INPUT_TYPES, JlAccordion, JlAccordionItem, JlAccountButton, JlAlert, JlAppIcon, JlAppShell, JlAuthLayout, JlAvatar, JlAvatarGroup, JlBadge, JlBreadcrumb, JlButton, JlCalendar, JlCard, JlCheckbox, JlChip, JlChipGroup, JlCodeBlock, JlCombobox, JlCommandPalette, JlConfirm, JlCopyButton, JlDatePicker, JlDialog, JlDivider, JlDrawer, JlElement, JlEmpty, JlFacts, JlField, JlFileDrop, JlFlow, JlFormControl, JlIcon, JlInput, JlInputList, JlKbd, JlLink, JlListItem, JlLoadMore, JlLoadState, JlMenu, JlNavbar, JlNumberInput, JlPage, JlPageHeader, JlPagination, JlPopover, JlProgress, JlProgressRing, JlRadioGroup, JlRating, JlSearch, JlSearchButton, JlSegmented, JlSelect, JlSideNav, JlSkeleton, JlSlider, JlSpinner, JlSplitView, JlStat, JlSteps, JlSwitch, JlTabBar, JlTabPanel, JlTable, JlTabs, JlTagInput, JlTextarea, JlTimeline, JlToast, JlToaster, JlTooltip, JlTree, LINK_VARIANTS, LOAD_SKELETONS, LOAD_STATES, PAGE_WIDTHS, PLACEMENTS, PROGRESS_SIZES, PROGRESS_TONES, RADIO_GROUP_ORIENTATIONS, RADIO_GROUP_VARIANTS, SKELETON_SHAPES, SPLIT_ORIENTATIONS, SPLIT_PANES, STAT_TRENDS, STEPS_ORIENTATIONS, SWITCH_SIZES, TABLE_EXPANSIONS, TABLE_SORT_DIRECTIONS, TAB_VARIANTS, TOASTER_PLACEMENTS, TOAST_TONES, TOKEN_STYLES, TONES, TONE_ICONS, TONE_ICON_FILLED, adoptTokens, cellOf, clampedNumber, computePosition, confirmDialog, define, download, downloadTexts, followAnchor, formatDuration, formatRelativeTime, guardLeave, hasIcon, iconElement, iconNames, jlText, jsonOf, oneOf, placeFloating, registerIcons, setFavicon, setTexts, toast };
|
package/dist/lib/attributes.d.ts
CHANGED
|
@@ -12,3 +12,12 @@ export declare const clampedNumber: (fallback: number, min: number, max: number)
|
|
|
12
12
|
* (`open`) for the common case of a single one. Empty or unreadable gives an empty list.
|
|
13
13
|
*/
|
|
14
14
|
export declare const stringList: (value: string | null) => string[];
|
|
15
|
+
/**
|
|
16
|
+
* A text the page wrote, in an attribute or an `<option>`, taken as one of a type's values: a choice's value, a
|
|
17
|
+
* field of a table's rows. HTML is not checked against the type, as with `jsonOf`.
|
|
18
|
+
*/
|
|
19
|
+
export declare const asValue: <Value extends string>(text: string) => Value;
|
|
20
|
+
/** A text attribute naming one of a type's values (see `asValue`); a missing one gives the fallback. */
|
|
21
|
+
export declare const textOf: <Value extends string>(fallback: Value) => (value: string | null) => Value;
|
|
22
|
+
/** `stringList` for a list of a type's values (see `asValue`). */
|
|
23
|
+
export declare const textListOf: <Value extends string>(value: string | null) => Value[];
|
package/dist/lib/attributes.js
CHANGED
|
@@ -31,4 +31,13 @@ var stringList = (value) => {
|
|
|
31
31
|
const parsed = jsonOf([])(text);
|
|
32
32
|
return Array.isArray(parsed) ? parsed.map(String) : [];
|
|
33
33
|
};
|
|
34
|
-
|
|
34
|
+
/**
|
|
35
|
+
* A text the page wrote, in an attribute or an `<option>`, taken as one of a type's values: a choice's value, a
|
|
36
|
+
* field of a table's rows. HTML is not checked against the type, as with `jsonOf`.
|
|
37
|
+
*/
|
|
38
|
+
var asValue = (text) => text;
|
|
39
|
+
/** A text attribute naming one of a type's values (see `asValue`); a missing one gives the fallback. */
|
|
40
|
+
var textOf = (fallback) => (value) => value === null ? fallback : asValue(value);
|
|
41
|
+
/** `stringList` for a list of a type's values (see `asValue`). */
|
|
42
|
+
var textListOf = (value) => stringList(value).map((text) => asValue(text));
|
|
43
|
+
export { asValue, clampedNumber, jsonOf, oneOf, stringList, textListOf, textOf };
|
package/dist/lib/nav-tree.d.ts
CHANGED
|
@@ -4,6 +4,6 @@ export declare function pathTo(items: readonly SideNavItem[], id: string): strin
|
|
|
4
4
|
/** The path to an item, looked for in every section. */
|
|
5
5
|
export declare const pathInSections: (sections: readonly SideNavSection[], id: string) => string[];
|
|
6
6
|
/** The item itself when it has no children, otherwise its first leaf: where a parent leads in the icon rail. */
|
|
7
|
-
export declare function firstLeaf(item: SideNavItem): SideNavItem
|
|
7
|
+
export declare function firstLeaf<Id extends string>(item: SideNavItem<Id>): SideNavItem<Id>;
|
|
8
8
|
/** Finds an item by id anywhere in the sections. */
|
|
9
|
-
export declare function findItem(sections: readonly SideNavSection[], id: string): SideNavItem | null;
|
|
9
|
+
export declare function findItem<Id extends string>(sections: readonly SideNavSection<Id>[], id: string): SideNavItem<Id> | null;
|
package/dist/lib/palette.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ import type { PaletteCommand, PaletteGroup, PaletteMatch } from '../types/jl-com
|
|
|
3
3
|
* The commands that match the search, best first; an empty search keeps them all in their order. The label's
|
|
4
4
|
* matched letters come with each, for highlighting; a command found by a keyword only has none.
|
|
5
5
|
*/
|
|
6
|
-
export declare function matchCommands(commands: readonly PaletteCommand[], query: string): PaletteMatch[];
|
|
6
|
+
export declare function matchCommands<Id extends string>(commands: readonly PaletteCommand<Id>[], query: string): PaletteMatch<Id>[];
|
|
7
7
|
/** The matches under their group headings, groups in the order their first command comes. */
|
|
8
|
-
export declare function groupMatches(matches: readonly PaletteMatch[]): PaletteGroup[];
|
|
8
|
+
export declare function groupMatches<Id extends string>(matches: readonly PaletteMatch<Id>[]): PaletteGroup<Id>[];
|
package/dist/lib/table.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TableAlign, TableCellFormat, TableCellRenderer, TableColumn,
|
|
1
|
+
import type { TableAlign, TableCellFormat, TableCellRenderer, TableColumn, TableExpansion, TableRowKey, TableSelectionState, TableSortDirection, TableToggle } from '../types/jl-table.types';
|
|
2
2
|
export declare const nextSortDirection: (direction: TableSortDirection) => TableSortDirection;
|
|
3
3
|
/** A cell's value as a number, `NaN` when it is not one. */
|
|
4
4
|
export declare function toNumber(value: unknown): number;
|
|
@@ -9,27 +9,40 @@ export declare function toTime(value: unknown): number;
|
|
|
9
9
|
* unreadable values come after the others.
|
|
10
10
|
*/
|
|
11
11
|
export declare function compareCells(a: unknown, b: unknown, format: TableCellFormat, locale?: string): number;
|
|
12
|
+
/**
|
|
13
|
+
* A row's field by its name, whatever the page's type of row: a column names its field as text, and the HTML that
|
|
14
|
+
* writes the rows is not checked against a type.
|
|
15
|
+
*/
|
|
16
|
+
export declare const fieldOf: (row: object, key: string) => unknown;
|
|
12
17
|
/**
|
|
13
18
|
* The rows ordered by one column; `none` gives them back as they came. The sort is stable, and empty values stay
|
|
14
19
|
* at the end in both directions.
|
|
15
20
|
*/
|
|
16
|
-
export declare function sortRows(rows: readonly
|
|
21
|
+
export declare function sortRows<Row extends object>(rows: readonly Row[], key: string, direction: TableSortDirection, format?: TableCellFormat, locale?: string): Row[];
|
|
17
22
|
/** A cell's text in its column's format; empty for a missing value. */
|
|
18
23
|
export declare function formatCell(value: unknown, format?: TableCellFormat, locale?: string): string;
|
|
19
24
|
/** Where a column's cells align: as asked, otherwise numbers right and the rest left. */
|
|
20
|
-
export declare function columnAlign(column: TableColumn): TableAlign;
|
|
25
|
+
export declare function columnAlign(column: Pick<TableColumn, 'align' | 'format'>): TableAlign;
|
|
21
26
|
/** A CSS width from a column's `width`: numbers are pixels. */
|
|
22
27
|
export declare function columnWidth(width: string | number | undefined): string;
|
|
23
28
|
/** A row's identity, read from its key field; its position when the field is missing. */
|
|
24
|
-
export declare function rowKeyOf(row:
|
|
29
|
+
export declare function rowKeyOf(row: object, keyField: string, index: number): TableRowKey;
|
|
25
30
|
/** What the select-all box shows: empty, a dash for some rows, a tick for all of them. */
|
|
26
31
|
export declare function selectionState(keys: readonly TableRowKey[], selected: ReadonlySet<TableRowKey>): TableSelectionState;
|
|
27
32
|
/** The selection after the select-all box is pressed: every row when not all were selected, else none of them. */
|
|
28
33
|
export declare function toggleAll(keys: readonly TableRowKey[], selected: ReadonlySet<TableRowKey>): TableRowKey[];
|
|
29
34
|
/** The selection with one row added or taken out. */
|
|
30
35
|
export declare function toggleKey(selected: readonly TableRowKey[], key: TableRowKey, on: boolean): TableRowKey[];
|
|
36
|
+
/** The rows shown open: none when rows do not open, the last one opened when they open one at a time. */
|
|
37
|
+
export declare const openRows: (expanded: readonly TableRowKey[], expansion: TableExpansion) => TableRowKey[];
|
|
38
|
+
/** The open rows after one opens or closes: one at a time, opening a row closes the one that was open. */
|
|
39
|
+
export declare const withRowOpen: (expanded: readonly TableRowKey[], key: TableRowKey, open: boolean, expansion: TableExpansion) => TableRowKey[];
|
|
40
|
+
/** What changed between two sets of open rows, as the `toggle` events to emit: the rows closed, then those opened. */
|
|
41
|
+
export declare function rowToggles(before: readonly TableRowKey[], after: readonly TableRowKey[]): TableToggle[];
|
|
31
42
|
/**
|
|
32
|
-
* A renderer of `renderers` written for the page's own type of row
|
|
33
|
-
*
|
|
43
|
+
* A renderer of `renderers` written for the page's own type of row, for a table that does not say its type of row:
|
|
44
|
+
* the table hands each renderer back a row the page gave it, so
|
|
45
|
+
* `cellOf<Order>((order) => <JlLink href={order.href} label={order.name} />)` reads it typed. A table typed by its
|
|
46
|
+
* rows (`JlTable<Order>`) hands its renderers an order already.
|
|
34
47
|
*/
|
|
35
48
|
export declare const cellOf: <Row>(draw: (row: Row) => Node) => TableCellRenderer;
|
package/dist/lib/table.js
CHANGED
|
@@ -52,6 +52,11 @@ function isUnorderable(value, format) {
|
|
|
52
52
|
}[format]();
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
|
+
* A row's field by its name, whatever the page's type of row: a column names its field as text, and the HTML that
|
|
56
|
+
* writes the rows is not checked against a type.
|
|
57
|
+
*/
|
|
58
|
+
var fieldOf = (row, key) => Reflect.get(row, key);
|
|
59
|
+
/**
|
|
55
60
|
* The rows ordered by one column; `none` gives them back as they came. The sort is stable, and empty values stay
|
|
56
61
|
* at the end in both directions.
|
|
57
62
|
*/
|
|
@@ -59,10 +64,12 @@ function sortRows(rows, key, direction, format = "text", locale) {
|
|
|
59
64
|
const sign = DIRECTION_SIGN[direction];
|
|
60
65
|
if (sign === 0 || key === "") return [...rows];
|
|
61
66
|
return [...rows].sort((a, b) => {
|
|
62
|
-
const
|
|
63
|
-
const
|
|
67
|
+
const aValue = fieldOf(a, key);
|
|
68
|
+
const bValue = fieldOf(b, key);
|
|
69
|
+
const aMissing = isUnorderable(aValue, format);
|
|
70
|
+
const bMissing = isUnorderable(bValue, format);
|
|
64
71
|
if (aMissing || bMissing) return Number(aMissing) - Number(bMissing);
|
|
65
|
-
return sign * COMPARERS[format](
|
|
72
|
+
return sign * COMPARERS[format](aValue, bValue, locale);
|
|
66
73
|
});
|
|
67
74
|
}
|
|
68
75
|
var FORMATTERS = {
|
|
@@ -98,7 +105,7 @@ function columnWidth(width) {
|
|
|
98
105
|
}
|
|
99
106
|
/** A row's identity, read from its key field; its position when the field is missing. */
|
|
100
107
|
function rowKeyOf(row, keyField, index) {
|
|
101
|
-
const value = row
|
|
108
|
+
const value = fieldOf(row, keyField);
|
|
102
109
|
return typeof value === "string" || typeof value === "number" ? value : index;
|
|
103
110
|
}
|
|
104
111
|
/** What the select-all box shows: empty, a dash for some rows, a tick for all of them. */
|
|
@@ -117,9 +124,37 @@ function toggleKey(selected, key, on) {
|
|
|
117
124
|
const without = selected.filter((candidate) => candidate !== key);
|
|
118
125
|
return on ? [...without, key] : without;
|
|
119
126
|
}
|
|
127
|
+
var OPEN_ROWS = {
|
|
128
|
+
multiple: (expanded) => [...expanded],
|
|
129
|
+
none: () => [],
|
|
130
|
+
single: (expanded) => expanded.slice(-1)
|
|
131
|
+
};
|
|
132
|
+
/** The rows shown open: none when rows do not open, the last one opened when they open one at a time. */
|
|
133
|
+
var openRows = (expanded, expansion) => OPEN_ROWS[expansion](expanded);
|
|
134
|
+
var ROW_OPENERS = {
|
|
135
|
+
multiple: (expanded, key, open) => toggleKey(expanded, key, open),
|
|
136
|
+
none: (expanded) => [...expanded],
|
|
137
|
+
single: (expanded, key, open) => open ? [key] : openRows(expanded, "single").filter((candidate) => candidate !== key)
|
|
138
|
+
};
|
|
139
|
+
/** The open rows after one opens or closes: one at a time, opening a row closes the one that was open. */
|
|
140
|
+
var withRowOpen = (expanded, key, open, expansion) => ROW_OPENERS[expansion](expanded, key, open);
|
|
141
|
+
/** What changed between two sets of open rows, as the `toggle` events to emit: the rows closed, then those opened. */
|
|
142
|
+
function rowToggles(before, after) {
|
|
143
|
+
const closed = before.filter((key) => !after.includes(key)).map((key) => ({
|
|
144
|
+
key,
|
|
145
|
+
open: false
|
|
146
|
+
}));
|
|
147
|
+
const opened = after.filter((key) => !before.includes(key)).map((key) => ({
|
|
148
|
+
key,
|
|
149
|
+
open: true
|
|
150
|
+
}));
|
|
151
|
+
return [...closed, ...opened];
|
|
152
|
+
}
|
|
120
153
|
/**
|
|
121
|
-
* A renderer of `renderers` written for the page's own type of row
|
|
122
|
-
*
|
|
154
|
+
* A renderer of `renderers` written for the page's own type of row, for a table that does not say its type of row:
|
|
155
|
+
* the table hands each renderer back a row the page gave it, so
|
|
156
|
+
* `cellOf<Order>((order) => <JlLink href={order.href} label={order.name} />)` reads it typed. A table typed by its
|
|
157
|
+
* rows (`JlTable<Order>`) hands its renderers an order already.
|
|
123
158
|
*/
|
|
124
159
|
var cellOf = (draw) => (row) => draw(row);
|
|
125
|
-
export { cellOf, columnAlign, columnWidth, formatCell, nextSortDirection, rowKeyOf, selectionState, sortRows, toNumber, toTime, toggleAll, toggleKey };
|
|
160
|
+
export { cellOf, columnAlign, columnWidth, fieldOf, formatCell, nextSortDirection, openRows, rowKeyOf, rowToggles, selectionState, sortRows, toNumber, toTime, toggleAll, toggleKey, withRowOpen };
|
package/dist/lib/texts.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export declare const DEFAULT_TEXTS: {
|
|
|
26
26
|
readonly copied: 'Copied';
|
|
27
27
|
readonly copy: 'Copy';
|
|
28
28
|
readonly decrease: 'Decrease';
|
|
29
|
+
readonly details: 'Details';
|
|
30
|
+
readonly detailsOf: 'Details of {name}';
|
|
29
31
|
readonly dismiss: 'Dismiss';
|
|
30
32
|
readonly downloadCancel: 'Cancel';
|
|
31
33
|
readonly downloadFailed: 'Not downloaded: {error}';
|
package/dist/lib/texts.js
CHANGED
|
@@ -5,20 +5,21 @@ import type { ControlSize } from '../types/options.types';
|
|
|
5
5
|
* A row of chips to choose from: a status to filter by, a category, a reason. One choice by default, as radios
|
|
6
6
|
* (choosing the chosen chip again keeps it); `multiple` lets people turn each chip on and off. On a narrow screen
|
|
7
7
|
* the row scrolls sideways; `wrap` lets it go to the next line instead. `change` fires with the chosen values.
|
|
8
|
+
* Typed by its values, `JlChipGroup<'open' | 'done'>` takes options of those values and gives them back.
|
|
8
9
|
*/
|
|
9
|
-
export declare class JlChipGroup extends JlFormControl {
|
|
10
|
+
export declare class JlChipGroup<Value extends string = string> extends JlFormControl {
|
|
10
11
|
static readonly selector = "jl-chip-group";
|
|
11
12
|
readonly events: Readonly<import("@jadis/core").UseEventsHandler<{
|
|
12
|
-
change:
|
|
13
|
+
change: Value[];
|
|
13
14
|
}>>;
|
|
14
15
|
readonly options: Readonly<Readonly<{
|
|
15
|
-
get(): ChipGroupOption[];
|
|
16
|
-
set(setter: ChipGroupOption[] | ((prevState: ChipGroupOption[]) => ChipGroupOption[])): void;
|
|
16
|
+
get(): ChipGroupOption<Value>[];
|
|
17
|
+
set(setter: ChipGroupOption<Value>[] | ((prevState: ChipGroupOption<Value>[]) => ChipGroupOption<Value>[])): void;
|
|
17
18
|
}>>;
|
|
18
19
|
/** The chosen values, in the options' order; with one choice, a list of at most one. */
|
|
19
20
|
readonly value: Readonly<Readonly<{
|
|
20
|
-
get():
|
|
21
|
-
set(setter:
|
|
21
|
+
get(): Value[];
|
|
22
|
+
set(setter: Value[] | ((prevState: Value[]) => Value[])): void;
|
|
22
23
|
}>>;
|
|
23
24
|
/** Several chips can be chosen, each turned on and off on its own. */
|
|
24
25
|
readonly multiple: Readonly<Readonly<{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BASE_STYLES } from "../styles/shared.js";
|
|
2
2
|
import { JlFormControl } from "../base/jl-form-control.js";
|
|
3
|
-
import { jsonOf, oneOf,
|
|
3
|
+
import { jsonOf, oneOf, textListOf } from "../lib/attributes.js";
|
|
4
4
|
import { registerIcons } from "../lib/icons.js";
|
|
5
5
|
import { CONTROL_SIZES } from "../lib/options.js";
|
|
6
6
|
import { jlText } from "../lib/texts.js";
|
|
@@ -38,6 +38,7 @@ var parseOptions = (value) => {
|
|
|
38
38
|
* A row of chips to choose from: a status to filter by, a category, a reason. One choice by default, as radios
|
|
39
39
|
* (choosing the chosen chip again keeps it); `multiple` lets people turn each chip on and off. On a narrow screen
|
|
40
40
|
* the row scrolls sideways; `wrap` lets it go to the next line instead. `change` fires with the chosen values.
|
|
41
|
+
* Typed by its values, `JlChipGroup<'open' | 'done'>` takes options of those values and gives them back.
|
|
41
42
|
*/
|
|
42
43
|
var JlChipGroup = class extends JlFormControl {
|
|
43
44
|
static selector = "jl-chip-group";
|
|
@@ -49,7 +50,7 @@ var JlChipGroup = class extends JlFormControl {
|
|
|
49
50
|
/** The chosen values, in the options' order; with one choice, a list of at most one. */
|
|
50
51
|
value = this.useChange([], () => this.renderValue(), {
|
|
51
52
|
attribute: "value",
|
|
52
|
-
parse:
|
|
53
|
+
parse: textListOf
|
|
53
54
|
});
|
|
54
55
|
/** Several chips can be chosen, each turned on and off on its own. */
|
|
55
56
|
multiple = this.useChange(false, (value) => {
|
|
@@ -114,7 +115,7 @@ var JlChipGroup = class extends JlFormControl {
|
|
|
114
115
|
this._nameWatch.disconnect();
|
|
115
116
|
}
|
|
116
117
|
resetValue() {
|
|
117
|
-
this.value.set(
|
|
118
|
+
this.value.set(textListOf(this.getAttribute("value")));
|
|
118
119
|
}
|
|
119
120
|
/** The browser calls it for a disabled fieldset and for the element's own `disabled`, even before it renders. */
|
|
120
121
|
setDisabledByForm(disabled) {
|
|
@@ -134,7 +135,8 @@ var JlChipGroup = class extends JlFormControl {
|
|
|
134
135
|
}
|
|
135
136
|
/** One choice: the chip becomes it. Several: the chip turns on or off, the values keeping the options' order. */
|
|
136
137
|
press(chip) {
|
|
137
|
-
const value = chip.dataset.value
|
|
138
|
+
const value = this.options.get().find((option) => option.value === chip.dataset.value)?.value;
|
|
139
|
+
if (value === void 0) return;
|
|
138
140
|
this._state.stop = value;
|
|
139
141
|
const chosen = this.chosen();
|
|
140
142
|
if (!this.multiple.get()) {
|
|
@@ -4,17 +4,19 @@ import type { MenuItem } from '../types/jl-menu.types';
|
|
|
4
4
|
/**
|
|
5
5
|
* A list of actions that opens from its trigger (`slot="trigger"`, any button): on a press or with ArrowDown. Arrows,
|
|
6
6
|
* Home, End and the first letter move through it; Enter chooses, Escape closes. `select` fires with the value.
|
|
7
|
+
* Typed by its values, `JlMenu<'edit' | 'delete'>` takes actions of those values and gives `select` one of them:
|
|
8
|
+
* a page handles them with a `Record<'edit' | 'delete', () => void>`, which misses none.
|
|
7
9
|
*/
|
|
8
|
-
export declare class JlMenu extends JlElement {
|
|
10
|
+
export declare class JlMenu<Value extends string = string> extends JlElement {
|
|
9
11
|
static readonly selector = "jl-menu";
|
|
10
12
|
readonly events: Readonly<import("@jadis/core").UseEventsHandler<{
|
|
11
|
-
select:
|
|
13
|
+
select: Value;
|
|
12
14
|
open: undefined;
|
|
13
15
|
close: undefined;
|
|
14
16
|
}>>;
|
|
15
17
|
readonly items: Readonly<Readonly<{
|
|
16
|
-
get(): MenuItem[];
|
|
17
|
-
set(setter: MenuItem[] | ((prevState: MenuItem[]) => MenuItem[])): void;
|
|
18
|
+
get(): MenuItem<Value>[];
|
|
19
|
+
set(setter: MenuItem<Value>[] | ((prevState: MenuItem<Value>[]) => MenuItem<Value>[])): void;
|
|
18
20
|
}>>;
|
|
19
21
|
/** Where the menu goes; it flips to the other side when there is no room. */
|
|
20
22
|
readonly placement: Readonly<Readonly<{
|
|
@@ -50,6 +52,8 @@ export declare class JlMenu extends JlElement {
|
|
|
50
52
|
private focusItem;
|
|
51
53
|
/** Chooses an item people picked: the menu closes, the focus goes back to the trigger, and `select` fires. */
|
|
52
54
|
private chooseItem;
|
|
55
|
+
/** The action an item of the list draws. */
|
|
56
|
+
private actionOf;
|
|
53
57
|
private onToggle;
|
|
54
58
|
private focusIsInMenu;
|
|
55
59
|
/** Keeps the menu by the trigger while it is open. */
|
|
@@ -44,6 +44,8 @@ var isTypeahead = (event) => event.key.length === 1 && event.key !== " " && !eve
|
|
|
44
44
|
/**
|
|
45
45
|
* A list of actions that opens from its trigger (`slot="trigger"`, any button): on a press or with ArrowDown. Arrows,
|
|
46
46
|
* Home, End and the first letter move through it; Enter chooses, Escape closes. `select` fires with the value.
|
|
47
|
+
* Typed by its values, `JlMenu<'edit' | 'delete'>` takes actions of those values and gives `select` one of them:
|
|
48
|
+
* a page handles them with a `Record<'edit' | 'delete', () => void>`, which misses none.
|
|
47
49
|
*/
|
|
48
50
|
var JlMenu = class extends JlElement {
|
|
49
51
|
static selector = "jl-menu";
|
|
@@ -192,9 +194,14 @@ var JlMenu = class extends JlElement {
|
|
|
192
194
|
/** Chooses an item people picked: the menu closes, the focus goes back to the trigger, and `select` fires. */
|
|
193
195
|
chooseItem(item) {
|
|
194
196
|
if (!(item instanceof HTMLElement) || item.hasAttribute("aria-disabled")) return;
|
|
197
|
+
const action = this.actionOf(item);
|
|
195
198
|
this.close();
|
|
196
199
|
this.triggerElement()?.focus();
|
|
197
|
-
this.events.emit("select",
|
|
200
|
+
if (action !== void 0) this.events.emit("select", action.value);
|
|
201
|
+
}
|
|
202
|
+
/** The action an item of the list draws. */
|
|
203
|
+
actionOf(item) {
|
|
204
|
+
return this.items.get().find((entry) => "value" in entry && entry.value === item.dataset.value);
|
|
198
205
|
}
|
|
199
206
|
onToggle(open) {
|
|
200
207
|
this.renderTrigger();
|
|
@@ -4,20 +4,21 @@ export declare const RADIO_GROUP_ORIENTATIONS: readonly RadioGroupOrientation[];
|
|
|
4
4
|
export declare const RADIO_GROUP_VARIANTS: readonly RadioGroupVariant[];
|
|
5
5
|
/**
|
|
6
6
|
* One choice among a few, all in view. It behaves as native radios: Tab reaches the chosen option, the arrow keys
|
|
7
|
-
* move the choice, Space chooses the focused option. `variant="cards"` draws each option as a card.
|
|
7
|
+
* move the choice, Space chooses the focused option. `variant="cards"` draws each option as a card. Typed by its
|
|
8
|
+
* values, `JlRadioGroup<'card' | 'invoice'>` takes options of those values and gives `change` one of them.
|
|
8
9
|
*/
|
|
9
|
-
export declare class JlRadioGroup extends JlFormControl {
|
|
10
|
+
export declare class JlRadioGroup<Value extends string = string> extends JlFormControl {
|
|
10
11
|
static readonly selector = "jl-radio-group";
|
|
11
12
|
readonly events: Readonly<import("@jadis/core").UseEventsHandler<{
|
|
12
|
-
change:
|
|
13
|
+
change: Value;
|
|
13
14
|
}>>;
|
|
14
15
|
readonly options: Readonly<Readonly<{
|
|
15
|
-
get(): RadioOption[];
|
|
16
|
-
set(setter: RadioOption[] | ((prevState: RadioOption[]) => RadioOption[])): void;
|
|
16
|
+
get(): RadioOption<Value>[];
|
|
17
|
+
set(setter: RadioOption<Value>[] | ((prevState: RadioOption<Value>[]) => RadioOption<Value>[])): void;
|
|
17
18
|
}>>;
|
|
18
19
|
readonly value: Readonly<Readonly<{
|
|
19
|
-
get():
|
|
20
|
-
set(setter:
|
|
20
|
+
get(): "" | Value;
|
|
21
|
+
set(setter: "" | Value | ((prevState: "" | Value) => "" | Value)): void;
|
|
21
22
|
}>>;
|
|
22
23
|
readonly orientation: Readonly<Readonly<{
|
|
23
24
|
get(): RadioGroupOrientation;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BASE_STYLES } from "../styles/shared.js";
|
|
2
2
|
import { JlFormControl } from "../base/jl-form-control.js";
|
|
3
|
-
import { jsonOf, oneOf } from "../lib/attributes.js";
|
|
3
|
+
import { jsonOf, oneOf, textOf } from "../lib/attributes.js";
|
|
4
4
|
import { jlText } from "../lib/texts.js";
|
|
5
5
|
import { rovingIndex } from "../lib/roving-index.js";
|
|
6
6
|
import jl_radio_group_default from "./jl-radio-group.css_raw.js";
|
|
@@ -23,7 +23,8 @@ var MOVES = /* @__PURE__ */ new Map([
|
|
|
23
23
|
var SPACE = " ";
|
|
24
24
|
/**
|
|
25
25
|
* One choice among a few, all in view. It behaves as native radios: Tab reaches the chosen option, the arrow keys
|
|
26
|
-
* move the choice, Space chooses the focused option. `variant="cards"` draws each option as a card.
|
|
26
|
+
* move the choice, Space chooses the focused option. `variant="cards"` draws each option as a card. Typed by its
|
|
27
|
+
* values, `JlRadioGroup<'card' | 'invoice'>` takes options of those values and gives `change` one of them.
|
|
27
28
|
*/
|
|
28
29
|
var JlRadioGroup = class extends JlFormControl {
|
|
29
30
|
static selector = "jl-radio-group";
|
|
@@ -32,7 +33,10 @@ var JlRadioGroup = class extends JlFormControl {
|
|
|
32
33
|
attribute: "options",
|
|
33
34
|
parse: jsonOf([])
|
|
34
35
|
});
|
|
35
|
-
value = this.useChange(NO_VALUE, () => this.renderValue(), {
|
|
36
|
+
value = this.useChange(NO_VALUE, () => this.renderValue(), {
|
|
37
|
+
attribute: "value",
|
|
38
|
+
parse: textOf(NO_VALUE)
|
|
39
|
+
});
|
|
36
40
|
orientation = this.useChange("vertical", (value) => {
|
|
37
41
|
this.reflect("orientation", value);
|
|
38
42
|
this._refs.group.setAttribute("aria-orientation", value);
|
|
@@ -95,7 +99,7 @@ var JlRadioGroup = class extends JlFormControl {
|
|
|
95
99
|
this.on(list, "keydown", (event) => this.onKey(event));
|
|
96
100
|
}
|
|
97
101
|
resetValue() {
|
|
98
|
-
this.value.set(this.getAttribute("value")
|
|
102
|
+
this.value.set(textOf(NO_VALUE)(this.getAttribute("value")));
|
|
99
103
|
}
|
|
100
104
|
/** The browser calls it for a disabled fieldset and for the element's own disabled attribute, even before render. */
|
|
101
105
|
setDisabledByForm(disabled) {
|
|
@@ -124,8 +128,8 @@ var JlRadioGroup = class extends JlFormControl {
|
|
|
124
128
|
}
|
|
125
129
|
choose(radio) {
|
|
126
130
|
radio.focus();
|
|
127
|
-
const value = radio.dataset.value
|
|
128
|
-
if (value === this.value.get()) return;
|
|
131
|
+
const value = this.options.get().find((option) => option.value === radio.dataset.value)?.value;
|
|
132
|
+
if (value === void 0 || value === this.value.get()) return;
|
|
129
133
|
this.value.set(value);
|
|
130
134
|
this.events.emit("change", value);
|
|
131
135
|
}
|
|
@@ -3,21 +3,22 @@ import type { SegmentedOption } from '../types/jl-segmented.types';
|
|
|
3
3
|
import type { ControlSize } from '../types/options.types';
|
|
4
4
|
/**
|
|
5
5
|
* A row of a few exclusive choices with a thumb that slides to the chosen one: a view switch, a period, a
|
|
6
|
-
* density. It takes part in forms like a radio group; `change` fires with the value people pick.
|
|
6
|
+
* density. It takes part in forms like a radio group; `change` fires with the value people pick. Typed by its values,
|
|
7
|
+
* `JlSegmented<'list' | 'grid'>` takes options of those values and gives `change` one of them.
|
|
7
8
|
*/
|
|
8
|
-
export declare class JlSegmented extends JlFormControl {
|
|
9
|
+
export declare class JlSegmented<Value extends string = string> extends JlFormControl {
|
|
9
10
|
static readonly selector = "jl-segmented";
|
|
10
11
|
readonly events: Readonly<import("@jadis/core").UseEventsHandler<{
|
|
11
|
-
change:
|
|
12
|
+
change: Value;
|
|
12
13
|
}>>;
|
|
13
14
|
readonly options: Readonly<Readonly<{
|
|
14
|
-
get(): SegmentedOption[];
|
|
15
|
-
set(setter: SegmentedOption[] | ((prevState: SegmentedOption[]) => SegmentedOption[])): void;
|
|
15
|
+
get(): SegmentedOption<Value>[];
|
|
16
|
+
set(setter: SegmentedOption<Value>[] | ((prevState: SegmentedOption<Value>[]) => SegmentedOption<Value>[])): void;
|
|
16
17
|
}>>;
|
|
17
18
|
/** The chosen option's value; the first option that can be chosen when it names none. */
|
|
18
19
|
readonly value: Readonly<Readonly<{
|
|
19
|
-
get():
|
|
20
|
-
set(setter:
|
|
20
|
+
get(): "" | Value;
|
|
21
|
+
set(setter: "" | Value | ((prevState: "" | Value) => "" | Value)): void;
|
|
21
22
|
}>>;
|
|
22
23
|
readonly size: Readonly<Readonly<{
|
|
23
24
|
get(): ControlSize;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BASE_STYLES } from "../styles/shared.js";
|
|
2
2
|
import { JlFormControl } from "../base/jl-form-control.js";
|
|
3
|
-
import { jsonOf, oneOf } from "../lib/attributes.js";
|
|
3
|
+
import { jsonOf, oneOf, textOf } from "../lib/attributes.js";
|
|
4
4
|
import { CONTROL_SIZES } from "../lib/options.js";
|
|
5
5
|
import { JlIcon } from "../atoms/jl-icon.js";
|
|
6
6
|
import { setOrRemove } from "../lib/dom.js";
|
|
@@ -16,6 +16,7 @@ var ICON_SIZES = {
|
|
|
16
16
|
md: 16,
|
|
17
17
|
sm: 14
|
|
18
18
|
};
|
|
19
|
+
var NO_VALUE = "";
|
|
19
20
|
var KEY_MOVES = /* @__PURE__ */ new Map([
|
|
20
21
|
["ArrowDown", (enabled, from) => stepIndex(enabled, from, 1)],
|
|
21
22
|
["ArrowLeft", (enabled, from) => stepIndex(enabled, from, -1)],
|
|
@@ -26,7 +27,8 @@ var KEY_MOVES = /* @__PURE__ */ new Map([
|
|
|
26
27
|
]);
|
|
27
28
|
/**
|
|
28
29
|
* A row of a few exclusive choices with a thumb that slides to the chosen one: a view switch, a period, a
|
|
29
|
-
* density. It takes part in forms like a radio group; `change` fires with the value people pick.
|
|
30
|
+
* density. It takes part in forms like a radio group; `change` fires with the value people pick. Typed by its values,
|
|
31
|
+
* `JlSegmented<'list' | 'grid'>` takes options of those values and gives `change` one of them.
|
|
30
32
|
*/
|
|
31
33
|
var JlSegmented = class extends JlFormControl {
|
|
32
34
|
static selector = "jl-segmented";
|
|
@@ -36,7 +38,10 @@ var JlSegmented = class extends JlFormControl {
|
|
|
36
38
|
parse: jsonOf([])
|
|
37
39
|
});
|
|
38
40
|
/** The chosen option's value; the first option that can be chosen when it names none. */
|
|
39
|
-
value = this.useChange(
|
|
41
|
+
value = this.useChange(NO_VALUE, () => this.renderValue(), {
|
|
42
|
+
attribute: "value",
|
|
43
|
+
parse: textOf(NO_VALUE)
|
|
44
|
+
});
|
|
40
45
|
size = this.useChange("md", (value) => {
|
|
41
46
|
this.reflect("size", value);
|
|
42
47
|
this.renderOptions();
|
|
@@ -91,7 +96,7 @@ var JlSegmented = class extends JlFormControl {
|
|
|
91
96
|
this._resize.disconnect();
|
|
92
97
|
}
|
|
93
98
|
resetValue() {
|
|
94
|
-
this.value.set(this.getAttribute("value")
|
|
99
|
+
this.value.set(textOf(NO_VALUE)(this.getAttribute("value")));
|
|
95
100
|
}
|
|
96
101
|
/** The browser calls it for a disabled fieldset and for the element's own `disabled`, even before it renders. */
|
|
97
102
|
setDisabledByForm(disabled) {
|
|
@@ -155,7 +160,7 @@ var JlSegmented = class extends JlFormControl {
|
|
|
155
160
|
this.value.set(option.value);
|
|
156
161
|
return;
|
|
157
162
|
}
|
|
158
|
-
const value = option?.value ??
|
|
163
|
+
const value = option?.value ?? NO_VALUE;
|
|
159
164
|
this.segments().forEach((segment) => {
|
|
160
165
|
const checked = segment.dataset.value === value;
|
|
161
166
|
segment.setAttribute("aria-checked", String(checked));
|