@holochain-open-dev/file-storage 0.4.2 → 0.4.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.
@@ -44,7 +44,7 @@ export declare class UploadFiles extends DropzoneElement implements FormField {
44
44
  */
45
45
  _controller: FormFieldController;
46
46
  firstUpdated(): Promise<void>;
47
- reset(): void;
47
+ reset(): Promise<void>;
48
48
  /**
49
49
  * @internal
50
50
  */
@@ -39,6 +39,11 @@ let UploadFiles = class UploadFiles extends DropzoneElement {
39
39
  }
40
40
  async firstUpdated() {
41
41
  super.firstUpdated();
42
+ this.reset();
43
+ }
44
+ async reset() {
45
+ this.dropzone.removeAllFiles(true);
46
+ this.clear();
42
47
  if (this.defaultValue !== undefined) {
43
48
  if (Array.isArray(this.defaultValue)) {
44
49
  for (const fileHash of this.defaultValue) {
@@ -52,10 +57,6 @@ let UploadFiles = class UploadFiles extends DropzoneElement {
52
57
  }
53
58
  }
54
59
  }
55
- reset() {
56
- this.dropzone.removeAllFiles(true);
57
- this.clear();
58
- }
59
60
  /**
60
61
  * @internal
61
62
  */
@@ -1 +1 @@
1
- {"version":3,"file":"upload-files.js","sourceRoot":"","sources":["../../src/elements/upload-files.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAChC,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,EAEL,mBAAmB,EACnB,YAAY,GACb,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG1C,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CA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4CACnB;AA0C5B;IADC,KAAK,CAAC,eAAe,CAAC;2CACW;AAvFvB,WAAW;IAFvB,SAAS,EAAE;IACX,aAAa,CAAC,cAAc,CAAC;GACjB,WAAW,CAiIvB;SAjIY,WAAW","sourcesContent":["import { css, 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 {\n FormField,\n FormFieldController,\n sharedStyles,\n} 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.dropzone.removeAllFiles(true);\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; display: flex\">\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 static get styles() {\n return [\n DropzoneElement.styles,\n sharedStyles,\n css`\n :host {\n display: flex;\n }\n `,\n ];\n }\n}\n"]}
1
+ {"version":3,"file":"upload-files.js","sourceRoot":"","sources":["../../src/elements/upload-files.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAChC,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,EAEL,mBAAmB,EACnB,YAAY,GACb,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,eAA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X;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;AA4C5B;IADC,KAAK,CAAC,eAAe,CAAC;2CACW;AAzFvB,WAAW;IAFvB,SAAS,EAAE;IACX,aAAa,CAAC,cAAc,CAAC;GACjB,WAAW,CAmIvB;SAnIY,WAAW","sourcesContent":["import { css, 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 {\n FormField,\n FormFieldController,\n sharedStyles,\n} 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\n this.reset();\n }\n\n async reset() {\n this.dropzone.removeAllFiles(true);\n this.clear();\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 /**\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; display: flex\">\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 static get styles() {\n return [\n DropzoneElement.styles,\n sharedStyles,\n css`\n :host {\n display: flex;\n }\n `,\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.4.2",
3
+ "version": "0.4.3",
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",
@@ -25,7 +25,7 @@
25
25
  "@lit-labs/context": "^0.2.0",
26
26
  "@lit-labs/task": "^2.0.0",
27
27
  "@lit/localize": "^0.11.4",
28
- "@scoped-elements/dropzone": "^0.2.0",
28
+ "@scoped-elements/dropzone": "^0.2.1",
29
29
  "@shoelace-style/shoelace": "^2.3.0",
30
30
  "lit": "^2.6.0"
31
31
  },