@dxos/plugin-search 0.8.4-main.e098934 → 0.8.4-main.e8ec1fe
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/dist/lib/browser/{app-graph-builder-D2QQTIIR.mjs → app-graph-builder-HQR6P4C7.mjs} +17 -16
- package/dist/lib/browser/app-graph-builder-HQR6P4C7.mjs.map +7 -0
- package/dist/lib/browser/chunk-GN2FSWTM.mjs +22 -0
- package/dist/lib/browser/chunk-GN2FSWTM.mjs.map +7 -0
- package/dist/lib/browser/{chunk-JVMYGOKS.mjs → chunk-TCVYYI44.mjs} +5 -5
- package/dist/lib/browser/chunk-TCVYYI44.mjs.map +7 -0
- package/dist/lib/browser/{chunk-YJGLEPHU.mjs → chunk-ZEP4O5SU.mjs} +109 -8
- package/dist/lib/browser/chunk-ZEP4O5SU.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +11 -11
- package/dist/lib/browser/index.mjs.map +2 -2
- package/dist/lib/browser/{intent-resolver-NXFDPFHC.mjs → intent-resolver-UYQA6UUQ.mjs} +5 -5
- package/dist/lib/browser/{intent-resolver-NXFDPFHC.mjs.map → intent-resolver-UYQA6UUQ.mjs.map} +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react-surface-H5CKQVII.mjs +307 -0
- package/dist/lib/browser/react-surface-H5CKQVII.mjs.map +7 -0
- package/dist/types/src/SearchPlugin.d.ts +1 -1
- package/dist/types/src/SearchPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/Search.stories.d.ts +1 -5
- package/dist/types/src/components/Search.stories.d.ts.map +1 -1
- package/dist/types/src/components/SearchDialog.d.ts +1 -1
- package/dist/types/src/components/SearchDialog.d.ts.map +1 -1
- package/dist/types/src/components/SearchMain.d.ts +4 -5
- package/dist/types/src/components/SearchMain.d.ts.map +1 -1
- package/dist/types/src/components/SearchResults/SearchResults.d.ts +9 -9
- package/dist/types/src/components/SearchResults/SearchResults.d.ts.map +1 -1
- package/dist/types/src/components/SearchResults/SearchResults.stories.d.ts +1 -2
- package/dist/types/src/components/SearchResults/SearchResults.stories.d.ts.map +1 -1
- package/dist/types/src/components/Searchbar/Searchbar.d.ts +5 -9
- package/dist/types/src/components/Searchbar/Searchbar.d.ts.map +1 -1
- package/dist/types/src/components/Searchbar/Searchbar.stories.d.ts +1 -2
- package/dist/types/src/components/Searchbar/Searchbar.stories.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/types/src/meta.d.ts +1 -2
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/search/exa.d.ts +1 -1
- package/dist/types/src/search/exa.d.ts.map +1 -1
- package/dist/types/src/types/action.d.ts +3 -3
- package/dist/types/src/types/action.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +39 -39
- package/src/SearchPlugin.tsx +41 -42
- package/src/capabilities/app-graph-builder.ts +14 -13
- package/src/capabilities/react-surface.tsx +0 -3
- package/src/components/Search.stories.tsx +6 -17
- package/src/components/SearchDialog.tsx +23 -11
- package/src/components/SearchMain.tsx +31 -37
- package/src/components/SearchResults/SearchResults.stories.tsx +4 -5
- package/src/components/SearchResults/SearchResults.tsx +46 -49
- package/src/components/Searchbar/Searchbar.stories.tsx +1 -3
- package/src/components/Searchbar/Searchbar.tsx +26 -45
- package/src/hooks/index.ts +2 -0
- package/src/hooks/sync.ts +5 -4
- package/src/hooks/useSearchResults.ts +2 -2
- package/src/hooks/useWebSearch.ts +1 -1
- package/src/meta.ts +8 -5
- package/src/search/exa.test.ts +8 -10
- package/src/search/exa.ts +6 -4
- package/src/types/action.tsx +3 -3
- package/dist/lib/browser/app-graph-builder-D2QQTIIR.mjs.map +0 -7
- package/dist/lib/browser/chunk-JVMYGOKS.mjs.map +0 -7
- package/dist/lib/browser/chunk-KNS62YL2.mjs +0 -20
- package/dist/lib/browser/chunk-KNS62YL2.mjs.map +0 -7
- package/dist/lib/browser/chunk-YJGLEPHU.mjs.map +0 -7
- package/dist/lib/browser/react-surface-LNREIVO7.mjs +0 -468
- package/dist/lib/browser/react-surface-LNREIVO7.mjs.map +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/plugin-search",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.e8ec1fe",
|
|
4
4
|
"description": "Braneframe sketch plugin",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -27,50 +27,50 @@
|
|
|
27
27
|
"@preact-signals/safe-react": "^0.9.0",
|
|
28
28
|
"exa-js": "^1.5.12",
|
|
29
29
|
"main-thread-scheduling": "^14.1.1",
|
|
30
|
-
"@dxos/ai": "0.8.4-main.
|
|
31
|
-
"@dxos/app-framework": "0.8.4-main.
|
|
32
|
-
"@dxos/assistant": "0.8.4-main.
|
|
33
|
-
"@dxos/blueprints": "0.8.4-main.
|
|
34
|
-
"@dxos/debug": "0.8.4-main.
|
|
35
|
-
"@dxos/echo": "0.8.4-main.
|
|
36
|
-
"@dxos/echo-protocol": "0.8.4-main.
|
|
37
|
-
"@dxos/
|
|
38
|
-
"@dxos/
|
|
39
|
-
"@dxos/
|
|
40
|
-
"@dxos/log": "0.8.4-main.
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/plugin-deck": "0.8.4-main.
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/plugin-
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/react-ui-
|
|
47
|
-
"@dxos/react-ui-
|
|
48
|
-
"@dxos/
|
|
49
|
-
"@dxos/
|
|
50
|
-
"@dxos/util": "0.8.4-main.
|
|
30
|
+
"@dxos/ai": "0.8.4-main.e8ec1fe",
|
|
31
|
+
"@dxos/app-framework": "0.8.4-main.e8ec1fe",
|
|
32
|
+
"@dxos/assistant": "0.8.4-main.e8ec1fe",
|
|
33
|
+
"@dxos/blueprints": "0.8.4-main.e8ec1fe",
|
|
34
|
+
"@dxos/debug": "0.8.4-main.e8ec1fe",
|
|
35
|
+
"@dxos/echo": "0.8.4-main.e8ec1fe",
|
|
36
|
+
"@dxos/echo-protocol": "0.8.4-main.e8ec1fe",
|
|
37
|
+
"@dxos/effect": "0.8.4-main.e8ec1fe",
|
|
38
|
+
"@dxos/invariant": "0.8.4-main.e8ec1fe",
|
|
39
|
+
"@dxos/live-object": "0.8.4-main.e8ec1fe",
|
|
40
|
+
"@dxos/log": "0.8.4-main.e8ec1fe",
|
|
41
|
+
"@dxos/plugin-client": "0.8.4-main.e8ec1fe",
|
|
42
|
+
"@dxos/plugin-deck": "0.8.4-main.e8ec1fe",
|
|
43
|
+
"@dxos/plugin-graph": "0.8.4-main.e8ec1fe",
|
|
44
|
+
"@dxos/plugin-space": "0.8.4-main.e8ec1fe",
|
|
45
|
+
"@dxos/react-client": "0.8.4-main.e8ec1fe",
|
|
46
|
+
"@dxos/react-ui-searchlist": "0.8.4-main.e8ec1fe",
|
|
47
|
+
"@dxos/react-ui-stack": "0.8.4-main.e8ec1fe",
|
|
48
|
+
"@dxos/schema": "0.8.4-main.e8ec1fe",
|
|
49
|
+
"@dxos/types": "0.8.4-main.e8ec1fe",
|
|
50
|
+
"@dxos/util": "0.8.4-main.e8ec1fe"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@effect-
|
|
54
|
-
"@effect/platform": "0.
|
|
55
|
-
"@types/react": "~
|
|
56
|
-
"@types/react-dom": "~
|
|
57
|
-
"effect": "3.
|
|
58
|
-
"react": "~
|
|
59
|
-
"react-dom": "~
|
|
60
|
-
"vite": "7.1.
|
|
61
|
-
"@dxos/random": "0.8.4-main.
|
|
62
|
-
"@dxos/react-ui
|
|
63
|
-
"@dxos/
|
|
64
|
-
"@dxos/
|
|
53
|
+
"@effect-atom/atom-react": "^0.3.4",
|
|
54
|
+
"@effect/platform": "0.92.1",
|
|
55
|
+
"@types/react": "~19.2.2",
|
|
56
|
+
"@types/react-dom": "~19.2.2",
|
|
57
|
+
"effect": "3.18.3",
|
|
58
|
+
"react": "~19.2.0",
|
|
59
|
+
"react-dom": "~19.2.0",
|
|
60
|
+
"vite": "7.1.9",
|
|
61
|
+
"@dxos/random": "0.8.4-main.e8ec1fe",
|
|
62
|
+
"@dxos/react-ui": "0.8.4-main.e8ec1fe",
|
|
63
|
+
"@dxos/react-ui-theme": "0.8.4-main.e8ec1fe",
|
|
64
|
+
"@dxos/storybook-utils": "0.8.4-main.e8ec1fe"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@effect-
|
|
67
|
+
"@effect-atom/atom-react": "^0.3.4",
|
|
68
68
|
"@effect/platform": "^0.80.12",
|
|
69
69
|
"effect": "^3.13.3",
|
|
70
|
-
"react": "
|
|
71
|
-
"react-dom": "
|
|
72
|
-
"@dxos/react-ui
|
|
73
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
70
|
+
"react": "^19.0.0",
|
|
71
|
+
"react-dom": "^19.0.0",
|
|
72
|
+
"@dxos/react-ui": "0.8.4-main.e8ec1fe",
|
|
73
|
+
"@dxos/react-ui-theme": "0.8.4-main.e8ec1fe"
|
|
74
74
|
},
|
|
75
75
|
"publishConfig": {
|
|
76
76
|
"access": "public"
|
package/src/SearchPlugin.tsx
CHANGED
|
@@ -9,46 +9,45 @@ import { SEARCH_RESULT, meta } from './meta';
|
|
|
9
9
|
import { translations } from './translations';
|
|
10
10
|
import { type SearchResult } from './types';
|
|
11
11
|
|
|
12
|
-
export const SearchPlugin = () =>
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
},
|
|
12
|
+
export const SearchPlugin = definePlugin(meta, () => [
|
|
13
|
+
defineModule({
|
|
14
|
+
id: `${meta.id}/module/translations`,
|
|
15
|
+
activatesOn: Events.SetupTranslations,
|
|
16
|
+
activate: () => contributes(Capabilities.Translations, translations),
|
|
17
|
+
}),
|
|
18
|
+
defineModule({
|
|
19
|
+
id: `${meta.id}/module/metadata`,
|
|
20
|
+
activatesOn: Events.SetupMetadata,
|
|
21
|
+
activate: () =>
|
|
22
|
+
contributes(Capabilities.Metadata, {
|
|
23
|
+
id: SEARCH_RESULT,
|
|
24
|
+
metadata: {
|
|
25
|
+
parse: (item: SearchResult, type: string) => {
|
|
26
|
+
switch (type) {
|
|
27
|
+
case 'node':
|
|
28
|
+
return { id: item.id, label: item.label, data: item.object };
|
|
29
|
+
case 'object':
|
|
30
|
+
return item.object;
|
|
31
|
+
case 'view-object':
|
|
32
|
+
return item;
|
|
33
|
+
}
|
|
36
34
|
},
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
}),
|
|
38
|
+
defineModule({
|
|
39
|
+
id: `${meta.id}/module/app-graph-builder`,
|
|
40
|
+
activatesOn: Events.SetupAppGraph,
|
|
41
|
+
activate: AppGraphBuilder,
|
|
42
|
+
}),
|
|
43
|
+
defineModule({
|
|
44
|
+
id: `${meta.id}/module/intent-resolver`,
|
|
45
|
+
activatesOn: Events.SetupIntentResolver,
|
|
46
|
+
activate: IntentResolver,
|
|
47
|
+
}),
|
|
48
|
+
defineModule({
|
|
49
|
+
id: `${meta.id}/module/react-surface`,
|
|
50
|
+
activatesOn: Events.SetupReactSurface,
|
|
51
|
+
activate: ReactSurface,
|
|
52
|
+
}),
|
|
53
|
+
]);
|
|
@@ -2,29 +2,30 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
5
|
+
import { Atom } from '@effect-atom/atom-react';
|
|
6
|
+
import * as Function from 'effect/Function';
|
|
7
|
+
import * as Option from 'effect/Option';
|
|
7
8
|
|
|
8
9
|
import { Capabilities, type PluginContext, contributes, createIntent } from '@dxos/app-framework';
|
|
9
10
|
import { ClientCapabilities } from '@dxos/plugin-client';
|
|
10
11
|
import { ATTENDABLE_PATH_SEPARATOR, DECK_COMPANION_TYPE } from '@dxos/plugin-deck/types';
|
|
11
|
-
import { ROOT_ID,
|
|
12
|
+
import { ROOT_ID, atomFromSignal, createExtension } from '@dxos/plugin-graph';
|
|
12
13
|
import { parseId } from '@dxos/react-client/echo';
|
|
13
14
|
|
|
14
|
-
import {
|
|
15
|
+
import { meta } from '../meta';
|
|
15
16
|
import { SearchAction } from '../types';
|
|
16
17
|
|
|
17
18
|
export default (context: PluginContext) =>
|
|
18
19
|
contributes(Capabilities.AppGraphBuilder, [
|
|
19
20
|
createExtension({
|
|
20
|
-
id: `${
|
|
21
|
+
id: `${meta.id}/space-search`,
|
|
21
22
|
connector: (node) =>
|
|
22
|
-
|
|
23
|
-
pipe(
|
|
23
|
+
Atom.make((get) =>
|
|
24
|
+
Function.pipe(
|
|
24
25
|
get(node),
|
|
25
26
|
Option.flatMap((node) => (node.id === ROOT_ID ? Option.some(node) : Option.none())),
|
|
26
27
|
Option.map((node) => {
|
|
27
|
-
const workspace = get(
|
|
28
|
+
const workspace = get(atomFromSignal(() => context.getCapability(Capabilities.Layout).workspace));
|
|
28
29
|
const client = context.getCapability(ClientCapabilities.Client);
|
|
29
30
|
const { spaceId } = parseId(workspace);
|
|
30
31
|
const space = spaceId ? client.spaces.get(spaceId) : null;
|
|
@@ -35,7 +36,7 @@ export default (context: PluginContext) =>
|
|
|
35
36
|
type: DECK_COMPANION_TYPE,
|
|
36
37
|
data: space,
|
|
37
38
|
properties: {
|
|
38
|
-
label: ['search label', { ns:
|
|
39
|
+
label: ['search label', { ns: meta.id }],
|
|
39
40
|
icon: 'ph--magnifying-glass--regular',
|
|
40
41
|
disposition: 'hidden',
|
|
41
42
|
},
|
|
@@ -47,10 +48,10 @@ export default (context: PluginContext) =>
|
|
|
47
48
|
),
|
|
48
49
|
}),
|
|
49
50
|
createExtension({
|
|
50
|
-
id:
|
|
51
|
+
id: meta.id,
|
|
51
52
|
actions: (node) =>
|
|
52
|
-
|
|
53
|
-
pipe(
|
|
53
|
+
Atom.make((get) =>
|
|
54
|
+
Function.pipe(
|
|
54
55
|
get(node),
|
|
55
56
|
Option.flatMap((node) => (node.id === ROOT_ID ? Option.some(node) : Option.none())),
|
|
56
57
|
Option.map(() => {
|
|
@@ -62,7 +63,7 @@ export default (context: PluginContext) =>
|
|
|
62
63
|
await dispatch(createIntent(SearchAction.OpenSearch));
|
|
63
64
|
},
|
|
64
65
|
properties: {
|
|
65
|
-
label: ['search action label', { ns:
|
|
66
|
+
label: ['search action label', { ns: meta.id }],
|
|
66
67
|
icon: 'ph--magnifying-glass--regular',
|
|
67
68
|
keyBinding: {
|
|
68
69
|
macos: 'shift+meta+f',
|
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
6
|
-
|
|
7
|
-
import { type Decorator, type Meta, type StoryFn, type StoryObj } from '@storybook/react-vite';
|
|
5
|
+
import { type Decorator, type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
6
|
import React, { useState } from 'react';
|
|
9
7
|
|
|
10
8
|
import { faker } from '@dxos/random';
|
|
11
|
-
import { withLayout, withTheme } from '@dxos/
|
|
9
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
12
10
|
|
|
13
11
|
import { SearchContextProvider, useGlobalSearch, useGlobalSearchResults } from '../hooks';
|
|
14
12
|
|
|
@@ -28,7 +26,7 @@ const DefaultStory = ({ objects, ...props }: StoryProps) => {
|
|
|
28
26
|
|
|
29
27
|
return (
|
|
30
28
|
<div className='flex grow justify-center overflow-hidden'>
|
|
31
|
-
<div className='flex flex-col
|
|
29
|
+
<div className='flex flex-col is-[300px] m-4 overflow-hidden'>
|
|
32
30
|
<Searchbar variant='subdued' placeholder='Enter regular expression...' onChange={setMatch} {...props} />
|
|
33
31
|
<SearchResults items={filteredItems} selected={selected} onSelect={setSelected} />
|
|
34
32
|
</div>
|
|
@@ -36,8 +34,8 @@ const DefaultStory = ({ objects, ...props }: StoryProps) => {
|
|
|
36
34
|
);
|
|
37
35
|
};
|
|
38
36
|
|
|
39
|
-
const
|
|
40
|
-
return (Story
|
|
37
|
+
const withSearchContext = (): Decorator => {
|
|
38
|
+
return (Story) => (
|
|
41
39
|
<SearchContextProvider>
|
|
42
40
|
<Story />
|
|
43
41
|
</SearchContextProvider>
|
|
@@ -58,16 +56,7 @@ const meta = {
|
|
|
58
56
|
title: 'plugins/plugin-search/Search',
|
|
59
57
|
component: Searchbar,
|
|
60
58
|
render: DefaultStory,
|
|
61
|
-
decorators: [
|
|
62
|
-
withTheme,
|
|
63
|
-
withLayout({
|
|
64
|
-
fullscreen: true,
|
|
65
|
-
}),
|
|
66
|
-
SearchContextDecorator(),
|
|
67
|
-
],
|
|
68
|
-
parameters: {
|
|
69
|
-
layout: 'fullscreen',
|
|
70
|
-
},
|
|
59
|
+
decorators: [withTheme, withLayout({ container: 'column' }), withSearchContext()],
|
|
71
60
|
} satisfies Meta<typeof Searchbar>;
|
|
72
61
|
|
|
73
62
|
export default meta;
|
|
@@ -2,28 +2,30 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Option from 'effect/Option';
|
|
6
6
|
import React, { forwardRef, useCallback, useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import { LayoutAction, createIntent
|
|
8
|
+
import { LayoutAction, createIntent } from '@dxos/app-framework';
|
|
9
|
+
import { useAppGraph, useIntentDispatcher, useLayout } from '@dxos/app-framework/react';
|
|
10
|
+
import { Obj } from '@dxos/echo';
|
|
9
11
|
import { type Node } from '@dxos/plugin-graph';
|
|
10
12
|
import { useClient } from '@dxos/react-client';
|
|
11
|
-
import { Filter,
|
|
13
|
+
import { Filter, useQuery } from '@dxos/react-client/echo';
|
|
12
14
|
import { Button, Dialog, Icon, toLocalizedString, useTranslation } from '@dxos/react-ui';
|
|
13
15
|
import { SearchList, type SearchListItemProps } from '@dxos/react-ui-searchlist';
|
|
14
16
|
import { descriptionText, mx } from '@dxos/react-ui-theme';
|
|
15
17
|
|
|
16
18
|
import { useSearchResults } from '../hooks';
|
|
17
|
-
import {
|
|
19
|
+
import { meta } from '../meta';
|
|
18
20
|
|
|
19
|
-
export const SEARCH_DIALOG = `${
|
|
21
|
+
export const SEARCH_DIALOG = `${meta.id}/SearchDialog`;
|
|
20
22
|
|
|
21
23
|
type SearchListResultProps = {
|
|
22
24
|
node: Node;
|
|
23
25
|
} & Pick<SearchListItemProps, 'onSelect'>;
|
|
24
26
|
|
|
25
27
|
const SearchListResult = forwardRef<HTMLDivElement, SearchListResultProps>(({ node, onSelect }, forwardedRef) => {
|
|
26
|
-
const { t } = useTranslation(
|
|
28
|
+
const { t } = useTranslation(meta.id);
|
|
27
29
|
const label = toLocalizedString(node?.properties.label ?? 'never', t);
|
|
28
30
|
return (
|
|
29
31
|
<SearchList.Item
|
|
@@ -44,7 +46,7 @@ export type SearchDialogProps = {
|
|
|
44
46
|
};
|
|
45
47
|
|
|
46
48
|
export const SearchDialog = ({ pivotId }: SearchDialogProps) => {
|
|
47
|
-
const { t } = useTranslation(
|
|
49
|
+
const { t } = useTranslation(meta.id);
|
|
48
50
|
const { graph } = useAppGraph();
|
|
49
51
|
const layout = useLayout();
|
|
50
52
|
const closed = (Array.isArray(layout.inactive) ? layout.inactive : [layout.inactive])
|
|
@@ -59,12 +61,22 @@ export const SearchDialog = ({ pivotId }: SearchDialogProps) => {
|
|
|
59
61
|
|
|
60
62
|
const handleSelect = useCallback(
|
|
61
63
|
async (nodeId: string) => {
|
|
62
|
-
await dispatch(
|
|
64
|
+
await dispatch(
|
|
65
|
+
createIntent(LayoutAction.UpdateDialog, {
|
|
66
|
+
part: 'dialog',
|
|
67
|
+
options: { state: false },
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
63
70
|
|
|
64
71
|
// If node is already present in the active parts, scroll to it and close the dialog.
|
|
65
72
|
const index = layout.active.findIndex((id) => id === nodeId);
|
|
66
73
|
if (index !== -1) {
|
|
67
|
-
await dispatch(
|
|
74
|
+
await dispatch(
|
|
75
|
+
createIntent(LayoutAction.ScrollIntoView, {
|
|
76
|
+
part: 'current',
|
|
77
|
+
subject: nodeId,
|
|
78
|
+
}),
|
|
79
|
+
);
|
|
68
80
|
} else {
|
|
69
81
|
await dispatch(
|
|
70
82
|
createIntent(LayoutAction.Open, {
|
|
@@ -91,13 +103,13 @@ export const SearchDialog = ({ pivotId }: SearchDialogProps) => {
|
|
|
91
103
|
setQueryString(nextValue);
|
|
92
104
|
}}
|
|
93
105
|
placeholder={t('search placeholder')}
|
|
94
|
-
classNames='
|
|
106
|
+
classNames='pli-1 my-2'
|
|
95
107
|
/>
|
|
96
108
|
<SearchList.Content classNames='max-bs-[24rem] overflow-auto'>
|
|
97
109
|
{queryString.length > 0 ? (
|
|
98
110
|
resultObjects.length > 0 ? (
|
|
99
111
|
resultObjects
|
|
100
|
-
.map((object) => graph.getNode(
|
|
112
|
+
.map((object) => graph.getNode(Obj.getDXN(object).toString()))
|
|
101
113
|
.filter(Option.isSome)
|
|
102
114
|
.map((node) => <SearchListResult key={node.value.id} node={node.value} onSelect={handleSelect} />)
|
|
103
115
|
) : (
|
|
@@ -2,67 +2,61 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React, {
|
|
5
|
+
import React, { useState } from 'react';
|
|
6
6
|
|
|
7
|
-
import { log } from '@dxos/log';
|
|
8
7
|
import { useClient } from '@dxos/react-client';
|
|
9
8
|
import { Filter, type Space, useQuery } from '@dxos/react-client/echo';
|
|
10
|
-
import {
|
|
9
|
+
import { useTranslation } from '@dxos/react-ui';
|
|
10
|
+
import { Stack, StackItem } from '@dxos/react-ui-stack';
|
|
11
11
|
import { activeSurface, mx } from '@dxos/react-ui-theme';
|
|
12
12
|
|
|
13
|
-
import { useGlobalSearch, useGlobalSearchResults } from '../hooks';
|
|
14
|
-
import {
|
|
15
|
-
import { SEARCH_PLUGIN } from '../meta';
|
|
13
|
+
import { useGlobalSearch, useGlobalSearchResults, useWebSearch } from '../hooks';
|
|
14
|
+
import { meta } from '../meta';
|
|
16
15
|
|
|
17
16
|
import { Searchbar } from './Searchbar';
|
|
18
17
|
import { SearchResults } from './SearchResults';
|
|
19
18
|
|
|
20
|
-
export const SearchMain
|
|
21
|
-
const { t } = useTranslation(
|
|
19
|
+
export const SearchMain = ({ space }: { space?: Space }) => {
|
|
20
|
+
const { t } = useTranslation(meta.id);
|
|
22
21
|
const client = useClient();
|
|
23
22
|
const { setMatch } = useGlobalSearch();
|
|
24
23
|
const [query, setQuery] = useState<string>();
|
|
25
|
-
// TODO(burdon):
|
|
24
|
+
// TODO(burdon): Option to search across spaces.
|
|
26
25
|
const allSpaces = false;
|
|
27
|
-
|
|
28
|
-
// TODO(burdon): Returns ALL objects (e.g., incl. Text objects that are fields of parent objects).
|
|
29
26
|
const objects = useQuery(allSpaces ? client.spaces : space, Filter.everything());
|
|
30
27
|
const results = useGlobalSearchResults(objects);
|
|
31
28
|
|
|
32
|
-
const {
|
|
33
|
-
runSearch,
|
|
34
|
-
results: webResults,
|
|
35
|
-
isLoading,
|
|
36
|
-
} = useWebSearch({
|
|
37
|
-
query,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
const [selected, setSelected] = useState<string>();
|
|
29
|
+
const { runSearch, results: webResults } = useWebSearch({ query });
|
|
41
30
|
|
|
42
31
|
// TODO(burdon): Activate and/or filter current main (set context).
|
|
32
|
+
const [selected, setSelected] = useState<string>();
|
|
43
33
|
const handleSelect = (id: string) => {
|
|
44
34
|
setSelected((selected) => (selected === id ? undefined : id));
|
|
45
35
|
};
|
|
46
36
|
|
|
47
37
|
const allResults = [...results, ...webResults];
|
|
48
|
-
log.info('results', { results, webResults });
|
|
49
38
|
|
|
50
39
|
return (
|
|
51
|
-
<
|
|
52
|
-
<
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
40
|
+
<Stack orientation='vertical' size='contain' itemsCount={1} rail={false} classNames={['bs-full', activeSurface]}>
|
|
41
|
+
<StackItem.Root item={{ id: 'search' }} role='article'>
|
|
42
|
+
<StackItem.Content toolbar>
|
|
43
|
+
<Searchbar
|
|
44
|
+
classNames='pli-2'
|
|
45
|
+
placeholder={t('search placeholder')}
|
|
46
|
+
delay={300}
|
|
47
|
+
onChange={(text) => {
|
|
48
|
+
setQuery(text);
|
|
49
|
+
setMatch?.(text);
|
|
50
|
+
}}
|
|
51
|
+
onSubmit={runSearch}
|
|
52
|
+
/>
|
|
53
|
+
{allResults.length > 0 && (
|
|
54
|
+
<div className={mx('flex flex-col bs-full overflow-hidden')}>
|
|
55
|
+
<SearchResults items={allResults} selected={selected} onSelect={handleSelect} />
|
|
56
|
+
</div>
|
|
57
|
+
)}
|
|
58
|
+
</StackItem.Content>
|
|
59
|
+
</StackItem.Root>
|
|
60
|
+
</Stack>
|
|
67
61
|
);
|
|
68
62
|
};
|
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@dxos-theme';
|
|
6
|
-
|
|
7
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
6
|
import React, { useState } from 'react';
|
|
9
7
|
|
|
8
|
+
import { withPluginManager } from '@dxos/app-framework/testing';
|
|
10
9
|
import { faker } from '@dxos/random';
|
|
11
|
-
import {
|
|
10
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
12
11
|
|
|
13
12
|
import { filterObjectsSync } from '../../hooks';
|
|
14
13
|
|
|
@@ -21,7 +20,7 @@ const DefaultStory = (props: SearchResultsProps) => {
|
|
|
21
20
|
|
|
22
21
|
return (
|
|
23
22
|
<div className='flex grow justify-center overflow-hidden'>
|
|
24
|
-
<div className='flex
|
|
23
|
+
<div className='flex is-[300px] m-4 overflow-hidden'>
|
|
25
24
|
<SearchResults {...props} selected={selected} onSelect={setSelected} />
|
|
26
25
|
</div>
|
|
27
26
|
</div>
|
|
@@ -42,7 +41,7 @@ const meta = {
|
|
|
42
41
|
title: 'plugins/plugin-search/SearchResults',
|
|
43
42
|
component: SearchResults,
|
|
44
43
|
render: DefaultStory,
|
|
45
|
-
decorators: [withTheme,
|
|
44
|
+
decorators: [withTheme, withPluginManager({ plugins: [] })],
|
|
46
45
|
parameters: {
|
|
47
46
|
layout: 'fullscreen',
|
|
48
47
|
},
|
|
@@ -4,12 +4,57 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { type FC, forwardRef } from 'react';
|
|
6
6
|
|
|
7
|
+
import { Surface } from '@dxos/app-framework/react';
|
|
8
|
+
import { Obj } from '@dxos/echo';
|
|
7
9
|
import { Card } from '@dxos/react-ui-stack';
|
|
8
10
|
import { ghostHover } from '@dxos/react-ui-theme';
|
|
9
11
|
|
|
10
|
-
import { SEARCH_RESULT } from '../../meta';
|
|
11
12
|
import { type SearchResult } from '../../types';
|
|
12
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
|
+
|
|
13
58
|
export const Snippet: FC<{ text: string; match?: RegExp }> = ({ text, match }) => {
|
|
14
59
|
let content = <>{text}</>;
|
|
15
60
|
if (match) {
|
|
@@ -36,51 +81,3 @@ export const Snippet: FC<{ text: string; match?: RegExp }> = ({ text, match }) =
|
|
|
36
81
|
|
|
37
82
|
return <span className='text-xs mb-1 line-clamp-3 text-neutral-300'>{content}</span>;
|
|
38
83
|
};
|
|
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 && (
|
|
52
|
-
<>
|
|
53
|
-
<div className='text-xs text-neutral-400 ml-4'>{objectType}</div>
|
|
54
|
-
</>
|
|
55
|
-
)}
|
|
56
|
-
<Card.Heading>{label ?? 'Untitled'}</Card.Heading>
|
|
57
|
-
{snippet && <Snippet text={snippet} match={match} />}
|
|
58
|
-
</Card.StaticRoot>
|
|
59
|
-
);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
export type SearchResultsProps = {
|
|
63
|
-
match?: RegExp;
|
|
64
|
-
items: SearchResult[];
|
|
65
|
-
selected?: string;
|
|
66
|
-
onSelect?: (id: string) => void;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
// TODO(burdon): Key cursor up/down.
|
|
70
|
-
export const SearchResults = ({ items, selected, onSelect }: SearchResultsProps) => {
|
|
71
|
-
return (
|
|
72
|
-
<div className='flex flex-col grow overflow-y-auto'>
|
|
73
|
-
<div className='flex flex-col'>
|
|
74
|
-
{items.map((item) => (
|
|
75
|
-
<SearchItem
|
|
76
|
-
key={item.id}
|
|
77
|
-
type={SEARCH_RESULT}
|
|
78
|
-
{...item}
|
|
79
|
-
onSelect={onSelect}
|
|
80
|
-
selected={selected === item.id}
|
|
81
|
-
/>
|
|
82
|
-
))}
|
|
83
|
-
</div>
|
|
84
|
-
</div>
|
|
85
|
-
);
|
|
86
|
-
};
|