@kubex/zinc 1.1.67 → 1.1.68
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/custom-elements.json +404 -278
- package/dist/vscode.html-custom-data.json +64 -30
- package/dist/web-types.json +124 -68
- package/dist/zn.d.ts +43 -6
- package/dist/zn.min.js +429 -431
- package/package.json +1 -1
- package/src/components/data-table/data-table.component.ts +49 -44
- package/src/components/data-table/data-table.scss +4 -0
- package/src/components/data-table/data-table.test.ts +42 -0
- package/src/components/defined-label/defined-label.component.ts +118 -95
- package/src/components/defined-label/defined-label.scss +40 -28
- package/src/components/file/file.component.ts +70 -0
- package/src/components/page-builder/page-builder.scss +1 -1
|
@@ -78,7 +78,13 @@ export default class ZnFile extends ZincElement implements ZincFormControl {
|
|
|
78
78
|
assumeInteractionOn: ['zn-change'],
|
|
79
79
|
// An explicitly cleared control submits an empty value so the server can
|
|
80
80
|
// remove the stored upload; an untouched empty control submits nothing.
|
|
81
|
+
// In upload-url mode the control submits the uploaded file's URL string
|
|
82
|
+
// instead of the file bytes.
|
|
81
83
|
value: (el: ZnFile) => {
|
|
84
|
+
if (el.uploadUrl) {
|
|
85
|
+
if (el.src) return el.src;
|
|
86
|
+
return el.clearedByUser ? '' : undefined;
|
|
87
|
+
}
|
|
82
88
|
if (el.files?.length) return el.files;
|
|
83
89
|
return el.clearedByUser ? '' : undefined;
|
|
84
90
|
}
|
|
@@ -148,12 +154,21 @@ export default class ZnFile extends ZincElement implements ZincFormControl {
|
|
|
148
154
|
*/
|
|
149
155
|
@property({type: String})
|
|
150
156
|
set value(v: string) {
|
|
157
|
+
// In upload-url mode the value is the uploaded file's URL, held in `src`
|
|
158
|
+
// (a native file input only accepts an empty string as value).
|
|
159
|
+
if (this.uploadUrl) {
|
|
160
|
+
this.src = v ?? '';
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
151
163
|
if (this.input) {
|
|
152
164
|
this.input.value = v;
|
|
153
165
|
}
|
|
154
166
|
}
|
|
155
167
|
|
|
156
168
|
get value() {
|
|
169
|
+
if (this.uploadUrl) {
|
|
170
|
+
return this.src ?? '';
|
|
171
|
+
}
|
|
157
172
|
return this.input?.value;
|
|
158
173
|
}
|
|
159
174
|
|
|
@@ -254,6 +269,16 @@ export default class ZnFile extends ZincElement implements ZincFormControl {
|
|
|
254
269
|
*/
|
|
255
270
|
@property({type: Boolean, attribute: 'show-link'}) showLink = false;
|
|
256
271
|
|
|
272
|
+
/**
|
|
273
|
+
* When set, a chosen file is immediately POSTed (multipart, field `file`) to this URL.
|
|
274
|
+
* The endpoint must respond with JSON `{"url": "..."}`; that URL becomes the control's
|
|
275
|
+
* value (and `src` preview) in place of the file bytes, so the control works inside
|
|
276
|
+
* JSON-serialising hosts such as `zn-page-builder`. Emits `zn-error` when the upload fails.
|
|
277
|
+
*/
|
|
278
|
+
@property({attribute: 'upload-url'}) uploadUrl = '';
|
|
279
|
+
|
|
280
|
+
@state() private uploading = false;
|
|
281
|
+
|
|
257
282
|
/** Gets the validity state object */
|
|
258
283
|
get validity() {
|
|
259
284
|
return this.input?.validity;
|
|
@@ -387,6 +412,14 @@ export default class ZnFile extends ZincElement implements ZincFormControl {
|
|
|
387
412
|
e.stopPropagation();
|
|
388
413
|
|
|
389
414
|
this.updatePreview();
|
|
415
|
+
|
|
416
|
+
const file = this.files?.[0];
|
|
417
|
+
if (this.uploadUrl && file) {
|
|
418
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
419
|
+
this.uploadFile(file);
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
|
|
390
423
|
this.emit('zn-input');
|
|
391
424
|
this.emit('zn-change');
|
|
392
425
|
|
|
@@ -395,6 +428,42 @@ export default class ZnFile extends ZincElement implements ZincFormControl {
|
|
|
395
428
|
}
|
|
396
429
|
}
|
|
397
430
|
|
|
431
|
+
/**
|
|
432
|
+
* Uploads the chosen file to `uploadUrl` and adopts the returned URL as the
|
|
433
|
+
* control's value. The local file preview stays visible while the upload runs.
|
|
434
|
+
*/
|
|
435
|
+
private async uploadFile(file: File) {
|
|
436
|
+
this.uploading = true;
|
|
437
|
+
try {
|
|
438
|
+
const body = new FormData();
|
|
439
|
+
body.append('file', file, file.name);
|
|
440
|
+
const response = await fetch(this.uploadUrl, {method: 'POST', body, credentials: 'same-origin'});
|
|
441
|
+
if (!response.ok) {
|
|
442
|
+
throw new Error(`upload failed with status ${response.status}`);
|
|
443
|
+
}
|
|
444
|
+
const data = await response.json() as { url?: string };
|
|
445
|
+
if (!data.url) {
|
|
446
|
+
throw new Error('upload response missing url');
|
|
447
|
+
}
|
|
448
|
+
this.src = data.url;
|
|
449
|
+
this.input.value = '';
|
|
450
|
+
this.files = null;
|
|
451
|
+
this.clearedByUser = false;
|
|
452
|
+
this.emit('zn-input');
|
|
453
|
+
this.emit('zn-change');
|
|
454
|
+
if (this.triggerSubmit) {
|
|
455
|
+
this.formControlController.submit();
|
|
456
|
+
}
|
|
457
|
+
} catch (error) {
|
|
458
|
+
console.warn('<zn-file> upload failed', error);
|
|
459
|
+
this.input.value = '';
|
|
460
|
+
this.files = null;
|
|
461
|
+
this.emit('zn-error');
|
|
462
|
+
} finally {
|
|
463
|
+
this.uploading = false;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
398
467
|
private handleDragOver = (e: DragEvent) => {
|
|
399
468
|
e.preventDefault();
|
|
400
469
|
e.stopPropagation();
|
|
@@ -698,6 +767,7 @@ export default class ZnFile extends ZincElement implements ZincFormControl {
|
|
|
698
767
|
'form-control--large': this.size === 'large',
|
|
699
768
|
'form-control--medium': this.size === 'medium',
|
|
700
769
|
'form-control--small': this.size === 'small',
|
|
770
|
+
'form-control--uploading': this.uploading,
|
|
701
771
|
'form-control--user-dragging': this.userIsDragging,
|
|
702
772
|
})}"
|
|
703
773
|
@dragenter="${this.handleDragOver}"
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// Canonical canvas card/container width, inherited by the section-card
|
|
6
6
|
// component's shadow styles (whose 560px var() fallback only applies when
|
|
7
7
|
// the card is used outside a builder).
|
|
8
|
-
--pb-card-width:
|
|
8
|
+
--pb-card-width: 1024px;
|
|
9
9
|
|
|
10
10
|
display: block;
|
|
11
11
|
width: 100%;
|