markupeditor 0.9.47 → 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 +69 -18
- 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
|
|
@@ -34480,6 +34541,7 @@ function toggleFormatCommand(type) {
|
|
|
34480
34541
|
} if (toggle && view) {
|
|
34481
34542
|
toggle(state, view.dispatch);
|
|
34482
34543
|
stateChanged(view);
|
|
34544
|
+
return true
|
|
34483
34545
|
} else {
|
|
34484
34546
|
return toggle
|
|
34485
34547
|
}
|
|
@@ -34551,6 +34613,7 @@ function setStyleCommand(style) {
|
|
|
34551
34613
|
const newState = view.state.apply(transaction);
|
|
34552
34614
|
view.updateState(newState);
|
|
34553
34615
|
stateChanged(view);
|
|
34616
|
+
return true
|
|
34554
34617
|
} else { // When checking if active based on state, return true only if different
|
|
34555
34618
|
return paragraphStyle(state) != style;
|
|
34556
34619
|
}
|
|
@@ -36008,11 +36071,6 @@ function _testKeyCodeFor(key) {
|
|
|
36008
36071
|
* @throws {Error} If `key` contains an unrecognized modifier
|
|
36009
36072
|
* prefix, including the unsupported "Mod-".
|
|
36010
36073
|
* @returns {boolean} Whether a handler returned `true` for the key.
|
|
36011
|
-
* NOT a reliable "the document changed" signal:
|
|
36012
|
-
* some commands (e.g. setStyleCommand,
|
|
36013
|
-
* toggleFormatCommand) dispatch without returning
|
|
36014
|
-
* `true`, so the document can still mutate while
|
|
36015
|
-
* this returns `false`.
|
|
36016
36074
|
*/
|
|
36017
36075
|
function testTypeKey(key) {
|
|
36018
36076
|
const view = activeView();
|
|
@@ -43330,19 +43388,12 @@ class MarkupEditor {
|
|
|
43330
43388
|
'delete': () => { setTimeout(() => { callbackInput(target); }, 0); },
|
|
43331
43389
|
},
|
|
43332
43390
|
handlePaste(view, event) {
|
|
43333
|
-
const
|
|
43334
|
-
const inCodeBlock = $from.parent.type === view.state.schema.nodes.code_block;
|
|
43335
|
-
if (inCodeBlock && event?.clipboardData) {
|
|
43336
|
-
const text = event.clipboardData.getData('text/plain');
|
|
43337
|
-
if (text) {
|
|
43338
|
-
view.dispatch(view.state.tr.insertText(text));
|
|
43339
|
-
setTimeout(() => { callbackInput(target); }, 0);
|
|
43340
|
-
return true
|
|
43341
|
-
}
|
|
43342
|
-
}
|
|
43391
|
+
const handled = handleCodeBlockPaste(view, event);
|
|
43343
43392
|
setTimeout(() => { callbackInput(target); }, 0);
|
|
43344
|
-
return
|
|
43393
|
+
return handled
|
|
43345
43394
|
},
|
|
43395
|
+
transformPastedHTML,
|
|
43396
|
+
transformPastedText,
|
|
43346
43397
|
handleKeyDown(view, event) {
|
|
43347
43398
|
switch (event.key) {
|
|
43348
43399
|
case 'Enter':
|