ngx-emfular-integration 0.0.1 → 0.0.2
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.
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { Injectable, Component } from '@angular/core';
|
|
2
|
+
import { Injectable, Component, InjectionToken, Inject } from '@angular/core';
|
|
3
|
+
import * as i1 from 'ngx-emfular-helper';
|
|
4
|
+
import { HistoryService } from 'ngx-emfular-helper';
|
|
3
5
|
|
|
4
6
|
class NgxEmfularIntegrationService {
|
|
5
7
|
constructor() { }
|
|
@@ -30,6 +32,69 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImpor
|
|
|
30
32
|
` }]
|
|
31
33
|
}] });
|
|
32
34
|
|
|
35
|
+
const HISTORY_SERVICE = new InjectionToken('HistoryService');
|
|
36
|
+
function provideHistoryForModel(prefix = 'history_', bufferSize = 50) {
|
|
37
|
+
return {
|
|
38
|
+
provide: HISTORY_SERVICE,
|
|
39
|
+
useFactory: () => new HistoryService(prefix, bufferSize)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
class ModelService {
|
|
43
|
+
historyService;
|
|
44
|
+
ioService;
|
|
45
|
+
_model;
|
|
46
|
+
get model() {
|
|
47
|
+
return this._model;
|
|
48
|
+
}
|
|
49
|
+
constructor(historyService, ioService) {
|
|
50
|
+
this.historyService = historyService;
|
|
51
|
+
this.ioService = ioService;
|
|
52
|
+
//should actually initialize a model:this._model = new M;
|
|
53
|
+
this.historyService.state$.subscribe(state => {
|
|
54
|
+
if (state) {
|
|
55
|
+
this.deserialize(state);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
serialize() {
|
|
60
|
+
return this.model.toJson();
|
|
61
|
+
}
|
|
62
|
+
saveCurrentState() {
|
|
63
|
+
this.historyService.save(this.serialize());
|
|
64
|
+
}
|
|
65
|
+
applyModel(modelJson) {
|
|
66
|
+
let m = this.deserialize(modelJson);
|
|
67
|
+
this._model = m;
|
|
68
|
+
return m;
|
|
69
|
+
}
|
|
70
|
+
load(modelJson) {
|
|
71
|
+
const model = this.applyModel(modelJson);
|
|
72
|
+
this.saveCurrentState();
|
|
73
|
+
return model;
|
|
74
|
+
}
|
|
75
|
+
loadFromFile(event) {
|
|
76
|
+
this.ioService.loadStringFromFile(event).then(txt => {
|
|
77
|
+
//todo insert detection code for wrong files (no json, not appropriately structured
|
|
78
|
+
this.load(JSON.parse(txt));
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
save() {
|
|
82
|
+
const jsonString = JSON.stringify(this.serialize());
|
|
83
|
+
this.ioService.saveJson(jsonString, this.fileTitle());
|
|
84
|
+
}
|
|
85
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ModelService, deps: [{ token: HISTORY_SERVICE }, { token: i1.IoService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
86
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ModelService, providedIn: 'root' });
|
|
87
|
+
}
|
|
88
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImport: i0, type: ModelService, decorators: [{
|
|
89
|
+
type: Injectable,
|
|
90
|
+
args: [{
|
|
91
|
+
providedIn: 'root'
|
|
92
|
+
}]
|
|
93
|
+
}], ctorParameters: () => [{ type: i1.HistoryService, decorators: [{
|
|
94
|
+
type: Inject,
|
|
95
|
+
args: [HISTORY_SERVICE]
|
|
96
|
+
}] }, { type: i1.IoService }] });
|
|
97
|
+
|
|
33
98
|
/*
|
|
34
99
|
* Public API Surface of ngx-emfular-integration
|
|
35
100
|
*/
|
|
@@ -38,5 +103,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.4", ngImpor
|
|
|
38
103
|
* Generated bundle index. Do not edit.
|
|
39
104
|
*/
|
|
40
105
|
|
|
41
|
-
export { NgxEmfularIntegrationComponent, NgxEmfularIntegrationService };
|
|
106
|
+
export { HISTORY_SERVICE, ModelService, NgxEmfularIntegrationComponent, NgxEmfularIntegrationService, provideHistoryForModel };
|
|
42
107
|
//# sourceMappingURL=ngx-emfular-integration.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngx-emfular-integration.mjs","sources":["../../../projects/ngx-emfular-integration/src/lib/ngx-emfular-integration.service.ts","../../../projects/ngx-emfular-integration/src/lib/ngx-emfular-integration.component.ts","../../../projects/ngx-emfular-integration/src/public-api.ts","../../../projects/ngx-emfular-integration/src/ngx-emfular-integration.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class NgxEmfularIntegrationService {\n\n constructor() { }\n}\n","import { Component } from '@angular/core';\n\n@Component({\n selector: 'lib-ngx-emfular-integration',\n imports: [],\n template: `\n <p>\n ngx-emfular-integration works!\n </p>\n `,\n styles: ``\n})\nexport class NgxEmfularIntegrationComponent {\n\n}\n","/*\n * Public API Surface of ngx-emfular-integration\n */\n\nexport * from './lib/ngx-emfular-integration.service';\nexport * from './lib/ngx-emfular-integration.component';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ngx-emfular-integration.mjs","sources":["../../../projects/ngx-emfular-integration/src/lib/ngx-emfular-integration.service.ts","../../../projects/ngx-emfular-integration/src/lib/ngx-emfular-integration.component.ts","../../../projects/ngx-emfular-integration/src/lib/model.service.ts","../../../projects/ngx-emfular-integration/src/public-api.ts","../../../projects/ngx-emfular-integration/src/ngx-emfular-integration.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class NgxEmfularIntegrationService {\n\n constructor() { }\n}\n","import { Component } from '@angular/core';\n\n@Component({\n selector: 'lib-ngx-emfular-integration',\n imports: [],\n template: `\n <p>\n ngx-emfular-integration works!\n </p>\n `,\n styles: ``\n})\nexport class NgxEmfularIntegrationComponent {\n\n}\n","import {Inject, Injectable, InjectionToken} from '@angular/core';\nimport {JsonOf, Referencable} from \"emfular\";\nimport {HistoryService, IoService} from \"ngx-emfular-helper\";\n\nexport const HISTORY_SERVICE = new InjectionToken<HistoryService<any>>(\n 'HistoryService'\n);\nexport function provideHistoryForModel<M>(\n prefix: string = 'history_',\n bufferSize: number = 50\n) {\n return {\n provide: HISTORY_SERVICE,\n useFactory: () => new HistoryService<JsonOf<M>>(prefix, bufferSize)\n };\n}\n\n\n@Injectable({\n providedIn: 'root'\n})\nexport abstract class ModelService<M extends Referencable<any>> {\n\n protected _model!: M\n get model(): M {\n return this._model;\n }\n\n abstract fileTitle(): string // either a fixed string or sth from the current model itself\n\n // M.fromJson(modelJson) plus any convenience /graphical organization necessary\n abstract deserialize(modelJson: JsonOf<M>): M\n\n protected constructor(\n @Inject(HISTORY_SERVICE) private readonly historyService: HistoryService<JsonOf<M>>,\n private ioService: IoService\n ) {\n //should actually initialize a model:this._model = new M;\n this.historyService.state$.subscribe(state => {\n if (state) {\n this.deserialize(state);\n }\n });\n }\n\n serialize(): JsonOf<M> {\n return this.model.toJson()\n }\n\n saveCurrentState() {\n this.historyService.save(this.serialize())\n }\n\n protected applyModel(modelJson: JsonOf<M>): M {\n let m: M = this.deserialize(modelJson);\n this._model = m;\n return m;\n }\n\n load(modelJson: JsonOf<M>): M {\n const model = this.applyModel(modelJson);\n this.saveCurrentState()\n return model;\n }\n\n loadFromFile(event: Event) {\n this.ioService.loadStringFromFile(event).then(txt => {\n //todo insert detection code for wrong files (no json, not appropriately structured\n this.load(JSON.parse(txt));\n });\n }\n\n save() {\n const jsonString = JSON.stringify(this.serialize());\n this.ioService.saveJson(jsonString, this.fileTitle())\n }\n\n}\n","/*\n * Public API Surface of ngx-emfular-integration\n */\n\nexport * from './lib/ngx-emfular-integration.service';\nexport * from './lib/ngx-emfular-integration.component';\nexport * from './lib/model.service';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;MAKa,4BAA4B,CAAA;AAEvC,IAAA,WAAA,GAAA;uGAFW,4BAA4B,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAA5B,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,4BAA4B,cAF3B,MAAM,EAAA,CAAA;;2FAEP,4BAA4B,EAAA,UAAA,EAAA,CAAA;kBAHxC,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE;AACb,iBAAA;;;MCQY,8BAA8B,CAAA;uGAA9B,8BAA8B,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;AAA9B,IAAA,OAAA,IAAA,GAAA,EAAA,CAAA,oBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,IAAA,EAAA,8BAA8B,EAP/B,YAAA,EAAA,IAAA,EAAA,QAAA,EAAA,6BAAA,EAAA,QAAA,EAAA,EAAA,EAAA,QAAA,EAAA;;;;AAIT,EAAA,CAAA,EAAA,QAAA,EAAA,IAAA,EAAA,MAAA,EAAA,CAAA,EAAA,CAAA,EAAA,CAAA;;2FAGU,8BAA8B,EAAA,UAAA,EAAA,CAAA;kBAV1C,SAAS;+BACE,6BAA6B,EAAA,OAAA,EAC9B,EAAE,EACD,QAAA,EAAA;;;;AAIT,EAAA,CAAA,EAAA;;;MCLU,eAAe,GAAG,IAAI,cAAc,CAC7C,gBAAgB;SAEJ,sBAAsB,CAClC,SAAiB,UAAU,EA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AC,CAAC;AAC5B,SAAC,CAAC;;IAGJ,IAAI,GAAA;QACF,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;AACnD,QAAA,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;;AArDnC,IAAA,OAAA,IAAA,GAAA,EAAA,CAAA,kBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,YAAY,kBAapB,eAAe,EAAA,EAAA,EAAA,KAAA,EAAA,EAAA,CAAA,SAAA,EAAA,CAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAbP,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,YAAY,cAFpB,MAAM,EAAA,CAAA;;2FAEE,YAAY,EAAA,UAAA,EAAA,CAAA;kBAHjC,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE;AACb,iBAAA;;0BAcM,MAAM;2BAAC,eAAe;;;AClC7B;;AAEG;;ACFH;;AAEG;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
import { JsonOf, Referencable } from "emfular";
|
|
3
|
+
import { HistoryService, IoService } from "ngx-emfular-helper";
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
export declare const HISTORY_SERVICE: InjectionToken<HistoryService<any>>;
|
|
6
|
+
export declare function provideHistoryForModel<M>(prefix?: string, bufferSize?: number): {
|
|
7
|
+
provide: InjectionToken<HistoryService<any>>;
|
|
8
|
+
useFactory: () => HistoryService<JsonOf<M>>;
|
|
9
|
+
};
|
|
10
|
+
export declare abstract class ModelService<M extends Referencable<any>> {
|
|
11
|
+
private readonly historyService;
|
|
12
|
+
private ioService;
|
|
13
|
+
protected _model: M;
|
|
14
|
+
get model(): M;
|
|
15
|
+
abstract fileTitle(): string;
|
|
16
|
+
abstract deserialize(modelJson: JsonOf<M>): M;
|
|
17
|
+
protected constructor(historyService: HistoryService<JsonOf<M>>, ioService: IoService);
|
|
18
|
+
serialize(): JsonOf<M>;
|
|
19
|
+
saveCurrentState(): void;
|
|
20
|
+
protected applyModel(modelJson: JsonOf<M>): M;
|
|
21
|
+
load(modelJson: JsonOf<M>): M;
|
|
22
|
+
loadFromFile(event: Event): void;
|
|
23
|
+
save(): void;
|
|
24
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ModelService<any>, never>;
|
|
25
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<ModelService<any>>;
|
|
26
|
+
}
|
package/package.json
CHANGED
package/public-api.d.ts
CHANGED