@skalfa/skalfa-app 1.0.3 → 1.0.6

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 (90) hide show
  1. package/.env.example +8 -16
  2. package/app/auth/edit/page.tsx +1 -1
  3. package/app/auth/login/page.tsx +1 -1
  4. package/app/auth/me/page.tsx +1 -1
  5. package/app/auth/register/page.tsx +1 -1
  6. package/app/auth/verify/page.tsx +1 -1
  7. package/app/dashboard/layout.tsx +2 -2
  8. package/app/dashboard/page.tsx +1 -1
  9. package/app/index.ts +1 -0
  10. package/app/layout.tsx +2 -4
  11. package/app/page.tsx +2 -2
  12. package/bun.lock +7 -2
  13. package/components/index.ts +1 -3
  14. package/package.json +10 -7
  15. package/styles/components.css +1392 -0
  16. package/styles/globals.css +40 -175
  17. package/styles/utilities.css +37 -0
  18. package/tsconfig.json +4 -2
  19. package/utils/commands/skalfa.ts +1 -1
  20. package/components/base.components/accordion/Accordion.component.tsx +0 -82
  21. package/components/base.components/breadcrumb/Breadcrumb.component.tsx +0 -80
  22. package/components/base.components/button/Button.component.tsx +0 -91
  23. package/components/base.components/button/IconButton.component.tsx +0 -88
  24. package/components/base.components/button/button.decorate.ts +0 -82
  25. package/components/base.components/card/AlertCard.component.tsx +0 -69
  26. package/components/base.components/card/Card.component.tsx +0 -25
  27. package/components/base.components/card/DashboardCard.component.tsx +0 -44
  28. package/components/base.components/card/GalleryCard.component.tsx +0 -50
  29. package/components/base.components/card/ProductCard.component.tsx +0 -65
  30. package/components/base.components/card/ProfileCard.component.tsx +0 -71
  31. package/components/base.components/carousel/Carousel.component.tsx +0 -113
  32. package/components/base.components/chip/Chip.component.tsx +0 -39
  33. package/components/base.components/document/DocumentViewer.component.tsx +0 -164
  34. package/components/base.components/document/ExportExcel.component.tsx +0 -340
  35. package/components/base.components/document/ImportExcel.component.tsx +0 -315
  36. package/components/base.components/document/PrintTable.component.tsx +0 -204
  37. package/components/base.components/document/RenderPDF.component.tsx +0 -416
  38. package/components/base.components/index.ts +0 -85
  39. package/components/base.components/input/Checkbox.component.tsx +0 -109
  40. package/components/base.components/input/Input.component.tsx +0 -332
  41. package/components/base.components/input/InputCheckbox.component.tsx +0 -174
  42. package/components/base.components/input/InputCurrency.component.tsx +0 -163
  43. package/components/base.components/input/InputDate.component.tsx +0 -352
  44. package/components/base.components/input/InputDatetime.component.tsx +0 -260
  45. package/components/base.components/input/InputDocument.component.tsx +0 -352
  46. package/components/base.components/input/InputImage.component.tsx +0 -533
  47. package/components/base.components/input/InputMap.component.tsx +0 -318
  48. package/components/base.components/input/InputNumber.component.tsx +0 -192
  49. package/components/base.components/input/InputOtp.component.tsx +0 -169
  50. package/components/base.components/input/InputPassword.component.tsx +0 -236
  51. package/components/base.components/input/InputRadio.component.tsx +0 -175
  52. package/components/base.components/input/InputTime.component.tsx +0 -276
  53. package/components/base.components/input/InputValues.component.tsx +0 -68
  54. package/components/base.components/input/Radio.component.tsx +0 -102
  55. package/components/base.components/input/Select.component.tsx +0 -541
  56. package/components/base.components/modal/BottomSheet.component.tsx +0 -246
  57. package/components/base.components/modal/FloatingPage.component.tsx +0 -104
  58. package/components/base.components/modal/Modal.component.tsx +0 -96
  59. package/components/base.components/modal/ModalConfirm.component.tsx +0 -218
  60. package/components/base.components/modal/Toast.component.tsx +0 -126
  61. package/components/base.components/nav/Bottombar.component.tsx +0 -116
  62. package/components/base.components/nav/Footer.component.tsx +0 -144
  63. package/components/base.components/nav/Headbar.component.tsx +0 -104
  64. package/components/base.components/nav/Navbar.component.tsx +0 -100
  65. package/components/base.components/nav/Sidebar.component.tsx +0 -301
  66. package/components/base.components/nav/Tabbar.component.tsx +0 -60
  67. package/components/base.components/nav/Wizard.component.tsx +0 -73
  68. package/components/base.components/supervision/FormSupervision.component.tsx +0 -434
  69. package/components/base.components/supervision/TableSupervision.component.tsx +0 -697
  70. package/components/base.components/table/ControlBar.component.tsx +0 -497
  71. package/components/base.components/table/FilterComponent.tsx +0 -518
  72. package/components/base.components/table/Pagination.component.tsx +0 -159
  73. package/components/base.components/table/Table.component.tsx +0 -469
  74. package/components/base.components/typography/TypographyArticle.component.tsx +0 -26
  75. package/components/base.components/typography/TypographyColumn.component.tsx +0 -20
  76. package/components/base.components/typography/TypographyContent.component.tsx +0 -20
  77. package/components/base.components/typography/TypographyTips.component.tsx +0 -20
  78. package/components/base.components/wrap/Draggable.component.tsx +0 -303
  79. package/components/base.components/wrap/IDBProvider.tsx +0 -12
  80. package/components/base.components/wrap/Image.component.tsx +0 -10
  81. package/components/base.components/wrap/OutsideClick.component.tsx +0 -48
  82. package/components/base.components/wrap/ScrollContainer.component.tsx +0 -104
  83. package/components/base.components/wrap/ShortcutProvider.tsx +0 -57
  84. package/components/base.components/wrap/Swipe.component.tsx +0 -93
  85. package/components/construct.components/example.tsx +0 -1
  86. package/components/construct.components/index.ts +0 -5
  87. package/components/structure.components/example.tsx +0 -1
  88. package/components/structure.components/index.ts +0 -5
  89. package/schema/idb/app.schema.ts +0 -9
  90. package/schema/index.ts +0 -5
@@ -1,533 +0,0 @@
1
- "use client"
2
-
3
- import { useEffect, useRef, useState } from "react";
4
- import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
5
- import { faHandHolding, faImages, faTimes } from "@fortawesome/free-solid-svg-icons";
6
- import { cn, pcn, useInputHandler, useInputRandomId, useResponsive, useValidation, validation, ValidationRules } from "@utils";
7
- import { BottomSheetComponent, ButtonComponent, IconButtonComponent, ModalComponent } from "@components";
8
-
9
-
10
- type CT = "label" | "error" | "input" | "tip";
11
-
12
- export interface InputImageProps {
13
- name : string;
14
- label ?: string;
15
- tip ?: string;
16
-
17
- value ?: string | File;
18
- aspect ?: string;
19
- invalid ?: string;
20
- disabled ?: boolean;
21
- validations ?: ValidationRules;
22
-
23
- onChange?: (file?: File | null) => void;
24
- register?: (name: string, validations?: ValidationRules) => void;
25
- unregister?: (name: string) => void;
26
-
27
- className?: string;
28
- }
29
-
30
-
31
-
32
- export const InputImageComponent: React.FC<InputImageProps> = ({
33
- name,
34
- label,
35
- tip,
36
-
37
- value,
38
- disabled,
39
- aspect = "1/1",
40
- invalid,
41
- validations,
42
-
43
- onChange,
44
- register,
45
- unregister,
46
- className = "",
47
- }) => {
48
- const { isSm } = useResponsive();
49
-
50
- const randomId = useInputRandomId();
51
- const inputRef = useRef<HTMLInputElement>(null);
52
-
53
- const [preview, setPreview] = useState("");
54
- const [drag, setDrag] = useState(false);
55
- const [cropSrc, setCropSrc] = useState<string | null>(null);
56
- const [openCrop, setOpenCrop] = useState(false);
57
-
58
- const inputHandler = useInputHandler(name, value, validations, register, unregister, true);
59
- const [invalidMessage, setInvalidMessage] = useValidation(inputHandler.value, validations, invalid, inputHandler.idle);
60
-
61
- useEffect(() => {
62
- if (value) {
63
- const url = typeof value === "object" ? URL.createObjectURL(value) : value;
64
- setPreview(url);
65
-
66
- return () => {
67
- typeof value === "object" && URL.revokeObjectURL(url);
68
- };
69
- } else {
70
- setPreview("");
71
- }
72
- }, [value]);
73
-
74
- const openCropper = (file: File) => {
75
- const reader = new FileReader();
76
- reader.onload = () => {
77
- setCropSrc(reader.result as string);
78
- setOpenCrop(true);
79
- };
80
- reader.readAsDataURL(file);
81
- };
82
-
83
- const onUpload = (e: React.ChangeEvent<HTMLInputElement>) => {
84
- const file = e.target.files?.[0];
85
- if (!file) return;
86
-
87
- const allowed = ["image/jpeg", "image/jpg", "image/png", "image/webp"];
88
- if (!allowed.includes(file.type)) {
89
- setInvalidMessage("Format gambar tidak diperbolehkan (JPG/PNG/WebP)");
90
- return;
91
- }
92
-
93
- openCropper(file);
94
- };
95
-
96
- const onCropDone = (file: File) => {
97
- const url = URL.createObjectURL(file);
98
- setPreview(url);
99
- onChange?.(file);
100
- setOpenCrop(false);
101
- };
102
-
103
- const onCropCancel = () => {
104
- setOpenCrop(false);
105
- inputRef.current!.value = "";
106
- };
107
-
108
- const remove = () => {
109
- setPreview("");
110
- onChange?.(null);
111
- inputRef.current && (inputRef.current.value = "");
112
- };
113
-
114
- const onDropFile = (e: React.DragEvent<HTMLDivElement>) => {
115
- e.preventDefault();
116
- setDrag(false);
117
-
118
- const file = e.dataTransfer.files?.[0];
119
- file && openCropper(file);
120
- };
121
-
122
- return (
123
- <div className="w-full relative">
124
- {label && (
125
- <label
126
- htmlFor={randomId}
127
- className={cn(
128
- "input-label",
129
- pcn<CT>(className, "label"),
130
- disabled && "opacity-50",
131
- inputHandler.focus && "text-primary",
132
- !!invalidMessage && "text-danger",
133
- )}
134
- >
135
- {label}
136
- {validations && validation.hasRules(validations, "required") && <span className="text-danger ml-1">*</span>}
137
- </label>
138
- )}
139
-
140
- {tip && (
141
- <small
142
- className={cn(
143
- "input-tip",
144
- pcn<CT>(className, "tip"),
145
- disabled && "opacity-60",
146
- )}
147
- >{tip}</small>
148
- )}
149
-
150
- <label htmlFor={randomId}>
151
- <div
152
- className={cn(
153
- "border-2 border-dashed rounded-xl p-2 w-full bg-background cursor-pointer overflow-hidden",
154
- drag ? "border-primary" : "border-gray-300",
155
- invalidMessage && "border-danger",
156
- pcn<CT>(className, "input")
157
- )}
158
- style={{
159
- aspectRatio: aspect,
160
- backgroundImage: preview ? `url(${preview})` : undefined,
161
- backgroundSize: "cover",
162
- backgroundPosition: "center",
163
- }}
164
- onDragOver={(e) => e.preventDefault()}
165
- onDragEnter={(e) => {
166
- e.preventDefault();
167
- setDrag(true);
168
- }}
169
- onDragLeave={() => setDrag(false)}
170
- onDrop={onDropFile}
171
- >
172
- <div className="absolute top-1/2 left-1/2 -translate-1/2 flex flex-col items-center text-light">
173
- <FontAwesomeIcon icon={drag ? faHandHolding : faImages} className="text-3xl" />
174
- <p className="text-xs text-center mt-4">{drag ? "Letakkan di sini" : preview ? "Klik atau seret untuk ganti Gambar" : "Klik atau seret gambar"}</p>
175
- </div>
176
-
177
- <input
178
- id={randomId}
179
- ref={inputRef}
180
- type="file"
181
- accept="image/*"
182
- className="hidden"
183
- disabled={disabled}
184
- onChange={onUpload}
185
- />
186
- </div>
187
- </label>
188
-
189
- {preview && !disabled && (
190
- <IconButtonComponent
191
- icon={faTimes}
192
- paint="danger"
193
- size="sm"
194
- className="absolute top-10 right-4"
195
- onClick={remove}
196
- />
197
- )}
198
-
199
- {invalidMessage && (
200
- <small className={cn("input-error-message", pcn<CT>(className, "error"))}>
201
- {invalidMessage}
202
- </small>
203
- )}
204
-
205
- {!isSm ? (
206
- <ModalComponent show={openCrop} onClose={onCropCancel} title="Sesuaikan Gambar" className="w-max max-w-[350px]">
207
- {cropSrc && (
208
- <div className="p-4">
209
- <CanvasCropper
210
- src={cropSrc}
211
- aspect={eval(aspect.replace(":", "/"))}
212
- onDone={onCropDone}
213
- />
214
- </div>
215
- )}
216
- </ModalComponent>
217
- ) : (
218
- <BottomSheetComponent show={openCrop} onClose={onCropCancel} size={400}>
219
- {cropSrc && (
220
- <div className="p-4">
221
- <CanvasCropper
222
- src={cropSrc}
223
- aspect={eval(aspect.replace(":", "/"))}
224
- onDone={onCropDone}
225
- />
226
- </div>
227
- )}
228
- </BottomSheetComponent>
229
- )}
230
-
231
- </div>
232
- );
233
- };
234
-
235
-
236
-
237
- interface CropperProps {
238
- src : string;
239
- aspect : number;
240
- onDone ?: (file: File) => void;
241
- }
242
-
243
- export const CanvasCropper: React.FC<CropperProps> = ({
244
- src,
245
- aspect,
246
- onDone,
247
- }) => {
248
- const canvasRef = useRef<HTMLCanvasElement>(null);
249
- const previewRef = useRef<HTMLCanvasElement>(null);
250
- const pinchDistRef = useRef(0);
251
- const pinchStartZoomRef = useRef(1);
252
-
253
- const [img, setImg] = useState<HTMLImageElement | null>(null);
254
- const [zoom, setZoom] = useState(1);
255
- const [minZoom, setMinZoom] = useState(1);
256
- const [maxZoom, setMaxZoom] = useState(4);
257
- const [pos, setPos] = useState({ x: 0, y: 0 });
258
- const [dragging, setDragging] = useState(false);
259
- const [start, setStart] = useState({ x: 0, y: 0 });
260
-
261
- const CROP_SIZE = 280;
262
- const CROP_W = CROP_SIZE * aspect;
263
-
264
- const clamp = (v: number, min: number, max: number) => Math.max(min, Math.min(max, v));
265
-
266
- useEffect(() => {
267
- const i = new Image();
268
- i.onload = () => setImg(i);
269
- i.src = src;
270
- }, [src]);
271
-
272
- const renderCanvas = () => {
273
- if (!img) return;
274
-
275
- const canvas = canvasRef.current!;
276
- const ctx = canvas.getContext("2d")!;
277
-
278
- canvas.width = CROP_W;
279
- canvas.height = CROP_SIZE;
280
-
281
- ctx.clearRect(0, 0, canvas.width, canvas.height);
282
-
283
- const scaledW = img.width * zoom;
284
- const scaledH = img.height * zoom;
285
-
286
- const x = pos.x - scaledW / 2 + CROP_W / 2;
287
- const y = pos.y - scaledH / 2 + CROP_SIZE / 2;
288
-
289
- ctx.drawImage(img, x, y, scaledW, scaledH);
290
- };
291
-
292
- useEffect(() => {
293
- renderCanvas();
294
- }, [img, zoom, pos]);
295
-
296
- useEffect(() => {
297
- if (!img) return;
298
-
299
- const imgW = img.naturalWidth;
300
- const imgH = img.naturalHeight;
301
-
302
- const scaleW = CROP_W / imgW;
303
- const scaleH = CROP_SIZE / imgH;
304
-
305
- const base = Math.max(scaleW, scaleH);
306
-
307
- setMinZoom(base);
308
- setZoom(base);
309
- setMaxZoom(base * 4);
310
-
311
- }, [img]);
312
-
313
- const handleDown = (e: React.MouseEvent) => {
314
- setDragging(true);
315
- setStart({ x: e.clientX, y: e.clientY });
316
- };
317
-
318
- const handleUp = () => setDragging(false);
319
-
320
- const handleMove = (e: React.MouseEvent) => {
321
- if (!dragging) return;
322
- const dx = e.clientX - start.x;
323
- const dy = e.clientY - start.y;
324
-
325
- setStart({ x: e.clientX, y: e.clientY });
326
- setPos((p) => {
327
- const scaledW = img!.naturalWidth * zoom;
328
- const scaledH = img!.naturalHeight * zoom;
329
-
330
- const minX = (scaledW - CROP_W) / 2;
331
- const maxX = -(scaledW - CROP_W) / 2;
332
- const minY = (scaledH - CROP_SIZE) / 2;
333
- const maxY = -(scaledH - CROP_SIZE) / 2;
334
-
335
- return {
336
- x: clamp(p.x + dx, maxX, minX),
337
- y: clamp(p.y + dy, maxY, minY),
338
- };
339
- });
340
- };
341
-
342
- const performCrop = () => {
343
- if (!img) return;
344
-
345
- const preview = previewRef.current!;
346
- const pctx = preview.getContext("2d")!;
347
-
348
- preview.width = CROP_W;
349
- preview.height = CROP_SIZE;
350
-
351
- const scaledW = img.width * zoom;
352
- const scaledH = img.height * zoom;
353
-
354
- const x = pos.x - scaledW / 2 + CROP_W / 2;
355
- const y = pos.y - scaledH / 2 + CROP_SIZE / 2;
356
-
357
- pctx.drawImage(img, x, y, scaledW, scaledH);
358
-
359
- preview.toBlob((blob) => {
360
- const file = new File([blob!], "cropped.png", { type: "image/png" });
361
- onDone?.(file);
362
- });
363
- };
364
-
365
-
366
- const handleWheel = (e: React.WheelEvent) => {
367
- e.preventDefault();
368
-
369
- setZoom((z) => {
370
- let next = z - e.deltaY * 0.002;
371
- next = Math.max(minZoom, Math.min(maxZoom, next));
372
-
373
- const scaledW = img!.naturalWidth * next;
374
- const scaledH = img!.naturalHeight * next;
375
-
376
- const minX = (scaledW - CROP_W) / 2;
377
- const maxX = -(scaledW - CROP_W) / 2;
378
-
379
- const minY = (scaledH - CROP_SIZE) / 2;
380
- const maxY = -(scaledH - CROP_SIZE) / 2;
381
-
382
- setPos((p) => ({
383
- x: clamp(p.x, maxX, minX),
384
- y: clamp(p.y, maxY, minY),
385
- }));
386
-
387
- return next;
388
- });
389
- };
390
-
391
-
392
- const handleTouchStart = (e: React.TouchEvent) => {
393
- if (e.touches.length === 2) {
394
- const t1 = e.touches[0];
395
- const t2 = e.touches[1];
396
-
397
- const dist = Math.hypot(
398
- t2.clientX - t1.clientX,
399
- t2.clientY - t1.clientY
400
- );
401
-
402
- pinchDistRef.current = dist;
403
- pinchStartZoomRef.current = zoom;
404
-
405
- e.preventDefault();
406
- }
407
-
408
- // Jika satu jari → drag
409
- if (e.touches.length === 1) {
410
- setDragging(true);
411
- setStart({
412
- x: e.touches[0].clientX,
413
- y: e.touches[0].clientY,
414
- });
415
- }
416
- };
417
-
418
-
419
- const handleTouchMove = (e: React.TouchEvent) => {
420
- if (e.touches.length === 2) {
421
- const t1 = e.touches[0];
422
- const t2 = e.touches[1];
423
- const currDist = Math.hypot(t2.clientX - t1.clientX, t2.clientY - t1.clientY);
424
-
425
- const diff = currDist - pinchDistRef.current;
426
- let nextZoom = pinchStartZoomRef.current + diff * 0.005;
427
-
428
- nextZoom = Math.max(minZoom, Math.min(maxZoom, nextZoom));
429
-
430
- setZoom(nextZoom);
431
-
432
- setPos((p) => {
433
- const scaledW = img!.naturalWidth * nextZoom;
434
- const scaledH = img!.naturalHeight * nextZoom;
435
-
436
- const minX = (scaledW - CROP_W) / 2;
437
- const maxX = -(scaledW - CROP_W) / 2;
438
-
439
- const minY = (scaledH - CROP_SIZE) / 2;
440
- const maxY = -(scaledH - CROP_SIZE) / 2;
441
-
442
- return {
443
- x: Math.max(maxX, Math.min(minX, p.x)),
444
- y: Math.max(maxY, Math.min(minY, p.y)),
445
- };
446
- });
447
-
448
- e.preventDefault();
449
- return;
450
- }
451
-
452
- if (dragging && e.touches.length === 1) {
453
- const { clientX, clientY } = e.touches[0];
454
-
455
- const dx = clientX - start.x;
456
- const dy = clientY - start.y;
457
-
458
- setStart({ x: clientX, y: clientY });
459
-
460
- setPos((p) => {
461
- const scaledW = img!.naturalWidth * zoom;
462
- const scaledH = img!.naturalHeight * zoom;
463
-
464
- const minX = (scaledW - CROP_W) / 2;
465
- const maxX = -(scaledW - CROP_W) / 2;
466
-
467
- const minY = (scaledH - CROP_SIZE) / 2;
468
- const maxY = -(scaledH - CROP_SIZE) / 2;
469
-
470
- return {
471
- x: Math.max(maxX, Math.min(minX, p.x + dx)),
472
- y: Math.max(maxY, Math.min(minY, p.y + dy)),
473
- };
474
- });
475
-
476
- e.preventDefault();
477
- }
478
- };
479
-
480
-
481
- const handleTouchEnd = () => {
482
- setDragging(false);
483
- pinchDistRef.current = 0;
484
- };
485
-
486
- return (
487
- <div style={{ touchAction: "none" }}>
488
- <div
489
- className="relative bg-background rounded-lg overflow-hidden mx-auto"
490
- style={{ width: CROP_W, height: CROP_SIZE }}
491
- onMouseMove={handleMove}
492
- onMouseUp={handleUp}
493
- onMouseLeave={handleUp}
494
- onWheel={handleWheel}
495
- onTouchStart={handleTouchStart}
496
- onTouchMove={handleTouchMove}
497
- onTouchEnd={handleTouchEnd}
498
- >
499
- <canvas
500
- ref={canvasRef}
501
- width={CROP_W}
502
- height={CROP_SIZE}
503
- onMouseDown={handleDown}
504
- className="cursor-move"
505
- />
506
-
507
- <div className="absolute top-0 left-0 pointer-events-none" style={{ width: CROP_W, height: CROP_SIZE }}>
508
- <div className="absolute inset-0 border-2 border-slate-200"></div>
509
- <div className="absolute inset-0">
510
- <div className="absolute top-1/3 left-0 w-full border-t border-slate-200"></div>
511
- <div className="absolute top-2/3 left-0 w-full border-t border-slate-200"></div>
512
- <div className="absolute left-1/3 top-0 h-full border-l border-slate-200"></div>
513
- <div className="absolute left-2/3 top-0 h-full border-l border-slate-200"></div>
514
- </div>
515
- </div>
516
- </div>
517
-
518
- <div className="p-4 pb-2">
519
- <ButtonComponent
520
- label="Selesai"
521
- variant="outline"
522
- onClick={performCrop}
523
- block
524
- />
525
- </div>
526
-
527
- <canvas ref={previewRef} className="hidden" />
528
- </div>
529
- );
530
- };
531
-
532
-
533
-