@prosekit/core 0.7.5 → 0.7.7

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.
@@ -15,6 +15,7 @@ import {
15
15
  htmlFromJSON,
16
16
  htmlFromNode,
17
17
  isAllSelection,
18
+ isElement,
18
19
  isMark,
19
20
  isMarkAbsent,
20
21
  isMarkActive,
@@ -22,6 +23,7 @@ import {
22
23
  isNodeSelection,
23
24
  isNotNull,
24
25
  isProseMirrorNode,
26
+ isSelection,
25
27
  isTextSelection,
26
28
  jsonFromHTML,
27
29
  jsonFromNode,
@@ -35,7 +37,7 @@ import {
35
37
  stateFromJSON,
36
38
  toReversed,
37
39
  union
38
- } from "./chunk-M267LRMB.js";
40
+ } from "./chunk-MDJ2B4IL.js";
39
41
 
40
42
  // src/commands/add-mark.ts
41
43
  import "@prosekit/pm/model";
@@ -453,11 +455,7 @@ function withPriority(extension, priority) {
453
455
  }
454
456
 
455
457
  // src/commands/insert-text.ts
456
- function insertText({
457
- text,
458
- from,
459
- to
460
- }) {
458
+ function insertText({ text, from, to }) {
461
459
  return (state, dispatch) => {
462
460
  if (text) {
463
461
  dispatch == null ? void 0 : dispatch(state.tr.insertText(text, from, to));
@@ -528,12 +526,6 @@ var schemaSpecFacet = defineFacet({
528
526
  singleton: true
529
527
  });
530
528
 
531
- // src/utils/is-element.ts
532
- var hasElement = typeof Element !== "undefined";
533
- function isElement(value) {
534
- return hasElement && value instanceof Element;
535
- }
536
-
537
529
  // src/extensions/node-spec.ts
538
530
  function defineNodeSpec(options) {
539
531
  const payload = [options, void 0];
@@ -545,16 +537,16 @@ function defineNodeAttr(options) {
545
537
  }
546
538
  var nodeSpecFacet = defineFacet({
547
539
  reducer: (payloads) => {
548
- let nodes = OrderedMap2.from({});
540
+ let specs = OrderedMap2.from({});
549
541
  let topNodeName = void 0;
550
542
  const specPayloads = payloads.map((input) => input[0]).filter(isNotNull);
551
543
  const attrPayloads = payloads.map((input) => input[1]).filter(isNotNull);
552
544
  for (const { name, topNode, ...spec } of specPayloads) {
553
- assert(!nodes.get(name), `Node type ${name} can only be defined once`);
545
+ assert(!specs.get(name), `Node type ${name} can only be defined once`);
554
546
  if (topNode) {
555
547
  topNodeName = name;
556
548
  }
557
- nodes = nodes.addToStart(name, spec);
549
+ specs = specs.addToStart(name, spec);
558
550
  }
559
551
  for (const {
560
552
  type,
@@ -564,7 +556,7 @@ var nodeSpecFacet = defineFacet({
564
556
  toDOM,
565
557
  parseDOM
566
558
  } of attrPayloads) {
567
- const spec = nodes.get(type);
559
+ const spec = specs.get(type);
568
560
  assert(spec, `Node type ${type} must be defined`);
569
561
  if (!spec.attrs) {
570
562
  spec.attrs = {};
@@ -629,7 +621,7 @@ var nodeSpecFacet = defineFacet({
629
621
  }
630
622
  }
631
623
  }
632
- return { nodes, topNode: topNodeName };
624
+ return { nodes: specs, topNode: topNodeName };
633
625
  },
634
626
  parent: schemaSpecFacet,
635
627
  singleton: true
@@ -663,17 +655,17 @@ import { PluginKey, ProseMirrorPlugin as ProseMirrorPlugin2 } from "@prosekit/pm
663
655
  import "@prosekit/pm/model";
664
656
  import { Plugin } from "@prosekit/pm/state";
665
657
  function definePlugin(plugin) {
666
- if (plugin instanceof Plugin) {
667
- return defineFacetPayload(pluginFacet, [() => [plugin]]);
668
- }
669
- if (Array.isArray(plugin) && plugin.every((p) => p instanceof Plugin)) {
670
- return defineFacetPayload(pluginFacet, [() => plugin]);
658
+ if (plugin instanceof Plugin || Array.isArray(plugin) && plugin.every((p) => p instanceof Plugin)) {
659
+ return definePluginPayload(() => plugin);
671
660
  }
672
661
  if (typeof plugin === "function") {
673
- return defineFacetPayload(pluginFacet, [plugin]);
662
+ return definePluginPayload(plugin);
674
663
  }
675
664
  throw new TypeError("Invalid plugin");
676
665
  }
666
+ function definePluginPayload(payload) {
667
+ return defineFacetPayload(pluginFacet, [payload]);
668
+ }
677
669
  var pluginFacet = defineFacet({
678
670
  reducer: (payloads) => {
679
671
  return ({ schema }) => {
@@ -698,13 +690,16 @@ var pluginFacet = defineFacet({
698
690
 
699
691
  // src/extensions/events/plugin-view.ts
700
692
  function defineMountHandler(handler) {
701
- return defineFacetPayload(pluginViewFacet, [["mount", handler]]);
693
+ return definePluginViewFacetPayload(["mount", handler]);
702
694
  }
703
695
  function defineUpdateHandler(handler) {
704
- return defineFacetPayload(pluginViewFacet, [["update", handler]]);
696
+ return definePluginViewFacetPayload(["update", handler]);
705
697
  }
706
698
  function defineUnmountHandler(handler) {
707
- return defineFacetPayload(pluginViewFacet, [["unmount", handler]]);
699
+ return definePluginViewFacetPayload(["unmount", handler]);
700
+ }
701
+ function definePluginViewFacetPayload(input) {
702
+ return defineFacetPayload(pluginViewFacet, [input]);
708
703
  }
709
704
  var pluginViewFacet = defineFacet({
710
705
  reduce: () => {
@@ -960,6 +955,7 @@ var isApple = typeof navigator !== "undefined" ? /Mac|iP(hone|[ao]d)/.test(navig
960
955
  import { chainCommands } from "@prosekit/pm/commands";
961
956
  import { keydownHandler } from "@prosekit/pm/keymap";
962
957
  import { Plugin as Plugin2, PluginKey as PluginKey4 } from "@prosekit/pm/state";
958
+ import mapValues from "just-map-values";
963
959
  function defineKeymap(keymap2) {
964
960
  return defineFacetPayload(keymapFacet, [keymap2]);
965
961
  }
@@ -995,12 +991,10 @@ function mergeKeymaps(keymaps) {
995
991
  commands2.push(command);
996
992
  }
997
993
  }
998
- return Object.fromEntries(
999
- Object.entries(bindings).map(([key, commands2]) => [
1000
- key,
1001
- chainCommands(...commands2)
1002
- ])
1003
- );
994
+ return mapValues(bindings, mergeCommands);
995
+ }
996
+ function mergeCommands(commands2) {
997
+ return chainCommands(...commands2);
1004
998
  }
1005
999
  var keymapPluginKey = new PluginKey4("prosekit-keymap");
1006
1000
 
@@ -1058,10 +1052,14 @@ var customBaseKeymap = {
1058
1052
  function defineBaseKeymap(options) {
1059
1053
  var _a;
1060
1054
  const priority = (_a = options == null ? void 0 : options.priority) != null ? _a : 1 /* low */;
1061
- return withPriority(defineKeymap(customBaseKeymap), priority);
1055
+ return withPriority(
1056
+ defineKeymap(customBaseKeymap),
1057
+ priority
1058
+ );
1062
1059
  }
1063
1060
 
1064
1061
  // src/extensions/mark-spec.ts
1062
+ import OrderedMap3 from "orderedmap";
1065
1063
  function defineMarkSpec(options) {
1066
1064
  const payload = [options, void 0];
1067
1065
  return defineFacetPayload(markSpecFacet, [payload]);
@@ -1072,14 +1070,12 @@ function defineMarkAttr(options) {
1072
1070
  }
1073
1071
  var markSpecFacet = defineFacet({
1074
1072
  reducer: (payloads) => {
1075
- const marks = {};
1073
+ let specs = OrderedMap3.from({});
1076
1074
  const specPayloads = payloads.map((input) => input[0]).filter(isNotNull);
1077
1075
  const attrPayloads = payloads.map((input) => input[1]).filter(isNotNull);
1078
1076
  for (const { name, ...spec } of specPayloads) {
1079
- if (marks[name]) {
1080
- throw new ProseKitError(`Mark type ${name} has already been defined`);
1081
- }
1082
- marks[name] = spec;
1077
+ assert(!specs.get(name), `Mark type ${name} can only be defined once`);
1078
+ specs = specs.addToStart(name, spec);
1083
1079
  }
1084
1080
  for (const {
1085
1081
  type,
@@ -1088,12 +1084,8 @@ var markSpecFacet = defineFacet({
1088
1084
  toDOM,
1089
1085
  parseDOM
1090
1086
  } of attrPayloads) {
1091
- const spec = marks[type];
1092
- if (!spec) {
1093
- throw new ProseKitError(
1094
- `Mark type ${type} must be defined before defining attributes`
1095
- );
1096
- }
1087
+ const spec = specs.get(type);
1088
+ assert(spec, `Mark type ${type} must be defined`);
1097
1089
  if (!spec.attrs) {
1098
1090
  spec.attrs = {};
1099
1091
  }
@@ -1146,7 +1138,7 @@ var markSpecFacet = defineFacet({
1146
1138
  }
1147
1139
  }
1148
1140
  }
1149
- return { marks, nodes: {} };
1141
+ return { marks: specs, nodes: {} };
1150
1142
  },
1151
1143
  parent: schemaSpecFacet,
1152
1144
  singleton: true
@@ -1402,6 +1394,7 @@ export {
1402
1394
  isMarkActive,
1403
1395
  isNodeSelection,
1404
1396
  isProseMirrorNode,
1397
+ isSelection,
1405
1398
  isTextSelection,
1406
1399
  jsonFromHTML,
1407
1400
  jsonFromNode,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/core",
3
3
  "type": "module",
4
- "version": "0.7.5",
4
+ "version": "0.7.7",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -41,15 +41,16 @@
41
41
  ],
42
42
  "dependencies": {
43
43
  "clsx": "^2.1.1",
44
+ "just-map-values": "^3.2.0",
44
45
  "orderedmap": "^2.1.1",
45
46
  "prosemirror-splittable": "^0.1.1",
46
- "type-fest": "^4.22.1",
47
+ "type-fest": "^4.23.0",
47
48
  "@prosekit/pm": "^0.1.7"
48
49
  },
49
50
  "devDependencies": {
50
- "tsup": "^8.1.2",
51
+ "tsup": "^8.2.2",
51
52
  "typescript": "^5.5.3",
52
- "vitest": "^2.0.3",
53
+ "vitest": "^2.0.4",
53
54
  "@prosekit/dev": "0.0.0"
54
55
  },
55
56
  "scripts": {