@dxos/plugin-search 0.8.4-main.c4373fc → 0.8.4-main.c85a9c8dae

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/README.md +0 -1
  2. package/dist/lib/browser/SearchDialog-E6336HCX.mjs +110 -0
  3. package/dist/lib/browser/SearchDialog-E6336HCX.mjs.map +7 -0
  4. package/dist/lib/browser/SearchMain-24ZNJB24.mjs +100 -0
  5. package/dist/lib/browser/SearchMain-24ZNJB24.mjs.map +7 -0
  6. package/dist/lib/browser/SpaceMain-IGCYHL7R.mjs +154 -0
  7. package/dist/lib/browser/SpaceMain-IGCYHL7R.mjs.map +7 -0
  8. package/dist/lib/browser/app-graph-builder-NUJ2FOVQ.mjs +82 -0
  9. package/dist/lib/browser/app-graph-builder-NUJ2FOVQ.mjs.map +7 -0
  10. package/dist/lib/browser/{chunk-5N6LDSFF.mjs → chunk-HRIWTRJV.mjs} +6 -2
  11. package/dist/lib/browser/chunk-HRIWTRJV.mjs.map +7 -0
  12. package/dist/lib/browser/chunk-I7YWQSUZ.mjs +26 -0
  13. package/dist/lib/browser/chunk-I7YWQSUZ.mjs.map +7 -0
  14. package/dist/lib/browser/chunk-NB4JZIOE.mjs +282 -0
  15. package/dist/lib/browser/chunk-NB4JZIOE.mjs.map +7 -0
  16. package/dist/lib/browser/index.mjs +52 -57
  17. package/dist/lib/browser/index.mjs.map +4 -4
  18. package/dist/lib/browser/meta.json +1 -1
  19. package/dist/lib/browser/operation-resolver-QEGN4ZKN.mjs +26 -0
  20. package/dist/lib/browser/operation-resolver-QEGN4ZKN.mjs.map +7 -0
  21. package/dist/lib/browser/react-surface-FLO4YTFP.mjs +73 -0
  22. package/dist/lib/browser/react-surface-FLO4YTFP.mjs.map +7 -0
  23. package/dist/types/src/SearchPlugin.d.ts +2 -1
  24. package/dist/types/src/SearchPlugin.d.ts.map +1 -1
  25. package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts +6 -0
  26. package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts.map +1 -0
  27. package/dist/types/src/capabilities/app-graph-builder/index.d.ts +3 -0
  28. package/dist/types/src/capabilities/app-graph-builder/index.d.ts.map +1 -0
  29. package/dist/types/src/capabilities/index.d.ts +3 -3
  30. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  31. package/dist/types/src/capabilities/operation-resolver/index.d.ts +3 -0
  32. package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +1 -0
  33. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +5 -0
  34. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -0
  35. package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
  36. package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
  37. package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
  38. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
  39. package/dist/types/src/components/index.d.ts +0 -3
  40. package/dist/types/src/components/index.d.ts.map +1 -1
  41. package/dist/types/src/constants.d.ts +2 -0
  42. package/dist/types/src/constants.d.ts.map +1 -0
  43. package/dist/types/src/{components → containers/SearchDialog}/SearchDialog.d.ts +0 -1
  44. package/dist/types/src/containers/SearchDialog/SearchDialog.d.ts.map +1 -0
  45. package/dist/types/src/containers/SearchDialog/index.d.ts +3 -0
  46. package/dist/types/src/containers/SearchDialog/index.d.ts.map +1 -0
  47. package/dist/types/src/containers/SearchMain/SearchMain.d.ts +6 -0
  48. package/dist/types/src/containers/SearchMain/SearchMain.d.ts.map +1 -0
  49. package/dist/types/src/containers/SearchMain/index.d.ts +3 -0
  50. package/dist/types/src/containers/SearchMain/index.d.ts.map +1 -0
  51. package/dist/types/src/containers/SpaceMain/SpaceMain.d.ts +6 -0
  52. package/dist/types/src/containers/SpaceMain/SpaceMain.d.ts.map +1 -0
  53. package/dist/types/src/containers/SpaceMain/index.d.ts +3 -0
  54. package/dist/types/src/containers/SpaceMain/index.d.ts.map +1 -0
  55. package/dist/types/src/containers/index.d.ts +6 -0
  56. package/dist/types/src/containers/index.d.ts.map +1 -0
  57. package/dist/types/src/hooks/index.d.ts +1 -0
  58. package/dist/types/src/hooks/index.d.ts.map +1 -1
  59. package/dist/types/src/hooks/sync.d.ts +3 -2
  60. package/dist/types/src/hooks/sync.d.ts.map +1 -1
  61. package/dist/types/src/hooks/useGlobalSearch.d.ts +7 -3
  62. package/dist/types/src/hooks/useGlobalSearch.d.ts.map +1 -1
  63. package/dist/types/src/hooks/useSearchResults.d.ts +3 -2
  64. package/dist/types/src/hooks/useSearchResults.d.ts.map +1 -1
  65. package/dist/types/src/hooks/useWebSearch.d.ts +6 -3
  66. package/dist/types/src/hooks/useWebSearch.d.ts.map +1 -1
  67. package/dist/types/src/meta.d.ts +2 -2
  68. package/dist/types/src/meta.d.ts.map +1 -1
  69. package/dist/types/src/search/exa.d.ts +3 -1
  70. package/dist/types/src/search/exa.d.ts.map +1 -1
  71. package/dist/types/src/translations.d.ts +1 -1
  72. package/dist/types/src/types/action.d.ts +13 -10
  73. package/dist/types/src/types/action.d.ts.map +1 -1
  74. package/dist/types/src/types/search.d.ts +3 -7
  75. package/dist/types/src/types/search.d.ts.map +1 -1
  76. package/dist/types/tsconfig.tsbuildinfo +1 -1
  77. package/package.json +56 -46
  78. package/src/SearchPlugin.tsx +25 -42
  79. package/src/capabilities/app-graph-builder/app-graph-builder.ts +71 -0
  80. package/src/capabilities/app-graph-builder/index.ts +7 -0
  81. package/src/capabilities/index.ts +3 -5
  82. package/src/capabilities/operation-resolver/index.ts +7 -0
  83. package/src/capabilities/operation-resolver/operation-resolver.ts +24 -0
  84. package/src/capabilities/react-surface/index.ts +7 -0
  85. package/src/capabilities/react-surface/react-surface.tsx +72 -0
  86. package/src/components/index.ts +0 -4
  87. package/src/constants.ts +7 -0
  88. package/src/containers/SearchDialog/SearchDialog.tsx +120 -0
  89. package/src/containers/SearchDialog/index.ts +7 -0
  90. package/src/containers/SearchMain/SearchMain.tsx +103 -0
  91. package/src/containers/SearchMain/index.ts +7 -0
  92. package/src/containers/SpaceMain/SpaceMain.tsx +180 -0
  93. package/src/containers/SpaceMain/index.ts +7 -0
  94. package/src/containers/index.ts +11 -0
  95. package/src/hooks/index.ts +2 -0
  96. package/src/hooks/sync.test.ts +6 -4
  97. package/src/hooks/sync.ts +25 -30
  98. package/src/hooks/useGlobalSearch.tsx +31 -12
  99. package/src/hooks/useSearchResults.ts +7 -4
  100. package/src/hooks/useWebSearch.ts +20 -9
  101. package/src/meta.ts +7 -3
  102. package/src/search/exa.test.ts +9 -11
  103. package/src/search/exa.ts +6 -5
  104. package/src/translations.ts +1 -1
  105. package/src/types/action.tsx +8 -6
  106. package/src/types/command-score.d.ts +16 -0
  107. package/src/types/search.ts +3 -9
  108. package/dist/lib/browser/app-graph-builder-YME7SN7O.mjs +0 -78
  109. package/dist/lib/browser/app-graph-builder-YME7SN7O.mjs.map +0 -7
  110. package/dist/lib/browser/chunk-5N6LDSFF.mjs.map +0 -7
  111. package/dist/lib/browser/chunk-WN3TVQLV.mjs +0 -190
  112. package/dist/lib/browser/chunk-WN3TVQLV.mjs.map +0 -7
  113. package/dist/lib/browser/chunk-YJGHPWUO.mjs +0 -21
  114. package/dist/lib/browser/chunk-YJGHPWUO.mjs.map +0 -7
  115. package/dist/lib/browser/intent-resolver-XNVR4XRX.mjs +0 -22
  116. package/dist/lib/browser/intent-resolver-XNVR4XRX.mjs.map +0 -7
  117. package/dist/lib/browser/react-surface-YOGLADC4.mjs +0 -470
  118. package/dist/lib/browser/react-surface-YOGLADC4.mjs.map +0 -7
  119. package/dist/types/src/capabilities/app-graph-builder.d.ts +0 -4
  120. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +0 -1
  121. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  122. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  123. package/dist/types/src/capabilities/react-surface.d.ts +0 -4
  124. package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
  125. package/dist/types/src/components/Search.stories.d.ts +0 -19
  126. package/dist/types/src/components/Search.stories.d.ts.map +0 -1
  127. package/dist/types/src/components/SearchDialog.d.ts.map +0 -1
  128. package/dist/types/src/components/SearchMain.d.ts +0 -7
  129. package/dist/types/src/components/SearchMain.d.ts.map +0 -1
  130. package/dist/types/src/components/SearchResults/SearchResults.d.ts +0 -20
  131. package/dist/types/src/components/SearchResults/SearchResults.d.ts.map +0 -1
  132. package/dist/types/src/components/SearchResults/SearchResults.stories.d.ts +0 -16
  133. package/dist/types/src/components/SearchResults/SearchResults.stories.d.ts.map +0 -1
  134. package/dist/types/src/components/SearchResults/index.d.ts +0 -2
  135. package/dist/types/src/components/SearchResults/index.d.ts.map +0 -1
  136. package/dist/types/src/components/Searchbar/Searchbar.d.ts +0 -14
  137. package/dist/types/src/components/Searchbar/Searchbar.d.ts.map +0 -1
  138. package/dist/types/src/components/Searchbar/Searchbar.stories.d.ts +0 -13
  139. package/dist/types/src/components/Searchbar/Searchbar.stories.d.ts.map +0 -1
  140. package/dist/types/src/components/Searchbar/index.d.ts +0 -2
  141. package/dist/types/src/components/Searchbar/index.d.ts.map +0 -1
  142. package/src/capabilities/app-graph-builder.ts +0 -80
  143. package/src/capabilities/intent-resolver.ts +0 -18
  144. package/src/capabilities/react-surface.tsx +0 -59
  145. package/src/components/Search.stories.tsx +0 -67
  146. package/src/components/SearchDialog.tsx +0 -124
  147. package/src/components/SearchMain.tsx +0 -68
  148. package/src/components/SearchResults/SearchResults.stories.tsx +0 -58
  149. package/src/components/SearchResults/SearchResults.tsx +0 -86
  150. package/src/components/SearchResults/index.ts +0 -5
  151. package/src/components/Searchbar/Searchbar.stories.tsx +0 -28
  152. package/src/components/Searchbar/Searchbar.tsx +0 -67
  153. package/src/components/Searchbar/index.ts +0 -5
@@ -0,0 +1,103 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import React, { useCallback, useMemo, useState } from 'react';
6
+
7
+ import { Surface } from '@dxos/app-framework/ui';
8
+ import { useObjectMenuItems, useObjectNavigate } from '@dxos/app-toolkit/ui';
9
+ import { Entity, Query } from '@dxos/echo';
10
+ import { Filter, type Space, useQuery } from '@dxos/react-client/echo';
11
+ import { Card, Panel, ScrollArea, Toolbar, useTranslation } from '@dxos/react-ui';
12
+ import { Menu } from '@dxos/react-ui-menu';
13
+ import { Mosaic, type MosaicStackTileComponent } from '@dxos/react-ui-mosaic';
14
+ import { SearchList } from '@dxos/react-ui-searchlist';
15
+ import { Text } from '@dxos/schema';
16
+
17
+ import { useGlobalSearch, useGlobalSearchResults, useWebSearch } from '../../hooks';
18
+ import { meta } from '../../meta';
19
+ import { type SearchResult } from '../../types';
20
+
21
+ export const SearchMain = ({ space }: { space?: Space }) => {
22
+ const { t } = useTranslation(meta.id);
23
+ const { setMatch } = useGlobalSearch();
24
+ const [query, setQuery] = useState<string>();
25
+ // TODO(burdon): Option to search across spaces.
26
+ const objects = useQuery(
27
+ space?.db,
28
+ query === undefined
29
+ ? Query.select(Filter.nothing())
30
+ : // TODO(dmaretskyi): Final version would walk the ancestry of the object until we find a non-system type.
31
+ Query.all(
32
+ Query.select(Filter.text(query, { type: 'full-text' })).select(Filter.not(Filter.type(Text.Text))),
33
+ Query.select(Filter.text(query, { type: 'full-text' }))
34
+ .select(Filter.type(Text.Text))
35
+ .referencedBy('dxos.org/type/Document', 'content'),
36
+ ),
37
+ );
38
+
39
+ const results = useGlobalSearchResults(objects);
40
+ const { results: webResults } = useWebSearch({ query });
41
+ const allResults = useMemo(
42
+ () => [...results, ...webResults].filter(({ object }) => object && Entity.getLabel(object)),
43
+ [results, webResults],
44
+ );
45
+
46
+ const handleSearch = useCallback(
47
+ (text: string) => {
48
+ setQuery(text);
49
+ setMatch?.(text);
50
+ },
51
+ [setMatch],
52
+ );
53
+
54
+ return (
55
+ <SearchList.Root onSearch={handleSearch}>
56
+ <Panel.Root className='dx-article'>
57
+ <Panel.Toolbar asChild>
58
+ <Toolbar.Root>
59
+ <SearchList.Input placeholder={t('search placeholder')} />
60
+ </Toolbar.Root>
61
+ </Panel.Toolbar>
62
+ <Panel.Content asChild>
63
+ <SearchList.Content>
64
+ <Mosaic.Container asChild>
65
+ <ScrollArea.Root orientation='vertical'>
66
+ <ScrollArea.Viewport>
67
+ <Mosaic.Stack items={allResults} getId={(result) => result.object!.id} Tile={SearchResultTile} />
68
+ </ScrollArea.Viewport>
69
+ </ScrollArea.Root>
70
+ </Mosaic.Container>
71
+ {allResults.length === 0 && <SearchList.Empty>{t('empty results message')}</SearchList.Empty>}
72
+ </SearchList.Content>
73
+ </Panel.Content>
74
+ </Panel.Root>
75
+ </SearchList.Root>
76
+ );
77
+ };
78
+
79
+ const SearchResultTile: MosaicStackTileComponent<SearchResult> = (props) => {
80
+ const data = props.data;
81
+ const object = data.object!;
82
+ const objectMenuItems = useObjectMenuItems(object);
83
+ const handleNavigate = useObjectNavigate(object);
84
+
85
+ return (
86
+ <Menu.Root>
87
+ <Card.Root key={data.id}>
88
+ <Card.Toolbar>
89
+ <Card.DragHandle />
90
+ <Card.Title onClick={handleNavigate}>
91
+ {data.label ?? (data.object && Entity.getLabel(data.object))}
92
+ </Card.Title>
93
+ {/* TODO(wittjosiah): Reconcile with Card.Menu. */}
94
+ <Menu.Trigger asChild disabled={!objectMenuItems?.length}>
95
+ <Toolbar.IconButton iconOnly variant='ghost' icon='ph--dots-three-vertical--regular' label='Actions' />
96
+ </Menu.Trigger>
97
+ <Menu.Content items={objectMenuItems} />
98
+ </Card.Toolbar>
99
+ <Surface.Surface role='card--content' data={{ subject: data.object }} limit={1} />
100
+ </Card.Root>
101
+ </Menu.Root>
102
+ );
103
+ };
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { SearchMain } from './SearchMain';
6
+
7
+ export default SearchMain;
@@ -0,0 +1,180 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import React, { useCallback, useEffect, useMemo, useState } from 'react';
6
+
7
+ import { useCapabilities, useOperationInvoker } from '@dxos/app-framework/ui';
8
+ import { AppCapabilities, LayoutOperation } from '@dxos/app-toolkit';
9
+ import { useAppGraph } from '@dxos/app-toolkit/ui';
10
+ import { Filter, Obj, Query } from '@dxos/echo';
11
+ import { Graph, Node, useActionRunner, useConnections } from '@dxos/plugin-graph';
12
+ import { type Space, useQuery } from '@dxos/react-client/echo';
13
+ import { ScrollArea, Toolbar, toLocalizedString, useTranslation } from '@dxos/react-ui';
14
+ import { Card, Panel } from '@dxos/react-ui';
15
+ import { Mosaic, type MosaicStackTileComponent } from '@dxos/react-ui-mosaic';
16
+ import { SearchList } from '@dxos/react-ui-searchlist';
17
+ import { Text } from '@dxos/schema';
18
+ import { getStyles } from '@dxos/ui-theme';
19
+
20
+ import { meta } from '../../meta';
21
+
22
+ export const SpaceMain = ({ space }: { space: Space }) => {
23
+ const { t } = useTranslation(meta.id);
24
+ const { items, handleSearch } = useSpaceItems(space);
25
+
26
+ return (
27
+ <SearchList.Root onSearch={handleSearch}>
28
+ <Panel.Root className='dx-article'>
29
+ <Panel.Toolbar asChild>
30
+ <Toolbar.Root>
31
+ <SearchList.Input placeholder={t('search placeholder')} />
32
+ </Toolbar.Root>
33
+ </Panel.Toolbar>
34
+ <Panel.Content asChild>
35
+ <SearchList.Content>
36
+ <Mosaic.Container asChild>
37
+ <ScrollArea.Root orientation='vertical'>
38
+ <ScrollArea.Viewport classNames='p-2'>
39
+ <Mosaic.Stack items={items} getId={(node) => node.id} Tile={NodeTile} />
40
+ </ScrollArea.Viewport>
41
+ </ScrollArea.Root>
42
+ </Mosaic.Container>
43
+ </SearchList.Content>
44
+ </Panel.Content>
45
+ </Panel.Root>
46
+ </SearchList.Root>
47
+ );
48
+ };
49
+
50
+ const NodeTile: MosaicStackTileComponent<Node.Node> = (props) => {
51
+ const node = props.data;
52
+ const { t } = useTranslation(meta.id);
53
+ const { graph } = useAppGraph();
54
+ const { invokeSync } = useOperationInvoker();
55
+ const runAction = useActionRunner();
56
+
57
+ const label = toLocalizedString(node.properties.label, t);
58
+ const icon = node.properties.icon ?? 'ph--placeholder--regular';
59
+ const iconHue = node.properties.iconHue;
60
+ const styles = iconHue ? getStyles(iconHue) : undefined;
61
+
62
+ const handleClick = () => {
63
+ if (Node.isAction(node)) {
64
+ // Run action if this is an action node.
65
+ const [parent] = Graph.getConnections(graph, node.id, Node.childRelation('inbound'));
66
+ if (parent) {
67
+ void runAction(node, { parent });
68
+ }
69
+ } else {
70
+ // Navigate to the node.
71
+ invokeSync(LayoutOperation.Open, { subject: [node.id] });
72
+ }
73
+ };
74
+
75
+ return (
76
+ <Card.Root fullWidth>
77
+ <Card.Toolbar>
78
+ <Card.ToolbarIconButton
79
+ variant='ghost'
80
+ label={label}
81
+ icon={icon}
82
+ iconOnly
83
+ iconClassNames={styles?.surfaceText}
84
+ />
85
+ <Card.Title onClick={handleClick}>{label}</Card.Title>
86
+ <Card.Menu />
87
+ </Card.Toolbar>
88
+ </Card.Root>
89
+ );
90
+ };
91
+
92
+ /**
93
+ * Hook to resolve metadata (icon, iconHue, etc.) for objects based on their typename.
94
+ */
95
+ // TODO(wittjosiah): Factor out.
96
+ const useMetadataResolver = () => {
97
+ const allMetadata = useCapabilities(AppCapabilities.Metadata);
98
+ return useCallback((typename: string) => allMetadata.find((m) => m.id === typename)?.metadata ?? {}, [allMetadata]);
99
+ };
100
+
101
+ /**
102
+ * Hook to get space items with search/filter support.
103
+ * Returns direct children when no query, or full-text search results when searching.
104
+ */
105
+ const useSpaceItems = (space: Space) => {
106
+ const { graph } = useAppGraph();
107
+ const [query, setQuery] = useState<string>();
108
+ const resolveMetadata = useMetadataResolver();
109
+
110
+ // Expand the space node to load its children (needed when navigating directly to a space URL).
111
+ useEffect(() => {
112
+ const frame = requestAnimationFrame(() => {
113
+ Graph.expand(graph, space.id, 'child');
114
+ });
115
+ return () => cancelAnimationFrame(frame);
116
+ }, [graph, space.id]);
117
+
118
+ // Get direct children of the space node for the default view.
119
+ const children = useConnections(graph, space.id, 'child');
120
+
121
+ const handleSearch = useCallback((text: string) => {
122
+ setQuery(text);
123
+ }, []);
124
+
125
+ // TODO(dmaretskyi): Switch back to QueryEditor once query builder is ready for production.
126
+ // Query results using full-text search.
127
+ const results = useQuery(
128
+ space.db,
129
+ query === undefined
130
+ ? Query.select(Filter.nothing())
131
+ : Query.all(
132
+ Query.select(Filter.text(query, { type: 'full-text' })).select(Filter.not(Filter.type(Text.Text))),
133
+ Query.select(Filter.text(query, { type: 'full-text' }))
134
+ .select(Filter.type(Text.Text))
135
+ .referencedBy('dxos.org/type/Document', 'content'),
136
+ ),
137
+ );
138
+
139
+ // Determine if query is empty (show default view).
140
+ const isQueryEmpty = !query?.trim();
141
+
142
+ // Filter children to those which are objects, actions with disposition 'item', or alternate-tree nodes.
143
+ const filteredChildren = useMemo(
144
+ () =>
145
+ children.filter((node) => {
146
+ // Include regular objects.
147
+ if (Obj.isObject(node.data)) {
148
+ return true;
149
+ }
150
+ // Include actions with disposition 'item'.
151
+ return Node.isAction(node) && node.properties.disposition === 'item';
152
+ }),
153
+ [children],
154
+ );
155
+
156
+ // When showing default view, use nodes (which may include actions).
157
+ // When showing search results, wrap objects in a compatible shape with resolved metadata.
158
+ const items = useMemo(() => {
159
+ if (isQueryEmpty) {
160
+ return filteredChildren;
161
+ }
162
+ // Wrap query results as pseudo-nodes for consistent rendering.
163
+ return results.map((obj) => {
164
+ const typename = Obj.getTypename(obj);
165
+ const metadata = typename ? resolveMetadata(typename) : {};
166
+ return {
167
+ id: obj.id,
168
+ type: 'search-result',
169
+ data: obj,
170
+ properties: {
171
+ label: Obj.getLabel(obj) ?? obj.id,
172
+ icon: metadata.icon ?? 'ph--placeholder--regular',
173
+ iconHue: metadata.iconHue,
174
+ },
175
+ } as Node.Node;
176
+ });
177
+ }, [isQueryEmpty, filteredChildren, results, resolveMetadata]);
178
+
179
+ return { items, handleSearch };
180
+ };
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { SpaceMain } from './SpaceMain';
6
+
7
+ export default SpaceMain;
@@ -0,0 +1,11 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { type ComponentType, lazy } from 'react';
6
+
7
+ export type { SearchDialogProps } from './SearchDialog/SearchDialog';
8
+
9
+ export const SearchDialog: ComponentType<any> = lazy(() => import('./SearchDialog'));
10
+ export const SearchMain: ComponentType<any> = lazy(() => import('./SearchMain'));
11
+ export const SpaceMain: ComponentType<any> = lazy(() => import('./SpaceMain'));
@@ -3,5 +3,7 @@
3
3
  //
4
4
 
5
5
  export * from './sync';
6
+
6
7
  export * from './useGlobalSearch';
7
8
  export * from './useSearchResults';
9
+ export * from './useWebSearch';
@@ -5,7 +5,8 @@
5
5
  import { describe, expect, test } from 'vitest';
6
6
 
7
7
  import { Client } from '@dxos/client';
8
- import { Filter, Obj, Type } from '@dxos/echo';
8
+ import { Filter, Obj } from '@dxos/echo';
9
+ import { TestSchema } from '@dxos/echo/testing';
9
10
  import { faker } from '@dxos/random';
10
11
 
11
12
  import { filterObjectsSync } from './sync';
@@ -15,7 +16,8 @@ faker.seed(1);
15
16
  // TODO(burdon): Reconcile with agent/minisearch.
16
17
 
17
18
  describe('Search', () => {
18
- test('Prefix text search', async () => {
19
+ // TODO(mykola): Fix FTS index to filter by fields.
20
+ test.skip('Prefix text search', async () => {
19
21
  const client = new Client();
20
22
  await client.initialize();
21
23
  await client.halo.createIdentity();
@@ -25,10 +27,10 @@ describe('Search', () => {
25
27
  Array.from({ length: 20 }).map((_, i) => {
26
28
  const content =
27
29
  i === 10 ? faker.lorem.sentence() + ` ${match}}. ` + faker.lorem.sentence() : faker.lorem.sentences();
28
- return space.db.add(Obj.make(Type.Expando, { title: faker.lorem.sentence(), content }));
30
+ return space.db.add(Obj.make(TestSchema.Expando, { title: faker.lorem.sentence(), content }));
29
31
  });
30
32
 
31
- const { objects } = await space.db.query(Filter.everything()).run();
33
+ const objects = await space.db.query(Filter.everything()).run();
32
34
  const results = filterObjectsSync(objects, new RegExp(match, 'i'));
33
35
  expect(results).to.have.length(1);
34
36
  });
package/src/hooks/sync.ts CHANGED
@@ -5,8 +5,8 @@
5
5
  import type * as Schema from 'effect/Schema';
6
6
  import * as SchemaAST from 'effect/SchemaAST';
7
7
 
8
- import { Obj } from '@dxos/echo';
9
- import { DataType } from '@dxos/schema';
8
+ import { type Entity, Obj } from '@dxos/echo';
9
+ import { Text } from '@dxos/schema';
10
10
 
11
11
  import { type SearchResult } from '../types';
12
12
 
@@ -39,39 +39,34 @@ const getIcon = (schema: Schema.Schema.AnyNoContext | undefined): string | undef
39
39
  export type TextFields = Record<string, string>;
40
40
 
41
41
  // TODO(thure): This returns `SearchResult[]` which is not just a narrower set of objects as the name implies.
42
- export const filterObjectsSync = <T extends Record<string, any>>(objects: T[], match?: RegExp): SearchResult[] => {
42
+ export const filterObjectsSync = <T extends Entity.Unknown>(objects: T[], match?: RegExp): SearchResult<T>[] => {
43
43
  if (!match) {
44
44
  return [];
45
45
  }
46
46
 
47
- return objects.reduce<SearchResult[]>((results, object) => {
47
+ return objects.reduce<SearchResult<T>[]>((results, object) => {
48
48
  // TODO(burdon): Hack to ignore Text objects.
49
- if (object instanceof DataType.Text) {
49
+ if (object instanceof Text.Text) {
50
50
  return results;
51
51
  }
52
52
 
53
53
  const fields = mapObjectToTextFields(object);
54
54
  Object.entries(fields).some(([, value]) => {
55
- const result = value.match(match);
56
- if (result) {
57
- // TODO(burdon): Use schema.
58
- const label = getStringProperty(object, ['label', 'name', 'title']);
59
-
60
- results.push({
61
- id: object.id,
62
- type: getIcon(Obj.getSchema(object)),
63
- label,
64
- match,
65
- // TODO(burdon): Truncate.
66
- // TODO(burdon): Issue with sketch documents.
67
- snippet: value !== label ? value : (fields.content ?? fields.description ?? undefined),
68
- object,
69
- });
70
-
71
- return true;
72
- }
55
+ // TODO(burdon): Use schema.
56
+ const label = Obj.getLabel(object as any);
57
+
58
+ results.push({
59
+ id: object.id,
60
+ type: getIcon(Obj.getSchema(object)),
61
+ label,
62
+ match,
63
+ // TODO(burdon): Truncate.
64
+ // TODO(burdon): Issue with sketch documents.
65
+ snippet: value !== label ? value : (fields.content ?? fields.description ?? undefined),
66
+ object,
67
+ });
73
68
 
74
- return false;
69
+ return true;
75
70
  });
76
71
 
77
72
  return results;
@@ -95,13 +90,13 @@ export const getStringProperty = (object: any, keys: string[]): string | undefin
95
90
  };
96
91
 
97
92
  // TODO(burdon): Filter system fields.
98
- const getKeys = (object: Record<string, unknown>): string[] => {
93
+ const getKeys = <T extends Entity.Unknown>(object: T): string[] => {
99
94
  try {
100
95
  const obj = JSON.parse(JSON.stringify(object));
101
96
  return Object.keys(obj).filter(
102
97
  (key) => key !== 'id' && key !== 'identityKey' && key[0] !== '_' && key[0] !== '@',
103
98
  ) as string[];
104
- } catch (err) {
99
+ } catch {
105
100
  // TODO(burdon): Error with TLDraw sketch.
106
101
  // Uncaught Error: Type with the name content has already been defined with a different constructor
107
102
  return [];
@@ -109,13 +104,13 @@ const getKeys = (object: Record<string, unknown>): string[] => {
109
104
  };
110
105
 
111
106
  // TODO(burdon): Use ECHO schema.
112
- export const mapObjectToTextFields = <T extends Record<string, unknown>>(object: T): TextFields => {
107
+ export const mapObjectToTextFields = <T extends Entity.Unknown>(object: T): TextFields => {
113
108
  return getKeys(object).reduce<TextFields>((fields, key) => {
114
- const value = object[key] as any;
115
- if (typeof value === 'string' || value instanceof DataType.Text) {
109
+ const value = (object as any)[key];
110
+ if (typeof value === 'string' || value instanceof Text.Text) {
116
111
  try {
117
112
  fields[key] = String(value);
118
- } catch (err) {
113
+ } catch {
119
114
  // TODO(burdon): Exception when parsing sketch document.
120
115
  }
121
116
  }
@@ -2,14 +2,19 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import React, { type PropsWithChildren, createContext, useContext, useMemo, useState } from 'react';
5
+ import React, { type PropsWithChildren, createContext, useCallback, useContext, useState } from 'react';
6
6
 
7
7
  import { raise } from '@dxos/debug';
8
+ import { type Entity } from '@dxos/echo';
9
+ import { GlobalFilterProvider } from '@dxos/react-ui-searchlist';
8
10
 
9
11
  import { type SearchResult } from '../types';
10
12
 
11
13
  import { filterObjectsSync, queryStringToMatch } from './sync';
12
14
 
15
+ // Re-export for backward compatibility.
16
+ export { useGlobalFilteredObjects, GlobalFilterProvider } from '@dxos/react-ui-searchlist';
17
+
13
18
  type SearchContextType = {
14
19
  match?: RegExp;
15
20
  setMatch?: (text?: string) => void;
@@ -17,26 +22,40 @@ type SearchContextType = {
17
22
 
18
23
  const SearchContext = createContext<SearchContextType>({});
19
24
 
25
+ /**
26
+ * Provider for global search context.
27
+ * Also provides the GlobalFilterProvider for useGlobalFilteredObjects to work.
28
+ */
20
29
  export const SearchContextProvider = ({ children }: PropsWithChildren) => {
21
30
  const [match, setMatch] = useState<RegExp>();
22
31
  const handleMatch = (text?: string) => setMatch(queryStringToMatch(text));
23
- return <SearchContext.Provider value={{ match, setMatch: handleMatch }}>{children}</SearchContext.Provider>;
32
+
33
+ // Provide a filter function for useGlobalFilteredObjects.
34
+ const filterFn = useCallback(
35
+ <T extends Entity.Any>(objects: T[]): T[] => {
36
+ if (!match) {
37
+ return objects;
38
+ }
39
+
40
+ return filterObjectsSync(objects, match)
41
+ .filter((result) => result.object)
42
+ .map((result) => result.object!);
43
+ },
44
+ [match],
45
+ );
46
+
47
+ return (
48
+ <SearchContext.Provider value={{ match, setMatch: handleMatch }}>
49
+ <GlobalFilterProvider filter={filterFn}>{children}</GlobalFilterProvider>
50
+ </SearchContext.Provider>
51
+ );
24
52
  };
25
53
 
26
54
  export const useGlobalSearch = () => {
27
55
  return useContext(SearchContext) ?? raise(new Error('Missing SearchContext.'));
28
56
  };
29
57
 
30
- export const useGlobalSearchResults = <T extends Record<string, any>>(objects?: T[]): SearchResult[] => {
58
+ export const useGlobalSearchResults = <T extends Entity.Unknown>(objects?: T[]): SearchResult<T>[] => {
31
59
  const { match } = useGlobalSearch();
32
60
  return objects && match ? filterObjectsSync(objects, match) : [];
33
61
  };
34
-
35
- export const useGlobalFilteredObjects = <T extends Record<string, any>>(objects?: T[]): T[] => {
36
- const { match } = useGlobalSearch();
37
- if (!match || !objects) {
38
- return objects ?? [];
39
- }
40
-
41
- return useMemo(() => filterObjectsSync(objects, match).map((result) => result.object), [objects, match]);
42
- };
@@ -5,12 +5,13 @@
5
5
  import { yieldOrContinue } from 'main-thread-scheduling';
6
6
  import { useEffect, useState } from 'react';
7
7
 
8
- import { DataType } from '@dxos/schema';
8
+ import { type Entity } from '@dxos/echo';
9
+ import { Text } from '@dxos/schema';
9
10
 
10
11
  // TODO(thure): Deprecate search-sync, move still-relevant utilities elsewhere (here, probably).
11
12
  import { mapObjectToTextFields, queryStringToMatch } from './sync';
12
13
 
13
- export const filterObjects = async <T extends Record<string, any>>(
14
+ export const filterObjects = async <T extends Entity.Unknown>(
14
15
  objects: T[],
15
16
  match?: RegExp,
16
17
  ): Promise<Map<T, string[][]>> => {
@@ -18,9 +19,10 @@ export const filterObjects = async <T extends Record<string, any>>(
18
19
  if (!match) {
19
20
  return result;
20
21
  }
22
+
21
23
  await Promise.all(
22
24
  objects
23
- .filter((object) => !(object instanceof DataType.Text))
25
+ .filter((object) => !(object instanceof Text.Text))
24
26
  .map(async (object) => {
25
27
  await yieldOrContinue('interactive');
26
28
  const fields = mapObjectToTextFields<T>(object);
@@ -34,10 +36,11 @@ export const filterObjects = async <T extends Record<string, any>>(
34
36
  });
35
37
  }),
36
38
  );
39
+
37
40
  return result;
38
41
  };
39
42
 
40
- export const useSearchResults = <T extends Record<string, any>>(
43
+ export const useSearchResults = <T extends Entity.Unknown>(
41
44
  queryString?: string,
42
45
  objects?: T[],
43
46
  delay: number = 400,
@@ -2,32 +2,44 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { useState } from 'react';
5
+ import { useCallback, useState } from 'react';
6
6
 
7
7
  import { EXA_API_KEY } from '@dxos/ai/testing';
8
8
  import { Obj } from '@dxos/echo';
9
- import { type DXN } from '@dxos/keys';
10
9
  import { log } from '@dxos/log';
11
10
  import { getIconAnnotation } from '@dxos/schema';
12
- import { Testing } from '@dxos/schema/testing';
11
+ import { TestSchema } from '@dxos/schema/testing';
13
12
 
14
13
  import { search } from '../search';
15
14
  import { type SearchResult } from '../types';
16
15
 
17
16
  import { getStringProperty } from './sync';
18
17
 
19
- export const useWebSearch = ({ query, context }: { query?: string; context?: string }) => {
18
+ export type UseWebSearchProps = {
19
+ query?: string;
20
+ context?: string;
21
+ };
22
+
23
+ export type UseWebSearch = {
24
+ update: () => Promise<void>;
25
+ results: SearchResult[];
26
+ isLoading: boolean;
27
+ };
28
+
29
+ /** @deprecated */
30
+ // TODO(burdon): Remove testing deps.
31
+ export const useWebSearch = ({ query, context }: UseWebSearchProps): UseWebSearch => {
20
32
  const [results, setResults] = useState<SearchResult[]>([]);
21
33
  const [isLoading, setIsLoading] = useState(false);
22
34
 
23
- const runSearch = async () => {
35
+ const update = useCallback(async () => {
24
36
  try {
25
37
  setIsLoading(true);
26
38
  log.info('Running web search', { query, context });
27
39
  const results = await search({
28
40
  query,
29
41
  context,
30
- schema: [Testing.Project, Testing.Organization, Testing.Contact],
42
+ schema: [TestSchema.Person, TestSchema.Project, TestSchema.Organization], // TODO(burdon): ???
31
43
  exaApiKey: EXA_API_KEY,
32
44
  });
33
45
 
@@ -35,7 +47,6 @@ export const useWebSearch = ({ query, context }: { query?: string; context?: str
35
47
  const schema = Obj.getSchema(result);
36
48
  return {
37
49
  id: result.id,
38
- objectType: Obj.getTypename(result) as DXN.String | undefined,
39
50
  label: getStringProperty(result, ['name', 'title', 'label']),
40
51
  snippet: getStringProperty(result, ['description', 'content', 'website', 'email']),
41
52
  object: result,
@@ -47,7 +58,7 @@ export const useWebSearch = ({ query, context }: { query?: string; context?: str
47
58
  } finally {
48
59
  setIsLoading(false);
49
60
  }
50
- };
61
+ }, [query, context]);
51
62
 
52
- return { runSearch, results, isLoading };
63
+ return { update, results, isLoading };
53
64
  };
package/src/meta.ts CHANGED
@@ -2,12 +2,16 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { type PluginMeta } from '@dxos/app-framework';
5
+ import { type Plugin } from '@dxos/app-framework';
6
+ import { trim } from '@dxos/util';
6
7
 
7
- export const meta: PluginMeta = {
8
+ export const meta: Plugin.Meta = {
8
9
  id: 'dxos.org/plugin/search',
9
10
  name: 'Search',
10
- description: 'Search ECHO spaces for content.',
11
+ description: trim`
12
+ Full-text search engine for finding content across all spaces and object types.
13
+ Quickly locate documents, tables, and other objects with instant results and relevance ranking.
14
+ `,
11
15
  icon: 'ph--magnifying-glass--regular',
12
16
  source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-search',
13
17
  tags: ['labs'],