@mat3ra/ade 2025.10.2-0
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/.babelrc +17 -0
- package/LICENSE.md +15 -0
- package/README.md +106 -0
- package/dist/js/ApplicationRegistry.d.ts +57 -0
- package/dist/js/ApplicationRegistry.js +171 -0
- package/dist/js/application.d.ts +8 -0
- package/dist/js/application.js +9 -0
- package/dist/js/applicationMixin.d.ts +23 -0
- package/dist/js/applicationMixin.js +48 -0
- package/dist/js/context/ContextProvider.d.ts +83 -0
- package/dist/js/context/ContextProvider.js +139 -0
- package/dist/js/context/ContextProviderRegistryContainer.d.ts +24 -0
- package/dist/js/context/ContextProviderRegistryContainer.js +30 -0
- package/dist/js/context/JSONSchemaFormDataProvider.d.ts +25 -0
- package/dist/js/context/JSONSchemaFormDataProvider.js +46 -0
- package/dist/js/executable.d.ts +8 -0
- package/dist/js/executable.js +12 -0
- package/dist/js/executableMixin.d.ts +22 -0
- package/dist/js/executableMixin.js +28 -0
- package/dist/js/flavor.d.ts +9 -0
- package/dist/js/flavor.js +12 -0
- package/dist/js/flavorMixin.d.ts +21 -0
- package/dist/js/flavorMixin.js +51 -0
- package/dist/js/index.d.ts +5 -0
- package/dist/js/index.js +14 -0
- package/dist/js/template.d.ts +8 -0
- package/dist/js/template.js +10 -0
- package/dist/js/templateMixin.d.ts +39 -0
- package/dist/js/templateMixin.js +162 -0
- package/package.json +88 -0
- package/src/js/ApplicationRegistry.ts +250 -0
- package/src/js/application.ts +18 -0
- package/src/js/applicationMixin.ts +86 -0
- package/src/js/context/ContextProvider.ts +189 -0
- package/src/js/context/ContextProviderRegistryContainer.ts +41 -0
- package/src/js/context/JSONSchemaFormDataProvider.ts +57 -0
- package/src/js/executable.ts +14 -0
- package/src/js/executableMixin.ts +49 -0
- package/src/js/flavor.ts +19 -0
- package/src/js/flavorMixin.ts +77 -0
- package/src/js/index.ts +6 -0
- package/src/js/template.ts +17 -0
- package/src/js/templateMixin.ts +242 -0
- package/tsconfig.json +3 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @summary This is a standalone class that contains "data" for a property with "name". Helps facilitate UI logic.
|
|
3
|
+
* Can be initialized from context when user edits are present:
|
|
4
|
+
* - user edits the corresponding property, eg. "kpath"
|
|
5
|
+
* - isKpathEdited is set to `true`
|
|
6
|
+
* - context property is updated for the parent entity (eg. Unit) in a way that persists in Redux state
|
|
7
|
+
* - new entity inherits the "data" through "context" field in config
|
|
8
|
+
* - `extraData` field is used to store any other data that should be passed from one instance of provider
|
|
9
|
+
* to next one, for example data about material to track when it is changed.
|
|
10
|
+
* @notes Should hold static data only (see `setData` method), no classes or functions
|
|
11
|
+
*/
|
|
12
|
+
import { Utils } from "@mat3ra/utils";
|
|
13
|
+
import lodash from "lodash";
|
|
14
|
+
|
|
15
|
+
export interface ContextProviderInstance {
|
|
16
|
+
constructor: typeof ContextProvider;
|
|
17
|
+
config: ContextProviderConfig;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ContextProviderConfig {
|
|
21
|
+
name: ContextProviderName | `${ContextProviderName}`;
|
|
22
|
+
domain?: string;
|
|
23
|
+
entityName?: string;
|
|
24
|
+
data?: object;
|
|
25
|
+
extraData?: object;
|
|
26
|
+
isEdited?: boolean;
|
|
27
|
+
context?: object;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// TODO: separate application-specific CPs
|
|
31
|
+
export enum ContextProviderName {
|
|
32
|
+
PlanewaveCutoffDataManager = "PlanewaveCutoffDataManager",
|
|
33
|
+
KGridFormDataManager = "KGridFormDataManager",
|
|
34
|
+
QGridFormDataManager = "QGridFormDataManager",
|
|
35
|
+
IGridFormDataManager = "IGridFormDataManager",
|
|
36
|
+
QPathFormDataManager = "QPathFormDataManager",
|
|
37
|
+
IPathFormDataManager = "IPathFormDataManager",
|
|
38
|
+
KPathFormDataManager = "KPathFormDataManager",
|
|
39
|
+
ExplicitKPathFormDataManager = "ExplicitKPathFormDataManager",
|
|
40
|
+
ExplicitKPath2PIBAFormDataManager = "ExplicitKPath2PIBAFormDataManager",
|
|
41
|
+
HubbardJContextManager = "HubbardJContextManager",
|
|
42
|
+
HubbardUContextManager = "HubbardUContextManager",
|
|
43
|
+
HubbardVContextManager = "HubbardVContextManager",
|
|
44
|
+
HubbardContextManagerLegacy = "HubbardContextManagerLegacy",
|
|
45
|
+
NEBFormDataManager = "NEBFormDataManager",
|
|
46
|
+
BoundaryConditionsFormDataManager = "BoundaryConditionsFormDataManager",
|
|
47
|
+
MLSettingsDataManager = "MLSettingsDataManager",
|
|
48
|
+
MLTrainTestSplitDataManager = "MLTrainTestSplitDataManager",
|
|
49
|
+
IonDynamicsContextProvider = "IonDynamicsContextProvider",
|
|
50
|
+
CollinearMagnetizationDataManager = "CollinearMagnetizationDataManager",
|
|
51
|
+
NonCollinearMagnetizationDataManager = "NonCollinearMagnetizationDataManager",
|
|
52
|
+
QEPWXInputDataManager = "QEPWXInputDataManager",
|
|
53
|
+
QENEBInputDataManager = "QENEBInputDataManager",
|
|
54
|
+
VASPInputDataManager = "VASPInputDataManager",
|
|
55
|
+
VASPNEBInputDataManager = "VASPNEBInputDataManager",
|
|
56
|
+
NWChemInputDataManager = "NWChemInputDataManager",
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface ContextProviderStatic {
|
|
60
|
+
getConstructorConfig: (config: ContextProviderConfig) => ContextProviderInstance;
|
|
61
|
+
createConfigFromContext: (config: ContextProviderConfig) => ContextProviderConfig;
|
|
62
|
+
getExtraDataKeyByName: (name: string) => string;
|
|
63
|
+
getIsEditedKeyByName: (name: string) => string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default class ContextProvider {
|
|
67
|
+
config: ContextProviderConfig;
|
|
68
|
+
|
|
69
|
+
name: `${ContextProviderName}`;
|
|
70
|
+
|
|
71
|
+
domain?: string;
|
|
72
|
+
|
|
73
|
+
entityName?: string;
|
|
74
|
+
|
|
75
|
+
data?: object;
|
|
76
|
+
|
|
77
|
+
extraData?: object;
|
|
78
|
+
|
|
79
|
+
isEdited?: boolean;
|
|
80
|
+
|
|
81
|
+
constructor(config: ContextProviderConfig) {
|
|
82
|
+
this.config = config;
|
|
83
|
+
this.name = config.name; // property name, ie. "kpath"
|
|
84
|
+
this.domain = config.domain || "default";
|
|
85
|
+
|
|
86
|
+
// if context is passed inside config, treat it as additional config
|
|
87
|
+
// eslint-disable-next-line no-param-reassign
|
|
88
|
+
if (config.context) config = ContextProvider.createConfigFromContext(config);
|
|
89
|
+
|
|
90
|
+
this.entityName = config.entityName || "unit"; // entity this provider yields data to, eg. "unit", "subworkflow"
|
|
91
|
+
this.data = config.data; // property data container
|
|
92
|
+
this.extraData = config.extraData; // property extraData container, used track changes to data, for example
|
|
93
|
+
this.isEdited = config.isEdited; // whether property was edited by user, available under `isEdited` key
|
|
94
|
+
|
|
95
|
+
this.setIsEdited = this.setIsEdited.bind(this);
|
|
96
|
+
this.getData = this.getData.bind(this);
|
|
97
|
+
this.setData = this.setData.bind(this);
|
|
98
|
+
this.transformData = this.transformData.bind(this);
|
|
99
|
+
this.yieldData = this.yieldData.bind(this);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static getConstructorConfig(config: ContextProviderConfig): ContextProviderInstance {
|
|
103
|
+
return {
|
|
104
|
+
constructor: this.prototype.constructor as typeof ContextProvider,
|
|
105
|
+
config,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static createConfigFromContext(config: ContextProviderConfig) {
|
|
110
|
+
const data = lodash.get(config.context, config.name);
|
|
111
|
+
const isEdited = lodash.get(config.context, this.getIsEditedKeyByName(config.name));
|
|
112
|
+
const extraData = lodash.get(config.context, this.getExtraDataKeyByName(config.name));
|
|
113
|
+
return Object.assign(
|
|
114
|
+
config,
|
|
115
|
+
data
|
|
116
|
+
? {
|
|
117
|
+
data,
|
|
118
|
+
extraData,
|
|
119
|
+
isEdited,
|
|
120
|
+
}
|
|
121
|
+
: {},
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
setIsEdited(isEdited: boolean) {
|
|
126
|
+
this.isEdited = isEdited;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
getData() {
|
|
130
|
+
return this.isEdited ? this.data : this.defaultData;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
setData(data: object) {
|
|
134
|
+
this.data = Utils.clone.deepClone(data);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// override in children
|
|
138
|
+
// eslint-disable-next-line class-methods-use-this
|
|
139
|
+
get defaultData(): object {
|
|
140
|
+
throw new Error("Not implemented.");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// override in children
|
|
144
|
+
// eslint-disable-next-line class-methods-use-this
|
|
145
|
+
transformData(data: object) {
|
|
146
|
+
return data;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
150
|
+
yieldData(...transformDataArgs: any) {
|
|
151
|
+
const extraDataObject = this.extraData ? { [this.extraDataKey]: this.extraData } : {};
|
|
152
|
+
return {
|
|
153
|
+
...extraDataObject,
|
|
154
|
+
// @ts-ignore
|
|
155
|
+
[this.name]: this.transformData(this.getData(), ...transformDataArgs),
|
|
156
|
+
[this.isEditedKey]: this.isEdited,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// override when this.data needs additional processing before making it available to rendering context
|
|
161
|
+
// used to calculate explicit points path, for example
|
|
162
|
+
yieldDataForRendering() {
|
|
163
|
+
return this.yieldData();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
get extraDataKey() {
|
|
167
|
+
return `${this.name}ExtraData`;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
static getExtraDataKeyByName(name: string) {
|
|
171
|
+
return `${name}ExtraData`;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
get isEditedKey() {
|
|
175
|
+
return `is${lodash.capitalize(this.name)}Edited`;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
static getIsEditedKeyByName(name: string) {
|
|
179
|
+
return `is${lodash.capitalize(name)}Edited`;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
get isUnitContextProvider() {
|
|
183
|
+
return this.entityName === "unit";
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
get isSubworkflowContextProvider() {
|
|
187
|
+
return this.entityName === "subworkflow";
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ContextProviderInstance } from "./ContextProvider";
|
|
2
|
+
import ContextProvider from "./ContextProvider";
|
|
3
|
+
|
|
4
|
+
export default class ContextProviderRegistryContainer {
|
|
5
|
+
_providers: {
|
|
6
|
+
name: string;
|
|
7
|
+
instance: ContextProviderInstance;
|
|
8
|
+
}[];
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
this._providers = [];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get providers() {
|
|
15
|
+
return this._providers;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
set providers(p) {
|
|
19
|
+
this._providers = p;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
addProvider({ name, instance }: { name: string; instance: ContextProviderInstance }) {
|
|
23
|
+
this._providers.push({
|
|
24
|
+
name,
|
|
25
|
+
instance,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
findProviderInstanceByName(name: string) {
|
|
30
|
+
const provider = this.providers.find((p) => p.name === name);
|
|
31
|
+
return provider && provider.instance;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
removeProvider(providerCls: ContextProvider) {
|
|
35
|
+
this.providers = this.providers.filter((p) => p.name !== providerCls.name);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
removeProviderByName(name: string) {
|
|
39
|
+
this.providers = this.providers.filter((p) => p.name !== name);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/* eslint-disable class-methods-use-this */
|
|
2
|
+
import type { UiSchema } from "react-jsonschema-form";
|
|
3
|
+
|
|
4
|
+
import ContextProvider, { type ContextProviderConfig } from "./ContextProvider";
|
|
5
|
+
|
|
6
|
+
interface JSONSchemaFormDataProviderConfig extends ContextProviderConfig {
|
|
7
|
+
isUsingJinjaVariables?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @summary Provides jsonSchema and uiSchema for generating react-jsonschema-form
|
|
12
|
+
* See https://github.com/mozilla-services/react-jsonschema-form for Form UI.
|
|
13
|
+
* Form generation example:
|
|
14
|
+
* ```
|
|
15
|
+
* <Form schema={provider.jsonSchema}
|
|
16
|
+
* uiSchema={provider.uiSchema}
|
|
17
|
+
* formData={provider.getData(unit.important)} />
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export default class JSONSchemaFormDataProvider extends ContextProvider {
|
|
21
|
+
isUsingJinjaVariables: boolean;
|
|
22
|
+
|
|
23
|
+
constructor(config: JSONSchemaFormDataProviderConfig) {
|
|
24
|
+
super(config);
|
|
25
|
+
this.isUsingJinjaVariables = Boolean(config?.isUsingJinjaVariables);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get jsonSchema() {
|
|
29
|
+
throw new Error("Not implemented.");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get uiSchema(): UiSchema {
|
|
33
|
+
throw new Error("Not implemented.");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get fields() {
|
|
37
|
+
return {};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get defaultFieldStyles() {
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get uiSchemaStyled(): UiSchema {
|
|
45
|
+
const schema = this.uiSchema;
|
|
46
|
+
return Object.fromEntries(
|
|
47
|
+
Object.entries(schema).map(([key, value]) => [
|
|
48
|
+
key,
|
|
49
|
+
{
|
|
50
|
+
...value,
|
|
51
|
+
...this.defaultFieldStyles,
|
|
52
|
+
classNames: `${value.classNames || ""}`,
|
|
53
|
+
},
|
|
54
|
+
]),
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { NamedDefaultableInMemoryEntity } from "@mat3ra/code/dist/js/entity";
|
|
2
|
+
import { runtimeItemsMixin } from "@mat3ra/code/dist/js/entity/mixins/RuntimeItemsMixin";
|
|
3
|
+
import type { Constructor } from "@mat3ra/code/dist/js/utils/types";
|
|
4
|
+
|
|
5
|
+
import { type ExecutableMixin, executableMixin, executableStaticMixin } from "./executableMixin";
|
|
6
|
+
|
|
7
|
+
type Base = Constructor<ExecutableMixin> & typeof NamedDefaultableInMemoryEntity;
|
|
8
|
+
|
|
9
|
+
export default class Executable extends (NamedDefaultableInMemoryEntity as Base) {}
|
|
10
|
+
|
|
11
|
+
// Apply mixins
|
|
12
|
+
runtimeItemsMixin(Executable.prototype);
|
|
13
|
+
executableMixin(Executable.prototype);
|
|
14
|
+
executableStaticMixin(Executable);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
|
|
2
|
+
import type { DefaultableInMemoryEntity } from "@mat3ra/code/dist/js/entity/mixins/DefaultableMixin";
|
|
3
|
+
import type { NamedInMemoryEntity } from "@mat3ra/code/dist/js/entity/mixins/NamedEntityMixin";
|
|
4
|
+
import type { Constructor } from "@mat3ra/code/dist/js/utils/types";
|
|
5
|
+
import JSONSchemasInterface from "@mat3ra/esse/dist/js/esse/JSONSchemasInterface";
|
|
6
|
+
import type { AnyObject } from "@mat3ra/esse/dist/js/esse/types";
|
|
7
|
+
import type { ExecutableSchema } from "@mat3ra/esse/dist/js/types";
|
|
8
|
+
|
|
9
|
+
import type { FlavorMixin } from "./flavorMixin";
|
|
10
|
+
|
|
11
|
+
type BaseFlavor = FlavorMixin & NamedInMemoryEntity & InMemoryEntity;
|
|
12
|
+
type Base = InMemoryEntity & NamedInMemoryEntity & DefaultableInMemoryEntity;
|
|
13
|
+
|
|
14
|
+
export function executableMixin(item: Base) {
|
|
15
|
+
// @ts-expect-error
|
|
16
|
+
const properties: ExecutableMixin & Base = {
|
|
17
|
+
get applicationId() {
|
|
18
|
+
return this.prop("applicationId", []);
|
|
19
|
+
},
|
|
20
|
+
set applicationId(value: string[]) {
|
|
21
|
+
this.setProp("applicationId", value);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function executableStaticMixin(Executable: Constructor<Base>) {
|
|
29
|
+
const properties: ExecutableStaticMixin = {
|
|
30
|
+
get jsonSchema() {
|
|
31
|
+
return JSONSchemasInterface.getSchemaById("software/executable") as ExecutableSchema;
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
Object.defineProperties(Executable, Object.getOwnPropertyDescriptors(properties));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type BaseConstructor = Constructor<Base> & {
|
|
39
|
+
constructCustomFlavor?: (config: object) => BaseFlavor;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type ExecutableMixin = {
|
|
43
|
+
applicationId: string[];
|
|
44
|
+
toJSON: () => ExecutableSchema & AnyObject;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type ExecutableStaticMixin = {
|
|
48
|
+
jsonSchema: ExecutableSchema;
|
|
49
|
+
};
|
package/src/js/flavor.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { NamedDefaultableInMemoryEntity } from "@mat3ra/code/dist/js/entity";
|
|
2
|
+
import {
|
|
3
|
+
type RuntimeItemsInMemoryEntity,
|
|
4
|
+
runtimeItemsMixin,
|
|
5
|
+
} from "@mat3ra/code/dist/js/entity/mixins/RuntimeItemsMixin";
|
|
6
|
+
import type { Constructor } from "@mat3ra/code/dist/js/utils/types";
|
|
7
|
+
|
|
8
|
+
import { type FlavorMixin, flavorMixin, flavorStaticMixin } from "./flavorMixin";
|
|
9
|
+
|
|
10
|
+
type Base = typeof NamedDefaultableInMemoryEntity &
|
|
11
|
+
Constructor<FlavorMixin> &
|
|
12
|
+
Constructor<RuntimeItemsInMemoryEntity>;
|
|
13
|
+
|
|
14
|
+
export default class Flavor extends (NamedDefaultableInMemoryEntity as Base) {}
|
|
15
|
+
|
|
16
|
+
// Apply mixins
|
|
17
|
+
flavorMixin(Flavor.prototype);
|
|
18
|
+
runtimeItemsMixin(Flavor.prototype);
|
|
19
|
+
flavorStaticMixin(Flavor);
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
|
|
2
|
+
import type { NamedInMemoryEntity } from "@mat3ra/code/dist/js/entity/mixins/NamedEntityMixin";
|
|
3
|
+
import type { Constructor } from "@mat3ra/code/dist/js/utils/types";
|
|
4
|
+
import JSONSchemasInterface from "@mat3ra/esse/dist/js/esse/JSONSchemasInterface";
|
|
5
|
+
import type { FlavorSchema } from "@mat3ra/esse/dist/js/types";
|
|
6
|
+
|
|
7
|
+
type Base = InMemoryEntity & NamedInMemoryEntity;
|
|
8
|
+
|
|
9
|
+
type Input = Required<FlavorSchema>["input"];
|
|
10
|
+
|
|
11
|
+
export type FlavorMixin = {
|
|
12
|
+
input: Input;
|
|
13
|
+
disableRenderMaterials: boolean;
|
|
14
|
+
executableId: string;
|
|
15
|
+
executableName: string;
|
|
16
|
+
applicationName: string;
|
|
17
|
+
supportedApplicationVersions?: string[];
|
|
18
|
+
getInputAsRenderedTemplates: (context: Record<string, unknown>) => Record<string, unknown>[];
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// TODO: should we add fields from esse schema (executableId, executableName, applicationName)?
|
|
22
|
+
export function flavorMixin(item: Base) {
|
|
23
|
+
// @ts-expect-error
|
|
24
|
+
const properties: FlavorMixin & Base = {
|
|
25
|
+
get input() {
|
|
26
|
+
return this.prop<Input>("input", []);
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
get disableRenderMaterials() {
|
|
30
|
+
return this.prop("isMultiMaterial", false);
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
get executableId() {
|
|
34
|
+
return this.prop("executableId", "");
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
get executableName() {
|
|
38
|
+
return this.prop("executableName", "");
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
get applicationName() {
|
|
42
|
+
return this.prop("applicationName", "");
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
get supportedApplicationVersions() {
|
|
46
|
+
return this.prop("supportedApplicationVersions");
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
getInputAsRenderedTemplates(context: Record<string, unknown>) {
|
|
50
|
+
const input = this.input;
|
|
51
|
+
return input.map((template) => {
|
|
52
|
+
if (template && typeof template === "object" && "getRenderedJSON" in template) {
|
|
53
|
+
return (template as any).getRenderedJSON(context);
|
|
54
|
+
}
|
|
55
|
+
return template;
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
|
|
61
|
+
|
|
62
|
+
return properties;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function flavorStaticMixin(Flavor: Constructor<Base>) {
|
|
66
|
+
const properties: FlavorStaticMixin = {
|
|
67
|
+
get jsonSchema() {
|
|
68
|
+
return JSONSchemasInterface.getSchemaById("software/flavor") as FlavorSchema;
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
Object.defineProperties(Flavor, Object.getOwnPropertyDescriptors(properties));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type FlavorStaticMixin = {
|
|
76
|
+
jsonSchema: FlavorSchema;
|
|
77
|
+
};
|
package/src/js/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { NamedInMemoryEntity } from "@mat3ra/code/dist/js/entity";
|
|
2
|
+
import type { Constructor } from "@mat3ra/code/dist/js/utils/types";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
type TemplateMixin,
|
|
6
|
+
type TemplateStaticMixin,
|
|
7
|
+
templateMixin,
|
|
8
|
+
templateStaticMixin,
|
|
9
|
+
} from "./templateMixin";
|
|
10
|
+
|
|
11
|
+
type Base = typeof NamedInMemoryEntity & Constructor<TemplateMixin> & TemplateStaticMixin;
|
|
12
|
+
|
|
13
|
+
export default class Template extends (NamedInMemoryEntity as Base) {}
|
|
14
|
+
|
|
15
|
+
// Apply mixins
|
|
16
|
+
templateMixin(Template.prototype);
|
|
17
|
+
templateStaticMixin(Template);
|