cloudmr-ux 1.0.7 → 1.0.8

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
@@ -164,6 +164,13 @@ declare const CmrUpload: {
164
164
  };
165
165
  };
166
166
 
167
+ declare function CmrNameDialog(props: {
168
+ originalName: string;
169
+ renamingCallback: (alias: string) => Promise<boolean>;
170
+ open: boolean;
171
+ setOpen: (open: boolean) => void;
172
+ }): react_jsx_runtime.JSX.Element;
173
+
167
174
  interface CmrTableProps extends Omit<DataGridProps, 'rows'> {
168
175
  dataSource: any[];
169
176
  idAlias?: string;
@@ -174,4 +181,4 @@ interface CmrTableProps extends Omit<DataGridProps, 'rows'> {
174
181
 
175
182
  declare const CmrTable: FC<CmrTableProps>;
176
183
 
177
- export { CmrUpload as CMRUpload, CmrButton, CmrCheckbox, CmrCollapse, CmrInput, CmrPanel, CmrRadioGroup, CmrSelect, CmrTable, CmrTableProps, LambdaFile };
184
+ export { CmrUpload as CMRUpload, CmrButton, CmrCheckbox, CmrCollapse, CmrInput, CmrNameDialog, CmrPanel, CmrRadioGroup, CmrSelect, CmrTable, CmrTableProps, LambdaFile };
package/dist/index.js CHANGED
@@ -35,6 +35,7 @@ __export(src_exports, {
35
35
  CmrCheckbox: () => CmrCheckbox,
36
36
  CmrCollapse: () => Collapse_default,
37
37
  CmrInput: () => CmrInput,
38
+ CmrNameDialog: () => CmrNameDialog,
38
39
  CmrPanel: () => Panel_default,
39
40
  CmrRadioGroup: () => CmrRadioGroup_default,
40
41
  CmrSelect: () => CmrSelect_default,
@@ -758,9 +759,98 @@ CmrUpload.defaultProps = {
758
759
  };
759
760
  var Upload_default = CmrUpload;
760
761
 
762
+ // src/CmrComponents/rename/edit.tsx
763
+ var React6 = __toESM(require("react"));
764
+ var import_material8 = require("@mui/material");
765
+ var import_TextField2 = __toESM(require("@mui/material/TextField"));
766
+ var import_Dialog2 = __toESM(require("@mui/material/Dialog"));
767
+ var import_DialogActions2 = __toESM(require("@mui/material/DialogActions"));
768
+ var import_DialogContent2 = __toESM(require("@mui/material/DialogContent"));
769
+ var import_DialogTitle2 = __toESM(require("@mui/material/DialogTitle"));
770
+ var import_react5 = require("react");
771
+ var import_jsx_runtime11 = require("react/jsx-runtime");
772
+ function CmrNameDialog(props) {
773
+ let { originalName, open, setOpen } = props;
774
+ const [helperText, setHelperText] = React6.useState("");
775
+ const [text, setText] = React6.useState(originalName);
776
+ const [error, setError] = React6.useState(false);
777
+ const renamingCallback = props.renamingCallback;
778
+ const handleClose = () => {
779
+ setOpen(false);
780
+ };
781
+ (0, import_react5.useEffect)(() => {
782
+ checkError(originalName);
783
+ }, [originalName]);
784
+ const handleConfirm = async () => {
785
+ if (await renamingCallback(text))
786
+ handleClose();
787
+ };
788
+ const handleTextFieldChange = (e) => {
789
+ setText(e.target.value);
790
+ checkError(e.target.value);
791
+ };
792
+ const checkError = (text2) => {
793
+ const fileNameRegex = /^[a-zA-Z0-9_\-]+\.[a-zA-Z]{1,5}$/;
794
+ let newExtension = text2.split(".").pop();
795
+ let orgExtension = originalName.indexOf(".") >= 0 ? originalName.split(".").pop() : "?";
796
+ if (!fileNameRegex.test(text2)) {
797
+ setError(true);
798
+ if (text2.indexOf(".") < 0) {
799
+ setHelperText("Invalid file name, needs a valid extension.");
800
+ } else {
801
+ setHelperText("Invalid file name, please check.");
802
+ }
803
+ } else if (newExtension !== orgExtension) {
804
+ setHelperText(`You are modifying your file extension from .${orgExtension} to .${newExtension}.`);
805
+ setError(false);
806
+ } else {
807
+ setError(false);
808
+ setHelperText("");
809
+ }
810
+ };
811
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
812
+ import_Dialog2.default,
813
+ {
814
+ open,
815
+ onClose: handleClose,
816
+ fullWidth: true,
817
+ maxWidth: "xs",
818
+ children: [
819
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_DialogTitle2.default, { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_material8.Typography, { children: [
820
+ " Rename the File ",
821
+ originalName,
822
+ " as:"
823
+ ] }) }),
824
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_DialogContent2.default, { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
825
+ import_TextField2.default,
826
+ {
827
+ autoFocus: true,
828
+ margin: "dense",
829
+ id: "name",
830
+ defaultValue: originalName,
831
+ onFocus: (event) => {
832
+ event.target.select();
833
+ },
834
+ fullWidth: true,
835
+ inputProps: { style: { fontSize: "16px" } },
836
+ variant: "standard",
837
+ onChange: handleTextFieldChange,
838
+ error,
839
+ helperText
840
+ }
841
+ ) }),
842
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_DialogActions2.default, { children: [
843
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(CmrButton, { variant: "outlined", onClick: handleClose, children: "Cancel" }),
844
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(CmrButton, { variant: "contained", color: "primary", onClick: handleConfirm, children: "Confirm" })
845
+ ] })
846
+ ]
847
+ }
848
+ ) });
849
+ }
850
+
761
851
  // src/CmrTable/CmrTable.tsx
762
852
  var import_x_data_grid = require("@mui/x-data-grid");
763
- var import_jsx_runtime11 = require("react/jsx-runtime");
853
+ var import_jsx_runtime12 = require("react/jsx-runtime");
764
854
  var CmrTable = (props) => {
765
855
  const {
766
856
  dataSource,
@@ -772,7 +862,7 @@ var CmrTable = (props) => {
772
862
  showCheckbox = true,
773
863
  ...rest
774
864
  } = props;
775
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { style: style ?? { height: "400px", width: "100%" }, className: className ?? "", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
865
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { style: style ?? { height: "400px", width: "100%" }, className: className ?? "", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
776
866
  import_x_data_grid.DataGrid,
777
867
  {
778
868
  rows: dataSource ? dataSource.map((row) => ({
@@ -803,6 +893,7 @@ var CmrTable2 = CmrTable_default;
803
893
  CmrCheckbox,
804
894
  CmrCollapse,
805
895
  CmrInput,
896
+ CmrNameDialog,
806
897
  CmrPanel,
807
898
  CmrRadioGroup,
808
899
  CmrSelect,
package/dist/index.mjs CHANGED
@@ -720,9 +720,98 @@ CmrUpload.defaultProps = {
720
720
  };
721
721
  var Upload_default = CmrUpload;
722
722
 
723
+ // src/CmrComponents/rename/edit.tsx
724
+ import * as React6 from "react";
725
+ import { Typography as Typography2 } from "@mui/material";
726
+ import TextField2 from "@mui/material/TextField";
727
+ import Dialog2 from "@mui/material/Dialog";
728
+ import DialogActions2 from "@mui/material/DialogActions";
729
+ import DialogContent2 from "@mui/material/DialogContent";
730
+ import DialogTitle2 from "@mui/material/DialogTitle";
731
+ import { useEffect } from "react";
732
+ import { jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
733
+ function CmrNameDialog(props) {
734
+ let { originalName, open, setOpen } = props;
735
+ const [helperText, setHelperText] = React6.useState("");
736
+ const [text, setText] = React6.useState(originalName);
737
+ const [error, setError] = React6.useState(false);
738
+ const renamingCallback = props.renamingCallback;
739
+ const handleClose = () => {
740
+ setOpen(false);
741
+ };
742
+ useEffect(() => {
743
+ checkError(originalName);
744
+ }, [originalName]);
745
+ const handleConfirm = async () => {
746
+ if (await renamingCallback(text))
747
+ handleClose();
748
+ };
749
+ const handleTextFieldChange = (e) => {
750
+ setText(e.target.value);
751
+ checkError(e.target.value);
752
+ };
753
+ const checkError = (text2) => {
754
+ const fileNameRegex = /^[a-zA-Z0-9_\-]+\.[a-zA-Z]{1,5}$/;
755
+ let newExtension = text2.split(".").pop();
756
+ let orgExtension = originalName.indexOf(".") >= 0 ? originalName.split(".").pop() : "?";
757
+ if (!fileNameRegex.test(text2)) {
758
+ setError(true);
759
+ if (text2.indexOf(".") < 0) {
760
+ setHelperText("Invalid file name, needs a valid extension.");
761
+ } else {
762
+ setHelperText("Invalid file name, please check.");
763
+ }
764
+ } else if (newExtension !== orgExtension) {
765
+ setHelperText(`You are modifying your file extension from .${orgExtension} to .${newExtension}.`);
766
+ setError(false);
767
+ } else {
768
+ setError(false);
769
+ setHelperText("");
770
+ }
771
+ };
772
+ return /* @__PURE__ */ jsx11("div", { children: /* @__PURE__ */ jsxs7(
773
+ Dialog2,
774
+ {
775
+ open,
776
+ onClose: handleClose,
777
+ fullWidth: true,
778
+ maxWidth: "xs",
779
+ children: [
780
+ /* @__PURE__ */ jsx11(DialogTitle2, { children: /* @__PURE__ */ jsxs7(Typography2, { children: [
781
+ " Rename the File ",
782
+ originalName,
783
+ " as:"
784
+ ] }) }),
785
+ /* @__PURE__ */ jsx11(DialogContent2, { children: /* @__PURE__ */ jsx11(
786
+ TextField2,
787
+ {
788
+ autoFocus: true,
789
+ margin: "dense",
790
+ id: "name",
791
+ defaultValue: originalName,
792
+ onFocus: (event) => {
793
+ event.target.select();
794
+ },
795
+ fullWidth: true,
796
+ inputProps: { style: { fontSize: "16px" } },
797
+ variant: "standard",
798
+ onChange: handleTextFieldChange,
799
+ error,
800
+ helperText
801
+ }
802
+ ) }),
803
+ /* @__PURE__ */ jsxs7(DialogActions2, { children: [
804
+ /* @__PURE__ */ jsx11(CmrButton, { variant: "outlined", onClick: handleClose, children: "Cancel" }),
805
+ /* @__PURE__ */ jsx11(CmrButton, { variant: "contained", color: "primary", onClick: handleConfirm, children: "Confirm" })
806
+ ] })
807
+ ]
808
+ }
809
+ ) });
810
+ }
811
+
723
812
  // src/CmrTable/CmrTable.tsx
724
813
  import { DataGrid } from "@mui/x-data-grid";
725
- import { jsx as jsx11 } from "react/jsx-runtime";
814
+ import { jsx as jsx12 } from "react/jsx-runtime";
726
815
  var CmrTable = (props) => {
727
816
  const {
728
817
  dataSource,
@@ -734,7 +823,7 @@ var CmrTable = (props) => {
734
823
  showCheckbox = true,
735
824
  ...rest
736
825
  } = props;
737
- return /* @__PURE__ */ jsx11("div", { style: style ?? { height: "400px", width: "100%" }, className: className ?? "", children: /* @__PURE__ */ jsx11(
826
+ return /* @__PURE__ */ jsx12("div", { style: style ?? { height: "400px", width: "100%" }, className: className ?? "", children: /* @__PURE__ */ jsx12(
738
827
  DataGrid,
739
828
  {
740
829
  rows: dataSource ? dataSource.map((row) => ({
@@ -764,6 +853,7 @@ export {
764
853
  CmrCheckbox,
765
854
  Collapse_default as CmrCollapse,
766
855
  CmrInput,
856
+ CmrNameDialog,
767
857
  Panel_default as CmrPanel,
768
858
  CmrRadioGroup_default as CmrRadioGroup,
769
859
  CmrSelect_default as CmrSelect,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloudmr-ux",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "author": "erosmontin@gmail.com",
5
5
  "license": "MIT",
6
6
  "repository": "erosmontin/cloudmr-ux",