@wix/bex-utils 2.20.0 → 2.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/cjs/FocusableWrapper/FocusableService.js +47 -0
  2. package/dist/cjs/FocusableWrapper/FocusableService.js.map +1 -0
  3. package/dist/cjs/FocusableWrapper/FocusableWrapper.js +72 -0
  4. package/dist/cjs/FocusableWrapper/FocusableWrapper.js.map +1 -0
  5. package/dist/cjs/FocusableWrapper/scrollAndFocus.js +30 -0
  6. package/dist/cjs/FocusableWrapper/scrollAndFocus.js.map +1 -0
  7. package/dist/cjs/FocusableWrapper/withFocusable.js +32 -0
  8. package/dist/cjs/FocusableWrapper/withFocusable.js.map +1 -0
  9. package/dist/cjs/index.js +12 -0
  10. package/dist/cjs/index.js.map +1 -1
  11. package/dist/esm/FocusableWrapper/FocusableService.js +26 -0
  12. package/dist/esm/FocusableWrapper/FocusableService.js.map +1 -0
  13. package/dist/esm/FocusableWrapper/FocusableWrapper.js +50 -0
  14. package/dist/esm/FocusableWrapper/FocusableWrapper.js.map +1 -0
  15. package/dist/esm/FocusableWrapper/scrollAndFocus.js +25 -0
  16. package/dist/esm/FocusableWrapper/scrollAndFocus.js.map +1 -0
  17. package/dist/esm/FocusableWrapper/withFocusable.js +15 -0
  18. package/dist/esm/FocusableWrapper/withFocusable.js.map +1 -0
  19. package/dist/esm/index.js +2 -0
  20. package/dist/esm/index.js.map +1 -1
  21. package/dist/types/FocusableWrapper/FocusableService.d.ts +20 -0
  22. package/dist/types/FocusableWrapper/FocusableService.d.ts.map +1 -0
  23. package/dist/types/FocusableWrapper/FocusableWrapper.d.ts +17 -0
  24. package/dist/types/FocusableWrapper/FocusableWrapper.d.ts.map +1 -0
  25. package/dist/types/FocusableWrapper/scrollAndFocus.d.ts +2 -0
  26. package/dist/types/FocusableWrapper/scrollAndFocus.d.ts.map +1 -0
  27. package/dist/types/FocusableWrapper/withFocusable.d.ts +5 -0
  28. package/dist/types/FocusableWrapper/withFocusable.d.ts.map +1 -0
  29. package/dist/types/index.d.ts +2 -0
  30. package/dist/types/index.d.ts.map +1 -1
  31. package/package.json +2 -2
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ exports.__esModule = true;
5
+ exports.FocusableItemsService = void 0;
6
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
7
+ class FocusableItemsService {
8
+ constructor() {
9
+ (0, _defineProperty2.default)(this, "focusableItems", void 0);
10
+ (0, _defineProperty2.default)(this, "scrollableContainers", void 0);
11
+ (0, _defineProperty2.default)(this, "getItemRef", itemName => this.focusableItems[itemName] && this.focusableItems[itemName].ref);
12
+ (0, _defineProperty2.default)(this, "getContainerRefByItem", itemName => {
13
+ var _this$focusableItems$;
14
+ const containerName = (_this$focusableItems$ = this.focusableItems[itemName]) == null ? void 0 : _this$focusableItems$.containerName;
15
+ const container = this.scrollableContainers[containerName];
16
+ return container == null ? void 0 : container.ref;
17
+ });
18
+ (0, _defineProperty2.default)(this, "getContainerRefByName", containerName => {
19
+ const container = this.scrollableContainers[containerName];
20
+ return container == null ? void 0 : container.ref;
21
+ });
22
+ this.focusableItems = {};
23
+ this.scrollableContainers = {};
24
+ }
25
+ addItem({
26
+ ref,
27
+ itemName,
28
+ containerName
29
+ }) {
30
+ this.focusableItems[itemName] = {
31
+ itemName,
32
+ ref,
33
+ containerName
34
+ };
35
+ }
36
+ addContainer({
37
+ containerName,
38
+ ref
39
+ }) {
40
+ this.scrollableContainers[containerName] = {
41
+ containerName,
42
+ ref
43
+ };
44
+ }
45
+ }
46
+ exports.FocusableItemsService = FocusableItemsService;
47
+ //# sourceMappingURL=FocusableService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["FocusableItemsService","constructor","_defineProperty2","default","itemName","focusableItems","ref","_this$focusableItems$","containerName","container","scrollableContainers","addItem","addContainer","exports"],"sources":["../../../src/FocusableWrapper/FocusableService.ts"],"sourcesContent":["export type FocusableItem = {\n containerName: string;\n ref: HTMLElement;\n itemName: string;\n};\n\nexport type ScrollableContainer = {\n containerName: string;\n ref: HTMLElement;\n};\n\nexport class FocusableItemsService {\n private focusableItems: {\n [itemName: string]: FocusableItem;\n };\n private scrollableContainers: {\n [containerName: string]: {\n ref: HTMLElement;\n containerName: string;\n };\n };\n\n constructor() {\n this.focusableItems = {};\n this.scrollableContainers = {};\n }\n\n addItem({ ref, itemName, containerName }: FocusableItem) {\n this.focusableItems[itemName] = { itemName, ref, containerName };\n }\n\n addContainer({ containerName, ref }: ScrollableContainer) {\n this.scrollableContainers[containerName] = {\n containerName,\n ref,\n };\n }\n\n getItemRef = (itemName: string) =>\n this.focusableItems[itemName] && this.focusableItems[itemName].ref;\n getContainerRefByItem = (itemName: string) => {\n const containerName = this.focusableItems[itemName]?.containerName;\n const container = this.scrollableContainers[containerName];\n return container?.ref;\n };\n getContainerRefByName = (containerName: string) => {\n const container = this.scrollableContainers[containerName];\n return container?.ref;\n };\n}\n"],"mappings":";;;;;;AAWO,MAAMA,qBAAqB,CAAC;EAWjCC,WAAWA,CAAA,EAAG;IAAA,IAAAC,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA;IAAA,IAAAD,gBAAA,CAAAC,OAAA,sBAgBAC,QAAgB,IAC5B,IAAI,CAACC,cAAc,CAACD,QAAQ,CAAC,IAAI,IAAI,CAACC,cAAc,CAACD,QAAQ,CAAC,CAACE,GAAG;IAAA,IAAAJ,gBAAA,CAAAC,OAAA,iCAC3CC,QAAgB,IAAK;MAAA,IAAAG,qBAAA;MAC5C,MAAMC,aAAa,IAAAD,qBAAA,GAAG,IAAI,CAACF,cAAc,CAACD,QAAQ,CAAC,qBAA7BG,qBAAA,CAA+BC,aAAa;MAClE,MAAMC,SAAS,GAAG,IAAI,CAACC,oBAAoB,CAACF,aAAa,CAAC;MAC1D,OAAOC,SAAS,oBAATA,SAAS,CAAEH,GAAG;IACvB,CAAC;IAAA,IAAAJ,gBAAA,CAAAC,OAAA,iCACwBK,aAAqB,IAAK;MACjD,MAAMC,SAAS,GAAG,IAAI,CAACC,oBAAoB,CAACF,aAAa,CAAC;MAC1D,OAAOC,SAAS,oBAATA,SAAS,CAAEH,GAAG;IACvB,CAAC;IAzBC,IAAI,CAACD,cAAc,GAAG,CAAC,CAAC;IACxB,IAAI,CAACK,oBAAoB,GAAG,CAAC,CAAC;EAChC;EAEAC,OAAOA,CAAC;IAAEL,GAAG;IAAEF,QAAQ;IAAEI;EAA6B,CAAC,EAAE;IACvD,IAAI,CAACH,cAAc,CAACD,QAAQ,CAAC,GAAG;MAAEA,QAAQ;MAAEE,GAAG;MAAEE;IAAc,CAAC;EAClE;EAEAI,YAAYA,CAAC;IAAEJ,aAAa;IAAEF;EAAyB,CAAC,EAAE;IACxD,IAAI,CAACI,oBAAoB,CAACF,aAAa,CAAC,GAAG;MACzCA,aAAa;MACbF;IACF,CAAC;EACH;AAaF;AAACO,OAAA,CAAAb,qBAAA,GAAAA,qBAAA","ignoreList":[]}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.getAnchorParam = exports.FocusableWrapper = exports.FocusableContext = void 0;
5
+ var _react = _interopRequireWildcard(require("react"));
6
+ var _FocusableService = require("./FocusableService");
7
+ var _scrollAndFocus = require("./scrollAndFocus");
8
+ var _jsxFileName = "/home/builduser/work/db7ea24852bc3350/packages/utils/dist/cjs/FocusableWrapper/FocusableWrapper.tsx";
9
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
+ const getAnchorParam = () => {
12
+ const searchParams = new URLSearchParams(window.location.search);
13
+ return searchParams.get('anchor');
14
+ };
15
+ exports.getAnchorParam = getAnchorParam;
16
+ const FocusableContext = exports.FocusableContext = /*#__PURE__*/_react.default.createContext(null);
17
+ const FocusableWrapper = ({
18
+ scrollableRef,
19
+ getScrollableTrigger,
20
+ getDoesItemExist,
21
+ children
22
+ }) => {
23
+ const focusableItemsService = (0, _react.useMemo)(() => new _FocusableService.FocusableItemsService(), []);
24
+ const scrollIfNeeded = (0, _react.useCallback)(() => {
25
+ const focusedItemName = getAnchorParam();
26
+ scrollByItemName(focusedItemName);
27
+ }, [scrollableRef]);
28
+ const scrollByItemName = (0, _react.useCallback)(focusedItemName => {
29
+ if (!focusedItemName) {
30
+ return;
31
+ }
32
+ const containerRefByItem = focusableItemsService.getContainerRefByItem(focusedItemName);
33
+ if (containerRefByItem) {
34
+ const focusedItem = focusableItemsService.getItemRef(focusedItemName);
35
+ return (0, _scrollAndFocus.scrollAndFocus)(scrollableRef, containerRefByItem, focusedItem);
36
+ }
37
+ const containerRef = focusableItemsService.getContainerRefByName(focusedItemName);
38
+ if (containerRef) {
39
+ (0, _scrollAndFocus.scrollAndFocus)(scrollableRef, containerRef, containerRef);
40
+ }
41
+ }, [focusableItemsService, scrollableRef]);
42
+ const doesItemExist = (0, _react.useCallback)(() => {
43
+ const focusedItemName = getAnchorParam();
44
+ if (!focusedItemName) {
45
+ return false;
46
+ }
47
+ return Boolean(focusableItemsService.getContainerRefByItem(focusedItemName));
48
+ }, [focusableItemsService]);
49
+ (0, _react.useEffect)(() => {
50
+ getScrollableTrigger(scrollIfNeeded);
51
+ getDoesItemExist(doesItemExist);
52
+ }, [getScrollableTrigger, getDoesItemExist, scrollIfNeeded, doesItemExist]);
53
+ const contextValue = (0, _react.useMemo)(() => ({
54
+ focusable: {
55
+ registerScrollableItem: scrollableItem => {
56
+ focusableItemsService.addContainer(scrollableItem);
57
+ focusableItemsService.addItem(scrollableItem);
58
+ }
59
+ }
60
+ }), [focusableItemsService]);
61
+ return /*#__PURE__*/_react.default.createElement(FocusableContext.Provider, {
62
+ value: contextValue,
63
+ __self: void 0,
64
+ __source: {
65
+ fileName: _jsxFileName,
66
+ lineNumber: 88,
67
+ columnNumber: 5
68
+ }
69
+ }, children);
70
+ };
71
+ exports.FocusableWrapper = FocusableWrapper;
72
+ //# sourceMappingURL=FocusableWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_FocusableService","_scrollAndFocus","_jsxFileName","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","getAnchorParam","searchParams","URLSearchParams","window","location","search","exports","FocusableContext","React","createContext","FocusableWrapper","scrollableRef","getScrollableTrigger","getDoesItemExist","children","focusableItemsService","useMemo","FocusableItemsService","scrollIfNeeded","useCallback","focusedItemName","scrollByItemName","containerRefByItem","getContainerRefByItem","focusedItem","getItemRef","scrollAndFocus","containerRef","getContainerRefByName","doesItemExist","Boolean","useEffect","contextValue","focusable","registerScrollableItem","scrollableItem","addContainer","addItem","createElement","Provider","value","__self","__source","fileName","lineNumber","columnNumber"],"sources":["../../../src/FocusableWrapper/FocusableWrapper.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useMemo } from 'react';\nimport { FocusableItem, FocusableItemsService } from './FocusableService';\nimport { scrollAndFocus } from './scrollAndFocus';\n\nexport const getAnchorParam = (): string | null => {\n const searchParams = new URLSearchParams(window.location.search);\n return searchParams.get('anchor');\n};\n\nexport type ContextProps = {\n focusable: {\n registerScrollableItem: (scrollableItem: FocusableItem) => void;\n };\n};\n\nexport const FocusableContext = React.createContext<ContextProps | null>(null);\n\ntype FocusableWrapperProps = {\n scrollableRef?: HTMLElement | null;\n getScrollableTrigger: (callback: () => void) => void;\n getDoesItemExist: (callback: () => boolean) => void;\n};\n\nexport const FocusableWrapper: React.FC<FocusableWrapperProps> = ({\n scrollableRef,\n getScrollableTrigger,\n getDoesItemExist,\n children,\n}) => {\n const focusableItemsService = useMemo(() => new FocusableItemsService(), []);\n\n const scrollIfNeeded = useCallback(() => {\n const focusedItemName = getAnchorParam();\n scrollByItemName(focusedItemName);\n }, [scrollableRef]);\n\n const scrollByItemName = useCallback(\n (focusedItemName: string | null) => {\n if (!focusedItemName) {\n return;\n }\n const containerRefByItem =\n focusableItemsService.getContainerRefByItem(focusedItemName);\n if (containerRefByItem) {\n const focusedItem = focusableItemsService.getItemRef(focusedItemName);\n return scrollAndFocus(scrollableRef, containerRefByItem, focusedItem);\n }\n\n const containerRef =\n focusableItemsService.getContainerRefByName(focusedItemName);\n if (containerRef) {\n scrollAndFocus(scrollableRef, containerRef, containerRef);\n }\n },\n [focusableItemsService, scrollableRef],\n );\n\n const doesItemExist = useCallback(() => {\n const focusedItemName = getAnchorParam();\n if (!focusedItemName) {\n return false;\n }\n\n return Boolean(\n focusableItemsService.getContainerRefByItem(focusedItemName),\n );\n }, [focusableItemsService]);\n\n useEffect(() => {\n getScrollableTrigger(scrollIfNeeded);\n\n getDoesItemExist(doesItemExist);\n }, [getScrollableTrigger, getDoesItemExist, scrollIfNeeded, doesItemExist]);\n\n const contextValue = useMemo<ContextProps>(\n () => ({\n focusable: {\n registerScrollableItem: (scrollableItem: FocusableItem) => {\n focusableItemsService.addContainer(scrollableItem);\n focusableItemsService.addItem(scrollableItem);\n },\n },\n }),\n [focusableItemsService],\n );\n\n return (\n <FocusableContext.Provider value={contextValue}>\n {children}\n </FocusableContext.Provider>\n );\n};\n"],"mappings":";;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,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AAM;IACtC,MAAMC,eAAe,GAAGpB,cAAc,CAAC,CAAC;IACxC,IAAI,CAACoB,eAAe,EAAE;MACpB,OAAO,KAAK;IACd;IAEA,OAAOU,OAAO,CACZf,qBAAqB,CAACQ,qBAAqB,CAACH,eAAe,CAC7D,CAAC;EACH,CAAC,EAAE,CAACL,qBAAqB,CAAC,CAAC;EAE3B,IAAAgB,gBAAS,EAAC,MAAM;IACdnB,oBAAoB,CAACM,cAAc,CAAC;IAEpCL,gBAAgB,CAACgB,aAAa,CAAC;EACjC,CAAC,EAAE,CAACjB,oBAAoB,EAAEC,gBAAgB,EAAEK,cAAc,EAAEW,aAAa,CAAC,CAAC;EAE3E,MAAMG,YAAY,GAAG,IAAAhB,cAAO,EAC1B,OAAO;IACLiB,SAAS,EAAE;MACTC,sBAAsB,EAAGC,cAA6B,IAAK;QACzDpB,qBAAqB,CAACqB,YAAY,CAACD,cAAc,CAAC;QAClDpB,qBAAqB,CAACsB,OAAO,CAACF,cAAc,CAAC;MAC/C;IACF;EACF,CAAC,CAAC,EACF,CAACpB,qBAAqB,CACxB,CAAC;EAED,oBACEzC,MAAA,CAAAY,OAAA,CAAAoD,aAAA,CAAC/B,gBAAgB,CAACgC,QAAQ;IAACC,KAAK,EAAER,YAAa;IAAAS,MAAA;IAAAC,QAAA;MAAAC,QAAA,EAAAhE,YAAA;MAAAiE,UAAA;MAAAC,YAAA;IAAA;EAAA,GAC5C/B,QACwB,CAAC;AAEhC,CAAC;AAACR,OAAA,CAAAI,gBAAA,GAAAA,gBAAA","ignoreList":[]}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.scrollAndFocus = void 0;
5
+ const MINIMIZED_HEADER_HEIGHT = 67;
6
+ const EXTRA_SPACE = 48; // Defined by UX
7
+
8
+ const scrollAndFocus = (scrollableRef, containerRef, focusedItemRef) => {
9
+ if (containerRef && focusedItemRef && scrollableRef) {
10
+ focusedItemRef.focus({
11
+ preventScroll: true
12
+ });
13
+ const scrollableRefTop = getTop(scrollableRef);
14
+ const containerRefTop = getTop(containerRef);
15
+ const top = containerRefTop - scrollableRefTop - MINIMIZED_HEADER_HEIGHT - EXTRA_SPACE;
16
+ const isFullHeaderDisplayed = scrollableRef.scrollTop < 40;
17
+ const avoidScrollingToKeepFullHeader = isFullHeaderDisplayed && top < 200;
18
+ if (!avoidScrollingToKeepFullHeader) {
19
+ setTimeout(() => {
20
+ scrollableRef.scrollBy({
21
+ top,
22
+ behavior: 'smooth'
23
+ });
24
+ }, 500);
25
+ }
26
+ }
27
+ };
28
+ exports.scrollAndFocus = scrollAndFocus;
29
+ const getTop = ref => ref && ref.getBoundingClientRect ? ref.getBoundingClientRect().top : 0;
30
+ //# sourceMappingURL=scrollAndFocus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["MINIMIZED_HEADER_HEIGHT","EXTRA_SPACE","scrollAndFocus","scrollableRef","containerRef","focusedItemRef","focus","preventScroll","scrollableRefTop","getTop","containerRefTop","top","isFullHeaderDisplayed","scrollTop","avoidScrollingToKeepFullHeader","setTimeout","scrollBy","behavior","exports","ref","getBoundingClientRect"],"sources":["../../../src/FocusableWrapper/scrollAndFocus.ts"],"sourcesContent":["const MINIMIZED_HEADER_HEIGHT = 67;\nconst EXTRA_SPACE = 48; // Defined by UX\n\nexport const scrollAndFocus = (\n scrollableRef: HTMLElement | undefined | null,\n containerRef: HTMLElement,\n focusedItemRef: HTMLElement,\n): void => {\n if (containerRef && focusedItemRef && scrollableRef) {\n focusedItemRef.focus({ preventScroll: true });\n const scrollableRefTop = getTop(scrollableRef);\n const containerRefTop = getTop(containerRef);\n const top =\n containerRefTop -\n scrollableRefTop -\n MINIMIZED_HEADER_HEIGHT -\n EXTRA_SPACE;\n\n const isFullHeaderDisplayed = scrollableRef.scrollTop < 40;\n const avoidScrollingToKeepFullHeader = isFullHeaderDisplayed && top < 200;\n\n if (!avoidScrollingToKeepFullHeader) {\n setTimeout(() => {\n scrollableRef.scrollBy({\n top,\n behavior: 'smooth',\n });\n }, 500);\n }\n }\n};\n\nconst getTop = (ref: HTMLElement): number =>\n ref && ref.getBoundingClientRect ? ref.getBoundingClientRect().top : 0;\n"],"mappings":";;;;AAAA,MAAMA,uBAAuB,GAAG,EAAE;AAClC,MAAMC,WAAW,GAAG,EAAE,CAAC,CAAC;;AAEjB,MAAMC,cAAc,GAAGA,CAC5BC,aAA6C,EAC7CC,YAAyB,EACzBC,cAA2B,KAClB;EACT,IAAID,YAAY,IAAIC,cAAc,IAAIF,aAAa,EAAE;IACnDE,cAAc,CAACC,KAAK,CAAC;MAAEC,aAAa,EAAE;IAAK,CAAC,CAAC;IAC7C,MAAMC,gBAAgB,GAAGC,MAAM,CAACN,aAAa,CAAC;IAC9C,MAAMO,eAAe,GAAGD,MAAM,CAACL,YAAY,CAAC;IAC5C,MAAMO,GAAG,GACPD,eAAe,GACfF,gBAAgB,GAChBR,uBAAuB,GACvBC,WAAW;IAEb,MAAMW,qBAAqB,GAAGT,aAAa,CAACU,SAAS,GAAG,EAAE;IAC1D,MAAMC,8BAA8B,GAAGF,qBAAqB,IAAID,GAAG,GAAG,GAAG;IAEzE,IAAI,CAACG,8BAA8B,EAAE;MACnCC,UAAU,CAAC,MAAM;QACfZ,aAAa,CAACa,QAAQ,CAAC;UACrBL,GAAG;UACHM,QAAQ,EAAE;QACZ,CAAC,CAAC;MACJ,CAAC,EAAE,GAAG,CAAC;IACT;EACF;AACF,CAAC;AAACC,OAAA,CAAAhB,cAAA,GAAAA,cAAA;AAEF,MAAMO,MAAM,GAAIU,GAAgB,IAC9BA,GAAG,IAAIA,GAAG,CAACC,qBAAqB,GAAGD,GAAG,CAACC,qBAAqB,CAAC,CAAC,CAACT,GAAG,GAAG,CAAC","ignoreList":[]}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ exports.__esModule = true;
5
+ exports.withFocusable = withFocusable;
6
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _FocusableWrapper = require("./FocusableWrapper");
9
+ var _jsxFileName = "/home/builduser/work/db7ea24852bc3350/packages/utils/dist/cjs/FocusableWrapper/withFocusable.tsx";
10
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
+ function withFocusable(WrappedComponent) {
13
+ return props => {
14
+ const context = (0, _react.useContext)(_FocusableWrapper.FocusableContext);
15
+ const registerScrollableItem = (0, _react.useCallback)(args => {
16
+ var _context$focusable;
17
+ context == null || (_context$focusable = context.focusable) == null || _context$focusable.registerScrollableItem == null || _context$focusable.registerScrollableItem(args);
18
+ }, [context]);
19
+ const addedProps = {
20
+ registerScrollableItem
21
+ };
22
+ return /*#__PURE__*/_react.default.createElement(WrappedComponent, (0, _extends2.default)({}, props, addedProps, {
23
+ __self: this,
24
+ __source: {
25
+ fileName: _jsxFileName,
26
+ lineNumber: 23,
27
+ columnNumber: 12
28
+ }
29
+ }));
30
+ };
31
+ }
32
+ //# sourceMappingURL=withFocusable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_FocusableWrapper","_jsxFileName","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","withFocusable","WrappedComponent","props","context","useContext","FocusableContext","registerScrollableItem","useCallback","args","_context$focusable","focusable","addedProps","createElement","_extends2","__self","__source","fileName","lineNumber","columnNumber"],"sources":["../../../src/FocusableWrapper/withFocusable.tsx"],"sourcesContent":["import React, { useCallback, useContext } from 'react';\nimport { ContextProps, FocusableContext } from './FocusableWrapper';\n\nexport type FocusableProps = ContextProps['focusable'];\n\nexport function withFocusable<P extends FocusableProps>(\n WrappedComponent: React.ComponentType<P>,\n): React.FC<Omit<P, keyof FocusableProps>> {\n return (props) => {\n const context = useContext(FocusableContext);\n\n const registerScrollableItem = useCallback(\n (args) => {\n context?.focusable?.registerScrollableItem?.(args);\n },\n [context],\n );\n\n const addedProps = {\n registerScrollableItem,\n };\n\n return <WrappedComponent {...(props as P)} {...addedProps} />;\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AAAoE,IAAAE,YAAA;AAAA,SAAAC,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAL,wBAAAK,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,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key) {
19
19
  if (key in exports && exports[key] === _reactiveContext[key]) return;
20
20
  exports[key] = _reactiveContext[key];
21
21
  });
22
+ var _FocusableWrapper = require("./FocusableWrapper/FocusableWrapper");
23
+ Object.keys(_FocusableWrapper).forEach(function (key) {
24
+ if (key === "default" || key === "__esModule") return;
25
+ if (key in exports && exports[key] === _FocusableWrapper[key]) return;
26
+ exports[key] = _FocusableWrapper[key];
27
+ });
28
+ var _withFocusable = require("./FocusableWrapper/withFocusable");
29
+ Object.keys(_withFocusable).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _withFocusable[key]) return;
32
+ exports[key] = _withFocusable[key];
33
+ });
22
34
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_reactive","require","Object","keys","forEach","key","exports","_PromiseState","_reactiveContext"],"sources":["../../src/index.ts"],"sourcesContent":["export * from './reactive';\nexport * from './PromiseState';\nexport * from './reactiveContext';\n"],"mappings":";;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,SAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,SAAA,CAAAK,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAL,SAAA,CAAAK,GAAA;AAAA;AACA,IAAAE,aAAA,GAAAN,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAI,aAAA,EAAAH,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAE,aAAA,CAAAF,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAE,aAAA,CAAAF,GAAA;AAAA;AACA,IAAAG,gBAAA,GAAAP,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAK,gBAAA,EAAAJ,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAG,gBAAA,CAAAH,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAG,gBAAA,CAAAH,GAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"names":["_reactive","require","Object","keys","forEach","key","exports","_PromiseState","_reactiveContext","_FocusableWrapper","_withFocusable"],"sources":["../../src/index.ts"],"sourcesContent":["export * from './reactive';\nexport * from './PromiseState';\nexport * from './reactiveContext';\nexport * from './FocusableWrapper/FocusableWrapper';\nexport * from './FocusableWrapper/withFocusable';\n"],"mappings":";;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,SAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,SAAA,CAAAK,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAL,SAAA,CAAAK,GAAA;AAAA;AACA,IAAAE,aAAA,GAAAN,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAI,aAAA,EAAAH,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAE,aAAA,CAAAF,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAE,aAAA,CAAAF,GAAA;AAAA;AACA,IAAAG,gBAAA,GAAAP,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAK,gBAAA,EAAAJ,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAG,gBAAA,CAAAH,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAG,gBAAA,CAAAH,GAAA;AAAA;AACA,IAAAI,iBAAA,GAAAR,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAM,iBAAA,EAAAL,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAI,iBAAA,CAAAJ,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAI,iBAAA,CAAAJ,GAAA;AAAA;AACA,IAAAK,cAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,cAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,cAAA,CAAAL,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAK,cAAA,CAAAL,GAAA;AAAA","ignoreList":[]}
@@ -0,0 +1,26 @@
1
+ export class FocusableItemsService {
2
+ constructor() {
3
+ this.getItemRef = (itemName) => this.focusableItems[itemName] && this.focusableItems[itemName].ref;
4
+ this.getContainerRefByItem = (itemName) => {
5
+ const containerName = this.focusableItems[itemName]?.containerName;
6
+ const container = this.scrollableContainers[containerName];
7
+ return container?.ref;
8
+ };
9
+ this.getContainerRefByName = (containerName) => {
10
+ const container = this.scrollableContainers[containerName];
11
+ return container?.ref;
12
+ };
13
+ this.focusableItems = {};
14
+ this.scrollableContainers = {};
15
+ }
16
+ addItem({ ref, itemName, containerName }) {
17
+ this.focusableItems[itemName] = { itemName, ref, containerName };
18
+ }
19
+ addContainer({ containerName, ref }) {
20
+ this.scrollableContainers[containerName] = {
21
+ containerName,
22
+ ref,
23
+ };
24
+ }
25
+ }
26
+ //# sourceMappingURL=FocusableService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FocusableService.js","sourceRoot":"","sources":["../../../src/FocusableWrapper/FocusableService.ts"],"names":[],"mappings":"AAWA,MAAM,OAAO,qBAAqB;IAWhC;QAgBA,eAAU,GAAG,CAAC,QAAgB,EAAE,EAAE,CAChC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC;QACrE,0BAAqB,GAAG,CAAC,QAAgB,EAAE,EAAE;YAC3C,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAC;YACnE,MAAM,SAAS,GAAG,IAAI,CAAC,oBAAoB,CAAC,aAAa,CAAC,CAAC;YAC3D,OAAO,SAAS,EAAE,GAAG,CAAC;QACxB,CAAC,CAAC;QACF,0BAAqB,GAAG,CAAC,aAAqB,EAAE,EAAE;YAChD,MAAM,SAAS,GAAG,IAAI,CAAC,oBAAoB,CAAC,aAAa,CAAC,CAAC;YAC3D,OAAO,SAAS,EAAE,GAAG,CAAC;QACxB,CAAC,CAAC;QAzBA,IAAI,CAAC,cAAc,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,oBAAoB,GAAG,EAAE,CAAC;IACjC,CAAC;IAED,OAAO,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,aAAa,EAAiB;QACrD,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC;IACnE,CAAC;IAED,YAAY,CAAC,EAAE,aAAa,EAAE,GAAG,EAAuB;QACtD,IAAI,CAAC,oBAAoB,CAAC,aAAa,CAAC,GAAG;YACzC,aAAa;YACb,GAAG;SACJ,CAAC;IACJ,CAAC;CAaF"}
@@ -0,0 +1,50 @@
1
+ import React, { useCallback, useEffect, useMemo } from 'react';
2
+ import { FocusableItemsService } from './FocusableService';
3
+ import { scrollAndFocus } from './scrollAndFocus';
4
+ export const getAnchorParam = () => {
5
+ const searchParams = new URLSearchParams(window.location.search);
6
+ return searchParams.get('anchor');
7
+ };
8
+ export const FocusableContext = React.createContext(null);
9
+ export const FocusableWrapper = ({ scrollableRef, getScrollableTrigger, getDoesItemExist, children, }) => {
10
+ const focusableItemsService = useMemo(() => new FocusableItemsService(), []);
11
+ const scrollIfNeeded = useCallback(() => {
12
+ const focusedItemName = getAnchorParam();
13
+ scrollByItemName(focusedItemName);
14
+ }, [scrollableRef]);
15
+ const scrollByItemName = useCallback((focusedItemName) => {
16
+ if (!focusedItemName) {
17
+ return;
18
+ }
19
+ const containerRefByItem = focusableItemsService.getContainerRefByItem(focusedItemName);
20
+ if (containerRefByItem) {
21
+ const focusedItem = focusableItemsService.getItemRef(focusedItemName);
22
+ return scrollAndFocus(scrollableRef, containerRefByItem, focusedItem);
23
+ }
24
+ const containerRef = focusableItemsService.getContainerRefByName(focusedItemName);
25
+ if (containerRef) {
26
+ scrollAndFocus(scrollableRef, containerRef, containerRef);
27
+ }
28
+ }, [focusableItemsService, scrollableRef]);
29
+ const doesItemExist = useCallback(() => {
30
+ const focusedItemName = getAnchorParam();
31
+ if (!focusedItemName) {
32
+ return false;
33
+ }
34
+ return Boolean(focusableItemsService.getContainerRefByItem(focusedItemName));
35
+ }, [focusableItemsService]);
36
+ useEffect(() => {
37
+ getScrollableTrigger(scrollIfNeeded);
38
+ getDoesItemExist(doesItemExist);
39
+ }, [getScrollableTrigger, getDoesItemExist, scrollIfNeeded, doesItemExist]);
40
+ const contextValue = useMemo(() => ({
41
+ focusable: {
42
+ registerScrollableItem: (scrollableItem) => {
43
+ focusableItemsService.addContainer(scrollableItem);
44
+ focusableItemsService.addItem(scrollableItem);
45
+ },
46
+ },
47
+ }), [focusableItemsService]);
48
+ return (React.createElement(FocusableContext.Provider, { value: contextValue }, children));
49
+ };
50
+ //# sourceMappingURL=FocusableWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FocusableWrapper.js","sourceRoot":"","sources":["../../../src/FocusableWrapper/FocusableWrapper.tsx"],"names":[],"mappings":"AAAA,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Ref) => {
4
+ if (containerRef && focusedItemRef && scrollableRef) {
5
+ focusedItemRef.focus({ preventScroll: true });
6
+ const scrollableRefTop = getTop(scrollableRef);
7
+ const containerRefTop = getTop(containerRef);
8
+ const top = containerRefTop -
9
+ scrollableRefTop -
10
+ MINIMIZED_HEADER_HEIGHT -
11
+ EXTRA_SPACE;
12
+ const isFullHeaderDisplayed = scrollableRef.scrollTop < 40;
13
+ const avoidScrollingToKeepFullHeader = isFullHeaderDisplayed && top < 200;
14
+ if (!avoidScrollingToKeepFullHeader) {
15
+ setTimeout(() => {
16
+ scrollableRef.scrollBy({
17
+ top,
18
+ behavior: 'smooth',
19
+ });
20
+ }, 500);
21
+ }
22
+ }
23
+ };
24
+ const getTop = (ref) => ref && ref.getBoundingClientRect ? ref.getBoundingClientRect().top : 0;
25
+ //# sourceMappingURL=scrollAndFocus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scrollAndFocus.js","sourceRoot":"","sources":["../../../src/FocusableWrapper/scrollAndFocus.ts"],"names":[],"mappings":"AAAA,MAAM,uBAAuB,GAAG,EAAE,CAAC;AACnC,MAAM,WAAW,GAAG,EAAE,CAAC,CAAC,gBAAgB;AAExC,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,aAA6C,EAC7C,YAAyB,EACzB,cAA2B,EACrB,EAAE;IACR,IAAI,YAAY,IAAI,cAAc,IAAI,aAAa,EAAE;QACnD,cAAc,CAAC,KAAK,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9C,MAAM,gBAAgB,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;QAC/C,MAAM,eAAe,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;QAC7C,MAAM,GAAG,GACP,eAAe;YACf,gBAAgB;YAChB,uBAAuB;YACvB,WAAW,CAAC;QAEd,MAAM,qBAAqB,GAAG,aAAa,CAAC,SAAS,GAAG,EAAE,CAAC;QAC3D,MAAM,8BAA8B,GAAG,qBAAqB,IAAI,GAAG,GAAG,GAAG,CAAC;QAE1E,IAAI,CAAC,8BAA8B,EAAE;YACnC,UAAU,CAAC,GAAG,EAAE;gBACd,aAAa,CAAC,QAAQ,CAAC;oBACrB,GAAG;oBACH,QAAQ,EAAE,QAAQ;iBACnB,CAAC,CAAC;YACL,CAAC,EAAE,GAAG,CAAC,CAAC;SACT;KACF;AACH,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,CAAC,GAAgB,EAAU,EAAE,CAC1C,GAAG,IAAI,GAAG,CAAC,qBAAqB,CAAC,CAAC,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import React, { useCallback, useContext } from 'react';
2
+ import { FocusableContext } from './FocusableWrapper';
3
+ export function withFocusable(WrappedComponent) {
4
+ return (props) => {
5
+ const context = useContext(FocusableContext);
6
+ const registerScrollableItem = useCallback((args) => {
7
+ context?.focusable?.registerScrollableItem?.(args);
8
+ }, [context]);
9
+ const addedProps = {
10
+ registerScrollableItem,
11
+ };
12
+ return React.createElement(WrappedComponent, { ...props, ...addedProps });
13
+ };
14
+ }
15
+ //# sourceMappingURL=withFocusable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withFocusable.js","sourceRoot":"","sources":["../../../src/FocusableWrapper/withFocusable.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAAgB,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAIpE,MAAM,UAAU,aAAa,CAC3B,gBAAwC;IAExC,OAAO,CAAC,KAAK,EAAE,EAAE;QACf,MAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;QAE7C,MAAM,sBAAsB,GAAG,WAAW,CACxC,CAAC,IAAI,EAAE,EAAE;YACP,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,CAAC,IAAI,CAAC,CAAC;QACrD,CAAC,EACD,CAAC,OAAO,CAAC,CACV,CAAC;QAEF,MAAM,UAAU,GAAG;YACjB,sBAAsB;SACvB,CAAC;QAEF,OAAO,oBAAC,gBAAgB,OAAM,KAAW,KAAM,UAAU,GAAI,CAAC;IAChE,CAAC,CAAC;AACJ,CAAC"}
package/dist/esm/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from './reactive';
2
2
  export * from './PromiseState';
3
3
  export * from './reactiveContext';
4
+ export * from './FocusableWrapper/FocusableWrapper';
5
+ export * from './FocusableWrapper/withFocusable';
4
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qCAAqC,CAAC;AACpD,cAAc,kCAAkC,CAAC"}
@@ -0,0 +1,20 @@
1
+ export type FocusableItem = {
2
+ containerName: string;
3
+ ref: HTMLElement;
4
+ itemName: string;
5
+ };
6
+ export type ScrollableContainer = {
7
+ containerName: string;
8
+ ref: HTMLElement;
9
+ };
10
+ export declare class FocusableItemsService {
11
+ private focusableItems;
12
+ private scrollableContainers;
13
+ constructor();
14
+ addItem({ ref, itemName, containerName }: FocusableItem): void;
15
+ addContainer({ containerName, ref }: ScrollableContainer): void;
16
+ getItemRef: (itemName: string) => HTMLElement;
17
+ getContainerRefByItem: (itemName: string) => HTMLElement;
18
+ getContainerRefByName: (containerName: string) => HTMLElement;
19
+ }
20
+ //# sourceMappingURL=FocusableService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FocusableService.d.ts","sourceRoot":"","sources":["../../../src/FocusableWrapper/FocusableService.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,WAAW,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,aAAa,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,WAAW,CAAC;CAClB,CAAC;AAEF,qBAAa,qBAAqB;IAChC,OAAO,CAAC,cAAc,CAEpB;IACF,OAAO,CAAC,oBAAoB,CAK1B;;IAOF,OAAO,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,aAAa,EAAE,EAAE,aAAa;IAIvD,YAAY,CAAC,EAAE,aAAa,EAAE,GAAG,EAAE,EAAE,mBAAmB;IAOxD,UAAU,aAAc,MAAM,iBACuC;IACrE,qBAAqB,aAAc,MAAM,iBAIvC;IACF,qBAAqB,kBAAmB,MAAM,iBAG5C;CACH"}
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { FocusableItem } from './FocusableService';
3
+ export declare const getAnchorParam: () => string | null;
4
+ export type ContextProps = {
5
+ focusable: {
6
+ registerScrollableItem: (scrollableItem: FocusableItem) => void;
7
+ };
8
+ };
9
+ export declare const FocusableContext: React.Context<ContextProps | null>;
10
+ type FocusableWrapperProps = {
11
+ scrollableRef?: HTMLElement | null;
12
+ getScrollableTrigger: (callback: () => void) => void;
13
+ getDoesItemExist: (callback: () => boolean) => void;
14
+ };
15
+ export declare const FocusableWrapper: React.FC<FocusableWrapperProps>;
16
+ export {};
17
+ //# sourceMappingURL=FocusableWrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FocusableWrapper.d.ts","sourceRoot":"","sources":["../../../src/FocusableWrapper/FocusableWrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA0C,MAAM,OAAO,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAyB,MAAM,oBAAoB,CAAC;AAG1E,eAAO,MAAM,cAAc,QAAO,MAAM,GAAG,IAG1C,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,SAAS,EAAE;QACT,sBAAsB,EAAE,CAAC,cAAc,EAAE,aAAa,KAAK,IAAI,CAAC;KACjE,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,gBAAgB,oCAAiD,CAAC;AAE/E,KAAK,qBAAqB,GAAG;IAC3B,aAAa,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IACnC,oBAAoB,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;IACrD,gBAAgB,EAAE,CAAC,QAAQ,EAAE,MAAM,OAAO,KAAK,IAAI,CAAC;CACrD,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAoE5D,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const scrollAndFocus: (scrollableRef: HTMLElement | undefined | null, containerRef: HTMLElement, focusedItemRef: HTMLElement) => void;
2
+ //# sourceMappingURL=scrollAndFocus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scrollAndFocus.d.ts","sourceRoot":"","sources":["../../../src/FocusableWrapper/scrollAndFocus.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,kBACV,WAAW,GAAG,SAAS,GAAG,IAAI,gBAC/B,WAAW,kBACT,WAAW,KAC1B,IAuBF,CAAC"}
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { ContextProps } from './FocusableWrapper';
3
+ export type FocusableProps = ContextProps['focusable'];
4
+ export declare function withFocusable<P extends FocusableProps>(WrappedComponent: React.ComponentType<P>): React.FC<Omit<P, keyof FocusableProps>>;
5
+ //# sourceMappingURL=withFocusable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withFocusable.d.ts","sourceRoot":"","sources":["../../../src/FocusableWrapper/withFocusable.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkC,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,YAAY,EAAoB,MAAM,oBAAoB,CAAC;AAEpE,MAAM,MAAM,cAAc,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;AAEvD,wBAAgB,aAAa,CAAC,CAAC,SAAS,cAAc,EACpD,gBAAgB,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,GACvC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,cAAc,CAAC,CAAC,CAiBzC"}
@@ -1,4 +1,6 @@
1
1
  export * from './reactive';
2
2
  export * from './PromiseState';
3
3
  export * from './reactiveContext';
4
+ export * from './FocusableWrapper/FocusableWrapper';
5
+ export * from './FocusableWrapper/withFocusable';
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,qCAAqC,CAAC;AACpD,cAAc,kCAAkC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/bex-utils",
3
- "version": "2.20.0",
3
+ "version": "2.21.0",
4
4
  "license": "UNLICENSED",
5
5
  "author": {
6
6
  "name": "Kobi",
@@ -149,5 +149,5 @@
149
149
  "wallaby": {
150
150
  "autoDetect": true
151
151
  },
152
- "falconPackageHash": "9c7505c95ff1814a600a4c6617d3d0faae86f1acde57a6452a0be272"
152
+ "falconPackageHash": "40d8c0583caa143abfdd162aab06ecbcb5b706029f83480663917ef5"
153
153
  }