@univerjs/core 1.0.0-rc.0 → 1.0.0

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 (32) hide show
  1. package/lib/cjs/facade.js +96 -40
  2. package/lib/cjs/index.js +985 -362
  3. package/lib/es/facade.js +97 -41
  4. package/lib/es/index.js +979 -362
  5. package/lib/facade.js +97 -41
  6. package/lib/index.js +979 -362
  7. package/lib/types/docs/data-model/text-x/action-types.d.ts +19 -1
  8. package/lib/types/docs/data-model/text-x/apply-utils/common.d.ts +1 -1
  9. package/lib/types/docs/data-model/text-x/apply-utils/delete-apply.d.ts +1 -1
  10. package/lib/types/docs/data-model/text-x/apply-utils/insert-apply.d.ts +1 -1
  11. package/lib/types/docs/data-model/text-x/apply.d.ts +1 -1
  12. package/lib/types/docs/data-model/text-x/build-utils/text-x-utils.d.ts +2 -1
  13. package/lib/types/docs/data-model/text-x/custom-range-update.d.ts +30 -0
  14. package/lib/types/docs/data-model/text-x/structure-validator.d.ts +1 -1
  15. package/lib/types/docs/data-model/text-x/text-x.d.ts +7 -3
  16. package/lib/types/docs/data-model/text-x/utils.d.ts +7 -1
  17. package/lib/types/docs/sdt-binding.d.ts +19 -0
  18. package/lib/types/facade/f-blob.d.ts +11 -11
  19. package/lib/types/facade/f-enum.d.ts +9 -1
  20. package/lib/types/facade/f-event-registry.d.ts +18 -6
  21. package/lib/types/facade/f-event.d.ts +4 -0
  22. package/lib/types/facade/f-univer.d.ts +43 -19
  23. package/lib/types/index.d.ts +2 -0
  24. package/lib/types/sheets/typedef.d.ts +38 -7
  25. package/lib/types/sheets/workbook.d.ts +1 -1
  26. package/lib/types/sheets/worksheet.d.ts +8 -7
  27. package/lib/types/types/enum/record-filter.d.ts +30 -0
  28. package/lib/types/types/interfaces/i-document-data.d.ts +256 -9
  29. package/lib/types/types/interfaces/i-drawing.d.ts +9 -1
  30. package/lib/umd/facade.js +1 -1
  31. package/lib/umd/index.js +26 -26
  32. package/package.json +7 -7
package/lib/facade.js CHANGED
@@ -1,4 +1,4 @@
1
- import { AbsoluteRefType, AutoFillSeries, BaselineOffset, BooleanNumber, BorderStyleTypes, BorderType, CanceledError, ColorType, CommandType, CommonHideTypes, CopyPasteType, DataValidationErrorStyle, DataValidationOperator, DataValidationRenderMode, DataValidationStatus, DataValidationType, DeleteDirection, DeveloperMetadataVisibility, Dimension, Direction, Disposable, HorizontalAlign, ICommandService, IUniverInstanceService, ImageSourceType, Inject, Injector, InterpolationPointType, LifecycleService, LifecycleStages, LocaleService, LocaleType, MentionType, NamedStyleType, NumberUnitType, ParagraphStyleBuilder, ParagraphStyleValue, PresetListType, ProtectionType, Rectangle, RedoCommand, RegionService, Registry, RelativeDate, RichTextBuilder, RichTextValue, SheetTypes, SpacingRule, TextDecoration, TextDecorationBuilder, TextDirection, TextStyleBuilder, TextStyleValue, ThemeColorType, ThemeService, Tools, UndoCommand, Univer, UniverInstanceType, UserManagerService, VerticalAlign, WrapStrategy, numfmt, toDisposable } from "@univerjs/core";
1
+ import { AbsoluteRefType, AutoFillSeries, BaselineOffset, BooleanNumber, BorderStyleTypes, BorderType, CanceledError, ColorType, CommandType, CommonHideTypes, CopyPasteType, DataValidationErrorStyle, DataValidationOperator, DataValidationRenderMode, DataValidationStatus, DataValidationType, DeleteDirection, DeveloperMetadataVisibility, Dimension, Direction, Disposable, FormulaType, HorizontalAlign, ICommandService, IUniverInstanceService, ImageSourceType, Inject, Injector, InterpolationPointType, LifecycleService, LifecycleStages, LocaleService, LocaleType, MentionType, NamedStyleType, NumberUnitType, ParagraphStyleBuilder, ParagraphStyleValue, PresetListType, ProtectionType, Rectangle, RedoCommand, RegionService, Registry, RelativeDate, RichTextBuilder, RichTextValue, SheetTypes, SpacingRule, TextDecoration, TextDecorationBuilder, TextDirection, TextStyleBuilder, TextStyleValue, ThemeColorType, ThemeService, Tools, UndoCommand, Univer, UniverInstanceType, UserManagerService, VerticalAlign, WorksheetHiddenState, WrapStrategy, numfmt, toDisposable } from "@univerjs/core";
2
2
 
3
3
  //#region src/facade/f-base.ts
4
4
  /**
@@ -80,7 +80,7 @@ var FBaseInitialable = class extends Disposable {
80
80
  };
81
81
 
82
82
  //#endregion
83
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
83
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
84
84
  function __decorateParam(paramIndex, decorator) {
85
85
  return function(target, key) {
86
86
  decorator(target, key, paramIndex);
@@ -88,7 +88,7 @@ function __decorateParam(paramIndex, decorator) {
88
88
  }
89
89
 
90
90
  //#endregion
91
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
91
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
92
92
  function __decorate(decorators, target, key, desc) {
93
93
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
94
94
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -119,9 +119,9 @@ let FBlob = _FBlob = class FBlob extends FBase {
119
119
  return this._injector.createInstance(_FBlob, this._blob);
120
120
  }
121
121
  /**
122
- * Return the data inside this object as a blob converted to the specified content type.
122
+ * Returns a copy labeled with the specified MIME type. The data bytes are not converted or re-encoded.
123
123
  * @param contentType the content type refer to https://developer.mozilla.org/en-US/docs/Web/HTTP/MIME_types/Common_types
124
- * @returns a new blob by converting the current blob to the specified content type
124
+ * @returns {FBlob} A new facade containing the same data with the specified MIME type.
125
125
  * @example
126
126
  * ```ts
127
127
  * const blob = univerAPI.newBlob();
@@ -147,10 +147,10 @@ let FBlob = _FBlob = class FBlob extends FBase {
147
147
  }
148
148
  /**
149
149
  * Gets the data stored in this blob.
150
- * @returns the blob content as a byte array
150
+ * @returns {Promise<Uint8Array>} A promise resolving to the bytes; rejects if no blob data is set.
151
151
  * @example
152
152
  * ```ts
153
- * const blob = univerAPI.newBlob();
153
+ * const blob = univerAPI.newBlob().setDataFromString('Hello, World!');
154
154
  * const bytes = await blob.getBytes();
155
155
  * console.log(bytes);
156
156
  * ```
@@ -181,7 +181,7 @@ let FBlob = _FBlob = class FBlob extends FBase {
181
181
  }
182
182
  /**
183
183
  * Gets the content type of the data stored in this blob.
184
- * @returns the content type
184
+ * @returns {string | undefined} The MIME type, or `undefined` if no blob data is set.
185
185
  * @example
186
186
  * ```ts
187
187
  * const blob = univerAPI.newBlob();
@@ -194,7 +194,7 @@ let FBlob = _FBlob = class FBlob extends FBase {
194
194
  return (_this$_blob = this._blob) === null || _this$_blob === void 0 ? void 0 : _this$_blob.type;
195
195
  }
196
196
  /**
197
- * Sets the content type of the data stored in this blob.
197
+ * Sets the MIME type without converting or re-encoding the data bytes. Has no effect when no blob data is set.
198
198
  * @param contentType the content type refer to https://developer.mozilla.org/en-US/docs/Web/HTTP/MIME_types/Common_types
199
199
  * @returns the blob object
200
200
  * @example
@@ -212,7 +212,7 @@ let FBlob = _FBlob = class FBlob extends FBase {
212
212
  FBlob = _FBlob = __decorate([__decorateParam(1, Inject(Injector))], FBlob);
213
213
 
214
214
  //#endregion
215
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
215
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
216
216
  function _typeof(o) {
217
217
  "@babel/helpers - typeof";
218
218
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -223,7 +223,7 @@ function _typeof(o) {
223
223
  }
224
224
 
225
225
  //#endregion
226
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
226
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
227
227
  function toPrimitive(t, r) {
228
228
  if ("object" != _typeof(t) || !t) return t;
229
229
  var e = t[Symbol.toPrimitive];
@@ -236,14 +236,14 @@ function toPrimitive(t, r) {
236
236
  }
237
237
 
238
238
  //#endregion
239
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
239
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
240
240
  function toPropertyKey(t) {
241
241
  var i = toPrimitive(t, "string");
242
242
  return "symbol" == _typeof(i) ? i : i + "";
243
243
  }
244
244
 
245
245
  //#endregion
246
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
246
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
247
247
  function _defineProperty(e, r, t) {
248
248
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
249
249
  value: t,
@@ -274,6 +274,18 @@ function _defineProperty(e, r, t) {
274
274
  * @hideconstructor
275
275
  */
276
276
  var FEnum = class FEnum {
277
+ /** SpreadsheetML formula types. */
278
+ get FormulaType() {
279
+ return FormulaType;
280
+ }
281
+ /** Worksheet hiding states: VISIBLE (0), HIDDEN (1), VERY_HIDDEN (2). */
282
+ get WorksheetHiddenState() {
283
+ return WorksheetHiddenState;
284
+ }
285
+ /**
286
+ * Returns the shared registry of Facade enum values.
287
+ * @returns {FEnum} The registry also exposed by `univerAPI.Enum`.
288
+ */
277
289
  static get() {
278
290
  if (this._instance) return this._instance;
279
291
  const instance = new FEnum();
@@ -724,6 +736,10 @@ _defineProperty(FEnum, "_instance", void 0);
724
736
  * @hideconstructor
725
737
  */
726
738
  var FEventName = class FEventName {
739
+ /**
740
+ * Returns the shared registry of Facade event names.
741
+ * @returns {FEventName} The registry also exposed by `univerAPI.Event`.
742
+ */
727
743
  static get() {
728
744
  if (this._instance) return this._instance;
729
745
  const instance = new FEventName();
@@ -922,6 +938,13 @@ var FEventRegistry = class {
922
938
  if (!this._eventRegistry.has(event)) this._eventRegistry.set(event, new Registry());
923
939
  return this._eventRegistry.get(event);
924
940
  }
941
+ /**
942
+ * Registers a factory for the underlying subscription that produces an event.
943
+ * The factory starts when the event has listeners; its subscription is disposed when the last listener is removed.
944
+ * @param {string} event The event name.
945
+ * @param {() => IDisposable | Subscription} handler Creates the underlying event subscription.
946
+ * @returns {IDisposable} Unregisters the factory and disposes its active subscription.
947
+ */
925
948
  registerEventHandler(event, handler) {
926
949
  const current = this._eventHandlerMap.get(event);
927
950
  if (current) current.add(handler);
@@ -934,6 +957,11 @@ var FEventRegistry = class {
934
957
  (_this$_eventHandlerRe2 = this._eventHandlerRegisted.get(event)) === null || _this$_eventHandlerRe2 === void 0 || _this$_eventHandlerRe2.delete(handler);
935
958
  });
936
959
  }
960
+ /**
961
+ * Removes one event listener and stops underlying subscriptions when no listeners remain.
962
+ * @param {T} event The event name.
963
+ * @param {(params: IEventParamConfig[T]) => void} callback The previously registered callback.
964
+ */
937
965
  removeEvent(event, callback) {
938
966
  const map = this._ensureEventRegistry(event);
939
967
  map.delete(callback);
@@ -957,9 +985,9 @@ var FEventRegistry = class {
957
985
  }
958
986
  /**
959
987
  * Add an event listener
960
- * @param {string} event key of event
961
- * @param {(params: IEventParamConfig[typeof event]) => void} callback callback when event triggered
962
- * @returns {Disposable} The Disposable instance, for remove the listener
988
+ * @param {T} event key of event
989
+ * @param {(params: IEventParamConfig[T]) => void} callback callback when event triggered
990
+ * @returns {IDisposable} A disposable that removes the event listener.
963
991
  * @example
964
992
  * ```ts
965
993
  * univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, (params) => {
@@ -975,9 +1003,9 @@ var FEventRegistry = class {
975
1003
  }
976
1004
  /**
977
1005
  * Fire an event, used in internal only.
978
- * @param {string} event key of event
979
- * @param {any} params params of event
980
- * @returns {boolean} should cancel
1006
+ * @param {T} event key of event
1007
+ * @param {IEventParamConfig[T]} params params of event
1008
+ * @returns {boolean | undefined} The event's `cancel` value after listeners run; `undefined` if it was not set.
981
1009
  * @example
982
1010
  * ```ts
983
1011
  * this.fireEvent(univerAPI.Event.LifeCycleChanged, params);
@@ -1104,7 +1132,7 @@ var _FUniver;
1104
1132
  const InitializerSymbol = Symbol("initializers");
1105
1133
  let FUniver = _FUniver = class FUniver extends Disposable {
1106
1134
  /**
1107
- * Create an FUniver instance, if the injector is not provided, it will create a new Univer instance.
1135
+ * Creates a Facade API instance for an existing Univer instance or its injector.
1108
1136
  * @static
1109
1137
  * @param {Univer | Injector} wrapped - The Univer instance or injector instance.
1110
1138
  * @returns {FUniver} - The FUniver instance.
@@ -1146,9 +1174,20 @@ let FUniver = _FUniver = class FUniver extends Disposable {
1146
1174
  this._univerInstanceService = _univerInstanceService;
1147
1175
  this._lifecycleService = _lifecycleService;
1148
1176
  _defineProperty(this, "_eventRegistry", new FEventRegistry());
1149
- _defineProperty(this, "registerEventHandler", (event, handler) => {
1150
- return this._eventRegistry.registerEventHandler(event, handler);
1151
- });
1177
+ _defineProperty(
1178
+ this,
1179
+ /**
1180
+ * Registers a factory for the subscription that produces an event.
1181
+ * The factory starts when listeners exist and its subscription is disposed when the last listener is removed.
1182
+ * @param event The event name.
1183
+ * @param handler Creates the underlying event subscription.
1184
+ * @returns A disposable that unregisters the factory and disposes its active subscription.
1185
+ */
1186
+ "registerEventHandler",
1187
+ (event, handler) => {
1188
+ return this._eventRegistry.registerEventHandler(event, handler);
1189
+ }
1190
+ );
1152
1191
  this.disposeWithMe(this.registerEventHandler(this.Event.LifeCycleChanged, () => toDisposable(this._lifecycleService.lifecycle$.subscribe((stage) => {
1153
1192
  this.fireEvent(this.Event.LifeCycleChanged, { stage });
1154
1193
  }))));
@@ -1264,8 +1303,8 @@ let FUniver = _FUniver = class FUniver extends Disposable {
1264
1303
  })));
1265
1304
  }
1266
1305
  /**
1267
- * Dispose the UniverSheet by the `unitId`. The UniverSheet would be unload from the application.
1268
- * @param unitId The unit id of the UniverSheet.
1306
+ * Disposes the document, workbook, or other Univer unit identified by `unitId`, unloading it from the application.
1307
+ * @param unitId The ID of the unit to dispose.
1269
1308
  * @returns Whether the Univer instance is disposed successfully.
1270
1309
  *
1271
1310
  * @example
@@ -1458,9 +1497,9 @@ let FUniver = _FUniver = class FUniver extends Disposable {
1458
1497
  /**
1459
1498
  * Execute a command with the given id and parameters.
1460
1499
  * @param id Identifier of the command.
1461
- * @param params Parameters of this execution.
1462
- * @param options Options of this execution.
1463
- * @returns The result of the execution. It is a boolean value by default which indicates the command is executed.
1500
+ * @param [params] Parameters of this execution.
1501
+ * @param [options] Options of this execution.
1502
+ * @returns {Promise<R>} The result of the execution. It is a boolean value by default which indicates the command is executed.
1464
1503
  *
1465
1504
  * @example
1466
1505
  * ```ts
@@ -1476,8 +1515,8 @@ let FUniver = _FUniver = class FUniver extends Disposable {
1476
1515
  /**
1477
1516
  * Execute a command with the given id and parameters synchronously.
1478
1517
  * @param id Identifier of the command.
1479
- * @param params Parameters of this execution.
1480
- * @param options Options of this execution.
1518
+ * @param [params] Parameters of this execution.
1519
+ * @param [options] Options of this execution.
1481
1520
  * @returns The result of the execution. It is a boolean value by default which indicates the command is executed.
1482
1521
  *
1483
1522
  * @example
@@ -1491,20 +1530,29 @@ let FUniver = _FUniver = class FUniver extends Disposable {
1491
1530
  syncExecuteCommand(id, params, options) {
1492
1531
  return this._commandService.syncExecuteCommand(id, params, options);
1493
1532
  }
1533
+ /**
1534
+ * Enums exposed by the registered Facade extensions.
1535
+ */
1494
1536
  get Enum() {
1495
1537
  return FEnum.get();
1496
1538
  }
1539
+ /**
1540
+ * Event names to use with `addEvent`.
1541
+ */
1497
1542
  get Event() {
1498
1543
  return FEventName.get();
1499
1544
  }
1545
+ /**
1546
+ * Utility functions exposed by the registered Facade extensions.
1547
+ */
1500
1548
  get Util() {
1501
1549
  return FUtil.get();
1502
1550
  }
1503
1551
  /**
1504
1552
  * Add an event listener
1505
- * @param {string} event key of event
1506
- * @param {(params: IEventParamConfig[typeof event]) => void} callback callback when event triggered
1507
- * @returns {Disposable} The Disposable instance, for remove the listener
1553
+ * @param {T} event key of event
1554
+ * @param {(params: IEventParamConfig[T]) => void} callback callback when event triggered
1555
+ * @returns {IDisposable} A disposable that removes the event listener.
1508
1556
  * @example
1509
1557
  * ```ts
1510
1558
  * // Add life cycle changed event listener
@@ -1522,9 +1570,9 @@ let FUniver = _FUniver = class FUniver extends Disposable {
1522
1570
  }
1523
1571
  /**
1524
1572
  * Fire an event, used in internal only.
1525
- * @param {string} event key of event
1526
- * @param {any} params params of event
1527
- * @returns {boolean} should cancel
1573
+ * @param {T} event key of event
1574
+ * @param {IEventParamConfig[T]} params params of event
1575
+ * @returns {boolean | undefined} The event's `cancel` value after listeners run; `undefined` if it was not set.
1528
1576
  * @example
1529
1577
  * ```ts
1530
1578
  * this.fireEvent(univerAPI.Event.LifeCycleChanged, params);
@@ -1533,6 +1581,14 @@ let FUniver = _FUniver = class FUniver extends Disposable {
1533
1581
  fireEvent(event, params) {
1534
1582
  return this._eventRegistry.fireEvent(event, params);
1535
1583
  }
1584
+ /**
1585
+ * Gets the facade for reading the current user.
1586
+ * @returns {FUserManager} The user manager facade.
1587
+ * @example
1588
+ * ```ts
1589
+ * const user = univerAPI.getUserManager().getCurrentUser();
1590
+ * ```
1591
+ */
1536
1592
  getUserManager() {
1537
1593
  return this._injector.createInstance(FUserManager);
1538
1594
  }
@@ -1593,7 +1649,7 @@ let FUniver = _FUniver = class FUniver extends Disposable {
1593
1649
  * This is an advanced document-model API. Application and agent code should normally use
1594
1650
  * `newRichText().paragraph({ ... })`.
1595
1651
  *
1596
- * @param {IParagraphStyle} style The paragraph style
1652
+ * @param {IParagraphStyle} [style] The paragraph style
1597
1653
  * @returns {ParagraphStyleBuilder} The new paragraph style instance
1598
1654
  * @advanced
1599
1655
  */
@@ -1602,7 +1658,7 @@ let FUniver = _FUniver = class FUniver extends Disposable {
1602
1658
  }
1603
1659
  /**
1604
1660
  * Create a new paragraph style value.
1605
- * @param {IParagraphStyle} style - The paragraph style
1661
+ * @param {IParagraphStyle} [style] - The paragraph style
1606
1662
  * @returns {ParagraphStyleValue} The new paragraph style value instance
1607
1663
  * @example
1608
1664
  * ```ts
@@ -1614,7 +1670,7 @@ let FUniver = _FUniver = class FUniver extends Disposable {
1614
1670
  }
1615
1671
  /**
1616
1672
  * Create a new text style.
1617
- * @param {ITextStyle} style - The text style
1673
+ * @param {ITextStyle} [style] - The text style
1618
1674
  * @returns {TextStyleBuilder} The new text style instance
1619
1675
  * @example
1620
1676
  * ```ts
@@ -1626,7 +1682,7 @@ let FUniver = _FUniver = class FUniver extends Disposable {
1626
1682
  }
1627
1683
  /**
1628
1684
  * Create a new text style value.
1629
- * @param {ITextStyle} style - The text style
1685
+ * @param {ITextStyle} [style] - The text style
1630
1686
  * @returns {TextStyleValue} The new text style value instance
1631
1687
  * @example
1632
1688
  * ```ts
@@ -1638,7 +1694,7 @@ let FUniver = _FUniver = class FUniver extends Disposable {
1638
1694
  }
1639
1695
  /**
1640
1696
  * Create a new text decoration.
1641
- * @param {ITextDecoration} decoration - The text decoration
1697
+ * @param {ITextDecoration} [decoration] - The text decoration
1642
1698
  * @returns {TextDecorationBuilder} The new text decoration instance
1643
1699
  * @example
1644
1700
  * ```ts