Skip to content

Commit 3be1e41

Browse files
authored
feat(yfmCut): updated yfmCut (#408)
1 parent 407037b commit 3be1e41

File tree

7 files changed

+31
-15
lines changed

7 files changed

+31
-15
lines changed

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
"@diplodoc/html-extension": "2.3.2",
205205
"@diplodoc/latex-extension": "1.0.3",
206206
"@diplodoc/mermaid-extension": "1.2.1",
207-
"@diplodoc/transform": "4.22.0",
207+
"@diplodoc/transform": "4.26.0",
208208
"@gravity-ui/components": "3.0.0",
209209
"@gravity-ui/eslint-config": "3.1.1",
210210
"@gravity-ui/prettier-config": "1.1.0",
@@ -279,7 +279,7 @@
279279
"@diplodoc/html-extension": "2.3.2",
280280
"@diplodoc/latex-extension": "^1.0.3",
281281
"@diplodoc/mermaid-extension": "^1.0.0",
282-
"@diplodoc/transform": ">=4.5.0 <4.19.0",
282+
"@diplodoc/transform": ">=4.5.0 <=4.26.0",
283283
"@gravity-ui/components": "^3.0.0",
284284
"@gravity-ui/uikit": "^6.11.0",
285285
"highlight.js": "^11.8.0",

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

Lines changed: 6 additions & 6 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'}},
18+
attrs: {class: {default: 'yfm-cut'}, open: {default: null}},
1919
content: `${CutNode.CutTitle} ${CutNode.CutContent}`,
2020
group: 'block yfm-cut',
21-
parseDOM: [{tag: 'div.yfm-cut'}],
21+
parseDOM: [{tag: '.yfm-cut'}],
2222
toDOM(node) {
23-
return ['div', node.attrs, 0];
23+
return ['details', node.attrs, 0];
2424
},
2525
selectable: true,
2626
allowSelection: true,
@@ -32,9 +32,9 @@ export const getSchemaSpecs = (
3232
attrs: {class: {default: 'yfm-cut-title'}},
3333
content: 'inline*',
3434
group: 'block yfm-cut',
35-
parseDOM: [{tag: 'div.yfm-cut-title'}],
35+
parseDOM: [{tag: '.yfm-cut-title'}],
3636
toDOM(node) {
37-
return ['div', node.attrs, 0];
37+
return ['summary', node.attrs, 0];
3838
},
3939
placeholder: {
4040
content:
@@ -53,7 +53,7 @@ export const getSchemaSpecs = (
5353
attrs: {class: {default: 'yfm-cut-content'}},
5454
content: '(block | paragraph)+',
5555
group: 'block yfm-cut',
56-
parseDOM: [{tag: 'div.yfm-cut-content'}],
56+
parseDOM: [{tag: '.yfm-cut-content'}],
5757
toDOM(node) {
5858
return ['div', node.attrs, 0];
5959
},

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'}, [
9+
return cutType(schema).create({class: 'yfm-cut open', open: true}, [
1010
cutTitleType(schema).create(null),
1111
cutContentType(schema).create(null, content),
1212
]);

src/extensions/yfm/YfmCut/index.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,17 @@
66
&.yfm-cut-active {
77
border-color: var(--g-color-line-generic);
88
}
9+
.yfm-cut-title:focus {
10+
outline: 0;
11+
}
12+
13+
/* TODO: Remove this after updating @diplodoc/transform to version 4.19.0 or higher */
14+
/* This ensures backward compatibility with earlier versions of cut-extension */
15+
.yfm-cut-title {
16+
list-style: none;
17+
}
18+
.yfm-cut-title::-webkit-details-marker,
19+
.yfm-cut-title::marker {
20+
display: none;
21+
}
922
}

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

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

15-
this.dom = document.createElement('div');
15+
this.dom = document.createElement('summary');
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');
1919
this.contentDOM.addEventListener('click', (e) => {
2020
// ignore clicking on the title content
2121
// you can open/close yfm-cut by clicking on the arrow icon
2222
e.stopPropagation();
23+
e.preventDefault();
2324
});
2425
}
2526

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ 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');
4748
depth--;
4849
}
4950
}
@@ -104,6 +105,7 @@ class CutAutoOpenOnDragOver implements PluginView {
104105
private _openCut() {
105106
if (this._editorView.dragging) {
106107
this._cutElem?.classList.add('open');
108+
this._cutElem?.setAttribute('open', 'true');
107109
}
108110
this._clear();
109111
}

0 commit comments

Comments
 (0)