lucid-extension-sdk 0.0.119 → 0.0.121

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucid-extension-sdk",
3
- "version": "0.0.119",
3
+ "version": "0.0.121",
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,6 +8,7 @@ import { SerializedDataError } from './core/serializeddataerror';
8
8
  import { ShapeDataInheritance } from './core/shapedatainheritance';
9
9
  import { DocumentElementType } from './document/documentelement/documentelementtype';
10
10
  import { SerializedLineTextAreaPositioning } from './document/linetextareapositioning';
11
+ import { TextStyle } from './document/text/textstyle';
11
12
  import { Box, Point } from './math';
12
13
  import { MenuLocation, MenuType } from './ui/menu';
13
14
  import { PanelLocation } from './ui/panel';
@@ -59,6 +60,7 @@ export declare const enum CommandName {
59
60
  GetRelativeLinePosition = "grlp",
60
61
  GetSelection = "gs",
61
62
  GetShapeData = "gsd",
63
+ GetTextStyle = "gts",
62
64
  HideModal = "hm",
63
65
  HidePanel = "hp",
64
66
  HookCreateItems = "hci",
@@ -96,6 +98,7 @@ export declare const enum CommandName {
96
98
  SetReferenceKey = "srk",
97
99
  SetShapeData = "ssd",
98
100
  SetText = "st",
101
+ SetTextStyle = "sts",
99
102
  ShowModal = "sm",
100
103
  ShowPanel = "spn",
101
104
  ShowPackageSettingsModal = "spsm",
@@ -277,6 +280,10 @@ export declare type CommandArgs = {
277
280
  query: GetShapeDataQuery;
278
281
  result: GetShapeDataResult;
279
282
  };
283
+ [CommandName.GetTextStyle]: {
284
+ query: GetTextStyleQuery;
285
+ result: GetTextStyleResult;
286
+ };
280
287
  [CommandName.HideModal]: {
281
288
  query: HideModalQuery;
282
289
  result: HideModalResult;
@@ -425,6 +432,10 @@ export declare type CommandArgs = {
425
432
  query: SetTextQuery;
426
433
  result: SetTextResult;
427
434
  };
435
+ [CommandName.SetTextStyle]: {
436
+ query: SetTextStyleQuery;
437
+ result: SetTextStyleResult;
438
+ };
428
439
  [CommandName.ShowModal]: {
429
440
  query: ShowModalQuery;
430
441
  result: ShowModalResult;
@@ -827,6 +838,13 @@ export declare type GetShapeDataQuery = {
827
838
  'n': string;
828
839
  };
829
840
  export declare type GetShapeDataResult = SerializedFieldType | SerializedDataError;
841
+ export declare type GetTextStyleQuery = {
842
+ /** ID of the element to get text style from */
843
+ 'id': string;
844
+ /** Name of the text area to get text style from */
845
+ 'n': string;
846
+ };
847
+ export declare type GetTextStyleResult = TextStyle;
830
848
  export declare type HideModalQuery = {
831
849
  /** Name of the modal's action for receiving events, i.e. ShowModalQuery['n'] */
832
850
  'n': string;
@@ -1063,6 +1081,15 @@ export declare type SetTextQuery = {
1063
1081
  'f'?: boolean | undefined;
1064
1082
  };
1065
1083
  export declare type SetTextResult = undefined;
1084
+ export declare type SetTextStyleQuery = {
1085
+ /** ID of the element to set text style on */
1086
+ 'id': string;
1087
+ /** Name of the text area to set text style on */
1088
+ 'n': string;
1089
+ /** Text styles to set */
1090
+ 's': Partial<TextStyle>;
1091
+ };
1092
+ export declare type SetTextStyleResult = Promise<undefined>;
1066
1093
  export declare type ShowModalQuery = {
1067
1094
  /** Name of the modal's action for receiving events; generated automatically by Modal base class */
1068
1095
  'n': string;
@@ -42,6 +42,7 @@ exports.commandTitles = new Map([
42
42
  ["grlp" /* CommandName.GetRelativeLinePosition */, 'GetRelativeLinePosition'],
43
43
  ["gs" /* CommandName.GetSelection */, 'GetSelection'],
44
44
  ["gsd" /* CommandName.GetShapeData */, 'GetShapeData'],
45
+ ["gts" /* CommandName.GetTextStyle */, 'GetTextStyle'],
45
46
  ["hm" /* CommandName.HideModal */, 'HideModal'],
46
47
  ["hp" /* CommandName.HidePanel */, 'HidePanel'],
47
48
  ["hci" /* CommandName.HookCreateItems */, 'HookCreateItems'],
@@ -77,6 +78,7 @@ exports.commandTitles = new Map([
77
78
  ["sp" /* CommandName.SetProperty */, 'SetProperty'],
78
79
  ["srk" /* CommandName.SetReferenceKey */, 'SetReferenceKey'],
79
80
  ["ssd" /* CommandName.SetShapeData */, 'SetShapeData'],
81
+ ["sts" /* CommandName.SetTextStyle */, 'SetTextStyle'],
80
82
  ["sm" /* CommandName.ShowModal */, 'ShowModal'],
81
83
  ["spsm" /* CommandName.ShowPackageSettingsModal */, 'ShowPackageSettingsModal'],
82
84
  ["spn" /* CommandName.ShowPanel */, 'ShowPanel'],
@@ -69,6 +69,14 @@ export declare function mapValidator<T>(subValidator: (p1: unknown) => p1 is T):
69
69
  export declare function objectValidator<T extends {
70
70
  [key: string]: (p1: unknown) => p1 is unknown;
71
71
  }>(validatorStructure: T): (subject: unknown) => subject is DestructureGuardedTypeObj<T>;
72
+ /**
73
+ * Creates a validator which tests if the target is an object
74
+ * and if the structure of the object matches the structure of the passed-in
75
+ * validator object, but with every entry being optional.
76
+ */
77
+ export declare function partialObjectValidator<T extends {
78
+ [key: string]: (p1: unknown) => p1 is unknown;
79
+ }>(validatorStructure: T): (subject: unknown) => subject is Partial<DestructureGuardedTypeObj<T>>;
72
80
  /**
73
81
  * Similar to {@link objectValidator}, but if the object has any non-undefined keys, they must also be present in the validator structure.
74
82
  * This is useful for things where extra data is unwanted, like Property serialization.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.asAssertion = exports.validatorWithMessage = exports.minLengthValidator = exports.maxLengthValidator = exports.isDate = exports.isPositiveNumber = exports.isSize = exports.isPanelSize = exports.isBoundingBox = exports.isPointLike = exports.isOpacity = exports.isTrue = exports.isFlag = exports.isRestrictions = exports.isStringOrNegativeOne = exports.isBooleanOrEmptyString = exports.isNumberOrEmptyString = exports.isSet = exports.propertyValidator = exports.exclude = exports.both = exports.either = exports.isNullOption = exports.nullableOption = exports.option = exports.nullable = exports.objectOfValidator = exports.recordValidator = exports.strictObjectValidator = exports.objectValidator = exports.mapValidator = exports.someValidator = exports.someValue = exports.tupleValidator = exports.arrayValidator = exports.rangeValidator = exports.enumValidator = exports.stringEnumValidator = void 0;
3
+ exports.asAssertion = exports.validatorWithMessage = exports.minLengthValidator = exports.maxLengthValidator = exports.isDate = exports.isPositiveNumber = exports.isSize = exports.isPanelSize = exports.isBoundingBox = exports.isPointLike = exports.isOpacity = exports.isTrue = exports.isFlag = exports.isRestrictions = exports.isStringOrNegativeOne = exports.isBooleanOrEmptyString = exports.isNumberOrEmptyString = exports.isSet = exports.propertyValidator = exports.exclude = exports.both = exports.either = exports.isNullOption = exports.nullableOption = exports.option = exports.nullable = exports.objectOfValidator = exports.recordValidator = exports.strictObjectValidator = exports.partialObjectValidator = exports.objectValidator = exports.mapValidator = exports.someValidator = exports.someValue = exports.tupleValidator = exports.arrayValidator = exports.rangeValidator = exports.enumValidator = exports.stringEnumValidator = void 0;
4
4
  const checks_1 = require("../checks");
5
5
  const object_1 = require("../object");
6
6
  /*********************************************************************************
@@ -145,6 +145,24 @@ function objectValidator(validatorStructure) {
145
145
  };
146
146
  }
147
147
  exports.objectValidator = objectValidator;
148
+ /**
149
+ * Creates a validator which tests if the target is an object
150
+ * and if the structure of the object matches the structure of the passed-in
151
+ * validator object, but with every entry being optional.
152
+ */
153
+ function partialObjectValidator(validatorStructure) {
154
+ return (subject) => {
155
+ if ((0, checks_1.isArray)(subject) || !(0, checks_1.isObject)(subject)) {
156
+ return false;
157
+ }
158
+ else {
159
+ return (0, object_1.objectEvery)(validatorStructure, (validator, key) => {
160
+ return subject[key] === undefined || validator(subject[key]);
161
+ });
162
+ }
163
+ };
164
+ }
165
+ exports.partialObjectValidator = partialObjectValidator;
148
166
  /**
149
167
  * Similar to {@link objectValidator}, but if the object has any non-undefined keys, they must also be present in the validator structure.
150
168
  * This is useful for things where extra data is unwanted, like Property serialization.
@@ -27,8 +27,8 @@ export declare type SerializedPatchChange = {
27
27
  'collections': {
28
28
  'collectionId': string;
29
29
  'itemsPatch': {
30
- 'items'?: Record<string, object>;
31
- 'itemsDeleted'?: string[];
30
+ 'items': Record<string, object>;
31
+ 'itemsDeleted': string[];
32
32
  };
33
33
  }[];
34
34
  };
@@ -33,11 +33,12 @@ function serializePatchResponse(patchChange) {
33
33
  return {
34
34
  'syncId': patchChange.syncId,
35
35
  'collections': patchChange.collections.map((c) => {
36
+ var _a, _b;
36
37
  return {
37
38
  'collectionId': c.collectionId,
38
39
  'itemsPatch': {
39
- 'items': c.items,
40
- 'itemsDeleted': c.itemsDeleted,
40
+ 'items': (_a = c.items) !== null && _a !== void 0 ? _a : {},
41
+ 'itemsDeleted': (_b = c.itemsDeleted) !== null && _b !== void 0 ? _b : [],
41
42
  },
42
43
  };
43
44
  }),
@@ -3,6 +3,7 @@ import { EditorClient } from '../editorclient';
3
3
  import { Box, Point } from '../math';
4
4
  import { ElementProxy } from './elementproxy';
5
5
  import { WriteableMapProxy } from './mapproxy';
6
+ import { TextStyle } from './text/textstyle';
6
7
  /**
7
8
  * A block, line, or group on a page of the current document.
8
9
  */
@@ -16,7 +17,11 @@ export declare class ItemProxy extends ElementProxy {
16
17
  /**
17
18
  * The plain text in each of the text areas on this item, organized by text area name.
18
19
  */
19
- readonly textAreas: WriteableMapProxy<string, string>;
20
+ readonly textAreas: WriteableMapProxy<string, string, undefined, string>;
21
+ /**
22
+ * The text style in each of the text areas on this item, organized by text area name.
23
+ */
24
+ readonly textStyles: WriteableMapProxy<string, TextStyle, Promise<undefined>, Partial<TextStyle>>;
20
25
  /**
21
26
  * @returns The bounding box of this item relative to its containing page. As pages may change size
22
27
  * to fit the content on them, note that these coordinates may be negative or very large.
@@ -27,6 +27,17 @@ class ItemProxy extends elementproxy_1.ElementProxy {
27
27
  't': plainText,
28
28
  'f': options === null || options === void 0 ? void 0 : options.force,
29
29
  }));
30
+ /**
31
+ * The text style in each of the text areas on this item, organized by text area name.
32
+ */
33
+ this.textStyles = new mapproxy_1.WriteableMapProxy(() => this.textAreas.keys(), (name) => this.client.sendCommand("gts" /* CommandName.GetTextStyle */, {
34
+ 'id': this.id,
35
+ 'n': name,
36
+ }), (name, style) => this.client.sendCommand("sts" /* CommandName.SetTextStyle */, {
37
+ 'id': this.id,
38
+ 'n': name,
39
+ 's': style,
40
+ }));
30
41
  }
31
42
  /**
32
43
  * @returns The bounding box of this item relative to its containing page. As pages may change size
@@ -15,10 +15,10 @@ export declare class MapProxy<KEY, VALUE> {
15
15
  get(key: KEY): VALUE;
16
16
  first(): VALUE | undefined;
17
17
  }
18
- export declare class WriteableMapProxy<KEY, VALUE> extends MapProxy<KEY, VALUE> {
18
+ export declare class WriteableMapProxy<KEY, VALUE, WRITERETURN, WRITEVALUE = VALUE> extends MapProxy<KEY, VALUE> {
19
19
  private readonly setter;
20
- constructor(getKeys: () => KEY[], getItem: (key: KEY) => VALUE, setter: (key: KEY, val: VALUE, options?: SetterOptions) => void);
21
- set(key: KEY, value: VALUE, options?: SetterOptions): void;
20
+ constructor(getKeys: () => KEY[], getItem: (key: KEY) => VALUE, setter: (key: KEY, val: WRITEVALUE, options?: SetterOptions) => WRITERETURN);
21
+ set(key: KEY, value: WRITEVALUE, options?: SetterOptions): WRITERETURN;
22
22
  }
23
23
  export interface SetterOptions {
24
24
  force?: boolean;
@@ -59,7 +59,7 @@ class WriteableMapProxy extends MapProxy {
59
59
  this.setter = setter;
60
60
  }
61
61
  set(key, value, options = {}) {
62
- this.setter(key, value, options);
62
+ return this.setter(key, value, options);
63
63
  }
64
64
  }
65
65
  exports.WriteableMapProxy = WriteableMapProxy;
@@ -11,7 +11,7 @@ export declare class PropertyStoreProxy {
11
11
  * Not all properties are writeable (e.g. "ClassName" on a block).
12
12
  * To move or resize elements, use setLocation() or setBoundingBox() or offset() instead.
13
13
  */
14
- readonly properties: WriteableMapProxy<string, import("..").JsonSerializable>;
14
+ readonly properties: WriteableMapProxy<string, import("..").JsonSerializable, void, import("..").JsonSerializable>;
15
15
  /**
16
16
  *
17
17
  * @param id ID of this element, or undefined for the document itself
@@ -6,7 +6,7 @@ import { WriteableMapProxy } from './mapproxy';
6
6
  /**
7
7
  * The shape data fields on a single element of the current document
8
8
  */
9
- export declare class ShapeDataProxy extends WriteableMapProxy<string, SerializedFieldType | SerializedDataError> {
9
+ export declare class ShapeDataProxy extends WriteableMapProxy<string, SerializedFieldType | SerializedDataError, void> {
10
10
  readonly id: string | undefined;
11
11
  protected readonly client: EditorClient;
12
12
  /**
@@ -0,0 +1,28 @@
1
+ import { isBoolean, isNumber, isString } from '../../core/checks';
2
+ /**
3
+ * Text styles that can be read and written with ItemProxy.textStyles.
4
+ */
5
+ export declare enum TextMarkupNames {
6
+ Family = "font",
7
+ Bold = "bold",
8
+ Italic = "italic",
9
+ Underline = "underline",
10
+ Size = "size",
11
+ Color = "color"
12
+ }
13
+ export interface TextStyle {
14
+ [TextMarkupNames.Family]: string;
15
+ [TextMarkupNames.Bold]: boolean;
16
+ [TextMarkupNames.Italic]: boolean;
17
+ [TextMarkupNames.Underline]: boolean;
18
+ [TextMarkupNames.Size]: number;
19
+ [TextMarkupNames.Color]: string;
20
+ }
21
+ export declare const isPartialTextStyle: (subject: unknown) => subject is Partial<import("../..").DestructureGuardedTypeObj<{
22
+ font: typeof isString;
23
+ bold: typeof isBoolean;
24
+ italic: typeof isBoolean;
25
+ underline: typeof isBoolean;
26
+ size: typeof isNumber;
27
+ color: typeof isString;
28
+ }>>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPartialTextStyle = exports.TextMarkupNames = void 0;
4
+ const checks_1 = require("../../core/checks");
5
+ const validators_1 = require("../../core/validators/validators");
6
+ /**
7
+ * Text styles that can be read and written with ItemProxy.textStyles.
8
+ */
9
+ var TextMarkupNames;
10
+ (function (TextMarkupNames) {
11
+ TextMarkupNames["Family"] = "font";
12
+ TextMarkupNames["Bold"] = "bold";
13
+ TextMarkupNames["Italic"] = "italic";
14
+ TextMarkupNames["Underline"] = "underline";
15
+ TextMarkupNames["Size"] = "size";
16
+ TextMarkupNames["Color"] = "color";
17
+ })(TextMarkupNames = exports.TextMarkupNames || (exports.TextMarkupNames = {}));
18
+ exports.isPartialTextStyle = (0, validators_1.partialObjectValidator)({
19
+ [TextMarkupNames.Family]: checks_1.isString,
20
+ [TextMarkupNames.Bold]: checks_1.isBoolean,
21
+ [TextMarkupNames.Italic]: checks_1.isBoolean,
22
+ [TextMarkupNames.Underline]: checks_1.isBoolean,
23
+ [TextMarkupNames.Size]: checks_1.isNumber,
24
+ [TextMarkupNames.Color]: checks_1.isString,
25
+ });
package/sdk/index.d.ts CHANGED
@@ -87,6 +87,7 @@ export * from './document/pagedefinition';
87
87
  export * from './document/pageproxy';
88
88
  export * from './document/propertystoreproxy';
89
89
  export * from './document/shapedataproxy';
90
+ export * from './document/text/textstyle';
90
91
  export * from './editorclient';
91
92
  export * from './index';
92
93
  export * from './math';
package/sdk/index.js CHANGED
@@ -103,6 +103,7 @@ __exportStar(require("./document/pagedefinition"), exports);
103
103
  __exportStar(require("./document/pageproxy"), exports);
104
104
  __exportStar(require("./document/propertystoreproxy"), exports);
105
105
  __exportStar(require("./document/shapedataproxy"), exports);
106
+ __exportStar(require("./document/text/textstyle"), exports);
106
107
  __exportStar(require("./editorclient"), exports);
107
108
  __exportStar(require("./index"), exports);
108
109
  __exportStar(require("./math"), exports);