@holochain-open-dev/file-storage 0.2.2 → 0.3.0
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LitElement } from "lit";
|
|
2
2
|
import "@shoelace-style/shoelace/dist/components/spinner/spinner.js";
|
|
3
|
-
import "@holochain-open-dev/elements/elements/display-error.js";
|
|
3
|
+
import "@holochain-open-dev/elements/dist/elements/display-error.js";
|
|
4
4
|
import { EntryHash } from "@holochain/client";
|
|
5
5
|
import { Task } from "@lit-labs/task";
|
|
6
6
|
import { FileStorageClient } from "../file-storage-client";
|
|
@@ -4,7 +4,7 @@ import { property, customElement } from "lit/decorators.js";
|
|
|
4
4
|
import { hashProperty, sharedStyles } from "@holochain-open-dev/elements";
|
|
5
5
|
import { consume } from "@lit-labs/context";
|
|
6
6
|
import "@shoelace-style/shoelace/dist/components/spinner/spinner.js";
|
|
7
|
-
import "@holochain-open-dev/elements/elements/display-error.js";
|
|
7
|
+
import "@holochain-open-dev/elements/dist/elements/display-error.js";
|
|
8
8
|
import { Task } from "@lit-labs/task";
|
|
9
9
|
import { fromUint8Array } from "js-base64";
|
|
10
10
|
import { localized, msg } from "@lit/localize";
|
|
@@ -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,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,CAAC;AACrE,OAAO,
|
|
1
|
+
{"version":3,"file":"show-image.js","sourceRoot":"","sources":["../../src/elements/show-image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AAC,MAAM,CAAC;YAC9B,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC;YAC5C,OAAO,EAAE,GAAG,EAAE,CACZ,IAAI,CAAA;;eAEG;YACT,KAAK,EAAE,CAAC,CAAM,EAAE,EAAE,CAChB,IAAI,CAAA;sBACU,GAAG,CAAC,0BAA0B,CAAC;0BAC3B;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/dist/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; overflow: hidden\"></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,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="dropzone" />
|
|
2
|
-
import { DropzoneElement, DropzoneOptions } from
|
|
3
|
-
import { FormField, FormFieldController } from
|
|
4
|
-
import { FileStorageClient } from
|
|
5
|
-
import { EntryHash } from
|
|
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';
|
|
6
6
|
/**
|
|
7
7
|
* @fires file-uploaded - Fired after having uploaded the file
|
|
8
8
|
* @csspart dropzone - Style the dropzone itself
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
|
-
import { html } from
|
|
3
|
-
import { customElement, property, query } from
|
|
4
|
-
import { DropzoneElement } from
|
|
5
|
-
import { consume } from
|
|
6
|
-
import { FormFieldController } from
|
|
7
|
-
import { localized } from
|
|
8
|
-
import { fileStorageClientContext } from
|
|
9
|
-
import { HolochainDropzone } from
|
|
2
|
+
import { html } from 'lit';
|
|
3
|
+
import { customElement, property, query } from 'lit/decorators.js';
|
|
4
|
+
import { DropzoneElement } from '@scoped-elements/dropzone';
|
|
5
|
+
import { consume } from '@lit-labs/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
|
|
@@ -63,7 +63,7 @@ let UploadFiles = class UploadFiles extends DropzoneElement {
|
|
|
63
63
|
return this.dropzone.files[0]
|
|
64
64
|
? this.dropzone.files[0].hash
|
|
65
65
|
: undefined;
|
|
66
|
-
return this.dropzone.files.map(
|
|
66
|
+
return this.dropzone.files.map(file => file.hash);
|
|
67
67
|
}
|
|
68
68
|
reportValidity() {
|
|
69
69
|
const invalid = this.required !== false && this.value === undefined;
|
|
@@ -78,7 +78,7 @@ let UploadFiles = class UploadFiles extends DropzoneElement {
|
|
|
78
78
|
}
|
|
79
79
|
render() {
|
|
80
80
|
return html `
|
|
81
|
-
<div style="position:relative">
|
|
81
|
+
<div style="position: relative; flex: 1">
|
|
82
82
|
<input
|
|
83
83
|
id="hidden-input"
|
|
84
84
|
style="width:0; height: 0; position: absolute; z-index: -1; left: 50%; top: 20%"
|
|
@@ -101,20 +101,20 @@ __decorate([
|
|
|
101
101
|
property()
|
|
102
102
|
], UploadFiles.prototype, "defaultValue", void 0);
|
|
103
103
|
__decorate([
|
|
104
|
-
property({ type: Boolean, attribute:
|
|
104
|
+
property({ type: Boolean, attribute: 'one-file' })
|
|
105
105
|
], UploadFiles.prototype, "oneFile", void 0);
|
|
106
106
|
__decorate([
|
|
107
|
-
property({ type: String, attribute:
|
|
107
|
+
property({ type: String, attribute: 'accepted-files' })
|
|
108
108
|
], UploadFiles.prototype, "acceptedFiles", void 0);
|
|
109
109
|
__decorate([
|
|
110
110
|
consume({ context: fileStorageClientContext })
|
|
111
111
|
], UploadFiles.prototype, "_client", void 0);
|
|
112
112
|
__decorate([
|
|
113
|
-
query(
|
|
113
|
+
query('#hidden-input')
|
|
114
114
|
], UploadFiles.prototype, "_input", void 0);
|
|
115
115
|
UploadFiles = __decorate([
|
|
116
116
|
localized(),
|
|
117
|
-
customElement(
|
|
117
|
+
customElement('upload-files')
|
|
118
118
|
], UploadFiles);
|
|
119
119
|
export { UploadFiles };
|
|
120
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,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,CAAC;QAQjB,wBAAwB;QAExB;;WAEG;QACiD,YAAO,GAAG,KAAK,CAAC;QAEpE;;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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; flex: 1\">\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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holochain-open-dev/file-storage",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
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,8 +8,7 @@
|
|
|
8
8
|
"module": "dist/index.js",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": "./dist/index.js",
|
|
11
|
-
"./
|
|
12
|
-
"./elements/*": "./dist/elements/*"
|
|
11
|
+
"./dist/*": "./dist/*"
|
|
13
12
|
},
|
|
14
13
|
"files": ["dist"],
|
|
15
14
|
"scripts": {
|
|
@@ -20,8 +19,8 @@
|
|
|
20
19
|
"format": "eslint --ext .ts,.html src --fix --ignore-path .gitignore"
|
|
21
20
|
},
|
|
22
21
|
"dependencies": {
|
|
23
|
-
"@holochain-open-dev/elements": "^0.
|
|
24
|
-
"@holochain-open-dev/utils": "^0.
|
|
22
|
+
"@holochain-open-dev/elements": "^0.4.0",
|
|
23
|
+
"@holochain-open-dev/utils": "^0.13.0",
|
|
25
24
|
"@holochain/client": "^0.12.0",
|
|
26
25
|
"@lit-labs/context": "^0.2.0",
|
|
27
26
|
"@lit-labs/task": "^2.0.0",
|