@dxos/plugin-search 0.8.4-main.ead640a → 0.8.4-main.effb148878
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 +102 -5
- package/README.md +0 -1
- package/dist/lib/neutral/SearchArticle-CQMZ46ZS.mjs +51 -0
- package/dist/lib/neutral/SearchArticle-CQMZ46ZS.mjs.map +7 -0
- package/dist/lib/neutral/SearchDialog-IFMA5UP5.mjs +76 -0
- package/dist/lib/neutral/SearchDialog-IFMA5UP5.mjs.map +7 -0
- package/dist/lib/neutral/SearchPlugin.mjs +10 -0
- package/dist/lib/neutral/SearchPlugin.mjs.map +7 -0
- package/dist/lib/neutral/app-graph-builder-B3W3UWHV.mjs +71 -0
- package/dist/lib/neutral/app-graph-builder-B3W3UWHV.mjs.map +7 -0
- package/dist/lib/neutral/capabilities/index.mjs +13 -0
- package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
- package/dist/lib/neutral/chunk-7ASS5WTT.mjs +8 -0
- package/dist/lib/neutral/chunk-7ASS5WTT.mjs.map +7 -0
- package/dist/lib/neutral/chunk-7VNJDD75.mjs +22 -0
- package/dist/lib/neutral/chunk-7VNJDD75.mjs.map +7 -0
- package/dist/lib/neutral/chunk-FIZRI3JV.mjs +27 -0
- package/dist/lib/neutral/chunk-FIZRI3JV.mjs.map +7 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/neutral/chunk-NAKPT2JM.mjs +8 -0
- package/dist/lib/neutral/chunk-NAKPT2JM.mjs.map +7 -0
- package/dist/lib/neutral/chunk-NBE5GQ5J.mjs +282 -0
- package/dist/lib/neutral/chunk-NBE5GQ5J.mjs.map +7 -0
- package/dist/lib/neutral/chunk-QWFRJRPV.mjs +38 -0
- package/dist/lib/neutral/chunk-QWFRJRPV.mjs.map +7 -0
- package/dist/lib/neutral/components/index.mjs +97 -0
- package/dist/lib/neutral/components/index.mjs.map +7 -0
- package/dist/lib/neutral/containers/index.mjs +11 -0
- package/dist/lib/neutral/containers/index.mjs.map +7 -0
- package/dist/lib/neutral/hooks/index.mjs +30 -0
- package/dist/lib/neutral/hooks/index.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +40 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/meta.mjs +10 -0
- package/dist/lib/neutral/meta.mjs.map +7 -0
- package/dist/lib/neutral/open-search-ABE2Y6ZG.mjs +23 -0
- package/dist/lib/neutral/open-search-ABE2Y6ZG.mjs.map +7 -0
- package/dist/lib/neutral/operation-handler-DY624P2R.mjs +13 -0
- package/dist/lib/neutral/operation-handler-DY624P2R.mjs.map +7 -0
- package/dist/lib/neutral/operations/index.mjs +8 -0
- package/dist/lib/neutral/operations/index.mjs.map +7 -0
- package/dist/lib/neutral/plugin.mjs +16 -0
- package/dist/lib/neutral/plugin.mjs.map +7 -0
- package/dist/lib/neutral/react-surface-ER7Q4W6Y.mjs +61 -0
- package/dist/lib/neutral/react-surface-ER7Q4W6Y.mjs.map +7 -0
- package/dist/lib/neutral/testing.mjs +8 -0
- package/dist/lib/neutral/testing.mjs.map +7 -0
- package/dist/lib/neutral/translations.mjs +25 -0
- package/dist/lib/neutral/translations.mjs.map +7 -0
- package/dist/lib/neutral/types/index.mjs +8 -0
- package/dist/lib/neutral/types/index.mjs.map +7 -0
- package/dist/types/src/SearchPlugin.d.ts +3 -1
- package/dist/types/src/SearchPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts +4 -2
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +5 -3
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
- package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface.d.ts +3 -2
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/SearchResultStack/SearchResultStack.d.ts +9 -0
- package/dist/types/src/components/SearchResultStack/SearchResultStack.d.ts.map +1 -0
- package/dist/types/src/components/SearchResultStack/index.d.ts +2 -0
- package/dist/types/src/components/SearchResultStack/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -3
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/constants.d.ts +2 -0
- package/dist/types/src/constants.d.ts.map +1 -0
- package/dist/types/src/containers/SearchArticle/SearchArticle.d.ts +4 -0
- package/dist/types/src/containers/SearchArticle/SearchArticle.d.ts.map +1 -0
- package/dist/types/src/{components/Searchbar/Searchbar.stories.d.ts → containers/SearchArticle/SearchArticle.stories.d.ts} +3 -2
- package/dist/types/src/containers/SearchArticle/SearchArticle.stories.d.ts.map +1 -0
- package/dist/types/src/containers/SearchArticle/index.d.ts +2 -0
- package/dist/types/src/containers/SearchArticle/index.d.ts.map +1 -0
- package/dist/types/src/containers/SearchDialog/SearchDialog.d.ts +7 -0
- package/dist/types/src/containers/SearchDialog/SearchDialog.d.ts.map +1 -0
- package/dist/types/src/{components/SearchResults/SearchResults.stories.d.ts → containers/SearchDialog/SearchDialog.stories.d.ts} +4 -4
- package/dist/types/src/containers/SearchDialog/SearchDialog.stories.d.ts.map +1 -0
- package/dist/types/src/containers/SearchDialog/index.d.ts +2 -0
- package/dist/types/src/containers/SearchDialog/index.d.ts.map +1 -0
- package/dist/types/src/containers/index.d.ts +4 -0
- package/dist/types/src/containers/index.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +1 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/sync.d.ts +4 -3
- package/dist/types/src/hooks/sync.d.ts.map +1 -1
- package/dist/types/src/hooks/useGlobalSearch.d.ts +8 -4
- package/dist/types/src/hooks/useGlobalSearch.d.ts.map +1 -1
- package/dist/types/src/hooks/useSearchResults.d.ts +3 -2
- package/dist/types/src/hooks/useSearchResults.d.ts.map +1 -1
- package/dist/types/src/hooks/useWebSearch.d.ts +7 -4
- package/dist/types/src/hooks/useWebSearch.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -2
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/operations/index.d.ts +3 -0
- package/dist/types/src/operations/index.d.ts.map +1 -0
- package/dist/types/src/operations/open-search.d.ts +5 -0
- package/dist/types/src/operations/open-search.d.ts.map +1 -0
- package/dist/types/src/plugin.d.ts +4 -0
- package/dist/types/src/plugin.d.ts.map +1 -0
- package/dist/types/src/search/exa.d.ts +5 -4
- package/dist/types/src/search/exa.d.ts.map +1 -1
- package/dist/types/src/testing.d.ts +2 -0
- package/dist/types/src/testing.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +15 -10
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/SearchOperation.d.ts +3 -0
- package/dist/types/src/types/SearchOperation.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +1 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/search.d.ts +1 -20
- package/dist/types/src/types/search.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +119 -47
- package/src/SearchPlugin.tsx +14 -47
- package/src/capabilities/app-graph-builder.ts +55 -69
- package/src/capabilities/index.ts +8 -4
- package/src/capabilities/operation-handler.ts +16 -0
- package/src/capabilities/react-surface.tsx +65 -52
- package/src/components/SearchResultStack/SearchResultStack.tsx +118 -0
- package/src/components/SearchResultStack/index.ts +5 -0
- package/src/components/index.ts +1 -3
- package/src/constants.ts +7 -0
- package/src/containers/SearchArticle/SearchArticle.stories.tsx +79 -0
- package/src/containers/SearchArticle/SearchArticle.tsx +60 -0
- package/src/containers/SearchArticle/index.ts +5 -0
- package/src/containers/SearchDialog/SearchDialog.stories.tsx +108 -0
- package/src/containers/SearchDialog/SearchDialog.tsx +93 -0
- package/src/containers/SearchDialog/index.ts +5 -0
- package/src/containers/index.ts +8 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/sync.test.ts +9 -7
- package/src/hooks/sync.ts +32 -34
- package/src/hooks/useGlobalSearch.tsx +32 -13
- package/src/hooks/useSearchResults.ts +7 -4
- package/src/hooks/useWebSearch.ts +25 -14
- package/src/index.ts +2 -2
- package/src/meta.ts +25 -5
- package/src/operations/index.ts +7 -0
- package/src/operations/open-search.ts +24 -0
- package/src/plugin.ts +11 -0
- package/src/search/exa.test.ts +9 -11
- package/src/search/exa.ts +11 -10
- package/src/testing.ts +7 -0
- package/src/translations.ts +10 -9
- package/src/types/SearchOperation.ts +19 -0
- package/src/types/command-score.d.ts +16 -0
- package/src/types/index.ts +2 -1
- package/src/types/search.ts +1 -25
- package/dist/lib/browser/app-graph-builder-YME7SN7O.mjs +0 -78
- package/dist/lib/browser/app-graph-builder-YME7SN7O.mjs.map +0 -7
- package/dist/lib/browser/chunk-5N6LDSFF.mjs +0 -18
- package/dist/lib/browser/chunk-5N6LDSFF.mjs.map +0 -7
- package/dist/lib/browser/chunk-WN3TVQLV.mjs +0 -190
- package/dist/lib/browser/chunk-WN3TVQLV.mjs.map +0 -7
- package/dist/lib/browser/chunk-YJGHPWUO.mjs +0 -21
- package/dist/lib/browser/chunk-YJGHPWUO.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -110
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-XNVR4XRX.mjs +0 -22
- package/dist/lib/browser/intent-resolver-XNVR4XRX.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/react-surface-YOGLADC4.mjs +0 -470
- package/dist/lib/browser/react-surface-YOGLADC4.mjs.map +0 -7
- package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
- package/dist/types/src/components/Search.stories.d.ts +0 -16
- package/dist/types/src/components/Search.stories.d.ts.map +0 -1
- package/dist/types/src/components/SearchDialog.d.ts +0 -7
- package/dist/types/src/components/SearchDialog.d.ts.map +0 -1
- package/dist/types/src/components/SearchMain.d.ts +0 -7
- package/dist/types/src/components/SearchMain.d.ts.map +0 -1
- package/dist/types/src/components/SearchResults/SearchResults.d.ts +0 -20
- package/dist/types/src/components/SearchResults/SearchResults.d.ts.map +0 -1
- package/dist/types/src/components/SearchResults/SearchResults.stories.d.ts.map +0 -1
- package/dist/types/src/components/SearchResults/index.d.ts +0 -2
- package/dist/types/src/components/SearchResults/index.d.ts.map +0 -1
- package/dist/types/src/components/Searchbar/Searchbar.d.ts +0 -14
- package/dist/types/src/components/Searchbar/Searchbar.d.ts.map +0 -1
- package/dist/types/src/components/Searchbar/Searchbar.stories.d.ts.map +0 -1
- package/dist/types/src/components/Searchbar/index.d.ts +0 -2
- package/dist/types/src/components/Searchbar/index.d.ts.map +0 -1
- package/dist/types/src/types/action.d.ts +0 -13
- package/dist/types/src/types/action.d.ts.map +0 -1
- package/src/capabilities/intent-resolver.ts +0 -18
- package/src/components/Search.stories.tsx +0 -64
- package/src/components/SearchDialog.tsx +0 -124
- package/src/components/SearchMain.tsx +0 -68
- package/src/components/SearchResults/SearchResults.stories.tsx +0 -58
- package/src/components/SearchResults/SearchResults.tsx +0 -86
- package/src/components/SearchResults/index.ts +0 -5
- package/src/components/Searchbar/Searchbar.stories.tsx +0 -28
- package/src/components/Searchbar/Searchbar.tsx +0 -67
- package/src/components/Searchbar/index.ts +0 -5
- package/src/types/action.tsx +0 -16
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { type KeyboardEvent, forwardRef, useCallback, useMemo, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { Surface } from '@dxos/app-framework/ui';
|
|
8
|
+
import { AppSurface, useObjectMenuItems } from '@dxos/app-toolkit/ui';
|
|
9
|
+
import { Entity } from '@dxos/echo';
|
|
10
|
+
import { Card, Toolbar } from '@dxos/react-ui';
|
|
11
|
+
import { ScrollArea } from '@dxos/react-ui';
|
|
12
|
+
import { composable, composableProps } from '@dxos/react-ui';
|
|
13
|
+
import { Menu } from '@dxos/react-ui-menu';
|
|
14
|
+
import { type MosaicTileProps, Mosaic, useMosaicContainer, Focus } from '@dxos/react-ui-mosaic';
|
|
15
|
+
import { type SearchResult } from '@dxos/react-ui-search';
|
|
16
|
+
|
|
17
|
+
//
|
|
18
|
+
// SearchResultStack
|
|
19
|
+
//
|
|
20
|
+
|
|
21
|
+
export type SearchResultStackProps = {
|
|
22
|
+
results: SearchResult[];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const SearchResultStack = composable<HTMLDivElement, SearchResultStackProps>(
|
|
26
|
+
({ results, ...props }, forwardedRef) => {
|
|
27
|
+
const [viewport, setViewport] = useState<HTMLElement | null>(null);
|
|
28
|
+
const items = useMemo(() => results.map((result) => ({ result })), [results]);
|
|
29
|
+
|
|
30
|
+
const handleKeyDown = useCallback((event: KeyboardEvent<HTMLDivElement>) => {
|
|
31
|
+
if (event.key === 'Enter') {
|
|
32
|
+
event.preventDefault();
|
|
33
|
+
(document.activeElement as HTMLElement | null)?.click();
|
|
34
|
+
}
|
|
35
|
+
}, []);
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<Focus.Group asChild {...composableProps(props)} onKeyDown={handleKeyDown} ref={forwardedRef}>
|
|
39
|
+
<Mosaic.Container asChild>
|
|
40
|
+
<ScrollArea.Root orientation='vertical' padding centered>
|
|
41
|
+
<ScrollArea.Viewport ref={setViewport}>
|
|
42
|
+
<Mosaic.VirtualStack
|
|
43
|
+
Tile={SearchResultTile}
|
|
44
|
+
classNames='my-2'
|
|
45
|
+
gap={8}
|
|
46
|
+
items={items}
|
|
47
|
+
draggable={false}
|
|
48
|
+
getId={(item) => item.result.id}
|
|
49
|
+
getScrollElement={() => viewport}
|
|
50
|
+
estimateSize={() => 150}
|
|
51
|
+
/>
|
|
52
|
+
</ScrollArea.Viewport>
|
|
53
|
+
</ScrollArea.Root>
|
|
54
|
+
</Mosaic.Container>
|
|
55
|
+
</Focus.Group>
|
|
56
|
+
);
|
|
57
|
+
},
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
SearchResultStack.displayName = 'SearchResultStack';
|
|
61
|
+
|
|
62
|
+
//
|
|
63
|
+
// SearchResultTile
|
|
64
|
+
//
|
|
65
|
+
|
|
66
|
+
type SearchResultTileData = {
|
|
67
|
+
result: SearchResult;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
type SearchResultTileProps = Pick<MosaicTileProps<SearchResultTileData>, 'location' | 'data' | 'current'>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Search result tile that uses Surface to render object content.
|
|
74
|
+
*/
|
|
75
|
+
const SearchResultTile = forwardRef<HTMLDivElement, SearchResultTileProps>(
|
|
76
|
+
({ data, location, current }, forwardedRef) => {
|
|
77
|
+
const { result } = data;
|
|
78
|
+
const menuItems = useObjectMenuItems(result.object);
|
|
79
|
+
const { setCurrentId } = useMosaicContainer('SearchResultTile');
|
|
80
|
+
|
|
81
|
+
const handleCurrentChange = useCallback(() => {
|
|
82
|
+
setCurrentId(result.id);
|
|
83
|
+
}, [result.id, setCurrentId]);
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<Menu.Root>
|
|
87
|
+
<Mosaic.Tile
|
|
88
|
+
asChild
|
|
89
|
+
classNames='dx-hover dx-current dx-selected'
|
|
90
|
+
id={result.id}
|
|
91
|
+
data={data}
|
|
92
|
+
location={location}
|
|
93
|
+
>
|
|
94
|
+
<Focus.Item asChild current={current} onCurrentChange={handleCurrentChange}>
|
|
95
|
+
<Card.Root ref={forwardedRef} role='button' classNames='cursor-pointer'>
|
|
96
|
+
<Card.Header>
|
|
97
|
+
<Card.IconBlock />
|
|
98
|
+
<Card.Title>{result.label ?? (result.object && Entity.getLabel(result.object))}</Card.Title>
|
|
99
|
+
<Menu.Trigger asChild disabled={!menuItems?.length}>
|
|
100
|
+
<Toolbar.IconButton
|
|
101
|
+
iconOnly
|
|
102
|
+
variant='ghost'
|
|
103
|
+
icon='ph--dots-three-vertical--regular'
|
|
104
|
+
label='Actions'
|
|
105
|
+
/>
|
|
106
|
+
</Menu.Trigger>
|
|
107
|
+
<Menu.Content items={menuItems} />
|
|
108
|
+
</Card.Header>
|
|
109
|
+
<Surface.Surface type={AppSurface.Card} data={{ subject: result.object }} limit={1} />
|
|
110
|
+
</Card.Root>
|
|
111
|
+
</Focus.Item>
|
|
112
|
+
</Mosaic.Tile>
|
|
113
|
+
</Menu.Root>
|
|
114
|
+
);
|
|
115
|
+
},
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
SearchResultTile.displayName = 'SearchResultTile';
|
package/src/components/index.ts
CHANGED
package/src/constants.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
|
|
9
|
+
import { Capability } from '@dxos/app-framework';
|
|
10
|
+
import { withPluginManager } from '@dxos/app-framework/testing';
|
|
11
|
+
import { AppCapabilities } from '@dxos/app-toolkit';
|
|
12
|
+
import { ClientPlugin } from '@dxos/plugin-client/testing';
|
|
13
|
+
import { initializeIdentity } from '@dxos/plugin-client/testing';
|
|
14
|
+
import { StorybookPlugin, corePlugins } from '@dxos/plugin-testing';
|
|
15
|
+
import { random } from '@dxos/random';
|
|
16
|
+
import { useSpaces } from '@dxos/react-client/echo';
|
|
17
|
+
import { Loading, withLayout } from '@dxos/react-ui/testing';
|
|
18
|
+
import { createObjectFactory } from '@dxos/schema/testing';
|
|
19
|
+
import { Organization, Person } from '@dxos/types';
|
|
20
|
+
|
|
21
|
+
import { SearchContextProvider } from '#hooks';
|
|
22
|
+
import { translations } from '#translations';
|
|
23
|
+
|
|
24
|
+
import { SearchArticle } from './SearchArticle';
|
|
25
|
+
|
|
26
|
+
random.seed(0);
|
|
27
|
+
|
|
28
|
+
const DefaultStory = () => {
|
|
29
|
+
const spaces = useSpaces();
|
|
30
|
+
const space = spaces[spaces.length - 1];
|
|
31
|
+
if (!space) {
|
|
32
|
+
return <Loading />;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<SearchContextProvider>
|
|
37
|
+
<SearchArticle role='article' space={space} attendableId={space.id} />
|
|
38
|
+
</SearchContextProvider>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const meta = {
|
|
43
|
+
title: 'plugins/plugin-search/containers/SearchArticle',
|
|
44
|
+
render: DefaultStory,
|
|
45
|
+
decorators: [
|
|
46
|
+
withLayout({ layout: 'column' }),
|
|
47
|
+
withPluginManager({
|
|
48
|
+
capabilities: [Capability.contributes(AppCapabilities.Translations, translations)],
|
|
49
|
+
plugins: [
|
|
50
|
+
...corePlugins(),
|
|
51
|
+
StorybookPlugin({}),
|
|
52
|
+
ClientPlugin({
|
|
53
|
+
types: [Organization.Organization, Person.Person],
|
|
54
|
+
onClientInitialized: ({ client }) =>
|
|
55
|
+
Effect.gen(function* () {
|
|
56
|
+
const { personalSpace } = yield* initializeIdentity(client);
|
|
57
|
+
|
|
58
|
+
const factory = createObjectFactory(personalSpace.db, random as any);
|
|
59
|
+
yield* Effect.promise(() =>
|
|
60
|
+
factory([
|
|
61
|
+
{ type: Organization.Organization, count: 10 },
|
|
62
|
+
{ type: Person.Person, count: 50 },
|
|
63
|
+
]),
|
|
64
|
+
);
|
|
65
|
+
}),
|
|
66
|
+
}),
|
|
67
|
+
],
|
|
68
|
+
}),
|
|
69
|
+
],
|
|
70
|
+
parameters: {
|
|
71
|
+
layout: 'fullscreen',
|
|
72
|
+
},
|
|
73
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
74
|
+
|
|
75
|
+
export default meta;
|
|
76
|
+
|
|
77
|
+
type Story = StoryObj<typeof meta>;
|
|
78
|
+
|
|
79
|
+
export const Default: Story = {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { AppSurface } from '@dxos/app-toolkit/ui';
|
|
8
|
+
import { Entity, Filter, Query } from '@dxos/echo';
|
|
9
|
+
import { useQuery } from '@dxos/react-client/echo';
|
|
10
|
+
import { Panel, Toolbar } from '@dxos/react-ui';
|
|
11
|
+
import { SearchList } from '@dxos/react-ui-search';
|
|
12
|
+
import { Text } from '@dxos/schema';
|
|
13
|
+
import { isTauri, getHostPlatform } from '@dxos/util';
|
|
14
|
+
|
|
15
|
+
import { SearchResultStack } from '#components';
|
|
16
|
+
import { useGlobalSearch, useGlobalSearchResults, useWebSearch } from '#hooks';
|
|
17
|
+
|
|
18
|
+
export const SearchArticle = ({ space }: AppSurface.SpaceArticleProps) => {
|
|
19
|
+
// TODO(burdon): Option to query across spaces.
|
|
20
|
+
const [query, setQuery] = useState<string>();
|
|
21
|
+
// TODO(burdon): Re-enable full-text search when indexer is available in all environments.
|
|
22
|
+
const objects = useQuery(
|
|
23
|
+
space.db,
|
|
24
|
+
query === undefined ? Query.select(Filter.nothing()) : Query.select(Filter.not(Filter.type(Text.Text))),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const { setMatch } = useGlobalSearch();
|
|
28
|
+
const results = useGlobalSearchResults(objects);
|
|
29
|
+
const { results: webResults } = useWebSearch({ query });
|
|
30
|
+
const allResults = useMemo(
|
|
31
|
+
() => [...results, ...webResults].filter(({ object }) => object && Entity.getLabel(object)),
|
|
32
|
+
[results, webResults],
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const handleSearch = useCallback(
|
|
36
|
+
(text: string) => {
|
|
37
|
+
setQuery(text);
|
|
38
|
+
setMatch?.(text);
|
|
39
|
+
},
|
|
40
|
+
[setMatch],
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const autoFocus = !isTauri() || getHostPlatform() !== 'ios';
|
|
44
|
+
|
|
45
|
+
// TODO(burdon): Move current up/down without losing focus.
|
|
46
|
+
return (
|
|
47
|
+
<SearchList.Root onSearch={handleSearch}>
|
|
48
|
+
<Panel.Root>
|
|
49
|
+
<Panel.Content asChild>
|
|
50
|
+
<SearchResultStack results={allResults} />
|
|
51
|
+
</Panel.Content>
|
|
52
|
+
<Panel.Statusbar asChild>
|
|
53
|
+
<Toolbar.Root>
|
|
54
|
+
<SearchList.Input placeholder='Search...' autoFocus={autoFocus} />
|
|
55
|
+
</Toolbar.Root>
|
|
56
|
+
</Panel.Statusbar>
|
|
57
|
+
</Panel.Root>
|
|
58
|
+
</SearchList.Root>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import { expect, userEvent, waitFor, within } from 'storybook/test';
|
|
9
|
+
|
|
10
|
+
import { Capability } from '@dxos/app-framework';
|
|
11
|
+
import { withPluginManager } from '@dxos/app-framework/testing';
|
|
12
|
+
import { AppCapabilities } from '@dxos/app-toolkit';
|
|
13
|
+
import { ClientPlugin } from '@dxos/plugin-client/testing';
|
|
14
|
+
import { initializeIdentity } from '@dxos/plugin-client/testing';
|
|
15
|
+
import { StorybookPlugin, corePlugins } from '@dxos/plugin-testing';
|
|
16
|
+
import { random } from '@dxos/random';
|
|
17
|
+
import { useSpaces } from '@dxos/react-client/echo';
|
|
18
|
+
import { Dialog } from '@dxos/react-ui';
|
|
19
|
+
import { Loading, withLayout } from '@dxos/react-ui/testing';
|
|
20
|
+
import { createObjectFactory } from '@dxos/schema/testing';
|
|
21
|
+
import { Organization, Person } from '@dxos/types';
|
|
22
|
+
|
|
23
|
+
import { SearchContextProvider } from '#hooks';
|
|
24
|
+
import { translations } from '#translations';
|
|
25
|
+
|
|
26
|
+
import { SearchDialog } from './SearchDialog';
|
|
27
|
+
|
|
28
|
+
random.seed(0);
|
|
29
|
+
|
|
30
|
+
const DefaultStory = () => {
|
|
31
|
+
const spaces = useSpaces();
|
|
32
|
+
const space = spaces[spaces.length - 1];
|
|
33
|
+
if (!space) {
|
|
34
|
+
return <Loading />;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<SearchContextProvider>
|
|
39
|
+
<Dialog.Root defaultOpen>
|
|
40
|
+
<Dialog.Overlay>
|
|
41
|
+
<SearchDialog role='article' space={space} attendableId={space.id} pivotId='storybook' />
|
|
42
|
+
</Dialog.Overlay>
|
|
43
|
+
</Dialog.Root>
|
|
44
|
+
</SearchContextProvider>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const meta = {
|
|
49
|
+
title: 'plugins/plugin-search/containers/SearchDialog',
|
|
50
|
+
render: DefaultStory,
|
|
51
|
+
decorators: [
|
|
52
|
+
withLayout({ layout: 'fullscreen' }),
|
|
53
|
+
withPluginManager({
|
|
54
|
+
capabilities: [Capability.contributes(AppCapabilities.Translations, translations)],
|
|
55
|
+
plugins: [
|
|
56
|
+
...corePlugins(),
|
|
57
|
+
StorybookPlugin({}),
|
|
58
|
+
ClientPlugin({
|
|
59
|
+
types: [Organization.Organization, Person.Person],
|
|
60
|
+
onClientInitialized: ({ client }) =>
|
|
61
|
+
Effect.gen(function* () {
|
|
62
|
+
const { personalSpace } = yield* initializeIdentity(client);
|
|
63
|
+
|
|
64
|
+
const factory = createObjectFactory(personalSpace.db, random as any);
|
|
65
|
+
yield* Effect.promise(() =>
|
|
66
|
+
factory([
|
|
67
|
+
{ type: Organization.Organization, count: 10 },
|
|
68
|
+
{ type: Person.Person, count: 50 },
|
|
69
|
+
]),
|
|
70
|
+
);
|
|
71
|
+
}),
|
|
72
|
+
}),
|
|
73
|
+
],
|
|
74
|
+
}),
|
|
75
|
+
],
|
|
76
|
+
tags: ['test'],
|
|
77
|
+
parameters: {
|
|
78
|
+
layout: 'fullscreen',
|
|
79
|
+
},
|
|
80
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
81
|
+
|
|
82
|
+
export default meta;
|
|
83
|
+
|
|
84
|
+
type Story = StoryObj<typeof meta>;
|
|
85
|
+
|
|
86
|
+
export const Default: Story = {};
|
|
87
|
+
|
|
88
|
+
export const Test: Story = {
|
|
89
|
+
play: async () => {
|
|
90
|
+
const body = within(document.body);
|
|
91
|
+
|
|
92
|
+
// Wait for the dialog to render and the search input to appear.
|
|
93
|
+
const searchInput = await body.findByRole('textbox', undefined, { timeout: 10_000 });
|
|
94
|
+
await expect(searchInput).toBeInTheDocument();
|
|
95
|
+
|
|
96
|
+
// Type a search term that should match generated Person/Organization names.
|
|
97
|
+
await userEvent.type(searchInput, 'a');
|
|
98
|
+
|
|
99
|
+
// Wait for search results to appear as options in the listbox.
|
|
100
|
+
await waitFor(
|
|
101
|
+
async () => {
|
|
102
|
+
const options = body.queryAllByRole('option');
|
|
103
|
+
await expect(options.length).toBeGreaterThan(0);
|
|
104
|
+
},
|
|
105
|
+
{ timeout: 10_000 },
|
|
106
|
+
);
|
|
107
|
+
},
|
|
108
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { useOperationInvoker } from '@dxos/app-framework/ui';
|
|
8
|
+
import { getObjectPathFromObject, LayoutOperation } from '@dxos/app-toolkit';
|
|
9
|
+
import { type AppSurface } from '@dxos/app-toolkit/ui';
|
|
10
|
+
import { useLayout } from '@dxos/app-toolkit/ui';
|
|
11
|
+
import { Entity, Filter, Obj, Query } from '@dxos/echo';
|
|
12
|
+
import { useQuery } from '@dxos/react-client/echo';
|
|
13
|
+
import { Dialog, useTranslation } from '@dxos/react-ui';
|
|
14
|
+
import { SearchList } from '@dxos/react-ui-search';
|
|
15
|
+
import { Text } from '@dxos/schema';
|
|
16
|
+
|
|
17
|
+
import { useGlobalSearch, useGlobalSearchResults } from '#hooks';
|
|
18
|
+
import { meta } from '#meta';
|
|
19
|
+
import { type SearchResult } from '#types';
|
|
20
|
+
|
|
21
|
+
export type SearchDialogProps = AppSurface.SpaceArticleProps<{
|
|
22
|
+
pivotId?: string;
|
|
23
|
+
}>;
|
|
24
|
+
|
|
25
|
+
export const SearchDialog = ({ space, pivotId: pivotIdProp }: SearchDialogProps) => {
|
|
26
|
+
const { t } = useTranslation(meta.id);
|
|
27
|
+
const { invokePromise } = useOperationInvoker();
|
|
28
|
+
const { setMatch } = useGlobalSearch();
|
|
29
|
+
const layout = useLayout();
|
|
30
|
+
const pivotId = pivotIdProp ?? layout.active[layout.active.length - 1];
|
|
31
|
+
const [query, setQuery] = useState<string>();
|
|
32
|
+
|
|
33
|
+
// TODO(burdon): Re-enable full-text search when indexer is available in all environments.
|
|
34
|
+
const objects = useQuery(
|
|
35
|
+
space?.db,
|
|
36
|
+
query === undefined ? Query.select(Filter.nothing()) : Query.select(Filter.not(Filter.type(Text.Text))),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const results = useGlobalSearchResults(objects);
|
|
40
|
+
const allResults = useMemo(() => results.filter(({ object }) => object && Entity.getLabel(object)), [results]);
|
|
41
|
+
|
|
42
|
+
const handleSearch = useCallback(
|
|
43
|
+
(text: string) => {
|
|
44
|
+
setQuery(text);
|
|
45
|
+
setMatch?.(text);
|
|
46
|
+
},
|
|
47
|
+
[setMatch],
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const handleSelect = useCallback(
|
|
51
|
+
async (result: SearchResult) => {
|
|
52
|
+
if (!result.object || !Obj.isObject(result.object)) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const qualifiedPath = getObjectPathFromObject(result.object);
|
|
57
|
+
await invokePromise(LayoutOperation.UpdateDialog, { state: false });
|
|
58
|
+
await invokePromise(LayoutOperation.Open, {
|
|
59
|
+
subject: [qualifiedPath],
|
|
60
|
+
pivotId,
|
|
61
|
+
positioning: 'end',
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
[pivotId, invokePromise],
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<Dialog.Content>
|
|
69
|
+
<Dialog.Header>
|
|
70
|
+
<Dialog.Title>{t('search-dialog.title')}</Dialog.Title>
|
|
71
|
+
<Dialog.Close asChild>
|
|
72
|
+
<Dialog.ActionIconButton action='close' />
|
|
73
|
+
</Dialog.Close>
|
|
74
|
+
</Dialog.Header>
|
|
75
|
+
<SearchList.Root onSearch={handleSearch}>
|
|
76
|
+
<SearchList.Input classNames='px-0' autoFocus placeholder={t('search.placeholder')} />
|
|
77
|
+
<SearchList.Viewport classNames='max-h-[24rem]'>
|
|
78
|
+
{allResults.map((result) => (
|
|
79
|
+
<SearchList.Item
|
|
80
|
+
key={result.id}
|
|
81
|
+
classNames='flex gap-2 items-center'
|
|
82
|
+
value={result.id}
|
|
83
|
+
label={result.label ?? (result.object ? Entity.getLabel(result.object) : undefined) ?? result.id}
|
|
84
|
+
icon={result.icon}
|
|
85
|
+
onSelect={() => void handleSelect(result)}
|
|
86
|
+
/>
|
|
87
|
+
))}
|
|
88
|
+
{query && allResults.length === 0 && <SearchList.Empty />}
|
|
89
|
+
</SearchList.Viewport>
|
|
90
|
+
</SearchList.Root>
|
|
91
|
+
</Dialog.Content>
|
|
92
|
+
);
|
|
93
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type ComponentType, lazy } from 'react';
|
|
6
|
+
|
|
7
|
+
export const SearchDialog: ComponentType<any> = lazy(() => import('./SearchDialog'));
|
|
8
|
+
export const SearchArticle: ComponentType<any> = lazy(() => import('./SearchArticle'));
|
package/src/hooks/index.ts
CHANGED
package/src/hooks/sync.test.ts
CHANGED
|
@@ -5,17 +5,19 @@
|
|
|
5
5
|
import { describe, expect, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { Client } from '@dxos/client';
|
|
8
|
-
import { Filter, Obj
|
|
9
|
-
import {
|
|
8
|
+
import { Filter, Obj } from '@dxos/echo';
|
|
9
|
+
import { TestSchema } from '@dxos/echo/testing';
|
|
10
|
+
import { random } from '@dxos/random';
|
|
10
11
|
|
|
11
12
|
import { filterObjectsSync } from './sync';
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
random.seed(1);
|
|
14
15
|
|
|
15
16
|
// TODO(burdon): Reconcile with agent/minisearch.
|
|
16
17
|
|
|
17
18
|
describe('Search', () => {
|
|
18
|
-
|
|
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();
|
|
@@ -24,11 +26,11 @@ describe('Search', () => {
|
|
|
24
26
|
const space = await client.spaces.create();
|
|
25
27
|
Array.from({ length: 20 }).map((_, i) => {
|
|
26
28
|
const content =
|
|
27
|
-
i === 10 ?
|
|
28
|
-
return space.db.add(Obj.make(
|
|
29
|
+
i === 10 ? random.lorem.sentence() + ` ${match}}. ` + random.lorem.sentence() : random.lorem.sentences();
|
|
30
|
+
return space.db.add(Obj.make(TestSchema.Expando, { title: random.lorem.sentence(), content }));
|
|
29
31
|
});
|
|
30
32
|
|
|
31
|
-
const
|
|
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
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import type * as Schema from 'effect/Schema';
|
|
6
5
|
import * as SchemaAST from 'effect/SchemaAST';
|
|
7
6
|
|
|
8
|
-
import { Obj } from '@dxos/echo';
|
|
9
|
-
import {
|
|
7
|
+
import { Entity, Obj, Type } from '@dxos/echo';
|
|
8
|
+
import { Text } from '@dxos/schema';
|
|
10
9
|
|
|
11
|
-
import { type SearchResult } from '
|
|
10
|
+
import { type SearchResult } from '#types';
|
|
12
11
|
|
|
13
12
|
export const queryStringToMatch = (queryString?: string): RegExp | undefined => {
|
|
14
13
|
const trimmed = queryString?.trim();
|
|
@@ -16,8 +15,12 @@ export const queryStringToMatch = (queryString?: string): RegExp | undefined =>
|
|
|
16
15
|
};
|
|
17
16
|
|
|
18
17
|
// TODO(burdon): Type name registry linked to schema?
|
|
19
|
-
const getIcon = (
|
|
20
|
-
if (!
|
|
18
|
+
const getIcon = (type: Type.AnyEntity | undefined): string | undefined => {
|
|
19
|
+
if (!type) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const schema = Type.getSchema(type);
|
|
23
|
+
if (!SchemaAST.isTypeLiteral(schema.ast)) {
|
|
21
24
|
return undefined;
|
|
22
25
|
}
|
|
23
26
|
const keys = schema.ast.propertySignatures.map((p) => p.name);
|
|
@@ -39,39 +42,34 @@ const getIcon = (schema: Schema.Schema.AnyNoContext | undefined): string | undef
|
|
|
39
42
|
export type TextFields = Record<string, string>;
|
|
40
43
|
|
|
41
44
|
// TODO(thure): This returns `SearchResult[]` which is not just a narrower set of objects as the name implies.
|
|
42
|
-
export const filterObjectsSync = <T extends
|
|
45
|
+
export const filterObjectsSync = <T extends Entity.Unknown>(objects: T[], match?: RegExp): SearchResult<T>[] => {
|
|
43
46
|
if (!match) {
|
|
44
47
|
return [];
|
|
45
48
|
}
|
|
46
49
|
|
|
47
|
-
return objects.reduce<SearchResult[]>((results, object) => {
|
|
50
|
+
return objects.reduce<SearchResult<T>[]>((results, object) => {
|
|
48
51
|
// TODO(burdon): Hack to ignore Text objects.
|
|
49
|
-
if (
|
|
52
|
+
if (Obj.instanceOf(Text.Text, object)) {
|
|
50
53
|
return results;
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
const fields = mapObjectToTextFields(object);
|
|
54
57
|
Object.entries(fields).some(([, value]) => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
object,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
58
|
+
// TODO(burdon): Use schema.
|
|
59
|
+
const label = Obj.getLabel(object as any);
|
|
60
|
+
|
|
61
|
+
results.push({
|
|
62
|
+
id: object.id,
|
|
63
|
+
type: getIcon(Entity.getType(object)),
|
|
64
|
+
label,
|
|
65
|
+
match,
|
|
66
|
+
// TODO(burdon): Truncate.
|
|
67
|
+
// TODO(burdon): Issue with sketch documents.
|
|
68
|
+
snippet: value !== label ? value : (fields.content ?? fields.description ?? undefined),
|
|
69
|
+
object,
|
|
70
|
+
});
|
|
73
71
|
|
|
74
|
-
return
|
|
72
|
+
return true;
|
|
75
73
|
});
|
|
76
74
|
|
|
77
75
|
return results;
|
|
@@ -95,13 +93,13 @@ export const getStringProperty = (object: any, keys: string[]): string | undefin
|
|
|
95
93
|
};
|
|
96
94
|
|
|
97
95
|
// TODO(burdon): Filter system fields.
|
|
98
|
-
const getKeys = (object:
|
|
96
|
+
const getKeys = <T extends Entity.Unknown>(object: T): string[] => {
|
|
99
97
|
try {
|
|
100
98
|
const obj = JSON.parse(JSON.stringify(object));
|
|
101
99
|
return Object.keys(obj).filter(
|
|
102
100
|
(key) => key !== 'id' && key !== 'identityKey' && key[0] !== '_' && key[0] !== '@',
|
|
103
101
|
) as string[];
|
|
104
|
-
} catch
|
|
102
|
+
} catch {
|
|
105
103
|
// TODO(burdon): Error with TLDraw sketch.
|
|
106
104
|
// Uncaught Error: Type with the name content has already been defined with a different constructor
|
|
107
105
|
return [];
|
|
@@ -109,13 +107,13 @@ const getKeys = (object: Record<string, unknown>): string[] => {
|
|
|
109
107
|
};
|
|
110
108
|
|
|
111
109
|
// TODO(burdon): Use ECHO schema.
|
|
112
|
-
export const mapObjectToTextFields = <T extends
|
|
110
|
+
export const mapObjectToTextFields = <T extends Entity.Unknown>(object: T): TextFields => {
|
|
113
111
|
return getKeys(object).reduce<TextFields>((fields, key) => {
|
|
114
|
-
const value = object
|
|
115
|
-
if (typeof value === 'string' ||
|
|
112
|
+
const value = (object as any)[key];
|
|
113
|
+
if (typeof value === 'string' || Obj.instanceOf(Text.Text, value)) {
|
|
116
114
|
try {
|
|
117
115
|
fields[key] = String(value);
|
|
118
|
-
} catch
|
|
116
|
+
} catch {
|
|
119
117
|
// TODO(burdon): Exception when parsing sketch document.
|
|
120
118
|
}
|
|
121
119
|
}
|