lucid-extension-sdk 1.0.0 → 1.0.1

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.
Files changed (66) hide show
  1. package/_validate_lucid-extension-sdk-ts_options.optionsvalid.d.ts +8 -0
  2. package/commandtypes.d.ts +71 -0
  3. package/{bin/constants.js → commandtypes.js} +0 -0
  4. package/{bin/constants.d.ts → constants.d.ts} +0 -0
  5. package/{bin/document/blockdefinition.js → constants.js} +0 -0
  6. package/core/jsonserializable.d.ts +8 -0
  7. package/{bin/document/pagedefinition.js → core/jsonserializable.js} +0 -0
  8. package/{bin/document → document}/blockclasses/blockproxyregistry.d.ts +0 -0
  9. package/{bin/document → document}/blockclasses/blockproxyregistry.js +1 -0
  10. package/{bin/document → document}/blockclasses/erdblockproxy.d.ts +0 -0
  11. package/{bin/document → document}/blockclasses/erdblockproxy.js +1 -0
  12. package/{bin/document → document}/blockdefinition.d.ts +0 -0
  13. package/{bin/math.js → document/blockdefinition.js} +0 -0
  14. package/{bin/document → document}/blockproxy.d.ts +0 -0
  15. package/{bin/document → document}/blockproxy.js +1 -0
  16. package/{bin/document → document}/documentproxy.d.ts +0 -0
  17. package/{bin/document → document}/documentproxy.js +1 -0
  18. package/{bin/document → document}/elementproxy.d.ts +0 -0
  19. package/{bin/document → document}/elementproxy.js +1 -0
  20. package/{bin/document → document}/groupproxy.d.ts +0 -0
  21. package/{bin/document → document}/groupproxy.js +1 -0
  22. package/{bin/document → document}/itemproxy.d.ts +0 -0
  23. package/{bin/document → document}/itemproxy.js +1 -0
  24. package/{bin/document → document}/linedefinition.d.ts +0 -0
  25. package/{bin/document → document}/linedefinition.js +1 -0
  26. package/{bin/document → document}/lineproxy.d.ts +0 -0
  27. package/{bin/document → document}/lineproxy.js +1 -0
  28. package/{bin/document → document}/mapproxy.d.ts +0 -0
  29. package/{bin/document → document}/mapproxy.js +1 -0
  30. package/{bin/document → document}/pagedefinition.d.ts +0 -0
  31. package/document/pagedefinition.js +2 -0
  32. package/{bin/document → document}/pageproxy.d.ts +0 -0
  33. package/{bin/document → document}/pageproxy.js +1 -0
  34. package/{bin/editorclient.d.ts → editorclient.d.ts} +0 -0
  35. package/{bin/editorclient.js → editorclient.js} +1 -0
  36. package/{bin/index.d.ts → index.d.ts} +0 -0
  37. package/index.js +6 -0
  38. package/{src/interop.d.ts → interop.d.ts} +0 -0
  39. package/{bin/math.d.ts → math.d.ts} +0 -0
  40. package/math.js +2 -0
  41. package/package.json +10 -4
  42. package/{bin/ui → ui}/menu.d.ts +0 -0
  43. package/{bin/ui → ui}/menu.js +1 -0
  44. package/{bin/ui → ui}/viewport.d.ts +0 -0
  45. package/{bin/ui → ui}/viewport.js +1 -0
  46. package/bin/index.js +0 -9
  47. package/src/constants.ts +0 -14
  48. package/src/document/blockclasses/blockproxyregistry.ts +0 -12
  49. package/src/document/blockclasses/erdblockproxy.ts +0 -41
  50. package/src/document/blockdefinition.ts +0 -6
  51. package/src/document/blockproxy.ts +0 -17
  52. package/src/document/documentproxy.ts +0 -28
  53. package/src/document/elementproxy.ts +0 -41
  54. package/src/document/groupproxy.ts +0 -25
  55. package/src/document/itemproxy.ts +0 -58
  56. package/src/document/linedefinition.ts +0 -41
  57. package/src/document/lineproxy.ts +0 -48
  58. package/src/document/mapproxy.ts +0 -43
  59. package/src/document/pagedefinition.ts +0 -3
  60. package/src/document/pageproxy.ts +0 -128
  61. package/src/editorclient.ts +0 -109
  62. package/src/index.ts +0 -4
  63. package/src/math.ts +0 -2
  64. package/src/ui/menu.ts +0 -43
  65. package/src/ui/viewport.ts +0 -22
  66. package/tsconfig.json +0 -38
@@ -0,0 +1,8 @@
1
+
2
+ // /home/ben/.cache/bazel/_bazel_ben/8a63763d5555f12fa5e47c2c43ebd4e3/sandbox/linux-sandbox/1940/execroot/lucid/node_modules/@bazel/typescript/internal/ts_project_options_validator.js checked attributes for //extensibility-sdk/lucid-extension-sdk:lucid-extension-sdk-ts
3
+ // composite: false
4
+ // declaration: true
5
+ // declaration_map: false
6
+ // incremental: false
7
+ // source_map: false
8
+ // emit_declaration_only: false
@@ -0,0 +1,71 @@
1
+ import { JsonSerializable } from './core/jsonserializable';
2
+ export declare const enum CommandName {
3
+ CreateBlock = "cb",
4
+ CreateLine = "cl",
5
+ CreatePage = "cp",
6
+ DeleteItem = "di",
7
+ DeletePage = "dp",
8
+ ElementExists = "ee",
9
+ GetElementType = "get",
10
+ GetProperty = "gp",
11
+ GetShapeData = "gsd",
12
+ ListBlocks = "lb",
13
+ ListGroups = "lg",
14
+ ListLines = "ll",
15
+ ListPages = "lp",
16
+ ListProperties = "lpr",
17
+ ListShapeData = "lsd",
18
+ ListTextAreas = "lta",
19
+ LoadBlockClasses = "lbc",
20
+ SetProperty = "sp"
21
+ }
22
+ export declare type CreateBlockQuery = {
23
+ 'p'?: string;
24
+ 'c': string;
25
+ };
26
+ export declare type CreateBlockResult = string | undefined;
27
+ export declare type CreateLineQuery = {
28
+ 'p'?: string;
29
+ };
30
+ export declare type CreateLineResult = string | undefined;
31
+ export declare type CreatePageQuery = undefined;
32
+ export declare type CreatePageResult = string | undefined;
33
+ export declare type DeleteItemQuery = string;
34
+ export declare type DeleteItemResult = boolean;
35
+ export declare type DeletePageQuery = string;
36
+ export declare type DeletePageResult = boolean;
37
+ export declare type ElementExistsQuery = string;
38
+ export declare type ElementExistsResult = boolean;
39
+ export declare type GetElementTypeQuery = string;
40
+ export declare type GetElementTypeResult = 'block' | 'line' | 'group' | 'page' | 'document' | 'generator' | 'panel';
41
+ export declare type GetPropertyQuery = {
42
+ 'id'?: string | undefined;
43
+ 'p': string;
44
+ };
45
+ export declare type GetPropertyResult = JsonSerializable;
46
+ export declare type GetShapeDataQuery = {
47
+ 'id': string;
48
+ 'n': string;
49
+ };
50
+ export declare type GetShapeDataResult = JsonSerializable;
51
+ export declare type ListChildrenQuery = {
52
+ 'id': string;
53
+ 'd'?: boolean;
54
+ };
55
+ export declare type ListChildrenResult = string[];
56
+ export declare type ListPagesQuery = undefined;
57
+ export declare type ListPagesResult = string[];
58
+ export declare type ListPropertiesQuery = string | undefined;
59
+ export declare type ListPropertiesResult = string[];
60
+ export declare type ListShapeDataQuery = string | undefined;
61
+ export declare type ListShapeDataResult = string[];
62
+ export declare type ListTextAreasQuery = string;
63
+ export declare type ListTextAreasResult = string[];
64
+ export declare type LoadBlockClassesQuery = string[];
65
+ export declare type LoadBlockClassesResult = Promise<undefined>;
66
+ export declare type SetPropertyQuery = {
67
+ 'id': string;
68
+ 'p': string;
69
+ 'v'?: JsonSerializable;
70
+ };
71
+ export declare type SetPropertyResult = undefined;
File without changes
File without changes
@@ -0,0 +1,8 @@
1
+ export declare type JsonArray = Array<JsonSerializable>;
2
+ export interface JsonObject {
3
+ [key: string]: JsonSerializable;
4
+ }
5
+ export interface JsonObjectConvertible {
6
+ toJsonObject(): JsonObject;
7
+ }
8
+ export declare type JsonSerializable = undefined | null | string | number | boolean | JsonArray | JsonObject;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findProxyClass = void 0;
3
4
  const erdblockproxy_1 = require("./erdblockproxy");
4
5
  const allProxyClasses = [erdblockproxy_1.ERDBlockProxy];
5
6
  function findProxyClass(className) {
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ERDBlockProxy = exports.ERDFieldProxy = void 0;
3
4
  const blockproxy_1 = require("../blockproxy");
4
5
  class ERDFieldProxy {
5
6
  constructor(block, index) {
File without changes
File without changes
File without changes
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BlockProxy = void 0;
3
4
  const itemproxy_1 = require("./itemproxy");
4
5
  const lineproxy_1 = require("./lineproxy");
5
6
  class BlockProxy extends itemproxy_1.ItemProxy {
File without changes
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocumentProxy = void 0;
3
4
  const elementproxy_1 = require("./elementproxy");
4
5
  const mapproxy_1 = require("./mapproxy");
5
6
  const pageproxy_1 = require("./pageproxy");
File without changes
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ElementProxy = void 0;
3
4
  const mapproxy_1 = require("./mapproxy");
4
5
  class ElementProxy {
5
6
  constructor(id, client) {
File without changes
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GroupProxy = void 0;
3
4
  const mapproxy_1 = require("./mapproxy");
4
5
  const lineproxy_1 = require("./lineproxy");
5
6
  const itemproxy_1 = require("./itemproxy");
File without changes
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ItemProxy = void 0;
3
4
  const elementproxy_1 = require("./elementproxy");
4
5
  const mapproxy_1 = require("./mapproxy");
5
6
  class ItemProxy extends elementproxy_1.ElementProxy {
File without changes
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isLineEndpointDefinition = exports.isBlockEndpointDefinition = void 0;
3
4
  const blockproxy_1 = require("./blockproxy");
4
5
  const lineproxy_1 = require("./lineproxy");
5
6
  function isBlockEndpointDefinition(ep) {
File without changes
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LineProxy = void 0;
3
4
  const itemproxy_1 = require("./itemproxy");
4
5
  class LineProxy extends itemproxy_1.ItemProxy {
5
6
  async getConnection(ep) {
File without changes
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WriteableMapProxy = exports.MapProxy = void 0;
3
4
  class MapProxy {
4
5
  constructor(client, keyCommand, keyParams, getter) {
5
6
  this.client = client;
File without changes
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
File without changes
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PageProxy = void 0;
3
4
  const elementproxy_1 = require("./elementproxy");
4
5
  const mapproxy_1 = require("./mapproxy");
5
6
  const lineproxy_1 = require("./lineproxy");
File without changes
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EditorClient = void 0;
3
4
  const blockproxy_1 = require("./document/blockproxy");
4
5
  const documentproxy_1 = require("./document/documentproxy");
5
6
  const elementproxy_1 = require("./document/elementproxy");
File without changes
package/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ __exportStar(require("./editorclient"), exports);
4
+ __exportStar(require("./document/documentproxy"), exports);
5
+ __exportStar(require("./ui/menu"), exports);
6
+ __exportStar(require("./ui/viewport"), exports);
File without changes
File without changes
package/math.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,13 +1,19 @@
1
1
  {
2
2
  "name": "lucid-extension-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Utility classes for writing Lucid Software editor extensions",
5
- "main": "bin/index.js",
6
- "types": "bin/index.d.ts",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
7
  "author": "",
8
8
  "license": "ISC",
9
9
  "declaration": true,
10
10
  "devDependencies": {
11
- "@types/node": "^16.11.11"
11
+ "@types/node": "^16.11.11",
12
+ "@bazel/typescript": "2.0.1",
13
+ "patch-package": "^6.4.7",
14
+ "typescript": "4.3.5"
15
+ },
16
+ "scripts": {
17
+ "postinstall": "patch-package"
12
18
  }
13
19
  }
File without changes
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Menu = void 0;
3
4
  class Menu {
4
5
  constructor(client) {
5
6
  this.client = client;
File without changes
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Viewport = void 0;
3
4
  const itemproxy_1 = require("../document/itemproxy");
4
5
  const pageproxy_1 = require("../document/pageproxy");
5
6
  class Viewport {
package/bin/index.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- function __export(m) {
3
- for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4
- }
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- __export(require("./editorclient"));
7
- __export(require("./document/documentproxy"));
8
- __export(require("./ui/menu"));
9
- __export(require("./ui/viewport"));
package/src/constants.ts DELETED
@@ -1,14 +0,0 @@
1
- export const enum OffsetType {
2
- NW = 0,
3
- NE = 1,
4
- SE = 2,
5
- SW = 3,
6
- MOVE = 4,
7
- ROTATE = 5,
8
- SCALE = 6,
9
- CUSTOM = 7,
10
- N = 8,
11
- E = 9,
12
- S = 10,
13
- W = 11,
14
- }
@@ -1,12 +0,0 @@
1
- import {BlockProxy} from '../blockproxy';
2
- import {ERDBlockProxy} from './erdblockproxy';
3
-
4
- export type BlockProxyConstructor = typeof BlockProxy & {
5
- classNameRegex: RegExp;
6
- };
7
-
8
- const allProxyClasses: BlockProxyConstructor[] = [ERDBlockProxy];
9
-
10
- export function findProxyClass(className: string): BlockProxyConstructor | undefined {
11
- return allProxyClasses.find((proxy) => proxy.classNameRegex.test(className));
12
- }
@@ -1,41 +0,0 @@
1
- import {BlockProxy} from '../blockproxy';
2
-
3
- export class ERDFieldProxy {
4
- constructor(private readonly block: ERDBlockProxy, private readonly index: number) {}
5
-
6
- public getName(): string {
7
- return this.block.properties.get('Field' + this.index);
8
- }
9
-
10
- public getType(): string {
11
- return this.block.properties.get('Type' + this.index) ?? '';
12
- }
13
-
14
- public getKey(): string {
15
- return this.block.properties.get('Key' + this.index) ?? '';
16
- }
17
- }
18
-
19
- export class ERDBlockProxy extends BlockProxy {
20
- public static classNameRegex = /^ERDEntityBlock(2|3|4)?$/;
21
-
22
- public getName(): string {
23
- return this.properties.get('Name');
24
- }
25
-
26
- public getFieldCount(): number {
27
- return this.properties.get('Fields');
28
- }
29
-
30
- public getFields() {
31
- const fields: ERDFieldProxy[] = [];
32
-
33
- const fieldCount = this.getFieldCount();
34
- for (let i = 1; i <= fieldCount; i++) {
35
- //These are 1-indexed in the property store
36
- fields.push(new ERDFieldProxy(this, i));
37
- }
38
-
39
- return fields;
40
- }
41
- }
@@ -1,6 +0,0 @@
1
- import {Box} from '../math';
2
-
3
- export type BlockDefinition = {
4
- className: string;
5
- boundingBox: Box;
6
- };
@@ -1,17 +0,0 @@
1
- import {ItemProxy} from './itemproxy';
2
- import {LineProxy} from './lineproxy';
3
-
4
- export class BlockProxy extends ItemProxy {
5
- public getClassName(): string {
6
- return this.properties.get('ClassName');
7
- }
8
-
9
- public getRotation(): number {
10
- return this.properties.get('Rotation');
11
- }
12
-
13
- public getConnectedLines() {
14
- const ids: string[] = this.client.sendCommand('gcl', this.id);
15
- return ids.map((id) => new LineProxy(id, this.client));
16
- }
17
- }
@@ -1,28 +0,0 @@
1
- import {EditorClient} from '../editorclient';
2
- import {ElementProxy} from './elementproxy';
3
- import {MapProxy} from './mapproxy';
4
- import {PageProxy} from './pageproxy';
5
- import {PageDefinition} from './pagedefinition';
6
-
7
- export class DocumentProxy extends ElementProxy {
8
- public readonly pages = new MapProxy<string, PageProxy>(
9
- this.client,
10
- 'lp',
11
- undefined,
12
- (pageId) => new PageProxy(pageId, this.client),
13
- );
14
-
15
- constructor(client: EditorClient) {
16
- super('', client);
17
- }
18
-
19
- public addPage(def: PageDefinition) {
20
- const id = this.client.sendCommand('cp', {
21
- 'Title': def.title,
22
- });
23
-
24
- const page = new PageProxy(id, this.client);
25
- page.setTitle(def.title);
26
- return page;
27
- }
28
- }
@@ -1,41 +0,0 @@
1
- import {EditorClient} from '../editorclient';
2
- import {MapProxy, WriteableMapProxy} from './mapproxy';
3
-
4
- export class ElementProxy {
5
- public readonly properties = new WriteableMapProxy<string, any>(
6
- this.client,
7
- 'lpr',
8
- this.id,
9
- (name) =>
10
- this.client.sendCommand('gp', {
11
- 'id': this.id,
12
- 'p': name,
13
- }),
14
- (name, value) => {
15
- if (name === 'BoundingBox') {
16
- throw new Error(
17
- 'Do not use properties.set() to move or resize items; use setLocation() or setBoundingBox() or offset()',
18
- );
19
- }
20
-
21
- this.client.sendCommand('sp', {
22
- 'id': this.id,
23
- 'p': name,
24
- 'v': value,
25
- });
26
- },
27
- );
28
-
29
- public readonly shapeData = new MapProxy<string, any>(this.client, 'lsd', this.id, (name) =>
30
- this.client.sendCommand('gsd', {
31
- 'id': this.id,
32
- 'n': name,
33
- }),
34
- );
35
-
36
- constructor(public readonly id: string, protected readonly client: EditorClient) {}
37
-
38
- public exists(): boolean {
39
- return this.client.sendCommand('ee', this.id);
40
- }
41
- }
@@ -1,25 +0,0 @@
1
- import {ElementProxy} from './elementproxy';
2
- import {MapProxy} from './mapproxy';
3
- import {BlockProxy} from './blockproxy';
4
- import {LineProxy} from './lineproxy';
5
- import {ItemProxy} from './itemproxy';
6
-
7
- export class GroupProxy extends ItemProxy {
8
- public readonly blocks = new MapProxy<string, BlockProxy>(this.client, 'lb', this.id, (id) =>
9
- this.client.getBlockProxy(id),
10
- );
11
-
12
- public readonly lines = new MapProxy<string, LineProxy>(
13
- this.client,
14
- 'll',
15
- this.id,
16
- (id) => new LineProxy(id, this.client),
17
- );
18
-
19
- public readonly groups = new MapProxy<string, GroupProxy>(
20
- this.client,
21
- 'lg',
22
- this.id,
23
- (id) => new GroupProxy(id, this.client),
24
- );
25
- }
@@ -1,58 +0,0 @@
1
- import {ElementProxy} from './elementproxy';
2
- import {MapProxy} from './mapproxy';
3
- import {OffsetType} from '../constants';
4
- import {Box, Point} from '../math';
5
-
6
- export class ItemProxy extends ElementProxy {
7
- public readonly textAreas = new MapProxy<string, string>(this.client, 'lta', this.id, (name) =>
8
- this.client.sendCommand('gp', {
9
- 'id': this.id,
10
- 'p': name,
11
- }),
12
- );
13
-
14
- public getBoundingBox() {
15
- return this.properties.get('BoundingBox') as Box;
16
- }
17
-
18
- public setBoundingBox(bb: Box) {
19
- const current = this.getBoundingBox();
20
- if (current.w === bb.w && current.h === bb.h) {
21
- //Move it into place
22
- if (current.x !== bb.x || current.y !== bb.y) {
23
- this.offset(OffsetType.MOVE, {x: bb.x - current.x, y: bb.y - current.y});
24
- }
25
- } else {
26
- //Stretch it to size
27
- if (current.x !== bb.x || current.y !== bb.y) {
28
- this.offset(OffsetType.NW, {x: bb.x - current.x, y: bb.y - current.y});
29
- }
30
- if (current.x + current.w !== bb.x + bb.w || current.y + current.h !== bb.y + bb.h) {
31
- this.offset(OffsetType.SE, {
32
- x: bb.x + bb.w - (current.x + current.w),
33
- y: bb.y + bb.h - (current.y + current.h),
34
- });
35
- }
36
- }
37
- }
38
-
39
- public getLocation() {
40
- const bb = this.getBoundingBox();
41
- return {x: bb.x, y: bb.y};
42
- }
43
-
44
- public setLocation(location: Point) {
45
- const current = this.getBoundingBox();
46
- if (current.x !== location.x || current.y !== location.y) {
47
- this.offset(OffsetType.MOVE, {x: location.x - current.x, y: location.y - current.y});
48
- }
49
- }
50
-
51
- public offset(type: OffsetType, offset: Point) {
52
- this.client.sendCommand('oi', {'ids': [this.id], 't': type, 'o': offset});
53
- }
54
-
55
- public delete() {
56
- this.client.sendCommand('di', this.id);
57
- }
58
- }
@@ -1,41 +0,0 @@
1
- import {BlockProxy} from './blockproxy';
2
- import {LineProxy} from './lineproxy';
3
-
4
- export interface EndpointStyle {
5
- style?: string; //Omit to use defaults (theme)
6
- }
7
-
8
- export interface BlockEndpointDefinition extends EndpointStyle {
9
- connection: BlockProxy;
10
- linkX: number; //0 to 1, relative X position in target block's bounding box
11
- linkY: number; //0 to 1, relative Y position in target block's bounding box
12
- inside?: boolean;
13
- autoLink?: boolean;
14
- padding?: number;
15
- }
16
-
17
- export interface LineEndpointDefinition extends EndpointStyle {
18
- connection: LineProxy;
19
- position: number; //0 to 1, distance along the target line
20
- }
21
-
22
- export interface PositionEndpointDefinition extends EndpointStyle {
23
- connection: void;
24
- x: number;
25
- y: number;
26
- }
27
-
28
- export type EndpointDefinition = BlockEndpointDefinition | LineEndpointDefinition | PositionEndpointDefinition;
29
-
30
- export function isBlockEndpointDefinition(ep: EndpointDefinition): ep is BlockEndpointDefinition {
31
- return ep.connection instanceof BlockProxy;
32
- }
33
-
34
- export function isLineEndpointDefinition(ep: EndpointDefinition): ep is LineEndpointDefinition {
35
- return ep.connection instanceof LineProxy;
36
- }
37
-
38
- export type LineDefinition = {
39
- endpoint1: EndpointDefinition;
40
- endpoint2: EndpointDefinition;
41
- };
@@ -1,48 +0,0 @@
1
- import {Point} from '../math';
2
- import {BlockProxy} from './blockproxy';
3
- import {ElementProxy} from './elementproxy';
4
- import {ItemProxy} from './itemproxy';
5
-
6
- export class LineProxy extends ItemProxy {
7
- private async getConnection(ep: {'Block'?: string; 'Line'?: string}) {
8
- let proxy: ElementProxy | undefined;
9
-
10
- if (ep['Block']) {
11
- proxy = this.client.getBlockProxy(ep['Block']);
12
- }
13
- if (ep['Line']) {
14
- proxy = new LineProxy(ep['Line'], this.client);
15
- }
16
-
17
- if (proxy && !proxy.exists()) {
18
- return undefined;
19
- }
20
-
21
- return proxy;
22
- }
23
-
24
- public async getUpstreamConnection() {
25
- const ep = this.properties.get('Endpoint1');
26
- if (!(typeof ep === 'object')) {
27
- return undefined;
28
- }
29
- return this.getConnection(ep);
30
- }
31
-
32
- public async getDownstreamConnection() {
33
- const ep = this.properties.get('Endpoint2');
34
- if (!(typeof ep === 'object')) {
35
- return undefined;
36
- }
37
- return this.getConnection(ep);
38
- }
39
-
40
- public getConnectedLines() {
41
- const ids: string[] = this.client.sendCommand('gcl', this.id);
42
- return ids.map((id) => new LineProxy(id, this.client));
43
- }
44
-
45
- public getRelativePosition(relative: number): Point {
46
- return this.client.sendCommand('grlp', {'id': this.id, 'p': relative});
47
- }
48
- }
@@ -1,43 +0,0 @@
1
- import {EditorClient} from '../editorclient';
2
-
3
- export class MapProxy<KEY, VALUE> {
4
- constructor(
5
- protected readonly client: EditorClient,
6
- private readonly keyCommand: string,
7
- private readonly keyParams: any,
8
- private readonly getter: (key: KEY) => VALUE,
9
- ) {}
10
-
11
- public *[Symbol.iterator](): Iterator<[KEY, VALUE]> {
12
- for (const key of this.keys()) {
13
- const value = this.get(key);
14
- if (value !== undefined) {
15
- yield [key, value];
16
- }
17
- }
18
- }
19
-
20
- public keys(): KEY[] {
21
- return this.client.sendCommand(this.keyCommand, this.keyParams);
22
- }
23
-
24
- public get(key: KEY) {
25
- return this.getter(key);
26
- }
27
- }
28
-
29
- export class WriteableMapProxy<KEY, VALUE> extends MapProxy<KEY, VALUE> {
30
- constructor(
31
- client: EditorClient,
32
- keyCommand: string,
33
- keyParams: any,
34
- getter: (key: KEY) => VALUE,
35
- private readonly setter: (key: KEY, val: VALUE) => void,
36
- ) {
37
- super(client, keyCommand, keyParams, getter);
38
- }
39
-
40
- public set(key: KEY, value: VALUE) {
41
- this.setter(key, value);
42
- }
43
- }
@@ -1,3 +0,0 @@
1
- export type PageDefinition = {
2
- title: string;
3
- };
@@ -1,128 +0,0 @@
1
- import {ElementProxy} from './elementproxy';
2
- import {MapProxy} from './mapproxy';
3
- import {BlockProxy} from './blockproxy';
4
- import {LineProxy} from './lineproxy';
5
- import {GroupProxy} from './groupproxy';
6
- import {BlockDefinition} from './blockdefinition';
7
- import {
8
- EndpointDefinition,
9
- LineDefinition,
10
- isBlockEndpointDefinition,
11
- isLineEndpointDefinition,
12
- } from './linedefinition';
13
-
14
- export class PageProxy extends ElementProxy {
15
- public readonly blocks = new MapProxy<string, BlockProxy>(this.client, 'lb', {id: this.id}, (id) =>
16
- this.client.getBlockProxy(id),
17
- );
18
-
19
- public readonly lines = new MapProxy<string, LineProxy>(
20
- this.client,
21
- 'll',
22
- {id: this.id},
23
- (id) => new LineProxy(id, this.client),
24
- );
25
-
26
- public readonly groups = new MapProxy<string, GroupProxy>(
27
- this.client,
28
- 'lg',
29
- {id: this.id},
30
- (id) => new GroupProxy(id, this.client),
31
- );
32
-
33
- public readonly allBlocks = new MapProxy<string, BlockProxy>(this.client, 'lb', {id: this.id, d: true}, (id) =>
34
- this.client.getBlockProxy(id),
35
- );
36
-
37
- public readonly allLines = new MapProxy<string, LineProxy>(
38
- this.client,
39
- 'll',
40
- {id: this.id, d: true},
41
- (id) => new LineProxy(id, this.client),
42
- );
43
-
44
- public readonly allGroups = new MapProxy<string, GroupProxy>(
45
- this.client,
46
- 'lg',
47
- {id: this.id, d: true},
48
- (id) => new GroupProxy(id, this.client),
49
- );
50
-
51
- public addBlock(def: BlockDefinition): BlockProxy {
52
- const properties: Record<string, any> = {};
53
- properties['BoundingBox'] = def.boundingBox;
54
-
55
- const id: string = this.client.sendCommand('cb', {
56
- 'p': this.id,
57
- 'c': def.className,
58
- });
59
-
60
- const block = this.client.getBlockProxy(id);
61
-
62
- for (const key in properties) {
63
- block.properties.set(key, properties[key]);
64
- }
65
-
66
- return block;
67
- }
68
-
69
- public addLine(def: LineDefinition): LineProxy {
70
- const properties: Record<string, any> = {};
71
-
72
- const setEndpoint = (ep: EndpointDefinition, name: string) => {
73
- if (isBlockEndpointDefinition(ep)) {
74
- const bb = ep.connection.getBoundingBox();
75
- properties[name] = {
76
- 'Style': ep.style,
77
- 'x': bb.x + bb.w * ep.linkX,
78
- 'y': bb.y + bb.h * ep.linkY,
79
- 'Block': ep.connection.id,
80
- 'LinkX': ep.linkX,
81
- 'LinkY': ep.linkY,
82
- 'Inside': ep.inside,
83
- 'AutoLink': ep.autoLink,
84
- 'Padding': ep.padding,
85
- };
86
- } else if (isLineEndpointDefinition(ep)) {
87
- properties[name] = {
88
- 'Style': ep.style,
89
- 'Line': ep.connection.id,
90
- 'LineP': ep.position,
91
- ...ep.connection.getRelativePosition(ep.position), //x,y
92
- };
93
- } else {
94
- properties[name] = {
95
- 'Style': ep.style,
96
- 'x': ep.x,
97
- 'y': ep.y,
98
- };
99
- }
100
- };
101
- setEndpoint(def.endpoint1, 'Endpoint1');
102
- setEndpoint(def.endpoint2, 'Endpoint2');
103
-
104
- const id = this.client.sendCommand('cl', {
105
- 'p': this.id,
106
- });
107
-
108
- const line = new LineProxy(id, this.client);
109
-
110
- for (const key in properties) {
111
- line.properties.set(key, properties[key]);
112
- }
113
-
114
- return line;
115
- }
116
-
117
- public setTitle(title: string) {
118
- this.properties.set('Title', title);
119
- }
120
-
121
- public getTitle(): string {
122
- return this.properties.get('Title');
123
- }
124
-
125
- public delete() {
126
- this.client.sendCommand('dp', this.id);
127
- }
128
- }
@@ -1,109 +0,0 @@
1
- import {BlockProxy} from './document/blockproxy';
2
- import {DocumentProxy} from './document/documentproxy';
3
- import {ElementProxy} from './document/elementproxy';
4
- import {GroupProxy} from './document/groupproxy';
5
- import {LineProxy} from './document/lineproxy';
6
- import {PageProxy} from './document/pageproxy';
7
- import {findProxyClass} from './document/blockclasses/blockproxyregistry';
8
-
9
- export class EditorClient {
10
- private nextId = 0;
11
- private readonly oneTimeCallbacks = new Map<number, (value: any) => void>();
12
- private readonly actions = new Map<string, (value: any) => void>();
13
-
14
- public killExtension() {
15
- this.sendCommand('k');
16
- }
17
-
18
- public reloadExtension() {
19
- this.sendCommand('r');
20
- }
21
-
22
- public download(filename: string, data: string, mime: string, base64: boolean) {
23
- this.sendCommand('d', {
24
- 'f': filename,
25
- 'd': data,
26
- 'm': mime,
27
- 'b64': base64,
28
- });
29
- }
30
-
31
- public showModal(title: string, width: number, height: number, content: string) {
32
- this.sendCommand('sm', {
33
- 't': title,
34
- 'w': width,
35
- 'h': height,
36
- 'c': content,
37
- });
38
- }
39
-
40
- public hideModal() {
41
- this.sendCommand('hm');
42
- }
43
-
44
- public registerOneTimeAction(cb: (value: any) => void): number {
45
- const id = this.nextId++;
46
- this.oneTimeCallbacks.set(id, cb);
47
- return id;
48
- }
49
-
50
- public registerAction(name: string, cb: (value: any) => void): void {
51
- this.actions.set(name, cb);
52
- }
53
-
54
- public deleteAction(name: string) {
55
- this.actions.delete(name);
56
- }
57
-
58
- public actionExists(name: string) {
59
- return this.actions.has(name);
60
- }
61
-
62
- public sendCommand(name: string, params?: any): any {
63
- return lucid.executeCommand(name, params);
64
- }
65
-
66
- public getBlockProxy(id: string): BlockProxy {
67
- const className = this.sendCommand('gp', {'id': id, 'p': 'ClassName'});
68
- const proxy = findProxyClass(className);
69
- if (proxy) {
70
- return new proxy(id, this);
71
- } else {
72
- return new BlockProxy(id, this);
73
- }
74
- }
75
-
76
- public loadBlockClasses(classNames: string[]): Promise<undefined> {
77
- return this.sendCommand('lbc', classNames);
78
- }
79
-
80
- public getElementProxy(id: string) {
81
- const type: string = this.sendCommand('get', id);
82
- switch (type) {
83
- case 'block':
84
- return this.getBlockProxy(id);
85
- case 'line':
86
- return new LineProxy(id, this);
87
- case 'page':
88
- return new PageProxy(id, this);
89
- case 'document':
90
- return new DocumentProxy(this);
91
- case 'group':
92
- return new GroupProxy(id, this);
93
- default:
94
- return new ElementProxy(id, this);
95
- }
96
- }
97
-
98
- constructor() {
99
- lucid.listen((msg: any) => {
100
- const resolver = this.oneTimeCallbacks.get(msg['id']);
101
- if (resolver) {
102
- resolver(msg['r']);
103
- this.oneTimeCallbacks.delete(msg['id']);
104
- } else {
105
- this.actions.get(msg['id'])?.(msg);
106
- }
107
- });
108
- }
109
- }
package/src/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './editorclient';
2
- export * from './document/documentproxy';
3
- export * from './ui/menu';
4
- export * from './ui/viewport';
package/src/math.ts DELETED
@@ -1,2 +0,0 @@
1
- export type Point = {x: number; y: number};
2
- export type Box = {x: number; y: number; w: number; h: number};
package/src/ui/menu.ts DELETED
@@ -1,43 +0,0 @@
1
- import {EditorClient} from '../editorclient';
2
- export const enum MenuType {
3
- Main = 0,
4
- Context = 1,
5
- }
6
-
7
- export interface CustomMenuItem {
8
- //The menu item itself
9
- label: string;
10
- action: string;
11
-
12
- //Where to display it
13
- menuType: MenuType;
14
-
15
- /**
16
- * The standard menu item to display this item after.
17
- * Examples:
18
- * ['file'] -> put at the top of the File menu
19
- * ['file', 'duplicate'] -> put after Duplicate in the File menu
20
- * ['file', 'export'] -> put at the top of the export submenu
21
- *
22
- * The path is interpreted up to the first invalid entry.
23
- * If the resulting valid path is empty, a new top-level menu named Add-ons appears before Help and this is added
24
- */
25
- path: string[];
26
- }
27
-
28
- export class Menu {
29
- constructor(private readonly client: EditorClient) {}
30
-
31
- public addMenuItem(item: CustomMenuItem) {
32
- if (!this.client.actionExists(item.action)) {
33
- throw new Error('Unregistered action: ' + item.action);
34
- }
35
-
36
- this.client.sendCommand('ami', {
37
- 'l': item.label,
38
- 'a': item.action,
39
- 't': item.menuType,
40
- 'p': item.path,
41
- });
42
- }
43
- }
@@ -1,22 +0,0 @@
1
- import {ItemProxy} from '../document/itemproxy';
2
- import {PageProxy} from '../document/pageproxy';
3
- import {EditorClient} from '../editorclient';
4
-
5
- export class Viewport {
6
- constructor(private readonly client: EditorClient) {}
7
-
8
- public getSelectedItems(): ItemProxy[] {
9
- const ids: string[] = this.client.sendCommand('gs');
10
- return ids
11
- .map((id) => this.client.getElementProxy(id))
12
- .filter((proxy) => proxy instanceof ItemProxy) as ItemProxy[];
13
- }
14
-
15
- public getCurrentPage() {
16
- return new PageProxy(this.client.sendCommand('gcp'), this.client);
17
- }
18
-
19
- public setCurrentPage(page: PageProxy) {
20
- this.client.sendCommand('scp', page.id);
21
- }
22
- }
package/tsconfig.json DELETED
@@ -1,38 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "declaration": true,
4
- "emitDecoratorMetadata": true,
5
- "experimentalDecorators": true,
6
- "forceConsistentCasingInFileNames": true,
7
- "module": "commonjs",
8
- "moduleResolution": "node",
9
- "newLine": "lf",
10
- "noEmitHelpers": true,
11
- "noEmitOnError": false,
12
- "noImplicitAny": true,
13
- "noImplicitReturns": true,
14
- "noImplicitThis": true,
15
- "noUnusedLocals": false,
16
- "pretty": true,
17
- "removeComments": false,
18
- "skipLibCheck": true,
19
- "sourceMap": false,
20
- "strictBindCallApply": true,
21
- "strictFunctionTypes": true,
22
- "strictNullChecks": true,
23
- "strictPropertyInitialization": true,
24
- "target": "ES2017",
25
- "types": ["node"],
26
- "lib": ["dom", "es5", "es6", "ES2016.Array.Include", "ES2017.String", "ES2018.Promise"],
27
- "outDir": "bin",
28
- },
29
- "files":[
30
- "src/interop.d.ts",
31
- ],
32
- "include": [
33
- "src/**/*"
34
- ],
35
- "exclude": [
36
- "node_modules"
37
- ]
38
- }