Skip to content

Commit

Permalink
feat: update prosemirror dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s committed Jun 1, 2022
1 parent 45868e2 commit 5bfb813
Show file tree
Hide file tree
Showing 21 changed files with 1,490 additions and 1,803 deletions.
3,152 changes: 1,432 additions & 1,720 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 8 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@
"@floating-ui/dom": "^0.5.2",
"@types/jasmine": "~3.10.0",
"@types/node": "^12.11.1",
"@types/prosemirror-commands": "^1.0.4",
"@types/prosemirror-history": "^1.0.3",
"@types/prosemirror-inputrules": "^1.0.4",
"@types/prosemirror-keymap": "^1.0.4",
"@types/prosemirror-model": "^1.16.2",
"@types/prosemirror-schema-list": "^1.0.3",
"@types/prosemirror-state": "^1.3.0",
"@types/prosemirror-view": "^1.23.1",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"docsify-cli": "^4.4.4",
Expand All @@ -87,14 +79,14 @@
"ng-packagr": "^13.0.0",
"prettier": "^2.6.2",
"prosemirror-codemirror-6": "^0.2.0",
"prosemirror-commands": "^1.2.2",
"prosemirror-history": "^1.2.0",
"prosemirror-inputrules": "^1.1.3",
"prosemirror-keymap": "^1.1.5",
"prosemirror-model": "^1.16.1",
"prosemirror-schema-list": "^1.1.6",
"prosemirror-state": "^1.3.4",
"prosemirror-view": "^1.23.13",
"prosemirror-commands": "^1.3.0",
"prosemirror-history": "^1.3.0",
"prosemirror-inputrules": "^1.2.0",
"prosemirror-keymap": "^1.2.0",
"prosemirror-model": "^1.17.0",
"prosemirror-schema-list": "^1.2.0",
"prosemirror-state": "^1.4.0",
"prosemirror-view": "^1.24.1",
"typescript": "~4.5.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ export class CustomMenuComponent implements OnInit {
const { schema } = state;

if (this.isActive) {
return setBlockType(schema.nodes.paragraph)(state, dispatch);
return setBlockType(schema.nodes['paragraph'])(state, dispatch);
}

return setBlockType(schema.nodes.code_mirror)(state, dispatch);
return setBlockType(schema.nodes['code_mirror'])(state, dispatch);
}

update = (view: EditorView):void => {
const { state } = view;
const { schema } = state;
this.isActive = isNodeActive(state, schema.nodes.code_mirror);
this.isActive = isNodeActive(state, schema.nodes['code_mirror']);
this.isDisabled = !this.execute(state, null); // returns true if executable
};

Expand Down
3 changes: 1 addition & 2 deletions projects/ngx-editor/commands/applyMark.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { MarkType } from 'prosemirror-model';
import { Command } from 'prosemirror-commands';
import { EditorState, TextSelection, Transaction } from 'prosemirror-state';
import { EditorState, TextSelection, Transaction, type Command } from 'prosemirror-state';

import { markApplies } from 'ngx-editor/helpers';

Expand Down
3 changes: 1 addition & 2 deletions projects/ngx-editor/commands/removeLink.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Command } from 'prosemirror-commands';
import { EditorState, Transaction } from 'prosemirror-state';
import { EditorState, Transaction, type Command } from 'prosemirror-state';

export const removeLink = (): Command => {
return (state: EditorState, dispatch?: (tr: Transaction) => void): boolean => {
Expand Down
3 changes: 1 addition & 2 deletions projects/ngx-editor/commands/removeMark.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { MarkType } from 'prosemirror-model';
import { EditorState, TextSelection, Transaction } from 'prosemirror-state';
import { EditorState, TextSelection, Transaction, type Command } from 'prosemirror-state';

import { markApplies } from 'ngx-editor/helpers';
import { Command } from 'prosemirror-commands';

export const removeMark = (type: MarkType): Command => {
return (state: EditorState, dispatch?: (tr: Transaction) => void): boolean => {
Expand Down
4 changes: 2 additions & 2 deletions projects/ngx-editor/helpers/getSelectionMarks.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { EditorState } from 'prosemirror-state';
import { Mark } from 'prosemirror-model';

export const getSelectionMarks = (state: EditorState): Mark[] => {
let marks: Mark[] = [];
export const getSelectionMarks = (state: EditorState): readonly Mark[] => {
let marks: readonly Mark[] = [];

const { selection, storedMarks } = state;
const { from, to, empty, $from } = selection;
Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-editor/helpers/markApplies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MarkType, Node as PrmosemirroNode } from 'prosemirror-model';
import { SelectionRange } from 'prosemirror-state';

// Ref: https://github.com/ProseMirror/prosemirror-commands/blob/master/src/commands.js
export const markApplies = (doc: PrmosemirroNode, ranges: SelectionRange[], type: MarkType): boolean => {
export const markApplies = (doc: PrmosemirroNode, ranges: readonly SelectionRange[], type: MarkType): boolean => {
for (const range of ranges) {
const { $from, $to } = range;

Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-editor/input-rules/auto-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const autoLink = (): InputRule => {
const { schema } = state;

const tr = state.tr.insertText(match[0], start, end); // Replace existing text with entire match
const mark = schema.marks.link.create({ href: match[0] });
const mark = schema.marks['link'].create({ href: match[0] });

return tr.addMark(start, start + match[0].length, mark);
});
Expand Down
24 changes: 8 additions & 16 deletions projects/ngx-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,14 @@
"dependencies": {
"@floating-ui/core": "^0.7.0",
"@floating-ui/dom": "^0.5.0",
"@types/prosemirror-commands": "1.0.4",
"@types/prosemirror-history": "1.0.3",
"@types/prosemirror-inputrules":"1.0.4",
"@types/prosemirror-keymap": "1.0.4",
"@types/prosemirror-model": "1.16.1",
"@types/prosemirror-schema-list": "1.0.3",
"@types/prosemirror-state": "1.2.8",
"@types/prosemirror-view": "1.23.1",
"prosemirror-commands": "^1.2.2",
"prosemirror-history": "^1.2.0",
"prosemirror-inputrules":"^1.1.3",
"prosemirror-keymap": "^1.1.5",
"prosemirror-model": "^1.16.1",
"prosemirror-schema-list": "^1.1.6",
"prosemirror-state": "^1.3.4",
"prosemirror-view": "^1.23.12",
"prosemirror-commands": "^1.3.0",
"prosemirror-history": "^1.3.0",
"prosemirror-inputrules":"^1.2.0",
"prosemirror-keymap": "^1.2.0",
"prosemirror-model": "^1.17.0",
"prosemirror-schema-list": "^1.2.0",
"prosemirror-state": "^1.4.0",
"prosemirror-view": "^1.24.1",
"tslib": "^2.3.0"
}
}
8 changes: 4 additions & 4 deletions projects/ngx-editor/src/lib/commands/Blockquote.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { NodeType } from 'prosemirror-model';
import type { EditorState, Transaction } from 'prosemirror-state';
import { type Command, lift, wrapIn } from 'prosemirror-commands';
import type { EditorState, Transaction, Command } from 'prosemirror-state';
import { lift, wrapIn } from 'prosemirror-commands';

import { isNodeActive } from 'ngx-editor/helpers';

Expand All @@ -9,7 +9,7 @@ class Blockqote {
return (state: EditorState, dispatch?: (tr: Transaction) => void): boolean => {
const { schema } = state;

const type: NodeType = schema.nodes.blockquote;
const type: NodeType = schema.nodes['blockquote'];
if (!type) {
return false;
}
Expand All @@ -25,7 +25,7 @@ class Blockqote {
isActive(state: EditorState): boolean {
const { schema } = state;

const type: NodeType = schema.nodes.blockquote;
const type: NodeType = schema.nodes['blockquote'];
if (!type) {
return false;
}
Expand Down
16 changes: 8 additions & 8 deletions projects/ngx-editor/src/lib/commands/Heading.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { NodeType, Node as ProseMirrorNode } from 'prosemirror-model';
import type { EditorState, Transaction } from 'prosemirror-state';
import { type Command, setBlockType } from 'prosemirror-commands';
import type { EditorState, Transaction, Command } from 'prosemirror-state';
import { setBlockType } from 'prosemirror-commands';

import { getSelectionNodes } from 'ngx-editor/helpers';

Expand All @@ -17,7 +17,7 @@ class Heading {
return (state: EditorState, dispatch?: (tr: Transaction) => void): boolean => {
const { schema } = state;

const type: NodeType = schema.nodes.heading;
const type: NodeType = schema.nodes['heading'];
if (!type) {
return false;
}
Expand All @@ -30,7 +30,7 @@ class Heading {
return (state: EditorState, dispatch?: (tr: Transaction) => void): boolean => {
const { schema, selection, doc } = state;

const type: NodeType = schema.nodes.heading;
const type: NodeType = schema.nodes['heading'];
if (!type) {
return false;
}
Expand All @@ -41,7 +41,7 @@ class Heading {
const attrs = node?.attrs ?? {};

if (this.isActive(state)) {
return setBlockType(schema.nodes.paragraph, attrs)(state, dispatch);
return setBlockType(schema.nodes['paragraph'], attrs)(state, dispatch);
}

return setBlockType(type, { ...attrs, level: this.level })(state, dispatch);
Expand All @@ -52,15 +52,15 @@ class Heading {
const { schema } = state;
const nodesInSelection = getSelectionNodes(state);

const type: NodeType = schema.nodes.heading;
const type: NodeType = schema.nodes['heading'];
if (!type) {
return false;
}

const supportedNodes = [
type,
schema.nodes.text,
schema.nodes.blockquote,
schema.nodes['text'],
schema.nodes['blockquote'],
];

// heading is a text node
Expand Down
7 changes: 3 additions & 4 deletions projects/ngx-editor/src/lib/commands/HorizontalRule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { NodeType } from 'prosemirror-model';
import type { EditorState, Transaction } from 'prosemirror-state';
import type { Command } from 'prosemirror-commands';
import type { EditorState, Transaction, Command } from 'prosemirror-state';

import { canInsert } from 'ngx-editor/helpers';

Expand All @@ -9,7 +8,7 @@ class HorizontalRule {
return (state: EditorState, dispatch?: (tr: Transaction) => void): boolean => {
const { schema, tr } = state;

const type: NodeType = schema.nodes.horizontal_rule;
const type: NodeType = schema.nodes['horizontal_rule'];

if (!type) {
return false;
Expand All @@ -21,7 +20,7 @@ class HorizontalRule {
}

canExecute(state: EditorState): boolean {
return canInsert(state, state.schema.nodes.horizontal_rule);
return canInsert(state, state.schema.nodes['horizontal_rule']);
}
}

Expand Down
5 changes: 2 additions & 3 deletions projects/ngx-editor/src/lib/commands/Image.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { type EditorState, NodeSelection } from 'prosemirror-state';
import type { Command } from 'prosemirror-commands';
import { type EditorState, NodeSelection, type Command } from 'prosemirror-state';

import { Dispatch } from './types';

Expand All @@ -14,7 +13,7 @@ class Image {
return (state: EditorState, dispatch?: Dispatch): boolean => {
const { schema, tr, selection } = state;

const type = schema.nodes.image;
const type = schema.nodes['image'];
if (!type) {
return false;
}
Expand Down
12 changes: 6 additions & 6 deletions projects/ngx-editor/src/lib/commands/Link.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { MarkType } from 'prosemirror-model';
import type { EditorState } from 'prosemirror-state';
import { type Command, toggleMark } from 'prosemirror-commands';
import type { EditorState, Command } from 'prosemirror-state';
import { toggleMark } from 'prosemirror-commands';

import { isMarkActive } from 'ngx-editor/helpers';
import { removeLink } from 'ngx-editor/commands';
Expand All @@ -21,7 +21,7 @@ class Link {
return (state: EditorState, dispatch?: Dispatch): boolean => {
const { schema, selection } = state;

const type: MarkType = schema.marks.link;
const type: MarkType = schema.marks['link'];
if (!type) {
return false;
}
Expand All @@ -38,7 +38,7 @@ class Link {
return (state: EditorState, dispatch?: Dispatch): boolean => {
const { schema, tr } = state;

const type: MarkType = schema.marks.link;
const type: MarkType = schema.marks['link'];
if (!type) {
return false;
}
Expand All @@ -49,7 +49,7 @@ class Link {
target: attrs.target ?? '_blank',
};

const node = schema.text(text, [schema.marks.link.create(linkAttrs)]);
const node = schema.text(text, [schema.marks['link'].create(linkAttrs)]);

tr.replaceSelectionWith(node, false)
.scrollIntoView();
Expand All @@ -69,7 +69,7 @@ class Link {
}

const { schema } = state;
const type = schema.marks.link;
const type = schema.marks['link'];

if (!type) {
return false;
Expand Down
5 changes: 2 additions & 3 deletions projects/ngx-editor/src/lib/commands/ListItem.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { NodeType, Schema } from 'prosemirror-model';
import type { EditorState, Transaction } from 'prosemirror-state';
import type { EditorState, Transaction, Command } from 'prosemirror-state';
import { liftListItem, wrapInList } from 'prosemirror-schema-list';
import type { Command } from 'prosemirror-commands';

import { isNodeActive } from 'ngx-editor/helpers';

Expand All @@ -26,7 +25,7 @@ class ListItem {
}

if (this.isActive(state)) {
return liftListItem(schema.nodes.list_item)(state, dispatch);
return liftListItem(schema.nodes['list_item'])(state, dispatch);
}

return wrapInList(type)(state, dispatch);
Expand Down
4 changes: 2 additions & 2 deletions projects/ngx-editor/src/lib/commands/Mark.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { MarkType } from 'prosemirror-model';
import type { EditorState, Transaction } from 'prosemirror-state';
import { type Command, toggleMark } from 'prosemirror-commands';
import type { EditorState, Transaction, Command } from 'prosemirror-state';
import { toggleMark } from 'prosemirror-commands';

import { applyMark } from 'ngx-editor/commands';
import { isMarkActive } from 'ngx-editor/helpers';
Expand Down
5 changes: 2 additions & 3 deletions projects/ngx-editor/src/lib/commands/TextAlign.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { EditorState, Transaction } from 'prosemirror-state';
import type { EditorState, Transaction, Command } from 'prosemirror-state';
import type { Node } from 'prosemirror-model';
import type { Command } from 'prosemirror-commands';

import { getSelectionNodes } from 'ngx-editor/helpers';

Expand All @@ -22,7 +21,7 @@ class TextAlign {

doc.nodesBetween(from, to, (node, pos) => {
const nodeType = node.type;
if ([schema.nodes.paragraph, schema.nodes.heading].includes(nodeType)) {
if ([schema.nodes['paragraph'], schema.nodes['heading']].includes(nodeType)) {
applicable = true;
tr.setNodeMarkup(pos, nodeType, { ...node.attrs, align: this.align });
}
Expand Down
3 changes: 1 addition & 2 deletions projects/ngx-editor/src/lib/commands/TextColor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { MarkType } from 'prosemirror-model';
import type { EditorState } from 'prosemirror-state';
import type { Command } from 'prosemirror-commands';
import type { EditorState, Command } from 'prosemirror-state';

import { getSelectionMarks, isMarkActive } from 'ngx-editor/helpers';
import { applyMark, removeMark } from 'ngx-editor/commands';
Expand Down
3 changes: 1 addition & 2 deletions projects/ngx-editor/src/lib/commands/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { EditorState, Transaction } from 'prosemirror-state';
import { Command } from 'prosemirror-commands';
import type { EditorState, Transaction, Command } from 'prosemirror-state';

export type Dispatch = (tr: Transaction) => void | null;

Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-editor/src/lib/plugins/editable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const editablePlugin = (editable = true): Plugin => {
init(): boolean {
return editable;
},
apply(tr: Transaction, previousVal: boolean): string {
apply(tr: Transaction, previousVal: boolean): boolean {
return tr.getMeta('UPDATE_EDITABLE') ?? previousVal;
},
},
Expand Down

0 comments on commit 5bfb813

Please sign in to comment.