@bsky.app/sift 0.2.3 → 0.2.5

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @bsky.app/sift
2
2
 
3
+ ## 0.2.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [`585e3f0`](https://github.com/bluesky-social/toolbox/commit/585e3f0fd73f986ab4f49d29551f182d296eeaad) Thanks [@estrattonbailey](https://github.com/estrattonbailey)! - onMouseDown and keyboardShouldPersistTaps for better outside click and selection handling
8
+
9
+ ## 0.2.4
10
+
11
+ ### Patch Changes
12
+
13
+ - [`1bf70bb`](https://github.com/bluesky-social/toolbox/commit/1bf70bb78e5d396cfd1ccf1db0002d7db4faa816) Thanks [@estrattonbailey](https://github.com/estrattonbailey)! - Remove `prepare` script
14
+
3
15
  ## 0.2.3
4
16
 
5
17
  ### Patch Changes
package/build/Sift.d.ts CHANGED
@@ -19,7 +19,7 @@ export declare function Sift<Item extends {
19
19
  onSelect?: (item: Item) => void;
20
20
  onDismiss?: () => void;
21
21
  inverted?: boolean;
22
- }): import("react").JSX.Element;
22
+ }): import("react/jsx-runtime").JSX.Element;
23
23
  /**
24
24
  * A Pressable wrapper for items rendered in Sift. It applies the necessary
25
25
  * accessibility props for each item.
@@ -30,5 +30,5 @@ export declare function SiftItem({ children, role, style, ...props }: Omit<Press
30
30
  pressed: boolean;
31
31
  hovered: boolean;
32
32
  }) => StyleProp<ViewStyle>) | undefined;
33
- }): import("react").JSX.Element;
33
+ }): import("react/jsx-runtime").JSX.Element;
34
34
  //# sourceMappingURL=Sift.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Sift.d.ts","sourceRoot":"","sources":["../src/Sift.tsx"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,cAAc,EAEpB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAC,KAAK,aA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S,CAAC,SAAS,CAAC,CAAC,GACvE,SAAS,CAAA;CACd,2CASA"}
package/build/Sift.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  import { useEffect, useRef, useState } from 'react';
2
3
  import { View, FlatList, Pressable, } from 'react-native';
3
4
  import { useKeyboardHandling } from './useKeyboardHandling';
@@ -44,25 +45,25 @@ export function Sift({ sift, data, render, style, onSelect, onDismiss, inverted,
44
45
  onDismiss,
45
46
  });
46
47
  const hasStyles = sift.popoverStyles.top != null;
47
- return (<View collapsable={false} ref={sift.refs.setPopover} role={"listbox"} id={sift.id} style={[style, sift.popoverStyles, !hasStyles && { opacity: 0 }]}>
48
- <FlatList data={data} inverted={inverted} keyExtractor={item => item.key} renderItem={items => render({
49
- active: items.index === activeIndex,
50
- props: {
51
- role: 'option',
52
- 'aria-selected': items.index === activeIndex,
53
- onPress: () => onSelect?.(items.item),
54
- },
55
- item: items.item,
56
- })}/>
57
- </View>);
48
+ return (_jsx(View, { collapsable: false, ref: sift.refs.setPopover, role: 'listbox', id: sift.id, style: [style, sift.popoverStyles, !hasStyles && { opacity: 0 }],
49
+ // @ts-ignore web only
50
+ onMouseDown: e => {
51
+ e.preventDefault();
52
+ }, children: _jsx(FlatList, { data: data, inverted: inverted, keyExtractor: item => item.key, renderItem: items => render({
53
+ active: items.index === activeIndex,
54
+ props: {
55
+ role: 'option',
56
+ 'aria-selected': items.index === activeIndex,
57
+ onPress: () => onSelect?.(items.item),
58
+ },
59
+ item: items.item,
60
+ }), keyboardShouldPersistTaps: "handled" }) }));
58
61
  }
59
62
  /**
60
63
  * A Pressable wrapper for items rendered in Sift. It applies the necessary
61
64
  * accessibility props for each item.
62
65
  */
63
66
  export function SiftItem({ children, role, style, ...props }) {
64
- return (<Pressable role={role} style={style} {...props}>
65
- {children}
66
- </Pressable>);
67
+ return (_jsx(Pressable, { role: role, style: style, ...props, children: children }));
67
68
  }
68
69
  //# sourceMappingURL=Sift.js.map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AC,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC,SAAS,IAAI,EAAC,OAAO,EAAE,CAAC,EAAC,CAAC,CAAC,CAC/D;MAAA,CAAC,QAAQ,CACP,IAAI,CAAC,CAAC,IAAI,CAAC,CACX,QAAQ,CAAC,CAAC,QAAQ,CAAC,CACnB,YAAY,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAC/B,UAAU,CAAC,CAAC,KAAK,CAAC,EAAE,CAClB,MAAM,CAAC;YACL,MAAM,EAAE,KAAK,CAAC,KAAK,KAAK,WAAW;YACnC,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,eAAe,EAAE,KAAK,CAAC,KAAK,KAAK,WAAW;gBAC5C,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC;aACtC;YACD,IAAI,EAAE,KAAK,CAAC,IAAI;SACjB,CACH,CAAC,EAEL;IAAA,EAAE,IAAI,CAAC,CACR,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,EACvB,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,GAAG,KAAK,EAOT;IACC,OAAO,CACL,CAAC,SAAS,CACR,IAAI,CAAC,CAAC,IAAY,CAAC,CACnB,KAAK,CAAC,CAAC,KAAgC,CAAC,CACxC,IAAI,KAAK,CAAC,CACV;MAAA,CAAC,QAAQ,CACX;IAAA,EAAE,SAAS,CAAC,CACb,CAAA;AACH,CAAC","sourcesContent":["import {useEffect, useRef, useState} from 'react'\nimport {\n View,\n FlatList,\n Pressable,\n type StyleProp,\n type ViewStyle,\n type PressableProps,\n type Role,\n} from 'react-native'\nimport {type UseSiftReturn} from './useSift'\nimport {useKeyboardHandling} from './useKeyboardHandling'\n\nexport * from './useSift'\n\nexport function Sift<Item extends {key: string}>({\n sift,\n data,\n render,\n style,\n onSelect,\n onDismiss,\n inverted,\n}: {\n sift: UseSiftReturn\n data: Item[]\n render: (props: {\n active: boolean\n props: {\n role: string\n 'aria-selected': boolean\n onPress: () => void\n }\n item: Item\n }) => React.ReactElement\n style?: StyleProp<ViewStyle>\n onSelect?: (item: Item) => void\n onDismiss?: () => void\n inverted?: boolean\n}) {\n const [activeIndex, setActiveIndex] = useState(0)\n const activeIndexRef = useRef(activeIndex)\n activeIndexRef.current = activeIndex\n const updateRef = useRef(sift.updatePosition)\n updateRef.current = sift.updatePosition\n\n useEffect(() => {\n setActiveIndex(0)\n updateRef.current()\n }, [data.length])\n\n const next = () => {\n if (data.length === 0) return\n setActiveIndex(i => (i + 1) % data.length)\n }\n const prev = () => {\n if (data.length === 0) return\n setActiveIndex(i => (i - 1 + data.length) % data.length)\n }\n const first = () => {\n if (data.length === 0) return\n setActiveIndex(0)\n }\n const last = () => {\n if (data.length === 0) return\n setActiveIndex(data.length - 1)\n }\n\n useKeyboardHandling({\n sift,\n onArrowDown: inverted ? prev : next,\n onArrowUp: inverted ? next : prev,\n onHome: inverted ? last : first,\n onEnd: inverted ? first : last,\n onSelect: () => {\n onSelect?.(data[activeIndexRef.current])\n },\n onDismiss,\n })\n\n const hasStyles = sift.popoverStyles.top != null\n\n return (\n <View\n collapsable={false}\n ref={sift.refs.setPopover}\n role={\"listbox\" as any}\n id={sift.id}\n style={[style, sift.popoverStyles, !hasStyles && {opacity: 0}]}>\n <FlatList\n data={data}\n inverted={inverted}\n keyExtractor={item => item.key}\n renderItem={items =>\n render({\n active: items.index === activeIndex,\n props: {\n role: 'option',\n 'aria-selected': items.index === activeIndex,\n onPress: () => onSelect?.(items.item),\n },\n item: items.item,\n })\n }\n />\n </View>\n )\n}\n\n/**\n * A Pressable wrapper for items rendered in Sift. It applies the necessary\n * accessibility props for each item.\n */\nexport function SiftItem({\n children,\n role,\n style,\n ...props\n}: Omit<PressableProps, 'role' | 'style'> & {\n role?: string\n style?:\n | StyleProp<ViewStyle>\n | ((state: {pressed: boolean; hovered: boolean}) => StyleProp<ViewStyle>)\n | undefined\n}) {\n return (\n <Pressable\n role={role as Role}\n style={style as PressableProps['style']}\n {...props}>\n {children}\n </Pressable>\n )\n}\n"]}
1
+ {"version":3,"file":"Sift.js","sourceRoot":"","sources":["../src/Sift.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAA;AACjD,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,SAAS,GAKV,MAAM,cAAc,CAAA;AAErB,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAA;AAEzD,cAAc,WAAW,CAAA;AAEzB,MAAM,UAAU,IAAI,CAA6B,EAC/C,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,KAAK,EACL,QAAQ,EACR,SAAS,EACT,QAAQ,GAiBT;IACC,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IACjD,MAAM,cAAc,GAAG,MAAM,CAAC,WAAW,CAAC,CAAA;IAC1C,cAAc,CAAC,OAAO,GAAG,WAAW,CAAA;IACpC,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;IAC7C,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,cAAc,CAAA;IAEvC,SAAS,CAAC,GAAG,EAAE;QACb,cAAc,CAAC,CAAC,CAAC,CAAA;QACjB,SAAS,CAAC,OAAO,EAAE,CAAA;IACrB,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;IAEjB,MAAM,IAAI,GAAG,GAAG,EAAE;QAChB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,OAAM;QAC7B,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAA;IAC5C,CAAC,CAAA;IACD,MAAM,IAAI,GAAG,GAAG,EAAE;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AAK,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC,SAAS,IAAI,EAAC,OAAO,EAAE,CAAC,EAAC,CAAC;QAC9D,sBAAsB;QACtB,WAAW,EAAE,CAAC,CAAC,EAAE;YACf,CAAC,CAAC,cAAc,EAAE,CAAA;QACpB,CAAC,YACD,KAAC,QAAQ,IACP,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,EAC9B,UAAU,EAAE,KAAK,CAAC,EAAE,CAClB,MAAM,CAAC;gBACL,MAAM,EAAE,KAAK,CAAC,KAAK,KAAK,WAAW;gBACnC,KAAK,EAAE;oBACL,IAAI,EAAE,QAAQ;oBACd,eAAe,EAAE,KAAK,CAAC,KAAK,KAAK,WAAW;oBAC5C,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC;iBACtC;gBACD,IAAI,EAAE,KAAK,CAAC,IAAI;aACjB,CAAC,EAEJ,yBAAyB,EAAC,SAAS,GACnC,GACG,CACR,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,EACvB,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,GAAG,KAAK,EAOT;IACC,OAAO,CACL,KAAC,SAAS,IACR,IAAI,EAAE,IAAY,EAClB,KAAK,EAAE,KAAgC,KACnC,KAAK,YACR,QAAQ,GACC,CACb,CAAA;AACH,CAAC","sourcesContent":["import {useEffect, useRef, useState} from 'react'\nimport {\n View,\n FlatList,\n Pressable,\n type StyleProp,\n type ViewStyle,\n type PressableProps,\n type Role,\n} from 'react-native'\nimport {type UseSiftReturn} from './useSift'\nimport {useKeyboardHandling} from './useKeyboardHandling'\n\nexport * from './useSift'\n\nexport function Sift<Item extends {key: string}>({\n sift,\n data,\n render,\n style,\n onSelect,\n onDismiss,\n inverted,\n}: {\n sift: UseSiftReturn\n data: Item[]\n render: (props: {\n active: boolean\n props: {\n role: string\n 'aria-selected': boolean\n onPress: () => void\n }\n item: Item\n }) => React.ReactElement\n style?: StyleProp<ViewStyle>\n onSelect?: (item: Item) => void\n onDismiss?: () => void\n inverted?: boolean\n}) {\n const [activeIndex, setActiveIndex] = useState(0)\n const activeIndexRef = useRef(activeIndex)\n activeIndexRef.current = activeIndex\n const updateRef = useRef(sift.updatePosition)\n updateRef.current = sift.updatePosition\n\n useEffect(() => {\n setActiveIndex(0)\n updateRef.current()\n }, [data.length])\n\n const next = () => {\n if (data.length === 0) return\n setActiveIndex(i => (i + 1) % data.length)\n }\n const prev = () => {\n if (data.length === 0) return\n setActiveIndex(i => (i - 1 + data.length) % data.length)\n }\n const first = () => {\n if (data.length === 0) return\n setActiveIndex(0)\n }\n const last = () => {\n if (data.length === 0) return\n setActiveIndex(data.length - 1)\n }\n\n useKeyboardHandling({\n sift,\n onArrowDown: inverted ? prev : next,\n onArrowUp: inverted ? next : prev,\n onHome: inverted ? last : first,\n onEnd: inverted ? first : last,\n onSelect: () => {\n onSelect?.(data[activeIndexRef.current])\n },\n onDismiss,\n })\n\n const hasStyles = sift.popoverStyles.top != null\n\n return (\n <View\n collapsable={false}\n ref={sift.refs.setPopover}\n role={'listbox' as any}\n id={sift.id}\n style={[style, sift.popoverStyles, !hasStyles && {opacity: 0}]}\n // @ts-ignore web only\n onMouseDown={e => {\n e.preventDefault()\n }}>\n <FlatList\n data={data}\n inverted={inverted}\n keyExtractor={item => item.key}\n renderItem={items =>\n render({\n active: items.index === activeIndex,\n props: {\n role: 'option',\n 'aria-selected': items.index === activeIndex,\n onPress: () => onSelect?.(items.item),\n },\n item: items.item,\n })\n }\n keyboardShouldPersistTaps=\"handled\"\n />\n </View>\n )\n}\n\n/**\n * A Pressable wrapper for items rendered in Sift. It applies the necessary\n * accessibility props for each item.\n */\nexport function SiftItem({\n children,\n role,\n style,\n ...props\n}: Omit<PressableProps, 'role' | 'style'> & {\n role?: string\n style?:\n | StyleProp<ViewStyle>\n | ((state: {pressed: boolean; hovered: boolean}) => StyleProp<ViewStyle>)\n | undefined\n}) {\n return (\n <Pressable\n role={role as Role}\n style={style as PressableProps['style']}\n {...props}>\n {children}\n </Pressable>\n )\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsky.app/sift",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "license": "MIT",
5
5
  "description": "A little React Native library for building autocompletes.",
6
6
  "repository": "https://github.com/bluesky-social/toolbox",
@@ -28,7 +28,7 @@
28
28
  "react-native": "*"
29
29
  },
30
30
  "scripts": {
31
- "build": "expo-module build",
31
+ "build": "expo-module clean && expo-module build",
32
32
  "clean": "expo-module clean",
33
33
  "lint": "expo-module lint",
34
34
  "test": "vitest run",
package/src/Sift.tsx CHANGED
@@ -84,9 +84,13 @@ export function Sift<Item extends {key: string}>({
84
84
  <View
85
85
  collapsable={false}
86
86
  ref={sift.refs.setPopover}
87
- role={"listbox" as any}
87
+ role={'listbox' as any}
88
88
  id={sift.id}
89
- style={[style, sift.popoverStyles, !hasStyles && {opacity: 0}]}>
89
+ style={[style, sift.popoverStyles, !hasStyles && {opacity: 0}]}
90
+ // @ts-ignore web only
91
+ onMouseDown={e => {
92
+ e.preventDefault()
93
+ }}>
90
94
  <FlatList
91
95
  data={data}
92
96
  inverted={inverted}
@@ -102,6 +106,7 @@ export function Sift<Item extends {key: string}>({
102
106
  item: items.item,
103
107
  })
104
108
  }
109
+ keyboardShouldPersistTaps="handled"
105
110
  />
106
111
  </View>
107
112
  )
package/tsconfig.json CHANGED
@@ -2,7 +2,8 @@
2
2
  {
3
3
  "extends": "expo-module-scripts/tsconfig.base",
4
4
  "compilerOptions": {
5
- "outDir": "./build"
5
+ "outDir": "./build",
6
+ "jsx": "react-jsx"
6
7
  },
7
8
  "include": ["./src"],
8
9
  "exclude": ["**/__mocks__/*", "**/__tests__/*", "**/__rsc_tests__/*"]