@textbus/xnote 0.0.6 → 0.0.8

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.
@@ -4,9 +4,16 @@ import { CollaborateConfig } from '@textbus/collaborate';
4
4
  import { Textbus, TextbusConfig } from '@textbus/core';
5
5
  import './assets/icons/style.css';
6
6
  import './textbus/doc.scss';
7
+ export interface XNoteCollaborateConfig extends CollaborateConfig {
8
+ userinfo: {
9
+ username: string;
10
+ color: string;
11
+ id: string;
12
+ };
13
+ }
7
14
  export interface EditorConfig extends TextbusConfig {
8
15
  content?: string;
9
- collaborateConfig?: CollaborateConfig;
16
+ collaborateConfig?: XNoteCollaborateConfig;
10
17
  viewOptions?: Partial<ViewOptions>;
11
18
  }
12
19
  export declare class Editor extends Textbus {
@@ -84,4 +84,4 @@
84
84
  <glyph unicode="&#xea7b;" glyph-name="indent-increase" d="M0 896.004h1024v-128h-1024zM384 704.004h640v-128h-640zM384 512.004h640v-128h-640zM384 320.004h640v-128h-640zM0 128.004h1024v-128h-1024zM0 256.004v384l256-192z" />
85
85
  <glyph unicode="&#xea7c;" glyph-name="indent-decrease" d="M0 896.004h1024v-128h-1024zM384 704.004h640v-128h-640zM384 512.004h640v-128h-640zM384 320.004h640v-128h-640zM0 128.004h1024v-128h-1024zM256 640.004v-384l-256 192z" />
86
86
  <glyph unicode="&#xea80;" glyph-name="code" horiz-adv-x="1280" d="M832 224l96-96 320 320-320 320-96-96 224-224zM448 672l-96 96-320-320 320-320 96 96-224 224zM701.298 809.481l69.468-18.944-191.987-704.026-69.468 18.944 191.987 704.026z" />
87
- </font></defs></svg>
87
+ </font></defs></svg>
@@ -10,7 +10,7 @@ import { v4 } from 'uuid';
10
10
  import Katex from 'katex';
11
11
  import { ViewflyAdapter, ViewflyVDomAdapter } from '@textbus/adapter-viewfly';
12
12
  import { any2Hsl, hsl2Rgb } from '@tanbo/color';
13
- import { CollaborateModule, UserActivity } from '@textbus/collaborate';
13
+ import { MessageBus, CollaborateModule } from '@textbus/collaborate';
14
14
 
15
15
  var scopedId$n = "vf-d94b56";
16
16
 
@@ -991,7 +991,8 @@ function ParagraphView(props) {
991
991
  }
992
992
  const paragraphComponentLoader = {
993
993
  match(element, returnableContentTypes) {
994
- return returnableContentTypes.includes(ContentType.BlockComponent) && (element.dataset.component === ParagraphComponent.componentName || /^P|H[1-6]$/.test(element.tagName));
994
+ return returnableContentTypes.includes(ContentType.BlockComponent) &&
995
+ (element.dataset.component === ParagraphComponent.componentName || /^P|H[1-6]$/.test(element.tagName));
995
996
  },
996
997
  read(element, textbus, slotParser) {
997
998
  let content;
@@ -6185,7 +6186,7 @@ let TableSelectionAwarenessDelegate = class TableSelectionAwarenessDelegate exte
6185
6186
  this.domAdapter = domAdapter;
6186
6187
  this.selection = selection;
6187
6188
  }
6188
- getRects(abstractSelection) {
6189
+ getRects(abstractSelection, _, data) {
6189
6190
  const { focusSlot, anchorSlot } = abstractSelection;
6190
6191
  const focusPaths = this.selection.getPathsBySlot(focusSlot);
6191
6192
  const anchorPaths = this.selection.getPathsBySlot(anchorSlot);
@@ -6204,7 +6205,7 @@ let TableSelectionAwarenessDelegate = class TableSelectionAwarenessDelegate exte
6204
6205
  if (!(commonAncestorComponent instanceof TableComponent)) {
6205
6206
  return false;
6206
6207
  }
6207
- const rect = commonAncestorComponent.getMaxRectangle(findFocusCell(commonAncestorComponent, startSlot), findFocusCell(commonAncestorComponent, endSlot));
6208
+ const rect = data.data || commonAncestorComponent.getMaxRectangle(findFocusCell(commonAncestorComponent, startSlot), findFocusCell(commonAncestorComponent, endSlot));
6208
6209
  const renderer = this.domAdapter;
6209
6210
  if (!rect) {
6210
6211
  return false;
@@ -6338,6 +6339,30 @@ const stepComponentLoader = {
6338
6339
  }
6339
6340
  };
6340
6341
 
6342
+ class XNoteMessageBug extends MessageBus {
6343
+ constructor(selection, collaborateCursor, userinfo) {
6344
+ super();
6345
+ this.selection = selection;
6346
+ this.collaborateCursor = collaborateCursor;
6347
+ this.userinfo = userinfo;
6348
+ this.messageChangeEvent = new Subject();
6349
+ this.onMessageChange = this.messageChangeEvent.asObservable();
6350
+ }
6351
+ get() {
6352
+ const selection = this.selection;
6353
+ const c = selection.commonAncestorComponent;
6354
+ return Object.assign(Object.assign({}, this.userinfo), { selection: selection.getPaths(), data: (!selection.isCollapsed && c instanceof TableComponent) ? c.getSelectedRect() : null });
6355
+ }
6356
+ consume(message) {
6357
+ this.messageChangeEvent.next([...message]);
6358
+ this.collaborateCursor.draw(message.filter(item => {
6359
+ return item.message.id !== this.userinfo.id;
6360
+ }).map(item => {
6361
+ return item.message;
6362
+ }));
6363
+ }
6364
+ }
6365
+
6341
6366
  class Editor extends Textbus {
6342
6367
  constructor(editorConfig = {}) {
6343
6368
  const adapter = new ViewflyAdapter({
@@ -6403,9 +6428,20 @@ class Editor extends Textbus {
6403
6428
  const modules = [browserModule];
6404
6429
  if (editorConfig.collaborateConfig) {
6405
6430
  modules.push(new CollaborateModule(editorConfig.collaborateConfig));
6406
- browserModule.providers.push({
6407
- provide: CollaborateSelectionAwarenessDelegate,
6408
- useClass: TableSelectionAwarenessDelegate
6431
+ modules.push({
6432
+ providers: [{
6433
+ provide: CollaborateSelectionAwarenessDelegate,
6434
+ useClass: TableSelectionAwarenessDelegate
6435
+ }, {
6436
+ provide: MessageBus,
6437
+ useFactory: (selection, collaborateCursor) => {
6438
+ return new XNoteMessageBug(selection, collaborateCursor, editorConfig.collaborateConfig.userinfo);
6439
+ },
6440
+ deps: [
6441
+ Selection,
6442
+ CollaborateCursor
6443
+ ]
6444
+ }]
6409
6445
  });
6410
6446
  }
6411
6447
  const vDomAdapter = new ViewflyVDomAdapter({
@@ -6475,19 +6511,7 @@ class Editor extends Textbus {
6475
6511
  ], plugins: [
6476
6512
  new LeftToolbarPlugin(),
6477
6513
  new ToolbarPlugin(),
6478
- ], setup(textbus) {
6479
- if (editorConfig.collaborateConfig) {
6480
- const activity = textbus.get(UserActivity);
6481
- const collabCursor = textbus.get(CollaborateCursor);
6482
- const sub = activity.onStateChange.subscribe(ev => {
6483
- collabCursor.draw(ev);
6484
- });
6485
- return () => {
6486
- sub.unsubscribe();
6487
- };
6488
- }
6489
- },
6490
- onAfterStartup(textbus) {
6514
+ ], onAfterStartup(textbus) {
6491
6515
  registerBoldShortcut(textbus);
6492
6516
  registerCodeShortcut(textbus);
6493
6517
  registerItalicShortcut(textbus);
@@ -6540,4 +6564,4 @@ class Editor extends Textbus {
6540
6564
  }
6541
6565
  }
6542
6566
 
6543
- export { AtComponent, AtComponentView, AttrTool, BlockTool, BlockquoteComponent, BlockquoteView, BoldTool, Button, CellAlignTool, CellBackgroundTool, CodeTool, ColorTool, ComponentToolbar, Divider, DragResize, Dropdown, DropdownContextService, DropdownMenuPortal, DropdownService, Editor, EditorService, FileUploader, FontFamilyTool, FontSizeTool, HighlightBoxComponent, HighlightBoxView, ImageComponent, ImageView, InsertTool, ItalicTool, KatexComponent, KatexComponentView, Keymap, LeftToolbar, LeftToolbarPlugin, LinkJump, LinkTool, ListComponent, ListComponentView, Matcher, MenuHeading, MenuItem, MergeCellsTool, Organization, OutputInjectionToken, ParagraphComponent, ParagraphView, Popup, RefreshService, RootComponent, RootView, SourceCodeComponent, SourceCodeView, SplitCellsTool, StrikeThroughTool, TableComponent, TableComponentView, TodolistComponent, TodolistView, Toolbar, ToolbarItem, ToolbarPlugin, UnderlineTool, VideoComponent, VideoView, atComponentLoader, backgroundColorFormatLoader, backgroundColorFormatter, blockquoteComponentLoader, boldFormatLoader, boldFormatter, cellAlignAttr, cellAlignAttrLoader, codeFormatLoader, codeFormatter, colorFormatLoader, colorFormatter, deltaToBlock, fontFamilyFormatLoader, fontFamilyFormatter, fontSizeFormatLoader, fontSizeFormatter, headingAttr, headingAttrLoader, highlightBoxComponentLoader, imageComponentLoader, isSupportFont, italicFormatLoader, italicFormatter, katexComponentLoader, languageList, linkFormatLoader, linkFormatter, listComponentLoader, paragraphComponentLoader, registerAtShortcut, registerBlockquoteShortcut, registerBoldShortcut, registerCodeShortcut, registerHeadingShortcut, registerItalicShortcut, registerListShortcut, registerStrikeThroughShortcut, registerTextAlignShortcut, registerTextIndentShortcut, registerUnderlineShortcut, rootComponentLoader, sourceCodeComponentLoader, sourceCodeThemes, strikeThroughFormatLoader, strikeThroughFormatter, tableComponentLoader, textAlignAttr, textAlignAttrLoader, textIndentAttr, textIndentAttrLoader, toBlockquote, toList, todolistComponentLoader, toggleBold, toggleCode, toggleItalic, toggleStrikeThrough, toggleUnderline, underlineFormatLoader, underlineFormatter, useActiveBlock, useBlockContent, useBlockTransform, useOutput, useReadonly, videoComponentLoader };
6567
+ export { AtComponent, AtComponentView, AttrTool, BlockTool, BlockquoteComponent, BlockquoteView, BoldTool, Button, CellAlignTool, CellBackgroundTool, CodeTool, ColorTool, ComponentToolbar, Divider, DragResize, Dropdown, DropdownContextService, DropdownMenuPortal, DropdownService, Editor, EditorService, FileUploader, FontFamilyTool, FontSizeTool, HighlightBoxComponent, HighlightBoxView, ImageComponent, ImageView, InsertTool, ItalicTool, KatexComponent, KatexComponentView, Keymap, LeftToolbar, LeftToolbarPlugin, LinkJump, LinkTool, ListComponent, ListComponentView, Matcher, MenuHeading, MenuItem, MergeCellsTool, Organization, OutputInjectionToken, ParagraphComponent, ParagraphView, Popup, RefreshService, RootComponent, RootView, SourceCodeComponent, SourceCodeView, SplitCellsTool, StrikeThroughTool, TableComponent, TableComponentView, TodolistComponent, TodolistView, Toolbar, ToolbarItem, ToolbarPlugin, UnderlineTool, VideoComponent, VideoView, XNoteMessageBug, atComponentLoader, backgroundColorFormatLoader, backgroundColorFormatter, blockquoteComponentLoader, boldFormatLoader, boldFormatter, cellAlignAttr, cellAlignAttrLoader, codeFormatLoader, codeFormatter, colorFormatLoader, colorFormatter, deltaToBlock, fontFamilyFormatLoader, fontFamilyFormatter, fontSizeFormatLoader, fontSizeFormatter, headingAttr, headingAttrLoader, highlightBoxComponentLoader, imageComponentLoader, isSupportFont, italicFormatLoader, italicFormatter, katexComponentLoader, languageList, linkFormatLoader, linkFormatter, listComponentLoader, paragraphComponentLoader, registerAtShortcut, registerBlockquoteShortcut, registerBoldShortcut, registerCodeShortcut, registerHeadingShortcut, registerItalicShortcut, registerListShortcut, registerStrikeThroughShortcut, registerTextAlignShortcut, registerTextIndentShortcut, registerUnderlineShortcut, rootComponentLoader, sourceCodeComponentLoader, sourceCodeThemes, strikeThroughFormatLoader, strikeThroughFormatter, tableComponentLoader, textAlignAttr, textAlignAttrLoader, textIndentAttr, textIndentAttrLoader, toBlockquote, toList, todolistComponentLoader, toggleBold, toggleCode, toggleItalic, toggleStrikeThrough, toggleUnderline, underlineFormatLoader, underlineFormatter, useActiveBlock, useBlockContent, useBlockTransform, useOutput, useReadonly, videoComponentLoader };
package/bundles/index.js CHANGED
@@ -993,7 +993,8 @@ function ParagraphView(props) {
993
993
  }
994
994
  const paragraphComponentLoader = {
995
995
  match(element, returnableContentTypes) {
996
- return returnableContentTypes.includes(core$1.ContentType.BlockComponent) && (element.dataset.component === ParagraphComponent.componentName || /^P|H[1-6]$/.test(element.tagName));
996
+ return returnableContentTypes.includes(core$1.ContentType.BlockComponent) &&
997
+ (element.dataset.component === ParagraphComponent.componentName || /^P|H[1-6]$/.test(element.tagName));
997
998
  },
998
999
  read(element, textbus, slotParser) {
999
1000
  let content;
@@ -6187,7 +6188,7 @@ let TableSelectionAwarenessDelegate = class TableSelectionAwarenessDelegate exte
6187
6188
  this.domAdapter = domAdapter;
6188
6189
  this.selection = selection;
6189
6190
  }
6190
- getRects(abstractSelection) {
6191
+ getRects(abstractSelection, _, data) {
6191
6192
  const { focusSlot, anchorSlot } = abstractSelection;
6192
6193
  const focusPaths = this.selection.getPathsBySlot(focusSlot);
6193
6194
  const anchorPaths = this.selection.getPathsBySlot(anchorSlot);
@@ -6206,7 +6207,7 @@ let TableSelectionAwarenessDelegate = class TableSelectionAwarenessDelegate exte
6206
6207
  if (!(commonAncestorComponent instanceof TableComponent)) {
6207
6208
  return false;
6208
6209
  }
6209
- const rect = commonAncestorComponent.getMaxRectangle(findFocusCell(commonAncestorComponent, startSlot), findFocusCell(commonAncestorComponent, endSlot));
6210
+ const rect = data.data || commonAncestorComponent.getMaxRectangle(findFocusCell(commonAncestorComponent, startSlot), findFocusCell(commonAncestorComponent, endSlot));
6210
6211
  const renderer = this.domAdapter;
6211
6212
  if (!rect) {
6212
6213
  return false;
@@ -6340,6 +6341,30 @@ const stepComponentLoader = {
6340
6341
  }
6341
6342
  };
6342
6343
 
6344
+ class XNoteMessageBug extends collaborate.MessageBus {
6345
+ constructor(selection, collaborateCursor, userinfo) {
6346
+ super();
6347
+ this.selection = selection;
6348
+ this.collaborateCursor = collaborateCursor;
6349
+ this.userinfo = userinfo;
6350
+ this.messageChangeEvent = new core$1.Subject();
6351
+ this.onMessageChange = this.messageChangeEvent.asObservable();
6352
+ }
6353
+ get() {
6354
+ const selection = this.selection;
6355
+ const c = selection.commonAncestorComponent;
6356
+ return Object.assign(Object.assign({}, this.userinfo), { selection: selection.getPaths(), data: (!selection.isCollapsed && c instanceof TableComponent) ? c.getSelectedRect() : null });
6357
+ }
6358
+ consume(message) {
6359
+ this.messageChangeEvent.next([...message]);
6360
+ this.collaborateCursor.draw(message.filter(item => {
6361
+ return item.message.id !== this.userinfo.id;
6362
+ }).map(item => {
6363
+ return item.message;
6364
+ }));
6365
+ }
6366
+ }
6367
+
6343
6368
  class Editor extends core$1.Textbus {
6344
6369
  constructor(editorConfig = {}) {
6345
6370
  const adapter = new adapterViewfly.ViewflyAdapter({
@@ -6405,9 +6430,20 @@ class Editor extends core$1.Textbus {
6405
6430
  const modules = [browserModule];
6406
6431
  if (editorConfig.collaborateConfig) {
6407
6432
  modules.push(new collaborate.CollaborateModule(editorConfig.collaborateConfig));
6408
- browserModule.providers.push({
6409
- provide: platformBrowser.CollaborateSelectionAwarenessDelegate,
6410
- useClass: TableSelectionAwarenessDelegate
6433
+ modules.push({
6434
+ providers: [{
6435
+ provide: platformBrowser.CollaborateSelectionAwarenessDelegate,
6436
+ useClass: TableSelectionAwarenessDelegate
6437
+ }, {
6438
+ provide: collaborate.MessageBus,
6439
+ useFactory: (selection, collaborateCursor) => {
6440
+ return new XNoteMessageBug(selection, collaborateCursor, editorConfig.collaborateConfig.userinfo);
6441
+ },
6442
+ deps: [
6443
+ core$1.Selection,
6444
+ platformBrowser.CollaborateCursor
6445
+ ]
6446
+ }]
6411
6447
  });
6412
6448
  }
6413
6449
  const vDomAdapter = new adapterViewfly.ViewflyVDomAdapter({
@@ -6477,19 +6513,7 @@ class Editor extends core$1.Textbus {
6477
6513
  ], plugins: [
6478
6514
  new LeftToolbarPlugin(),
6479
6515
  new ToolbarPlugin(),
6480
- ], setup(textbus) {
6481
- if (editorConfig.collaborateConfig) {
6482
- const activity = textbus.get(collaborate.UserActivity);
6483
- const collabCursor = textbus.get(platformBrowser.CollaborateCursor);
6484
- const sub = activity.onStateChange.subscribe(ev => {
6485
- collabCursor.draw(ev);
6486
- });
6487
- return () => {
6488
- sub.unsubscribe();
6489
- };
6490
- }
6491
- },
6492
- onAfterStartup(textbus) {
6516
+ ], onAfterStartup(textbus) {
6493
6517
  registerBoldShortcut(textbus);
6494
6518
  registerCodeShortcut(textbus);
6495
6519
  registerItalicShortcut(textbus);
@@ -6603,6 +6627,7 @@ exports.ToolbarPlugin = ToolbarPlugin;
6603
6627
  exports.UnderlineTool = UnderlineTool;
6604
6628
  exports.VideoComponent = VideoComponent;
6605
6629
  exports.VideoView = VideoView;
6630
+ exports.XNoteMessageBug = XNoteMessageBug;
6606
6631
  exports.atComponentLoader = atComponentLoader;
6607
6632
  exports.backgroundColorFormatLoader = backgroundColorFormatLoader;
6608
6633
  exports.backgroundColorFormatter = backgroundColorFormatter;
@@ -4,3 +4,4 @@ export * from './services/_api';
4
4
  export * from './textbus/_api';
5
5
  export * from './interfaces';
6
6
  export * from './editor';
7
+ export * from './xnote-message-bus';
@@ -1,4 +1,4 @@
1
- import { CollaborateSelectionAwarenessDelegate, DomAdapter } from '@textbus/platform-browser';
1
+ import { CollaborateSelectionAwarenessDelegate, DomAdapter, UserSelectionCursor } from '@textbus/platform-browser';
2
2
  import { AbstractSelection, Slot, Selection } from '@textbus/core';
3
3
  import { TableComponent } from './table.component';
4
4
  export declare function findFocusCell(table: TableComponent, slot: Slot): Slot | null;
@@ -6,7 +6,7 @@ export declare class TableSelectionAwarenessDelegate extends CollaborateSelectio
6
6
  private domAdapter;
7
7
  private selection;
8
8
  constructor(domAdapter: DomAdapter, selection: Selection);
9
- getRects(abstractSelection: AbstractSelection): false | {
9
+ getRects(abstractSelection: AbstractSelection, _: any, data: UserSelectionCursor): false | {
10
10
  left: number;
11
11
  top: number;
12
12
  width: number;
@@ -0,0 +1,21 @@
1
+ import { Observable, Selection, Subject } from '@textbus/core';
2
+ import { CollaborateCursor, UserSelectionCursor } from '@textbus/platform-browser';
3
+ import { Message, MessageBus } from '@textbus/collaborate';
4
+ export interface UserInfo {
5
+ username: string;
6
+ color: string;
7
+ id: string;
8
+ }
9
+ export interface XNoteMessage extends UserSelectionCursor {
10
+ id: string;
11
+ }
12
+ export declare class XNoteMessageBug extends MessageBus<XNoteMessage> {
13
+ private selection;
14
+ private collaborateCursor;
15
+ private userinfo;
16
+ onMessageChange: Observable<Message<XNoteMessage>[]>;
17
+ protected messageChangeEvent: Subject<Message<XNoteMessage>[]>;
18
+ constructor(selection: Selection, collaborateCursor: CollaborateCursor, userinfo: UserInfo);
19
+ get(): XNoteMessage;
20
+ consume(message: Message<XNoteMessage>[]): void;
21
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textbus/xnote",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "A high-performance rich text editor that supports multiplayer online collaboration.",
5
5
  "main": "./bundles/index.js",
6
6
  "module": "./bundles/index.esm.js",
@@ -27,10 +27,10 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@tanbo/color": "^0.1.1",
30
- "@textbus/adapter-viewfly": "^4.1.0",
31
- "@textbus/collaborate": "^4.1.0",
32
- "@textbus/core": "^4.1.0",
33
- "@textbus/platform-browser": "^4.1.0",
30
+ "@textbus/adapter-viewfly": "^4.2.0",
31
+ "@textbus/collaborate": "^4.2.0",
32
+ "@textbus/core": "^4.2.0",
33
+ "@textbus/platform-browser": "^4.2.0",
34
34
  "@viewfly/core": "^1.0.5",
35
35
  "@viewfly/hooks": "^1.0.5",
36
36
  "@viewfly/platform-browser": "^1.0.5",