loseta 0.16.0 → 0.18.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.
Files changed (138) hide show
  1. package/README.md +33 -8
  2. package/dist/commands/add.d.ts +8 -0
  3. package/dist/commands/add.js +60 -15
  4. package/dist/commands/add.js.map +1 -1
  5. package/dist/commands/init.js +2 -1
  6. package/dist/commands/init.js.map +1 -1
  7. package/dist/config.d.ts +7 -0
  8. package/dist/config.js +13 -0
  9. package/dist/config.js.map +1 -1
  10. package/dist/imports.d.ts +4 -0
  11. package/dist/imports.js +30 -2
  12. package/dist/imports.js.map +1 -1
  13. package/dist/install.d.ts +23 -3
  14. package/dist/install.js +84 -5
  15. package/dist/install.js.map +1 -1
  16. package/dist/style-switch.js +2 -1
  17. package/dist/style-switch.js.map +1 -1
  18. package/dist/types.d.ts +11 -0
  19. package/dist/ui.js +4 -1
  20. package/dist/ui.js.map +1 -1
  21. package/package.json +4 -3
  22. package/registry/behaviors/code-block.js +106 -0
  23. package/registry/behaviors/combobox.js +237 -0
  24. package/registry/behaviors/command.js +105 -0
  25. package/registry/behaviors/core.js +302 -0
  26. package/registry/behaviors/dialog.js +97 -0
  27. package/registry/behaviors/listbox.js +135 -0
  28. package/registry/behaviors/menu.js +586 -0
  29. package/registry/behaviors/popover.js +127 -0
  30. package/registry/behaviors/select.js +196 -0
  31. package/registry/behaviors/tabs.js +95 -0
  32. package/registry/behaviors/toast.js +137 -0
  33. package/registry/components/badge.css +4 -7
  34. package/registry/components/breadcrumb.css +9 -1
  35. package/registry/components/calendar.css +39 -0
  36. package/registry/components/card.css +5 -0
  37. package/registry/components/code-block.css +19 -0
  38. package/registry/components/input-otp.css +103 -10
  39. package/registry/components/kbd.css +8 -0
  40. package/registry/components/native-select.css +6 -0
  41. package/registry/components/select.css +3 -0
  42. package/registry/components/tooltip.css +295 -144
  43. package/registry/examples/alert-dialog.html +21 -21
  44. package/registry/examples/badge.html +37 -0
  45. package/registry/examples/breadcrumb.html +86 -6
  46. package/registry/examples/button-group.html +3 -3
  47. package/registry/examples/calendar.html +687 -51
  48. package/registry/examples/card.html +190 -4
  49. package/registry/examples/code-block.html +10 -4
  50. package/registry/examples/combobox.html +2 -0
  51. package/registry/examples/command.html +17 -17
  52. package/registry/examples/context-menu.html +18 -18
  53. package/registry/examples/dialog.html +15 -15
  54. package/registry/examples/drawer.html +22 -22
  55. package/registry/examples/input-otp.html +116 -11
  56. package/registry/examples/kbd.html +90 -2
  57. package/registry/examples/native-select.html +83 -2
  58. package/registry/examples/select.html +206 -6
  59. package/registry/examples/sheet.html +23 -23
  60. package/registry/examples/sidebar.html +11 -11
  61. package/registry/examples/toast.html +11 -0
  62. package/registry/examples/tooltip.html +75 -70
  63. package/registry/primitives/dialog-shell.css +5 -0
  64. package/registry/primitives/menu.css +15 -3
  65. package/registry/registry.json +231 -9
  66. package/registry/schema.json +17 -0
  67. package/registry/styles/luma/badge.css +28 -0
  68. package/registry/styles/luma/breadcrumb.css +2 -1
  69. package/registry/styles/luma/calendar.css +62 -0
  70. package/registry/styles/luma/card.css +9 -27
  71. package/registry/styles/luma/input-otp.css +79 -36
  72. package/registry/styles/luma/native-select.css +9 -2
  73. package/registry/styles/luma/primitives/listbox.css +8 -0
  74. package/registry/styles/luma/select.css +7 -2
  75. package/registry/styles/luma/tooltip.css +29 -16
  76. package/registry/styles/lyra/badge.css +28 -0
  77. package/registry/styles/lyra/breadcrumb.css +2 -1
  78. package/registry/styles/lyra/calendar.css +62 -0
  79. package/registry/styles/lyra/card.css +9 -27
  80. package/registry/styles/lyra/input-otp.css +79 -36
  81. package/registry/styles/lyra/native-select.css +6 -1
  82. package/registry/styles/lyra/primitives/listbox.css +8 -0
  83. package/registry/styles/lyra/select.css +6 -1
  84. package/registry/styles/lyra/tooltip.css +29 -16
  85. package/registry/styles/maia/badge.css +29 -0
  86. package/registry/styles/maia/breadcrumb.css +2 -1
  87. package/registry/styles/maia/calendar.css +62 -0
  88. package/registry/styles/maia/card.css +9 -27
  89. package/registry/styles/maia/input-otp.css +79 -36
  90. package/registry/styles/maia/native-select.css +9 -2
  91. package/registry/styles/maia/primitives/listbox.css +8 -0
  92. package/registry/styles/maia/select.css +7 -2
  93. package/registry/styles/maia/tooltip.css +29 -16
  94. package/registry/styles/mira/badge.css +32 -0
  95. package/registry/styles/mira/breadcrumb.css +2 -1
  96. package/registry/styles/mira/calendar.css +62 -0
  97. package/registry/styles/mira/card.css +9 -27
  98. package/registry/styles/mira/input-otp.css +79 -36
  99. package/registry/styles/mira/native-select.css +7 -2
  100. package/registry/styles/mira/primitives/listbox.css +8 -0
  101. package/registry/styles/mira/select.css +7 -2
  102. package/registry/styles/mira/tooltip.css +29 -16
  103. package/registry/styles/nova/badge.css +28 -0
  104. package/registry/styles/nova/breadcrumb.css +2 -1
  105. package/registry/styles/nova/calendar.css +62 -0
  106. package/registry/styles/nova/card.css +9 -27
  107. package/registry/styles/nova/input-otp.css +79 -36
  108. package/registry/styles/nova/native-select.css +9 -2
  109. package/registry/styles/nova/primitives/listbox.css +8 -0
  110. package/registry/styles/nova/select.css +7 -2
  111. package/registry/styles/nova/tooltip.css +29 -16
  112. package/registry/styles/rhea/badge.css +28 -0
  113. package/registry/styles/rhea/breadcrumb.css +2 -1
  114. package/registry/styles/rhea/calendar.css +62 -0
  115. package/registry/styles/rhea/card.css +9 -27
  116. package/registry/styles/rhea/input-otp.css +79 -36
  117. package/registry/styles/rhea/native-select.css +9 -2
  118. package/registry/styles/rhea/primitives/listbox.css +8 -0
  119. package/registry/styles/rhea/select.css +7 -2
  120. package/registry/styles/rhea/tooltip.css +29 -16
  121. package/registry/styles/sera/badge.css +29 -1
  122. package/registry/styles/sera/breadcrumb.css +2 -1
  123. package/registry/styles/sera/calendar.css +66 -0
  124. package/registry/styles/sera/card.css +9 -27
  125. package/registry/styles/sera/input-otp.css +80 -37
  126. package/registry/styles/sera/native-select.css +9 -2
  127. package/registry/styles/sera/primitives/listbox.css +8 -0
  128. package/registry/styles/sera/select.css +7 -2
  129. package/registry/styles/sera/tooltip.css +29 -16
  130. package/registry/styles/vega/badge.css +28 -0
  131. package/registry/styles/vega/breadcrumb.css +2 -1
  132. package/registry/styles/vega/calendar.css +62 -0
  133. package/registry/styles/vega/card.css +9 -27
  134. package/registry/styles/vega/input-otp.css +79 -36
  135. package/registry/styles/vega/native-select.css +9 -2
  136. package/registry/styles/vega/primitives/listbox.css +8 -0
  137. package/registry/styles/vega/select.css +7 -2
  138. package/registry/styles/vega/tooltip.css +29 -16
@@ -1 +1 @@
1
- {"version":3,"file":"style-switch.js","sourceRoot":"","sources":["../src/style-switch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAc7D;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAAkB,EAClB,QAAkB,EAClB,MAAoB,EACpB,IAAwB;IAExB,MAAM,SAAS,GAAG,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC5C,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO;YACL,MAAM,EAAE,OAAO;YACf,OAAO,EAAE,iDAAiD,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;SAClF,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC;QACjC,OAAO;YACL,MAAM,EAAE,OAAO;YACf,OAAO,EAAE,kBAAkB,IAAI,uBAAuB,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;SAC9E,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC;QAC1B,OAAO;YACL,MAAM,EAAE,MAAM;YACd,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L,MAAM,EAAE,QAAQ;QAChB,IAAI,EAAE;YACJ,QAAQ,EAAE,MAAM,CAAC,KAAK;YACtB,UAAU,EAAE,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE;YACtC,KAAK;SACN;KACF,CAAC;AACJ,CAAC;AAOD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,KAMtC;IACC,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC;QAChC,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,UAAU;QAC7B,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK;QACvB,gBAAgB,EAAE,KAAK;QACvB,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE;YACnB,IAAI,MAAM,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO;gBAAE,OAAO,WAAW,CAAC;YAChE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACvB,OAAO,MAAM,CAAC;QAChB,CAAC;KACF,CAAC,CAAC;IACH,WAAW,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACtD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAC1B,CAAC"}
package/dist/types.d.ts CHANGED
@@ -2,12 +2,20 @@ export type ItemType = "component" | "primitive" | "foundation" | "style";
2
2
  export type ItemStatus = "stable" | "experimental";
3
3
  export type FileRole = "base" | "style";
4
4
  export type LayerName = "loseta.tokens" | "loseta.reset" | "loseta.base" | "loseta.components" | "loseta.style" | "loseta.utilities";
5
+ export type BehaviorKind = "entry" | "support";
5
6
  export interface RegistryFile {
6
7
  path: string;
7
8
  target: string;
8
9
  role: FileRole;
9
10
  layer: LayerName;
10
11
  }
12
+ export interface RegistryBehavior {
13
+ path: string;
14
+ target: string;
15
+ kind: BehaviorKind;
16
+ }
17
+ /** A file copied by `add`, CSS or behavior. */
18
+ export type InstallableFile = RegistryFile | RegistryBehavior;
11
19
  export interface RegistryItem {
12
20
  name: string;
13
21
  type: ItemType;
@@ -19,6 +27,7 @@ export interface RegistryItem {
19
27
  registryDependencies?: string[];
20
28
  optionalDependencies?: string[];
21
29
  files: RegistryFile[];
30
+ behaviors?: RegistryBehavior[];
22
31
  examples?: string[];
23
32
  }
24
33
  export interface StyleDefinition {
@@ -36,6 +45,7 @@ export interface Registry {
36
45
  export interface LosetaConfig {
37
46
  $schema?: string;
38
47
  cssDir: string;
48
+ behaviorDir?: string;
39
49
  entrypoint?: string;
40
50
  style: string;
41
51
  }
@@ -51,4 +61,5 @@ export interface ManifestItem {
51
61
  export interface Manifest {
52
62
  version: string;
53
63
  items: ManifestItem[];
64
+ behaviors?: string[];
54
65
  }
package/dist/ui.js CHANGED
@@ -4,7 +4,10 @@ export function printItems(items) {
4
4
  for (const item of items) {
5
5
  const name = pc.cyan(item.name.padEnd(18));
6
6
  const kind = pc.dim(item.type.padEnd(11));
7
- console.log(`${name} ${kind} ${item.description}`);
7
+ const behavior = (item.behaviors ?? []).some((entry) => entry.kind === "entry")
8
+ ? pc.green("js")
9
+ : pc.dim(" ");
10
+ console.log(`${name} ${kind} ${behavior} ${item.description}`);
8
11
  }
9
12
  }
10
13
  /** Prints a one-line summary of installed item names. */
package/dist/ui.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ui.js","sourceRoot":"","sources":["../src/ui.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B,+CAA+C;AAC/C,MAAM,UAAU,UAAU,CAAC,KAAqB;IAC9C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;Q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CAAC,GAAG,CAAC,GAAG,IAAI,IAAI,IAAI,IAAI,QAAQ,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IACjE,CAAC;AACH,CAAC;AAED,yDAAyD;AACzD,MAAM,UAAU,gBAAgB,CAAC,KAAe;IAC9C,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACzD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loseta",
3
- "version": "0.16.0",
3
+ "version": "0.18.0",
4
4
  "description": "Native CSS component scaffolds with the shadcn feel.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -41,10 +41,11 @@
41
41
  "smoke": "bash scripts/smoke-init.sh",
42
42
  "validate": "node scripts/validate-registry.mjs",
43
43
  "examples": "tsx scripts/generate-examples.ts",
44
- "check": "pnpm build && pnpm validate",
44
+ "check": "pnpm build && pnpm validate && pnpm behaviors:check",
45
45
  "test": "tsx --test test/*.test.ts",
46
46
  "prepack": "pnpm build",
47
- "prepublishOnly": "pnpm validate"
47
+ "prepublishOnly": "pnpm validate",
48
+ "behaviors:check": "tsc -p tsconfig.behaviors.json"
48
49
  },
49
50
  "dependencies": {
50
51
  "@clack/prompts": "^1.8.1",
@@ -0,0 +1,106 @@
1
+ // @ts-check
2
+
3
+ import { init, on } from "./core.js";
4
+
5
+ const FEEDBACK_MS = 1500;
6
+
7
+ /** @type {WeakMap<HTMLElement, number>} */
8
+ const feedbackTimers = new WeakMap();
9
+ /** @type {WeakMap<HTMLElement, { label: string, text: string | null }>} */
10
+ const originals = new WeakMap();
11
+
12
+ /** @param {Element} block */
13
+ function codeText(block) {
14
+ const code = block.querySelector("pre code");
15
+ if (!code) return "";
16
+
17
+ const lines = [...code.querySelectorAll("[data-slot='line']")];
18
+ const text =
19
+ lines.length > 0
20
+ ? lines
21
+ .map((line) => {
22
+ const content = line.querySelector("[data-slot='line-content']");
23
+ return content?.textContent ?? line.textContent ?? "";
24
+ })
25
+ .join("\n")
26
+ : (code.textContent ?? "");
27
+
28
+ return text.replace(/\n+$/, "");
29
+ }
30
+
31
+ /** @param {HTMLElement} button */
32
+ function resetFeedback(button) {
33
+ const timer = feedbackTimers.get(button);
34
+ if (timer !== undefined) {
35
+ window.clearTimeout(timer);
36
+ feedbackTimers.delete(button);
37
+ }
38
+ button.removeAttribute("data-copied");
39
+ const original = originals.get(button);
40
+ if (original) {
41
+ button.setAttribute("aria-label", original.label);
42
+ if (original.text !== null) button.textContent = original.text;
43
+ }
44
+ }
45
+
46
+ /** @param {HTMLElement} button @param {string} label @param {boolean} copied */
47
+ function showFeedback(button, label, copied) {
48
+ if (!originals.has(button)) {
49
+ originals.set(button, {
50
+ label: button.getAttribute("aria-label") ?? "Copy",
51
+ text: button.querySelector("svg") ? null : (button.textContent ?? "")
52
+ });
53
+ }
54
+
55
+ resetFeedback(button);
56
+
57
+ if (copied) {
58
+ button.setAttribute("data-copied", "");
59
+ const original = originals.get(button);
60
+ if (original?.text !== null && original?.text !== undefined) {
61
+ button.textContent = "Copied";
62
+ }
63
+ }
64
+ button.setAttribute("aria-label", label);
65
+
66
+ const timer = window.setTimeout(() => resetFeedback(button), FEEDBACK_MS);
67
+ feedbackTimers.set(button, timer);
68
+ }
69
+
70
+ on("click", ".code-block [data-slot='copy']", (event, target) => {
71
+ if (!(target instanceof HTMLElement)) return;
72
+ const block = target.closest(".code-block");
73
+ if (!block) return;
74
+
75
+ event.preventDefault();
76
+
77
+ const text = codeText(block);
78
+ if (!text) return true;
79
+
80
+ const write = navigator.clipboard?.writeText(text);
81
+ if (!write) {
82
+ showFeedback(target, "Copy failed", false);
83
+ return true;
84
+ }
85
+
86
+ write
87
+ .then(() => showFeedback(target, "Copied", true))
88
+ .catch(() => showFeedback(target, "Copy failed", false));
89
+
90
+ return true;
91
+ });
92
+
93
+ on("click", ".code-block [data-slot='wrap']", (event, target) => {
94
+ if (!(target instanceof HTMLElement)) return;
95
+ const block = target.closest(".code-block");
96
+ const pre = block?.querySelector("pre");
97
+ if (!pre) return;
98
+
99
+ const next = !pre.hasAttribute("data-wrap");
100
+ pre.toggleAttribute("data-wrap", next);
101
+ target.setAttribute("aria-pressed", String(next));
102
+ event.preventDefault();
103
+ return true;
104
+ });
105
+
106
+ init();
@@ -0,0 +1,237 @@
1
+ // @ts-check
2
+
3
+ import { emit, init, on, onDocument, panelFor } from "./core.js";
4
+ import {
5
+ filterOptions,
6
+ firstOption,
7
+ highlight,
8
+ lastOption,
9
+ listboxIn,
10
+ moveHighlight,
11
+ optionsOf,
12
+ resetFilter,
13
+ selectOption,
14
+ selectedOptions,
15
+ selectedValues
16
+ } from "./listbox.js";
17
+
18
+ /** @type {WeakSet<HTMLInputElement>} */
19
+ const suppressFocus = new WeakSet();
20
+
21
+ /** @param {HTMLInputElement} input */
22
+ function rootOf(input) {
23
+ return input.closest(".combobox") ?? input.parentElement ?? input;
24
+ }
25
+
26
+ /** @param {HTMLInputElement} input */
27
+ function parts(input) {
28
+ const panel = panelFor(input);
29
+ const listbox = panel ? listboxIn(panel) : null;
30
+ return { panel, listbox };
31
+ }
32
+
33
+ /** @param {HTMLInputElement} input */
34
+ function isExpanded(input) {
35
+ return input.getAttribute("aria-expanded") === "true";
36
+ }
37
+
38
+ /** @param {HTMLInputElement} input @param {boolean} open */
39
+ function setExpanded(input, open) {
40
+ const { panel } = parts(input);
41
+ input.setAttribute("aria-expanded", String(open));
42
+ if (panel) panel.setAttribute("aria-hidden", String(!open));
43
+ }
44
+
45
+ /** @param {HTMLInputElement} input */
46
+ function multiple(input) {
47
+ const { listbox } = parts(input);
48
+ return listbox?.getAttribute("aria-multiselectable") === "true";
49
+ }
50
+
51
+ /** @param {HTMLInputElement} input */
52
+ function syncHidden(input) {
53
+ if (multiple(input)) return;
54
+ const { listbox } = parts(input);
55
+ if (!listbox) return;
56
+ const hidden = rootOf(input).querySelector("input[data-slot='input']");
57
+ if (hidden instanceof HTMLInputElement) {
58
+ hidden.value = selectedValues(listbox)[0] ?? "";
59
+ }
60
+ }
61
+
62
+ /** @param {HTMLInputElement} input */
63
+ function openCombobox(input) {
64
+ const { listbox } = parts(input);
65
+ if (!listbox) return;
66
+
67
+ resetFilter(listbox);
68
+ setExpanded(input, true);
69
+ const selected = selectedOptions(listbox)[0] ?? firstOption(listbox);
70
+ highlight(listbox, selected, input);
71
+ }
72
+
73
+ /** @param {HTMLInputElement} input @param {boolean} restore */
74
+ function closeCombobox(input, restore) {
75
+ const { listbox } = parts(input);
76
+ setExpanded(input, false);
77
+ if (listbox) highlight(listbox, null, input);
78
+
79
+ if (!restore) return;
80
+ const selected = listbox ? selectedValues(listbox) : [];
81
+ input.value = multiple(input) ? "" : (selected[0] ?? "");
82
+ if (listbox) resetFilter(listbox);
83
+ }
84
+
85
+ /** @param {HTMLInputElement} input */
86
+ function filter(input) {
87
+ const { listbox } = parts(input);
88
+ if (!listbox) return;
89
+
90
+ if (!isExpanded(input)) setExpanded(input, true);
91
+ if (input.value.trim() === "") {
92
+ resetFilter(listbox);
93
+ } else {
94
+ filterOptions(listbox, input.value);
95
+ }
96
+ highlight(listbox, firstOption(listbox), input);
97
+ }
98
+
99
+ /** @param {HTMLInputElement} input @param {Element} option */
100
+ function choose(input, option) {
101
+ const { listbox } = parts(input);
102
+ if (!listbox) return;
103
+
104
+ const isMultiple = multiple(input);
105
+ const values = selectOption(listbox, option, isMultiple);
106
+ const root = rootOf(input);
107
+
108
+ if (isMultiple) {
109
+ input.value = "";
110
+ resetFilter(listbox);
111
+ highlight(listbox, firstOption(listbox), input);
112
+ emit(root, "change", { values });
113
+ syncHidden(input);
114
+ input.focus();
115
+ return;
116
+ }
117
+
118
+ const value = values[0] ?? "";
119
+ input.value = value;
120
+ setExpanded(input, false);
121
+ highlight(listbox, null, input);
122
+ syncHidden(input);
123
+ emit(root, "change", { value });
124
+ if (document.activeElement !== input) {
125
+ suppressFocus.add(input);
126
+ input.focus();
127
+ }
128
+ }
129
+
130
+ /** @param {HTMLInputElement} input */
131
+ function clear(input) {
132
+ const { listbox } = parts(input);
133
+ if (!listbox) return;
134
+
135
+ for (const option of optionsOf(listbox)) {
136
+ option.setAttribute("aria-selected", "false");
137
+ }
138
+ input.value = "";
139
+ resetFilter(listbox);
140
+ highlight(listbox, firstOption(listbox), input);
141
+ syncHidden(input);
142
+ emit(rootOf(input), "change", { value: "", values: [] });
143
+ input.focus();
144
+ }
145
+
146
+ on("focusin", ".combobox [role='combobox']", (_event, target) => {
147
+ if (!(target instanceof HTMLInputElement)) return;
148
+ if (suppressFocus.has(target)) {
149
+ suppressFocus.delete(target);
150
+ return;
151
+ }
152
+ if (!isExpanded(target)) openCombobox(target);
153
+ });
154
+
155
+ on("click", ".combobox [role='combobox']", (_event, target) => {
156
+ if (!(target instanceof HTMLInputElement)) return;
157
+ if (!isExpanded(target)) openCombobox(target);
158
+ });
159
+
160
+ on("input", ".combobox [role='combobox']", (event, target) => {
161
+ if (!(target instanceof HTMLInputElement)) return;
162
+ if (event instanceof InputEvent && event.isComposing) return;
163
+ filter(target);
164
+ });
165
+
166
+ on("click", ".combobox [role='option']", (event, target) => {
167
+ if (!(target instanceof HTMLElement) || target.getAttribute("aria-disabled") === "true") {
168
+ return;
169
+ }
170
+ const input = target.closest(".combobox")?.querySelector("[role='combobox']");
171
+ if (input instanceof HTMLInputElement) choose(input, target);
172
+ event.preventDefault();
173
+ return true;
174
+ });
175
+
176
+ on("click", ".combobox [data-slot='clear']", (event, target) => {
177
+ if (!(target instanceof HTMLElement)) return;
178
+ const input = target.closest(".combobox")?.querySelector("[role='combobox']");
179
+ if (input instanceof HTMLInputElement) clear(input);
180
+ event.preventDefault();
181
+ return true;
182
+ });
183
+
184
+ on("keydown", ".combobox [role='combobox']", (event, target) => {
185
+ if (!(event instanceof KeyboardEvent) || !(target instanceof HTMLInputElement)) return;
186
+ const { listbox } = parts(target);
187
+ if (!listbox) return;
188
+
189
+ if (event.key === "Escape") {
190
+ if (!isExpanded(target)) return;
191
+ closeCombobox(target, true);
192
+ event.preventDefault();
193
+ return true;
194
+ }
195
+
196
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
197
+ if (!isExpanded(target)) openCombobox(target);
198
+ const next = moveHighlight(listbox, event.key === "ArrowDown" ? 1 : -1);
199
+ if (next) highlight(listbox, next, target);
200
+ event.preventDefault();
201
+ return true;
202
+ }
203
+
204
+ if (event.key === "Home" || event.key === "End") {
205
+ if (!isExpanded(target)) openCombobox(target);
206
+ highlight(
207
+ listbox,
208
+ event.key === "Home" ? firstOption(listbox) : lastOption(listbox),
209
+ target
210
+ );
211
+ event.preventDefault();
212
+ return true;
213
+ }
214
+
215
+ if (event.key === "Enter") {
216
+ const option = listbox.querySelector("[data-highlighted]");
217
+ if (option instanceof HTMLElement) choose(target, option);
218
+ event.preventDefault();
219
+ return true;
220
+ }
221
+
222
+ if (event.key === "Tab") {
223
+ closeCombobox(target, true);
224
+ }
225
+ }, 25);
226
+
227
+ onDocument("pointerdown", (event) => {
228
+ if (!(event.target instanceof Node)) return;
229
+ for (const input of document.querySelectorAll(".combobox [role='combobox']")) {
230
+ if (!(input instanceof HTMLInputElement) || !isExpanded(input)) continue;
231
+ const root = rootOf(input);
232
+ if (root.contains(event.target)) continue;
233
+ closeCombobox(input, true);
234
+ }
235
+ });
236
+
237
+ init();
@@ -0,0 +1,105 @@
1
+ // @ts-check
2
+
3
+ import { init, on, uniqueId } from "./core.js";
4
+ import {
5
+ filterOptions,
6
+ firstOption,
7
+ highlight,
8
+ lastOption,
9
+ listboxIn,
10
+ moveHighlight,
11
+ resetFilter
12
+ } from "./listbox.js";
13
+
14
+ /** @param {Element} root */
15
+ function parts(root) {
16
+ const input = root.querySelector("input");
17
+ const listbox = listboxIn(root);
18
+ return {
19
+ input: input instanceof HTMLInputElement ? input : null,
20
+ listbox
21
+ };
22
+ }
23
+
24
+ /** @param {HTMLInputElement} input @param {HTMLElement} listbox */
25
+ function link(input, listbox) {
26
+ if (!listbox.id) listbox.id = uniqueId("loseta-listbox");
27
+ if (!input.hasAttribute("role")) input.setAttribute("role", "combobox");
28
+ if (!input.hasAttribute("aria-controls")) input.setAttribute("aria-controls", listbox.id);
29
+ if (!input.hasAttribute("aria-expanded")) input.setAttribute("aria-expanded", "true");
30
+ if (!input.hasAttribute("aria-autocomplete")) input.setAttribute("aria-autocomplete", "list");
31
+ }
32
+
33
+ /** @param {Element} root @param {HTMLInputElement} input */
34
+ function refresh(root, input) {
35
+ const { listbox } = parts(root);
36
+ if (!listbox) return;
37
+
38
+ link(input, listbox);
39
+ if (input.value.trim() === "") {
40
+ resetFilter(listbox);
41
+ } else {
42
+ filterOptions(listbox, input.value);
43
+ }
44
+ highlight(listbox, firstOption(listbox), input);
45
+ }
46
+
47
+ on("focusin", ".command input", (_event, target) => {
48
+ if (!(target instanceof HTMLInputElement)) return;
49
+ const root = target.closest(".command");
50
+ if (!root) return;
51
+ const { listbox } = parts(root);
52
+ if (!listbox) return;
53
+ link(target, listbox);
54
+ if (!listbox.querySelector("[data-highlighted]")) {
55
+ highlight(listbox, firstOption(listbox), target);
56
+ }
57
+ });
58
+
59
+ on("input", ".command input", (_event, target) => {
60
+ if (!(target instanceof HTMLInputElement)) return;
61
+ const root = target.closest(".command");
62
+ if (root) refresh(root, target);
63
+ });
64
+
65
+ on("keydown", ".command input", (event, target) => {
66
+ if (!(event instanceof KeyboardEvent) || !(target instanceof HTMLInputElement)) return;
67
+ const root = target.closest(".command");
68
+ if (!root) return;
69
+ const { listbox } = parts(root);
70
+ if (!listbox) return;
71
+
72
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
73
+ const next = moveHighlight(listbox, event.key === "ArrowDown" ? 1 : -1);
74
+ if (next) highlight(listbox, next, target);
75
+ event.preventDefault();
76
+ return true;
77
+ }
78
+
79
+ if (event.key === "Home" || event.key === "End") {
80
+ highlight(
81
+ listbox,
82
+ event.key === "Home" ? firstOption(listbox) : lastOption(listbox),
83
+ target
84
+ );
85
+ event.preventDefault();
86
+ return true;
87
+ }
88
+
89
+ if (event.key === "Enter") {
90
+ const option = listbox.querySelector("[data-highlighted]");
91
+ if (option instanceof HTMLElement) option.click();
92
+ event.preventDefault();
93
+ return true;
94
+ }
95
+ });
96
+
97
+ on("pointermove", ".command [role='option']", (event, target) => {
98
+ if (!(event instanceof PointerEvent) || !(target instanceof HTMLElement)) return;
99
+ const root = target.closest(".command");
100
+ if (!root) return;
101
+ const { input, listbox } = parts(root);
102
+ if (listbox) highlight(listbox, target, input);
103
+ });
104
+
105
+ init();