@agimon-ai/po-native-components 0.0.0-alpha.7 → 0.0.0-alpha.71
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/LICENSE +149 -22
- package/dist/components/AgentAvatar.d.mts +14 -0
- package/dist/components/AgentAvatar.d.mts.map +1 -0
- package/dist/components/AgentAvatar.mjs +87 -0
- package/dist/components/AgentAvatar.mjs.map +1 -0
- package/dist/components/AnnotationSurface.d.mts +69 -0
- package/dist/components/AnnotationSurface.d.mts.map +1 -0
- package/dist/components/AnnotationSurface.mjs +426 -0
- package/dist/components/AnnotationSurface.mjs.map +1 -0
- package/dist/components/Badge.d.mts +1 -1
- package/dist/components/Badge.mjs +1 -1
- package/dist/components/Button.mjs +2 -2
- package/dist/components/CodeBlock.d.mts +3 -1
- package/dist/components/CodeBlock.d.mts.map +1 -1
- package/dist/components/CodeBlock.mjs +35 -47
- package/dist/components/CodeBlock.mjs.map +1 -1
- package/dist/components/CopyButton.d.mts +13 -0
- package/dist/components/CopyButton.d.mts.map +1 -0
- package/dist/components/CopyButton.mjs +43 -0
- package/dist/components/CopyButton.mjs.map +1 -0
- package/dist/components/Dialog.mjs +3 -3
- package/dist/components/Dot.d.mts +1 -1
- package/dist/components/Dot.mjs +2 -2
- package/dist/components/DropdownMenu.d.mts.map +1 -1
- package/dist/components/DropdownMenu.mjs +12 -6
- package/dist/components/DropdownMenu.mjs.map +1 -1
- package/dist/components/HashlineLines.d.mts +13 -0
- package/dist/components/HashlineLines.d.mts.map +1 -0
- package/dist/components/HashlineLines.mjs +148 -0
- package/dist/components/HashlineLines.mjs.map +1 -0
- package/dist/components/HostFilter.d.mts +17 -0
- package/dist/components/HostFilter.d.mts.map +1 -0
- package/dist/components/HostFilter.mjs +66 -0
- package/dist/components/HostFilter.mjs.map +1 -0
- package/dist/components/HostTag.d.mts +7 -0
- package/dist/components/HostTag.d.mts.map +1 -0
- package/dist/components/HostTag.mjs +47 -0
- package/dist/components/HostTag.mjs.map +1 -0
- package/dist/components/InfoStrip.d.mts +9 -0
- package/dist/components/InfoStrip.d.mts.map +1 -0
- package/dist/components/InfoStrip.mjs +53 -0
- package/dist/components/InfoStrip.mjs.map +1 -0
- package/dist/components/Input.mjs +3 -2
- package/dist/components/Input.mjs.map +1 -1
- package/dist/components/Label.mjs +1 -1
- package/dist/components/List.d.mts.map +1 -1
- package/dist/components/List.mjs +38 -6
- package/dist/components/List.mjs.map +1 -1
- package/dist/components/LiveDuration.d.mts +30 -0
- package/dist/components/LiveDuration.d.mts.map +1 -0
- package/dist/components/LiveDuration.mjs +67 -0
- package/dist/components/LiveDuration.mjs.map +1 -0
- package/dist/components/Markdown.d.mts +10 -1
- package/dist/components/Markdown.d.mts.map +1 -1
- package/dist/components/Markdown.mjs +330 -27
- package/dist/components/Markdown.mjs.map +1 -1
- package/dist/components/MessageItem.d.mts +8 -8
- package/dist/components/MessageItem.d.mts.map +1 -1
- package/dist/components/MessageItem.mjs +71 -55
- package/dist/components/MessageItem.mjs.map +1 -1
- package/dist/components/SectionLabel.mjs +1 -1
- package/dist/components/Sheet.d.mts +7 -1
- package/dist/components/Sheet.d.mts.map +1 -1
- package/dist/components/Sheet.mjs +19 -4
- package/dist/components/Sheet.mjs.map +1 -1
- package/dist/components/SheetFrame.d.mts +13 -0
- package/dist/components/SheetFrame.d.mts.map +1 -0
- package/dist/components/SheetFrame.mjs +113 -16
- package/dist/components/SheetFrame.mjs.map +1 -1
- package/dist/components/SheetList.d.mts +14 -0
- package/dist/components/SheetList.d.mts.map +1 -0
- package/dist/components/SheetList.mjs +34 -0
- package/dist/components/SheetList.mjs.map +1 -0
- package/dist/components/ShowMore.d.mts +10 -0
- package/dist/components/ShowMore.d.mts.map +1 -0
- package/dist/components/ShowMore.mjs +44 -0
- package/dist/components/ShowMore.mjs.map +1 -0
- package/dist/components/Spinner.d.mts +1 -1
- package/dist/components/StatusBadge.d.mts +1 -1
- package/dist/components/SyntaxLine.d.mts +19 -0
- package/dist/components/SyntaxLine.d.mts.map +1 -0
- package/dist/components/SyntaxLine.mjs +134 -0
- package/dist/components/SyntaxLine.mjs.map +1 -0
- package/dist/components/Tabs.mjs +2 -2
- package/dist/components/ToolPathLink.d.mts +10 -0
- package/dist/components/ToolPathLink.d.mts.map +1 -0
- package/dist/components/ToolPathLink.mjs +40 -0
- package/dist/components/ToolPathLink.mjs.map +1 -0
- package/dist/icons/iconGlyphs.d.mts +56 -0
- package/dist/icons/iconGlyphs.d.mts.map +1 -1
- package/dist/icons/iconGlyphs.mjs +56 -0
- package/dist/icons/iconGlyphs.mjs.map +1 -1
- package/dist/icons/icons.d.mts +57 -1
- package/dist/icons/icons.d.mts.map +1 -1
- package/dist/icons/icons.mjs +15 -1
- package/dist/icons/icons.mjs.map +1 -1
- package/dist/index.d.mts +17 -4
- package/dist/index.mjs +18 -5
- package/dist/lib/fonts.d.mts +3 -1
- package/dist/lib/fonts.d.mts.map +1 -1
- package/dist/lib/fonts.mjs +4 -2
- package/dist/lib/fonts.mjs.map +1 -1
- package/dist/lib/markdown.mjs +172 -23
- package/dist/lib/markdown.mjs.map +1 -1
- package/dist/lib/reading.mjs +60 -0
- package/dist/lib/reading.mjs.map +1 -0
- package/dist/lib/useReadingPage.mjs +33 -0
- package/dist/lib/useReadingPage.mjs.map +1 -0
- package/package.json +18 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeBlock.mjs","names":["
|
|
1
|
+
{"version":3,"file":"CodeBlock.mjs","names":["StyleSheet","fontOf","codePrefix","useReadingPage","CopyButton","ShowMore","CodeBlockProps","text","language","initialPage","CodeBlock","page","reveal","visible","styles","root","block","undefined","scroll","code","copy","length","split","create","theme","gap","spacing","minWidth","uni__dependencies","borderRadius","DEFAULT","borderWidth","borderColor","colors","border","backgroundColor","deep","padding","paddingRight","color","fontFamily","mono","fontSize","sm","lineHeight","lineHeightRelaxed","position","top","right"],"sources":["../../src/components/CodeBlock.tsx"],"sourcesContent":["import { ScrollView, Text, View } from 'react-native';\nimport { StyleSheet } from 'react-native-unistyles';\n\nimport { fontOf } from '../lib/fonts';\nimport { codePrefix } from '../lib/reading';\nimport { useReadingPage } from '../lib/useReadingPage';\nimport { CopyButton } from './CopyButton';\nimport { ShowMore } from './ShowMore';\n\n/*\n * A fenced code block: the source in selectable mono type that scrolls\n * sideways rather than wrapping, and a copy button that says when it worked.\n *\n * ponytail: no syntax colouring and no mermaid diagrams yet; a mermaid fence\n * shows its source, which is still the whole content.\n */\n\nexport interface CodeBlockProps {\n /** The block's source, without the fence lines. */\n text: string;\n /** The fence's language word, such as `ts`; the web reads it from a `language-*` class. */\n language?: string;\n /** Initial reveal pages, useful for a reader restored to a known position. */\n initialPage?: number;\n}\n\nexport function CodeBlock({ text, language, initialPage = 1 }: CodeBlockProps) {\n const { page, reveal } = useReadingPage(text, initialPage);\n const visible = codePrefix(text, page);\n return (\n <View style={styles.root}>\n <View style={styles.block} accessibilityLabel={language === undefined ? undefined : `${language} code`}>\n <ScrollView horizontal showsHorizontalScrollIndicator={false} contentContainerStyle={styles.scroll}>\n <Text selectable style={styles.code}>\n {visible}\n </Text>\n </ScrollView>\n\n <CopyButton text={text} style={styles.copy} />\n </View>\n {visible.length < text.length ? (\n <ShowMore\n label=\"Show more code\"\n summary={`${visible.length} of ${text.length} characters · ${visible.split('\\n').length} of ${text.split('\\n').length} lines`}\n onPress={reveal}\n />\n ) : null}\n </View>\n );\n}\n\nconst styles = StyleSheet.create((theme) => ({\n root: { gap: theme.spacing(2), minWidth: 0 },\n block: {\n borderRadius: theme.borderRadius.DEFAULT,\n borderWidth: 1,\n borderColor: theme.colors.border,\n backgroundColor: theme.colors.deep,\n },\n // The right padding keeps the first line clear of the copy button.\n scroll: { padding: theme.spacing(2.5), paddingRight: theme.spacing(9) },\n code: {\n color: theme.colors.text,\n fontFamily: fontOf(theme.fontFamily.mono),\n fontSize: theme.fontSize.sm,\n lineHeight: theme.lineHeightRelaxed.sm,\n },\n copy: { position: 'absolute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iC,YAAYvC,OAAOuB,MAAMgB,WAAWC,IAAI;EACxCC,UAAUlB,MAAMkB,SAASC;EACzBC,YAAYpB,MAAMqB,kBAAkBF;EAAEf,mBAAA,CAAA,CAAA;CACxC;CACAR,MAAM;EAAE0B,UAAU;EAAYC,KAAKvB,MAAME,QAAQ,GAAG;EAAGsB,OAAOxB,MAAME,QAAQ,GAAG;EAACE,mBAAA,CAAA,CAAA;CAAC;AACnF,EAAE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { StyleProp, ViewStyle } from "react-native";
|
|
2
|
+
//#region src/components/CopyButton.d.ts
|
|
3
|
+
export interface CopyButtonProps {
|
|
4
|
+
/** The text the press puts on the clipboard. */
|
|
5
|
+
text: string;
|
|
6
|
+
/** What is copied, announced before the state, such as `path`. */
|
|
7
|
+
label?: string;
|
|
8
|
+
style?: StyleProp<ViewStyle>;
|
|
9
|
+
}
|
|
10
|
+
/** A quiet icon button that copies text and says, briefly, whether it worked. */
|
|
11
|
+
export declare function CopyButton({ text, label, style }: CopyButtonProps): import("react").JSX.Element;
|
|
12
|
+
//#endregion
|
|
13
|
+
//# sourceMappingURL=CopyButton.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CopyButton.d.mts","names":[],"sources":["../../src/components/CopyButton.tsx"],"mappings":";;iBAkBiB;;EAEf;;EAEA;EACA,QAAQ,UAAU;;;wBAIJ,aAAa,MAAM,OAAO,SAAS,kCAAe,IAAA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Button } from "./Button.mjs";
|
|
2
|
+
import { CheckIcon, CopyIcon } from "../icons/icons.mjs";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { setStringAsync } from "expo-clipboard";
|
|
6
|
+
|
|
7
|
+
//#region src/components/CopyButton.tsx
|
|
8
|
+
/** How long the control stays acknowledged before returning to its icon. */
|
|
9
|
+
const FEEDBACK_MS = 1500;
|
|
10
|
+
const LABELS = {
|
|
11
|
+
idle: "copy",
|
|
12
|
+
copied: "copied",
|
|
13
|
+
failed: "copying failed"
|
|
14
|
+
};
|
|
15
|
+
/** A quiet icon button that copies text and says, briefly, whether it worked. */
|
|
16
|
+
function CopyButton({ text, label, style }) {
|
|
17
|
+
const [state, setState] = useState("idle");
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (state === "idle") return void 0;
|
|
20
|
+
const timer = setTimeout(() => setState("idle"), FEEDBACK_MS);
|
|
21
|
+
return () => clearTimeout(timer);
|
|
22
|
+
}, [state]);
|
|
23
|
+
return /* @__PURE__ */ jsx(Button, {
|
|
24
|
+
variant: "ghost",
|
|
25
|
+
size: "icon",
|
|
26
|
+
accessibilityLabel: label === void 0 ? LABELS[state] : `${LABELS[state]} ${label}`,
|
|
27
|
+
onPress: () => {
|
|
28
|
+
setStringAsync(text).then((saved) => setState(saved ? "copied" : "failed"), () => setState("failed"));
|
|
29
|
+
},
|
|
30
|
+
style,
|
|
31
|
+
children: state === "copied" ? /* @__PURE__ */ jsx(CheckIcon, {
|
|
32
|
+
size: 12,
|
|
33
|
+
color: "green"
|
|
34
|
+
}) : /* @__PURE__ */ jsx(CopyIcon, {
|
|
35
|
+
size: 12,
|
|
36
|
+
color: "faint"
|
|
37
|
+
})
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { CopyButton };
|
|
43
|
+
//# sourceMappingURL=CopyButton.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CopyButton.mjs","names":["setStringAsync","useEffect","useState","StyleProp","ViewStyle","CheckIcon","CopyIcon","Button","FEEDBACK_MS","CopyState","LABELS","Readonly","Record","idle","copied","failed","CopyButtonProps","text","label","style","CopyButton","state","setState","undefined","timer","setTimeout","clearTimeout","then","saved"],"sources":["../../src/components/CopyButton.tsx"],"sourcesContent":["import { setStringAsync } from 'expo-clipboard';\nimport { useEffect, useState } from 'react';\nimport type { StyleProp, ViewStyle } from 'react-native';\n\nimport { CheckIcon, CopyIcon } from '../icons/icons';\nimport { Button } from './Button';\n\n/** How long the control stays acknowledged before returning to its icon. */\nconst FEEDBACK_MS = 1500;\n\ntype CopyState = 'idle' | 'copied' | 'failed';\n\nconst LABELS: Readonly<Record<CopyState, string>> = {\n idle: 'copy',\n copied: 'copied',\n failed: 'copying failed',\n};\n\nexport interface CopyButtonProps {\n /** The text the press puts on the clipboard. */\n text: string;\n /** What is copied, announced before the state, such as `path`. */\n label?: string;\n style?: StyleProp<ViewStyle>;\n}\n\n/** A quiet icon button that copies text and says, briefly, whether it worked. */\nexport function CopyButton({ text, label, style }: CopyButtonProps) {\n const [state, setState] = useState<CopyState>('idle');\n\n useEffect(() => {\n if (state === 'idle') return undefined;\n const timer = setTimeout(() => setState('idle'), FEEDBACK_MS);\n return () => clearTimeout(timer);\n }, [state]);\n\n return (\n <Button\n variant=\"ghost\"\n size=\"icon\"\n accessibilityLabel={label === undefined ? LABELS[state] : `${LABELS[state]} ${label}`}\n onPress={() => {\n setStringAsync(text).then(\n (saved) => setState(saved ? 'copied' : 'failed'),\n () => setState('failed'),\n );\n }}\n style={style}\n >\n {state === 'copied' ? <CheckIcon size={12} color=\"green\" /> : <CopyIcon size={12} color=\"faint\" />}\n </Button>\n );\n}\n"],"mappings":";;;;;;;;AAQA,MAAMQ,cAAc;AAIpB,MAAME,SAA8C;CAClDG,MAAM;CACNC,QAAQ;CACRC,QAAQ;AACV;;AAWA,SAAgBK,WAAW,EAAEH,MAAMC,OAAOC,SAA0B;CAClE,MAAM,CAACE,OAAOC,YAAYpB,SAAoB,MAAM;CAEpDD,gBAAgB;EACd,IAAIoB,UAAU,QAAQ,OAAOE;EAC7B,MAAMC,QAAQC,iBAAiBH,SAAS,MAAM,GAAGd,WAAW;EAC5D,aAAakB,aAAaF,KAAK;CACjC,GAAG,CAACH,KAAK,CAAC;CAEV,OACE,oBAAC,QAAD;EACE,SAAQ;EACR,MAAK;EACL,oBAAoBH,UAAUK,SAAYb,OAAOW,SAAS,GAAGX,OAAOW,OAAM,GAAIH;EAC9E,eAAe;GACblB,eAAeiB,IAAI,CAAC,CAACU,MAClBC,UAAUN,SAASM,QAAQ,WAAW,QAAQ,SACzCN,SAAS,QAAQ,CACzB;EACF;EACOH;YAENE,UAAU,WAAW,oBAAC,WAAD;GAAW,MAAM;GAAI,OAAM;EAAO,KAAM,oBAAC,UAAD;GAAU,MAAM;GAAI,OAAM;EAAO;CACzF;AAEZ"}
|
|
@@ -4,14 +4,14 @@ import { Button } from "./Button.mjs";
|
|
|
4
4
|
import { CloseIcon } from "../icons/icons.mjs";
|
|
5
5
|
import { useControllable } from "../lib/useControllable.mjs";
|
|
6
6
|
import { View } from "react-native-unistyles/components/native/View";
|
|
7
|
-
import {
|
|
7
|
+
import { Text } from "react-native-unistyles/components/native/Text";
|
|
8
8
|
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
|
9
9
|
import { Easing, Modal, Platform } from "react-native";
|
|
10
|
-
import {
|
|
10
|
+
import { Animated } from "react-native-unistyles/components/native/Animated";
|
|
11
|
+
import { withAlpha } from "@agimon-ai/po-web-components/nativeTheme";
|
|
11
12
|
import { createContext, useContext, useEffect, useRef } from "react";
|
|
12
13
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
14
|
import { Pressable } from "react-native-unistyles/components/native/Pressable";
|
|
14
|
-
import { Animated } from "react-native-unistyles/components/native/Animated";
|
|
15
15
|
|
|
16
16
|
//#region src/components/Dialog.tsx
|
|
17
17
|
/** `bg-po-deep/70`. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DotTone } from "@agimon-ai/po-web-components/nativeTheme";
|
|
2
1
|
import { StyleProp, ViewStyle } from "react-native";
|
|
2
|
+
import { DotTone } from "@agimon-ai/po-web-components/nativeTheme";
|
|
3
3
|
//#region src/components/Dot.d.ts
|
|
4
4
|
type DotTone$1 = DotTone;
|
|
5
5
|
export type DotSize = 'xs' | 'sm' | 'md' | 'lg';
|
package/dist/components/Dot.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { withAlpha } from "@agimon-ai/po-web-components/nativeTheme";
|
|
2
1
|
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
|
2
|
+
import { Animated } from "react-native-unistyles/components/native/Animated";
|
|
3
|
+
import { withAlpha } from "@agimon-ai/po-web-components/nativeTheme";
|
|
3
4
|
import { useEffect, useRef } from "react";
|
|
4
5
|
import { jsx } from "react/jsx-runtime";
|
|
5
|
-
import { Animated } from "react-native-unistyles/components/native/Animated";
|
|
6
6
|
|
|
7
7
|
//#region src/components/Dot.tsx
|
|
8
8
|
/** `bg-po-faint/40`: a thing that exists but is not live. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DropdownMenu.d.mts","names":[],"sources":["../../src/components/DropdownMenu.tsx"],"mappings":";;;;iBAyCiB;;EAEf;EACA;EACA,gBAAgB;EAChB,WAAW;;wBAGG,eAAe,MAAM,aAAqB,cAAc,YAAY,oCAAiB,IAAA;;wBAMrF,sBAAsB,SAAS,uBAAuB,SAAS,8BAAW,IAAA;iBAczE;EACf,WAAW;;;wBAIG,sBAAsB,YAAY,2CAAwB,IAAA;
|
|
1
|
+
{"version":3,"file":"DropdownMenu.d.mts","names":[],"sources":["../../src/components/DropdownMenu.tsx"],"mappings":";;;;iBAyCiB;;EAEf;EACA;EACA,gBAAgB;EAChB,WAAW;;wBAGG,eAAe,MAAM,aAAqB,cAAc,YAAY,oCAAiB,IAAA;;wBAMrF,sBAAsB,SAAS,uBAAuB,SAAS,8BAAW,IAAA;iBAczE;EACf,WAAW;;;wBAIG,sBAAsB,YAAY,2CAAwB,IAAA;iBAazD,8BAA8B,KAAK;EAClD,WAAW;EACX,QAAQ,UAAU;;;wBAIJ,oBAAoB,aAAa,SAAS,wCAAqB,IAAA;YAInE;iBAEK;EACf,UAAU;;EAEV;EACA;;EAEA;;EAEA,WAAW;EACX,QAAQ,UAAU;;wBA8CJ,iBAAiB,OAAO,wCAAqB,IAAA;iBAI5C,sCAAsC,KAAK;EAC1D;EACA,mBAAmB;;;wBAIL,2BACd,SACA,iBACA,aACG,SACF,gDAA6B,IAAA;iBAef,oCAAoC;EACnD;EACA,iBAAiB;;;wBAIH,yBAAyB,OAAO,eAAe,aAAa,SAAS,8CAA2B,IAAA;iBAU/F,mCAAmC,KAAK;EACvD;;wBAGc,wBAAwB,OAAO,aAAa,SAAS,6CAA0B,IAAA;;wBAkB/E,oBAAoB,OAAO,aAAa,SAAS,4BAAS,IAAA;;wBAU1D,uBAAuB,UAAU,SAAS,4BAAS,IAAA;wBAInD,wBAAwB;EAAW,QAAQ,UAAU;oBAAY,IAAA"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { fontOf } from "../lib/fonts.mjs";
|
|
2
|
-
import { wrapText } from "../lib/wrapText.mjs";
|
|
3
2
|
import { selectionTick } from "../lib/haptics.mjs";
|
|
3
|
+
import { wrapText } from "../lib/wrapText.mjs";
|
|
4
4
|
import { Button } from "./Button.mjs";
|
|
5
5
|
import { CheckIcon } from "../icons/icons.mjs";
|
|
6
6
|
import { useControllable } from "../lib/useControllable.mjs";
|
|
7
7
|
import { SheetFrame } from "./SheetFrame.mjs";
|
|
8
8
|
import { View } from "react-native-unistyles/components/native/View";
|
|
9
|
-
import { StyleSheet } from "react-native-unistyles";
|
|
10
9
|
import { Text } from "react-native-unistyles/components/native/Text";
|
|
10
|
+
import { StyleSheet } from "react-native-unistyles";
|
|
11
11
|
import { createContext, useContext } from "react";
|
|
12
12
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { Pressable } from "react-native-unistyles/components/native/Pressable";
|
|
@@ -57,10 +57,16 @@ function DropdownMenuContent({ children }) {
|
|
|
57
57
|
return /* @__PURE__ */ jsx(SheetFrame, {
|
|
58
58
|
open,
|
|
59
59
|
onClose: () => setOpen(false),
|
|
60
|
-
children: /* @__PURE__ */ jsx(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
children: /* @__PURE__ */ jsx(MenuContext.Provider, {
|
|
61
|
+
value: {
|
|
62
|
+
open,
|
|
63
|
+
setOpen
|
|
64
|
+
},
|
|
65
|
+
children: /* @__PURE__ */ jsx(View, {
|
|
66
|
+
accessibilityRole: "menu",
|
|
67
|
+
style: styles.content,
|
|
68
|
+
children
|
|
69
|
+
})
|
|
64
70
|
})
|
|
65
71
|
});
|
|
66
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DropdownMenu.mjs","names":["createContext","ReactNode","useContext","StyleProp","TextProps","ViewProps","ViewStyle","StyleSheet","CheckIcon","fontOf","selectionTick","useControllable","wrapText","Button","ButtonProps","SheetFrame","INDICATOR_GUTTER","MIN_ROW_HEIGHT","DISABLED_OPACITY","RADIO_DOT","MenuState","open","setOpen","MenuContext","undefined","RadioState","value","onValueChange","RadioContext","DropdownMenuProps","defaultOpen","onOpenChange","children","DropdownMenu","current","DropdownMenuTrigger","onPress","accessibilityState","props","expanded","event","DropdownMenuContentProps","DropdownMenuContent","styles","content","DropdownMenuPartProps","Omit","style","DropdownMenuGroup","DropdownMenuItemVariant","DropdownMenuItemProps","variant","indented","disabled","onSelect","ItemRowProps","role","checked","indicator","ItemRow","_styles","useVariants","pressed","item","label","DropdownMenuItem","DropdownMenuCheckboxItemProps","onCheckedChange","DropdownMenuCheckboxItem","DropdownMenuRadioGroupProps","DropdownMenuRadioGroup","DropdownMenuRadioItemProps","DropdownMenuRadioItem","radio","radioDot","DropdownMenuLabel","charAt","toUpperCase","slice","menuLabel","DropdownMenuShortcut","shortcut","DropdownMenuSeparator","separator","create","theme","paddingVertical","spacing","uni__dependencies","flexDirection","alignItems","gap","minHeight","paddingHorizontal","paddingLeft","position","left","width","height","justifyContent","borderRadius","full","backgroundColor","colors","blue","deep","opacity","flexShrink","fontFamily","sans","fontSize","base","lineHeight","variants","default","color","hi","destructive","red","dim","sm","fontWeight","semibold","marginLeft","marginVertical"],"sources":["../../src/components/DropdownMenu.tsx"],"sourcesContent":["import { createContext, type ReactNode, useContext } from 'react';\nimport { Pressable, type StyleProp, Text, type TextProps, View, type ViewProps, type ViewStyle } from 'react-native';\nimport { StyleSheet } from 'react-native-unistyles';\n\nimport { CheckIcon } from '../icons/icons';\nimport { fontOf } from '../lib/fonts';\nimport { selectionTick } from '../lib/haptics';\nimport { useControllable } from '../lib/useControllable';\nimport { wrapText } from '../lib/wrapText';\nimport { Button, type ButtonProps } from './Button';\nimport { SheetFrame } from './SheetFrame';\n\n/*\n * The web DropdownMenu as an action sheet: the same items rise in a bottom\n * sheet, each a full-width 44pt row, choosing one ticks once and closes the\n * menu, and destructive rows are red.\n *\n * ponytail: submenus are not ported; a native action list nests by opening a\n * second menu from an item.\n */\n\n/** A row that carries a check or bullet keeps a gutter for it, so labels line up whether or not one is set. */\nconst INDICATOR_GUTTER = 28;\nconst MIN_ROW_HEIGHT = 44;\nconst DISABLED_OPACITY = 0.4;\nconst RADIO_DOT = 6;\n\ninterface MenuState {\n open: boolean;\n setOpen: (open: boolean) => void;\n}\n\nconst MenuContext = createContext<MenuState>({ open: false, setOpen: () => undefined });\n\ninterface RadioState {\n value: string | undefined;\n onValueChange: ((value: string) => void) | undefined;\n}\n\nconst RadioContext = createContext<RadioState>({ value: undefined, onValueChange: undefined });\n\nexport interface DropdownMenuProps {\n /** Controlled mode; pair with onOpenChange. Omit it and the menu keeps its own state. */\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n children?: ReactNode;\n}\n\nexport function DropdownMenu({ open, defaultOpen = false, onOpenChange, children }: DropdownMenuProps) {\n const [current, setOpen] = useControllable(open, defaultOpen, onOpenChange);\n return <MenuContext.Provider value={{ open: current, setOpen }}>{children}</MenuContext.Provider>;\n}\n\n/** A Button that opens the menu; announces that it opens a menu. */\nexport function DropdownMenuTrigger({ onPress, accessibilityState, ...props }: ButtonProps) {\n const { open, setOpen } = useContext(MenuContext);\n return (\n <Button\n accessibilityState={{ ...accessibilityState, expanded: open }}\n onPress={(event) => {\n onPress?.(event);\n setOpen(true);\n }}\n {...props}\n />\n );\n}\n\nexport interface DropdownMenuContentProps {\n children?: ReactNode;\n}\n\n/** The action list, in a bottom sheet. */\nexport function DropdownMenuContent({ children }: DropdownMenuContentProps) {\n const { open, setOpen } = useContext(MenuContext);\n return (\n <SheetFrame open={open} onClose={() => setOpen(false)}>\n <View accessibilityRole=\"menu\" style={styles.content}>\n {children}\n </View>\n </SheetFrame>\n );\n}\n\nexport interface DropdownMenuPartProps extends Omit<ViewProps, 'children' | 'style'> {\n children?: ReactNode;\n style?: StyleProp<ViewStyle>;\n}\n\n/** A run of items under one label, so the separator between groups is structural. */\nexport function DropdownMenuGroup({ children, ...props }: DropdownMenuPartProps) {\n return <View {...props}>{children}</View>;\n}\n\nexport type DropdownMenuItemVariant = 'default' | 'destructive';\n\nexport interface DropdownMenuItemProps {\n variant?: DropdownMenuItemVariant;\n /** Keep the indicator gutter, so the label lines up with checkbox and radio rows. */\n indented?: boolean;\n disabled?: boolean;\n /** Chosen: the menu ticks, runs this, then closes. */\n onSelect?: () => void;\n /** The label, optionally followed by a DropdownMenuShortcut. */\n children?: ReactNode;\n style?: StyleProp<ViewStyle>;\n}\n\ninterface ItemRowProps extends DropdownMenuItemProps {\n role: 'menuitem' | 'checkbox' | 'radio';\n checked?: boolean;\n indicator?: ReactNode;\n}\n\nfunction ItemRow({\n variant = 'default',\n indented = false,\n disabled = false,\n onSelect,\n role,\n checked,\n indicator,\n children,\n style,\n}: ItemRowProps) {\n const { setOpen } = useContext(MenuContext);\n styles.useVariants({ variant: variant === 'destructive' ? 'destructive' : undefined });\n return (\n <Pressable\n accessibilityRole={role}\n accessibilityState={{ disabled, checked }}\n disabled={disabled}\n onPress={() => {\n selectionTick();\n onSelect?.();\n setOpen(false);\n }}\n style={({ pressed }) => [\n styles.item,\n (indented || indicator !== undefined) && styles.indented,\n pressed && styles.pressed,\n disabled && styles.disabled,\n style,\n ]}\n >\n {indicator !== undefined ? <View style={styles.indicator}>{indicator}</View> : null}\n {wrapText(children, styles.label)}\n </Pressable>\n );\n}\n\nexport function DropdownMenuItem(props: DropdownMenuItemProps) {\n return <ItemRow role=\"menuitem\" {...props} />;\n}\n\nexport interface DropdownMenuCheckboxItemProps extends Omit<DropdownMenuItemProps, 'indented'> {\n checked?: boolean;\n onCheckedChange?: (checked: boolean) => void;\n}\n\n/** A row that toggles: the check lives in the gutter so the label never shifts. */\nexport function DropdownMenuCheckboxItem({\n checked = false,\n onCheckedChange,\n onSelect,\n ...props\n}: DropdownMenuCheckboxItemProps) {\n return (\n <ItemRow\n role=\"checkbox\"\n checked={checked}\n indicator={checked ? <CheckIcon size={12} color=\"blue\" /> : null}\n onSelect={() => {\n onCheckedChange?.(!checked);\n onSelect?.();\n }}\n {...props}\n />\n );\n}\n\nexport interface DropdownMenuRadioGroupProps extends DropdownMenuPartProps {\n value?: string;\n onValueChange?: (value: string) => void;\n}\n\n/** The exclusive-choice group; pair it with DropdownMenuRadioItem. */\nexport function DropdownMenuRadioGroup({ value, onValueChange, children, ...props }: DropdownMenuRadioGroupProps) {\n return (\n <RadioContext.Provider value={{ value, onValueChange }}>\n <View accessibilityRole=\"radiogroup\" {...props}>\n {children}\n </View>\n </RadioContext.Provider>\n );\n}\n\nexport interface DropdownMenuRadioItemProps extends Omit<DropdownMenuItemProps, 'indented'> {\n value: string;\n}\n\nexport function DropdownMenuRadioItem({ value, onSelect, ...props }: DropdownMenuRadioItemProps) {\n const radio = useContext(RadioContext);\n const checked = radio.value === value;\n return (\n <ItemRow\n role=\"radio\"\n checked={checked}\n indicator={checked ? <View style={styles.radioDot} /> : null}\n onSelect={() => {\n radio.onValueChange?.(value);\n onSelect?.();\n }}\n {...props}\n />\n );\n}\n\n/** The heading over a run of items, raised to sentence case as the web's `first-letter:uppercase`. */\nexport function DropdownMenuLabel({ style, children, ...props }: TextProps) {\n const label = typeof children === 'string' ? children.charAt(0).toUpperCase() + children.slice(1) : children;\n return (\n <Text accessibilityRole=\"header\" style={[styles.menuLabel, style]} {...props}>\n {label}\n </Text>\n );\n}\n\n/** The keystroke printed at the right of a row; the row supplies the gap. */\nexport function DropdownMenuShortcut({ style, ...props }: TextProps) {\n return <Text style={[styles.shortcut, style]} {...props} />;\n}\n\nexport function DropdownMenuSeparator({ style }: { style?: StyleProp<ViewStyle> }) {\n return <View accessible={false} style={[styles.separator, style]} />;\n}\n\nconst styles = StyleSheet.create((theme) => ({\n content: { paddingVertical: theme.spacing(1) },\n item: {\n flexDirection: 'row',\n alignItems: 'center',\n gap: theme.spacing(2),\n minHeight: MIN_ROW_HEIGHT,\n paddingHorizontal: theme.spacing(4),\n },\n indented: { paddingLeft: theme.spacing(4) + INDICATOR_GUTTER },\n indicator: {\n position: 'absolute',\n left: theme.spacing(4),\n width: theme.spacing(3),\n height: theme.spacing(3),\n alignItems: 'center',\n justifyContent: 'center',\n },\n radioDot: {\n width: RADIO_DOT,\n height: RADIO_DOT,\n borderRadius: theme.borderRadius.full,\n backgroundColor: theme.colors.blue,\n },\n pressed: { backgroundColor: theme.colors.deep },\n disabled: { opacity: DISABLED_OPACITY },\n label: {\n flexShrink: 1,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.base,\n lineHeight: theme.lineHeight.base,\n variants: {\n variant: {\n default: { color: theme.colors.hi },\n destructive: { color: theme.colors.red },\n },\n },\n },\n menuLabel: {\n paddingHorizontal: theme.spacing(4),\n paddingVertical: theme.spacing(1),\n color: theme.colors.dim,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.sm,\n lineHeight: theme.lineHeight.sm,\n fontWeight: theme.fontWeight.semibold,\n },\n shortcut: {\n marginLeft: 'auto',\n flexShrink: 0,\n color: theme.colors.dim,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.sm,\n lineHeight: theme.lineHeight.sm,\n },\n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,WAAWQ;EAAEhC,mBAAA,CAAA,CAAA;CACjC;CACAL,WAAW;EAAEe,QAAQ;EAAG0B,gBAAgBvC,MAAME,QAAQ,CAAC;EAAGe,iBAAiBjB,MAAMkB,OAAO;EAAcf,mBAAA,CAAA,CAAA;CAAC;AACzG,EAAE"}
|
|
1
|
+
{"version":3,"file":"DropdownMenu.mjs","names":["createContext","ReactNode","useContext","StyleProp","TextProps","ViewProps","ViewStyle","StyleSheet","CheckIcon","fontOf","selectionTick","useControllable","wrapText","Button","ButtonProps","SheetFrame","INDICATOR_GUTTER","MIN_ROW_HEIGHT","DISABLED_OPACITY","RADIO_DOT","MenuState","open","setOpen","MenuContext","undefined","RadioState","value","onValueChange","RadioContext","DropdownMenuProps","defaultOpen","onOpenChange","children","DropdownMenu","current","DropdownMenuTrigger","onPress","accessibilityState","props","expanded","event","DropdownMenuContentProps","DropdownMenuContent","styles","content","DropdownMenuPartProps","Omit","style","DropdownMenuGroup","DropdownMenuItemVariant","DropdownMenuItemProps","variant","indented","disabled","onSelect","ItemRowProps","role","checked","indicator","ItemRow","_styles","useVariants","pressed","item","label","DropdownMenuItem","DropdownMenuCheckboxItemProps","onCheckedChange","DropdownMenuCheckboxItem","DropdownMenuRadioGroupProps","DropdownMenuRadioGroup","DropdownMenuRadioItemProps","DropdownMenuRadioItem","radio","radioDot","DropdownMenuLabel","charAt","toUpperCase","slice","menuLabel","DropdownMenuShortcut","shortcut","DropdownMenuSeparator","separator","create","theme","paddingVertical","spacing","uni__dependencies","flexDirection","alignItems","gap","minHeight","paddingHorizontal","paddingLeft","position","left","width","height","justifyContent","borderRadius","full","backgroundColor","colors","blue","deep","opacity","flexShrink","fontFamily","sans","fontSize","base","lineHeight","variants","default","color","hi","destructive","red","dim","sm","fontWeight","semibold","marginLeft","marginVertical"],"sources":["../../src/components/DropdownMenu.tsx"],"sourcesContent":["import { createContext, type ReactNode, useContext } from 'react';\nimport { Pressable, type StyleProp, Text, type TextProps, View, type ViewProps, type ViewStyle } from 'react-native';\nimport { StyleSheet } from 'react-native-unistyles';\n\nimport { CheckIcon } from '../icons/icons';\nimport { fontOf } from '../lib/fonts';\nimport { selectionTick } from '../lib/haptics';\nimport { useControllable } from '../lib/useControllable';\nimport { wrapText } from '../lib/wrapText';\nimport { Button, type ButtonProps } from './Button';\nimport { SheetFrame } from './SheetFrame';\n\n/*\n * The web DropdownMenu as an action sheet: the same items rise in a bottom\n * sheet, each a full-width 44pt row, choosing one ticks once and closes the\n * menu, and destructive rows are red.\n *\n * ponytail: submenus are not ported; a native action list nests by opening a\n * second menu from an item.\n */\n\n/** A row that carries a check or bullet keeps a gutter for it, so labels line up whether or not one is set. */\nconst INDICATOR_GUTTER = 28;\nconst MIN_ROW_HEIGHT = 44;\nconst DISABLED_OPACITY = 0.4;\nconst RADIO_DOT = 6;\n\ninterface MenuState {\n open: boolean;\n setOpen: (open: boolean) => void;\n}\n\nconst MenuContext = createContext<MenuState>({ open: false, setOpen: () => undefined });\n\ninterface RadioState {\n value: string | undefined;\n onValueChange: ((value: string) => void) | undefined;\n}\n\nconst RadioContext = createContext<RadioState>({ value: undefined, onValueChange: undefined });\n\nexport interface DropdownMenuProps {\n /** Controlled mode; pair with onOpenChange. Omit it and the menu keeps its own state. */\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n children?: ReactNode;\n}\n\nexport function DropdownMenu({ open, defaultOpen = false, onOpenChange, children }: DropdownMenuProps) {\n const [current, setOpen] = useControllable(open, defaultOpen, onOpenChange);\n return <MenuContext.Provider value={{ open: current, setOpen }}>{children}</MenuContext.Provider>;\n}\n\n/** A Button that opens the menu; announces that it opens a menu. */\nexport function DropdownMenuTrigger({ onPress, accessibilityState, ...props }: ButtonProps) {\n const { open, setOpen } = useContext(MenuContext);\n return (\n <Button\n accessibilityState={{ ...accessibilityState, expanded: open }}\n onPress={(event) => {\n onPress?.(event);\n setOpen(true);\n }}\n {...props}\n />\n );\n}\n\nexport interface DropdownMenuContentProps {\n children?: ReactNode;\n}\n\n/** The action list, in a bottom sheet. */\nexport function DropdownMenuContent({ children }: DropdownMenuContentProps) {\n const { open, setOpen } = useContext(MenuContext);\n return (\n <SheetFrame open={open} onClose={() => setOpen(false)}>\n <MenuContext.Provider value={{ open, setOpen }}>\n <View accessibilityRole=\"menu\" style={styles.content}>\n {children}\n </View>\n </MenuContext.Provider>\n </SheetFrame>\n );\n}\n\nexport interface DropdownMenuPartProps extends Omit<ViewProps, 'children' | 'style'> {\n children?: ReactNode;\n style?: StyleProp<ViewStyle>;\n}\n\n/** A run of items under one label, so the separator between groups is structural. */\nexport function DropdownMenuGroup({ children, ...props }: DropdownMenuPartProps) {\n return <View {...props}>{children}</View>;\n}\n\nexport type DropdownMenuItemVariant = 'default' | 'destructive';\n\nexport interface DropdownMenuItemProps {\n variant?: DropdownMenuItemVariant;\n /** Keep the indicator gutter, so the label lines up with checkbox and radio rows. */\n indented?: boolean;\n disabled?: boolean;\n /** Chosen: the menu ticks, runs this, then closes. */\n onSelect?: () => void;\n /** The label, optionally followed by a DropdownMenuShortcut. */\n children?: ReactNode;\n style?: StyleProp<ViewStyle>;\n}\n\ninterface ItemRowProps extends DropdownMenuItemProps {\n role: 'menuitem' | 'checkbox' | 'radio';\n checked?: boolean;\n indicator?: ReactNode;\n}\n\nfunction ItemRow({\n variant = 'default',\n indented = false,\n disabled = false,\n onSelect,\n role,\n checked,\n indicator,\n children,\n style,\n}: ItemRowProps) {\n const { setOpen } = useContext(MenuContext);\n styles.useVariants({ variant: variant === 'destructive' ? 'destructive' : undefined });\n return (\n <Pressable\n accessibilityRole={role}\n accessibilityState={{ disabled, checked }}\n disabled={disabled}\n onPress={() => {\n selectionTick();\n onSelect?.();\n setOpen(false);\n }}\n style={({ pressed }) => [\n styles.item,\n (indented || indicator !== undefined) && styles.indented,\n pressed && styles.pressed,\n disabled && styles.disabled,\n style,\n ]}\n >\n {indicator !== undefined ? <View style={styles.indicator}>{indicator}</View> : null}\n {wrapText(children, styles.label)}\n </Pressable>\n );\n}\n\nexport function DropdownMenuItem(props: DropdownMenuItemProps) {\n return <ItemRow role=\"menuitem\" {...props} />;\n}\n\nexport interface DropdownMenuCheckboxItemProps extends Omit<DropdownMenuItemProps, 'indented'> {\n checked?: boolean;\n onCheckedChange?: (checked: boolean) => void;\n}\n\n/** A row that toggles: the check lives in the gutter so the label never shifts. */\nexport function DropdownMenuCheckboxItem({\n checked = false,\n onCheckedChange,\n onSelect,\n ...props\n}: DropdownMenuCheckboxItemProps) {\n return (\n <ItemRow\n role=\"checkbox\"\n checked={checked}\n indicator={checked ? <CheckIcon size={12} color=\"blue\" /> : null}\n onSelect={() => {\n onCheckedChange?.(!checked);\n onSelect?.();\n }}\n {...props}\n />\n );\n}\n\nexport interface DropdownMenuRadioGroupProps extends DropdownMenuPartProps {\n value?: string;\n onValueChange?: (value: string) => void;\n}\n\n/** The exclusive-choice group; pair it with DropdownMenuRadioItem. */\nexport function DropdownMenuRadioGroup({ value, onValueChange, children, ...props }: DropdownMenuRadioGroupProps) {\n return (\n <RadioContext.Provider value={{ value, onValueChange }}>\n <View accessibilityRole=\"radiogroup\" {...props}>\n {children}\n </View>\n </RadioContext.Provider>\n );\n}\n\nexport interface DropdownMenuRadioItemProps extends Omit<DropdownMenuItemProps, 'indented'> {\n value: string;\n}\n\nexport function DropdownMenuRadioItem({ value, onSelect, ...props }: DropdownMenuRadioItemProps) {\n const radio = useContext(RadioContext);\n const checked = radio.value === value;\n return (\n <ItemRow\n role=\"radio\"\n checked={checked}\n indicator={checked ? <View style={styles.radioDot} /> : null}\n onSelect={() => {\n radio.onValueChange?.(value);\n onSelect?.();\n }}\n {...props}\n />\n );\n}\n\n/** The heading over a run of items, raised to sentence case as the web's `first-letter:uppercase`. */\nexport function DropdownMenuLabel({ style, children, ...props }: TextProps) {\n const label = typeof children === 'string' ? children.charAt(0).toUpperCase() + children.slice(1) : children;\n return (\n <Text accessibilityRole=\"header\" style={[styles.menuLabel, style]} {...props}>\n {label}\n </Text>\n );\n}\n\n/** The keystroke printed at the right of a row; the row supplies the gap. */\nexport function DropdownMenuShortcut({ style, ...props }: TextProps) {\n return <Text style={[styles.shortcut, style]} {...props} />;\n}\n\nexport function DropdownMenuSeparator({ style }: { style?: StyleProp<ViewStyle> }) {\n return <View accessible={false} style={[styles.separator, style]} />;\n}\n\nconst styles = StyleSheet.create((theme) => ({\n content: { paddingVertical: theme.spacing(1) },\n item: {\n flexDirection: 'row',\n alignItems: 'center',\n gap: theme.spacing(2),\n minHeight: MIN_ROW_HEIGHT,\n paddingHorizontal: theme.spacing(4),\n },\n indented: { paddingLeft: theme.spacing(4) + INDICATOR_GUTTER },\n indicator: {\n position: 'absolute',\n left: theme.spacing(4),\n width: theme.spacing(3),\n height: theme.spacing(3),\n alignItems: 'center',\n justifyContent: 'center',\n },\n radioDot: {\n width: RADIO_DOT,\n height: RADIO_DOT,\n borderRadius: theme.borderRadius.full,\n backgroundColor: theme.colors.blue,\n },\n pressed: { backgroundColor: theme.colors.deep },\n disabled: { opacity: DISABLED_OPACITY },\n label: {\n flexShrink: 1,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.base,\n lineHeight: theme.lineHeight.base,\n variants: {\n variant: {\n default: { color: theme.colors.hi },\n destructive: { color: theme.colors.red },\n },\n },\n },\n menuLabel: {\n paddingHorizontal: theme.spacing(4),\n paddingVertical: theme.spacing(1),\n color: theme.colors.dim,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.sm,\n lineHeight: theme.lineHeight.sm,\n fontWeight: theme.fontWeight.semibold,\n },\n shortcut: {\n marginLeft: 'auto',\n flexShrink: 0,\n color: theme.colors.dim,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.sm,\n lineHeight: theme.lineHeight.sm,\n },\n separator: { height: 1, marginVertical: theme.spacing(1), backgroundColor: theme.colors['border-soft'] },\n}));\n"],"mappings":";;;;;;;;;;;;;;;;AAsBA,MAAMgB,mBAAmB;A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L,WAAW;EAAEe,QAAQ;EAAG0B,gBAAgBvC,MAAME,QAAQ,CAAC;EAAGe,iBAAiBjB,MAAMkB,OAAO;EAAcf,mBAAA,CAAA,CAAA;CAAC;AACzG,EAAE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PresentedLine } from "@agimon-ai/po-web-components/text";
|
|
2
|
+
import { ViewProps } from "react-native";
|
|
3
|
+
//#region src/components/HashlineLines.d.ts
|
|
4
|
+
export interface HashlineLinesProps extends Omit<ViewProps, 'children'> {
|
|
5
|
+
lines: readonly PresentedLine[];
|
|
6
|
+
/** Width of the line-number column, in characters, from `hashlineBody`. */
|
|
7
|
+
gutter: number;
|
|
8
|
+
/** The file a body of bare anchored lines came from, for highlighting. */
|
|
9
|
+
path?: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
export declare function HashlineLines({ lines, gutter, path, style, ...props }: HashlineLinesProps): import("react").JSX.Element;
|
|
12
|
+
//#endregion
|
|
13
|
+
//# sourceMappingURL=HashlineLines.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HashlineLines.d.mts","names":[],"sources":["../../src/components/HashlineLines.tsx"],"mappings":";;;iBA6BiB,2BAA2B,KAAK;EAC/C,gBAAgB;;EAEhB;;EAEA;;wBAwCc,gBAAgB,OAAO,QAAQ,MAAM,UAAU,SAAS,qCAAkB,IAAA"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { fontOf } from "../lib/fonts.mjs";
|
|
2
|
+
import { READING } from "../lib/reading.mjs";
|
|
3
|
+
import { useReadingPage } from "../lib/useReadingPage.mjs";
|
|
4
|
+
import { ShowMore } from "./ShowMore.mjs";
|
|
5
|
+
import { SyntaxLine } from "./SyntaxLine.mjs";
|
|
6
|
+
import { detectGrammar, hashlineGroups, hashlineGroupsKey, highlightToLines } from "@agimon-ai/po-web-components/text";
|
|
7
|
+
import { View } from "react-native-unistyles/components/native/View";
|
|
8
|
+
import { Text } from "react-native-unistyles/components/native/Text";
|
|
9
|
+
import { StyleSheet } from "react-native-unistyles";
|
|
10
|
+
import { useEffect, useMemo, useState } from "react";
|
|
11
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
+
|
|
13
|
+
//#region src/components/HashlineLines.tsx
|
|
14
|
+
const NO_SPANS = /* @__PURE__ */ new Map();
|
|
15
|
+
/** Spans per presented-line index, kept with the body they belong to, as the web's hook. */
|
|
16
|
+
function useHashlineSpans(lines, path) {
|
|
17
|
+
const groups = useMemo(() => hashlineGroups(lines, path), [lines, path]);
|
|
18
|
+
const key = hashlineGroupsKey(groups);
|
|
19
|
+
const [done, setDone] = useState();
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
let live = true;
|
|
22
|
+
const controller = new AbortController();
|
|
23
|
+
const next = /* @__PURE__ */ new Map();
|
|
24
|
+
const work = groups.map(async (group) => {
|
|
25
|
+
const grammar = detectGrammar({
|
|
26
|
+
path: group.path,
|
|
27
|
+
text: group.text
|
|
28
|
+
});
|
|
29
|
+
if (grammar === void 0) return;
|
|
30
|
+
const highlighted = await highlightToLines(group.text, grammar, controller.signal);
|
|
31
|
+
if (highlighted === void 0) return;
|
|
32
|
+
for (const [offset, index] of group.indices.entries()) {
|
|
33
|
+
const line = highlighted[offset];
|
|
34
|
+
if (line !== void 0) next.set(index, line);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
Promise.allSettled(work).then(() => {
|
|
38
|
+
if (live && next.size > 0) setDone({
|
|
39
|
+
key,
|
|
40
|
+
spans: next
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
return () => {
|
|
44
|
+
live = false;
|
|
45
|
+
controller.abort();
|
|
46
|
+
};
|
|
47
|
+
}, [key]);
|
|
48
|
+
return done?.key === key ? done.spans : NO_SPANS;
|
|
49
|
+
}
|
|
50
|
+
function HashlineLines({ lines, gutter, path, style, ...props }) {
|
|
51
|
+
const { page, reveal } = useReadingPage(`${path ?? ""}\n${lines.map((line) => JSON.stringify(line)).join("\n")}`);
|
|
52
|
+
const visible = useMemo(() => lines.slice(0, READING.hashlines * page), [lines, page]);
|
|
53
|
+
const spans = useHashlineSpans(visible, path);
|
|
54
|
+
return /* @__PURE__ */ jsxs(View, {
|
|
55
|
+
style,
|
|
56
|
+
...props,
|
|
57
|
+
children: [visible.map((line, index) => {
|
|
58
|
+
if (line.type === "file") return /* @__PURE__ */ jsx(Text, {
|
|
59
|
+
numberOfLines: 1,
|
|
60
|
+
style: [
|
|
61
|
+
styles.mono,
|
|
62
|
+
styles.faint,
|
|
63
|
+
index > 0 && styles.fileGap
|
|
64
|
+
],
|
|
65
|
+
children: line.path
|
|
66
|
+
}, index);
|
|
67
|
+
if (line.type === "plain") return /* @__PURE__ */ jsx(Text, {
|
|
68
|
+
selectable: true,
|
|
69
|
+
style: [styles.mono, styles.dim],
|
|
70
|
+
children: line.text
|
|
71
|
+
}, index);
|
|
72
|
+
const { value } = line;
|
|
73
|
+
const match = value.marker === "match";
|
|
74
|
+
return /* @__PURE__ */ jsxs(View, {
|
|
75
|
+
style: styles.row,
|
|
76
|
+
children: [
|
|
77
|
+
value.marker !== void 0 ? /* @__PURE__ */ jsx(Text, {
|
|
78
|
+
style: [styles.mono, match ? styles.marker : styles.faint],
|
|
79
|
+
children: match ? ">>" : " "
|
|
80
|
+
}) : null,
|
|
81
|
+
/* @__PURE__ */ jsx(Text, {
|
|
82
|
+
style: [styles.mono, styles.faint],
|
|
83
|
+
children: String(value.line).padStart(gutter)
|
|
84
|
+
}),
|
|
85
|
+
/* @__PURE__ */ jsx(SyntaxLine, {
|
|
86
|
+
selectable: true,
|
|
87
|
+
spans: spans.get(index),
|
|
88
|
+
text: value.content,
|
|
89
|
+
style: [
|
|
90
|
+
styles.mono,
|
|
91
|
+
styles.content,
|
|
92
|
+
match ? styles.hi : styles.text
|
|
93
|
+
]
|
|
94
|
+
})
|
|
95
|
+
]
|
|
96
|
+
}, index);
|
|
97
|
+
}), visible.length < lines.length ? /* @__PURE__ */ jsx(ShowMore, {
|
|
98
|
+
label: "Show more lines",
|
|
99
|
+
summary: `${visible.length} of ${lines.length} lines`,
|
|
100
|
+
onPress: reveal
|
|
101
|
+
}) : null]
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
const styles = StyleSheet.create((theme) => ({
|
|
105
|
+
row: {
|
|
106
|
+
flexDirection: "row",
|
|
107
|
+
gap: theme.spacing(2),
|
|
108
|
+
uni__dependencies: [0]
|
|
109
|
+
},
|
|
110
|
+
fileGap: {
|
|
111
|
+
marginTop: theme.spacing(1),
|
|
112
|
+
uni__dependencies: [0]
|
|
113
|
+
},
|
|
114
|
+
mono: {
|
|
115
|
+
fontFamily: fontOf(theme.fontFamily.mono),
|
|
116
|
+
fontSize: theme.fontSize.sm,
|
|
117
|
+
lineHeight: theme.lineHeightRelaxed.sm,
|
|
118
|
+
uni__dependencies: [0]
|
|
119
|
+
},
|
|
120
|
+
content: {
|
|
121
|
+
flex: 1,
|
|
122
|
+
minWidth: 0
|
|
123
|
+
},
|
|
124
|
+
marker: {
|
|
125
|
+
color: theme.colors.blue,
|
|
126
|
+
uni__dependencies: [0]
|
|
127
|
+
},
|
|
128
|
+
faint: {
|
|
129
|
+
color: theme.colors.faint,
|
|
130
|
+
uni__dependencies: [0]
|
|
131
|
+
},
|
|
132
|
+
dim: {
|
|
133
|
+
color: theme.colors.dim,
|
|
134
|
+
uni__dependencies: [0]
|
|
135
|
+
},
|
|
136
|
+
text: {
|
|
137
|
+
color: theme.colors.text,
|
|
138
|
+
uni__dependencies: [0]
|
|
139
|
+
},
|
|
140
|
+
hi: {
|
|
141
|
+
color: theme.colors.hi,
|
|
142
|
+
uni__dependencies: [0]
|
|
143
|
+
}
|
|
144
|
+
}));
|
|
145
|
+
|
|
146
|
+
//#endregion
|
|
147
|
+
export { HashlineLines };
|
|
148
|
+
//# sourceMappingURL=HashlineLines.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HashlineLines.mjs","names":["detectGrammar","hashlineGroups","hashlineGroupsKey","highlightToLines","PresentedLine","SyntaxSpan","useEffect","useMemo","useState","ViewProps","StyleSheet","fontOf","READING","useReadingPage","ShowMore","SyntaxLine","HashlineLinesProps","Omit","lines","gutter","path","NO_SPANS","ReadonlyMap","Map","useHashlineSpans","groups","key","done","setDone","spans","live","controller","AbortController","next","work","map","group","grammar","text","undefined","highlighted","signal","offset","index","indices","entries","line","set","Promise","allSettled","then","size","abort","HashlineLines","style","props","page","reveal","JSON","stringify","join","visible","slice","hashlines","type","styles","mono","faint","fileGap","dim","value","match","marker","row","String","padStart","get","content","hi","length","create","theme","flexDirection","gap","spacing","uni__dependencies","marginTop","fontFamily","fontSize","sm","lineHeight","lineHeightRelaxed","flex","minWidth","color","colors","blue"],"sources":["../../src/components/HashlineLines.tsx"],"sourcesContent":["import {\n detectGrammar,\n hashlineGroups,\n hashlineGroupsKey,\n highlightToLines,\n type PresentedLine,\n type SyntaxSpan,\n} from '@agimon-ai/po-web-components/text';\nimport { useEffect, useMemo, useState } from 'react';\nimport { Text, View, type ViewProps } from 'react-native';\nimport { StyleSheet } from 'react-native-unistyles';\n\nimport { fontOf } from '../lib/fonts';\nimport { READING } from '../lib/reading';\nimport { useReadingPage } from '../lib/useReadingPage';\nimport { ShowMore } from './ShowMore';\nimport { SyntaxLine } from './SyntaxLine';\n\n/*\n * The anchored body shared by hashline results, as the web's HashlineLines: a\n * file heading per group, a right-aligned line-number gutter, and a `>>`\n * marker on grep matches. Mono type makes a padded number the gutter, so the\n * column needs no measuring.\n *\n * The anchored lines are coloured with the web's grammars and palette when the\n * body names a file, or when `path` names one. Colour arrives late and never\n * blocks the text: an unhighlighted body is the same body without the colours.\n */\n\nexport interface HashlineLinesProps extends Omit<ViewProps, 'children'> {\n lines: readonly PresentedLine[];\n /** Width of the line-number column, in characters, from `hashlineBody`. */\n gutter: number;\n /** The file a body of bare anchored lines came from, for highlighting. */\n path?: string | undefined;\n}\n\nconst NO_SPANS: ReadonlyMap<number, readonly SyntaxSpan[]> = new Map();\n\n/** Spans per presented-line index, kept with the body they belong to, as the web's hook. */\nfunction useHashlineSpans(lines: readonly PresentedLine[], path: string | undefined) {\n const groups = useMemo(() => hashlineGroups(lines, path), [lines, path]);\n const key = hashlineGroupsKey(groups);\n const [done, setDone] = useState<{ key: string; spans: ReadonlyMap<number, readonly SyntaxSpan[]> }>();\n\n useEffect(() => {\n let live = true;\n const controller = new AbortController();\n const next = new Map<number, readonly SyntaxSpan[]>();\n const work = groups.map(async (group) => {\n const grammar = detectGrammar({ path: group.path, text: group.text });\n if (grammar === undefined) return;\n const highlighted = await highlightToLines(group.text, grammar, controller.signal);\n if (highlighted === undefined) return;\n for (const [offset, index] of group.indices.entries()) {\n const line = highlighted[offset];\n if (line !== undefined) next.set(index, line);\n }\n });\n // A grammar that fails to load leaves its run plain: colour is decoration.\n void Promise.allSettled(work).then(() => {\n if (live && next.size > 0) setDone({ key, spans: next });\n });\n return () => {\n live = false;\n controller.abort();\n };\n // The groups are rebuilt with the lines; their key is what actually changes.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [key]);\n\n return done?.key === key ? done.spans : NO_SPANS;\n}\n\nexport function HashlineLines({ lines, gutter, path, style, ...props }: HashlineLinesProps) {\n // Whole anchored lines retain their exact content and line numbers, even above 640 characters.\n const { page, reveal } = useReadingPage(`${path ?? ''}\\n${lines.map((line) => JSON.stringify(line)).join('\\n')}`);\n const visible = useMemo(() => lines.slice(0, READING.hashlines * page), [lines, page]);\n const spans = useHashlineSpans(visible, path);\n return (\n <View style={style} {...props}>\n {visible.map((line, index) => {\n if (line.type === 'file') {\n return (\n <Text key={index} numberOfLines={1} style={[styles.mono, styles.faint, index > 0 && styles.fileGap]}>\n {line.path}\n </Text>\n );\n }\n if (line.type === 'plain') {\n return (\n <Text key={index} selectable style={[styles.mono, styles.dim]}>\n {line.text}\n </Text>\n );\n }\n const { value } = line;\n const match = value.marker === 'match';\n return (\n <View key={index} style={styles.row}>\n {value.marker !== undefined ? (\n <Text style={[styles.mono, match ? styles.marker : styles.faint]}>{match ? '>>' : ' '}</Text>\n ) : null}\n <Text style={[styles.mono, styles.faint]}>{String(value.line).padStart(gutter)}</Text>\n <SyntaxLine\n selectable\n spans={spans.get(index)}\n text={value.content}\n style={[styles.mono, styles.content, match ? styles.hi : styles.text]}\n />\n </View>\n );\n })}\n {visible.length < lines.length ? (\n <ShowMore label=\"Show more lines\" summary={`${visible.length} of ${lines.length} lines`} onPress={reveal} />\n ) : null}\n </View>\n );\n}\n\nconst styles = StyleSheet.create((theme) => ({\n row: { flexDirection: 'row', gap: theme.spacing(2) },\n fileGap: { marginTop: theme.spacing(1) },\n mono: {\n fontFamily: fontOf(theme.fontFamily.mono),\n fontSize: theme.fontSize.sm,\n lineHeight: theme.lineHeightRelaxed.sm,\n },\n content: { flex: 1, minWidth: 0 },\n marker: { color: theme.colors.blue },\n faint: { color: theme.colors.faint },\n dim: { color: theme.colors.dim },\n text: { color: theme.colors.text },\n hi: { color: theme.colors.hi },\n}));\n"],"mappings":";;;;;;;;;;;;;AAqCA,MAAMqB,2BAAuD,IAAIE,IAAI;;AAGrE,SAASC,iBAAiBN,OAAiCE,MAA0B;CACnF,MAAMK,SAASlB,cAAcN,eAAeiB,OAAOE,IAAI,GAAG,CAACF,OAAOE,IAAI,CAAC;CACvE,MAAMM,MAAMxB,kBAAkBuB,MAAM;CACpC,MAAM,CAACE,MAAMC,WAAWpB,SAA6E;CAErGF,gBAAgB;EACd,IAAIwB,OAAO;EACX,MAAMC,aAAa,IAAIC,gBAAgB;EACvC,MAAMC,uBAAO,IAAIV,IAAmC;EACpD,MAAMW,OAAOT,OAAOU,IAAI,OAAOC,UAAU;GACvC,MAAMC,UAAUrC,cAAc;IAAEoB,MAAMgB,MAAMhB;IAAMkB,MAAMF,MAAME;GAAK,CAAC;GACpE,IAAID,YAAYE,QAAW;GAC3B,MAAMC,cAAc,MAAMrC,iBAAiBiC,MAAME,MAAMD,SAASN,WAAWU,M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AOb,MAAMc,OAAOC;EAAIX,mBAAA,CAAA,CAAA;CAAC;CACnClB,OAAO;EAAE2B,OAAOb,MAAMc,OAAO5B;EAAKkB,mBAAA,CAAA,CAAA;CAAC;CACnChB,KAAK;EAAEyB,OAAOb,MAAMc,OAAO1B;EAAGgB,mBAAA,CAAA,CAAA;CAAC;CAC/B/C,MAAM;EAAEwD,OAAOb,MAAMc,OAAOzD;EAAI+C,mBAAA,CAAA,CAAA;CAAC;CACjCP,IAAI;EAAEgB,OAAOb,MAAMc,OAAOjB;EAAEO,mBAAA,CAAA,CAAA;CAAC;AAC/B,EAAE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/components/HostFilter.d.ts
|
|
2
|
+
export interface HostFilterProps {
|
|
3
|
+
hosts: readonly {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
}[];
|
|
7
|
+
/** null means All. This is presentation only, not a transport selection. */
|
|
8
|
+
value: string | null;
|
|
9
|
+
onChange: (id: string | null) => void;
|
|
10
|
+
/** Off when the choice names where something lives, so exactly one computer is always chosen. */
|
|
11
|
+
includeAll?: boolean;
|
|
12
|
+
accessibilityLabel?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Short names use the native segmented control; long names remain reachable by scrolling. */
|
|
15
|
+
export declare function HostFilter({ hosts, value, onChange, includeAll, accessibilityLabel }: HostFilterProps): import("react").JSX.Element;
|
|
16
|
+
//#endregion
|
|
17
|
+
//# sourceMappingURL=HostFilter.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HostFilter.d.mts","names":[],"sources":["../../src/components/HostFilter.tsx"],"mappings":";iBAOiB;EACf;IAAkB;IAAY;;;EAE9B;EACA,WAAW;;EAEX;EACA;;;wBAOc,aACd,OACA,OACA,UACA,YACA,sBACC,kCAAe,IAAA"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { selectionTick } from "../lib/haptics.mjs";
|
|
2
|
+
import { Button } from "./Button.mjs";
|
|
3
|
+
import { SegmentedControl } from "./SegmentedControl.mjs";
|
|
4
|
+
import { View } from "react-native-unistyles/components/native/View";
|
|
5
|
+
import { StyleSheet } from "react-native-unistyles";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import { ScrollView } from "react-native-unistyles/components/native/ScrollView";
|
|
8
|
+
|
|
9
|
+
//#region src/components/HostFilter.tsx
|
|
10
|
+
const ALL = "";
|
|
11
|
+
const MAX_SEGMENTS = 3;
|
|
12
|
+
const MAX_SEGMENT_LABEL = 12;
|
|
13
|
+
/** Short names use the native segmented control; long names remain reachable by scrolling. */
|
|
14
|
+
function HostFilter({ hosts, value, onChange, includeAll = true, accessibilityLabel = "Filter by computer" }) {
|
|
15
|
+
const options = [...includeAll ? [{
|
|
16
|
+
value: ALL,
|
|
17
|
+
label: "All"
|
|
18
|
+
}] : [], ...hosts.map(({ id, label }) => ({
|
|
19
|
+
value: id,
|
|
20
|
+
label
|
|
21
|
+
}))];
|
|
22
|
+
const selected = hosts.some(({ id }) => id === value) ? value : includeAll ? ALL : hosts[0]?.id ?? ALL;
|
|
23
|
+
if (options.length <= MAX_SEGMENTS && options.every(({ label }) => label.length <= MAX_SEGMENT_LABEL)) return /* @__PURE__ */ jsx(SegmentedControl, {
|
|
24
|
+
options,
|
|
25
|
+
value: selected,
|
|
26
|
+
onValueChange: (id) => onChange(id || null),
|
|
27
|
+
accessibilityLabel,
|
|
28
|
+
style: styles.control
|
|
29
|
+
});
|
|
30
|
+
return /* @__PURE__ */ jsx(ScrollView, {
|
|
31
|
+
horizontal: true,
|
|
32
|
+
showsHorizontalScrollIndicator: false,
|
|
33
|
+
accessibilityLabel,
|
|
34
|
+
children: /* @__PURE__ */ jsx(View, {
|
|
35
|
+
style: styles.choices,
|
|
36
|
+
children: options.map(({ value: id, label }) => /* @__PURE__ */ jsx(Button, {
|
|
37
|
+
variant: selected === id ? "subtle" : "ghost",
|
|
38
|
+
accessibilityState: { selected: selected === id },
|
|
39
|
+
style: [styles.choice, selected === id && styles.selected],
|
|
40
|
+
onPress: () => {
|
|
41
|
+
selectionTick();
|
|
42
|
+
onChange(id || null);
|
|
43
|
+
},
|
|
44
|
+
children: label
|
|
45
|
+
}, id))
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const styles = StyleSheet.create((theme) => ({
|
|
50
|
+
control: { minHeight: 44 },
|
|
51
|
+
choices: {
|
|
52
|
+
flexDirection: "row",
|
|
53
|
+
gap: theme.spacing(2),
|
|
54
|
+
uni__dependencies: [0]
|
|
55
|
+
},
|
|
56
|
+
choice: { minHeight: 44 },
|
|
57
|
+
selected: {
|
|
58
|
+
backgroundColor: theme.colors["tint-green"],
|
|
59
|
+
borderColor: theme.colors["edge-green"],
|
|
60
|
+
uni__dependencies: [0]
|
|
61
|
+
}
|
|
62
|
+
}));
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
export { HostFilter };
|
|
66
|
+
//# sourceMappingURL=HostFilter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HostFilter.mjs","names":["StyleSheet","selectionTick","Button","SegmentedControl","HostFilterProps","hosts","id","label","value","onChange","includeAll","accessibilityLabel","ALL","MAX_SEGMENTS","MAX_SEGMENT_LABEL","HostFilter","options","map","selected","some","length","every","styles","control","choices","choice","create","theme","minHeight","flexDirection","gap","spacing","uni__dependencies","backgroundColor","colors","borderColor"],"sources":["../../src/components/HostFilter.tsx"],"sourcesContent":["import { ScrollView, View } from 'react-native';\nimport { StyleSheet } from 'react-native-unistyles';\n\nimport { selectionTick } from '../lib/haptics';\nimport { Button } from './Button';\nimport { SegmentedControl } from './SegmentedControl';\n\nexport interface HostFilterProps {\n hosts: readonly { id: string; label: string }[];\n /** null means All. This is presentation only, not a transport selection. */\n value: string | null;\n onChange: (id: string | null) => void;\n /** Off when the choice names where something lives, so exactly one computer is always chosen. */\n includeAll?: boolean;\n accessibilityLabel?: string;\n}\nconst ALL = '';\nconst MAX_SEGMENTS = 3;\nconst MAX_SEGMENT_LABEL = 12;\n\n/** Short names use the native segmented control; long names remain reachable by scrolling. */\nexport function HostFilter({\n hosts,\n value,\n onChange,\n includeAll = true,\n accessibilityLabel = 'Filter by computer',\n}: HostFilterProps) {\n const options = [\n ...(includeAll ? [{ value: ALL, label: 'All' }] : []),\n ...hosts.map(({ id, label }) => ({ value: id, label })),\n ];\n const selected = hosts.some(({ id }) => id === value) ? value! : includeAll ? ALL : (hosts[0]?.id ?? ALL);\n if (options.length <= MAX_SEGMENTS && options.every(({ label }) => label.length <= MAX_SEGMENT_LABEL)) {\n return (\n <SegmentedControl\n options={options}\n value={selected}\n onValueChange={(id) => onChange(id || null)}\n accessibilityLabel={accessibilityLabel}\n style={styles.control}\n />\n );\n }\n return (\n <ScrollView horizontal showsHorizontalScrollIndicator={false} accessibilityLabel={accessibilityLabel}>\n <View style={styles.choices}>\n {options.map(({ value: id, label }) => (\n <Button\n key={id}\n variant={selected === id ? 'subtle' : 'ghost'}\n accessibilityState={{ selected: selected === id }}\n style={[styles.choice, selected === id && styles.selected]}\n onPress={() => {\n selectionTick();\n onChange(id || null);\n }}\n >\n {label}\n </Button>\n ))}\n </View>\n </ScrollView>\n );\n}\nconst styles = StyleSheet.create((theme) => ({\n control: { minHeight: 44 },\n choices: { flexDirection: 'row', gap: theme.spacing(2) },\n choice: { minHeight: 44 },\n selected: { backgroundColor: theme.colors['tint-green'], borderColor: theme.colors['edge-green'] },\n}));\n"],"mappings":";;;;;;;;;AAgBA,MAAMY,MAAM;AACZ,MAAMC,eAAe;AACrB,MAAMC,oBAAoB;;AAG1B,SAAgBC,WAAW,EACzBV,OACAG,OACAC,UACAC,aAAa,MACbC,qBAAqB,wBACH;CAClB,MAAMK,UAAU,CACd,GAAIN,aAAa,CAAC;EAAEF,OAAOI;EAAKL,OAAO;CAAM,CAAC,IAAI,CAAA,GAClD,GAAGF,MAAMY,KAAK,EAAEX,IAAIC,aAAa;EAAEC,OAAOF;EAAIC;CAAM,EAAE,CAAC;CAEzD,MAAMW,WAAWb,MAAMc,MAAM,EAAEb,SAASA,OAAOE,KAAK,IAAIA,QAASE,aAAaE,MAAOP,MAAM,EAAE,EAAEC,MAAMM;CACrG,IAAII,QAAQI,UAAUP,gBAAgBG,QAAQK,OAAO,EAAEd,YAAYA,MAAMa,UAAUN,iBAAiB,GAClG,OACE,oBAAC,kBAAD;EACWE;EACT,OAAOE;EACP,gBAAgBZ,OAAOG,SAASH,MAAM,IAAI;EACtBK;EACpB,OAAOW,OAAOC;CAAQ;CAI5B,OACE,oBAAC,YAAD;EAAY;EAAW,gCAAgC;EAA2BZ;YAChF,oBAAC,MAAD;GAAM,OAAOW,OAAOE;aACjBR,QAAQC,KAAK,EAAET,OAAOF,IAAIC,YACzB,oBAAC,QAAD;IAEE,SAASW,aAAaZ,KAAK,WAAW;IACtC,oBAAoB,EAAEY,UAAUA,aAAaZ,GAAG;IAChD,OAAO,CAACgB,OAAOG,QAAQP,aAAaZ,MAAMgB,OAAOJ,QAAQ;IACzD,eAAe;KACbjB,cAAc;KACdQ,SAASH,MAAM,IAAI;IACrB;cAECC;GACK,GAVDD,EAUC,CACT;EACG;CACI;AAEhB;AACA,MAAMgB,SAAStB,WAAW0B,QAAQC,WAAW;CAC3CJ,SAAS,EAAEK,WAAW,GAAG;CACzBJ,SAAS;EAAEK,eAAe;EAAOC,KAAKH,MAAMI,QAAQ,CAAC;EAACC,mBAAA,CAAA,CAAA;CAAC;CACvDP,QAAQ,EAAEG,WAAW,GAAG;CACxBV,UAAU;EAAEe,iBAAiBN,MAAMO,OAAO;EAAeC,aAAaR,MAAMO,OAAO;EAAaF,mBAAA,CAAA,CAAA;CAAC;AACnG,EAAE"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/components/HostTag.d.ts
|
|
2
|
+
/** A computer's display label, never an authority or connection indicator. */
|
|
3
|
+
export declare function HostTag({ label }: {
|
|
4
|
+
label: string;
|
|
5
|
+
}): import("react").JSX.Element;
|
|
6
|
+
//#endregion
|
|
7
|
+
//# sourceMappingURL=HostTag.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HostTag.d.mts","names":[],"sources":["../../src/components/HostTag.tsx"],"mappings":";;wBAQgB,UAAU;EAAW;oBAAe,IAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { fontOf } from "../lib/fonts.mjs";
|
|
2
|
+
import { agentInitials } from "./AgentAvatar.mjs";
|
|
3
|
+
import { Badge } from "./Badge.mjs";
|
|
4
|
+
import { Text } from "react-native-unistyles/components/native/Text";
|
|
5
|
+
import { StyleSheet } from "react-native-unistyles";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
|
|
8
|
+
//#region src/components/HostTag.tsx
|
|
9
|
+
/** A computer's display label, never an authority or connection indicator. */
|
|
10
|
+
function HostTag({ label }) {
|
|
11
|
+
return /* @__PURE__ */ jsxs(Badge, {
|
|
12
|
+
accessibilityLabel: `Computer: ${label}`,
|
|
13
|
+
style: styles.tag,
|
|
14
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
15
|
+
style: styles.initials,
|
|
16
|
+
children: agentInitials(label)
|
|
17
|
+
}), /* @__PURE__ */ jsx(Text, {
|
|
18
|
+
style: styles.label,
|
|
19
|
+
numberOfLines: 1,
|
|
20
|
+
children: label
|
|
21
|
+
})]
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
const styles = StyleSheet.create((theme) => ({
|
|
25
|
+
tag: {
|
|
26
|
+
maxWidth: "100%",
|
|
27
|
+
flexShrink: 1
|
|
28
|
+
},
|
|
29
|
+
initials: {
|
|
30
|
+
fontFamily: fontOf(theme.fontFamily.sans),
|
|
31
|
+
fontSize: theme.fontSize.xs,
|
|
32
|
+
color: theme.colors.dim,
|
|
33
|
+
uni__dependencies: [0]
|
|
34
|
+
},
|
|
35
|
+
label: {
|
|
36
|
+
fontFamily: fontOf(theme.fontFamily.sans),
|
|
37
|
+
fontSize: theme.fontSize.sm,
|
|
38
|
+
lineHeight: theme.lineHeight.sm,
|
|
39
|
+
color: theme.colors.dim,
|
|
40
|
+
flexShrink: 1,
|
|
41
|
+
uni__dependencies: [0]
|
|
42
|
+
}
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { HostTag };
|
|
47
|
+
//# sourceMappingURL=HostTag.mjs.map
|