@fluid-topics/ft-search-input 1.2.1 → 1.2.3
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/build/ft-search-input-suggestion.d.ts +4 -0
- package/build/ft-search-input-suggestion.js +52 -16
- package/build/ft-search-input.d.ts +3 -0
- package/build/ft-search-input.js +29 -4
- package/build/ft-search-input.light.js +185 -159
- package/build/ft-search-input.min.js +220 -194
- package/package.json +11 -10
|
@@ -7,8 +7,12 @@ export declare class SuggestionSelectedEvent extends CustomEvent<string> {
|
|
|
7
7
|
export declare class FtSearchInputSuggestion extends FtSearchComponent implements FtSearchInputSuggestionProperties {
|
|
8
8
|
static elementDefinitions: ElementDefinitionsMap;
|
|
9
9
|
static styles: import("lit").CSSResult[];
|
|
10
|
+
private request?;
|
|
10
11
|
private suggestResults?;
|
|
12
|
+
launchSearchPath?: string;
|
|
11
13
|
render(): import("lit").TemplateResult<1>;
|
|
14
|
+
private renderSuggestion;
|
|
15
|
+
private onSuggestLinkClick;
|
|
12
16
|
private onSuggestKeyDown;
|
|
13
17
|
private onSuggestKeyUp;
|
|
14
18
|
private onSuggestSelected;
|
|
@@ -6,13 +6,14 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
import { redux, wordWrap } from "@fluid-topics/ft-wc-utils";
|
|
8
8
|
import { html } from "lit";
|
|
9
|
-
import { customElement } from "lit/decorators.js";
|
|
9
|
+
import { customElement, property } from "lit/decorators.js";
|
|
10
10
|
import { suggestionStyles } from "./ft-search-input-suggestion.styles";
|
|
11
11
|
import { repeat } from "lit/directives/repeat.js";
|
|
12
12
|
import { FtIcon, FtIcons, FtIconVariants, resolveFileFormatIcon } from "@fluid-topics/ft-icon";
|
|
13
13
|
import { FtRipple } from "@fluid-topics/ft-ripple";
|
|
14
14
|
import { FtTypography } from "@fluid-topics/ft-typography";
|
|
15
15
|
import { FtSearchComponent } from "@fluid-topics/ft-search-context/build/registration";
|
|
16
|
+
import { SearchPlaceConverterProvider } from "@fluid-topics/ft-app-context";
|
|
16
17
|
export class SuggestionSelectedEvent extends CustomEvent {
|
|
17
18
|
constructor(value) {
|
|
18
19
|
super("suggestion-selected", { detail: value });
|
|
@@ -20,24 +21,52 @@ export class SuggestionSelectedEvent extends CustomEvent {
|
|
|
20
21
|
}
|
|
21
22
|
let FtSearchInputSuggestion = class FtSearchInputSuggestion extends FtSearchComponent {
|
|
22
23
|
render() {
|
|
24
|
+
const searchPlaceConverter = SearchPlaceConverterProvider.get();
|
|
23
25
|
return html `
|
|
24
26
|
<div class="ft-search-input-suggestion ft-word-wrap"
|
|
25
27
|
part="container"
|
|
26
28
|
@keydown=${(e) => this.onSuggestKeyDown(e)}>
|
|
27
|
-
${repeat(this.suggestResults || [], suggest => suggest.value, suggest =>
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class="ft-search-input-suggestion--suggestion"
|
|
31
|
-
@keyup=${(e) => this.onSuggestKeyUp(e, suggest.value)}
|
|
32
|
-
@click=${(e) => this.onSuggestSelected(e, suggest.value)}>
|
|
33
|
-
<ft-ripple></ft-ripple>
|
|
34
|
-
${this.getIcon(suggest)}
|
|
35
|
-
<ft-typography variant="body1">${suggest.value}</ft-typography>
|
|
36
|
-
</a>
|
|
37
|
-
`)}
|
|
29
|
+
${repeat(this.suggestResults || [], suggest => suggest.value, suggest => {
|
|
30
|
+
return this.renderSuggestion(suggest, searchPlaceConverter);
|
|
31
|
+
})}
|
|
38
32
|
</div>
|
|
39
33
|
`;
|
|
40
34
|
}
|
|
35
|
+
renderSuggestion(suggest, searchPlaceConverter) {
|
|
36
|
+
if (this.launchSearchPath) {
|
|
37
|
+
const suggestRequest = { ...this.request, query: suggest.value };
|
|
38
|
+
const launchSuggestUrl = searchPlaceConverter.serializeToCurrentPageIfPossible(suggestRequest, this.launchSearchPath);
|
|
39
|
+
return html `
|
|
40
|
+
<a href="${launchSuggestUrl}"
|
|
41
|
+
part="suggestion"
|
|
42
|
+
class="ft-search-input-suggestion--suggestion"
|
|
43
|
+
@keyup=${(e) => this.onSuggestKeyUp(e)}
|
|
44
|
+
@click=${(e) => this.onSuggestLinkClick(e, suggest)}>
|
|
45
|
+
<ft-ripple></ft-ripple>
|
|
46
|
+
${this.getIcon(suggest)}
|
|
47
|
+
<ft-typography variant="body1">${suggest.value}</ft-typography>
|
|
48
|
+
</a>
|
|
49
|
+
`;
|
|
50
|
+
}
|
|
51
|
+
return html `
|
|
52
|
+
<div tabindex="0"
|
|
53
|
+
part="suggestion"
|
|
54
|
+
class="ft-search-input-suggestion--suggestion"
|
|
55
|
+
@keyup=${(e) => this.onSuggestKeyUp(e)}
|
|
56
|
+
@click=${(e) => this.onSuggestSelected(suggest.value)}>
|
|
57
|
+
<ft-ripple></ft-ripple>
|
|
58
|
+
${this.getIcon(suggest)}
|
|
59
|
+
<ft-typography variant="body1">${suggest.value}</ft-typography>
|
|
60
|
+
</div>
|
|
61
|
+
`;
|
|
62
|
+
}
|
|
63
|
+
onSuggestLinkClick(e, suggest) {
|
|
64
|
+
if (!e.metaKey && !e.ctrlKey) {
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
e.stopPropagation();
|
|
67
|
+
}
|
|
68
|
+
this.onSuggestSelected(suggest.value);
|
|
69
|
+
}
|
|
41
70
|
onSuggestKeyDown(e) {
|
|
42
71
|
var _a, _b, _c, _d, _e, _f;
|
|
43
72
|
switch (e.key) {
|
|
@@ -53,13 +82,14 @@ let FtSearchInputSuggestion = class FtSearchInputSuggestion extends FtSearchComp
|
|
|
53
82
|
break;
|
|
54
83
|
}
|
|
55
84
|
}
|
|
56
|
-
onSuggestKeyUp(e
|
|
85
|
+
onSuggestKeyUp(e) {
|
|
57
86
|
if (e.key === "Enter" || e.key === " ") {
|
|
58
|
-
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
e.stopPropagation();
|
|
89
|
+
e.target.click();
|
|
59
90
|
}
|
|
60
91
|
}
|
|
61
|
-
onSuggestSelected(
|
|
62
|
-
e.preventDefault();
|
|
92
|
+
onSuggestSelected(suggest) {
|
|
63
93
|
this.dispatchEvent(new SuggestionSelectedEvent(suggest));
|
|
64
94
|
}
|
|
65
95
|
getIcon(suggest) {
|
|
@@ -104,9 +134,15 @@ FtSearchInputSuggestion.styles = [
|
|
|
104
134
|
wordWrap,
|
|
105
135
|
suggestionStyles,
|
|
106
136
|
];
|
|
137
|
+
__decorate([
|
|
138
|
+
redux()
|
|
139
|
+
], FtSearchInputSuggestion.prototype, "request", void 0);
|
|
107
140
|
__decorate([
|
|
108
141
|
redux()
|
|
109
142
|
], FtSearchInputSuggestion.prototype, "suggestResults", void 0);
|
|
143
|
+
__decorate([
|
|
144
|
+
property()
|
|
145
|
+
], FtSearchInputSuggestion.prototype, "launchSearchPath", void 0);
|
|
110
146
|
FtSearchInputSuggestion = __decorate([
|
|
111
147
|
customElement("ft-search-input-suggestion")
|
|
112
148
|
], FtSearchInputSuggestion);
|
|
@@ -10,8 +10,11 @@ export declare class FtSearchInput extends FtSearchInput_base implements FtSearc
|
|
|
10
10
|
private liveQuery;
|
|
11
11
|
private suggestResults?;
|
|
12
12
|
private forceCloseSuggestion;
|
|
13
|
+
launchSearchPath?: string;
|
|
14
|
+
useCustomSearchPath: boolean;
|
|
13
15
|
private input;
|
|
14
16
|
private suggestion;
|
|
17
|
+
private launchSearchButton;
|
|
15
18
|
protected render(): import("lit").TemplateResult<1>;
|
|
16
19
|
private onSearchBarKeyDown;
|
|
17
20
|
private onSearchBarKeyUp;
|
package/build/ft-search-input.js
CHANGED
|
@@ -10,16 +10,18 @@ import { styles } from "./ft-search-input.styles";
|
|
|
10
10
|
import { FtSearchComponent } from "@fluid-topics/ft-search-context/build/registration";
|
|
11
11
|
import { withI18n } from "@fluid-topics/ft-i18n";
|
|
12
12
|
import { searchInputContext } from "./SearchInputMessages";
|
|
13
|
-
import { query, state } from "lit/decorators.js";
|
|
13
|
+
import { property, query, state } from "lit/decorators.js";
|
|
14
14
|
import { classMap } from "lit/directives/class-map.js";
|
|
15
15
|
import { FtSearchInputSuggestion } from "./ft-search-input-suggestion";
|
|
16
16
|
import { FtButton } from "@fluid-topics/ft-button";
|
|
17
17
|
import { FtTypographyBody2 } from "@fluid-topics/ft-typography";
|
|
18
|
+
import { SearchPlaceConverterProvider } from "@fluid-topics/ft-app-context";
|
|
18
19
|
class FtSearchInput extends withI18n(FtSearchComponent) {
|
|
19
20
|
constructor() {
|
|
20
21
|
super();
|
|
21
22
|
this.liveQuery = "";
|
|
22
23
|
this.forceCloseSuggestion = false;
|
|
24
|
+
this.useCustomSearchPath = false;
|
|
23
25
|
this.addI18nContext(searchInputContext);
|
|
24
26
|
}
|
|
25
27
|
render() {
|
|
@@ -29,6 +31,9 @@ class FtSearchInput extends withI18n(FtSearchComponent) {
|
|
|
29
31
|
"ft-search-input--with-suggestions": (_b = (_a = this.suggestResults) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0 > 0,
|
|
30
32
|
"ft-search-input--with-suggestions-closed": this.forceCloseSuggestion,
|
|
31
33
|
};
|
|
34
|
+
const liveRequest = { ...this.request, query: this.liveQuery };
|
|
35
|
+
const searchPage = this.useCustomSearchPath ? this.launchSearchPath : undefined;
|
|
36
|
+
const launchSearchUrl = SearchPlaceConverterProvider.get().serializeToCurrentPageIfPossible(liveRequest, searchPage);
|
|
32
37
|
return html `
|
|
33
38
|
<div class="${classMap(classes)}" @focusout=${() => this.forceCloseSuggestion = false} role="search">
|
|
34
39
|
<div class="ft-search-input--input-container" part="input-container" tabindex="-1">
|
|
@@ -43,6 +48,8 @@ class FtSearchInput extends withI18n(FtSearchComponent) {
|
|
|
43
48
|
@keyup=${(e) => this.onSearchBarKeyUp(e)}>
|
|
44
49
|
</div>
|
|
45
50
|
<ft-search-input-suggestion exportpartsPrefix="suggestion"
|
|
51
|
+
.request=${this.request}
|
|
52
|
+
.launchSearchPath=${searchPage}
|
|
46
53
|
@suggestion-selected=${this.onSuggestionSelected}
|
|
47
54
|
></ft-search-input-suggestion>
|
|
48
55
|
</div>
|
|
@@ -55,7 +62,8 @@ class FtSearchInput extends withI18n(FtSearchComponent) {
|
|
|
55
62
|
round dense
|
|
56
63
|
label="${searchInputContext.messages.clearButton()}"
|
|
57
64
|
@click=${() => {
|
|
58
|
-
|
|
65
|
+
var _a;
|
|
66
|
+
(_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.setLiveQuery("");
|
|
59
67
|
this.input.focus();
|
|
60
68
|
}}
|
|
61
69
|
></ft-button>
|
|
@@ -66,6 +74,7 @@ class FtSearchInput extends withI18n(FtSearchComponent) {
|
|
|
66
74
|
icon="search"
|
|
67
75
|
round dense
|
|
68
76
|
label="${searchInputContext.messages.searchButton()}"
|
|
77
|
+
href="${this.useCustomSearchPath ? launchSearchUrl : ""}"
|
|
69
78
|
@click=${() => this.launchSearch(this.liveQuery)}
|
|
70
79
|
></ft-button>
|
|
71
80
|
</div>
|
|
@@ -90,7 +99,12 @@ class FtSearchInput extends withI18n(FtSearchComponent) {
|
|
|
90
99
|
e.stopPropagation();
|
|
91
100
|
break;
|
|
92
101
|
case "Enter":
|
|
93
|
-
|
|
102
|
+
if (this.useCustomSearchPath) {
|
|
103
|
+
this.launchSearchButton.click();
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
this.launchSearch(this.liveQuery);
|
|
107
|
+
}
|
|
94
108
|
break;
|
|
95
109
|
default:
|
|
96
110
|
break;
|
|
@@ -103,11 +117,13 @@ class FtSearchInput extends withI18n(FtSearchComponent) {
|
|
|
103
117
|
}
|
|
104
118
|
launchSearch(query) {
|
|
105
119
|
var _a;
|
|
106
|
-
(_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.setQuery(query);
|
|
107
120
|
this.forceCloseSuggestion = true;
|
|
108
121
|
this.dispatchEvent(new CustomEvent("change", { detail: query }));
|
|
122
|
+
(_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.setQuery(query);
|
|
109
123
|
}
|
|
110
124
|
onSuggestionSelected(e) {
|
|
125
|
+
var _a;
|
|
126
|
+
(_a = this.input) === null || _a === void 0 ? void 0 : _a.focus();
|
|
111
127
|
this.launchSearch(e.detail);
|
|
112
128
|
}
|
|
113
129
|
}
|
|
@@ -132,10 +148,19 @@ __decorate([
|
|
|
132
148
|
__decorate([
|
|
133
149
|
state()
|
|
134
150
|
], FtSearchInput.prototype, "forceCloseSuggestion", void 0);
|
|
151
|
+
__decorate([
|
|
152
|
+
property()
|
|
153
|
+
], FtSearchInput.prototype, "launchSearchPath", void 0);
|
|
154
|
+
__decorate([
|
|
155
|
+
property({ type: Boolean })
|
|
156
|
+
], FtSearchInput.prototype, "useCustomSearchPath", void 0);
|
|
135
157
|
__decorate([
|
|
136
158
|
query(".ft-search-input--input")
|
|
137
159
|
], FtSearchInput.prototype, "input", void 0);
|
|
138
160
|
__decorate([
|
|
139
161
|
query("ft-search-input-suggestion")
|
|
140
162
|
], FtSearchInput.prototype, "suggestion", void 0);
|
|
163
|
+
__decorate([
|
|
164
|
+
query(`[part="launch-search-in-input"]`)
|
|
165
|
+
], FtSearchInput.prototype, "launchSearchButton", void 0);
|
|
141
166
|
export { FtSearchInput };
|