Skip to content

Commit

Permalink
fix(YfmCut): reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
d3m1d0v committed Feb 6, 2024
1 parent 80ad40f commit 6b27b6d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
6 changes: 6 additions & 0 deletions src/extensions/yfm/YfmCut/YfmCutSpecs/const.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import {nodeTypeFactory} from '../../../../utils/schema';

export enum CutNode {
Cut = 'yfm_cut',
CutTitle = 'yfm_cut_title',
CutContent = 'yfm_cut_content',
}

export const cutType = nodeTypeFactory(CutNode.Cut);
export const cutTitleType = nodeTypeFactory(CutNode.CutTitle);
export const cutContentType = nodeTypeFactory(CutNode.CutContent);
6 changes: 1 addition & 5 deletions src/extensions/yfm/YfmCut/YfmCutSpecs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ import yfmPlugin from '@diplodoc/transform/lib/plugins/cut';
import type {NodeSpec} from 'prosemirror-model';

import type {ExtensionAuto, YENodeSpec} from '../../../../core';
import {nodeTypeFactory} from '../../../../utils/schema';

import {CutNode} from './const';
import {fromYfm} from './fromYfm';
import {getSpec} from './spec';
import {toYfm} from './toYfm';

export {CutNode} from './const';
export const cutType = nodeTypeFactory(CutNode.Cut);
export const cutTitleType = nodeTypeFactory(CutNode.CutTitle);
export const cutContentType = nodeTypeFactory(CutNode.CutContent);
export {CutNode, cutType, cutTitleType, cutContentType} from './const';

export type YfmCutSpecsOptions = {
cutView?: YENodeSpec['view'];
Expand Down
4 changes: 3 additions & 1 deletion src/extensions/yfm/YfmCut/YfmCutSpecs/spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {NodeSpec} from 'prosemirror-model';

import {PlaceholderOptions} from '../../../../utils/placeholder';
import type {PlaceholderOptions} from '../../../../utils/placeholder';
import {CutNode} from '../const';

import type {YfmCutSpecsOptions} from './index';
Expand Down Expand Up @@ -43,6 +43,7 @@ export const getSpec = (
DEFAULT_PLACEHOLDERS.Title,
alwaysVisible: true,
},
definingAsContext: true,
selectable: false,
allowSelection: false,
complex: 'leaf',
Expand All @@ -63,6 +64,7 @@ export const getSpec = (
DEFAULT_PLACEHOLDERS.Content,
alwaysVisible: true,
},
definingAsContext: true,
selectable: false,
allowSelection: false,
complex: 'leaf',
Expand Down
13 changes: 4 additions & 9 deletions src/extensions/yfm/YfmCut/actions/toYfmCut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@ import type {Command} from 'prosemirror-state';
import {findParentNodeOfType} from 'prosemirror-utils';

import type {ActionSpec} from '../../../../core';
import {nodeTypeFactory} from '../../../../utils/schema';
import {CutNode} from '../const';

const yfmCutType = nodeTypeFactory(CutNode.Cut);
const yfmCutTitleType = nodeTypeFactory(CutNode.CutTitle);
const yfmCutContentType = nodeTypeFactory(CutNode.CutContent);
import {cutContentType, cutTitleType, cutType} from '../const';

const createYfmCutNode = (schema: Schema) => (content?: Node | Node[]) => {
return yfmCutType(schema).create(null, [
yfmCutTitleType(schema).create(null),
yfmCutContentType(schema).create(null, content),
return cutType(schema).create(null, [
cutTitleType(schema).create(null),
cutContentType(schema).create(null, content),
]);
};

Expand Down

0 comments on commit 6b27b6d

Please sign in to comment.