@fluid-topics/ft-viewer 2.1.20 → 2.1.22

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 (39) hide show
  1. package/build/common/model/FtViewerReduxStore.js +4 -0
  2. package/build/common/model/ft-viewer.models.d.ts +6 -1
  3. package/build/common/utils/MetadataValueLocalizer.d.ts +8 -0
  4. package/build/common/utils/MetadataValueLocalizer.js +20 -0
  5. package/build/definitions.d.ts +3 -1
  6. package/build/definitions.js +3 -1
  7. package/build/ft-viewer.light.js +1795 -217
  8. package/build/ft-viewer.min.js +1753 -182
  9. package/build/index.d.ts +1 -0
  10. package/build/index.js +1 -0
  11. package/build/ud/components/ft-ud-viewer-feedback.d.ts +53 -0
  12. package/build/ud/components/ft-ud-viewer-feedback.js +257 -0
  13. package/build/ud/components/ft-ud-viewer-feedback.styles.d.ts +2 -0
  14. package/build/ud/components/ft-ud-viewer-feedback.styles.js +13 -0
  15. package/build/ud/components/ft-ud-viewer-metadata.d.ts +37 -0
  16. package/build/ud/components/ft-ud-viewer-metadata.js +231 -0
  17. package/build/ud/components/ft-ud-viewer-metadata.properties.d.ts +10 -0
  18. package/build/ud/components/ft-ud-viewer-metadata.properties.js +1 -0
  19. package/build/ud/components/ft-ud-viewer-metadata.styles.d.ts +2 -0
  20. package/build/ud/components/ft-ud-viewer-metadata.styles.js +24 -0
  21. package/build/ud/components/ft-viewer-feedback.d.ts +4 -0
  22. package/build/ud/components/ft-viewer-feedback.js +6 -0
  23. package/build/ud/components/registration.d.ts +1 -0
  24. package/build/ud/components/registration.js +11 -0
  25. package/build/ud/ft-ud-viewer-context.d.ts +1 -0
  26. package/build/ud/ft-ud-viewer-context.js +17 -1
  27. package/build/ud/ft-ud-viewer.messages.d.ts +1 -0
  28. package/build/ud/ft-ud-viewer.messages.js +1 -0
  29. package/build/ud/index.d.ts +4 -0
  30. package/build/ud/index.js +4 -0
  31. package/build/ud/model/FtUdViewerService.d.ts +10 -3
  32. package/build/ud/model/FtUdViewerService.js +48 -2
  33. package/build/ud/model/FtUdViewerStateManager.d.ts +16 -1
  34. package/build/ud/model/FtUdViewerStateManager.js +79 -5
  35. package/build/ud/model/ft-ud-viewer.models.d.ts +11 -1
  36. package/build/ud/model/ft-ud-viewer.models.js +7 -0
  37. package/build/utils/events.d.ts +14 -0
  38. package/build/utils/events.js +17 -0
  39. package/package.json +10 -8
package/build/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./common";
2
2
  export * from "./asset";
3
3
  export * from "./ud";
4
+ export * from "./utils/events";
package/build/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./common";
2
2
  export * from "./asset";
3
3
  export * from "./ud";
4
+ export * from "./utils/events";
@@ -0,0 +1,53 @@
1
+ import { PropertyValues } from "lit";
2
+ import { Debouncer, ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
3
+ import { FtPublicationRatingSummary, FtRatingType, FtReaderFeedbackConfiguration, FtSession, FtUnstructuredDocument } from "@fluid-topics/public-api";
4
+ import { FtIconVariants } from "@fluid-topics/ft-icon";
5
+ import { GuestLocalStorage } from "@fluid-topics/ft-app-context";
6
+ import { FeedbackI18nProperties } from "@fluid-topics/ft-reader-feedback/build/ft-base-feedback";
7
+ import { FtViewerFeedback } from "./ft-viewer-feedback";
8
+ import { FtViewerComponent } from "../../common/FtViewerComponent";
9
+ import { SendFeedbackEvent } from "@fluid-topics/ft-reader-feedback/build/utils/events";
10
+ import { FtFeedbackProperties } from "@fluid-topics/ft-reader-feedback/build/ft-base-feedback.properties";
11
+ import { FeedbackMailLinkBuilder } from "@fluid-topics/ft-reader-feedback/build/utils/mail";
12
+ declare const FtUdViewerFeedback_base: import("./registration").FtUdViewerComponentType<typeof FtViewerComponent & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-i18n").FtLitElementWithI18nInterface>>;
13
+ export declare class FtUdViewerFeedback extends FtUdViewerFeedback_base implements FtFeedbackProperties {
14
+ private readonly guestStorage;
15
+ static styles: import("lit").CSSResult;
16
+ static elementDefinitions: ElementDefinitionsMap;
17
+ private static storedRatingIfAuthenticated;
18
+ session?: FtSession;
19
+ document?: FtUnstructuredDocument;
20
+ editorMode: boolean;
21
+ configuration?: FtReaderFeedbackConfiguration;
22
+ ratingSummary?: FtPublicationRatingSummary;
23
+ hideTitle: boolean;
24
+ iconVariant: FtIconVariants;
25
+ emptyStarIcon?: string;
26
+ filledStarIcon?: string;
27
+ emptyLikeIcon?: string;
28
+ filledLikeIcon?: string;
29
+ emptyDislikeIcon?: string;
30
+ filledDislikeIcon?: string;
31
+ viewerFeedback: FtViewerFeedback;
32
+ feedbackLinkBuilder: FeedbackMailLinkBuilder;
33
+ mailSubject: string;
34
+ private displayName?;
35
+ i18nProperties: FeedbackI18nProperties;
36
+ get canAccessFeedback(): boolean | undefined;
37
+ get canRateThisContent(): boolean | undefined;
38
+ get configuredRatingType(): FtRatingType.NO_RATING | "STARS" | "LIKE" | "DICHOTOMOUS" | "NO_RATING";
39
+ constructor(guestStorage?: GuestLocalStorage<FtPublicationRatingSummary>);
40
+ protected render(): import("lit-html").TemplateResult<1>;
41
+ protected willUpdate(props: PropertyValues): void;
42
+ connectedCallback(): void;
43
+ disconnectedCallback(): void;
44
+ private readonly loadGuestRating;
45
+ private readonly guestRatingKey;
46
+ protected sendRatingDebouncer: Debouncer;
47
+ protected rate(ratingEvent: CustomEvent<number | undefined>): void;
48
+ protected sendRating(value: number | undefined): Promise<void>;
49
+ protected sendFeedback(ratingEvent: SendFeedbackEvent): Promise<void>;
50
+ protected onMailerFeedbackSent(): void;
51
+ protected openMoreOptions(): void;
52
+ }
53
+ export {};
@@ -0,0 +1,257 @@
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, query, } from "lit/decorators.js";
9
+ import { Debouncer, FtNotificationEvent, redux, } from "@fluid-topics/ft-wc-utils";
10
+ import { FtRatingType, } from "@fluid-topics/public-api";
11
+ import { FtIconVariants } from "@fluid-topics/ft-icon";
12
+ import { ftAppInfoStore, GuestLocalStorage, } from "@fluid-topics/ft-app-context";
13
+ import { i18n, withI18n, } from "@fluid-topics/ft-i18n";
14
+ import { toFtUdViewerComponent } from "./registration";
15
+ import { OpenUdFeedbackDrawerEvent, SendMailerUdFeedbackEvent, } from "../../utils/events";
16
+ import { FtViewerFeatures } from "../model/ft-ud-viewer.models";
17
+ import { generateFeedbackStyles } from "@fluid-topics/ft-reader-feedback/build/ft-base-feedback.styles";
18
+ import { FtViewerFeedbackCssVariables } from "./ft-ud-viewer-feedback.styles";
19
+ import { FtViewerFeedback } from "./ft-viewer-feedback";
20
+ import { FtViewerComponent } from "../../common/FtViewerComponent";
21
+ import { defaultDesignerMessages, designer, } from "@fluid-topics/ft-reader-feedback/build/utils/InDesignerFeedbackComponentMessages";
22
+ import { feedback } from "@fluid-topics/ft-reader-feedback/build/utils/IntegratedFeedbackComponentMessages";
23
+ import { FeedbackMailLinkBuilder } from "@fluid-topics/ft-reader-feedback/build/utils/mail";
24
+ import { server } from "@fluid-topics/ft-reader-feedback/build/utils/ServerMessages";
25
+ export class FtUdViewerFeedback extends toFtUdViewerComponent(withI18n(FtViewerComponent)) {
26
+ get canAccessFeedback() {
27
+ var _a;
28
+ return (_a = this.service) === null || _a === void 0 ? void 0 : _a.isFeatureAccessible(FtViewerFeatures.FEEDBACK, { session: this.session });
29
+ }
30
+ get canRateThisContent() {
31
+ var _a;
32
+ const canAccessRating = (_a = this.service) === null || _a === void 0 ? void 0 : _a.isFeatureAccessible(FtViewerFeatures.RATING, { session: this.session });
33
+ return canAccessRating && this.configuredRatingType != FtRatingType.NO_RATING;
34
+ }
35
+ get configuredRatingType() {
36
+ var _a, _b;
37
+ return (_b = (_a = this.ratingSummary) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : FtRatingType.NO_RATING;
38
+ }
39
+ constructor(guestStorage = new GuestLocalStorage()) {
40
+ super();
41
+ this.guestStorage = guestStorage;
42
+ this.editorMode = false;
43
+ this.hideTitle = false;
44
+ this.iconVariant = FtIconVariants.fluid_topics;
45
+ this.emptyStarIcon = "STAR";
46
+ this.filledStarIcon = "STAR_PLAIN";
47
+ this.emptyLikeIcon = "THUMBS_UP";
48
+ this.filledLikeIcon = "THUMBS_UP_PLAIN";
49
+ this.emptyDislikeIcon = "THUMBS_DOWN";
50
+ this.filledDislikeIcon = "THUMBS_DOWN_PLAIN";
51
+ this.feedbackLinkBuilder = new FeedbackMailLinkBuilder();
52
+ this.i18nProperties = {
53
+ feedbackMainTitle: feedback.properties.viewerFeedbackMainTitle(),
54
+ ratingSectionTitle: feedback.properties.viewerRatingSectionTitle(),
55
+ dichotomousRatingSectionTitle: feedback.properties.viewerDichotomousRatingSectionTitle(),
56
+ feedbackSectionTitle: feedback.properties.viewerFeedbackSectionTitle(),
57
+ };
58
+ this.loadGuestRating = () => {
59
+ const guestRating = this.guestStorage.get(this.guestRatingKey());
60
+ if (guestRating) {
61
+ this.ratingSummary = guestRating;
62
+ }
63
+ };
64
+ this.guestRatingKey = () => {
65
+ var _a;
66
+ return "ft-viewer-document-feedback-guest-rating-" + ((_a = this.document) === null || _a === void 0 ? void 0 : _a.id);
67
+ };
68
+ this.sendRatingDebouncer = new Debouncer(500);
69
+ this.addStore(ftAppInfoStore);
70
+ }
71
+ render() {
72
+ return html `
73
+ <ft-viewer-feedback
74
+ ?hideTitle=${this.hideTitle}
75
+ iconVariant="${this.iconVariant}"
76
+ emptyStarIcon="${this.emptyStarIcon}"
77
+ filledStarIcon="${this.filledStarIcon}"
78
+ emptyLikeIcon="${this.emptyLikeIcon}"
79
+ filledLikeIcon="${this.filledLikeIcon}"
80
+ emptyDislikeIcon="${this.emptyDislikeIcon}"
81
+ filledDislikeIcon="${this.filledDislikeIcon}"
82
+ ?canAccessFeedback=${this.canAccessFeedback}
83
+ ?canRateThisContent=${this.canRateThisContent}
84
+ .i18nProperties=${this.i18nProperties}
85
+ .ratingSummary=${this.ratingSummary}
86
+ .configuration=${this.configuration}
87
+ .feedbackMailLinkBuilder=${(feedbackMessage) => this.feedbackLinkBuilder.build(feedbackMessage)}
88
+ @rate=${this.rate}
89
+ @send-feedback=${this.sendFeedback}
90
+ @mailer-feedback=${this.onMailerFeedbackSent}
91
+ @open-more-options=${this.openMoreOptions}
92
+ ></ft-viewer-feedback>
93
+ `;
94
+ }
95
+ willUpdate(props) {
96
+ var _a, _b, _c;
97
+ super.willUpdate(props);
98
+ if (props.has("editorMode") && this.editorMode) {
99
+ this.addI18nContext(designer, defaultDesignerMessages);
100
+ }
101
+ if (["document", "configuration", "user", "mailSubject"].some((p) => props.has(p)) && this.document && this.configuration) {
102
+ this.feedbackLinkBuilder.update(this.mailSubject, (_a = this.document.prettyUrl) !== null && _a !== void 0 ? _a : "", this.document.metadata, this.configuration, ((_c = (_b = this.session) === null || _b === void 0 ? void 0 : _b.profile) === null || _c === void 0 ? void 0 : _c.userId) != null);
103
+ }
104
+ if (["session", "document"].some((p) => props.has(p)) && this.session && this.document) {
105
+ this.loadGuestRating();
106
+ }
107
+ }
108
+ connectedCallback() {
109
+ super.connectedCallback();
110
+ this.guestStorage.addStoreListener(this.guestRatingKey, this.loadGuestRating);
111
+ }
112
+ disconnectedCallback() {
113
+ super.disconnectedCallback();
114
+ this.guestStorage.clearStoreListeners();
115
+ }
116
+ rate(ratingEvent) {
117
+ if (this.ratingSummary) {
118
+ this.ratingSummary = {
119
+ ...this.ratingSummary,
120
+ rating: ratingEvent.detail == null ? undefined : {
121
+ type: this.ratingSummary.type,
122
+ value: ratingEvent.detail,
123
+ date: new Date(),
124
+ },
125
+ };
126
+ this.guestStorage.store(this.guestRatingKey(), this.ratingSummary);
127
+ this.sendRatingDebouncer.run(() => this.sendRating(ratingEvent.detail));
128
+ }
129
+ }
130
+ async sendRating(value) {
131
+ var _a, _b, _c;
132
+ if (!this.editorMode && this.ratingSummary) {
133
+ try {
134
+ if (value == null) {
135
+ await ((_a = this.service) === null || _a === void 0 ? void 0 : _a.unrateDocument(this.document.id));
136
+ }
137
+ else {
138
+ await ((_b = this.service) === null || _b === void 0 ? void 0 : _b.rateDocument(this.document.id, (_c = this.ratingSummary) === null || _c === void 0 ? void 0 : _c.type, value));
139
+ }
140
+ }
141
+ catch {
142
+ this.dispatchEvent(new FtNotificationEvent({
143
+ type: "error",
144
+ message: feedback.messages.ratingFailure(),
145
+ }));
146
+ }
147
+ }
148
+ }
149
+ async sendFeedback(ratingEvent) {
150
+ var _a;
151
+ try {
152
+ if (!this.editorMode) {
153
+ await ((_a = this.service) === null || _a === void 0 ? void 0 : _a.sendDocumentFeedback(this.document.id, ratingEvent.detail.message, ratingEvent.detail.from));
154
+ this.dispatchEvent(new FtNotificationEvent({
155
+ type: "info",
156
+ message: feedback.messages.feedbackSuccess(),
157
+ }));
158
+ }
159
+ else {
160
+ this.dispatchEvent(new FtNotificationEvent({
161
+ type: "info",
162
+ message: designer.messages.feedbackAndRatingDisabledInEditor(),
163
+ }));
164
+ }
165
+ this.viewerFeedback.clearFeedbackInput();
166
+ }
167
+ catch {
168
+ this.dispatchEvent(new FtNotificationEvent({
169
+ type: "error",
170
+ message: feedback.messages.feedbackFailure(),
171
+ }));
172
+ }
173
+ }
174
+ onMailerFeedbackSent() {
175
+ this.dispatchEvent(new SendMailerUdFeedbackEvent());
176
+ }
177
+ openMoreOptions() {
178
+ var _a, _b;
179
+ this.dispatchEvent(new OpenUdFeedbackDrawerEvent({
180
+ documentId: this.document.id,
181
+ documentTitle: this.displayName || "",
182
+ ratingType: ((_a = this.ratingSummary) === null || _a === void 0 ? void 0 : _a.type) || FtRatingType.NO_RATING,
183
+ ratingValue: (_b = this.ratingSummary) === null || _b === void 0 ? void 0 : _b.rating,
184
+ }));
185
+ }
186
+ }
187
+ FtUdViewerFeedback.styles = generateFeedbackStyles(FtViewerFeedbackCssVariables);
188
+ FtUdViewerFeedback.elementDefinitions = {
189
+ "ft-viewer-feedback": FtViewerFeedback,
190
+ };
191
+ FtUdViewerFeedback.storedRatingIfAuthenticated = (state, self) => {
192
+ var _a, _b;
193
+ if ((_a = self.session) === null || _a === void 0 ? void 0 : _a.sessionAuthenticated) {
194
+ return state.documentRating;
195
+ }
196
+ return (_b = self.ratingSummary) !== null && _b !== void 0 ? _b : state.documentRating;
197
+ };
198
+ __decorate([
199
+ redux({ store: ftAppInfoStore.name })
200
+ ], FtUdViewerFeedback.prototype, "session", void 0);
201
+ __decorate([
202
+ redux({ store: "viewer" })
203
+ ], FtUdViewerFeedback.prototype, "document", void 0);
204
+ __decorate([
205
+ redux({ store: ftAppInfoStore.name })
206
+ ], FtUdViewerFeedback.prototype, "editorMode", void 0);
207
+ __decorate([
208
+ redux({
209
+ store: "viewer",
210
+ selector: (state) => { var _a; return (_a = state.configuration) === null || _a === void 0 ? void 0 : _a.feedback; },
211
+ })
212
+ ], FtUdViewerFeedback.prototype, "configuration", void 0);
213
+ __decorate([
214
+ redux({
215
+ store: "viewer",
216
+ selector: FtUdViewerFeedback.storedRatingIfAuthenticated,
217
+ })
218
+ ], FtUdViewerFeedback.prototype, "ratingSummary", void 0);
219
+ __decorate([
220
+ property({ type: Boolean })
221
+ ], FtUdViewerFeedback.prototype, "hideTitle", void 0);
222
+ __decorate([
223
+ property()
224
+ ], FtUdViewerFeedback.prototype, "iconVariant", void 0);
225
+ __decorate([
226
+ property()
227
+ ], FtUdViewerFeedback.prototype, "emptyStarIcon", void 0);
228
+ __decorate([
229
+ property()
230
+ ], FtUdViewerFeedback.prototype, "filledStarIcon", void 0);
231
+ __decorate([
232
+ property()
233
+ ], FtUdViewerFeedback.prototype, "emptyLikeIcon", void 0);
234
+ __decorate([
235
+ property()
236
+ ], FtUdViewerFeedback.prototype, "filledLikeIcon", void 0);
237
+ __decorate([
238
+ property()
239
+ ], FtUdViewerFeedback.prototype, "emptyDislikeIcon", void 0);
240
+ __decorate([
241
+ property()
242
+ ], FtUdViewerFeedback.prototype, "filledDislikeIcon", void 0);
243
+ __decorate([
244
+ query("ft-viewer-feedback")
245
+ ], FtUdViewerFeedback.prototype, "viewerFeedback", void 0);
246
+ __decorate([
247
+ i18n(server.properties["mail.file_feedback.subject"]((self) => {
248
+ var _a, _b;
249
+ return [
250
+ ((_a = self.document) === null || _a === void 0 ? void 0 : _a.title) || "Document",
251
+ ((_b = self.document) === null || _b === void 0 ? void 0 : _b.filename) || "Filename",
252
+ ];
253
+ }))
254
+ ], FtUdViewerFeedback.prototype, "mailSubject", void 0);
255
+ __decorate([
256
+ redux({ store: "viewer", selector: ({ descriptor }) => descriptor === null || descriptor === void 0 ? void 0 : descriptor.displayName })
257
+ ], FtUdViewerFeedback.prototype, "displayName", void 0);
@@ -0,0 +1,2 @@
1
+ import { FtBaseFeedbackCssVariables } from "@fluid-topics/ft-reader-feedback/build/ft-base-feedback.styles";
2
+ export declare const FtViewerFeedbackCssVariables: FtBaseFeedbackCssVariables;
@@ -0,0 +1,13 @@
1
+ import { designSystemVariables, FtCssVariableFactory, } from "@fluid-topics/ft-wc-utils";
2
+ import { FtTypographyTitleCssVariables, FtTypographyTitleDenseCssVariables, } from "@fluid-topics/ft-typography/build/ft-typography.styles";
3
+ export const FtViewerFeedbackCssVariables = {
4
+ feedbackInputMinWidth: FtCssVariableFactory.create("--ft-viewer-feedback-input-min-width", "", "SIZE", "300px"),
5
+ ratedDateColor: FtCssVariableFactory.external(designSystemVariables.colorOnSurfaceMedium, "Design system"),
6
+ sendFeedbackColor: FtCssVariableFactory.extend("--ft-viewer-feedback-send-feedback-color", "", designSystemVariables.colorOnPrimary),
7
+ sendFeedbackBackgroundColor: FtCssVariableFactory.extend("--ft-viewer-feedback-send-feedback-background-color", "", designSystemVariables.colorPrimary),
8
+ filledRatingColor: FtCssVariableFactory.extend("--ft-viewer-feedback-filled-rating-color", "", designSystemVariables.colorPrimary),
9
+ emptyRatingColor: FtCssVariableFactory.extend("--ft-viewer-feedback-empty-rating-color", "", designSystemVariables.colorOnSurfaceMedium),
10
+ mainTitleFontSize: FtCssVariableFactory.external(FtTypographyTitleCssVariables.fontSize, "Typography"),
11
+ sectionTitleFontSize: FtCssVariableFactory.external(FtTypographyTitleDenseCssVariables.fontSize, "Typography"),
12
+ starsBackgroundColor: FtCssVariableFactory.create("--ft-viewer-feedback-stars-background-color", "", "COLOR", designSystemVariables.colorSurface),
13
+ };
@@ -0,0 +1,37 @@
1
+ import { FtUdViewerComponent } from "./FtUdViewerComponent";
2
+ import { FtUdViewerMetadataProperties } from "./ft-ud-viewer-metadata.properties";
3
+ import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
4
+ import { FtUnstructuredDocument } from "@fluid-topics/public-api";
5
+ import { PropertyValues } from "lit";
6
+ import { FtUdViewerStateManager } from "./registration";
7
+ declare const FtUdViewerMetadata_base: typeof FtUdViewerComponent & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-i18n").FtLitElementWithI18nInterface> & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-app-context").FtLitElementWithDateFormatInterface>;
8
+ export declare class FtUdViewerMetadata extends FtUdViewerMetadata_base implements FtUdViewerMetadataProperties {
9
+ static elementDefinitions: ElementDefinitionsMap;
10
+ static styles: import("lit").CSSResult;
11
+ key?: string;
12
+ multiLine: boolean;
13
+ useForSwitchingToRelatives: boolean;
14
+ displayLabel: boolean;
15
+ hierarchicalValueTruncatingLevel?: number;
16
+ forceTooltip: boolean;
17
+ editorMode: boolean;
18
+ translateValues: boolean;
19
+ private metadata?;
20
+ private flatMetadata?;
21
+ document?: FtUnstructuredDocument;
22
+ private relatives;
23
+ private availableContentLocales?;
24
+ private noValueMessage;
25
+ private get metadataValue();
26
+ get metadataLabel(): string | undefined;
27
+ setUdvStateManager(stateManager: FtUdViewerStateManager): void;
28
+ constructor();
29
+ protected willUpdate(props: PropertyValues): void;
30
+ private updateRelatives;
31
+ protected render(): import("lit-html").TemplateResult<1>;
32
+ private hideIfEmpty;
33
+ private renderSwitchToRelatives;
34
+ private renderRelativeItem;
35
+ private renderChip;
36
+ }
37
+ export {};
@@ -0,0 +1,231 @@
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 { ftAppInfoStore, withDateFormat } from "@fluid-topics/ft-app-context";
8
+ import { i18n, withI18n } from "@fluid-topics/ft-i18n";
9
+ import { FtUdViewerComponent } from "./FtUdViewerComponent";
10
+ import { ClusteringHelper, numberProperty, redux, reduxEventListener, reduxReactive, } from "@fluid-topics/ft-wc-utils";
11
+ import { property, state } from "lit/decorators.js";
12
+ import { udViewerContext } from "../ft-ud-viewer.messages";
13
+ import { styles } from "./ft-ud-viewer-metadata.styles";
14
+ import { FtTooltip } from "@fluid-topics/ft-tooltip";
15
+ import { FtChip } from "@fluid-topics/ft-chip";
16
+ import { FtFloatingMenu, FtFloatingMenuItem, FtFloatingMenuLabel, } from "@fluid-topics/ft-floating-menu";
17
+ import { FtRipple } from "@fluid-topics/ft-ripple";
18
+ import { html, nothing } from "lit";
19
+ import { repeat } from "lit/directives/repeat.js";
20
+ import { getResultUrl } from "@fluid-topics/ft-search-result-context/build/utils";
21
+ import { FtUdViewerStoreEvents } from "../model/ft-ud-viewer.models";
22
+ import { MetadataValueLocalizer } from "../../common/utils/MetadataValueLocalizer";
23
+ export class FtUdViewerMetadata extends withDateFormat(withI18n(FtUdViewerComponent)) {
24
+ get metadataValue() {
25
+ if (this.flatMetadata) {
26
+ return this.flatMetadata.displayValue;
27
+ }
28
+ if (this.editorMode) {
29
+ return this.key ? `no value for ${this.key}` : `no metadata selected`;
30
+ }
31
+ return this.noValueMessage;
32
+ }
33
+ get metadataLabel() {
34
+ var _a, _b, _c, _d, _e, _f;
35
+ if (this.metadata) {
36
+ return this.metadata.label;
37
+ }
38
+ return (_f = (_d = (_c = (_b = (_a = this.viewerStateManager) === null || _a === void 0 ? void 0 : _a.clusteringHelper) === null || _b === void 0 ? void 0 : _b.getMetadataDescriptor(this.key)) === null || _c === void 0 ? void 0 : _c.label) !== null && _d !== void 0 ? _d : (_e = this.relatives.find((item) => item.metadata.value)) === null || _e === void 0 ? void 0 : _e.metadata.label) !== null && _f !== void 0 ? _f : this.key;
39
+ }
40
+ setUdvStateManager(stateManager) {
41
+ super.setUdvStateManager(stateManager);
42
+ if (this.key && this.useForSwitchingToRelatives) {
43
+ stateManager.registerMetadataForSwitchToRelatives(this.key);
44
+ }
45
+ }
46
+ constructor() {
47
+ super();
48
+ this.multiLine = false;
49
+ this.useForSwitchingToRelatives = false;
50
+ this.displayLabel = false;
51
+ this.hierarchicalValueTruncatingLevel = 3;
52
+ this.forceTooltip = false;
53
+ this.editorMode = false;
54
+ this.translateValues = false;
55
+ this.relatives = [];
56
+ this.noValueMessage = "No value";
57
+ this.addI18nContext(udViewerContext);
58
+ }
59
+ willUpdate(props) {
60
+ var _a, _b, _c, _d, _e;
61
+ super.willUpdate(props);
62
+ if (props.has("key") && this.useForSwitchingToRelatives) {
63
+ if (props.get("key")) {
64
+ (_a = this.viewerStateManager) === null || _a === void 0 ? void 0 : _a.unregisterMetadataForSwitchToRelatives(props.get("key"));
65
+ }
66
+ if (this.key) {
67
+ (_b = this.viewerStateManager) === null || _b === void 0 ? void 0 : _b.registerMetadataForSwitchToRelatives(this.key);
68
+ }
69
+ }
70
+ if (props.has("useForSwitchingToRelatives") && this.key) {
71
+ if (this.useForSwitchingToRelatives) {
72
+ (_c = this.viewerStateManager) === null || _c === void 0 ? void 0 : _c.registerMetadataForSwitchToRelatives(this.key);
73
+ }
74
+ else {
75
+ (_d = this.viewerStateManager) === null || _d === void 0 ? void 0 : _d.unregisterMetadataForSwitchToRelatives(this.key);
76
+ }
77
+ }
78
+ if (props.has("translateValues") || props.has("metadata") || props.has("hierarchicalValueTruncatingLevel") || props.has("availableContentLocales") || this.dateFormatOptionsChanged(props)) {
79
+ this.flatMetadata = this.metadata
80
+ ? ClusteringHelper.flattenMetadata(this.metadata, this.hierarchicalValueTruncatingLevel, this.getDateFormatter(this.metadata.key))
81
+ : undefined;
82
+ if (this.translateValues) {
83
+ this.flatMetadata = new MetadataValueLocalizer((_e = this.availableContentLocales) !== null && _e !== void 0 ? _e : []).localize(this.flatMetadata);
84
+ }
85
+ }
86
+ }
87
+ updateRelatives() {
88
+ var _a, _b, _c, _d;
89
+ if (this.useForSwitchingToRelatives && this.key) {
90
+ this.relatives = (_d = (_b = (_a = this.viewerStateManager) === null || _a === void 0 ? void 0 : _a.clusteringHelper) === null || _b === void 0 ? void 0 : _b.computeClustersItemsForMetadata(this.key, ((_c = this.document) === null || _c === void 0 ? void 0 : _c.lang) || "en", this.noValueMessage, this.hierarchicalValueTruncatingLevel, this.getDateFormatter(this.key))) !== null && _d !== void 0 ? _d : [];
91
+ }
92
+ else {
93
+ this.relatives = [];
94
+ }
95
+ }
96
+ render() {
97
+ return html `
98
+ ${this.useForSwitchingToRelatives && this.relatives.length > 0 ? this.renderSwitchToRelatives() : this.renderChip()}
99
+ ${this.hideIfEmpty()}
100
+ `;
101
+ }
102
+ hideIfEmpty() {
103
+ const shouldHide = this.flatMetadata == null && (this.useForSwitchingToRelatives ? this.relatives.length === 0 : true);
104
+ if (!this.editorMode && shouldHide) {
105
+ return html `
106
+ <style>
107
+ :host {
108
+ display: none !important;
109
+ }
110
+ </style>
111
+ `;
112
+ }
113
+ return nothing;
114
+ }
115
+ renderSwitchToRelatives() {
116
+ return html `
117
+ <div part="floating-menu-container" class="ft-ud-viewer-metadata--container">
118
+ <ft-floating-menu part="floating-menu" text="Toggle collapsible" trailingIcon>
119
+ ${this.renderChip(true)}
120
+ <ft-floating-menu-label>${this.metadataLabel}</ft-floating-menu-label>
121
+ ${repeat(this.relatives, (relative) => relative.metadata.value, (relative) => this.renderRelativeItem(relative.result, relative.metadata))}
122
+ </ft-floating-menu>
123
+ </div>
124
+ `;
125
+ }
126
+ renderRelativeItem(result, metadata) {
127
+ var _a, _b;
128
+ const translatedMetadata = this.translateValues
129
+ ? (_b = new MetadataValueLocalizer((_a = this.availableContentLocales) !== null && _a !== void 0 ? _a : []).localize(metadata)) !== null && _b !== void 0 ? _b : metadata
130
+ : metadata;
131
+ const url = getResultUrl(result);
132
+ return html `
133
+ <a part="relative-item-link"
134
+ href="${url}" >
135
+ <ft-ripple part="relative-item-ripple"></ft-ripple>
136
+ <ft-floating-menu-item part="relative-item" value="${translatedMetadata.value}" notFocusable>
137
+ ${translatedMetadata.value == null || translatedMetadata.value === translatedMetadata.displayValue
138
+ ? translatedMetadata.displayValue
139
+ : html `
140
+ <ft-tooltip part="relative-item-tooltip" text="${(translatedMetadata.value)}">
141
+ ${translatedMetadata.displayValue}
142
+ </ft-tooltip>
143
+ `}
144
+ </ft-floating-menu-item>
145
+ </a>
146
+ `;
147
+ }
148
+ renderChip(inFloatingMenu = false) {
149
+ var _a, _b, _c, _d, _e, _f;
150
+ const noTooltip = !this.forceTooltip && this.displayLabel && ((_a = this.flatMetadata) === null || _a === void 0 ? void 0 : _a.displayTooltipValue) == ((_b = this.flatMetadata) === null || _b === void 0 ? void 0 : _b.displayValue);
151
+ const tooltipLabel = `${this.metadataLabel}: ${(_d = (_c = this.flatMetadata) === null || _c === void 0 ? void 0 : _c.displayTooltipValue) !== null && _d !== void 0 ? _d : this.noValueMessage}`;
152
+ const chip = html `
153
+ <ft-chip part="chip"
154
+ exportpartsPrefix="chip"
155
+ label="${tooltipLabel}"
156
+ slot="${noTooltip && inFloatingMenu ? "toggle" : ""}"
157
+ trailingIcon icon="${inFloatingMenu ? "thin_arrow" : ""}"
158
+ ?clickable=${inFloatingMenu}
159
+ ?multiLine=${this.multiLine}>
160
+ ${this.displayLabel ? html `
161
+ <span part="label">${(_f = (_e = this.metadata) === null || _e === void 0 ? void 0 : _e.label) !== null && _f !== void 0 ? _f : this.key}: </span>
162
+ ` : nothing}
163
+ ${this.metadataValue.length === 0 ? nothing : html `
164
+ <span part="values">${this.metadataValue}</span>
165
+ `}
166
+ </ft-chip>`;
167
+ return noTooltip ? chip : html `
168
+ <ft-tooltip part="tooltip"
169
+ slot="${inFloatingMenu ? "toggle" : ""}"
170
+ class="${this.multiLine ? "ft-ud-viewer-metadata-multi-line" : ""}"
171
+ text="${tooltipLabel}">
172
+ ${chip}
173
+ </ft-tooltip>
174
+ `;
175
+ }
176
+ }
177
+ FtUdViewerMetadata.elementDefinitions = {
178
+ "ft-chip": FtChip,
179
+ "ft-floating-menu": FtFloatingMenu,
180
+ "ft-floating-menu-item": FtFloatingMenuItem,
181
+ "ft-floating-menu-label": FtFloatingMenuLabel,
182
+ "ft-ripple": FtRipple,
183
+ "ft-tooltip": FtTooltip,
184
+ };
185
+ FtUdViewerMetadata.styles = styles;
186
+ __decorate([
187
+ property(),
188
+ reduxReactive()
189
+ ], FtUdViewerMetadata.prototype, "key", void 0);
190
+ __decorate([
191
+ property({ type: Boolean })
192
+ ], FtUdViewerMetadata.prototype, "multiLine", void 0);
193
+ __decorate([
194
+ property({ type: Boolean })
195
+ ], FtUdViewerMetadata.prototype, "useForSwitchingToRelatives", void 0);
196
+ __decorate([
197
+ property({ type: Boolean })
198
+ ], FtUdViewerMetadata.prototype, "displayLabel", void 0);
199
+ __decorate([
200
+ numberProperty()
201
+ ], FtUdViewerMetadata.prototype, "hierarchicalValueTruncatingLevel", void 0);
202
+ __decorate([
203
+ property({ type: Boolean })
204
+ ], FtUdViewerMetadata.prototype, "forceTooltip", void 0);
205
+ __decorate([
206
+ property({ attribute: false })
207
+ ], FtUdViewerMetadata.prototype, "editorMode", void 0);
208
+ __decorate([
209
+ property({ type: Boolean })
210
+ ], FtUdViewerMetadata.prototype, "translateValues", void 0);
211
+ __decorate([
212
+ redux({ store: "viewer", selector: (s, e) => { var _a, _b; return (_b = (_a = s.document) === null || _a === void 0 ? void 0 : _a.metadata) === null || _b === void 0 ? void 0 : _b.find((m) => m.key === e.key); } })
213
+ ], FtUdViewerMetadata.prototype, "metadata", void 0);
214
+ __decorate([
215
+ state()
216
+ ], FtUdViewerMetadata.prototype, "flatMetadata", void 0);
217
+ __decorate([
218
+ redux({ store: "viewer" })
219
+ ], FtUdViewerMetadata.prototype, "document", void 0);
220
+ __decorate([
221
+ state()
222
+ ], FtUdViewerMetadata.prototype, "relatives", void 0);
223
+ __decorate([
224
+ redux({ store: ftAppInfoStore.name })
225
+ ], FtUdViewerMetadata.prototype, "availableContentLocales", void 0);
226
+ __decorate([
227
+ i18n(udViewerContext.properties.itemWithNoValueForSwitchToRelatives())
228
+ ], FtUdViewerMetadata.prototype, "noValueMessage", void 0);
229
+ __decorate([
230
+ reduxEventListener({ eventName: FtUdViewerStoreEvents.clusteringHelperCreated })
231
+ ], FtUdViewerMetadata.prototype, "updateRelatives", null);
@@ -0,0 +1,10 @@
1
+ export interface FtUdViewerMetadataProperties {
2
+ key?: string;
3
+ multiLine?: boolean;
4
+ forceTooltip?: boolean;
5
+ editorMode?: boolean;
6
+ useForSwitchingToRelatives?: boolean;
7
+ displayLabel?: boolean;
8
+ translateValues?: boolean;
9
+ hierarchicalValueTruncatingLevel?: number;
10
+ }
@@ -0,0 +1,2 @@
1
+ export declare const FtUdViewerMetadataCssVariables: {};
2
+ export declare const styles: import("lit").CSSResult;
@@ -0,0 +1,24 @@
1
+ import { css } from "lit";
2
+ export const FtUdViewerMetadataCssVariables = {};
3
+ // language=CSS
4
+ export const styles = css `
5
+ :host {
6
+ display: inline-block;
7
+ }
8
+
9
+ .ft-ud-viewer-metadata--container {
10
+ position: relative;
11
+ }
12
+
13
+ [part="tooltip"]:not(.ft-ud-viewer-metadata-multi-line),
14
+ [part="tooltip"]:not(.ft-ud-viewer-metadata-multi-line) [part="floating-menu-container"],
15
+ [part="tooltip"]:not(.ft-ud-viewer-metadata-multi-line) [part="floating-menu"],
16
+ [part="tooltip"]:not(.ft-ud-viewer-metadata-multi-line) [part="chip"] {
17
+ max-width: 100%;
18
+ }
19
+
20
+ a {
21
+ all: unset;
22
+ position: relative;
23
+ }
24
+ `;
@@ -0,0 +1,4 @@
1
+ import { FtBaseFeedback } from "@fluid-topics/ft-reader-feedback/build/ft-base-feedback";
2
+ export declare class FtViewerFeedback extends FtBaseFeedback {
3
+ static styles: import("lit").CSSResult;
4
+ }