@tiptap/extension-character-count 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +5 -1
- package/dist/index.cjs +32 -95
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +9 -92
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
- package/src/index.ts +3 -2
- package/dist/index.umd.js +0 -100
- package/dist/index.umd.js.map +0 -1
- package/dist/packages/core/src/CommandManager.d.ts +0 -20
- package/dist/packages/core/src/Editor.d.ts +0 -161
- package/dist/packages/core/src/EventEmitter.d.ts +0 -11
- package/dist/packages/core/src/Extension.d.ts +0 -343
- package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
- package/dist/packages/core/src/InputRule.d.ts +0 -42
- package/dist/packages/core/src/Mark.d.ts +0 -451
- package/dist/packages/core/src/Node.d.ts +0 -611
- package/dist/packages/core/src/NodePos.d.ts +0 -44
- package/dist/packages/core/src/NodeView.d.ts +0 -31
- package/dist/packages/core/src/PasteRule.d.ts +0 -50
- package/dist/packages/core/src/Tracker.d.ts +0 -11
- package/dist/packages/core/src/commands/blur.d.ts +0 -13
- package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
- package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
- package/dist/packages/core/src/commands/command.d.ts +0 -18
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
- package/dist/packages/core/src/commands/cut.d.ts +0 -20
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
- package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
- package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
- package/dist/packages/core/src/commands/enter.d.ts +0 -13
- package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
- package/dist/packages/core/src/commands/first.d.ts +0 -14
- package/dist/packages/core/src/commands/focus.d.ts +0 -27
- package/dist/packages/core/src/commands/forEach.d.ts +0 -14
- package/dist/packages/core/src/commands/index.d.ts +0 -55
- package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
- package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
- package/dist/packages/core/src/commands/join.d.ts +0 -41
- package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
- package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
- package/dist/packages/core/src/commands/lift.d.ts +0 -17
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
- package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
- package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
- package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
- package/dist/packages/core/src/commands/setContent.d.ts +0 -40
- package/dist/packages/core/src/commands/setMark.d.ts +0 -15
- package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
- package/dist/packages/core/src/commands/setNode.d.ts +0 -16
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
- package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
- package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
- package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
- package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
- package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
- package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
- package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
- package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
- package/dist/packages/core/src/extensions/commands.d.ts +0 -3
- package/dist/packages/core/src/extensions/editable.d.ts +0 -2
- package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
- package/dist/packages/core/src/extensions/index.d.ts +0 -6
- package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
- package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
- package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
- package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
- package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
- package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
- package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
- package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
- package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
- package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
- package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
- package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
- package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getText.d.ts +0 -15
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
- package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
- package/dist/packages/core/src/helpers/index.d.ts +0 -50
- package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
- package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
- package/dist/packages/core/src/helpers/isList.d.ts +0 -2
- package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -2
- package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
- package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
- package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
- package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
- package/dist/packages/core/src/index.d.ts +0 -24
- package/dist/packages/core/src/inputRules/index.d.ts +0 -5
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
- package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
- package/dist/packages/core/src/style.d.ts +0 -1
- package/dist/packages/core/src/types.d.ts +0 -255
- package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
- package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
- package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
- package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
- package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/index.d.ts +0 -20
- package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
- package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
- package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
- package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
- package/dist/packages/core/src/utilities/isString.d.ts +0 -1
- package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
- package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
- package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
- package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
- package/dist/packages/extension-character-count/src/character-count.d.ts +0 -42
- package/dist/packages/extension-character-count/src/index.d.ts +0 -3
- package/src/character-count.ts +0 -144
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
import { Mark as ProseMirrorMark, Node as ProseMirrorNode, NodeType, ParseOptions } from '@tiptap/pm/model';
|
|
2
|
-
import { EditorState, Transaction } from '@tiptap/pm/state';
|
|
3
|
-
import { Decoration, EditorProps, EditorView, NodeView } from '@tiptap/pm/view';
|
|
4
|
-
import { Editor } from './Editor.js';
|
|
5
|
-
import { Extension } from './Extension.js';
|
|
6
|
-
import { Commands, ExtensionConfig, MarkConfig, NodeConfig } from './index.js';
|
|
7
|
-
import { Mark } from './Mark.js';
|
|
8
|
-
import { Node } from './Node.js';
|
|
9
|
-
export type AnyConfig = ExtensionConfig | NodeConfig | MarkConfig;
|
|
10
|
-
export type AnyExtension = Extension | Node | Mark;
|
|
11
|
-
export type Extensions = AnyExtension[];
|
|
12
|
-
export type ParentConfig<T> = Partial<{
|
|
13
|
-
[P in keyof T]: Required<T>[P] extends (...args: any) => any ? (...args: Parameters<Required<T>[P]>) => ReturnType<Required<T>[P]> : T[P];
|
|
14
|
-
}>;
|
|
15
|
-
export type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
16
|
-
export type RemoveThis<T> = T extends (...args: any) => any ? (...args: Parameters<T>) => ReturnType<T> : T;
|
|
17
|
-
export type MaybeReturnType<T> = T extends (...args: any) => any ? ReturnType<T> : T;
|
|
18
|
-
export type MaybeThisParameterType<T> = Exclude<T, Primitive> extends (...args: any) => any ? ThisParameterType<Exclude<T, Primitive>> : any;
|
|
19
|
-
export interface EditorEvents {
|
|
20
|
-
beforeCreate: {
|
|
21
|
-
editor: Editor;
|
|
22
|
-
};
|
|
23
|
-
create: {
|
|
24
|
-
editor: Editor;
|
|
25
|
-
};
|
|
26
|
-
contentError: {
|
|
27
|
-
editor: Editor;
|
|
28
|
-
error: Error;
|
|
29
|
-
/**
|
|
30
|
-
* If called, will re-initialize the editor with the collaboration extension removed.
|
|
31
|
-
* This will prevent syncing back deletions of content not present in the current schema.
|
|
32
|
-
*/
|
|
33
|
-
disableCollaboration: () => void;
|
|
34
|
-
};
|
|
35
|
-
update: {
|
|
36
|
-
editor: Editor;
|
|
37
|
-
transaction: Transaction;
|
|
38
|
-
};
|
|
39
|
-
selectionUpdate: {
|
|
40
|
-
editor: Editor;
|
|
41
|
-
transaction: Transaction;
|
|
42
|
-
};
|
|
43
|
-
beforeTransaction: {
|
|
44
|
-
editor: Editor;
|
|
45
|
-
transaction: Transaction;
|
|
46
|
-
nextState: EditorState;
|
|
47
|
-
};
|
|
48
|
-
transaction: {
|
|
49
|
-
editor: Editor;
|
|
50
|
-
transaction: Transaction;
|
|
51
|
-
};
|
|
52
|
-
focus: {
|
|
53
|
-
editor: Editor;
|
|
54
|
-
event: FocusEvent;
|
|
55
|
-
transaction: Transaction;
|
|
56
|
-
};
|
|
57
|
-
blur: {
|
|
58
|
-
editor: Editor;
|
|
59
|
-
event: FocusEvent;
|
|
60
|
-
transaction: Transaction;
|
|
61
|
-
};
|
|
62
|
-
destroy: void;
|
|
63
|
-
}
|
|
64
|
-
export type EnableRules = (AnyExtension | string)[] | boolean;
|
|
65
|
-
export interface EditorOptions {
|
|
66
|
-
element: Element;
|
|
67
|
-
content: Content;
|
|
68
|
-
extensions: Extensions;
|
|
69
|
-
injectCSS: boolean;
|
|
70
|
-
injectNonce: string | undefined;
|
|
71
|
-
autofocus: FocusPosition;
|
|
72
|
-
editable: boolean;
|
|
73
|
-
editorProps: EditorProps;
|
|
74
|
-
parseOptions: ParseOptions;
|
|
75
|
-
coreExtensionOptions?: {
|
|
76
|
-
clipboardTextSerializer?: {
|
|
77
|
-
blockSeparator?: string;
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
enableInputRules: EnableRules;
|
|
81
|
-
enablePasteRules: EnableRules;
|
|
82
|
-
enableCoreExtensions: boolean;
|
|
83
|
-
/**
|
|
84
|
-
* If `true`, the editor will check the content for errors on initialization.
|
|
85
|
-
* Emitting the `contentError` event if the content is invalid.
|
|
86
|
-
* Which can be used to show a warning or error message to the user.
|
|
87
|
-
* @default false
|
|
88
|
-
*/
|
|
89
|
-
enableContentCheck: boolean;
|
|
90
|
-
onBeforeCreate: (props: EditorEvents['beforeCreate']) => void;
|
|
91
|
-
onCreate: (props: EditorEvents['create']) => void;
|
|
92
|
-
/**
|
|
93
|
-
* Called when the editor encounters an error while parsing the content.
|
|
94
|
-
* Only enabled if `enableContentCheck` is `true`.
|
|
95
|
-
*/
|
|
96
|
-
onContentError: (props: EditorEvents['contentError']) => void;
|
|
97
|
-
onUpdate: (props: EditorEvents['update']) => void;
|
|
98
|
-
onSelectionUpdate: (props: EditorEvents['selectionUpdate']) => void;
|
|
99
|
-
onTransaction: (props: EditorEvents['transaction']) => void;
|
|
100
|
-
onFocus: (props: EditorEvents['focus']) => void;
|
|
101
|
-
onBlur: (props: EditorEvents['blur']) => void;
|
|
102
|
-
onDestroy: (props: EditorEvents['destroy']) => void;
|
|
103
|
-
}
|
|
104
|
-
export type HTMLContent = string;
|
|
105
|
-
export type JSONContent = {
|
|
106
|
-
type?: string;
|
|
107
|
-
attrs?: Record<string, any>;
|
|
108
|
-
content?: JSONContent[];
|
|
109
|
-
marks?: {
|
|
110
|
-
type: string;
|
|
111
|
-
attrs?: Record<string, any>;
|
|
112
|
-
[key: string]: any;
|
|
113
|
-
}[];
|
|
114
|
-
text?: string;
|
|
115
|
-
[key: string]: any;
|
|
116
|
-
};
|
|
117
|
-
export type Content = HTMLContent | JSONContent | JSONContent[] | null;
|
|
118
|
-
export type CommandProps = {
|
|
119
|
-
editor: Editor;
|
|
120
|
-
tr: Transaction;
|
|
121
|
-
commands: SingleCommands;
|
|
122
|
-
can: () => CanCommands;
|
|
123
|
-
chain: () => ChainedCommands;
|
|
124
|
-
state: EditorState;
|
|
125
|
-
view: EditorView;
|
|
126
|
-
dispatch: ((args?: any) => any) | undefined;
|
|
127
|
-
};
|
|
128
|
-
export type Command = (props: CommandProps) => boolean;
|
|
129
|
-
export type CommandSpec = (...args: any[]) => Command;
|
|
130
|
-
export type KeyboardShortcutCommand = (props: {
|
|
131
|
-
editor: Editor;
|
|
132
|
-
}) => boolean;
|
|
133
|
-
export type Attribute = {
|
|
134
|
-
default?: any;
|
|
135
|
-
rendered?: boolean;
|
|
136
|
-
renderHTML?: ((attributes: Record<string, any>) => Record<string, any> | null) | null;
|
|
137
|
-
parseHTML?: ((element: HTMLElement) => any | null) | null;
|
|
138
|
-
keepOnSplit?: boolean;
|
|
139
|
-
isRequired?: boolean;
|
|
140
|
-
};
|
|
141
|
-
export type Attributes = {
|
|
142
|
-
[key: string]: Attribute;
|
|
143
|
-
};
|
|
144
|
-
export type ExtensionAttribute = {
|
|
145
|
-
type: string;
|
|
146
|
-
name: string;
|
|
147
|
-
attribute: Required<Attribute>;
|
|
148
|
-
};
|
|
149
|
-
export type GlobalAttributes = {
|
|
150
|
-
/**
|
|
151
|
-
* The node & mark types this attribute should be applied to.
|
|
152
|
-
*/
|
|
153
|
-
types: string[];
|
|
154
|
-
/**
|
|
155
|
-
* The attributes to add to the node or mark types.
|
|
156
|
-
*/
|
|
157
|
-
attributes: {
|
|
158
|
-
[key: string]: Attribute;
|
|
159
|
-
};
|
|
160
|
-
}[];
|
|
161
|
-
export type PickValue<T, K extends keyof T> = T[K];
|
|
162
|
-
export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
163
|
-
export type Diff<T extends keyof any, U extends keyof any> = ({
|
|
164
|
-
[P in T]: P;
|
|
165
|
-
} & {
|
|
166
|
-
[P in U]: never;
|
|
167
|
-
} & {
|
|
168
|
-
[x: string]: never;
|
|
169
|
-
})[T];
|
|
170
|
-
export type Overwrite<T, U> = Pick<T, Diff<keyof T, keyof U>> & U;
|
|
171
|
-
export type ValuesOf<T> = T[keyof T];
|
|
172
|
-
export type KeysWithTypeOf<T, Type> = {
|
|
173
|
-
[P in keyof T]: T[P] extends Type ? P : never;
|
|
174
|
-
}[keyof T];
|
|
175
|
-
export type DecorationWithType = Decoration & {
|
|
176
|
-
type: NodeType;
|
|
177
|
-
};
|
|
178
|
-
export type NodeViewProps = {
|
|
179
|
-
editor: Editor;
|
|
180
|
-
node: ProseMirrorNode;
|
|
181
|
-
decorations: DecorationWithType[];
|
|
182
|
-
selected: boolean;
|
|
183
|
-
extension: Node;
|
|
184
|
-
getPos: () => number;
|
|
185
|
-
updateAttributes: (attributes: Record<string, any>) => void;
|
|
186
|
-
deleteNode: () => void;
|
|
187
|
-
};
|
|
188
|
-
export interface NodeViewRendererOptions {
|
|
189
|
-
stopEvent: ((props: {
|
|
190
|
-
event: Event;
|
|
191
|
-
}) => boolean) | null;
|
|
192
|
-
ignoreMutation: ((props: {
|
|
193
|
-
mutation: MutationRecord | {
|
|
194
|
-
type: 'selection';
|
|
195
|
-
target: Element;
|
|
196
|
-
};
|
|
197
|
-
}) => boolean) | null;
|
|
198
|
-
contentDOMElementTag: string;
|
|
199
|
-
}
|
|
200
|
-
export type NodeViewRendererProps = {
|
|
201
|
-
editor: Editor;
|
|
202
|
-
node: ProseMirrorNode;
|
|
203
|
-
getPos: (() => number) | boolean;
|
|
204
|
-
HTMLAttributes: Record<string, any>;
|
|
205
|
-
decorations: Decoration[];
|
|
206
|
-
extension: Node;
|
|
207
|
-
};
|
|
208
|
-
export type NodeViewRenderer = (props: NodeViewRendererProps) => NodeView | {};
|
|
209
|
-
export type AnyCommands = Record<string, (...args: any[]) => Command>;
|
|
210
|
-
export type UnionCommands<T = Command> = UnionToIntersection<ValuesOf<Pick<Commands<T>, KeysWithTypeOf<Commands<T>, {}>>>>;
|
|
211
|
-
export type RawCommands = {
|
|
212
|
-
[Item in keyof UnionCommands]: UnionCommands<Command>[Item];
|
|
213
|
-
};
|
|
214
|
-
export type SingleCommands = {
|
|
215
|
-
[Item in keyof UnionCommands]: UnionCommands<boolean>[Item];
|
|
216
|
-
};
|
|
217
|
-
export type ChainedCommands = {
|
|
218
|
-
[Item in keyof UnionCommands]: UnionCommands<ChainedCommands>[Item];
|
|
219
|
-
} & {
|
|
220
|
-
run: () => boolean;
|
|
221
|
-
};
|
|
222
|
-
export type CanCommands = SingleCommands & {
|
|
223
|
-
chain: () => ChainedCommands;
|
|
224
|
-
};
|
|
225
|
-
export type FocusPosition = 'start' | 'end' | 'all' | number | boolean | null;
|
|
226
|
-
export type Range = {
|
|
227
|
-
from: number;
|
|
228
|
-
to: number;
|
|
229
|
-
};
|
|
230
|
-
export type NodeRange = {
|
|
231
|
-
node: ProseMirrorNode;
|
|
232
|
-
from: number;
|
|
233
|
-
to: number;
|
|
234
|
-
};
|
|
235
|
-
export type MarkRange = {
|
|
236
|
-
mark: ProseMirrorMark;
|
|
237
|
-
from: number;
|
|
238
|
-
to: number;
|
|
239
|
-
};
|
|
240
|
-
export type Predicate = (node: ProseMirrorNode) => boolean;
|
|
241
|
-
export type NodeWithPos = {
|
|
242
|
-
node: ProseMirrorNode;
|
|
243
|
-
pos: number;
|
|
244
|
-
};
|
|
245
|
-
export type TextSerializer = (props: {
|
|
246
|
-
node: ProseMirrorNode;
|
|
247
|
-
pos: number;
|
|
248
|
-
parent: ProseMirrorNode;
|
|
249
|
-
index: number;
|
|
250
|
-
range: Range;
|
|
251
|
-
}) => string;
|
|
252
|
-
export type ExtendedRegExpMatchArray = RegExpMatchArray & {
|
|
253
|
-
data?: Record<string, any>;
|
|
254
|
-
};
|
|
255
|
-
export type Dispatch = ((args?: any) => any) | undefined;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { MaybeReturnType } from '../types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Optionally calls `value` as a function.
|
|
4
|
-
* Otherwise it is returned directly.
|
|
5
|
-
* @param value Function or any value.
|
|
6
|
-
* @param context Optional context to bind to function.
|
|
7
|
-
* @param props Optional props to pass to function.
|
|
8
|
-
*/
|
|
9
|
-
export declare function callOrReturn<T>(value: T, context?: any, ...props: any[]): MaybeReturnType<T>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function createStyleTag(style: string, nonce?: string, suffix?: string): HTMLStyleElement;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function elementFromString(value: string): HTMLElement;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function escapeForRegEx(string: string): string;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function findDuplicates(items: any[]): any[];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function fromString(value: any): any;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export * from './callOrReturn.js';
|
|
2
|
-
export * from './createStyleTag.js';
|
|
3
|
-
export * from './deleteProps.js';
|
|
4
|
-
export * from './elementFromString.js';
|
|
5
|
-
export * from './escapeForRegEx.js';
|
|
6
|
-
export * from './findDuplicates.js';
|
|
7
|
-
export * from './fromString.js';
|
|
8
|
-
export * from './isEmptyObject.js';
|
|
9
|
-
export * from './isFunction.js';
|
|
10
|
-
export * from './isiOS.js';
|
|
11
|
-
export * from './isMacOS.js';
|
|
12
|
-
export * from './isNumber.js';
|
|
13
|
-
export * from './isPlainObject.js';
|
|
14
|
-
export * from './isRegExp.js';
|
|
15
|
-
export * from './isString.js';
|
|
16
|
-
export * from './mergeAttributes.js';
|
|
17
|
-
export * from './mergeDeep.js';
|
|
18
|
-
export * from './minMax.js';
|
|
19
|
-
export * from './objectIncludes.js';
|
|
20
|
-
export * from './removeDuplicates.js';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isAndroid(): boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isEmptyObject(value?: {}): boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isFunction(value: any): value is Function;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isMacOS(): boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isNumber(value: any): value is number;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isPlainObject(value: any): value is Record<string, any>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isRegExp(value: any): value is RegExp;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isString(value: any): value is string;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isiOS(): boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function mergeAttributes(...objects: Record<string, any>[]): Record<string, any>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function mergeDeep(target: Record<string, any>, source: Record<string, any>): Record<string, any>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function minMax(value?: number, min?: number, max?: number): number;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Removes duplicated values within an array.
|
|
3
|
-
* Supports numbers, strings and objects.
|
|
4
|
-
*/
|
|
5
|
-
export declare function removeDuplicates<T>(array: T[], by?: {
|
|
6
|
-
(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string;
|
|
7
|
-
(value: any, replacer?: (number | string)[] | null, space?: string | number): string;
|
|
8
|
-
}): T[];
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Extension } from '@tiptap/core';
|
|
2
|
-
import { Node as ProseMirrorNode } from '@tiptap/pm/model';
|
|
3
|
-
export interface CharacterCountOptions {
|
|
4
|
-
/**
|
|
5
|
-
* The maximum number of characters that should be allowed. Defaults to `0`.
|
|
6
|
-
* @default null
|
|
7
|
-
* @example 180
|
|
8
|
-
*/
|
|
9
|
-
limit: number | null | undefined;
|
|
10
|
-
/**
|
|
11
|
-
* The mode by which the size is calculated. If set to `textSize`, the textContent of the document is used.
|
|
12
|
-
* If set to `nodeSize`, the nodeSize of the document is used.
|
|
13
|
-
* @default 'textSize'
|
|
14
|
-
* @example 'textSize'
|
|
15
|
-
*/
|
|
16
|
-
mode: 'textSize' | 'nodeSize';
|
|
17
|
-
}
|
|
18
|
-
export interface CharacterCountStorage {
|
|
19
|
-
/**
|
|
20
|
-
* Get the number of characters for the current document.
|
|
21
|
-
* @param options The options for the character count. (optional)
|
|
22
|
-
* @param options.node The node to get the characters from. Defaults to the current document.
|
|
23
|
-
* @param options.mode The mode by which the size is calculated. If set to `textSize`, the textContent of the document is used.
|
|
24
|
-
*/
|
|
25
|
-
characters: (options?: {
|
|
26
|
-
node?: ProseMirrorNode;
|
|
27
|
-
mode?: 'textSize' | 'nodeSize';
|
|
28
|
-
}) => number;
|
|
29
|
-
/**
|
|
30
|
-
* Get the number of words for the current document.
|
|
31
|
-
* @param options The options for the character count. (optional)
|
|
32
|
-
* @param options.node The node to get the words from. Defaults to the current document.
|
|
33
|
-
*/
|
|
34
|
-
words: (options?: {
|
|
35
|
-
node?: ProseMirrorNode;
|
|
36
|
-
}) => number;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* This extension allows you to count the characters and words of your document.
|
|
40
|
-
* @see https://tiptap.dev/api/extensions/character-count
|
|
41
|
-
*/
|
|
42
|
-
export declare const CharacterCount: Extension<CharacterCountOptions, CharacterCountStorage>;
|
package/src/character-count.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { Extension } from '@tiptap/core'
|
|
2
|
-
import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
3
|
-
import { Plugin, PluginKey } from '@tiptap/pm/state'
|
|
4
|
-
|
|
5
|
-
export interface CharacterCountOptions {
|
|
6
|
-
/**
|
|
7
|
-
* The maximum number of characters that should be allowed. Defaults to `0`.
|
|
8
|
-
* @default null
|
|
9
|
-
* @example 180
|
|
10
|
-
*/
|
|
11
|
-
limit: number | null | undefined
|
|
12
|
-
/**
|
|
13
|
-
* The mode by which the size is calculated. If set to `textSize`, the textContent of the document is used.
|
|
14
|
-
* If set to `nodeSize`, the nodeSize of the document is used.
|
|
15
|
-
* @default 'textSize'
|
|
16
|
-
* @example 'textSize'
|
|
17
|
-
*/
|
|
18
|
-
mode: 'textSize' | 'nodeSize'
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface CharacterCountStorage {
|
|
22
|
-
/**
|
|
23
|
-
* Get the number of characters for the current document.
|
|
24
|
-
* @param options The options for the character count. (optional)
|
|
25
|
-
* @param options.node The node to get the characters from. Defaults to the current document.
|
|
26
|
-
* @param options.mode The mode by which the size is calculated. If set to `textSize`, the textContent of the document is used.
|
|
27
|
-
*/
|
|
28
|
-
characters: (options?: { node?: ProseMirrorNode; mode?: 'textSize' | 'nodeSize' }) => number
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Get the number of words for the current document.
|
|
32
|
-
* @param options The options for the character count. (optional)
|
|
33
|
-
* @param options.node The node to get the words from. Defaults to the current document.
|
|
34
|
-
*/
|
|
35
|
-
words: (options?: { node?: ProseMirrorNode }) => number
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* This extension allows you to count the characters and words of your document.
|
|
40
|
-
* @see https://tiptap.dev/api/extensions/character-count
|
|
41
|
-
*/
|
|
42
|
-
export const CharacterCount = Extension.create<CharacterCountOptions, CharacterCountStorage>({
|
|
43
|
-
name: 'characterCount',
|
|
44
|
-
|
|
45
|
-
addOptions() {
|
|
46
|
-
return {
|
|
47
|
-
limit: null,
|
|
48
|
-
mode: 'textSize',
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
addStorage() {
|
|
53
|
-
return {
|
|
54
|
-
characters: () => 0,
|
|
55
|
-
words: () => 0,
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
onBeforeCreate() {
|
|
60
|
-
this.storage.characters = options => {
|
|
61
|
-
const node = options?.node || this.editor.state.doc
|
|
62
|
-
const mode = options?.mode || this.options.mode
|
|
63
|
-
|
|
64
|
-
if (mode === 'textSize') {
|
|
65
|
-
const text = node.textBetween(0, node.content.size, undefined, ' ')
|
|
66
|
-
|
|
67
|
-
return text.length
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return node.nodeSize
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
this.storage.words = options => {
|
|
74
|
-
const node = options?.node || this.editor.state.doc
|
|
75
|
-
const text = node.textBetween(0, node.content.size, ' ', ' ')
|
|
76
|
-
const words = text.split(' ').filter(word => word !== '')
|
|
77
|
-
|
|
78
|
-
return words.length
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
addProseMirrorPlugins() {
|
|
83
|
-
return [
|
|
84
|
-
new Plugin({
|
|
85
|
-
key: new PluginKey('characterCount'),
|
|
86
|
-
filterTransaction: (transaction, state) => {
|
|
87
|
-
const limit = this.options.limit
|
|
88
|
-
|
|
89
|
-
// Nothing has changed or no limit is defined. Ignore it.
|
|
90
|
-
if (!transaction.docChanged || limit === 0 || limit === null || limit === undefined) {
|
|
91
|
-
return true
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const oldSize = this.storage.characters({ node: state.doc })
|
|
95
|
-
const newSize = this.storage.characters({ node: transaction.doc })
|
|
96
|
-
|
|
97
|
-
// Everything is in the limit. Good.
|
|
98
|
-
if (newSize <= limit) {
|
|
99
|
-
return true
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// The limit has already been exceeded but will be reduced.
|
|
103
|
-
if (oldSize > limit && newSize > limit && newSize <= oldSize) {
|
|
104
|
-
return true
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// The limit has already been exceeded and will be increased further.
|
|
108
|
-
if (oldSize > limit && newSize > limit && newSize > oldSize) {
|
|
109
|
-
return false
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const isPaste = transaction.getMeta('paste')
|
|
113
|
-
|
|
114
|
-
// Block all exceeding transactions that were not pasted.
|
|
115
|
-
if (!isPaste) {
|
|
116
|
-
return false
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// For pasted content, we try to remove the exceeding content.
|
|
120
|
-
const pos = transaction.selection.$head.pos
|
|
121
|
-
const over = newSize - limit
|
|
122
|
-
const from = pos - over
|
|
123
|
-
const to = pos
|
|
124
|
-
|
|
125
|
-
// It’s probably a bad idea to mutate transactions within `filterTransaction`
|
|
126
|
-
// but for now this is working fine.
|
|
127
|
-
transaction.deleteRange(from, to)
|
|
128
|
-
|
|
129
|
-
// In some situations, the limit will continue to be exceeded after trimming.
|
|
130
|
-
// This happens e.g. when truncating within a complex node (e.g. table)
|
|
131
|
-
// and ProseMirror has to close this node again.
|
|
132
|
-
// If this is the case, we prevent the transaction completely.
|
|
133
|
-
const updatedSize = this.storage.characters({ node: transaction.doc })
|
|
134
|
-
|
|
135
|
-
if (updatedSize > limit) {
|
|
136
|
-
return false
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return true
|
|
140
|
-
},
|
|
141
|
-
}),
|
|
142
|
-
]
|
|
143
|
-
},
|
|
144
|
-
})
|