@fluid-topics/ft-search-result-metadata 0.3.62

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/README.md ADDED
@@ -0,0 +1,21 @@
1
+ Search result metadata for integrated search component
2
+
3
+ ## Install
4
+
5
+ ```shell
6
+ npm install @fluid-topics/ft-search-result-metadata
7
+ yarn add @fluid-topics/ft-search-result-metadata
8
+ ```
9
+
10
+ ## Usage
11
+
12
+ ```typescript
13
+ import { html } from "lit"
14
+ import "@fluid-topics/ft-search-result-metadata"
15
+
16
+ function render() {
17
+ return html`<ft-search-result-context>
18
+ <ft-search-result-metadata key="author"></ft-search-result-metadata>
19
+ </ft-search-result-context>`
20
+ }
21
+ ```
@@ -0,0 +1,7 @@
1
+ import { I18nMessageContext, I18nMessages } from "@fluid-topics/ft-i18n";
2
+ export interface SearchResultMetadataMessages extends I18nMessages {
3
+ noKeySelected(): string;
4
+ noValuePresent(key: string): string;
5
+ }
6
+ export declare const searchResultMetadataContext: I18nMessageContext<SearchResultMetadataMessages>;
7
+ //# sourceMappingURL=SearchResultMetadataMessages.d.ts.map
@@ -0,0 +1,3 @@
1
+ import { I18nMessageContext } from "@fluid-topics/ft-i18n";
2
+ export const searchResultMetadataContext = I18nMessageContext.build("designedSearchResultMetadata");
3
+ //# sourceMappingURL=SearchResultMetadataMessages.js.map
@@ -0,0 +1,3 @@
1
+ export declare const FtSearchResultMetadataCssVariables: {};
2
+ export declare const styles: import("lit").CSSResult;
3
+ //# sourceMappingURL=ft-search-result-metadata.css.d.ts.map
@@ -0,0 +1,6 @@
1
+ import { css } from "lit";
2
+ export const FtSearchResultMetadataCssVariables = {};
3
+ // language=CSS
4
+ export const styles = css `
5
+ `;
6
+ //# sourceMappingURL=ft-search-result-metadata.css.js.map
@@ -0,0 +1,27 @@
1
+ import { PropertyValues } from "lit";
2
+ import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
3
+ import { FtSearchResultMetadataProperties } from "./ft-search-result-metadata.properties";
4
+ import { FtSearchResultComponent } from "@fluid-topics/ft-search-result-context/build/registration";
5
+ declare const FtSearchResultMetadata_base: typeof FtSearchResultComponent & (new (...args: any[]) => import("@fluid-topics/ft-i18n").FtLitElementWithI18nInterface);
6
+ export declare class FtSearchResultMetadata extends FtSearchResultMetadata_base implements FtSearchResultMetadataProperties {
7
+ static elementDefinitions: ElementDefinitionsMap;
8
+ static styles: import("lit").CSSResult;
9
+ key?: string;
10
+ useChip?: boolean;
11
+ /**
12
+ * @deprecated Use CSS
13
+ */
14
+ maxLength?: number;
15
+ private editorMode;
16
+ private metadata?;
17
+ constructor();
18
+ protected render(): import("lit-html").TemplateResult<1>;
19
+ private renderContent;
20
+ private getEllipsis;
21
+ protected updated(props: PropertyValues): void;
22
+ private selectMetadata;
23
+ private get valueText();
24
+ private get tooltipText();
25
+ }
26
+ export {};
27
+ //# sourceMappingURL=ft-search-result-metadata.d.ts.map
@@ -0,0 +1,107 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { html } from "lit";
8
+ import { property, state } from "lit/decorators.js";
9
+ import { redux } from "@fluid-topics/ft-wc-utils";
10
+ import { styles } from "./ft-search-result-metadata.css";
11
+ import { FtSearchResultComponent } from "@fluid-topics/ft-search-result-context/build/registration";
12
+ import { ftAppInfoStore } from "@fluid-topics/ft-app-context";
13
+ import { withI18n } from "@fluid-topics/ft-i18n";
14
+ import { searchResultMetadataContext } from "./SearchResultMetadataMessages";
15
+ import { FtTooltip } from "@fluid-topics/ft-tooltip";
16
+ import { FtChip } from "@fluid-topics/ft-chip";
17
+ export class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
18
+ constructor() {
19
+ super();
20
+ this.useChip = false;
21
+ this.editorMode = false;
22
+ this.addStore(ftAppInfoStore);
23
+ this.addI18nContext(searchResultMetadataContext);
24
+ }
25
+ render() {
26
+ if (this.useChip) {
27
+ return html `
28
+ <ft-tooltip text="${this.tooltipText}">
29
+ <ft-chip>${this.renderContent()}</ft-chip>
30
+ </ft-tooltip>
31
+ `;
32
+ }
33
+ else {
34
+ return html `${this.renderContent()}`;
35
+ }
36
+ }
37
+ renderContent() {
38
+ if (this.metadata) {
39
+ return html `${this.getEllipsis(this.valueText)}`;
40
+ }
41
+ if (this.editorMode) {
42
+ if (this.key) {
43
+ return html `${searchResultMetadataContext.messages.noValuePresent(this.key)}`;
44
+ }
45
+ else {
46
+ return html `${searchResultMetadataContext.messages.noKeySelected()}`;
47
+ }
48
+ }
49
+ return html `
50
+ <style>
51
+ :host {
52
+ display: none !important;
53
+ }
54
+ </style>
55
+ `;
56
+ }
57
+ getEllipsis(text) {
58
+ let cutText = this.maxLength ? text.substring(0, this.maxLength) : text;
59
+ return cutText + (cutText.length < text.length ? "..." : "");
60
+ }
61
+ updated(props) {
62
+ super.updated(props);
63
+ if (props.has("result") && this.result) {
64
+ this.metadata = this.selectMetadata(this.result);
65
+ }
66
+ }
67
+ selectMetadata(result) {
68
+ switch (result.type) {
69
+ case "MAP":
70
+ return result.map.metadata.find(m => m.key == this.key);
71
+ case "DOCUMENT":
72
+ return result.document.metadata.find(m => m.key == this.key);
73
+ case "TOPIC":
74
+ return result.topic.metadata.find(m => m.key == this.key);
75
+ }
76
+ return undefined;
77
+ }
78
+ get valueText() {
79
+ var _a, _b;
80
+ return (_b = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.values.join(", ")) !== null && _b !== void 0 ? _b : "";
81
+ }
82
+ get tooltipText() {
83
+ var _a, _b;
84
+ return this.metadata ? `${(_b = (_a = this.metadata) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : this.metadata.key}: ${this.valueText}` : "";
85
+ }
86
+ }
87
+ FtSearchResultMetadata.elementDefinitions = {
88
+ "ft-tooltip": FtTooltip,
89
+ "ft-chip": FtChip,
90
+ };
91
+ FtSearchResultMetadata.styles = styles;
92
+ __decorate([
93
+ property()
94
+ ], FtSearchResultMetadata.prototype, "key", void 0);
95
+ __decorate([
96
+ property({ type: Boolean })
97
+ ], FtSearchResultMetadata.prototype, "useChip", void 0);
98
+ __decorate([
99
+ property({ type: Number, attribute: "max-length" })
100
+ ], FtSearchResultMetadata.prototype, "maxLength", void 0);
101
+ __decorate([
102
+ redux({ store: ftAppInfoStore.name })
103
+ ], FtSearchResultMetadata.prototype, "editorMode", void 0);
104
+ __decorate([
105
+ state()
106
+ ], FtSearchResultMetadata.prototype, "metadata", void 0);
107
+ //# sourceMappingURL=ft-search-result-metadata.js.map