@onehat/data 1.22.29 → 1.22.31
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 +1 -1
- package/src/Property/Mixed.js +60 -1
- package/src/Schema/Schema.js +3 -1
package/package.json
CHANGED
package/src/Property/Mixed.js
CHANGED
|
@@ -21,7 +21,7 @@ import _ from 'lodash';
|
|
|
21
21
|
* Class represents a Property that can store values of multiple types.
|
|
22
22
|
* The actual type is determined dynamically based on the value being set.
|
|
23
23
|
*
|
|
24
|
-
* Usage: { name: 'date', title: 'Date', types: ['date', 'string'], },
|
|
24
|
+
* Usage: { name: 'date', title: 'Date', type: 'mixed', types: ['date', 'string'], },
|
|
25
25
|
* This is primarily used to allow a field that's normally one PropertyType
|
|
26
26
|
* to also accept string values (e.g. values like '2025-01-01' or 'N/A').
|
|
27
27
|
*
|
|
@@ -38,12 +38,21 @@ export default class MixedProperty extends EventEmitter {
|
|
|
38
38
|
|
|
39
39
|
super(config, entity);
|
|
40
40
|
|
|
41
|
+
// Apply config to this instance (similar to how Property does it)
|
|
42
|
+
_.merge(this, config);
|
|
43
|
+
this._originalConfig = config;
|
|
44
|
+
this._entity = entity;
|
|
45
|
+
|
|
41
46
|
this.registerEvents([
|
|
42
47
|
'change',
|
|
43
48
|
'changeValidity',
|
|
44
49
|
'destroy',
|
|
45
50
|
]);
|
|
46
51
|
|
|
52
|
+
this.rawValue = null;
|
|
53
|
+
this.parsedValue = null;
|
|
54
|
+
this.isDestroyed = false;
|
|
55
|
+
|
|
47
56
|
this.types = config.types;
|
|
48
57
|
this.currentType = this.types[0].type || this.types[0];
|
|
49
58
|
this.internalProperties = new Map();
|
|
@@ -402,6 +411,56 @@ export default class MixedProperty extends EventEmitter {
|
|
|
402
411
|
this.internalProperties.forEach((property) => property.destroy());
|
|
403
412
|
this.internalProperties.clear();
|
|
404
413
|
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Returns the default configuration for this PropertyType.
|
|
417
|
+
* For MixedProperty, this delegates to the first configured type's defaults.
|
|
418
|
+
* @param {Object} defaults - The default configuration to merge with (should include 'types' array)
|
|
419
|
+
* @returns {Object} The default configuration
|
|
420
|
+
*/
|
|
421
|
+
static getStaticDefaults(defaults = {}) {
|
|
422
|
+
const mixedPropertyDefaults = {
|
|
423
|
+
name: null,
|
|
424
|
+
allowNull: true,
|
|
425
|
+
depends: null,
|
|
426
|
+
mapping: null,
|
|
427
|
+
submitAsString: false,
|
|
428
|
+
isSortable: true,
|
|
429
|
+
isTempId: false,
|
|
430
|
+
isVirtual: false,
|
|
431
|
+
title: null,
|
|
432
|
+
tooltip: null,
|
|
433
|
+
fieldGroup: null,
|
|
434
|
+
isForeignModel: false,
|
|
435
|
+
filterType: null,
|
|
436
|
+
isFilteringDisabled: false,
|
|
437
|
+
viewerType: null,
|
|
438
|
+
editorType: null,
|
|
439
|
+
isEditingDisabled: false,
|
|
440
|
+
defaultValue: null,
|
|
441
|
+
formatter: null,
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
// If types are configured, use the first type's default value
|
|
445
|
+
if (defaults.types && Array.isArray(defaults.types) && defaults.types.length > 0) {
|
|
446
|
+
const
|
|
447
|
+
firstTypeConfig = defaults.types[0],
|
|
448
|
+
firstTypeName = typeof firstTypeConfig === 'string' ? firstTypeConfig : firstTypeConfig.type;
|
|
449
|
+
if (firstTypeName) {
|
|
450
|
+
try {
|
|
451
|
+
const PropertyClass = MixedProperty.prototype._getPropertyClass(firstTypeName);
|
|
452
|
+
const typeDefaults = PropertyClass.getStaticDefaults ? PropertyClass.getStaticDefaults() : {};
|
|
453
|
+
if (typeDefaults.defaultValue !== undefined) {
|
|
454
|
+
mixedPropertyDefaults.defaultValue = typeDefaults.defaultValue;
|
|
455
|
+
}
|
|
456
|
+
} catch (e) {
|
|
457
|
+
// If we can't get the property class, just use null default
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
return _.merge({}, mixedPropertyDefaults, defaults);
|
|
463
|
+
}
|
|
405
464
|
}
|
|
406
465
|
|
|
407
466
|
MixedProperty.className = 'Mixed';
|
package/src/Schema/Schema.js
CHANGED
|
@@ -286,7 +286,9 @@ export default class Schema extends EventEmitter {
|
|
|
286
286
|
if (!propertyType) {
|
|
287
287
|
propertyType = PropertyTypes['string'];
|
|
288
288
|
}
|
|
289
|
-
|
|
289
|
+
// Pass the property definition to getStaticDefaults for types like 'mixed'
|
|
290
|
+
// that need access to the configuration (e.g., the types array)
|
|
291
|
+
const staticDefaults = propertyType.getStaticDefaults(property);
|
|
290
292
|
defaultValue = staticDefaults.defaultValue;
|
|
291
293
|
}
|
|
292
294
|
if (_.isFunction(defaultValue)) {
|