Skip to content

Commit 8be5211

Browse files
authored
fix(yfmCut): reverted details, summary tags (#431)
1 parent e24aa27 commit 8be5211

File tree

6 files changed

+31
-7
lines changed

6 files changed

+31
-7
lines changed

demo/YFM.stories.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ This is an alert.
5454
Content displayed when clicked.
5555
5656
{% endcut %}
57+
58+
{% cut "Cut with nested сut header" %}
59+
60+
{% cut "Cut header" %}
61+
62+
Content displayed when clicked.
63+
64+
{% endcut %}
65+
66+
{% endcut %}
67+
5768
`.trim(),
5869

5970
yfmTabs: `

src/extensions/yfm/YfmCut/YfmCutSpecs/schema.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ export const getSchemaSpecs = (
1515
placeholder?: PlaceholderOptions,
1616
): Record<CutNode, NodeSpec> => ({
1717
[CutNode.Cut]: {
18-
attrs: {class: {default: 'yfm-cut'}, open: {default: null}},
18+
attrs: {class: {default: 'yfm-cut'}},
1919
content: `${CutNode.CutTitle} ${CutNode.CutContent}`,
2020
group: 'block yfm-cut',
2121
parseDOM: [{tag: '.yfm-cut'}],
2222
toDOM(node) {
23-
return ['details', node.attrs, 0];
23+
return ['div', node.attrs, 0];
2424
},
2525
selectable: true,
2626
allowSelection: true,
@@ -34,7 +34,7 @@ export const getSchemaSpecs = (
3434
group: 'block yfm-cut',
3535
parseDOM: [{tag: '.yfm-cut-title'}],
3636
toDOM(node) {
37-
return ['summary', node.attrs, 0];
37+
return ['div', node.attrs, 0];
3838
},
3939
placeholder: {
4040
content:

src/extensions/yfm/YfmCut/actions/toYfmCut.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {ActionSpec} from '../../../../core';
66
import {cutContentType, cutTitleType, cutType} from '../const';
77

88
const createYfmCutNode = (schema: Schema) => (content?: Node | Node[] | Fragment) => {
9-
return cutType(schema).create({class: 'yfm-cut open', open: true}, [
9+
return cutType(schema).create({class: 'yfm-cut open'}, [
1010
cutTitleType(schema).create(null),
1111
cutContentType(schema).create(null, content),
1212
]);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
11
.yfm-cut-title .g-md-yfm-cut-title-inner {
22
cursor: text;
33
}
4+
5+
// FIXME: Restore the cut-extension mapping after the fix:
6+
// when using <details> and <summary> tags, the click does
7+
// not work correctly on the placeholder
8+
9+
.yfm-cut-content {
10+
display: none;
11+
overflow: hidden;
12+
13+
transition: height 0.3s ease-in-out;
14+
}
15+
16+
.open > .yfm-cut-content {
17+
display: revert;
18+
}

src/extensions/yfm/YfmCut/nodeviews/yfm-cut-title.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class YfmCutTitleNodeView implements NodeView {
1212
constructor(node: Node) {
1313
this.node = node;
1414

15-
this.dom = document.createElement('summary');
15+
this.dom = document.createElement('div');
1616
this.dom.classList.add('yfm-cut-title');
1717
this.dom.replaceChildren((this.contentDOM = document.createElement('div')));
1818
this.contentDOM.classList.add('g-md-yfm-cut-title-inner');

src/extensions/yfm/YfmCut/plugins/auto-open.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ function openParentYfmCuts($pos: ResolvedPos, domAtPos: EditorView['domAtPos']):
4444
if ($pos.node(depth - 1).type === cutType(schema)) {
4545
const {node: cutDomNode} = domAtPos($pos.start(depth - 1), 0);
4646
(cutDomNode as Element).classList.add('open');
47-
(cutDomNode as Element).setAttribute('open', 'true');
4847
depth--;
4948
}
5049
}
@@ -105,7 +104,6 @@ class CutAutoOpenOnDragOver implements PluginView {
105104
private _openCut() {
106105
if (this._editorView.dragging) {
107106
this._cutElem?.classList.add('open');
108-
this._cutElem?.setAttribute('open', 'true');
109107
}
110108
this._clear();
111109
}

0 commit comments

Comments
 (0)