lucid-extension-sdk 0.0.6 → 0.0.13

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 (55) hide show
  1. package/interop.d.ts +4 -0
  2. package/package.json +3 -3
  3. package/sdk/commandtypes.d.ts +241 -5
  4. package/sdk/commandtypes.js +6 -0
  5. package/sdk/core/data/referencekeys/serializedreferencekey.d.ts +6 -0
  6. package/sdk/core/data/referencekeys/serializedreferencekey.js +17 -1
  7. package/sdk/core/jsonserializable.d.ts +4 -0
  8. package/sdk/data/collectionproxy.d.ts +2 -2
  9. package/sdk/data/collectionproxy.js +2 -2
  10. package/sdk/data/datasourceproxy.d.ts +9 -3
  11. package/sdk/data/datasourceproxy.js +9 -3
  12. package/sdk/data/referencekeydefinition.d.ts +30 -2
  13. package/sdk/data/referencekeydefinition.js +26 -1
  14. package/sdk/data/referencekeyproxy.d.ts +4 -0
  15. package/sdk/data/referencekeyproxy.js +25 -0
  16. package/sdk/data/schemadefinition.d.ts +13 -0
  17. package/sdk/data/schemadefinition.js +13 -1
  18. package/sdk/document/blockclasses/blockproxyregistry.js +2 -1
  19. package/sdk/document/blockclasses/customblockproxy.d.ts +6 -0
  20. package/sdk/document/blockclasses/customblockproxy.js +24 -0
  21. package/sdk/document/blockdefinition.d.ts +4 -2
  22. package/sdk/document/blockproxy.d.ts +20 -4
  23. package/sdk/document/blockproxy.js +31 -4
  24. package/sdk/document/documentproxy.d.ts +22 -2
  25. package/sdk/document/documentproxy.js +33 -2
  26. package/sdk/document/elementproxy.d.ts +26 -18
  27. package/sdk/document/elementproxy.js +26 -29
  28. package/sdk/document/groupproxy.d.ts +1 -1
  29. package/sdk/document/groupproxy.js +1 -1
  30. package/sdk/document/itemproxy.d.ts +5 -5
  31. package/sdk/document/itemproxy.js +5 -5
  32. package/sdk/document/lineproxy.d.ts +32 -6
  33. package/sdk/document/lineproxy.js +52 -6
  34. package/sdk/document/linetextareapositioning.d.ts +31 -0
  35. package/sdk/document/linetextareapositioning.js +30 -0
  36. package/sdk/document/mapproxy.d.ts +7 -1
  37. package/sdk/document/mapproxy.js +8 -0
  38. package/sdk/document/propertystoreproxy.d.ts +21 -0
  39. package/sdk/document/propertystoreproxy.js +37 -0
  40. package/sdk/document/shapedataproxy.d.ts +5 -0
  41. package/sdk/document/shapedataproxy.js +5 -0
  42. package/sdk/editorclient.d.ts +8 -2
  43. package/sdk/editorclient.js +51 -9
  44. package/sdk/index.d.ts +1 -0
  45. package/sdk/index.js +1 -0
  46. package/sdk/ui/alertmodal.d.ts +2 -3
  47. package/sdk/ui/alertmodal.js +2 -3
  48. package/sdk/ui/iframeui.d.ts +57 -0
  49. package/sdk/ui/iframeui.js +82 -0
  50. package/sdk/ui/modal.d.ts +11 -33
  51. package/sdk/ui/modal.js +9 -46
  52. package/sdk/ui/panel.d.ts +43 -0
  53. package/sdk/ui/panel.js +50 -0
  54. package/sdk/ui/viewport.d.ts +45 -0
  55. package/sdk/ui/viewport.js +80 -0
@@ -1,6 +1,6 @@
1
1
  import { JsonSerializable } from '../core/jsonserializable';
2
- import { ElementProxy } from '../document/elementproxy';
3
2
  import { MapProxy } from '../document/mapproxy';
3
+ import { PropertyStoreProxy } from '../document/propertystoreproxy';
4
4
  import { EditorClient } from '../editorclient';
5
5
  import { CollectionProxy } from './collectionproxy';
6
6
  import { SchemaDefinition } from './schemadefinition';
@@ -8,7 +8,7 @@ import { SchemaDefinition } from './schemadefinition';
8
8
  * A data source represents a set of related data collections on a document. Typically one data source
9
9
  * is produced for each data import.
10
10
  */
11
- export declare class DataSourceProxy extends ElementProxy {
11
+ export declare class DataSourceProxy extends PropertyStoreProxy {
12
12
  readonly id: string;
13
13
  /**
14
14
  * @param id ID of the collection on the current document
@@ -21,9 +21,15 @@ export declare class DataSourceProxy extends ElementProxy {
21
21
  * the collection ID on other documents if the same data is imported there.
22
22
  */
23
23
  readonly collections: MapProxy<string, CollectionProxy>;
24
+ /**
25
+ * Create a new collection as part of this data source.
26
+ * @param name
27
+ * @param schema
28
+ * @returns The newly created collection
29
+ */
24
30
  addCollection(name: string, schema: SchemaDefinition): CollectionProxy;
25
31
  /**
26
- * @returns a human-readable name for this data source
32
+ * @returns A human-readable name for this data source
27
33
  */
28
34
  getName(): string;
29
35
  /**
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DataSourceProxy = void 0;
4
4
  const checks_1 = require("../core/checks");
5
5
  const fieldtypedefinition_1 = require("../core/data/fieldtypedefinition/fieldtypedefinition");
6
- const elementproxy_1 = require("../document/elementproxy");
7
6
  const mapproxy_1 = require("../document/mapproxy");
7
+ const propertystoreproxy_1 = require("../document/propertystoreproxy");
8
8
  const collectionproxy_1 = require("./collectionproxy");
9
9
  /**
10
10
  * A data source represents a set of related data collections on a document. Typically one data source
11
11
  * is produced for each data import.
12
12
  */
13
- class DataSourceProxy extends elementproxy_1.ElementProxy {
13
+ class DataSourceProxy extends propertystoreproxy_1.PropertyStoreProxy {
14
14
  /**
15
15
  * @param id ID of the collection on the current document
16
16
  * @param client
@@ -25,6 +25,12 @@ class DataSourceProxy extends elementproxy_1.ElementProxy {
25
25
  */
26
26
  this.collections = new mapproxy_1.MapProxy(() => this.client.sendCommand("lc" /* ListCollections */, { 'id': this.id }), (id) => new collectionproxy_1.CollectionProxy(id, this.client));
27
27
  }
28
+ /**
29
+ * Create a new collection as part of this data source.
30
+ * @param name
31
+ * @param schema
32
+ * @returns The newly created collection
33
+ */
28
34
  addCollection(name, schema) {
29
35
  return new collectionproxy_1.CollectionProxy(this.client.sendCommand("cc" /* CreateCollection */, {
30
36
  's': this.id,
@@ -34,7 +40,7 @@ class DataSourceProxy extends elementproxy_1.ElementProxy {
34
40
  }), this.client);
35
41
  }
36
42
  /**
37
- * @returns a human-readable name for this data source
43
+ * @returns A human-readable name for this data source
38
44
  */
39
45
  getName() {
40
46
  return this.properties.get('Name');
@@ -1,17 +1,45 @@
1
1
  import { SerializedReferenceKeyType } from '../core/data/referencekeys/serializedreferencekey';
2
2
  import { SerializedFieldType } from '../core/data/serializedfield/serializedfields';
3
3
  import { SchemaDefinition } from './schemadefinition';
4
+ /**
5
+ * A reference key that points to a [DataItem](#classes_data_dataitemproxy-DataItemProxy) in a
6
+ * [Collection](#classes_data_collectionproxy-CollectionProxy). This is the most common type of
7
+ * reference key to create.
8
+ *
9
+ * For more information, see the [Developer Guide](/extension-api#guide-reference-keys).
10
+ */
4
11
  export interface CollectionReferenceKeyDefinition {
12
+ /** The ID of the collection referenced */
5
13
  collectionId: string;
14
+ /** The [primary key](#classes_data_dataitemproxy-DataItemProxy_primarykey) of the data item referenced */
6
15
  primaryKey: string;
7
- fieldWhitelist?: string[];
16
+ /** If true, prevent the user from editing the field values of this reference key through the normal UI */
8
17
  readonly?: boolean;
18
+ /**
19
+ * If specified, only expose this list of fields through this reference key. This can be used to limit
20
+ * namespace pollution in shape data from lots of unnecessary fields, or just to hide information you'd
21
+ * prefer not to be visible in the UI or through formulas.
22
+ */
23
+ fieldWhitelist?: string[];
9
24
  }
25
+ /**
26
+ * A reference key that has the field values embedded directly in the reference definition. This can be
27
+ * useful in cases when you want to have a standard schema of data associated with an element but do not
28
+ * for whatever reason want to construct an actual [Collection](#classes_data_collectionproxy-CollectionProxy)
29
+ * to house that data.
30
+ */
10
31
  export interface FlattenedReferenceDefinition {
11
- name: string;
32
+ /** Name to display to the user for the reference key (what would normally be the collection name) */
33
+ name?: string;
34
+ /** Schema of the data stored at this key */
12
35
  schema: SchemaDefinition;
36
+ /** Field values available at this reference key */
13
37
  data: Record<string, SerializedFieldType>;
14
38
  }
15
39
  export declare type ReferenceKeyDefinition = CollectionReferenceKeyDefinition | FlattenedReferenceDefinition;
40
+ /** @ignore */
16
41
  export declare function isCollectionReferenceKeyDefinition(def: ReferenceKeyDefinition): def is CollectionReferenceKeyDefinition;
42
+ /** @ignore */
17
43
  export declare function serializeReferenceKeyDefinition(def: ReferenceKeyDefinition): SerializedReferenceKeyType;
44
+ /** @ignore */
45
+ export declare function parseReferenceKeyDefinition(def: SerializedReferenceKeyType): ReferenceKeyDefinition;
@@ -1,12 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.serializeReferenceKeyDefinition = exports.isCollectionReferenceKeyDefinition = void 0;
3
+ exports.parseReferenceKeyDefinition = exports.serializeReferenceKeyDefinition = exports.isCollectionReferenceKeyDefinition = void 0;
4
4
  const checks_1 = require("../core/checks");
5
+ const serializedreferencekey_1 = require("../core/data/referencekeys/serializedreferencekey");
5
6
  const schemadefinition_1 = require("./schemadefinition");
7
+ /** @ignore */
6
8
  function isCollectionReferenceKeyDefinition(def) {
7
9
  return (0, checks_1.isString)(def.collectionId);
8
10
  }
9
11
  exports.isCollectionReferenceKeyDefinition = isCollectionReferenceKeyDefinition;
12
+ /** @ignore */
10
13
  function serializeReferenceKeyDefinition(def) {
11
14
  if (isCollectionReferenceKeyDefinition(def)) {
12
15
  return {
@@ -25,3 +28,25 @@ function serializeReferenceKeyDefinition(def) {
25
28
  }
26
29
  }
27
30
  exports.serializeReferenceKeyDefinition = serializeReferenceKeyDefinition;
31
+ /** @ignore */
32
+ function parseReferenceKeyDefinition(def) {
33
+ if ((0, serializedreferencekey_1.isTypedSerializedFlattenedReference)(def)) {
34
+ return {
35
+ schema: (0, schemadefinition_1.parseSchemaDefinition)(def['sc']),
36
+ name: def['n'],
37
+ data: def['d'],
38
+ };
39
+ }
40
+ else if ((0, serializedreferencekey_1.isUnTypedSerializedFlattenedReference)(def)) {
41
+ throw new Error('Untyped serialized flattened references not implemented');
42
+ }
43
+ else {
44
+ return {
45
+ collectionId: def['cid'],
46
+ primaryKey: def['pk'],
47
+ fieldWhitelist: def['wl'],
48
+ readonly: def['ro'],
49
+ };
50
+ }
51
+ }
52
+ exports.parseReferenceKeyDefinition = parseReferenceKeyDefinition;
@@ -6,4 +6,8 @@ export declare class ReferenceKeyProxy {
6
6
  private readonly client;
7
7
  private readonly settings;
8
8
  constructor(elementId: string | undefined, key: string | number, client: EditorClient, settings: SerializedReferenceKeyType);
9
+ get collectionId(): string | undefined;
10
+ get primaryKey(): string | undefined;
11
+ get definition(): import("./referencekeydefinition").ReferenceKeyDefinition;
12
+ getItem(): import("./dataitemproxy").DataItemProxy;
9
13
  }
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ReferenceKeyProxy = void 0;
4
+ const serializedreferencekey_1 = require("../core/data/referencekeys/serializedreferencekey");
5
+ const collectionproxy_1 = require("./collectionproxy");
6
+ const referencekeydefinition_1 = require("./referencekeydefinition");
4
7
  class ReferenceKeyProxy {
5
8
  constructor(elementId, key, client, settings) {
6
9
  this.elementId = elementId;
@@ -8,5 +11,27 @@ class ReferenceKeyProxy {
8
11
  this.client = client;
9
12
  this.settings = settings;
10
13
  }
14
+ get collectionId() {
15
+ if ((0, serializedreferencekey_1.isSerializedFlattenedReference)(this.settings)) {
16
+ return undefined;
17
+ }
18
+ return this.settings['cid'];
19
+ }
20
+ get primaryKey() {
21
+ if ((0, serializedreferencekey_1.isSerializedFlattenedReference)(this.settings)) {
22
+ return undefined;
23
+ }
24
+ return this.settings['pk'];
25
+ }
26
+ get definition() {
27
+ return (0, referencekeydefinition_1.parseReferenceKeyDefinition)(this.settings);
28
+ }
29
+ getItem() {
30
+ const collectionId = this.collectionId;
31
+ if ((0, serializedreferencekey_1.isSerializedFlattenedReference)(this.settings) || !collectionId) {
32
+ throw new Error('Not implemented for flattened references');
33
+ }
34
+ return new collectionproxy_1.CollectionProxy(collectionId, this.client).items.get(this.settings['pk']);
35
+ }
11
36
  }
12
37
  exports.ReferenceKeyProxy = ReferenceKeyProxy;
@@ -1,11 +1,24 @@
1
1
  import { FieldTypeDefinition } from '../core/data/fieldtypedefinition/fieldtypedefinition';
2
2
  import { SerializedSchema } from '../core/data/serializedfield/serializedschema';
3
+ /**
4
+ * The definition for a field to be included in a [SchemaDefinition](#interfaces_data_schemadefinition-SchemaDefinition)
5
+ */
3
6
  export interface FieldDefinition {
4
7
  name: string;
5
8
  type: FieldTypeDefinition;
6
9
  }
10
+ /**
11
+ * Definition of a schema for creating a [Collection](#classes_data_collectionproxy-CollectionProxy)
12
+ */
7
13
  export interface SchemaDefinition {
8
14
  fields: FieldDefinition[];
15
+ /**
16
+ * Field names that are used to construct primary keys for new data items.
17
+ * Typically this contains only one field name, and that field is usually unique.
18
+ */
9
19
  primaryKey: string[];
10
20
  }
21
+ /** @ignore */
11
22
  export declare function serializeSchemaDefinition(def: SchemaDefinition): SerializedSchema;
23
+ /** @ignore */
24
+ export declare function parseSchemaDefinition(def: SerializedSchema): SchemaDefinition;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.serializeSchemaDefinition = void 0;
3
+ exports.parseSchemaDefinition = exports.serializeSchemaDefinition = void 0;
4
4
  const fieldtypedefinition_1 = require("../core/data/fieldtypedefinition/fieldtypedefinition");
5
+ /** @ignore */
5
6
  function serializeSchemaDefinition(def) {
6
7
  return {
7
8
  'Fields': def.fields.map((field) => ({
@@ -12,3 +13,14 @@ function serializeSchemaDefinition(def) {
12
13
  };
13
14
  }
14
15
  exports.serializeSchemaDefinition = serializeSchemaDefinition;
16
+ /** @ignore */
17
+ function parseSchemaDefinition(def) {
18
+ return {
19
+ fields: def['Fields'].map((field) => ({
20
+ name: field['Name'],
21
+ type: (0, fieldtypedefinition_1.deserializeFieldTypeDefinition)(field['Type']),
22
+ })),
23
+ primaryKey: def['PrimaryKey'],
24
+ };
25
+ }
26
+ exports.parseSchemaDefinition = parseSchemaDefinition;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.findProxyClass = void 0;
4
+ const customblockproxy_1 = require("./customblockproxy");
4
5
  const erdblockproxy_1 = require("./erdblockproxy");
5
- const allProxyClasses = [erdblockproxy_1.ERDBlockProxy];
6
+ const allProxyClasses = [erdblockproxy_1.ERDBlockProxy, customblockproxy_1.CustomBlockProxy];
6
7
  function findProxyClass(className) {
7
8
  return allProxyClasses.find((proxy) => proxy.classNameRegex.test(className));
8
9
  }
@@ -0,0 +1,6 @@
1
+ import { BlockProxy } from '../blockproxy';
2
+ export declare class CustomBlockProxy extends BlockProxy {
3
+ static classNameRegex: RegExp;
4
+ isFromStencil(library: string, shape: string): boolean;
5
+ getStencilTextAreaName(stencilTextAreaName: string): string | undefined;
6
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CustomBlockProxy = void 0;
4
+ const checks_1 = require("../../core/checks");
5
+ const blockproxy_1 = require("../blockproxy");
6
+ class CustomBlockProxy extends blockproxy_1.BlockProxy {
7
+ isFromStencil(library, shape) {
8
+ const stencil = this.properties.get('Stencil');
9
+ if ((0, checks_1.isObject)(stencil)) {
10
+ const sourceStencil = this.client.sendCommand("gp" /* GetProperty */, { 'p': 'Stencil-' + stencil['id'] });
11
+ if ((0, checks_1.isObject)(sourceStencil) && (0, checks_1.isObject)(sourceStencil['sourcePackage'])) {
12
+ return (sourceStencil['sourcePackage']['packageId'] === lucid.getPackageId() &&
13
+ sourceStencil['sourcePackage']['library'] === library &&
14
+ sourceStencil['sourcePackage']['shape'] === shape);
15
+ }
16
+ }
17
+ return false;
18
+ }
19
+ getStencilTextAreaName(stencilTextAreaName) {
20
+ return this.textAreas.keys().find((name) => name.endsWith('_' + stencilTextAreaName));
21
+ }
22
+ }
23
+ exports.CustomBlockProxy = CustomBlockProxy;
24
+ CustomBlockProxy.classNameRegex = /^CustomBlock$/;
@@ -13,12 +13,14 @@ export interface BlockDefinition {
13
13
  */
14
14
  boundingBox: Box;
15
15
  /**
16
- * Additional properties to set on the block immediately after creation
16
+ * Additional properties to set on the block immediately after creation. This is not typically
17
+ * set directly (it's easier and safer to call `.properties.set()` after block creation) but
18
+ * is set by [EditorClient.getCustomShapeDefinition](#classes_editorclient-EditorClient_getcustomshapedefinition).
17
19
  */
18
20
  properties?: JsonObject;
19
21
  /**
20
22
  * If specified, the stencil to use for a custom shape. This is not typically set directly; use
21
- * PageProxy.getCustomShapeDefinition().
23
+ * [EditorClient.getCustomShapeDefinition](#classes_editorclient-EditorClient_getcustomshapedefinition).
22
24
  */
23
25
  stencil?: JsonSerializable;
24
26
  }
@@ -1,18 +1,34 @@
1
1
  import { ItemProxy } from './itemproxy';
2
2
  /**
3
- * A block is a single shape on the document.
3
+ * A block is a single shape on the document. A BlockProxy provides an interface to
4
+ * read and write the content of an existing block, and is typically accessed through
5
+ * [PageProxy.blocks](#classes_document_pageproxy-PageProxy_blocks) or another
6
+ * similar mechanism.
4
7
  */
5
8
  export declare class BlockProxy extends ItemProxy {
6
9
  /**
7
- * @returns the type of block this is
10
+ * @returns The class name of this block. This name is not necessarily human-readable,
11
+ * and will remain consistent over time, e.g. "ProcessBlock"..
8
12
  */
9
13
  getClassName(): string;
10
14
  /**
11
- * @returns The amount this block is rotated around its own center, in radians
15
+ * @returns The amount this block is rotated around its own center, in radians.
12
16
  */
13
17
  getRotation(): number;
14
18
  /**
15
- * @returns an array of lines that have one or both endpoints connected to this block
19
+ * @returns An array of lines that have one or both endpoints connected to this block.
16
20
  */
17
21
  getConnectedLines(): import("./lineproxy").LineProxy[];
22
+ /**
23
+ * Link a text area to a data field, so that editing the text area will also update the
24
+ * associated data, and vice versa.
25
+ *
26
+ * To use this, first establish a reference key on this block with
27
+ * [setReferenceKey](/extension-sdk/#classes_document_blockproxy-BlockProxy_setreferencekey).
28
+ *
29
+ * @param textAreaKey
30
+ * @param referenceKey
31
+ * @param field
32
+ */
33
+ linkText(textAreaKey: string, referenceKey: string | number, field: string): void;
18
34
  }
@@ -3,27 +3,54 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BlockProxy = void 0;
4
4
  const itemproxy_1 = require("./itemproxy");
5
5
  /**
6
- * A block is a single shape on the document.
6
+ * A block is a single shape on the document. A BlockProxy provides an interface to
7
+ * read and write the content of an existing block, and is typically accessed through
8
+ * [PageProxy.blocks](#classes_document_pageproxy-PageProxy_blocks) or another
9
+ * similar mechanism.
7
10
  */
8
11
  class BlockProxy extends itemproxy_1.ItemProxy {
9
12
  /**
10
- * @returns the type of block this is
13
+ * @returns The class name of this block. This name is not necessarily human-readable,
14
+ * and will remain consistent over time, e.g. "ProcessBlock"..
11
15
  */
12
16
  getClassName() {
13
17
  return this.properties.get('ClassName');
14
18
  }
15
19
  /**
16
- * @returns The amount this block is rotated around its own center, in radians
20
+ * @returns The amount this block is rotated around its own center, in radians.
17
21
  */
18
22
  getRotation() {
19
23
  return this.properties.get('Rotation');
20
24
  }
21
25
  /**
22
- * @returns an array of lines that have one or both endpoints connected to this block
26
+ * @returns An array of lines that have one or both endpoints connected to this block.
23
27
  */
24
28
  getConnectedLines() {
25
29
  const ids = this.client.sendCommand("gcl" /* GetConnectedLines */, this.id);
26
30
  return ids.map((id) => this.client.getLineProxy(id));
27
31
  }
32
+ /**
33
+ * Link a text area to a data field, so that editing the text area will also update the
34
+ * associated data, and vice versa.
35
+ *
36
+ * To use this, first establish a reference key on this block with
37
+ * [setReferenceKey](/extension-sdk/#classes_document_blockproxy-BlockProxy_setreferencekey).
38
+ *
39
+ * @param textAreaKey
40
+ * @param referenceKey
41
+ * @param field
42
+ */
43
+ linkText(textAreaKey, referenceKey, field) {
44
+ if (!this.textAreas.keys().includes(textAreaKey)) {
45
+ throw new Error('Invalid text area key');
46
+ }
47
+ if (!this.referenceKeys.keys().includes(referenceKey)) {
48
+ throw new Error('Invalid reference key');
49
+ }
50
+ this.properties.set(textAreaKey + '_Link', {
51
+ 'ref': referenceKey,
52
+ 'f': field,
53
+ });
54
+ }
28
55
  }
29
56
  exports.BlockProxy = BlockProxy;
@@ -1,5 +1,6 @@
1
1
  import { EditorClient } from '../editorclient';
2
2
  import { ElementProxy } from './elementproxy';
3
+ import { ItemProxy } from './itemproxy';
3
4
  import { MapProxy } from './mapproxy';
4
5
  import { PageDefinition } from './pagedefinition';
5
6
  import { PageProxy } from './pageproxy';
@@ -7,6 +8,8 @@ import { PageProxy } from './pageproxy';
7
8
  * The currently-open Lucid document
8
9
  */
9
10
  export declare class DocumentProxy extends ElementProxy {
11
+ private static nextHookId;
12
+ private static getNextHookName;
10
13
  /**
11
14
  * The set of pages on this document, organized by ID
12
15
  */
@@ -15,7 +18,7 @@ export declare class DocumentProxy extends ElementProxy {
15
18
  /**
16
19
  * Add a new page to the current document
17
20
  * @param def Definition of the page to add
18
- * @returns the created page
21
+ * @returns The created page
19
22
  */
20
23
  addPage(def: PageDefinition): PageProxy;
21
24
  /**
@@ -24,7 +27,24 @@ export declare class DocumentProxy extends ElementProxy {
24
27
  */
25
28
  setTitle(title: string): void;
26
29
  /**
27
- * @returns the title of this document
30
+ * @returns The title of this document
28
31
  */
29
32
  getTitle(): string;
33
+ /**
34
+ * Watch for new blocks, lines, or groups added to this document. The callback will
35
+ * be called with new items created by the current user, but will not be called with items
36
+ * created
37
+ *
38
+ * - As part of a generated diagram, e.g. org chart
39
+ * - As a result of undo or redo
40
+ * - By another user on the same document
41
+ *
42
+ * @param callback
43
+ * @returns A handle that can be passed to `unhookCreateItems`
44
+ */
45
+ hookCreateItems(callback: (items: ItemProxy[]) => void): string;
46
+ /**
47
+ * @param handle Return value from `hookCreateItems`
48
+ */
49
+ unhookCreateItems(handle: string): void;
30
50
  }
@@ -15,10 +15,13 @@ class DocumentProxy extends elementproxy_1.ElementProxy {
15
15
  */
16
16
  this.pages = new mapproxy_1.MapProxy(() => this.client.sendCommand("lp" /* ListPages */, undefined), (pageId) => new pageproxy_1.PageProxy(pageId, this.client));
17
17
  }
18
+ static getNextHookName() {
19
+ return '__documentproxy__hook' + DocumentProxy.nextHookId++;
20
+ }
18
21
  /**
19
22
  * Add a new page to the current document
20
23
  * @param def Definition of the page to add
21
- * @returns the created page
24
+ * @returns The created page
22
25
  */
23
26
  addPage(def) {
24
27
  const id = this.client.sendCommand("cp" /* CreatePage */, undefined);
@@ -34,10 +37,38 @@ class DocumentProxy extends elementproxy_1.ElementProxy {
34
37
  this.properties.set('Title', title);
35
38
  }
36
39
  /**
37
- * @returns the title of this document
40
+ * @returns The title of this document
38
41
  */
39
42
  getTitle() {
40
43
  return this.properties.get('Title');
41
44
  }
45
+ /**
46
+ * Watch for new blocks, lines, or groups added to this document. The callback will
47
+ * be called with new items created by the current user, but will not be called with items
48
+ * created
49
+ *
50
+ * - As part of a generated diagram, e.g. org chart
51
+ * - As a result of undo or redo
52
+ * - By another user on the same document
53
+ *
54
+ * @param callback
55
+ * @returns A handle that can be passed to `unhookCreateItems`
56
+ */
57
+ hookCreateItems(callback) {
58
+ const actionName = DocumentProxy.getNextHookName();
59
+ this.client.registerAction(actionName, (msg) => {
60
+ callback(msg['ids'].map((id) => this.client.getItemProxy(id)));
61
+ });
62
+ this.client.sendCommand("hci" /* HookCreateItems */, { 'n': actionName });
63
+ return actionName;
64
+ }
65
+ /**
66
+ * @param handle Return value from `hookCreateItems`
67
+ */
68
+ unhookCreateItems(handle) {
69
+ this.client.deleteAction(handle);
70
+ this.client.sendCommand("uci" /* UnhookCreateItems */, { 'n': handle });
71
+ }
42
72
  }
43
73
  exports.DocumentProxy = DocumentProxy;
74
+ DocumentProxy.nextHookId = 0;
@@ -1,25 +1,18 @@
1
1
  import { ReferenceKeyDefinition } from '../data/referencekeydefinition';
2
2
  import { ReferenceKeyProxy } from '../data/referencekeyproxy';
3
3
  import { EditorClient } from '../editorclient';
4
- import { MapProxy, WriteableMapProxy } from './mapproxy';
4
+ import { MapProxy } from './mapproxy';
5
+ import { PropertyStoreProxy } from './propertystoreproxy';
5
6
  import { ShapeDataProxy } from './shapedataproxy';
6
7
  /**
7
8
  * An element is anything on a Lucid document that can have properties and shape data:
8
- * * The document itself
9
- * * Pages
10
- * * Blocks
11
- * * Lines
12
- * * Groups
9
+ * * [The document itself](#classes_document_documentproxy-DocumentProxy)
10
+ * * [Pages](#classes_document_pageproxy-PageProxy)
11
+ * * [Blocks](#classes_document_blockproxy-BlockProxy)
12
+ * * [Lines](#classes_document_lineproxy-LineProxy)
13
+ * * [Groups](#classes_document_groupproxy-GroupProxy)
13
14
  */
14
- export declare class ElementProxy {
15
- readonly id: string | undefined;
16
- protected readonly client: EditorClient;
17
- /**
18
- * All properties available on this element, organized by name.
19
- * Not all properties are writeable (e.g. "ClassName" on a block).
20
- * To move or resize elements, use setLocation() or setBoundingBox() or offset() instead.
21
- */
22
- readonly properties: WriteableMapProxy<string, import("..").JsonSerializable>;
15
+ export declare class ElementProxy extends PropertyStoreProxy {
23
16
  /**
24
17
  * The shape data set directly on this element (not including any shape data inherited from the page or a containing group).
25
18
  */
@@ -29,23 +22,38 @@ export declare class ElementProxy {
29
22
  * This collection is read-only.
30
23
  */
31
24
  readonly allShapeData: MapProxy<string, import("..").SerializedFieldType | import("..").DataError>;
25
+ /**
26
+ * The set of reference keys, organized by their ID, which can be either a string or number.
27
+ *
28
+ * For more information, see the [Developer Guide](/extension-api#guide-reference-keys).
29
+ */
32
30
  readonly referenceKeys: MapProxy<string | number, ReferenceKeyProxy>;
31
+ /**
32
+ * Set a reference key on this element, replacing any existing reference at the specified key.
33
+ *
34
+ * @param key
35
+ * @param settings
36
+ */
33
37
  setReferenceKey(key: number | string, settings: ReferenceKeyDefinition): void;
38
+ /**
39
+ * Remove the specified reference key from this element.
40
+ * @param key
41
+ */
34
42
  removeReferenceKey(key: number | string): void;
35
43
  /**
36
44
  *
37
- * @param id ID of this element, or undefined for the document itself
45
+ * @param id ID of this element, or `undefined` for the document itself
38
46
  * @param client
39
47
  */
40
48
  constructor(id: string | undefined, client: EditorClient);
41
49
  /**
42
- * @returns true if this element still exists on the document, or false otherwise
50
+ * @returns `true` if this element still exists on the document, or `false` otherwise
43
51
  */
44
52
  exists(): boolean;
45
53
  /**
46
54
  * Execute a formula in the context of this element
47
55
  * @param formula The formula text, e.g. "@a + @b" to add together the shape data values a and b.
48
- * @returns the result of the formula, or an error.
56
+ * @returns The result of the formula, or an error.
49
57
  */
50
58
  executeFormula(formula: string): import("..").SerializedFieldType | import("..").DataError;
51
59
  }