rme 0.3.0-beta.31 → 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,28 +564,32 @@ 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;
568
567
 
569
568
  /*
570
- Reset the counter for the first list node in the sequence.
569
+ If the node has a custom order number, set the counter to that value.
570
+ Otherwise, increment the counter normally.
571
571
  */
572
- &:first-child,
573
- :not(&) + & {
574
- 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
- }
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
+ }
583
576
 
584
- @supports not (counter-set: prosemirror-flat-list-counter 1) {
585
- counter-increment: prosemirror-flat-list-counter var(--prosemirror-flat-list-order);
586
- }
577
+ @supports not (counter-set: prosemirror-flat-list-counter 1) {
578
+ counter-reset: prosemirror-flat-list-counter var(--prosemirror-flat-list-order);
587
579
  }
588
580
  }
581
+
582
+ &:not([data-list-order]) {
583
+ counter-increment: prosemirror-flat-list-counter;
584
+ }
585
+
586
+ /*
587
+ Reset the counter for the first list node in the sequence or when
588
+ the previous sibling is not a list (paragraph break).
589
+ */
590
+ &:first-child {
591
+ counter-reset: prosemirror-flat-list-counter;
592
+ }
589
593
  }
590
594
 
591
595
  &[data-list-kind='task'] {
@@ -620,6 +624,24 @@ var FlatListStyles = css`
620
624
  }
621
625
  }
622
626
  }
627
+
628
+ /*
629
+ Reset counter when an ordered list follows a non-list element.
630
+ This handles the case where there's a paragraph break (e.g., h3) between lists.
631
+ */
632
+ :not(.prosemirror-flat-list[data-list-kind='ordered']) + .prosemirror-flat-list[data-list-kind='ordered'] {
633
+ counter-reset: prosemirror-flat-list-counter;
634
+
635
+ &[data-list-order] {
636
+ @supports (counter-set: prosemirror-flat-list-counter 1) {
637
+ counter-set: prosemirror-flat-list-counter var(--prosemirror-flat-list-order);
638
+ }
639
+
640
+ @supports not (counter-set: prosemirror-flat-list-counter 1) {
641
+ counter-increment: prosemirror-flat-list-counter var(--prosemirror-flat-list-order);
642
+ }
643
+ }
644
+ }
623
645
  `;
624
646
 
625
647
  // src/editor/theme/WysiwygThemeWrapper.tsx
@@ -2477,7 +2499,20 @@ var rule = (state) => {
2477
2499
  const tokens = state.tokens;
2478
2500
  const tokensLength = tokens.length;
2479
2501
  for (let i = tokensLength - 3; i >= 0; i--) {
2480
- 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])) {
2481
2516
  const inlineToken = tokens[i + 2];
2482
2517
  const match = /^\[([ |x])\]\s?/.exec(inlineToken.content);
2483
2518
  if (match) {
@@ -3157,6 +3192,7 @@ var MarkdownParseState = class {
3157
3192
  this.schema = schema;
3158
3193
  this.stack = [{ type: schema.topNodeType, content: [] }];
3159
3194
  this.contextStack = [];
3195
+ this.contextTokenStack = [];
3160
3196
  this.marks = Mark.none;
3161
3197
  this.tokenHandlers = tokenHandlers;
3162
3198
  }
@@ -3226,15 +3262,23 @@ var MarkdownParseState = class {
3226
3262
  }
3227
3263
  return this.addNode(info.type, info.attrs, info.content);
3228
3264
  }
3229
- openContext(context) {
3265
+ openContext(context, token) {
3230
3266
  this.contextStack.push(context);
3267
+ this.contextTokenStack.push(token);
3231
3268
  }
3232
3269
  closeContext() {
3233
3270
  this.contextStack.pop();
3271
+ this.contextTokenStack.pop();
3272
+ }
3273
+ closeContextToken() {
3274
+ return this.contextTokenStack.pop();
3234
3275
  }
3235
3276
  topContext() {
3236
3277
  return this.contextStack[this.contextStack.length - 1];
3237
3278
  }
3279
+ topContextToken() {
3280
+ return this.contextTokenStack[this.contextTokenStack.length - 1];
3281
+ }
3238
3282
  };
3239
3283
  function withoutTrailingNewline(str) {
3240
3284
  return str.endsWith("\n") ? str.slice(0, str.length - 1) : str;
@@ -3262,8 +3306,8 @@ function buildBlockTokenHandler(parserRule, handlers, schema) {
3262
3306
  }
3263
3307
  }
3264
3308
  function buildContextTokenHandler(parserRule, handlers) {
3265
- handlers[parserRule.token + "_open"] = (state) => {
3266
- state.openContext(parserRule.context);
3309
+ handlers[parserRule.token + "_open"] = (state, tok) => {
3310
+ state.openContext(parserRule.context, tok);
3267
3311
  };
3268
3312
  handlers[parserRule.token + "_close"] = (state) => {
3269
3313
  state.closeContext();
@@ -9620,10 +9664,26 @@ var LineListExtension = class extends NodeExtension8 {
9620
9664
  {
9621
9665
  type: 4 /* free */,
9622
9666
  token: "list_item_open",
9623
- handler: (state) => {
9667
+ handler: (state, token) => {
9624
9668
  switch (state.topContext()) {
9625
9669
  case "ordered_list":
9626
- 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
+ });
9627
9687
  break;
9628
9688
  case "bullet_list":
9629
9689
  state.openNode(this.type, { kind: "bullet" });
@@ -9670,7 +9730,8 @@ var LineListExtension = class extends NodeExtension8 {
9670
9730
  const attrs = node.attrs;
9671
9731
  let firstDelim = "";
9672
9732
  if (attrs.kind === "ordered") {
9673
- firstDelim = `${counter}. `;
9733
+ const order = attrs.order != null ? attrs.order : counter;
9734
+ firstDelim = `${order}. `;
9674
9735
  } else if (attrs.kind === "task") {
9675
9736
  firstDelim = attrs.checked ? "- [x] " : "- [ ] ";
9676
9737
  } else if (attrs.kind === "bullet") {
@@ -11003,7 +11064,6 @@ var ReferenceDefinitionExtension = class extends NodeExtension12 {
11003
11064
  token: "reference_def",
11004
11065
  hasOpenClose: true,
11005
11066
  getAttrs: (token) => {
11006
- console.log("token11", token);
11007
11067
  return {
11008
11068
  label: token.attrs?.[0]?.[1] || "",
11009
11069
  href: token.attrs?.[1]?.[1] || "",
@@ -11618,7 +11678,16 @@ var MarkdownSerializerState = class {
11618
11678
  if (parent.forEach) {
11619
11679
  parent.forEach((node, offset, index) => {
11620
11680
  if (isOrderedListNode(node)) {
11621
- 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
+ }
11622
11691
  } else {
11623
11692
  counter = 0;
11624
11693
  }
@@ -11626,7 +11695,12 @@ var MarkdownSerializerState = class {
11626
11695
  });
11627
11696
  } else {
11628
11697
  if (isOrderedListNode(parent)) {
11629
- counter += 1;
11698
+ const attrs = parent.attrs;
11699
+ if (attrs.order != null) {
11700
+ counter = attrs.order;
11701
+ } else {
11702
+ counter += 1;
11703
+ }
11630
11704
  } else {
11631
11705
  counter = 0;
11632
11706
  }