@syware/jlib 0.6.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.
Files changed (130) hide show
  1. package/dist/all.js +10 -5
  2. package/dist/atoms/jl-app-icon.d.ts +5 -0
  3. package/dist/atoms/jl-app-icon.js +26 -4
  4. package/dist/atoms/jl-badge.js +1 -1
  5. package/dist/atoms/jl-button.d.ts +5 -0
  6. package/dist/atoms/jl-button.js +4 -1
  7. package/dist/atoms/jl-chip.js +3 -2
  8. package/dist/atoms/jl-input.js +4 -3
  9. package/dist/atoms/jl-link.js +1 -1
  10. package/dist/atoms/jl-rating.js +4 -5
  11. package/dist/atoms/jl-select.css_raw.js +1 -1
  12. package/dist/atoms/jl-select.d.ts +10 -8
  13. package/dist/atoms/jl-select.js +15 -9
  14. package/dist/atoms/jl-spinner.js +2 -2
  15. package/dist/base/jl-form-control.js +2 -1
  16. package/dist/index.d.ts +8 -0
  17. package/dist/index.js +9 -4
  18. package/dist/lib/app-icon.d.ts +8 -0
  19. package/dist/lib/app-icon.js +37 -0
  20. package/dist/lib/attributes.d.ts +9 -0
  21. package/dist/lib/attributes.js +10 -1
  22. package/dist/lib/dom.d.ts +2 -0
  23. package/dist/lib/dom.js +3 -1
  24. package/dist/lib/download.d.ts +10 -0
  25. package/dist/lib/download.js +62 -0
  26. package/dist/lib/icons.d.ts +4 -0
  27. package/dist/lib/icons.js +7 -4
  28. package/dist/lib/input-list.d.ts +12 -0
  29. package/dist/lib/input-list.js +14 -0
  30. package/dist/lib/internals.d.ts +5 -0
  31. package/dist/lib/internals.js +18 -0
  32. package/dist/lib/nav-tree.d.ts +2 -2
  33. package/dist/lib/palette.d.ts +2 -2
  34. package/dist/lib/palette.js +6 -0
  35. package/dist/lib/resize.d.ts +2 -0
  36. package/dist/lib/resize.js +10 -0
  37. package/dist/lib/table.d.ts +22 -4
  38. package/dist/lib/table.js +55 -5
  39. package/dist/lib/text.d.ts +2 -0
  40. package/dist/lib/text.js +4 -1
  41. package/dist/lib/texts.d.ts +99 -0
  42. package/dist/lib/texts.js +104 -0
  43. package/dist/lib/tree.d.ts +10 -1
  44. package/dist/lib/tree.js +37 -3
  45. package/dist/molecules/jl-account-button.js +1 -1
  46. package/dist/molecules/jl-alert.js +2 -1
  47. package/dist/molecules/jl-breadcrumb.js +3 -3
  48. package/dist/molecules/jl-calendar.js +4 -4
  49. package/dist/molecules/jl-chip-group.d.ts +7 -6
  50. package/dist/molecules/jl-chip-group.js +8 -6
  51. package/dist/molecules/jl-code-block.css_raw.js +1 -1
  52. package/dist/molecules/jl-code-block.d.ts +5 -0
  53. package/dist/molecules/jl-code-block.js +5 -2
  54. package/dist/molecules/jl-combobox.js +5 -6
  55. package/dist/molecules/jl-copy-button.js +5 -4
  56. package/dist/molecules/jl-date-picker.js +6 -7
  57. package/dist/molecules/jl-empty.js +1 -1
  58. package/dist/molecules/jl-facts.css_raw.js +3 -0
  59. package/dist/molecules/jl-facts.d.ts +35 -0
  60. package/dist/molecules/jl-facts.js +64 -0
  61. package/dist/molecules/jl-file-drop.d.ts +5 -0
  62. package/dist/molecules/jl-file-drop.js +17 -14
  63. package/dist/molecules/jl-input-list.css_raw.js +3 -0
  64. package/dist/molecules/jl-input-list.d.ts +79 -0
  65. package/dist/molecules/jl-input-list.js +177 -0
  66. package/dist/molecules/jl-load-more.css_raw.js +3 -0
  67. package/dist/molecules/jl-load-more.d.ts +41 -0
  68. package/dist/molecules/jl-load-more.js +62 -0
  69. package/dist/molecules/jl-load-state.js +6 -7
  70. package/dist/molecules/jl-menu.d.ts +8 -4
  71. package/dist/molecules/jl-menu.js +8 -1
  72. package/dist/molecules/jl-number-input.js +4 -4
  73. package/dist/molecules/jl-pagination.js +5 -5
  74. package/dist/molecules/jl-radio-group.d.ts +8 -7
  75. package/dist/molecules/jl-radio-group.js +12 -8
  76. package/dist/molecules/jl-search-button.js +4 -4
  77. package/dist/molecules/jl-search.js +4 -4
  78. package/dist/molecules/jl-segmented.d.ts +8 -7
  79. package/dist/molecules/jl-segmented.js +12 -6
  80. package/dist/molecules/jl-steps.css_raw.js +1 -1
  81. package/dist/molecules/jl-steps.d.ts +2 -0
  82. package/dist/molecules/jl-steps.js +30 -14
  83. package/dist/molecules/jl-tabs.js +2 -1
  84. package/dist/molecules/jl-tag-input.js +2 -2
  85. package/dist/molecules/jl-toast.css_raw.js +1 -1
  86. package/dist/molecules/jl-toast.d.ts +13 -1
  87. package/dist/molecules/jl-toast.js +23 -3
  88. package/dist/organisms/jl-command-palette.css_raw.js +1 -1
  89. package/dist/organisms/jl-command-palette.d.ts +20 -4
  90. package/dist/organisms/jl-command-palette.js +41 -9
  91. package/dist/organisms/jl-confirm.js +5 -7
  92. package/dist/organisms/jl-dialog.js +2 -1
  93. package/dist/organisms/jl-drawer.js +2 -1
  94. package/dist/organisms/jl-flow.js +12 -12
  95. package/dist/organisms/jl-navbar.js +6 -6
  96. package/dist/organisms/jl-side-nav.css_raw.js +1 -1
  97. package/dist/organisms/jl-side-nav.d.ts +40 -7
  98. package/dist/organisms/jl-side-nav.js +78 -16
  99. package/dist/organisms/jl-tab-bar.d.ts +8 -7
  100. package/dist/organisms/jl-tab-bar.js +12 -6
  101. package/dist/organisms/jl-table.css_raw.js +1 -1
  102. package/dist/organisms/jl-table.d.ts +62 -15
  103. package/dist/organisms/jl-table.js +246 -35
  104. package/dist/organisms/jl-toaster.d.ts +9 -1
  105. package/dist/organisms/jl-toaster.js +148 -7
  106. package/dist/organisms/jl-tree.css_raw.js +1 -1
  107. package/dist/organisms/jl-tree.d.ts +71 -4
  108. package/dist/organisms/jl-tree.js +303 -40
  109. package/dist/templates/jl-app-shell.css_raw.js +1 -1
  110. package/dist/templates/jl-app-shell.d.ts +10 -0
  111. package/dist/templates/jl-app-shell.js +16 -2
  112. package/dist/templates/jl-auth-layout.js +1 -1
  113. package/dist/templates/jl-page.js +3 -3
  114. package/dist/templates/jl-split-view.js +5 -4
  115. package/dist/types/jl-app-icon.types.d.ts +5 -0
  116. package/dist/types/jl-chip-group.types.d.ts +3 -3
  117. package/dist/types/jl-command-palette.types.d.ts +17 -6
  118. package/dist/types/jl-facts.types.d.ts +17 -0
  119. package/dist/types/jl-menu.types.d.ts +4 -4
  120. package/dist/types/jl-radio-group.types.d.ts +6 -3
  121. package/dist/types/jl-segmented.types.d.ts +6 -3
  122. package/dist/types/jl-select.types.d.ts +6 -3
  123. package/dist/types/jl-side-nav.types.d.ts +11 -6
  124. package/dist/types/jl-steps.types.d.ts +2 -0
  125. package/dist/types/jl-tab-bar.types.d.ts +6 -3
  126. package/dist/types/jl-table.types.d.ts +42 -9
  127. package/dist/types/jl-toaster.types.d.ts +42 -1
  128. package/dist/types/jl-tree.types.d.ts +26 -0
  129. package/dist/types/texts.types.d.ts +5 -0
  130. package/package.json +3 -3
@@ -3,6 +3,7 @@ import { JlElement } from "../base/jl-element.js";
3
3
  import { oneOf } from "../lib/attributes.js";
4
4
  import { define } from "../lib/define.js";
5
5
  import { registerIcons } from "../lib/icons.js";
6
+ import { jlText } from "../lib/texts.js";
6
7
  import { setOrRemove } from "../lib/dom.js";
7
8
  import { JlButton } from "../atoms/jl-button.js";
8
9
  import { JlPageHeader } from "../organisms/jl-page-header.js";
@@ -20,7 +21,6 @@ var PAGE_WIDTHS = [
20
21
  "full"
21
22
  ];
22
23
  var BREADCRUMB_SLOT = "breadcrumb";
23
- var DEFAULT_BACK_LABEL = "Back";
24
24
  var TITLE_SEPARATOR = " · ";
25
25
  /**
26
26
  * A page of an app: its header (a back link named after the page it leads to, the heading, a sentence on what the
@@ -48,7 +48,7 @@ var JlPage = class extends JlElement {
48
48
  appName = this.useChange("", () => this.renderTitle(), { attribute: "app-name" });
49
49
  _refs = this.useRefs((ref) => ({
50
50
  back: ref(".back"),
51
- header: ref("jl-page-header")
51
+ header: ref(JlPageHeader)
52
52
  }));
53
53
  templateHtml() {
54
54
  return /* @__PURE__ */ jsxs("div", {
@@ -88,7 +88,7 @@ var JlPage = class extends JlElement {
88
88
  const back = this._refs.back;
89
89
  const href = this.back.get();
90
90
  back.href.set(href);
91
- back.label.set(this.backLabel.get() || DEFAULT_BACK_LABEL);
91
+ back.label.set(this.backLabel.get() || jlText("back"));
92
92
  setOrRemove(back, "slot", href === "" ? "" : BREADCRUMB_SLOT);
93
93
  }
94
94
  renderTitle() {
@@ -1,6 +1,8 @@
1
1
  import { BASE_STYLES } from "../styles/shared.js";
2
2
  import { JlElement } from "../base/jl-element.js";
3
3
  import { clampedNumber, oneOf } from "../lib/attributes.js";
4
+ import { jlText } from "../lib/texts.js";
5
+ import { watchSizes } from "../lib/resize.js";
4
6
  import { clampMin, clampSplit, positionAfterKey, positionAt } from "../lib/split.js";
5
7
  import jl_split_view_default from "./jl-split-view.css_raw.js";
6
8
  import { css } from "@jadis/core";
@@ -13,7 +15,6 @@ var DEFAULT_MIN = 15;
13
15
  var FULL = 100;
14
16
  var MAX_MIN = 50;
15
17
  var PRIMARY_BUTTON = 0;
16
- var DEFAULT_LABEL = "Resize the panes";
17
18
  var STACKED = "stacked";
18
19
  var MAX_STACK_WIDTH = 4e3;
19
20
  var SEPARATOR_ORIENTATION = {
@@ -61,11 +62,11 @@ var JlSplitView = class extends JlElement {
61
62
  parse: oneOf(SPLIT_PANES, "start")
62
63
  });
63
64
  /** The divider's name for screen readers. */
64
- label = this.useChange(DEFAULT_LABEL, (value) => {
65
- this._refs.divider.setAttribute("aria-label", value === "" ? DEFAULT_LABEL : value);
65
+ label = this.useChange(jlText("resizePanes"), (value) => {
66
+ this._refs.divider.setAttribute("aria-label", value === "" ? jlText("resizePanes") : value);
66
67
  }, { attribute: "label" });
67
68
  _drag = { from: DEFAULT_POSITION };
68
- _resize = new ResizeObserver(() => this.renderStacked());
69
+ _resize = watchSizes(() => this.renderStacked());
69
70
  /** Whether it shows one pane at a time now. */
70
71
  isStacked() {
71
72
  return this.hasAttribute(STACKED);
@@ -0,0 +1,5 @@
1
+ /** The colours an app's icon is drawn in as a file: its tile's and its glyph's. */
2
+ export type AppIconColors = {
3
+ tile: string;
4
+ glyph: string;
5
+ };
@@ -1,6 +1,6 @@
1
- /** One choice of a chip group. */
2
- export type ChipGroupOption = {
3
- value: string;
1
+ /** One choice of a chip group. Typed by its values (`ChipGroupOption<'open' | 'done'>`), `value` is one of them. */
2
+ export type ChipGroupOption<Value extends string = string> = {
3
+ value: Value;
4
4
  label: string;
5
5
  /** An icon name before the label; a chosen chip without one shows a check. */
6
6
  icon?: string;
@@ -1,22 +1,33 @@
1
- export type PaletteCommand = {
2
- id: string;
1
+ /**
2
+ * A command of the palette: `select` fires with its id. Typed by its ids (`PaletteCommand<'theme' | 'logout'>`, or
3
+ * `` `open:${string}` `` for the records a search finds), `id` is one of them.
4
+ */
5
+ export type PaletteCommand<Id extends string = string> = {
6
+ id: Id;
3
7
  label: string;
4
8
  /** The heading the command is listed under. */
5
9
  group?: string;
6
10
  icon?: string;
11
+ /** What it is, beside its label and quieter: a record's type, a person's username. Tells apart two of one name. */
12
+ description?: string;
7
13
  /** Keys shown beside it, joined by `+`: `mod+shift+p` (`mod` is ⌘ on Apple, Ctrl elsewhere). */
8
14
  shortcut?: string;
9
15
  /** Other words that find it: `["preferences", "options"]` for "Settings". */
10
16
  keywords?: string[];
17
+ /**
18
+ * Found by the page for what was typed (a record, a person, "Open" with the ID pasted): listed whatever the
19
+ * search, since the page chose it already, after the commands the search matches.
20
+ */
21
+ result?: boolean;
11
22
  };
12
23
  /** A command that matches the search, with the places of the matched letters in its label. */
13
- export type PaletteMatch = {
14
- command: PaletteCommand;
24
+ export type PaletteMatch<Id extends string = string> = {
25
+ command: PaletteCommand<Id>;
15
26
  score: number;
16
27
  positions: number[];
17
28
  };
18
29
  /** Commands under one heading, in the order they are listed. */
19
- export type PaletteGroup = {
30
+ export type PaletteGroup<Id extends string = string> = {
20
31
  label: string;
21
- matches: PaletteMatch[];
32
+ matches: PaletteMatch<Id>[];
22
33
  };
@@ -0,0 +1,17 @@
1
+ /** One fact about a thing: its label and value. A fact without a value is left out. */
2
+ export type Fact = {
3
+ label: string;
4
+ value: string | number | null;
5
+ /** Drawn in the monospace font and broken anywhere: an identifier, a digest, a path. */
6
+ code?: boolean;
7
+ /** An address: the value is a link to it. */
8
+ href?: string;
9
+ /** The value's tooltip. */
10
+ hint?: string;
11
+ /** Names the fact for a renderer of `renderers`, which then draws its value. */
12
+ key?: string;
13
+ };
14
+ /** Draws a fact's value: a badge, links, a list. */
15
+ export type FactRenderer = (fact: Fact) => Node;
16
+ /** `horizontal` puts each label beside its value, `vertical` over it, the facts side by side. */
17
+ export type FactsOrientation = 'horizontal' | 'vertical';
@@ -1,6 +1,6 @@
1
- /** A choice of a menu: `select` fires with its value. */
2
- export type MenuAction = {
3
- value: string;
1
+ /** A choice of a menu: `select` fires with its value. Typed (`MenuAction<'edit' | 'delete'>`), it is one of those. */
2
+ export type MenuAction<Value extends string = string> = {
3
+ value: Value;
4
4
  label: string;
5
5
  icon?: string;
6
6
  /** The keys that do the same, shown at the end: "⌘D". */
@@ -19,4 +19,4 @@ export type MenuDivider = {
19
19
  export type MenuHeading = {
20
20
  heading: string;
21
21
  };
22
- export type MenuItem = MenuAction | MenuDivider | MenuHeading;
22
+ export type MenuItem<Value extends string = string> = MenuAction<Value> | MenuDivider | MenuHeading;
@@ -1,6 +1,9 @@
1
- /** One choice of a radio group, with an optional line that explains it. */
2
- export type RadioOption = {
3
- value: string;
1
+ /**
2
+ * One choice of a radio group, with an optional line that explains it. Typed by its values
3
+ * (`RadioOption<'card' | 'invoice'>`), `value` is one of them.
4
+ */
5
+ export type RadioOption<Value extends string = string> = {
6
+ value: Value;
4
7
  label: string;
5
8
  description?: string;
6
9
  disabled?: boolean;
@@ -1,6 +1,9 @@
1
- /** One choice of a segmented control; without a label it shows its icon, and its value names it. */
2
- export type SegmentedOption = {
3
- value: string;
1
+ /**
2
+ * One choice of a segmented control; without a label it shows its icon, and its value names it. Typed by its values
3
+ * (`SegmentedOption<'list' | 'grid'>`), `value` is one of them.
4
+ */
5
+ export type SegmentedOption<Value extends string = string> = {
6
+ value: Value;
4
7
  label?: string;
5
8
  icon?: string;
6
9
  /** A count or a short word after the label: what waits behind the choice. */
@@ -1,6 +1,9 @@
1
- /** One choice of a select: `group` gathers it with the others of the same group under that heading. */
2
- export type SelectOption = {
3
- value: string;
1
+ /**
2
+ * One choice of a select: `group` gathers it with the others of the same group under that heading. Typed by its
3
+ * values (`SelectOption<'eur' | 'chf'>`), `value` is one of them.
4
+ */
5
+ export type SelectOption<Value extends string = string> = {
6
+ value: Value;
4
7
  label: string;
5
8
  disabled?: boolean;
6
9
  group?: string;
@@ -1,17 +1,22 @@
1
- /** One entry of a side navigation; with `children`, it opens and closes to show them. */
2
- export type SideNavItem = {
3
- id: string;
1
+ /**
2
+ * One entry of a side navigation; with `children`, it opens and closes to show them. Typed by its ids
3
+ * (`SideNavItem<'jobs' | 'people'>`), `id` is one of them.
4
+ */
5
+ export type SideNavItem<Id extends string = string> = {
6
+ id: Id;
4
7
  label: string;
5
8
  /** An icon name; the collapsed rail shows only the icons. */
6
9
  icon?: string;
7
10
  /** A link to follow; without it the item is a button that fires `select`. */
8
11
  href?: string;
12
+ /** Where the link opens: `_blank` for a new tab (the API's documentation beside the app). */
13
+ target?: string;
9
14
  /** A count or a short word beside the label: `3`, `New`. */
10
15
  badge?: string | number;
11
- children?: SideNavItem[];
16
+ children?: SideNavItem<Id>[];
12
17
  };
13
18
  /** A group of items under an optional heading. */
14
- export type SideNavSection = {
19
+ export type SideNavSection<Id extends string = string> = {
15
20
  label?: string;
16
- items: SideNavItem[];
21
+ items: SideNavItem<Id>[];
17
22
  };
@@ -2,6 +2,8 @@
2
2
  export type StepItem = {
3
3
  label: string;
4
4
  description?: string;
5
+ /** The step ended in failure (a payment refused, a transaction rolled back): an × in the danger colour. */
6
+ failed?: boolean;
5
7
  };
6
8
  export type StepsOrientation = 'horizontal' | 'vertical';
7
9
  /** Where a step stands against the current one. */
@@ -1,6 +1,9 @@
1
- /** One place in a bottom tab bar: an icon over a short label. */
2
- export type TabBarItem = {
3
- id: string;
1
+ /**
2
+ * One place in a bottom tab bar: an icon over a short label. Typed by its ids (`TabBarItem<'home' | 'jobs'>`), `id`
3
+ * is one of them.
4
+ */
5
+ export type TabBarItem<Id extends string = string> = {
6
+ id: Id;
4
7
  label: string;
5
8
  /** An icon name: the tab bar draws one over every label. */
6
9
  icon: string;
@@ -1,12 +1,26 @@
1
1
  import type { Tone } from './options.types';
2
- /** How a cell shows its value: as it is, a localised number or date, a badge, or code. */
3
- export type TableCellFormat = 'text' | 'number' | 'date' | 'badge' | 'code';
2
+ /** How a cell shows its value: as it is, a localised number, date or date and time, a badge, or code. */
3
+ export type TableCellFormat = 'text' | 'number' | 'date' | 'datetime' | 'badge' | 'code';
4
4
  export type TableAlign = 'left' | 'center' | 'right';
5
5
  /** The order of a sorted column; `none` keeps the rows as they came. */
6
6
  export type TableSortDirection = 'asc' | 'desc' | 'none';
7
- export type TableColumn = {
8
- /** The row's field shown in this column. */
9
- key: string;
7
+ /** A row of a table that does not say its type: any field, of any value. */
8
+ export type TableRow = Record<string, unknown>;
9
+ /** The names of a type of row's fields: what a column shows, sorts by, or shows under its value. */
10
+ export type TableField<Row> = Extract<keyof Row, string>;
11
+ /**
12
+ * What a column's `key` names: a field of the row, or one of the `Extra` columns a renderer draws from the whole
13
+ * row, such as a column of actions. The extra columns are named, never guessed from the keys: a misspelt field is
14
+ * an error, not a new column.
15
+ */
16
+ export type TableColumnKey<Row, Extra extends string = never> = TableField<Row> | NoInfer<Extra>;
17
+ /**
18
+ * A column of a table. Typed by its rows (`TableColumn<Order>`), its `key` and `description` are fields of an
19
+ * order, checked and completed by the editor.
20
+ */
21
+ export type TableColumn<Row extends object = TableRow, Extra extends string = never> = {
22
+ /** The row's field shown in this column, or one of the `Extra` columns a renderer draws. */
23
+ key: TableColumnKey<Row, Extra>;
10
24
  label: string;
11
25
  /** Numbers are right-aligned when absent; the rest left. */
12
26
  align?: TableAlign;
@@ -16,15 +30,34 @@ export type TableColumn = {
16
30
  format?: TableCellFormat;
17
31
  /** For badges: the tone of each value (`{ "Active": "ok" }`); neutral otherwise. */
18
32
  tones?: Record<string, Tone>;
33
+ /** The row's field shown as a quieter line under the value: a package's format under its name. */
34
+ description?: TableField<Row>;
35
+ /**
36
+ * Long text, a description or a note, breaks over lines instead of widening the table; cells stay on one line
37
+ * otherwise.
38
+ */
39
+ wrap?: boolean;
19
40
  };
20
- export type TableRow = Record<string, unknown>;
21
41
  /** A row's identity, the value of its `row-key` field. */
22
42
  export type TableRowKey = string | number;
23
- export type TableSort = {
24
- key: string;
43
+ export type TableSort<Row extends object = TableRow, Extra extends string = never> = {
44
+ key: TableColumnKey<Row, Extra>;
25
45
  direction: TableSortDirection;
26
46
  };
27
47
  /** Draws a cell of a column in place of its formatted value. */
28
- export type TableCellRenderer = (row: TableRow) => Node;
48
+ export type TableCellRenderer<Row extends object = TableRow> = (row: Row) => Node;
49
+ /** The renderers of a table, by the key of the column whose cells they draw. */
50
+ export type TableRenderers<Row extends object = TableRow, Extra extends string = never> = {
51
+ [Key in TableColumnKey<Row, Extra>]?: TableCellRenderer<Row>;
52
+ };
29
53
  /** What the select-all box shows: no row selected, some, or all of them. */
30
54
  export type TableSelectionState = 'none' | 'some' | 'all';
55
+ /** Whether rows open to show more under them: never, one at a time, or any number at once. */
56
+ export type TableExpansion = 'none' | 'single' | 'multiple';
57
+ /** Draws what an open row shows under it. */
58
+ export type TableDetailRenderer<Row extends object = TableRow> = (row: Row) => Node;
59
+ /** A row opened or closed: its key, and whether it is open now. */
60
+ export type TableToggle = {
61
+ key: TableRowKey;
62
+ open: boolean;
63
+ };
@@ -16,8 +16,49 @@ export type ToastOptions = {
16
16
  actionLabel?: string;
17
17
  /** Called when that button is pressed; the toast then closes. */
18
18
  onAction?: () => void;
19
+ /** Shows a progress bar under the text, while the work it tells about runs. */
20
+ working?: boolean;
21
+ /** How far that work is, in percent; `null` for work of unknown length. */
22
+ progress?: number | null;
19
23
  };
20
- /** What `toast()` returns: a way to close the notification before its time. */
24
+ /** What `toast()` returns: a way to change the notification while it shows, and to close it before its time. */
21
25
  export type ToastHandle = {
26
+ /** Changes what the toast says (its text, tone, progress, action…): the options given replace those it had. */
27
+ update(changes: ToastOptions): void;
22
28
  dismiss(): void;
23
29
  };
30
+ /** The texts a download's toast shows: `{time}`, `{received}`, `{total}`, `{name}`, `{size}` and `{error}` are filled. */
31
+ export type DownloadTexts = {
32
+ /** While the server prepares the file: "Preparing the file… {time}". */
33
+ preparing: string;
34
+ /** Bytes received, of a size the server did not say: "{received} received". */
35
+ received: string;
36
+ /** Bytes received of the size the server said: "{received} of {total}". */
37
+ receivedOf: string;
38
+ /** Saved: "Saved as {name}, {size}". */
39
+ saved: string;
40
+ /** Failed: "Not downloaded: {error}". */
41
+ failed: string;
42
+ /** The action that stops it. */
43
+ cancel: string;
44
+ };
45
+ export type DownloadOptions = {
46
+ /** The toast's heading: what is downloaded ("METS of Letters 1902"); the file's name otherwise. */
47
+ title?: string;
48
+ /** The name to save under when the server gives none; the address's last segment otherwise. */
49
+ fileName?: string;
50
+ /** The request's options: headers, credentials… */
51
+ init?: RequestInit;
52
+ texts?: Partial<DownloadTexts>;
53
+ };
54
+ /** How a download ended: saved (under a name, its size in bytes), failed (why), or canceled. */
55
+ export type DownloadResult = {
56
+ outcome: 'saved';
57
+ name: string;
58
+ size: number;
59
+ } | {
60
+ outcome: 'failed';
61
+ error: string;
62
+ } | {
63
+ outcome: 'canceled';
64
+ };
@@ -5,7 +5,33 @@ export type TreeItem = {
5
5
  icon?: string;
6
6
  /** Present, even empty, the item is a folder that opens. */
7
7
  children?: TreeItem[];
8
+ /** A folder whose children the tree's `loader` brings, the first time it opens. */
9
+ lazy?: boolean;
10
+ /** An address: the row is a link, which a middle click opens in a new tab, and it fires no `select`. */
11
+ href?: string;
12
+ /** The row's tooltip, such as the whole name of an item whose label is short. */
13
+ hint?: string;
14
+ /** A count or a short word after the label: how many items a folder holds. */
15
+ badge?: string | number;
8
16
  };
17
+ /** One page of a level, as a loader answers it: some of its items, and how many the level has in all. */
18
+ export type TreePage = {
19
+ items: TreeItem[];
20
+ total: number;
21
+ };
22
+ /** Loads a page of a level, from `offset` on: the roots when `parent` is null. */
23
+ export type TreeLoader = (parent: string | null, offset: number) => Promise<TreePage>;
24
+ /** A level the tree loads: how many items it has in all, the page on its way, and the last load's error. */
25
+ export type TreeLevel = {
26
+ total: number;
27
+ pending: Promise<void> | null;
28
+ error: string;
29
+ };
30
+ /**
31
+ * The row that ends a level of the tree: its page on the way, the error of its last load, the button for its next
32
+ * page, the text of an empty tree, or none.
33
+ */
34
+ export type TreeLevelEnd = 'loading' | 'error' | 'more' | 'empty' | 'none';
9
35
  /** An item as listed: its depth from 1 at the roots, and its parent's id. */
10
36
  export type VisibleTreeItem = {
11
37
  item: TreeItem;
@@ -0,0 +1,5 @@
1
+ import type { DEFAULT_TEXTS } from '../lib/texts';
2
+ /** The name of one of the texts jlib's components show on their own. */
3
+ export type JlTextKey = keyof typeof DEFAULT_TEXTS;
4
+ /** The texts in the page's language: some or all of them, the rest staying in English. */
5
+ export type JlTexts = Partial<Record<JlTextKey, string>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syware/jlib",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "A tree-shakeable component library on Jadis and native Web Components, organised in atomic design",
5
5
  "keywords": [
6
6
  "web-components",
@@ -85,7 +85,7 @@
85
85
  "prepublishOnly": "npm run check"
86
86
  },
87
87
  "peerDependencies": {
88
- "@jadis/core": "^1.3.0"
88
+ "@jadis/core": "^1.4.0"
89
89
  },
90
90
  "dependencies": {
91
91
  "lucide": "^1.61.0"
@@ -94,7 +94,7 @@
94
94
  "@biomejs/biome": "^2.6.3",
95
95
  "@fontsource-variable/jetbrains-mono": "^5.3.0",
96
96
  "@fontsource-variable/manrope": "^5.3.0",
97
- "@jadis/core": "^1.3.0",
97
+ "@jadis/core": "^1.4.2",
98
98
  "@types/node": "^24.13.3",
99
99
  "playwright-core": "^1.64.1",
100
100
  "typescript": "^7.0.2",