lucid-extension-sdk 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,6 +4,113 @@
4
4
 
5
5
  TypeScript SDK for building in-editor extensions for the products of Lucid Software.
6
6
 
7
+ ## Getting started
8
+
9
+ To get started building an extension for Lucid products, follow the instructions in
10
+ the [`lucid-package` CLI](https://www.npmjs.com/package/lucid-package).
11
+
12
+ ## Simple examples
13
+
14
+ ### Add a new entry in the main menu
15
+
16
+ ```
17
+ import {EditorClient, Menu, MenuType} from 'lucid-extension-sdk';
18
+
19
+ const client = new EditorClient();
20
+ const menu = new Menu(client);
21
+
22
+ client.registerAction('my-new-action', () => {
23
+ console.log('Hello world');
24
+ });
25
+
26
+ menu.addMenuItem({
27
+ label: 'Hello world',
28
+ action: 'my-new-action',
29
+ menuType: MenuType.Main,
30
+ });
31
+ ```
32
+
33
+ ### Create a new page and add some shapes to it
34
+
35
+ ```
36
+ import {DocumentProxy, EditorClient, Menu, MenuType, Viewport} from 'lucid-extension-sdk';
37
+
38
+ const client = new EditorClient();
39
+ const menu = new Menu(client);
40
+ const viewport = new Viewport(client);
41
+ const document = new DocumentProxy(client);
42
+
43
+ client.registerAction('create-content', async () => {
44
+ const page = document.addPage({title: 'Hello world'});
45
+ viewport.setCurrentPage(page);
46
+
47
+ //Before creating any blocks, you must make sure the code
48
+ //for that kind of block is loaded.
49
+ await client.loadBlockClasses(['ProcessBlock']);
50
+
51
+ let y = 0;
52
+ for (const char of 'Hello world') {
53
+ const block = page.addBlock({
54
+ className: 'ProcessBlock',
55
+ boundingBox: {
56
+ x: 0,
57
+ y,
58
+ w: 60,
59
+ h: 60,
60
+ },
61
+ });
62
+
63
+ const textAreaName = block.textAreas.keys()[0];
64
+ block.textAreas.set(textAreaName, char);
65
+
66
+ y += 80;
67
+ }
68
+ });
69
+
70
+ menu.addMenuItem({
71
+ label: 'Hello world',
72
+ action: 'create-content',
73
+ menuType: MenuType.Main,
74
+ });
75
+ ```
76
+
77
+ ### Create and download a CSV with shape data from the current page
78
+
79
+ ```
80
+ import {EditorClient, Menu, MenuLocation, MenuType, Viewport} from 'lucid-extension-sdk';
81
+
82
+ const client = new EditorClient();
83
+ const menu = new Menu(client);
84
+ const viewport = new Viewport(client);
85
+
86
+ client.registerAction('download', async () => {
87
+ const page = viewport.getCurrentPage();
88
+ if (!page) {
89
+ return;
90
+ }
91
+
92
+ const csv: string[][] = [['Type', 'ID', 'Text', 'DataValue']];
93
+
94
+ for (const [id, block] of page?.allBlocks) {
95
+ csv.push([
96
+ block.getClassName(),
97
+ block.id,
98
+ block.textAreas.first() ?? '',
99
+ JSON.stringify(block.allShapeData.get('DataValue')),
100
+ ]);
101
+ }
102
+
103
+ client.download('data.csv', csv.map((line) => line.join(',')).join('\n'), 'text/plain', false);
104
+ });
105
+
106
+ menu.addMenuItem({
107
+ label: 'Download CSV',
108
+ action: 'download',
109
+ menuType: MenuType.Main,
110
+ location: MenuLocation.Export, //Near File -> Export
111
+ });
112
+ ```
113
+
7
114
  ## License
8
115
 
9
116
  This project is distributed under the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucid-extension-sdk",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Utility classes for writing Lucid Software editor extensions",
5
5
  "main": "sdk/index.js",
6
6
  "types": "sdk/index.d.ts",
@@ -8,8 +8,9 @@
8
8
  "license": "Apache-2.0",
9
9
  "declaration": true,
10
10
  "devDependencies": {
11
- "@types/node": "^16.11.11",
12
11
  "@bazel/typescript": "2.0.1",
12
+ "@types/node": "^16.11.11",
13
+ "typedoc": "^0.22.11",
13
14
  "typescript": "4.3.5"
14
15
  }
15
16
  }
@@ -1,7 +1,3 @@
1
- /**
2
- * Once we have full server support for complex field types,
3
- * we should be able to support object/array data here
4
- */
5
1
  export declare type SerializedFieldType = number | boolean | string | null | SerializedLucidDateObject | SerializedColorObjectFieldType | SerializedLucidDictionary | SerializedLucidCurrency | undefined | Array<SerializedFieldType>;
6
2
  export declare type SerializedLucidDictionary = {
7
3
  'dict': {
@@ -36,5 +36,5 @@ export declare class CollectionProxy extends ElementProxy {
36
36
  /**
37
37
  * @returns an array of field names that are accessible on the items in this collection
38
38
  */
39
- getFields(): import("../commandtypes").ListCollectionFieldsResult;
39
+ getFields(): string[];
40
40
  }
@@ -17,5 +17,5 @@ export declare class DataItemProxy {
17
17
  /**
18
18
  * The fields on this data item, organized by their name.
19
19
  */
20
- readonly fields: MapProxy<string, import("../core/serializedfields").SerializedFieldType>;
20
+ readonly fields: MapProxy<string, import("..").SerializedFieldType>;
21
21
  }
@@ -4,8 +4,8 @@ export declare class ERDFieldProxy {
4
4
  private readonly index;
5
5
  constructor(block: ERDBlockProxy, index: number);
6
6
  getName(): string;
7
- getType(): string | number | boolean | import("../../core/jsonserializable").JsonArray | import("../../core/jsonserializable").JsonObject;
8
- getKey(): string | number | boolean | import("../../core/jsonserializable").JsonArray | import("../../core/jsonserializable").JsonObject;
7
+ getType(): string | number | boolean | import("../..").JsonArray | import("../..").JsonObject;
8
+ getKey(): string | number | boolean | import("../..").JsonArray | import("../..").JsonObject;
9
9
  }
10
10
  export declare class ERDBlockProxy extends BlockProxy {
11
11
  static classNameRegex: RegExp;
@@ -17,7 +17,7 @@ export declare class ElementProxy {
17
17
  * Not all properties are writeable (e.g. "ClassName" on a block).
18
18
  * To move or resize elements, use setLocation() or setBoundingBox() or offset() instead.
19
19
  */
20
- readonly properties: WriteableMapProxy<string, import("../core/jsonserializable").JsonSerializable>;
20
+ readonly properties: WriteableMapProxy<string, import("..").JsonSerializable>;
21
21
  /**
22
22
  * The shape data set directly on this element (not including any shape data inherited from the page or a containing group).
23
23
  */
@@ -26,7 +26,7 @@ export declare class ElementProxy {
26
26
  * All shape data accessible on this element, including shape data inherited from the page or a containing group.
27
27
  * This collection is read-only.
28
28
  */
29
- readonly allShapeData: MapProxy<string, import("../core/serializedfields").SerializedFieldType | import("../data/dataerror").DataError>;
29
+ readonly allShapeData: MapProxy<string, import("..").SerializedFieldType | import("..").DataError>;
30
30
  /**
31
31
  *
32
32
  * @param id ID of this element, or undefined for the document itself
@@ -42,5 +42,5 @@ export declare class ElementProxy {
42
42
  * @param formula The formula text, e.g. "@a + @b" to add together the shape data values a and b.
43
43
  * @returns the result of the formula, or an error.
44
44
  */
45
- executeFormula(formula: string): import("../core/serializedfields").SerializedFieldType | import("../data/dataerror").DataError;
45
+ executeFormula(formula: string): import("..").SerializedFieldType | import("..").DataError;
46
46
  }
@@ -2,7 +2,7 @@ import { LinearOffsetType } from '../core/offsettype';
2
2
  import { EditorClient } from '../editorclient';
3
3
  import { Box, Point } from '../math';
4
4
  import { ElementProxy } from './elementproxy';
5
- import { MapProxy } from './mapproxy';
5
+ import { WriteableMapProxy } from './mapproxy';
6
6
  /**
7
7
  * A block, line, or group on a page of the current document.
8
8
  */
@@ -16,7 +16,7 @@ export declare class ItemProxy extends ElementProxy {
16
16
  /**
17
17
  * The plain text in each of the text areas on this item, organized by text area name.
18
18
  */
19
- readonly textAreas: MapProxy<string, string>;
19
+ readonly textAreas: WriteableMapProxy<string, string>;
20
20
  /**
21
21
  * @returns the bounding box of this item relative to its containing page. As pages may change size
22
22
  * to fit the content on them, note that these coordinates may be negative or very large.
@@ -18,9 +18,13 @@ class ItemProxy extends elementproxy_1.ElementProxy {
18
18
  /**
19
19
  * The plain text in each of the text areas on this item, organized by text area name.
20
20
  */
21
- this.textAreas = new mapproxy_1.MapProxy(() => this.client.sendCommand("lta" /* ListTextAreas */, this.id), (name) => this.client.sendCommand("gp" /* GetProperty */, {
21
+ this.textAreas = new mapproxy_1.WriteableMapProxy(() => this.client.sendCommand("lta" /* ListTextAreas */, this.id), (name) => this.client.sendCommand("gp" /* GetProperty */, {
22
22
  'id': this.id,
23
23
  'p': name,
24
+ }), (name, plainText) => this.client.sendCommand("sp" /* SetProperty */, {
25
+ 'id': this.id,
26
+ 'p': name,
27
+ 'v': plainText,
24
28
  }));
25
29
  }
26
30
  /**
@@ -62,12 +62,17 @@ export declare class EditorClient {
62
62
  * Register a named action. These actions can be triggered from custom UI, for example as the action of a
63
63
  * custom menu item.
64
64
  *
65
- * Throws an error if the same action is registered multiple times.
65
+ * Some actions may return a value that is used by the core application, e.g. a `visibleAction` for a menu
66
+ * item. However, if you return a `Promise` from your callback, that value will be discarded and your
67
+ * action will return `undefined` instead. The ability to provide a callback that returns a Promise is only
68
+ * a convenience so that you can register actions with `async` callbacks for easy async/await.
69
+ *
70
+ * Throws an error if the same action name is registered multiple times.
66
71
  *
67
72
  * @param name name of the action
68
73
  * @param callback function to execute when this action is invoked
69
74
  */
70
- registerAction(name: string, callback: (value: any) => JsonSerializable | void): void;
75
+ registerAction(name: string, callback: (value: any) => JsonSerializable | void | Promise<any>): void;
71
76
  /**
72
77
  * Remove the callback for a given action. If the action is later invoked, nothing will happen.
73
78
  * @param name name of the action to unregister
@@ -82,6 +87,7 @@ export declare class EditorClient {
82
87
  * Execute an API command. This is the low-level API that most of this SDK wraps. It is not expected that you should
83
88
  * ever need to use this directly.
84
89
  *
90
+ * @hidden
85
91
  * @param name name of the API command to execute
86
92
  * @param params data to pass to the API command
87
93
  * @returns the output of the given API command
@@ -120,6 +126,9 @@ export declare class EditorClient {
120
126
  * @returns the given element
121
127
  */
122
128
  getElementProxy(id: string): ElementProxy;
129
+ /**
130
+ * @hidden
131
+ */
123
132
  protected listenToEditor(): void;
124
133
  constructor();
125
134
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EditorClient = void 0;
4
+ const checks_1 = require("./core/checks");
4
5
  const blockproxyregistry_1 = require("./document/blockclasses/blockproxyregistry");
5
6
  const blockproxy_1 = require("./document/blockproxy");
6
7
  const documentproxy_1 = require("./document/documentproxy");
@@ -78,7 +79,12 @@ class EditorClient {
78
79
  * Register a named action. These actions can be triggered from custom UI, for example as the action of a
79
80
  * custom menu item.
80
81
  *
81
- * Throws an error if the same action is registered multiple times.
82
+ * Some actions may return a value that is used by the core application, e.g. a `visibleAction` for a menu
83
+ * item. However, if you return a `Promise` from your callback, that value will be discarded and your
84
+ * action will return `undefined` instead. The ability to provide a callback that returns a Promise is only
85
+ * a convenience so that you can register actions with `async` callbacks for easy async/await.
86
+ *
87
+ * Throws an error if the same action name is registered multiple times.
82
88
  *
83
89
  * @param name name of the action
84
90
  * @param callback function to execute when this action is invoked
@@ -111,6 +117,7 @@ class EditorClient {
111
117
  * Execute an API command. This is the low-level API that most of this SDK wraps. It is not expected that you should
112
118
  * ever need to use this directly.
113
119
  *
120
+ * @hidden
114
121
  * @param name name of the API command to execute
115
122
  * @param params data to pass to the API command
116
123
  * @returns the output of the given API command
@@ -182,10 +189,17 @@ class EditorClient {
182
189
  return new elementproxy_1.ElementProxy(id, this);
183
190
  }
184
191
  }
192
+ /**
193
+ * @hidden
194
+ */
185
195
  listenToEditor() {
186
196
  lucid.listen((msg) => {
187
197
  var _a;
188
- return (_a = this.callbacks.get(msg['id'])) === null || _a === void 0 ? void 0 : _a(msg);
198
+ const value = (_a = this.callbacks.get(msg['id'])) === null || _a === void 0 ? void 0 : _a(msg);
199
+ if ((0, checks_1.isPromise)(value)) {
200
+ return undefined;
201
+ }
202
+ return value;
189
203
  });
190
204
  }
191
205
  }
package/sdk/index.d.ts CHANGED
@@ -1,7 +1,29 @@
1
- export { DataProxy } from './data/dataproxy';
2
- export { DocumentProxy } from './document/documentproxy';
3
- export { EditorClient } from './editorclient';
4
- export { AlertModal } from './ui/alertmodal';
5
- export { CustomMenuItem, Menu, MenuLocation, MenuType } from './ui/menu';
6
- export { Modal } from './ui/modal';
7
- export { Viewport } from './ui/viewport';
1
+ export * from './core/dataerrortype';
2
+ export * from './core/jsonserializable';
3
+ export * from './core/offsettype';
4
+ export * from './core/serializeddataerror';
5
+ export * from './core/serializedfields';
6
+ export * from './core/shapedatainheritance';
7
+ export * from './data/collectionproxy';
8
+ export * from './data/dataerror';
9
+ export * from './data/dataitemproxy';
10
+ export * from './data/dataproxy';
11
+ export * from './data/datasourceproxy';
12
+ export * from './document/blockdefinition';
13
+ export * from './document/blockproxy';
14
+ export * from './document/documentproxy';
15
+ export * from './document/elementproxy';
16
+ export * from './document/groupproxy';
17
+ export * from './document/itemproxy';
18
+ export * from './document/linedefinition';
19
+ export * from './document/lineproxy';
20
+ export * from './document/mapproxy';
21
+ export * from './document/pagedefinition';
22
+ export * from './document/pageproxy';
23
+ export * from './document/shapedataproxy';
24
+ export * from './editorclient';
25
+ export * from './math';
26
+ export * from './ui/alertmodal';
27
+ export * from './ui/menu';
28
+ export * from './ui/modal';
29
+ export * from './ui/viewport';
package/sdk/index.js CHANGED
@@ -1,19 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Viewport = exports.Modal = exports.MenuType = exports.MenuLocation = exports.Menu = exports.AlertModal = exports.EditorClient = exports.DocumentProxy = exports.DataProxy = void 0;
4
- var dataproxy_1 = require("./data/dataproxy");
5
- Object.defineProperty(exports, "DataProxy", { enumerable: true, get: function () { return dataproxy_1.DataProxy; } });
6
- var documentproxy_1 = require("./document/documentproxy");
7
- Object.defineProperty(exports, "DocumentProxy", { enumerable: true, get: function () { return documentproxy_1.DocumentProxy; } });
8
- var editorclient_1 = require("./editorclient");
9
- Object.defineProperty(exports, "EditorClient", { enumerable: true, get: function () { return editorclient_1.EditorClient; } });
10
- var alertmodal_1 = require("./ui/alertmodal");
11
- Object.defineProperty(exports, "AlertModal", { enumerable: true, get: function () { return alertmodal_1.AlertModal; } });
12
- var menu_1 = require("./ui/menu");
13
- Object.defineProperty(exports, "Menu", { enumerable: true, get: function () { return menu_1.Menu; } });
14
- Object.defineProperty(exports, "MenuLocation", { enumerable: true, get: function () { return menu_1.MenuLocation; } });
15
- Object.defineProperty(exports, "MenuType", { enumerable: true, get: function () { return menu_1.MenuType; } });
16
- var modal_1 = require("./ui/modal");
17
- Object.defineProperty(exports, "Modal", { enumerable: true, get: function () { return modal_1.Modal; } });
18
- var viewport_1 = require("./ui/viewport");
19
- Object.defineProperty(exports, "Viewport", { enumerable: true, get: function () { return viewport_1.Viewport; } });
3
+ __exportStar(require("./core/dataerrortype"), exports);
4
+ __exportStar(require("./core/jsonserializable"), exports);
5
+ __exportStar(require("./core/offsettype"), exports);
6
+ __exportStar(require("./core/serializeddataerror"), exports);
7
+ __exportStar(require("./core/serializedfields"), exports);
8
+ __exportStar(require("./core/shapedatainheritance"), exports);
9
+ __exportStar(require("./data/collectionproxy"), exports);
10
+ __exportStar(require("./data/dataerror"), exports);
11
+ __exportStar(require("./data/dataitemproxy"), exports);
12
+ __exportStar(require("./data/dataproxy"), exports);
13
+ __exportStar(require("./data/datasourceproxy"), exports);
14
+ __exportStar(require("./document/blockdefinition"), exports);
15
+ __exportStar(require("./document/blockproxy"), exports);
16
+ __exportStar(require("./document/documentproxy"), exports);
17
+ __exportStar(require("./document/elementproxy"), exports);
18
+ __exportStar(require("./document/groupproxy"), exports);
19
+ __exportStar(require("./document/itemproxy"), exports);
20
+ __exportStar(require("./document/linedefinition"), exports);
21
+ __exportStar(require("./document/lineproxy"), exports);
22
+ __exportStar(require("./document/mapproxy"), exports);
23
+ __exportStar(require("./document/pagedefinition"), exports);
24
+ __exportStar(require("./document/pageproxy"), exports);
25
+ __exportStar(require("./document/shapedataproxy"), exports);
26
+ __exportStar(require("./editorclient"), exports);
27
+ __exportStar(require("./math"), exports);
28
+ __exportStar(require("./ui/alertmodal"), exports);
29
+ __exportStar(require("./ui/menu"), exports);
30
+ __exportStar(require("./ui/modal"), exports);
31
+ __exportStar(require("./ui/viewport"), exports);