@dxos/plugin-search 0.8.4-main.bc674ce → 0.8.4-main.bcb3aa67d6
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/README.md +0 -1
- package/dist/lib/browser/index.mjs +306 -52
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/SearchPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts +6 -0
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -0
- 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 +5 -0
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -0
- package/dist/types/src/components/SearchResultStack/SearchResultStack.d.ts +13 -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 +7 -0
- package/dist/types/src/containers/SearchArticle/SearchArticle.d.ts.map +1 -0
- package/dist/types/src/containers/SearchArticle/SearchArticle.stories.d.ts +15 -0
- package/dist/types/src/containers/SearchArticle/SearchArticle.stories.d.ts.map +1 -0
- package/dist/types/src/containers/SearchArticle/index.d.ts +3 -0
- package/dist/types/src/containers/SearchArticle/index.d.ts.map +1 -0
- package/dist/types/src/containers/SearchDialog/SearchDialog.d.ts +8 -0
- package/dist/types/src/containers/SearchDialog/SearchDialog.d.ts.map +1 -0
- package/dist/types/src/containers/SearchDialog/SearchDialog.stories.d.ts +17 -0
- package/dist/types/src/containers/SearchDialog/SearchDialog.stories.d.ts.map +1 -0
- package/dist/types/src/containers/SearchDialog/index.d.ts +3 -0
- package/dist/types/src/containers/SearchDialog/index.d.ts.map +1 -0
- package/dist/types/src/containers/index.d.ts +5 -0
- package/dist/types/src/containers/index.d.ts.map +1 -0
- package/dist/types/src/hooks/sync.d.ts +1 -1
- package/dist/types/src/hooks/sync.d.ts.map +1 -1
- package/dist/types/src/hooks/useGlobalSearch.d.ts +2 -2
- package/dist/types/src/hooks/useGlobalSearch.d.ts.map +1 -1
- package/dist/types/src/hooks/useWebSearch.d.ts +1 -1
- package/dist/types/src/hooks/useWebSearch.d.ts.map +1 -1
- package/dist/types/src/operations/definitions.d.ts +3 -0
- package/dist/types/src/operations/definitions.d.ts.map +1 -0
- package/dist/types/src/operations/index.d.ts +4 -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/translations.d.ts +15 -9
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +0 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/search.d.ts +1 -16
- package/dist/types/src/types/search.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +53 -41
- package/src/SearchPlugin.tsx +11 -9
- package/src/capabilities/{app-graph-builder/app-graph-builder.ts → app-graph-builder.ts} +16 -20
- package/src/capabilities/index.ts +9 -3
- package/src/capabilities/operation-handler.ts +16 -0
- package/src/capabilities/react-surface.tsx +62 -0
- 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 +80 -0
- package/src/containers/SearchArticle/SearchArticle.tsx +63 -0
- package/src/containers/SearchArticle/index.ts +7 -0
- package/src/containers/SearchDialog/SearchDialog.stories.tsx +109 -0
- package/src/containers/SearchDialog/SearchDialog.tsx +100 -0
- package/src/containers/SearchDialog/index.ts +6 -0
- package/src/containers/index.ts +10 -0
- package/src/hooks/sync.ts +1 -1
- package/src/hooks/useGlobalSearch.tsx +3 -3
- package/src/hooks/useWebSearch.ts +1 -1
- package/src/meta.ts +2 -2
- package/src/operations/definitions.ts +17 -0
- package/src/operations/index.ts +9 -0
- package/src/operations/open-search.ts +25 -0
- package/src/search/exa.ts +1 -1
- package/src/translations.ts +10 -9
- package/src/types/index.ts +0 -1
- package/src/types/search.ts +1 -19
- package/dist/lib/browser/app-graph-builder-KZ3V2E5U.mjs +0 -81
- package/dist/lib/browser/app-graph-builder-KZ3V2E5U.mjs.map +0 -7
- package/dist/lib/browser/chunk-HRIWTRJV.mjs +0 -22
- package/dist/lib/browser/chunk-HRIWTRJV.mjs.map +0 -7
- package/dist/lib/browser/chunk-I7YWQSUZ.mjs +0 -26
- package/dist/lib/browser/chunk-I7YWQSUZ.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZRJJXRGF.mjs +0 -282
- package/dist/lib/browser/chunk-ZRJJXRGF.mjs.map +0 -7
- package/dist/lib/browser/operation-resolver-6MBOKZQH.mjs +0 -25
- package/dist/lib/browser/operation-resolver-6MBOKZQH.mjs.map +0 -7
- package/dist/lib/browser/react-surface-RVLK6KJ5.mjs +0 -368
- package/dist/lib/browser/react-surface-RVLK6KJ5.mjs.map +0 -7
- package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts +0 -6
- package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts.map +0 -1
- package/dist/types/src/capabilities/app-graph-builder/index.d.ts +0 -3
- package/dist/types/src/capabilities/app-graph-builder/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/operation-resolver/index.d.ts +0 -3
- package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +0 -5
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface/index.d.ts +0 -3
- package/dist/types/src/capabilities/react-surface/index.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts +0 -5
- package/dist/types/src/capabilities/react-surface/react-surface.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 -6
- package/dist/types/src/components/SearchMain.d.ts.map +0 -1
- package/dist/types/src/components/SearchMain.stories.d.ts +0 -31
- package/dist/types/src/components/SearchMain.stories.d.ts.map +0 -1
- package/dist/types/src/components/SpaceMain.d.ts +0 -9
- package/dist/types/src/components/SpaceMain.d.ts.map +0 -1
- package/dist/types/src/types/action.d.ts +0 -16
- package/dist/types/src/types/action.d.ts.map +0 -1
- package/src/capabilities/app-graph-builder/index.ts +0 -7
- package/src/capabilities/operation-resolver/index.ts +0 -7
- package/src/capabilities/operation-resolver/operation-resolver.ts +0 -23
- package/src/capabilities/react-surface/index.ts +0 -7
- package/src/capabilities/react-surface/react-surface.tsx +0 -70
- package/src/components/SearchDialog.tsx +0 -130
- package/src/components/SearchMain.stories.tsx +0 -90
- package/src/components/SearchMain.tsx +0 -83
- package/src/components/SpaceMain.tsx +0 -169
- package/src/types/action.tsx +0 -18
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as Effect from 'effect/Effect';
|
|
6
|
-
|
|
7
|
-
import { Capability, Common } from '@dxos/app-framework';
|
|
8
|
-
import { Operation, OperationResolver } from '@dxos/operation';
|
|
9
|
-
|
|
10
|
-
import { SearchOperation } from '../../types';
|
|
11
|
-
|
|
12
|
-
export default Capability.makeModule(
|
|
13
|
-
Effect.fnUntraced(function* () {
|
|
14
|
-
return Capability.contributes(Common.Capability.OperationResolver, [
|
|
15
|
-
OperationResolver.make({
|
|
16
|
-
operation: SearchOperation.OpenSearch,
|
|
17
|
-
handler: Effect.fnUntraced(function* () {
|
|
18
|
-
yield* Operation.invoke(Common.LayoutOperation.UpdateComplementary, { subject: 'search' });
|
|
19
|
-
}),
|
|
20
|
-
}),
|
|
21
|
-
]);
|
|
22
|
-
}),
|
|
23
|
-
);
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as Effect from 'effect/Effect';
|
|
6
|
-
import React from 'react';
|
|
7
|
-
|
|
8
|
-
import { Capability, Common } from '@dxos/app-framework';
|
|
9
|
-
import { useActiveSpace } from '@dxos/plugin-space';
|
|
10
|
-
import { type Space, SpaceState, isSpace } from '@dxos/react-client/echo';
|
|
11
|
-
|
|
12
|
-
import { SEARCH_DIALOG, SearchDialog, type SearchDialogProps, SearchMain, SpaceMain } from '../../components';
|
|
13
|
-
import { SearchContextProvider } from '../../hooks';
|
|
14
|
-
import { meta } from '../../meta';
|
|
15
|
-
|
|
16
|
-
export default Capability.makeModule(() =>
|
|
17
|
-
Effect.succeed(
|
|
18
|
-
Capability.contributes(Common.Capability.ReactSurface, [
|
|
19
|
-
Common.createSurface({
|
|
20
|
-
id: SEARCH_DIALOG,
|
|
21
|
-
role: 'dialog',
|
|
22
|
-
filter: (data): data is { props: SearchDialogProps } => data.component === SEARCH_DIALOG,
|
|
23
|
-
component: ({ data }) => (
|
|
24
|
-
<SearchContextProvider>
|
|
25
|
-
<SearchDialog {...data.props} />
|
|
26
|
-
</SearchContextProvider>
|
|
27
|
-
),
|
|
28
|
-
}),
|
|
29
|
-
Common.createSurface({
|
|
30
|
-
id: `${SEARCH_DIALOG}/search-input`,
|
|
31
|
-
role: 'search-input',
|
|
32
|
-
component: () => {
|
|
33
|
-
const space = useActiveSpace();
|
|
34
|
-
|
|
35
|
-
return (
|
|
36
|
-
<SearchContextProvider>
|
|
37
|
-
<SearchMain space={space} />
|
|
38
|
-
</SearchContextProvider>
|
|
39
|
-
);
|
|
40
|
-
},
|
|
41
|
-
}),
|
|
42
|
-
Common.createSurface({
|
|
43
|
-
id: `${SEARCH_DIALOG}/search`,
|
|
44
|
-
role: 'deck-companion--search',
|
|
45
|
-
filter: (data): data is { subject: Space } => isSpace(data.subject),
|
|
46
|
-
component: ({ data }) => {
|
|
47
|
-
const space = data.subject;
|
|
48
|
-
if (!space) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<SearchContextProvider>
|
|
54
|
-
<SearchMain space={space} />
|
|
55
|
-
</SearchContextProvider>
|
|
56
|
-
);
|
|
57
|
-
},
|
|
58
|
-
}),
|
|
59
|
-
Common.createSurface({
|
|
60
|
-
id: `${meta.id}/space-article`,
|
|
61
|
-
role: 'article',
|
|
62
|
-
position: 'hoist',
|
|
63
|
-
filter: (data): data is { subject: Space } =>
|
|
64
|
-
// TODO(wittjosiah): Need to avoid shotgun parsing space state everywhere.
|
|
65
|
-
isSpace(data.subject) && data.subject.state.get() === SpaceState.SPACE_READY,
|
|
66
|
-
component: ({ data }) => <SpaceMain space={data.subject} />,
|
|
67
|
-
}),
|
|
68
|
-
]),
|
|
69
|
-
),
|
|
70
|
-
);
|
|
@@ -1,130 +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 { Common } from '@dxos/app-framework';
|
|
9
|
-
import { useAppGraph, useLayout, useOperationInvoker } from '@dxos/app-framework/react';
|
|
10
|
-
import { Obj } from '@dxos/echo';
|
|
11
|
-
import { Graph, 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, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
15
|
-
import { SearchList } from '@dxos/react-ui-searchlist';
|
|
16
|
-
import { descriptionText, mx, osTranslations } from '@dxos/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.Node;
|
|
25
|
-
onSelect?: (nodeId: string) => void;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const SearchListResult = forwardRef<HTMLDivElement, SearchListResultProps>(({ node, onSelect }, forwardedRef) => {
|
|
29
|
-
const { t } = useTranslation(meta.id);
|
|
30
|
-
const label = toLocalizedString(node?.properties.label ?? 'never', t);
|
|
31
|
-
const handleSelect = useCallback(() => {
|
|
32
|
-
onSelect?.(node!.id);
|
|
33
|
-
}, [node, onSelect]);
|
|
34
|
-
return (
|
|
35
|
-
<SearchList.Item
|
|
36
|
-
value={node!.id}
|
|
37
|
-
label={label}
|
|
38
|
-
icon={node?.properties.icon}
|
|
39
|
-
classNames='flex gap-2 items-center pli-2'
|
|
40
|
-
onSelect={handleSelect}
|
|
41
|
-
ref={forwardedRef}
|
|
42
|
-
/>
|
|
43
|
-
);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
export type SearchDialogProps = {
|
|
47
|
-
pivotId: string;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export const SearchDialog = ({ pivotId }: SearchDialogProps) => {
|
|
51
|
-
const { t } = useTranslation(meta.id);
|
|
52
|
-
const { graph } = useAppGraph();
|
|
53
|
-
const layout = useLayout();
|
|
54
|
-
const closed = (Array.isArray(layout.inactive) ? layout.inactive : [layout.inactive])
|
|
55
|
-
.map((id) => (graph ? Graph.getNode(graph, id) : Option.none()))
|
|
56
|
-
.filter(Boolean);
|
|
57
|
-
const [queryString, setQueryString] = useState('');
|
|
58
|
-
const client = useClient();
|
|
59
|
-
const dangerouslyLoadAllObjects = useQuery(client.spaces, Filter.everything());
|
|
60
|
-
const [pending, results] = useSearchResults(queryString, dangerouslyLoadAllObjects);
|
|
61
|
-
const resultObjects = Array.from(results.keys());
|
|
62
|
-
const { invokePromise } = useOperationInvoker();
|
|
63
|
-
|
|
64
|
-
const handleSelect = useCallback(
|
|
65
|
-
async (nodeId: string) => {
|
|
66
|
-
await invokePromise(Common.LayoutOperation.UpdateDialog, { state: false });
|
|
67
|
-
|
|
68
|
-
// If node is already present in the active parts, scroll to it and close the dialog.
|
|
69
|
-
const index = layout.active.findIndex((id) => id === nodeId);
|
|
70
|
-
if (index !== -1) {
|
|
71
|
-
await invokePromise(Common.LayoutOperation.ScrollIntoView, { subject: nodeId });
|
|
72
|
-
} else {
|
|
73
|
-
await invokePromise(Common.LayoutOperation.Open, {
|
|
74
|
-
subject: [nodeId],
|
|
75
|
-
pivotId,
|
|
76
|
-
positioning: 'end',
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
[pivotId, invokePromise, layout],
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
const handleSearch = useCallback((query: string) => {
|
|
84
|
-
setQueryString(query);
|
|
85
|
-
}, []);
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
<Dialog.Content>
|
|
89
|
-
<Dialog.Title>{t('search dialog title')}</Dialog.Title>
|
|
90
|
-
<SearchList.Root onSearch={handleSearch}>
|
|
91
|
-
<div
|
|
92
|
-
role='combobox'
|
|
93
|
-
aria-expanded='true'
|
|
94
|
-
aria-label={t('search placeholder')}
|
|
95
|
-
className='flex flex-col grow overflow-hidden'
|
|
96
|
-
>
|
|
97
|
-
<SearchList.Input placeholder={t('search placeholder')} />
|
|
98
|
-
<SearchList.Content classNames='max-bs-[24rem] overflow-auto'>
|
|
99
|
-
<SearchList.Viewport>
|
|
100
|
-
{queryString.length > 0 ? (
|
|
101
|
-
resultObjects.length > 0 ? (
|
|
102
|
-
resultObjects
|
|
103
|
-
.map((object) => Graph.getNode(graph, Obj.getDXN(object).toString()))
|
|
104
|
-
.filter(Option.isSome)
|
|
105
|
-
.map((node) => <SearchListResult key={node.value.id} node={node.value} onSelect={handleSelect} />)
|
|
106
|
-
) : (
|
|
107
|
-
<p className='pli-1'>{t(pending ? 'pending results message' : 'empty results message')}</p>
|
|
108
|
-
)
|
|
109
|
-
) : (
|
|
110
|
-
<>
|
|
111
|
-
{closed.length > 0 && (
|
|
112
|
-
<h2 className={mx('mlb-1', descriptionText)}>{t('recently closed heading')}</h2>
|
|
113
|
-
)}
|
|
114
|
-
{closed.filter(Option.isSome).map((node) => (
|
|
115
|
-
<SearchListResult key={node.value.id} node={node.value} onSelect={handleSelect} />
|
|
116
|
-
))}
|
|
117
|
-
</>
|
|
118
|
-
)}
|
|
119
|
-
</SearchList.Viewport>
|
|
120
|
-
</SearchList.Content>
|
|
121
|
-
</div>
|
|
122
|
-
</SearchList.Root>
|
|
123
|
-
<Dialog.Close asChild>
|
|
124
|
-
<Button variant='primary' classNames='mbs-2'>
|
|
125
|
-
{t('close label', { ns: osTranslations })}
|
|
126
|
-
</Button>
|
|
127
|
-
</Dialog.Close>
|
|
128
|
-
</Dialog.Content>
|
|
129
|
-
);
|
|
130
|
-
};
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Decorator, type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
-
import * as Effect from 'effect/Effect';
|
|
7
|
-
import React from 'react';
|
|
8
|
-
|
|
9
|
-
import { withPluginManager } from '@dxos/app-framework/testing';
|
|
10
|
-
import { Obj } from '@dxos/echo';
|
|
11
|
-
import { TestSchema } from '@dxos/echo/testing';
|
|
12
|
-
import { ClientPlugin } from '@dxos/plugin-client';
|
|
13
|
-
import { PreviewPlugin } from '@dxos/plugin-preview';
|
|
14
|
-
import { corePlugins } from '@dxos/plugin-testing';
|
|
15
|
-
import { faker } from '@dxos/random';
|
|
16
|
-
import { useSpaces } from '@dxos/react-client/echo';
|
|
17
|
-
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
18
|
-
import { withMosaic } from '@dxos/react-ui-mosaic/testing';
|
|
19
|
-
|
|
20
|
-
import { SearchContextProvider } from '../hooks';
|
|
21
|
-
import { translations } from '../translations';
|
|
22
|
-
|
|
23
|
-
import { SearchMain } from './SearchMain';
|
|
24
|
-
|
|
25
|
-
faker.seed(1234);
|
|
26
|
-
|
|
27
|
-
const withSearchContext = (): Decorator => {
|
|
28
|
-
return (Story) => (
|
|
29
|
-
<SearchContextProvider>
|
|
30
|
-
<Story />
|
|
31
|
-
</SearchContextProvider>
|
|
32
|
-
);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const DefaultStory = () => {
|
|
36
|
-
const spaces = useSpaces();
|
|
37
|
-
const space = spaces[spaces.length - 1];
|
|
38
|
-
return <SearchMain space={space} />;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const meta = {
|
|
42
|
-
title: 'plugins/plugin-search/SearchMain',
|
|
43
|
-
component: SearchMain,
|
|
44
|
-
render: DefaultStory,
|
|
45
|
-
decorators: [
|
|
46
|
-
withTheme,
|
|
47
|
-
withLayout({ layout: 'column' }),
|
|
48
|
-
withMosaic(),
|
|
49
|
-
withSearchContext(),
|
|
50
|
-
withPluginManager({
|
|
51
|
-
plugins: [
|
|
52
|
-
...corePlugins(),
|
|
53
|
-
ClientPlugin({
|
|
54
|
-
types: [TestSchema.Task, TestSchema.Organization, TestSchema.Person],
|
|
55
|
-
onClientInitialized: ({ client }) =>
|
|
56
|
-
Effect.gen(function* () {
|
|
57
|
-
yield* Effect.promise(() => client.halo.createIdentity());
|
|
58
|
-
yield* Effect.promise(() => client.spaces.waitUntilReady());
|
|
59
|
-
const space = yield* Effect.promise(() => client.spaces.create({ name: 'Test Space' }));
|
|
60
|
-
yield* Effect.promise(() => space.waitUntilReady());
|
|
61
|
-
// Create some test data to search.
|
|
62
|
-
space.db.add(
|
|
63
|
-
Obj.make(TestSchema.Task, { title: 'Project Proposal', description: 'A proposal for a new project' }),
|
|
64
|
-
);
|
|
65
|
-
space.db.add(
|
|
66
|
-
Obj.make(TestSchema.Task, { title: 'Meeting Notes', description: 'Notes from the team meeting' }),
|
|
67
|
-
);
|
|
68
|
-
space.db.add(
|
|
69
|
-
Obj.make(TestSchema.Task, { title: 'Budget Report', description: 'Q3 financial budget report' }),
|
|
70
|
-
);
|
|
71
|
-
space.db.add(Obj.make(TestSchema.Person, { name: 'Alice Smith', email: 'alice@example.com' }));
|
|
72
|
-
space.db.add(Obj.make(TestSchema.Person, { name: 'Bob Jones', email: 'bob@example.com' }));
|
|
73
|
-
space.db.add(Obj.make(TestSchema.Organization, { name: 'Composer Project' }));
|
|
74
|
-
}),
|
|
75
|
-
}),
|
|
76
|
-
PreviewPlugin(),
|
|
77
|
-
],
|
|
78
|
-
}),
|
|
79
|
-
],
|
|
80
|
-
parameters: {
|
|
81
|
-
layout: 'fullscreen',
|
|
82
|
-
translations,
|
|
83
|
-
},
|
|
84
|
-
} satisfies Meta<typeof SearchMain>;
|
|
85
|
-
|
|
86
|
-
export default meta;
|
|
87
|
-
|
|
88
|
-
type Story = StoryObj<typeof meta>;
|
|
89
|
-
|
|
90
|
-
export const Default: Story = {};
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, { useCallback, useMemo, useState } from 'react';
|
|
6
|
-
|
|
7
|
-
import { Surface } from '@dxos/app-framework/react';
|
|
8
|
-
import { Entity, Query } from '@dxos/echo';
|
|
9
|
-
import { Filter, type Space, useQuery } from '@dxos/react-client/echo';
|
|
10
|
-
import { Toolbar, useTranslation } from '@dxos/react-ui';
|
|
11
|
-
import { Card, Mosaic, type StackTileComponent } from '@dxos/react-ui-mosaic';
|
|
12
|
-
import { Layout } from '@dxos/react-ui-mosaic';
|
|
13
|
-
import { SearchList } from '@dxos/react-ui-searchlist';
|
|
14
|
-
import { Text } from '@dxos/schema';
|
|
15
|
-
|
|
16
|
-
import { useGlobalSearch, useGlobalSearchResults, useWebSearch } from '../hooks';
|
|
17
|
-
import { meta } from '../meta';
|
|
18
|
-
import { type SearchResult } from '../types';
|
|
19
|
-
|
|
20
|
-
export const SearchMain = ({ space }: { space?: Space }) => {
|
|
21
|
-
const { t } = useTranslation(meta.id);
|
|
22
|
-
const { setMatch } = useGlobalSearch();
|
|
23
|
-
const [query, setQuery] = useState<string>();
|
|
24
|
-
// TODO(burdon): Option to search across spaces.
|
|
25
|
-
const objects = useQuery(
|
|
26
|
-
space?.db,
|
|
27
|
-
query === undefined
|
|
28
|
-
? Query.select(Filter.nothing())
|
|
29
|
-
: // TODO(dmaretskyi): Final version would walk the ancestry of the object until we find a non-system type.
|
|
30
|
-
Query.all(
|
|
31
|
-
Query.select(Filter.text(query, { type: 'full-text' })).select(Filter.not(Filter.type(Text.Text))),
|
|
32
|
-
Query.select(Filter.text(query, { type: 'full-text' }))
|
|
33
|
-
.select(Filter.type(Text.Text))
|
|
34
|
-
.referencedBy('dxos.org/type/Document', 'content'),
|
|
35
|
-
),
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
const results = useGlobalSearchResults(objects);
|
|
39
|
-
const { results: webResults } = useWebSearch({ query });
|
|
40
|
-
const allResults = useMemo(
|
|
41
|
-
() => [...results, ...webResults].filter(({ object }) => object && Entity.getLabel(object)),
|
|
42
|
-
[results, webResults],
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
const handleSearch = useCallback(
|
|
46
|
-
(text: string) => {
|
|
47
|
-
setQuery(text);
|
|
48
|
-
setMatch?.(text);
|
|
49
|
-
},
|
|
50
|
-
[setMatch],
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
return (
|
|
54
|
-
<Layout.Main toolbar>
|
|
55
|
-
<SearchList.Root onSearch={handleSearch}>
|
|
56
|
-
<Toolbar.Root>
|
|
57
|
-
<SearchList.Input placeholder={t('search placeholder')} />
|
|
58
|
-
</Toolbar.Root>
|
|
59
|
-
<SearchList.Content>
|
|
60
|
-
<Mosaic.Container asChild>
|
|
61
|
-
<Mosaic.Viewport>
|
|
62
|
-
<Mosaic.Stack items={allResults} getId={(result) => result.object!.id} Tile={SearchResultTile} />
|
|
63
|
-
</Mosaic.Viewport>
|
|
64
|
-
</Mosaic.Container>
|
|
65
|
-
{allResults.length === 0 && <SearchList.Empty>{t('empty results message')}</SearchList.Empty>}
|
|
66
|
-
</SearchList.Content>
|
|
67
|
-
</SearchList.Root>
|
|
68
|
-
</Layout.Main>
|
|
69
|
-
);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const SearchResultTile: StackTileComponent<SearchResult> = ({ data }) => {
|
|
73
|
-
return (
|
|
74
|
-
<Card.Root key={data.id}>
|
|
75
|
-
<Card.Toolbar>
|
|
76
|
-
<Card.DragHandle />
|
|
77
|
-
<Card.Title>{data.label ?? (data.object && Entity.getLabel(data.object))}</Card.Title>
|
|
78
|
-
<Card.Menu />
|
|
79
|
-
</Card.Toolbar>
|
|
80
|
-
<Surface role='card--content' data={{ subject: data.object }} limit={1} />
|
|
81
|
-
</Card.Root>
|
|
82
|
-
);
|
|
83
|
-
};
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
6
|
-
|
|
7
|
-
import { Common } from '@dxos/app-framework';
|
|
8
|
-
import { useAppGraph, useCapabilities, useOperationInvoker } from '@dxos/app-framework/react';
|
|
9
|
-
import { Filter, Obj, Query } from '@dxos/echo';
|
|
10
|
-
import { Graph, Node, useActionRunner, useConnections } from '@dxos/plugin-graph';
|
|
11
|
-
import { type Space, useQuery } from '@dxos/react-client/echo';
|
|
12
|
-
import { Toolbar, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
13
|
-
import { Card, Mosaic, type StackTileComponent } from '@dxos/react-ui-mosaic';
|
|
14
|
-
import { Layout } from '@dxos/react-ui-mosaic';
|
|
15
|
-
import { SearchList } from '@dxos/react-ui-searchlist';
|
|
16
|
-
import { Text } from '@dxos/schema';
|
|
17
|
-
import { getStyles } from '@dxos/ui-theme';
|
|
18
|
-
|
|
19
|
-
import { meta } from '../meta';
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
*
|
|
23
|
-
*/
|
|
24
|
-
export const SpaceMain = ({ space }: { space: Space }) => {
|
|
25
|
-
const { t } = useTranslation(meta.id);
|
|
26
|
-
const { items, handleSearch } = useSpaceItems(space);
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<Layout.Main toolbar>
|
|
30
|
-
<SearchList.Root onSearch={handleSearch}>
|
|
31
|
-
<Toolbar.Root>
|
|
32
|
-
<SearchList.Input placeholder={t('search placeholder')} />
|
|
33
|
-
</Toolbar.Root>
|
|
34
|
-
<SearchList.Content>
|
|
35
|
-
<Mosaic.Container asChild>
|
|
36
|
-
<Mosaic.Viewport padding>
|
|
37
|
-
<Mosaic.Stack items={items} getId={(node) => node.id} Tile={NodeTile} />
|
|
38
|
-
</Mosaic.Viewport>
|
|
39
|
-
</Mosaic.Container>
|
|
40
|
-
</SearchList.Content>
|
|
41
|
-
</SearchList.Root>
|
|
42
|
-
</Layout.Main>
|
|
43
|
-
);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const NodeTile: StackTileComponent<Node.Node> = ({ data: node }) => {
|
|
47
|
-
const { t } = useTranslation(meta.id);
|
|
48
|
-
const { graph } = useAppGraph();
|
|
49
|
-
const { invokeSync } = useOperationInvoker();
|
|
50
|
-
const runAction = useActionRunner();
|
|
51
|
-
|
|
52
|
-
const label = toLocalizedString(node.properties.label, t);
|
|
53
|
-
const icon = node.properties.icon ?? 'ph--placeholder--regular';
|
|
54
|
-
const iconHue = node.properties.iconHue;
|
|
55
|
-
const styles = iconHue ? getStyles(iconHue) : undefined;
|
|
56
|
-
|
|
57
|
-
const handleClick = () => {
|
|
58
|
-
if (Node.isAction(node)) {
|
|
59
|
-
// Run action if this is an action node.
|
|
60
|
-
const [parent] = Graph.getConnections(graph, node.id, 'inbound');
|
|
61
|
-
if (parent) {
|
|
62
|
-
void runAction(node, { parent });
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
// Navigate to the node.
|
|
66
|
-
invokeSync(Common.LayoutOperation.Open, { subject: [node.id] });
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
return (
|
|
71
|
-
<Card.Root fullWidth>
|
|
72
|
-
<Card.Toolbar>
|
|
73
|
-
<Card.ToolbarIconButton variant='ghost' label={label} icon={icon} iconOnly iconClassNames={styles?.icon} />
|
|
74
|
-
<Card.Title onClick={handleClick}>{label}</Card.Title>
|
|
75
|
-
<Card.Menu />
|
|
76
|
-
</Card.Toolbar>
|
|
77
|
-
</Card.Root>
|
|
78
|
-
);
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Hook to resolve metadata (icon, iconHue, etc.) for objects based on their typename.
|
|
83
|
-
*/
|
|
84
|
-
// TODO(wittjosiah): Factor out.
|
|
85
|
-
const useMetadataResolver = () => {
|
|
86
|
-
const allMetadata = useCapabilities(Common.Capability.Metadata);
|
|
87
|
-
return useCallback((typename: string) => allMetadata.find((m) => m.id === typename)?.metadata ?? {}, [allMetadata]);
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Hook to get space items with search/filter support.
|
|
92
|
-
* Returns direct children when no query, or full-text search results when searching.
|
|
93
|
-
*/
|
|
94
|
-
const useSpaceItems = (space: Space) => {
|
|
95
|
-
const { graph } = useAppGraph();
|
|
96
|
-
const [query, setQuery] = useState<string>();
|
|
97
|
-
const resolveMetadata = useMetadataResolver();
|
|
98
|
-
|
|
99
|
-
// Expand the space node to load its children (needed when navigating directly to a space URL).
|
|
100
|
-
useEffect(() => {
|
|
101
|
-
const frame = requestAnimationFrame(() => {
|
|
102
|
-
Graph.expand(graph, space.id, 'outbound');
|
|
103
|
-
});
|
|
104
|
-
return () => cancelAnimationFrame(frame);
|
|
105
|
-
}, [graph, space.id]);
|
|
106
|
-
|
|
107
|
-
// Get direct children of the space node for the default view.
|
|
108
|
-
const children = useConnections(graph, space.id, 'outbound');
|
|
109
|
-
|
|
110
|
-
const handleSearch = useCallback((text: string) => {
|
|
111
|
-
setQuery(text);
|
|
112
|
-
}, []);
|
|
113
|
-
|
|
114
|
-
// TODO(dmaretskyi): Switch back to QueryEditor once query builder is ready for production.
|
|
115
|
-
// Query results using full-text search.
|
|
116
|
-
const results = useQuery(
|
|
117
|
-
space.db,
|
|
118
|
-
query === undefined
|
|
119
|
-
? Query.select(Filter.nothing())
|
|
120
|
-
: Query.all(
|
|
121
|
-
Query.select(Filter.text(query, { type: 'full-text' })).select(Filter.not(Filter.type(Text.Text))),
|
|
122
|
-
Query.select(Filter.text(query, { type: 'full-text' }))
|
|
123
|
-
.select(Filter.type(Text.Text))
|
|
124
|
-
.referencedBy('dxos.org/type/Document', 'content'),
|
|
125
|
-
),
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
// Determine if query is empty (show default view).
|
|
129
|
-
const isQueryEmpty = !query?.trim();
|
|
130
|
-
|
|
131
|
-
// Filter children to those which are objects or actions with disposition 'item'.
|
|
132
|
-
const filteredChildren = useMemo(
|
|
133
|
-
() =>
|
|
134
|
-
children.filter((node) => {
|
|
135
|
-
// Include regular objects.
|
|
136
|
-
if (Obj.isObject(node.data)) {
|
|
137
|
-
return true;
|
|
138
|
-
}
|
|
139
|
-
// Include actions with disposition 'item'.
|
|
140
|
-
return Node.isAction(node) && node.properties.disposition === 'item';
|
|
141
|
-
}),
|
|
142
|
-
[children],
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
// When showing default view, use nodes (which may include actions).
|
|
146
|
-
// When showing search results, wrap objects in a compatible shape with resolved metadata.
|
|
147
|
-
const items = useMemo(() => {
|
|
148
|
-
if (isQueryEmpty) {
|
|
149
|
-
return filteredChildren;
|
|
150
|
-
}
|
|
151
|
-
// Wrap query results as pseudo-nodes for consistent rendering.
|
|
152
|
-
return results.map((obj) => {
|
|
153
|
-
const typename = Obj.getTypename(obj);
|
|
154
|
-
const metadata = typename ? resolveMetadata(typename) : {};
|
|
155
|
-
return {
|
|
156
|
-
id: obj.id,
|
|
157
|
-
type: 'search-result',
|
|
158
|
-
data: obj,
|
|
159
|
-
properties: {
|
|
160
|
-
label: Obj.getLabel(obj) ?? obj.id,
|
|
161
|
-
icon: metadata.icon ?? 'ph--placeholder--regular',
|
|
162
|
-
iconHue: metadata.iconHue,
|
|
163
|
-
},
|
|
164
|
-
} as Node.Node;
|
|
165
|
-
});
|
|
166
|
-
}, [isQueryEmpty, filteredChildren, results, resolveMetadata]);
|
|
167
|
-
|
|
168
|
-
return { items, handleSearch };
|
|
169
|
-
};
|
package/src/types/action.tsx
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as Schema from 'effect/Schema';
|
|
6
|
-
|
|
7
|
-
import { Operation } from '@dxos/operation';
|
|
8
|
-
|
|
9
|
-
import { meta } from '../meta';
|
|
10
|
-
|
|
11
|
-
const SEARCH_OPERATION = `${meta.id}/operation`;
|
|
12
|
-
|
|
13
|
-
export namespace SearchOperation {
|
|
14
|
-
export const OpenSearch = Operation.make({
|
|
15
|
-
meta: { key: `${SEARCH_OPERATION}/open-search`, name: 'Open Search' },
|
|
16
|
-
schema: { input: Schema.Void, output: Schema.Void },
|
|
17
|
-
});
|
|
18
|
-
}
|