zidan-select 2.2.4 → 2.3.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.
- package/README.md +135 -55
- package/dist/file/plugin-file-core.css +38 -5
- package/dist/file/plugin-file-core.min.css +9 -0
- package/dist/file/plugin-file-theme.css +23 -6
- package/dist/file/plugin-file-theme.min.css +9 -0
- package/dist/file/zidan-file.d.ts +32 -0
- package/dist/file/zidan-file.js +286 -44
- package/dist/file/zidan-file.min.js +11 -0
- package/dist/plugin-core.css +214 -15
- package/dist/plugin-core.min.css +10 -0
- package/dist/plugin-theme.css +36 -6
- package/dist/plugin-theme.min.css +13 -0
- package/dist/select/plugin-select-core.css +22 -3
- package/dist/select/plugin-select-core.min.css +9 -0
- package/dist/select/plugin-select-theme.css +28 -4
- package/dist/select/plugin-select-theme.min.css +9 -0
- package/dist/select/zidan-select.d.ts +33 -0
- package/dist/select/zidan-select.js +377 -32
- package/dist/select/zidan-select.min.js +11 -0
- package/dist/zidan-form.js +696 -109
- package/dist/zidan-form.min.js +14 -0
- package/docs/build.md +20 -13
- package/docs/comparison.md +11 -6
- package/docs/html-and-wordpress.md +893 -0
- package/docs/index.html +21 -3
- package/docs/options.md +101 -20
- package/docs/validation.md +44 -1
- package/package.json +25 -2
- package/plugin-core.css +214 -15
- package/plugin-theme.css +36 -6
- package/zidan-form.d.ts +431 -0
- package/zidan-form.js +696 -109
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZidanForm File-only v2.3.1 — type definitions.
|
|
3
|
+
* https://github.com/akhtar1985/zidan-select
|
|
4
|
+
*/
|
|
5
|
+
export {
|
|
6
|
+
ZidanForm,
|
|
7
|
+
ZidanFileUpload,
|
|
8
|
+
ZidanFieldBase,
|
|
9
|
+
zidanField,
|
|
10
|
+
initZidanForms,
|
|
11
|
+
registerIcon
|
|
12
|
+
} from '../../zidan-form';
|
|
13
|
+
export type {
|
|
14
|
+
Framework,
|
|
15
|
+
Theme,
|
|
16
|
+
FieldLayout,
|
|
17
|
+
ValidationState,
|
|
18
|
+
AsyncValidationContext,
|
|
19
|
+
AsyncRuleResult,
|
|
20
|
+
RuleResult,
|
|
21
|
+
FieldRule,
|
|
22
|
+
FieldMessages,
|
|
23
|
+
FieldOptions,
|
|
24
|
+
FileFieldOptions,
|
|
25
|
+
UploadContext,
|
|
26
|
+
UploadHandler,
|
|
27
|
+
UploadState,
|
|
28
|
+
ZidanFormStatic,
|
|
29
|
+
AutoInitTarget,
|
|
30
|
+
AutoInitConfig
|
|
31
|
+
} from '../../zidan-form';
|
|
32
|
+
export { default } from '../../zidan-form';
|
package/dist/file/zidan-file.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* ZidanForm File-only v2.
|
|
2
|
+
* ZidanForm File-only v2.3.1
|
|
3
3
|
* Zero-dependency drag & drop file upload with variants, previews, limits and progress.
|
|
4
4
|
* Pairs with plugin-file-core.css and plugin-file-theme.css.
|
|
5
5
|
*
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
})(typeof window !== 'undefined' ? window : this, function (global) {
|
|
30
30
|
'use strict';
|
|
31
31
|
|
|
32
|
-
var VERSION = '2.
|
|
32
|
+
var VERSION = '2.3.1';
|
|
33
33
|
|
|
34
34
|
// Loading the file twice (classic script + module wrapper, or two bundles)
|
|
35
35
|
// must not replace the classes and orphan the live instances.
|
|
@@ -93,6 +93,24 @@
|
|
|
93
93
|
return Array.isArray(value) ? value.slice() : [value];
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
function isThenable(value) {
|
|
97
|
+
return !!(value && (typeof value === 'object' || typeof value === 'function') && typeof value.then === 'function');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/* true when the element renders right-to-left, following the nearest dir attribute */
|
|
101
|
+
function isRtl(element) {
|
|
102
|
+
if (!element) return false;
|
|
103
|
+
var host = element.closest ? element.closest('[dir]') : null;
|
|
104
|
+
var dir = host ? host.getAttribute('dir') : '';
|
|
105
|
+
if (!dir && doc && doc.documentElement) dir = doc.documentElement.getAttribute('dir') || '';
|
|
106
|
+
if (dir) return String(dir).toLowerCase() === 'rtl';
|
|
107
|
+
try {
|
|
108
|
+
return !!(global.getComputedStyle && global.getComputedStyle(element).direction === 'rtl');
|
|
109
|
+
} catch (err) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
96
114
|
function isElement(value) {
|
|
97
115
|
return !!(value && typeof value === 'object' && value.nodeType === 1);
|
|
98
116
|
}
|
|
@@ -288,9 +306,9 @@
|
|
|
288
306
|
}
|
|
289
307
|
|
|
290
308
|
function registerIcon(name, markup) {
|
|
291
|
-
if (!name || typeof markup !== 'string') return ZidanSelect;
|
|
292
|
-
ICON_REGISTRY[String(name)] = markup;
|
|
293
|
-
return ZidanSelect;
|
|
309
|
+
if (typeof ZidanSelect !== 'undefined' && (!name || typeof markup !== 'string')) return ZidanSelect;
|
|
310
|
+
if (name && typeof markup === 'string') ICON_REGISTRY[String(name)] = markup;
|
|
311
|
+
return typeof ZidanSelect !== 'undefined' ? ZidanSelect : ZidanForm;
|
|
294
312
|
}
|
|
295
313
|
|
|
296
314
|
/* ---------------- field options (JS options + data-* attributes) ---------------- */
|
|
@@ -348,6 +366,7 @@
|
|
|
348
366
|
fileType: 'This file type is not allowed.',
|
|
349
367
|
fileSize: 'This file is too large.',
|
|
350
368
|
fileCount: 'Too many files.',
|
|
369
|
+
pending: 'Checking…',
|
|
351
370
|
generic: 'Please check this field.'
|
|
352
371
|
};
|
|
353
372
|
|
|
@@ -375,6 +394,20 @@
|
|
|
375
394
|
return fillTemplate(map[key] || FIELD_MESSAGES[key] || map.generic, vars);
|
|
376
395
|
}
|
|
377
396
|
|
|
397
|
+
var NATIVE_VALIDITY_FLAGS = ['valueMissing', 'typeMismatch', 'patternMismatch', 'rangeUnderflow',
|
|
398
|
+
'rangeOverflow', 'stepMismatch', 'tooShort', 'tooLong', 'badInput', 'fileMissing'];
|
|
399
|
+
|
|
400
|
+
/* customError is the library mirroring its own message onto the input, so re-reading it
|
|
401
|
+
would turn a pending/custom check into a phantom native constraint failure */
|
|
402
|
+
function hasNativeValidityError(input) {
|
|
403
|
+
var v = input && input.validity;
|
|
404
|
+
if (!v) return false;
|
|
405
|
+
for (var i = 0; i < NATIVE_VALIDITY_FLAGS.length; i += 1) {
|
|
406
|
+
if (v[NATIVE_VALIDITY_FLAGS[i]]) return true;
|
|
407
|
+
}
|
|
408
|
+
return false;
|
|
409
|
+
}
|
|
410
|
+
|
|
378
411
|
/* first non-empty value of any of `names`, walking up the tree */
|
|
379
412
|
function inheritedAttr(node, names) {
|
|
380
413
|
var current = node;
|
|
@@ -393,6 +426,24 @@
|
|
|
393
426
|
return list.indexOf(candidate) === -1 ? fallback : candidate;
|
|
394
427
|
}
|
|
395
428
|
|
|
429
|
+
/* rangeTicks: JS array, JSON array, comma list or a tick count */
|
|
430
|
+
function parseRangeTicks(value) {
|
|
431
|
+
if (Array.isArray(value)) return value.slice();
|
|
432
|
+
if (typeof value === 'string') {
|
|
433
|
+
var raw = value.trim();
|
|
434
|
+
if (raw.charAt(0) === '[') {
|
|
435
|
+
try {
|
|
436
|
+
var parsed = JSON.parse(raw);
|
|
437
|
+
if (Array.isArray(parsed)) return parsed;
|
|
438
|
+
} catch (err) { /* fall back to the tick count */ }
|
|
439
|
+
} else if (raw.indexOf(',') !== -1) {
|
|
440
|
+
return raw.split(',').map(function (part) { return Number(part.trim()); })
|
|
441
|
+
.filter(function (number) { return isFinite(number); });
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
return value;
|
|
445
|
+
}
|
|
446
|
+
|
|
396
447
|
/* theme/framework/layout resolution shared by every field and the select */
|
|
397
448
|
function resolveScope(node, options) {
|
|
398
449
|
var opts = options || {};
|
|
@@ -439,6 +490,8 @@
|
|
|
439
490
|
var RADIO_VARIANTS = ['stacked', 'inline', 'card', 'button', 'tile'];
|
|
440
491
|
var FILE_VARIANTS = ['dropzone', 'button', 'avatar', 'gallery', 'compact'];
|
|
441
492
|
var RANGE_VARIANTS = ['default', 'gradient', 'stepped', 'minimal'];
|
|
493
|
+
var RANGE_BUBBLE_MODES = ['always', 'active', 'never'];
|
|
494
|
+
var RANGE_BUBBLE_POSITIONS = ['top', 'bottom'];
|
|
442
495
|
|
|
443
496
|
function textWithout(rootNode, skip) {
|
|
444
497
|
var out = '';
|
|
@@ -471,9 +524,13 @@
|
|
|
471
524
|
this.validation = null;
|
|
472
525
|
this.errorMessage = null;
|
|
473
526
|
this.errorEl = null;
|
|
527
|
+
this.pending = false;
|
|
528
|
+
this._asyncToken = 0;
|
|
529
|
+
this._asyncController = null;
|
|
474
530
|
this.destroyed = false;
|
|
475
531
|
this._listeners = [];
|
|
476
532
|
this._cleanups = [];
|
|
533
|
+
this._describedByBefore = [];
|
|
477
534
|
this.formEl = target.form || (target.closest ? target.closest('form') : null);
|
|
478
535
|
var scope = resolveScope(target, this.opts);
|
|
479
536
|
this.theme = scope.theme;
|
|
@@ -511,6 +568,7 @@
|
|
|
511
568
|
root.id = this.id + '-field';
|
|
512
569
|
root.setAttribute('data-zs-kind', kind);
|
|
513
570
|
root.classList.add('zs-field--' + kind);
|
|
571
|
+
if (isRtl(this.el)) root.setAttribute('dir', 'rtl');
|
|
514
572
|
this._applyScope(root);
|
|
515
573
|
this.root = root;
|
|
516
574
|
return root;
|
|
@@ -561,15 +619,133 @@
|
|
|
561
619
|
var targets = this.validationTargets();
|
|
562
620
|
for (var i = 0; i < targets.length; i += 1) {
|
|
563
621
|
var input = targets[i];
|
|
564
|
-
if (input
|
|
622
|
+
if (hasNativeValidityError(input)) return this._messageFor(input);
|
|
565
623
|
}
|
|
566
624
|
return '';
|
|
567
625
|
};
|
|
568
626
|
|
|
569
|
-
|
|
627
|
+
/* subclasses forward this context to async validators so they can abort */
|
|
628
|
+
ZidanFieldBase.prototype._asyncSignal = function () {
|
|
629
|
+
return this._asyncController ? this._asyncController.signal : undefined;
|
|
630
|
+
};
|
|
631
|
+
|
|
632
|
+
ZidanFieldBase.prototype._asyncContext = function () {
|
|
633
|
+
return { signal: this._asyncSignal(), field: this, instance: this };
|
|
634
|
+
};
|
|
635
|
+
|
|
636
|
+
/* text inputs override this to block form submission while pending/invalid */
|
|
637
|
+
ZidanFieldBase.prototype._setCustomValidity = function () {};
|
|
638
|
+
|
|
639
|
+
ZidanFieldBase.prototype._abortAsync = function () {
|
|
640
|
+
this._asyncToken += 1;
|
|
641
|
+
if (this._asyncController) {
|
|
642
|
+
try { this._asyncController.abort(); } catch (err) { /* already settled */ }
|
|
643
|
+
this._asyncController = null;
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
/* returns { pending: promise } for async checks, otherwise { error, custom } */
|
|
648
|
+
ZidanFieldBase.prototype._evaluate = function () {
|
|
649
|
+
this._abortAsync();
|
|
650
|
+
if (typeof AbortController !== 'undefined') this._asyncController = new AbortController();
|
|
570
651
|
var custom = this._customError ? this._customError() : '';
|
|
571
|
-
if (custom) return
|
|
572
|
-
|
|
652
|
+
if (isThenable(custom)) return { pending: custom };
|
|
653
|
+
this._asyncController = null;
|
|
654
|
+
if (custom) {
|
|
655
|
+
return { error: typeof custom === 'string' ? custom : this.opts.messages.generic, custom: true };
|
|
656
|
+
}
|
|
657
|
+
var native = this._nativeError();
|
|
658
|
+
return native ? { error: native, custom: false } : {};
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
ZidanFieldBase.prototype._applyValidity = function (message, show, custom) {
|
|
662
|
+
this._setCustomValidity(message && custom ? message : '');
|
|
663
|
+
if (message) {
|
|
664
|
+
if (show) this.setError(message);
|
|
665
|
+
else this.setValidation('invalid', true);
|
|
666
|
+
return this;
|
|
667
|
+
}
|
|
668
|
+
if (this.errorMessage) this.setError(null);
|
|
669
|
+
/* keep an initial or manually set invalid state until the user interacts */
|
|
670
|
+
if (this.validation === 'invalid' && !this._presetValidation) this.setValidation(null, true);
|
|
671
|
+
return this;
|
|
672
|
+
};
|
|
673
|
+
|
|
674
|
+
ZidanFieldBase.prototype._setPending = function (on) {
|
|
675
|
+
on = !!on;
|
|
676
|
+
this.pending = on;
|
|
677
|
+
if (this.root) {
|
|
678
|
+
this.root.classList.toggle('zs-field--pending', on);
|
|
679
|
+
if (on) {
|
|
680
|
+
this.root.setAttribute('data-zs-validation', 'pending');
|
|
681
|
+
} else if (this.root.getAttribute('data-zs-validation') === 'pending') {
|
|
682
|
+
this.root.removeAttribute('data-zs-validation');
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
this.validationTargets().forEach(function (input) {
|
|
686
|
+
if (!input || !input.setAttribute) return;
|
|
687
|
+
if (on) input.setAttribute('aria-busy', 'true');
|
|
688
|
+
else input.removeAttribute('aria-busy');
|
|
689
|
+
}, this);
|
|
690
|
+
if (on) {
|
|
691
|
+
if (this.errorMessage) this.setError(null);
|
|
692
|
+
this._setCustomValidity(this.opts.messages.pending || FIELD_MESSAGES.pending);
|
|
693
|
+
} else {
|
|
694
|
+
this._setCustomValidity('');
|
|
695
|
+
}
|
|
696
|
+
return this;
|
|
697
|
+
};
|
|
698
|
+
|
|
699
|
+
ZidanFieldBase.prototype._runAsync = function (promise) {
|
|
700
|
+
var self = this;
|
|
701
|
+
if (self.destroyed) return Promise.resolve(false);
|
|
702
|
+
var token = self._asyncToken;
|
|
703
|
+
self._setPending(true);
|
|
704
|
+
return Promise.resolve(promise).then(function (value) {
|
|
705
|
+
if (self.destroyed || token !== self._asyncToken) return false;
|
|
706
|
+
self._asyncController = null;
|
|
707
|
+
self._setPending(false);
|
|
708
|
+
var message = '';
|
|
709
|
+
if (value === false) message = self.opts.messages.generic;
|
|
710
|
+
else if (typeof value === 'string') message = value;
|
|
711
|
+
else if (value instanceof Error) message = value.message || self.opts.messages.generic;
|
|
712
|
+
self._applyValidity(message, self.touched || self.opts.alwaysValidate || !!message, true);
|
|
713
|
+
if (!message && self.opts.showValidState) self.setValidation('valid');
|
|
714
|
+
self.emit('async-validation', { valid: !message, message: message });
|
|
715
|
+
return !message;
|
|
716
|
+
}, function (err) {
|
|
717
|
+
if (self.destroyed || token !== self._asyncToken || (err && err.name === 'AbortError')) return false;
|
|
718
|
+
self._asyncController = null;
|
|
719
|
+
self._setPending(false);
|
|
720
|
+
var message = (err && (err.message || err.error)) || self.opts.messages.generic;
|
|
721
|
+
if (typeof message !== 'string') message = self.opts.messages.generic;
|
|
722
|
+
self._applyValidity(message, true, true);
|
|
723
|
+
self.emit('async-validation', { valid: false, message: message, error: err });
|
|
724
|
+
return false;
|
|
725
|
+
});
|
|
726
|
+
};
|
|
727
|
+
|
|
728
|
+
/* convenience: resolves with the async result, false when sync-invalid, true when sync-valid */
|
|
729
|
+
ZidanFieldBase.prototype.checkAsync = function () {
|
|
730
|
+
var result = this._evaluate();
|
|
731
|
+
if (result.pending) return this._runAsync(result.pending);
|
|
732
|
+
return Promise.resolve(!result.error);
|
|
733
|
+
};
|
|
734
|
+
|
|
735
|
+
ZidanFieldBase.prototype._trackDescribedBy = function (input) {
|
|
736
|
+
if (!input || !input.getAttribute) return;
|
|
737
|
+
for (var i = 0; i < this._describedByBefore.length; i += 1) {
|
|
738
|
+
if (this._describedByBefore[i][0] === input) return;
|
|
739
|
+
}
|
|
740
|
+
this._describedByBefore.push([input, input.getAttribute('aria-describedby')]);
|
|
741
|
+
};
|
|
742
|
+
|
|
743
|
+
ZidanFieldBase.prototype._addDescribedBy = function (input, id) {
|
|
744
|
+
if (!input || !input.getAttribute || !id) return;
|
|
745
|
+
this._trackDescribedBy(input);
|
|
746
|
+
var current = (input.getAttribute('aria-describedby') || '').split(/\s+/).filter(Boolean);
|
|
747
|
+
if (current.indexOf(id) === -1) current.push(id);
|
|
748
|
+
input.setAttribute('aria-describedby', current.join(' '));
|
|
573
749
|
};
|
|
574
750
|
|
|
575
751
|
ZidanFieldBase.prototype._syncDescribedBy = function () {
|
|
@@ -580,6 +756,7 @@
|
|
|
580
756
|
var targets = this.validationTargets();
|
|
581
757
|
targets.forEach(function (input) {
|
|
582
758
|
if (!input || !input.getAttribute) return;
|
|
759
|
+
this._trackDescribedBy(input);
|
|
583
760
|
var current = (input.getAttribute('aria-describedby') || '').split(/\s+/).filter(Boolean);
|
|
584
761
|
var next = current.filter(function (id) { return id !== errorId && id !== hintId; });
|
|
585
762
|
if (hintId) next.push(hintId);
|
|
@@ -637,22 +814,35 @@
|
|
|
637
814
|
this.validationTargets().forEach(function (input) {
|
|
638
815
|
self.on(input, 'invalid', function () {
|
|
639
816
|
self.touched = true;
|
|
640
|
-
var
|
|
641
|
-
if (
|
|
817
|
+
var result = self._evaluate();
|
|
818
|
+
if (result.pending) {
|
|
819
|
+
self._runAsync(result.pending);
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
if (result.error) self.setError(result.error);
|
|
642
823
|
else self.setValidation('invalid');
|
|
643
824
|
});
|
|
644
825
|
self.on(input, 'blur', function () {
|
|
645
826
|
self.touched = true;
|
|
827
|
+
self._presetValidation = false;
|
|
828
|
+
self._mirrorValidity();
|
|
829
|
+
});
|
|
830
|
+
self.on(input, 'input', function () {
|
|
831
|
+
self._presetValidation = false;
|
|
832
|
+
self._mirrorValidity();
|
|
833
|
+
});
|
|
834
|
+
self.on(input, 'change', function () {
|
|
835
|
+
self._presetValidation = false;
|
|
646
836
|
self._mirrorValidity();
|
|
647
837
|
});
|
|
648
|
-
self.on(input, 'input', function () { self._mirrorValidity(); });
|
|
649
|
-
self.on(input, 'change', function () { self._mirrorValidity(); });
|
|
650
838
|
});
|
|
651
839
|
this.on(this.formEl, 'reset', function () {
|
|
652
840
|
global.setTimeout(function () {
|
|
653
841
|
if (self.destroyed) return;
|
|
842
|
+
self._abortAsync();
|
|
654
843
|
self.touched = false;
|
|
655
844
|
self.errorMessage = null;
|
|
845
|
+
self._setPending(false);
|
|
656
846
|
if (self.errorEl) {
|
|
657
847
|
self.errorEl.textContent = '';
|
|
658
848
|
self.errorEl.hidden = true;
|
|
@@ -668,31 +858,35 @@
|
|
|
668
858
|
};
|
|
669
859
|
|
|
670
860
|
ZidanFieldBase.prototype._mirrorValidity = function () {
|
|
671
|
-
var
|
|
672
|
-
if (
|
|
673
|
-
|
|
674
|
-
else this.setValidation('invalid');
|
|
861
|
+
var result = this._evaluate();
|
|
862
|
+
if (result.pending) {
|
|
863
|
+
this._runAsync(result.pending);
|
|
675
864
|
return this;
|
|
676
865
|
}
|
|
677
|
-
if (this.
|
|
678
|
-
|
|
866
|
+
if (this.pending) this._setPending(false);
|
|
867
|
+
this._applyValidity(result.error || '', this.touched || this.opts.alwaysValidate, result.custom);
|
|
679
868
|
return this;
|
|
680
869
|
};
|
|
681
870
|
|
|
871
|
+
/* returns a boolean for sync rules and a Promise<boolean> when an async rule runs */
|
|
682
872
|
ZidanFieldBase.prototype.validate = function () {
|
|
683
873
|
this.touched = true;
|
|
684
|
-
var
|
|
685
|
-
if (
|
|
686
|
-
|
|
874
|
+
var result = this._evaluate();
|
|
875
|
+
if (result.pending) return this._runAsync(result.pending);
|
|
876
|
+
if (this.pending) this._setPending(false);
|
|
877
|
+
if (result.error) {
|
|
878
|
+
this._applyValidity(result.error, true, result.custom);
|
|
687
879
|
return false;
|
|
688
880
|
}
|
|
689
|
-
this.
|
|
881
|
+
this._applyValidity('', true, false);
|
|
690
882
|
if (this.opts.showValidState) this.setValidation('valid');
|
|
691
883
|
return true;
|
|
692
884
|
};
|
|
693
885
|
|
|
694
|
-
ZidanFieldBase.prototype.setValidation = function (state) {
|
|
886
|
+
ZidanFieldBase.prototype.setValidation = function (state, internal) {
|
|
695
887
|
this.validation = VALIDATION_STATES.indexOf(state) === -1 ? null : state;
|
|
888
|
+
/* public calls pin the state; internal mirrors may clear it again */
|
|
889
|
+
if (!internal) this._presetValidation = this.validation === 'invalid';
|
|
696
890
|
var invalid = this.validation === 'invalid' || !!this.errorMessage;
|
|
697
891
|
if (this.root) {
|
|
698
892
|
this.root.classList.toggle('zs-field--invalid', invalid);
|
|
@@ -716,6 +910,10 @@
|
|
|
716
910
|
return this.validation;
|
|
717
911
|
};
|
|
718
912
|
|
|
913
|
+
ZidanFieldBase.prototype.isPending = function () {
|
|
914
|
+
return this.pending;
|
|
915
|
+
};
|
|
916
|
+
|
|
719
917
|
ZidanFieldBase.prototype.getValue = function () {
|
|
720
918
|
var el = this.el;
|
|
721
919
|
if (!el) return null;
|
|
@@ -770,6 +968,7 @@
|
|
|
770
968
|
ZidanFieldBase.prototype.destroy = function () {
|
|
771
969
|
if (this.destroyed) return this;
|
|
772
970
|
this.destroyed = true;
|
|
971
|
+
this._abortAsync();
|
|
773
972
|
this._listeners.forEach(function (entry) {
|
|
774
973
|
entry[0].removeEventListener(entry[1], entry[2], entry[3]);
|
|
775
974
|
});
|
|
@@ -778,7 +977,16 @@
|
|
|
778
977
|
this._cleanups.forEach(function (fn) { fn(); });
|
|
779
978
|
this._cleanups.length = 0;
|
|
780
979
|
this.emit('destroy', {});
|
|
781
|
-
|
|
980
|
+
/* radio groups use the author's <fieldset> as their root: removing it would
|
|
981
|
+
delete the original radios too, so only remove roots the field created. */
|
|
982
|
+
if (this.root && this.root !== this.el && this.root.parentNode) this.root.parentNode.removeChild(this.root);
|
|
983
|
+
this._describedByBefore.forEach(function (entry) {
|
|
984
|
+
var input = entry[0];
|
|
985
|
+
if (!input || !input.getAttribute) return;
|
|
986
|
+
if (entry[1] === null || entry[1] === undefined) input.removeAttribute('aria-describedby');
|
|
987
|
+
else input.setAttribute('aria-describedby', entry[1]);
|
|
988
|
+
});
|
|
989
|
+
this._describedByBefore = [];
|
|
782
990
|
if (this.el.__zidanField === this) delete this.el.__zidanField;
|
|
783
991
|
ZidanForm._unregister(this);
|
|
784
992
|
return this;
|
|
@@ -953,6 +1161,22 @@
|
|
|
953
1161
|
|
|
954
1162
|
self.on(clearBtn, 'click', function () { self.clear(); });
|
|
955
1163
|
|
|
1164
|
+
/* Delegated once: the list is rebuilt on every upload progress tick, so
|
|
1165
|
+
per-item listeners would grow without bound. */
|
|
1166
|
+
self.on(list, 'click', function (event) {
|
|
1167
|
+
var button = event.target && event.target.closest ? event.target.closest('button') : null;
|
|
1168
|
+
if (!button || !list.contains(button)) return;
|
|
1169
|
+
var item = button.closest('.zs-file-item');
|
|
1170
|
+
var index = item ? parseInt(item.getAttribute('data-zs-file-index'), 10) : -1;
|
|
1171
|
+
var file = index >= 0 ? self.getFiles()[index] : null;
|
|
1172
|
+
if (!file) return;
|
|
1173
|
+
event.preventDefault();
|
|
1174
|
+
event.stopPropagation();
|
|
1175
|
+
if (button.classList.contains('zs-file-cancel')) self.cancelUpload(file);
|
|
1176
|
+
else if (button.classList.contains('zs-file-retry')) self.retryUpload(file);
|
|
1177
|
+
else if (button.classList.contains('zs-file-remove')) self.removeFile(file);
|
|
1178
|
+
});
|
|
1179
|
+
|
|
956
1180
|
this._bindValidity();
|
|
957
1181
|
this.on(this.formEl, 'reset', function () {
|
|
958
1182
|
global.setTimeout(function () {
|
|
@@ -1110,8 +1334,19 @@
|
|
|
1110
1334
|
};
|
|
1111
1335
|
};
|
|
1112
1336
|
|
|
1337
|
+
ZidanFileUpload.prototype._setCustomValidity = function (message) {
|
|
1338
|
+
if (this.el && this.el.setCustomValidity) this.el.setCustomValidity(message || '');
|
|
1339
|
+
};
|
|
1340
|
+
|
|
1113
1341
|
ZidanFileUpload.prototype._customError = function () {
|
|
1114
|
-
|
|
1342
|
+
if (this.fileError) return this.fileError;
|
|
1343
|
+
if (typeof this.opts.validate === 'function') {
|
|
1344
|
+
var result = this.opts.validate(this.getFiles(), this, this._asyncContext());
|
|
1345
|
+
if (result === false) return this.opts.messages.generic;
|
|
1346
|
+
if (typeof result === 'string' && result) return result;
|
|
1347
|
+
if (isThenable(result)) return result;
|
|
1348
|
+
}
|
|
1349
|
+
return '';
|
|
1115
1350
|
};
|
|
1116
1351
|
|
|
1117
1352
|
ZidanFileUpload.prototype._validate = function () {
|
|
@@ -1148,7 +1383,9 @@
|
|
|
1148
1383
|
}
|
|
1149
1384
|
|
|
1150
1385
|
this.fileError = error;
|
|
1151
|
-
if (input.setCustomValidity)
|
|
1386
|
+
if (input.setCustomValidity) {
|
|
1387
|
+
input.setCustomValidity(this.pending ? (messages.pending || FIELD_MESSAGES.pending) : (error || ''));
|
|
1388
|
+
}
|
|
1152
1389
|
var shown = error || this._nativeError();
|
|
1153
1390
|
if (shown) this.setError(shown);
|
|
1154
1391
|
else if (this.errorMessage) this.setError(null);
|
|
@@ -1236,6 +1473,7 @@
|
|
|
1236
1473
|
var state = self._stateFor(file, false) || { status: 'idle', progress: 0, error: '', result: null };
|
|
1237
1474
|
var item = el('li', 'zs-file-item');
|
|
1238
1475
|
item.setAttribute('data-zs-upload-state', state.status);
|
|
1476
|
+
item.setAttribute('data-zs-file-index', String(index));
|
|
1239
1477
|
|
|
1240
1478
|
var thumb = el('span', 'zs-file-thumb');
|
|
1241
1479
|
if (/^image\//.test(file.type)) {
|
|
@@ -1285,30 +1523,15 @@
|
|
|
1285
1523
|
if (state.status === 'uploading') {
|
|
1286
1524
|
var cancel = el('button', 'zs-file-cancel', { type: 'button', 'aria-label': 'Cancel upload of ' + file.name });
|
|
1287
1525
|
cancel.textContent = opts.cancelLabel || 'Cancel';
|
|
1288
|
-
self.on(cancel, 'click', function (event) {
|
|
1289
|
-
event.preventDefault();
|
|
1290
|
-
event.stopPropagation();
|
|
1291
|
-
self.cancelUpload(file);
|
|
1292
|
-
});
|
|
1293
1526
|
actions.appendChild(cancel);
|
|
1294
1527
|
} else if (state.status === 'error' || state.status === 'canceled') {
|
|
1295
1528
|
var retry = el('button', 'zs-file-retry', { type: 'button', 'aria-label': 'Retry upload of ' + file.name });
|
|
1296
1529
|
retry.textContent = opts.retryLabel || 'Retry';
|
|
1297
|
-
self.on(retry, 'click', function (event) {
|
|
1298
|
-
event.preventDefault();
|
|
1299
|
-
event.stopPropagation();
|
|
1300
|
-
self.retryUpload(file);
|
|
1301
|
-
});
|
|
1302
1530
|
actions.appendChild(retry);
|
|
1303
1531
|
}
|
|
1304
1532
|
|
|
1305
1533
|
var remove = el('button', 'zs-file-remove', { type: 'button', 'aria-label': 'Remove ' + file.name });
|
|
1306
1534
|
remove.textContent = '\u00d7';
|
|
1307
|
-
self.on(remove, 'click', function (event) {
|
|
1308
|
-
event.preventDefault();
|
|
1309
|
-
event.stopPropagation();
|
|
1310
|
-
self.removeFile(file);
|
|
1311
|
-
});
|
|
1312
1535
|
actions.appendChild(remove);
|
|
1313
1536
|
|
|
1314
1537
|
item.appendChild(thumb);
|
|
@@ -1375,6 +1598,14 @@
|
|
|
1375
1598
|
var self = this;
|
|
1376
1599
|
if (!this.hasUploader) return this;
|
|
1377
1600
|
if (!this._validate()) return this;
|
|
1601
|
+
var check = this.validate();
|
|
1602
|
+
if (isThenable(check)) {
|
|
1603
|
+
return check.then(function (valid) {
|
|
1604
|
+
if (valid && !self.destroyed) self.getFiles().forEach(function (file) { self.uploadFile(file); });
|
|
1605
|
+
return valid;
|
|
1606
|
+
});
|
|
1607
|
+
}
|
|
1608
|
+
if (!check) return this;
|
|
1378
1609
|
this.getFiles().forEach(function (file) { self.uploadFile(file); });
|
|
1379
1610
|
return this;
|
|
1380
1611
|
};
|
|
@@ -1638,7 +1869,11 @@
|
|
|
1638
1869
|
// (output, counter, clearable, …) work without a data attribute
|
|
1639
1870
|
var kind = fieldKindFor(node) || inferredTextKind(node);
|
|
1640
1871
|
if (!kind) return;
|
|
1641
|
-
if (kind === 'radio'
|
|
1872
|
+
if (kind === 'radio' || kind === 'radio-group') {
|
|
1873
|
+
if (/^INPUT$/i.test(node.tagName)) {
|
|
1874
|
+
node = node.closest ? node.closest('fieldset, [data-zidan-radio-group]') : null;
|
|
1875
|
+
if (!node) return;
|
|
1876
|
+
}
|
|
1642
1877
|
kind = 'radio-group';
|
|
1643
1878
|
}
|
|
1644
1879
|
var instance = createField(node, kind, options || {});
|
|
@@ -1653,7 +1888,13 @@
|
|
|
1653
1888
|
if (!isElement(node) || node.__zidanField) return;
|
|
1654
1889
|
var kind = fieldKindFor(node);
|
|
1655
1890
|
if (!kind) return;
|
|
1656
|
-
if (kind === 'radio'
|
|
1891
|
+
if (kind === 'radio' || kind === 'radio-group') {
|
|
1892
|
+
if (/^INPUT$/i.test(node.tagName)) {
|
|
1893
|
+
node = node.closest ? node.closest('fieldset, [data-zidan-radio-group]') : null;
|
|
1894
|
+
if (!node) return;
|
|
1895
|
+
}
|
|
1896
|
+
kind = 'radio-group';
|
|
1897
|
+
}
|
|
1657
1898
|
var instance = createField(node, kind, options || {});
|
|
1658
1899
|
if (instance) instances.push(instance);
|
|
1659
1900
|
});
|
|
@@ -1758,6 +1999,7 @@
|
|
|
1758
1999
|
ZidanSelect.frameworks = FRAMEWORKS.slice();
|
|
1759
2000
|
ZidanSelect.scrollbars = SCROLLBARS.slice();
|
|
1760
2001
|
ZidanSelect.defaults = DEFAULTS;
|
|
2002
|
+
ZidanSelect.cacheLimit = 50;
|
|
1761
2003
|
ZidanSelect.get = function (target) {
|
|
1762
2004
|
var element = typeof target === 'string' ? doc.querySelector(target) : target;
|
|
1763
2005
|
if (!isElement(element)) return null;
|