@dxos/plugin-search 0.8.4-main.fffef41 → 0.8.4-staging.60fe92afc8

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 (198) hide show
  1. package/LICENSE +102 -5
  2. package/PLUGIN.mdl +291 -0
  3. package/README.md +0 -1
  4. package/dist/lib/neutral/SearchArticle-CQMZ46ZS.mjs +51 -0
  5. package/dist/lib/neutral/SearchArticle-CQMZ46ZS.mjs.map +7 -0
  6. package/dist/lib/neutral/SearchDialog-IFMA5UP5.mjs +76 -0
  7. package/dist/lib/neutral/SearchDialog-IFMA5UP5.mjs.map +7 -0
  8. package/dist/lib/neutral/SearchPlugin.mjs +10 -0
  9. package/dist/lib/neutral/SearchPlugin.mjs.map +7 -0
  10. package/dist/lib/neutral/app-graph-builder-ADB5LBS5.mjs +71 -0
  11. package/dist/lib/neutral/app-graph-builder-ADB5LBS5.mjs.map +7 -0
  12. package/dist/lib/neutral/capabilities/index.mjs +13 -0
  13. package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
  14. package/dist/lib/neutral/chunk-2XHA22US.mjs +9 -0
  15. package/dist/lib/neutral/chunk-2XHA22US.mjs.map +7 -0
  16. package/dist/lib/neutral/chunk-BST37VRI.mjs +34 -0
  17. package/dist/lib/neutral/chunk-BST37VRI.mjs.map +7 -0
  18. package/dist/lib/neutral/chunk-GT3AGVU6.mjs +28 -0
  19. package/dist/lib/neutral/chunk-GT3AGVU6.mjs.map +7 -0
  20. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  21. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
  22. package/dist/lib/{browser/chunk-ZEP4O5SU.mjs → neutral/chunk-M7FWWQKQ.mjs} +67 -76
  23. package/dist/lib/neutral/chunk-M7FWWQKQ.mjs.map +7 -0
  24. package/dist/lib/neutral/chunk-Q2F6YOOZ.mjs +41 -0
  25. package/dist/lib/neutral/chunk-Q2F6YOOZ.mjs.map +7 -0
  26. package/dist/lib/neutral/chunk-TN4G3MZZ.mjs +8 -0
  27. package/dist/lib/neutral/chunk-TN4G3MZZ.mjs.map +7 -0
  28. package/dist/lib/neutral/components/index.mjs +97 -0
  29. package/dist/lib/neutral/components/index.mjs.map +7 -0
  30. package/dist/lib/neutral/containers/index.mjs +11 -0
  31. package/dist/lib/neutral/containers/index.mjs.map +7 -0
  32. package/dist/lib/neutral/hooks/index.mjs +30 -0
  33. package/dist/lib/neutral/hooks/index.mjs.map +7 -0
  34. package/dist/lib/neutral/index.mjs +40 -0
  35. package/dist/lib/neutral/index.mjs.map +7 -0
  36. package/dist/lib/neutral/meta.json +1 -0
  37. package/dist/lib/neutral/meta.mjs +10 -0
  38. package/dist/lib/neutral/meta.mjs.map +7 -0
  39. package/dist/lib/neutral/open-search-Y6OUELN3.mjs +23 -0
  40. package/dist/lib/neutral/open-search-Y6OUELN3.mjs.map +7 -0
  41. package/dist/lib/neutral/operation-handler-DY624P2R.mjs +13 -0
  42. package/dist/lib/neutral/operation-handler-DY624P2R.mjs.map +7 -0
  43. package/dist/lib/neutral/operations/index.mjs +8 -0
  44. package/dist/lib/neutral/operations/index.mjs.map +7 -0
  45. package/dist/lib/neutral/plugin.mjs +16 -0
  46. package/dist/lib/neutral/plugin.mjs.map +7 -0
  47. package/dist/lib/neutral/react-surface-3IXL3EOJ.mjs +61 -0
  48. package/dist/lib/neutral/react-surface-3IXL3EOJ.mjs.map +7 -0
  49. package/dist/lib/neutral/testing.mjs +8 -0
  50. package/dist/lib/neutral/testing.mjs.map +7 -0
  51. package/dist/lib/neutral/translations.mjs +25 -0
  52. package/dist/lib/neutral/translations.mjs.map +7 -0
  53. package/dist/lib/neutral/types/index.mjs +8 -0
  54. package/dist/lib/neutral/types/index.mjs.map +7 -0
  55. package/dist/types/src/SearchPlugin.d.ts +3 -1
  56. package/dist/types/src/SearchPlugin.d.ts.map +1 -1
  57. package/dist/types/src/capabilities/app-graph-builder.d.ts +4 -2
  58. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
  59. package/dist/types/src/capabilities/index.d.ts +5 -3
  60. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  61. package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
  62. package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
  63. package/dist/types/src/capabilities/react-surface.d.ts +3 -2
  64. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  65. package/dist/types/src/components/SearchResultStack/SearchResultStack.d.ts +9 -0
  66. package/dist/types/src/components/SearchResultStack/SearchResultStack.d.ts.map +1 -0
  67. package/dist/types/src/components/SearchResultStack/index.d.ts +2 -0
  68. package/dist/types/src/components/SearchResultStack/index.d.ts.map +1 -0
  69. package/dist/types/src/components/index.d.ts +1 -3
  70. package/dist/types/src/components/index.d.ts.map +1 -1
  71. package/dist/types/src/constants.d.ts +3 -0
  72. package/dist/types/src/constants.d.ts.map +1 -0
  73. package/dist/types/src/containers/SearchArticle/SearchArticle.d.ts +4 -0
  74. package/dist/types/src/containers/SearchArticle/SearchArticle.d.ts.map +1 -0
  75. package/dist/types/src/{components/Searchbar/Searchbar.stories.d.ts → containers/SearchArticle/SearchArticle.stories.d.ts} +3 -2
  76. package/dist/types/src/containers/SearchArticle/SearchArticle.stories.d.ts.map +1 -0
  77. package/dist/types/src/containers/SearchArticle/index.d.ts +2 -0
  78. package/dist/types/src/containers/SearchArticle/index.d.ts.map +1 -0
  79. package/dist/types/src/containers/SearchDialog/SearchDialog.d.ts +7 -0
  80. package/dist/types/src/containers/SearchDialog/SearchDialog.d.ts.map +1 -0
  81. package/dist/types/src/{components/SearchResults/SearchResults.stories.d.ts → containers/SearchDialog/SearchDialog.stories.d.ts} +4 -4
  82. package/dist/types/src/containers/SearchDialog/SearchDialog.stories.d.ts.map +1 -0
  83. package/dist/types/src/containers/SearchDialog/index.d.ts +2 -0
  84. package/dist/types/src/containers/SearchDialog/index.d.ts.map +1 -0
  85. package/dist/types/src/containers/index.d.ts +4 -0
  86. package/dist/types/src/containers/index.d.ts.map +1 -0
  87. package/dist/types/src/hooks/sync.d.ts +4 -3
  88. package/dist/types/src/hooks/sync.d.ts.map +1 -1
  89. package/dist/types/src/hooks/useGlobalSearch.d.ts +8 -4
  90. package/dist/types/src/hooks/useGlobalSearch.d.ts.map +1 -1
  91. package/dist/types/src/hooks/useSearchResults.d.ts +3 -2
  92. package/dist/types/src/hooks/useSearchResults.d.ts.map +1 -1
  93. package/dist/types/src/hooks/useWebSearch.d.ts +7 -4
  94. package/dist/types/src/hooks/useWebSearch.d.ts.map +1 -1
  95. package/dist/types/src/index.d.ts +0 -1
  96. package/dist/types/src/index.d.ts.map +1 -1
  97. package/dist/types/src/meta.d.ts +2 -2
  98. package/dist/types/src/meta.d.ts.map +1 -1
  99. package/dist/types/src/operations/index.d.ts +3 -0
  100. package/dist/types/src/operations/index.d.ts.map +1 -0
  101. package/dist/types/src/operations/open-search.d.ts +5 -0
  102. package/dist/types/src/operations/open-search.d.ts.map +1 -0
  103. package/dist/types/src/plugin.d.ts +4 -0
  104. package/dist/types/src/plugin.d.ts.map +1 -0
  105. package/dist/types/src/search/exa.d.ts +5 -4
  106. package/dist/types/src/search/exa.d.ts.map +1 -1
  107. package/dist/types/src/testing.d.ts +2 -0
  108. package/dist/types/src/testing.d.ts.map +1 -0
  109. package/dist/types/src/translations.d.ts +15 -10
  110. package/dist/types/src/translations.d.ts.map +1 -1
  111. package/dist/types/src/types/SearchOperation.d.ts +3 -0
  112. package/dist/types/src/types/SearchOperation.d.ts.map +1 -0
  113. package/dist/types/src/types/index.d.ts +1 -1
  114. package/dist/types/src/types/index.d.ts.map +1 -1
  115. package/dist/types/src/types/search.d.ts +1 -20
  116. package/dist/types/src/types/search.d.ts.map +1 -1
  117. package/dist/types/tsconfig.tsbuildinfo +1 -1
  118. package/package.json +115 -50
  119. package/src/SearchPlugin.tsx +19 -46
  120. package/src/capabilities/app-graph-builder.ts +55 -69
  121. package/src/capabilities/index.ts +8 -4
  122. package/src/capabilities/operation-handler.ts +16 -0
  123. package/src/capabilities/react-surface.tsx +65 -49
  124. package/src/components/SearchResultStack/SearchResultStack.tsx +118 -0
  125. package/src/components/SearchResultStack/index.ts +5 -0
  126. package/src/components/index.ts +1 -3
  127. package/src/constants.ts +9 -0
  128. package/src/containers/SearchArticle/SearchArticle.stories.tsx +79 -0
  129. package/src/containers/SearchArticle/SearchArticle.tsx +60 -0
  130. package/src/containers/SearchArticle/index.ts +5 -0
  131. package/src/containers/SearchDialog/SearchDialog.stories.tsx +108 -0
  132. package/src/containers/SearchDialog/SearchDialog.tsx +93 -0
  133. package/src/containers/SearchDialog/index.ts +5 -0
  134. package/src/containers/index.ts +8 -0
  135. package/src/hooks/sync.test.ts +9 -7
  136. package/src/hooks/sync.ts +31 -33
  137. package/src/hooks/useGlobalSearch.tsx +32 -13
  138. package/src/hooks/useSearchResults.ts +6 -3
  139. package/src/hooks/useWebSearch.ts +25 -14
  140. package/src/index.ts +2 -2
  141. package/src/meta.ts +25 -7
  142. package/src/operations/index.ts +7 -0
  143. package/src/operations/open-search.ts +24 -0
  144. package/src/plugin.ts +11 -0
  145. package/src/search/exa.test.ts +7 -7
  146. package/src/search/exa.ts +16 -15
  147. package/src/testing.ts +7 -0
  148. package/src/translations.ts +10 -9
  149. package/src/types/SearchOperation.ts +20 -0
  150. package/src/types/command-score.d.ts +16 -0
  151. package/src/types/index.ts +2 -1
  152. package/src/types/search.ts +1 -25
  153. package/src/vite-env.d.ts +10 -0
  154. package/dist/lib/browser/app-graph-builder-HQR6P4C7.mjs +0 -78
  155. package/dist/lib/browser/app-graph-builder-HQR6P4C7.mjs.map +0 -7
  156. package/dist/lib/browser/chunk-GN2FSWTM.mjs +0 -22
  157. package/dist/lib/browser/chunk-GN2FSWTM.mjs.map +0 -7
  158. package/dist/lib/browser/chunk-TCVYYI44.mjs +0 -21
  159. package/dist/lib/browser/chunk-TCVYYI44.mjs.map +0 -7
  160. package/dist/lib/browser/chunk-ZEP4O5SU.mjs.map +0 -7
  161. package/dist/lib/browser/index.mjs +0 -112
  162. package/dist/lib/browser/index.mjs.map +0 -7
  163. package/dist/lib/browser/intent-resolver-UYQA6UUQ.mjs +0 -22
  164. package/dist/lib/browser/intent-resolver-UYQA6UUQ.mjs.map +0 -7
  165. package/dist/lib/browser/meta.json +0 -1
  166. package/dist/lib/browser/react-surface-LV7ZVI2K.mjs +0 -293
  167. package/dist/lib/browser/react-surface-LV7ZVI2K.mjs.map +0 -7
  168. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  169. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  170. package/dist/types/src/components/Search.stories.d.ts +0 -16
  171. package/dist/types/src/components/Search.stories.d.ts.map +0 -1
  172. package/dist/types/src/components/SearchDialog.d.ts +0 -7
  173. package/dist/types/src/components/SearchDialog.d.ts.map +0 -1
  174. package/dist/types/src/components/SearchMain.d.ts +0 -6
  175. package/dist/types/src/components/SearchMain.d.ts.map +0 -1
  176. package/dist/types/src/components/SearchResults/SearchResults.d.ts +0 -20
  177. package/dist/types/src/components/SearchResults/SearchResults.d.ts.map +0 -1
  178. package/dist/types/src/components/SearchResults/SearchResults.stories.d.ts.map +0 -1
  179. package/dist/types/src/components/SearchResults/index.d.ts +0 -2
  180. package/dist/types/src/components/SearchResults/index.d.ts.map +0 -1
  181. package/dist/types/src/components/Searchbar/Searchbar.d.ts +0 -10
  182. package/dist/types/src/components/Searchbar/Searchbar.d.ts.map +0 -1
  183. package/dist/types/src/components/Searchbar/Searchbar.stories.d.ts.map +0 -1
  184. package/dist/types/src/components/Searchbar/index.d.ts +0 -2
  185. package/dist/types/src/components/Searchbar/index.d.ts.map +0 -1
  186. package/dist/types/src/types/action.d.ts +0 -13
  187. package/dist/types/src/types/action.d.ts.map +0 -1
  188. package/src/capabilities/intent-resolver.ts +0 -18
  189. package/src/components/Search.stories.tsx +0 -64
  190. package/src/components/SearchDialog.tsx +0 -136
  191. package/src/components/SearchMain.tsx +0 -59
  192. package/src/components/SearchResults/SearchResults.stories.tsx +0 -59
  193. package/src/components/SearchResults/SearchResults.tsx +0 -83
  194. package/src/components/SearchResults/index.ts +0 -5
  195. package/src/components/Searchbar/Searchbar.stories.tsx +0 -28
  196. package/src/components/Searchbar/Searchbar.tsx +0 -48
  197. package/src/components/Searchbar/index.ts +0 -5
  198. package/src/types/action.tsx +0 -16
@@ -1,136 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import * as Option from 'effect/Option';
6
- import React, { forwardRef, useCallback, useState } from 'react';
7
-
8
- import { LayoutAction, createIntent } from '@dxos/app-framework';
9
- import { useAppGraph, useIntentDispatcher, useLayout } from '@dxos/app-framework/react';
10
- import { Obj } from '@dxos/echo';
11
- import { type Node } from '@dxos/plugin-graph';
12
- import { useClient } from '@dxos/react-client';
13
- import { Filter, useQuery } from '@dxos/react-client/echo';
14
- import { Button, Dialog, Icon, toLocalizedString, useTranslation } from '@dxos/react-ui';
15
- import { SearchList, type SearchListItemProps } from '@dxos/react-ui-searchlist';
16
- import { descriptionText, mx } from '@dxos/react-ui-theme';
17
-
18
- import { useSearchResults } from '../hooks';
19
- import { meta } from '../meta';
20
-
21
- export const SEARCH_DIALOG = `${meta.id}/SearchDialog`;
22
-
23
- type SearchListResultProps = {
24
- node: Node;
25
- } & Pick<SearchListItemProps, 'onSelect'>;
26
-
27
- const SearchListResult = forwardRef<HTMLDivElement, SearchListResultProps>(({ node, onSelect }, forwardedRef) => {
28
- const { t } = useTranslation(meta.id);
29
- const label = toLocalizedString(node?.properties.label ?? 'never', t);
30
- return (
31
- <SearchList.Item
32
- value={label}
33
- key={node!.id}
34
- classNames='flex gap-2 items-center pli-2'
35
- onSelect={() => onSelect?.(node!.id)}
36
- ref={forwardedRef}
37
- >
38
- <Icon size={5} icon={node?.properties.icon} />
39
- <span className='is-0 grow truncate'>{label}</span>
40
- </SearchList.Item>
41
- );
42
- });
43
-
44
- export type SearchDialogProps = {
45
- pivotId: string;
46
- };
47
-
48
- export const SearchDialog = ({ pivotId }: SearchDialogProps) => {
49
- const { t } = useTranslation(meta.id);
50
- const { graph } = useAppGraph();
51
- const layout = useLayout();
52
- const closed = (Array.isArray(layout.inactive) ? layout.inactive : [layout.inactive])
53
- .map((id) => graph?.getNode(id))
54
- .filter(Boolean);
55
- const [queryString, setQueryString] = useState('');
56
- const client = useClient();
57
- const dangerouslyLoadAllObjects = useQuery(client.spaces, Filter.everything());
58
- const [pending, results] = useSearchResults(queryString, dangerouslyLoadAllObjects);
59
- const resultObjects = Array.from(results.keys());
60
- const { dispatchPromise: dispatch } = useIntentDispatcher();
61
-
62
- const handleSelect = useCallback(
63
- async (nodeId: string) => {
64
- await dispatch(
65
- createIntent(LayoutAction.UpdateDialog, {
66
- part: 'dialog',
67
- options: { state: false },
68
- }),
69
- );
70
-
71
- // If node is already present in the active parts, scroll to it and close the dialog.
72
- const index = layout.active.findIndex((id) => id === nodeId);
73
- if (index !== -1) {
74
- await dispatch(
75
- createIntent(LayoutAction.ScrollIntoView, {
76
- part: 'current',
77
- subject: nodeId,
78
- }),
79
- );
80
- } else {
81
- await dispatch(
82
- createIntent(LayoutAction.Open, {
83
- part: 'main',
84
- subject: [nodeId],
85
- options: {
86
- pivotId,
87
- positioning: 'end',
88
- },
89
- }),
90
- );
91
- }
92
- },
93
- [pivotId, dispatch, layout],
94
- );
95
-
96
- return (
97
- <Dialog.Content classNames={['md:max-is-[24rem] overflow-hidden mbs-12']}>
98
- <Dialog.Title>{t('search dialog title')}</Dialog.Title>
99
- <SearchList.Root label={t('search placeholder')} classNames='flex flex-col grow overflow-hidden my-2'>
100
- <SearchList.Input
101
- value={queryString}
102
- onValueChange={(nextValue) => {
103
- setQueryString(nextValue);
104
- }}
105
- placeholder={t('search placeholder')}
106
- classNames='pli-1 my-2'
107
- />
108
- <SearchList.Content classNames='max-bs-[24rem] overflow-auto'>
109
- {queryString.length > 0 ? (
110
- resultObjects.length > 0 ? (
111
- resultObjects
112
- .map((object) => graph.getNode(Obj.getDXN(object).toString()))
113
- .filter(Option.isSome)
114
- .map((node) => <SearchListResult key={node.value.id} node={node.value} onSelect={handleSelect} />)
115
- ) : (
116
- <p className='pli-1'>{t(pending ? 'pending results message' : 'empty results message')}</p>
117
- )
118
- ) : (
119
- <>
120
- {closed.length > 0 && <h2 className={mx('mlb-1', descriptionText)}>{t('recently closed heading')}</h2>}
121
- {closed.filter(Option.isSome).map((node) => (
122
- <SearchListResult key={node.value.id} node={node.value} onSelect={handleSelect} />
123
- ))}
124
- </>
125
- )}
126
- </SearchList.Content>
127
- </SearchList.Root>
128
-
129
- <Dialog.Close asChild>
130
- <Button variant='primary' classNames='mbs-2'>
131
- {t('close label', { ns: 'os' })}
132
- </Button>
133
- </Dialog.Close>
134
- </Dialog.Content>
135
- );
136
- };
@@ -1,59 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import React, { useState } from 'react';
6
-
7
- import { useClient } from '@dxos/react-client';
8
- import { Filter, type Space, useQuery } from '@dxos/react-client/echo';
9
- import { useTranslation } from '@dxos/react-ui';
10
- import { StackItem } from '@dxos/react-ui-stack';
11
- import { mx } from '@dxos/react-ui-theme';
12
-
13
- import { useGlobalSearch, useGlobalSearchResults, useWebSearch } from '../hooks';
14
- import { meta } from '../meta';
15
-
16
- import { Searchbar } from './Searchbar';
17
- import { SearchResults } from './SearchResults';
18
-
19
- export const SearchMain = ({ space }: { space?: Space }) => {
20
- const { t } = useTranslation(meta.id);
21
- const client = useClient();
22
- const { setMatch } = useGlobalSearch();
23
- const [query, setQuery] = useState<string>();
24
- // TODO(burdon): Option to search across spaces.
25
- const allSpaces = false;
26
- const objects = useQuery(allSpaces ? client.spaces : space, Filter.everything());
27
- const results = useGlobalSearchResults(objects);
28
-
29
- const { runSearch, results: webResults } = useWebSearch({ query });
30
-
31
- // TODO(burdon): Activate and/or filter current main (set context).
32
- const [selected, setSelected] = useState<string>();
33
- const handleSelect = (id: string) => {
34
- setSelected((selected) => (selected === id ? undefined : id));
35
- };
36
-
37
- const allResults = [...results, ...webResults];
38
-
39
- return (
40
- <StackItem.Content toolbar>
41
- <Searchbar
42
- classNames='pli-2'
43
- placeholder={t('search placeholder')}
44
- delay={300}
45
- onChange={(text) => {
46
- setQuery(text);
47
- setMatch?.(text);
48
- }}
49
- onSubmit={runSearch}
50
- />
51
-
52
- {allResults.length > 0 && (
53
- <div className={mx('flex flex-col bs-full overflow-hidden')}>
54
- <SearchResults items={allResults} selected={selected} onSelect={handleSelect} />
55
- </div>
56
- )}
57
- </StackItem.Content>
58
- );
59
- };
@@ -1,59 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { type Meta, type StoryObj } from '@storybook/react-vite';
6
- import React, { useState } from 'react';
7
-
8
- import { withPluginManager } from '@dxos/app-framework/testing';
9
- import { faker } from '@dxos/random';
10
- import { withTheme } from '@dxos/react-ui/testing';
11
-
12
- import { filterObjectsSync } from '../../hooks';
13
-
14
- import { SearchResults, type SearchResultsProps } from './SearchResults';
15
-
16
- faker.seed(1);
17
-
18
- const DefaultStory = (props: SearchResultsProps) => {
19
- const [selected, setSelected] = useState<string>();
20
-
21
- return (
22
- <div className='flex grow justify-center overflow-hidden'>
23
- <div className='flex is-[300px] m-4 overflow-hidden'>
24
- <SearchResults {...props} selected={selected} onSelect={setSelected} />
25
- </div>
26
- </div>
27
- );
28
- };
29
-
30
- const word = 'hello';
31
-
32
- const objects = Array.from({ length: 100 }).map((_, i) => ({
33
- id: faker.string.uuid(),
34
- name: faker.lorem.sentence(4),
35
- content: faker.lorem.sentence() + ` ${word} ` + faker.lorem.sentence(),
36
- }));
37
-
38
- const match = new RegExp(word, 'i');
39
-
40
- const meta = {
41
- title: 'plugins/plugin-search/SearchResults',
42
- component: SearchResults,
43
- render: DefaultStory,
44
- decorators: [withTheme, withPluginManager({ plugins: [] })],
45
- parameters: {
46
- layout: 'fullscreen',
47
- },
48
- } satisfies Meta<typeof SearchResults>;
49
-
50
- export default meta;
51
-
52
- type Story = StoryObj<typeof meta>;
53
-
54
- export const Default: Story = {
55
- args: {
56
- items: filterObjectsSync(objects, match),
57
- match,
58
- },
59
- };
@@ -1,83 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import React, { type FC, forwardRef } from 'react';
6
-
7
- import { Surface } from '@dxos/app-framework/react';
8
- import { Obj } from '@dxos/echo';
9
- import { Card } from '@dxos/react-ui-stack';
10
- import { ghostHover } from '@dxos/react-ui-theme';
11
-
12
- import { type SearchResult } from '../../types';
13
-
14
- export type SearchResultsProps = {
15
- items: SearchResult[];
16
- match?: RegExp;
17
- selected?: string;
18
- onSelect?: (id: string) => void;
19
- };
20
-
21
- // TODO(burdon): Key cursor up/down.
22
- // TODO(burdon): Use stack (should be virtualized).
23
- export const SearchResults = ({ items }: SearchResultsProps) => {
24
- return (
25
- <div className='overflow-y-auto'>
26
- <div className='flex flex-col'>
27
- {items
28
- // TODO(burdon): Hack to reduce noise from system objects.
29
- .filter((item) => Obj.getLabel(item.object))
30
- .map((item) => (
31
- <div key={item.id} role='none' className='pli-2 first:pbs-2 pbe-2'>
32
- <Surface role='card' data={{ subject: item.object }} limit={1} />
33
- </div>
34
- ))}
35
- </div>
36
- </div>
37
- );
38
- };
39
-
40
- export type SearchItemProps = SearchResult & { selected: boolean } & Pick<SearchResultsProps, 'onSelect'>;
41
-
42
- export const SearchItem = forwardRef<HTMLDivElement, SearchItemProps>((item, forwardRef) => {
43
- const { id, objectType, label, snippet, match, selected, onSelect } = item;
44
-
45
- return (
46
- <Card.StaticRoot
47
- ref={forwardRef}
48
- classNames={['mx-2 mt-2 cursor-pointer', selected && '!bg-activeSurface', ghostHover]}
49
- onClick={() => onSelect?.(id)}
50
- >
51
- {objectType && <div className='text-xs text-neutral-400 ml-4'>{objectType}</div>}
52
- <Card.Heading>{label ?? 'Untitled'}</Card.Heading>
53
- {snippet && <Snippet text={snippet} match={match} />}
54
- </Card.StaticRoot>
55
- );
56
- });
57
-
58
- export const Snippet: FC<{ text: string; match?: RegExp }> = ({ text, match }) => {
59
- let content = <>{text}</>;
60
- if (match) {
61
- const result = text.match(match);
62
- if (result?.index !== undefined) {
63
- // Break near to match.
64
- const maxOffset = 16;
65
- let before = text.slice(0, result.index);
66
- if (before.length > maxOffset) {
67
- const idx = before.indexOf(' ', result.index - maxOffset);
68
- before = '… ' + before.slice(idx);
69
- }
70
-
71
- const after = text.slice(result.index + result[0].length);
72
- content = (
73
- <>
74
- {before}
75
- <span className='text-blue-500'>{result[0]}</span>
76
- {after}
77
- </>
78
- );
79
- }
80
- }
81
-
82
- return <span className='text-xs mb-1 line-clamp-3 text-neutral-300'>{content}</span>;
83
- };
@@ -1,5 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- export * from './SearchResults';
@@ -1,28 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { type Meta, type StoryObj } from '@storybook/react-vite';
6
-
7
- import { withTheme } from '@dxos/react-ui/testing';
8
-
9
- import { Searchbar } from './Searchbar';
10
-
11
- const meta = {
12
- title: 'plugins/plugin-search/Searchbar',
13
- component: Searchbar,
14
- decorators: [withTheme],
15
- parameters: {
16
- layout: 'centered',
17
- },
18
- } satisfies Meta<typeof Searchbar>;
19
-
20
- export default meta;
21
-
22
- type Story = StoryObj<typeof meta>;
23
-
24
- export const Default: Story = {
25
- args: {
26
- placeholder: 'Search...',
27
- },
28
- };
@@ -1,48 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import React, { type KeyboardEvent, useCallback, useRef } from 'react';
6
-
7
- import { Input, type TextInputProps, type ThemedClassName, Toolbar, useControlledState } from '@dxos/react-ui';
8
-
9
- export type SearchbarProps = ThemedClassName<
10
- Pick<TextInputProps, 'variant' | 'placeholder'> & {
11
- delay?: number;
12
- value?: string;
13
- onChange?: (text?: string) => void;
14
- onSubmit?: (text?: string) => void;
15
- }
16
- >;
17
-
18
- export const Searchbar = ({ classNames, variant, placeholder, value, onChange, onSubmit }: SearchbarProps) => {
19
- const [text, setText] = useControlledState(value, onChange);
20
- const inputRef = useRef<HTMLInputElement>(null);
21
-
22
- const handleKeyDown = useCallback(
23
- (event: KeyboardEvent<HTMLInputElement>) => {
24
- switch (event.key) {
25
- case 'Enter':
26
- onSubmit?.(text);
27
- break;
28
- }
29
- },
30
- [text, onSubmit],
31
- );
32
-
33
- return (
34
- <Toolbar.Root classNames={classNames}>
35
- <Input.Root>
36
- <Input.TextInput
37
- ref={inputRef}
38
- placeholder={placeholder}
39
- autoFocus
40
- variant={variant}
41
- value={text ?? ''}
42
- onChange={({ target }) => setText(target.value)}
43
- onKeyDown={handleKeyDown}
44
- />
45
- </Input.Root>
46
- </Toolbar.Root>
47
- );
48
- };
@@ -1,5 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- export * from './Searchbar';
@@ -1,16 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import * as Schema from 'effect/Schema';
6
-
7
- import { meta } from '../meta';
8
-
9
- export namespace SearchAction {
10
- const SEARCH_ACTION = `${meta.id}/action`;
11
-
12
- export class OpenSearch extends Schema.TaggedClass<OpenSearch>()(`${SEARCH_ACTION}/open-search`, {
13
- input: Schema.Void,
14
- output: Schema.Void,
15
- }) {}
16
- }