@amodx/schemas 0.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/Inputs/DefaultInputs.d.ts +201 -0
- package/Inputs/DefaultInputs.js +376 -0
- package/Inputs/PropertyInput.d.ts +46 -0
- package/Inputs/PropertyInput.js +35 -0
- package/Inputs/PropertyInputRegister.d.ts +7 -0
- package/Inputs/PropertyInputRegister.js +13 -0
- package/Properties/ObjectPath.d.ts +17 -0
- package/Properties/ObjectPath.js +33 -0
- package/Properties/Property.d.ts +24 -0
- package/Properties/Property.js +38 -0
- package/Properties/PropertyCondition.d.ts +11 -0
- package/Properties/PropertyCondition.js +37 -0
- package/Properties/PropertyConditionAction.d.ts +11 -0
- package/Properties/PropertyConditionAction.js +38 -0
- package/Properties.d.ts +44 -0
- package/Properties.js +239 -0
- package/Schema.d.ts +22 -0
- package/Schema.js +99 -0
- package/Schemas/BinaryObjectSchema.d.ts +3 -0
- package/Schemas/BinaryObjectSchema.js +3 -0
- package/Schemas/ObjectSchema.d.ts +17 -0
- package/Schemas/ObjectSchema.js +103 -0
- package/Schemas/ObjectSchemaInstance.d.ts +10 -0
- package/Schemas/ObjectSchemaInstance.js +14 -0
- package/Schemas/SchemaNode.d.ts +62 -0
- package/Schemas/SchemaNode.js +172 -0
- package/Validation/ObjectPropertyValidator.d.ts +7 -0
- package/Validation/ObjectPropertyValidator.js +9 -0
- package/Validation/ObjectPropertyValidatorRegister.d.ts +7 -0
- package/Validation/ObjectPropertyValidatorRegister.js +13 -0
- package/Validation/ObjectValidation.types.d.ts +13 -0
- package/Validation/ObjectValidation.types.js +1 -0
- package/Validation/index.d.ts +3 -0
- package/Validation/index.js +3 -0
- package/index.d.ts +8 -0
- package/index.js +8 -0
- package/package.json +27 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export class ObjectPath {
|
|
2
|
+
path;
|
|
3
|
+
static Create(path) {
|
|
4
|
+
return new ObjectPath(path);
|
|
5
|
+
}
|
|
6
|
+
static Generator() {
|
|
7
|
+
return (path) => new ObjectPath(path);
|
|
8
|
+
}
|
|
9
|
+
propertyPath;
|
|
10
|
+
constructor(path) {
|
|
11
|
+
this.path = path;
|
|
12
|
+
this.propertyPath = path;
|
|
13
|
+
}
|
|
14
|
+
resolvePath(obj) {
|
|
15
|
+
return this.propertyPath.reduce((acc, part) => acc && acc[part], obj);
|
|
16
|
+
}
|
|
17
|
+
resolveParentPath(obj) {
|
|
18
|
+
return this.propertyPath
|
|
19
|
+
.slice(0, -1)
|
|
20
|
+
.reduce((acc, part) => acc && acc[part], obj);
|
|
21
|
+
}
|
|
22
|
+
get(obj) {
|
|
23
|
+
return this.resolvePath(obj);
|
|
24
|
+
}
|
|
25
|
+
set(obj, value) {
|
|
26
|
+
const path = [...this.propertyPath];
|
|
27
|
+
const lastProperty = path.pop();
|
|
28
|
+
const target = this.resolveParentPath(obj);
|
|
29
|
+
if (lastProperty && target) {
|
|
30
|
+
target[lastProperty] = value;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { PropertyConditionAction } from "./PropertyConditionAction";
|
|
2
|
+
import { PropertyInputData } from "../Inputs/PropertyInput";
|
|
3
|
+
import { SchemaNode } from "../Schemas/SchemaNode";
|
|
4
|
+
declare class PropertyState {
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
locked: boolean;
|
|
7
|
+
valid: boolean;
|
|
8
|
+
static Create(data: Partial<PropertyState>): PropertyState;
|
|
9
|
+
private constructor();
|
|
10
|
+
}
|
|
11
|
+
export declare class Property<Value = any, Input extends PropertyInputData | null = null> {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
value: Value;
|
|
15
|
+
state: PropertyState;
|
|
16
|
+
initialize?: ((node: SchemaNode) => void) | undefined;
|
|
17
|
+
input?: Input | undefined;
|
|
18
|
+
editable?: boolean | undefined;
|
|
19
|
+
conditions?: PropertyConditionAction[] | undefined;
|
|
20
|
+
children?: Property<any>[] | undefined;
|
|
21
|
+
static Create<Value = any, Input extends PropertyInputData | null = null>(data: Partial<Property<Value, Input>>): Property<Value, Input>;
|
|
22
|
+
private constructor();
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
class PropertyState {
|
|
2
|
+
enabled;
|
|
3
|
+
locked;
|
|
4
|
+
valid;
|
|
5
|
+
static Create(data) {
|
|
6
|
+
return new PropertyState(data.enabled, data.locked);
|
|
7
|
+
}
|
|
8
|
+
constructor(enabled = true, locked = false, valid = true) {
|
|
9
|
+
this.enabled = enabled;
|
|
10
|
+
this.locked = locked;
|
|
11
|
+
this.valid = valid;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export class Property {
|
|
15
|
+
id;
|
|
16
|
+
name;
|
|
17
|
+
value;
|
|
18
|
+
state;
|
|
19
|
+
initialize;
|
|
20
|
+
input;
|
|
21
|
+
editable;
|
|
22
|
+
conditions;
|
|
23
|
+
children;
|
|
24
|
+
static Create(data) {
|
|
25
|
+
return new Property(data.id ? data.id : "", data.name ? data.name : data.id ? data.id : "", data.value, data.state ? PropertyState.Create(data.state) : PropertyState.Create({}), data.initialize, data.input, data.editable, data.conditions, data.children);
|
|
26
|
+
}
|
|
27
|
+
constructor(id, name, value, state, initialize, input, editable, conditions, children) {
|
|
28
|
+
this.id = id;
|
|
29
|
+
this.name = name;
|
|
30
|
+
this.value = value;
|
|
31
|
+
this.state = state;
|
|
32
|
+
this.initialize = initialize;
|
|
33
|
+
this.input = input;
|
|
34
|
+
this.editable = editable;
|
|
35
|
+
this.conditions = conditions;
|
|
36
|
+
this.children = children;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ObjectPath } from "./ObjectPath";
|
|
2
|
+
type LogicalOperation = "==" | "===" | "!=" | "!==" | "<" | ">" | "<=" | ">=";
|
|
3
|
+
export declare class PropertyCondition<Data extends object = {}> {
|
|
4
|
+
path: ObjectPath<Data, any>;
|
|
5
|
+
operation: LogicalOperation;
|
|
6
|
+
static Create<Data extends object>(path: ObjectPath<Data, any>, operation: LogicalOperation, value: any): PropertyCondition<Data>;
|
|
7
|
+
private constructor();
|
|
8
|
+
value: any;
|
|
9
|
+
evaluate(newValue: any): boolean;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export class PropertyCondition {
|
|
2
|
+
path;
|
|
3
|
+
operation;
|
|
4
|
+
static Create(path, operation, value) {
|
|
5
|
+
const query = new PropertyCondition(path, operation);
|
|
6
|
+
query.value = value;
|
|
7
|
+
return query;
|
|
8
|
+
}
|
|
9
|
+
constructor(path, operation) {
|
|
10
|
+
this.path = path;
|
|
11
|
+
this.operation = operation;
|
|
12
|
+
}
|
|
13
|
+
value;
|
|
14
|
+
evaluate(newValue) {
|
|
15
|
+
const value = this.value;
|
|
16
|
+
switch (this.operation) {
|
|
17
|
+
case "==":
|
|
18
|
+
return newValue == value;
|
|
19
|
+
case "===":
|
|
20
|
+
return newValue === value;
|
|
21
|
+
case "!=":
|
|
22
|
+
return newValue != value;
|
|
23
|
+
case "!==":
|
|
24
|
+
return newValue !== value;
|
|
25
|
+
case "<":
|
|
26
|
+
return newValue < value;
|
|
27
|
+
case ">":
|
|
28
|
+
return newValue > value;
|
|
29
|
+
case "<=":
|
|
30
|
+
return newValue <= value;
|
|
31
|
+
case ">=":
|
|
32
|
+
return newValue >= value;
|
|
33
|
+
default:
|
|
34
|
+
throw new Error(`Unsupported operation: ${this.operation}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SchemaNode } from "../Schemas/SchemaNode";
|
|
2
|
+
import { PropertyCondition } from "./PropertyCondition";
|
|
3
|
+
type PropertyConditionFunction = <Data extends object = {}>(action: PropertyConditionAction<Data>, node: SchemaNode, result: boolean) => void;
|
|
4
|
+
export declare class PropertyConditionAction<Data extends object = {}> {
|
|
5
|
+
action: "enable" | "lock" | PropertyConditionFunction;
|
|
6
|
+
conditions: PropertyCondition<Data>[];
|
|
7
|
+
static Create<Data extends object = any>(action: "enable" | "lock" | PropertyConditionFunction, conditions: PropertyCondition<Data>[]): PropertyConditionAction;
|
|
8
|
+
private constructor();
|
|
9
|
+
evaluate(newValue: any, affectedNode: SchemaNode): void;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export class PropertyConditionAction {
|
|
2
|
+
action;
|
|
3
|
+
conditions;
|
|
4
|
+
static Create(action, conditions) {
|
|
5
|
+
return new PropertyConditionAction(action, conditions);
|
|
6
|
+
}
|
|
7
|
+
constructor(action, conditions) {
|
|
8
|
+
this.action = action;
|
|
9
|
+
this.conditions = conditions;
|
|
10
|
+
}
|
|
11
|
+
evaluate(newValue, affectedNode) {
|
|
12
|
+
let result = false;
|
|
13
|
+
for (const e of this.conditions) {
|
|
14
|
+
result = e.evaluate(newValue);
|
|
15
|
+
}
|
|
16
|
+
if (result) {
|
|
17
|
+
if (this.action == "enable") {
|
|
18
|
+
affectedNode.setEnabled(true);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (this.action == "lock") {
|
|
22
|
+
affectedNode.setLocked(true);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
if (this.action == "enable") {
|
|
28
|
+
affectedNode.setEnabled(false);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (this.action == "lock") {
|
|
32
|
+
affectedNode.setLocked(false);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return this.action(this, affectedNode, result);
|
|
37
|
+
}
|
|
38
|
+
}
|
package/Properties.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { PropertyInputBase, PropertyInputData } from "./Inputs/PropertyInput";
|
|
2
|
+
import { ColorPropertyInput, FilePathPropertyInput, FloatPropertyInput, IntPropertyInput, PasswordPropertyInput, RangePropertyInput, SelectPropertyInput, StringPropertyInput, Vec2PropertyInput, Vec3PropertyInput, CheckboxPropertyInput, DatePropertyInput, TextareaPropertyInput, EmailPropertyInput, UrlPropertyInput } from "./Inputs/DefaultInputs";
|
|
3
|
+
import { ObjectPath } from "./Properties/ObjectPath";
|
|
4
|
+
import { Property } from "./Properties/Property";
|
|
5
|
+
import { PropertyCondition } from "./Properties/PropertyCondition";
|
|
6
|
+
import { PropertyConditionAction } from "./Properties/PropertyConditionAction";
|
|
7
|
+
import { SchemaNode } from "./Schemas/SchemaNode";
|
|
8
|
+
type PropertyCreateData<Value extends any, Input extends PropertyInputData> = {
|
|
9
|
+
name?: string;
|
|
10
|
+
value?: Value;
|
|
11
|
+
validator?: string;
|
|
12
|
+
initialize?: (node: SchemaNode) => void;
|
|
13
|
+
} & Partial<Input["properties"]>;
|
|
14
|
+
type PropertyFC<Value extends any, Input extends PropertyInputBase> = (id: string, data?: Exclude<PropertyCreateData<Value, Input["data"]>, "id">) => Property<Value, Input["data"]>;
|
|
15
|
+
export declare const PropConditions: ((data: Property<any, any>, ...conditions: PropertyConditionAction[]) => Property<any, any>) & {
|
|
16
|
+
Action: typeof PropertyConditionAction.Create;
|
|
17
|
+
Condition: typeof PropertyCondition.Create;
|
|
18
|
+
Path: typeof ObjectPath.Create;
|
|
19
|
+
};
|
|
20
|
+
export declare const ObjectProp: (id: string, name: string, ...properties: Property<any, any>[]) => Property<any, null>;
|
|
21
|
+
export declare const AnyProp: PropertyFC<any, any>;
|
|
22
|
+
export declare const StringProp: PropertyFC<string, StringPropertyInput>;
|
|
23
|
+
export declare const PasswordProp: PropertyFC<string, PasswordPropertyInput>;
|
|
24
|
+
export declare const FloatProp: PropertyFC<number, FloatPropertyInput>;
|
|
25
|
+
export declare const IntProp: PropertyFC<number, IntPropertyInput>;
|
|
26
|
+
export declare const RangeProp: PropertyFC<number, RangePropertyInput>;
|
|
27
|
+
export declare const ColorProp: PropertyFC<string, ColorPropertyInput>;
|
|
28
|
+
export declare const SelectProp: PropertyFC<string | number, SelectPropertyInput>;
|
|
29
|
+
export declare const FilePathProp: PropertyFC<string, FilePathPropertyInput>;
|
|
30
|
+
export declare const Vec2Prop: PropertyFC<{
|
|
31
|
+
x: number;
|
|
32
|
+
y: number;
|
|
33
|
+
}, Vec2PropertyInput>;
|
|
34
|
+
export declare const Vec3Prop: PropertyFC<{
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
z: number;
|
|
38
|
+
}, Vec3PropertyInput>;
|
|
39
|
+
export declare const CheckboxProp: PropertyFC<boolean, CheckboxPropertyInput>;
|
|
40
|
+
export declare const DateProp: PropertyFC<string, DatePropertyInput>;
|
|
41
|
+
export declare const TextareaProp: PropertyFC<string, TextareaPropertyInput>;
|
|
42
|
+
export declare const EmailProp: PropertyFC<string, EmailPropertyInput>;
|
|
43
|
+
export declare const UrlProp: PropertyFC<string, UrlPropertyInput>;
|
|
44
|
+
export {};
|
package/Properties.js
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { ColorPropertyInput, FilePathPropertyInput, FloatPropertyInput, IntPropertyInput, PasswordPropertyInput, RangePropertyInput, SelectPropertyInput, StringPropertyInput, Vec2PropertyInput, Vec3PropertyInput, CheckboxPropertyInput, DatePropertyInput, TextareaPropertyInput, EmailPropertyInput, UrlPropertyInput, } from "./Inputs/DefaultInputs";
|
|
2
|
+
import { ObjectPath } from "./Properties/ObjectPath";
|
|
3
|
+
import { Property } from "./Properties/Property";
|
|
4
|
+
import { PropertyCondition } from "./Properties/PropertyCondition";
|
|
5
|
+
import { PropertyConditionAction } from "./Properties/PropertyConditionAction";
|
|
6
|
+
export const PropConditions = Object.assign((data, ...conditions) => {
|
|
7
|
+
data.conditions = conditions;
|
|
8
|
+
return data;
|
|
9
|
+
}, {
|
|
10
|
+
Action: PropertyConditionAction.Create,
|
|
11
|
+
Condition: PropertyCondition.Create,
|
|
12
|
+
Path: ObjectPath.Create,
|
|
13
|
+
});
|
|
14
|
+
export const ObjectProp = (id, name, ...properties) => {
|
|
15
|
+
return Property.Create({
|
|
16
|
+
id: id,
|
|
17
|
+
name: name,
|
|
18
|
+
children: properties,
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export const AnyProp = (id, data = {}) => {
|
|
22
|
+
return Property.Create({
|
|
23
|
+
id,
|
|
24
|
+
name: data.name,
|
|
25
|
+
value: data.value ? data.value : null,
|
|
26
|
+
initialize: data.initialize,
|
|
27
|
+
input: null,
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
export const StringProp = (id, data = {}) => {
|
|
31
|
+
return Property.Create({
|
|
32
|
+
id,
|
|
33
|
+
name: data.name,
|
|
34
|
+
value: data.value ? data.value : "",
|
|
35
|
+
initialize: data.initialize,
|
|
36
|
+
input: StringPropertyInput.Create({
|
|
37
|
+
validator: data.validator,
|
|
38
|
+
properties: {
|
|
39
|
+
min: data.min ? data.min : 0,
|
|
40
|
+
max: data.max ? data.max : Number.MAX_SAFE_INTEGER,
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
export const PasswordProp = (id, data = {}) => {
|
|
46
|
+
return Property.Create({
|
|
47
|
+
id,
|
|
48
|
+
name: data.name,
|
|
49
|
+
value: data.value ? data.value : "",
|
|
50
|
+
initialize: data.initialize,
|
|
51
|
+
input: PasswordPropertyInput.Create({
|
|
52
|
+
validator: data.validator,
|
|
53
|
+
properties: {
|
|
54
|
+
min: data.min ? data.min : 0,
|
|
55
|
+
max: data.max ? data.max : Number.MAX_SAFE_INTEGER,
|
|
56
|
+
},
|
|
57
|
+
}),
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
export const FloatProp = (id, data = {}) => {
|
|
61
|
+
return Property.Create({
|
|
62
|
+
id,
|
|
63
|
+
name: data.name,
|
|
64
|
+
value: data.value ? data.value : 0,
|
|
65
|
+
initialize: data.initialize,
|
|
66
|
+
input: FloatPropertyInput.Create({
|
|
67
|
+
validator: data.validator,
|
|
68
|
+
properties: {
|
|
69
|
+
min: data.min ? data.min : 0,
|
|
70
|
+
max: data.max ? data.max : Number.MAX_VALUE,
|
|
71
|
+
},
|
|
72
|
+
}),
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
export const IntProp = (id, data = {}) => {
|
|
76
|
+
return Property.Create({
|
|
77
|
+
id,
|
|
78
|
+
name: data.name,
|
|
79
|
+
value: data.value ? data.value : 0,
|
|
80
|
+
initialize: data.initialize,
|
|
81
|
+
input: IntPropertyInput.Create({
|
|
82
|
+
validator: data.validator,
|
|
83
|
+
properties: {
|
|
84
|
+
min: data.min ? data.min : 0,
|
|
85
|
+
max: data.max ? data.max : Number.MAX_SAFE_INTEGER,
|
|
86
|
+
},
|
|
87
|
+
}),
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
export const RangeProp = (id, data = {}) => {
|
|
91
|
+
return Property.Create({
|
|
92
|
+
id,
|
|
93
|
+
name: data.name,
|
|
94
|
+
value: data.value ? data.value : 0,
|
|
95
|
+
initialize: data.initialize,
|
|
96
|
+
input: RangePropertyInput.Create({
|
|
97
|
+
validator: data.validator,
|
|
98
|
+
properties: {
|
|
99
|
+
min: data.min ? data.min : 0,
|
|
100
|
+
max: data.max ? data.max : Number.MAX_VALUE,
|
|
101
|
+
step: data.step ? data.step : 0.1,
|
|
102
|
+
},
|
|
103
|
+
}),
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
export const ColorProp = (id, data = {}) => {
|
|
107
|
+
return Property.Create({
|
|
108
|
+
id,
|
|
109
|
+
name: data.name,
|
|
110
|
+
value: data.value ? data.value : "#ffffff",
|
|
111
|
+
initialize: data.initialize,
|
|
112
|
+
input: ColorPropertyInput.Create({
|
|
113
|
+
validator: data.validator,
|
|
114
|
+
properties: {},
|
|
115
|
+
}),
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
export const SelectProp = (id, data = {}) => {
|
|
119
|
+
return Property.Create({
|
|
120
|
+
id,
|
|
121
|
+
name: data.name,
|
|
122
|
+
value: data.value ? data.value : "",
|
|
123
|
+
initialize: data.initialize,
|
|
124
|
+
input: SelectPropertyInput.Create({
|
|
125
|
+
validator: data.validator,
|
|
126
|
+
properties: {
|
|
127
|
+
options: data.options ? data.options : [],
|
|
128
|
+
mode: data.mode,
|
|
129
|
+
},
|
|
130
|
+
}),
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
export const FilePathProp = (id, data = {}) => {
|
|
134
|
+
return Property.Create({
|
|
135
|
+
id,
|
|
136
|
+
name: data.name,
|
|
137
|
+
value: data.value ? data.value : "#ffffff",
|
|
138
|
+
initialize: data.initialize,
|
|
139
|
+
input: FilePathPropertyInput.Create({
|
|
140
|
+
validator: data.validator,
|
|
141
|
+
properties: {
|
|
142
|
+
acceptedFileExtensions: data.acceptedFileExtensions
|
|
143
|
+
? data.acceptedFileExtensions
|
|
144
|
+
: [],
|
|
145
|
+
},
|
|
146
|
+
}),
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
export const Vec2Prop = (id, data = {}) => {
|
|
150
|
+
return Property.Create({
|
|
151
|
+
id,
|
|
152
|
+
name: data.name,
|
|
153
|
+
value: data.value ? data.value : { x: 0, y: 0 },
|
|
154
|
+
initialize: data.initialize,
|
|
155
|
+
input: Vec2PropertyInput.Create({
|
|
156
|
+
validator: data.validator,
|
|
157
|
+
properties: {
|
|
158
|
+
valueType: data.valueType ? data.valueType : "position",
|
|
159
|
+
},
|
|
160
|
+
}),
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
export const Vec3Prop = (id, data = {}) => {
|
|
164
|
+
return Property.Create({
|
|
165
|
+
id,
|
|
166
|
+
name: data.name,
|
|
167
|
+
value: data.value ? data.value : { x: 0, y: 0, z: 0 },
|
|
168
|
+
initialize: data.initialize,
|
|
169
|
+
input: Vec3PropertyInput.Create({
|
|
170
|
+
validator: data.validator,
|
|
171
|
+
properties: {
|
|
172
|
+
valueType: data.valueType ? data.valueType : "position",
|
|
173
|
+
},
|
|
174
|
+
}),
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
export const CheckboxProp = (id, data = {}) => {
|
|
178
|
+
return Property.Create({
|
|
179
|
+
id,
|
|
180
|
+
name: data.name,
|
|
181
|
+
value: data.value ? data.value : false,
|
|
182
|
+
initialize: data.initialize,
|
|
183
|
+
input: CheckboxPropertyInput.Create({
|
|
184
|
+
validator: data.validator,
|
|
185
|
+
properties: {},
|
|
186
|
+
}),
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
export const DateProp = (id, data = {}) => {
|
|
190
|
+
return Property.Create({
|
|
191
|
+
id,
|
|
192
|
+
name: data.name,
|
|
193
|
+
value: data.value ? data.value : "",
|
|
194
|
+
initialize: data.initialize,
|
|
195
|
+
input: DatePropertyInput.Create({
|
|
196
|
+
validator: data.validator,
|
|
197
|
+
properties: {},
|
|
198
|
+
}),
|
|
199
|
+
});
|
|
200
|
+
};
|
|
201
|
+
export const TextareaProp = (id, data = {}) => {
|
|
202
|
+
return Property.Create({
|
|
203
|
+
id,
|
|
204
|
+
name: data.name,
|
|
205
|
+
value: data.value ? data.value : "",
|
|
206
|
+
initialize: data.initialize,
|
|
207
|
+
input: TextareaPropertyInput.Create({
|
|
208
|
+
validator: data.validator,
|
|
209
|
+
properties: {
|
|
210
|
+
rows: data.rows ? data.rows : 4,
|
|
211
|
+
cols: data.cols ? data.cols : 10,
|
|
212
|
+
},
|
|
213
|
+
}),
|
|
214
|
+
});
|
|
215
|
+
};
|
|
216
|
+
export const EmailProp = (id, data = {}) => {
|
|
217
|
+
return Property.Create({
|
|
218
|
+
id,
|
|
219
|
+
name: data.name,
|
|
220
|
+
value: data.value ? data.value : "",
|
|
221
|
+
initialize: data.initialize,
|
|
222
|
+
input: EmailPropertyInput.Create({
|
|
223
|
+
validator: data.validator,
|
|
224
|
+
properties: {},
|
|
225
|
+
}),
|
|
226
|
+
});
|
|
227
|
+
};
|
|
228
|
+
export const UrlProp = (id, data = {}) => {
|
|
229
|
+
return Property.Create({
|
|
230
|
+
id,
|
|
231
|
+
name: data.name,
|
|
232
|
+
value: data.value ? data.value : "",
|
|
233
|
+
initialize: data.initialize,
|
|
234
|
+
input: UrlPropertyInput.Create({
|
|
235
|
+
validator: data.validator,
|
|
236
|
+
properties: {},
|
|
237
|
+
}),
|
|
238
|
+
});
|
|
239
|
+
};
|
package/Schema.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Property } from "./Properties/Property";
|
|
2
|
+
import { PropertyInputRegister } from "./Inputs/PropertyInputRegister";
|
|
3
|
+
import { ObjectSchemaInstance } from "./Schemas/ObjectSchemaInstance";
|
|
4
|
+
declare class SchemaData {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
properties: Property<any, any>[];
|
|
8
|
+
static Create(data: Partial<SchemaData>): SchemaData;
|
|
9
|
+
private constructor();
|
|
10
|
+
}
|
|
11
|
+
export declare class Schema<DataInterface extends object = {}> {
|
|
12
|
+
data: SchemaData;
|
|
13
|
+
static Create<DataInterface extends object = {}>(...properties: Property<any, any>[]): Schema<DataInterface>;
|
|
14
|
+
static CreateInstance<DataInterface extends object = {}>(...properties: Property<any, any>[]): ObjectSchemaInstance<DataInterface>;
|
|
15
|
+
static Inputs: typeof PropertyInputRegister;
|
|
16
|
+
private constructor();
|
|
17
|
+
private template;
|
|
18
|
+
createData(): DataInterface;
|
|
19
|
+
instantiate(data?: Partial<DataInterface>): ObjectSchemaInstance<DataInterface>;
|
|
20
|
+
private process;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
package/Schema.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Property } from "./Properties/Property";
|
|
2
|
+
import { PropertyInputRegister } from "./Inputs/PropertyInputRegister";
|
|
3
|
+
import { SchemaNode, TemplateNode } from "./Schemas/SchemaNode";
|
|
4
|
+
import { ObjectSchema } from "./Schemas/ObjectSchema";
|
|
5
|
+
import { ObjectSchemaInstanceBase, } from "./Schemas/ObjectSchemaInstance";
|
|
6
|
+
class SchemaData {
|
|
7
|
+
id;
|
|
8
|
+
name;
|
|
9
|
+
properties;
|
|
10
|
+
static Create(data) {
|
|
11
|
+
return {
|
|
12
|
+
id: data.id ? data.id : crypto.randomUUID(),
|
|
13
|
+
name: data.id ? data.id : data.name || "",
|
|
14
|
+
properties: data.properties ? [...data.properties] : [],
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
constructor(id, name, properties) {
|
|
18
|
+
this.id = id;
|
|
19
|
+
this.name = name;
|
|
20
|
+
this.properties = properties;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const traverseInstantiate = (objectSchema, properties, schemaNode, parentObject) => {
|
|
24
|
+
for (const template of properties.children) {
|
|
25
|
+
schemaNode.children ??= [];
|
|
26
|
+
const node = new SchemaNode(Property.Create(template.property), objectSchema);
|
|
27
|
+
schemaNode.children.push(node);
|
|
28
|
+
if (template.children && template.children.length) {
|
|
29
|
+
const parent = {};
|
|
30
|
+
traverseInstantiate(objectSchema, template, node, parent);
|
|
31
|
+
parentObject[template.property.id] = parent;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(parentObject, template.property.id, {
|
|
35
|
+
get() {
|
|
36
|
+
return node.get();
|
|
37
|
+
},
|
|
38
|
+
set(value) {
|
|
39
|
+
node.update(value);
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const traverseCreateData = (properties, parentObject) => {
|
|
45
|
+
for (const template of properties.children) {
|
|
46
|
+
if (template.children && template.children.length) {
|
|
47
|
+
const parent = {};
|
|
48
|
+
traverseCreateData(template, parent);
|
|
49
|
+
parentObject[template.property.id] = parent;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
Object.defineProperty(parentObject, template.property.id, {
|
|
53
|
+
value: template.property.value,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
export class Schema {
|
|
58
|
+
data;
|
|
59
|
+
static Create(...properties) {
|
|
60
|
+
return new Schema(SchemaData.Create({ id: "", name: "", properties }));
|
|
61
|
+
}
|
|
62
|
+
static CreateInstance(...properties) {
|
|
63
|
+
return new Schema(SchemaData.Create({ id: "", name: "", properties })).instantiate();
|
|
64
|
+
}
|
|
65
|
+
static Inputs = PropertyInputRegister;
|
|
66
|
+
constructor(data) {
|
|
67
|
+
this.data = data;
|
|
68
|
+
this.process();
|
|
69
|
+
}
|
|
70
|
+
template;
|
|
71
|
+
createData() {
|
|
72
|
+
const instance = {};
|
|
73
|
+
traverseCreateData(this.template, instance);
|
|
74
|
+
return instance;
|
|
75
|
+
}
|
|
76
|
+
instantiate(data) {
|
|
77
|
+
const objectSchema = new ObjectSchema(this);
|
|
78
|
+
const instance = new ObjectSchemaInstanceBase(this, objectSchema);
|
|
79
|
+
traverseInstantiate(objectSchema, this.template, objectSchema.__root, instance);
|
|
80
|
+
if (data)
|
|
81
|
+
objectSchema.loadIn(data);
|
|
82
|
+
objectSchema.init();
|
|
83
|
+
return instance;
|
|
84
|
+
}
|
|
85
|
+
process() {
|
|
86
|
+
const traverse = (properties, parent) => {
|
|
87
|
+
for (const property of properties) {
|
|
88
|
+
parent.children ??= [];
|
|
89
|
+
const newNode = new TemplateNode(property);
|
|
90
|
+
parent.children.push(newNode);
|
|
91
|
+
if (property.children)
|
|
92
|
+
traverse(property.children, newNode);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const root = new TemplateNode(Property.Create({ id: "__root__" }));
|
|
96
|
+
traverse(this.data.properties, root);
|
|
97
|
+
this.template = root;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Schema } from "../Schema";
|
|
2
|
+
import { SchemaNode } from "./SchemaNode";
|
|
3
|
+
import { ObjectPath } from "../Properties/ObjectPath";
|
|
4
|
+
export declare class ObjectSchema<DataInterface extends object = {}> {
|
|
5
|
+
private readonly __schema;
|
|
6
|
+
__root: SchemaNode<any, any>;
|
|
7
|
+
constructor(__schema: Schema);
|
|
8
|
+
init(): this;
|
|
9
|
+
evaluate(): void;
|
|
10
|
+
validate(): void;
|
|
11
|
+
traverse(run: (node: SchemaNode) => void): void;
|
|
12
|
+
getRoot(): SchemaNode<any, any>;
|
|
13
|
+
clone(): ObjectSchema<DataInterface>;
|
|
14
|
+
getNode(path: ObjectPath<DataInterface, any>): SchemaNode | null;
|
|
15
|
+
store(): DataInterface;
|
|
16
|
+
loadIn(data: DataInterface): void;
|
|
17
|
+
}
|