@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.
Files changed (50) hide show
  1. package/LICENSE.md +21 -0
  2. package/dist/index.cjs +285 -246
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +86 -0
  5. package/dist/index.d.ts +86 -10
  6. package/dist/index.js +255 -238
  7. package/dist/index.js.map +1 -1
  8. package/package.json +13 -9
  9. package/src/invisible-characters.ts +39 -43
  10. package/src/plugin/InvisibleCharacter.ts +3 -3
  11. package/src/plugin/InvisibleCharactersPlugin.ts +19 -16
  12. package/src/plugin/InvisibleNode.ts +5 -5
  13. package/src/plugin/reducers.ts +2 -5
  14. package/src/plugin/utils/create-style-tag.ts +3 -1
  15. package/src/plugin/utils/get-updated-ranges.ts +3 -6
  16. package/src/plugin/utils/text-between.ts +2 -2
  17. package/src/types.ts +11 -11
  18. package/dist/index.d.ts.map +0 -1
  19. package/dist/index.umd.js +0 -312
  20. package/dist/index.umd.js.map +0 -1
  21. package/dist/invisible-characters.d.ts +0 -27
  22. package/dist/invisible-characters.d.ts.map +0 -1
  23. package/dist/plugin/InvisibleCharacter.d.ts +0 -19
  24. package/dist/plugin/InvisibleCharacter.d.ts.map +0 -1
  25. package/dist/plugin/InvisibleCharactersPlugin.d.ts +0 -10
  26. package/dist/plugin/InvisibleCharactersPlugin.d.ts.map +0 -1
  27. package/dist/plugin/InvisibleNode.d.ts +0 -21
  28. package/dist/plugin/InvisibleNode.d.ts.map +0 -1
  29. package/dist/plugin/index.d.ts +0 -2
  30. package/dist/plugin/index.d.ts.map +0 -1
  31. package/dist/plugin/invisible-characters/hardBreak.d.ts +0 -6
  32. package/dist/plugin/invisible-characters/hardBreak.d.ts.map +0 -1
  33. package/dist/plugin/invisible-characters/paragraph.d.ts +0 -6
  34. package/dist/plugin/invisible-characters/paragraph.d.ts.map +0 -1
  35. package/dist/plugin/invisible-characters/space.d.ts +0 -6
  36. package/dist/plugin/invisible-characters/space.d.ts.map +0 -1
  37. package/dist/plugin/reducers.d.ts +0 -4
  38. package/dist/plugin/reducers.d.ts.map +0 -1
  39. package/dist/plugin/style.d.ts +0 -3
  40. package/dist/plugin/style.d.ts.map +0 -1
  41. package/dist/plugin/utils/create-decoration-widget.d.ts +0 -4
  42. package/dist/plugin/utils/create-decoration-widget.d.ts.map +0 -1
  43. package/dist/plugin/utils/create-style-tag.d.ts +0 -3
  44. package/dist/plugin/utils/create-style-tag.d.ts.map +0 -1
  45. package/dist/plugin/utils/get-updated-ranges.d.ts +0 -5
  46. package/dist/plugin/utils/get-updated-ranges.d.ts.map +0 -1
  47. package/dist/plugin/utils/text-between.d.ts +0 -5
  48. package/dist/plugin/utils/text-between.d.ts.map +0 -1
  49. package/dist/types.d.ts +0 -18
  50. 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
- 'use strict';
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
- Object.defineProperty(exports, '__esModule', { value: true });
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
- var core = require('@tiptap/core');
6
- var state = require('@tiptap/pm/state');
7
- var view = require('@tiptap/pm/view');
33
+ // src/invisible-characters.ts
34
+ var import_core = require("@tiptap/core");
8
35
 
9
- const stateReducer = (state, visible) => {
10
- if (visible === undefined) {
11
- return state;
12
- }
13
- return { ...state, visible };
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
- const style = `.Tiptap-invisible-character {
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
- const createStyleTag = (style, nonce) => {
59
- const tiptapStyleTag = document.querySelector('style[data-tiptap-extension-invisible-characters-style]');
60
- if (tiptapStyleTag !== null) {
61
- return tiptapStyleTag;
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
- const styleNode = document.createElement('style');
64
- if (nonce) {
65
- styleNode.setAttribute('nonce', nonce);
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
- styleNode.setAttribute('data-tiptap-extension-invisible-characters-style', '');
68
- styleNode.innerHTML = style;
69
- document.getElementsByTagName('head')[0].appendChild(styleNode);
70
- return styleNode;
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
- const getUpdatedRanges = ({ mapping }) => {
74
- const ranges = [];
75
- mapping.maps.forEach((stepMap, i) => {
76
- stepMap.forEach((_oldStart, _oldEnd, newStart, newEnd) => {
77
- ranges.push([
78
- mapping.slice(i + 1).map(newStart),
79
- mapping.slice(i + 1).map(newEnd),
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 ranges;
213
+ return newDecorations;
214
+ }
215
+ test(value) {
216
+ return this.predicate(value);
217
+ }
84
218
  };
85
219
 
86
- const InvisibleCharactersPluginKey = new state.PluginKey('invisibleCharacters');
87
- const InvisibleCharactersPlugin = (state$1, options) => {
88
- const key = InvisibleCharactersPluginKey;
89
- const emptyDecorationSet = view.DecorationSet.create(state$1.doc, []);
90
- const addDecorationsBetweenPositions = (from, to, editorState, decorations) => {
91
- return options.builders.sort((builderA, builderB) => {
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
- const createDecorationWidget = (pos, type, content) => {
136
- const createElement = () => {
137
- const newElement = document.createElement('span');
138
- newElement.classList.add('Tiptap-invisible-character');
139
- newElement.classList.add(`Tiptap-invisible-character--${type}`);
140
- if (content) {
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
- /** Default position for nodes is always at the end of the node */
156
- const defaultPosition = (node, pos) => pos + node.nodeSize - 1;
157
- class InvisibleNode {
158
- constructor(options) {
159
- this.predicate = options.predicate;
160
- this.type = options.type;
161
- this.position = options.position || defaultPosition;
162
- this.content = options.content;
163
- this.priority = options.priority || 100;
164
- }
165
- createDecoration(from, to, doc, decorations) {
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
- class ParagraphNode extends InvisibleNode {
193
- constructor() {
194
- super({
195
- type: 'paragraph',
196
- predicate: node => node.type === node.type.schema.nodes.paragraph,
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
- const textBetween = (from, to, doc) => {
202
- const positions = [];
203
- doc.nodesBetween(from, to, (node, pos) => {
204
- var _a;
205
- if (node.isText) {
206
- const offset = Math.max(from, pos) - pos;
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
- return positions;
284
+ }
214
285
  };
215
286
 
216
- class InvisibleCharacter {
217
- constructor(options) {
218
- this.predicate = options.predicate;
219
- this.type = options.type;
220
- this.content = options.content;
221
- this.priority = options.priority || 100;
222
- }
223
- createDecoration(from, to, doc, decorations) {
224
- const textContent = textBetween(from, to, doc);
225
- return textContent.reduce((oldDecorations, currentPosition) => {
226
- return currentPosition.text.split('').reduce((innerDecorations, char, i) => {
227
- return this.test(char)
228
- ? innerDecorations.add(doc, [createDecorationWidget(currentPosition.pos + i, this.type, this.content)])
229
- : innerDecorations;
230
- }, oldDecorations);
231
- }, decorations);
232
- }
233
- test(value) {
234
- return this.predicate(value);
235
- }
236
- }
237
-
238
- class SpaceCharacter extends InvisibleCharacter {
239
- constructor() {
240
- super({
241
- type: 'space',
242
- predicate: (char) => char === ' ',
243
- });
244
- }
245
- }
246
-
247
- const InvisibleCharacters = core.Extension.create({
248
- name: 'invisibleCharacters',
249
- addOptions() {
250
- return {
251
- visible: true,
252
- builders: [
253
- new SpaceCharacter(),
254
- new ParagraphNode(),
255
- new HardBreakNode(),
256
- ],
257
- injectCSS: true,
258
- injectNonce: undefined,
259
- };
260
- },
261
- addProseMirrorPlugins() {
262
- return [
263
- InvisibleCharactersPlugin(this.editor.state, this.options),
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
- exports.HardBreakNode = HardBreakNode;
304
- exports.InvisibleCharacter = InvisibleCharacter;
305
- exports.InvisibleCharacters = InvisibleCharacters;
306
- exports.InvisibleNode = InvisibleNode;
307
- exports.ParagraphNode = ParagraphNode;
308
- exports.SpaceCharacter = SpaceCharacter;
309
- exports.default = InvisibleCharacters;
310
- //# sourceMappingURL=index.cjs.map
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