@bsky.app/sift 0.2.7 → 0.2.8
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/CHANGELOG.md +6 -0
- package/build/computeStyles.d.ts +4 -0
- package/build/computeStyles.d.ts.map +1 -1
- package/build/computeStyles.js +9 -0
- package/build/computeStyles.js.map +1 -1
- package/build/computeStyles.web.d.ts +4 -0
- package/build/computeStyles.web.d.ts.map +1 -1
- package/build/computeStyles.web.js +7 -0
- package/build/computeStyles.web.js.map +1 -1
- package/build/useSift.d.ts +5 -1
- package/build/useSift.d.ts.map +1 -1
- package/build/useSift.js +3 -1
- package/build/useSift.js.map +1 -1
- package/package.json +1 -1
- package/src/computeStyles.ts +11 -0
- package/src/computeStyles.web.ts +9 -0
- package/src/useSift.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @bsky.app/sift
|
|
2
2
|
|
|
3
|
+
## 0.2.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`ff2c77b`](https://github.com/bluesky-social/toolbox/commit/ff2c77b752cc3e312f06f8d440cb3a46d7483715) Thanks [@estrattonbailey](https://github.com/estrattonbailey)! - Support `insets` on `useSift`
|
|
8
|
+
|
|
3
9
|
## 0.2.7
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/build/computeStyles.d.ts
CHANGED
|
@@ -8,5 +8,9 @@ export declare function computeStyles({ anchor, input, popover, }: {
|
|
|
8
8
|
offset: number;
|
|
9
9
|
placement: Placement;
|
|
10
10
|
dynamicWidth?: boolean;
|
|
11
|
+
insets?: {
|
|
12
|
+
top: number;
|
|
13
|
+
bottom: number;
|
|
14
|
+
};
|
|
11
15
|
}): Promise<ViewStyle | null>;
|
|
12
16
|
//# sourceMappingURL=computeStyles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computeStyles.d.ts","sourceRoot":"","sources":["../src/computeStyles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,SAAS,EAAC,MAAM,cAAc,CAAA;AACvD,OAAO,EAAC,KAAK,SAAS,EAAC,MAAM,WAAW,CAAA;AAcxC,wBAAsB,aAAa,CACjC,EACE,MAAM,EACN,KAAK,EACL,OAAO,GACR,EAAE;IACD,MAAM,EAAE,GAAG,CAAA;IACX,KAAK,EAAE,GAAG,CAAA;IACV,OAAO,EAAE,GAAG,GAAG,IAAI,CAAA;CACpB,EACD,OAAO,EAAE;IACP,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,SAAS,CAAA;IACpB,YAAY,CAAC,EAAE,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"computeStyles.d.ts","sourceRoot":"","sources":["../src/computeStyles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,SAAS,EAAC,MAAM,cAAc,CAAA;AACvD,OAAO,EAAC,KAAK,SAAS,EAAC,MAAM,WAAW,CAAA;AAcxC,wBAAsB,aAAa,CACjC,EACE,MAAM,EACN,KAAK,EACL,OAAO,GACR,EAAE;IACD,MAAM,EAAE,GAAG,CAAA;IACX,KAAK,EAAE,GAAG,CAAA;IACV,OAAO,EAAE,GAAG,GAAG,IAAI,CAAA;CACpB,EACD,OAAO,EAAE;IACP,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,SAAS,CAAA;IACpB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,MAAM,CAAC,EAAE;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,CAAA;CACvC,GACA,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAwD3B"}
|
package/build/computeStyles.js
CHANGED
|
@@ -18,13 +18,21 @@ export async function computeStyles({ anchor, input, popover, }, options) {
|
|
|
18
18
|
return null;
|
|
19
19
|
const popoverWidth = popoverRect?.width ?? 0;
|
|
20
20
|
const [side, align] = options.placement.split('-');
|
|
21
|
+
const insetTop = options.insets?.top ?? 0;
|
|
22
|
+
const insetBottom = options.insets?.bottom ?? 0;
|
|
21
23
|
let top = 'auto';
|
|
22
24
|
let bottom = 'auto';
|
|
25
|
+
let maxHeight;
|
|
23
26
|
if (side === 'top') {
|
|
24
27
|
bottom = Dimensions.get('window').height - anchorRect.y + options.offset;
|
|
28
|
+
maxHeight = anchorRect.y - options.offset - insetTop;
|
|
25
29
|
}
|
|
26
30
|
else {
|
|
27
31
|
top = anchorRect.y + anchorRect.height + options.offset;
|
|
32
|
+
maxHeight =
|
|
33
|
+
Dimensions.get('window').height -
|
|
34
|
+
insetBottom -
|
|
35
|
+
(anchorRect.y + anchorRect.height + options.offset);
|
|
28
36
|
}
|
|
29
37
|
let left;
|
|
30
38
|
if (align === 'start') {
|
|
@@ -47,6 +55,7 @@ export async function computeStyles({ anchor, input, popover, }, options) {
|
|
|
47
55
|
bottom,
|
|
48
56
|
left,
|
|
49
57
|
maxWidth,
|
|
58
|
+
maxHeight,
|
|
50
59
|
};
|
|
51
60
|
}
|
|
52
61
|
//# sourceMappingURL=computeStyles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computeStyles.js","sourceRoot":"","sources":["../src/computeStyles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAiB,MAAM,cAAc,CAAA;AAGvD,SAAS,eAAe,CACtB,IAAS;IAET,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QAC3B,IAAI,CAAC,eAAe,CAClB,CAAC,CAAS,EAAE,CAAS,EAAE,KAAa,EAAE,MAAc,EAAE,EAAE;YACtD,OAAO,CAAC,EAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAC,CAAC,CAAA;QAChC,CAAC,CACF,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,EACE,MAAM,EACN,KAAK,EACL,OAAO,GAKR,EACD,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KAAK,CAAA;IAC7B,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,UAAU;QACpB,GAAG;QACH,MAAM;QACN,IAAI;QACJ,QAAQ;QACR,SAAS;KACV,CAAA;AACH,CAAC","sourcesContent":["import {Dimensions, type ViewStyle} from 'react-native'\nimport {type Placement} from './useSift'\n\nfunction measureInWindow(\n node: any,\n): Promise<{x: number; y: number; width: number; height: number}> {\n return new Promise(resolve => {\n node.measureInWindow(\n (x: number, y: number, width: number, height: number) => {\n resolve({x, y, width, height})\n },\n )\n })\n}\n\nexport async function computeStyles(\n {\n anchor,\n input,\n popover,\n }: {\n anchor: any\n input: any\n popover: any | null\n },\n options: {\n offset: number\n placement: Placement\n dynamicWidth?: boolean\n insets?: {top: number; bottom: number}\n },\n): Promise<ViewStyle | null> {\n const anchorRect = await measureInWindow(anchor)\n const inputRect = await measureInWindow(input)\n const popoverRect = popover ? await measureInWindow(popover) : null\n\n // If any measurement failed (view not in hierarchy yet), return null\n // so the caller keeps the previous styles.\n if (!anchorRect.width || !inputRect.width) return null\n if (popoverRect && !popoverRect.width && !popoverRect.height) return null\n\n const popoverWidth = popoverRect?.width ?? 0\n const [side, align] = options.placement.split('-') as [\n string,\n string | undefined,\n ]\n\n const insetTop = options.insets?.top ?? 0\n const insetBottom = options.insets?.bottom ?? 0\n\n let top: number | 'auto' = 'auto'\n let bottom: number | 'auto' = 'auto'\n let maxHeight: number | undefined\n if (side === 'top') {\n bottom = Dimensions.get('window').height - anchorRect.y + options.offset\n maxHeight = anchorRect.y - options.offset - insetTop\n } else {\n top = anchorRect.y + anchorRect.height + options.offset\n maxHeight =\n Dimensions.get('window').height -\n insetBottom -\n (anchorRect.y + anchorRect.height + options.offset)\n }\n\n let left: number\n if (align === 'start') {\n left = anchorRect.x\n } else if (align === 'end') {\n left = anchorRect.x + anchorRect.width - popoverWidth\n } else {\n left = anchorRect.x + (anchorRect.width - popoverWidth) / 2\n }\n\n let maxWidth: number | undefined\n if (options.dynamicWidth === false) {\n left = anchorRect.x\n maxWidth = anchorRect.width\n }\n\n return {\n position: 'absolute',\n top,\n bottom,\n left,\n maxWidth,\n maxHeight,\n }\n}\n"]}
|
|
@@ -8,5 +8,9 @@ export declare function computeStyles({ anchor, input, popover, }: {
|
|
|
8
8
|
offset: number;
|
|
9
9
|
placement: Placement;
|
|
10
10
|
dynamicWidth?: boolean;
|
|
11
|
+
insets?: {
|
|
12
|
+
top: number;
|
|
13
|
+
bottom: number;
|
|
14
|
+
};
|
|
11
15
|
}): ViewStyle | null;
|
|
12
16
|
//# sourceMappingURL=computeStyles.web.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computeStyles.web.d.ts","sourceRoot":"","sources":["../src/computeStyles.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,SAAS,EAAC,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAC,KAAK,SAAS,EAAC,MAAM,WAAW,CAAA;AAExC,wBAAgB,aAAa,CAC3B,EACE,MAAM,EACN,KAAK,EACL,OAAO,GACR,EAAE;IACD,MAAM,EAAE,WAAW,CAAA;IACnB,KAAK,EAAE,WAAW,CAAA;IAClB,OAAO,EAAE,WAAW,GAAG,IAAI,CAAA;CAC5B,EACD,OAAO,EAAE;IACP,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,SAAS,CAAA;IACpB,YAAY,CAAC,EAAE,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"computeStyles.web.d.ts","sourceRoot":"","sources":["../src/computeStyles.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,SAAS,EAAC,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAC,KAAK,SAAS,EAAC,MAAM,WAAW,CAAA;AAExC,wBAAgB,aAAa,CAC3B,EACE,MAAM,EACN,KAAK,EACL,OAAO,GACR,EAAE;IACD,MAAM,EAAE,WAAW,CAAA;IACnB,KAAK,EAAE,WAAW,CAAA;IAClB,OAAO,EAAE,WAAW,GAAG,IAAI,CAAA;CAC5B,EACD,OAAO,EAAE;IACP,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,SAAS,CAAA;IACpB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,MAAM,CAAC,EAAE;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,CAAA;CACvC,GACA,SAAS,GAAG,IAAI,CAwDlB"}
|
|
@@ -10,13 +10,19 @@ export function computeStyles({ anchor, input, popover, }, options) {
|
|
|
10
10
|
return null;
|
|
11
11
|
const popoverWidth = popoverRect?.width ?? 0;
|
|
12
12
|
const [side, align] = options.placement.split('-');
|
|
13
|
+
const insetTop = options.insets?.top ?? 0;
|
|
14
|
+
const insetBottom = options.insets?.bottom ?? 0;
|
|
13
15
|
let top = 'auto';
|
|
14
16
|
let bottom = 'auto';
|
|
17
|
+
let maxHeight;
|
|
15
18
|
if (side === 'top') {
|
|
16
19
|
bottom = window.innerHeight - anchorRect.top + options.offset;
|
|
20
|
+
maxHeight = anchorRect.top - options.offset - insetTop;
|
|
17
21
|
}
|
|
18
22
|
else {
|
|
19
23
|
top = anchorRect.bottom + options.offset + window.scrollY;
|
|
24
|
+
maxHeight =
|
|
25
|
+
window.innerHeight - insetBottom - anchorRect.bottom - options.offset;
|
|
20
26
|
}
|
|
21
27
|
let left;
|
|
22
28
|
if (align === 'start') {
|
|
@@ -41,6 +47,7 @@ export function computeStyles({ anchor, input, popover, }, options) {
|
|
|
41
47
|
bottom,
|
|
42
48
|
left,
|
|
43
49
|
maxWidth,
|
|
50
|
+
maxHeight,
|
|
44
51
|
};
|
|
45
52
|
}
|
|
46
53
|
//# sourceMappingURL=computeStyles.web.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computeStyles.web.js","sourceRoot":"","sources":["../src/computeStyles.web.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,aAAa,CAC3B,EACE,MAAM,EACN,KAAK,EACL,OAAO,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G,UAAU,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAA;QACzD,SAAS;YACP,MAAM,CAAC,WAAW,GAAG,WAAW,GAAG,UAAU,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;IACzE,CAAC;IAED,IAAI,IAAY,CAAA;IAChB,IAAI,KAAK,KAAK,OAAO,EAAE,CAAC;QACtB,IAAI,GAAG,UAAU,CAAC,IAAI,CAAA;IACxB,CAAC;SAAM,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;QAC3B,IAAI,GAAG,UAAU,CAAC,KAAK,GAAG,YAAY,CAAA;IACxC,CAAC;SAAM,CAAC;QACN,IAAI,GAAG,UAAU,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,CAAA;IAChE,CAAC;IACD,IAAI,IAAI,MAAM,CAAC,OAAO,CAAA;IAEtB,IAAI,QAA4B,CAAA;IAChC,IAAI,OAAO,CAAC,YAAY,KAAK,KAAK,EAAE,CAAC;QACnC,IAAI,GAAG,UAAU,CAAC,IAAI,GAAG,MAAM,CAAC,OAAO,CAAA;QACvC,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAA;IAC7B,CAAC;IAED,OAAO;QACL,aAAa;QACb,QAAQ,EAAE,OAAO;QACjB,GAAG;QACH,MAAM;QACN,IAAI;QACJ,QAAQ;QACR,SAAS;KACV,CAAA;AACH,CAAC","sourcesContent":["import {type ViewStyle} from 'react-native'\nimport {type Placement} from './useSift'\n\nexport function computeStyles(\n {\n anchor,\n input,\n popover,\n }: {\n anchor: HTMLElement\n input: HTMLElement\n popover: HTMLElement | null\n },\n options: {\n offset: number\n placement: Placement\n dynamicWidth?: boolean\n insets?: {top: number; bottom: number}\n },\n): ViewStyle | null {\n const anchorRect = anchor.getBoundingClientRect()\n const inputRect = input.getBoundingClientRect()\n const popoverRect = popover?.getBoundingClientRect()\n\n // If any measurement failed (view not in hierarchy yet), return null\n // so the caller keeps the previous styles.\n if (!anchorRect.width || !inputRect.width) return null\n if (popoverRect && !popoverRect.width && !popoverRect.height) return null\n\n const popoverWidth = popoverRect?.width ?? 0\n const [side, align] = options.placement.split('-') as [\n string,\n string | undefined,\n ]\n\n const insetTop = options.insets?.top ?? 0\n const insetBottom = options.insets?.bottom ?? 0\n\n let top: number | 'auto' = 'auto'\n let bottom: number | 'auto' = 'auto'\n let maxHeight: number | undefined\n if (side === 'top') {\n bottom = window.innerHeight - anchorRect.top + options.offset\n maxHeight = anchorRect.top - options.offset - insetTop\n } else {\n top = anchorRect.bottom + options.offset + window.scrollY\n maxHeight =\n window.innerHeight - insetBottom - anchorRect.bottom - options.offset\n }\n\n let left: number\n if (align === 'start') {\n left = anchorRect.left\n } else if (align === 'end') {\n left = anchorRect.right - popoverWidth\n } else {\n left = anchorRect.left + (anchorRect.width - popoverWidth) / 2\n }\n left += window.scrollX\n\n let maxWidth: number | undefined\n if (options.dynamicWidth === false) {\n left = anchorRect.left + window.scrollX\n maxWidth = anchorRect.width\n }\n\n return {\n // @ts-ignore\n position: 'fixed',\n top,\n bottom,\n left,\n maxWidth,\n maxHeight,\n }\n}\n"]}
|
package/build/useSift.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { type ViewStyle } from 'react-native';
|
|
2
2
|
export type Placement = 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end';
|
|
3
3
|
export type UseSiftReturn = ReturnType<typeof useSift>;
|
|
4
|
-
export declare function useSift({ offset: offsetValue, placement, dynamicWidth, }?: {
|
|
4
|
+
export declare function useSift({ offset: offsetValue, placement, dynamicWidth, insets, }?: {
|
|
5
5
|
offset?: number;
|
|
6
6
|
placement?: Placement;
|
|
7
7
|
dynamicWidth?: boolean;
|
|
8
|
+
insets?: {
|
|
9
|
+
top: number;
|
|
10
|
+
bottom: number;
|
|
11
|
+
};
|
|
8
12
|
}): {
|
|
9
13
|
id: string;
|
|
10
14
|
refs: {
|
package/build/useSift.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSift.d.ts","sourceRoot":"","sources":["../src/useSift.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,SAAS,EAAC,MAAM,cAAc,CAAA;AAK3C,MAAM,MAAM,SAAS,GACjB,KAAK,GACL,WAAW,GACX,SAAS,GACT,QAAQ,GACR,cAAc,GACd,YAAY,CAAA;AAEhB,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,OAAO,CAAC,CAAA;AAEtD,wBAAgB,OAAO,CAAC,EACtB,MAAM,EAAE,WAAe,EACvB,SAAoB,EACpB,YAAoB,
|
|
1
|
+
{"version":3,"file":"useSift.d.ts","sourceRoot":"","sources":["../src/useSift.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,SAAS,EAAC,MAAM,cAAc,CAAA;AAK3C,MAAM,MAAM,SAAS,GACjB,KAAK,GACL,WAAW,GACX,SAAS,GACT,QAAQ,GACR,cAAc,GACd,YAAY,CAAA;AAEhB,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,OAAO,CAAC,CAAA;AAEtD,wBAAgB,OAAO,CAAC,EACtB,MAAM,EAAE,WAAe,EACvB,SAAoB,EACpB,YAAoB,EACpB,MAAM,GACP,GAAE;IACD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,MAAM,CAAC,EAAE;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,CAAA;CAClC;;;2BAmDK,GAAG;0BAaH,GAAG;;;;;;;;;;oBAnB8B,GAAG;;;;;;EAiD9C"}
|
package/build/useSift.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCallback, useId, useRef, useState } from 'react';
|
|
2
2
|
import { computeStyles } from './computeStyles';
|
|
3
3
|
const DEFAULT_POPOVER_STYLES = { position: 'absolute' };
|
|
4
|
-
export function useSift({ offset: offsetValue = 0, placement = 'bottom', dynamicWidth = false, } = {}) {
|
|
4
|
+
export function useSift({ offset: offsetValue = 0, placement = 'bottom', dynamicWidth = false, insets, } = {}) {
|
|
5
5
|
const id = useId();
|
|
6
6
|
/*
|
|
7
7
|
* These are reactive values and need to remain in state
|
|
@@ -20,11 +20,13 @@ export function useSift({ offset: offsetValue = 0, placement = 'bottom', dynamic
|
|
|
20
20
|
offset: offsetValue,
|
|
21
21
|
placement,
|
|
22
22
|
dynamicWidth,
|
|
23
|
+
insets,
|
|
23
24
|
});
|
|
24
25
|
options.current = {
|
|
25
26
|
offset: offsetValue,
|
|
26
27
|
placement,
|
|
27
28
|
dynamicWidth,
|
|
29
|
+
insets,
|
|
28
30
|
};
|
|
29
31
|
const update = useCallback(async () => {
|
|
30
32
|
if (!inputRef.current || !popoverRef.current)
|
package/build/useSift.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSift.js","sourceRoot":"","sources":["../src/useSift.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAA;AAE1D,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAA;AAE7C,MAAM,sBAAsB,GAAc,EAAC,QAAQ,EAAE,UAAU,EAAC,CAAA;AAYhE,MAAM,UAAU,OAAO,CAAC,EACtB,MAAM,EAAE,WAAW,GAAG,CAAC,EACvB,SAAS,GAAG,QAAQ,EACpB,YAAY,GAAG,KAAK,
|
|
1
|
+
{"version":3,"file":"useSift.js","sourceRoot":"","sources":["../src/useSift.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAA;AAE1D,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CA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State} from 'react'\nimport {type ViewStyle} from 'react-native'\nimport {computeStyles} from './computeStyles'\n\nconst DEFAULT_POPOVER_STYLES: ViewStyle = {position: 'absolute'}\n\nexport type Placement =\n | 'top'\n | 'top-start'\n | 'top-end'\n | 'bottom'\n | 'bottom-start'\n | 'bottom-end'\n\nexport type UseSiftReturn = ReturnType<typeof useSift>\n\nexport function useSift({\n offset: offsetValue = 0,\n placement = 'bottom',\n dynamicWidth = false,\n insets,\n}: {\n offset?: number\n placement?: Placement\n dynamicWidth?: boolean\n insets?: {top: number; bottom: number}\n} = {}) {\n const id = useId()\n\n /*\n * These are reactive values and need to remain in state\n */\n const [input, setInput] = useState<any>(null)\n const [popover, setPopover] = useState<any>(null)\n const [popoverStyles, setPopoverStyles] = useState<ViewStyle>(\n DEFAULT_POPOVER_STYLES,\n )\n\n /*\n * These are non-reactive values that we want to persist across renders\n * without causing re-renders when they change, so we store them in refs.\n */\n const inputRef = useRef<any>(null)\n const popoverRef = useRef<any>(null)\n const anchorRef = useRef<any>(null)\n const options = useRef({\n offset: offsetValue,\n placement,\n dynamicWidth,\n insets,\n })\n options.current = {\n offset: offsetValue,\n placement,\n dynamicWidth,\n insets,\n }\n\n const update = useCallback(async () => {\n if (!inputRef.current || !popoverRef.current) return\n const styles = await computeStyles(\n {\n anchor: anchorRef.current || inputRef.current,\n input: inputRef.current,\n popover: popoverRef.current,\n },\n options.current,\n )\n if (styles) setPopoverStyles(styles)\n }, [])\n\n const handleSetInput = useCallback((node: any) => {\n inputRef.current = node\n setInput(node)\n }, [])\n\n const handleSetPopover = useCallback(\n (node: any) => {\n popoverRef.current = node\n setPopover(node)\n if (node) {\n update()\n } else {\n setPopoverStyles(DEFAULT_POPOVER_STYLES)\n }\n },\n [update],\n )\n\n const handleSetAnchor = useCallback(\n (node: any) => {\n anchorRef.current = node\n if (node) update()\n },\n [update],\n )\n\n return {\n id,\n refs: {\n setPopover: handleSetPopover,\n setAnchor: handleSetAnchor,\n },\n elements: {\n input,\n popover,\n },\n isActive() {\n return !!popover\n },\n popoverStyles,\n updatePosition: update,\n targetProps: {\n ref: handleSetInput,\n role: 'combobox' as const,\n 'aria-controls': id,\n 'aria-expanded': !!popover,\n 'aria-autocomplete': 'list' as const,\n },\n }\n}\n"]}
|
package/package.json
CHANGED
package/src/computeStyles.ts
CHANGED
|
@@ -27,6 +27,7 @@ export async function computeStyles(
|
|
|
27
27
|
offset: number
|
|
28
28
|
placement: Placement
|
|
29
29
|
dynamicWidth?: boolean
|
|
30
|
+
insets?: {top: number; bottom: number}
|
|
30
31
|
},
|
|
31
32
|
): Promise<ViewStyle | null> {
|
|
32
33
|
const anchorRect = await measureInWindow(anchor)
|
|
@@ -44,12 +45,21 @@ export async function computeStyles(
|
|
|
44
45
|
string | undefined,
|
|
45
46
|
]
|
|
46
47
|
|
|
48
|
+
const insetTop = options.insets?.top ?? 0
|
|
49
|
+
const insetBottom = options.insets?.bottom ?? 0
|
|
50
|
+
|
|
47
51
|
let top: number | 'auto' = 'auto'
|
|
48
52
|
let bottom: number | 'auto' = 'auto'
|
|
53
|
+
let maxHeight: number | undefined
|
|
49
54
|
if (side === 'top') {
|
|
50
55
|
bottom = Dimensions.get('window').height - anchorRect.y + options.offset
|
|
56
|
+
maxHeight = anchorRect.y - options.offset - insetTop
|
|
51
57
|
} else {
|
|
52
58
|
top = anchorRect.y + anchorRect.height + options.offset
|
|
59
|
+
maxHeight =
|
|
60
|
+
Dimensions.get('window').height -
|
|
61
|
+
insetBottom -
|
|
62
|
+
(anchorRect.y + anchorRect.height + options.offset)
|
|
53
63
|
}
|
|
54
64
|
|
|
55
65
|
let left: number
|
|
@@ -73,5 +83,6 @@ export async function computeStyles(
|
|
|
73
83
|
bottom,
|
|
74
84
|
left,
|
|
75
85
|
maxWidth,
|
|
86
|
+
maxHeight,
|
|
76
87
|
}
|
|
77
88
|
}
|
package/src/computeStyles.web.ts
CHANGED
|
@@ -15,6 +15,7 @@ export function computeStyles(
|
|
|
15
15
|
offset: number
|
|
16
16
|
placement: Placement
|
|
17
17
|
dynamicWidth?: boolean
|
|
18
|
+
insets?: {top: number; bottom: number}
|
|
18
19
|
},
|
|
19
20
|
): ViewStyle | null {
|
|
20
21
|
const anchorRect = anchor.getBoundingClientRect()
|
|
@@ -32,12 +33,19 @@ export function computeStyles(
|
|
|
32
33
|
string | undefined,
|
|
33
34
|
]
|
|
34
35
|
|
|
36
|
+
const insetTop = options.insets?.top ?? 0
|
|
37
|
+
const insetBottom = options.insets?.bottom ?? 0
|
|
38
|
+
|
|
35
39
|
let top: number | 'auto' = 'auto'
|
|
36
40
|
let bottom: number | 'auto' = 'auto'
|
|
41
|
+
let maxHeight: number | undefined
|
|
37
42
|
if (side === 'top') {
|
|
38
43
|
bottom = window.innerHeight - anchorRect.top + options.offset
|
|
44
|
+
maxHeight = anchorRect.top - options.offset - insetTop
|
|
39
45
|
} else {
|
|
40
46
|
top = anchorRect.bottom + options.offset + window.scrollY
|
|
47
|
+
maxHeight =
|
|
48
|
+
window.innerHeight - insetBottom - anchorRect.bottom - options.offset
|
|
41
49
|
}
|
|
42
50
|
|
|
43
51
|
let left: number
|
|
@@ -63,5 +71,6 @@ export function computeStyles(
|
|
|
63
71
|
bottom,
|
|
64
72
|
left,
|
|
65
73
|
maxWidth,
|
|
74
|
+
maxHeight,
|
|
66
75
|
}
|
|
67
76
|
}
|
package/src/useSift.ts
CHANGED
|
@@ -18,10 +18,12 @@ export function useSift({
|
|
|
18
18
|
offset: offsetValue = 0,
|
|
19
19
|
placement = 'bottom',
|
|
20
20
|
dynamicWidth = false,
|
|
21
|
+
insets,
|
|
21
22
|
}: {
|
|
22
23
|
offset?: number
|
|
23
24
|
placement?: Placement
|
|
24
25
|
dynamicWidth?: boolean
|
|
26
|
+
insets?: {top: number; bottom: number}
|
|
25
27
|
} = {}) {
|
|
26
28
|
const id = useId()
|
|
27
29
|
|
|
@@ -45,11 +47,13 @@ export function useSift({
|
|
|
45
47
|
offset: offsetValue,
|
|
46
48
|
placement,
|
|
47
49
|
dynamicWidth,
|
|
50
|
+
insets,
|
|
48
51
|
})
|
|
49
52
|
options.current = {
|
|
50
53
|
offset: offsetValue,
|
|
51
54
|
placement,
|
|
52
55
|
dynamicWidth,
|
|
56
|
+
insets,
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
const update = useCallback(async () => {
|