@prismora/elements 0.0.0-stage → 0.1.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 (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,427 @@
1
+ import { css, html, nothing } from 'lit';
2
+ import { PmElement, defineElement } from '../base.js';
3
+ import { buildUrl, fetchJson, field, isAbort, pick } from '../remote.js';
4
+ import treeCss from '../styles/tree.js';
5
+ import { namedIcon } from '../named-icon.js';
6
+ /**
7
+ * Tree view (file browsers, nested navigation).
8
+ *
9
+ * Full keyboard support per the WAI-ARIA tree pattern: ↑/↓ move, → expands or enters, ← collapses or goes to the
10
+ * parent, Home/End, Enter/Space select, type-ahead. `selection="checkbox"`: tri-state checkboxes that cascade to
11
+ * children and parents (Space toggles; `values` lists checked leaves). `filter` shows matching items and their
12
+ * ancestors, highlighted. `lazy` items load children on first expand (`pm-load`).
13
+ *
14
+ * Children from an API: set `src` (`src="/api/folders/{value}/children"`, `{value}` is the expanded item's value)
15
+ * or the `loader` property (`async (item, { signal }) => items`); the tree then builds the child items itself from
16
+ * `label-key`, `value-key`, `lazy-key` (has children to load), `icon-key` and `children-key` (nested items), or from
17
+ * `mapItem`. Failures collapse the item again and fire `pm-load-error`.
18
+ * @tag pm-tree
19
+ * @slot - `pm-tree-item` elements (nest them for children).
20
+ * @fires pm-select - An item was selected. detail: { value, item }
21
+ * @fires pm-check - Checkboxes changed. detail: { values, item, checked }
22
+ * @fires pm-load - A `lazy` item was expanded for the first time; append its children (done for you with `src` / `loader`). detail: { item, value }
23
+ * @fires pm-load-error - Loading children failed. detail: { item, value, error }
24
+ * @example <pm-tree label="Files"><pm-tree-item label="src" expanded><pm-tree-item label="index.ts" value="src/index.ts"></pm-tree-item></pm-tree-item><pm-tree-item label="README.md"></pm-tree-item></pm-tree>
25
+ */
26
+ export class PmTree extends PmElement {
27
+ static { this.componentName = 'tree'; }
28
+ static { this.styles = [...PmElement.styles, treeCss, css `:host { display: block; } .pm-tree-empty { margin: 0; padding: var(--pm-space-3); color: var(--pm-color-fg-muted); font-size: var(--pm-font-size-sm); }`]; }
29
+ static { this.properties = { label: {}, value: { reflect: true }, selection: { reflect: true }, filter: {}, emptyText: { attribute: 'empty-text' }, _empty: { state: true },
30
+ src: {}, loader: { attribute: false }, mapItem: { attribute: false }, childrenPath: { attribute: 'children-path' }, labelKey: { attribute: 'label-key' },
31
+ valueKey: { attribute: 'value-key' }, lazyKey: { attribute: 'lazy-key' }, iconKey: { attribute: 'icon-key' }, childrenKey: { attribute: 'children-key' } }; }
32
+ #loads = new AbortController();
33
+ #saved = new Map();
34
+ #seeded = false;
35
+ get #checkbox() { return this.selection === 'checkbox'; }
36
+ /** Values of checked leaf items (checkbox mode). */
37
+ get values() { return [...this.querySelectorAll('pm-tree-item')].filter((i) => i.checked && i.isLeaf).map((i) => i.itemValue); }
38
+ /** Check the leaves with these values (checkbox mode). */
39
+ set values(v) {
40
+ const want = new Set(v);
41
+ for (const i of this.querySelectorAll('pm-tree-item'))
42
+ if (i.isLeaf)
43
+ i.checked = want.has(i.itemValue);
44
+ this.#derive();
45
+ }
46
+ /** Check or uncheck an item and everything under it; parents become checked, unchecked or mixed. */
47
+ setChecked(item, checked) {
48
+ if (item.disabled)
49
+ return;
50
+ item.checked = checked;
51
+ item.indeterminate = false;
52
+ for (const d of item.querySelectorAll('pm-tree-item'))
53
+ if (!d.disabled) {
54
+ d.checked = checked;
55
+ d.indeterminate = false;
56
+ }
57
+ this.#derive();
58
+ this.emit('pm-check', { values: this.values, item, checked });
59
+ }
60
+ /** Recompute branch states bottom-up from their children. */
61
+ #derive() {
62
+ const all = [...this.querySelectorAll('pm-tree-item')].reverse();
63
+ for (const it of all) {
64
+ const kids = it.childItems();
65
+ if (!kids.length)
66
+ continue;
67
+ const on = kids.filter((k) => k.checked).length;
68
+ const mixed = kids.some((k) => k.indeterminate);
69
+ it.checked = on === kids.length && !mixed;
70
+ it.indeterminate = !it.checked && (on > 0 || mixed);
71
+ }
72
+ }
73
+ #applyFilter(all) {
74
+ const q = this.filter?.trim().toLowerCase() ?? '';
75
+ if (!q) {
76
+ if (this.#saved.size) {
77
+ for (const [it, exp] of this.#saved)
78
+ it.expanded = exp;
79
+ this.#saved.clear();
80
+ }
81
+ for (const it of all)
82
+ it.hidden = false;
83
+ this._empty = false;
84
+ return;
85
+ }
86
+ const show = new Set();
87
+ for (const it of all) {
88
+ if (!it.labelText.toLowerCase().includes(q))
89
+ continue;
90
+ show.add(it);
91
+ let p = it.parentElement;
92
+ while (p instanceof PmTreeItem) {
93
+ show.add(p);
94
+ if (!this.#saved.has(p))
95
+ this.#saved.set(p, p.expanded);
96
+ p.expanded = true;
97
+ p = p.parentElement;
98
+ }
99
+ }
100
+ for (const it of all)
101
+ it.hidden = !show.has(it);
102
+ this._empty = show.size === 0;
103
+ }
104
+ #typed = '';
105
+ #typedTimer;
106
+ connectedCallback() {
107
+ super.connectedCallback();
108
+ this.setAttribute('role', 'tree');
109
+ this.addEventListener('keydown', this.#onKey);
110
+ this.addEventListener('pm-tree-activate', this.#onActivate);
111
+ this.addEventListener('focusin', this.#onFocus);
112
+ this.addEventListener('pm-load', this.#onLoad);
113
+ this.#loads = new AbortController();
114
+ }
115
+ disconnectedCallback() {
116
+ super.disconnectedCallback();
117
+ this.#loads.abort();
118
+ }
119
+ #toData(raw) {
120
+ if (this.mapItem)
121
+ return this.mapItem(raw);
122
+ if (raw == null || typeof raw !== 'object')
123
+ return { label: String(raw), value: String(raw) };
124
+ const label = String(field(raw, [this.labelKey, 'label', 'name', 'title']) ?? '');
125
+ const kids = field(raw, [this.childrenKey, 'children']);
126
+ const icon = field(raw, [this.iconKey, 'icon']);
127
+ return {
128
+ label, value: String(field(raw, [this.valueKey, 'value', 'id']) ?? label),
129
+ lazy: !!field(raw, [this.lazyKey, 'lazy', 'hasChildren']), ...(icon ? { icon: String(icon) } : {}),
130
+ ...(Array.isArray(kids) ? { children: kids.map((k) => this.#toData(k)) } : {}),
131
+ };
132
+ }
133
+ /** Append tree items built from data to a parent item (or the tree). */
134
+ appendItems(parent, items) {
135
+ const make = (d) => {
136
+ const el = document.createElement('pm-tree-item');
137
+ el.label = d.label;
138
+ if (d.value !== undefined)
139
+ el.value = d.value;
140
+ if (d.lazy)
141
+ el.lazy = true;
142
+ if (d.icon)
143
+ el.icon = d.icon;
144
+ for (const c of d.children ?? [])
145
+ el.append(make(c));
146
+ return el;
147
+ };
148
+ parent.append(...items.map(make));
149
+ }
150
+ #onLoad = async (e) => {
151
+ if (!this.loader && !this.src)
152
+ return;
153
+ const { item, value } = e.detail;
154
+ const signal = this.#loads.signal;
155
+ try {
156
+ const data = this.loader ? await this.loader({ value, item }, { signal }) : await fetchJson(buildUrl(this.src, { value }), signal);
157
+ const list = pick(data, this.childrenPath);
158
+ if (!Array.isArray(list))
159
+ throw new Error(`Expected a list${this.childrenPath ? ` at "${this.childrenPath}"` : ''} of children`);
160
+ if (list.length)
161
+ this.appendItems(item, list.map((x) => this.#toData(x)));
162
+ else {
163
+ item.lazy = false;
164
+ item.expanded = false;
165
+ }
166
+ item.loading = false;
167
+ }
168
+ catch (error) {
169
+ if (isAbort(error))
170
+ return;
171
+ item.loading = false;
172
+ item.expanded = false;
173
+ this.emit('pm-load-error', { item, value, error });
174
+ }
175
+ };
176
+ render() {
177
+ if (this.label)
178
+ this.setAttribute('aria-label', this.label);
179
+ if (this.#checkbox)
180
+ this.setAttribute('aria-multiselectable', 'true');
181
+ else
182
+ this.removeAttribute('aria-multiselectable');
183
+ return html `<div class="pm-tree" part="base"><slot @slotchange=${this.#sync}></slot>
184
+ ${this._empty ? html `<p class="pm-tree-empty" role="status">${this.emptyText ?? 'No matches'}</p>` : nothing}</div>`;
185
+ }
186
+ updated() { this.#sync(); }
187
+ /** Items currently visible (ancestors expanded), in order. */
188
+ visibleItems() {
189
+ const out = [];
190
+ const walk = (parent) => {
191
+ for (const c of parent.children) {
192
+ if (!(c instanceof PmTreeItem) || c.hidden)
193
+ continue;
194
+ out.push(c);
195
+ if (c.expanded)
196
+ walk(c);
197
+ }
198
+ };
199
+ walk(this);
200
+ return out;
201
+ }
202
+ #sync = () => {
203
+ const all = [...this.querySelectorAll('pm-tree-item')];
204
+ if (this.value !== undefined && !this.#checkbox)
205
+ for (const it of all)
206
+ it.selected = it.itemValue === this.value;
207
+ if (this.#checkbox) {
208
+ if (!this.#seeded) {
209
+ for (const it of all)
210
+ if (it.checked)
211
+ for (const d of it.querySelectorAll('pm-tree-item'))
212
+ d.checked = true;
213
+ this.#seeded = true;
214
+ }
215
+ this.#derive();
216
+ }
217
+ this.#applyFilter(all);
218
+ for (const it of all)
219
+ it.requestUpdate();
220
+ const visible = this.visibleItems();
221
+ const active = visible.find((i) => i.selected) ?? visible[0];
222
+ for (const it of all)
223
+ it.tabIndex = it === active ? 0 : -1;
224
+ };
225
+ #focusItem(it) {
226
+ if (!it)
227
+ return;
228
+ for (const i of this.querySelectorAll('pm-tree-item'))
229
+ i.tabIndex = -1;
230
+ it.tabIndex = 0;
231
+ it.focus();
232
+ }
233
+ #onFocus = (e) => {
234
+ const it = e.target.closest?.('pm-tree-item');
235
+ if (it instanceof PmTreeItem)
236
+ for (const i of this.querySelectorAll('pm-tree-item'))
237
+ i.tabIndex = i === it ? 0 : -1;
238
+ };
239
+ #onActivate = (e) => {
240
+ if (this.#checkbox)
241
+ this.setChecked(e.detail.item, !e.detail.item.checked);
242
+ else
243
+ this.select(e.detail.item);
244
+ };
245
+ /** Select an item (emits pm-select). */
246
+ select(item) {
247
+ if (item.disabled)
248
+ return;
249
+ for (const i of this.querySelectorAll('pm-tree-item'))
250
+ i.selected = i === item;
251
+ this.value = item.itemValue;
252
+ this.emit('pm-select', { value: item.itemValue, item });
253
+ }
254
+ #onKey = (e) => {
255
+ const cur = e.target.closest?.('pm-tree-item');
256
+ if (!(cur instanceof PmTreeItem))
257
+ return;
258
+ const vis = this.visibleItems();
259
+ const i = vis.indexOf(cur);
260
+ const rtl = getComputedStyle(this).direction === 'rtl';
261
+ const key = rtl ? { ArrowLeft: 'ArrowRight', ArrowRight: 'ArrowLeft' }[e.key] ?? e.key : e.key;
262
+ const parent = cur.parentElement instanceof PmTreeItem ? cur.parentElement : undefined;
263
+ switch (key) {
264
+ case 'ArrowDown':
265
+ this.#focusItem(vis[i + 1]);
266
+ break;
267
+ case 'ArrowUp':
268
+ this.#focusItem(vis[i - 1]);
269
+ break;
270
+ case 'Home':
271
+ this.#focusItem(vis[0]);
272
+ break;
273
+ case 'End':
274
+ this.#focusItem(vis[vis.length - 1]);
275
+ break;
276
+ case 'ArrowRight':
277
+ if (!cur.isLeaf && !cur.expanded)
278
+ cur.toggle(true);
279
+ else if (!cur.isLeaf)
280
+ this.#focusItem(cur.childItems()[0]);
281
+ break;
282
+ case 'ArrowLeft':
283
+ if (!cur.isLeaf && cur.expanded)
284
+ cur.toggle(false);
285
+ else
286
+ this.#focusItem(parent);
287
+ break;
288
+ case ' ':
289
+ if (this.#checkbox) {
290
+ this.setChecked(cur, !cur.checked);
291
+ break;
292
+ }
293
+ this.select(cur);
294
+ break;
295
+ case 'Enter':
296
+ this.select(cur);
297
+ break;
298
+ default:
299
+ if (e.key.length === 1 && /\S/.test(e.key) && !e.ctrlKey && !e.metaKey && !e.altKey) {
300
+ this.#typed += e.key.toLowerCase();
301
+ clearTimeout(this.#typedTimer);
302
+ this.#typedTimer = setTimeout(() => (this.#typed = ''), 500);
303
+ const order = [...vis.slice(i + 1), ...vis.slice(0, i + 1)];
304
+ this.#focusItem(order.find((it) => it.labelText.toLowerCase().startsWith(this.#typed)));
305
+ break;
306
+ }
307
+ return;
308
+ }
309
+ e.preventDefault();
310
+ };
311
+ }
312
+ /**
313
+ * Tree node. Nest `pm-tree-item`s inside to make a branch.
314
+ * @tag pm-tree-item
315
+ * @slot - Child `pm-tree-item` elements.
316
+ * @slot icon - Icon before the label.
317
+ * @slot end - Trailing content (count, badge, actions).
318
+ * @fires pm-toggle - Branch expanded or collapsed. detail: { expanded }
319
+ * @example <pm-tree-item label="Documents" expanded><pm-tree-item label="Report.pdf"></pm-tree-item></pm-tree-item>
320
+ */
321
+ export class PmTreeItem extends PmElement {
322
+ static { this.componentName = 'tree-item'; }
323
+ static { this.styles = [...PmElement.styles, treeCss, css `
324
+ :host { display: block; outline: none; }
325
+ :host([hidden]) { display: none; }
326
+ :host(:focus-visible) > .pm-tree-row { outline: 2px solid var(--pm-color-ring); outline-offset: -2px; }
327
+ :host([disabled]) > .pm-tree-row { opacity: 0.5; cursor: not-allowed; }
328
+ `]; }
329
+ static { this.properties = { icon: { reflect: true },
330
+ label: {}, value: {}, expanded: { type: Boolean, reflect: true }, selected: { type: Boolean, reflect: true }, disabled: { type: Boolean, reflect: true },
331
+ checked: { type: Boolean, reflect: true }, indeterminate: { type: Boolean, reflect: true }, lazy: { type: Boolean, reflect: true }, loading: { type: Boolean, reflect: true },
332
+ _hasChildren: { state: true },
333
+ }; }
334
+ constructor() { super(); this.expanded = false; this.selected = false; this.disabled = false; this.checked = false; this.indeterminate = false; this.lazy = false; this.loading = false; this._hasChildren = false; }
335
+ get itemValue() { return this.value ?? this.labelText; }
336
+ get labelText() { return this.label ?? ''; }
337
+ get isLeaf() { return this.childItems().length === 0 && !this.lazy; }
338
+ childItems() { return [...this.children].filter((c) => c instanceof PmTreeItem); }
339
+ get depth() { let d = 0; let p = this.parentElement; while (p instanceof PmTreeItem) {
340
+ d++;
341
+ p = p.parentElement;
342
+ } return d; }
343
+ connectedCallback() { super.connectedCallback(); this.setAttribute('role', 'treeitem'); }
344
+ /** Expand (true), collapse (false) or toggle. */
345
+ toggle(force) {
346
+ if (this.isLeaf)
347
+ return;
348
+ const next = force ?? !this.expanded;
349
+ if (next === this.expanded)
350
+ return;
351
+ this.expanded = next;
352
+ this.emit('pm-toggle', { expanded: next });
353
+ if (next && this.lazy && !this.childItems().length && !this.loading) {
354
+ this.loading = true;
355
+ this.emit('pm-load', { item: this, value: this.itemValue });
356
+ }
357
+ }
358
+ updated() {
359
+ this.setAttribute('aria-level', String(this.depth + 1));
360
+ const tree = this.closest('pm-tree');
361
+ if (tree?.selection === 'checkbox') {
362
+ this.setAttribute('aria-checked', this.indeterminate ? 'mixed' : String(this.checked));
363
+ this.removeAttribute('aria-selected');
364
+ }
365
+ else {
366
+ this.removeAttribute('aria-checked');
367
+ this.setAttribute('aria-selected', String(this.selected));
368
+ }
369
+ if (this.loading)
370
+ this.setAttribute('aria-busy', 'true');
371
+ else
372
+ this.removeAttribute('aria-busy');
373
+ if (this._hasChildren || this.lazy)
374
+ this.setAttribute('aria-expanded', String(this.expanded));
375
+ else
376
+ this.removeAttribute('aria-expanded');
377
+ if (this.disabled)
378
+ this.setAttribute('aria-disabled', 'true');
379
+ else
380
+ this.removeAttribute('aria-disabled');
381
+ if (this.label)
382
+ this.setAttribute('aria-label', this.label);
383
+ }
384
+ #label() {
385
+ const tree = this.closest('pm-tree');
386
+ const q = tree?.filter?.trim().toLowerCase();
387
+ const text = this.label ?? '';
388
+ const i = q ? text.toLowerCase().indexOf(q) : -1;
389
+ return i < 0 ? text : html `${text.slice(0, i)}<mark class="pm-tree-mark">${text.slice(i, i + q.length)}</mark>${text.slice(i + q.length)}`;
390
+ }
391
+ render() {
392
+ const tree = this.closest('pm-tree');
393
+ const box = tree?.selection === 'checkbox';
394
+ return html `<div class="pm-tree-row" part="row" style="--_depth: ${this.depth}" ?data-selected=${this.selected && !box}
395
+ @click=${this.#onRow}>
396
+ <span class="pm-tree-toggle" part="toggle" ?data-open=${this.expanded} ?data-leaf=${!this._hasChildren && !this.lazy}
397
+ @click=${this.#onToggle} aria-hidden="true">${this.loading
398
+ ? html `<span class="pm-tree-spinner"></span>`
399
+ : html `<svg viewBox="0 0 24 24" width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 6l6 6-6 6"/></svg>`}</span>
400
+ ${box ? html `<span class="pm-tree-check" part="checkbox" aria-hidden="true" data-state=${this.indeterminate ? 'mixed' : this.checked ? 'checked' : 'unchecked'}>${this.indeterminate
401
+ ? html `<svg viewBox="0 0 24 24" width="0.8em" height="0.8em" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round"><path d="M6 12h12"/></svg>`
402
+ : this.checked ? html `<svg viewBox="0 0 24 24" width="0.8em" height="0.8em" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>` : nothing}</span>` : nothing}
403
+ <slot name="icon">${namedIcon(this.icon)}</slot>
404
+ <span part="label" style="flex: 1; min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap">${this.#label()}</span>
405
+ <slot name="end"></slot>
406
+ </div>
407
+ <div class="pm-tree-group" role="group" part="group" ?hidden=${!this.expanded}><slot @slotchange=${this.#onChildren}></slot></div>`;
408
+ }
409
+ #onChildren = () => {
410
+ this._hasChildren = this.childItems().length > 0;
411
+ if (this._hasChildren && this.loading)
412
+ this.loading = false;
413
+ };
414
+ #onToggle = (e) => { e.stopPropagation(); this.toggle(); this.focus(); };
415
+ #onRow = (e) => {
416
+ if (this.disabled)
417
+ return;
418
+ e.stopPropagation();
419
+ this.focus();
420
+ const box = this.closest('pm-tree')?.selection === 'checkbox';
421
+ if (!this.isLeaf && !box)
422
+ this.toggle();
423
+ this.emit('pm-tree-activate', { item: this }, { composed: false });
424
+ };
425
+ }
426
+ defineElement('pm-tree', PmTree);
427
+ defineElement('pm-tree-item', PmTreeItem);
@@ -0,0 +1,41 @@
1
+ import { type PropertyDeclarations, type TemplateResult } from 'lit';
2
+ import { PmElement } from '../base.js';
3
+ /**
4
+ * List for thousands of rows: only the rows in view exist in the page, so scrolling stays fast.
5
+ *
6
+ * Give it `items` and, for anything richer than text, a `renderItem` function. Every row has the same height
7
+ * (`item-height`). Rows carry their position ("row 120 of 5,000") for screen readers, and `pm-end` fires near the
8
+ * end so more rows can be loaded.
9
+ * @tag pm-virtual-list
10
+ * @fires pm-end - The end of the list is in view (load more here). detail: { count }
11
+ * @fires pm-select - A row was activated by click or Enter. detail: { item, index }
12
+ * @example <pm-virtual-list label="Log lines" item-height="36"></pm-virtual-list>
13
+ */
14
+ export declare class PmVirtualList extends PmElement {
15
+ #private;
16
+ static componentName: string;
17
+ static styles: import("lit").CSSResult[];
18
+ static properties: PropertyDeclarations;
19
+ /** The rows: strings, numbers or objects (objects need `renderItem`, or have a `label`). */
20
+ items: unknown[];
21
+ /** Height of every row in pixels (default 40). */
22
+ itemHeight: number;
23
+ /** Height of the list: any CSS length (default 20rem). */
24
+ height?: string;
25
+ /** Accessible name of the list. */
26
+ label?: string;
27
+ /** Extra rows kept above and below the visible ones (default 4). */
28
+ overscan: number;
29
+ /** Shown when there are no items. */
30
+ emptyText: string;
31
+ /** Returns a row's content: a string of trusted HTML or a Lit template. Property only. */
32
+ renderItem?: (item: unknown, index: number) => string | TemplateResult;
33
+ _top: number;
34
+ _view: number;
35
+ constructor();
36
+ firstUpdated(): void;
37
+ disconnectedCallback(): void;
38
+ /** Scroll a row into view. */
39
+ scrollToIndex(index: number, behavior?: ScrollBehavior): void;
40
+ render(): TemplateResult<1>;
41
+ }
@@ -0,0 +1,77 @@
1
+ import { css, html, nothing } from 'lit';
2
+ import { unsafeHTML } from 'lit/directives/unsafe-html.js';
3
+ import { PmElement, defineElement } from '../base.js';
4
+ import extrasCss from '../styles/extras.js';
5
+ /**
6
+ * List for thousands of rows: only the rows in view exist in the page, so scrolling stays fast.
7
+ *
8
+ * Give it `items` and, for anything richer than text, a `renderItem` function. Every row has the same height
9
+ * (`item-height`). Rows carry their position ("row 120 of 5,000") for screen readers, and `pm-end` fires near the
10
+ * end so more rows can be loaded.
11
+ * @tag pm-virtual-list
12
+ * @fires pm-end - The end of the list is in view (load more here). detail: { count }
13
+ * @fires pm-select - A row was activated by click or Enter. detail: { item, index }
14
+ * @example <pm-virtual-list label="Log lines" item-height="36"></pm-virtual-list>
15
+ */
16
+ export class PmVirtualList extends PmElement {
17
+ static { this.componentName = 'virtual-list'; }
18
+ static { this.styles = [...PmElement.styles, extrasCss, css `:host { display: block; min-inline-size: 0; } :host([hidden]) { display: none; }`]; }
19
+ static { this.properties = {
20
+ items: { type: Array }, itemHeight: { type: Number, attribute: 'item-height' }, height: {}, label: {}, overscan: { type: Number },
21
+ emptyText: { attribute: 'empty-text' }, renderItem: { attribute: false }, _top: { state: true }, _view: { state: true },
22
+ }; }
23
+ #resize;
24
+ #endAt = -1;
25
+ constructor() { super(); this.items = []; this.itemHeight = 40; this.overscan = 4; this.emptyText = 'Nothing to show'; this._top = 0; this._view = 320; }
26
+ firstUpdated() {
27
+ const box = this.renderRoot.querySelector('.pm-vlist');
28
+ this._view = box.clientHeight;
29
+ this.#resize = new ResizeObserver(() => { this._view = box.clientHeight; });
30
+ this.#resize.observe(box);
31
+ }
32
+ disconnectedCallback() { super.disconnectedCallback(); this.#resize?.disconnect(); }
33
+ /** Scroll a row into view. */
34
+ scrollToIndex(index, behavior = 'auto') {
35
+ this.renderRoot.querySelector('.pm-vlist')?.scrollTo({ top: Math.max(0, Math.min(index, this.items.length - 1)) * this.itemHeight, behavior });
36
+ }
37
+ #onScroll = (e) => {
38
+ const box = e.currentTarget;
39
+ this._top = box.scrollTop;
40
+ const n = this.items.length;
41
+ if (n && box.scrollTop + box.clientHeight >= n * this.itemHeight - this.itemHeight * 2 && this.#endAt !== n) {
42
+ this.#endAt = n;
43
+ this.emit('pm-end', { count: n });
44
+ }
45
+ };
46
+ #onKey = (e) => {
47
+ const box = e.currentTarget;
48
+ const page = Math.max(1, Math.floor(box.clientHeight / this.itemHeight) - 1) * this.itemHeight;
49
+ const to = e.key === 'Home' ? 0 : e.key === 'End' ? box.scrollHeight : e.key === 'PageDown' ? box.scrollTop + page : e.key === 'PageUp' ? box.scrollTop - page : null;
50
+ if (to !== null) {
51
+ e.preventDefault();
52
+ box.scrollTo({ top: to });
53
+ }
54
+ };
55
+ #text(item) {
56
+ return item !== null && typeof item === 'object' ? String(item.label ?? '') : String(item ?? '');
57
+ }
58
+ render() {
59
+ const n = this.items.length;
60
+ const h = Math.max(1, this.itemHeight);
61
+ const first = Math.max(0, Math.floor(this._top / h) - this.overscan);
62
+ const last = Math.min(n, Math.ceil((this._top + this._view) / h) + this.overscan);
63
+ const rows = [];
64
+ for (let i = first; i < last; i++) {
65
+ const item = this.items[i];
66
+ const out = this.renderItem ? this.renderItem(item, i) : this.#text(item);
67
+ rows.push(html `<div class="pm-vlist-row" part="row" role="listitem" aria-setsize=${n} aria-posinset=${i + 1} data-index=${i}
68
+ style="inset-block-start: ${i * h}px; block-size: ${h}px"
69
+ @click=${() => this.emit('pm-select', { item, index: i })}>${typeof out === 'string' ? (this.renderItem ? unsafeHTML(out) : out) : out}</div>`);
70
+ }
71
+ return html `<div class="pm-vlist" part="base" role="list" tabindex="0" aria-label=${this.label ?? nothing} style=${this.height ? `--_height: ${this.height}` : nothing}
72
+ @scroll=${this.#onScroll} @keydown=${this.#onKey}>
73
+ ${n ? html `<div class="pm-vlist-space" style="block-size: ${n * h}px">${rows}</div>` : html `<div class="pm-vlist-empty">${this.emptyText}</div>`}
74
+ </div>`;
75
+ }
76
+ }
77
+ defineElement('pm-virtual-list', PmVirtualList);
@@ -0,0 +1,21 @@
1
+ export interface ConfirmOptions {
2
+ title: string;
3
+ description?: string;
4
+ /** Label of the confirming button (default "Confirm"). */
5
+ confirmLabel?: string;
6
+ /** Label of the cancelling button (default "Cancel"). */
7
+ cancelLabel?: string;
8
+ /** `danger` for destructive actions: the confirm button turns red and Cancel takes focus. */
9
+ tone?: 'accent' | 'danger' | 'warning' | 'success';
10
+ /** Hide the cancel button (an acknowledgement: resolves true when closed with the button). */
11
+ alert?: boolean;
12
+ }
13
+ /**
14
+ * Ask the user to confirm before an action that is hard to undo. Opens a modal alert dialog (a bottom sheet in
15
+ * native phone mode) and resolves `true` when confirmed, `false` when cancelled, dismissed or closed with Escape.
16
+ * Focus returns to the element that had it.
17
+ * @example if (await confirm({ title: 'Delete project?', description: 'This cannot be undone.', confirmLabel: 'Delete', tone: 'danger' })) remove();
18
+ */
19
+ export declare function confirm(opts: ConfirmOptions | string): Promise<boolean>;
20
+ /** Tell the user something they must acknowledge. Resolves when closed. */
21
+ export declare const alert: (opts: Omit<ConfirmOptions, "alert" | "cancelLabel"> | string) => Promise<void>;
@@ -0,0 +1,69 @@
1
+ import { nextId } from './id.js';
2
+ import { adoptDocumentStyles } from './register.js';
3
+ import buttonCss from './styles/button.js';
4
+ import dialogCss from './styles/dialog.js';
5
+ import overlayCss from './styles/overlay.js';
6
+ import { closeTopLayer } from './top-layer.js';
7
+ import { isMobile, isCompact } from './sheet.js';
8
+ /**
9
+ * Ask the user to confirm before an action that is hard to undo. Opens a modal alert dialog (a bottom sheet in
10
+ * native phone mode) and resolves `true` when confirmed, `false` when cancelled, dismissed or closed with Escape.
11
+ * Focus returns to the element that had it.
12
+ * @example if (await confirm({ title: 'Delete project?', description: 'This cannot be undone.', confirmLabel: 'Delete', tone: 'danger' })) remove();
13
+ */
14
+ export function confirm(opts) {
15
+ const o = typeof opts === 'string' ? { title: opts } : opts;
16
+ adoptDocumentStyles([overlayCss, buttonCss, dialogCss]);
17
+ const d = document.createElement('dialog');
18
+ const id = nextId('confirm');
19
+ d.className = 'pm-dialog';
20
+ d.dataset.size = 'sm';
21
+ d.setAttribute('role', 'alertdialog');
22
+ d.setAttribute('aria-labelledby', `${id}-t`);
23
+ if (o.description)
24
+ d.setAttribute('aria-describedby', `${id}-d`);
25
+ if (isMobile(document.body) && isCompact())
26
+ d.setAttribute('data-sheet', '');
27
+ const header = document.createElement('header');
28
+ const h = document.createElement('h2');
29
+ h.className = 'pm-dialog-title';
30
+ h.id = `${id}-t`;
31
+ h.textContent = o.title;
32
+ header.append(h);
33
+ if (o.description) {
34
+ const p = document.createElement('p');
35
+ p.className = 'pm-dialog-description';
36
+ p.id = `${id}-d`;
37
+ p.textContent = o.description;
38
+ header.append(p);
39
+ }
40
+ const footer = document.createElement('footer');
41
+ const button = (label, value, variant, tone) => {
42
+ const b = document.createElement('button');
43
+ b.type = 'button';
44
+ b.className = 'pm-button';
45
+ b.textContent = label;
46
+ b.value = value;
47
+ if (variant)
48
+ b.dataset.variant = variant;
49
+ if (tone)
50
+ b.dataset.tone = tone;
51
+ b.addEventListener('click', () => void closeTopLayer(d, () => d.close(value)));
52
+ return b;
53
+ };
54
+ const cancel = o.alert ? undefined : button(o.cancelLabel ?? 'Cancel', 'cancel', 'outline', 'neutral');
55
+ const ok = button(o.confirmLabel ?? (o.alert ? 'OK' : 'Confirm'), 'confirm', undefined, o.tone && o.tone !== 'accent' ? o.tone : undefined);
56
+ if (cancel)
57
+ footer.append(cancel);
58
+ footer.append(ok);
59
+ d.append(header, footer);
60
+ document.body.append(d);
61
+ return new Promise((resolve) => {
62
+ d.addEventListener('close', () => { d.remove(); resolve(d.returnValue === 'confirm'); }, { once: true });
63
+ d.showModal();
64
+ // Destructive: the safe choice has focus, so Enter does not delete by accident.
65
+ (o.tone === 'danger' && cancel ? cancel : ok).focus();
66
+ });
67
+ }
68
+ /** Tell the user something they must acknowledge. Resolves when closed. */
69
+ export const alert = (opts) => confirm({ ...(typeof opts === 'string' ? { title: opts } : opts), alert: true }).then(() => undefined);
@@ -0,0 +1,5 @@
1
+ /** Count display shared by `<pm-indicator>`, tab and nav item counts. */
2
+ /** "7", or "99+" above `max`; empty for missing or negative counts. */
3
+ export declare function formatCount(count: number | undefined | null, max?: number): string;
4
+ /** Fill `{count}` in a label template ("{count} unread" → "3 unread"); the template itself if it has no placeholder. */
5
+ export declare function countLabel(template: string, count: number | undefined | null, max?: number): string;
package/dist/count.js ADDED
@@ -0,0 +1,12 @@
1
+ /** Count display shared by `<pm-indicator>`, tab and nav item counts. */
2
+ /** "7", or "99+" above `max`; empty for missing or negative counts. */
3
+ export function formatCount(count, max = 99) {
4
+ if (count == null || !Number.isFinite(count) || count < 0)
5
+ return '';
6
+ const n = Math.floor(count);
7
+ return max > 0 && n > max ? `${max}+` : String(n);
8
+ }
9
+ /** Fill `{count}` in a label template ("{count} unread" → "3 unread"); the template itself if it has no placeholder. */
10
+ export function countLabel(template, count, max = 99) {
11
+ return template.replace(/\{count\}/g, formatCount(count, max)).trim();
12
+ }
@@ -0,0 +1,8 @@
1
+ export declare const ICON: {
2
+ dots: import("lit").TemplateResult<1>;
3
+ chev: import("lit").TemplateResult<1>;
4
+ search: import("lit").TemplateResult<1>;
5
+ columns: import("lit").TemplateResult<1>;
6
+ download: import("lit").TemplateResult<1>;
7
+ pin: import("lit").TemplateResult<1>;
8
+ };