@tiptap/extensions 3.0.0-next.3
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.
- package/LICENSE.md +21 -0
- package/README.md +18 -0
- package/dist/focus/index.cjs +95 -0
- package/dist/focus/index.cjs.map +1 -0
- package/dist/focus/index.d.cts +28 -0
- package/dist/focus/index.d.ts +28 -0
- package/dist/focus/index.js +68 -0
- package/dist/focus/index.js.map +1 -0
- package/dist/gap-cursor/index.cjs +51 -0
- package/dist/gap-cursor/index.cjs.map +1 -0
- package/dist/gap-cursor/index.d.cts +25 -0
- package/dist/gap-cursor/index.d.ts +25 -0
- package/dist/gap-cursor/index.js +24 -0
- package/dist/gap-cursor/index.js.map +1 -0
- package/dist/index.cjs +222 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +117 -0
- package/dist/index.d.ts +117 -0
- package/dist/index.js +191 -0
- package/dist/index.js.map +1 -0
- package/dist/selection/index.cjs +63 -0
- package/dist/selection/index.cjs.map +1 -0
- package/dist/selection/index.d.cts +17 -0
- package/dist/selection/index.d.ts +17 -0
- package/dist/selection/index.js +36 -0
- package/dist/selection/index.js.map +1 -0
- package/dist/trailing-node/index.cjs +78 -0
- package/dist/trailing-node/index.cjs.map +1 -0
- package/dist/trailing-node/index.d.cts +28 -0
- package/dist/trailing-node/index.d.ts +28 -0
- package/dist/trailing-node/index.js +51 -0
- package/dist/trailing-node/index.js.map +1 -0
- package/package.json +93 -0
- package/src/drop-cursor/drop-cursor.ts +47 -0
- package/src/drop-cursor/index.ts +1 -0
- package/src/focus/focus.ts +110 -0
- package/src/focus/index.ts +1 -0
- package/src/gap-cursor/gap-cursor.ts +46 -0
- package/src/gap-cursor/index.ts +1 -0
- package/src/index.ts +5 -0
- package/src/selection/index.ts +1 -0
- package/src/selection/selection.ts +51 -0
- package/src/trailing-node/index.ts +1 -0
- package/src/trailing-node/trailing-node.ts +84 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/drop-cursor/drop-cursor.ts","../src/focus/focus.ts","../src/gap-cursor/gap-cursor.ts","../src/selection/selection.ts","../src/trailing-node/trailing-node.ts"],"sourcesContent":["export * from './drop-cursor/index.js'\nexport * from './focus/index.js'\nexport * from './gap-cursor/index.js'\nexport * from './selection/index.js'\nexport * from './trailing-node/index.js'\n","import { Extension } from '@tiptap/core'\nimport { dropCursor } from '@tiptap/pm/dropcursor'\n\nexport interface DropcursorOptions {\n /**\n * The color of the drop cursor\n * @default 'currentColor'\n * @example 'red'\n */\n color: string | undefined\n\n /**\n * The width of the drop cursor\n * @default 1\n * @example 2\n */\n width: number | undefined\n\n /**\n * The class of the drop cursor\n * @default undefined\n * @example 'drop-cursor'\n */\n class: string | undefined\n}\n\n/**\n * This extension allows you to add a drop cursor to your editor.\n * A drop cursor is a line that appears when you drag and drop content\n * in-between nodes.\n * @see https://tiptap.dev/api/extensions/dropcursor\n */\nexport const Dropcursor = Extension.create<DropcursorOptions>({\n name: 'dropCursor',\n\n addOptions() {\n return {\n color: 'currentColor',\n width: 1,\n class: undefined,\n }\n },\n\n addProseMirrorPlugins() {\n return [dropCursor(this.options)]\n },\n})\n","import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface FocusOptions {\n /**\n * The class name that should be added to the focused node.\n * @default 'has-focus'\n * @example 'is-focused'\n */\n className: string\n\n /**\n * The mode by which the focused node is determined.\n * - All: All nodes are marked as focused.\n * - Deepest: Only the deepest node is marked as focused.\n * - Shallowest: Only the shallowest node is marked as focused.\n *\n * @default 'all'\n * @example 'deepest'\n * @example 'shallowest'\n */\n mode: 'all' | 'deepest' | 'shallowest'\n}\n\n/**\n * This extension allows you to add a class to the focused node.\n * @see https://www.tiptap.dev/api/extensions/focus\n */\nexport const Focus = Extension.create<FocusOptions>({\n name: 'focus',\n\n addOptions() {\n return {\n className: 'has-focus',\n mode: 'all',\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('focus'),\n props: {\n decorations: ({ doc, selection }) => {\n const { isEditable, isFocused } = this.editor\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!isEditable || !isFocused) {\n return DecorationSet.create(doc, [])\n }\n\n // Maximum Levels\n let maxLevels = 0\n\n if (this.options.mode === 'deepest') {\n doc.descendants((node, pos) => {\n if (node.isText) {\n return\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n maxLevels += 1\n })\n }\n\n // Loop through current\n let currentLevel = 0\n\n doc.descendants((node, pos) => {\n if (node.isText) {\n return false\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n currentLevel += 1\n\n const outOfScope =\n (this.options.mode === 'deepest' && maxLevels - currentLevel > 0) ||\n (this.options.mode === 'shallowest' && currentLevel > 1)\n\n if (outOfScope) {\n return this.options.mode === 'deepest'\n }\n\n decorations.push(\n Decoration.node(pos, pos + node.nodeSize, {\n class: this.options.className,\n }),\n )\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n","import { callOrReturn, Extension, getExtensionField, ParentConfig } from '@tiptap/core'\nimport { gapCursor } from '@tiptap/pm/gapcursor'\n\ndeclare module '@tiptap/core' {\n interface NodeConfig<Options, Storage> {\n /**\n * A function to determine whether the gap cursor is allowed at the current position. Must return `true` or `false`.\n * @default null\n */\n allowGapCursor?:\n | boolean\n | null\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options>>['allowGapCursor']\n }) => boolean | null)\n }\n}\n\n/**\n * This extension allows you to add a gap cursor to your editor.\n * A gap cursor is a cursor that appears when you click on a place\n * where no content is present, for example inbetween nodes.\n * @see https://tiptap.dev/api/extensions/gapcursor\n */\nexport const Gapcursor = Extension.create({\n name: 'gapCursor',\n\n addProseMirrorPlugins() {\n return [gapCursor()]\n },\n\n extendNodeSchema(extension) {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n }\n\n return {\n allowGapCursor: callOrReturn(getExtensionField(extension, 'allowGapCursor', context)) ?? null,\n }\n },\n})\n","import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport type SelectionOptions = {\n /**\n * The class name that should be added to the selected text.\n * @default 'selection'\n * @example 'is-selected'\n */\n className: string\n}\n\n/**\n * This extension allows you to add a class to the selected text.\n * @see https://www.tiptap.dev/api/extensions/selection\n */\nexport const Selection = Extension.create({\n name: 'selection',\n\n addOptions() {\n return {\n className: 'selection',\n }\n },\n\n addProseMirrorPlugins() {\n const { editor, options } = this\n\n return [\n new Plugin({\n key: new PluginKey('selection'),\n props: {\n decorations(state) {\n if (state.selection.empty || editor.isFocused) {\n return null\n }\n\n return DecorationSet.create(state.doc, [\n Decoration.inline(state.selection.from, state.selection.to, {\n class: options.className,\n }),\n ])\n },\n },\n }),\n ]\n },\n})\n\nexport default Selection\n","import { Extension } from '@tiptap/core'\nimport { Node, NodeType } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\n\nfunction nodeEqualsType({ types, node }: { types: NodeType | NodeType[]; node: Node | null | undefined }) {\n return (node && Array.isArray(types) && types.includes(node.type)) || node?.type === types\n}\n\n/**\n * Extension based on:\n * - https://github.com/ueberdosis/tiptap/blob/v1/packages/tiptap-extensions/src/extensions/TrailingNode.js\n * - https://github.com/remirror/remirror/blob/e0f1bec4a1e8073ce8f5500d62193e52321155b9/packages/prosemirror-trailing-node/src/trailing-node-plugin.ts\n */\n\nexport interface TrailingNodeOptions {\n /**\n * The node type that should be inserted at the end of the document.\n * @note the node will always be added to the `notAfter` lists to\n * prevent an infinite loop.\n * @default 'paragraph'\n */\n node: string\n /**\n * The node types after which the trailing node should not be inserted.\n * @default ['paragraph']\n */\n notAfter?: string | string[]\n}\n\n/**\n * This extension allows you to add an extra node at the end of the document.\n * @see https://www.tiptap.dev/api/extensions/trailing-node\n */\nexport const TrailingNode = Extension.create<TrailingNodeOptions>({\n name: 'trailingNode',\n\n addOptions() {\n return {\n node: 'paragraph',\n notAfter: [],\n }\n },\n\n addProseMirrorPlugins() {\n const plugin = new PluginKey(this.name)\n const disabledNodes = Object.entries(this.editor.schema.nodes)\n .map(([, value]) => value)\n .filter(node => (this.options.notAfter || []).concat(this.options.node).includes(node.name))\n\n return [\n new Plugin({\n key: plugin,\n appendTransaction: (_, __, state) => {\n const { doc, tr, schema } = state\n const shouldInsertNodeAtEnd = plugin.getState(state)\n const endPosition = doc.content.size\n const type = schema.nodes[this.options.node]\n\n if (!shouldInsertNodeAtEnd) {\n return\n }\n\n return tr.insert(endPosition, type.create())\n },\n state: {\n init: (_, state) => {\n const lastNode = state.tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n apply: (tr, value) => {\n if (!tr.docChanged) {\n return value\n }\n\n const lastNode = tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n },\n }),\n ]\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA0B;AAC1B,wBAA2B;AA+BpB,IAAM,aAAa,sBAAU,OAA0B;AAAA,EAC5D,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,OAAO;AAAA,MACP,OAAO;AAAA,MACP,OAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,WAAO,KAAC,8BAAW,KAAK,OAAO,CAAC;AAAA,EAClC;AACF,CAAC;;;AC9CD,IAAAA,eAA0B;AAC1B,mBAAkC;AAClC,kBAA0C;AA2BnC,IAAM,QAAQ,uBAAU,OAAqB;AAAA,EAClD,MAAM;AAAA,EAEN,aA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mBAAO,CAAC,eAAe,EAAE,MAAM,UAAU,OAAO,cAAc,CAAC;AAAA,UACjE;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;","names":["import_core","import_core","import_core","import_state","import_view","import_core","import_state"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Extension, ParentConfig } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
interface DropcursorOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The color of the drop cursor
|
|
6
|
+
* @default 'currentColor'
|
|
7
|
+
* @example 'red'
|
|
8
|
+
*/
|
|
9
|
+
color: string | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* The width of the drop cursor
|
|
12
|
+
* @default 1
|
|
13
|
+
* @example 2
|
|
14
|
+
*/
|
|
15
|
+
width: number | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* The class of the drop cursor
|
|
18
|
+
* @default undefined
|
|
19
|
+
* @example 'drop-cursor'
|
|
20
|
+
*/
|
|
21
|
+
class: string | undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* This extension allows you to add a drop cursor to your editor.
|
|
25
|
+
* A drop cursor is a line that appears when you drag and drop content
|
|
26
|
+
* in-between nodes.
|
|
27
|
+
* @see https://tiptap.dev/api/extensions/dropcursor
|
|
28
|
+
*/
|
|
29
|
+
declare const Dropcursor: Extension<DropcursorOptions, any>;
|
|
30
|
+
|
|
31
|
+
interface FocusOptions {
|
|
32
|
+
/**
|
|
33
|
+
* The class name that should be added to the focused node.
|
|
34
|
+
* @default 'has-focus'
|
|
35
|
+
* @example 'is-focused'
|
|
36
|
+
*/
|
|
37
|
+
className: string;
|
|
38
|
+
/**
|
|
39
|
+
* The mode by which the focused node is determined.
|
|
40
|
+
* - All: All nodes are marked as focused.
|
|
41
|
+
* - Deepest: Only the deepest node is marked as focused.
|
|
42
|
+
* - Shallowest: Only the shallowest node is marked as focused.
|
|
43
|
+
*
|
|
44
|
+
* @default 'all'
|
|
45
|
+
* @example 'deepest'
|
|
46
|
+
* @example 'shallowest'
|
|
47
|
+
*/
|
|
48
|
+
mode: 'all' | 'deepest' | 'shallowest';
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* This extension allows you to add a class to the focused node.
|
|
52
|
+
* @see https://www.tiptap.dev/api/extensions/focus
|
|
53
|
+
*/
|
|
54
|
+
declare const Focus: Extension<FocusOptions, any>;
|
|
55
|
+
|
|
56
|
+
declare module '@tiptap/core' {
|
|
57
|
+
interface NodeConfig<Options, Storage> {
|
|
58
|
+
/**
|
|
59
|
+
* A function to determine whether the gap cursor is allowed at the current position. Must return `true` or `false`.
|
|
60
|
+
* @default null
|
|
61
|
+
*/
|
|
62
|
+
allowGapCursor?: boolean | null | ((this: {
|
|
63
|
+
name: string;
|
|
64
|
+
options: Options;
|
|
65
|
+
storage: Storage;
|
|
66
|
+
parent: ParentConfig<NodeConfig<Options>>['allowGapCursor'];
|
|
67
|
+
}) => boolean | null);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* This extension allows you to add a gap cursor to your editor.
|
|
72
|
+
* A gap cursor is a cursor that appears when you click on a place
|
|
73
|
+
* where no content is present, for example inbetween nodes.
|
|
74
|
+
* @see https://tiptap.dev/api/extensions/gapcursor
|
|
75
|
+
*/
|
|
76
|
+
declare const Gapcursor: Extension<any, any>;
|
|
77
|
+
|
|
78
|
+
type SelectionOptions = {
|
|
79
|
+
/**
|
|
80
|
+
* The class name that should be added to the selected text.
|
|
81
|
+
* @default 'selection'
|
|
82
|
+
* @example 'is-selected'
|
|
83
|
+
*/
|
|
84
|
+
className: string;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* This extension allows you to add a class to the selected text.
|
|
88
|
+
* @see https://www.tiptap.dev/api/extensions/selection
|
|
89
|
+
*/
|
|
90
|
+
declare const Selection: Extension<any, any>;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Extension based on:
|
|
94
|
+
* - https://github.com/ueberdosis/tiptap/blob/v1/packages/tiptap-extensions/src/extensions/TrailingNode.js
|
|
95
|
+
* - https://github.com/remirror/remirror/blob/e0f1bec4a1e8073ce8f5500d62193e52321155b9/packages/prosemirror-trailing-node/src/trailing-node-plugin.ts
|
|
96
|
+
*/
|
|
97
|
+
interface TrailingNodeOptions {
|
|
98
|
+
/**
|
|
99
|
+
* The node type that should be inserted at the end of the document.
|
|
100
|
+
* @note the node will always be added to the `notAfter` lists to
|
|
101
|
+
* prevent an infinite loop.
|
|
102
|
+
* @default 'paragraph'
|
|
103
|
+
*/
|
|
104
|
+
node: string;
|
|
105
|
+
/**
|
|
106
|
+
* The node types after which the trailing node should not be inserted.
|
|
107
|
+
* @default ['paragraph']
|
|
108
|
+
*/
|
|
109
|
+
notAfter?: string | string[];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* This extension allows you to add an extra node at the end of the document.
|
|
113
|
+
* @see https://www.tiptap.dev/api/extensions/trailing-node
|
|
114
|
+
*/
|
|
115
|
+
declare const TrailingNode: Extension<TrailingNodeOptions, any>;
|
|
116
|
+
|
|
117
|
+
export { Dropcursor, type DropcursorOptions, Focus, type FocusOptions, Gapcursor, Selection, type SelectionOptions, TrailingNode, type TrailingNodeOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Extension, ParentConfig } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
interface DropcursorOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The color of the drop cursor
|
|
6
|
+
* @default 'currentColor'
|
|
7
|
+
* @example 'red'
|
|
8
|
+
*/
|
|
9
|
+
color: string | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* The width of the drop cursor
|
|
12
|
+
* @default 1
|
|
13
|
+
* @example 2
|
|
14
|
+
*/
|
|
15
|
+
width: number | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* The class of the drop cursor
|
|
18
|
+
* @default undefined
|
|
19
|
+
* @example 'drop-cursor'
|
|
20
|
+
*/
|
|
21
|
+
class: string | undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* This extension allows you to add a drop cursor to your editor.
|
|
25
|
+
* A drop cursor is a line that appears when you drag and drop content
|
|
26
|
+
* in-between nodes.
|
|
27
|
+
* @see https://tiptap.dev/api/extensions/dropcursor
|
|
28
|
+
*/
|
|
29
|
+
declare const Dropcursor: Extension<DropcursorOptions, any>;
|
|
30
|
+
|
|
31
|
+
interface FocusOptions {
|
|
32
|
+
/**
|
|
33
|
+
* The class name that should be added to the focused node.
|
|
34
|
+
* @default 'has-focus'
|
|
35
|
+
* @example 'is-focused'
|
|
36
|
+
*/
|
|
37
|
+
className: string;
|
|
38
|
+
/**
|
|
39
|
+
* The mode by which the focused node is determined.
|
|
40
|
+
* - All: All nodes are marked as focused.
|
|
41
|
+
* - Deepest: Only the deepest node is marked as focused.
|
|
42
|
+
* - Shallowest: Only the shallowest node is marked as focused.
|
|
43
|
+
*
|
|
44
|
+
* @default 'all'
|
|
45
|
+
* @example 'deepest'
|
|
46
|
+
* @example 'shallowest'
|
|
47
|
+
*/
|
|
48
|
+
mode: 'all' | 'deepest' | 'shallowest';
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* This extension allows you to add a class to the focused node.
|
|
52
|
+
* @see https://www.tiptap.dev/api/extensions/focus
|
|
53
|
+
*/
|
|
54
|
+
declare const Focus: Extension<FocusOptions, any>;
|
|
55
|
+
|
|
56
|
+
declare module '@tiptap/core' {
|
|
57
|
+
interface NodeConfig<Options, Storage> {
|
|
58
|
+
/**
|
|
59
|
+
* A function to determine whether the gap cursor is allowed at the current position. Must return `true` or `false`.
|
|
60
|
+
* @default null
|
|
61
|
+
*/
|
|
62
|
+
allowGapCursor?: boolean | null | ((this: {
|
|
63
|
+
name: string;
|
|
64
|
+
options: Options;
|
|
65
|
+
storage: Storage;
|
|
66
|
+
parent: ParentConfig<NodeConfig<Options>>['allowGapCursor'];
|
|
67
|
+
}) => boolean | null);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* This extension allows you to add a gap cursor to your editor.
|
|
72
|
+
* A gap cursor is a cursor that appears when you click on a place
|
|
73
|
+
* where no content is present, for example inbetween nodes.
|
|
74
|
+
* @see https://tiptap.dev/api/extensions/gapcursor
|
|
75
|
+
*/
|
|
76
|
+
declare const Gapcursor: Extension<any, any>;
|
|
77
|
+
|
|
78
|
+
type SelectionOptions = {
|
|
79
|
+
/**
|
|
80
|
+
* The class name that should be added to the selected text.
|
|
81
|
+
* @default 'selection'
|
|
82
|
+
* @example 'is-selected'
|
|
83
|
+
*/
|
|
84
|
+
className: string;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* This extension allows you to add a class to the selected text.
|
|
88
|
+
* @see https://www.tiptap.dev/api/extensions/selection
|
|
89
|
+
*/
|
|
90
|
+
declare const Selection: Extension<any, any>;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Extension based on:
|
|
94
|
+
* - https://github.com/ueberdosis/tiptap/blob/v1/packages/tiptap-extensions/src/extensions/TrailingNode.js
|
|
95
|
+
* - https://github.com/remirror/remirror/blob/e0f1bec4a1e8073ce8f5500d62193e52321155b9/packages/prosemirror-trailing-node/src/trailing-node-plugin.ts
|
|
96
|
+
*/
|
|
97
|
+
interface TrailingNodeOptions {
|
|
98
|
+
/**
|
|
99
|
+
* The node type that should be inserted at the end of the document.
|
|
100
|
+
* @note the node will always be added to the `notAfter` lists to
|
|
101
|
+
* prevent an infinite loop.
|
|
102
|
+
* @default 'paragraph'
|
|
103
|
+
*/
|
|
104
|
+
node: string;
|
|
105
|
+
/**
|
|
106
|
+
* The node types after which the trailing node should not be inserted.
|
|
107
|
+
* @default ['paragraph']
|
|
108
|
+
*/
|
|
109
|
+
notAfter?: string | string[];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* This extension allows you to add an extra node at the end of the document.
|
|
113
|
+
* @see https://www.tiptap.dev/api/extensions/trailing-node
|
|
114
|
+
*/
|
|
115
|
+
declare const TrailingNode: Extension<TrailingNodeOptions, any>;
|
|
116
|
+
|
|
117
|
+
export { Dropcursor, type DropcursorOptions, Focus, type FocusOptions, Gapcursor, Selection, type SelectionOptions, TrailingNode, type TrailingNodeOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// src/drop-cursor/drop-cursor.ts
|
|
2
|
+
import { Extension } from "@tiptap/core";
|
|
3
|
+
import { dropCursor } from "@tiptap/pm/dropcursor";
|
|
4
|
+
var Dropcursor = Extension.create({
|
|
5
|
+
name: "dropCursor",
|
|
6
|
+
addOptions() {
|
|
7
|
+
return {
|
|
8
|
+
color: "currentColor",
|
|
9
|
+
width: 1,
|
|
10
|
+
class: void 0
|
|
11
|
+
};
|
|
12
|
+
},
|
|
13
|
+
addProseMirrorPlugins() {
|
|
14
|
+
return [dropCursor(this.options)];
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// src/focus/focus.ts
|
|
19
|
+
import { Extension as Extension2 } from "@tiptap/core";
|
|
20
|
+
import { Plugin, PluginKey } from "@tiptap/pm/state";
|
|
21
|
+
import { Decoration, DecorationSet } from "@tiptap/pm/view";
|
|
22
|
+
var Focus = Extension2.create({
|
|
23
|
+
name: "focus",
|
|
24
|
+
addOptions() {
|
|
25
|
+
return {
|
|
26
|
+
className: "has-focus",
|
|
27
|
+
mode: "all"
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
addProseMirrorPlugins() {
|
|
31
|
+
return [
|
|
32
|
+
new Plugin({
|
|
33
|
+
key: new PluginKey("focus"),
|
|
34
|
+
props: {
|
|
35
|
+
decorations: ({ doc, selection }) => {
|
|
36
|
+
const { isEditable, isFocused } = this.editor;
|
|
37
|
+
const { anchor } = selection;
|
|
38
|
+
const decorations = [];
|
|
39
|
+
if (!isEditable || !isFocused) {
|
|
40
|
+
return DecorationSet.create(doc, []);
|
|
41
|
+
}
|
|
42
|
+
let maxLevels = 0;
|
|
43
|
+
if (this.options.mode === "deepest") {
|
|
44
|
+
doc.descendants((node, pos) => {
|
|
45
|
+
if (node.isText) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
|
|
49
|
+
if (!isCurrent) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
maxLevels += 1;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
let currentLevel = 0;
|
|
56
|
+
doc.descendants((node, pos) => {
|
|
57
|
+
if (node.isText) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
|
|
61
|
+
if (!isCurrent) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
currentLevel += 1;
|
|
65
|
+
const outOfScope = this.options.mode === "deepest" && maxLevels - currentLevel > 0 || this.options.mode === "shallowest" && currentLevel > 1;
|
|
66
|
+
if (outOfScope) {
|
|
67
|
+
return this.options.mode === "deepest";
|
|
68
|
+
}
|
|
69
|
+
decorations.push(
|
|
70
|
+
Decoration.node(pos, pos + node.nodeSize, {
|
|
71
|
+
class: this.options.className
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
return DecorationSet.create(doc, decorations);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// src/gap-cursor/gap-cursor.ts
|
|
84
|
+
import { callOrReturn, Extension as Extension3, getExtensionField } from "@tiptap/core";
|
|
85
|
+
import { gapCursor } from "@tiptap/pm/gapcursor";
|
|
86
|
+
var Gapcursor = Extension3.create({
|
|
87
|
+
name: "gapCursor",
|
|
88
|
+
addProseMirrorPlugins() {
|
|
89
|
+
return [gapCursor()];
|
|
90
|
+
},
|
|
91
|
+
extendNodeSchema(extension) {
|
|
92
|
+
var _a;
|
|
93
|
+
const context = {
|
|
94
|
+
name: extension.name,
|
|
95
|
+
options: extension.options,
|
|
96
|
+
storage: extension.storage
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
allowGapCursor: (_a = callOrReturn(getExtensionField(extension, "allowGapCursor", context))) != null ? _a : null
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// src/selection/selection.ts
|
|
105
|
+
import { Extension as Extension4 } from "@tiptap/core";
|
|
106
|
+
import { Plugin as Plugin2, PluginKey as PluginKey2 } from "@tiptap/pm/state";
|
|
107
|
+
import { Decoration as Decoration2, DecorationSet as DecorationSet2 } from "@tiptap/pm/view";
|
|
108
|
+
var Selection = Extension4.create({
|
|
109
|
+
name: "selection",
|
|
110
|
+
addOptions() {
|
|
111
|
+
return {
|
|
112
|
+
className: "selection"
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
addProseMirrorPlugins() {
|
|
116
|
+
const { editor, options } = this;
|
|
117
|
+
return [
|
|
118
|
+
new Plugin2({
|
|
119
|
+
key: new PluginKey2("selection"),
|
|
120
|
+
props: {
|
|
121
|
+
decorations(state) {
|
|
122
|
+
if (state.selection.empty || editor.isFocused) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
return DecorationSet2.create(state.doc, [
|
|
126
|
+
Decoration2.inline(state.selection.from, state.selection.to, {
|
|
127
|
+
class: options.className
|
|
128
|
+
})
|
|
129
|
+
]);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
];
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// src/trailing-node/trailing-node.ts
|
|
138
|
+
import { Extension as Extension5 } from "@tiptap/core";
|
|
139
|
+
import { Plugin as Plugin3, PluginKey as PluginKey3 } from "@tiptap/pm/state";
|
|
140
|
+
function nodeEqualsType({ types, node }) {
|
|
141
|
+
return node && Array.isArray(types) && types.includes(node.type) || (node == null ? void 0 : node.type) === types;
|
|
142
|
+
}
|
|
143
|
+
var TrailingNode = Extension5.create({
|
|
144
|
+
name: "trailingNode",
|
|
145
|
+
addOptions() {
|
|
146
|
+
return {
|
|
147
|
+
node: "paragraph",
|
|
148
|
+
notAfter: []
|
|
149
|
+
};
|
|
150
|
+
},
|
|
151
|
+
addProseMirrorPlugins() {
|
|
152
|
+
const plugin = new PluginKey3(this.name);
|
|
153
|
+
const disabledNodes = Object.entries(this.editor.schema.nodes).map(([, value]) => value).filter((node) => (this.options.notAfter || []).concat(this.options.node).includes(node.name));
|
|
154
|
+
return [
|
|
155
|
+
new Plugin3({
|
|
156
|
+
key: plugin,
|
|
157
|
+
appendTransaction: (_, __, state) => {
|
|
158
|
+
const { doc, tr, schema } = state;
|
|
159
|
+
const shouldInsertNodeAtEnd = plugin.getState(state);
|
|
160
|
+
const endPosition = doc.content.size;
|
|
161
|
+
const type = schema.nodes[this.options.node];
|
|
162
|
+
if (!shouldInsertNodeAtEnd) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
return tr.insert(endPosition, type.create());
|
|
166
|
+
},
|
|
167
|
+
state: {
|
|
168
|
+
init: (_, state) => {
|
|
169
|
+
const lastNode = state.tr.doc.lastChild;
|
|
170
|
+
return !nodeEqualsType({ node: lastNode, types: disabledNodes });
|
|
171
|
+
},
|
|
172
|
+
apply: (tr, value) => {
|
|
173
|
+
if (!tr.docChanged) {
|
|
174
|
+
return value;
|
|
175
|
+
}
|
|
176
|
+
const lastNode = tr.doc.lastChild;
|
|
177
|
+
return !nodeEqualsType({ node: lastNode, types: disabledNodes });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
})
|
|
181
|
+
];
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
export {
|
|
185
|
+
Dropcursor,
|
|
186
|
+
Focus,
|
|
187
|
+
Gapcursor,
|
|
188
|
+
Selection,
|
|
189
|
+
TrailingNode
|
|
190
|
+
};
|
|
191
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/drop-cursor/drop-cursor.ts","../src/focus/focus.ts","../src/gap-cursor/gap-cursor.ts","../src/selection/selection.ts","../src/trailing-node/trailing-node.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport { dropCursor } from '@tiptap/pm/dropcursor'\n\nexport interface DropcursorOptions {\n /**\n * The color of the drop cursor\n * @default 'currentColor'\n * @example 'red'\n */\n color: string | undefined\n\n /**\n * The width of the drop cursor\n * @default 1\n * @example 2\n */\n width: number | undefined\n\n /**\n * The class of the drop cursor\n * @default undefined\n * @example 'drop-cursor'\n */\n class: string | undefined\n}\n\n/**\n * This extension allows you to add a drop cursor to your editor.\n * A drop cursor is a line that appears when you drag and drop content\n * in-between nodes.\n * @see https://tiptap.dev/api/extensions/dropcursor\n */\nexport const Dropcursor = Extension.create<DropcursorOptions>({\n name: 'dropCursor',\n\n addOptions() {\n return {\n color: 'currentColor',\n width: 1,\n class: undefined,\n }\n },\n\n addProseMirrorPlugins() {\n return [dropCursor(this.options)]\n },\n})\n","import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface FocusOptions {\n /**\n * The class name that should be added to the focused node.\n * @default 'has-focus'\n * @example 'is-focused'\n */\n className: string\n\n /**\n * The mode by which the focused node is determined.\n * - All: All nodes are marked as focused.\n * - Deepest: Only the deepest node is marked as focused.\n * - Shallowest: Only the shallowest node is marked as focused.\n *\n * @default 'all'\n * @example 'deepest'\n * @example 'shallowest'\n */\n mode: 'all' | 'deepest' | 'shallowest'\n}\n\n/**\n * This extension allows you to add a class to the focused node.\n * @see https://www.tiptap.dev/api/extensions/focus\n */\nexport const Focus = Extension.create<FocusOptions>({\n name: 'focus',\n\n addOptions() {\n return {\n className: 'has-focus',\n mode: 'all',\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('focus'),\n props: {\n decorations: ({ doc, selection }) => {\n const { isEditable, isFocused } = this.editor\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!isEditable || !isFocused) {\n return DecorationSet.create(doc, [])\n }\n\n // Maximum Levels\n let maxLevels = 0\n\n if (this.options.mode === 'deepest') {\n doc.descendants((node, pos) => {\n if (node.isText) {\n return\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n maxLevels += 1\n })\n }\n\n // Loop through current\n let currentLevel = 0\n\n doc.descendants((node, pos) => {\n if (node.isText) {\n return false\n }\n\n const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1\n\n if (!isCurrent) {\n return false\n }\n\n currentLevel += 1\n\n const outOfScope =\n (this.options.mode === 'deepest' && maxLevels - currentLevel > 0) ||\n (this.options.mode === 'shallowest' && currentLevel > 1)\n\n if (outOfScope) {\n return this.options.mode === 'deepest'\n }\n\n decorations.push(\n Decoration.node(pos, pos + node.nodeSize, {\n class: this.options.className,\n }),\n )\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n","import { callOrReturn, Extension, getExtensionField, ParentConfig } from '@tiptap/core'\nimport { gapCursor } from '@tiptap/pm/gapcursor'\n\ndeclare module '@tiptap/core' {\n interface NodeConfig<Options, Storage> {\n /**\n * A function to determine whether the gap cursor is allowed at the current position. Must return `true` or `false`.\n * @default null\n */\n allowGapCursor?:\n | boolean\n | null\n | ((this: {\n name: string\n options: Options\n storage: Storage\n parent: ParentConfig<NodeConfig<Options>>['allowGapCursor']\n }) => boolean | null)\n }\n}\n\n/**\n * This extension allows you to add a gap cursor to your editor.\n * A gap cursor is a cursor that appears when you click on a place\n * where no content is present, for example inbetween nodes.\n * @see https://tiptap.dev/api/extensions/gapcursor\n */\nexport const Gapcursor = Extension.create({\n name: 'gapCursor',\n\n addProseMirrorPlugins() {\n return [gapCursor()]\n },\n\n extendNodeSchema(extension) {\n const context = {\n name: extension.name,\n options: extension.options,\n storage: extension.storage,\n }\n\n return {\n allowGapCursor: callOrReturn(getExtensionField(extension, 'allowGapCursor', context)) ?? null,\n }\n },\n})\n","import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport type SelectionOptions = {\n /**\n * The class name that should be added to the selected text.\n * @default 'selection'\n * @example 'is-selected'\n */\n className: string\n}\n\n/**\n * This extension allows you to add a class to the selected text.\n * @see https://www.tiptap.dev/api/extensions/selection\n */\nexport const Selection = Extension.create({\n name: 'selection',\n\n addOptions() {\n return {\n className: 'selection',\n }\n },\n\n addProseMirrorPlugins() {\n const { editor, options } = this\n\n return [\n new Plugin({\n key: new PluginKey('selection'),\n props: {\n decorations(state) {\n if (state.selection.empty || editor.isFocused) {\n return null\n }\n\n return DecorationSet.create(state.doc, [\n Decoration.inline(state.selection.from, state.selection.to, {\n class: options.className,\n }),\n ])\n },\n },\n }),\n ]\n },\n})\n\nexport default Selection\n","import { Extension } from '@tiptap/core'\nimport { Node, NodeType } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\n\nfunction nodeEqualsType({ types, node }: { types: NodeType | NodeType[]; node: Node | null | undefined }) {\n return (node && Array.isArray(types) && types.includes(node.type)) || node?.type === types\n}\n\n/**\n * Extension based on:\n * - https://github.com/ueberdosis/tiptap/blob/v1/packages/tiptap-extensions/src/extensions/TrailingNode.js\n * - https://github.com/remirror/remirror/blob/e0f1bec4a1e8073ce8f5500d62193e52321155b9/packages/prosemirror-trailing-node/src/trailing-node-plugin.ts\n */\n\nexport interface TrailingNodeOptions {\n /**\n * The node type that should be inserted at the end of the document.\n * @note the node will always be added to the `notAfter` lists to\n * prevent an infinite loop.\n * @default 'paragraph'\n */\n node: string\n /**\n * The node types after which the trailing node should not be inserted.\n * @default ['paragraph']\n */\n notAfter?: string | string[]\n}\n\n/**\n * This extension allows you to add an extra node at the end of the document.\n * @see https://www.tiptap.dev/api/extensions/trailing-node\n */\nexport const TrailingNode = Extension.create<TrailingNodeOptions>({\n name: 'trailingNode',\n\n addOptions() {\n return {\n node: 'paragraph',\n notAfter: [],\n }\n },\n\n addProseMirrorPlugins() {\n const plugin = new PluginKey(this.name)\n const disabledNodes = Object.entries(this.editor.schema.nodes)\n .map(([, value]) => value)\n .filter(node => (this.options.notAfter || []).concat(this.options.node).includes(node.name))\n\n return [\n new Plugin({\n key: plugin,\n appendTransaction: (_, __, state) => {\n const { doc, tr, schema } = state\n const shouldInsertNodeAtEnd = plugin.getState(state)\n const endPosition = doc.content.size\n const type = schema.nodes[this.options.node]\n\n if (!shouldInsertNodeAtEnd) {\n return\n }\n\n return tr.insert(endPosition, type.create())\n },\n state: {\n init: (_, state) => {\n const lastNode = state.tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n apply: (tr, value) => {\n if (!tr.docChanged) {\n return value\n }\n\n const lastNode = tr.doc.lastChild\n\n return !nodeEqualsType({ node: lastNode, types: disabledNodes })\n },\n },\n }),\n ]\n },\n})\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AA+BpB,IAAM,aAAa,UAAU,OAA0B;AAAA,EAC5D,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,OAAO;AAAA,MACP,OAAO;AAAA,MACP,OAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,WAAO,CAAC,WAAW,KAAK,OAAO,CAAC;AAAA,EAClC;AACF,CAAC;;;AC9CD,SAAS,aAAAA,kBAAiB;AAC1B,SAAS,QAAQ,iBAAiB;AAClC,SAAS,YAAY,qBAAqB;AA2BnC,IAAM,QAAQA,WAAU,OAAqB;AAAA,EAClD,MAAM;AAAA,EAEN,aAAa;AACX,WAA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AI,CAAC,GAAG,YAAY;AAClB,qBAAO;AAAA,YACT;AAEA,kBAAM,WAAW,GAAG,IAAI;AAExB,mBAAO,CAAC,eAAe,EAAE,MAAM,UAAU,OAAO,cAAc,CAAC;AAAA,UACjE;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;","names":["Extension","Extension","Extension","Plugin","PluginKey","Decoration","DecorationSet","Extension","Plugin","PluginKey"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/selection/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Selection: () => Selection
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/selection/selection.ts
|
|
28
|
+
var import_core = require("@tiptap/core");
|
|
29
|
+
var import_state = require("@tiptap/pm/state");
|
|
30
|
+
var import_view = require("@tiptap/pm/view");
|
|
31
|
+
var Selection = import_core.Extension.create({
|
|
32
|
+
name: "selection",
|
|
33
|
+
addOptions() {
|
|
34
|
+
return {
|
|
35
|
+
className: "selection"
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
addProseMirrorPlugins() {
|
|
39
|
+
const { editor, options } = this;
|
|
40
|
+
return [
|
|
41
|
+
new import_state.Plugin({
|
|
42
|
+
key: new import_state.PluginKey("selection"),
|
|
43
|
+
props: {
|
|
44
|
+
decorations(state) {
|
|
45
|
+
if (state.selection.empty || editor.isFocused) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
return import_view.DecorationSet.create(state.doc, [
|
|
49
|
+
import_view.Decoration.inline(state.selection.from, state.selection.to, {
|
|
50
|
+
class: options.className
|
|
51
|
+
})
|
|
52
|
+
]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {
|
|
61
|
+
Selection
|
|
62
|
+
});
|
|
63
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/selection/index.ts","../../src/selection/selection.ts"],"sourcesContent":["export * from './selection.js'\n","import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport type SelectionOptions = {\n /**\n * The class name that should be added to the selected text.\n * @default 'selection'\n * @example 'is-selected'\n */\n className: string\n}\n\n/**\n * This extension allows you to add a class to the selected text.\n * @see https://www.tiptap.dev/api/extensions/selection\n */\nexport const Selection = Extension.create({\n name: 'selection',\n\n addOptions() {\n return {\n className: 'selection',\n }\n },\n\n addProseMirrorPlugins() {\n const { editor, options } = this\n\n return [\n new Plugin({\n key: new PluginKey('selection'),\n props: {\n decorations(state) {\n if (state.selection.empty || editor.isFocused) {\n return null\n }\n\n return DecorationSet.create(state.doc, [\n Decoration.inline(state.selection.from, state.selection.to, {\n class: options.className,\n }),\n ])\n },\n },\n }),\n ]\n },\n})\n\nexport default Selection\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA0B;AAC1B,mBAAkC;AAClC,kBAA0C;AAenC,IAAM,YAAY,sBAAU,OAAO;AAAA,EACxC,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,WAAW;AAAA,IACb;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,UAAM,EAAE,QAAQ,QAAQ,IAAI;AAE5B,WAAO;AAAA,MACL,IAAI,oBAAO;AAAA,QACT,KAAK,IAAI,uBAAU,WAAW;AAAA,QAC9B,OAAO;AAAA,UACL,YAAY,OAAO;AACjB,gBAAI,MAAM,UAAU,SAAS,OAAO,WAAW;AAC7C,qBAAO;AAAA,YACT;AAEA,mBAAO,0BAAc,OAAO,MAAM,KAAK;AAAA,cACrC,uBAAW,OAAO,MAAM,UAAU,MAAM,MAAM,UAAU,IAAI;AAAA,gBAC1D,OAAO,QAAQ;AAAA,cACjB,CAAC;AAAA,YACH,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
type SelectionOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* The class name that should be added to the selected text.
|
|
6
|
+
* @default 'selection'
|
|
7
|
+
* @example 'is-selected'
|
|
8
|
+
*/
|
|
9
|
+
className: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* This extension allows you to add a class to the selected text.
|
|
13
|
+
* @see https://www.tiptap.dev/api/extensions/selection
|
|
14
|
+
*/
|
|
15
|
+
declare const Selection: Extension<any, any>;
|
|
16
|
+
|
|
17
|
+
export { Selection, type SelectionOptions };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
type SelectionOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* The class name that should be added to the selected text.
|
|
6
|
+
* @default 'selection'
|
|
7
|
+
* @example 'is-selected'
|
|
8
|
+
*/
|
|
9
|
+
className: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* This extension allows you to add a class to the selected text.
|
|
13
|
+
* @see https://www.tiptap.dev/api/extensions/selection
|
|
14
|
+
*/
|
|
15
|
+
declare const Selection: Extension<any, any>;
|
|
16
|
+
|
|
17
|
+
export { Selection, type SelectionOptions };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/selection/selection.ts
|
|
2
|
+
import { Extension } from "@tiptap/core";
|
|
3
|
+
import { Plugin, PluginKey } from "@tiptap/pm/state";
|
|
4
|
+
import { Decoration, DecorationSet } from "@tiptap/pm/view";
|
|
5
|
+
var Selection = Extension.create({
|
|
6
|
+
name: "selection",
|
|
7
|
+
addOptions() {
|
|
8
|
+
return {
|
|
9
|
+
className: "selection"
|
|
10
|
+
};
|
|
11
|
+
},
|
|
12
|
+
addProseMirrorPlugins() {
|
|
13
|
+
const { editor, options } = this;
|
|
14
|
+
return [
|
|
15
|
+
new Plugin({
|
|
16
|
+
key: new PluginKey("selection"),
|
|
17
|
+
props: {
|
|
18
|
+
decorations(state) {
|
|
19
|
+
if (state.selection.empty || editor.isFocused) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return DecorationSet.create(state.doc, [
|
|
23
|
+
Decoration.inline(state.selection.from, state.selection.to, {
|
|
24
|
+
class: options.className
|
|
25
|
+
})
|
|
26
|
+
]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
export {
|
|
34
|
+
Selection
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/selection/selection.ts"],"sourcesContent":["import { Extension } from '@tiptap/core'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport type SelectionOptions = {\n /**\n * The class name that should be added to the selected text.\n * @default 'selection'\n * @example 'is-selected'\n */\n className: string\n}\n\n/**\n * This extension allows you to add a class to the selected text.\n * @see https://www.tiptap.dev/api/extensions/selection\n */\nexport const Selection = Extension.create({\n name: 'selection',\n\n addOptions() {\n return {\n className: 'selection',\n }\n },\n\n addProseMirrorPlugins() {\n const { editor, options } = this\n\n return [\n new Plugin({\n key: new PluginKey('selection'),\n props: {\n decorations(state) {\n if (state.selection.empty || editor.isFocused) {\n return null\n }\n\n return DecorationSet.create(state.doc, [\n Decoration.inline(state.selection.from, state.selection.to, {\n class: options.className,\n }),\n ])\n },\n },\n }),\n ]\n },\n})\n\nexport default Selection\n"],"mappings":";AAAA,SAAS,iBAAiB;AAC1B,SAAS,QAAQ,iBAAiB;AAClC,SAAS,YAAY,qBAAqB;AAenC,IAAM,YAAY,UAAU,OAAO;AAAA,EACxC,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,WAAW;AAAA,IACb;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,UAAM,EAAE,QAAQ,QAAQ,IAAI;AAE5B,WAAO;AAAA,MACL,IAAI,OAAO;AAAA,QACT,KAAK,IAAI,UAAU,WAAW;AAAA,QAC9B,OAAO;AAAA,UACL,YAAY,OAAO;AACjB,gBAAI,MAAM,UAAU,SAAS,OAAO,WAAW;AAC7C,qBAAO;AAAA,YACT;AAEA,mBAAO,cAAc,OAAO,MAAM,KAAK;AAAA,cACrC,WAAW,OAAO,MAAM,UAAU,MAAM,MAAM,UAAU,IAAI;AAAA,gBAC1D,OAAO,QAAQ;AAAA,cACjB,CAAC;AAAA,YACH,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;","names":[]}
|