dry-ux 1.53.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) {
@@ -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
- export declare const Spinner: React.MemoExoticComponent<() => JSX.Element>;
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
+ */
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();
@@ -1,5 +1,4 @@
1
- /// <reference types="react" />
2
- export declare type PopUp = {
1
+ export type PopUp = {
3
2
  /**
4
3
  * Hides the modal.
5
4
  */
@@ -13,7 +12,7 @@ export declare type PopUp = {
13
12
  */
14
13
  remove: () => void;
15
14
  };
16
- export declare type PopUpOptions = {
15
+ export type PopUpOptions = {
17
16
  /**
18
17
  * The content of the modal.
19
18
  */
@@ -55,8 +54,8 @@ export declare type PopUpOptions = {
55
54
  */
56
55
  centered?: boolean;
57
56
  };
58
- export declare type ButtonType = "primary" | "info" | "success" | "warning" | "danger";
59
- export declare type PopUpAction = {
57
+ export type ButtonType = "primary" | "info" | "success" | "warning" | "danger";
58
+ export type PopUpAction = {
60
59
  /**
61
60
  * The content to display in the modal.
62
61
  */
@@ -74,7 +73,7 @@ export declare type PopUpAction = {
74
73
  */
75
74
  closeOnClick?: boolean;
76
75
  };
77
- export declare type UIUtilModal = {
76
+ export type UIUtilModal = {
78
77
  /**
79
78
  * Creates a non-unique modal.
80
79
  * @param options The options for the modal.
@@ -133,4 +132,4 @@ export interface IUIUtilLoader {
133
132
  */
134
133
  hide: () => void;
135
134
  }
136
- export declare type UIUtilPrompt = Pick<UIUtilModal, "showConfirm" | "showActions" | "instances" | "getCurrent">;
135
+ export type UIUtilPrompt = Pick<UIUtilModal, "showConfirm" | "showActions" | "instances" | "getCurrent">;
@@ -52,5 +52,5 @@ export declare class UIUtilProvider extends React.PureComponent<{}, IUIUtilProvi
52
52
  removeModalInstance(id: string): void;
53
53
  getCurrentModal(id: string): PopUp;
54
54
  createModal(id: string, options: PopUpOptions): PopUp;
55
- render(): JSX.Element;
55
+ render(): React.JSX.Element;
56
56
  }
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { IModalProps } from "./Modal";
3
- export declare type UIUtilRendererProps = {
3
+ export type UIUtilRendererProps = {
4
4
  modalConfig?: IModalProps["config"];
5
5
  };
6
6
  export declare const UIUtilRenderer: React.FC<UIUtilRendererProps>;
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "dry-ux",
3
- "version": "1.53.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",