wj-elements 0.2.0-alpha.1 → 0.2.0-alpha.11
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/packages/utils/utils.d.ts +16 -0
- package/dist/packages/wje-chip/chip.element.d.ts +12 -0
- package/dist/packages/wje-chip/chip.test.d.ts +1 -0
- package/dist/packages/wje-file-upload/file-upload.element.d.ts +18 -6
- package/dist/packages/wje-file-upload/file-upload.test.d.ts +1 -0
- package/dist/packages/wje-file-upload/service/service.d.ts +0 -23
- package/dist/packages/wje-file-upload-item/file-upload-item.element.d.ts +25 -8
- package/dist/packages/wje-select/select.element.d.ts +2 -0
- package/dist/packages/wje-toggle/toggle.test.d.ts +1 -0
- package/dist/utils.js +18 -1
- package/dist/utils.js.map +1 -1
- package/dist/wje-chip.js +20 -0
- package/dist/wje-chip.js.map +1 -1
- package/dist/wje-file-upload-item.js +29 -8
- package/dist/wje-file-upload-item.js.map +1 -1
- package/dist/wje-file-upload.js +86 -62
- package/dist/wje-file-upload.js.map +1 -1
- package/dist/wje-select.js +76 -32
- package/dist/wje-select.js.map +1 -1
- package/package.json +13 -10
|
@@ -1 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given file matches any of the accepted file types.
|
|
3
|
+
* @param {File} file The file to validate.
|
|
4
|
+
* @param {string|string[]} acceptedFileTypes A comma-separated string or an array of accepted MIME types or file extensions.
|
|
5
|
+
* @returns {boolean} Returns `true` if the file type is valid, otherwise `false`.
|
|
6
|
+
* @throws {Error} Throws an error if `acceptedFileTypes` is empty.
|
|
7
|
+
* @example
|
|
8
|
+
* const file = new File([""], "example.png", { type: "image/png" });
|
|
9
|
+
* const isValid = isValidFileType(file, "image/*,application/pdf");
|
|
10
|
+
* console.log(isValid); // true
|
|
11
|
+
* @example
|
|
12
|
+
* const file = new File([""], "example.txt", { type: "text/plain" });
|
|
13
|
+
* const isValid = isValidFileType(file, ["text/plain", "application/json"]);
|
|
14
|
+
* console.log(isValid); // true
|
|
15
|
+
*/
|
|
16
|
+
export function isValidFileType(file: File, acceptedFileTypes: string | string[]): boolean;
|
|
1
17
|
export function bool(v: any): boolean;
|
|
@@ -50,6 +50,18 @@ export default class Chip extends WJElement {
|
|
|
50
50
|
* @returns {boolean} True if the element has the 'removable' attribute, otherwise false.
|
|
51
51
|
*/
|
|
52
52
|
get removable(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Sets the disabled state of the element.
|
|
55
|
+
* If true, the 'disabled' attribute is added to the element.
|
|
56
|
+
* If false, the 'disabled' attribute is removed from the element.
|
|
57
|
+
* @param {boolean} value Specifies whether the element should be disabled.
|
|
58
|
+
*/
|
|
59
|
+
set disabled(value: boolean);
|
|
60
|
+
/**
|
|
61
|
+
* Determines if the element has the 'disabled' attribute.
|
|
62
|
+
* @returns {boolean} True if the element has the 'disabled' attribute, otherwise false.
|
|
63
|
+
*/
|
|
64
|
+
get disabled(): boolean;
|
|
53
65
|
/**
|
|
54
66
|
* Draws the Chip element.
|
|
55
67
|
* @returns {DocumentFragment}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -119,6 +119,18 @@ export default class FileUpload extends WJElement {
|
|
|
119
119
|
* @returns {boolean}
|
|
120
120
|
*/
|
|
121
121
|
get toChunk(): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Sets the maximum number of files that can be uploaded or managed.
|
|
124
|
+
* Assigns the specified value to the 'max-files' attribute.
|
|
125
|
+
* @param {number} value The maximum allowable number of files.
|
|
126
|
+
*/
|
|
127
|
+
set maxFiles(value: number);
|
|
128
|
+
/**
|
|
129
|
+
* Retrieves the maximum number of files allowed from the `max-files` attribute.
|
|
130
|
+
* If the attribute is not set or is invalid, defaults to 0.
|
|
131
|
+
* @returns {number} The maximum number of files allowed.
|
|
132
|
+
*/
|
|
133
|
+
get maxFiles(): number;
|
|
122
134
|
beforeDraw(): void;
|
|
123
135
|
uploadFunction: Function;
|
|
124
136
|
/**
|
|
@@ -136,19 +148,19 @@ export default class FileUpload extends WJElement {
|
|
|
136
148
|
afterDraw(): void;
|
|
137
149
|
/**
|
|
138
150
|
* Method to handle form submission.
|
|
139
|
-
* @param {Event}
|
|
151
|
+
* @param {Event} e The form submission event.
|
|
140
152
|
*/
|
|
141
|
-
handleSubmit(
|
|
153
|
+
handleSubmit(e: Event): void;
|
|
142
154
|
/**
|
|
143
155
|
* Method to handle file drop event.
|
|
144
|
-
* @param {Event}
|
|
156
|
+
* @param {Event} e The file drop event object.
|
|
145
157
|
*/
|
|
146
|
-
handleDrop: (
|
|
158
|
+
handleDrop: (e: Event) => void;
|
|
147
159
|
/**
|
|
148
160
|
* Method to handle file input change event.
|
|
149
|
-
* @param {Event}
|
|
161
|
+
* @param {Event} e The file input change event object.
|
|
150
162
|
*/
|
|
151
|
-
handleInputChange: (
|
|
163
|
+
handleInputChange: (e: Event) => void;
|
|
152
164
|
/**
|
|
153
165
|
* Method to add files to the queue.
|
|
154
166
|
* @param files
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -7,29 +7,6 @@
|
|
|
7
7
|
* getFileTypeIcon('folder'); // Returns 'folder'.
|
|
8
8
|
*/
|
|
9
9
|
export function getFileTypeIcon(type: string): string;
|
|
10
|
-
/**
|
|
11
|
-
* Checks if a given file matches any of the accepted file types.
|
|
12
|
-
* @param {File} file The file to validate.
|
|
13
|
-
* @param {string|string[]} acceptedFileTypes A comma-separated string or an array of accepted MIME types or file extensions.
|
|
14
|
-
* @returns {boolean} Returns `true` if the file type is valid, otherwise `false`.
|
|
15
|
-
* @throws {Error} Throws an error if `acceptedFileTypes` is empty.
|
|
16
|
-
* @example
|
|
17
|
-
* const file = new File([""], "example.png", { type: "image/png" });
|
|
18
|
-
* const isValid = isValidFileType(file, "image/*,application/pdf");
|
|
19
|
-
* console.log(isValid); // true
|
|
20
|
-
* @example
|
|
21
|
-
* const file = new File([""], "example.txt", { type: "text/plain" });
|
|
22
|
-
* const isValid = isValidFileType(file, ["text/plain", "application/json"]);
|
|
23
|
-
* console.log(isValid); // true
|
|
24
|
-
*/
|
|
25
|
-
export function isValidFileType(file: File, acceptedFileTypes: string | string[]): boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Uploads a file in chunks using `XMLHttpRequest`, allowing for progress tracking.
|
|
28
|
-
* @param {File} file The file to be uploaded.
|
|
29
|
-
* @param {number} chunkSize The size of each chunk in bytes.
|
|
30
|
-
* @param {HTMLElement} preview The element used to display upload progress.
|
|
31
|
-
*/
|
|
32
|
-
export function uploadFile(file: File, chunkSize: number, preview: HTMLElement): void;
|
|
33
10
|
/**
|
|
34
11
|
* Returns a function for uploading files either in chunks or as a whole file, based on the provided options.
|
|
35
12
|
* @param {string} url The URL to which the file will be uploaded.
|
|
@@ -31,24 +31,41 @@ export default class FileUploadItem extends WJElement {
|
|
|
31
31
|
*/
|
|
32
32
|
static get observedAttributes(): Array<string>;
|
|
33
33
|
localizer: Localizer;
|
|
34
|
+
/**
|
|
35
|
+
* Sets the 'is-uploaded' attribute to indicate the uploaded status.
|
|
36
|
+
* @param {boolean} value The value to determine if the element is uploaded.
|
|
37
|
+
*/
|
|
34
38
|
set isUploaded(value: boolean);
|
|
39
|
+
/**
|
|
40
|
+
* Checks if the 'is-uploaded' attribute is present on the element.
|
|
41
|
+
* @returns {boolean} True if the 'is-uploaded' attribute exists, otherwise false.
|
|
42
|
+
*/
|
|
35
43
|
get isUploaded(): boolean;
|
|
36
|
-
|
|
37
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Sets the size attribute of the element.
|
|
46
|
+
* @param {string | number} value The value to set for the size attribute.
|
|
47
|
+
*/
|
|
48
|
+
set size(value: string | number);
|
|
49
|
+
/**
|
|
50
|
+
* Retrieves the value of the 'size' attribute.
|
|
51
|
+
* @returns {string|null} The value of the 'size' attribute, or null if the attribute is not present.
|
|
52
|
+
*/
|
|
53
|
+
get size(): string | null;
|
|
38
54
|
/**
|
|
39
55
|
* Dependencies for the component.
|
|
40
56
|
* @type {object}
|
|
41
57
|
*/
|
|
42
58
|
dependencies: object;
|
|
43
59
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* @param {string} name The name of the attribute
|
|
47
|
-
* @param {string
|
|
48
|
-
* @param {string
|
|
49
|
-
* @returns {void}
|
|
60
|
+
* A lifecycle method that is called when one of the observed attributes of the custom element is added, removed, or changed.
|
|
61
|
+
* This method is used to react to changes in the specified attributes.
|
|
62
|
+
* @param {string} name The name of the attribute that was changed.
|
|
63
|
+
* @param {string|null} oldValue The previous value of the attribute before the change, or null if the attribute was not previously set.
|
|
64
|
+
* @param {string|null} newValue The new value of the attribute after the change, or null if the attribute has been removed.
|
|
65
|
+
* @returns {void} This method does not return a value.
|
|
50
66
|
*/
|
|
51
67
|
attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
|
|
68
|
+
progress: number;
|
|
52
69
|
/**
|
|
53
70
|
* Method to draw the component on the screen.
|
|
54
71
|
* @returns {DocumentFragment} The fragment containing the component.
|
|
@@ -371,6 +371,8 @@ export class Select extends FormAssociatedElement {
|
|
|
371
371
|
selectOptions(values: any | any[], silent?: boolean): void;
|
|
372
372
|
/**
|
|
373
373
|
* Clones and appends an icon with the "check" slot to the specified option element.
|
|
374
|
+
* If the option already contains a custom element with slot="check" (e.g. <wje-status slot="check">),
|
|
375
|
+
* it is left untouched and no template icon is added.
|
|
374
376
|
* @param {HTMLElement} option The target HTML element to which the cloned "check" icon will be appended.
|
|
375
377
|
* @returns {void} This method does not return a value, but it modifies the DOM by appending a cloned "check" icon to the provided option element.
|
|
376
378
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/utils.js
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
const bool = (v) => {
|
|
2
2
|
return v === "false" || v === "null" || v === "NaN" || v === "undefined" || v === "0" ? false : !!v;
|
|
3
3
|
};
|
|
4
|
+
function isValidFileType(file, acceptedFileTypes) {
|
|
5
|
+
const mime = file.type.toLowerCase();
|
|
6
|
+
const base = mime.split("/")[0];
|
|
7
|
+
const ext = file.name.split(".").pop().toLowerCase();
|
|
8
|
+
let accepted = Array.isArray(acceptedFileTypes) ? acceptedFileTypes : acceptedFileTypes.split(",").map((t) => t.trim().toLowerCase());
|
|
9
|
+
if (accepted.length === 0) {
|
|
10
|
+
throw new Error("acceptedFileTypes is empty");
|
|
11
|
+
}
|
|
12
|
+
for (let type of accepted) {
|
|
13
|
+
type = type.toLowerCase();
|
|
14
|
+
if (type === base + "/*") return true;
|
|
15
|
+
if (type === mime) return true;
|
|
16
|
+
if (type === ext) return true;
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
4
20
|
export {
|
|
5
|
-
bool
|
|
21
|
+
bool,
|
|
22
|
+
isValidFileType
|
|
6
23
|
};
|
|
7
24
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../packages/utils/utils.js"],"sourcesContent":["export const bool = (v) => {\n return v === 'false' || v === 'null' || v === 'NaN' || v === 'undefined' || v === '0' ? false : !!v;\n};\n"],"names":[],"mappings":"AAAY,MAAC,OAAO,CAAC,MAAM;AACvB,SAAO,MAAM,WAAW,MAAM,UAAU,MAAM,SAAS,MAAM,eAAe,MAAM,MAAM,QAAQ,CAAC,CAAC;AACtG;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../packages/utils/utils.js"],"sourcesContent":["export const bool = (v) => {\n return v === 'false' || v === 'null' || v === 'NaN' || v === 'undefined' || v === '0' ? false : !!v;\n};\n\n/**\n * Checks if a given file matches any of the accepted file types.\n * @param {File} file The file to validate.\n * @param {string|string[]} acceptedFileTypes A comma-separated string or an array of accepted MIME types or file extensions.\n * @returns {boolean} Returns `true` if the file type is valid, otherwise `false`.\n * @throws {Error} Throws an error if `acceptedFileTypes` is empty.\n * @example\n * const file = new File([\"\"], \"example.png\", { type: \"image/png\" });\n * const isValid = isValidFileType(file, \"image/*,application/pdf\");\n * console.log(isValid); // true\n * @example\n * const file = new File([\"\"], \"example.txt\", { type: \"text/plain\" });\n * const isValid = isValidFileType(file, [\"text/plain\", \"application/json\"]);\n * console.log(isValid); // true\n */\nexport function isValidFileType(file, acceptedFileTypes) {\n const mime = file.type.toLowerCase();\n const base = mime.split('/')[0];\n const ext = file.name.split('.').pop().toLowerCase();\n\n let accepted = Array.isArray(acceptedFileTypes)\n ? acceptedFileTypes\n : acceptedFileTypes.split(',').map(t => t.trim().toLowerCase());\n\n if (accepted.length === 0) {\n throw new Error('acceptedFileTypes is empty');\n }\n\n for (let type of accepted) {\n type = type.toLowerCase();\n\n // image/* alebo application/*\n if (type === base + '/*') return true;\n\n // presný MIME typ\n if (type === mime) return true;\n\n // extension (xlsx, png, pdf…)\n if (type === ext) return true;\n }\n\n return false;\n}\n"],"names":[],"mappings":"AAAY,MAAC,OAAO,CAAC,MAAM;AACvB,SAAO,MAAM,WAAW,MAAM,UAAU,MAAM,SAAS,MAAM,eAAe,MAAM,MAAM,QAAQ,CAAC,CAAC;AACtG;AAiBO,SAAS,gBAAgB,MAAM,mBAAmB;AACrD,QAAM,OAAO,KAAK,KAAK,YAAa;AACpC,QAAM,OAAO,KAAK,MAAM,GAAG,EAAE,CAAC;AAC9B,QAAM,MAAM,KAAK,KAAK,MAAM,GAAG,EAAE,IAAK,EAAC,YAAa;AAEpD,MAAI,WAAW,MAAM,QAAQ,iBAAiB,IAC1C,oBACA,kBAAkB,MAAM,GAAG,EAAE,IAAI,OAAK,EAAE,OAAO,aAAa;AAEhE,MAAI,SAAS,WAAW,GAAG;AACvB,UAAM,IAAI,MAAM,4BAA4B;AAAA,EACpD;AAEI,WAAS,QAAQ,UAAU;AACvB,WAAO,KAAK,YAAa;AAGzB,QAAI,SAAS,OAAO,KAAM,QAAO;AAGjC,QAAI,SAAS,KAAM,QAAO;AAG1B,QAAI,SAAS,IAAK,QAAO;AAAA,EACjC;AAEI,SAAO;AACX;"}
|
package/dist/wje-chip.js
CHANGED
|
@@ -71,6 +71,26 @@ class Chip extends WJElement {
|
|
|
71
71
|
get removable() {
|
|
72
72
|
return this.hasAttribute("removable");
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Sets the disabled state of the element.
|
|
76
|
+
* If true, the 'disabled' attribute is added to the element.
|
|
77
|
+
* If false, the 'disabled' attribute is removed from the element.
|
|
78
|
+
* @param {boolean} value Specifies whether the element should be disabled.
|
|
79
|
+
*/
|
|
80
|
+
set disabled(value) {
|
|
81
|
+
if (value) {
|
|
82
|
+
this.setAttribute("disabled", "");
|
|
83
|
+
} else {
|
|
84
|
+
this.removeAttribute("disabled");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Determines if the element has the 'disabled' attribute.
|
|
89
|
+
* @returns {boolean} True if the element has the 'disabled' attribute, otherwise false.
|
|
90
|
+
*/
|
|
91
|
+
get disabled() {
|
|
92
|
+
return this.hasAttribute("disabled");
|
|
93
|
+
}
|
|
74
94
|
/**
|
|
75
95
|
* Getter for the CSS stylesheet.
|
|
76
96
|
* @returns {*}
|
package/dist/wje-chip.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wje-chip.js","sources":["../packages/wje-chip/chip.element.js","../packages/wje-chip/chip.js"],"sourcesContent":["import { default as WJElement, event, WjElementUtils } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * @summary This method dispatches a custom event named \"wje-chip:remove\".\n * It is triggered when the remove button is clicked, which happens when the chip is removed.\n * The event is dispatched on the current instance of the Chip class.\n * @documentation https://elements.webjet.sk/components/chip\n * @status stable\n * @augments WJElement\n * @slot - The chip main content.\n * @csspart native - The component's native wrapper.\n * //@fires wje-chip:remove - Dispatched when the chip is removed;\n */\nexport default class Chip extends WJElement {\n /**\n * Chip constructor method.\n */\n constructor() {\n super();\n }\n\n /**\n * Sets or removes the \"round\" attribute on the element based on the provided value.\n * @param {boolean} value Determines whether the \"round\" attribute should be set or removed.\n * If true, the \"round\" attribute is added. If false, the \"round\"\n * attribute is removed.\n */\n set round(value) {\n if (value) {\n this.setAttribute('round', '');\n } else {\n this.removeAttribute('round');\n }\n }\n\n /**\n * Checks if the 'round' attribute is present on the element.\n * @returns {boolean} Returns true if the 'round' attribute exists, otherwise false.\n */\n get round() {\n return this.hasAttribute('round');\n }\n\n /**\n * Sets the size attribute of the element.\n * @param {string} value The value to set for the size attribute.\n */\n set size(value) {\n this.setAttribute('size', value);\n }\n\n /**\n * Retrieves the 'size' attribute of the current element.\n * @returns {string | null} The value of the 'size' attribute, or null if the attribute is not set.\n */\n get size() {\n return this.getAttribute('size');\n }\n\n /**\n * Sets or removes the \"removable\" attribute on the element.\n * @param {boolean} value A boolean indicating whether the element should have the \"removable\" attribute.\n * If true, the \"removable\" attribute is added;\n * if false, the \"removable\" attribute is removed.\n */\n set removable(value) {\n if (value) {\n this.setAttribute('removable', '');\n } else {\n this.removeAttribute('removable');\n }\n }\n\n /**\n * Determines if the element has the 'removable' attribute.\n * @returns {boolean} True if the element has the 'removable' attribute, otherwise false.\n */\n get removable() {\n return this.hasAttribute('removable');\n }\n\n /**\n * Class name for the Chip element.\n * @type {string}\n */\n className = 'Chip';\n\n /**\n * Getter for the CSS stylesheet.\n * @returns {*}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Getter for the observed attributes.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Draws the Chip element.\n * @returns {DocumentFragment}\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('div');\n native.setAttribute('part', 'native');\n native.classList.add('native-chip');\n\n let slot = document.createElement('slot');\n\n let slotEnd = document.createElement('slot');\n slotEnd.setAttribute('name', 'end');\n\n let remove = document.createElement('wje-button');\n remove.setAttribute('part', 'remove');\n remove.setAttribute('fill', 'link');\n remove.setAttribute('color', this.color || 'default');\n remove.round = !this.round;\n\n if(this.hasAttribute('size')) {\n if(this.size === 'small') {\n remove.innerHTML = `<wje-icon name=\"x\" size=\"small\"></wje-icon>`;\n } else if (this.size === 'large') {\n remove.innerHTML = `<wje-icon name=\"x\"></wje-icon>`;\n }\n } else {\n remove.innerHTML = `<wje-icon name=\"x\"></wje-icon>`;\n }\n\n let active = document.createElement('wje-icon');\n active.setAttribute('name', 'check');\n active.classList.add('check');\n\n // Add color\n if (this.hasAttribute('color')) native.classList.add('wje-color-' + this.color, 'wje-color');\n else native.classList.add('wje-color-default', 'wje-color');\n\n if (this.disabled) this.classList.add('wje-disabled');\n\n if (this.outline) this.classList.add('wje-outline');\n\n native.appendChild(slot);\n native.appendChild(slotEnd);\n native.appendChild(active);\n\n if (this.removable) native.appendChild(remove);\n\n fragment.appendChild(native);\n\n this.removeElement = remove;\n this.slotEnd = slotEnd;\n\n return fragment;\n }\n\n /**\n * Getter for the observed attributes.\n */\n afterDraw() {\n if (WjElementUtils.hasSlotContent(this.context, 'end')) this.slotEnd.classList.add('has-content');\n\n event.addListener(this.removeElement, 'click', 'wje:chip-remove', null, { stopPropagation: true });\n }\n\n /**\n * Before disconnect event for the Chip element.\n */\n beforeDisconnect() {\n event.removeListener(this.removeElement, 'click', 'wje:chip-remove');\n }\n}\n","import { default as WJElement } from '../wje-element/element.js';\nimport Chip from './chip.element.js';\n\n// export * from \"./chip.element.js\";\nexport default Chip;\n\nWJElement.define('wje-chip', Chip);\n"],"names":[],"mappings":";;;;;;;AAce,MAAM,aAAa,UAAU;AAAA;AAAA;AAAA;AAAA,EAIxC,cAAc;AACV,UAAO;
|
|
1
|
+
{"version":3,"file":"wje-chip.js","sources":["../packages/wje-chip/chip.element.js","../packages/wje-chip/chip.js"],"sourcesContent":["import { default as WJElement, event, WjElementUtils } from '../wje-element/element.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * @summary This method dispatches a custom event named \"wje-chip:remove\".\n * It is triggered when the remove button is clicked, which happens when the chip is removed.\n * The event is dispatched on the current instance of the Chip class.\n * @documentation https://elements.webjet.sk/components/chip\n * @status stable\n * @augments WJElement\n * @slot - The chip main content.\n * @csspart native - The component's native wrapper.\n * //@fires wje-chip:remove - Dispatched when the chip is removed;\n */\nexport default class Chip extends WJElement {\n /**\n * Chip constructor method.\n */\n constructor() {\n super();\n }\n\n /**\n * Sets or removes the \"round\" attribute on the element based on the provided value.\n * @param {boolean} value Determines whether the \"round\" attribute should be set or removed.\n * If true, the \"round\" attribute is added. If false, the \"round\"\n * attribute is removed.\n */\n set round(value) {\n if (value) {\n this.setAttribute('round', '');\n } else {\n this.removeAttribute('round');\n }\n }\n\n /**\n * Checks if the 'round' attribute is present on the element.\n * @returns {boolean} Returns true if the 'round' attribute exists, otherwise false.\n */\n get round() {\n return this.hasAttribute('round');\n }\n\n /**\n * Sets the size attribute of the element.\n * @param {string} value The value to set for the size attribute.\n */\n set size(value) {\n this.setAttribute('size', value);\n }\n\n /**\n * Retrieves the 'size' attribute of the current element.\n * @returns {string | null} The value of the 'size' attribute, or null if the attribute is not set.\n */\n get size() {\n return this.getAttribute('size');\n }\n\n /**\n * Sets or removes the \"removable\" attribute on the element.\n * @param {boolean} value A boolean indicating whether the element should have the \"removable\" attribute.\n * If true, the \"removable\" attribute is added;\n * if false, the \"removable\" attribute is removed.\n */\n set removable(value) {\n if (value) {\n this.setAttribute('removable', '');\n } else {\n this.removeAttribute('removable');\n }\n }\n\n /**\n * Determines if the element has the 'removable' attribute.\n * @returns {boolean} True if the element has the 'removable' attribute, otherwise false.\n */\n get removable() {\n return this.hasAttribute('removable');\n }\n\n /**\n * Sets the disabled state of the element.\n * If true, the 'disabled' attribute is added to the element.\n * If false, the 'disabled' attribute is removed from the element.\n * @param {boolean} value Specifies whether the element should be disabled.\n */\n set disabled(value) {\n if (value) {\n this.setAttribute('disabled', '');\n } else {\n this.removeAttribute('disabled');\n }\n }\n\n /**\n * Determines if the element has the 'disabled' attribute.\n * @returns {boolean} True if the element has the 'disabled' attribute, otherwise false.\n */\n get disabled() {\n return this.hasAttribute('disabled');\n }\n\n /**\n * Class name for the Chip element.\n * @type {string}\n */\n className = 'Chip';\n\n /**\n * Getter for the CSS stylesheet.\n * @returns {*}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Getter for the observed attributes.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Draws the Chip element.\n * @returns {DocumentFragment}\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('div');\n native.setAttribute('part', 'native');\n native.classList.add('native-chip');\n\n let slot = document.createElement('slot');\n\n let slotEnd = document.createElement('slot');\n slotEnd.setAttribute('name', 'end');\n\n let remove = document.createElement('wje-button');\n remove.setAttribute('part', 'remove');\n remove.setAttribute('fill', 'link');\n remove.setAttribute('color', this.color || 'default');\n remove.round = !this.round;\n\n if(this.hasAttribute('size')) {\n if(this.size === 'small') {\n remove.innerHTML = `<wje-icon name=\"x\" size=\"small\"></wje-icon>`;\n } else if (this.size === 'large') {\n remove.innerHTML = `<wje-icon name=\"x\"></wje-icon>`;\n }\n } else {\n remove.innerHTML = `<wje-icon name=\"x\"></wje-icon>`;\n }\n\n let active = document.createElement('wje-icon');\n active.setAttribute('name', 'check');\n active.classList.add('check');\n\n // Add color\n if (this.hasAttribute('color')) native.classList.add('wje-color-' + this.color, 'wje-color');\n else native.classList.add('wje-color-default', 'wje-color');\n\n if (this.disabled) this.classList.add('wje-disabled');\n\n if (this.outline) this.classList.add('wje-outline');\n\n native.appendChild(slot);\n native.appendChild(slotEnd);\n native.appendChild(active);\n\n if (this.removable) native.appendChild(remove);\n\n fragment.appendChild(native);\n\n this.removeElement = remove;\n this.slotEnd = slotEnd;\n\n return fragment;\n }\n\n /**\n * Getter for the observed attributes.\n */\n afterDraw() {\n if (WjElementUtils.hasSlotContent(this.context, 'end')) this.slotEnd.classList.add('has-content');\n\n event.addListener(this.removeElement, 'click', 'wje:chip-remove', null, { stopPropagation: true });\n }\n\n /**\n * Before disconnect event for the Chip element.\n */\n beforeDisconnect() {\n event.removeListener(this.removeElement, 'click', 'wje:chip-remove');\n }\n}\n","import { default as WJElement } from '../wje-element/element.js';\nimport Chip from './chip.element.js';\n\n// export * from \"./chip.element.js\";\nexport default Chip;\n\nWJElement.define('wje-chip', Chip);\n"],"names":[],"mappings":";;;;;;;AAce,MAAM,aAAa,UAAU;AAAA;AAAA;AAAA;AAAA,EAIxC,cAAc;AACV,UAAO;AAyFX;AAAA;AAAA;AAAA;AAAA,qCAAY;AAAA,EAxFhB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQI,IAAI,MAAM,OAAO;AACb,QAAI,OAAO;AACP,WAAK,aAAa,SAAS,EAAE;AAAA,IACzC,OAAe;AACH,WAAK,gBAAgB,OAAO;AAAA,IACxC;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,IAAI,QAAQ;AACR,WAAO,KAAK,aAAa,OAAO;AAAA,EACxC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,IAAI,KAAK,OAAO;AACZ,SAAK,aAAa,QAAQ,KAAK;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,IAAI,OAAO;AACP,WAAO,KAAK,aAAa,MAAM;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQI,IAAI,UAAU,OAAO;AACjB,QAAI,OAAO;AACP,WAAK,aAAa,aAAa,EAAE;AAAA,IAC7C,OAAe;AACH,WAAK,gBAAgB,WAAW;AAAA,IAC5C;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,IAAI,YAAY;AACZ,WAAO,KAAK,aAAa,WAAW;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQI,IAAI,SAAS,OAAO;AAChB,QAAI,OAAO;AACP,WAAK,aAAa,YAAY,EAAE;AAAA,IAC5C,OAAe;AACH,WAAK,gBAAgB,UAAU;AAAA,IAC3C;AAA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,IAAI;AACvB,WAAO,YAAY,OAAO;AAC1B,WAAO,YAAY,MAAM;AAEzB,QAAI,KAAK,UAAW,QAAO,YAAY,MAAM;AAE7C,aAAS,YAAY,MAAM;AAE3B,SAAK,gBAAgB;AACrB,SAAK,UAAU;AAEf,WAAO;AAAA,EACf;AAAA;AAAA;AAAA;AAAA,EAKI,YAAY;AACR,QAAI,eAAe,eAAe,KAAK,SAAS,KAAK,EAAG,MAAK,QAAQ,UAAU,IAAI,aAAa;AAEhG,UAAM,YAAY,KAAK,eAAe,SAAS,mBAAmB,MAAM,EAAE,iBAAiB,MAAM;AAAA,EACzG;AAAA;AAAA;AAAA;AAAA,EAKI,mBAAmB;AACf,UAAM,eAAe,KAAK,eAAe,SAAS,iBAAiB;AAAA,EAC3E;AACA;AChMA,UAAU,OAAO,YAAY,IAAI;"}
|
|
@@ -7,6 +7,7 @@ import WJElement from "./wje-element.js";
|
|
|
7
7
|
import FormatDigital from "./wje-format-digital.js";
|
|
8
8
|
import { I as Icon } from "./icon-DY5AZ6xM.js";
|
|
9
9
|
import Slider from "./wje-slider.js";
|
|
10
|
+
import { event } from "./event.js";
|
|
10
11
|
const styles = "/*\n[ WJ File Upload Item ]\n*/\n\n:host {\n width: 100%;\n}\n\n.native-file-upload-item {\n display: grid;\n grid-template-columns: auto 1fr 1fr;\n grid-template-rows: auto auto auto;\n gap: 0.5rem;\n grid-template-areas:\n 'image name actions'\n 'image size actions'\n 'progress progress progress';\n padding: 0.5rem;\n border-width: var(--wje-file-upload-item-border-width);\n border-style: var(--wje-file-upload-item-border-style);\n border-color: var(--wje-file-upload-item-border-color);\n border-radius: var(--wje-border-radius-medium);\n}\n\n.image {\n grid-area: image;\n align-items: center;\n display: flex;\n}\n\n::slotted([slot='img']) {\n --wje-img-border-radius: var(--wje-border-radius-medium) !important;\n}\n\n.name {\n grid-area: name;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n font-weight: bold;\n}\n\n.size {\n grid-area: size;\n display: flex;\n}\n\n.actions {\n grid-area: actions;\n display: flex;\n align-items: center;\n justify-content: flex-end;\n}\n\n.file-progress {\n grid-area: progress;\n}\n\n.file-info > span {\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n\nwje-slider {\n flex-basis: 100%;\n margin-top: 0.5rem;\n}\n\nwje-slider::part(slider) {\n color: yellow;\n}\n\nwje-slider::part(slider)::-webkit-slider-thumb {\n visibility: hidden;\n}\n\nwje-slider::part(slider)::-moz-range-thumb {\n visibility: hidden;\n}\n\nwje-slider::part(slider)::-ms-thumb {\n visibility: hidden;\n}\n\nwje-img {\n width: 50px;\n height: 50px;\n display: flex;\n align-items: center;\n padding: 0.25rem;\n border: 1px solid var(--wje-border-color);\n border-radius: var(--wje-border-radius-medium);\n}\n";
|
|
11
12
|
class FileUploadItem extends WJElement {
|
|
12
13
|
/**
|
|
@@ -30,19 +31,36 @@ class FileUploadItem extends WJElement {
|
|
|
30
31
|
* Handles the delete action.
|
|
31
32
|
*/
|
|
32
33
|
__publicField(this, "onDelete", () => {
|
|
34
|
+
event.dispatchCustomEvent(this, "wje-file-upload-item:remove", this.data);
|
|
33
35
|
this.remove();
|
|
34
36
|
});
|
|
35
37
|
this.localizer = new Localizer(this);
|
|
36
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Sets the 'is-uploaded' attribute to indicate the uploaded status.
|
|
41
|
+
* @param {boolean} value The value to determine if the element is uploaded.
|
|
42
|
+
*/
|
|
37
43
|
set isUploaded(value) {
|
|
38
44
|
this.setAttribute("is-uploaded", "");
|
|
39
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Checks if the 'is-uploaded' attribute is present on the element.
|
|
48
|
+
* @returns {boolean} True if the 'is-uploaded' attribute exists, otherwise false.
|
|
49
|
+
*/
|
|
40
50
|
get isUploaded() {
|
|
41
51
|
return this.hasAttribute("is-uploaded");
|
|
42
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Sets the size attribute of the element.
|
|
55
|
+
* @param {string | number} value The value to set for the size attribute.
|
|
56
|
+
*/
|
|
43
57
|
set size(value) {
|
|
44
58
|
this.setAttribute("size", value);
|
|
45
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves the value of the 'size' attribute.
|
|
62
|
+
* @returns {string|null} The value of the 'size' attribute, or null if the attribute is not present.
|
|
63
|
+
*/
|
|
46
64
|
get size() {
|
|
47
65
|
return this.getAttribute("size");
|
|
48
66
|
}
|
|
@@ -60,21 +78,24 @@ class FileUploadItem extends WJElement {
|
|
|
60
78
|
* @returns {Array<string>}
|
|
61
79
|
*/
|
|
62
80
|
static get observedAttributes() {
|
|
63
|
-
return ["uploaded"];
|
|
81
|
+
return ["uploaded", "is-uploaded"];
|
|
64
82
|
}
|
|
65
83
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* @param {string} name The name of the attribute
|
|
69
|
-
* @param {string
|
|
70
|
-
* @param {string
|
|
71
|
-
* @returns {void}
|
|
84
|
+
* A lifecycle method that is called when one of the observed attributes of the custom element is added, removed, or changed.
|
|
85
|
+
* This method is used to react to changes in the specified attributes.
|
|
86
|
+
* @param {string} name The name of the attribute that was changed.
|
|
87
|
+
* @param {string|null} oldValue The previous value of the attribute before the change, or null if the attribute was not previously set.
|
|
88
|
+
* @param {string|null} newValue The new value of the attribute after the change, or null if the attribute has been removed.
|
|
89
|
+
* @returns {void} This method does not return a value.
|
|
72
90
|
*/
|
|
73
91
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
92
|
+
if (super.attributeChangedCallback) {
|
|
93
|
+
super.attributeChangedCallback(name, oldValue, newValue);
|
|
94
|
+
}
|
|
74
95
|
if (name === "uploaded" && oldValue !== newValue && this.uploadedEl) {
|
|
75
96
|
this.uploadedEl.setAttribute("value", newValue);
|
|
76
97
|
let progress = +newValue / +this.size * 100 || 0;
|
|
77
|
-
this.
|
|
98
|
+
this.progress = Math.round(progress, 0);
|
|
78
99
|
}
|
|
79
100
|
}
|
|
80
101
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wje-file-upload-item.js","sources":["../packages/wje-file-upload-item/file-upload-item.element.js","../packages/wje-file-upload-item/file-upload-item.js"],"sourcesContent":["import { Localizer } from '../utils/localize.js';\nimport Button from '../wje-button/button.js';\nimport { default as WJElement } from '../wje-element/element.js';\nimport FormatDigital from '../wje-format-digital/format-digital.js';\nimport Icon from '../wje-icon/icon.js';\nimport Slider from '../wje-slider/slider.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * @summary This element allows users to upload files.\n * `FileUploadItem` is a custom web component that represents a file upload item.\n * It extends from `WJElement` and uses the `Localizer` utility for localization.\n * @documentation https://elements.webjet.sk/components/file-upload\n * @status stable\n * @augments WJElement\n * @csspart button - The delete button part\n * @csspart image - The image part\n * @csspart name - The name part\n * @csspart size - The size part\n * @slot img - Slot for the image\n * @slot action - Slot for the action buttons\n * @cssproperty --primary-color - The primary color of the file upload item.\n * //@fires wje-button:click - Dispatches when the delete button is clicked\n * @tag wje-file-upload\n */\nexport default class FileUploadItem extends WJElement {\n /**\n * Creates an instance of FileUploadItem.\n * @class\n */\n constructor() {\n super();\n this.localizer = new Localizer(this);\n }\n\n set isUploaded(value) {\n this.setAttribute('is-uploaded', '');\n }\n\n get isUploaded() {\n return this.hasAttribute('is-uploaded');\n }\n\n set size(value) {\n this.setAttribute('size', value);\n }\n\n get size() {\n return this.getAttribute('size');\n }\n\n /**\n * Dependencies for the component.\n * @type {object}\n */\n dependencies = {\n 'wje-format-digital': FormatDigital,\n 'wje-button': Button,\n 'wje-slider': Slider,\n 'wje-icon': Icon,\n };\n\n className = 'FileUploadItem';\n\n /**\n * Returns the CSS styles for the component.\n * @static\n * @returns {CSSStyleSheet}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Returns the list of attributes to observe for changes.\n * @static\n * @returns {Array<string>}\n */\n static get observedAttributes() {\n return ['uploaded'];\n }\n\n /**\n * Handles updates to the attributes of a custom element whenever one of the observed attributes is changed.\n * Updates the related elements based on the changed attribute and its new value.\n * @param {string} name The name of the attribute being changed.\n * @param {string | null} oldValue The previous value of the attribute before the change, or null if the attribute was not previously set.\n * @param {string | null} newValue The new value of the attribute after the change, or null if the attribute is being removed.\n * @returns {void} Does not return a value.\n */\n attributeChangedCallback(name, oldValue, newValue) {\n if (name === 'uploaded' && oldValue !== newValue && this.uploadedEl) {\n this.uploadedEl.setAttribute('value', newValue);\n\n let progress = (+newValue / +this.size) * 100 || 0;\n\n this.sliderEl.setAttribute('progress', Math.round(progress, 0));\n }\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Method to draw the component on the screen.\n * @returns {DocumentFragment} The fragment containing the component.\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('div');\n native.classList.add('native-file-upload-item');\n\n let slot = document.createElement('slot');\n slot.setAttribute('name', 'img');\n\n let image = document.createElement('div');\n image.setAttribute('part', 'image');\n image.classList.add('image');\n\n let name = document.createElement('span');\n name.classList.add('name');\n name.innerText = this.name;\n\n let actions = document.createElement('slot');\n actions.classList.add('actions');\n actions.setAttribute('name', 'action');\n\n let button = document.createElement('wje-button');\n button.setAttribute('fill', 'link');\n button.setAttribute('size', 'small');\n button.innerHTML = `<wje-icon name=\"x\" size=\"small\"></wje-icon>`;\n\n let sizeWrapper = document.createElement('span');\n sizeWrapper.classList.add('size');\n\n let uploaded = document.createElement('wje-format-digital');\n uploaded.setAttribute('value', this.uploaded || 0);\n uploaded.innerHTML = `<span slot=\"start\">${this.localizer.translate('wj.file.upload.uploaded')}</span>`;\n\n let size = document.createElement('wje-format-digital');\n size.setAttribute('value', this.size || 0);\n size.innerHTML = `<span slot=\"start\"> ${this.localizer.translate('wj.file.upload.from')} </span>`;\n\n let size2 = document.createElement('wje-format-digital');\n size2.setAttribute('value', this.size || 0);\n\n let slider = document.createElement('wje-progress-bar');\n slider.classList.add('file-progress');\n slider.setAttribute('id', 'id-' + this.lastModified);\n slider.setAttribute('progress', this.progress);\n slider.setAttribute('color', 'success');\n\n image.appendChild(slot);\n actions.appendChild(button);\n\n sizeWrapper.appendChild(uploaded);\n sizeWrapper.appendChild(size);\n\n native.appendChild(image);\n native.appendChild(name);\n\n if (!this.isUploaded)\n native.appendChild(sizeWrapper);\n else\n native.appendChild(size2);\n\n native.appendChild(actions);\n\n if (!this.isUploaded)\n native.appendChild(slider);\n\n fragment.appendChild(native);\n\n this.button = button;\n this.uploadedEl = uploaded;\n this.sliderEl = slider;\n\n return fragment;\n }\n\n /**\n * Called after the component has been drawn.\n */\n afterDraw() {\n this.button.addEventListener('wje-button:click', this.onDelete);\n }\n\n /**\n * Handles the delete action.\n */\n onDelete = () => {\n this.remove();\n };\n}\n","import FileUploadItem from './file-upload-item.element.js';\n\nexport default FileUploadItem;\n\nFileUploadItem.define('wje-file-upload-item', FileUploadItem);\n"],"names":[],"mappings":";;;;;;;;;;AAyBe,MAAM,uBAAuB,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAKlD,cAAc;AACV,UAAO;AAwBX;AAAA;AAAA;AAAA;AAAA,wCAAe;AAAA,MACX,sBAAsB;AAAA,MACtB,cAAc;AAAA,MACd,cAAc;AAAA,MACd,YAAY;AAAA,IACf;AAED,qCAAY;AAqIZ;AAAA;AAAA;AAAA,oCAAW,MAAM;AACb,WAAK,OAAQ;AAAA,IAChB;AArKG,SAAK,YAAY,IAAI,UAAU,IAAI;AAAA,EAC3C;AAAA,EAEI,IAAI,WAAW,OAAO;AAClB,SAAK,aAAa,eAAe,EAAE;AAAA,EAC3C;AAAA,EAEI,IAAI,aAAa;AACb,WAAO,KAAK,aAAa,aAAa;AAAA,EAC9C;AAAA,EAEI,IAAI,KAAK,OAAO;AACZ,SAAK,aAAa,QAAQ,KAAK;AAAA,EACvC;AAAA,EAEI,IAAI,OAAO;AACP,WAAO,KAAK,aAAa,MAAM;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA;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AAI,WAAW,SAAS,cAAc,oBAAoB;AAC1D,aAAS,aAAa,SAAS,KAAK,YAAY,CAAC;AACjD,aAAS,YAAY,sBAAsB,KAAK,UAAU,UAAU,yBAAyB,CAAC;AAE9F,QAAI,OAAO,SAAS,cAAc,oBAAoB;AACtD,SAAK,aAAa,SAAS,KAAK,QAAQ,CAAC;AACzC,SAAK,YAAY,4BAA4B,KAAK,UAAU,UAAU,qBAAqB,CAAC;AAE5F,QAAI,QAAQ,SAAS,cAAc,oBAAoB;AACvD,UAAM,aAAa,SAAS,KAAK,QAAQ,CAAC;AAE1C,QAAI,SAAS,SAAS,cAAc,kBAAkB;AACtD,WAAO,UAAU,IAAI,eAAe;AACpC,WAAO,aAAa,MAAM,QAAQ,KAAK,YAAY;AACnD,WAAO,aAAa,YAAY,KAAK,QAAQ;AAC7C,WAAO,aAAa,SAAS,SAAS;AAEtC,UAAM,YAAY,IAAI;AACtB,YAAQ,YAAY,MAAM;AAE1B,gBAAY,YAAY,QAAQ;AAChC,gBAAY,YAAY,IAAI;AAE5B,WAAO,YAAY,KAAK;AACxB,WAAO,YAAY,IAAI;AAEvB,QAAI,CAAC,KAAK;AACN,aAAO,YAAY,WAAW;AAAA;AAE9B,aAAO,YAAY,KAAK;AAE5B,WAAO,YAAY,OAAO;AAE1B,QAAI,CAAC,KAAK;AACN,aAAO,YAAY,MAAM;AAE7B,aAAS,YAAY,MAAM;AAE3B,SAAK,SAAS;AACd,SAAK,aAAa;AAClB,SAAK,WAAW;AAEhB,WAAO;AAAA,EACf;AAAA;AAAA;AAAA;AAAA,EAKI,YAAY;AACR,SAAK,OAAO,iBAAiB,oBAAoB,KAAK,QAAQ;AAAA,EACtE;AAQA;AClMA,eAAe,OAAO,wBAAwB,cAAc;"}
|
|
1
|
+
{"version":3,"file":"wje-file-upload-item.js","sources":["../packages/wje-file-upload-item/file-upload-item.element.js","../packages/wje-file-upload-item/file-upload-item.js"],"sourcesContent":["import { Localizer } from '../utils/localize.js';\nimport Button from '../wje-button/button.js';\nimport { default as WJElement, event } from '../wje-element/element.js';\nimport FormatDigital from '../wje-format-digital/format-digital.js';\nimport Icon from '../wje-icon/icon.js';\nimport Slider from '../wje-slider/slider.js';\nimport styles from './styles/styles.css?inline';\n\n/**\n * @summary This element allows users to upload files.\n * `FileUploadItem` is a custom web component that represents a file upload item.\n * It extends from `WJElement` and uses the `Localizer` utility for localization.\n * @documentation https://elements.webjet.sk/components/file-upload\n * @status stable\n * @augments WJElement\n * @csspart button - The delete button part\n * @csspart image - The image part\n * @csspart name - The name part\n * @csspart size - The size part\n * @slot img - Slot for the image\n * @slot action - Slot for the action buttons\n * @cssproperty --primary-color - The primary color of the file upload item.\n * //@fires wje-button:click - Dispatches when the delete button is clicked\n * @tag wje-file-upload\n */\nexport default class FileUploadItem extends WJElement {\n /**\n * Creates an instance of FileUploadItem.\n * @class\n */\n constructor() {\n super();\n this.localizer = new Localizer(this);\n }\n\n /**\n * Sets the 'is-uploaded' attribute to indicate the uploaded status.\n * @param {boolean} value The value to determine if the element is uploaded.\n */\n set isUploaded(value) {\n this.setAttribute('is-uploaded', '');\n }\n\n /**\n * Checks if the 'is-uploaded' attribute is present on the element.\n * @returns {boolean} True if the 'is-uploaded' attribute exists, otherwise false.\n */\n get isUploaded() {\n return this.hasAttribute('is-uploaded');\n }\n\n /**\n * Sets the size attribute of the element.\n * @param {string | number} value The value to set for the size attribute.\n */\n set size(value) {\n this.setAttribute('size', value);\n }\n\n /**\n * Retrieves the value of the 'size' attribute.\n * @returns {string|null} The value of the 'size' attribute, or null if the attribute is not present.\n */\n get size() {\n return this.getAttribute('size');\n }\n\n /**\n * Dependencies for the component.\n * @type {object}\n */\n dependencies = {\n 'wje-format-digital': FormatDigital,\n 'wje-button': Button,\n 'wje-slider': Slider,\n 'wje-icon': Icon,\n };\n\n className = 'FileUploadItem';\n\n /**\n * Returns the CSS styles for the component.\n * @static\n * @returns {CSSStyleSheet}\n */\n static get cssStyleSheet() {\n return styles;\n }\n\n /**\n * Returns the list of attributes to observe for changes.\n * @static\n * @returns {Array<string>}\n */\n static get observedAttributes() {\n return ['uploaded', 'is-uploaded'];\n }\n\n /**\n * A lifecycle method that is called when one of the observed attributes of the custom element is added, removed, or changed.\n * This method is used to react to changes in the specified attributes.\n * @param {string} name The name of the attribute that was changed.\n * @param {string|null} oldValue The previous value of the attribute before the change, or null if the attribute was not previously set.\n * @param {string|null} newValue The new value of the attribute after the change, or null if the attribute has been removed.\n * @returns {void} This method does not return a value.\n */\n attributeChangedCallback(name, oldValue, newValue) {\n if (super.attributeChangedCallback) {\n super.attributeChangedCallback(name, oldValue, newValue);\n }\n\n if (name === 'uploaded' && oldValue !== newValue && this.uploadedEl) {\n this.uploadedEl.setAttribute('value', newValue);\n\n let progress = (+newValue / +this.size) * 100 || 0;\n\n this.progress = Math.round(progress, 0);\n }\n }\n\n /**\n * Sets up the attributes for the component.\n */\n setupAttributes() {\n this.isShadowRoot = 'open';\n }\n\n /**\n * Method to draw the component on the screen.\n * @returns {DocumentFragment} The fragment containing the component.\n */\n draw() {\n let fragment = document.createDocumentFragment();\n\n let native = document.createElement('div');\n native.classList.add('native-file-upload-item');\n\n let slot = document.createElement('slot');\n slot.setAttribute('name', 'img');\n\n let image = document.createElement('div');\n image.setAttribute('part', 'image');\n image.classList.add('image');\n\n let name = document.createElement('span');\n name.classList.add('name');\n name.innerText = this.name;\n\n let actions = document.createElement('slot');\n actions.classList.add('actions');\n actions.setAttribute('name', 'action');\n\n let button = document.createElement('wje-button');\n button.setAttribute('fill', 'link');\n button.setAttribute('size', 'small');\n button.innerHTML = `<wje-icon name=\"x\" size=\"small\"></wje-icon>`;\n\n let sizeWrapper = document.createElement('span');\n sizeWrapper.classList.add('size');\n\n let uploaded = document.createElement('wje-format-digital');\n uploaded.setAttribute('value', this.uploaded || 0);\n uploaded.innerHTML = `<span slot=\"start\">${this.localizer.translate('wj.file.upload.uploaded')}</span>`;\n\n let size = document.createElement('wje-format-digital');\n size.setAttribute('value', this.size || 0);\n size.innerHTML = `<span slot=\"start\"> ${this.localizer.translate('wj.file.upload.from')} </span>`;\n\n let size2 = document.createElement('wje-format-digital');\n size2.setAttribute('value', this.size || 0);\n\n let slider = document.createElement('wje-progress-bar');\n slider.classList.add('file-progress');\n slider.setAttribute('id', 'id-' + this.lastModified);\n slider.setAttribute('progress', this.progress);\n slider.setAttribute('color', 'success');\n\n image.appendChild(slot);\n actions.appendChild(button);\n\n sizeWrapper.appendChild(uploaded);\n sizeWrapper.appendChild(size);\n\n native.appendChild(image);\n native.appendChild(name);\n\n if (!this.isUploaded)\n native.appendChild(sizeWrapper);\n else\n native.appendChild(size2);\n\n native.appendChild(actions);\n\n if (!this.isUploaded)\n native.appendChild(slider);\n\n fragment.appendChild(native);\n\n this.button = button;\n this.uploadedEl = uploaded;\n this.sliderEl = slider;\n\n return fragment;\n }\n\n /**\n * Called after the component has been drawn.\n */\n afterDraw() {\n this.button.addEventListener('wje-button:click', this.onDelete);\n }\n\n /**\n * Handles the delete action.\n */\n onDelete = () => {\n event.dispatchCustomEvent(this, 'wje-file-upload-item:remove', this.data);\n\n this.remove();\n };\n}\n","import FileUploadItem from './file-upload-item.element.js';\n\nexport default FileUploadItem;\n\nFileUploadItem.define('wje-file-upload-item', FileUploadItem);\n"],"names":[],"mappings":";;;;;;;;;;;AAyBe,MAAM,uBAAuB,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA,EAKlD,cAAc;AACV,UAAO;AAwCX;AAAA;AAAA;AAAA;AAAA,wCAAe;AAAA,MACX,sBAAsB;AAAA,MACtB,cAAc;AAAA,MACd,cAAc;AAAA,MACd,YAAY;AAAA,IACf;AAED,qCAAY;AAyIZ;AAAA;AAAA;AAAA,oCAAW,MAAM;AACb,YAAM,oBAAoB,MAAM,+BAA+B,KAAK,IAAI;AAExE,WAAK,OAAQ;AAAA,IAChB;AA3LG,SAAK,YAAY,IAAI,UAAU,IAAI;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMI,IA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