Skip to content

Commit

Permalink
fix: only apply custom counter number for the first list node (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocavue authored Nov 21, 2023
1 parent 3f3df5d commit 7d227f8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-parrots-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'prosemirror-flat-list': patch
---

Only allow the first ordered list node in the sequence to have a custom counter number.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

- name: Emit .d.ts files
run: nr --filter prosemirror-flat-list build

- name: Lint
run: nr lint

Expand Down
6 changes: 1 addition & 5 deletions packages/core/src/schema/to-dom.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { DOMOutputSpec, Node as ProsemirrorNode } from 'prosemirror-model'

import { ListAttributes } from '../types'
import * as browser from '../utils/browser'

/** @public */
export interface ListToDOMOptions {
Expand Down Expand Up @@ -112,10 +111,7 @@ export function defaultAttributesGetter(node: ProsemirrorNode) {
'data-list-collapsable': node.childCount >= 2 ? '' : undefined,
style:
attrs.order != null
? // Safari (at least version <= 16.5) doesn't support `counter-set`
browser.safari
? `counter-reset: prosemirror-flat-list-counter; counter-increment: prosemirror-flat-list-counter ${attrs.order};`
: `counter-set: prosemirror-flat-list-counter ${attrs.order};`
? `--prosemirror-flat-list-order: ${attrs.order};`
: undefined,
}

Expand Down
21 changes: 20 additions & 1 deletion packages/core/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,29 @@
counter-increment: prosemirror-flat-list-counter;

/*
Reset the counter for the first child of the list.
Reset the counter for the first list node in the sequence.
*/
&:first-child,
:not(&) + & {
counter-reset: prosemirror-flat-list-counter;

/*
If the first list node has a custom order number, set the counter to that value.
*/
&[data-list-order] {
@supports (counter-set: prosemirror-flat-list-counter 1) {
counter-set: prosemirror-flat-list-counter
var(--prosemirror-flat-list-order);
}

/*
Safari (at least version <= 17.1) doesn't support `counter-set`
*/
@supports not (counter-set: prosemirror-flat-list-counter 1) {
counter-increment: prosemirror-flat-list-counter
var(--prosemirror-flat-list-order);
}
}
}
}

Expand Down

0 comments on commit 7d227f8

Please sign in to comment.