@rock555/frontend-core 2.0.2 → 2.0.3

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 (58) hide show
  1. package/README.md +95 -95
  2. package/package.json +98 -98
  3. package/src/components/GlobalPendingBar.vue +85 -85
  4. package/src/components/SearchPicker.vue +84 -84
  5. package/src/components/filters/DateRangeField.vue +692 -692
  6. package/src/components/filters/ExportCsvButton.vue +60 -60
  7. package/src/components/filters/FiltersBar.vue +150 -150
  8. package/src/components/filters/MonthField.vue +309 -309
  9. package/src/components/filters/SortControl.vue +162 -162
  10. package/src/components/filters/SortControlPanel.vue +242 -242
  11. package/src/components/filters/sortControl.types.ts +25 -25
  12. package/src/components/modals/ConfirmModal.vue +58 -58
  13. package/src/components/modals/ImageViewerModal.vue +200 -200
  14. package/src/components/tables/MultiSortHeader.vue +126 -126
  15. package/src/components/tables/TableBodyRow.vue +62 -62
  16. package/src/components/tables/TableFooterRow.vue +54 -54
  17. package/src/components/tables/TableHeaderRow.vue +75 -75
  18. package/src/components/tables/TableLoadedCount.vue +61 -61
  19. package/src/components/tables/TableLoadedFooter.vue +44 -44
  20. package/src/components/tables/TableSkeletonRows.vue +40 -40
  21. package/src/components/tables/TableVirtualPad.vue +16 -16
  22. package/src/components/tables/cells/BoolBadgeCell.vue +32 -32
  23. package/src/components/tables/multiSortHeader.types.ts +16 -16
  24. package/src/components/ui/UiActionTiles.vue +92 -92
  25. package/src/components/ui/UiBackLink.vue +39 -39
  26. package/src/components/ui/UiBadge.vue +60 -60
  27. package/src/components/ui/UiButton.vue +126 -126
  28. package/src/components/ui/UiCard.vue +88 -88
  29. package/src/components/ui/UiCount.vue +35 -35
  30. package/src/components/ui/UiKpiGrid.vue +142 -142
  31. package/src/components/ui/UiPopover.vue +62 -62
  32. package/src/components/ui/UiSearchInput.vue +102 -102
  33. package/src/components/ui/UiSegmented.vue +145 -145
  34. package/src/components/ui/UiTableCard.vue +116 -116
  35. package/src/components/ui/uiActionTiles.types.ts +10 -10
  36. package/src/components/ui/uiBadge.types.ts +11 -11
  37. package/src/components/ui/uiKpi.types.ts +17 -17
  38. package/src/composables/useAppForm.ts +67 -67
  39. package/src/composables/useConfirm.ts +21 -21
  40. package/src/composables/useFilterState.ts +70 -70
  41. package/src/composables/useServerList.ts +348 -348
  42. package/src/composables/useServerTable.ts +117 -117
  43. package/src/composables/useSharedAsync.ts +51 -51
  44. package/src/composables/useVirtualTable.ts +77 -77
  45. package/src/config.ts +155 -155
  46. package/src/errors/actionCancelled.ts +9 -9
  47. package/src/errors/apiError.helper.ts +161 -161
  48. package/src/errors/useHandleError.ts +33 -33
  49. package/src/helpers/calendarRange.helper.ts +74 -74
  50. package/src/helpers/month.helper.ts +63 -63
  51. package/src/helpers/periodLabel.helper.ts +70 -70
  52. package/src/helpers/periodPresets.helper.ts +76 -76
  53. package/src/helpers/sort.helper.ts +57 -57
  54. package/src/helpers/tableFields.helper.ts +205 -205
  55. package/src/helpers/urlParams.helper.ts +99 -99
  56. package/src/helpers/urlSchema.helper.ts +296 -296
  57. package/src/plugins/modals.plugin.ts +253 -253
  58. package/src/plugins/table.plugin.ts +173 -173
@@ -1,173 +1,173 @@
1
- import type {} from '../types/table'
2
- import { type CellContext, type ColumnDef, createColumnHelper, type DisplayColumnDef } from '@tanstack/vue-table'
3
- import { Component, h, type VNode, VNodeChild } from 'vue'
4
- import AmountCell from '../components/tables/cells/AmountCell.vue'
5
- import DateTimeCell from '../components/tables/cells/DateTimeCell.vue'
6
- import MoneyCell from '../components/tables/cells/MoneyCell.vue'
7
- import SimpleCell from '../components/tables/cells/SimpleCell.vue'
8
- import { ExtractComponentPublicProps } from '../types/vue-utils'
9
-
10
- /** Дістає число з рядка — воно ж іде і в клітинку, і в підсумок. */
11
- type Pick<TData> = (row: TData) => number
12
-
13
- // Общий реестр cell-компонентов. Автоматически мерджится в каждый фичевый
14
- // helper через TableHelperFactory.createHelper — фичам остаётся регистрировать
15
- // только специфичные cells.
16
- //
17
- // Доступны во всех фичах:
18
- // • MoneyCell — { value: number|null, emphasis?: 'positive'|'muted' }
19
- // • AmountCell — { value: number|null, suffix?, precision?, emphasis? }
20
- // • DateTimeCell — { value: number|string|null, source?, format? }
21
- // • SimpleCell — { text, subText? }
22
-
23
- /**
24
- * Що фабриці треба знати про колонку, щоб не питати це в кожному `*Row.vue`:
25
- * назва, підказка, чи сортується і з якого напрямку. Джерело — реєстр полів
26
- * фічі (`TableFieldsHelper` у shared); тут лише форма, бо _shared у shared не
27
- * заглядає.
28
- */
29
- export interface ColumnFieldMeta {
30
- header: string
31
- hint?: string
32
- isSortable: boolean
33
- isDescFirst: boolean
34
- }
35
-
36
- export interface ColumnFieldsSource<TId extends string> {
37
- column(id: TId): ColumnFieldMeta
38
- /** Приховані стовпці-носії сортування — фабрика заводить їх сама. */
39
- readonly hiddenIds: readonly TId[]
40
- }
41
-
42
- /** Хвіст налаштувань числової колонки. Назву й сортування бере реєстр полів. */
43
- interface ValueColumnOptions {
44
- emphasis?: 'positive' | 'muted'
45
- /**
46
- * ГОТОВИЙ підсумок колонки — агрегат бека по всій вибірці фільтра.
47
- *
48
- * Не задано — футера немає. Суму видимих рядків не підставляємо: вона стрибає
49
- * від сторінки, а читається як підсумок періоду. Порожню комірку помітно,
50
- * неправильне число — ні.
51
- */
52
- footer?: () => number | null
53
- }
54
-
55
- interface NumColumnOptions extends ValueColumnOptions {
56
- /** «км», «хв», «поїздок» — той самий suffix іде і в підсумок. */
57
- suffix?: string
58
- precision?: number
59
- }
60
-
61
- /** Решта ColumnDef: ячейка, футер, вирівнювання, шапка-компонент замість назви. */
62
- type ColumnOptions<TData> = Omit<DisplayColumnDef<TData, any>, 'id'>
63
-
64
- const CellRegistry = {
65
- // презентационные
66
- MoneyCell,
67
- AmountCell,
68
- DateTimeCell,
69
- SimpleCell,
70
- } as const
71
-
72
- export class TableHelperFactory {
73
- /**
74
- * Каррі: тип рядка задаємо явно (з полів він не виводиться), id колонок TS
75
- * бере з реєстру полів.
76
- */
77
- static createHelper<TData>() {
78
- return <TId extends string, TR extends Record<string, Component>>(
79
- fields: ColumnFieldsSource<TId>,
80
- registry: TR,
81
- ) => {
82
- type Registry = TR & typeof CellRegistry
83
- type CellFn = (ctx: CellContext<TData, any>) => VNodeChild
84
-
85
- interface ColumnContext {
86
- /** Строго типізовані пропси ячейки з реєстру cell-компонентів. */
87
- cell: <K extends keyof Registry>(
88
- key: K,
89
- build: (ctx: CellContext<TData, any>) => ExtractComponentPublicProps<Registry[K]>,
90
- ) => CellFn
91
- /** Сирий h() — для фрагментів, слотів та інших винятків. */
92
- cellRaw: (build: (ctx: CellContext<TData, any>) => VNode | VNodeChild) => CellFn
93
- /** Колонка зі значенням: назва, підказка й сортування — з реєстру полів. */
94
- accessor: (id: TId, pick: (row: TData) => unknown, options?: ColumnOptions<TData>) => ColumnDef<TData, any>
95
- /** Колонка без значення (дії, збірна ячейка): сортувати нічого. */
96
- display: (id: TId, options?: ColumnOptions<TData>) => ColumnDef<TData, any>
97
- /**
98
- * Числова колонка одним рядком: ячейка + вирівнювання праворуч (+ футер,
99
- * якщо передали тотал). Це був найчастіший копіпаст, і футери в копіях
100
- * уже розійшлися.
101
- */
102
- money: (id: TId, pick: Pick<TData>, options?: ValueColumnOptions) => ColumnDef<TData, any>
103
- num: (id: TId, pick: Pick<TData>, options?: NumColumnOptions) => ColumnDef<TData, any>
104
- /**
105
- * Готовий грошовий підсумок для колонки зі СВОЄЮ ячейкою — там, де
106
- * `money()` не підходить (ставка поруч із сумою, тижні абонплати).
107
- */
108
- moneyTotal: (value: number | null, emphasis?: ValueColumnOptions['emphasis']) => VNode
109
- }
110
-
111
- const cells = { ...CellRegistry, ...registry } as Registry
112
- const ch = createColumnHelper<TData>()
113
-
114
- const meta = (id: TId, own: ColumnOptions<TData>['meta']) => ({ hint: fields.column(id).hint, ...own })
115
-
116
- const ctx: ColumnContext = {
117
- cell: (key, build) => cellCtx => h(cells[key], build(cellCtx)),
118
- cellRaw: build => cellCtx => build(cellCtx),
119
-
120
- accessor: (id, pick, options = {}) => {
121
- const field = fields.column(id)
122
-
123
- return ch.accessor(pick, {
124
- id,
125
- header: field.header,
126
- enableSorting: field.isSortable,
127
- sortDescFirst: field.isDescFirst,
128
- ...options,
129
- meta: meta(id, options.meta),
130
- }) as ColumnDef<TData, any>
131
- },
132
-
133
- display: (id, options = {}) => ch.display({
134
- id,
135
- header: fields.column(id).header,
136
- ...options,
137
- meta: meta(id, options.meta),
138
- }) as ColumnDef<TData, any>,
139
-
140
- money: (id, pick, { emphasis, footer } = {}) => ctx.accessor(id, pick, {
141
- cell: c => h(MoneyCell, { value: pick(c.row.original), emphasis }),
142
- // Підсумок теж через MoneyCell — щоб мінусовий тотал червонів так
143
- // само, як мінусова клітинка.
144
- footer: footer && (() => h(MoneyCell, { value: footer(), emphasis })),
145
- meta: { align: 'right' },
146
- }),
147
-
148
- num: (id, pick, { footer, ...cellProps } = {}) => ctx.accessor(id, pick, {
149
- cell: c => h(AmountCell, { value: pick(c.row.original), ...cellProps }),
150
- footer: footer && (() => h(AmountCell, { value: footer(), ...cellProps })),
151
- meta: { align: 'right' },
152
- }),
153
-
154
- moneyTotal: (value, emphasis) => h(MoneyCell, { value, emphasis }),
155
- }
156
-
157
- // Приховані стовпці-носії: значення їм не потрібне (сортує бек), але без
158
- // accessorFn TanStack не вважає стовпець сортованим і не тримає ключ.
159
- const hidden = (): Array<ColumnDef<TData, any>> => fields.hiddenIds.map(id => ch.accessor(() => null, {
160
- id,
161
- header: '',
162
- enableSorting: true,
163
- sortDescFirst: fields.column(id).isDescFirst,
164
- }) as ColumnDef<TData, any>)
165
-
166
- return {
167
- /** Колонки таблиці. `*Row.vue` описує лише видимі — приховані додаються самі. */
168
- columns: (config: (ctx: ColumnContext) => Array<ColumnDef<TData, any>>): Array<ColumnDef<TData, any>> =>
169
- [...config(ctx), ...hidden()],
170
- }
171
- }
172
- }
173
- }
1
+ import type {} from '../types/table'
2
+ import { type CellContext, type ColumnDef, createColumnHelper, type DisplayColumnDef } from '@tanstack/vue-table'
3
+ import { Component, h, type VNode, VNodeChild } from 'vue'
4
+ import AmountCell from '../components/tables/cells/AmountCell.vue'
5
+ import DateTimeCell from '../components/tables/cells/DateTimeCell.vue'
6
+ import MoneyCell from '../components/tables/cells/MoneyCell.vue'
7
+ import SimpleCell from '../components/tables/cells/SimpleCell.vue'
8
+ import { ExtractComponentPublicProps } from '../types/vue-utils'
9
+
10
+ /** Дістає число з рядка — воно ж іде і в клітинку, і в підсумок. */
11
+ type Pick<TData> = (row: TData) => number
12
+
13
+ // Общий реестр cell-компонентов. Автоматически мерджится в каждый фичевый
14
+ // helper через TableHelperFactory.createHelper — фичам остаётся регистрировать
15
+ // только специфичные cells.
16
+ //
17
+ // Доступны во всех фичах:
18
+ // • MoneyCell — { value: number|null, emphasis?: 'positive'|'muted' }
19
+ // • AmountCell — { value: number|null, suffix?, precision?, emphasis? }
20
+ // • DateTimeCell — { value: number|string|null, source?, format? }
21
+ // • SimpleCell — { text, subText? }
22
+
23
+ /**
24
+ * Що фабриці треба знати про колонку, щоб не питати це в кожному `*Row.vue`:
25
+ * назва, підказка, чи сортується і з якого напрямку. Джерело — реєстр полів
26
+ * фічі (`TableFieldsHelper` у shared); тут лише форма, бо _shared у shared не
27
+ * заглядає.
28
+ */
29
+ export interface ColumnFieldMeta {
30
+ header: string
31
+ hint?: string
32
+ isSortable: boolean
33
+ isDescFirst: boolean
34
+ }
35
+
36
+ export interface ColumnFieldsSource<TId extends string> {
37
+ column(id: TId): ColumnFieldMeta
38
+ /** Приховані стовпці-носії сортування — фабрика заводить їх сама. */
39
+ readonly hiddenIds: readonly TId[]
40
+ }
41
+
42
+ /** Хвіст налаштувань числової колонки. Назву й сортування бере реєстр полів. */
43
+ interface ValueColumnOptions {
44
+ emphasis?: 'positive' | 'muted'
45
+ /**
46
+ * ГОТОВИЙ підсумок колонки — агрегат бека по всій вибірці фільтра.
47
+ *
48
+ * Не задано — футера немає. Суму видимих рядків не підставляємо: вона стрибає
49
+ * від сторінки, а читається як підсумок періоду. Порожню комірку помітно,
50
+ * неправильне число — ні.
51
+ */
52
+ footer?: () => number | null
53
+ }
54
+
55
+ interface NumColumnOptions extends ValueColumnOptions {
56
+ /** «км», «хв», «поїздок» — той самий suffix іде і в підсумок. */
57
+ suffix?: string
58
+ precision?: number
59
+ }
60
+
61
+ /** Решта ColumnDef: ячейка, футер, вирівнювання, шапка-компонент замість назви. */
62
+ type ColumnOptions<TData> = Omit<DisplayColumnDef<TData, any>, 'id'>
63
+
64
+ const CellRegistry = {
65
+ // презентационные
66
+ MoneyCell,
67
+ AmountCell,
68
+ DateTimeCell,
69
+ SimpleCell,
70
+ } as const
71
+
72
+ export class TableHelperFactory {
73
+ /**
74
+ * Каррі: тип рядка задаємо явно (з полів він не виводиться), id колонок TS
75
+ * бере з реєстру полів.
76
+ */
77
+ static createHelper<TData>() {
78
+ return <TId extends string, TR extends Record<string, Component>>(
79
+ fields: ColumnFieldsSource<TId>,
80
+ registry: TR,
81
+ ) => {
82
+ type Registry = TR & typeof CellRegistry
83
+ type CellFn = (ctx: CellContext<TData, any>) => VNodeChild
84
+
85
+ interface ColumnContext {
86
+ /** Строго типізовані пропси ячейки з реєстру cell-компонентів. */
87
+ cell: <K extends keyof Registry>(
88
+ key: K,
89
+ build: (ctx: CellContext<TData, any>) => ExtractComponentPublicProps<Registry[K]>,
90
+ ) => CellFn
91
+ /** Сирий h() — для фрагментів, слотів та інших винятків. */
92
+ cellRaw: (build: (ctx: CellContext<TData, any>) => VNode | VNodeChild) => CellFn
93
+ /** Колонка зі значенням: назва, підказка й сортування — з реєстру полів. */
94
+ accessor: (id: TId, pick: (row: TData) => unknown, options?: ColumnOptions<TData>) => ColumnDef<TData, any>
95
+ /** Колонка без значення (дії, збірна ячейка): сортувати нічого. */
96
+ display: (id: TId, options?: ColumnOptions<TData>) => ColumnDef<TData, any>
97
+ /**
98
+ * Числова колонка одним рядком: ячейка + вирівнювання праворуч (+ футер,
99
+ * якщо передали тотал). Це був найчастіший копіпаст, і футери в копіях
100
+ * уже розійшлися.
101
+ */
102
+ money: (id: TId, pick: Pick<TData>, options?: ValueColumnOptions) => ColumnDef<TData, any>
103
+ num: (id: TId, pick: Pick<TData>, options?: NumColumnOptions) => ColumnDef<TData, any>
104
+ /**
105
+ * Готовий грошовий підсумок для колонки зі СВОЄЮ ячейкою — там, де
106
+ * `money()` не підходить (ставка поруч із сумою, тижні абонплати).
107
+ */
108
+ moneyTotal: (value: number | null, emphasis?: ValueColumnOptions['emphasis']) => VNode
109
+ }
110
+
111
+ const cells = { ...CellRegistry, ...registry } as Registry
112
+ const ch = createColumnHelper<TData>()
113
+
114
+ const meta = (id: TId, own: ColumnOptions<TData>['meta']) => ({ hint: fields.column(id).hint, ...own })
115
+
116
+ const ctx: ColumnContext = {
117
+ cell: (key, build) => cellCtx => h(cells[key], build(cellCtx)),
118
+ cellRaw: build => cellCtx => build(cellCtx),
119
+
120
+ accessor: (id, pick, options = {}) => {
121
+ const field = fields.column(id)
122
+
123
+ return ch.accessor(pick, {
124
+ id,
125
+ header: field.header,
126
+ enableSorting: field.isSortable,
127
+ sortDescFirst: field.isDescFirst,
128
+ ...options,
129
+ meta: meta(id, options.meta),
130
+ }) as ColumnDef<TData, any>
131
+ },
132
+
133
+ display: (id, options = {}) => ch.display({
134
+ id,
135
+ header: fields.column(id).header,
136
+ ...options,
137
+ meta: meta(id, options.meta),
138
+ }) as ColumnDef<TData, any>,
139
+
140
+ money: (id, pick, { emphasis, footer } = {}) => ctx.accessor(id, pick, {
141
+ cell: c => h(MoneyCell, { value: pick(c.row.original), emphasis }),
142
+ // Підсумок теж через MoneyCell — щоб мінусовий тотал червонів так
143
+ // само, як мінусова клітинка.
144
+ footer: footer && (() => h(MoneyCell, { value: footer(), emphasis })),
145
+ meta: { align: 'right' },
146
+ }),
147
+
148
+ num: (id, pick, { footer, ...cellProps } = {}) => ctx.accessor(id, pick, {
149
+ cell: c => h(AmountCell, { value: pick(c.row.original), ...cellProps }),
150
+ footer: footer && (() => h(AmountCell, { value: footer(), ...cellProps })),
151
+ meta: { align: 'right' },
152
+ }),
153
+
154
+ moneyTotal: (value, emphasis) => h(MoneyCell, { value, emphasis }),
155
+ }
156
+
157
+ // Приховані стовпці-носії: значення їм не потрібне (сортує бек), але без
158
+ // accessorFn TanStack не вважає стовпець сортованим і не тримає ключ.
159
+ const hidden = (): Array<ColumnDef<TData, any>> => fields.hiddenIds.map(id => ch.accessor(() => null, {
160
+ id,
161
+ header: '',
162
+ enableSorting: true,
163
+ sortDescFirst: fields.column(id).isDescFirst,
164
+ }) as ColumnDef<TData, any>)
165
+
166
+ return {
167
+ /** Колонки таблиці. `*Row.vue` описує лише видимі — приховані додаються самі. */
168
+ columns: (config: (ctx: ColumnContext) => Array<ColumnDef<TData, any>>): Array<ColumnDef<TData, any>> =>
169
+ [...config(ctx), ...hidden()],
170
+ }
171
+ }
172
+ }
173
+ }