@jvs-milkdown/prose 1.0.0
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 +21 -0
- package/README.md +11 -0
- package/lib/changeset.d.ts +2 -0
- package/lib/changeset.d.ts.map +1 -0
- package/lib/changeset.js +2 -0
- package/lib/changeset.js.map +1 -0
- package/lib/commands.d.ts +2 -0
- package/lib/commands.d.ts.map +1 -0
- package/lib/commands.js +2 -0
- package/lib/commands.js.map +1 -0
- package/lib/dropcursor.d.ts +2 -0
- package/lib/dropcursor.d.ts.map +1 -0
- package/lib/dropcursor.js +2 -0
- package/lib/dropcursor.js.map +1 -0
- package/lib/gapcursor.d.ts +2 -0
- package/lib/gapcursor.d.ts.map +1 -0
- package/lib/gapcursor.js +2 -0
- package/lib/gapcursor.js.map +1 -0
- package/lib/history.d.ts +2 -0
- package/lib/history.d.ts.map +1 -0
- package/lib/history.js +2 -0
- package/lib/history.js.map +1 -0
- package/lib/index.d.ts +132 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +402 -0
- package/lib/index.js.map +1 -0
- package/lib/inputrules.d.ts +2 -0
- package/lib/inputrules.d.ts.map +1 -0
- package/lib/inputrules.js +2 -0
- package/lib/inputrules.js.map +1 -0
- package/lib/keymap.d.ts +2 -0
- package/lib/keymap.d.ts.map +1 -0
- package/lib/keymap.js +2 -0
- package/lib/keymap.js.map +1 -0
- package/lib/model.d.ts +2 -0
- package/lib/model.d.ts.map +1 -0
- package/lib/model.js +2 -0
- package/lib/model.js.map +1 -0
- package/lib/schema-list.d.ts +2 -0
- package/lib/schema-list.d.ts.map +1 -0
- package/lib/schema-list.js +2 -0
- package/lib/schema-list.js.map +1 -0
- package/lib/state.d.ts +2 -0
- package/lib/state.d.ts.map +1 -0
- package/lib/state.js +2 -0
- package/lib/state.js.map +1 -0
- package/lib/style/gapcursor.css +25 -0
- package/lib/style/prosemirror.css +54 -0
- package/lib/style/tables.css +48 -0
- package/lib/tables.d.ts +2 -0
- package/lib/tables.d.ts.map +1 -0
- package/lib/tables.js +2 -0
- package/lib/tables.js.map +1 -0
- package/lib/toolkit/browser.d.ts +17 -0
- package/lib/toolkit/browser.d.ts.map +1 -0
- package/lib/toolkit/index.d.ts +5 -0
- package/lib/toolkit/index.d.ts.map +1 -0
- package/lib/toolkit/input-rules/common.d.ts +20 -0
- package/lib/toolkit/input-rules/common.d.ts.map +1 -0
- package/lib/toolkit/input-rules/custom-input-rules.d.ts +7 -0
- package/lib/toolkit/input-rules/custom-input-rules.d.ts.map +1 -0
- package/lib/toolkit/input-rules/index.d.ts +5 -0
- package/lib/toolkit/input-rules/index.d.ts.map +1 -0
- package/lib/toolkit/input-rules/mark-rule.d.ts +5 -0
- package/lib/toolkit/input-rules/mark-rule.d.ts.map +1 -0
- package/lib/toolkit/input-rules/node-rule.d.ts +5 -0
- package/lib/toolkit/input-rules/node-rule.d.ts.map +1 -0
- package/lib/toolkit/position/index.d.ts +13 -0
- package/lib/toolkit/position/index.d.ts.map +1 -0
- package/lib/toolkit/prose/helper.d.ts +6 -0
- package/lib/toolkit/prose/helper.d.ts.map +1 -0
- package/lib/toolkit/prose/index.d.ts +5 -0
- package/lib/toolkit/prose/index.d.ts.map +1 -0
- package/lib/toolkit/prose/node.d.ts +17 -0
- package/lib/toolkit/prose/node.d.ts.map +1 -0
- package/lib/toolkit/prose/schema.d.ts +4 -0
- package/lib/toolkit/prose/schema.d.ts.map +1 -0
- package/lib/toolkit/prose/selection.d.ts +19 -0
- package/lib/toolkit/prose/selection.d.ts.map +1 -0
- package/lib/toolkit/prose/types.d.ts +3 -0
- package/lib/toolkit/prose/types.d.ts.map +1 -0
- package/lib/transform.d.ts +2 -0
- package/lib/transform.d.ts.map +1 -0
- package/lib/transform.js +2 -0
- package/lib/transform.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/view.d.ts +2 -0
- package/lib/view.d.ts.map +1 -0
- package/lib/view.js +2 -0
- package/lib/view.js.map +1 -0
- package/package.json +141 -0
- package/src/changeset.ts +1 -0
- package/src/commands.ts +1 -0
- package/src/dropcursor.ts +1 -0
- package/src/gapcursor.ts +1 -0
- package/src/history.ts +1 -0
- package/src/index.ts +1 -0
- package/src/inputrules.ts +1 -0
- package/src/keymap.ts +1 -0
- package/src/model.ts +1 -0
- package/src/schema-list.ts +1 -0
- package/src/state.ts +1 -0
- package/src/tables.ts +1 -0
- package/src/toolkit/browser.ts +39 -0
- package/src/toolkit/index.ts +4 -0
- package/src/toolkit/input-rules/common.ts +25 -0
- package/src/toolkit/input-rules/custom-input-rules.ts +113 -0
- package/src/toolkit/input-rules/index.ts +4 -0
- package/src/toolkit/input-rules/mark-rule.ts +60 -0
- package/src/toolkit/input-rules/node-rule.ts +51 -0
- package/src/toolkit/position/index.ts +108 -0
- package/src/toolkit/prose/helper.ts +30 -0
- package/src/toolkit/prose/index.ts +4 -0
- package/src/toolkit/prose/node.ts +63 -0
- package/src/toolkit/prose/schema.ts +19 -0
- package/src/toolkit/prose/selection.ts +97 -0
- package/src/toolkit/prose/types.ts +3 -0
- package/src/transform.ts +1 -0
- package/src/view.ts +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-present Mirone
|
|
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/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @jvs-milkdown/prose
|
|
2
|
+
|
|
3
|
+
The prose module of [milkdown](https://milkdown.dev/).
|
|
4
|
+
|
|
5
|
+
# Official Documentation
|
|
6
|
+
|
|
7
|
+
Documentation can be found on the [Milkdown website](https://milkdown.dev/).
|
|
8
|
+
|
|
9
|
+
# License
|
|
10
|
+
|
|
11
|
+
Milkdown is open sourced software licensed under [MIT license](https://github.com/Milkdown/milkdown/blob/main/LICENSE).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"changeset.d.ts","sources":[],"mappings":"","names":[]}
|
package/lib/changeset.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"changeset.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sources":[],"mappings":"","names":[]}
|
package/lib/commands.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dropcursor.d.ts","sources":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dropcursor.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gapcursor.d.ts","sources":[],"mappings":"","names":[]}
|
package/lib/gapcursor.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gapcursor.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/lib/history.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.d.ts","sources":[],"mappings":"","names":[]}
|
package/lib/history.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { InputRule } from 'prosemirror-inputrules';
|
|
2
|
+
import { Plugin, PluginKey, Transaction, EditorState, Selection } from 'prosemirror-state';
|
|
3
|
+
import { Attrs, MarkType, NodeType, Node, Slice, ResolvedPos, Schema } from 'prosemirror-model';
|
|
4
|
+
import { EditorView } from 'prosemirror-view';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Copy paste from:
|
|
8
|
+
* https://github.com/ProseMirror/prosemirror-view/blob/master/src/browser.ts
|
|
9
|
+
*/
|
|
10
|
+
declare const ie: boolean;
|
|
11
|
+
declare const ie_version: unknown;
|
|
12
|
+
declare const gecko: boolean;
|
|
13
|
+
declare const gecko_version: number | false;
|
|
14
|
+
declare const chrome: boolean;
|
|
15
|
+
declare const chrome_version: number;
|
|
16
|
+
declare const safari: boolean;
|
|
17
|
+
declare const ios: boolean;
|
|
18
|
+
declare const mac: boolean;
|
|
19
|
+
declare const android: boolean;
|
|
20
|
+
declare const webkit: boolean;
|
|
21
|
+
declare const webkit_version: number;
|
|
22
|
+
|
|
23
|
+
declare const browser_android: typeof android;
|
|
24
|
+
declare const browser_chrome: typeof chrome;
|
|
25
|
+
declare const browser_chrome_version: typeof chrome_version;
|
|
26
|
+
declare const browser_gecko: typeof gecko;
|
|
27
|
+
declare const browser_gecko_version: typeof gecko_version;
|
|
28
|
+
declare const browser_ie: typeof ie;
|
|
29
|
+
declare const browser_ie_version: typeof ie_version;
|
|
30
|
+
declare const browser_ios: typeof ios;
|
|
31
|
+
declare const browser_mac: typeof mac;
|
|
32
|
+
declare const browser_safari: typeof safari;
|
|
33
|
+
declare const browser_webkit: typeof webkit;
|
|
34
|
+
declare const browser_webkit_version: typeof webkit_version;
|
|
35
|
+
declare namespace browser {
|
|
36
|
+
export {
|
|
37
|
+
browser_android as android,
|
|
38
|
+
browser_chrome as chrome,
|
|
39
|
+
browser_chrome_version as chrome_version,
|
|
40
|
+
browser_gecko as gecko,
|
|
41
|
+
browser_gecko_version as gecko_version,
|
|
42
|
+
browser_ie as ie,
|
|
43
|
+
browser_ie_version as ie_version,
|
|
44
|
+
browser_ios as ios,
|
|
45
|
+
browser_mac as mac,
|
|
46
|
+
browser_safari as safari,
|
|
47
|
+
browser_webkit as webkit,
|
|
48
|
+
browser_webkit_version as webkit_version,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare const customInputRulesKey: PluginKey<any>;
|
|
53
|
+
declare function customInputRules({ rules }: {
|
|
54
|
+
rules: InputRule[];
|
|
55
|
+
}): Plugin;
|
|
56
|
+
|
|
57
|
+
interface Captured {
|
|
58
|
+
group: string | undefined;
|
|
59
|
+
fullMatch: string;
|
|
60
|
+
start: number;
|
|
61
|
+
end: number;
|
|
62
|
+
}
|
|
63
|
+
interface BeforeDispatch {
|
|
64
|
+
match: string[];
|
|
65
|
+
start: number;
|
|
66
|
+
end: number;
|
|
67
|
+
tr: Transaction;
|
|
68
|
+
}
|
|
69
|
+
interface Options {
|
|
70
|
+
getAttr?: (match: RegExpMatchArray) => Attrs;
|
|
71
|
+
updateCaptured?: (captured: Captured) => Partial<Captured>;
|
|
72
|
+
beforeDispatch?: (options: BeforeDispatch) => void;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
declare function markRule(regexp: RegExp, markType: MarkType, options?: Options): InputRule;
|
|
76
|
+
|
|
77
|
+
declare function nodeRule(regexp: RegExp, nodeType: NodeType, options?: Options): InputRule;
|
|
78
|
+
|
|
79
|
+
type Point = [top: number, left: number];
|
|
80
|
+
declare function calculateNodePosition(view: EditorView, target: HTMLElement, handler: (selectedRect: DOMRect, targetRect: DOMRect, parentRect: DOMRect) => Point): void;
|
|
81
|
+
interface Rect {
|
|
82
|
+
left: number;
|
|
83
|
+
right: number;
|
|
84
|
+
top: number;
|
|
85
|
+
bottom: number;
|
|
86
|
+
}
|
|
87
|
+
declare function calculateTextPosition(view: EditorView, target: HTMLElement, handler: (start: Rect, end: Rect, targetRect: DOMRect, parentRect: DOMRect) => Point): void;
|
|
88
|
+
declare function posToDOMRect(view: EditorView, from: number, to: number): DOMRect;
|
|
89
|
+
|
|
90
|
+
declare function cloneTr(tr: Transaction): Transaction;
|
|
91
|
+
declare function equalNodeType(nodeType: NodeType | NodeType[], node: Node): boolean;
|
|
92
|
+
declare function isTextOnlySlice(slice: Slice): Node | false;
|
|
93
|
+
|
|
94
|
+
type Predicate = (node: Node) => boolean;
|
|
95
|
+
|
|
96
|
+
interface NodeWithPos {
|
|
97
|
+
pos: number;
|
|
98
|
+
node: Node;
|
|
99
|
+
}
|
|
100
|
+
interface NodeWithFromTo {
|
|
101
|
+
from: number;
|
|
102
|
+
to: number;
|
|
103
|
+
node: Node;
|
|
104
|
+
}
|
|
105
|
+
declare function flatten(node: Node, descend?: boolean): NodeWithPos[];
|
|
106
|
+
declare function findChildren(predicate: Predicate): (node: Node, descend?: boolean) => NodeWithPos[];
|
|
107
|
+
declare function findChildrenByMark(node: Node, markType: MarkType, descend?: boolean): NodeWithPos[];
|
|
108
|
+
declare function findParent(predicate: Predicate): ($pos: ResolvedPos) => NodeWithFromTo | undefined;
|
|
109
|
+
declare function findParentNodeType($pos: ResolvedPos, nodeType: NodeType): NodeWithFromTo | undefined;
|
|
110
|
+
|
|
111
|
+
declare function getNodeFromSchema(type: string, schema: Schema): NodeType;
|
|
112
|
+
declare function getMarkFromSchema(type: string, schema: Schema): MarkType;
|
|
113
|
+
|
|
114
|
+
interface ContentNodeWithPos {
|
|
115
|
+
pos: number;
|
|
116
|
+
start: number;
|
|
117
|
+
depth: number;
|
|
118
|
+
node: Node;
|
|
119
|
+
}
|
|
120
|
+
declare function findParentNodeClosestToPos(predicate: Predicate): ($pos: ResolvedPos) => ContentNodeWithPos | undefined;
|
|
121
|
+
declare function findParentNode(predicate: Predicate): (selection: Selection) => ContentNodeWithPos | undefined;
|
|
122
|
+
declare function findSelectedNodeOfType(selection: Selection, nodeType: NodeType): ContentNodeWithPos | undefined;
|
|
123
|
+
type FindNodeInSelectionResult = {
|
|
124
|
+
hasNode: boolean;
|
|
125
|
+
pos: number;
|
|
126
|
+
target: Node | null;
|
|
127
|
+
};
|
|
128
|
+
declare const findNodeInSelection: (state: EditorState, node: NodeType) => FindNodeInSelectionResult;
|
|
129
|
+
|
|
130
|
+
export { browser, calculateNodePosition, calculateTextPosition, cloneTr, customInputRules, customInputRulesKey, equalNodeType, findChildren, findChildrenByMark, findNodeInSelection, findParent, findParentNode, findParentNodeClosestToPos, findParentNodeType, findSelectedNodeOfType, flatten, getMarkFromSchema, getNodeFromSchema, isTextOnlySlice, markRule, nodeRule, posToDOMRect };
|
|
131
|
+
export type { BeforeDispatch, Captured, ContentNodeWithPos, FindNodeInSelectionResult, NodeWithFromTo, NodeWithPos, Options };
|
|
132
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sources":["../src/toolkit/browser.ts","../src/toolkit/input-rules/custom-input-rules.ts","../src/toolkit/input-rules/common.ts","../src/toolkit/input-rules/mark-rule.ts","../src/toolkit/input-rules/node-rule.ts","../src/toolkit/position/index.ts","../src/toolkit/prose/helper.ts","../src/toolkit/prose/types.ts","../src/toolkit/prose/node.ts","../src/toolkit/prose/schema.ts","../src/toolkit/prose/selection.ts"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA,cAAc,EAAE;AAChB,cAAc,UAAU;AACxB,cAAc,KAAK;AACnB,cAAc,aAAa;AAC3B,cAAc,MAAM;AACpB,cAAc,cAAc;AAC5B,cAAc,MAAM;AACpB,cAAc,GAAG;AACjB,cAAc,GAAG;AACjB,cAAc,OAAO;AACrB,cAAc,MAAM;AACpB,cAAc,cAAc;;;;;;;;;;;;;;;;;;ACb5B,cAAc,mBAAmB,EAAE,SAAS;AAC5C,iBAAiB,gBAAgB;AACjC,WAAW,SAAS;AACpB,IAAI,MAAM;;ACHV,UAAU,QAAQ;AAClB;AACA;AACA;AACA;AACA;AACA,UAAU,cAAc;AACxB;AACA;AACA;AACA,QAAQ,WAAW;AACnB;AACA,UAAU,OAAO;AACjB,sBAAsB,gBAAgB,KAAK,KAAK;AAChD,gCAAgC,QAAQ,KAAK,OAAO,CAAC,QAAQ;AAC7D,+BAA+B,cAAc;AAC7C;;ACfA,iBAAiB,QAAQ,SAAS,MAAM,YAAY,QAAQ,YAAY,OAAO,GAAG,SAAS;;ACA3F,iBAAiB,QAAQ,SAAS,MAAM,YAAY,QAAQ,YAAY,OAAO,GAAG,SAAS;;ACF3F,KAAK,KAAK;AACV,iBAAiB,qBAAqB,OAAO,UAAU,UAAU,WAAW,0BAA0B,OAAO,cAAc,OAAO,cAAc,OAAO,KAAK,KAAK;AACjK,UAAU,IAAI;AACd;AACA;AACA;AACA;AACA;AACA,iBAAiB,qBAAqB,OAAO,UAAU,UAAU,WAAW,mBAAmB,IAAI,OAAO,IAAI,cAAc,OAAO,cAAc,OAAO,KAAK,KAAK;AAClK,iBAAiB,YAAY,OAAO,UAAU,6BAA6B,OAAO;;ACRlF,iBAAiB,OAAO,KAAK,WAAW,GAAG,WAAW;AACtD,iBAAiB,aAAa,WAAW,QAAQ,GAAG,QAAQ,UAAUA,IAAS;AAC/E,iBAAiB,eAAe,QAAQ,KAAK,GAAGA,IAAS;;ACHzD,KAAK,SAAS,UAAU,IAAI;;ACC5B,UAAU,WAAW;AACrB;AACA,UAAU,IAAI;AACd;AACA,UAAU,cAAc;AACxB;AACA;AACA,UAAU,IAAI;AACd;AACA,iBAAiB,OAAO,OAAO,IAAI,sBAAsB,WAAW;AACpE,iBAAiB,YAAY,YAAY,SAAS,UAAU,IAAI,wBAAwB,WAAW;AACnG,iBAAiB,kBAAkB,OAAO,IAAI,YAAY,QAAQ,sBAAsB,WAAW;AACnG,iBAAiB,UAAU,YAAY,SAAS,UAAU,WAAW,KAAK,cAAc;AACxF,iBAAiB,kBAAkB,OAAO,WAAW,YAAY,QAAQ,GAAG,cAAc;;ACd1F,iBAAiB,iBAAiB,uBAAuB,MAAM,GAAG,QAAQ;AAC1E,iBAAiB,iBAAiB,uBAAuB,MAAM,GAAG,QAAQ;;ACC1E,UAAU,kBAAkB;AAC5B;AACA;AACA;AACA,UAAUA,IAAS;AACnB;AACA,iBAAiB,0BAA0B,YAAY,SAAS,UAAU,WAAW,KAAK,kBAAkB;AAC5G,iBAAiB,cAAc,YAAY,SAAS,eAAe,SAAS,KAAK,kBAAkB;AACnG,iBAAiB,sBAAsB,YAAY,SAAS,YAAY,QAAQ,GAAG,kBAAkB;AACrG,KAAK,yBAAyB;AAC9B;AACA;AACA,YAAYA,IAAS;AACrB;AACA,cAAc,mBAAmB,UAAU,WAAW,QAAQ,QAAQ,KAAK,yBAAyB;;;;","names":["ProseNode"]}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { PluginKey, Plugin, NodeSelection } from 'prosemirror-state';
|
|
2
|
+
import { InputRule } from 'prosemirror-inputrules';
|
|
3
|
+
import { expectDomTypeError, missingRootElement, getAtomFromSchemaFail } from '@jvs-milkdown/exception';
|
|
4
|
+
|
|
5
|
+
const nav = typeof navigator != "undefined" ? navigator : null;
|
|
6
|
+
const doc = typeof document != "undefined" ? document : null;
|
|
7
|
+
const agent = nav && nav.userAgent || "";
|
|
8
|
+
const ie_edge = /Edge\/(\d+)/.exec(agent);
|
|
9
|
+
const ie_upto10 = /MSIE \d/.exec(agent);
|
|
10
|
+
const ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(agent);
|
|
11
|
+
const ie = !!(ie_upto10 || ie_11up || ie_edge);
|
|
12
|
+
const ie_version = ie_upto10 ? document.documentMode : ie_11up ? +ie_11up[1] : ie_edge ? +ie_edge[1] : 0;
|
|
13
|
+
const gecko = !ie && /gecko\/(\d+)/i.test(agent);
|
|
14
|
+
const gecko_version = gecko && +(/Firefox\/(\d+)/.exec(agent) || [0, 0])[1];
|
|
15
|
+
const _chrome = !ie && /Chrome\/(\d+)/.exec(agent);
|
|
16
|
+
const chrome = !!_chrome;
|
|
17
|
+
const chrome_version = _chrome ? +_chrome[1] : 0;
|
|
18
|
+
const safari = !ie && !!nav && /Apple Computer/.test(nav.vendor);
|
|
19
|
+
const ios = safari && (/Mobile\/\w+/.test(agent) || !!nav && nav.maxTouchPoints > 2);
|
|
20
|
+
const mac = ios || (nav ? /Mac/.test(nav.platform) : false);
|
|
21
|
+
const android = /Android \d/.test(agent);
|
|
22
|
+
const webkit = !!doc && "webkitFontSmoothing" in doc.documentElement.style;
|
|
23
|
+
const webkit_version = webkit ? +(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent) || [0, 0])[1] : 0;
|
|
24
|
+
|
|
25
|
+
var browser = /*#__PURE__*/Object.freeze({
|
|
26
|
+
__proto__: null,
|
|
27
|
+
android: android,
|
|
28
|
+
chrome: chrome,
|
|
29
|
+
chrome_version: chrome_version,
|
|
30
|
+
gecko: gecko,
|
|
31
|
+
gecko_version: gecko_version,
|
|
32
|
+
ie: ie,
|
|
33
|
+
ie_version: ie_version,
|
|
34
|
+
ios: ios,
|
|
35
|
+
mac: mac,
|
|
36
|
+
safari: safari,
|
|
37
|
+
webkit: webkit,
|
|
38
|
+
webkit_version: webkit_version
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
function run(view, from, to, text, rules, plugin) {
|
|
42
|
+
if (view.composing) return false;
|
|
43
|
+
const state = view.state;
|
|
44
|
+
const $from = state.doc.resolve(from);
|
|
45
|
+
if ($from.parent.type.spec.code) return false;
|
|
46
|
+
const textBefore = $from.parent.textBetween(
|
|
47
|
+
Math.max(0, $from.parentOffset - 500),
|
|
48
|
+
$from.parentOffset,
|
|
49
|
+
void 0,
|
|
50
|
+
"\uFFFC"
|
|
51
|
+
) + text;
|
|
52
|
+
for (let _matcher of rules) {
|
|
53
|
+
const matcher = _matcher;
|
|
54
|
+
const match = matcher.match.exec(textBefore);
|
|
55
|
+
const tr = match && match[0] && matcher.handler(state, match, from - (match[0].length - text.length), to);
|
|
56
|
+
if (!tr) continue;
|
|
57
|
+
if (matcher.undoable !== false)
|
|
58
|
+
tr.setMeta(plugin, { transform: tr, from, to, text });
|
|
59
|
+
view.dispatch(tr);
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
const customInputRulesKey = new PluginKey("MILKDOWN_CUSTOM_INPUTRULES");
|
|
65
|
+
function customInputRules({ rules }) {
|
|
66
|
+
const plugin = new Plugin({
|
|
67
|
+
key: customInputRulesKey,
|
|
68
|
+
isInputRules: true,
|
|
69
|
+
state: {
|
|
70
|
+
init() {
|
|
71
|
+
return null;
|
|
72
|
+
},
|
|
73
|
+
apply(tr, prev) {
|
|
74
|
+
const stored = tr.getMeta(this);
|
|
75
|
+
if (stored) return stored;
|
|
76
|
+
return tr.selectionSet || tr.docChanged ? null : prev;
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
props: {
|
|
80
|
+
handleTextInput(view, from, to, text) {
|
|
81
|
+
return run(view, from, to, text, rules, plugin);
|
|
82
|
+
},
|
|
83
|
+
handleDOMEvents: {
|
|
84
|
+
compositionend: (view) => {
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
const { $cursor } = view.state.selection;
|
|
87
|
+
if ($cursor) run(view, $cursor.pos, $cursor.pos, "", rules, plugin);
|
|
88
|
+
});
|
|
89
|
+
return false;
|
|
90
|
+
},
|
|
91
|
+
keydown: (view, event) => {
|
|
92
|
+
if (!(android && chrome && event.key === "Enter"))
|
|
93
|
+
return false;
|
|
94
|
+
if (view.composing) return false;
|
|
95
|
+
if (view.someProp(
|
|
96
|
+
"handleKeyDown",
|
|
97
|
+
(f) => f(view, event)
|
|
98
|
+
)) {
|
|
99
|
+
event.preventDefault();
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
handleKeyDown(view, event) {
|
|
106
|
+
if (event.key !== "Enter") return false;
|
|
107
|
+
const { $cursor } = view.state.selection;
|
|
108
|
+
if ($cursor)
|
|
109
|
+
return run(view, $cursor.pos, $cursor.pos, "\n", rules, plugin);
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
return plugin;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function markRule(regexp, markType, options = {}) {
|
|
118
|
+
return new InputRule(regexp, (state, match, start, end) => {
|
|
119
|
+
var _a, _b, _c, _d;
|
|
120
|
+
const { tr } = state;
|
|
121
|
+
const matchLength = match.length;
|
|
122
|
+
let group = match[matchLength - 1];
|
|
123
|
+
let fullMatch = match[0];
|
|
124
|
+
let initialStoredMarks = [];
|
|
125
|
+
let markEnd;
|
|
126
|
+
const captured = {
|
|
127
|
+
group,
|
|
128
|
+
fullMatch,
|
|
129
|
+
start,
|
|
130
|
+
end
|
|
131
|
+
};
|
|
132
|
+
const result = (_a = options.updateCaptured) == null ? void 0 : _a.call(options, captured);
|
|
133
|
+
Object.assign(captured, result);
|
|
134
|
+
({ group, fullMatch, start, end } = captured);
|
|
135
|
+
if (fullMatch === null) return null;
|
|
136
|
+
if ((group == null ? void 0 : group.trim()) === "") return null;
|
|
137
|
+
if (group) {
|
|
138
|
+
const startSpaces = fullMatch.search(/\S/);
|
|
139
|
+
const textStart = start + fullMatch.indexOf(group);
|
|
140
|
+
const textEnd = textStart + group.length;
|
|
141
|
+
initialStoredMarks = (_b = tr.storedMarks) != null ? _b : [];
|
|
142
|
+
if (textEnd < end) tr.delete(textEnd, end);
|
|
143
|
+
if (textStart > start) tr.delete(start + startSpaces, textStart);
|
|
144
|
+
markEnd = start + startSpaces + group.length;
|
|
145
|
+
const attrs = (_c = options.getAttr) == null ? void 0 : _c.call(options, match);
|
|
146
|
+
tr.addMark(start, markEnd, markType.create(attrs));
|
|
147
|
+
tr.setStoredMarks(initialStoredMarks);
|
|
148
|
+
(_d = options.beforeDispatch) == null ? void 0 : _d.call(options, { match, start, end, tr });
|
|
149
|
+
}
|
|
150
|
+
return tr;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function nodeRule(regexp, nodeType, options = {}) {
|
|
155
|
+
return new InputRule(regexp, (state, match, start, end) => {
|
|
156
|
+
var _a, _b, _c;
|
|
157
|
+
const { tr } = state;
|
|
158
|
+
let group = match[1];
|
|
159
|
+
let fullMatch = match[0];
|
|
160
|
+
const captured = {
|
|
161
|
+
group,
|
|
162
|
+
fullMatch,
|
|
163
|
+
start,
|
|
164
|
+
end
|
|
165
|
+
};
|
|
166
|
+
const result = (_a = options.updateCaptured) == null ? void 0 : _a.call(options, captured);
|
|
167
|
+
Object.assign(captured, result);
|
|
168
|
+
({ group, fullMatch, start, end } = captured);
|
|
169
|
+
if (fullMatch === null) return null;
|
|
170
|
+
if (!group || group.trim() === "") return null;
|
|
171
|
+
const attrs = (_b = options.getAttr) == null ? void 0 : _b.call(options, match);
|
|
172
|
+
const node = nodeType.createAndFill(attrs);
|
|
173
|
+
if (node) {
|
|
174
|
+
tr.replaceRangeWith(
|
|
175
|
+
nodeType.isBlock ? tr.doc.resolve(start).before() : start,
|
|
176
|
+
end,
|
|
177
|
+
node
|
|
178
|
+
);
|
|
179
|
+
(_c = options.beforeDispatch) == null ? void 0 : _c.call(options, {
|
|
180
|
+
match: [fullMatch, group],
|
|
181
|
+
start,
|
|
182
|
+
end,
|
|
183
|
+
tr
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
return tr;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
var __defProp = Object.defineProperty;
|
|
191
|
+
var __defProps = Object.defineProperties;
|
|
192
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
193
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
194
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
195
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
196
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
197
|
+
var __spreadValues = (a, b) => {
|
|
198
|
+
for (var prop in b || (b = {}))
|
|
199
|
+
if (__hasOwnProp.call(b, prop))
|
|
200
|
+
__defNormalProp(a, prop, b[prop]);
|
|
201
|
+
if (__getOwnPropSymbols)
|
|
202
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
203
|
+
if (__propIsEnum.call(b, prop))
|
|
204
|
+
__defNormalProp(a, prop, b[prop]);
|
|
205
|
+
}
|
|
206
|
+
return a;
|
|
207
|
+
};
|
|
208
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
209
|
+
function calculateNodePosition(view, target, handler) {
|
|
210
|
+
const state = view.state;
|
|
211
|
+
const { from } = state.selection;
|
|
212
|
+
const { node } = view.domAtPos(from);
|
|
213
|
+
const element = node instanceof Text ? node.parentElement : node;
|
|
214
|
+
if (!(element instanceof HTMLElement)) throw expectDomTypeError(element);
|
|
215
|
+
const selectedNodeRect = element.getBoundingClientRect();
|
|
216
|
+
const targetNodeRect = target.getBoundingClientRect();
|
|
217
|
+
const parent = target.parentElement;
|
|
218
|
+
if (!parent) throw expectDomTypeError(parent);
|
|
219
|
+
const parentNodeRect = parent.getBoundingClientRect();
|
|
220
|
+
const [top, left] = handler(selectedNodeRect, targetNodeRect, parentNodeRect);
|
|
221
|
+
target.style.top = `${top}px`;
|
|
222
|
+
target.style.left = `${left}px`;
|
|
223
|
+
}
|
|
224
|
+
function calculateTextPosition(view, target, handler) {
|
|
225
|
+
const state = view.state;
|
|
226
|
+
const { from, to } = state.selection;
|
|
227
|
+
const start = view.coordsAtPos(from);
|
|
228
|
+
const end = view.coordsAtPos(to);
|
|
229
|
+
const targetNodeRect = target.getBoundingClientRect();
|
|
230
|
+
const parent = target.parentElement;
|
|
231
|
+
if (!parent) throw missingRootElement();
|
|
232
|
+
const parentNodeRect = parent.getBoundingClientRect();
|
|
233
|
+
const [top, left] = handler(start, end, targetNodeRect, parentNodeRect);
|
|
234
|
+
target.style.top = `${top}px`;
|
|
235
|
+
target.style.left = `${left}px`;
|
|
236
|
+
}
|
|
237
|
+
function minMax(value = 0, min = 0, max = 0) {
|
|
238
|
+
return Math.min(Math.max(value, min), max);
|
|
239
|
+
}
|
|
240
|
+
function posToDOMRect(view, from, to) {
|
|
241
|
+
const minPos = 0;
|
|
242
|
+
const maxPos = view.state.doc.content.size;
|
|
243
|
+
const resolvedFrom = minMax(from, minPos, maxPos);
|
|
244
|
+
const resolvedEnd = minMax(to, minPos, maxPos);
|
|
245
|
+
const start = view.coordsAtPos(resolvedFrom);
|
|
246
|
+
const end = view.coordsAtPos(resolvedEnd, -1);
|
|
247
|
+
const top = Math.min(start.top, end.top);
|
|
248
|
+
const bottom = Math.max(start.bottom, end.bottom);
|
|
249
|
+
const left = Math.min(start.left, end.left);
|
|
250
|
+
const right = Math.max(start.right, end.right);
|
|
251
|
+
const width = right - left;
|
|
252
|
+
const height = bottom - top;
|
|
253
|
+
const x = left;
|
|
254
|
+
const y = top;
|
|
255
|
+
const data = {
|
|
256
|
+
top,
|
|
257
|
+
bottom,
|
|
258
|
+
left,
|
|
259
|
+
right,
|
|
260
|
+
width,
|
|
261
|
+
height,
|
|
262
|
+
x,
|
|
263
|
+
y
|
|
264
|
+
};
|
|
265
|
+
return __spreadProps(__spreadValues({}, data), {
|
|
266
|
+
toJSON: () => data
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function cloneTr(tr) {
|
|
271
|
+
return Object.assign(Object.create(tr), tr).setTime(Date.now());
|
|
272
|
+
}
|
|
273
|
+
function equalNodeType(nodeType, node) {
|
|
274
|
+
return Array.isArray(nodeType) && nodeType.includes(node.type) || node.type === nodeType;
|
|
275
|
+
}
|
|
276
|
+
function isTextOnlySlice(slice) {
|
|
277
|
+
if (slice.content.childCount === 1) {
|
|
278
|
+
const node = slice.content.firstChild;
|
|
279
|
+
if ((node == null ? void 0 : node.type.name) === "text" && node.marks.length === 0) return node;
|
|
280
|
+
if ((node == null ? void 0 : node.type.name) === "paragraph" && node.childCount === 1) {
|
|
281
|
+
const _node = node.firstChild;
|
|
282
|
+
if ((_node == null ? void 0 : _node.type.name) === "text" && _node.marks.length === 0) return _node;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function flatten(node, descend = true) {
|
|
289
|
+
const result = [];
|
|
290
|
+
node.descendants((child, pos) => {
|
|
291
|
+
result.push({ node: child, pos });
|
|
292
|
+
if (!descend) return false;
|
|
293
|
+
return void 0;
|
|
294
|
+
});
|
|
295
|
+
return result;
|
|
296
|
+
}
|
|
297
|
+
function findChildren(predicate) {
|
|
298
|
+
return (node, descend) => flatten(node, descend).filter((child) => predicate(child.node));
|
|
299
|
+
}
|
|
300
|
+
function findChildrenByMark(node, markType, descend) {
|
|
301
|
+
return findChildren((child) => Boolean(markType.isInSet(child.marks)))(
|
|
302
|
+
node,
|
|
303
|
+
descend
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
function findParent(predicate) {
|
|
307
|
+
return ($pos) => {
|
|
308
|
+
for (let depth = $pos.depth; depth > 0; depth -= 1) {
|
|
309
|
+
const node = $pos.node(depth);
|
|
310
|
+
if (predicate(node)) {
|
|
311
|
+
const from = $pos.before(depth);
|
|
312
|
+
const to = $pos.after(depth);
|
|
313
|
+
return {
|
|
314
|
+
from,
|
|
315
|
+
to,
|
|
316
|
+
node
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return void 0;
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
function findParentNodeType($pos, nodeType) {
|
|
324
|
+
return findParent((node) => node.type === nodeType)($pos);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function getNodeFromSchema(type, schema) {
|
|
328
|
+
const target = schema.nodes[type];
|
|
329
|
+
if (!target) throw getAtomFromSchemaFail("node", type);
|
|
330
|
+
return target;
|
|
331
|
+
}
|
|
332
|
+
function getMarkFromSchema(type, schema) {
|
|
333
|
+
const target = schema.marks[type];
|
|
334
|
+
if (!target) throw getAtomFromSchemaFail("mark", type);
|
|
335
|
+
return target;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function findParentNodeClosestToPos(predicate) {
|
|
339
|
+
return ($pos) => {
|
|
340
|
+
for (let i = $pos.depth; i > 0; i--) {
|
|
341
|
+
const node = $pos.node(i);
|
|
342
|
+
if (predicate(node)) {
|
|
343
|
+
return {
|
|
344
|
+
pos: $pos.before(i),
|
|
345
|
+
start: $pos.start(i),
|
|
346
|
+
depth: i,
|
|
347
|
+
node
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return void 0;
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
function findParentNode(predicate) {
|
|
355
|
+
return (selection) => {
|
|
356
|
+
return findParentNodeClosestToPos(predicate)(selection.$from);
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
function findSelectedNodeOfType(selection, nodeType) {
|
|
360
|
+
if (!(selection instanceof NodeSelection)) return;
|
|
361
|
+
const { node, $from } = selection;
|
|
362
|
+
if (equalNodeType(nodeType, node))
|
|
363
|
+
return {
|
|
364
|
+
node,
|
|
365
|
+
pos: $from.pos,
|
|
366
|
+
start: $from.start($from.depth),
|
|
367
|
+
depth: $from.depth
|
|
368
|
+
};
|
|
369
|
+
return void 0;
|
|
370
|
+
}
|
|
371
|
+
const findNodeInSelection = (state, node) => {
|
|
372
|
+
const { selection, doc } = state;
|
|
373
|
+
if (selection instanceof NodeSelection) {
|
|
374
|
+
return {
|
|
375
|
+
hasNode: selection.node.type === node,
|
|
376
|
+
pos: selection.from,
|
|
377
|
+
target: selection.node
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
const { from, to } = selection;
|
|
381
|
+
let hasNode = false;
|
|
382
|
+
let pos = -1;
|
|
383
|
+
let target = null;
|
|
384
|
+
doc.nodesBetween(from, to, (n, p) => {
|
|
385
|
+
if (target) return false;
|
|
386
|
+
if (n.type === node) {
|
|
387
|
+
hasNode = true;
|
|
388
|
+
pos = p;
|
|
389
|
+
target = n;
|
|
390
|
+
return false;
|
|
391
|
+
}
|
|
392
|
+
return true;
|
|
393
|
+
});
|
|
394
|
+
return {
|
|
395
|
+
hasNode,
|
|
396
|
+
pos,
|
|
397
|
+
target
|
|
398
|
+
};
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
export { browser, calculateNodePosition, calculateTextPosition, cloneTr, customInputRules, customInputRulesKey, equalNodeType, findChildren, findChildrenByMark, findNodeInSelection, findParent, findParentNode, findParentNodeClosestToPos, findParentNodeType, findSelectedNodeOfType, flatten, getMarkFromSchema, getNodeFromSchema, isTextOnlySlice, markRule, nodeRule, posToDOMRect };
|
|
402
|
+
//# sourceMappingURL=index.js.map
|