Skip to content

Commit

Permalink
refactor(angular-text): remove useless plugin(withInline) and rename …
Browse files Browse the repository at this point in the history
…withSelection to withInlineMove (#992)
  • Loading branch information
pubuzhixing8 authored Dec 3, 2024
1 parent 60a7c16 commit 71a1f32
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 77 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-bugs-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@plait/angular-text': minor
---

remove useless plugin(withInline) and rename withSelection to withInlineMove
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Editor, Element, Transforms, Range, Path } from 'slate';
import { AngularEditor, hotkeys } from 'slate-angular';

export const withSelection = <T extends AngularEditor>(editor: T): T => {
export const withInlineMove = <T extends AngularEditor>(editor: T): T => {
const { onKeydown } = editor;

editor.onKeydown = (event: KeyboardEvent) => {
Expand Down
66 changes: 0 additions & 66 deletions packages/angular-text/src/plugins/with-inline.ts

This file was deleted.

5 changes: 1 addition & 4 deletions packages/angular-text/src/plugins/with-text.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { PlaitBoard } from '@plait/core';
import { CLIPBOARD_FORMAT_KEY } from '@plait/text-plugins';
import { AngularEditor } from 'slate-angular';
import { PlaitTextEditor } from './text.editor';

export const withText = <T extends AngularEditor>(editor: T, board: PlaitBoard) => {
export const withText = <T extends AngularEditor>(editor: T) => {
const e = editor as T & PlaitTextEditor;
const { insertData } = e;

Expand All @@ -25,7 +24,5 @@ export const withText = <T extends AngularEditor>(editor: T, board: PlaitBoard)
insertData(data);
};

e.board = board;

return e;
};
8 changes: 3 additions & 5 deletions packages/angular-text/src/text/text.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { withHistory } from 'slate-history';
import { PlaitLinkNodeComponent } from '../plugins/link/link.component';
import { withMarkHotkey } from '../plugins/mark-hotkey/with-mark-hotkey';
import { ParagraphElementComponent } from '../plugins/paragraph/paragraph.component';
import { withSelection } from '../plugins/with-selection';
import { withInlineMove } from '../plugins/with-inline-move';
import { withText } from '../plugins/with-text';
import { PlaitTextNodeComponent } from '../text-node/text.component';
import { FormsModule } from '@angular/forms';
Expand Down Expand Up @@ -63,9 +63,7 @@ export class PlaitTextComponent implements OnInit, AfterViewInit, OnChanges {
@Input()
board!: PlaitBoard;

editor = withSelection(
withPasteLink(withMarkHotkey(withText(withHistory(withAngular(createEditor(), CLIPBOARD_FORMAT_KEY)), this.board)))
);
editor = withInlineMove(withPasteLink(withMarkHotkey(withText(withHistory(withAngular(createEditor(), CLIPBOARD_FORMAT_KEY))))));

nativeElement() {
return this.elementRef.nativeElement;
Expand Down Expand Up @@ -136,5 +134,5 @@ export class PlaitTextComponent implements OnInit, AfterViewInit, OnChanges {

scrollSelectionIntoView = () => {
// prevent auto scroll
}
};
}
2 changes: 1 addition & 1 deletion packages/text-plugins/src/link/with-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { LinkElement } from '@plait/common';
import { Element, NodeEntry, Transforms, Node, Editor } from 'slate';

export const withLink = <T extends Editor>(editor: T): T => {
const { isInline, normalizeNode, insertFragment } = editor;
const { isInline, normalizeNode } = editor;

editor.isInline = (element: Element) => {
return (element as LinkElement).type === 'link' ? true : isInline(element);
Expand Down

0 comments on commit 71a1f32

Please sign in to comment.