@threadlabs/looma 0.53.9 → 0.53.11
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 +16 -0
- package/blocks/editor-workspace.html +53 -0
- package/blocks/editor-workspace.js +15 -0
- package/blocks/list-detail.html +54 -0
- package/blocks/list-detail.js +62 -0
- package/blocks/search-and-open.html +33 -0
- package/blocks/search-and-open.js +53 -0
- package/blocks/settings-form.html +26 -0
- package/blocks/settings-form.js +16 -0
- package/components/shared/behaviors.d.ts +2 -0
- package/components/shared/behaviors.js +2 -0
- package/components/shared/collection-navigation.d.ts +28 -0
- package/components/shared/collection-navigation.js +40 -0
- package/components/shared/deferred-focus.d.ts +8 -0
- package/components/shared/deferred-focus.js +21 -0
- package/components/shared/form-reset.js +14 -6
- package/components/shared/menu-navigation.js +19 -22
- package/components/shared/overlay-dismissal.js +7 -0
- package/components/shared/overlay.js +3 -2
- package/components/ui-button/ui-button.html +1 -0
- package/components/ui-checkbox/ui-checkbox.html +1 -0
- package/components/ui-color-picker/ui-color-picker.html +1 -1
- package/components/ui-combobox/ui-combobox.html +5 -2
- package/components/ui-combobox/ui-combobox.js +6 -6
- package/components/ui-date-picker/ui-date-picker.js +5 -6
- package/components/ui-date-range-picker/ui-date-range-picker.js +6 -8
- package/components/ui-disclosure/ui-disclosure.html +3 -2
- package/components/ui-editor-toolbar/ui-editor-toolbar.js +8 -6
- package/components/ui-form-field/ui-form-field.html +1 -1
- package/components/ui-input/ui-input.html +1 -0
- package/components/ui-list-item/ui-list-item.html +3 -3
- package/components/ui-listbox/ui-listbox.html +1 -0
- package/components/ui-listbox/ui-listbox.js +10 -16
- package/components/ui-menu/ui-menu.html +1 -1
- package/components/ui-menu-item/ui-menu-item.html +1 -1
- package/components/ui-nav-item/ui-nav-item.html +2 -2
- package/components/ui-radio/ui-radio.html +1 -0
- package/components/ui-radio-group/ui-radio-group.html +1 -0
- package/components/ui-search-shell/ui-search-shell.js +4 -5
- package/components/ui-segmented-control/ui-segmented-control.html +3 -2
- package/components/ui-select/ui-select.html +4 -1
- package/components/ui-sidebar/ui-sidebar.html +7 -0
- package/components/ui-switch/ui-switch.html +1 -0
- package/components/ui-switcher/ui-switcher.html +28 -1
- package/components/ui-tabs/ui-tabs.js +5 -3
- package/components/ui-textarea/ui-textarea.html +5 -2
- package/dist/index.js +1 -1
- package/docs/catalog.json +80 -32
- package/editor/components.css +7 -3
- package/editor/index.js +77 -43
- package/package.json +8 -1
- package/styles/ui-button.css +1 -0
- package/styles/ui-checkbox.css +1 -0
- package/styles/ui-color-picker.css +2 -2
- package/styles/ui-combobox.css +8 -4
- package/styles/ui-disclosure.css +2 -1
- package/styles/ui-form-field.css +1 -1
- package/styles/ui-input.css +1 -0
- package/styles/ui-list-item.css +3 -3
- package/styles/ui-listbox.css +2 -0
- package/styles/ui-menu-item.css +1 -1
- package/styles/ui-nav-item.css +1 -1
- package/styles/ui-radio-group.css +1 -0
- package/styles/ui-radio.css +1 -0
- package/styles/ui-segmented-control.css +3 -2
- package/styles/ui-select.css +4 -1
- package/styles/ui-sidebar.css +12 -1
- package/styles/ui-switch.css +1 -0
- package/styles/ui-switcher.css +22 -1
- package/styles/ui-textarea.css +5 -2
- package/theme-system.css +3 -2
- package/tokens.css +1 -1
- package/vanilla/UiSwitcher.d.ts +2 -1
- package/vanilla/UiSwitcher.js +96 -16
package/README.md
CHANGED
|
@@ -35,6 +35,22 @@ and include its `src/html-next.d.ts` output in your TypeScript project.
|
|
|
35
35
|
The framework-neutral `trackInputModality` helper is available from
|
|
36
36
|
`@threadlabs/looma/input-modality` for client setup.
|
|
37
37
|
|
|
38
|
+
Use `@threadlabs/looma/behaviors` for shared collection navigation and deferred
|
|
39
|
+
focus in custom controls. These helpers compose with native markup and can be
|
|
40
|
+
imported on the server.
|
|
41
|
+
|
|
42
|
+
The [Blocks catalog](https://threadlabs.studio/looma/blocks/) shows complete HTML Next
|
|
43
|
+
compositions for editor workspaces, list and detail, settings, and search. Copy the
|
|
44
|
+
markup from the catalog or from the corresponding HTML file in
|
|
45
|
+
`@threadlabs/looma/blocks/`. Call its companion JavaScript setup function with the
|
|
46
|
+
rendered root after initializing Looma.
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
import setupListDetail from "@threadlabs/looma/blocks/list-detail.js";
|
|
50
|
+
|
|
51
|
+
const dispose = setupListDetail(document.querySelector('[data-block="list-detail"]'));
|
|
52
|
+
```
|
|
53
|
+
|
|
38
54
|
For React, use `target: "react"` before `react()` from `@vitejs/plugin-react`.
|
|
39
55
|
For Svelte 5, use `target: "svelte"` before `svelte()` from
|
|
40
56
|
`@sveltejs/vite-plugin-svelte`. Both import the same prefixed names from
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<link rel="component" href="@threadlabs/looma/components/ui-button/ui-button.html">
|
|
2
|
+
<link rel="component" href="@threadlabs/looma/components/ui-card/ui-card.html">
|
|
3
|
+
<link rel="component" href="@threadlabs/looma/components/ui-cluster/ui-cluster.html">
|
|
4
|
+
<link rel="component" href="@threadlabs/looma/components/ui-container/ui-container.html">
|
|
5
|
+
<link rel="component" href="@threadlabs/looma/components/ui-dialog/ui-dialog.html">
|
|
6
|
+
<link rel="component" href="@threadlabs/looma/components/ui-editor/ui-editor.html">
|
|
7
|
+
<link rel="component" href="@threadlabs/looma/components/ui-nav-item/ui-nav-item.html">
|
|
8
|
+
<link rel="component" href="@threadlabs/looma/components/ui-sidebar/ui-sidebar.html">
|
|
9
|
+
<link rel="component" href="@threadlabs/looma/components/ui-stack/ui-stack.html">
|
|
10
|
+
<link rel="component" href="@threadlabs/looma/components/ui-text/ui-text.html">
|
|
11
|
+
|
|
12
|
+
<ui-card data-block="editor-workspace" padding="sm" aria-label="Editor workspace example">
|
|
13
|
+
<ui-stack gap="s">
|
|
14
|
+
<ui-cluster justify="between" gap="xs" role="group" aria-label="Workspace controls">
|
|
15
|
+
<ui-button variant="ghost" commandfor="workspace-outline" command="--toggle">Outline</ui-button>
|
|
16
|
+
<ui-button variant="ghost" id="workspace-details-button">Details</ui-button>
|
|
17
|
+
</ui-cluster>
|
|
18
|
+
<ui-cluster wrap="nowrap" align="stretch" gap="s">
|
|
19
|
+
<ui-sidebar breakpoint="lg" width="200" id="workspace-outline" aria-label="Document outline">
|
|
20
|
+
<nav aria-label="Document sections" data-outline>
|
|
21
|
+
<ui-stack gap="xs">
|
|
22
|
+
<ui-nav-item as="a" href="#workspace-draft">Draft</ui-nav-item>
|
|
23
|
+
<ui-nav-item as="a" href="#workspace-notes">Revision notes</ui-nav-item>
|
|
24
|
+
</ui-stack>
|
|
25
|
+
</nav>
|
|
26
|
+
</ui-sidebar>
|
|
27
|
+
<ui-container fill gutters="s">
|
|
28
|
+
<ui-stack gap="m">
|
|
29
|
+
<section aria-labelledby="workspace-draft">
|
|
30
|
+
<ui-stack gap="s">
|
|
31
|
+
<ui-text as="h3" id="workspace-draft" variant="heading" tabindex="-1">Field notes from the coast</ui-text>
|
|
32
|
+
<ui-editor
|
|
33
|
+
label="Draft"
|
|
34
|
+
toolbar-mode="sticky"
|
|
35
|
+
content='{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"By the time we reached the tide pools, the wind had dropped. Small crabs moved between the stones, and the incoming water traced a bright line along the sand."}]},{"type":"paragraph","content":[{"type":"text","text":"We marked the spot on the map and waited for the last pool to fill."}]}]}'
|
|
36
|
+
></ui-editor>
|
|
37
|
+
</ui-stack>
|
|
38
|
+
</section>
|
|
39
|
+
<section aria-labelledby="workspace-notes">
|
|
40
|
+
<ui-stack gap="xs">
|
|
41
|
+
<ui-text as="h3" id="workspace-notes" variant="heading" tabindex="-1">Revision notes</ui-text>
|
|
42
|
+
<ui-text as="p" tone="secondary">Add the time of day and check the name of the beach.</ui-text>
|
|
43
|
+
</ui-stack>
|
|
44
|
+
</section>
|
|
45
|
+
</ui-stack>
|
|
46
|
+
</ui-container>
|
|
47
|
+
</ui-cluster>
|
|
48
|
+
</ui-stack>
|
|
49
|
+
<ui-dialog id="workspace-details" for="workspace-details-button" modal label="Document details">
|
|
50
|
+
<p>This draft is part of the field notes collection.</p>
|
|
51
|
+
<ui-button slot="actions" commandfor="workspace-details" command="close">Done</ui-button>
|
|
52
|
+
</ui-dialog>
|
|
53
|
+
</ui-card>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Following an outline link should land in the document, including when the outline is a drawer.
|
|
2
|
+
export default function setup(root) {
|
|
3
|
+
const navigation = root.querySelector("[data-outline]");
|
|
4
|
+
const follow = (event) => {
|
|
5
|
+
if (event.defaultPrevented || event.button !== 0 || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
|
|
6
|
+
const link = event.target.closest('a[href^="#"]');
|
|
7
|
+
if (!link) return;
|
|
8
|
+
const drawer = navigation.closest('aside:popover-open');
|
|
9
|
+
drawer?.hidePopover();
|
|
10
|
+
const target = root.ownerDocument.getElementById(link.hash.slice(1));
|
|
11
|
+
target?.focus({ preventScroll: true });
|
|
12
|
+
};
|
|
13
|
+
navigation.addEventListener("click", follow);
|
|
14
|
+
return () => navigation.removeEventListener("click", follow);
|
|
15
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<link rel="component" href="@threadlabs/looma/components/ui-button/ui-button.html">
|
|
2
|
+
<link rel="component" href="@threadlabs/looma/components/ui-card/ui-card.html">
|
|
3
|
+
<link rel="component" href="@threadlabs/looma/components/ui-disclosure/ui-disclosure.html">
|
|
4
|
+
<link rel="component" href="@threadlabs/looma/components/ui-form-field/ui-form-field.html">
|
|
5
|
+
<link rel="component" href="@threadlabs/looma/components/ui-input/ui-input.html">
|
|
6
|
+
<link rel="component" href="@threadlabs/looma/components/ui-nav-item/ui-nav-item.html">
|
|
7
|
+
<link rel="component" href="@threadlabs/looma/components/ui-stack/ui-stack.html">
|
|
8
|
+
<link rel="component" href="@threadlabs/looma/components/ui-switcher/ui-switcher.html">
|
|
9
|
+
<link rel="component" href="@threadlabs/looma/components/ui-text/ui-text.html">
|
|
10
|
+
|
|
11
|
+
<ui-switcher data-block="list-detail" balance="narrow-start" threshold="sm" align="start">
|
|
12
|
+
<ui-card slot="start" padding="sm">
|
|
13
|
+
<ui-stack gap="s">
|
|
14
|
+
<div data-filter hidden>
|
|
15
|
+
<ui-stack gap="xs">
|
|
16
|
+
<ui-form-field>
|
|
17
|
+
<label slot="label" for="report-query">Filter field reports</label>
|
|
18
|
+
<ui-input id="report-query" type="search"></ui-input>
|
|
19
|
+
</ui-form-field>
|
|
20
|
+
<ui-text data-status size="sm" tone="secondary" role="status" aria-atomic="true"></ui-text>
|
|
21
|
+
</ui-stack>
|
|
22
|
+
</div>
|
|
23
|
+
<nav aria-label="Field reports" data-records>
|
|
24
|
+
<ui-stack gap="xs">
|
|
25
|
+
<ui-nav-item as="a" href="#report-north" current="location">North trail</ui-nav-item>
|
|
26
|
+
<ui-nav-item as="a" href="#report-south">South trail</ui-nav-item>
|
|
27
|
+
</ui-stack>
|
|
28
|
+
</nav>
|
|
29
|
+
<ui-button variant="ghost" data-clear hidden>Clear filter</ui-button>
|
|
30
|
+
</ui-stack>
|
|
31
|
+
</ui-card>
|
|
32
|
+
<ui-card slot="end" padding="sm" aria-label="Report detail">
|
|
33
|
+
<ui-stack gap="s" data-details>
|
|
34
|
+
<section aria-labelledby="report-north">
|
|
35
|
+
<ui-stack gap="s">
|
|
36
|
+
<ui-text as="h3" id="report-north" variant="heading" tabindex="-1">North trail</ui-text>
|
|
37
|
+
<ui-text as="p">The footbridge is open. The lower path is still muddy after rain.</ui-text>
|
|
38
|
+
<ui-disclosure summary="Source notes" density="compact">
|
|
39
|
+
<ui-text size="sm" tone="secondary">The trail crew checked the bridge and lower path on Tuesday morning.</ui-text>
|
|
40
|
+
</ui-disclosure>
|
|
41
|
+
</ui-stack>
|
|
42
|
+
</section>
|
|
43
|
+
<section aria-labelledby="report-south">
|
|
44
|
+
<ui-stack gap="s">
|
|
45
|
+
<ui-text as="h3" id="report-south" variant="heading" tabindex="-1">South trail</ui-text>
|
|
46
|
+
<ui-text as="p">The overlook is closed while the railing is repaired.</ui-text>
|
|
47
|
+
<ui-disclosure summary="Source notes" density="compact">
|
|
48
|
+
<ui-text size="sm" tone="secondary">The repair notice was posted by the trail crew at the overlook entrance.</ui-text>
|
|
49
|
+
</ui-disclosure>
|
|
50
|
+
</ui-stack>
|
|
51
|
+
</section>
|
|
52
|
+
</ui-stack>
|
|
53
|
+
</ui-card>
|
|
54
|
+
</ui-switcher>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export default function setup(root) {
|
|
2
|
+
const records = root.querySelector("[data-records]");
|
|
3
|
+
const details = root.querySelector("[data-details]");
|
|
4
|
+
const filter = root.querySelector("[data-filter]");
|
|
5
|
+
const query = filter.querySelector('input[type="search"]');
|
|
6
|
+
const status = filter.querySelector("[data-status]");
|
|
7
|
+
const clear = root.querySelector("[data-clear]");
|
|
8
|
+
const links = Array.from(records.querySelectorAll("a"));
|
|
9
|
+
const panels = new Map(Array.from(details.children, panel => [panel.getAttribute("aria-labelledby"), panel]));
|
|
10
|
+
const initial = panels.keys().next().value;
|
|
11
|
+
const show = (id, moveFocus) => {
|
|
12
|
+
const selected = panels.get(id);
|
|
13
|
+
if (!selected) return;
|
|
14
|
+
for (const panel of panels.values()) panel.hidden = panel !== selected;
|
|
15
|
+
for (const link of links) {
|
|
16
|
+
if (link.hash === `#${id}`) link.setAttribute("aria-current", "location");
|
|
17
|
+
else link.removeAttribute("aria-current");
|
|
18
|
+
}
|
|
19
|
+
if (moveFocus) selected.querySelector("h3").focus();
|
|
20
|
+
};
|
|
21
|
+
const view = root.ownerDocument.defaultView;
|
|
22
|
+
const sync = () => {
|
|
23
|
+
const fragment = view.location.hash.slice(1);
|
|
24
|
+
show(panels.has(fragment) ? fragment : initial, false);
|
|
25
|
+
};
|
|
26
|
+
const onClick = (event) => {
|
|
27
|
+
if (event.defaultPrevented || event.button !== 0 || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
|
|
28
|
+
const link = event.target.closest("a");
|
|
29
|
+
if (links.includes(link)) show(link.hash.slice(1), true);
|
|
30
|
+
};
|
|
31
|
+
const applyFilter = () => {
|
|
32
|
+
const term = query.value.trim().toLocaleLowerCase();
|
|
33
|
+
let count = 0;
|
|
34
|
+
for (const link of links) {
|
|
35
|
+
const matches = link.textContent.toLocaleLowerCase().includes(term);
|
|
36
|
+
link.hidden = !matches;
|
|
37
|
+
if (matches) count++;
|
|
38
|
+
}
|
|
39
|
+
records.hidden = count === 0;
|
|
40
|
+
clear.hidden = count !== 0;
|
|
41
|
+
status.textContent = count === 0 ? "No matching reports." : count === 1 ? "1 report" : `${count} reports`;
|
|
42
|
+
};
|
|
43
|
+
const clearFilter = () => {
|
|
44
|
+
query.value = "";
|
|
45
|
+
applyFilter();
|
|
46
|
+
query.focus();
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
sync();
|
|
50
|
+
filter.hidden = false;
|
|
51
|
+
applyFilter();
|
|
52
|
+
records.addEventListener("click", onClick);
|
|
53
|
+
query.addEventListener("input", applyFilter);
|
|
54
|
+
clear.addEventListener("click", clearFilter);
|
|
55
|
+
view.addEventListener("hashchange", sync);
|
|
56
|
+
return () => {
|
|
57
|
+
records.removeEventListener("click", onClick);
|
|
58
|
+
query.removeEventListener("input", applyFilter);
|
|
59
|
+
clear.removeEventListener("click", clearFilter);
|
|
60
|
+
view.removeEventListener("hashchange", sync);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<link rel="component" href="@threadlabs/looma/components/ui-button/ui-button.html">
|
|
2
|
+
<link rel="component" href="@threadlabs/looma/components/ui-card/ui-card.html">
|
|
3
|
+
<link rel="component" href="@threadlabs/looma/components/ui-input/ui-input.html">
|
|
4
|
+
<link rel="component" href="@threadlabs/looma/components/ui-search-result-row/ui-search-result-row.html">
|
|
5
|
+
<link rel="component" href="@threadlabs/looma/components/ui-search-shell/ui-search-shell.html">
|
|
6
|
+
<link rel="component" href="@threadlabs/looma/components/ui-stack/ui-stack.html">
|
|
7
|
+
<link rel="component" href="@threadlabs/looma/components/ui-text/ui-text.html">
|
|
8
|
+
|
|
9
|
+
<ui-card data-block="search-and-open" padding="sm" aria-label="Search and open example">
|
|
10
|
+
<ui-stack gap="s" align="start">
|
|
11
|
+
<ui-button data-trigger>Find a field guide</ui-button>
|
|
12
|
+
<section aria-label="Open field guide">
|
|
13
|
+
<ui-text as="h3" variant="heading" tabindex="-1" data-heading><span data-title>Trail access</span></ui-text>
|
|
14
|
+
<ui-text as="p"><span data-detail>Check the latest access notes before choosing a route.</span></ui-text>
|
|
15
|
+
</section>
|
|
16
|
+
</ui-stack>
|
|
17
|
+
<ui-search-shell data-shell modal dismissible label="Find a field guide">
|
|
18
|
+
<ui-input slot="search" data-query type="search" aria-label="Filter field guides" placeholder="Search guides" autofocus></ui-input>
|
|
19
|
+
<output slot="status" data-status aria-live="polite">3 guides</output>
|
|
20
|
+
<ui-search-result-row slot="body" data-guide="trail">
|
|
21
|
+
<span slot="title">Trail access</span>
|
|
22
|
+
<span slot="excerpt">Routes and recent closures</span>
|
|
23
|
+
</ui-search-result-row>
|
|
24
|
+
<ui-search-result-row slot="body" data-guide="coast">
|
|
25
|
+
<span slot="title">Coastal conditions</span>
|
|
26
|
+
<span slot="excerpt">Tides and wind</span>
|
|
27
|
+
</ui-search-result-row>
|
|
28
|
+
<ui-search-result-row slot="body" data-guide="equipment">
|
|
29
|
+
<span slot="title">Equipment checklist</span>
|
|
30
|
+
<span slot="excerpt">Tools and supplies</span>
|
|
31
|
+
</ui-search-result-row>
|
|
32
|
+
</ui-search-shell>
|
|
33
|
+
</ui-card>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { componentRegistry } from "@nextwebwg/html-next/runtime";
|
|
2
|
+
import { deferredFocus } from "@threadlabs/looma/behaviors";
|
|
3
|
+
|
|
4
|
+
const guides = new Map([
|
|
5
|
+
["trail", ["Trail access", "Check the latest access notes before choosing a route."]],
|
|
6
|
+
["coast", ["Coastal conditions", "Check the tide window before descending to the shore."]],
|
|
7
|
+
["equipment", ["Equipment checklist", "Take a headlamp, a first-aid kit, and drinking water."]],
|
|
8
|
+
]);
|
|
9
|
+
|
|
10
|
+
export default function setup(root) {
|
|
11
|
+
const trigger = root.querySelector("[data-trigger]");
|
|
12
|
+
const shell = root.querySelector("[data-shell]");
|
|
13
|
+
const query = root.querySelector("[data-query]");
|
|
14
|
+
const status = root.querySelector("[data-status]");
|
|
15
|
+
const heading = root.querySelector("[data-heading]");
|
|
16
|
+
const title = root.querySelector("[data-title]");
|
|
17
|
+
const detail = root.querySelector("[data-detail]");
|
|
18
|
+
const focus = deferredFocus(root.ownerDocument.defaultView);
|
|
19
|
+
const close = () => componentRegistry.update(shell, { open: false });
|
|
20
|
+
const filter = () => {
|
|
21
|
+
const term = query.value.trim().toLocaleLowerCase();
|
|
22
|
+
let visible = 0;
|
|
23
|
+
for (const row of shell.querySelectorAll("[data-guide]")) {
|
|
24
|
+
row.hidden = !row.textContent.toLocaleLowerCase().includes(term);
|
|
25
|
+
if (!row.hidden) visible++;
|
|
26
|
+
}
|
|
27
|
+
status.textContent = visible === 0 ? "No matching guides" : `${visible} guide${visible === 1 ? "" : "s"}`;
|
|
28
|
+
};
|
|
29
|
+
const open = () => {
|
|
30
|
+
filter();
|
|
31
|
+
componentRegistry.update(shell, { open: true });
|
|
32
|
+
};
|
|
33
|
+
const choose = (event) => {
|
|
34
|
+
const row = event.target.closest("[data-guide]");
|
|
35
|
+
if (!row || row.hidden) return;
|
|
36
|
+
const guide = guides.get(row.dataset.guide);
|
|
37
|
+
if (!guide) return;
|
|
38
|
+
[title.textContent, detail.textContent] = guide;
|
|
39
|
+
close();
|
|
40
|
+
focus.schedule(() => heading.focus());
|
|
41
|
+
};
|
|
42
|
+
trigger.addEventListener("click", open);
|
|
43
|
+
shell.addEventListener("close", close);
|
|
44
|
+
shell.addEventListener("click", choose);
|
|
45
|
+
query.addEventListener("input", filter);
|
|
46
|
+
return () => {
|
|
47
|
+
trigger.removeEventListener("click", open);
|
|
48
|
+
shell.removeEventListener("close", close);
|
|
49
|
+
shell.removeEventListener("click", choose);
|
|
50
|
+
query.removeEventListener("input", filter);
|
|
51
|
+
focus.cancel();
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<link rel="component" href="@threadlabs/looma/components/ui-action-bar/ui-action-bar.html">
|
|
2
|
+
<link rel="component" href="@threadlabs/looma/components/ui-button/ui-button.html">
|
|
3
|
+
<link rel="component" href="@threadlabs/looma/components/ui-checkbox/ui-checkbox.html">
|
|
4
|
+
<link rel="component" href="@threadlabs/looma/components/ui-container/ui-container.html">
|
|
5
|
+
<link rel="component" href="@threadlabs/looma/components/ui-form-field/ui-form-field.html">
|
|
6
|
+
<link rel="component" href="@threadlabs/looma/components/ui-input/ui-input.html">
|
|
7
|
+
<link rel="component" href="@threadlabs/looma/components/ui-stack/ui-stack.html">
|
|
8
|
+
<link rel="component" href="@threadlabs/looma/components/ui-text/ui-text.html">
|
|
9
|
+
|
|
10
|
+
<form data-block="settings-form" aria-label="Report preferences">
|
|
11
|
+
<ui-container gutters="s">
|
|
12
|
+
<ui-stack gap="m">
|
|
13
|
+
<ui-text as="h3" variant="heading">Report preferences</ui-text>
|
|
14
|
+
<ui-form-field required>
|
|
15
|
+
<label slot="label" for="settings-display-name">Display name</label>
|
|
16
|
+
<ui-input id="settings-display-name" name="displayName" value="Field team" required></ui-input>
|
|
17
|
+
</ui-form-field>
|
|
18
|
+
<ui-checkbox name="summary">Include a weekly summary</ui-checkbox>
|
|
19
|
+
<ui-action-bar>
|
|
20
|
+
<ui-button slot="tertiary" type="reset" variant="ghost">Reset</ui-button>
|
|
21
|
+
<ui-button slot="primary" type="submit" preset="primary">Save preferences</ui-button>
|
|
22
|
+
</ui-action-bar>
|
|
23
|
+
<output aria-live="polite" data-message></output>
|
|
24
|
+
</ui-stack>
|
|
25
|
+
</ui-container>
|
|
26
|
+
</form>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export default function setup(root) {
|
|
2
|
+
const form = root;
|
|
3
|
+
const message = form.querySelector("[data-message]");
|
|
4
|
+
const submit = (event) => {
|
|
5
|
+
event.preventDefault();
|
|
6
|
+
const values = new FormData(form);
|
|
7
|
+
message.textContent = `Preview updated for ${values.get("displayName")}.`;
|
|
8
|
+
};
|
|
9
|
+
const reset = () => { message.textContent = ""; };
|
|
10
|
+
form.addEventListener("submit", submit);
|
|
11
|
+
form.addEventListener("reset", reset);
|
|
12
|
+
return () => {
|
|
13
|
+
form.removeEventListener("submit", submit);
|
|
14
|
+
form.removeEventListener("reset", reset);
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Return the original indices of enabled options, in their authored order.
|
|
2
|
+
* @param {ReadonlyArray<{ disabled?: boolean }>} options
|
|
3
|
+
* @contract Recompute when the option order or disabled state changes.
|
|
4
|
+
*/
|
|
5
|
+
export function enabledOptionIndices(options: ReadonlyArray<{
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
}>): number[];
|
|
8
|
+
/** Resolve a navigation key to a source index, or -1 when the collection or key has no destination.
|
|
9
|
+
* @param {readonly number[]} indices Eligible source indices in navigation order.
|
|
10
|
+
* @param {number} active Active source index, or -1 if no option is active.
|
|
11
|
+
* @param {string} key A collection navigation key.
|
|
12
|
+
* @param {{ wrap?: boolean }} [options] Wrap across edges when selected; otherwise clamp.
|
|
13
|
+
* @ownership The caller applies focus, updates active state, and decides whether to commit.
|
|
14
|
+
*/
|
|
15
|
+
export function nextActiveIndex(indices: readonly number[], active: number, key: string, { wrap }?: {
|
|
16
|
+
wrap?: boolean;
|
|
17
|
+
}): number;
|
|
18
|
+
/** Move through an already filtered collection without allocating an index array.
|
|
19
|
+
* @param {number} length Number of eligible items.
|
|
20
|
+
* @param {number} current Position in the eligible collection, or -1.
|
|
21
|
+
* @param {string} key A collection navigation key.
|
|
22
|
+
* @param {boolean} wrap Whether to wrap at either edge.
|
|
23
|
+
*/
|
|
24
|
+
export function nextCollectionPosition(length: number, current: number, key: string, wrap: boolean): number;
|
|
25
|
+
/** Keys used by vertical collection navigation. Horizontal widgets translate their arrow keys.
|
|
26
|
+
* @type {readonly string[]}
|
|
27
|
+
*/
|
|
28
|
+
export const collectionNavigationKeys: readonly string[];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Keys used by vertical collection navigation. Horizontal widgets translate their arrow keys.
|
|
2
|
+
* @type {readonly string[]}
|
|
3
|
+
*/
|
|
4
|
+
export const collectionNavigationKeys = Object.freeze(["ArrowDown", "ArrowUp", "Home", "End"]);
|
|
5
|
+
|
|
6
|
+
/** Return the original indices of enabled options, in their authored order.
|
|
7
|
+
* @param {ReadonlyArray<{ disabled?: boolean }>} options
|
|
8
|
+
* @contract Recompute when the option order or disabled state changes.
|
|
9
|
+
*/
|
|
10
|
+
export function enabledOptionIndices(options) {
|
|
11
|
+
return options.flatMap((option, index) => option.disabled ? [] : [index]);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Resolve a navigation key to a source index, or -1 when the collection or key has no destination.
|
|
15
|
+
* @param {readonly number[]} indices Eligible source indices in navigation order.
|
|
16
|
+
* @param {number} active Active source index, or -1 if no option is active.
|
|
17
|
+
* @param {string} key A collection navigation key.
|
|
18
|
+
* @param {{ wrap?: boolean }} [options] Wrap across edges when selected; otherwise clamp.
|
|
19
|
+
* @ownership The caller applies focus, updates active state, and decides whether to commit.
|
|
20
|
+
*/
|
|
21
|
+
export function nextActiveIndex(indices, active, key, { wrap = false } = {}) {
|
|
22
|
+
const next = nextCollectionPosition(indices.length, indices.indexOf(active), key, wrap);
|
|
23
|
+
return indices[next] ?? -1;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Move through an already filtered collection without allocating an index array.
|
|
27
|
+
* @param {number} length Number of eligible items.
|
|
28
|
+
* @param {number} current Position in the eligible collection, or -1.
|
|
29
|
+
* @param {string} key A collection navigation key.
|
|
30
|
+
* @param {boolean} wrap Whether to wrap at either edge.
|
|
31
|
+
*/
|
|
32
|
+
export function nextCollectionPosition(length, current, key, wrap) {
|
|
33
|
+
const last = length - 1;
|
|
34
|
+
if (last < 0) return -1;
|
|
35
|
+
if (key === "Home") return 0;
|
|
36
|
+
if (key === "End") return last;
|
|
37
|
+
if (key === "ArrowDown") return current === last && wrap ? 0 : Math.min(current + 1, last);
|
|
38
|
+
if (key === "ArrowUp") return current < 0 || (current === 0 && wrap) ? last : Math.max(current - 1, 0);
|
|
39
|
+
return -1;
|
|
40
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Allow only the latest focus request to run after rendering.
|
|
2
|
+
* @param {Pick<Window, "requestAnimationFrame" | "cancelAnimationFrame">} view Window that owns the control.
|
|
3
|
+
* @lifecycle Call the returned cancel function when disconnecting the owner.
|
|
4
|
+
*/
|
|
5
|
+
export function deferredFocus(view: Pick<Window, "requestAnimationFrame" | "cancelAnimationFrame">): {
|
|
6
|
+
schedule: (focus: () => void) => void;
|
|
7
|
+
cancel: () => void;
|
|
8
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Allow only the latest focus request to run after rendering.
|
|
2
|
+
* @param {Pick<Window, "requestAnimationFrame" | "cancelAnimationFrame">} view Window that owns the control.
|
|
3
|
+
* @lifecycle Call the returned cancel function when disconnecting the owner.
|
|
4
|
+
*/
|
|
5
|
+
export function deferredFocus(view) {
|
|
6
|
+
/** @type {number | undefined} */
|
|
7
|
+
let frame;
|
|
8
|
+
const cancel = () => {
|
|
9
|
+
if (frame !== undefined) view.cancelAnimationFrame(frame);
|
|
10
|
+
frame = undefined;
|
|
11
|
+
};
|
|
12
|
+
/** @param {() => void} focus */
|
|
13
|
+
const schedule = (focus) => {
|
|
14
|
+
cancel();
|
|
15
|
+
frame = view.requestAnimationFrame(() => {
|
|
16
|
+
frame = undefined;
|
|
17
|
+
focus();
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
return { schedule, cancel };
|
|
21
|
+
}
|
|
@@ -8,14 +8,22 @@
|
|
|
8
8
|
* @lifecycle Returns the function that stops listening.
|
|
9
9
|
*/
|
|
10
10
|
export function afterFormReset(control, callback) {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
// Reset bubbles within a tree but does not cross a shadow boundary.
|
|
12
|
+
const tree = control.getRootNode();
|
|
13
|
+
const root = tree.host ? tree : control.ownerDocument;
|
|
14
|
+
const pending = new Set();
|
|
13
15
|
const onReset = (event) => {
|
|
14
|
-
if (event.target
|
|
16
|
+
if (event.target !== control.form) return;
|
|
17
|
+
const timer = setTimeout(() => {
|
|
18
|
+
pending.delete(timer);
|
|
19
|
+
if (!event.defaultPrevented) callback();
|
|
20
|
+
});
|
|
21
|
+
pending.add(timer);
|
|
15
22
|
};
|
|
16
|
-
|
|
23
|
+
root.addEventListener("reset", onReset, { capture: true });
|
|
17
24
|
return () => {
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
root.removeEventListener("reset", onReset, { capture: true });
|
|
26
|
+
for (const timer of pending) clearTimeout(timer);
|
|
27
|
+
pending.clear();
|
|
20
28
|
};
|
|
21
29
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { focusAndRevealItem } from "./active-item-reveal.js";
|
|
2
|
+
import { collectionNavigationKeys, nextCollectionPosition } from "./collection-navigation.js";
|
|
2
3
|
|
|
3
4
|
const itemSelector = '[role="menuitem"], [role="menuitemcheckbox"], [role="menuitemradio"]';
|
|
4
5
|
const searches = new WeakMap();
|
|
@@ -22,28 +23,24 @@ export function navigateMenu(event, menu) {
|
|
|
22
23
|
if (!items.length) return false;
|
|
23
24
|
const current = menuItemFrom(event.target);
|
|
24
25
|
const index = items.indexOf(current);
|
|
25
|
-
let next
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
44
|
-
next = find(query);
|
|
45
|
-
if (next < 0 && query.length > 1) next = find(event.key.toLocaleLowerCase());
|
|
46
|
-
}
|
|
26
|
+
let next;
|
|
27
|
+
if (collectionNavigationKeys.includes(event.key)) {
|
|
28
|
+
next = nextCollectionPosition(items.length, index, event.key, true);
|
|
29
|
+
} else {
|
|
30
|
+
if (event.key.length !== 1 || event.key === " " || event.altKey || event.ctrlKey || event.metaKey) return false;
|
|
31
|
+
const now = Date.now();
|
|
32
|
+
const previous = searches.get(menu);
|
|
33
|
+
const query = `${previous && now - previous.time < 700 ? previous.query : ""}${event.key.toLocaleLowerCase()}`;
|
|
34
|
+
searches.set(menu, { query, time: now });
|
|
35
|
+
const find = (prefix) => {
|
|
36
|
+
for (let offset = 1; offset <= items.length; offset += 1) {
|
|
37
|
+
const candidate = (index + offset + items.length) % items.length;
|
|
38
|
+
if (label(items[candidate]).startsWith(prefix)) return candidate;
|
|
39
|
+
}
|
|
40
|
+
return -1;
|
|
41
|
+
};
|
|
42
|
+
next = find(query);
|
|
43
|
+
if (next < 0 && query.length > 1) next = find(event.key.toLocaleLowerCase());
|
|
47
44
|
}
|
|
48
45
|
event.preventDefault();
|
|
49
46
|
if (next >= 0) focusAndRevealItem(menu, items[next]);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// A blocked top overlay still owns the request. The overlay beneath it must stay open.
|
|
2
|
+
export function overlayDismissalTarget(records, reason) {
|
|
3
|
+
const top = records.at(-1);
|
|
4
|
+
if (!top) return undefined;
|
|
5
|
+
if (top.dismissible === false && (reason === "escape" || reason === "light-dismiss")) return undefined;
|
|
6
|
+
return top.canClose?.(reason) === false ? undefined : top;
|
|
7
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { updateSurfaceMaterial } from "./surface-material.js";
|
|
2
|
+
import { overlayDismissalTarget } from "./overlay-dismissal.js";
|
|
2
3
|
|
|
3
4
|
const dialogInvokers = new WeakMap();
|
|
4
5
|
|
|
@@ -25,8 +26,8 @@ function syncModalBackdrops(state) {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
function requestClose(document, reason, trigger) {
|
|
28
|
-
const record = stateFor(document).records
|
|
29
|
-
if (!record
|
|
29
|
+
const record = overlayDismissalTarget(stateFor(document).records, reason);
|
|
30
|
+
if (!record) return false;
|
|
30
31
|
record.requestClose(reason, trigger);
|
|
31
32
|
return true;
|
|
32
33
|
}
|
|
@@ -226,6 +226,7 @@
|
|
|
226
226
|
background-color: var(--ui-button-surface, oklch(from var(--_tone) l c h / calc(5% * var(--ui-tonal-opacity, 1))));
|
|
227
227
|
color: var(--ui-button-text, var(--_tone-text));
|
|
228
228
|
font: inherit;
|
|
229
|
+
font-size: var(--ui-font-size-sm);
|
|
229
230
|
font-weight: var(--ui-font-medium);
|
|
230
231
|
text-decoration: none;
|
|
231
232
|
/* Unset, a button wraps as its container does. */
|
|
@@ -604,10 +604,11 @@
|
|
|
604
604
|
min-inline-size: 0;
|
|
605
605
|
color: var(--ui-text-primary);
|
|
606
606
|
font: inherit;
|
|
607
|
+
font-size: var(--ui-font-size-sm);
|
|
607
608
|
}
|
|
608
609
|
label {
|
|
609
610
|
color: var(--_ui-combobox-label-text, var(--ui-text-primary));
|
|
610
|
-
font-size: var(--_ui-combobox-label-font-size, var(--ui-field-label-font-size, var(--ui-font-size-
|
|
611
|
+
font-size: var(--_ui-combobox-label-font-size, var(--ui-field-label-font-size, var(--ui-font-size-sm)));
|
|
611
612
|
font-weight: 500;
|
|
612
613
|
}
|
|
613
614
|
/* The field and anything that annotates it sit on one row; the help button is beside the box,
|
|
@@ -839,7 +840,9 @@
|
|
|
839
840
|
white-space: nowrap;
|
|
840
841
|
}
|
|
841
842
|
@media (pointer: coarse) {
|
|
842
|
-
:host
|
|
843
|
+
:host input,
|
|
844
|
+
:host([size="sm"]) input,
|
|
845
|
+
:host([size="lg"]) input {
|
|
843
846
|
font-size: var(--ui-font-size-md);
|
|
844
847
|
}
|
|
845
848
|
}
|