@tiptap/extension-invisible-characters 2.24.2 → 3.0.0-beta.10
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/dist/index.cjs +285 -246
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +86 -0
- package/dist/index.d.ts +86 -10
- package/dist/index.js +255 -238
- package/dist/index.js.map +1 -1
- package/package.json +13 -9
- package/src/invisible-characters.ts +39 -43
- package/src/plugin/InvisibleCharacter.ts +3 -3
- package/src/plugin/InvisibleCharactersPlugin.ts +19 -16
- package/src/plugin/InvisibleNode.ts +5 -5
- package/src/plugin/reducers.ts +2 -5
- package/src/plugin/utils/create-style-tag.ts +3 -1
- package/src/plugin/utils/get-updated-ranges.ts +3 -6
- package/src/plugin/utils/text-between.ts +2 -2
- package/src/types.ts +11 -11
- package/dist/index.d.ts.map +0 -1
- package/dist/index.umd.js +0 -312
- package/dist/index.umd.js.map +0 -1
- package/dist/invisible-characters.d.ts +0 -27
- package/dist/invisible-characters.d.ts.map +0 -1
- package/dist/plugin/InvisibleCharacter.d.ts +0 -19
- package/dist/plugin/InvisibleCharacter.d.ts.map +0 -1
- package/dist/plugin/InvisibleCharactersPlugin.d.ts +0 -10
- package/dist/plugin/InvisibleCharactersPlugin.d.ts.map +0 -1
- package/dist/plugin/InvisibleNode.d.ts +0 -21
- package/dist/plugin/InvisibleNode.d.ts.map +0 -1
- package/dist/plugin/index.d.ts +0 -2
- package/dist/plugin/index.d.ts.map +0 -1
- package/dist/plugin/invisible-characters/hardBreak.d.ts +0 -6
- package/dist/plugin/invisible-characters/hardBreak.d.ts.map +0 -1
- package/dist/plugin/invisible-characters/paragraph.d.ts +0 -6
- package/dist/plugin/invisible-characters/paragraph.d.ts.map +0 -1
- package/dist/plugin/invisible-characters/space.d.ts +0 -6
- package/dist/plugin/invisible-characters/space.d.ts.map +0 -1
- package/dist/plugin/reducers.d.ts +0 -4
- package/dist/plugin/reducers.d.ts.map +0 -1
- package/dist/plugin/style.d.ts +0 -3
- package/dist/plugin/style.d.ts.map +0 -1
- package/dist/plugin/utils/create-decoration-widget.d.ts +0 -4
- package/dist/plugin/utils/create-decoration-widget.d.ts.map +0 -1
- package/dist/plugin/utils/create-style-tag.d.ts +0 -3
- package/dist/plugin/utils/create-style-tag.d.ts.map +0 -1
- package/dist/plugin/utils/get-updated-ranges.d.ts +0 -5
- package/dist/plugin/utils/get-updated-ranges.d.ts.map +0 -1
- package/dist/plugin/utils/text-between.d.ts +0 -5
- package/dist/plugin/utils/text-between.d.ts.map +0 -1
- package/dist/types.d.ts +0 -18
- package/dist/types.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/extension-invisible-characters",
|
|
3
3
|
"description": "invisible characters extension for tiptap",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "3.0.0-beta.10",
|
|
5
5
|
"homepage": "https://tiptap.dev/docs/editor/extensions/functionality/invisiblecharacters",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -15,26 +15,30 @@
|
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
18
|
-
"types":
|
|
18
|
+
"types": {
|
|
19
|
+
"import": "./dist/index.d.ts",
|
|
20
|
+
"require": "./dist/index.d.cts"
|
|
21
|
+
},
|
|
19
22
|
"import": "./dist/index.js",
|
|
20
23
|
"require": "./dist/index.cjs"
|
|
21
24
|
}
|
|
22
25
|
},
|
|
23
26
|
"main": "dist/index.cjs",
|
|
24
27
|
"module": "dist/index.js",
|
|
25
|
-
"umd": "dist/index.umd.js",
|
|
26
28
|
"types": "dist/index.d.ts",
|
|
27
29
|
"files": [
|
|
28
30
|
"src",
|
|
29
31
|
"dist"
|
|
30
32
|
],
|
|
31
33
|
"devDependencies": {
|
|
32
|
-
"@tiptap/core": "
|
|
33
|
-
"@tiptap/extension-text-style": "
|
|
34
|
+
"@tiptap/core": "3.0.0-beta.10",
|
|
35
|
+
"@tiptap/extension-text-style": "3.0.0-beta.10",
|
|
36
|
+
"@tiptap/pm": "3.0.0-beta.10"
|
|
34
37
|
},
|
|
35
38
|
"peerDependencies": {
|
|
36
|
-
"@tiptap/core": "
|
|
37
|
-
"@tiptap/extension-text-style": "
|
|
39
|
+
"@tiptap/core": "3.0.0-beta.10",
|
|
40
|
+
"@tiptap/extension-text-style": "3.0.0-beta.10",
|
|
41
|
+
"@tiptap/pm": "3.0.0-beta.10"
|
|
38
42
|
},
|
|
39
43
|
"repository": {
|
|
40
44
|
"type": "git",
|
|
@@ -42,7 +46,7 @@
|
|
|
42
46
|
"directory": "packages/extension-invisible-characters"
|
|
43
47
|
},
|
|
44
48
|
"scripts": {
|
|
45
|
-
"
|
|
46
|
-
"
|
|
49
|
+
"build": "tsup",
|
|
50
|
+
"lint": "prettier ./src/ --check && eslint --cache --quiet --no-error-on-unmatched-pattern ./src/"
|
|
47
51
|
}
|
|
48
52
|
}
|
|
@@ -4,30 +4,26 @@ import { InvisibleCharactersPlugin, InvisibleCharactersPluginKey } from './plugi
|
|
|
4
4
|
import { HardBreakNode } from './plugin/invisible-characters/hardBreak.js'
|
|
5
5
|
import { ParagraphNode } from './plugin/invisible-characters/paragraph.js'
|
|
6
6
|
import { SpaceCharacter } from './plugin/invisible-characters/space.js'
|
|
7
|
-
import { InvisibleCharactersOptions } from './types.js'
|
|
7
|
+
import type { InvisibleCharactersOptions } from './types.js'
|
|
8
8
|
|
|
9
|
-
export {
|
|
10
|
-
HardBreakNode,
|
|
11
|
-
ParagraphNode,
|
|
12
|
-
SpaceCharacter,
|
|
13
|
-
}
|
|
9
|
+
export { HardBreakNode, ParagraphNode, SpaceCharacter }
|
|
14
10
|
|
|
15
11
|
declare module '@tiptap/core' {
|
|
16
12
|
interface Commands<ReturnType> {
|
|
17
13
|
invisibleCharacters: {
|
|
18
14
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
* Show invisible characters
|
|
16
|
+
*/
|
|
21
17
|
showInvisibleCharacters: (show?: boolean) => ReturnType
|
|
22
18
|
|
|
23
19
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
* Hide invisible characters
|
|
21
|
+
*/
|
|
26
22
|
hideInvisibleCharacters: () => ReturnType
|
|
27
23
|
|
|
28
24
|
/**
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
* Toggle invisible characters
|
|
26
|
+
*/
|
|
31
27
|
toggleInvisibleCharacters: () => ReturnType
|
|
32
28
|
}
|
|
33
29
|
}
|
|
@@ -39,20 +35,14 @@ export const InvisibleCharacters = Extension.create<InvisibleCharactersOptions>(
|
|
|
39
35
|
addOptions() {
|
|
40
36
|
return {
|
|
41
37
|
visible: true,
|
|
42
|
-
builders: [
|
|
43
|
-
new SpaceCharacter(),
|
|
44
|
-
new ParagraphNode(),
|
|
45
|
-
new HardBreakNode(),
|
|
46
|
-
],
|
|
38
|
+
builders: [new SpaceCharacter(), new ParagraphNode(), new HardBreakNode()],
|
|
47
39
|
injectCSS: true,
|
|
48
40
|
injectNonce: undefined,
|
|
49
41
|
}
|
|
50
42
|
},
|
|
51
43
|
|
|
52
44
|
addProseMirrorPlugins() {
|
|
53
|
-
return [
|
|
54
|
-
InvisibleCharactersPlugin(this.editor.state, this.options),
|
|
55
|
-
]
|
|
45
|
+
return [InvisibleCharactersPlugin(this.editor.state, this.options)]
|
|
56
46
|
},
|
|
57
47
|
|
|
58
48
|
addStorage() {
|
|
@@ -69,29 +59,35 @@ export const InvisibleCharacters = Extension.create<InvisibleCharactersOptions>(
|
|
|
69
59
|
|
|
70
60
|
addCommands() {
|
|
71
61
|
return {
|
|
72
|
-
showInvisibleCharacters:
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
62
|
+
showInvisibleCharacters:
|
|
63
|
+
(visibility = true) =>
|
|
64
|
+
({ dispatch, tr }) => {
|
|
65
|
+
if (dispatch) {
|
|
66
|
+
tr.setMeta('setInvisibleCharactersVisible', visibility)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return true
|
|
70
|
+
},
|
|
71
|
+
hideInvisibleCharacters:
|
|
72
|
+
() =>
|
|
73
|
+
({ dispatch, tr }) => {
|
|
74
|
+
if (dispatch) {
|
|
75
|
+
tr.setMeta('setInvisibleCharactersVisible', false)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return true
|
|
79
|
+
},
|
|
80
|
+
toggleInvisibleCharacters:
|
|
81
|
+
() =>
|
|
82
|
+
({ dispatch, tr, state }) => {
|
|
83
|
+
const visibility = !InvisibleCharactersPluginKey.getState(state)?.visible
|
|
84
|
+
|
|
85
|
+
if (dispatch) {
|
|
86
|
+
tr.setMeta('setInvisibleCharactersVisible', visibility)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return true
|
|
90
|
+
},
|
|
95
91
|
}
|
|
96
92
|
},
|
|
97
93
|
})
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Node } from '@tiptap/pm/model'
|
|
2
|
-
import { DecorationSet } from '@tiptap/pm/view'
|
|
1
|
+
import type { Node } from '@tiptap/pm/model'
|
|
2
|
+
import type { DecorationSet } from '@tiptap/pm/view'
|
|
3
3
|
|
|
4
4
|
import { createDecorationWidget } from './utils/create-decoration-widget.js'
|
|
5
5
|
import { textBetween } from './utils/text-between.js'
|
|
6
6
|
|
|
7
7
|
export interface InvisibleCharacterOptions {
|
|
8
|
-
type: string
|
|
8
|
+
type: string
|
|
9
9
|
predicate: (value: string) => boolean
|
|
10
10
|
priority?: number
|
|
11
11
|
content?: string
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from '@tiptap/pm/state'
|
|
1
|
+
import type { EditorState } from '@tiptap/pm/state'
|
|
2
|
+
import { AllSelection, Plugin, PluginKey } from '@tiptap/pm/state'
|
|
4
3
|
import { DecorationSet } from '@tiptap/pm/view'
|
|
5
4
|
|
|
6
|
-
import { InvisibleCharactersOptions, PluginState } from '../types.js'
|
|
5
|
+
import type { InvisibleCharactersOptions, PluginState } from '../types.js'
|
|
7
6
|
import { stateReducer } from './reducers.js'
|
|
8
7
|
import { style } from './style.js'
|
|
9
8
|
import { createStyleTag } from './utils/create-style-tag.js'
|
|
@@ -21,15 +20,17 @@ export const InvisibleCharactersPlugin = (state: EditorState, options: Invisible
|
|
|
21
20
|
editorState: EditorState,
|
|
22
21
|
decorations: DecorationSet,
|
|
23
22
|
) => {
|
|
24
|
-
return options.builders
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
return options.builders
|
|
24
|
+
.sort((builderA, builderB) => {
|
|
25
|
+
if (builderA.priority > builderB.priority) {
|
|
26
|
+
return 1
|
|
27
|
+
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
return -1
|
|
30
|
+
})
|
|
31
|
+
.reduce((newDecos, builder) => {
|
|
32
|
+
return builder.createDecoration(from, to, editorState.doc, newDecos)
|
|
33
|
+
}, decorations)
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
return new Plugin({
|
|
@@ -51,9 +52,12 @@ export const InvisibleCharactersPlugin = (state: EditorState, options: Invisible
|
|
|
51
52
|
apply: (tr, pluginState, _, currentState) => {
|
|
52
53
|
const newPluginState = stateReducer(pluginState, tr.getMeta('setInvisibleCharactersVisible'))
|
|
53
54
|
|
|
54
|
-
const decorations = getUpdatedRanges(tr).reduce(
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const decorations = getUpdatedRanges(tr).reduce(
|
|
56
|
+
(nextDecorations, [from, to]) => {
|
|
57
|
+
return addDecorationsBetweenPositions(from, to, currentState, nextDecorations)
|
|
58
|
+
},
|
|
59
|
+
newPluginState.decorations.map(tr.mapping, tr.doc),
|
|
60
|
+
)
|
|
57
61
|
|
|
58
62
|
return {
|
|
59
63
|
...newPluginState,
|
|
@@ -72,7 +76,6 @@ export const InvisibleCharactersPlugin = (state: EditorState, options: Invisible
|
|
|
72
76
|
return visible ? decorations : emptyDecorationSet
|
|
73
77
|
},
|
|
74
78
|
},
|
|
75
|
-
|
|
76
79
|
})
|
|
77
80
|
}
|
|
78
81
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Node } from '@tiptap/pm/model'
|
|
2
|
-
import { DecorationSet } from '@tiptap/pm/view'
|
|
1
|
+
import type { Node } from '@tiptap/pm/model'
|
|
2
|
+
import type { DecorationSet } from '@tiptap/pm/view'
|
|
3
3
|
|
|
4
4
|
import { createDecorationWidget } from './utils/create-decoration-widget.js'
|
|
5
5
|
|
|
6
6
|
export interface InvisibleNodeOptions {
|
|
7
7
|
content?: string
|
|
8
|
-
position?: (node: Node, pos: number) => number
|
|
8
|
+
position?: (node: Node, pos: number) => number
|
|
9
9
|
predicate: (value: Node) => boolean
|
|
10
10
|
priority?: number
|
|
11
|
-
type: string
|
|
11
|
+
type: string
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/** Default position for nodes is always at the end of the node */
|
|
@@ -19,7 +19,7 @@ export class InvisibleNode {
|
|
|
19
19
|
|
|
20
20
|
position: (node: Node, pos: number) => number
|
|
21
21
|
|
|
22
|
-
content
|
|
22
|
+
content?: string
|
|
23
23
|
|
|
24
24
|
type: string
|
|
25
25
|
|
package/src/plugin/reducers.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { PluginState } from '../types.js'
|
|
1
|
+
import type { PluginState } from '../types.js'
|
|
2
2
|
|
|
3
|
-
export const stateReducer = (
|
|
4
|
-
state: PluginState,
|
|
5
|
-
visible: boolean,
|
|
6
|
-
): PluginState => {
|
|
3
|
+
export const stateReducer = (state: PluginState, visible: boolean): PluginState => {
|
|
7
4
|
if (visible === undefined) {
|
|
8
5
|
return state
|
|
9
6
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export const createStyleTag = (style: string, nonce?: string): HTMLStyleElement => {
|
|
2
|
-
const tiptapStyleTag =
|
|
2
|
+
const tiptapStyleTag = <HTMLStyleElement>(
|
|
3
|
+
document.querySelector('style[data-tiptap-extension-invisible-characters-style]')
|
|
4
|
+
)
|
|
3
5
|
|
|
4
6
|
if (tiptapStyleTag !== null) {
|
|
5
7
|
return tiptapStyleTag
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { Transaction } from '@tiptap/pm/state'
|
|
1
|
+
import type { Transaction } from '@tiptap/pm/state'
|
|
2
2
|
|
|
3
|
-
type StepRange = [from: number, to: number]
|
|
3
|
+
type StepRange = [from: number, to: number]
|
|
4
4
|
|
|
5
5
|
export const getUpdatedRanges = ({ mapping }: Transaction): StepRange[] => {
|
|
6
6
|
const ranges: StepRange[] = []
|
|
7
7
|
|
|
8
8
|
mapping.maps.forEach((stepMap, i) => {
|
|
9
9
|
stepMap.forEach((_oldStart, _oldEnd, newStart, newEnd) => {
|
|
10
|
-
ranges.push([
|
|
11
|
-
mapping.slice(i + 1).map(newStart),
|
|
12
|
-
mapping.slice(i + 1).map(newEnd),
|
|
13
|
-
])
|
|
10
|
+
ranges.push([mapping.slice(i + 1).map(newStart), mapping.slice(i + 1).map(newEnd)])
|
|
14
11
|
})
|
|
15
12
|
})
|
|
16
13
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Node } from '@tiptap/pm/model'
|
|
1
|
+
import type { Node } from '@tiptap/pm/model'
|
|
2
2
|
|
|
3
|
-
import { Position } from '../../types.js'
|
|
3
|
+
import type { Position } from '../../types.js'
|
|
4
4
|
|
|
5
5
|
export const textBetween = (from: number, to: number, doc: Node) => {
|
|
6
6
|
const positions: Position[] = []
|
package/src/types.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { DecorationSet } from '@tiptap/pm/view'
|
|
1
|
+
import type { DecorationSet } from '@tiptap/pm/view'
|
|
2
2
|
|
|
3
|
-
import { InvisibleCharacter } from './plugin/InvisibleCharacter.js'
|
|
4
|
-
import { InvisibleNode } from './plugin/InvisibleNode.js'
|
|
3
|
+
import type { InvisibleCharacter } from './plugin/InvisibleCharacter.js'
|
|
4
|
+
import type { InvisibleNode } from './plugin/InvisibleNode.js'
|
|
5
5
|
|
|
6
6
|
export interface InvisibleCharactersOptions {
|
|
7
|
-
visible: boolean
|
|
8
|
-
builders: Array<InvisibleCharacter | InvisibleNode
|
|
9
|
-
injectCSS: boolean
|
|
10
|
-
injectNonce: string | undefined
|
|
7
|
+
visible: boolean
|
|
8
|
+
builders: Array<InvisibleCharacter | InvisibleNode>
|
|
9
|
+
injectCSS: boolean
|
|
10
|
+
injectNonce: string | undefined
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export interface Position {
|
|
14
|
-
pos: number
|
|
15
|
-
text: string
|
|
14
|
+
pos: number
|
|
15
|
+
text: string
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export interface PluginState {
|
|
19
|
-
visible: boolean
|
|
20
|
-
decorations: DecorationSet
|
|
19
|
+
visible: boolean
|
|
20
|
+
decorations: DecorationSet
|
|
21
21
|
}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAE/D,cAAc,2BAA2B,CAAA;AACzC,cAAc,4CAA4C,CAAA;AAC1D,cAAc,4CAA4C,CAAA;AAC1D,cAAc,wCAAwC,CAAA;AACtD,cAAc,gCAAgC,CAAA;AAC9C,cAAc,2BAA2B,CAAA;AACzC,cAAc,YAAY,CAAA;AAE1B,eAAe,mBAAmB,CAAA"}
|