@social-mail/social-mail-client 1.2.2 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@social-mail/social-mail-client",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -58,7 +58,7 @@ const onAttachInlineImage = async (ce: CustomEvent) => {
58
58
  reader.onload = () => {
59
59
  c.executeCommand("insertHTML", void 0, `<div><img
60
60
  data-content="data-url"
61
- src="${reader.result}" style='max-height: 700px;'/>
61
+ src="${reader.result as any}" style='max-height: 700px;'/>
62
62
  </div>`);
63
63
  };
64
64
  reader.readAsDataURL(file);
@@ -10,6 +10,8 @@ import XNode from "@web-atoms/core/dist/core/XNode";
10
10
  import AtomRepeater from "@web-atoms/web-controls/dist/basic/AtomRepeater";
11
11
  import Bind from "@web-atoms/core/dist/core/Bind";
12
12
  import PopupService from "@web-atoms/core/dist/web/services/PopupService";
13
+ import { IAppFile } from "../../model/model";
14
+ import TaskManager from "@web-atoms/entity/dist/models/TaskManager";
13
15
 
14
16
  export const acceptDocumentAndMedia = ".doc, .docx, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, video/*, application/pdf, .pdf, .txt, audio/*, image/*, .csv, text/csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, text/plain, text/html";
15
17
 
@@ -30,16 +32,9 @@ export type UploadedFiles = CustomEvent<{ files: IUploadedFile[], extra: any}>;
30
32
  styled.css `
31
33
  display: inline-grid;
32
34
  grid-template-rows: auto auto;
33
- grid-template-columns: auto 1fr auto;
34
-
35
- & > [data-element=preview] {
36
- grid-row: 1 / span 2;
37
- grid-column: 1;
38
- }
39
35
 
40
36
  & > [data-element=file-name] {
41
37
  grid-row: 1;
42
- grid-column: 2;
43
38
  overflow: hidden;
44
39
  white-space: nowrap;
45
40
  text-overflow: ellipsis;
@@ -47,14 +42,9 @@ export type UploadedFiles = CustomEvent<{ files: IUploadedFile[], extra: any}>;
47
42
 
48
43
  & > [data-element=progress] {
49
44
  grid-row: 2;
50
- grid-column: 2 / span 2;
51
45
  width: 100%;
52
46
  }
53
47
 
54
- & > [data-element=delete] {
55
- grid-row: 1;
56
- grid-column: 3;
57
- }
58
48
  `.installGlobal("[data-attachment-file]");
59
49
 
60
50
  export interface IFileUpload {
@@ -64,12 +54,13 @@ export interface IFileUpload {
64
54
  }
65
55
 
66
56
  @DISingleton()
67
- export default class LocalFileService {
57
+ export default class LocalFileService extends TaskManager {
68
58
 
69
59
  @Inject
70
60
  private app: App;
71
61
 
72
62
  constructor() {
63
+ super();
73
64
  document.body.addEventListener("uploadRequested", (ce: CustomEvent) => {
74
65
  const { target, detail: { files, extra, uploadEvent } } = ce;
75
66
  ce.preventDefault();
@@ -165,14 +156,35 @@ export default class LocalFileService {
165
156
  });
166
157
  }
167
158
 
168
- async upload(files: File[], extra: any, ct?: CancelToken) {
169
- return files.map((file) => {
159
+ upload(files: File[], extra: any, ct?: CancelToken) {
160
+
161
+ const { parentID } = extra;
162
+
163
+ const tasks = [] as IFileUpload[];
164
+ const upload = {
165
+ total: 0,
166
+ tasks,
167
+ progress:0
168
+ };
169
+ for (const file of files) {
170
+ upload.total += file.size;
170
171
  const uploadFile: IFileUpload = {
171
- name: file.name
172
+ name: file.name,
173
+ progress: 0
172
174
  };
173
- uploadFile.promise = this.uploadFile(file, extra, ct, (n) => uploadFile.progress = n);
174
- return uploadFile;
175
- });
175
+ uploadFile.promise = this.run(async () => {
176
+ uploadFile.progress = 0.01;
177
+
178
+ // we will check if file exists and has same sha256?
179
+
180
+ const r = await this.uploadFile(file, extra, ct, (n) => uploadFile.progress = n);
181
+ upload.progress += r.file.size;
182
+ setTimeout(() => tasks.remove(uploadFile), 500);
183
+ return r;
184
+ });
185
+ tasks.push(uploadFile);
186
+ }
187
+ return upload;
176
188
  }
177
189
 
178
190
  }
@@ -197,17 +209,27 @@ class FileUploadWindow extends PopupWindow {
197
209
  await this.requestCancel();
198
210
  }, null, { capture: true });
199
211
 
200
- this.files = await this.localFileService.upload(this.parameters.files, this.parameters.extra, this.cancelToken);
212
+ const task = this.localFileService.upload(this.parameters.files, this.parameters.extra, this.cancelToken);
213
+ this.files = task.tasks;
214
+
215
+ this.footerRenderer = () => <div data-layout="command-row">
216
+ <progress min={0} max={task.total} value={Bind.source(task, (x) => x.source.progress)}/>
217
+ </div>;
201
218
 
202
- this.render(<div>
219
+ this.render(<div
220
+ data-overflow="auto"
221
+ style-max-height="500px"
222
+ style-max-width="400px">
203
223
  <AtomRepeater
224
+ data-layout="vertical-flex-stretch-items"
204
225
  items={this.files}
205
226
  itemRenderer={(file) =>
206
227
  <div data-attachment-file="file">
207
228
  <div data-element="file-name" text={file.name}/>
208
229
  <progress
230
+ style-display={Bind.source(file, (x) => x.source.progress > 0)}
209
231
  min={0}
210
- max={100}
232
+ max={1}
211
233
  value={Bind.source(file, (x) => x.source.progress)}/>
212
234
  </div>}
213
235
  />