@skalfa/skalfa-component 1.0.38 → 1.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.
- package/dist/input/InputImage.component.js +1 -1
- package/dist/supervision/FormSupervision.component.d.ts +1 -1
- package/dist/supervision/FormSupervision.component.js +12 -9
- package/package.json +1 -1
- package/src/input/InputImage.component.tsx +1 -1
- package/src/supervision/FormSupervision.component.tsx +13 -12
|
@@ -99,7 +99,7 @@ const InputImageComponent = ({ name, label, tip, value, disabled, aspect, invali
|
|
|
99
99
|
}, onDragOver: (e) => e.preventDefault(), onDragEnter: (e) => {
|
|
100
100
|
e.preventDefault();
|
|
101
101
|
setDrag(true);
|
|
102
|
-
}, onDragLeave: () => setDrag(false), onDrop: onDropFile, children: [preview && !containerAspect ? ((0, jsx_runtime_1.jsxs)("div", { className: "relative group w-full h-full flex items-center justify-center", children: [(0, jsx_runtime_1.jsx)("img", { src: preview, alt: "Preview", className: "w-full h-auto max-h-[400px] object-contain rounded-lg" }), (0, jsx_runtime_1.jsxs)("div", { className: "absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 transition-opacity duration-200 flex flex-col items-center justify-center text-white rounded-lg", children: [(0, jsx_runtime_1.jsx)(skalfa_icon_1.Icon, { icon: "solid/images", className: "text-3xl mb-2" }), (0, jsx_runtime_1.jsx)("p", { className: "text-xs text-center", children: "Klik atau seret untuk ganti Gambar" })] })] })) : ((0, jsx_runtime_1.jsxs)("div", { className: "input-image-dropzone-content", children: [(0, jsx_runtime_1.jsx)(skalfa_icon_1.Icon, { icon: drag ? "solid/hand-holding" : "solid/images", className: "text-3xl" }), (0, jsx_runtime_1.jsx)("p", { className: "input-image-dropzone-text", children: drag ? "Letakkan di sini" : preview ? "Klik atau seret untuk ganti Gambar" : "Klik atau seret gambar" })] })), (0, jsx_runtime_1.jsx)("input", { id: randomId, ref: inputRef, type: "file", accept: "image/*", className: "hidden", disabled: disabled, onChange: onUpload })] }) }), preview && !disabled && ((0, jsx_runtime_1.jsx)(Button_component_1.ButtonComponent, { icon: "solid/times", paint: "danger", size: "sm", className: "absolute top-10 right-4", onClick: remove })), invalidMessage && ((0, jsx_runtime_1.jsx)("small", { className: (0, _utils_1.cn)("input-error-message", (0, _utils_1.pcn)(className, "error")), children: invalidMessage })), !isSm ? ((0, jsx_runtime_1.jsx)(Modal_component_1.ModalComponent, { show: openCrop, onClose: onCropCancel, title: "Sesuaikan Gambar", className: "w-max
|
|
102
|
+
}, onDragLeave: () => setDrag(false), onDrop: onDropFile, children: [preview && !containerAspect ? ((0, jsx_runtime_1.jsxs)("div", { className: "relative group w-full h-full flex items-center justify-center", children: [(0, jsx_runtime_1.jsx)("img", { src: preview, alt: "Preview", className: "w-full h-auto max-h-[400px] object-contain rounded-lg" }), (0, jsx_runtime_1.jsxs)("div", { className: "absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 transition-opacity duration-200 flex flex-col items-center justify-center text-white rounded-lg", children: [(0, jsx_runtime_1.jsx)(skalfa_icon_1.Icon, { icon: "solid/images", className: "text-3xl mb-2" }), (0, jsx_runtime_1.jsx)("p", { className: "text-xs text-center", children: "Klik atau seret untuk ganti Gambar" })] })] })) : ((0, jsx_runtime_1.jsxs)("div", { className: "input-image-dropzone-content", children: [(0, jsx_runtime_1.jsx)(skalfa_icon_1.Icon, { icon: drag ? "solid/hand-holding" : "solid/images", className: "text-3xl" }), (0, jsx_runtime_1.jsx)("p", { className: "input-image-dropzone-text", children: drag ? "Letakkan di sini" : preview ? "Klik atau seret untuk ganti Gambar" : "Klik atau seret gambar" })] })), (0, jsx_runtime_1.jsx)("input", { id: randomId, ref: inputRef, type: "file", accept: "image/*", className: "hidden", disabled: disabled, onChange: onUpload })] }) }), preview && !disabled && ((0, jsx_runtime_1.jsx)(Button_component_1.ButtonComponent, { icon: "solid/times", paint: "danger", size: "sm", className: "absolute top-10 right-4", onClick: remove })), invalidMessage && ((0, jsx_runtime_1.jsx)("small", { className: (0, _utils_1.cn)("input-error-message", (0, _utils_1.pcn)(className, "error")), children: invalidMessage })), !isSm ? ((0, jsx_runtime_1.jsx)(Modal_component_1.ModalComponent, { show: openCrop, onClose: onCropCancel, title: "Sesuaikan Gambar", className: "w-max", children: cropSrc && ((0, jsx_runtime_1.jsx)("div", { className: "p-4", children: (0, jsx_runtime_1.jsx)(exports.CanvasCropper, { src: cropSrc, aspect: eval(currentAspect.replace(":", "/")), onDone: onCropDone }) })) })) : ((0, jsx_runtime_1.jsx)(BottomSheet_component_1.BottomSheetComponent, { show: openCrop, onClose: onCropCancel, size: 400, children: cropSrc && ((0, jsx_runtime_1.jsx)("div", { className: "p-4", children: (0, jsx_runtime_1.jsx)(exports.CanvasCropper, { src: cropSrc, aspect: eval(currentAspect.replace(":", "/")), onDone: onCropDone }) })) }))] }));
|
|
103
103
|
};
|
|
104
104
|
exports.InputImageComponent = InputImageComponent;
|
|
105
105
|
const CanvasCropper = ({ src, aspect, onDone, }) => {
|
|
@@ -65,7 +65,7 @@ export interface FormType<T extends TypeKeys = keyof ConstructionMap> {
|
|
|
65
65
|
className?: string;
|
|
66
66
|
construction?: ConstructionMap[T];
|
|
67
67
|
type?: T;
|
|
68
|
-
onHide?: (values: Record<string, any
|
|
68
|
+
onHide?: (values: Record<string, any>, prefix?: string) => boolean;
|
|
69
69
|
onWatch?: (ctx: WatchContext) => WatchAction | undefined;
|
|
70
70
|
}
|
|
71
71
|
export interface formSupervisionProps {
|
|
@@ -106,15 +106,18 @@ function FormSupervisionComponent({ title, fields, submitControl, confirmation,
|
|
|
106
106
|
const GroupsFromDefaults = (defaults) => {
|
|
107
107
|
const groups = {};
|
|
108
108
|
Object.keys(defaults).forEach((key) => {
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
groups[groupKey]
|
|
109
|
+
const regex = /([a-zA-Z0-9_]+)\[(\d+)\]/g;
|
|
110
|
+
let match;
|
|
111
|
+
let currentPrefix = "";
|
|
112
|
+
while ((match = regex.exec(key)) !== null) {
|
|
113
|
+
const groupKey = currentPrefix ? `${currentPrefix}.${match[1]}` : match[1];
|
|
114
|
+
const index = parseInt(match[2], 10);
|
|
115
|
+
if (!groups[groupKey]) {
|
|
116
|
+
groups[groupKey] = new Set();
|
|
117
|
+
}
|
|
118
|
+
groups[groupKey].add(index);
|
|
119
|
+
currentPrefix = `${groupKey}[${index}]`;
|
|
116
120
|
}
|
|
117
|
-
groups[groupKey].add(index);
|
|
118
121
|
});
|
|
119
122
|
return Object.fromEntries(Object.entries(groups).map(([key, indexSet]) => [
|
|
120
123
|
key,
|
|
@@ -191,7 +194,7 @@ function FormSupervisionComponent({ title, fields, submitControl, confirmation,
|
|
|
191
194
|
const name = prefix ? `${prefix}.${form.construction?.name}` : form.construction?.name || "input_name";
|
|
192
195
|
const valMap = {};
|
|
193
196
|
values.forEach((v) => { valMap[v.name] = v.value; });
|
|
194
|
-
if (form?.onHide?.(valMap))
|
|
197
|
+
if (form?.onHide?.(valMap, prefix))
|
|
195
198
|
return null;
|
|
196
199
|
const ws = watchState[name];
|
|
197
200
|
if (ws?.hidden)
|
package/package.json
CHANGED
|
@@ -237,7 +237,7 @@ export const InputImageComponent: React.FC<InputImageProps> = ({
|
|
|
237
237
|
)}
|
|
238
238
|
|
|
239
239
|
{!isSm ? (
|
|
240
|
-
<ModalComponent show={openCrop} onClose={onCropCancel} title="Sesuaikan Gambar" className="w-max
|
|
240
|
+
<ModalComponent show={openCrop} onClose={onCropCancel} title="Sesuaikan Gambar" className="w-max">
|
|
241
241
|
{cropSrc && (
|
|
242
242
|
<div className="p-4">
|
|
243
243
|
<CanvasCropper
|
|
@@ -116,7 +116,7 @@ export interface FormType<T extends TypeKeys = keyof ConstructionMap> {
|
|
|
116
116
|
className ?: string;
|
|
117
117
|
construction ?: ConstructionMap[T];
|
|
118
118
|
type ?: T;
|
|
119
|
-
onHide ?: (values: Record<string, any
|
|
119
|
+
onHide ?: (values: Record<string, any>, prefix?: string) => boolean;
|
|
120
120
|
onWatch ?: (ctx: WatchContext) => WatchAction | undefined;
|
|
121
121
|
}
|
|
122
122
|
|
|
@@ -283,17 +283,18 @@ export function FormSupervisionComponent({
|
|
|
283
283
|
const groups: Record<string, Set<number>> = {};
|
|
284
284
|
|
|
285
285
|
Object.keys(defaults).forEach((key) => {
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
286
|
+
const regex = /([a-zA-Z0-9_]+)\[(\d+)\]/g;
|
|
287
|
+
let match;
|
|
288
|
+
let currentPrefix = "";
|
|
289
|
+
while ((match = regex.exec(key)) !== null) {
|
|
290
|
+
const groupKey = currentPrefix ? `${currentPrefix}.${match[1]}` : match[1];
|
|
291
|
+
const index = parseInt(match[2], 10);
|
|
292
|
+
if (!groups[groupKey]) {
|
|
293
|
+
groups[groupKey] = new Set();
|
|
294
|
+
}
|
|
295
|
+
groups[groupKey].add(index);
|
|
296
|
+
currentPrefix = `${groupKey}[${index}]`;
|
|
294
297
|
}
|
|
295
|
-
|
|
296
|
-
groups[groupKey].add(index);
|
|
297
298
|
});
|
|
298
299
|
|
|
299
300
|
return Object.fromEntries(
|
|
@@ -385,7 +386,7 @@ export function FormSupervisionComponent({
|
|
|
385
386
|
const valMap: Record<string, any> = {};
|
|
386
387
|
values.forEach((v) => { valMap[v.name] = v.value; });
|
|
387
388
|
|
|
388
|
-
if (form?.onHide?.(valMap)) return null;
|
|
389
|
+
if (form?.onHide?.(valMap, prefix)) return null;
|
|
389
390
|
|
|
390
391
|
const ws = watchState[name];
|
|
391
392
|
if (ws?.hidden) return null;
|