athena-ui-js 2.2.0 → 2.4.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.
@@ -0,0 +1,102 @@
1
+ //Grid layout maths of Athena UI (no DOM): where widgets sit on a grid of columns, what moves when one is dragged or resized.
2
+ //An item is { id, x, y, w, h, locked? } in grid cells, x and y counted from 0. Every function returns new items; the argument is not changed.
3
+ //LICENCE: MIT
4
+ //Repository: https://github.com/csabatibortoth/athena-ui
5
+
6
+ /** Do two items cover a common cell? */
7
+ export const collides = (a, b) => a.id !== b.id && a.x < b.x + b.w && a.x + a.w > b.x && a.y < b.y + b.h && a.y + a.h > b.y;
8
+
9
+ const copy = items => items.map(item => ({ ...item }));
10
+ const byPlace = (a, b) => a.y - b.y || a.x - b.x;
11
+
12
+ /** Puts an item inside the columns and inside its size limits ({ min: {w, h}, max: {w, h} }). */
13
+ export function clampItem(item, columns, { min = {}, max = {} } = {}) {
14
+ const minW = Math.max(1, Math.min(min.w ?? 1, columns));
15
+ const minH = Math.max(1, min.h ?? 1);
16
+ const w = Math.min(Math.max(Math.round(item.w) || minW, minW), Math.min(max.w ?? columns, columns));
17
+ const h = Math.min(Math.max(Math.round(item.h) || minH, minH), max.h ?? Infinity);
18
+ const x = Math.min(Math.max(Math.round(item.x) || 0, 0), columns - w);
19
+ const y = Math.max(Math.round(item.y) || 0, 0);
20
+ return { ...item, x, y, w, h };
21
+ }
22
+
23
+ /**
24
+ * Gravity: every item that is not locked moves up as far as it can (locked items stay where they are).
25
+ * @returns {object[]} new items, in the order of the argument
26
+ */
27
+ export function compact(items) {
28
+ const result = copy(items);
29
+ const placed = result.filter(item => item.locked);
30
+ for (const item of result.filter(item => !item.locked).sort(byPlace)) {
31
+ while (item.y > 0) {
32
+ item.y--;
33
+ if (placed.some(other => collides(item, other))) {
34
+ item.y++;
35
+ break;
36
+ }
37
+ }
38
+ placed.push(item);
39
+ }
40
+ return result;
41
+ }
42
+
43
+ /** Pushes what the item `moved` covers downwards, and what that covers in turn. Returns false when a locked item is in the way. */
44
+ function resolve(layout, moved, depth = 0) {
45
+ if (depth > layout.length + 2) return false;
46
+ for (const other of layout.filter(item => collides(moved, item)).sort(byPlace)) {
47
+ if (other.locked) return false;
48
+ other.y = moved.y + moved.h;
49
+ if (!resolve(layout, other, depth + 1)) return false;
50
+ }
51
+ return true;
52
+ }
53
+
54
+ /**
55
+ * Sets the place of one item (clamped), pushes the others out of its way and, unless `compactItems` is false, lets everything fall upwards.
56
+ * @param {object[]} items
57
+ * @param {string} id
58
+ * @param {{x?: number, y?: number, w?: number, h?: number}} place the new place; missing values stay as they are
59
+ * @param {number} columns
60
+ * @param {object} [options]
61
+ * @param {{min?: object, max?: object}} [options.limits] size limits of this item
62
+ * @param {boolean} [options.compactItems=true]
63
+ * @returns {object[]|null} the new layout, or null when it is not possible (a locked item is in the way, or the item is locked)
64
+ */
65
+ export function placeItem(items, id, place, columns, { limits, compactItems = true } = {}) {
66
+ const layout = copy(items);
67
+ const item = layout.find(entry => entry.id === id);
68
+ if (!item || item.locked) return null;
69
+ Object.assign(item, clampItem({ ...item, ...place }, columns, limits));
70
+ if (layout.some(other => other.locked && collides(item, other))) return null;
71
+ if (!resolve(layout, item)) return null;
72
+ return compactItems ? compact(layout) : layout;
73
+ }
74
+
75
+ /** The first free place of the size w x h (rows grow without end). */
76
+ export function findFreeSpot(items, w, h, columns) {
77
+ const width = Math.min(Math.max(1, w), columns);
78
+ for (let y = 0; ; y++) {
79
+ for (let x = 0; x + width <= columns; x++) {
80
+ const probe = { id: "\0probe", x, y, w: width, h };
81
+ if (!items.some(item => collides(probe, item))) return { x, y };
82
+ }
83
+ }
84
+ }
85
+
86
+ /**
87
+ * Makes any list of items a valid layout for `columns`: inside the columns, without overlaps, compact. Items keep their order of reading
88
+ * (top to bottom, left to right). Used for loaded layouts and for a breakpoint that has no layout of its own.
89
+ */
90
+ export function normalize(items, columns, limitsOf = () => ({})) {
91
+ const placed = [];
92
+ for (const raw of copy(items).sort(byPlace)) {
93
+ const item = clampItem(raw, columns, limitsOf(raw));
94
+ while (placed.some(other => collides(item, other))) item.y++;
95
+ placed.push(item);
96
+ }
97
+ const order = new Map(items.map((item, index) => [item.id, index]));
98
+ return compact(placed).sort((a, b) => order.get(a.id) - order.get(b.id));
99
+ }
100
+
101
+ /** The height of the layout in rows. */
102
+ export const rowsOf = items => items.reduce((rows, item) => Math.max(rows, item.y + item.h), 0);
@@ -21,6 +21,50 @@ const messages = {
21
21
  rememberMe: "Remember me",
22
22
  ok: "OK",
23
23
  save: "Save",
24
+ "widget.move": "Move {title}",
25
+ "widget.settings": "Settings of {title}",
26
+ "widget.duplicate": "Duplicate {title}",
27
+ "widget.remove": "Remove {title}",
28
+ "widget.copy": "{title} (copy)",
29
+ "widget.titleLabel": "Title",
30
+ "widget.settingsTitle": "Widget settings",
31
+ "widget.unknown": "Unknown widget type \"{type}\".",
32
+ "widget.failed": "This widget could not be shown.",
33
+ "widget.pickedUp": "{title} picked up. Arrow keys move it, Shift with arrow keys resizes it, Enter drops it, Escape cancels.",
34
+ "widget.dropped": "{title} dropped.",
35
+ "widget.cancelled": "Cancelled.",
36
+ "widget.blocked": "Not possible here.",
37
+ "widget.position": "Column {x}, row {y}, {w} wide, {h} high.",
38
+ "widget.added": "{title} added.",
39
+ "widget.removed": "{title} removed.",
40
+ "code.copy": "Copy",
41
+ "code.copied": "Copied",
42
+ "code.copyFailed": "Copy failed",
43
+ "code.diff": "Differences",
44
+ "code.original": "Original",
45
+ "code.modified": "Modified",
46
+ "code.unchanged": "{count} unchanged lines",
47
+ "code.removed": "removed",
48
+ "code.added": "added",
49
+ "code.noChanges": "No differences.",
50
+ "code.editorLabel": "Code editor",
51
+ "code.escapeHint": "Press Escape, then Tab, to leave the editor.",
52
+ "code.tabLeaves": "The next Tab key leaves the editor.",
53
+ "code.find": "Find",
54
+ "code.replaceWith": "Replace with",
55
+ "code.next": "Next match",
56
+ "code.previous": "Previous match",
57
+ "code.replaceOne": "Replace",
58
+ "code.replaceAll": "Replace all",
59
+ "code.close": "Close",
60
+ "code.matchCase": "Match case",
61
+ "code.useRegex": "Regular expression",
62
+ "code.matches": "{current} of {total}",
63
+ "code.noMatches": "No matches",
64
+ "code.invalidPattern": "Invalid pattern",
65
+ "code.position": "Line {line}, column {column}",
66
+ "code.marker": "Line {line}: {message}",
67
+ "code.suggestions": "Suggestions",
24
68
  "range.preset": "Range",
25
69
  "range.custom": "Custom",
26
70
  "range.last15m": "Last 15 minutes",
@@ -118,6 +162,50 @@ const messages = {
118
162
  rememberMe: "Emlékezz rám",
119
163
  ok: "OK",
120
164
  save: "Mentés",
165
+ "widget.move": "{title} áthelyezése",
166
+ "widget.settings": "{title} beállításai",
167
+ "widget.duplicate": "{title} másolása",
168
+ "widget.remove": "{title} eltávolítása",
169
+ "widget.copy": "{title} (másolat)",
170
+ "widget.titleLabel": "Cím",
171
+ "widget.settingsTitle": "Widget beállításai",
172
+ "widget.unknown": "Ismeretlen widgettípus: \"{type}\".",
173
+ "widget.failed": "Ez a widget nem jeleníthető meg.",
174
+ "widget.pickedUp": "{title} felvéve. A nyilak mozgatják, Shift és nyilak átméretezik, Enter leteszi, Escape megszakítja.",
175
+ "widget.dropped": "{title} letéve.",
176
+ "widget.cancelled": "Megszakítva.",
177
+ "widget.blocked": "Itt nem lehetséges.",
178
+ "widget.position": "{x}. oszlop, {y}. sor, {w} széles, {h} magas.",
179
+ "widget.added": "{title} hozzáadva.",
180
+ "widget.removed": "{title} eltávolítva.",
181
+ "code.copy": "Másolás",
182
+ "code.copied": "Másolva",
183
+ "code.copyFailed": "A másolás nem sikerült",
184
+ "code.diff": "Különbségek",
185
+ "code.original": "Eredeti",
186
+ "code.modified": "Módosított",
187
+ "code.unchanged": "{count} változatlan sor",
188
+ "code.removed": "törölve",
189
+ "code.added": "hozzáadva",
190
+ "code.noChanges": "Nincs különbség.",
191
+ "code.editorLabel": "Kódszerkesztő",
192
+ "code.escapeHint": "A szerkesztőből az Escape, majd a Tab billentyűvel lehet kilépni.",
193
+ "code.tabLeaves": "A következő Tab kilép a szerkesztőből.",
194
+ "code.find": "Keresés",
195
+ "code.replaceWith": "Csere erre",
196
+ "code.next": "Következő találat",
197
+ "code.previous": "Előző találat",
198
+ "code.replaceOne": "Csere",
199
+ "code.replaceAll": "Összes cseréje",
200
+ "code.close": "Bezárás",
201
+ "code.matchCase": "Kis- és nagybetű",
202
+ "code.useRegex": "Reguláris kifejezés",
203
+ "code.matches": "{current} / {total}",
204
+ "code.noMatches": "Nincs találat",
205
+ "code.invalidPattern": "Érvénytelen minta",
206
+ "code.position": "{line}. sor, {column}. oszlop",
207
+ "code.marker": "{line}. sor: {message}",
208
+ "code.suggestions": "Javaslatok",
121
209
  "range.preset": "Időszak",
122
210
  "range.custom": "Egyéni",
123
211
  "range.last15m": "Utolsó 15 perc",