markupeditor 0.9.48 → 0.9.50

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.
@@ -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 { $from } = view.state.selection;
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 false
43393
+ return handled
43342
43394
  },
43395
+ transformPastedHTML,
43396
+ transformPastedText,
43343
43397
  handleKeyDown(view, event) {
43344
43398
  switch (event.key) {
43345
43399
  case 'Enter':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markupeditor",
3
- "version": "0.9.48",
3
+ "version": "0.9.50",
4
4
  "description": "A web component and API for WYSIWYG HTML editing.",
5
5
  "keywords": [
6
6
  "wysiwyg",
@@ -30,7 +30,6 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "crelt": "^1.0.6",
33
- "express": "^5.1.0",
34
33
  "highlight.js": "^11.11.1",
35
34
  "prosemirror-commands": "^1.0.0",
36
35
  "prosemirror-dropcursor": "^1.8.1",