@prosekit/core 0.7.4 → 0.7.5

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.
@@ -272,6 +272,13 @@ declare interface CommandTyping {
272
272
  export { CommandTyping }
273
273
  export { CommandTyping as CommandTyping_alias_1 }
274
274
 
275
+ /**
276
+ * @internal
277
+ */
278
+ declare function containsInlineNode(doc: ProseMirrorNode, from: number, to: number): boolean;
279
+ export { containsInlineNode }
280
+ export { containsInlineNode as containsInlineNode_alias_1 }
281
+
275
282
  /**
276
283
  * @public
277
284
  */
@@ -709,6 +716,9 @@ export declare function defineTestExtension(): Extension<{
709
716
  doc: Attrs_2;
710
717
  text: Attrs_2;
711
718
  heading: Attrs_2;
719
+ codeBlock: {
720
+ language: string;
721
+ };
712
722
  }>;
713
723
  Marks: SimplifyDeeper< {
714
724
  bold: Attrs_2;
@@ -1346,6 +1356,8 @@ declare function htmlFromNode(node: ProseMirrorNode, options?: DOMSerializerOpti
1346
1356
  export { htmlFromNode }
1347
1357
  export { htmlFromNode as htmlFromNode_alias_1 }
1348
1358
 
1359
+ export declare function includesMark(marks: readonly Mark[], markType: MarkType, attrs?: Attrs | null): boolean;
1360
+
1349
1361
  /**
1350
1362
  * Returns a command that inserts the given node at the current selection or at
1351
1363
  * the given position.
@@ -1441,6 +1453,7 @@ export { isMark as isMark_alias_1 }
1441
1453
  /**
1442
1454
  * Returns true if the given mark is missing in some part of the range.
1443
1455
  * Returns false if the entire range has the given mark.
1456
+ * Returns true if the mark is not allowed in the range.
1444
1457
  *
1445
1458
  * @internal
1446
1459
  */
@@ -1473,6 +1486,13 @@ declare function isProseMirrorNode(node: unknown): node is ProseMirrorNode;
1473
1486
  export { isProseMirrorNode }
1474
1487
  export { isProseMirrorNode as isProseMirrorNode_alias_1 }
1475
1488
 
1489
+ /**
1490
+ * Check if `subset` is a subset of `superset`.
1491
+ *
1492
+ * @internal
1493
+ */
1494
+ export declare function isSubset(subset: Record<string, unknown>, superset: Record<string, unknown>): boolean;
1495
+
1476
1496
  /**
1477
1497
  * @internal
1478
1498
  */
@@ -2098,6 +2118,9 @@ export declare function setupTest(): {
2098
2118
  doc: Attrs_2;
2099
2119
  text: Attrs_2;
2100
2120
  heading: Attrs_2;
2121
+ codeBlock: {
2122
+ language: string;
2123
+ };
2101
2124
  }>;
2102
2125
  Marks: SimplifyDeeper< {
2103
2126
  bold: Attrs_2;
@@ -2123,20 +2146,6 @@ export declare function setupTest(): {
2123
2146
  readonly redo: [];
2124
2147
  };
2125
2148
  }>>;
2126
- n: ToNodeAction<SimplifyDeeper< {
2127
- paragraph: {
2128
- readonly [x: string]: any;
2129
- };
2130
- doc: {
2131
- readonly [x: string]: any;
2132
- };
2133
- text: {
2134
- readonly [x: string]: any;
2135
- };
2136
- heading: {
2137
- readonly [x: string]: any;
2138
- };
2139
- }>>;
2140
2149
  m: ToMarkAction<SimplifyDeeper< {
2141
2150
  bold: {
2142
2151
  readonly [x: string]: any;
@@ -2145,6 +2154,26 @@ export declare function setupTest(): {
2145
2154
  readonly [x: string]: any;
2146
2155
  };
2147
2156
  }>>;
2157
+ n: {
2158
+ p: NodeAction< {
2159
+ readonly [x: string]: any;
2160
+ }>;
2161
+ paragraph: NodeAction< {
2162
+ readonly [x: string]: any;
2163
+ }>;
2164
+ doc: NodeAction< {
2165
+ readonly [x: string]: any;
2166
+ }>;
2167
+ text: NodeAction< {
2168
+ readonly [x: string]: any;
2169
+ }>;
2170
+ heading: NodeAction< {
2171
+ readonly [x: string]: any;
2172
+ }>;
2173
+ codeBlock: NodeAction< {
2174
+ language: string;
2175
+ }>;
2176
+ };
2148
2177
  };
2149
2178
 
2150
2179
  /**
@@ -512,15 +512,36 @@ function defineDefaultState({
512
512
  ]);
513
513
  }
514
514
 
515
+ // src/utils/is-subset.ts
516
+ function isSubset(subset, superset) {
517
+ return Object.keys(subset).every((key) => subset[key] === superset[key]);
518
+ }
519
+
520
+ // src/utils/includes-mark.ts
521
+ function includesMark(marks, markType, attrs) {
522
+ attrs = attrs || {};
523
+ return marks.some((mark) => {
524
+ return mark.type === markType && isSubset(attrs, mark.attrs);
525
+ });
526
+ }
527
+
515
528
  // src/utils/is-mark-absent.ts
516
529
  function isMarkAbsent(node, from, to, markType, attrs) {
517
- const mark = attrs ? markType.create(attrs) : markType;
518
530
  let missing = false;
531
+ let available = false;
519
532
  node.nodesBetween(from, to, (node2, pos, parent) => {
520
- if (missing) return false;
521
- missing = !mark.isInSet(node2.marks) && !!parent && parent.type.allowsMarkType(markType);
533
+ if (missing) {
534
+ return false;
535
+ }
536
+ const allowed = (parent == null ? void 0 : parent.type.allowsMarkType(markType)) && !node2.marks.some((m) => m.type !== markType && m.type.excludes(markType));
537
+ if (allowed) {
538
+ available = true;
539
+ if (!includesMark(node2.marks, markType, attrs)) {
540
+ missing = true;
541
+ }
542
+ }
522
543
  });
523
- return missing;
544
+ return available ? missing : true;
524
545
  }
525
546
 
526
547
  // src/utils/is-mark-active.ts
@@ -528,8 +549,8 @@ function isMarkActive(state, type, attrs) {
528
549
  const { from, $from, to, empty } = state.selection;
529
550
  const markType = getMarkType(state.schema, type);
530
551
  if (empty) {
531
- const mark = attrs ? markType.create(attrs) : markType;
532
- return !!mark.isInSet(state.storedMarks || $from.marks());
552
+ const marks = state.storedMarks || $from.marks();
553
+ return includesMark(marks, markType, attrs);
533
554
  } else {
534
555
  return !isMarkAbsent(state.doc, from, to, markType, attrs);
535
556
  }
@@ -5,7 +5,7 @@ import {
5
5
  createMarkActions,
6
6
  createNodeActions,
7
7
  setupEditorExtension
8
- } from "./chunk-52BNHWWJ.js";
8
+ } from "./chunk-M267LRMB.js";
9
9
 
10
10
  // src/test/test-editor.ts
11
11
  import { EditorState, NodeSelection, TextSelection } from "@prosekit/pm/state";
@@ -136,6 +136,7 @@ export { canUseRegexLookbehind } from './_tsup-dts-rollup';
136
136
  export { clsx } from './_tsup-dts-rollup';
137
137
  export { collectNodes } from './_tsup-dts-rollup';
138
138
  export { NodeContent } from './_tsup-dts-rollup';
139
+ export { containsInlineNode } from './_tsup-dts-rollup';
139
140
  export { defaultBlockAt } from './_tsup-dts-rollup';
140
141
  export { isApple } from './_tsup-dts-rollup';
141
142
  export { _getId } from './_tsup-dts-rollup';
@@ -35,7 +35,7 @@ import {
35
35
  stateFromJSON,
36
36
  toReversed,
37
37
  union
38
- } from "./chunk-52BNHWWJ.js";
38
+ } from "./chunk-M267LRMB.js";
39
39
 
40
40
  // src/commands/add-mark.ts
41
41
  import "@prosekit/pm/model";
@@ -1274,6 +1274,16 @@ function collectNodes(content) {
1274
1274
  throw new ProseKitError(`Invalid node content: ${typeof content}`);
1275
1275
  }
1276
1276
 
1277
+ // src/utils/contains-inline-node.ts
1278
+ function containsInlineNode(doc, from, to) {
1279
+ let found = false;
1280
+ doc.nodesBetween(from, to, (node) => {
1281
+ if (found) return false;
1282
+ if (node.isInline) found = true;
1283
+ });
1284
+ return found;
1285
+ }
1286
+
1277
1287
  // src/utils/default-block-at.ts
1278
1288
  function defaultBlockAt(match) {
1279
1289
  for (let i = 0; i < match.edgeCount; i++) {
@@ -1335,6 +1345,7 @@ export {
1335
1345
  canUseRegexLookbehind,
1336
1346
  clsx,
1337
1347
  collectNodes,
1348
+ containsInlineNode,
1338
1349
  createEditor,
1339
1350
  defaultBlockAt,
1340
1351
  defineBaseCommands,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/core",
3
3
  "type": "module",
4
- "version": "0.7.4",
4
+ "version": "0.7.5",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -44,7 +44,7 @@
44
44
  "orderedmap": "^2.1.1",
45
45
  "prosemirror-splittable": "^0.1.1",
46
46
  "type-fest": "^4.22.1",
47
- "@prosekit/pm": "^0.1.6"
47
+ "@prosekit/pm": "^0.1.7"
48
48
  },
49
49
  "devDependencies": {
50
50
  "tsup": "^8.1.2",