sprotty-protocol
Advanced tools
Comparing version 0.11.0-next.ddf634c to 0.11.0
@@ -17,6 +17,5 @@ /******************************************************************************** | ||
import { Action, ResponseAction, RequestModelAction, ComputedBoundsAction, LayoutAction, RequestAction } from './actions'; | ||
import { DiagramServices, DiagramState, IDiagramGenerator, IModelLayoutEngine } from './diagram-services'; | ||
import { SModelRoot } from './model'; | ||
import { Deferred } from './utils/async'; | ||
import { JsonMap } from './utils/json'; | ||
import { SModelIndex } from './utils/model-utils'; | ||
/** | ||
@@ -27,9 +26,10 @@ * An instance of this class is responsible for handling a single diagram client. It holds the current | ||
export declare class DiagramServer { | ||
protected readonly state: DiagramState & { | ||
readonly state: DiagramState & { | ||
lastSubmittedModelType?: string; | ||
}; | ||
readonly dispatch: <A extends Action>(action: A) => Promise<void>; | ||
protected readonly diagramGenerator: IDiagramGenerator; | ||
protected readonly layoutEngine?: IModelLayoutEngine; | ||
protected readonly requests: Map<string, Deferred<ResponseAction>>; | ||
protected readonly handlers: Map<string, ServerActionHandler<Action>[]>; | ||
readonly dispatch: <A extends Action>(action: A) => Promise<void>; | ||
readonly services: DiagramServices; | ||
constructor(dispatch: <A extends Action>(action: A) => Promise<void>, services: DiagramServices); | ||
@@ -93,22 +93,3 @@ /** | ||
} | ||
export declare type DiagramOptions = JsonMap; | ||
export interface IModelLayoutEngine { | ||
layout(model: SModelRoot, index?: SModelIndex): SModelRoot | Promise<SModelRoot>; | ||
} | ||
export interface IDiagramGenerator { | ||
generate(args: { | ||
options: DiagramOptions; | ||
state: DiagramState; | ||
}): SModelRoot | Promise<SModelRoot>; | ||
} | ||
export interface DiagramServices { | ||
readonly diagramGenerator: IDiagramGenerator; | ||
readonly layoutEngine: IModelLayoutEngine; | ||
} | ||
export interface DiagramState { | ||
options?: DiagramOptions; | ||
currentRoot: SModelRoot; | ||
revision: number; | ||
} | ||
export declare type ServerActionHandler<A extends Action = Action> = (action: A, state: DiagramState, server: DiagramServer) => Promise<void>; | ||
//# sourceMappingURL=diagram-server.d.ts.map |
@@ -73,3 +73,4 @@ "use strict"; | ||
this.dispatch = dispatch; | ||
this.services = services; | ||
this.diagramGenerator = services.DiagramGenerator; | ||
this.layoutEngine = services.ModelLayoutEngine; | ||
} | ||
@@ -239,3 +240,3 @@ /** | ||
_b.trys.push([1, 4, , 5]); | ||
return [4 /*yield*/, this.services.diagramGenerator.generate({ | ||
return [4 /*yield*/, this.diagramGenerator.generate({ | ||
options: (_a = this.state.options) !== null && _a !== void 0 ? _a : {}, | ||
@@ -310,4 +311,4 @@ state: this.state | ||
} | ||
if (!this.needsServerLayout) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.services.layoutEngine.layout(newRoot)]; | ||
if (!(this.needsServerLayout && this.layoutEngine)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.layoutEngine.layout(newRoot)]; | ||
case 1: | ||
@@ -350,9 +351,25 @@ newRoot = _a.sent(); | ||
DiagramServer.prototype.handleLayout = function (action) { | ||
if (!this.needsServerLayout) { | ||
return Promise.resolve(); | ||
} | ||
var newRoot = model_utils_1.cloneModel(this.state.currentRoot); | ||
newRoot.revision = ++this.state.revision; | ||
this.state.currentRoot = newRoot; | ||
return this.doSubmitModel(newRoot, true, action); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var newRoot; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!this.layoutEngine) { | ||
return [2 /*return*/]; | ||
} | ||
if (!!this.needsServerLayout) return [3 /*break*/, 2]; | ||
newRoot = model_utils_1.cloneModel(this.state.currentRoot); | ||
return [4 /*yield*/, this.layoutEngine.layout(newRoot)]; | ||
case 1: | ||
newRoot = _a.sent(); | ||
newRoot.revision = ++this.state.revision; | ||
this.state.currentRoot = newRoot; | ||
_a.label = 2; | ||
case 2: return [4 /*yield*/, this.doSubmitModel(this.state.currentRoot, true, action)]; | ||
case 3: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
@@ -359,0 +376,0 @@ return DiagramServer; |
@@ -18,2 +18,3 @@ /******************************************************************************** | ||
export * from './diagram-server'; | ||
export * from './diagram-services'; | ||
export * from './model'; | ||
@@ -20,0 +21,0 @@ export * from './utils/async'; |
{ | ||
"name": "sprotty-protocol", | ||
"version": "0.11.0-next.ddf634c", | ||
"version": "0.11.0", | ||
"description": "TypeScript declarations for Sprotty to be used both in browser and Node.js context", | ||
@@ -5,0 +5,0 @@ "license": "(EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0)", |
@@ -48,3 +48,3 @@ /******************************************************************************** | ||
}, { | ||
diagramGenerator: { | ||
DiagramGenerator: { | ||
generate: () => { | ||
@@ -57,3 +57,3 @@ return { | ||
}, | ||
layoutEngine: { | ||
ModelLayoutEngine: { | ||
layout: model => { | ||
@@ -60,0 +60,0 @@ (model as SModelRoot & BoundsAware).position = { x: 10, y: 10 }; |
@@ -21,6 +21,6 @@ /******************************************************************************** | ||
} from './actions'; | ||
import { DiagramServices, DiagramState, IDiagramGenerator, IModelLayoutEngine } from './diagram-services'; | ||
import { SModelRoot } from './model'; | ||
import { Deferred } from './utils/async'; | ||
import { JsonMap } from './utils/json'; | ||
import { applyBounds, cloneModel, SModelIndex } from './utils/model-utils'; | ||
import { applyBounds, cloneModel } from './utils/model-utils'; | ||
@@ -33,3 +33,3 @@ /** | ||
protected readonly state: DiagramState & { | ||
readonly state: DiagramState & { | ||
lastSubmittedModelType?: string | ||
@@ -43,6 +43,8 @@ } = { | ||
}; | ||
readonly dispatch: <A extends Action>(action: A) => Promise<void>; | ||
protected readonly diagramGenerator: IDiagramGenerator; | ||
protected readonly layoutEngine?: IModelLayoutEngine; | ||
protected readonly requests = new Map<string, Deferred<ResponseAction>>(); | ||
protected readonly handlers = new Map<string, ServerActionHandler[]>(); | ||
readonly dispatch: <A extends Action>(action: A) => Promise<void>; | ||
readonly services: DiagramServices; | ||
@@ -52,3 +54,4 @@ constructor(dispatch: <A extends Action>(action: A) => Promise<void>, | ||
this.dispatch = dispatch; | ||
this.services = services; | ||
this.diagramGenerator = services.DiagramGenerator; | ||
this.layoutEngine = services.ModelLayoutEngine; | ||
} | ||
@@ -208,3 +211,3 @@ | ||
try { | ||
const newRoot = await this.services.diagramGenerator.generate({ | ||
const newRoot = await this.diagramGenerator.generate({ | ||
options: this.state.options ?? {}, | ||
@@ -250,4 +253,4 @@ state: this.state | ||
} | ||
if (this.needsServerLayout) { | ||
newRoot = await this.services.layoutEngine.layout(newRoot); | ||
if (this.needsServerLayout && this.layoutEngine) { | ||
newRoot = await this.layoutEngine.layout(newRoot); | ||
} | ||
@@ -275,10 +278,13 @@ const modelType = newRoot.type; | ||
protected handleLayout(action: LayoutAction): Promise<void> { | ||
protected async handleLayout(action: LayoutAction): Promise<void> { | ||
if (!this.layoutEngine) { | ||
return; | ||
} | ||
if (!this.needsServerLayout) { | ||
return Promise.resolve(); | ||
let newRoot = cloneModel(this.state.currentRoot); | ||
newRoot = await this.layoutEngine.layout(newRoot); | ||
newRoot.revision = ++this.state.revision; | ||
this.state.currentRoot = newRoot; | ||
} | ||
const newRoot = cloneModel(this.state.currentRoot); | ||
newRoot.revision = ++this.state.revision; | ||
this.state.currentRoot = newRoot; | ||
return this.doSubmitModel(newRoot, true, action); | ||
await this.doSubmitModel(this.state.currentRoot, true, action); | ||
} | ||
@@ -288,23 +294,2 @@ | ||
export type DiagramOptions = JsonMap; | ||
export interface IModelLayoutEngine { | ||
layout(model: SModelRoot, index?: SModelIndex): SModelRoot | Promise<SModelRoot>; | ||
} | ||
export interface IDiagramGenerator { | ||
generate(args: { options: DiagramOptions, state: DiagramState }): SModelRoot | Promise<SModelRoot> | ||
} | ||
export interface DiagramServices { | ||
readonly diagramGenerator: IDiagramGenerator | ||
readonly layoutEngine: IModelLayoutEngine; | ||
} | ||
export interface DiagramState { | ||
options?: DiagramOptions; | ||
currentRoot: SModelRoot; | ||
revision: number; | ||
} | ||
export type ServerActionHandler<A extends Action = Action> = (action: A, state: DiagramState, server: DiagramServer) => Promise<void>; |
@@ -19,2 +19,3 @@ /******************************************************************************** | ||
export * from './diagram-server'; | ||
export * from './diagram-services'; | ||
export * from './model'; | ||
@@ -21,0 +22,0 @@ export * from './utils/async'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 15 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
225412
55
4136
19
60