sales-frontend-components 0.0.39 → 0.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/index.d.ts CHANGED
@@ -126,7 +126,7 @@ interface StepIndicatorProps {
126
126
 
127
127
  declare const StepIndicator: ({ items, onClickItem, currentIndex, defaultValue, dotCount }: StepIndicatorProps) => react_jsx_runtime.JSX.Element;
128
128
 
129
- interface AttachedPhoto$1 {
129
+ interface AttachedPhoto {
130
130
  id: string;
131
131
  src: string;
132
132
  name?: string;
@@ -147,7 +147,7 @@ interface cameraOptions {
147
147
 
148
148
  declare function useCamera({ onChange, resize: resizeOption, cameraOnly, onDelete, show, type }?: Partial<cameraOptions>): {
149
149
  onClick: () => void;
150
- getImage: (imageId: string) => any;
150
+ getImage: (imageId: string) => AttachedPhoto | undefined;
151
151
  deleteImage: (imageId: string) => void;
152
152
  attachedPhotos: AttachedPhoto[];
153
153
  Attachment: () => react_jsx_runtime.JSX.Element;
@@ -175,13 +175,13 @@ declare function useCamera({ onChange, resize: resizeOption, cameraOnly, onDelet
175
175
  declare function resize<T extends string | File>(image: T, options?: cameraOptions['resize']): Promise<T>;
176
176
 
177
177
  interface AttachmentProps {
178
- photos: AttachedPhoto$1[];
178
+ photos: AttachedPhoto[];
179
179
  onAddPhoto: () => void;
180
180
  onRemovePhoto: (id: string) => void;
181
181
  show: boolean;
182
182
  type?: 'single' | 'multiple';
183
183
  }
184
- declare function Attachement({ photos, onAddPhoto, onRemovePhoto, show, type }: AttachmentProps): react_jsx_runtime.JSX.Element | null;
184
+ declare function Attachment({ photos, onAddPhoto, onRemovePhoto, show, type }: AttachmentProps): react_jsx_runtime.JSX.Element | null;
185
185
 
186
- export { Attachement, DataTable, FormDatePicker, FormSegmentGroup, FormSignature, FormTextField, StepIndicator, resize, useCamera, useFormSignature, useTable };
187
- export type { AttachedPhoto$1 as AttachedPhoto, AttachmentProps, DataTableProps, FormSignatureProps, FormSignatureRef, SignatureData, StepIndicatorProps, StepItem, cameraOptions };
186
+ export { Attachment, DataTable, FormDatePicker, FormSegmentGroup, FormSignature, FormTextField, StepIndicator, resize, useCamera, useFormSignature, useTable };
187
+ export type { AttachedPhoto, AttachmentProps, DataTableProps, FormSignatureProps, FormSignatureRef, SignatureData, StepIndicatorProps, StepItem, cameraOptions };
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) return;
327
+ if (!canvas) {
328
+ return;
329
+ }
328
330
  const ctx = canvas.getContext("2d");
329
- if (!ctx) return;
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) return { x: 0, y: 0 };
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) return;
370
+ if (!canvas) {
371
+ return;
372
+ }
365
373
  const ctx = canvas.getContext("2d");
366
- if (!ctx) return;
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) return;
390
+ if (!isDrawing) {
391
+ return;
392
+ }
381
393
  const canvas = canvasRef.current;
382
- if (!canvas) return;
394
+ if (!canvas) {
395
+ return;
396
+ }
383
397
  const ctx = canvas.getContext("2d");
384
- if (!ctx) return;
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) return;
430
+ if (!canvas) {
431
+ return;
432
+ }
415
433
  const ctx = canvas.getContext("2d");
416
- if (!ctx) return;
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) return;
454
+ if (!canvas) {
455
+ return;
456
+ }
435
457
  const ctx = canvas.getContext("2d");
436
- if (!ctx) return;
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()) return;
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) return;
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) return false;
671
+ if (!basicValid) {
672
+ return false;
673
+ }
644
674
  const data = signatureRef.current?.getSignatureData();
645
- if (!data) return false;
646
- if (isLoadedFromRecent) return true;
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,7 @@ const StepIndicator = ({
720
754
  };
721
755
 
722
756
  const cx = classNames.bind(styles$3);
723
- function Attachement({ photos, onAddPhoto, onRemovePhoto, show, type = "multiple" }) {
757
+ function Attachment({ photos, onAddPhoto, onRemovePhoto, show, type = "multiple" }) {
724
758
  const handleAddPhoto = () => {
725
759
  onAddPhoto();
726
760
  };
@@ -829,7 +863,7 @@ function resize(image, options = { ext: "jpeg", filesize: maxImageSize }) {
829
863
  return;
830
864
  }
831
865
  const mimeType = ext === "png" ? "image/png" : "image/jpeg";
832
- const fileName = image.name ? image.name.replace(/\.[^/.]+$/, "") + "." + ext : "resized." + ext;
866
+ const fileName = image.name ? `${image.name.replace(/\.[^/.]+$/, "")}.${ext}` : `resized.${ext}`;
833
867
  const resizedFile = new File([blob], fileName, { type: mimeType });
834
868
  resolve(resizedFile);
835
869
  },
@@ -882,7 +916,7 @@ function useCamera({
882
916
  }
883
917
  input.addEventListener("change", async (event) => {
884
918
  const target = event.target;
885
- const files = target.files;
919
+ const { files } = target;
886
920
  if (files && files.length > 0) {
887
921
  const file = files[0];
888
922
  if (file) {
@@ -906,14 +940,12 @@ function useCamera({
906
940
  const imageIndex = attachedPhotos.findIndex((image) => image.id === imageId);
907
941
  if (imageIndex > -1) {
908
942
  const item = attachedPhotos.splice(imageIndex, 1);
909
- URL.revokeObjectURL(item[0].src);
943
+ URL.revokeObjectURL(item[0] ? item[0].src : "");
910
944
  setAttachedPhotos([...attachedPhotos]);
911
945
  onDelete && onDelete(imageId);
912
946
  }
913
947
  };
914
- const CameraComponent = useCallback(() => {
915
- return /* @__PURE__ */ jsx(Attachement, { show: true, onAddPhoto: onClick, onRemovePhoto: deleteImage, photos: attachedPhotos, type });
916
- }, [attachedPhotos, onClick, deleteImage, show]);
948
+ const CameraComponent = () => /* @__PURE__ */ jsx(Attachment, { show: !!show, onAddPhoto: onClick, onRemovePhoto: deleteImage, photos: attachedPhotos, type });
917
949
  useEffect(() => {
918
950
  return () => {
919
951
  attachedPhotos.forEach((image) => {
@@ -930,5 +962,5 @@ function useCamera({
930
962
  };
931
963
  }
932
964
 
933
- export { Attachement, DataTable, FormDatePicker, FormSegmentGroup, FormSignature, FormTextField, StepIndicator, resize, useCamera, useFormSignature, useTable };
965
+ export { Attachment, DataTable, FormDatePicker, FormSegmentGroup, FormSignature, FormTextField, StepIndicator, resize, useCamera, useFormSignature, useTable };
934
966
  //# sourceMappingURL=index.esm.js.map