@tiptap/extension-invisible-characters 2.24.1 → 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/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025, Tiptap GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
CHANGED
|
@@ -1,19 +1,52 @@
|
|
|
1
|
-
|
|
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);
|
|
2
19
|
|
|
3
|
-
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
HardBreakNode: () => HardBreakNode,
|
|
24
|
+
InvisibleCharacter: () => InvisibleCharacter,
|
|
25
|
+
InvisibleCharacters: () => InvisibleCharacters,
|
|
26
|
+
InvisibleNode: () => InvisibleNode,
|
|
27
|
+
ParagraphNode: () => ParagraphNode,
|
|
28
|
+
SpaceCharacter: () => SpaceCharacter,
|
|
29
|
+
default: () => index_default
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(index_exports);
|
|
4
32
|
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
var view = require('@tiptap/pm/view');
|
|
33
|
+
// src/invisible-characters.ts
|
|
34
|
+
var import_core = require("@tiptap/core");
|
|
8
35
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
36
|
+
// src/plugin/InvisibleCharactersPlugin.ts
|
|
37
|
+
var import_state = require("@tiptap/pm/state");
|
|
38
|
+
var import_view = require("@tiptap/pm/view");
|
|
39
|
+
|
|
40
|
+
// src/plugin/reducers.ts
|
|
41
|
+
var stateReducer = (state, visible) => {
|
|
42
|
+
if (visible === void 0) {
|
|
43
|
+
return state;
|
|
44
|
+
}
|
|
45
|
+
return { ...state, visible };
|
|
14
46
|
};
|
|
15
47
|
|
|
16
|
-
|
|
48
|
+
// src/plugin/style.ts
|
|
49
|
+
var style = `.Tiptap-invisible-character {
|
|
17
50
|
height: 0;
|
|
18
51
|
padding: 0;
|
|
19
52
|
pointer-events: none;
|
|
@@ -32,15 +65,15 @@ const style = `.Tiptap-invisible-character {
|
|
|
32
65
|
}
|
|
33
66
|
|
|
34
67
|
.Tiptap-invisible-character--space::before {
|
|
35
|
-
content: '
|
|
68
|
+
content: '\xB7'
|
|
36
69
|
}
|
|
37
70
|
|
|
38
71
|
.Tiptap-invisible-character--break::before {
|
|
39
|
-
content: '
|
|
72
|
+
content: '\xAC'
|
|
40
73
|
}
|
|
41
74
|
|
|
42
75
|
.Tiptap-invisible-character--paragraph::before {
|
|
43
|
-
content: '
|
|
76
|
+
content: '\xB6'
|
|
44
77
|
}
|
|
45
78
|
|
|
46
79
|
.Tiptap-invisible-character + img.ProseMirror-separator {
|
|
@@ -55,256 +88,262 @@ const style = `.Tiptap-invisible-character {
|
|
|
55
88
|
}
|
|
56
89
|
`;
|
|
57
90
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
91
|
+
// src/plugin/utils/create-style-tag.ts
|
|
92
|
+
var createStyleTag = (style2, nonce) => {
|
|
93
|
+
const tiptapStyleTag = document.querySelector("style[data-tiptap-extension-invisible-characters-style]");
|
|
94
|
+
if (tiptapStyleTag !== null) {
|
|
95
|
+
return tiptapStyleTag;
|
|
96
|
+
}
|
|
97
|
+
const styleNode = document.createElement("style");
|
|
98
|
+
if (nonce) {
|
|
99
|
+
styleNode.setAttribute("nonce", nonce);
|
|
100
|
+
}
|
|
101
|
+
styleNode.setAttribute("data-tiptap-extension-invisible-characters-style", "");
|
|
102
|
+
styleNode.innerHTML = style2;
|
|
103
|
+
document.getElementsByTagName("head")[0].appendChild(styleNode);
|
|
104
|
+
return styleNode;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// src/plugin/utils/get-updated-ranges.ts
|
|
108
|
+
var getUpdatedRanges = ({ mapping }) => {
|
|
109
|
+
const ranges = [];
|
|
110
|
+
mapping.maps.forEach((stepMap, i) => {
|
|
111
|
+
stepMap.forEach((_oldStart, _oldEnd, newStart, newEnd) => {
|
|
112
|
+
ranges.push([mapping.slice(i + 1).map(newStart), mapping.slice(i + 1).map(newEnd)]);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
return ranges;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// src/plugin/InvisibleCharactersPlugin.ts
|
|
119
|
+
var InvisibleCharactersPluginKey = new import_state.PluginKey("invisibleCharacters");
|
|
120
|
+
var InvisibleCharactersPlugin = (state, options) => {
|
|
121
|
+
const key = InvisibleCharactersPluginKey;
|
|
122
|
+
const emptyDecorationSet = import_view.DecorationSet.create(state.doc, []);
|
|
123
|
+
const addDecorationsBetweenPositions = (from, to, editorState, decorations) => {
|
|
124
|
+
return options.builders.sort((builderA, builderB) => {
|
|
125
|
+
if (builderA.priority > builderB.priority) {
|
|
126
|
+
return 1;
|
|
127
|
+
}
|
|
128
|
+
return -1;
|
|
129
|
+
}).reduce((newDecos, builder) => {
|
|
130
|
+
return builder.createDecoration(from, to, editorState.doc, newDecos);
|
|
131
|
+
}, decorations);
|
|
132
|
+
};
|
|
133
|
+
return new import_state.Plugin({
|
|
134
|
+
key,
|
|
135
|
+
state: {
|
|
136
|
+
init: () => {
|
|
137
|
+
const { $from, $to } = new import_state.AllSelection(state.doc);
|
|
138
|
+
if (options.injectCSS && document) {
|
|
139
|
+
createStyleTag(style, options.injectNonce);
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
visible: options.visible,
|
|
143
|
+
decorations: addDecorationsBetweenPositions($from.pos, $to.pos, state, import_view.DecorationSet.empty)
|
|
144
|
+
};
|
|
145
|
+
},
|
|
146
|
+
apply: (tr, pluginState, _, currentState) => {
|
|
147
|
+
const newPluginState = stateReducer(pluginState, tr.getMeta("setInvisibleCharactersVisible"));
|
|
148
|
+
const decorations = getUpdatedRanges(tr).reduce(
|
|
149
|
+
(nextDecorations, [from, to]) => {
|
|
150
|
+
return addDecorationsBetweenPositions(from, to, currentState, nextDecorations);
|
|
151
|
+
},
|
|
152
|
+
newPluginState.decorations.map(tr.mapping, tr.doc)
|
|
153
|
+
);
|
|
154
|
+
return {
|
|
155
|
+
...newPluginState,
|
|
156
|
+
decorations
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
props: {
|
|
161
|
+
decorations(editorState) {
|
|
162
|
+
const pluginState = this.getState(editorState);
|
|
163
|
+
const visible = pluginState == null ? void 0 : pluginState.visible;
|
|
164
|
+
const decorations = pluginState == null ? void 0 : pluginState.decorations;
|
|
165
|
+
return visible ? decorations : emptyDecorationSet;
|
|
166
|
+
}
|
|
62
167
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// src/plugin/utils/create-decoration-widget.ts
|
|
172
|
+
var import_view2 = require("@tiptap/pm/view");
|
|
173
|
+
var createDecorationWidget = (pos, type, content) => {
|
|
174
|
+
const createElement = () => {
|
|
175
|
+
const newElement = document.createElement("span");
|
|
176
|
+
newElement.classList.add("Tiptap-invisible-character");
|
|
177
|
+
newElement.classList.add(`Tiptap-invisible-character--${type}`);
|
|
178
|
+
if (content) {
|
|
179
|
+
newElement.textContent = content;
|
|
66
180
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
181
|
+
return newElement;
|
|
182
|
+
};
|
|
183
|
+
return import_view2.Decoration.widget(pos, createElement, {
|
|
184
|
+
key: type,
|
|
185
|
+
marks: [],
|
|
186
|
+
side: 1e3
|
|
187
|
+
});
|
|
71
188
|
};
|
|
72
189
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
190
|
+
// src/plugin/InvisibleNode.ts
|
|
191
|
+
var defaultPosition = (node, pos) => pos + node.nodeSize - 1;
|
|
192
|
+
var InvisibleNode = class {
|
|
193
|
+
constructor(options) {
|
|
194
|
+
this.predicate = options.predicate;
|
|
195
|
+
this.type = options.type;
|
|
196
|
+
this.position = options.position || defaultPosition;
|
|
197
|
+
this.content = options.content;
|
|
198
|
+
this.priority = options.priority || 100;
|
|
199
|
+
}
|
|
200
|
+
createDecoration(from, to, doc, decorations) {
|
|
201
|
+
let newDecorations = decorations;
|
|
202
|
+
doc.nodesBetween(from, to, (node, pos) => {
|
|
203
|
+
if (this.test(node)) {
|
|
204
|
+
const decorationPosition = this.position(node, pos);
|
|
205
|
+
const oldDecorations = newDecorations.find(
|
|
206
|
+
decorationPosition,
|
|
207
|
+
decorationPosition,
|
|
208
|
+
(spec) => spec.key === this.type
|
|
209
|
+
);
|
|
210
|
+
newDecorations = newDecorations.remove(oldDecorations).add(doc, [createDecorationWidget(decorationPosition, this.type, this.content)]);
|
|
211
|
+
}
|
|
82
212
|
});
|
|
83
|
-
return
|
|
213
|
+
return newDecorations;
|
|
214
|
+
}
|
|
215
|
+
test(value) {
|
|
216
|
+
return this.predicate(value);
|
|
217
|
+
}
|
|
84
218
|
};
|
|
85
219
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (builderA.priority > builderB.priority) {
|
|
93
|
-
return 1;
|
|
94
|
-
}
|
|
95
|
-
return -1;
|
|
96
|
-
}).reduce((newDecos, builder) => {
|
|
97
|
-
return builder.createDecoration(from, to, editorState.doc, newDecos);
|
|
98
|
-
}, decorations);
|
|
99
|
-
};
|
|
100
|
-
return new state.Plugin({
|
|
101
|
-
key,
|
|
102
|
-
state: {
|
|
103
|
-
init: () => {
|
|
104
|
-
const { $from, $to } = new state.AllSelection(state$1.doc);
|
|
105
|
-
if (options.injectCSS && document) {
|
|
106
|
-
createStyleTag(style, options.injectNonce);
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
visible: options.visible,
|
|
110
|
-
decorations: addDecorationsBetweenPositions($from.pos, $to.pos, state$1, view.DecorationSet.empty),
|
|
111
|
-
};
|
|
112
|
-
},
|
|
113
|
-
apply: (tr, pluginState, _, currentState) => {
|
|
114
|
-
const newPluginState = stateReducer(pluginState, tr.getMeta('setInvisibleCharactersVisible'));
|
|
115
|
-
const decorations = getUpdatedRanges(tr).reduce((nextDecorations, [from, to]) => {
|
|
116
|
-
return addDecorationsBetweenPositions(from, to, currentState, nextDecorations);
|
|
117
|
-
}, newPluginState.decorations.map(tr.mapping, tr.doc));
|
|
118
|
-
return {
|
|
119
|
-
...newPluginState,
|
|
120
|
-
decorations,
|
|
121
|
-
};
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
props: {
|
|
125
|
-
decorations(editorState) {
|
|
126
|
-
const pluginState = this.getState(editorState);
|
|
127
|
-
const visible = pluginState === null || pluginState === void 0 ? void 0 : pluginState.visible;
|
|
128
|
-
const decorations = pluginState === null || pluginState === void 0 ? void 0 : pluginState.decorations;
|
|
129
|
-
return visible ? decorations : emptyDecorationSet;
|
|
130
|
-
},
|
|
131
|
-
},
|
|
220
|
+
// src/plugin/invisible-characters/hardBreak.ts
|
|
221
|
+
var HardBreakNode = class extends InvisibleNode {
|
|
222
|
+
constructor() {
|
|
223
|
+
super({
|
|
224
|
+
type: "break",
|
|
225
|
+
predicate: (node) => node.type === node.type.schema.nodes.hardBreak
|
|
132
226
|
});
|
|
227
|
+
}
|
|
133
228
|
};
|
|
134
229
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
newElement.textContent = content;
|
|
142
|
-
}
|
|
143
|
-
return newElement;
|
|
144
|
-
};
|
|
145
|
-
// return Decoration.inline(pos - 1, pos, {
|
|
146
|
-
// class: `Tiptap-invisible-character Tiptap-invisible-character--${type}`,
|
|
147
|
-
// })
|
|
148
|
-
return view.Decoration.widget(pos, createElement, {
|
|
149
|
-
key: type,
|
|
150
|
-
marks: [],
|
|
151
|
-
side: 1000,
|
|
230
|
+
// src/plugin/invisible-characters/paragraph.ts
|
|
231
|
+
var ParagraphNode = class extends InvisibleNode {
|
|
232
|
+
constructor() {
|
|
233
|
+
super({
|
|
234
|
+
type: "paragraph",
|
|
235
|
+
predicate: (node) => node.type === node.type.schema.nodes.paragraph
|
|
152
236
|
});
|
|
237
|
+
}
|
|
153
238
|
};
|
|
154
239
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
let newDecorations = decorations;
|
|
167
|
-
doc.nodesBetween(from, to, (node, pos) => {
|
|
168
|
-
if (this.test(node)) {
|
|
169
|
-
const decorationPosition = this.position(node, pos);
|
|
170
|
-
const oldDecorations = newDecorations.find(decorationPosition, decorationPosition, spec => spec.key === this.type);
|
|
171
|
-
newDecorations = newDecorations
|
|
172
|
-
.remove(oldDecorations)
|
|
173
|
-
.add(doc, [createDecorationWidget(decorationPosition, this.type, this.content)]);
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
return newDecorations;
|
|
177
|
-
}
|
|
178
|
-
test(value) {
|
|
179
|
-
return this.predicate(value);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
class HardBreakNode extends InvisibleNode {
|
|
184
|
-
constructor() {
|
|
185
|
-
super({
|
|
186
|
-
type: 'break',
|
|
187
|
-
predicate: node => node.type === node.type.schema.nodes.hardBreak,
|
|
188
|
-
});
|
|
240
|
+
// src/plugin/utils/text-between.ts
|
|
241
|
+
var textBetween = (from, to, doc) => {
|
|
242
|
+
const positions = [];
|
|
243
|
+
doc.nodesBetween(from, to, (node, pos) => {
|
|
244
|
+
var _a;
|
|
245
|
+
if (node.isText) {
|
|
246
|
+
const offset = Math.max(from, pos) - pos;
|
|
247
|
+
positions.push({
|
|
248
|
+
pos: pos + offset,
|
|
249
|
+
text: ((_a = node.text) == null ? void 0 : _a.slice(offset, to - pos)) || ""
|
|
250
|
+
});
|
|
189
251
|
}
|
|
190
|
-
}
|
|
252
|
+
});
|
|
253
|
+
return positions;
|
|
254
|
+
};
|
|
191
255
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
256
|
+
// src/plugin/InvisibleCharacter.ts
|
|
257
|
+
var InvisibleCharacter = class {
|
|
258
|
+
constructor(options) {
|
|
259
|
+
this.predicate = options.predicate;
|
|
260
|
+
this.type = options.type;
|
|
261
|
+
this.content = options.content;
|
|
262
|
+
this.priority = options.priority || 100;
|
|
263
|
+
}
|
|
264
|
+
createDecoration(from, to, doc, decorations) {
|
|
265
|
+
const textContent = textBetween(from, to, doc);
|
|
266
|
+
return textContent.reduce((oldDecorations, currentPosition) => {
|
|
267
|
+
return currentPosition.text.split("").reduce((innerDecorations, char, i) => {
|
|
268
|
+
return this.test(char) ? innerDecorations.add(doc, [createDecorationWidget(currentPosition.pos + i, this.type, this.content)]) : innerDecorations;
|
|
269
|
+
}, oldDecorations);
|
|
270
|
+
}, decorations);
|
|
271
|
+
}
|
|
272
|
+
test(value) {
|
|
273
|
+
return this.predicate(value);
|
|
274
|
+
}
|
|
275
|
+
};
|
|
200
276
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
positions.push({
|
|
208
|
-
pos: pos + offset,
|
|
209
|
-
text: ((_a = node.text) === null || _a === void 0 ? void 0 : _a.slice(offset, to - pos)) || '',
|
|
210
|
-
});
|
|
211
|
-
}
|
|
277
|
+
// src/plugin/invisible-characters/space.ts
|
|
278
|
+
var SpaceCharacter = class extends InvisibleCharacter {
|
|
279
|
+
constructor() {
|
|
280
|
+
super({
|
|
281
|
+
type: "space",
|
|
282
|
+
predicate: (char) => char === " "
|
|
212
283
|
});
|
|
213
|
-
|
|
284
|
+
}
|
|
214
285
|
};
|
|
215
286
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
},
|
|
266
|
-
addStorage() {
|
|
267
|
-
return {
|
|
268
|
-
visibility: () => this.options.visible,
|
|
269
|
-
};
|
|
270
|
-
},
|
|
271
|
-
onBeforeCreate() {
|
|
272
|
-
this.storage.visibility = () => {
|
|
273
|
-
var _a;
|
|
274
|
-
return (_a = InvisibleCharactersPluginKey.getState(this.editor.state)) === null || _a === void 0 ? void 0 : _a.visible;
|
|
275
|
-
};
|
|
276
|
-
},
|
|
277
|
-
addCommands() {
|
|
278
|
-
return {
|
|
279
|
-
showInvisibleCharacters: (visibility = true) => ({ dispatch, tr }) => {
|
|
280
|
-
if (dispatch) {
|
|
281
|
-
tr.setMeta('setInvisibleCharactersVisible', visibility);
|
|
282
|
-
}
|
|
283
|
-
return true;
|
|
284
|
-
},
|
|
285
|
-
hideInvisibleCharacters: () => ({ dispatch, tr }) => {
|
|
286
|
-
if (dispatch) {
|
|
287
|
-
tr.setMeta('setInvisibleCharactersVisible', false);
|
|
288
|
-
}
|
|
289
|
-
return true;
|
|
290
|
-
},
|
|
291
|
-
toggleInvisibleCharacters: () => ({ dispatch, tr, state }) => {
|
|
292
|
-
var _a;
|
|
293
|
-
const visibility = !((_a = InvisibleCharactersPluginKey.getState(state)) === null || _a === void 0 ? void 0 : _a.visible);
|
|
294
|
-
if (dispatch) {
|
|
295
|
-
tr.setMeta('setInvisibleCharactersVisible', visibility);
|
|
296
|
-
}
|
|
297
|
-
return true;
|
|
298
|
-
},
|
|
299
|
-
};
|
|
300
|
-
},
|
|
287
|
+
// src/invisible-characters.ts
|
|
288
|
+
var InvisibleCharacters = import_core.Extension.create({
|
|
289
|
+
name: "invisibleCharacters",
|
|
290
|
+
addOptions() {
|
|
291
|
+
return {
|
|
292
|
+
visible: true,
|
|
293
|
+
builders: [new SpaceCharacter(), new ParagraphNode(), new HardBreakNode()],
|
|
294
|
+
injectCSS: true,
|
|
295
|
+
injectNonce: void 0
|
|
296
|
+
};
|
|
297
|
+
},
|
|
298
|
+
addProseMirrorPlugins() {
|
|
299
|
+
return [InvisibleCharactersPlugin(this.editor.state, this.options)];
|
|
300
|
+
},
|
|
301
|
+
addStorage() {
|
|
302
|
+
return {
|
|
303
|
+
visibility: () => this.options.visible
|
|
304
|
+
};
|
|
305
|
+
},
|
|
306
|
+
onBeforeCreate() {
|
|
307
|
+
this.storage.visibility = () => {
|
|
308
|
+
var _a;
|
|
309
|
+
return (_a = InvisibleCharactersPluginKey.getState(this.editor.state)) == null ? void 0 : _a.visible;
|
|
310
|
+
};
|
|
311
|
+
},
|
|
312
|
+
addCommands() {
|
|
313
|
+
return {
|
|
314
|
+
showInvisibleCharacters: (visibility = true) => ({ dispatch, tr }) => {
|
|
315
|
+
if (dispatch) {
|
|
316
|
+
tr.setMeta("setInvisibleCharactersVisible", visibility);
|
|
317
|
+
}
|
|
318
|
+
return true;
|
|
319
|
+
},
|
|
320
|
+
hideInvisibleCharacters: () => ({ dispatch, tr }) => {
|
|
321
|
+
if (dispatch) {
|
|
322
|
+
tr.setMeta("setInvisibleCharactersVisible", false);
|
|
323
|
+
}
|
|
324
|
+
return true;
|
|
325
|
+
},
|
|
326
|
+
toggleInvisibleCharacters: () => ({ dispatch, tr, state }) => {
|
|
327
|
+
var _a;
|
|
328
|
+
const visibility = !((_a = InvisibleCharactersPluginKey.getState(state)) == null ? void 0 : _a.visible);
|
|
329
|
+
if (dispatch) {
|
|
330
|
+
tr.setMeta("setInvisibleCharactersVisible", visibility);
|
|
331
|
+
}
|
|
332
|
+
return true;
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
}
|
|
301
336
|
});
|
|
302
337
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
exports
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
338
|
+
// src/index.ts
|
|
339
|
+
var index_default = InvisibleCharacters;
|
|
340
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
341
|
+
0 && (module.exports = {
|
|
342
|
+
HardBreakNode,
|
|
343
|
+
InvisibleCharacter,
|
|
344
|
+
InvisibleCharacters,
|
|
345
|
+
InvisibleNode,
|
|
346
|
+
ParagraphNode,
|
|
347
|
+
SpaceCharacter
|
|
348
|
+
});
|
|
349
|
+
//# sourceMappingURL=index.cjs.map
|