@operato/attachment 10.29.98 → 10.29.99
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/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/ox-attachment-files.d.ts +45 -0
- package/dist/src/ox-attachment-files.js +295 -0
- package/package.json +9 -5
- package/translations/en.json +2 -1
- package/translations/es.json +2 -1
- package/translations/ja.json +2 -1
- package/translations/ko.json +2 -1
- package/translations/ms.json +2 -1
- package/translations/zh.json +2 -1
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import '@material/web/icon/icon.js';
|
|
2
|
+
import { LitElement } from 'lit';
|
|
3
|
+
/** A file as the servers hand it - an `Attachment`, or a record's paper built from one. */
|
|
4
|
+
export interface AttachmentFile {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
fullpath: string;
|
|
8
|
+
mimetype?: string | null;
|
|
9
|
+
size?: number | null;
|
|
10
|
+
/** When it was attached - an ISO text or epoch milliseconds. */
|
|
11
|
+
createdAt?: string | number | null;
|
|
12
|
+
/** Who attached it - a name, or a user with one. */
|
|
13
|
+
creator?: string | {
|
|
14
|
+
name?: string | null;
|
|
15
|
+
} | null;
|
|
16
|
+
}
|
|
17
|
+
/** A size as a person reads it - B, KB, MB, GB. */
|
|
18
|
+
export declare function fileSizeText(bytes?: number | null): string;
|
|
19
|
+
/** The day it was attached, YYYY-MM-DD in the viewer's zone - or nothing for a day that does not read. */
|
|
20
|
+
export declare function fileDayText(at?: string | number | null): string;
|
|
21
|
+
/** The extension of a name, upper case - `PDF` - or nothing. */
|
|
22
|
+
export declare function fileExtensionText(name?: string | null): string;
|
|
23
|
+
/** The icon of a file's kind - the tile's families, and a picture for an image (the tile previews those instead). */
|
|
24
|
+
export declare function fileKindIcon(mimetype?: string | null, name?: string | null): string;
|
|
25
|
+
/**
|
|
26
|
+
* The files of one record, as a list: each with its kind's icon, its name opening it in a new tab, a line of what
|
|
27
|
+
* it is (type · size · day · who), and its own open and download buttons. With `removable` each also has a remove
|
|
28
|
+
* button that asks nothing itself - it fires `file-remove` with the file, and the owner confirms and removes.
|
|
29
|
+
*
|
|
30
|
+
* The list holds no data of its own: the owner reads and writes the files and hands them in as `files`.
|
|
31
|
+
*/
|
|
32
|
+
export declare class OxAttachmentFiles extends LitElement {
|
|
33
|
+
static styles: import("lit").CSSResult;
|
|
34
|
+
/** The files, in the order they are shown. */
|
|
35
|
+
files: AttachmentFile[];
|
|
36
|
+
/** Whether each file has a remove button - it fires `file-remove`. */
|
|
37
|
+
removable: boolean;
|
|
38
|
+
/** While the owner writes: the remove buttons wait. */
|
|
39
|
+
disabled: boolean;
|
|
40
|
+
/** What the list says with no file. */
|
|
41
|
+
emptyText: string;
|
|
42
|
+
/** The remove button's word, when the owner's is not 「delete」 - 「take off」. */
|
|
43
|
+
removeLabel: string;
|
|
44
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
45
|
+
}
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import '@material/web/icon/icon.js';
|
|
3
|
+
import { css, html, LitElement, nothing } from 'lit';
|
|
4
|
+
import { customElement, property } from 'lit/decorators.js';
|
|
5
|
+
import { i18next } from '@operato/i18n';
|
|
6
|
+
import { fileFamilyIcon } from './ox-attachment-tile.js';
|
|
7
|
+
/** A size as a person reads it - B, KB, MB, GB. */
|
|
8
|
+
export function fileSizeText(bytes) {
|
|
9
|
+
if (bytes === null || bytes === undefined || !Number.isFinite(bytes) || bytes < 0)
|
|
10
|
+
return '';
|
|
11
|
+
if (bytes < 1024)
|
|
12
|
+
return `${bytes}B`;
|
|
13
|
+
const units = ['KB', 'MB', 'GB'];
|
|
14
|
+
let value = bytes / 1024;
|
|
15
|
+
let unit = 0;
|
|
16
|
+
while (value >= 1024 && unit < units.length - 1) {
|
|
17
|
+
value /= 1024;
|
|
18
|
+
unit++;
|
|
19
|
+
}
|
|
20
|
+
return `${value >= 100 || unit === 0 ? Math.round(value) : value.toFixed(1)}${units[unit]}`;
|
|
21
|
+
}
|
|
22
|
+
/** The day it was attached, YYYY-MM-DD in the viewer's zone - or nothing for a day that does not read. */
|
|
23
|
+
export function fileDayText(at) {
|
|
24
|
+
if (at === null || at === undefined || at === '')
|
|
25
|
+
return '';
|
|
26
|
+
const day = new Date(typeof at === 'string' && /^\d+$/.test(at) ? Number(at) : at);
|
|
27
|
+
if (Number.isNaN(day.getTime()))
|
|
28
|
+
return '';
|
|
29
|
+
const two = (n) => String(n).padStart(2, '0');
|
|
30
|
+
return `${day.getFullYear()}-${two(day.getMonth() + 1)}-${two(day.getDate())}`;
|
|
31
|
+
}
|
|
32
|
+
/** The extension of a name, upper case - `PDF` - or nothing. */
|
|
33
|
+
export function fileExtensionText(name) {
|
|
34
|
+
const match = /\.([A-Za-z0-9]{1,8})$/.exec(name !== null && name !== void 0 ? name : '');
|
|
35
|
+
return match ? match[1].toUpperCase() : '';
|
|
36
|
+
}
|
|
37
|
+
const IMAGE_EXTENSIONS = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'svg', 'heic', 'tif', 'tiff'];
|
|
38
|
+
/** The icon of a file's kind - the tile's families, and a picture for an image (the tile previews those instead). */
|
|
39
|
+
export function fileKindIcon(mimetype, name) {
|
|
40
|
+
const ext = fileExtensionText(name).toLowerCase();
|
|
41
|
+
if ((mimetype !== null && mimetype !== void 0 ? mimetype : '').startsWith('image/') || IMAGE_EXTENSIONS.includes(ext))
|
|
42
|
+
return 'image';
|
|
43
|
+
return fileFamilyIcon(mimetype !== null && mimetype !== void 0 ? mimetype : '', name !== null && name !== void 0 ? name : '');
|
|
44
|
+
}
|
|
45
|
+
const creatorName = (creator) => (typeof creator === 'string' ? creator : creator === null || creator === void 0 ? void 0 : creator.name) || '';
|
|
46
|
+
/**
|
|
47
|
+
* The files of one record, as a list: each with its kind's icon, its name opening it in a new tab, a line of what
|
|
48
|
+
* it is (type · size · day · who), and its own open and download buttons. With `removable` each also has a remove
|
|
49
|
+
* button that asks nothing itself - it fires `file-remove` with the file, and the owner confirms and removes.
|
|
50
|
+
*
|
|
51
|
+
* The list holds no data of its own: the owner reads and writes the files and hands them in as `files`.
|
|
52
|
+
*/
|
|
53
|
+
let OxAttachmentFiles = class OxAttachmentFiles extends LitElement {
|
|
54
|
+
constructor() {
|
|
55
|
+
super(...arguments);
|
|
56
|
+
/** The files, in the order they are shown. */
|
|
57
|
+
this.files = [];
|
|
58
|
+
/** Whether each file has a remove button - it fires `file-remove`. */
|
|
59
|
+
this.removable = false;
|
|
60
|
+
/** While the owner writes: the remove buttons wait. */
|
|
61
|
+
this.disabled = false;
|
|
62
|
+
/** What the list says with no file. */
|
|
63
|
+
this.emptyText = '';
|
|
64
|
+
/** The remove button's word, when the owner's is not 「delete」 - 「take off」. */
|
|
65
|
+
this.removeLabel = '';
|
|
66
|
+
}
|
|
67
|
+
render() {
|
|
68
|
+
var _a;
|
|
69
|
+
if (!((_a = this.files) === null || _a === void 0 ? void 0 : _a.length))
|
|
70
|
+
return html `<p empty>${this.emptyText || i18next.t('text.no-attachments')}</p>`;
|
|
71
|
+
const open = i18next.t('button.open-in-new');
|
|
72
|
+
const download = i18next.t('button.download');
|
|
73
|
+
const remove = this.removeLabel || i18next.t('button.delete');
|
|
74
|
+
return html `<ul>
|
|
75
|
+
${this.files.map(file => {
|
|
76
|
+
const icon = fileKindIcon(file.mimetype, file.name);
|
|
77
|
+
const ext = fileExtensionText(file.name);
|
|
78
|
+
const size = fileSizeText(file.size);
|
|
79
|
+
const day = fileDayText(file.createdAt);
|
|
80
|
+
const who = creatorName(file.creator);
|
|
81
|
+
return html `<li>
|
|
82
|
+
<span kind ?pdf=${icon === 'picture_as_pdf'} aria-hidden="true"><md-icon>${icon}</md-icon></span>
|
|
83
|
+
<div body>
|
|
84
|
+
<a filename href=${file.fullpath} target="_blank" rel="noopener" title=${file.name}>${file.name}</a>
|
|
85
|
+
<div meta>
|
|
86
|
+
${ext ? html `<span ext>${ext}</span>` : nothing}${size ? html `<span size>${size}</span>` : nothing}${day
|
|
87
|
+
? html `<span day>${day}</span>`
|
|
88
|
+
: nothing}${who ? html `<span who>${who}</span>` : nothing}
|
|
89
|
+
</div>
|
|
90
|
+
</div>
|
|
91
|
+
<div acts>
|
|
92
|
+
<a act open href=${file.fullpath} target="_blank" rel="noopener" title=${open} aria-label=${`${open} · ${file.name}`}
|
|
93
|
+
><md-icon>open_in_new</md-icon></a
|
|
94
|
+
>
|
|
95
|
+
<a act download href=${file.fullpath} download=${file.name} title=${download} aria-label=${`${download} · ${file.name}`}
|
|
96
|
+
><md-icon>download</md-icon></a
|
|
97
|
+
>
|
|
98
|
+
${this.removable
|
|
99
|
+
? html `<button
|
|
100
|
+
act
|
|
101
|
+
danger
|
|
102
|
+
remove
|
|
103
|
+
type="button"
|
|
104
|
+
?disabled=${this.disabled}
|
|
105
|
+
title=${remove}
|
|
106
|
+
aria-label=${`${remove} · ${file.name}`}
|
|
107
|
+
@click=${() => this.dispatchEvent(new CustomEvent('file-remove', { detail: file, bubbles: true, composed: true }))}
|
|
108
|
+
>
|
|
109
|
+
<md-icon>delete</md-icon>
|
|
110
|
+
</button>`
|
|
111
|
+
: nothing}
|
|
112
|
+
</div>
|
|
113
|
+
</li>`;
|
|
114
|
+
})}
|
|
115
|
+
</ul>`;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
OxAttachmentFiles.styles = css `
|
|
119
|
+
:host {
|
|
120
|
+
display: block;
|
|
121
|
+
container-type: inline-size;
|
|
122
|
+
font: var(--ox-attachment-files-font, inherit);
|
|
123
|
+
color: var(--md-sys-color-on-surface, #1b1b21);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
ul {
|
|
127
|
+
list-style: none;
|
|
128
|
+
margin: 0;
|
|
129
|
+
padding: 0;
|
|
130
|
+
border: 1px solid var(--md-sys-color-outline-variant, #c5c6d0);
|
|
131
|
+
border-radius: var(--md-sys-shape-corner-medium, 8px);
|
|
132
|
+
overflow: hidden;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
li {
|
|
136
|
+
display: flex;
|
|
137
|
+
align-items: center;
|
|
138
|
+
gap: 12px;
|
|
139
|
+
min-height: 56px;
|
|
140
|
+
padding: 8px 8px 8px 12px;
|
|
141
|
+
box-sizing: border-box;
|
|
142
|
+
background: var(--md-sys-color-surface, #fff);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
li + li {
|
|
146
|
+
border-top: 1px solid var(--md-sys-color-outline-variant, #c5c6d0);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
li:hover,
|
|
150
|
+
li:focus-within {
|
|
151
|
+
background: var(--md-sys-color-surface-container-low, #f4f3fa);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
[kind] {
|
|
155
|
+
flex: none;
|
|
156
|
+
display: grid;
|
|
157
|
+
place-items: center;
|
|
158
|
+
width: 36px;
|
|
159
|
+
height: 36px;
|
|
160
|
+
border-radius: var(--md-sys-shape-corner-small, 6px);
|
|
161
|
+
color: var(--md-sys-color-on-secondary-container, #001e2c);
|
|
162
|
+
background: var(--md-sys-color-secondary-container, #c3e8ff);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
[kind] md-icon {
|
|
166
|
+
--md-icon-size: 20px;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
[kind][pdf] {
|
|
170
|
+
color: var(--md-sys-color-on-error-container, #410002);
|
|
171
|
+
background: var(--md-sys-color-error-container, #ffdad6);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
[body] {
|
|
175
|
+
flex: 1;
|
|
176
|
+
min-width: 0;
|
|
177
|
+
display: flex;
|
|
178
|
+
flex-direction: column;
|
|
179
|
+
gap: 2px;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
[filename] {
|
|
183
|
+
overflow: hidden;
|
|
184
|
+
text-overflow: ellipsis;
|
|
185
|
+
white-space: nowrap;
|
|
186
|
+
font-weight: 500;
|
|
187
|
+
color: inherit;
|
|
188
|
+
text-decoration: none;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
[filename]:hover {
|
|
192
|
+
color: var(--md-sys-color-primary, #495d92);
|
|
193
|
+
text-decoration: underline;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
[filename]:focus-visible,
|
|
197
|
+
[act]:focus-visible {
|
|
198
|
+
outline: 2px solid var(--md-sys-color-primary, #495d92);
|
|
199
|
+
outline-offset: 2px;
|
|
200
|
+
border-radius: 4px;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
[meta] {
|
|
204
|
+
overflow: hidden;
|
|
205
|
+
text-overflow: ellipsis;
|
|
206
|
+
white-space: nowrap;
|
|
207
|
+
font-size: 0.8em;
|
|
208
|
+
color: var(--md-sys-color-on-surface-variant, #45464f);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
[meta] span + span::before {
|
|
212
|
+
content: '·';
|
|
213
|
+
margin: 0 6px;
|
|
214
|
+
color: var(--md-sys-color-outline, #757680);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
[acts] {
|
|
218
|
+
flex: none;
|
|
219
|
+
display: flex;
|
|
220
|
+
gap: 2px;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
[act] {
|
|
224
|
+
display: inline-grid;
|
|
225
|
+
place-items: center;
|
|
226
|
+
width: 36px;
|
|
227
|
+
height: 36px;
|
|
228
|
+
padding: 0;
|
|
229
|
+
border: none;
|
|
230
|
+
border-radius: 50%;
|
|
231
|
+
background: none;
|
|
232
|
+
color: var(--md-sys-color-on-surface-variant, #45464f);
|
|
233
|
+
cursor: pointer;
|
|
234
|
+
text-decoration: none;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
[act] md-icon {
|
|
238
|
+
--md-icon-size: 20px;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
[act]:hover {
|
|
242
|
+
color: var(--md-sys-color-primary, #495d92);
|
|
243
|
+
background: color-mix(in srgb, var(--md-sys-color-primary, #495d92) 10%, transparent);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
[act][danger]:hover {
|
|
247
|
+
color: var(--md-sys-color-error, #ba1a1a);
|
|
248
|
+
background: color-mix(in srgb, var(--md-sys-color-error, #ba1a1a) 10%, transparent);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
[act][disabled] {
|
|
252
|
+
opacity: 0.38;
|
|
253
|
+
pointer-events: none;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
[empty] {
|
|
257
|
+
margin: 0;
|
|
258
|
+
padding: 24px 12px;
|
|
259
|
+
text-align: center;
|
|
260
|
+
color: var(--md-sys-color-on-surface-variant, #45464f);
|
|
261
|
+
border: 1px dashed var(--md-sys-color-outline-variant, #c5c6d0);
|
|
262
|
+
border-radius: var(--md-sys-shape-corner-medium, 8px);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/* Narrow: the type and the uploader leave the line first; the buttons stay. */
|
|
266
|
+
@container (max-width: 360px) {
|
|
267
|
+
[meta] [ext],
|
|
268
|
+
[meta] [who] {
|
|
269
|
+
display: none;
|
|
270
|
+
}
|
|
271
|
+
[meta] [ext] + span::before {
|
|
272
|
+
content: none;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
`;
|
|
276
|
+
__decorate([
|
|
277
|
+
property({ type: Array })
|
|
278
|
+
], OxAttachmentFiles.prototype, "files", void 0);
|
|
279
|
+
__decorate([
|
|
280
|
+
property({ type: Boolean })
|
|
281
|
+
], OxAttachmentFiles.prototype, "removable", void 0);
|
|
282
|
+
__decorate([
|
|
283
|
+
property({ type: Boolean })
|
|
284
|
+
], OxAttachmentFiles.prototype, "disabled", void 0);
|
|
285
|
+
__decorate([
|
|
286
|
+
property({ attribute: 'empty-text' })
|
|
287
|
+
], OxAttachmentFiles.prototype, "emptyText", void 0);
|
|
288
|
+
__decorate([
|
|
289
|
+
property({ attribute: 'remove-label' })
|
|
290
|
+
], OxAttachmentFiles.prototype, "removeLabel", void 0);
|
|
291
|
+
OxAttachmentFiles = __decorate([
|
|
292
|
+
customElement('ox-attachment-files')
|
|
293
|
+
], OxAttachmentFiles);
|
|
294
|
+
export { OxAttachmentFiles };
|
|
295
|
+
//# sourceMappingURL=ox-attachment-files.js.map
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@operato/attachment",
|
|
3
3
|
"description": "Webcomponent attachment following open-wc recommendations",
|
|
4
4
|
"author": "heartyoh",
|
|
5
|
-
"version": "10.29.
|
|
5
|
+
"version": "10.29.99",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/src/index.js",
|
|
8
8
|
"module": "dist/src/index.js",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"./ox-attachment-list.js": "./dist/src/ox-attachment-list.js",
|
|
13
13
|
"./ox-attachment-selector.js": "./dist/src/ox-attachment-selector.js",
|
|
14
14
|
"./ox-property-editor-attachment-selector.js": "./dist/src/ox-property-editor-attachment-selector.js",
|
|
15
|
-
"./ox-property-editor-image-selector.js": "./dist/src/ox-property-editor-image-selector.js"
|
|
15
|
+
"./ox-property-editor-image-selector.js": "./dist/src/ox-property-editor-image-selector.js",
|
|
16
|
+
"./ox-attachment-files.js": "./dist/src/ox-attachment-files.js"
|
|
16
17
|
},
|
|
17
18
|
"files": [
|
|
18
19
|
"README.md",
|
|
@@ -40,6 +41,9 @@
|
|
|
40
41
|
],
|
|
41
42
|
"ox-property-editor-image-selector.js": [
|
|
42
43
|
"dist/src/ox-property-editor-image-selector.d.ts"
|
|
44
|
+
],
|
|
45
|
+
"ox-attachment-files.js": [
|
|
46
|
+
"dist/src/ox-attachment-files.d.ts"
|
|
43
47
|
]
|
|
44
48
|
}
|
|
45
49
|
},
|
|
@@ -68,11 +72,11 @@
|
|
|
68
72
|
},
|
|
69
73
|
"dependencies": {
|
|
70
74
|
"@material/web": "^2.0.0",
|
|
71
|
-
"@operato/data-grist": "^10.29.
|
|
75
|
+
"@operato/data-grist": "^10.29.99",
|
|
72
76
|
"@operato/graphql": "^10.29.85",
|
|
73
77
|
"@operato/i18n": "^10.29.85",
|
|
74
78
|
"@operato/input": "^10.29.96",
|
|
75
|
-
"@operato/property-editor": "^10.29.
|
|
79
|
+
"@operato/property-editor": "^10.29.99",
|
|
76
80
|
"@operato/styles": "^10.29.83",
|
|
77
81
|
"@operato/utils": "^10.29.85",
|
|
78
82
|
"i18next": "^24.2.1",
|
|
@@ -110,5 +114,5 @@
|
|
|
110
114
|
"prettier --write"
|
|
111
115
|
]
|
|
112
116
|
},
|
|
113
|
-
"gitHead": "
|
|
117
|
+
"gitHead": "9520c03ab49e0e2f691b93f9d8d3dd6bd5428a24"
|
|
114
118
|
}
|
package/translations/en.json
CHANGED
package/translations/es.json
CHANGED
package/translations/ja.json
CHANGED
package/translations/ko.json
CHANGED
package/translations/ms.json
CHANGED