@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,23 @@
1
+ import { css, html } from 'lit';
2
+ import { PmElement, defineElement } from '../base.js';
3
+ import separatorCss from '../styles/separator.js';
4
+ /**
5
+ * Divider (separator), optionally labelled.
6
+ * @tag pm-divider
7
+ * @slot - Optional label, e.g. "or".
8
+ * @example <pm-divider>or continue with</pm-divider>
9
+ */
10
+ export class PmDivider extends PmElement {
11
+ static { this.componentName = 'divider'; }
12
+ static { this.styles = [...PmElement.styles, separatorCss, css `
13
+ :host { display: block; margin-block: var(--pm-divider-space, var(--pm-space-4)); }
14
+ :host([orientation='vertical']) { display: inline-flex; align-self: stretch; margin-block: 0; margin-inline: var(--pm-divider-space, var(--pm-space-3)); }
15
+ `]; }
16
+ static { this.properties = { orientation: { reflect: true } }; }
17
+ constructor() { super(); this.orientation = 'horizontal'; }
18
+ render() {
19
+ const empty = !this.textContent?.trim() && !this.children.length;
20
+ return html `<div class="pm-separator" part="base" role="separator" aria-orientation=${this.orientation} ?data-empty=${empty}><slot @slotchange=${() => this.requestUpdate()}></slot></div>`;
21
+ }
22
+ }
23
+ defineElement('pm-divider', PmDivider);
@@ -0,0 +1,19 @@
1
+ import { type PropertyDeclarations, type PropertyValues } from 'lit';
2
+ import { PmDialog } from './dialog.js';
3
+ /**
4
+ * Side sheet / drawer (a modal dialog anchored to an edge). `side="bottom"` is a bottom sheet with a grab handle
5
+ * that can be swiped down to close on touch screens.
6
+ * @tag pm-drawer
7
+ * @example <pm-drawer heading="Filters" side="end">…</pm-drawer>
8
+ */
9
+ export declare class PmDrawer extends PmDialog {
10
+ static styles: import("lit").CSSResult[];
11
+ static componentName: string;
12
+ static properties: PropertyDeclarations;
13
+ /** Edge the drawer slides in from: start, end (default) or bottom (a bottom sheet). */
14
+ placement: 'start' | 'end' | 'bottom' | 'top';
15
+ protected cls: string;
16
+ constructor();
17
+ protected get sheet(): boolean;
18
+ willUpdate(changed: PropertyValues<this>): void;
19
+ }
@@ -0,0 +1,27 @@
1
+ import {} from 'lit';
2
+ import { defineElement } from '../base.js';
3
+ import { PmDialog } from './dialog.js';
4
+ import drawerCss from '../styles/drawer.js';
5
+ /**
6
+ * Side sheet / drawer (a modal dialog anchored to an edge). `side="bottom"` is a bottom sheet with a grab handle
7
+ * that can be swiped down to close on touch screens.
8
+ * @tag pm-drawer
9
+ * @example <pm-drawer heading="Filters" side="end">…</pm-drawer>
10
+ */
11
+ export class PmDrawer extends PmDialog {
12
+ static { this.styles = [...PmDialog.styles, drawerCss]; }
13
+ static { this.componentName = 'drawer'; }
14
+ static { this.properties = { placement: { reflect: true, attribute: 'side' } }; }
15
+ constructor() {
16
+ super();
17
+ this.cls = 'pm-drawer';
18
+ this.placement = 'end';
19
+ this.dismiss = 'any';
20
+ }
21
+ get sheet() { return this.placement === 'bottom'; }
22
+ willUpdate(changed) {
23
+ super.willUpdate(changed);
24
+ this.side = this.placement === 'end' ? undefined : this.placement;
25
+ }
26
+ }
27
+ defineElement('pm-drawer', PmDrawer);
@@ -0,0 +1,50 @@
1
+ import { SafeHTMLElement } from '../base.js';
2
+ /**
3
+ * Reduce HTML to the editor's small set of formatting tags. Everything else is unwrapped (its text is kept),
4
+ * dangerous elements are removed with their content, and every attribute is dropped except safe link targets.
5
+ */
6
+ export declare function sanitizeRichText(input: string): string;
7
+ /**
8
+ * Rich-text editor for short formatted content: comments, descriptions, notes. Form-associated; submits clean HTML.
9
+ *
10
+ * Supports bold, italic, underline, headings, lists, quotes, code and links, with the usual keyboard shortcuts.
11
+ * Pasted and assigned content is reduced to those tags, so the value never contains scripts, styles or unknown
12
+ * markup. Sanitise again on the server before storing or showing it: the browser is not a trust boundary.
13
+ * @tag pm-editor
14
+ * @attr {string} label - Visible label (required for accessibility).
15
+ * @attr {string} name - Form field name.
16
+ * @attr {string} value - Initial HTML.
17
+ * @attr {string} placeholder - Shown while empty.
18
+ * @attr {string} hint - Help text under the editor.
19
+ * @attr {string} error - Custom error message. Setting it marks the field invalid.
20
+ * @attr {boolean} required - The form cannot be submitted while the editor is empty.
21
+ * @attr {boolean} disabled - Not editable and not submitted.
22
+ * @attr {boolean} readonly - Not editable, still submitted.
23
+ * @attr {string} toolbar - Tools to show, space-separated, with `|` for a divider: bold italic underline strike h2 h3 bullet number quote code link clear undo redo.
24
+ * @attr {number} maxlength - Longest allowed text, in characters.
25
+ * @fires pm-input - The content changed. detail: { value, text }
26
+ * @fires pm-change - The content changed and the editor lost focus. detail: { value, text }
27
+ * @example <pm-editor label="Description" name="description" placeholder="Describe the change…"></pm-editor>
28
+ */
29
+ export declare class PmEditor extends SafeHTMLElement {
30
+ #private;
31
+ static formAssociated: boolean;
32
+ static get observedAttributes(): string[];
33
+ /** The content as sanitised HTML (empty string when there is no text). */
34
+ get value(): string;
35
+ set value(v: string);
36
+ /** The content as plain text. */
37
+ get text(): string;
38
+ get disabled(): boolean;
39
+ set disabled(v: boolean);
40
+ get form(): HTMLFormElement | null;
41
+ get validity(): ValidityState;
42
+ checkValidity(): boolean;
43
+ reportValidity(): boolean;
44
+ focus(options?: FocusOptions): void;
45
+ connectedCallback(): void;
46
+ disconnectedCallback(): void;
47
+ attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
48
+ formResetCallback(): void;
49
+ formDisabledCallback(d: boolean): void;
50
+ }
@@ -0,0 +1,474 @@
1
+ import { nextId, SafeHTMLElement, defineElement } from '../base.js';
2
+ import editorCss from '../styles/editor.js';
3
+ import fieldCss from '../styles/field.js';
4
+ import inputCss from '../styles/input.js';
5
+ import buttonCss from '../styles/button.js';
6
+ const ALLOWED = new Set(['P', 'BR', 'STRONG', 'B', 'EM', 'I', 'U', 'S', 'H2', 'H3', 'UL', 'OL', 'LI', 'BLOCKQUOTE', 'CODE', 'PRE', 'A']);
7
+ const DROP = new Set(['SCRIPT', 'STYLE', 'IFRAME', 'OBJECT', 'EMBED', 'TEMPLATE', 'NOSCRIPT', 'SVG', 'MATH', 'HEAD', 'TITLE', 'META', 'LINK']);
8
+ const SAFE_URL = /^(https?:|mailto:|tel:|\/(?!\/)|#)/i;
9
+ /**
10
+ * Reduce HTML to the editor's small set of formatting tags. Everything else is unwrapped (its text is kept),
11
+ * dangerous elements are removed with their content, and every attribute is dropped except safe link targets.
12
+ */
13
+ export function sanitizeRichText(input) {
14
+ const doc = new DOMParser().parseFromString(`<body>${input}</body>`, 'text/html');
15
+ const clean = (node, out) => {
16
+ for (const child of [...node.childNodes]) {
17
+ if (child.nodeType === Node.TEXT_NODE) {
18
+ out.appendChild(document.createTextNode(child.textContent ?? ''));
19
+ continue;
20
+ }
21
+ if (child.nodeType !== Node.ELEMENT_NODE)
22
+ continue;
23
+ const el = child;
24
+ const tag = el.tagName.toUpperCase();
25
+ if (DROP.has(tag))
26
+ continue;
27
+ // Common equivalents from other editors and browsers.
28
+ const name = tag === 'DIV' ? 'P' : tag === 'H1' ? 'H2' : /^H[4-6]$/.test(tag) ? 'H3' : tag === 'STRIKE' || tag === 'DEL' ? 'S' : tag;
29
+ if (!ALLOWED.has(name)) {
30
+ clean(el, out);
31
+ continue;
32
+ }
33
+ const copy = document.createElement(name.toLowerCase());
34
+ if (name === 'A') {
35
+ const href = (el.getAttribute('href') ?? '').trim();
36
+ if (!SAFE_URL.test(href)) {
37
+ clean(el, out);
38
+ continue;
39
+ }
40
+ copy.setAttribute('href', href);
41
+ if (/^https?:/i.test(href))
42
+ copy.setAttribute('rel', 'noopener noreferrer');
43
+ }
44
+ clean(el, copy);
45
+ out.appendChild(copy);
46
+ }
47
+ };
48
+ const box = document.createElement('div');
49
+ clean(doc.body, box);
50
+ return box.innerHTML;
51
+ }
52
+ const TOOLS = {
53
+ bold: { id: 'bold', label: 'Bold', glyph: 'B', command: 'bold', state: 'bold' },
54
+ italic: { id: 'italic', label: 'Italic', glyph: 'I', command: 'italic', state: 'italic' },
55
+ underline: { id: 'underline', label: 'Underline', glyph: 'U', command: 'underline', state: 'underline' },
56
+ strike: { id: 'strike', label: 'Strikethrough', glyph: 'S', command: 'strikeThrough', state: 'strikeThrough' },
57
+ h2: { id: 'h2', label: 'Heading', glyph: 'H2', command: 'formatBlock', value: 'h2', block: 'h2' },
58
+ h3: { id: 'h3', label: 'Subheading', glyph: 'H3', command: 'formatBlock', value: 'h3', block: 'h3' },
59
+ bullet: { id: 'bullet', label: 'Bulleted list', glyph: '•≡', command: 'insertUnorderedList', state: 'insertUnorderedList' },
60
+ number: { id: 'number', label: 'Numbered list', glyph: '1.', command: 'insertOrderedList', state: 'insertOrderedList' },
61
+ quote: { id: 'quote', label: 'Quote', glyph: '❝', command: 'formatBlock', value: 'blockquote', block: 'blockquote' },
62
+ code: { id: 'code', label: 'Code block', glyph: '</>', command: 'formatBlock', value: 'pre', block: 'pre' },
63
+ link: { id: 'link', label: 'Link', glyph: '🔗', command: 'link' },
64
+ clear: { id: 'clear', label: 'Clear formatting', glyph: 'Tx', command: 'removeFormat' },
65
+ undo: { id: 'undo', label: 'Undo', glyph: '↶', command: 'undo' },
66
+ redo: { id: 'redo', label: 'Redo', glyph: '↷', command: 'redo' },
67
+ };
68
+ const DEFAULT_TOOLBAR = 'bold italic underline | h2 h3 | bullet number quote | link clear | undo redo';
69
+ /**
70
+ * Rich-text editor for short formatted content: comments, descriptions, notes. Form-associated; submits clean HTML.
71
+ *
72
+ * Supports bold, italic, underline, headings, lists, quotes, code and links, with the usual keyboard shortcuts.
73
+ * Pasted and assigned content is reduced to those tags, so the value never contains scripts, styles or unknown
74
+ * markup. Sanitise again on the server before storing or showing it: the browser is not a trust boundary.
75
+ * @tag pm-editor
76
+ * @attr {string} label - Visible label (required for accessibility).
77
+ * @attr {string} name - Form field name.
78
+ * @attr {string} value - Initial HTML.
79
+ * @attr {string} placeholder - Shown while empty.
80
+ * @attr {string} hint - Help text under the editor.
81
+ * @attr {string} error - Custom error message. Setting it marks the field invalid.
82
+ * @attr {boolean} required - The form cannot be submitted while the editor is empty.
83
+ * @attr {boolean} disabled - Not editable and not submitted.
84
+ * @attr {boolean} readonly - Not editable, still submitted.
85
+ * @attr {string} toolbar - Tools to show, space-separated, with `|` for a divider: bold italic underline strike h2 h3 bullet number quote code link clear undo redo.
86
+ * @attr {number} maxlength - Longest allowed text, in characters.
87
+ * @fires pm-input - The content changed. detail: { value, text }
88
+ * @fires pm-change - The content changed and the editor lost focus. detail: { value, text }
89
+ * @example <pm-editor label="Description" name="description" placeholder="Describe the change…"></pm-editor>
90
+ */
91
+ export class PmEditor extends SafeHTMLElement {
92
+ static { this.formAssociated = true; }
93
+ static get observedAttributes() { return ['label', 'value', 'placeholder', 'hint', 'error', 'required', 'disabled', 'readonly', 'toolbar', 'maxlength']; }
94
+ #internals = this.attachInternals?.();
95
+ #id = nextId('ed');
96
+ #area;
97
+ #box;
98
+ #bar;
99
+ #linkRow;
100
+ #label;
101
+ #hint;
102
+ #error;
103
+ /** Last selection inside the editor, as plain positions (a live Range would follow later selection changes). */
104
+ #saved = null;
105
+ #initial = '';
106
+ #lastChange = '';
107
+ #touched = false;
108
+ #built = false;
109
+ /** The content as sanitised HTML (empty string when there is no text). */
110
+ get value() { return this.#area && !this.#isEmpty() ? sanitizeRichText(this.#area.innerHTML) : this.#built ? '' : this.getAttribute('value') ?? ''; }
111
+ set value(v) {
112
+ if (!this.#area) {
113
+ this.setAttribute('value', v ?? '');
114
+ return;
115
+ }
116
+ this.#area.innerHTML = sanitizeRichText(v ?? '');
117
+ this.#sync();
118
+ }
119
+ /** The content as plain text. */
120
+ get text() { return (this.#area?.innerText ?? '').replace(/ /g, ' ').trim(); }
121
+ get disabled() { return this.hasAttribute('disabled'); }
122
+ set disabled(v) { this.toggleAttribute('disabled', !!v); }
123
+ get form() { return this.#internals?.form ?? null; }
124
+ get validity() { return this.#internals?.validity; }
125
+ checkValidity() { return this.#internals?.checkValidity() ?? true; }
126
+ reportValidity() { this.#touched = true; this.#validate(); return this.#internals?.reportValidity() ?? true; }
127
+ focus(options) { this.#area?.focus(options); }
128
+ connectedCallback() {
129
+ if (this.#built)
130
+ return;
131
+ this.#built = true;
132
+ this.classList.add('pm-editor');
133
+ this.#initial = this.getAttribute('value') ?? this.innerHTML;
134
+ const el = (tag, cls, attrs = {}) => {
135
+ const n = document.createElement(tag);
136
+ if (cls)
137
+ n.className = cls;
138
+ for (const [k, v] of Object.entries(attrs))
139
+ n.setAttribute(k, v);
140
+ return n;
141
+ };
142
+ const field = el('div', 'pm-field');
143
+ this.#label = el('span', 'pm-label', { id: `${this.#id}-l` });
144
+ this.#box = el('div', 'pm-editor-box');
145
+ this.#bar = el('div', 'pm-editor-toolbar', { role: 'toolbar', 'aria-controls': `${this.#id}-a` });
146
+ this.#linkRow = el('div', 'pm-editor-link', { hidden: '' });
147
+ const url = el('input', 'pm-input', { type: 'url', 'data-size': 'sm', placeholder: 'https://', 'aria-label': 'Link address' });
148
+ const apply = el('button', 'pm-button', { type: 'button', 'data-size': 'sm' });
149
+ apply.textContent = 'Apply';
150
+ const remove = el('button', 'pm-button', { type: 'button', 'data-size': 'sm', 'data-variant': 'ghost', 'data-tone': 'neutral' });
151
+ remove.textContent = 'Remove link';
152
+ this.#linkRow.append(url, apply, remove);
153
+ this.#area = el('div', 'pm-editor-area', { id: `${this.#id}-a`, role: 'textbox', 'aria-multiline': 'true', 'aria-labelledby': `${this.#id}-l`, contenteditable: 'true', spellcheck: 'true' });
154
+ this.#hint = el('span', 'pm-hint', { id: `${this.#id}-h` });
155
+ this.#error = el('span', 'pm-error', { id: `${this.#id}-e`, hidden: '' });
156
+ this.#box.append(this.#bar, this.#linkRow, this.#area);
157
+ field.append(this.#label, this.#box, this.#hint, this.#error);
158
+ this.replaceChildren(field);
159
+ this.#area.innerHTML = sanitizeRichText(this.#initial);
160
+ try {
161
+ document.execCommand('defaultParagraphSeparator', false, 'p');
162
+ }
163
+ catch { /* not supported: browser default */ }
164
+ this.#bar.addEventListener('click', (e) => { const b = e.target.closest('button[data-tool]'); if (b && !b.disabled)
165
+ this.#run(TOOLS[b.dataset.tool]); });
166
+ this.#bar.addEventListener('keydown', this.#onBarKey);
167
+ // Keep the text selection when a toolbar button is pressed with the pointer.
168
+ this.#bar.addEventListener('pointerdown', (e) => { if (e.target.closest('button'))
169
+ e.preventDefault(); });
170
+ this.#area.addEventListener('input', () => {
171
+ // Text typed into an empty editor has no block around it yet: make it a paragraph, like every later line.
172
+ const first = this.#area.firstChild;
173
+ if (first && first.nodeType === Node.TEXT_NODE && first.textContent?.trim()) {
174
+ try {
175
+ document.execCommand('formatBlock', false, 'p');
176
+ }
177
+ catch { /* keep the bare text */ }
178
+ }
179
+ this.#touched = true;
180
+ this.#sync();
181
+ this.#notify('pm-input');
182
+ });
183
+ this.#area.addEventListener('blur', () => { this.#touched = true; this.#validate(); if (this.value !== this.#lastChange) {
184
+ this.#lastChange = this.value;
185
+ this.#notify('pm-change');
186
+ } });
187
+ this.#area.addEventListener('paste', this.#onPaste);
188
+ this.#area.addEventListener('keydown', this.#onKey);
189
+ this.addEventListener('invalid', () => { this.#touched = true; this.#validate(); });
190
+ document.addEventListener('selectionchange', this.#onSelection);
191
+ apply.addEventListener('click', () => this.#applyLink(url.value));
192
+ remove.addEventListener('click', () => this.#applyLink(''));
193
+ url.addEventListener('keydown', (e) => { if (e.key === 'Enter') {
194
+ e.preventDefault();
195
+ this.#applyLink(url.value);
196
+ }
197
+ else if (e.key === 'Escape') {
198
+ e.preventDefault();
199
+ this.#closeLink();
200
+ } });
201
+ this.#render();
202
+ this.#lastChange = this.value;
203
+ this.#sync();
204
+ }
205
+ disconnectedCallback() { document.removeEventListener('selectionchange', this.#onSelection); }
206
+ attributeChangedCallback(name, _old, value) {
207
+ if (!this.#built)
208
+ return;
209
+ if (name === 'value') {
210
+ this.#area.innerHTML = sanitizeRichText(value ?? '');
211
+ this.#sync();
212
+ return;
213
+ }
214
+ this.#render();
215
+ this.#validate();
216
+ }
217
+ formResetCallback() { if (this.#area) {
218
+ this.#area.innerHTML = sanitizeRichText(this.#initial);
219
+ this.#touched = false;
220
+ this.#sync();
221
+ } }
222
+ formDisabledCallback(d) { this.toggleAttribute('data-form-disabled', d); this.#render(); }
223
+ get #locked() { return this.disabled || this.hasAttribute('readonly') || this.hasAttribute('data-form-disabled'); }
224
+ #isEmpty() { return !this.text && !this.#area?.querySelector('li, pre, blockquote'); }
225
+ #notify(name) { this.dispatchEvent(new CustomEvent(name, { detail: { value: this.value, text: this.text }, bubbles: true, composed: true })); }
226
+ #render() {
227
+ const label = this.getAttribute('label') ?? 'Text';
228
+ this.#label.textContent = label;
229
+ this.#label.toggleAttribute('data-required', this.hasAttribute('required'));
230
+ const locked = this.#locked;
231
+ this.#area.setAttribute('contenteditable', locked ? 'false' : 'true');
232
+ this.#area.tabIndex = this.disabled ? -1 : 0;
233
+ this.#area.setAttribute('data-placeholder', this.getAttribute('placeholder') ?? '');
234
+ if (this.hasAttribute('required'))
235
+ this.#area.setAttribute('aria-required', 'true');
236
+ else
237
+ this.#area.removeAttribute('aria-required');
238
+ if (this.hasAttribute('readonly'))
239
+ this.#area.setAttribute('aria-readonly', 'true');
240
+ else
241
+ this.#area.removeAttribute('aria-readonly');
242
+ this.#box.toggleAttribute('data-disabled', this.disabled || this.hasAttribute('data-form-disabled'));
243
+ this.#bar.setAttribute('aria-label', `${label}: formatting`);
244
+ const hint = this.getAttribute('hint');
245
+ this.#hint.textContent = hint ?? '';
246
+ this.#hint.hidden = !hint;
247
+ // Toolbar: one tab stop; arrow keys move between the buttons.
248
+ const spec = (this.getAttribute('toolbar') ?? DEFAULT_TOOLBAR).split(/\s+/).filter(Boolean);
249
+ const nodes = [];
250
+ let first = true;
251
+ for (const id of spec) {
252
+ if (id === '|') {
253
+ const sep = document.createElement('span');
254
+ sep.className = 'pm-editor-sep';
255
+ sep.setAttribute('role', 'separator');
256
+ nodes.push(sep);
257
+ continue;
258
+ }
259
+ const tool = TOOLS[id];
260
+ if (!tool)
261
+ continue;
262
+ const b = document.createElement('button');
263
+ b.type = 'button';
264
+ b.dataset.tool = id;
265
+ b.title = tool.label;
266
+ // The glyph is drawn by CSS, so the button's only name is its label.
267
+ b.dataset.glyph = tool.glyph;
268
+ b.setAttribute('aria-label', tool.label);
269
+ if (tool.state || tool.block || id === 'link')
270
+ b.setAttribute('aria-pressed', 'false');
271
+ b.disabled = locked;
272
+ b.tabIndex = first ? 0 : -1;
273
+ first = false;
274
+ nodes.push(b);
275
+ }
276
+ this.#bar.replaceChildren(...nodes);
277
+ this.#bar.hidden = !nodes.length;
278
+ this.#states();
279
+ }
280
+ /** After every change: placeholder, form value, validity. */
281
+ #sync() {
282
+ this.#area.toggleAttribute('data-empty', this.#isEmpty());
283
+ const name = this.getAttribute('name');
284
+ this.#internals?.setFormValue(this.disabled || !name ? null : this.value);
285
+ this.#validate();
286
+ this.#states();
287
+ }
288
+ #validate() {
289
+ const custom = this.getAttribute('error');
290
+ const max = Number(this.getAttribute('maxlength')) || 0;
291
+ const problem = custom || (this.hasAttribute('required') && this.#isEmpty() && !this.disabled ? 'Please fill in this field.' : max && this.text.length > max ? `Please shorten this text to ${max} characters or fewer (now ${this.text.length}).` : '');
292
+ if (!this.#internals)
293
+ return;
294
+ if (problem)
295
+ this.#internals.setValidity(custom ? { customError: true } : this.#isEmpty() ? { valueMissing: true } : { tooLong: true }, problem, this.#area);
296
+ else
297
+ this.#internals.setValidity({});
298
+ const shown = custom || (this.#touched ? problem : '');
299
+ this.#error.textContent = shown;
300
+ this.#error.hidden = !shown;
301
+ if (shown)
302
+ this.#error.setAttribute('role', 'alert');
303
+ else
304
+ this.#error.removeAttribute('role');
305
+ this.#box.toggleAttribute('data-invalid', !!shown);
306
+ if (shown)
307
+ this.#area.setAttribute('aria-invalid', 'true');
308
+ else
309
+ this.#area.removeAttribute('aria-invalid');
310
+ const described = [this.getAttribute('hint') ? this.#hint.id : '', shown ? this.#error.id : ''].filter(Boolean).join(' ');
311
+ if (described)
312
+ this.#area.setAttribute('aria-describedby', described);
313
+ else
314
+ this.#area.removeAttribute('aria-describedby');
315
+ }
316
+ #inArea(node) { return !!node && !!this.#area?.contains(node); }
317
+ /** Remember the selection while it is inside the editor. Formatting commands move it without an event, so this is also called directly. */
318
+ #save() {
319
+ const sel = document.getSelection();
320
+ if (!sel?.rangeCount || !sel.anchorNode || !sel.focusNode || !this.#inArea(sel.anchorNode) || !this.#inArea(sel.focusNode))
321
+ return false;
322
+ this.#saved = { anchor: sel.anchorNode, anchorOffset: sel.anchorOffset, focus: sel.focusNode, focusOffset: sel.focusOffset };
323
+ return true;
324
+ }
325
+ #onSelection = () => { if (this.#save())
326
+ this.#states(); };
327
+ #blockTag() {
328
+ let n = document.getSelection()?.anchorNode;
329
+ while (n && n !== this.#area) {
330
+ if (n instanceof HTMLElement && /^(H2|H3|BLOCKQUOTE|PRE|P|LI)$/.test(n.tagName))
331
+ return n.tagName.toLowerCase();
332
+ n = n.parentNode;
333
+ }
334
+ return '';
335
+ }
336
+ #linkAtSelection() {
337
+ let n = document.getSelection()?.anchorNode;
338
+ while (n && n !== this.#area) {
339
+ if (n instanceof HTMLAnchorElement)
340
+ return n;
341
+ n = n.parentNode;
342
+ }
343
+ return null;
344
+ }
345
+ /** Pressed state of the toolbar buttons for the current selection. */
346
+ #states() {
347
+ if (!this.#bar)
348
+ return;
349
+ const inside = this.#inArea(document.getSelection()?.anchorNode);
350
+ const block = inside ? this.#blockTag() : '';
351
+ for (const b of this.#bar.querySelectorAll('button[aria-pressed]')) {
352
+ const tool = TOOLS[b.dataset.tool];
353
+ let on = false;
354
+ if (inside) {
355
+ if (tool.block)
356
+ on = block === tool.block;
357
+ else if (tool.id === 'link')
358
+ on = !!this.#linkAtSelection();
359
+ else if (tool.state) {
360
+ try {
361
+ on = document.queryCommandState(tool.state);
362
+ }
363
+ catch {
364
+ on = false;
365
+ }
366
+ }
367
+ }
368
+ b.setAttribute('aria-pressed', String(on));
369
+ }
370
+ }
371
+ #restore() {
372
+ this.#area.focus({ preventScroll: true });
373
+ const s = this.#saved;
374
+ if (!s || !this.#inArea(s.anchor) || !this.#inArea(s.focus))
375
+ return;
376
+ const len = (n) => (n.nodeType === Node.TEXT_NODE ? (n.textContent ?? '').length : n.childNodes.length);
377
+ try {
378
+ document.getSelection()?.setBaseAndExtent(s.anchor, Math.min(s.anchorOffset, len(s.anchor)), s.focus, Math.min(s.focusOffset, len(s.focus)));
379
+ }
380
+ catch { /* nodes changed: keep the caret where focus put it */ }
381
+ }
382
+ #run(tool) {
383
+ if (this.#locked)
384
+ return;
385
+ if (tool.id === 'link') {
386
+ this.#openLink();
387
+ return;
388
+ }
389
+ this.#restore();
390
+ // Block tools toggle: pressing "Heading" on a heading turns it back into a paragraph.
391
+ const value = tool.block && this.#blockTag() === tool.block ? 'p' : tool.value;
392
+ try {
393
+ document.execCommand(tool.command, false, value);
394
+ }
395
+ catch { /* command not supported in this browser */ }
396
+ this.#save();
397
+ this.#touched = true;
398
+ this.#sync();
399
+ this.#notify('pm-input');
400
+ }
401
+ #openLink() {
402
+ this.#save();
403
+ const input = this.#linkRow.querySelector('input');
404
+ input.value = this.#linkAtSelection()?.getAttribute('href') ?? '';
405
+ this.#linkRow.hidden = false;
406
+ input.focus();
407
+ input.select();
408
+ }
409
+ #closeLink() { this.#linkRow.hidden = true; this.#restore(); }
410
+ #applyLink(raw) {
411
+ const href = raw.trim() && !/^[a-z][a-z0-9+.-]*:|^[/#]/i.test(raw.trim()) ? `https://${raw.trim()}` : raw.trim();
412
+ this.#linkRow.hidden = true;
413
+ this.#restore();
414
+ try {
415
+ if (!href || !SAFE_URL.test(href))
416
+ document.execCommand('unlink');
417
+ else if (document.getSelection()?.isCollapsed && !this.#linkAtSelection())
418
+ document.execCommand('insertHTML', false, sanitizeRichText(`<a href="${href.replace(/"/g, '&quot;')}">${href.replace(/</g, '&lt;')}</a>`));
419
+ else
420
+ document.execCommand('createLink', false, href);
421
+ }
422
+ catch { /* not supported */ }
423
+ this.#save();
424
+ this.#sync();
425
+ this.#notify('pm-input');
426
+ }
427
+ #onPaste = (e) => {
428
+ if (this.#locked || !e.clipboardData)
429
+ return;
430
+ e.preventDefault();
431
+ const rich = e.clipboardData.getData('text/html');
432
+ const plain = e.clipboardData.getData('text/plain');
433
+ const safe = rich ? sanitizeRichText(rich) : plain.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\r?\n/g, '<br>');
434
+ try {
435
+ document.execCommand('insertHTML', false, safe);
436
+ }
437
+ catch {
438
+ document.execCommand('insertText', false, plain);
439
+ }
440
+ };
441
+ #onKey = (e) => {
442
+ if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'k') {
443
+ e.preventDefault();
444
+ if (!this.#locked)
445
+ this.#openLink();
446
+ }
447
+ // Alt+F10 moves to the toolbar, as in other editors.
448
+ else if (e.altKey && e.key === 'F10') {
449
+ e.preventDefault();
450
+ this.#bar?.querySelector('button[tabindex="0"]')?.focus();
451
+ }
452
+ };
453
+ #onBarKey = (e) => {
454
+ const buttons = [...this.#bar.querySelectorAll('button:not(:disabled)')];
455
+ const i = buttons.indexOf(document.activeElement);
456
+ if (i < 0)
457
+ return;
458
+ const rtl = getComputedStyle(this).direction === 'rtl';
459
+ const to = e.key === 'ArrowRight' ? i + (rtl ? -1 : 1) : e.key === 'ArrowLeft' ? i + (rtl ? 1 : -1) : e.key === 'Home' ? 0 : e.key === 'End' ? buttons.length - 1 : null;
460
+ if (to === null) {
461
+ if (e.key === 'Escape') {
462
+ e.preventDefault();
463
+ this.#restore();
464
+ }
465
+ return;
466
+ }
467
+ e.preventDefault();
468
+ const next = buttons[(to + buttons.length) % buttons.length];
469
+ for (const b of buttons)
470
+ b.tabIndex = b === next ? 0 : -1;
471
+ next.focus();
472
+ };
473
+ }
474
+ defineElement('pm-editor', PmEditor, [fieldCss, inputCss, buttonCss, editorCss]);
@@ -0,0 +1,24 @@
1
+ import { type PropertyDeclarations } from 'lit';
2
+ import { PmElement } from '../base.js';
3
+ /**
4
+ * Empty state: what to do when there is nothing to show yet.
5
+ * @tag pm-empty-state
6
+ * @slot icon - Illustration or icon.
7
+ * @slot - Actions (buttons).
8
+ * @example <pm-empty-state heading="No projects yet" description="Create your first project to get started."><pm-button>New project</pm-button></pm-empty-state>
9
+ */
10
+ export declare class PmEmptyState extends PmElement {
11
+ static componentName: string;
12
+ static styles: import("lit").CSSResult[];
13
+ static properties: PropertyDeclarations;
14
+ /** Registered icon name (see `registerIcons`); an `icon` slot overrides it. */
15
+ icon?: string;
16
+ heading?: string;
17
+ /** Heading level for the document outline (default 2). */
18
+ headingLevel?: number;
19
+ description?: string;
20
+ /** Dashed outline (drop zones, empty panels). */
21
+ bordered: boolean;
22
+ constructor();
23
+ render(): import("lit").TemplateResult<1>;
24
+ }
@@ -0,0 +1,27 @@
1
+ import { css, html, nothing } from 'lit';
2
+ import { PmElement, defineElement } from '../base.js';
3
+ import emptyStateCss from '../styles/empty-state.js';
4
+ import { namedIcon } from '../named-icon.js';
5
+ /**
6
+ * Empty state: what to do when there is nothing to show yet.
7
+ * @tag pm-empty-state
8
+ * @slot icon - Illustration or icon.
9
+ * @slot - Actions (buttons).
10
+ * @example <pm-empty-state heading="No projects yet" description="Create your first project to get started."><pm-button>New project</pm-button></pm-empty-state>
11
+ */
12
+ export class PmEmptyState extends PmElement {
13
+ static { this.componentName = 'empty-state'; }
14
+ static { this.styles = [...PmElement.styles, emptyStateCss, css `:host { display: block; }`]; }
15
+ static { this.properties = { icon: { reflect: true }, heading: {}, headingLevel: { type: Number, attribute: 'heading-level' }, description: {}, bordered: { type: Boolean, reflect: true } }; }
16
+ constructor() { super(); this.bordered = false; }
17
+ render() {
18
+ const hasIcon = !!this.icon || !!this.querySelector('[slot="icon"]');
19
+ return html `<div class="pm-empty-state" part="base" ?data-bordered=${this.bordered}>
20
+ ${hasIcon ? html `<span class="pm-empty-state-icon" part="icon"><slot name="icon">${namedIcon(this.icon)}</slot></span>` : nothing}
21
+ ${this.heading ? html `<div class="pm-empty-state-title" part="heading" role="heading" aria-level=${Math.min(6, Math.max(1, this.headingLevel ?? 2))}>${this.heading}</div>` : nothing}
22
+ ${this.description ? html `<p class="pm-empty-state-description" part="description">${this.description}</p>` : nothing}
23
+ <div class="pm-empty-state-actions" part="actions"><slot></slot></div>
24
+ </div>`;
25
+ }
26
+ }
27
+ defineElement('pm-empty-state', PmEmptyState);