@xerios/design-system 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +403 -2
  3. package/dist/components/AnchorHeading.svelte +79 -0
  4. package/dist/components/AnchorHeading.svelte.d.ts +28 -0
  5. package/dist/components/Breadcrumbs.svelte +216 -0
  6. package/dist/components/Breadcrumbs.svelte.d.ts +37 -0
  7. package/dist/components/Button.svelte +185 -0
  8. package/dist/components/Button.svelte.d.ts +70 -0
  9. package/dist/components/Canvas.svelte +248 -0
  10. package/dist/components/Canvas.svelte.d.ts +91 -0
  11. package/dist/components/Collapsible.svelte +139 -0
  12. package/dist/components/Collapsible.svelte.d.ts +52 -0
  13. package/dist/components/CollapsibleAdvanced.svelte +174 -0
  14. package/dist/components/CollapsibleAdvanced.svelte.d.ts +43 -0
  15. package/dist/components/DashOutline.svelte +47 -0
  16. package/dist/components/DashOutline.svelte.d.ts +6 -0
  17. package/dist/components/Dialogs.svelte +123 -0
  18. package/dist/components/Dialogs.svelte.d.ts +6 -0
  19. package/dist/components/Drawer.svelte +231 -0
  20. package/dist/components/Drawer.svelte.d.ts +62 -0
  21. package/dist/components/ErrorMessage.svelte +140 -0
  22. package/dist/components/ErrorMessage.svelte.d.ts +41 -0
  23. package/dist/components/Icon.svelte +94 -0
  24. package/dist/components/Icon.svelte.d.ts +33 -0
  25. package/dist/components/InfoTip.svelte +183 -0
  26. package/dist/components/InfoTip.svelte.d.ts +28 -0
  27. package/dist/components/Md.svelte +28 -0
  28. package/dist/components/Md.svelte.d.ts +11 -0
  29. package/dist/components/Modal.svelte +91 -0
  30. package/dist/components/Modal.svelte.d.ts +41 -0
  31. package/dist/components/Notice.svelte +50 -0
  32. package/dist/components/Notice.svelte.d.ts +30 -0
  33. package/dist/components/Popover.svelte +212 -0
  34. package/dist/components/Popover.svelte.d.ts +70 -0
  35. package/dist/components/Shimmer.svelte +27 -0
  36. package/dist/components/Shimmer.svelte.d.ts +22 -0
  37. package/dist/components/Splitter.svelte +152 -0
  38. package/dist/components/Splitter.svelte.d.ts +41 -0
  39. package/dist/components/Table.svelte +448 -0
  40. package/dist/components/Table.svelte.d.ts +268 -0
  41. package/dist/components/Toast.svelte +273 -0
  42. package/dist/components/Toast.svelte.d.ts +31 -0
  43. package/dist/components/Tooltip.svelte +97 -0
  44. package/dist/components/Tooltip.svelte.d.ts +19 -0
  45. package/dist/components/WorkingBorder.svelte +105 -0
  46. package/dist/components/WorkingBorder.svelte.d.ts +26 -0
  47. package/dist/components/empty/Empty.svelte +55 -0
  48. package/dist/components/empty/Empty.svelte.d.ts +39 -0
  49. package/dist/components/empty/EmptyError.svelte +47 -0
  50. package/dist/components/empty/EmptyError.svelte.d.ts +28 -0
  51. package/dist/components/empty/index.d.ts +18 -0
  52. package/dist/components/empty/index.js +10 -0
  53. package/dist/components/filters/DateFilter.svelte +59 -0
  54. package/dist/components/filters/DateFilter.svelte.d.ts +23 -0
  55. package/dist/components/filters/FilterBar.svelte +401 -0
  56. package/dist/components/filters/FilterBar.svelte.d.ts +283 -0
  57. package/dist/components/filters/FilterChip.svelte +235 -0
  58. package/dist/components/filters/FilterChip.svelte.d.ts +68 -0
  59. package/dist/components/filters/OptionList.svelte +352 -0
  60. package/dist/components/filters/OptionList.svelte.d.ts +91 -0
  61. package/dist/components/filters/Panel.svelte +123 -0
  62. package/dist/components/filters/Panel.svelte.d.ts +25 -0
  63. package/dist/components/filters/index.d.ts +288 -0
  64. package/dist/components/filters/index.js +12 -0
  65. package/dist/components/icons.d.ts +54 -0
  66. package/dist/components/icons.js +58 -0
  67. package/dist/components/inputs/ButtonGroup.svelte +110 -0
  68. package/dist/components/inputs/ButtonGroup.svelte.d.ts +40 -0
  69. package/dist/components/inputs/Calendar.svelte +535 -0
  70. package/dist/components/inputs/Calendar.svelte.d.ts +45 -0
  71. package/dist/components/inputs/DateField.svelte +247 -0
  72. package/dist/components/inputs/DateField.svelte.d.ts +74 -0
  73. package/dist/components/inputs/DateInput.svelte +118 -0
  74. package/dist/components/inputs/DateInput.svelte.d.ts +43 -0
  75. package/dist/components/inputs/DatePicker.svelte +102 -0
  76. package/dist/components/inputs/DatePicker.svelte.d.ts +67 -0
  77. package/dist/components/inputs/DateRangePicker.svelte +208 -0
  78. package/dist/components/inputs/DateRangePicker.svelte.d.ts +76 -0
  79. package/dist/components/inputs/DateRangeSelect.svelte +548 -0
  80. package/dist/components/inputs/DateRangeSelect.svelte.d.ts +70 -0
  81. package/dist/components/inputs/FieldLabel.svelte +43 -0
  82. package/dist/components/inputs/FieldLabel.svelte.d.ts +28 -0
  83. package/dist/components/inputs/ListSearch.svelte +142 -0
  84. package/dist/components/inputs/ListSearch.svelte.d.ts +35 -0
  85. package/dist/components/inputs/RadioGroup.svelte +151 -0
  86. package/dist/components/inputs/RadioGroup.svelte.d.ts +49 -0
  87. package/dist/components/inputs/RangeShortcuts.svelte +90 -0
  88. package/dist/components/inputs/RangeShortcuts.svelte.d.ts +31 -0
  89. package/dist/components/inputs/RangeSlider.svelte +225 -0
  90. package/dist/components/inputs/RangeSlider.svelte.d.ts +37 -0
  91. package/dist/components/inputs/SearchField.svelte +24 -0
  92. package/dist/components/inputs/SearchField.svelte.d.ts +41 -0
  93. package/dist/components/inputs/Segmented.svelte +79 -0
  94. package/dist/components/inputs/Segmented.svelte.d.ts +43 -0
  95. package/dist/components/inputs/Select.svelte +552 -0
  96. package/dist/components/inputs/Select.svelte.d.ts +100 -0
  97. package/dist/components/inputs/Slider.svelte +177 -0
  98. package/dist/components/inputs/Slider.svelte.d.ts +33 -0
  99. package/dist/components/inputs/SliderTicks.svelte +62 -0
  100. package/dist/components/inputs/SliderTicks.svelte.d.ts +23 -0
  101. package/dist/components/inputs/Switch.svelte +120 -0
  102. package/dist/components/inputs/Switch.svelte.d.ts +31 -0
  103. package/dist/components/inputs/TagInput.svelte +296 -0
  104. package/dist/components/inputs/TagInput.svelte.d.ts +61 -0
  105. package/dist/components/inputs/TextArea.svelte +86 -0
  106. package/dist/components/inputs/TextArea.svelte.d.ts +56 -0
  107. package/dist/components/inputs/TextField.svelte +170 -0
  108. package/dist/components/inputs/TextField.svelte.d.ts +80 -0
  109. package/dist/components/menu/ContextMenu.svelte +25 -0
  110. package/dist/components/menu/ContextMenu.svelte.d.ts +26 -0
  111. package/dist/components/menu/MenuButton.svelte +46 -0
  112. package/dist/components/menu/MenuButton.svelte.d.ts +16 -0
  113. package/dist/components/menu/MenuList.svelte +319 -0
  114. package/dist/components/menu/MenuList.svelte.d.ts +30 -0
  115. package/dist/components/metadata/Metadata.svelte +38 -0
  116. package/dist/components/metadata/Metadata.svelte.d.ts +31 -0
  117. package/dist/components/metadata/MetadataRow.svelte +84 -0
  118. package/dist/components/metadata/MetadataRow.svelte.d.ts +26 -0
  119. package/dist/components/metadata/index.d.ts +8 -0
  120. package/dist/components/metadata/index.js +13 -0
  121. package/dist/components/side-menu/SideMenu.svelte +138 -0
  122. package/dist/components/side-menu/SideMenu.svelte.d.ts +25 -0
  123. package/dist/components/side-menu/SideMenuGroup.svelte +108 -0
  124. package/dist/components/side-menu/SideMenuGroup.svelte.d.ts +31 -0
  125. package/dist/components/side-menu/SideMenuItem.svelte +221 -0
  126. package/dist/components/side-menu/SideMenuItem.svelte.d.ts +46 -0
  127. package/dist/components/side-menu/context.d.ts +1 -0
  128. package/dist/components/side-menu/context.js +3 -0
  129. package/dist/components/side-menu/index.d.ts +62 -0
  130. package/dist/components/side-menu/index.js +15 -0
  131. package/dist/components/tiles/Tile.svelte +419 -0
  132. package/dist/components/tiles/Tile.svelte.d.ts +58 -0
  133. package/dist/components/tiles/TileGroup.svelte +135 -0
  134. package/dist/components/tiles/TileGroup.svelte.d.ts +45 -0
  135. package/dist/components/tiles/context.d.ts +35 -0
  136. package/dist/components/tiles/context.js +14 -0
  137. package/dist/components/tiles/index.d.ts +6 -0
  138. package/dist/components/tiles/index.js +13 -0
  139. package/dist/components/upload/FileCard.svelte +301 -0
  140. package/dist/components/upload/FileCard.svelte.d.ts +127 -0
  141. package/dist/components/upload/Thumb.svelte +274 -0
  142. package/dist/components/upload/Thumb.svelte.d.ts +101 -0
  143. package/dist/components/upload/UploadFile.svelte +123 -0
  144. package/dist/components/upload/UploadFile.svelte.d.ts +48 -0
  145. package/dist/components/upload/UploadFiles.svelte +177 -0
  146. package/dist/components/upload/UploadFiles.svelte.d.ts +50 -0
  147. package/dist/components/upload/UploadFolder.svelte +153 -0
  148. package/dist/components/upload/UploadFolder.svelte.d.ts +63 -0
  149. package/dist/components/upload/UploadImage.svelte +137 -0
  150. package/dist/components/upload/UploadImage.svelte.d.ts +52 -0
  151. package/dist/components/upload/UploadImages.svelte +172 -0
  152. package/dist/components/upload/UploadImages.svelte.d.ts +52 -0
  153. package/dist/components/upload/UploadZone.svelte +130 -0
  154. package/dist/components/upload/UploadZone.svelte.d.ts +41 -0
  155. package/dist/components/upload/common.d.ts +31 -0
  156. package/dist/components/upload/common.js +103 -0
  157. package/dist/components/upload/context.d.ts +18 -0
  158. package/dist/components/upload/context.js +10 -0
  159. package/dist/components/upload/index.d.ts +16 -0
  160. package/dist/components/upload/index.js +18 -0
  161. package/dist/css/atoms.css +899 -0
  162. package/dist/css/base.css +334 -0
  163. package/dist/css/effects.css +430 -0
  164. package/dist/css/index.css +10 -0
  165. package/dist/css/tokens.css +296 -0
  166. package/dist/fonts.d.ts +1 -0
  167. package/dist/fonts.js +7 -0
  168. package/dist/index.d.ts +68 -0
  169. package/dist/index.js +77 -0
  170. package/dist/lib/announce.d.ts +8 -0
  171. package/dist/lib/announce.js +48 -0
  172. package/dist/lib/controls.d.ts +10 -0
  173. package/dist/lib/controls.js +42 -0
  174. package/dist/lib/dates.d.ts +104 -0
  175. package/dist/lib/dates.js +235 -0
  176. package/dist/lib/dialogs.svelte.d.ts +8 -0
  177. package/dist/lib/dialogs.svelte.js +45 -0
  178. package/dist/lib/dom.d.ts +34 -0
  179. package/dist/lib/dom.js +90 -0
  180. package/dist/lib/field-errors.svelte.d.ts +40 -0
  181. package/dist/lib/field-errors.svelte.js +89 -0
  182. package/dist/lib/files.d.ts +74 -0
  183. package/dist/lib/files.js +215 -0
  184. package/dist/lib/inline-md.d.ts +1 -0
  185. package/dist/lib/inline-md.js +36 -0
  186. package/dist/lib/invalid.d.ts +4 -0
  187. package/dist/lib/invalid.js +35 -0
  188. package/dist/lib/list-search.d.ts +9 -0
  189. package/dist/lib/list-search.js +27 -0
  190. package/dist/lib/menu.svelte.d.ts +39 -0
  191. package/dist/lib/menu.svelte.js +98 -0
  192. package/dist/lib/morph.svelte.d.ts +17 -0
  193. package/dist/lib/morph.svelte.js +46 -0
  194. package/dist/lib/motion.d.ts +115 -0
  195. package/dist/lib/motion.js +174 -0
  196. package/dist/lib/observe.d.ts +36 -0
  197. package/dist/lib/observe.js +142 -0
  198. package/dist/lib/reveal.d.ts +7 -0
  199. package/dist/lib/reveal.js +28 -0
  200. package/dist/lib/roving.d.ts +16 -0
  201. package/dist/lib/roving.js +35 -0
  202. package/dist/lib/runs.d.ts +18 -0
  203. package/dist/lib/runs.js +25 -0
  204. package/dist/lib/scroll-fade.d.ts +4 -0
  205. package/dist/lib/scroll-fade.js +71 -0
  206. package/dist/lib/spotlight.d.ts +4 -0
  207. package/dist/lib/spotlight.js +109 -0
  208. package/dist/lib/ticks.d.ts +12 -0
  209. package/dist/lib/ticks.js +24 -0
  210. package/dist/lib/tooltip.d.ts +4 -0
  211. package/dist/lib/tooltip.js +110 -0
  212. package/dist/lib/validity.d.ts +16 -0
  213. package/dist/lib/validity.js +36 -0
  214. package/package.json +69 -3
@@ -0,0 +1,401 @@
1
+ <script>
2
+ /**
3
+ * A row of filters drawn from data (Linear's view filters): one FilterChip per filter, then a funnel button that adds
4
+ * one. The button lists the fields (with a search field when there are many); picking one shows its value editor in
5
+ * the same panel, and the filter joins the row as soon as it has a value. A field already filtered opens its chip
6
+ * instead, so each field has one filter. A filter left with no value (every value unticked, every word removed) leaves
7
+ * `filters` at once, so nothing filters by it; its chip stays on the row until its panel closes, and picking a value
8
+ * again puts it back in its place.
9
+ *
10
+ * <FilterBar bind:filters fields={[
11
+ * { key: 'status', label: 'Status', icon: 'circleDashed', options: [{ value: 'open', label: 'Open', icon: 'checkCircle', tone: 'success', hint: '12 items' }, …], plural: 'statuses' },
12
+ * { key: 'created', label: 'Created', icon: 'calendar', kind: 'date' },
13
+ * { key: 'words', label: 'Keywords', icon: 'search', kind: 'text' },
14
+ * ]} />
15
+ *
16
+ * fields: [{ key, label, icon?, kind?, options?, operators?, plural?, presets?, search? }]. kind:
17
+ * 'options' (the default): ticks values of `options` (OptionList's shape: { value, label, icon?, tone?, hint? });
18
+ * the filter's value is an array. The chip shows one value with its icon, or several as their icons and
19
+ * "3 {plural}" (default "values"). Conditions default to ['is', 'is not']. `search` as OptionList's.
20
+ * 'date': a day from `presets` ([{ value, label }], default datePresets() in lib/dates.js: 1 day ago … 3 months ago)
21
+ * or a calendar; the value is a relative id ('-3d') or an ISO day, relativeDay(value) turns either into a day.
22
+ * Conditions default to ['after', 'before'].
23
+ * 'text': words typed into a TagInput (Enter or a comma adds one); the value is an array of strings, applied as each
24
+ * word is added. The chip shows them as small label chips (three, then "+2"). Conditions default to
25
+ * ['contains', 'does not contain'].
26
+ * 'custom': the `panel` snippet edits the value and `summary` draws it on the chip. Conditions default to ['is'].
27
+ * Without a `panel` snippet a custom field can't be edited, so the add button leaves it out.
28
+ * operators: the conditions to choose from, the first being where a new filter starts.
29
+ * filters (bindable): [{ field, op, value }], field a key of `fields`. The app applies them; this only edits them.
30
+ * onchange(filters): after every edit. label: the row's accessible name ("Filters"). addLabel: the button's ("Add filter").
31
+ * panel: snippet ({ filter, field, set, close }) for a custom field's editor: set(value) stores a value, close() closes.
32
+ * summary: snippet ({ filter, field }) drawing a custom field's value on its chip (default: the value as text).
33
+ * Keyboard: the chips' parts and the add button are in the tab order. In the add panel, Backspace on a field's values
34
+ * goes back to the field list, unless it deletes something there (typed text, a word). Removing a filter moves the focus
35
+ * to the next one, else the button.
36
+ * Other attributes (class…) and attachments go to the row.
37
+ */
38
+ import { tick } from 'svelte'
39
+ import Icon from '../Icon.svelte'
40
+ import FilterChip from './FilterChip.svelte'
41
+ import OptionList from './OptionList.svelte'
42
+ import DateFilter from './DateFilter.svelte'
43
+ import TagInput from '../inputs/TagInput.svelte'
44
+ import Panel from './Panel.svelte'
45
+ import { tooltip } from '../../lib/tooltip.js'
46
+ import { composing } from '../../lib/dom.js'
47
+ import { datePresets, formatDay, relativeDay } from '../../lib/dates.js'
48
+
49
+ /**
50
+ * @typedef {{ value: any, label: string, icon?: string, tone?: string, hint?: string }} Option
51
+ * @typedef {{ key: string, label: string, icon?: string, kind?: 'options' | 'date' | 'text' | 'custom', options?: Option[], operators?: string[], plural?: string, presets?: { value: string, label: string }[], search?: 'auto' | boolean }} Field
52
+ * @typedef {{ field: string, op: string, value: any }} Filter
53
+ * @typedef {object} Props
54
+ * @property {Field[]} fields
55
+ * @property {Filter[]} [filters] bindable
56
+ * @property {(filters: Filter[]) => void} [onchange]
57
+ * @property {string} [label]
58
+ * @property {string} [addLabel]
59
+ * @property {import('svelte').Snippet<[{ filter: Filter, field: Field, set: (value: any) => void, close: () => void }]>} [panel]
60
+ * @property {import('svelte').Snippet<[{ filter: Filter, field: Field }]>} [summary]
61
+ */
62
+ /** @type {Props & Omit<import('svelte/elements').HTMLAttributes<HTMLDivElement>, keyof Props>} */
63
+ let {
64
+ fields,
65
+ filters = $bindable([]),
66
+ onchange,
67
+ label = 'Filters',
68
+ addLabel = 'Add filter',
69
+ panel,
70
+ summary,
71
+ class: className,
72
+ ...rest
73
+ } = $props()
74
+
75
+ const uid = $props.id()
76
+ const anchor = `--filter-add-${uid}`
77
+ /** @type {HTMLButtonElement | undefined} */
78
+ let addButton = $state()
79
+ /** @type {Record<string, { focus: () => void }>} */
80
+ const chips = $state({})
81
+ /** The field whose chip has its panel open. */
82
+ let openKey = $state(/** @type {string | null} */ (null))
83
+ /** The add panel: closed, listing the fields, or showing one field's values. */
84
+ let adding = $state(/** @type {null | { key: string | null }} */ (null))
85
+ /** A filter emptied while its panel is open: out of `filters`, but its chip stays on the row (at `at`) until it closes. */
86
+ let held = $state(/** @type {null | { at: number, filter: Filter }} */ (null))
87
+ /** The chips on the row: the filters, with the held one back in its place. */
88
+ const rows = $derived.by(() => {
89
+ if (!held || filters.some((x) => x.field === held?.filter.field)) return filters
90
+ const at = Math.min(held.at, filters.length)
91
+ return [...filters.slice(0, at), held.filter, ...filters.slice(at)]
92
+ })
93
+
94
+ const byKey = $derived(new Map(fields.map((f) => [f.key, f])))
95
+ /** @param {Field} f */
96
+ const kindOf = (f) => f.kind ?? 'options'
97
+ /** Whether a field has something to edit it with: a custom one needs the `panel` snippet. @param {Field} f */
98
+ const editable = (f) => kindOf(f) !== 'custom' || !!panel
99
+ const fieldOptions = $derived(fields.filter(editable).map((f) => ({ value: f.key, label: f.label, icon: f.icon })))
100
+ /** @param {Field} f */
101
+ const operatorsOf = (f) =>
102
+ f.operators ?? { options: ['is', 'is not'], date: ['after', 'before'], text: ['contains', 'does not contain'], custom: ['is'] }[kindOf(f)]
103
+ /** @param {any} v */
104
+ const isEmpty = (v) => v == null || v === '' || (Array.isArray(v) && !v.length)
105
+ /** @param {string} key */
106
+ const find = (key) => rows.find((x) => x.field === key)
107
+ /** @param {string} key */
108
+ const isHeld = (key) => held?.filter.field === key
109
+
110
+ /** @param {Filter[]} next */
111
+ function commitAll(next) {
112
+ filters = next
113
+ onchange?.(next)
114
+ }
115
+ /** @param {string} key @param {Partial<Filter>} patch */
116
+ function update(key, patch) {
117
+ if (held && isHeld(key)) {
118
+ const filter = { ...held.filter, ...patch }
119
+ if (isEmpty(filter.value)) held = { ...held, filter }
120
+ else {
121
+ const at = Math.min(held.at, filters.length)
122
+ held = null
123
+ commitAll([...filters.slice(0, at), filter, ...filters.slice(at)])
124
+ }
125
+ return
126
+ }
127
+ const at = filters.findIndex((x) => x.field === key)
128
+ if (at < 0) return
129
+ const filter = { ...filters[at], ...patch }
130
+ if (isEmpty(filter.value)) {
131
+ // Nothing to filter by: out of `filters` now, its chip held on the row until its panel closes.
132
+ held = { at, filter }
133
+ commitAll(filters.filter((_, i) => i !== at))
134
+ } else commitAll(filters.map((x, i) => (i === at ? filter : x)))
135
+ }
136
+ /** Stores a value for a field: on its filter, or as a new one once there is something to filter by. @param {string} key @param {any} value */
137
+ function put(key, value) {
138
+ const field = byKey.get(key)
139
+ if (!field) return
140
+ if (find(key)) update(key, { value })
141
+ else if (!isEmpty(value)) commitAll([...filters, { field: key, op: operatorsOf(field)[0], value }])
142
+ }
143
+ /** Drops a field's chip if it has nothing left to filter by. @param {string} key */
144
+ function prune(key) {
145
+ if (isHeld(key)) held = null
146
+ const f = filters.find((x) => x.field === key)
147
+ if (f && isEmpty(f.value)) commitAll(filters.filter((x) => x !== f))
148
+ }
149
+ /** @param {string} key */
150
+ async function remove(key) {
151
+ const at = rows.findIndex((x) => x.field === key)
152
+ if (at < 0) return
153
+ if (openKey === key) openKey = null
154
+ if (isHeld(key)) held = null
155
+ commitAll(filters.filter((x) => x.field !== key))
156
+ await tick()
157
+ const next = rows[at] ?? rows[at - 1]
158
+ if (next) chips[next.field]?.focus()
159
+ else addButton?.focus()
160
+ }
161
+
162
+ /** @param {string} key */
163
+ function pickField(key) {
164
+ if (find(key)) {
165
+ adding = null
166
+ openKey = key
167
+ } else adding = { key }
168
+ }
169
+ /** @param {boolean} refocus */
170
+ function closeAdding(refocus) {
171
+ const key = adding?.key
172
+ adding = null
173
+ if (key) prune(key)
174
+ if (refocus) addButton?.focus()
175
+ }
176
+
177
+ /** Attachment on the add panel's value step: it replaces the field list, which held the focus, so the focus moves into
178
+ * it (OptionList takes it itself; a text or custom editor doesn't). */
179
+ const focusIn = (/** @type {HTMLElement} */ node) => {
180
+ tick().then(() => {
181
+ if (node.contains(document.activeElement)) return
182
+ ;/** @type {HTMLElement | null} */ (node.querySelector('input, textarea, button:not(:disabled), [tabindex]:not([tabindex="-1"])'))?.focus()
183
+ })
184
+ }
185
+
186
+ /** Attachment on the add panel's value step: Backspace goes back to the field list, whichever editor has the focus,
187
+ * unless the editor used it (a TagInput removing a word) or it deletes text where it was pressed.
188
+ * @param {() => void} back */
189
+ const NOT_TYPED = new Set(['checkbox', 'radio', 'button', 'submit', 'reset', 'range', 'color', 'file', 'image'])
190
+ const backOnBackspace = (back) => (/** @type {HTMLElement} */ node) => {
191
+ /** @param {KeyboardEvent} e */
192
+ const onkeydown = (e) => {
193
+ if (e.key !== 'Backspace' || e.defaultPrevented || composing(e) || e.ctrlKey || e.metaKey || e.altKey) return
194
+ const t = /** @type {HTMLElement} */ (e.target)
195
+ if (t.isContentEditable && t.textContent) return
196
+ // Text a Backspace would delete (a checkbox's or a button-like input's value isn't).
197
+ if (t instanceof HTMLTextAreaElement && t.value && !t.readOnly) return
198
+ if (t instanceof HTMLInputElement && t.value && !t.readOnly && !NOT_TYPED.has(t.type)) return
199
+ e.preventDefault()
200
+ back()
201
+ }
202
+ node.addEventListener('keydown', onkeydown)
203
+ return () => node.removeEventListener('keydown', onkeydown)
204
+ }
205
+
206
+ /** @param {Filter} filter @param {Field} field */
207
+ const presetOf = (filter, field) => (field.presets ?? datePresets()).find((p) => p.value === filter.value)
208
+ /** @param {Filter} filter @param {Field} field */
209
+ const isPreset = (filter, field) => !!presetOf(filter, field)
210
+ /** @param {Filter} filter @param {Field} field */
211
+ function describe(filter, field) {
212
+ if (kindOf(field) === 'date') {
213
+ const day = relativeDay(filter.value)
214
+ return presetOf(filter, field)?.label ?? (day ? formatDay(day) : String(filter.value ?? ''))
215
+ }
216
+ return String(filter.value ?? '')
217
+ }
218
+ </script>
219
+
220
+ {#snippet editor(/** @type {Field} */ field, /** @type {Filter} */ current, /** @type {() => void} */ close)}
221
+ {#if kindOf(field) === 'options'}
222
+ <OptionList
223
+ value={current.value ?? []}
224
+ options={field.options ?? []}
225
+ label={field.label}
226
+ search={field.search ?? 'auto'}
227
+ onchange={(v) => put(field.key, v)}
228
+ />
229
+ {:else if kindOf(field) === 'date'}
230
+ <DateFilter
231
+ value={current.value}
232
+ presets={field.presets ?? datePresets()}
233
+ label={field.label}
234
+ onpick={(v) => {
235
+ put(field.key, v)
236
+ close()
237
+ }}
238
+ />
239
+ {:else if kindOf(field) === 'text'}
240
+ <div class="words">
241
+ <TagInput
242
+ bind:value={() => (Array.isArray(current.value) ? current.value : []), (words) => put(field.key, words)}
243
+ id="{uid}-{field.key}-words"
244
+ label={field.label}
245
+ hideLabel
246
+ placeholder="Type a word, then Enter"
247
+ />
248
+ </div>
249
+ {:else if panel}
250
+ {@render panel({ filter: current, field, set: (v) => put(field.key, v), close })}
251
+ {/if}
252
+ {/snippet}
253
+
254
+ {#snippet shown(/** @type {Filter} */ filter, /** @type {Field} */ field)}
255
+ {#if kindOf(field) === 'options'}
256
+ {@const on = (field.options ?? []).filter((o) => Array.isArray(filter.value) && filter.value.includes(o.value))}
257
+ {#if on.length === 1}
258
+ {#if on[0].icon}<span class="tone" data-tone={on[0].tone}><Icon name={on[0].icon} size="sm" /></span>{/if}
259
+ <span class="text">{on[0].label}</span>
260
+ {:else}
261
+ <span class="icons">
262
+ {#each on.slice(0, 3) as o (o.value)}
263
+ {#if o.icon}<span class="tone" data-tone={o.tone}><Icon name={o.icon} size="sm" /></span>{/if}
264
+ {/each}
265
+ </span>
266
+ <span class="text"><span class="num">{on.length}</span> {field.plural ?? 'values'}</span>
267
+ {/if}
268
+ {:else if kindOf(field) === 'text'}
269
+ {@const words = Array.isArray(filter.value) ? filter.value : [filter.value]}
270
+ <span class="words-shown">
271
+ {#each words.slice(0, 3) as word (word)}<span class="label-chip word">{word}</span>{/each}
272
+ {#if words.length > 3}<span class="more">+{words.length - 3}</span>{/if}
273
+ </span>
274
+ {:else if kindOf(field) === 'custom' && summary}
275
+ {@render summary({ filter, field })}
276
+ {:else}
277
+ <span class="text" class:num={kindOf(field) === 'date' && !isPreset(filter, field)}>{describe(filter, field)}</span>
278
+ {/if}
279
+ {/snippet}
280
+
281
+ <div class={['filter-bar', className]} role="group" aria-label={label} {...rest}>
282
+ {#each rows as filter (filter.field)}
283
+ {@const field = byKey.get(filter.field)}
284
+ {#if field}
285
+ {#snippet editPanel(/** @type {{ close: () => void }} */ { close })}{@render editor(field, filter, close)}{/snippet}
286
+ <FilterChip
287
+ bind:this={chips[filter.field]}
288
+ field={{ label: field.label, icon: field.icon }}
289
+ operator={filter.op}
290
+ operators={operatorsOf(field)}
291
+ onoperator={(op) => update(field.key, { op })}
292
+ onremove={() => remove(field.key)}
293
+ bind:open={() => openKey === field.key, (v) => (openKey = v ? field.key : openKey === field.key ? null : openKey)}
294
+ onclose={() => prune(field.key)}
295
+ panel={editable(field) ? editPanel : undefined}
296
+ >
297
+ {#snippet value()}<span class="summary">{@render shown(filter, field)}</span>{/snippet}
298
+ </FilterChip>
299
+ {/if}
300
+ {/each}
301
+ <button
302
+ bind:this={addButton}
303
+ type="button"
304
+ class="icon-btn add"
305
+ style:anchor-name={anchor}
306
+ aria-label={addLabel}
307
+ aria-haspopup="dialog"
308
+ aria-expanded={!!adding}
309
+ {@attach tooltip(addLabel)}
310
+ onclick={() => (adding ? closeAdding(true) : (adding = { key: null }))}
311
+ >
312
+ <Icon name="funnel" />
313
+ </button>
314
+ </div>
315
+
316
+ {#if adding && addButton}
317
+ {@const field = adding.key ? byKey.get(adding.key) : null}
318
+ <Panel anchor={addButton} name={anchor} label={field ? field.label : addLabel} onclose={closeAdding}>
319
+ {#if field}
320
+ {#key field.key}
321
+ <div
322
+ class="step"
323
+ {@attach focusIn}
324
+ {@attach backOnBackspace(() => {
325
+ prune(field.key)
326
+ adding = { key: null }
327
+ })}
328
+ >
329
+ {@render editor(field, find(field.key) ?? { field: field.key, op: operatorsOf(field)[0], value: null }, () => closeAdding(true))}
330
+ </div>
331
+ {/key}
332
+ {:else}
333
+ <OptionList options={fieldOptions} multiple={false} label={addLabel} placeholder="Filter by…" onpick={pickField} />
334
+ {/if}
335
+ </Panel>
336
+ {/if}
337
+
338
+ <style>
339
+ /* Chrome, not content: a press or drag across the row doesn't select its words. */
340
+ .filter-bar {
341
+ user-select: none;
342
+ display: flex;
343
+ flex-wrap: wrap;
344
+ align-items: center;
345
+ gap: var(--space-2);
346
+ min-width: 0;
347
+ }
348
+ .step {
349
+ display: flex;
350
+ flex-direction: column;
351
+ min-height: 0;
352
+ }
353
+ .words {
354
+ width: 280px;
355
+ max-width: 100%;
356
+ padding: var(--space-2);
357
+ }
358
+ .summary {
359
+ display: inline-flex;
360
+ align-items: center;
361
+ gap: 6px;
362
+ min-width: 0;
363
+ }
364
+ .text {
365
+ min-width: 0;
366
+ overflow: clip;
367
+ text-overflow: ellipsis;
368
+ }
369
+ .num {
370
+ font-family: var(--font-data);
371
+ font-variant-numeric: tabular-nums;
372
+ }
373
+ .words-shown {
374
+ display: inline-flex;
375
+ align-items: center;
376
+ gap: var(--space-1);
377
+ min-width: 0;
378
+ }
379
+ /* The .label-chip atom, a size down to sit inside the chip's 26px row. */
380
+ .word {
381
+ min-height: 18px;
382
+ padding: 0 6px;
383
+ color: var(--fg-2);
384
+ }
385
+ .more {
386
+ color: var(--muted);
387
+ font-family: var(--font-data);
388
+ font-variant-numeric: tabular-nums;
389
+ }
390
+ .icons {
391
+ display: inline-flex;
392
+ gap: 2px;
393
+ }
394
+ .tone {
395
+ display: inline-flex;
396
+ color: var(--muted);
397
+ }
398
+ .tone[data-tone] {
399
+ color: var(--tone);
400
+ }
401
+ </style>
@@ -0,0 +1,283 @@
1
+ export default FilterBar;
2
+ type FilterBar = {
3
+ $on?(type: string, callback: (e: any) => void): () => void;
4
+ $set?(props: Partial<Props & Omit<HTMLAttributes<HTMLDivElement>, keyof Props>>): void;
5
+ };
6
+ declare const FilterBar: import("svelte").Component<{
7
+ fields: {
8
+ key: string;
9
+ label: string;
10
+ icon?: string;
11
+ kind?: "options" | "date" | "text" | "custom";
12
+ options?: {
13
+ value: any;
14
+ label: string;
15
+ icon?: string;
16
+ tone?: string;
17
+ hint?: string;
18
+ }[];
19
+ operators?: string[];
20
+ plural?: string;
21
+ presets?: {
22
+ value: string;
23
+ label: string;
24
+ }[];
25
+ search?: "auto" | boolean;
26
+ }[];
27
+ /**
28
+ * bindable
29
+ */
30
+ filters?: {
31
+ field: string;
32
+ op: string;
33
+ value: any;
34
+ }[] | undefined;
35
+ onchange?: ((filters: {
36
+ field: string;
37
+ op: string;
38
+ value: any;
39
+ }[]) => void) | undefined;
40
+ label?: string | undefined;
41
+ addLabel?: string | undefined;
42
+ panel?: import("svelte").Snippet<[{
43
+ filter: {
44
+ field: string;
45
+ op: string;
46
+ value: any;
47
+ };
48
+ field: {
49
+ key: string;
50
+ label: string;
51
+ icon?: string;
52
+ kind?: "options" | "date" | "text" | "custom";
53
+ options?: {
54
+ value: any;
55
+ label: string;
56
+ icon?: string;
57
+ tone?: string;
58
+ hint?: string;
59
+ }[];
60
+ operators?: string[];
61
+ plural?: string;
62
+ presets?: {
63
+ value: string;
64
+ label: string;
65
+ }[];
66
+ search?: "auto" | boolean;
67
+ };
68
+ set: (value: any) => void;
69
+ close: () => void;
70
+ }]> | undefined;
71
+ summary?: import("svelte").Snippet<[{
72
+ filter: {
73
+ field: string;
74
+ op: string;
75
+ value: any;
76
+ };
77
+ field: {
78
+ key: string;
79
+ label: string;
80
+ icon?: string;
81
+ kind?: "options" | "date" | "text" | "custom";
82
+ options?: {
83
+ value: any;
84
+ label: string;
85
+ icon?: string;
86
+ tone?: string;
87
+ hint?: string;
88
+ }[];
89
+ operators?: string[];
90
+ plural?: string;
91
+ presets?: {
92
+ value: string;
93
+ label: string;
94
+ }[];
95
+ search?: "auto" | boolean;
96
+ };
97
+ }]> | undefined;
98
+ } & Omit<import("svelte/elements").HTMLAttributes<HTMLDivElement>, keyof {
99
+ fields: {
100
+ key: string;
101
+ label: string;
102
+ icon?: string;
103
+ kind?: "options" | "date" | "text" | "custom";
104
+ options?: {
105
+ value: any;
106
+ label: string;
107
+ icon?: string;
108
+ tone?: string;
109
+ hint?: string;
110
+ }[];
111
+ operators?: string[];
112
+ plural?: string;
113
+ presets?: {
114
+ value: string;
115
+ label: string;
116
+ }[];
117
+ search?: "auto" | boolean;
118
+ }[];
119
+ /**
120
+ * bindable
121
+ */
122
+ filters?: {
123
+ field: string;
124
+ op: string;
125
+ value: any;
126
+ }[] | undefined;
127
+ onchange?: ((filters: {
128
+ field: string;
129
+ op: string;
130
+ value: any;
131
+ }[]) => void) | undefined;
132
+ label?: string | undefined;
133
+ addLabel?: string | undefined;
134
+ panel?: import("svelte").Snippet<[{
135
+ filter: {
136
+ field: string;
137
+ op: string;
138
+ value: any;
139
+ };
140
+ field: {
141
+ key: string;
142
+ label: string;
143
+ icon?: string;
144
+ kind?: "options" | "date" | "text" | "custom";
145
+ options?: {
146
+ value: any;
147
+ label: string;
148
+ icon?: string;
149
+ tone?: string;
150
+ hint?: string;
151
+ }[];
152
+ operators?: string[];
153
+ plural?: string;
154
+ presets?: {
155
+ value: string;
156
+ label: string;
157
+ }[];
158
+ search?: "auto" | boolean;
159
+ };
160
+ set: (value: any) => void;
161
+ close: () => void;
162
+ }]> | undefined;
163
+ summary?: import("svelte").Snippet<[{
164
+ filter: {
165
+ field: string;
166
+ op: string;
167
+ value: any;
168
+ };
169
+ field: {
170
+ key: string;
171
+ label: string;
172
+ icon?: string;
173
+ kind?: "options" | "date" | "text" | "custom";
174
+ options?: {
175
+ value: any;
176
+ label: string;
177
+ icon?: string;
178
+ tone?: string;
179
+ hint?: string;
180
+ }[];
181
+ operators?: string[];
182
+ plural?: string;
183
+ presets?: {
184
+ value: string;
185
+ label: string;
186
+ }[];
187
+ search?: "auto" | boolean;
188
+ };
189
+ }]> | undefined;
190
+ }>, {}, "filters">;
191
+ type Props = {
192
+ fields: {
193
+ key: string;
194
+ label: string;
195
+ icon?: string;
196
+ kind?: "options" | "date" | "text" | "custom";
197
+ options?: {
198
+ value: any;
199
+ label: string;
200
+ icon?: string;
201
+ tone?: string;
202
+ hint?: string;
203
+ }[];
204
+ operators?: string[];
205
+ plural?: string;
206
+ presets?: {
207
+ value: string;
208
+ label: string;
209
+ }[];
210
+ search?: "auto" | boolean;
211
+ }[];
212
+ /**
213
+ * bindable
214
+ */
215
+ filters?: {
216
+ field: string;
217
+ op: string;
218
+ value: any;
219
+ }[] | undefined;
220
+ onchange?: ((filters: {
221
+ field: string;
222
+ op: string;
223
+ value: any;
224
+ }[]) => void) | undefined;
225
+ label?: string | undefined;
226
+ addLabel?: string | undefined;
227
+ panel?: import("svelte").Snippet<[{
228
+ filter: {
229
+ field: string;
230
+ op: string;
231
+ value: any;
232
+ };
233
+ field: {
234
+ key: string;
235
+ label: string;
236
+ icon?: string;
237
+ kind?: "options" | "date" | "text" | "custom";
238
+ options?: {
239
+ value: any;
240
+ label: string;
241
+ icon?: string;
242
+ tone?: string;
243
+ hint?: string;
244
+ }[];
245
+ operators?: string[];
246
+ plural?: string;
247
+ presets?: {
248
+ value: string;
249
+ label: string;
250
+ }[];
251
+ search?: "auto" | boolean;
252
+ };
253
+ set: (value: any) => void;
254
+ close: () => void;
255
+ }]> | undefined;
256
+ summary?: import("svelte").Snippet<[{
257
+ filter: {
258
+ field: string;
259
+ op: string;
260
+ value: any;
261
+ };
262
+ field: {
263
+ key: string;
264
+ label: string;
265
+ icon?: string;
266
+ kind?: "options" | "date" | "text" | "custom";
267
+ options?: {
268
+ value: any;
269
+ label: string;
270
+ icon?: string;
271
+ tone?: string;
272
+ hint?: string;
273
+ }[];
274
+ operators?: string[];
275
+ plural?: string;
276
+ presets?: {
277
+ value: string;
278
+ label: string;
279
+ }[];
280
+ search?: "auto" | boolean;
281
+ };
282
+ }]> | undefined;
283
+ };