@vaadin/custom-field 23.3.0-alpha4 → 23.3.0-alpha6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/custom-field",
3
- "version": "23.3.0-alpha4",
3
+ "version": "23.3.0-alpha6",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -35,30 +35,30 @@
35
35
  ],
36
36
  "dependencies": {
37
37
  "@polymer/polymer": "^3.0.0",
38
- "@vaadin/component-base": "23.3.0-alpha4",
39
- "@vaadin/field-base": "23.3.0-alpha4",
40
- "@vaadin/vaadin-lumo-styles": "23.3.0-alpha4",
41
- "@vaadin/vaadin-material-styles": "23.3.0-alpha4",
42
- "@vaadin/vaadin-themable-mixin": "23.3.0-alpha4"
38
+ "@vaadin/component-base": "23.3.0-alpha6",
39
+ "@vaadin/field-base": "23.3.0-alpha6",
40
+ "@vaadin/vaadin-lumo-styles": "23.3.0-alpha6",
41
+ "@vaadin/vaadin-material-styles": "23.3.0-alpha6",
42
+ "@vaadin/vaadin-themable-mixin": "23.3.0-alpha6"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@esm-bundle/chai": "^4.3.4",
46
- "@vaadin/combo-box": "23.3.0-alpha4",
47
- "@vaadin/date-picker": "23.3.0-alpha4",
48
- "@vaadin/email-field": "23.3.0-alpha4",
49
- "@vaadin/form-layout": "23.3.0-alpha4",
50
- "@vaadin/number-field": "23.3.0-alpha4",
51
- "@vaadin/password-field": "23.3.0-alpha4",
52
- "@vaadin/select": "23.3.0-alpha4",
46
+ "@vaadin/combo-box": "23.3.0-alpha6",
47
+ "@vaadin/date-picker": "23.3.0-alpha6",
48
+ "@vaadin/email-field": "23.3.0-alpha6",
49
+ "@vaadin/form-layout": "23.3.0-alpha6",
50
+ "@vaadin/number-field": "23.3.0-alpha6",
51
+ "@vaadin/password-field": "23.3.0-alpha6",
52
+ "@vaadin/select": "23.3.0-alpha6",
53
53
  "@vaadin/testing-helpers": "^0.3.2",
54
- "@vaadin/text-area": "23.3.0-alpha4",
55
- "@vaadin/text-field": "23.3.0-alpha4",
56
- "@vaadin/time-picker": "23.3.0-alpha4",
54
+ "@vaadin/text-area": "23.3.0-alpha6",
55
+ "@vaadin/text-field": "23.3.0-alpha6",
56
+ "@vaadin/time-picker": "23.3.0-alpha6",
57
57
  "sinon": "^13.0.2"
58
58
  },
59
59
  "web-types": [
60
60
  "web-types.json",
61
61
  "web-types.lit.json"
62
62
  ],
63
- "gitHead": "da037c0aa36e4b2874f253967300f6ca1af27315"
63
+ "gitHead": "796e51380384cfa30282eecbc4e0463038298547"
64
64
  }
@@ -111,6 +111,39 @@ declare class CustomField extends FieldMixin(FocusMixin(KeyboardMixin(ThemableMi
111
111
  */
112
112
  readonly inputs: HTMLElement[] | undefined;
113
113
 
114
+ /**
115
+ * A function to format the values of the individual fields contained by
116
+ * the custom field into a single component value. The function receives
117
+ * an array of all values of the individual fields in the order of their
118
+ * presence in the DOM, and must return a single component value.
119
+ * This function is called each time a value of an internal field is
120
+ * changed.
121
+ *
122
+ * Example:
123
+ * ```js
124
+ * customField.formatValue = (fieldValues) => {
125
+ * return fieldValues.join("-");
126
+ * }
127
+ * ```
128
+ */
129
+ formatValue: CustomFieldFormatValueFn | undefined;
130
+
131
+ /**
132
+ * A function to parse the component value into values for the individual
133
+ * fields contained by the custom field. The function receives the
134
+ * component value, and must return an array of values for the individual
135
+ * fields in the order of their presence in the DOM.
136
+ * The function is called each time the value of the component changes.
137
+ *
138
+ * Example:
139
+ * ```js
140
+ * customField.parseValue = (componentValue) => {
141
+ * return componentValue.split("-");
142
+ * }
143
+ * ```
144
+ */
145
+ parseValue: CustomFieldParseValueFn | undefined;
146
+
114
147
  /**
115
148
  * The object used to localize this component.
116
149
  * To change the default localization, replace the entire
@@ -140,6 +173,9 @@ declare class CustomField extends FieldMixin(FocusMixin(KeyboardMixin(ThemableMi
140
173
  * }
141
174
  * }
142
175
  * ```
176
+ * @deprecated Since 23.3
177
+ * Use the [`formatValue`](#/elements/vaadin-custom-field#property-formatValue)
178
+ * and [`parseValue`](#/elements/vaadin-custom-field#property-parseValue) properties instead
143
179
  */
144
180
  i18n: CustomFieldI18n;
145
181
 
@@ -151,8 +187,10 @@ declare class CustomField extends FieldMixin(FocusMixin(KeyboardMixin(ThemableMi
151
187
  /**
152
188
  * The value of the field. When wrapping several inputs, it will contain `\t`
153
189
  * (Tab character) as a delimiter indicating parts intended to be used as the
154
- * corresponding inputs values. Use the [`i18n`](#/elements/vaadin-custom-field#property-i18n)
155
- * property to customize this behavior.
190
+ * corresponding inputs values.
191
+ * Use the [`formatValue`](#/elements/vaadin-custom-field#property-formatValue)
192
+ * and [`parseValue`](#/elements/vaadin-custom-field#property-parseValue)
193
+ * properties to customize this behavior.
156
194
  */
157
195
  value: string | null | undefined;
158
196
 
@@ -130,8 +130,10 @@ class CustomField extends FieldMixin(FocusMixin(KeyboardMixin(ThemableMixin(Elem
130
130
  /**
131
131
  * The value of the field. When wrapping several inputs, it will contain `\t`
132
132
  * (Tab character) as a delimiter indicating parts intended to be used as the
133
- * corresponding inputs values. Use the [`i18n`](#/elements/vaadin-custom-field#property-i18n)
134
- * property to customize this behavior.
133
+ * corresponding inputs values.
134
+ * Use the [`formatValue`](#/elements/vaadin-custom-field#property-formatValue)
135
+ * and [`parseValue`](#/elements/vaadin-custom-field#property-parseValue)
136
+ * properties to customize this behavior.
135
137
  */
136
138
  value: {
137
139
  type: String,
@@ -148,6 +150,45 @@ class CustomField extends FieldMixin(FocusMixin(KeyboardMixin(ThemableMixin(Elem
148
150
  readOnly: true,
149
151
  },
150
152
 
153
+ /**
154
+ * A function to format the values of the individual fields contained by
155
+ * the custom field into a single component value. The function receives
156
+ * an array of all values of the individual fields in the order of their
157
+ * presence in the DOM, and must return a single component value.
158
+ * This function is called each time a value of an internal field is
159
+ * changed.
160
+ *
161
+ * Example:
162
+ * ```js
163
+ * customField.formatValue = (fieldValues) => {
164
+ * return fieldValues.join("-");
165
+ * }
166
+ * ```
167
+ * @type {!CustomFieldFormatValueFn | undefined}
168
+ */
169
+ formatValue: {
170
+ type: Function,
171
+ },
172
+
173
+ /**
174
+ * A function to parse the component value into values for the individual
175
+ * fields contained by the custom field. The function receives the
176
+ * component value, and must return an array of values for the individual
177
+ * fields in the order of their presence in the DOM.
178
+ * The function is called each time the value of the component changes.
179
+ *
180
+ * Example:
181
+ * ```js
182
+ * customField.parseValue = (componentValue) => {
183
+ * return componentValue.split("-");
184
+ * }
185
+ * ```
186
+ * @type {!CustomFieldParseValueFn | undefined}
187
+ */
188
+ parseValue: {
189
+ type: Function,
190
+ },
191
+
151
192
  /**
152
193
  * The object used to localize this component.
153
194
  * To change the default localization, replace the entire
@@ -179,6 +220,9 @@ class CustomField extends FieldMixin(FocusMixin(KeyboardMixin(ThemableMixin(Elem
179
220
  * ```
180
221
  *
181
222
  * @type {!CustomFieldI18n}
223
+ * @deprecated Since 23.3
224
+ * Use the [`formatValue`](#/elements/vaadin-custom-field#property-formatValue)
225
+ * and [`parseValue`](#/elements/vaadin-custom-field#property-parseValue) properties instead
182
226
  */
183
227
  i18n: {
184
228
  type: Object,
@@ -324,7 +368,8 @@ class CustomField extends FieldMixin(FocusMixin(KeyboardMixin(ThemableMixin(Elem
324
368
  /** @private */
325
369
  __setValue() {
326
370
  this.__settingValue = true;
327
- this.value = this.i18n.formatValue.apply(this, [this.inputs.map((input) => input.value)]);
371
+ const formatFn = this.formatValue || this.i18n.formatValue;
372
+ this.value = formatFn.apply(this, [this.inputs.map((input) => input.value)]);
328
373
  this.__settingValue = false;
329
374
  }
330
375
 
@@ -375,7 +420,8 @@ class CustomField extends FieldMixin(FocusMixin(KeyboardMixin(ThemableMixin(Elem
375
420
 
376
421
  this.__toggleHasValue(value);
377
422
 
378
- const valuesArray = this.i18n.parseValue(value);
423
+ const parseFn = this.parseValue || this.i18n.parseValue;
424
+ const valuesArray = parseFn.apply(this, [value]);
379
425
  if (!valuesArray || valuesArray.length === 0) {
380
426
  console.warn('Value parser has not provided values array');
381
427
  return;
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/custom-field",
4
- "version": "23.3.0-alpha4",
4
+ "version": "23.3.0-alpha6",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {
@@ -78,7 +78,7 @@
78
78
  },
79
79
  {
80
80
  "name": "value",
81
- "description": "The value of the field. When wrapping several inputs, it will contain `\\t`\n(Tab character) as a delimiter indicating parts intended to be used as the\ncorresponding inputs values. Use the [`i18n`](https://cdn.vaadin.com/vaadin-web-components/23.3.0-alpha4/#/elements/vaadin-custom-field#property-i18n)\nproperty to customize this behavior.",
81
+ "description": "The value of the field. When wrapping several inputs, it will contain `\\t`\n(Tab character) as a delimiter indicating parts intended to be used as the\ncorresponding inputs values.\nUse the [`formatValue`](https://cdn.vaadin.com/vaadin-web-components/23.3.0-alpha6/#/elements/vaadin-custom-field#property-formatValue)\nand [`parseValue`](https://cdn.vaadin.com/vaadin-web-components/23.3.0-alpha6/#/elements/vaadin-custom-field#property-parseValue)\nproperties to customize this behavior.",
82
82
  "value": {
83
83
  "type": [
84
84
  "string",
@@ -169,7 +169,7 @@
169
169
  },
170
170
  {
171
171
  "name": "value",
172
- "description": "The value of the field. When wrapping several inputs, it will contain `\\t`\n(Tab character) as a delimiter indicating parts intended to be used as the\ncorresponding inputs values. Use the [`i18n`](https://cdn.vaadin.com/vaadin-web-components/23.3.0-alpha4/#/elements/vaadin-custom-field#property-i18n)\nproperty to customize this behavior.",
172
+ "description": "The value of the field. When wrapping several inputs, it will contain `\\t`\n(Tab character) as a delimiter indicating parts intended to be used as the\ncorresponding inputs values.\nUse the [`formatValue`](https://cdn.vaadin.com/vaadin-web-components/23.3.0-alpha6/#/elements/vaadin-custom-field#property-formatValue)\nand [`parseValue`](https://cdn.vaadin.com/vaadin-web-components/23.3.0-alpha6/#/elements/vaadin-custom-field#property-parseValue)\nproperties to customize this behavior.",
173
173
  "value": {
174
174
  "type": [
175
175
  "string",
@@ -178,6 +178,26 @@
178
178
  ]
179
179
  }
180
180
  },
181
+ {
182
+ "name": "formatValue",
183
+ "description": "A function to format the values of the individual fields contained by\nthe custom field into a single component value. The function receives\nan array of all values of the individual fields in the order of their\npresence in the DOM, and must return a single component value.\nThis function is called each time a value of an internal field is\nchanged.\n\nExample:\n```js\ncustomField.formatValue = (fieldValues) => {\n return fieldValues.join(\"-\");\n}\n```",
184
+ "value": {
185
+ "type": [
186
+ "CustomFieldFormatValueFn",
187
+ "undefined"
188
+ ]
189
+ }
190
+ },
191
+ {
192
+ "name": "parseValue",
193
+ "description": "A function to parse the component value into values for the individual\nfields contained by the custom field. The function receives the\ncomponent value, and must return an array of values for the individual\nfields in the order of their presence in the DOM.\nThe function is called each time the value of the component changes.\n\nExample:\n```js\ncustomField.parseValue = (componentValue) => {\n return componentValue.split(\"-\");\n}\n```",
194
+ "value": {
195
+ "type": [
196
+ "CustomFieldParseValueFn",
197
+ "undefined"
198
+ ]
199
+ }
200
+ },
181
201
  {
182
202
  "name": "i18n",
183
203
  "description": "The object used to localize this component.\nTo change the default localization, replace the entire\n_i18n_ object or just the property you want to modify.\n\nThe object has the following JSON structure:\n\n```\n{\n // A function to format given `Array` as\n // component value. Array is list of all internal values\n // in the order of their presence in the DOM\n // This function is called each time the internal input\n // value is changed.\n formatValue: inputValues => {\n // returns a representation of the given array of values\n // in the form of string with delimiter characters\n },\n\n // A function to parse the given value to an `Array` in the format\n // of the list of all internal values\n // in the order of their presence in the DOM\n // This function is called when value of the\n // custom field is set.\n parseValue: value => {\n // returns the array of values from parsed value string.\n }\n}\n```",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/custom-field",
4
- "version": "23.3.0-alpha4",
4
+ "version": "23.3.0-alpha6",
5
5
  "description-markup": "markdown",
6
6
  "framework": "lit",
7
7
  "framework-config": {
@@ -63,7 +63,21 @@
63
63
  },
64
64
  {
65
65
  "name": ".value",
66
- "description": "The value of the field. When wrapping several inputs, it will contain `\\t`\n(Tab character) as a delimiter indicating parts intended to be used as the\ncorresponding inputs values. Use the [`i18n`](https://cdn.vaadin.com/vaadin-web-components/23.3.0-alpha4/#/elements/vaadin-custom-field#property-i18n)\nproperty to customize this behavior.",
66
+ "description": "The value of the field. When wrapping several inputs, it will contain `\\t`\n(Tab character) as a delimiter indicating parts intended to be used as the\ncorresponding inputs values.\nUse the [`formatValue`](https://cdn.vaadin.com/vaadin-web-components/23.3.0-alpha6/#/elements/vaadin-custom-field#property-formatValue)\nand [`parseValue`](https://cdn.vaadin.com/vaadin-web-components/23.3.0-alpha6/#/elements/vaadin-custom-field#property-parseValue)\nproperties to customize this behavior.",
67
+ "value": {
68
+ "kind": "expression"
69
+ }
70
+ },
71
+ {
72
+ "name": ".formatValue",
73
+ "description": "A function to format the values of the individual fields contained by\nthe custom field into a single component value. The function receives\nan array of all values of the individual fields in the order of their\npresence in the DOM, and must return a single component value.\nThis function is called each time a value of an internal field is\nchanged.\n\nExample:\n```js\ncustomField.formatValue = (fieldValues) => {\n return fieldValues.join(\"-\");\n}\n```",
74
+ "value": {
75
+ "kind": "expression"
76
+ }
77
+ },
78
+ {
79
+ "name": ".parseValue",
80
+ "description": "A function to parse the component value into values for the individual\nfields contained by the custom field. The function receives the\ncomponent value, and must return an array of values for the individual\nfields in the order of their presence in the DOM.\nThe function is called each time the value of the component changes.\n\nExample:\n```js\ncustomField.parseValue = (componentValue) => {\n return componentValue.split(\"-\");\n}\n```",
67
81
  "value": {
68
82
  "kind": "expression"
69
83
  }