@xerios/design-system 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 (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 +178 -0
  8. package/dist/components/Button.svelte.d.ts +58 -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 +342 -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 +104 -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 +153 -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 +76 -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 +892 -0
  162. package/dist/css/base.css +333 -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,342 @@
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. Unticking every value of a filter removes it as its panel closes.
7
+ *
8
+ * <FilterBar bind:filters fields={[
9
+ * { key: 'status', label: 'Status', icon: 'circleDashed', options: [{ value: 'open', label: 'Open', icon: 'checkCircle', tone: 'success', hint: '12 items' }, …], plural: 'statuses' },
10
+ * { key: 'created', label: 'Created', icon: 'calendar', kind: 'date' },
11
+ * { key: 'words', label: 'Keywords', icon: 'search', kind: 'text' },
12
+ * ]} />
13
+ *
14
+ * fields: [{ key, label, icon?, kind?, options?, operators?, plural?, presets?, search? }]. kind:
15
+ * 'options' (the default): ticks values of `options` (OptionList's shape: { value, label, icon?, tone?, hint? });
16
+ * the filter's value is an array. The chip shows one value with its icon, or several as their icons and
17
+ * "3 {plural}" (default "values"). Conditions default to ['is', 'is not']. `search` as OptionList's.
18
+ * 'date': a day from `presets` ([{ value, label }], default datePresets() in lib/dates.js: 1 day ago … 3 months ago)
19
+ * or a calendar; the value is a relative id ('-3d') or an ISO day, relativeDay(value) turns either into a day.
20
+ * Conditions default to ['after', 'before'].
21
+ * 'text': words typed into a TagInput (Enter or a comma adds one); the value is an array of strings, applied as each
22
+ * word is added. The chip shows them as small label chips (three, then "+2"). Conditions default to
23
+ * ['contains', 'does not contain'].
24
+ * 'custom': the `panel` snippet edits the value and `summary` draws it on the chip. Conditions default to ['is'].
25
+ * Without a `panel` snippet a custom field can't be edited, so the add button leaves it out.
26
+ * operators: the conditions to choose from, the first being where a new filter starts.
27
+ * filters (bindable): [{ field, op, value }], field a key of `fields`. The app applies them; this only edits them.
28
+ * onchange(filters): after every edit. label: the row's accessible name ("Filters"). addLabel: the button's ("Add filter").
29
+ * panel: snippet ({ filter, field, set, close }) for a custom field's editor: set(value) stores a value, close() closes.
30
+ * summary: snippet ({ filter, field }) drawing a custom field's value on its chip (default: the value as text).
31
+ * Keyboard: the chips' parts and the add button are in the tab order. In the add panel, Backspace in an empty search
32
+ * goes from a field's values back to the field list. Removing a filter moves the focus to the next one, else the button.
33
+ * Other attributes (class…) and attachments go to the row.
34
+ */
35
+ import { tick } from 'svelte'
36
+ import Icon from '../Icon.svelte'
37
+ import FilterChip from './FilterChip.svelte'
38
+ import OptionList from './OptionList.svelte'
39
+ import DateFilter from './DateFilter.svelte'
40
+ import TagInput from '../inputs/TagInput.svelte'
41
+ import Panel from './Panel.svelte'
42
+ import { tooltip } from '../../lib/tooltip.js'
43
+ import { datePresets, formatDay, relativeDay } from '../../lib/dates.js'
44
+
45
+ /**
46
+ * @typedef {{ value: any, label: string, icon?: string, tone?: string, hint?: string }} Option
47
+ * @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
48
+ * @typedef {{ field: string, op: string, value: any }} Filter
49
+ * @typedef {object} Props
50
+ * @property {Field[]} fields
51
+ * @property {Filter[]} [filters] bindable
52
+ * @property {(filters: Filter[]) => void} [onchange]
53
+ * @property {string} [label]
54
+ * @property {string} [addLabel]
55
+ * @property {import('svelte').Snippet<[{ filter: Filter, field: Field, set: (value: any) => void, close: () => void }]>} [panel]
56
+ * @property {import('svelte').Snippet<[{ filter: Filter, field: Field }]>} [summary]
57
+ */
58
+ /** @type {Props & Omit<import('svelte/elements').HTMLAttributes<HTMLDivElement>, keyof Props>} */
59
+ let {
60
+ fields,
61
+ filters = $bindable([]),
62
+ onchange,
63
+ label = 'Filters',
64
+ addLabel = 'Add filter',
65
+ panel,
66
+ summary,
67
+ class: className,
68
+ ...rest
69
+ } = $props()
70
+
71
+ const uid = $props.id()
72
+ const anchor = `--filter-add-${uid}`
73
+ /** @type {HTMLButtonElement | undefined} */
74
+ let addButton = $state()
75
+ /** @type {Record<string, { focus: () => void }>} */
76
+ const chips = $state({})
77
+ /** The field whose chip has its panel open. */
78
+ let openKey = $state(/** @type {string | null} */ (null))
79
+ /** The add panel: closed, listing the fields, or showing one field's values. */
80
+ let adding = $state(/** @type {null | { key: string | null }} */ (null))
81
+
82
+ const byKey = $derived(new Map(fields.map((f) => [f.key, f])))
83
+ /** @param {Field} f */
84
+ const kindOf = (f) => f.kind ?? 'options'
85
+ /** Whether a field has something to edit it with: a custom one needs the `panel` snippet. @param {Field} f */
86
+ const editable = (f) => kindOf(f) !== 'custom' || !!panel
87
+ const fieldOptions = $derived(fields.filter(editable).map((f) => ({ value: f.key, label: f.label, icon: f.icon })))
88
+ /** @param {Field} f */
89
+ const operatorsOf = (f) =>
90
+ f.operators ?? { options: ['is', 'is not'], date: ['after', 'before'], text: ['contains', 'does not contain'], custom: ['is'] }[kindOf(f)]
91
+ /** @param {any} v */
92
+ const isEmpty = (v) => v == null || v === '' || (Array.isArray(v) && !v.length)
93
+ /** @param {string} key */
94
+ const find = (key) => filters.find((x) => x.field === key)
95
+
96
+ /** @param {Filter[]} next */
97
+ function commitAll(next) {
98
+ filters = next
99
+ onchange?.(next)
100
+ }
101
+ /** @param {string} key @param {Partial<Filter>} patch */
102
+ function update(key, patch) {
103
+ commitAll(filters.map((x) => (x.field === key ? { ...x, ...patch } : x)))
104
+ }
105
+ /** 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 */
106
+ function put(key, value) {
107
+ const field = byKey.get(key)
108
+ if (!field) return
109
+ if (find(key)) update(key, { value })
110
+ else if (!isEmpty(value)) commitAll([...filters, { field: key, op: operatorsOf(field)[0], value }])
111
+ }
112
+ /** Drops a field's filter if it has nothing left to filter by. @param {string} key */
113
+ function prune(key) {
114
+ const f = find(key)
115
+ if (f && isEmpty(f.value)) commitAll(filters.filter((x) => x !== f))
116
+ }
117
+ /** @param {string} key */
118
+ async function remove(key) {
119
+ const at = filters.findIndex((x) => x.field === key)
120
+ if (at < 0) return
121
+ if (openKey === key) openKey = null
122
+ commitAll(filters.filter((x) => x.field !== key))
123
+ await tick()
124
+ const next = filters[at] ?? filters[at - 1]
125
+ if (next) chips[next.field]?.focus()
126
+ else addButton?.focus()
127
+ }
128
+
129
+ /** @param {string} key */
130
+ function pickField(key) {
131
+ if (find(key)) {
132
+ adding = null
133
+ openKey = key
134
+ } else adding = { key }
135
+ }
136
+ /** @param {boolean} refocus */
137
+ function closeAdding(refocus) {
138
+ const key = adding?.key
139
+ adding = null
140
+ if (key) prune(key)
141
+ if (refocus) addButton?.focus()
142
+ }
143
+
144
+ /** Attachment on the add panel's value step: it replaces the field list, which held the focus, so the focus moves into
145
+ * it (OptionList takes it itself; a text or custom editor doesn't). */
146
+ const focusIn = (/** @type {HTMLElement} */ node) => {
147
+ tick().then(() => {
148
+ if (node.contains(document.activeElement)) return
149
+ ;/** @type {HTMLElement | null} */ (node.querySelector('input, textarea, button:not(:disabled), [tabindex]:not([tabindex="-1"])'))?.focus()
150
+ })
151
+ }
152
+
153
+ /** @param {Filter} filter @param {Field} field */
154
+ const presetOf = (filter, field) => (field.presets ?? datePresets()).find((p) => p.value === filter.value)
155
+ /** @param {Filter} filter @param {Field} field */
156
+ const isPreset = (filter, field) => !!presetOf(filter, field)
157
+ /** @param {Filter} filter @param {Field} field */
158
+ function describe(filter, field) {
159
+ if (kindOf(field) === 'date') {
160
+ const day = relativeDay(filter.value)
161
+ return presetOf(filter, field)?.label ?? (day ? formatDay(day) : String(filter.value ?? ''))
162
+ }
163
+ return String(filter.value ?? '')
164
+ }
165
+ </script>
166
+
167
+ {#snippet editor(/** @type {Field} */ field, /** @type {Filter} */ current, /** @type {() => void} */ close, /** @type {(() => void) | undefined} */ back)}
168
+ {#if kindOf(field) === 'options'}
169
+ <OptionList
170
+ value={current.value ?? []}
171
+ options={field.options ?? []}
172
+ label={field.label}
173
+ search={field.search ?? 'auto'}
174
+ onchange={(v) => put(field.key, v)}
175
+ onback={back}
176
+ />
177
+ {:else if kindOf(field) === 'date'}
178
+ <DateFilter
179
+ value={current.value}
180
+ presets={field.presets ?? datePresets()}
181
+ label={field.label}
182
+ onpick={(v) => {
183
+ put(field.key, v)
184
+ close()
185
+ }}
186
+ />
187
+ {:else if kindOf(field) === 'text'}
188
+ <div class="words">
189
+ <TagInput
190
+ bind:value={() => (Array.isArray(current.value) ? current.value : []), (words) => put(field.key, words)}
191
+ id="{uid}-{field.key}-words"
192
+ label={field.label}
193
+ hideLabel
194
+ placeholder="Type a word, then Enter"
195
+ />
196
+ </div>
197
+ {:else if panel}
198
+ {@render panel({ filter: current, field, set: (v) => put(field.key, v), close })}
199
+ {/if}
200
+ {/snippet}
201
+
202
+ {#snippet shown(/** @type {Filter} */ filter, /** @type {Field} */ field)}
203
+ {#if kindOf(field) === 'options'}
204
+ {@const on = (field.options ?? []).filter((o) => Array.isArray(filter.value) && filter.value.includes(o.value))}
205
+ {#if on.length === 1}
206
+ {#if on[0].icon}<span class="tone" data-tone={on[0].tone}><Icon name={on[0].icon} size="sm" /></span>{/if}
207
+ <span class="text">{on[0].label}</span>
208
+ {:else}
209
+ <span class="icons">
210
+ {#each on.slice(0, 3) as o (o.value)}
211
+ {#if o.icon}<span class="tone" data-tone={o.tone}><Icon name={o.icon} size="sm" /></span>{/if}
212
+ {/each}
213
+ </span>
214
+ <span class="text"><span class="num">{on.length}</span> {field.plural ?? 'values'}</span>
215
+ {/if}
216
+ {:else if kindOf(field) === 'text'}
217
+ {@const words = Array.isArray(filter.value) ? filter.value : [filter.value]}
218
+ <span class="words-shown">
219
+ {#each words.slice(0, 3) as word (word)}<span class="label-chip word">{word}</span>{/each}
220
+ {#if words.length > 3}<span class="more">+{words.length - 3}</span>{/if}
221
+ </span>
222
+ {:else if kindOf(field) === 'custom' && summary}
223
+ {@render summary({ filter, field })}
224
+ {:else}
225
+ <span class="text" class:num={kindOf(field) === 'date' && !isPreset(filter, field)}>{describe(filter, field)}</span>
226
+ {/if}
227
+ {/snippet}
228
+
229
+ <div class={['filter-bar', className]} role="group" aria-label={label} {...rest}>
230
+ {#each filters as filter (filter.field)}
231
+ {@const field = byKey.get(filter.field)}
232
+ {#if field}
233
+ {#snippet editPanel(/** @type {{ close: () => void }} */ { close })}{@render editor(field, filter, close, undefined)}{/snippet}
234
+ <FilterChip
235
+ bind:this={chips[filter.field]}
236
+ field={{ label: field.label, icon: field.icon }}
237
+ operator={filter.op}
238
+ operators={operatorsOf(field)}
239
+ onoperator={(op) => update(field.key, { op })}
240
+ onremove={() => remove(field.key)}
241
+ bind:open={() => openKey === field.key, (v) => (openKey = v ? field.key : openKey === field.key ? null : openKey)}
242
+ onclose={() => prune(field.key)}
243
+ panel={editable(field) ? editPanel : undefined}
244
+ >
245
+ {#snippet value()}<span class="summary">{@render shown(filter, field)}</span>{/snippet}
246
+ </FilterChip>
247
+ {/if}
248
+ {/each}
249
+ <button
250
+ bind:this={addButton}
251
+ type="button"
252
+ class="icon-btn add"
253
+ style:anchor-name={anchor}
254
+ aria-label={addLabel}
255
+ aria-haspopup="dialog"
256
+ aria-expanded={!!adding}
257
+ {@attach tooltip(addLabel)}
258
+ onclick={() => (adding ? closeAdding(true) : (adding = { key: null }))}
259
+ >
260
+ <Icon name="funnel" />
261
+ </button>
262
+ </div>
263
+
264
+ {#if adding && addButton}
265
+ {@const field = adding.key ? byKey.get(adding.key) : null}
266
+ <Panel anchor={addButton} name={anchor} label={field ? field.label : addLabel} onclose={closeAdding}>
267
+ {#if field}
268
+ {#key field.key}
269
+ <div class="step" {@attach focusIn}>
270
+ {@render editor(field, find(field.key) ?? { field: field.key, op: operatorsOf(field)[0], value: null }, () => closeAdding(true), () => (adding = { key: null }))}
271
+ </div>
272
+ {/key}
273
+ {:else}
274
+ <OptionList options={fieldOptions} multiple={false} label={addLabel} placeholder="Filter by…" onpick={pickField} />
275
+ {/if}
276
+ </Panel>
277
+ {/if}
278
+
279
+ <style>
280
+ /* Chrome, not content: a press or drag across the row doesn't select its words. */
281
+ .filter-bar {
282
+ user-select: none;
283
+ display: flex;
284
+ flex-wrap: wrap;
285
+ align-items: center;
286
+ gap: var(--space-2);
287
+ min-width: 0;
288
+ }
289
+ .step {
290
+ display: flex;
291
+ flex-direction: column;
292
+ min-height: 0;
293
+ }
294
+ .words {
295
+ width: 280px;
296
+ max-width: 100%;
297
+ padding: var(--space-2);
298
+ }
299
+ .summary {
300
+ display: inline-flex;
301
+ align-items: center;
302
+ gap: 6px;
303
+ min-width: 0;
304
+ }
305
+ .text {
306
+ min-width: 0;
307
+ overflow: clip;
308
+ text-overflow: ellipsis;
309
+ }
310
+ .num {
311
+ font-family: var(--font-data);
312
+ font-variant-numeric: tabular-nums;
313
+ }
314
+ .words-shown {
315
+ display: inline-flex;
316
+ align-items: center;
317
+ gap: var(--space-1);
318
+ min-width: 0;
319
+ }
320
+ /* The .label-chip atom, a size down to sit inside the chip's 26px row. */
321
+ .word {
322
+ min-height: 18px;
323
+ padding: 0 6px;
324
+ color: var(--fg-2);
325
+ }
326
+ .more {
327
+ color: var(--muted);
328
+ font-family: var(--font-data);
329
+ font-variant-numeric: tabular-nums;
330
+ }
331
+ .icons {
332
+ display: inline-flex;
333
+ gap: 2px;
334
+ }
335
+ .tone {
336
+ display: inline-flex;
337
+ color: var(--muted);
338
+ }
339
+ .tone[data-tone] {
340
+ color: var(--tone);
341
+ }
342
+ </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
+ };