@fluid-topics/ft-reader-attachments 1.1.12

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,19 @@
1
+ Reader component to list map attachments
2
+
3
+ ## Install
4
+
5
+ ```shell
6
+ npm install @fluid-topics/ft-reader-attachments
7
+ yarn add @fluid-topics/ft-reader-attachments
8
+ ```
9
+
10
+ ## Usage
11
+
12
+ ```typescript
13
+ import { html } from "lit"
14
+ import "@fluid-topics/ft-reader-attachments"
15
+
16
+ function render() {
17
+ return html` <ft-reader-attachments></ft-reader-attachments> `
18
+ }
19
+ ```
@@ -0,0 +1,6 @@
1
+ import { DefaultI18nMessages, I18nMessageContext, I18nMessages } from "@fluid-topics/ft-i18n";
2
+ export interface DesignedReaderAttachmentsMessages extends I18nMessages {
3
+ download(filename: string): string;
4
+ }
5
+ export declare const attachmentsMessages: I18nMessageContext<DesignedReaderAttachmentsMessages>;
6
+ export declare const defaultMessages: DefaultI18nMessages<DesignedReaderAttachmentsMessages>;
@@ -0,0 +1,5 @@
1
+ import { I18nMessageContext } from "@fluid-topics/ft-i18n";
2
+ export const attachmentsMessages = I18nMessageContext.build("designedReaderAttachments");
3
+ export const defaultMessages = {
4
+ download: "Download “{0}”"
5
+ };
@@ -0,0 +1,14 @@
1
+ export declare const FtReaderAttachmentsCssVariables: {
2
+ itemsGap: import("@fluid-topics/ft-wc-utils").FtCssVariable;
3
+ itemPadding: import("@fluid-topics/ft-wc-utils").FtCssVariable;
4
+ itemBorderWidth: import("@fluid-topics/ft-wc-utils").FtCssVariable;
5
+ itemBorderColor: import("@fluid-topics/ft-wc-utils").FtCssVariable;
6
+ itemBorderRadius: import("@fluid-topics/ft-wc-utils").FtCssVariable;
7
+ itemBackgroundColor: import("@fluid-topics/ft-wc-utils").FtCssVariable;
8
+ itemTextColor: import("@fluid-topics/ft-wc-utils").FtCssVariable;
9
+ itemHoverBackgroundColor: import("@fluid-topics/ft-wc-utils").FtCssVariable;
10
+ itemHoverTextColor: import("@fluid-topics/ft-wc-utils").FtCssVariable;
11
+ fileFormatIconSize: import("@fluid-topics/ft-wc-utils").FtCssVariable;
12
+ downloadIconSize: import("@fluid-topics/ft-wc-utils").FtCssVariable;
13
+ };
14
+ export declare const styles: import("lit").CSSResult;
@@ -0,0 +1,86 @@
1
+ import { css } from "lit";
2
+ import { designSystemVariables, FtCssVariableFactory, setVariable } from "@fluid-topics/ft-wc-utils";
3
+ import { FtRippleCssVariables } from "@fluid-topics/ft-ripple/build/ft-ripple.css";
4
+ import { FtIconCssVariables } from "@fluid-topics/ft-icon/build/ft-icon.css";
5
+ export const FtReaderAttachmentsCssVariables = {
6
+ itemsGap: FtCssVariableFactory.create("--ft-reader-attachments-items-gap", "", "SIZE", "8px"),
7
+ itemPadding: FtCssVariableFactory.create("--ft-reader-attachments-item-padding", "", "SIZE", "8px"),
8
+ itemBorderWidth: FtCssVariableFactory.create("--ft-reader-attachments-item-border-width", "", "SIZE", "1px"),
9
+ itemBorderColor: FtCssVariableFactory.extend("--ft-reader-attachments-item-border-color", "", designSystemVariables.colorOutline),
10
+ itemBorderRadius: FtCssVariableFactory.extend("--ft-reader-attachments-item-border-radius", "", designSystemVariables.borderRadiusS),
11
+ itemBackgroundColor: FtCssVariableFactory.extend("--ft-reader-attachments-item-background-color", "", designSystemVariables.colorSurface),
12
+ itemTextColor: FtCssVariableFactory.extend("--ft-reader-attachments-item-text-color", "", designSystemVariables.colorOnSurfaceMedium),
13
+ itemHoverBackgroundColor: FtCssVariableFactory.extend("--ft-reader-attachments-item-hover-background-color", "", designSystemVariables.colorPrimary),
14
+ itemHoverTextColor: FtCssVariableFactory.extend("--ft-reader-attachments-item-hover-text-color", "", designSystemVariables.colorOnSurfaceHigh),
15
+ fileFormatIconSize: FtCssVariableFactory.create("--ft-reader-attachments-file-format-icon-size", "", "SIZE", "30px"),
16
+ downloadIconSize: FtCssVariableFactory.create("--ft-reader-attachments-down-icon-size", "", "SIZE", "20px"),
17
+ };
18
+ // language=CSS
19
+ export const styles = css `
20
+ [part="container"] {
21
+ display: flex;
22
+ flex-direction: column;
23
+ gap: ${FtReaderAttachmentsCssVariables.itemsGap};
24
+ }
25
+
26
+ [part="attachment"] {
27
+ border-style: solid;
28
+ border-width: ${FtReaderAttachmentsCssVariables.itemBorderWidth};
29
+ border-color: ${FtReaderAttachmentsCssVariables.itemBorderColor};
30
+ border-radius: ${FtReaderAttachmentsCssVariables.itemBorderRadius};
31
+ background-color: ${FtReaderAttachmentsCssVariables.itemBackgroundColor};
32
+ }
33
+
34
+ [part="attachment"], [part="viewer-link"], [part="download-link"] {
35
+ display: flex;
36
+ flex-direction: row;
37
+ }
38
+
39
+ [part="viewer-link"], [part="download-link"] {
40
+ position: relative;
41
+ color: ${FtReaderAttachmentsCssVariables.itemTextColor};
42
+ text-decoration: none;
43
+ padding: ${FtReaderAttachmentsCssVariables.itemPadding};
44
+ align-items: center;
45
+ }
46
+
47
+ [part="viewer-link"]:hover, [part="download-link"]:hover {
48
+ color: ${FtReaderAttachmentsCssVariables.itemHoverTextColor};
49
+ }
50
+
51
+ [part="viewer-link"] {
52
+ gap: 8px;
53
+ }
54
+
55
+ [part="viewer-link"], [part="name"] {
56
+ flex-grow: 1;
57
+ flex-shrink: 1;
58
+ word-wrap: break-word;
59
+ word-break: break-word;
60
+ }
61
+
62
+ [part~="ripple"] {
63
+ ${setVariable(FtRippleCssVariables.color, FtReaderAttachmentsCssVariables.itemHoverBackgroundColor)};
64
+ ${setVariable(FtRippleCssVariables.borderRadius, FtReaderAttachmentsCssVariables.itemBorderRadius)};
65
+ }
66
+
67
+ [part="file-format-icon"] {
68
+ ${setVariable(FtIconCssVariables.size, FtReaderAttachmentsCssVariables.fileFormatIconSize)};
69
+ }
70
+
71
+ [part="download-icon"] {
72
+ ${setVariable(FtIconCssVariables.size, FtReaderAttachmentsCssVariables.downloadIconSize)};
73
+ }
74
+
75
+ .hide-file-format-icon [part="file-format-icon"] {
76
+ display: none;
77
+ }
78
+
79
+ .hide-filename [part="name"] {
80
+ display: none;
81
+ }
82
+
83
+ .hide-download-icon [part="download-link"] {
84
+ display: none;
85
+ }
86
+ `;
@@ -0,0 +1,19 @@
1
+ import { nothing, PropertyValues } from "lit";
2
+ import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
3
+ import { FtReaderAttachmentsProperties } from "./ft-reader-attachments.properties";
4
+ import { FtReaderComponent } from "@fluid-topics/ft-reader-context/build/registration";
5
+ import { FtMap, FtMapAttachment } from "@fluid-topics/public-api";
6
+ declare const FtReaderAttachments_base: typeof FtReaderComponent & import("@fluid-topics/ft-wc-utils").Constructor<import("@fluid-topics/ft-i18n").FtLitElementWithI18nInterface>;
7
+ export declare class FtReaderAttachments extends FtReaderAttachments_base implements FtReaderAttachmentsProperties {
8
+ static elementDefinitions: ElementDefinitionsMap;
9
+ static styles: import("lit").CSSResult;
10
+ hideFileFormatIcon: boolean;
11
+ hideFilename: boolean;
12
+ hideDownloadIcon: boolean;
13
+ map?: FtMap;
14
+ attachments?: Array<FtMapAttachment>;
15
+ constructor();
16
+ protected render(): import("lit").TemplateResult<1> | typeof nothing;
17
+ protected update(props: PropertyValues): void;
18
+ }
19
+ export {};
@@ -0,0 +1,99 @@
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, nothing } from "lit";
8
+ import { property, state } from "lit/decorators.js";
9
+ import { last, redux } from "@fluid-topics/ft-wc-utils";
10
+ import { styles } from "./ft-reader-attachments.css";
11
+ import { FtReaderComponent } from "@fluid-topics/ft-reader-context/build/registration";
12
+ import { repeat } from "lit/directives/repeat.js";
13
+ import { attachmentsMessages, defaultMessages } from "./DesignedReaderAttachmentsMessages";
14
+ import { fileFormatColors, FtFileFormatIcons, FtIcon, resolveFileFormatIcon } from "@fluid-topics/ft-icon";
15
+ import { FtTypography } from "@fluid-topics/ft-typography";
16
+ import { withI18n } from "@fluid-topics/ft-i18n";
17
+ import { classMap } from "lit/directives/class-map.js";
18
+ import { FtRipple } from "@fluid-topics/ft-ripple";
19
+ class FtReaderAttachments extends withI18n(FtReaderComponent) {
20
+ constructor() {
21
+ super();
22
+ this.hideFileFormatIcon = false;
23
+ this.hideFilename = false;
24
+ this.hideDownloadIcon = false;
25
+ this.addI18nContext(attachmentsMessages, defaultMessages);
26
+ }
27
+ render() {
28
+ var _a, _b;
29
+ if (((_b = (_a = this.attachments) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0) {
30
+ const classes = {
31
+ ["hide-file-format-icon"]: this.hideFileFormatIcon,
32
+ ["hide-filename"]: this.hideFilename,
33
+ ["hide-download-icon"]: this.hideDownloadIcon,
34
+ };
35
+ return html `
36
+ <div part="container" class="${classMap(classes)}">
37
+ ${repeat(this.attachments, attachment => attachment.id, attachment => {
38
+ var _a, _b, _c, _d;
39
+ const icon = resolveFileFormatIcon(attachment.mimeType, last(attachment.file.split(".")));
40
+ const url = attachment.externalLink ? attachment.viewerUrl : (_a = this.service) === null || _a === void 0 ? void 0 : _a.makeAbsolute((_b = attachment.viewerUrl) !== null && _b !== void 0 ? _b : "");
41
+ return html `
42
+ <div part="attachment">
43
+ <a part="viewer-link" href="${url}">
44
+ <ft-ripple part="ripple viewer-link-ripple"></ft-ripple>
45
+ <ft-icon part="file-format-icon"
46
+ variant="file-format"
47
+ value="${icon}"
48
+ style="color: ${(_c = fileFormatColors[icon]) !== null && _c !== void 0 ? _c : fileFormatColors[FtFileFormatIcons.UNKNOWN]}"></ft-icon>
49
+ <ft-typography part="name" variant="body2">${attachment.name}</ft-typography>
50
+ </a>
51
+ <a part="download-link"
52
+ href="${(_d = this.service) === null || _d === void 0 ? void 0 : _d.getAttachmentDownloadLink(attachment.id)}"
53
+ title="${attachmentsMessages.messages.download(attachment.file)}">
54
+ <ft-ripple part="ripple download-link-ripple"></ft-ripple>
55
+ <ft-icon part="download-icon">DOWNLOAD</ft-icon>
56
+ </a>
57
+ </div>
58
+ `;
59
+ })}
60
+ </div>
61
+ `;
62
+ }
63
+ return nothing;
64
+ }
65
+ update(props) {
66
+ var _a;
67
+ super.update(props);
68
+ if (props.has("map")) {
69
+ if (this.map) {
70
+ (_a = this.service) === null || _a === void 0 ? void 0 : _a.getAttachments().then(attachments => this.attachments = attachments);
71
+ }
72
+ else {
73
+ this.attachments = undefined;
74
+ }
75
+ }
76
+ }
77
+ }
78
+ FtReaderAttachments.elementDefinitions = {
79
+ "ft-icon": FtIcon,
80
+ "ft-ripple": FtRipple,
81
+ "ft-typography": FtTypography,
82
+ };
83
+ FtReaderAttachments.styles = styles;
84
+ __decorate([
85
+ property({ type: Boolean })
86
+ ], FtReaderAttachments.prototype, "hideFileFormatIcon", void 0);
87
+ __decorate([
88
+ property({ type: Boolean })
89
+ ], FtReaderAttachments.prototype, "hideFilename", void 0);
90
+ __decorate([
91
+ property({ type: Boolean })
92
+ ], FtReaderAttachments.prototype, "hideDownloadIcon", void 0);
93
+ __decorate([
94
+ redux({ store: "reader" })
95
+ ], FtReaderAttachments.prototype, "map", void 0);
96
+ __decorate([
97
+ state()
98
+ ], FtReaderAttachments.prototype, "attachments", void 0);
99
+ export { FtReaderAttachments };