@elliemae/ds-app-picker 3.61.11 → 3.70.0-alpha.9
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/DSAppPicker.js +10 -141
- package/dist/cjs/DSAppPicker.js.map +3 -3
- package/dist/cjs/{utils.js → DSAppPickerCTX.js} +8 -25
- package/dist/cjs/DSAppPickerCTX.js.map +7 -0
- package/dist/cjs/config/useAppPicker.js +25 -8
- package/dist/cjs/config/useAppPicker.js.map +3 -3
- package/dist/cjs/config/useFocusTracker.js +104 -0
- package/dist/cjs/config/useFocusTracker.js.map +7 -0
- package/dist/cjs/config/useValidateProps.js +63 -0
- package/dist/cjs/config/useValidateProps.js.map +7 -0
- package/dist/cjs/constants/index.js +11 -1
- package/dist/cjs/constants/index.js.map +2 -2
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/index.js.map +3 -3
- package/dist/cjs/parts/AppPanel.js +143 -0
- package/dist/cjs/parts/AppPanel.js.map +7 -0
- package/dist/cjs/parts/AppPickerFloatingContext/AppPickerContent.js +104 -0
- package/dist/cjs/parts/AppPickerFloatingContext/AppPickerContent.js.map +7 -0
- package/dist/cjs/parts/AppPickerFloatingContext/useAppPickerFloatingContext.js +195 -0
- package/dist/cjs/parts/AppPickerFloatingContext/useAppPickerFloatingContext.js.map +7 -0
- package/dist/cjs/parts/AppPickerItem.js +104 -0
- package/dist/cjs/parts/AppPickerItem.js.map +7 -0
- package/dist/cjs/parts/AppSection.js +95 -0
- package/dist/cjs/parts/AppSection.js.map +7 -0
- package/dist/cjs/parts/Trigger.js +83 -0
- package/dist/cjs/parts/Trigger.js.map +7 -0
- package/dist/cjs/parts/shared-styles.js +44 -0
- package/dist/cjs/parts/shared-styles.js.map +7 -0
- package/dist/cjs/react-desc-prop-types.js +28 -8
- package/dist/cjs/react-desc-prop-types.js.map +2 -2
- package/dist/cjs/typescript-testing/slot-props.js +48 -0
- package/dist/cjs/typescript-testing/slot-props.js.map +7 -0
- package/dist/cjs/typescript-testing/typescript-app-picker-valid.js +15 -2
- package/dist/cjs/typescript-testing/typescript-app-picker-valid.js.map +2 -2
- package/dist/cjs/util/getChipId.js +36 -0
- package/dist/cjs/util/getChipId.js.map +7 -0
- package/dist/cjs/util/getChipRegionId.js +37 -0
- package/dist/cjs/util/getChipRegionId.js.map +7 -0
- package/dist/cjs/util/getDSAppPickerContractProps.js +38 -0
- package/dist/cjs/util/getDSAppPickerContractProps.js.map +7 -0
- package/dist/cjs/util/instanceIds.js +42 -0
- package/dist/cjs/util/instanceIds.js.map +7 -0
- package/dist/esm/DSAppPicker.js +10 -141
- package/dist/esm/DSAppPicker.js.map +3 -3
- package/dist/esm/DSAppPickerCTX.js +8 -0
- package/dist/esm/DSAppPickerCTX.js.map +7 -0
- package/dist/esm/config/useAppPicker.js +29 -13
- package/dist/esm/config/useAppPicker.js.map +3 -3
- package/dist/esm/config/useFocusTracker.js +74 -0
- package/dist/esm/config/useFocusTracker.js.map +7 -0
- package/dist/esm/config/useValidateProps.js +33 -0
- package/dist/esm/config/useValidateProps.js.map +7 -0
- package/dist/esm/constants/index.js +11 -1
- package/dist/esm/constants/index.js.map +2 -2
- package/dist/esm/index.js +13 -1
- package/dist/esm/index.js.map +3 -3
- package/dist/esm/parts/AppPanel.js +118 -0
- package/dist/esm/parts/AppPanel.js.map +7 -0
- package/dist/esm/parts/AppPickerFloatingContext/AppPickerContent.js +74 -0
- package/dist/esm/parts/AppPickerFloatingContext/AppPickerContent.js.map +7 -0
- package/dist/esm/parts/AppPickerFloatingContext/useAppPickerFloatingContext.js +165 -0
- package/dist/esm/parts/AppPickerFloatingContext/useAppPickerFloatingContext.js.map +7 -0
- package/dist/esm/parts/AppPickerItem.js +74 -0
- package/dist/esm/parts/AppPickerItem.js.map +7 -0
- package/dist/esm/parts/AppSection.js +65 -0
- package/dist/esm/parts/AppSection.js.map +7 -0
- package/dist/esm/parts/Trigger.js +53 -0
- package/dist/esm/parts/Trigger.js.map +7 -0
- package/dist/esm/parts/shared-styles.js +14 -0
- package/dist/esm/parts/shared-styles.js.map +7 -0
- package/dist/esm/react-desc-prop-types.js +34 -9
- package/dist/esm/react-desc-prop-types.js.map +2 -2
- package/dist/esm/typescript-testing/slot-props.js +25 -0
- package/dist/esm/typescript-testing/slot-props.js.map +7 -0
- package/dist/esm/typescript-testing/typescript-app-picker-valid.js +15 -2
- package/dist/esm/typescript-testing/typescript-app-picker-valid.js.map +2 -2
- package/dist/esm/util/getChipId.js +6 -0
- package/dist/esm/util/getChipId.js.map +7 -0
- package/dist/esm/util/getChipRegionId.js +7 -0
- package/dist/esm/util/getChipRegionId.js.map +7 -0
- package/dist/esm/util/getDSAppPickerContractProps.js +8 -0
- package/dist/esm/util/getDSAppPickerContractProps.js.map +7 -0
- package/dist/esm/util/instanceIds.js +12 -0
- package/dist/esm/util/instanceIds.js.map +7 -0
- package/dist/types/DSAppPicker.d.ts +1 -2
- package/dist/types/DSAppPickerCTX.d.ts +6 -0
- package/dist/types/config/useAppPicker.d.ts +111 -92
- package/dist/types/config/useFocusTracker.d.ts +19 -0
- package/dist/types/config/useValidateProps.d.ts +3 -0
- package/dist/types/constants/index.d.ts +17 -7
- package/dist/types/index.d.ts +2 -0
- package/dist/types/parts/AppPanel.d.ts +2 -0
- package/dist/types/parts/AppPickerFloatingContext/AppPickerContent.d.ts +3 -0
- package/dist/types/parts/AppPickerFloatingContext/useAppPickerFloatingContext.d.ts +171 -0
- package/dist/types/parts/AppPickerItem.d.ts +11 -0
- package/dist/types/parts/AppSection.d.ts +6 -0
- package/dist/types/parts/Trigger.d.ts +14 -0
- package/dist/types/parts/shared-styles.d.ts +2 -0
- package/dist/types/react-desc-prop-types.d.ts +112 -9
- package/dist/types/util/getChipId.d.ts +2 -0
- package/dist/types/util/getChipRegionId.d.ts +1 -0
- package/dist/types/util/getDSAppPickerContractProps.d.ts +37 -0
- package/dist/types/util/instanceIds.d.ts +11 -0
- package/package.json +21 -18
- package/dist/cjs/AppPickerImpl.js +0 -204
- package/dist/cjs/AppPickerImpl.js.map +0 -7
- package/dist/cjs/hooks/useKeepTrackButtons.js +0 -69
- package/dist/cjs/hooks/useKeepTrackButtons.js.map +0 -7
- package/dist/cjs/styles.js +0 -76
- package/dist/cjs/styles.js.map +0 -7
- package/dist/cjs/utils.js.map +0 -7
- package/dist/esm/AppPickerImpl.js +0 -174
- package/dist/esm/AppPickerImpl.js.map +0 -7
- package/dist/esm/hooks/useKeepTrackButtons.js +0 -39
- package/dist/esm/hooks/useKeepTrackButtons.js.map +0 -7
- package/dist/esm/styles.js +0 -46
- package/dist/esm/styles.js.map +0 -7
- package/dist/esm/utils.js +0 -25
- package/dist/esm/utils.js.map +0 -7
- package/dist/types/AppPickerImpl.d.ts +0 -11
- package/dist/types/hooks/useKeepTrackButtons.d.ts +0 -13
- package/dist/types/styles.d.ts +0 -7
- package/dist/types/tests/app-picker.a11y.test.d.ts +0 -1
- package/dist/types/tests/app-picker.data-testid.test.d.ts +0 -1
- package/dist/types/tests/app-picker.events.test.d.ts +0 -1
- package/dist/types/tests/app-picker.exports.test.d.ts +0 -1
- package/dist/types/tests/app-picker.get-owner-props.test.d.ts +0 -1
- package/dist/types/tests/app-picker.keyboard.test.d.ts +0 -1
- package/dist/types/typescript-testing/typescript-app-picker-valid.d.ts +0 -1
- package/dist/types/utils.d.ts +0 -14
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useCallback, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { APP_PICKER_REGION_FOCUSES } from "../constants/index.js";
|
|
4
|
+
import { getChipId } from "../util/getChipId.js";
|
|
5
|
+
import { getChipRegionId } from "../util/getChipRegionId.js";
|
|
6
|
+
const useFocusTracker = (config) => {
|
|
7
|
+
const { allApps } = config;
|
|
8
|
+
const firstFocusableIdx = useMemo(() => allApps.findIndex((app) => !app.disabled), [allApps]);
|
|
9
|
+
const lastFocusableIdx = useMemo(() => allApps.reduce((acc, app, i) => !app.disabled ? i : acc, -1), [allApps]);
|
|
10
|
+
const [focusRegion, setFocusRegion] = useState(APP_PICKER_REGION_FOCUSES.RESET);
|
|
11
|
+
const firstFocusableRef = useRef(null);
|
|
12
|
+
const lastFocusableRef = useRef(null);
|
|
13
|
+
const trackFocusChip = useCallback((chipId) => {
|
|
14
|
+
setFocusRegion(getChipRegionId(chipId));
|
|
15
|
+
}, []);
|
|
16
|
+
const trackFocusRegionReset = useCallback(() => {
|
|
17
|
+
setFocusRegion(APP_PICKER_REGION_FOCUSES.RESET);
|
|
18
|
+
}, []);
|
|
19
|
+
const trackFocusTrigger = useCallback(() => {
|
|
20
|
+
setFocusRegion(APP_PICKER_REGION_FOCUSES.TRIGGER);
|
|
21
|
+
}, []);
|
|
22
|
+
const trackFocusPanel = useCallback(() => {
|
|
23
|
+
setFocusRegion(APP_PICKER_REGION_FOCUSES.PANEL);
|
|
24
|
+
}, []);
|
|
25
|
+
const trackFocusSelectedItem = useCallback(() => {
|
|
26
|
+
const selectedIdx = allApps.findIndex((app) => app.selected);
|
|
27
|
+
const index = selectedIdx !== -1 ? selectedIdx : allApps.findIndex((app) => !app.disabled);
|
|
28
|
+
if (index !== -1) setFocusRegion(getChipRegionId(getChipId(allApps[index], index)));
|
|
29
|
+
}, [allApps]);
|
|
30
|
+
const trackFocusSelectedOrLastItem = useCallback(() => {
|
|
31
|
+
const selectedIdx = allApps.findIndex((app) => app.selected);
|
|
32
|
+
const index = selectedIdx !== -1 ? selectedIdx : lastFocusableIdx;
|
|
33
|
+
if (index !== -1) setFocusRegion(getChipRegionId(getChipId(allApps[index], index)));
|
|
34
|
+
}, [allApps, lastFocusableIdx]);
|
|
35
|
+
const trackFocusItemAtIndex = useCallback(
|
|
36
|
+
(index) => {
|
|
37
|
+
const target = allApps[index];
|
|
38
|
+
if (target) setFocusRegion(getChipRegionId(getChipId(target, index)));
|
|
39
|
+
},
|
|
40
|
+
[allApps]
|
|
41
|
+
);
|
|
42
|
+
return useMemo(
|
|
43
|
+
() => ({
|
|
44
|
+
firstFocusableIdx,
|
|
45
|
+
lastFocusableIdx,
|
|
46
|
+
focusRegion,
|
|
47
|
+
firstFocusableRef,
|
|
48
|
+
lastFocusableRef,
|
|
49
|
+
trackFocusChip,
|
|
50
|
+
trackFocusRegionReset,
|
|
51
|
+
trackFocusTrigger,
|
|
52
|
+
trackFocusPanel,
|
|
53
|
+
trackFocusSelectedItem,
|
|
54
|
+
trackFocusSelectedOrLastItem,
|
|
55
|
+
trackFocusItemAtIndex
|
|
56
|
+
}),
|
|
57
|
+
[
|
|
58
|
+
firstFocusableIdx,
|
|
59
|
+
lastFocusableIdx,
|
|
60
|
+
focusRegion,
|
|
61
|
+
trackFocusChip,
|
|
62
|
+
trackFocusRegionReset,
|
|
63
|
+
trackFocusTrigger,
|
|
64
|
+
trackFocusPanel,
|
|
65
|
+
trackFocusSelectedItem,
|
|
66
|
+
trackFocusSelectedOrLastItem,
|
|
67
|
+
trackFocusItemAtIndex
|
|
68
|
+
]
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
export {
|
|
72
|
+
useFocusTracker
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=useFocusTracker.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/config/useFocusTracker.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useCallback, useMemo, useRef, useState } from 'react';\nimport { APP_PICKER_REGION_FOCUSES } from '../constants/index.js';\nimport type { DSAppPickerT } from '../react-desc-prop-types.js';\nimport { getChipId } from '../util/getChipId.js';\nimport { getChipRegionId } from '../util/getChipRegionId.js';\n\ntype FocusTrackerConfigT = {\n allApps: DSAppPickerT.AppItem[];\n};\n\nexport const useFocusTracker = (config: FocusTrackerConfigT) => {\n const { allApps } = config;\n\n // Flat indices of the first/last non-disabled item, used to mark the focus-trap edges.\n // AppSection passes isFirstFocusable/isLastFocusable to AppPickerItem, which sets\n // firstFocusableRef/lastFocusableRef when its innerRef fires.\n const firstFocusableIdx = useMemo(() => allApps.findIndex((app) => !app.disabled), [allApps]);\n const lastFocusableIdx = useMemo(() => allApps.reduce((acc, app, i) => (!app.disabled ? i : acc), -1), [allApps]);\n\n const [focusRegion, setFocusRegion] = useState<string>(APP_PICKER_REGION_FOCUSES.RESET);\n\n // DOM refs for the first and last focusable chips \u2014 set by AppPickerItem's innerRef.\n // Used by useFocusTrap in AppPanel so the focus trap needs no DOM query.\n const firstFocusableRef = useRef<HTMLElement | null>(null);\n const lastFocusableRef = useRef<HTMLElement | null>(null);\n\n const trackFocusChip = useCallback((chipId: string) => {\n setFocusRegion(getChipRegionId(chipId));\n }, []);\n\n const trackFocusRegionReset = useCallback(() => {\n setFocusRegion(APP_PICKER_REGION_FOCUSES.RESET);\n }, []);\n\n const trackFocusTrigger = useCallback(() => {\n setFocusRegion(APP_PICKER_REGION_FOCUSES.TRIGGER);\n }, []);\n\n const trackFocusPanel = useCallback(() => {\n setFocusRegion(APP_PICKER_REGION_FOCUSES.PANEL);\n }, []);\n\n const trackFocusSelectedItem = useCallback(() => {\n const selectedIdx = allApps.findIndex((app) => app.selected);\n const index = selectedIdx !== -1 ? selectedIdx : allApps.findIndex((app) => !app.disabled);\n if (index !== -1) setFocusRegion(getChipRegionId(getChipId(allApps[index], index)));\n }, [allApps]);\n\n // ArrowUp's counterpart to trackFocusSelectedItem. Same first clause \u2014 the selection wins \u2014 but the\n // fallback is the LAST available item rather than the first, because \"open upwards\" lands at the end.\n const trackFocusSelectedOrLastItem = useCallback(() => {\n const selectedIdx = allApps.findIndex((app) => app.selected);\n const index = selectedIdx !== -1 ? selectedIdx : lastFocusableIdx;\n if (index !== -1) setFocusRegion(getChipRegionId(getChipId(allApps[index], index)));\n }, [allApps, lastFocusableIdx]);\n\n const trackFocusItemAtIndex = useCallback(\n (index: number) => {\n const target = allApps[index];\n if (target) setFocusRegion(getChipRegionId(getChipId(target, index)));\n },\n [allApps],\n );\n\n return useMemo(\n () => ({\n firstFocusableIdx,\n lastFocusableIdx,\n focusRegion,\n firstFocusableRef,\n lastFocusableRef,\n trackFocusChip,\n trackFocusRegionReset,\n trackFocusTrigger,\n trackFocusPanel,\n trackFocusSelectedItem,\n trackFocusSelectedOrLastItem,\n trackFocusItemAtIndex,\n }),\n [\n firstFocusableIdx,\n lastFocusableIdx,\n focusRegion,\n trackFocusChip,\n trackFocusRegionReset,\n trackFocusTrigger,\n trackFocusPanel,\n trackFocusSelectedItem,\n trackFocusSelectedOrLastItem,\n trackFocusItemAtIndex,\n ],\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,aAAa,SAAS,QAAQ,gBAAgB;AACvD,SAAS,iCAAiC;AAE1C,SAAS,iBAAiB;AAC1B,SAAS,uBAAuB;AAMzB,MAAM,kBAAkB,CAAC,WAAgC;AAC9D,QAAM,EAAE,QAAQ,IAAI;AAKpB,QAAM,oBAAoB,QAAQ,MAAM,QAAQ,UAAU,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC,OAAO,CAAC;AAC5F,QAAM,mBAAmB,QAAQ,MAAM,QAAQ,OAAO,CAAC,KAAK,KAAK,MAAO,CAAC,IAAI,WAAW,IAAI,KAAM,EAAE,GAAG,CAAC,OAAO,CAAC;AAEhH,QAAM,CAAC,aAAa,cAAc,IAAI,SAAiB,0BAA0B,KAAK;AAItF,QAAM,oBAAoB,OAA2B,IAAI;AACzD,QAAM,mBAAmB,OAA2B,IAAI;AAExD,QAAM,iBAAiB,YAAY,CAAC,WAAmB;AACrD,mBAAe,gBAAgB,MAAM,CAAC;AAAA,EACxC,GAAG,CAAC,CAAC;AAEL,QAAM,wBAAwB,YAAY,MAAM;AAC9C,mBAAe,0BAA0B,KAAK;AAAA,EAChD,GAAG,CAAC,CAAC;AAEL,QAAM,oBAAoB,YAAY,MAAM;AAC1C,mBAAe,0BAA0B,OAAO;AAAA,EAClD,GAAG,CAAC,CAAC;AAEL,QAAM,kBAAkB,YAAY,MAAM;AACxC,mBAAe,0BAA0B,KAAK;AAAA,EAChD,GAAG,CAAC,CAAC;AAEL,QAAM,yBAAyB,YAAY,MAAM;AAC/C,UAAM,cAAc,QAAQ,UAAU,CAAC,QAAQ,IAAI,QAAQ;AAC3D,UAAM,QAAQ,gBAAgB,KAAK,cAAc,QAAQ,UAAU,CAAC,QAAQ,CAAC,IAAI,QAAQ;AACzF,QAAI,UAAU,GAAI,gBAAe,gBAAgB,UAAU,QAAQ,KAAK,GAAG,KAAK,CAAC,CAAC;AAAA,EACpF,GAAG,CAAC,OAAO,CAAC;AAIZ,QAAM,+BAA+B,YAAY,MAAM;AACrD,UAAM,cAAc,QAAQ,UAAU,CAAC,QAAQ,IAAI,QAAQ;AAC3D,UAAM,QAAQ,gBAAgB,KAAK,cAAc;AACjD,QAAI,UAAU,GAAI,gBAAe,gBAAgB,UAAU,QAAQ,KAAK,GAAG,KAAK,CAAC,CAAC;AAAA,EACpF,GAAG,CAAC,SAAS,gBAAgB,CAAC;AAE9B,QAAM,wBAAwB;AAAA,IAC5B,CAAC,UAAkB;AACjB,YAAM,SAAS,QAAQ,KAAK;AAC5B,UAAI,OAAQ,gBAAe,gBAAgB,UAAU,QAAQ,KAAK,CAAC,CAAC;AAAA,IACtE;AAAA,IACA,CAAC,OAAO;AAAA,EACV;AAEA,SAAO;AAAA,IACL,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useValidateTypescriptPropTypes } from "@elliemae/ds-props-helpers";
|
|
3
|
+
import { DSAppPickerName } from "../constants/index.js";
|
|
4
|
+
const useValidateProps = (props, propTypes) => {
|
|
5
|
+
useValidateTypescriptPropTypes(props, propTypes, DSAppPickerName);
|
|
6
|
+
if (!props.apps.length && !props.customApps.length) {
|
|
7
|
+
throw new Error(
|
|
8
|
+
`[${DSAppPickerName}] At least one of "apps" or "customApps" must contain items. Providing both as empty arrays renders an empty picker.`
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
const suppliedAppIds = [...props.apps, ...props.customApps].map((app) => app.id).filter((id) => id !== void 0);
|
|
12
|
+
const seen = /* @__PURE__ */ new Set();
|
|
13
|
+
const duplicates = /* @__PURE__ */ new Set();
|
|
14
|
+
for (const id of suppliedAppIds) {
|
|
15
|
+
if (seen.has(id)) duplicates.add(id);
|
|
16
|
+
else seen.add(id);
|
|
17
|
+
}
|
|
18
|
+
const duplicatedAppIds = [...duplicates];
|
|
19
|
+
if (duplicatedAppIds.length) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`[${DSAppPickerName}] Every app "id" must be unique across "apps" and "customApps" \u2014 each one is rendered as that chip's DOM id, and duplicates produce an invalid document. Duplicated: ${duplicatedAppIds.map((id) => `"${id}"`).join(", ")}.`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
if (props.id !== void 0 && suppliedAppIds.includes(props.id)) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`[${DSAppPickerName}] The app "id" "${props.id}" collides with the "id" given to the component, which is rendered on the root element. Every other id is suffixed away from it \u2014 see getIdForAppPickerTrigger / getIdForAppPickerSectionTitle / getIdForAppPickerCustomSectionTitle \u2014 but this one is not ours to move.`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
useValidateProps
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=useValidateProps.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/config/useValidateProps.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useValidateTypescriptPropTypes } from '@elliemae/ds-props-helpers';\nimport type { ValidationMap } from '@elliemae/ds-props-helpers';\nimport { type DSAppPickerT } from '../react-desc-prop-types.js';\nimport { DSAppPickerName } from '../constants/index.js';\n\nexport const useValidateProps = (props: DSAppPickerT.InternalProps, propTypes: ValidationMap<unknown>): void => {\n useValidateTypescriptPropTypes(props, propTypes, DSAppPickerName);\n\n if (!props.apps.length && !props.customApps.length) {\n throw new Error(\n `[${DSAppPickerName}] At least one of \"apps\" or \"customApps\" must contain items. ` +\n `Providing both as empty arrays renders an empty picker.`,\n );\n }\n\n /*\n * An app's `id` is rendered verbatim as the chip's DOM id \u2014 it is the consumer's own value, deliberately\n * left un-namespaced so they can address their chips by the identity they already know. `apps` and\n * `customApps` are two independent arrays, so nothing about the shape of the API stops the same value\n * appearing twice, and a duplicate DOM id is a broken document: `getElementById`, `document.querySelector`\n * and every `aria-*` reference silently resolve to the first match only.\n *\n * We do not fix that by rewriting their ids \u2014 that would take away the surface the field exists to\n * provide. We make it impossible to ship instead. Uniqueness stays the consumer's responsibility; this\n * turns \"silently wrong in production\" into \"cannot render\", which is the only version of that\n * responsibility that actually holds.\n *\n * Scoped to ids the consumer supplied: id-less apps are legal (AppSection falls back to a positional key\n * and getChipId to a label-index identity), and no chip id is emitted for them at all.\n */\n const suppliedAppIds = [...props.apps, ...props.customApps]\n .map((app) => app.id)\n .filter((id): id is string => id !== undefined);\n\n const seen = new Set<string>();\n const duplicates = new Set<string>();\n for (const id of suppliedAppIds) {\n if (seen.has(id)) duplicates.add(id);\n else seen.add(id);\n }\n const duplicatedAppIds = [...duplicates];\n if (duplicatedAppIds.length) {\n throw new Error(\n `[${DSAppPickerName}] Every app \"id\" must be unique across \"apps\" and \"customApps\" \u2014 each one is ` +\n `rendered as that chip's DOM id, and duplicates produce an invalid document. ` +\n `Duplicated: ${duplicatedAppIds.map((id) => `\"${id}\"`).join(', ')}.`,\n );\n }\n\n /*\n * Same defect, one level up: the consumer's `id` lands unmodified on the ROOT (see util/instanceIds), so\n * an app carrying that same value collides with it. Every id this component generates for itself is\n * suffixed through that module and therefore cannot participate \u2014 this is the one remaining pair where\n * two consumer-supplied values meet.\n */\n if (props.id !== undefined && suppliedAppIds.includes(props.id)) {\n throw new Error(\n `[${DSAppPickerName}] The app \"id\" \"${props.id}\" collides with the \"id\" given to the component, ` +\n `which is rendered on the root element. Every other id is suffixed away from it \u2014 see ` +\n `getIdForAppPickerTrigger / getIdForAppPickerSectionTitle / getIdForAppPickerCustomSectionTitle \u2014 but this one is not ours to move.`,\n );\n }\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,sCAAsC;AAG/C,SAAS,uBAAuB;AAEzB,MAAM,mBAAmB,CAAC,OAAmC,cAA4C;AAC9G,iCAA+B,OAAO,WAAW,eAAe;AAEhE,MAAI,CAAC,MAAM,KAAK,UAAU,CAAC,MAAM,WAAW,QAAQ;AAClD,UAAM,IAAI;AAAA,MACR,IAAI,eAAe;AAAA,IAErB;AAAA,EACF;AAiBA,QAAM,iBAAiB,CAAC,GAAG,MAAM,MAAM,GAAG,MAAM,UAAU,EACvD,IAAI,CAAC,QAAQ,IAAI,EAAE,EACnB,OAAO,CAAC,OAAqB,OAAO,MAAS;AAEhD,QAAM,OAAO,oBAAI,IAAY;AAC7B,QAAM,aAAa,oBAAI,IAAY;AACnC,aAAW,MAAM,gBAAgB;AAC/B,QAAI,KAAK,IAAI,EAAE,EAAG,YAAW,IAAI,EAAE;AAAA,QAC9B,MAAK,IAAI,EAAE;AAAA,EAClB;AACA,QAAM,mBAAmB,CAAC,GAAG,UAAU;AACvC,MAAI,iBAAiB,QAAQ;AAC3B,UAAM,IAAI;AAAA,MACR,IAAI,eAAe,6KAEF,iBAAiB,IAAI,CAAC,OAAO,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAAA,IACrE;AAAA,EACF;AAQA,MAAI,MAAM,OAAO,UAAa,eAAe,SAAS,MAAM,EAAE,GAAG;AAC/D,UAAM,IAAI;AAAA,MACR,IAAI,eAAe,mBAAmB,MAAM,EAAE;AAAA,IAGhD;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { slotObjectToDataTestIds } from "@elliemae/ds-system";
|
|
3
3
|
const DSAppPickerName = "DSApppicker";
|
|
4
|
+
const APP_PICKER_REGION_FOCUSES = {
|
|
5
|
+
RESET: "",
|
|
6
|
+
TRIGGER: "trigger",
|
|
7
|
+
PANEL: "panel"
|
|
8
|
+
};
|
|
9
|
+
const CHIP_REGION_PREFIX = "chip-";
|
|
4
10
|
const DSAppPickerSlots = {
|
|
5
11
|
ROOT: "root",
|
|
12
|
+
GROUP: "group",
|
|
6
13
|
ITEM: "item",
|
|
7
14
|
TITLE: "title",
|
|
8
15
|
SEPARATOR: "separator",
|
|
9
16
|
ROW: "row",
|
|
10
17
|
CHIP: "chip",
|
|
11
|
-
BUTTON: "button"
|
|
18
|
+
BUTTON: "button",
|
|
19
|
+
FLOATING_WRAPPER: "floating-wrapper"
|
|
12
20
|
};
|
|
13
21
|
const DSAppPickerDataTestIds = {
|
|
14
22
|
...slotObjectToDataTestIds(DSAppPickerName, DSAppPickerSlots),
|
|
@@ -16,6 +24,8 @@ const DSAppPickerDataTestIds = {
|
|
|
16
24
|
BUTTON: "app-picker__button"
|
|
17
25
|
};
|
|
18
26
|
export {
|
|
27
|
+
APP_PICKER_REGION_FOCUSES,
|
|
28
|
+
CHIP_REGION_PREFIX,
|
|
19
29
|
DSAppPickerDataTestIds,
|
|
20
30
|
DSAppPickerName,
|
|
21
31
|
DSAppPickerSlots
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/constants/index.ts"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { slotObjectToDataTestIds } from '@elliemae/ds-system';\n\nexport const DSAppPickerName = 'DSApppicker';\n\nexport const DSAppPickerSlots = {\n ROOT: 'root',\n ITEM: 'item',\n TITLE: 'title',\n SEPARATOR: 'separator',\n ROW: 'row',\n CHIP: 'chip',\n BUTTON: 'button',\n};\n\nexport const DSAppPickerDataTestIds = {\n ...(slotObjectToDataTestIds(DSAppPickerName, DSAppPickerSlots) as Record<keyof typeof DSAppPickerSlots, string>),\n CHIP: 'app-picker__chip',\n BUTTON: 'app-picker__button',\n};\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,+BAA+B;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { slotObjectToDataTestIds } from '@elliemae/ds-system';\n\n// DEV-001: triple-p \"DSApppicker\" is the legacy public name. Renaming would break consumers.\n// See KNOWN_INTENTIONAL_DEVIATIONS.md.\nexport const DSAppPickerName = 'DSApppicker';\n\n// we are naming this with the ${component_name}_region_focuses convention to namespace & avoid errors on duplicate exports variables in aggregators\nexport const APP_PICKER_REGION_FOCUSES = {\n RESET: '',\n TRIGGER: 'trigger',\n PANEL: 'panel',\n} as const;\n\n// Prefix for the per-chip focus-region identifiers (see getChipRegionId in src/util).\nexport const CHIP_REGION_PREFIX = 'chip-';\n\n// we are naming this with the ${component_name}_slots convention to namespace & avoid errors on duplicate exports variables in aggregators\nexport const DSAppPickerSlots = {\n ROOT: 'root',\n GROUP: 'group',\n ITEM: 'item',\n TITLE: 'title',\n SEPARATOR: 'separator',\n ROW: 'row',\n CHIP: 'chip',\n BUTTON: 'button',\n FLOATING_WRAPPER: 'floating-wrapper',\n} as const;\n\n// Layer 2 legacy data-testid overrides:\n// CHIP and BUTTON predate the slot naming scheme; existing QA selectors must keep matching.\n// See project_compatibility.md (legacy data-testid 3-layer override pattern).\nexport const DSAppPickerDataTestIds = {\n ...(slotObjectToDataTestIds(DSAppPickerName, DSAppPickerSlots) as Record<keyof typeof DSAppPickerSlots, string>),\n CHIP: 'app-picker__chip',\n BUTTON: 'app-picker__button',\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,+BAA+B;AAIjC,MAAM,kBAAkB;AAGxB,MAAM,4BAA4B;AAAA,EACvC,OAAO;AAAA,EACP,SAAS;AAAA,EACT,OAAO;AACT;AAGO,MAAM,qBAAqB;AAG3B,MAAM,mBAAmB;AAAA,EAC9B,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AAAA,EACP,WAAW;AAAA,EACX,KAAK;AAAA,EACL,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,kBAAkB;AACpB;AAKO,MAAM,yBAAyB;AAAA,EACpC,GAAI,wBAAwB,iBAAiB,gBAAgB;AAAA,EAC7D,MAAM;AAAA,EACN,QAAQ;AACV;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { DSAppPicker, AppPickerWithSchema } from "./DSAppPicker.js";
|
|
3
3
|
import { DSAppPickerName, DSAppPickerSlots, DSAppPickerDataTestIds } from "./constants/index.js";
|
|
4
|
+
import { getDSAppPickerContractProps } from "./util/getDSAppPickerContractProps.js";
|
|
5
|
+
import {
|
|
6
|
+
getIdForAppPickerRoot,
|
|
7
|
+
getIdForAppPickerTrigger,
|
|
8
|
+
getIdForAppPickerSectionTitle,
|
|
9
|
+
getIdForAppPickerCustomSectionTitle
|
|
10
|
+
} from "./util/instanceIds.js";
|
|
4
11
|
export {
|
|
5
12
|
AppPickerWithSchema,
|
|
6
13
|
DSAppPicker,
|
|
7
14
|
DSAppPickerDataTestIds,
|
|
8
15
|
DSAppPickerName,
|
|
9
|
-
DSAppPickerSlots
|
|
16
|
+
DSAppPickerSlots,
|
|
17
|
+
getDSAppPickerContractProps,
|
|
18
|
+
getIdForAppPickerCustomSectionTitle,
|
|
19
|
+
getIdForAppPickerRoot,
|
|
20
|
+
getIdForAppPickerSectionTitle,
|
|
21
|
+
getIdForAppPickerTrigger
|
|
10
22
|
};
|
|
11
23
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/index.
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export { DSAppPicker, AppPickerWithSchema } from './DSAppPicker.js';\nexport { DSAppPickerName, DSAppPickerSlots, DSAppPickerDataTestIds } from './constants/index.js';\nexport type { DSAppPickerT } from './react-desc-prop-types.js';\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,aAAa,2BAA2B;AACjD,SAAS,iBAAiB,kBAAkB,8BAA8B;",
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export { DSAppPicker, AppPickerWithSchema } from './DSAppPicker.js';\nexport { DSAppPickerName, DSAppPickerSlots, DSAppPickerDataTestIds } from './constants/index.js';\nexport { getDSAppPickerContractProps } from './util/getDSAppPickerContractProps.js';\nexport {\n getIdForAppPickerRoot,\n getIdForAppPickerTrigger,\n getIdForAppPickerSectionTitle,\n getIdForAppPickerCustomSectionTitle,\n} from './util/instanceIds.js';\nexport type { DSAppPickerT } from './react-desc-prop-types.js';\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,aAAa,2BAA2B;AACjD,SAAS,iBAAiB,kBAAkB,8BAA8B;AAC1E,SAAS,mCAAmC;AAC5C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Grid } from "@elliemae/ds-grid";
|
|
4
|
+
import { useFocusTrap } from "@elliemae/ds-hooks-focus-trap";
|
|
5
|
+
import { styled } from "@elliemae/ds-system";
|
|
6
|
+
import React2, { memo, useCallback, useContext, useEffect } from "react";
|
|
7
|
+
import {
|
|
8
|
+
APP_PICKER_REGION_FOCUSES,
|
|
9
|
+
DSAppPickerDataTestIds,
|
|
10
|
+
DSAppPickerName,
|
|
11
|
+
DSAppPickerSlots
|
|
12
|
+
} from "../constants/index.js";
|
|
13
|
+
import { DSAppPickerContext } from "../DSAppPickerCTX.js";
|
|
14
|
+
import { AppSection } from "./AppSection.js";
|
|
15
|
+
import { StyledListItemFullRow } from "./shared-styles.js";
|
|
16
|
+
const StyledWrapper = styled(Grid, { name: DSAppPickerName, slot: DSAppPickerSlots.ROOT })`
|
|
17
|
+
background-color: ${({ theme }) => theme.colors.neutral["000"]};
|
|
18
|
+
min-width: 308px;
|
|
19
|
+
min-height: 110px;
|
|
20
|
+
max-height: 449px;
|
|
21
|
+
width: 308px;
|
|
22
|
+
overflow-y: auto;
|
|
23
|
+
overflow-x: hidden;
|
|
24
|
+
/* Baseline 2024: reserve scrollbar gutter so the layout doesn't shift between overflow/no-overflow.
|
|
25
|
+
Replaces a JS isOverflow detection effect that toggled right padding. */
|
|
26
|
+
scrollbar-gutter: stable;
|
|
27
|
+
margin: 0;
|
|
28
|
+
padding: 0 0 8px 16px;
|
|
29
|
+
&:focus {
|
|
30
|
+
outline: none;
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
const StyledSeparator = styled("hr", { name: DSAppPickerName, slot: DSAppPickerSlots.SEPARATOR })`
|
|
34
|
+
border-top: 1px solid ${({ theme }) => theme.colors.neutral[300]};
|
|
35
|
+
border-bottom: none;
|
|
36
|
+
width: 100%;
|
|
37
|
+
margin: 8px 0 0 0;
|
|
38
|
+
`;
|
|
39
|
+
const wrapperGridLayout = {
|
|
40
|
+
cols: ["repeat(3, 92px)"],
|
|
41
|
+
// Row tracks are intentionally auto-sized:
|
|
42
|
+
// - title row picks up its own typography height
|
|
43
|
+
// - chip rows expand when `wrapText` causes a chip to wrap onto a second line (Reflow story)
|
|
44
|
+
// - separator row picks up its own 1px height + margin
|
|
45
|
+
rows: ["auto"]
|
|
46
|
+
};
|
|
47
|
+
const useExecOnceAfterFirstRender = (callback) => {
|
|
48
|
+
const hasExecutedRef = React2.useRef(false);
|
|
49
|
+
const executeInitialFocusRef = React2.useRef(callback);
|
|
50
|
+
executeInitialFocusRef.current = callback;
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (!hasExecutedRef.current) {
|
|
53
|
+
executeInitialFocusRef.current();
|
|
54
|
+
hasExecutedRef.current = true;
|
|
55
|
+
}
|
|
56
|
+
}, []);
|
|
57
|
+
};
|
|
58
|
+
const useMountedOpenAutofocusNuance = ({ pendingRef, trackFocusPanel }) => {
|
|
59
|
+
useExecOnceAfterFirstRender(() => {
|
|
60
|
+
if (!pendingRef.current) return;
|
|
61
|
+
pendingRef.current = false;
|
|
62
|
+
trackFocusPanel();
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
const AppPanelBase = () => {
|
|
66
|
+
const {
|
|
67
|
+
propsWithDefault: { customApps, onKeyDown },
|
|
68
|
+
ownerPropsConfig,
|
|
69
|
+
globalAttributes,
|
|
70
|
+
xstyledProps,
|
|
71
|
+
mountedOpenAutofocusPendingRef,
|
|
72
|
+
focusTrackers: { focusRegion, firstFocusableRef, lastFocusableRef, trackFocusPanel }
|
|
73
|
+
} = useContext(DSAppPickerContext);
|
|
74
|
+
const { wrap, onClick, onKeyDown: onKeyDownGlobal, ...safeGlobalAttributes } = globalAttributes;
|
|
75
|
+
useMountedOpenAutofocusNuance({
|
|
76
|
+
pendingRef: mountedOpenAutofocusPendingRef,
|
|
77
|
+
trackFocusPanel
|
|
78
|
+
});
|
|
79
|
+
const isWrapperFocused = focusRegion === APP_PICKER_REGION_FOCUSES.PANEL;
|
|
80
|
+
const handleWrapperRef = useCallback(
|
|
81
|
+
(node) => {
|
|
82
|
+
if (node && isWrapperFocused) node.focus();
|
|
83
|
+
},
|
|
84
|
+
[isWrapperFocused]
|
|
85
|
+
);
|
|
86
|
+
const handleOnKeyDown = useFocusTrap({
|
|
87
|
+
firstElementRef: firstFocusableRef,
|
|
88
|
+
lastElementRef: lastFocusableRef,
|
|
89
|
+
onKeyDown
|
|
90
|
+
});
|
|
91
|
+
return /* @__PURE__ */ jsxs(
|
|
92
|
+
StyledWrapper,
|
|
93
|
+
{
|
|
94
|
+
innerRef: handleWrapperRef,
|
|
95
|
+
"data-testid": DSAppPickerDataTestIds.ROOT,
|
|
96
|
+
cols: wrapperGridLayout.cols,
|
|
97
|
+
rows: wrapperGridLayout.rows,
|
|
98
|
+
tabIndex: -1,
|
|
99
|
+
...ownerPropsConfig,
|
|
100
|
+
...safeGlobalAttributes,
|
|
101
|
+
...xstyledProps,
|
|
102
|
+
onKeyDown: handleOnKeyDown,
|
|
103
|
+
children: [
|
|
104
|
+
/* @__PURE__ */ jsx(AppSection, {}),
|
|
105
|
+
customApps.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
106
|
+
/* @__PURE__ */ jsx(StyledListItemFullRow, { "data-testid": DSAppPickerDataTestIds.ROW, ...ownerPropsConfig, children: /* @__PURE__ */ jsx(StyledSeparator, { "data-testid": DSAppPickerDataTestIds.SEPARATOR, ...ownerPropsConfig }) }),
|
|
107
|
+
/* @__PURE__ */ jsx(AppSection, { isCustomApps: true })
|
|
108
|
+
] })
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
const AppPanel = memo(AppPanelBase);
|
|
114
|
+
AppPanel.displayName = "DSAppPicker.AppPanel";
|
|
115
|
+
export {
|
|
116
|
+
AppPanel
|
|
117
|
+
};
|
|
118
|
+
//# sourceMappingURL=AppPanel.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/parts/AppPanel.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { Grid } from '@elliemae/ds-grid';\nimport { useFocusTrap } from '@elliemae/ds-hooks-focus-trap';\nimport { styled } from '@elliemae/ds-system';\nimport React, { memo, useCallback, useContext, useEffect } from 'react';\nimport {\n APP_PICKER_REGION_FOCUSES,\n DSAppPickerDataTestIds,\n DSAppPickerName,\n DSAppPickerSlots,\n} from '../constants/index.js';\nimport { DSAppPickerContext } from '../DSAppPickerCTX.js';\nimport { AppSection } from './AppSection.js';\nimport { StyledListItemFullRow } from './shared-styles.js';\n\nconst StyledWrapper = styled(Grid, { name: DSAppPickerName, slot: DSAppPickerSlots.ROOT })`\n background-color: ${({ theme }) => theme.colors.neutral['000']};\n min-width: 308px;\n min-height: 110px;\n max-height: 449px;\n width: 308px;\n overflow-y: auto;\n overflow-x: hidden;\n /* Baseline 2024: reserve scrollbar gutter so the layout doesn't shift between overflow/no-overflow.\n Replaces a JS isOverflow detection effect that toggled right padding. */\n scrollbar-gutter: stable;\n margin: 0;\n padding: 0 0 8px 16px;\n &:focus {\n outline: none;\n }\n`;\n\nconst StyledSeparator = styled('hr', { name: DSAppPickerName, slot: DSAppPickerSlots.SEPARATOR })`\n border-top: 1px solid ${({ theme }) => theme.colors.neutral[300]};\n border-bottom: none;\n width: 100%;\n margin: 8px 0 0 0;\n`;\n\nconst wrapperGridLayout = {\n cols: ['repeat(3, 92px)'],\n // Row tracks are intentionally auto-sized:\n // - title row picks up its own typography height\n // - chip rows expand when `wrapText` causes a chip to wrap onto a second line (Reflow story)\n // - separator row picks up its own 1px height + margin\n rows: ['auto'],\n};\n\nconst useExecOnceAfterFirstRender = (callback: () => void) => {\n const hasExecutedRef = React.useRef(false);\n const executeInitialFocusRef = React.useRef(callback);\n executeInitialFocusRef.current = callback;\n useEffect(() => {\n if (!hasExecutedRef.current) {\n executeInitialFocusRef.current();\n hasExecutedRef.current = true;\n }\n }, []);\n};\n\ntype MountedOpenAutofocusNuanceConfig = {\n pendingRef: React.MutableRefObject<boolean>;\n trackFocusPanel: () => void;\n};\n\n/**\n * NUANCE \u2014 the single case that initial-focus-on-open (useAppPickerFloatingContext's onOpen) cannot\n * cover: DSAppPicker rendered ALREADY open (declarative `isOpen` at mount, no user interaction).\n * That open is not a transition, so `onOpen` never fires for it. This mount-time hook seeds the panel\n * wrapper, which is what a pointer open seeds too: there was no gesture at all here, so the\n * keyboard-only \"land on the selected app\" rule does not apply, and the panel is the target that gets\n * the dialog announced. `pendingRef` is true only when the component started open and is flipped\n * false on first consume, so a later controlled reopen \u2014 a real transition handled by `onOpen` \u2014\n * does not double-seed. Every user-driven open (click/keyboard) is a transition handled by `onOpen`,\n * NOT here.\n *\n * REMOVABILITY: if the team decides declarative-open should not autofocus, delete this hook and its\n * call, and flip the \"rendered already-open \u2026 focuses the panel wrapper\" assertions in\n * DSAppPicker.keyboard.test.js. Nothing else depends on it.\n */\nconst useMountedOpenAutofocusNuance = ({ pendingRef, trackFocusPanel }: MountedOpenAutofocusNuanceConfig) => {\n useExecOnceAfterFirstRender(() => {\n if (!pendingRef.current) return;\n pendingRef.current = false;\n trackFocusPanel();\n });\n};\n\nconst AppPanelBase = () => {\n const {\n propsWithDefault: { customApps, onKeyDown },\n ownerPropsConfig,\n globalAttributes,\n xstyledProps,\n mountedOpenAutofocusPendingRef,\n focusTrackers: { focusRegion, firstFocusableRef, lastFocusableRef, trackFocusPanel },\n } = useContext(DSAppPickerContext);\n\n // Global attributes are spread here, on the panel root, which is this component's root for the purpose\n // of the Dimsum convention that global attributes land on the styled root (see project_slots.md \u2014 it is\n // gate 2 of `data-dimsum-parent-slot`, and a component spreading them on an inner control is treated as\n // a defect, not a variant).\n //\n // There is no element containing both the trigger and the floating panel, so \"root\" has to be chosen\n // rather than read off the tree. The panel is the right choice, and not merely the larger one: the\n // floating context, the sections and the chips are what this component actually is, while the trigger is\n // the replaceable part \u2014 `TriggerComponent` already lets a consumer supply their own, and the direction\n // ds-menu-button points at (a behavioural layer wrapping arbitrary children, with the menu as its own\n // part) would make it fully app-owned. The panel stays the root through that change; a trigger-rooted\n // choice would not survive it.\n //\n // `wrap`, `onClick`, and `onKeyDown` are filtered out because they collide with the public component API\n // (which uses these for different semantics).\n const { wrap, onClick, onKeyDown: onKeyDownGlobal, ...safeGlobalAttributes } = globalAttributes;\n\n // ---------------------------------------------------------------------------\n // Initial focus on panel open.\n // ---------------------------------------------------------------------------\n // User-driven opens (click/keyboard) are open transitions, seeded by\n // useAppPickerFloatingContext's onOpen. The one case that isn't a transition \u2014 being rendered\n // already-open (declarative `isOpen` at mount) \u2014 is covered here, scoped to exactly that.\n useMountedOpenAutofocusNuance({\n pendingRef: mountedOpenAutofocusPendingRef,\n trackFocusPanel,\n });\n\n // ---------------------------------------------------------------------------\n // Panel wrapper \u2014 tracker-driven focus for the mouse-open announcement path.\n // handleWrapperRef gets a new reference when isWrapperFocused changes \u2192 React\n // re-invokes the callback with the DOM node \u2192 node.focus() fires.\n // ---------------------------------------------------------------------------\n const isWrapperFocused = focusRegion === APP_PICKER_REGION_FOCUSES.PANEL;\n\n const handleWrapperRef = useCallback(\n (node: HTMLElement | null) => {\n if (node && isWrapperFocused) node.focus();\n },\n [isWrapperFocused],\n );\n\n // Default Escape-close/refocus is handled declaratively by useFloatingContext\n // (see useAppPickerFloatingContext's closeOnEscape/onEscape wiring) whenever there is no consumer\n // onKeyDown \u2014 a consumer-provided onKeyDown takes over keydown handling entirely.\n const handleOnKeyDown = useFocusTrap({\n firstElementRef: firstFocusableRef,\n lastElementRef: lastFocusableRef,\n onKeyDown,\n });\n\n // The panel root carries NO aria-label: it is a roleless element (generic role does not support\n // an accessible name, so any label here is dropped by assistive tech). The component's accessible\n // name lives on the dialog \u2014 see AppPickerContent's role=\"dialog\" + aria-labelledby.\n return (\n <StyledWrapper\n innerRef={handleWrapperRef}\n data-testid={DSAppPickerDataTestIds.ROOT}\n cols={wrapperGridLayout.cols}\n rows={wrapperGridLayout.rows}\n // when opening the dialog via mouse, the focus is programmatically assigned here via handleWrapperRef, -1 allows .focus() to work\n tabIndex={-1}\n {...ownerPropsConfig}\n {...safeGlobalAttributes}\n {...xstyledProps}\n onKeyDown={handleOnKeyDown}\n >\n <AppSection />\n {customApps.length > 0 && (\n <>\n <StyledListItemFullRow data-testid={DSAppPickerDataTestIds.ROW} {...ownerPropsConfig}>\n <StyledSeparator data-testid={DSAppPickerDataTestIds.SEPARATOR} {...ownerPropsConfig} />\n </StyledListItemFullRow>\n <AppSection isCustomApps />\n </>\n )}\n </StyledWrapper>\n );\n};\n\nexport const AppPanel = memo(AppPanelBase);\nAppPanel.displayName = 'DSAppPicker.AppPanel';\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACqKjB,SAEE,UAFF,KAEE,YAFF;AArKN,SAAS,YAAY;AACrB,SAAS,oBAAoB;AAC7B,SAAS,cAAc;AACvB,OAAOA,UAAS,MAAM,aAAa,YAAY,iBAAiB;AAChE;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;AACnC,SAAS,kBAAkB;AAC3B,SAAS,6BAA6B;AAEtC,MAAM,gBAAgB,OAAO,MAAM,EAAE,MAAM,iBAAiB,MAAM,iBAAiB,KAAK,CAAC;AAAA,sBACnE,CAAC,EAAE,MAAM,MAAM,MAAM,OAAO,QAAQ,KAAK,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBhE,MAAM,kBAAkB,OAAO,MAAM,EAAE,MAAM,iBAAiB,MAAM,iBAAiB,UAAU,CAAC;AAAA,0BACtE,CAAC,EAAE,MAAM,MAAM,MAAM,OAAO,QAAQ,GAAG,CAAC;AAAA;AAAA;AAAA;AAAA;AAMlE,MAAM,oBAAoB;AAAA,EACxB,MAAM,CAAC,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA,EAKxB,MAAM,CAAC,MAAM;AACf;AAEA,MAAM,8BAA8B,CAAC,aAAyB;AAC5D,QAAM,iBAAiBA,OAAM,OAAO,KAAK;AACzC,QAAM,yBAAyBA,OAAM,OAAO,QAAQ;AACpD,yBAAuB,UAAU;AACjC,YAAU,MAAM;AACd,QAAI,CAAC,eAAe,SAAS;AAC3B,6BAAuB,QAAQ;AAC/B,qBAAe,UAAU;AAAA,IAC3B;AAAA,EACF,GAAG,CAAC,CAAC;AACP;AAsBA,MAAM,gCAAgC,CAAC,EAAE,YAAY,gBAAgB,MAAwC;AAC3G,8BAA4B,MAAM;AAChC,QAAI,CAAC,WAAW,QAAS;AACzB,eAAW,UAAU;AACrB,oBAAgB;AAAA,EAClB,CAAC;AACH;AAEA,MAAM,eAAe,MAAM;AACzB,QAAM;AAAA,IACJ,kBAAkB,EAAE,YAAY,UAAU;AAAA,IAC1C;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,eAAe,EAAE,aAAa,mBAAmB,kBAAkB,gBAAgB;AAAA,EACrF,IAAI,WAAW,kBAAkB;AAiBjC,QAAM,EAAE,MAAM,SAAS,WAAW,iBAAiB,GAAG,qBAAqB,IAAI;AAQ/E,gCAA8B;AAAA,IAC5B,YAAY;AAAA,IACZ;AAAA,EACF,CAAC;AAOD,QAAM,mBAAmB,gBAAgB,0BAA0B;AAEnE,QAAM,mBAAmB;AAAA,IACvB,CAAC,SAA6B;AAC5B,UAAI,QAAQ,iBAAkB,MAAK,MAAM;AAAA,IAC3C;AAAA,IACA,CAAC,gBAAgB;AAAA,EACnB;AAKA,QAAM,kBAAkB,aAAa;AAAA,IACnC,iBAAiB;AAAA,IACjB,gBAAgB;AAAA,IAChB;AAAA,EACF,CAAC;AAKD,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU;AAAA,MACV,eAAa,uBAAuB;AAAA,MACpC,MAAM,kBAAkB;AAAA,MACxB,MAAM,kBAAkB;AAAA,MAExB,UAAU;AAAA,MACT,GAAG;AAAA,MACH,GAAG;AAAA,MACH,GAAG;AAAA,MACJ,WAAW;AAAA,MAEX;AAAA,4BAAC,cAAW;AAAA,QACX,WAAW,SAAS,KACnB,iCACE;AAAA,8BAAC,yBAAsB,eAAa,uBAAuB,KAAM,GAAG,kBAClE,8BAAC,mBAAgB,eAAa,uBAAuB,WAAY,GAAG,kBAAkB,GACxF;AAAA,UACA,oBAAC,cAAW,cAAY,MAAC;AAAA,WAC3B;AAAA;AAAA;AAAA,EAEJ;AAEJ;AAEO,MAAM,WAAW,KAAK,YAAY;AACzC,SAAS,cAAc;",
|
|
6
|
+
"names": ["React"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { FloatingWrapper, PopoverArrow } from "@elliemae/ds-floating-context";
|
|
4
|
+
import { styled } from "@elliemae/ds-system";
|
|
5
|
+
import { useContext } from "react";
|
|
6
|
+
import { DSAppPickerName, DSAppPickerSlots } from "../../constants/index.js";
|
|
7
|
+
import { DSAppPickerContext } from "../../DSAppPickerCTX.js";
|
|
8
|
+
import { getIdForAppPickerTrigger } from "../../util/instanceIds.js";
|
|
9
|
+
import { AppPanel } from "../AppPanel.js";
|
|
10
|
+
import { Trigger } from "../Trigger.js";
|
|
11
|
+
import { useAppPickerFloatingContext } from "./useAppPickerFloatingContext.js";
|
|
12
|
+
const StyledAppPickerFloating = styled(FloatingWrapper, {
|
|
13
|
+
name: DSAppPickerName,
|
|
14
|
+
slot: DSAppPickerSlots.FLOATING_WRAPPER
|
|
15
|
+
})``;
|
|
16
|
+
const AppPickerContent = () => {
|
|
17
|
+
const {
|
|
18
|
+
ownerPropsConfig,
|
|
19
|
+
propsWithDefault,
|
|
20
|
+
focusTrackers,
|
|
21
|
+
openIntentRef,
|
|
22
|
+
resolvedIsOpen,
|
|
23
|
+
setInternalIsOpen,
|
|
24
|
+
instanceUid
|
|
25
|
+
} = useContext(DSAppPickerContext);
|
|
26
|
+
const {
|
|
27
|
+
floatingStyles,
|
|
28
|
+
arrowStyles,
|
|
29
|
+
floatingContext,
|
|
30
|
+
floatingInnerRef,
|
|
31
|
+
handleTriggerRef,
|
|
32
|
+
handleTriggerClick,
|
|
33
|
+
handleTriggerKeyDown
|
|
34
|
+
} = useAppPickerFloatingContext({
|
|
35
|
+
propsWithDefault,
|
|
36
|
+
focusTrackers,
|
|
37
|
+
openIntentRef,
|
|
38
|
+
resolvedIsOpen,
|
|
39
|
+
setInternalIsOpen
|
|
40
|
+
});
|
|
41
|
+
const dialogLabelId = getIdForAppPickerTrigger(instanceUid);
|
|
42
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
43
|
+
/* @__PURE__ */ jsx(
|
|
44
|
+
Trigger,
|
|
45
|
+
{
|
|
46
|
+
handleTriggerRef,
|
|
47
|
+
handleTriggerClick,
|
|
48
|
+
handleTriggerKeyDown,
|
|
49
|
+
dialogLabelId
|
|
50
|
+
}
|
|
51
|
+
),
|
|
52
|
+
/* @__PURE__ */ jsxs(
|
|
53
|
+
StyledAppPickerFloating,
|
|
54
|
+
{
|
|
55
|
+
innerRef: floatingInnerRef,
|
|
56
|
+
isOpen: resolvedIsOpen,
|
|
57
|
+
floatingStyles,
|
|
58
|
+
context: floatingContext,
|
|
59
|
+
getOwnerProps: ownerPropsConfig.getOwnerProps,
|
|
60
|
+
getOwnerPropsArguments: ownerPropsConfig.getOwnerPropsArguments,
|
|
61
|
+
role: "dialog",
|
|
62
|
+
"aria-labelledby": dialogLabelId,
|
|
63
|
+
children: [
|
|
64
|
+
/* @__PURE__ */ jsx(AppPanel, {}),
|
|
65
|
+
/* @__PURE__ */ jsx(PopoverArrow, { ...arrowStyles })
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
)
|
|
69
|
+
] });
|
|
70
|
+
};
|
|
71
|
+
export {
|
|
72
|
+
AppPickerContent
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=AppPickerContent.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../../scripts/build/transpile/react-shim.js", "../../../../src/parts/AppPickerFloatingContext/AppPickerContent.tsx"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { FloatingWrapper, PopoverArrow } from '@elliemae/ds-floating-context';\nimport { styled } from '@elliemae/ds-system';\nimport React, { useContext } from 'react';\nimport { DSAppPickerName, DSAppPickerSlots } from '../../constants/index.js';\nimport { DSAppPickerContext } from '../../DSAppPickerCTX.js';\nimport type { DSAppPickerT } from '../../react-desc-prop-types.js';\nimport { getIdForAppPickerTrigger } from '../../util/instanceIds.js';\nimport { AppPanel } from '../AppPanel.js';\nimport { Trigger } from '../Trigger.js';\nimport { useAppPickerFloatingContext } from './useAppPickerFloatingContext.js';\n\nconst StyledAppPickerFloating = styled(FloatingWrapper, {\n name: DSAppPickerName,\n slot: DSAppPickerSlots.FLOATING_WRAPPER,\n})``;\n\nexport const AppPickerContent: React.ComponentType<DSAppPickerT.Props> = () => {\n const {\n ownerPropsConfig,\n propsWithDefault,\n focusTrackers,\n openIntentRef,\n resolvedIsOpen,\n setInternalIsOpen,\n instanceUid,\n } = useContext(DSAppPickerContext);\n const {\n floatingStyles,\n arrowStyles,\n floatingContext,\n floatingInnerRef,\n handleTriggerRef,\n handleTriggerClick,\n handleTriggerKeyDown,\n } = useAppPickerFloatingContext({\n propsWithDefault,\n focusTrackers,\n openIntentRef,\n resolvedIsOpen,\n setInternalIsOpen,\n });\n\n // Suffix owned by util/instanceIds \u2014 never composed inline, so consumers and this call site cannot\n // drift apart. `getIdForAppPickerTrigger` is the exported counterpart.\n const dialogLabelId = getIdForAppPickerTrigger(instanceUid);\n\n return (\n <>\n <Trigger\n handleTriggerRef={handleTriggerRef}\n handleTriggerClick={handleTriggerClick}\n handleTriggerKeyDown={handleTriggerKeyDown}\n dialogLabelId={dialogLabelId}\n />\n <StyledAppPickerFloating\n innerRef={floatingInnerRef}\n isOpen={resolvedIsOpen}\n floatingStyles={floatingStyles}\n context={floatingContext}\n getOwnerProps={ownerPropsConfig.getOwnerProps}\n getOwnerPropsArguments={ownerPropsConfig.getOwnerPropsArguments}\n role=\"dialog\"\n aria-labelledby={dialogLabelId}\n >\n <AppPanel />\n <PopoverArrow {...arrowStyles} />\n </StyledAppPickerFloating>\n </>\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;AC+CnB,mBACE,KAMA,YAPF;AA/CJ,SAAS,iBAAiB,oBAAoB;AAC9C,SAAS,cAAc;AACvB,SAAgB,kBAAkB;AAClC,SAAS,iBAAiB,wBAAwB;AAClD,SAAS,0BAA0B;AAEnC,SAAS,gCAAgC;AACzC,SAAS,gBAAgB;AACzB,SAAS,eAAe;AACxB,SAAS,mCAAmC;AAE5C,MAAM,0BAA0B,OAAO,iBAAiB;AAAA,EACtD,MAAM;AAAA,EACN,MAAM,iBAAiB;AACzB,CAAC;AAEM,MAAM,mBAA4D,MAAM;AAC7E,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,kBAAkB;AACjC,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,4BAA4B;AAAA,IAC9B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAID,QAAM,gBAAgB,yBAAyB,WAAW;AAE1D,SACE,iCACE;AAAA;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACF;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACC,UAAU;AAAA,QACV,QAAQ;AAAA,QACR;AAAA,QACA,SAAS;AAAA,QACT,eAAe,iBAAiB;AAAA,QAChC,wBAAwB,iBAAiB;AAAA,QACzC,MAAK;AAAA,QACL,mBAAiB;AAAA,QAEjB;AAAA,8BAAC,YAAS;AAAA,UACV,oBAAC,gBAAc,GAAG,aAAa;AAAA;AAAA;AAAA,IACjC;AAAA,KACF;AAEJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useFloatingContext } from "@elliemae/ds-floating-context";
|
|
3
|
+
import { useCallback, useMemo, useRef } from "react";
|
|
4
|
+
const useAppPickerFloatingContext = (appPickerConfig) => {
|
|
5
|
+
const { propsWithDefault, focusTrackers, openIntentRef, resolvedIsOpen, setInternalIsOpen } = appPickerConfig;
|
|
6
|
+
const {
|
|
7
|
+
onOpen,
|
|
8
|
+
onClose,
|
|
9
|
+
actionRef,
|
|
10
|
+
onClick,
|
|
11
|
+
onClickOutside,
|
|
12
|
+
onKeyDown,
|
|
13
|
+
triggerRef,
|
|
14
|
+
isOpen,
|
|
15
|
+
openAndFocusOnArrowKeys
|
|
16
|
+
} = propsWithDefault;
|
|
17
|
+
const isControlled = typeof isOpen === "boolean";
|
|
18
|
+
const { trackFocusSelectedItem, trackFocusSelectedOrLastItem, trackFocusItemAtIndex, trackFocusPanel } = focusTrackers;
|
|
19
|
+
const defaultTriggerRef = useRef(null);
|
|
20
|
+
const handleClickOutside = useCallback(
|
|
21
|
+
(e) => {
|
|
22
|
+
if (!isControlled) onClose?.({ reason: "click-outside", event: e });
|
|
23
|
+
setInternalIsOpen(false);
|
|
24
|
+
onClickOutside?.(e);
|
|
25
|
+
},
|
|
26
|
+
[isControlled, onClose, setInternalIsOpen, onClickOutside]
|
|
27
|
+
);
|
|
28
|
+
const handleScopedEscape = useCallback(
|
|
29
|
+
(event) => {
|
|
30
|
+
if (!isControlled) onClose?.({ reason: "escape", event });
|
|
31
|
+
setInternalIsOpen(false);
|
|
32
|
+
},
|
|
33
|
+
[isControlled, onClose, setInternalIsOpen]
|
|
34
|
+
);
|
|
35
|
+
const handleFloatingClose = useCallback(
|
|
36
|
+
(info) => {
|
|
37
|
+
if (info.reason === "controlled-flip" && isControlled) onClose?.({ reason: "controlled" });
|
|
38
|
+
},
|
|
39
|
+
[isControlled, onClose]
|
|
40
|
+
);
|
|
41
|
+
const handleFloatingOpen = useCallback(
|
|
42
|
+
(info) => {
|
|
43
|
+
if (openIntentRef.current === "keyboard-first") trackFocusSelectedItem();
|
|
44
|
+
else if (openIntentRef.current === "keyboard-last") trackFocusSelectedOrLastItem();
|
|
45
|
+
else trackFocusPanel();
|
|
46
|
+
if (info.reason === "controlled-flip" && isControlled) onOpen?.({ reason: "controlled" });
|
|
47
|
+
},
|
|
48
|
+
[openIntentRef, trackFocusSelectedItem, trackFocusSelectedOrLastItem, trackFocusPanel, isControlled, onOpen]
|
|
49
|
+
);
|
|
50
|
+
const floatingContextConfig = useMemo(
|
|
51
|
+
() => ({
|
|
52
|
+
placement: "bottom",
|
|
53
|
+
// Arrow tip is ~6.1px above the panel top (arrowPlacementBase16 ≈ 17.5px, tip at 11.4px from box top).
|
|
54
|
+
// 4px spec gap → 4 + 6.1 ≈ 10px offset.
|
|
55
|
+
customOffset: [0, 10],
|
|
56
|
+
externallyControlledIsOpen: resolvedIsOpen,
|
|
57
|
+
withoutAnimation: true,
|
|
58
|
+
onClickOutside: handleClickOutside,
|
|
59
|
+
/*
|
|
60
|
+
* Two conditions, and the second is a safety gate rather than a preference.
|
|
61
|
+
*
|
|
62
|
+
* `!onKeyDown` — a consumer who supplies onKeyDown owns the key entirely, so useFloatingContext
|
|
63
|
+
* neither routes the Escape to onEscape (see handleScopedEscape) nor returns focus to the trigger.
|
|
64
|
+
*
|
|
65
|
+
* `!isControlled` — `returnFocusToReference` is true below, and the hook applies it on a scoped
|
|
66
|
+
* Escape regardless of who owns the open state. For a controlled picker `handleScopedEscape`'s
|
|
67
|
+
* `setInternalIsOpen(false)` is inert, so leaving this on would move focus to the trigger while
|
|
68
|
+
* the consumer's panel is still open: focus outside an open dialog. A controlled consumer owns
|
|
69
|
+
* the close, so they own the Escape and the refocus that goes with it.
|
|
70
|
+
*/
|
|
71
|
+
closeOnEscape: !onKeyDown && !isControlled,
|
|
72
|
+
onClose: handleFloatingClose,
|
|
73
|
+
onEscape: handleScopedEscape,
|
|
74
|
+
onOpen: handleFloatingOpen,
|
|
75
|
+
returnFocusToReference: true,
|
|
76
|
+
externalReferenceElement: triggerRef?.current || defaultTriggerRef.current
|
|
77
|
+
}),
|
|
78
|
+
[
|
|
79
|
+
handleClickOutside,
|
|
80
|
+
handleScopedEscape,
|
|
81
|
+
handleFloatingClose,
|
|
82
|
+
handleFloatingOpen,
|
|
83
|
+
isControlled,
|
|
84
|
+
onKeyDown,
|
|
85
|
+
resolvedIsOpen,
|
|
86
|
+
triggerRef
|
|
87
|
+
]
|
|
88
|
+
);
|
|
89
|
+
const {
|
|
90
|
+
refs: floatingRefs,
|
|
91
|
+
floatingStyles,
|
|
92
|
+
arrowStyles,
|
|
93
|
+
context: floatingContext
|
|
94
|
+
} = useFloatingContext(floatingContextConfig);
|
|
95
|
+
const handleTriggerRef = useCallback(
|
|
96
|
+
(node) => {
|
|
97
|
+
defaultTriggerRef.current = node;
|
|
98
|
+
floatingRefs.setReference(node);
|
|
99
|
+
if (triggerRef) {
|
|
100
|
+
triggerRef.current = node;
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
[floatingRefs, triggerRef]
|
|
104
|
+
);
|
|
105
|
+
const handleActionRef = useCallback(
|
|
106
|
+
(node) => {
|
|
107
|
+
if (node && actionRef?.current) {
|
|
108
|
+
actionRef.current.focusToIndex = (index) => {
|
|
109
|
+
trackFocusItemAtIndex(index);
|
|
110
|
+
};
|
|
111
|
+
actionRef.current.focusWrapper = () => {
|
|
112
|
+
trackFocusPanel();
|
|
113
|
+
};
|
|
114
|
+
actionRef.current.focusSelectedOrFirstAvailable = () => {
|
|
115
|
+
trackFocusSelectedItem();
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
[actionRef, trackFocusItemAtIndex, trackFocusPanel, trackFocusSelectedItem]
|
|
120
|
+
);
|
|
121
|
+
const floatingInnerRef = useCallback(
|
|
122
|
+
(node) => {
|
|
123
|
+
floatingRefs.setFloating(node);
|
|
124
|
+
handleActionRef(node);
|
|
125
|
+
},
|
|
126
|
+
[floatingRefs.setFloating, handleActionRef]
|
|
127
|
+
);
|
|
128
|
+
const handleTriggerClick = useCallback(
|
|
129
|
+
(e) => {
|
|
130
|
+
openIntentRef.current = e.detail === 0 ? "keyboard-first" : "pointer";
|
|
131
|
+
onClick?.(e);
|
|
132
|
+
if (!isControlled) {
|
|
133
|
+
if (resolvedIsOpen) onClose?.({ reason: "trigger-toggle", event: e });
|
|
134
|
+
else onOpen?.({ reason: "trigger", event: e });
|
|
135
|
+
}
|
|
136
|
+
setInternalIsOpen((prev) => !prev);
|
|
137
|
+
},
|
|
138
|
+
[onClick, openIntentRef, setInternalIsOpen, isControlled, resolvedIsOpen, onClose, onOpen]
|
|
139
|
+
);
|
|
140
|
+
const handleTriggerKeyDown = useCallback(
|
|
141
|
+
(e) => {
|
|
142
|
+
if (!openAndFocusOnArrowKeys) return;
|
|
143
|
+
if (e.code !== "ArrowDown" && e.code !== "ArrowUp") return;
|
|
144
|
+
if (resolvedIsOpen) return;
|
|
145
|
+
e.preventDefault();
|
|
146
|
+
openIntentRef.current = e.code === "ArrowDown" ? "keyboard-first" : "keyboard-last";
|
|
147
|
+
if (!isControlled) onOpen?.({ reason: "trigger", event: e });
|
|
148
|
+
setInternalIsOpen(true);
|
|
149
|
+
},
|
|
150
|
+
[openAndFocusOnArrowKeys, resolvedIsOpen, openIntentRef, isControlled, onOpen, setInternalIsOpen]
|
|
151
|
+
);
|
|
152
|
+
return {
|
|
153
|
+
floatingStyles,
|
|
154
|
+
arrowStyles,
|
|
155
|
+
floatingContext,
|
|
156
|
+
handleTriggerRef,
|
|
157
|
+
handleTriggerClick,
|
|
158
|
+
handleTriggerKeyDown,
|
|
159
|
+
floatingInnerRef
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
export {
|
|
163
|
+
useAppPickerFloatingContext
|
|
164
|
+
};
|
|
165
|
+
//# sourceMappingURL=useAppPickerFloatingContext.js.map
|