ember-headless-form 1.0.0-beta.3 → 1.0.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/dist/-private/components/control/checkbox.js.map +1 -1
- package/dist/-private/components/control/input.js.map +1 -1
- package/dist/-private/components/control/radio-group/label.d.ts +1 -0
- package/dist/-private/components/control/radio-group/label.js.map +1 -1
- package/dist/-private/components/control/radio-group/radio/input.d.ts +1 -0
- package/dist/-private/components/control/radio-group/radio/input.js.map +1 -1
- package/dist/-private/components/control/radio-group/radio.js.map +1 -1
- package/dist/-private/components/control/radio-group.d.ts +1 -0
- package/dist/-private/components/control/radio-group.js.map +1 -1
- package/dist/-private/components/control/select/option.js.map +1 -1
- package/dist/-private/components/control/select.js.map +1 -1
- package/dist/-private/components/control/textarea.js.map +1 -1
- package/dist/-private/components/errors.js.map +1 -1
- package/dist/-private/components/field.d.ts +1 -0
- package/dist/-private/components/field.js.map +1 -1
- package/dist/-private/components/label.d.ts +1 -0
- package/dist/-private/components/label.js.map +1 -1
- package/dist/-private/modifiers/capture-events.js.map +1 -1
- package/dist/-private/utils.js.map +1 -1
- package/dist/components/headless-form.js +17 -7
- package/dist/components/headless-form.js.map +1 -1
- package/package.json +10 -13
- package/README.md +0 -39
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"capture-events.js","sources":["../../../src/-private/modifiers/capture-events.ts"],"sourcesContent":["import { modifier } from 'ember-modifier';\n\nexport interface CaptureEventsModifierSignature {\n Element: HTMLElement;\n Args: {\n Named: {\n /*\n * @internal\n */\n event: 'focusout' | 'change' | 'input' | undefined;\n\n /*\n * @internal\n */\n triggerValidation(): void;\n };\n };\n}\n\nconst CaptureEventsModifier = modifier<CaptureEventsModifierSignature>(\n (element, _pos, { event, triggerValidation }) => {\n if (event) {\n element.addEventListener(event, triggerValidation, { passive: true });\n\n return () => {\n element.removeEventListener(event, triggerValidation);\n };\n }\n }\n);\n\nexport default CaptureEventsModifier;\n"],"names":["CaptureEventsModifier","modifier","element","_pos","event","triggerValidation","addEventListener","passive","removeEventListener"],"mappings":";;AAmBMA,MAAAA,qBAAqB,GAAGC,QAAQ,CACpC,CAACC,OAAO,EAAEC,IAAI,EAAE;EAAEC,KAAK;AAAEC,EAAAA,iBAAAA;AAAkB,CAAC,KAAK;AAC/C,EAAA,IAAID,KAAK,EAAE;AACTF,IAAAA,OAAO,CAACI,gBAAgB,CAACF,KAAK,EAAEC,iBAAiB,EAAE;AAAEE,MAAAA,OAAO,EAAE,IAAA;AAAK,KAAC,CAAC,CAAA;AAErE,IAAA,OAAO,MAAM;AACXL,MAAAA,OAAO,CAACM,mBAAmB,CAACJ,KAAK,EAAEC,iBAAiB,CAAC,CAAA;KACtD,CAAA;AACH,GAAA;AACF,
|
1
|
+
{"version":3,"file":"capture-events.js","sources":["../../../src/-private/modifiers/capture-events.ts"],"sourcesContent":["import { modifier } from 'ember-modifier';\n\nexport interface CaptureEventsModifierSignature {\n Element: HTMLElement;\n Args: {\n Named: {\n /*\n * @internal\n */\n event: 'focusout' | 'change' | 'input' | undefined;\n\n /*\n * @internal\n */\n triggerValidation(): void;\n };\n };\n}\n\nconst CaptureEventsModifier = modifier<CaptureEventsModifierSignature>(\n (element, _pos, { event, triggerValidation }) => {\n if (event) {\n element.addEventListener(event, triggerValidation, { passive: true });\n\n return () => {\n element.removeEventListener(event, triggerValidation);\n };\n }\n }\n);\n\nexport default CaptureEventsModifier;\n"],"names":["CaptureEventsModifier","modifier","element","_pos","event","triggerValidation","addEventListener","passive","removeEventListener"],"mappings":";;AAmBMA,MAAAA,qBAAqB,GAAGC,QAAQ,CACpC,CAACC,OAAO,EAAEC,IAAI,EAAE;EAAEC,KAAK;AAAEC,EAAAA,iBAAAA;AAAkB,CAAC,KAAK;AAC/C,EAAA,IAAID,KAAK,EAAE;AACTF,IAAAA,OAAO,CAACI,gBAAgB,CAACF,KAAK,EAAEC,iBAAiB,EAAE;AAAEE,MAAAA,OAAO,EAAE,IAAA;AAAK,KAAC,CAAC,CAAA;AAErE,IAAA,OAAO,MAAM;AACXL,MAAAA,OAAO,CAACM,mBAAmB,CAACJ,KAAK,EAAEC,iBAAiB,CAAC,CAAA;KACtD,CAAA;AACH,GAAA;AACF,CACF;;;;"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../src/-private/utils.ts"],"sourcesContent":["import type { ErrorRecord, FormData, FormKey, ValidationError } from './types';\n\nexport function mergeErrorRecord<\n DATA extends FormData,\n KEY extends FormKey<DATA> = FormKey<DATA>\n>(\n ...records: Array<ErrorRecord<DATA, KEY> | undefined>\n): ErrorRecord<DATA, KEY> {\n const errors: ErrorRecord<DATA, KEY> = {};\n\n for (const record of records) {\n if (!record) {\n continue;\n }\n\n for (const [name, fieldErrors] of Object.entries(record) as [\n // TS does not infer the types correctly here, fieldErrors would be unknown, not sure why\n KEY,\n ValidationError<DATA[KEY]>[]\n ][]) {\n const existingFieldErrors = errors[name];\n\n errors[name] = existingFieldErrors\n ? [...existingFieldErrors, ...fieldErrors]\n : fieldErrors;\n }\n }\n\n return errors;\n}\n\n// this is copy pasted from https://github.com/emberjs/ember.js/blob/60d2e0cddb353aea0d6e36a72fda971010d92355/packages/%40ember/-internals/glimmer/lib/helpers/unique-id.ts\n// Unfortunately due to https://github.com/emberjs/ember.js/issues/20165 we cannot use the built-in version in template tags\nexport function uniqueId() {\n // @ts-expect-error this one-liner abuses weird JavaScript semantics that\n // TypeScript (legitimately) doesn't like, but they're nonetheless valid and\n // specced.\n return ([3e7] + -1e3 + -4e3 + -2e3 + -1e11).replace(/[0-3]/g, (a) =>\n ((a * 4) ^ ((Math.random() * 16) >> (a & 2))).toString(16)\n );\n}\n"],"names":["mergeErrorRecord","records","errors","record","name","fieldErrors","Object","entries","existingFieldErrors","uniqueId","replace","a","Math","random","toString"],"mappings":"AAEO,SAASA,gBAAgBA,CAI9B,GAAGC,OAAkD,EAC7B;EACxB,MAAMC,MAA8B,GAAG,EAAE,CAAA;AAEzC,EAAA,KAAK,MAAMC,MAAM,IAAIF,OAAO,EAAE;IAC5B,IAAI,CAACE,MAAM,EAAE;AACX,MAAA,SAAA;AACF,KAAA;AAEA,IAAA,KAAK,MAAM,CAACC,IAAI,EAAEC,WAAW,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACJ,MAAM,CAAC,EAInD;AACH,MAAA,MAAMK,mBAAmB,GAAGN,MAAM,CAACE,IAAI,CAAC,CAAA;AAExCF,MAAAA,MAAM,CAACE,IAAI,CAAC,GAAGI,mBAAmB,GAC9B,CAAC,GAAGA,mBAAmB,EAAE,GAAGH,WAAW,CAAC,GACxCA,WAAW,CAAA;AACjB,KAAA;AACF,GAAA;AAEA,EAAA,OAAOH,MAAM,CAAA;AACf,CAAA;;AAEA;AACA;AACO,SAASO,QAAQA,GAAG;AACzB;AACA;AACA;EACA,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,IAAI,EAAEC,OAAO,CAAC,QAAQ,EAAGC,CAAC,IAC9D,CAAEA,CAAC,GAAG,CAAC,GAAMC,IAAI,CAACC,MAAM,EAAE,GAAG,EAAE,KAAMF,CAAC,GAAG,CAAC,CAAE,EAAEG,QAAQ,CAAC,EAAE,CAAC,
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/-private/utils.ts"],"sourcesContent":["import type { ErrorRecord, FormData, FormKey, ValidationError } from './types';\n\nexport function mergeErrorRecord<\n DATA extends FormData,\n KEY extends FormKey<DATA> = FormKey<DATA>\n>(\n ...records: Array<ErrorRecord<DATA, KEY> | undefined>\n): ErrorRecord<DATA, KEY> {\n const errors: ErrorRecord<DATA, KEY> = {};\n\n for (const record of records) {\n if (!record) {\n continue;\n }\n\n for (const [name, fieldErrors] of Object.entries(record) as [\n // TS does not infer the types correctly here, fieldErrors would be unknown, not sure why\n KEY,\n ValidationError<DATA[KEY]>[]\n ][]) {\n const existingFieldErrors = errors[name];\n\n errors[name] = existingFieldErrors\n ? [...existingFieldErrors, ...fieldErrors]\n : fieldErrors;\n }\n }\n\n return errors;\n}\n\n// this is copy pasted from https://github.com/emberjs/ember.js/blob/60d2e0cddb353aea0d6e36a72fda971010d92355/packages/%40ember/-internals/glimmer/lib/helpers/unique-id.ts\n// Unfortunately due to https://github.com/emberjs/ember.js/issues/20165 we cannot use the built-in version in template tags\nexport function uniqueId() {\n // @ts-expect-error this one-liner abuses weird JavaScript semantics that\n // TypeScript (legitimately) doesn't like, but they're nonetheless valid and\n // specced.\n return ([3e7] + -1e3 + -4e3 + -2e3 + -1e11).replace(/[0-3]/g, (a) =>\n ((a * 4) ^ ((Math.random() * 16) >> (a & 2))).toString(16)\n );\n}\n"],"names":["mergeErrorRecord","records","errors","record","name","fieldErrors","Object","entries","existingFieldErrors","uniqueId","replace","a","Math","random","toString"],"mappings":"AAEO,SAASA,gBAAgBA,CAI9B,GAAGC,OAAkD,EAC7B;EACxB,MAAMC,MAA8B,GAAG,EAAE,CAAA;AAEzC,EAAA,KAAK,MAAMC,MAAM,IAAIF,OAAO,EAAE;IAC5B,IAAI,CAACE,MAAM,EAAE;AACX,MAAA,SAAA;AACF,KAAA;AAEA,IAAA,KAAK,MAAM,CAACC,IAAI,EAAEC,WAAW,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACJ,MAAM,CAAC,EAInD;AACH,MAAA,MAAMK,mBAAmB,GAAGN,MAAM,CAACE,IAAI,CAAC,CAAA;AAExCF,MAAAA,MAAM,CAACE,IAAI,CAAC,GAAGI,mBAAmB,GAC9B,CAAC,GAAGA,mBAAmB,EAAE,GAAGH,WAAW,CAAC,GACxCA,WAAW,CAAA;AACjB,KAAA;AACF,GAAA;AAEA,EAAA,OAAOH,MAAM,CAAA;AACf,CAAA;;AAEA;AACA;AACO,SAASO,QAAQA,GAAG;AACzB;AACA;AACA;EACA,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,IAAI,EAAEC,OAAO,CAAC,QAAQ,EAAGC,CAAC,IAC9D,CAAEA,CAAC,GAAG,CAAC,GAAMC,IAAI,CAACC,MAAM,EAAE,GAAG,EAAE,KAAMF,CAAC,GAAG,CAAC,CAAE,EAAEG,QAAQ,CAAC,EAAE,CAC3D,CAAC,CAAA;AACH;;;;"}
|
@@ -22,14 +22,16 @@ var _class, _descriptor, _class3, _descriptor2, _descriptor3, _descriptor4;
|
|
22
22
|
*/
|
23
23
|
let FieldData = (_class = class FieldData {
|
24
24
|
constructor(fieldRegistration) {
|
25
|
+
/**
|
26
|
+
* tracked state that enabled a dynamic validation of a field *before* the whole form is submitted, e.g. by `@validateOn="blur" and the blur event being triggered for that particular field.
|
27
|
+
*/
|
25
28
|
_initializerDefineProperty(this, "validationEnabled", _descriptor, this);
|
29
|
+
/**
|
30
|
+
* The *field* level validation callback passed to the field as in `<form.field @name="foo" @validate={{this.validateCallback}}>`
|
31
|
+
*/
|
26
32
|
_defineProperty(this, "validate", void 0);
|
27
33
|
this.validate = fieldRegistration.validate;
|
28
34
|
}
|
29
|
-
|
30
|
-
/**
|
31
|
-
* tracked state that enabled a dynamic validation of a field *before* the whole form is submitted, e.g. by `@validateOn="blur" and the blur event being triggered for that particular field.
|
32
|
-
*/
|
33
35
|
}, (_descriptor = _applyDecoratedDescriptor(_class.prototype, "validationEnabled", [tracked], {
|
34
36
|
configurable: true,
|
35
37
|
enumerable: true,
|
@@ -117,10 +119,16 @@ let HeadlessFormComponent = setComponentTemplate(precompileTemplate(`
|
|
117
119
|
_defineProperty(this, "registerForm", modifier((el, _p) => {
|
118
120
|
this.formElement = el;
|
119
121
|
}));
|
122
|
+
/**
|
123
|
+
* A copy of the passed `@data` stored internally, which is only passed back to the component consumer after a (successful) form submission.
|
124
|
+
*/
|
120
125
|
_defineProperty(this, "internalData", new TrackedObject({}));
|
121
126
|
_defineProperty(this, "fields", new Map());
|
122
127
|
_initializerDefineProperty(this, "validationState", _descriptor2, this);
|
123
128
|
_initializerDefineProperty(this, "submissionState", _descriptor3, this);
|
129
|
+
/**
|
130
|
+
* When this is set to true by submitting the form, eventual validation errors are show for *all* field, regardless of their individual dynamic validation status in `FieldData#validationEnabled`
|
131
|
+
*/
|
124
132
|
_initializerDefineProperty(this, "showAllValidations", _descriptor4, this);
|
125
133
|
_defineProperty(this, "onValidation", modifier((el, [eventName, handler]) => {
|
126
134
|
if (eventName) {
|
@@ -228,7 +236,7 @@ let HeadlessFormComponent = setComponentTemplate(precompileTemplate(`
|
|
228
236
|
}
|
229
237
|
async _validate() {
|
230
238
|
const promise = this.validate();
|
231
|
-
this.validationState = new TrackedAsyncData(promise
|
239
|
+
this.validationState = new TrackedAsyncData(promise);
|
232
240
|
return promise;
|
233
241
|
}
|
234
242
|
validateNative() {
|
@@ -290,10 +298,12 @@ let HeadlessFormComponent = setComponentTemplate(precompileTemplate(`
|
|
290
298
|
this.showAllValidations = true;
|
291
299
|
if (!this.hasValidationErrors) {
|
292
300
|
if (this.args.onSubmit) {
|
293
|
-
this.submissionState = new TrackedAsyncData(this.args.onSubmit(this.effectiveData)
|
301
|
+
this.submissionState = new TrackedAsyncData(this.args.onSubmit(this.effectiveData));
|
294
302
|
}
|
295
303
|
} else {
|
296
|
-
assert('Validation errors expected to be present. If you see this, please report it as a bug to ember-headless-form!',
|
304
|
+
assert('Validation errors expected to be present. If you see this, please report it as a bug to ember-headless-form!',
|
305
|
+
// Do *not* use optional chaining due to https://github.com/ember-cli/babel-plugin-debug-macros/issues/89
|
306
|
+
this.validationState && this.validationState.isResolved);
|
297
307
|
this.args.onInvalid?.(this.effectiveData, this.validationState.value);
|
298
308
|
}
|
299
309
|
}
|