@prismora/elements 0.0.0-stage → 0.1.1

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 (393) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +21 -2
  3. package/components.json +15600 -0
  4. package/custom-elements.json +56320 -0
  5. package/dist/base.d.ts +42 -0
  6. package/dist/base.js +62 -0
  7. package/dist/catalog.d.ts +33 -0
  8. package/dist/catalog.js +803 -0
  9. package/dist/components/accordion.d.ts +31 -0
  10. package/dist/components/accordion.js +63 -0
  11. package/dist/components/alert.d.ts +27 -0
  12. package/dist/components/alert.js +40 -0
  13. package/dist/components/avatar-group.d.ts +23 -0
  14. package/dist/components/avatar-group.js +43 -0
  15. package/dist/components/avatar.d.ts +24 -0
  16. package/dist/components/avatar.js +43 -0
  17. package/dist/components/back-to-top.d.ts +32 -0
  18. package/dist/components/back-to-top.js +50 -0
  19. package/dist/components/badge.d.ts +17 -0
  20. package/dist/components/badge.js +20 -0
  21. package/dist/components/banner.d.ts +34 -0
  22. package/dist/components/banner.js +54 -0
  23. package/dist/components/breadcrumb.d.ts +42 -0
  24. package/dist/components/breadcrumb.js +63 -0
  25. package/dist/components/button-group.d.ts +14 -0
  26. package/dist/components/button-group.js +28 -0
  27. package/dist/components/button.d.ts +59 -0
  28. package/dist/components/button.js +162 -0
  29. package/dist/components/calendar.d.ts +48 -0
  30. package/dist/components/calendar.js +296 -0
  31. package/dist/components/card.d.ts +23 -0
  32. package/dist/components/card.js +44 -0
  33. package/dist/components/carousel.d.ts +41 -0
  34. package/dist/components/carousel.js +156 -0
  35. package/dist/components/cascader.d.ts +70 -0
  36. package/dist/components/cascader.js +220 -0
  37. package/dist/components/chart.d.ts +59 -0
  38. package/dist/components/chart.js +267 -0
  39. package/dist/components/chat.d.ts +98 -0
  40. package/dist/components/chat.js +134 -0
  41. package/dist/components/checkbox-group.d.ts +48 -0
  42. package/dist/components/checkbox-group.js +111 -0
  43. package/dist/components/checkbox.d.ts +23 -0
  44. package/dist/components/checkbox.js +70 -0
  45. package/dist/components/code-block.d.ts +46 -0
  46. package/dist/components/code-block.js +86 -0
  47. package/dist/components/color-picker.d.ts +46 -0
  48. package/dist/components/color-picker.js +292 -0
  49. package/dist/components/combobox.d.ts +89 -0
  50. package/dist/components/combobox.js +384 -0
  51. package/dist/components/command.d.ts +96 -0
  52. package/dist/components/command.js +289 -0
  53. package/dist/components/context-menu.d.ts +23 -0
  54. package/dist/components/context-menu.js +110 -0
  55. package/dist/components/copy-button.d.ts +33 -0
  56. package/dist/components/copy-button.js +62 -0
  57. package/dist/components/countdown.d.ts +36 -0
  58. package/dist/components/countdown.js +56 -0
  59. package/dist/components/data-table.d.ts +180 -0
  60. package/dist/components/data-table.js +1060 -0
  61. package/dist/components/date-picker.d.ts +47 -0
  62. package/dist/components/date-picker.js +267 -0
  63. package/dist/components/description-list.d.ts +38 -0
  64. package/dist/components/description-list.js +41 -0
  65. package/dist/components/dialog.d.ts +47 -0
  66. package/dist/components/dialog.js +189 -0
  67. package/dist/components/divider.d.ts +16 -0
  68. package/dist/components/divider.js +23 -0
  69. package/dist/components/drawer.d.ts +19 -0
  70. package/dist/components/drawer.js +27 -0
  71. package/dist/components/editor.d.ts +50 -0
  72. package/dist/components/editor.js +474 -0
  73. package/dist/components/empty-state.d.ts +24 -0
  74. package/dist/components/empty-state.js +27 -0
  75. package/dist/components/file-upload.d.ts +56 -0
  76. package/dist/components/file-upload.js +176 -0
  77. package/dist/components/form-control.d.ts +69 -0
  78. package/dist/components/form-control.js +134 -0
  79. package/dist/components/form.d.ts +38 -0
  80. package/dist/components/form.js +161 -0
  81. package/dist/components/format-number.d.ts +37 -0
  82. package/dist/components/format-number.js +86 -0
  83. package/dist/components/icon.d.ts +34 -0
  84. package/dist/components/icon.js +47 -0
  85. package/dist/components/image.d.ts +44 -0
  86. package/dist/components/image.js +53 -0
  87. package/dist/components/indicator.d.ts +41 -0
  88. package/dist/components/indicator.js +65 -0
  89. package/dist/components/inline-edit.d.ts +45 -0
  90. package/dist/components/inline-edit.js +129 -0
  91. package/dist/components/input.d.ts +55 -0
  92. package/dist/components/input.js +186 -0
  93. package/dist/components/kbd.d.ts +15 -0
  94. package/dist/components/kbd.js +18 -0
  95. package/dist/components/list.d.ts +68 -0
  96. package/dist/components/list.js +180 -0
  97. package/dist/components/menu.d.ts +22 -0
  98. package/dist/components/menu.js +182 -0
  99. package/dist/components/menubar.d.ts +20 -0
  100. package/dist/components/menubar.js +120 -0
  101. package/dist/components/meter.d.ts +38 -0
  102. package/dist/components/meter.js +48 -0
  103. package/dist/components/nav.d.ts +91 -0
  104. package/dist/components/nav.js +228 -0
  105. package/dist/components/number-input.d.ts +26 -0
  106. package/dist/components/number-input.js +70 -0
  107. package/dist/components/pagination.d.ts +44 -0
  108. package/dist/components/pagination.js +94 -0
  109. package/dist/components/pin-input.d.ts +25 -0
  110. package/dist/components/pin-input.js +128 -0
  111. package/dist/components/popover.d.ts +23 -0
  112. package/dist/components/popover.js +140 -0
  113. package/dist/components/progress.d.ts +26 -0
  114. package/dist/components/progress.js +66 -0
  115. package/dist/components/pull-refresh.d.ts +41 -0
  116. package/dist/components/pull-refresh.js +101 -0
  117. package/dist/components/qr-code.d.ts +33 -0
  118. package/dist/components/qr-code.js +54 -0
  119. package/dist/components/radio-group.d.ts +37 -0
  120. package/dist/components/radio-group.js +82 -0
  121. package/dist/components/range-slider.d.ts +46 -0
  122. package/dist/components/range-slider.js +95 -0
  123. package/dist/components/rating.d.ts +38 -0
  124. package/dist/components/rating.js +80 -0
  125. package/dist/components/relative-time.d.ts +31 -0
  126. package/dist/components/relative-time.js +51 -0
  127. package/dist/components/scheduler.d.ts +84 -0
  128. package/dist/components/scheduler.js +187 -0
  129. package/dist/components/segmented.d.ts +58 -0
  130. package/dist/components/segmented.js +129 -0
  131. package/dist/components/select.d.ts +62 -0
  132. package/dist/components/select.js +140 -0
  133. package/dist/components/share-button.d.ts +37 -0
  134. package/dist/components/share-button.js +60 -0
  135. package/dist/components/signature.d.ts +54 -0
  136. package/dist/components/signature.js +152 -0
  137. package/dist/components/skeleton.d.ts +21 -0
  138. package/dist/components/skeleton.js +26 -0
  139. package/dist/components/slider.d.ts +31 -0
  140. package/dist/components/slider.js +80 -0
  141. package/dist/components/sortable.d.ts +22 -0
  142. package/dist/components/sortable.js +196 -0
  143. package/dist/components/sparkline.d.ts +28 -0
  144. package/dist/components/sparkline.js +46 -0
  145. package/dist/components/spinner.d.ts +16 -0
  146. package/dist/components/spinner.js +22 -0
  147. package/dist/components/splitter.d.ts +28 -0
  148. package/dist/components/splitter.js +89 -0
  149. package/dist/components/stat.d.ts +28 -0
  150. package/dist/components/stat.js +33 -0
  151. package/dist/components/steps.d.ts +53 -0
  152. package/dist/components/steps.js +91 -0
  153. package/dist/components/switch.d.ts +12 -0
  154. package/dist/components/switch.js +18 -0
  155. package/dist/components/table.d.ts +58 -0
  156. package/dist/components/table.js +96 -0
  157. package/dist/components/tabs.d.ts +62 -0
  158. package/dist/components/tabs.js +310 -0
  159. package/dist/components/tag.d.ts +32 -0
  160. package/dist/components/tag.js +58 -0
  161. package/dist/components/textarea.d.ts +25 -0
  162. package/dist/components/textarea.js +56 -0
  163. package/dist/components/theme-switch.d.ts +51 -0
  164. package/dist/components/theme-switch.js +85 -0
  165. package/dist/components/time-picker.d.ts +39 -0
  166. package/dist/components/time-picker.js +257 -0
  167. package/dist/components/timeline.d.ts +38 -0
  168. package/dist/components/timeline.js +56 -0
  169. package/dist/components/toaster.d.ts +25 -0
  170. package/dist/components/toaster.js +44 -0
  171. package/dist/components/toggle-group.d.ts +70 -0
  172. package/dist/components/toggle-group.js +172 -0
  173. package/dist/components/toolbar.d.ts +23 -0
  174. package/dist/components/toolbar.js +81 -0
  175. package/dist/components/tooltip.d.ts +18 -0
  176. package/dist/components/tooltip.js +92 -0
  177. package/dist/components/tour.d.ts +41 -0
  178. package/dist/components/tour.js +197 -0
  179. package/dist/components/transfer.d.ts +57 -0
  180. package/dist/components/transfer.js +161 -0
  181. package/dist/components/tree-select.d.ts +66 -0
  182. package/dist/components/tree-select.js +282 -0
  183. package/dist/components/tree.d.ts +129 -0
  184. package/dist/components/tree.js +427 -0
  185. package/dist/components/virtual-list.d.ts +41 -0
  186. package/dist/components/virtual-list.js +77 -0
  187. package/dist/confirm.d.ts +21 -0
  188. package/dist/confirm.js +69 -0
  189. package/dist/count.d.ts +5 -0
  190. package/dist/count.js +12 -0
  191. package/dist/data-table/icons.d.ts +8 -0
  192. package/dist/data-table/icons.js +10 -0
  193. package/dist/data-table/logic.d.ts +33 -0
  194. package/dist/data-table/logic.js +141 -0
  195. package/dist/data-table/strings.d.ts +37 -0
  196. package/dist/data-table/strings.js +36 -0
  197. package/dist/data-table/types.d.ts +76 -0
  198. package/dist/data-table/types.js +1 -0
  199. package/dist/define.d.ts +2 -0
  200. package/dist/define.js +2 -0
  201. package/dist/field-validity.d.ts +42 -0
  202. package/dist/field-validity.js +58 -0
  203. package/dist/floating.d.ts +13 -0
  204. package/dist/floating.js +65 -0
  205. package/dist/highlight.d.ts +11 -0
  206. package/dist/highlight.js +103 -0
  207. package/dist/id.d.ts +2 -0
  208. package/dist/id.js +3 -0
  209. package/dist/index.d.ts +102 -0
  210. package/dist/index.js +102 -0
  211. package/dist/manifest.d.ts +51 -0
  212. package/dist/manifest.js +11 -0
  213. package/dist/named-icon.d.ts +8 -0
  214. package/dist/named-icon.js +8 -0
  215. package/dist/patterns/account.d.ts +6 -0
  216. package/dist/patterns/account.js +137 -0
  217. package/dist/patterns/app.d.ts +7 -0
  218. package/dist/patterns/app.js +351 -0
  219. package/dist/patterns/commerce.d.ts +4 -0
  220. package/dist/patterns/commerce.js +200 -0
  221. package/dist/patterns/flows.d.ts +3 -0
  222. package/dist/patterns/flows.js +100 -0
  223. package/dist/patterns/index.d.ts +9 -0
  224. package/dist/patterns/index.js +29 -0
  225. package/dist/patterns/marketing.d.ts +4 -0
  226. package/dist/patterns/marketing.js +173 -0
  227. package/dist/patterns/more.d.ts +15 -0
  228. package/dist/patterns/more.js +581 -0
  229. package/dist/patterns/shell.d.ts +9 -0
  230. package/dist/patterns/shell.js +48 -0
  231. package/dist/patterns/types.d.ts +19 -0
  232. package/dist/patterns/types.js +1 -0
  233. package/dist/position.d.ts +2 -0
  234. package/dist/position.js +33 -0
  235. package/dist/prismora.standalone.js +5222 -0
  236. package/dist/prismora.standalone.js.map +199 -0
  237. package/dist/qr.d.ts +14 -0
  238. package/dist/qr.js +258 -0
  239. package/dist/register.d.ts +8 -0
  240. package/dist/register.js +21 -0
  241. package/dist/registry.d.ts +203 -0
  242. package/dist/registry.js +203 -0
  243. package/dist/remote.d.ts +58 -0
  244. package/dist/remote.js +130 -0
  245. package/dist/sheet.d.ts +34 -0
  246. package/dist/sheet.js +153 -0
  247. package/dist/styles/accordion.d.ts +2 -0
  248. package/dist/styles/accordion.js +3 -0
  249. package/dist/styles/alert.d.ts +2 -0
  250. package/dist/styles/alert.js +3 -0
  251. package/dist/styles/avatar.d.ts +2 -0
  252. package/dist/styles/avatar.js +3 -0
  253. package/dist/styles/badge.d.ts +2 -0
  254. package/dist/styles/badge.js +3 -0
  255. package/dist/styles/banner.d.ts +2 -0
  256. package/dist/styles/banner.js +3 -0
  257. package/dist/styles/breadcrumb.d.ts +2 -0
  258. package/dist/styles/breadcrumb.js +3 -0
  259. package/dist/styles/button.d.ts +2 -0
  260. package/dist/styles/button.js +3 -0
  261. package/dist/styles/calendar.d.ts +2 -0
  262. package/dist/styles/calendar.js +3 -0
  263. package/dist/styles/card.d.ts +2 -0
  264. package/dist/styles/card.js +3 -0
  265. package/dist/styles/carousel.d.ts +2 -0
  266. package/dist/styles/carousel.js +3 -0
  267. package/dist/styles/chart.d.ts +2 -0
  268. package/dist/styles/chart.js +3 -0
  269. package/dist/styles/chat.d.ts +2 -0
  270. package/dist/styles/chat.js +3 -0
  271. package/dist/styles/checkbox.d.ts +2 -0
  272. package/dist/styles/checkbox.js +3 -0
  273. package/dist/styles/color-picker.d.ts +2 -0
  274. package/dist/styles/color-picker.js +3 -0
  275. package/dist/styles/combobox.d.ts +2 -0
  276. package/dist/styles/combobox.js +3 -0
  277. package/dist/styles/command.d.ts +2 -0
  278. package/dist/styles/command.js +3 -0
  279. package/dist/styles/data-table.d.ts +2 -0
  280. package/dist/styles/data-table.js +3 -0
  281. package/dist/styles/description-list.d.ts +2 -0
  282. package/dist/styles/description-list.js +3 -0
  283. package/dist/styles/dialog.d.ts +2 -0
  284. package/dist/styles/dialog.js +3 -0
  285. package/dist/styles/drawer.d.ts +2 -0
  286. package/dist/styles/drawer.js +3 -0
  287. package/dist/styles/editor.d.ts +2 -0
  288. package/dist/styles/editor.js +3 -0
  289. package/dist/styles/empty-state.d.ts +2 -0
  290. package/dist/styles/empty-state.js +3 -0
  291. package/dist/styles/extras.d.ts +2 -0
  292. package/dist/styles/extras.js +3 -0
  293. package/dist/styles/field.d.ts +2 -0
  294. package/dist/styles/field.js +3 -0
  295. package/dist/styles/file-upload.d.ts +2 -0
  296. package/dist/styles/file-upload.js +3 -0
  297. package/dist/styles/foundation.d.ts +2 -0
  298. package/dist/styles/foundation.js +3 -0
  299. package/dist/styles/helpers.d.ts +2 -0
  300. package/dist/styles/helpers.js +3 -0
  301. package/dist/styles/icon.d.ts +2 -0
  302. package/dist/styles/icon.js +3 -0
  303. package/dist/styles/image.d.ts +2 -0
  304. package/dist/styles/image.js +3 -0
  305. package/dist/styles/indicator.d.ts +2 -0
  306. package/dist/styles/indicator.js +3 -0
  307. package/dist/styles/input.d.ts +2 -0
  308. package/dist/styles/input.js +3 -0
  309. package/dist/styles/kbd.d.ts +2 -0
  310. package/dist/styles/kbd.js +3 -0
  311. package/dist/styles/list.d.ts +2 -0
  312. package/dist/styles/list.js +3 -0
  313. package/dist/styles/listbox.d.ts +2 -0
  314. package/dist/styles/listbox.js +3 -0
  315. package/dist/styles/meter.d.ts +2 -0
  316. package/dist/styles/meter.js +3 -0
  317. package/dist/styles/nav.d.ts +2 -0
  318. package/dist/styles/nav.js +3 -0
  319. package/dist/styles/number-input.d.ts +2 -0
  320. package/dist/styles/number-input.js +3 -0
  321. package/dist/styles/overlay.d.ts +2 -0
  322. package/dist/styles/overlay.js +3 -0
  323. package/dist/styles/pagination.d.ts +2 -0
  324. package/dist/styles/pagination.js +3 -0
  325. package/dist/styles/pickers.d.ts +2 -0
  326. package/dist/styles/pickers.js +3 -0
  327. package/dist/styles/pin-input.d.ts +2 -0
  328. package/dist/styles/pin-input.js +3 -0
  329. package/dist/styles/popover.d.ts +2 -0
  330. package/dist/styles/popover.js +3 -0
  331. package/dist/styles/progress.d.ts +2 -0
  332. package/dist/styles/progress.js +3 -0
  333. package/dist/styles/pull-refresh.d.ts +2 -0
  334. package/dist/styles/pull-refresh.js +3 -0
  335. package/dist/styles/range-slider.d.ts +2 -0
  336. package/dist/styles/range-slider.js +3 -0
  337. package/dist/styles/rating.d.ts +2 -0
  338. package/dist/styles/rating.js +3 -0
  339. package/dist/styles/scheduler.d.ts +2 -0
  340. package/dist/styles/scheduler.js +3 -0
  341. package/dist/styles/segmented.d.ts +2 -0
  342. package/dist/styles/segmented.js +3 -0
  343. package/dist/styles/select.d.ts +2 -0
  344. package/dist/styles/select.js +3 -0
  345. package/dist/styles/separator.d.ts +2 -0
  346. package/dist/styles/separator.js +3 -0
  347. package/dist/styles/sheet.d.ts +2 -0
  348. package/dist/styles/sheet.js +3 -0
  349. package/dist/styles/skeleton.d.ts +2 -0
  350. package/dist/styles/skeleton.js +3 -0
  351. package/dist/styles/slider.d.ts +2 -0
  352. package/dist/styles/slider.js +3 -0
  353. package/dist/styles/sortable.d.ts +2 -0
  354. package/dist/styles/sortable.js +3 -0
  355. package/dist/styles/spinner.d.ts +2 -0
  356. package/dist/styles/spinner.js +3 -0
  357. package/dist/styles/splitter.d.ts +2 -0
  358. package/dist/styles/splitter.js +3 -0
  359. package/dist/styles/stat.d.ts +2 -0
  360. package/dist/styles/stat.js +3 -0
  361. package/dist/styles/steps.d.ts +2 -0
  362. package/dist/styles/steps.js +3 -0
  363. package/dist/styles/surface.d.ts +2 -0
  364. package/dist/styles/surface.js +3 -0
  365. package/dist/styles/switch.d.ts +2 -0
  366. package/dist/styles/switch.js +3 -0
  367. package/dist/styles/table.d.ts +2 -0
  368. package/dist/styles/table.js +3 -0
  369. package/dist/styles/tabs.d.ts +2 -0
  370. package/dist/styles/tabs.js +3 -0
  371. package/dist/styles/tag.d.ts +2 -0
  372. package/dist/styles/tag.js +3 -0
  373. package/dist/styles/time-picker.d.ts +2 -0
  374. package/dist/styles/time-picker.js +3 -0
  375. package/dist/styles/timeline.d.ts +2 -0
  376. package/dist/styles/timeline.js +3 -0
  377. package/dist/styles/toast.d.ts +2 -0
  378. package/dist/styles/toast.js +3 -0
  379. package/dist/styles/toggle.d.ts +2 -0
  380. package/dist/styles/toggle.js +3 -0
  381. package/dist/styles/toolbar.d.ts +2 -0
  382. package/dist/styles/toolbar.js +3 -0
  383. package/dist/styles/tooltip.d.ts +2 -0
  384. package/dist/styles/tooltip.js +3 -0
  385. package/dist/styles/tree.d.ts +2 -0
  386. package/dist/styles/tree.js +3 -0
  387. package/dist/table-core.d.ts +75 -0
  388. package/dist/table-core.js +205 -0
  389. package/dist/toast.d.ts +42 -0
  390. package/dist/toast.js +206 -0
  391. package/dist/top-layer.d.ts +4 -0
  392. package/dist/top-layer.js +33 -0
  393. package/package.json +101 -4
@@ -0,0 +1,384 @@
1
+ import { css, html, nothing } from 'lit';
2
+ import { ifDefined } from 'lit/directives/if-defined.js';
3
+ import { live } from 'lit/directives/live.js';
4
+ import { defineElement } from '../base.js';
5
+ import { attachBelow, hidePopup, showPopup } from '../floating.js';
6
+ import { RemoteRequest, buildUrl, fetchJson, field, pick } from '../remote.js';
7
+ import comboboxCss from '../styles/combobox.js';
8
+ import inputCss from '../styles/input.js';
9
+ import listboxCss from '../styles/listbox.js';
10
+ import tagCss from '../styles/tag.js';
11
+ import { PmFormControl } from './form-control.js';
12
+ const CHEVRON = html `<svg viewBox="0 0 24 24" width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 9l6 6 6-6"/></svg>`;
13
+ const CHECK = html `<svg viewBox="0 0 24 24" width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>`;
14
+ /**
15
+ * Combobox / autocomplete: a searchable select.
16
+ *
17
+ * Single or `multiple` (selections become tags), `creatable` entries, `clearable` and grouped options. Options come
18
+ * from child `<option>` / `<optgroup>` elements or the `options` property. Keyboard: ↓/↑ move, Enter selects, Esc
19
+ * closes, Backspace removes the last tag.
20
+ *
21
+ * Server-side search: set `src` to a URL template (`src="/api/users?q={query}"`) and say where the list is in the
22
+ * JSON (`options-path="data"`) and which fields to use (`value-key="id" label-key="name"`), or set the `loader`
23
+ * property to your own `async (query, { signal }) => items` and optionally `mapOption` to format each item.
24
+ * Requests are debounced (`debounce`, default 250 ms), start after `min-chars` characters, cancel when superseded,
25
+ * and show loading, empty and error (with Retry) states. Selected values keep their labels across searches.
26
+ * Without either, you can still filter yourself: `filter="none"`, listen for `pm-search` and set `options`.
27
+ * @tag pm-combobox
28
+ * @fires pm-search - The query changed. detail: { query }
29
+ * @fires pm-create - A new entry was created (with `creatable`). detail: { value }
30
+ * @fires pm-load - Server results arrived. detail: { query, options }
31
+ * @fires pm-load-error - A server search failed. detail: { query, error }
32
+ * @example <pm-combobox label="Country" placeholder="Search…"><option value="de">Germany</option><option value="fr">France</option><option value="jp">Japan</option></pm-combobox>
33
+ */
34
+ export class PmCombobox extends PmFormControl {
35
+ static { this.componentName = 'combobox'; }
36
+ static { this.styles = [...PmFormControl.styles, inputCss, tagCss, listboxCss, comboboxCss, css ``]; }
37
+ static { this.properties = {
38
+ options: { attribute: false },
39
+ values: { attribute: false },
40
+ multiple: { type: Boolean, reflect: true },
41
+ placeholder: {},
42
+ creatable: { type: Boolean },
43
+ clearable: { type: Boolean },
44
+ filter: {},
45
+ loading: { type: Boolean },
46
+ emptyText: { attribute: 'empty-text' },
47
+ src: {},
48
+ loader: { attribute: false },
49
+ mapOption: { attribute: false },
50
+ optionsPath: { attribute: 'options-path' },
51
+ valueKey: { attribute: 'value-key' },
52
+ labelKey: { attribute: 'label-key' },
53
+ descriptionKey: { attribute: 'description-key' },
54
+ groupKey: { attribute: 'group-key' },
55
+ debounce: { type: Number },
56
+ minChars: { type: Number, attribute: 'min-chars' },
57
+ _open: { state: true },
58
+ _query: { state: true },
59
+ _active: { state: true },
60
+ _typing: { state: true },
61
+ }; }
62
+ #listId = `${this.controlId}-list`;
63
+ /** Options seen for selected values, so their labels survive new search results. */
64
+ #known = new Map();
65
+ #loadedFor;
66
+ #remote = new RemoteRequest(this, {
67
+ debounce: () => this.debounce,
68
+ run: async (query, ctx) => {
69
+ const data = this.loader ? await this.loader(query, ctx) : await fetchJson(buildUrl(this.src, { query, q: query }), ctx.signal);
70
+ const list = pick(data, this.optionsPath);
71
+ if (!Array.isArray(list))
72
+ throw new Error(`Expected a list${this.optionsPath ? ` at "${this.optionsPath}"` : ''} in the search response`);
73
+ return list.map((item) => this.mapOption?.(item) ?? this.#toOption(item));
74
+ },
75
+ done: (options, query) => {
76
+ this.#loadedFor = query;
77
+ this.options = options;
78
+ this._active = this.#nextEnabled(this.#rows, -1, 1);
79
+ this.emit('pm-load', { query, options });
80
+ },
81
+ failed: (error, query) => this.emit('pm-load-error', { query, error }),
82
+ });
83
+ get #isRemote() { return !!(this.loader || this.src); }
84
+ #toOption(item) {
85
+ if (item == null || typeof item !== 'object')
86
+ return { value: String(item ?? ''), label: String(item ?? '') };
87
+ const value = String(field(item, [this.valueKey, 'value', 'id']) ?? '');
88
+ const desc = field(item, [this.descriptionKey, 'description']);
89
+ const group = field(item, [this.groupKey, 'group']);
90
+ return {
91
+ value,
92
+ label: String(field(item, [this.labelKey, 'label', 'name', 'title']) ?? value),
93
+ ...(desc != null ? { description: String(desc) } : {}),
94
+ ...(group != null ? { group: String(group) } : {}),
95
+ ...(item.disabled ? { disabled: true } : {}),
96
+ };
97
+ }
98
+ /** Search the server now (e.g. after changing `src`). */
99
+ search(query = this._query) { if (this.#isRemote)
100
+ this.#remote.request(query, true); }
101
+ #mo;
102
+ #detach;
103
+ constructor() {
104
+ super();
105
+ this.options = [];
106
+ this.values = [];
107
+ this.multiple = false;
108
+ this.creatable = false;
109
+ this.clearable = false;
110
+ this.filter = 'contains';
111
+ this.loading = false;
112
+ this.emptyText = 'No results';
113
+ this._open = false;
114
+ this._query = '';
115
+ this._active = -1;
116
+ this._typing = false;
117
+ this.debounce = 250;
118
+ this.minChars = 1;
119
+ }
120
+ connectedCallback() {
121
+ super.connectedCallback();
122
+ if (this.multiple && !this.values.length && this.getAttribute('value'))
123
+ this.values = this.getAttribute('value').split(',').map((v) => v.trim()).filter(Boolean);
124
+ this.#readChildren();
125
+ this.#mo = new MutationObserver(() => this.#readChildren());
126
+ this.#mo.observe(this, { childList: true, subtree: true, attributes: true, characterData: true });
127
+ this.addEventListener('focusout', this.#onFocusOut);
128
+ }
129
+ disconnectedCallback() { super.disconnectedCallback(); this.#mo?.disconnect(); this.#close(); }
130
+ #readChildren() {
131
+ const opts = [...this.querySelectorAll('option')].map((o) => ({
132
+ value: o.value,
133
+ label: o.label || o.textContent?.trim() || o.value,
134
+ disabled: o.disabled,
135
+ group: o.parentElement instanceof HTMLOptGroupElement ? o.parentElement.label : undefined,
136
+ description: o.dataset.description,
137
+ }));
138
+ if (opts.length)
139
+ this.options = opts;
140
+ }
141
+ formResetCallback() { super.formResetCallback(); this.values = this.multiple ? (this.getAttribute('value')?.split(',').filter(Boolean) ?? []) : []; this._query = ''; }
142
+ syncFormValue() {
143
+ if (this.multiple) {
144
+ const data = new FormData();
145
+ for (const v of this.values)
146
+ data.append(this.name ?? 'value', v);
147
+ this.internals.setFormValue(this.values.length ? data : null);
148
+ }
149
+ else
150
+ this.internals.setFormValue(this.value || null);
151
+ }
152
+ syncValidity() {
153
+ const anchor = this.control ?? undefined;
154
+ const empty = this.multiple ? !this.values.length : !this.value;
155
+ if (this.error)
156
+ this.internals.setValidity({ customError: true }, this.error, anchor);
157
+ else if (this.required && empty)
158
+ this.internals.setValidity({ valueMissing: true }, 'Please choose an option.', anchor);
159
+ else
160
+ this.internals.setValidity({});
161
+ }
162
+ #label(v) { return (this.options.find((o) => o.value === v) ?? this.#known.get(v))?.label ?? v; }
163
+ get #rows() {
164
+ const q = this._typing ? this._query.trim().toLowerCase() : '';
165
+ const match = (o) => !q || this.filter === 'none' || this.#isRemote
166
+ || (this.filter === 'starts-with' ? o.label.toLowerCase().startsWith(q) : o.label.toLowerCase().includes(q) || o.value.toLowerCase().includes(q));
167
+ const rows = this.options.filter(match).map((option) => ({ kind: 'option', option }));
168
+ const exact = this.options.some((o) => o.label.toLowerCase() === q || o.value.toLowerCase() === q);
169
+ if (this.creatable && q && !exact)
170
+ rows.push({ kind: 'create', query: this._query.trim() });
171
+ return rows;
172
+ }
173
+ #isSelected(v) { return this.multiple ? this.values.includes(v) : this.value === v; }
174
+ #open() {
175
+ if (this._open || this.disabled || this.readonly)
176
+ return;
177
+ this._open = true;
178
+ const rows = this.#rows;
179
+ const sel = rows.findIndex((r) => r.kind === 'option' && this.#isSelected(r.option.value));
180
+ this._active = sel >= 0 ? sel : this.#nextEnabled(rows, -1, 1);
181
+ if (this.#isRemote && this.minChars <= 0 && this.#loadedFor === undefined)
182
+ this.#remote.request('', true);
183
+ }
184
+ #close() {
185
+ if (!this._open)
186
+ return;
187
+ this._open = false;
188
+ this._active = -1;
189
+ this._typing = false;
190
+ this._query = '';
191
+ }
192
+ updated(changed) {
193
+ super.updated(changed);
194
+ const popup = this.renderRoot.querySelector('.pm-listbox-popup');
195
+ const box = this.renderRoot.querySelector('.pm-combobox');
196
+ if (!popup || !box)
197
+ return;
198
+ if (this._open) {
199
+ showPopup(popup);
200
+ this.#detach ??= attachBelow(popup, box);
201
+ this.renderRoot.querySelector('[data-active]')?.scrollIntoView({ block: 'nearest' });
202
+ }
203
+ else {
204
+ this.#detach?.();
205
+ this.#detach = undefined;
206
+ hidePopup(popup);
207
+ }
208
+ }
209
+ #nextEnabled(rows, from, dir) {
210
+ for (let i = from + dir, n = 0; n < rows.length; i += dir, n++) {
211
+ const k = (i + rows.length) % rows.length;
212
+ const r = rows[k];
213
+ if (r.kind === 'create' || !r.option.disabled)
214
+ return k;
215
+ }
216
+ return -1;
217
+ }
218
+ #choose(row) {
219
+ let value;
220
+ if (row.kind === 'create') {
221
+ value = row.query;
222
+ if (!this.options.some((o) => o.value === value))
223
+ this.options = [...this.options, { value, label: value }];
224
+ this.emit('pm-create', { value });
225
+ }
226
+ else {
227
+ if (row.option.disabled)
228
+ return;
229
+ value = row.option.value;
230
+ this.#known.set(value, row.option);
231
+ }
232
+ if (this.multiple) {
233
+ this.values = this.values.includes(value) ? this.values.filter((v) => v !== value) : [...this.values, value];
234
+ this._query = '';
235
+ this._typing = false;
236
+ this.emit('pm-change', { value: this.values.join(','), values: this.values });
237
+ }
238
+ else {
239
+ this.value = value;
240
+ this.#close();
241
+ this.emit('pm-change', { value });
242
+ }
243
+ }
244
+ #remove(v) {
245
+ this.values = this.values.filter((x) => x !== v);
246
+ this.emit('pm-change', { value: this.values.join(','), values: this.values });
247
+ this.control?.focus();
248
+ }
249
+ #clear() {
250
+ if (this.multiple)
251
+ this.values = [];
252
+ else
253
+ this.value = '';
254
+ this._query = '';
255
+ this.emit('pm-change', { value: '', values: [] });
256
+ this.control?.focus();
257
+ }
258
+ #onInput(e) {
259
+ this._query = e.target.value;
260
+ this._typing = true;
261
+ this.emit('pm-search', { query: this._query });
262
+ if (this.#isRemote) {
263
+ if (this._query.trim().length >= this.minChars)
264
+ this.#remote.request(this._query.trim());
265
+ else {
266
+ this.#remote.cancel();
267
+ this.options = [];
268
+ this.#loadedFor = undefined;
269
+ }
270
+ }
271
+ if (!this._open)
272
+ this.#open();
273
+ this._active = this.#nextEnabled(this.#rows, -1, 1);
274
+ }
275
+ #onKey(e) {
276
+ const rows = this.#rows;
277
+ switch (e.key) {
278
+ case 'ArrowDown':
279
+ e.preventDefault();
280
+ if (!this._open)
281
+ this.#open();
282
+ else
283
+ this._active = this.#nextEnabled(rows, this._active, 1);
284
+ break;
285
+ case 'ArrowUp':
286
+ e.preventDefault();
287
+ if (!this._open) {
288
+ this.#open();
289
+ this._active = this.#nextEnabled(rows, 0, -1);
290
+ }
291
+ else
292
+ this._active = this.#nextEnabled(rows, this._active, -1);
293
+ break;
294
+ case 'Enter':
295
+ if (this._open && rows[this._active]) {
296
+ e.preventDefault();
297
+ this.#choose(rows[this._active]);
298
+ }
299
+ break;
300
+ case 'Escape':
301
+ if (this._open) {
302
+ e.preventDefault();
303
+ e.stopPropagation();
304
+ this.#close();
305
+ }
306
+ else if (this._query) {
307
+ this._query = '';
308
+ this._typing = false;
309
+ }
310
+ break;
311
+ case 'Backspace':
312
+ if (this.multiple && !this._query && this.values.length)
313
+ this.#remove(this.values[this.values.length - 1]);
314
+ break;
315
+ case 'Tab':
316
+ this.#close();
317
+ break;
318
+ }
319
+ }
320
+ #onFocusOut = (e) => {
321
+ if (e.relatedTarget && this.contains(e.relatedTarget))
322
+ return;
323
+ if (e.relatedTarget && this.renderRoot.contains(e.relatedTarget))
324
+ return;
325
+ this.#close();
326
+ this.onBlur();
327
+ };
328
+ #highlight(label) {
329
+ const q = this._typing ? this._query.trim() : '';
330
+ const i = q ? label.toLowerCase().indexOf(q.toLowerCase()) : -1;
331
+ if (i < 0)
332
+ return label;
333
+ return html `${label.slice(0, i)}<mark>${label.slice(i, i + q.length)}</mark>${label.slice(i + q.length)}`;
334
+ }
335
+ render() {
336
+ const rows = this.#rows;
337
+ const inputText = this._typing || this.multiple ? this._query : this.value ? this.#label(this.value) : this._query;
338
+ const hasValue = this.multiple ? this.values.length > 0 : !!this.value;
339
+ const activeId = this._open && this._active >= 0 ? `${this.#listId}-${this._active}` : undefined;
340
+ let lastGroup;
341
+ const list = rows.map((r, i) => {
342
+ const id = `${this.#listId}-${i}`;
343
+ if (r.kind === 'create') {
344
+ return html `<li class="pm-option" role="option" id=${id} aria-selected="false" ?data-active=${i === this._active}
345
+ @pointerdown=${(e) => e.preventDefault()} @click=${() => this.#choose(r)}>
346
+ <span class="pm-option-check" aria-hidden="true">+</span><span class="pm-option-label">Create “${r.query}”</span></li>`;
347
+ }
348
+ const o = r.option;
349
+ const header = o.group && o.group !== lastGroup ? html `<li class="pm-listbox-group" role="presentation">${o.group}</li>` : nothing;
350
+ lastGroup = o.group;
351
+ return html `${header}<li class="pm-option" role="option" id=${id} aria-selected=${this.#isSelected(o.value) ? 'true' : 'false'}
352
+ aria-disabled=${o.disabled ? 'true' : nothing} ?data-active=${i === this._active}
353
+ @pointerdown=${(e) => e.preventDefault()} @pointermove=${() => { if (this._active !== i && !o.disabled)
354
+ this._active = i; }} @click=${() => this.#choose(r)}>
355
+ <span class="pm-option-check">${CHECK}</span><span class="pm-option-label">${this.#highlight(o.label)}</span>
356
+ ${o.description ? html `<span class="pm-option-hint">${o.description}</span>` : nothing}</li>`;
357
+ });
358
+ const remote = this.#isRemote;
359
+ const tooShort = remote && this._query.trim().length < this.minChars && !rows.length;
360
+ const failed = remote && !!this.#remote.error && !this.#remote.pending;
361
+ const status = this.loading || this.#remote.pending ? 'Loading…' : failed ? "Couldn't load results." : tooShort
362
+ ? (this.minChars > 1 ? `Type at least ${this.minChars} characters to search` : 'Type to search') : rows.length ? '' : this.emptyText;
363
+ return this.field(html `<div class="pm-input pm-combobox" part="box" data-size=${ifDefined(this.size)} ?data-invalid=${this.showInvalid} ?data-disabled=${this.disabled}
364
+ @click=${() => { this.control?.focus(); this.#open(); }}>
365
+ ${this.multiple ? this.values.map((v) => html `<span class="pm-tag" data-size="sm" part="tag">${this.#label(v)}<button type="button" class="pm-tag-remove"
366
+ aria-label=${`Remove ${this.#label(v)}`} tabindex="-1" ?disabled=${this.disabled} @click=${(e) => { e.stopPropagation(); this.#remove(v); }}>✕</button></span>`) : nothing}
367
+ <input data-control part="control" id=${this.controlId} role="combobox" type="text" autocomplete="off" spellcheck="false"
368
+ .value=${live(inputText)} placeholder=${ifDefined(hasValue && this.multiple ? undefined : this.placeholder)}
369
+ aria-expanded=${this._open ? 'true' : 'false'} aria-controls=${this.#listId} aria-autocomplete="list" aria-haspopup="listbox" aria-busy=${this.#remote.pending ? 'true' : nothing}
370
+ aria-activedescendant=${ifDefined(activeId)} aria-invalid=${this.showInvalid ? 'true' : nothing} aria-describedby=${ifDefined(this.describedBy())}
371
+ ?required=${this.required} ?disabled=${this.disabled} ?readonly=${this.readonly}
372
+ @input=${this.#onInput} @keydown=${this.#onKey} />
373
+ <span class="pm-combobox-icon">${this.clearable && hasValue && !this.disabled
374
+ ? html `<button type="button" class="pm-input-action pm-combobox-clear" aria-label="Clear selection" tabindex="-1" @click=${(e) => { e.stopPropagation(); this.#clear(); }}>✕</button>`
375
+ : CHEVRON}</span>
376
+ </div>
377
+ <div class="pm-listbox-popup" popover="manual" part="popup">
378
+ <ul class="pm-listbox" role="listbox" id=${this.#listId} aria-label=${ifDefined(this.label)} aria-multiselectable=${this.multiple ? 'true' : nothing}>${list}</ul>
379
+ ${status ? html `<div class="pm-listbox-empty" role="status" ?data-error=${failed}>${status}${failed
380
+ ? html ` <button type="button" class="pm-listbox-retry" @pointerdown=${(e) => e.preventDefault()} @click=${() => this.#remote.retry()}>Retry</button>` : nothing}</div>` : nothing}
381
+ </div>`);
382
+ }
383
+ }
384
+ defineElement('pm-combobox', PmCombobox);
@@ -0,0 +1,96 @@
1
+ import { type PropertyDeclarations, type PropertyValues } from 'lit';
2
+ import { PmElement, SafeHTMLElement } from '../base.js';
3
+ import { type Loader } from '../remote.js';
4
+ export interface CommandItem {
5
+ value: string;
6
+ label: string;
7
+ group?: string;
8
+ /** Extra words that match the search (synonyms). */
9
+ keywords?: string[];
10
+ /** Shortcut hint, e.g. "⌘ N". */
11
+ shortcut?: string;
12
+ /** Navigate here when chosen. */
13
+ href?: string;
14
+ disabled?: boolean;
15
+ }
16
+ /** Server search for the palette: `async (query, { signal }) => items` (raw items are mapped with `mapItem` / `*-key`). */
17
+ export type CommandLoader = Loader<string, unknown>;
18
+ /** Fuzzy score: substring beats subsequence; 0 = no match. */
19
+ export declare function commandScore(item: CommandItem, query: string): number;
20
+ /**
21
+ * Command palette (⌘K / Ctrl+K): a modal search over actions and pages, grouped, fuzzy-matched, keyboard driven.
22
+ *
23
+ * Items come from child `<pm-command-item>` elements or the `items` property. Open with the shortcut, `el.show()`,
24
+ * or an invoker: `<pm-button commandfor="cmd" command="--open">`.
25
+ *
26
+ * Server search: set `src` (`src="/api/search?q={query}"`, with `items-path`, `value-key`, `label-key`,
27
+ * `group-key`, `href-key`) or the `loader` property (`async (query, { signal }) => items`, `mapItem` to format).
28
+ * Local commands still match instantly; server results follow under their own group (`results-group`), debounced,
29
+ * with loading and error (Retry) states.
30
+ * @tag pm-command
31
+ * @fires pm-select - An item was chosen. detail: { value, item }
32
+ * @fires pm-open - Opened.
33
+ * @fires pm-close - Closed.
34
+ * @fires pm-load - Server results arrived. detail: { query, items }
35
+ * @fires pm-load-error - A server search failed. detail: { query, error }
36
+ * @example <pm-command><pm-command-item value="new" group="Actions" shortcut="⌘ N">New project</pm-command-item><pm-command-item value="settings" group="Pages" href="/settings">Settings</pm-command-item></pm-command>
37
+ */
38
+ export declare class PmCommand extends PmElement {
39
+ #private;
40
+ static componentName: string;
41
+ static styles: import("lit").CSSResult[];
42
+ static properties: PropertyDeclarations;
43
+ open: boolean;
44
+ items: CommandItem[];
45
+ placeholder: string;
46
+ label: string;
47
+ /** Global shortcut ("mod+k" by default; "mod" is ⌘ on Apple, Ctrl elsewhere). Set to "" to disable. */
48
+ shortcut: string;
49
+ emptyText: string;
50
+ /** Search URL; `{query}` is replaced with the URL-encoded text. Response: JSON. */
51
+ src?: string;
52
+ /** Your own search function (takes precedence over `src`). */
53
+ loader?: CommandLoader;
54
+ /** Turn one server item into a command item. */
55
+ mapItem?: (item: unknown) => CommandItem;
56
+ /** Where the list is in the response (dotted path; empty = the response itself). */
57
+ itemsPath?: string;
58
+ /** Item field for the value (default `value`, then `id`). */
59
+ valueKey?: string;
60
+ /** Item field for the label (default `label`, then `name`, then `title`). */
61
+ labelKey?: string;
62
+ /** Item field for the group heading (default: `results-group`). */
63
+ groupKey?: string;
64
+ /** Item field for a link to open (default `href`, then `url`). */
65
+ hrefKey?: string;
66
+ /** Group heading for server results without their own group. */
67
+ resultsGroup: string;
68
+ /** Milliseconds to wait after typing before searching the server. */
69
+ debounce: number;
70
+ /** Characters needed before searching the server. */
71
+ minChars: number;
72
+ _remote: CommandItem[];
73
+ _query: string;
74
+ _active: number;
75
+ constructor();
76
+ connectedCallback(): void;
77
+ disconnectedCallback(): void;
78
+ show(): void;
79
+ hide(): void;
80
+ toggle(): void;
81
+ protected updated(changed: PropertyValues<this>): void;
82
+ render(): import("lit").TemplateResult<1>;
83
+ }
84
+ /**
85
+ * An action in a command palette (data only, not rendered itself).
86
+ * @tag pm-command-item
87
+ * @attr {string} value - Value reported in pm-select (defaults to the text).
88
+ * @attr {string} group - Group heading.
89
+ * @attr {string} keywords - Extra search words, space or comma separated.
90
+ * @attr {string} shortcut - Shortcut hint shown on the right, e.g. "Ctrl N".
91
+ * @attr {string} href - Navigate here when chosen.
92
+ * @attr {boolean} disabled
93
+ * @example <pm-command-item value="logout" group="Account" keywords="sign out">Log out</pm-command-item>
94
+ */
95
+ export declare class PmCommandItem extends SafeHTMLElement {
96
+ }