@skalfa/skalfa-app 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +44 -0
- package/README.md +28 -0
- package/app/auth/edit/page.tsx +65 -0
- package/app/auth/login/page.tsx +63 -0
- package/app/auth/me/page.tsx +58 -0
- package/app/auth/register/page.tsx +69 -0
- package/app/auth/verify/page.tsx +53 -0
- package/app/dashboard/layout.tsx +47 -0
- package/app/dashboard/page.tsx +9 -0
- package/app/dashboard/user/page.tsx +77 -0
- package/app/index.ts +14 -0
- package/app/layout.tsx +38 -0
- package/app/page.tsx +13 -0
- package/barrels.json +6 -0
- package/blueprints/starter.blueprint.json +103 -0
- package/components/base.components/accordion/Accordion.component.tsx +82 -0
- package/components/base.components/breadcrumb/Breadcrumb.component.tsx +80 -0
- package/components/base.components/button/Button.component.tsx +91 -0
- package/components/base.components/button/IconButton.component.tsx +88 -0
- package/components/base.components/button/button.decorate.ts +82 -0
- package/components/base.components/card/AlertCard.component.tsx +69 -0
- package/components/base.components/card/Card.component.tsx +25 -0
- package/components/base.components/card/DashboardCard.component.tsx +44 -0
- package/components/base.components/card/GalleryCard.component.tsx +50 -0
- package/components/base.components/card/ProductCard.component.tsx +65 -0
- package/components/base.components/card/ProfileCard.component.tsx +71 -0
- package/components/base.components/carousel/Carousel.component.tsx +113 -0
- package/components/base.components/chip/Chip.component.tsx +39 -0
- package/components/base.components/document/DocumentViewer.component.tsx +164 -0
- package/components/base.components/document/ExportExcel.component.tsx +340 -0
- package/components/base.components/document/ImportExcel.component.tsx +315 -0
- package/components/base.components/document/PrintTable.component.tsx +204 -0
- package/components/base.components/document/RenderPDF.component.tsx +416 -0
- package/components/base.components/index.ts +85 -0
- package/components/base.components/input/Checkbox.component.tsx +109 -0
- package/components/base.components/input/Input.component.tsx +332 -0
- package/components/base.components/input/InputCheckbox.component.tsx +174 -0
- package/components/base.components/input/InputCurrency.component.tsx +163 -0
- package/components/base.components/input/InputDate.component.tsx +352 -0
- package/components/base.components/input/InputDatetime.component.tsx +260 -0
- package/components/base.components/input/InputDocument.component.tsx +352 -0
- package/components/base.components/input/InputImage.component.tsx +533 -0
- package/components/base.components/input/InputMap.component.tsx +318 -0
- package/components/base.components/input/InputNumber.component.tsx +192 -0
- package/components/base.components/input/InputOtp.component.tsx +169 -0
- package/components/base.components/input/InputPassword.component.tsx +236 -0
- package/components/base.components/input/InputRadio.component.tsx +175 -0
- package/components/base.components/input/InputTime.component.tsx +276 -0
- package/components/base.components/input/InputValues.component.tsx +68 -0
- package/components/base.components/input/Radio.component.tsx +102 -0
- package/components/base.components/input/Select.component.tsx +541 -0
- package/components/base.components/modal/BottomSheet.component.tsx +246 -0
- package/components/base.components/modal/FloatingPage.component.tsx +104 -0
- package/components/base.components/modal/Modal.component.tsx +96 -0
- package/components/base.components/modal/ModalConfirm.component.tsx +218 -0
- package/components/base.components/modal/Toast.component.tsx +126 -0
- package/components/base.components/nav/Bottombar.component.tsx +116 -0
- package/components/base.components/nav/Footer.component.tsx +144 -0
- package/components/base.components/nav/Headbar.component.tsx +104 -0
- package/components/base.components/nav/Navbar.component.tsx +100 -0
- package/components/base.components/nav/Sidebar.component.tsx +301 -0
- package/components/base.components/nav/Tabbar.component.tsx +60 -0
- package/components/base.components/nav/Wizard.component.tsx +73 -0
- package/components/base.components/supervision/FormSupervision.component.tsx +434 -0
- package/components/base.components/supervision/TableSupervision.component.tsx +697 -0
- package/components/base.components/table/ControlBar.component.tsx +497 -0
- package/components/base.components/table/FilterComponent.tsx +518 -0
- package/components/base.components/table/Pagination.component.tsx +159 -0
- package/components/base.components/table/Table.component.tsx +469 -0
- package/components/base.components/typography/TypographyArticle.component.tsx +26 -0
- package/components/base.components/typography/TypographyColumn.component.tsx +20 -0
- package/components/base.components/typography/TypographyContent.component.tsx +20 -0
- package/components/base.components/typography/TypographyTips.component.tsx +20 -0
- package/components/base.components/wrap/Draggable.component.tsx +303 -0
- package/components/base.components/wrap/IDBProvider.tsx +12 -0
- package/components/base.components/wrap/Image.component.tsx +10 -0
- package/components/base.components/wrap/OutsideClick.component.tsx +48 -0
- package/components/base.components/wrap/ScrollContainer.component.tsx +104 -0
- package/components/base.components/wrap/ShortcutProvider.tsx +57 -0
- package/components/base.components/wrap/Swipe.component.tsx +93 -0
- package/components/construct.components/example.tsx +1 -0
- package/components/construct.components/index.ts +5 -0
- package/components/index.ts +3 -0
- package/components/structure.components/example.tsx +1 -0
- package/components/structure.components/index.ts +5 -0
- package/contexts/AppProvider.tsx +12 -0
- package/contexts/Auth.context.tsx +64 -0
- package/contexts/Toggle.context.tsx +44 -0
- package/contexts/index.ts +7 -0
- package/eslint.config.mjs +34 -0
- package/langs/index.ts +1 -0
- package/langs/validation.langs.ts +17 -0
- package/next.config.ts +17 -0
- package/package.json +43 -0
- package/postcss.config.mjs +12 -0
- package/public/204.svg +19 -0
- package/public/500.svg +39 -0
- package/public/images/avatar.jpg +0 -0
- package/public/images/example.png +0 -0
- package/schema/idb/app.schema.ts +9 -0
- package/schema/index.ts +5 -0
- package/styles/globals.css +231 -0
- package/styles/tailwind.safelist +69 -0
- package/tailwind.config.ts +10 -0
- package/tsconfig.json +35 -0
- package/utils/commands/barrels.ts +28 -0
- package/utils/commands/blueprint.ts +421 -0
- package/utils/commands/light.ts +21 -0
- package/utils/commands/logger.ts +42 -0
- package/utils/commands/stubs/table-blueprint.stub +13 -0
- package/utils/commands/use-pdf.ts +29 -0
- package/utils/index.ts +3 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useRef, useEffect, useState, ReactNode, forwardRef, useImperativeHandle, CSSProperties } from 'react';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
type SpringConfig = {
|
|
8
|
+
stiffness ?: number;
|
|
9
|
+
damping ?: number;
|
|
10
|
+
mass ?: number;
|
|
11
|
+
stopThreshold ?: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type Bounds = {
|
|
15
|
+
left ?: number;
|
|
16
|
+
top ?: number;
|
|
17
|
+
right ?: number;
|
|
18
|
+
bottom ?: number;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type DragState = {
|
|
22
|
+
x : number;
|
|
23
|
+
y : number;
|
|
24
|
+
vx : number;
|
|
25
|
+
vy : number;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type DraggableProps = {
|
|
29
|
+
children ?: ReactNode;
|
|
30
|
+
className ?: string;
|
|
31
|
+
style ?: CSSProperties;
|
|
32
|
+
initial ?: { x?: number; y?: number };
|
|
33
|
+
bounds ?: Bounds;
|
|
34
|
+
spring ?: SpringConfig;
|
|
35
|
+
onDrag ?: (state: { x: number; y: number; vx: number; vy: number; dragging: boolean }) => void;
|
|
36
|
+
useTranslate3d ?: boolean;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// -----------------------------------------------------
|
|
40
|
+
// DraggableComponent
|
|
41
|
+
// -----------------------------------------------------
|
|
42
|
+
export const DraggableComponent = forwardRef(function DraggableComponent(
|
|
43
|
+
{
|
|
44
|
+
children,
|
|
45
|
+
className,
|
|
46
|
+
style,
|
|
47
|
+
initial = { x: 0, y: 0 },
|
|
48
|
+
bounds,
|
|
49
|
+
spring,
|
|
50
|
+
onDrag,
|
|
51
|
+
useTranslate3d = true,
|
|
52
|
+
}: DraggableProps,
|
|
53
|
+
ref
|
|
54
|
+
) {
|
|
55
|
+
const elRef = useRef<HTMLDivElement | null>(null);
|
|
56
|
+
const frameRef = useRef<number | null>(null);
|
|
57
|
+
const draggingRef = useRef(false);
|
|
58
|
+
const pointerIdRef = useRef<number | null>(null);
|
|
59
|
+
const stateRef = useRef<DragState>({ x: initial.x || 0, y: initial.y || 0, vx: 0, vy: 0 });
|
|
60
|
+
const targetRef = useRef<{ x: number; y: number }>({ x: initial.x || 0, y: initial.y || 0 });
|
|
61
|
+
|
|
62
|
+
const historyRef = useRef<Array<{ t: number; x: number; y: number }>>([]);
|
|
63
|
+
|
|
64
|
+
const cfg: Required<SpringConfig> = {
|
|
65
|
+
stiffness : spring?.stiffness ?? 180,
|
|
66
|
+
damping : spring?.damping ?? 24,
|
|
67
|
+
mass : spring?.mass ?? 1,
|
|
68
|
+
stopThreshold : spring?.stopThreshold ?? 0.02,
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const [, setTick] = useState(0);
|
|
72
|
+
|
|
73
|
+
const now = () => performance.now();
|
|
74
|
+
|
|
75
|
+
function applyStyle(x: number, y: number) {
|
|
76
|
+
const el = elRef.current;
|
|
77
|
+
if (!el) return;
|
|
78
|
+
const transform = useTranslate3d ? `translate3d(${x}px, ${y}px, 0)` : `translate(${x}px, ${y}px)`;
|
|
79
|
+
el.style.transform = transform;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function clampToBounds(x: number, y: number) {
|
|
83
|
+
if (!bounds) return { x, y };
|
|
84
|
+
return {
|
|
85
|
+
x: Math.max(bounds.left ?? -Infinity, Math.min(x, bounds.right ?? Infinity)),
|
|
86
|
+
y: Math.max(bounds.top ?? -Infinity, Math.min(y, bounds.bottom ?? Infinity)),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function estimateVelocity() {
|
|
91
|
+
const h = historyRef.current;
|
|
92
|
+
if (h.length < 2) return { vx: 0, vy: 0 };
|
|
93
|
+
const last = h[h.length - 1];
|
|
94
|
+
const threshold = 50;
|
|
95
|
+
let idx = h.length - 2;
|
|
96
|
+
while (idx > 0 && last.t - h[idx].t < threshold) idx--;
|
|
97
|
+
const prev = h[idx];
|
|
98
|
+
const dt = Math.max(1, last.t - prev.t);
|
|
99
|
+
return {
|
|
100
|
+
vx: (last.x - prev.x) / (dt / 1000),
|
|
101
|
+
vy: (last.y - prev.y) / (dt / 1000),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function cancelFrame() {
|
|
106
|
+
if (frameRef.current != null) {
|
|
107
|
+
cancelAnimationFrame(frameRef.current);
|
|
108
|
+
frameRef.current = null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function startSpringAnimation(initVX = 0, initVY = 0) {
|
|
113
|
+
cancelFrame();
|
|
114
|
+
|
|
115
|
+
const mass = cfg.mass;
|
|
116
|
+
const k = cfg.stiffness;
|
|
117
|
+
const c = cfg.damping;
|
|
118
|
+
|
|
119
|
+
stateRef.current.vx = initVX;
|
|
120
|
+
stateRef.current.vy = initVY;
|
|
121
|
+
|
|
122
|
+
let lastTime = now();
|
|
123
|
+
|
|
124
|
+
function step() {
|
|
125
|
+
const t = now();
|
|
126
|
+
const dt = Math.min(32, t - lastTime) / 1000;
|
|
127
|
+
lastTime = t;
|
|
128
|
+
|
|
129
|
+
const sx = stateRef.current.x;
|
|
130
|
+
const sy = stateRef.current.y;
|
|
131
|
+
const vx = stateRef.current.vx;
|
|
132
|
+
const vy = stateRef.current.vy;
|
|
133
|
+
const tx = targetRef.current.x;
|
|
134
|
+
const ty = targetRef.current.y;
|
|
135
|
+
|
|
136
|
+
const ax = (-c * vx - k * (sx - tx)) / mass;
|
|
137
|
+
const ay = (-c * vy - k * (sy - ty)) / mass;
|
|
138
|
+
|
|
139
|
+
const nvx = vx + ax * dt;
|
|
140
|
+
const nvy = vy + ay * dt;
|
|
141
|
+
const nx = sx + nvx * dt;
|
|
142
|
+
const ny = sy + nvy * dt;
|
|
143
|
+
|
|
144
|
+
stateRef.current.x = nx;
|
|
145
|
+
stateRef.current.y = ny;
|
|
146
|
+
stateRef.current.vx = nvx;
|
|
147
|
+
stateRef.current.vy = nvy;
|
|
148
|
+
|
|
149
|
+
applyStyle(nx, ny);
|
|
150
|
+
onDrag?.({ x: nx, y: ny, vx: nvx, vy: nvy, dragging: false });
|
|
151
|
+
|
|
152
|
+
const disp = Math.hypot(nx - tx, ny - ty);
|
|
153
|
+
const vel = Math.hypot(nvx, nvy);
|
|
154
|
+
|
|
155
|
+
if (disp < cfg.stopThreshold && vel < cfg.stopThreshold) {
|
|
156
|
+
stateRef.current.x = tx;
|
|
157
|
+
stateRef.current.y = ty;
|
|
158
|
+
stateRef.current.vx = 0;
|
|
159
|
+
stateRef.current.vy = 0;
|
|
160
|
+
applyStyle(tx, ty);
|
|
161
|
+
onDrag?.({ x: tx, y: ty, vx: 0, vy: 0, dragging: false });
|
|
162
|
+
frameRef.current = null;
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
frameRef.current = requestAnimationFrame(step);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
frameRef.current = requestAnimationFrame(step);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// -------------------------------------------------------------------
|
|
173
|
+
// Expose API ke parent: setTarget & setPositionImmediate
|
|
174
|
+
// -------------------------------------------------------------------
|
|
175
|
+
useImperativeHandle(ref, () => ({
|
|
176
|
+
setTarget(pos: { x: number; y: number }) {
|
|
177
|
+
targetRef.current.x = pos.x;
|
|
178
|
+
targetRef.current.y = pos.y;
|
|
179
|
+
startSpringAnimation(0, 0);
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
setPosition(pos: { x: number; y: number }) {
|
|
183
|
+
stateRef.current.x = pos.x;
|
|
184
|
+
stateRef.current.y = pos.y;
|
|
185
|
+
targetRef.current.x = pos.x;
|
|
186
|
+
targetRef.current.y = pos.y;
|
|
187
|
+
applyStyle(pos.x, pos.y);
|
|
188
|
+
},
|
|
189
|
+
}));
|
|
190
|
+
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
const el = elRef.current;
|
|
193
|
+
if (!el) return;
|
|
194
|
+
|
|
195
|
+
function onDown(e: PointerEvent) {
|
|
196
|
+
if (e.pointerType === 'mouse' && e.button !== 0) return;
|
|
197
|
+
|
|
198
|
+
(e.target as Element).setPointerCapture?.(e.pointerId);
|
|
199
|
+
pointerIdRef.current = e.pointerId;
|
|
200
|
+
draggingRef.current = true;
|
|
201
|
+
cancelFrame();
|
|
202
|
+
|
|
203
|
+
historyRef.current = [{ t: now(), x: stateRef.current.x, y: stateRef.current.y }];
|
|
204
|
+
|
|
205
|
+
(el as any).__dragBase = {
|
|
206
|
+
px: e.clientX,
|
|
207
|
+
py: e.clientY,
|
|
208
|
+
startX: stateRef.current.x,
|
|
209
|
+
startY: stateRef.current.y,
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
onDrag?.({
|
|
213
|
+
x: stateRef.current.x,
|
|
214
|
+
y: stateRef.current.y,
|
|
215
|
+
vx: 0,
|
|
216
|
+
vy: 0,
|
|
217
|
+
dragging: true,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function onMove(e: PointerEvent) {
|
|
222
|
+
if (!draggingRef.current) return;
|
|
223
|
+
if (pointerIdRef.current !== null && e.pointerId !== pointerIdRef.current) return;
|
|
224
|
+
|
|
225
|
+
const base = (el as any).__dragBase;
|
|
226
|
+
if (!base) return;
|
|
227
|
+
|
|
228
|
+
let nx = base.startX + (e.clientX - base.px);
|
|
229
|
+
let ny = base.startY + (e.clientY - base.py);
|
|
230
|
+
|
|
231
|
+
({ x: nx, y: ny } = clampToBounds(nx, ny));
|
|
232
|
+
|
|
233
|
+
historyRef.current.push({ t: now(), x: nx, y: ny });
|
|
234
|
+
if (historyRef.current.length > 8) historyRef.current.shift();
|
|
235
|
+
|
|
236
|
+
stateRef.current.x = nx;
|
|
237
|
+
stateRef.current.y = ny;
|
|
238
|
+
stateRef.current.vx = 0;
|
|
239
|
+
stateRef.current.vy = 0;
|
|
240
|
+
|
|
241
|
+
applyStyle(nx, ny);
|
|
242
|
+
onDrag?.({ x: nx, y: ny, vx: 0, vy: 0, dragging: true });
|
|
243
|
+
|
|
244
|
+
setTick(t => t + 1);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function onUp(e: PointerEvent) {
|
|
248
|
+
if (!draggingRef.current) return;
|
|
249
|
+
if (pointerIdRef.current !== null && e.pointerId !== pointerIdRef.current) return;
|
|
250
|
+
|
|
251
|
+
(e.target as Element).releasePointerCapture?.(e.pointerId);
|
|
252
|
+
draggingRef.current = false;
|
|
253
|
+
pointerIdRef.current = null;
|
|
254
|
+
|
|
255
|
+
const { vx, vy } = estimateVelocity();
|
|
256
|
+
|
|
257
|
+
let tx = stateRef.current.x;
|
|
258
|
+
let ty = stateRef.current.y;
|
|
259
|
+
({ x: tx, y: ty } = clampToBounds(tx, ty));
|
|
260
|
+
|
|
261
|
+
targetRef.current.x = tx;
|
|
262
|
+
targetRef.current.y = ty;
|
|
263
|
+
|
|
264
|
+
startSpringAnimation(vx, vy);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
el.addEventListener('pointerdown', onDown as EventListener);
|
|
268
|
+
window.addEventListener('pointermove', onMove as EventListener);
|
|
269
|
+
window.addEventListener('pointerup', onUp as EventListener);
|
|
270
|
+
window.addEventListener('pointercancel', onUp as EventListener);
|
|
271
|
+
|
|
272
|
+
return () => {
|
|
273
|
+
el.removeEventListener('pointerdown', onDown as EventListener);
|
|
274
|
+
window.removeEventListener('pointermove', onMove as EventListener);
|
|
275
|
+
window.removeEventListener('pointerup', onUp as EventListener);
|
|
276
|
+
window.removeEventListener('pointercancel', onUp as EventListener);
|
|
277
|
+
cancelFrame();
|
|
278
|
+
};
|
|
279
|
+
}, [bounds]);
|
|
280
|
+
|
|
281
|
+
// initial pos
|
|
282
|
+
useEffect(() => {
|
|
283
|
+
stateRef.current.x = initial.x || 0;
|
|
284
|
+
stateRef.current.y = initial.y || 0;
|
|
285
|
+
applyStyle(initial.x || 0, initial.y || 0);
|
|
286
|
+
}, []);
|
|
287
|
+
|
|
288
|
+
return (
|
|
289
|
+
<div
|
|
290
|
+
ref={elRef}
|
|
291
|
+
className={className}
|
|
292
|
+
style={{
|
|
293
|
+
touchAction: 'none',
|
|
294
|
+
cursor: 'grab',
|
|
295
|
+
display: 'inline-block',
|
|
296
|
+
...style,
|
|
297
|
+
}}
|
|
298
|
+
onMouseDown={(e) => e.preventDefault()}
|
|
299
|
+
>
|
|
300
|
+
{children}
|
|
301
|
+
</div>
|
|
302
|
+
);
|
|
303
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useEffect } from "react"
|
|
4
|
+
import { idb } from "@skalfa/skalfa-idb"
|
|
5
|
+
import { AppSchema } from "@schema"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export function IDBProvider({ children }: { children: React.ReactNode }) {
|
|
9
|
+
useEffect(() => idb.setDefaultSchema(AppSchema), [])
|
|
10
|
+
|
|
11
|
+
return <>{children}</>
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* eslint-disable jsx-a11y/alt-text */
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import Image, { ImageProps } from "next/image";
|
|
5
|
+
|
|
6
|
+
export function ImageComponent(props: ImageProps) {
|
|
7
|
+
const isProd = process.env.NODE_ENV === "production";
|
|
8
|
+
|
|
9
|
+
return <Image {...props} unoptimized={!isProd} />;
|
|
10
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { FC, ReactNode, useEffect, useRef } from "react";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export interface OutsideClickHandlerProps {
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
onOutsideClick?: () => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export const OutsideClickComponent: FC<OutsideClickHandlerProps> = ({
|
|
15
|
+
children,
|
|
16
|
+
onOutsideClick,
|
|
17
|
+
}) => {
|
|
18
|
+
const ref = useRef<HTMLDivElement | null>(null);
|
|
19
|
+
const handlerRef = useRef(onOutsideClick);
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
handlerRef.current = onOutsideClick;
|
|
23
|
+
}, [onOutsideClick]);
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const handlePointerDown = (event: PointerEvent) => {
|
|
27
|
+
const el = ref.current;
|
|
28
|
+
if (!el || !(event.target instanceof Node)) return;
|
|
29
|
+
|
|
30
|
+
const isOutside = !el.contains(event.target);
|
|
31
|
+
|
|
32
|
+
if (isOutside) {
|
|
33
|
+
queueMicrotask(() => {
|
|
34
|
+
if (ref.current && !ref.current.contains(event.target as Node)) {
|
|
35
|
+
handlerRef.current?.();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
document.addEventListener("pointerdown", handlePointerDown, true);
|
|
42
|
+
return () => {
|
|
43
|
+
document.removeEventListener("pointerdown", handlePointerDown, true);
|
|
44
|
+
};
|
|
45
|
+
}, []);
|
|
46
|
+
|
|
47
|
+
return <div ref={ref}>{children}</div>;
|
|
48
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { cn, pcn } from "@utils";
|
|
4
|
+
import { useRef, useState, useEffect, ReactNode } from "react";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
type CT = "base" | "container" | "floating-scroll";
|
|
9
|
+
|
|
10
|
+
export interface ScrollContainerProps {
|
|
11
|
+
children : ReactNode;
|
|
12
|
+
footer ?: ReactNode;
|
|
13
|
+
scrollFloating ?: boolean;
|
|
14
|
+
onScroll ?: (e: any) => void;
|
|
15
|
+
|
|
16
|
+
/** Use custom class with: "container::", "floating-scroll::"". */
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export function ScrollContainerComponent({
|
|
23
|
+
children,
|
|
24
|
+
footer,
|
|
25
|
+
className = "",
|
|
26
|
+
scrollFloating = false,
|
|
27
|
+
onScroll,
|
|
28
|
+
}: ScrollContainerProps) {
|
|
29
|
+
const containerRef = useRef<HTMLDivElement | null>(null);
|
|
30
|
+
const floatingScrollbarRef = useRef<HTMLDivElement | null>(null);
|
|
31
|
+
const floatingScrollbarContainerRef = useRef<HTMLDivElement | null>(null);
|
|
32
|
+
const [containerWidth, setContainerWidth] = useState(0);
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const handleScroll = () => {
|
|
36
|
+
if (!containerRef.current) return;
|
|
37
|
+
onScroll?.(containerRef.current);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const container = containerRef.current;
|
|
41
|
+
if (container) {
|
|
42
|
+
handleScroll();
|
|
43
|
+
container.addEventListener("scroll", handleScroll);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return () => container?.removeEventListener("scroll", handleScroll);
|
|
47
|
+
}, []);
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const scrollContainer = containerRef.current;
|
|
51
|
+
const floatingScrollbar = floatingScrollbarRef.current;
|
|
52
|
+
|
|
53
|
+
if (!scrollContainer || !floatingScrollbar) return;
|
|
54
|
+
|
|
55
|
+
const syncScroll = () => floatingScrollbar.scrollLeft = scrollContainer.scrollLeft;
|
|
56
|
+
const syncScrollReverse = () => scrollContainer.scrollLeft = floatingScrollbar.scrollLeft;
|
|
57
|
+
|
|
58
|
+
scrollContainer.addEventListener("scroll", syncScroll);
|
|
59
|
+
floatingScrollbar.addEventListener("scroll", syncScrollReverse);
|
|
60
|
+
|
|
61
|
+
return () => {
|
|
62
|
+
scrollContainer.removeEventListener("scroll", syncScroll);
|
|
63
|
+
floatingScrollbar.removeEventListener("scroll", syncScrollReverse);
|
|
64
|
+
};
|
|
65
|
+
}, []);
|
|
66
|
+
|
|
67
|
+
const handleResize = () => {
|
|
68
|
+
if (containerRef.current) setContainerWidth(containerRef.current.offsetWidth);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
handleResize();
|
|
73
|
+
window.addEventListener("resize", handleResize);
|
|
74
|
+
|
|
75
|
+
return () => window.removeEventListener("resize", handleResize);
|
|
76
|
+
}, []);
|
|
77
|
+
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (floatingScrollbarContainerRef.current) floatingScrollbarContainerRef.current.style.width = `${containerWidth}px`;
|
|
80
|
+
}, [containerWidth]);
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<div className={cn("relative", pcn<CT>(className, "base"))}>
|
|
84
|
+
<div
|
|
85
|
+
ref={containerRef}
|
|
86
|
+
className={cn(
|
|
87
|
+
"w-full overflow-x-auto scroll",
|
|
88
|
+
scrollFloating && "scroll-none",
|
|
89
|
+
pcn<CT>(className, "container"),
|
|
90
|
+
)}
|
|
91
|
+
>
|
|
92
|
+
{children}
|
|
93
|
+
</div>
|
|
94
|
+
|
|
95
|
+
<div className="fixed bottom-0 py-1 bg-background w-full" ref={floatingScrollbarContainerRef}>
|
|
96
|
+
<div ref={floatingScrollbarRef} className={cn(scrollFloating ? "scroll overflow-x-auto overflow-y-hidden" : "")}>
|
|
97
|
+
<div className="h-0.5 opacity-0">{children}</div>
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
{footer}
|
|
101
|
+
</div>
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useEffect } from "react"
|
|
4
|
+
import { shortcut } from "@utils"
|
|
5
|
+
import { useToggleContext } from "@contexts"
|
|
6
|
+
import { ModalComponent } from "@components";
|
|
7
|
+
|
|
8
|
+
export function ShortcutProvider() {
|
|
9
|
+
const { setToggle, toggle } = useToggleContext();
|
|
10
|
+
const shortcuts = shortcut.list()
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
shortcut.init()
|
|
14
|
+
}, [])
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
shortcut.register("ctrl+/", () => {
|
|
18
|
+
setToggle("MODAL_SHORTCUT_HELP")
|
|
19
|
+
}, "List Shortcut")
|
|
20
|
+
}, [])
|
|
21
|
+
|
|
22
|
+
function formatShortcutKey(key: string) {
|
|
23
|
+
return key
|
|
24
|
+
.split("+")
|
|
25
|
+
.map(k => {
|
|
26
|
+
if (k === "ctrl") return "Ctrl"
|
|
27
|
+
if (k === "shift") return "Shift"
|
|
28
|
+
if (k === "alt") return "Alt"
|
|
29
|
+
if (k === "arrowup") return "↑"
|
|
30
|
+
if (k === "arrowdown") return "↓"
|
|
31
|
+
if (k === " ") return "SPACE"
|
|
32
|
+
return k.toUpperCase()
|
|
33
|
+
})
|
|
34
|
+
.join(" + ")
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<>
|
|
39
|
+
<ModalComponent
|
|
40
|
+
show={!!toggle["MODAL_SHORTCUT_HELP"]}
|
|
41
|
+
onClose={() => setToggle("MODAL_SHORTCUT_HELP")}
|
|
42
|
+
title="Shortcut"
|
|
43
|
+
>
|
|
44
|
+
<div className="p-4 grid grid-cols-2 gap-4">
|
|
45
|
+
{shortcuts.map(({ key, description }) => (
|
|
46
|
+
<>
|
|
47
|
+
<kbd className="px-2 py-1 border rounded bg-gray-100 w-max">
|
|
48
|
+
{formatShortcutKey(key)}
|
|
49
|
+
</kbd>
|
|
50
|
+
<span>: {description}</span>
|
|
51
|
+
</>
|
|
52
|
+
))}
|
|
53
|
+
</div>
|
|
54
|
+
</ModalComponent>
|
|
55
|
+
</>
|
|
56
|
+
)
|
|
57
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { ReactNode, useRef, useState } from 'react'
|
|
4
|
+
import { cn } from '@/utils';
|
|
5
|
+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export type SwipeActionType = {
|
|
9
|
+
label ?: string,
|
|
10
|
+
icon ?: any,
|
|
11
|
+
onAction ?: () => void;
|
|
12
|
+
className ?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type SwipeProps = {
|
|
16
|
+
leftActionControl ?: SwipeActionType;
|
|
17
|
+
rightActionControl ?: SwipeActionType;
|
|
18
|
+
children ?: ReactNode;
|
|
19
|
+
className ?: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function SwipeComponent({
|
|
23
|
+
leftActionControl,
|
|
24
|
+
rightActionControl,
|
|
25
|
+
children,
|
|
26
|
+
className,
|
|
27
|
+
} : SwipeProps) {
|
|
28
|
+
|
|
29
|
+
const startX = useRef(0);
|
|
30
|
+
const [offset, setOffset] = useState(0);
|
|
31
|
+
const [dragging, setDragging] = useState(false);
|
|
32
|
+
|
|
33
|
+
function onTouchStart(e: React.TouchEvent) {
|
|
34
|
+
setDragging(true);
|
|
35
|
+
startX.current = e.touches[0].clientX;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function onTouchMove(e: React.TouchEvent) {
|
|
39
|
+
if (!dragging) return;
|
|
40
|
+
|
|
41
|
+
const currentX = e.touches[0].clientX;
|
|
42
|
+
const delta = currentX - startX.current;
|
|
43
|
+
|
|
44
|
+
let allowed = delta;
|
|
45
|
+
|
|
46
|
+
// Jika tidak ada aksi kiri → larang geser ke kanan
|
|
47
|
+
if (!leftActionControl && delta > 0) allowed = 0;
|
|
48
|
+
|
|
49
|
+
// Jika tidak ada aksi kanan → larang geser ke kiri
|
|
50
|
+
if (!rightActionControl && delta < 0) allowed = 0;
|
|
51
|
+
|
|
52
|
+
// Batasi maksimal ±100px
|
|
53
|
+
allowed = Math.max(Math.min(allowed, 100), -100);
|
|
54
|
+
|
|
55
|
+
setOffset(allowed);
|
|
56
|
+
e.preventDefault();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function onTouchEnd() {
|
|
60
|
+
if (!dragging) return;
|
|
61
|
+
setDragging(false);
|
|
62
|
+
|
|
63
|
+
if (offset > 60 && leftActionControl) leftActionControl.onAction?.();
|
|
64
|
+
if (offset < -60 && rightActionControl) rightActionControl.onAction?.();
|
|
65
|
+
|
|
66
|
+
setOffset(0);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<div className="relative w-full overflow-hidden select-none">
|
|
71
|
+
<div className={cn("absolute h-full left-0 w-1/2 flex items-center px-5 gap-2 bg-light-warning text-warning", leftActionControl?.className)}>
|
|
72
|
+
<FontAwesomeIcon icon={leftActionControl?.icon} /> {leftActionControl?.label}
|
|
73
|
+
</div>
|
|
74
|
+
|
|
75
|
+
<div className={cn("absolute h-full right-0 w-1/2 flex justify-end items-center px-5 gap-2 bg-light-danger text-danger", rightActionControl?.className)}>
|
|
76
|
+
<FontAwesomeIcon icon={rightActionControl?.icon} /> {rightActionControl?.label}
|
|
77
|
+
</div>
|
|
78
|
+
|
|
79
|
+
<div
|
|
80
|
+
className={cn("relative z-10 bg-background", className)}
|
|
81
|
+
style={{
|
|
82
|
+
transform: `translateX(${offset}px)`,
|
|
83
|
+
transition: dragging ? "none" : "transform 0.2s ease",
|
|
84
|
+
}}
|
|
85
|
+
onTouchStart={onTouchStart}
|
|
86
|
+
onTouchMove={onTouchMove}
|
|
87
|
+
onTouchEnd={onTouchEnd}
|
|
88
|
+
>
|
|
89
|
+
{children}
|
|
90
|
+
</div>
|
|
91
|
+
</div>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const construct = () => ("");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const structure = () => ("");
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactNode } from 'react'
|
|
2
|
+
import { AuthContextProvider } from './Auth.context'
|
|
3
|
+
import { ToggleContextProvider } from './Toggle.context'
|
|
4
|
+
|
|
5
|
+
const registerProviders = [
|
|
6
|
+
AuthContextProvider,
|
|
7
|
+
ToggleContextProvider,
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
export function ContextAppProvider({ children }: { children: ReactNode }) {
|
|
11
|
+
return registerProviders.reduceRight((acc, Provider) => <Provider>{acc}</Provider>, children)
|
|
12
|
+
}
|