Skip to content

Commit

Permalink
feat: add re-export serializeForClipboard function from prosemirror-v…
Browse files Browse the repository at this point in the history
…iew (#107)
  • Loading branch information
d3m1d0v authored Jun 26, 2023
1 parent 7a08e9d commit 3574ea2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
9 changes: 1 addition & 8 deletions src/extensions/behavior/Clipboard/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@ import type {EditorView} from 'prosemirror-view';
import {Fragment, Schema, Slice} from 'prosemirror-model';
import {EditorState, Selection, Plugin} from 'prosemirror-state';

// @ts-expect-error internal types
import {__serializeForClipboard} from 'prosemirror-view';
if (!__serializeForClipboard)
throw new Error('__serializeForClipboard not exported from prosemirror-view module.');

type SerializeForClipboard = (view: EditorView, slice: Slice) => {dom: HTMLElement; text: string};
const serializeForClipboard: SerializeForClipboard = __serializeForClipboard;

import '../../../types/spec';

import {logger} from '../../../logger';
import {tryCatch} from '../../../utils/helpers';
import {Parser, Serializer, trackTransactionMetrics} from '../../../core';
import {isTextSelection, isNodeSelection, isWholeSelection} from '../../../utils/selection';
import {serializeForClipboard} from '../../../utils/serialize-for-clipboard';
import {BaseNode, pType} from '../../base/BaseSchema';

import {isInsideCode} from './code';
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ export * from './table-utils';
export type {NodeChild} from './utils/nodes';
export {getChildrenOfNode, getLastChildOfNode} from './utils/nodes';

export {serializeForClipboard} from './utils/serialize-for-clipboard';

export * from './utils/event-emitter';
19 changes: 19 additions & 0 deletions src/utils/serialize-for-clipboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type {Slice} from 'prosemirror-model';
import type {EditorView} from 'prosemirror-view';

declare module 'prosemirror-view' {
type SerializeForClipboard = (
view: EditorView,
slice: Slice,
) => {dom: HTMLElement; text: string};

// internal export
export const __serializeForClipboard: SerializeForClipboard;
}

import {__serializeForClipboard} from 'prosemirror-view';

if (!__serializeForClipboard)
throw new Error('__serializeForClipboard not exported from prosemirror-view module.');

export {__serializeForClipboard as serializeForClipboard};

0 comments on commit 3574ea2

Please sign in to comment.