@holochain-open-dev/file-storage 0.1.4 → 0.2.1
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/elements/file-storage-context.d.ts +1 -1
- package/dist/elements/file-storage-context.js +8 -4
- package/dist/elements/file-storage-context.js.map +1 -1
- package/dist/elements/show-image.d.ts +4 -13
- package/dist/elements/show-image.js +8 -16
- package/dist/elements/show-image.js.map +1 -1
- package/dist/elements/upload-files.d.ts +39 -8
- package/dist/elements/upload-files.js +85 -35
- package/dist/elements/upload-files.js.map +1 -1
- package/dist/index.d.ts +4 -7
- package/dist/index.js +4 -7
- package/dist/index.js.map +1 -1
- package/package.json +5 -9
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LitElement } from "lit";
|
|
2
|
-
import { FileStorageClient } from "../file-storage-client";
|
|
2
|
+
import { FileStorageClient } from "../file-storage-client.js";
|
|
3
3
|
export declare class FileStorageContext extends LitElement {
|
|
4
4
|
client: FileStorageClient;
|
|
5
5
|
render(): import("lit-html").TemplateResult<1>;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { css, html, LitElement } from "lit";
|
|
3
3
|
import { provide } from "@lit-labs/context";
|
|
4
|
-
import { property } from "lit/decorators.js";
|
|
5
|
-
import { fileStorageClientContext } from "../context";
|
|
6
|
-
|
|
4
|
+
import { property, customElement } from "lit/decorators.js";
|
|
5
|
+
import { fileStorageClientContext } from "../context.js";
|
|
6
|
+
let FileStorageContext = class FileStorageContext extends LitElement {
|
|
7
7
|
render() {
|
|
8
8
|
return html `<slot></slot>`;
|
|
9
9
|
}
|
|
10
|
-
}
|
|
10
|
+
};
|
|
11
11
|
FileStorageContext.styles = css `
|
|
12
12
|
:host {
|
|
13
13
|
display: contents;
|
|
@@ -17,4 +17,8 @@ __decorate([
|
|
|
17
17
|
provide({ context: fileStorageClientContext }),
|
|
18
18
|
property({ type: Object })
|
|
19
19
|
], FileStorageContext.prototype, "client", void 0);
|
|
20
|
+
FileStorageContext = __decorate([
|
|
21
|
+
customElement("file-storage-context")
|
|
22
|
+
], FileStorageContext);
|
|
23
|
+
export { FileStorageContext };
|
|
20
24
|
//# sourceMappingURL=file-storage-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-storage-context.js","sourceRoot":"","sources":["../../src/elements/file-storage-context.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"file-storage-context.js","sourceRoot":"","sources":["../../src/elements/file-storage-context.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAE5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAIlD,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,UAAU;IAKhD,MAAM;QACJ,OAAO,IAAI,CAAA,eAAe,CAAC;IAC7B,CAAC;;AAEM,yBAAM,GAAG,GAAG,CAAA;;;;GAIlB,CAAC;AAVF;IAFC,OAAO,CAAC,EAAE,OAAO,EAAE,wBAAwB,EAAE,CAAC;IAC9C,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;kDACA;AAHhB,kBAAkB;IAD9B,aAAa,CAAC,sBAAsB,CAAC;GACzB,kBAAkB,CAc9B;SAdY,kBAAkB","sourcesContent":["import { css, html, LitElement } from \"lit\";\nimport { provide } from \"@lit-labs/context\";\nimport { property, customElement } from \"lit/decorators.js\";\n\nimport { fileStorageClientContext } from \"../context.js\";\nimport { FileStorageClient } from \"../file-storage-client.js\";\n\n@customElement(\"file-storage-context\")\nexport class FileStorageContext extends LitElement {\n @provide({ context: fileStorageClientContext })\n @property({ type: Object })\n client!: FileStorageClient;\n\n render() {\n return html`<slot></slot>`;\n }\n\n static styles = css`\n :host {\n display: contents;\n }\n `;\n}\n"]}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { LitElement } from "lit";
|
|
2
|
-
import
|
|
2
|
+
import "@shoelace-style/shoelace/dist/components/spinner/spinner.js";
|
|
3
|
+
import "@holochain-open-dev/elements/elements/display-error.js";
|
|
3
4
|
import { EntryHash } from "@holochain/client";
|
|
4
5
|
import { Task } from "@lit-labs/task";
|
|
5
|
-
import { CircularProgress } from "@scoped-elements/material-web";
|
|
6
6
|
import { FileStorageClient } from "../file-storage-client";
|
|
7
|
-
declare const ShowImage_base: typeof LitElement & import("@open-wc/dedupe-mixin").Constructor<import("@open-wc/scoped-elements/types/src/types").ScopedElementsHost>;
|
|
8
7
|
/**
|
|
9
8
|
* @fires file-uploaded - Fired after having uploaded the file
|
|
10
9
|
* @csspart dropzone - Style the dropzone itself
|
|
11
10
|
*/
|
|
12
|
-
export declare class ShowImage extends
|
|
11
|
+
export declare class ShowImage extends LitElement {
|
|
13
12
|
/** Public attributes */
|
|
14
13
|
/**
|
|
15
14
|
* REQUIRED. The hash of the image to be rendered
|
|
@@ -25,13 +24,5 @@ export declare class ShowImage extends ShowImage_base {
|
|
|
25
24
|
_renderImage: Task<Uint8Array[], [File, Uint8Array]>;
|
|
26
25
|
renderImage(file: File, data: Uint8Array): import("lit-html").TemplateResult<1>;
|
|
27
26
|
render(): unknown;
|
|
28
|
-
static get styles(): import("lit").CSSResult[];
|
|
29
|
-
/**
|
|
30
|
-
* @internal
|
|
31
|
-
*/
|
|
32
|
-
static get scopedElements(): {
|
|
33
|
-
"mwc-circular-progress": typeof CircularProgress;
|
|
34
|
-
"display-error": typeof DisplayError;
|
|
35
|
-
};
|
|
27
|
+
static get styles(): (import("lit").CSSResult | import("lit").CSSResult[])[];
|
|
36
28
|
}
|
|
37
|
-
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { css, html, LitElement } from "lit";
|
|
3
|
-
import { property } from "lit/decorators.js";
|
|
4
|
-
import {
|
|
5
|
-
import { ScopedElementsMixin } from "@open-wc/scoped-elements";
|
|
3
|
+
import { property, customElement } from "lit/decorators.js";
|
|
4
|
+
import { hashProperty, sharedStyles } from "@holochain-open-dev/elements";
|
|
6
5
|
import { consume } from "@lit-labs/context";
|
|
6
|
+
import "@shoelace-style/shoelace/dist/components/spinner/spinner.js";
|
|
7
|
+
import "@holochain-open-dev/elements/elements/display-error.js";
|
|
7
8
|
import { Task } from "@lit-labs/task";
|
|
8
|
-
import { CircularProgress } from "@scoped-elements/material-web";
|
|
9
9
|
import { fromUint8Array } from "js-base64";
|
|
10
10
|
import { localized, msg } from "@lit/localize";
|
|
11
11
|
import { fileStorageClientContext } from "../context";
|
|
@@ -13,7 +13,7 @@ import { fileStorageClientContext } from "../context";
|
|
|
13
13
|
* @fires file-uploaded - Fired after having uploaded the file
|
|
14
14
|
* @csspart dropzone - Style the dropzone itself
|
|
15
15
|
*/
|
|
16
|
-
let ShowImage = class ShowImage extends
|
|
16
|
+
let ShowImage = class ShowImage extends LitElement {
|
|
17
17
|
constructor() {
|
|
18
18
|
/** Public attributes */
|
|
19
19
|
super(...arguments);
|
|
@@ -33,7 +33,7 @@ let ShowImage = class ShowImage extends ScopedElementsMixin(LitElement) {
|
|
|
33
33
|
return this._renderImage.render({
|
|
34
34
|
complete: ([f, d]) => this.renderImage(f, d),
|
|
35
35
|
pending: () => html `<div class="row center-content" style="flex: 1">
|
|
36
|
-
<
|
|
36
|
+
<sl-spinner style="font-size: 2rem"></sl-spinner>
|
|
37
37
|
</div>`,
|
|
38
38
|
error: (e) => html `<display-error
|
|
39
39
|
.headline=${msg("Error fetching the image")}
|
|
@@ -51,15 +51,6 @@ let ShowImage = class ShowImage extends ScopedElementsMixin(LitElement) {
|
|
|
51
51
|
`,
|
|
52
52
|
];
|
|
53
53
|
}
|
|
54
|
-
/**
|
|
55
|
-
* @internal
|
|
56
|
-
*/
|
|
57
|
-
static get scopedElements() {
|
|
58
|
-
return {
|
|
59
|
-
"mwc-circular-progress": CircularProgress,
|
|
60
|
-
"display-error": DisplayError,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
54
|
};
|
|
64
55
|
__decorate([
|
|
65
56
|
property(hashProperty("image-hash"))
|
|
@@ -68,7 +59,8 @@ __decorate([
|
|
|
68
59
|
consume({ context: fileStorageClientContext })
|
|
69
60
|
], ShowImage.prototype, "client", void 0);
|
|
70
61
|
ShowImage = __decorate([
|
|
71
|
-
localized()
|
|
62
|
+
localized(),
|
|
63
|
+
customElement("show-image")
|
|
72
64
|
], ShowImage);
|
|
73
65
|
export { ShowImage };
|
|
74
66
|
//# sourceMappingURL=show-image.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"show-image.js","sourceRoot":"","sources":["../../src/elements/show-image.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"show-image.js","sourceRoot":"","sources":["../../src/elements/show-image.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,6DAA6D,C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;SACrB,CAAC,CAAC;IACL,CAAC;IAED,MAAM,KAAK,MAAM;QACf,OAAO;YACL,YAAY;YACZ,GAAG,CAAA;;;;;OAKF;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AArDuC;IAArC,QAAQ,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;4CAAuB;AAM5D;IADC,OAAO,CAAC,EAAE,OAAO,EAAE,wBAAwB,EAAE,CAAC;yCACpB;AAZhB,SAAS;IAFrB,SAAS,EAAE;IACX,aAAa,CAAC,YAAY,CAAC;GACf,SAAS,CA2DrB;SA3DY,SAAS","sourcesContent":["import { css, html, LitElement } from \"lit\";\nimport { property, customElement } from \"lit/decorators.js\";\nimport { hashProperty, sharedStyles } from \"@holochain-open-dev/elements\";\nimport { consume } from \"@lit-labs/context\";\n\nimport \"@shoelace-style/shoelace/dist/components/spinner/spinner.js\";\nimport \"@holochain-open-dev/elements/elements/display-error.js\";\n\nimport { EntryHash } from \"@holochain/client\";\nimport { Task } from \"@lit-labs/task\";\nimport { fromUint8Array } from \"js-base64\";\nimport { localized, msg } from \"@lit/localize\";\n\nimport { FileStorageClient } from \"../file-storage-client\";\nimport { fileStorageClientContext } from \"../context\";\n\n/**\n * @fires file-uploaded - Fired after having uploaded the file\n * @csspart dropzone - Style the dropzone itself\n */\n@localized()\n@customElement(\"show-image\")\nexport class ShowImage extends LitElement {\n /** Public attributes */\n\n /**\n * REQUIRED. The hash of the image to be rendered\n */\n @property(hashProperty(\"image-hash\")) imageHash!: EntryHash;\n\n /**\n * @internal\n */\n @consume({ context: fileStorageClientContext })\n client!: FileStorageClient;\n\n /**\n * @internal\n */\n _renderImage = new Task(\n this,\n async ([fileHash]) => {\n const file = await this.client.downloadFile(fileHash);\n const data = await file.arrayBuffer();\n\n return [file, new Uint8Array(data)] as [File, Uint8Array];\n },\n () => [this.imageHash]\n );\n\n renderImage(file: File, data: Uint8Array) {\n return html`<img src=\"data:${file.type};base64,${fromUint8Array(\n data\n )}\" style=\"flex: 1; object-fit: cover\"></img>`;\n }\n\n render() {\n return this._renderImage.render({\n complete: ([f, d]) => this.renderImage(f, d),\n pending: () =>\n html`<div class=\"row center-content\" style=\"flex: 1\">\n <sl-spinner style=\"font-size: 2rem\"></sl-spinner>\n </div>`,\n error: (e: any) =>\n html`<display-error\n .headline=${msg(\"Error fetching the image\")}\n ></display-error>`,\n });\n }\n\n static get styles() {\n return [\n sharedStyles,\n css`\n :host {\n display: flex;\n flex: 1;\n }\n `,\n ];\n }\n}\n"]}
|
|
@@ -1,11 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
/// <reference types="dropzone" />
|
|
2
|
+
import { DropzoneElement, DropzoneOptions } from "@scoped-elements/dropzone";
|
|
3
|
+
import { FormField, FormFieldController } from "@holochain-open-dev/elements";
|
|
4
|
+
import { FileStorageClient } from "../file-storage-client.js";
|
|
5
|
+
import { EntryHash } from "@holochain/client";
|
|
4
6
|
/**
|
|
5
7
|
* @fires file-uploaded - Fired after having uploaded the file
|
|
6
8
|
* @csspart dropzone - Style the dropzone itself
|
|
7
9
|
*/
|
|
8
|
-
export declare class UploadFiles extends
|
|
10
|
+
export declare class UploadFiles extends DropzoneElement implements FormField {
|
|
11
|
+
/**
|
|
12
|
+
* The name of the field if this element is used inside a form
|
|
13
|
+
* Required only if the element is used inside a form
|
|
14
|
+
*/
|
|
15
|
+
name: string;
|
|
16
|
+
/**
|
|
17
|
+
* Whether this field is required if this element is used inside a form
|
|
18
|
+
*/
|
|
19
|
+
required: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Whether this field is disabled if this element is used inside a form
|
|
22
|
+
*/
|
|
23
|
+
disabled: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The default value that this element will take if it is resetted in a form
|
|
26
|
+
*/
|
|
27
|
+
defaultValue: EntryHash | Array<EntryHash>;
|
|
9
28
|
/** Public attributes */
|
|
10
29
|
/**
|
|
11
30
|
* Whether this element should allow only file to be uploaded
|
|
@@ -20,9 +39,21 @@ export declare class UploadFiles extends UploadFiles_base {
|
|
|
20
39
|
* @internal
|
|
21
40
|
*/
|
|
22
41
|
_client: FileStorageClient;
|
|
23
|
-
|
|
24
|
-
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
_controller: FormFieldController;
|
|
46
|
+
firstUpdated(): Promise<void>;
|
|
47
|
+
reset(): void;
|
|
48
|
+
/**
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
get value(): any;
|
|
52
|
+
/**
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
private _input;
|
|
56
|
+
reportValidity(): boolean;
|
|
57
|
+
buildDropzone(dropzoneElement: HTMLElement, options: DropzoneOptions): import("dropzone");
|
|
25
58
|
render(): import("lit-html").TemplateResult<1>;
|
|
26
|
-
static get styles(): import("lit").CSSResult[];
|
|
27
59
|
}
|
|
28
|
-
export {};
|
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
-
import {
|
|
3
|
-
import { property } from "lit/decorators.js";
|
|
4
|
-
import { ScopedElementsMixin } from "@open-wc/scoped-elements";
|
|
2
|
+
import { html } from "lit";
|
|
3
|
+
import { customElement, property, query } from "lit/decorators.js";
|
|
5
4
|
import { DropzoneElement } from "@scoped-elements/dropzone";
|
|
6
5
|
import { consume } from "@lit-labs/context";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { fileStorageClientContext } from "../context";
|
|
6
|
+
import { FormFieldController } from "@holochain-open-dev/elements";
|
|
7
|
+
import { localized } from "@lit/localize";
|
|
8
|
+
import { fileStorageClientContext } from "../context.js";
|
|
9
|
+
import { HolochainDropzone } from "../holochain-dropzone.js";
|
|
10
10
|
/**
|
|
11
11
|
* @fires file-uploaded - Fired after having uploaded the file
|
|
12
12
|
* @csspart dropzone - Style the dropzone itself
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
let UploadFiles = class UploadFiles extends DropzoneElement {
|
|
15
15
|
constructor() {
|
|
16
|
-
/** Public attributes */
|
|
17
16
|
super(...arguments);
|
|
17
|
+
/**
|
|
18
|
+
* Whether this field is required if this element is used inside a form
|
|
19
|
+
*/
|
|
20
|
+
this.required = false;
|
|
21
|
+
/**
|
|
22
|
+
* Whether this field is disabled if this element is used inside a form
|
|
23
|
+
*/
|
|
24
|
+
this.disabled = false;
|
|
25
|
+
/** Public attributes */
|
|
18
26
|
/**
|
|
19
27
|
* Whether this element should allow only file to be uploaded
|
|
20
28
|
*/
|
|
@@ -24,40 +32,74 @@ export class UploadFiles extends ScopedElementsMixin(LitElement) {
|
|
|
24
32
|
* Learn how to use this here: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept
|
|
25
33
|
*/
|
|
26
34
|
this.acceptedFiles = undefined;
|
|
35
|
+
/**
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
this._controller = new FormFieldController(this);
|
|
27
39
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return new HolochainDropzone(dropzoneElement, client, options);
|
|
40
|
+
async firstUpdated() {
|
|
41
|
+
super.firstUpdated();
|
|
42
|
+
if (this.defaultValue !== undefined) {
|
|
43
|
+
if (Array.isArray(this.defaultValue)) {
|
|
44
|
+
for (const fileHash of this.defaultValue) {
|
|
45
|
+
const image = await this._client.downloadFile(fileHash);
|
|
46
|
+
this.dropzone.addFile(image);
|
|
47
|
+
}
|
|
37
48
|
}
|
|
38
|
-
|
|
49
|
+
else {
|
|
50
|
+
const image = await this._client.downloadFile(this.defaultValue);
|
|
51
|
+
this.dropzone.addFile(image);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
reset() {
|
|
56
|
+
this.clear();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
get value() {
|
|
62
|
+
if (this.oneFile)
|
|
63
|
+
return this.dropzone.files[0]
|
|
64
|
+
? this.dropzone.files[0].hash
|
|
65
|
+
: undefined;
|
|
66
|
+
return this.dropzone.files.map((file) => file.hash);
|
|
67
|
+
}
|
|
68
|
+
reportValidity() {
|
|
69
|
+
const invalid = this.required !== false && this.value === undefined;
|
|
70
|
+
if (invalid) {
|
|
71
|
+
this._input.setCustomValidity(`Uploading a file is required`);
|
|
72
|
+
this._input.reportValidity();
|
|
73
|
+
}
|
|
74
|
+
return !invalid;
|
|
75
|
+
}
|
|
76
|
+
buildDropzone(dropzoneElement, options) {
|
|
77
|
+
return new HolochainDropzone(dropzoneElement, this._client, options);
|
|
39
78
|
}
|
|
40
79
|
render() {
|
|
41
80
|
return html `
|
|
42
|
-
<
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
81
|
+
<div style="position:relative">
|
|
82
|
+
<input
|
|
83
|
+
id="hidden-input"
|
|
84
|
+
style="width:0; height: 0; position: absolute; z-index: -1; left: 50%; top: 20%"
|
|
85
|
+
/>
|
|
86
|
+
${super.render()}
|
|
87
|
+
</div>
|
|
48
88
|
`;
|
|
49
89
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
90
|
+
};
|
|
91
|
+
__decorate([
|
|
92
|
+
property()
|
|
93
|
+
], UploadFiles.prototype, "name", void 0);
|
|
94
|
+
__decorate([
|
|
95
|
+
property()
|
|
96
|
+
], UploadFiles.prototype, "required", void 0);
|
|
97
|
+
__decorate([
|
|
98
|
+
property()
|
|
99
|
+
], UploadFiles.prototype, "disabled", void 0);
|
|
100
|
+
__decorate([
|
|
101
|
+
property()
|
|
102
|
+
], UploadFiles.prototype, "defaultValue", void 0);
|
|
61
103
|
__decorate([
|
|
62
104
|
property({ type: Boolean, attribute: "one-file" })
|
|
63
105
|
], UploadFiles.prototype, "oneFile", void 0);
|
|
@@ -67,4 +109,12 @@ __decorate([
|
|
|
67
109
|
__decorate([
|
|
68
110
|
consume({ context: fileStorageClientContext })
|
|
69
111
|
], UploadFiles.prototype, "_client", void 0);
|
|
112
|
+
__decorate([
|
|
113
|
+
query("#hidden-input")
|
|
114
|
+
], UploadFiles.prototype, "_input", void 0);
|
|
115
|
+
UploadFiles = __decorate([
|
|
116
|
+
localized(),
|
|
117
|
+
customElement("upload-files")
|
|
118
|
+
], UploadFiles);
|
|
119
|
+
export { UploadFiles };
|
|
70
120
|
//# sourceMappingURL=upload-files.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload-files.js","sourceRoot":"","sources":["../../src/elements/upload-files.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"upload-files.js","sourceRoot":"","sources":["../../src/elements/upload-files.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EAAE,eAAe,EAAmB,MAAM,2BAA2B,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAa,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG1C,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAG7D;;;GAGG;AAGI,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,eAAe;IAAzC;;QAQL;;WAEG;QAEH,aAAQ,GAAG,KAAK,CAAC;QAEjB;;WAEG;QAEH,aAAQ,GAAG,KAAK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O,GAAG,IAAI,CAAC,QAAQ,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC;QACpE,IAAI,OAAO,EAAE;YACX,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,8BAA8B,CAAC,CAAC;YAC9D,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;SAC9B;QAED,OAAO,CAAC,OAAO,CAAC;IAClB,CAAC;IAED,aAAa,CAAC,eAA4B,EAAE,OAAwB;QAClE,OAAO,IAAI,iBAAiB,CAC1B,eAAe,EACf,IAAI,CAAC,OAAO,EACZ,OAAO,CACW,CAAC;IACvB,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAA;;;;;;UAML,KAAK,CAAC,MAAM,EAAE;;KAEnB,CAAC;IACJ,CAAC;CACF,CAAA;AA/GC;IADC,QAAQ,EAAE;yCACG;AAMd;IADC,QAAQ,EAAE;6CACM;AAMjB;IADC,QAAQ,EAAE;6CACM;AAMjB;IADC,QAAQ,EAAE;iDACiC;AAOQ;IAAnD,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;4CAAiB;AAMX;IAAxD,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC;kDAE9B;AAM1B;IADC,OAAO,CAAC,EAAE,OAAO,EAAE,wBAAwB,EAAE,CAAC;4CACnB;AAyC5B;IADC,KAAK,CAAC,eAAe,CAAC;2CACW;AAtFvB,WAAW;IAFvB,SAAS,EAAE;IACX,aAAa,CAAC,cAAc,CAAC;GACjB,WAAW,CAqHvB;SArHY,WAAW","sourcesContent":["import { html } from \"lit\";\nimport { customElement, property, query } from \"lit/decorators.js\";\n\nimport { DropzoneElement, DropzoneOptions } from \"@scoped-elements/dropzone\";\nimport { consume } from \"@lit-labs/context\";\nimport { FormField, FormFieldController } from \"@holochain-open-dev/elements\";\nimport { localized } from \"@lit/localize\";\n\nimport { FileStorageClient } from \"../file-storage-client.js\";\nimport { fileStorageClientContext } from \"../context.js\";\nimport { HolochainDropzone } from \"../holochain-dropzone.js\";\nimport { EntryHash } from \"@holochain/client\";\n\n/**\n * @fires file-uploaded - Fired after having uploaded the file\n * @csspart dropzone - Style the dropzone itself\n */\n@localized()\n@customElement(\"upload-files\")\nexport class UploadFiles extends DropzoneElement implements FormField {\n /**\n * The name of the field if this element is used inside a form\n * Required only if the element is used inside a form\n */\n @property()\n name!: string;\n\n /**\n * Whether this field is required if this element is used inside a form\n */\n @property()\n required = false;\n\n /**\n * Whether this field is disabled if this element is used inside a form\n */\n @property()\n disabled = false;\n\n /**\n * The default value that this element will take if it is resetted in a form\n */\n @property()\n defaultValue!: EntryHash | Array<EntryHash>;\n\n /** Public attributes */\n\n /**\n * Whether this element should allow only file to be uploaded\n */\n @property({ type: Boolean, attribute: \"one-file\" }) oneFile = false;\n\n /**\n * The type of files accepted by this element\n * Learn how to use this here: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept\n */\n @property({ type: String, attribute: \"accepted-files\" }) acceptedFiles:\n | string\n | undefined = undefined;\n\n /**\n * @internal\n */\n @consume({ context: fileStorageClientContext })\n _client!: FileStorageClient;\n\n /**\n * @internal\n */\n _controller = new FormFieldController(this);\n\n async firstUpdated() {\n super.firstUpdated();\n if (this.defaultValue !== undefined) {\n if (Array.isArray(this.defaultValue)) {\n for (const fileHash of this.defaultValue) {\n const image = await this._client.downloadFile(fileHash);\n this.dropzone.addFile(image as any);\n }\n } else {\n const image = await this._client.downloadFile(this.defaultValue);\n this.dropzone.addFile(image as any);\n }\n }\n }\n\n reset() {\n this.clear();\n }\n\n /**\n * @internal\n */\n get value() {\n if (this.oneFile)\n return this.dropzone.files[0]\n ? (this.dropzone.files[0] as any).hash\n : undefined;\n return this.dropzone.files.map((file) => (file as any).hash);\n }\n\n /**\n * @internal\n */\n @query(\"#hidden-input\")\n private _input!: HTMLInputElement;\n\n reportValidity() {\n const invalid = this.required !== false && this.value === undefined;\n if (invalid) {\n this._input.setCustomValidity(`Uploading a file is required`);\n this._input.reportValidity();\n }\n\n return !invalid;\n }\n\n buildDropzone(dropzoneElement: HTMLElement, options: DropzoneOptions) {\n return new HolochainDropzone(\n dropzoneElement,\n this._client,\n options\n ) as any as Dropzone;\n }\n\n render() {\n return html`\n <div style=\"position:relative\">\n <input\n id=\"hidden-input\"\n style=\"width:0; height: 0; position: absolute; z-index: -1; left: 50%; top: 20%\"\n />\n ${super.render()}\n </div>\n `;\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./holochain-dropzone";
|
|
6
|
-
export * from "./types";
|
|
7
|
-
export * from "./context";
|
|
1
|
+
export * from "./file-storage-client.js";
|
|
2
|
+
export * from "./holochain-dropzone.js";
|
|
3
|
+
export * from "./types.js";
|
|
4
|
+
export * from "./context.js";
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./holochain-dropzone";
|
|
6
|
-
export * from "./types";
|
|
7
|
-
export * from "./context";
|
|
1
|
+
export * from "./file-storage-client.js";
|
|
2
|
+
export * from "./holochain-dropzone.js";
|
|
3
|
+
export * from "./types.js";
|
|
4
|
+
export * from "./context.js";
|
|
8
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC","sourcesContent":["export * from \"./file-storage-client.js\";\nexport * from \"./holochain-dropzone.js\";\nexport * from \"./types.js\";\nexport * from \"./context.js\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holochain-open-dev/file-storage",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "File storage utilities to store and retrieve files in a holochain DHT",
|
|
5
5
|
"author": "guillem.cordoba@gmail.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,10 +8,8 @@
|
|
|
8
8
|
"module": "dist/index.js",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": "./dist/index.js",
|
|
11
|
-
"./file-storage-context": "./dist/definitions/file-storage-context.js",
|
|
12
|
-
"./upload-files": "./dist/definitions/upload-files.js",
|
|
13
11
|
"./mocks": "./dist/mocks.js",
|
|
14
|
-
"./
|
|
12
|
+
"./elements/*": "./dist/elements/*"
|
|
15
13
|
},
|
|
16
14
|
"files": ["dist"],
|
|
17
15
|
"scripts": {
|
|
@@ -22,16 +20,14 @@
|
|
|
22
20
|
"format": "eslint --ext .ts,.html src --fix --ignore-path .gitignore"
|
|
23
21
|
},
|
|
24
22
|
"dependencies": {
|
|
25
|
-
"@holochain-open-dev/elements": "^0.
|
|
23
|
+
"@holochain-open-dev/elements": "^0.3.0",
|
|
26
24
|
"@holochain-open-dev/utils": "^0.12.0",
|
|
27
25
|
"@holochain/client": "^0.12.0",
|
|
28
26
|
"@lit-labs/context": "^0.2.0",
|
|
29
27
|
"@lit-labs/task": "^2.0.0",
|
|
30
28
|
"@lit/localize": "^0.11.4",
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
33
|
-
"@scoped-elements/material-web": "^0.1.7",
|
|
34
|
-
"@scoped-elements/shoelace": "^0.1.0",
|
|
29
|
+
"@scoped-elements/dropzone": "^0.1.3",
|
|
30
|
+
"@shoelace-style/shoelace": "^2.3.0",
|
|
35
31
|
"lit": "^2.6.0"
|
|
36
32
|
},
|
|
37
33
|
"devDependencies": {
|