markupeditor 0.9.48 → 0.9.49
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/dist/markup-editor.js +67 -13
- package/package.json +1 -1
package/dist/markup-editor.js
CHANGED
|
@@ -33691,19 +33691,80 @@ function pasteHTML(html, event) {
|
|
|
33691
33691
|
view.pasteHTML(html, event);
|
|
33692
33692
|
stateChanged(view);
|
|
33693
33693
|
}
|
|
33694
|
+
/**
|
|
33695
|
+
* Replace curly quotes/apostrophes with their straight ASCII equivalents. A smart
|
|
33696
|
+
* quote is never something the user typed themselves in this editor -- matches the
|
|
33697
|
+
* same normalization MarkupEditorApp applies to its own Source view text on the way
|
|
33698
|
+
* into the document.
|
|
33699
|
+
* @ignore
|
|
33700
|
+
* @param {string} text
|
|
33701
|
+
* @returns {string}
|
|
33702
|
+
*/
|
|
33703
|
+
function _normalizeSmartPunctuation(text) {
|
|
33704
|
+
return text
|
|
33705
|
+
.replaceAll('‘', "'").replaceAll('’', "'")
|
|
33706
|
+
.replaceAll('“', '"').replaceAll('”', '"')
|
|
33707
|
+
}
|
|
33694
33708
|
/**
|
|
33695
33709
|
* Paste the `text` into a code block. Caller determines whether to use this method
|
|
33696
33710
|
* based on the selection state.
|
|
33697
|
-
*
|
|
33711
|
+
*
|
|
33698
33712
|
* @param {string} text The text to be pasted in a preformatted code block
|
|
33699
33713
|
*/
|
|
33700
33714
|
function pasteCode(text) {
|
|
33701
33715
|
const view = activeView();
|
|
33702
33716
|
if (!view) return
|
|
33703
|
-
view.dispatch(view.state.tr.insertText(text));
|
|
33717
|
+
view.dispatch(view.state.tr.insertText(_normalizeSmartPunctuation(text)));
|
|
33704
33718
|
stateChanged(view);
|
|
33705
33719
|
}
|
|
33706
33720
|
|
|
33721
|
+
/**
|
|
33722
|
+
* ProseMirror's own handlePaste EditorView prop for a REAL DOM paste event (e.g. a
|
|
33723
|
+
* plain browser Cmd+V, distinct from pasteCode's own explicit insertText call -- see
|
|
33724
|
+
* that function's own comment). Only intervenes when the selection is inside a
|
|
33725
|
+
* code_block; returns false (unhandled) for anything else,
|
|
33726
|
+
* letting ProseMirror's default paste behavior take over. Extracted out of
|
|
33727
|
+
* markupeditor.js's inline handlePaste prop so this decision/normalization logic is
|
|
33728
|
+
* testable independent of that prop's own target-closure/callbackInput side effect.
|
|
33729
|
+
* @ignore
|
|
33730
|
+
* @param {EditorView} view
|
|
33731
|
+
* @param {ClipboardEvent} event
|
|
33732
|
+
* @returns {boolean}
|
|
33733
|
+
*/
|
|
33734
|
+
function handleCodeBlockPaste(view, event) {
|
|
33735
|
+
const { $from } = view.state.selection;
|
|
33736
|
+
const inCodeBlock = $from.parent.type === view.state.schema.nodes.code_block;
|
|
33737
|
+
if (!inCodeBlock || !event?.clipboardData) return false
|
|
33738
|
+
const text = event.clipboardData.getData('text/plain');
|
|
33739
|
+
if (!text) return false
|
|
33740
|
+
view.dispatch(view.state.tr.insertText(_normalizeSmartPunctuation(text)));
|
|
33741
|
+
return true
|
|
33742
|
+
}
|
|
33743
|
+
|
|
33744
|
+
/**
|
|
33745
|
+
* ProseMirror's transformPastedHTML EditorView prop, run on pasted HTML before it's
|
|
33746
|
+
* parsed into the document, for both a real DOM paste and this file's own
|
|
33747
|
+
* pasteHTML/pasteText. Does not fire for a code_block paste, since handleCodeBlockPaste
|
|
33748
|
+
* already intercepts and returns true before ProseMirror's default paste handling runs.
|
|
33749
|
+
* @ignore
|
|
33750
|
+
* @param {string} html
|
|
33751
|
+
* @returns {string}
|
|
33752
|
+
*/
|
|
33753
|
+
function transformPastedHTML(html) {
|
|
33754
|
+
return _normalizeSmartPunctuation(html)
|
|
33755
|
+
}
|
|
33756
|
+
|
|
33757
|
+
/**
|
|
33758
|
+
* ProseMirror's transformPastedText EditorView prop -- the plain-text counterpart to
|
|
33759
|
+
* transformPastedHTML, run when the clipboard is pasted as plain text.
|
|
33760
|
+
* @ignore
|
|
33761
|
+
* @param {string} text
|
|
33762
|
+
* @returns {string}
|
|
33763
|
+
*/
|
|
33764
|
+
function transformPastedText(text) {
|
|
33765
|
+
return _normalizeSmartPunctuation(text)
|
|
33766
|
+
}
|
|
33767
|
+
|
|
33707
33768
|
/**
|
|
33708
33769
|
* Do a custom paste operation of "text only", which we will extract from the html
|
|
33709
33770
|
* ourselves. First we get a node that conforms to the schema, which by definition
|
|
@@ -43327,19 +43388,12 @@ class MarkupEditor {
|
|
|
43327
43388
|
'delete': () => { setTimeout(() => { callbackInput(target); }, 0); },
|
|
43328
43389
|
},
|
|
43329
43390
|
handlePaste(view, event) {
|
|
43330
|
-
const
|
|
43331
|
-
const inCodeBlock = $from.parent.type === view.state.schema.nodes.code_block;
|
|
43332
|
-
if (inCodeBlock && event?.clipboardData) {
|
|
43333
|
-
const text = event.clipboardData.getData('text/plain');
|
|
43334
|
-
if (text) {
|
|
43335
|
-
view.dispatch(view.state.tr.insertText(text));
|
|
43336
|
-
setTimeout(() => { callbackInput(target); }, 0);
|
|
43337
|
-
return true
|
|
43338
|
-
}
|
|
43339
|
-
}
|
|
43391
|
+
const handled = handleCodeBlockPaste(view, event);
|
|
43340
43392
|
setTimeout(() => { callbackInput(target); }, 0);
|
|
43341
|
-
return
|
|
43393
|
+
return handled
|
|
43342
43394
|
},
|
|
43395
|
+
transformPastedHTML,
|
|
43396
|
+
transformPastedText,
|
|
43343
43397
|
handleKeyDown(view, event) {
|
|
43344
43398
|
switch (event.key) {
|
|
43345
43399
|
case 'Enter':
|