@dxos/plugin-search 0.8.4-main.ae835ea → 0.8.4-main.bc674ce

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/dist/lib/browser/app-graph-builder-KZ3V2E5U.mjs +81 -0
  2. package/dist/lib/browser/app-graph-builder-KZ3V2E5U.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-GN2FSWTM.mjs → chunk-HRIWTRJV.mjs} +1 -1
  4. package/dist/lib/browser/chunk-HRIWTRJV.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-I7YWQSUZ.mjs +26 -0
  6. package/dist/lib/browser/chunk-I7YWQSUZ.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-ZRJJXRGF.mjs +282 -0
  8. package/dist/lib/browser/chunk-ZRJJXRGF.mjs.map +7 -0
  9. package/dist/lib/browser/index.mjs +51 -57
  10. package/dist/lib/browser/index.mjs.map +4 -4
  11. package/dist/lib/browser/meta.json +1 -1
  12. package/dist/lib/browser/operation-resolver-6MBOKZQH.mjs +25 -0
  13. package/dist/lib/browser/operation-resolver-6MBOKZQH.mjs.map +7 -0
  14. package/dist/lib/browser/react-surface-RVLK6KJ5.mjs +368 -0
  15. package/dist/lib/browser/react-surface-RVLK6KJ5.mjs.map +7 -0
  16. package/dist/types/src/SearchPlugin.d.ts +2 -1
  17. package/dist/types/src/SearchPlugin.d.ts.map +1 -1
  18. package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts +6 -0
  19. package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts.map +1 -0
  20. package/dist/types/src/capabilities/app-graph-builder/index.d.ts +3 -0
  21. package/dist/types/src/capabilities/app-graph-builder/index.d.ts.map +1 -0
  22. package/dist/types/src/capabilities/index.d.ts +3 -3
  23. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  24. package/dist/types/src/capabilities/operation-resolver/index.d.ts +3 -0
  25. package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +1 -0
  26. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +5 -0
  27. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -0
  28. package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
  29. package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
  30. package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
  31. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
  32. package/dist/types/src/components/SearchDialog.d.ts.map +1 -1
  33. package/dist/types/src/components/SearchMain.d.ts +4 -5
  34. package/dist/types/src/components/SearchMain.d.ts.map +1 -1
  35. package/dist/types/src/components/SearchMain.stories.d.ts +31 -0
  36. package/dist/types/src/components/SearchMain.stories.d.ts.map +1 -0
  37. package/dist/types/src/components/SpaceMain.d.ts +9 -0
  38. package/dist/types/src/components/SpaceMain.d.ts.map +1 -0
  39. package/dist/types/src/components/index.d.ts +1 -1
  40. package/dist/types/src/components/index.d.ts.map +1 -1
  41. package/dist/types/src/hooks/index.d.ts +1 -0
  42. package/dist/types/src/hooks/index.d.ts.map +1 -1
  43. package/dist/types/src/hooks/sync.d.ts +3 -2
  44. package/dist/types/src/hooks/sync.d.ts.map +1 -1
  45. package/dist/types/src/hooks/useGlobalSearch.d.ts +7 -3
  46. package/dist/types/src/hooks/useGlobalSearch.d.ts.map +1 -1
  47. package/dist/types/src/hooks/useSearchResults.d.ts +3 -2
  48. package/dist/types/src/hooks/useSearchResults.d.ts.map +1 -1
  49. package/dist/types/src/hooks/useWebSearch.d.ts +6 -3
  50. package/dist/types/src/hooks/useWebSearch.d.ts.map +1 -1
  51. package/dist/types/src/meta.d.ts +2 -2
  52. package/dist/types/src/meta.d.ts.map +1 -1
  53. package/dist/types/src/search/exa.d.ts +3 -1
  54. package/dist/types/src/search/exa.d.ts.map +1 -1
  55. package/dist/types/src/translations.d.ts +1 -1
  56. package/dist/types/src/types/action.d.ts +13 -10
  57. package/dist/types/src/types/action.d.ts.map +1 -1
  58. package/dist/types/src/types/search.d.ts +3 -7
  59. package/dist/types/src/types/search.d.ts.map +1 -1
  60. package/dist/types/tsconfig.tsbuildinfo +1 -1
  61. package/package.json +53 -45
  62. package/src/SearchPlugin.tsx +24 -42
  63. package/src/capabilities/app-graph-builder/app-graph-builder.ts +70 -0
  64. package/src/capabilities/app-graph-builder/index.ts +7 -0
  65. package/src/capabilities/index.ts +3 -5
  66. package/src/capabilities/operation-resolver/index.ts +7 -0
  67. package/src/capabilities/operation-resolver/operation-resolver.ts +23 -0
  68. package/src/capabilities/react-surface/index.ts +7 -0
  69. package/src/capabilities/react-surface/react-surface.tsx +70 -0
  70. package/src/components/SearchDialog.tsx +67 -61
  71. package/src/components/SearchMain.stories.tsx +90 -0
  72. package/src/components/SearchMain.tsx +63 -48
  73. package/src/components/SpaceMain.tsx +169 -0
  74. package/src/components/index.ts +1 -1
  75. package/src/hooks/index.ts +2 -0
  76. package/src/hooks/sync.test.ts +6 -4
  77. package/src/hooks/sync.ts +25 -30
  78. package/src/hooks/useGlobalSearch.tsx +31 -12
  79. package/src/hooks/useSearchResults.ts +7 -4
  80. package/src/hooks/useWebSearch.ts +20 -9
  81. package/src/meta.ts +2 -2
  82. package/src/search/exa.test.ts +9 -11
  83. package/src/search/exa.ts +6 -5
  84. package/src/translations.ts +1 -1
  85. package/src/types/action.tsx +8 -6
  86. package/src/types/command-score.d.ts +16 -0
  87. package/src/types/search.ts +3 -9
  88. package/dist/lib/browser/app-graph-builder-EVWBWGSY.mjs +0 -78
  89. package/dist/lib/browser/app-graph-builder-EVWBWGSY.mjs.map +0 -7
  90. package/dist/lib/browser/chunk-GN2FSWTM.mjs.map +0 -7
  91. package/dist/lib/browser/chunk-TCVYYI44.mjs +0 -21
  92. package/dist/lib/browser/chunk-TCVYYI44.mjs.map +0 -7
  93. package/dist/lib/browser/chunk-WN3TVQLV.mjs +0 -190
  94. package/dist/lib/browser/chunk-WN3TVQLV.mjs.map +0 -7
  95. package/dist/lib/browser/intent-resolver-UYQA6UUQ.mjs +0 -22
  96. package/dist/lib/browser/intent-resolver-UYQA6UUQ.mjs.map +0 -7
  97. package/dist/lib/browser/react-surface-MKWVVY3M.mjs +0 -470
  98. package/dist/lib/browser/react-surface-MKWVVY3M.mjs.map +0 -7
  99. package/dist/types/src/capabilities/app-graph-builder.d.ts +0 -4
  100. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +0 -1
  101. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  102. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  103. package/dist/types/src/capabilities/react-surface.d.ts +0 -4
  104. package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
  105. package/dist/types/src/components/Search.stories.d.ts +0 -16
  106. package/dist/types/src/components/Search.stories.d.ts.map +0 -1
  107. package/dist/types/src/components/SearchResults/SearchResults.d.ts +0 -20
  108. package/dist/types/src/components/SearchResults/SearchResults.d.ts.map +0 -1
  109. package/dist/types/src/components/SearchResults/SearchResults.stories.d.ts +0 -16
  110. package/dist/types/src/components/SearchResults/SearchResults.stories.d.ts.map +0 -1
  111. package/dist/types/src/components/SearchResults/index.d.ts +0 -2
  112. package/dist/types/src/components/SearchResults/index.d.ts.map +0 -1
  113. package/dist/types/src/components/Searchbar/Searchbar.d.ts +0 -14
  114. package/dist/types/src/components/Searchbar/Searchbar.d.ts.map +0 -1
  115. package/dist/types/src/components/Searchbar/Searchbar.stories.d.ts +0 -13
  116. package/dist/types/src/components/Searchbar/Searchbar.stories.d.ts.map +0 -1
  117. package/dist/types/src/components/Searchbar/index.d.ts +0 -2
  118. package/dist/types/src/components/Searchbar/index.d.ts.map +0 -1
  119. package/src/capabilities/app-graph-builder.ts +0 -80
  120. package/src/capabilities/intent-resolver.ts +0 -18
  121. package/src/capabilities/react-surface.tsx +0 -59
  122. package/src/components/Search.stories.tsx +0 -64
  123. package/src/components/SearchResults/SearchResults.stories.tsx +0 -58
  124. package/src/components/SearchResults/SearchResults.tsx +0 -86
  125. package/src/components/SearchResults/index.ts +0 -5
  126. package/src/components/Searchbar/Searchbar.stories.tsx +0 -28
  127. package/src/components/Searchbar/Searchbar.tsx +0 -67
  128. package/src/components/Searchbar/index.ts +0 -5
@@ -1,20 +0,0 @@
1
- import React, { type FC } from 'react';
2
- import { type SearchResult } from '../../types';
3
- export declare const Snippet: FC<{
4
- text: string;
5
- match?: RegExp;
6
- }>;
7
- export type SearchItemProps = SearchResult & {
8
- selected: boolean;
9
- } & Pick<SearchResultsProps, 'onSelect'>;
10
- export declare const SearchItem: React.ForwardRefExoticComponent<SearchResult & {
11
- selected: boolean;
12
- } & Pick<SearchResultsProps, "onSelect"> & React.RefAttributes<HTMLDivElement>>;
13
- export type SearchResultsProps = {
14
- match?: RegExp;
15
- items: SearchResult[];
16
- selected?: string;
17
- onSelect?: (id: string) => void;
18
- };
19
- export declare const SearchResults: ({ items, selected, onSelect }: SearchResultsProps) => React.JSX.Element;
20
- //# sourceMappingURL=SearchResults.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SearchResults.d.ts","sourceRoot":"","sources":["../../../../../src/components/SearchResults/SearchResults.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAAE,KAAK,EAAE,EAAc,MAAM,OAAO,CAAC;AAMnD,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,eAAO,MAAM,OAAO,EAAE,EAAE,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAyBxD,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC;AAE1G,eAAO,MAAM,UAAU;cAFkC,OAAO;+EAoB9D,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC,CAAC;AAGF,eAAO,MAAM,aAAa,GAAI,+BAA+B,kBAAkB,sBAgB9E,CAAC"}
@@ -1,16 +0,0 @@
1
- import { type StoryObj } from '@storybook/react-vite';
2
- import React from 'react';
3
- import { type SearchResultsProps } from './SearchResults';
4
- declare const meta: {
5
- title: string;
6
- component: ({ items, selected, onSelect }: SearchResultsProps) => React.JSX.Element;
7
- render: (props: SearchResultsProps) => React.JSX.Element;
8
- decorators: import("@storybook/react").Decorator[];
9
- parameters: {
10
- layout: string;
11
- };
12
- };
13
- export default meta;
14
- type Story = StoryObj<typeof meta>;
15
- export declare const Default: Story;
16
- //# sourceMappingURL=SearchResults.stories.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SearchResults.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/SearchResults/SearchResults.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAmB,MAAM,OAAO,CAAC;AAOxC,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AA0BzE,QAAA,MAAM,IAAI;;;oBAtBmB,kBAAkB;;;;;CA8BT,CAAC;AAEvC,eAAe,IAAI,CAAC;AAEpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,OAAO,EAAE,KAKrB,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './SearchResults';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/SearchResults/index.ts"],"names":[],"mappings":"AAIA,cAAc,iBAAiB,CAAC"}
@@ -1,14 +0,0 @@
1
- import React from 'react';
2
- import { type TextInputProps } from '@dxos/react-ui';
3
- export type SearchbarProps = Pick<TextInputProps, 'variant' | 'placeholder'> & {
4
- classes?: {
5
- root?: string;
6
- input?: string;
7
- };
8
- value?: string;
9
- onChange?: (text?: string) => void;
10
- onSubmit?: (text?: string) => void;
11
- delay?: number;
12
- };
13
- export declare const Searchbar: ({ classes, variant, placeholder, value, onChange, onSubmit }: SearchbarProps) => React.JSX.Element;
14
- //# sourceMappingURL=Searchbar.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Searchbar.d.ts","sourceRoot":"","sources":["../../../../../src/components/Searchbar/Searchbar.tsx"],"names":[],"mappings":"AAIA,OAAO,KAA0D,MAAM,OAAO,CAAC;AAE/E,OAAO,EAAe,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAElE,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,EAAE,SAAS,GAAG,aAAa,CAAC,GAAG;IAC7E,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,8DAA8D,cAAc,sBA+CrG,CAAC"}
@@ -1,13 +0,0 @@
1
- import { type StoryObj } from '@storybook/react-vite';
2
- declare const meta: {
3
- title: string;
4
- component: ({ classes, variant, placeholder, value, onChange, onSubmit }: import("./Searchbar").SearchbarProps) => import("react").JSX.Element;
5
- decorators: import("@storybook/react").Decorator[];
6
- parameters: {
7
- layout: string;
8
- };
9
- };
10
- export default meta;
11
- type Story = StoryObj<typeof meta>;
12
- export declare const Default: Story;
13
- //# sourceMappingURL=Searchbar.stories.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Searchbar.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/Searchbar/Searchbar.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAMjE,QAAA,MAAM,IAAI;;;;;;;CAOwB,CAAC;AAEnC,eAAe,IAAI,CAAC;AAEpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,OAAO,EAAE,KAIrB,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './Searchbar';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/Searchbar/index.ts"],"names":[],"mappings":"AAIA,cAAc,aAAa,CAAC"}
@@ -1,80 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Rx } from '@effect-rx/rx-react';
6
- import * as Function from 'effect/Function';
7
- import * as Option from 'effect/Option';
8
-
9
- import { Capabilities, type PluginContext, contributes, createIntent } from '@dxos/app-framework';
10
- import { ClientCapabilities } from '@dxos/plugin-client';
11
- import { ATTENDABLE_PATH_SEPARATOR, DECK_COMPANION_TYPE } from '@dxos/plugin-deck/types';
12
- import { ROOT_ID, createExtension, rxFromSignal } from '@dxos/plugin-graph';
13
- import { parseId } from '@dxos/react-client/echo';
14
-
15
- import { meta } from '../meta';
16
- import { SearchAction } from '../types';
17
-
18
- export default (context: PluginContext) =>
19
- contributes(Capabilities.AppGraphBuilder, [
20
- createExtension({
21
- id: `${meta.id}/space-search`,
22
- connector: (node) =>
23
- Rx.make((get) =>
24
- Function.pipe(
25
- get(node),
26
- Option.flatMap((node) => (node.id === ROOT_ID ? Option.some(node) : Option.none())),
27
- Option.map((node) => {
28
- const workspace = get(rxFromSignal(() => context.getCapability(Capabilities.Layout).workspace));
29
- const client = context.getCapability(ClientCapabilities.Client);
30
- const { spaceId } = parseId(workspace);
31
- const space = spaceId ? client.spaces.get(spaceId) : null;
32
-
33
- return [
34
- {
35
- id: [node.id, 'search'].join(ATTENDABLE_PATH_SEPARATOR),
36
- type: DECK_COMPANION_TYPE,
37
- data: space,
38
- properties: {
39
- label: ['search label', { ns: meta.id }],
40
- icon: 'ph--magnifying-glass--regular',
41
- disposition: 'hidden',
42
- },
43
- },
44
- ];
45
- }),
46
- Option.getOrElse(() => []),
47
- ),
48
- ),
49
- }),
50
- createExtension({
51
- id: meta.id,
52
- actions: (node) =>
53
- Rx.make((get) =>
54
- Function.pipe(
55
- get(node),
56
- Option.flatMap((node) => (node.id === ROOT_ID ? Option.some(node) : Option.none())),
57
- Option.map(() => {
58
- return [
59
- {
60
- id: SearchAction.OpenSearch._tag,
61
- data: async () => {
62
- const { dispatchPromise: dispatch } = context.getCapability(Capabilities.IntentDispatcher);
63
- await dispatch(createIntent(SearchAction.OpenSearch));
64
- },
65
- properties: {
66
- label: ['search action label', { ns: meta.id }],
67
- icon: 'ph--magnifying-glass--regular',
68
- keyBinding: {
69
- macos: 'shift+meta+f',
70
- windows: 'shift+alt+f',
71
- },
72
- },
73
- },
74
- ];
75
- }),
76
- Option.getOrElse(() => []),
77
- ),
78
- ),
79
- }),
80
- ]);
@@ -1,18 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Capabilities, LayoutAction, contributes, createIntent, createResolver } from '@dxos/app-framework';
6
-
7
- import { SearchAction } from '../types';
8
-
9
- export default () =>
10
- contributes(
11
- Capabilities.IntentResolver,
12
- createResolver({
13
- intent: SearchAction.OpenSearch,
14
- resolve: () => ({
15
- intents: [createIntent(LayoutAction.UpdateComplementary, { part: 'complementary', subject: 'search' })],
16
- }),
17
- }),
18
- );
@@ -1,59 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import React from 'react';
6
-
7
- import { Capabilities, contributes, createSurface } from '@dxos/app-framework';
8
- import { useActiveSpace } from '@dxos/plugin-space';
9
- import { type Space, isSpace } from '@dxos/react-client/echo';
10
-
11
- import { SEARCH_DIALOG, SearchDialog, type SearchDialogProps, SearchMain } from '../components';
12
- import { SearchContextProvider } from '../hooks';
13
-
14
- export default () =>
15
- contributes(Capabilities.ReactSurface, [
16
- createSurface({
17
- id: SEARCH_DIALOG,
18
- role: 'dialog',
19
- filter: (data): data is { props: SearchDialogProps } => data.component === SEARCH_DIALOG,
20
- component: ({ data }) => (
21
- <SearchContextProvider>
22
- <SearchDialog {...data.props} />
23
- </SearchContextProvider>
24
- ),
25
- }),
26
- createSurface({
27
- id: `${SEARCH_DIALOG}/search-input`,
28
- role: 'search-input',
29
- component: () => {
30
- const space = useActiveSpace();
31
- if (!space) {
32
- return null;
33
- }
34
-
35
- return (
36
- <SearchContextProvider>
37
- <SearchMain space={space} />
38
- </SearchContextProvider>
39
- );
40
- },
41
- }),
42
- 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
- ]);
@@ -1,64 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { type Decorator, type Meta, type StoryObj } from '@storybook/react-vite';
6
- import React, { useState } from 'react';
7
-
8
- import { faker } from '@dxos/random';
9
- import { withLayout, withTheme } from '@dxos/react-ui/testing';
10
-
11
- import { SearchContextProvider, useGlobalSearch, useGlobalSearchResults } from '../hooks';
12
-
13
- import { Searchbar, type SearchbarProps } from './Searchbar';
14
- import { SearchResults } from './SearchResults';
15
-
16
- faker.seed(1);
17
-
18
- type StoryProps = SearchbarProps & {
19
- objects?: any[];
20
- };
21
-
22
- const DefaultStory = ({ objects, ...props }: StoryProps) => {
23
- const [selected, setSelected] = useState<string>();
24
- const { setMatch } = useGlobalSearch();
25
- const filteredItems = useGlobalSearchResults(objects);
26
-
27
- return (
28
- <div className='flex grow justify-center overflow-hidden'>
29
- <div className='flex flex-col w-[300px] m-4 overflow-hidden'>
30
- <Searchbar variant='subdued' placeholder='Enter regular expression...' onChange={setMatch} {...props} />
31
- <SearchResults items={filteredItems} selected={selected} onSelect={setSelected} />
32
- </div>
33
- </div>
34
- );
35
- };
36
-
37
- const withSearchContext = (): Decorator => {
38
- return (Story) => (
39
- <SearchContextProvider>
40
- <Story />
41
- </SearchContextProvider>
42
- );
43
- };
44
-
45
- export const Default: Story = {
46
- args: {
47
- objects: Array.from({ length: 8 }).map(() => ({
48
- id: faker.string.uuid(),
49
- label: faker.lorem.sentence(4).replace(/\./g, ''),
50
- content: faker.lorem.sentences(3),
51
- })),
52
- },
53
- };
54
-
55
- const meta = {
56
- title: 'plugins/plugin-search/Search',
57
- component: Searchbar,
58
- render: DefaultStory,
59
- decorators: [withTheme, withLayout({ container: 'column' }), withSearchContext()],
60
- } satisfies Meta<typeof Searchbar>;
61
-
62
- export default meta;
63
-
64
- type Story = StoryObj<typeof meta>;
@@ -1,58 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { type Meta, type StoryObj } from '@storybook/react-vite';
6
- import React, { useState } from 'react';
7
-
8
- import { faker } from '@dxos/random';
9
- import { withTheme } from '@dxos/react-ui/testing';
10
-
11
- import { filterObjectsSync } from '../../hooks';
12
-
13
- import { SearchResults, type SearchResultsProps } from './SearchResults';
14
-
15
- faker.seed(1);
16
-
17
- const DefaultStory = (props: SearchResultsProps) => {
18
- const [selected, setSelected] = useState<string>();
19
-
20
- return (
21
- <div className='flex grow justify-center overflow-hidden'>
22
- <div className='flex w-[300px] m-4 overflow-hidden'>
23
- <SearchResults {...props} selected={selected} onSelect={setSelected} />
24
- </div>
25
- </div>
26
- );
27
- };
28
-
29
- const word = 'hello';
30
-
31
- const objects = Array.from({ length: 100 }).map((_, i) => ({
32
- id: faker.string.uuid(),
33
- name: faker.lorem.sentence(4),
34
- content: faker.lorem.sentence() + ` ${word} ` + faker.lorem.sentence(),
35
- }));
36
-
37
- const match = new RegExp(word, 'i');
38
-
39
- const meta = {
40
- title: 'plugins/plugin-search/SearchResults',
41
- component: SearchResults,
42
- render: DefaultStory,
43
- decorators: [withTheme],
44
- parameters: {
45
- layout: 'fullscreen',
46
- },
47
- } satisfies Meta<typeof SearchResults>;
48
-
49
- export default meta;
50
-
51
- type Story = StoryObj<typeof meta>;
52
-
53
- export const Default: Story = {
54
- args: {
55
- items: filterObjectsSync(objects, match),
56
- match,
57
- },
58
- };
@@ -1,86 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import React, { type FC, forwardRef } from 'react';
6
-
7
- import { Card } from '@dxos/react-ui-stack';
8
- import { ghostHover } from '@dxos/react-ui-theme';
9
-
10
- import { SEARCH_RESULT } from '../../meta';
11
- import { type SearchResult } from '../../types';
12
-
13
- export const Snippet: FC<{ text: string; match?: RegExp }> = ({ text, match }) => {
14
- let content = <>{text}</>;
15
- if (match) {
16
- const result = text.match(match);
17
- if (result?.index !== undefined) {
18
- // Break near to match.
19
- const maxOffset = 16;
20
- let before = text.slice(0, result.index);
21
- if (before.length > maxOffset) {
22
- const idx = before.indexOf(' ', result.index - maxOffset);
23
- before = '… ' + before.slice(idx);
24
- }
25
-
26
- const after = text.slice(result.index + result[0].length);
27
- content = (
28
- <>
29
- {before}
30
- <span className='text-blue-500'>{result[0]}</span>
31
- {after}
32
- </>
33
- );
34
- }
35
- }
36
-
37
- return <span className='text-xs mb-1 line-clamp-3 text-neutral-300'>{content}</span>;
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 && (
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
- };
@@ -1,5 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- export * from './SearchResults';
@@ -1,28 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { type Meta, type StoryObj } from '@storybook/react-vite';
6
-
7
- import { withTheme } from '@dxos/react-ui/testing';
8
-
9
- import { Searchbar } from './Searchbar';
10
-
11
- const meta = {
12
- title: 'plugins/plugin-search/Searchbar',
13
- component: Searchbar,
14
- decorators: [withTheme],
15
- parameters: {
16
- layout: 'centered',
17
- },
18
- } satisfies Meta<typeof Searchbar>;
19
-
20
- export default meta;
21
-
22
- type Story = StoryObj<typeof meta>;
23
-
24
- export const Default: Story = {
25
- args: {
26
- placeholder: 'Search...',
27
- },
28
- };
@@ -1,67 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import React, { type KeyboardEvent, useEffect, useRef, useState } from 'react';
6
-
7
- import { Icon, Input, type TextInputProps } from '@dxos/react-ui';
8
-
9
- export type SearchbarProps = Pick<TextInputProps, 'variant' | 'placeholder'> & {
10
- classes?: {
11
- root?: string;
12
- input?: string;
13
- };
14
- value?: string;
15
- onChange?: (text?: string) => void;
16
- onSubmit?: (text?: string) => void;
17
- delay?: number;
18
- };
19
-
20
- export const Searchbar = ({ classes, variant, placeholder, value, onChange, onSubmit }: SearchbarProps) => {
21
- const inputRef = useRef<HTMLInputElement>(null);
22
- const [text, setText] = useState(value);
23
- useEffect(() => {
24
- setText(value);
25
- }, [value]);
26
- const handleChange = (text?: string) => {
27
- setText(text);
28
- onChange?.(text);
29
- };
30
-
31
- const handleReset = () => {
32
- handleChange(undefined);
33
- inputRef.current?.focus();
34
- };
35
-
36
- const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
37
- switch (event.key) {
38
- case 'Enter':
39
- onSubmit?.(text);
40
- break;
41
- case 'Escape':
42
- handleReset();
43
- break;
44
- }
45
- };
46
-
47
- return (
48
- <div className='flex shrink-0w-full items-center pli-1 pbs-1'>
49
- <Input.Root>
50
- <Input.TextInput
51
- ref={inputRef}
52
- placeholder={placeholder}
53
- variant={variant}
54
- value={text ?? ''}
55
- classNames={['pl-3 pr-10', classes?.input]}
56
- onChange={({ target }) => handleChange(target.value)}
57
- onKeyDown={handleKeyDown}
58
- />
59
-
60
- {/* TODO(burdon): Margin should be density specific. */}
61
- <div role='button' className='-ml-7 p-0 cursor-pointer' onClick={handleReset}>
62
- <Icon icon='ph--magnifying-glass--regular' size={5} />
63
- </div>
64
- </Input.Root>
65
- </div>
66
- );
67
- };
@@ -1,5 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- export * from './Searchbar';