@gravity-ui/markdown-editor 14.7.0 → 14.9.0

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.
Files changed (62) hide show
  1. package/README.md +16 -14
  2. package/build/cjs/bundle/MarkdownEditorView.d.ts +27 -0
  3. package/build/cjs/bundle/MarkdownEditorView.js +19 -2
  4. package/build/cjs/bundle/config/action-names.d.ts +1 -1
  5. package/build/cjs/bundle/config/action-names.js +50 -27
  6. package/build/cjs/bundle/config/index.d.ts +3 -0
  7. package/build/cjs/bundle/config/index.js +3 -0
  8. package/build/cjs/bundle/config/markup.js +3 -0
  9. package/build/cjs/bundle/config/wysiwyg.d.ts +3 -0
  10. package/build/cjs/bundle/toolbar/utils.d.ts +17 -0
  11. package/build/cjs/bundle/toolbar/utils.js +64 -0
  12. package/build/cjs/extensions/markdown/Link/paste-plugin.js +21 -5
  13. package/build/cjs/i18n/menubar/en.json +1 -0
  14. package/build/cjs/i18n/menubar/index.d.ts +2 -1
  15. package/build/cjs/i18n/menubar/ru.json +1 -0
  16. package/build/cjs/markup/codemirror/create.js +24 -11
  17. package/build/cjs/markup/codemirror/smart-reindent/index.d.ts +4 -0
  18. package/build/cjs/markup/codemirror/smart-reindent/index.js +42 -0
  19. package/build/cjs/markup/codemirror/smart-reindent/utils.d.ts +15 -0
  20. package/build/cjs/markup/codemirror/smart-reindent/utils.js +59 -0
  21. package/build/cjs/modules/toolbars/constants.d.ts +13 -0
  22. package/build/cjs/modules/toolbars/constants.js +18 -0
  23. package/build/cjs/modules/toolbars/items.d.ts +127 -0
  24. package/build/cjs/modules/toolbars/items.js +736 -0
  25. package/build/cjs/modules/toolbars/presets.d.ts +6 -0
  26. package/build/cjs/modules/toolbars/presets.js +465 -0
  27. package/build/cjs/modules/toolbars/types.d.ts +62 -0
  28. package/build/cjs/modules/toolbars/types.js +2 -0
  29. package/build/cjs/toolbar/types.d.ts +8 -0
  30. package/build/cjs/toolbar/types.js +2 -0
  31. package/build/cjs/version.js +1 -1
  32. package/build/esm/bundle/MarkdownEditorView.d.ts +27 -0
  33. package/build/esm/bundle/MarkdownEditorView.js +19 -2
  34. package/build/esm/bundle/config/action-names.d.ts +1 -1
  35. package/build/esm/bundle/config/action-names.js +50 -27
  36. package/build/esm/bundle/config/index.d.ts +3 -0
  37. package/build/esm/bundle/config/index.js +3 -0
  38. package/build/esm/bundle/config/markup.js +3 -0
  39. package/build/esm/bundle/config/wysiwyg.d.ts +3 -0
  40. package/build/esm/bundle/toolbar/utils.d.ts +17 -0
  41. package/build/esm/bundle/toolbar/utils.js +59 -0
  42. package/build/esm/extensions/markdown/Link/paste-plugin.js +21 -5
  43. package/build/esm/i18n/menubar/en.json +1 -0
  44. package/build/esm/i18n/menubar/index.d.ts +2 -1
  45. package/build/esm/i18n/menubar/ru.json +1 -0
  46. package/build/esm/markup/codemirror/create.js +24 -11
  47. package/build/esm/markup/codemirror/smart-reindent/index.d.ts +4 -0
  48. package/build/esm/markup/codemirror/smart-reindent/index.js +38 -0
  49. package/build/esm/markup/codemirror/smart-reindent/utils.d.ts +15 -0
  50. package/build/esm/markup/codemirror/smart-reindent/utils.js +55 -0
  51. package/build/esm/modules/toolbars/constants.d.ts +13 -0
  52. package/build/esm/modules/toolbars/constants.js +15 -0
  53. package/build/esm/modules/toolbars/items.d.ts +127 -0
  54. package/build/esm/modules/toolbars/items.js +730 -0
  55. package/build/esm/modules/toolbars/presets.d.ts +6 -0
  56. package/build/esm/modules/toolbars/presets.js +462 -0
  57. package/build/esm/modules/toolbars/types.d.ts +62 -0
  58. package/build/esm/modules/toolbars/types.js +1 -0
  59. package/build/esm/toolbar/types.d.ts +8 -0
  60. package/build/esm/toolbar/types.js +2 -0
  61. package/build/esm/version.js +1 -1
  62. package/package.json +10 -2
@@ -1,3 +1,3 @@
1
- declare const namesObj: Record<"bold" | "mono" | "link" | "italic" | "strike" | "underline" | "mark" | "quote" | "paragraph" | "anchor" | "table" | "image" | "code_inline" | "code_block" | "file" | "checkbox" | "emoji" | "undo" | "redo" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "bulletList" | "orderedList" | "liftListItem" | "sinkListItem" | "yfm_cut" | "yfm_note" | "yfm_block" | "yfm_html_block" | "yfm_layout" | "horizontalrule" | "math_inline" | "math_block" | "tabs" | "mermaid" | "gpt", string>;
1
+ declare const namesObj: Record<"bold" | "colorify" | "mono" | "link" | "italic" | "strike" | "underline" | "mark" | "quote" | "block" | "paragraph" | "cut" | "anchor" | "table" | "image" | "code_inline" | "code_block" | "note" | "file" | "codeBlock" | "checkbox" | "emoji" | "bulletList" | "codeInline" | "filePopup" | "gpt" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "horizontalrule" | "horizontalRule" | "imagePopup" | "liftListItem" | "math_block" | "mathBlock" | "math_inline" | "mathInline" | "mermaid" | "orderedList" | "redo" | "sinkListItem" | "tabs" | "undo" | "yfm_block" | "yfm_cut" | "yfm_html_block" | "htmlBlock" | "yfm_layout" | "layout" | "yfm_note", string>;
2
2
  export declare const ActionName: Readonly<typeof namesObj>;
3
3
  export {};
@@ -1,44 +1,67 @@
1
1
  const names = [
2
- 'undo',
3
- 'redo',
2
+ 'anchor',
4
3
  'bold',
5
- 'italic',
6
- 'underline',
7
- 'strike',
8
- 'mono',
9
- 'mark',
10
- 'paragraph',
4
+ 'bulletList',
5
+ 'checkbox',
6
+ /** @deprecated use codeBlock */
7
+ 'code_block',
8
+ 'codeBlock',
9
+ /** @deprecated use codeInline */
10
+ 'code_inline',
11
+ 'codeInline',
12
+ 'colorify',
13
+ 'emoji',
14
+ 'file',
15
+ 'filePopup',
16
+ 'gpt',
11
17
  'heading1',
12
18
  'heading2',
13
19
  'heading3',
14
20
  'heading4',
15
21
  'heading5',
16
22
  'heading6',
17
- 'bulletList',
18
- 'orderedList',
23
+ /** @deprecated use horizontalRule */
24
+ 'horizontalrule',
25
+ 'horizontalRule',
26
+ 'image',
27
+ 'imagePopup',
28
+ 'italic',
19
29
  'liftListItem',
20
- 'sinkListItem',
21
- 'checkbox',
22
30
  'link',
31
+ 'mark',
32
+ /** @deprecated use mathBlock */
33
+ 'math_block',
34
+ 'mathBlock',
35
+ /** @deprecated use mathInline */
36
+ 'math_inline',
37
+ 'mathInline',
38
+ 'mermaid',
39
+ 'mono',
40
+ 'orderedList',
41
+ 'paragraph',
23
42
  'quote',
24
- 'yfm_cut',
25
- 'yfm_note',
43
+ 'redo',
44
+ 'sinkListItem',
45
+ 'strike',
46
+ 'table',
47
+ 'tabs',
48
+ 'underline',
49
+ 'undo',
50
+ /** @deprecated use block */
26
51
  'yfm_block',
52
+ 'block',
53
+ /** @deprecated use cut */
54
+ 'yfm_cut',
55
+ 'cut',
56
+ /** @deprecated use htmlBlock */
27
57
  'yfm_html_block',
58
+ 'htmlBlock',
59
+ /** @deprecated use layout */
28
60
  'yfm_layout',
29
- 'table',
30
- 'code_inline',
31
- 'code_block',
32
- 'image',
33
- 'horizontalrule',
34
- 'emoji',
35
- 'file',
36
- 'anchor',
37
- 'math_inline',
38
- 'math_block',
39
- 'tabs',
40
- 'mermaid',
41
- 'gpt',
61
+ 'layout',
62
+ /** @deprecated use note */
63
+ 'yfm_note',
64
+ 'note',
42
65
  ];
43
66
  const namesObj = names.reduce((obj, val) => {
44
67
  obj[val] = val;
@@ -1,2 +1,5 @@
1
+ /**
2
+ * @deprecated This file is deprecated. Use ToolbarsPreset instead.
3
+ */
1
4
  export * from './wysiwyg';
2
5
  export * from './markup';
@@ -1,2 +1,5 @@
1
+ /**
2
+ * @deprecated This file is deprecated. Use ToolbarsPreset instead.
3
+ */
1
4
  export * from './wysiwyg';
2
5
  export * from './markup';
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @deprecated This file is deprecated. Use ToolbarsPreset instead.
3
+ */
1
4
  import React from 'react';
2
5
  import { i18n } from '../../i18n/menubar';
3
6
  import { insertHRule, insertLink, insertMermaidDiagram, insertYfmHtmlBlock, insertYfmTable, insertYfmTabs, liftListItem, redo, redoDepth, sinkListItem, toBulletList, toH1, toH2, toH3, toH4, toH5, toH6, toOrderedList, toggleBold, toggleItalic, toggleMarked, toggleMonospace, toggleStrikethrough, toggleUnderline, undo, undoDepth, wrapToBlockquote, wrapToCheckbox, wrapToCodeBlock, wrapToInlineCode, wrapToMathBlock, wrapToMathInline, wrapToYfmCut, wrapToYfmNote, } from '../../markup/commands';
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @deprecated This file is deprecated. Use ToolbarsPreset instead.
3
+ */
1
4
  import { ActionStorage } from 'src/core';
2
5
  import type { SelectionContextConfig, SelectionContextItemData } from '../../extensions/behavior/SelectionContext';
3
6
  import { ToolbarGroupItemData, ToolbarItemData, ToolbarListButtonItemData, ToolbarListItemData, ToolbarSingleItemData } from '../../toolbar';
@@ -0,0 +1,17 @@
1
+ import type { ToolbarsPreset } from '../../modules/toolbars/types';
2
+ import type { MToolbarData, MToolbarItemData, WToolbarData, WToolbarItemData } from '../../toolbar';
3
+ import type { MarkdownEditorViewProps } from '../MarkdownEditorView';
4
+ import { MarkdownEditorPreset } from '../types';
5
+ export declare const createConfig: <T extends MToolbarData | WToolbarData>(editorType: 'wysiwyg' | 'markup', toolbarPreset: ToolbarsPreset | MarkdownEditorPreset, toolbarName: string) => T;
6
+ interface GetToolbarsConfigsArgs {
7
+ toolbarsPreset?: ToolbarsPreset;
8
+ props: Pick<MarkdownEditorViewProps, 'markupToolbarConfig' | 'wysiwygToolbarConfig' | 'wysiwygHiddenActionsConfig' | 'markupHiddenActionsConfig'>;
9
+ preset: MarkdownEditorPreset;
10
+ }
11
+ export declare const getToolbarsConfigs: ({ toolbarsPreset, props, preset }: GetToolbarsConfigsArgs) => {
12
+ wysiwygToolbarConfig: WToolbarData;
13
+ markupToolbarConfig: MToolbarData;
14
+ wysiwygHiddenActionsConfig: WToolbarItemData[];
15
+ markupHiddenActionsConfig: MToolbarItemData[];
16
+ };
17
+ export {};
@@ -0,0 +1,59 @@
1
+ import { ToolbarName } from '../../modules/toolbars/constants';
2
+ import { commonmark, defaultPreset, full, yfm, zero } from '../../modules/toolbars/presets';
3
+ import { ToolbarDataType } from '../../toolbar';
4
+ const defaultPresets = {
5
+ zero,
6
+ commonmark,
7
+ default: defaultPreset,
8
+ yfm,
9
+ full,
10
+ };
11
+ const transformItem = (type, item, id = 'unknown') => {
12
+ var _a;
13
+ if (!item) {
14
+ console.warn(`Toolbar item "${id}" not found, it might not have been added to the items dictionary.`);
15
+ return {};
16
+ }
17
+ const isListButton = item.view.type === ToolbarDataType.ListButton;
18
+ return Object.assign(Object.assign(Object.assign({ type: (_a = item.view.type) !== null && _a !== void 0 ? _a : ToolbarDataType.SingleButton, id, title: item.view.title, hint: item.view.hint, icon: item.view.icon, hotkey: item.view.hotkey }, (isListButton && { withArrow: item.view.withArrow })), (type === 'wysiwyg' && item.wysiwyg && Object.assign({}, item.wysiwyg))), (type === 'markup' && item.markup && Object.assign({}, item.markup)));
19
+ };
20
+ export const createConfig = (editorType, toolbarPreset, toolbarName) => {
21
+ var _a;
22
+ const preset = typeof toolbarPreset === 'string'
23
+ ? defaultPresets[toolbarPreset] || defaultPresets.default
24
+ : toolbarPreset;
25
+ const orders = (_a = preset.orders[toolbarName]) !== null && _a !== void 0 ? _a : [[]];
26
+ const { items } = preset;
27
+ const toolbarData = orders.map((group) => group.map((action) => {
28
+ return typeof action === 'string'
29
+ ? transformItem(editorType, items[action], action)
30
+ : Object.assign(Object.assign({}, transformItem(editorType, items[action.id], action.id)), { data: action.items.map((id) => transformItem(editorType, items[id], id)) });
31
+ }));
32
+ return toolbarData;
33
+ };
34
+ const flattenPreset = (config) => {
35
+ var _a;
36
+ // TODO: @makhnatkin add logic for flatten
37
+ return ((_a = config[0]) !== null && _a !== void 0 ? _a : []);
38
+ };
39
+ export const getToolbarsConfigs = ({ toolbarsPreset, props, preset }) => {
40
+ var _a, _b, _c, _d;
41
+ const wysiwygToolbarConfig = toolbarsPreset
42
+ ? createConfig('wysiwyg', toolbarsPreset, ToolbarName.wysiwygMain)
43
+ : (_a = props.wysiwygToolbarConfig) !== null && _a !== void 0 ? _a : createConfig('wysiwyg', preset, ToolbarName.wysiwygMain);
44
+ const markupToolbarConfig = toolbarsPreset
45
+ ? createConfig('markup', toolbarsPreset, ToolbarName.markupMain)
46
+ : (_b = props.markupToolbarConfig) !== null && _b !== void 0 ? _b : createConfig('markup', preset, ToolbarName.markupMain);
47
+ const wysiwygHiddenActionsConfig = toolbarsPreset
48
+ ? flattenPreset(createConfig('wysiwyg', toolbarsPreset, ToolbarName.wysiwygHidden))
49
+ : (_c = props.wysiwygHiddenActionsConfig) !== null && _c !== void 0 ? _c : flattenPreset(createConfig('wysiwyg', preset, ToolbarName.wysiwygHidden));
50
+ const markupHiddenActionsConfig = toolbarsPreset
51
+ ? flattenPreset(createConfig('markup', toolbarsPreset, ToolbarName.markupHidden))
52
+ : (_d = props.markupHiddenActionsConfig) !== null && _d !== void 0 ? _d : flattenPreset(createConfig('markup', preset, ToolbarName.markupHidden));
53
+ return {
54
+ wysiwygToolbarConfig,
55
+ markupToolbarConfig,
56
+ wysiwygHiddenActionsConfig,
57
+ markupHiddenActionsConfig,
58
+ };
59
+ };
@@ -10,21 +10,37 @@ export function linkPasteEnhance({ markupParser: parser }) {
10
10
  paste(view, e) {
11
11
  const { state, dispatch } = view;
12
12
  const sel = state.selection;
13
+ let tr = null;
13
14
  if (isTextSelection(sel) ||
14
15
  (isNodeSelection(sel) && sel.node.type === imageType(state.schema))) {
15
16
  const { $from, $to } = sel;
16
- if ($from.pos !== $to.pos && $from.sameParent($to)) {
17
+ if ($from.pos === $to.pos) {
17
18
  const url = getUrl(e.clipboardData, parser);
18
19
  if (url) {
19
- const tr = state.tr.addMark($from.pos, $to.pos, linkType(state.schema).create({
20
+ const linkMarkType = linkType(state.schema);
21
+ tr = state.tr.replaceSelectionWith(state.schema.text(url, [
22
+ ...$from
23
+ .marks()
24
+ .filter((mark) => mark.type !== linkMarkType),
25
+ linkMarkType.create({ [LinkAttr.Href]: url }),
26
+ ]), false);
27
+ }
28
+ }
29
+ else if ($from.sameParent($to)) {
30
+ const url = getUrl(e.clipboardData, parser);
31
+ if (url) {
32
+ tr = state.tr.addMark($from.pos, $to.pos, linkType(state.schema).create({
20
33
  [LinkAttr.Href]: url,
21
34
  }));
22
- dispatch(tr.setSelection(TextSelection.create(tr.doc, $to.pos)));
23
- e.preventDefault();
24
- return true;
35
+ tr.setSelection(TextSelection.create(tr.doc, $to.pos));
25
36
  }
26
37
  }
27
38
  }
39
+ if (tr) {
40
+ dispatch(tr.scrollIntoView());
41
+ e.preventDefault();
42
+ return true;
43
+ }
28
44
  return false;
29
45
  },
30
46
  },
@@ -44,6 +44,7 @@
44
44
  "mermaid": "Mermaid",
45
45
  "mono": "Monospace",
46
46
  "more_action": "More action",
47
+ "move_list": "Move list item",
47
48
  "note": "Note",
48
49
  "olist": "Ordered list",
49
50
  "quote": "Quote",
@@ -1,4 +1,4 @@
1
- export declare const i18n: <G extends "bold" | "code" | "colorify" | "mono" | "link" | "italic" | "strike" | "underline" | "mark" | "quote" | "text" | "html" | "cut" | "table" | "image" | "code_inline" | "list" | "heading" | "note" | "file" | "checkbox" | "emoji" | "undo" | "redo" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "math_inline" | "math_block" | "tabs" | "mermaid" | "gpt" | "codeblock" | "math" | "colorify__color_blue" | "colorify__color_default" | "colorify__color_gray" | "colorify__color_green" | "colorify__color_orange" | "colorify__color_red" | "colorify__color_violet" | "colorify__color_yellow" | "colorify__group_text" | "emoji__hint" | "folding-heading" | "folding-heading__hint" | "hrule" | "list__action_lift" | "list__action_sink" | "list_action_disabled" | "more_action" | "olist" | "ulist", S extends string>(key: G | (string extends S ? S : never), params?: {
1
+ export declare const i18n: <G extends "bold" | "code" | "colorify" | "mono" | "link" | "italic" | "strike" | "underline" | "mark" | "quote" | "text" | "html" | "cut" | "table" | "image" | "code_inline" | "list" | "heading" | "note" | "file" | "checkbox" | "emoji" | "gpt" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "math_block" | "math_inline" | "mermaid" | "redo" | "tabs" | "undo" | "codeblock" | "math" | "colorify__color_blue" | "colorify__color_default" | "colorify__color_gray" | "colorify__color_green" | "colorify__color_orange" | "colorify__color_red" | "colorify__color_violet" | "colorify__color_yellow" | "colorify__group_text" | "emoji__hint" | "folding-heading" | "folding-heading__hint" | "hrule" | "list__action_lift" | "list__action_sink" | "list_action_disabled" | "more_action" | "move_list" | "olist" | "ulist", S extends string>(key: G | (string extends S ? S : never), params?: {
2
2
  [key: string]: any;
3
3
  } | undefined) => S extends G ? {
4
4
  bold: string;
@@ -46,6 +46,7 @@ export declare const i18n: <G extends "bold" | "code" | "colorify" | "mono" | "l
46
46
  mermaid: string;
47
47
  mono: string;
48
48
  more_action: string;
49
+ move_list: string;
49
50
  note: string;
50
51
  olist: string;
51
52
  quote: string;
@@ -44,6 +44,7 @@
44
44
  "mermaid": "Mermaid",
45
45
  "mono": "Моноширинный",
46
46
  "more_action": "Другие действия",
47
+ "move_list": "Переместить элемент списка",
47
48
  "note": "Примечание",
48
49
  "olist": "Нумерованный список",
49
50
  "quote": "Цитата",
@@ -14,6 +14,7 @@ import { MarkdownConverter } from './html-to-markdown/converters';
14
14
  import { PairingCharactersExtension } from './pairing-chars';
15
15
  import { ReactRendererFacet } from './react-facet';
16
16
  import { SearchPanelPlugin } from './search-plugin/plugin';
17
+ import { smartReindent } from './smart-reindent';
17
18
  import { yfmLang } from './yfm';
18
19
  export function createCodemirror(params) {
19
20
  const { doc, reactRenderer, onCancel, onScroll, onSubmit, onChange, onDocChange, disabledExtensions = {}, keymaps = [], receiver, yfmLangOptions, extensions: extraExtensions, placeholder: placeholderContent, autocompletion: autocompletionConfig, parseHtmlOnPaste, parseInsertedUrlAsImage, directiveSyntax, } = params;
@@ -70,12 +71,16 @@ export function createCodemirror(params) {
70
71
  var _a;
71
72
  if (!event.clipboardData)
72
73
  return;
74
+ const { from } = editor.state.selection.main;
75
+ const line = editor.state.doc.lineAt(from);
76
+ const currentLine = line.text;
73
77
  // if clipboard contains YFM content - avoid any meddling with pasted content
74
78
  // since text/yfm will contain valid markdown
75
79
  const yfmContent = event.clipboardData.getData(DataTransferType.Yfm);
76
80
  if (yfmContent) {
77
81
  event.preventDefault();
78
- editor.dispatch(editor.state.replaceSelection(yfmContent));
82
+ const reindentedYfmContent = smartReindent(yfmContent, currentLine);
83
+ editor.dispatch(editor.state.replaceSelection(reindentedYfmContent));
79
84
  return;
80
85
  }
81
86
  // checking if a copy buffer content is suitable for convertion
@@ -100,23 +105,31 @@ export function createCodemirror(params) {
100
105
  }
101
106
  if (parsedMarkdownMarkup !== undefined) {
102
107
  event.preventDefault();
103
- editor.dispatch(editor.state.replaceSelection(parsedMarkdownMarkup));
108
+ const reindentedHtmlContent = smartReindent(parsedMarkdownMarkup, currentLine);
109
+ editor.dispatch(editor.state.replaceSelection(reindentedHtmlContent));
104
110
  return;
105
111
  }
106
112
  }
107
113
  if (parseInsertedUrlAsImage) {
108
114
  const { imageUrl, title } = parseInsertedUrlAsImage((_a = event.clipboardData.getData(DataTransferType.Text)) !== null && _a !== void 0 ? _a : '') || {};
109
- if (!imageUrl) {
110
- return;
115
+ if (imageUrl) {
116
+ event.preventDefault();
117
+ insertImages([
118
+ {
119
+ url: imageUrl,
120
+ alt: title,
121
+ title,
122
+ },
123
+ ])(editor);
111
124
  }
125
+ }
126
+ // Reindenting pasted plain text
127
+ const pastedText = event.clipboardData.getData(DataTransferType.Text);
128
+ const reindentedText = smartReindent(pastedText, currentLine);
129
+ // but only if there is a need for reindentation
130
+ if (pastedText !== reindentedText) {
131
+ editor.dispatch(editor.state.replaceSelection(reindentedText));
112
132
  event.preventDefault();
113
- insertImages([
114
- {
115
- url: imageUrl,
116
- alt: title,
117
- title,
118
- },
119
- ])(editor);
120
133
  }
121
134
  },
122
135
  }), SearchPanelPlugin({
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Reindents pasted text based on the current line's markers
3
+ */
4
+ export declare function smartReindent(pastedText: string, currentLineText: string): string;
@@ -0,0 +1,38 @@
1
+ import { parseMarkers } from './utils';
2
+ /**
3
+ * Reindents pasted text based on the current line's markers
4
+ */
5
+ export function smartReindent(pastedText, currentLineText) {
6
+ // If current line is empty, return pasted text as is
7
+ if (currentLineText.length === 0) {
8
+ return pastedText;
9
+ }
10
+ // Get markers from current line
11
+ const markers = parseMarkers(currentLineText);
12
+ // If no markers found, return pasted text as is
13
+ if (markers.length === 0) {
14
+ return pastedText;
15
+ }
16
+ // Create indentation for subsequent lines by replacing list markers with spaces
17
+ const subsequentIndent = markers
18
+ .map((marker) => {
19
+ if (marker.match(/^\d{1,6}\. |-|\*|\+/)) {
20
+ return ' '.repeat(marker.length);
21
+ }
22
+ return marker;
23
+ })
24
+ .join('');
25
+ // Split and process the pasted text
26
+ const lines = pastedText.split('\n');
27
+ const reindentedText = lines
28
+ .map((line, index) => {
29
+ // First line doesn't need indentation
30
+ if (index === 0) {
31
+ return line;
32
+ }
33
+ // Add indentation to all subsequent lines, including empty ones
34
+ return subsequentIndent + line;
35
+ })
36
+ .join('\n');
37
+ return reindentedText;
38
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Parses markdown-style markers from the start of a line
3
+ * Returns an array of markers found:
4
+ * - ' ' for indentation
5
+ * - '> ' for blockquotes
6
+ * - '* ' or '- ' for list items
7
+ * - '1. ' for numbered lists
8
+ *
9
+ * Example inputs:
10
+ * " * list" -> [' ', '* ']
11
+ * "> quoted" -> ['> ']
12
+ * " nested" -> [' ', ' ']
13
+ * "1. list" -> ['1. ']
14
+ */
15
+ export declare function parseMarkers(text: string): string[];
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Parses markdown-style markers from the start of a line
3
+ * Returns an array of markers found:
4
+ * - ' ' for indentation
5
+ * - '> ' for blockquotes
6
+ * - '* ' or '- ' for list items
7
+ * - '1. ' for numbered lists
8
+ *
9
+ * Example inputs:
10
+ * " * list" -> [' ', '* ']
11
+ * "> quoted" -> ['> ']
12
+ * " nested" -> [' ', ' ']
13
+ * "1. list" -> ['1. ']
14
+ */
15
+ export function parseMarkers(text) {
16
+ const markers = [];
17
+ let pos = 0;
18
+ while (pos < text.length) {
19
+ // Handle code block (4 spaces)
20
+ if (pos + 3 < text.length &&
21
+ text[pos] === ' ' &&
22
+ text[pos + 1] === ' ' &&
23
+ text[pos + 2] === ' ' &&
24
+ text[pos + 3] === ' ') {
25
+ markers.push(' ');
26
+ pos += 4;
27
+ continue;
28
+ }
29
+ // Handle numbered lists (1-6 digits followed by dot and space)
30
+ if (/^\d{1,6}\. /.test(text.slice(pos))) {
31
+ const match = text.slice(pos).match(/^(\d{1,6}\. )/);
32
+ if (match) {
33
+ markers.push(match[1]);
34
+ pos += match[1].length;
35
+ continue;
36
+ }
37
+ }
38
+ // Handle block quotes and list markers
39
+ if (text[pos] === '>' || text[pos] === '-' || text[pos] === '*' || text[pos] === '+') {
40
+ if (pos + 1 < text.length && text[pos + 1] === ' ') {
41
+ markers.push(text[pos] + ' ');
42
+ pos += 2;
43
+ continue;
44
+ }
45
+ }
46
+ // Handle single space (last priority)
47
+ if (text[pos] === ' ') {
48
+ markers.push(' ');
49
+ pos += 1;
50
+ continue;
51
+ }
52
+ break;
53
+ }
54
+ return markers;
55
+ }
@@ -0,0 +1,13 @@
1
+ export declare enum ListName {
2
+ heading = "heading",
3
+ lists = "lists",
4
+ code = "code"
5
+ }
6
+ export declare enum ToolbarName {
7
+ markupHidden = "markupHidden",
8
+ markupMain = "markupMain",
9
+ wysiwygHidden = "wysiwygHidden",
10
+ wysiwygMain = "wysiwygMain",
11
+ wysiwygSelection = "wysiwygSelection",
12
+ wysiwygSlash = "wysiwygSlash"
13
+ }
@@ -0,0 +1,15 @@
1
+ export var ListName;
2
+ (function (ListName) {
3
+ ListName["heading"] = "heading";
4
+ ListName["lists"] = "lists";
5
+ ListName["code"] = "code";
6
+ })(ListName || (ListName = {}));
7
+ export var ToolbarName;
8
+ (function (ToolbarName) {
9
+ ToolbarName["markupHidden"] = "markupHidden";
10
+ ToolbarName["markupMain"] = "markupMain";
11
+ ToolbarName["wysiwygHidden"] = "wysiwygHidden";
12
+ ToolbarName["wysiwygMain"] = "wysiwygMain";
13
+ ToolbarName["wysiwygSelection"] = "wysiwygSelection";
14
+ ToolbarName["wysiwygSlash"] = "wysiwygSlash";
15
+ })(ToolbarName || (ToolbarName = {}));
@@ -0,0 +1,127 @@
1
+ import { ToolbarDataType } from '../../toolbar';
2
+ import { ToolbarItemMarkup, ToolbarItemView, ToolbarItemWysiwyg } from './types';
3
+ export declare const undoItemView: ToolbarItemView;
4
+ export declare const undoItemWysiwyg: ToolbarItemWysiwyg;
5
+ export declare const undoItemMarkup: ToolbarItemMarkup;
6
+ export declare const redoItemView: ToolbarItemView;
7
+ export declare const redoItemWysiwyg: ToolbarItemWysiwyg;
8
+ export declare const redoItemMarkup: ToolbarItemMarkup;
9
+ export declare const boldItemView: ToolbarItemView;
10
+ export declare const boldItemWysiwyg: ToolbarItemWysiwyg;
11
+ export declare const boldItemMarkup: ToolbarItemMarkup;
12
+ export declare const italicItemView: ToolbarItemView;
13
+ export declare const italicItemWysiwyg: ToolbarItemWysiwyg;
14
+ export declare const italicItemMarkup: ToolbarItemMarkup;
15
+ export declare const underlineItemView: ToolbarItemView;
16
+ export declare const underlineItemWysiwyg: ToolbarItemWysiwyg;
17
+ export declare const underlineItemMarkup: ToolbarItemMarkup;
18
+ export declare const strikethroughItemView: ToolbarItemView;
19
+ export declare const strikethroughItemWysiwyg: ToolbarItemWysiwyg;
20
+ export declare const strikethroughItemMarkup: ToolbarItemMarkup;
21
+ export declare const monospaceItemView: ToolbarItemView;
22
+ export declare const monospaceItemWysiwyg: ToolbarItemWysiwyg;
23
+ export declare const monospaceItemMarkup: ToolbarItemMarkup;
24
+ export declare const markedItemView: ToolbarItemView;
25
+ export declare const markedItemWysiwyg: ToolbarItemWysiwyg;
26
+ export declare const markedItemMarkup: ToolbarItemMarkup;
27
+ export declare const checkboxItemView: ToolbarItemView;
28
+ export declare const checkboxItemWysiwyg: ToolbarItemWysiwyg;
29
+ export declare const checkboxItemMarkup: ToolbarItemMarkup;
30
+ export declare const linkItemView: ToolbarItemView;
31
+ export declare const linkItemWysiwyg: ToolbarItemWysiwyg;
32
+ export declare const linkItemMarkup: ToolbarItemMarkup;
33
+ export declare const quoteItemView: ToolbarItemView;
34
+ export declare const quoteItemWysiwyg: ToolbarItemWysiwyg;
35
+ export declare const quoteItemMarkup: ToolbarItemMarkup;
36
+ export declare const cutItemView: ToolbarItemView;
37
+ export declare const cutItemWysiwyg: ToolbarItemWysiwyg;
38
+ export declare const cutItemMarkup: ToolbarItemMarkup;
39
+ export declare const noteItemView: ToolbarItemView;
40
+ export declare const noteItemWysiwyg: ToolbarItemWysiwyg;
41
+ export declare const noteItemMarkup: ToolbarItemMarkup;
42
+ export declare const tableItemView: ToolbarItemView;
43
+ export declare const tableItemWysiwyg: ToolbarItemWysiwyg;
44
+ export declare const tableItemMarkup: ToolbarItemMarkup;
45
+ export declare const codeItemView: ToolbarItemView;
46
+ export declare const codeItemWysiwyg: ToolbarItemWysiwyg;
47
+ export declare const codeItemMarkup: ToolbarItemMarkup;
48
+ export declare const imageItemView: ToolbarItemView;
49
+ export declare const imagePopupItemView: ToolbarItemView;
50
+ export declare const imageItemWysiwyg: ToolbarItemWysiwyg;
51
+ export declare const imageItemMarkup: ToolbarItemMarkup<ToolbarDataType.ButtonPopup>;
52
+ export declare const fileItemView: ToolbarItemView;
53
+ export declare const filePopupItemView: ToolbarItemView;
54
+ export declare const fileItemWysiwyg: ToolbarItemWysiwyg;
55
+ export declare const fileItemMarkup: ToolbarItemMarkup<ToolbarDataType.ButtonPopup>;
56
+ export declare const tabsItemView: ToolbarItemView;
57
+ export declare const tabsItemWysiwyg: ToolbarItemWysiwyg;
58
+ export declare const tabsItemMarkup: ToolbarItemMarkup;
59
+ export declare const mathInlineItemView: ToolbarItemView;
60
+ export declare const mathInlineItemWysiwyg: ToolbarItemWysiwyg;
61
+ export declare const mathInlineItemMarkup: ToolbarItemMarkup;
62
+ export declare const mathBlockItemView: ToolbarItemView;
63
+ export declare const mathBlockItemWysiwyg: ToolbarItemWysiwyg;
64
+ export declare const mathBlockItemMarkup: ToolbarItemMarkup;
65
+ export declare const yfmHtmlBlockItemView: ToolbarItemView;
66
+ export declare const yfmHtmlBlockItemWysiwyg: ToolbarItemWysiwyg;
67
+ export declare const yfmHtmlBlockItemMarkup: ToolbarItemMarkup;
68
+ export declare const mermaidItemView: ToolbarItemView;
69
+ export declare const mermaidItemWysiwyg: ToolbarItemWysiwyg;
70
+ export declare const mermaidItemMarkup: ToolbarItemMarkup;
71
+ export declare const codeBlockItemView: ToolbarItemView;
72
+ export declare const codeBlockItemWysiwyg: ToolbarItemWysiwyg;
73
+ export declare const codeBlockItemMarkup: ToolbarItemMarkup;
74
+ export declare const hruleItemView: ToolbarItemView;
75
+ export declare const hruleItemWysiwyg: ToolbarItemWysiwyg;
76
+ export declare const hruleItemMarkup: ToolbarItemMarkup;
77
+ export declare const emojiItemView: ToolbarItemView;
78
+ export declare const emojiItemWysiwyg: ToolbarItemWysiwyg;
79
+ export declare const emojiItemMarkup: ToolbarItemMarkup;
80
+ export declare const heading1ItemView: ToolbarItemView;
81
+ export declare const heading1ItemWysiwyg: ToolbarItemWysiwyg;
82
+ export declare const heading1ItemMarkup: ToolbarItemMarkup;
83
+ export declare const heading2ItemView: ToolbarItemView;
84
+ export declare const heading2ItemWysiwyg: ToolbarItemWysiwyg;
85
+ export declare const heading2ItemMarkup: ToolbarItemMarkup;
86
+ export declare const heading3ItemView: ToolbarItemView;
87
+ export declare const heading3ItemWysiwyg: ToolbarItemWysiwyg;
88
+ export declare const heading3ItemMarkup: ToolbarItemMarkup;
89
+ export declare const heading4ItemView: ToolbarItemView;
90
+ export declare const heading4ItemWysiwyg: ToolbarItemWysiwyg;
91
+ export declare const heading4ItemMarkup: ToolbarItemMarkup;
92
+ export declare const heading5ItemView: ToolbarItemView;
93
+ export declare const heading5ItemWysiwyg: ToolbarItemWysiwyg;
94
+ export declare const heading5ItemMarkup: ToolbarItemMarkup;
95
+ export declare const heading6ItemView: ToolbarItemView;
96
+ export declare const heading6ItemWysiwyg: ToolbarItemWysiwyg;
97
+ export declare const heading6ItemMarkup: ToolbarItemMarkup;
98
+ export declare const bulletListItemView: ToolbarItemView;
99
+ export declare const bulletListItemWysiwyg: ToolbarItemWysiwyg;
100
+ export declare const bulletListItemMarkup: ToolbarItemMarkup;
101
+ export declare const orderedListItemView: ToolbarItemView;
102
+ export declare const orderedListItemWysiwyg: ToolbarItemWysiwyg;
103
+ export declare const orderedListItemMarkup: ToolbarItemMarkup;
104
+ export declare const sinkListItemView: ToolbarItemView;
105
+ export declare const sinkListItemWysiwyg: ToolbarItemWysiwyg;
106
+ export declare const sinkListItemMarkup: ToolbarItemMarkup;
107
+ export declare const liftListItemView: ToolbarItemView;
108
+ export declare const liftListItemWysiwyg: ToolbarItemWysiwyg;
109
+ export declare const liftListItemMarkup: ToolbarItemMarkup;
110
+ export declare const toggleHeadingFoldingItemView: ToolbarItemView;
111
+ export declare const toggleHeadingFoldingItemWysiwyg: ToolbarItemWysiwyg;
112
+ export declare const textContextItemView: ToolbarItemView<ToolbarDataType.ReactComponent>;
113
+ export declare const textContextItemWisywig: ToolbarItemWysiwyg<ToolbarDataType.ReactComponent>;
114
+ export declare const paragraphItemView: ToolbarItemView;
115
+ export declare const paragraphItemWisywig: ToolbarItemWysiwyg;
116
+ export declare const paragraphItemMarkup: ToolbarItemMarkup;
117
+ export declare const colorifyItemView: ToolbarItemView<ToolbarDataType.ReactComponent>;
118
+ export declare const colorifyItemWysiwyg: ToolbarItemWysiwyg<ToolbarDataType.ReactComponent>;
119
+ export declare const colorifyItemMarkup: ToolbarItemMarkup<ToolbarDataType.ReactComponent>;
120
+ export declare const gptItemView: ToolbarItemView;
121
+ export declare const gptItemWysiwyg: ToolbarItemWysiwyg;
122
+ export declare const gptItemMarkup: ToolbarItemMarkup;
123
+ export declare const headingListItemView: ToolbarItemView<ToolbarDataType.ListButton>;
124
+ export declare const listsListItemView: ToolbarItemView<ToolbarDataType.ListButton>;
125
+ export declare const moveListItemView: ToolbarItemView<ToolbarDataType.ListButton>;
126
+ export declare const codeBlocksListItemView: ToolbarItemView<ToolbarDataType.ListButton>;
127
+ export declare const mathListItemView: ToolbarItemView<ToolbarDataType.ListButton>;