@itwin/editor-backend 3.6.0-dev.53 → 3.6.0-dev.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/EditBuiltInCommand.d.ts +78 -78
- package/lib/cjs/EditBuiltInCommand.js +638 -638
- package/lib/cjs/EditBuiltInCommand.js.map +1 -1
- package/lib/cjs/EditCommand.d.ts +57 -57
- package/lib/cjs/EditCommand.js +108 -108
- package/lib/cjs/EditCommand.js.map +1 -1
- package/lib/cjs/editor-backend.d.ts +2 -2
- package/lib/cjs/editor-backend.js +18 -18
- package/lib/cjs/editor-backend.js.map +1 -1
- package/package.json +12 -12
package/lib/cjs/EditCommand.js
CHANGED
|
@@ -1,109 +1,109 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
/** @packageDocumentation
|
|
7
|
-
* @module Editing
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.EditCommandAdmin = exports.EditCommand = void 0;
|
|
11
|
-
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
|
-
const core_backend_1 = require("@itwin/core-backend");
|
|
13
|
-
const core_common_1 = require("@itwin/core-common");
|
|
14
|
-
const editor_common_1 = require("@itwin/editor-common");
|
|
15
|
-
/**
|
|
16
|
-
* An EditCommand performs an editing action on the backend. EditCommands are usually paired with and driven by EditTools on the frontend.
|
|
17
|
-
* EditCommands have a *commandId* that uniquely identifies them, so they can be found via a lookup in the [[EditCommandAdmin]].
|
|
18
|
-
* Every time an EditCommand runs, a new instance of (a subclass of) this class is created.
|
|
19
|
-
* @alpha
|
|
20
|
-
*/
|
|
21
|
-
class EditCommand {
|
|
22
|
-
constructor(iModel, ..._args) {
|
|
23
|
-
this.iModel = iModel;
|
|
24
|
-
}
|
|
25
|
-
get ctor() { return this.constructor; }
|
|
26
|
-
async onStart() { }
|
|
27
|
-
async ping() {
|
|
28
|
-
return { version: this.ctor.version, commandId: this.ctor.commandId };
|
|
29
|
-
}
|
|
30
|
-
onCleanup() { }
|
|
31
|
-
onFinish() { }
|
|
32
|
-
}
|
|
33
|
-
exports.EditCommand = EditCommand;
|
|
34
|
-
/** The unique string that identifies this EditCommand class. This must be overridden in every subclass. */
|
|
35
|
-
EditCommand.commandId = "";
|
|
36
|
-
EditCommand.version = "1.0.0";
|
|
37
|
-
class EditorAppHandler extends core_backend_1.IpcHandler {
|
|
38
|
-
get channelName() { return editor_common_1.editorChannel; }
|
|
39
|
-
async startCommand(commandId, iModelKey, ...args) {
|
|
40
|
-
const commandClass = EditCommandAdmin.commands.get(commandId);
|
|
41
|
-
if (undefined === commandClass)
|
|
42
|
-
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NotRegistered, `Command not registered [${commandId}]`);
|
|
43
|
-
return EditCommandAdmin.runCommand(new commandClass(core_backend_1.IModelDb.findByKey(iModelKey), ...args));
|
|
44
|
-
}
|
|
45
|
-
async callMethod(methodName, ...args) {
|
|
46
|
-
const cmd = EditCommandAdmin.activeCommand;
|
|
47
|
-
if (!cmd)
|
|
48
|
-
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NoActiveCommand, `No active command`);
|
|
49
|
-
const func = cmd[methodName];
|
|
50
|
-
if (typeof func !== "function")
|
|
51
|
-
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.FunctionNotFound, `Method ${methodName} not found on ${cmd.ctor.commandId}`);
|
|
52
|
-
return func.call(cmd, ...args);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/** EditCommandAdmin holds a mapping between commandIds and their corresponding [[EditCommand]] class. This provides the mechanism to
|
|
56
|
-
* run EditCommands by commandId.
|
|
57
|
-
* It also keeps track of the currently active EditCommand. When a new EditCommand starts, the active EditCommand is terminated.
|
|
58
|
-
* @alpha
|
|
59
|
-
*/
|
|
60
|
-
class EditCommandAdmin {
|
|
61
|
-
static get activeCommand() { return this._activeCommand; }
|
|
62
|
-
static runCommand(cmd) {
|
|
63
|
-
if (this._activeCommand)
|
|
64
|
-
this._activeCommand.onFinish();
|
|
65
|
-
this._activeCommand = cmd;
|
|
66
|
-
return cmd ? cmd.onStart() : undefined;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Un-register a previously registered EditCommand class.
|
|
70
|
-
* @param commandId the commandId of a previously registered EditCommand to unRegister.
|
|
71
|
-
*/
|
|
72
|
-
static unRegister(commandId) {
|
|
73
|
-
this.commands.delete(commandId);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Register an EditCommand class. This establishes a connection between the commandId of the class and the class itself.
|
|
77
|
-
* @param commandType the subclass of Tool to register.
|
|
78
|
-
*/
|
|
79
|
-
static register(commandType) {
|
|
80
|
-
if (!this._isInitialized) {
|
|
81
|
-
this._isInitialized = true;
|
|
82
|
-
if (!core_backend_1.IpcHost.isValid)
|
|
83
|
-
throw new Error("Edit Commands require IpcHost");
|
|
84
|
-
EditorAppHandler.register();
|
|
85
|
-
}
|
|
86
|
-
if (commandType.commandId.length !== 0)
|
|
87
|
-
this.commands.set(commandType.commandId, commandType);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Register all the EditCommand classes found in a module.
|
|
91
|
-
* @param modelObj the module to search for subclasses of EditCommand.
|
|
92
|
-
*/
|
|
93
|
-
static registerModule(moduleObj) {
|
|
94
|
-
let foundOne = false;
|
|
95
|
-
for (const thisMember in moduleObj) { // eslint-disable-line guard-for-in
|
|
96
|
-
const thisCmd = moduleObj[thisMember];
|
|
97
|
-
if (thisCmd.prototype instanceof EditCommand) {
|
|
98
|
-
foundOne = true;
|
|
99
|
-
this.register(thisCmd);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
if (!foundOne)
|
|
103
|
-
throw new Error(`no EditCommands found - are you sure this is a module? Maybe you meant to call "register"?`);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
exports.EditCommandAdmin = EditCommandAdmin;
|
|
107
|
-
EditCommandAdmin.commands = new Map();
|
|
108
|
-
EditCommandAdmin._isInitialized = false;
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module Editing
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.EditCommandAdmin = exports.EditCommand = void 0;
|
|
11
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
|
+
const core_backend_1 = require("@itwin/core-backend");
|
|
13
|
+
const core_common_1 = require("@itwin/core-common");
|
|
14
|
+
const editor_common_1 = require("@itwin/editor-common");
|
|
15
|
+
/**
|
|
16
|
+
* An EditCommand performs an editing action on the backend. EditCommands are usually paired with and driven by EditTools on the frontend.
|
|
17
|
+
* EditCommands have a *commandId* that uniquely identifies them, so they can be found via a lookup in the [[EditCommandAdmin]].
|
|
18
|
+
* Every time an EditCommand runs, a new instance of (a subclass of) this class is created.
|
|
19
|
+
* @alpha
|
|
20
|
+
*/
|
|
21
|
+
class EditCommand {
|
|
22
|
+
constructor(iModel, ..._args) {
|
|
23
|
+
this.iModel = iModel;
|
|
24
|
+
}
|
|
25
|
+
get ctor() { return this.constructor; }
|
|
26
|
+
async onStart() { }
|
|
27
|
+
async ping() {
|
|
28
|
+
return { version: this.ctor.version, commandId: this.ctor.commandId };
|
|
29
|
+
}
|
|
30
|
+
onCleanup() { }
|
|
31
|
+
onFinish() { }
|
|
32
|
+
}
|
|
33
|
+
exports.EditCommand = EditCommand;
|
|
34
|
+
/** The unique string that identifies this EditCommand class. This must be overridden in every subclass. */
|
|
35
|
+
EditCommand.commandId = "";
|
|
36
|
+
EditCommand.version = "1.0.0";
|
|
37
|
+
class EditorAppHandler extends core_backend_1.IpcHandler {
|
|
38
|
+
get channelName() { return editor_common_1.editorChannel; }
|
|
39
|
+
async startCommand(commandId, iModelKey, ...args) {
|
|
40
|
+
const commandClass = EditCommandAdmin.commands.get(commandId);
|
|
41
|
+
if (undefined === commandClass)
|
|
42
|
+
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NotRegistered, `Command not registered [${commandId}]`);
|
|
43
|
+
return EditCommandAdmin.runCommand(new commandClass(core_backend_1.IModelDb.findByKey(iModelKey), ...args));
|
|
44
|
+
}
|
|
45
|
+
async callMethod(methodName, ...args) {
|
|
46
|
+
const cmd = EditCommandAdmin.activeCommand;
|
|
47
|
+
if (!cmd)
|
|
48
|
+
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.NoActiveCommand, `No active command`);
|
|
49
|
+
const func = cmd[methodName];
|
|
50
|
+
if (typeof func !== "function")
|
|
51
|
+
throw new core_common_1.IModelError(core_bentley_1.IModelStatus.FunctionNotFound, `Method ${methodName} not found on ${cmd.ctor.commandId}`);
|
|
52
|
+
return func.call(cmd, ...args);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** EditCommandAdmin holds a mapping between commandIds and their corresponding [[EditCommand]] class. This provides the mechanism to
|
|
56
|
+
* run EditCommands by commandId.
|
|
57
|
+
* It also keeps track of the currently active EditCommand. When a new EditCommand starts, the active EditCommand is terminated.
|
|
58
|
+
* @alpha
|
|
59
|
+
*/
|
|
60
|
+
class EditCommandAdmin {
|
|
61
|
+
static get activeCommand() { return this._activeCommand; }
|
|
62
|
+
static runCommand(cmd) {
|
|
63
|
+
if (this._activeCommand)
|
|
64
|
+
this._activeCommand.onFinish();
|
|
65
|
+
this._activeCommand = cmd;
|
|
66
|
+
return cmd ? cmd.onStart() : undefined;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Un-register a previously registered EditCommand class.
|
|
70
|
+
* @param commandId the commandId of a previously registered EditCommand to unRegister.
|
|
71
|
+
*/
|
|
72
|
+
static unRegister(commandId) {
|
|
73
|
+
this.commands.delete(commandId);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Register an EditCommand class. This establishes a connection between the commandId of the class and the class itself.
|
|
77
|
+
* @param commandType the subclass of Tool to register.
|
|
78
|
+
*/
|
|
79
|
+
static register(commandType) {
|
|
80
|
+
if (!this._isInitialized) {
|
|
81
|
+
this._isInitialized = true;
|
|
82
|
+
if (!core_backend_1.IpcHost.isValid)
|
|
83
|
+
throw new Error("Edit Commands require IpcHost");
|
|
84
|
+
EditorAppHandler.register();
|
|
85
|
+
}
|
|
86
|
+
if (commandType.commandId.length !== 0)
|
|
87
|
+
this.commands.set(commandType.commandId, commandType);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Register all the EditCommand classes found in a module.
|
|
91
|
+
* @param modelObj the module to search for subclasses of EditCommand.
|
|
92
|
+
*/
|
|
93
|
+
static registerModule(moduleObj) {
|
|
94
|
+
let foundOne = false;
|
|
95
|
+
for (const thisMember in moduleObj) { // eslint-disable-line guard-for-in
|
|
96
|
+
const thisCmd = moduleObj[thisMember];
|
|
97
|
+
if (thisCmd.prototype instanceof EditCommand) {
|
|
98
|
+
foundOne = true;
|
|
99
|
+
this.register(thisCmd);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (!foundOne)
|
|
103
|
+
throw new Error(`no EditCommands found - are you sure this is a module? Maybe you meant to call "register"?`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.EditCommandAdmin = EditCommandAdmin;
|
|
107
|
+
EditCommandAdmin.commands = new Map();
|
|
108
|
+
EditCommandAdmin._isInitialized = false;
|
|
109
109
|
//# sourceMappingURL=EditCommand.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"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,CAAC;SAC7B;QACD,IAAI,WAAW,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC;YACpC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,cAAc,CAAC,SAAc;QACzC,IAAI,QAAQ,GAAG,KAAK,CAAC;QACrB,KAAK,MAAM,UAAU,IAAI,SAAS,EAAE,EAAG,mCAAmC;YACxE,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;YACtC,IAAI,OAAO,CAAC,SAAS,YAAY,WAAW,EAAE;gBAC5C,QAAQ,GAAG,IAAI,CAAC;gBAChB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;aACxB;SACF;QACD,IAAI,CAAC,QAAQ;YACX,MAAM,IAAI,KAAK,CAAC,4FAA4F,CAAC,CAAC;IAClH,CAAC;;AApDH,4CAqDC;AApDwB,yBAAQ,GAAG,IAAI,GAAG,EAA2B,CAAC;AAGtD,+BAAc,GAAG,KAAK,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Editing\n */\n\nimport { IModelStatus } from \"@itwin/core-bentley\";\nimport { IModelDb, IpcHandler, IpcHost } from \"@itwin/core-backend\";\nimport { IModelError } from \"@itwin/core-common\";\nimport { EditCommandIpc, editorChannel, EditorIpc } from \"@itwin/editor-common\";\n\n/** @alpha */\nexport type EditCommandType = typeof EditCommand;\n\n/**\n * An EditCommand performs an editing action on the backend. EditCommands are usually paired with and driven by EditTools on the frontend.\n * EditCommands have a *commandId* that uniquely identifies them, so they can be found via a lookup in the [[EditCommandAdmin]].\n * Every time an EditCommand runs, a new instance of (a subclass of) this class is created.\n * @alpha\n */\nexport class EditCommand implements EditCommandIpc {\n /** The unique string that identifies this EditCommand class. This must be overridden in every subclass. */\n public static commandId = \"\";\n public static version = \"1.0.0\";\n\n /** The iModel this EditCommand may modify. */\n public readonly iModel: IModelDb;\n\n public constructor(iModel: IModelDb, ..._args: any[]) {\n this.iModel = iModel;\n }\n public get ctor(): EditCommandType { return this.constructor as EditCommandType; }\n\n public async onStart(): Promise<any> { }\n\n public async ping(): Promise<{ commandId: string, version: string, [propName: string]: any }> {\n return { version: this.ctor.version, commandId: this.ctor.commandId };\n }\n\n public onCleanup(): void { }\n\n public onFinish(): void { }\n}\n\nclass EditorAppHandler extends IpcHandler implements EditorIpc {\n public get channelName() { return editorChannel; }\n\n public async startCommand(commandId: string, iModelKey: string, ...args: any[]) {\n const commandClass = EditCommandAdmin.commands.get(commandId);\n if (undefined === commandClass)\n throw new IModelError(IModelStatus.NotRegistered, `Command not registered [${commandId}]`);\n\n return EditCommandAdmin.runCommand(new commandClass(IModelDb.findByKey(iModelKey), ...args));\n }\n\n public async callMethod(methodName: string, ...args: any[]) {\n const cmd = EditCommandAdmin.activeCommand;\n if (!cmd)\n throw new IModelError(IModelStatus.NoActiveCommand, `No active command`);\n\n const func = (cmd as any)[methodName];\n if (typeof func !== \"function\")\n throw new IModelError(IModelStatus.FunctionNotFound, `Method ${methodName} not found on ${cmd.ctor.commandId}`);\n\n return func.call(cmd, ...args);\n }\n}\n\n/** EditCommandAdmin holds a mapping between commandIds and their corresponding [[EditCommand]] class. This provides the mechanism to\n * run EditCommands by commandId.\n * It also keeps track of the currently active EditCommand. When a new EditCommand starts, the active EditCommand is terminated.\n * @alpha\n */\nexport class EditCommandAdmin {\n public static readonly commands = new Map<string, EditCommandType>();\n\n private static _activeCommand?: EditCommand;\n private static _isInitialized = false;\n public static get activeCommand() { return this._activeCommand; }\n\n public static runCommand(cmd?: EditCommand) {\n if (this._activeCommand)\n this._activeCommand.onFinish();\n this._activeCommand = cmd;\n return cmd ? cmd.onStart() : undefined;\n }\n\n /**\n * Un-register a previously registered EditCommand class.\n * @param commandId the commandId of a previously registered EditCommand to unRegister.\n */\n public static unRegister(commandId: string) {\n this.commands.delete(commandId);\n }\n\n /**\n * Register an EditCommand class. This establishes a connection between the commandId of the class and the class itself.\n * @param commandType the subclass of Tool to register.\n */\n public static register(commandType: EditCommandType) {\n if (!this._isInitialized) {\n this._isInitialized = true;\n if (!IpcHost.isValid)\n throw new Error(\"Edit Commands require IpcHost\");\n EditorAppHandler.register();\n }\n if (commandType.commandId.length !== 0)\n this.commands.set(commandType.commandId, commandType);\n }\n\n /**\n * Register all the EditCommand classes found in a module.\n * @param modelObj the module to search for subclasses of EditCommand.\n */\n public static registerModule(moduleObj: any) {\n let foundOne = false;\n for (const thisMember in moduleObj) { // eslint-disable-line guard-for-in\n const thisCmd = moduleObj[thisMember];\n if (thisCmd.prototype instanceof EditCommand) {\n foundOne = true;\n this.register(thisCmd);\n }\n }\n if (!foundOne)\n throw new Error(`no EditCommands found - are you sure this is a module? Maybe you meant to call \"register\"?`);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"EditCommand.js","sourceRoot":"","sources":["../../src/EditCommand.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAmD;AACnD,sDAAoE;AACpE,oDAAiD;AACjD,wDAAgF;AAKhF;;;;;GAKG;AACH,MAAa,WAAW;IAQtB,YAAmB,MAAgB,EAAE,GAAG,KAAY;QAClD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IACD,IAAW,IAAI,KAAsB,OAAO,IAAI,CAAC,WAA8B,CAAC,CAAC,CAAC;IAE3E,KAAK,CAAC,OAAO,KAAmB,CAAC;IAEjC,KAAK,CAAC,IAAI;QACf,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;IACxE,CAAC;IAEM,SAAS,KAAW,CAAC;IAErB,QAAQ,KAA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H,CAAC;;AApDH,4CAqDC;AApDwB,yBAAQ,GAAG,IAAI,GAAG,EAA2B,CAAC;AAGtD,+BAAc,GAAG,KAAK,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Editing\r\n */\r\n\r\nimport { IModelStatus } from \"@itwin/core-bentley\";\r\nimport { IModelDb, IpcHandler, IpcHost } from \"@itwin/core-backend\";\r\nimport { IModelError } from \"@itwin/core-common\";\r\nimport { EditCommandIpc, editorChannel, EditorIpc } from \"@itwin/editor-common\";\r\n\r\n/** @alpha */\r\nexport type EditCommandType = typeof EditCommand;\r\n\r\n/**\r\n * An EditCommand performs an editing action on the backend. EditCommands are usually paired with and driven by EditTools on the frontend.\r\n * EditCommands have a *commandId* that uniquely identifies them, so they can be found via a lookup in the [[EditCommandAdmin]].\r\n * Every time an EditCommand runs, a new instance of (a subclass of) this class is created.\r\n * @alpha\r\n */\r\nexport class EditCommand implements EditCommandIpc {\r\n /** The unique string that identifies this EditCommand class. This must be overridden in every subclass. */\r\n public static commandId = \"\";\r\n public static version = \"1.0.0\";\r\n\r\n /** The iModel this EditCommand may modify. */\r\n public readonly iModel: IModelDb;\r\n\r\n public constructor(iModel: IModelDb, ..._args: any[]) {\r\n this.iModel = iModel;\r\n }\r\n public get ctor(): EditCommandType { return this.constructor as EditCommandType; }\r\n\r\n public async onStart(): Promise<any> { }\r\n\r\n public async ping(): Promise<{ commandId: string, version: string, [propName: string]: any }> {\r\n return { version: this.ctor.version, commandId: this.ctor.commandId };\r\n }\r\n\r\n public onCleanup(): void { }\r\n\r\n public onFinish(): void { }\r\n}\r\n\r\nclass EditorAppHandler extends IpcHandler implements EditorIpc {\r\n public get channelName() { return editorChannel; }\r\n\r\n public async startCommand(commandId: string, iModelKey: string, ...args: any[]) {\r\n const commandClass = EditCommandAdmin.commands.get(commandId);\r\n if (undefined === commandClass)\r\n throw new IModelError(IModelStatus.NotRegistered, `Command not registered [${commandId}]`);\r\n\r\n return EditCommandAdmin.runCommand(new commandClass(IModelDb.findByKey(iModelKey), ...args));\r\n }\r\n\r\n public async callMethod(methodName: string, ...args: any[]) {\r\n const cmd = EditCommandAdmin.activeCommand;\r\n if (!cmd)\r\n throw new IModelError(IModelStatus.NoActiveCommand, `No active command`);\r\n\r\n const func = (cmd as any)[methodName];\r\n if (typeof func !== \"function\")\r\n throw new IModelError(IModelStatus.FunctionNotFound, `Method ${methodName} not found on ${cmd.ctor.commandId}`);\r\n\r\n return func.call(cmd, ...args);\r\n }\r\n}\r\n\r\n/** EditCommandAdmin holds a mapping between commandIds and their corresponding [[EditCommand]] class. This provides the mechanism to\r\n * run EditCommands by commandId.\r\n * It also keeps track of the currently active EditCommand. When a new EditCommand starts, the active EditCommand is terminated.\r\n * @alpha\r\n */\r\nexport class EditCommandAdmin {\r\n public static readonly commands = new Map<string, EditCommandType>();\r\n\r\n private static _activeCommand?: EditCommand;\r\n private static _isInitialized = false;\r\n public static get activeCommand() { return this._activeCommand; }\r\n\r\n public static runCommand(cmd?: EditCommand) {\r\n if (this._activeCommand)\r\n this._activeCommand.onFinish();\r\n this._activeCommand = cmd;\r\n return cmd ? cmd.onStart() : undefined;\r\n }\r\n\r\n /**\r\n * Un-register a previously registered EditCommand class.\r\n * @param commandId the commandId of a previously registered EditCommand to unRegister.\r\n */\r\n public static unRegister(commandId: string) {\r\n this.commands.delete(commandId);\r\n }\r\n\r\n /**\r\n * Register an EditCommand class. This establishes a connection between the commandId of the class and the class itself.\r\n * @param commandType the subclass of Tool to register.\r\n */\r\n public static register(commandType: EditCommandType) {\r\n if (!this._isInitialized) {\r\n this._isInitialized = true;\r\n if (!IpcHost.isValid)\r\n throw new Error(\"Edit Commands require IpcHost\");\r\n EditorAppHandler.register();\r\n }\r\n if (commandType.commandId.length !== 0)\r\n this.commands.set(commandType.commandId, commandType);\r\n }\r\n\r\n /**\r\n * Register all the EditCommand classes found in a module.\r\n * @param modelObj the module to search for subclasses of EditCommand.\r\n */\r\n public static registerModule(moduleObj: any) {\r\n let foundOne = false;\r\n for (const thisMember in moduleObj) { // eslint-disable-line guard-for-in\r\n const thisCmd = moduleObj[thisMember];\r\n if (thisCmd.prototype instanceof EditCommand) {\r\n foundOne = true;\r\n this.register(thisCmd);\r\n }\r\n }\r\n if (!foundOne)\r\n throw new Error(`no EditCommands found - are you sure this is a module? Maybe you meant to call \"register\"?`);\r\n }\r\n}\r\n"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./EditCommand";
|
|
2
|
-
export * from "./EditBuiltInCommand";
|
|
1
|
+
export * from "./EditCommand";
|
|
2
|
+
export * from "./EditBuiltInCommand";
|
|
3
3
|
//# sourceMappingURL=editor-backend.d.ts.map
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
/*---------------------------------------------------------------------------------------------
|
|
14
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
15
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
16
|
-
*--------------------------------------------------------------------------------------------*/
|
|
17
|
-
__exportStar(require("./EditCommand"), exports);
|
|
18
|
-
__exportStar(require("./EditBuiltInCommand"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
/*---------------------------------------------------------------------------------------------
|
|
14
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
15
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
16
|
+
*--------------------------------------------------------------------------------------------*/
|
|
17
|
+
__exportStar(require("./EditCommand"), exports);
|
|
18
|
+
__exportStar(require("./EditBuiltInCommand"), exports);
|
|
19
19
|
//# sourceMappingURL=editor-backend.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editor-backend.js","sourceRoot":"","sources":["../../src/editor-backend.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,gDAA8B;AAC9B,uDAAqC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nexport * from \"./EditCommand\";\nexport * from \"./EditBuiltInCommand\";\n\n"]}
|
|
1
|
+
{"version":3,"file":"editor-backend.js","sourceRoot":"","sources":["../../src/editor-backend.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,gDAA8B;AAC9B,uDAAqC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nexport * from \"./EditCommand\";\r\nexport * from \"./EditBuiltInCommand\";\r\n\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/editor-backend",
|
|
3
|
-
"version": "3.6.0-dev.
|
|
3
|
+
"version": "3.6.0-dev.55",
|
|
4
4
|
"description": "iTwin.js editor backend",
|
|
5
5
|
"main": "lib/cjs/editor-backend.js",
|
|
6
6
|
"typings": "lib/cjs/editor-backend",
|
|
@@ -24,28 +24,28 @@
|
|
|
24
24
|
"url": "http://www.bentley.com"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@itwin/core-backend": "^3.6.0-dev.
|
|
28
|
-
"@itwin/core-bentley": "^3.6.0-dev.
|
|
29
|
-
"@itwin/core-common": "^3.6.0-dev.
|
|
30
|
-
"@itwin/core-geometry": "^3.6.0-dev.
|
|
27
|
+
"@itwin/core-backend": "^3.6.0-dev.55",
|
|
28
|
+
"@itwin/core-bentley": "^3.6.0-dev.55",
|
|
29
|
+
"@itwin/core-common": "^3.6.0-dev.55",
|
|
30
|
+
"@itwin/core-geometry": "^3.6.0-dev.55"
|
|
31
31
|
},
|
|
32
32
|
"//devDependencies": [
|
|
33
33
|
"NOTE: All peerDependencies should also be listed as devDependencies since peerDependencies are not considered by npm install",
|
|
34
34
|
"NOTE: All tools used by scripts in this package must be listed as devDependencies"
|
|
35
35
|
],
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@itwin/build-tools": "3.6.0-dev.
|
|
38
|
-
"@itwin/core-backend": "3.6.0-dev.
|
|
39
|
-
"@itwin/core-bentley": "3.6.0-dev.
|
|
40
|
-
"@itwin/core-common": "3.6.0-dev.
|
|
41
|
-
"@itwin/core-geometry": "3.6.0-dev.
|
|
42
|
-
"@itwin/eslint-plugin": "3.6.0-dev.
|
|
37
|
+
"@itwin/build-tools": "3.6.0-dev.55",
|
|
38
|
+
"@itwin/core-backend": "3.6.0-dev.55",
|
|
39
|
+
"@itwin/core-bentley": "3.6.0-dev.55",
|
|
40
|
+
"@itwin/core-common": "3.6.0-dev.55",
|
|
41
|
+
"@itwin/core-geometry": "3.6.0-dev.55",
|
|
42
|
+
"@itwin/eslint-plugin": "3.6.0-dev.55",
|
|
43
43
|
"eslint": "^7.11.0",
|
|
44
44
|
"rimraf": "^3.0.2",
|
|
45
45
|
"typescript": "~4.4.0"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@itwin/editor-common": "3.6.0-dev.
|
|
48
|
+
"@itwin/editor-common": "3.6.0-dev.55"
|
|
49
49
|
},
|
|
50
50
|
"eslintConfig": {
|
|
51
51
|
"plugins": [
|