@elliemae/ds-hooks-on-first-focus-in 3.31.0-next.6
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/DSHookOnFirstFocusIn.js +82 -0
- package/dist/cjs/DSHookOnFirstFocusIn.js.map +7 -0
- package/dist/cjs/index.js +37 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/package.json +7 -0
- package/dist/cjs/react-desc-prop-types.js +28 -0
- package/dist/cjs/react-desc-prop-types.js.map +7 -0
- package/dist/esm/DSHookOnFirstFocusIn.js +52 -0
- package/dist/esm/DSHookOnFirstFocusIn.js.map +7 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/package.json +7 -0
- package/dist/esm/react-desc-prop-types.js +2 -0
- package/dist/esm/react-desc-prop-types.js.map +7 -0
- package/dist/types/DSHookOnFirstFocusIn.d.ts +7 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/react-desc-prop-types.d.ts +12 -0
- package/package.json +67 -0
|
@@ -0,0 +1,82 @@
|
|
|
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 DSHookOnFirstFocusIn_exports = {};
|
|
30
|
+
__export(DSHookOnFirstFocusIn_exports, {
|
|
31
|
+
UseOnFirstFocusInWithSchema: () => UseOnFirstFocusInWithSchema,
|
|
32
|
+
useOnFirstFocusIn: () => useOnFirstFocusIn
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(DSHookOnFirstFocusIn_exports);
|
|
35
|
+
var React = __toESM(require("react"));
|
|
36
|
+
var import_react = require("react");
|
|
37
|
+
var import_ds_props_helpers = require("@elliemae/ds-props-helpers");
|
|
38
|
+
const propTypes = {
|
|
39
|
+
onFirstFocusCb: import_ds_props_helpers.PropTypes.func.description("The function to be invoked when focus enters the wrapping container for the first time").signature("((e: React.FocusEvent, ...args: unknown[]) => void)").isRequired,
|
|
40
|
+
onBlurCb: import_ds_props_helpers.PropTypes.func.description("Optional onBlur function to be invoked along the returned onBlur handler").signature("((e: React.FocusEvent, ...args: unknown[]) => void)")
|
|
41
|
+
};
|
|
42
|
+
const useOnFirstFocusIn = ({ onFirstFocus, onBlur }) => {
|
|
43
|
+
const mutableDidChildBlur = (0, import_react.useRef)(false);
|
|
44
|
+
const onFirstFocusHelper = (0, import_react.useCallback)(
|
|
45
|
+
(e, ...args) => {
|
|
46
|
+
const { currentTarget } = e;
|
|
47
|
+
requestAnimationFrame(() => {
|
|
48
|
+
const isChildFocus = currentTarget.contains(document.activeElement);
|
|
49
|
+
const isFirstFocus = isChildFocus && !mutableDidChildBlur.current;
|
|
50
|
+
if (isFirstFocus) {
|
|
51
|
+
onFirstFocus(e, ...args);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
[onFirstFocus]
|
|
56
|
+
);
|
|
57
|
+
const onBlurHelper = (0, import_react.useCallback)(
|
|
58
|
+
(e, ...args) => {
|
|
59
|
+
onBlur?.(e, ...args);
|
|
60
|
+
const { currentTarget } = e;
|
|
61
|
+
requestAnimationFrame(() => {
|
|
62
|
+
const isChildBlur = currentTarget.contains(document.activeElement);
|
|
63
|
+
mutableDidChildBlur.current = isChildBlur;
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
[onBlur]
|
|
67
|
+
);
|
|
68
|
+
return (0, import_react.useMemo)(
|
|
69
|
+
() => ({
|
|
70
|
+
onFirstFocus: onFirstFocusHelper,
|
|
71
|
+
onBlur: onBlurHelper
|
|
72
|
+
}),
|
|
73
|
+
[onFirstFocusHelper, onBlurHelper]
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
const UseOnFirstFocusInWithSchema = (0, import_ds_props_helpers.describe)(useOnFirstFocusIn);
|
|
77
|
+
UseOnFirstFocusInWithSchema.propTypes = propTypes;
|
|
78
|
+
UseOnFirstFocusInWithSchema.returnType = {
|
|
79
|
+
onFirstFocus: import_ds_props_helpers.PropTypes.func.description("On focus event for inputs").signature("((e: React.FocusEvent, ...args: unknown[]) => void").isRequired,
|
|
80
|
+
onBlur: import_ds_props_helpers.PropTypes.func.description("On blur event for inputs").signature("((e: React.FocusEvent, ...args: unknown[]) => void").isRequired
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=DSHookOnFirstFocusIn.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/DSHookOnFirstFocusIn.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["import { useCallback, useMemo, useRef } from 'react';\nimport type { WeakValidationMap } from 'react';\nimport { describe, PropTypes } from '@elliemae/ds-props-helpers';\nimport { type DSHooksUseOnFirstFocusInT } from './react-desc-prop-types.js';\n\nconst propTypes = {\n onFirstFocusCb: PropTypes.func\n .description('The function to be invoked when focus enters the wrapping container for the first time')\n .signature('((e: React.FocusEvent, ...args: unknown[]) => void)').isRequired,\n onBlurCb: PropTypes.func\n .description('Optional onBlur function to be invoked along the returned onBlur handler')\n .signature('((e: React.FocusEvent, ...args: unknown[]) => void)'),\n} as WeakValidationMap<unknown>;\n\nconst useOnFirstFocusIn: DSHooksUseOnFirstFocusInT.UseFirstFocusIn = ({ onFirstFocus, onBlur }) => {\n const mutableDidChildBlur = useRef(false);\n const onFirstFocusHelper = useCallback<DSHooksUseOnFirstFocusInT.OnFirstFocusCb>(\n (e, ...args) => {\n const { currentTarget } = e;\n // Give browser time to focus the next element\n requestAnimationFrame(() => {\n const isChildFocus = currentTarget.contains(document.activeElement);\n const isFirstFocus = isChildFocus && !mutableDidChildBlur.current;\n if (isFirstFocus) {\n onFirstFocus(e, ...args);\n }\n });\n },\n [onFirstFocus],\n );\n const onBlurHelper = useCallback<DSHooksUseOnFirstFocusInT.OnBlurCb>(\n (e, ...args) => {\n onBlur?.(e, ...args);\n const { currentTarget } = e;\n // Give browser time to focus the next element\n requestAnimationFrame(() => {\n const isChildBlur = currentTarget.contains(document.activeElement);\n mutableDidChildBlur.current = isChildBlur;\n });\n },\n [onBlur],\n );\n return useMemo(\n () => ({\n onFirstFocus: onFirstFocusHelper,\n onBlur: onBlurHelper,\n }),\n [onFirstFocusHelper, onBlurHelper],\n );\n};\n\nconst UseOnFirstFocusInWithSchema = describe(useOnFirstFocusIn);\nUseOnFirstFocusInWithSchema.propTypes = propTypes;\nUseOnFirstFocusInWithSchema.returnType = {\n onFirstFocus: PropTypes.func\n .description('On focus event for inputs')\n .signature('((e: React.FocusEvent, ...args: unknown[]) => void').isRequired,\n onBlur: PropTypes.func\n .description('On blur event for inputs')\n .signature('((e: React.FocusEvent, ...args: unknown[]) => void').isRequired,\n};\n\nexport { useOnFirstFocusIn, UseOnFirstFocusInWithSchema };\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAA6C;AAE7C,8BAAoC;AAGpC,MAAM,YAAY;AAAA,EAChB,gBAAgB,kCAAU,KACvB,YAAY,wFAAwF,EACpG,UAAU,qDAAqD,EAAE;AAAA,EACpE,UAAU,kCAAU,KACjB,YAAY,0EAA0E,EACtF,UAAU,qDAAqD;AACpE;AAEA,MAAM,oBAA+D,CAAC,EAAE,cAAc,OAAO,MAAM;AACjG,QAAM,0BAAsB,qBAAO,KAAK;AACxC,QAAM,yBAAqB;AAAA,IACzB,CAAC,MAAM,SAAS;AACd,YAAM,EAAE,cAAc,IAAI;AAE1B,4BAAsB,MAAM;AAC1B,cAAM,eAAe,cAAc,SAAS,SAAS,aAAa;AAClE,cAAM,eAAe,gBAAgB,CAAC,oBAAoB;AAC1D,YAAI,cAAc;AAChB,uBAAa,GAAG,GAAG,IAAI;AAAA,QACzB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IACA,CAAC,YAAY;AAAA,EACf;AACA,QAAM,mBAAe;AAAA,IACnB,CAAC,MAAM,SAAS;AACd,eAAS,GAAG,GAAG,IAAI;AACnB,YAAM,EAAE,cAAc,IAAI;AAE1B,4BAAsB,MAAM;AAC1B,cAAM,cAAc,cAAc,SAAS,SAAS,aAAa;AACjE,4BAAoB,UAAU;AAAA,MAChC,CAAC;AAAA,IACH;AAAA,IACA,CAAC,MAAM;AAAA,EACT;AACA,aAAO;AAAA,IACL,OAAO;AAAA,MACL,cAAc;AAAA,MACd,QAAQ;AAAA,IACV;AAAA,IACA,CAAC,oBAAoB,YAAY;AAAA,EACnC;AACF;AAEA,MAAM,kCAA8B,kCAAS,iBAAiB;AAC9D,4BAA4B,YAAY;AACxC,4BAA4B,aAAa;AAAA,EACvC,cAAc,kCAAU,KACrB,YAAY,2BAA2B,EACvC,UAAU,oDAAoD,EAAE;AAAA,EACnE,QAAQ,kCAAU,KACf,YAAY,0BAA0B,EACtC,UAAU,oDAAoD,EAAE;AACrE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
UseOnFirstFocusInWithSchema: () => import_DSHookOnFirstFocusIn.UseOnFirstFocusInWithSchema,
|
|
32
|
+
useOnFirstFocusIn: () => import_DSHookOnFirstFocusIn.useOnFirstFocusIn
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(src_exports);
|
|
35
|
+
var React = __toESM(require("react"));
|
|
36
|
+
var import_DSHookOnFirstFocusIn = require("./DSHookOnFirstFocusIn.js");
|
|
37
|
+
//# 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 { useOnFirstFocusIn, UseOnFirstFocusInWithSchema } from './DSHookOnFirstFocusIn.js';\nexport type { DSHooksUseOnFirstFocusInT } 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,kCAA+D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var react_desc_prop_types_exports = {};
|
|
26
|
+
module.exports = __toCommonJS(react_desc_prop_types_exports);
|
|
27
|
+
var React = __toESM(require("react"));
|
|
28
|
+
//# 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": ["export declare namespace DSHooksUseOnFirstFocusInT {\n export type OnBlurCb = (e: React.FocusEvent<HTMLElement>, ...args: unknown[]) => void;\n export type OnFirstFocusCb = (e: React.FocusEvent<HTMLElement>, ...args: unknown[]) => void;\n export type UseFirstFocusIn = ({ onFirstFocus, onBlur }: { onFirstFocus: OnFirstFocusCb; onBlur: OnBlurCb }) => {\n onFirstFocus: OnFirstFocusCb;\n onBlur: OnBlurCb;\n };\n}\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;ACAA,YAAuB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useCallback, useMemo, useRef } from "react";
|
|
3
|
+
import { describe, PropTypes } from "@elliemae/ds-props-helpers";
|
|
4
|
+
const propTypes = {
|
|
5
|
+
onFirstFocusCb: PropTypes.func.description("The function to be invoked when focus enters the wrapping container for the first time").signature("((e: React.FocusEvent, ...args: unknown[]) => void)").isRequired,
|
|
6
|
+
onBlurCb: PropTypes.func.description("Optional onBlur function to be invoked along the returned onBlur handler").signature("((e: React.FocusEvent, ...args: unknown[]) => void)")
|
|
7
|
+
};
|
|
8
|
+
const useOnFirstFocusIn = ({ onFirstFocus, onBlur }) => {
|
|
9
|
+
const mutableDidChildBlur = useRef(false);
|
|
10
|
+
const onFirstFocusHelper = useCallback(
|
|
11
|
+
(e, ...args) => {
|
|
12
|
+
const { currentTarget } = e;
|
|
13
|
+
requestAnimationFrame(() => {
|
|
14
|
+
const isChildFocus = currentTarget.contains(document.activeElement);
|
|
15
|
+
const isFirstFocus = isChildFocus && !mutableDidChildBlur.current;
|
|
16
|
+
if (isFirstFocus) {
|
|
17
|
+
onFirstFocus(e, ...args);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
[onFirstFocus]
|
|
22
|
+
);
|
|
23
|
+
const onBlurHelper = useCallback(
|
|
24
|
+
(e, ...args) => {
|
|
25
|
+
onBlur?.(e, ...args);
|
|
26
|
+
const { currentTarget } = e;
|
|
27
|
+
requestAnimationFrame(() => {
|
|
28
|
+
const isChildBlur = currentTarget.contains(document.activeElement);
|
|
29
|
+
mutableDidChildBlur.current = isChildBlur;
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
[onBlur]
|
|
33
|
+
);
|
|
34
|
+
return useMemo(
|
|
35
|
+
() => ({
|
|
36
|
+
onFirstFocus: onFirstFocusHelper,
|
|
37
|
+
onBlur: onBlurHelper
|
|
38
|
+
}),
|
|
39
|
+
[onFirstFocusHelper, onBlurHelper]
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
const UseOnFirstFocusInWithSchema = describe(useOnFirstFocusIn);
|
|
43
|
+
UseOnFirstFocusInWithSchema.propTypes = propTypes;
|
|
44
|
+
UseOnFirstFocusInWithSchema.returnType = {
|
|
45
|
+
onFirstFocus: PropTypes.func.description("On focus event for inputs").signature("((e: React.FocusEvent, ...args: unknown[]) => void").isRequired,
|
|
46
|
+
onBlur: PropTypes.func.description("On blur event for inputs").signature("((e: React.FocusEvent, ...args: unknown[]) => void").isRequired
|
|
47
|
+
};
|
|
48
|
+
export {
|
|
49
|
+
UseOnFirstFocusInWithSchema,
|
|
50
|
+
useOnFirstFocusIn
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=DSHookOnFirstFocusIn.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/DSHookOnFirstFocusIn.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useCallback, useMemo, useRef } from 'react';\nimport type { WeakValidationMap } from 'react';\nimport { describe, PropTypes } from '@elliemae/ds-props-helpers';\nimport { type DSHooksUseOnFirstFocusInT } from './react-desc-prop-types.js';\n\nconst propTypes = {\n onFirstFocusCb: PropTypes.func\n .description('The function to be invoked when focus enters the wrapping container for the first time')\n .signature('((e: React.FocusEvent, ...args: unknown[]) => void)').isRequired,\n onBlurCb: PropTypes.func\n .description('Optional onBlur function to be invoked along the returned onBlur handler')\n .signature('((e: React.FocusEvent, ...args: unknown[]) => void)'),\n} as WeakValidationMap<unknown>;\n\nconst useOnFirstFocusIn: DSHooksUseOnFirstFocusInT.UseFirstFocusIn = ({ onFirstFocus, onBlur }) => {\n const mutableDidChildBlur = useRef(false);\n const onFirstFocusHelper = useCallback<DSHooksUseOnFirstFocusInT.OnFirstFocusCb>(\n (e, ...args) => {\n const { currentTarget } = e;\n // Give browser time to focus the next element\n requestAnimationFrame(() => {\n const isChildFocus = currentTarget.contains(document.activeElement);\n const isFirstFocus = isChildFocus && !mutableDidChildBlur.current;\n if (isFirstFocus) {\n onFirstFocus(e, ...args);\n }\n });\n },\n [onFirstFocus],\n );\n const onBlurHelper = useCallback<DSHooksUseOnFirstFocusInT.OnBlurCb>(\n (e, ...args) => {\n onBlur?.(e, ...args);\n const { currentTarget } = e;\n // Give browser time to focus the next element\n requestAnimationFrame(() => {\n const isChildBlur = currentTarget.contains(document.activeElement);\n mutableDidChildBlur.current = isChildBlur;\n });\n },\n [onBlur],\n );\n return useMemo(\n () => ({\n onFirstFocus: onFirstFocusHelper,\n onBlur: onBlurHelper,\n }),\n [onFirstFocusHelper, onBlurHelper],\n );\n};\n\nconst UseOnFirstFocusInWithSchema = describe(useOnFirstFocusIn);\nUseOnFirstFocusInWithSchema.propTypes = propTypes;\nUseOnFirstFocusInWithSchema.returnType = {\n onFirstFocus: PropTypes.func\n .description('On focus event for inputs')\n .signature('((e: React.FocusEvent, ...args: unknown[]) => void').isRequired,\n onBlur: PropTypes.func\n .description('On blur event for inputs')\n .signature('((e: React.FocusEvent, ...args: unknown[]) => void').isRequired,\n};\n\nexport { useOnFirstFocusIn, UseOnFirstFocusInWithSchema };\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,aAAa,SAAS,cAAc;AAE7C,SAAS,UAAU,iBAAiB;AAGpC,MAAM,YAAY;AAAA,EAChB,gBAAgB,UAAU,KACvB,YAAY,wFAAwF,EACpG,UAAU,qDAAqD,EAAE;AAAA,EACpE,UAAU,UAAU,KACjB,YAAY,0EAA0E,EACtF,UAAU,qDAAqD;AACpE;AAEA,MAAM,oBAA+D,CAAC,EAAE,cAAc,OAAO,MAAM;AACjG,QAAM,sBAAsB,OAAO,KAAK;AACxC,QAAM,qBAAqB;AAAA,IACzB,CAAC,MAAM,SAAS;AACd,YAAM,EAAE,cAAc,IAAI;AAE1B,4BAAsB,MAAM;AAC1B,cAAM,eAAe,cAAc,SAAS,SAAS,aAAa;AAClE,cAAM,eAAe,gBAAgB,CAAC,oBAAoB;AAC1D,YAAI,cAAc;AAChB,uBAAa,GAAG,GAAG,IAAI;AAAA,QACzB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IACA,CAAC,YAAY;AAAA,EACf;AACA,QAAM,eAAe;AAAA,IACnB,CAAC,MAAM,SAAS;AACd,eAAS,GAAG,GAAG,IAAI;AACnB,YAAM,EAAE,cAAc,IAAI;AAE1B,4BAAsB,MAAM;AAC1B,cAAM,cAAc,cAAc,SAAS,SAAS,aAAa;AACjE,4BAAoB,UAAU;AAAA,MAChC,CAAC;AAAA,IACH;AAAA,IACA,CAAC,MAAM;AAAA,EACT;AACA,SAAO;AAAA,IACL,OAAO;AAAA,MACL,cAAc;AAAA,MACd,QAAQ;AAAA,IACV;AAAA,IACA,CAAC,oBAAoB,YAAY;AAAA,EACnC;AACF;AAEA,MAAM,8BAA8B,SAAS,iBAAiB;AAC9D,4BAA4B,YAAY;AACxC,4BAA4B,aAAa;AAAA,EACvC,cAAc,UAAU,KACrB,YAAY,2BAA2B,EACvC,UAAU,oDAAoD,EAAE;AAAA,EACnE,QAAQ,UAAU,KACf,YAAY,0BAA0B,EACtC,UAAU,oDAAoD,EAAE;AACrE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export { useOnFirstFocusIn, UseOnFirstFocusInWithSchema } from './DSHookOnFirstFocusIn.js';\nexport type { DSHooksUseOnFirstFocusInT } from './react-desc-prop-types.js';\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,mBAAmB,mCAAmC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type DSHooksUseOnFirstFocusInT } from './react-desc-prop-types.js';
|
|
2
|
+
declare const useOnFirstFocusIn: DSHooksUseOnFirstFocusInT.UseFirstFocusIn;
|
|
3
|
+
declare const UseOnFirstFocusInWithSchema: import("@elliemae/ds-props-helpers/dist/types/propTypes/types.js").DocumentedReactComponent<{
|
|
4
|
+
onFirstFocus: DSHooksUseOnFirstFocusInT.OnFirstFocusCb;
|
|
5
|
+
onBlur: DSHooksUseOnFirstFocusInT.OnBlurCb;
|
|
6
|
+
}>;
|
|
7
|
+
export { useOnFirstFocusIn, UseOnFirstFocusInWithSchema };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare namespace DSHooksUseOnFirstFocusInT {
|
|
3
|
+
type OnBlurCb = (e: React.FocusEvent<HTMLElement>, ...args: unknown[]) => void;
|
|
4
|
+
type OnFirstFocusCb = (e: React.FocusEvent<HTMLElement>, ...args: unknown[]) => void;
|
|
5
|
+
type UseFirstFocusIn = ({ onFirstFocus, onBlur }: {
|
|
6
|
+
onFirstFocus: OnFirstFocusCb;
|
|
7
|
+
onBlur: OnBlurCb;
|
|
8
|
+
}) => {
|
|
9
|
+
onFirstFocus: OnFirstFocusCb;
|
|
10
|
+
onBlur: OnBlurCb;
|
|
11
|
+
};
|
|
12
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elliemae/ds-hooks-on-first-focus-in",
|
|
3
|
+
"version": "3.31.0-next.6",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "ICE MT - Dimsum - Hooks Font On First Focus In",
|
|
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.31.0-next.6"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@elliemae/pui-cli": "~9.0.0-next.31",
|
|
42
|
+
"@elliemae/ds-monorepo-devops": "3.31.0-next.6"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"lodash": "^4.17.21",
|
|
46
|
+
"react": "~17.0.2",
|
|
47
|
+
"react-dom": "^17.0.2",
|
|
48
|
+
"styled-components": "~5.3.9",
|
|
49
|
+
"styled-system": "^5.1.5"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public",
|
|
53
|
+
"typeSafety": true
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"dev": "cross-env NODE_ENV=development node ../../../scripts/build/build.mjs --watch",
|
|
57
|
+
"test": "pui-cli test --passWithNoTests",
|
|
58
|
+
"lint": "node ../../../scripts/lint.mjs --fix",
|
|
59
|
+
"eslint:fix": "eslint --ext='.js,.jsx,.test.js,.ts,.tsx' --fix --config='../../../.eslintrc.js' src/",
|
|
60
|
+
"dts": "node ../../../scripts/dts.mjs",
|
|
61
|
+
"dts:withdeps": "pnpm --filter {.}... dts",
|
|
62
|
+
"build": "cross-env NODE_ENV=production node ../../../scripts/build/build.mjs",
|
|
63
|
+
"dev:build": "pnpm --filter {.}... build",
|
|
64
|
+
"dev:install": "pnpm --filter {.}... i --no-lockfile && pnpm run dev:build",
|
|
65
|
+
"checkDeps": "npm exec ../../util/ds-codemods -- check-missing-packages --projectFolderPath=\"./\" --ignorePackagesGlobPattern=\"\" --ignoreFilesGlobPattern=\"**/test-ables/*,**/tests/*\""
|
|
66
|
+
}
|
|
67
|
+
}
|