rme 0.3.0-beta.32 → 0.3.0-beta.33

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
@@ -382,6 +382,7 @@ declare class MarkdownParseState {
382
382
  private marks;
383
383
  private tokenHandlers;
384
384
  private contextStack;
385
+ private contextTokenStack;
385
386
  stack: StackItem[];
386
387
  constructor(schema: Schema, tokenHandlers: TokenHandlers);
387
388
  top(): StackItem;
@@ -394,9 +395,11 @@ declare class MarkdownParseState {
394
395
  addNode(type: NodeType, attrs?: Record<string, any>, content?: Node[]): Node;
395
396
  openNode(type: NodeType, attrs?: Record<string, any>): void;
396
397
  closeNode(): Node;
397
- openContext(context: ParserRuleContext): void;
398
+ openContext(context: ParserRuleContext, token: Token$1): void;
398
399
  closeContext(): void;
400
+ closeContextToken(): Token$1 | undefined;
399
401
  topContext(): ParserRuleContext | undefined;
402
+ topContextToken(): Token$1 | undefined;
400
403
  }
401
404
  declare class MarkdownParser {
402
405
  private schema;
@@ -676,7 +679,7 @@ declare class LineListExtension extends NodeExtension {
676
679
  fromMarkdown(): readonly [{
677
680
  readonly type: ParserRuleType.free;
678
681
  readonly token: "list_item_open";
679
- readonly handler: (state: MarkdownParseState) => void;
682
+ readonly handler: (state: MarkdownParseState, token: Token) => void;
680
683
  }, {
681
684
  readonly type: ParserRuleType.free;
682
685
  readonly token: "list_checkbox";
package/dist/index.mjs CHANGED
@@ -564,7 +564,24 @@ var FlatListStyles = css`
564
564
  content: counter(prosemirror-flat-list-counter, decimal) '. ';
565
565
  font-variant-numeric: tabular-nums;
566
566
  }
567
- counter-increment: prosemirror-flat-list-counter;
567
+
568
+ /*
569
+ If the node has a custom order number, set the counter to that value.
570
+ Otherwise, increment the counter normally.
571
+ */
572
+ &[data-list-order] {
573
+ @supports (counter-set: prosemirror-flat-list-counter 1) {
574
+ counter-set: prosemirror-flat-list-counter var(--prosemirror-flat-list-order);
575
+ }
576
+
577
+ @supports not (counter-set: prosemirror-flat-list-counter 1) {
578
+ counter-reset: prosemirror-flat-list-counter var(--prosemirror-flat-list-order);
579
+ }
580
+ }
581
+
582
+ &:not([data-list-order]) {
583
+ counter-increment: prosemirror-flat-list-counter;
584
+ }
568
585
 
569
586
  /*
570
587
  Reset the counter for the first list node in the sequence or when
@@ -572,19 +589,6 @@ var FlatListStyles = css`
572
589
  */
573
590
  &:first-child {
574
591
  counter-reset: prosemirror-flat-list-counter;
575
-
576
- /*
577
- If the first list node has a custom order number, set the counter to that value.
578
- */
579
- &[data-list-order] {
580
- @supports (counter-set: prosemirror-flat-list-counter 1) {
581
- counter-set: prosemirror-flat-list-counter var(--prosemirror-flat-list-order);
582
- }
583
-
584
- @supports not (counter-set: prosemirror-flat-list-counter 1) {
585
- counter-increment: prosemirror-flat-list-counter var(--prosemirror-flat-list-order);
586
- }
587
- }
588
592
  }
589
593
  }
590
594
 
@@ -625,7 +629,7 @@ var FlatListStyles = css`
625
629
  Reset counter when an ordered list follows a non-list element.
626
630
  This handles the case where there's a paragraph break (e.g., h3) between lists.
627
631
  */
628
- :not(.prosemirror-flat-list) + .prosemirror-flat-list[data-list-kind='ordered'] {
632
+ :not(.prosemirror-flat-list[data-list-kind='ordered']) + .prosemirror-flat-list[data-list-kind='ordered'] {
629
633
  counter-reset: prosemirror-flat-list-counter;
630
634
 
631
635
  &[data-list-order] {
@@ -2495,7 +2499,20 @@ var rule = (state) => {
2495
2499
  const tokens = state.tokens;
2496
2500
  const tokensLength = tokens.length;
2497
2501
  for (let i = tokensLength - 3; i >= 0; i--) {
2498
- if (isBulletListItemToken(tokens[i]) && isParagraphOpenToken(tokens[i + 1]) && isInlineToken(tokens[i + 2])) {
2502
+ const curToken = tokens[i];
2503
+ if (curToken.type === "ordered_list_open") {
2504
+ curToken.attrs?.some(([name, value]) => {
2505
+ if (name === "start") {
2506
+ const startNum = parseInt(value, 10);
2507
+ if (!isNaN(startNum) && startNum >= 1) {
2508
+ curToken.attrPush(["order", value]);
2509
+ }
2510
+ return true;
2511
+ }
2512
+ return false;
2513
+ });
2514
+ }
2515
+ if (isBulletListItemToken(curToken) && isParagraphOpenToken(tokens[i + 1]) && isInlineToken(tokens[i + 2])) {
2499
2516
  const inlineToken = tokens[i + 2];
2500
2517
  const match = /^\[([ |x])\]\s?/.exec(inlineToken.content);
2501
2518
  if (match) {
@@ -3175,6 +3192,7 @@ var MarkdownParseState = class {
3175
3192
  this.schema = schema;
3176
3193
  this.stack = [{ type: schema.topNodeType, content: [] }];
3177
3194
  this.contextStack = [];
3195
+ this.contextTokenStack = [];
3178
3196
  this.marks = Mark.none;
3179
3197
  this.tokenHandlers = tokenHandlers;
3180
3198
  }
@@ -3244,15 +3262,23 @@ var MarkdownParseState = class {
3244
3262
  }
3245
3263
  return this.addNode(info.type, info.attrs, info.content);
3246
3264
  }
3247
- openContext(context) {
3265
+ openContext(context, token) {
3248
3266
  this.contextStack.push(context);
3267
+ this.contextTokenStack.push(token);
3249
3268
  }
3250
3269
  closeContext() {
3251
3270
  this.contextStack.pop();
3271
+ this.contextTokenStack.pop();
3272
+ }
3273
+ closeContextToken() {
3274
+ return this.contextTokenStack.pop();
3252
3275
  }
3253
3276
  topContext() {
3254
3277
  return this.contextStack[this.contextStack.length - 1];
3255
3278
  }
3279
+ topContextToken() {
3280
+ return this.contextTokenStack[this.contextTokenStack.length - 1];
3281
+ }
3256
3282
  };
3257
3283
  function withoutTrailingNewline(str) {
3258
3284
  return str.endsWith("\n") ? str.slice(0, str.length - 1) : str;
@@ -3280,8 +3306,8 @@ function buildBlockTokenHandler(parserRule, handlers, schema) {
3280
3306
  }
3281
3307
  }
3282
3308
  function buildContextTokenHandler(parserRule, handlers) {
3283
- handlers[parserRule.token + "_open"] = (state) => {
3284
- state.openContext(parserRule.context);
3309
+ handlers[parserRule.token + "_open"] = (state, tok) => {
3310
+ state.openContext(parserRule.context, tok);
3285
3311
  };
3286
3312
  handlers[parserRule.token + "_close"] = (state) => {
3287
3313
  state.closeContext();
@@ -9638,10 +9664,26 @@ var LineListExtension = class extends NodeExtension8 {
9638
9664
  {
9639
9665
  type: 4 /* free */,
9640
9666
  token: "list_item_open",
9641
- handler: (state) => {
9667
+ handler: (state, token) => {
9642
9668
  switch (state.topContext()) {
9643
9669
  case "ordered_list":
9644
- state.openNode(this.type, { kind: "ordered" });
9670
+ const token2 = state.topContextToken();
9671
+ state.closeContext;
9672
+ let startOrder;
9673
+ if (token2?.type === "ordered_list_open") {
9674
+ token2?.attrs?.some(([name, value]) => {
9675
+ if (name === "order") {
9676
+ startOrder = parseInt(value, 10);
9677
+ state.closeContextToken();
9678
+ return true;
9679
+ }
9680
+ return false;
9681
+ });
9682
+ }
9683
+ state.openNode(this.type, {
9684
+ kind: "ordered",
9685
+ order: startOrder
9686
+ });
9645
9687
  break;
9646
9688
  case "bullet_list":
9647
9689
  state.openNode(this.type, { kind: "bullet" });
@@ -9688,7 +9730,8 @@ var LineListExtension = class extends NodeExtension8 {
9688
9730
  const attrs = node.attrs;
9689
9731
  let firstDelim = "";
9690
9732
  if (attrs.kind === "ordered") {
9691
- firstDelim = `${counter}. `;
9733
+ const order = attrs.order != null ? attrs.order : counter;
9734
+ firstDelim = `${order}. `;
9692
9735
  } else if (attrs.kind === "task") {
9693
9736
  firstDelim = attrs.checked ? "- [x] " : "- [ ] ";
9694
9737
  } else if (attrs.kind === "bullet") {
@@ -11021,7 +11064,6 @@ var ReferenceDefinitionExtension = class extends NodeExtension12 {
11021
11064
  token: "reference_def",
11022
11065
  hasOpenClose: true,
11023
11066
  getAttrs: (token) => {
11024
- console.log("token11", token);
11025
11067
  return {
11026
11068
  label: token.attrs?.[0]?.[1] || "",
11027
11069
  href: token.attrs?.[1]?.[1] || "",
@@ -11636,7 +11678,16 @@ var MarkdownSerializerState = class {
11636
11678
  if (parent.forEach) {
11637
11679
  parent.forEach((node, offset, index) => {
11638
11680
  if (isOrderedListNode(node)) {
11639
- counter += 1;
11681
+ const prevSibling = index > 0 ? parent.child(index - 1) : null;
11682
+ if (prevSibling && !isOrderedListNode(prevSibling)) {
11683
+ counter = 0;
11684
+ }
11685
+ const attrs = node.attrs;
11686
+ if (attrs.order != null) {
11687
+ counter = attrs.order;
11688
+ } else {
11689
+ counter += 1;
11690
+ }
11640
11691
  } else {
11641
11692
  counter = 0;
11642
11693
  }
@@ -11644,7 +11695,12 @@ var MarkdownSerializerState = class {
11644
11695
  });
11645
11696
  } else {
11646
11697
  if (isOrderedListNode(parent)) {
11647
- counter += 1;
11698
+ const attrs = parent.attrs;
11699
+ if (attrs.order != null) {
11700
+ counter = attrs.order;
11701
+ } else {
11702
+ counter += 1;
11703
+ }
11648
11704
  } else {
11649
11705
  counter = 0;
11650
11706
  }