@elliemae/ds-hooks-focus-stack 3.33.0-next.10
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/DSHooksFocusStack.js +79 -0
- package/dist/cjs/DSHooksFocusStack.js.map +7 -0
- package/dist/cjs/index.js +38 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/package.json +7 -0
- package/dist/cjs/react-desc-prop-types.js +39 -0
- package/dist/cjs/react-desc-prop-types.js.map +7 -0
- package/dist/esm/DSHooksFocusStack.js +49 -0
- package/dist/esm/DSHooksFocusStack.js.map +7 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/package.json +7 -0
- package/dist/esm/react-desc-prop-types.js +9 -0
- package/dist/esm/react-desc-prop-types.js.map +7 -0
- package/dist/types/DSHooksFocusStack.d.ts +10 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/react-desc-prop-types.d.ts +7 -0
- package/package.json +71 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var DSHooksFocusStack_exports = {};
|
|
30
|
+
__export(DSHooksFocusStack_exports, {
|
|
31
|
+
UseFocusStackWithSchema: () => UseFocusStackWithSchema,
|
|
32
|
+
useFocusStack: () => useFocusStack
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(DSHooksFocusStack_exports);
|
|
35
|
+
var React = __toESM(require("react"));
|
|
36
|
+
var import_react = require("react");
|
|
37
|
+
var import_ds_utilities = require("@elliemae/ds-utilities");
|
|
38
|
+
var import_ds_props_helpers = require("@elliemae/ds-props-helpers");
|
|
39
|
+
var import_react_desc_prop_types2 = require("./react-desc-prop-types.js");
|
|
40
|
+
const useFocusStack = (props) => {
|
|
41
|
+
const { fallBackRef } = props;
|
|
42
|
+
const [stack, setStack] = (0, import_react.useState)([]);
|
|
43
|
+
const handleOnFocus = (0, import_react.useCallback)(
|
|
44
|
+
(e) => {
|
|
45
|
+
if (e.target !== stack[0] && e.relatedTarget)
|
|
46
|
+
setStack((prev) => [e.relatedTarget, ...prev]);
|
|
47
|
+
else
|
|
48
|
+
setStack((prev) => prev.length > 0 ? prev.slice(1) : prev);
|
|
49
|
+
},
|
|
50
|
+
[stack]
|
|
51
|
+
);
|
|
52
|
+
const config = (0, import_react.useMemo)(
|
|
53
|
+
() => ({
|
|
54
|
+
onBlur: () => setStack([])
|
|
55
|
+
}),
|
|
56
|
+
[]
|
|
57
|
+
);
|
|
58
|
+
const handleOnBlur = (0, import_ds_utilities.useOnBlurOut)(config);
|
|
59
|
+
const focusLastElement = (0, import_react.useCallback)(() => {
|
|
60
|
+
if (stack.length > 0 && stack[0]?.checkVisibility()) {
|
|
61
|
+
stack[0]?.focus();
|
|
62
|
+
} else {
|
|
63
|
+
fallBackRef.current?.focus();
|
|
64
|
+
}
|
|
65
|
+
}, [fallBackRef, stack]);
|
|
66
|
+
return (0, import_react.useMemo)(
|
|
67
|
+
() => ({ trackFocus: handleOnFocus, cleanStack: handleOnBlur, stack, focusLastElement }),
|
|
68
|
+
[handleOnFocus, handleOnBlur, stack, focusLastElement]
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
const UseFocusStackWithSchema = (0, import_ds_props_helpers.describe)(useFocusStack);
|
|
72
|
+
UseFocusStackWithSchema.propTypes = import_react_desc_prop_types2.propTypes;
|
|
73
|
+
UseFocusStackWithSchema.returnType = {
|
|
74
|
+
stack: import_ds_props_helpers.PropTypes.object.description("The stack of elements that have been focused").isRequired,
|
|
75
|
+
trackFocus: import_ds_props_helpers.PropTypes.func.description("The function to be invoked when focus enters the wrapping container").signature("((e: React.FocusEvent<HTMLElement>) => void)").isRequired,
|
|
76
|
+
cleanStack: import_ds_props_helpers.PropTypes.func.description("The function to be invoked when focus exits the wrapping container").signature("((e: React.FocusEvent<HTMLElement>) => void)").isRequired,
|
|
77
|
+
focusLastElement: import_ds_props_helpers.PropTypes.func.description("Focuses the last element in the stack").signature("() => void").isRequired
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=DSHooksFocusStack.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/DSHooksFocusStack.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["import { useCallback, useMemo, useState } from 'react';\nimport { useOnBlurOut } from '@elliemae/ds-utilities';\nimport { describe, PropTypes } from '@elliemae/ds-props-helpers';\nimport { type DSHooksFocusStackT } from './react-desc-prop-types.js';\nimport { propTypes } from './react-desc-prop-types.js';\nconst useFocusStack = (props: DSHooksFocusStackT.Props) => {\n const { fallBackRef } = props;\n const [stack, setStack] = useState<HTMLElement[]>([]);\n\n const handleOnFocus: React.FocusEventHandler<HTMLElement> = useCallback(\n (e) => {\n // check if the new focused element is not the first element in the stack\n // if it is, remove it from the stack\n if (e.target !== stack[0] && e.relatedTarget) setStack((prev) => [e.relatedTarget as HTMLElement, ...prev]);\n else setStack((prev) => (prev.length > 0 ? prev.slice(1) : prev));\n },\n [stack],\n );\n\n const config = useMemo(\n () => ({\n onBlur: () => setStack([]),\n }),\n [],\n );\n const handleOnBlur = useOnBlurOut(config);\n\n const focusLastElement = useCallback(() => {\n if (stack.length > 0 && stack[0]?.checkVisibility()) {\n stack[0]?.focus();\n } else {\n fallBackRef.current?.focus();\n }\n }, [fallBackRef, stack]);\n\n return useMemo(\n () => ({ trackFocus: handleOnFocus, cleanStack: handleOnBlur, stack, focusLastElement }),\n [handleOnFocus, handleOnBlur, stack, focusLastElement],\n );\n};\n\nconst UseFocusStackWithSchema = describe(useFocusStack);\nUseFocusStackWithSchema.propTypes = propTypes;\nUseFocusStackWithSchema.returnType = {\n stack: PropTypes.object.description('The stack of elements that have been focused').isRequired,\n trackFocus: PropTypes.func\n .description('The function to be invoked when focus enters the wrapping container')\n .signature('((e: React.FocusEvent<HTMLElement>) => void)').isRequired,\n cleanStack: PropTypes.func\n .description('The function to be invoked when focus exits the wrapping container')\n .signature('((e: React.FocusEvent<HTMLElement>) => void)').isRequired,\n focusLastElement: PropTypes.func.description('Focuses the last element in the stack').signature('() => void')\n .isRequired,\n};\nexport { useFocusStack, UseFocusStackWithSchema };\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;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qE,EACjF,UAAU,8CAA8C,EAAE;AAAA,EAC7D,YAAY,kCAAU,KACnB,YAAY,oEAAoE,EAChF,UAAU,8CAA8C,EAAE;AAAA,EAC7D,kBAAkB,kCAAU,KAAK,YAAY,uCAAuC,EAAE,UAAU,YAAY,EACzG;AACL;",
|
|
6
|
+
"names": ["import_react_desc_prop_types"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var src_exports = {};
|
|
30
|
+
__export(src_exports, {
|
|
31
|
+
UseFocusStackWithSchema: () => import_DSHooksFocusStack.UseFocusStackWithSchema,
|
|
32
|
+
useFocusStack: () => import_DSHooksFocusStack.useFocusStack
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(src_exports);
|
|
35
|
+
var React = __toESM(require("react"));
|
|
36
|
+
var import_DSHooksFocusStack = require("./DSHooksFocusStack.js");
|
|
37
|
+
var import_react_desc_prop_types = require("./react-desc-prop-types.js");
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/index.ts", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["export { UseFocusStackWithSchema, useFocusStack } from './DSHooksFocusStack.js';\nexport { type DSHooksFocusStackT } from './react-desc-prop-types.js';\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,+BAAuD;AACvD,mCAAwC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var react_desc_prop_types_exports = {};
|
|
30
|
+
__export(react_desc_prop_types_exports, {
|
|
31
|
+
propTypes: () => propTypes
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(react_desc_prop_types_exports);
|
|
34
|
+
var React = __toESM(require("react"));
|
|
35
|
+
var import_ds_utilities = require("@elliemae/ds-utilities");
|
|
36
|
+
const propTypes = {
|
|
37
|
+
fallBackRef: import_ds_utilities.PropTypes.object.description("The fallback ref to focus when the stack is empty").isRequired
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=react-desc-prop-types.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/react-desc-prop-types.ts", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/no-empty-interface */\n\nimport type React from 'react';\nimport { PropTypes } from '@elliemae/ds-utilities';\nexport declare namespace DSHooksFocusStackT {\n interface Props {\n fallBackRef: React.RefObject<HTMLElement>;\n }\n}\n\nexport const propTypes = {\n fallBackRef: PropTypes.object.description('The fallback ref to focus when the stack is empty').isRequired,\n} as React.WeakValidationMap<unknown>;\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADGvB,0BAA0B;AAOnB,MAAM,YAAY;AAAA,EACvB,aAAa,8BAAU,OAAO,YAAY,mDAAmD,EAAE;AACjG;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useCallback, useMemo, useState } from "react";
|
|
3
|
+
import { useOnBlurOut } from "@elliemae/ds-utilities";
|
|
4
|
+
import { describe, PropTypes } from "@elliemae/ds-props-helpers";
|
|
5
|
+
import { propTypes } from "./react-desc-prop-types.js";
|
|
6
|
+
const useFocusStack = (props) => {
|
|
7
|
+
const { fallBackRef } = props;
|
|
8
|
+
const [stack, setStack] = useState([]);
|
|
9
|
+
const handleOnFocus = useCallback(
|
|
10
|
+
(e) => {
|
|
11
|
+
if (e.target !== stack[0] && e.relatedTarget)
|
|
12
|
+
setStack((prev) => [e.relatedTarget, ...prev]);
|
|
13
|
+
else
|
|
14
|
+
setStack((prev) => prev.length > 0 ? prev.slice(1) : prev);
|
|
15
|
+
},
|
|
16
|
+
[stack]
|
|
17
|
+
);
|
|
18
|
+
const config = useMemo(
|
|
19
|
+
() => ({
|
|
20
|
+
onBlur: () => setStack([])
|
|
21
|
+
}),
|
|
22
|
+
[]
|
|
23
|
+
);
|
|
24
|
+
const handleOnBlur = useOnBlurOut(config);
|
|
25
|
+
const focusLastElement = useCallback(() => {
|
|
26
|
+
if (stack.length > 0 && stack[0]?.checkVisibility()) {
|
|
27
|
+
stack[0]?.focus();
|
|
28
|
+
} else {
|
|
29
|
+
fallBackRef.current?.focus();
|
|
30
|
+
}
|
|
31
|
+
}, [fallBackRef, stack]);
|
|
32
|
+
return useMemo(
|
|
33
|
+
() => ({ trackFocus: handleOnFocus, cleanStack: handleOnBlur, stack, focusLastElement }),
|
|
34
|
+
[handleOnFocus, handleOnBlur, stack, focusLastElement]
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
const UseFocusStackWithSchema = describe(useFocusStack);
|
|
38
|
+
UseFocusStackWithSchema.propTypes = propTypes;
|
|
39
|
+
UseFocusStackWithSchema.returnType = {
|
|
40
|
+
stack: PropTypes.object.description("The stack of elements that have been focused").isRequired,
|
|
41
|
+
trackFocus: PropTypes.func.description("The function to be invoked when focus enters the wrapping container").signature("((e: React.FocusEvent<HTMLElement>) => void)").isRequired,
|
|
42
|
+
cleanStack: PropTypes.func.description("The function to be invoked when focus exits the wrapping container").signature("((e: React.FocusEvent<HTMLElement>) => void)").isRequired,
|
|
43
|
+
focusLastElement: PropTypes.func.description("Focuses the last element in the stack").signature("() => void").isRequired
|
|
44
|
+
};
|
|
45
|
+
export {
|
|
46
|
+
UseFocusStackWithSchema,
|
|
47
|
+
useFocusStack
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=DSHooksFocusStack.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/DSHooksFocusStack.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useCallback, useMemo, useState } from 'react';\nimport { useOnBlurOut } from '@elliemae/ds-utilities';\nimport { describe, PropTypes } from '@elliemae/ds-props-helpers';\nimport { type DSHooksFocusStackT } from './react-desc-prop-types.js';\nimport { propTypes } from './react-desc-prop-types.js';\nconst useFocusStack = (props: DSHooksFocusStackT.Props) => {\n const { fallBackRef } = props;\n const [stack, setStack] = useState<HTMLElement[]>([]);\n\n const handleOnFocus: React.FocusEventHandler<HTMLElement> = useCallback(\n (e) => {\n // check if the new focused element is not the first element in the stack\n // if it is, remove it from the stack\n if (e.target !== stack[0] && e.relatedTarget) setStack((prev) => [e.relatedTarget as HTMLElement, ...prev]);\n else setStack((prev) => (prev.length > 0 ? prev.slice(1) : prev));\n },\n [stack],\n );\n\n const config = useMemo(\n () => ({\n onBlur: () => setStack([]),\n }),\n [],\n );\n const handleOnBlur = useOnBlurOut(config);\n\n const focusLastElement = useCallback(() => {\n if (stack.length > 0 && stack[0]?.checkVisibility()) {\n stack[0]?.focus();\n } else {\n fallBackRef.current?.focus();\n }\n }, [fallBackRef, stack]);\n\n return useMemo(\n () => ({ trackFocus: handleOnFocus, cleanStack: handleOnBlur, stack, focusLastElement }),\n [handleOnFocus, handleOnBlur, stack, focusLastElement],\n );\n};\n\nconst UseFocusStackWithSchema = describe(useFocusStack);\nUseFocusStackWithSchema.propTypes = propTypes;\nUseFocusStackWithSchema.returnType = {\n stack: PropTypes.object.description('The stack of elements that have been focused').isRequired,\n trackFocus: PropTypes.func\n .description('The function to be invoked when focus enters the wrapping container')\n .signature('((e: React.FocusEvent<HTMLElement>) => void)').isRequired,\n cleanStack: PropTypes.func\n .description('The function to be invoked when focus exits the wrapping container')\n .signature('((e: React.FocusEvent<HTMLElement>) => void)').isRequired,\n focusLastElement: PropTypes.func.description('Focuses the last element in the stack').signature('() => void')\n .isRequired,\n};\nexport { useFocusStack, UseFocusStackWithSchema };\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,aAAa,SAAS,gBAAgB;AAC/C,SAAS,oBAAoB;AAC7B,SAAS,UAAU,iBAAiB;AAEpC,SAAS,iBAAiB;AAC1B,MAAM,gBAAgB,CAAC,UAAoC;AACzD,QAAM,EAAE,YAAY,IAAI;AACxB,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAwB,CAAC,CAAC;AAEpD,QA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ources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export { UseFocusStackWithSchema, useFocusStack } from './DSHooksFocusStack.js';\nexport { type DSHooksFocusStackT } from './react-desc-prop-types.js';\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,yBAAyB,qBAAqB;AACvD,eAAwC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { PropTypes } from "@elliemae/ds-utilities";
|
|
3
|
+
const propTypes = {
|
|
4
|
+
fallBackRef: PropTypes.object.description("The fallback ref to focus when the stack is empty").isRequired
|
|
5
|
+
};
|
|
6
|
+
export {
|
|
7
|
+
propTypes
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=react-desc-prop-types.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/react-desc-prop-types.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable @typescript-eslint/no-empty-interface */\n\nimport type React from 'react';\nimport { PropTypes } from '@elliemae/ds-utilities';\nexport declare namespace DSHooksFocusStackT {\n interface Props {\n fallBackRef: React.RefObject<HTMLElement>;\n }\n}\n\nexport const propTypes = {\n fallBackRef: PropTypes.object.description('The fallback ref to focus when the stack is empty').isRequired,\n} as React.WeakValidationMap<unknown>;\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACGvB,SAAS,iBAAiB;AAOnB,MAAM,YAAY;AAAA,EACvB,aAAa,UAAU,OAAO,YAAY,mDAAmD,EAAE;AACjG;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { type DSHooksFocusStackT } from './react-desc-prop-types.js';
|
|
3
|
+
declare const useFocusStack: (props: DSHooksFocusStackT.Props) => {
|
|
4
|
+
trackFocus: import("react").FocusEventHandler<HTMLElement>;
|
|
5
|
+
cleanStack: import("@elliemae/ds-utilities").DSHooksUseOBlurOutT.OnBlurCb;
|
|
6
|
+
stack: HTMLElement[];
|
|
7
|
+
focusLastElement: () => void;
|
|
8
|
+
};
|
|
9
|
+
declare const UseFocusStackWithSchema: import("@elliemae/ds-props-helpers/dist/types/propTypes/types.js").DocumentedReactComponent<DSHooksFocusStackT.Props>;
|
|
10
|
+
export { useFocusStack, UseFocusStackWithSchema };
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elliemae/ds-hooks-focus-stack",
|
|
3
|
+
"version": "3.33.0-next.10",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "ICE MT - Dimsum - Hooks Focus Stack",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"module": "./dist/esm/index.js",
|
|
10
|
+
"main": "./dist/cjs/index.js",
|
|
11
|
+
"types": "./dist/types/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/esm/index.js",
|
|
15
|
+
"require": "./dist/cjs/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"sideEffects": [
|
|
19
|
+
"*.css",
|
|
20
|
+
"*.scss"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://git.elliemae.io/platform-ui/dimsum.git"
|
|
25
|
+
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"pnpm": ">=6",
|
|
28
|
+
"node": ">=16"
|
|
29
|
+
},
|
|
30
|
+
"author": "ICE MT",
|
|
31
|
+
"jestSonar": {
|
|
32
|
+
"sonar56x": true,
|
|
33
|
+
"reportPath": "reports",
|
|
34
|
+
"reportFile": "tests.xml",
|
|
35
|
+
"indent": 4
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@elliemae/ds-props-helpers": "3.33.0-next.10",
|
|
39
|
+
"@elliemae/ds-utilities": "3.33.0-next.10"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@elliemae/pui-cli": "~9.0.0-next.31",
|
|
43
|
+
"@xstyled/system": "3.7.0",
|
|
44
|
+
"styled-components": "~5.3.9",
|
|
45
|
+
"styled-system": "~5.1.5",
|
|
46
|
+
"@elliemae/ds-monorepo-devops": "3.33.0-next.10"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"lodash": "^4.17.21",
|
|
50
|
+
"react": "~17.0.2",
|
|
51
|
+
"react-dom": "^17.0.2",
|
|
52
|
+
"styled-components": "~5.3.9",
|
|
53
|
+
"styled-system": "^5.1.5"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public",
|
|
57
|
+
"typeSafety": true
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"dev": "cross-env NODE_ENV=development node ../../../scripts/build/build.mjs --watch",
|
|
61
|
+
"test": "pui-cli test --passWithNoTests --coverage=\"false\"",
|
|
62
|
+
"lint": "node ../../../scripts/lint.mjs --fix",
|
|
63
|
+
"eslint:fix": "eslint --ext='.js,.jsx,.test.js,.ts,.tsx' --fix --config='../../../.eslintrc.js' src/",
|
|
64
|
+
"dts": "node ../../../scripts/dts.mjs",
|
|
65
|
+
"dts:withdeps": "pnpm --filter {.}... dts",
|
|
66
|
+
"build": "cross-env NODE_ENV=production node ../../../scripts/build/build.mjs",
|
|
67
|
+
"dev:build": "pnpm --filter {.}... build",
|
|
68
|
+
"dev:install": "pnpm --filter {.}... i --no-lockfile && pnpm run dev:build",
|
|
69
|
+
"checkDeps": "npm exec ../../util/ds-codemods -- check-missing-packages --projectFolderPath=\"./\" --ignorePackagesGlobPattern=\"\" --ignoreFilesGlobPattern=\"**/test-ables/*,**/tests/*\""
|
|
70
|
+
}
|
|
71
|
+
}
|