athena-ui-js 1.0.0 → 1.2.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.
@@ -448,16 +448,22 @@ textarea {
448
448
  /* Dialog (built on .modal) */
449
449
 
450
450
  .dialog-backdrop {
451
+ display: block; /* shown by the class, not by an inline style (CSP) */
451
452
  padding-top: 12vh;
452
453
  }
453
454
 
454
455
  .dialog {
455
456
  position: relative;
456
- width: min(480px, 92%);
457
+ width: min(var(--dialog-width, 480px), 92%);
457
458
  border-radius: var(--athena-radius);
458
459
  box-shadow: var(--athena-shadow);
459
460
  }
460
461
 
462
+ .dialog-small { --dialog-width: 360px; }
463
+ .dialog-medium { --dialog-width: 480px; }
464
+ .dialog-large { --dialog-width: 720px; }
465
+ .dialog-full { --dialog-width: 100%; min-height: calc(100vh - 12vh - 40px); }
466
+
461
467
  .dialog-title {
462
468
  margin: 0 28px 12px 0;
463
469
  }
@@ -992,6 +998,16 @@ textarea {
992
998
  display: none;
993
999
  }
994
1000
 
1001
+ .dropzone-disabled {
1002
+ opacity: 0.5;
1003
+ cursor: not-allowed;
1004
+ }
1005
+
1006
+ .dropzone-disabled:hover {
1007
+ border-color: var(--athena-line);
1008
+ background-color: transparent;
1009
+ }
1010
+
995
1011
  .file-list {
996
1012
  list-style: none;
997
1013
  padding: 0;
@@ -1131,6 +1147,37 @@ textarea {
1131
1147
  margin-top: 8px;
1132
1148
  }
1133
1149
 
1150
+ .athena-table-pager[hidden] {
1151
+ display: none;
1152
+ }
1153
+
1154
+ /* Table options: density, wrapping, alignment */
1155
+
1156
+ .athena-table.athena-table-compact th,
1157
+ .athena-table.athena-table-compact td {
1158
+ padding: 2px 6px;
1159
+ }
1160
+
1161
+ .athena-table.athena-table-nowrap td {
1162
+ white-space: nowrap;
1163
+ overflow: hidden;
1164
+ text-overflow: ellipsis;
1165
+ max-width: 0;
1166
+ }
1167
+
1168
+ .athena-table.athena-table-wrap td {
1169
+ white-space: normal;
1170
+ overflow-wrap: anywhere;
1171
+ }
1172
+
1173
+ .athena-table td.athena-align-center { text-align: center; }
1174
+ .athena-table td.athena-align-right { text-align: right; }
1175
+
1176
+ .athena-table tr:focus-visible {
1177
+ outline: 2px solid var(--athena-focus, currentColor);
1178
+ outline-offset: -2px;
1179
+ }
1180
+
1134
1181
  /* Charts */
1135
1182
 
1136
1183
  .athena-chart {
@@ -1322,7 +1369,8 @@ textarea {
1322
1369
  }
1323
1370
 
1324
1371
  /* The window of rows is computed from a fixed row height, so every row has to be exactly that high. */
1325
- .athena-table-virtual td {
1372
+ /* The doubled class beats a general `.athena-table td` padding of the application. */
1373
+ .athena-table.athena-table-virtual td {
1326
1374
  box-sizing: border-box;
1327
1375
  height: var(--row-height, 36px);
1328
1376
  padding-top: 0;
@@ -1443,6 +1491,24 @@ textarea {
1443
1491
  margin: 0 0 8px;
1444
1492
  }
1445
1493
 
1494
+ .rt-source-view {
1495
+ display: block;
1496
+ box-sizing: border-box;
1497
+ width: 100%;
1498
+ padding: 8px 10px;
1499
+ border: 0;
1500
+ outline: none;
1501
+ resize: vertical;
1502
+ background: transparent;
1503
+ color: var(--athena-fg);
1504
+ font-family: monospace;
1505
+ }
1506
+
1507
+ .rt-source-view[hidden],
1508
+ .rt-editor[hidden] {
1509
+ display: none;
1510
+ }
1511
+
1446
1512
  .rt-disabled .rt-editor {
1447
1513
  opacity: 0.6;
1448
1514
  }
package/src/testing.js ADDED
@@ -0,0 +1,71 @@
1
+ //testing helpers for Athena UI
2
+ //Author: Csaba Tóth https://github.com/csabatibortoth/
3
+ //LICENCE: MIT
4
+ //Repository: https://github.com/csabatibortoth/athena-ui
5
+
6
+ // Helpers for the tests of an application that uses Athena UI (Node's test runner and jsdom, or a browser).
7
+ // They have no dependency of their own: you give installDom the JSDOM class of your own jsdom.
8
+ //
9
+ // import { JSDOM } from "jsdom";
10
+ // import { installDom, until, tick } from "athena-ui-js/testing";
11
+ // const dom = installDom(JSDOM);
12
+ // ...
13
+ // dom.uninstall();
14
+
15
+ const GLOBALS = ["window", "document", "navigator", "Node", "Element", "HTMLElement", "Event", "CustomEvent", "KeyboardEvent",
16
+ "MouseEvent", "PointerEvent", "DocumentFragment", "MutationObserver", "getComputedStyle", "requestAnimationFrame",
17
+ "cancelAnimationFrame", "localStorage", "location"];
18
+
19
+ const BOUND = new Set(["getComputedStyle", "requestAnimationFrame", "cancelAnimationFrame"]);
20
+
21
+ /**
22
+ * Makes a jsdom window the global one, so Athena components can run in Node.
23
+ * The components create their events from the element's own window, so no global Event is needed for them,
24
+ * but code written without that care (and tests) can still use `new Event(...)`.
25
+ *
26
+ * @param {new (html?: string, options?: object) => {window: object}} JSDOM the JSDOM class of jsdom
27
+ * @param {string} [html] page to start with
28
+ * @param {object} [options] passed to JSDOM (default: url "http://localhost/", pretendToBeVisual so animation frames work)
29
+ * @returns {{window: object, document: Document, uninstall: () => void}}
30
+ */
31
+ export function installDom(JSDOM, html = '<!doctype html><html><body><div id="wrapper"></div></body></html>', options = {}) {
32
+ const dom = new JSDOM(html, { url: "http://localhost/", pretendToBeVisual: true, ...options });
33
+ const { window } = dom;
34
+ const saved = new Map();
35
+ for (const name of GLOBALS) {
36
+ saved.set(name, Object.getOwnPropertyDescriptor(globalThis, name));
37
+ const value = name === "window" ? window : window[name];
38
+ if (value === undefined) continue;
39
+ // Functions of the window (getComputedStyle, requestAnimationFrame, ...) need the window as `this`.
40
+ const bound = BOUND.has(name) ? value.bind(window) : value;
41
+ Object.defineProperty(globalThis, name, { value: bound, configurable: true, writable: true });
42
+ }
43
+ return {
44
+ window,
45
+ document: window.document,
46
+ uninstall() {
47
+ for (const [name, descriptor] of saved) {
48
+ if (descriptor) Object.defineProperty(globalThis, name, descriptor);
49
+ else delete globalThis[name];
50
+ }
51
+ window.close();
52
+ }
53
+ };
54
+ }
55
+
56
+ /** Waits for `ms` milliseconds (0 = the next turn of the event loop). */
57
+ export const tick = (ms = 0) => new Promise(resolve => setTimeout(resolve, ms));
58
+
59
+ /**
60
+ * Waits until `condition()` returns something truthy, and returns that value.
61
+ * Throws after `timeout` ms, naming `message`, so a test fails with a reason instead of hanging.
62
+ */
63
+ export async function until(condition, { timeout = 2000, interval = 10, message = "condition" } = {}) {
64
+ const start = Date.now();
65
+ for (;;) {
66
+ const value = await condition();
67
+ if (value) return value;
68
+ if (Date.now() - start > timeout) throw new Error(`Timed out after ${timeout} ms waiting for ${message}`);
69
+ await tick(interval);
70
+ }
71
+ }