@holochain-open-dev/file-storage 0.2.0 → 0.2.2

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.
@@ -27,7 +27,7 @@ let ShowImage = class ShowImage extends LitElement {
27
27
  }, () => [this.imageHash]);
28
28
  }
29
29
  renderImage(file, data) {
30
- return html `<img src="data:${file.type};base64,${fromUint8Array(data)}" style="flex: 1; object-fit: cover"></img>`;
30
+ return html `<img src="data:${file.type};base64,${fromUint8Array(data)}" style="flex: 1; object-fit: cover; overflow: hidden"></img>`;
31
31
  }
32
32
  render() {
33
33
  return this._renderImage.render({
@@ -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,wDAAwD,CAAC;AAGhE,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAEtD;;;GAGG;AAGI,IAAM,SAAS,GAAf,MAAM,SAAU,SAAQ,UAAU;IAAlC;QACL,wBAAwB;;QAaxB;;WAEG;QACH,iBAAY,GAAG,IAAI,IAAI,CACrB,IAAI,EACJ,KAAK,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE;YACnB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;YACtD,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;YAEtC,OAAO,CAAC,IAAI,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC,CAAuB,CAAC;QAC5D,CAAC,EACD,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CACvB,CAAC;IAiCJ,CAAC;IA/BC,WAAW,CAAC,IAAU,EAAE,IAAgB;QACtC,OAAO,IAAI,CAAA,kBAAkB,IAAI,CAAC,IAAI,WAAW,cAAc,CAC7D,IAAI,CACL,6CAA6C,CAAC;IACjD,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,YAAY,CAAC,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/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
+ {"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,Q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AC,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/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"]}
@@ -24,7 +24,7 @@ export declare class UploadFiles extends DropzoneElement implements FormField {
24
24
  /**
25
25
  * The default value that this element will take if it is resetted in a form
26
26
  */
27
- defaultValue: EntryHash;
27
+ defaultValue: EntryHash | Array<EntryHash>;
28
28
  /** Public attributes */
29
29
  /**
30
30
  * Whether this element should allow only file to be uploaded
@@ -3,7 +3,7 @@ import { html } from "lit";
3
3
  import { customElement, property, query } from "lit/decorators.js";
4
4
  import { DropzoneElement } from "@scoped-elements/dropzone";
5
5
  import { consume } from "@lit-labs/context";
6
- import { FormFieldController, } from "@holochain-open-dev/elements";
6
+ import { FormFieldController } from "@holochain-open-dev/elements";
7
7
  import { localized } from "@lit/localize";
8
8
  import { fileStorageClientContext } from "../context.js";
9
9
  import { HolochainDropzone } from "../holochain-dropzone.js";
@@ -40,8 +40,16 @@ let UploadFiles = class UploadFiles extends DropzoneElement {
40
40
  async firstUpdated() {
41
41
  super.firstUpdated();
42
42
  if (this.defaultValue !== undefined) {
43
- const image = await this._client.downloadFile(this.defaultValue);
44
- this.dropzone.addFile(image);
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
+ }
48
+ }
49
+ else {
50
+ const image = await this._client.downloadFile(this.defaultValue);
51
+ this.dropzone.addFile(image);
52
+ }
45
53
  }
46
54
  }
47
55
  reset() {
@@ -63,7 +71,7 @@ let UploadFiles = class UploadFiles extends DropzoneElement {
63
71
  this._input.setCustomValidity(`Uploading a file is required`);
64
72
  this._input.reportValidity();
65
73
  }
66
- return invalid;
74
+ return !invalid;
67
75
  }
68
76
  buildDropzone(dropzoneElement, options) {
69
77
  return new HolochainDropzone(dropzoneElement, this._client, options);
@@ -1 +1 @@
1
- {"version":3,"file":"upload-files.js","sourceRoot":"","sources":["../../src/elements/upload-files.ts"],"names":[],"mappings":";AAAA,OAAO,EAAO,IAAI,EAAc,MAAM,KAAK,CAAC;AAC5C,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,GAEpB,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,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;;;WAGG;QACsD,kBAAa,GAEtD,SAAS,CAAC;QAQ1B;;WAEG;QACH,gBAAW,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,CAAC;I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,CAAC;CACF,CAAA;AAxGC;IADC,QAAQ,EAAE;yCACG;AAMd;IADC,QAAQ,EAAE;6CACM;AAMjB;IADC,QAAQ,EAAE;6CACM;AAMjB;IADC,QAAQ,EAAE;iDACc;AAO2B;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;AAkC5B;IADC,KAAK,CAAC,eAAe,CAAC;2CACW;AA/EvB,WAAW;IAFvB,SAAS,EAAE;IACX,aAAa,CAAC,cAAc,CAAC;GACjB,WAAW,CA8GvB;SA9GY,WAAW","sourcesContent":["import { css, html, LitElement } 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;\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 const image = await this._client.downloadFile(this.defaultValue);\n this.dropzone.addFile(image as any);\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"]}
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,CA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E,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holochain-open-dev/file-storage",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
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",
@@ -26,7 +26,7 @@
26
26
  "@lit-labs/context": "^0.2.0",
27
27
  "@lit-labs/task": "^2.0.0",
28
28
  "@lit/localize": "^0.11.4",
29
- "@scoped-elements/dropzone": "^0.1.2",
29
+ "@scoped-elements/dropzone": "^0.1.3",
30
30
  "@shoelace-style/shoelace": "^2.3.0",
31
31
  "lit": "^2.6.0"
32
32
  },