@tiptap/extension-invisible-characters 2.24.2 → 3.0.0-beta.11

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
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/plugin/reducers.ts","../src/plugin/style.ts","../src/plugin/utils/create-style-tag.ts","../src/plugin/utils/get-updated-ranges.ts","../src/plugin/InvisibleCharactersPlugin.ts","../src/plugin/utils/create-decoration-widget.ts","../src/plugin/InvisibleNode.ts","../src/plugin/invisible-characters/hardBreak.ts","../src/plugin/invisible-characters/paragraph.ts","../src/plugin/utils/text-between.ts","../src/plugin/InvisibleCharacter.ts","../src/plugin/invisible-characters/space.ts","../src/invisible-characters.ts"],"sourcesContent":["import { PluginState } from '../types.js'\n\nexport const stateReducer = (\n state: PluginState,\n visible: boolean,\n): PluginState => {\n if (visible === undefined) {\n return state\n }\n\n return { ...state, visible }\n}\n\nexport default stateReducer\n","export const style = `.Tiptap-invisible-character {\n height: 0;\n padding: 0;\n pointer-events: none;\n user-select: none;\n width: 0;\n}\n\n.Tiptap-invisible-character::before {\n caret-color: inherit;\n color: #aaa;\n display: inline-block;\n font-style: normal;\n font-weight: 400;\n line-height: 1em;\n width: 0;\n}\n\n.Tiptap-invisible-character--space::before {\n content: '·'\n}\n\n.Tiptap-invisible-character--break::before {\n content: '¬'\n}\n\n.Tiptap-invisible-character--paragraph::before {\n content: '¶'\n}\n\n.Tiptap-invisible-character + img.ProseMirror-separator {\n height: 0 !important;\n pointer-events: none;\n user-select: none;\n width: 0 !important;\n}\n\n.is-empty[data-placeholder].has-focus > .Tiptap-invisible-character {\n display: none;\n}\n`\n\nexport default style\n","export const createStyleTag = (style: string, nonce?: string): HTMLStyleElement => {\n const tiptapStyleTag = (<HTMLStyleElement>document.querySelector('style[data-tiptap-extension-invisible-characters-style]'))\n\n if (tiptapStyleTag !== null) {\n return tiptapStyleTag\n }\n\n const styleNode = document.createElement('style')\n\n if (nonce) {\n styleNode.setAttribute('nonce', nonce)\n }\n\n styleNode.setAttribute('data-tiptap-extension-invisible-characters-style', '')\n styleNode.innerHTML = style\n document.getElementsByTagName('head')[0].appendChild(styleNode)\n\n return styleNode\n}\n\nexport default createStyleTag\n","import { Transaction } from '@tiptap/pm/state'\n\ntype StepRange = [from: number, to: number];\n\nexport const getUpdatedRanges = ({ mapping }: Transaction): StepRange[] => {\n const ranges: StepRange[] = []\n\n mapping.maps.forEach((stepMap, i) => {\n stepMap.forEach((_oldStart, _oldEnd, newStart, newEnd) => {\n ranges.push([\n mapping.slice(i + 1).map(newStart),\n mapping.slice(i + 1).map(newEnd),\n ])\n })\n })\n\n return ranges\n}\n\nexport default getUpdatedRanges\n","import {\n AllSelection, EditorState, Plugin, PluginKey,\n} from '@tiptap/pm/state'\nimport { DecorationSet } from '@tiptap/pm/view'\n\nimport { InvisibleCharactersOptions, PluginState } from '../types.js'\nimport { stateReducer } from './reducers.js'\nimport { style } from './style.js'\nimport { createStyleTag } from './utils/create-style-tag.js'\nimport { getUpdatedRanges } from './utils/get-updated-ranges.js'\n\nexport const InvisibleCharactersPluginKey = new PluginKey<PluginState>('invisibleCharacters')\n\nexport const InvisibleCharactersPlugin = (state: EditorState, options: InvisibleCharactersOptions) => {\n const key = InvisibleCharactersPluginKey\n const emptyDecorationSet = DecorationSet.create(state.doc, [])\n\n const addDecorationsBetweenPositions = (\n from: number,\n to: number,\n editorState: EditorState,\n decorations: DecorationSet,\n ) => {\n return options.builders.sort((builderA, builderB) => {\n if (builderA.priority > builderB.priority) {\n return 1\n }\n\n return -1\n }).reduce((newDecos, builder) => {\n return builder.createDecoration(from, to, editorState.doc, newDecos)\n }, decorations)\n }\n\n return new Plugin({\n key,\n\n state: {\n init: () => {\n const { $from, $to } = new AllSelection(state.doc)\n\n if (options.injectCSS && document) {\n createStyleTag(style, options.injectNonce)\n }\n\n return {\n visible: options.visible,\n decorations: addDecorationsBetweenPositions($from.pos, $to.pos, state, DecorationSet.empty),\n }\n },\n apply: (tr, pluginState, _, currentState) => {\n const newPluginState = stateReducer(pluginState, tr.getMeta('setInvisibleCharactersVisible'))\n\n const decorations = getUpdatedRanges(tr).reduce((nextDecorations, [from, to]) => {\n return addDecorationsBetweenPositions(from, to, currentState, nextDecorations)\n }, newPluginState.decorations.map(tr.mapping, tr.doc))\n\n return {\n ...newPluginState,\n decorations,\n }\n },\n },\n\n props: {\n decorations(editorState) {\n const pluginState = this.getState(editorState)\n\n const visible = pluginState?.visible\n const decorations = pluginState?.decorations\n\n return visible ? decorations : emptyDecorationSet\n },\n },\n\n })\n}\n\nexport default InvisibleCharactersPlugin\n","import { Decoration } from '@tiptap/pm/view'\n\nexport const createDecorationWidget = (pos: number, type: string, content?: string) => {\n const createElement = () => {\n const newElement = document.createElement('span')\n\n newElement.classList.add('Tiptap-invisible-character')\n newElement.classList.add(`Tiptap-invisible-character--${type}`)\n\n if (content) {\n newElement.textContent = content\n }\n\n return newElement\n }\n\n // return Decoration.inline(pos - 1, pos, {\n // class: `Tiptap-invisible-character Tiptap-invisible-character--${type}`,\n // })\n\n return Decoration.widget(pos, createElement, {\n key: type,\n marks: [],\n side: 1000,\n })\n}\n\nexport default createDecorationWidget\n","import { Node } from '@tiptap/pm/model'\nimport { DecorationSet } from '@tiptap/pm/view'\n\nimport { createDecorationWidget } from './utils/create-decoration-widget.js'\n\nexport interface InvisibleNodeOptions {\n content?: string\n position?: (node: Node, pos: number) => number;\n predicate: (value: Node) => boolean\n priority?: number\n type: string;\n}\n\n/** Default position for nodes is always at the end of the node */\nconst defaultPosition = (node: Node, pos: number) => pos + node.nodeSize - 1\n\nexport class InvisibleNode {\n predicate: (value: Node) => boolean\n\n position: (node: Node, pos: number) => number\n\n content ?: string\n\n type: string\n\n priority: number\n\n constructor(options: InvisibleNodeOptions) {\n this.predicate = options.predicate\n this.type = options.type\n this.position = options.position || defaultPosition\n this.content = options.content\n this.priority = options.priority || 100\n }\n\n createDecoration(from: number, to: number, doc: Node, decorations: DecorationSet) {\n let newDecorations = decorations\n\n doc.nodesBetween(from, to, (node, pos) => {\n if (this.test(node)) {\n const decorationPosition = this.position(node, pos)\n const oldDecorations = newDecorations.find(\n decorationPosition,\n decorationPosition,\n spec => spec.key === this.type,\n )\n\n newDecorations = newDecorations\n .remove(oldDecorations)\n .add(doc, [createDecorationWidget(decorationPosition, this.type, this.content)])\n }\n })\n return newDecorations\n }\n\n test(value: Node) {\n return this.predicate(value)\n }\n}\n\nexport default InvisibleNode\n","import { InvisibleNode } from '../InvisibleNode.js'\n\nexport class HardBreakNode extends InvisibleNode {\n constructor() {\n super({\n type: 'break',\n predicate: node => node.type === node.type.schema.nodes.hardBreak,\n })\n }\n}\n\nexport default HardBreakNode\n","import { InvisibleNode } from '../InvisibleNode.js'\n\nexport class ParagraphNode extends InvisibleNode {\n constructor() {\n super({\n type: 'paragraph',\n predicate: node => node.type === node.type.schema.nodes.paragraph,\n })\n }\n}\n\nexport default ParagraphNode\n","import { Node } from '@tiptap/pm/model'\n\nimport { Position } from '../../types.js'\n\nexport const textBetween = (from: number, to: number, doc: Node) => {\n const positions: Position[] = []\n\n doc.nodesBetween(from, to, (node, pos) => {\n if (node.isText) {\n const offset = Math.max(from, pos) - pos\n\n positions.push({\n pos: pos + offset,\n text: node.text?.slice(offset, to - pos) || '',\n })\n }\n })\n\n return positions\n}\n\nexport default textBetween\n","import { Node } from '@tiptap/pm/model'\nimport { DecorationSet } from '@tiptap/pm/view'\n\nimport { createDecorationWidget } from './utils/create-decoration-widget.js'\nimport { textBetween } from './utils/text-between.js'\n\nexport interface InvisibleCharacterOptions {\n type: string;\n predicate: (value: string) => boolean\n priority?: number\n content?: string\n}\n\nexport class InvisibleCharacter {\n predicate: (value: string) => boolean\n\n content?: string\n\n type: string\n\n priority: number\n\n constructor(options: InvisibleCharacterOptions) {\n this.predicate = options.predicate\n this.type = options.type\n this.content = options.content\n this.priority = options.priority || 100\n }\n\n createDecoration(from: number, to: number, doc: Node, decorations: DecorationSet) {\n const textContent = textBetween(from, to, doc)\n\n return textContent.reduce((oldDecorations, currentPosition) => {\n return currentPosition.text.split('').reduce((innerDecorations, char, i) => {\n return this.test(char)\n ? innerDecorations.add(doc, [createDecorationWidget(currentPosition.pos + i, this.type, this.content)])\n : innerDecorations\n }, oldDecorations)\n }, decorations)\n }\n\n test(value: string) {\n return this.predicate(value)\n }\n}\n\nexport default InvisibleCharacter\n","import { InvisibleCharacter } from '../InvisibleCharacter.js'\n\nexport class SpaceCharacter extends InvisibleCharacter {\n constructor() {\n super({\n type: 'space',\n predicate: (char: string) => char === ' ',\n })\n }\n}\n\nexport default SpaceCharacter\n","import { Extension } from '@tiptap/core'\n\nimport { InvisibleCharactersPlugin, InvisibleCharactersPluginKey } from './plugin/index.js'\nimport { HardBreakNode } from './plugin/invisible-characters/hardBreak.js'\nimport { ParagraphNode } from './plugin/invisible-characters/paragraph.js'\nimport { SpaceCharacter } from './plugin/invisible-characters/space.js'\nimport { InvisibleCharactersOptions } from './types.js'\n\nexport {\n HardBreakNode,\n ParagraphNode,\n SpaceCharacter,\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n invisibleCharacters: {\n /**\n * Show invisible characters\n */\n showInvisibleCharacters: (show?: boolean) => ReturnType\n\n /**\n * Hide invisible characters\n */\n hideInvisibleCharacters: () => ReturnType\n\n /**\n * Toggle invisible characters\n */\n toggleInvisibleCharacters: () => ReturnType\n }\n }\n}\n\nexport const InvisibleCharacters = Extension.create<InvisibleCharactersOptions>({\n name: 'invisibleCharacters',\n\n addOptions() {\n return {\n visible: true,\n builders: [\n new SpaceCharacter(),\n new ParagraphNode(),\n new HardBreakNode(),\n ],\n injectCSS: true,\n injectNonce: undefined,\n }\n },\n\n addProseMirrorPlugins() {\n return [\n InvisibleCharactersPlugin(this.editor.state, this.options),\n ]\n },\n\n addStorage() {\n return {\n visibility: () => this.options.visible,\n }\n },\n\n onBeforeCreate() {\n this.storage.visibility = () => {\n return InvisibleCharactersPluginKey.getState(this.editor.state)?.visible\n }\n },\n\n addCommands() {\n return {\n showInvisibleCharacters: (visibility = true) => ({ dispatch, tr }) => {\n if (dispatch) {\n tr.setMeta('setInvisibleCharactersVisible', visibility)\n }\n\n return true\n },\n hideInvisibleCharacters: () => ({ dispatch, tr }) => {\n if (dispatch) {\n tr.setMeta('setInvisibleCharactersVisible', false)\n }\n\n return true\n },\n toggleInvisibleCharacters: () => ({ dispatch, tr, state }) => {\n const visibility = !InvisibleCharactersPluginKey.getState(state)?.visible\n\n if (dispatch) {\n tr.setMeta('setInvisibleCharactersVisible', visibility)\n }\n\n return true\n },\n }\n },\n})\n\nexport default InvisibleCharacters\n"],"names":["PluginKey","state","DecorationSet","Plugin","AllSelection","Decoration","Extension"],"mappings":";;;;;;;;AAEO,MAAM,YAAY,GAAG,CAC1B,KAAkB,EAClB,OAAgB,KACD;AACf,IAAA,IAAI,OAAO,KAAK,SAAS,EAAE;AACzB,QAAA,OAAO,KAAK;;AAGd,IAAA,OAAO,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE;AAC9B,CAAC;;ACXM,MAAM,KAAK,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwCpB;;ACxCM,MAAM,cAAc,GAAG,CAAC,KAAa,EAAE,KAAc,KAAs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AA,OAAO,IAAI;aACZ;YACD,uBAAuB,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAI;gBAClD,IAAI,QAAQ,EAAE;AACZ,oBAAA,EAAE,CAAC,OAAO,CAAC,+BAA+B,EAAE,KAAK,CAAC;;AAGpD,gBAAA,OAAO,IAAI;aACZ;AACD,YAAA,yBAAyB,EAAE,MAAM,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,KAAI;;AAC3D,gBAAA,MAAM,UAAU,GAAG,EAAC,MAAA,4BAA4B,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAE,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,OAAO,CAAA;gBAEzE,IAAI,QAAQ,EAAE;AACZ,oBAAA,EAAE,CAAC,OAAO,CAAC,+BAA+B,EAAE,UAAU,CAAC;;AAGzD,gBAAA,OAAO,IAAI;aACZ;SACF;KACF;AACF,CAAA;;;;;;;;;;"}
1
+ {"version":3,"sources":["../src/index.ts","../src/invisible-characters.ts","../src/plugin/InvisibleCharactersPlugin.ts","../src/plugin/reducers.ts","../src/plugin/style.ts","../src/plugin/utils/create-style-tag.ts","../src/plugin/utils/get-updated-ranges.ts","../src/plugin/utils/create-decoration-widget.ts","../src/plugin/InvisibleNode.ts","../src/plugin/invisible-characters/hardBreak.ts","../src/plugin/invisible-characters/paragraph.ts","../src/plugin/utils/text-between.ts","../src/plugin/InvisibleCharacter.ts","../src/plugin/invisible-characters/space.ts"],"sourcesContent":["import { InvisibleCharacters } from './invisible-characters.js'\n\nexport * from './invisible-characters.js'\nexport * from './plugin/invisible-characters/hardBreak.js'\nexport * from './plugin/invisible-characters/paragraph.js'\nexport * from './plugin/invisible-characters/space.js'\nexport * from './plugin/InvisibleCharacter.js'\nexport * from './plugin/InvisibleNode.js'\nexport * from './types.js'\n\nexport default InvisibleCharacters\n","import { Extension } from '@tiptap/core'\n\nimport { InvisibleCharactersPlugin, InvisibleCharactersPluginKey } from './plugin/index.js'\nimport { HardBreakNode } from './plugin/invisible-characters/hardBreak.js'\nimport { ParagraphNode } from './plugin/invisible-characters/paragraph.js'\nimport { SpaceCharacter } from './plugin/invisible-characters/space.js'\nimport type { InvisibleCharactersOptions } from './types.js'\n\nexport { HardBreakNode, ParagraphNode, SpaceCharacter }\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n invisibleCharacters: {\n /**\n * Show invisible characters\n */\n showInvisibleCharacters: (show?: boolean) => ReturnType\n\n /**\n * Hide invisible characters\n */\n hideInvisibleCharacters: () => ReturnType\n\n /**\n * Toggle invisible characters\n */\n toggleInvisibleCharacters: () => ReturnType\n }\n }\n}\n\nexport const InvisibleCharacters = Extension.create<InvisibleCharactersOptions>({\n name: 'invisibleCharacters',\n\n addOptions() {\n return {\n visible: true,\n builders: [new SpaceCharacter(), new ParagraphNode(), new HardBreakNode()],\n injectCSS: true,\n injectNonce: undefined,\n }\n },\n\n addProseMirrorPlugins() {\n return [InvisibleCharactersPlugin(this.editor.state, this.options)]\n },\n\n addStorage() {\n return {\n visibility: () => this.options.visible,\n }\n },\n\n onBeforeCreate() {\n this.storage.visibility = () => {\n return InvisibleCharactersPluginKey.getState(this.editor.state)?.visible\n }\n },\n\n addCommands() {\n return {\n showInvisibleCharacters:\n (visibility = true) =>\n ({ dispatch, tr }) => {\n if (dispatch) {\n tr.setMeta('setInvisibleCharactersVisible', visibility)\n }\n\n return true\n },\n hideInvisibleCharacters:\n () =>\n ({ dispatch, tr }) => {\n if (dispatch) {\n tr.setMeta('setInvisibleCharactersVisible', false)\n }\n\n return true\n },\n toggleInvisibleCharacters:\n () =>\n ({ dispatch, tr, state }) => {\n const visibility = !InvisibleCharactersPluginKey.getState(state)?.visible\n\n if (dispatch) {\n tr.setMeta('setInvisibleCharactersVisible', visibility)\n }\n\n return true\n },\n }\n },\n})\n\nexport default InvisibleCharacters\n","import type { EditorState } from '@tiptap/pm/state'\nimport { AllSelection, Plugin, PluginKey } from '@tiptap/pm/state'\nimport { DecorationSet } from '@tiptap/pm/view'\n\nimport type { InvisibleCharactersOptions, PluginState } from '../types.js'\nimport { stateReducer } from './reducers.js'\nimport { style } from './style.js'\nimport { createStyleTag } from './utils/create-style-tag.js'\nimport { getUpdatedRanges } from './utils/get-updated-ranges.js'\n\nexport const InvisibleCharactersPluginKey = new PluginKey<PluginState>('invisibleCharacters')\n\nexport const InvisibleCharactersPlugin = (state: EditorState, options: InvisibleCharactersOptions) => {\n const key = InvisibleCharactersPluginKey\n const emptyDecorationSet = DecorationSet.create(state.doc, [])\n\n const addDecorationsBetweenPositions = (\n from: number,\n to: number,\n editorState: EditorState,\n decorations: DecorationSet,\n ) => {\n return options.builders\n .sort((builderA, builderB) => {\n if (builderA.priority > builderB.priority) {\n return 1\n }\n\n return -1\n })\n .reduce((newDecos, builder) => {\n return builder.createDecoration(from, to, editorState.doc, newDecos)\n }, decorations)\n }\n\n return new Plugin({\n key,\n\n state: {\n init: () => {\n const { $from, $to } = new AllSelection(state.doc)\n\n if (options.injectCSS && document) {\n createStyleTag(style, options.injectNonce)\n }\n\n return {\n visible: options.visible,\n decorations: addDecorationsBetweenPositions($from.pos, $to.pos, state, DecorationSet.empty),\n }\n },\n apply: (tr, pluginState, _, currentState) => {\n const newPluginState = stateReducer(pluginState, tr.getMeta('setInvisibleCharactersVisible'))\n\n const decorations = getUpdatedRanges(tr).reduce(\n (nextDecorations, [from, to]) => {\n return addDecorationsBetweenPositions(from, to, currentState, nextDecorations)\n },\n newPluginState.decorations.map(tr.mapping, tr.doc),\n )\n\n return {\n ...newPluginState,\n decorations,\n }\n },\n },\n\n props: {\n decorations(editorState) {\n const pluginState = this.getState(editorState)\n\n const visible = pluginState?.visible\n const decorations = pluginState?.decorations\n\n return visible ? decorations : emptyDecorationSet\n },\n },\n })\n}\n\nexport default InvisibleCharactersPlugin\n","import type { PluginState } from '../types.js'\n\nexport const stateReducer = (state: PluginState, visible: boolean): PluginState => {\n if (visible === undefined) {\n return state\n }\n\n return { ...state, visible }\n}\n\nexport default stateReducer\n","export const style = `.Tiptap-invisible-character {\n height: 0;\n padding: 0;\n pointer-events: none;\n user-select: none;\n width: 0;\n}\n\n.Tiptap-invisible-character::before {\n caret-color: inherit;\n color: #aaa;\n display: inline-block;\n font-style: normal;\n font-weight: 400;\n line-height: 1em;\n width: 0;\n}\n\n.Tiptap-invisible-character--space::before {\n content: '·'\n}\n\n.Tiptap-invisible-character--break::before {\n content: '¬'\n}\n\n.Tiptap-invisible-character--paragraph::before {\n content: '¶'\n}\n\n.Tiptap-invisible-character + img.ProseMirror-separator {\n height: 0 !important;\n pointer-events: none;\n user-select: none;\n width: 0 !important;\n}\n\n.is-empty[data-placeholder].has-focus > .Tiptap-invisible-character {\n display: none;\n}\n`\n\nexport default style\n","export const createStyleTag = (style: string, nonce?: string): HTMLStyleElement => {\n const tiptapStyleTag = <HTMLStyleElement>(\n document.querySelector('style[data-tiptap-extension-invisible-characters-style]')\n )\n\n if (tiptapStyleTag !== null) {\n return tiptapStyleTag\n }\n\n const styleNode = document.createElement('style')\n\n if (nonce) {\n styleNode.setAttribute('nonce', nonce)\n }\n\n styleNode.setAttribute('data-tiptap-extension-invisible-characters-style', '')\n styleNode.innerHTML = style\n document.getElementsByTagName('head')[0].appendChild(styleNode)\n\n return styleNode\n}\n\nexport default createStyleTag\n","import type { Transaction } from '@tiptap/pm/state'\n\ntype StepRange = [from: number, to: number]\n\nexport const getUpdatedRanges = ({ mapping }: Transaction): StepRange[] => {\n const ranges: StepRange[] = []\n\n mapping.maps.forEach((stepMap, i) => {\n stepMap.forEach((_oldStart, _oldEnd, newStart, newEnd) => {\n ranges.push([mapping.slice(i + 1).map(newStart), mapping.slice(i + 1).map(newEnd)])\n })\n })\n\n return ranges\n}\n\nexport default getUpdatedRanges\n","import { Decoration } from '@tiptap/pm/view'\n\nexport const createDecorationWidget = (pos: number, type: string, content?: string) => {\n const createElement = () => {\n const newElement = document.createElement('span')\n\n newElement.classList.add('Tiptap-invisible-character')\n newElement.classList.add(`Tiptap-invisible-character--${type}`)\n\n if (content) {\n newElement.textContent = content\n }\n\n return newElement\n }\n\n // return Decoration.inline(pos - 1, pos, {\n // class: `Tiptap-invisible-character Tiptap-invisible-character--${type}`,\n // })\n\n return Decoration.widget(pos, createElement, {\n key: type,\n marks: [],\n side: 1000,\n })\n}\n\nexport default createDecorationWidget\n","import type { Node } from '@tiptap/pm/model'\nimport type { DecorationSet } from '@tiptap/pm/view'\n\nimport { createDecorationWidget } from './utils/create-decoration-widget.js'\n\nexport interface InvisibleNodeOptions {\n content?: string\n position?: (node: Node, pos: number) => number\n predicate: (value: Node) => boolean\n priority?: number\n type: string\n}\n\n/** Default position for nodes is always at the end of the node */\nconst defaultPosition = (node: Node, pos: number) => pos + node.nodeSize - 1\n\nexport class InvisibleNode {\n predicate: (value: Node) => boolean\n\n position: (node: Node, pos: number) => number\n\n content?: string\n\n type: string\n\n priority: number\n\n constructor(options: InvisibleNodeOptions) {\n this.predicate = options.predicate\n this.type = options.type\n this.position = options.position || defaultPosition\n this.content = options.content\n this.priority = options.priority || 100\n }\n\n createDecoration(from: number, to: number, doc: Node, decorations: DecorationSet) {\n let newDecorations = decorations\n\n doc.nodesBetween(from, to, (node, pos) => {\n if (this.test(node)) {\n const decorationPosition = this.position(node, pos)\n const oldDecorations = newDecorations.find(\n decorationPosition,\n decorationPosition,\n spec => spec.key === this.type,\n )\n\n newDecorations = newDecorations\n .remove(oldDecorations)\n .add(doc, [createDecorationWidget(decorationPosition, this.type, this.content)])\n }\n })\n return newDecorations\n }\n\n test(value: Node) {\n return this.predicate(value)\n }\n}\n\nexport default InvisibleNode\n","import { InvisibleNode } from '../InvisibleNode.js'\n\nexport class HardBreakNode extends InvisibleNode {\n constructor() {\n super({\n type: 'break',\n predicate: node => node.type === node.type.schema.nodes.hardBreak,\n })\n }\n}\n\nexport default HardBreakNode\n","import { InvisibleNode } from '../InvisibleNode.js'\n\nexport class ParagraphNode extends InvisibleNode {\n constructor() {\n super({\n type: 'paragraph',\n predicate: node => node.type === node.type.schema.nodes.paragraph,\n })\n }\n}\n\nexport default ParagraphNode\n","import type { Node } from '@tiptap/pm/model'\n\nimport type { Position } from '../../types.js'\n\nexport const textBetween = (from: number, to: number, doc: Node) => {\n const positions: Position[] = []\n\n doc.nodesBetween(from, to, (node, pos) => {\n if (node.isText) {\n const offset = Math.max(from, pos) - pos\n\n positions.push({\n pos: pos + offset,\n text: node.text?.slice(offset, to - pos) || '',\n })\n }\n })\n\n return positions\n}\n\nexport default textBetween\n","import type { Node } from '@tiptap/pm/model'\nimport type { DecorationSet } from '@tiptap/pm/view'\n\nimport { createDecorationWidget } from './utils/create-decoration-widget.js'\nimport { textBetween } from './utils/text-between.js'\n\nexport interface InvisibleCharacterOptions {\n type: string\n predicate: (value: string) => boolean\n priority?: number\n content?: string\n}\n\nexport class InvisibleCharacter {\n predicate: (value: string) => boolean\n\n content?: string\n\n type: string\n\n priority: number\n\n constructor(options: InvisibleCharacterOptions) {\n this.predicate = options.predicate\n this.type = options.type\n this.content = options.content\n this.priority = options.priority || 100\n }\n\n createDecoration(from: number, to: number, doc: Node, decorations: DecorationSet) {\n const textContent = textBetween(from, to, doc)\n\n return textContent.reduce((oldDecorations, currentPosition) => {\n return currentPosition.text.split('').reduce((innerDecorations, char, i) => {\n return this.test(char)\n ? innerDecorations.add(doc, [createDecorationWidget(currentPosition.pos + i, this.type, this.content)])\n : innerDecorations\n }, oldDecorations)\n }, decorations)\n }\n\n test(value: string) {\n return this.predicate(value)\n }\n}\n\nexport default InvisibleCharacter\n","import { InvisibleCharacter } from '../InvisibleCharacter.js'\n\nexport class SpaceCharacter extends InvisibleCharacter {\n constructor() {\n super({\n type: 'space',\n predicate: (char: string) => char === ' ',\n })\n }\n}\n\nexport default SpaceCharacter\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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AA,QACnD;AAEA,eAAO;AAAA,MACT;AAAA,MACF,2BACE,MACA,CAAC,EAAE,UAAU,IAAI,MAAM,MAAM;AAjFrC;AAkFU,cAAM,aAAa,GAAC,kCAA6B,SAAS,KAAK,MAA3C,mBAA8C;AAElE,YAAI,UAAU;AACZ,aAAG,QAAQ,iCAAiC,UAAU;AAAA,QACxD;AAEA,eAAO;AAAA,MACT;AAAA,IACJ;AAAA,EACF;AACF,CAAC;;;ADlFD,IAAO,gBAAQ;","names":["style","import_view"]}
@@ -0,0 +1,86 @@
1
+ import { Extension } from '@tiptap/core';
2
+ import { DecorationSet } from '@tiptap/pm/view';
3
+ import { Node } from '@tiptap/pm/model';
4
+
5
+ interface InvisibleNodeOptions {
6
+ content?: string;
7
+ position?: (node: Node, pos: number) => number;
8
+ predicate: (value: Node) => boolean;
9
+ priority?: number;
10
+ type: string;
11
+ }
12
+ declare class InvisibleNode {
13
+ predicate: (value: Node) => boolean;
14
+ position: (node: Node, pos: number) => number;
15
+ content?: string;
16
+ type: string;
17
+ priority: number;
18
+ constructor(options: InvisibleNodeOptions);
19
+ createDecoration(from: number, to: number, doc: Node, decorations: DecorationSet): DecorationSet;
20
+ test(value: Node): boolean;
21
+ }
22
+
23
+ declare class HardBreakNode extends InvisibleNode {
24
+ constructor();
25
+ }
26
+
27
+ declare class ParagraphNode extends InvisibleNode {
28
+ constructor();
29
+ }
30
+
31
+ interface InvisibleCharacterOptions {
32
+ type: string;
33
+ predicate: (value: string) => boolean;
34
+ priority?: number;
35
+ content?: string;
36
+ }
37
+ declare class InvisibleCharacter {
38
+ predicate: (value: string) => boolean;
39
+ content?: string;
40
+ type: string;
41
+ priority: number;
42
+ constructor(options: InvisibleCharacterOptions);
43
+ createDecoration(from: number, to: number, doc: Node, decorations: DecorationSet): DecorationSet;
44
+ test(value: string): boolean;
45
+ }
46
+
47
+ declare class SpaceCharacter extends InvisibleCharacter {
48
+ constructor();
49
+ }
50
+
51
+ interface InvisibleCharactersOptions {
52
+ visible: boolean;
53
+ builders: Array<InvisibleCharacter | InvisibleNode>;
54
+ injectCSS: boolean;
55
+ injectNonce: string | undefined;
56
+ }
57
+ interface Position {
58
+ pos: number;
59
+ text: string;
60
+ }
61
+ interface PluginState {
62
+ visible: boolean;
63
+ decorations: DecorationSet;
64
+ }
65
+
66
+ declare module '@tiptap/core' {
67
+ interface Commands<ReturnType> {
68
+ invisibleCharacters: {
69
+ /**
70
+ * Show invisible characters
71
+ */
72
+ showInvisibleCharacters: (show?: boolean) => ReturnType;
73
+ /**
74
+ * Hide invisible characters
75
+ */
76
+ hideInvisibleCharacters: () => ReturnType;
77
+ /**
78
+ * Toggle invisible characters
79
+ */
80
+ toggleInvisibleCharacters: () => ReturnType;
81
+ };
82
+ }
83
+ }
84
+ declare const InvisibleCharacters: Extension<InvisibleCharactersOptions, any>;
85
+
86
+ export { HardBreakNode, InvisibleCharacter, type InvisibleCharacterOptions, InvisibleCharacters, type InvisibleCharactersOptions, InvisibleNode, type InvisibleNodeOptions, ParagraphNode, type PluginState, type Position, SpaceCharacter, InvisibleCharacters as default };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,86 @@
1
- import { InvisibleCharacters } from './invisible-characters.js';
2
- export * from './invisible-characters.js';
3
- export * from './plugin/invisible-characters/hardBreak.js';
4
- export * from './plugin/invisible-characters/paragraph.js';
5
- export * from './plugin/invisible-characters/space.js';
6
- export * from './plugin/InvisibleCharacter.js';
7
- export * from './plugin/InvisibleNode.js';
8
- export * from './types.js';
9
- export default InvisibleCharacters;
10
- //# sourceMappingURL=index.d.ts.map
1
+ import { Extension } from '@tiptap/core';
2
+ import { DecorationSet } from '@tiptap/pm/view';
3
+ import { Node } from '@tiptap/pm/model';
4
+
5
+ interface InvisibleNodeOptions {
6
+ content?: string;
7
+ position?: (node: Node, pos: number) => number;
8
+ predicate: (value: Node) => boolean;
9
+ priority?: number;
10
+ type: string;
11
+ }
12
+ declare class InvisibleNode {
13
+ predicate: (value: Node) => boolean;
14
+ position: (node: Node, pos: number) => number;
15
+ content?: string;
16
+ type: string;
17
+ priority: number;
18
+ constructor(options: InvisibleNodeOptions);
19
+ createDecoration(from: number, to: number, doc: Node, decorations: DecorationSet): DecorationSet;
20
+ test(value: Node): boolean;
21
+ }
22
+
23
+ declare class HardBreakNode extends InvisibleNode {
24
+ constructor();
25
+ }
26
+
27
+ declare class ParagraphNode extends InvisibleNode {
28
+ constructor();
29
+ }
30
+
31
+ interface InvisibleCharacterOptions {
32
+ type: string;
33
+ predicate: (value: string) => boolean;
34
+ priority?: number;
35
+ content?: string;
36
+ }
37
+ declare class InvisibleCharacter {
38
+ predicate: (value: string) => boolean;
39
+ content?: string;
40
+ type: string;
41
+ priority: number;
42
+ constructor(options: InvisibleCharacterOptions);
43
+ createDecoration(from: number, to: number, doc: Node, decorations: DecorationSet): DecorationSet;
44
+ test(value: string): boolean;
45
+ }
46
+
47
+ declare class SpaceCharacter extends InvisibleCharacter {
48
+ constructor();
49
+ }
50
+
51
+ interface InvisibleCharactersOptions {
52
+ visible: boolean;
53
+ builders: Array<InvisibleCharacter | InvisibleNode>;
54
+ injectCSS: boolean;
55
+ injectNonce: string | undefined;
56
+ }
57
+ interface Position {
58
+ pos: number;
59
+ text: string;
60
+ }
61
+ interface PluginState {
62
+ visible: boolean;
63
+ decorations: DecorationSet;
64
+ }
65
+
66
+ declare module '@tiptap/core' {
67
+ interface Commands<ReturnType> {
68
+ invisibleCharacters: {
69
+ /**
70
+ * Show invisible characters
71
+ */
72
+ showInvisibleCharacters: (show?: boolean) => ReturnType;
73
+ /**
74
+ * Hide invisible characters
75
+ */
76
+ hideInvisibleCharacters: () => ReturnType;
77
+ /**
78
+ * Toggle invisible characters
79
+ */
80
+ toggleInvisibleCharacters: () => ReturnType;
81
+ };
82
+ }
83
+ }
84
+ declare const InvisibleCharacters: Extension<InvisibleCharactersOptions, any>;
85
+
86
+ export { HardBreakNode, InvisibleCharacter, type InvisibleCharacterOptions, InvisibleCharacters, type InvisibleCharactersOptions, InvisibleNode, type InvisibleNodeOptions, ParagraphNode, type PluginState, type Position, SpaceCharacter, InvisibleCharacters as default };