@threadlabs/looma 0.53.8 → 0.53.10

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.
Files changed (40) hide show
  1. package/README.md +16 -0
  2. package/blocks/editor-workspace.html +53 -0
  3. package/blocks/editor-workspace.js +15 -0
  4. package/blocks/list-detail.html +54 -0
  5. package/blocks/list-detail.js +62 -0
  6. package/blocks/search-and-open.html +33 -0
  7. package/blocks/search-and-open.js +53 -0
  8. package/blocks/settings-form.html +26 -0
  9. package/blocks/settings-form.js +16 -0
  10. package/components/shared/behaviors.d.ts +2 -0
  11. package/components/shared/behaviors.js +2 -0
  12. package/components/shared/collection-navigation.d.ts +28 -0
  13. package/components/shared/collection-navigation.js +40 -0
  14. package/components/shared/deferred-focus.d.ts +8 -0
  15. package/components/shared/deferred-focus.js +21 -0
  16. package/components/shared/form-reset.js +14 -6
  17. package/components/shared/menu-navigation.js +19 -22
  18. package/components/shared/overlay-dismissal.js +7 -0
  19. package/components/shared/overlay.js +3 -2
  20. package/components/ui-combobox/ui-combobox.js +6 -6
  21. package/components/ui-date-picker/ui-date-picker.js +5 -6
  22. package/components/ui-date-range-picker/ui-date-range-picker.js +6 -8
  23. package/components/ui-editor-toolbar/ui-editor-toolbar.js +8 -6
  24. package/components/ui-listbox/ui-listbox.js +10 -16
  25. package/components/ui-search-shell/ui-search-shell.js +4 -5
  26. package/components/ui-sidebar/ui-sidebar.html +7 -0
  27. package/components/ui-switcher/ui-switcher.html +28 -1
  28. package/components/ui-tabs/ui-tabs.js +5 -3
  29. package/dist/index.js +1 -1
  30. package/docs/catalog.json +49 -4
  31. package/editor/chunks/expressmark.js +43 -12
  32. package/editor/chunks/extensions.js +15 -2
  33. package/editor/extensions/index.js +1 -1
  34. package/editor/heading-alignment.d.ts +2 -0
  35. package/editor/index.js +78 -44
  36. package/package.json +9 -2
  37. package/styles/ui-sidebar.css +12 -1
  38. package/styles/ui-switcher.css +22 -1
  39. package/vanilla/UiSwitcher.d.ts +2 -1
  40. package/vanilla/UiSwitcher.js +96 -16
@@ -6,6 +6,7 @@ import { afterFormReset } from "../shared/form-reset.js";
6
6
  import { externalValueTracker } from "../shared/external-value.js";
7
7
  import { readOptionalInput } from "../shared/binding-inputs.js";
8
8
  import { initialFieldValue } from "../shared/initial-field-value.js";
9
+ import { deferredFocus } from "../shared/deferred-focus.js";
9
10
 
10
11
  const optionNames = ["type", "valueFormat", "timeZone", "disambiguation", "min", "max", "allowedDates", "allowedRanges", "disabledDates", "disabledRanges", "disabledWeekdays"];
11
12
 
@@ -22,7 +23,7 @@ function interactions(host) {
22
23
  let current = host.state.current ?? host.props.value.value ?? "";
23
24
  const externalChanged = externalValueTracker(element, { initialValue: host.props.value.value });
24
25
  let connected = true;
25
- let frame;
26
+ const focus = deferredFocus(element.ownerDocument.defaultView);
26
27
  const settings = () => Object.fromEntries(optionNames.map(name => [name, host.props[name].value]));
27
28
  const initial = initialFieldValue(field, { ...settings(), locale: host.props.locale.value });
28
29
  try {
@@ -34,8 +35,7 @@ function interactions(host) {
34
35
  const close = restore => {
35
36
  host.state.opened = false; host.state.error = "";
36
37
  if (restore) {
37
- cancelAnimationFrame(frame);
38
- frame = requestAnimationFrame(() => { if (connected) trigger.focus(); });
38
+ focus.schedule(() => trigger.focus());
39
39
  }
40
40
  };
41
41
  const seed = () => {
@@ -60,8 +60,7 @@ function interactions(host) {
60
60
  queueMicrotask(() => {
61
61
  if (connected && host.state.opened && element.ownerDocument.activeElement !== clock) time.dispatchEvent(new CustomEvent("set-value", { cancelable: true, detail: { value: host.state.draftTime } }));
62
62
  });
63
- cancelAnimationFrame(frame);
64
- frame = requestAnimationFrame(() => {
63
+ focus.schedule(() => {
65
64
  if (!connected || !host.state.opened || popover.contains(element.ownerDocument.activeElement)) return;
66
65
  const date = host.state.draftDate || host.props.today.value;
67
66
  if (date) calendar.dispatchEvent(new CustomEvent("focus-date", { detail: { value: date } }));
@@ -122,7 +121,7 @@ function interactions(host) {
122
121
  });
123
122
  const reset = afterFormReset(control, () => { current = host.props.value.value ?? ""; host.state.current = current; close(); });
124
123
  return () => {
125
- connected = false; cancelAnimationFrame(frame); observer.disconnect(); stop(); reset(); close(); host.state.enhanced = false;
124
+ connected = false; focus.cancel(); observer.disconnect(); stop(); reset(); close(); host.state.enhanced = false;
126
125
  for (const name of fieldEvents) field.removeEventListener(name, relay);
127
126
  for (const name of ["open", "close"]) popover.removeEventListener(name, overlay);
128
127
  for (const name of fieldEvents) popover.removeEventListener(name, draft);
@@ -6,6 +6,7 @@ import { afterFormReset } from "../shared/form-reset.js";
6
6
  import { externalValueTracker } from "../shared/external-value.js";
7
7
  import { readOptionalInput } from "../shared/binding-inputs.js";
8
8
  import { initialFieldValue } from "../shared/initial-field-value.js";
9
+ import { deferredFocus } from "../shared/deferred-focus.js";
9
10
 
10
11
  const ruleNames = ["min", "max", "allowedDates", "allowedRanges", "disabledDates", "disabledRanges", "disabledWeekdays"];
11
12
  const endpoints = ["start", "end"];
@@ -24,9 +25,8 @@ function interactions(host) {
24
25
  let current = copy(host.state.current ?? host.props.value.value);
25
26
  const externalChanged = externalValueTracker(element, { initialValue: signature(copy(host.props.value.value)) });
26
27
  let committed = signature(current);
27
- let connected = true;
28
28
  let setting = false;
29
- let frame;
29
+ const focus = deferredFocus(element.ownerDocument.defaultView);
30
30
  let lastTrigger = "keyboard";
31
31
  const settings = () => Object.fromEntries(ruleNames.map(name => [name, host.props[name].value]));
32
32
  const allowed = range => isRangeAllowed(range, compileDateRules(settings()), host.props.allowUnavailableWithinRange.value);
@@ -63,8 +63,7 @@ function interactions(host) {
63
63
  host.state.opened = false; host.state.anchor = ""; host.state.error = "";
64
64
  if (wasOpen) host.dispatch("close", { open: false, reason, trigger });
65
65
  if (restore) {
66
- cancelAnimationFrame(frame);
67
- frame = requestAnimationFrame(() => { if (connected) element.ownerDocument.getElementById(host.state.activeAnchor)?.focus(); });
66
+ focus.schedule(() => element.ownerDocument.getElementById(host.state.activeAnchor)?.focus());
68
67
  }
69
68
  };
70
69
  const replaceFields = range => {
@@ -119,9 +118,8 @@ function interactions(host) {
119
118
  host.state.anchor = ""; host.state.popupValue = range[name] || range.start || range.end || "";
120
119
  host.state.activeAnchor = anchorId; host.state.error = ""; host.state.opened = true;
121
120
  host.dispatch("open", { open: true, reason: "action", trigger });
122
- cancelAnimationFrame(frame);
123
- frame = requestAnimationFrame(() => {
124
- if (!connected || !host.state.opened) return;
121
+ focus.schedule(() => {
122
+ if (!host.state.opened) return;
125
123
  const date = host.state.popupValue || host.props.today.value;
126
124
  if (date) calendar.dispatchEvent(new CustomEvent("focus-date", { detail: { value: date } }));
127
125
  else calendar.querySelector('[data-calendar-day][tabindex="0"], [data-calendar-days][tabindex="0"]')?.focus();
@@ -193,7 +191,7 @@ function interactions(host) {
193
191
  accept(copy(host.props.value.value)); committed = signature(current); close(); replaceFields(current);
194
192
  });
195
193
  return () => {
196
- connected = false; cancelAnimationFrame(frame); observer.disconnect(); stop(); reset();
194
+ focus.cancel(); observer.disconnect(); stop(); reset();
197
195
  for (const release of listeners) release();
198
196
  host.state.opened = false; host.state.enhanced = false;
199
197
  };
@@ -1,3 +1,5 @@
1
+ import { nextCollectionPosition } from "../shared/collection-navigation.js";
2
+
1
3
  const selector = 'button, a[href], [role="button"], select, input:not([type="hidden"])';
2
4
 
3
5
  /** Keep one Tab stop in the toolbar; arrow keys move among its enabled authored controls. */
@@ -24,12 +26,12 @@ export function connect(host) {
24
26
  const index = items.indexOf(event.target.closest?.(selector));
25
27
  if (index < 0) return;
26
28
  const rtl = getComputedStyle(strip).direction === "rtl";
27
- let next;
28
- if (event.key === "ArrowRight") next = (index + (rtl ? -1 : 1) + items.length) % items.length;
29
- else if (event.key === "ArrowLeft") next = (index + (rtl ? 1 : -1) + items.length) % items.length;
30
- else if (event.key === "Home") next = 0;
31
- else if (event.key === "End") next = items.length - 1;
32
- else return;
29
+ if (event.key === "ArrowUp" || event.key === "ArrowDown") return;
30
+ const previousKey = rtl ? "ArrowRight" : "ArrowLeft";
31
+ const nextKey = rtl ? "ArrowLeft" : "ArrowRight";
32
+ const key = event.key === previousKey ? "ArrowUp" : event.key === nextKey ? "ArrowDown" : event.key;
33
+ const next = nextCollectionPosition(items.length, index, key, true);
34
+ if (next < 0) return;
33
35
  event.preventDefault();
34
36
  items[next]?.focus();
35
37
  };
@@ -1,4 +1,6 @@
1
1
  import { cancelActiveItemReveal, revealActiveItem } from "../shared/active-item-reveal.js";
2
+ import { collectionNavigationKeys, enabledOptionIndices, nextActiveIndex } from "../shared/collection-navigation.js";
3
+ import { afterFormReset } from "../shared/form-reset.js";
2
4
  let nextId = 0;
3
5
 
4
6
  const same = (left, right) => JSON.stringify(left) === JSON.stringify(right);
@@ -17,7 +19,6 @@ function readOptions(container) {
17
19
  export function connect(host) {
18
20
  const element = host.element;
19
21
  const { options: authored, validity } = host.refs;
20
- const form = element.closest("form");
21
22
  host.state.uid = `ui-listbox-${++nextId}`;
22
23
  if (element.id && !element.hasAttribute("aria-label") && !element.hasAttribute("aria-labelledby")) {
23
24
  const label = Array.from(element.ownerDocument.querySelectorAll("label[for]")).find((candidate) => candidate.htmlFor === element.id);
@@ -39,7 +40,6 @@ export function connect(host) {
39
40
  : (host.props.value.value === undefined || host.props.value.value === null ? null : [String(host.props.value.value)]);
40
41
  const defaultSelection = () => externallySelected()
41
42
  ?? options.filter((option) => option.selected).map((option) => option.value).slice(0, host.props.multiple.value ? undefined : 1);
42
- const enabledIndices = () => options.filter((option) => !option.disabled).map((option) => option.index);
43
43
  const render = () => {
44
44
  const set = new Set(selected());
45
45
  const rows = options.map((option) => ({
@@ -94,15 +94,10 @@ export function connect(host) {
94
94
  } else setSelection([option.value], trigger);
95
95
  };
96
96
  const move = (key) => {
97
- const indices = enabledIndices();
98
- if (!indices.length) return;
99
- const current = indices.indexOf(host.state.active);
100
- const next = key === "Home" ? indices[0]
101
- : key === "End" ? indices[indices.length - 1]
102
- : key === "ArrowDown" ? indices[(current + 1) % indices.length]
103
- : indices[(current <= 0 ? indices.length : current) - 1];
104
- activate(next);
105
- if (!host.props.multiple.value) choose(next, "keyboard");
97
+ const next = nextActiveIndex(enabledOptionIndices(options), host.state.active, key, { wrap: true });
98
+ if (next < 0) return;
99
+ if (host.props.multiple.value) activate(next);
100
+ else choose(next, "keyboard");
106
101
  };
107
102
  const onClick = (event) => {
108
103
  if (host.props.disabled.value) return;
@@ -113,12 +108,12 @@ export function connect(host) {
113
108
  };
114
109
  const onKeydown = (event) => {
115
110
  if (host.props.disabled.value || event.altKey || event.metaKey || event.ctrlKey) return;
116
- if (["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) {
111
+ if (collectionNavigationKeys.includes(event.key)) {
117
112
  event.preventDefault();
118
113
  move(event.key);
119
114
  } else if (event.key === " " || event.key === "Enter") {
120
115
  event.preventDefault();
121
- choose(host.state.active >= 0 ? host.state.active : enabledIndices()[0], "keyboard");
116
+ choose(host.state.active >= 0 ? host.state.active : enabledOptionIndices(options)[0], "keyboard");
122
117
  } else if (event.key.length === 1 && !event.shiftKey) {
123
118
  typeahead += event.key.toLocaleLowerCase();
124
119
  clearTimeout(typeaheadTimer);
@@ -130,7 +125,7 @@ export function connect(host) {
130
125
  }
131
126
  }
132
127
  };
133
- const onReset = () => queueMicrotask(() => {
128
+ const stopReset = afterFormReset(validity, () => {
134
129
  setSelection(initial);
135
130
  host.state.validationError = false;
136
131
  });
@@ -156,7 +151,6 @@ export function connect(host) {
156
151
  });
157
152
  element.addEventListener("click", onClick);
158
153
  element.addEventListener("keydown", onKeydown);
159
- form?.addEventListener("reset", onReset);
160
154
  validity.addEventListener("invalid", onInvalid);
161
155
  return () => {
162
156
  cancelActiveItemReveal(element);
@@ -167,7 +161,7 @@ export function connect(host) {
167
161
  clearTimeout(typeaheadTimer);
168
162
  element.removeEventListener("click", onClick);
169
163
  element.removeEventListener("keydown", onKeydown);
170
- form?.removeEventListener("reset", onReset);
164
+ stopReset();
171
165
  validity.removeEventListener("invalid", onInvalid);
172
166
  };
173
167
  }
@@ -1,4 +1,5 @@
1
1
  import { cancelActiveItemReveal, focusAndRevealItem } from "../shared/active-item-reveal.js";
2
+ import { collectionNavigationKeys, nextCollectionPosition } from "../shared/collection-navigation.js";
2
3
  import { closeDialog, closeOverlay, openOverlay, showDialog } from "../shared/overlay.js";
3
4
  import { trackTrigger } from "../shared/trigger.js";
4
5
 
@@ -57,7 +58,7 @@ export function connect(host) {
57
58
  dispatchClose("escape", "keyboard");
58
59
  return;
59
60
  }
60
- if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) return;
61
+ if (!collectionNavigationKeys.includes(event.key)) return;
61
62
  const rows = resultRows();
62
63
  if (!rows.length) return;
63
64
  const target = event.target;
@@ -65,10 +66,8 @@ export function connect(host) {
65
66
  const index = rows.indexOf(target.closest?.(".body button[aria-current]"));
66
67
  if (!fromSearch && index < 0) return;
67
68
  event.preventDefault();
68
- if (event.key === "Home") focusAndRevealItem(dialog, rows[0]);
69
- else if (event.key === "End") focusAndRevealItem(dialog, rows.at(-1));
70
- else if (event.key === "ArrowDown") focusAndRevealItem(dialog, rows[fromSearch ? 0 : (index + 1) % rows.length]);
71
- else focusAndRevealItem(dialog, rows[fromSearch ? rows.length - 1 : (index - 1 + rows.length) % rows.length]);
69
+ const next = nextCollectionPosition(rows.length, fromSearch ? -1 : index, event.key, true);
70
+ focusAndRevealItem(dialog, rows[next]);
72
71
  };
73
72
  const onClick = (event) => {
74
73
  if (host.props.dismissible.value && event.target === dialog) dispatchClose("light-dismiss", trigger());
@@ -57,6 +57,13 @@
57
57
  transition: inline-size var(--ui-motion-layout) var(--ui-motion-layout-ease), visibility var(--ui-motion-layout);
58
58
  }
59
59
 
60
+ /* Without a drawer controller, keep navigation in flow and reserve most of the row for content. */
61
+ @media (scripting: none) {
62
+ :host {
63
+ max-inline-size: 33%;
64
+ }
65
+ }
66
+
60
67
  :host([side="end"]) {
61
68
  border-inline-end: 0;
62
69
  border-inline-start: var(--ui-border-width) solid var(--ui-sidebar-border, var(--ui-border-divider));
@@ -11,9 +11,18 @@
11
11
  bottoms.</prop>
12
12
  <prop name="limit" type="integer"
13
13
  >Most children allowed in a horizontal row. When the count exceeds this value, every child stacks regardless of width. Omit it for no count limit.</prop>
14
+ <prop name="balance" type="keyword" values="equal, narrow-start, narrow-end" default="equal"
15
+ >Use the start and end slots to give one pane about a third of the row for a rail or inspector. At the same threshold, the start pane stacks above the end
16
+ pane. Equal uses the default slot and gives children the same width.</prop>
14
17
  <state type="boolean" name="overLimit" value="false"></state>
15
18
  </defs>
16
- <div><slot></slot></div>
19
+ <template $match>
20
+ <div $when="$balance = 'equal'"><slot></slot></div>
21
+ <div $else>
22
+ <div class="start"><slot name="start"></slot></div>
23
+ <div class="end"><slot name="end"></slot></div>
24
+ </div>
25
+ </template>
17
26
  <style>
18
27
  :host {
19
28
  --_switcher-gap: var(--ui-space-4);
@@ -34,6 +43,24 @@
34
43
  grid-template-columns: minmax(0, 1fr);
35
44
  }
36
45
 
46
+ /* Reuse the width threshold as the flex basis. Below it, each full-width item
47
+ gets its own line. Above it, grow factors divide the available space. */
48
+ :host(:is([balance="narrow-start"], [balance="narrow-end"]):not(:state(overLimit))):not([hidden]) {
49
+ display: flex !important;
50
+ flex-flow: row wrap !important;
51
+ }
52
+
53
+ .start,
54
+ .end {
55
+ flex: 2 1 var(--_switcher-track) !important;
56
+ min-inline-size: 0;
57
+ }
58
+
59
+ :host([balance="narrow-start"]) > .start,
60
+ :host([balance="narrow-end"]) > .end {
61
+ flex-grow: 1 !important;
62
+ }
63
+
37
64
  :host([gap="xs"]) {
38
65
  --_switcher-gap: var(--ui-space-2);
39
66
  }
@@ -1,4 +1,5 @@
1
1
  import { trackTrigger } from "../shared/trigger.js";
2
+ import { nextCollectionPosition } from "../shared/collection-navigation.js";
2
3
 
3
4
  let panelIds = 0;
4
5
  const GROUP_EVENT = "looma-tabs-group";
@@ -111,10 +112,11 @@ export function connect(host) {
111
112
  select(button, "keyboard");
112
113
  return;
113
114
  }
114
- if (event.key !== previousKey && event.key !== nextKey && event.key !== "Home" && event.key !== "End") return;
115
+ const key = event.key === previousKey ? "ArrowUp" : event.key === nextKey ? "ArrowDown" : event.key;
116
+ if (!vertical && (event.key === "ArrowUp" || event.key === "ArrowDown")) return;
117
+ const next = buttons[nextCollectionPosition(buttons.length, buttons.indexOf(button), key, true)];
118
+ if (!next) return;
115
119
  event.preventDefault();
116
- const index = buttons.indexOf(button);
117
- const next = event.key === "Home" ? buttons[0] : event.key === "End" ? buttons.at(-1) : buttons[(index + (event.key === nextKey ? 1 : buttons.length - 1)) % buttons.length];
118
120
  if (host.props.activation.value !== "manual") select(next, "keyboard");
119
121
  focusTab(next);
120
122
  };