@gravity-ui/markdown-editor 13.5.3 → 13.6.1
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/build/cjs/bundle/Editor.js +8 -5
- package/build/cjs/bundle/config/icons.d.ts +1 -1
- package/build/cjs/bundle/config/icons.js +1 -0
- package/build/cjs/bundle/config/wysiwyg.d.ts +2 -1
- package/build/cjs/bundle/config/wysiwyg.js +13 -2
- package/build/cjs/extensions/yfm/FoldingHeading/FoldingHeading.d.ts +12 -0
- package/build/cjs/extensions/yfm/FoldingHeading/FoldingHeading.js +22 -0
- package/build/cjs/extensions/yfm/FoldingHeading/FoldingHeadingSpec/FoldingHeadingSpecs.d.ts +2 -0
- package/build/cjs/extensions/yfm/FoldingHeading/FoldingHeadingSpec/FoldingHeadingSpecs.js +9 -0
- package/build/cjs/extensions/yfm/FoldingHeading/FoldingHeadingSpec/const.d.ts +11 -0
- package/build/cjs/extensions/yfm/FoldingHeading/FoldingHeadingSpec/const.js +5 -0
- package/build/cjs/extensions/yfm/FoldingHeading/FoldingHeadingSpec/index.d.ts +1 -0
- package/build/cjs/extensions/yfm/FoldingHeading/FoldingHeadingSpec/index.js +4 -0
- package/build/cjs/extensions/yfm/FoldingHeading/FoldingHeadingSpec/md/skip-heading-sections.d.ts +3 -0
- package/build/cjs/extensions/yfm/FoldingHeading/FoldingHeadingSpec/md/skip-heading-sections.js +17 -0
- package/build/cjs/extensions/yfm/FoldingHeading/actions.d.ts +2 -0
- package/build/cjs/extensions/yfm/FoldingHeading/actions.js +10 -0
- package/build/cjs/extensions/yfm/FoldingHeading/commands/index.d.ts +3 -0
- package/build/cjs/extensions/yfm/FoldingHeading/commands/index.js +6 -0
- package/build/cjs/extensions/yfm/FoldingHeading/commands/openHeadingAndCreateParagraphAfterIfCursorAtEndOfHeading.d.ts +2 -0
- package/build/cjs/extensions/yfm/FoldingHeading/commands/openHeadingAndCreateParagraphAfterIfCursorAtEndOfHeading.js +27 -0
- package/build/cjs/extensions/yfm/FoldingHeading/commands/removeFoldingIfCursorAtStartOfHeading.d.ts +2 -0
- package/build/cjs/extensions/yfm/FoldingHeading/commands/removeFoldingIfCursorAtStartOfHeading.js +17 -0
- package/build/cjs/extensions/yfm/FoldingHeading/commands/toggleFoldingOfHeading.d.ts +2 -0
- package/build/cjs/extensions/yfm/FoldingHeading/commands/toggleFoldingOfHeading.js +26 -0
- package/build/cjs/extensions/yfm/FoldingHeading/const.d.ts +1 -0
- package/build/cjs/extensions/yfm/FoldingHeading/const.js +6 -0
- package/build/cjs/extensions/yfm/FoldingHeading/index.d.ts +1 -0
- package/build/cjs/extensions/yfm/FoldingHeading/index.js +5 -0
- package/build/cjs/extensions/yfm/FoldingHeading/input-rules.d.ts +4 -0
- package/build/cjs/extensions/yfm/FoldingHeading/input-rules.js +31 -0
- package/build/cjs/extensions/yfm/FoldingHeading/plugins/Folding.d.ts +3 -0
- package/build/cjs/extensions/yfm/FoldingHeading/plugins/Folding.js +167 -0
- package/build/cjs/extensions/yfm/FoldingHeading/plugins/folding.css +51 -0
- package/build/cjs/extensions/yfm/FoldingHeading/utils.d.ts +10 -0
- package/build/cjs/extensions/yfm/FoldingHeading/utils.js +30 -0
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/const.d.ts +1 -1
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/const.js +1 -1
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.js +4 -4
- package/build/cjs/extensions/yfm/YfmHeading/YfmHeadingSpecs/utils.js +9 -1
- package/build/cjs/i18n/menubar/en.json +2 -0
- package/build/cjs/i18n/menubar/index.d.ts +3 -1
- package/build/cjs/i18n/menubar/ru.json +2 -0
- package/build/cjs/icons/index.d.ts +1 -1
- package/build/cjs/icons/index.js +2 -1
- package/build/cjs/version.js +1 -1
- package/build/esm/bundle/Editor.js +8 -5
- package/build/esm/bundle/config/icons.d.ts +1 -1
- package/build/esm/bundle/config/icons.js +2 -1
- package/build/esm/bundle/config/wysiwyg.d.ts +2 -1
- package/build/esm/bundle/config/wysiwyg.js +12 -1
- package/build/esm/extensions/yfm/FoldingHeading/FoldingHeading.d.ts +12 -0
- package/build/esm/extensions/yfm/FoldingHeading/FoldingHeading.js +18 -0
- package/build/esm/extensions/yfm/FoldingHeading/FoldingHeadingSpec/FoldingHeadingSpecs.d.ts +2 -0
- package/build/esm/extensions/yfm/FoldingHeading/FoldingHeadingSpec/FoldingHeadingSpecs.js +5 -0
- package/build/esm/extensions/yfm/FoldingHeading/FoldingHeadingSpec/const.d.ts +11 -0
- package/build/esm/extensions/yfm/FoldingHeading/FoldingHeadingSpec/const.js +2 -0
- package/build/esm/extensions/yfm/FoldingHeading/FoldingHeadingSpec/index.d.ts +1 -0
- package/build/esm/extensions/yfm/FoldingHeading/FoldingHeadingSpec/index.js +1 -0
- package/build/esm/extensions/yfm/FoldingHeading/FoldingHeadingSpec/md/skip-heading-sections.d.ts +3 -0
- package/build/esm/extensions/yfm/FoldingHeading/FoldingHeadingSpec/md/skip-heading-sections.js +13 -0
- package/build/esm/extensions/yfm/FoldingHeading/actions.d.ts +2 -0
- package/build/esm/extensions/yfm/FoldingHeading/actions.js +7 -0
- package/build/esm/extensions/yfm/FoldingHeading/commands/index.d.ts +3 -0
- package/build/esm/extensions/yfm/FoldingHeading/commands/index.js +3 -0
- package/build/esm/extensions/yfm/FoldingHeading/commands/openHeadingAndCreateParagraphAfterIfCursorAtEndOfHeading.d.ts +2 -0
- package/build/esm/extensions/yfm/FoldingHeading/commands/openHeadingAndCreateParagraphAfterIfCursorAtEndOfHeading.js +23 -0
- package/build/esm/extensions/yfm/FoldingHeading/commands/removeFoldingIfCursorAtStartOfHeading.d.ts +2 -0
- package/build/esm/extensions/yfm/FoldingHeading/commands/removeFoldingIfCursorAtStartOfHeading.js +13 -0
- package/build/esm/extensions/yfm/FoldingHeading/commands/toggleFoldingOfHeading.d.ts +2 -0
- package/build/esm/extensions/yfm/FoldingHeading/commands/toggleFoldingOfHeading.js +22 -0
- package/build/esm/extensions/yfm/FoldingHeading/const.d.ts +1 -0
- package/build/esm/extensions/yfm/FoldingHeading/const.js +1 -0
- package/build/esm/extensions/yfm/FoldingHeading/index.d.ts +1 -0
- package/build/esm/extensions/yfm/FoldingHeading/index.js +1 -0
- package/build/esm/extensions/yfm/FoldingHeading/input-rules.d.ts +4 -0
- package/build/esm/extensions/yfm/FoldingHeading/input-rules.js +27 -0
- package/build/esm/extensions/yfm/FoldingHeading/plugins/Folding.d.ts +4 -0
- package/build/esm/extensions/yfm/FoldingHeading/plugins/Folding.js +164 -0
- package/build/esm/extensions/yfm/FoldingHeading/plugins/folding.css +51 -0
- package/build/esm/extensions/yfm/FoldingHeading/utils.d.ts +10 -0
- package/build/esm/extensions/yfm/FoldingHeading/utils.js +19 -0
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/const.d.ts +1 -1
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/const.js +1 -1
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/index.js +4 -4
- package/build/esm/extensions/yfm/YfmHeading/YfmHeadingSpecs/utils.js +9 -1
- package/build/esm/i18n/menubar/en.json +2 -0
- package/build/esm/i18n/menubar/index.d.ts +3 -1
- package/build/esm/i18n/menubar/ru.json +2 -0
- package/build/esm/icons/index.d.ts +1 -1
- package/build/esm/icons/index.js +1 -1
- package/build/esm/version.js +1 -1
- package/build/styles.css +51 -0
- package/package.json +10 -5
|
@@ -241,15 +241,18 @@ class EditorImpl extends event_emitter_1.SafeEventEmitter {
|
|
|
241
241
|
}
|
|
242
242
|
return this.currentEditor.moveCursor(position);
|
|
243
243
|
}
|
|
244
|
-
moveCursorToLine(line) {
|
|
244
|
+
moveCursorToLine(/** 0-based line number */ line) {
|
|
245
245
|
const mode = this.currentMode;
|
|
246
246
|
switch (mode) {
|
|
247
247
|
case 'markup': {
|
|
248
|
-
const lineNumber = line + 1;
|
|
249
248
|
const view = this.markupEditor.cm;
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
249
|
+
let cmLine = line + 1; // lines in codemirror is 1-based
|
|
250
|
+
cmLine = Math.max(cmLine, 1);
|
|
251
|
+
cmLine = Math.min(cmLine, view.state.doc.lines);
|
|
252
|
+
view.dispatch({
|
|
253
|
+
scrollIntoView: true,
|
|
254
|
+
selection: { anchor: view.state.doc.line(cmLine).from },
|
|
255
|
+
});
|
|
253
256
|
break;
|
|
254
257
|
}
|
|
255
258
|
case 'wysiwyg': {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ToolbarIconData } from '../../toolbar/types';
|
|
2
|
-
declare type Icon = 'undo' | 'redo' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'mono' | 'mark' | 'textColor' | 'text' | 'headline' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'bulletList' | 'orderedList' | 'sink' | 'lift' | 'cut' | 'note' | 'code' | 'codeBlock' | 'link' | 'image' | 'table' | 'quote' | 'checklist' | 'horizontalRule' | 'file' | 'functionInline' | 'functionBlock' | 'emoji' | 'tabs' | 'mermaid' | 'html';
|
|
2
|
+
declare type Icon = 'undo' | 'redo' | 'bold' | 'italic' | 'underline' | 'strikethrough' | 'mono' | 'mark' | 'textColor' | 'text' | 'headline' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'bulletList' | 'orderedList' | 'sink' | 'lift' | 'cut' | 'note' | 'code' | 'codeBlock' | 'link' | 'image' | 'table' | 'quote' | 'checklist' | 'horizontalRule' | 'file' | 'functionInline' | 'functionBlock' | 'emoji' | 'tabs' | 'mermaid' | 'html' | 'foldingHeading';
|
|
3
3
|
declare type Icons = Record<Icon, ToolbarIconData>;
|
|
4
4
|
export declare const icons: Icons;
|
|
5
5
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ActionStorage } from 'src/core';
|
|
2
|
-
import type { SelectionContextConfig } from '../../extensions/behavior/SelectionContext';
|
|
2
|
+
import type { SelectionContextConfig, SelectionContextItemData } from '../../extensions/behavior/SelectionContext';
|
|
3
3
|
import { ToolbarData } from '../../toolbar/Toolbar';
|
|
4
4
|
import { ToolbarGroupData } from '../../toolbar/ToolbarGroup';
|
|
5
5
|
import { ToolbarListButtonData } from '../../toolbar/ToolbarListButton';
|
|
@@ -49,6 +49,7 @@ export declare const wCommandMenuConfig: WToolbarItemData[];
|
|
|
49
49
|
export declare const wHiddenData: WToolbarItemData[];
|
|
50
50
|
/** prepared wysiwyg toolbar config */
|
|
51
51
|
export declare const wToolbarConfig: WToolbarData;
|
|
52
|
+
export declare const wToggleHeadingFoldingItemData: SelectionContextItemData;
|
|
52
53
|
export declare const wSelectionMenuConfig: SelectionContextConfig;
|
|
53
54
|
export declare const wMermaidItemData: WToolbarSingleItemData;
|
|
54
55
|
export declare const wToolbarConfigByPreset: Record<EditorPreset, WToolbarData>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.wSelectionMenuConfigByPreset = exports.wHiddenDataByPreset = exports.wCommandMenuConfigByPreset = exports.wToolbarConfigByPreset = exports.wMermaidItemData = exports.wSelectionMenuConfig = exports.wToolbarConfig = exports.wHiddenData = exports.wCommandMenuConfig = exports.wYfmHtmlBlockItemData = exports.wMathListItem = exports.wMathListConfig = exports.wMathBlockItemData = exports.wTabsItemData = exports.wMathInlineItemData = exports.wFileItemData = exports.wEmojiItemData = exports.wHruleItemData = exports.wImageItemData = exports.wCodeListConfig = exports.wCodeBlockItemData = exports.wCodeItemData = exports.wTableItemData = exports.wNoteItemData = exports.wListMoveListConfig = exports.wCutItemData = exports.wQuoteItemData = exports.wLinkItemData = exports.wCheckboxItemData = exports.wListsListConfig = exports.wHeadingListConfig = exports.wTextItemData = exports.wBiusGroupConfig = exports.wMarkedItemData = exports.wMonospaceItemData = exports.wStrikethroughItemData = exports.wUnderlineItemData = exports.wItalicItemData = exports.wBoldItemData = exports.wHistoryGroupConfig = void 0;
|
|
3
|
+
exports.wSelectionMenuConfigByPreset = exports.wHiddenDataByPreset = exports.wCommandMenuConfigByPreset = exports.wToolbarConfigByPreset = exports.wMermaidItemData = exports.wSelectionMenuConfig = exports.wToggleHeadingFoldingItemData = exports.wToolbarConfig = exports.wHiddenData = exports.wCommandMenuConfig = exports.wYfmHtmlBlockItemData = exports.wMathListItem = exports.wMathListConfig = exports.wMathBlockItemData = exports.wTabsItemData = exports.wMathInlineItemData = exports.wFileItemData = exports.wEmojiItemData = exports.wHruleItemData = exports.wImageItemData = exports.wCodeListConfig = exports.wCodeBlockItemData = exports.wCodeItemData = exports.wTableItemData = exports.wNoteItemData = exports.wListMoveListConfig = exports.wCutItemData = exports.wQuoteItemData = exports.wLinkItemData = exports.wCheckboxItemData = exports.wListsListConfig = exports.wHeadingListConfig = exports.wTextItemData = exports.wBiusGroupConfig = exports.wMarkedItemData = exports.wMonospaceItemData = exports.wStrikethroughItemData = exports.wUnderlineItemData = exports.wItalicItemData = exports.wBoldItemData = exports.wHistoryGroupConfig = void 0;
|
|
4
4
|
const extensions_1 = require("../../extensions");
|
|
5
5
|
const hints_1 = require("../../i18n/hints");
|
|
6
6
|
const menubar_1 = require("../../i18n/menubar");
|
|
@@ -443,6 +443,17 @@ exports.wToolbarConfig = [
|
|
|
443
443
|
],
|
|
444
444
|
[exports.wImageItemData, exports.wFileItemData, exports.wTableItemData, exports.wCheckboxItemData],
|
|
445
445
|
];
|
|
446
|
+
exports.wToggleHeadingFoldingItemData = {
|
|
447
|
+
id: 'folding-heading',
|
|
448
|
+
type: types_1.ToolbarDataType.SingleButton,
|
|
449
|
+
icon: icons_1.icons.foldingHeading,
|
|
450
|
+
title: () => (0, menubar_1.i18n)('folding-heading'),
|
|
451
|
+
hint: () => (0, menubar_1.i18n)('folding-heading_hint'),
|
|
452
|
+
isActive: (editor) => { var _a, _b; return (_b = (_a = editor.actions.toggleHeadingFolding) === null || _a === void 0 ? void 0 : _a.isActive()) !== null && _b !== void 0 ? _b : false; },
|
|
453
|
+
isEnable: (editor) => { var _a, _b; return (_b = (_a = editor.actions.toggleHeadingFolding) === null || _a === void 0 ? void 0 : _a.isEnable()) !== null && _b !== void 0 ? _b : false; },
|
|
454
|
+
exec: (editor) => editor.actions.toggleHeadingFolding.run(),
|
|
455
|
+
condition: 'enabled',
|
|
456
|
+
};
|
|
446
457
|
const textContextItemData = {
|
|
447
458
|
id: 'text',
|
|
448
459
|
type: types_1.ToolbarDataType.ReactComponent,
|
|
@@ -456,7 +467,7 @@ const textContextItemData = {
|
|
|
456
467
|
},
|
|
457
468
|
};
|
|
458
469
|
exports.wSelectionMenuConfig = [
|
|
459
|
-
[textContextItemData],
|
|
470
|
+
[exports.wToggleHeadingFoldingItemData, textContextItemData],
|
|
460
471
|
[...exports.wBiusGroupConfig, exports.wCodeItemData],
|
|
461
472
|
[
|
|
462
473
|
{
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Action, ExtensionAuto } from '../../../core';
|
|
2
|
+
import '@diplodoc/folding-headings-extension/runtime/styles.css';
|
|
3
|
+
declare const action = "toggleHeadingFolding";
|
|
4
|
+
export declare const FoldingHeading: ExtensionAuto;
|
|
5
|
+
declare global {
|
|
6
|
+
namespace WysiwygEditor {
|
|
7
|
+
interface Actions {
|
|
8
|
+
[action]: Action;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FoldingHeading = void 0;
|
|
4
|
+
const FoldingHeadingSpec_1 = require("./FoldingHeadingSpec");
|
|
5
|
+
const actions_1 = require("./actions");
|
|
6
|
+
const commands_1 = require("./commands");
|
|
7
|
+
const input_rules_1 = require("./input-rules");
|
|
8
|
+
const Folding_1 = require("./plugins/Folding");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
require("@diplodoc/folding-headings-extension/runtime/styles.css");
|
|
11
|
+
const action = 'toggleHeadingFolding';
|
|
12
|
+
const FoldingHeading = (builder) => {
|
|
13
|
+
builder.use(FoldingHeadingSpec_1.FoldingHeadingSpecs);
|
|
14
|
+
builder.addAction(action, () => actions_1.toggleHeadingFoldingAction);
|
|
15
|
+
builder.addInputRules(({ schema }) => ({ rules: [(0, input_rules_1.foldingHeadingRule)((0, utils_1.headingType)(schema), 6)] }));
|
|
16
|
+
builder.addKeymap(() => ({
|
|
17
|
+
Enter: commands_1.openHeadingAndCreateParagraphAfterIfCursorAtEndOfHeading,
|
|
18
|
+
Backspace: commands_1.removeFoldingIfCursorAtStartOfHeading,
|
|
19
|
+
}), builder.Priority.High);
|
|
20
|
+
builder.addPlugin(Folding_1.foldingPlugin);
|
|
21
|
+
};
|
|
22
|
+
exports.FoldingHeading = FoldingHeading;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FoldingHeadingSpecs = void 0;
|
|
4
|
+
const folding_headings_extension_1 = require("@diplodoc/folding-headings-extension");
|
|
5
|
+
const skip_heading_sections_1 = require("./md/skip-heading-sections");
|
|
6
|
+
const FoldingHeadingSpecs = (builder) => {
|
|
7
|
+
builder.configureMd((md) => md.use((0, folding_headings_extension_1.transform)({ bundle: false })).use(skip_heading_sections_1.skipSectionsPlugin));
|
|
8
|
+
};
|
|
9
|
+
exports.FoldingHeadingSpecs = FoldingHeadingSpecs;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const TokenType: Pick<{
|
|
2
|
+
readonly Heading: "heading";
|
|
3
|
+
readonly HeadingOpen: "heading_open";
|
|
4
|
+
readonly HeadingClose: "heading_close";
|
|
5
|
+
readonly Section: "heading_section";
|
|
6
|
+
readonly SectionOpen: "heading_section_open";
|
|
7
|
+
readonly SectionClose: "heading_section_close";
|
|
8
|
+
readonly Content: "heading_section_content";
|
|
9
|
+
readonly ContentOpen: "heading_section_content_open";
|
|
10
|
+
readonly ContentClose: "heading_section_content_close";
|
|
11
|
+
}, "Heading" | "Section" | "Content">;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './FoldingHeadingSpecs';
|
package/build/cjs/extensions/yfm/FoldingHeading/FoldingHeadingSpec/md/skip-heading-sections.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.skipSectionsPlugin = void 0;
|
|
4
|
+
const folding_headings_extension_1 = require("@diplodoc/folding-headings-extension");
|
|
5
|
+
const ignoreTokenTypes = [
|
|
6
|
+
folding_headings_extension_1.TokenType.SectionOpen,
|
|
7
|
+
folding_headings_extension_1.TokenType.SectionClose,
|
|
8
|
+
folding_headings_extension_1.TokenType.ContentOpen,
|
|
9
|
+
folding_headings_extension_1.TokenType.ContentClose,
|
|
10
|
+
];
|
|
11
|
+
/** Filter heading section tokens, which are not needed in prosemirror-document */
|
|
12
|
+
const skipSectionsPlugin = (md) => {
|
|
13
|
+
md.core.ruler.push('skip-heading-sections', (state) => {
|
|
14
|
+
state.tokens = state.tokens.filter((token) => !ignoreTokenTypes.includes(token.type));
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
exports.skipSectionsPlugin = skipSectionsPlugin;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toggleHeadingFoldingAction = void 0;
|
|
4
|
+
const commands_1 = require("./commands");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
exports.toggleHeadingFoldingAction = {
|
|
7
|
+
isActive: (state) => (0, utils_1.hasFolding)(state.selection),
|
|
8
|
+
isEnable: commands_1.toggleFoldingOfHeading,
|
|
9
|
+
run: commands_1.toggleFoldingOfHeading,
|
|
10
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./removeFoldingIfCursorAtStartOfHeading"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./toggleFoldingOfHeading"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./openHeadingAndCreateParagraphAfterIfCursorAtEndOfHeading"), exports);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.openHeadingAndCreateParagraphAfterIfCursorAtEndOfHeading = void 0;
|
|
4
|
+
const prosemirror_state_1 = require("prosemirror-state");
|
|
5
|
+
const selection_1 = require("../../../../utils/selection");
|
|
6
|
+
const specs_1 = require("../../../base/specs");
|
|
7
|
+
const const_1 = require("../const");
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
const openHeadingAndCreateParagraphAfterIfCursorAtEndOfHeading = (state, dispatch) => {
|
|
10
|
+
const $cursor = get$CursorAtBlockEnd(state.selection);
|
|
11
|
+
if (!$cursor || !(0, utils_1.isFoldedHeading)($cursor.parent))
|
|
12
|
+
return false;
|
|
13
|
+
if (dispatch) {
|
|
14
|
+
const tr = state.tr
|
|
15
|
+
.setNodeAttribute($cursor.before(), const_1.YfmHeadingAttr.Folding, false)
|
|
16
|
+
.insert($cursor.after(), (0, specs_1.pType)(state.schema).createAndFill());
|
|
17
|
+
dispatch(tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, $cursor.after() + 1)).scrollIntoView());
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
};
|
|
21
|
+
exports.openHeadingAndCreateParagraphAfterIfCursorAtEndOfHeading = openHeadingAndCreateParagraphAfterIfCursorAtEndOfHeading;
|
|
22
|
+
function get$CursorAtBlockEnd(selection) {
|
|
23
|
+
const $cursor = (0, selection_1.get$Cursor)(selection);
|
|
24
|
+
if (!$cursor || $cursor.parent.isInline || $cursor.parentOffset < $cursor.parent.content.size)
|
|
25
|
+
return null;
|
|
26
|
+
return $cursor;
|
|
27
|
+
}
|
package/build/cjs/extensions/yfm/FoldingHeading/commands/removeFoldingIfCursorAtStartOfHeading.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.removeFoldingIfCursorAtStartOfHeading = void 0;
|
|
4
|
+
const selection_1 = require("../../../../utils/selection");
|
|
5
|
+
const const_1 = require("../const");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const removeFoldingIfCursorAtStartOfHeading = (state, dispatch) => {
|
|
8
|
+
const $cursor = (0, selection_1.get$Cursor)(state.selection);
|
|
9
|
+
if (!$cursor)
|
|
10
|
+
return false;
|
|
11
|
+
if ($cursor.parentOffset === 0 && (0, utils_1.isFoldingHeading)($cursor.parent)) {
|
|
12
|
+
dispatch === null || dispatch === void 0 ? void 0 : dispatch(state.tr.setNodeAttribute($cursor.before(), const_1.YfmHeadingAttr.Folding, null));
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
};
|
|
17
|
+
exports.removeFoldingIfCursorAtStartOfHeading = removeFoldingIfCursorAtStartOfHeading;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toggleFoldingOfHeading = void 0;
|
|
4
|
+
const specs_1 = require("../../../base/specs");
|
|
5
|
+
const const_1 = require("../const");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const toggleFoldingOfHeading = (state, dispatch) => {
|
|
8
|
+
if (!(0, utils_1.insideHeading)(state.selection))
|
|
9
|
+
return false;
|
|
10
|
+
if (dispatch) {
|
|
11
|
+
const { $head } = state.selection;
|
|
12
|
+
const folding = (0, utils_1.isFoldingHeading)($head.parent);
|
|
13
|
+
const level = (0, utils_1.parseLevel)($head.parent);
|
|
14
|
+
const tr = state.tr.setNodeAttribute($head.before(), const_1.YfmHeadingAttr.Folding, folding ? null : false);
|
|
15
|
+
if (!folding) {
|
|
16
|
+
// insert empty paragraph if content of new folding heading is empty
|
|
17
|
+
const nextNode = $head.node(-1).maybeChild($head.indexAfter(-1));
|
|
18
|
+
if (!nextNode || ((0, utils_1.isFoldingHeading)(nextNode) && (0, utils_1.parseLevel)(nextNode) <= level)) {
|
|
19
|
+
tr.insert($head.after(), (0, specs_1.pType)(state.schema).create());
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
dispatch(tr);
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
};
|
|
26
|
+
exports.toggleFoldingOfHeading = toggleFoldingOfHeading;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { YfmHeadingAttr, headingNodeName, type HeadingLevel } from '../YfmHeading/const';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.headingNodeName = exports.YfmHeadingAttr = void 0;
|
|
4
|
+
var const_1 = require("../YfmHeading/const");
|
|
5
|
+
Object.defineProperty(exports, "YfmHeadingAttr", { enumerable: true, get: function () { return const_1.YfmHeadingAttr; } });
|
|
6
|
+
Object.defineProperty(exports, "headingNodeName", { enumerable: true, get: function () { return const_1.headingNodeName; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FoldingHeading } from './FoldingHeading';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FoldingHeading = void 0;
|
|
4
|
+
var FoldingHeading_1 = require("./FoldingHeading");
|
|
5
|
+
Object.defineProperty(exports, "FoldingHeading", { enumerable: true, get: function () { return FoldingHeading_1.FoldingHeading; } });
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.foldingHeadingRule = void 0;
|
|
4
|
+
const prosemirror_inputrules_1 = require("prosemirror-inputrules");
|
|
5
|
+
const inputrules_1 = require("../../../utils/inputrules");
|
|
6
|
+
const specs_1 = require("../../base/specs");
|
|
7
|
+
const const_1 = require("./const");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
function foldingHeadingRule(nodeType, maxLevel) {
|
|
10
|
+
return new prosemirror_inputrules_1.InputRule(new RegExp('^(#{1,' + maxLevel + '})\\+\\s$'), (state, match, start, end) => {
|
|
11
|
+
if ((0, inputrules_1.hasCodeMark)(state, match, start, end))
|
|
12
|
+
return null;
|
|
13
|
+
const $start = state.doc.resolve(start);
|
|
14
|
+
if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType))
|
|
15
|
+
return null;
|
|
16
|
+
const level = match[1].length;
|
|
17
|
+
const pos = $start.before();
|
|
18
|
+
const tr = state.tr.delete(start, end);
|
|
19
|
+
if (!(0, utils_1.isHeading)($start.parent))
|
|
20
|
+
tr.setNodeMarkup(pos, nodeType);
|
|
21
|
+
tr.setNodeAttribute(pos, const_1.YfmHeadingAttr.Level, level);
|
|
22
|
+
tr.setNodeAttribute(pos, const_1.YfmHeadingAttr.Folding, false);
|
|
23
|
+
// insert empty paragraph if content of new folding heading is empty
|
|
24
|
+
const nextNode = $start.node(-1).maybeChild($start.indexAfter(-1));
|
|
25
|
+
if (!nextNode || ((0, utils_1.isFoldingHeading)(nextNode) && (0, utils_1.parseLevel)(nextNode) <= level)) {
|
|
26
|
+
tr.insert(tr.mapping.map($start.after()), (0, specs_1.pType)(state.schema).create());
|
|
27
|
+
}
|
|
28
|
+
return tr;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
exports.foldingHeadingRule = foldingHeadingRule;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.foldingPlugin = void 0;
|
|
4
|
+
const prosemirror_state_1 = require("prosemirror-state");
|
|
5
|
+
const prosemirror_transform_1 = require("prosemirror-transform");
|
|
6
|
+
const prosemirror_utils_1 = require("prosemirror-utils");
|
|
7
|
+
const prosemirror_view_1 = require("prosemirror-view");
|
|
8
|
+
const const_1 = require("../const");
|
|
9
|
+
const utils_1 = require("../utils");
|
|
10
|
+
const CHANGE_META_KEY = 'folding-heading-changed';
|
|
11
|
+
const foldingPlugin = () => {
|
|
12
|
+
return new prosemirror_state_1.Plugin({
|
|
13
|
+
state: {
|
|
14
|
+
init: (_config, state) => buildDecosSet(state.doc),
|
|
15
|
+
apply: (tr, prev) => {
|
|
16
|
+
if (tr.getMeta(CHANGE_META_KEY)) {
|
|
17
|
+
return buildDecosSet(tr.doc);
|
|
18
|
+
}
|
|
19
|
+
if (!tr.docChanged ||
|
|
20
|
+
// Optimization: ignoring trs, that don't change position of blocks in doc
|
|
21
|
+
canSafelyIgnoreTr(tr)) {
|
|
22
|
+
return prev.map(tr.mapping, tr.doc);
|
|
23
|
+
}
|
|
24
|
+
return buildDecosSet(tr.doc);
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
props: {
|
|
28
|
+
decorations(state) {
|
|
29
|
+
return this.getState(state);
|
|
30
|
+
},
|
|
31
|
+
handleClickOn(view, _pos, node, nodePos, event, direct) {
|
|
32
|
+
if (direct && (0, utils_1.isFoldingHeading)(node) && isLeftPaddingClick(event)) {
|
|
33
|
+
view.dispatch(view.state.tr
|
|
34
|
+
.setNodeAttribute(nodePos, const_1.YfmHeadingAttr.Folding, !node.attrs[const_1.YfmHeadingAttr.Folding])
|
|
35
|
+
.setMeta(CHANGE_META_KEY, true));
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
exports.foldingPlugin = foldingPlugin;
|
|
42
|
+
function isLeftPaddingClick(event) {
|
|
43
|
+
const elem = event.target;
|
|
44
|
+
const leftPadding = parseInt(window.getComputedStyle(elem).paddingLeft, 10);
|
|
45
|
+
if (Number.isNaN(leftPadding))
|
|
46
|
+
return true;
|
|
47
|
+
return event.offsetX < leftPadding;
|
|
48
|
+
}
|
|
49
|
+
const safeSteps = [prosemirror_transform_1.AddMarkStep, prosemirror_transform_1.AddNodeMarkStep, prosemirror_transform_1.DocAttrStep, prosemirror_transform_1.RemoveMarkStep, prosemirror_transform_1.RemoveNodeMarkStep];
|
|
50
|
+
function canSafelyIgnoreTr(tr) {
|
|
51
|
+
if (isInputTr(tr) || isTextBackspaceTr(tr))
|
|
52
|
+
return true;
|
|
53
|
+
if (tr.steps.every((step) => safeSteps.some((SafeStep) => step instanceof SafeStep)))
|
|
54
|
+
return true;
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
function isInputTr(tr) {
|
|
58
|
+
if (tr.steps.length !== 1)
|
|
59
|
+
return false;
|
|
60
|
+
const [step] = tr.steps;
|
|
61
|
+
return (step instanceof prosemirror_transform_1.ReplaceStep &&
|
|
62
|
+
step.from === step.to &&
|
|
63
|
+
step.slice.content.childCount === 1 &&
|
|
64
|
+
step.slice.content.child(0).type.name === 'text');
|
|
65
|
+
}
|
|
66
|
+
function isTextBackspaceTr(tr) {
|
|
67
|
+
if (tr.steps.length !== 1)
|
|
68
|
+
return false;
|
|
69
|
+
const [step] = tr.steps;
|
|
70
|
+
return step instanceof prosemirror_transform_1.ReplaceStep && step.to - step.from === 1 && step.slice.size === 0;
|
|
71
|
+
}
|
|
72
|
+
// eslint-disable-next-line complexity
|
|
73
|
+
function buildDecosSet(doc) {
|
|
74
|
+
var _a;
|
|
75
|
+
const contentDecos = {};
|
|
76
|
+
const separatorDecos = {};
|
|
77
|
+
const headings = (0, prosemirror_utils_1.findChildren)(doc, utils_1.isFoldingHeading, true);
|
|
78
|
+
for (const { node, pos } of headings) {
|
|
79
|
+
// don't add decorations to nested hidden headings and its content
|
|
80
|
+
if ((_a = contentDecos[pos]) === null || _a === void 0 ? void 0 : _a.hidden)
|
|
81
|
+
continue;
|
|
82
|
+
const isFolded = (0, utils_1.isFoldedHeading)(node);
|
|
83
|
+
const nodeLevel = (0, utils_1.parseLevel)(node);
|
|
84
|
+
const $pos = doc.resolve(pos + 1);
|
|
85
|
+
const depth = $pos.depth - 1;
|
|
86
|
+
const parent = $pos.node(depth);
|
|
87
|
+
let idx = $pos.index(depth);
|
|
88
|
+
let child = null;
|
|
89
|
+
if (isFolded) {
|
|
90
|
+
while ((child = parent.maybeChild(++idx))) {
|
|
91
|
+
if ((0, utils_1.isHeading)(child) && (0, utils_1.parseLevel)(child) <= nodeLevel)
|
|
92
|
+
break;
|
|
93
|
+
const childPos = $pos.posAtIndex(idx, depth);
|
|
94
|
+
contentDecos[childPos] = {
|
|
95
|
+
from: childPos,
|
|
96
|
+
to: childPos + child.nodeSize,
|
|
97
|
+
hidden: true,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
let hLevel = nodeLevel;
|
|
103
|
+
let nextFoldingHeadingFound = false;
|
|
104
|
+
let hidden = false;
|
|
105
|
+
let lastNonHiddenChild = null;
|
|
106
|
+
while ((child = parent.maybeChild(++idx))) {
|
|
107
|
+
const childPos = $pos.posAtIndex(idx, depth);
|
|
108
|
+
if ((0, utils_1.isHeading)(child)) {
|
|
109
|
+
if ((0, utils_1.isFoldingHeading)(child)) {
|
|
110
|
+
nextFoldingHeadingFound = true;
|
|
111
|
+
}
|
|
112
|
+
const level = (0, utils_1.parseLevel)(child);
|
|
113
|
+
if (level <= nodeLevel)
|
|
114
|
+
break;
|
|
115
|
+
if (!hidden) {
|
|
116
|
+
lastNonHiddenChild = { node: child, pos: childPos, level: hLevel };
|
|
117
|
+
}
|
|
118
|
+
if ((0, utils_1.isUnfoldedHeading)(child)) {
|
|
119
|
+
hLevel = level;
|
|
120
|
+
hidden = false;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
hidden = true;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (!hidden) {
|
|
127
|
+
lastNonHiddenChild = { node: child, pos: childPos, level: hLevel };
|
|
128
|
+
}
|
|
129
|
+
if (!nextFoldingHeadingFound) {
|
|
130
|
+
contentDecos[childPos] = {
|
|
131
|
+
from: childPos,
|
|
132
|
+
to: childPos + child.nodeSize,
|
|
133
|
+
hidden: false,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (lastNonHiddenChild && !separatorDecos[lastNonHiddenChild.pos]) {
|
|
138
|
+
const { pos, node, level } = lastNonHiddenChild;
|
|
139
|
+
separatorDecos[pos] = {
|
|
140
|
+
from: pos,
|
|
141
|
+
to: pos + node.nodeSize,
|
|
142
|
+
value: nodeLevel === level ? 'h' + hLevel : `h${nodeLevel}-h${hLevel}`,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const decorations = [];
|
|
147
|
+
for (const item of Object.values(contentDecos)) {
|
|
148
|
+
const attrs = item.hidden
|
|
149
|
+
? { class: 'pm-h-folding-hidden' }
|
|
150
|
+
: {
|
|
151
|
+
class: 'pm-h-folding-content',
|
|
152
|
+
nodeName: 'div',
|
|
153
|
+
};
|
|
154
|
+
decorations.push(prosemirror_view_1.Decoration.node(item.from, item.to, attrs));
|
|
155
|
+
}
|
|
156
|
+
for (const item of Object.values(separatorDecos)) {
|
|
157
|
+
decorations.push(prosemirror_view_1.Decoration.node(item.from, item.to, {
|
|
158
|
+
nodeName: 'div',
|
|
159
|
+
class: 'pm-h-folding-label',
|
|
160
|
+
'data-value': item.value,
|
|
161
|
+
}), prosemirror_view_1.Decoration.node(item.from, item.to, {
|
|
162
|
+
nodeName: 'div',
|
|
163
|
+
class: 'pm-h-folding-separator',
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
return prosemirror_view_1.DecorationSet.create(doc, decorations);
|
|
167
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
.pm-h-folding-hidden {
|
|
2
|
+
display: none;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.pm-h-folding-content {
|
|
6
|
+
padding-left: 28px;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.pm-h-folding-separator {
|
|
10
|
+
position: relative;
|
|
11
|
+
}
|
|
12
|
+
.pm-h-folding-separator::before {
|
|
13
|
+
position: absolute;
|
|
14
|
+
z-index: 1;
|
|
15
|
+
bottom: -4px;
|
|
16
|
+
left: 0;
|
|
17
|
+
width: 12px;
|
|
18
|
+
height: 12px;
|
|
19
|
+
content: "";
|
|
20
|
+
background-color: var(--g-color-text-secondary);
|
|
21
|
+
mask-image: url('data:image/svg+xml;svg,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16"><path fill="currentColor" fill-rule="evenodd" d="M2 7.25a.75.75 0 0 0 0 1.5h5.69l-2.72 2.72a.75.75 0 1 0 1.06 1.06l4-4a.75.75 0 0 0 0-1.06l-4-4a.75.75 0 0 0-1.06 1.06l2.72 2.72zm7.47 4.22a.75.75 0 1 0 1.06 1.06l4-4a.75.75 0 0 0 0-1.06l-4-4a.75.75 0 1 0-1.06 1.06L12.94 8z" clip-rule="evenodd"/></svg>');
|
|
22
|
+
mask-size: 12px;
|
|
23
|
+
transform: translateY(80%);
|
|
24
|
+
}
|
|
25
|
+
.pm-h-folding-separator::after {
|
|
26
|
+
position: absolute;
|
|
27
|
+
z-index: 1;
|
|
28
|
+
bottom: -8px;
|
|
29
|
+
left: 16px;
|
|
30
|
+
display: block;
|
|
31
|
+
width: calc(100% - 16px - 56px - 6px);
|
|
32
|
+
content: "";
|
|
33
|
+
border-top: 1px dashed var(--g-color-line-generic);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.pm-h-folding-label::after {
|
|
37
|
+
position: absolute;
|
|
38
|
+
z-index: 1;
|
|
39
|
+
right: 2px;
|
|
40
|
+
bottom: -6px;
|
|
41
|
+
display: block;
|
|
42
|
+
padding: 0 8px;
|
|
43
|
+
content: attr(data-value);
|
|
44
|
+
color: var(--g-color-text-misc);
|
|
45
|
+
border-radius: 4px;
|
|
46
|
+
background-color: var(--g-color-base-misc-medium-hover);
|
|
47
|
+
transform: translate(0, 50%);
|
|
48
|
+
font-size: var(--g-text-body-1-font-size);
|
|
49
|
+
line-height: var(--g-text-body-1-line-height);
|
|
50
|
+
font-weight: var(--g-text-body-font-weight);
|
|
51
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Node } from 'prosemirror-model';
|
|
2
|
+
import type { Selection } from 'prosemirror-state';
|
|
3
|
+
export { headingType } from '../../markdown/Heading/HeadingSpecs';
|
|
4
|
+
export declare const insideHeading: ({ $anchor, $head }: Selection) => boolean;
|
|
5
|
+
export declare const hasFolding: (sel: Selection) => boolean;
|
|
6
|
+
export declare function isHeading(node: Node): boolean;
|
|
7
|
+
export declare function isFoldingHeading(node: Node): boolean;
|
|
8
|
+
export declare function isFoldedHeading(node: Node): boolean;
|
|
9
|
+
export declare function isUnfoldedHeading(node: Node): boolean;
|
|
10
|
+
export declare function parseLevel(node: Node): number;
|