@eclipse-glsp/protocol
Advanced tools
Comparing version 0.9.0 to 0.10.0-next.5043408.167
@@ -0,80 +1,173 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
import { JsonPrimitive } from 'sprotty-protocol'; | ||
import * as sprotty from 'sprotty-protocol/lib/actions'; | ||
import { TypeGuard } from '../utils/type-util'; | ||
/** | ||
* A general message serves as an envelope carrying an action to be transmitted between the client and the server via a DiagramServer. | ||
* An action is a declarative description of a behavior that shall be invoked by the receiver upon receipt of the action. | ||
* It is a plain data structure, and as such transferable between server and client. An action must never contain actual | ||
* SModelElement instances, but either refer to them via their ids or contain serializable schema for model elements. | ||
* Additional typeguard functions are provided via the corresponding namespace. | ||
*/ | ||
export interface ActionMessage<A extends Action = Action> { | ||
export interface Action extends sprotty.Action { | ||
/** | ||
* Used to identify a specific client session. | ||
* Unique identifier specifying the kind of action to process. | ||
*/ | ||
clientId: string; | ||
kind: string; | ||
} | ||
export declare namespace Action { | ||
function is(object: any): object is Action; | ||
/** | ||
* The action to execute. | ||
* Typeguard function to check wether the given object is an {@link Action} with the given `kind`. | ||
* @param object The object to check. | ||
* @param kind The expected action kind. | ||
* @returns A type literal indicating wether the given object is an action with the given kind. | ||
*/ | ||
action: A; | ||
function hasKind(object: any, kind: string): object is Action; | ||
} | ||
export declare function isActionMessage(object: any): object is ActionMessage; | ||
export declare function isActionMessageOfType<A extends Action>(object: any, guard: (action: any) => action is A): object is ActionMessage<A>; | ||
/** | ||
* An action is a declarative description of a behavior that shall be invoked by the receiver upon receipt of the action. | ||
* It is a plain data structure, and as such transferable between server and client. An action must never contain actual | ||
* SModelElement instances, but either refer to them via their ids or contain serializable schema for model elements. | ||
* A general message serves as an envelope carrying an action to be transmitted between the client and the server via a DiagramServer. | ||
* @typeParam A the {@link Action} type that is contained by this message. | ||
* A typeguard function is provided via the corresponding namespace. | ||
*/ | ||
export interface Action { | ||
export interface ActionMessage<A extends Action = Action> extends sprotty.ActionMessage { | ||
/** | ||
* Unique identifier specifying the kind of action to process. | ||
* The unique client id | ||
* */ | ||
clientId: string; | ||
/** | ||
* The action to execute. | ||
*/ | ||
readonly kind: string; | ||
action: A; | ||
} | ||
export declare function isAction(action: any): action is Action; | ||
export declare function isActionKind(action: any, kind: string): action is Action; | ||
export declare namespace ActionMessage { | ||
function is<A extends Action>(object: any, typeguard?: TypeGuard<A>): object is ActionMessage<A>; | ||
} | ||
/** | ||
* A request action is tied to the expectation of receiving a corresponding response action. The requestId property is used to match the | ||
* received response with the original request. | ||
* received response with the original request. Typically its not necessary to create an explicit requestId. The requestId can be set | ||
* to an empty string. The action dispatcher than auto generates an request id if needed (i.e. the action was dispatched as request). | ||
* | ||
* A typeguard function, and a generic helper function to generate a request id are provided via the corresponding namespace. | ||
*/ | ||
export interface RequestAction<Res extends ResponseAction> extends Action { | ||
export interface RequestAction<Res extends ResponseAction> extends Action, sprotty.RequestAction<Res> { | ||
/** | ||
* Unique id for this request. In order to match a response to this request, the response needs to have the same id. | ||
*/ | ||
readonly requestId: string; | ||
requestId: string; | ||
} | ||
export declare function isRequestAction(action?: any): action is RequestAction<ResponseAction>; | ||
export declare function generateRequestId(): string; | ||
export declare namespace RequestAction { | ||
function is(object: any): object is RequestAction<ResponseAction>; | ||
/** | ||
* Typeguard function to check wether the given object is an {@link RequestAction} with the given `kind`. | ||
* @param object The object to check. | ||
* @param kind The expected action kind. | ||
* @returns A type literal indicating wether the given object is a request action with the given kind. | ||
*/ | ||
function hasKind(object: any, kind: string): object is Action; | ||
function generateRequestId(): string; | ||
} | ||
/** | ||
* A response action is sent to respond to a request action. The responseId must match the requestId of the preceding request. | ||
* In case the responseId is empty or undefined, the action is handled as standalone, i.e. it was fired without a preceding request. | ||
* In case the responseId is empty, the action is handled as standalone, i.e. it was fired without a preceding request. | ||
* The action dispatcher of the GLSP server has a special handling for {@link RequestAction} handlers | ||
* and automatically sets the `responseId` of the corresponding responseAction. So on the server side its typically enough | ||
* to set the `responseId` to an empty string and rely on the `ActionDispatcher` for assigning the correct `responseId. | ||
* Additional typeguard functions are provided via the corresponding namespace. | ||
*/ | ||
export interface ResponseAction extends Action { | ||
export interface ResponseAction extends Action, sprotty.ResponseAction { | ||
/** | ||
* Id corresponding to the request this action responds to. | ||
*/ | ||
readonly responseId: string; | ||
responseId: string; | ||
} | ||
export declare function isResponseAction(action?: any): action is ResponseAction; | ||
export declare namespace ResponseAction { | ||
function is(object: any): object is ResponseAction; | ||
/** | ||
* Typeguard function to check wether the given object is an {@link ResponseAction} with a non-empty response id. | ||
* @param object The object to check. | ||
* @returns A type literal indicating wether the given object is a response action with a non-empty response id. | ||
*/ | ||
function hasValidResponseId(object: any): object is ResponseAction; | ||
} | ||
/** | ||
* A reject action is a response fired to indicate that a request must be rejected. | ||
* A reject action is a {@link ResponseAction} fired to indicate that a certain {@link ResponseAction} | ||
* has been rejected. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `RejectActions`. | ||
*/ | ||
export declare class RejectAction implements ResponseAction { | ||
readonly message: string; | ||
readonly responseId: string; | ||
readonly detail?: string | number | boolean | import("./types").Args | import("./types").JsonArray | null | undefined; | ||
static readonly KIND = "rejectRequest"; | ||
readonly kind = "rejectRequest"; | ||
constructor(message: string, responseId: string, detail?: string | number | boolean | import("./types").Args | import("./types").JsonArray | null | undefined); | ||
export interface RejectAction extends ResponseAction, sprotty.RejectAction { | ||
kind: typeof RejectAction.KIND; | ||
/** | ||
* A human-readable description of the reject reason. Typically this is an error message | ||
* that has been thrown when handling the corresponding {@link RequestAction}. | ||
*/ | ||
message: string; | ||
/** | ||
* Optional additional details. | ||
*/ | ||
detail?: JsonPrimitive; | ||
} | ||
export declare function isRejectAction(action: any): action is RejectAction; | ||
export declare namespace RejectAction { | ||
const KIND = "rejectRequest"; | ||
function is(object: any): object is RejectAction; | ||
function create(message: string, options?: { | ||
detail?: JsonPrimitive; | ||
responseId?: string; | ||
}): RejectAction; | ||
} | ||
/** | ||
* Operations are actions that denote requests from the client to _modify_ the model. Model modifications are always performed by the | ||
* server. After a successful modification, the server sends the updated model back to the client using the `UpdateModelAction`. | ||
* An operation contains a dedicated `isOperation` property that is used as a discriminator. This is necessary so that the server | ||
* can distinguish between plain actions and operations. | ||
* The corresponding namespace offers a helper function for type guard checks. | ||
*/ | ||
export interface Operation extends Action { | ||
/** | ||
* Discriminator property to make operations distinguishable from plain {@link Action}s. | ||
*/ | ||
isOperation: true; | ||
} | ||
export declare namespace Operation { | ||
function is(object: any): object is Operation; | ||
/** | ||
* Typeguard function to check wether the given object is an {@link Operation} with the given `kind`. | ||
* @param object The object to check. | ||
* @param kind The expected operation kind. | ||
* @returns A type literal indicating wether the given object is an operation with the given kind. | ||
*/ | ||
function hasKind(object: any, kind: string): object is Operation; | ||
} | ||
/** | ||
* An operation that executes a list of sub-operations. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `CompoundOperations`. | ||
*/ | ||
export declare class CompoundOperation implements Operation { | ||
export interface CompoundOperation extends Operation { | ||
kind: typeof CompoundOperation.KIND; | ||
/** | ||
* List of operations that should be executed. | ||
*/ | ||
operationList: Operation[]; | ||
readonly kind: string; | ||
static readonly KIND = "compound"; | ||
constructor(operationList: Operation[], kind?: string); | ||
} | ||
export declare function isCompoundOperation(operation?: any): operation is CompoundOperation; | ||
export declare namespace CompoundOperation { | ||
const KIND = "compound"; | ||
function is(object: any): object is CompoundOperation; | ||
function create(operationList: Operation[]): CompoundOperation; | ||
} | ||
//# sourceMappingURL=base-protocol.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isCompoundOperation = exports.CompoundOperation = exports.isRejectAction = exports.RejectAction = exports.isResponseAction = exports.generateRequestId = exports.isRequestAction = exports.isActionKind = exports.isAction = exports.isActionMessageOfType = exports.isActionMessage = void 0; | ||
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
const uuid = require("uuid"); | ||
const typeguard_util_1 = require("../utils/typeguard-util"); | ||
function isActionMessage(object) { | ||
return object !== undefined && typeguard_util_1.isString(object, 'clientId') && isAction(object['action']); | ||
} | ||
exports.isActionMessage = isActionMessage; | ||
function isActionMessageOfType(object, guard) { | ||
return isActionMessage(object) && guard(object.action); | ||
} | ||
exports.isActionMessageOfType = isActionMessageOfType; | ||
function isAction(action) { | ||
return action !== undefined && typeguard_util_1.isString(action, 'kind'); | ||
} | ||
exports.isAction = isAction; | ||
function isActionKind(action, kind) { | ||
return isAction(action) && action.kind === kind; | ||
} | ||
exports.isActionKind = isActionKind; | ||
function isRequestAction(action) { | ||
return isAction(action) && typeguard_util_1.isString(action, 'requestId'); | ||
} | ||
exports.isRequestAction = isRequestAction; | ||
function generateRequestId() { | ||
return uuid.v4(); | ||
} | ||
exports.generateRequestId = generateRequestId; | ||
function isResponseAction(action) { | ||
return isAction(action) && 'responseId' in action && typeof action['responseId'] === 'string' && action['responseId'] !== ''; | ||
} | ||
exports.isResponseAction = isResponseAction; | ||
/** | ||
* A reject action is a response fired to indicate that a request must be rejected. | ||
*/ | ||
class RejectAction { | ||
constructor(message, responseId, detail) { | ||
this.message = message; | ||
this.responseId = responseId; | ||
this.detail = detail; | ||
this.kind = RejectAction.KIND; | ||
exports.CompoundOperation = exports.Operation = exports.RejectAction = exports.ResponseAction = exports.RequestAction = exports.ActionMessage = exports.Action = void 0; | ||
const sprotty = require("sprotty-protocol/lib/actions"); | ||
const type_util_1 = require("../utils/type-util"); | ||
var Action; | ||
(function (Action) { | ||
function is(object) { | ||
return type_util_1.AnyObject.is(object) && (0, type_util_1.hasStringProp)(object, 'kind'); | ||
} | ||
} | ||
exports.RejectAction = RejectAction; | ||
RejectAction.KIND = 'rejectRequest'; | ||
function isRejectAction(action) { | ||
return isResponseAction(action) && action.kind === RejectAction.KIND && typeguard_util_1.isString(action, 'message'); | ||
} | ||
exports.isRejectAction = isRejectAction; | ||
/** | ||
* An operation that executes a list of sub-operations. | ||
*/ | ||
class CompoundOperation { | ||
constructor(operationList, kind = CompoundOperation.KIND) { | ||
this.operationList = operationList; | ||
this.kind = kind; | ||
Action.is = is; | ||
/** | ||
* Typeguard function to check wether the given object is an {@link Action} with the given `kind`. | ||
* @param object The object to check. | ||
* @param kind The expected action kind. | ||
* @returns A type literal indicating wether the given object is an action with the given kind. | ||
*/ | ||
function hasKind(object, kind) { | ||
return Action.is(object) && object.kind === kind; | ||
} | ||
} | ||
exports.CompoundOperation = CompoundOperation; | ||
CompoundOperation.KIND = 'compound'; | ||
function isCompoundOperation(operation) { | ||
return isActionKind(operation, CompoundOperation.KIND) && typeguard_util_1.isArray(operation, 'operationList'); | ||
} | ||
exports.isCompoundOperation = isCompoundOperation; | ||
Action.hasKind = hasKind; | ||
})(Action = exports.Action || (exports.Action = {})); | ||
var ActionMessage; | ||
(function (ActionMessage) { | ||
function is(object, typeguard) { | ||
const actionGuard = typeguard !== null && typeguard !== void 0 ? typeguard : Action.is; | ||
return type_util_1.AnyObject.is(object) && (0, type_util_1.hasStringProp)(object, 'clientId') && actionGuard(object.action); | ||
} | ||
ActionMessage.is = is; | ||
})(ActionMessage = exports.ActionMessage || (exports.ActionMessage = {})); | ||
var RequestAction; | ||
(function (RequestAction) { | ||
function is(object) { | ||
return Action.is(object) && (0, type_util_1.hasStringProp)(object, 'requestId'); | ||
} | ||
RequestAction.is = is; | ||
/** | ||
* Typeguard function to check wether the given object is an {@link RequestAction} with the given `kind`. | ||
* @param object The object to check. | ||
* @param kind The expected action kind. | ||
* @returns A type literal indicating wether the given object is a request action with the given kind. | ||
*/ | ||
function hasKind(object, kind) { | ||
return RequestAction.is(object) && object.kind === kind; | ||
} | ||
RequestAction.hasKind = hasKind; | ||
function generateRequestId() { | ||
return sprotty.generateRequestId(); | ||
} | ||
RequestAction.generateRequestId = generateRequestId; | ||
})(RequestAction = exports.RequestAction || (exports.RequestAction = {})); | ||
var ResponseAction; | ||
(function (ResponseAction) { | ||
function is(object) { | ||
return Action.is(object) && (0, type_util_1.hasStringProp)(object, 'responseId'); | ||
} | ||
ResponseAction.is = is; | ||
/** | ||
* Typeguard function to check wether the given object is an {@link ResponseAction} with a non-empty response id. | ||
* @param object The object to check. | ||
* @returns A type literal indicating wether the given object is a response action with a non-empty response id. | ||
*/ | ||
function hasValidResponseId(object) { | ||
return ResponseAction.is(object) && object.responseId !== ''; | ||
} | ||
ResponseAction.hasValidResponseId = hasValidResponseId; | ||
})(ResponseAction = exports.ResponseAction || (exports.ResponseAction = {})); | ||
var RejectAction; | ||
(function (RejectAction) { | ||
RejectAction.KIND = 'rejectRequest'; | ||
function is(object) { | ||
return Action.hasKind(object, RejectAction.KIND) && (0, type_util_1.hasStringProp)(object, 'message'); | ||
} | ||
RejectAction.is = is; | ||
function create(message, options = {}) { | ||
return Object.assign({ kind: RejectAction.KIND, responseId: '', message }, options); | ||
} | ||
RejectAction.create = create; | ||
})(RejectAction = exports.RejectAction || (exports.RejectAction = {})); | ||
var Operation; | ||
(function (Operation) { | ||
function is(object) { | ||
return Action.is(object) && object.isOperation === true; | ||
} | ||
Operation.is = is; | ||
/** | ||
* Typeguard function to check wether the given object is an {@link Operation} with the given `kind`. | ||
* @param object The object to check. | ||
* @param kind The expected operation kind. | ||
* @returns A type literal indicating wether the given object is an operation with the given kind. | ||
*/ | ||
function hasKind(object, kind) { | ||
return Operation.is(object) && object.kind === kind; | ||
} | ||
Operation.hasKind = hasKind; | ||
})(Operation = exports.Operation || (exports.Operation = {})); | ||
var CompoundOperation; | ||
(function (CompoundOperation) { | ||
CompoundOperation.KIND = 'compound'; | ||
function is(object) { | ||
return Operation.hasKind(object, CompoundOperation.KIND) && (0, type_util_1.hasArrayProp)(object, 'operationList'); | ||
} | ||
CompoundOperation.is = is; | ||
function create(operationList) { | ||
return { | ||
kind: CompoundOperation.KIND, | ||
isOperation: true, | ||
operationList | ||
}; | ||
} | ||
CompoundOperation.create = create; | ||
})(CompoundOperation = exports.CompoundOperation || (exports.CompoundOperation = {})); | ||
//# sourceMappingURL=base-protocol.js.map |
import { Action } from './base-protocol'; | ||
export declare type ServerSeverity = 'NONE' | 'INFO' | 'WARNING' | 'ERROR' | 'FATAL' | 'OK'; | ||
/** | ||
* This action is typically sent by the server to signal a state change. This action extends the corresponding Sprotty action to include | ||
* a timeout. If a timeout is given the respective status should disappear after the timeout is reached. | ||
* Sent by the server to signal a state change. | ||
* If a timeout is given the respective status should disappear after the timeout is reached. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `ServerStatusActions`. | ||
*/ | ||
export declare class GLSPServerStatusAction implements Action { | ||
export interface ServerStatusAction extends Action { | ||
kind: typeof ServerStatusAction.KIND; | ||
/** | ||
* The severity of the status. | ||
*/ | ||
severity: ServerSeverity; | ||
/** | ||
* The user-facing message describing the status. | ||
*/ | ||
message: string; | ||
timeout: number; | ||
readonly kind: string; | ||
static KIND: string; | ||
constructor(severity: ServerSeverity, message: string, timeout?: number, kind?: string); | ||
/** | ||
* Timeout after which a displayed status should disappear. | ||
*/ | ||
timeout?: number; | ||
} | ||
export declare function isGLSPServerStatusAction(action: any): action is GLSPServerStatusAction; | ||
export declare namespace ServerStatusAction { | ||
const KIND = "serverStatus"; | ||
function is(object: any): object is ServerStatusAction; | ||
function create(message: string, options?: { | ||
severity?: ServerSeverity; | ||
timeout?: number; | ||
}): ServerStatusAction; | ||
} | ||
/** | ||
* This action is typically sent by the server to notify the user about something of interest. | ||
* The possible server status severity levels. | ||
*/ | ||
export declare class ServerMessageAction implements Action { | ||
export declare type ServerSeverity = 'NONE' | 'INFO' | 'WARNING' | 'ERROR' | 'FATAL' | 'OK'; | ||
/** | ||
* Sent by the server to notify the user about something of interest. Typically this message is handled by | ||
* the client by showing a message to the user with the application's message service. | ||
* If a timeout is given the respective message should disappear after the timeout is reached. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `ServerMessageActions`. | ||
*/ | ||
export interface ServerMessageAction extends Action { | ||
kind: typeof ServerMessageAction.KIND; | ||
severity: ServerSeverity; | ||
/** | ||
* The message that shall be shown to the user. | ||
*/ | ||
message: string; | ||
details?: string | undefined; | ||
timeout: number; | ||
readonly kind: string; | ||
static KIND: string; | ||
constructor(severity: ServerSeverity, message: string, details?: string | undefined, timeout?: number, kind?: string); | ||
/** | ||
* Further details on the message. | ||
*/ | ||
details?: string; | ||
/** | ||
* Timeout after which a displayed message disappears. | ||
*/ | ||
timeout?: number; | ||
} | ||
export declare function isServerMessageAction(action?: any): action is ServerMessageAction; | ||
export declare namespace ServerMessageAction { | ||
const KIND = "serverMessage"; | ||
function is(object: any): object is ServerMessageAction; | ||
function create(message: string, options?: { | ||
severity?: ServerSeverity; | ||
details?: string; | ||
timeout?: number; | ||
}): ServerMessageAction; | ||
} | ||
//# sourceMappingURL=client-notification.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isServerMessageAction = exports.ServerMessageAction = exports.isGLSPServerStatusAction = exports.GLSPServerStatusAction = void 0; | ||
exports.ServerMessageAction = exports.ServerStatusAction = void 0; | ||
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -19,46 +19,28 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
const typeguard_util_1 = require("../utils/typeguard-util"); | ||
const type_util_1 = require("../utils/type-util"); | ||
const base_protocol_1 = require("./base-protocol"); | ||
/** | ||
* This action is typically sent by the server to signal a state change. This action extends the corresponding Sprotty action to include | ||
* a timeout. If a timeout is given the respective status should disappear after the timeout is reached. | ||
*/ | ||
class GLSPServerStatusAction { | ||
constructor(severity, message, timeout = -1, kind = GLSPServerStatusAction.KIND) { | ||
this.severity = severity; | ||
this.message = message; | ||
this.timeout = timeout; | ||
this.kind = kind; | ||
var ServerStatusAction; | ||
(function (ServerStatusAction) { | ||
ServerStatusAction.KIND = 'serverStatus'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, ServerStatusAction.KIND) && (0, type_util_1.hasStringProp)(object, 'severity') && (0, type_util_1.hasStringProp)(object, 'message'); | ||
} | ||
} | ||
exports.GLSPServerStatusAction = GLSPServerStatusAction; | ||
GLSPServerStatusAction.KIND = 'serverStatus'; | ||
function isGLSPServerStatusAction(action) { | ||
return (base_protocol_1.isActionKind(action, GLSPServerStatusAction.KIND) && | ||
typeguard_util_1.isString(action, 'severity') && | ||
typeguard_util_1.isString(action, 'message') && | ||
typeguard_util_1.isNumber(action, 'timeout')); | ||
} | ||
exports.isGLSPServerStatusAction = isGLSPServerStatusAction; | ||
/** | ||
* This action is typically sent by the server to notify the user about something of interest. | ||
*/ | ||
class ServerMessageAction { | ||
constructor(severity, message, details, timeout = -1, kind = ServerMessageAction.KIND) { | ||
this.severity = severity; | ||
this.message = message; | ||
this.details = details; | ||
this.timeout = timeout; | ||
this.kind = kind; | ||
ServerStatusAction.is = is; | ||
function create(message, options = {}) { | ||
return Object.assign({ kind: ServerStatusAction.KIND, severity: 'INFO', message }, options); | ||
} | ||
} | ||
exports.ServerMessageAction = ServerMessageAction; | ||
ServerMessageAction.KIND = 'serverMessage'; | ||
function isServerMessageAction(action) { | ||
return (base_protocol_1.isActionKind(action, ServerMessageAction.KIND) && | ||
typeguard_util_1.isString(action, 'severity') && | ||
typeguard_util_1.isString(action, 'message') && | ||
typeguard_util_1.isNumber(action, 'timeout')); | ||
} | ||
exports.isServerMessageAction = isServerMessageAction; | ||
ServerStatusAction.create = create; | ||
})(ServerStatusAction = exports.ServerStatusAction || (exports.ServerStatusAction = {})); | ||
var ServerMessageAction; | ||
(function (ServerMessageAction) { | ||
ServerMessageAction.KIND = 'serverMessage'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, ServerMessageAction.KIND) && (0, type_util_1.hasStringProp)(object, 'message') && (0, type_util_1.hasStringProp)(object, 'severity'); | ||
} | ||
ServerMessageAction.is = is; | ||
function create(message, options = {}) { | ||
return Object.assign({ kind: ServerMessageAction.KIND, message, severity: 'INFO' }, options); | ||
} | ||
ServerMessageAction.create = create; | ||
})(ServerMessageAction = exports.ServerMessageAction || (exports.ServerMessageAction = {})); | ||
//# sourceMappingURL=client-notification.js.map |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -20,46 +20,76 @@ * This program and the accompanying materials are made available under the | ||
* Requests the clipboard data for the current editor context, i.e., the selected elements, in a clipboard-compatible format. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `RequestClipboardDataActions`. | ||
*/ | ||
export declare class RequestClipboardDataAction implements RequestAction<SetClipboardDataAction> { | ||
readonly editorContext: EditorContext; | ||
readonly requestId: string; | ||
readonly kind: string; | ||
static readonly KIND = "requestClipboardData"; | ||
constructor(editorContext: EditorContext, requestId?: string, kind?: string); | ||
static create(editorContext: EditorContext): RequestAction<SetClipboardDataAction>; | ||
export interface RequestClipboardDataAction extends RequestAction<SetClipboardDataAction> { | ||
kind: typeof RequestClipboardDataAction.KIND; | ||
editorContext: EditorContext; | ||
} | ||
export declare function isRequestClipboardDataAction(action: any): action is RequestClipboardDataAction; | ||
export declare namespace RequestClipboardDataAction { | ||
const KIND = "requestClipboardData"; | ||
function is(object: any): object is RequestClipboardDataAction; | ||
function create(editorContext: EditorContext, options?: { | ||
requestId?: string; | ||
}): RequestClipboardDataAction; | ||
} | ||
/** | ||
* Server response to a {@link RequestClipboardDataAction} containing the selected elements as clipboard-compatible format. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetClipboardDataActions`. | ||
*/ | ||
export declare class SetClipboardDataAction implements ResponseAction { | ||
readonly clipboardData: ClipboardData; | ||
readonly responseId: string; | ||
readonly kind: string; | ||
static readonly KIND = "setClipboardData"; | ||
constructor(clipboardData: ClipboardData, responseId?: string, kind?: string); | ||
export interface SetClipboardDataAction extends ResponseAction { | ||
kind: typeof SetClipboardDataAction.KIND; | ||
/** | ||
* The data to be added into the clipboard. This data will be sent back to the server on paste. | ||
*/ | ||
clipboardData: ClipboardData; | ||
} | ||
export declare function isSetClipboardDataAction(action: any): action is SetClipboardDataAction; | ||
export declare namespace SetClipboardDataAction { | ||
const KIND = "setClipboardData"; | ||
function is(object: any): object is SetClipboardDataAction; | ||
function create(clipboardData: ClipboardData, options?: { | ||
responseId?: string; | ||
}): SetClipboardDataAction; | ||
} | ||
/** | ||
* Requests a cut operation from the server, i.e., deleting the selected elements from the model. Before submitting a `CutOperation` | ||
* a client should ensure that the cut elements are put into the clipboard. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `CutOperations`. | ||
*/ | ||
export declare class CutOperation implements Operation { | ||
readonly editorContext: EditorContext; | ||
readonly kind: string; | ||
static readonly KIND = "cut"; | ||
constructor(editorContext: EditorContext, kind?: string); | ||
export interface CutOperation extends Operation { | ||
kind: typeof CutOperation.KIND; | ||
editorContext: EditorContext; | ||
} | ||
export declare function isCutOperation(action: any): action is CutOperation; | ||
export declare namespace CutOperation { | ||
const KIND = "cut"; | ||
function is(object: any): object is CutOperation; | ||
function create(editorContext: EditorContext): CutOperation; | ||
} | ||
/** | ||
* Requests a paste operation from the server by providing the current clipboard data. Typically this means that elements should be created | ||
* based on the data in the clipboard. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `PasteOperations`. | ||
*/ | ||
export declare class PasteOperation implements Operation { | ||
readonly clipboardData: ClipboardData; | ||
readonly editorContext: EditorContext; | ||
readonly kind: string; | ||
static readonly KIND = "paste"; | ||
constructor(clipboardData: ClipboardData, editorContext: EditorContext, kind?: string); | ||
export interface PasteOperation extends Operation { | ||
kind: typeof PasteOperation.KIND; | ||
editorContext: EditorContext; | ||
/** | ||
* The clipboard data that should be pasted to the editor's last recorded mouse position (see `editorContext`). | ||
*/ | ||
clipboardData: ClipboardData; | ||
} | ||
export declare function isPasteOperation(action: any): action is PasteOperation; | ||
export declare namespace PasteOperation { | ||
const KIND = "paste"; | ||
function is(object: any): object is PasteOperation; | ||
function create(options: { | ||
editorContext: EditorContext; | ||
clipboardData: ClipboardData; | ||
}): PasteOperation; | ||
} | ||
/** | ||
* In GLSP the clipboard needs to be managed by the client but the conversion from the selection to be copied into a | ||
* clipboard-compatible format is handled by the server. By default, GLSP use application/json as exchange format. | ||
*/ | ||
export interface ClipboardData { | ||
@@ -66,0 +96,0 @@ [format: string]: string; |
"use strict"; | ||
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -18,73 +18,57 @@ * This program and the accompanying materials are made available under the | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isPasteOperation = exports.PasteOperation = exports.isCutOperation = exports.CutOperation = exports.isSetClipboardDataAction = exports.SetClipboardDataAction = exports.isRequestClipboardDataAction = exports.RequestClipboardDataAction = void 0; | ||
const typeguard_util_1 = require("../utils/typeguard-util"); | ||
exports.PasteOperation = exports.CutOperation = exports.SetClipboardDataAction = exports.RequestClipboardDataAction = void 0; | ||
const type_util_1 = require("../utils/type-util"); | ||
const base_protocol_1 = require("./base-protocol"); | ||
/** | ||
* Requests the clipboard data for the current editor context, i.e., the selected elements, in a clipboard-compatible format. | ||
*/ | ||
class RequestClipboardDataAction { | ||
constructor(editorContext, requestId = base_protocol_1.generateRequestId(), kind = RequestClipboardDataAction.KIND) { | ||
this.editorContext = editorContext; | ||
this.requestId = requestId; | ||
this.kind = kind; | ||
var RequestClipboardDataAction; | ||
(function (RequestClipboardDataAction) { | ||
RequestClipboardDataAction.KIND = 'requestClipboardData'; | ||
function is(object) { | ||
return base_protocol_1.RequestAction.hasKind(object, RequestClipboardDataAction.KIND) && (0, type_util_1.hasObjectProp)(object, 'editorContext'); | ||
} | ||
static create(editorContext) { | ||
return new RequestClipboardDataAction(editorContext); | ||
RequestClipboardDataAction.is = is; | ||
function create(editorContext, options = {}) { | ||
return Object.assign({ kind: RequestClipboardDataAction.KIND, requestId: '', editorContext }, options); | ||
} | ||
} | ||
exports.RequestClipboardDataAction = RequestClipboardDataAction; | ||
RequestClipboardDataAction.KIND = 'requestClipboardData'; | ||
function isRequestClipboardDataAction(action) { | ||
return base_protocol_1.isActionKind(action, RequestClipboardDataAction.KIND) && typeguard_util_1.isObject(action, 'editorContext') && typeguard_util_1.isString(action, 'requestId'); | ||
} | ||
exports.isRequestClipboardDataAction = isRequestClipboardDataAction; | ||
/** | ||
* Server response to a {@link RequestClipboardDataAction} containing the selected elements as clipboard-compatible format. | ||
*/ | ||
class SetClipboardDataAction { | ||
constructor(clipboardData, responseId = '', kind = SetClipboardDataAction.KIND) { | ||
this.clipboardData = clipboardData; | ||
this.responseId = responseId; | ||
this.kind = kind; | ||
RequestClipboardDataAction.create = create; | ||
})(RequestClipboardDataAction = exports.RequestClipboardDataAction || (exports.RequestClipboardDataAction = {})); | ||
var SetClipboardDataAction; | ||
(function (SetClipboardDataAction) { | ||
SetClipboardDataAction.KIND = 'setClipboardData'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, SetClipboardDataAction.KIND) && (0, type_util_1.hasObjectProp)(object, 'clipboardData'); | ||
} | ||
} | ||
exports.SetClipboardDataAction = SetClipboardDataAction; | ||
SetClipboardDataAction.KIND = 'setClipboardData'; | ||
function isSetClipboardDataAction(action) { | ||
return base_protocol_1.isActionKind(action, SetClipboardDataAction.KIND) && typeguard_util_1.isObject(action, 'clipboardData') && typeguard_util_1.isString(action, 'responseId'); | ||
} | ||
exports.isSetClipboardDataAction = isSetClipboardDataAction; | ||
/** | ||
* Requests a cut operation from the server, i.e., deleting the selected elements from the model. Before submitting a `CutOperation` | ||
* a client should ensure that the cut elements are put into the clipboard. | ||
*/ | ||
class CutOperation { | ||
constructor(editorContext, kind = CutOperation.KIND) { | ||
this.editorContext = editorContext; | ||
this.kind = kind; | ||
SetClipboardDataAction.is = is; | ||
function create(clipboardData, options = {}) { | ||
return Object.assign({ kind: SetClipboardDataAction.KIND, responseId: '', clipboardData }, options); | ||
} | ||
} | ||
exports.CutOperation = CutOperation; | ||
CutOperation.KIND = 'cut'; | ||
function isCutOperation(action) { | ||
return base_protocol_1.isActionKind(action, CutOperation.KIND) && typeguard_util_1.isObject(action, 'editorContext'); | ||
} | ||
exports.isCutOperation = isCutOperation; | ||
/** | ||
* Requests a paste operation from the server by providing the current clipboard data. Typically this means that elements should be created | ||
* based on the data in the clipboard. | ||
*/ | ||
class PasteOperation { | ||
constructor(clipboardData, editorContext, kind = PasteOperation.KIND) { | ||
this.clipboardData = clipboardData; | ||
this.editorContext = editorContext; | ||
this.kind = kind; | ||
SetClipboardDataAction.create = create; | ||
})(SetClipboardDataAction = exports.SetClipboardDataAction || (exports.SetClipboardDataAction = {})); | ||
var CutOperation; | ||
(function (CutOperation) { | ||
CutOperation.KIND = 'cut'; | ||
function is(object) { | ||
return base_protocol_1.Operation.hasKind(object, CutOperation.KIND) && (0, type_util_1.hasObjectProp)(object, 'editorContext'); | ||
} | ||
} | ||
exports.PasteOperation = PasteOperation; | ||
PasteOperation.KIND = 'paste'; | ||
function isPasteOperation(action) { | ||
return base_protocol_1.isActionKind(action, PasteOperation.KIND) && typeguard_util_1.isObject(action, 'clipboardData') && typeguard_util_1.isObject(action, 'editorContext'); | ||
} | ||
exports.isPasteOperation = isPasteOperation; | ||
CutOperation.is = is; | ||
function create(editorContext) { | ||
return { | ||
kind: CutOperation.KIND, | ||
isOperation: true, | ||
editorContext | ||
}; | ||
} | ||
CutOperation.create = create; | ||
})(CutOperation = exports.CutOperation || (exports.CutOperation = {})); | ||
var PasteOperation; | ||
(function (PasteOperation) { | ||
PasteOperation.KIND = 'paste'; | ||
function is(object) { | ||
return base_protocol_1.Operation.hasKind(object, PasteOperation.KIND) && (0, type_util_1.hasObjectProp)(object, 'clipboardData') && (0, type_util_1.hasObjectProp)(object, 'editorContext'); | ||
} | ||
PasteOperation.is = is; | ||
function create(options) { | ||
return Object.assign({ kind: PasteOperation.KIND, isOperation: true }, options); | ||
} | ||
PasteOperation.create = create; | ||
})(PasteOperation = exports.PasteOperation || (exports.PasteOperation = {})); | ||
//# sourceMappingURL=clipboard.js.map |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -20,24 +20,46 @@ * This program and the accompanying materials are made available under the | ||
* The `RequestContextActions` is sent from the client to the server to request the available actions for the context with id contextId. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `RequestContextActions`. | ||
*/ | ||
export declare class RequestContextActions implements RequestAction<SetContextActions> { | ||
readonly contextId: string; | ||
readonly editorContext: EditorContext; | ||
readonly requestId: string; | ||
readonly kind: string; | ||
static readonly KIND = "requestContextActions"; | ||
constructor(contextId: string, editorContext: EditorContext, requestId?: string, kind?: string); | ||
export interface RequestContextActions extends RequestAction<SetContextActions> { | ||
kind: typeof RequestContextActions.KIND; | ||
/** | ||
* The identifier for the context. | ||
*/ | ||
contextId: string; | ||
editorContext: EditorContext; | ||
} | ||
export declare function isRequestContextActions(action: any): action is RequestContextActions; | ||
export declare namespace RequestContextActions { | ||
const KIND = "requestContextActions"; | ||
function is(object: any): object is RequestContextActions; | ||
function create(options: { | ||
contextId: string; | ||
editorContext: EditorContext; | ||
requestId?: string; | ||
}): RequestContextActions; | ||
} | ||
/** | ||
* The `SetContextActions` is the response to a {@link RequestContextActions} containing all actions for the queried context. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetContextsActions`. | ||
*/ | ||
export declare class SetContextActions implements ResponseAction { | ||
export interface SetContextActions extends ResponseAction { | ||
kind: typeof SetContextActions.KIND; | ||
/** | ||
* The actions available in the queried context. | ||
*/ | ||
readonly actions: LabeledAction[]; | ||
readonly responseId: string; | ||
readonly args?: Args | undefined; | ||
readonly kind: string; | ||
static readonly KIND = "setContextActions"; | ||
constructor(actions: LabeledAction[], responseId?: string, args?: Args | undefined, kind?: string); | ||
/** | ||
* Custom arguments. | ||
*/ | ||
args?: Args; | ||
} | ||
export declare function isSetContextActionsAction(action: any): action is SetContextActions; | ||
export declare namespace SetContextActions { | ||
const KIND = "setContextActions"; | ||
function is(object: any): object is SetContextActions; | ||
function create(actions: LabeledAction[], options?: { | ||
args?: Args; | ||
responseId?: string; | ||
}): SetContextActions; | ||
} | ||
//# sourceMappingURL=contexts.d.ts.map |
"use strict"; | ||
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -18,42 +18,29 @@ * This program and the accompanying materials are made available under the | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isSetContextActionsAction = exports.SetContextActions = exports.isRequestContextActions = exports.RequestContextActions = void 0; | ||
const typeguard_util_1 = require("../utils/typeguard-util"); | ||
exports.SetContextActions = exports.RequestContextActions = void 0; | ||
const type_util_1 = require("../utils/type-util"); | ||
const base_protocol_1 = require("./base-protocol"); | ||
/** | ||
* The `RequestContextActions` is sent from the client to the server to request the available actions for the context with id contextId. | ||
*/ | ||
class RequestContextActions { | ||
constructor(contextId, editorContext, requestId = base_protocol_1.generateRequestId(), kind = RequestContextActions.KIND) { | ||
this.contextId = contextId; | ||
this.editorContext = editorContext; | ||
this.requestId = requestId; | ||
this.kind = kind; | ||
var RequestContextActions; | ||
(function (RequestContextActions) { | ||
RequestContextActions.KIND = 'requestContextActions'; | ||
function is(object) { | ||
return base_protocol_1.RequestAction.hasKind(object, RequestContextActions.KIND) && (0, type_util_1.hasStringProp)(object, 'contextId') && (0, type_util_1.hasObjectProp)(object, 'editorContext'); | ||
} | ||
} | ||
exports.RequestContextActions = RequestContextActions; | ||
RequestContextActions.KIND = 'requestContextActions'; | ||
function isRequestContextActions(action) { | ||
return (base_protocol_1.isActionKind(action, RequestContextActions.KIND) && | ||
typeguard_util_1.isString(action, 'contextId') && | ||
typeguard_util_1.isObject(action, 'editorContext') && | ||
typeguard_util_1.isString(action, 'requestId')); | ||
} | ||
exports.isRequestContextActions = isRequestContextActions; | ||
/** | ||
* The `SetContextActions` is the response to a {@link RequestContextActions} containing all actions for the queried context. | ||
*/ | ||
class SetContextActions { | ||
constructor(actions, responseId = '', args, kind = SetContextActions.KIND) { | ||
this.actions = actions; | ||
this.responseId = responseId; | ||
this.args = args; | ||
this.kind = kind; | ||
RequestContextActions.is = is; | ||
function create(options) { | ||
return Object.assign({ kind: RequestContextActions.KIND, requestId: '' }, options); | ||
} | ||
} | ||
exports.SetContextActions = SetContextActions; | ||
SetContextActions.KIND = 'setContextActions'; | ||
function isSetContextActionsAction(action) { | ||
return base_protocol_1.isActionKind(action, SetContextActions.KIND) && typeguard_util_1.isArray(action, 'actions') && typeguard_util_1.isString(action, 'responseId'); | ||
} | ||
exports.isSetContextActionsAction = isSetContextActionsAction; | ||
RequestContextActions.create = create; | ||
})(RequestContextActions = exports.RequestContextActions || (exports.RequestContextActions = {})); | ||
var SetContextActions; | ||
(function (SetContextActions) { | ||
SetContextActions.KIND = 'setContextActions'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, SetContextActions.KIND) && (0, type_util_1.hasArrayProp)(object, 'actions'); | ||
} | ||
SetContextActions.is = is; | ||
function create(actions, options = {}) { | ||
return Object.assign({ kind: SetContextActions.KIND, responseId: '', actions }, options); | ||
} | ||
SetContextActions.create = create; | ||
})(SetContextActions = exports.SetContextActions || (exports.SetContextActions = {})); | ||
//# sourceMappingURL=contexts.js.map |
/******************************************************************************** | ||
* Copyright (c) 2021 EclipseSource and others. | ||
* Copyright (c) 2021-2022 EclipseSource and others. | ||
* | ||
@@ -17,26 +17,52 @@ * This program and the accompanying materials are made available under the | ||
import { Operation } from './base-protocol'; | ||
import { ElementAndRoutingPoints } from './types'; | ||
import { Args, ElementAndRoutingPoints } from './types'; | ||
/** | ||
* If the source and/or target element of an edge should be adapted, the client can send a `ReconnectEdgeOperation` to the server. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `ReconnectEdgeOperations`. | ||
*/ | ||
export declare class ReconnectEdgeOperation implements Operation { | ||
readonly edgeElementId: string; | ||
readonly sourceElementId: string; | ||
readonly targetElementId: string; | ||
readonly kind: string; | ||
static readonly KIND = "reconnectEdge"; | ||
constructor(edgeElementId: string, sourceElementId: string, targetElementId: string, kind?: string); | ||
export interface ReconnectEdgeOperation extends Operation { | ||
kind: typeof ReconnectEdgeOperation.KIND; | ||
/** | ||
* The edge element that should be reconnected. | ||
*/ | ||
edgeElementId: string; | ||
/** | ||
* The (new) source element of the edge. | ||
*/ | ||
sourceElementId: string; | ||
/** | ||
* The (new) target element of the edge. | ||
*/ | ||
targetElementId: string; | ||
args?: Args; | ||
} | ||
export declare function isReconnectEdgeOperation(action: any): action is ReconnectEdgeOperation; | ||
export declare namespace ReconnectEdgeOperation { | ||
const KIND = "reconnectEdge"; | ||
function is(object: any): object is ReconnectEdgeOperation; | ||
function create(options: { | ||
edgeElementId: string; | ||
sourceElementId: string; | ||
targetElementId: string; | ||
args?: Args; | ||
}): ReconnectEdgeOperation; | ||
} | ||
/** | ||
* An edge may have zero or more routing points that "re-direct" the edge between the source and the target element. In order to set these | ||
* routing points the client may send a `ChangeRoutingPointsOperation`. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `ChangeRoutingPointsOperations`. | ||
*/ | ||
export declare class ChangeRoutingPointsOperation implements Operation { | ||
export interface ChangeRoutingPointsOperation extends Operation { | ||
kind: typeof ChangeRoutingPointsOperation.KIND; | ||
/** | ||
* The routing points of the edge (may be empty). | ||
*/ | ||
newRoutingPoints: ElementAndRoutingPoints[]; | ||
readonly kind: string; | ||
static readonly KIND = "changeRoutingPoints"; | ||
constructor(newRoutingPoints: ElementAndRoutingPoints[], kind?: string); | ||
} | ||
export declare function isChangeRoutingsPointsOperation(action: any): action is ChangeRoutingPointsOperation; | ||
export declare namespace ChangeRoutingPointsOperation { | ||
const KIND = "changeRoutingPoints"; | ||
function is(object: any): object is ChangeRoutingPointsOperation; | ||
function create(newRoutingPoints: ElementAndRoutingPoints[]): ChangeRoutingPointsOperation; | ||
} | ||
//# sourceMappingURL=edge-modification.d.ts.map |
"use strict"; | ||
/******************************************************************************** | ||
* Copyright (c) 2021 EclipseSource and others. | ||
* Copyright (c) 2021-2022 EclipseSource and others. | ||
* | ||
@@ -18,41 +18,36 @@ * This program and the accompanying materials are made available under the | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isChangeRoutingsPointsOperation = exports.ChangeRoutingPointsOperation = exports.isReconnectEdgeOperation = exports.ReconnectEdgeOperation = void 0; | ||
const typeguard_util_1 = require("../utils/typeguard-util"); | ||
exports.ChangeRoutingPointsOperation = exports.ReconnectEdgeOperation = void 0; | ||
const type_util_1 = require("../utils/type-util"); | ||
const base_protocol_1 = require("./base-protocol"); | ||
/** | ||
* If the source and/or target element of an edge should be adapted, the client can send a `ReconnectEdgeOperation` to the server. | ||
*/ | ||
class ReconnectEdgeOperation { | ||
constructor(edgeElementId, sourceElementId, targetElementId, kind = ReconnectEdgeOperation.KIND) { | ||
this.edgeElementId = edgeElementId; | ||
this.sourceElementId = sourceElementId; | ||
this.targetElementId = targetElementId; | ||
this.kind = kind; | ||
var ReconnectEdgeOperation; | ||
(function (ReconnectEdgeOperation) { | ||
ReconnectEdgeOperation.KIND = 'reconnectEdge'; | ||
function is(object) { | ||
return (base_protocol_1.Operation.hasKind(object, ReconnectEdgeOperation.KIND) && | ||
(0, type_util_1.hasStringProp)(object, 'edgeElementId') && | ||
(0, type_util_1.hasStringProp)(object, 'sourceElementId') && | ||
(0, type_util_1.hasStringProp)(object, 'targetElementId')); | ||
} | ||
} | ||
exports.ReconnectEdgeOperation = ReconnectEdgeOperation; | ||
ReconnectEdgeOperation.KIND = 'reconnectEdge'; | ||
function isReconnectEdgeOperation(action) { | ||
return (base_protocol_1.isActionKind(action, ReconnectEdgeOperation.KIND) && | ||
typeguard_util_1.isString(action, 'edgeElementId') && | ||
typeguard_util_1.isString(action, 'sourceElementId') && | ||
typeguard_util_1.isString(action, 'targetElementId')); | ||
} | ||
exports.isReconnectEdgeOperation = isReconnectEdgeOperation; | ||
/** | ||
* An edge may have zero or more routing points that "re-direct" the edge between the source and the target element. In order to set these | ||
* routing points the client may send a `ChangeRoutingPointsOperation`. | ||
*/ | ||
class ChangeRoutingPointsOperation { | ||
constructor(newRoutingPoints, kind = ChangeRoutingPointsOperation.KIND) { | ||
this.newRoutingPoints = newRoutingPoints; | ||
this.kind = kind; | ||
ReconnectEdgeOperation.is = is; | ||
function create(options) { | ||
return Object.assign({ kind: ReconnectEdgeOperation.KIND, isOperation: true }, options); | ||
} | ||
} | ||
exports.ChangeRoutingPointsOperation = ChangeRoutingPointsOperation; | ||
ChangeRoutingPointsOperation.KIND = 'changeRoutingPoints'; | ||
function isChangeRoutingsPointsOperation(action) { | ||
return base_protocol_1.isActionKind(action, ChangeRoutingPointsOperation.KIND) && typeguard_util_1.isArray(action, 'newRoutingPoints'); | ||
} | ||
exports.isChangeRoutingsPointsOperation = isChangeRoutingsPointsOperation; | ||
ReconnectEdgeOperation.create = create; | ||
})(ReconnectEdgeOperation = exports.ReconnectEdgeOperation || (exports.ReconnectEdgeOperation = {})); | ||
var ChangeRoutingPointsOperation; | ||
(function (ChangeRoutingPointsOperation) { | ||
ChangeRoutingPointsOperation.KIND = 'changeRoutingPoints'; | ||
function is(object) { | ||
return base_protocol_1.Operation.hasKind(object, ChangeRoutingPointsOperation.KIND) && (0, type_util_1.hasArrayProp)(object, 'newRoutingPoints'); | ||
} | ||
ChangeRoutingPointsOperation.is = is; | ||
function create(newRoutingPoints) { | ||
return { | ||
kind: ChangeRoutingPointsOperation.KIND, | ||
isOperation: true, | ||
newRoutingPoints | ||
}; | ||
} | ||
ChangeRoutingPointsOperation.create = create; | ||
})(ChangeRoutingPointsOperation = exports.ChangeRoutingPointsOperation || (exports.ChangeRoutingPointsOperation = {})); | ||
//# sourceMappingURL=edge-modification.js.map |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -16,45 +16,87 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import { Point } from 'sprotty-protocol'; | ||
import { Operation } from './base-protocol'; | ||
import { Args, Point } from './types'; | ||
import { Args } from './types'; | ||
/** | ||
* Common interface for all create {@link Operation}s in GLSP. | ||
* The corresponding namespace offers a helper function for type guard checks. | ||
*/ | ||
export interface CreateOperation extends Operation { | ||
/** | ||
* The type of the element that should be created. | ||
*/ | ||
elementTypeId: string; | ||
/** | ||
* Optional additional arguments for the server to execute the create operation. | ||
*/ | ||
args?: Args; | ||
} | ||
export declare function isCreateOperation(action: any): action is CreateOperation; | ||
export declare namespace CreateOperation { | ||
function is(object: any): object is CreateOperation; | ||
/** | ||
* Typeguard function to check wether the given object is a {@link CreateOperation} with the given `kind`. | ||
* @param object The object to check. | ||
* @param kind The expected operation kind. | ||
* @returns A type literal indicating wether the given object is a create operation with the given kind. | ||
*/ | ||
function hasKind(object: any, kind: string): object is CreateOperation; | ||
} | ||
/** | ||
* In order to create a node in the model the client can send a CreateNodeOperation with the necessary information to create that node. | ||
* In order to create a node in the model the client can send a CreateNodeOperation with the necessary information to create | ||
* the element that corresponds to that node in the source model. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `CreateNodeOperations`. | ||
*/ | ||
export declare class CreateNodeOperation implements CreateOperation { | ||
readonly elementTypeId: string; | ||
location?: Point | undefined; | ||
containerId?: string | undefined; | ||
args?: Args | undefined; | ||
readonly kind: string; | ||
static readonly KIND = "createNode"; | ||
constructor(elementTypeId: string, location?: Point | undefined, containerId?: string | undefined, args?: Args | undefined, kind?: string); | ||
export interface CreateNodeOperation extends CreateOperation { | ||
kind: typeof CreateNodeOperation.KIND; | ||
location?: Point; | ||
containerId?: string; | ||
} | ||
export declare function isCreateNodeOperation(action: any): action is CreateNodeOperation; | ||
export declare namespace CreateNodeOperation { | ||
const KIND = "createNode"; | ||
function is(object: any): object is CreateNodeOperation; | ||
function create(elementTypeId: string, options?: { | ||
location?: Point; | ||
containerId?: string; | ||
args?: Args; | ||
}): CreateNodeOperation; | ||
} | ||
/** | ||
* In order to create an edge in the model the client can send a `CreateEdgeOperation` with the necessary information to create that edge. | ||
* In order to create an edge in the model the client can send a `CreateEdgeOperation` with the necessary information to create | ||
* the element that corresponds to that edge in the source model. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `CreateEdgeOperations`. | ||
*/ | ||
export declare class CreateEdgeOperation implements CreateOperation { | ||
readonly elementTypeId: string; | ||
export interface CreateEdgeOperation extends CreateOperation { | ||
kind: typeof CreateEdgeOperation.KIND; | ||
sourceElementId: string; | ||
targetElementId: string; | ||
args?: Args | undefined; | ||
readonly kind: string; | ||
static readonly KIND = "createEdge"; | ||
constructor(elementTypeId: string, sourceElementId: string, targetElementId: string, args?: Args | undefined, kind?: string); | ||
} | ||
export declare function isCreateEdgeOperation(action: any): action is CreateEdgeOperation; | ||
export declare namespace CreateEdgeOperation { | ||
const KIND = "createEdge"; | ||
function is(object: any): object is CreateEdgeOperation; | ||
function create(options: { | ||
elementTypeId: string; | ||
sourceElementId: string; | ||
targetElementId: string; | ||
args?: Args; | ||
}): CreateEdgeOperation; | ||
} | ||
/** | ||
* The client sends a `DeleteElementOperation` to the server to request the deletion of an element from the model. | ||
* The client sends a `DeleteElementOperation` to the server to request the deletion of an element from the source model. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `DeleteElementOperations`. | ||
*/ | ||
export declare class DeleteElementOperation implements Operation { | ||
readonly elementIds: string[]; | ||
readonly kind: string; | ||
static readonly KIND = "deleteElement"; | ||
constructor(elementIds: string[], kind?: string); | ||
export interface DeleteElementOperation extends Operation { | ||
kind: typeof DeleteElementOperation.KIND; | ||
/** | ||
* The ids of the elements to be deleted. | ||
*/ | ||
elementIds: string[]; | ||
} | ||
export declare function isDeleteElementOperation(action: any): action is DeleteElementOperation; | ||
export declare namespace DeleteElementOperation { | ||
const KIND = "deleteElement"; | ||
function is(object: any): object is DeleteElementOperation; | ||
function create(elementIds: string[]): DeleteElementOperation; | ||
} | ||
//# sourceMappingURL=element-creation.d.ts.map |
"use strict"; | ||
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -18,63 +18,62 @@ * This program and the accompanying materials are made available under the | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isDeleteElementOperation = exports.DeleteElementOperation = exports.isCreateEdgeOperation = exports.CreateEdgeOperation = exports.isCreateNodeOperation = exports.CreateNodeOperation = exports.isCreateOperation = void 0; | ||
const typeguard_util_1 = require("../utils/typeguard-util"); | ||
exports.DeleteElementOperation = exports.CreateEdgeOperation = exports.CreateNodeOperation = exports.CreateOperation = void 0; | ||
const type_util_1 = require("../utils/type-util"); | ||
const base_protocol_1 = require("./base-protocol"); | ||
function isCreateOperation(action) { | ||
return base_protocol_1.isAction(action) && typeguard_util_1.isString(action, 'elementTypeId'); | ||
} | ||
exports.isCreateOperation = isCreateOperation; | ||
/** | ||
* In order to create a node in the model the client can send a CreateNodeOperation with the necessary information to create that node. | ||
*/ | ||
class CreateNodeOperation { | ||
constructor(elementTypeId, location, containerId, args, kind = CreateNodeOperation.KIND) { | ||
this.elementTypeId = elementTypeId; | ||
this.location = location; | ||
this.containerId = containerId; | ||
this.args = args; | ||
this.kind = kind; | ||
var CreateOperation; | ||
(function (CreateOperation) { | ||
function is(object) { | ||
return base_protocol_1.Operation.is(object) && (0, type_util_1.hasStringProp)(object, 'elementTypeId'); | ||
} | ||
} | ||
exports.CreateNodeOperation = CreateNodeOperation; | ||
CreateNodeOperation.KIND = 'createNode'; | ||
function isCreateNodeOperation(action) { | ||
return base_protocol_1.isActionKind(action, CreateNodeOperation.KIND) && typeguard_util_1.isString(action, 'elementTypeId'); | ||
} | ||
exports.isCreateNodeOperation = isCreateNodeOperation; | ||
/** | ||
* In order to create an edge in the model the client can send a `CreateEdgeOperation` with the necessary information to create that edge. | ||
*/ | ||
class CreateEdgeOperation { | ||
constructor(elementTypeId, sourceElementId, targetElementId, args, kind = CreateEdgeOperation.KIND) { | ||
this.elementTypeId = elementTypeId; | ||
this.sourceElementId = sourceElementId; | ||
this.targetElementId = targetElementId; | ||
this.args = args; | ||
this.kind = kind; | ||
CreateOperation.is = is; | ||
/** | ||
* Typeguard function to check wether the given object is a {@link CreateOperation} with the given `kind`. | ||
* @param object The object to check. | ||
* @param kind The expected operation kind. | ||
* @returns A type literal indicating wether the given object is a create operation with the given kind. | ||
*/ | ||
function hasKind(object, kind) { | ||
return CreateOperation.is(object) && object.kind === kind; | ||
} | ||
} | ||
exports.CreateEdgeOperation = CreateEdgeOperation; | ||
CreateEdgeOperation.KIND = 'createEdge'; | ||
function isCreateEdgeOperation(action) { | ||
return (base_protocol_1.isActionKind(action, CreateEdgeOperation.KIND) && | ||
typeguard_util_1.isString(action, 'elementTypeId') && | ||
typeguard_util_1.isString(action, 'sourceElementId') && | ||
typeguard_util_1.isString(action, 'targetElementId')); | ||
} | ||
exports.isCreateEdgeOperation = isCreateEdgeOperation; | ||
/** | ||
* The client sends a `DeleteElementOperation` to the server to request the deletion of an element from the model. | ||
*/ | ||
class DeleteElementOperation { | ||
constructor(elementIds, kind = DeleteElementOperation.KIND) { | ||
this.elementIds = elementIds; | ||
this.kind = kind; | ||
CreateOperation.hasKind = hasKind; | ||
})(CreateOperation = exports.CreateOperation || (exports.CreateOperation = {})); | ||
var CreateNodeOperation; | ||
(function (CreateNodeOperation) { | ||
CreateNodeOperation.KIND = 'createNode'; | ||
function is(object) { | ||
return CreateOperation.hasKind(object, CreateNodeOperation.KIND); | ||
} | ||
} | ||
exports.DeleteElementOperation = DeleteElementOperation; | ||
DeleteElementOperation.KIND = 'deleteElement'; | ||
function isDeleteElementOperation(action) { | ||
return base_protocol_1.isActionKind(action, DeleteElementOperation.KIND) && typeguard_util_1.isArray(action, 'elementIds'); | ||
} | ||
exports.isDeleteElementOperation = isDeleteElementOperation; | ||
CreateNodeOperation.is = is; | ||
function create(elementTypeId, options = {}) { | ||
return Object.assign({ kind: CreateNodeOperation.KIND, isOperation: true, elementTypeId }, options); | ||
} | ||
CreateNodeOperation.create = create; | ||
})(CreateNodeOperation = exports.CreateNodeOperation || (exports.CreateNodeOperation = {})); | ||
var CreateEdgeOperation; | ||
(function (CreateEdgeOperation) { | ||
CreateEdgeOperation.KIND = 'createEdge'; | ||
function is(object) { | ||
return (CreateOperation.hasKind(object, CreateEdgeOperation.KIND) && (0, type_util_1.hasStringProp)(object, 'sourceElementId') && (0, type_util_1.hasStringProp)(object, 'targetElementId')); | ||
} | ||
CreateEdgeOperation.is = is; | ||
function create(options) { | ||
return Object.assign({ kind: CreateEdgeOperation.KIND, isOperation: true }, options); | ||
} | ||
CreateEdgeOperation.create = create; | ||
})(CreateEdgeOperation = exports.CreateEdgeOperation || (exports.CreateEdgeOperation = {})); | ||
var DeleteElementOperation; | ||
(function (DeleteElementOperation) { | ||
DeleteElementOperation.KIND = 'deleteElement'; | ||
function is(object) { | ||
return base_protocol_1.Operation.hasKind(object, DeleteElementOperation.KIND) && (0, type_util_1.hasArrayProp)(object, 'elementIds'); | ||
} | ||
DeleteElementOperation.is = is; | ||
function create(elementIds) { | ||
return { | ||
kind: DeleteElementOperation.KIND, | ||
isOperation: true, | ||
elementIds | ||
}; | ||
} | ||
DeleteElementOperation.create = create; | ||
})(DeleteElementOperation = exports.DeleteElementOperation || (exports.DeleteElementOperation = {})); | ||
//# sourceMappingURL=element-creation.js.map |
@@ -0,31 +1,63 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
import { Bounds } from 'sprotty-protocol'; | ||
import * as sprotty from 'sprotty-protocol/lib/actions'; | ||
import { RequestAction, ResponseAction } from './base-protocol'; | ||
import { SModelRootSchema } from './model-structure'; | ||
import { Bounds } from './types'; | ||
/** | ||
* Triggered when the user hovers the mouse pointer over an element to get a popup with details on that element. | ||
* This action is sent from the client to the server. The response is a `SetPopupModelAction`. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `RequestPopupModelActions`. | ||
*/ | ||
export declare class RequestPopupModelAction implements RequestAction<SetPopupModelAction> { | ||
readonly elementId: string; | ||
readonly bounds: Bounds; | ||
readonly requestId: string; | ||
static readonly KIND = "requestPopupModel"; | ||
readonly kind = "requestPopupModel"; | ||
constructor(elementId: string, bounds: Bounds, requestId?: string); | ||
/** Factory function to dispatch a request with the `IActionDispatcher` */ | ||
static create(elementId: string, bounds: Bounds): RequestAction<SetPopupModelAction>; | ||
export interface RequestPopupModelAction extends RequestAction<SetPopupModelAction>, sprotty.RequestPopupModelAction { | ||
kind: typeof RequestPopupModelAction.KIND; | ||
/** | ||
* The identifier of the elements for which a popup is requested. | ||
*/ | ||
elementId: string; | ||
/** | ||
* The popup bounds declaring the position of the popup. Optionally the desired dimension. | ||
*/ | ||
bounds: Bounds; | ||
} | ||
export declare function isRequestPopupModelAction(action: any): action is RequestPopupModelAction; | ||
export declare namespace RequestPopupModelAction { | ||
const KIND = "requestPopupModel"; | ||
function is(object: any): object is RequestPopupModelAction; | ||
function create(options: { | ||
elementId: string; | ||
bounds: Bounds; | ||
requestId?: string; | ||
}): RequestPopupModelAction; | ||
} | ||
/** | ||
* Sent from the server to the client to display a popup in response to a RequestPopupModelAction. This action can also be used to remove | ||
* any existing popup by choosing EMPTY_ROOT as root element. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetPopupModelActions`. | ||
*/ | ||
export declare class SetPopupModelAction implements ResponseAction { | ||
readonly newRoot: SModelRootSchema; | ||
readonly responseId: string; | ||
static readonly KIND = "setPopupModel"; | ||
readonly kind = "setPopupModel"; | ||
constructor(newRoot: SModelRootSchema, responseId?: string); | ||
export interface SetPopupModelAction extends ResponseAction, sprotty.SetPopupModelAction { | ||
kind: typeof SetPopupModelAction.KIND; | ||
newRoot: SModelRootSchema; | ||
} | ||
export declare function isSetPopupModelAction(action: any): action is SetPopupModelAction; | ||
export declare namespace SetPopupModelAction { | ||
const KIND = "setPopupModel"; | ||
function is(object: any): object is SetPopupModelAction; | ||
function create(newRoot: SModelRootSchema, options?: { | ||
responseId?: string; | ||
}): SetPopupModelAction; | ||
} | ||
//# sourceMappingURL=element-hover.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isSetPopupModelAction = exports.SetPopupModelAction = exports.isRequestPopupModelAction = exports.RequestPopupModelAction = void 0; | ||
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
const typeguard_util_1 = require("../utils/typeguard-util"); | ||
exports.SetPopupModelAction = exports.RequestPopupModelAction = void 0; | ||
const type_util_1 = require("../utils/type-util"); | ||
const base_protocol_1 = require("./base-protocol"); | ||
/** | ||
* Triggered when the user hovers the mouse pointer over an element to get a popup with details on that element. | ||
* This action is sent from the client to the server. The response is a `SetPopupModelAction`. | ||
*/ | ||
class RequestPopupModelAction { | ||
constructor(elementId, bounds, requestId = '') { | ||
this.elementId = elementId; | ||
this.bounds = bounds; | ||
this.requestId = requestId; | ||
this.kind = RequestPopupModelAction.KIND; | ||
var RequestPopupModelAction; | ||
(function (RequestPopupModelAction) { | ||
RequestPopupModelAction.KIND = 'requestPopupModel'; | ||
function is(object) { | ||
return base_protocol_1.RequestAction.hasKind(object, RequestPopupModelAction.KIND) && (0, type_util_1.hasStringProp)(object, 'elementId') && (0, type_util_1.hasObjectProp)(object, 'bounds'); | ||
} | ||
/** Factory function to dispatch a request with the `IActionDispatcher` */ | ||
static create(elementId, bounds) { | ||
return new RequestPopupModelAction(elementId, bounds, base_protocol_1.generateRequestId()); | ||
RequestPopupModelAction.is = is; | ||
function create(options) { | ||
return Object.assign({ kind: RequestPopupModelAction.KIND, requestId: '' }, options); | ||
} | ||
} | ||
exports.RequestPopupModelAction = RequestPopupModelAction; | ||
RequestPopupModelAction.KIND = 'requestPopupModel'; | ||
function isRequestPopupModelAction(action) { | ||
return (base_protocol_1.isActionKind(action, RequestPopupModelAction.KIND) && | ||
typeguard_util_1.isString(action, 'elementId') && | ||
typeguard_util_1.isObject(action, 'bounds') && | ||
typeguard_util_1.isString(action, 'requestId')); | ||
} | ||
exports.isRequestPopupModelAction = isRequestPopupModelAction; | ||
/** | ||
* Sent from the server to the client to display a popup in response to a RequestPopupModelAction. This action can also be used to remove | ||
* any existing popup by choosing EMPTY_ROOT as root element. | ||
*/ | ||
class SetPopupModelAction { | ||
constructor(newRoot, responseId = '') { | ||
this.newRoot = newRoot; | ||
this.responseId = responseId; | ||
this.kind = SetPopupModelAction.KIND; | ||
RequestPopupModelAction.create = create; | ||
})(RequestPopupModelAction = exports.RequestPopupModelAction || (exports.RequestPopupModelAction = {})); | ||
var SetPopupModelAction; | ||
(function (SetPopupModelAction) { | ||
SetPopupModelAction.KIND = 'setPopupModel'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, SetPopupModelAction.KIND) && (0, type_util_1.hasObjectProp)(object, 'newRoot'); | ||
} | ||
} | ||
exports.SetPopupModelAction = SetPopupModelAction; | ||
SetPopupModelAction.KIND = 'setPopupModel'; | ||
function isSetPopupModelAction(action) { | ||
return base_protocol_1.isActionKind(action, SetPopupModelAction.KIND) && typeguard_util_1.isObject(action, 'newRoot') && typeguard_util_1.isString(action, 'responseId'); | ||
} | ||
exports.isSetPopupModelAction = isSetPopupModelAction; | ||
SetPopupModelAction.is = is; | ||
function create(newRoot, options = {}) { | ||
return Object.assign({ kind: SetPopupModelAction.KIND, responseId: '', newRoot }, options); | ||
} | ||
SetPopupModelAction.create = create; | ||
})(SetPopupModelAction = exports.SetPopupModelAction || (exports.SetPopupModelAction = {})); | ||
//# sourceMappingURL=element-hover.js.map |
@@ -0,25 +1,107 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2020-2022 EclipseSource and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
import { JsonPrimitive } from 'sprotty-protocol'; | ||
import { Action, RequestAction, ResponseAction } from './base-protocol'; | ||
import { Args, EditorContext } from './types'; | ||
/** | ||
* A NavigationTarget identifies the object we want to navigate to via its uri and may further provide a label to display for the client. | ||
* A `NavigationTarget` identifies the object we want to navigate to via its uri and may further provide a label to display to the user. | ||
* The corresponding namespace offers a set of utility function to interact with `NavigationTargets`. | ||
*/ | ||
export interface NavigationTarget { | ||
/** | ||
* URI to identify the object we want to navigate to. | ||
*/ | ||
uri: string; | ||
/** | ||
* Optional label to display to the user. | ||
*/ | ||
label?: string; | ||
/** | ||
* Domain-specific arguments that may be interpreted directly or resolved further. | ||
*/ | ||
args?: Args; | ||
} | ||
export declare namespace NavigationTarget { | ||
function is(object: any): object is NavigationTarget; | ||
/** | ||
* Generic key to store element ids as additional argument | ||
*/ | ||
const ELEMENT_IDS = "elementIds"; | ||
/** | ||
* The separator that is used to store he values for the {@link ELEMENT_IDS} as a single string. | ||
*/ | ||
const ELEMENT_IDS_SEPARATOR = "&"; | ||
/** | ||
* Generic key ot store the line property of a {@link TextPosition} as additional argument. | ||
*/ | ||
const TEXT_LINE = "line"; | ||
/** | ||
* Generic key ot store the character property of a {@link TextPosition} as additional argument. | ||
*/ | ||
const TEXT_COLUMN = "column"; | ||
/** | ||
* Denotes the position of the cursor in a text element. | ||
*/ | ||
interface TextPosition { | ||
line: number; | ||
/** | ||
* The character number within the line. Also refereed to as column. | ||
*/ | ||
character: number; | ||
} | ||
/** | ||
* Utility function to check wether the given {@link NavigationTarget} has additional arguments defined. | ||
* @param target The navigation target to check. | ||
* @returns `true` if the navigation target has a non-empty `args` property, `false` | ||
*/ | ||
function hasArguments(target: NavigationTarget): boolean; | ||
function addArgument(target: NavigationTarget, key: string, value: string | number | boolean): void; | ||
/** | ||
* Adds a new key-value pair to the additional arguments of the given {@link NavigationTarget}. | ||
* @param target The navigation target. | ||
* @param key The key of the new argument. | ||
* @param value The (primitive) value of the new argument. | ||
*/ | ||
function addArgument(target: NavigationTarget, key: string, value: JsonPrimitive): void; | ||
/** | ||
* Retrieves the element ids that have been stored with the generic {@link ELEMENT_IDS} key from the args of the | ||
* given target. | ||
* @param target The navigation target. | ||
* @returns An array with the parsed element ids. The array is empty if no {@link ELEMENT_IDS} key is present in the args | ||
* of the navigation target. | ||
*/ | ||
function getElementIds(target: NavigationTarget): string[]; | ||
function setElementIds(target: NavigationTarget, elementIds: string[]): string; | ||
/** | ||
* Stores the given element ids in the given {@link NavigationTarget} as additional arguments using the generic {@link ELEMENT_IDS} key. | ||
* @param target The navigation target. | ||
* @param elementIds The element ids that should be stored. | ||
* @returns the value of the {@link ELEMENT_IDS} key after storing the given element ids. | ||
*/ | ||
function setElementIds(target: NavigationTarget, ...elementIds: string[]): string; | ||
/** | ||
* Stores the given {@link TextPosition} in the given {@link NavigationTarget} as additional arguments using | ||
* the generic {@link TEXT_LINE} & {@link TEXT_COLUMN} keys. | ||
* @param target The navigation target. | ||
* @param position The text position that should be stored. | ||
*/ | ||
function setTextPosition(target: NavigationTarget, position: TextPosition | undefined): void; | ||
/** | ||
* Retrieves the {@link TextPosition} that have been stored with the generic {@link TEXT_LINE} & {@link TEXT_COLUMN} keys | ||
* from the args of the given target. | ||
* @param target The navigation target. | ||
* @returns The parsed text position or `undefined` if one of the generic text keys is not present in the args | ||
* of the navigation target. | ||
*/ | ||
function getTextPosition(target: NavigationTarget): TextPosition | undefined; | ||
@@ -29,61 +111,106 @@ } | ||
* Action that is usually sent from the client to the server to request navigation targets for a specific navigation type such as | ||
* documentation or implementation in the given editor context. | ||
* `documentation` or `implementation` in the given editor context. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `RequestNavigationTargetsActions`. | ||
*/ | ||
export declare class RequestNavigationTargetsAction implements RequestAction<SetNavigationTargetsAction> { | ||
readonly targetTypeId: string; | ||
readonly editorContext: EditorContext; | ||
readonly requestId: string; | ||
static readonly KIND = "requestNavigationTargets"; | ||
kind: string; | ||
constructor(targetTypeId: string, editorContext: EditorContext, requestId?: string); | ||
export interface RequestNavigationTargetsAction extends RequestAction<SetNavigationTargetsAction> { | ||
kind: typeof RequestNavigationTargetsAction.KIND; | ||
/** | ||
* Identifier of the type of navigation targets we want to retrieve, e.g., 'documentation', 'implementation', etc. | ||
*/ | ||
targetTypeId: string; | ||
editorContext: EditorContext; | ||
} | ||
export declare function isRequestNavigationTargetsAction(action: any): action is RequestNavigationTargetsAction; | ||
export declare namespace RequestNavigationTargetsAction { | ||
const KIND = "requestNavigationTargets"; | ||
function is(object: any): object is RequestNavigationTargetsAction; | ||
function create(options: { | ||
targetTypeId: string; | ||
editorContext: EditorContext; | ||
requestId?: string; | ||
}): RequestNavigationTargetsAction; | ||
} | ||
/** | ||
* Response action from the server following a {@link RequestNavigationTargetsAction}. It contains all available navigation targets for the | ||
* queried target type in the provided editor context. The server may also provide additional information using the arguments, e.g., | ||
* warnings, that can be interpreted by the client. | ||
* warnings, that can be interpreted by the client. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetNavigationTargetsActions`. | ||
*/ | ||
export declare class SetNavigationTargetsAction implements ResponseAction { | ||
readonly targets: NavigationTarget[]; | ||
readonly responseId: string; | ||
readonly args?: Args | undefined; | ||
static readonly KIND = "setNavigationTargets"; | ||
kind: string; | ||
constructor(targets: NavigationTarget[], responseId?: string, args?: Args | undefined); | ||
export interface SetNavigationTargetsAction extends ResponseAction { | ||
kind: typeof SetNavigationTargetsAction.KIND; | ||
targets: NavigationTarget[]; | ||
/** | ||
* Custom arguments that may be interpreted by the client. | ||
*/ | ||
args?: Args; | ||
} | ||
export declare function isSetNavigationTargetsAction(action: any): action is SetNavigationTargetsAction; | ||
/** Action that triggers the navigation to a particular navigation target, such as element IDs, queries, etc.. */ | ||
export declare class NavigateToTargetAction implements Action { | ||
readonly target: NavigationTarget; | ||
static readonly KIND = "navigateToTarget"; | ||
readonly kind = "navigateToTarget"; | ||
constructor(target: NavigationTarget); | ||
export declare namespace SetNavigationTargetsAction { | ||
const KIND = "setNavigationTargets"; | ||
function is(object: any): object is SetNavigationTargetsAction; | ||
function create(targets: NavigationTarget[], options?: { | ||
args?: Args; | ||
responseId?: string; | ||
}): SetNavigationTargetsAction; | ||
} | ||
export declare function isNavigateToTargetAction(action: any): action is NavigateToTargetAction; | ||
/** | ||
* Action that triggers the navigation to a particular navigation target, such as element IDs, queries, etc.. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `NavigateToTargetActions`. | ||
*/ | ||
export interface NavigateToTargetAction extends Action { | ||
kind: typeof NavigateToTargetAction.KIND; | ||
target: NavigationTarget; | ||
} | ||
export declare namespace NavigateToTargetAction { | ||
const KIND = "navigateToTarget"; | ||
function is(object: any): object is NavigateToTargetAction; | ||
function create(target: NavigationTarget): NavigateToTargetAction; | ||
} | ||
/** | ||
* If a client cannot navigate to a target directly, a {@link ResolveNavigationTargetAction} may be sent to the server to resolve the | ||
* navigation target to one or more model elements. This may be useful in cases where the resolution of each target is expensive or the | ||
* client architecture requires an indirection. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `ResolveNavigationTargetActions`. | ||
*/ | ||
export declare class ResolveNavigationTargetAction implements RequestAction<SetResolvedNavigationTargetAction> { | ||
readonly navigationTarget: NavigationTarget; | ||
readonly requestId: string; | ||
static readonly KIND = "resolveNavigationTarget"; | ||
kind: string; | ||
constructor(navigationTarget: NavigationTarget, requestId?: string); | ||
export interface ResolveNavigationTargetAction extends RequestAction<SetResolvedNavigationTargetAction> { | ||
kind: typeof ResolveNavigationTargetAction.KIND; | ||
/** | ||
* The navigation target to resolve. | ||
*/ | ||
navigationTarget: NavigationTarget; | ||
} | ||
export declare function isResolveNavigationTargetAction(action: any): action is ResolveNavigationTargetAction; | ||
export declare namespace ResolveNavigationTargetAction { | ||
const KIND = "resolveNavigationTarget"; | ||
function is(object: any): object is ResolveNavigationTargetAction; | ||
function create(navigationTarget: NavigationTarget, options?: { | ||
requestId?: string; | ||
}): ResolveNavigationTargetAction; | ||
} | ||
/** | ||
* An action sent from the server in response to a {@link ResolveNavigationTargetAction}. The response contains the resolved element ids | ||
* for the given target and may contain additional information in the args property. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetResolvedNavigationTargetActions`. | ||
*/ | ||
export declare class SetResolvedNavigationTargetAction implements ResponseAction { | ||
readonly elementIds: string[]; | ||
readonly args?: Args | undefined; | ||
readonly responseId: string; | ||
static readonly KIND = "setResolvedNavigationTarget"; | ||
kind: string; | ||
constructor(elementIds?: string[], args?: Args | undefined, responseId?: string); | ||
export interface SetResolvedNavigationTargetAction extends ResponseAction { | ||
kind: typeof SetResolvedNavigationTargetAction.KIND; | ||
/** | ||
* The element ids of the resolved navigation target. | ||
*/ | ||
elementIds: string[]; | ||
/** | ||
* Custom arguments that may be interpreted by the client. | ||
*/ | ||
args?: Args; | ||
} | ||
export declare function isSetResolvedNavigationTargets(action: any): action is SetResolvedNavigationTargetAction; | ||
export declare namespace SetResolvedNavigationTargetAction { | ||
const KIND = "setResolvedNavigationTarget"; | ||
function is(object: any): object is SetResolvedNavigationTargetAction; | ||
function create(elementIds: string[], options?: { | ||
args?: Args; | ||
responseId?: string; | ||
}): SetResolvedNavigationTargetAction; | ||
} | ||
/** | ||
@@ -93,10 +220,17 @@ * If a {@link NavigationTarget} cannot be resolved or the resolved target is something that is not part of our model source, e.g., | ||
* an action would be typically handled by an integration layer (such as the surrounding IDE). | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `NavigateToExternalTargetActions`. | ||
*/ | ||
export declare class NavigateToExternalTargetAction implements Action { | ||
readonly target: NavigationTarget; | ||
static readonly KIND = "navigateToExternalTarget"; | ||
readonly kind = "navigateToExternalTarget"; | ||
constructor(target: NavigationTarget); | ||
export interface NavigateToExternalTargetAction extends Action { | ||
kind: typeof NavigateToExternalTargetAction.KIND; | ||
/** | ||
* The diagram-external target to which the client shall navigate. | ||
*/ | ||
target: NavigationTarget; | ||
} | ||
export declare function isNavigateToExternalTargetAction(action: any): action is NavigateToExternalTargetAction; | ||
export declare namespace NavigateToExternalTargetAction { | ||
const KIND = "navigateToExternalTarget"; | ||
function is(object: any): object is NavigateToExternalTargetAction; | ||
function create(target: NavigationTarget): NavigateToExternalTargetAction; | ||
} | ||
//# sourceMappingURL=element-navigation.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isNavigateToExternalTargetAction = exports.NavigateToExternalTargetAction = exports.isSetResolvedNavigationTargets = exports.SetResolvedNavigationTargetAction = exports.isResolveNavigationTargetAction = exports.ResolveNavigationTargetAction = exports.isNavigateToTargetAction = exports.NavigateToTargetAction = exports.isSetNavigationTargetsAction = exports.SetNavigationTargetsAction = exports.isRequestNavigationTargetsAction = exports.RequestNavigationTargetsAction = exports.NavigationTarget = void 0; | ||
/******************************************************************************** | ||
* Copyright (c) 2020-2021 EclipseSource and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
const typeguard_util_1 = require("../utils/typeguard-util"); | ||
exports.NavigateToExternalTargetAction = exports.SetResolvedNavigationTargetAction = exports.ResolveNavigationTargetAction = exports.NavigateToTargetAction = exports.SetNavigationTargetsAction = exports.RequestNavigationTargetsAction = exports.NavigationTarget = void 0; | ||
const type_util_1 = require("../utils/type-util"); | ||
const base_protocol_1 = require("./base-protocol"); | ||
var NavigationTarget; | ||
(function (NavigationTarget) { | ||
function is(object) { | ||
return object !== undefined && (0, type_util_1.hasStringProp)(object, 'uri'); | ||
} | ||
NavigationTarget.is = is; | ||
/** | ||
* Generic key to store element ids as additional argument | ||
*/ | ||
NavigationTarget.ELEMENT_IDS = 'elementIds'; | ||
/** | ||
* The separator that is used to store he values for the {@link ELEMENT_IDS} as a single string. | ||
*/ | ||
NavigationTarget.ELEMENT_IDS_SEPARATOR = '&'; | ||
/** | ||
* Generic key ot store the line property of a {@link TextPosition} as additional argument. | ||
*/ | ||
NavigationTarget.TEXT_LINE = 'line'; | ||
/** | ||
* Generic key ot store the character property of a {@link TextPosition} as additional argument. | ||
*/ | ||
NavigationTarget.TEXT_COLUMN = 'column'; | ||
/** | ||
* Utility function to check wether the given {@link NavigationTarget} has additional arguments defined. | ||
* @param target The navigation target to check. | ||
* @returns `true` if the navigation target has a non-empty `args` property, `false` | ||
*/ | ||
function hasArguments(target) { | ||
@@ -31,4 +37,10 @@ return target.args !== undefined && Object.keys(target.args).length > 0; | ||
NavigationTarget.hasArguments = hasArguments; | ||
/** | ||
* Adds a new key-value pair to the additional arguments of the given {@link NavigationTarget}. | ||
* @param target The navigation target. | ||
* @param key The key of the new argument. | ||
* @param value The (primitive) value of the new argument. | ||
*/ | ||
function addArgument(target, key, value) { | ||
if (target.args === undefined) { | ||
if (!target.args) { | ||
target.args = {}; | ||
@@ -39,4 +51,12 @@ } | ||
NavigationTarget.addArgument = addArgument; | ||
/** | ||
* Retrieves the element ids that have been stored with the generic {@link ELEMENT_IDS} key from the args of the | ||
* given target. | ||
* @param target The navigation target. | ||
* @returns An array with the parsed element ids. The array is empty if no {@link ELEMENT_IDS} key is present in the args | ||
* of the navigation target. | ||
*/ | ||
function getElementIds(target) { | ||
if (target.args === undefined || target.args[NavigationTarget.ELEMENT_IDS] === undefined) { | ||
var _a; | ||
if (!((_a = target === null || target === void 0 ? void 0 : target.args) === null || _a === void 0 ? void 0 : _a[NavigationTarget.ELEMENT_IDS])) { | ||
return []; | ||
@@ -48,3 +68,9 @@ } | ||
NavigationTarget.getElementIds = getElementIds; | ||
function setElementIds(target, elementIds) { | ||
/** | ||
* Stores the given element ids in the given {@link NavigationTarget} as additional arguments using the generic {@link ELEMENT_IDS} key. | ||
* @param target The navigation target. | ||
* @param elementIds The element ids that should be stored. | ||
* @returns the value of the {@link ELEMENT_IDS} key after storing the given element ids. | ||
*/ | ||
function setElementIds(target, ...elementIds) { | ||
if (target.args === undefined) { | ||
@@ -56,2 +82,8 @@ target.args = {}; | ||
NavigationTarget.setElementIds = setElementIds; | ||
/** | ||
* Stores the given {@link TextPosition} in the given {@link NavigationTarget} as additional arguments using | ||
* the generic {@link TEXT_LINE} & {@link TEXT_COLUMN} keys. | ||
* @param target The navigation target. | ||
* @param position The text position that should be stored. | ||
*/ | ||
function setTextPosition(target, position) { | ||
@@ -67,4 +99,11 @@ if (position) { | ||
NavigationTarget.setTextPosition = setTextPosition; | ||
/** | ||
* Retrieves the {@link TextPosition} that have been stored with the generic {@link TEXT_LINE} & {@link TEXT_COLUMN} keys | ||
* from the args of the given target. | ||
* @param target The navigation target. | ||
* @returns The parsed text position or `undefined` if one of the generic text keys is not present in the args | ||
* of the navigation target. | ||
*/ | ||
function getTextPosition(target) { | ||
if (target.args === undefined || target.args[NavigationTarget.TEXT_LINE] === undefined || target.args[NavigationTarget.TEXT_COLUMN] === undefined) { | ||
if (!target.args || !target.args[NavigationTarget.TEXT_LINE] || !target.args[NavigationTarget.TEXT_COLUMN]) { | ||
return undefined; | ||
@@ -79,108 +118,80 @@ } | ||
})(NavigationTarget = exports.NavigationTarget || (exports.NavigationTarget = {})); | ||
/** | ||
* Action that is usually sent from the client to the server to request navigation targets for a specific navigation type such as | ||
* documentation or implementation in the given editor context. | ||
*/ | ||
class RequestNavigationTargetsAction { | ||
constructor(targetTypeId, editorContext, requestId = base_protocol_1.generateRequestId()) { | ||
this.targetTypeId = targetTypeId; | ||
this.editorContext = editorContext; | ||
this.requestId = requestId; | ||
this.kind = RequestNavigationTargetsAction.KIND; | ||
var RequestNavigationTargetsAction; | ||
(function (RequestNavigationTargetsAction) { | ||
RequestNavigationTargetsAction.KIND = 'requestNavigationTargets'; | ||
function is(object) { | ||
return base_protocol_1.RequestAction.hasKind(object, RequestNavigationTargetsAction.KIND) && (0, type_util_1.hasStringProp)(object, 'targetTypeId') && (0, type_util_1.hasObjectProp)(object, 'editorContext'); | ||
} | ||
} | ||
exports.RequestNavigationTargetsAction = RequestNavigationTargetsAction; | ||
RequestNavigationTargetsAction.KIND = 'requestNavigationTargets'; | ||
function isRequestNavigationTargetsAction(action) { | ||
return (base_protocol_1.isActionKind(action, RequestNavigationTargetsAction.KIND) && | ||
typeguard_util_1.isString(action, 'targetTypeId') && | ||
typeguard_util_1.isObject(action, 'editorContext') && | ||
typeguard_util_1.isString(action, 'requestId')); | ||
} | ||
exports.isRequestNavigationTargetsAction = isRequestNavigationTargetsAction; | ||
/** | ||
* Response action from the server following a {@link RequestNavigationTargetsAction}. It contains all available navigation targets for the | ||
* queried target type in the provided editor context. The server may also provide additional information using the arguments, e.g., | ||
* warnings, that can be interpreted by the client. | ||
*/ | ||
class SetNavigationTargetsAction { | ||
constructor(targets, responseId = '', args) { | ||
this.targets = targets; | ||
this.responseId = responseId; | ||
this.args = args; | ||
this.kind = SetNavigationTargetsAction.KIND; | ||
RequestNavigationTargetsAction.is = is; | ||
function create(options) { | ||
return Object.assign({ kind: RequestNavigationTargetsAction.KIND, requestId: '' }, options); | ||
} | ||
} | ||
exports.SetNavigationTargetsAction = SetNavigationTargetsAction; | ||
SetNavigationTargetsAction.KIND = 'setNavigationTargets'; | ||
function isSetNavigationTargetsAction(action) { | ||
return base_protocol_1.isActionKind(action, SetNavigationTargetsAction.KIND) && typeguard_util_1.isArray(action, 'targets') && typeguard_util_1.isString(action, 'responseId'); | ||
} | ||
exports.isSetNavigationTargetsAction = isSetNavigationTargetsAction; | ||
/** Action that triggers the navigation to a particular navigation target, such as element IDs, queries, etc.. */ | ||
class NavigateToTargetAction { | ||
constructor(target) { | ||
this.target = target; | ||
this.kind = NavigateToTargetAction.KIND; | ||
RequestNavigationTargetsAction.create = create; | ||
})(RequestNavigationTargetsAction = exports.RequestNavigationTargetsAction || (exports.RequestNavigationTargetsAction = {})); | ||
var SetNavigationTargetsAction; | ||
(function (SetNavigationTargetsAction) { | ||
SetNavigationTargetsAction.KIND = 'setNavigationTargets'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, SetNavigationTargetsAction.KIND) && (0, type_util_1.hasArrayProp)(object, 'targets'); | ||
} | ||
} | ||
exports.NavigateToTargetAction = NavigateToTargetAction; | ||
NavigateToTargetAction.KIND = 'navigateToTarget'; | ||
function isNavigateToTargetAction(action) { | ||
return base_protocol_1.isActionKind(action, NavigateToTargetAction.KIND) && typeguard_util_1.isObject(action, 'target'); | ||
} | ||
exports.isNavigateToTargetAction = isNavigateToTargetAction; | ||
/** | ||
* If a client cannot navigate to a target directly, a {@link ResolveNavigationTargetAction} may be sent to the server to resolve the | ||
* navigation target to one or more model elements. This may be useful in cases where the resolution of each target is expensive or the | ||
* client architecture requires an indirection. | ||
*/ | ||
class ResolveNavigationTargetAction { | ||
constructor(navigationTarget, requestId = base_protocol_1.generateRequestId()) { | ||
this.navigationTarget = navigationTarget; | ||
this.requestId = requestId; | ||
this.kind = ResolveNavigationTargetAction.KIND; | ||
SetNavigationTargetsAction.is = is; | ||
function create(targets, options = {}) { | ||
return Object.assign({ kind: SetNavigationTargetsAction.KIND, responseId: '', targets }, options); | ||
} | ||
} | ||
exports.ResolveNavigationTargetAction = ResolveNavigationTargetAction; | ||
ResolveNavigationTargetAction.KIND = 'resolveNavigationTarget'; | ||
function isResolveNavigationTargetAction(action) { | ||
return (base_protocol_1.isActionKind(action, ResolveNavigationTargetAction.KIND) && typeguard_util_1.isObject(action, 'navigationTarget') && typeguard_util_1.isString(action, 'requestId')); | ||
} | ||
exports.isResolveNavigationTargetAction = isResolveNavigationTargetAction; | ||
/** | ||
* An action sent from the server in response to a {@link ResolveNavigationTargetAction}. The response contains the resolved element ids | ||
* for the given target and may contain additional information in the args property. | ||
*/ | ||
class SetResolvedNavigationTargetAction { | ||
constructor(elementIds = [], args, responseId = '') { | ||
this.elementIds = elementIds; | ||
this.args = args; | ||
this.responseId = responseId; | ||
this.kind = SetResolvedNavigationTargetAction.KIND; | ||
SetNavigationTargetsAction.create = create; | ||
})(SetNavigationTargetsAction = exports.SetNavigationTargetsAction || (exports.SetNavigationTargetsAction = {})); | ||
var NavigateToTargetAction; | ||
(function (NavigateToTargetAction) { | ||
NavigateToTargetAction.KIND = 'navigateToTarget'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, NavigateToTargetAction.KIND) && (0, type_util_1.hasObjectProp)(object, 'target'); | ||
} | ||
} | ||
exports.SetResolvedNavigationTargetAction = SetResolvedNavigationTargetAction; | ||
SetResolvedNavigationTargetAction.KIND = 'setResolvedNavigationTarget'; | ||
function isSetResolvedNavigationTargets(action) { | ||
return base_protocol_1.isActionKind(action, SetResolvedNavigationTargetAction.KIND) && typeguard_util_1.isArray(action, 'elementIds') && typeguard_util_1.isString(action, 'responseId'); | ||
} | ||
exports.isSetResolvedNavigationTargets = isSetResolvedNavigationTargets; | ||
/** | ||
* If a {@link NavigationTarget} cannot be resolved or the resolved target is something that is not part of our model source, e.g., | ||
* a separate documentation file, a {@link NavigateToExternalTargetAction} may be sent. Since the target it outside of the model scope such | ||
* an action would be typically handled by an integration layer (such as the surrounding IDE). | ||
*/ | ||
class NavigateToExternalTargetAction { | ||
constructor(target) { | ||
this.target = target; | ||
this.kind = NavigateToExternalTargetAction.KIND; | ||
NavigateToTargetAction.is = is; | ||
function create(target) { | ||
return { | ||
kind: NavigateToTargetAction.KIND, | ||
target | ||
}; | ||
} | ||
} | ||
exports.NavigateToExternalTargetAction = NavigateToExternalTargetAction; | ||
NavigateToExternalTargetAction.KIND = 'navigateToExternalTarget'; | ||
function isNavigateToExternalTargetAction(action) { | ||
return base_protocol_1.isActionKind(action, NavigateToExternalTargetAction.KIND) && typeguard_util_1.isObject(action, 'target'); | ||
} | ||
exports.isNavigateToExternalTargetAction = isNavigateToExternalTargetAction; | ||
NavigateToTargetAction.create = create; | ||
})(NavigateToTargetAction = exports.NavigateToTargetAction || (exports.NavigateToTargetAction = {})); | ||
var ResolveNavigationTargetAction; | ||
(function (ResolveNavigationTargetAction) { | ||
ResolveNavigationTargetAction.KIND = 'resolveNavigationTarget'; | ||
function is(object) { | ||
return base_protocol_1.RequestAction.hasKind(object, ResolveNavigationTargetAction.KIND) && (0, type_util_1.hasObjectProp)(object, 'navigationTarget'); | ||
} | ||
ResolveNavigationTargetAction.is = is; | ||
function create(navigationTarget, options = {}) { | ||
return Object.assign({ kind: ResolveNavigationTargetAction.KIND, requestId: '', navigationTarget }, options); | ||
} | ||
ResolveNavigationTargetAction.create = create; | ||
})(ResolveNavigationTargetAction = exports.ResolveNavigationTargetAction || (exports.ResolveNavigationTargetAction = {})); | ||
var SetResolvedNavigationTargetAction; | ||
(function (SetResolvedNavigationTargetAction) { | ||
SetResolvedNavigationTargetAction.KIND = 'setResolvedNavigationTarget'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, SetResolvedNavigationTargetAction.KIND) && (0, type_util_1.hasArrayProp)(object, 'elementIds'); | ||
} | ||
SetResolvedNavigationTargetAction.is = is; | ||
function create(elementIds, options = {}) { | ||
return Object.assign({ kind: SetResolvedNavigationTargetAction.KIND, responseId: '', elementIds }, options); | ||
} | ||
SetResolvedNavigationTargetAction.create = create; | ||
})(SetResolvedNavigationTargetAction = exports.SetResolvedNavigationTargetAction || (exports.SetResolvedNavigationTargetAction = {})); | ||
var NavigateToExternalTargetAction; | ||
(function (NavigateToExternalTargetAction) { | ||
NavigateToExternalTargetAction.KIND = 'navigateToExternalTarget'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, NavigateToExternalTargetAction.KIND) && (0, type_util_1.hasObjectProp)(object, 'target'); | ||
} | ||
NavigateToExternalTargetAction.is = is; | ||
function create(target) { | ||
return { | ||
kind: NavigateToExternalTargetAction.KIND, | ||
target | ||
}; | ||
} | ||
NavigateToExternalTargetAction.create = create; | ||
})(NavigateToExternalTargetAction = exports.NavigateToExternalTargetAction || (exports.NavigateToExternalTargetAction = {})); | ||
//# sourceMappingURL=element-navigation.js.map |
@@ -0,1 +1,17 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
import * as sprotty from 'sprotty-protocol/lib/actions'; | ||
import { Action } from './base-protocol'; | ||
@@ -5,25 +21,42 @@ /** | ||
* selected state accordingly, so the elements can be rendered differently. The server can send such an action to the client in order to | ||
* change the selection remotely. | ||
* change the selection remotely. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SelectActions`. | ||
*/ | ||
export declare class SelectAction implements Action { | ||
readonly selectedElementsIDs: string[]; | ||
readonly deselectedElementsIDs: string[]; | ||
static readonly KIND = "elementSelected"; | ||
kind: string; | ||
constructor(selectedElementsIDs?: string[], deselectedElementsIDs?: string[]); | ||
export interface SelectAction extends Action, sprotty.SelectAction { | ||
kind: typeof SelectAction.KIND; | ||
/** | ||
* The identifiers of the elements to mark as selected. | ||
*/ | ||
selectedElementsIDs: string[]; | ||
/** | ||
* The identifiers of the elements to mark as not selected. | ||
*/ | ||
deselectedElementsIDs: string[]; | ||
} | ||
export declare function isSelectAction(action: any): action is SelectAction; | ||
export declare namespace SelectAction { | ||
const KIND = "elementSelected"; | ||
function is(object: any): object is SelectAction; | ||
function create(options?: { | ||
selectedElementsIDs?: string[]; | ||
deselectedElementsIDs?: string[]; | ||
}): SelectAction; | ||
} | ||
/** | ||
* Programmatic action for selecting or deselecting all elements. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SelectAllActions`. | ||
*/ | ||
export declare class SelectAllAction implements Action { | ||
readonly select: boolean; | ||
static readonly KIND = "allSelected"; | ||
kind: string; | ||
export interface SelectAllAction extends Action, sprotty.SelectAllAction { | ||
kind: typeof SelectAllAction.KIND; | ||
/** | ||
* If `select` is true, all elements are selected, otherwise they are deselected. | ||
*/ | ||
constructor(select?: boolean); | ||
select: boolean; | ||
} | ||
export declare function isSelectAllAction(action: any): action is SelectAllAction; | ||
export declare namespace SelectAllAction { | ||
const KIND = "allSelected"; | ||
function is(object: any): object is SelectAllAction; | ||
function create(select?: boolean): SelectAllAction; | ||
} | ||
//# sourceMappingURL=element-selection.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isSelectAllAction = exports.SelectAllAction = exports.isSelectAction = exports.SelectAction = void 0; | ||
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
const typeguard_util_1 = require("../utils/typeguard-util"); | ||
exports.SelectAllAction = exports.SelectAction = void 0; | ||
const type_util_1 = require("../utils/type-util"); | ||
const base_protocol_1 = require("./base-protocol"); | ||
/** | ||
* Triggered when the user changes the selection, e.g. by clicking on a selectable element. The action should trigger a change in the | ||
* selected state accordingly, so the elements can be rendered differently. The server can send such an action to the client in order to | ||
* change the selection remotely. | ||
*/ | ||
class SelectAction { | ||
constructor(selectedElementsIDs = [], deselectedElementsIDs = []) { | ||
this.selectedElementsIDs = selectedElementsIDs; | ||
this.deselectedElementsIDs = deselectedElementsIDs; | ||
this.kind = SelectAction.KIND; | ||
var SelectAction; | ||
(function (SelectAction) { | ||
SelectAction.KIND = 'elementSelected'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, SelectAction.KIND) && (0, type_util_1.hasArrayProp)(object, 'selectedElementsIDs') && (0, type_util_1.hasArrayProp)(object, 'deselectedElementsIDs'); | ||
} | ||
} | ||
exports.SelectAction = SelectAction; | ||
SelectAction.KIND = 'elementSelected'; | ||
function isSelectAction(action) { | ||
return base_protocol_1.isActionKind(action, SelectAction.KIND) && typeguard_util_1.isArray(action, 'selectedElementsIDs') && typeguard_util_1.isArray(action, 'deselectedElementsIDs'); | ||
} | ||
exports.isSelectAction = isSelectAction; | ||
/** | ||
* Programmatic action for selecting or deselecting all elements. | ||
*/ | ||
class SelectAllAction { | ||
/** | ||
* If `select` is true, all elements are selected, otherwise they are deselected. | ||
*/ | ||
constructor(select = true) { | ||
this.select = select; | ||
this.kind = SelectAllAction.KIND; | ||
SelectAction.is = is; | ||
function create(options = {}) { | ||
return Object.assign({ kind: SelectAction.KIND, selectedElementsIDs: [], deselectedElementsIDs: [] }, options); | ||
} | ||
} | ||
exports.SelectAllAction = SelectAllAction; | ||
SelectAllAction.KIND = 'allSelected'; | ||
function isSelectAllAction(action) { | ||
return base_protocol_1.isActionKind(action, SelectAllAction.KIND) && typeguard_util_1.isBoolean(action, 'select'); | ||
} | ||
exports.isSelectAllAction = isSelectAllAction; | ||
SelectAction.create = create; | ||
})(SelectAction = exports.SelectAction || (exports.SelectAction = {})); | ||
var SelectAllAction; | ||
(function (SelectAllAction) { | ||
SelectAllAction.KIND = 'allSelected'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, SelectAllAction.KIND) && (0, type_util_1.hasBooleanProp)(object, 'select'); | ||
} | ||
SelectAllAction.is = is; | ||
function create(select = true) { | ||
return { | ||
kind: SelectAllAction.KIND, | ||
select | ||
}; | ||
} | ||
SelectAllAction.create = create; | ||
})(SelectAllAction = exports.SelectAllAction || (exports.SelectAllAction = {})); | ||
//# sourceMappingURL=element-selection.js.map |
@@ -1,36 +0,82 @@ | ||
import { Action, Operation, RequestAction, ResponseAction } from './base-protocol'; | ||
import { Operation, RequestAction, ResponseAction } from './base-protocol'; | ||
import { Args } from './types'; | ||
/** | ||
* Requests the validation of the given text in the context of the provided model element. Typically sent from the client to the server. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `NewActions`. | ||
*/ | ||
export declare class RequestEditValidationAction implements RequestAction<SetEditValidationResultAction> { | ||
readonly contextId: string; | ||
readonly modelElementId: string; | ||
readonly text: string; | ||
readonly requestId: string; | ||
readonly kind: string; | ||
static readonly KIND = "requestEditValidation"; | ||
constructor(contextId: string, modelElementId: string, text: string, requestId?: string, kind?: string); | ||
export interface RequestEditValidationAction extends RequestAction<SetEditValidationResultAction> { | ||
kind: typeof RequestEditValidationAction.KIND; | ||
/** | ||
* Context in which the text is validated, e.g., 'label-edit'. | ||
*/ | ||
contextId: string; | ||
/** | ||
* Model element that is being edited. | ||
*/ | ||
modelElementId: string; | ||
/** | ||
* Text that should be validated for the given context and the model element. | ||
*/ | ||
text: string; | ||
} | ||
export declare function isRequestEditValidationAction(action: any): action is RequestEditValidationAction; | ||
export declare namespace RequestEditValidationAction { | ||
const KIND = "requestEditValidation"; | ||
function is(object: any): object is RequestEditValidationAction; | ||
function create(options: { | ||
contextId: string; | ||
modelElementId: string; | ||
text: string; | ||
requestId?: string; | ||
}): RequestEditValidationAction; | ||
} | ||
/** | ||
* Response to a {@link RequestEditValidationAction} containing the validation result for applying a text on a certain model element. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetEditValidationResultActions`. | ||
*/ | ||
export declare class SetEditValidationResultAction implements ResponseAction { | ||
readonly status: ValidationStatus; | ||
readonly responseId: string; | ||
readonly args?: Args | undefined; | ||
readonly kind: string; | ||
static readonly KIND = "setEditValidationResult"; | ||
constructor(status: ValidationStatus, responseId?: string, args?: Args | undefined, kind?: string); | ||
export interface SetEditValidationResultAction extends ResponseAction { | ||
kind: typeof SetEditValidationResultAction.KIND; | ||
status: ValidationStatus; | ||
args?: Args; | ||
} | ||
export declare function isSetEditValidationResultAction(action: Action): action is SetEditValidationResultAction; | ||
export declare class ApplyLabelEditOperation implements Operation { | ||
readonly labelId: string; | ||
readonly text: string; | ||
static KIND: string; | ||
kind: string; | ||
constructor(labelId: string, text: string); | ||
export declare namespace SetEditValidationResultAction { | ||
const KIND = "setEditValidationResult"; | ||
function is(object: any): object is SetEditValidationResultAction; | ||
function create(status: ValidationStatus, options?: { | ||
args?: Args; | ||
responseId?: string; | ||
}): SetEditValidationResultAction; | ||
} | ||
export declare function isApplyLabelEditOperation(action: any): action is ApplyLabelEditOperation; | ||
/** | ||
* A very common use case in domain models is the support of labels that display textual information to the user. | ||
* To apply new text to such a label element the client may send an ApplyLabelEditOperation to the server. Typically this is | ||
* done by the client after it has received a error free validation result via {@link SetEditValidationResultAction} from the server. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `ApplyLabelEditOperations`. | ||
*/ | ||
export interface ApplyLabelEditOperation extends Operation { | ||
kind: typeof ApplyLabelEditOperation.KIND; | ||
/** | ||
* Identifier of the label model element. | ||
*/ | ||
labelId: string; | ||
/** | ||
* Text that should be applied on the label. | ||
*/ | ||
text: string; | ||
} | ||
export declare namespace ApplyLabelEditOperation { | ||
const KIND = "applyLabelEdit"; | ||
function is(object: any): object is ApplyLabelEditOperation; | ||
function create(options: { | ||
labelId: string; | ||
text: string; | ||
}): ApplyLabelEditOperation; | ||
} | ||
/** | ||
* The serializable result of an an validation request. | ||
* Tje corresponding namespace offers the default severity values | ||
* and other utility functions. | ||
*/ | ||
export interface ValidationStatus { | ||
@@ -50,17 +96,6 @@ /** | ||
} | ||
export interface ResponseError { | ||
export declare namespace ValidationStatus { | ||
/** | ||
* Code identifying the error kind. | ||
* The default {@link ValidationStatus} severity levels used in GLSP. | ||
*/ | ||
readonly code: number; | ||
/** | ||
* Error message. | ||
*/ | ||
readonly message: string; | ||
/** | ||
* Additional custom data, e.g., a serialized stacktrace. | ||
*/ | ||
readonly data: Record<string, any>; | ||
} | ||
export declare namespace ValidationStatus { | ||
enum Severity { | ||
@@ -74,7 +109,45 @@ FATAL = 0, | ||
} | ||
/** | ||
* An empty {@link ValidationStatus}. | ||
*/ | ||
const NONE: ValidationStatus; | ||
/** | ||
* Utility function to check wether the given {@link ValidationStatus} has | ||
* a severity that is considered to be OK. | ||
* @param validationStatus The validation status to check. | ||
* @returns `true` if the given status has a non critical severity, `false` otherwise. | ||
*/ | ||
function isOk(validationStatus: ValidationStatus): boolean; | ||
/** | ||
* Utility function to check wether the given {@link ValidationStatus} has | ||
* a `warning` severity. | ||
* @param validationStatus The validation status to check. | ||
* @returns `true` if the given status has a `warning` severity, `false` otherwise. | ||
*/ | ||
function isWarning(validationStatus: ValidationStatus): boolean; | ||
/** | ||
* Utility function to check wether the given {@link ValidationStatus} has | ||
* an `error` or `fatal` severity. | ||
* @param validationStatus The validation status to check. | ||
* @returns `true` if the given status has a `error` or `fatal` severity, `false` otherwise. | ||
*/ | ||
function isError(validationStatus: ValidationStatus): boolean; | ||
} | ||
/** | ||
* The serializable format of an error that occurred during validation. | ||
*/ | ||
export interface ResponseError { | ||
/** | ||
* Code identifying the error kind. | ||
*/ | ||
readonly code: number; | ||
/** | ||
* Error message. | ||
*/ | ||
readonly message: string; | ||
/** | ||
* Additional custom data, e.g., a serialized stacktrace. | ||
*/ | ||
readonly data: Record<string, any>; | ||
} | ||
//# sourceMappingURL=element-text-editing.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ValidationStatus = exports.isApplyLabelEditOperation = exports.ApplyLabelEditOperation = exports.isSetEditValidationResultAction = exports.SetEditValidationResultAction = exports.isRequestEditValidationAction = exports.RequestEditValidationAction = void 0; | ||
exports.ValidationStatus = exports.ApplyLabelEditOperation = exports.SetEditValidationResultAction = exports.RequestEditValidationAction = void 0; | ||
/******************************************************************************** | ||
* Copyright (c) 2020-2021 EclipseSource and others. | ||
* Copyright (c) 2020-2022 EclipseSource and others. | ||
* | ||
@@ -19,58 +19,48 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
const typeguard_util_1 = require("../utils/typeguard-util"); | ||
const type_util_1 = require("../utils/type-util"); | ||
const base_protocol_1 = require("./base-protocol"); | ||
/** | ||
* Requests the validation of the given text in the context of the provided model element. Typically sent from the client to the server. | ||
*/ | ||
class RequestEditValidationAction { | ||
constructor(contextId, modelElementId, text, requestId = base_protocol_1.generateRequestId(), kind = RequestEditValidationAction.KIND) { | ||
this.contextId = contextId; | ||
this.modelElementId = modelElementId; | ||
this.text = text; | ||
this.requestId = requestId; | ||
this.kind = kind; | ||
var RequestEditValidationAction; | ||
(function (RequestEditValidationAction) { | ||
RequestEditValidationAction.KIND = 'requestEditValidation'; | ||
function is(object) { | ||
return (base_protocol_1.RequestAction.hasKind(object, RequestEditValidationAction.KIND) && | ||
(0, type_util_1.hasStringProp)(object, 'contextId') && | ||
(0, type_util_1.hasStringProp)(object, 'modelElementId') && | ||
(0, type_util_1.hasStringProp)(object, 'text')); | ||
} | ||
} | ||
exports.RequestEditValidationAction = RequestEditValidationAction; | ||
RequestEditValidationAction.KIND = 'requestEditValidation'; | ||
function isRequestEditValidationAction(action) { | ||
return (base_protocol_1.isRequestAction(action) && | ||
action.kind === RequestEditValidationAction.KIND && | ||
typeguard_util_1.isString(action, 'contextId') && | ||
typeguard_util_1.isString(action, 'modelElementId') && | ||
typeguard_util_1.isString(action, 'text')); | ||
} | ||
exports.isRequestEditValidationAction = isRequestEditValidationAction; | ||
/** | ||
* Response to a {@link RequestEditValidationAction} containing the validation result for applying a text on a certain model element. | ||
*/ | ||
class SetEditValidationResultAction { | ||
constructor(status, responseId = '', args, kind = SetEditValidationResultAction.KIND) { | ||
this.status = status; | ||
this.responseId = responseId; | ||
this.args = args; | ||
this.kind = kind; | ||
RequestEditValidationAction.is = is; | ||
function create(options) { | ||
return Object.assign({ kind: RequestEditValidationAction.KIND, requestId: '' }, options); | ||
} | ||
} | ||
exports.SetEditValidationResultAction = SetEditValidationResultAction; | ||
SetEditValidationResultAction.KIND = 'setEditValidationResult'; | ||
function isSetEditValidationResultAction(action) { | ||
return base_protocol_1.isActionKind(action, SetEditValidationResultAction.KIND) && typeguard_util_1.isObject(action, 'status') && typeguard_util_1.isString(action, 'responseId'); | ||
} | ||
exports.isSetEditValidationResultAction = isSetEditValidationResultAction; | ||
class ApplyLabelEditOperation { | ||
constructor(labelId, text) { | ||
this.labelId = labelId; | ||
this.text = text; | ||
this.kind = ApplyLabelEditOperation.KIND; | ||
RequestEditValidationAction.create = create; | ||
})(RequestEditValidationAction = exports.RequestEditValidationAction || (exports.RequestEditValidationAction = {})); | ||
var SetEditValidationResultAction; | ||
(function (SetEditValidationResultAction) { | ||
SetEditValidationResultAction.KIND = 'setEditValidationResult'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, SetEditValidationResultAction.KIND) && (0, type_util_1.hasObjectProp)(object, 'status'); | ||
} | ||
} | ||
exports.ApplyLabelEditOperation = ApplyLabelEditOperation; | ||
ApplyLabelEditOperation.KIND = 'applyLabelEdit'; | ||
function isApplyLabelEditOperation(action) { | ||
return base_protocol_1.isActionKind(action, ApplyLabelEditOperation.KIND) && typeguard_util_1.isString(action, 'labelId') && typeguard_util_1.isString(action, 'text'); | ||
} | ||
exports.isApplyLabelEditOperation = isApplyLabelEditOperation; | ||
SetEditValidationResultAction.is = is; | ||
function create(status, options = {}) { | ||
return Object.assign({ kind: SetEditValidationResultAction.KIND, responseId: '', status }, options); | ||
} | ||
SetEditValidationResultAction.create = create; | ||
})(SetEditValidationResultAction = exports.SetEditValidationResultAction || (exports.SetEditValidationResultAction = {})); | ||
var ApplyLabelEditOperation; | ||
(function (ApplyLabelEditOperation) { | ||
ApplyLabelEditOperation.KIND = 'applyLabelEdit'; | ||
function is(object) { | ||
return base_protocol_1.Operation.hasKind(object, ApplyLabelEditOperation.KIND) && (0, type_util_1.hasStringProp)(object, 'labelId') && (0, type_util_1.hasStringProp)(object, 'text'); | ||
} | ||
ApplyLabelEditOperation.is = is; | ||
function create(options) { | ||
return Object.assign({ kind: ApplyLabelEditOperation.KIND, isOperation: true }, options); | ||
} | ||
ApplyLabelEditOperation.create = create; | ||
})(ApplyLabelEditOperation = exports.ApplyLabelEditOperation || (exports.ApplyLabelEditOperation = {})); | ||
var ValidationStatus; | ||
(function (ValidationStatus) { | ||
/** | ||
* The default {@link ValidationStatus} severity levels used in GLSP. | ||
*/ | ||
// eslint-disable-next-line no-shadow | ||
@@ -87,2 +77,5 @@ let Severity; | ||
})(Severity = ValidationStatus.Severity || (ValidationStatus.Severity = {})); | ||
/** | ||
* An empty {@link ValidationStatus}. | ||
*/ | ||
ValidationStatus.NONE = { | ||
@@ -93,2 +86,8 @@ severity: Severity.NONE, | ||
}; | ||
/** | ||
* Utility function to check wether the given {@link ValidationStatus} has | ||
* a severity that is considered to be OK. | ||
* @param validationStatus The validation status to check. | ||
* @returns `true` if the given status has a non critical severity, `false` otherwise. | ||
*/ | ||
function isOk(validationStatus) { | ||
@@ -100,2 +99,8 @@ return (validationStatus.severity === Severity.OK || | ||
ValidationStatus.isOk = isOk; | ||
/** | ||
* Utility function to check wether the given {@link ValidationStatus} has | ||
* a `warning` severity. | ||
* @param validationStatus The validation status to check. | ||
* @returns `true` if the given status has a `warning` severity, `false` otherwise. | ||
*/ | ||
function isWarning(validationStatus) { | ||
@@ -105,2 +110,8 @@ return validationStatus.severity === Severity.WARNING; | ||
ValidationStatus.isWarning = isWarning; | ||
/** | ||
* Utility function to check wether the given {@link ValidationStatus} has | ||
* an `error` or `fatal` severity. | ||
* @param validationStatus The validation status to check. | ||
* @returns `true` if the given status has a `error` or `fatal` severity, `false` otherwise. | ||
*/ | ||
function isError(validationStatus) { | ||
@@ -107,0 +118,0 @@ return validationStatus.severity === Severity.ERROR || validationStatus.severity === Severity.FATAL; |
/******************************************************************************** | ||
* Copyright (c) 2019-2021 EclipseSource and others. | ||
* Copyright (c) 2019-2022 EclipseSource and others. | ||
* | ||
@@ -16,3 +16,7 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import { RequestAction, ResponseAction } from '.'; | ||
import { RequestAction, ResponseAction } from './base-protocol'; | ||
/** | ||
* Type hints are used to define what modifications are supported on the different element types. | ||
* The rationale is to avoid a client-server round-trip for user feedback of each synchronous user interaction. | ||
*/ | ||
export interface TypeHint { | ||
@@ -32,2 +36,5 @@ /** | ||
} | ||
/** | ||
* A {@link TypeHint} with additional modification properties for shape elements. | ||
*/ | ||
export interface ShapeTypeHint extends TypeHint { | ||
@@ -47,2 +54,5 @@ /** | ||
} | ||
/** | ||
* A {@link TypeHint} with additional modification properties for edge elements. | ||
*/ | ||
export interface EdgeTypeHint extends TypeHint { | ||
@@ -66,22 +76,34 @@ /** | ||
* receiving the model via RequestModelAction. The response is a {@link SetTypeHintsAction}. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `RequestTypeHintsActions`. | ||
*/ | ||
export declare class RequestTypeHintsAction implements RequestAction<SetTypeHintsAction> { | ||
readonly requestId: string; | ||
readonly kind: string; | ||
static readonly KIND = "requestTypeHints"; | ||
constructor(requestId?: string, kind?: string); | ||
export interface RequestTypeHintsAction extends RequestAction<SetTypeHintsAction> { | ||
kind: typeof RequestTypeHintsAction.KIND; | ||
} | ||
export declare function isRequestTypeHintsAction(action: any): action is RequestTypeHintsAction; | ||
export declare namespace RequestTypeHintsAction { | ||
const KIND = "requestTypeHints"; | ||
function is(object: any): object is RequestTypeHintsAction; | ||
function create(options?: { | ||
requestId?: string; | ||
}): RequestTypeHintsAction; | ||
} | ||
/** | ||
* Sent from the server to the client in order to provide hints certain modifications are allowed for a specific element type. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetTypeHintsActions`. | ||
*/ | ||
export declare class SetTypeHintsAction implements ResponseAction { | ||
readonly shapeHints: ShapeTypeHint[]; | ||
readonly edgeHints: EdgeTypeHint[]; | ||
readonly responseId: string; | ||
readonly kind: string; | ||
static readonly KIND = "setTypeHints"; | ||
constructor(shapeHints: ShapeTypeHint[], edgeHints: EdgeTypeHint[], responseId?: string, kind?: string); | ||
export interface SetTypeHintsAction extends ResponseAction { | ||
kind: typeof SetTypeHintsAction.KIND; | ||
shapeHints: ShapeTypeHint[]; | ||
edgeHints: EdgeTypeHint[]; | ||
} | ||
export declare function isSetTypeHintsAction(action: any): action is SetTypeHintsAction; | ||
export declare namespace SetTypeHintsAction { | ||
const KIND = "setTypeHints"; | ||
function is(object: any): object is SetTypeHintsAction; | ||
function create(options: { | ||
shapeHints: ShapeTypeHint[]; | ||
edgeHints: EdgeTypeHint[]; | ||
responseId?: string; | ||
}): SetTypeHintsAction; | ||
} | ||
//# sourceMappingURL=element-type-hints.d.ts.map |
"use strict"; | ||
/******************************************************************************** | ||
* Copyright (c) 2019-2022 EclipseSource and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isSetTypeHintsAction = exports.SetTypeHintsAction = exports.isRequestTypeHintsAction = exports.RequestTypeHintsAction = void 0; | ||
const typeguard_util_1 = require("../utils/typeguard-util"); | ||
exports.SetTypeHintsAction = exports.RequestTypeHintsAction = void 0; | ||
const type_util_1 = require("../utils/type-util"); | ||
const base_protocol_1 = require("./base-protocol"); | ||
/** | ||
* Sent from the client to the server in order to request hints on whether certain modifications are allowed for a specific element type. | ||
* The `RequestTypeHintsAction` is optional, but should usually be among the first messages sent from the client to the server after | ||
* receiving the model via RequestModelAction. The response is a {@link SetTypeHintsAction}. | ||
*/ | ||
class RequestTypeHintsAction { | ||
constructor(requestId = '', kind = RequestTypeHintsAction.KIND) { | ||
this.requestId = requestId; | ||
this.kind = kind; | ||
var RequestTypeHintsAction; | ||
(function (RequestTypeHintsAction) { | ||
RequestTypeHintsAction.KIND = 'requestTypeHints'; | ||
function is(object) { | ||
return base_protocol_1.RequestAction.hasKind(object, RequestTypeHintsAction.KIND); | ||
} | ||
} | ||
exports.RequestTypeHintsAction = RequestTypeHintsAction; | ||
RequestTypeHintsAction.KIND = 'requestTypeHints'; | ||
function isRequestTypeHintsAction(action) { | ||
return base_protocol_1.isActionKind(action, RequestTypeHintsAction.KIND); | ||
} | ||
exports.isRequestTypeHintsAction = isRequestTypeHintsAction; | ||
/** | ||
* Sent from the server to the client in order to provide hints certain modifications are allowed for a specific element type. | ||
*/ | ||
class SetTypeHintsAction { | ||
constructor(shapeHints, edgeHints, responseId = '', kind = SetTypeHintsAction.KIND) { | ||
this.shapeHints = shapeHints; | ||
this.edgeHints = edgeHints; | ||
this.responseId = responseId; | ||
this.kind = kind; | ||
RequestTypeHintsAction.is = is; | ||
function create(options = {}) { | ||
return Object.assign({ kind: RequestTypeHintsAction.KIND, requestId: '' }, options); | ||
} | ||
} | ||
exports.SetTypeHintsAction = SetTypeHintsAction; | ||
SetTypeHintsAction.KIND = 'setTypeHints'; | ||
function isSetTypeHintsAction(action) { | ||
return base_protocol_1.isActionKind(action, SetTypeHintsAction.KIND) && typeguard_util_1.isArray(action, 'shapeHints') && typeguard_util_1.isArray(action, 'edgeHints'); | ||
} | ||
exports.isSetTypeHintsAction = isSetTypeHintsAction; | ||
RequestTypeHintsAction.create = create; | ||
})(RequestTypeHintsAction = exports.RequestTypeHintsAction || (exports.RequestTypeHintsAction = {})); | ||
var SetTypeHintsAction; | ||
(function (SetTypeHintsAction) { | ||
SetTypeHintsAction.KIND = 'setTypeHints'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, SetTypeHintsAction.KIND) && (0, type_util_1.hasArrayProp)(object, 'shapeHints') && (0, type_util_1.hasArrayProp)(object, 'edgeHints'); | ||
} | ||
SetTypeHintsAction.is = is; | ||
function create(options) { | ||
return Object.assign({ kind: SetTypeHintsAction.KIND, responseId: '' }, options); | ||
} | ||
SetTypeHintsAction.create = create; | ||
})(SetTypeHintsAction = exports.SetTypeHintsAction || (exports.SetTypeHintsAction = {})); | ||
//# sourceMappingURL=element-type-hints.js.map |
@@ -1,3 +0,2 @@ | ||
import { RequestAction, ResponseAction } from '.'; | ||
import { Action } from './base-protocol'; | ||
import { Action, RequestAction, ResponseAction } from './base-protocol'; | ||
/** | ||
@@ -24,2 +23,5 @@ * Validation in GLSP is performed by using validation markers. A marker represents the validation result for a single model element | ||
} | ||
/** | ||
* The default marker kinds used in GLSP | ||
*/ | ||
export declare namespace MarkerKind { | ||
@@ -32,32 +34,57 @@ const INFO = "info"; | ||
* Action to retrieve markers for the specified model elements. Sent from the client to the server. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `RequestMarkersActions`. | ||
*/ | ||
export declare class RequestMarkersAction implements RequestAction<SetMarkersAction> { | ||
readonly elementsIDs: string[]; | ||
readonly requestId: string; | ||
readonly kind: string; | ||
static readonly KIND = "requestMarkers"; | ||
constructor(elementsIDs?: string[], requestId?: string, kind?: string); | ||
export interface RequestMarkersAction extends RequestAction<SetMarkersAction> { | ||
kind: typeof RequestMarkersAction.KIND; | ||
/** | ||
* The elements for which markers are requested, may be just the root element. | ||
*/ | ||
elementsIDs: string[]; | ||
} | ||
export declare function isRequestMarkersAction(action: any): action is RequestMarkersAction; | ||
export declare namespace RequestMarkersAction { | ||
const KIND = "requestMarkers"; | ||
function is(object: any): object is RequestMarkersAction; | ||
function create(elementsIDs: string[], options?: { | ||
requestId?: string; | ||
}): RequestMarkersAction; | ||
} | ||
/** | ||
* Response to the {@link RequestMarkersAction} containing all validation markers. Sent from the server to the client. | ||
* Instructs the client to add markers to the diagram. | ||
* Typically, this is a response to the {@link RequestMarkersAction} containing all validation markers, but can be sent by the server at | ||
* any time. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetMarkersActions`. | ||
*/ | ||
export declare class SetMarkersAction implements ResponseAction { | ||
export interface SetMarkersAction extends ResponseAction { | ||
kind: typeof SetMarkersAction.KIND; | ||
/** | ||
* The list of markers to be added to the diagram. | ||
*/ | ||
readonly markers: Marker[]; | ||
readonly responseId: string; | ||
readonly kind: string; | ||
static readonly KIND = "setMarkers"; | ||
constructor(markers: Marker[], responseId?: string, kind?: string); | ||
} | ||
export declare function isSetMarkersAction(action: any): action is SetMarkersAction; | ||
export declare namespace SetMarkersAction { | ||
const KIND = "setMarkers"; | ||
function is(object: any): object is SetMarkersAction; | ||
function create(markers: Marker[], options?: { | ||
responseId?: string; | ||
}): SetMarkersAction; | ||
} | ||
/** | ||
* Action for clearing makers of a model | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `DeleteMarkersActions`. Can be sent by either the client or the server. | ||
*/ | ||
export declare class DeleteMarkersAction implements Action { | ||
readonly markers: Marker[]; | ||
readonly kind: string; | ||
static readonly KIND = "deleteMarkers"; | ||
constructor(markers: Marker[], kind?: string); | ||
export interface DeleteMarkersAction extends Action { | ||
kind: typeof DeleteMarkersAction.KIND; | ||
/** | ||
* The list of markers that has been requested by the `RequestMarkersAction`. | ||
*/ | ||
markers: Marker[]; | ||
} | ||
export declare function isDeleteMarkersAction(action: any): action is DeleteMarkersAction; | ||
export declare namespace DeleteMarkersAction { | ||
const KIND = "deleteMarkers"; | ||
function is(object: any): object is DeleteMarkersAction; | ||
function create(markers: Marker[]): DeleteMarkersAction; | ||
} | ||
//# sourceMappingURL=element-validation.d.ts.map |
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
var DeleteMarkersAction_1; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isDeleteMarkersAction = exports.DeleteMarkersAction = exports.isSetMarkersAction = exports.SetMarkersAction = exports.isRequestMarkersAction = exports.RequestMarkersAction = exports.MarkerKind = void 0; | ||
exports.DeleteMarkersAction = exports.SetMarkersAction = exports.RequestMarkersAction = exports.MarkerKind = void 0; | ||
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -29,5 +19,7 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
const inversify_1 = require("inversify"); | ||
const typeguard_util_1 = require("../utils/typeguard-util"); | ||
const type_util_1 = require("../utils/type-util"); | ||
const base_protocol_1 = require("./base-protocol"); | ||
/** | ||
* The default marker kinds used in GLSP | ||
*/ | ||
var MarkerKind; | ||
@@ -39,53 +31,41 @@ (function (MarkerKind) { | ||
})(MarkerKind = exports.MarkerKind || (exports.MarkerKind = {})); | ||
/** | ||
* Action to retrieve markers for the specified model elements. Sent from the client to the server. | ||
*/ | ||
class RequestMarkersAction { | ||
constructor(elementsIDs = [], requestId = '', kind = RequestMarkersAction.KIND) { | ||
this.elementsIDs = elementsIDs; | ||
this.requestId = requestId; | ||
this.kind = kind; | ||
var RequestMarkersAction; | ||
(function (RequestMarkersAction) { | ||
RequestMarkersAction.KIND = 'requestMarkers'; | ||
function is(object) { | ||
return base_protocol_1.RequestAction.hasKind(object, RequestMarkersAction.KIND) && (0, type_util_1.hasArrayProp)(object, 'elementsIDs'); | ||
} | ||
} | ||
exports.RequestMarkersAction = RequestMarkersAction; | ||
RequestMarkersAction.KIND = 'requestMarkers'; | ||
function isRequestMarkersAction(action) { | ||
return base_protocol_1.isActionKind(action, RequestMarkersAction.KIND) && typeguard_util_1.isArray(action, 'elementsIDs'); | ||
} | ||
exports.isRequestMarkersAction = isRequestMarkersAction; | ||
/** | ||
* Response to the {@link RequestMarkersAction} containing all validation markers. Sent from the server to the client. | ||
*/ | ||
class SetMarkersAction { | ||
constructor(markers, responseId = '', kind = SetMarkersAction.KIND) { | ||
this.markers = markers; | ||
this.responseId = responseId; | ||
this.kind = kind; | ||
RequestMarkersAction.is = is; | ||
function create(elementsIDs, options = {}) { | ||
return Object.assign({ kind: RequestMarkersAction.KIND, requestId: '', elementsIDs }, options); | ||
} | ||
} | ||
exports.SetMarkersAction = SetMarkersAction; | ||
SetMarkersAction.KIND = 'setMarkers'; | ||
function isSetMarkersAction(action) { | ||
return base_protocol_1.isActionKind(action, SetMarkersAction.KIND) && typeguard_util_1.isArray(action, 'markers'); | ||
} | ||
exports.isSetMarkersAction = isSetMarkersAction; | ||
/** | ||
* Action for clearing makers of a model | ||
*/ | ||
let DeleteMarkersAction = DeleteMarkersAction_1 = class DeleteMarkersAction { | ||
constructor(markers, kind = DeleteMarkersAction_1.KIND) { | ||
this.markers = markers; | ||
this.kind = kind; | ||
RequestMarkersAction.create = create; | ||
})(RequestMarkersAction = exports.RequestMarkersAction || (exports.RequestMarkersAction = {})); | ||
var SetMarkersAction; | ||
(function (SetMarkersAction) { | ||
SetMarkersAction.KIND = 'setMarkers'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, SetMarkersAction.KIND) && (0, type_util_1.hasArrayProp)(object, 'markers'); | ||
} | ||
}; | ||
DeleteMarkersAction.KIND = 'deleteMarkers'; | ||
DeleteMarkersAction = DeleteMarkersAction_1 = __decorate([ | ||
inversify_1.injectable(), | ||
__metadata("design:paramtypes", [Array, Object]) | ||
], DeleteMarkersAction); | ||
exports.DeleteMarkersAction = DeleteMarkersAction; | ||
function isDeleteMarkersAction(action) { | ||
return base_protocol_1.isActionKind(action, DeleteMarkersAction.KIND) && typeguard_util_1.isArray(action, 'markers'); | ||
} | ||
exports.isDeleteMarkersAction = isDeleteMarkersAction; | ||
SetMarkersAction.is = is; | ||
function create(markers, options = {}) { | ||
return Object.assign({ kind: SetMarkersAction.KIND, responseId: '', markers }, options); | ||
} | ||
SetMarkersAction.create = create; | ||
})(SetMarkersAction = exports.SetMarkersAction || (exports.SetMarkersAction = {})); | ||
var DeleteMarkersAction; | ||
(function (DeleteMarkersAction) { | ||
DeleteMarkersAction.KIND = 'deleteMarkers'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, DeleteMarkersAction.KIND) && (0, type_util_1.hasArrayProp)(object, 'markers'); | ||
} | ||
DeleteMarkersAction.is = is; | ||
function create(markers) { | ||
return { | ||
kind: DeleteMarkersAction.KIND, | ||
markers | ||
}; | ||
} | ||
DeleteMarkersAction.create = create; | ||
})(DeleteMarkersAction = exports.DeleteMarkersAction || (exports.DeleteMarkersAction = {})); | ||
//# sourceMappingURL=element-validation.js.map |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -28,5 +28,5 @@ * This program and the accompanying materials are made available under the | ||
export * from './element-validation'; | ||
export * from './mode-layout'; | ||
export * from './model-data'; | ||
export * from './model-edit-mode'; | ||
export * from './model-layout'; | ||
export * from './model-saving'; | ||
@@ -33,0 +33,0 @@ export * from './model-structure'; |
@@ -10,7 +10,7 @@ "use strict"; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -41,5 +41,5 @@ * This program and the accompanying materials are made available under the | ||
__exportStar(require("./element-validation"), exports); | ||
__exportStar(require("./mode-layout"), exports); | ||
__exportStar(require("./model-data"), exports); | ||
__exportStar(require("./model-edit-mode"), exports); | ||
__exportStar(require("./model-layout"), exports); | ||
__exportStar(require("./model-saving"), exports); | ||
@@ -46,0 +46,0 @@ __exportStar(require("./model-structure"), exports); |
@@ -0,53 +1,98 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
import * as sprotty from 'sprotty-protocol/lib/actions'; | ||
import { Action, RequestAction, ResponseAction } from './base-protocol'; | ||
import { SModelRootSchema } from './model-structure'; | ||
import { JsonPrimitive } from './types'; | ||
import { Args } from './types'; | ||
/** | ||
* Sent from the server to the client in order to set the model. If a model is already present, it is replaced. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `RequestModelActions`. | ||
*/ | ||
export declare class RequestModelAction implements RequestAction<SetModelAction> { | ||
readonly options?: { | ||
[key: string]: JsonPrimitive; | ||
} | undefined; | ||
readonly requestId: string; | ||
static readonly KIND = "requestModel"; | ||
readonly kind = "requestModel"; | ||
constructor(options?: { | ||
[key: string]: JsonPrimitive; | ||
} | undefined, requestId?: string); | ||
/** Factory function to dispatch a request with the `IActionDispatcher` */ | ||
static create(options?: { | ||
[key: string]: JsonPrimitive; | ||
}): RequestAction<SetModelAction>; | ||
export interface RequestModelAction extends RequestAction<SetModelAction>, sprotty.RequestModelAction { | ||
kind: typeof RequestModelAction.KIND; | ||
/** | ||
* Additional options used to compute the graphical model. | ||
*/ | ||
options?: Args; | ||
} | ||
export declare function isRequestModelAction(action: any): action is RequestModelAction; | ||
export declare namespace RequestModelAction { | ||
const KIND = "requestModel"; | ||
function is(object: any): object is RequestModelAction; | ||
function create(options?: { | ||
options?: Args; | ||
requestId?: string; | ||
}): RequestModelAction; | ||
} | ||
/** | ||
* Sent from the model source to the client in order to set the model. If a model is already present, it is replaced. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetModelActions`. | ||
*/ | ||
export declare class SetModelAction implements ResponseAction { | ||
readonly newRoot: SModelRootSchema; | ||
readonly responseId: string; | ||
static readonly KIND = "setModel"; | ||
readonly kind = "setModel"; | ||
constructor(newRoot: SModelRootSchema, responseId?: string); | ||
export interface SetModelAction extends ResponseAction, sprotty.SetModelAction { | ||
kind: typeof SetModelAction.KIND; | ||
/** | ||
* The new graphical model root. | ||
*/ | ||
newRoot: SModelRootSchema; | ||
} | ||
export declare function isSetModelAction(action: any): action is SetModelAction; | ||
export declare namespace SetModelAction { | ||
const KIND = "setModel"; | ||
function is(object: any): object is SetModelAction; | ||
function create(newRoot: SModelRootSchema, options?: { | ||
responseId?: string; | ||
}): SetModelAction; | ||
} | ||
/** | ||
* Sent from the server to the client in order to update the model. If no model is present yet, this behaves the same as a SetModelAction. | ||
* The transition from the old model to the new one can be animated. | ||
* Sent from the server to the client in order to update the model. If no model is present yet, this behaves the same as | ||
* a {@link SetModelAction}. The transition from the old model to the new one can be animated. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `UpdateModelActions`. | ||
*/ | ||
export declare class UpdateModelAction implements Action { | ||
readonly newRoot: SModelRootSchema; | ||
readonly animate: boolean; | ||
static readonly KIND = "updateModel"; | ||
readonly kind = "updateModel"; | ||
constructor(newRoot: SModelRootSchema, animate?: boolean); | ||
export interface UpdateModelAction extends Action, Omit<sprotty.UpdateModelAction, 'matches' | 'cause'> { | ||
kind: typeof UpdateModelAction.KIND; | ||
newRoot: SModelRootSchema; | ||
/** | ||
* Boolean flag to indicate wether updated/changed elements should be animated in the diagram. | ||
*/ | ||
animate?: boolean; | ||
} | ||
export declare function isUpdateModelAction(action: any): action is UpdateModelAction; | ||
export declare class ModelSourceChangedAction implements Action { | ||
readonly modelSourceName: string; | ||
static KIND: string; | ||
readonly kind: string; | ||
constructor(modelSourceName: string); | ||
export declare namespace UpdateModelAction { | ||
const KIND = "updateModel"; | ||
function is(action: any): action is UpdateModelAction; | ||
function create(newRoot: SModelRootSchema, options?: { | ||
animate?: boolean; | ||
}): UpdateModelAction; | ||
} | ||
export declare function isModelSourceChangedAction(action?: any): action is ModelSourceChangedAction; | ||
/** | ||
* Sent from the server to the client in order to indicate that the model source has changed. | ||
* The model source denotes the data source from which the diagram has been originally derived (such as a file, a database, etc.). | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `ModelSourceChangedActions`. | ||
*/ | ||
export interface ModelSourceChangedAction extends Action { | ||
kind: typeof ModelSourceChangedAction.KIND; | ||
/** | ||
* A human readable name of the model source (e.g. the file name). | ||
*/ | ||
modelSourceName: string; | ||
} | ||
export declare namespace ModelSourceChangedAction { | ||
const KIND = "modelSourceChanged"; | ||
function is(object: any): object is ModelSourceChangedAction; | ||
function create(modelSourceName: string): ModelSourceChangedAction; | ||
} | ||
//# sourceMappingURL=model-data.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isModelSourceChangedAction = exports.ModelSourceChangedAction = exports.isUpdateModelAction = exports.UpdateModelAction = exports.isSetModelAction = exports.SetModelAction = exports.isRequestModelAction = exports.RequestModelAction = void 0; | ||
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
const typeguard_util_1 = require("../utils/typeguard-util"); | ||
exports.ModelSourceChangedAction = exports.UpdateModelAction = exports.SetModelAction = exports.RequestModelAction = void 0; | ||
const type_util_1 = require("../utils/type-util"); | ||
const base_protocol_1 = require("./base-protocol"); | ||
/** | ||
* Sent from the server to the client in order to set the model. If a model is already present, it is replaced. | ||
*/ | ||
class RequestModelAction { | ||
constructor(options, requestId = '') { | ||
this.options = options; | ||
this.requestId = requestId; | ||
this.kind = RequestModelAction.KIND; | ||
var RequestModelAction; | ||
(function (RequestModelAction) { | ||
RequestModelAction.KIND = 'requestModel'; | ||
function is(object) { | ||
return base_protocol_1.RequestAction.hasKind(object, RequestModelAction.KIND); | ||
} | ||
/** Factory function to dispatch a request with the `IActionDispatcher` */ | ||
static create(options) { | ||
return new RequestModelAction(options, base_protocol_1.generateRequestId()); | ||
RequestModelAction.is = is; | ||
function create(options = {}) { | ||
return Object.assign({ kind: RequestModelAction.KIND, requestId: '' }, options); | ||
} | ||
} | ||
exports.RequestModelAction = RequestModelAction; | ||
RequestModelAction.KIND = 'requestModel'; | ||
function isRequestModelAction(action) { | ||
return base_protocol_1.isActionKind(action, RequestModelAction.KIND); | ||
} | ||
exports.isRequestModelAction = isRequestModelAction; | ||
/** | ||
* Sent from the model source to the client in order to set the model. If a model is already present, it is replaced. | ||
*/ | ||
class SetModelAction { | ||
constructor(newRoot, responseId = '') { | ||
this.newRoot = newRoot; | ||
this.responseId = responseId; | ||
this.kind = SetModelAction.KIND; | ||
RequestModelAction.create = create; | ||
})(RequestModelAction = exports.RequestModelAction || (exports.RequestModelAction = {})); | ||
var SetModelAction; | ||
(function (SetModelAction) { | ||
SetModelAction.KIND = 'setModel'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, SetModelAction.KIND) && (0, type_util_1.hasObjectProp)(object, 'newRoot'); | ||
} | ||
} | ||
exports.SetModelAction = SetModelAction; | ||
SetModelAction.KIND = 'setModel'; | ||
function isSetModelAction(action) { | ||
return base_protocol_1.isActionKind(action, SetModelAction.KIND) && typeguard_util_1.isObject(action, 'newRoot'); | ||
} | ||
exports.isSetModelAction = isSetModelAction; | ||
/** | ||
* Sent from the server to the client in order to update the model. If no model is present yet, this behaves the same as a SetModelAction. | ||
* The transition from the old model to the new one can be animated. | ||
*/ | ||
class UpdateModelAction { | ||
constructor(newRoot, animate = true) { | ||
this.newRoot = newRoot; | ||
this.animate = animate; | ||
this.kind = UpdateModelAction.KIND; | ||
SetModelAction.is = is; | ||
function create(newRoot, options = {}) { | ||
return Object.assign({ kind: SetModelAction.KIND, responseId: '', newRoot }, options); | ||
} | ||
} | ||
exports.UpdateModelAction = UpdateModelAction; | ||
UpdateModelAction.KIND = 'updateModel'; | ||
function isUpdateModelAction(action) { | ||
return base_protocol_1.isActionKind(action, UpdateModelAction.KIND) && typeguard_util_1.isObject(action, 'newRoot') && typeguard_util_1.isBoolean(action, 'animate'); | ||
} | ||
exports.isUpdateModelAction = isUpdateModelAction; | ||
class ModelSourceChangedAction { | ||
constructor(modelSourceName) { | ||
this.modelSourceName = modelSourceName; | ||
this.kind = ModelSourceChangedAction.KIND; | ||
SetModelAction.create = create; | ||
})(SetModelAction = exports.SetModelAction || (exports.SetModelAction = {})); | ||
var UpdateModelAction; | ||
(function (UpdateModelAction) { | ||
UpdateModelAction.KIND = 'updateModel'; | ||
function is(action) { | ||
return base_protocol_1.Action.hasKind(action, UpdateModelAction.KIND) && (0, type_util_1.hasObjectProp)(action, 'newRoot'); | ||
} | ||
} | ||
exports.ModelSourceChangedAction = ModelSourceChangedAction; | ||
ModelSourceChangedAction.KIND = 'modelSourceChanged'; | ||
function isModelSourceChangedAction(action) { | ||
return base_protocol_1.isActionKind(action, ModelSourceChangedAction.KIND) && typeguard_util_1.isString(action, 'modelSourceName'); | ||
} | ||
exports.isModelSourceChangedAction = isModelSourceChangedAction; | ||
UpdateModelAction.is = is; | ||
function create(newRoot, options = {}) { | ||
return Object.assign({ kind: UpdateModelAction.KIND, newRoot, animate: true }, options); | ||
} | ||
UpdateModelAction.create = create; | ||
})(UpdateModelAction = exports.UpdateModelAction || (exports.UpdateModelAction = {})); | ||
var ModelSourceChangedAction; | ||
(function (ModelSourceChangedAction) { | ||
ModelSourceChangedAction.KIND = 'modelSourceChanged'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, ModelSourceChangedAction.KIND) && (0, type_util_1.hasStringProp)(object, 'modelSourceName'); | ||
} | ||
ModelSourceChangedAction.is = is; | ||
function create(modelSourceName) { | ||
return { | ||
kind: ModelSourceChangedAction.KIND, | ||
modelSourceName | ||
}; | ||
} | ||
ModelSourceChangedAction.create = create; | ||
})(ModelSourceChangedAction = exports.ModelSourceChangedAction || (exports.ModelSourceChangedAction = {})); | ||
//# sourceMappingURL=model-data.js.map |
@@ -1,9 +0,23 @@ | ||
import { Action } from 'sprotty'; | ||
export declare class SetEditModeAction implements Action { | ||
readonly editMode: string; | ||
readonly kind: string; | ||
static readonly KIND = "setEditMode"; | ||
constructor(editMode?: string, kind?: string); | ||
import { Action } from './base-protocol'; | ||
/** | ||
* Sent from the client to the server to set the model into a specific editor mode, allowing the server to react to certain | ||
* requests differently depending on the mode. A client may also listen to this action to prevent certain user interactions preemptively. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetEditModeActions`. | ||
*/ | ||
export interface SetEditModeAction extends Action { | ||
kind: typeof SetEditModeAction.KIND; | ||
/** | ||
* The new edit mode of the diagram. | ||
*/ | ||
editMode: string; | ||
} | ||
export declare function isSetEditModeAction(action: Action): action is SetEditModeAction; | ||
export declare namespace SetEditModeAction { | ||
const KIND = "setEditMode"; | ||
function is(object: any): object is SetEditModeAction; | ||
function create(editMode: string): SetEditModeAction; | ||
} | ||
/** | ||
* The potential default values for the `editMode` property of a {@link SetEditModeAction}. | ||
*/ | ||
export declare namespace EditMode { | ||
@@ -10,0 +24,0 @@ const READONLY = "readonly"; |
"use strict"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
var SetEditModeAction_1; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EditMode = exports.isSetEditModeAction = exports.SetEditModeAction = void 0; | ||
exports.EditMode = exports.SetEditModeAction = void 0; | ||
/******************************************************************************** | ||
* Copyright (c) 2020-2021 EclipseSource and others. | ||
* Copyright (c) 2020-2022 EclipseSource and others. | ||
* | ||
@@ -29,21 +19,22 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
const inversify_1 = require("inversify"); | ||
const typeguard_util_1 = require("../utils/typeguard-util"); | ||
const type_util_1 = require("../utils/type-util"); | ||
const base_protocol_1 = require("./base-protocol"); | ||
let SetEditModeAction = SetEditModeAction_1 = class SetEditModeAction { | ||
constructor(editMode = EditMode.EDITABLE, kind = SetEditModeAction_1.KIND) { | ||
this.editMode = editMode; | ||
this.kind = kind; | ||
var SetEditModeAction; | ||
(function (SetEditModeAction) { | ||
SetEditModeAction.KIND = 'setEditMode'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, SetEditModeAction.KIND) && (0, type_util_1.hasStringProp)(object, 'editMode'); | ||
} | ||
}; | ||
SetEditModeAction.KIND = 'setEditMode'; | ||
SetEditModeAction = SetEditModeAction_1 = __decorate([ | ||
inversify_1.injectable(), | ||
__metadata("design:paramtypes", [String, String]) | ||
], SetEditModeAction); | ||
exports.SetEditModeAction = SetEditModeAction; | ||
function isSetEditModeAction(action) { | ||
return base_protocol_1.isActionKind(action, SetEditModeAction.KIND) && typeguard_util_1.isString(action, 'editMode'); | ||
} | ||
exports.isSetEditModeAction = isSetEditModeAction; | ||
SetEditModeAction.is = is; | ||
function create(editMode) { | ||
return { | ||
kind: SetEditModeAction.KIND, | ||
editMode | ||
}; | ||
} | ||
SetEditModeAction.create = create; | ||
})(SetEditModeAction = exports.SetEditModeAction || (exports.SetEditModeAction = {})); | ||
/** | ||
* The potential default values for the `editMode` property of a {@link SetEditModeAction}. | ||
*/ | ||
var EditMode; | ||
@@ -50,0 +41,0 @@ (function (EditMode) { |
@@ -1,32 +0,81 @@ | ||
import { Action, ResponseAction } from './base-protocol'; | ||
export declare class SaveModelAction implements Action { | ||
readonly fileUri?: string | undefined; | ||
readonly kind: string; | ||
static readonly KIND = "saveModel"; | ||
constructor(fileUri?: string | undefined, kind?: string); | ||
import { Action, RequestAction, ResponseAction } from './base-protocol'; | ||
/** | ||
* Sent from the client to the server in order to persist the current model state back to the model source. | ||
* A new fileUri can be defined to save the model to a new destination different from its original model source. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SaveModelActions`. | ||
*/ | ||
export interface SaveModelAction extends Action { | ||
kind: typeof SaveModelAction.KIND; | ||
/** | ||
* The optional destination file uri. | ||
*/ | ||
fileUri?: string; | ||
} | ||
export declare function isSaveModelAction(action?: any): action is SaveModelAction; | ||
export declare class SetDirtyStateAction implements Action { | ||
readonly isDirty: boolean; | ||
readonly reason?: string | undefined; | ||
readonly kind: string; | ||
static readonly KIND = "setDirtyState"; | ||
constructor(isDirty: boolean, reason?: string | undefined, kind?: string); | ||
export declare namespace SaveModelAction { | ||
const KIND = "saveModel"; | ||
function is(object: any): object is SaveModelAction; | ||
function create(options?: { | ||
fileUri?: string; | ||
}): SaveModelAction; | ||
} | ||
export declare namespace DirtyStateChangeReason { | ||
const OPERATION = "operation"; | ||
const UNDO = "undo"; | ||
const REDO = "redo"; | ||
const SAVE = "save"; | ||
const EXTERNAL = "external"; | ||
/** | ||
* The server sends this action to indicate to the client that the current model state on the server does not correspond | ||
* to the persisted model state of the model source. A client may ignore such an action or use it to indicate to the user the dirty state. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetDirtyStateActions`. | ||
*/ | ||
export interface SetDirtyStateAction extends Action { | ||
kind: typeof SetDirtyStateAction.KIND; | ||
/** | ||
* True if the current model state is dirty | ||
*/ | ||
isDirty: boolean; | ||
/** | ||
* A string indicating the reason for the dirty state change e.g 'operation', 'undo',... | ||
*/ | ||
reason?: DirtyStateChangeReason; | ||
} | ||
export declare function isSetDirtyStateAction(action?: any): action is SetDirtyStateAction; | ||
export declare class ExportSvgAction implements ResponseAction { | ||
readonly svg: string; | ||
readonly responseId: string; | ||
static KIND: string; | ||
kind: string; | ||
constructor(svg: string, responseId?: string); | ||
export declare type DirtyStateChangeReason = 'operation' | 'undo' | 'redo' | 'save' | 'external'; | ||
export declare namespace SetDirtyStateAction { | ||
const KIND = "setDirtyState"; | ||
function is(object: any): object is SetDirtyStateAction; | ||
function create(isDirty: boolean, options?: { | ||
reason?: DirtyStateChangeReason; | ||
}): SetDirtyStateAction; | ||
} | ||
export declare function isExportSvgAction(action?: any): action is ExportSvgAction; | ||
/** | ||
* A `RequestExportSvgAction` is sent by the client (or the server) to initiate the SVG export of the current diagram. | ||
* The handler of this action is expected to retrieve the diagram SVG and should send a {@link ExportSvgAction} as response. | ||
* Typically the {@link ExportSvgAction} is handled directly on client side. | ||
*/ | ||
export interface RequestExportSvgAction extends RequestAction<ExportSvgAction> { | ||
kind: typeof RequestExportSvgAction.KIND; | ||
} | ||
export declare namespace RequestExportSvgAction { | ||
const KIND = "requestExportSvg"; | ||
function is(object: any): object is RequestExportSvgAction; | ||
function create(options?: { | ||
requestId?: string; | ||
}): RequestExportSvgAction; | ||
} | ||
/** | ||
* The client sends an `ExportSvgAction` to indicate that the diagram, which represents the current model state, | ||
* should be exported in SVG format. The action only provides the diagram SVG as plain string. The expected result of executing | ||
* an `ExportSvgAction` is a new file in SVG-format on the underlying filesystem. However, other details like the target destination, | ||
* concrete file name, file extension etc. are not specified in the protocol. So it is the responsibility of the action handler to | ||
* process this information accordingly and export the result to the underlying filesystem. | ||
*/ | ||
export interface ExportSvgAction extends ResponseAction { | ||
kind: typeof ExportSvgAction.KIND; | ||
svg: string; | ||
responseId: string; | ||
} | ||
export declare namespace ExportSvgAction { | ||
const KIND = "exportSvg"; | ||
function is(object: any): object is RequestExportSvgAction; | ||
function create(svg: string, options?: { | ||
responseId?: string; | ||
}): ExportSvgAction; | ||
} | ||
//# sourceMappingURL=model-saving.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isExportSvgAction = exports.ExportSvgAction = exports.isSetDirtyStateAction = exports.DirtyStateChangeReason = exports.SetDirtyStateAction = exports.isSaveModelAction = exports.SaveModelAction = void 0; | ||
exports.ExportSvgAction = exports.RequestExportSvgAction = exports.SetDirtyStateAction = exports.SaveModelAction = void 0; | ||
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -19,50 +19,52 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
const typeguard_util_1 = require("../utils/typeguard-util"); | ||
const type_util_1 = require("../utils/type-util"); | ||
const base_protocol_1 = require("./base-protocol"); | ||
class SaveModelAction { | ||
constructor(fileUri, kind = SaveModelAction.KIND) { | ||
this.fileUri = fileUri; | ||
this.kind = kind; | ||
var SaveModelAction; | ||
(function (SaveModelAction) { | ||
SaveModelAction.KIND = 'saveModel'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, SaveModelAction.KIND); | ||
} | ||
} | ||
exports.SaveModelAction = SaveModelAction; | ||
SaveModelAction.KIND = 'saveModel'; | ||
function isSaveModelAction(action) { | ||
return base_protocol_1.isActionKind(action, SaveModelAction.KIND); | ||
} | ||
exports.isSaveModelAction = isSaveModelAction; | ||
class SetDirtyStateAction { | ||
constructor(isDirty, reason, kind = SetDirtyStateAction.KIND) { | ||
this.isDirty = isDirty; | ||
this.reason = reason; | ||
this.kind = kind; | ||
SaveModelAction.is = is; | ||
function create(options = {}) { | ||
return Object.assign({ kind: SaveModelAction.KIND }, options); | ||
} | ||
} | ||
exports.SetDirtyStateAction = SetDirtyStateAction; | ||
SetDirtyStateAction.KIND = 'setDirtyState'; | ||
var DirtyStateChangeReason; | ||
(function (DirtyStateChangeReason) { | ||
DirtyStateChangeReason.OPERATION = 'operation'; | ||
DirtyStateChangeReason.UNDO = 'undo'; | ||
DirtyStateChangeReason.REDO = 'redo'; | ||
DirtyStateChangeReason.SAVE = 'save'; | ||
DirtyStateChangeReason.EXTERNAL = 'external'; | ||
})(DirtyStateChangeReason = exports.DirtyStateChangeReason || (exports.DirtyStateChangeReason = {})); | ||
function isSetDirtyStateAction(action) { | ||
return base_protocol_1.isActionKind(action, SetDirtyStateAction.KIND) && typeguard_util_1.isBoolean(action, 'isDirty'); | ||
} | ||
exports.isSetDirtyStateAction = isSetDirtyStateAction; | ||
class ExportSvgAction { | ||
constructor(svg, responseId = '') { | ||
this.svg = svg; | ||
this.responseId = responseId; | ||
this.kind = ExportSvgAction.KIND; | ||
SaveModelAction.create = create; | ||
})(SaveModelAction = exports.SaveModelAction || (exports.SaveModelAction = {})); | ||
var SetDirtyStateAction; | ||
(function (SetDirtyStateAction) { | ||
SetDirtyStateAction.KIND = 'setDirtyState'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, SetDirtyStateAction.KIND) && (0, type_util_1.hasBooleanProp)(object, 'isDirty'); | ||
} | ||
} | ||
exports.ExportSvgAction = ExportSvgAction; | ||
ExportSvgAction.KIND = 'exportSvg'; | ||
function isExportSvgAction(action) { | ||
return base_protocol_1.isActionKind(action, ExportSvgAction.KIND) && typeguard_util_1.isString(action, 'svg'); | ||
} | ||
exports.isExportSvgAction = isExportSvgAction; | ||
SetDirtyStateAction.is = is; | ||
function create(isDirty, options = {}) { | ||
return Object.assign({ kind: SetDirtyStateAction.KIND, isDirty }, options); | ||
} | ||
SetDirtyStateAction.create = create; | ||
})(SetDirtyStateAction = exports.SetDirtyStateAction || (exports.SetDirtyStateAction = {})); | ||
var RequestExportSvgAction; | ||
(function (RequestExportSvgAction) { | ||
RequestExportSvgAction.KIND = 'requestExportSvg'; | ||
function is(object) { | ||
return base_protocol_1.RequestAction.hasKind(object, RequestExportSvgAction.KIND); | ||
} | ||
RequestExportSvgAction.is = is; | ||
function create(options = {}) { | ||
return Object.assign({ kind: RequestExportSvgAction.KIND, requestId: '' }, options); | ||
} | ||
RequestExportSvgAction.create = create; | ||
})(RequestExportSvgAction = exports.RequestExportSvgAction || (exports.RequestExportSvgAction = {})); | ||
var ExportSvgAction; | ||
(function (ExportSvgAction) { | ||
ExportSvgAction.KIND = 'exportSvg'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, ExportSvgAction.KIND) && (0, type_util_1.hasStringProp)(object, 'svg'); | ||
} | ||
ExportSvgAction.is = is; | ||
function create(svg, options = {}) { | ||
return Object.assign({ kind: ExportSvgAction.KIND, svg, responseId: '' }, options); | ||
} | ||
ExportSvgAction.create = create; | ||
})(ExportSvgAction = exports.ExportSvgAction || (exports.ExportSvgAction = {})); | ||
//# sourceMappingURL=model-saving.js.map |
@@ -1,14 +0,43 @@ | ||
import { Bounds } from './types'; | ||
/******************************************************************************** | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
import { Bounds } from 'sprotty-protocol'; | ||
import * as sprotty from 'sprotty-protocol/lib/model'; | ||
/** | ||
* The schema of an SModelElement describes its serializable form. The actual model is created from | ||
* its schema with an IModelFactory. | ||
* Each model element must have a unique ID and a type that is used to look up its view. | ||
* The schema of an SModelElement describes its serializable form. The actual class-based model is derived | ||
* its schema whenever the client or server deserializes a received schema`. | ||
* Each model element must have a unique ID and a type that is used on the client to look up its view. | ||
*/ | ||
export interface SModelElementSchema { | ||
export interface SModelElementSchema extends sprotty.SModelElement { | ||
id: string; | ||
/** | ||
* Type to look up the graphical representation of this element. | ||
*/ | ||
type: string; | ||
id: string; | ||
children?: SModelElementSchema[]; | ||
/** | ||
* CSS classes that should be applied on the rendered SVG element representing this element. | ||
*/ | ||
cssClasses?: string[]; | ||
} | ||
export declare function isSModelElementSchema(schema: any): schema is SModelElementSchema; | ||
export declare namespace SModelElementSchema { | ||
/** | ||
* Typeguard function to check wether the given object is an {@link SModelElementSchema}. | ||
* @param object The object to check. | ||
* @returns A type literal indicating wether the given object is of type {@link SModelElementSchema}. | ||
*/ | ||
function is(object: any): object is SModelElementSchema; | ||
} | ||
/** | ||
@@ -18,6 +47,11 @@ * Serializable schema for the root element of the model tree. | ||
export interface SModelRootSchema extends SModelElementSchema { | ||
/** | ||
* Bounds of this element in the canvas. | ||
*/ | ||
canvasBounds?: Bounds; | ||
/** | ||
* The revision number identifies single versions of the models sent by the server. | ||
*/ | ||
revision?: number; | ||
} | ||
export declare function isSModelRootSchema(schema: any): schema is SModelRootSchema; | ||
//# sourceMappingURL=model-structure.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isSModelRootSchema = exports.isSModelElementSchema = void 0; | ||
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
const typeguard_util_1 = require("../utils/typeguard-util"); | ||
function isSModelElementSchema(schema) { | ||
return schema !== undefined && typeof schema === 'object' && typeguard_util_1.isString(schema, 'type') && typeguard_util_1.isString(schema, 'id'); | ||
} | ||
exports.isSModelElementSchema = isSModelElementSchema; | ||
function isSModelRootSchema(schema) { | ||
return isSModelElementSchema(schema) && !('parent' in schema); | ||
} | ||
exports.isSModelRootSchema = isSModelRootSchema; | ||
exports.SModelElementSchema = void 0; | ||
const type_util_1 = require("../utils/type-util"); | ||
var SModelElementSchema; | ||
(function (SModelElementSchema) { | ||
/** | ||
* Typeguard function to check wether the given object is an {@link SModelElementSchema}. | ||
* @param object The object to check. | ||
* @returns A type literal indicating wether the given object is of type {@link SModelElementSchema}. | ||
*/ | ||
function is(object) { | ||
return typeof object === 'object' && (0, type_util_1.hasStringProp)(object, 'type') && (0, type_util_1.hasStringProp)(object, 'id'); | ||
} | ||
SModelElementSchema.is = is; | ||
})(SModelElementSchema = exports.SModelElementSchema || (exports.SModelElementSchema = {})); | ||
//# sourceMappingURL=model-structure.js.map |
/******************************************************************************** | ||
* Copyright (c) 2021 EclipseSource and others. | ||
* Copyright (c) 2021-2022 EclipseSource and others. | ||
* | ||
@@ -16,4 +16,5 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import { Point } from 'sprotty-protocol'; | ||
import { Operation } from './base-protocol'; | ||
import { ElementAndBounds, Point } from './types'; | ||
import { ElementAndBounds } from './types'; | ||
/** | ||
@@ -23,22 +24,44 @@ * Triggers the position or size change of elements. This action concerns only the element's graphical size and position. | ||
* before resizing or repositioning. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `ChangeBoundsOperations`. | ||
*/ | ||
export declare class ChangeBoundsOperation implements Operation { | ||
export interface ChangeBoundsOperation extends Operation { | ||
kind: typeof ChangeBoundsOperation.KIND; | ||
newBounds: ElementAndBounds[]; | ||
readonly kind: string; | ||
static readonly KIND = "changeBounds"; | ||
constructor(newBounds: ElementAndBounds[], kind?: string); | ||
} | ||
export declare function isChangeBoundsOperation(action: any): action is ChangeBoundsOperation; | ||
export declare namespace ChangeBoundsOperation { | ||
const KIND = "changeBounds"; | ||
function is(object: any): object is ChangeBoundsOperation; | ||
function create(newBounds: ElementAndBounds[]): ChangeBoundsOperation; | ||
} | ||
/** | ||
* The client sends a `ChangeContainerOperation` to the server to request the execution of a changeContainer operation. | ||
* The client sends a `ChangeContainerOperation` to the server to request the a semantic move i.e. the corresponding element | ||
* should be moved form its current container to the target container. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `ChangeContainerOperations`. | ||
*/ | ||
export declare class ChangeContainerOperation implements Operation { | ||
readonly elementId: string; | ||
readonly targetContainerId: string; | ||
readonly location?: Point | undefined; | ||
readonly kind: string; | ||
static readonly KIND = "changeContainer"; | ||
constructor(elementId: string, targetContainerId: string, location?: Point | undefined, kind?: string); | ||
export interface ChangeContainerOperation extends Operation { | ||
kind: typeof ChangeContainerOperation.KIND; | ||
/** | ||
* The element to be changed. | ||
*/ | ||
elementId: string; | ||
/** | ||
* The element container of the changeContainer operation. | ||
*/ | ||
targetContainerId: string; | ||
/** | ||
* The graphical location. | ||
*/ | ||
location?: Point; | ||
} | ||
export declare function isChangeContainerOperation(action: any): action is ChangeContainerOperation; | ||
export declare namespace ChangeContainerOperation { | ||
const KIND = "changeContainer"; | ||
function is(object: any): object is ChangeContainerOperation; | ||
function create(options: { | ||
elementId: string; | ||
targetContainerId: string; | ||
location?: Point; | ||
}): ChangeContainerOperation; | ||
} | ||
//# sourceMappingURL=node-modification.d.ts.map |
"use strict"; | ||
/******************************************************************************** | ||
* Copyright (c) 2021 EclipseSource and others. | ||
* Copyright (c) 2021-2022 EclipseSource and others. | ||
* | ||
@@ -18,39 +18,33 @@ * This program and the accompanying materials are made available under the | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isChangeContainerOperation = exports.ChangeContainerOperation = exports.isChangeBoundsOperation = exports.ChangeBoundsOperation = void 0; | ||
const typeguard_util_1 = require("../utils/typeguard-util"); | ||
exports.ChangeContainerOperation = exports.ChangeBoundsOperation = void 0; | ||
const type_util_1 = require("../utils/type-util"); | ||
const base_protocol_1 = require("./base-protocol"); | ||
/** | ||
* Triggers the position or size change of elements. This action concerns only the element's graphical size and position. | ||
* Whether an element can be resized or repositioned may be specified by the server with a `TypeHint` to allow for immediate user feedback | ||
* before resizing or repositioning. | ||
*/ | ||
class ChangeBoundsOperation { | ||
constructor(newBounds, kind = ChangeBoundsOperation.KIND) { | ||
this.newBounds = newBounds; | ||
this.kind = kind; | ||
var ChangeBoundsOperation; | ||
(function (ChangeBoundsOperation) { | ||
ChangeBoundsOperation.KIND = 'changeBounds'; | ||
function is(object) { | ||
return base_protocol_1.Operation.hasKind(object, ChangeBoundsOperation.KIND) && (0, type_util_1.hasArrayProp)(object, 'newBounds'); | ||
} | ||
} | ||
exports.ChangeBoundsOperation = ChangeBoundsOperation; | ||
ChangeBoundsOperation.KIND = 'changeBounds'; | ||
function isChangeBoundsOperation(action) { | ||
return base_protocol_1.isActionKind(action, ChangeBoundsOperation.KIND) && typeguard_util_1.isArray(action, 'newBounds'); | ||
} | ||
exports.isChangeBoundsOperation = isChangeBoundsOperation; | ||
/** | ||
* The client sends a `ChangeContainerOperation` to the server to request the execution of a changeContainer operation. | ||
*/ | ||
class ChangeContainerOperation { | ||
constructor(elementId, targetContainerId, location, kind = ChangeContainerOperation.KIND) { | ||
this.elementId = elementId; | ||
this.targetContainerId = targetContainerId; | ||
this.location = location; | ||
this.kind = kind; | ||
ChangeBoundsOperation.is = is; | ||
function create(newBounds) { | ||
return { | ||
kind: ChangeBoundsOperation.KIND, | ||
isOperation: true, | ||
newBounds | ||
}; | ||
} | ||
} | ||
exports.ChangeContainerOperation = ChangeContainerOperation; | ||
ChangeContainerOperation.KIND = 'changeContainer'; | ||
function isChangeContainerOperation(action) { | ||
return base_protocol_1.isActionKind(action, ChangeContainerOperation.KIND) && typeguard_util_1.isString(action, 'elementId') && typeguard_util_1.isString(action, 'targetContainerId'); | ||
} | ||
exports.isChangeContainerOperation = isChangeContainerOperation; | ||
ChangeBoundsOperation.create = create; | ||
})(ChangeBoundsOperation = exports.ChangeBoundsOperation || (exports.ChangeBoundsOperation = {})); | ||
var ChangeContainerOperation; | ||
(function (ChangeContainerOperation) { | ||
ChangeContainerOperation.KIND = 'changeContainer'; | ||
function is(object) { | ||
return base_protocol_1.Operation.hasKind(object, ChangeContainerOperation.KIND) && (0, type_util_1.hasStringProp)(object, 'elementId') && (0, type_util_1.hasStringProp)(object, 'targetContainerId'); | ||
} | ||
ChangeContainerOperation.is = is; | ||
function create(options) { | ||
return Object.assign({ kind: ChangeContainerOperation.KIND, isOperation: true }, options); | ||
} | ||
ChangeContainerOperation.create = create; | ||
})(ChangeContainerOperation = exports.ChangeContainerOperation || (exports.ChangeContainerOperation = {})); | ||
//# sourceMappingURL=node-modification.js.map |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -18,33 +18,51 @@ * This program and the accompanying materials are made available under the | ||
import { Args } from './types'; | ||
export declare abstract class TriggerElementCreationAction implements Action { | ||
readonly elementTypeId: string; | ||
readonly args?: Args | undefined; | ||
readonly kind: string; | ||
constructor(elementTypeId: string, args?: Args | undefined, kind?: string); | ||
} | ||
export declare function isTriggerElementTypeCreationAction(action: any): action is TriggerElementCreationAction; | ||
/** | ||
* Triggers the enablement of the tool that is responsible for creating nodes and initializes it with the creation of nodes of the given | ||
* `elementTypeId`. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `TriggerNodeCreationActions`. | ||
*/ | ||
export declare class TriggerNodeCreationAction extends TriggerElementCreationAction { | ||
readonly elementTypeId: string; | ||
readonly args?: Args | undefined; | ||
readonly kind: string; | ||
static readonly KIND = "triggerNodeCreation"; | ||
constructor(elementTypeId: string, args?: Args | undefined, kind?: string); | ||
export interface TriggerNodeCreationAction extends Action { | ||
kind: typeof TriggerNodeCreationAction.KIND; | ||
/** | ||
* The type of edge that should be created by the nodes creation tool. | ||
*/ | ||
elementTypeId: string; | ||
/** | ||
* Custom arguments. | ||
*/ | ||
args?: Args; | ||
} | ||
export declare function isTriggerNodeCreationAction(action: any): action is TriggerNodeCreationAction; | ||
export declare namespace TriggerNodeCreationAction { | ||
const KIND = "triggerNodeCreation"; | ||
function is(object: any): object is TriggerNodeCreationAction; | ||
function create(elementTypeId: string, options?: { | ||
args?: Args; | ||
}): TriggerNodeCreationAction; | ||
} | ||
/** | ||
* Triggers the enablement of the tool that is responsible for creating edges and initializes it with the creation of edges of the given | ||
* `elementTypeId`. | ||
* <Insert documentation> | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `TriggerEdgeCreationActions`. | ||
*/ | ||
export declare class TriggerEdgeCreationAction extends TriggerElementCreationAction { | ||
readonly elementTypeId: string; | ||
readonly args?: Args | undefined; | ||
readonly kind: string; | ||
static readonly KIND = "triggerEdgeCreation"; | ||
constructor(elementTypeId: string, args?: Args | undefined, kind?: string); | ||
export interface TriggerEdgeCreationAction extends Action { | ||
kind: typeof TriggerEdgeCreationAction.KIND; | ||
/** | ||
* The type of edge that should be created by the edge creation tool. | ||
*/ | ||
elementTypeId: string; | ||
/** | ||
* Custom arguments. | ||
*/ | ||
args?: Args; | ||
} | ||
export declare function isTriggerEdgeCreationAction(action: any): action is TriggerEdgeCreationAction; | ||
export declare namespace TriggerEdgeCreationAction { | ||
const KIND = "triggerEdgeCreation"; | ||
function is(object: any): object is TriggerEdgeCreationAction; | ||
function create(elementTypeId: string, options?: { | ||
args?: Args; | ||
}): TriggerEdgeCreationAction; | ||
} | ||
//# sourceMappingURL=tool-palette.d.ts.map |
"use strict"; | ||
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -18,53 +18,29 @@ * This program and the accompanying materials are made available under the | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isTriggerEdgeCreationAction = exports.TriggerEdgeCreationAction = exports.isTriggerNodeCreationAction = exports.TriggerNodeCreationAction = exports.isTriggerElementTypeCreationAction = exports.TriggerElementCreationAction = void 0; | ||
const typeguard_util_1 = require("../utils/typeguard-util"); | ||
exports.TriggerEdgeCreationAction = exports.TriggerNodeCreationAction = void 0; | ||
const type_util_1 = require("../utils/type-util"); | ||
const base_protocol_1 = require("./base-protocol"); | ||
class TriggerElementCreationAction { | ||
constructor(elementTypeId, args, kind = 'unknown') { | ||
this.elementTypeId = elementTypeId; | ||
this.args = args; | ||
this.kind = kind; | ||
var TriggerNodeCreationAction; | ||
(function (TriggerNodeCreationAction) { | ||
TriggerNodeCreationAction.KIND = 'triggerNodeCreation'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, TriggerNodeCreationAction.KIND) && (0, type_util_1.hasStringProp)(object, 'elementTypeId'); | ||
} | ||
} | ||
exports.TriggerElementCreationAction = TriggerElementCreationAction; | ||
function isTriggerElementTypeCreationAction(action) { | ||
return base_protocol_1.isAction(action) && typeguard_util_1.isString(action, 'elementTypeId'); | ||
} | ||
exports.isTriggerElementTypeCreationAction = isTriggerElementTypeCreationAction; | ||
/** | ||
* Triggers the enablement of the tool that is responsible for creating nodes and initializes it with the creation of nodes of the given | ||
* `elementTypeId`. | ||
*/ | ||
class TriggerNodeCreationAction extends TriggerElementCreationAction { | ||
constructor(elementTypeId, args, kind = TriggerNodeCreationAction.KIND) { | ||
super(elementTypeId, args, kind); | ||
this.elementTypeId = elementTypeId; | ||
this.args = args; | ||
this.kind = kind; | ||
TriggerNodeCreationAction.is = is; | ||
function create(elementTypeId, options = {}) { | ||
return Object.assign({ kind: TriggerNodeCreationAction.KIND, elementTypeId }, options); | ||
} | ||
} | ||
exports.TriggerNodeCreationAction = TriggerNodeCreationAction; | ||
TriggerNodeCreationAction.KIND = 'triggerNodeCreation'; | ||
function isTriggerNodeCreationAction(action) { | ||
return isTriggerElementTypeCreationAction(action) && action.kind === TriggerNodeCreationAction.KIND; | ||
} | ||
exports.isTriggerNodeCreationAction = isTriggerNodeCreationAction; | ||
/** | ||
* Triggers the enablement of the tool that is responsible for creating edges and initializes it with the creation of edges of the given | ||
* `elementTypeId`. | ||
*/ | ||
class TriggerEdgeCreationAction extends TriggerElementCreationAction { | ||
constructor(elementTypeId, args, kind = TriggerEdgeCreationAction.KIND) { | ||
super(elementTypeId, args, kind); | ||
this.elementTypeId = elementTypeId; | ||
this.args = args; | ||
this.kind = kind; | ||
TriggerNodeCreationAction.create = create; | ||
})(TriggerNodeCreationAction = exports.TriggerNodeCreationAction || (exports.TriggerNodeCreationAction = {})); | ||
var TriggerEdgeCreationAction; | ||
(function (TriggerEdgeCreationAction) { | ||
TriggerEdgeCreationAction.KIND = 'triggerEdgeCreation'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, TriggerEdgeCreationAction.KIND) && (0, type_util_1.hasStringProp)(object, 'elementTypeId'); | ||
} | ||
} | ||
exports.TriggerEdgeCreationAction = TriggerEdgeCreationAction; | ||
TriggerEdgeCreationAction.KIND = 'triggerEdgeCreation'; | ||
function isTriggerEdgeCreationAction(action) { | ||
return isTriggerElementTypeCreationAction(action) && action.kind === TriggerEdgeCreationAction.KIND; | ||
} | ||
exports.isTriggerEdgeCreationAction = isTriggerEdgeCreationAction; | ||
TriggerEdgeCreationAction.is = is; | ||
function create(elementTypeId, options = {}) { | ||
return Object.assign({ kind: TriggerEdgeCreationAction.KIND, elementTypeId }, options); | ||
} | ||
TriggerEdgeCreationAction.create = create; | ||
})(TriggerEdgeCreationAction = exports.TriggerEdgeCreationAction || (exports.TriggerEdgeCreationAction = {})); | ||
//# sourceMappingURL=tool-palette.js.map |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -16,4 +16,6 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import * as sprotty from 'sprotty-protocol'; | ||
import { Dimension, Point } from 'sprotty-protocol'; | ||
import { Action } from './base-protocol'; | ||
export declare type JsonPrimitive = string | number | boolean; | ||
import { TriggerEdgeCreationAction, TriggerNodeCreationAction } from './tool-palette'; | ||
/** | ||
@@ -23,30 +25,33 @@ * A key-value pair structure for primitive typed custom arguments. | ||
export interface Args { | ||
[key: string]: JsonPrimitive; | ||
[key: string]: sprotty.JsonPrimitive; | ||
} | ||
export interface Point { | ||
readonly x: number; | ||
readonly y: number; | ||
} | ||
export declare const ORIGIN_POINT: Point; | ||
export interface Dimension { | ||
readonly width: number; | ||
readonly height: number; | ||
} | ||
export declare const EMPTY_DIMENSION: Dimension; | ||
/** | ||
* The bounds are the position (x, y) and dimension (width, height) of an object. | ||
* The ElementAndBounds type is used to associate new bounds with a model element, which is referenced via its id. | ||
*/ | ||
export interface Bounds extends Point, Dimension { | ||
} | ||
export declare const EMPTY_BOUNDS: Bounds; | ||
export interface ElementAndBounds { | ||
export interface ElementAndBounds extends sprotty.ElementAndBounds { | ||
/** | ||
* The identifier of the element. | ||
*/ | ||
elementId: string; | ||
/** | ||
* The new size of the element. | ||
*/ | ||
newSize: Dimension; | ||
/** | ||
* The new position of the element. | ||
*/ | ||
newPosition?: Point; | ||
newSize: Dimension; | ||
} | ||
/** | ||
* Associates a new alignment with a model element, which is referenced via its id. | ||
* The `ElementAndAlignment` type is used to associate a new alignment with a model element, which is referenced via its id. | ||
* Typically used to align label relative to their parent element. | ||
*/ | ||
export interface ElementAndAlignment { | ||
export interface ElementAndAlignment extends sprotty.ElementAndAlignment { | ||
/** | ||
* The identifier of the element. | ||
*/ | ||
elementId: string; | ||
/** | ||
* The new alignment of the element. | ||
*/ | ||
newAlignment: Point; | ||
@@ -86,16 +91,74 @@ } | ||
} | ||
export declare namespace EditorContext { | ||
function is(object: any): object is EditorContext; | ||
} | ||
/** | ||
*Labeled actions are used to denote a group of actions in a user-interface context, e.g., to define an entry in the command palette or | ||
*in the context menu. | ||
* Labeled actions are used to denote a group of actions in a user-interface context, e.g., to define an entry in the command palette or | ||
* in the context menu. | ||
* The corresponding namespace offers a helper function for type guard checks. | ||
*/ | ||
export declare class LabeledAction { | ||
readonly label: string; | ||
readonly actions: Action[]; | ||
readonly icon?: string | undefined; | ||
constructor(label: string, actions: Action[], icon?: string | undefined); | ||
export interface LabeledAction { | ||
/** | ||
* Group label. | ||
*/ | ||
label: string; | ||
/** | ||
* Actions in the group. | ||
*/ | ||
actions: Action[]; | ||
/** | ||
* Optional group icon. | ||
*/ | ||
icon?: string; | ||
} | ||
export declare function isLabeledAction(element: any): element is LabeledAction; | ||
export declare type JsonAny = JsonPrimitive | Args | JsonArray | null; | ||
export interface JsonArray extends Array<JsonAny> { | ||
export declare namespace LabeledAction { | ||
function is(object: any): object is LabeledAction; | ||
function toActionArray(input: LabeledAction | Action[] | Action): Action[]; | ||
} | ||
/** | ||
* A special {@link LabeledAction} that is used to denote actions that should be triggered when the user | ||
* click a tool palette item (e.g. a button to create a new node)., | ||
*/ | ||
export interface PaletteItem extends LabeledAction { | ||
/** Technical id of the palette item. */ | ||
readonly id: string; | ||
/** String indicating the order. */ | ||
readonly sortString: string; | ||
/** Children of this item. If this item has children, the client will know to render them as sub group. */ | ||
readonly children?: PaletteItem[]; | ||
} | ||
export declare namespace PaletteItem { | ||
function is(object: any): object is PaletteItem; | ||
function getTriggerAction(item?: PaletteItem): TriggerElementCreationAction | undefined; | ||
type TriggerElementCreationAction = TriggerEdgeCreationAction | TriggerNodeCreationAction; | ||
function isTriggerElementCreationAction(object: any): object is TriggerElementCreationAction; | ||
} | ||
/** | ||
* A special {@link LabeledAction} that is used to denote items in a menu. | ||
*/ | ||
export interface MenuItem extends LabeledAction { | ||
/** Technical id of the menu item. */ | ||
readonly id: string; | ||
/** String indicating the order. */ | ||
readonly sortString?: string; | ||
/** String indicating the grouping (separators). Items with equal group will be in the same group. */ | ||
readonly group?: string; | ||
/** | ||
* The optional parent id can be used to add this element as a child of another element provided by another menu provider. | ||
* The `parentId` must be fully qualified in the form of `a.b.c`, whereas `a`, `b` and `c` are referring to the IDs of other elements. | ||
* Note that this attribute will only be considered for root items of a provider and not for children of provided items. | ||
*/ | ||
readonly parentId?: string; | ||
/** Function determining whether the element is enabled. */ | ||
readonly isEnabled?: () => boolean; | ||
/** Function determining whether the element is visible. */ | ||
readonly isVisible?: () => boolean; | ||
/** Function determining whether the element is toggled on or off. */ | ||
readonly isToggled?: () => boolean; | ||
/** Children of this item. If this item has children, they will be added into a submenu of this item. */ | ||
children?: MenuItem[]; | ||
} | ||
export declare namespace MenuItem { | ||
function is(object: any): object is MenuItem; | ||
} | ||
//# sourceMappingURL=types.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isLabeledAction = exports.LabeledAction = exports.EMPTY_BOUNDS = exports.EMPTY_DIMENSION = exports.ORIGIN_POINT = void 0; | ||
exports.ORIGIN_POINT = Object.freeze({ | ||
x: 0, | ||
y: 0 | ||
}); | ||
exports.EMPTY_DIMENSION = Object.freeze({ | ||
width: -1, | ||
height: -1 | ||
}); | ||
exports.EMPTY_BOUNDS = Object.freeze(Object.assign(Object.assign({}, exports.EMPTY_DIMENSION), exports.ORIGIN_POINT)); | ||
/** | ||
*Labeled actions are used to denote a group of actions in a user-interface context, e.g., to define an entry in the command palette or | ||
*in the context menu. | ||
*/ | ||
class LabeledAction { | ||
constructor(label, actions, icon) { | ||
this.label = label; | ||
this.actions = actions; | ||
this.icon = icon; | ||
exports.MenuItem = exports.PaletteItem = exports.LabeledAction = exports.EditorContext = void 0; | ||
const type_util_1 = require("../utils/type-util"); | ||
const tool_palette_1 = require("./tool-palette"); | ||
var EditorContext; | ||
(function (EditorContext) { | ||
function is(object) { | ||
return object !== undefined && (0, type_util_1.hasArrayProp)(object, 'selectedElementIds'); | ||
} | ||
} | ||
exports.LabeledAction = LabeledAction; | ||
function isLabeledAction(element) { | ||
return element !== undefined && typeof element === 'object' && 'label' in element && 'actions' in element; | ||
} | ||
exports.isLabeledAction = isLabeledAction; | ||
EditorContext.is = is; | ||
})(EditorContext = exports.EditorContext || (exports.EditorContext = {})); | ||
var LabeledAction; | ||
(function (LabeledAction) { | ||
function is(object) { | ||
return type_util_1.AnyObject.is(object) && (0, type_util_1.hasStringProp)(object, 'label') && (0, type_util_1.hasArrayProp)(object, 'actions'); | ||
} | ||
LabeledAction.is = is; | ||
function toActionArray(input) { | ||
if (Array.isArray(input)) { | ||
return input; | ||
} | ||
else if (LabeledAction.is(input)) { | ||
return input.actions; | ||
} | ||
return [input]; | ||
} | ||
LabeledAction.toActionArray = toActionArray; | ||
})(LabeledAction = exports.LabeledAction || (exports.LabeledAction = {})); | ||
var PaletteItem; | ||
(function (PaletteItem) { | ||
function is(object) { | ||
return LabeledAction.is(object) && (0, type_util_1.hasStringProp)(object, 'id') && (0, type_util_1.hasStringProp)(object, 'sortString'); | ||
} | ||
PaletteItem.is = is; | ||
function getTriggerAction(item) { | ||
if (item) { | ||
const initialActions = item.actions | ||
.filter(a => isTriggerElementCreationAction(a)) | ||
.map(action => action); | ||
return initialActions.length > 0 ? initialActions[0] : undefined; | ||
} | ||
return undefined; | ||
} | ||
PaletteItem.getTriggerAction = getTriggerAction; | ||
function isTriggerElementCreationAction(object) { | ||
return tool_palette_1.TriggerNodeCreationAction.is(object) || tool_palette_1.TriggerEdgeCreationAction.is(object); | ||
} | ||
PaletteItem.isTriggerElementCreationAction = isTriggerElementCreationAction; | ||
})(PaletteItem = exports.PaletteItem || (exports.PaletteItem = {})); | ||
var MenuItem; | ||
(function (MenuItem) { | ||
function is(object) { | ||
return LabeledAction.is(object) && (0, type_util_1.hasStringProp)(object, 'id'); | ||
} | ||
MenuItem.is = is; | ||
})(MenuItem = exports.MenuItem || (exports.MenuItem = {})); | ||
//# sourceMappingURL=types.js.map |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -19,18 +19,26 @@ * This program and the accompanying materials are made available under the | ||
* Trigger an undo of the latest executed command. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `UndoOperations`. | ||
*/ | ||
export declare class UndoOperation implements Operation { | ||
readonly kind: string; | ||
static readonly KIND = "glspUndo"; | ||
constructor(kind?: string); | ||
export interface UndoOperation extends Operation { | ||
kind: typeof UndoOperation.KIND; | ||
} | ||
export declare function isUndoOperation(action: any): action is UndoOperation; | ||
export declare namespace UndoOperation { | ||
const KIND = "glspUndo"; | ||
function is(object: any): object is UndoOperation; | ||
function create(): UndoOperation; | ||
} | ||
/** | ||
* Trigger a redo of the latest undone command. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `RedoOperations`. | ||
*/ | ||
export declare class RedoOperation implements Operation { | ||
readonly kind: string; | ||
static readonly KIND = "glspRedo"; | ||
constructor(kind?: string); | ||
export interface RedoOperation extends Operation { | ||
kind: typeof RedoOperation.KIND; | ||
} | ||
export declare function isRedoOperation(action: any): action is RedoOperation; | ||
export declare namespace RedoOperation { | ||
const KIND = "glspRedo"; | ||
function is(object: any): object is RedoOperation; | ||
function create(): RedoOperation; | ||
} | ||
//# sourceMappingURL=undo-redo.d.ts.map |
"use strict"; | ||
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -18,32 +18,34 @@ * This program and the accompanying materials are made available under the | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isRedoOperation = exports.RedoOperation = exports.isUndoOperation = exports.UndoOperation = void 0; | ||
exports.RedoOperation = exports.UndoOperation = void 0; | ||
const base_protocol_1 = require("./base-protocol"); | ||
/** | ||
* Trigger an undo of the latest executed command. | ||
*/ | ||
class UndoOperation { | ||
constructor(kind = UndoOperation.KIND) { | ||
this.kind = kind; | ||
var UndoOperation; | ||
(function (UndoOperation) { | ||
UndoOperation.KIND = 'glspUndo'; | ||
function is(object) { | ||
return base_protocol_1.Operation.hasKind(object, UndoOperation.KIND); | ||
} | ||
} | ||
exports.UndoOperation = UndoOperation; | ||
UndoOperation.KIND = 'glspUndo'; | ||
function isUndoOperation(action) { | ||
return base_protocol_1.isActionKind(action, UndoOperation.KIND); | ||
} | ||
exports.isUndoOperation = isUndoOperation; | ||
/** | ||
* Trigger a redo of the latest undone command. | ||
*/ | ||
class RedoOperation { | ||
constructor(kind = RedoOperation.KIND) { | ||
this.kind = kind; | ||
UndoOperation.is = is; | ||
function create() { | ||
return { | ||
kind: UndoOperation.KIND, | ||
isOperation: true | ||
}; | ||
} | ||
} | ||
exports.RedoOperation = RedoOperation; | ||
RedoOperation.KIND = 'glspRedo'; | ||
function isRedoOperation(action) { | ||
return base_protocol_1.isActionKind(action, RedoOperation.KIND); | ||
} | ||
exports.isRedoOperation = isRedoOperation; | ||
UndoOperation.create = create; | ||
})(UndoOperation = exports.UndoOperation || (exports.UndoOperation = {})); | ||
var RedoOperation; | ||
(function (RedoOperation) { | ||
RedoOperation.KIND = 'glspRedo'; | ||
function is(object) { | ||
return base_protocol_1.Operation.hasKind(object, RedoOperation.KIND); | ||
} | ||
RedoOperation.is = is; | ||
function create() { | ||
return { | ||
kind: RedoOperation.KIND, | ||
isOperation: true | ||
}; | ||
} | ||
RedoOperation.create = create; | ||
})(RedoOperation = exports.RedoOperation || (exports.RedoOperation = {})); | ||
//# sourceMappingURL=undo-redo.js.map |
@@ -0,26 +1,82 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
import * as sprotty from 'sprotty-protocol/lib/actions'; | ||
import { Action } from './base-protocol'; | ||
/** | ||
* Centers the viewport on the elements with the given identifiers. It changes the scroll setting of the viewport accordingly and resets | ||
* the zoom to its default. This action can also be created on the client but it can also be sent by the server in order to perform such | ||
* a viewport change remotely. | ||
* the zoom to its default. This action is usually be created on the client but it can also be sent by the server in order to perform such | ||
* a viewport change remotely. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `CenterActions`. | ||
*/ | ||
export declare class CenterAction implements Action { | ||
readonly elementIds: string[]; | ||
readonly animate: boolean; | ||
readonly retainZoom: boolean; | ||
static readonly KIND = "center"; | ||
readonly kind = "center"; | ||
constructor(elementIds: string[], animate?: boolean, retainZoom?: boolean); | ||
export interface CenterAction extends Action, sprotty.CenterAction { | ||
kind: typeof CenterAction.KIND; | ||
/** | ||
* The identifier of the elements on which the viewport should be centered. | ||
* If empty the root element will be used. | ||
*/ | ||
elementIds: string[]; | ||
/** | ||
* Indicate if the modification of the viewport should be realized with or without support of animations. | ||
*/ | ||
animate: boolean; | ||
/** | ||
* Indicates whether the zoom level should be kept. | ||
*/ | ||
retainZoom: boolean; | ||
} | ||
export declare function isCenterAction(action: any): action is CenterAction; | ||
export declare class FitToScreenAction implements Action { | ||
readonly elementIds: string[]; | ||
readonly padding?: number | undefined; | ||
readonly maxZoom?: number | undefined; | ||
readonly animate: boolean; | ||
static readonly KIND = "fit"; | ||
readonly kind = "fit"; | ||
constructor(elementIds: string[], padding?: number | undefined, maxZoom?: number | undefined, animate?: boolean); | ||
export declare namespace CenterAction { | ||
const KIND = "center"; | ||
function is(object: any): object is CenterAction; | ||
function create(elementIds: string[], options?: { | ||
animate?: boolean; | ||
retainZoom?: boolean; | ||
}): CenterAction; | ||
} | ||
export declare function isFitToScreenAction(action: any): action is FitToScreenAction; | ||
/** | ||
* Triggers to fit all or a list of elements into the available diagram canvas. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `CenterActions`. | ||
*/ | ||
export interface FitToScreenAction extends Action, sprotty.FitToScreenAction { | ||
kind: typeof FitToScreenAction.KIND; | ||
/** | ||
* The identifier of the elements to fit on screen. | ||
*/ | ||
elementIds: string[]; | ||
/** | ||
* The padding that should be visible on the viewport. | ||
*/ | ||
padding?: number; | ||
/** | ||
* The max zoom level authorized. | ||
*/ | ||
maxZoom?: number; | ||
/** | ||
* Indicate if the action should be performed with animation support or not. | ||
*/ | ||
animate: boolean; | ||
} | ||
export declare namespace FitToScreenAction { | ||
const KIND = "fit"; | ||
function is(object: any): object is FitToScreenAction; | ||
function create(elementIds: string[], options?: { | ||
padding?: number; | ||
maxZoom?: number; | ||
animate?: boolean; | ||
}): FitToScreenAction; | ||
} | ||
//# sourceMappingURL=viewport.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isFitToScreenAction = exports.FitToScreenAction = exports.isCenterAction = exports.CenterAction = void 0; | ||
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
const typeguard_util_1 = require("../utils/typeguard-util"); | ||
exports.FitToScreenAction = exports.CenterAction = void 0; | ||
const type_util_1 = require("../utils/type-util"); | ||
const base_protocol_1 = require("./base-protocol"); | ||
/** | ||
* Centers the viewport on the elements with the given identifiers. It changes the scroll setting of the viewport accordingly and resets | ||
* the zoom to its default. This action can also be created on the client but it can also be sent by the server in order to perform such | ||
* a viewport change remotely. | ||
*/ | ||
class CenterAction { | ||
constructor(elementIds, animate = true, retainZoom = false) { | ||
this.elementIds = elementIds; | ||
this.animate = animate; | ||
this.retainZoom = retainZoom; | ||
this.kind = CenterAction.KIND; | ||
var CenterAction; | ||
(function (CenterAction) { | ||
CenterAction.KIND = 'center'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, CenterAction.KIND) && (0, type_util_1.hasBooleanProp)(object, 'animate') && (0, type_util_1.hasBooleanProp)(object, 'retainZoom'); | ||
} | ||
} | ||
exports.CenterAction = CenterAction; | ||
CenterAction.KIND = 'center'; | ||
function isCenterAction(action) { | ||
return base_protocol_1.isActionKind(action, CenterAction.KIND) && typeguard_util_1.isBoolean(action, 'animate') && typeguard_util_1.isBoolean(action, 'retainZoom'); | ||
} | ||
exports.isCenterAction = isCenterAction; | ||
class FitToScreenAction { | ||
constructor(elementIds, padding, maxZoom, animate = true) { | ||
this.elementIds = elementIds; | ||
this.padding = padding; | ||
this.maxZoom = maxZoom; | ||
this.animate = animate; | ||
this.kind = FitToScreenAction.KIND; | ||
CenterAction.is = is; | ||
function create(elementIds, options = {}) { | ||
return Object.assign({ kind: CenterAction.KIND, animate: true, retainZoom: false, elementIds }, options); | ||
} | ||
} | ||
exports.FitToScreenAction = FitToScreenAction; | ||
FitToScreenAction.KIND = 'fit'; | ||
function isFitToScreenAction(action) { | ||
return base_protocol_1.isActionKind(action, FitToScreenAction.KIND) && typeguard_util_1.isArray(action, 'elementIds') && typeguard_util_1.isBoolean(action, 'animate'); | ||
} | ||
exports.isFitToScreenAction = isFitToScreenAction; | ||
CenterAction.create = create; | ||
})(CenterAction = exports.CenterAction || (exports.CenterAction = {})); | ||
var FitToScreenAction; | ||
(function (FitToScreenAction) { | ||
FitToScreenAction.KIND = 'fit'; | ||
function is(object) { | ||
return base_protocol_1.Action.hasKind(object, FitToScreenAction.KIND) && (0, type_util_1.hasArrayProp)(object, 'elementIds') && (0, type_util_1.hasBooleanProp)(object, 'animate'); | ||
} | ||
FitToScreenAction.is = is; | ||
function create(elementIds, options = {}) { | ||
return Object.assign({ kind: FitToScreenAction.KIND, animate: true, elementIds }, options); | ||
} | ||
FitToScreenAction.create = create; | ||
})(FitToScreenAction = exports.FitToScreenAction || (exports.FitToScreenAction = {})); | ||
//# sourceMappingURL=viewport.js.map |
/******************************************************************************** | ||
* Copyright (c) 2020-2021 EclipseSource and others. | ||
* Copyright (c) 2020-2022 EclipseSource and others. | ||
* | ||
@@ -16,2 +16,16 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import { SetBoundsAction, SetViewportAction } from 'sprotty-protocol/lib/actions'; | ||
declare module 'sprotty-protocol/lib/actions' { | ||
namespace SetViewportAction { | ||
function is(object: any): object is SetViewportAction; | ||
} | ||
namespace SetBoundsAction { | ||
function is(object: any): object is SetBoundsAction; | ||
} | ||
} | ||
export { Viewport } from 'sprotty-protocol/lib/model'; | ||
export * from 'sprotty-protocol/lib/utils/async'; | ||
export * from 'sprotty-protocol/lib/utils/geometry'; | ||
export * from 'sprotty-protocol/lib/utils/json'; | ||
export * from 'sprotty-protocol/lib/utils/model-utils'; | ||
export * from './action-protocol'; | ||
@@ -21,6 +35,7 @@ export * from './glsp-client'; | ||
export * from './jsonrpc/glsp-jsonrpc-client'; | ||
export * from './types/default-types'; | ||
export * from './model/default-types'; | ||
export * from './model/model-schema'; | ||
export * from './utils/array-util'; | ||
export * from './utils/launch-util'; | ||
export * from './utils/typeguard-util'; | ||
export * from './utils/type-util'; | ||
export { SetBoundsAction, SetViewportAction }; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -10,7 +10,8 @@ "use strict"; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SetViewportAction = exports.SetBoundsAction = void 0; | ||
/******************************************************************************** | ||
* Copyright (c) 2020-2021 EclipseSource and others. | ||
* Copyright (c) 2020-2022 EclipseSource and others. | ||
* | ||
@@ -29,2 +30,17 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
const actions_1 = require("sprotty-protocol/lib/actions"); | ||
Object.defineProperty(exports, "SetBoundsAction", { enumerable: true, get: function () { return actions_1.SetBoundsAction; } }); | ||
Object.defineProperty(exports, "SetViewportAction", { enumerable: true, get: function () { return actions_1.SetViewportAction; } }); | ||
const action_protocol_1 = require("./action-protocol"); | ||
const type_util_1 = require("./utils/type-util"); | ||
actions_1.SetViewportAction.is = (object) => action_protocol_1.Action.hasKind(object, actions_1.SetViewportAction.KIND) && | ||
(0, type_util_1.hasStringProp)(object, 'elementId') && | ||
(0, type_util_1.hasObjectProp)(object, 'newViewport') && | ||
(0, type_util_1.hasBooleanProp)(object, 'animate'); | ||
actions_1.SetBoundsAction.is = (object) => action_protocol_1.Action.hasKind(object, actions_1.SetBoundsAction.KIND) && (0, type_util_1.hasObjectProp)(object, 'bounds'); | ||
__exportStar(require("sprotty-protocol/lib/utils/async"), exports); | ||
__exportStar(require("sprotty-protocol/lib/utils/geometry"), exports); | ||
__exportStar(require("sprotty-protocol/lib/utils/json"), exports); | ||
__exportStar(require("sprotty-protocol/lib/utils/model-utils"), exports); | ||
// Default export of @eclipse-glsp/protocol | ||
__exportStar(require("./action-protocol"), exports); | ||
@@ -34,6 +50,6 @@ __exportStar(require("./glsp-client"), exports); | ||
__exportStar(require("./jsonrpc/glsp-jsonrpc-client"), exports); | ||
__exportStar(require("./types/default-types"), exports); | ||
__exportStar(require("./model/default-types"), exports); | ||
__exportStar(require("./model/model-schema"), exports); | ||
__exportStar(require("./utils/array-util"), exports); | ||
__exportStar(require("./utils/launch-util"), exports); | ||
__exportStar(require("./utils/typeguard-util"), exports); | ||
__exportStar(require("./utils/type-util"), exports); | ||
//# sourceMappingURL=index.js.map |
/******************************************************************************** | ||
* Copyright (c) 2019-2021 EclipseSource and others. | ||
* Copyright (c) 2019-2022 EclipseSource and others. | ||
* | ||
@@ -16,4 +16,4 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import { ActionMessage } from 'sprotty'; | ||
import { Message, MessageConnection } from 'vscode-ws-jsonrpc'; | ||
import { ActionMessage } from '../action-protocol'; | ||
import { ActionMessageHandler, ClientState, DisposeClientSessionParameters, GLSPClient, InitializeClientSessionParameters, InitializeParameters, InitializeResult } from '../glsp-client'; | ||
@@ -40,3 +40,3 @@ import { ConnectionProvider, JsonrpcGLSPClient } from './glsp-jsonrpc-client'; | ||
protected doCreateConnection(): Promise<MessageConnection>; | ||
protected handleConnectionError(error: Error, message: Message, count: number): void; | ||
protected handleConnectionError(error: Error, message: Message | undefined, count: number | undefined): void; | ||
protected handleConnectionClosed(): void; | ||
@@ -43,0 +43,0 @@ protected isConnectionActive(): boolean; |
@@ -88,3 +88,3 @@ "use strict"; | ||
const connection = typeof this.connectionProvider === 'function' ? await this.connectionProvider() : this.connectionProvider; | ||
connection.onError((data) => this.handleConnectionError(data[0], data[1], data[2])); | ||
connection.onError(data => this.handleConnectionError(data[0], data[1], data[2])); | ||
connection.onClose(() => this.handleConnectionClosed()); | ||
@@ -91,0 +91,0 @@ return connection; |
/******************************************************************************** | ||
* Copyright (c) 2020-2021 EclipseSource and others. | ||
* Copyright (c) 2020-2022 EclipseSource and others. | ||
* | ||
@@ -16,5 +16,5 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import { ActionMessage } from 'sprotty'; | ||
import { MessageConnection, NotificationType, RequestType } from 'vscode-jsonrpc'; | ||
import { Logger, NotificationType0 } from 'vscode-ws-jsonrpc'; | ||
import { ActionMessage } from '../action-protocol/base-protocol'; | ||
import { DisposeClientSessionParameters, GLSPClient, InitializeClientSessionParameters, InitializeParameters, InitializeResult } from '../glsp-client'; | ||
@@ -28,3 +28,3 @@ export declare type MaybePromise<T> = T | Promise<T> | PromiseLike<T>; | ||
function isOptions(object: any): object is Options; | ||
const ActionMessageNotification: NotificationType<ActionMessage, void>; | ||
const ActionMessageNotification: NotificationType<ActionMessage<import("../action-protocol/base-protocol").Action>, void>; | ||
const InitializeRequest: RequestType<InitializeParameters, InitializeResult, void, void>; | ||
@@ -31,0 +31,0 @@ const InitializeClientSessionRequest: RequestType<InitializeClientSessionParameters, void, void, void>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.JsonrpcGLSPClient = void 0; | ||
/******************************************************************************** | ||
* Copyright (c) 2020-2022 EclipseSource and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
const vscode_jsonrpc_1 = require("vscode-jsonrpc"); | ||
@@ -21,6 +36,6 @@ const vscode_ws_jsonrpc_1 = require("vscode-ws-jsonrpc"); | ||
function createWebsocketConnectionProvider(websocket, logger) { | ||
const socket = vscode_ws_jsonrpc_1.toSocket(websocket); | ||
const socket = (0, vscode_ws_jsonrpc_1.toSocket)(websocket); | ||
const reader = new vscode_ws_jsonrpc_1.WebSocketMessageReader(socket); | ||
const writer = new vscode_ws_jsonrpc_1.WebSocketMessageWriter(socket); | ||
return vscode_ws_jsonrpc_1.createMessageConnection(reader, writer, logger); | ||
return (0, vscode_ws_jsonrpc_1.createMessageConnection)(reader, writer, logger); | ||
} | ||
@@ -27,0 +42,0 @@ JsonrpcGLSPClient.createWebsocketConnectionProvider = createWebsocketConnectionProvider; |
/******************************************************************************** | ||
* Copyright (c) 2019-2021 EclipseSource and others. | ||
* Copyright (c) 2019-2022 EclipseSource and others. | ||
* | ||
@@ -16,6 +16,40 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
/** | ||
* A union type for for objects that can either be a single element or and array of elements. | ||
*/ | ||
export declare type MaybeArray<T> = T | T[]; | ||
export declare function remove<T>(array: T[], value: T): boolean; | ||
/** | ||
* Returns the first element of the given array. | ||
* @param array the array. | ||
* @returns the element at index 0. | ||
*/ | ||
export declare function first<T>(array: T[]): number; | ||
/** | ||
* Returns the first n elements of the given array. | ||
* @param array the array. | ||
* @param n the number of elements that should be returned | ||
* @returns the first n elements of the array | ||
*/ | ||
export declare function first<T>(array: T[], n: number): T[]; | ||
/** | ||
* Removes the given values from the given array (if present). | ||
* @param array The array to execute the remove operation on. | ||
* @param values The values that should be removed from the array. | ||
*/ | ||
export declare function remove<T>(array: T[], ...values: T[]): void; | ||
/** | ||
* Push an array of values to the given array. The values can either be single objects of a concrete type `T` | ||
* or can also be nested arrays of T. If nested arrays are passed the they will be destructured (i.e. flattened) | ||
* so that they can be pushed to the given array. | ||
* @param array The array to push to. | ||
* @param toPush The values of {@link MaybeArray}s that should be pushed. | ||
*/ | ||
export declare function flatPush<T>(array: T[], toPush: MaybeArray<T>[]): void; | ||
export declare function distinctAdd<T>(array: T[], value: T): boolean; | ||
/** | ||
* Adds the given values to the given array. The add operation is executed distinct meaning | ||
* a value will not be pushed to the array if its already present in the array. | ||
* @param array The array to push to. | ||
* @param values The values that should be added distinctively. | ||
*/ | ||
export declare function distinctAdd<T>(array: T[], ...values: T[]): void; | ||
interface Constructor<T> { | ||
@@ -25,8 +59,46 @@ new (...args: any[]): T; | ||
declare type PrimitiveType = 'bigint' | 'boolean' | 'function' | 'number' | 'object' | 'string' | 'symbol' | 'undefined'; | ||
/** | ||
* A typeguard function to check wether a given object is an array of a specific type `T`. As it checks the type of each individual | ||
* array element this guard check is expensive and should only be used in cases where complete type-safety is required. | ||
* @param object The object to check. | ||
* @param typeGuard A typeguard to check the type of the individual elements. | ||
* @param supportEmpty A flag to determine wether empty arrays should pass the typeguard check. | ||
* @returns A type predicate indicating wether the given object has passed the type guard check. | ||
*/ | ||
export declare function isArrayOfType<T>(object: any, typeGuard: (elem: any) => elem is T, supportEmpty?: boolean): object is T[]; | ||
export declare function isArrayOfClass<T>(object: any, className: Constructor<T>, supportEmpty?: boolean): object is T[]; | ||
/** | ||
* A typeguard function to check wether a given object is an array of a class`T`. As it checks the wether each individual element | ||
* is an instance of the given class this guard check is expensive and should only be used in cases where complete type-safety is required. | ||
* @param object The object to check. | ||
* @param constructor The constructor for the class under test. | ||
* @param supportEmpty A flag to determine wether empty arrays should pass the typeguard check. | ||
* @returns A type predicate indicating wether the given object has passed the type guard check. | ||
*/ | ||
export declare function isArrayOfClass<T>(object: any, constructor: Constructor<T>, supportEmpty?: boolean): object is T[]; | ||
/** | ||
* A typeguard function to check wether a given object is an array of a {@link PrimitiveType} `T. As it checks the type of each individual | ||
* array element this guard check is expensive and should only be used in cases where complete type-safety is required. | ||
* @param object The object to check. | ||
* @param primitiveType The expected primitive type of the elements. | ||
* @param supportEmpty A flag to determine wether empty arrays should pass the typeguard check. | ||
* @returns A type predicate indicating wether the given object has passed the type guard check. | ||
*/ | ||
export declare function isArrayOfPrimitive<T>(object: any, primitiveType: PrimitiveType, supportEmpty?: boolean): object is T[]; | ||
/** | ||
* A typeguard function to check wether a given object is an array of a strings. As it checks the type of each individual | ||
* array element this guard check is expensive and should only be used in cases where complete type-safety is required. | ||
* @param object The object to check. | ||
* @param supportEmpty A flag to determine wether empty arrays should pass the typeguard check. | ||
* @returns A type predicate indicating wether the given object has passed the type guard check. | ||
*/ | ||
export declare function isStringArray(object: any, supportEmpty?: boolean): object is string[]; | ||
/** | ||
* A typeguard function to check wether a given object is an array where each element matches the given predicate. | ||
* @param object The object to check. | ||
* @param predicate The predicate to test with. | ||
* @param supportEmpty A flag to determine wether empty arrays be matched by the predicate.. | ||
* @returns `true` if the given object is an array and all elements match the given predicate. `false` otherwise. | ||
*/ | ||
export declare function isArrayMatching(object: any, predicate: (elem: any) => boolean, supportEmpty?: boolean): boolean; | ||
export {}; | ||
//# sourceMappingURL=array-util.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isArrayMatching = exports.isStringArray = exports.isArrayOfPrimitive = exports.isArrayOfClass = exports.isArrayOfType = exports.distinctAdd = exports.flatPush = exports.remove = void 0; | ||
function remove(array, value) { | ||
const index = array.indexOf(value); | ||
if (index >= 0) { | ||
array.splice(index, 1); | ||
return true; | ||
exports.isArrayMatching = exports.isStringArray = exports.isArrayOfPrimitive = exports.isArrayOfClass = exports.isArrayOfType = exports.distinctAdd = exports.flatPush = exports.remove = exports.first = void 0; | ||
function first(array, n) { | ||
if (n) { | ||
return array.filter((_, index) => index < n); | ||
} | ||
return false; | ||
return array[0]; | ||
} | ||
exports.first = first; | ||
/** | ||
* Removes the given values from the given array (if present). | ||
* @param array The array to execute the remove operation on. | ||
* @param values The values that should be removed from the array. | ||
*/ | ||
function remove(array, ...values) { | ||
values.forEach(value => { | ||
const index = array.indexOf(value); | ||
if (index >= 0) { | ||
array.splice(index, 1); | ||
} | ||
}); | ||
} | ||
exports.remove = remove; | ||
/** | ||
* Push an array of values to the given array. The values can either be single objects of a concrete type `T` | ||
* or can also be nested arrays of T. If nested arrays are passed the they will be destructured (i.e. flattened) | ||
* so that they can be pushed to the given array. | ||
* @param array The array to push to. | ||
* @param toPush The values of {@link MaybeArray}s that should be pushed. | ||
*/ | ||
function flatPush(array, toPush) { | ||
@@ -17,10 +36,24 @@ toPush.forEach(value => (Array.isArray(value) ? array.push(...value) : array.push(value))); | ||
exports.flatPush = flatPush; | ||
function distinctAdd(array, value) { | ||
if (!array.includes(value)) { | ||
array.push(value); | ||
return true; | ||
} | ||
return false; | ||
/** | ||
* Adds the given values to the given array. The add operation is executed distinct meaning | ||
* a value will not be pushed to the array if its already present in the array. | ||
* @param array The array to push to. | ||
* @param values The values that should be added distinctively. | ||
*/ | ||
function distinctAdd(array, ...values) { | ||
values.forEach(value => { | ||
if (!array.includes(value)) { | ||
array.push(value); | ||
} | ||
}); | ||
} | ||
exports.distinctAdd = distinctAdd; | ||
/** | ||
* A typeguard function to check wether a given object is an array of a specific type `T`. As it checks the type of each individual | ||
* array element this guard check is expensive and should only be used in cases where complete type-safety is required. | ||
* @param object The object to check. | ||
* @param typeGuard A typeguard to check the type of the individual elements. | ||
* @param supportEmpty A flag to determine wether empty arrays should pass the typeguard check. | ||
* @returns A type predicate indicating wether the given object has passed the type guard check. | ||
*/ | ||
function isArrayOfType(object, typeGuard, supportEmpty = false) { | ||
@@ -30,6 +63,22 @@ return isArrayMatching(object, element => typeGuard(element), supportEmpty); | ||
exports.isArrayOfType = isArrayOfType; | ||
function isArrayOfClass(object, className, supportEmpty = false) { | ||
return isArrayMatching(object, element => element instanceof className, supportEmpty); | ||
/** | ||
* A typeguard function to check wether a given object is an array of a class`T`. As it checks the wether each individual element | ||
* is an instance of the given class this guard check is expensive and should only be used in cases where complete type-safety is required. | ||
* @param object The object to check. | ||
* @param constructor The constructor for the class under test. | ||
* @param supportEmpty A flag to determine wether empty arrays should pass the typeguard check. | ||
* @returns A type predicate indicating wether the given object has passed the type guard check. | ||
*/ | ||
function isArrayOfClass(object, constructor, supportEmpty = false) { | ||
return isArrayMatching(object, element => element instanceof constructor, supportEmpty); | ||
} | ||
exports.isArrayOfClass = isArrayOfClass; | ||
/** | ||
* A typeguard function to check wether a given object is an array of a {@link PrimitiveType} `T. As it checks the type of each individual | ||
* array element this guard check is expensive and should only be used in cases where complete type-safety is required. | ||
* @param object The object to check. | ||
* @param primitiveType The expected primitive type of the elements. | ||
* @param supportEmpty A flag to determine wether empty arrays should pass the typeguard check. | ||
* @returns A type predicate indicating wether the given object has passed the type guard check. | ||
*/ | ||
function isArrayOfPrimitive(object, primitiveType, supportEmpty = false) { | ||
@@ -39,2 +88,9 @@ return isArrayMatching(object, element => typeof element === primitiveType, supportEmpty); | ||
exports.isArrayOfPrimitive = isArrayOfPrimitive; | ||
/** | ||
* A typeguard function to check wether a given object is an array of a strings. As it checks the type of each individual | ||
* array element this guard check is expensive and should only be used in cases where complete type-safety is required. | ||
* @param object The object to check. | ||
* @param supportEmpty A flag to determine wether empty arrays should pass the typeguard check. | ||
* @returns A type predicate indicating wether the given object has passed the type guard check. | ||
*/ | ||
function isStringArray(object, supportEmpty = false) { | ||
@@ -44,2 +100,9 @@ return isArrayOfPrimitive(object, 'string', supportEmpty); | ||
exports.isStringArray = isStringArray; | ||
/** | ||
* A typeguard function to check wether a given object is an array where each element matches the given predicate. | ||
* @param object The object to check. | ||
* @param predicate The predicate to test with. | ||
* @param supportEmpty A flag to determine wether empty arrays be matched by the predicate.. | ||
* @returns `true` if the given object is an array and all elements match the given predicate. `false` otherwise. | ||
*/ | ||
function isArrayMatching(object, predicate, supportEmpty = false) { | ||
@@ -46,0 +109,0 @@ return Array.isArray(object) && object.every(predicate) && (supportEmpty || object.length > 0); |
{ | ||
"name": "@eclipse-glsp/protocol", | ||
"version": "0.9.0", | ||
"version": "0.10.0-next.5043408.167+5043408", | ||
"description": "The protocol definition for client-server communication in GLSP", | ||
@@ -36,3 +36,3 @@ "license": "(EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0)", | ||
"dependencies": { | ||
"inversify": "^5.0.1", | ||
"sprotty-protocol": "next", | ||
"uuid": "7.0.3", | ||
@@ -42,12 +42,11 @@ "vscode-ws-jsonrpc": "0.2.0" | ||
"devDependencies": { | ||
"@babel/runtime": "^7.11.2", | ||
"@types/uuid": "3.4.5", | ||
"rimraf": "^2.6.1", | ||
"typescript": "^3.9.2" | ||
"@types/uuid": "3.4.5" | ||
}, | ||
"scripts": { | ||
"prepare": "yarn clean && yarn build && yarn lint", | ||
"clean": "rimraf lib", | ||
"clean": "rimraf lib tsconfig.tsbuildinfo ", | ||
"build": "tsc", | ||
"lint": "eslint -c ./.eslintrc.js --ext .ts ./src", | ||
"test": "mocha --config ../../.mocharc.json \"./src/**/*.spec.?(ts|tsx)\"", | ||
"test:ci": "export JUNIT_REPORT_PATH=./report.xml && yarn test --reporter mocha-jenkins-reporter", | ||
"watch": "tsc -w" | ||
@@ -60,3 +59,3 @@ }, | ||
"types": "lib/index", | ||
"gitHead": "5e12ddb7e7da0e1b55555d95607645e24555f6b4" | ||
"gitHead": "50434080a9890d7e9087fb5b561d5cea70f0230f" | ||
} |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -16,94 +16,157 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import * as uuid from 'uuid'; | ||
import { isArray, isString } from '../utils/typeguard-util'; | ||
import { JsonAny } from './types'; | ||
import { JsonPrimitive } from 'sprotty-protocol'; | ||
import * as sprotty from 'sprotty-protocol/lib/actions'; | ||
import { AnyObject, hasArrayProp, hasStringProp, TypeGuard } from '../utils/type-util'; | ||
/** | ||
* A general message serves as an envelope carrying an action to be transmitted between the client and the server via a DiagramServer. | ||
* An action is a declarative description of a behavior that shall be invoked by the receiver upon receipt of the action. | ||
* It is a plain data structure, and as such transferable between server and client. An action must never contain actual | ||
* SModelElement instances, but either refer to them via their ids or contain serializable schema for model elements. | ||
* Additional typeguard functions are provided via the corresponding namespace. | ||
*/ | ||
export interface ActionMessage<A extends Action = Action> { | ||
export interface Action extends sprotty.Action { | ||
/** | ||
* Used to identify a specific client session. | ||
* Unique identifier specifying the kind of action to process. | ||
*/ | ||
clientId: string; | ||
kind: string; | ||
} | ||
export namespace Action { | ||
export function is(object: any): object is Action { | ||
return AnyObject.is(object) && hasStringProp(object, 'kind'); | ||
} | ||
/** | ||
* The action to execute. | ||
* Typeguard function to check wether the given object is an {@link Action} with the given `kind`. | ||
* @param object The object to check. | ||
* @param kind The expected action kind. | ||
* @returns A type literal indicating wether the given object is an action with the given kind. | ||
*/ | ||
action: A; | ||
export function hasKind(object: any, kind: string): object is Action { | ||
return Action.is(object) && object.kind === kind; | ||
} | ||
} | ||
export function isActionMessage(object: any): object is ActionMessage { | ||
return object !== undefined && isString(object, 'clientId') && isAction(object['action']); | ||
} | ||
export function isActionMessageOfType<A extends Action>(object: any, guard: (action: any) => action is A): object is ActionMessage<A> { | ||
return isActionMessage(object) && guard(object.action); | ||
} | ||
/** | ||
* An action is a declarative description of a behavior that shall be invoked by the receiver upon receipt of the action. | ||
* It is a plain data structure, and as such transferable between server and client. An action must never contain actual | ||
* SModelElement instances, but either refer to them via their ids or contain serializable schema for model elements. | ||
* A general message serves as an envelope carrying an action to be transmitted between the client and the server via a DiagramServer. | ||
* @typeParam A the {@link Action} type that is contained by this message. | ||
* A typeguard function is provided via the corresponding namespace. | ||
*/ | ||
export interface Action { | ||
export interface ActionMessage<A extends Action = Action> extends sprotty.ActionMessage { | ||
/** | ||
* Unique identifier specifying the kind of action to process. | ||
* The unique client id | ||
* */ | ||
clientId: string; | ||
/** | ||
* The action to execute. | ||
*/ | ||
readonly kind: string; | ||
action: A; | ||
} | ||
export function isAction(action: any): action is Action { | ||
return action !== undefined && isString(action, 'kind'); | ||
export namespace ActionMessage { | ||
export function is<A extends Action>(object: any, typeguard?: TypeGuard<A>): object is ActionMessage<A> { | ||
const actionGuard = typeguard ?? Action.is; | ||
return AnyObject.is(object) && hasStringProp(object, 'clientId') && actionGuard(object.action); | ||
} | ||
} | ||
export function isActionKind(action: any, kind: string): action is Action { | ||
return isAction(action) && action.kind === kind; | ||
} | ||
/** | ||
* A request action is tied to the expectation of receiving a corresponding response action. The requestId property is used to match the | ||
* received response with the original request. | ||
* received response with the original request. Typically its not necessary to create an explicit requestId. The requestId can be set | ||
* to an empty string. The action dispatcher than auto generates an request id if needed (i.e. the action was dispatched as request). | ||
* | ||
* A typeguard function, and a generic helper function to generate a request id are provided via the corresponding namespace. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export interface RequestAction<Res extends ResponseAction> extends Action { | ||
export interface RequestAction<Res extends ResponseAction> extends Action, sprotty.RequestAction<Res> { | ||
/** | ||
* Unique id for this request. In order to match a response to this request, the response needs to have the same id. | ||
*/ | ||
readonly requestId: string; | ||
requestId: string; | ||
} | ||
export function isRequestAction(action?: any): action is RequestAction<ResponseAction> { | ||
return isAction(action) && isString(action, 'requestId'); | ||
export namespace RequestAction { | ||
export function is(object: any): object is RequestAction<ResponseAction> { | ||
return Action.is(object) && hasStringProp(object, 'requestId'); | ||
} | ||
/** | ||
* Typeguard function to check wether the given object is an {@link RequestAction} with the given `kind`. | ||
* @param object The object to check. | ||
* @param kind The expected action kind. | ||
* @returns A type literal indicating wether the given object is a request action with the given kind. | ||
*/ | ||
export function hasKind(object: any, kind: string): object is Action { | ||
return RequestAction.is(object) && object.kind === kind; | ||
} | ||
export function generateRequestId(): string { | ||
return sprotty.generateRequestId(); | ||
} | ||
} | ||
export function generateRequestId(): string { | ||
return uuid.v4(); | ||
} | ||
/** | ||
* A response action is sent to respond to a request action. The responseId must match the requestId of the preceding request. | ||
* In case the responseId is empty or undefined, the action is handled as standalone, i.e. it was fired without a preceding request. | ||
* In case the responseId is empty, the action is handled as standalone, i.e. it was fired without a preceding request. | ||
* The action dispatcher of the GLSP server has a special handling for {@link RequestAction} handlers | ||
* and automatically sets the `responseId` of the corresponding responseAction. So on the server side its typically enough | ||
* to set the `responseId` to an empty string and rely on the `ActionDispatcher` for assigning the correct `responseId. | ||
* Additional typeguard functions are provided via the corresponding namespace. | ||
*/ | ||
export interface ResponseAction extends Action { | ||
export interface ResponseAction extends Action, sprotty.ResponseAction { | ||
/** | ||
* Id corresponding to the request this action responds to. | ||
*/ | ||
readonly responseId: string; | ||
responseId: string; | ||
} | ||
export function isResponseAction(action?: any): action is ResponseAction { | ||
return isAction(action) && 'responseId' in action && typeof action['responseId'] === 'string' && action['responseId'] !== ''; | ||
export namespace ResponseAction { | ||
export function is(object: any): object is ResponseAction { | ||
return Action.is(object) && hasStringProp(object, 'responseId'); | ||
} | ||
/** | ||
* Typeguard function to check wether the given object is an {@link ResponseAction} with a non-empty response id. | ||
* @param object The object to check. | ||
* @returns A type literal indicating wether the given object is a response action with a non-empty response id. | ||
*/ | ||
export function hasValidResponseId(object: any): object is ResponseAction { | ||
return ResponseAction.is(object) && object.responseId !== ''; | ||
} | ||
} | ||
/** | ||
* A reject action is a response fired to indicate that a request must be rejected. | ||
* A reject action is a {@link ResponseAction} fired to indicate that a certain {@link ResponseAction} | ||
* has been rejected. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `RejectActions`. | ||
*/ | ||
export class RejectAction implements ResponseAction { | ||
static readonly KIND = 'rejectRequest'; | ||
readonly kind = RejectAction.KIND; | ||
constructor(public readonly message: string, public readonly responseId: string, public readonly detail?: JsonAny) {} | ||
export interface RejectAction extends ResponseAction, sprotty.RejectAction { | ||
kind: typeof RejectAction.KIND; | ||
/** | ||
* A human-readable description of the reject reason. Typically this is an error message | ||
* that has been thrown when handling the corresponding {@link RequestAction}. | ||
*/ | ||
message: string; | ||
/** | ||
* Optional additional details. | ||
*/ | ||
detail?: JsonPrimitive; | ||
} | ||
export function isRejectAction(action: any): action is RejectAction { | ||
return isResponseAction(action) && action.kind === RejectAction.KIND && isString(action, 'message'); | ||
export namespace RejectAction { | ||
export const KIND = 'rejectRequest'; | ||
export function is(object: any): object is RejectAction { | ||
return Action.hasKind(object, RejectAction.KIND) && hasStringProp(object, 'message'); | ||
} | ||
export function create(message: string, options: { detail?: JsonPrimitive; responseId?: string } = {}): RejectAction { | ||
return { | ||
kind: KIND, | ||
responseId: '', | ||
message, | ||
...options | ||
}; | ||
} | ||
} | ||
@@ -114,15 +177,56 @@ | ||
* server. After a successful modification, the server sends the updated model back to the client using the `UpdateModelAction`. | ||
* An operation contains a dedicated `isOperation` property that is used as a discriminator. This is necessary so that the server | ||
* can distinguish between plain actions and operations. | ||
* The corresponding namespace offers a helper function for type guard checks. | ||
*/ | ||
export interface Operation extends Action {} | ||
export interface Operation extends Action { | ||
/** | ||
* Discriminator property to make operations distinguishable from plain {@link Action}s. | ||
*/ | ||
isOperation: true; | ||
} | ||
export namespace Operation { | ||
export function is(object: any): object is Operation { | ||
return Action.is(object) && (object as any).isOperation === true; | ||
} | ||
/** | ||
* Typeguard function to check wether the given object is an {@link Operation} with the given `kind`. | ||
* @param object The object to check. | ||
* @param kind The expected operation kind. | ||
* @returns A type literal indicating wether the given object is an operation with the given kind. | ||
*/ | ||
export function hasKind(object: any, kind: string): object is Operation { | ||
return Operation.is(object) && object.kind === kind; | ||
} | ||
} | ||
/** | ||
* An operation that executes a list of sub-operations. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `CompoundOperations`. | ||
*/ | ||
export class CompoundOperation implements Operation { | ||
static readonly KIND = 'compound'; | ||
constructor(public operationList: Operation[], public readonly kind: string = CompoundOperation.KIND) {} | ||
export interface CompoundOperation extends Operation { | ||
kind: typeof CompoundOperation.KIND; | ||
/** | ||
* List of operations that should be executed. | ||
*/ | ||
operationList: Operation[]; | ||
} | ||
export function isCompoundOperation(operation?: any): operation is CompoundOperation { | ||
return isActionKind(operation, CompoundOperation.KIND) && isArray(operation, 'operationList'); | ||
export namespace CompoundOperation { | ||
export const KIND = 'compound'; | ||
export function is(object: any): object is CompoundOperation { | ||
return Operation.hasKind(object, KIND) && hasArrayProp(object, 'operationList'); | ||
} | ||
export function create(operationList: Operation[]): CompoundOperation { | ||
return { | ||
kind: KIND, | ||
isOperation: true, | ||
operationList | ||
}; | ||
} | ||
} |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -16,51 +16,102 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import { isNumber, isString } from '../utils/typeguard-util'; | ||
import { Action, isActionKind } from './base-protocol'; | ||
import { hasStringProp } from '../utils/type-util'; | ||
import { Action } from './base-protocol'; | ||
export type ServerSeverity = 'NONE' | 'INFO' | 'WARNING' | 'ERROR' | 'FATAL' | 'OK'; | ||
/** | ||
* This action is typically sent by the server to signal a state change. This action extends the corresponding Sprotty action to include | ||
* a timeout. If a timeout is given the respective status should disappear after the timeout is reached. | ||
* Sent by the server to signal a state change. | ||
* If a timeout is given the respective status should disappear after the timeout is reached. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `ServerStatusActions`. | ||
*/ | ||
export class GLSPServerStatusAction implements Action { | ||
static KIND = 'serverStatus'; | ||
export interface ServerStatusAction extends Action { | ||
kind: typeof ServerStatusAction.KIND; | ||
/** | ||
* The severity of the status. | ||
*/ | ||
severity: ServerSeverity; | ||
constructor( | ||
public severity: ServerSeverity, | ||
public message: string, | ||
public timeout = -1, | ||
readonly kind = GLSPServerStatusAction.KIND | ||
) {} | ||
/** | ||
* The user-facing message describing the status. | ||
*/ | ||
message: string; | ||
/** | ||
* Timeout after which a displayed status should disappear. | ||
*/ | ||
timeout?: number; | ||
} | ||
export function isGLSPServerStatusAction(action: any): action is GLSPServerStatusAction { | ||
return ( | ||
isActionKind(action, GLSPServerStatusAction.KIND) && | ||
isString(action, 'severity') && | ||
isString(action, 'message') && | ||
isNumber(action, 'timeout') | ||
); | ||
export namespace ServerStatusAction { | ||
export const KIND = 'serverStatus'; | ||
export function is(object: any): object is ServerStatusAction { | ||
return Action.hasKind(object, KIND) && hasStringProp(object, 'severity') && hasStringProp(object, 'message'); | ||
} | ||
export function create(message: string, options: { severity?: ServerSeverity; timeout?: number } = {}): ServerStatusAction { | ||
return { | ||
kind: KIND, | ||
severity: 'INFO', | ||
message, | ||
...options | ||
}; | ||
} | ||
} | ||
/** | ||
* This action is typically sent by the server to notify the user about something of interest. | ||
* The possible server status severity levels. | ||
*/ | ||
export class ServerMessageAction implements Action { | ||
static KIND = 'serverMessage'; | ||
constructor( | ||
public severity: ServerSeverity, | ||
public message: string, | ||
public details?: string, | ||
public timeout = -1, | ||
readonly kind = ServerMessageAction.KIND | ||
) {} | ||
export type ServerSeverity = 'NONE' | 'INFO' | 'WARNING' | 'ERROR' | 'FATAL' | 'OK'; | ||
/** | ||
* Sent by the server to notify the user about something of interest. Typically this message is handled by | ||
* the client by showing a message to the user with the application's message service. | ||
* If a timeout is given the respective message should disappear after the timeout is reached. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `ServerMessageActions`. | ||
*/ | ||
export interface ServerMessageAction extends Action { | ||
kind: typeof ServerMessageAction.KIND; | ||
severity: ServerSeverity; | ||
/** | ||
* The message that shall be shown to the user. | ||
*/ | ||
message: string; | ||
/** | ||
* Further details on the message. | ||
*/ | ||
details?: string; | ||
/** | ||
* Timeout after which a displayed message disappears. | ||
*/ | ||
timeout?: number; | ||
} | ||
export function isServerMessageAction(action?: any): action is ServerMessageAction { | ||
return ( | ||
isActionKind(action, ServerMessageAction.KIND) && | ||
isString(action, 'severity') && | ||
isString(action, 'message') && | ||
isNumber(action, 'timeout') | ||
); | ||
export namespace ServerMessageAction { | ||
export const KIND = 'serverMessage'; | ||
export function is(object: any): object is ServerMessageAction { | ||
return Action.hasKind(object, KIND) && hasStringProp(object, 'message') && hasStringProp(object, 'severity'); | ||
} | ||
export function create( | ||
message: string, | ||
options: { | ||
severity?: ServerSeverity; | ||
details?: string; | ||
timeout?: number; | ||
} = {} | ||
): ServerMessageAction { | ||
return { | ||
kind: KIND, | ||
message, | ||
severity: 'INFO', | ||
...options | ||
}; | ||
} | ||
} |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -17,4 +17,4 @@ * This program and the accompanying materials are made available under the | ||
import { isObject, isString } from '../utils/typeguard-util'; | ||
import { generateRequestId, isActionKind, Operation, RequestAction, ResponseAction } from './base-protocol'; | ||
import { hasObjectProp } from '../utils/type-util'; | ||
import { Action, Operation, RequestAction, ResponseAction } from './base-protocol'; | ||
import { EditorContext } from './types'; | ||
@@ -24,19 +24,26 @@ | ||
* Requests the clipboard data for the current editor context, i.e., the selected elements, in a clipboard-compatible format. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `RequestClipboardDataActions`. | ||
*/ | ||
export class RequestClipboardDataAction implements RequestAction<SetClipboardDataAction> { | ||
static readonly KIND = 'requestClipboardData'; | ||
export interface RequestClipboardDataAction extends RequestAction<SetClipboardDataAction> { | ||
kind: typeof RequestClipboardDataAction.KIND; | ||
constructor( | ||
public readonly editorContext: EditorContext, | ||
public readonly requestId: string = generateRequestId(), | ||
public readonly kind: string = RequestClipboardDataAction.KIND | ||
) {} | ||
editorContext: EditorContext; | ||
} | ||
static create(editorContext: EditorContext): RequestAction<SetClipboardDataAction> { | ||
return new RequestClipboardDataAction(editorContext); | ||
export namespace RequestClipboardDataAction { | ||
export const KIND = 'requestClipboardData'; | ||
export function is(object: any): object is RequestClipboardDataAction { | ||
return RequestAction.hasKind(object, KIND) && hasObjectProp(object, 'editorContext'); | ||
} | ||
} | ||
export function isRequestClipboardDataAction(action: any): action is RequestClipboardDataAction { | ||
return isActionKind(action, RequestClipboardDataAction.KIND) && isObject(action, 'editorContext') && isString(action, 'requestId'); | ||
export function create(editorContext: EditorContext, options: { requestId?: string } = {}): RequestClipboardDataAction { | ||
return { | ||
kind: KIND, | ||
requestId: '', | ||
editorContext, | ||
...options | ||
}; | ||
} | ||
} | ||
@@ -46,15 +53,29 @@ | ||
* Server response to a {@link RequestClipboardDataAction} containing the selected elements as clipboard-compatible format. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetClipboardDataActions`. | ||
*/ | ||
export class SetClipboardDataAction implements ResponseAction { | ||
static readonly KIND = 'setClipboardData'; | ||
export interface SetClipboardDataAction extends ResponseAction { | ||
kind: typeof SetClipboardDataAction.KIND; | ||
constructor( | ||
public readonly clipboardData: ClipboardData, | ||
public readonly responseId: string = '', | ||
public readonly kind: string = SetClipboardDataAction.KIND | ||
) {} | ||
/** | ||
* The data to be added into the clipboard. This data will be sent back to the server on paste. | ||
*/ | ||
clipboardData: ClipboardData; | ||
} | ||
export function isSetClipboardDataAction(action: any): action is SetClipboardDataAction { | ||
return isActionKind(action, SetClipboardDataAction.KIND) && isObject(action, 'clipboardData') && isString(action, 'responseId'); | ||
export namespace SetClipboardDataAction { | ||
export const KIND = 'setClipboardData'; | ||
export function is(object: any): object is SetClipboardDataAction { | ||
return Action.hasKind(object, KIND) && hasObjectProp(object, 'clipboardData'); | ||
} | ||
export function create(clipboardData: ClipboardData, options: { responseId?: string } = {}): SetClipboardDataAction { | ||
return { | ||
kind: KIND, | ||
responseId: '', | ||
clipboardData, | ||
...options | ||
}; | ||
} | ||
} | ||
@@ -65,11 +86,25 @@ | ||
* a client should ensure that the cut elements are put into the clipboard. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `CutOperations`. | ||
*/ | ||
export class CutOperation implements Operation { | ||
static readonly KIND = 'cut'; | ||
export interface CutOperation extends Operation { | ||
kind: typeof CutOperation.KIND; | ||
constructor(public readonly editorContext: EditorContext, public readonly kind: string = CutOperation.KIND) {} | ||
editorContext: EditorContext; | ||
} | ||
export function isCutOperation(action: any): action is CutOperation { | ||
return isActionKind(action, CutOperation.KIND) && isObject(action, 'editorContext'); | ||
export namespace CutOperation { | ||
export const KIND = 'cut'; | ||
export function is(object: any): object is CutOperation { | ||
return Operation.hasKind(object, KIND) && hasObjectProp(object, 'editorContext'); | ||
} | ||
export function create(editorContext: EditorContext): CutOperation { | ||
return { | ||
kind: KIND, | ||
isOperation: true, | ||
editorContext | ||
}; | ||
} | ||
} | ||
@@ -80,19 +115,37 @@ | ||
* based on the data in the clipboard. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `PasteOperations`. | ||
*/ | ||
export class PasteOperation implements Operation { | ||
static readonly KIND = 'paste'; | ||
export interface PasteOperation extends Operation { | ||
kind: typeof PasteOperation.KIND; | ||
constructor( | ||
public readonly clipboardData: ClipboardData, | ||
public readonly editorContext: EditorContext, | ||
public readonly kind: string = PasteOperation.KIND | ||
) {} | ||
editorContext: EditorContext; | ||
/** | ||
* The clipboard data that should be pasted to the editor's last recorded mouse position (see `editorContext`). | ||
*/ | ||
clipboardData: ClipboardData; | ||
} | ||
export function isPasteOperation(action: any): action is PasteOperation { | ||
return isActionKind(action, PasteOperation.KIND) && isObject(action, 'clipboardData') && isObject(action, 'editorContext'); | ||
export namespace PasteOperation { | ||
export const KIND = 'paste'; | ||
export function is(object: any): object is PasteOperation { | ||
return Operation.hasKind(object, KIND) && hasObjectProp(object, 'clipboardData') && hasObjectProp(object, 'editorContext'); | ||
} | ||
export function create(options: { editorContext: EditorContext; clipboardData: ClipboardData }): PasteOperation { | ||
return { | ||
kind: KIND, | ||
isOperation: true, | ||
...options | ||
}; | ||
} | ||
} | ||
/** | ||
* In GLSP the clipboard needs to be managed by the client but the conversion from the selection to be copied into a | ||
* clipboard-compatible format is handled by the server. By default, GLSP use application/json as exchange format. | ||
*/ | ||
export interface ClipboardData { | ||
[format: string]: string; | ||
} |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -17,4 +17,4 @@ * This program and the accompanying materials are made available under the | ||
import { isArray, isObject, isString } from '../utils/typeguard-util'; | ||
import { generateRequestId, isActionKind, RequestAction, ResponseAction } from './base-protocol'; | ||
import { hasArrayProp, hasObjectProp, hasStringProp } from '../utils/type-util'; | ||
import { Action, RequestAction, ResponseAction } from './base-protocol'; | ||
import { Args, EditorContext, LabeledAction } from './types'; | ||
@@ -24,20 +24,30 @@ | ||
* The `RequestContextActions` is sent from the client to the server to request the available actions for the context with id contextId. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `RequestContextActions`. | ||
*/ | ||
export class RequestContextActions implements RequestAction<SetContextActions> { | ||
static readonly KIND = 'requestContextActions'; | ||
constructor( | ||
public readonly contextId: string, | ||
public readonly editorContext: EditorContext, | ||
public readonly requestId: string = generateRequestId(), | ||
public readonly kind: string = RequestContextActions.KIND | ||
) {} | ||
export interface RequestContextActions extends RequestAction<SetContextActions> { | ||
kind: typeof RequestContextActions.KIND; | ||
/** | ||
* The identifier for the context. | ||
*/ | ||
contextId: string; | ||
editorContext: EditorContext; | ||
} | ||
export function isRequestContextActions(action: any): action is RequestContextActions { | ||
return ( | ||
isActionKind(action, RequestContextActions.KIND) && | ||
isString(action, 'contextId') && | ||
isObject(action, 'editorContext') && | ||
isString(action, 'requestId') | ||
); | ||
export namespace RequestContextActions { | ||
export const KIND = 'requestContextActions'; | ||
export function is(object: any): object is RequestContextActions { | ||
return RequestAction.hasKind(object, KIND) && hasStringProp(object, 'contextId') && hasObjectProp(object, 'editorContext'); | ||
} | ||
export function create(options: { contextId: string; editorContext: EditorContext; requestId?: string }): RequestContextActions { | ||
return { | ||
kind: KIND, | ||
requestId: '', | ||
...options | ||
}; | ||
} | ||
} | ||
@@ -47,15 +57,34 @@ | ||
* The `SetContextActions` is the response to a {@link RequestContextActions} containing all actions for the queried context. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetContextsActions`. | ||
*/ | ||
export class SetContextActions implements ResponseAction { | ||
static readonly KIND = 'setContextActions'; | ||
constructor( | ||
public readonly actions: LabeledAction[], | ||
public readonly responseId: string = '', | ||
public readonly args?: Args, | ||
public readonly kind: string = SetContextActions.KIND | ||
) {} | ||
export interface SetContextActions extends ResponseAction { | ||
kind: typeof SetContextActions.KIND; | ||
/** | ||
* The actions available in the queried context. | ||
*/ | ||
readonly actions: LabeledAction[]; | ||
/** | ||
* Custom arguments. | ||
*/ | ||
args?: Args; | ||
} | ||
export function isSetContextActionsAction(action: any): action is SetContextActions { | ||
return isActionKind(action, SetContextActions.KIND) && isArray(action, 'actions') && isString(action, 'responseId'); | ||
export namespace SetContextActions { | ||
export const KIND = 'setContextActions'; | ||
export function is(object: any): object is SetContextActions { | ||
return Action.hasKind(object, KIND) && hasArrayProp(object, 'actions'); | ||
} | ||
export function create(actions: LabeledAction[], options: { args?: Args; responseId?: string } = {}): SetContextActions { | ||
return { | ||
kind: KIND, | ||
responseId: '', | ||
actions, | ||
...options | ||
}; | ||
} | ||
} |
/******************************************************************************** | ||
* Copyright (c) 2021 EclipseSource and others. | ||
* Copyright (c) 2021-2022 EclipseSource and others. | ||
* | ||
@@ -17,26 +17,59 @@ * This program and the accompanying materials are made available under the | ||
import { isArray, isString } from '../utils/typeguard-util'; | ||
import { isActionKind, Operation } from './base-protocol'; | ||
import { ElementAndRoutingPoints } from './types'; | ||
import { hasArrayProp, hasStringProp } from '../utils/type-util'; | ||
import { Operation } from './base-protocol'; | ||
import { Args, ElementAndRoutingPoints } from './types'; | ||
/** | ||
* If the source and/or target element of an edge should be adapted, the client can send a `ReconnectEdgeOperation` to the server. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `ReconnectEdgeOperations`. | ||
*/ | ||
export class ReconnectEdgeOperation implements Operation { | ||
static readonly KIND = 'reconnectEdge'; | ||
constructor( | ||
public readonly edgeElementId: string, | ||
public readonly sourceElementId: string, | ||
public readonly targetElementId: string, | ||
public readonly kind: string = ReconnectEdgeOperation.KIND | ||
) {} | ||
export interface ReconnectEdgeOperation extends Operation { | ||
kind: typeof ReconnectEdgeOperation.KIND; | ||
/** | ||
* The edge element that should be reconnected. | ||
*/ | ||
edgeElementId: string; | ||
/** | ||
* The (new) source element of the edge. | ||
*/ | ||
sourceElementId: string; | ||
/** | ||
* The (new) target element of the edge. | ||
*/ | ||
targetElementId: string; | ||
/* | ||
* Additional arguments for custom behavior. | ||
*/ | ||
args?: Args; | ||
} | ||
export function isReconnectEdgeOperation(action: any): action is ReconnectEdgeOperation { | ||
return ( | ||
isActionKind(action, ReconnectEdgeOperation.KIND) && | ||
isString(action, 'edgeElementId') && | ||
isString(action, 'sourceElementId') && | ||
isString(action, 'targetElementId') | ||
); | ||
export namespace ReconnectEdgeOperation { | ||
export const KIND = 'reconnectEdge'; | ||
export function is(object: any): object is ReconnectEdgeOperation { | ||
return ( | ||
Operation.hasKind(object, KIND) && | ||
hasStringProp(object, 'edgeElementId') && | ||
hasStringProp(object, 'sourceElementId') && | ||
hasStringProp(object, 'targetElementId') | ||
); | ||
} | ||
export function create(options: { | ||
edgeElementId: string; | ||
sourceElementId: string; | ||
targetElementId: string; | ||
args?: Args; | ||
}): ReconnectEdgeOperation { | ||
return { | ||
kind: KIND, | ||
isOperation: true, | ||
...options | ||
}; | ||
} | ||
} | ||
@@ -47,10 +80,28 @@ | ||
* routing points the client may send a `ChangeRoutingPointsOperation`. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `ChangeRoutingPointsOperations`. | ||
*/ | ||
export class ChangeRoutingPointsOperation implements Operation { | ||
static readonly KIND = 'changeRoutingPoints'; | ||
constructor(public newRoutingPoints: ElementAndRoutingPoints[], public readonly kind: string = ChangeRoutingPointsOperation.KIND) {} | ||
export interface ChangeRoutingPointsOperation extends Operation { | ||
kind: typeof ChangeRoutingPointsOperation.KIND; | ||
/** | ||
* The routing points of the edge (may be empty). | ||
*/ | ||
newRoutingPoints: ElementAndRoutingPoints[]; | ||
} | ||
export function isChangeRoutingsPointsOperation(action: any): action is ChangeRoutingPointsOperation { | ||
return isActionKind(action, ChangeRoutingPointsOperation.KIND) && isArray(action, 'newRoutingPoints'); | ||
export namespace ChangeRoutingPointsOperation { | ||
export const KIND = 'changeRoutingPoints'; | ||
export function is(object: any): object is ChangeRoutingPointsOperation { | ||
return Operation.hasKind(object, KIND) && hasArrayProp(object, 'newRoutingPoints'); | ||
} | ||
export function create(newRoutingPoints: ElementAndRoutingPoints[]): ChangeRoutingPointsOperation { | ||
return { | ||
kind: KIND, | ||
isOperation: true, | ||
newRoutingPoints | ||
}; | ||
} | ||
} |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -17,67 +17,142 @@ * This program and the accompanying materials are made available under the | ||
import { isArray, isString } from '../utils/typeguard-util'; | ||
import { isAction, isActionKind, Operation } from './base-protocol'; | ||
import { Args, Point } from './types'; | ||
import { Point } from 'sprotty-protocol'; | ||
import { hasArrayProp, hasStringProp } from '../utils/type-util'; | ||
import { Operation } from './base-protocol'; | ||
import { Args } from './types'; | ||
/** | ||
* Common interface for all create {@link Operation}s in GLSP. | ||
* The corresponding namespace offers a helper function for type guard checks. | ||
*/ | ||
export interface CreateOperation extends Operation { | ||
/** | ||
* The type of the element that should be created. | ||
*/ | ||
elementTypeId: string; | ||
/** | ||
* Optional additional arguments for the server to execute the create operation. | ||
*/ | ||
args?: Args; | ||
} | ||
export function isCreateOperation(action: any): action is CreateOperation { | ||
return isAction(action) && isString(action, 'elementTypeId'); | ||
export namespace CreateOperation { | ||
export function is(object: any): object is CreateOperation { | ||
return Operation.is(object) && hasStringProp(object, 'elementTypeId'); | ||
} | ||
/** | ||
* Typeguard function to check wether the given object is a {@link CreateOperation} with the given `kind`. | ||
* @param object The object to check. | ||
* @param kind The expected operation kind. | ||
* @returns A type literal indicating wether the given object is a create operation with the given kind. | ||
*/ | ||
export function hasKind(object: any, kind: string): object is CreateOperation { | ||
return CreateOperation.is(object) && object.kind === kind; | ||
} | ||
} | ||
/** | ||
* In order to create a node in the model the client can send a CreateNodeOperation with the necessary information to create that node. | ||
* In order to create a node in the model the client can send a CreateNodeOperation with the necessary information to create | ||
* the element that corresponds to that node in the source model. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `CreateNodeOperations`. | ||
*/ | ||
export class CreateNodeOperation implements CreateOperation { | ||
static readonly KIND = 'createNode'; | ||
export interface CreateNodeOperation extends CreateOperation { | ||
kind: typeof CreateNodeOperation.KIND; | ||
constructor( | ||
public readonly elementTypeId: string, | ||
public location?: Point, | ||
public containerId?: string, | ||
public args?: Args, | ||
public readonly kind: string = CreateNodeOperation.KIND | ||
) {} | ||
/* | ||
* The location at which the operation shall be executed. | ||
*/ | ||
location?: Point; | ||
/* | ||
* The id of container element in which the node should be created. If not defined | ||
* the root element will be used. | ||
*/ | ||
containerId?: string; | ||
} | ||
export function isCreateNodeOperation(action: any): action is CreateNodeOperation { | ||
return isActionKind(action, CreateNodeOperation.KIND) && isString(action, 'elementTypeId'); | ||
export namespace CreateNodeOperation { | ||
export const KIND = 'createNode'; | ||
export function is(object: any): object is CreateNodeOperation { | ||
return CreateOperation.hasKind(object, KIND); | ||
} | ||
export function create( | ||
elementTypeId: string, | ||
options: { location?: Point; containerId?: string; args?: Args } = {} | ||
): CreateNodeOperation { | ||
return { | ||
kind: KIND, | ||
isOperation: true, | ||
elementTypeId, | ||
...options | ||
}; | ||
} | ||
} | ||
/** | ||
* In order to create an edge in the model the client can send a `CreateEdgeOperation` with the necessary information to create that edge. | ||
* In order to create an edge in the model the client can send a `CreateEdgeOperation` with the necessary information to create | ||
* the element that corresponds to that edge in the source model. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `CreateEdgeOperations`. | ||
*/ | ||
export class CreateEdgeOperation implements CreateOperation { | ||
static readonly KIND = 'createEdge'; | ||
export interface CreateEdgeOperation extends CreateOperation { | ||
kind: typeof CreateEdgeOperation.KIND; | ||
constructor( | ||
public readonly elementTypeId: string, | ||
public sourceElementId: string, | ||
public targetElementId: string, | ||
public args?: Args, | ||
public readonly kind: string = CreateEdgeOperation.KIND | ||
) {} | ||
sourceElementId: string; | ||
targetElementId: string; | ||
} | ||
export function isCreateEdgeOperation(action: any): action is CreateEdgeOperation { | ||
return ( | ||
isActionKind(action, CreateEdgeOperation.KIND) && | ||
isString(action, 'elementTypeId') && | ||
isString(action, 'sourceElementId') && | ||
isString(action, 'targetElementId') | ||
); | ||
export namespace CreateEdgeOperation { | ||
export const KIND = 'createEdge'; | ||
export function is(object: any): object is CreateEdgeOperation { | ||
return ( | ||
CreateOperation.hasKind(object, KIND) && hasStringProp(object, 'sourceElementId') && hasStringProp(object, 'targetElementId') | ||
); | ||
} | ||
export function create(options: { | ||
elementTypeId: string; | ||
sourceElementId: string; | ||
targetElementId: string; | ||
args?: Args; | ||
}): CreateEdgeOperation { | ||
return { | ||
kind: KIND, | ||
isOperation: true, | ||
...options | ||
}; | ||
} | ||
} | ||
/** | ||
* The client sends a `DeleteElementOperation` to the server to request the deletion of an element from the model. | ||
* The client sends a `DeleteElementOperation` to the server to request the deletion of an element from the source model. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `DeleteElementOperations`. | ||
*/ | ||
export class DeleteElementOperation implements Operation { | ||
static readonly KIND = 'deleteElement'; | ||
constructor(readonly elementIds: string[], public readonly kind: string = DeleteElementOperation.KIND) {} | ||
export interface DeleteElementOperation extends Operation { | ||
kind: typeof DeleteElementOperation.KIND; | ||
/** | ||
* The ids of the elements to be deleted. | ||
*/ | ||
elementIds: string[]; | ||
} | ||
export function isDeleteElementOperation(action: any): action is DeleteElementOperation { | ||
return isActionKind(action, DeleteElementOperation.KIND) && isArray(action, 'elementIds'); | ||
export namespace DeleteElementOperation { | ||
export const KIND = 'deleteElement'; | ||
export function is(object: any): object is DeleteElementOperation { | ||
return Operation.hasKind(object, KIND) && hasArrayProp(object, 'elementIds'); | ||
} | ||
export function create(elementIds: string[]): DeleteElementOperation { | ||
return { | ||
kind: KIND, | ||
isOperation: true, | ||
elementIds | ||
}; | ||
} | ||
} |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -16,6 +16,7 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import { isObject, isString } from '../utils/typeguard-util'; | ||
import { generateRequestId, isActionKind, RequestAction, ResponseAction } from './base-protocol'; | ||
import { Bounds } from 'sprotty-protocol'; | ||
import * as sprotty from 'sprotty-protocol/lib/actions'; | ||
import { hasObjectProp, hasStringProp } from '../utils/type-util'; | ||
import { Action, RequestAction, ResponseAction } from './base-protocol'; | ||
import { SModelRootSchema } from './model-structure'; | ||
import { Bounds } from './types'; | ||
@@ -25,22 +26,33 @@ /** | ||
* This action is sent from the client to the server. The response is a `SetPopupModelAction`. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `RequestPopupModelActions`. | ||
*/ | ||
export class RequestPopupModelAction implements RequestAction<SetPopupModelAction> { | ||
static readonly KIND = 'requestPopupModel'; | ||
readonly kind = RequestPopupModelAction.KIND; | ||
export interface RequestPopupModelAction extends RequestAction<SetPopupModelAction>, sprotty.RequestPopupModelAction { | ||
kind: typeof RequestPopupModelAction.KIND; | ||
constructor(public readonly elementId: string, public readonly bounds: Bounds, public readonly requestId = '') {} | ||
/** | ||
* The identifier of the elements for which a popup is requested. | ||
*/ | ||
elementId: string; | ||
/** Factory function to dispatch a request with the `IActionDispatcher` */ | ||
static create(elementId: string, bounds: Bounds): RequestAction<SetPopupModelAction> { | ||
return new RequestPopupModelAction(elementId, bounds, generateRequestId()); | ||
} | ||
/** | ||
* The popup bounds declaring the position of the popup. Optionally the desired dimension. | ||
*/ | ||
bounds: Bounds; | ||
} | ||
export function isRequestPopupModelAction(action: any): action is RequestPopupModelAction { | ||
return ( | ||
isActionKind(action, RequestPopupModelAction.KIND) && | ||
isString(action, 'elementId') && | ||
isObject(action, 'bounds') && | ||
isString(action, 'requestId') | ||
); | ||
export namespace RequestPopupModelAction { | ||
export const KIND = 'requestPopupModel'; | ||
export function is(object: any): object is RequestPopupModelAction { | ||
return RequestAction.hasKind(object, KIND) && hasStringProp(object, 'elementId') && hasObjectProp(object, 'bounds'); | ||
} | ||
export function create(options: { elementId: string; bounds: Bounds; requestId?: string }): RequestPopupModelAction { | ||
return { | ||
kind: KIND, | ||
requestId: '', | ||
...options | ||
}; | ||
} | ||
} | ||
@@ -51,12 +63,26 @@ | ||
* any existing popup by choosing EMPTY_ROOT as root element. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetPopupModelActions`. | ||
*/ | ||
export class SetPopupModelAction implements ResponseAction { | ||
static readonly KIND = 'setPopupModel'; | ||
readonly kind = SetPopupModelAction.KIND; | ||
export interface SetPopupModelAction extends ResponseAction, sprotty.SetPopupModelAction { | ||
kind: typeof SetPopupModelAction.KIND; | ||
constructor(public readonly newRoot: SModelRootSchema, public readonly responseId = '') {} | ||
newRoot: SModelRootSchema; | ||
} | ||
export function isSetPopupModelAction(action: any): action is SetPopupModelAction { | ||
return isActionKind(action, SetPopupModelAction.KIND) && isObject(action, 'newRoot') && isString(action, 'responseId'); | ||
export namespace SetPopupModelAction { | ||
export const KIND = 'setPopupModel'; | ||
export function is(object: any): object is SetPopupModelAction { | ||
return Action.hasKind(object, KIND) && hasObjectProp(object, 'newRoot'); | ||
} | ||
export function create(newRoot: SModelRootSchema, options: { responseId?: string } = {}): SetPopupModelAction { | ||
return { | ||
kind: KIND, | ||
responseId: '', | ||
newRoot, | ||
...options | ||
}; | ||
} | ||
} |
/******************************************************************************** | ||
* Copyright (c) 2020-2021 EclipseSource and others. | ||
* Copyright (c) 2020-2022 EclipseSource and others. | ||
* | ||
@@ -16,12 +16,25 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import { isArray, isObject, isString } from '../utils/typeguard-util'; | ||
import { Action, generateRequestId, isActionKind, RequestAction, ResponseAction } from './base-protocol'; | ||
import { JsonPrimitive } from 'sprotty-protocol'; | ||
import { hasArrayProp, hasObjectProp, hasStringProp } from '../utils/type-util'; | ||
import { Action, RequestAction, ResponseAction } from './base-protocol'; | ||
import { Args, EditorContext } from './types'; | ||
/** | ||
* A NavigationTarget identifies the object we want to navigate to via its uri and may further provide a label to display for the client. | ||
* A `NavigationTarget` identifies the object we want to navigate to via its uri and may further provide a label to display to the user. | ||
* The corresponding namespace offers a set of utility function to interact with `NavigationTargets`. | ||
*/ | ||
export interface NavigationTarget { | ||
/** | ||
* URI to identify the object we want to navigate to. | ||
*/ | ||
uri: string; | ||
/** | ||
* Optional label to display to the user. | ||
*/ | ||
label?: string; | ||
/** | ||
* Domain-specific arguments that may be interpreted directly or resolved further. | ||
*/ | ||
args?: Args; | ||
@@ -31,12 +44,38 @@ } | ||
export namespace NavigationTarget { | ||
export function is(object: any): object is NavigationTarget { | ||
return object !== undefined && hasStringProp(object, 'uri'); | ||
} | ||
/** | ||
* Generic key to store element ids as additional argument | ||
*/ | ||
export const ELEMENT_IDS = 'elementIds'; | ||
/** | ||
* The separator that is used to store he values for the {@link ELEMENT_IDS} as a single string. | ||
*/ | ||
export const ELEMENT_IDS_SEPARATOR = '&'; | ||
/** | ||
* Generic key ot store the line property of a {@link TextPosition} as additional argument. | ||
*/ | ||
export const TEXT_LINE = 'line'; | ||
/** | ||
* Generic key ot store the character property of a {@link TextPosition} as additional argument. | ||
*/ | ||
export const TEXT_COLUMN = 'column'; | ||
/** | ||
* Denotes the position of the cursor in a text element. | ||
*/ | ||
export interface TextPosition { | ||
line: number; | ||
/** | ||
* The character number within the line. Also refereed to as column. | ||
*/ | ||
character: number; | ||
} | ||
/** | ||
* Utility function to check wether the given {@link NavigationTarget} has additional arguments defined. | ||
* @param target The navigation target to check. | ||
* @returns `true` if the navigation target has a non-empty `args` property, `false` | ||
*/ | ||
export function hasArguments(target: NavigationTarget): boolean { | ||
@@ -46,4 +85,10 @@ return target.args !== undefined && Object.keys(target.args).length > 0; | ||
export function addArgument(target: NavigationTarget, key: string, value: string | number | boolean): void { | ||
if (target.args === undefined) { | ||
/** | ||
* Adds a new key-value pair to the additional arguments of the given {@link NavigationTarget}. | ||
* @param target The navigation target. | ||
* @param key The key of the new argument. | ||
* @param value The (primitive) value of the new argument. | ||
*/ | ||
export function addArgument(target: NavigationTarget, key: string, value: JsonPrimitive): void { | ||
if (!target.args) { | ||
target.args = {}; | ||
@@ -54,4 +99,11 @@ } | ||
/** | ||
* Retrieves the element ids that have been stored with the generic {@link ELEMENT_IDS} key from the args of the | ||
* given target. | ||
* @param target The navigation target. | ||
* @returns An array with the parsed element ids. The array is empty if no {@link ELEMENT_IDS} key is present in the args | ||
* of the navigation target. | ||
*/ | ||
export function getElementIds(target: NavigationTarget): string[] { | ||
if (target.args === undefined || target.args[ELEMENT_IDS] === undefined) { | ||
if (!target?.args?.[ELEMENT_IDS]) { | ||
return []; | ||
@@ -63,3 +115,9 @@ } | ||
export function setElementIds(target: NavigationTarget, elementIds: string[]): string { | ||
/** | ||
* Stores the given element ids in the given {@link NavigationTarget} as additional arguments using the generic {@link ELEMENT_IDS} key. | ||
* @param target The navigation target. | ||
* @param elementIds The element ids that should be stored. | ||
* @returns the value of the {@link ELEMENT_IDS} key after storing the given element ids. | ||
*/ | ||
export function setElementIds(target: NavigationTarget, ...elementIds: string[]): string { | ||
if (target.args === undefined) { | ||
@@ -71,2 +129,8 @@ target.args = {}; | ||
/** | ||
* Stores the given {@link TextPosition} in the given {@link NavigationTarget} as additional arguments using | ||
* the generic {@link TEXT_LINE} & {@link TEXT_COLUMN} keys. | ||
* @param target The navigation target. | ||
* @param position The text position that should be stored. | ||
*/ | ||
export function setTextPosition(target: NavigationTarget, position: TextPosition | undefined): void { | ||
@@ -82,4 +146,11 @@ if (position) { | ||
/** | ||
* Retrieves the {@link TextPosition} that have been stored with the generic {@link TEXT_LINE} & {@link TEXT_COLUMN} keys | ||
* from the args of the given target. | ||
* @param target The navigation target. | ||
* @returns The parsed text position or `undefined` if one of the generic text keys is not present in the args | ||
* of the navigation target. | ||
*/ | ||
export function getTextPosition(target: NavigationTarget): TextPosition | undefined { | ||
if (target.args === undefined || target.args[TEXT_LINE] === undefined || target.args[TEXT_COLUMN] === undefined) { | ||
if (!target.args || !target.args[TEXT_LINE] || !target.args[TEXT_COLUMN]) { | ||
return undefined; | ||
@@ -96,17 +167,35 @@ } | ||
* Action that is usually sent from the client to the server to request navigation targets for a specific navigation type such as | ||
* documentation or implementation in the given editor context. | ||
* `documentation` or `implementation` in the given editor context. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `RequestNavigationTargetsActions`. | ||
*/ | ||
export class RequestNavigationTargetsAction implements RequestAction<SetNavigationTargetsAction> { | ||
static readonly KIND = 'requestNavigationTargets'; | ||
kind = RequestNavigationTargetsAction.KIND; | ||
constructor(readonly targetTypeId: string, readonly editorContext: EditorContext, readonly requestId: string = generateRequestId()) {} | ||
export interface RequestNavigationTargetsAction extends RequestAction<SetNavigationTargetsAction> { | ||
kind: typeof RequestNavigationTargetsAction.KIND; | ||
/** | ||
* Identifier of the type of navigation targets we want to retrieve, e.g., 'documentation', 'implementation', etc. | ||
*/ | ||
targetTypeId: string; | ||
editorContext: EditorContext; | ||
} | ||
export function isRequestNavigationTargetsAction(action: any): action is RequestNavigationTargetsAction { | ||
return ( | ||
isActionKind(action, RequestNavigationTargetsAction.KIND) && | ||
isString(action, 'targetTypeId') && | ||
isObject(action, 'editorContext') && | ||
isString(action, 'requestId') | ||
); | ||
export namespace RequestNavigationTargetsAction { | ||
export const KIND = 'requestNavigationTargets'; | ||
export function is(object: any): object is RequestNavigationTargetsAction { | ||
return RequestAction.hasKind(object, KIND) && hasStringProp(object, 'targetTypeId') && hasObjectProp(object, 'editorContext'); | ||
} | ||
export function create(options: { | ||
targetTypeId: string; | ||
editorContext: EditorContext; | ||
requestId?: string; | ||
}): RequestNavigationTargetsAction { | ||
return { | ||
kind: KIND, | ||
requestId: '', | ||
...options | ||
}; | ||
} | ||
} | ||
@@ -117,23 +206,58 @@ | ||
* queried target type in the provided editor context. The server may also provide additional information using the arguments, e.g., | ||
* warnings, that can be interpreted by the client. | ||
* warnings, that can be interpreted by the client. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetNavigationTargetsActions`. | ||
*/ | ||
export class SetNavigationTargetsAction implements ResponseAction { | ||
static readonly KIND = 'setNavigationTargets'; | ||
kind = SetNavigationTargetsAction.KIND; | ||
constructor(readonly targets: NavigationTarget[], readonly responseId: string = '', readonly args?: Args) {} | ||
export interface SetNavigationTargetsAction extends ResponseAction { | ||
kind: typeof SetNavigationTargetsAction.KIND; | ||
targets: NavigationTarget[]; | ||
/** | ||
* Custom arguments that may be interpreted by the client. | ||
*/ | ||
args?: Args; | ||
} | ||
export function isSetNavigationTargetsAction(action: any): action is SetNavigationTargetsAction { | ||
return isActionKind(action, SetNavigationTargetsAction.KIND) && isArray(action, 'targets') && isString(action, 'responseId'); | ||
export namespace SetNavigationTargetsAction { | ||
export const KIND = 'setNavigationTargets'; | ||
export function is(object: any): object is SetNavigationTargetsAction { | ||
return Action.hasKind(object, KIND) && hasArrayProp(object, 'targets'); | ||
} | ||
export function create(targets: NavigationTarget[], options: { args?: Args; responseId?: string } = {}): SetNavigationTargetsAction { | ||
return { | ||
kind: KIND, | ||
responseId: '', | ||
targets, | ||
...options | ||
}; | ||
} | ||
} | ||
/** Action that triggers the navigation to a particular navigation target, such as element IDs, queries, etc.. */ | ||
export class NavigateToTargetAction implements Action { | ||
static readonly KIND = 'navigateToTarget'; | ||
readonly kind = NavigateToTargetAction.KIND; | ||
constructor(readonly target: NavigationTarget) {} | ||
/** | ||
* Action that triggers the navigation to a particular navigation target, such as element IDs, queries, etc.. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `NavigateToTargetActions`. | ||
*/ | ||
export interface NavigateToTargetAction extends Action { | ||
kind: typeof NavigateToTargetAction.KIND; | ||
target: NavigationTarget; | ||
} | ||
export function isNavigateToTargetAction(action: any): action is NavigateToTargetAction { | ||
return isActionKind(action, NavigateToTargetAction.KIND) && isObject(action, 'target'); | ||
export namespace NavigateToTargetAction { | ||
export const KIND = 'navigateToTarget'; | ||
export function is(object: any): object is NavigateToTargetAction { | ||
return Action.hasKind(object, KIND) && hasObjectProp(object, 'target'); | ||
} | ||
export function create(target: NavigationTarget): NavigateToTargetAction { | ||
return { | ||
kind: KIND, | ||
target | ||
}; | ||
} | ||
} | ||
@@ -145,13 +269,29 @@ | ||
* client architecture requires an indirection. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `ResolveNavigationTargetActions`. | ||
*/ | ||
export class ResolveNavigationTargetAction implements RequestAction<SetResolvedNavigationTargetAction> { | ||
static readonly KIND = 'resolveNavigationTarget'; | ||
kind = ResolveNavigationTargetAction.KIND; | ||
constructor(readonly navigationTarget: NavigationTarget, public readonly requestId: string = generateRequestId()) {} | ||
export interface ResolveNavigationTargetAction extends RequestAction<SetResolvedNavigationTargetAction> { | ||
kind: typeof ResolveNavigationTargetAction.KIND; | ||
/** | ||
* The navigation target to resolve. | ||
*/ | ||
navigationTarget: NavigationTarget; | ||
} | ||
export function isResolveNavigationTargetAction(action: any): action is ResolveNavigationTargetAction { | ||
return ( | ||
isActionKind(action, ResolveNavigationTargetAction.KIND) && isObject(action, 'navigationTarget') && isString(action, 'requestId') | ||
); | ||
export namespace ResolveNavigationTargetAction { | ||
export const KIND = 'resolveNavigationTarget'; | ||
export function is(object: any): object is ResolveNavigationTargetAction { | ||
return RequestAction.hasKind(object, KIND) && hasObjectProp(object, 'navigationTarget'); | ||
} | ||
export function create(navigationTarget: NavigationTarget, options: { requestId?: string } = {}): ResolveNavigationTargetAction { | ||
return { | ||
kind: KIND, | ||
requestId: '', | ||
navigationTarget, | ||
...options | ||
}; | ||
} | ||
} | ||
@@ -162,11 +302,34 @@ | ||
* for the given target and may contain additional information in the args property. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetResolvedNavigationTargetActions`. | ||
*/ | ||
export class SetResolvedNavigationTargetAction implements ResponseAction { | ||
static readonly KIND = 'setResolvedNavigationTarget'; | ||
kind = SetResolvedNavigationTargetAction.KIND; | ||
constructor(readonly elementIds: string[] = [], readonly args?: Args, readonly responseId: string = '') {} | ||
export interface SetResolvedNavigationTargetAction extends ResponseAction { | ||
kind: typeof SetResolvedNavigationTargetAction.KIND; | ||
/** | ||
* The element ids of the resolved navigation target. | ||
*/ | ||
elementIds: string[]; | ||
/** | ||
* Custom arguments that may be interpreted by the client. | ||
*/ | ||
args?: Args; | ||
} | ||
export function isSetResolvedNavigationTargets(action: any): action is SetResolvedNavigationTargetAction { | ||
return isActionKind(action, SetResolvedNavigationTargetAction.KIND) && isArray(action, 'elementIds') && isString(action, 'responseId'); | ||
export namespace SetResolvedNavigationTargetAction { | ||
export const KIND = 'setResolvedNavigationTarget'; | ||
export function is(object: any): object is SetResolvedNavigationTargetAction { | ||
return Action.hasKind(object, KIND) && hasArrayProp(object, 'elementIds'); | ||
} | ||
export function create(elementIds: string[], options: { args?: Args; responseId?: string } = {}): SetResolvedNavigationTargetAction { | ||
return { | ||
kind: KIND, | ||
responseId: '', | ||
elementIds, | ||
...options | ||
}; | ||
} | ||
} | ||
@@ -178,11 +341,27 @@ | ||
* an action would be typically handled by an integration layer (such as the surrounding IDE). | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `NavigateToExternalTargetActions`. | ||
*/ | ||
export class NavigateToExternalTargetAction implements Action { | ||
static readonly KIND = 'navigateToExternalTarget'; | ||
readonly kind = NavigateToExternalTargetAction.KIND; | ||
constructor(readonly target: NavigationTarget) {} | ||
export interface NavigateToExternalTargetAction extends Action { | ||
kind: typeof NavigateToExternalTargetAction.KIND; | ||
/** | ||
* The diagram-external target to which the client shall navigate. | ||
*/ | ||
target: NavigationTarget; | ||
} | ||
export function isNavigateToExternalTargetAction(action: any): action is NavigateToExternalTargetAction { | ||
return isActionKind(action, NavigateToExternalTargetAction.KIND) && isObject(action, 'target'); | ||
export namespace NavigateToExternalTargetAction { | ||
export const KIND = 'navigateToExternalTarget'; | ||
export function is(object: any): object is NavigateToExternalTargetAction { | ||
return Action.hasKind(object, KIND) && hasObjectProp(object, 'target'); | ||
} | ||
export function create(target: NavigationTarget): NavigateToExternalTargetAction { | ||
return { | ||
kind: KIND, | ||
target | ||
}; | ||
} | ||
} |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -16,4 +16,5 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import { isArray, isBoolean } from '../utils/typeguard-util'; | ||
import { Action, isActionKind } from './base-protocol'; | ||
import * as sprotty from 'sprotty-protocol/lib/actions'; | ||
import { hasArrayProp, hasBooleanProp } from '../utils/type-util'; | ||
import { Action } from './base-protocol'; | ||
@@ -23,13 +24,35 @@ /** | ||
* selected state accordingly, so the elements can be rendered differently. The server can send such an action to the client in order to | ||
* change the selection remotely. | ||
* change the selection remotely. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SelectActions`. | ||
*/ | ||
export class SelectAction implements Action { | ||
static readonly KIND = 'elementSelected'; | ||
kind = SelectAction.KIND; | ||
export interface SelectAction extends Action, sprotty.SelectAction { | ||
kind: typeof SelectAction.KIND; | ||
constructor(public readonly selectedElementsIDs: string[] = [], public readonly deselectedElementsIDs: string[] = []) {} | ||
/** | ||
* The identifiers of the elements to mark as selected. | ||
*/ | ||
selectedElementsIDs: string[]; | ||
/** | ||
* The identifiers of the elements to mark as not selected. | ||
*/ | ||
deselectedElementsIDs: string[]; | ||
} | ||
export function isSelectAction(action: any): action is SelectAction { | ||
return isActionKind(action, SelectAction.KIND) && isArray(action, 'selectedElementsIDs') && isArray(action, 'deselectedElementsIDs'); | ||
export namespace SelectAction { | ||
export const KIND = 'elementSelected'; | ||
export function is(object: any): object is SelectAction { | ||
return Action.hasKind(object, KIND) && hasArrayProp(object, 'selectedElementsIDs') && hasArrayProp(object, 'deselectedElementsIDs'); | ||
} | ||
export function create(options: { selectedElementsIDs?: string[]; deselectedElementsIDs?: string[] } = {}): SelectAction { | ||
return { | ||
kind: KIND, | ||
selectedElementsIDs: [], | ||
deselectedElementsIDs: [], | ||
...options | ||
}; | ||
} | ||
} | ||
@@ -39,6 +62,7 @@ | ||
* Programmatic action for selecting or deselecting all elements. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SelectAllActions`. | ||
*/ | ||
export class SelectAllAction implements Action { | ||
static readonly KIND = 'allSelected'; | ||
kind = SelectAllAction.KIND; | ||
export interface SelectAllAction extends Action, sprotty.SelectAllAction { | ||
kind: typeof SelectAllAction.KIND; | ||
@@ -48,7 +72,18 @@ /** | ||
*/ | ||
constructor(public readonly select: boolean = true) {} | ||
select: boolean; | ||
} | ||
export function isSelectAllAction(action: any): action is SelectAllAction { | ||
return isActionKind(action, SelectAllAction.KIND) && isBoolean(action, 'select'); | ||
export namespace SelectAllAction { | ||
export const KIND = 'allSelected'; | ||
export function is(object: any): object is SelectAllAction { | ||
return Action.hasKind(object, KIND) && hasBooleanProp(object, 'select'); | ||
} | ||
export function create(select = true): SelectAllAction { | ||
return { | ||
kind: KIND, | ||
select | ||
}; | ||
} | ||
} |
/******************************************************************************** | ||
* Copyright (c) 2020-2021 EclipseSource and others. | ||
* Copyright (c) 2020-2022 EclipseSource and others. | ||
* | ||
@@ -16,4 +16,4 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import { isObject, isString } from '../utils/typeguard-util'; | ||
import { Action, generateRequestId, isActionKind, isRequestAction, Operation, RequestAction, ResponseAction } from './base-protocol'; | ||
import { hasObjectProp, hasStringProp } from '../utils/type-util'; | ||
import { Action, Operation, RequestAction, ResponseAction } from './base-protocol'; | ||
import { Args } from './types'; | ||
@@ -23,22 +23,48 @@ | ||
* Requests the validation of the given text in the context of the provided model element. Typically sent from the client to the server. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `NewActions`. | ||
*/ | ||
export class RequestEditValidationAction implements RequestAction<SetEditValidationResultAction> { | ||
static readonly KIND = 'requestEditValidation'; | ||
constructor( | ||
public readonly contextId: string, | ||
public readonly modelElementId: string, | ||
public readonly text: string, | ||
public readonly requestId: string = generateRequestId(), | ||
public readonly kind: string = RequestEditValidationAction.KIND | ||
) {} | ||
export interface RequestEditValidationAction extends RequestAction<SetEditValidationResultAction> { | ||
kind: typeof RequestEditValidationAction.KIND; | ||
/** | ||
* Context in which the text is validated, e.g., 'label-edit'. | ||
*/ | ||
contextId: string; | ||
/** | ||
* Model element that is being edited. | ||
*/ | ||
modelElementId: string; | ||
/** | ||
* Text that should be validated for the given context and the model element. | ||
*/ | ||
text: string; | ||
} | ||
export function isRequestEditValidationAction(action: any): action is RequestEditValidationAction { | ||
return ( | ||
isRequestAction(action) && | ||
action.kind === RequestEditValidationAction.KIND && | ||
isString(action, 'contextId') && | ||
isString(action, 'modelElementId') && | ||
isString(action, 'text') | ||
); | ||
export namespace RequestEditValidationAction { | ||
export const KIND = 'requestEditValidation'; | ||
export function is(object: any): object is RequestEditValidationAction { | ||
return ( | ||
RequestAction.hasKind(object, KIND) && | ||
hasStringProp(object, 'contextId') && | ||
hasStringProp(object, 'modelElementId') && | ||
hasStringProp(object, 'text') | ||
); | ||
} | ||
export function create(options: { | ||
contextId: string; | ||
modelElementId: string; | ||
text: string; | ||
requestId?: string; | ||
}): RequestEditValidationAction { | ||
return { | ||
kind: KIND, | ||
requestId: '', | ||
...options | ||
}; | ||
} | ||
} | ||
@@ -48,27 +74,75 @@ | ||
* Response to a {@link RequestEditValidationAction} containing the validation result for applying a text on a certain model element. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetEditValidationResultActions`. | ||
*/ | ||
export class SetEditValidationResultAction implements ResponseAction { | ||
static readonly KIND = 'setEditValidationResult'; | ||
constructor( | ||
public readonly status: ValidationStatus, | ||
public readonly responseId: string = '', | ||
public readonly args?: Args, | ||
public readonly kind: string = SetEditValidationResultAction.KIND | ||
) {} | ||
export interface SetEditValidationResultAction extends ResponseAction { | ||
kind: typeof SetEditValidationResultAction.KIND; | ||
status: ValidationStatus; | ||
/* | ||
* Additional arguments for custom behavior. | ||
*/ | ||
args?: Args; | ||
} | ||
export function isSetEditValidationResultAction(action: Action): action is SetEditValidationResultAction { | ||
return isActionKind(action, SetEditValidationResultAction.KIND) && isObject(action, 'status') && isString(action, 'responseId'); | ||
export namespace SetEditValidationResultAction { | ||
export const KIND = 'setEditValidationResult'; | ||
export function is(object: any): object is SetEditValidationResultAction { | ||
return Action.hasKind(object, KIND) && hasObjectProp(object, 'status'); | ||
} | ||
export function create(status: ValidationStatus, options: { args?: Args; responseId?: string } = {}): SetEditValidationResultAction { | ||
return { | ||
kind: KIND, | ||
responseId: '', | ||
status, | ||
...options | ||
}; | ||
} | ||
} | ||
export class ApplyLabelEditOperation implements Operation { | ||
static KIND = 'applyLabelEdit'; | ||
kind = ApplyLabelEditOperation.KIND; | ||
constructor(readonly labelId: string, readonly text: string) {} | ||
/** | ||
* A very common use case in domain models is the support of labels that display textual information to the user. | ||
* To apply new text to such a label element the client may send an ApplyLabelEditOperation to the server. Typically this is | ||
* done by the client after it has received a error free validation result via {@link SetEditValidationResultAction} from the server. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `ApplyLabelEditOperations`. | ||
*/ | ||
export interface ApplyLabelEditOperation extends Operation { | ||
kind: typeof ApplyLabelEditOperation.KIND; | ||
/** | ||
* Identifier of the label model element. | ||
*/ | ||
labelId: string; | ||
/** | ||
* Text that should be applied on the label. | ||
*/ | ||
text: string; | ||
} | ||
export function isApplyLabelEditOperation(action: any): action is ApplyLabelEditOperation { | ||
return isActionKind(action, ApplyLabelEditOperation.KIND) && isString(action, 'labelId') && isString(action, 'text'); | ||
export namespace ApplyLabelEditOperation { | ||
export const KIND = 'applyLabelEdit'; | ||
export function is(object: any): object is ApplyLabelEditOperation { | ||
return Operation.hasKind(object, KIND) && hasStringProp(object, 'labelId') && hasStringProp(object, 'text'); | ||
} | ||
export function create(options: { labelId: string; text: string }): ApplyLabelEditOperation { | ||
return { | ||
kind: KIND, | ||
isOperation: true, | ||
...options | ||
}; | ||
} | ||
} | ||
/** | ||
* The serializable result of an an validation request. | ||
* Tje corresponding namespace offers the default severity values | ||
* and other utility functions. | ||
*/ | ||
export interface ValidationStatus { | ||
@@ -91,20 +165,6 @@ /** | ||
export interface ResponseError { | ||
export namespace ValidationStatus { | ||
/** | ||
* Code identifying the error kind. | ||
* The default {@link ValidationStatus} severity levels used in GLSP. | ||
*/ | ||
readonly code: number; | ||
/** | ||
* Error message. | ||
*/ | ||
readonly message: string; | ||
/** | ||
* Additional custom data, e.g., a serialized stacktrace. | ||
*/ | ||
readonly data: Record<string, any>; | ||
} | ||
export namespace ValidationStatus { | ||
// eslint-disable-next-line no-shadow | ||
@@ -121,2 +181,5 @@ export enum Severity { | ||
/** | ||
* An empty {@link ValidationStatus}. | ||
*/ | ||
export const NONE: ValidationStatus = { | ||
@@ -128,2 +191,8 @@ severity: Severity.NONE, | ||
/** | ||
* Utility function to check wether the given {@link ValidationStatus} has | ||
* a severity that is considered to be OK. | ||
* @param validationStatus The validation status to check. | ||
* @returns `true` if the given status has a non critical severity, `false` otherwise. | ||
*/ | ||
export function isOk(validationStatus: ValidationStatus): boolean { | ||
@@ -137,2 +206,8 @@ return ( | ||
/** | ||
* Utility function to check wether the given {@link ValidationStatus} has | ||
* a `warning` severity. | ||
* @param validationStatus The validation status to check. | ||
* @returns `true` if the given status has a `warning` severity, `false` otherwise. | ||
*/ | ||
export function isWarning(validationStatus: ValidationStatus): boolean { | ||
@@ -142,2 +217,8 @@ return validationStatus.severity === Severity.WARNING; | ||
/** | ||
* Utility function to check wether the given {@link ValidationStatus} has | ||
* an `error` or `fatal` severity. | ||
* @param validationStatus The validation status to check. | ||
* @returns `true` if the given status has a `error` or `fatal` severity, `false` otherwise. | ||
*/ | ||
export function isError(validationStatus: ValidationStatus): boolean { | ||
@@ -147,1 +228,21 @@ return validationStatus.severity === Severity.ERROR || validationStatus.severity === Severity.FATAL; | ||
} | ||
/** | ||
* The serializable format of an error that occurred during validation. | ||
*/ | ||
export interface ResponseError { | ||
/** | ||
* Code identifying the error kind. | ||
*/ | ||
readonly code: number; | ||
/** | ||
* Error message. | ||
*/ | ||
readonly message: string; | ||
/** | ||
* Additional custom data, e.g., a serialized stacktrace. | ||
*/ | ||
readonly data: Record<string, any>; | ||
} |
/******************************************************************************** | ||
* Copyright (c) 2019-2021 EclipseSource and others. | ||
* Copyright (c) 2019-2022 EclipseSource and others. | ||
* | ||
@@ -16,6 +16,10 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import { RequestAction, ResponseAction } from '.'; | ||
import { isArray } from '../utils/typeguard-util'; | ||
import { isActionKind } from './base-protocol'; | ||
import { hasArrayProp } from '../utils/type-util'; | ||
import { Action, RequestAction, ResponseAction } from './base-protocol'; | ||
/** | ||
* Type hints are used to define what modifications are supported on the different element types. | ||
* The rationale is to avoid a client-server round-trip for user feedback of each synchronous user interaction. | ||
*/ | ||
export interface TypeHint { | ||
@@ -38,2 +42,5 @@ /** | ||
/** | ||
* A {@link TypeHint} with additional modification properties for shape elements. | ||
*/ | ||
export interface ShapeTypeHint extends TypeHint { | ||
@@ -56,2 +63,5 @@ /** | ||
/** | ||
* A {@link TypeHint} with additional modification properties for edge elements. | ||
*/ | ||
export interface EdgeTypeHint extends TypeHint { | ||
@@ -78,10 +88,23 @@ /** | ||
* receiving the model via RequestModelAction. The response is a {@link SetTypeHintsAction}. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `RequestTypeHintsActions`. | ||
*/ | ||
export class RequestTypeHintsAction implements RequestAction<SetTypeHintsAction> { | ||
static readonly KIND = 'requestTypeHints'; | ||
constructor(public readonly requestId = '', public readonly kind: string = RequestTypeHintsAction.KIND) {} | ||
export interface RequestTypeHintsAction extends RequestAction<SetTypeHintsAction> { | ||
kind: typeof RequestTypeHintsAction.KIND; | ||
} | ||
export function isRequestTypeHintsAction(action: any): action is RequestTypeHintsAction { | ||
return isActionKind(action, RequestTypeHintsAction.KIND); | ||
export namespace RequestTypeHintsAction { | ||
export const KIND = 'requestTypeHints'; | ||
export function is(object: any): object is RequestTypeHintsAction { | ||
return RequestAction.hasKind(object, KIND); | ||
} | ||
export function create(options: { requestId?: string } = {}): RequestTypeHintsAction { | ||
return { | ||
kind: KIND, | ||
requestId: '', | ||
...options | ||
}; | ||
} | ||
} | ||
@@ -91,15 +114,27 @@ | ||
* Sent from the server to the client in order to provide hints certain modifications are allowed for a specific element type. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetTypeHintsActions`. | ||
*/ | ||
export class SetTypeHintsAction implements ResponseAction { | ||
static readonly KIND = 'setTypeHints'; | ||
constructor( | ||
public readonly shapeHints: ShapeTypeHint[], | ||
public readonly edgeHints: EdgeTypeHint[], | ||
public readonly responseId = '', | ||
public readonly kind: string = SetTypeHintsAction.KIND | ||
) {} | ||
export interface SetTypeHintsAction extends ResponseAction { | ||
kind: typeof SetTypeHintsAction.KIND; | ||
shapeHints: ShapeTypeHint[]; | ||
edgeHints: EdgeTypeHint[]; | ||
} | ||
export function isSetTypeHintsAction(action: any): action is SetTypeHintsAction { | ||
return isActionKind(action, SetTypeHintsAction.KIND) && isArray(action, 'shapeHints') && isArray(action, 'edgeHints'); | ||
export namespace SetTypeHintsAction { | ||
export const KIND = 'setTypeHints'; | ||
export function is(object: any): object is SetTypeHintsAction { | ||
return Action.hasKind(object, KIND) && hasArrayProp(object, 'shapeHints') && hasArrayProp(object, 'edgeHints'); | ||
} | ||
export function create(options: { shapeHints: ShapeTypeHint[]; edgeHints: EdgeTypeHint[]; responseId?: string }): SetTypeHintsAction { | ||
return { | ||
kind: KIND, | ||
responseId: '', | ||
...options | ||
}; | ||
} | ||
} |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -16,6 +16,4 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import { injectable } from 'inversify'; | ||
import { RequestAction, ResponseAction } from '.'; | ||
import { isArray } from '../utils/typeguard-util'; | ||
import { Action, isActionKind } from './base-protocol'; | ||
import { hasArrayProp } from '../utils/type-util'; | ||
import { Action, RequestAction, ResponseAction } from './base-protocol'; | ||
@@ -44,2 +42,5 @@ /** | ||
/** | ||
* The default marker kinds used in GLSP | ||
*/ | ||
export namespace MarkerKind { | ||
@@ -53,26 +54,62 @@ export const INFO = 'info'; | ||
* Action to retrieve markers for the specified model elements. Sent from the client to the server. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `RequestMarkersActions`. | ||
*/ | ||
export class RequestMarkersAction implements RequestAction<SetMarkersAction> { | ||
static readonly KIND = 'requestMarkers'; | ||
constructor( | ||
public readonly elementsIDs: string[] = [], | ||
public readonly requestId = '', | ||
public readonly kind = RequestMarkersAction.KIND | ||
) {} | ||
export interface RequestMarkersAction extends RequestAction<SetMarkersAction> { | ||
kind: typeof RequestMarkersAction.KIND; | ||
/** | ||
* The elements for which markers are requested, may be just the root element. | ||
*/ | ||
elementsIDs: string[]; | ||
} | ||
export function isRequestMarkersAction(action: any): action is RequestMarkersAction { | ||
return isActionKind(action, RequestMarkersAction.KIND) && isArray(action, 'elementsIDs'); | ||
export namespace RequestMarkersAction { | ||
export const KIND = 'requestMarkers'; | ||
export function is(object: any): object is RequestMarkersAction { | ||
return RequestAction.hasKind(object, KIND) && hasArrayProp(object, 'elementsIDs'); | ||
} | ||
export function create(elementsIDs: string[], options: { requestId?: string } = {}): RequestMarkersAction { | ||
return { | ||
kind: KIND, | ||
requestId: '', | ||
elementsIDs, | ||
...options | ||
}; | ||
} | ||
} | ||
/** | ||
* Response to the {@link RequestMarkersAction} containing all validation markers. Sent from the server to the client. | ||
* Instructs the client to add markers to the diagram. | ||
* Typically, this is a response to the {@link RequestMarkersAction} containing all validation markers, but can be sent by the server at | ||
* any time. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetMarkersActions`. | ||
*/ | ||
export class SetMarkersAction implements ResponseAction { | ||
static readonly KIND = 'setMarkers'; | ||
constructor(public readonly markers: Marker[], public readonly responseId = '', public readonly kind = SetMarkersAction.KIND) {} | ||
export interface SetMarkersAction extends ResponseAction { | ||
kind: typeof SetMarkersAction.KIND; | ||
/** | ||
* The list of markers to be added to the diagram. | ||
*/ | ||
readonly markers: Marker[]; | ||
} | ||
export function isSetMarkersAction(action: any): action is SetMarkersAction { | ||
return isActionKind(action, SetMarkersAction.KIND) && isArray(action, 'markers'); | ||
export namespace SetMarkersAction { | ||
export const KIND = 'setMarkers'; | ||
export function is(object: any): object is SetMarkersAction { | ||
return Action.hasKind(object, KIND) && hasArrayProp(object, 'markers'); | ||
} | ||
export function create(markers: Marker[], options: { responseId?: string } = {}): SetMarkersAction { | ||
return { | ||
kind: KIND, | ||
responseId: '', | ||
markers, | ||
...options | ||
}; | ||
} | ||
} | ||
@@ -82,11 +119,27 @@ | ||
* Action for clearing makers of a model | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `DeleteMarkersActions`. Can be sent by either the client or the server. | ||
*/ | ||
@injectable() | ||
export class DeleteMarkersAction implements Action { | ||
static readonly KIND = 'deleteMarkers'; | ||
constructor(public readonly markers: Marker[], public readonly kind = DeleteMarkersAction.KIND) {} | ||
export interface DeleteMarkersAction extends Action { | ||
kind: typeof DeleteMarkersAction.KIND; | ||
/** | ||
* The list of markers that has been requested by the `RequestMarkersAction`. | ||
*/ | ||
markers: Marker[]; | ||
} | ||
export function isDeleteMarkersAction(action: any): action is DeleteMarkersAction { | ||
return isActionKind(action, DeleteMarkersAction.KIND) && isArray(action, 'markers'); | ||
export namespace DeleteMarkersAction { | ||
export const KIND = 'deleteMarkers'; | ||
export function is(object: any): object is DeleteMarkersAction { | ||
return Action.hasKind(object, KIND) && hasArrayProp(object, 'markers'); | ||
} | ||
export function create(markers: Marker[]): DeleteMarkersAction { | ||
return { | ||
kind: KIND, | ||
markers | ||
}; | ||
} | ||
} |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -28,5 +28,5 @@ * This program and the accompanying materials are made available under the | ||
export * from './element-validation'; | ||
export * from './mode-layout'; | ||
export * from './model-data'; | ||
export * from './model-edit-mode'; | ||
export * from './model-layout'; | ||
export * from './model-saving'; | ||
@@ -33,0 +33,0 @@ export * from './model-structure'; |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -16,62 +16,129 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import { isBoolean, isObject, isString } from '../utils/typeguard-util'; | ||
import { Action, generateRequestId, isActionKind, RequestAction, ResponseAction } from './base-protocol'; | ||
import * as sprotty from 'sprotty-protocol/lib/actions'; | ||
import { hasObjectProp, hasStringProp } from '../utils/type-util'; | ||
import { Action, RequestAction, ResponseAction } from './base-protocol'; | ||
import { SModelRootSchema } from './model-structure'; | ||
import { JsonPrimitive } from './types'; | ||
import { Args } from './types'; | ||
/** | ||
* Sent from the server to the client in order to set the model. If a model is already present, it is replaced. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `RequestModelActions`. | ||
*/ | ||
export class RequestModelAction implements RequestAction<SetModelAction> { | ||
static readonly KIND = 'requestModel'; | ||
readonly kind = RequestModelAction.KIND; | ||
export interface RequestModelAction extends RequestAction<SetModelAction>, sprotty.RequestModelAction { | ||
kind: typeof RequestModelAction.KIND; | ||
constructor(public readonly options?: { [key: string]: JsonPrimitive }, public readonly requestId = '') {} | ||
/** | ||
* Additional options used to compute the graphical model. | ||
*/ | ||
options?: Args; | ||
} | ||
/** Factory function to dispatch a request with the `IActionDispatcher` */ | ||
static create(options?: { [key: string]: JsonPrimitive }): RequestAction<SetModelAction> { | ||
return new RequestModelAction(options, generateRequestId()); | ||
export namespace RequestModelAction { | ||
export const KIND = 'requestModel'; | ||
export function is(object: any): object is RequestModelAction { | ||
return RequestAction.hasKind(object, KIND); | ||
} | ||
export function create(options: { options?: Args; requestId?: string } = {}): RequestModelAction { | ||
return { | ||
kind: KIND, | ||
requestId: '', | ||
...options | ||
}; | ||
} | ||
} | ||
export function isRequestModelAction(action: any): action is RequestModelAction { | ||
return isActionKind(action, RequestModelAction.KIND); | ||
} | ||
/** | ||
* Sent from the model source to the client in order to set the model. If a model is already present, it is replaced. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetModelActions`. | ||
*/ | ||
export class SetModelAction implements ResponseAction { | ||
static readonly KIND = 'setModel'; | ||
readonly kind = SetModelAction.KIND; | ||
constructor(public readonly newRoot: SModelRootSchema, public readonly responseId = '') {} | ||
export interface SetModelAction extends ResponseAction, sprotty.SetModelAction { | ||
kind: typeof SetModelAction.KIND; | ||
/** | ||
* The new graphical model root. | ||
*/ | ||
newRoot: SModelRootSchema; | ||
} | ||
export function isSetModelAction(action: any): action is SetModelAction { | ||
return isActionKind(action, SetModelAction.KIND) && isObject(action, 'newRoot'); | ||
export namespace SetModelAction { | ||
export const KIND = 'setModel'; | ||
export function is(object: any): object is SetModelAction { | ||
return Action.hasKind(object, KIND) && hasObjectProp(object, 'newRoot'); | ||
} | ||
export function create(newRoot: SModelRootSchema, options: { responseId?: string } = {}): SetModelAction { | ||
return { | ||
kind: KIND, | ||
responseId: '', | ||
newRoot, | ||
...options | ||
}; | ||
} | ||
} | ||
/** | ||
* Sent from the server to the client in order to update the model. If no model is present yet, this behaves the same as a SetModelAction. | ||
* The transition from the old model to the new one can be animated. | ||
* Sent from the server to the client in order to update the model. If no model is present yet, this behaves the same as | ||
* a {@link SetModelAction}. The transition from the old model to the new one can be animated. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `UpdateModelActions`. | ||
*/ | ||
export class UpdateModelAction implements Action { | ||
static readonly KIND = 'updateModel'; | ||
readonly kind = UpdateModelAction.KIND; | ||
export interface UpdateModelAction extends Action, Omit<sprotty.UpdateModelAction, 'matches' | 'cause'> { | ||
kind: typeof UpdateModelAction.KIND; | ||
constructor(public readonly newRoot: SModelRootSchema, public readonly animate: boolean = true) {} | ||
newRoot: SModelRootSchema; | ||
/** | ||
* Boolean flag to indicate wether updated/changed elements should be animated in the diagram. | ||
*/ | ||
animate?: boolean; | ||
} | ||
export function isUpdateModelAction(action: any): action is UpdateModelAction { | ||
return isActionKind(action, UpdateModelAction.KIND) && isObject(action, 'newRoot') && isBoolean(action, 'animate'); | ||
export namespace UpdateModelAction { | ||
export const KIND = 'updateModel'; | ||
export function is(action: any): action is UpdateModelAction { | ||
return Action.hasKind(action, KIND) && hasObjectProp(action, 'newRoot'); | ||
} | ||
export function create(newRoot: SModelRootSchema, options: { animate?: boolean } = {}): UpdateModelAction { | ||
return { | ||
kind: KIND, | ||
newRoot, | ||
animate: true, | ||
...options | ||
}; | ||
} | ||
} | ||
export class ModelSourceChangedAction implements Action { | ||
static KIND = 'modelSourceChanged'; | ||
readonly kind = ModelSourceChangedAction.KIND; | ||
constructor(public readonly modelSourceName: string) {} | ||
/** | ||
* Sent from the server to the client in order to indicate that the model source has changed. | ||
* The model source denotes the data source from which the diagram has been originally derived (such as a file, a database, etc.). | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `ModelSourceChangedActions`. | ||
*/ | ||
export interface ModelSourceChangedAction extends Action { | ||
kind: typeof ModelSourceChangedAction.KIND; | ||
/** | ||
* A human readable name of the model source (e.g. the file name). | ||
*/ | ||
modelSourceName: string; | ||
} | ||
export function isModelSourceChangedAction(action?: any): action is ModelSourceChangedAction { | ||
return isActionKind(action, ModelSourceChangedAction.KIND) && isString(action, 'modelSourceName'); | ||
export namespace ModelSourceChangedAction { | ||
export const KIND = 'modelSourceChanged'; | ||
export function is(object: any): object is ModelSourceChangedAction { | ||
return Action.hasKind(object, KIND) && hasStringProp(object, 'modelSourceName'); | ||
} | ||
export function create(modelSourceName: string): ModelSourceChangedAction { | ||
return { | ||
kind: KIND, | ||
modelSourceName | ||
}; | ||
} | ||
} |
/******************************************************************************** | ||
* Copyright (c) 2020-2021 EclipseSource and others. | ||
* Copyright (c) 2020-2022 EclipseSource and others. | ||
* | ||
@@ -16,17 +16,38 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import { injectable } from 'inversify'; | ||
import { Action } from 'sprotty'; | ||
import { isString } from '../utils/typeguard-util'; | ||
import { isActionKind } from './base-protocol'; | ||
import { hasStringProp } from '../utils/type-util'; | ||
import { Action } from './base-protocol'; | ||
@injectable() | ||
export class SetEditModeAction implements Action { | ||
static readonly KIND = 'setEditMode'; | ||
constructor(public readonly editMode: string = EditMode.EDITABLE, public readonly kind: string = SetEditModeAction.KIND) {} | ||
/** | ||
* Sent from the client to the server to set the model into a specific editor mode, allowing the server to react to certain | ||
* requests differently depending on the mode. A client may also listen to this action to prevent certain user interactions preemptively. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetEditModeActions`. | ||
*/ | ||
export interface SetEditModeAction extends Action { | ||
kind: typeof SetEditModeAction.KIND; | ||
/** | ||
* The new edit mode of the diagram. | ||
*/ | ||
editMode: string; | ||
} | ||
export function isSetEditModeAction(action: Action): action is SetEditModeAction { | ||
return isActionKind(action, SetEditModeAction.KIND) && isString(action, 'editMode'); | ||
export namespace SetEditModeAction { | ||
export const KIND = 'setEditMode'; | ||
export function is(object: any): object is SetEditModeAction { | ||
return Action.hasKind(object, KIND) && hasStringProp(object, 'editMode'); | ||
} | ||
export function create(editMode: string): SetEditModeAction { | ||
return { | ||
kind: KIND, | ||
editMode | ||
}; | ||
} | ||
} | ||
/** | ||
* The potential default values for the `editMode` property of a {@link SetEditModeAction}. | ||
*/ | ||
export namespace EditMode { | ||
@@ -33,0 +54,0 @@ export const READONLY = 'readonly'; |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -16,40 +16,122 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import { isBoolean, isString } from '../utils/typeguard-util'; | ||
import { Action, isActionKind, ResponseAction } from './base-protocol'; | ||
import { hasBooleanProp, hasStringProp } from '../utils/type-util'; | ||
import { Action, RequestAction, ResponseAction } from './base-protocol'; | ||
export class SaveModelAction implements Action { | ||
static readonly KIND = 'saveModel'; | ||
constructor(public readonly fileUri?: string, public readonly kind: string = SaveModelAction.KIND) {} | ||
/** | ||
* Sent from the client to the server in order to persist the current model state back to the model source. | ||
* A new fileUri can be defined to save the model to a new destination different from its original model source. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SaveModelActions`. | ||
*/ | ||
export interface SaveModelAction extends Action { | ||
kind: typeof SaveModelAction.KIND; | ||
/** | ||
* The optional destination file uri. | ||
*/ | ||
fileUri?: string; | ||
} | ||
export function isSaveModelAction(action?: any): action is SaveModelAction { | ||
return isActionKind(action, SaveModelAction.KIND); | ||
export namespace SaveModelAction { | ||
export const KIND = 'saveModel'; | ||
export function is(object: any): object is SaveModelAction { | ||
return Action.hasKind(object, KIND); | ||
} | ||
export function create(options: { fileUri?: string } = {}): SaveModelAction { | ||
return { | ||
kind: KIND, | ||
...options | ||
}; | ||
} | ||
} | ||
export class SetDirtyStateAction implements Action { | ||
static readonly KIND = 'setDirtyState'; | ||
constructor(public readonly isDirty: boolean, public readonly reason?: string, public readonly kind = SetDirtyStateAction.KIND) {} | ||
/** | ||
* The server sends this action to indicate to the client that the current model state on the server does not correspond | ||
* to the persisted model state of the model source. A client may ignore such an action or use it to indicate to the user the dirty state. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `SetDirtyStateActions`. | ||
*/ | ||
export interface SetDirtyStateAction extends Action { | ||
kind: typeof SetDirtyStateAction.KIND; | ||
/** | ||
* True if the current model state is dirty | ||
*/ | ||
isDirty: boolean; | ||
/** | ||
* A string indicating the reason for the dirty state change e.g 'operation', 'undo',... | ||
*/ | ||
reason?: DirtyStateChangeReason; | ||
} | ||
export namespace DirtyStateChangeReason { | ||
export const OPERATION = 'operation'; | ||
export const UNDO = 'undo'; | ||
export const REDO = 'redo'; | ||
export const SAVE = 'save'; | ||
export const EXTERNAL = 'external'; | ||
export type DirtyStateChangeReason = 'operation' | 'undo' | 'redo' | 'save' | 'external'; | ||
export namespace SetDirtyStateAction { | ||
export const KIND = 'setDirtyState'; | ||
export function is(object: any): object is SetDirtyStateAction { | ||
return Action.hasKind(object, KIND) && hasBooleanProp(object, 'isDirty'); | ||
} | ||
export function create(isDirty: boolean, options: { reason?: DirtyStateChangeReason } = {}): SetDirtyStateAction { | ||
return { | ||
kind: KIND, | ||
isDirty, | ||
...options | ||
}; | ||
} | ||
} | ||
export function isSetDirtyStateAction(action?: any): action is SetDirtyStateAction { | ||
return isActionKind(action, SetDirtyStateAction.KIND) && isBoolean(action, 'isDirty'); | ||
/** | ||
* A `RequestExportSvgAction` is sent by the client (or the server) to initiate the SVG export of the current diagram. | ||
* The handler of this action is expected to retrieve the diagram SVG and should send a {@link ExportSvgAction} as response. | ||
* Typically the {@link ExportSvgAction} is handled directly on client side. | ||
*/ | ||
export interface RequestExportSvgAction extends RequestAction<ExportSvgAction> { | ||
kind: typeof RequestExportSvgAction.KIND; | ||
} | ||
export namespace RequestExportSvgAction { | ||
export const KIND = 'requestExportSvg'; | ||
export class ExportSvgAction implements ResponseAction { | ||
static KIND = 'exportSvg'; | ||
kind = ExportSvgAction.KIND; | ||
export function is(object: any): object is RequestExportSvgAction { | ||
return RequestAction.hasKind(object, KIND); | ||
} | ||
constructor(public readonly svg: string, public readonly responseId: string = '') {} | ||
export function create(options: { requestId?: string } = {}): RequestExportSvgAction { | ||
return { | ||
kind: KIND, | ||
requestId: '', | ||
...options | ||
}; | ||
} | ||
} | ||
export function isExportSvgAction(action?: any): action is ExportSvgAction { | ||
return isActionKind(action, ExportSvgAction.KIND) && isString(action, 'svg'); | ||
/** | ||
* The client sends an `ExportSvgAction` to indicate that the diagram, which represents the current model state, | ||
* should be exported in SVG format. The action only provides the diagram SVG as plain string. The expected result of executing | ||
* an `ExportSvgAction` is a new file in SVG-format on the underlying filesystem. However, other details like the target destination, | ||
* concrete file name, file extension etc. are not specified in the protocol. So it is the responsibility of the action handler to | ||
* process this information accordingly and export the result to the underlying filesystem. | ||
*/ | ||
export interface ExportSvgAction extends ResponseAction { | ||
kind: typeof ExportSvgAction.KIND; | ||
svg: string; | ||
responseId: string; | ||
} | ||
export namespace ExportSvgAction { | ||
export const KIND = 'exportSvg'; | ||
export function is(object: any): object is RequestExportSvgAction { | ||
return Action.hasKind(object, KIND) && hasStringProp(object, 'svg'); | ||
} | ||
export function create(svg: string, options: { responseId?: string } = {}): ExportSvgAction { | ||
return { | ||
kind: KIND, | ||
svg, | ||
responseId: '', | ||
...options | ||
}; | ||
} | ||
} |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -16,19 +16,35 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import { isString } from '../utils/typeguard-util'; | ||
import { Bounds } from './types'; | ||
import { Bounds } from 'sprotty-protocol'; | ||
import * as sprotty from 'sprotty-protocol/lib/model'; | ||
import { hasStringProp } from '../utils/type-util'; | ||
/** | ||
* The schema of an SModelElement describes its serializable form. The actual model is created from | ||
* its schema with an IModelFactory. | ||
* Each model element must have a unique ID and a type that is used to look up its view. | ||
* The schema of an SModelElement describes its serializable form. The actual class-based model is derived | ||
* its schema whenever the client or server deserializes a received schema`. | ||
* Each model element must have a unique ID and a type that is used on the client to look up its view. | ||
*/ | ||
export interface SModelElementSchema { | ||
export interface SModelElementSchema extends sprotty.SModelElement { | ||
id: string; | ||
/** | ||
* Type to look up the graphical representation of this element. | ||
*/ | ||
type: string; | ||
id: string; | ||
children?: SModelElementSchema[]; | ||
/** | ||
* CSS classes that should be applied on the rendered SVG element representing this element. | ||
*/ | ||
cssClasses?: string[]; | ||
} | ||
export function isSModelElementSchema(schema: any): schema is SModelElementSchema { | ||
return schema !== undefined && typeof schema === 'object' && isString(schema, 'type') && isString(schema, 'id'); | ||
export namespace SModelElementSchema { | ||
/** | ||
* Typeguard function to check wether the given object is an {@link SModelElementSchema}. | ||
* @param object The object to check. | ||
* @returns A type literal indicating wether the given object is of type {@link SModelElementSchema}. | ||
*/ | ||
export function is(object: any): object is SModelElementSchema { | ||
return typeof object === 'object' && hasStringProp(object, 'type') && hasStringProp(object, 'id'); | ||
} | ||
} | ||
@@ -40,8 +56,11 @@ | ||
export interface SModelRootSchema extends SModelElementSchema { | ||
/** | ||
* Bounds of this element in the canvas. | ||
*/ | ||
canvasBounds?: Bounds; | ||
/** | ||
* The revision number identifies single versions of the models sent by the server. | ||
*/ | ||
revision?: number; | ||
} | ||
export function isSModelRootSchema(schema: any): schema is SModelRootSchema { | ||
return isSModelElementSchema(schema) && !('parent' in schema); | ||
} |
/******************************************************************************** | ||
* Copyright (c) 2021 EclipseSource and others. | ||
* Copyright (c) 2021-2022 EclipseSource and others. | ||
* | ||
@@ -17,5 +17,6 @@ * This program and the accompanying materials are made available under the | ||
import { isArray, isString } from '../utils/typeguard-util'; | ||
import { isActionKind, Operation } from './base-protocol'; | ||
import { ElementAndBounds, Point } from './types'; | ||
import { Point } from 'sprotty-protocol'; | ||
import { hasArrayProp, hasStringProp } from '../utils/type-util'; | ||
import { Operation } from './base-protocol'; | ||
import { ElementAndBounds } from './types'; | ||
@@ -26,27 +27,66 @@ /** | ||
* before resizing or repositioning. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `ChangeBoundsOperations`. | ||
*/ | ||
export class ChangeBoundsOperation implements Operation { | ||
static readonly KIND = 'changeBounds'; | ||
constructor(public newBounds: ElementAndBounds[], public readonly kind: string = ChangeBoundsOperation.KIND) {} | ||
export interface ChangeBoundsOperation extends Operation { | ||
kind: typeof ChangeBoundsOperation.KIND; | ||
newBounds: ElementAndBounds[]; | ||
} | ||
export function isChangeBoundsOperation(action: any): action is ChangeBoundsOperation { | ||
return isActionKind(action, ChangeBoundsOperation.KIND) && isArray(action, 'newBounds'); | ||
export namespace ChangeBoundsOperation { | ||
export const KIND = 'changeBounds'; | ||
export function is(object: any): object is ChangeBoundsOperation { | ||
return Operation.hasKind(object, KIND) && hasArrayProp(object, 'newBounds'); | ||
} | ||
export function create(newBounds: ElementAndBounds[]): ChangeBoundsOperation { | ||
return { | ||
kind: KIND, | ||
isOperation: true, | ||
newBounds | ||
}; | ||
} | ||
} | ||
/** | ||
* The client sends a `ChangeContainerOperation` to the server to request the execution of a changeContainer operation. | ||
* The client sends a `ChangeContainerOperation` to the server to request the a semantic move i.e. the corresponding element | ||
* should be moved form its current container to the target container. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `ChangeContainerOperations`. | ||
*/ | ||
export class ChangeContainerOperation implements Operation { | ||
static readonly KIND = 'changeContainer'; | ||
constructor( | ||
public readonly elementId: string, | ||
public readonly targetContainerId: string, | ||
public readonly location?: Point, | ||
public readonly kind: string = ChangeContainerOperation.KIND | ||
) {} | ||
export interface ChangeContainerOperation extends Operation { | ||
kind: typeof ChangeContainerOperation.KIND; | ||
/** | ||
* The element to be changed. | ||
*/ | ||
elementId: string; | ||
/** | ||
* The element container of the changeContainer operation. | ||
*/ | ||
targetContainerId: string; | ||
/** | ||
* The graphical location. | ||
*/ | ||
location?: Point; | ||
} | ||
export function isChangeContainerOperation(action: any): action is ChangeContainerOperation { | ||
return isActionKind(action, ChangeContainerOperation.KIND) && isString(action, 'elementId') && isString(action, 'targetContainerId'); | ||
export namespace ChangeContainerOperation { | ||
export const KIND = 'changeContainer'; | ||
export function is(object: any): object is ChangeContainerOperation { | ||
return Operation.hasKind(object, KIND) && hasStringProp(object, 'elementId') && hasStringProp(object, 'targetContainerId'); | ||
} | ||
export function create(options: { elementId: string; targetContainerId: string; location?: Point }): ChangeContainerOperation { | ||
return { | ||
kind: KIND, | ||
isOperation: true, | ||
...options | ||
}; | ||
} | ||
} |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -17,28 +17,40 @@ * This program and the accompanying materials are made available under the | ||
import { isString } from '../utils/typeguard-util'; | ||
import { Action, isAction } from './base-protocol'; | ||
import { hasStringProp } from '../utils/type-util'; | ||
import { Action } from './base-protocol'; | ||
import { Args } from './types'; | ||
export abstract class TriggerElementCreationAction implements Action { | ||
constructor(public readonly elementTypeId: string, readonly args?: Args, public readonly kind: string = 'unknown') {} | ||
} | ||
export function isTriggerElementTypeCreationAction(action: any): action is TriggerElementCreationAction { | ||
return isAction(action) && isString(action, 'elementTypeId'); | ||
} | ||
/** | ||
* Triggers the enablement of the tool that is responsible for creating nodes and initializes it with the creation of nodes of the given | ||
* `elementTypeId`. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `TriggerNodeCreationActions`. | ||
*/ | ||
export class TriggerNodeCreationAction extends TriggerElementCreationAction { | ||
static readonly KIND = 'triggerNodeCreation'; | ||
export interface TriggerNodeCreationAction extends Action { | ||
kind: typeof TriggerNodeCreationAction.KIND; | ||
constructor(public readonly elementTypeId: string, readonly args?: Args, public readonly kind = TriggerNodeCreationAction.KIND) { | ||
super(elementTypeId, args, kind); | ||
} | ||
/** | ||
* The type of edge that should be created by the nodes creation tool. | ||
*/ | ||
elementTypeId: string; | ||
/** | ||
* Custom arguments. | ||
*/ | ||
args?: Args; | ||
} | ||
export function isTriggerNodeCreationAction(action: any): action is TriggerNodeCreationAction { | ||
return isTriggerElementTypeCreationAction(action) && action.kind === TriggerNodeCreationAction.KIND; | ||
export namespace TriggerNodeCreationAction { | ||
export const KIND = 'triggerNodeCreation'; | ||
export function is(object: any): object is TriggerNodeCreationAction { | ||
return Action.hasKind(object, KIND) && hasStringProp(object, 'elementTypeId'); | ||
} | ||
export function create(elementTypeId: string, options: { args?: Args } = {}): TriggerNodeCreationAction { | ||
return { | ||
kind: KIND, | ||
elementTypeId, | ||
...options | ||
}; | ||
} | ||
} | ||
@@ -49,17 +61,34 @@ | ||
* `elementTypeId`. | ||
* <Insert documentation> | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `TriggerEdgeCreationActions`. | ||
*/ | ||
export class TriggerEdgeCreationAction extends TriggerElementCreationAction { | ||
static readonly KIND = 'triggerEdgeCreation'; | ||
export interface TriggerEdgeCreationAction extends Action { | ||
kind: typeof TriggerEdgeCreationAction.KIND; | ||
constructor( | ||
public readonly elementTypeId: string, | ||
readonly args?: Args, | ||
public readonly kind: string = TriggerEdgeCreationAction.KIND | ||
) { | ||
super(elementTypeId, args, kind); | ||
} | ||
/** | ||
* The type of edge that should be created by the edge creation tool. | ||
*/ | ||
elementTypeId: string; | ||
/** | ||
* Custom arguments. | ||
*/ | ||
args?: Args; | ||
} | ||
export function isTriggerEdgeCreationAction(action: any): action is TriggerEdgeCreationAction { | ||
return isTriggerElementTypeCreationAction(action) && action.kind === TriggerEdgeCreationAction.KIND; | ||
export namespace TriggerEdgeCreationAction { | ||
export const KIND = 'triggerEdgeCreation'; | ||
export function is(object: any): object is TriggerEdgeCreationAction { | ||
return Action.hasKind(object, KIND) && hasStringProp(object, 'elementTypeId'); | ||
} | ||
export function create(elementTypeId: string, options: { args?: Args } = {}): TriggerEdgeCreationAction { | ||
return { | ||
kind: KIND, | ||
elementTypeId, | ||
...options | ||
}; | ||
} | ||
} |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -16,6 +16,9 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import * as sprotty from 'sprotty-protocol'; | ||
import { Dimension, Point } from 'sprotty-protocol'; | ||
import { AnyObject, hasArrayProp, hasStringProp } from '../utils/type-util'; | ||
import { Action } from './base-protocol'; | ||
import { TriggerEdgeCreationAction, TriggerNodeCreationAction } from './tool-palette'; | ||
// A collection of convenience and utility types that are used in the GLSP action protocol. | ||
export type JsonPrimitive = string | number | boolean; | ||
/** | ||
@@ -25,43 +28,35 @@ * A key-value pair structure for primitive typed custom arguments. | ||
export interface Args { | ||
[key: string]: JsonPrimitive; | ||
[key: string]: sprotty.JsonPrimitive; | ||
} | ||
export interface Point { | ||
readonly x: number; | ||
readonly y: number; | ||
} | ||
export const ORIGIN_POINT: Point = Object.freeze({ | ||
x: 0, | ||
y: 0 | ||
}); | ||
export interface Dimension { | ||
readonly width: number; | ||
readonly height: number; | ||
} | ||
export const EMPTY_DIMENSION: Dimension = Object.freeze({ | ||
width: -1, | ||
height: -1 | ||
}); | ||
/** | ||
* The bounds are the position (x, y) and dimension (width, height) of an object. | ||
* The ElementAndBounds type is used to associate new bounds with a model element, which is referenced via its id. | ||
*/ | ||
export interface Bounds extends Point, Dimension {} | ||
export const EMPTY_BOUNDS: Bounds = Object.freeze({ ...EMPTY_DIMENSION, ...ORIGIN_POINT }); | ||
export interface ElementAndBounds { | ||
export interface ElementAndBounds extends sprotty.ElementAndBounds { | ||
/** | ||
* The identifier of the element. | ||
*/ | ||
elementId: string; | ||
/** | ||
* The new size of the element. | ||
*/ | ||
newSize: Dimension; | ||
/** | ||
* The new position of the element. | ||
*/ | ||
newPosition?: Point; | ||
newSize: Dimension; | ||
} | ||
/** | ||
* Associates a new alignment with a model element, which is referenced via its id. | ||
* The `ElementAndAlignment` type is used to associate a new alignment with a model element, which is referenced via its id. | ||
* Typically used to align label relative to their parent element. | ||
*/ | ||
export interface ElementAndAlignment { | ||
export interface ElementAndAlignment extends sprotty.ElementAndAlignment { | ||
/** | ||
* The identifier of the element. | ||
*/ | ||
elementId: string; | ||
/** | ||
* The new alignment of the element. | ||
*/ | ||
newAlignment: Point; | ||
@@ -107,16 +102,108 @@ } | ||
export namespace EditorContext { | ||
export function is(object: any): object is EditorContext { | ||
return object !== undefined && hasArrayProp(object, 'selectedElementIds'); | ||
} | ||
} | ||
/** | ||
*Labeled actions are used to denote a group of actions in a user-interface context, e.g., to define an entry in the command palette or | ||
*in the context menu. | ||
* Labeled actions are used to denote a group of actions in a user-interface context, e.g., to define an entry in the command palette or | ||
* in the context menu. | ||
* The corresponding namespace offers a helper function for type guard checks. | ||
*/ | ||
export class LabeledAction { | ||
constructor(readonly label: string, readonly actions: Action[], readonly icon?: string) {} | ||
export interface LabeledAction { | ||
/** | ||
* Group label. | ||
*/ | ||
label: string; | ||
/** | ||
* Actions in the group. | ||
*/ | ||
actions: Action[]; | ||
/** | ||
* Optional group icon. | ||
*/ | ||
icon?: string; | ||
} | ||
export function isLabeledAction(element: any): element is LabeledAction { | ||
return element !== undefined && typeof element === 'object' && 'label' in element && 'actions' in element; | ||
export namespace LabeledAction { | ||
export function is(object: any): object is LabeledAction { | ||
return AnyObject.is(object) && hasStringProp(object, 'label') && hasArrayProp(object, 'actions'); | ||
} | ||
export function toActionArray(input: LabeledAction | Action[] | Action): Action[] { | ||
if (Array.isArray(input)) { | ||
return input; | ||
} else if (LabeledAction.is(input)) { | ||
return input.actions; | ||
} | ||
return [input]; | ||
} | ||
} | ||
export type JsonAny = JsonPrimitive | Args | JsonArray | null; | ||
/** | ||
* A special {@link LabeledAction} that is used to denote actions that should be triggered when the user | ||
* click a tool palette item (e.g. a button to create a new node)., | ||
*/ | ||
export interface PaletteItem extends LabeledAction { | ||
/** Technical id of the palette item. */ | ||
readonly id: string; | ||
/** String indicating the order. */ | ||
readonly sortString: string; | ||
/** Children of this item. If this item has children, the client will know to render them as sub group. */ | ||
readonly children?: PaletteItem[]; | ||
} | ||
export interface JsonArray extends Array<JsonAny> {} | ||
export namespace PaletteItem { | ||
export function is(object: any): object is PaletteItem { | ||
return LabeledAction.is(object) && hasStringProp(object, 'id') && hasStringProp(object, 'sortString'); | ||
} | ||
export function getTriggerAction(item?: PaletteItem): TriggerElementCreationAction | undefined { | ||
if (item) { | ||
const initialActions = item.actions | ||
.filter(a => isTriggerElementCreationAction(a)) | ||
.map(action => action as TriggerElementCreationAction); | ||
return initialActions.length > 0 ? initialActions[0] : undefined; | ||
} | ||
return undefined; | ||
} | ||
export type TriggerElementCreationAction = TriggerEdgeCreationAction | TriggerNodeCreationAction; | ||
export function isTriggerElementCreationAction(object: any): object is TriggerElementCreationAction { | ||
return TriggerNodeCreationAction.is(object) || TriggerEdgeCreationAction.is(object); | ||
} | ||
} | ||
/** | ||
* A special {@link LabeledAction} that is used to denote items in a menu. | ||
*/ | ||
export interface MenuItem extends LabeledAction { | ||
/** Technical id of the menu item. */ | ||
readonly id: string; | ||
/** String indicating the order. */ | ||
readonly sortString?: string; | ||
/** String indicating the grouping (separators). Items with equal group will be in the same group. */ | ||
readonly group?: string; | ||
/** | ||
* The optional parent id can be used to add this element as a child of another element provided by another menu provider. | ||
* The `parentId` must be fully qualified in the form of `a.b.c`, whereas `a`, `b` and `c` are referring to the IDs of other elements. | ||
* Note that this attribute will only be considered for root items of a provider and not for children of provided items. | ||
*/ | ||
readonly parentId?: string; | ||
/** Function determining whether the element is enabled. */ | ||
readonly isEnabled?: () => boolean; | ||
/** Function determining whether the element is visible. */ | ||
readonly isVisible?: () => boolean; | ||
/** Function determining whether the element is toggled on or off. */ | ||
readonly isToggled?: () => boolean; | ||
/** Children of this item. If this item has children, they will be added into a submenu of this item. */ | ||
children?: MenuItem[]; | ||
} | ||
export namespace MenuItem { | ||
export function is(object: any): object is MenuItem { | ||
return LabeledAction.is(object) && hasStringProp(object, 'id'); | ||
} | ||
} |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -17,14 +17,26 @@ * This program and the accompanying materials are made available under the | ||
import { isActionKind, Operation } from './base-protocol'; | ||
import { Operation } from './base-protocol'; | ||
/** | ||
* Trigger an undo of the latest executed command. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `UndoOperations`. | ||
*/ | ||
export class UndoOperation implements Operation { | ||
static readonly KIND = 'glspUndo'; | ||
constructor(public readonly kind = UndoOperation.KIND) {} | ||
export interface UndoOperation extends Operation { | ||
kind: typeof UndoOperation.KIND; | ||
} | ||
export function isUndoOperation(action: any): action is UndoOperation { | ||
return isActionKind(action, UndoOperation.KIND); | ||
export namespace UndoOperation { | ||
export const KIND = 'glspUndo'; | ||
export function is(object: any): object is UndoOperation { | ||
return Operation.hasKind(object, KIND); | ||
} | ||
export function create(): UndoOperation { | ||
return { | ||
kind: KIND, | ||
isOperation: true | ||
}; | ||
} | ||
} | ||
@@ -34,10 +46,22 @@ | ||
* Trigger a redo of the latest undone command. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `RedoOperations`. | ||
*/ | ||
export class RedoOperation implements Operation { | ||
static readonly KIND = 'glspRedo'; | ||
constructor(public readonly kind = RedoOperation.KIND) {} | ||
export interface RedoOperation extends Operation { | ||
kind: typeof RedoOperation.KIND; | ||
} | ||
export function isRedoOperation(action: any): action is RedoOperation { | ||
return isActionKind(action, RedoOperation.KIND); | ||
export namespace RedoOperation { | ||
export const KIND = 'glspRedo'; | ||
export function is(object: any): object is RedoOperation { | ||
return Operation.hasKind(object, KIND); | ||
} | ||
export function create(): RedoOperation { | ||
return { | ||
kind: KIND, | ||
isOperation: true | ||
}; | ||
} | ||
} |
/******************************************************************************** | ||
* Copyright (c) 2021 STMicroelectronics and others. | ||
* Copyright (c) 2021-2022 STMicroelectronics and others. | ||
* | ||
@@ -16,39 +16,98 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import { isArray, isBoolean } from '../utils/typeguard-util'; | ||
import { Action, isActionKind } from './base-protocol'; | ||
import * as sprotty from 'sprotty-protocol/lib/actions'; | ||
import { hasArrayProp, hasBooleanProp } from '../utils/type-util'; | ||
import { Action } from './base-protocol'; | ||
/** | ||
* Centers the viewport on the elements with the given identifiers. It changes the scroll setting of the viewport accordingly and resets | ||
* the zoom to its default. This action can also be created on the client but it can also be sent by the server in order to perform such | ||
* a viewport change remotely. | ||
* the zoom to its default. This action is usually be created on the client but it can also be sent by the server in order to perform such | ||
* a viewport change remotely. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `CenterActions`. | ||
*/ | ||
export class CenterAction implements Action { | ||
static readonly KIND = 'center'; | ||
readonly kind = CenterAction.KIND; | ||
export interface CenterAction extends Action, sprotty.CenterAction { | ||
kind: typeof CenterAction.KIND; | ||
constructor( | ||
public readonly elementIds: string[], | ||
public readonly animate: boolean = true, | ||
public readonly retainZoom: boolean = false | ||
) {} | ||
/** | ||
* The identifier of the elements on which the viewport should be centered. | ||
* If empty the root element will be used. | ||
*/ | ||
elementIds: string[]; | ||
/** | ||
* Indicate if the modification of the viewport should be realized with or without support of animations. | ||
*/ | ||
animate: boolean; | ||
/** | ||
* Indicates whether the zoom level should be kept. | ||
*/ | ||
retainZoom: boolean; | ||
} | ||
export function isCenterAction(action: any): action is CenterAction { | ||
return isActionKind(action, CenterAction.KIND) && isBoolean(action, 'animate') && isBoolean(action, 'retainZoom'); | ||
export namespace CenterAction { | ||
export const KIND = 'center'; | ||
export function is(object: any): object is CenterAction { | ||
return Action.hasKind(object, KIND) && hasBooleanProp(object, 'animate') && hasBooleanProp(object, 'retainZoom'); | ||
} | ||
export function create(elementIds: string[], options: { animate?: boolean; retainZoom?: boolean } = {}): CenterAction { | ||
return { | ||
kind: KIND, | ||
animate: true, | ||
retainZoom: false, | ||
elementIds, | ||
...options | ||
}; | ||
} | ||
} | ||
export class FitToScreenAction implements Action { | ||
static readonly KIND = 'fit'; | ||
readonly kind = FitToScreenAction.KIND; | ||
/** | ||
* Triggers to fit all or a list of elements into the available diagram canvas. | ||
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks | ||
* and creating new `CenterActions`. | ||
*/ | ||
export interface FitToScreenAction extends Action, sprotty.FitToScreenAction { | ||
kind: typeof FitToScreenAction.KIND; | ||
constructor( | ||
public readonly elementIds: string[], | ||
public readonly padding?: number, | ||
public readonly maxZoom?: number, | ||
public readonly animate: boolean = true | ||
) {} | ||
/** | ||
* The identifier of the elements to fit on screen. | ||
*/ | ||
elementIds: string[]; | ||
/** | ||
* The padding that should be visible on the viewport. | ||
*/ | ||
padding?: number; | ||
/** | ||
* The max zoom level authorized. | ||
*/ | ||
maxZoom?: number; | ||
/** | ||
* Indicate if the action should be performed with animation support or not. | ||
*/ | ||
animate: boolean; | ||
} | ||
export function isFitToScreenAction(action: any): action is FitToScreenAction { | ||
return isActionKind(action, FitToScreenAction.KIND) && isArray(action, 'elementIds') && isBoolean(action, 'animate'); | ||
export namespace FitToScreenAction { | ||
export const KIND = 'fit'; | ||
export function is(object: any): object is FitToScreenAction { | ||
return Action.hasKind(object, KIND) && hasArrayProp(object, 'elementIds') && hasBooleanProp(object, 'animate'); | ||
} | ||
export function create( | ||
elementIds: string[], | ||
options: { padding?: number; maxZoom?: number; animate?: boolean } = {} | ||
): FitToScreenAction { | ||
return { | ||
kind: KIND, | ||
animate: true, | ||
elementIds, | ||
...options | ||
}; | ||
} | ||
} |
/******************************************************************************** | ||
* Copyright (c) 2020-2021 EclipseSource and others. | ||
* Copyright (c) 2020-2022 EclipseSource and others. | ||
* | ||
@@ -16,2 +16,35 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import { SetBoundsAction, SetViewportAction } from 'sprotty-protocol/lib/actions'; | ||
import { Action } from './action-protocol'; | ||
import { hasBooleanProp, hasObjectProp, hasStringProp } from './utils/type-util'; | ||
// Add the is() function to the namespace declarations of sprotty-protocol actions | ||
declare module 'sprotty-protocol/lib/actions' { | ||
// eslint-disable-next-line no-shadow | ||
namespace SetViewportAction { | ||
export function is(object: any): object is SetViewportAction; | ||
} | ||
// eslint-disable-next-line no-shadow | ||
namespace SetBoundsAction { | ||
export function is(object: any): object is SetBoundsAction; | ||
} | ||
} | ||
SetViewportAction.is = (object: any): object is SetViewportAction => | ||
Action.hasKind(object, SetViewportAction.KIND) && | ||
hasStringProp(object, 'elementId') && | ||
hasObjectProp(object, 'newViewport') && | ||
hasBooleanProp(object, 'animate'); | ||
SetBoundsAction.is = (object: any): object is SetBoundsAction => | ||
Action.hasKind(object, SetBoundsAction.KIND) && hasObjectProp(object, 'bounds'); | ||
// Partial reexport of sprotty-protocol | ||
export { Viewport } from 'sprotty-protocol/lib/model'; | ||
export * from 'sprotty-protocol/lib/utils/async'; | ||
export * from 'sprotty-protocol/lib/utils/geometry'; | ||
export * from 'sprotty-protocol/lib/utils/json'; | ||
export * from 'sprotty-protocol/lib/utils/model-utils'; | ||
// Default export of @eclipse-glsp/protocol | ||
export * from './action-protocol'; | ||
@@ -21,5 +54,6 @@ export * from './glsp-client'; | ||
export * from './jsonrpc/glsp-jsonrpc-client'; | ||
export * from './types/default-types'; | ||
export * from './model/default-types'; | ||
export * from './model/model-schema'; | ||
export * from './utils/array-util'; | ||
export * from './utils/launch-util'; | ||
export * from './utils/typeguard-util'; | ||
export * from './utils/type-util'; | ||
export { SetBoundsAction, SetViewportAction }; |
/******************************************************************************** | ||
* Copyright (c) 2019-2021 EclipseSource and others. | ||
* Copyright (c) 2019-2022 EclipseSource and others. | ||
* | ||
@@ -16,5 +16,4 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import { ActionMessage } from 'sprotty'; | ||
import { Message, MessageConnection } from 'vscode-ws-jsonrpc'; | ||
import { ActionMessage } from '../action-protocol'; | ||
import { | ||
@@ -130,3 +129,3 @@ ActionMessageHandler, | ||
const connection = typeof this.connectionProvider === 'function' ? await this.connectionProvider() : this.connectionProvider; | ||
connection.onError((data: [Error, Message, number]) => this.handleConnectionError(data[0], data[1], data[2])); | ||
connection.onError(data => this.handleConnectionError(data[0], data[1], data[2])); | ||
connection.onClose(() => this.handleConnectionClosed()); | ||
@@ -136,3 +135,3 @@ return connection; | ||
protected handleConnectionError(error: Error, message: Message, count: number): void { | ||
protected handleConnectionError(error: Error, message: Message | undefined, count: number | undefined): void { | ||
JsonrpcGLSPClient.error('Connection to server is erroring. Shutting down server.', error); | ||
@@ -139,0 +138,0 @@ this.stop(); |
/******************************************************************************** | ||
* Copyright (c) 2020-2021 EclipseSource and others. | ||
* Copyright (c) 2020-2022 EclipseSource and others. | ||
* | ||
@@ -16,3 +16,2 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
import { ActionMessage } from 'sprotty'; | ||
import { MessageConnection, NotificationType, RequestType } from 'vscode-jsonrpc'; | ||
@@ -27,2 +26,3 @@ import { | ||
} from 'vscode-ws-jsonrpc'; | ||
import { ActionMessage } from '../action-protocol/base-protocol'; | ||
import { | ||
@@ -29,0 +29,0 @@ DisposeClientSessionParameters, |
/******************************************************************************** | ||
* Copyright (c) 2019-2021 EclipseSource and others. | ||
* Copyright (c) 2019-2022 EclipseSource and others. | ||
* | ||
@@ -16,13 +16,48 @@ * This program and the accompanying materials are made available under the | ||
********************************************************************************/ | ||
/** | ||
* A union type for for objects that can either be a single element or and array of elements. | ||
*/ | ||
export type MaybeArray<T> = T | T[]; | ||
export function remove<T>(array: T[], value: T): boolean { | ||
const index = array.indexOf(value); | ||
if (index >= 0) { | ||
array.splice(index, 1); | ||
return true; | ||
/** | ||
* Returns the first element of the given array. | ||
* @param array the array. | ||
* @returns the element at index 0. | ||
*/ | ||
export function first<T>(array: T[]): number; | ||
/** | ||
* Returns the first n elements of the given array. | ||
* @param array the array. | ||
* @param n the number of elements that should be returned | ||
* @returns the first n elements of the array | ||
*/ | ||
export function first<T>(array: T[], n: number): T[]; | ||
export function first<T>(array: T[], n?: number): T[] | T { | ||
if (n) { | ||
return array.filter((_, index) => index < n); | ||
} | ||
return false; | ||
return array[0]; | ||
} | ||
/** | ||
* Removes the given values from the given array (if present). | ||
* @param array The array to execute the remove operation on. | ||
* @param values The values that should be removed from the array. | ||
*/ | ||
export function remove<T>(array: T[], ...values: T[]): void { | ||
values.forEach(value => { | ||
const index = array.indexOf(value); | ||
if (index >= 0) { | ||
array.splice(index, 1); | ||
} | ||
}); | ||
} | ||
/** | ||
* Push an array of values to the given array. The values can either be single objects of a concrete type `T` | ||
* or can also be nested arrays of T. If nested arrays are passed the they will be destructured (i.e. flattened) | ||
* so that they can be pushed to the given array. | ||
* @param array The array to push to. | ||
* @param toPush The values of {@link MaybeArray}s that should be pushed. | ||
*/ | ||
export function flatPush<T>(array: T[], toPush: MaybeArray<T>[]): void { | ||
@@ -32,10 +67,15 @@ toPush.forEach(value => (Array.isArray(value) ? array.push(...value) : array.push(value))); | ||
export function distinctAdd<T>(array: T[], value: T): boolean { | ||
if (!array.includes(value)) { | ||
array.push(value); | ||
return true; | ||
} | ||
return false; | ||
/** | ||
* Adds the given values to the given array. The add operation is executed distinct meaning | ||
* a value will not be pushed to the array if its already present in the array. | ||
* @param array The array to push to. | ||
* @param values The values that should be added distinctively. | ||
*/ | ||
export function distinctAdd<T>(array: T[], ...values: T[]): void { | ||
values.forEach(value => { | ||
if (!array.includes(value)) { | ||
array.push(value); | ||
} | ||
}); | ||
} | ||
interface Constructor<T> { | ||
@@ -46,2 +86,10 @@ new (...args: any[]): T; | ||
/** | ||
* A typeguard function to check wether a given object is an array of a specific type `T`. As it checks the type of each individual | ||
* array element this guard check is expensive and should only be used in cases where complete type-safety is required. | ||
* @param object The object to check. | ||
* @param typeGuard A typeguard to check the type of the individual elements. | ||
* @param supportEmpty A flag to determine wether empty arrays should pass the typeguard check. | ||
* @returns A type predicate indicating wether the given object has passed the type guard check. | ||
*/ | ||
export function isArrayOfType<T>(object: any, typeGuard: (elem: any) => elem is T, supportEmpty = false): object is T[] { | ||
@@ -51,6 +99,22 @@ return isArrayMatching(object, element => typeGuard(element), supportEmpty); | ||
export function isArrayOfClass<T>(object: any, className: Constructor<T>, supportEmpty = false): object is T[] { | ||
return isArrayMatching(object, element => element instanceof className, supportEmpty); | ||
/** | ||
* A typeguard function to check wether a given object is an array of a class`T`. As it checks the wether each individual element | ||
* is an instance of the given class this guard check is expensive and should only be used in cases where complete type-safety is required. | ||
* @param object The object to check. | ||
* @param constructor The constructor for the class under test. | ||
* @param supportEmpty A flag to determine wether empty arrays should pass the typeguard check. | ||
* @returns A type predicate indicating wether the given object has passed the type guard check. | ||
*/ | ||
export function isArrayOfClass<T>(object: any, constructor: Constructor<T>, supportEmpty = false): object is T[] { | ||
return isArrayMatching(object, element => element instanceof constructor, supportEmpty); | ||
} | ||
/** | ||
* A typeguard function to check wether a given object is an array of a {@link PrimitiveType} `T. As it checks the type of each individual | ||
* array element this guard check is expensive and should only be used in cases where complete type-safety is required. | ||
* @param object The object to check. | ||
* @param primitiveType The expected primitive type of the elements. | ||
* @param supportEmpty A flag to determine wether empty arrays should pass the typeguard check. | ||
* @returns A type predicate indicating wether the given object has passed the type guard check. | ||
*/ | ||
export function isArrayOfPrimitive<T>(object: any, primitiveType: PrimitiveType, supportEmpty = false): object is T[] { | ||
@@ -60,2 +124,9 @@ return isArrayMatching(object, element => typeof element === primitiveType, supportEmpty); | ||
/** | ||
* A typeguard function to check wether a given object is an array of a strings. As it checks the type of each individual | ||
* array element this guard check is expensive and should only be used in cases where complete type-safety is required. | ||
* @param object The object to check. | ||
* @param supportEmpty A flag to determine wether empty arrays should pass the typeguard check. | ||
* @returns A type predicate indicating wether the given object has passed the type guard check. | ||
*/ | ||
export function isStringArray(object: any, supportEmpty = false): object is string[] { | ||
@@ -65,4 +136,11 @@ return isArrayOfPrimitive(object, 'string', supportEmpty); | ||
/** | ||
* A typeguard function to check wether a given object is an array where each element matches the given predicate. | ||
* @param object The object to check. | ||
* @param predicate The predicate to test with. | ||
* @param supportEmpty A flag to determine wether empty arrays be matched by the predicate.. | ||
* @returns `true` if the given object is an array and all elements match the given predicate. `false` otherwise. | ||
*/ | ||
export function isArrayMatching(object: any, predicate: (elem: any) => boolean, supportEmpty = false): boolean { | ||
return Array.isArray(object) && object.every(predicate) && (supportEmpty || object.length > 0); | ||
} |
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
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
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
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
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
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
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
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
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
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
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
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
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 7 instances in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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 6 instances in 1 package
873515
1
263
13386
13
2
+ Addedsprotty-protocol@next
+ Addedsprotty-protocol@1.3.0-next.9aa2083.6(transitive)
- Removedinversify@^5.0.1
- Removedinversify@5.1.1(transitive)