@oliasoft-open-source/react-ui-library 4.6.5 → 4.6.6-beta-1

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.
Files changed (35) hide show
  1. package/dist/index.d.ts +22 -0
  2. package/dist/index.js +146 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/storybook/assets/{Color-6VNJS4EI-6QyiStBx.js → Color-6VNJS4EI-BrOcbA6h.js} +1 -1
  5. package/dist/storybook/assets/{DocsRenderer-NNNQARDV-2upuKe-y.js → DocsRenderer-NNNQARDV-tJI6VTjP.js} +1 -1
  6. package/dist/storybook/assets/{WithTooltip-V3YHNWJZ-sasadf5B.js → WithTooltip-V3YHNWJZ-YRJYbhNd.js} +1 -1
  7. package/dist/storybook/assets/{buttons-and-links-5qDA5c0M.js → buttons-and-links-VKKWJKFr.js} +1 -1
  8. package/dist/storybook/assets/{casing-loads.stories-Ilvo3kc-.js → casing-loads.stories-oh3l5Q7X.js} +1 -1
  9. package/dist/storybook/assets/{chunk-HLWAVYOI-2WzL7lNK.js → chunk-HLWAVYOI-83EByc66.js} +1 -1
  10. package/dist/storybook/assets/{color-oYWpjfqe.js → color-ugWGhOJm.js} +1 -1
  11. package/dist/storybook/assets/dialog-JbUIdbsX.js +1 -0
  12. package/dist/storybook/assets/{file-input.stories-OwcfaeRF.js → file-input.stories-8w1taUk6.js} +1 -1
  13. package/dist/storybook/assets/{form.stories-8fqEXOZ2.js → form.stories-b8fSf1KV.js} +1 -1
  14. package/dist/storybook/assets/{formatter-SWP5E3XI-NZzQKsls.js → formatter-SWP5E3XI-umUJAuhQ.js} +1 -1
  15. package/dist/storybook/assets/{iframe-GxJzSQlX.js → iframe-LJjp0O19.js} +2 -2
  16. package/dist/storybook/assets/{index-NMzKYhDm.js → index-hMEOtd8c.js} +5 -5
  17. package/dist/storybook/assets/{input-validation-0WooNvL8.js → input-validation-5TXTtQCt.js} +1 -1
  18. package/dist/storybook/assets/{inputs-ZnQpWnaa.js → inputs-rK_va801.js} +1 -1
  19. package/dist/storybook/assets/{layout-forms-MHOKZcG9.js → layout-forms-4SDauXUc.js} +1 -1
  20. package/dist/storybook/assets/{layout-general-X0JNgpR0.js → layout-general-4b2v8KKO.js} +1 -1
  21. package/dist/storybook/assets/modal.stories-DDey1uF7.js +200 -0
  22. package/dist/storybook/assets/{padding-and-spacing-hLcWI3R8.js → padding-and-spacing-0ADtQv-B.js} +1 -1
  23. package/dist/storybook/assets/{preview-TQVrQPI_.js → preview-Jj3eWAFT.js} +1 -1
  24. package/dist/storybook/assets/{preview-r7HHhykG.js → preview-ZGYBin_R.js} +2 -2
  25. package/dist/storybook/assets/{syntaxhighlighter-B5GMVT5T-gFlfxFDl.js → syntaxhighlighter-B5GMVT5T-yVSKFRoH.js} +1 -1
  26. package/dist/storybook/assets/{textarea-TIELeiGt.js → textarea-gwm6gdQO.js} +1 -1
  27. package/dist/storybook/assets/{textarea.stories-DIzqgg9F.js → textarea.stories-eOTtHmL4.js} +1 -1
  28. package/dist/storybook/iframe.html +1 -1
  29. package/dist/storybook/index.json +1 -1
  30. package/dist/storybook/project.json +1 -1
  31. package/dist/storybook/stories.json +1 -1
  32. package/package.json +1 -1
  33. package/dist/404.html +0 -1
  34. package/dist/storybook/assets/dialog-roJ8Yns6.js +0 -1
  35. package/dist/storybook/assets/modal.stories-dirXv4n_.js +0 -173
package/dist/index.d.ts CHANGED
@@ -1665,6 +1665,8 @@ export declare const SideBar: React_2.MemoExoticComponent<({ options, startOpen,
1665
1665
 
1666
1666
  export declare const Slider: ({ name, label, width, labelWidth, value, min, max, step, marks, showArrows, showTooltip, tooltipFormatter, disabled, range, small, vertical, onChange, }: ISliderProps) => JSX_2.Element;
1667
1667
 
1668
+ export declare const SmartUploadModal: ({ visible, prompt, onCloseModal, onUpload, onComplete, onFailed, onError, width, heading, dialogText, fileInputText, fileInputPlaceholder, uploadText, cancelText, testId, }: TSmartUploadModalProps) => JSX_2.Element;
1669
+
1668
1670
  export declare const Spacer: ({ height, width, flex, }: ISpacerProps) => JSX_2.Element;
1669
1671
 
1670
1672
  export declare const Spinner: ({ small, colored, dark, tiny, }: ISpinnerProps) => JSX_2.Element;
@@ -1800,6 +1802,26 @@ declare type TSliderMark = {
1800
1802
  tooltip?: number | string | ReactNode;
1801
1803
  };
1802
1804
 
1805
+ export declare type TSmartUploadModalProps = {
1806
+ visible: boolean;
1807
+ prompt: string;
1808
+ onCloseModal: () => void;
1809
+ onUpload: (prompt: string, file: File) => any;
1810
+ onComplete: (data: {
1811
+ [key: string]: string;
1812
+ }[]) => void;
1813
+ onFailed?: () => void;
1814
+ onError?: (error: any) => void;
1815
+ width?: number;
1816
+ heading?: string;
1817
+ dialogText?: string;
1818
+ fileInputText?: string;
1819
+ fileInputPlaceholder?: string;
1820
+ uploadText?: string;
1821
+ cancelText?: string;
1822
+ testId?: string;
1823
+ };
1824
+
1803
1825
  declare type TStringNumberNull = string | number | null;
1804
1826
 
1805
1827
  declare type TStringOrNumber = string | number;
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import * as PropTypes from "prop-types";
11
11
  import PropTypes__default from "prop-types";
12
12
  import ReactDOM, { createPortal, unstable_batchedUpdates, render } from "react-dom";
13
13
  import _$1, { set, get as get$2, isString as isString$3, isNumber as isNumber$1, isBoolean as isBoolean$2, isFunction as isFunction$3, isEmpty, isArray as isArray$1, toNumber, debounce as debounce$2, isObject as isObject$5, isObjectLike, has as has$1, isEqual as isEqual$4 } from "lodash";
14
- import { roundToFixed, validateNumber, cleanNumStr, unitFromQuantity, isValueWithUnit, withUnit, convertSamePrecision, getValue as getValue$1, getUnit, KNOWN_UNITS, split as split$1, checkAndCleanDecimalComma, label as label$b, altUnitsList, getUnitsForQuantity, convertAndGetValue, isScientificStringNum, roundToPrecision } from "@oliasoft-open-source/units";
14
+ import { roundToFixed, validateNumber, cleanNumStr, unitFromQuantity, isValueWithUnit, withUnit, convertSamePrecision, getValue as getValue$1, getUnit, KNOWN_UNITS, split as split$1, checkAndCleanDecimalComma, label as label$b, altUnitsList, getUnitsForQuantity, convertAndGetValue, isScientificStringNum, roundToPrecision, roundByMagnitudeToFixed } from "@oliasoft-open-source/units";
15
15
  import { isValueWithUnit as isValueWithUnit$1 } from "@oliasoft-open-source/units/dist/units";
16
16
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
17
17
  function getDefaultExportFromCjs(x2) {
@@ -70855,6 +70855,150 @@ const UnitTable = ({
70855
70855
  }
70856
70856
  );
70857
70857
  };
70858
+ const INTERVAL_TIME = 250;
70859
+ const REQUEST_TIME = 4e4;
70860
+ const FINISH_INTERVALS = 20;
70861
+ const FINISH_TIME = 500;
70862
+ const SmartUploadModal = ({
70863
+ visible,
70864
+ prompt,
70865
+ onCloseModal,
70866
+ onUpload,
70867
+ onComplete,
70868
+ onFailed,
70869
+ onError: onError3,
70870
+ width: width2,
70871
+ heading: heading2,
70872
+ dialogText,
70873
+ fileInputText,
70874
+ fileInputPlaceholder,
70875
+ uploadText,
70876
+ cancelText,
70877
+ testId
70878
+ }) => {
70879
+ const [file, setFile] = useState(void 0);
70880
+ const [isFetching, setFetching] = useState(false);
70881
+ const [requestTimer, setRequestTimer] = useState(0);
70882
+ let timer = 0;
70883
+ const updateTimer = () => {
70884
+ const newTime = timer + INTERVAL_TIME;
70885
+ timer = newTime;
70886
+ setRequestTimer(timer);
70887
+ };
70888
+ const finishTimer = (deltaTime) => {
70889
+ let newTime = timer + deltaTime;
70890
+ if (newTime >= 0.99 * REQUEST_TIME) {
70891
+ newTime = REQUEST_TIME;
70892
+ }
70893
+ timer = newTime;
70894
+ setRequestTimer(timer);
70895
+ };
70896
+ useEffect(() => {
70897
+ setFile(void 0);
70898
+ }, [visible]);
70899
+ const handleFileChange = (event) => {
70900
+ if (!event.target.value)
70901
+ return;
70902
+ setFile(event.target.value);
70903
+ };
70904
+ const handleUpload = async () => {
70905
+ setRequestTimer(0);
70906
+ const id2 = setInterval(updateTimer, INTERVAL_TIME);
70907
+ try {
70908
+ if (!file)
70909
+ return;
70910
+ setFetching(true);
70911
+ const data = await onUpload(prompt, file);
70912
+ if (data) {
70913
+ clearInterval(id2);
70914
+ const id22 = setInterval(
70915
+ finishTimer,
70916
+ FINISH_TIME / FINISH_INTERVALS,
70917
+ (REQUEST_TIME - timer) / (FINISH_INTERVALS - 1)
70918
+ );
70919
+ await setTimeout(() => {
70920
+ onComplete(data);
70921
+ clearInterval(id22);
70922
+ setFetching(false);
70923
+ }, FINISH_TIME);
70924
+ } else {
70925
+ onFailed == null ? void 0 : onFailed();
70926
+ setFetching(false);
70927
+ }
70928
+ } catch (error2) {
70929
+ onError3 == null ? void 0 : onError3(error2);
70930
+ setFetching(false);
70931
+ } finally {
70932
+ clearInterval(id2);
70933
+ }
70934
+ };
70935
+ const onConfirm = () => {
70936
+ handleUpload();
70937
+ };
70938
+ const onClose = () => {
70939
+ onCloseModal();
70940
+ };
70941
+ const content2 = /* @__PURE__ */ jsxs(Fragment$1, { children: [
70942
+ /* @__PURE__ */ jsx(Text, { children: dialogText || "Upload file and extract data using a LLM" }),
70943
+ /* @__PURE__ */ jsx(Spacer, {}),
70944
+ /* @__PURE__ */ jsx(
70945
+ FileInput,
70946
+ {
70947
+ placeholder: fileInputPlaceholder || "No file",
70948
+ label: fileInputText || "Select",
70949
+ file: file || void 0,
70950
+ onChange: handleFileChange,
70951
+ testId: `${testId}-file-input`,
70952
+ accept: "image/*"
70953
+ }
70954
+ ),
70955
+ /* @__PURE__ */ jsx(Spacer, {}),
70956
+ isFetching && /* @__PURE__ */ jsx(
70957
+ ProgressBar$1,
70958
+ {
70959
+ percentage: roundByMagnitudeToFixed(
70960
+ 100 * requestTimer / REQUEST_TIME,
70961
+ 3
70962
+ )
70963
+ }
70964
+ )
70965
+ ] });
70966
+ const footer2 = /* @__PURE__ */ jsxs(Fragment$1, { children: [
70967
+ /* @__PURE__ */ jsx(
70968
+ Button$1,
70969
+ {
70970
+ label: uploadText || "Upload",
70971
+ colored: true,
70972
+ onClick: onConfirm,
70973
+ disabled: !file || isFetching,
70974
+ testId: `${testId}-button-upload`
70975
+ }
70976
+ ),
70977
+ /* @__PURE__ */ jsx(
70978
+ Button$1,
70979
+ {
70980
+ label: cancelText || "Cancel",
70981
+ onClick: onClose,
70982
+ testId: `${testId}-button-cancel`
70983
+ }
70984
+ )
70985
+ ] });
70986
+ useKeyboardEvent("Escape", () => onClose());
70987
+ return /* @__PURE__ */ jsx(Modal, { visible, centered: true, children: /* @__PURE__ */ jsx(
70988
+ Dialog,
70989
+ {
70990
+ dialog: {
70991
+ scroll: true,
70992
+ heading: heading2 || "Smart Upload",
70993
+ content: content2,
70994
+ footer: footer2,
70995
+ onClose,
70996
+ width: width2 || 350,
70997
+ testId
70998
+ }
70999
+ }
71000
+ ) });
71001
+ };
70858
71002
  export {
70859
71003
  Accordion,
70860
71004
  AccordionWithDefaultToggle,
@@ -70919,6 +71063,7 @@ export {
70919
71063
  Select,
70920
71064
  SideBar,
70921
71065
  Slider,
71066
+ SmartUploadModal,
70922
71067
  Spacer,
70923
71068
  Spinner$1 as Spinner,
70924
71069
  Table,