@startsimpli/integrations 0.2.79 → 0.2.80

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startsimpli/integrations",
3
- "version": "0.2.79",
3
+ "version": "0.2.80",
4
4
  "description": "Provider-agnostic types, API clients, hooks, and UI primitives for email + calendar integrations across StartSimpli apps, plus foundry customer email (subpath ./comms).",
5
5
  "license": "MIT",
6
6
  "homepage": "https://startsimpli.com",
@@ -90,9 +90,9 @@
90
90
  "vitest": "^3.0.0",
91
91
  "react-native": "0.85.3",
92
92
  "react-native-safe-area-context": "~5.7.0",
93
+ "@startsimpli/ui-native": "0.1.2",
93
94
  "@startsimpli/llm": "0.4.28",
94
- "@startsimpli/ui": "0.4.167",
95
- "@startsimpli/ui-native": "0.1.2"
95
+ "@startsimpli/ui": "0.4.167"
96
96
  },
97
97
  "scripts": {
98
98
  "type-check": "tsc --noEmit && tsc --noEmit -p tsconfig.native.json",
@@ -1,8 +1,10 @@
1
- import { useMemo, useSyncExternalStore, type ReactNode } from 'react';
2
- import { View } from 'react-native';
1
+ import { useMemo, useState, useSyncExternalStore, type ReactNode } from 'react';
2
+ import { Pressable, Text, View } from 'react-native';
3
3
  import { useSafeAreaInsets } from 'react-native-safe-area-context';
4
4
  import { TabBar, useTheme, type TabItem } from '@startsimpli/ui-native';
5
5
  import { createTabsNavigator, type Route, type TabsNavigator } from '../shell/navigator';
6
+ import { DEFAULT_MAX_VISIBLE, MORE_KEY, planTabs } from '../shell/overflow';
7
+ import { MoreTabList } from './MoreTabList';
6
8
 
7
9
  /** What a tab's `render` is given. */
8
10
  export interface TabContext {
@@ -23,6 +25,10 @@ export interface FoundryTab {
23
25
  key: string;
24
26
  label: string;
25
27
  icon?: TabItem['icon'];
28
+ /** One line shown under the label when the tab sits in the More list. */
29
+ description?: string;
30
+ /** Higher stays in the bar when tabs overflow. Default 0; ties keep declared order. */
31
+ priority?: number;
26
32
  render(ctx: TabContext): ReactNode;
27
33
  /** Pad the top safe area for this tab. Default true; a screen that draws under the status bar sets false. */
28
34
  safeArea?: boolean;
@@ -32,11 +38,16 @@ export interface FoundryTab {
32
38
 
33
39
  export interface FoundryTabsShellProps {
34
40
  tabs: FoundryTab[];
41
+ /** A tab key, or `more` to open the More list. */
35
42
  initialTab?: string;
36
43
  /** Open straight on one detail (implies its tab). From a launch arg or deep link. */
37
44
  initialDetail?: { tab: string; id: string; params?: Record<string, unknown> };
38
45
  /** Drive the shell from outside (warm deep links): `navigator.open(tab, {id})`. */
39
46
  navigator?: TabsNavigator;
47
+ /** Bar slots, More included. Above this many tabs the rest go behind More. Default 5. */
48
+ maxVisible?: number;
49
+ /** Label of the overflow tab. Default "More". */
50
+ moreLabel?: string;
40
51
  }
41
52
 
42
53
  /**
@@ -44,7 +55,7 @@ export interface FoundryTabsShellProps {
44
55
  * tab is mounted the first time it is shown and then kept mounted (hidden) so
45
56
  * its state - and a recording on the GO tab - survives switching away.
46
57
  */
47
- export function FoundryTabsShell({ tabs, initialTab, initialDetail, navigator }: FoundryTabsShellProps) {
58
+ export function FoundryTabsShell({ tabs, initialTab, initialDetail, navigator, maxVisible = DEFAULT_MAX_VISIBLE, moreLabel = 'More' }: FoundryTabsShellProps) {
48
59
  const theme = useTheme();
49
60
  const insets = useSafeAreaInsets();
50
61
  const nav = useMemo(
@@ -54,10 +65,36 @@ export function FoundryTabsShell({ tabs, initialTab, initialDetail, navigator }:
54
65
  [navigator],
55
66
  );
56
67
  const state = useSyncExternalStore(nav.subscribe, nav.getState, nav.getState);
68
+ const { primary, overflow } = useMemo(() => planTabs(tabs, maxVisible), [tabs, maxVisible]);
69
+ const overflowKeys = useMemo(() => new Set(overflow.map((t) => t.key)), [overflow]);
70
+
71
+ // The More list is open while `moreAt` still matches the navigator: any navigation that changes the
72
+ // active tab or replaces its stack (a bar tap, a deep link, openTab) closes it without extra wiring.
73
+ const [moreAt, setMoreAt] = useState<{ key: string; stack: Route[] } | null>(() => {
74
+ // `initialTab: 'more'` launches on the More list itself.
75
+ const s0 = nav.getState();
76
+ return initialTab === MORE_KEY && overflow.length ? { key: s0.activeKey, stack: s0.stacks[s0.activeKey] } : null;
77
+ });
78
+ const moreOpen = overflow.length > 0 && moreAt !== null && moreAt.key === state.activeKey && moreAt.stack === state.stacks[state.activeKey];
79
+ const markMore = () => { const s = nav.getState(); setMoreAt({ key: s.activeKey, stack: s.stacks[s.activeKey] }); };
80
+ const activeTab = tabs.find((t) => t.key === state.activeKey);
81
+
82
+ const openMore = () => {
83
+ // Going to the More list is leaving the current tab.
84
+ if (activeTab?.resetOnLeave && !moreOpen) nav.open(state.activeKey, null);
85
+ markMore();
86
+ };
87
+ const choose = (key: string) => { setMoreAt(null); nav.select(key); };
88
+ const inMore = moreOpen || overflowKeys.has(state.activeKey);
89
+
90
+ const items: TabItem[] = primary.map(({ key, label, icon }) => ({ key, label, icon }));
91
+ if (overflow.length) items.push({ key: MORE_KEY, label: moreLabel });
92
+
57
93
  return (
58
94
  <View style={{ flex: 1, backgroundColor: theme.colors.background }}>
95
+ {moreOpen ? <MoreTabList tabs={overflow} title={moreLabel} onOpen={choose} /> : null}
59
96
  {tabs.filter((t) => state.visited.includes(t.key)).map((t) => {
60
- const active = t.key === state.activeKey;
97
+ const active = t.key === state.activeKey && !moreOpen;
61
98
  const route = state.stacks[t.key]?.slice(-1)[0] ?? null;
62
99
  const ctx: TabContext = {
63
100
  tab: t.key, active, route,
@@ -65,16 +102,27 @@ export function FoundryTabsShell({ tabs, initialTab, initialDetail, navigator }:
65
102
  back: () => nav.pop(t.key),
66
103
  openTab: (key, detailId) => (detailId ? nav.open(key, { id: detailId }) : nav.select(key)),
67
104
  };
105
+ // A More tab at its list gets a Back to More strip; the strip carries the top inset instead of the tab.
106
+ const strip = overflowKeys.has(t.key) && !route;
107
+ const topPad = t.safeArea === false || strip ? 0 : insets.top;
68
108
  return (
69
- <View key={t.key} style={{ flex: 1, display: active ? 'flex' : 'none', paddingTop: t.safeArea === false ? 0 : insets.top }}>
109
+ <View key={t.key} style={{ flex: 1, display: active ? 'flex' : 'none', paddingTop: topPad }}>
110
+ {strip ? (
111
+ <Pressable
112
+ testID="more-back" accessibilityRole="button" accessibilityLabel={`Back to ${moreLabel}`} onPress={openMore}
113
+ style={{ paddingTop: insets.top + theme.spacing.xs, paddingHorizontal: theme.spacing.md, paddingBottom: theme.spacing.xs }}
114
+ >
115
+ <Text numberOfLines={1} style={{ color: theme.colors.primary, fontSize: theme.fontSizes.base }}>{`\u2039 ${moreLabel}`}</Text>
116
+ </Pressable>
117
+ ) : null}
70
118
  {t.render(ctx)}
71
119
  </View>
72
120
  );
73
121
  })}
74
122
  <TabBar
75
- items={tabs.map(({ key, label, icon }) => ({ key, label, icon }))}
76
- activeKey={state.activeKey}
77
- onChange={(key) => nav.select(key)}
123
+ items={items}
124
+ activeKey={inMore ? MORE_KEY : state.activeKey}
125
+ onChange={(key) => (key === MORE_KEY ? openMore() : choose(key))}
78
126
  />
79
127
  </View>
80
128
  );
@@ -0,0 +1,35 @@
1
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
2
+ import { Pressable, ScrollView, Text, View } from 'react-native';
3
+ import { useTheme } from '@startsimpli/ui-native';
4
+ import type { FoundryTab } from './FoundryTabsShell';
5
+
6
+ /** The list behind the More tab: one row per overflow tab (icon, label, optional description). */
7
+ export function MoreTabList({ tabs, onOpen, title = 'More' }: { tabs: FoundryTab[]; onOpen(key: string): void; title?: string }) {
8
+ const theme = useTheme();
9
+ const insets = useSafeAreaInsets();
10
+ const { colors, spacing, fontSizes } = theme;
11
+ return (
12
+ <View style={{ flex: 1, backgroundColor: colors.background }} testID="more-list">
13
+ <Text accessibilityRole="header" style={{ color: colors.foreground, fontSize: fontSizes.xl, fontWeight: '700', padding: spacing.md, paddingTop: insets.top + spacing.md }}>{title}</Text>
14
+ <ScrollView>
15
+ {tabs.map((t) => (
16
+ <Pressable
17
+ key={t.key}
18
+ testID={`more-row-${t.key}`}
19
+ accessibilityRole="button"
20
+ accessibilityLabel={t.label}
21
+ onPress={() => onOpen(t.key)}
22
+ style={{ flexDirection: 'row', alignItems: 'center', gap: spacing.md, paddingHorizontal: spacing.md, paddingVertical: spacing.md, borderTopWidth: 1, borderTopColor: colors.border }}
23
+ >
24
+ {t.icon ? <View style={{ width: 28, alignItems: 'center' }}>{t.icon({ active: false, color: colors.mutedForeground })}</View> : null}
25
+ <View style={{ flex: 1 }}>
26
+ <Text numberOfLines={1} style={{ color: colors.foreground, fontSize: fontSizes.base }}>{t.label}</Text>
27
+ {t.description ? <Text numberOfLines={2} style={{ color: colors.mutedForeground, fontSize: fontSizes.sm }}>{t.description}</Text> : null}
28
+ </View>
29
+ <Text style={{ color: colors.mutedForeground, fontSize: fontSizes.lg }}>{'›'}</Text>
30
+ </Pressable>
31
+ ))}
32
+ </ScrollView>
33
+ </View>
34
+ );
35
+ }
@@ -0,0 +1,101 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import { Text } from 'react-native';
3
+ import { act, allText, hostById, maybeById, press, render } from '../../../../../ui-native/test/render';
4
+ import { FoundryTabsShell, type FoundryTab, type TabContext } from '../FoundryTabsShell';
5
+ import { createTabsNavigator } from '../../shell/navigator';
6
+
7
+ const mk = (key: string, extra: Partial<FoundryTab> = {}): FoundryTab => ({
8
+ key, label: key.toUpperCase(),
9
+ render: (ctx: TabContext) => <Text testID={`body-${key}`} onPress={() => ctx.push('d1')}>{`${key}:${ctx.route ? `detail ${ctx.route.id}` : 'list'}${ctx.active ? '' : ':hidden'}`}</Text>,
10
+ ...extra,
11
+ });
12
+ const keys = ['home', 'go', 'notes', 'tracker', 'library', 'ask', 'planning'];
13
+ const tabs = (over: Record<string, Partial<FoundryTab>> = {}) => keys.map((k) => mk(k, over[k]));
14
+ const tabNodes = (r: ReturnType<typeof render>) => r.root.findAll((n) => n.type === 'Pressable' && n.props.accessibilityRole === 'tab');
15
+ const barLabels = (r: ReturnType<typeof render>) =>
16
+ tabNodes(r).map((n) => n.findAllByType('Text').at(-1)!.children.join(''));
17
+ const selected = (r: ReturnType<typeof render>) =>
18
+ tabNodes(r).filter((n) => n.props.accessibilityState?.selected).map((n) => n.findAllByType('Text').at(-1)!.children.join(''));
19
+
20
+ describe('FoundryTabsShell overflow', () => {
21
+ it('shows 4 tabs plus More when 7 tabs exceed the default 5', () => {
22
+ const r = render(<FoundryTabsShell tabs={tabs()} />);
23
+ expect(barLabels(r)).toEqual(['HOME', 'GO', 'NOTES', 'TRACKER', 'More']);
24
+ });
25
+ it('keeps every tab in the bar when they fit', () => {
26
+ const r = render(<FoundryTabsShell tabs={tabs().slice(0, 5)} />);
27
+ expect(barLabels(r)).toEqual(['HOME', 'GO', 'NOTES', 'TRACKER', 'LIBRARY']);
28
+ });
29
+ it('maxVisible and priority choose the bar', () => {
30
+ const r = render(<FoundryTabsShell tabs={tabs({ planning: { priority: 5 } })} maxVisible={4} />);
31
+ expect(barLabels(r)).toEqual(['HOME', 'GO', 'PLANNING', 'More']);
32
+ });
33
+ it('More lists the rest with descriptions, and opening one shows its content with Back to More', () => {
34
+ const r = render(<FoundryTabsShell tabs={tabs({ ask: { description: 'Ask your documents' } })} />);
35
+ press(tabNodes(r).at(-1)!);
36
+ expect(maybeById(r, 'more-list').length).toBe(1);
37
+ expect(allText(r)).toContain('Ask your documents');
38
+ expect(selected(r)).toEqual(['More']);
39
+ press(hostById(r, 'more-row-ask'));
40
+ expect(maybeById(r, 'more-list').length).toBe(0);
41
+ expect(allText(r)).toContain('ask:list');
42
+ expect(selected(r)).toEqual(['More']);
43
+ press(hostById(r, 'more-back'));
44
+ expect(maybeById(r, 'more-list').length).toBe(1);
45
+ });
46
+ it('a More tab keeps its list->detail stack and shows no Back to More while in detail', () => {
47
+ const r = render(<FoundryTabsShell tabs={tabs()} initialDetail={{ tab: 'library', id: 'd9' }} />);
48
+ expect(allText(r)).toContain('library:detail d9');
49
+ expect(selected(r)).toEqual(['More']);
50
+ expect(maybeById(r, 'more-back').length).toBe(0);
51
+ });
52
+ it('initialTab inside More opens that tab', () => {
53
+ const r = render(<FoundryTabsShell tabs={tabs()} initialTab="planning" />);
54
+ expect(allText(r)).toContain('planning:list');
55
+ expect(selected(r)).toEqual(['More']);
56
+ });
57
+ it('initialTab "more" opens the More list', () => {
58
+ const r = render(<FoundryTabsShell tabs={tabs()} initialTab="more" />);
59
+ expect(maybeById(r, 'more-list').length).toBe(1);
60
+ expect(selected(r)).toEqual(['More']);
61
+ });
62
+ it('a warm deep link into More leaves the More list and opens the detail', () => {
63
+ const list = tabs();
64
+ const navigator = createTabsNavigator({ tabs: list });
65
+ const r = render(<FoundryTabsShell tabs={list} navigator={navigator} />);
66
+ press(tabNodes(r).at(-1)!);
67
+ expect(maybeById(r, 'more-list').length).toBe(1);
68
+ act(() => navigator.open('ask', { id: 'x' }));
69
+ expect(maybeById(r, 'more-list').length).toBe(0);
70
+ expect(allText(r)).toContain('ask:detail x');
71
+ });
72
+ it('visited tabs stay mounted, hidden', () => {
73
+ const r = render(<FoundryTabsShell tabs={tabs()} initialTab="notes" />);
74
+ press(tabNodes(r).at(-1)!);
75
+ expect(allText(r)).toContain('notes:list:hidden');
76
+ });
77
+ it('resetOnLeave pops a More tab when the user goes to a bar tab', () => {
78
+ const r = render(<FoundryTabsShell tabs={tabs({ ask: { resetOnLeave: true } })} initialDetail={{ tab: 'ask', id: 'q' }} />);
79
+ expect(allText(r)).toContain('ask:detail q');
80
+ press(tabNodes(r)[0]);
81
+ expect(allText(r)).toContain('ask:list:hidden');
82
+ });
83
+ it('resetOnLeave also resets when the user taps More from a More tab', () => {
84
+ const r = render(<FoundryTabsShell tabs={tabs({ ask: { resetOnLeave: true } })} initialDetail={{ tab: 'ask', id: 'q' }} />);
85
+ press(tabNodes(r).at(-1)!);
86
+ expect(allText(r)).toContain('ask:list:hidden');
87
+ });
88
+ it('tapping a bar tab from the More list leaves the list', () => {
89
+ const r = render(<FoundryTabsShell tabs={tabs()} />);
90
+ press(tabNodes(r).at(-1)!);
91
+ press(tabNodes(r)[0]);
92
+ expect(maybeById(r, 'more-list').length).toBe(0);
93
+ expect(allText(r)).toContain('home:list');
94
+ });
95
+ it('openTab from a tab into a More tab works', () => {
96
+ const spy = vi.fn();
97
+ const r = render(<FoundryTabsShell tabs={[...tabs().slice(0, 3), mk('tracker', { render: (c) => <Text testID="go-ask" onPress={() => { spy(); c.openTab('ask', 'd4'); }}>t</Text> }), ...tabs().slice(4)]} initialTab="tracker" />);
98
+ press(hostById(r, 'go-ask'));
99
+ expect(allText(r)).toContain('ask:detail d4');
100
+ });
101
+ });
@@ -15,6 +15,7 @@ export { NoteDetailScreen, type NoteDetailScreenProps } from './components/NoteD
15
15
  export { NotesShell, type NotesShellProps } from './components/NotesShell';
16
16
  export { FoundryTabsShell, type FoundryTab, type FoundryTabsShellProps, type TabContext } from './components/FoundryTabsShell';
17
17
  export * from './shell/navigator';
18
+ export * from './shell/overflow';
18
19
  export * from './corpus/api';
19
20
  export * from './corpus/ask';
20
21
  export * from './corpus/paged';
@@ -0,0 +1,31 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { planTabs } from '../overflow';
3
+
4
+ const tab = (key: string, priority?: number) => ({ key, ...(priority === undefined ? {} : { priority }) });
5
+ const keys = (ts: { key: string }[]) => ts.map((t) => t.key);
6
+ const nine = ['home', 'go', 'notes', 'tracker', 'library', 'ask', 'planning', 'connections', 'claude'].map((k) => tab(k));
7
+
8
+ describe('planTabs', () => {
9
+ it('shows every tab when they fit', () => {
10
+ expect(keys(planTabs(nine.slice(0, 5)).primary)).toHaveLength(5);
11
+ expect(planTabs(nine.slice(0, 5)).overflow).toEqual([]);
12
+ });
13
+ it('defaults to 5 slots: the first four plus More', () => {
14
+ const p = planTabs(nine);
15
+ expect(keys(p.primary)).toEqual(['home', 'go', 'notes', 'tracker']);
16
+ expect(keys(p.overflow)).toEqual(['library', 'ask', 'planning', 'connections', 'claude']);
17
+ });
18
+ it('honours maxVisible', () => {
19
+ expect(keys(planTabs(nine, 4).primary)).toEqual(['home', 'go', 'notes']);
20
+ expect(keys(planTabs(nine, 6).primary)).toHaveLength(5);
21
+ });
22
+ it('priority beats order, and the bar keeps declared order', () => {
23
+ const p = planTabs([tab('a'), tab('b'), tab('c', 9), tab('d'), tab('e', 5), tab('f')], 4);
24
+ expect(keys(p.primary)).toEqual(['a', 'c', 'e']);
25
+ expect(keys(p.overflow)).toEqual(['b', 'd', 'f']);
26
+ });
27
+ it('never fewer than two slots', () => {
28
+ expect(keys(planTabs(nine, 0).primary)).toHaveLength(4);
29
+ expect(keys(planTabs(nine, 1).primary)).toEqual(['home']);
30
+ });
31
+ });
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Which tabs sit in the bottom bar and which go behind a "More" tab. Pure, so
3
+ * the rule is tested without rendering.
4
+ *
5
+ * With at most `maxVisible` tabs they all show. With more, the bar shows the
6
+ * top `maxVisible - 1` tabs plus More; the rest are listed under More. "Top"
7
+ * is highest `priority` first (default 0), ties broken by array order. Both
8
+ * groups keep the order the tabs were declared in.
9
+ */
10
+ export const MORE_KEY = 'more';
11
+ export const DEFAULT_MAX_VISIBLE = 5;
12
+
13
+ export interface Rankable { key: string; priority?: number }
14
+
15
+ export function planTabs<T extends Rankable>(tabs: T[], maxVisible: number = DEFAULT_MAX_VISIBLE): { primary: T[]; overflow: T[] } {
16
+ const max = Math.max(2, Math.floor(maxVisible) || DEFAULT_MAX_VISIBLE);
17
+ if (tabs.length <= max) return { primary: tabs, overflow: [] };
18
+ const ranked = tabs
19
+ .map((tab, index) => ({ tab, index }))
20
+ .sort((a, b) => (b.tab.priority ?? 0) - (a.tab.priority ?? 0) || a.index - b.index);
21
+ const keep = new Set(ranked.slice(0, max - 1).map((r) => r.tab.key));
22
+ return { primary: tabs.filter((t) => keep.has(t.key)), overflow: tabs.filter((t) => !keep.has(t.key)) };
23
+ }