lucid-extension-sdk 0.0.9 → 0.0.16

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 (34) hide show
  1. package/interop.d.ts +2 -0
  2. package/package.json +1 -1
  3. package/sdk/commandtypes.d.ts +153 -5
  4. package/sdk/commandtypes.js +6 -0
  5. package/sdk/core/base64.d.ts +1 -0
  6. package/sdk/core/base64.js +45 -0
  7. package/sdk/core/data/referencekeys/serializedreferencekey.d.ts +6 -0
  8. package/sdk/core/data/referencekeys/serializedreferencekey.js +17 -1
  9. package/sdk/data/datasourceproxy.js +3 -1
  10. package/sdk/data/referencekeydefinition.d.ts +3 -1
  11. package/sdk/data/referencekeydefinition.js +24 -1
  12. package/sdk/data/referencekeyproxy.d.ts +4 -0
  13. package/sdk/data/referencekeyproxy.js +25 -0
  14. package/sdk/data/schemadefinition.d.ts +2 -0
  15. package/sdk/data/schemadefinition.js +20 -5
  16. package/sdk/document/blockclasses/blockproxyregistry.js +2 -1
  17. package/sdk/document/blockclasses/customblockproxy.d.ts +6 -0
  18. package/sdk/document/blockclasses/customblockproxy.js +24 -0
  19. package/sdk/document/blockproxy.d.ts +12 -0
  20. package/sdk/document/blockproxy.js +23 -0
  21. package/sdk/document/documentproxy.d.ts +20 -0
  22. package/sdk/document/documentproxy.js +31 -0
  23. package/sdk/document/lineproxy.d.ts +26 -0
  24. package/sdk/document/lineproxy.js +46 -0
  25. package/sdk/document/linetextareapositioning.d.ts +31 -0
  26. package/sdk/document/linetextareapositioning.js +30 -0
  27. package/sdk/document/mapproxy.d.ts +2 -1
  28. package/sdk/document/mapproxy.js +3 -0
  29. package/sdk/editorclient.d.ts +52 -0
  30. package/sdk/editorclient.js +97 -13
  31. package/sdk/ui/menu.d.ts +19 -2
  32. package/sdk/ui/menu.js +11 -2
  33. package/sdk/ui/viewport.d.ts +45 -0
  34. package/sdk/ui/viewport.js +80 -0
package/interop.d.ts CHANGED
@@ -2,6 +2,8 @@
2
2
  declare namespace lucid {
3
3
  export function executeCommand(name: string, params: any): any;
4
4
  export function listen(msg: any): void;
5
+ export function getPackageId(): string;
6
+ export function getVersion(): string;
5
7
  }
6
8
 
7
9
  /** @ignore */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucid-extension-sdk",
3
- "version": "0.0.9",
3
+ "version": "0.0.16",
4
4
  "description": "Utility classes for writing Lucid Software editor extensions",
5
5
  "main": "sdk/index.js",
6
6
  "types": "sdk/index.d.ts",
@@ -5,6 +5,7 @@ import { JsonObject, JsonSerializable } from './core/jsonserializable';
5
5
  import { LinearOffsetType } from './core/offsettype';
6
6
  import { SerializedDataError } from './core/serializeddataerror';
7
7
  import { ShapeDataInheritance } from './core/shapedatainheritance';
8
+ import { SerializedLineTextAreaPositioning } from './document/linetextareapositioning';
8
9
  import { Box, Point } from './math';
9
10
  import { MenuLocation, MenuType } from './ui/menu';
10
11
  import { PanelLocation } from './ui/panel';
@@ -16,15 +17,19 @@ import { PanelLocation } from './ui/panel';
16
17
  * To use these directly, use [EditorClient.sendCommand](#classes_editorclient-EditorClient_sendcommand).
17
18
  */
18
19
  export declare const enum CommandName {
20
+ AddLineTextArea = "alta",
19
21
  AddMenuItem = "ami",
20
22
  AddShapeData = "asd",
23
+ Alert = "a",
21
24
  AnimateViewport = "av",
22
25
  Bootstrap = "b",
26
+ Confirm = "c",
23
27
  CreateBlock = "cb",
24
28
  CreateCollection = "cc",
25
29
  CreateDataSource = "cds",
26
30
  CreateLine = "cl",
27
31
  CreatePage = "cp",
32
+ DataAction = "da",
28
33
  DeleteItem = "di",
29
34
  DeletePage = "dp",
30
35
  DeleteShapeData = "dsd",
@@ -44,6 +49,9 @@ export declare const enum CommandName {
44
49
  GetShapeData = "gsd",
45
50
  HideModal = "hm",
46
51
  HidePanel = "hp",
52
+ HookCreateItems = "hci",
53
+ HookSelection = "hs",
54
+ HookTextEdit = "hte",
47
55
  KillExtension = "k",
48
56
  ListBlocks = "lb",
49
57
  ListCollectionFields = "lcf",
@@ -72,7 +80,10 @@ export declare const enum CommandName {
72
80
  SetShapeData = "ssd",
73
81
  ShowModal = "sm",
74
82
  ShowPanel = "spn",
75
- SleepForTestCase = "sleep"
83
+ SleepForTestCase = "sleep",
84
+ UnhookCreateItems = "uci",
85
+ UnhookSelection = "us",
86
+ UnhookTextEdit = "ute"
76
87
  }
77
88
  /**
78
89
  * This is a type declaration whose purpose is to allow TypeScript to enforce the correct parameter and
@@ -80,9 +91,9 @@ export declare const enum CommandName {
80
91
  * which command name you pass in as the first parameter.
81
92
  */
82
93
  export declare type CommandArgs = {
83
- [CommandName.AnimateViewport]: {
84
- query: AnimateViewportQuery;
85
- result: AnimateViewportResult;
94
+ [CommandName.AddLineTextArea]: {
95
+ query: AddLineTextAreaQuery;
96
+ result: AddLineTextAreaResult;
86
97
  };
87
98
  [CommandName.AddMenuItem]: {
88
99
  query: AddMenuItemQuery;
@@ -92,10 +103,22 @@ export declare type CommandArgs = {
92
103
  query: AddShapeDataQuery;
93
104
  result: AddShapeDataResult;
94
105
  };
106
+ [CommandName.Alert]: {
107
+ query: AlertQuery;
108
+ result: AlertResult;
109
+ };
110
+ [CommandName.AnimateViewport]: {
111
+ query: AnimateViewportQuery;
112
+ result: AnimateViewportResult;
113
+ };
95
114
  [CommandName.Bootstrap]: {
96
115
  query: BootstrapQuery;
97
116
  result: BootstrapResult;
98
117
  };
118
+ [CommandName.Confirm]: {
119
+ query: ConfirmQuery;
120
+ result: ConfirmResult;
121
+ };
99
122
  [CommandName.CreateBlock]: {
100
123
  query: CreateBlockQuery;
101
124
  result: CreateBlockResult;
@@ -116,6 +139,10 @@ export declare type CommandArgs = {
116
139
  query: CreatePageQuery;
117
140
  result: CreatePageResult;
118
141
  };
142
+ [CommandName.DataAction]: {
143
+ query: DataActionQuery;
144
+ result: DataActionResult;
145
+ };
119
146
  [CommandName.DeleteItem]: {
120
147
  query: DeleteItemQuery;
121
148
  result: DeleteItemResult;
@@ -192,6 +219,18 @@ export declare type CommandArgs = {
192
219
  query: HidePanelQuery;
193
220
  result: HidePanelResult;
194
221
  };
222
+ [CommandName.HookCreateItems]: {
223
+ query: HookCreateItemsQuery;
224
+ result: HookCreateItemsResult;
225
+ };
226
+ [CommandName.HookSelection]: {
227
+ query: HookSelectionQuery;
228
+ result: HookSelectionResult;
229
+ };
230
+ [CommandName.HookTextEdit]: {
231
+ query: HookTextEditQuery;
232
+ result: HookTextEditResult;
233
+ };
195
234
  [CommandName.KillExtension]: {
196
235
  query: KillExtensionQuery;
197
236
  result: KillExtensionResult;
@@ -308,14 +347,36 @@ export declare type CommandArgs = {
308
347
  query: SleepForTestCaseQuery;
309
348
  result: SleepForTestCaseResult;
310
349
  };
350
+ [CommandName.UnhookCreateItems]: {
351
+ query: UnhookCreateItemsQuery;
352
+ result: UnhookCreateItemsResult;
353
+ };
354
+ [CommandName.UnhookSelection]: {
355
+ query: UnhookSelectionQuery;
356
+ result: UnhookSelectionResult;
357
+ };
358
+ [CommandName.UnhookTextEdit]: {
359
+ query: UnhookTextEditQuery;
360
+ result: UnhookTextEditResult;
361
+ };
362
+ };
363
+ export declare type AddLineTextAreaQuery = {
364
+ /** Which line */
365
+ 'id': string;
366
+ /** Where to place the text along the line */
367
+ 'p': SerializedLineTextAreaPositioning;
368
+ /** Plain text to put at this location (will be styled with document theme) */
369
+ 't': string;
311
370
  };
371
+ /** The name of the created text area */
372
+ export declare type AddLineTextAreaResult = string;
312
373
  /** @ignore */
313
374
  export declare type UnionToIntersection<T> = (T extends any ? (x: T) => unknown : never) extends (x: infer R) => unknown ? R : never;
314
375
  export declare type AddMenuItemQuery = {
315
376
  /** Label to display on the menu item */
316
377
  'l': string;
317
378
  /** Named action to run when the menu item is clicked */
318
- 'a': string;
379
+ 'a'?: string;
319
380
  /** Named action that returns whether the menu item should be visible */
320
381
  'v'?: string;
321
382
  /** Named action that returns whether the menu item should be disabled */
@@ -324,6 +385,17 @@ export declare type AddMenuItemQuery = {
324
385
  't': MenuType;
325
386
  /** If specified, where to place the menu item; defaults to MenuLocation.Extension */
326
387
  'loc'?: MenuLocation;
388
+ /** If specified, this menu item should launch a file picker */
389
+ 'f'?: {
390
+ /** Action to call when files are selected */
391
+ 'a': string;
392
+ /** File types to accept */
393
+ 'ac': string;
394
+ /** Single file only */
395
+ 's'?: boolean;
396
+ /** Return content in a binary ArrayBuffer instead of as text */
397
+ 'b'?: boolean;
398
+ };
327
399
  };
328
400
  export declare type AddMenuItemResult = undefined;
329
401
  export declare type AddShapeDataQuery = {
@@ -337,6 +409,16 @@ export declare type AddShapeDataQuery = {
337
409
  'v'?: SerializedFieldType;
338
410
  };
339
411
  export declare type AddShapeDataResult = undefined;
412
+ export declare type AlertQuery = {
413
+ /** Title; defaults to extension title */
414
+ 't'?: string;
415
+ /** Body text */
416
+ 'b': string;
417
+ /** Button text; defaults to i18n'ed "OK" */
418
+ 'bt'?: string;
419
+ };
420
+ /** True if they click OK, false otherwise */
421
+ export declare type AlertResult = Promise<boolean>;
340
422
  export declare type BootstrapQuery = {
341
423
  /**
342
424
  * Named action that accepts the bootstrap data, and which may return a Promise or void. After awaiting\
@@ -345,6 +427,18 @@ export declare type BootstrapQuery = {
345
427
  'c': string;
346
428
  };
347
429
  export declare type BootstrapResult = Promise<void>;
430
+ export declare type ConfirmQuery = {
431
+ /** Title; defaults to extension title */
432
+ 't'?: string;
433
+ /** Body text */
434
+ 'b': string;
435
+ /** OK button text; defaults to i18n'ed "OK" */
436
+ 'o'?: string;
437
+ /** Cancel button text; defaults to i18n'ed "Cancel" */
438
+ 'c'?: string;
439
+ };
440
+ /** True if they click OK, false otherwise */
441
+ export declare type ConfirmResult = Promise<boolean>;
348
442
  export declare type CreateBlockQuery = {
349
443
  /**
350
444
  * By default, we add the block to the current page & currently active group. If specified, the
@@ -393,6 +487,29 @@ export declare type CreateLineQuery = {
393
487
  export declare type CreateLineResult = string;
394
488
  export declare type CreatePageQuery = void;
395
489
  export declare type CreatePageResult = string;
490
+ export declare type DataActionQuery = {
491
+ /** Flow Name */
492
+ 'fn': string;
493
+ /** Is Async */
494
+ 'a': boolean;
495
+ /** Flow Data */
496
+ 'fd'?: unknown;
497
+ /** Sync data source ID */
498
+ 's': string;
499
+ /** Data Connector Name */
500
+ 'n': string;
501
+ };
502
+ export declare type RawDataActionResult = {
503
+ /** The external service responded with this code */
504
+ 'c': number;
505
+ } & ({
506
+ /** And this text */
507
+ 't': string;
508
+ } | {
509
+ /** Or this JSON */
510
+ 'j': unknown;
511
+ });
512
+ export declare type DataActionResult = Promise<RawDataActionResult>;
396
513
  export declare type DeleteItemQuery = string;
397
514
  export declare type DeleteItemResult = boolean;
398
515
  export declare type DeletePageQuery = string;
@@ -509,6 +626,21 @@ export declare type HidePanelQuery = {
509
626
  'n': string;
510
627
  };
511
628
  export declare type HidePanelResult = undefined;
629
+ export declare type HookCreateItemsQuery = {
630
+ /** Name of the action for receiving events. Will be called with an array of strings of all recently created item IDs. */
631
+ 'n': string;
632
+ };
633
+ export declare type HookCreateItemsResult = undefined;
634
+ export declare type HookSelectionQuery = {
635
+ /** Name of the action for receiving events. Will be called with an array of strings of all selected item IDs. */
636
+ 'n': string;
637
+ };
638
+ export declare type HookSelectionResult = undefined;
639
+ export declare type HookTextEditQuery = {
640
+ /** Name of the action for receiving these events */
641
+ 'n': string;
642
+ };
643
+ export declare type HookTextEditResult = undefined;
512
644
  export declare type KillExtensionQuery = void;
513
645
  export declare type KillExtensionResult = undefined;
514
646
  export declare type ListChildrenQuery = {
@@ -641,6 +773,7 @@ export declare type RawSendXHRResponse = {
641
773
  'to'?: boolean;
642
774
  };
643
775
  export declare type SendXHRResponse = Promise<RawSendXHRResponse>;
776
+ export declare function isRawSendXHRResponse(val: any): val is RawSendXHRResponse;
644
777
  export declare type SetCurrentPageQuery = string;
645
778
  export declare type SetCurrentPageResult = Promise<void>;
646
779
  export declare type SetPropertyQuery = {
@@ -690,3 +823,18 @@ export declare type ShowPanelQuery = {
690
823
  export declare type ShowPanelResult = undefined;
691
824
  export declare type SleepForTestCaseQuery = number;
692
825
  export declare type SleepForTestCaseResult = Promise<void>;
826
+ export declare type UnhookCreateItemsQuery = {
827
+ /** Name of the action passed to HookCreateItems */
828
+ 'n': string;
829
+ };
830
+ export declare type UnhookCreateItemsResult = undefined;
831
+ export declare type UnhookSelectionQuery = {
832
+ /** Name of the action for receiving these events */
833
+ 'n': string;
834
+ };
835
+ export declare type UnhookSelectionResult = undefined;
836
+ export declare type UnhookTextEditQuery = {
837
+ /** Name of the action for receiving these events */
838
+ 'n': string;
839
+ };
840
+ export declare type UnhookTextEditResult = undefined;
@@ -1,2 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isRawSendXHRResponse = void 0;
4
+ const checks_1 = require("./core/checks");
5
+ function isRawSendXHRResponse(val) {
6
+ return (0, checks_1.isString)(val['url']) && (0, checks_1.isString)(val['t']) && (0, checks_1.isNumber)(val['s']) && (0, checks_1.isObject)(val['h']);
7
+ }
8
+ exports.isRawSendXHRResponse = isRawSendXHRResponse;
@@ -0,0 +1 @@
1
+ export declare function decodeBase64(base64String: string): Uint8Array;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeBase64 = void 0;
4
+ const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
5
+ //This gives a ~8x speedup vs. using alphabet.indexOf() in the main decode loop.
6
+ const charCodeToEncodedInt = [];
7
+ for (let i = 0; i < alphabet.length; i++) {
8
+ charCodeToEncodedInt[alphabet.charCodeAt(i)] = i;
9
+ }
10
+ function decodeBase64(base64String) {
11
+ //Filter out whitespace, etc
12
+ base64String = base64String.replace(/[^A-Za-z0-9\+\/\=]/g, '');
13
+ if (base64String.length % 4 !== 0) {
14
+ throw new Error('Invalid base64 input; length must be a multiple of 4');
15
+ }
16
+ //4 characters of input turns into 3 bytes of output
17
+ let bytes = (base64String.length / 4) * 3;
18
+ //But each trailing = (up to 2) is one fewer byte of output
19
+ if (base64String.endsWith('==')) {
20
+ bytes -= 2;
21
+ }
22
+ else if (base64String.endsWith('=')) {
23
+ bytes -= 1;
24
+ }
25
+ const output = new Uint8Array(bytes);
26
+ let inputIndex = 0;
27
+ for (let outputIndex = 0; outputIndex < bytes; outputIndex += 3) {
28
+ //Get the 4 numbers 0-63 encoded in the next 4 characters
29
+ const enc1 = charCodeToEncodedInt[base64String.charCodeAt(inputIndex++)];
30
+ const enc2 = charCodeToEncodedInt[base64String.charCodeAt(inputIndex++)];
31
+ const enc3 = charCodeToEncodedInt[base64String.charCodeAt(inputIndex++)];
32
+ const enc4 = charCodeToEncodedInt[base64String.charCodeAt(inputIndex++)];
33
+ //Read 8 total bits into each of the output values. Skip one byte
34
+ //for each padding = at the end of the string
35
+ output[outputIndex] = (enc1 << 2) | (enc2 >> 4);
36
+ if (enc3 != 64) {
37
+ output[outputIndex + 1] = ((enc2 & 15) << 4) | (enc3 >> 2);
38
+ }
39
+ if (enc4 != 64) {
40
+ output[outputIndex + 2] = ((enc3 & 3) << 6) | enc4;
41
+ }
42
+ }
43
+ return output;
44
+ }
45
+ exports.decodeBase64 = decodeBase64;
@@ -22,3 +22,9 @@ export declare type UnTypedSerializedFlattenedReference = {
22
22
  };
23
23
  export declare type SerializedFlattenedReference = TypedSerializedFlattenedReference | UnTypedSerializedFlattenedReference;
24
24
  export declare type SerializedReferenceKeyType = SerializedReferenceKey | SerializedFlattenedReference;
25
+ /** @ignore */
26
+ export declare function isTypedSerializedFlattenedReference(data: unknown): data is TypedSerializedFlattenedReference;
27
+ /** @ignore */
28
+ export declare function isUnTypedSerializedFlattenedReference(data: unknown): data is UnTypedSerializedFlattenedReference;
29
+ /** @ignore */
30
+ export declare function isSerializedFlattenedReference(data: unknown): data is SerializedFlattenedReference;
@@ -1,5 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FlattenedReferenceKeyName = exports.FlattenedReferenceKeyId = void 0;
3
+ exports.isSerializedFlattenedReference = exports.isUnTypedSerializedFlattenedReference = exports.isTypedSerializedFlattenedReference = exports.FlattenedReferenceKeyName = exports.FlattenedReferenceKeyId = void 0;
4
+ const checks_1 = require("../../checks");
4
5
  exports.FlattenedReferenceKeyId = '192d0e9f-2f5a-4032-9f03-59bbf1ea5891';
5
6
  exports.FlattenedReferenceKeyName = '192d0e9f-2f5a-4032-9f03-59bbf1ea5891_n';
7
+ /** @ignore */
8
+ function isTypedSerializedFlattenedReference(data) {
9
+ return (0, checks_1.isObject)(data) && (0, checks_1.isObject)(data['sc']) && (0, checks_1.isObject)(data['d']);
10
+ }
11
+ exports.isTypedSerializedFlattenedReference = isTypedSerializedFlattenedReference;
12
+ /** @ignore */
13
+ function isUnTypedSerializedFlattenedReference(data) {
14
+ return (0, checks_1.isObject)(data) && data[exports.FlattenedReferenceKeyId] === true;
15
+ }
16
+ exports.isUnTypedSerializedFlattenedReference = isUnTypedSerializedFlattenedReference;
17
+ /** @ignore */
18
+ function isSerializedFlattenedReference(data) {
19
+ return isUnTypedSerializedFlattenedReference(data) || isTypedSerializedFlattenedReference(data);
20
+ }
21
+ exports.isSerializedFlattenedReference = isSerializedFlattenedReference;
@@ -35,7 +35,9 @@ class DataSourceProxy extends propertystoreproxy_1.PropertyStoreProxy {
35
35
  return new collectionproxy_1.CollectionProxy(this.client.sendCommand("cc" /* CreateCollection */, {
36
36
  's': this.id,
37
37
  'n': name,
38
- 'f': schema.fields.map((field) => ({ 'n': field.name, 't': (0, fieldtypedefinition_1.serializeFieldTypeDefinition)(field.type) })),
38
+ 'f': schema.fields.map((field) => {
39
+ return { 'n': field.name, 't': (0, fieldtypedefinition_1.serializeFieldTypeDefinition)(field.type) };
40
+ }),
39
41
  'p': schema.primaryKey,
40
42
  }), this.client);
41
43
  }
@@ -30,7 +30,7 @@ export interface CollectionReferenceKeyDefinition {
30
30
  */
31
31
  export interface FlattenedReferenceDefinition {
32
32
  /** Name to display to the user for the reference key (what would normally be the collection name) */
33
- name: string;
33
+ name?: string;
34
34
  /** Schema of the data stored at this key */
35
35
  schema: SchemaDefinition;
36
36
  /** Field values available at this reference key */
@@ -41,3 +41,5 @@ export declare type ReferenceKeyDefinition = CollectionReferenceKeyDefinition |
41
41
  export declare function isCollectionReferenceKeyDefinition(def: ReferenceKeyDefinition): def is CollectionReferenceKeyDefinition;
42
42
  /** @ignore */
43
43
  export declare function serializeReferenceKeyDefinition(def: ReferenceKeyDefinition): SerializedReferenceKeyType;
44
+ /** @ignore */
45
+ export declare function parseReferenceKeyDefinition(def: SerializedReferenceKeyType): ReferenceKeyDefinition;
@@ -1,7 +1,8 @@
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");
6
7
  /** @ignore */
7
8
  function isCollectionReferenceKeyDefinition(def) {
@@ -27,3 +28,25 @@ function serializeReferenceKeyDefinition(def) {
27
28
  }
28
29
  }
29
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;
@@ -20,3 +20,5 @@ export interface SchemaDefinition {
20
20
  }
21
21
  /** @ignore */
22
22
  export declare function serializeSchemaDefinition(def: SchemaDefinition): SerializedSchema;
23
+ /** @ignore */
24
+ export declare function parseSchemaDefinition(def: SerializedSchema): SchemaDefinition;
@@ -1,15 +1,30 @@
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
5
  /** @ignore */
6
6
  function serializeSchemaDefinition(def) {
7
7
  return {
8
- 'Fields': def.fields.map((field) => ({
9
- 'Name': field.name,
10
- 'Type': (0, fieldtypedefinition_1.serializeFieldTypeDefinition)(field.type),
11
- })),
8
+ 'Fields': def.fields.map((field) => {
9
+ return {
10
+ 'Name': field.name,
11
+ 'Type': (0, fieldtypedefinition_1.serializeFieldTypeDefinition)(field.type),
12
+ };
13
+ }),
12
14
  'PrimaryKey': def.primaryKey,
13
15
  };
14
16
  }
15
17
  exports.serializeSchemaDefinition = serializeSchemaDefinition;
18
+ /** @ignore */
19
+ function parseSchemaDefinition(def) {
20
+ return {
21
+ fields: def['Fields'].map((field) => {
22
+ return {
23
+ name: field['Name'],
24
+ type: (0, fieldtypedefinition_1.deserializeFieldTypeDefinition)(field['Type']),
25
+ };
26
+ }),
27
+ primaryKey: def['PrimaryKey'],
28
+ };
29
+ }
30
+ 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$/;
@@ -19,4 +19,16 @@ export declare class BlockProxy extends ItemProxy {
19
19
  * @returns An array of lines that have one or both endpoints connected to this block.
20
20
  */
21
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;
22
34
  }
@@ -29,5 +29,28 @@ class BlockProxy extends itemproxy_1.ItemProxy {
29
29
  const ids = this.client.sendCommand("gcl" /* GetConnectedLines */, this.id);
30
30
  return ids.map((id) => this.client.getLineProxy(id));
31
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
+ }
32
55
  }
33
56
  exports.BlockProxy = BlockProxy;