@x-tech-laboratories/x-libs 0.13.0 → 0.14.1
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 +1 -1
- package/dist/web/react/menus.js +11 -7
- package/package.json +1 -1
- package/dist/agent/client.d.ts +0 -32
- package/dist/agent/client.js +0 -148
- package/dist/agent/commands.d.ts +0 -23
- package/dist/agent/commands.js +0 -118
- package/dist/agent/keys.d.ts +0 -14
- package/dist/agent/keys.js +0 -81
- package/dist/agent/long_runs.d.ts +0 -32
- package/dist/agent/long_runs.js +0 -316
- package/dist/agent/protocol.d.ts +0 -148
- package/dist/agent/protocol.js +0 -131
- package/dist/agent/session.d.ts +0 -50
- package/dist/agent/session.js +0 -225
- package/dist/agent/tasks.d.ts +0 -17
- package/dist/agent/tasks.js +0 -15
- package/dist/backups.d.ts +0 -31
- package/dist/backups.js +0 -43
- package/dist/dates.d.ts +0 -9
- package/dist/dates.js +0 -60
- package/dist/durations.d.ts +0 -11
- package/dist/durations.js +0 -49
- package/dist/electron/app.d.ts +0 -13
- package/dist/electron/app.js +0 -27
- package/dist/electron/bridge.d.ts +0 -55
- package/dist/electron/bridge.js +0 -105
- package/dist/electron/events.d.ts +0 -21
- package/dist/electron/events.js +0 -25
- package/dist/electron/fetch.d.ts +0 -52
- package/dist/electron/fetch.js +0 -175
- package/dist/electron/window.d.ts +0 -96
- package/dist/electron/window.js +0 -128
- package/dist/log.d.ts +0 -30
- package/dist/log.js +0 -79
- package/dist/server/agents/agent.d.ts +0 -27
- package/dist/server/agents/agent.js +0 -16
- package/dist/server/agents/connection.d.ts +0 -51
- package/dist/server/agents/connection.js +0 -239
- package/dist/server/agents/hub.d.ts +0 -86
- package/dist/server/agents/hub.js +0 -241
- package/dist/server/agents/local.d.ts +0 -24
- package/dist/server/agents/local.js +0 -62
- package/dist/server/agents/route.d.ts +0 -3
- package/dist/server/agents/route.js +0 -24
- package/dist/server/backup_files.d.ts +0 -3
- package/dist/server/backup_files.js +0 -25
- package/dist/server/config.d.ts +0 -39
- package/dist/server/config.js +0 -109
- package/dist/server/cors.d.ts +0 -8
- package/dist/server/cors.js +0 -13
- package/dist/server/events.d.ts +0 -33
- package/dist/server/events.js +0 -68
- package/dist/server/hash_password.d.ts +0 -1
- package/dist/server/hash_password.js +0 -46
- package/dist/server/login_page.d.ts +0 -8
- package/dist/server/login_page.js +0 -79
- package/dist/server/passwords.d.ts +0 -8
- package/dist/server/passwords.js +0 -59
- package/dist/server/replies.d.ts +0 -12
- package/dist/server/replies.js +0 -41
- package/dist/server/sign_in.d.ts +0 -27
- package/dist/server/sign_in.js +0 -95
- package/dist/server/web_folder.d.ts +0 -11
- package/dist/server/web_folder.js +0 -40
- package/dist/web/dom.d.ts +0 -7
- package/dist/web/dom.js +0 -32
- package/dist/web/drag.d.ts +0 -3
- package/dist/web/drag.js +0 -13
- package/dist/web/errors.d.ts +0 -1
- package/dist/web/errors.js +0 -27
- package/dist/web/format.d.ts +0 -11
- package/dist/web/format.js +0 -82
- package/dist/web/menus.d.ts +0 -17
- package/dist/web/menus.js +0 -40
- package/dist/web/prefs.d.ts +0 -12
- package/dist/web/prefs.js +0 -62
- package/dist/web/react/badges.d.ts +0 -35
- package/dist/web/react/badges.js +0 -32
- package/dist/web/react/controls.d.ts +0 -86
- package/dist/web/react/controls.js +0 -154
- package/dist/web/react/dialog.d.ts +0 -45
- package/dist/web/react/dialog.js +0 -82
- package/dist/web/react/following.d.ts +0 -25
- package/dist/web/react/following.js +0 -34
- package/dist/web/react/layout.d.ts +0 -111
- package/dist/web/react/layout.js +0 -85
- package/dist/web/react/list_picker.d.ts +0 -19
- package/dist/web/react/list_picker.js +0 -50
- package/dist/web/react/markdown.d.ts +0 -8
- package/dist/web/react/markdown.js +0 -40
- package/dist/web/react/media.d.ts +0 -24
- package/dist/web/react/media.js +0 -18
- package/dist/web/react/menu_button.d.ts +0 -10
- package/dist/web/react/menu_button.js +0 -16
- package/dist/web/react/menus.d.ts +0 -31
- package/dist/web/react/page_view.d.ts +0 -16
- package/dist/web/react/page_view.js +0 -6
- package/dist/web/react/prefs.d.ts +0 -2
- package/dist/web/react/prefs.js +0 -11
- package/dist/web/react/progress.d.ts +0 -10
- package/dist/web/react/progress.js +0 -9
- package/dist/web/react/rating.d.ts +0 -8
- package/dist/web/react/rating.js +0 -23
- package/dist/web/react/reveal.d.ts +0 -10
- package/dist/web/react/reveal.js +0 -30
- package/dist/web/react/shell.d.ts +0 -45
- package/dist/web/react/shell.js +0 -94
- package/dist/web/react/shortcuts.d.ts +0 -23
- package/dist/web/react/shortcuts.js +0 -95
- package/dist/web/react/split.d.ts +0 -23
- package/dist/web/react/split.js +0 -94
- package/dist/web/react/states.d.ts +0 -36
- package/dist/web/react/states.js +0 -64
- package/dist/web/react/store.d.ts +0 -4
- package/dist/web/react/store.js +0 -7
- package/dist/web/react/suggestions.d.ts +0 -23
- package/dist/web/react/suggestions.js +0 -57
- package/dist/web/react/table.d.ts +0 -77
- package/dist/web/react/table.js +0 -398
- package/dist/web/react/test_stubs.d.ts +0 -1
- package/dist/web/react/test_stubs.js +0 -25
- package/dist/web/react/time.d.ts +0 -5
- package/dist/web/react/time.js +0 -19
- package/dist/web/react/toasts.d.ts +0 -29
- package/dist/web/react/toasts.js +0 -72
- package/dist/web/react/tree.d.ts +0 -28
- package/dist/web/react/tree.js +0 -183
- package/dist/web/react/volume.d.ts +0 -8
- package/dist/web/react/volume.js +0 -42
- package/dist/web/react/watch.d.ts +0 -3
- package/dist/web/react/watch.js +0 -5
- package/dist/web/router.d.ts +0 -7
- package/dist/web/router.js +0 -29
- package/dist/web/selection.d.ts +0 -25
- package/dist/web/selection.js +0 -106
- package/dist/web/split.d.ts +0 -15
- package/dist/web/split.js +0 -104
- package/dist/web/states.d.ts +0 -3
- package/dist/web/states.js +0 -10
- package/dist/web/store.d.ts +0 -11
- package/dist/web/store.js +0 -17
- package/dist/web/tables.d.ts +0 -28
- package/dist/web/tables.js +0 -88
- package/dist/web/theme.d.ts +0 -14
- package/dist/web/theme.js +0 -52
- package/dist/web/tree.d.ts +0 -40
- package/dist/web/tree.js +0 -130
- package/dist/web/virtual.d.ts +0 -7
- package/dist/web/virtual.js +0 -10
- package/dist/web/watch.d.ts +0 -11
- package/dist/web/watch.js +0 -37
package/dist/web/states.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// What a request throws when the session has lapsed, so a page can tell it from any other failure and ask for a login.
|
|
2
|
-
export class LoginNeeded extends Error {
|
|
3
|
-
}
|
|
4
|
-
// Hands a LoginNeeded on as an unhandled rejection, which the page's login listens for.
|
|
5
|
-
export function pass_login_needed(error) {
|
|
6
|
-
if (!(error instanceof LoginNeeded))
|
|
7
|
-
return false;
|
|
8
|
-
void Promise.reject(error);
|
|
9
|
-
return true;
|
|
10
|
-
}
|
package/dist/web/store.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type Watch } from "./watch.ts";
|
|
2
|
-
export interface Store<Value> {
|
|
3
|
-
get(): Value;
|
|
4
|
-
set(next: Value): void;
|
|
5
|
-
update(make: (current: Value) => Value): void;
|
|
6
|
-
watch: Watch;
|
|
7
|
-
}
|
|
8
|
-
export interface StoreOptions {
|
|
9
|
-
coalesce_in_milliseconds?: number;
|
|
10
|
-
}
|
|
11
|
-
export declare function create_store<Value>(initial: Value, options?: StoreOptions): Store<Value>;
|
package/dist/web/store.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// A value a page reads and events change, with a watch that redraws only what reads it.
|
|
2
|
-
import { coalesce_bumps, create_watch } from "./watch.js";
|
|
3
|
-
export function create_store(initial, options = {}) {
|
|
4
|
-
let value = initial;
|
|
5
|
-
const watch = create_watch();
|
|
6
|
-
const bump = options.coalesce_in_milliseconds ? coalesce_bumps(watch, options.coalesce_in_milliseconds) : watch.bump;
|
|
7
|
-
const set = (next) => {
|
|
8
|
-
value = next;
|
|
9
|
-
bump();
|
|
10
|
-
};
|
|
11
|
-
return {
|
|
12
|
-
get: () => value,
|
|
13
|
-
set,
|
|
14
|
-
update: (make) => set(make(value)),
|
|
15
|
-
watch,
|
|
16
|
-
};
|
|
17
|
-
}
|
package/dist/web/tables.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export interface Sorting {
|
|
2
|
-
key: string;
|
|
3
|
-
descending: boolean;
|
|
4
|
-
}
|
|
5
|
-
export interface SortableColumn<Row> {
|
|
6
|
-
label: string;
|
|
7
|
-
id?: string;
|
|
8
|
-
sort?: (row: Row) => string | number | null;
|
|
9
|
-
}
|
|
10
|
-
export type SortValue = string | number | null | undefined;
|
|
11
|
-
export declare function column_id(column: {
|
|
12
|
-
id?: string;
|
|
13
|
-
label: string;
|
|
14
|
-
}): string;
|
|
15
|
-
export declare function sorting_list(sorting: Sorting | readonly Sorting[] | undefined): Sorting[];
|
|
16
|
-
export declare function compare_values(first: SortValue, second: SortValue, descending?: boolean): number;
|
|
17
|
-
export declare function sorted_rows<Row>(columns: SortableColumn<Row>[], rows: Row[], sorting: Sorting | readonly Sorting[] | undefined): Row[];
|
|
18
|
-
export interface TreeRow<Row> {
|
|
19
|
-
row: Row;
|
|
20
|
-
children: TreeRow<Row>[];
|
|
21
|
-
}
|
|
22
|
-
export declare function sorted_tree<Row>(columns: SortableColumn<Row>[], rows: Row[], sorting: Sorting | readonly Sorting[] | undefined, get_children: (row: Row) => Row[] | undefined): TreeRow<Row>[];
|
|
23
|
-
export declare function sort_after_click(sorting: readonly Sorting[], key: string, adding: boolean): Sorting[];
|
|
24
|
-
export declare function sorting_from(query: URLSearchParams, fallback: Sorting): Sorting;
|
|
25
|
-
export declare function ordered_columns(saved_order: readonly string[], all_columns: readonly string[]): string[];
|
|
26
|
-
export declare function move_column(order: readonly string[], column: string, target: string, after: boolean): string[];
|
|
27
|
-
export declare function moved<Item>(items: readonly Item[], from: number, to: number): Item[];
|
|
28
|
-
export declare function clamp_width(width: number, min?: number, max?: number): number;
|
package/dist/web/tables.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
// The order a sorted table shows its rows in, the sorting a click or a view's query asks for, and the order of its columns.
|
|
2
|
-
export function column_id(column) {
|
|
3
|
-
return column.id ?? column.label;
|
|
4
|
-
}
|
|
5
|
-
// One sorting or several as a list, the first deciding first.
|
|
6
|
-
export function sorting_list(sorting) {
|
|
7
|
-
if (!sorting)
|
|
8
|
-
return [];
|
|
9
|
-
return Array.isArray(sorting) ? [...sorting] : [sorting];
|
|
10
|
-
}
|
|
11
|
-
const is_empty = (value) => value === null || value === undefined || value === "";
|
|
12
|
-
// Numbers by size and text by its words and numbers, with an empty value last whichever way the column sorts.
|
|
13
|
-
export function compare_values(first, second, descending = false) {
|
|
14
|
-
if (is_empty(first) || is_empty(second))
|
|
15
|
-
return Number(is_empty(first)) - Number(is_empty(second));
|
|
16
|
-
const order = typeof first === "number" && typeof second === "number"
|
|
17
|
-
? first - second
|
|
18
|
-
: String(first).localeCompare(String(second), undefined, { numeric: true, sensitivity: "base" });
|
|
19
|
-
return descending ? -order : order;
|
|
20
|
-
}
|
|
21
|
-
// The rows in the order the sortings ask for, the later ones breaking ties, and rows missing a value last.
|
|
22
|
-
export function sorted_rows(columns, rows, sorting) {
|
|
23
|
-
const keys = sorting_list(sorting).flatMap((key) => {
|
|
24
|
-
const column = columns.find((candidate) => column_id(candidate) === key.key && candidate.sort);
|
|
25
|
-
return column?.sort ? [{ value: column.sort, descending: key.descending }] : [];
|
|
26
|
-
});
|
|
27
|
-
if (keys.length === 0)
|
|
28
|
-
return rows;
|
|
29
|
-
return [...rows].sort((left, right) => {
|
|
30
|
-
for (const key of keys) {
|
|
31
|
-
const order = compare_values(key.value(left), key.value(right), key.descending);
|
|
32
|
-
if (order !== 0)
|
|
33
|
-
return order;
|
|
34
|
-
}
|
|
35
|
-
return 0;
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
// Sorts each level of a tree on its own, so children stay under their parents.
|
|
39
|
-
export function sorted_tree(columns, rows, sorting, get_children) {
|
|
40
|
-
return sorted_rows(columns, rows, sorting).map((row) => ({ row, children: sorted_tree(columns, get_children(row) ?? [], sorting, get_children) }));
|
|
41
|
-
}
|
|
42
|
-
// A plain click sorts by that column alone; a Shift+click adds it to the sort or flips it; a third click takes it out.
|
|
43
|
-
export function sort_after_click(sorting, key, adding) {
|
|
44
|
-
const current = sorting.find((each) => each.key === key);
|
|
45
|
-
const next = !current ? { key, descending: false } : current.descending ? null : { key, descending: true };
|
|
46
|
-
if (!adding) {
|
|
47
|
-
if (current && sorting.length === 1)
|
|
48
|
-
return next ? [next] : [];
|
|
49
|
-
return [{ key, descending: false }];
|
|
50
|
-
}
|
|
51
|
-
if (!current)
|
|
52
|
-
return [...sorting, next];
|
|
53
|
-
return next ? sorting.map((each) => (each.key === key ? next : each)) : sorting.filter((each) => each.key !== key);
|
|
54
|
-
}
|
|
55
|
-
// The sorting a view's query asks for, such as ?sort=Name&dir=desc.
|
|
56
|
-
export function sorting_from(query, fallback) {
|
|
57
|
-
const key = query.get("sort");
|
|
58
|
-
return key ? { key, descending: query.get("dir") === "desc" } : fallback;
|
|
59
|
-
}
|
|
60
|
-
// ── Columns ──────────────────────────────────────────────────────────────────
|
|
61
|
-
// Every column in its saved order, leaving out ones gone since and placing a new one just after the column before it.
|
|
62
|
-
export function ordered_columns(saved_order, all_columns) {
|
|
63
|
-
const ordered = saved_order.filter((column, index) => all_columns.includes(column) && saved_order.indexOf(column) === index);
|
|
64
|
-
all_columns.forEach((column, index) => {
|
|
65
|
-
if (ordered.includes(column))
|
|
66
|
-
return;
|
|
67
|
-
ordered.splice(index === 0 ? 0 : ordered.indexOf(all_columns[index - 1]) + 1, 0, column);
|
|
68
|
-
});
|
|
69
|
-
return ordered;
|
|
70
|
-
}
|
|
71
|
-
// Moves a column to just before or after another one.
|
|
72
|
-
export function move_column(order, column, target, after) {
|
|
73
|
-
const rest = order.filter((each) => each !== column);
|
|
74
|
-
const index = rest.indexOf(target) + (after ? 1 : 0);
|
|
75
|
-
return [...rest.slice(0, index), column, ...rest.slice(index)];
|
|
76
|
-
}
|
|
77
|
-
// Moves the item at from to to, such as for a list's up and down buttons.
|
|
78
|
-
export function moved(items, from, to) {
|
|
79
|
-
if (from < 0 || from >= items.length)
|
|
80
|
-
return [...items];
|
|
81
|
-
const rest = items.filter((_, index) => index !== from);
|
|
82
|
-
rest.splice(Math.max(0, Math.min(to, rest.length)), 0, items[from]);
|
|
83
|
-
return rest;
|
|
84
|
-
}
|
|
85
|
-
// A width held between the column's narrowest and widest.
|
|
86
|
-
export function clamp_width(width, min = 48, max = 960) {
|
|
87
|
-
return Math.round(Math.min(max, Math.max(min, width)));
|
|
88
|
-
}
|
package/dist/web/theme.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export type Theme = "system" | "light" | "dark";
|
|
2
|
-
export interface ThemeChoice {
|
|
3
|
-
get(): Theme;
|
|
4
|
-
set(theme: Theme): void;
|
|
5
|
-
on_change(listener: (theme: Theme) => void): () => void;
|
|
6
|
-
apply(theme?: Theme): void;
|
|
7
|
-
}
|
|
8
|
-
export interface ThemeStorage {
|
|
9
|
-
read(): Theme | undefined;
|
|
10
|
-
write(theme: Theme): void;
|
|
11
|
-
}
|
|
12
|
-
export declare function local_theme_storage(storage_key: string): ThemeStorage;
|
|
13
|
-
export declare function theme_choice(where: string | ThemeStorage): ThemeChoice;
|
|
14
|
-
export declare function next_theme(theme: Theme): Theme;
|
package/dist/web/theme.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
// The light, dark or system theme, kept in this browser or the app's own settings, and set as data-theme on the page.
|
|
2
|
-
// The choice kept in this browser under the storage key, such as "x-nix-theme".
|
|
3
|
-
export function local_theme_storage(storage_key) {
|
|
4
|
-
return {
|
|
5
|
-
read: () => {
|
|
6
|
-
try {
|
|
7
|
-
const saved = localStorage.getItem(storage_key);
|
|
8
|
-
return saved === "light" || saved === "dark" ? saved : undefined;
|
|
9
|
-
}
|
|
10
|
-
catch {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
write: (theme) => {
|
|
15
|
-
try {
|
|
16
|
-
if (theme === "system")
|
|
17
|
-
localStorage.removeItem(storage_key);
|
|
18
|
-
else
|
|
19
|
-
localStorage.setItem(storage_key, theme);
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
// Without storage the choice lasts until the page is closed.
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
// The choice kept under a storage key in this browser, or in the storage the app hands over.
|
|
28
|
-
export function theme_choice(where) {
|
|
29
|
-
const storage = typeof where === "string" ? local_theme_storage(where) : where;
|
|
30
|
-
const listeners = new Set();
|
|
31
|
-
const get = () => storage.read() ?? "system";
|
|
32
|
-
const apply = (theme = get()) => {
|
|
33
|
-
if (theme === "system")
|
|
34
|
-
delete document.documentElement.dataset.theme;
|
|
35
|
-
else
|
|
36
|
-
document.documentElement.dataset.theme = theme;
|
|
37
|
-
for (const listener of listeners)
|
|
38
|
-
listener(theme);
|
|
39
|
-
};
|
|
40
|
-
const set = (theme) => {
|
|
41
|
-
storage.write(theme);
|
|
42
|
-
apply(theme);
|
|
43
|
-
};
|
|
44
|
-
return { get, set, apply, on_change: (listener) => {
|
|
45
|
-
listeners.add(listener);
|
|
46
|
-
return () => void listeners.delete(listener);
|
|
47
|
-
} };
|
|
48
|
-
}
|
|
49
|
-
// The header's button steps through system, light and dark.
|
|
50
|
-
export function next_theme(theme) {
|
|
51
|
-
return theme === "system" ? "light" : theme === "light" ? "dark" : "system";
|
|
52
|
-
}
|
package/dist/web/tree.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export interface TreeItem {
|
|
2
|
-
id: string;
|
|
3
|
-
parent_id: string | null;
|
|
4
|
-
position: number;
|
|
5
|
-
}
|
|
6
|
-
export interface TreeNode<Item> {
|
|
7
|
-
item: Item;
|
|
8
|
-
children: TreeNode<Item>[];
|
|
9
|
-
}
|
|
10
|
-
export type SidePlacement = "before" | "after";
|
|
11
|
-
export type DropPlacement = SidePlacement | "inside";
|
|
12
|
-
export interface TreeMove {
|
|
13
|
-
parent_id: string | null;
|
|
14
|
-
position: number;
|
|
15
|
-
}
|
|
16
|
-
export interface DropOptions {
|
|
17
|
-
by_list_order?: boolean;
|
|
18
|
-
}
|
|
19
|
-
export declare function by_position<Item extends {
|
|
20
|
-
position: number;
|
|
21
|
-
}>(first: Item, second: Item): number;
|
|
22
|
-
export declare function children_of<Item extends TreeItem>(parent_id: string | null, items: Item[]): Item[];
|
|
23
|
-
export declare function subtree_ids(item_id: string, items: TreeItem[]): Set<string>;
|
|
24
|
-
export declare function nest<Item extends TreeItem>(shown: Item[], all?: Item[]): TreeNode<Item>[];
|
|
25
|
-
export declare function in_tree_order<Item extends TreeItem>(items: Item[], reversed?: boolean): Item[];
|
|
26
|
-
export declare function path_names<Item extends TreeItem>(item: Item, items: Item[], name_of: (item: Item) => string): string[];
|
|
27
|
-
export declare function placement_at(fraction_down: number, allow_inside: boolean): DropPlacement;
|
|
28
|
-
export declare function can_drop(dragged_id: string, target_id: string, items: TreeItem[]): boolean;
|
|
29
|
-
export declare function position_for_drop<Item extends {
|
|
30
|
-
id: string;
|
|
31
|
-
position: number;
|
|
32
|
-
}>(dragged: Item, target: Item, placement: SidePlacement, items: Item[], options?: DropOptions): number;
|
|
33
|
-
export declare function move_for_drop<Item extends TreeItem>(dragged: Item, target: Item, placement: DropPlacement, items: Item[], options?: DropOptions): TreeMove;
|
|
34
|
-
export declare function moves_for_drop<Item extends TreeItem>(dragged: Item[], target: Item, placement: DropPlacement, items: Item[], options?: DropOptions): TreeMove[];
|
|
35
|
-
export type KeyMove = "up" | "down" | "indent" | "outdent";
|
|
36
|
-
export declare function key_drop<Item extends TreeItem>(item: Item, direction: KeyMove, items: Item[]): {
|
|
37
|
-
target: Item;
|
|
38
|
-
placement: DropPlacement;
|
|
39
|
-
} | null;
|
|
40
|
-
export declare function move_for_key<Item extends TreeItem>(item: Item, direction: KeyMove, items: Item[]): TreeMove | null;
|
package/dist/web/tree.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
// Trees of rows that name their parent and their place among siblings, and where a dragged or keyed row lands.
|
|
2
|
-
// ── Shape ────────────────────────────────────────────────────────────────────
|
|
3
|
-
export function by_position(first, second) {
|
|
4
|
-
return first.position - second.position;
|
|
5
|
-
}
|
|
6
|
-
export function children_of(parent_id, items) {
|
|
7
|
-
return items.filter((item) => item.parent_id === parent_id);
|
|
8
|
-
}
|
|
9
|
-
// The item itself plus everything below it, at any depth.
|
|
10
|
-
export function subtree_ids(item_id, items) {
|
|
11
|
-
const ids = new Set([item_id]);
|
|
12
|
-
for (const id of ids) {
|
|
13
|
-
for (const child of children_of(id, items))
|
|
14
|
-
ids.add(child.id);
|
|
15
|
-
}
|
|
16
|
-
return ids;
|
|
17
|
-
}
|
|
18
|
-
// Each shown item sits under its nearest ancestor that is also shown, or at the top when none is, in the order given.
|
|
19
|
-
export function nest(shown, all = shown) {
|
|
20
|
-
const item_by_id = new Map(all.map((item) => [item.id, item]));
|
|
21
|
-
const node_by_id = new Map(shown.map((item) => [item.id, { item, children: [] }]));
|
|
22
|
-
const top_nodes = [];
|
|
23
|
-
for (const node of node_by_id.values()) {
|
|
24
|
-
const seen = new Set([node.item.id]);
|
|
25
|
-
let ancestor_id = node.item.parent_id;
|
|
26
|
-
while (ancestor_id && !node_by_id.has(ancestor_id) && !seen.has(ancestor_id)) {
|
|
27
|
-
seen.add(ancestor_id);
|
|
28
|
-
ancestor_id = item_by_id.get(ancestor_id)?.parent_id ?? null;
|
|
29
|
-
}
|
|
30
|
-
if (ancestor_id && node_by_id.has(ancestor_id) && !seen.has(ancestor_id))
|
|
31
|
-
node_by_id.get(ancestor_id).children.push(node);
|
|
32
|
-
else
|
|
33
|
-
top_nodes.push(node);
|
|
34
|
-
}
|
|
35
|
-
return top_nodes;
|
|
36
|
-
}
|
|
37
|
-
// Every item in tree order: each followed by the items below it, siblings by position, each set of siblings reversed when asked.
|
|
38
|
-
export function in_tree_order(items, reversed = false) {
|
|
39
|
-
const sorted = [...items].sort(by_position);
|
|
40
|
-
if (reversed)
|
|
41
|
-
sorted.reverse();
|
|
42
|
-
const walk = (nodes) => nodes.flatMap((node) => [node.item, ...walk(node.children)]);
|
|
43
|
-
const ordered = walk(nest(sorted, items));
|
|
44
|
-
const reached = new Set(ordered);
|
|
45
|
-
return [...ordered, ...sorted.filter((item) => !reached.has(item))];
|
|
46
|
-
}
|
|
47
|
-
// The names from the top of the tree down to the item, such as ["Work", "Clients"]; stops at a missing parent or a loop.
|
|
48
|
-
export function path_names(item, items, name_of) {
|
|
49
|
-
const item_by_id = new Map(items.map((each) => [each.id, each]));
|
|
50
|
-
const path = [item];
|
|
51
|
-
let parent = item.parent_id === null ? undefined : item_by_id.get(item.parent_id);
|
|
52
|
-
while (parent && !path.includes(parent)) {
|
|
53
|
-
path.unshift(parent);
|
|
54
|
-
parent = parent.parent_id === null ? undefined : item_by_id.get(parent.parent_id);
|
|
55
|
-
}
|
|
56
|
-
return path.map(name_of);
|
|
57
|
-
}
|
|
58
|
-
// ── Dropping ─────────────────────────────────────────────────────────────────
|
|
59
|
-
// The top and bottom quarters of a row drop beside it and the middle drops into it, or halves when nothing drops inside.
|
|
60
|
-
export function placement_at(fraction_down, allow_inside) {
|
|
61
|
-
if (!allow_inside)
|
|
62
|
-
return fraction_down < 0.5 ? "before" : "after";
|
|
63
|
-
if (fraction_down < 0.25)
|
|
64
|
-
return "before";
|
|
65
|
-
if (fraction_down > 0.75)
|
|
66
|
-
return "after";
|
|
67
|
-
return "inside";
|
|
68
|
-
}
|
|
69
|
-
// A row cannot drop onto itself or anything below it.
|
|
70
|
-
export function can_drop(dragged_id, target_id, items) {
|
|
71
|
-
return !subtree_ids(dragged_id, items).has(target_id);
|
|
72
|
-
}
|
|
73
|
-
// Picks a position between the neighbours at the drop point, so only the moved item changes.
|
|
74
|
-
function position_beside(siblings, target, placement, options = {}) {
|
|
75
|
-
const sorted = options.by_list_order ? siblings : [...siblings].sort(by_position);
|
|
76
|
-
const index = sorted.findIndex((sibling) => sibling.id === target.id);
|
|
77
|
-
const neighbour = sorted[placement === "before" ? index - 1 : index + 1];
|
|
78
|
-
if (!neighbour)
|
|
79
|
-
return placement === "before" ? target.position - 1 : target.position + 1;
|
|
80
|
-
return (target.position + neighbour.position) / 2;
|
|
81
|
-
}
|
|
82
|
-
// For a flat list, where items only move before or after each other.
|
|
83
|
-
export function position_for_drop(dragged, target, placement, items, options = {}) {
|
|
84
|
-
return position_beside(items.filter((item) => item.id !== dragged.id), target, placement, options);
|
|
85
|
-
}
|
|
86
|
-
// Inside drops after the target's last child; before and after drop among the target's siblings.
|
|
87
|
-
export function move_for_drop(dragged, target, placement, items, options = {}) {
|
|
88
|
-
const others = items.filter((item) => item.id !== dragged.id);
|
|
89
|
-
if (placement === "inside") {
|
|
90
|
-
const last_child_position = Math.max(target.position, ...children_of(target.id, others).map((item) => item.position));
|
|
91
|
-
return { parent_id: target.id, position: last_child_position + 1 };
|
|
92
|
-
}
|
|
93
|
-
return { parent_id: target.parent_id, position: position_beside(children_of(target.parent_id, others), target, placement, options) };
|
|
94
|
-
}
|
|
95
|
-
// Moves several items together, keeping their order: inside the target after its last child, or in a run between it and its neighbour.
|
|
96
|
-
export function moves_for_drop(dragged, target, placement, items, options = {}) {
|
|
97
|
-
const dragged_ids = new Set(dragged.map((item) => item.id));
|
|
98
|
-
const others = items.filter((item) => !dragged_ids.has(item.id));
|
|
99
|
-
if (placement === "inside") {
|
|
100
|
-
const last_child_position = Math.max(target.position, ...children_of(target.id, others).map((item) => item.position));
|
|
101
|
-
return dragged.map((_, index) => ({ parent_id: target.id, position: last_child_position + index + 1 }));
|
|
102
|
-
}
|
|
103
|
-
const siblings = children_of(target.parent_id, others);
|
|
104
|
-
if (!options.by_list_order)
|
|
105
|
-
siblings.sort(by_position);
|
|
106
|
-
const index = siblings.findIndex((sibling) => sibling.id === target.id);
|
|
107
|
-
const neighbour = siblings[placement === "before" ? index - 1 : index + 1];
|
|
108
|
-
const low = placement === "before" ? (neighbour?.position ?? target.position - 1) : target.position;
|
|
109
|
-
const high = placement === "before" ? target.position : (neighbour?.position ?? target.position + 1);
|
|
110
|
-
return dragged.map((_, index) => ({ parent_id: target.parent_id, position: low + ((high - low) * (index + 1)) / (dragged.length + 1) }));
|
|
111
|
-
}
|
|
112
|
-
// Up and down pass the sibling beside it, indent goes last inside the sibling above, outdent goes after its parent; null when it cannot go that way.
|
|
113
|
-
export function key_drop(item, direction, items) {
|
|
114
|
-
const siblings = children_of(item.parent_id, items).sort(by_position);
|
|
115
|
-
const index = siblings.findIndex((sibling) => sibling.id === item.id);
|
|
116
|
-
const above = siblings[index - 1];
|
|
117
|
-
const below = siblings[index + 1];
|
|
118
|
-
const parent = items.find((each) => each.id === item.parent_id);
|
|
119
|
-
if (direction === "up")
|
|
120
|
-
return above ? { target: above, placement: "before" } : null;
|
|
121
|
-
if (direction === "down")
|
|
122
|
-
return below ? { target: below, placement: "after" } : null;
|
|
123
|
-
if (direction === "indent")
|
|
124
|
-
return above ? { target: above, placement: "inside" } : null;
|
|
125
|
-
return parent ? { target: parent, placement: "after" } : null;
|
|
126
|
-
}
|
|
127
|
-
export function move_for_key(item, direction, items) {
|
|
128
|
-
const drop = key_drop(item, direction, items);
|
|
129
|
-
return drop && move_for_drop(item, drop.target, drop.placement, items);
|
|
130
|
-
}
|
package/dist/web/virtual.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export interface VirtualWindow {
|
|
2
|
-
start: number;
|
|
3
|
-
end: number;
|
|
4
|
-
offset_px: number;
|
|
5
|
-
total_px: number;
|
|
6
|
-
}
|
|
7
|
-
export declare function virtual_window(total_rows: number, row_height: number, scroll_top: number, viewport_height: number, overscan?: number): VirtualWindow;
|
package/dist/web/virtual.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// Which rows of a long list a scrolled viewport needs, so only those are drawn.
|
|
2
|
-
export function virtual_window(total_rows, row_height, scroll_top, viewport_height, overscan = 8) {
|
|
3
|
-
if (row_height <= 0)
|
|
4
|
-
throw new Error("row_height must be positive");
|
|
5
|
-
const first_visible = Math.floor(Math.max(0, scroll_top) / row_height);
|
|
6
|
-
const visible_count = Math.ceil(viewport_height / row_height);
|
|
7
|
-
const start = Math.max(0, first_visible - overscan);
|
|
8
|
-
const end = Math.min(total_rows, first_visible + visible_count + overscan);
|
|
9
|
-
return { start, end, offset_px: start * row_height, total_px: total_rows * row_height };
|
|
10
|
-
}
|
package/dist/web/watch.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export interface Watch {
|
|
2
|
-
version(): number;
|
|
3
|
-
bump(): void;
|
|
4
|
-
subscribe(listener: () => void): () => void;
|
|
5
|
-
}
|
|
6
|
-
export declare function create_watch(): Watch;
|
|
7
|
-
export interface CoalescedBump {
|
|
8
|
-
(): void;
|
|
9
|
-
cancel(): void;
|
|
10
|
-
}
|
|
11
|
-
export declare function coalesce_bumps(watch: Watch, interval_in_milliseconds: number, now?: () => number): CoalescedBump;
|
package/dist/web/watch.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
// A change counter a store bumps and a page watches, so only what reads the store redraws when it changes.
|
|
2
|
-
export function create_watch() {
|
|
3
|
-
let version = 0;
|
|
4
|
-
const listeners = new Set();
|
|
5
|
-
return {
|
|
6
|
-
version: () => version,
|
|
7
|
-
bump: () => {
|
|
8
|
-
version += 1;
|
|
9
|
-
for (const listener of listeners)
|
|
10
|
-
listener();
|
|
11
|
-
},
|
|
12
|
-
subscribe: (listener) => {
|
|
13
|
-
listeners.add(listener);
|
|
14
|
-
return () => void listeners.delete(listener);
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
export function coalesce_bumps(watch, interval_in_milliseconds, now = () => performance.now()) {
|
|
19
|
-
let timer = null;
|
|
20
|
-
let last_bump_at = -Infinity;
|
|
21
|
-
const schedule = () => {
|
|
22
|
-
if (timer !== null)
|
|
23
|
-
return;
|
|
24
|
-
const wait = Math.max(0, interval_in_milliseconds - (now() - last_bump_at));
|
|
25
|
-
timer = setTimeout(() => {
|
|
26
|
-
timer = null;
|
|
27
|
-
last_bump_at = now();
|
|
28
|
-
watch.bump();
|
|
29
|
-
}, wait);
|
|
30
|
-
};
|
|
31
|
-
schedule.cancel = () => {
|
|
32
|
-
if (timer !== null)
|
|
33
|
-
clearTimeout(timer);
|
|
34
|
-
timer = null;
|
|
35
|
-
};
|
|
36
|
-
return schedule;
|
|
37
|
-
}
|