@dxos/plugin-search 0.6.8-main.046e6cf

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 (67) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +4 -0
  3. package/dist/lib/browser/chunk-56ITWEGS.mjs +23 -0
  4. package/dist/lib/browser/chunk-56ITWEGS.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +616 -0
  6. package/dist/lib/browser/index.mjs.map +7 -0
  7. package/dist/lib/browser/meta.json +1 -0
  8. package/dist/lib/browser/meta.mjs +11 -0
  9. package/dist/lib/browser/meta.mjs.map +7 -0
  10. package/dist/types/src/SearchPlugin.d.ts +4 -0
  11. package/dist/types/src/SearchPlugin.d.ts.map +1 -0
  12. package/dist/types/src/components/Search.stories.d.ts +25 -0
  13. package/dist/types/src/components/Search.stories.d.ts.map +1 -0
  14. package/dist/types/src/components/SearchDialog.d.ts +10 -0
  15. package/dist/types/src/components/SearchDialog.d.ts.map +1 -0
  16. package/dist/types/src/components/SearchMain.d.ts +6 -0
  17. package/dist/types/src/components/SearchMain.d.ts.map +1 -0
  18. package/dist/types/src/components/SearchResults/SearchResults.d.ts +19 -0
  19. package/dist/types/src/components/SearchResults/SearchResults.d.ts.map +1 -0
  20. package/dist/types/src/components/SearchResults/SearchResults.stories.d.ts +20 -0
  21. package/dist/types/src/components/SearchResults/SearchResults.stories.d.ts.map +1 -0
  22. package/dist/types/src/components/SearchResults/index.d.ts +2 -0
  23. package/dist/types/src/components/SearchResults/index.d.ts.map +1 -0
  24. package/dist/types/src/components/Searchbar/Searchbar.d.ts +13 -0
  25. package/dist/types/src/components/Searchbar/Searchbar.d.ts.map +1 -0
  26. package/dist/types/src/components/Searchbar/Searchbar.stories.d.ts +18 -0
  27. package/dist/types/src/components/Searchbar/Searchbar.stories.d.ts.map +1 -0
  28. package/dist/types/src/components/Searchbar/index.d.ts +2 -0
  29. package/dist/types/src/components/Searchbar/index.d.ts.map +1 -0
  30. package/dist/types/src/components/index.d.ts +4 -0
  31. package/dist/types/src/components/index.d.ts.map +1 -0
  32. package/dist/types/src/context.d.ts +12 -0
  33. package/dist/types/src/context.d.ts.map +1 -0
  34. package/dist/types/src/index.d.ts +6 -0
  35. package/dist/types/src/index.d.ts.map +1 -0
  36. package/dist/types/src/meta.d.ts +16 -0
  37. package/dist/types/src/meta.d.ts.map +1 -0
  38. package/dist/types/src/search-sync.d.ts +13 -0
  39. package/dist/types/src/search-sync.d.ts.map +1 -0
  40. package/dist/types/src/search.d.ts +3 -0
  41. package/dist/types/src/search.d.ts.map +1 -0
  42. package/dist/types/src/search.test.d.ts +2 -0
  43. package/dist/types/src/search.test.d.ts.map +1 -0
  44. package/dist/types/src/translations.d.ts +15 -0
  45. package/dist/types/src/translations.d.ts.map +1 -0
  46. package/dist/types/src/types.d.ts +6 -0
  47. package/dist/types/src/types.d.ts.map +1 -0
  48. package/package.json +66 -0
  49. package/src/SearchPlugin.tsx +122 -0
  50. package/src/components/Search.stories.tsx +63 -0
  51. package/src/components/SearchDialog.tsx +141 -0
  52. package/src/components/SearchMain.tsx +48 -0
  53. package/src/components/SearchResults/SearchResults.stories.tsx +57 -0
  54. package/src/components/SearchResults/SearchResults.tsx +124 -0
  55. package/src/components/SearchResults/index.ts +5 -0
  56. package/src/components/Searchbar/Searchbar.stories.tsx +34 -0
  57. package/src/components/Searchbar/Searchbar.tsx +57 -0
  58. package/src/components/Searchbar/index.ts +5 -0
  59. package/src/components/index.ts +7 -0
  60. package/src/context.tsx +41 -0
  61. package/src/index.ts +12 -0
  62. package/src/meta.tsx +20 -0
  63. package/src/search-sync.ts +130 -0
  64. package/src/search.test.ts +36 -0
  65. package/src/search.ts +61 -0
  66. package/src/translations.ts +21 -0
  67. package/src/types.tsx +25 -0
package/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ MIT License
2
+ Copyright (c) 2022 DXOS
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,4 @@
1
+ # @dxos/plugin-search
2
+
3
+ Surface plugin for search.
4
+
@@ -0,0 +1,23 @@
1
+ // packages/plugins/experimental/plugin-search/src/meta.tsx
2
+ import { MagnifyingGlass } from "@phosphor-icons/react";
3
+ import React from "react";
4
+ import { pluginMeta } from "@dxos/app-framework";
5
+ var SEARCH_PLUGIN = "dxos.org/plugin/search";
6
+ var SEARCH_RESULT = `${SEARCH_PLUGIN}/result`;
7
+ var meta_default = pluginMeta({
8
+ id: SEARCH_PLUGIN,
9
+ name: "Search",
10
+ description: "Search ECHO spaces for content.",
11
+ tags: [
12
+ "experimental"
13
+ ],
14
+ iconComponent: (props) => /* @__PURE__ */ React.createElement(MagnifyingGlass, props),
15
+ iconSymbol: "ph--magnifying-glass--regular"
16
+ });
17
+
18
+ export {
19
+ SEARCH_PLUGIN,
20
+ SEARCH_RESULT,
21
+ meta_default
22
+ };
23
+ //# sourceMappingURL=chunk-56ITWEGS.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/meta.tsx"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { MagnifyingGlass, type IconProps } from '@phosphor-icons/react';\nimport React from 'react';\n\nimport { pluginMeta } from '@dxos/app-framework';\n\nexport const SEARCH_PLUGIN = 'dxos.org/plugin/search';\nexport const SEARCH_RESULT = `${SEARCH_PLUGIN}/result`;\n\nexport default pluginMeta({\n id: SEARCH_PLUGIN,\n name: 'Search',\n description: 'Search ECHO spaces for content.',\n tags: ['experimental'],\n iconComponent: (props: IconProps) => <MagnifyingGlass {...props} />,\n iconSymbol: 'ph--magnifying-glass--regular',\n});\n"],
5
+ "mappings": ";AAIA,SAASA,uBAAuC;AAChD,OAAOC,WAAW;AAElB,SAASC,kBAAkB;AAEpB,IAAMC,gBAAgB;AACtB,IAAMC,gBAAgB,GAAGD,aAAAA;AAEhC,IAAA,eAAeE,WAAW;EACxBC,IAAIH;EACJI,MAAM;EACNC,aAAa;EACbC,MAAM;IAAC;;EACPC,eAAe,CAACC,UAAqB,sBAAA,cAACC,iBAAoBD,KAAAA;EAC1DE,YAAY;AACd,CAAA;",
6
+ "names": ["MagnifyingGlass", "React", "pluginMeta", "SEARCH_PLUGIN", "SEARCH_RESULT", "pluginMeta", "id", "name", "description", "tags", "iconComponent", "props", "MagnifyingGlass", "iconSymbol"]
7
+ }
@@ -0,0 +1,616 @@
1
+ import {
2
+ SEARCH_PLUGIN,
3
+ SEARCH_RESULT,
4
+ meta_default
5
+ } from "./chunk-56ITWEGS.mjs";
6
+
7
+ // packages/plugins/experimental/plugin-search/src/SearchPlugin.tsx
8
+ import { MagnifyingGlass as MagnifyingGlass2 } from "@phosphor-icons/react";
9
+ import React6 from "react";
10
+ import { resolvePlugin, parseIntentPlugin, parseGraphPlugin as parseGraphPlugin2, parseNavigationPlugin as parseNavigationPlugin2, LayoutAction as LayoutAction2, firstIdInPart } from "@dxos/app-framework";
11
+ import { createExtension } from "@dxos/plugin-graph";
12
+ import { getActiveSpace } from "@dxos/plugin-space";
13
+
14
+ // packages/plugins/experimental/plugin-search/src/components/Searchbar/Searchbar.tsx
15
+ import { MagnifyingGlass } from "@phosphor-icons/react";
16
+ import React, { useEffect, useRef, useState } from "react";
17
+ import { Input } from "@dxos/react-ui";
18
+ import { getSize, mx } from "@dxos/react-ui-theme";
19
+ var Searchbar = ({ classes, variant, placeholder, value, onChange }) => {
20
+ const inputRef = useRef(null);
21
+ const [text, setText] = useState(value);
22
+ useEffect(() => {
23
+ setText(value);
24
+ }, [
25
+ value
26
+ ]);
27
+ const handleChange = (text2) => {
28
+ setText(text2);
29
+ onChange?.(text2);
30
+ };
31
+ const handleReset = () => {
32
+ handleChange(void 0);
33
+ inputRef.current?.focus();
34
+ };
35
+ return /* @__PURE__ */ React.createElement("div", {
36
+ className: "flex w-full items-center pli-1 pbs-1"
37
+ }, /* @__PURE__ */ React.createElement(Input.Root, null, /* @__PURE__ */ React.createElement(Input.TextInput, {
38
+ ref: inputRef,
39
+ placeholder,
40
+ variant,
41
+ value: text ?? "",
42
+ classNames: mx("pl-3 pr-10", classes?.input),
43
+ onChange: ({ target }) => handleChange(target.value),
44
+ onKeyDown: ({ key }) => key === "Escape" && handleReset()
45
+ }), /* @__PURE__ */ React.createElement("div", {
46
+ role: "button",
47
+ className: "-ml-7 p-0 cursor-pointer",
48
+ onClick: handleReset
49
+ }, /* @__PURE__ */ React.createElement(MagnifyingGlass, {
50
+ className: getSize(5)
51
+ }))));
52
+ };
53
+
54
+ // packages/plugins/experimental/plugin-search/src/components/SearchMain.tsx
55
+ import React4, { useState as useState3 } from "react";
56
+ import { useClient } from "@dxos/react-client";
57
+ import { useQuery } from "@dxos/react-client/echo";
58
+ import { useTranslation } from "@dxos/react-ui";
59
+ import { groupSurface, mx as mx3 } from "@dxos/react-ui-theme";
60
+
61
+ // packages/plugins/experimental/plugin-search/src/components/SearchResults/SearchResults.tsx
62
+ import { Buildings, Folders, User } from "@phosphor-icons/react";
63
+ import React2, { forwardRef } from "react";
64
+ import { ScrollArea } from "@dxos/react-ui";
65
+ import { Card } from "@dxos/react-ui-card";
66
+ import { Mosaic } from "@dxos/react-ui-mosaic";
67
+ import { ghostHover, mx as mx2 } from "@dxos/react-ui-theme";
68
+ var styles = {
69
+ selected: "!bg-primary-100 !dark:bg-primary-900"
70
+ };
71
+ var getIcon = (type) => {
72
+ const iconMap = {
73
+ user: User,
74
+ organization: Buildings,
75
+ project: Folders
76
+ };
77
+ return iconMap[type];
78
+ };
79
+ var Snippet = ({ text, match }) => {
80
+ let content = /* @__PURE__ */ React2.createElement(React2.Fragment, null, text);
81
+ if (match) {
82
+ const result = text.match(match);
83
+ if (result?.index !== void 0) {
84
+ const maxOffset = 16;
85
+ let before = text.slice(0, result.index);
86
+ if (before.length > maxOffset) {
87
+ const idx = before.indexOf(" ", result.index - maxOffset);
88
+ before = "\u2026 " + before.slice(idx);
89
+ }
90
+ const after = text.slice(result.index + result[0].length);
91
+ content = /* @__PURE__ */ React2.createElement(React2.Fragment, null, before, /* @__PURE__ */ React2.createElement("span", {
92
+ className: "text-blue-500"
93
+ }, result[0]), after);
94
+ }
95
+ }
96
+ return /* @__PURE__ */ React2.createElement("span", {
97
+ className: "text-xs mb-1 line-clamp-3 text-neutral-300"
98
+ }, content);
99
+ };
100
+ var SearchItem = /* @__PURE__ */ forwardRef(({ draggableStyle, draggableProps, item, debug = false }, forwardRef3) => {
101
+ const { id, type, label, snippet, match, selected, onSelect } = item;
102
+ const Icon = type ? getIcon(type) : void 0;
103
+ return /* @__PURE__ */ React2.createElement(Card.Root, {
104
+ ref: forwardRef3,
105
+ style: draggableStyle,
106
+ classNames: mx2("mx-2 mt-2 cursor-pointer", ghostHover, selected && styles.selected),
107
+ onClick: () => onSelect?.(id)
108
+ }, /* @__PURE__ */ React2.createElement(Card.Header, null, /* @__PURE__ */ React2.createElement(Card.DragHandle, draggableProps), /* @__PURE__ */ React2.createElement(Card.Title, {
109
+ title: label ?? "Untitled"
110
+ }), Icon && /* @__PURE__ */ React2.createElement(Card.Endcap, {
111
+ Icon
112
+ })), snippet && /* @__PURE__ */ React2.createElement(Card.Body, {
113
+ gutter: true
114
+ }, /* @__PURE__ */ React2.createElement(Snippet, {
115
+ text: snippet,
116
+ match
117
+ })), debug && /* @__PURE__ */ React2.createElement(Card.Body, {
118
+ gutter: true
119
+ }, /* @__PURE__ */ React2.createElement("pre", {
120
+ className: "text-xs whitespace-pre-line"
121
+ }, JSON.stringify(item))));
122
+ });
123
+ var SearchResults = ({ items, selected, onSelect }) => {
124
+ const path = "search";
125
+ return /* @__PURE__ */ React2.createElement(ScrollArea.Root, {
126
+ classNames: "grow"
127
+ }, /* @__PURE__ */ React2.createElement(ScrollArea.Viewport, null, /* @__PURE__ */ React2.createElement(Mosaic.Container, {
128
+ id: path,
129
+ Component: SearchItem
130
+ }, items.map((item) => /* @__PURE__ */ React2.createElement(Mosaic.DraggableTile, {
131
+ key: item.id,
132
+ path,
133
+ type: SEARCH_RESULT,
134
+ item: {
135
+ ...item,
136
+ selected: selected === item.id,
137
+ onSelect
138
+ },
139
+ Component: SearchItem
140
+ })))), /* @__PURE__ */ React2.createElement(ScrollArea.Scrollbar, {
141
+ orientation: "vertical"
142
+ }, /* @__PURE__ */ React2.createElement(ScrollArea.Thumb, null)), /* @__PURE__ */ React2.createElement(ScrollArea.Corner, null));
143
+ };
144
+
145
+ // packages/plugins/experimental/plugin-search/src/context.tsx
146
+ import React3, { createContext, useContext, useState as useState2 } from "react";
147
+ import { raise } from "@dxos/debug";
148
+
149
+ // packages/plugins/experimental/plugin-search/src/search-sync.ts
150
+ import { getSchema } from "@dxos/echo-schema";
151
+ import { AST } from "@dxos/echo-schema";
152
+ import { TextType } from "@dxos/plugin-markdown/types";
153
+ var queryStringToMatch = (queryString) => {
154
+ const trimmed = queryString?.trim();
155
+ return trimmed ? new RegExp(trimmed, "i") : void 0;
156
+ };
157
+ var getIcon2 = (schema) => {
158
+ if (!(schema && AST.isTypeLiteral(schema.ast))) {
159
+ return void 0;
160
+ }
161
+ const keys = schema.ast.propertySignatures.map((p) => p.name);
162
+ if (keys.indexOf("email") !== -1) {
163
+ return "user";
164
+ }
165
+ if (keys.indexOf("website") !== -1) {
166
+ return "organization";
167
+ }
168
+ if (keys.indexOf("repo") !== -1) {
169
+ return "project";
170
+ }
171
+ return void 0;
172
+ };
173
+ var filterObjectsSync = (objects, match) => {
174
+ if (!match) {
175
+ return [];
176
+ }
177
+ return objects.reduce((results, object) => {
178
+ if (object instanceof TextType) {
179
+ return results;
180
+ }
181
+ const fields = mapObjectToTextFields(object);
182
+ Object.entries(fields).some(([, value]) => {
183
+ const result = value.match(match);
184
+ if (result) {
185
+ const label = getStringProperty(object, [
186
+ "label",
187
+ "name",
188
+ "title"
189
+ ]);
190
+ results.push({
191
+ id: object.id,
192
+ type: getIcon2(getSchema(object)),
193
+ label,
194
+ match,
195
+ // TODO(burdon): Truncate.
196
+ // TODO(burdon): Issue with sketch documents.
197
+ snippet: value !== label ? value : fields.content ?? fields.description ?? void 0,
198
+ object
199
+ });
200
+ return true;
201
+ }
202
+ return false;
203
+ });
204
+ return results;
205
+ }, []);
206
+ };
207
+ var getStringProperty = (object, keys) => {
208
+ let label;
209
+ keys.some((key) => {
210
+ const value = object[key];
211
+ if (typeof value === "string") {
212
+ label = value;
213
+ return true;
214
+ }
215
+ return false;
216
+ });
217
+ return label;
218
+ };
219
+ var getKeys = (object) => {
220
+ try {
221
+ const obj = JSON.parse(JSON.stringify(object));
222
+ return Object.keys(obj).filter((key) => key !== "id" && key !== "identityKey" && key[0] !== "_" && key[0] !== "@");
223
+ } catch (err) {
224
+ return [];
225
+ }
226
+ };
227
+ var mapObjectToTextFields = (object) => {
228
+ return getKeys(object).reduce((fields, key) => {
229
+ const value = object[key];
230
+ if (typeof value === "string" || value instanceof TextType) {
231
+ try {
232
+ fields[key] = String(value);
233
+ } catch (err) {
234
+ }
235
+ }
236
+ return fields;
237
+ }, {});
238
+ };
239
+
240
+ // packages/plugins/experimental/plugin-search/src/context.tsx
241
+ var SearchContext = /* @__PURE__ */ createContext({});
242
+ var SearchContextProvider = ({ children }) => {
243
+ const [match, setMatch] = useState2();
244
+ const handleMatch = (text) => setMatch(queryStringToMatch(text));
245
+ return /* @__PURE__ */ React3.createElement(SearchContext.Provider, {
246
+ value: {
247
+ match,
248
+ setMatch: handleMatch
249
+ }
250
+ }, children);
251
+ };
252
+ var useGlobalSearch = () => {
253
+ return useContext(SearchContext) ?? raise(new Error("Missing SearchContext."));
254
+ };
255
+ var useGlobalSearchResults = (objects) => {
256
+ const { match } = useGlobalSearch();
257
+ return objects && match ? filterObjectsSync(objects, match) : [];
258
+ };
259
+ var useGlobalFilteredObjects = (objects) => {
260
+ const { match } = useGlobalSearch();
261
+ if (!match || !objects) {
262
+ return objects ?? [];
263
+ }
264
+ const matching = filterObjectsSync(objects, match);
265
+ return matching.map((result) => result.object);
266
+ };
267
+
268
+ // packages/plugins/experimental/plugin-search/src/components/SearchMain.tsx
269
+ var SearchMain = ({ space }) => {
270
+ const { t } = useTranslation(SEARCH_PLUGIN);
271
+ const client = useClient();
272
+ const { setMatch } = useGlobalSearch();
273
+ const allSpaces = false;
274
+ const objects = useQuery(allSpaces ? client.spaces : space);
275
+ const results = useGlobalSearchResults(objects);
276
+ const [selected, setSelected] = useState3();
277
+ const handleSelect = (id) => {
278
+ setSelected((selected2) => selected2 === id ? void 0 : id);
279
+ };
280
+ return /* @__PURE__ */ React4.createElement("div", {
281
+ className: "flex flex-col grow h-full"
282
+ }, /* @__PURE__ */ React4.createElement(Searchbar, {
283
+ placeholder: t("search placeholder"),
284
+ onChange: setMatch
285
+ }), results.length > 0 && /* @__PURE__ */ React4.createElement("div", {
286
+ className: "absolute top-[--topbar-size] bottom-0 z-[1]"
287
+ }, /* @__PURE__ */ React4.createElement("div", {
288
+ className: mx3("flex flex-col h-full overflow-hidden", groupSurface)
289
+ }, /* @__PURE__ */ React4.createElement(SearchResults, {
290
+ items: results,
291
+ selected,
292
+ onSelect: handleSelect
293
+ }))));
294
+ };
295
+
296
+ // packages/plugins/experimental/plugin-search/src/components/SearchDialog.tsx
297
+ import { Placeholder } from "@phosphor-icons/react";
298
+ import React5, { forwardRef as forwardRef2, useCallback, useState as useState5 } from "react";
299
+ import { useResolvePlugin, parseNavigationPlugin, parseGraphPlugin, NavigationAction, LayoutAction, isLayoutParts, useIntentDispatcher } from "@dxos/app-framework";
300
+ import { useClient as useClient2 } from "@dxos/react-client";
301
+ import { fullyQualifiedId, useQuery as useQuery2 } from "@dxos/react-client/echo";
302
+ import { Button, Dialog, toLocalizedString, useTranslation as useTranslation2 } from "@dxos/react-ui";
303
+ import { SearchList } from "@dxos/react-ui-searchlist";
304
+ import { descriptionText, mx as mx4 } from "@dxos/react-ui-theme";
305
+
306
+ // packages/plugins/experimental/plugin-search/src/search.ts
307
+ import { yieldOrContinue } from "main-thread-scheduling";
308
+ import { useEffect as useEffect2, useState as useState4 } from "react";
309
+ import { TextType as TextType2 } from "@dxos/plugin-markdown/types";
310
+ var filterObjects = async (objects, match) => {
311
+ const result = /* @__PURE__ */ new Map();
312
+ if (!match) {
313
+ return result;
314
+ }
315
+ await Promise.all(objects.filter((object) => !(object instanceof TextType2)).map(async (object) => {
316
+ await yieldOrContinue("interactive");
317
+ const fields = mapObjectToTextFields(object);
318
+ Object.entries(fields).filter(([_, value]) => value.match(match)).forEach(([key, value]) => {
319
+ if (!result.has(object)) {
320
+ result.set(object, []);
321
+ }
322
+ result.set(object, [
323
+ ...result.get(object),
324
+ [
325
+ key,
326
+ value
327
+ ]
328
+ ]);
329
+ });
330
+ }));
331
+ return result;
332
+ };
333
+ var useSearchResults = (queryString, objects, delay = 400) => {
334
+ const [results, setResults] = useState4(/* @__PURE__ */ new Map());
335
+ const [pending, setPending] = useState4(false);
336
+ useEffect2(() => {
337
+ setPending(!!(objects && queryString));
338
+ const timeoutId = setTimeout(async () => {
339
+ const nextResults = objects && queryString ? await filterObjects(objects, queryStringToMatch(queryString)) : /* @__PURE__ */ new Map();
340
+ setResults(nextResults);
341
+ setPending(false);
342
+ }, delay);
343
+ return () => clearTimeout(timeoutId);
344
+ }, [
345
+ queryString,
346
+ objects
347
+ ]);
348
+ return [
349
+ pending,
350
+ results
351
+ ];
352
+ };
353
+
354
+ // packages/plugins/experimental/plugin-search/src/components/SearchDialog.tsx
355
+ var SearchListResult = /* @__PURE__ */ forwardRef2(({ node, onSelect }, forwardedRef) => {
356
+ const { t } = useTranslation2(SEARCH_PLUGIN);
357
+ const Icon = node?.properties.icon ?? Placeholder;
358
+ const label = toLocalizedString(node?.properties.label ?? "never", t);
359
+ return /* @__PURE__ */ React5.createElement(SearchList.Item, {
360
+ value: label,
361
+ key: node.id,
362
+ classNames: "flex gap-2 items-center pli-2",
363
+ onSelect: () => onSelect?.(node.id),
364
+ ref: forwardedRef
365
+ }, /* @__PURE__ */ React5.createElement(Icon, null), /* @__PURE__ */ React5.createElement("span", {
366
+ className: "is-0 grow truncate"
367
+ }, label));
368
+ });
369
+ var SearchDialog = ({ subject }) => {
370
+ const { t } = useTranslation2(SEARCH_PLUGIN);
371
+ const graphPlugin = useResolvePlugin(parseGraphPlugin);
372
+ const graph = graphPlugin?.provides.graph;
373
+ const navigationPlugin = useResolvePlugin(parseNavigationPlugin);
374
+ const providedClosed = navigationPlugin?.provides.location.closed ?? [];
375
+ const closed = (Array.isArray(providedClosed) ? providedClosed : [
376
+ providedClosed
377
+ ]).map((id) => graph?.findNode(id)).filter(Boolean);
378
+ const active = navigationPlugin?.provides.location.active;
379
+ const [queryString, setQueryString] = useState5("");
380
+ const client = useClient2();
381
+ const dangerouslyLoadAllObjects = useQuery2(client.spaces);
382
+ const [pending, results] = useSearchResults(queryString, dangerouslyLoadAllObjects);
383
+ const resultObjects = Array.from(results.keys());
384
+ const dispatch = useIntentDispatcher();
385
+ const handleSelect = useCallback((nodeId) => {
386
+ if (active && isLayoutParts(active)) {
387
+ const index = active?.main?.findIndex((entry) => entry.id === nodeId);
388
+ if (index !== -1) {
389
+ return dispatch([
390
+ {
391
+ action: LayoutAction.SET_LAYOUT,
392
+ data: {
393
+ element: "dialog",
394
+ state: false
395
+ }
396
+ },
397
+ {
398
+ action: LayoutAction.SCROLL_INTO_VIEW,
399
+ data: {
400
+ id: nodeId
401
+ }
402
+ }
403
+ ]);
404
+ }
405
+ return dispatch([
406
+ {
407
+ action: NavigationAction.ADD_TO_ACTIVE,
408
+ data: {
409
+ part: subject.layoutCoordinate.part,
410
+ id: nodeId,
411
+ pivotId: subject.layoutCoordinate.entryId,
412
+ positioning: "end"
413
+ }
414
+ },
415
+ {
416
+ action: LayoutAction.SET_LAYOUT,
417
+ data: {
418
+ element: "dialog",
419
+ state: false
420
+ }
421
+ },
422
+ {
423
+ action: LayoutAction.SCROLL_INTO_VIEW,
424
+ data: {
425
+ id: nodeId
426
+ }
427
+ }
428
+ ]);
429
+ }
430
+ }, [
431
+ subject,
432
+ dispatch,
433
+ active
434
+ ]);
435
+ return /* @__PURE__ */ React5.createElement(Dialog.Content, {
436
+ classNames: [
437
+ "md:max-is-[24rem] overflow-hidden mbs-12"
438
+ ]
439
+ }, /* @__PURE__ */ React5.createElement(Dialog.Title, null, t("search dialog title")), /* @__PURE__ */ React5.createElement(SearchList.Root, {
440
+ label: t("search placeholder"),
441
+ classNames: "flex flex-col grow overflow-hidden my-2"
442
+ }, /* @__PURE__ */ React5.createElement(SearchList.Input, {
443
+ value: queryString,
444
+ onValueChange: (nextValue) => {
445
+ setQueryString(nextValue);
446
+ },
447
+ placeholder: t("search placeholder"),
448
+ classNames: "px-1 my-2"
449
+ }), /* @__PURE__ */ React5.createElement(SearchList.Content, {
450
+ classNames: "max-bs-[24rem] overflow-auto"
451
+ }, queryString.length > 0 ? resultObjects.length > 0 ? resultObjects.map((object) => graph?.findNode(fullyQualifiedId(object))).filter(Boolean).map((node) => /* @__PURE__ */ React5.createElement(SearchListResult, {
452
+ key: node.id,
453
+ node,
454
+ onSelect: handleSelect
455
+ })) : /* @__PURE__ */ React5.createElement("p", {
456
+ className: "pli-1"
457
+ }, t(pending ? "pending results message" : "empty results message")) : /* @__PURE__ */ React5.createElement(React5.Fragment, null, closed.length > 0 && /* @__PURE__ */ React5.createElement("h2", {
458
+ className: mx4("mlb-1", descriptionText)
459
+ }, t("recently closed heading")), closed.map((node) => /* @__PURE__ */ React5.createElement(SearchListResult, {
460
+ key: node.id,
461
+ node,
462
+ onSelect: handleSelect
463
+ }))))), /* @__PURE__ */ React5.createElement(Dialog.Close, {
464
+ asChild: true
465
+ }, /* @__PURE__ */ React5.createElement(Button, {
466
+ variant: "primary",
467
+ classNames: "mbs-2"
468
+ }, t("close label", {
469
+ ns: "os"
470
+ }))));
471
+ };
472
+
473
+ // packages/plugins/experimental/plugin-search/src/translations.ts
474
+ var translations_default = [
475
+ {
476
+ "en-US": {
477
+ [SEARCH_PLUGIN]: {
478
+ "plugin name": "Search",
479
+ "search action label": "Search spaces",
480
+ "search placeholder": "Search\u2026",
481
+ "search dialog title": "Open",
482
+ "recently closed heading": "Recently closed",
483
+ "pending results message": "Searching\u2026",
484
+ "empty results message": "No matching items in your spaces"
485
+ }
486
+ }
487
+ }
488
+ ];
489
+
490
+ // packages/plugins/experimental/plugin-search/src/types.tsx
491
+ var SEARCH_ACTION = `${SEARCH_PLUGIN}/action`;
492
+ var SearchAction;
493
+ (function(SearchAction2) {
494
+ SearchAction2[SearchAction2["SEARCH"] = `${SEARCH_ACTION}/search`] = "SEARCH";
495
+ })(SearchAction || (SearchAction = {}));
496
+
497
+ // packages/plugins/experimental/plugin-search/src/SearchPlugin.tsx
498
+ var SearchPlugin = () => {
499
+ let navigationPlugin;
500
+ let graphPlugin;
501
+ return {
502
+ meta: meta_default,
503
+ ready: async (plugins) => {
504
+ navigationPlugin = resolvePlugin(plugins, parseNavigationPlugin2);
505
+ graphPlugin = resolvePlugin(plugins, parseGraphPlugin2);
506
+ },
507
+ provides: {
508
+ translations: translations_default,
509
+ metadata: {
510
+ records: {
511
+ [SEARCH_RESULT]: {
512
+ parse: (item, type) => {
513
+ switch (type) {
514
+ case "node":
515
+ return {
516
+ id: item.id,
517
+ label: item.label,
518
+ data: item.object
519
+ };
520
+ case "object":
521
+ return item.object;
522
+ case "view-object":
523
+ return item;
524
+ }
525
+ }
526
+ }
527
+ }
528
+ },
529
+ graph: {
530
+ builder: (plugins) => {
531
+ const intentPlugin = resolvePlugin(plugins, parseIntentPlugin);
532
+ return createExtension({
533
+ id: SEARCH_PLUGIN,
534
+ filter: (node) => node.id === "root",
535
+ actions: () => [
536
+ {
537
+ id: SearchAction.SEARCH,
538
+ data: async () => {
539
+ await intentPlugin?.provides.intent.dispatch({
540
+ plugin: SEARCH_PLUGIN,
541
+ action: SearchAction.SEARCH
542
+ });
543
+ },
544
+ properties: {
545
+ label: [
546
+ "search action label",
547
+ {
548
+ ns: SEARCH_PLUGIN
549
+ }
550
+ ],
551
+ icon: (props) => /* @__PURE__ */ React6.createElement(MagnifyingGlass2, props),
552
+ iconSymbol: "ph--magnifying-glass--regular",
553
+ keyBinding: {
554
+ macos: "shift+meta+f",
555
+ windows: "shift+alt+f"
556
+ },
557
+ testId: "searchPlugin.search"
558
+ }
559
+ }
560
+ ]
561
+ });
562
+ }
563
+ },
564
+ context: ({ children }) => /* @__PURE__ */ React6.createElement(SearchContextProvider, null, children),
565
+ surface: {
566
+ component: ({ data, role }) => {
567
+ const location = navigationPlugin?.provides.location;
568
+ const graph = graphPlugin?.provides.graph;
569
+ const space = graph && location ? getActiveSpace(graph, firstIdInPart(location.active, "main")) : void 0;
570
+ switch (role) {
571
+ case "dialog":
572
+ return data.component === `${SEARCH_PLUGIN}/Dialog` ? /* @__PURE__ */ React6.createElement(SearchDialog, {
573
+ subject: data.subject
574
+ }) : null;
575
+ case "search-input":
576
+ return space ? /* @__PURE__ */ React6.createElement(SearchMain, {
577
+ space
578
+ }) : null;
579
+ }
580
+ return null;
581
+ }
582
+ },
583
+ intent: {
584
+ resolver: (intent, plugins) => {
585
+ switch (intent.action) {
586
+ case SearchAction.SEARCH: {
587
+ const intentPlugin = resolvePlugin(plugins, parseIntentPlugin);
588
+ return intentPlugin?.provides.intent.dispatch({
589
+ action: LayoutAction2.SET_LAYOUT,
590
+ data: {
591
+ element: "complementary",
592
+ state: true
593
+ }
594
+ });
595
+ }
596
+ }
597
+ }
598
+ }
599
+ }
600
+ };
601
+ };
602
+
603
+ // packages/plugins/experimental/plugin-search/src/index.ts
604
+ var src_default = SearchPlugin;
605
+ export {
606
+ SearchContextProvider,
607
+ SearchPlugin,
608
+ src_default as default,
609
+ filterObjectsSync,
610
+ mapObjectToTextFields,
611
+ queryStringToMatch,
612
+ useGlobalFilteredObjects,
613
+ useGlobalSearch,
614
+ useGlobalSearchResults
615
+ };
616
+ //# sourceMappingURL=index.mjs.map