@univerjs/docs-ui 0.4.0-alpha.1 → 0.4.0-experimental.d7288c0-20241017

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/lib/es/index.js CHANGED
@@ -9,9 +9,9 @@ import * as require$$0 from "react";
9
9
  import require$$0__default, { useState, useRef, useEffect, forwardRef, createElement, useMemo, useCallback } from "react";
10
10
  import { LexerTreeBuilder, operatorToken, isReferenceStrings, serializeRange, serializeRangeWithSheet, serializeRangeWithSpreadsheet, isReferenceStringWithEffectiveColumn, getRangeWithRefsString } from "@univerjs/engine-formula";
11
11
  import { Subject, BehaviorSubject, takeUntil, fromEvent, merge, combineLatest, Observable, map as map$1, distinctUntilChanged, filter as filter$1, throttleTime, mergeMap, take, animationFrameScheduler } from "rxjs";
12
- import { ILayoutService, useEvent, ComponentManager, ISidebarService, KeyCode, MetaKeys, IClipboardInterfaceService, PLAIN_TEXT_CLIPBOARD_MIME_TYPE, HTML_CLIPBOARD_MIME_TYPE, CopyCommand, CutCommand, PasteCommand, IConfirmService, MenuItemType, getMenuHiddenObservable, FONT_FAMILY_LIST, FONT_SIZE_LIST, getHeaderFooterMenuHiddenObservable, RibbonStartGroup, ContextMenuPosition, ContextMenuGroup, FontFamily, FontFamilyItem, FontSize, BuiltInUIPart, IMenuManagerService, IUIPartsService, IShortcutService, ICanvasPopupService, IContextMenuService, SetEditorResizeOperation } from "@univerjs/ui";
13
- import { Tooltip, Dialog, Button, Input, Checkbox, InputNumber, Slider, Select, ColorPicker } from "@univerjs/design";
12
+ import { ILayoutService, KeyCode, useEvent, ComponentManager, ISidebarService, MetaKeys, IClipboardInterfaceService, PLAIN_TEXT_CLIPBOARD_MIME_TYPE, HTML_CLIPBOARD_MIME_TYPE, CopyCommand, CutCommand, PasteCommand, IConfirmService, MenuItemType, getMenuHiddenObservable, FONT_FAMILY_LIST, FONT_SIZE_LIST, getHeaderFooterMenuHiddenObservable, RibbonStartGroup, ContextMenuPosition, ContextMenuGroup, FontFamily, FontFamilyItem, FontSize, BuiltInUIPart, IMenuManagerService, IUIPartsService, IShortcutService, ICanvasPopupService, IContextMenuService, SetEditorResizeOperation } from "@univerjs/ui";
14
13
  import { filter, bufferTime, map } from "rxjs/operators";
14
+ import { Tooltip, Dialog, Button, Input, Checkbox, InputNumber, Slider, Select, ColorPicker } from "@univerjs/design";
15
15
  var __defProp$r = Object.defineProperty, __getOwnPropDesc$r = Object.getOwnPropertyDescriptor, __decorateClass$r = /* @__PURE__ */ __name((decorators, target, key, kind) => {
16
16
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$r(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
17
17
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
@@ -1691,6 +1691,7 @@ let DocSelectionRenderService = (_a2 = class extends RxDisposable {
1691
1691
  _setRangeStyle(style = NORMAL_TEXT_SELECTION_PLUGIN_STYLE) {
1692
1692
  this._selectionStyle = style;
1693
1693
  }
1694
+ // eslint-disable-next-line max-lines-per-function
1694
1695
  addDocRanges(ranges, isEditing = !0, options) {
1695
1696
  const {
1696
1697
  _currentSegmentId: segmentId,
@@ -1712,19 +1713,28 @@ let DocSelectionRenderService = (_a2 = class extends RxDisposable {
1712
1713
  );
1713
1714
  rectRange && this._addRectRanges([rectRange]);
1714
1715
  } else if (rangeType === DOC_RANGE_TYPE.TEXT) {
1715
- const textRange = getTextRangeFromCharIndex(
1716
- startNodePosition != null && startNodePosition.isBack ? startOffset : startOffset - 1,
1717
- endNodePosition != null && endNodePosition.isBack ? endOffset : endOffset - 1,
1716
+ let textRange = null;
1717
+ startNodePosition && endNodePosition ? textRange = getTextRangeFromCharIndex(
1718
+ startNodePosition.isBack ? startOffset : startOffset - 1,
1719
+ endNodePosition.isBack ? endOffset : endOffset - 1,
1718
1720
  scene,
1719
1721
  document2,
1720
1722
  docSkeleton,
1721
1723
  style,
1722
1724
  segmentId,
1723
1725
  segmentPage,
1724
- startNodePosition == null ? void 0 : startNodePosition.isBack,
1725
- endNodePosition == null ? void 0 : endNodePosition.isBack
1726
- );
1727
- textRange && this._addTextRange(textRange);
1726
+ startNodePosition.isBack,
1727
+ endNodePosition.isBack
1728
+ ) : textRange = getTextRangeFromCharIndex(
1729
+ startOffset,
1730
+ endOffset,
1731
+ scene,
1732
+ document2,
1733
+ docSkeleton,
1734
+ style,
1735
+ segmentId,
1736
+ segmentPage
1737
+ ), textRange && this._addTextRange(textRange);
1728
1738
  } else {
1729
1739
  const rangeList = getRangeListFromCharIndex(
1730
1740
  startOffset,
@@ -2345,7 +2355,10 @@ const _Editor = class _Editor extends Disposable {
2345
2355
  ), this.disposeWithMe(
2346
2356
  merge(
2347
2357
  docSelectionRenderService.onInput$,
2348
- docSelectionRenderService.onKeydown$,
2358
+ docSelectionRenderService.onKeydown$.pipe(filter((e) => {
2359
+ const event = e.event;
2360
+ return event.ctrlKey || event.metaKey ? [KeyCode.X, KeyCode.V].includes(event.keyCode) : [KeyCode.BACKSPACE].includes(event.keyCode);
2361
+ })),
2349
2362
  docSelectionRenderService.onCompositionupdate$,
2350
2363
  docSelectionRenderService.onCompositionend$,
2351
2364
  docSelectionRenderService.onPaste$
@@ -2688,7 +2701,7 @@ let EditorService = (_b = class extends Disposable {
2688
2701
  const editor = this.getEditor(editorUnitId);
2689
2702
  if (!editor)
2690
2703
  return !1;
2691
- editor.setFocus(!0), this._contextService.setContextValue(EDITOR_ACTIVATED, !0), this._contextService.setContextValue(FOCUSING_EDITOR_STANDALONE, !0), this._contextService.setContextValue(FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE, editor.isSingle()), this._spreadsheetFocusState || this.singleSelection(editor.isSingleChoice()), this._focusStyle$.next(editorUnitId), this.setFocusId(editorUnitId);
2704
+ editor.setFocus(!0), this._contextService.setContextValue(EDITOR_ACTIVATED, !0), this._contextService.setContextValue(FOCUSING_EDITOR_STANDALONE, !0), this._contextService.setContextValue(FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE, editor.isSingle()), this._spreadsheetFocusState || this.singleSelection(!!editor.isSingleChoice()), this._focusStyle$.next(editorUnitId), this.setFocusId(editorUnitId);
2692
2705
  }
2693
2706
  /** @deprecated */
2694
2707
  singleSelection(state) {
@@ -4334,145 +4347,58 @@ __name(getReverseFormatValueInSelection, "getReverseFormatValueInSelection");
4334
4347
  const ListOperationCommand = {
4335
4348
  id: "doc.command.list-operation",
4336
4349
  type: CommandType.COMMAND,
4337
- // eslint-disable-next-line max-lines-per-function, complexity
4338
4350
  handler: /* @__PURE__ */ __name((accessor, params) => {
4339
- var _a28, _b2, _c, _d, _e, _f;
4340
- const docSelectionManagerService = accessor.get(DocSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService);
4341
- let listType = params.listType;
4342
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance(), docRanges = (_a28 = docSelectionManagerService.getDocRanges()) != null ? _a28 : [];
4351
+ var _a28, _b2;
4352
+ const docSelectionManagerService = accessor.get(DocSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), listType = params.listType, docDataModel = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC), docRanges = (_a28 = docSelectionManagerService.getDocRanges()) != null ? _a28 : [];
4343
4353
  if (docDataModel == null || docRanges.length === 0)
4344
4354
  return !1;
4345
4355
  const segmentId = docRanges[0].segmentId, paragraphs = (_b2 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _b2.paragraphs;
4346
4356
  if (paragraphs == null)
4347
4357
  return !1;
4348
- const sectionBreaks = (_d = (_c = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _c.sectionBreaks) != null ? _d : [], currentParagraphs = getParagraphsInRanges(docRanges, paragraphs), unitId = docDataModel.getUnitId(), isAlreadyList = currentParagraphs.every((paragraph) => {
4349
- var _a29;
4350
- return ((_a29 = paragraph.bullet) == null ? void 0 : _a29.listType.indexOf(listType)) === 0;
4351
- });
4352
- let listId = Tools.generateRandomId(6);
4353
- if (currentParagraphs.length === 1) {
4354
- const curIndex = paragraphs.indexOf(currentParagraphs[0]), prevParagraph = paragraphs[curIndex - 1], nextParagraph = paragraphs[curIndex + 1];
4355
- prevParagraph && prevParagraph.bullet && prevParagraph.bullet.listType.indexOf(listType) === 0 ? (listId = prevParagraph.bullet.listId, listType !== PresetListType.CHECK_LIST && (listType = prevParagraph.bullet.listType)) : nextParagraph && nextParagraph.bullet && nextParagraph.bullet.listType.indexOf(listType) === 0 && (listId = nextParagraph.bullet.listId, listType !== PresetListType.CHECK_LIST && (listType = nextParagraph.bullet.listType));
4356
- }
4357
- const doMutation = {
4358
+ const currentParagraphs = getParagraphsInRanges(docRanges, paragraphs), unitId = docDataModel.getUnitId(), doMutation = {
4358
4359
  id: RichTextEditingMutation.id,
4359
4360
  params: {
4360
4361
  unitId,
4361
4362
  actions: [],
4362
4363
  textRanges: docRanges
4363
4364
  }
4364
- }, memoryCursor = new MemoryCursor();
4365
- memoryCursor.reset();
4366
- const textX = new TextX(), jsonX = JSONX.getInstance(), customLists = (_e = docDataModel.getSnapshot().lists) != null ? _e : {}, lists = {
4367
- ...PRESET_LIST_TYPE,
4368
- ...customLists
4369
- }, { defaultTabStop = 36 } = docDataModel.getSnapshot().documentStyle;
4370
- for (const paragraph of currentParagraphs) {
4371
- const { startIndex, paragraphStyle = {}, bullet } = paragraph, { indentFirstLine, snapToGrid, indentStart } = paragraphStyle;
4372
- lists[listType].nestingLevel[0].paragraphProperties;
4373
- const { charSpace, gridType } = findNearestSectionBreak(startIndex, sectionBreaks) || { charSpace: 0, gridType: GridType.LINES };
4374
- getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid), textX.push({
4375
- t: TextXActionType.RETAIN,
4376
- len: startIndex - memoryCursor.cursor,
4377
- segmentId
4378
- }), textX.push({
4379
- t: TextXActionType.RETAIN,
4380
- len: 1,
4381
- body: {
4382
- dataStream: "",
4383
- paragraphs: [
4384
- isAlreadyList ? {
4385
- paragraphStyle: {
4386
- ...paragraphStyle
4387
- // hanging: undefined,
4388
- // indentStart: indentStart ? { v: Math.max(0, getNumberUnitValue(indentStart, charSpaceApply) + getNumberUnitValue(listHanging, charSpaceApply) - getNumberUnitValue(listIndentStart, charSpaceApply)) } : undefined,
4389
- },
4390
- startIndex: 0
4391
- } : {
4392
- startIndex: 0,
4393
- paragraphStyle: {
4394
- ...paragraphStyle
4395
- // indentFirstLine: undefined,
4396
- // hanging: listHanging,
4397
- // indentStart: { v: getNumberUnitValue(listIndentStart, charSpaceApply) - getNumberUnitValue(listHanging, charSpaceApply) + getNumberUnitValue(indentFirstLine, charSpaceApply) + getNumberUnitValue(indentStart, charSpaceApply) },
4398
- },
4399
- bullet: {
4400
- nestingLevel: (_f = bullet == null ? void 0 : bullet.nestingLevel) != null ? _f : 0,
4401
- textStyle: {
4402
- fs: 20
4403
- },
4404
- listType,
4405
- listId
4406
- }
4407
- }
4408
- ]
4409
- },
4410
- segmentId,
4411
- coverType: UpdateDocsAttributeType.REPLACE
4412
- }), memoryCursor.moveCursorTo(startIndex + 1);
4413
- }
4414
- const path = getRichTextEditPath(docDataModel, segmentId);
4365
+ };
4366
+ new MemoryCursor().reset();
4367
+ const textX = BuildTextUtils.paragraph.bullet.switch({
4368
+ paragraphs: currentParagraphs,
4369
+ listType,
4370
+ document: docDataModel,
4371
+ segmentId
4372
+ }), jsonX = JSONX.getInstance(), path = getRichTextEditPath(docDataModel, segmentId);
4415
4373
  return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
4416
4374
  }, "handler")
4417
4375
  }, ChangeListTypeCommand = {
4418
4376
  id: "doc.command.change-list-type",
4419
4377
  type: CommandType.COMMAND,
4420
- // eslint-disable-next-line max-lines-per-function
4421
4378
  handler: /* @__PURE__ */ __name((accessor, params) => {
4422
- var _a28, _b2, _c, _d, _e;
4423
- const docSelectionManagerService = accessor.get(DocSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { listType } = params, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeRanges = docSelectionManagerService.getDocRanges();
4379
+ var _a28, _b2;
4380
+ const docSelectionManagerService = accessor.get(DocSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { listType } = params, docDataModel = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC), activeRanges = docSelectionManagerService.getDocRanges();
4424
4381
  if (docDataModel == null || activeRanges == null || !activeRanges.length)
4425
4382
  return !1;
4426
4383
  const { segmentId } = activeRanges[0], selections = (_a28 = docSelectionManagerService.getDocRanges()) != null ? _a28 : [], paragraphs = (_b2 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _b2.paragraphs;
4427
4384
  if (paragraphs == null)
4428
4385
  return !1;
4429
- (_d = (_c = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _c.sectionBreaks) != null;
4430
- const currentParagraphs = getParagraphsRelative(activeRanges, paragraphs), unitId = docDataModel.getUnitId(), listId = Tools.generateRandomId(6), doMutation = {
4386
+ const currentParagraphs = getParagraphsInRanges(selections, paragraphs), unitId = docDataModel.getUnitId(), textX = BuildTextUtils.paragraph.bullet.set({
4387
+ paragraphs: currentParagraphs,
4388
+ listType,
4389
+ segmentId,
4390
+ document: docDataModel
4391
+ });
4392
+ if (!textX)
4393
+ return !1;
4394
+ const jsonX = JSONX.getInstance(), doMutation = {
4431
4395
  id: RichTextEditingMutation.id,
4432
4396
  params: {
4433
4397
  unitId,
4434
4398
  actions: [],
4435
4399
  textRanges: selections
4436
4400
  }
4437
- }, memoryCursor = new MemoryCursor();
4438
- memoryCursor.reset();
4439
- const textX = new TextX(), jsonX = JSONX.getInstance();
4440
- for (const paragraph of currentParagraphs) {
4441
- const { startIndex, paragraphStyle = {}, bullet } = paragraph;
4442
- textX.push({
4443
- t: TextXActionType.RETAIN,
4444
- len: startIndex - memoryCursor.cursor,
4445
- segmentId
4446
- }), textX.push({
4447
- t: TextXActionType.RETAIN,
4448
- len: 1,
4449
- body: {
4450
- dataStream: "",
4451
- paragraphs: [
4452
- {
4453
- startIndex: 0,
4454
- paragraphStyle: {
4455
- ...paragraphStyle
4456
- // indentFirstLine: undefined,
4457
- // hanging: listHanging,
4458
- // indentStart: { v: getNumberUnitValue(listIndentStart, charSpaceApply) - getNumberUnitValue(listHanging, charSpaceApply) + getNumberUnitValue(indentFirstLine, charSpaceApply) + getNumberUnitValue(indentStart, charSpaceApply) },
4459
- },
4460
- bullet: {
4461
- nestingLevel: (_e = bullet == null ? void 0 : bullet.nestingLevel) != null ? _e : 0,
4462
- textStyle: (bullet == null ? void 0 : bullet.listType) === listType ? bullet.textStyle : {
4463
- fs: 20
4464
- },
4465
- listType,
4466
- listId
4467
- }
4468
- }
4469
- ]
4470
- },
4471
- segmentId,
4472
- coverType: UpdateDocsAttributeType.REPLACE
4473
- }), memoryCursor.moveCursorTo(startIndex + 1);
4474
- }
4475
- const path = getRichTextEditPath(docDataModel, segmentId);
4401
+ }, path = getRichTextEditPath(docDataModel, segmentId);
4476
4402
  return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
4477
4403
  }, "handler")
4478
4404
  };
@@ -4480,68 +4406,29 @@ var ChangeListNestingLevelType = /* @__PURE__ */ ((ChangeListNestingLevelType2)
4480
4406
  const ChangeListNestingLevelCommand = {
4481
4407
  id: "doc.command.change-list-nesting-level",
4482
4408
  type: CommandType.COMMAND,
4483
- // eslint-disable-next-line max-lines-per-function
4484
4409
  handler: /* @__PURE__ */ __name((accessor, params) => {
4485
- var _a28, _b2, _c, _d, _e;
4410
+ var _a28, _b2;
4486
4411
  if (!params)
4487
4412
  return !1;
4488
- const { type } = params, docSelectionManagerService = accessor.get(DocSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeRange = docSelectionManagerService.getActiveTextRange();
4413
+ const { type } = params, docSelectionManagerService = accessor.get(DocSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), docDataModel = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC), activeRange = docSelectionManagerService.getActiveTextRange();
4489
4414
  if (docDataModel == null || activeRange == null)
4490
4415
  return !1;
4491
- const { segmentId } = activeRange, tables = (_b2 = (_a28 = docDataModel.getBody()) == null ? void 0 : _a28.tables) != null ? _b2 : [], selections = (_c = docSelectionManagerService.getDocRanges()) != null ? _c : [], paragraphs = (_d = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _d.paragraphs;
4416
+ const { segmentId } = activeRange, selections = (_a28 = docSelectionManagerService.getDocRanges()) != null ? _a28 : [], paragraphs = (_b2 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _b2.paragraphs;
4492
4417
  if (paragraphs == null)
4493
4418
  return !1;
4494
- const currentParagraphs = getParagraphsInRange(activeRange, paragraphs), unitId = docDataModel.getUnitId(), doMutation = {
4419
+ const currentParagraphs = getParagraphsInRange(activeRange, paragraphs), unitId = docDataModel.getUnitId(), jsonX = JSONX.getInstance(), textX = BuildTextUtils.paragraph.bullet.changeNestLevel({
4420
+ paragraphs: currentParagraphs,
4421
+ type,
4422
+ segmentId,
4423
+ document: docDataModel
4424
+ }), doMutation = {
4495
4425
  id: RichTextEditingMutation.id,
4496
4426
  params: {
4497
4427
  unitId,
4498
4428
  actions: [],
4499
4429
  textRanges: selections
4500
4430
  }
4501
- }, memoryCursor = new MemoryCursor();
4502
- memoryCursor.reset();
4503
- const textX = new TextX(), jsonX = JSONX.getInstance(), customLists = (_e = docDataModel.getSnapshot().lists) != null ? _e : {}, lists = {
4504
- ...PRESET_LIST_TYPE,
4505
- ...customLists
4506
- };
4507
- for (const paragraph of currentParagraphs) {
4508
- const { startIndex, paragraphStyle = {}, bullet } = paragraph, isInTable = hasParagraphInTable(paragraph, tables);
4509
- if (textX.push({
4510
- t: TextXActionType.RETAIN,
4511
- len: startIndex - memoryCursor.cursor,
4512
- segmentId
4513
- }), bullet) {
4514
- const listType = bullet.listType;
4515
- let maxLevel = lists[listType].nestingLevel.length - 1;
4516
- isInTable && (maxLevel = Math.min(maxLevel, 2)), textX.push({
4517
- t: TextXActionType.RETAIN,
4518
- len: 1,
4519
- body: {
4520
- dataStream: "",
4521
- paragraphs: [
4522
- {
4523
- startIndex: 0,
4524
- paragraphStyle: {
4525
- ...paragraphStyle
4526
- },
4527
- bullet: {
4528
- ...bullet,
4529
- nestingLevel: Math.max(Math.min(bullet.nestingLevel + type, maxLevel), 0)
4530
- }
4531
- }
4532
- ]
4533
- },
4534
- segmentId,
4535
- coverType: UpdateDocsAttributeType.REPLACE
4536
- });
4537
- } else
4538
- textX.push({
4539
- t: TextXActionType.RETAIN,
4540
- len: 1
4541
- });
4542
- memoryCursor.moveCursorTo(startIndex + 1);
4543
- }
4544
- const path = getRichTextEditPath(docDataModel, segmentId);
4431
+ }, path = getRichTextEditPath(docDataModel, segmentId);
4545
4432
  return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
4546
4433
  }, "handler")
4547
4434
  }, BulletListCommand = {
@@ -4569,21 +4456,14 @@ const ChangeListNestingLevelCommand = {
4569
4456
  }, ToggleCheckListCommand = {
4570
4457
  id: "doc.command.toggle-check-list",
4571
4458
  type: CommandType.COMMAND,
4572
- // eslint-disable-next-line max-lines-per-function
4573
4459
  handler: /* @__PURE__ */ __name((accessor, params) => {
4574
4460
  var _a28;
4575
4461
  if (!params)
4576
4462
  return !1;
4577
- const univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { index, segmentId, textRanges } = params, docDataModel = univerInstanceService.getCurrentUniverDocInstance();
4578
- if (docDataModel == null)
4579
- return !1;
4580
- const paragraphs = (_a28 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a28.paragraphs;
4581
- if (paragraphs == null)
4582
- return !1;
4583
- const currentParagraph = paragraphs.find((p2) => p2.startIndex === index), unitId = docDataModel.getUnitId();
4584
- if (!(currentParagraph != null && currentParagraph.bullet) || currentParagraph.bullet.listType.indexOf(PresetListType.CHECK_LIST) === -1)
4463
+ const univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { index, segmentId, textRanges } = params, docDataModel = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
4464
+ if (docDataModel == null || ((_a28 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a28.paragraphs) == null)
4585
4465
  return !1;
4586
- const doMutation = {
4466
+ const unitId = docDataModel.getUnitId(), doMutation = {
4587
4467
  id: RichTextEditingMutation.id,
4588
4468
  params: {
4589
4469
  unitId,
@@ -4591,34 +4471,14 @@ const ChangeListNestingLevelCommand = {
4591
4471
  textRanges: textRanges != null ? textRanges : [],
4592
4472
  segmentId
4593
4473
  }
4594
- }, memoryCursor = new MemoryCursor();
4595
- memoryCursor.reset();
4596
- const textX = new TextX(), jsonX = JSONX.getInstance(), { startIndex, paragraphStyle = {} } = currentParagraph, listType = currentParagraph.bullet.listType === PresetListType.CHECK_LIST ? PresetListType.CHECK_LIST_CHECKED : PresetListType.CHECK_LIST;
4597
- textX.push({
4598
- t: TextXActionType.RETAIN,
4599
- len: startIndex - memoryCursor.cursor,
4474
+ }, textX = BuildTextUtils.paragraph.bullet.toggleChecklist({
4475
+ document: docDataModel,
4476
+ paragraphIndex: index,
4600
4477
  segmentId
4601
- }), textX.push({
4602
- t: TextXActionType.RETAIN,
4603
- len: 1,
4604
- body: {
4605
- dataStream: "",
4606
- paragraphs: [
4607
- {
4608
- ...currentParagraph,
4609
- paragraphStyle,
4610
- startIndex: 0,
4611
- bullet: {
4612
- ...currentParagraph.bullet,
4613
- listType
4614
- }
4615
- }
4616
- ]
4617
- },
4618
- coverType: UpdateDocsAttributeType.REPLACE,
4619
- segmentId
4620
- }), memoryCursor.moveCursorTo(startIndex + 1);
4621
- const path = getRichTextEditPath(docDataModel, segmentId);
4478
+ });
4479
+ if (!textX)
4480
+ return !1;
4481
+ const jsonX = JSONX.getInstance(), path = getRichTextEditPath(docDataModel, segmentId);
4622
4482
  return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
4623
4483
  }, "handler")
4624
4484
  }, OrderListCommand = {
@@ -4640,7 +4500,7 @@ const ChangeListNestingLevelCommand = {
4640
4500
  var _a28, _b2, _c, _d, _e;
4641
4501
  if (!params)
4642
4502
  return !1;
4643
- const docSelectionManagerService = accessor.get(DocSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeRange = docSelectionManagerService.getActiveTextRange();
4503
+ const docSelectionManagerService = accessor.get(DocSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), docDataModel = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC), activeRange = docSelectionManagerService.getActiveTextRange();
4644
4504
  if (docDataModel == null || activeRange == null)
4645
4505
  return !1;
4646
4506
  const { segmentId } = activeRange, { listType, paragraph } = params, { paragraphStart, paragraphEnd } = paragraph, textX = new TextX(), jsonX = JSONX.getInstance(), { defaultTabStop = 36 } = docDataModel.getSnapshot().documentStyle, sectionBreaks = (_b2 = (_a28 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a28.sectionBreaks) != null ? _b2 : [], { startIndex, paragraphStyle = {} } = paragraph, { indentFirstLine, snapToGrid, indentStart } = paragraphStyle, paragraphProperties = PRESET_LIST_TYPE[listType].nestingLevel[0].paragraphProperties || {}, { hanging: listHanging, indentStart: listIndentStart } = paragraphProperties, bulletParagraphTextStyle = paragraphProperties.textStyle, { charSpace, gridType } = findNearestSectionBreak(startIndex, sectionBreaks) || { charSpace: 0, gridType: GridType.LINES }, charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);
@@ -4712,22 +4572,6 @@ function getParagraphsInRange(activeRange, paragraphs) {
4712
4572
  return results;
4713
4573
  }
4714
4574
  __name(getParagraphsInRange, "getParagraphsInRange");
4715
- function getParagraphsRelative(ranges, paragraphs) {
4716
- const selectionParagraphs = getParagraphsInRanges(ranges, paragraphs), startIndex = paragraphs.indexOf(selectionParagraphs[0]), endIndex = paragraphs.indexOf(selectionParagraphs[selectionParagraphs.length - 1]);
4717
- if (selectionParagraphs[0].bullet)
4718
- for (let i = startIndex - 1; i >= 0; i--) {
4719
- const prevParagraph = paragraphs[i];
4720
- prevParagraph.bullet && prevParagraph.bullet.listId === selectionParagraphs[0].bullet.listId && selectionParagraphs.unshift(prevParagraph);
4721
- }
4722
- const lastParagraph = selectionParagraphs[selectionParagraphs.length - 1];
4723
- if (lastParagraph.bullet)
4724
- for (let i = endIndex + 1; i < paragraphs.length; i++) {
4725
- const nextParagraph = paragraphs[i];
4726
- nextParagraph.bullet && nextParagraph.bullet.listId === lastParagraph.bullet.listId && selectionParagraphs.push(nextParagraph);
4727
- }
4728
- return selectionParagraphs;
4729
- }
4730
- __name(getParagraphsRelative, "getParagraphsRelative");
4731
4575
  function getParagraphsInRanges(ranges, paragraphs) {
4732
4576
  const results = [];
4733
4577
  for (const range of ranges) {
@@ -7191,7 +7035,6 @@ const DOC_CLIPBOARD_PRIORITY = 999, DocCopyCommand = {
7191
7035
  }, "handler")
7192
7036
  }, COMPONENT_DOC_CREATE_TABLE_CONFIRM = "COMPONENT_DOC_CREATE_TABLE_CONFIRM";
7193
7037
  function generateParagraphs(dataStream, prevParagraph) {
7194
- var _a28, _b2;
7195
7038
  const paragraphs = [];
7196
7039
  for (let i = 0, len = dataStream.length; i < len; i++)
7197
7040
  dataStream[i] === DataStreamTreeTokenType.PARAGRAPH && paragraphs.push({
@@ -7199,9 +7042,7 @@ function generateParagraphs(dataStream, prevParagraph) {
7199
7042
  });
7200
7043
  if (prevParagraph)
7201
7044
  for (const paragraph of paragraphs)
7202
- prevParagraph.bullet && (paragraph.bullet = Tools.deepClone(prevParagraph.bullet), paragraph.bullet.listType === PresetListType.CHECK_LIST_CHECKED && (paragraph.bullet.listType = PresetListType.CHECK_LIST)), prevParagraph.paragraphStyle && (paragraph.paragraphStyle = Tools.deepClone(prevParagraph.paragraphStyle), ((_a28 = prevParagraph.bullet) == null ? void 0 : _a28.listType) === PresetListType.CHECK_LIST_CHECKED && (_b2 = paragraph.paragraphStyle) != null && _b2.textStyle && (paragraph.paragraphStyle.textStyle.st = {
7203
- s: BooleanNumber.FALSE
7204
- }));
7045
+ prevParagraph.bullet && (paragraph.bullet = Tools.deepClone(prevParagraph.bullet)), prevParagraph.paragraphStyle && (paragraph.paragraphStyle = Tools.deepClone(prevParagraph.paragraphStyle));
7205
7046
  return paragraphs;
7206
7047
  }
7207
7048
  __name(generateParagraphs, "generateParagraphs");
@@ -7209,7 +7050,7 @@ const BreakLineCommand = {
7209
7050
  id: "doc.command.break-line",
7210
7051
  type: CommandType.COMMAND,
7211
7052
  handler: /* @__PURE__ */ __name(async (accessor) => {
7212
- var _a28, _b2;
7053
+ var _a28, _b2, _c, _d;
7213
7054
  const docSelectionManagerService = accessor.get(DocSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), activeTextRange = docSelectionManagerService.getActiveTextRange(), rectRanges = docSelectionManagerService.getRectRanges();
7214
7055
  if (activeTextRange == null)
7215
7056
  return !1;
@@ -7224,39 +7065,30 @@ const BreakLineCommand = {
7224
7065
  if (!docDataModel || !body)
7225
7066
  return !1;
7226
7067
  const unitId = docDataModel.getUnitId(), { startOffset, endOffset } = BuildTextUtils.selection.getInsertSelection(activeTextRange, body), prevParagraph = ((_a28 = body.paragraphs) != null ? _a28 : []).find((p2) => p2.startIndex >= startOffset);
7227
- if (prevParagraph && prevParagraph.startIndex > endOffset) {
7228
- const bodyAfter = normalizeBody(getBodySlice(body, endOffset, prevParagraph.startIndex + 1));
7229
- bodyAfter.customRanges = (_b2 = bodyAfter.customRanges) == null ? void 0 : _b2.map(BuildTextUtils.customRange.copyCustomRange);
7230
- const deleteRange = {
7231
- startOffset,
7232
- endOffset: prevParagraph.startIndex + 1,
7233
- collapsed: !1
7234
- };
7235
- return updateAttributeByInsert(
7236
- bodyAfter,
7237
- {
7238
- dataStream: DataStreamTreeTokenType.PARAGRAPH,
7239
- paragraphs: generateParagraphs(DataStreamTreeTokenType.PARAGRAPH, prevParagraph)
7240
- },
7241
- 1,
7242
- 0
7243
- ), await commandService.executeCommand(InsertCommand.id, {
7244
- unitId,
7245
- body: bodyAfter,
7246
- range: deleteRange,
7247
- segmentId,
7248
- cursorOffset: 1
7249
- });
7250
- } else
7251
- return await commandService.executeCommand(InsertCommand.id, {
7252
- unitId,
7253
- body: {
7254
- dataStream: DataStreamTreeTokenType.PARAGRAPH,
7255
- paragraphs: generateParagraphs(DataStreamTreeTokenType.PARAGRAPH, prevParagraph)
7256
- },
7257
- range: activeTextRange,
7258
- segmentId
7259
- });
7068
+ if (!prevParagraph)
7069
+ return !1;
7070
+ const bodyAfter = normalizeBody(getBodySlice(body, endOffset, prevParagraph.startIndex + 1));
7071
+ bodyAfter.customRanges = (_b2 = bodyAfter.customRanges) == null ? void 0 : _b2.map(BuildTextUtils.customRange.copyCustomRange);
7072
+ const deleteRange = {
7073
+ startOffset,
7074
+ endOffset: prevParagraph.startIndex + 1,
7075
+ collapsed: !1
7076
+ };
7077
+ return ((_d = (_c = bodyAfter.paragraphs) == null ? void 0 : _c[0].bullet) == null ? void 0 : _d.listType) === PresetListType.CHECK_LIST_CHECKED && (bodyAfter.paragraphs[0].bullet.listType = PresetListType.CHECK_LIST), updateAttributeByInsert(
7078
+ bodyAfter,
7079
+ {
7080
+ dataStream: DataStreamTreeTokenType.PARAGRAPH,
7081
+ paragraphs: generateParagraphs(DataStreamTreeTokenType.PARAGRAPH, prevParagraph)
7082
+ },
7083
+ 1,
7084
+ 0
7085
+ ), await commandService.executeCommand(InsertCommand.id, {
7086
+ unitId,
7087
+ body: bodyAfter,
7088
+ range: deleteRange,
7089
+ segmentId,
7090
+ cursorOffset: 1
7091
+ });
7260
7092
  }, "handler")
7261
7093
  }, CreateDocTableCommandId = "doc.command.create-table", CreateDocTableCommand = {
7262
7094
  id: CreateDocTableCommandId,
@@ -7759,7 +7591,7 @@ const getDisableWhenSelectionNotInTableObservable = /* @__PURE__ */ __name((acce
7759
7591
  }
7760
7592
  subscriber.next(!0);
7761
7593
  });
7762
- return () => observable.unsubscribe();
7594
+ return subscriber.next(!0), () => observable.unsubscribe();
7763
7595
  });
7764
7596
  }, "getDisableWhenSelectionNotInTableObservable"), CopyMenuFactory = /* @__PURE__ */ __name((accessor) => ({
7765
7597
  id: DocCopyCommand.name,
@@ -8792,7 +8624,7 @@ let DocBackScrollRenderController = (_a7 = class extends RxDisposable {
8792
8624
  if (!skeleton)
8793
8625
  return;
8794
8626
  const { startOffset } = range, anchorNodePosition = skeleton.findNodePositionByCharIndex(startOffset);
8795
- this.scrollToNode(anchorNodePosition);
8627
+ anchorNodePosition && this.scrollToNode(anchorNodePosition);
8796
8628
  }
8797
8629
  scrollToNode(startNodePosition) {
8798
8630
  var _a28;
@@ -10589,7 +10421,7 @@ const _DocPageLayoutService = class _DocPageLayoutService extends Disposable {
10589
10421
  return;
10590
10422
  const { width: engineWidth, height: engineHeight } = parent;
10591
10423
  let docsLeft = 0, docsTop = 0, sceneWidth = 0, sceneHeight = 0, scrollToX = Number.POSITIVE_INFINITY;
10592
- engineWidth > (docsWidth + pageMarginLeft * 2) * zoomRatio ? (docsLeft = engineWidth / 2 - docsWidth * zoomRatio / 2, docsLeft /= zoomRatio, sceneWidth = (engineWidth - pageMarginLeft * 2) / zoomRatio, scrollToX = 0) : (docsLeft = pageMarginLeft, sceneWidth = docsWidth + pageMarginLeft * 2, scrollToX = (sceneWidth - engineWidth / zoomRatio) / 2), engineHeight > docsHeight ? (docsTop = engineHeight / 2 - docsHeight / 2, sceneHeight = (engineHeight - pageMarginTop * 2) / zoomRatio) : (docsTop = pageMarginTop, sceneHeight = docsHeight + pageMarginTop * 2), scene.resize(sceneWidth, sceneHeight + 200), engineWidth <= 1 && (docsLeft = Number.POSITIVE_INFINITY, docsTop = Number.POSITIVE_INFINITY), docsComponent.translate(docsLeft, docsTop), docBackground.translate(docsLeft, docsTop);
10424
+ engineWidth > (docsWidth + pageMarginLeft * 2) * zoomRatio ? (docsLeft = engineWidth / 2 - docsWidth * zoomRatio / 2, docsLeft /= zoomRatio, sceneWidth = (engineWidth - pageMarginLeft * 2) / zoomRatio, scrollToX = 0) : (docsLeft = pageMarginLeft, sceneWidth = docsWidth + pageMarginLeft * 2, scrollToX = (sceneWidth - engineWidth / zoomRatio) / 2), engineHeight > docsHeight ? (docsTop = engineHeight / 2 - docsHeight / 2, sceneHeight = (engineHeight - pageMarginTop * 2) / zoomRatio) : (docsTop = pageMarginTop, sceneHeight = docsHeight + pageMarginTop * 2), scene.resize(sceneWidth, sceneHeight + 200), engineWidth <= 1 && (docsLeft = -1e4, docsTop = -1e4), docsComponent.translate(docsLeft, docsTop), docBackground.translate(docsLeft, docsTop);
10593
10425
  const viewport = scene.getViewport(VIEWPORT_KEY.VIEW_MAIN);
10594
10426
  return scrollToX !== Number.POSITIVE_INFINITY && viewport != null && viewport.scrollToViewportPos({
10595
10427
  viewportScrollX: scrollToX
@@ -1,4 +1,4 @@
1
- import { PresetListType, ICommand, IParagraph, IParagraphRange, ISectionBreak } from '@univerjs/core';
1
+ import { ICommand, IParagraph, IParagraphRange, ISectionBreak, PresetListType } from '@univerjs/core';
2
2
  import { ITextRangeWithStyle } from '@univerjs/engine-render';
3
3
  interface IListOperationCommandParams {
4
4
  listType: PresetListType;
@@ -18,4 +18,7 @@ export interface IRangeSelectorProps {
18
18
  onSelectorVisibleChange?: (visible: boolean) => void;
19
19
  dialogOnly?: boolean;
20
20
  }
21
+ /**
22
+ * @deprecated
23
+ */
21
24
  export declare function RangeSelector(props: IRangeSelectorProps): React.JSX.Element;
@@ -1,6 +1,6 @@
1
- import { Disposable, ICommandService, IUniverInstanceService, DocumentDataModel } from '@univerjs/core';
2
- import { DocSelectionManagerService, DocSkeletonManagerService } from '@univerjs/docs';
1
+ import { DocumentDataModel, Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
3
2
  import { IRenderContext, IRenderModule } from '@univerjs/engine-render';
3
+ import { DocSelectionManagerService, DocSkeletonManagerService } from '@univerjs/docs';
4
4
  import { IEditorService } from '../../services/editor/editor-manager.service';
5
5
  import { DocSelectionRenderService } from '../../services/selection/doc-selection-render.service';
6
6
  export declare class DocSelectionRenderController extends Disposable implements IRenderModule {
@@ -1,4 +1,4 @@
1
- import { Disposable, DocumentDataModel } from '@univerjs/core';
1
+ import { DocumentDataModel, Disposable } from '@univerjs/core';
2
2
  import { IRenderContext, IRenderModule } from '@univerjs/engine-render';
3
3
  export declare class DocPageLayoutService extends Disposable implements IRenderModule {
4
4
  private _context;