@meowdown/core 0.72.0 → 0.72.1

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/index.d.ts CHANGED
@@ -1162,7 +1162,7 @@ declare function defineEditorExtensionImpl(options: EditorExtensionOptions): imp
1162
1162
  fenceLength?: number | null;
1163
1163
  };
1164
1164
  };
1165
- }>, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension]>, MeowdownHorizontalRuleExtension, import("@prosekit/core").Extension<{
1165
+ }>, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension]>, MeowdownHorizontalRuleExtension, import("@prosekit/core").Extension<{
1166
1166
  Nodes: {
1167
1167
  htmlComment: MeowdownHTMLCommentAttrs;
1168
1168
  };
@@ -1226,7 +1226,7 @@ declare function defineEditorExtensionImpl(options: EditorExtensionOptions): imp
1226
1226
  Marks: {
1227
1227
  mdPack: MdPackAttrs;
1228
1228
  };
1229
- }>]>, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").Extension<import("@prosekit/core").ExtensionTyping<any, any, any>>, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").Union<readonly [import("@prosekit/core").Extension<{
1229
+ }>]>, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").Extension<import("@prosekit/core").ExtensionTyping<any, any, any>>, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").PlainExtension, import("@prosekit/core").Union<readonly [import("@prosekit/core").Extension<{
1230
1230
  Commands: {
1231
1231
  insertSoftBreak: [];
1232
1232
  };
@@ -1409,7 +1409,7 @@ export declare const EDITOR_KEY_BINDINGS: {
1409
1409
  readonly 'Mod-5': "Heading 5";
1410
1410
  readonly 'Mod-6': "Heading 6";
1411
1411
  readonly 'Mod-.': "Fold or unfold a bullet";
1412
- readonly 'Shift-Enter': "Insert a line break";
1412
+ readonly 'Shift-Enter': "Insert a line break, or leave a code block from its end";
1413
1413
  readonly 'Mod-Enter': "Follow the link under the caret, or cycle a checkbox task";
1414
1414
  readonly 'Mod-Shift-Enter': "Cycle a circle checkbox task";
1415
1415
  readonly 'Mod-Shift-7': "Ordered list";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Priority, Priority as Priority$1, createMarkBuilders, createNodeBuilders, defineBaseCommands, defineBaseKeymap, defineClipboardSerializer, defineCommands, defineHistory, defineKeymap, defineMarkSpec, defineMarkView, defineNodeAttr, defineNodeSpec, definePlugin, findMarkRange, getMarkRange, getMarkType, getNodeType, isAllSelection, isApple, isAtBlockStart, isNodeSelection, isTextSelection, setBlockType, toggleNode, union, unsetBlockType, withPriority, withPriority as withPriority$1, withSkipCodeBlock } from "@prosekit/core";
1
+ import { Priority, Priority as Priority$1, createMarkBuilders, createNodeBuilders, defaultBlockAt, defineBaseCommands, defineBaseKeymap, defineClipboardSerializer, defineCommands, defineHistory, defineKeymap, defineMarkSpec, defineMarkView, defineNodeAttr, defineNodeSpec, definePlugin, findMarkRange, getMarkRange, getMarkType, getNodeType, isAllSelection, isApple, isAtBlockStart, isNodeSelection, isTextSelection, setBlockType, toggleNode, union, unsetBlockType, withPriority, withPriority as withPriority$1, withSkipCodeBlock } from "@prosekit/core";
2
2
  import { defineCodeBlock, defineCodeBlockHighlight, defineCodeBlockPreviewPlugin, isCodeBlockPreviewHiddenDecoration } from "@prosekit/extensions/code-block";
3
3
  import { definePlaceholder, definePlaceholder as definePlaceholder$1 } from "@prosekit/extensions/placeholder";
4
4
  import { NodeSelection, Plugin, PluginKey, Selection, TextSelection } from "@prosekit/pm/state";
@@ -602,6 +602,41 @@ function defineBulletAfterHeading(enabled) {
602
602
  } }), Priority$1.high);
603
603
  }
604
604
 
605
+ //#endregion
606
+ //#region src/extensions/click-below.ts
607
+ const clickBelowKey = new PluginKey("meowdown-click-below");
608
+ function acceptsCaretAtEnd(node) {
609
+ return node.isTextblock && !node.type.spec.code;
610
+ }
611
+ function handleMouseDown(view, event) {
612
+ if (event.target !== view.dom) return false;
613
+ if (event.button !== 0 || !view.editable) return false;
614
+ const { doc } = view.state;
615
+ const lastBlock = doc.lastChild;
616
+ if (!lastBlock || acceptsCaretAtEnd(lastBlock)) return false;
617
+ const lastBlockDOM = view.nodeDOM(doc.content.size - lastBlock.nodeSize);
618
+ if (!(lastBlockDOM instanceof HTMLElement)) return false;
619
+ if (event.clientY <= lastBlockDOM.getBoundingClientRect().bottom) return false;
620
+ const block = defaultBlockAt(doc.contentMatchAt(doc.childCount))?.createAndFill();
621
+ if (!block) return false;
622
+ event.preventDefault();
623
+ const end = doc.content.size;
624
+ const tr = view.state.tr.insert(end, block);
625
+ view.dispatch(tr.setSelection(TextSelection.create(tr.doc, end + 1)).scrollIntoView());
626
+ view.focus();
627
+ return true;
628
+ }
629
+ /**
630
+ * A press below the last block appends an empty paragraph and puts the caret
631
+ * in it, when that block would otherwise keep the caret inside itself.
632
+ */
633
+ function defineClickBelow() {
634
+ return definePlugin(new Plugin({
635
+ key: clickBelowKey,
636
+ props: { handleDOMEvents: { mousedown: handleMouseDown } }
637
+ }));
638
+ }
639
+
605
640
  //#endregion
606
641
  //#region src/converters/html-to-md.ts
607
642
  /**
@@ -2222,6 +2257,38 @@ function getCodeTokens(code, language) {
2222
2257
  return loadLanguageSupport(trimmed).then((loaded) => loaded ? tokenize(code, loaded) : []);
2223
2258
  }
2224
2259
 
2260
+ //#endregion
2261
+ //#region src/extensions/code-block-exit.ts
2262
+ /**
2263
+ * With the caret at the end of a code block, move it into the block below when
2264
+ * that block is an empty paragraph, and into a new default block otherwise.
2265
+ */
2266
+ const exitCodeBlockAtEnd = (state, dispatch) => {
2267
+ const { $head, empty } = state.selection;
2268
+ if (!empty) return false;
2269
+ const codeBlock = $head.parent;
2270
+ if (!codeBlock.type.spec.code || $head.parentOffset !== codeBlock.content.size) return false;
2271
+ const container = $head.node(-1);
2272
+ const indexAfter = $head.indexAfter(-1);
2273
+ const after = $head.after();
2274
+ const next = container.maybeChild(indexAfter);
2275
+ if (next && isNodeOfType(next, "paragraph") && next.content.size === 0) {
2276
+ dispatch?.(state.tr.setSelection(TextSelection.create(state.doc, after + 1)).scrollIntoView());
2277
+ return true;
2278
+ }
2279
+ const type = defaultBlockAt(container.contentMatchAt(indexAfter));
2280
+ const block = type?.createAndFill();
2281
+ if (!type || !block || !container.canReplaceWith(indexAfter, indexAfter, type)) return false;
2282
+ if (dispatch) {
2283
+ const tr = state.tr.insert(after, block);
2284
+ dispatch(tr.setSelection(TextSelection.create(tr.doc, after + 1)).scrollIntoView());
2285
+ }
2286
+ return true;
2287
+ };
2288
+ function defineCodeBlockExitKeymap() {
2289
+ return defineKeymap({ "Mod-Enter": exitCodeBlockAtEnd });
2290
+ }
2291
+
2225
2292
  //#endregion
2226
2293
  //#region src/extensions/code-block.ts
2227
2294
  function defineFenceStyleAttr() {
@@ -2279,7 +2346,7 @@ function defineDollarFenceEnterRule() {
2279
2346
  });
2280
2347
  }
2281
2348
  function defineCodeBlock$1() {
2282
- return union(defineCodeBlock(), defineFenceStyleAttr(), defineFenceLengthAttr(), defineTildeFenceInputRule(), defineTildeFenceEnterRule(), defineDollarFenceEnterRule());
2349
+ return union(defineCodeBlock(), defineFenceStyleAttr(), defineFenceLengthAttr(), defineTildeFenceInputRule(), defineTildeFenceEnterRule(), defineDollarFenceEnterRule(), defineCodeBlockExitKeymap());
2283
2350
  }
2284
2351
 
2285
2352
  //#endregion
@@ -7288,7 +7355,7 @@ function insertSoftBreak() {
7288
7355
  return softBreakCommand;
7289
7356
  }
7290
7357
  function defineSoftBreak() {
7291
- return union(defineCommands({ insertSoftBreak }), defineKeymap({ "Shift-Enter": softBreakCommand }));
7358
+ return union(defineCommands({ insertSoftBreak }), defineKeymap({ "Shift-Enter": chainCommands(exitCodeBlockAtEnd, softBreakCommand) }));
7292
7359
  }
7293
7360
 
7294
7361
  //#endregion
@@ -7547,7 +7614,7 @@ function defineEditorExtensionImpl(options) {
7547
7614
  if (editorClassName) attributes.class += ` ${editorClassName}`;
7548
7615
  if (spellCheck != null) attributes.spellcheck = String(spellCheck);
7549
7616
  return attributes;
7550
- }), defineCodeBlockSyntaxHighlight(), defineCrossEditorDrag(), defineEscapeCollapse(), defineSoftBreak(), defineMoveBlock(), defineSelectDocBoundary(), defineInlineMarkPlugin(getEditorConfig), defineInlineToggle(), defineLinkCommands(), defineWikilink(), defineMath(), defineMarkMode(getMarkMode), defineClipboard(), defineScrollToSelection(), defineHiddenRunCaret(), defineSystemSubstitutionGuard(), defineAtomMarkNavigation({ marks: ATOM_SOURCE_MARK_NAMES.map((name) => ({
7617
+ }), defineCodeBlockSyntaxHighlight(), defineCrossEditorDrag(), defineClickBelow(), defineEscapeCollapse(), defineSoftBreak(), defineMoveBlock(), defineSelectDocBoundary(), defineInlineMarkPlugin(getEditorConfig), defineInlineToggle(), defineLinkCommands(), defineWikilink(), defineMath(), defineMarkMode(getMarkMode), defineClipboard(), defineScrollToSelection(), defineHiddenRunCaret(), defineSystemSubstitutionGuard(), defineAtomMarkNavigation({ marks: ATOM_SOURCE_MARK_NAMES.map((name) => ({
7551
7618
  name,
7552
7619
  modes: [
7553
7620
  "hide",
@@ -8340,7 +8407,7 @@ const EDITOR_KEY_BINDINGS = {
8340
8407
  "Mod-5": "Heading 5",
8341
8408
  "Mod-6": "Heading 6",
8342
8409
  "Mod-.": "Fold or unfold a bullet",
8343
- "Shift-Enter": "Insert a line break",
8410
+ "Shift-Enter": "Insert a line break, or leave a code block from its end",
8344
8411
  "Mod-Enter": "Follow the link under the caret, or cycle a checkbox task",
8345
8412
  "Mod-Shift-Enter": "Cycle a circle checkbox task",
8346
8413
  "Mod-Shift-7": "Ordered list",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@meowdown/core",
3
3
  "type": "module",
4
- "version": "0.72.0",
4
+ "version": "0.72.1",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -25,6 +25,7 @@
25
25
  "@codemirror/language-data": "^6.5.2",
26
26
  "@floating-ui/dom": "^1.8.0",
27
27
  "@lezer/highlight": "^1.2.3",
28
+ "@meowdown/markdown": "^0.72.0",
28
29
  "@ocavue/utils": "^1.8.0",
29
30
  "@post-embed/elements": "^0.5.0",
30
31
  "@post-embed/exporter": "^0.4.1",
@@ -48,10 +49,10 @@
48
49
  "remark-stringify": "^11.0.0",
49
50
  "unicode-by-name": "^0.2.0",
50
51
  "unified": "^11.0.5",
51
- "valibot": "^1.5.0",
52
- "@meowdown/markdown": "^0.72.0"
52
+ "valibot": "^1.5.0"
53
53
  },
54
54
  "devDependencies": {
55
+ "@meowdown/vitest": "0.0.0",
55
56
  "@ocavue/tsconfig": "^0.7.1",
56
57
  "@tsdown/css": "^0.23.0",
57
58
  "@types/hast": "^3.0.5",
@@ -61,9 +62,7 @@
61
62
  "dedent": "^1.7.2",
62
63
  "diffable-html-snapshot": "^0.3.0",
63
64
  "tsdown": "^0.23.0",
64
- "vitest": "^5.0.1",
65
- "vitest-browser-commands": "^0.4.1",
66
- "@meowdown/vitest": "0.0.0"
65
+ "vitest": "^5.0.1"
67
66
  },
68
67
  "publishConfig": {
69
68
  "access": "public"