@masterteam/components 0.0.286 → 0.0.287

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.
@@ -161,6 +161,29 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
161
161
  }, template: "@if (config().label) {\r\n <label class=\"font-medium text-color\">\r\n {{ config().label }}\r\n </label>\r\n}\r\n\r\n<div\r\n class=\"rounded-lg border border-surface-200 bg-surface-50 px-3 flex items-center\"\r\n>\r\n @if (activeCell(); as cell) {\r\n <div class=\"flex flex-1 min-h-6 items-center gap-2 justify-between\">\r\n <span\r\n class=\"h-6 w-2 shrink-0 rounded-[2px] border border-surface-200\"\r\n [style.background-color]=\"getSwatchColor(cell.color)\"\r\n [style.border-color]=\"getSwatchColor(cell.color)\"\r\n ></span>\r\n\r\n <div class=\"min-w-0 flex-1 py-2 flex items-center justify-between\">\r\n <div class=\"truncate font-semibold text-gray-500\">\r\n {{ cell.label }}\r\n </div>\r\n\r\n @if (selectionSummary()) {\r\n <div class=\"font-bold text-gray-500\">\r\n <mt-icon\r\n [mtTooltip]=\"selectionSummary()\"\r\n icon=\"general.info-circle\"\r\n />\r\n </div>\r\n }\r\n </div>\r\n </div>\r\n } @else {\r\n <div class=\"flex min-h-6 items-center text-muted-color py-2\">\r\n {{ hasMatrix() ? missingResultMessage() : config().emptyMessage }}\r\n </div>\r\n }\r\n</div>\r\n" }]
162
162
  }], propDecorators: { config: [{ type: i0.Input, args: [{ isSignal: true, alias: "config", required: true }] }] } });
163
163
 
164
+ /**
165
+ * Read a control value as a payload, accepting the serialized JSON string a
166
+ * form load can patch in. {@link SchemaConnectionField.writeValue} and the
167
+ * required validator must agree on this: while only `writeValue` parsed, a
168
+ * string-valued connection rendered as filled but validated as empty.
169
+ */
170
+ function parseConnectionPayload(value) {
171
+ if (typeof value === 'string') {
172
+ const trimmed = value.trim();
173
+ if (!trimmed)
174
+ return null;
175
+ try {
176
+ const parsed = JSON.parse(trimmed);
177
+ return parsed && typeof parsed === 'object'
178
+ ? parsed
179
+ : null;
180
+ }
181
+ catch {
182
+ return null;
183
+ }
184
+ }
185
+ return value ?? null;
186
+ }
164
187
  class SchemaConnectionField {
165
188
  // ============================================================================
166
189
  // Inputs
@@ -208,7 +231,7 @@ class SchemaConnectionField {
208
231
  * collapses a source-less selection to `null`.
209
232
  */
210
233
  connectionRequiredValidator = (control) => {
211
- const value = control.value;
234
+ const value = parseConnectionPayload(control.value);
212
235
  const hasSources = !!value && Array.isArray(value.sources) && value.sources.length > 0;
213
236
  return hasSources ? null : { required: true };
214
237
  };
@@ -436,16 +459,9 @@ class SchemaConnectionField {
436
459
  // ControlValueAccessor
437
460
  // ============================================================================
438
461
  writeValue(value) {
439
- if (typeof value === 'string') {
440
- try {
441
- value = JSON.parse(value);
442
- }
443
- catch {
444
- value = null;
445
- }
446
- }
447
- this.value.set(value ?? null);
448
- this.distributeToSelections(value ?? null);
462
+ const payload = parseConnectionPayload(value);
463
+ this.value.set(payload);
464
+ this.distributeToSelections(payload);
449
465
  }
450
466
  registerOnChange(fn) {
451
467
  this.onModelChange = fn;