@syware/jlib 0.16.1 → 0.17.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/lib/input-list.d.ts
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A row: its text, and the index it had in the `values` last set from outside — its origin. A row keeps its origin
|
|
3
|
+
* while it is typed in, emptied and filled again; a row added since has none.
|
|
4
|
+
*/
|
|
5
|
+
export type InputListRow = {
|
|
6
|
+
value: string;
|
|
7
|
+
origin: number | undefined;
|
|
8
|
+
};
|
|
9
|
+
/** An empty row with no origin, for a list that holds nothing. */
|
|
10
|
+
export declare const emptyRow: () => InputListRow;
|
|
11
|
+
/** The rows shown: the values, each with its index, or one empty row to type the first one in. */
|
|
12
|
+
export declare const rowsOf: (values: readonly string[]) => InputListRow[];
|
|
13
|
+
/** The rows with the one at `index` changed; it keeps its origin. */
|
|
14
|
+
export declare const withRowAt: (rows: readonly InputListRow[], index: number, value: string) => InputListRow[];
|
|
15
|
+
/** The rows without the one at `index`, the others keeping their origin; one empty row stays when it was the last. */
|
|
16
|
+
export declare const withoutRowAt: (rows: readonly InputListRow[], index: number) => InputListRow[];
|
|
17
|
+
/** The rows people filled in. */
|
|
18
|
+
export declare const filledRows: (rows: readonly InputListRow[]) => InputListRow[];
|
|
7
19
|
/** The values kept: the rows people filled in. */
|
|
8
|
-
export declare const filledValues: (rows: readonly
|
|
20
|
+
export declare const filledValues: (rows: readonly InputListRow[]) => string[];
|
|
21
|
+
/** The origin of each value kept, in the same order: what tells a value from the one it started as. */
|
|
22
|
+
export declare const filledOrigins: (rows: readonly InputListRow[]) => (number | undefined)[];
|
|
9
23
|
/** Whether another row fits under `max`; none or zero means no limit. */
|
|
10
24
|
export declare const canAddRow: (count: number, max: number) => boolean;
|
|
11
25
|
/** Whether two lists hold the same values in the same order. */
|
package/dist/lib/input-list.js
CHANGED
|
@@ -1,14 +1,32 @@
|
|
|
1
1
|
// src/lib/input-list.ts
|
|
2
|
-
/**
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
/** An empty row with no origin, for a list that holds nothing. */
|
|
3
|
+
var emptyRow = () => ({
|
|
4
|
+
origin: void 0,
|
|
5
|
+
value: ""
|
|
6
|
+
});
|
|
7
|
+
/** The rows shown: the values, each with its index, or one empty row to type the first one in. */
|
|
8
|
+
var rowsOf = (values) => values.length === 0 ? [emptyRow()] : values.map((value, origin) => ({
|
|
9
|
+
origin,
|
|
10
|
+
value
|
|
11
|
+
}));
|
|
12
|
+
/** The rows with the one at `index` changed; it keeps its origin. */
|
|
13
|
+
var withRowAt = (rows, index, value) => rows.map((row, at) => at === index ? {
|
|
14
|
+
...row,
|
|
15
|
+
value
|
|
16
|
+
} : row);
|
|
17
|
+
/** The rows without the one at `index`, the others keeping their origin; one empty row stays when it was the last. */
|
|
18
|
+
var withoutRowAt = (rows, index) => {
|
|
19
|
+
const kept = rows.filter((_, at) => at !== index);
|
|
20
|
+
return kept.length === 0 ? [emptyRow()] : kept;
|
|
21
|
+
};
|
|
22
|
+
/** The rows people filled in. */
|
|
23
|
+
var filledRows = (rows) => rows.filter((row) => row.value.trim() !== "");
|
|
8
24
|
/** The values kept: the rows people filled in. */
|
|
9
|
-
var filledValues = (rows) => rows.
|
|
25
|
+
var filledValues = (rows) => filledRows(rows).map((row) => row.value);
|
|
26
|
+
/** The origin of each value kept, in the same order: what tells a value from the one it started as. */
|
|
27
|
+
var filledOrigins = (rows) => filledRows(rows).map((row) => row.origin);
|
|
10
28
|
/** Whether another row fits under `max`; none or zero means no limit. */
|
|
11
29
|
var canAddRow = (count, max) => max <= 0 || count < max;
|
|
12
30
|
/** Whether two lists hold the same values in the same order. */
|
|
13
31
|
var sameValues = (left, right) => left.length === right.length && left.every((value, index) => value === right[index]);
|
|
14
|
-
export { canAddRow, filledValues, rowsOf, sameValues, withRowAt, withoutRowAt };
|
|
32
|
+
export { canAddRow, emptyRow, filledOrigins, filledRows, filledValues, rowsOf, sameValues, withRowAt, withoutRowAt };
|
|
@@ -64,6 +64,12 @@ export declare class JlInputList extends JlElement {
|
|
|
64
64
|
private readonly _refs;
|
|
65
65
|
templateHtml(): Node;
|
|
66
66
|
templateCss(): string;
|
|
67
|
+
/**
|
|
68
|
+
* The origin of each value of `values`: the index it had in the values last set from outside, and undefined for a
|
|
69
|
+
* row added since. A row keeps it while it is typed in, a removed row takes it away, so a corrected value is not
|
|
70
|
+
* taken for a removal beside an addition.
|
|
71
|
+
*/
|
|
72
|
+
origins(): (number | undefined)[];
|
|
67
73
|
onConnect(): void;
|
|
68
74
|
/** Values set from outside start the rows again; those the rows themselves gave change nothing. */
|
|
69
75
|
private follow;
|
|
@@ -73,7 +79,7 @@ export declare class JlInputList extends JlElement {
|
|
|
73
79
|
* runs as the list appears: a build in each made about ten per list.
|
|
74
80
|
*/
|
|
75
81
|
private drawRows;
|
|
76
|
-
/** Builds every row again, from the
|
|
82
|
+
/** Builds every row again, from the rows in `_state`. */
|
|
77
83
|
private renderRows;
|
|
78
84
|
/** The add button: its text, and hidden at `max`; the CSS hides it in a disabled list. */
|
|
79
85
|
private renderAdd;
|
|
@@ -7,7 +7,7 @@ import { JlButton } from "../atoms/jl-button.js";
|
|
|
7
7
|
import { INPUT_TYPES, JlInput } from "../atoms/jl-input.js";
|
|
8
8
|
import { JlSelect } from "../atoms/jl-select.js";
|
|
9
9
|
import { JlTextarea } from "../atoms/jl-textarea.js";
|
|
10
|
-
import { canAddRow, filledValues, rowsOf, sameValues, withRowAt, withoutRowAt } from "../lib/input-list.js";
|
|
10
|
+
import { canAddRow, emptyRow, filledOrigins, filledValues, rowsOf, sameValues, withRowAt, withoutRowAt } from "../lib/input-list.js";
|
|
11
11
|
import jl_input_list_default from "./jl-input-list.css.js";
|
|
12
12
|
import { css } from "@jadis/core";
|
|
13
13
|
import { Plus, X } from "lucide";
|
|
@@ -64,7 +64,7 @@ var JlInputList = class extends JlElement {
|
|
|
64
64
|
addLabel = this.useChange("", () => this.renderAdd(), { attribute: "add-label" });
|
|
65
65
|
/** The text a screen reader says for each row's remove button; jlib's own when empty. */
|
|
66
66
|
removeLabel = this.useChange("", () => this.drawRows(), { attribute: "remove-label" });
|
|
67
|
-
_state = { rows: [
|
|
67
|
+
_state = { rows: rowsOf([]) };
|
|
68
68
|
_drawn = {
|
|
69
69
|
kind: void 0,
|
|
70
70
|
rows: []
|
|
@@ -88,6 +88,14 @@ var JlInputList = class extends JlElement {
|
|
|
88
88
|
templateCss() {
|
|
89
89
|
return css`${BASE_STYLES}${jl_input_list_default}`;
|
|
90
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* The origin of each value of `values`: the index it had in the values last set from outside, and undefined for a
|
|
93
|
+
* row added since. A row keeps it while it is typed in, a removed row takes it away, so a corrected value is not
|
|
94
|
+
* taken for a removal beside an addition.
|
|
95
|
+
*/
|
|
96
|
+
origins() {
|
|
97
|
+
return filledOrigins(this._state.rows);
|
|
98
|
+
}
|
|
91
99
|
onConnect() {
|
|
92
100
|
this._refs.add.events.register("press", () => this.addRow());
|
|
93
101
|
}
|
|
@@ -112,10 +120,10 @@ var JlInputList = class extends JlElement {
|
|
|
112
120
|
for (const row of this._drawn.rows) this.drawRow(row);
|
|
113
121
|
this.renderAdd();
|
|
114
122
|
}
|
|
115
|
-
/** Builds every row again, from the
|
|
123
|
+
/** Builds every row again, from the rows in `_state`. */
|
|
116
124
|
renderRows() {
|
|
117
125
|
this._drawn.kind = this.rowKind();
|
|
118
|
-
this._drawn.rows = this._state.rows.map((
|
|
126
|
+
this._drawn.rows = this._state.rows.map((row, index) => this.row(row.value, index));
|
|
119
127
|
this._refs.rows.replaceChildren(...this._drawn.rows.map(({ control, remove }) => /* @__PURE__ */ jsxs("div", {
|
|
120
128
|
class: "row",
|
|
121
129
|
children: [control, remove]
|
|
@@ -197,7 +205,7 @@ var JlInputList = class extends JlElement {
|
|
|
197
205
|
}
|
|
198
206
|
addRow() {
|
|
199
207
|
if (!canAddRow(this._state.rows.length, this.max.get())) return;
|
|
200
|
-
this._state.rows = [...this._state.rows,
|
|
208
|
+
this._state.rows = [...this._state.rows, emptyRow()];
|
|
201
209
|
this.renderRows();
|
|
202
210
|
const added = this._refs.rows.lastElementChild?.firstElementChild;
|
|
203
211
|
if (added instanceof HTMLElement) added.focus();
|