@g4rcez/components 0.0.38 → 0.0.40

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 (194) hide show
  1. package/dist/index.css +1 -1
  2. package/dist/index.js +201 -10
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +3609 -3600
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/index.umd.js +40 -40
  7. package/dist/index.umd.js.map +1 -1
  8. package/dist/preset.tailwind.d.ts +10 -0
  9. package/dist/preset.tailwind.d.ts.map +1 -0
  10. package/dist/preset.tailwind.js +53 -0
  11. package/dist/src/components/core/button.d.ts +16 -0
  12. package/dist/src/components/core/button.d.ts.map +1 -0
  13. package/dist/src/components/core/button.js +43 -0
  14. package/dist/src/components/core/polymorph.d.ts +10 -0
  15. package/dist/src/components/core/polymorph.d.ts.map +1 -0
  16. package/dist/src/components/core/polymorph.js +8 -0
  17. package/dist/src/components/core/resizable.d.ts +3 -0
  18. package/dist/src/components/core/resizable.d.ts.map +1 -0
  19. package/dist/src/components/core/resizable.js +50 -0
  20. package/dist/src/components/core/tag.d.ts +19 -0
  21. package/dist/src/components/core/tag.d.ts.map +1 -0
  22. package/dist/src/components/core/tag.js +45 -0
  23. package/dist/src/components/display/alert.d.ts +19 -0
  24. package/dist/src/components/display/alert.d.ts.map +1 -0
  25. package/dist/src/components/display/alert.js +34 -0
  26. package/dist/src/components/display/calendar.d.ts +42 -0
  27. package/dist/src/components/display/calendar.d.ts.map +1 -0
  28. package/dist/src/components/display/calendar.js +215 -0
  29. package/dist/src/components/display/card.d.ts +10 -0
  30. package/dist/src/components/display/card.d.ts.map +1 -0
  31. package/dist/src/components/display/card.js +8 -0
  32. package/dist/src/components/display/list.d.ts +16 -0
  33. package/dist/src/components/display/list.d.ts.map +1 -0
  34. package/dist/src/components/display/list.js +31 -0
  35. package/dist/src/components/display/notifications.d.ts +25 -0
  36. package/dist/src/components/display/notifications.d.ts.map +1 -0
  37. package/dist/src/components/display/notifications.js +70 -0
  38. package/dist/src/components/display/stats.d.ts +10 -0
  39. package/dist/src/components/display/stats.d.ts.map +1 -0
  40. package/dist/src/components/display/stats.js +5 -0
  41. package/dist/src/components/display/step.d.ts +14 -0
  42. package/dist/src/components/display/step.d.ts.map +1 -0
  43. package/dist/src/components/display/step.js +59 -0
  44. package/dist/src/components/display/tabs.d.ts +20 -0
  45. package/dist/src/components/display/tabs.d.ts.map +1 -0
  46. package/dist/src/components/display/tabs.js +67 -0
  47. package/dist/src/components/display/timeline.d.ts +32 -0
  48. package/dist/src/components/display/timeline.d.ts.map +1 -0
  49. package/dist/src/components/display/timeline.js +21 -0
  50. package/dist/src/components/floating/dropdown.d.ts +14 -0
  51. package/dist/src/components/floating/dropdown.d.ts.map +1 -0
  52. package/dist/src/components/floating/dropdown.js +39 -0
  53. package/dist/src/components/floating/expand.d.ts +9 -0
  54. package/dist/src/components/floating/expand.d.ts.map +1 -0
  55. package/dist/src/components/floating/expand.js +25 -0
  56. package/dist/src/components/floating/menu.d.ts +52 -0
  57. package/dist/src/components/floating/menu.d.ts.map +1 -0
  58. package/dist/src/components/floating/menu.js +126 -0
  59. package/dist/src/components/floating/modal.d.ts +19 -0
  60. package/dist/src/components/floating/modal.d.ts.map +1 -0
  61. package/dist/src/components/floating/modal.js +102 -0
  62. package/dist/src/components/floating/toolbar.d.ts +6 -0
  63. package/dist/src/components/floating/toolbar.d.ts.map +1 -0
  64. package/dist/src/components/floating/toolbar.js +4 -0
  65. package/dist/src/components/floating/tooltip.d.ts +12 -0
  66. package/dist/src/components/floating/tooltip.d.ts.map +1 -0
  67. package/dist/src/components/floating/tooltip.js +28 -0
  68. package/dist/src/components/form/autocomplete.d.ts +17 -0
  69. package/dist/src/components/form/autocomplete.d.ts.map +1 -0
  70. package/dist/src/components/form/autocomplete.js +152 -0
  71. package/dist/src/components/form/checkbox.d.ts +11 -0
  72. package/dist/src/components/form/checkbox.d.ts.map +1 -0
  73. package/dist/src/components/form/checkbox.js +8 -0
  74. package/dist/src/components/form/date-picker.d.ts +61 -0
  75. package/dist/src/components/form/date-picker.d.ts.map +1 -0
  76. package/dist/src/components/form/date-picker.js +78 -0
  77. package/dist/src/components/form/file-upload.d.ts +12 -0
  78. package/dist/src/components/form/file-upload.d.ts.map +1 -0
  79. package/dist/src/components/form/file-upload.js +62 -0
  80. package/dist/src/components/form/form.d.ts +4 -0
  81. package/dist/src/components/form/form.d.ts.map +1 -0
  82. package/dist/src/components/form/form.js +28 -0
  83. package/dist/src/components/form/input-field.d.ts +30 -0
  84. package/dist/src/components/form/input-field.d.ts.map +1 -0
  85. package/dist/src/components/form/input-field.js +14 -0
  86. package/dist/src/components/form/input.d.ts +9 -0
  87. package/dist/src/components/form/input.d.ts.map +1 -0
  88. package/dist/src/components/form/input.js +38 -0
  89. package/dist/src/components/form/radiobox.d.ts +7 -0
  90. package/dist/src/components/form/radiobox.d.ts.map +1 -0
  91. package/dist/src/components/form/radiobox.js +7 -0
  92. package/dist/src/components/form/select.d.ts +13 -0
  93. package/dist/src/components/form/select.d.ts.map +1 -0
  94. package/dist/src/components/form/select.js +33 -0
  95. package/dist/src/components/form/switch.d.ts +8 -0
  96. package/dist/src/components/form/switch.d.ts.map +1 -0
  97. package/dist/src/components/form/switch.js +39 -0
  98. package/dist/src/components/form/task-list.d.ts +3 -0
  99. package/dist/src/components/form/task-list.d.ts.map +1 -0
  100. package/dist/src/components/form/task-list.js +26 -0
  101. package/dist/src/components/form/transfer-list.d.ts +14 -0
  102. package/dist/src/components/form/transfer-list.d.ts.map +1 -0
  103. package/dist/src/components/form/transfer-list.js +21 -0
  104. package/dist/src/components/index.d.ts +30 -0
  105. package/dist/src/components/index.d.ts.map +1 -0
  106. package/dist/src/components/index.js +29 -0
  107. package/dist/src/components/table/filter.d.ts +41 -0
  108. package/dist/src/components/table/filter.d.ts.map +1 -0
  109. package/dist/src/components/table/filter.js +91 -0
  110. package/dist/src/components/table/group.d.ts +17 -0
  111. package/dist/src/components/table/group.d.ts.map +1 -0
  112. package/dist/src/components/table/group.js +43 -0
  113. package/dist/src/components/table/index.d.ts +38 -0
  114. package/dist/src/components/table/index.d.ts.map +1 -0
  115. package/dist/src/components/table/index.js +146 -0
  116. package/dist/src/components/table/metadata.d.ts +3 -0
  117. package/dist/src/components/table/metadata.d.ts.map +1 -0
  118. package/dist/src/components/table/metadata.js +10 -0
  119. package/dist/src/components/table/pagination.d.ts +3 -0
  120. package/dist/src/components/table/pagination.d.ts.map +1 -0
  121. package/dist/src/components/table/pagination.js +43 -0
  122. package/dist/src/components/table/sort.d.ts +28 -0
  123. package/dist/src/components/table/sort.d.ts.map +1 -0
  124. package/dist/src/components/table/sort.js +79 -0
  125. package/dist/src/components/table/table-lib.d.ts +122 -0
  126. package/dist/src/components/table/table-lib.d.ts.map +1 -0
  127. package/dist/src/components/table/table-lib.js +51 -0
  128. package/dist/src/components/table/thead.d.ts +8 -0
  129. package/dist/src/components/table/thead.d.ts.map +1 -0
  130. package/dist/src/components/table/thead.js +29 -0
  131. package/dist/src/constants.d.ts +3 -0
  132. package/dist/src/constants.d.ts.map +1 -0
  133. package/dist/src/constants.js +2 -0
  134. package/dist/src/hooks/use-callback-ref.d.ts +3 -0
  135. package/dist/src/hooks/use-callback-ref.d.ts.map +1 -0
  136. package/dist/src/hooks/use-callback-ref.js +8 -0
  137. package/dist/src/hooks/use-click-outside.d.ts +3 -0
  138. package/dist/src/hooks/use-click-outside.d.ts.map +1 -0
  139. package/dist/src/hooks/use-click-outside.js +17 -0
  140. package/dist/src/hooks/use-debounce.d.ts +4 -0
  141. package/dist/src/hooks/use-debounce.d.ts.map +1 -0
  142. package/dist/src/hooks/use-debounce.js +12 -0
  143. package/dist/src/hooks/use-form.d.ts +41 -0
  144. package/dist/src/hooks/use-form.d.ts.map +1 -0
  145. package/dist/src/hooks/use-form.js +169 -0
  146. package/dist/src/hooks/use-hover.d.ts +3 -0
  147. package/dist/src/hooks/use-hover.d.ts.map +1 -0
  148. package/dist/src/hooks/use-hover.js +18 -0
  149. package/dist/src/hooks/use-media-query.d.ts +2 -0
  150. package/dist/src/hooks/use-media-query.d.ts.map +1 -0
  151. package/dist/src/hooks/use-media-query.js +25 -0
  152. package/dist/src/hooks/use-mutable-state.d.ts +2 -0
  153. package/dist/src/hooks/use-mutable-state.d.ts.map +1 -0
  154. package/dist/src/hooks/use-mutable-state.js +8 -0
  155. package/dist/src/hooks/use-on-event.d.ts +4 -0
  156. package/dist/src/hooks/use-on-event.d.ts.map +1 -0
  157. package/dist/src/hooks/use-on-event.js +7 -0
  158. package/dist/src/hooks/use-parent.d.ts +3 -0
  159. package/dist/src/hooks/use-parent.d.ts.map +1 -0
  160. package/dist/src/hooks/use-parent.js +21 -0
  161. package/dist/src/hooks/use-previous.d.ts +2 -0
  162. package/dist/src/hooks/use-previous.d.ts.map +1 -0
  163. package/dist/src/hooks/use-previous.js +8 -0
  164. package/dist/src/hooks/use-reactive.d.ts +2 -0
  165. package/dist/src/hooks/use-reactive.d.ts.map +1 -0
  166. package/dist/src/hooks/use-reactive.js +8 -0
  167. package/dist/src/hooks/use-stable-ref.d.ts +2 -0
  168. package/dist/src/hooks/use-stable-ref.d.ts.map +1 -0
  169. package/dist/src/hooks/use-stable-ref.js +8 -0
  170. package/dist/src/hooks/use-translate-context.d.ts +103 -0
  171. package/dist/src/hooks/use-translate-context.d.ts.map +1 -0
  172. package/dist/src/hooks/use-translate-context.js +63 -0
  173. package/dist/src/index.d.ts +12 -0
  174. package/dist/src/index.d.ts.map +1 -0
  175. package/dist/src/index.js +10 -0
  176. package/dist/src/lib/dom.d.ts +9 -0
  177. package/dist/src/lib/dom.d.ts.map +1 -0
  178. package/dist/src/lib/dom.js +34 -0
  179. package/dist/src/lib/fns.d.ts +7 -0
  180. package/dist/src/lib/fns.d.ts.map +1 -0
  181. package/dist/src/lib/fns.js +26 -0
  182. package/dist/src/styles/design-tokens.d.ts +19 -0
  183. package/dist/src/styles/design-tokens.d.ts.map +1 -0
  184. package/dist/src/styles/design-tokens.js +52 -0
  185. package/dist/src/styles/theme.d.ts +4 -0
  186. package/dist/src/styles/theme.d.ts.map +1 -0
  187. package/dist/src/styles/theme.js +294 -0
  188. package/dist/src/styles/theme.types.d.ts +101 -0
  189. package/dist/src/styles/theme.types.d.ts.map +1 -0
  190. package/dist/src/styles/theme.types.js +1 -0
  191. package/dist/src/types.d.ts +10 -0
  192. package/dist/src/types.d.ts.map +1 -0
  193. package/dist/src/types.js +1 -0
  194. package/package.json +1 -1
@@ -0,0 +1,41 @@
1
+ import React from "react";
2
+ import { AllPaths } from "sidekicker";
3
+ import { Label } from "../../types";
4
+ import { OptionProps } from "../form/select";
5
+ import { Col, ColType, TableConfiguration } from "./table-lib";
6
+ type Operators = {
7
+ value: string;
8
+ label: string;
9
+ symbol: string;
10
+ };
11
+ type OperatorTypes = "contains" | "is" | "isNot" | "notContains" | "lessThan" | "greaterThan" | "startsWith" | "endsWith";
12
+ type Operations = Record<OperatorTypes, Operators>;
13
+ type OperationOptions = Partial<Record<ColType, OptionProps[]>>;
14
+ type FilterValue = string | number | string[] | boolean;
15
+ export type FilterConfig<T extends {} = {}> = {
16
+ id: string;
17
+ label: Label;
18
+ name: AllPaths<T>;
19
+ type: ColType;
20
+ operation: Operators;
21
+ value: FilterValue;
22
+ };
23
+ type Props<T extends {}> = TableConfiguration<T, {
24
+ cols: Col<T>[];
25
+ filters: FilterConfig<T>[];
26
+ set: React.Dispatch<React.SetStateAction<FilterConfig<T>[]>>;
27
+ }>;
28
+ export declare const createFilterFromCol: <T extends {}>(f: Col<T>, options: OperationOptions, operations: Operations, rest?: Partial<FilterConfig<T>>) => FilterConfig<T>;
29
+ export declare const useOperators: () => {
30
+ operationOptions: Partial<Record<ColType, OptionProps[]>>;
31
+ operations: Operations;
32
+ };
33
+ export declare const Filter: <T extends {}>(props: Props<T>) => import("react/jsx-runtime").JSX.Element;
34
+ type ColumnHeaderFilterProps<T extends {}> = {
35
+ filter: FilterConfig<T>;
36
+ onDelete: (e: React.MouseEvent<HTMLButtonElement>) => void;
37
+ set: React.Dispatch<React.SetStateAction<FilterConfig<T>[]>>;
38
+ };
39
+ export declare const ColumnHeaderFilter: <T extends {}>({ filter, onDelete, set }: ColumnHeaderFilterProps<T>) => import("react/jsx-runtime").JSX.Element;
40
+ export {};
41
+ //# sourceMappingURL=filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../../../src/components/table/filter.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4B,MAAM,OAAO,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC,OAAO,EAAE,WAAW,EAAU,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,GAAG,EAAE,OAAO,EAAY,kBAAkB,EAAiB,MAAM,aAAa,CAAC;AAGxF,KAAK,SAAS,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAA;AAEjE,KAAK,aAAa,GAAG,UAAU,GAAG,IAAI,GAAG,OAAO,GAAG,aAAa,GAAG,UAAU,GAAG,aAAa,GAAG,YAAY,GAAG,UAAU,CAAA;AAEzH,KAAK,UAAU,GAAG,MAAM,CAAC,aAAa,EAAE,SAAS,CAAC,CAAA;AAElD,KAAK,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC,CAAA;AAE/D,KAAK,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC;AAExD,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI;IAC1C,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,SAAS,CAAC;IACrB,KAAK,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF,KAAK,KAAK,CAAC,CAAC,SAAS,EAAE,IAAI,kBAAkB,CACzC,CAAC,EACD;IACI,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACf,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3B,GAAG,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CAChE,CACJ,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,WAAW,gBAAgB,cAAc,UAAU,SAAQ,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,KAAQ,YAAY,CAAC,CAAC,CAMnK,CAAC;AAEF,eAAO,MAAM,YAAY;;;CAwBxB,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,EAAE,SAAS,KAAK,CAAC,CAAC,CAAC,4CAiGnD,CAAC;AAEF,KAAK,uBAAuB,CAAC,CAAC,SAAS,EAAE,IAAI;IACzC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IACxB,QAAQ,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC;IAC3D,GAAG,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CAChE,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,CAAC,SAAS,EAAE,6BAA6B,uBAAuB,CAAC,CAAC,CAAC,4CAsCrG,CAAC"}
@@ -0,0 +1,91 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ListFilterIcon, PlusIcon, Trash2Icon } from "lucide-react";
3
+ import { Fragment, useMemo } from "react";
4
+ import { uuid } from "../../lib/fns";
5
+ import { Dropdown } from "../floating/dropdown";
6
+ import { Input } from "../form/input";
7
+ import { Select } from "../form/select";
8
+ import { ColType, getLabel, valueFromType } from "./table-lib";
9
+ import { useTranslations } from "../../hooks/use-translate-context";
10
+ export const createFilterFromCol = (f, options, operations, rest = {}) => {
11
+ var _a, _b;
12
+ const name = f.id;
13
+ const type = (_a = f.type) !== null && _a !== void 0 ? _a : ColType.Text;
14
+ const operatorId = (_b = options[type]) === null || _b === void 0 ? void 0 : _b[0].value;
15
+ const operation = operations[operatorId];
16
+ return Object.assign({ id: uuid(), operation, label: getLabel(f), name, type, value: "" }, rest);
17
+ };
18
+ export const useOperators = () => {
19
+ const translation = useTranslations();
20
+ const operations = useMemo(() => {
21
+ return {
22
+ contains: { value: "contains", label: translation.tableFilterTypeContains, symbol: "includes" },
23
+ is: { value: "is", label: translation.tableFilterTypeIs, symbol: "is" },
24
+ isNot: { value: "isNot", label: translation.tableFilterTypeIsNot, symbol: "!==" },
25
+ notContains: { value: "notContains", label: translation.tableFilterTypeNotContains, symbol: "notIncludes" },
26
+ lessThan: { value: "lessThan", label: translation.tableFilterTypeLessThan, symbol: "<=" },
27
+ greaterThan: { value: "greaterThan", label: translation.tableFilterTypeGreaterThan, symbol: ">=" },
28
+ startsWith: { value: "startsWith", label: translation.tableFilterTypeStartsWith, symbol: "startsWith" },
29
+ endsWith: { value: "endsWith", label: translation.tableFilterTypeEndsWith, symbol: "endsWith" },
30
+ };
31
+ }, [translation]);
32
+ const operationOptions = useMemo(() => {
33
+ return {
34
+ [ColType.Text]: [operations.is, operations.isNot, operations.contains, operations.notContains, operations.startsWith, operations.endsWith],
35
+ [ColType.Boolean]: [operations.is, operations.isNot],
36
+ [ColType.Number]: [operations.is, operations.isNot, operations.greaterThan, operations.lessThan],
37
+ };
38
+ }, [translation]);
39
+ return { operationOptions, operations };
40
+ };
41
+ export const Filter = (props) => {
42
+ const translation = useTranslations();
43
+ const { operationOptions, operations } = useOperators();
44
+ const onAddFilter = () => {
45
+ const col = props.cols.at(0);
46
+ props.set((prev) => [...prev, createFilterFromCol(col, operationOptions, operations)]);
47
+ };
48
+ const onSelectProperty = (e) => {
49
+ const changedId = e.target.dataset.id || "";
50
+ const newId = e.target.value;
51
+ props.set((prev) => prev.map((x) => {
52
+ if (changedId !== x.id)
53
+ return x;
54
+ const col = props.cols.find((x) => newId === x.id);
55
+ return createFilterFromCol(col, operationOptions, operations, { value: "" });
56
+ }));
57
+ };
58
+ const onSelectOperation = (e) => {
59
+ const id = e.target.dataset.id || "";
60
+ const operator = e.target.value;
61
+ props.set((prev) => prev.map((x) => (x.id === id ? Object.assign(Object.assign({}, x), { operation: operations[operator] }) : x)));
62
+ };
63
+ const onDelete = (e) => {
64
+ const id = e.currentTarget.dataset.id || "";
65
+ props.set((prev) => prev.filter((x) => x.id !== id));
66
+ };
67
+ const onChangeValue = (e) => {
68
+ const id = e.target.dataset.id || "";
69
+ const value = valueFromType(e.target);
70
+ props.set((prev) => prev.map((x) => (x.id === id ? Object.assign(Object.assign({}, x), { value }) : x)));
71
+ };
72
+ return (_jsx(Fragment, { children: _jsx(Dropdown, { arrow: true, title: translation.tableFilterDropdownTitle, trigger: _jsxs("span", { className: "flex items-center gap-1 proportional-nums", children: [_jsx(ListFilterIcon, { size: 14 }), translation.tableFilterLabel, " ", props.filters.length === 0 ? "" : ` (${props.filters.length})`] }), children: _jsxs("ul", { className: "mt-4 space-y-2", children: [props.filters.map((filter) => {
73
+ const operators = operationOptions[filter.type];
74
+ return (_jsxs("li", { className: "flex flex-nowrap gap-3", children: [_jsx(Select, { options: props.options, title: translation.tableFilterColumnTitle, placeholder: translation.tableFilterColumnPlaceholder, value: filter.name, "data-id": filter.id, onChange: onSelectProperty }), _jsx(Select, { "data-id": filter.id, onChange: onSelectOperation, value: filter.operation.value, options: operators, title: translation.tableFilterOperatorTitle, placeholder: translation.tableFilterOperatorPlaceholder }), _jsx(Input, { "data-id": filter.id, onChange: onChangeValue, title: translation.tableFilterValueTitle, placeholder: translation.tableFilterValuePlaceholder, type: filter.type, value: filter.value, optionalText: "" }), _jsx("div", { className: "flex items-center justify-center mt-5", children: _jsx("button", { "data-id": filter.id, type: "button", onClick: onDelete, children: _jsx(Trash2Icon, { className: "text-danger", size: 16 }) }) })] }, `filter-select-${filter.id}`));
75
+ }), _jsx("li", { children: _jsxs("button", { type: "button", onClick: onAddFilter, className: "text-primary flex items-center gap-1", children: [_jsx(PlusIcon, { size: 14 }), " ", translation.tableFilterNewFilter] }) })] }) }) }));
76
+ };
77
+ export const ColumnHeaderFilter = ({ filter, onDelete, set }) => {
78
+ const translation = useTranslations();
79
+ const { operationOptions, operations } = useOperators();
80
+ const onSelectOperation = (e) => {
81
+ const operator = e.target.value;
82
+ const id = e.target.dataset.id || "";
83
+ set((prev) => prev.map((x) => (x.id === id ? Object.assign(Object.assign({}, x), { operation: operations[operator] }) : x)));
84
+ };
85
+ const onChangeValue = (e) => {
86
+ const id = e.target.dataset.id || "";
87
+ const value = valueFromType(e.target);
88
+ set((prev) => prev.map((x) => (x.id === id ? Object.assign(Object.assign({}, x), { value }) : x)));
89
+ };
90
+ return (_jsxs("div", { className: "flex flex-nowrap items-center gap-4 py-2", children: [_jsx(Select, { "data-id": filter.id, onChange: onSelectOperation, options: operationOptions[filter.type], title: translation.tableFilterColumnTitle, placeholder: translation.tableFilterColumnPlaceholder, value: filter.operation.value }), _jsx(Input, { "data-id": filter.id, onChange: onChangeValue, type: filter.type, value: filter.value, title: translation.tableFilterValueTitle, placeholder: translation.tableFilterValueTitle }), _jsx("button", { onClick: onDelete, "data-id": filter.id, type: "button", className: "mt-4", children: _jsx(Trash2Icon, { className: "text-danger", size: 14 }) })] }));
91
+ };
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+ import { Col, TableConfiguration } from "./table-lib";
3
+ export type GroupItem<T extends {}> = Col<T> & {
4
+ rows: T[];
5
+ index: number;
6
+ groupId: string;
7
+ groupName: string;
8
+ groupKey: keyof T;
9
+ };
10
+ type Props<T extends {}> = TableConfiguration<T, {
11
+ rows: T[];
12
+ groups: GroupItem<T>[];
13
+ setGroups: React.Dispatch<React.SetStateAction<GroupItem<T>[]>>;
14
+ }>;
15
+ export declare const Group: <T extends {}>(props: Props<T>) => import("react/jsx-runtime").JSX.Element;
16
+ export {};
17
+ //# sourceMappingURL=group.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../../../../src/components/table/group.tsx"],"names":[],"mappings":"AAIA,OAAO,KAA6B,MAAM,OAAO,CAAC;AAOlD,OAAO,EAAE,GAAG,EAAoB,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAExE,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG;IAC3C,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC,CAAC;CACrB,CAAC;AAEF,KAAK,KAAK,CAAC,CAAC,SAAS,EAAE,IAAI,kBAAkB,CACzC,CAAC,EACD;IACI,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;IACvB,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CACnE,CACJ,CAAC;AAqBF,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,EAAE,SAAS,KAAK,CAAC,CAAC,CAAC,4CA2ElD,CAAC"}
@@ -0,0 +1,43 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { LayoutGroup, Reorder, useDragControls, useMotionValue } from "framer-motion";
4
+ import Linq from "linq-arrays";
5
+ import { GripVerticalIcon, Trash2Icon, UngroupIcon } from "lucide-react";
6
+ import { Fragment, useState } from "react";
7
+ import { keys } from "sidekicker";
8
+ import { useTranslations } from "../../hooks/use-translate-context";
9
+ import { uuid } from "../../lib/fns";
10
+ import { Button } from "../core/button";
11
+ import { Dropdown } from "../floating/dropdown";
12
+ import { Select } from "../form/select";
13
+ import { createOptionCols } from "./table-lib";
14
+ const Item = ({ item, onPointerDown }) => {
15
+ const y = useMotionValue(0);
16
+ return (_jsxs(Reorder.Item, { onPointerDown: onPointerDown, id: item.groupId, className: "flex flex-row items-center gap-2", value: item, style: { y }, children: [_jsx("button", { type: "button", className: "cursor-grab", children: _jsx(GripVerticalIcon, { size: 14 }) }), _jsx("span", { children: item.groupName })] }, item.groupId));
17
+ };
18
+ export const Group = (props) => {
19
+ var _a;
20
+ const translations = useTranslations();
21
+ const options = createOptionCols(props.cols);
22
+ const controls = useDragControls();
23
+ const [group, setGroup] = useState(((_a = props.groups[0]) === null || _a === void 0 ? void 0 : _a.thead) || "");
24
+ const onChange = (e) => {
25
+ var _a;
26
+ const select = e.target;
27
+ const key = select.value;
28
+ const index = select.options.selectedIndex;
29
+ const label = ((_a = select.options.item(index)) === null || _a === void 0 ? void 0 : _a.label) || "";
30
+ setGroup(label);
31
+ const groupBy = new Linq(props.rows).GroupBy(key);
32
+ const col = props.cols.find((x) => x.id === key);
33
+ props.setGroups(keys(groupBy).map((groupName, index) => {
34
+ const rows = groupBy[groupName];
35
+ return Object.assign(Object.assign({}, col), { groupId: uuid(), groupKey: key, index, rows, groupName: groupName });
36
+ }));
37
+ };
38
+ const onDelete = () => props.setGroups([]);
39
+ return (_jsx(Fragment, { children: _jsxs(Dropdown, { arrow: false, title: translations.tableGroupLabel, trigger: _jsxs("span", { className: "flex items-center gap-1 proportional-nums", children: [_jsx(UngroupIcon, { size: 14 }), translations.tableGroupLabelWithCount, props.groups.length > 0 ? ` - ${group}(${props.groups.length})` : ""] }), children: [_jsxs("div", { className: "flex flex-nowrap items-center", children: [_jsx(Select, { value: group, title: "Tipo de agrupamento", onChange: onChange, options: options, placeholder: "Agrupar por..." }), _jsx(Button, { className: "mt-4", onClick: onDelete, theme: "raw", "data-id": group, children: _jsx(Trash2Icon, { size: 16, className: "text-danger" }) })] }), props.groups.length > 0 ? (_jsxs("section", { className: "my-4", children: [_jsx("header", { children: _jsx("h2", { className: "text-xl font-medium", children: "Order groups" }) }), _jsx(LayoutGroup, { children: _jsx(Reorder.Group, { axis: "y", className: "relative space-y-2", drag: true, dragControls: controls, dragListener: false, layoutScroll: true, onReorder: props.setGroups, values: props.groups, children: props.groups.map((item) => (_jsx(Item, { item: item, onPointerDown: (e) => {
40
+ controls.start(e);
41
+ props.setGroups([...props.groups]);
42
+ } }, item.groupId))) }) })] })) : null] }) }));
43
+ };
@@ -0,0 +1,38 @@
1
+ import React, { HTMLAttributes } from "react";
2
+ import { OptionProps } from "../form/select";
3
+ import { FilterConfig } from "./filter";
4
+ import { GroupItem } from "./group";
5
+ import { Sorter } from "./sort";
6
+ import { Col, TableOperationProps } from "./table-lib";
7
+ type InnerTableProps<T extends {}> = HTMLAttributes<HTMLTableElement> & TableOperationProps<T> & {
8
+ border?: boolean;
9
+ useControl?: boolean;
10
+ loading?: boolean;
11
+ group?: GroupItem<T>;
12
+ groups?: GroupItem<T>[];
13
+ optionCols: OptionProps[];
14
+ index: number;
15
+ rows: T[];
16
+ cols: Col<T>[];
17
+ sorters?: Sorter<T>[];
18
+ showMetadata?: boolean;
19
+ filters?: FilterConfig<T>[];
20
+ setGroups: React.Dispatch<React.SetStateAction<GroupItem<T>[]>>;
21
+ onScrollEnd?: () => void;
22
+ loadingMore?: boolean;
23
+ };
24
+ export type TableProps<T extends {}> = Pick<InnerTableProps<T>, "cols" | "rows" | "loadingMore" | "border"> & {
25
+ name: string;
26
+ } & Partial<TableOperationProps<T> & {
27
+ inlineFilter: boolean;
28
+ inlineSorter: boolean;
29
+ loading: boolean;
30
+ onScrollEnd: () => void;
31
+ operations: boolean;
32
+ reference: keyof T;
33
+ sticky: number;
34
+ useControl: boolean;
35
+ }>;
36
+ export declare const Table: <T extends {}>(props: TableProps<T>) => import("react/jsx-runtime").JSX.Element;
37
+ export {};
38
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/table/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAA2B,cAAc,EAAoD,MAAM,OAAO,CAAC;AAMzH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGpC,OAAO,EAAa,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAoB,GAAG,EAA+B,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAStG,KAAK,eAAe,CAAC,CAAC,SAAS,EAAE,IAAI,cAAc,CAAC,gBAAgB,CAAC,GACjE,mBAAmB,CAAC,CAAC,CAAC,GAAG;IACrB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACrB,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;IACxB,UAAU,EAAE,WAAW,EAAE,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACtB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,OAAO,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5B,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAChE,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,WAAW,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAgLN,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,EAAE,IAAI,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,aAAa,GAAG,QAAQ,CAAC,GAAG;IAC1G,IAAI,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CACH,mBAAmB,CAAC,CAAC,CAAC,GAAG;IACrB,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;CACvB,CACJ,CAAC;AASN,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,EAAE,SAAS,UAAU,CAAC,CAAC,CAAC,4CA8GvD,CAAC"}
@@ -0,0 +1,146 @@
1
+ import { __rest } from "tslib";
2
+ import { createElement as _createElement } from "react";
3
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
+ import { AnimatePresence, motion } from "framer-motion";
5
+ import Linq from "linq-arrays";
6
+ import React, { createContext, Fragment, useContext, useEffect, useMemo, useRef, useState } from "react";
7
+ import { TableVirtuoso } from "react-virtuoso";
8
+ import { Is } from "sidekicker";
9
+ import { useReducer } from "use-typed-reducer";
10
+ import { useCallbackRef } from "../../hooks/use-callback-ref";
11
+ import { path } from "../../lib/fns";
12
+ import { Metadata } from "./metadata";
13
+ import { Pagination } from "./pagination";
14
+ import { multiSort } from "./sort";
15
+ import { createOptionCols } from "./table-lib";
16
+ import { TableHeader } from "./thead";
17
+ const TableContext = createContext({});
18
+ const useTable = () => useContext(TableContext);
19
+ const TableBody = React.forwardRef((props, ref) => {
20
+ var _a;
21
+ return (_jsx("tbody", Object.assign({}, props, { role: "rowgroup", className: `divide-y divide-table-border ${(_a = props.className) !== null && _a !== void 0 ? _a : ""}`, ref: ref, children: _jsx(AnimatePresence, { children: props.children }) })));
22
+ });
23
+ const VirtualTable = React.forwardRef((props, ref) => {
24
+ var _a;
25
+ return (_jsx("table", Object.assign({}, props, { ref: ref, role: "table", className: `table min-w-full table-auto divide-y divide-table-border text-left ${(_a = props.className) !== null && _a !== void 0 ? _a : ""}` })));
26
+ });
27
+ const Thead = React.forwardRef((_a, ref) => {
28
+ var _b;
29
+ var { context } = _a, props = __rest(_a, ["context"]);
30
+ const ctx = useTable();
31
+ const style = Object.assign(Object.assign({}, props === null || props === void 0 ? void 0 : props.style), { sticky: Is.number(ctx.sticky) ? `${ctx.sticky}px` : (_b = props === null || props === void 0 ? void 0 : props.style) === null || _b === void 0 ? void 0 : _b.sticky });
32
+ return _jsx("thead", Object.assign({}, props, { style: style, role: "rowgroup", className: "shadow-xs group:sticky top-0 bg-card-background", ref: ref }));
33
+ });
34
+ const TRow = React.forwardRef((_a, ref) => {
35
+ var _b;
36
+ var { context, item } = _a, props = __rest(_a, ["context", "item"]);
37
+ return (_jsx("tr", Object.assign({}, props, { role: "row", ref: ref, className: `table-row ${(_b = props === null || props === void 0 ? void 0 : props.className) !== null && _b !== void 0 ? _b : ""}` })));
38
+ });
39
+ const TFoot = React.forwardRef((props, ref) => {
40
+ if (props.context.loadingMore) {
41
+ return (_jsx("tfoot", Object.assign({}, props, { ref: ref, className: "bg-card-background", children: _jsx("tr", { role: "row", className: "bg-card-background", children: _jsx("td", { colSpan: 999, className: "h-14 bg-card-background px-2", children: _jsx("span", { className: "block h-2 w-full animate-pulse rounded bg-foreground opacity-60" }) }) }) })));
42
+ }
43
+ return null;
44
+ });
45
+ const components = {
46
+ TableHead: Thead,
47
+ Table: VirtualTable,
48
+ TableBody: TableBody,
49
+ TableRow: TRow,
50
+ TableFoot: TFoot,
51
+ };
52
+ const loadingArray = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
53
+ const ItemContent = (index, row, context) => {
54
+ const cols = context.cols;
55
+ const loading = context.loading;
56
+ return (_jsx(Fragment, { children: cols.map((col, colIndex) => {
57
+ var _a;
58
+ const matrix = `${colIndex},${index}`;
59
+ const value = path(row, col.id);
60
+ const Component = col.Element;
61
+ const className = ((_a = col.cellProps) === null || _a === void 0 ? void 0 : _a.className) || "";
62
+ return (_createElement("td", Object.assign({}, col.cellProps, { role: "cell", "data-matrix": matrix, key: `accessor-${index}-${colIndex}`, className: `hidden h-14 border-none px-2 first:table-cell md:table-cell ${className}` }), loading ? (_jsx("div", { className: "h-2 w-10/12 animate-pulse rounded bg-table-border" })) : Component ? (_jsx(Component, { row: row, matrix: matrix, col: col, rowIndex: index, value: value })) : (_jsx(Fragment, { children: Is.nil(value) ? "" : value }))));
63
+ }) }));
64
+ };
65
+ const Frag = () => _jsx(Fragment, {});
66
+ const InnerTable = (_a) => {
67
+ var { filters, pagination = null, onScrollEnd, useControl = false, setCols, setFilters, sorters, cols, border = false, setSorters } = _a, props = __rest(_a, ["filters", "pagination", "onScrollEnd", "useControl", "setCols", "setFilters", "sorters", "cols", "border", "setSorters"]);
68
+ const ref = useRef(null);
69
+ const [showLoadingFooter, setShowLoadingFooter] = useState(false);
70
+ const onScrollEndRef = useCallbackRef(onScrollEnd);
71
+ const loadingMoreRef = useCallbackRef(props.loadingMore);
72
+ const rows = useMemo(() => {
73
+ if (props.loading)
74
+ return loadingArray;
75
+ if (useControl)
76
+ return props.rows;
77
+ const linq = new Linq(props.rows);
78
+ if (filters.length > 0) {
79
+ filters.forEach((x) => x.value === "" || Number.isNaN(x.value) ? undefined : linq.Where(x.name, x.operation.symbol, x.value));
80
+ }
81
+ if (sorters.length === 0)
82
+ return linq.Select();
83
+ return multiSort(linq.Select(), sorters);
84
+ }, [props.rows, filters, sorters, props.loading]);
85
+ useEffect(() => {
86
+ if (ref.current === null) {
87
+ return () => { };
88
+ }
89
+ const div = ref.current;
90
+ const observer = new IntersectionObserver((entries) => {
91
+ var _a;
92
+ const endOfPage = entries[entries.length - 1];
93
+ const condition = endOfPage.isIntersecting && loadingMoreRef.current;
94
+ if (condition) {
95
+ (_a = onScrollEndRef.current) === null || _a === void 0 ? void 0 : _a.call(onScrollEndRef);
96
+ return void setShowLoadingFooter(true);
97
+ }
98
+ return setShowLoadingFooter(false);
99
+ });
100
+ observer.observe(div);
101
+ return () => observer.disconnect();
102
+ }, []);
103
+ return (_jsxs("div", { className: "min-w-full", children: [_jsxs("div", { className: `group rounded-lg px-1 ${border ? "border border-table-border" : ""}`, children: [_jsx(TableVirtuoso, { data: rows, useWindowScroll: true, components: components, totalCount: rows.length, itemContent: ItemContent, context: { loading: props.loading, loadingMore: props.loadingMore, cols: cols }, fixedFooterContent: showLoadingFooter ? Frag : null, fixedHeaderContent: () => (_jsx(TableHeader, { filters: filters, headers: cols, inlineFilter: props.inlineFilter, inlineSorter: props.inlineSorter, loading: !!props.loading, setCols: setCols, setFilters: setFilters, setSorters: setSorters, sorters: sorters })) }), _jsx("div", { "aria-hidden": "true", ref: ref, className: "h-0.5 w-full" })] }), pagination !== null ? _jsx(Pagination, Object.assign({}, pagination)) : null] }));
104
+ };
105
+ const dispatcherFun = (prev, setter) => typeof setter === "function" ? setter(prev) : setter;
106
+ const compareAndExec = (prev, state, exec) => (prev === state ? undefined : exec === null || exec === void 0 ? void 0 : exec(state));
107
+ export const Table = (props) => {
108
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
109
+ const contextState = useMemo(() => ({ sticky: props.sticky }), [props.sticky]);
110
+ const operations = (_a = props.operations) !== null && _a !== void 0 ? _a : true;
111
+ const optionCols = useMemo(() => createOptionCols(props.cols), [props.cols]);
112
+ const [state, dispatch] = useReducer({
113
+ cols: props.cols,
114
+ filters: ((_b = props.filters) !== null && _b !== void 0 ? _b : []),
115
+ groups: ((_c = props.groups) !== null && _c !== void 0 ? _c : []),
116
+ sorters: ((_d = props.sorters) !== null && _d !== void 0 ? _d : []),
117
+ }, (get) => {
118
+ const create = (key) => (arg) => {
119
+ const state = get.state();
120
+ return Object.assign(Object.assign({}, state), { [key]: dispatcherFun(state[key], arg) });
121
+ };
122
+ return {
123
+ cols: create("cols"),
124
+ filters: create("filters"),
125
+ groups: create("groups"),
126
+ sorters: create("sorters"),
127
+ };
128
+ }, {
129
+ postMiddleware: [
130
+ (state, prev) => {
131
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
132
+ console.log("->", state, prev);
133
+ (_a = props.set) === null || _a === void 0 ? void 0 : _a.call(props, state);
134
+ compareAndExec((_b = prev === null || prev === void 0 ? void 0 : prev.filters) !== null && _b !== void 0 ? _b : [], (_c = state.filters) !== null && _c !== void 0 ? _c : [], props.setFilters);
135
+ compareAndExec((_d = prev === null || prev === void 0 ? void 0 : prev.sorters) !== null && _d !== void 0 ? _d : [], (_e = state.sorters) !== null && _e !== void 0 ? _e : [], props.setSorters);
136
+ compareAndExec((_f = prev === null || prev === void 0 ? void 0 : prev.groups) !== null && _f !== void 0 ? _f : [], (_g = state.groups) !== null && _g !== void 0 ? _g : [], props.setGroups);
137
+ compareAndExec((_h = prev === null || prev === void 0 ? void 0 : prev.cols) !== null && _h !== void 0 ? _h : [], (_j = state.cols) !== null && _j !== void 0 ? _j : [], props.setCols);
138
+ return state;
139
+ },
140
+ ],
141
+ });
142
+ return (_jsx(TableContext.Provider, { value: contextState, children: _jsxs("div", { className: "relative min-w-full", children: [operations ? (_jsx(Metadata, { cols: state.cols, filters: state.filters, groups: state.groups, inlineFilter: (_e = props.inlineFilter) !== null && _e !== void 0 ? _e : true, inlineSorter: (_f = props.inlineSorter) !== null && _f !== void 0 ? _f : true, options: optionCols, pagination: (_g = props.pagination) !== null && _g !== void 0 ? _g : null, rows: props.rows, setCols: dispatch.cols, setFilters: dispatch.filters, setGroups: dispatch.groups, setSorters: dispatch.sorters, sorters: state.sorters })) : null, state.groups.length === 0 ? (_jsx(InnerTable, Object.assign({}, props, { inlineFilter: (_h = props.inlineFilter) !== null && _h !== void 0 ? _h : true, inlineSorter: (_j = props.inlineSorter) !== null && _j !== void 0 ? _j : true, onScrollEnd: props.onScrollEnd, cols: state.cols, filters: state.filters, groups: state.groups, index: 0, optionCols: optionCols, options: optionCols, setCols: dispatch.cols, setFilters: dispatch.filters, setGroups: dispatch.groups, setSorters: dispatch.sorters, sorters: state.sorters, pagination: (_k = props.pagination) !== null && _k !== void 0 ? _k : null }))) : (_jsx("div", { className: "flex flex-wrap gap-4", children: state.groups.map((group, index) => {
143
+ var _a, _b;
144
+ return (_jsx(motion.div, { className: "min-w-full", children: _jsx(InnerTable, Object.assign({}, props, { inlineFilter: (_a = props.inlineFilter) !== null && _a !== void 0 ? _a : true, inlineSorter: (_b = props.inlineSorter) !== null && _b !== void 0 ? _b : true, pagination: null, onScrollEnd: props.onScrollEnd, cols: state.cols, filters: state.filters, group: group, groups: state.groups, index: index, optionCols: optionCols, options: optionCols, rows: group.rows, setCols: dispatch.cols, setFilters: dispatch.filters, setGroups: dispatch.groups, setSorters: dispatch.sorters, sorters: state.sorters })) }, `group-${group.groupId}`));
145
+ }) }))] }) }));
146
+ };
@@ -0,0 +1,3 @@
1
+ import { TableOperationProps } from "./table-lib";
2
+ export declare const Metadata: <T extends {}>(props: TableOperationProps<T>) => import("react/jsx-runtime").JSX.Element;
3
+ //# sourceMappingURL=metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../../../src/components/table/metadata.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAiB,MAAM,aAAa,CAAC;AAEjE,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,EAAE,SAAS,mBAAmB,CAAC,CAAC,CAAC,4CAiDnE,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Filter } from "./filter";
3
+ import { Group } from "./group";
4
+ import { Sort } from "./sort";
5
+ import { valueFromType } from "./table-lib";
6
+ export const Metadata = (props) => (_jsx("header", { className: "min-w-full mb-1", children: _jsxs("div", { className: "flex flex-wrap min-w-full items-center justify-between gap-x-4 gap-y-1", children: [_jsxs("div", { className: "flex w-fit items-centeend gap-4 whitespace-nowrap py-2", children: [_jsx("span", { children: _jsx(Filter, { cols: props.cols, options: props.options, filters: props.filters, set: props.setFilters }) }), _jsx("span", { children: _jsx(Sort, { options: props.options, cols: props.cols, sorters: props.sorters, set: props.setSorters }) }), _jsx("span", { children: _jsx(Group, { rows: props.rows, groups: props.groups, setGroups: props.setGroups, options: props.options, cols: props.cols }) })] }), _jsx("ul", { className: "flex flex-wrap w-full flex-1 flex-grow flex-row items-center md:justify-end gap-4", children: props.filters.map((x) => (_jsxs("li", { className: "flex gap-1 items-center rounded-xl border border-card-border px-4 py-0.5", children: [_jsxs("span", { children: [_jsx("span", { className: "size-3 mr-2 aspect-square bg-primary inline-block rounded-full", "aria-hidden": "true" }), x.label, " ", x.operation.label.toLowerCase(), ":"] }), _jsxs("div", { className: "relative w-min min-w-[1ch]", children: [_jsx("span", { "aria-hidden": "true", className: "invisible whitespace-pre p-0", children: x.value || " " }), _jsx("input", { type: x.type, value: x.value, className: "absolute left-0 top-0 m-0 inline-block w-full bg-transparent p-0 placeholder-primary/70 outline-none [appearance:textfield] after:empty:text-primary/70 [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none", onChange: (e) => {
7
+ const value = valueFromType(e.target);
8
+ props.setFilters((prev) => prev.map((item) => x.id === item.id
9
+ ? Object.assign(Object.assign({}, item), { value }) : item));
10
+ } })] })] }, `filter-table-${x.id}`))) })] }) }));
@@ -0,0 +1,3 @@
1
+ import { TablePagination } from "./table-lib";
2
+ export declare const Pagination: (pagination: TablePagination) => import("react/jsx-runtime").JSX.Element;
3
+ //# sourceMappingURL=pagination.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../../../../src/components/table/pagination.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAwB9C,eAAO,MAAM,UAAU,eAAgB,eAAe,4CAyErD,CAAC"}
@@ -0,0 +1,43 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Fragment, useId, useMemo } from "react";
3
+ import { useTranslations } from "../../hooks/use-translate-context";
4
+ function createPaginationItems(current, max) {
5
+ if (!current || !max)
6
+ return [];
7
+ const items = [1];
8
+ if (current === 1 && max === 1)
9
+ return items;
10
+ if (current > 4)
11
+ items.push("-");
12
+ let r = 2;
13
+ const r1 = current - r;
14
+ const r2 = current + r;
15
+ for (let i = r1 > 2 ? r1 : 2; i <= Math.min(max, r2); i++)
16
+ items.push(i);
17
+ const p2 = max - 2;
18
+ if (r2 + 1 !== p2) {
19
+ if (r2 + 1 < max)
20
+ items.push("_");
21
+ }
22
+ if (r2 < max) {
23
+ items.push(max - 2);
24
+ items.push(max - 1);
25
+ items.push(max);
26
+ }
27
+ return Array.from(new Set(items));
28
+ }
29
+ export const Pagination = (pagination) => {
30
+ const id = useId();
31
+ const translation = useTranslations();
32
+ const Render = pagination.asLink || "button";
33
+ const pageNavigation = useMemo(() => createPaginationItems(pagination.current, pagination.pages), [pagination.current, pagination.pages]);
34
+ const hasNext = pagination.current < pagination.pages;
35
+ return (_jsxs("footer", { className: "flex px-1 py-4 items-center justify-center gap-4 lg:justify-between flex-wrap lg:flex-nowrap", children: [_jsx("p", { children: _jsx(translation.tablePaginationFooter, Object.assign({}, pagination, { sizes: pagination.sizes, select: pagination.onChangeSize && Array.isArray(pagination.sizes) ? (_jsxs(Fragment, { children: [_jsx("label", { htmlFor: id, children: translation.tablePaginationSelectLabel }), _jsx("select", { id: id, value: pagination.size, className: "cursor-pointer bg-transparent", onChange: (e) => {
36
+ var _a;
37
+ (_a = pagination.onChangeSize) === null || _a === void 0 ? void 0 : _a.call(pagination, Number(e.target.value));
38
+ }, children: pagination.sizes.map((value) => (_jsx("option", { value: value, children: value }, `pagination-opt-${value}`))) }), " "] })) : null })) }), _jsx("nav", { children: _jsxs("ul", { className: "flex items-center gap-2", children: [pagination.current > 1 ? (_jsx("li", { children: _jsx(Render, { href: "previous", className: "", children: translation.tablePaginationPrevious }) })) : null, pageNavigation.map((x) => {
39
+ if (x === null)
40
+ return null;
41
+ return (_jsx(Fragment, { children: typeof x === "string" ? (_jsx("li", { children: "..." })) : (_jsx("li", { children: _jsx(Render, { href: x, className: `cursor-pointer px-3 py-1 transition-colors border-b-2 hover:text-primary-subtle hover:border-primary-subtle proportional-nums ${x === pagination.current ? "text-primary border-primary" : "border-transparent"}`, children: x }) })) }, `pagination-${x}`));
42
+ }), hasNext ? (_jsx("li", { children: _jsx(Render, { href: "next", className: "", children: translation.tablePaginationNext }) })) : null] }) })] }));
43
+ };
@@ -0,0 +1,28 @@
1
+ import React from "react";
2
+ import { Label } from "../../types";
3
+ import { Col, TableConfiguration, TableOperationProps } from "./table-lib";
4
+ type Keyof<T extends {}> = keyof T extends infer R extends string ? R : never;
5
+ declare enum Order {
6
+ Asc = "asc",
7
+ Desc = "desc",
8
+ Undefined = "undefined"
9
+ }
10
+ export type Sorter<T extends {}> = {
11
+ value: Keyof<T>;
12
+ type: Order;
13
+ label: Label;
14
+ id: string;
15
+ };
16
+ export declare const multiSort: <T extends {}>(array: T[], fields: Sorter<T>[]) => T[];
17
+ type Props<T extends {}> = TableConfiguration<T, {
18
+ cols: Col<T>[];
19
+ sorters: Sorter<T>[];
20
+ set: React.Dispatch<React.SetStateAction<Sorter<T>[]>>;
21
+ }>;
22
+ export declare const Sort: <T extends {}>(props: Props<T>) => import("react/jsx-runtime").JSX.Element;
23
+ type SorterHeadProps<T extends {}> = Pick<TableOperationProps<T>, "sorters" | "setSorters"> & {
24
+ col: Col<T>;
25
+ };
26
+ export declare const SorterHead: <T extends {}>(props: SorterHeadProps<T>) => import("react/jsx-runtime").JSX.Element;
27
+ export {};
28
+ //# sourceMappingURL=sort.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../../../../src/components/table/sort.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAwC,MAAM,OAAO,CAAC;AAG7D,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGpC,OAAO,EAAE,GAAG,EAAY,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAErF,KAAK,KAAK,CAAC,CAAC,SAAS,EAAE,IAAI,MAAM,CAAC,SAAS,MAAM,CAAC,SAAS,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC;AAE9E,aAAK,KAAK;IACN,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,SAAS,cAAc;CAC1B;AAED,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,EAAE,IAAI;IAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAAC,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,KAAK,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC;AAY9F,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,UAAU,MAAM,CAAC,CAAC,CAAC,EAAE,QAA2C,CAAC;AAEnH,KAAK,KAAK,CAAC,CAAC,SAAS,EAAE,IAAI,kBAAkB,CACzC,CAAC,EACD;IACI,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IACrB,GAAG,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CAC1D,CACJ,CAAC;AASF,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,EAAE,SAAS,KAAK,CAAC,CAAC,CAAC,4CA0EjD,CAAC;AAEF,KAAK,eAAe,CAAC,CAAC,SAAS,EAAE,IAAI,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,SAAS,GAAG,YAAY,CAAC,GAAG;IAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC;AAE9G,eAAO,MAAM,UAAU,GAAI,CAAC,SAAS,EAAE,SAAS,eAAe,CAAC,CAAC,CAAC,4CAkCjE,CAAC"}
@@ -0,0 +1,79 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { ArrowDown01Icon, ArrowUp01Icon, ArrowUpDownIcon, PlusIcon, Trash2Icon } from "lucide-react";
4
+ import { Fragment, useEffect, useState } from "react";
5
+ import { useTranslations } from "../../hooks/use-translate-context";
6
+ import { uuid } from "../../lib/fns";
7
+ import { Dropdown } from "../floating/dropdown";
8
+ import { Select } from "../form/select";
9
+ import { getLabel } from "./table-lib";
10
+ var Order;
11
+ (function (Order) {
12
+ Order["Asc"] = "asc";
13
+ Order["Desc"] = "desc";
14
+ Order["Undefined"] = "undefined";
15
+ })(Order || (Order = {}));
16
+ const createSorterFn = (fields) => (a, b) => fields.reduce((acc, x) => {
17
+ const reverse = x.type === "desc" ? -1 : 1;
18
+ const property = x.value;
19
+ const p = a[property] > b[property] ? reverse : a[property] < b[property] ? -reverse : 0;
20
+ return acc !== 0 ? acc : p;
21
+ }, 0);
22
+ export const multiSort = (array, fields) => array.toSorted(createSorterFn(fields));
23
+ const createSorter = (col, label, order) => ({
24
+ id: uuid(),
25
+ type: order,
26
+ value: col.id,
27
+ label,
28
+ });
29
+ export const Sort = (props) => {
30
+ const translation = useTranslations();
31
+ const orders = {
32
+ asc: { label: translation.tableSortAsc, value: Order.Asc },
33
+ desc: { label: translation.tableSortDesc, value: Order.Desc },
34
+ };
35
+ const orderOptions = [orders.asc, orders.desc];
36
+ const onAddSorter = () => {
37
+ const col = props.cols[0];
38
+ if (col)
39
+ props.set((prev) => [...prev, createSorter(col, orders.asc.label, orders.asc.value)]);
40
+ };
41
+ const onSetSorter = (id) => (e) => {
42
+ const value = e.target.value;
43
+ props.set((prev) => prev.map((x) => (x.id === id ? Object.assign(Object.assign({}, x), { value: value }) : x)));
44
+ };
45
+ const onSortOrderType = (id) => (e) => {
46
+ const type = e.target.value;
47
+ props.set((prev) => prev.map((x) => (x.id === id ? Object.assign(Object.assign({}, x), { type: type }) : x)));
48
+ };
49
+ const onDelete = (e) => {
50
+ const id = e.currentTarget.dataset.id || "";
51
+ props.set((prev) => prev.filter((x) => x.id !== id));
52
+ };
53
+ return (_jsx(Fragment, { children: _jsx(Dropdown, { title: translation.tableSortDropdownTitle, trigger: _jsxs("span", { className: "flex items-center gap-1 proportional-nums", children: [_jsx(ArrowUpDownIcon, { size: 14 }), translation.tableSortOrderByLabel, " ", props.sorters.length === 0 ? "" : ` (${props.sorters.length})`] }), children: _jsxs("ul", { className: "mt-4 space-y-2", children: [props.sorters.map((sorter) => {
54
+ return (_jsxs("li", { className: "flex flex-nowrap gap-3", children: [_jsx(Select, { options: props.options, value: sorter.value, onChange: onSetSorter(sorter.id), title: translation.tableSortOrderInputTitle, placeholder: translation.tableSortOrderInputPlaceholder }), _jsx(Select, { onChange: onSortOrderType(sorter.id), value: sorter.type, options: orderOptions, title: translation.tableSortTypeInputTitle, placeholder: translation.tableSortTypeInputPlaceholder }), _jsx("button", { className: "mt-4", "data-id": sorter.id, onClick: onDelete, children: _jsx(Trash2Icon, { className: "text-danger", size: 14 }) })] }, `sorter-select-${sorter.id}`));
55
+ }), _jsx("li", { children: _jsxs("button", { type: "button", onClick: onAddSorter, className: "text-primary flex items-center gap-1", children: [_jsx(PlusIcon, { size: 14 }), " ", translation.tableSortAddButton] }) })] }) }) }));
56
+ };
57
+ export const SorterHead = (props) => {
58
+ const translations = useTranslations();
59
+ const [status, setStatus] = useState(() => {
60
+ const sorter = props.sorters.find((sort) => sort.value === props.col.id);
61
+ return sorter ? sorter.type : Order.Undefined;
62
+ });
63
+ const onClick = () => setStatus((prev) => (prev === Order.Undefined ? Order.Asc : prev === Order.Asc ? Order.Desc : Order.Undefined));
64
+ useEffect(() => {
65
+ props.setSorters((prev) => {
66
+ if (status === Order.Undefined)
67
+ return prev.filter((x) => x.value !== props.col.id);
68
+ const findIndex = prev.findIndex((p) => p.value === props.col.id);
69
+ const sorter = createSorter(props.col, status, status);
70
+ if (findIndex === -1)
71
+ return [...prev, sorter];
72
+ prev[findIndex] = sorter;
73
+ return [...prev];
74
+ });
75
+ }, [status, props.col]);
76
+ const labelId = `${props.col.id}-sorter-id`;
77
+ const label = getLabel(props.col);
78
+ return (_jsxs("button", { "aria-labelledby": labelId, className: "isolate flex items-center", onClick: onClick, type: "button", children: [_jsxs("span", { id: labelId, className: "sr-only", children: [translations.tableSortDropdownTitle, " ", label] }), status === Order.Asc ? _jsx(ArrowUp01Icon, { size: 14 }) : null, status === Order.Desc ? _jsx(ArrowDown01Icon, { size: 14 }) : null, status === Order.Undefined ? _jsx(ArrowUpDownIcon, { size: 14 }) : null] }));
79
+ };