@bk2k/ui 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (313) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/USAGE.md +20 -9
  3. package/custom-elements.json +1 -1
  4. package/dist/charts/frame.d.ts +2 -0
  5. package/dist/components/bk-alert.js +1 -1
  6. package/dist/components/bk-button.d.ts +5 -0
  7. package/dist/components/bk-button.js +15 -4
  8. package/dist/components/bk-card.d.ts +6 -3
  9. package/dist/components/bk-card.js +15 -9
  10. package/dist/components/bk-chart-area.d.ts +4 -0
  11. package/dist/components/bk-chart-line.d.ts +15 -0
  12. package/dist/components/bk-chart-line.js +16 -6
  13. package/dist/components/bk-chip.d.ts +2 -0
  14. package/dist/components/bk-chip.js +3 -1
  15. package/dist/components/bk-combobox.d.ts +2 -2
  16. package/dist/components/bk-combobox.js +7 -20
  17. package/dist/components/bk-footnotes-item.d.ts +2 -2
  18. package/dist/components/bk-image-compare.d.ts +36 -1
  19. package/dist/components/bk-image-compare.js +47 -11
  20. package/dist/components/bk-image-viewer.d.ts +74 -3
  21. package/dist/components/bk-image-viewer.js +115 -28
  22. package/dist/components/bk-input-color.d.ts +2 -5
  23. package/dist/components/bk-input-color.js +0 -14
  24. package/dist/components/bk-input-file.d.ts +17 -0
  25. package/dist/components/bk-input-file.js +18 -8
  26. package/dist/components/bk-input-tags.d.ts +219 -0
  27. package/dist/components/bk-input-tags.js +293 -0
  28. package/dist/components/bk-input-text.d.ts +9 -0
  29. package/dist/components/bk-input-text.js +18 -2
  30. package/dist/components/bk-lightbox.d.ts +25 -1
  31. package/dist/components/bk-lightbox.js +7 -0
  32. package/dist/components/bk-page-cta.d.ts +2 -0
  33. package/dist/components/bk-page-cta.js +8 -1
  34. package/dist/components/bk-split-grid.js +7 -2
  35. package/dist/components/bk-stat.d.ts +2 -0
  36. package/dist/components/bk-stat.js +1 -1
  37. package/dist/components/bk-table.d.ts +2 -0
  38. package/dist/components/bk-table.js +1 -1
  39. package/dist/components/bk-tabs.d.ts +2 -1
  40. package/dist/components/bk-tabs.js +15 -3
  41. package/dist/index.d.ts +1 -0
  42. package/dist/index.js +1 -0
  43. package/dist/internal/announcer.d.ts +6 -0
  44. package/dist/internal/announcer.js +7 -2
  45. package/dist/internal/cloak.js +1 -0
  46. package/dist/internal/define.d.ts +9 -0
  47. package/dist/internal/define.js +47 -1
  48. package/dist/internal/elements.d.ts +6 -0
  49. package/dist/internal/elements.js +5 -0
  50. package/dist/internal/hue.d.ts +8 -0
  51. package/dist/internal/hue.js +15 -4
  52. package/dist/internal/late/bk-tabs.d.ts +4 -0
  53. package/dist/internal/late/bk-tabs.js +8 -0
  54. package/dist/internal/late.js +3 -3
  55. package/dist/internal/tags.d.ts +15 -0
  56. package/dist/internal/tags.js +44 -0
  57. package/dist/internal/text-field.d.ts +2 -0
  58. package/dist/internal/text-field.js +8 -0
  59. package/dist/internal/toggle-control.js +3 -1
  60. package/dist/jsx.d.ts +85 -6
  61. package/dist/kit.d.ts +1 -0
  62. package/dist/kit.js +3 -0
  63. package/dist/reset.css +1 -1
  64. package/dist/standalone/all.js +106 -105
  65. package/dist/standalone/bk-accordion-item.js +3 -3
  66. package/dist/standalone/bk-accordion.js +1 -1
  67. package/dist/standalone/bk-action-bar.js +1 -1
  68. package/dist/standalone/bk-alert-offline.js +1 -1
  69. package/dist/standalone/bk-alert.js +7 -4
  70. package/dist/standalone/bk-app-state.js +1 -1
  71. package/dist/standalone/bk-attachment.js +2 -2
  72. package/dist/standalone/bk-avatar-group.js +1 -1
  73. package/dist/standalone/bk-avatar.js +3 -3
  74. package/dist/standalone/bk-badge.js +1 -1
  75. package/dist/standalone/bk-bar.js +1 -1
  76. package/dist/standalone/bk-brand.js +1 -1
  77. package/dist/standalone/bk-breadcrumbs.js +2 -2
  78. package/dist/standalone/bk-button-copy.js +4 -4
  79. package/dist/standalone/bk-button-group.js +2 -2
  80. package/dist/standalone/bk-button-share.js +4 -4
  81. package/dist/standalone/bk-button-top.js +1 -1
  82. package/dist/standalone/bk-button.js +14 -6
  83. package/dist/standalone/bk-calendar-event.js +1 -1
  84. package/dist/standalone/bk-calendar-week.js +1 -1
  85. package/dist/standalone/bk-calendar.js +2 -2
  86. package/dist/standalone/bk-card.js +17 -11
  87. package/dist/standalone/bk-carousel-controls.js +2 -2
  88. package/dist/standalone/bk-carousel-item.js +1 -1
  89. package/dist/standalone/bk-carousel.js +1 -1
  90. package/dist/standalone/bk-chart-area.js +1 -1
  91. package/dist/standalone/bk-chart-bar-list.js +2 -2
  92. package/dist/standalone/bk-chart-bar.js +1 -1
  93. package/dist/standalone/bk-chart-bridge.js +1 -1
  94. package/dist/standalone/bk-chart-bullet.js +1 -1
  95. package/dist/standalone/bk-chart-calendar.js +1 -1
  96. package/dist/standalone/bk-chart-heatmap.js +1 -1
  97. package/dist/standalone/bk-chart-histogram.js +1 -1
  98. package/dist/standalone/bk-chart-legend.js +1 -1
  99. package/dist/standalone/bk-chart-line.js +16 -8
  100. package/dist/standalone/bk-chart-mark.js +1 -1
  101. package/dist/standalone/bk-chart-scatter.js +1 -1
  102. package/dist/standalone/bk-chart-sparkline.js +1 -1
  103. package/dist/standalone/bk-chart-stacked-bar.js +1 -1
  104. package/dist/standalone/bk-chart-tracker.js +1 -1
  105. package/dist/standalone/bk-chart-waterfall.js +2 -2
  106. package/dist/standalone/bk-checkbox-group.js +5 -5
  107. package/dist/standalone/bk-checkbox.js +3 -3
  108. package/dist/standalone/bk-chip-group.js +4 -4
  109. package/dist/standalone/bk-chip.js +5 -3
  110. package/dist/standalone/bk-cluster.js +1 -1
  111. package/dist/standalone/bk-code-diff.js +2 -2
  112. package/dist/standalone/bk-code-stack.js +1 -1
  113. package/dist/standalone/bk-code.js +1 -1
  114. package/dist/standalone/bk-color-panel.js +2 -2
  115. package/dist/standalone/bk-columns.js +1 -1
  116. package/dist/standalone/bk-combobox.js +21 -30
  117. package/dist/standalone/bk-command-menu.js +3 -3
  118. package/dist/standalone/bk-command-palette.js +4 -4
  119. package/dist/standalone/bk-composer.js +4 -4
  120. package/dist/standalone/bk-delta.js +1 -1
  121. package/dist/standalone/bk-diagram.js +1 -1
  122. package/dist/standalone/bk-dialog.js +1 -1
  123. package/dist/standalone/bk-disclosure.js +2 -2
  124. package/dist/standalone/bk-divider.js +4 -4
  125. package/dist/standalone/bk-drawer.js +2 -2
  126. package/dist/standalone/bk-drop-target.js +1 -1
  127. package/dist/standalone/bk-empty-state.js +2 -2
  128. package/dist/standalone/bk-error-summary.js +1 -1
  129. package/dist/standalone/bk-facts-item.js +1 -1
  130. package/dist/standalone/bk-facts.js +1 -1
  131. package/dist/standalone/bk-feature.js +2 -2
  132. package/dist/standalone/bk-fieldset.js +1 -1
  133. package/dist/standalone/bk-filter-bar.js +2 -2
  134. package/dist/standalone/bk-folder-browser.js +2 -2
  135. package/dist/standalone/bk-footnote.js +1 -1
  136. package/dist/standalone/bk-footnotes-item.js +2 -2
  137. package/dist/standalone/bk-footnotes.js +1 -1
  138. package/dist/standalone/bk-form-guard.js +1 -1
  139. package/dist/standalone/bk-form-steps.js +1 -1
  140. package/dist/standalone/bk-grid.js +1 -1
  141. package/dist/standalone/bk-icon-tile.js +2 -2
  142. package/dist/standalone/bk-icon.js +1 -1
  143. package/dist/standalone/bk-image-compare.js +55 -27
  144. package/dist/standalone/bk-image-crop.js +3 -3
  145. package/dist/standalone/bk-image-editor.js +1 -1
  146. package/dist/standalone/bk-image-viewer.js +127 -57
  147. package/dist/standalone/bk-input-code.js +2 -2
  148. package/dist/standalone/bk-input-color.js +3 -13
  149. package/dist/standalone/bk-input-date-range.js +2 -2
  150. package/dist/standalone/bk-input-date.js +2 -2
  151. package/dist/standalone/bk-input-file.js +20 -13
  152. package/dist/standalone/bk-input-group.js +2 -2
  153. package/dist/standalone/bk-input-inline.js +1 -1
  154. package/dist/standalone/bk-input-number.js +4 -4
  155. package/dist/standalone/bk-input-rating.js +4 -4
  156. package/dist/standalone/bk-input-rich.js +1 -1
  157. package/dist/standalone/bk-input-search.js +4 -4
  158. package/dist/standalone/bk-input-slider-range.js +2 -2
  159. package/dist/standalone/bk-input-slider.js +2 -2
  160. package/dist/standalone/bk-input-tags.js +224 -0
  161. package/dist/standalone/bk-input-text.js +1 -1
  162. package/dist/standalone/bk-input-time-zone.js +1 -1
  163. package/dist/standalone/bk-input-time.js +4 -4
  164. package/dist/standalone/bk-item-group.js +2 -2
  165. package/dist/standalone/bk-item.js +2 -2
  166. package/dist/standalone/bk-kbd-shortcuts.js +1 -1
  167. package/dist/standalone/bk-kbd.js +1 -1
  168. package/dist/standalone/bk-lightbox.js +16 -3
  169. package/dist/standalone/bk-lines.js +1 -1
  170. package/dist/standalone/bk-link.js +2 -2
  171. package/dist/standalone/bk-listbox-columns.js +6 -6
  172. package/dist/standalone/bk-listbox-item.js +1 -1
  173. package/dist/standalone/bk-listbox-search.js +5 -5
  174. package/dist/standalone/bk-listbox-transfer.js +4 -4
  175. package/dist/standalone/bk-listbox.js +5 -5
  176. package/dist/standalone/bk-logo-wall.js +1 -1
  177. package/dist/standalone/bk-logo.js +2 -2
  178. package/dist/standalone/bk-menu-bar.js +1 -1
  179. package/dist/standalone/bk-menu-context.js +1 -1
  180. package/dist/standalone/bk-menu-divider.js +1 -1
  181. package/dist/standalone/bk-menu-item.js +2 -2
  182. package/dist/standalone/bk-menu-label.js +1 -1
  183. package/dist/standalone/bk-menu-list.js +1 -1
  184. package/dist/standalone/bk-menu.js +4 -4
  185. package/dist/standalone/bk-message-approval.js +2 -2
  186. package/dist/standalone/bk-message-branches.js +1 -1
  187. package/dist/standalone/bk-message-citation.js +1 -1
  188. package/dist/standalone/bk-message-feedback.js +2 -2
  189. package/dist/standalone/bk-message-list.js +2 -2
  190. package/dist/standalone/bk-message-reasoning.js +3 -3
  191. package/dist/standalone/bk-message-source.js +1 -1
  192. package/dist/standalone/bk-message-tool-group.js +3 -3
  193. package/dist/standalone/bk-message-tool.js +3 -3
  194. package/dist/standalone/bk-message.js +2 -2
  195. package/dist/standalone/bk-meter.js +1 -1
  196. package/dist/standalone/bk-model-viewer.js +1 -1
  197. package/dist/standalone/bk-nav-divider.js +1 -1
  198. package/dist/standalone/bk-nav-group.js +5 -5
  199. package/dist/standalone/bk-nav-item.js +2 -2
  200. package/dist/standalone/bk-nav-toc.js +1 -1
  201. package/dist/standalone/bk-nav.js +1 -1
  202. package/dist/standalone/bk-overflow.js +1 -1
  203. package/dist/standalone/bk-page-cta.js +10 -3
  204. package/dist/standalone/bk-page-footer-column.js +1 -1
  205. package/dist/standalone/bk-page-footer.js +1 -1
  206. package/dist/standalone/bk-page-header.js +2 -2
  207. package/dist/standalone/bk-page-hero.js +2 -2
  208. package/dist/standalone/bk-page-pager.js +2 -2
  209. package/dist/standalone/bk-page-section.js +2 -2
  210. package/dist/standalone/bk-pagination.js +3 -3
  211. package/dist/standalone/bk-pane.js +2 -2
  212. package/dist/standalone/bk-panel.js +2 -2
  213. package/dist/standalone/bk-period-nav.js +2 -2
  214. package/dist/standalone/bk-picture.js +1 -175
  215. package/dist/standalone/bk-popover-help.js +1 -1
  216. package/dist/standalone/bk-popover.js +1 -1
  217. package/dist/standalone/bk-presence-cursor.js +2 -2
  218. package/dist/standalone/bk-preview.js +2 -2
  219. package/dist/standalone/bk-progress.js +1 -1
  220. package/dist/standalone/bk-prose.js +1 -1
  221. package/dist/standalone/bk-qr-code.js +1 -1
  222. package/dist/standalone/bk-radio-group.js +5 -5
  223. package/dist/standalone/bk-radio.js +2 -2
  224. package/dist/standalone/bk-rating.js +3 -3
  225. package/dist/standalone/bk-scroll.js +1 -1
  226. package/dist/standalone/bk-segmented-item.js +2 -2
  227. package/dist/standalone/bk-segmented.js +4 -4
  228. package/dist/standalone/bk-select-cascade.js +3 -3
  229. package/dist/standalone/bk-select-tree.js +4 -4
  230. package/dist/standalone/bk-select.js +4 -4
  231. package/dist/standalone/bk-shell-app.js +1 -1
  232. package/dist/standalone/bk-shell-centered.js +1 -1
  233. package/dist/standalone/bk-shell-sites.js +1 -1
  234. package/dist/standalone/bk-skeleton.js +1 -1
  235. package/dist/standalone/bk-sortable.js +2 -2
  236. package/dist/standalone/bk-spinner.js +1 -1
  237. package/dist/standalone/bk-split-grid.js +10 -7
  238. package/dist/standalone/bk-split.js +6 -6
  239. package/dist/standalone/bk-stack.js +1 -1
  240. package/dist/standalone/bk-stat-group.js +1 -1
  241. package/dist/standalone/bk-stat.js +3 -3
  242. package/dist/standalone/bk-status-dot.js +2 -2
  243. package/dist/standalone/bk-steps-item.js +2 -2
  244. package/dist/standalone/bk-steps.js +1 -1
  245. package/dist/standalone/bk-surface.js +1 -1
  246. package/dist/standalone/bk-swatch-group.js +6 -6
  247. package/dist/standalone/bk-swatch-palette.js +1 -1
  248. package/dist/standalone/bk-swatch.js +1 -1
  249. package/dist/standalone/bk-switch.js +2 -2
  250. package/dist/standalone/bk-table.js +1 -1
  251. package/dist/standalone/bk-tabs-item.js +2 -2
  252. package/dist/standalone/bk-tabs-panel.js +1 -1
  253. package/dist/standalone/bk-tabs.js +3 -414
  254. package/dist/standalone/bk-tasks-item.js +2 -2
  255. package/dist/standalone/bk-tasks.js +1 -1
  256. package/dist/standalone/bk-testimonial.js +2 -2
  257. package/dist/standalone/bk-text.js +3 -3
  258. package/dist/standalone/bk-time-countdown.js +2 -2
  259. package/dist/standalone/bk-time-relative.js +1 -1
  260. package/dist/standalone/bk-timeline-item.js +2 -2
  261. package/dist/standalone/bk-timeline.js +1 -1
  262. package/dist/standalone/bk-toast-group.js +1 -1
  263. package/dist/standalone/bk-toast.js +2 -2
  264. package/dist/standalone/bk-toolbar.js +1 -1
  265. package/dist/standalone/bk-tooltip.js +1 -1
  266. package/dist/standalone/bk-tree-item.js +3 -3
  267. package/dist/standalone/bk-tree.js +4 -4
  268. package/dist/standalone/bk-video.js +2 -2
  269. package/dist/standalone/bk-visually-hidden.js +1 -1
  270. package/dist/standalone/bk-zoom.js +3 -3
  271. package/dist/standalone/chunks/{announcer-D1zrRWwO.js → announcer-6tMlCOq1.js} +9 -4
  272. package/dist/standalone/chunks/{bk-alert-offline-Clw0ZSsH.js → bk-alert-offline-hCLuG-RM.js} +1 -1
  273. package/dist/standalone/chunks/{bk-carousel-Biz7t8sL.js → bk-carousel-_dudBMVq.js} +2 -2
  274. package/dist/standalone/chunks/{bk-diagram-D_fQf6SF.js → bk-diagram-BB2odomE.js} +2 -2
  275. package/dist/standalone/chunks/{bk-dialog-DwZyUUHh.js → bk-dialog-DcvwnOtN.js} +2 -2
  276. package/dist/standalone/chunks/{bk-icon-Bp_flKdv.js → bk-icon-D4kI4F18.js} +1 -1
  277. package/dist/standalone/chunks/{bk-image-editor-BADsoLRL.js → bk-image-editor-SRVkHI-4.js} +2 -2
  278. package/dist/standalone/chunks/{bk-input-date-range-DHcJ8-5g.js → bk-input-date-range-C0Vd-p0T.js} +2 -2
  279. package/dist/standalone/chunks/{bk-input-rich-CFhW6vRa.js → bk-input-rich-AmDv87E5.js} +3 -3
  280. package/dist/standalone/chunks/{bk-input-text-DviyLBqj.js → bk-input-text-2n89GDIT.js} +15 -5
  281. package/dist/standalone/chunks/{bk-model-viewer-w_Ah4Tvs.js → bk-model-viewer-BoNYBd6W.js} +2 -2
  282. package/dist/standalone/chunks/bk-picture-CA5gLxgZ.js +186 -0
  283. package/dist/standalone/chunks/{bk-qr-code-CYMovNVl.js → bk-qr-code-CSFfc8As.js} +1 -1
  284. package/dist/standalone/chunks/{bk-shell-app-B2lxHit8.js → bk-shell-app-BlCOG25y.js} +31 -30
  285. package/dist/standalone/chunks/{bk-surface-D7e0tErs.js → bk-surface-BULRdKam.js} +1 -1
  286. package/dist/standalone/chunks/{bk-swatch-palette-x13JgJQi.js → bk-swatch-palette-Cqj85tSW.js} +1 -1
  287. package/dist/standalone/chunks/{bk-table-CP8n_jy7.js → bk-table-DWlD7yoM.js} +72 -71
  288. package/dist/standalone/chunks/bk-tabs-STkr3-E1.js +422 -0
  289. package/dist/standalone/chunks/{bk-toast-group-CoL6W7uk.js → bk-toast-group-5nZg7BaJ.js} +2 -2
  290. package/dist/standalone/chunks/{busy-BUB22mGY.js → busy-eG3uHonz.js} +1 -1
  291. package/dist/standalone/chunks/{choice-field-poOTerh1.js → choice-field-B0oe_9fI.js} +4 -4
  292. package/dist/standalone/chunks/{date-field-B-fCXa2D.js → date-field-Dy1_qxNv.js} +2 -2
  293. package/dist/standalone/chunks/define-6OfuRn5c.js +60 -0
  294. package/dist/standalone/chunks/{form-control-CHpfKAKa.js → form-control-Bmk0SRDX.js} +1 -1
  295. package/dist/standalone/chunks/{handle-menu-BgYUbGO2.js → handle-menu-BAe9fPYJ.js} +10 -36
  296. package/dist/standalone/chunks/{heading-text-CgnCa_q2.js → heading-text-B2kF-b8p.js} +1 -1
  297. package/dist/standalone/chunks/hue-vLbNdAEl.js +20 -0
  298. package/dist/standalone/chunks/late-CPQ_RbU-.js +30 -0
  299. package/dist/standalone/chunks/{options-BdC8-KKM.js → options-ySaDL-dW.js} +1 -1
  300. package/dist/standalone/chunks/{stars-BgKEjDQx.js → stars-BAUc_LqI.js} +1 -1
  301. package/dist/standalone/chunks/tags-CMLAGsVw.js +37 -0
  302. package/dist/standalone/chunks/{text-field-CqhJSAwZ.js → text-field-CufOGdfr.js} +16 -10
  303. package/dist/standalone/chunks/{toggle-control-lvZbQtGW.js → toggle-control-Cgqp1jhf.js} +4 -2
  304. package/dist/standalone/chunks/{virtual-C_h6sHnm.js → virtual-D-qgACnE.js} +1 -1
  305. package/dist/standalone/confirm.js +2 -2
  306. package/dist/standalone/reset.css +1 -1
  307. package/dist/standalone/toast.js +1 -1
  308. package/dist/standalone/tokens.css +1 -1
  309. package/dist/tokens.css +1 -1
  310. package/package.json +2 -2
  311. package/dist/standalone/chunks/define-DkVeu7e9.js +0 -30
  312. package/dist/standalone/chunks/hue-Jvb-141g.js +0 -14
  313. package/dist/standalone/chunks/keyed-CZ2AaouM.js +0 -16
@@ -34,7 +34,7 @@ import "../icons/set/chevron-down.js";
34
34
  * a colour stays in the field, and the field shows "Enter a valid colour." and is invalid (`badInput`,
35
35
  * the `invalid` attribute) until the user corrects it. Leaving the field keeps the text and the error,
36
36
  * as a native field keeps a bad entry. Escape restores the last valid colour and removes the error.
37
- * The swatch is then the button that opens the panel; the chevron opens it too.
37
+ * The swatch is then the only button that opens the panel. The box shows no chevron: it is a text field, not a choice.
38
38
  *
39
39
  * Extras in the box (the shared text field extras of `bk-input-text`): `clearable` shows a clear
40
40
  * button while there is a colour; it sets the value to "" (no colour) and fires `input` and
@@ -53,7 +53,7 @@ import "../icons/set/chevron-down.js";
53
53
  * @csspart prefix - The `prefix` text.
54
54
  * @csspart suffix - The `suffix` text.
55
55
  * @csspart clear-button - The clear button of `clearable`.
56
- * @csspart chevron - The dropdown icon.
56
+ * @csspart chevron - The dropdown icon (not with `editable`).
57
57
  * @csspart popup - The popup dialog (the overlay surface).
58
58
  * @csspart panel - The `<bk-color-panel>` in the popup.
59
59
  * @csspart hint - Hint text.
@@ -246,9 +246,6 @@ export declare class BkInputColor extends TextField {
246
246
  render(): import("lit-html").TemplateResult<1>;
247
247
  /** The box of `editable`: the swatch opens the panel, the text field contains the colour as text. */
248
248
  private renderEditableBox;
249
- /** The chevron of `editable` opens and closes the panel like the swatch, and keeps the focus where it is. */
250
- private onChevronPointerdown;
251
- private onChevronClick;
252
249
  }
253
250
  declare global {
254
251
  interface HTMLElementTagNameMap {
@@ -72,8 +72,6 @@ class BkInputColor extends TextField {
72
72
  .box:has(.pick:focus) {
73
73
  border-color: var(--bk-field-border, var(--bk-line-strong)); box-shadow: var(--bk-field-shadow, var(--bk-shadow-control));
74
74
  }
75
- :host([editable]) .chevron { cursor: pointer; }
76
- :host([editable][disabled]) .chevron { cursor: not-allowed; }
77
75
  input { font-variant-numeric: tabular-nums; }
78
76
  /* The trigger fills the box: its ::before covers the whole box, so a click anywhere opens the panel. */
79
77
  .trigger {
@@ -364,20 +362,8 @@ class BkInputColor extends TextField {
364
362
  ${this.renderSuffix()}
365
363
  ${this.renderClear()}
366
364
  ${this.renderEnd()}
367
- <bk-icon class="chevron" part="chevron" name="chevron-down"
368
- @pointerdown=${this.onChevronPointerdown} @click=${this.onChevronClick}></bk-icon>
369
365
  </div>`;
370
366
  }
371
- /** The chevron of `editable` opens and closes the panel like the swatch, and keeps the focus where it is. */
372
- onChevronPointerdown(e) {
373
- e.preventDefault();
374
- this.onBoxPointerdown();
375
- }
376
- onChevronClick() {
377
- if (this.isDisabled)
378
- return;
379
- this.onBoxClick();
380
- }
381
367
  }
382
368
  define("bk-input-color", BkInputColor);
383
369
  export {
@@ -86,11 +86,27 @@ export type FilePasteScope = "focus" | "page";
86
86
  * a button that opens a gallery of the app. The field styles them like its browse button. The
87
87
  * app passes the chosen files to `addFiles()`. `accept` and `max-files` apply to them too.
88
88
  *
89
+ * Put a preview of the chosen file in the `preview` slot, for example a picture, a 3D viewer or a crop
90
+ * tool. The zone then shows the preview in place of its icon, with the prompt, the browse button and
91
+ * the actions in a row below it. The field shows no list and no tiles: the app shows the files and
92
+ * uploads them. The zone still accepts dropped and pasted files, and fires `input` and `change`.
93
+ * Without `multiple` a new file replaces the chosen one. A click on the preview does not open the
94
+ * file dialog. To show the empty zone again, remove the preview and set `files = []`
95
+ * (a form reset clears `files` too).
96
+ *
97
+ * ```html
98
+ * <bk-input-file name="image" label="Image" accept="image/*">
99
+ * <img slot="preview" src="blob:…" alt="The chosen image">
100
+ * </bk-input-file>
101
+ * ```
102
+ *
89
103
  * @slot - Prompt in the zone before the browse button (default: i18n `fileDropPrompt`).
90
104
  * @slot actions - Other sources of files after the browse button: `<button type="button">` elements, in the look of the browse button.
105
+ * @slot preview - A preview of the chosen file in the zone, in place of the icon (a picture, a viewer, a crop tool). The field then shows no list and no tiles.
91
106
  * @csspart field - Wrapper of label, zone, hint and list.
92
107
  * @csspart label - The visible label.
93
108
  * @csspart zone - The dashed drop zone.
109
+ * @csspart preview - The area of the `preview` slot in the zone.
94
110
  * @csspart browse - The button that opens the file dialog.
95
111
  * @csspart browse-folder - The button that opens the folder dialog (`folders`).
96
112
  * @csspart files - The list of chosen files.
@@ -114,6 +130,7 @@ export type FilePasteScope = "focus" | "page";
114
130
  * @cssprop --bk-input-file-padding-block - Space above and below the zone content (default from `size`: --bk-space-3, --bk-space-5, --bk-space-8).
115
131
  * @cssprop --bk-input-file-padding-inline - Space before and after the zone content (default from `size`: --bk-space-3, --bk-space-4, --bk-space-6).
116
132
  * @cssprop --bk-input-file-gap - Space between icon and prompt (default --bk-space-1).
133
+ * @cssprop --bk-input-file-preview-gap - Space between the preview and the row of the browse button (default --bk-space-2).
117
134
  * @cssprop --bk-input-file-font-size - Zone text size (default from `size`: --bk-type-small, --bk-type-small, --bk-type-body).
118
135
  * @cssprop --bk-input-file-icon-size - Zone icon size (default from `size`: --bk-icon-md, --bk-icon-lg, 1.5 × --bk-icon-lg).
119
136
  * @cssprop --bk-input-file-icon-color - Zone icon colour (default: the text colour).
@@ -135,10 +135,14 @@ class BkInputFile extends FormControl {
135
135
  font-size: var(--_bk-input-file-font); line-height: var(--bk-line-height-tight); text-align: center;
136
136
  cursor: pointer; transition: border-color var(--bk-duration-fast), background-color var(--bk-duration-fast), box-shadow var(--bk-duration-fast);
137
137
  }
138
+ .zone.has-preview { gap: var(--bk-input-file-preview-gap, var(--bk-space-2)); }
139
+ .preview { justify-self: stretch; display: grid; place-items: center; min-inline-size: 0; cursor: auto; }
140
+ .preview[hidden] { display: none; }
141
+ .preview ::slotted(*) { max-inline-size: 100%; }
138
142
  .zone bk-icon { --bk-icon-size: var(--_bk-input-file-icon-size); color: var(--bk-input-file-icon-color, currentColor); }
139
143
  @media (hover: hover) { :host(:not([disabled])) .zone:hover:not(:focus-within) { border-color: var(--bk-input-file-hover-border, var(--bk-line-hover)); } }
140
- /* The zone is the field: it shows focus on any focus, like the box of an input. */
141
- .zone:focus-within {
144
+ /* The zone is the field: it shows focus on any focus, like the box of an input. A preview with focus shows its own focus. */
145
+ .zone:not(.has-preview):focus-within, .zone.has-preview:has(> .line:focus-within) {
142
146
  border-style: solid; border-color: var(--bk-input-file-active-border, var(--bk-accent-solid));
143
147
  box-shadow: var(--bk-field-focus-ring, var(--bk-ring-focus));
144
148
  }
@@ -439,6 +443,9 @@ class BkInputFile extends FormControl {
439
443
  onZoneClick(e) {
440
444
  if (e.target.closest?.(".browse, [slot='actions']"))
441
445
  return;
446
+ const preview = this.renderRoot.querySelector(".preview");
447
+ if (preview && e.composedPath().includes(preview))
448
+ return;
442
449
  this.showPicker();
443
450
  }
444
451
  hasFiles(e) {
@@ -597,12 +604,14 @@ class BkInputFile extends FormControl {
597
604
  ?disabled=${this.isDisabled} @change=${this.onPick} @click=${(e) => e.stopPropagation()} />
598
605
  ${this.folders ? html`<input type="file" webkitdirectory tabindex="-1" aria-hidden="true" ?disabled=${this.isDisabled}
599
606
  @change=${this.onPick} @click=${(e) => e.stopPropagation()} />` : nothing}`;
600
- const zone = html`<div class="zone ${this.dragging ? "dragging" : ""} ${this.invalid ? "has-error" : ""}" part="zone"
607
+ const preview = this.slots.has("preview");
608
+ const zone = html`<div class="zone ${this.dragging ? "dragging" : ""} ${this.invalid ? "has-error" : ""} ${preview ? "has-preview" : ""}" part="zone"
601
609
  aria-disabled=${ifDefined(this.isDisabled ? "true" : void 0)}
602
610
  @click=${this.onZoneClick} @dragenter=${this.onDragEnter} @dragover=${this.onDragOver}
603
611
  @dragleave=${this.onDragLeave} @drop=${this.onDrop}>
604
- <bk-icon name=${this.icon}></bk-icon>
605
- <span><span class="prompt" id="prompt"><slot></slot>${this.slots.has("") ? nothing : this.i18n.t(this.folders ? "fileDropPromptFolders" : this.multiple ? "fileDropPromptMany" : "fileDropPrompt")}</span>
612
+ ${preview ? nothing : html`<bk-icon name=${this.icon}></bk-icon>`}
613
+ <div class="preview" part="preview" ?hidden=${!preview}><slot name="preview"></slot></div>
614
+ <span class="line"><span class="prompt" id="prompt"><slot></slot>${this.slots.has("") ? nothing : this.i18n.t(this.folders ? "fileDropPromptFolders" : this.multiple ? "fileDropPromptMany" : "fileDropPrompt")}</span>
606
615
  <button type="button" class="browse" part="browse" id="control" ?disabled=${this.isDisabled}
607
616
  aria-labelledby=${ifDefined(this.label ? "label control" : void 0)}
608
617
  aria-label=${ifDefined(external ? `${external}, ${browse}` : void 0)}
@@ -614,7 +623,8 @@ class BkInputFile extends FormControl {
614
623
  @click=${() => this.showFolderPicker()}>${folder}</button>` : nothing}${this.slots.has("actions") ? html`<span aria-hidden="true"> · </span>` : nothing}<slot name="actions"></slot></span>
615
624
  ${inputs}
616
625
  </div>`;
617
- const tiles = this.variant === "tiles" && this.files.length > 0;
626
+ const tiles = this.variant === "tiles" && this.files.length > 0 && !preview;
627
+ const list = this.files.length > 0 && !tiles && !preview;
618
628
  return html`${fieldTemplate({
619
629
  label: this.label,
620
630
  hint: this.fieldHint(this.hint),
@@ -626,10 +636,10 @@ class BkInputFile extends FormControl {
626
636
  labelFor: "control",
627
637
  control: tiles ? this.renderTiles(inputs, desc, external) : zone
628
638
  })}
629
- ${this.files.length && !tiles ? html`<ul class="files" part="files" aria-label=${this.i18n.t("fileList")}>
639
+ ${list ? html`<ul class="files" part="files" aria-label=${this.i18n.t("fileList")}>
630
640
  ${repeat(this.files, (f) => f, (f, i) => this.renderFile(f, i))}
631
641
  </ul>` : nothing}
632
- ${many && this.files.length ? html`<bk-bar class="footer" part="footer">
642
+ ${many && this.files.length && !preview ? html`<bk-bar class="footer" part="footer">
633
643
  <span>${this.maxFiles === void 0 ? this.i18n.t("fileCount", { count: this.files.length }) : this.i18n.t("fileCountOf", { count: this.files.length, max: this.maxFiles })}</span>
634
644
  <bk-button slot="end" class="remove-all" part="remove-all" variant="ghost" size="sm" ?disabled=${this.isDisabled}
635
645
  @click=${this.onRemoveAll}>${this.i18n.t("fileRemoveAll")}</bk-button>
@@ -0,0 +1,219 @@
1
+ import { type PropertyValues } from "lit";
2
+ import { TextField } from "../internal/text-field.js";
3
+ import type { BkChip } from "./bk-chip.js";
4
+ import "./bk-chip.js";
5
+ /** `detail` of the `add` event: the text that the user wants to add as a tag. */
6
+ export type InputTagsAddDetail = {
7
+ value: string;
8
+ };
9
+ /** `detail` of the `remove` event: the value of the tag, and the slotted chip (undefined for a chip of the element). */
10
+ export type InputTagsRemoveDetail = {
11
+ value: string;
12
+ chip?: BkChip;
13
+ };
14
+ /**
15
+ * A text field for a list of short values, for example the tags of a record. Each value shows as a `<bk-chip>` before
16
+ * the text. The user types a value and adds it with Enter or a comma.
17
+ *
18
+ * ```html
19
+ * <bk-input-tags label="Tags" name="tags" placeholder="Add a tag…"></bk-input-tags>
20
+ * ```
21
+ *
22
+ * - **Value**: `values` is the list of values, in the order the user added them. A value that is already in the list
23
+ * is not added again. The compare is case-sensitive: "Design" and "design" are two values.
24
+ * - **Keyboard**: Enter or a comma adds the typed text. Backspace in the empty text removes the last tag. When the
25
+ * field loses focus, the field adds the typed text. A pasted list (parts with a comma, a semicolon or a line break
26
+ * between them) adds one tag for each part.
27
+ * - **Events**: before the field adds a value, it fires a cancelable `add` event (`detail.value`). Before it removes a
28
+ * value (Backspace or the remove button of a chip), it fires a cancelable `remove` event (`detail.value`). Cancel the
29
+ * event to keep the list as it is, for example for a value that is not valid. The typed text of a cancelled `add`
30
+ * stays in the field. After a change of `values`, the field fires `input` and `change`.
31
+ * - **Slotted chips**: put `<bk-chip>` elements in the default slot, and the field shows them instead of its own
32
+ * chips. The app then controls the chips: the field adds and removes no chip itself. `add` and `remove`
33
+ * (`detail.chip` is the chip) tell the app what the user wants. The app adds a chip, removes it, or marks it
34
+ * (`removed`, `tone="success"`), for example in a diff of tags. The value is the text of each chip that is not
35
+ * `removed`. The field stops the `remove` event of a slotted chip and fires its own `remove` (`detail.chip` is the
36
+ * chip), so a listener on the field gets one shape for Backspace and for the remove button. A listener on the chip
37
+ * still gets the event of the chip. The `restore` event of a `removed` chip bubbles to the app unchanged: its target
38
+ * is the chip. Give the chips `removable` and the `size` of the field. Without slotted chips, the field shows
39
+ * `values` again.
40
+ * - **Forms**: form-associated like a native control: `name`, `values` (one entry for each value), `required` (an empty
41
+ * list is not valid), reset (to the values at the first connection), disabled fieldsets, `<label for>`.
42
+ * - **Box**: the shared text box of `<bk-input-text>`: `label`, `hint`, `error`, `size`, the `icon` attribute and the
43
+ * `start` slot, `prefix` and `suffix` (the prefix comes before the tags), the `end` slot and `clearable`. The clear
44
+ * button empties the typed text and the values of the field (not slotted chips).
45
+ *
46
+ * i18n keys: `valueRequired`, `clear`; the chips use `removeItem` and `restoreItem`. `clear-label` overrides the name of
47
+ * the clear button.
48
+ *
49
+ * @tag bk-input-tags
50
+ * @keyboard Enter, Comma - Add the typed text as a tag. Enter in an empty field submits the form.
51
+ * @keyboard Backspace - In an empty field, remove the last tag (not a `removed` chip).
52
+ * @a11y A native text `<input>` with its `<label>`. The description of the input lists the values. The remove button of each chip is a native button in the tab order, named "Remove {item}" ("Restore {item}" on a `removed` chip). The clear button is not in the tab order.
53
+ * @fires {Event} restore - The `restore` event of a slotted `removed` chip, unchanged (the chip is the target).
54
+ * @slot - `<bk-chip>` elements that the app controls (see "Slotted chips").
55
+ * @slot start - Leading content inside the box, for example a `<bk-icon>`.
56
+ * @slot end - Trailing content inside the box.
57
+ * @slot label-end - Content after the label in its row, for example a `<bk-popover-help>`.
58
+ * @slot hint - Rich hint below the control, for example with inline `<code>`. It replaces the `hint` text. The control uses it as its description.
59
+ * @csspart field - Wrapper of label, box and hint.
60
+ * @csspart label - The `<label>`.
61
+ * @csspart box - The bordered box.
62
+ * @csspart input - The text `<input>`.
63
+ * @csspart tag - Each value of the field (a `<bk-chip>`). Slotted chips are not parts.
64
+ * @csspart prefix - The `prefix` text.
65
+ * @csspart suffix - The `suffix` text.
66
+ * @csspart clear-button - The clear button of `clearable`.
67
+ * @csspart hint - Hint text under the box.
68
+ * @csspart error - Error text.
69
+ * @cssprop --bk-input-tags-font-size - Text size in the box (default from `size`: --bk-type-small, --bk-type-body, --bk-type-lead).
70
+ * @cssprop --bk-input-tags-tag-gap - Space between the tags and the text (default --bk-space-1).
71
+ * @cssprop --bk-input-tags-tags-padding - Padding of the box with tags above, below and before the first chip (default the inset of a button in a field: --bk-field-button-inset, else --bk-space-0 / --bk-space-1 / --bk-space-1-5 by size).
72
+ * @cssprop --bk-input-tags-input-min-width - Narrowest text field next to the tags before it wraps (default --bk-target-min).
73
+ * @cssprop --bk-field-* - Shared field tokens, see `<bk-input-text>`.
74
+ * @fires {CustomEvent<InputTagsAddDetail>} add - The user adds a value (Enter, comma, paste, blur). Cancelable: cancel it to keep the list as it is. It bubbles and is composed.
75
+ * @fires {CustomEvent<InputTagsRemoveDetail>} remove - The user removes a value (Backspace, or the remove button of a chip of the field). Cancelable. It bubbles and is composed. With slotted chips, `detail.chip` is the chip. The field stops the `remove` event of a slotted chip at the field and fires this event instead.
76
+ * @fires {Event} input - When the values of the field change by the user (added, removed, cleared).
77
+ * @fires {Event} change - When the values of the field change by the user.
78
+ */
79
+ export declare class BkInputTags extends TextField {
80
+ static properties: {
81
+ name: {
82
+ reflect: boolean;
83
+ useDefault: boolean;
84
+ };
85
+ disabled: {
86
+ type: BooleanConstructor;
87
+ reflect: boolean;
88
+ };
89
+ required: {
90
+ type: BooleanConstructor;
91
+ reflect: boolean;
92
+ };
93
+ invalid: {
94
+ type: BooleanConstructor;
95
+ reflect: boolean;
96
+ };
97
+ validationText: {
98
+ state: boolean;
99
+ };
100
+ externalLabel: {
101
+ state: boolean;
102
+ };
103
+ optional: {
104
+ type: BooleanConstructor;
105
+ reflect: boolean;
106
+ };
107
+ label: {};
108
+ hint: {};
109
+ error: {};
110
+ icon: {};
111
+ size: {
112
+ reflect: boolean;
113
+ useDefault: boolean;
114
+ };
115
+ prefixText: {
116
+ attribute: string;
117
+ };
118
+ suffixText: {
119
+ attribute: string;
120
+ };
121
+ clearable: {
122
+ type: BooleanConstructor;
123
+ reflect: boolean;
124
+ };
125
+ clearLabel: {
126
+ attribute: string;
127
+ };
128
+ labelPosition: {
129
+ attribute: string;
130
+ reflect: boolean;
131
+ useDefault: boolean;
132
+ };
133
+ values: {
134
+ attribute: boolean;
135
+ noAccessor: boolean;
136
+ };
137
+ placeholder: {};
138
+ readonly: {
139
+ type: BooleanConstructor;
140
+ reflect: boolean;
141
+ };
142
+ enterKeyHint: {
143
+ attribute: string;
144
+ };
145
+ text: {
146
+ state: boolean;
147
+ };
148
+ };
149
+ static styles: import("lit").CSSResultGroup[];
150
+ /** Text shown while the field has no tags. */
151
+ placeholder: string | undefined;
152
+ /** Shows the values, but the user cannot change them. */
153
+ readonly: boolean;
154
+ /** Label of the Enter key on a phone keyboard, like the native `enterkeyhint`: `enter`, `done`, `go`, `next`, `previous`, `search`, `send`. */
155
+ enterKeyHint: string;
156
+ /** The typed text that is not a tag yet. */
157
+ private text;
158
+ /** The values of the field when it has no slotted chips. */
159
+ private own;
160
+ /** The values at the first connection, restored on form reset. */
161
+ defaultValues: string[];
162
+ private connectedOnce;
163
+ private observer;
164
+ constructor();
165
+ /** The slotted `<bk-chip>` elements, in their order. */
166
+ private get chips();
167
+ /** The app controls the chips: the default slot has `<bk-chip>` elements. */
168
+ private get controlled();
169
+ /** The values: the text of the slotted chips that are not `removed`, else the values of the field. */
170
+ get values(): string[];
171
+ set values(v: string[]);
172
+ connectedCallback(): void;
173
+ disconnectedCallback(): void;
174
+ protected get control(): HTMLInputElement | null;
175
+ focus(options?: FocusOptions): void;
176
+ blur(): void;
177
+ protected get changeable(): boolean;
178
+ protected formValue(): FormData | null;
179
+ protected formState(): string;
180
+ protected resetValue(): void;
181
+ protected restoreValue(state: string): void;
182
+ protected computeValidity(): {
183
+ flags: ValidityStateFlags;
184
+ message: string;
185
+ };
186
+ protected get filled(): boolean;
187
+ protected emptyValue(): false | undefined;
188
+ /** Sets the values of the field after a user action; fires `input` and `change` when they changed. */
189
+ private commit;
190
+ /**
191
+ * Asks to add each of `values`: a cancelable `add` for each value that is not in the list yet. Without slotted
192
+ * chips the field adds the values that nobody cancelled. Returns the cancelled values.
193
+ */
194
+ private addValues;
195
+ /** Adds the typed text as a tag. A cancelled `add` keeps the text in the field. */
196
+ private addTyped;
197
+ /** Asks to remove `value`: a cancelable `remove`. Without slotted chips the field removes it. */
198
+ private removeValue;
199
+ /** The last tag that is not `removed`: the value and the slotted chip. */
200
+ private get lastTag();
201
+ private onInput;
202
+ private onKeydown;
203
+ /** A pasted list adds one tag for each part. The parts with a cancelled `add` stay in the field as text. */
204
+ private onPaste;
205
+ private onFocusOut;
206
+ /** A click in the box puts the caret into the text. Chips, the clear button and the `end` slot content have their own action. */
207
+ private onBoxClick;
208
+ /** The remove button of a slotted chip: the field stops the event of the chip and fires its own `remove`. */
209
+ private onSlottedRemove;
210
+ private onTagRemove;
211
+ protected willUpdate(changed: PropertyValues): void;
212
+ render(): import("lit-html").TemplateResult<1>;
213
+ }
214
+ declare global {
215
+ interface HTMLElementTagNameMap {
216
+ "bk-input-tags": BkInputTags;
217
+ }
218
+ }
219
+ //# sourceMappingURL=bk-input-tags.d.ts.map
@@ -0,0 +1,293 @@
1
+ import { css, html, nothing } from "lit";
2
+ import { ifDefined } from "lit/directives/if-defined.js";
3
+ import { live } from "lit/directives/live.js";
4
+ import { define } from "../internal/define.js";
5
+ import { emit, emitDetail } from "../internal/events.js";
6
+ import { lightDom, mutationObserver } from "../internal/server.js";
7
+ import { submitImplicitly } from "../internal/submit.js";
8
+ import { pastedTags, tagFieldStyles } from "../internal/tags.js";
9
+ import { TextField } from "../internal/text-field.js";
10
+ import "./bk-chip.js";
11
+ function chipText(chip) {
12
+ return [...chip.childNodes].filter((n) => !(n instanceof Element && n.slot)).map((n) => n.textContent ?? "").join("").trim();
13
+ }
14
+ const listFormats = /* @__PURE__ */ new Map();
15
+ function listFormat(locale) {
16
+ let f = listFormats.get(locale);
17
+ if (!f)
18
+ listFormats.set(locale, f = new Intl.ListFormat(locale, { type: "unit", style: "short" }));
19
+ return f;
20
+ }
21
+ class BkInputTags extends TextField {
22
+ static properties = {
23
+ ...TextField.properties,
24
+ values: { attribute: false, noAccessor: true },
25
+ placeholder: {},
26
+ readonly: { type: Boolean, reflect: true },
27
+ enterKeyHint: { attribute: "enterkeyhint" },
28
+ text: { state: true }
29
+ };
30
+ static styles = [TextField.styles, tagFieldStyles("input-tags"), css`
31
+ :host { --_bk-text-field-font-size: var(--bk-input-tags-font-size); }
32
+ `];
33
+ /** The values of the field when it has no slotted chips. */
34
+ own = [];
35
+ /** The values at the first connection, restored on form reset. */
36
+ defaultValues = [];
37
+ connectedOnce = false;
38
+ observer = mutationObserver(() => this.requestUpdate());
39
+ constructor() {
40
+ super();
41
+ this.readonly = false;
42
+ this.enterKeyHint = "";
43
+ this.text = "";
44
+ }
45
+ /** The slotted `<bk-chip>` elements, in their order. */
46
+ get chips() {
47
+ const host = lightDom(this);
48
+ return host ? [...host.children].filter((c) => c.localName === "bk-chip" && !c.slot) : [];
49
+ }
50
+ /** The app controls the chips: the default slot has `<bk-chip>` elements. */
51
+ get controlled() {
52
+ return this.chips.length > 0;
53
+ }
54
+ /** The values: the text of the slotted chips that are not `removed`, else the values of the field. */
55
+ get values() {
56
+ const chips = this.chips;
57
+ return chips.length ? chips.filter((c) => !c.hasAttribute("removed")).map(chipText) : [...this.own];
58
+ }
59
+ set values(v) {
60
+ const old = this.values;
61
+ this.own = [...new Set((v ?? []).map(String).filter(Boolean))];
62
+ this.requestUpdate("values", old);
63
+ }
64
+ connectedCallback() {
65
+ super.connectedCallback();
66
+ if (!this.connectedOnce) {
67
+ this.connectedOnce = true;
68
+ if (!this.defaultValues.length)
69
+ this.defaultValues = [...this.own];
70
+ }
71
+ this.observer.observe(this, { childList: true, subtree: true, characterData: true, attributes: true, attributeFilter: ["removed", "slot"] });
72
+ }
73
+ disconnectedCallback() {
74
+ super.disconnectedCallback();
75
+ this.observer.disconnect();
76
+ }
77
+ get control() {
78
+ return this.renderRoot?.querySelector("input") ?? null;
79
+ }
80
+ focus(options) {
81
+ this.control?.focus(options);
82
+ }
83
+ blur() {
84
+ this.control?.blur();
85
+ }
86
+ get changeable() {
87
+ return super.changeable && !this.readonly;
88
+ }
89
+ /* ---------- form ---------- */
90
+ formValue() {
91
+ const values = this.values;
92
+ if (!this.name || !values.length)
93
+ return null;
94
+ const data = new FormData();
95
+ for (const v of values)
96
+ data.append(this.name, v);
97
+ return data;
98
+ }
99
+ formState() {
100
+ return JSON.stringify(this.values);
101
+ }
102
+ resetValue() {
103
+ this.values = [...this.defaultValues];
104
+ this.text = "";
105
+ }
106
+ restoreValue(state) {
107
+ try {
108
+ const list = JSON.parse(state);
109
+ if (Array.isArray(list))
110
+ this.values = list;
111
+ } catch {
112
+ }
113
+ }
114
+ computeValidity() {
115
+ return this.required && !this.values.length ? { flags: { valueMissing: true }, message: this.i18n.t("valueRequired") } : { flags: {}, message: "" };
116
+ }
117
+ /* ---------- clear button ---------- */
118
+ get filled() {
119
+ return !!this.text || !this.controlled && this.own.length > 0;
120
+ }
121
+ emptyValue() {
122
+ this.text = "";
123
+ if (this.controlled || !this.own.length)
124
+ return false;
125
+ this.values = [];
126
+ }
127
+ /* ---------- value ---------- */
128
+ /** Sets the values of the field after a user action; fires `input` and `change` when they changed. */
129
+ commit(next) {
130
+ const old = this.own;
131
+ if (next.join("\0") === old.join("\0"))
132
+ return;
133
+ this.own = next;
134
+ this.requestUpdate("values", old);
135
+ emit(this, "input");
136
+ emit(this, "change");
137
+ }
138
+ /**
139
+ * Asks to add each of `values`: a cancelable `add` for each value that is not in the list yet. Without slotted
140
+ * chips the field adds the values that nobody cancelled. Returns the cancelled values.
141
+ */
142
+ addValues(values) {
143
+ const rejected = [];
144
+ let next = this.own;
145
+ for (const value of values) {
146
+ if ((this.controlled ? this.values : next).includes(value))
147
+ continue;
148
+ if (!emitDetail(this, "add", { value }, true))
149
+ rejected.push(value);
150
+ else if (!this.controlled)
151
+ next = [...next, value];
152
+ }
153
+ if (!this.controlled)
154
+ this.commit(next);
155
+ return rejected;
156
+ }
157
+ /** Adds the typed text as a tag. A cancelled `add` keeps the text in the field. */
158
+ addTyped() {
159
+ const t = this.text.trim();
160
+ if (!t) {
161
+ this.text = "";
162
+ return;
163
+ }
164
+ if (!this.addValues([t]).length)
165
+ this.text = "";
166
+ }
167
+ /** Asks to remove `value`: a cancelable `remove`. Without slotted chips the field removes it. */
168
+ removeValue(value, chip) {
169
+ if (!emitDetail(this, "remove", { value, chip }, true) || this.controlled)
170
+ return;
171
+ this.commit(this.own.filter((v) => v !== value));
172
+ }
173
+ /** The last tag that is not `removed`: the value and the slotted chip. */
174
+ get lastTag() {
175
+ if (!this.controlled)
176
+ return this.own.length ? { value: this.own[this.own.length - 1] } : void 0;
177
+ const chip = this.chips.filter((c) => !c.hasAttribute("removed")).pop();
178
+ return chip ? { value: chipText(chip), chip } : void 0;
179
+ }
180
+ /* ---------- events ---------- */
181
+ onInput(e) {
182
+ e.stopPropagation();
183
+ this.text = e.target.value;
184
+ }
185
+ onKeydown(e) {
186
+ if (!this.changeable || e.isComposing)
187
+ return;
188
+ switch (e.key) {
189
+ case "Enter": {
190
+ if (this.text.trim()) {
191
+ e.preventDefault();
192
+ this.addTyped();
193
+ return;
194
+ }
195
+ const form = this.internals.form;
196
+ if (form)
197
+ setTimeout(() => submitImplicitly(form));
198
+ return;
199
+ }
200
+ case ",":
201
+ e.preventDefault();
202
+ this.addTyped();
203
+ return;
204
+ case "Backspace": {
205
+ const last = this.text ? void 0 : this.lastTag;
206
+ if (!last)
207
+ return;
208
+ e.preventDefault();
209
+ this.removeValue(last.value, last.chip);
210
+ return;
211
+ }
212
+ }
213
+ }
214
+ /** A pasted list adds one tag for each part. The parts with a cancelled `add` stay in the field as text. */
215
+ onPaste(e) {
216
+ if (!this.changeable)
217
+ return;
218
+ const parts = pastedTags(e, this.text);
219
+ if (parts)
220
+ this.text = this.addValues(parts).join(", ");
221
+ }
222
+ onFocusOut(e) {
223
+ const to = e.relatedTarget;
224
+ if (to && (this.renderRoot.contains(to) || this.contains(to)))
225
+ return;
226
+ if (this.changeable && this.text.trim())
227
+ this.addTyped();
228
+ }
229
+ /** A click in the box puts the caret into the text. Chips, the clear button and the `end` slot content have their own action. */
230
+ onBoxClick(e) {
231
+ if (this.isDisabled)
232
+ return;
233
+ const own = (n) => n instanceof Element && (n.localName === "bk-chip" || n.classList.contains("clear") || n.parentElement === this && n.slot === "end");
234
+ if (e.composedPath().some(own))
235
+ return;
236
+ this.control?.focus();
237
+ }
238
+ /** The remove button of a slotted chip: the field stops the event of the chip and fires its own `remove`. */
239
+ onSlottedRemove(e) {
240
+ const chip = e.target;
241
+ if (chip.localName !== "bk-chip" || chip.parentElement !== this)
242
+ return;
243
+ e.stopPropagation();
244
+ if (this.changeable)
245
+ this.removeValue(chipText(chip), chip);
246
+ }
247
+ onTagRemove(e, value) {
248
+ e.stopPropagation();
249
+ if (!this.changeable)
250
+ return;
251
+ this.removeValue(value);
252
+ this.control?.focus();
253
+ }
254
+ /* ---------- render ---------- */
255
+ willUpdate(changed) {
256
+ super.willUpdate(changed);
257
+ if ((changed.has("readonly") || changed.has("disabled")) && !this.changeable)
258
+ this.text = "";
259
+ }
260
+ render() {
261
+ const controlled = this.controlled;
262
+ const values = this.values;
263
+ const tags = controlled || values.length > 0;
264
+ const desc = this.descriptionIds(values.length ? "tags-text" : void 0);
265
+ const removable = this.changeable;
266
+ const invalid = this.showInvalid;
267
+ return html`<div @focusout=${this.onFocusOut}>
268
+ ${this.renderField(html`<div class="${this.boxClass}${tags ? " has-tags" : ""}${tags && !this.hasLead ? " tags-first" : ""}" part="box" @click=${this.onBoxClick}>
269
+ ${this.renderStart()}
270
+ ${this.renderPrefix()}
271
+ <div class="values">
272
+ <span class="tags">${controlled ? nothing : this.own.map((v) => html`<bk-chip part="tag" size=${this.size} ?removable=${removable}
273
+ @remove=${(e) => this.onTagRemove(e, v)}>${v}</bk-chip>`)}<slot @remove=${this.onSlottedRemove}></slot></span>
274
+ <input part="input" id="control" type="text" autocomplete="off" autocapitalize="off" spellcheck="false"
275
+ enterkeyhint=${ifDefined(this.enterKeyHint || void 0)} .value=${live(this.text)}
276
+ placeholder=${ifDefined(tags ? void 0 : this.placeholder)} ?disabled=${this.isDisabled} ?readonly=${this.readonly}
277
+ aria-label=${ifDefined(this.label ? void 0 : this.forwardedName)} aria-describedby=${ifDefined(desc)}
278
+ aria-required=${this.required ? "true" : "false"} aria-invalid=${invalid ? "true" : "false"}
279
+ @input=${this.onInput} @paste=${this.onPaste} @change=${(e) => e.stopPropagation()} @keydown=${this.onKeydown} />
280
+ ${values.length ? html`<span class="sr-only" id="tags-text">${listFormat(this.i18n.locale).format(values)}</span>` : nothing}
281
+ </div>
282
+ ${this.renderSuffix()}
283
+ ${this.renderClear()}
284
+ ${this.renderEnd()}
285
+ </div>`)}
286
+ </div>`;
287
+ }
288
+ }
289
+ define("bk-input-tags", BkInputTags);
290
+ export {
291
+ BkInputTags
292
+ };
293
+ //# sourceMappingURL=bk-input-tags.js.map