@handlewithcare/react-prosemirror 2.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.txt +12 -0
- package/README.md +705 -0
- package/dist/cjs/browser.js +53 -0
- package/dist/cjs/components/ChildNodeViews.js +376 -0
- package/dist/cjs/components/CursorWrapper.js +91 -0
- package/dist/cjs/components/CustomNodeView.js +79 -0
- package/dist/cjs/components/DocNodeView.js +104 -0
- package/dist/cjs/components/LayoutGroup.js +111 -0
- package/dist/cjs/components/MarkView.js +115 -0
- package/dist/cjs/components/NativeWidgetView.js +109 -0
- package/dist/cjs/components/NodeView.js +196 -0
- package/dist/cjs/components/NodeViewComponentProps.js +4 -0
- package/dist/cjs/components/OutputSpec.js +88 -0
- package/dist/cjs/components/ProseMirror.js +103 -0
- package/dist/cjs/components/ProseMirrorDoc.js +92 -0
- package/dist/cjs/components/SeparatorHackView.js +100 -0
- package/dist/cjs/components/TextNodeView.js +112 -0
- package/dist/cjs/components/TrailingHackView.js +90 -0
- package/dist/cjs/components/WidgetView.js +95 -0
- package/dist/cjs/components/WidgetViewComponentProps.js +4 -0
- package/dist/cjs/components/__tests__/ProseMirror.composition.test.js +398 -0
- package/dist/cjs/components/__tests__/ProseMirror.domchange.test.js +270 -0
- package/dist/cjs/components/__tests__/ProseMirror.draw-decoration.test.js +1010 -0
- package/dist/cjs/components/__tests__/ProseMirror.draw.test.js +337 -0
- package/dist/cjs/components/__tests__/ProseMirror.node-view.test.js +315 -0
- package/dist/cjs/components/__tests__/ProseMirror.selection.test.js +444 -0
- package/dist/cjs/components/__tests__/ProseMirror.test.js +382 -0
- package/dist/cjs/contexts/ChildDescriptorsContext.js +19 -0
- package/dist/cjs/contexts/EditorContext.js +12 -0
- package/dist/cjs/contexts/EditorStateContext.js +12 -0
- package/dist/cjs/contexts/LayoutGroupContext.js +12 -0
- package/dist/cjs/contexts/NodeViewContext.js +12 -0
- package/dist/cjs/contexts/SelectNodeContext.js +12 -0
- package/dist/cjs/contexts/StopEventContext.js +12 -0
- package/dist/cjs/contexts/__tests__/DeferredLayoutEffects.test.js +141 -0
- package/dist/cjs/decorations/ReactWidgetType.js +58 -0
- package/dist/cjs/decorations/computeDocDeco.js +44 -0
- package/dist/cjs/decorations/internalTypes.js +4 -0
- package/dist/cjs/decorations/iterDeco.js +79 -0
- package/dist/cjs/decorations/viewDecorations.js +163 -0
- package/dist/cjs/dom.js +142 -0
- package/dist/cjs/hooks/__tests__/useEditorViewLayoutEffect.test.js +108 -0
- package/dist/cjs/hooks/useClientOnly.js +18 -0
- package/dist/cjs/hooks/useComponentEventListeners.js +39 -0
- package/dist/cjs/hooks/useEditor.js +287 -0
- package/dist/cjs/hooks/useEditorEffect.js +35 -0
- package/dist/cjs/hooks/useEditorEventCallback.js +33 -0
- package/dist/cjs/hooks/useEditorEventListener.js +34 -0
- package/dist/cjs/hooks/useEditorState.js +16 -0
- package/dist/cjs/hooks/useForceUpdate.js +15 -0
- package/dist/cjs/hooks/useLayoutGroupEffect.js +19 -0
- package/dist/cjs/hooks/useNodeViewDescriptor.js +115 -0
- package/dist/cjs/hooks/useReactKeys.js +17 -0
- package/dist/cjs/hooks/useSelectNode.js +28 -0
- package/dist/cjs/hooks/useStopEvent.js +24 -0
- package/dist/cjs/index.js +53 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/plugins/__tests__/reactKeys.test.js +81 -0
- package/dist/cjs/plugins/beforeInputPlugin.js +143 -0
- package/dist/cjs/plugins/componentEventListeners.js +35 -0
- package/dist/cjs/plugins/componentEventListenersPlugin.js +35 -0
- package/dist/cjs/plugins/reactKeys.js +96 -0
- package/dist/cjs/props.js +269 -0
- package/dist/cjs/selection/SelectionDOMObserver.js +174 -0
- package/dist/cjs/selection/hasFocusAndSelection.js +35 -0
- package/dist/cjs/selection/selectionFromDOM.js +77 -0
- package/dist/cjs/selection/selectionToDOM.js +226 -0
- package/dist/cjs/ssr.js +85 -0
- package/dist/cjs/testing/editorViewTestHelpers.js +111 -0
- package/dist/cjs/testing/setupProseMirrorView.js +94 -0
- package/dist/cjs/viewdesc.js +664 -0
- package/dist/esm/browser.js +43 -0
- package/dist/esm/components/ChildNodeViews.js +318 -0
- package/dist/esm/components/CursorWrapper.js +40 -0
- package/dist/esm/components/CustomNodeView.js +28 -0
- package/dist/esm/components/DocNodeView.js +53 -0
- package/dist/esm/components/LayoutGroup.js +66 -0
- package/dist/esm/components/MarkView.js +64 -0
- package/dist/esm/components/NativeWidgetView.js +58 -0
- package/dist/esm/components/NodeView.js +145 -0
- package/dist/esm/components/NodeViewComponentProps.js +1 -0
- package/dist/esm/components/OutputSpec.js +38 -0
- package/dist/esm/components/ProseMirror.js +52 -0
- package/dist/esm/components/ProseMirrorDoc.js +34 -0
- package/dist/esm/components/SeparatorHackView.js +49 -0
- package/dist/esm/components/TextNodeView.js +102 -0
- package/dist/esm/components/TrailingHackView.js +39 -0
- package/dist/esm/components/WidgetView.js +44 -0
- package/dist/esm/components/WidgetViewComponentProps.js +1 -0
- package/dist/esm/components/__tests__/ProseMirror.composition.test.js +395 -0
- package/dist/esm/components/__tests__/ProseMirror.domchange.test.js +266 -0
- package/dist/esm/components/__tests__/ProseMirror.draw-decoration.test.js +967 -0
- package/dist/esm/components/__tests__/ProseMirror.draw.test.js +294 -0
- package/dist/esm/components/__tests__/ProseMirror.node-view.test.js +272 -0
- package/dist/esm/components/__tests__/ProseMirror.selection.test.js +440 -0
- package/dist/esm/components/__tests__/ProseMirror.test.js +339 -0
- package/dist/esm/contexts/ChildDescriptorsContext.js +9 -0
- package/dist/esm/contexts/EditorContext.js +7 -0
- package/dist/esm/contexts/EditorStateContext.js +2 -0
- package/dist/esm/contexts/LayoutGroupContext.js +2 -0
- package/dist/esm/contexts/NodeViewContext.js +2 -0
- package/dist/esm/contexts/SelectNodeContext.js +2 -0
- package/dist/esm/contexts/StopEventContext.js +2 -0
- package/dist/esm/contexts/__tests__/DeferredLayoutEffects.test.js +98 -0
- package/dist/esm/decorations/ReactWidgetType.js +40 -0
- package/dist/esm/decorations/computeDocDeco.js +44 -0
- package/dist/esm/decorations/internalTypes.js +1 -0
- package/dist/esm/decorations/iterDeco.js +73 -0
- package/dist/esm/decorations/viewDecorations.js +163 -0
- package/dist/esm/dom.js +105 -0
- package/dist/esm/hooks/__tests__/useEditorViewLayoutEffect.test.js +99 -0
- package/dist/esm/hooks/useClientOnly.js +8 -0
- package/dist/esm/hooks/useComponentEventListeners.js +54 -0
- package/dist/esm/hooks/useEditor.js +278 -0
- package/dist/esm/hooks/useEditorEffect.js +38 -0
- package/dist/esm/hooks/useEditorEventCallback.js +35 -0
- package/dist/esm/hooks/useEditorEventListener.js +28 -0
- package/dist/esm/hooks/useEditorState.js +8 -0
- package/dist/esm/hooks/useForceUpdate.js +8 -0
- package/dist/esm/hooks/useLayoutGroupEffect.js +9 -0
- package/dist/esm/hooks/useNodeViewDescriptor.js +105 -0
- package/dist/esm/hooks/useReactKeys.js +7 -0
- package/dist/esm/hooks/useSelectNode.js +18 -0
- package/dist/esm/hooks/useStopEvent.js +14 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/plugins/__tests__/reactKeys.test.js +77 -0
- package/dist/esm/plugins/beforeInputPlugin.js +133 -0
- package/dist/esm/plugins/componentEventListeners.js +25 -0
- package/dist/esm/plugins/componentEventListenersPlugin.js +25 -0
- package/dist/esm/plugins/reactKeys.js +81 -0
- package/dist/esm/props.js +251 -0
- package/dist/esm/selection/SelectionDOMObserver.js +164 -0
- package/dist/esm/selection/hasFocusAndSelection.js +17 -0
- package/dist/esm/selection/selectionFromDOM.js +59 -0
- package/dist/esm/selection/selectionToDOM.js +196 -0
- package/dist/esm/ssr.js +82 -0
- package/dist/esm/testing/editorViewTestHelpers.js +88 -0
- package/dist/esm/testing/setupProseMirrorView.js +76 -0
- package/dist/esm/viewdesc.js +654 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/browser.d.ts +15 -0
- package/dist/types/components/ChildNodeViews.d.ts +9 -0
- package/dist/types/components/CursorWrapper.d.ts +5 -0
- package/dist/types/components/CustomNodeView.d.ts +21 -0
- package/dist/types/components/DocNodeView.d.ts +20 -0
- package/dist/types/components/LayoutGroup.d.ts +12 -0
- package/dist/types/components/MarkView.d.ts +9 -0
- package/dist/types/components/NativeWidgetView.d.ts +8 -0
- package/dist/types/components/NodeView.d.ts +11 -0
- package/dist/types/components/NodeViewComponentProps.d.ts +12 -0
- package/dist/types/components/OutputSpec.d.ts +8 -0
- package/dist/types/components/ProseMirror.d.ts +15 -0
- package/dist/types/components/ProseMirrorDoc.d.ts +10 -0
- package/dist/types/components/SeparatorHackView.d.ts +6 -0
- package/dist/types/components/TextNodeView.d.ts +23 -0
- package/dist/types/components/TrailingHackView.d.ts +6 -0
- package/dist/types/components/WidgetView.d.ts +8 -0
- package/dist/types/components/WidgetViewComponentProps.d.ts +6 -0
- package/dist/types/components/__tests__/ProseMirror.composition.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.domchange.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.draw-decoration.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.draw.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.node-view.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.selection.test.d.ts +1 -0
- package/dist/types/components/__tests__/ProseMirror.test.d.ts +1 -0
- package/dist/types/contexts/ChildDescriptorsContext.d.ts +6 -0
- package/dist/types/contexts/EditorContext.d.ts +14 -0
- package/dist/types/contexts/EditorStateContext.d.ts +2 -0
- package/dist/types/contexts/LayoutGroupContext.d.ts +5 -0
- package/dist/types/contexts/NodeViewContext.d.ts +6 -0
- package/dist/types/contexts/SelectNodeContext.d.ts +3 -0
- package/dist/types/contexts/StopEventContext.d.ts +3 -0
- package/dist/types/contexts/__tests__/DeferredLayoutEffects.test.d.ts +1 -0
- package/dist/types/decorations/ReactWidgetType.d.ts +39 -0
- package/dist/types/decorations/computeDocDeco.d.ts +13 -0
- package/dist/types/decorations/internalTypes.d.ts +16 -0
- package/dist/types/decorations/iterDeco.d.ts +3 -0
- package/dist/types/decorations/viewDecorations.d.ts +13 -0
- package/dist/types/dom.d.ts +22 -0
- package/dist/types/hooks/__tests__/useEditorViewLayoutEffect.test.d.ts +1 -0
- package/dist/types/hooks/useClientOnly.d.ts +1 -0
- package/dist/types/hooks/useComponentEventListeners.d.ts +33 -0
- package/dist/types/hooks/useEditor.d.ts +66 -0
- package/dist/types/hooks/useEditorEffect.d.ts +17 -0
- package/dist/types/hooks/useEditorEventCallback.d.ts +15 -0
- package/dist/types/hooks/useEditorEventListener.d.ts +8 -0
- package/dist/types/hooks/useEditorState.d.ts +5 -0
- package/dist/types/hooks/useForceUpdate.d.ts +5 -0
- package/dist/types/hooks/useLayoutGroupEffect.d.ts +3 -0
- package/dist/types/hooks/useNodeViewDescriptor.d.ts +11 -0
- package/dist/types/hooks/useReactKeys.d.ts +5 -0
- package/dist/types/hooks/useSelectNode.d.ts +1 -0
- package/dist/types/hooks/useStopEvent.d.ts +2 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/plugins/__tests__/reactKeys.test.d.ts +1 -0
- package/dist/types/plugins/beforeInputPlugin.d.ts +3 -0
- package/dist/types/plugins/componentEventListeners.d.ts +4 -0
- package/dist/types/plugins/componentEventListenersPlugin.d.ts +4 -0
- package/dist/types/plugins/reactKeys.d.ts +19 -0
- package/dist/types/props.d.ts +1174 -0
- package/dist/types/selection/SelectionDOMObserver.d.ts +34 -0
- package/dist/types/selection/hasFocusAndSelection.d.ts +3 -0
- package/dist/types/selection/selectionFromDOM.d.ts +4 -0
- package/dist/types/selection/selectionToDOM.d.ts +9 -0
- package/dist/types/ssr.d.ts +19 -0
- package/dist/types/testing/editorViewTestHelpers.d.ts +23 -0
- package/dist/types/testing/setupProseMirrorView.d.ts +2 -0
- package/dist/types/viewdesc.d.ts +131 -0
- package/package.json +113 -0
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
cssToStyles: function() {
|
|
13
|
+
return cssToStyles;
|
|
14
|
+
},
|
|
15
|
+
htmlAttrsToReactProps: function() {
|
|
16
|
+
return htmlAttrsToReactProps;
|
|
17
|
+
},
|
|
18
|
+
kebabCaseToCamelCase: function() {
|
|
19
|
+
return kebabCaseToCamelCase;
|
|
20
|
+
},
|
|
21
|
+
mergeReactProps: function() {
|
|
22
|
+
return mergeReactProps;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const _classnames = /*#__PURE__*/ _interop_require_default(require("classnames"));
|
|
26
|
+
function _interop_require_default(obj) {
|
|
27
|
+
return obj && obj.__esModule ? obj : {
|
|
28
|
+
default: obj
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function kebabCaseToCamelCase(str) {
|
|
32
|
+
return str.replaceAll(/-[a-z]/g, (g)=>g[1]?.toUpperCase() ?? "");
|
|
33
|
+
}
|
|
34
|
+
function cssToStyles(css) {
|
|
35
|
+
const stylesheet = new CSSStyleSheet();
|
|
36
|
+
stylesheet.insertRule(`* { ${css} }`);
|
|
37
|
+
const insertedRule = stylesheet.cssRules[0];
|
|
38
|
+
const declaration = insertedRule.style;
|
|
39
|
+
const styles = {};
|
|
40
|
+
for(let i = 0; i < declaration.length; i++){
|
|
41
|
+
const property = declaration.item(i);
|
|
42
|
+
const value = declaration.getPropertyValue(property);
|
|
43
|
+
const camelCasePropertyName = property.startsWith("--") ? property : kebabCaseToCamelCase(property);
|
|
44
|
+
styles[camelCasePropertyName] = value;
|
|
45
|
+
}
|
|
46
|
+
return styles;
|
|
47
|
+
}
|
|
48
|
+
function mergeReactProps(a, b) {
|
|
49
|
+
return {
|
|
50
|
+
...a,
|
|
51
|
+
...b,
|
|
52
|
+
className: (0, _classnames.default)(a.className, b.className),
|
|
53
|
+
style: {
|
|
54
|
+
...a.style,
|
|
55
|
+
...b.style
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function htmlAttrsToReactProps(attrs) {
|
|
60
|
+
const props = {};
|
|
61
|
+
for (const [attrName, attrValue] of Object.entries(attrs)){
|
|
62
|
+
switch(attrName.toLowerCase()){
|
|
63
|
+
case "class":
|
|
64
|
+
{
|
|
65
|
+
props.className = attrValue;
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
case "style":
|
|
69
|
+
{
|
|
70
|
+
props.style = cssToStyles(attrValue);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
case "autocapitalize":
|
|
74
|
+
{
|
|
75
|
+
props.autoCapitalize = attrValue;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
case "contenteditable":
|
|
79
|
+
{
|
|
80
|
+
if (attrValue === "" || attrValue === "true") {
|
|
81
|
+
props.contentEditable = true;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
if (attrValue === "false") {
|
|
85
|
+
props.contentEditable = false;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
if (attrValue === "plaintext-only") {
|
|
89
|
+
props.contentEditable = "plaintext-only";
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
props.contentEditable = null;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
case "draggable":
|
|
96
|
+
{
|
|
97
|
+
props.draggable = attrValue != null;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
case "enterkeyhint":
|
|
101
|
+
{
|
|
102
|
+
props.enterKeyHint = attrValue;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case "for":
|
|
106
|
+
{
|
|
107
|
+
props.htmlFor = attrValue;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
case "hidden":
|
|
111
|
+
{
|
|
112
|
+
props.hidden = attrValue;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
case "inputmode":
|
|
116
|
+
{
|
|
117
|
+
props.inputMode = attrValue;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
case "itemprop":
|
|
121
|
+
{
|
|
122
|
+
props.itemProp = attrValue;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
case "spellcheck":
|
|
126
|
+
{
|
|
127
|
+
if (attrValue === "" || attrValue === "true") {
|
|
128
|
+
props.spellCheck = true;
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
if (attrValue === "false") {
|
|
132
|
+
props.spellCheck = false;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
props.spellCheck = null;
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
case "tabindex":
|
|
139
|
+
{
|
|
140
|
+
const numValue = parseInt(attrValue, 10);
|
|
141
|
+
if (!Number.isNaN(numValue)) {
|
|
142
|
+
props.tabIndex = numValue;
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
case "autocomplete":
|
|
147
|
+
{
|
|
148
|
+
props.autoComplete = attrValue;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
case "autofocus":
|
|
152
|
+
{
|
|
153
|
+
props.autoFocus = attrValue != null;
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
case "formaction":
|
|
157
|
+
{
|
|
158
|
+
props.formAction = attrValue;
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
case "formenctype":
|
|
162
|
+
{
|
|
163
|
+
props.formEnctype = attrValue;
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
case "formmethod":
|
|
167
|
+
{
|
|
168
|
+
props.formMethod = attrValue;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
case "formnovalidate":
|
|
172
|
+
{
|
|
173
|
+
props.formNoValidate = attrValue;
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
case "formtarget":
|
|
177
|
+
{
|
|
178
|
+
props.formTarget = attrValue;
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
case "maxlength":
|
|
182
|
+
{
|
|
183
|
+
const numValue = parseInt(attrValue, 10);
|
|
184
|
+
if (!Number.isNaN(numValue)) {
|
|
185
|
+
props.maxLength = attrValue;
|
|
186
|
+
}
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
case "minlength":
|
|
190
|
+
{
|
|
191
|
+
const numValue = parseInt(attrValue, 10);
|
|
192
|
+
if (!Number.isNaN(numValue)) {
|
|
193
|
+
props.minLength = attrValue;
|
|
194
|
+
}
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case "max":
|
|
198
|
+
{
|
|
199
|
+
const numValue = parseInt(attrValue, 10);
|
|
200
|
+
if (!Number.isNaN(numValue)) {
|
|
201
|
+
props.max = attrValue;
|
|
202
|
+
}
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
case "min":
|
|
206
|
+
{
|
|
207
|
+
const numValue = parseInt(attrValue, 10);
|
|
208
|
+
if (!Number.isNaN(numValue)) {
|
|
209
|
+
props.min = attrValue;
|
|
210
|
+
}
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
case "multiple":
|
|
214
|
+
{
|
|
215
|
+
props.multiple = attrValue != null;
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
case "readonly":
|
|
219
|
+
{
|
|
220
|
+
props.readOnly = attrValue != null;
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
case "required":
|
|
224
|
+
{
|
|
225
|
+
props.required = attrValue != null;
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
case "size":
|
|
229
|
+
{
|
|
230
|
+
const numValue = parseInt(attrValue, 10);
|
|
231
|
+
if (!Number.isNaN(numValue)) {
|
|
232
|
+
props.size = attrValue;
|
|
233
|
+
}
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
case "step":
|
|
237
|
+
{
|
|
238
|
+
if (attrValue === "any") {
|
|
239
|
+
props.step = attrValue;
|
|
240
|
+
break;
|
|
241
|
+
}
|
|
242
|
+
const numValue = parseInt(attrValue, 10);
|
|
243
|
+
if (!Number.isNaN(numValue) && numValue > 0) {
|
|
244
|
+
props.step = attrValue;
|
|
245
|
+
}
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
case "disabled":
|
|
249
|
+
{
|
|
250
|
+
props.disabled = attrValue != null;
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
case "rows":
|
|
254
|
+
{
|
|
255
|
+
const numValue = parseInt(attrValue, 10);
|
|
256
|
+
if (!Number.isNaN(numValue)) {
|
|
257
|
+
props.rows = attrValue;
|
|
258
|
+
}
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
default:
|
|
262
|
+
{
|
|
263
|
+
props[attrName] = attrValue;
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return props;
|
|
269
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "SelectionDOMObserver", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return SelectionDOMObserver;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _prosemirrorstate = require("prosemirror-state");
|
|
12
|
+
const _browser = require("../browser.js");
|
|
13
|
+
const _dom = require("../dom.js");
|
|
14
|
+
const _hasFocusAndSelection = require("./hasFocusAndSelection.js");
|
|
15
|
+
const _selectionFromDOM = require("./selectionFromDOM.js");
|
|
16
|
+
const _selectionToDOM = require("./selectionToDOM.js");
|
|
17
|
+
let SelectionState = class SelectionState {
|
|
18
|
+
anchorNode = null;
|
|
19
|
+
anchorOffset = 0;
|
|
20
|
+
focusNode = null;
|
|
21
|
+
focusOffset = 0;
|
|
22
|
+
set(sel) {
|
|
23
|
+
this.anchorNode = sel.anchorNode;
|
|
24
|
+
this.anchorOffset = sel.anchorOffset;
|
|
25
|
+
this.focusNode = sel.focusNode;
|
|
26
|
+
this.focusOffset = sel.focusOffset;
|
|
27
|
+
}
|
|
28
|
+
clear() {
|
|
29
|
+
this.anchorNode = this.focusNode = null;
|
|
30
|
+
}
|
|
31
|
+
eq(sel) {
|
|
32
|
+
return sel.anchorNode == this.anchorNode && sel.anchorOffset == this.anchorOffset && sel.focusNode == this.focusNode && sel.focusOffset == this.focusOffset;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
let SelectionDOMObserver = class SelectionDOMObserver {
|
|
36
|
+
view;
|
|
37
|
+
flushingSoon;
|
|
38
|
+
currentSelection;
|
|
39
|
+
suppressingSelectionUpdates;
|
|
40
|
+
constructor(view){
|
|
41
|
+
this.view = view;
|
|
42
|
+
this.flushingSoon = -1;
|
|
43
|
+
this.currentSelection = new SelectionState();
|
|
44
|
+
this.suppressingSelectionUpdates = false;
|
|
45
|
+
this.view = view;
|
|
46
|
+
this.onSelectionChange = this.onSelectionChange.bind(this);
|
|
47
|
+
}
|
|
48
|
+
connectSelection() {
|
|
49
|
+
this.view.dom.ownerDocument.addEventListener("selectionchange", this.onSelectionChange);
|
|
50
|
+
}
|
|
51
|
+
disconnectSelection() {
|
|
52
|
+
this.view.dom.ownerDocument.removeEventListener("selectionchange", this.onSelectionChange);
|
|
53
|
+
}
|
|
54
|
+
stop() {
|
|
55
|
+
this.disconnectSelection();
|
|
56
|
+
}
|
|
57
|
+
start() {
|
|
58
|
+
this.connectSelection();
|
|
59
|
+
}
|
|
60
|
+
suppressSelectionUpdates() {
|
|
61
|
+
this.suppressingSelectionUpdates = true;
|
|
62
|
+
setTimeout(()=>this.suppressingSelectionUpdates = false, 50);
|
|
63
|
+
}
|
|
64
|
+
setCurSelection() {
|
|
65
|
+
// @ts-expect-error Internal method
|
|
66
|
+
this.currentSelection.set(this.view.domSelectionRange());
|
|
67
|
+
}
|
|
68
|
+
ignoreSelectionChange(sel) {
|
|
69
|
+
if (!sel.focusNode) return true;
|
|
70
|
+
const ancestors = new Set();
|
|
71
|
+
let container;
|
|
72
|
+
for(let scan = sel.focusNode; scan; scan = (0, _dom.parentNode)(scan))ancestors.add(scan);
|
|
73
|
+
for(let scan = sel.anchorNode; scan; scan = (0, _dom.parentNode)(scan))if (ancestors.has(scan)) {
|
|
74
|
+
container = scan;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
// @ts-expect-error Internal property (docView)
|
|
78
|
+
const desc = container && this.view.docView.nearestDesc(container);
|
|
79
|
+
if (desc && desc.ignoreMutation({
|
|
80
|
+
type: "selection",
|
|
81
|
+
target: container?.nodeType == 3 ? container?.parentNode : container
|
|
82
|
+
})) {
|
|
83
|
+
this.setCurSelection();
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
registerMutation() {
|
|
89
|
+
// pass
|
|
90
|
+
}
|
|
91
|
+
flushSoon() {
|
|
92
|
+
if (this.flushingSoon < 0) this.flushingSoon = window.setTimeout(()=>{
|
|
93
|
+
this.flushingSoon = -1;
|
|
94
|
+
this.flush();
|
|
95
|
+
}, 20);
|
|
96
|
+
}
|
|
97
|
+
updateSelection() {
|
|
98
|
+
const { view } = this;
|
|
99
|
+
const compositionID = // @ts-expect-error Internal property (input)
|
|
100
|
+
view.input.compositionPendingChanges || // @ts-expect-error Internal property (input)
|
|
101
|
+
(view.composing ? view.input.compositionID : 0);
|
|
102
|
+
// @ts-expect-error Internal property (input)
|
|
103
|
+
view.input.compositionPendingChanges = 0;
|
|
104
|
+
const origin = // @ts-expect-error Internal property (input)
|
|
105
|
+
view.input.lastSelectionTime > Date.now() - 50 ? view.input.lastSelectionOrigin : null;
|
|
106
|
+
const newSel = (0, _selectionFromDOM.selectionFromDOM)(view, origin);
|
|
107
|
+
if (newSel && !view.state.selection.eq(newSel)) {
|
|
108
|
+
const tr = view.state.tr.setSelection(newSel);
|
|
109
|
+
if (origin == "pointer") tr.setMeta("pointer", true);
|
|
110
|
+
else if (origin == "key") tr.scrollIntoView();
|
|
111
|
+
if (compositionID) tr.setMeta("composition", compositionID);
|
|
112
|
+
view.dispatch(tr);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
selectionToDOM() {
|
|
116
|
+
const { view } = this;
|
|
117
|
+
(0, _selectionToDOM.selectionToDOM)(view);
|
|
118
|
+
// @ts-expect-error Internal property (domSelectionRange)
|
|
119
|
+
const sel = view.domSelectionRange();
|
|
120
|
+
this.currentSelection.set(sel);
|
|
121
|
+
}
|
|
122
|
+
flush() {
|
|
123
|
+
const { view } = this;
|
|
124
|
+
// @ts-expect-error Internal property (docView)
|
|
125
|
+
if (!view.docView || this.flushingSoon > -1) return;
|
|
126
|
+
// @ts-expect-error Internal property (domSelectionRange)
|
|
127
|
+
const sel = view.domSelectionRange();
|
|
128
|
+
const newSel = !this.suppressingSelectionUpdates && !this.currentSelection.eq(sel) && (0, _hasFocusAndSelection.hasFocusAndSelection)(view) && !this.ignoreSelectionChange(sel);
|
|
129
|
+
let readSel = null;
|
|
130
|
+
// If it looks like the browser has reset the selection to the
|
|
131
|
+
// start of the document after focus, restore the selection from
|
|
132
|
+
// the state
|
|
133
|
+
if (newSel && // @ts-expect-error Internal property (input)
|
|
134
|
+
view.input.lastFocus > Date.now() - 200 && // @ts-expect-error Internal property (input)
|
|
135
|
+
Math.max(view.input.lastTouch, view.input.lastClick.time) < Date.now() - 300 && (0, _dom.selectionCollapsed)(sel) && (readSel = (0, _selectionFromDOM.selectionFromDOM)(view)) && readSel.eq(_prosemirrorstate.Selection.near(view.state.doc.resolve(0), 1))) {
|
|
136
|
+
// @ts-expect-error Internal property (input)
|
|
137
|
+
view.input.lastFocus = 0;
|
|
138
|
+
(0, _selectionToDOM.selectionToDOM)(view);
|
|
139
|
+
this.currentSelection.set(sel);
|
|
140
|
+
// @ts-expect-error Internal property (scrollToSelection)
|
|
141
|
+
view.scrollToSelection();
|
|
142
|
+
} else if (newSel) {
|
|
143
|
+
this.updateSelection();
|
|
144
|
+
if (!this.currentSelection.eq(sel)) (0, _selectionToDOM.selectionToDOM)(view);
|
|
145
|
+
this.currentSelection.set(sel);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
selectionChanged(sel) {
|
|
149
|
+
return !this.suppressingSelectionUpdates && !this.currentSelection.eq(sel) && (0, _hasFocusAndSelection.hasFocusAndSelection)(this.view) && !this.ignoreSelectionChange(sel);
|
|
150
|
+
}
|
|
151
|
+
forceFlush() {
|
|
152
|
+
if (this.flushingSoon > -1) {
|
|
153
|
+
window.clearTimeout(this.flushingSoon);
|
|
154
|
+
this.flushingSoon = -1;
|
|
155
|
+
this.flush();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
onSelectionChange() {
|
|
159
|
+
if (!(0, _hasFocusAndSelection.hasFocusAndSelection)(this.view)) return;
|
|
160
|
+
if (this.view.composing) return;
|
|
161
|
+
if (this.suppressingSelectionUpdates) return (0, _selectionToDOM.selectionToDOM)(this.view);
|
|
162
|
+
// Deletions on IE11 fire their events in the wrong order, giving
|
|
163
|
+
// us a selection change event before the DOM changes are
|
|
164
|
+
// reported.
|
|
165
|
+
if (_browser.browser.ie && _browser.browser.ie_version <= 11 && !this.view.state.selection.empty) {
|
|
166
|
+
// @ts-expect-error Internal method
|
|
167
|
+
const sel = this.view.domSelectionRange();
|
|
168
|
+
// Selection.isCollapsed isn't reliable on IE
|
|
169
|
+
if (sel.focusNode && (0, _selectionToDOM.isEquivalentPosition)(sel.focusNode, sel.focusOffset, // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
170
|
+
sel.anchorNode, sel.anchorOffset)) return this.flushSoon();
|
|
171
|
+
}
|
|
172
|
+
this.flush();
|
|
173
|
+
}
|
|
174
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
hasFocusAndSelection: function() {
|
|
13
|
+
return hasFocusAndSelection;
|
|
14
|
+
},
|
|
15
|
+
hasSelection: function() {
|
|
16
|
+
return hasSelection;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
function hasFocusAndSelection(view) {
|
|
20
|
+
if (view.editable && !view.hasFocus()) return false;
|
|
21
|
+
return hasSelection(view);
|
|
22
|
+
}
|
|
23
|
+
function hasSelection(view) {
|
|
24
|
+
// @ts-expect-error Internal method
|
|
25
|
+
const sel = view.domSelectionRange();
|
|
26
|
+
if (!sel.anchorNode) return false;
|
|
27
|
+
try {
|
|
28
|
+
// Firefox will raise 'permission denied' errors when accessing
|
|
29
|
+
// properties of `sel.anchorNode` when it's in a generated CSS
|
|
30
|
+
// element.
|
|
31
|
+
return view.dom.contains(sel.anchorNode.nodeType == 3 ? sel.anchorNode.parentNode : sel.anchorNode) && (view.editable || view.dom.contains(sel.focusNode?.nodeType == 3 ? sel.focusNode?.parentNode : sel.focusNode));
|
|
32
|
+
} catch (_) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
selectionBetween: function() {
|
|
13
|
+
return selectionBetween;
|
|
14
|
+
},
|
|
15
|
+
selectionFromDOM: function() {
|
|
16
|
+
return selectionFromDOM;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _prosemirrorstate = require("prosemirror-state");
|
|
20
|
+
const _dom = require("../dom.js");
|
|
21
|
+
function selectionBetween(view, $anchor, $head, bias) {
|
|
22
|
+
return view.someProp("createSelectionBetween", (f)=>f(view, $anchor, $head)) || _prosemirrorstate.TextSelection.between($anchor, $head, bias);
|
|
23
|
+
}
|
|
24
|
+
function selectionFromDOM(view) {
|
|
25
|
+
let origin = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null;
|
|
26
|
+
// @ts-expect-error Internal method
|
|
27
|
+
const domSel = view.domSelectionRange(), doc = view.state.doc;
|
|
28
|
+
if (!domSel.focusNode) return null;
|
|
29
|
+
// @ts-expect-error Internal method
|
|
30
|
+
let nearestDesc = view.docView.nearestDesc(domSel.focusNode);
|
|
31
|
+
const inWidget = nearestDesc && nearestDesc.size == 0;
|
|
32
|
+
// @ts-expect-error Internal method
|
|
33
|
+
let head = view.docView.posFromDOM(domSel.focusNode, domSel.focusOffset, 1);
|
|
34
|
+
if (head < 0) return null;
|
|
35
|
+
let $head = doc.resolve(head), anchor, selection;
|
|
36
|
+
if ((0, _dom.selectionCollapsed)(domSel)) {
|
|
37
|
+
anchor = head;
|
|
38
|
+
while(nearestDesc && !nearestDesc.node)nearestDesc = nearestDesc.parent;
|
|
39
|
+
const nearestDescNode = nearestDesc.node;
|
|
40
|
+
if (nearestDesc && nearestDescNode.isAtom && _prosemirrorstate.NodeSelection.isSelectable(nearestDescNode) && nearestDesc.parent && !(nearestDescNode.isInline && (0, _dom.isOnEdge)(domSel.focusNode, domSel.focusOffset, nearestDesc.dom))) {
|
|
41
|
+
const pos = nearestDesc.posBefore;
|
|
42
|
+
selection = new _prosemirrorstate.NodeSelection(head == pos ? $head : doc.resolve(pos));
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
if (// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
46
|
+
domSel instanceof view.dom.ownerDocument.defaultView.Selection && domSel.rangeCount > 1) {
|
|
47
|
+
let min = head, max = head;
|
|
48
|
+
for(let i = 0; i < domSel.rangeCount; i++){
|
|
49
|
+
const range = domSel.getRangeAt(i);
|
|
50
|
+
min = Math.min(min, // @ts-expect-error Internal method
|
|
51
|
+
view.docView.posFromDOM(range.startContainer, range.startOffset, 1));
|
|
52
|
+
max = Math.max(max, // @ts-expect-error Internal method
|
|
53
|
+
view.docView.posFromDOM(range.endContainer, range.endOffset, -1));
|
|
54
|
+
}
|
|
55
|
+
if (min < 0) return null;
|
|
56
|
+
[anchor, head] = max == view.state.selection.anchor ? [
|
|
57
|
+
max,
|
|
58
|
+
min
|
|
59
|
+
] : [
|
|
60
|
+
min,
|
|
61
|
+
max
|
|
62
|
+
];
|
|
63
|
+
$head = doc.resolve(head);
|
|
64
|
+
} else {
|
|
65
|
+
// @ts-expect-error Internal method
|
|
66
|
+
anchor = view.docView.posFromDOM(// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
67
|
+
domSel.anchorNode, domSel.anchorOffset, 1);
|
|
68
|
+
}
|
|
69
|
+
if (anchor < 0) return null;
|
|
70
|
+
}
|
|
71
|
+
const $anchor = doc.resolve(anchor);
|
|
72
|
+
if (!selection) {
|
|
73
|
+
const bias = origin == "pointer" || view.state.selection.head < $head.pos && !inWidget ? 1 : -1;
|
|
74
|
+
selection = selectionBetween(view, $anchor, $head, bias);
|
|
75
|
+
}
|
|
76
|
+
return selection;
|
|
77
|
+
}
|