@skalfa/skalfa-app 1.0.0 → 1.0.2

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 (87) hide show
  1. package/.env.example +43 -43
  2. package/.github/workflows/publish.yml +39 -0
  3. package/CONTRIBUTING.md +45 -0
  4. package/LICENSE +21 -0
  5. package/README.md +91 -28
  6. package/app/auth/edit/page.tsx +65 -65
  7. package/app/auth/login/page.tsx +63 -63
  8. package/app/auth/me/page.tsx +58 -58
  9. package/app/auth/register/page.tsx +69 -69
  10. package/app/auth/verify/page.tsx +53 -53
  11. package/app/dashboard/user/page.tsx +76 -76
  12. package/app/layout.tsx +37 -37
  13. package/app/manifest.ts +25 -0
  14. package/app/page.tsx +13 -13
  15. package/barrels.json +5 -5
  16. package/blueprints/starter.blueprint.json +102 -102
  17. package/bun.lock +916 -0
  18. package/components/base.components/chip/Chip.component.tsx +39 -39
  19. package/components/base.components/document/DocumentViewer.component.tsx +163 -163
  20. package/components/base.components/document/ExportExcel.component.tsx +340 -340
  21. package/components/base.components/document/ImportExcel.component.tsx +315 -315
  22. package/components/base.components/document/PrintTable.component.tsx +204 -204
  23. package/components/base.components/document/RenderPDF.component.tsx +415 -415
  24. package/components/base.components/input/Checkbox.component.tsx +109 -109
  25. package/components/base.components/input/Input.component.tsx +332 -332
  26. package/components/base.components/input/InputCheckbox.component.tsx +174 -174
  27. package/components/base.components/input/InputCurrency.component.tsx +163 -163
  28. package/components/base.components/input/InputDate.component.tsx +352 -352
  29. package/components/base.components/input/InputDatetime.component.tsx +260 -260
  30. package/components/base.components/input/InputDocument.component.tsx +351 -351
  31. package/components/base.components/input/InputImage.component.tsx +533 -533
  32. package/components/base.components/input/InputMap.component.tsx +317 -317
  33. package/components/base.components/input/InputNumber.component.tsx +192 -192
  34. package/components/base.components/input/InputOtp.component.tsx +169 -169
  35. package/components/base.components/input/InputPassword.component.tsx +236 -236
  36. package/components/base.components/input/InputRadio.component.tsx +175 -175
  37. package/components/base.components/input/InputTime.component.tsx +275 -275
  38. package/components/base.components/input/InputValues.component.tsx +68 -68
  39. package/components/base.components/input/Radio.component.tsx +102 -102
  40. package/components/base.components/input/Select.component.tsx +541 -541
  41. package/components/base.components/modal/BottomSheet.component.tsx +245 -245
  42. package/components/base.components/supervision/FormSupervision.component.tsx +433 -433
  43. package/components/base.components/supervision/TableSupervision.component.tsx +697 -697
  44. package/components/base.components/table/ControlBar.component.tsx +497 -497
  45. package/components/base.components/table/FilterComponent.tsx +518 -518
  46. package/components/base.components/table/Table.component.tsx +469 -469
  47. package/components/base.components/typography/TypographyArticle.component.tsx +26 -26
  48. package/components/base.components/typography/TypographyColumn.component.tsx +20 -20
  49. package/components/base.components/typography/TypographyContent.component.tsx +20 -20
  50. package/components/base.components/typography/TypographyTips.component.tsx +20 -20
  51. package/components/base.components/wrap/Draggable.component.tsx +303 -303
  52. package/components/base.components/wrap/IDBProvider.tsx +12 -12
  53. package/components/base.components/wrap/Image.component.tsx +9 -9
  54. package/components/base.components/wrap/ShortcutProvider.tsx +57 -57
  55. package/components/base.components/wrap/Swipe.component.tsx +93 -93
  56. package/components/index.ts +2 -2
  57. package/contexts/AppProvider.tsx +11 -11
  58. package/contexts/Auth.context.tsx +64 -64
  59. package/contexts/Toggle.context.tsx +44 -44
  60. package/next.config.ts +15 -1
  61. package/package.json +14 -13
  62. package/public/204.svg +19 -19
  63. package/public/500.svg +39 -39
  64. package/public/icon-192.png +0 -0
  65. package/public/icon-512.png +0 -0
  66. package/public/images/logo-fill.png +0 -0
  67. package/public/images/logo-full-fill.png +0 -0
  68. package/public/images/logo-full.png +0 -0
  69. package/public/images/logo.png +0 -0
  70. package/schema/idb/app.schema.ts +8 -8
  71. package/src-tauri/Cargo.toml +14 -0
  72. package/src-tauri/build.rs +3 -0
  73. package/src-tauri/capabilities/default.json +11 -0
  74. package/src-tauri/icons/128x128.png +0 -0
  75. package/src-tauri/icons/128x128@2x.png +0 -0
  76. package/src-tauri/icons/32x32.png +0 -0
  77. package/src-tauri/icons/icon.icns +0 -0
  78. package/src-tauri/icons/icon.ico +0 -0
  79. package/src-tauri/src/main.rs +7 -0
  80. package/src-tauri/tauri.conf.json +36 -0
  81. package/styles/globals.css +231 -231
  82. package/styles/tailwind.safelist +68 -68
  83. package/utils/commands/barrels.ts +27 -27
  84. package/utils/commands/light.ts +21 -21
  85. package/utils/commands/logger.ts +42 -42
  86. package/utils/commands/stubs/table-blueprint.stub +12 -12
  87. package/utils/commands/use-pdf.ts +29 -29
@@ -1,204 +1,204 @@
1
- "use client";
2
-
3
- import { useEffect, useMemo, useState } from "react";
4
- import { FetchControlType, useTable } from "@utils";
5
- import { TableComponent, IconButtonComponent, FilterComponent, NodeSchema, PageSchema, RenderPDFPreview, ButtonComponent, RenderPDF } from "@components";
6
- import { faArrowLeft, faArrowRight } from "@fortawesome/free-solid-svg-icons";
7
-
8
-
9
- export type PrintColumn = {
10
- selector : string;
11
- source : string | null;
12
- width : number;
13
- };
14
-
15
- export type ColumnControl = {
16
- selector : string;
17
- label : string;
18
- };
19
-
20
-
21
-
22
- function usePrintColumns(data: any[], columnControl?: ColumnControl[]) {
23
- const fields = useMemo(() => {
24
- if (!data?.[0]) return [];
25
- return Object.keys(data[0]);
26
- }, [data]);
27
-
28
- const [columns, setColumns] = useState<PrintColumn[]>([]);
29
-
30
- useEffect(() => {
31
- if (!data?.[0] || columns.length) return;
32
-
33
- if (columnControl?.length) {
34
- setColumns(
35
- columnControl.map((c) => ({
36
- selector: c.label,
37
- source: c.selector,
38
- width: 120,
39
- }))
40
- );
41
- return;
42
- }
43
-
44
- setColumns(
45
- fields.map((f) => ({
46
- selector: f,
47
- source: f,
48
- width: 120,
49
- }))
50
- );
51
- }, [data, fields, columnControl]);
52
-
53
- const move = (selector: string, dir: "left" | "right") => {
54
- setColumns(prev => {
55
- const idx = prev.findIndex(c => c.selector === selector);
56
- const target = dir === "left" ? idx - 1 : idx + 1;
57
- if (idx < 0 || target < 0 || target >= prev.length) return prev;
58
- const next = [...prev];
59
- [next[idx], next[target]] = [next[target], next[idx]];
60
- return next.map((c) => ({ ...c, selector: c.selector }));
61
- });
62
- };
63
-
64
- return { columns, move };
65
- }
66
-
67
-
68
- function buildPrintSchema({ title, columns, data, columnControl }: {
69
- title ?: string;
70
- columns : PrintColumn[];
71
- data : any[];
72
- columnControl ?: ColumnControl[];
73
- }) : PageSchema[] {
74
- const active = columns.filter(c => c.source);
75
-
76
- const getHeaderLabel = (source: string | null) => {
77
- if (!source) return "";
78
-
79
- const found = columnControl?.find(c => c.selector === source);
80
-
81
- return found?.label ?? source;
82
- };
83
-
84
- const content: NodeSchema[] = [];
85
-
86
- if (title) {
87
- content.push({
88
- type : "text",
89
- content : title,
90
- style : { fontSize: 16, fontWeight: "bold", marginBottom: 12 },
91
- });
92
- }
93
-
94
- content.push({
95
- type : "table",
96
- content : [
97
- {
98
- type : "tr" as const,
99
- content : active.map<NodeSchema>(c => ({
100
- type : "th" as const,
101
- content : getHeaderLabel(c.source),
102
- style : { width: c.width },
103
- })),
104
- },
105
- ...data.map<NodeSchema>(row => ({
106
- type : "tr" as const,
107
- content : active.map<NodeSchema>(c => ({
108
- type : "td" as const,
109
- content : String(row[c.source!] ?? ""),
110
- style : { width: c.width },
111
- })),
112
- })),
113
- ],
114
- });
115
-
116
- return [{ page: { size: "A4", margin: 40, content } }];
117
- }
118
-
119
-
120
-
121
- export function PrintTable({ fetchControl, columnControl, title }: { fetchControl: FetchControlType; columnControl?: ColumnControl[]; title?: string; }) {
122
- const { data } = useTable(fetchControl, undefined, undefined, false);
123
- const rows = data?.data ?? [];
124
-
125
- const { columns, move } = usePrintColumns(rows, columnControl);
126
-
127
- const schema = useMemo(() => buildPrintSchema({
128
- title: title,
129
- columns,
130
- data: rows,
131
- columnControl,
132
- }), [columns, rows, columnControl]);
133
-
134
- return (
135
- <>
136
- <div className="p-4">
137
- <FilterComponent
138
- columns={data?.data[0] && Object.keys(data?.data[0])?.map((c) => ({ label: c, selector: c }))}
139
- onChange={() => {}}
140
- value={[]}
141
- />
142
- </div>
143
-
144
- <div className="p-4">
145
- <TableComponent
146
- controlBar={false}
147
- pagination={false}
148
- noIndex
149
- columns={columns.map(c => ({ selector: c.selector, label: c.selector }))}
150
- data={[
151
- Object.fromEntries(
152
- columns.map((c, key) => [
153
- c.selector,
154
- <div className="flex gap-1" key={key}>
155
- {key > 0 && (
156
- <IconButtonComponent
157
- icon={faArrowLeft}
158
- size="xs"
159
- variant="outline"
160
- className="!text-foreground"
161
- onClick={() => move(c.selector, "left")}
162
- />
163
- )}
164
-
165
- {key < (columns.length - 1) && (
166
- <IconButtonComponent
167
- icon={faArrowRight}
168
- size="xs"
169
- variant="outline"
170
- className="!text-foreground"
171
- onClick={() => move(c.selector, "right")}
172
- />
173
- )}
174
- </div>,
175
- ])
176
- ),
177
- ]}
178
- className="row::bg-transparent row::border-0 row::gap-0 row::!hover:bg-white column::p-2 column::border-l head-column::p-2 head-column::border-l"
179
- />
180
- </div>
181
-
182
- <RenderPDFPreview schema={schema} className="w-full max-h-[400px] overflow-y-auto flex justify-center bg-background mt-4" />
183
-
184
-
185
- <div className="px-4 mt-8">
186
- <ButtonComponent label=" Download PDF" block onClick={async () => {
187
- const bytes = await RenderPDF({ content: schema });
188
-
189
- const arrayBuffer = bytes.buffer instanceof ArrayBuffer ? bytes.buffer : bytes.slice().buffer;
190
-
191
- const blob = new Blob([arrayBuffer], { type: "application/pdf" });
192
- const url = URL.createObjectURL(blob);
193
-
194
- const a = document.createElement("a");
195
- a.href = url;
196
- a.download = title ? `${title}.pdf` : "print.pdf";
197
- a.click();
198
-
199
- URL.revokeObjectURL(url);
200
- }} />
201
- </div>
202
- </>
203
- );
204
- }
1
+ "use client";
2
+
3
+ import { useEffect, useMemo, useState } from "react";
4
+ import { FetchControlType, useTable } from "@utils";
5
+ import { TableComponent, IconButtonComponent, FilterComponent, NodeSchema, PageSchema, RenderPDFPreview, ButtonComponent, RenderPDF } from "@components";
6
+ import { faArrowLeft, faArrowRight } from "@fortawesome/free-solid-svg-icons";
7
+
8
+
9
+ export type PrintColumn = {
10
+ selector : string;
11
+ source : string | null;
12
+ width : number;
13
+ };
14
+
15
+ export type ColumnControl = {
16
+ selector : string;
17
+ label : string;
18
+ };
19
+
20
+
21
+
22
+ function usePrintColumns(data: any[], columnControl?: ColumnControl[]) {
23
+ const fields = useMemo(() => {
24
+ if (!data?.[0]) return [];
25
+ return Object.keys(data[0]);
26
+ }, [data]);
27
+
28
+ const [columns, setColumns] = useState<PrintColumn[]>([]);
29
+
30
+ useEffect(() => {
31
+ if (!data?.[0] || columns.length) return;
32
+
33
+ if (columnControl?.length) {
34
+ setColumns(
35
+ columnControl.map((c) => ({
36
+ selector: c.label,
37
+ source: c.selector,
38
+ width: 120,
39
+ }))
40
+ );
41
+ return;
42
+ }
43
+
44
+ setColumns(
45
+ fields.map((f) => ({
46
+ selector: f,
47
+ source: f,
48
+ width: 120,
49
+ }))
50
+ );
51
+ }, [data, fields, columnControl]);
52
+
53
+ const move = (selector: string, dir: "left" | "right") => {
54
+ setColumns(prev => {
55
+ const idx = prev.findIndex(c => c.selector === selector);
56
+ const target = dir === "left" ? idx - 1 : idx + 1;
57
+ if (idx < 0 || target < 0 || target >= prev.length) return prev;
58
+ const next = [...prev];
59
+ [next[idx], next[target]] = [next[target], next[idx]];
60
+ return next.map((c) => ({ ...c, selector: c.selector }));
61
+ });
62
+ };
63
+
64
+ return { columns, move };
65
+ }
66
+
67
+
68
+ function buildPrintSchema({ title, columns, data, columnControl }: {
69
+ title ?: string;
70
+ columns : PrintColumn[];
71
+ data : any[];
72
+ columnControl ?: ColumnControl[];
73
+ }) : PageSchema[] {
74
+ const active = columns.filter(c => c.source);
75
+
76
+ const getHeaderLabel = (source: string | null) => {
77
+ if (!source) return "";
78
+
79
+ const found = columnControl?.find(c => c.selector === source);
80
+
81
+ return found?.label ?? source;
82
+ };
83
+
84
+ const content: NodeSchema[] = [];
85
+
86
+ if (title) {
87
+ content.push({
88
+ type : "text",
89
+ content : title,
90
+ style : { fontSize: 16, fontWeight: "bold", marginBottom: 12 },
91
+ });
92
+ }
93
+
94
+ content.push({
95
+ type : "table",
96
+ content : [
97
+ {
98
+ type : "tr" as const,
99
+ content : active.map<NodeSchema>(c => ({
100
+ type : "th" as const,
101
+ content : getHeaderLabel(c.source),
102
+ style : { width: c.width },
103
+ })),
104
+ },
105
+ ...data.map<NodeSchema>(row => ({
106
+ type : "tr" as const,
107
+ content : active.map<NodeSchema>(c => ({
108
+ type : "td" as const,
109
+ content : String(row[c.source!] ?? ""),
110
+ style : { width: c.width },
111
+ })),
112
+ })),
113
+ ],
114
+ });
115
+
116
+ return [{ page: { size: "A4", margin: 40, content } }];
117
+ }
118
+
119
+
120
+
121
+ export function PrintTable({ fetchControl, columnControl, title }: { fetchControl: FetchControlType; columnControl?: ColumnControl[]; title?: string; }) {
122
+ const { data } = useTable(fetchControl, undefined, undefined, false);
123
+ const rows = data?.data ?? [];
124
+
125
+ const { columns, move } = usePrintColumns(rows, columnControl);
126
+
127
+ const schema = useMemo(() => buildPrintSchema({
128
+ title: title,
129
+ columns,
130
+ data: rows,
131
+ columnControl,
132
+ }), [columns, rows, columnControl]);
133
+
134
+ return (
135
+ <>
136
+ <div className="p-4">
137
+ <FilterComponent
138
+ columns={data?.data[0] && Object.keys(data?.data[0])?.map((c) => ({ label: c, selector: c }))}
139
+ onChange={() => {}}
140
+ value={[]}
141
+ />
142
+ </div>
143
+
144
+ <div className="p-4">
145
+ <TableComponent
146
+ controlBar={false}
147
+ pagination={false}
148
+ noIndex
149
+ columns={columns.map(c => ({ selector: c.selector, label: c.selector }))}
150
+ data={[
151
+ Object.fromEntries(
152
+ columns.map((c, key) => [
153
+ c.selector,
154
+ <div className="flex gap-1" key={key}>
155
+ {key > 0 && (
156
+ <IconButtonComponent
157
+ icon={faArrowLeft}
158
+ size="xs"
159
+ variant="outline"
160
+ className="!text-foreground"
161
+ onClick={() => move(c.selector, "left")}
162
+ />
163
+ )}
164
+
165
+ {key < (columns.length - 1) && (
166
+ <IconButtonComponent
167
+ icon={faArrowRight}
168
+ size="xs"
169
+ variant="outline"
170
+ className="!text-foreground"
171
+ onClick={() => move(c.selector, "right")}
172
+ />
173
+ )}
174
+ </div>,
175
+ ])
176
+ ),
177
+ ]}
178
+ className="row::bg-transparent row::border-0 row::gap-0 row::!hover:bg-white column::p-2 column::border-l head-column::p-2 head-column::border-l"
179
+ />
180
+ </div>
181
+
182
+ <RenderPDFPreview schema={schema} className="w-full max-h-[400px] overflow-y-auto flex justify-center bg-background mt-4" />
183
+
184
+
185
+ <div className="px-4 mt-8">
186
+ <ButtonComponent label=" Download PDF" block onClick={async () => {
187
+ const bytes = await RenderPDF({ content: schema });
188
+
189
+ const arrayBuffer = bytes.buffer instanceof ArrayBuffer ? bytes.buffer : bytes.slice().buffer;
190
+
191
+ const blob = new Blob([arrayBuffer], { type: "application/pdf" });
192
+ const url = URL.createObjectURL(blob);
193
+
194
+ const a = document.createElement("a");
195
+ a.href = url;
196
+ a.download = title ? `${title}.pdf` : "print.pdf";
197
+ a.click();
198
+
199
+ URL.revokeObjectURL(url);
200
+ }} />
201
+ </div>
202
+ </>
203
+ );
204
+ }