dry-ux 1.52.0 → 1.54.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.
@@ -111,8 +111,15 @@ const fnWithAuthCheck = (fn, authCheckUrl, authRedirectUrl) => fetch(authCheckUr
111
111
  }
112
112
  });
113
113
  exports.fnWithAuthCheck = fnWithAuthCheck;
114
- exports.StorageUtils = {
115
- isStorageAvailable: function () {
114
+ /**
115
+ * Utility class for storage-related operations.
116
+ */
117
+ class StorageUtils {
118
+ /**
119
+ * Checks if the storage is available.
120
+ * @returns A boolean indicating if the storage is available.
121
+ */
122
+ static isStorageAvailable() {
116
123
  let available = typeof Storage !== "undefined";
117
124
  try {
118
125
  if (available)
@@ -122,8 +129,14 @@ exports.StorageUtils = {
122
129
  available = false;
123
130
  }
124
131
  return available;
125
- },
126
- };
132
+ }
133
+ }
134
+ exports.StorageUtils = StorageUtils;
135
+ /**
136
+ * Converts a string to a hash code.
137
+ * @param input The string to convert.
138
+ * @returns The hash code of the input string.
139
+ */
127
140
  const toHashCode = (input) => {
128
141
  let hash = 0;
129
142
  if (input.length === 0)
@@ -135,6 +148,11 @@ const toHashCode = (input) => {
135
148
  return hash;
136
149
  };
137
150
  exports.toHashCode = toHashCode;
151
+ /**
152
+ * Inserts a URL parameter.
153
+ * @param key The key of the parameter.
154
+ * @param value The value of the parameter.
155
+ */
138
156
  const insertUrlParam = (key, value) => {
139
157
  if (history.pushState) {
140
158
  let searchParams = new URLSearchParams(window.location.search);
@@ -149,8 +167,16 @@ const insertUrlParam = (key, value) => {
149
167
  }
150
168
  };
151
169
  exports.insertUrlParam = insertUrlParam;
170
+ /**
171
+ * Inserts multiple URL parameters.
172
+ * @param params An object containing key-value pairs of parameters.
173
+ */
152
174
  const insertUrlParams = (params) => Object.keys(params).forEach(key => (0, exports.insertUrlParam)(key, params[key]));
153
175
  exports.insertUrlParams = insertUrlParams;
176
+ /**
177
+ * Retrieves URL parameters as an object.
178
+ * @returns An object containing the URL parameters.
179
+ */
154
180
  const getUrlParams = () => {
155
181
  const searchParams = new URLSearchParams(window.location.search);
156
182
  const params = {};
@@ -160,6 +186,9 @@ const getUrlParams = () => {
160
186
  return params;
161
187
  };
162
188
  exports.getUrlParams = getUrlParams;
189
+ /**
190
+ * A class representing a deferred promise.
191
+ */
163
192
  class Deferred {
164
193
  constructor() {
165
194
  this.promise = new Promise((resolve, reject) => {
@@ -167,14 +196,26 @@ class Deferred {
167
196
  this._reject = reject;
168
197
  });
169
198
  }
199
+ /**
200
+ * Resolves the promise with the given result.
201
+ */
170
202
  get resolve() {
171
203
  return this._resolve;
172
204
  }
205
+ /**
206
+ * Rejects the promise with the given error.
207
+ */
173
208
  get reject() {
174
209
  return this._reject;
175
210
  }
176
211
  }
177
212
  exports.Deferred = Deferred;
213
+ /**
214
+ * Parses a JSON string and returns the corresponding object.
215
+ * @param json The JSON string to parse.
216
+ * @param errorValue The value to return if parsing fails.
217
+ * @returns The parsed object or the error value.
218
+ */
178
219
  const tryParseJson = (json, errorValue = {}) => {
179
220
  try {
180
221
  return JSON.parse(json);
@@ -184,6 +225,11 @@ const tryParseJson = (json, errorValue = {}) => {
184
225
  }
185
226
  };
186
227
  exports.tryParseJson = tryParseJson;
228
+ /**
229
+ * Hook to check if an element is visible in the viewport.
230
+ * @param ref The reference to the element.
231
+ * @returns A boolean indicating if the element is visible.
232
+ */
187
233
  const useIsVisible = (ref) => {
188
234
  const [isIntersecting, setIntersecting] = React.useState(false);
189
235
  React.useEffect(() => {
@@ -196,13 +242,32 @@ const useIsVisible = (ref) => {
196
242
  return isIntersecting;
197
243
  };
198
244
  exports.useIsVisible = useIsVisible;
245
+ /**
246
+ * Hook to publish and subscribe to custom events.
247
+ * @returns An object containing the usePub and useSub hooks.
248
+ */
199
249
  const usePubSub = () => {
200
250
  const getEventName = (event) => `dry-ux-event-${event}`;
251
+ /**
252
+ * Publishes a custom event with the specified name and data.
253
+ * @template TName The type of the event name.
254
+ * @template TPayload The type of the event payload.
255
+ * @param event The name of the event to publish.
256
+ * @param data The data to include in the event payload.
257
+ */
201
258
  const usePub = () => (event, data) => {
202
259
  document.dispatchEvent(new CustomEvent(getEventName(event), {
203
260
  detail: data,
204
261
  }));
205
262
  };
263
+ /**
264
+ * Subscribes to a custom event with the specified name and calls the callback when the event is triggered.
265
+ * @template TName The type of the event name.
266
+ * @template TPayload The type of the event payload.
267
+ * @param event The name of the event to subscribe to.
268
+ * @param callback The function to call when the event is triggered.
269
+ * @returns A function to unsubscribe from the event.
270
+ */
206
271
  const useSub = (event, callback) => {
207
272
  const controller = new AbortController();
208
273
  const unsubscribe = () => controller.abort();
package/dist/index.d.ts CHANGED
@@ -14,3 +14,6 @@ export { ErrorScreen } from "./error/ErrorScreen";
14
14
  export { Loader } from "./ui-utils/Loader";
15
15
  export { Spinner } from "./ui-utils/Spinner";
16
16
  export { RenderWhenVisible } from "./ui-utils/RenderWhenVisible";
17
+ export { Validation, Element } from "./enhanced-inputs/Validaition";
18
+ export * from "./enhanced-inputs/HTMLInputs";
19
+ export * from "./enhanced-inputs/interface";
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.RenderWhenVisible = exports.Spinner = exports.Loader = exports.ErrorScreen = exports.ErrorBoundary = exports.DajaxiceProxy = exports.unflatten = exports.flatten = exports.classSet = exports.DryUXProvider = exports.Money = exports.DryUXRenderer = exports.DryUXContext = exports.useDryUxContext = void 0;
17
+ exports.Element = exports.Validation = exports.RenderWhenVisible = exports.Spinner = exports.Loader = exports.ErrorScreen = exports.ErrorBoundary = exports.DajaxiceProxy = exports.unflatten = exports.flatten = exports.classSet = exports.DryUXProvider = exports.Money = exports.DryUXRenderer = exports.DryUXContext = exports.useDryUxContext = void 0;
18
18
  var UIUtilProvider_1 = require("./ui-utils/UIUtilProvider");
19
19
  Object.defineProperty(exports, "useDryUxContext", { enumerable: true, get: function () { return UIUtilProvider_1.useUIUtilContext; } });
20
20
  Object.defineProperty(exports, "DryUXContext", { enumerable: true, get: function () { return UIUtilProvider_1.UIUtilContext; } });
@@ -44,3 +44,8 @@ var Spinner_1 = require("./ui-utils/Spinner");
44
44
  Object.defineProperty(exports, "Spinner", { enumerable: true, get: function () { return Spinner_1.Spinner; } });
45
45
  var RenderWhenVisible_1 = require("./ui-utils/RenderWhenVisible");
46
46
  Object.defineProperty(exports, "RenderWhenVisible", { enumerable: true, get: function () { return RenderWhenVisible_1.RenderWhenVisible; } });
47
+ var Validaition_1 = require("./enhanced-inputs/Validaition");
48
+ Object.defineProperty(exports, "Validation", { enumerable: true, get: function () { return Validaition_1.Validation; } });
49
+ Object.defineProperty(exports, "Element", { enumerable: true, get: function () { return Validaition_1.Element; } });
50
+ __exportStar(require("./enhanced-inputs/HTMLInputs"), exports);
51
+ __exportStar(require("./enhanced-inputs/interface"), exports);
@@ -1,11 +1,31 @@
1
+ /**
2
+ * A singleton class that manages the display of a fullscreen loader spinner.
3
+ */
1
4
  export declare class Loader {
2
5
  private readonly spinnerStyles;
3
6
  private readonly elementId;
4
7
  private static instance;
5
8
  private constructor();
9
+ /**
10
+ * Returns the singleton instance of the Loader class.
11
+ * @returns The Loader instance.
12
+ */
6
13
  static getInstance(): Loader;
14
+ /**
15
+ * Gets the loader element from the DOM.
16
+ * @returns The loader element.
17
+ */
7
18
  get element(): HTMLElement;
19
+ /**
20
+ * Shows the loader by setting its visibility to visible.
21
+ */
8
22
  show(): void;
23
+ /**
24
+ * Hides the loader by setting its visibility to hidden.
25
+ */
9
26
  hide(): void;
27
+ /**
28
+ * Adds the loader elements to the DOM if they do not already exist.
29
+ */
10
30
  private addElementsIfNotExists;
11
31
  }
@@ -2,29 +2,49 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Loader = void 0;
4
4
  const SpinnerStyles_1 = require("./SpinnerStyles");
5
+ /**
6
+ * A singleton class that manages the display of a fullscreen loader spinner.
7
+ */
5
8
  class Loader {
6
9
  constructor() {
7
10
  this.spinnerStyles = SpinnerStyles_1.SpinnerStyles.getInstance();
8
11
  this.elementId = "dry-ux-loader";
9
12
  }
13
+ /**
14
+ * Returns the singleton instance of the Loader class.
15
+ * @returns The Loader instance.
16
+ */
10
17
  static getInstance() {
11
18
  if (!Loader.instance) {
12
19
  Loader.instance = new Loader();
13
20
  }
14
21
  return Loader.instance;
15
22
  }
23
+ /**
24
+ * Gets the loader element from the DOM.
25
+ * @returns The loader element.
26
+ */
16
27
  get element() {
17
28
  return document.getElementById(this.elementId);
18
29
  }
30
+ /**
31
+ * Shows the loader by setting its visibility to visible.
32
+ */
19
33
  show() {
20
34
  this.addElementsIfNotExists();
21
35
  this.element.style.visibility = "visible";
22
36
  }
37
+ /**
38
+ * Hides the loader by setting its visibility to hidden.
39
+ */
23
40
  hide() {
24
41
  if (this.element) {
25
42
  this.element.style.visibility = "hidden";
26
43
  }
27
44
  }
45
+ /**
46
+ * Adds the loader elements to the DOM if they do not already exist.
47
+ */
28
48
  addElementsIfNotExists() {
29
49
  this.spinnerStyles.add();
30
50
  if (!this.element) {
@@ -10,6 +10,7 @@ export interface IModalProps {
10
10
  };
11
11
  defaultModalStyles?: boolean;
12
12
  setBackdropHeight?: boolean;
13
+ centered?: boolean;
13
14
  };
14
15
  }
15
16
  declare const Modal: React.FC<IModalProps & {
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const React = require("react");
4
4
  const react_bootstrap_1 = require("react-bootstrap");
5
- const Modal = React.memo(({ handleClose, shown, options: { content, footerContent, cssClass, closeBtn, title, width, onClose, titleCloseBtn = true }, config: { defaultModalStyles = false, styles = {}, setBackdropHeight = true }, }) => {
5
+ const Modal = React.memo(({ handleClose, shown, options: { content, footerContent, cssClass, closeBtn, title, width, onClose, titleCloseBtn = true, centered }, config: { defaultModalStyles = false, styles = {}, setBackdropHeight = true, centered: globalCentered }, }) => {
6
+ const isCentered = centered !== null && centered !== void 0 ? centered : globalCentered;
6
7
  const applyStyles = React.useCallback(() => {
7
8
  document.querySelectorAll(".modal-dialog").forEach((el) => {
8
9
  el.style.width = typeof width == "number" ? `${width}px` : width;
@@ -12,6 +13,13 @@ const Modal = React.memo(({ handleClose, shown, options: { content, footerConten
12
13
  el.querySelectorAll(".modal-header").forEach((el) => (el.style.display = "block"));
13
14
  el.querySelectorAll(".modal-title").forEach((el) => (el.style.marginTop = "0"));
14
15
  }
16
+ if (isCentered) {
17
+ el.style.position = "absolute";
18
+ el.style.transform = "translate(-50%, -50%)";
19
+ el.style.top = "50%";
20
+ el.style.left = "50%";
21
+ el.style.marginTop = "unset";
22
+ }
15
23
  });
16
24
  document.querySelectorAll("[role=dialog]").forEach((el) => (el.style.opacity = "1"));
17
25
  if (setBackdropHeight) {
@@ -26,24 +34,24 @@ const Modal = React.memo(({ handleClose, shown, options: { content, footerConten
26
34
  });
27
35
  });
28
36
  });
29
- }, [width, defaultModalStyles]);
37
+ }, [width, defaultModalStyles, isCentered, styles, setBackdropHeight]);
30
38
  React.useEffect(() => {
31
39
  if (shown) {
32
40
  applyStyles();
33
41
  }
34
42
  }, [shown, width, defaultModalStyles]);
35
- const hide = () => {
43
+ const onHide = () => {
36
44
  handleClose();
37
45
  onClose && onClose();
38
46
  };
39
47
  const contentToRender = typeof content == "string" ? React.createElement("div", { dangerouslySetInnerHTML: { __html: content } }) : content;
40
48
  const showFooter = closeBtn || footerContent;
41
- return (React.createElement(react_bootstrap_1.Modal, { onHide: hide, show: shown, animation: true, autoFocus: true, keyboard: false, className: cssClass, backdropStyle: { zIndex: 1040, opacity: 0.5 }, backdrop: "static" },
42
- !!title && (React.createElement(react_bootstrap_1.Modal.Header, { closeButton: titleCloseBtn, onHide: hide },
49
+ return (React.createElement(react_bootstrap_1.Modal, { onHide: onHide, show: shown, animation: true, autoFocus: true, keyboard: false, className: cssClass, backdropStyle: { zIndex: 1040, opacity: 0.5 }, backdrop: "static" },
50
+ !!title && (React.createElement(react_bootstrap_1.Modal.Header, { closeButton: titleCloseBtn, onHide: onHide },
43
51
  React.createElement(react_bootstrap_1.Modal.Title, null, title))),
44
52
  React.createElement(react_bootstrap_1.Modal.Body, null, contentToRender),
45
53
  showFooter && (React.createElement(react_bootstrap_1.Modal.Footer, null,
46
54
  footerContent,
47
- closeBtn && (React.createElement(react_bootstrap_1.Button, { bsClass: "btn btn-danger", onClick: hide }, "Close"))))));
55
+ closeBtn && (React.createElement(react_bootstrap_1.Button, { bsClass: "btn btn-danger", onClick: onHide }, "Close"))))));
48
56
  });
49
57
  exports.default = Modal;
@@ -1,4 +1,11 @@
1
1
  import * as React from "react";
2
+ /**
3
+ * A React component that renders its children only when they become visible in the viewport.
4
+ * @param children The JSX element to render when visible.
5
+ * @param onLoad An optional callback function to call when the children are loaded.
6
+ * @param minHeight An optional minimum height for the container to ensure visibility.
7
+ * @returns A JSX element that conditionally renders its children based on visibility.
8
+ */
2
9
  export declare const RenderWhenVisible: React.FC<{
3
10
  children: JSX.Element;
4
11
  onLoad?: () => void;
@@ -3,6 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RenderWhenVisible = void 0;
4
4
  const React = require("react");
5
5
  const utilities_1 = require("../helpers/utilities");
6
+ /**
7
+ * A React component that renders its children only when they become visible in the viewport.
8
+ * @param children The JSX element to render when visible.
9
+ * @param onLoad An optional callback function to call when the children are loaded.
10
+ * @param minHeight An optional minimum height for the container to ensure visibility.
11
+ * @returns A JSX element that conditionally renders its children based on visibility.
12
+ */
6
13
  exports.RenderWhenVisible = React.memo(({ children, minHeight, onLoad }) => {
7
14
  const [isLoaded, setIsLoaded] = React.useState(false);
8
15
  const ref = React.useRef(null);
@@ -1,2 +1,7 @@
1
1
  import * as React from "react";
2
+ /**
3
+ * A React component that renders a spinner.
4
+ * The spinner styles are added when the component is mounted.
5
+ * @returns A JSX element representing the spinner.
6
+ */
2
7
  export declare const Spinner: React.MemoExoticComponent<() => React.JSX.Element>;
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Spinner = void 0;
4
4
  const React = require("react");
5
5
  const SpinnerStyles_1 = require("./SpinnerStyles");
6
+ /**
7
+ * A React component that renders a spinner.
8
+ * The spinner styles are added when the component is mounted.
9
+ * @returns A JSX element representing the spinner.
10
+ */
6
11
  exports.Spinner = React.memo(() => {
7
12
  React.useEffect(() => {
8
13
  const spinnerStyles = SpinnerStyles_1.SpinnerStyles.getInstance();
@@ -49,6 +49,10 @@ export type PopUpOptions = {
49
49
  * If true, the modal will be destroyed when it is closed.
50
50
  */
51
51
  destroyOnClose?: boolean;
52
+ /**
53
+ * If true, the modal will be centered vertically.
54
+ */
55
+ centered?: boolean;
52
56
  };
53
57
  export type ButtonType = "primary" | "info" | "success" | "warning" | "danger";
54
58
  export type PopUpAction = {
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "dry-ux",
3
- "version": "1.52.0",
3
+ "version": "1.54.0",
4
4
  "description": "",
5
5
  "main": "dist/index",
6
6
  "scripts": {
7
- "build": "rimraf dist/ && tsc",
7
+ "copy-css": "copyfiles -u 2 \"./src/enhanced-inputs/styles.css\" \"./dist/enhanced-inputs\"",
8
+ "build": "rimraf dist/ && tsc && npm run copy-css",
8
9
  "watch": "rimraf dist/ && tsc --watch",
9
10
  "format": "prettier --write \"src/**/*.ts\" \"src/**/*.tsx\"",
10
11
  "update:version": "npm version minor --no-git-tag-version",
@@ -23,6 +24,7 @@
23
24
  "author": "Naved Rangwala",
24
25
  "license": "ISC",
25
26
  "devDependencies": {
27
+ "copyfiles": "^2.4.1",
26
28
  "react": "^16.8.2",
27
29
  "react-dom": "^16.8.2",
28
30
  "@types/react": "^17.0.0",