@backstage/plugin-search-react 1.7.1-next.0 → 1.7.1-next.1
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/CHANGELOG.md +15 -0
- package/alpha/package.json +7 -0
- package/dist/alpha.d.ts +54 -0
- package/dist/alpha.esm.js +47 -0
- package/dist/alpha.esm.js.map +1 -0
- package/dist/esm/extensions-c878c532.esm.js +200 -0
- package/dist/esm/extensions-c878c532.esm.js.map +1 -0
- package/dist/index.esm.js +11 -201
- package/dist/index.esm.js.map +1 -1
- package/package.json +25 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @backstage/plugin-search-react
|
|
2
2
|
|
|
3
|
+
## 1.7.1-next.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 703a4ffc5b: Create `createSearchResultListItem` alpha version that only supports declarative integration.
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @backstage/frontend-plugin-api@0.1.1-next.1
|
|
10
|
+
- @backstage/core-components@0.13.6-next.1
|
|
11
|
+
- @backstage/frontend-app-api@0.2.0-next.1
|
|
12
|
+
- @backstage/core-plugin-api@1.7.0-next.0
|
|
13
|
+
- @backstage/theme@0.4.2
|
|
14
|
+
- @backstage/types@1.1.1
|
|
15
|
+
- @backstage/version-bridge@1.0.5
|
|
16
|
+
- @backstage/plugin-search-common@1.2.6
|
|
17
|
+
|
|
3
18
|
## 1.7.1-next.0
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/alpha.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import * as _backstage_frontend_plugin_api from '@backstage/frontend-plugin-api';
|
|
3
|
+
import { PortableSchema } from '@backstage/frontend-plugin-api';
|
|
4
|
+
import { ListItemProps } from '@material-ui/core';
|
|
5
|
+
import { SearchDocument, SearchResult } from '@backstage/plugin-search-common';
|
|
6
|
+
|
|
7
|
+
/** @alpha */
|
|
8
|
+
type BaseSearchResultListItemProps<T = {}> = T & {
|
|
9
|
+
rank?: number;
|
|
10
|
+
result?: SearchDocument;
|
|
11
|
+
} & Omit<ListItemProps, 'button'>;
|
|
12
|
+
/** @alpha */
|
|
13
|
+
type SearchResultItemExtensionComponent = <P extends BaseSearchResultListItemProps>(props: P) => JSX.Element | null;
|
|
14
|
+
/** @alpha */
|
|
15
|
+
type SearchResultItemExtensionPredicate = (result: SearchResult) => boolean;
|
|
16
|
+
/** @alpha */
|
|
17
|
+
declare const searchResultItemExtensionData: _backstage_frontend_plugin_api.ConfigurableExtensionDataRef<{
|
|
18
|
+
predicate?: SearchResultItemExtensionPredicate | undefined;
|
|
19
|
+
component: SearchResultItemExtensionComponent;
|
|
20
|
+
}, {}>;
|
|
21
|
+
/** @alpha */
|
|
22
|
+
type SearchResultItemExtensionOptions<TConfig extends {
|
|
23
|
+
noTrack?: boolean;
|
|
24
|
+
}> = {
|
|
25
|
+
/**
|
|
26
|
+
* The extension id.
|
|
27
|
+
*/
|
|
28
|
+
id: string;
|
|
29
|
+
/**
|
|
30
|
+
* The extension attachment point (e.g., search modal or page).
|
|
31
|
+
*/
|
|
32
|
+
at?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Optional extension config schema.
|
|
35
|
+
*/
|
|
36
|
+
configSchema?: PortableSchema<TConfig>;
|
|
37
|
+
/**
|
|
38
|
+
* The extension component.
|
|
39
|
+
*/
|
|
40
|
+
component: (options: {
|
|
41
|
+
config: TConfig;
|
|
42
|
+
}) => Promise<SearchResultItemExtensionComponent>;
|
|
43
|
+
/**
|
|
44
|
+
* When an extension defines a predicate, it returns true if the result should be rendered by that extension.
|
|
45
|
+
* Defaults to a predicate that returns true, which means it renders all sorts of results.
|
|
46
|
+
*/
|
|
47
|
+
predicate?: SearchResultItemExtensionPredicate;
|
|
48
|
+
};
|
|
49
|
+
/** @alpha */
|
|
50
|
+
declare function createSearchResultListItemExtension<TConfig extends {
|
|
51
|
+
noTrack?: boolean;
|
|
52
|
+
}>(options: SearchResultItemExtensionOptions<TConfig>): _backstage_frontend_plugin_api.Extension<TConfig>;
|
|
53
|
+
|
|
54
|
+
export { BaseSearchResultListItemProps, SearchResultItemExtensionComponent, SearchResultItemExtensionOptions, SearchResultItemExtensionPredicate, createSearchResultListItemExtension, searchResultItemExtensionData };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import React, { lazy, Suspense } from 'react';
|
|
2
|
+
import { createExtensionDataRef, createSchemaFromZod, createExtension, ExtensionBoundary } from '@backstage/frontend-plugin-api';
|
|
3
|
+
import { Progress } from '@backstage/core-components';
|
|
4
|
+
import { a as SearchResultListItemExtension } from './esm/extensions-c878c532.esm.js';
|
|
5
|
+
import '@backstage/core-plugin-api';
|
|
6
|
+
import '@material-ui/core';
|
|
7
|
+
import '@material-ui/core/Typography';
|
|
8
|
+
|
|
9
|
+
const searchResultItemExtensionData = createExtensionDataRef("plugin.search.result.item.data");
|
|
10
|
+
function createSearchResultListItemExtension(options) {
|
|
11
|
+
var _a;
|
|
12
|
+
const configSchema = "configSchema" in options ? options.configSchema : createSchemaFromZod(
|
|
13
|
+
(z) => z.object({
|
|
14
|
+
noTrack: z.boolean().default(false)
|
|
15
|
+
})
|
|
16
|
+
);
|
|
17
|
+
return createExtension({
|
|
18
|
+
id: `plugin.search.result.item.${options.id}`,
|
|
19
|
+
at: (_a = options.at) != null ? _a : "plugin.search.page/items",
|
|
20
|
+
configSchema,
|
|
21
|
+
output: {
|
|
22
|
+
item: searchResultItemExtensionData
|
|
23
|
+
},
|
|
24
|
+
factory({ bind, config, source }) {
|
|
25
|
+
const LazyComponent = lazy(
|
|
26
|
+
() => options.component({ config }).then((component) => ({ default: component }))
|
|
27
|
+
);
|
|
28
|
+
bind({
|
|
29
|
+
item: {
|
|
30
|
+
predicate: options.predicate,
|
|
31
|
+
component: (props) => /* @__PURE__ */ React.createElement(ExtensionBoundary, { source }, /* @__PURE__ */ React.createElement(Suspense, { fallback: /* @__PURE__ */ React.createElement(Progress, null) }, /* @__PURE__ */ React.createElement(
|
|
32
|
+
SearchResultListItemExtension,
|
|
33
|
+
{
|
|
34
|
+
rank: props.rank,
|
|
35
|
+
result: props.result,
|
|
36
|
+
noTrack: config.noTrack
|
|
37
|
+
},
|
|
38
|
+
/* @__PURE__ */ React.createElement(LazyComponent, { ...props })
|
|
39
|
+
)))
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { createSearchResultListItemExtension, searchResultItemExtensionData };
|
|
47
|
+
//# sourceMappingURL=alpha.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alpha.esm.js","sources":["../src/alpha.tsx"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { lazy, Suspense } from 'react';\n\nimport { ListItemProps } from '@material-ui/core';\n\nimport {\n ExtensionBoundary,\n PortableSchema,\n createExtension,\n createExtensionDataRef,\n createSchemaFromZod,\n} from '@backstage/frontend-plugin-api';\nimport { Progress } from '@backstage/core-components';\nimport { SearchDocument, SearchResult } from '@backstage/plugin-search-common';\n\nimport { SearchResultListItemExtension } from './extensions';\n\n/** @alpha */\nexport type BaseSearchResultListItemProps<T = {}> = T & {\n rank?: number;\n result?: SearchDocument;\n} & Omit<ListItemProps, 'button'>;\n\n/** @alpha */\nexport type SearchResultItemExtensionComponent = <\n P extends BaseSearchResultListItemProps,\n>(\n props: P,\n) => JSX.Element | null;\n\n/** @alpha */\nexport type SearchResultItemExtensionPredicate = (\n result: SearchResult,\n) => boolean;\n\n/** @alpha */\nexport const searchResultItemExtensionData = createExtensionDataRef<{\n predicate?: SearchResultItemExtensionPredicate;\n component: SearchResultItemExtensionComponent;\n}>('plugin.search.result.item.data');\n\n/** @alpha */\nexport type SearchResultItemExtensionOptions<\n TConfig extends { noTrack?: boolean },\n> = {\n /**\n * The extension id.\n */\n id: string;\n /**\n * The extension attachment point (e.g., search modal or page).\n */\n at?: string;\n /**\n * Optional extension config schema.\n */\n configSchema?: PortableSchema<TConfig>;\n /**\n * The extension component.\n */\n component: (options: {\n config: TConfig;\n }) => Promise<SearchResultItemExtensionComponent>;\n /**\n * When an extension defines a predicate, it returns true if the result should be rendered by that extension.\n * Defaults to a predicate that returns true, which means it renders all sorts of results.\n */\n predicate?: SearchResultItemExtensionPredicate;\n};\n\n/** @alpha */\nexport function createSearchResultListItemExtension<\n TConfig extends { noTrack?: boolean },\n>(options: SearchResultItemExtensionOptions<TConfig>) {\n const configSchema =\n 'configSchema' in options\n ? options.configSchema\n : (createSchemaFromZod(z =>\n z.object({\n noTrack: z.boolean().default(false),\n }),\n ) as PortableSchema<TConfig>);\n return createExtension({\n id: `plugin.search.result.item.${options.id}`,\n at: options.at ?? 'plugin.search.page/items',\n configSchema,\n output: {\n item: searchResultItemExtensionData,\n },\n factory({ bind, config, source }) {\n const LazyComponent = lazy(() =>\n options\n .component({ config })\n .then(component => ({ default: component })),\n ) as unknown as SearchResultItemExtensionComponent;\n\n bind({\n item: {\n predicate: options.predicate,\n component: props => (\n <ExtensionBoundary source={source}>\n <Suspense fallback={<Progress />}>\n <SearchResultListItemExtension\n rank={props.rank}\n result={props.result}\n noTrack={config.noTrack}\n >\n <LazyComponent {...props} />\n </SearchResultListItemExtension>\n </Suspense>\n </ExtensionBoundary>\n ),\n },\n });\n },\n });\n}\n"],"names":[],"mappings":";;;;;;;;AAmDa,MAAA,6BAAA,GAAgC,uBAG1C,gCA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M,CAAA,IAAA;AAAA,cACZ,QAAQ,KAAM,CAAA,MAAA;AAAA,cACd,SAAS,MAAO,CAAA,OAAA;AAAA,aAAA;AAAA,4BAEhB,KAAA,CAAA,aAAA,CAAC,aAAe,EAAA,EAAA,GAAG,KAAO,EAAA,CAAA;AAAA,WAE9B,CACF,CAAA;AAAA,SAEJ;AAAA,OACD,CAAA,CAAA;AAAA,KACH;AAAA,GACD,CAAA,CAAA;AACH;;;;"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import React, { useMemo, useCallback, createElement, Fragment, isValidElement, cloneElement } from 'react';
|
|
2
|
+
import { AnalyticsContext, useAnalytics, createReactExtension, useElementFilter, getComponentData } from '@backstage/core-plugin-api';
|
|
3
|
+
import { makeStyles, ListItemIcon, ListItemText, Box, ListItem, List } from '@material-ui/core';
|
|
4
|
+
import Typography from '@material-ui/core/Typography';
|
|
5
|
+
import { Link } from '@backstage/core-components';
|
|
6
|
+
|
|
7
|
+
const useStyles = makeStyles(
|
|
8
|
+
() => ({
|
|
9
|
+
highlight: {}
|
|
10
|
+
}),
|
|
11
|
+
{ name: "BackstageHighlightedSearchResultText" }
|
|
12
|
+
);
|
|
13
|
+
const HighlightedSearchResultText = (props) => {
|
|
14
|
+
const { text, preTag, postTag } = props;
|
|
15
|
+
const classes = useStyles();
|
|
16
|
+
const terms = useMemo(
|
|
17
|
+
() => text.split(new RegExp(`(${preTag}.+?${postTag})`)),
|
|
18
|
+
[postTag, preTag, text]
|
|
19
|
+
);
|
|
20
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, terms.map(
|
|
21
|
+
(t, idx) => t.includes(preTag) ? /* @__PURE__ */ React.createElement("mark", { className: classes.highlight, key: idx }, t.replace(new RegExp(`${preTag}|${postTag}`, "g"), "")) : t
|
|
22
|
+
));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const DefaultResultListItemComponent = ({
|
|
26
|
+
result,
|
|
27
|
+
highlight,
|
|
28
|
+
icon,
|
|
29
|
+
secondaryAction,
|
|
30
|
+
lineClamp = 5
|
|
31
|
+
}) => {
|
|
32
|
+
if (!result)
|
|
33
|
+
return null;
|
|
34
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, icon && /* @__PURE__ */ React.createElement(ListItemIcon, null, icon), /* @__PURE__ */ React.createElement(
|
|
35
|
+
ListItemText,
|
|
36
|
+
{
|
|
37
|
+
primaryTypographyProps: { variant: "h6" },
|
|
38
|
+
primary: /* @__PURE__ */ React.createElement(Link, { noTrack: true, to: result.location }, (highlight == null ? void 0 : highlight.fields.title) ? /* @__PURE__ */ React.createElement(
|
|
39
|
+
HighlightedSearchResultText,
|
|
40
|
+
{
|
|
41
|
+
text: (highlight == null ? void 0 : highlight.fields.title) || "",
|
|
42
|
+
preTag: (highlight == null ? void 0 : highlight.preTag) || "",
|
|
43
|
+
postTag: (highlight == null ? void 0 : highlight.postTag) || ""
|
|
44
|
+
}
|
|
45
|
+
) : result.title),
|
|
46
|
+
secondary: /* @__PURE__ */ React.createElement(
|
|
47
|
+
Typography,
|
|
48
|
+
{
|
|
49
|
+
component: "span",
|
|
50
|
+
style: {
|
|
51
|
+
display: "-webkit-box",
|
|
52
|
+
WebkitBoxOrient: "vertical",
|
|
53
|
+
WebkitLineClamp: lineClamp,
|
|
54
|
+
overflow: "hidden"
|
|
55
|
+
},
|
|
56
|
+
color: "textSecondary",
|
|
57
|
+
variant: "body2"
|
|
58
|
+
},
|
|
59
|
+
(highlight == null ? void 0 : highlight.fields.text) ? /* @__PURE__ */ React.createElement(
|
|
60
|
+
HighlightedSearchResultText,
|
|
61
|
+
{
|
|
62
|
+
text: highlight.fields.text,
|
|
63
|
+
preTag: highlight.preTag,
|
|
64
|
+
postTag: highlight.postTag
|
|
65
|
+
}
|
|
66
|
+
) : result.text
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
), secondaryAction && /* @__PURE__ */ React.createElement(Box, { alignItems: "flex-end" }, secondaryAction));
|
|
70
|
+
};
|
|
71
|
+
const HigherOrderDefaultResultListItem = (props) => {
|
|
72
|
+
return /* @__PURE__ */ React.createElement(
|
|
73
|
+
AnalyticsContext,
|
|
74
|
+
{
|
|
75
|
+
attributes: {
|
|
76
|
+
pluginId: "search",
|
|
77
|
+
extension: "DefaultResultListItem"
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
/* @__PURE__ */ React.createElement(DefaultResultListItemComponent, { ...props })
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const SEARCH_RESULT_LIST_ITEM_EXTENSION = "search.results.list.items.extensions.v1";
|
|
85
|
+
const findSearchResultListItemExtensionElement = (elements, result) => {
|
|
86
|
+
for (const element of elements) {
|
|
87
|
+
if (!isValidElement(element))
|
|
88
|
+
continue;
|
|
89
|
+
const predicate = getComponentData(
|
|
90
|
+
element,
|
|
91
|
+
SEARCH_RESULT_LIST_ITEM_EXTENSION
|
|
92
|
+
);
|
|
93
|
+
if (!(predicate == null ? void 0 : predicate(result)))
|
|
94
|
+
continue;
|
|
95
|
+
return cloneElement(element, {
|
|
96
|
+
rank: result.rank,
|
|
97
|
+
highlight: result.highlight,
|
|
98
|
+
result: result.document,
|
|
99
|
+
// Use props in situations where a consumer is manually rendering the extension
|
|
100
|
+
...element.props
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
};
|
|
105
|
+
const SearchResultListItemExtension = (props) => {
|
|
106
|
+
const {
|
|
107
|
+
rank,
|
|
108
|
+
result,
|
|
109
|
+
noTrack,
|
|
110
|
+
children,
|
|
111
|
+
alignItems = "flex-start",
|
|
112
|
+
...rest
|
|
113
|
+
} = props;
|
|
114
|
+
const analytics = useAnalytics();
|
|
115
|
+
const handleClickCapture = useCallback(() => {
|
|
116
|
+
if (noTrack)
|
|
117
|
+
return;
|
|
118
|
+
if (!result)
|
|
119
|
+
return;
|
|
120
|
+
analytics.captureEvent("discover", result.title, {
|
|
121
|
+
attributes: { to: result.location },
|
|
122
|
+
value: rank
|
|
123
|
+
});
|
|
124
|
+
}, [rank, result, noTrack, analytics]);
|
|
125
|
+
return /* @__PURE__ */ React.createElement(
|
|
126
|
+
ListItem,
|
|
127
|
+
{
|
|
128
|
+
divider: true,
|
|
129
|
+
alignItems,
|
|
130
|
+
onClickCapture: handleClickCapture,
|
|
131
|
+
...rest
|
|
132
|
+
},
|
|
133
|
+
children
|
|
134
|
+
);
|
|
135
|
+
};
|
|
136
|
+
const createSearchResultListItemExtension = (options) => {
|
|
137
|
+
const { name, component, predicate = () => true } = options;
|
|
138
|
+
return createReactExtension({
|
|
139
|
+
name,
|
|
140
|
+
component: {
|
|
141
|
+
lazy: () => component().then(
|
|
142
|
+
(type) => (props) => /* @__PURE__ */ React.createElement(
|
|
143
|
+
SearchResultListItemExtension,
|
|
144
|
+
{
|
|
145
|
+
rank: props.rank,
|
|
146
|
+
result: props.result,
|
|
147
|
+
noTrack: props.noTrack
|
|
148
|
+
},
|
|
149
|
+
createElement(type, props)
|
|
150
|
+
)
|
|
151
|
+
)
|
|
152
|
+
},
|
|
153
|
+
data: {
|
|
154
|
+
[SEARCH_RESULT_LIST_ITEM_EXTENSION]: predicate
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
const useSearchResultListItemExtensions = (children) => {
|
|
159
|
+
const elements = useElementFilter(
|
|
160
|
+
children,
|
|
161
|
+
(collection) => {
|
|
162
|
+
return collection.selectByComponentData({
|
|
163
|
+
key: SEARCH_RESULT_LIST_ITEM_EXTENSION
|
|
164
|
+
}).getElements();
|
|
165
|
+
},
|
|
166
|
+
[children]
|
|
167
|
+
);
|
|
168
|
+
return useCallback(
|
|
169
|
+
(result, key) => {
|
|
170
|
+
const element = findSearchResultListItemExtensionElement(
|
|
171
|
+
elements,
|
|
172
|
+
result
|
|
173
|
+
);
|
|
174
|
+
return /* @__PURE__ */ React.createElement(Fragment, { key }, element != null ? element : /* @__PURE__ */ React.createElement(
|
|
175
|
+
SearchResultListItemExtension,
|
|
176
|
+
{
|
|
177
|
+
rank: result.rank,
|
|
178
|
+
result: result.document
|
|
179
|
+
},
|
|
180
|
+
/* @__PURE__ */ React.createElement(
|
|
181
|
+
HigherOrderDefaultResultListItem,
|
|
182
|
+
{
|
|
183
|
+
rank: result.rank,
|
|
184
|
+
highlight: result.highlight,
|
|
185
|
+
result: result.document
|
|
186
|
+
}
|
|
187
|
+
)
|
|
188
|
+
));
|
|
189
|
+
},
|
|
190
|
+
[elements]
|
|
191
|
+
);
|
|
192
|
+
};
|
|
193
|
+
const SearchResultListItemExtensions = (props) => {
|
|
194
|
+
const { results, children, ...rest } = props;
|
|
195
|
+
const render = useSearchResultListItemExtensions(children);
|
|
196
|
+
return /* @__PURE__ */ React.createElement(List, { ...rest }, results.map(render));
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
export { HigherOrderDefaultResultListItem as H, SearchResultListItemExtensions as S, SearchResultListItemExtension as a, HighlightedSearchResultText as b, createSearchResultListItemExtension as c, useSearchResultListItemExtensions as u };
|
|
200
|
+
//# sourceMappingURL=extensions-c878c532.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extensions-c878c532.esm.js","sources":["../../src/components/HighlightedSearchResultText/HighlightedSearchResultText.tsx","../../src/components/DefaultResultListItem/DefaultResultListItem.tsx","../../src/extensions.tsx"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { useMemo } from 'react';\nimport { makeStyles } from '@material-ui/core';\n\nconst useStyles = makeStyles(\n () => ({\n highlight: {},\n }),\n { name: 'BackstageHighlightedSearchResultText' },\n);\n\n/**\n * Props for {@link HighlightedSearchResultText}.\n *\n * @public\n */\nexport type HighlightedSearchResultTextProps = {\n text: string;\n preTag: string;\n postTag: string;\n};\n\n/**\n * @public\n */\nexport const HighlightedSearchResultText = (\n props: HighlightedSearchResultTextProps,\n) => {\n const { text, preTag, postTag } = props;\n\n const classes = useStyles();\n const terms = useMemo(\n () => text.split(new RegExp(`(${preTag}.+?${postTag})`)),\n [postTag, preTag, text],\n );\n\n return (\n <>\n {terms.map((t, idx) =>\n t.includes(preTag) ? (\n <mark className={classes.highlight} key={idx}>\n {t.replace(new RegExp(`${preTag}|${postTag}`, 'g'), '')}\n </mark>\n ) : (\n t\n ),\n )}\n </>\n );\n};\n","/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { ReactNode } from 'react';\nimport { AnalyticsContext } from '@backstage/core-plugin-api';\nimport {\n ResultHighlight,\n SearchDocument,\n} from '@backstage/plugin-search-common';\nimport { HighlightedSearchResultText } from '../HighlightedSearchResultText';\nimport { ListItemIcon, ListItemText, Box } from '@material-ui/core';\nimport Typography from '@material-ui/core/Typography';\nimport { Link } from '@backstage/core-components';\n\n/**\n * Props for {@link DefaultResultListItem}\n *\n * @public\n */\nexport type DefaultResultListItemProps = {\n icon?: ReactNode;\n secondaryAction?: ReactNode;\n result?: SearchDocument;\n highlight?: ResultHighlight;\n rank?: number;\n lineClamp?: number;\n toggleModal?: () => void;\n};\n\n/**\n * A default result list item.\n *\n * @public\n */\nexport const DefaultResultListItemComponent = ({\n result,\n highlight,\n icon,\n secondaryAction,\n lineClamp = 5,\n}: DefaultResultListItemProps) => {\n if (!result) return null;\n\n return (\n <>\n {icon && <ListItemIcon>{icon}</ListItemIcon>}\n <ListItemText\n primaryTypographyProps={{ variant: 'h6' }}\n primary={\n <Link noTrack to={result.location}>\n {highlight?.fields.title ? (\n <HighlightedSearchResultText\n text={highlight?.fields.title || ''}\n preTag={highlight?.preTag || ''}\n postTag={highlight?.postTag || ''}\n />\n ) : (\n result.title\n )}\n </Link>\n }\n secondary={\n <Typography\n component=\"span\"\n style={{\n display: '-webkit-box',\n WebkitBoxOrient: 'vertical',\n WebkitLineClamp: lineClamp,\n overflow: 'hidden',\n }}\n color=\"textSecondary\"\n variant=\"body2\"\n >\n {highlight?.fields.text ? (\n <HighlightedSearchResultText\n text={highlight.fields.text}\n preTag={highlight.preTag}\n postTag={highlight.postTag}\n />\n ) : (\n result.text\n )}\n </Typography>\n }\n />\n {secondaryAction && <Box alignItems=\"flex-end\">{secondaryAction}</Box>}\n </>\n );\n};\n\n/**\n * @public\n */\nconst HigherOrderDefaultResultListItem = (\n props: DefaultResultListItemProps,\n) => {\n return (\n <AnalyticsContext\n attributes={{\n pluginId: 'search',\n extension: 'DefaultResultListItem',\n }}\n >\n <DefaultResultListItemComponent {...props} />\n </AnalyticsContext>\n );\n};\n\nexport { HigherOrderDefaultResultListItem as DefaultResultListItem };\n","/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, {\n Fragment,\n ReactNode,\n PropsWithChildren,\n isValidElement,\n createElement,\n cloneElement,\n useCallback,\n} from 'react';\n\nimport {\n getComponentData,\n useElementFilter,\n Extension,\n createReactExtension,\n useAnalytics,\n} from '@backstage/core-plugin-api';\nimport { SearchDocument, SearchResult } from '@backstage/plugin-search-common';\n\nimport { ListItem, List, ListProps, ListItemProps } from '@material-ui/core';\n\nimport { DefaultResultListItem } from './components/DefaultResultListItem';\n\n/**\n * @internal\n * Key for result extensions.\n */\nconst SEARCH_RESULT_LIST_ITEM_EXTENSION =\n 'search.results.list.items.extensions.v1';\n\n/**\n * @internal\n * Returns the first extension element found for a given result, and null otherwise.\n * @param elements - All extension elements.\n * @param result - The search result.\n */\nconst findSearchResultListItemExtensionElement = (\n elements: ReactNode[],\n result: SearchResult,\n) => {\n for (const element of elements) {\n if (!isValidElement(element)) continue;\n const predicate = getComponentData<(result: SearchResult) => boolean>(\n element,\n SEARCH_RESULT_LIST_ITEM_EXTENSION,\n );\n if (!predicate?.(result)) continue;\n return cloneElement(element, {\n rank: result.rank,\n highlight: result.highlight,\n result: result.document,\n // Use props in situations where a consumer is manually rendering the extension\n ...element.props,\n });\n }\n return null;\n};\n\n/**\n * @public\n * Extends props for any search result list item extension\n */\nexport type SearchResultListItemExtensionProps<Props extends {} = {}> = Props &\n PropsWithChildren<\n {\n rank?: number;\n result?: SearchDocument;\n noTrack?: boolean;\n } & Omit<ListItemProps, 'button'>\n >;\n\n/**\n * @internal\n * Extends children with extension capabilities.\n * @param props - see {@link SearchResultListItemExtensionProps}.\n */\nexport const SearchResultListItemExtension = (\n props: SearchResultListItemExtensionProps,\n) => {\n const {\n rank,\n result,\n noTrack,\n children,\n alignItems = 'flex-start',\n ...rest\n } = props;\n const analytics = useAnalytics();\n\n const handleClickCapture = useCallback(() => {\n if (noTrack) return;\n if (!result) return;\n analytics.captureEvent('discover', result.title, {\n attributes: { to: result.location },\n value: rank,\n });\n }, [rank, result, noTrack, analytics]);\n\n return (\n <ListItem\n divider\n alignItems={alignItems}\n onClickCapture={handleClickCapture}\n {...rest}\n >\n {children}\n </ListItem>\n );\n};\n\n/**\n * @public\n * Options for {@link createSearchResultListItemExtension}.\n */\nexport type SearchResultListItemExtensionOptions<\n Component extends (props: any) => JSX.Element | null,\n> = {\n /**\n * The extension name.\n */\n name: string;\n /**\n * The extension component.\n */\n component: () => Promise<Component>;\n /**\n * When an extension defines a predicate, it returns true if the result should be rendered by that extension.\n * Defaults to a predicate that returns true, which means it renders all sorts of results.\n */\n predicate?: (result: SearchResult) => boolean;\n};\n\n/**\n * @public\n * Creates a search result item extension.\n * @param options - The extension options, see {@link SearchResultListItemExtensionOptions} for more details.\n */\nexport const createSearchResultListItemExtension = <\n Component extends (props: any) => JSX.Element | null,\n>(\n options: SearchResultListItemExtensionOptions<Component>,\n): Extension<Component> => {\n const { name, component, predicate = () => true } = options;\n\n return createReactExtension<Component>({\n name,\n component: {\n lazy: () =>\n component().then(\n type =>\n (props => (\n <SearchResultListItemExtension\n rank={props.rank}\n result={props.result}\n noTrack={props.noTrack}\n >\n {createElement(type, props)}\n </SearchResultListItemExtension>\n )) as Component,\n ),\n },\n data: {\n [SEARCH_RESULT_LIST_ITEM_EXTENSION]: predicate,\n },\n });\n};\n\n/**\n * @public\n * Returns a function that renders a result using extensions.\n */\nexport const useSearchResultListItemExtensions = (children: ReactNode) => {\n const elements = useElementFilter(\n children,\n collection => {\n return collection\n .selectByComponentData({\n key: SEARCH_RESULT_LIST_ITEM_EXTENSION,\n })\n .getElements();\n },\n [children],\n );\n\n return useCallback(\n (result: SearchResult, key?: number) => {\n const element = findSearchResultListItemExtensionElement(\n elements,\n result,\n );\n\n return (\n <Fragment key={key}>\n {element ?? (\n <SearchResultListItemExtension\n rank={result.rank}\n result={result.document}\n >\n <DefaultResultListItem\n rank={result.rank}\n highlight={result.highlight}\n result={result.document}\n />\n </SearchResultListItemExtension>\n )}\n </Fragment>\n );\n },\n [elements],\n );\n};\n\n/**\n * @public\n * Props for {@link SearchResultListItemExtensions}\n */\nexport type SearchResultListItemExtensionsProps = Omit<ListProps, 'results'> & {\n /**\n * Search result list.\n */\n results: SearchResult[];\n};\n\n/**\n * @public\n * Render results using search extensions.\n * @param props - see {@link SearchResultListItemExtensionsProps}\n */\nexport const SearchResultListItemExtensions = (\n props: SearchResultListItemExtensionsProps,\n) => {\n const { results, children, ...rest } = props;\n const render = useSearchResultListItemExtensions(children);\n return <List {...rest}>{results.map(render)}</List>;\n};\n"],"names":["DefaultResultListItem"],"mappings":";;;;;;AAmBA,MAAM,SAAY,GAAA,UAAA;AAAA,EAChB,OAAO;AAAA,IACL,WAAW,EAAC;AAAA,GACd,CAAA;AAAA,EACA,EAAE,MAAM,sCAAuC,EAAA;AACjD,CAAA,CAAA;AAgBa,MAAA,2BAAA,GAA8B,CACzC,KACG,KAAA;AACH,EAAA,MAAM,EAAE,IAAA,EAAM,MAAQ,EAAA,OAAA,EAAY,GAAA,KAAA,CAAA;AAElC,EAAA,MAAM,UAAU,SAAU,EAAA,CAAA;AAC1B,EAAA,MAAM,KAAQ,GAAA,OAAA;AAAA,IACZ,MAAM,IAAK,CAAA,KAAA,CAAM,IAAI,MAAA,CAAO,IAAI,MAAM,CAAA,GAAA,EAAM,OAAO,CAAA,CAAA,CAAG,CAAC,CAAA;AAAA,IACvD,CAAC,OAAS,EAAA,MAAA,EAAQ,IAAI,CAAA;AAAA,GACxB,CAAA;AAEA,EAAA,iEAEK,KAAM,CAAA,GAAA;AAAA,IAAI,CAAC,CAAG,EAAA,GAAA,KACb,CAAE,CAAA,QAAA,CAAS,MAAM,CAAA,mBACd,KAAA,CAAA,aAAA,CAAA,MAAA,EAAA,EAAK,SAAW,EAAA,OAAA,CAAQ,SAAW,EAAA,GAAA,EAAK,GACtC,EAAA,EAAA,CAAA,CAAE,OAAQ,CAAA,IAAI,MAAO,CAAA,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,OAAO,CAAA,CAAA,EAAI,GAAG,CAAA,EAAG,EAAE,CACxD,CAEA,GAAA,CAAA;AAAA,GAGN,CAAA,CAAA;AAEJ;;ACjBO,MAAM,iCAAiC,CAAC;AAA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AA,IAAA;AAAA,UACb,QAAQ,MAAO,CAAA,QAAA;AAAA,SAAA;AAAA,wBAEf,KAAA,CAAA,aAAA;AAAA,UAACA,gCAAA;AAAA,UAAA;AAAA,YACC,MAAM,MAAO,CAAA,IAAA;AAAA,YACb,WAAW,MAAO,CAAA,SAAA;AAAA,YAClB,QAAQ,MAAO,CAAA,QAAA;AAAA,WAAA;AAAA,SACjB;AAAA,OAGN,CAAA,CAAA;AAAA,KAEJ;AAAA,IACA,CAAC,QAAQ,CAAA;AAAA,GACX,CAAA;AACF,EAAA;AAkBa,MAAA,8BAAA,GAAiC,CAC5C,KACG,KAAA;AACH,EAAA,MAAM,EAAE,OAAA,EAAS,QAAU,EAAA,GAAG,MAAS,GAAA,KAAA,CAAA;AACvC,EAAM,MAAA,MAAA,GAAS,kCAAkC,QAAQ,CAAA,CAAA;AACzD,EAAA,2CAAQ,IAAM,EAAA,EAAA,GAAG,QAAO,OAAQ,CAAA,GAAA,CAAI,MAAM,CAAE,CAAA,CAAA;AAC9C;;;;"}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { createApiRef,
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import Typography from '@material-ui/core
|
|
5
|
-
import { Link, Progress, ResponseErrorPanel, EmptyState } from '@backstage/core-components';
|
|
1
|
+
import { createApiRef, useApi, configApiRef, AnalyticsContext, useAnalytics } from '@backstage/core-plugin-api';
|
|
2
|
+
import { S as SearchResultListItemExtensions, u as useSearchResultListItemExtensions, H as HigherOrderDefaultResultListItem } from './esm/extensions-c878c532.esm.js';
|
|
3
|
+
export { H as DefaultResultListItem, b as HighlightedSearchResultText, a as SearchResultListItemExtension, S as SearchResultListItemExtensions, c as createSearchResultListItemExtension, u as useSearchResultListItemExtensions } from './esm/extensions-c878c532.esm.js';
|
|
4
|
+
import { TextField, InputAdornment, IconButton, makeStyles, CircularProgress, ListItemIcon, ListItemText, Chip, FormControl, FormLabel, FormControlLabel, Checkbox, InputLabel, Select, MenuItem, Typography, TablePagination, List, InputBase, ListSubheader, Menu, Button as Button$1 } from '@material-ui/core';
|
|
6
5
|
import Button from '@material-ui/core/Button';
|
|
7
6
|
import SearchIcon from '@material-ui/icons/Search';
|
|
7
|
+
import React, { useContext, useState, useCallback, useEffect, forwardRef, useMemo, useRef } from 'react';
|
|
8
8
|
import useDebounce from 'react-use/lib/useDebounce';
|
|
9
9
|
import { isEqual, isFunction } from 'lodash';
|
|
10
10
|
import useAsync from 'react-use/lib/useAsync';
|
|
@@ -12,10 +12,12 @@ import usePrevious from 'react-use/lib/usePrevious';
|
|
|
12
12
|
import { createVersionedContext, createVersionedValueMap } from '@backstage/version-bridge';
|
|
13
13
|
import { Autocomplete } from '@material-ui/lab';
|
|
14
14
|
import useAsyncFn from 'react-use/lib/useAsyncFn';
|
|
15
|
+
import { Progress, ResponseErrorPanel, EmptyState, Link } from '@backstage/core-components';
|
|
15
16
|
import qs from 'qs';
|
|
16
17
|
import AddIcon from '@material-ui/icons/Add';
|
|
17
18
|
import ArrowRightIcon from '@material-ui/icons/ArrowForwardIos';
|
|
18
19
|
import ArrowBackIosIcon from '@material-ui/icons/ArrowBackIos';
|
|
20
|
+
import '@material-ui/core/Typography';
|
|
19
21
|
|
|
20
22
|
const searchApiRef = createApiRef({
|
|
21
23
|
id: "plugin.search.queryservice"
|
|
@@ -29,198 +31,6 @@ class MockSearchApi {
|
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
const useStyles$4 = makeStyles(
|
|
33
|
-
() => ({
|
|
34
|
-
highlight: {}
|
|
35
|
-
}),
|
|
36
|
-
{ name: "BackstageHighlightedSearchResultText" }
|
|
37
|
-
);
|
|
38
|
-
const HighlightedSearchResultText = (props) => {
|
|
39
|
-
const { text, preTag, postTag } = props;
|
|
40
|
-
const classes = useStyles$4();
|
|
41
|
-
const terms = useMemo(
|
|
42
|
-
() => text.split(new RegExp(`(${preTag}.+?${postTag})`)),
|
|
43
|
-
[postTag, preTag, text]
|
|
44
|
-
);
|
|
45
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, terms.map(
|
|
46
|
-
(t, idx) => t.includes(preTag) ? /* @__PURE__ */ React.createElement("mark", { className: classes.highlight, key: idx }, t.replace(new RegExp(`${preTag}|${postTag}`, "g"), "")) : t
|
|
47
|
-
));
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const DefaultResultListItemComponent = ({
|
|
51
|
-
result,
|
|
52
|
-
highlight,
|
|
53
|
-
icon,
|
|
54
|
-
secondaryAction,
|
|
55
|
-
lineClamp = 5
|
|
56
|
-
}) => {
|
|
57
|
-
if (!result)
|
|
58
|
-
return null;
|
|
59
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, icon && /* @__PURE__ */ React.createElement(ListItemIcon, null, icon), /* @__PURE__ */ React.createElement(
|
|
60
|
-
ListItemText,
|
|
61
|
-
{
|
|
62
|
-
primaryTypographyProps: { variant: "h6" },
|
|
63
|
-
primary: /* @__PURE__ */ React.createElement(Link, { noTrack: true, to: result.location }, (highlight == null ? void 0 : highlight.fields.title) ? /* @__PURE__ */ React.createElement(
|
|
64
|
-
HighlightedSearchResultText,
|
|
65
|
-
{
|
|
66
|
-
text: (highlight == null ? void 0 : highlight.fields.title) || "",
|
|
67
|
-
preTag: (highlight == null ? void 0 : highlight.preTag) || "",
|
|
68
|
-
postTag: (highlight == null ? void 0 : highlight.postTag) || ""
|
|
69
|
-
}
|
|
70
|
-
) : result.title),
|
|
71
|
-
secondary: /* @__PURE__ */ React.createElement(
|
|
72
|
-
Typography,
|
|
73
|
-
{
|
|
74
|
-
component: "span",
|
|
75
|
-
style: {
|
|
76
|
-
display: "-webkit-box",
|
|
77
|
-
WebkitBoxOrient: "vertical",
|
|
78
|
-
WebkitLineClamp: lineClamp,
|
|
79
|
-
overflow: "hidden"
|
|
80
|
-
},
|
|
81
|
-
color: "textSecondary",
|
|
82
|
-
variant: "body2"
|
|
83
|
-
},
|
|
84
|
-
(highlight == null ? void 0 : highlight.fields.text) ? /* @__PURE__ */ React.createElement(
|
|
85
|
-
HighlightedSearchResultText,
|
|
86
|
-
{
|
|
87
|
-
text: highlight.fields.text,
|
|
88
|
-
preTag: highlight.preTag,
|
|
89
|
-
postTag: highlight.postTag
|
|
90
|
-
}
|
|
91
|
-
) : result.text
|
|
92
|
-
)
|
|
93
|
-
}
|
|
94
|
-
), secondaryAction && /* @__PURE__ */ React.createElement(Box, { alignItems: "flex-end" }, secondaryAction));
|
|
95
|
-
};
|
|
96
|
-
const HigherOrderDefaultResultListItem = (props) => {
|
|
97
|
-
return /* @__PURE__ */ React.createElement(
|
|
98
|
-
AnalyticsContext,
|
|
99
|
-
{
|
|
100
|
-
attributes: {
|
|
101
|
-
pluginId: "search",
|
|
102
|
-
extension: "DefaultResultListItem"
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
/* @__PURE__ */ React.createElement(DefaultResultListItemComponent, { ...props })
|
|
106
|
-
);
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const SEARCH_RESULT_LIST_ITEM_EXTENSION = "search.results.list.items.extensions.v1";
|
|
110
|
-
const findSearchResultListItemExtensionElement = (elements, result) => {
|
|
111
|
-
for (const element of elements) {
|
|
112
|
-
if (!isValidElement(element))
|
|
113
|
-
continue;
|
|
114
|
-
const predicate = getComponentData(
|
|
115
|
-
element,
|
|
116
|
-
SEARCH_RESULT_LIST_ITEM_EXTENSION
|
|
117
|
-
);
|
|
118
|
-
if (!(predicate == null ? void 0 : predicate(result)))
|
|
119
|
-
continue;
|
|
120
|
-
return cloneElement(element, {
|
|
121
|
-
rank: result.rank,
|
|
122
|
-
highlight: result.highlight,
|
|
123
|
-
result: result.document,
|
|
124
|
-
// Use props in situations where a consumer is manually rendering the extension
|
|
125
|
-
...element.props
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
return null;
|
|
129
|
-
};
|
|
130
|
-
const SearchResultListItemExtension = (props) => {
|
|
131
|
-
const {
|
|
132
|
-
rank,
|
|
133
|
-
result,
|
|
134
|
-
noTrack,
|
|
135
|
-
children,
|
|
136
|
-
alignItems = "flex-start",
|
|
137
|
-
...rest
|
|
138
|
-
} = props;
|
|
139
|
-
const analytics = useAnalytics();
|
|
140
|
-
const handleClickCapture = useCallback(() => {
|
|
141
|
-
if (noTrack)
|
|
142
|
-
return;
|
|
143
|
-
if (!result)
|
|
144
|
-
return;
|
|
145
|
-
analytics.captureEvent("discover", result.title, {
|
|
146
|
-
attributes: { to: result.location },
|
|
147
|
-
value: rank
|
|
148
|
-
});
|
|
149
|
-
}, [rank, result, noTrack, analytics]);
|
|
150
|
-
return /* @__PURE__ */ React.createElement(
|
|
151
|
-
ListItem,
|
|
152
|
-
{
|
|
153
|
-
divider: true,
|
|
154
|
-
alignItems,
|
|
155
|
-
onClickCapture: handleClickCapture,
|
|
156
|
-
...rest
|
|
157
|
-
},
|
|
158
|
-
children
|
|
159
|
-
);
|
|
160
|
-
};
|
|
161
|
-
const createSearchResultListItemExtension = (options) => {
|
|
162
|
-
const { name, component, predicate = () => true } = options;
|
|
163
|
-
return createReactExtension({
|
|
164
|
-
name,
|
|
165
|
-
component: {
|
|
166
|
-
lazy: () => component().then(
|
|
167
|
-
(type) => (props) => /* @__PURE__ */ React.createElement(
|
|
168
|
-
SearchResultListItemExtension,
|
|
169
|
-
{
|
|
170
|
-
rank: props.rank,
|
|
171
|
-
result: props.result,
|
|
172
|
-
noTrack: props.noTrack
|
|
173
|
-
},
|
|
174
|
-
createElement(type, props)
|
|
175
|
-
)
|
|
176
|
-
)
|
|
177
|
-
},
|
|
178
|
-
data: {
|
|
179
|
-
[SEARCH_RESULT_LIST_ITEM_EXTENSION]: predicate
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
};
|
|
183
|
-
const useSearchResultListItemExtensions = (children) => {
|
|
184
|
-
const elements = useElementFilter(
|
|
185
|
-
children,
|
|
186
|
-
(collection) => {
|
|
187
|
-
return collection.selectByComponentData({
|
|
188
|
-
key: SEARCH_RESULT_LIST_ITEM_EXTENSION
|
|
189
|
-
}).getElements();
|
|
190
|
-
},
|
|
191
|
-
[children]
|
|
192
|
-
);
|
|
193
|
-
return useCallback(
|
|
194
|
-
(result, key) => {
|
|
195
|
-
const element = findSearchResultListItemExtensionElement(
|
|
196
|
-
elements,
|
|
197
|
-
result
|
|
198
|
-
);
|
|
199
|
-
return /* @__PURE__ */ React.createElement(Fragment, { key }, element != null ? element : /* @__PURE__ */ React.createElement(
|
|
200
|
-
SearchResultListItemExtension,
|
|
201
|
-
{
|
|
202
|
-
rank: result.rank,
|
|
203
|
-
result: result.document
|
|
204
|
-
},
|
|
205
|
-
/* @__PURE__ */ React.createElement(
|
|
206
|
-
HigherOrderDefaultResultListItem,
|
|
207
|
-
{
|
|
208
|
-
rank: result.rank,
|
|
209
|
-
highlight: result.highlight,
|
|
210
|
-
result: result.document
|
|
211
|
-
}
|
|
212
|
-
)
|
|
213
|
-
));
|
|
214
|
-
},
|
|
215
|
-
[elements]
|
|
216
|
-
);
|
|
217
|
-
};
|
|
218
|
-
const SearchResultListItemExtensions = (props) => {
|
|
219
|
-
const { results, children, ...rest } = props;
|
|
220
|
-
const render = useSearchResultListItemExtensions(children);
|
|
221
|
-
return /* @__PURE__ */ React.createElement(List, { ...rest }, results.map(render));
|
|
222
|
-
};
|
|
223
|
-
|
|
224
34
|
const SearchContext = createVersionedContext("search-context");
|
|
225
35
|
const useSearch = () => {
|
|
226
36
|
const context = useContext(SearchContext);
|
|
@@ -843,7 +653,7 @@ const SelectFilter = (props) => {
|
|
|
843
653
|
onChange: handleChange
|
|
844
654
|
},
|
|
845
655
|
/* @__PURE__ */ React.createElement(MenuItem, { value: "" }, /* @__PURE__ */ React.createElement("em", null, "All")),
|
|
846
|
-
values.map((value) => /* @__PURE__ */ React.createElement(MenuItem, { key: value, value }, /* @__PURE__ */ React.createElement(Typography
|
|
656
|
+
values.map((value) => /* @__PURE__ */ React.createElement(MenuItem, { key: value, value }, /* @__PURE__ */ React.createElement(Typography, { variant: "inherit", noWrap: true }, value)))
|
|
847
657
|
)
|
|
848
658
|
);
|
|
849
659
|
};
|
|
@@ -1115,7 +925,7 @@ const SearchResultGroupTextFilterField = (props) => {
|
|
|
1115
925
|
[onChange]
|
|
1116
926
|
);
|
|
1117
927
|
return /* @__PURE__ */ React.createElement(SearchResultGroupFilterFieldLayout, { label, onDelete }, /* @__PURE__ */ React.createElement(
|
|
1118
|
-
Typography
|
|
928
|
+
Typography,
|
|
1119
929
|
{
|
|
1120
930
|
role: "textbox",
|
|
1121
931
|
component: "span",
|
|
@@ -1216,7 +1026,7 @@ function SearchResultGroupLayout(props) {
|
|
|
1216
1026
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, noResultsComponent);
|
|
1217
1027
|
}
|
|
1218
1028
|
return /* @__PURE__ */ React.createElement(List, { ...rest }, /* @__PURE__ */ React.createElement(ListSubheader, { className: classes.listSubheader }, icon, /* @__PURE__ */ React.createElement(
|
|
1219
|
-
Typography
|
|
1029
|
+
Typography,
|
|
1220
1030
|
{
|
|
1221
1031
|
className: classes.listSubheaderName,
|
|
1222
1032
|
component: "strong",
|
|
@@ -1320,5 +1130,5 @@ const SearchResultPager = () => {
|
|
|
1320
1130
|
));
|
|
1321
1131
|
};
|
|
1322
1132
|
|
|
1323
|
-
export { AutocompleteFilter, CheckboxFilter,
|
|
1133
|
+
export { AutocompleteFilter, CheckboxFilter, MockSearchApi, SearchAutocomplete, SearchAutocompleteDefaultOption, SearchBar, SearchBarBase, SearchContextProvider, SearchFilter, SearchPagination, SearchPaginationBase, SearchResult, SearchResultApi, SearchResultComponent, SearchResultContext, SearchResultGroup, SearchResultGroupFilterFieldLayout, SearchResultGroupLayout, SearchResultGroupSelectFilterField, SearchResultGroupTextFilterField, SearchResultList, SearchResultListLayout, SearchResultPager, SearchResultState, SelectFilter, searchApiRef, useSearch, useSearchContextCheck };
|
|
1324
1134
|
//# sourceMappingURL=index.esm.js.map
|