Skip to content

Commit

Permalink
feat: upgrade to latest tiptap, pm type import from tiptap/pm
Browse files Browse the repository at this point in the history
  • Loading branch information
Leecason committed Oct 26, 2023
1 parent d96dcea commit bcfdf40
Show file tree
Hide file tree
Showing 8 changed files with 361 additions and 43 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"@tiptap/extension-text-align": "^2.0.0-beta.29",
"@tiptap/extension-text-style": "^2.0.0-beta.23",
"@tiptap/extension-underline": "^2.0.0-beta.22",
"@tiptap/vue-3": "^2.0.0-beta.90",
"@tiptap/pm": "^2.1.12",
"@tiptap/vue-3": "^2.1.12",
"core-js": "^3.4.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/MenuBubble/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import { defineComponent, inject } from 'vue';
import { Editor, BubbleMenu } from '@tiptap/vue-3';
import { getMarkRange } from '@tiptap/core';
import { TextSelection, AllSelection, Selection } from 'prosemirror-state';
import { TextSelection, AllSelection, Selection } from '@tiptap/pm/state';
import VIcon from '../Icon/Icon.vue';
import LinkBubbleMenu from './LinkBubbleMenu.vue';
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/link.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getMarkRange } from '@tiptap/core';
import type { Editor } from '@tiptap/core';
import TiptapLink from '@tiptap/extension-link';
import { Plugin, TextSelection } from 'prosemirror-state';
import { EditorView } from 'prosemirror-view';
import { Plugin, TextSelection } from '@tiptap/pm/state';
import { EditorView } from '@tiptap/pm/view';
import AddLinkCommandButton from '@/components/MenuCommands/Link/AddLinkCommandButton.vue';

const Link = TiptapLink.extend({
Expand Down
2 changes: 1 addition & 1 deletion src/utils/indent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Command, Editor } from '@tiptap/core';
import { isList } from '@tiptap/core';
import { TextSelection, AllSelection, Transaction } from 'prosemirror-state';
import { TextSelection, AllSelection, Transaction } from '@tiptap/pm/state';
import { clamp } from './shared';

export const enum IndentProps {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/line-height.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
AllSelection,
EditorState,
Transaction,
} from 'prosemirror-state';
import { Node as ProsemirrorNode, NodeType } from 'prosemirror-model';
} from '@tiptap/pm/state';
import { Node as ProsemirrorNode, NodeType } from '@tiptap/pm/model';
import { LINE_HEIGHT_100, DEFAULT_LINE_HEIGHT } from '@/constants';
import type { Command } from '@tiptap/core';

Expand Down
20 changes: 13 additions & 7 deletions src/utils/print.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { EditorView } from 'prosemirror-view';
import { EditorView } from '@tiptap/pm/view';
import Logger from './logger';

function printHtml(dom: Element) {
const style :string = Array.from(document.querySelectorAll('style, link'))
.reduce((str, style) => str + style.outerHTML, '');
const style: string = Array.from(
document.querySelectorAll('style, link')
).reduce((str, style) => str + style.outerHTML, '');

const content: string = style + dom.outerHTML;

const iframe: HTMLIFrameElement = document.createElement('iframe');
iframe.id = 'el-tiptap-iframe';
iframe.setAttribute('style', 'position: absolute; width: 0; height: 0; top: -10px; left: -10px;');
iframe.setAttribute(
'style',
'position: absolute; width: 0; height: 0; top: -10px; left: -10px;'
);
document.body.appendChild(iframe);

const frameWindow = iframe.contentWindow;
const doc = iframe.contentDocument || (iframe.contentWindow && iframe.contentWindow.document);
const doc =
iframe.contentDocument ||
(iframe.contentWindow && iframe.contentWindow.document);

if (doc) {
doc.open();
Expand All @@ -22,7 +28,7 @@ function printHtml(dom: Element) {
}

if (frameWindow) {
iframe.onload = function() {
iframe.onload = function () {
try {
setTimeout(() => {
frameWindow.focus();
Expand All @@ -39,7 +45,7 @@ function printHtml(dom: Element) {
Logger.error(err);
}

setTimeout(function() {
setTimeout(function () {
document.body.removeChild(iframe);
}, 100);
};
Expand Down
9 changes: 6 additions & 3 deletions src/utils/table.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mergeCells, splitCell } from 'prosemirror-tables';
import { EditorState } from 'prosemirror-state';
import { mergeCells, splitCell } from '@tiptap/pm/tables';
import { EditorState } from '@tiptap/pm/state';

export function isTableActive(state: EditorState): boolean {
const { selection, doc } = state;
Expand All @@ -12,7 +12,10 @@ export function isTableActive(state: EditorState): boolean {
const name = node.type.name;
if (
keepLooking &&
(name === 'table' || name === 'table_row' || name === 'table_column' || name === 'table_cell')
(name === 'table' ||
name === 'table_row' ||
name === 'table_column' ||
name === 'table_cell')
) {
keepLooking = false;
active = true;
Expand Down
Loading

0 comments on commit bcfdf40

Please sign in to comment.