athena-ui-js 2.2.0 → 2.3.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/README.md CHANGED
@@ -5,7 +5,7 @@ layout (header, menu, content wrapper, footer) from a single `init()` call, load
5
5
  and theme, and ships the building blocks of a multipurpose application: forms, tables, charts,
6
6
  feedback, navigation, a router and more.
7
7
 
8
- Current version: **2.2.0**
8
+ Current version: **2.3.0**
9
9
 
10
10
  [Quick start](#usage) · [API](#api) · [Components](#charts) · [Themes](#themes) · [Tests](#tests) · [Release notes](#releases)
11
11
 
@@ -67,7 +67,7 @@ import { generateTable } from "athena-ui-js/table"; // or only what you u
67
67
  ```
68
68
 
69
69
  The entry points are `table`, `chart`, `dialog`, `menu`, `navigation`, `forms`, `feedback`, `components`, `inputs`, `router`, `session`, `theme`, `i18n`, `format`,
70
- `validation`, `motion`, `sanitize`, `csv`, `dom` and `controls`. TypeScript definitions are included (`types/`, generated from the JSDoc with `npm run types`).
70
+ `validation`, `motion`, `widgets`, `sanitize`, `csv`, `dom` and `controls`. TypeScript definitions are included (`types/`, generated from the JSDoc with `npm run types`).
71
71
  The package has `"sideEffects"` for `classic.js`, `theme-boot.js` and CSS only, so a bundler drops everything you do not import.
72
72
 
73
73
  Without npm, serve the `src` folder with any static web server and open `index.html` to see the example.
@@ -149,7 +149,7 @@ It takes the options of `init()`. The header and footer follow the settings `gen
149
149
  | `header_title_text` | `"Athena UI"` | Title in the header |
150
150
  | `header_img_url` | | Header logo URL |
151
151
  | `copyright` | placeholder text | Footer text, the version is appended |
152
- | `version` | `"2.2.0"` | Version shown in the footer |
152
+ | `version` | `"2.3.0"` | Version shown in the footer |
153
153
  | `bordered` | `true` | Draw a border around the layout blocks |
154
154
  | `generateHeader`, `generateFooter` | `true` | Generate the header / footer block |
155
155
  | `generateHeadercontent`, `generateFooterContent`, `generateWrappercontent` | `true` | Generate the content of the block |
@@ -195,6 +195,7 @@ Everything is exported from `athena-ui.js`:
195
195
  | `formatBytes`, `formatNumber`, `formatDuration`, `formatRelativeTime`, `formatDate` | Format helpers on top of `Intl`, in the current language |
196
196
  | `el`, `setContent`, `resolveElement`, `asHandle`, `createSafeBuilder` | See [Safe DOM building](#safe-dom-building) |
197
197
  | `animate`, `flip`, `stagger`, `spring`, `tween`, `transition`, `viewTransition`, `setMotion`, `prefersReducedMotion`, `easings`, `generateSkeleton` | See [Motion](#motion-animations-and-transitions) |
198
+ | `registerWidget`, `createWidgetGrid`, `getWidgetTypes`, `placeItem`, `compact`, `findFreeSpot`, `normalize` | See [Widgets](#widgets-a-dashboard-that-can-be-built) |
198
199
  | `generateCard`, `generateSection`, `generateGrid`, `generateBadge`, `generateAvatar`, `generateStat`, `generateLink`, `generateTooltip` | See [Components](#components) |
199
200
  | `generateAutocomplete`, `generateMultiSelect`, `generateFileUpload`, `generateDropZone`, `generateStepper`, `generateDateRange`, `generateRichText`, `generateWysiwyg` | See [Inputs](#inputs) |
200
201
  | `sanitizeHtml(html)`, `htmlToText(html)`, `isSafeUrl(url)` | The allow-list sanitizer behind the rich text editor |
@@ -694,6 +695,47 @@ setMotion("reduce"); // "system"
694
695
  In a page that is not drawn (a hidden tab) there are no frames: `animate` and `tween` finish by a timer, so nothing hangs. Dialogs and toasts stay in the page for the length of their
695
696
  exit transition (none under reduced motion); in your tests call `setMotion("reduce")` first, so they are gone at once.
696
697
 
698
+ ### Widgets: a dashboard that can be built
699
+
700
+ `athena-ui-js/widgets`: a grid of widgets that can be added, configured, moved, resized, locked, saved and loaded. No dependency, no drag library, no inline style.
701
+
702
+ ```js
703
+ import { registerWidget, createWidgetGrid } from "athena-ui-js/widgets";
704
+
705
+ // a type of widget: a function that draws into the body it is given, and cleans up after itself
706
+ registerWidget("clock", {
707
+ title: "Clock", defaultSize: { w: 3, h: 2 }, minSize: { w: 2, h: 1 }, defaultConfig: { seconds: true },
708
+ configForm: [{ name: "seconds", label: "Show seconds", type: "checkbox" }], // the settings dialog (showFormDialog)
709
+ render(context) { // called when the widget is first seen (IntersectionObserver)
710
+ const time = el("p");
711
+ context.element.append(time);
712
+ const show = () => time.textContent = new Date().toLocaleTimeString();
713
+ const timer = setInterval(show, 1000);
714
+ return { update: show, destroy: () => clearInterval(timer) }; // update(): config or title changed (throttled), destroy(): removed
715
+ }
716
+ });
717
+
718
+ const grid = createWidgetGrid({
719
+ element: "dashboard", columns: 12, rowHeight: 80, gap: 12, editable: true,
720
+ breakpoints: { wide: { minWidth: 900, columns: 12 }, narrow: { minWidth: 0, columns: 6 } }, // optional: a layout per width
721
+ widgets: [{ type: "clock", x: 0, y: 0 }],
722
+ onChange: (layout, reason) => localStorage.setItem("dashboard", JSON.stringify(layout)) // "move", "resize", "add", "remove", "settings", "undo", ...
723
+ });
724
+ grid.setLayout(JSON.parse(localStorage.getItem("dashboard"))); // plain, versioned JSON ({ version: 1, widgets: [...] })
725
+ ```
726
+
727
+ - **Layout** is CSS grid. The columns, the row height, the gap and the place of every widget are CSS classes written into a constructed style sheet, so a strict
728
+ Content-Security-Policy (no `style` attribute) is fine. Widgets fall upwards (`compact: false` keeps the gaps) and slide to their new places (not under reduced motion).
729
+ - **Edit mode** (`setEditable(true)`): drag by the handle, resize by any edge or corner, snap to cells, push other widgets out of the way. Settings, duplicate and remove buttons.
730
+ A **locked** widget (`lockWidget(id)`) is not moved, not resized, not pushed, and nothing can be put on it.
731
+ - **Keyboard**: focus the handle, Space or Enter picks the widget up, arrow keys move it, Shift with arrow keys resizes it, Enter drops it, Escape cancels. Every step is announced
732
+ in a live region ("Column 2, row 1, 3 wide, 2 high"). Pointer Events: mouse, pen and touch work the same.
733
+ - **Undo and redo** of every change (`undo()`, `redo()`, `canUndo()`); `updateWidget(id, { config })` is for data from code and is not an undo step.
734
+ - **Layouts** (`getLayout()` / `setLayout(json)`) are plain JSON and the application decides where they are stored. Loading is checked: a bad entry is skipped (reported in the result),
735
+ duplicate ids are replaced, places are clamped and made free of overlaps, `__proto__`-style keys are dropped, and a type that is not registered is shown as a placeholder (its data is kept, nothing is executed).
736
+ - **Performance**: a widget is rendered only when it is first seen, `resize(context, size)` is called throttled when its body changes size, and nothing re-renders while it is out of view.
737
+ - The grid maths (`placeItem`, `compact`, `findFreeSpot`, `normalize`, `collides`) is exported as well, for your own layouts.
738
+
697
739
  ### Safe DOM building
698
740
 
699
741
  `el(tag, { class, id, text, attrs, on, prop }, ...children)` is the way Athena builds its own pages, and it is exported. Strings are only ever inserted as **text**, children can be
package/docs/styling.md CHANGED
@@ -100,4 +100,4 @@ Dark colours: set `data-mode="dark"` on `<html>` (or let `createThemeManager` do
100
100
  | A place holder for what is loading: a skeleton with a shimmer (generateSkeleton) | `.athena-skeleton` `.athena-skeleton-line` | `--athena-hover` `--athena-radius` `--athena-space-2` `--athena-surface` |
101
101
  | A theme or mode change cross-fades instead of flashing (the theme manager sets the class for a moment) | `.athena-switching` | `--athena-duration-slow` `--athena-ease-standard` |
102
102
  | Page transitions of the router (router({ transition: true })) | - | `--athena-duration-base` `--athena-ease-standard` |
103
- | Charts draw themselves when they appear: bars grow, lines are drawn, slices pop in (only the first time, not when a chart streams or is zoomed) | `.athena-chart-animated` `.chart-area` `.chart-bar` `.chart-line` `.chart-point` `.chart-slice` | `--athena-duration-slow` `--athena-ease-out` |
103
+ | Charts draw themselves when they appear: bars grow, lines are drawn, slices pop in (only the first time, not when a chart streams or is zoomed) | `.athena-chart-animated` `.athena-widget-grid` `.chart-area` `.chart-bar` `.chart-line` `.chart-point` `.chart-slice` `.is-dragging` `.is-editable` `.is-failed` `.is-locked` `.is-unknown` `.widget` `.widget-action` `.widget-actions` `.widget-body` `.widget-handle` `.widget-header` `.widget-note` `.widget-resize` `.widget-resize-e` `.widget-resize-n` `.widget-resize-ne` `.widget-resize-nw` `.widget-resize-s` `.widget-resize-se` `.widget-resize-sw` `.widget-resize-w` `.widget-title` | `--athena-accent` `--athena-accent-fg` `--athena-border` `--athena-border-width` `--athena-duration-fast` `--athena-duration-slow` `--athena-ease-out` `--athena-ease-standard` `--athena-fg` `--athena-focus` `--athena-focus-width` `--athena-hover` `--athena-line` `--athena-muted` `--athena-radius` `--athena-shadow` `--athena-surface` `--athena-surface-alt` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "athena-ui-js",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "A small, dependency-free UI framework: forms, tables, charts, menus, dialogs, themes and a router, written as ES modules.",
5
5
  "type": "module",
6
6
  "main": "./src/athena-ui.js",
@@ -91,6 +91,10 @@
91
91
  "types": "./types/motion.d.ts",
92
92
  "default": "./src/motion.js"
93
93
  },
94
+ "./widgets": {
95
+ "types": "./types/widgets.d.ts",
96
+ "default": "./src/widgets.js"
97
+ },
94
98
  "./sanitize": {
95
99
  "types": "./types/sanitize.d.ts",
96
100
  "default": "./src/sanitize.js"
package/src/athena-ui.js CHANGED
@@ -2,7 +2,7 @@
2
2
  //Author: Csaba Tóth https://github.com/csabatibortoth/
3
3
  //LICENCE: MIT
4
4
  //Repository: https://github.com/csabatibortoth/athena-ui
5
- //Version: 2.2.0
5
+ //Version: 2.3.0
6
6
 
7
7
  // The whole API as ES module exports. There are no side effects: importing this file does not touch the page, does not load a script and does not
8
8
  // put anything on globalThis. For pages that need globals use `athena-ui-js/classic`, and to download only what you use import from the entry points
@@ -124,6 +124,8 @@ export * from "./libs/core/csv.js";
124
124
  export * from "./libs/core/dateRange.js";
125
125
  export * from "./libs/core/format.js";
126
126
  export * from "./libs/core/motion.js";
127
+ export * from "./libs/hephaestus/widgetGrid/widgetGrid.js";
128
+ export * from "./libs/core/gridLayout.js";
127
129
  export * from "./libs/hephaestus/modalGenerator/modalGenerator.js";
128
130
  export * from "./libs/core/theme.js";
129
131
  export * from "./libs/hephaestus/componentGenerator/themePicker.js";
@@ -6,7 +6,7 @@
6
6
  export const BORDERED_CLASS = "default-cointainer-bordered";
7
7
 
8
8
  export const defaults = Object.freeze({
9
- version: "2.2.0",
9
+ version: "2.3.0",
10
10
  container_class: "container",
11
11
  header_class: "header-container",
12
12
  header_menu_class: "header-menu menu",
@@ -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,22 @@ 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.",
24
40
  "range.preset": "Range",
25
41
  "range.custom": "Custom",
26
42
  "range.last15m": "Last 15 minutes",
@@ -118,6 +134,22 @@ const messages = {
118
134
  rememberMe: "Emlékezz rám",
119
135
  ok: "OK",
120
136
  save: "Mentés",
137
+ "widget.move": "{title} áthelyezése",
138
+ "widget.settings": "{title} beállításai",
139
+ "widget.duplicate": "{title} másolása",
140
+ "widget.remove": "{title} eltávolítása",
141
+ "widget.copy": "{title} (másolat)",
142
+ "widget.titleLabel": "Cím",
143
+ "widget.settingsTitle": "Widget beállításai",
144
+ "widget.unknown": "Ismeretlen widgettípus: \"{type}\".",
145
+ "widget.failed": "Ez a widget nem jeleníthető meg.",
146
+ "widget.pickedUp": "{title} felvéve. A nyilak mozgatják, Shift és nyilak átméretezik, Enter leteszi, Escape megszakítja.",
147
+ "widget.dropped": "{title} letéve.",
148
+ "widget.cancelled": "Megszakítva.",
149
+ "widget.blocked": "Itt nem lehetséges.",
150
+ "widget.position": "{x}. oszlop, {y}. sor, {w} széles, {h} magas.",
151
+ "widget.added": "{title} hozzáadva.",
152
+ "widget.removed": "{title} eltávolítva.",
121
153
  "range.preset": "Időszak",
122
154
  "range.custom": "Egyéni",
123
155
  "range.last15m": "Utolsó 15 perc",
@@ -2374,4 +2374,189 @@ dialog.dialog[open]::backdrop {
2374
2374
  animation: athena-pop var(--athena-duration-slow) var(--athena-ease-out) backwards;
2375
2375
  }
2376
2376
 
2377
+
2378
+ /* ------------------------------------------------------------ Widgets
2379
+ createWidgetGrid: a CSS grid. The columns, the row height and the gap are classes (wg-cols-12, wg-rh-80, wg-gap-12) and so is the place of every
2380
+ widget (wg-x-1, wg-y-1, wg-w-3, wg-h-2), written into a constructed style sheet: no style attribute, so a strict Content-Security-Policy is fine.
2381
+ The controls of the edit mode (handle, buttons, resize edges) exist in every widget and are shown only in .is-editable. */
2382
+
2383
+ .athena-widget-grid {
2384
+ display: grid;
2385
+ position: relative;
2386
+ align-items: stretch;
2387
+ }
2388
+
2389
+ .widget {
2390
+ position: relative;
2391
+ display: flex;
2392
+ flex-direction: column;
2393
+ min-width: 0;
2394
+ min-height: 0;
2395
+ border: var(--athena-border-width) solid var(--athena-line);
2396
+ border-radius: var(--athena-radius);
2397
+ background: var(--athena-surface);
2398
+ color: var(--athena-fg);
2399
+ overflow: hidden;
2400
+ transition: box-shadow var(--athena-duration-fast) var(--athena-ease-standard), border-color var(--athena-duration-fast) var(--athena-ease-standard);
2401
+ }
2402
+
2403
+ .widget-header {
2404
+ display: flex;
2405
+ align-items: center;
2406
+ gap: 6px;
2407
+ padding: 6px 10px;
2408
+ border-bottom: var(--athena-border-width) solid var(--athena-line);
2409
+ background: var(--athena-surface-alt);
2410
+ }
2411
+
2412
+ .widget-title {
2413
+ flex: 1;
2414
+ min-width: 0;
2415
+ margin: 0;
2416
+ font-size: 0.95rem;
2417
+ font-weight: 600;
2418
+ overflow: hidden;
2419
+ text-overflow: ellipsis;
2420
+ white-space: nowrap;
2421
+ }
2422
+
2423
+ .widget-body {
2424
+ flex: 1;
2425
+ min-height: 0;
2426
+ padding: 10px;
2427
+ overflow: auto;
2428
+ }
2429
+
2430
+ .widget-note {
2431
+ margin: 0;
2432
+ color: var(--athena-muted);
2433
+ }
2434
+
2435
+ .widget.is-unknown,
2436
+ .widget.is-failed {
2437
+ border-style: dashed;
2438
+ }
2439
+
2440
+ .widget-handle,
2441
+ .widget-actions,
2442
+ .widget-resize {
2443
+ display: none;
2444
+ }
2445
+
2446
+ .widget-actions {
2447
+ gap: 2px;
2448
+ }
2449
+
2450
+ .widget-handle,
2451
+ .widget-action {
2452
+ padding: 2px 6px;
2453
+ border: var(--athena-border-width) solid transparent;
2454
+ border-radius: var(--athena-radius);
2455
+ background: transparent;
2456
+ color: var(--athena-fg);
2457
+ font: inherit;
2458
+ line-height: 1.2;
2459
+ cursor: pointer;
2460
+ }
2461
+
2462
+ .widget-handle:hover,
2463
+ .widget-action:hover {
2464
+ background: var(--athena-hover);
2465
+ }
2466
+
2467
+ .widget-handle:focus-visible,
2468
+ .widget-action:focus-visible {
2469
+ outline: var(--athena-focus-width) solid var(--athena-focus);
2470
+ outline-offset: 1px;
2471
+ }
2472
+
2473
+ .widget-handle {
2474
+ cursor: grab;
2475
+ touch-action: none;
2476
+ }
2477
+
2478
+ .widget-handle[aria-pressed="true"] {
2479
+ background: var(--athena-accent);
2480
+ color: var(--athena-accent-fg);
2481
+ }
2482
+
2483
+ .is-editable .widget-handle {
2484
+ display: inline-block;
2485
+ }
2486
+
2487
+ .is-editable .widget-actions {
2488
+ display: flex;
2489
+ }
2490
+
2491
+ .is-editable .widget {
2492
+ border-color: var(--athena-border);
2493
+ }
2494
+
2495
+ .is-editable .widget.is-locked .widget-handle,
2496
+ .is-editable .widget.is-locked .widget-resize {
2497
+ display: none;
2498
+ }
2499
+
2500
+ .is-editable .widget.is-locked .widget-title::after {
2501
+ content: " 🔒";
2502
+ }
2503
+
2504
+ .widget.is-dragging {
2505
+ z-index: 2;
2506
+ border-color: var(--athena-accent);
2507
+ box-shadow: var(--athena-shadow);
2508
+ }
2509
+
2510
+ .is-editable .widget-resize {
2511
+ display: block;
2512
+ position: absolute;
2513
+ z-index: 1;
2514
+ touch-action: none;
2515
+ }
2516
+
2517
+ .widget-resize-n,
2518
+ .widget-resize-s {
2519
+ left: 12px;
2520
+ right: 12px;
2521
+ height: 8px;
2522
+ cursor: ns-resize;
2523
+ }
2524
+
2525
+ .widget-resize-e,
2526
+ .widget-resize-w {
2527
+ top: 12px;
2528
+ bottom: 12px;
2529
+ width: 8px;
2530
+ cursor: ew-resize;
2531
+ }
2532
+
2533
+ .widget-resize-n { top: 0; }
2534
+ .widget-resize-s { bottom: 0; }
2535
+ .widget-resize-e { right: 0; }
2536
+ .widget-resize-w { left: 0; }
2537
+
2538
+ .widget-resize-ne,
2539
+ .widget-resize-nw,
2540
+ .widget-resize-se,
2541
+ .widget-resize-sw {
2542
+ width: 14px;
2543
+ height: 14px;
2544
+ }
2545
+
2546
+ .widget-resize-ne { top: 0; right: 0; cursor: nesw-resize; }
2547
+ .widget-resize-nw { top: 0; left: 0; cursor: nwse-resize; }
2548
+ .widget-resize-se { bottom: 0; right: 0; cursor: nwse-resize; }
2549
+ .widget-resize-sw { bottom: 0; left: 0; cursor: nesw-resize; }
2550
+
2551
+ .widget-resize-se::after {
2552
+ content: "";
2553
+ position: absolute;
2554
+ right: 3px;
2555
+ bottom: 3px;
2556
+ width: 8px;
2557
+ height: 8px;
2558
+ border-right: 2px solid var(--athena-muted);
2559
+ border-bottom: 2px solid var(--athena-muted);
2560
+ }
2561
+
2377
2562
  }
package/src/widgets.js ADDED
@@ -0,0 +1,7 @@
1
+ //widgets entry of Athena UI: a dashboard of widgets (registerWidget, createWidgetGrid) and the grid maths
2
+ //Import only what you use: `import { registerWidget, createWidgetGrid } from "athena-ui-js/widgets"`.
3
+ //LICENCE: MIT
4
+ //Repository: https://github.com/csabatibortoth/athena-ui
5
+
6
+ export * from "./libs/hephaestus/widgetGrid/widgetGrid.js";
7
+ export * from "./libs/core/gridLayout.js";
@@ -88,6 +88,8 @@ export * from "./libs/core/csv.js";
88
88
  export * from "./libs/core/dateRange.js";
89
89
  export * from "./libs/core/format.js";
90
90
  export * from "./libs/core/motion.js";
91
+ export * from "./libs/hephaestus/widgetGrid/widgetGrid.js";
92
+ export * from "./libs/core/gridLayout.js";
91
93
  export * from "./libs/hephaestus/modalGenerator/modalGenerator.js";
92
94
  export * from "./libs/core/theme.js";
93
95
  export * from "./libs/hephaestus/componentGenerator/themePicker.js";
@@ -1,5 +1,5 @@
1
1
  export function applyConfig(...sources: any[]): {
2
- version: "2.2.0";
2
+ version: "2.3.0";
3
3
  container_class: "container";
4
4
  header_class: "header-container";
5
5
  header_menu_class: "header-menu menu";
@@ -32,7 +32,7 @@ export function applyConfig(...sources: any[]): {
32
32
  export function withBorder(className: any): any;
33
33
  export const BORDERED_CLASS: "default-cointainer-bordered";
34
34
  export const defaults: Readonly<{
35
- version: "2.2.0";
35
+ version: "2.3.0";
36
36
  container_class: "container";
37
37
  header_class: "header-container";
38
38
  header_menu_class: "header-menu menu";
@@ -64,7 +64,7 @@ export const defaults: Readonly<{
64
64
  }>;
65
65
  export default config;
66
66
  declare namespace config {
67
- let version: "2.2.0";
67
+ let version: "2.3.0";
68
68
  let container_class: "container";
69
69
  let header_class: "header-container";
70
70
  let header_menu_class: "header-menu menu";
@@ -0,0 +1,45 @@
1
+ /** Puts an item inside the columns and inside its size limits ({ min: {w, h}, max: {w, h} }). */
2
+ export function clampItem(item: any, columns: any, { min, max }?: {
3
+ min?: {};
4
+ max?: {};
5
+ }): any;
6
+ /**
7
+ * Gravity: every item that is not locked moves up as far as it can (locked items stay where they are).
8
+ * @returns {object[]} new items, in the order of the argument
9
+ */
10
+ export function compact(items: any): object[];
11
+ /**
12
+ * Sets the place of one item (clamped), pushes the others out of its way and, unless `compactItems` is false, lets everything fall upwards.
13
+ * @param {object[]} items
14
+ * @param {string} id
15
+ * @param {{x?: number, y?: number, w?: number, h?: number}} place the new place; missing values stay as they are
16
+ * @param {number} columns
17
+ * @param {object} [options]
18
+ * @param {{min?: object, max?: object}} [options.limits] size limits of this item
19
+ * @param {boolean} [options.compactItems=true]
20
+ * @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)
21
+ */
22
+ export function placeItem(items: object[], id: string, place: {
23
+ x?: number;
24
+ y?: number;
25
+ w?: number;
26
+ h?: number;
27
+ }, columns: number, { limits, compactItems }?: {
28
+ limits?: {
29
+ min?: object;
30
+ max?: object;
31
+ };
32
+ compactItems?: boolean;
33
+ }): object[] | null;
34
+ /** The first free place of the size w x h (rows grow without end). */
35
+ export function findFreeSpot(items: any, w: any, h: any, columns: any): {
36
+ x: number;
37
+ y: number;
38
+ };
39
+ /**
40
+ * Makes any list of items a valid layout for `columns`: inside the columns, without overlaps, compact. Items keep their order of reading
41
+ * (top to bottom, left to right). Used for loaded layouts and for a breakpoint that has no layout of its own.
42
+ */
43
+ export function normalize(items: any, columns: any, limitsOf?: () => {}): any[];
44
+ export function collides(a: any, b: any): boolean;
45
+ export function rowsOf(items: any): any;