@singularsystems/neo-core 1.3.5 → 1.3.6
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/CHANGELOG.md +5 -0
- package/dist/Components/Modal/ModalOptions.d.ts +4 -0
- package/dist/Components/Modal/ModalStore.d.ts +5 -5
- package/dist/Components/Modal/ModalStore.js +2 -1
- package/dist/Data/Deserialiser.d.ts +2 -2
- package/dist/Data/Deserialiser.js +14 -13
- package/dist/Model/Decorators.d.ts +2 -2
- package/dist/Model/IModelBase.d.ts +9 -1
- package/dist/Model/IModelBase.js +26 -1
- package/dist/Model/List.d.ts +1 -1
- package/dist/Model/List.js +8 -3
- package/dist/Model/PropertyInfo.d.ts +4 -7
- package/dist/Model/PropertyInfo.js +16 -18
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -37,6 +37,10 @@ export default interface IModalOptions extends IModalOptionsBase {
|
|
|
37
37
|
onClose: (event: any) => void;
|
|
38
38
|
children: any;
|
|
39
39
|
}
|
|
40
|
+
export interface ICodeModalOptions extends IModalOptions {
|
|
41
|
+
/** Indicates that this modal was created using ModalUtils. */
|
|
42
|
+
isCodeModal: true;
|
|
43
|
+
}
|
|
40
44
|
export interface IModalOptionsAuto extends IModalOptionsBase {
|
|
41
45
|
/**
|
|
42
46
|
* Controls the visibility of the modal.
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import IModalOptions from './ModalOptions';
|
|
1
|
+
import IModalOptions, { ICodeModalOptions } from './ModalOptions';
|
|
2
2
|
export interface IModalStore {
|
|
3
3
|
modals: CodeModal[];
|
|
4
4
|
addModal(title: string, message: any, modalOptions: Partial<IModalOptions>): ICodeModal;
|
|
5
5
|
removeModal(modal: CodeModal): void;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
|
-
* Represents a list of modal components added
|
|
8
|
+
* Represents a list of modal components added programmatically.
|
|
9
9
|
* Modals will be removed from the list when they are closed by the user, and the animation has been complete.
|
|
10
10
|
* A modal container will render modals based on the information in this list
|
|
11
11
|
*/
|
|
12
12
|
export default class ModalStore implements IModalStore {
|
|
13
13
|
modals: CodeModal[];
|
|
14
|
-
addModal(title: string, message: any, modalOptions: Partial<
|
|
14
|
+
addModal(title: string, message: any, modalOptions: Partial<ICodeModalOptions>): ICodeModal;
|
|
15
15
|
removeModal(modal: CodeModal): void;
|
|
16
16
|
}
|
|
17
17
|
export interface ICodeModal {
|
|
@@ -22,8 +22,8 @@ export interface ICodeModal {
|
|
|
22
22
|
declare class CodeModal implements ICodeModal {
|
|
23
23
|
private store;
|
|
24
24
|
content: any;
|
|
25
|
-
options:
|
|
26
|
-
constructor(store: IModalStore, content: any, options:
|
|
25
|
+
options: ICodeModalOptions;
|
|
26
|
+
constructor(store: IModalStore, content: any, options: ICodeModalOptions);
|
|
27
27
|
interceptClick(onClick?: (e: any) => void): (e: any) => void;
|
|
28
28
|
id: string;
|
|
29
29
|
close(): void;
|
|
@@ -5,7 +5,7 @@ import { Settings } from '../../Settings';
|
|
|
5
5
|
import { Utils } from '../../Utils';
|
|
6
6
|
import { injectable } from 'inversify';
|
|
7
7
|
/**
|
|
8
|
-
* Represents a list of modal components added
|
|
8
|
+
* Represents a list of modal components added programmatically.
|
|
9
9
|
* Modals will be removed from the list when they are closed by the user, and the animation has been complete.
|
|
10
10
|
* A modal container will render modals based on the information in this list
|
|
11
11
|
*/
|
|
@@ -14,6 +14,7 @@ var ModalStore = /** @class */ (function () {
|
|
|
14
14
|
this.modals = [];
|
|
15
15
|
}
|
|
16
16
|
ModalStore.prototype.addModal = function (title, message, modalOptions) {
|
|
17
|
+
modalOptions.isCodeModal = true;
|
|
17
18
|
modalOptions.title = title;
|
|
18
19
|
modalOptions.show = true;
|
|
19
20
|
var codeModal = new CodeModal(this, message, modalOptions);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IBindableBase, ItemConstructor } from '../Model/IModelBase';
|
|
2
2
|
import { PropertyInfoMap } from '../Model/PropertyInfo';
|
|
3
3
|
interface IMapOptions {
|
|
4
4
|
includeEntityIdentifiers?: boolean;
|
|
@@ -32,7 +32,7 @@ export declare class Deserialiser {
|
|
|
32
32
|
* Called after an object has been deserialised. Object tracking should be re-enabled here.
|
|
33
33
|
*/
|
|
34
34
|
protected endObjectDeserialise(object: any, wasCreated: boolean): void;
|
|
35
|
-
deserialise(from: object, to: IBindableBase | IBindableBase[],
|
|
35
|
+
deserialise(from: object, to: IBindableBase | IBindableBase[], itemConstructor?: ItemConstructor, options?: IDeserialiseOptions, justCreated?: boolean): void;
|
|
36
36
|
private cleanUp;
|
|
37
37
|
private deserialiseArray;
|
|
38
38
|
private deserialiseDictionary;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createItemInstance, disambiguateItemConstructor } from '../Model/IModelBase';
|
|
1
2
|
import { TrackingState, SerialiseType, DataType, RelationType, RemoveItemBehavior } from '../Model/Misc';
|
|
2
3
|
import { Utils } from '../Utils';
|
|
3
4
|
import NumberUtils from "../NumberUtils";
|
|
@@ -30,7 +31,7 @@ var Deserialiser = /** @class */ (function () {
|
|
|
30
31
|
object.onDeserialiseCompleted(wasCreated);
|
|
31
32
|
}
|
|
32
33
|
};
|
|
33
|
-
Deserialiser.prototype.deserialise = function (from, to,
|
|
34
|
+
Deserialiser.prototype.deserialise = function (from, to, itemConstructor, options, justCreated) {
|
|
34
35
|
var _this = this;
|
|
35
36
|
if (options === void 0) { options = {}; }
|
|
36
37
|
if (justCreated === void 0) { justCreated = false; }
|
|
@@ -40,7 +41,7 @@ var Deserialiser = /** @class */ (function () {
|
|
|
40
41
|
try {
|
|
41
42
|
Utils.batchUpdate(function () {
|
|
42
43
|
if (from instanceof Array) {
|
|
43
|
-
_this.deserialiseArray(from, to,
|
|
44
|
+
_this.deserialiseArray(from, to, itemConstructor ? disambiguateItemConstructor(itemConstructor) : undefined);
|
|
44
45
|
}
|
|
45
46
|
else {
|
|
46
47
|
_this.deserialiseObject(from, to, justCreated);
|
|
@@ -63,7 +64,7 @@ var Deserialiser = /** @class */ (function () {
|
|
|
63
64
|
}
|
|
64
65
|
});
|
|
65
66
|
};
|
|
66
|
-
Deserialiser.prototype.deserialiseArray = function (from, to,
|
|
67
|
+
Deserialiser.prototype.deserialiseArray = function (from, to, itemConstructorOptions) {
|
|
67
68
|
var _a;
|
|
68
69
|
if (!to) {
|
|
69
70
|
throw "Cannot deserialise array into a non initialised property.";
|
|
@@ -106,14 +107,11 @@ var Deserialiser = /** @class */ (function () {
|
|
|
106
107
|
deserialise = false;
|
|
107
108
|
}
|
|
108
109
|
else {
|
|
109
|
-
if (
|
|
110
|
-
toItem =
|
|
111
|
-
}
|
|
112
|
-
else if (type) {
|
|
113
|
-
toItem = new type();
|
|
110
|
+
if (itemConstructorOptions) {
|
|
111
|
+
toItem = createItemInstance(itemConstructorOptions, fromItem);
|
|
114
112
|
}
|
|
115
113
|
else {
|
|
116
|
-
toItem = to.createChild();
|
|
114
|
+
toItem = to.createChild(fromItem);
|
|
117
115
|
}
|
|
118
116
|
}
|
|
119
117
|
}
|
|
@@ -134,7 +132,7 @@ var Deserialiser = /** @class */ (function () {
|
|
|
134
132
|
if (list.deletedList) {
|
|
135
133
|
list.clearDeletedList();
|
|
136
134
|
}
|
|
137
|
-
if (deletedItems) {
|
|
135
|
+
if (deletedItems.length > 0) {
|
|
138
136
|
(_a = list.deletedList).push.apply(_a, deletedItems);
|
|
139
137
|
}
|
|
140
138
|
};
|
|
@@ -154,7 +152,6 @@ var Deserialiser = /** @class */ (function () {
|
|
|
154
152
|
}
|
|
155
153
|
};
|
|
156
154
|
Deserialiser.prototype.deserialiseObject = function (from, to, justCreated) {
|
|
157
|
-
var _a;
|
|
158
155
|
if (!from || !to) {
|
|
159
156
|
throw "From and to objects are required.";
|
|
160
157
|
}
|
|
@@ -192,8 +189,12 @@ var Deserialiser = /** @class */ (function () {
|
|
|
192
189
|
else {
|
|
193
190
|
if (fromValue instanceof Array && !propertyInfo.assignOnDeserialise) {
|
|
194
191
|
if (!to[key] || !(to[key] instanceof Array) || to[key].canDeserialise) {
|
|
195
|
-
// Deserialise into full list.
|
|
196
|
-
|
|
192
|
+
// Deserialise into full list / array.
|
|
193
|
+
if (!to[key] && propertyInfo.relationType === RelationType.ChildList) {
|
|
194
|
+
// If the property is null, assume it is an array, not a list.
|
|
195
|
+
to[key] = [];
|
|
196
|
+
}
|
|
197
|
+
this.deserialiseArray(fromValue, to[key], propertyInfo.itemConstructorOptions);
|
|
197
198
|
}
|
|
198
199
|
else {
|
|
199
200
|
// Plain array
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SerialiseType, DataType, TimeZoneFormat } from './Misc';
|
|
2
|
-
import { IObjectFactoryOptions } from './IModelBase';
|
|
2
|
+
import { IObjectFactoryOptions, ItemConstructor } from './IModelBase';
|
|
3
3
|
export declare function Display(name: string): (type: any, propertyKey: string) => void;
|
|
4
4
|
/** Indicates that this is a date property. Json strings will be converted to date objects on deserialisation. */
|
|
5
5
|
export declare function Date(timeZoneSerialisation?: TimeZoneFormat): (type: any, propertyKey: string, descriptor?: PropertyDescriptor) => void;
|
|
@@ -21,7 +21,7 @@ export declare function Observable(isObservable?: boolean): (type: any, property
|
|
|
21
21
|
export declare function NoTracking(serialisation?: SerialiseType): (type: any, propertyKey: string) => void;
|
|
22
22
|
export declare function Serialisation(serialisation: SerialiseType): (type: any, propertyKey: string) => void;
|
|
23
23
|
/** Indicates that this is a list property, and specifies the item type. This is not required if the list is initialised with a value. */
|
|
24
|
-
export declare function ChildList(childType?:
|
|
24
|
+
export declare function ChildList(childType?: ItemConstructor): (type: any, propertyKey: string) => any;
|
|
25
25
|
/** Indicates that this is a child object property, and specifies the child type. This is not required if the property is initialised with a value. */
|
|
26
26
|
export declare function ChildObject(childType: new () => any, isValueObject?: boolean): Function;
|
|
27
27
|
export declare function ChildObject(childType: () => any, isValueObject?: boolean): Function;
|
|
@@ -107,7 +107,15 @@ export interface IModelBaseStatic {
|
|
|
107
107
|
new (): IModelBase;
|
|
108
108
|
typeName: string;
|
|
109
109
|
}
|
|
110
|
-
export type
|
|
110
|
+
export type ItemConstructor<T = any> = (new () => T) | (() => T) | IObjectFactoryOptions;
|
|
111
|
+
export type ItemConstructorOptions = {
|
|
112
|
+
type?: new () => any;
|
|
113
|
+
typeCallback?: () => any;
|
|
114
|
+
itemFactory?: ObjectFactory;
|
|
115
|
+
};
|
|
116
|
+
export declare function disambiguateItemConstructor(factory: ItemConstructor): ItemConstructorOptions;
|
|
117
|
+
export declare function createItemInstance(options: ItemConstructorOptions, rawData: object): object;
|
|
118
|
+
export type ObjectFactory = (rawData?: object) => object;
|
|
111
119
|
export interface IObjectFactoryOptions {
|
|
112
120
|
/** Function that creates an instance of an object based on some input data. */
|
|
113
121
|
itemFactory: ObjectFactory;
|
package/dist/Model/IModelBase.js
CHANGED
|
@@ -1 +1,26 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export function disambiguateItemConstructor(factory) {
|
|
2
|
+
var _a;
|
|
3
|
+
if (typeof factory === "function") {
|
|
4
|
+
var constructor = (_a = factory.prototype) === null || _a === void 0 ? void 0 : _a.constructor;
|
|
5
|
+
// Anonymous functions have a constructor name of "" or undefined.
|
|
6
|
+
if ((constructor === null || constructor === void 0 ? void 0 : constructor.neo) === undefined && (!factory.prototype || !(constructor === null || constructor === void 0 ? void 0 : constructor.name))) {
|
|
7
|
+
return { typeCallback: factory };
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
return { type: factory };
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return { itemFactory: factory.itemFactory };
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function createItemInstance(options, rawData) {
|
|
18
|
+
var _a;
|
|
19
|
+
if (options.itemFactory) {
|
|
20
|
+
return options.itemFactory(rawData);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
var type = (_a = options.type) !== null && _a !== void 0 ? _a : options.typeCallback();
|
|
24
|
+
return new type();
|
|
25
|
+
}
|
|
26
|
+
}
|
package/dist/Model/List.d.ts
CHANGED
|
@@ -67,7 +67,7 @@ export default class List<T> extends Array<T> {
|
|
|
67
67
|
*/
|
|
68
68
|
static fromJSArray<T>(childType: new () => T, jsArray: PartialPlainObject<T>[], deserialiseOptions?: IDeserialiseOptions, listOptions?: IListCreationOptions): List<T>;
|
|
69
69
|
/** Creates a new item of type T */
|
|
70
|
-
createChild(): T;
|
|
70
|
+
createChild(data?: object): T;
|
|
71
71
|
push(...items: T[]): any;
|
|
72
72
|
clearDeletedList(): void;
|
|
73
73
|
private setParent;
|
package/dist/Model/List.js
CHANGED
|
@@ -118,11 +118,16 @@ var List = /** @class */ (function (_super) {
|
|
|
118
118
|
return list;
|
|
119
119
|
};
|
|
120
120
|
/** Creates a new item of type T */
|
|
121
|
-
List.prototype.createChild = function () {
|
|
122
|
-
if (
|
|
121
|
+
List.prototype.createChild = function (data) {
|
|
122
|
+
if (this.itemFactory) {
|
|
123
|
+
return this.itemFactory(data);
|
|
124
|
+
}
|
|
125
|
+
else if (this.childObjectType) {
|
|
126
|
+
return new this.childObjectType();
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
123
129
|
throw "Cannot create child, type was not passed to constructor.";
|
|
124
130
|
}
|
|
125
|
-
return new this.childObjectType();
|
|
126
131
|
};
|
|
127
132
|
List.prototype.push = function () {
|
|
128
133
|
var _this = this;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SerialiseType, RelationType, OnChangedOptions, DataType, TimeZoneFormat } from './Misc';
|
|
2
2
|
import { Nullable } from '../Utils';
|
|
3
|
-
import { INonObservableModelBase,
|
|
3
|
+
import { INonObservableModelBase, ItemConstructor, ItemConstructorOptions, ObjectFactory } from './IModelBase';
|
|
4
4
|
import { Rule } from '../Validation/Rules';
|
|
5
5
|
export type PropertyInfoMap = {
|
|
6
6
|
[index: string]: PropertyInfo;
|
|
@@ -13,10 +13,6 @@ export default class PropertyInfo {
|
|
|
13
13
|
private _parent?;
|
|
14
14
|
private _readableName;
|
|
15
15
|
private attributeRules;
|
|
16
|
-
/** The class type of child.*/
|
|
17
|
-
private _type?;
|
|
18
|
-
/** A function that returns the constructor of the property type. */
|
|
19
|
-
private typeCallback?;
|
|
20
16
|
/** Name to use on labels for this property */
|
|
21
17
|
displayName: string;
|
|
22
18
|
/** True if the property does not cause the object to become dirty. */
|
|
@@ -59,7 +55,8 @@ export default class PropertyInfo {
|
|
|
59
55
|
/** Indicates that this property must be assigned to on de/serialisation. The de/serialiser will not try create a model instance of the object / array. */
|
|
60
56
|
assignOnDeserialise: boolean;
|
|
61
57
|
/** Object factory used for deserialisation. Set by ChildList / ChildObject decorators. */
|
|
62
|
-
itemFactory
|
|
58
|
+
get itemFactory(): ObjectFactory | undefined;
|
|
59
|
+
itemConstructorOptions?: ItemConstructorOptions;
|
|
63
60
|
constructor(propertyName: string);
|
|
64
61
|
/** Gets the readable name of the property. Uses string.readable if Display decorator was not specified. */
|
|
65
62
|
get readableName(): string;
|
|
@@ -69,7 +66,7 @@ export default class PropertyInfo {
|
|
|
69
66
|
get parent(): PropertyInfo | undefined;
|
|
70
67
|
addAttributeRule(rule: Rule): void;
|
|
71
68
|
clone(): PropertyInfo;
|
|
72
|
-
setPropertyType(propertyType:
|
|
69
|
+
setPropertyType(propertyType: ItemConstructor): void;
|
|
73
70
|
/**
|
|
74
71
|
* Gets the constructor function of the return type.
|
|
75
72
|
* Returns null if the property has not been decorated with a ChildObject / Parent attribute.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { __spreadArray } from "tslib";
|
|
2
2
|
import { SerialiseType, RelationType, DataType } from './Misc';
|
|
3
|
+
import { disambiguateItemConstructor } from './IModelBase';
|
|
3
4
|
import NumberUtils from "../NumberUtils";
|
|
4
5
|
var PropertyInfo = /** @class */ (function () {
|
|
5
6
|
function PropertyInfo(propertyName) {
|
|
@@ -32,6 +33,15 @@ var PropertyInfo = /** @class */ (function () {
|
|
|
32
33
|
/** Indicates that this property must be assigned to on de/serialisation. The de/serialiser will not try create a model instance of the object / array. */
|
|
33
34
|
this.assignOnDeserialise = false;
|
|
34
35
|
}
|
|
36
|
+
Object.defineProperty(PropertyInfo.prototype, "itemFactory", {
|
|
37
|
+
/** Object factory used for deserialisation. Set by ChildList / ChildObject decorators. */
|
|
38
|
+
get: function () {
|
|
39
|
+
var _a;
|
|
40
|
+
return (_a = this.itemConstructorOptions) === null || _a === void 0 ? void 0 : _a.itemFactory;
|
|
41
|
+
},
|
|
42
|
+
enumerable: false,
|
|
43
|
+
configurable: true
|
|
44
|
+
});
|
|
35
45
|
Object.defineProperty(PropertyInfo.prototype, "readableName", {
|
|
36
46
|
/** Gets the readable name of the property. Uses string.readable if Display decorator was not specified. */
|
|
37
47
|
get: function () {
|
|
@@ -75,20 +85,7 @@ var PropertyInfo = /** @class */ (function () {
|
|
|
75
85
|
return clone;
|
|
76
86
|
};
|
|
77
87
|
PropertyInfo.prototype.setPropertyType = function (propertyType) {
|
|
78
|
-
|
|
79
|
-
if (typeof propertyType === "function") {
|
|
80
|
-
var constructor = (_a = propertyType.prototype) === null || _a === void 0 ? void 0 : _a.constructor;
|
|
81
|
-
// Anonymous functions have a constructor name of "" or undefined.
|
|
82
|
-
if ((constructor === null || constructor === void 0 ? void 0 : constructor.neo) === undefined && (!propertyType.prototype || !(constructor === null || constructor === void 0 ? void 0 : constructor.name))) {
|
|
83
|
-
this.typeCallback = propertyType;
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
this._type = propertyType;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
this.itemFactory = propertyType.itemFactory;
|
|
91
|
-
}
|
|
88
|
+
this.itemConstructorOptions = disambiguateItemConstructor(propertyType);
|
|
92
89
|
};
|
|
93
90
|
Object.defineProperty(PropertyInfo.prototype, "type", {
|
|
94
91
|
/**
|
|
@@ -96,11 +93,12 @@ var PropertyInfo = /** @class */ (function () {
|
|
|
96
93
|
* Returns null if the property has not been decorated with a ChildObject / Parent attribute.
|
|
97
94
|
*/
|
|
98
95
|
get: function () {
|
|
99
|
-
|
|
100
|
-
|
|
96
|
+
var _a, _b;
|
|
97
|
+
if (((_a = this.itemConstructorOptions) === null || _a === void 0 ? void 0 : _a.typeCallback) !== undefined) {
|
|
98
|
+
return this.itemConstructorOptions.typeCallback();
|
|
101
99
|
}
|
|
102
|
-
else if (this.
|
|
103
|
-
return this.
|
|
100
|
+
else if ((_b = this.itemConstructorOptions) === null || _b === void 0 ? void 0 : _b.type) {
|
|
101
|
+
return this.itemConstructorOptions.type;
|
|
104
102
|
}
|
|
105
103
|
else {
|
|
106
104
|
return null;
|