@sustaina/shared-ui 1.10.1 → 1.11.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/dist/index.mjs CHANGED
@@ -5,7 +5,7 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
  import * as React5 from 'react';
6
6
  import React5__default, { forwardRef, useRef, useMemo, useCallback, isValidElement, useState, useEffect, createElement } from 'react';
7
7
  import { format, isValid, parseISO, isAfter, compareAsc, parse } from 'date-fns';
8
- import { CircleX, CircleHelp, Undo, Redo, Bold, Italic, Underline, Strikethrough, Code, Pilcrow, Heading1, Heading2, Heading3, List as List$1, ListOrdered, Quote, CodeSquare, Link, Link2Off, Image, AlignLeft, AlignCenter, AlignRight, XIcon, ChevronRight, CheckIcon, Triangle, CalendarIcon, X, Search, ChevronUp, ChevronDown, Plus, ChevronLeft, CircleUserRound, PanelLeftIcon, Bug, GripVertical, Info, CircleMinus, Minus } from 'lucide-react';
8
+ import { CircleX, CircleHelp, Undo, Redo, Bold, Italic, Underline, Strikethrough, Code, Pilcrow, Heading1, Heading2, Heading3, List as List$1, ListOrdered, Quote, CodeSquare, Link, Link2Off, Image as Image$1, AlignLeft, AlignCenter, AlignRight, XIcon, ChevronRight, CheckIcon, Triangle, CalendarIcon, X, Search, ChevronUp, ChevronDown, Plus, ChevronLeft, CircleUserRound, PanelLeftIcon, Bug, GripVertical, Info, CircleMinus, Minus } from 'lucide-react';
9
9
  import { createPortal } from 'react-dom';
10
10
  import * as SelectPrimitive from '@radix-ui/react-select';
11
11
  import { useForm, FormProvider, Controller, useFormContext, useFormState, useFieldArray, useWatch } from 'react-hook-form';
@@ -48,6 +48,7 @@ import { mergeRegister } from '@lexical/utils';
48
48
  import { $setBlocksType } from '@lexical/selection';
49
49
  import * as SeparatorPrimitive from '@radix-ui/react-separator';
50
50
  import * as SwitchPrimitive from '@radix-ui/react-switch';
51
+ import Cropper from 'react-easy-crop';
51
52
 
52
53
  var __defProp = Object.defineProperty;
53
54
  var __export = (target, all) => {
@@ -6478,7 +6479,7 @@ function ToolbarPlugin({
6478
6479
  ToolbarButton,
6479
6480
  {
6480
6481
  label: "Insert image",
6481
- icon: Image,
6482
+ icon: Image$1,
6482
6483
  onClick: handleInsertImage,
6483
6484
  disabled: disabled || !canInsertImage
6484
6485
  }
@@ -7642,6 +7643,173 @@ function SidebarLayout({
7642
7643
  ] }) });
7643
7644
  }
7644
7645
 
7645
- export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, AdvanceSearch_default as AdvanceSearch, arrow_default as ArrowIcon, Button, Checkbox, Collapsible, CollapsibleContent2 as CollapsibleContent, CollapsibleTrigger2 as CollapsibleTrigger, DataTable_default as DataTable, DatePicker2 as DatePicker, Dialog, DialogAlert, DialogContent, DialogDescription, DialogFooter, DialogTitle, DialogTrigger, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, GridSettingsModal_default as GridSettingsModal, HeaderCell_default as HeaderCell, Input, Label2 as Label, List_default as List, container_default as ListContainer, header_default as ListHeader, table_default as ListTable, LookupSelect, MonthPicker2 as MonthPicker, navbar_default as Navbar, not_found_default as NotFoundIcon, Popover, PopoverAnchor, PopoverArrow, PopoverContent, PopoverTrigger, PreventPageLeave_default as PreventPageLeave, RadioGroupItem, RadioGroupRoot, RadioLabel, RichText, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator2 as Separator, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger, Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupAction, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInput, SidebarInset, SidebarLayout, SidebarMenu, SidebarMenuAction, SidebarMenuBadge, SidebarMenuButton, SidebarMenuItem, SidebarMenuSkeleton, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarRail, SidebarSeparator, SidebarTrigger, Skeleton, calendar_default as SuiCalendarIcon, check_default as SuiCheckIcon, dots_vertical_default as SuiDotsVerticalIcon, empty_data_default as SuiEmptyDataIcon, expand_default as SuiExpandIcon, filter_default as SuiFilterIcon, setting_default as SuiSettingIcon, triangle_down_default as SuiTriangleDownIcon, warning_default as SuiWarningIcon, Switch, Textarea, Tooltip, TooltipArrow, TooltipContent, TooltipProvider, TooltipTrigger, ui_exports as UI, booleanToSelectValue, buttonVariants, cn, compareAlphanumeric, debounce, inputVariants, isDefined, isEmptyObject, selectValueToBoolean, stripNullishObject, throttle, useFormField, useGridSettingsStore_default as useGridSettingsStore, useHover_default as useHover, useIntersectionObserver_default as useIntersectionObserver, useMediaQuery_default as useMediaQuery, usePreventPageLeave_default as usePreventPageLeave, usePreventPageLeaveStore_default as usePreventPageLeaveStore, useScreenSize_default as useScreenSize, useSidebar, useTruncated_default as useTruncated };
7646
+ // src/components/cropperModal/helper.ts
7647
+ var createImage = (url) => new Promise((resolve, reject) => {
7648
+ const image = new Image();
7649
+ image.addEventListener("load", () => resolve(image));
7650
+ image.addEventListener("error", (error) => reject(error));
7651
+ image.setAttribute("crossOrigin", "anonymous");
7652
+ image.src = url;
7653
+ });
7654
+ async function getCroppedImg(imageSrc, pixelCrop, desiredDimension) {
7655
+ const image = await createImage(imageSrc);
7656
+ const canvas = document.createElement("canvas");
7657
+ const ctx = canvas.getContext("2d");
7658
+ if (!ctx) {
7659
+ throw new Error("can not create canvas");
7660
+ }
7661
+ canvas.width = image.width;
7662
+ canvas.height = image.height;
7663
+ ctx.drawImage(image, 0, 0);
7664
+ const croppedCanvas = document.createElement("canvas");
7665
+ const croppedCtx = croppedCanvas.getContext("2d");
7666
+ if (!croppedCtx) {
7667
+ throw new Error("can not create canvas");
7668
+ }
7669
+ croppedCanvas.width = desiredDimension?.width ?? pixelCrop.width;
7670
+ croppedCanvas.height = desiredDimension?.height ?? pixelCrop.height;
7671
+ croppedCtx.drawImage(
7672
+ canvas,
7673
+ pixelCrop.x,
7674
+ pixelCrop.y,
7675
+ pixelCrop.width,
7676
+ pixelCrop.height,
7677
+ 0,
7678
+ 0,
7679
+ desiredDimension?.width ?? pixelCrop.width,
7680
+ desiredDimension?.height ?? pixelCrop.height
7681
+ );
7682
+ return new Promise((resolve, reject) => {
7683
+ croppedCanvas.toBlob((file) => {
7684
+ if (file) {
7685
+ resolve(URL.createObjectURL(file));
7686
+ } else {
7687
+ reject("croppedCanvas gave null object");
7688
+ }
7689
+ }, "image/png");
7690
+ });
7691
+ }
7692
+ var CropperModal = ({
7693
+ open,
7694
+ onOpenChange,
7695
+ imageSrc,
7696
+ onConfirm,
7697
+ onCancel,
7698
+ onError,
7699
+ cropSize,
7700
+ outputExactCropSize,
7701
+ generateBlobUrlOutput,
7702
+ title,
7703
+ props
7704
+ }) => {
7705
+ const [isLoading, setIsLoading] = useState(false);
7706
+ const [crop, setCrop] = useState({ x: 0, y: 0 });
7707
+ const [zoom, setZoom] = useState();
7708
+ const [croppedAreaPixels, setCroppedAreaPixels] = useState(null);
7709
+ const handleClose = useCallback(() => {
7710
+ onOpenChange(false);
7711
+ }, [onOpenChange]);
7712
+ const handleCancel = useCallback(() => {
7713
+ if (onCancel) {
7714
+ onCancel();
7715
+ }
7716
+ handleClose();
7717
+ }, [handleClose, onCancel]);
7718
+ const handleCropComplete = useCallback((_, croppedAreaPixels2) => {
7719
+ setCroppedAreaPixels(croppedAreaPixels2);
7720
+ }, []);
7721
+ const handleConfirm = async () => {
7722
+ if (!imageSrc || !onConfirm) {
7723
+ handleClose();
7724
+ return;
7725
+ }
7726
+ if (!generateBlobUrlOutput) {
7727
+ onConfirm({ crop, croppedAreaPixels });
7728
+ return;
7729
+ }
7730
+ if (!croppedAreaPixels) {
7731
+ onConfirm({ crop, croppedAreaPixels, croppedImageBlobUrl: imageSrc });
7732
+ return;
7733
+ }
7734
+ setIsLoading(true);
7735
+ try {
7736
+ const desiredDimension = outputExactCropSize ? cropSize : void 0;
7737
+ const croppedImage = await getCroppedImg(imageSrc, croppedAreaPixels, desiredDimension);
7738
+ onConfirm({ crop, croppedAreaPixels, croppedImageBlobUrl: croppedImage });
7739
+ } catch (e) {
7740
+ if (onError) {
7741
+ onError(e);
7742
+ }
7743
+ } finally {
7744
+ setIsLoading(false);
7745
+ handleClose();
7746
+ }
7747
+ };
7748
+ return /* @__PURE__ */ jsx(
7749
+ Dialog,
7750
+ {
7751
+ open,
7752
+ onOpenChange: (nextOpen) => {
7753
+ if (!nextOpen) {
7754
+ handleClose();
7755
+ } else {
7756
+ onOpenChange(true);
7757
+ }
7758
+ },
7759
+ children: /* @__PURE__ */ jsxs(
7760
+ DialogContent,
7761
+ {
7762
+ className: "flex flex-col w-fit !max-w-6xl p-0 overflow-clip gap-0 border-0",
7763
+ ...props?.dialogContent,
7764
+ children: [
7765
+ /* @__PURE__ */ jsxs(
7766
+ "div",
7767
+ {
7768
+ className: "flex w-full bg-[#82B495] text-white justify-between items-center p-4",
7769
+ ...props?.dialogTitleContainer,
7770
+ children: [
7771
+ /* @__PURE__ */ jsx(DialogTitle, { className: "text-2xl font-semibold", ...props?.dialogTitle, children: title ?? "Crop Image" }),
7772
+ /* @__PURE__ */ jsx(
7773
+ "button",
7774
+ {
7775
+ type: "button",
7776
+ className: "text-white hover:text-gray-100 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed",
7777
+ onClick: handleCancel,
7778
+ disabled: isLoading,
7779
+ children: /* @__PURE__ */ jsx(XIcon, { className: "w-4 h-4" })
7780
+ }
7781
+ )
7782
+ ]
7783
+ }
7784
+ ),
7785
+ /* @__PURE__ */ jsx("div", { className: "w-120 md:w-[50vw] h-[70vh] mx-auto", ...props?.cropperContainer, children: /* @__PURE__ */ jsx(
7786
+ Cropper,
7787
+ {
7788
+ image: imageSrc ?? void 0,
7789
+ crop,
7790
+ onCropChange: setCrop,
7791
+ zoom,
7792
+ onZoomChange: setZoom,
7793
+ style: { containerStyle: { position: "relative", width: "100%", height: "100%" } },
7794
+ onCropComplete: handleCropComplete,
7795
+ aspect: cropSize ? cropSize.width / cropSize.height : void 0,
7796
+ zoomWithScroll: true,
7797
+ showGrid: true,
7798
+ restrictPosition: true,
7799
+ ...props?.cropper
7800
+ }
7801
+ ) }),
7802
+ /* @__PURE__ */ jsx("div", { className: "w-full py-4 px-8", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full justify-between", children: [
7803
+ /* @__PURE__ */ jsx(Button, { type: "button", variant: "cancel", onClick: handleCancel, disabled: isLoading, children: "Cancel" }),
7804
+ /* @__PURE__ */ jsx("div", { className: "ml-auto flex gap-x-2", children: /* @__PURE__ */ jsx(Button, { type: "button", variant: "default", onClick: handleConfirm, disabled: isLoading, children: "Confirm" }) })
7805
+ ] }) })
7806
+ ]
7807
+ }
7808
+ )
7809
+ }
7810
+ );
7811
+ };
7812
+
7813
+ export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, AdvanceSearch_default as AdvanceSearch, arrow_default as ArrowIcon, Button, Checkbox, Collapsible, CollapsibleContent2 as CollapsibleContent, CollapsibleTrigger2 as CollapsibleTrigger, CropperModal, DataTable_default as DataTable, DatePicker2 as DatePicker, Dialog, DialogAlert, DialogContent, DialogDescription, DialogFooter, DialogTitle, DialogTrigger, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, GridSettingsModal_default as GridSettingsModal, HeaderCell_default as HeaderCell, Input, Label2 as Label, List_default as List, container_default as ListContainer, header_default as ListHeader, table_default as ListTable, LookupSelect, MonthPicker2 as MonthPicker, navbar_default as Navbar, not_found_default as NotFoundIcon, Popover, PopoverAnchor, PopoverArrow, PopoverContent, PopoverTrigger, PreventPageLeave_default as PreventPageLeave, RadioGroupItem, RadioGroupRoot, RadioLabel, RichText, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator2 as Separator, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger, Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupAction, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInput, SidebarInset, SidebarLayout, SidebarMenu, SidebarMenuAction, SidebarMenuBadge, SidebarMenuButton, SidebarMenuItem, SidebarMenuSkeleton, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarRail, SidebarSeparator, SidebarTrigger, Skeleton, calendar_default as SuiCalendarIcon, check_default as SuiCheckIcon, dots_vertical_default as SuiDotsVerticalIcon, empty_data_default as SuiEmptyDataIcon, expand_default as SuiExpandIcon, filter_default as SuiFilterIcon, setting_default as SuiSettingIcon, triangle_down_default as SuiTriangleDownIcon, warning_default as SuiWarningIcon, Switch, Textarea, Tooltip, TooltipArrow, TooltipContent, TooltipProvider, TooltipTrigger, ui_exports as UI, booleanToSelectValue, buttonVariants, cn, compareAlphanumeric, debounce, inputVariants, isDefined, isEmptyObject, selectValueToBoolean, stripNullishObject, throttle, useFormField, useGridSettingsStore_default as useGridSettingsStore, useHover_default as useHover, useIntersectionObserver_default as useIntersectionObserver, useMediaQuery_default as useMediaQuery, usePreventPageLeave_default as usePreventPageLeave, usePreventPageLeaveStore_default as usePreventPageLeaveStore, useScreenSize_default as useScreenSize, useSidebar, useTruncated_default as useTruncated };
7646
7814
  //# sourceMappingURL=index.mjs.map
7647
7815
  //# sourceMappingURL=index.mjs.map