@elliemae/pui-app-sdk 5.9.0 → 5.10.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/cjs/index.js CHANGED
@@ -67,6 +67,7 @@ __export(lib_exports, {
67
67
  TextBox: () => import_text_box.TextBox,
68
68
  Themes: () => import_constants2.Themes,
69
69
  Toggle: () => import_toggle.Toggle,
70
+ UseStateSelectorOptions: () => import_use_state_selector.UseStateSelectorOptions,
70
71
  VisuallyHidden: () => import_visually_hidden.VisuallyHidden,
71
72
  WaitMessage: () => import_wait_message.WaitMessage,
72
73
  ariaLive: () => import_live_message.actions,
@@ -140,6 +141,8 @@ __export(lib_exports, {
140
141
  useInjectSaga: () => import_redux_injectors.useInjectSaga,
141
142
  useInjectSideEffect: () => import_react.useInjectSideEffect,
142
143
  useMediaQueryList: () => import_use_media_query_list.useMediaQueryList,
144
+ useStateSelector: () => import_use_state_selector.useStateSelector,
145
+ useStateSelectorShallow: () => import_use_state_selector.useStateSelectorShallow,
143
146
  waitMessageAction: () => import_actions3.waitMessage,
144
147
  withAppDecorator: () => import_decorator.withAppDecorator
145
148
  });
@@ -156,6 +159,7 @@ var import_page = require("./view/page.js");
156
159
  var import_constants = __toESM(require("./utils/constants.js"));
157
160
  var import_redux_injectors = require("redux-injectors");
158
161
  var import_react = require("./data/react.js");
162
+ var import_use_state_selector = require("./utils/custom-hooks/use-state-selector.js");
159
163
  var import_errorMiddleware = require("./data/errorMiddleware.js");
160
164
  var import_listenerMiddleware = require("./data/listenerMiddleware.js");
161
165
  var import_helper = require("./utils/auth/helper.js");
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var use_state_selector_exports = {};
20
+ __export(use_state_selector_exports, {
21
+ useStateSelector: () => useStateSelector,
22
+ useStateSelectorShallow: () => useStateSelectorShallow
23
+ });
24
+ module.exports = __toCommonJS(use_state_selector_exports);
25
+ var import_react = require("react");
26
+ var import_react_redux = require("react-redux");
27
+ function useStateSelector(selectStateFieldFunc, fieldName = "", {
28
+ defaultValue = void 0,
29
+ equalityFn = void 0
30
+ } = {}) {
31
+ const [finalDefaultValue] = (0, import_react.useState)(
32
+ defaultValue
33
+ );
34
+ return (0, import_react_redux.useSelector)(
35
+ selectStateFieldFunc(fieldName, finalDefaultValue),
36
+ equalityFn
37
+ );
38
+ }
39
+ function useStateSelectorShallow(selectStateFieldFunc, fieldName = "", {
40
+ defaultValue = void 0,
41
+ equalityFn = import_react_redux.shallowEqual
42
+ } = {}) {
43
+ return useStateSelector(selectStateFieldFunc, fieldName, {
44
+ defaultValue,
45
+ equalityFn
46
+ });
47
+ }
package/dist/esm/index.js CHANGED
@@ -23,6 +23,11 @@ import {
23
23
  useAppSelector,
24
24
  useAppMiddleware
25
25
  } from "./data/react.js";
26
+ import {
27
+ useStateSelector,
28
+ useStateSelectorShallow,
29
+ UseStateSelectorOptions
30
+ } from "./utils/custom-hooks/use-state-selector.js";
26
31
  import { errorMiddleware } from "./data/errorMiddleware.js";
27
32
  import {
28
33
  startSideEffect,
@@ -167,6 +172,7 @@ export {
167
172
  TextBox,
168
173
  Themes,
169
174
  Toggle,
175
+ UseStateSelectorOptions,
170
176
  VisuallyHidden,
171
177
  WaitMessage,
172
178
  actions as ariaLive,
@@ -240,6 +246,8 @@ export {
240
246
  useInjectSaga,
241
247
  useInjectSideEffect,
242
248
  useMediaQueryList,
249
+ useStateSelector,
250
+ useStateSelectorShallow,
243
251
  waitMessage as waitMessageAction,
244
252
  withAppDecorator
245
253
  };
@@ -0,0 +1,27 @@
1
+ import { useState } from "react";
2
+ import { useSelector, shallowEqual } from "react-redux";
3
+ function useStateSelector(selectStateFieldFunc, fieldName = "", {
4
+ defaultValue = void 0,
5
+ equalityFn = void 0
6
+ } = {}) {
7
+ const [finalDefaultValue] = useState(
8
+ defaultValue
9
+ );
10
+ return useSelector(
11
+ selectStateFieldFunc(fieldName, finalDefaultValue),
12
+ equalityFn
13
+ );
14
+ }
15
+ function useStateSelectorShallow(selectStateFieldFunc, fieldName = "", {
16
+ defaultValue = void 0,
17
+ equalityFn = shallowEqual
18
+ } = {}) {
19
+ return useStateSelector(selectStateFieldFunc, fieldName, {
20
+ defaultValue,
21
+ equalityFn
22
+ });
23
+ }
24
+ export {
25
+ useStateSelector,
26
+ useStateSelectorShallow
27
+ };
@@ -52,7 +52,7 @@ export declare const getApiActionCreator: (api: string) => (operation: string) =
52
52
  *
53
53
  * export const useSelectSomeState = (fieldName, defaultValue) => {
54
54
  * const finalDefaultValue = useMemo(() => defaultValue, []);
55
- * useSelector(selectSomeState(fieldName, defaultValue), shallowEqual);
55
+ * useSelector(selectSomeState(fieldName, finalDefaultValue), shallowEqual);
56
56
  * }
57
57
  *
58
58
  * // some-component.js
@@ -10,6 +10,7 @@ export { Page } from './view/page.js';
10
10
  export { default as globalConstants } from './utils/constants.js';
11
11
  export { useInjectReducer, useInjectSaga, createManager, } from 'redux-injectors';
12
12
  export { useInjectQuery, useInjectSideEffect, useAppDispatch, useAppSelector, useAppMiddleware, } from './data/react.js';
13
+ export { useStateSelector, useStateSelectorShallow, UseStateSelectorOptions, } from './utils/custom-hooks/use-state-selector.js';
13
14
  export { errorMiddleware } from './data/errorMiddleware.js';
14
15
  export { startSideEffect, createSideEffect, removeSideEffect, clearSideEffects, } from './data/listenerMiddleware.js';
15
16
  export { getAuthorizationHeader } from './utils/auth/helper.js';
@@ -90,3 +91,4 @@ export type { RootState, AppStore, AppDispatch } from './data/types.js';
90
91
  export type { AppConfig } from './utils/app-config/config.js';
91
92
  export type { OnInitCallback, OnMountCallback, OnUnMountCallback, } from './utils/micro-frontend/guest.js';
92
93
  export type { OnInitCallback as OnHostInitCallback } from './utils/micro-frontend/host.js';
94
+ export type { SelectStateFieldFunction } from './utils/custom-hooks/use-state-selector.js';
@@ -0,0 +1,42 @@
1
+ import { EqualityFn } from 'react-redux';
2
+ export type SelectStateFieldFunction<TState = unknown, Selected = unknown> = (fieldName: string | Array<string>, defaultValue?: Selected | Selected[]) => (state: TState) => Selected;
3
+ export interface UseStateSelectorOptions<Selected = unknown> {
4
+ defaultValue?: Selected | Array<Selected>;
5
+ equalityFn?: EqualityFn<Selected>;
6
+ }
7
+ /**
8
+ * Generic selector that receives a field selector function returned from getSelectField
9
+ *
10
+ * @see /lib/api/helpers.ts#getSelectField
11
+ * @param {SelectStateFieldFunction} selectStateFieldFunc the store state's field selector function
12
+ * ```javascript
13
+ * // reducer.js
14
+ * import { getSelectField } from 'elliemae/pui-app-sdk';
15
+ *
16
+ * const name = 'someState';
17
+ * export selectStateFieldFunc = getSelectField(name);
18
+ * ```
19
+ * @param {string | Array<string>} fieldName the state's field you want to acccess, this accepts nested objects access, like so 'rootObj.childObj.field'
20
+ * @param {useStateSelectorOptions} opts options { defaultValue, equalityFn }
21
+ * @returns
22
+ */
23
+ export declare function useStateSelector<TState = unknown, Selected = unknown>(selectStateFieldFunc: SelectStateFieldFunction<TState, Selected>, fieldName?: string | Array<string>, { defaultValue, equalityFn, }?: UseStateSelectorOptions<Selected>): Selected;
24
+ /**
25
+ * Generic selector that receives a field selector function returned from getSelectField.
26
+ *
27
+ * @see /lib/api/helpers.ts#getSelectField
28
+ *
29
+ * This is the same as useStateSelector with shallowEqual as default for equalityFn option.
30
+ * @param {SelectStateFieldFunction} selectStateFieldFunc the store state's field selector function
31
+ * ```javascript
32
+ * // reducer.js
33
+ * import { getSelectField } from 'elliemae/pui-app-sdk';
34
+ *
35
+ * const name = 'someState';
36
+ * export selectStateFieldFunc = getSelectField(name);
37
+ * ```
38
+ * @param {string | Array<string>} fieldName the state's field you want to acccess, this accepts nested objects access, like so 'rootObj.childObj.field'
39
+ * @param {useStateSelectorOptions} opts options { defaultValue, equalityFn = shallowEqual }
40
+ * @returns
41
+ */
42
+ export declare function useStateSelectorShallow<TState = unknown, Selected = unknown>(selectStateFieldFunc: SelectStateFieldFunction<TState, Selected>, fieldName?: string | Array<string>, { defaultValue, equalityFn, }?: UseStateSelectorOptions<Selected>): Selected;
@@ -5,6 +5,6 @@ export declare const Basic: Story<{
5
5
  name: string;
6
6
  defaultValue?: boolean | undefined;
7
7
  rules?: Omit<import("react-hook-form").RegisterOptions<import("react-hook-form").FieldValues, string>, "setValueAs" | "valueAsNumber" | "valueAsDate"> | undefined;
8
- } & Omit<import("@elliemae/ds-controlled-form").DSControlledToggleT.Props, "onChange" | "defaultValue" | "selectedValues"> & {
8
+ } & Omit<import("@elliemae/ds-controlled-form").DSControlledToggleT.Props, "defaultValue" | "onChange" | "selectedValues"> & {
9
9
  label: string;
10
10
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliemae/pui-app-sdk",
3
- "version": "5.9.0",
3
+ "version": "5.10.0",
4
4
  "description": "ICE MT UI Platform Application SDK ",
5
5
  "sideEffects": [
6
6
  "*.css",