sales-frontend-components 0.0.39 → 0.0.41
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/camera/camera.module.scss +5 -0
- package/dist/index.cjs.js +84 -30
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +9 -7
- package/dist/index.esm.js +84 -30
- package/dist/index.esm.js.map +1 -1
- package/dist/modal/sample/test.module.scss +5 -0
- package/package.json +8 -8
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { flexRender, useReactTable, getSortedRowModel, getCoreRowModel, getPaginationRowModel } from '@tanstack/react-table';
|
|
3
|
-
import styles from './data-table/data-table.module.scss';
|
|
4
3
|
import { Table, DatePicker, SegmentGroup, FormField, Button, Icon } from 'sales-frontend-design-system';
|
|
4
|
+
import styles from './data-table/data-table.module.scss';
|
|
5
5
|
import React, { useState, useRef, useEffect, useCallback, useImperativeHandle } from 'react';
|
|
6
6
|
import { useController } from 'react-hook-form';
|
|
7
7
|
import styles$1 from './form/form-signautre/form-signature.module.scss';
|
|
@@ -324,9 +324,13 @@ const FormSignature = ({
|
|
|
324
324
|
const [currentStrokeLength, setCurrentStrokeLength] = useState(0);
|
|
325
325
|
useEffect(() => {
|
|
326
326
|
const canvas = canvasRef.current;
|
|
327
|
-
if (!canvas)
|
|
327
|
+
if (!canvas) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
328
330
|
const ctx = canvas.getContext("2d");
|
|
329
|
-
if (!ctx)
|
|
331
|
+
if (!ctx) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
330
334
|
ctx.strokeStyle = "#000000";
|
|
331
335
|
ctx.lineWidth = Math.max(1, canvasWidth / 400);
|
|
332
336
|
ctx.lineCap = "round";
|
|
@@ -346,7 +350,9 @@ const FormSignature = ({
|
|
|
346
350
|
}, [isDrawing]);
|
|
347
351
|
const getCanvasCoordinates = useCallback((e) => {
|
|
348
352
|
const canvas = canvasRef.current;
|
|
349
|
-
if (!canvas)
|
|
353
|
+
if (!canvas) {
|
|
354
|
+
return { x: 0, y: 0 };
|
|
355
|
+
}
|
|
350
356
|
const rect = canvas.getBoundingClientRect();
|
|
351
357
|
const scaleX = canvas.width / rect.width;
|
|
352
358
|
const scaleY = canvas.height / rect.height;
|
|
@@ -361,9 +367,13 @@ const FormSignature = ({
|
|
|
361
367
|
const startDrawing = useCallback(
|
|
362
368
|
(e) => {
|
|
363
369
|
const canvas = canvasRef.current;
|
|
364
|
-
if (!canvas)
|
|
370
|
+
if (!canvas) {
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
365
373
|
const ctx = canvas.getContext("2d");
|
|
366
|
-
if (!ctx)
|
|
374
|
+
if (!ctx) {
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
367
377
|
const { x, y } = getCanvasCoordinates(e);
|
|
368
378
|
setIsDrawing(true);
|
|
369
379
|
setIsMousePressed(true);
|
|
@@ -377,11 +387,17 @@ const FormSignature = ({
|
|
|
377
387
|
);
|
|
378
388
|
const draw = useCallback(
|
|
379
389
|
(e) => {
|
|
380
|
-
if (!isDrawing)
|
|
390
|
+
if (!isDrawing) {
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
381
393
|
const canvas = canvasRef.current;
|
|
382
|
-
if (!canvas)
|
|
394
|
+
if (!canvas) {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
383
397
|
const ctx = canvas.getContext("2d");
|
|
384
|
-
if (!ctx)
|
|
398
|
+
if (!ctx) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
385
401
|
const { x, y } = getCanvasCoordinates(e);
|
|
386
402
|
const currentPoint = { x, y };
|
|
387
403
|
if (lastPoint) {
|
|
@@ -411,9 +427,13 @@ const FormSignature = ({
|
|
|
411
427
|
(e) => {
|
|
412
428
|
if (isMousePressed && !isDrawing) {
|
|
413
429
|
const canvas = canvasRef.current;
|
|
414
|
-
if (!canvas)
|
|
430
|
+
if (!canvas) {
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
415
433
|
const ctx = canvas.getContext("2d");
|
|
416
|
-
if (!ctx)
|
|
434
|
+
if (!ctx) {
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
417
437
|
const { x, y } = getCanvasCoordinates(e);
|
|
418
438
|
setIsDrawing(true);
|
|
419
439
|
setLastPoint({ x, y });
|
|
@@ -431,9 +451,13 @@ const FormSignature = ({
|
|
|
431
451
|
}, [isDrawing]);
|
|
432
452
|
const clearSignature = useCallback(() => {
|
|
433
453
|
const canvas = canvasRef.current;
|
|
434
|
-
if (!canvas)
|
|
454
|
+
if (!canvas) {
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
435
457
|
const ctx = canvas.getContext("2d");
|
|
436
|
-
if (!ctx)
|
|
458
|
+
if (!ctx) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
437
461
|
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
|
|
438
462
|
setIsEmpty(true);
|
|
439
463
|
setSignatureData("");
|
|
@@ -491,7 +515,9 @@ const FormSignature = ({
|
|
|
491
515
|
};
|
|
492
516
|
}, [signatureData, isEmpty, totalLineLength, strokeLengths]);
|
|
493
517
|
const handleSubmit = useCallback(() => {
|
|
494
|
-
if (!validateForm())
|
|
518
|
+
if (!validateForm()) {
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
495
521
|
const data = getSignatureDataObject();
|
|
496
522
|
if (data) {
|
|
497
523
|
console.log("\uC81C\uCD9C\uB41C \uB370\uC774\uD130:", data);
|
|
@@ -503,7 +529,9 @@ const FormSignature = ({
|
|
|
503
529
|
onReset?.();
|
|
504
530
|
}, [clearSignature, onReset]);
|
|
505
531
|
const handleRecentSignatureLoad = useCallback(async () => {
|
|
506
|
-
if (!onRecentSignatureLoad)
|
|
532
|
+
if (!onRecentSignatureLoad) {
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
507
535
|
try {
|
|
508
536
|
setIsLoadingSignature(true);
|
|
509
537
|
const loadedSignature = await onRecentSignatureLoad();
|
|
@@ -640,10 +668,16 @@ const useFormSignature = ({ onSubmit, onError, onClear, minLength = 100 } = {})
|
|
|
640
668
|
}, []);
|
|
641
669
|
const isValid = useCallback(() => {
|
|
642
670
|
const basicValid = signatureRef.current?.isValid() ?? false;
|
|
643
|
-
if (!basicValid)
|
|
671
|
+
if (!basicValid) {
|
|
672
|
+
return false;
|
|
673
|
+
}
|
|
644
674
|
const data = signatureRef.current?.getSignatureData();
|
|
645
|
-
if (!data)
|
|
646
|
-
|
|
675
|
+
if (!data) {
|
|
676
|
+
return false;
|
|
677
|
+
}
|
|
678
|
+
if (isLoadedFromRecent) {
|
|
679
|
+
return true;
|
|
680
|
+
}
|
|
647
681
|
return data.totalLineLength >= minLength;
|
|
648
682
|
}, [minLength, isLoadedFromRecent]);
|
|
649
683
|
const getSignatureData = useCallback(() => {
|
|
@@ -720,7 +754,14 @@ const StepIndicator = ({
|
|
|
720
754
|
};
|
|
721
755
|
|
|
722
756
|
const cx = classNames.bind(styles$3);
|
|
723
|
-
function
|
|
757
|
+
function Attachment({
|
|
758
|
+
photos,
|
|
759
|
+
onAddPhoto,
|
|
760
|
+
onRemovePhoto,
|
|
761
|
+
show,
|
|
762
|
+
type = "multiple",
|
|
763
|
+
buttonText
|
|
764
|
+
}) {
|
|
724
765
|
const handleAddPhoto = () => {
|
|
725
766
|
onAddPhoto();
|
|
726
767
|
};
|
|
@@ -731,7 +772,7 @@ function Attachement({ photos, onAddPhoto, onRemovePhoto, show, type = "multiple
|
|
|
731
772
|
if (photos.length === 0) {
|
|
732
773
|
return /* @__PURE__ */ jsx("div", { className: cx("single-photo-item", "add-photo-item"), children: /* @__PURE__ */ jsxs("button", { className: cx("add-photo-button-single"), onClick: handleAddPhoto, children: [
|
|
733
774
|
/* @__PURE__ */ jsx(Icon, { name: "illust/camera" }),
|
|
734
|
-
/* @__PURE__ */ jsx("span", { children: "\uC0AC\uC9C4 \uCCA8\uBD80\uD558\uAE30" })
|
|
775
|
+
/* @__PURE__ */ jsx("span", { children: buttonText || "\uC0AC\uC9C4 \uCCA8\uBD80\uD558\uAE30" })
|
|
735
776
|
] }) });
|
|
736
777
|
}
|
|
737
778
|
return photos.map((photo) => /* @__PURE__ */ jsxs("div", { className: cx("single-photo-item"), children: [
|
|
@@ -746,7 +787,7 @@ function Attachement({ photos, onAddPhoto, onRemovePhoto, show, type = "multiple
|
|
|
746
787
|
gridItems.push(
|
|
747
788
|
/* @__PURE__ */ jsx("div", { className: cx("photo-item", "add-photo-item"), children: /* @__PURE__ */ jsxs("button", { className: cx("add-photo-button"), onClick: handleAddPhoto, children: [
|
|
748
789
|
/* @__PURE__ */ jsx(Icon, { name: "illust/camera" }),
|
|
749
|
-
/* @__PURE__ */ jsx("span", { children: "\uCCA8\uBD80\uD558\uAE30" }),
|
|
790
|
+
/* @__PURE__ */ jsx("span", { children: buttonText || "\uCCA8\uBD80\uD558\uAE30" }),
|
|
750
791
|
/* @__PURE__ */ jsxs("span", { className: cx("photo-count"), children: [
|
|
751
792
|
"(",
|
|
752
793
|
/* @__PURE__ */ jsx("span", { className: cx("photo-count-number"), children: photos.length }),
|
|
@@ -829,7 +870,7 @@ function resize(image, options = { ext: "jpeg", filesize: maxImageSize }) {
|
|
|
829
870
|
return;
|
|
830
871
|
}
|
|
831
872
|
const mimeType = ext === "png" ? "image/png" : "image/jpeg";
|
|
832
|
-
const fileName = image.name ? image.name.replace(/\.[^/.]+$/, "")
|
|
873
|
+
const fileName = image.name ? `${image.name.replace(/\.[^/.]+$/, "")}.${ext}` : `resized.${ext}`;
|
|
833
874
|
const resizedFile = new File([blob], fileName, { type: mimeType });
|
|
834
875
|
resolve(resizedFile);
|
|
835
876
|
},
|
|
@@ -867,7 +908,8 @@ function useCamera({
|
|
|
867
908
|
cameraOnly,
|
|
868
909
|
onDelete,
|
|
869
910
|
show,
|
|
870
|
-
type = "multiple"
|
|
911
|
+
type = "multiple",
|
|
912
|
+
buttonText
|
|
871
913
|
} = {}) {
|
|
872
914
|
const [attachedPhotos, setAttachedPhotos] = useState([]);
|
|
873
915
|
const findImage = (imageId) => {
|
|
@@ -882,7 +924,7 @@ function useCamera({
|
|
|
882
924
|
}
|
|
883
925
|
input.addEventListener("change", async (event) => {
|
|
884
926
|
const target = event.target;
|
|
885
|
-
const files = target
|
|
927
|
+
const { files } = target;
|
|
886
928
|
if (files && files.length > 0) {
|
|
887
929
|
const file = files[0];
|
|
888
930
|
if (file) {
|
|
@@ -892,7 +934,11 @@ function useCamera({
|
|
|
892
934
|
src: URL.createObjectURL(resizedFile),
|
|
893
935
|
name: `\uC11C\uB958\uC0AC\uC9C4_${attachedPhotos.length + 1}`
|
|
894
936
|
};
|
|
895
|
-
|
|
937
|
+
if (type === "single") {
|
|
938
|
+
setAttachedPhotos([newPhoto]);
|
|
939
|
+
} else {
|
|
940
|
+
setAttachedPhotos([...attachedPhotos, newPhoto]);
|
|
941
|
+
}
|
|
896
942
|
onChange && onChange(file);
|
|
897
943
|
}
|
|
898
944
|
}
|
|
@@ -906,14 +952,22 @@ function useCamera({
|
|
|
906
952
|
const imageIndex = attachedPhotos.findIndex((image) => image.id === imageId);
|
|
907
953
|
if (imageIndex > -1) {
|
|
908
954
|
const item = attachedPhotos.splice(imageIndex, 1);
|
|
909
|
-
URL.revokeObjectURL(item[0].src);
|
|
955
|
+
item[0] && URL.revokeObjectURL(item[0].src);
|
|
910
956
|
setAttachedPhotos([...attachedPhotos]);
|
|
911
957
|
onDelete && onDelete(imageId);
|
|
912
958
|
}
|
|
913
959
|
};
|
|
914
|
-
const CameraComponent =
|
|
915
|
-
|
|
916
|
-
|
|
960
|
+
const CameraComponent = () => /* @__PURE__ */ jsx(
|
|
961
|
+
Attachment,
|
|
962
|
+
{
|
|
963
|
+
show: !!show,
|
|
964
|
+
onAddPhoto: onClick,
|
|
965
|
+
onRemovePhoto: deleteImage,
|
|
966
|
+
photos: attachedPhotos,
|
|
967
|
+
type,
|
|
968
|
+
buttonText
|
|
969
|
+
}
|
|
970
|
+
);
|
|
917
971
|
useEffect(() => {
|
|
918
972
|
return () => {
|
|
919
973
|
attachedPhotos.forEach((image) => {
|
|
@@ -930,5 +984,5 @@ function useCamera({
|
|
|
930
984
|
};
|
|
931
985
|
}
|
|
932
986
|
|
|
933
|
-
export {
|
|
987
|
+
export { Attachment, DataTable, FormDatePicker, FormSegmentGroup, FormSignature, FormTextField, StepIndicator, resize, useCamera, useFormSignature, useTable };
|
|
934
988
|
//# sourceMappingURL=index.esm.js.map
|