@dile/crud 0.1.1 → 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.
@@ -0,0 +1,2 @@
1
+ import { DileImageUploaderForm } from './src/DileImageUploaderForm.js';
2
+ customElements.define('dile-image-uploader-form', DileImageUploaderForm);
@@ -0,0 +1,2 @@
1
+ import { DileImageUploader } from './src/DileImageUploader.js';
2
+ customElements.define('dile-image-uploader', DileImageUploader);
@@ -0,0 +1,2 @@
1
+ export { DileImageUploaderForm } from './src/DileImageUploaderForm.js';
2
+ export { DileImageUploader } from './src/DileImageUploader.js';
@@ -0,0 +1,70 @@
1
+ import { LitElement, html, css } from 'lit';
2
+ import '../../ajax-form/ajax-form.js';
3
+ import '../image-uploader-form.js';
4
+ import { ResponseApiAdapter } from '../../../lib/ResponseApiAdapter.js';
5
+ import { DileI18nMixin } from '../../../lib/DileI18nMixin.js';
6
+
7
+ export class DileImageUploader extends DileI18nMixin(LitElement) {
8
+ static styles = [
9
+ css`
10
+ :host {
11
+ display: block;
12
+ }
13
+ `
14
+ ];
15
+
16
+ static get properties() {
17
+ return {
18
+ endpoint: { type: String },
19
+ selectImageLabel: { type: String },
20
+ saveLabel: { type: String },
21
+ allowedExtensions: { type: Array },
22
+ responseAdapter: { type: Object },
23
+ };
24
+ }
25
+
26
+ constructor() {
27
+ super();
28
+ this.responseAdapter = new ResponseApiAdapter();
29
+ this.allowedExtensions = ['jpeg', 'jpg', 'png'];
30
+ }
31
+
32
+ render() {
33
+ return html`
34
+ <dile-ajax-form
35
+ id="elform"
36
+ operation="insert"
37
+ endpoint=${this.endpoint}
38
+ actionLabel="${this.saveLabelComputed(this.saveLabel, this.translations)}"
39
+ sendDataAsFormData
40
+ language="es"
41
+ @save-success=${this.imageSaveSuccess}
42
+ .responseAdapter=${this.responseAdapter}
43
+ >
44
+ <dile-image-uploader-form
45
+ id="form"
46
+ label="${this.selectLabelComputed(this.selectImageLabel, this.translations)}"
47
+ .allowedExtensions=${this.allowedExtensions}
48
+ .translations=${this.translations}
49
+ ></dile-image-uploader-form>
50
+ </dile-ajax-form>
51
+ `;
52
+ }
53
+
54
+ selectLabelComputed(label, translations) {
55
+ return label ? label : translations?.select_image ? translations.select_image : 'Select an image';
56
+ }
57
+
58
+ saveLabelComputed(label, translations) {
59
+ return label ? label : translations?.save_image ? translations.save_image : 'Save image';
60
+ }
61
+
62
+ imageSaveSuccess(e) {
63
+ this.dispatchEvent(new CustomEvent('image-uploaded', {
64
+ bubbles: true,
65
+ composed: true,
66
+ detail: e.detail
67
+ }));
68
+ }
69
+
70
+ }
@@ -0,0 +1,39 @@
1
+ import { LitElement, html, css } from 'lit';
2
+ import { DileForm } from '@dile/ui/mixins/form/index.js'
3
+ import "@dile/ui/components/drop-file/drop-file.js"
4
+
5
+ export class DileImageUploaderForm extends DileForm(LitElement) {
6
+ static styles = [
7
+ css`
8
+ :host {
9
+ display: block;
10
+ }
11
+ dile-drop-file {
12
+ margin-bottom: 0;
13
+ }
14
+ `
15
+ ];
16
+
17
+ static get properties() {
18
+ return {
19
+ label: { type: String },
20
+ allowedExtensions: { type: Array },
21
+ translations: { type: Object },
22
+ };
23
+ }
24
+
25
+ render() {
26
+ return html`
27
+ <dile-drop-file
28
+ name="image"
29
+ label="${this.label}"
30
+ id="dropfile"
31
+ .allowedExtensions=${this.allowedExtensions}
32
+ dropLabel="${this.translations.file_drop}"
33
+ buttonLabel="${this.translations.select_file}"
34
+ selectedFileLabel="${this.translations.selected_file}"
35
+ extensionErrorMessage="${this.translations.extension_allowed}"
36
+ ></dile-drop-file>
37
+ `;
38
+ }
39
+ }
package/lib/i18n/en.js CHANGED
@@ -42,5 +42,10 @@ export const translations = {
42
42
  all_in_page: "All in this page",
43
43
  select_matching: "Select all matching",
44
44
  element_actions: "Element actions",
45
-
45
+ select_image: "Select an image",
46
+ save_image: "Save image",
47
+ file_drop: "Drop here your file",
48
+ select_file: "Select file",
49
+ selected_file: "Selected file",
50
+ extension_allowed: "Only this file extensions are allowed: ",
46
51
  };
package/lib/i18n/es.js CHANGED
@@ -42,4 +42,10 @@ export const translations = {
42
42
  all_in_page: "Todos de esta página",
43
43
  select_matching: "Seleccionar coincidentes",
44
44
  element_actions: "Acciones en este ítem",
45
+ select_image: "Selecciona una imagen",
46
+ save_image: "Salvar la imagen",
47
+ file_drop: "Suelta aquí el archivo",
48
+ select_file: "Seleccionar archivo",
49
+ selected_file: "Archivo seleccionado",
50
+ extension_allowed: "Solo se permiten estas extensiones: ",
45
51
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dile/crud",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
4
4
  "description": "Components to create a generic crud system based on Web Components and Lit",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -24,12 +24,12 @@
24
24
  },
25
25
  "homepage": "https://dile-components.polydile.com/",
26
26
  "dependencies": {
27
- "@dile/ui": "^2.1.39",
27
+ "@dile/ui": "^2.2.0",
28
28
  "axios": "^1.7.2",
29
29
  "lit": "^2.7.0 || ^3.0.0"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
- "gitHead": "072d0ecf23ade48c6f33d3dc37b29a209114f08b"
34
+ "gitHead": "5d4e95bced050de218bb3d5a0e489437d9dea8a6"
35
35
  }