@gravity-ui/markdown-editor 14.5.1 → 14.7.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.
- package/build/cjs/bundle/config/wysiwyg.d.ts +0 -1
- package/build/cjs/bundle/config/wysiwyg.js +2 -13
- package/build/cjs/bundle/toolbar/ToolbarButtonWithPopupMenu.d.ts +4 -0
- package/build/cjs/bundle/toolbar/ToolbarButtonWithPopupMenu.js +11 -5
- package/build/cjs/bundle/toolbar/custom/ToolbarColors.css +42 -0
- package/build/cjs/bundle/toolbar/custom/ToolbarColors.js +1 -1
- package/build/cjs/bundle/types.d.ts +11 -0
- package/build/cjs/bundle/useMarkdownEditor.js +1 -1
- package/build/cjs/bundle/wysiwyg-preset.d.ts +2 -1
- package/build/cjs/bundle/wysiwyg-preset.js +12 -2
- package/build/cjs/extensions/additional/GPT/index.d.ts +1 -1
- package/build/cjs/extensions/additional/GPT/index.js +1 -1
- package/build/cjs/extensions/additional/GPT/{toolbar.d.ts → wGptItemData.d.ts} +1 -1
- package/build/cjs/extensions/additional/GPT/{toolbar.js → wGptItemData.js} +2 -2
- package/build/cjs/extensions/behavior/Cursor/gapcursor.js +12 -0
- package/build/cjs/extensions/behavior/Cursor/index.js +1 -1
- package/build/cjs/extensions/yfm/Checkbox/CheckboxSpecs/const.d.ts +3 -0
- package/build/cjs/extensions/yfm/Checkbox/CheckboxSpecs/const.js +5 -1
- package/build/cjs/extensions/yfm/Checkbox/CheckboxSpecs/index.d.ts +1 -4
- package/build/cjs/extensions/yfm/Checkbox/CheckboxSpecs/index.js +5 -6
- package/build/cjs/extensions/yfm/Checkbox/CheckboxSpecs/schema.d.ts +2 -2
- package/build/cjs/extensions/yfm/Checkbox/CheckboxSpecs/schema.js +41 -4
- package/build/cjs/extensions/yfm/Checkbox/index.js +2 -0
- package/build/cjs/extensions/yfm/Checkbox/plugins/fix-paste.d.ts +2 -0
- package/build/cjs/extensions/yfm/Checkbox/plugins/fix-paste.js +22 -0
- package/build/cjs/utils/schema.d.ts +1 -1
- package/build/cjs/version.js +1 -1
- package/build/esm/bundle/config/wysiwyg.d.ts +0 -1
- package/build/esm/bundle/config/wysiwyg.js +0 -11
- package/build/esm/bundle/toolbar/ToolbarButtonWithPopupMenu.d.ts +4 -0
- package/build/esm/bundle/toolbar/ToolbarButtonWithPopupMenu.js +11 -5
- package/build/esm/bundle/toolbar/custom/ToolbarColors.css +42 -0
- package/build/esm/bundle/toolbar/custom/ToolbarColors.js +1 -1
- package/build/esm/bundle/types.d.ts +11 -0
- package/build/esm/bundle/useMarkdownEditor.js +1 -1
- package/build/esm/bundle/wysiwyg-preset.d.ts +2 -1
- package/build/esm/bundle/wysiwyg-preset.js +12 -2
- package/build/esm/extensions/additional/GPT/index.d.ts +1 -1
- package/build/esm/extensions/additional/GPT/index.js +1 -1
- package/build/esm/extensions/additional/GPT/{toolbar.d.ts → wGptItemData.d.ts} +1 -1
- package/build/esm/extensions/additional/GPT/{toolbar.js → wGptItemData.js} +1 -1
- package/build/esm/extensions/behavior/Cursor/gapcursor.js +13 -1
- package/build/esm/extensions/behavior/Cursor/index.js +1 -1
- package/build/esm/extensions/yfm/Checkbox/CheckboxSpecs/const.d.ts +3 -0
- package/build/esm/extensions/yfm/Checkbox/CheckboxSpecs/const.js +4 -0
- package/build/esm/extensions/yfm/Checkbox/CheckboxSpecs/index.d.ts +1 -4
- package/build/esm/extensions/yfm/Checkbox/CheckboxSpecs/index.js +1 -5
- package/build/esm/extensions/yfm/Checkbox/CheckboxSpecs/schema.d.ts +2 -2
- package/build/esm/extensions/yfm/Checkbox/CheckboxSpecs/schema.js +42 -5
- package/build/esm/extensions/yfm/Checkbox/index.js +2 -0
- package/build/esm/extensions/yfm/Checkbox/plugins/fix-paste.d.ts +2 -0
- package/build/esm/extensions/yfm/Checkbox/plugins/fix-paste.js +18 -0
- package/build/esm/utils/schema.d.ts +1 -1
- package/build/esm/version.js +1 -1
- package/build/styles.css +42 -0
- package/package.json +4 -4
|
@@ -34,7 +34,6 @@ export declare const wTabsItemData: WToolbarSingleItemData;
|
|
|
34
34
|
export declare const wMathInlineItemData: WToolbarSingleItemData;
|
|
35
35
|
export declare const wMathBlockItemData: WToolbarSingleItemData;
|
|
36
36
|
export declare const wYfmHtmlBlockItemData: WToolbarSingleItemData;
|
|
37
|
-
export declare const wGptItemData: WToolbarSingleItemData;
|
|
38
37
|
export declare const wMermaidItemData: WToolbarSingleItemData;
|
|
39
38
|
export declare const wCodeBlockItemData: WToolbarItemData;
|
|
40
39
|
export declare const wHruleItemData: WToolbarItemData;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.wToolbarConfig = exports.wBiusGroupConfig = exports.wHistoryGroupConfig = exports.wHiddenData = exports.wCommandMenuConfig = exports.wMathListConfig = exports.wCodeListConfig = exports.wListMoveListConfig = exports.wListsListConfig = exports.wHeadingListConfig = exports.wLiftListItemData = exports.wSinkListItemData = exports.wOrderedListItemData = exports.wBulletListItemData = exports.wHeading6ItemData = exports.wHeading5ItemData = exports.wHeading4ItemData = exports.wHeading3ItemData = exports.wHeading2ItemData = exports.wHeading1ItemData = exports.wTextItemData = exports.wMathListItem = exports.textContextItemData = exports.wToggleHeadingFoldingItemData = exports.wEmojiItemData = exports.wHruleItemData = exports.wCodeBlockItemData = exports.wMermaidItemData = exports.
|
|
4
|
-
exports.wSelectionMenuConfigByPreset = exports.wHiddenDataByPreset = exports.wCommandMenuConfigByPreset = exports.wToolbarConfigByPreset =
|
|
3
|
+
exports.wSelectionMenuConfig = exports.wToolbarConfig = exports.wBiusGroupConfig = exports.wHistoryGroupConfig = exports.wHiddenData = exports.wCommandMenuConfig = exports.wMathListConfig = exports.wCodeListConfig = exports.wListMoveListConfig = exports.wListsListConfig = exports.wHeadingListConfig = exports.wLiftListItemData = exports.wSinkListItemData = exports.wOrderedListItemData = exports.wBulletListItemData = exports.wHeading6ItemData = exports.wHeading5ItemData = exports.wHeading4ItemData = exports.wHeading3ItemData = exports.wHeading2ItemData = exports.wHeading1ItemData = exports.wTextItemData = exports.wMathListItem = exports.textContextItemData = exports.wToggleHeadingFoldingItemData = exports.wEmojiItemData = exports.wHruleItemData = exports.wCodeBlockItemData = exports.wMermaidItemData = exports.wYfmHtmlBlockItemData = exports.wMathBlockItemData = exports.wMathInlineItemData = exports.wTabsItemData = exports.wFileItemData = exports.wImageItemData = exports.wCodeItemData = exports.wTableItemData = exports.wNoteItemData = exports.wCutItemData = exports.wQuoteItemData = exports.wLinkItemData = exports.wCheckboxItemData = exports.wMarkedItemData = exports.wMonospaceItemData = exports.wStrikethroughItemData = exports.wUnderlineItemData = exports.wItalicItemData = exports.wBoldItemData = exports.wRedoItemData = exports.wUndoItemData = void 0;
|
|
4
|
+
exports.wSelectionMenuConfigByPreset = exports.wHiddenDataByPreset = exports.wCommandMenuConfigByPreset = exports.wToolbarConfigByPreset = void 0;
|
|
5
5
|
const extensions_1 = require("../../extensions");
|
|
6
|
-
const constants_1 = require("../../extensions/additional/GPT/constants");
|
|
7
6
|
const hints_1 = require("../../i18n/hints");
|
|
8
7
|
const menubar_1 = require("../../i18n/menubar");
|
|
9
8
|
const shortcuts_1 = require("../../shortcuts");
|
|
@@ -218,16 +217,6 @@ exports.wYfmHtmlBlockItemData = {
|
|
|
218
217
|
isActive: (e) => e.actions.createYfmHtmlBlock.isActive(),
|
|
219
218
|
isEnable: (e) => e.actions.createYfmHtmlBlock.isEnable(),
|
|
220
219
|
};
|
|
221
|
-
exports.wGptItemData = {
|
|
222
|
-
id: action_names_1.ActionName.gpt,
|
|
223
|
-
type: toolbar_1.ToolbarDataType.SingleButton,
|
|
224
|
-
title: menubar_1.i18n.bind(null, 'gpt'),
|
|
225
|
-
hotkey: constants_1.gptHotKeys.openGptKeyTooltip,
|
|
226
|
-
icon: icons_1.icons.gpt,
|
|
227
|
-
exec: (e) => e.actions.addGptWidget.run({}),
|
|
228
|
-
isActive: (e) => e.actions.addGptWidget.isActive(),
|
|
229
|
-
isEnable: (e) => e.actions.addGptWidget.isEnable(),
|
|
230
|
-
};
|
|
231
220
|
exports.wMermaidItemData = {
|
|
232
221
|
id: action_names_1.ActionName.mermaid,
|
|
233
222
|
type: toolbar_1.ToolbarDataType.SingleButton,
|
|
@@ -14,7 +14,11 @@ export declare type MenuItem = {
|
|
|
14
14
|
};
|
|
15
15
|
export declare type ToolbarButtonWithPopupMenuProps = Omit<ToolbarBaseProps<ActionStorage> & {
|
|
16
16
|
icon: ToolbarIconData;
|
|
17
|
+
iconClassName?: string;
|
|
18
|
+
chevronIconClassName?: string;
|
|
17
19
|
title: string | (() => string);
|
|
18
20
|
menuItems: MenuItem[];
|
|
21
|
+
/** @default 'classic' */
|
|
22
|
+
_selectionType?: 'classic' | 'light';
|
|
19
23
|
}, 'editor'>;
|
|
20
24
|
export declare const ToolbarButtonWithPopupMenu: React.FC<ToolbarButtonWithPopupMenuProps>;
|
|
@@ -10,10 +10,10 @@ const lodash_1 = require("../../lodash");
|
|
|
10
10
|
const hooks_1 = require("../../react-utils/hooks");
|
|
11
11
|
const toolbar_1 = require("../../toolbar");
|
|
12
12
|
const b = (0, classname_1.cn)('toolbar-button-with-popup-menu');
|
|
13
|
-
const ToolbarButtonWithPopupMenu = ({ className, focus, onClick, icon, title, menuItems, }) => {
|
|
13
|
+
const ToolbarButtonWithPopupMenu = ({ className, focus, onClick, icon, iconClassName, chevronIconClassName, title, menuItems, _selectionType, }) => {
|
|
14
14
|
const buttonRef = react_1.default.useRef(null);
|
|
15
15
|
const [open, , hide, toggleOpen] = (0, hooks_1.useBooleanState)(false);
|
|
16
|
-
const groups = react_1.default.useMemo(() => (0, lodash_1.groupBy)(menuItems.map((i) => (Object.assign(Object.assign({}, i), { group: i.group || '' }))), 'group'), [menuItems
|
|
16
|
+
const groups = react_1.default.useMemo(() => (0, lodash_1.groupBy)(menuItems.map((i) => (Object.assign(Object.assign({}, i), { group: i.group || '' }))), 'group'), [menuItems]);
|
|
17
17
|
const someActive = menuItems.some((item) => !item.ignoreActive && item.action.isActive() === true);
|
|
18
18
|
const everyDisabled = menuItems.every((item) => item.action.isEnable() === false);
|
|
19
19
|
const popupOpen = everyDisabled ? false : open;
|
|
@@ -23,12 +23,18 @@ const ToolbarButtonWithPopupMenu = ({ className, focus, onClick, icon, title, me
|
|
|
23
23
|
hide();
|
|
24
24
|
}
|
|
25
25
|
}, [hide, shouldForceHide]);
|
|
26
|
+
const [btnView, btnSelected] = _selectionType === 'light'
|
|
27
|
+
? [
|
|
28
|
+
popupOpen ? 'normal' : someActive ? 'flat-action' : 'flat',
|
|
29
|
+
popupOpen && someActive,
|
|
30
|
+
]
|
|
31
|
+
: [someActive || popupOpen ? 'normal' : 'flat', someActive];
|
|
26
32
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
27
33
|
react_1.default.createElement(uikit_1.ActionTooltip, { disabled: popupOpen, openDelay: toolbar_1.ToolbarTooltipDelay.Open, closeDelay: toolbar_1.ToolbarTooltipDelay.Close, title: (0, lodash_1.isFunction)(title) ? title() : title },
|
|
28
|
-
react_1.default.createElement(uikit_1.Button, { size: "m", ref: buttonRef, view:
|
|
29
|
-
react_1.default.createElement(uikit_1.Icon, { data: icon.data, size: icon.size }),
|
|
34
|
+
react_1.default.createElement(uikit_1.Button, { size: "m", ref: buttonRef, view: btnView, selected: btnSelected, disabled: everyDisabled, className: b(null, [className]), onClick: toggleOpen },
|
|
35
|
+
react_1.default.createElement(uikit_1.Icon, { data: icon.data, size: icon.size, className: iconClassName }),
|
|
30
36
|
'',
|
|
31
|
-
react_1.default.createElement(uikit_1.Icon, { data: icons_1.ChevronDown }))),
|
|
37
|
+
react_1.default.createElement(uikit_1.Icon, { data: icons_1.ChevronDown, className: chevronIconClassName }))),
|
|
32
38
|
react_1.default.createElement(uikit_1.Popup, { anchorRef: buttonRef, open: popupOpen, onClose: hide },
|
|
33
39
|
react_1.default.createElement(uikit_1.Menu, { size: "l" }, Object.entries(groups).map(([label, items], key) => {
|
|
34
40
|
return (react_1.default.createElement(uikit_1.Menu.Group, { label: label, key: key, className: b('menu-group') }, items.map(({ id, icon, iconSize = 16, action, text, iconClassname }) => (react_1.default.createElement(uikit_1.Menu.Item, { key: id, icon: react_1.default.createElement(uikit_1.Icon, { data: icon, size: iconSize, className: iconClassname }), active: action.isActive(), disabled: !action.isEnable(), onClick: () => {
|
|
@@ -1,21 +1,63 @@
|
|
|
1
|
+
.g-md-toolbar-colors__menu-icon_color_gray {
|
|
2
|
+
color: var(--yfm-colorify-gray);
|
|
3
|
+
}
|
|
4
|
+
.g-md-toolbar-colors__chevron-icon_color_gray {
|
|
5
|
+
color: var(--yfm-colorify-gray);
|
|
6
|
+
}
|
|
1
7
|
.g-md-toolbar-colors__item-icon_color_gray {
|
|
2
8
|
color: var(--yfm-colorify-gray);
|
|
3
9
|
}
|
|
10
|
+
.g-md-toolbar-colors__menu-icon_color_yellow {
|
|
11
|
+
color: var(--yfm-colorify-yellow);
|
|
12
|
+
}
|
|
13
|
+
.g-md-toolbar-colors__chevron-icon_color_yellow {
|
|
14
|
+
color: var(--yfm-colorify-yellow);
|
|
15
|
+
}
|
|
4
16
|
.g-md-toolbar-colors__item-icon_color_yellow {
|
|
5
17
|
color: var(--yfm-colorify-yellow);
|
|
6
18
|
}
|
|
19
|
+
.g-md-toolbar-colors__menu-icon_color_orange {
|
|
20
|
+
color: var(--yfm-colorify-orange);
|
|
21
|
+
}
|
|
22
|
+
.g-md-toolbar-colors__chevron-icon_color_orange {
|
|
23
|
+
color: var(--yfm-colorify-orange);
|
|
24
|
+
}
|
|
7
25
|
.g-md-toolbar-colors__item-icon_color_orange {
|
|
8
26
|
color: var(--yfm-colorify-orange);
|
|
9
27
|
}
|
|
28
|
+
.g-md-toolbar-colors__menu-icon_color_red {
|
|
29
|
+
color: var(--yfm-colorify-red);
|
|
30
|
+
}
|
|
31
|
+
.g-md-toolbar-colors__chevron-icon_color_red {
|
|
32
|
+
color: var(--yfm-colorify-red);
|
|
33
|
+
}
|
|
10
34
|
.g-md-toolbar-colors__item-icon_color_red {
|
|
11
35
|
color: var(--yfm-colorify-red);
|
|
12
36
|
}
|
|
37
|
+
.g-md-toolbar-colors__menu-icon_color_green {
|
|
38
|
+
color: var(--yfm-colorify-green);
|
|
39
|
+
}
|
|
40
|
+
.g-md-toolbar-colors__chevron-icon_color_green {
|
|
41
|
+
color: var(--yfm-colorify-green);
|
|
42
|
+
}
|
|
13
43
|
.g-md-toolbar-colors__item-icon_color_green {
|
|
14
44
|
color: var(--yfm-colorify-green);
|
|
15
45
|
}
|
|
46
|
+
.g-md-toolbar-colors__menu-icon_color_blue {
|
|
47
|
+
color: var(--yfm-colorify-blue);
|
|
48
|
+
}
|
|
49
|
+
.g-md-toolbar-colors__chevron-icon_color_blue {
|
|
50
|
+
color: var(--yfm-colorify-blue);
|
|
51
|
+
}
|
|
16
52
|
.g-md-toolbar-colors__item-icon_color_blue {
|
|
17
53
|
color: var(--yfm-colorify-blue);
|
|
18
54
|
}
|
|
55
|
+
.g-md-toolbar-colors__menu-icon_color_violet {
|
|
56
|
+
color: var(--yfm-colorify-violet);
|
|
57
|
+
}
|
|
58
|
+
.g-md-toolbar-colors__chevron-icon_color_violet {
|
|
59
|
+
color: var(--yfm-colorify-violet);
|
|
60
|
+
}
|
|
19
61
|
.g-md-toolbar-colors__item-icon_color_violet {
|
|
20
62
|
color: var(--yfm-colorify-violet);
|
|
21
63
|
}
|
|
@@ -62,6 +62,6 @@ const ToolbarColors = (props) => {
|
|
|
62
62
|
},
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
|
-
return (react_1.default.createElement(ToolbarButtonWithPopupMenu_1.ToolbarButtonWithPopupMenu, Object.assign({}, props, { title: (0, menubar_1.i18n)('colorify'), menuItems: items, icon: textColorIcon })));
|
|
65
|
+
return (react_1.default.createElement(ToolbarButtonWithPopupMenu_1.ToolbarButtonWithPopupMenu, Object.assign({}, props, { title: (0, menubar_1.i18n)('colorify'), menuItems: items, icon: textColorIcon, _selectionType: "light", iconClassName: b('menu-icon', { color: currentColor }), chevronIconClassName: b('chevron-icon', { color: currentColor }) })));
|
|
66
66
|
};
|
|
67
67
|
exports.ToolbarColors = ToolbarColors;
|
|
@@ -21,6 +21,16 @@ export declare type ParseInsertedUrlAsImage = (text: string) => {
|
|
|
21
21
|
imageUrl: string;
|
|
22
22
|
title?: string;
|
|
23
23
|
} | null;
|
|
24
|
+
export declare type WysiwygPlaceholderOptions = {
|
|
25
|
+
value?: string | (() => string);
|
|
26
|
+
/** Default – empty-doc
|
|
27
|
+
Values:
|
|
28
|
+
- 'empty-doc' – The placeholder will only be shown when the document is completely empty;
|
|
29
|
+
- 'empty-row-top-level' – The placeholder will be displayed in an empty line that is at the top level of the document structure;
|
|
30
|
+
- 'empty-row' – The placeholder will be shown in any empty line within the document, regardless of its nesting level.
|
|
31
|
+
*/
|
|
32
|
+
behavior?: 'empty-doc' | 'empty-row-top-level' | 'empty-row';
|
|
33
|
+
};
|
|
24
34
|
export declare type MarkdownEditorMdOptions = {
|
|
25
35
|
html?: boolean;
|
|
26
36
|
breaks?: boolean;
|
|
@@ -130,6 +140,7 @@ export declare type MarkdownEditorWysiwygConfig = {
|
|
|
130
140
|
extensions?: Extension;
|
|
131
141
|
extensionOptions?: ExtensionsOptions;
|
|
132
142
|
escapeConfig?: EscapeConfig;
|
|
143
|
+
placeholderOptions?: WysiwygPlaceholderOptions;
|
|
133
144
|
};
|
|
134
145
|
export declare type MarkdownEditorOptions<T extends object = {}> = {
|
|
135
146
|
/**
|
|
@@ -29,7 +29,7 @@ function useMarkdownEditor(props, deps = []) {
|
|
|
29
29
|
}, onSubmit: () => {
|
|
30
30
|
editor.emit('submit', null);
|
|
31
31
|
return true;
|
|
32
|
-
}, mdBreaks: breaks, fileUploadHandler: uploadFile, needToSetDimensionsForUploadedImages,
|
|
32
|
+
}, placeholderOptions: wysiwygConfig.placeholderOptions, mdBreaks: breaks, fileUploadHandler: uploadFile, needToSetDimensionsForUploadedImages,
|
|
33
33
|
enableNewImageSizeCalculation }));
|
|
34
34
|
{
|
|
35
35
|
const extraExtensions = wysiwygConfig.extensions || props.extraExtensions;
|
|
@@ -4,12 +4,13 @@ import { EditorModeKeymapOptions } from '../extensions/behavior/EditorModeKeymap
|
|
|
4
4
|
import { FullPresetOptions } from '../presets/full';
|
|
5
5
|
import type { DirectiveSyntaxContext } from '../utils/directive';
|
|
6
6
|
import type { FileUploadHandler } from '../utils/upload';
|
|
7
|
-
import type { MarkdownEditorPreset } from './types';
|
|
7
|
+
import type { MarkdownEditorPreset, WysiwygPlaceholderOptions } from './types';
|
|
8
8
|
export declare type ExtensionsOptions = BehaviorPresetOptions & FullPresetOptions;
|
|
9
9
|
export declare type BundlePresetOptions = ExtensionsOptions & EditorModeKeymapOptions & {
|
|
10
10
|
preset: MarkdownEditorPreset;
|
|
11
11
|
mdBreaks?: boolean;
|
|
12
12
|
fileUploadHandler?: FileUploadHandler;
|
|
13
|
+
placeholderOptions?: WysiwygPlaceholderOptions;
|
|
13
14
|
/**
|
|
14
15
|
* If we need to set dimensions for uploaded images
|
|
15
16
|
*
|
|
@@ -22,8 +22,18 @@ const BundlePreset = (builder, opts) => {
|
|
|
22
22
|
width: 2,
|
|
23
23
|
};
|
|
24
24
|
const zeroOptions = Object.assign(Object.assign({}, opts), { cursor: { dropOptions: dropCursor }, clipboard: Object.assign({ pasteFileHandler: opts.fileUploadHandler }, opts.clipboard), selectionContext: Object.assign({ config: wysiwyg_1.wSelectionMenuConfigByPreset.zero }, opts.selectionContext), commandMenu: Object.assign({ actions: wysiwyg_1.wCommandMenuConfigByPreset.zero }, opts.commandMenu), history: Object.assign({ undoKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Undo), redoKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Redo) }, opts.history), baseSchema: Object.assign({ paragraphKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Text), paragraphPlaceholder: (node, parent) => {
|
|
25
|
-
const
|
|
26
|
-
|
|
25
|
+
const { value, behavior } = opts.placeholderOptions || {};
|
|
26
|
+
const emptyEntries = {
|
|
27
|
+
'empty-row': !node.text,
|
|
28
|
+
'empty-row-top-level': !node.text && (parent === null || parent === void 0 ? void 0 : parent.type.name) === specs_1.BaseNode.Doc,
|
|
29
|
+
'empty-doc': !node.text && (parent === null || parent === void 0 ? void 0 : parent.type.name) === specs_1.BaseNode.Doc && parent.childCount === 1,
|
|
30
|
+
};
|
|
31
|
+
const showPlaceholder = emptyEntries[behavior || 'empty-doc'];
|
|
32
|
+
if (!showPlaceholder)
|
|
33
|
+
return null;
|
|
34
|
+
return typeof value === 'function'
|
|
35
|
+
? value()
|
|
36
|
+
: value !== null && value !== void 0 ? value : (0, placeholder_1.i18n)('doc_empty');
|
|
27
37
|
} }, opts.baseSchema) });
|
|
28
38
|
const commonMarkOptions = Object.assign(Object.assign({}, zeroOptions), { selectionContext: Object.assign({ config: wysiwyg_1.wSelectionMenuConfigByPreset.commonmark }, opts.selectionContext), commandMenu: Object.assign({ actions: wysiwyg_1.wCommandMenuConfigByPreset.commonmark }, opts.commandMenu), breaks: Object.assign({ preferredBreak: (opts.mdBreaks ? 'soft' : 'hard') }, opts.breaks), bold: Object.assign({ boldKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Bold) }, opts.bold), italic: Object.assign({ italicKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Italic) }, opts.italic), code: Object.assign({ codeKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Code) }, opts.code), codeBlock: Object.assign({ codeBlockKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.CodeBlock) }, opts.codeBlock), blockquote: Object.assign({ qouteKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Quote) }, opts.blockquote), link: Object.assign({ linkKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.Link) }, opts.link), lists: Object.assign({ ulKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.BulletList), olKey: shortcuts_1.formatter.toPM(shortcuts_1.Action.OrderedList), ulInputRules: { plus: false } }, opts.lists), image: {
|
|
29
39
|
parseInsertedUrlAsImage: (_a = opts.imgSize) === null || _a === void 0 ? void 0 : _a.parseInsertedUrlAsImage,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./
|
|
4
|
+
tslib_1.__exportStar(require("./wGptItemData"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./gptExtension/gptExtension"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./MarkupGpt"), exports);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type WToolbarSingleItemData } from '../../../toolbar';
|
|
2
2
|
export declare const cnGptButton: import("@bem-react/classname").ClassNameFormatter;
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const wGptItemData: WToolbarSingleItemData;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.wGptItemData = exports.cnGptButton = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const classname_1 = require("@bem-react/classname");
|
|
6
6
|
const extension_1 = require("../../../i18n/gpt/extension");
|
|
@@ -8,7 +8,7 @@ const GPT_1 = tslib_1.__importDefault(require("../../../icons/GPT"));
|
|
|
8
8
|
const toolbar_1 = require("../../../toolbar");
|
|
9
9
|
const constants_1 = require("./constants");
|
|
10
10
|
exports.cnGptButton = (0, classname_1.cn)('gpt-button');
|
|
11
|
-
exports.
|
|
11
|
+
exports.wGptItemData = {
|
|
12
12
|
type: toolbar_1.ToolbarDataType.SingleButton,
|
|
13
13
|
id: 'gpt',
|
|
14
14
|
title: () => `${(0, extension_1.i18n)('help-with-text')}`,
|
|
@@ -27,6 +27,18 @@ const gapCursor = () => new prosemirror_state_1.Plugin({
|
|
|
27
27
|
};
|
|
28
28
|
},
|
|
29
29
|
props: {
|
|
30
|
+
handleKeyPress(view) {
|
|
31
|
+
const { state, state: { selection: sel }, } = view;
|
|
32
|
+
if ((0, GapCursorSelection_1.isGapCursorSelection)(sel)) {
|
|
33
|
+
// Replace GapCursorSelection with empty textblock before run all other handlers.
|
|
34
|
+
// This should be done before all inputRules and other handlers, that handle text input.
|
|
35
|
+
// Thus, entering text into a native textblock and into a "virtual" one – GapCursor – will be the same.
|
|
36
|
+
const tr = state.tr.replaceSelectionWith((0, BaseSchema_1.pType)(state.schema).create());
|
|
37
|
+
tr.setSelection(prosemirror_state_1.TextSelection.create(tr.doc, sel.pos + 1));
|
|
38
|
+
view.dispatch(tr.scrollIntoView());
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
},
|
|
30
42
|
decorations: ({ doc, selection }) => {
|
|
31
43
|
if ((0, GapCursorSelection_1.isGapCursorSelection)(selection)) {
|
|
32
44
|
const position = selection.head;
|
|
@@ -7,7 +7,7 @@ var GapCursorSelection_1 = require("./GapCursorSelection");
|
|
|
7
7
|
Object.defineProperty(exports, "GapCursorSelection", { enumerable: true, get: function () { return GapCursorSelection_1.GapCursorSelection; } });
|
|
8
8
|
Object.defineProperty(exports, "isGapCursorSelection", { enumerable: true, get: function () { return GapCursorSelection_1.isGapCursorSelection; } });
|
|
9
9
|
const Cursor = (builder, opts) => {
|
|
10
|
-
builder.addPlugin(() => (0, gapcursor_1.gapCursor)());
|
|
10
|
+
builder.addPlugin(() => (0, gapcursor_1.gapCursor)(), builder.Priority.Highest);
|
|
11
11
|
builder.addPlugin(() => (0, prosemirror_dropcursor_1.dropCursor)(opts.dropOptions));
|
|
12
12
|
};
|
|
13
13
|
exports.Cursor = Cursor;
|
|
@@ -12,3 +12,6 @@ export declare const CheckboxAttr: {
|
|
|
12
12
|
};
|
|
13
13
|
export declare const idPrefix = "yfm-editor-checkbox";
|
|
14
14
|
export declare const b: import("@bem-react/classname").ClassNameFormatter;
|
|
15
|
+
export declare const checkboxType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
16
|
+
export declare const checkboxLabelType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
17
|
+
export declare const checkboxInputType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.b = exports.idPrefix = exports.CheckboxAttr = exports.CheckboxNode = void 0;
|
|
3
|
+
exports.checkboxInputType = exports.checkboxLabelType = exports.checkboxType = exports.b = exports.idPrefix = exports.CheckboxAttr = exports.CheckboxNode = void 0;
|
|
4
4
|
const classname_1 = require("../../../../classname");
|
|
5
|
+
const schema_1 = require("../../../../utils/schema");
|
|
5
6
|
var CheckboxNode;
|
|
6
7
|
(function (CheckboxNode) {
|
|
7
8
|
CheckboxNode["Checkbox"] = "checkbox";
|
|
@@ -17,3 +18,6 @@ exports.CheckboxAttr = {
|
|
|
17
18
|
};
|
|
18
19
|
exports.idPrefix = 'yfm-editor-checkbox';
|
|
19
20
|
exports.b = (0, classname_1.cn)('checkbox');
|
|
21
|
+
exports.checkboxType = (0, schema_1.nodeTypeFactory)(CheckboxNode.Checkbox);
|
|
22
|
+
exports.checkboxLabelType = (0, schema_1.nodeTypeFactory)(CheckboxNode.Label);
|
|
23
|
+
exports.checkboxInputType = (0, schema_1.nodeTypeFactory)(CheckboxNode.Input);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import type { NodeSpec } from 'prosemirror-model';
|
|
2
2
|
import type { ExtensionAuto, ExtensionNodeSpec } from '../../../../core';
|
|
3
|
-
export { CheckboxAttr, CheckboxNode } from './const';
|
|
4
|
-
export declare const checkboxType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
5
|
-
export declare const checkboxLabelType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
6
|
-
export declare const checkboxInputType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
3
|
+
export { CheckboxAttr, CheckboxNode, checkboxType, checkboxLabelType, checkboxInputType, } from './const';
|
|
7
4
|
export declare type CheckboxSpecsOptions = {
|
|
8
5
|
/**
|
|
9
6
|
* @deprecated: use placeholder option in BehaviorPreset instead.
|
|
@@ -3,19 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.CheckboxSpecs = exports.checkboxInputType = exports.checkboxLabelType = exports.checkboxType = exports.CheckboxNode = exports.CheckboxAttr = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const checkbox_1 = tslib_1.__importDefault(require("@diplodoc/transform/lib/plugins/checkbox"));
|
|
6
|
-
const schema_1 = require("../../../../utils/schema");
|
|
7
6
|
const const_1 = require("./const");
|
|
8
7
|
const parser_1 = require("./parser");
|
|
9
|
-
const
|
|
8
|
+
const schema_1 = require("./schema");
|
|
10
9
|
const serializer_1 = require("./serializer");
|
|
11
10
|
var const_2 = require("./const");
|
|
12
11
|
Object.defineProperty(exports, "CheckboxAttr", { enumerable: true, get: function () { return const_2.CheckboxAttr; } });
|
|
13
12
|
Object.defineProperty(exports, "CheckboxNode", { enumerable: true, get: function () { return const_2.CheckboxNode; } });
|
|
14
|
-
exports
|
|
15
|
-
exports
|
|
16
|
-
exports
|
|
13
|
+
Object.defineProperty(exports, "checkboxType", { enumerable: true, get: function () { return const_2.checkboxType; } });
|
|
14
|
+
Object.defineProperty(exports, "checkboxLabelType", { enumerable: true, get: function () { return const_2.checkboxLabelType; } });
|
|
15
|
+
Object.defineProperty(exports, "checkboxInputType", { enumerable: true, get: function () { return const_2.checkboxInputType; } });
|
|
17
16
|
const CheckboxSpecs = (builder, opts) => {
|
|
18
|
-
const schemaSpecs = (0,
|
|
17
|
+
const schemaSpecs = (0, schema_1.getSchemaSpecs)(opts, builder.context.get('placeholder'));
|
|
19
18
|
builder
|
|
20
19
|
.configureMd((md) => md.use(checkbox_1.default, { idPrefix: const_1.idPrefix, divClass: (0, const_1.b)() }))
|
|
21
20
|
.addNode(const_1.CheckboxNode.Checkbox, () => ({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { PlaceholderOptions } from '../../../../utils/placeholder';
|
|
1
|
+
import { type NodeSpec } from 'prosemirror-model';
|
|
2
|
+
import type { PlaceholderOptions } from '../../../../utils/placeholder';
|
|
3
3
|
import { CheckboxNode } from './const';
|
|
4
4
|
import type { CheckboxSpecsOptions } from './index';
|
|
5
5
|
export declare const getSchemaSpecs: (opts?: Pick<CheckboxSpecsOptions, 'checkboxLabelPlaceholder'>, placeholder?: PlaceholderOptions) => Record<CheckboxNode, NodeSpec>;
|
|
@@ -1,27 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getSchemaSpecs = void 0;
|
|
4
|
+
const prosemirror_model_1 = require("prosemirror-model");
|
|
4
5
|
const const_1 = require("./const");
|
|
5
6
|
const DEFAULT_LABEL_PLACEHOLDER = 'Checkbox';
|
|
6
7
|
const getSchemaSpecs = (opts, placeholder) => {
|
|
7
8
|
var _a, _b;
|
|
8
9
|
return ({
|
|
9
10
|
[const_1.CheckboxNode.Checkbox]: {
|
|
10
|
-
group: 'block',
|
|
11
|
+
group: 'block checkbox',
|
|
11
12
|
content: `${const_1.CheckboxNode.Input} ${const_1.CheckboxNode.Label}`,
|
|
12
13
|
selectable: true,
|
|
13
14
|
allowSelection: false,
|
|
14
|
-
parseDOM: [],
|
|
15
15
|
attrs: {
|
|
16
16
|
[const_1.CheckboxAttr.Class]: { default: (0, const_1.b)() },
|
|
17
17
|
},
|
|
18
|
+
parseDOM: [
|
|
19
|
+
{
|
|
20
|
+
tag: 'div.checkbox',
|
|
21
|
+
priority: 100,
|
|
22
|
+
getContent(node, schema) {
|
|
23
|
+
const input = node.querySelector('input[type=checkbox]');
|
|
24
|
+
const label = node.querySelector('label[for]');
|
|
25
|
+
const checked = (input === null || input === void 0 ? void 0 : input.checked) ? 'true' : null;
|
|
26
|
+
const text = label === null || label === void 0 ? void 0 : label.textContent;
|
|
27
|
+
return prosemirror_model_1.Fragment.from([
|
|
28
|
+
(0, const_1.checkboxInputType)(schema).create({ [const_1.CheckboxAttr.Checked]: checked }),
|
|
29
|
+
(0, const_1.checkboxLabelType)(schema).create(null, text ? schema.text(text) : null),
|
|
30
|
+
]);
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
tag: 'input[type=checkbox]',
|
|
35
|
+
priority: 50,
|
|
36
|
+
getContent(node, schema) {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
const id = node.id;
|
|
39
|
+
const checked = node.checked ? 'true' : null;
|
|
40
|
+
const text = (_b = (_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.querySelector(`label[for=${id}]`)) === null || _b === void 0 ? void 0 : _b.textContent;
|
|
41
|
+
return prosemirror_model_1.Fragment.from([
|
|
42
|
+
(0, const_1.checkboxInputType)(schema).create({ [const_1.CheckboxAttr.Checked]: checked }),
|
|
43
|
+
(0, const_1.checkboxLabelType)(schema).create(null, text ? schema.text(text) : null),
|
|
44
|
+
]);
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
],
|
|
18
48
|
toDOM(node) {
|
|
19
49
|
return ['div', node.attrs, 0];
|
|
20
50
|
},
|
|
21
51
|
complex: 'root',
|
|
22
52
|
},
|
|
23
53
|
[const_1.CheckboxNode.Input]: {
|
|
24
|
-
group: 'block',
|
|
54
|
+
group: 'block checkbox',
|
|
25
55
|
parseDOM: [],
|
|
26
56
|
attrs: {
|
|
27
57
|
[const_1.CheckboxAttr.Type]: { default: 'checkbox' },
|
|
@@ -37,7 +67,7 @@ const getSchemaSpecs = (opts, placeholder) => {
|
|
|
37
67
|
},
|
|
38
68
|
[const_1.CheckboxNode.Label]: {
|
|
39
69
|
content: 'inline*',
|
|
40
|
-
group: 'block',
|
|
70
|
+
group: 'block checkbox',
|
|
41
71
|
parseDOM: [
|
|
42
72
|
{
|
|
43
73
|
tag: `span[class="${(0, const_1.b)('label')}"]`,
|
|
@@ -45,6 +75,13 @@ const getSchemaSpecs = (opts, placeholder) => {
|
|
|
45
75
|
[const_1.CheckboxAttr.For]: node.getAttribute(const_1.CheckboxAttr.For) || '',
|
|
46
76
|
}),
|
|
47
77
|
},
|
|
78
|
+
{
|
|
79
|
+
// input handled by checkbox node parse rule
|
|
80
|
+
// ignore label
|
|
81
|
+
tag: 'input[type=checkbox] ~ label[for]',
|
|
82
|
+
ignore: true,
|
|
83
|
+
consuming: true,
|
|
84
|
+
},
|
|
48
85
|
],
|
|
49
86
|
attrs: {
|
|
50
87
|
[const_1.CheckboxAttr.For]: { default: null },
|
|
@@ -6,6 +6,7 @@ const CheckboxSpecs_1 = require("./CheckboxSpecs");
|
|
|
6
6
|
const actions_1 = require("./actions");
|
|
7
7
|
const nodeviews_1 = require("./nodeviews");
|
|
8
8
|
const plugin_1 = require("./plugin");
|
|
9
|
+
const fix_paste_1 = require("./plugins/fix-paste");
|
|
9
10
|
const utils_1 = require("./utils");
|
|
10
11
|
const checkboxAction = 'addCheckbox';
|
|
11
12
|
var CheckboxSpecs_2 = require("./CheckboxSpecs");
|
|
@@ -18,6 +19,7 @@ const Checkbox = (builder, opts) => {
|
|
|
18
19
|
builder.use(CheckboxSpecs_1.CheckboxSpecs, Object.assign(Object.assign({}, opts), { inputView: () => nodeviews_1.CheckboxInputView.create }));
|
|
19
20
|
builder
|
|
20
21
|
.addPlugin(plugin_1.keymapPlugin, builder.Priority.High)
|
|
22
|
+
.addPlugin(fix_paste_1.fixPastePlugin)
|
|
21
23
|
.addAction(checkboxAction, () => (0, actions_1.addCheckbox)())
|
|
22
24
|
.addInputRules(({ schema }) => ({
|
|
23
25
|
rules: [
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fixPastePlugin = void 0;
|
|
4
|
+
const prosemirror_model_1 = require("prosemirror-model");
|
|
5
|
+
const prosemirror_state_1 = require("prosemirror-state");
|
|
6
|
+
const CheckboxSpecs_1 = require("../CheckboxSpecs");
|
|
7
|
+
const fixPastePlugin = () => new prosemirror_state_1.Plugin({
|
|
8
|
+
props: {
|
|
9
|
+
transformPasted(slice) {
|
|
10
|
+
const { firstChild } = slice.content;
|
|
11
|
+
if (firstChild && firstChild.type === (0, CheckboxSpecs_1.checkboxType)(firstChild.type.schema)) {
|
|
12
|
+
// When paste html with checkboxes and checkbox is first node,
|
|
13
|
+
// pm creates slice with broken openStart and openEnd.
|
|
14
|
+
// And content is inserted without a container block for checkboxes.
|
|
15
|
+
// It is fixed by create new slice with zeroed openStart and openEnd.
|
|
16
|
+
return new prosemirror_model_1.Slice(slice.content, 0, 0);
|
|
17
|
+
}
|
|
18
|
+
return slice;
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
exports.fixPastePlugin = fixPastePlugin;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Node, NodeType, Schema } from 'prosemirror-model';
|
|
1
|
+
import { Node, type NodeType, type Schema } from 'prosemirror-model';
|
|
2
2
|
export declare const nodeTypeFactory: (nodeName: string) => (schema: Schema) => NodeType;
|
|
3
3
|
export declare const markTypeFactory: (markName: string) => (schema: Schema) => import("prosemirror-model").MarkType;
|
|
4
4
|
export declare function isSameNodeType(a: Node | NodeType, b: Node | NodeType): boolean;
|
package/build/cjs/version.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VERSION = void 0;
|
|
4
4
|
/** During build process, the current version will be injected here */
|
|
5
|
-
exports.VERSION = typeof '14.
|
|
5
|
+
exports.VERSION = typeof '14.7.0' !== 'undefined' ? '14.7.0' : 'unknown';
|
|
@@ -34,7 +34,6 @@ export declare const wTabsItemData: WToolbarSingleItemData;
|
|
|
34
34
|
export declare const wMathInlineItemData: WToolbarSingleItemData;
|
|
35
35
|
export declare const wMathBlockItemData: WToolbarSingleItemData;
|
|
36
36
|
export declare const wYfmHtmlBlockItemData: WToolbarSingleItemData;
|
|
37
|
-
export declare const wGptItemData: WToolbarSingleItemData;
|
|
38
37
|
export declare const wMermaidItemData: WToolbarSingleItemData;
|
|
39
38
|
export declare const wCodeBlockItemData: WToolbarItemData;
|
|
40
39
|
export declare const wHruleItemData: WToolbarItemData;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { headingType, pType } from '../../extensions';
|
|
2
|
-
import { gptHotKeys } from '../../extensions/additional/GPT/constants';
|
|
3
2
|
import { i18n as i18nHint } from '../../i18n/hints';
|
|
4
3
|
import { i18n } from '../../i18n/menubar';
|
|
5
4
|
import { Action as A, formatter as f } from '../../shortcuts';
|
|
@@ -214,16 +213,6 @@ export const wYfmHtmlBlockItemData = {
|
|
|
214
213
|
isActive: (e) => e.actions.createYfmHtmlBlock.isActive(),
|
|
215
214
|
isEnable: (e) => e.actions.createYfmHtmlBlock.isEnable(),
|
|
216
215
|
};
|
|
217
|
-
export const wGptItemData = {
|
|
218
|
-
id: ActionName.gpt,
|
|
219
|
-
type: ToolbarDataType.SingleButton,
|
|
220
|
-
title: i18n.bind(null, 'gpt'),
|
|
221
|
-
hotkey: gptHotKeys.openGptKeyTooltip,
|
|
222
|
-
icon: icons.gpt,
|
|
223
|
-
exec: (e) => e.actions.addGptWidget.run({}),
|
|
224
|
-
isActive: (e) => e.actions.addGptWidget.isActive(),
|
|
225
|
-
isEnable: (e) => e.actions.addGptWidget.isEnable(),
|
|
226
|
-
};
|
|
227
216
|
export const wMermaidItemData = {
|
|
228
217
|
id: ActionName.mermaid,
|
|
229
218
|
type: ToolbarDataType.SingleButton,
|
|
@@ -15,7 +15,11 @@ export declare type MenuItem = {
|
|
|
15
15
|
};
|
|
16
16
|
export declare type ToolbarButtonWithPopupMenuProps = Omit<ToolbarBaseProps<ActionStorage> & {
|
|
17
17
|
icon: ToolbarIconData;
|
|
18
|
+
iconClassName?: string;
|
|
19
|
+
chevronIconClassName?: string;
|
|
18
20
|
title: string | (() => string);
|
|
19
21
|
menuItems: MenuItem[];
|
|
22
|
+
/** @default 'classic' */
|
|
23
|
+
_selectionType?: 'classic' | 'light';
|
|
20
24
|
}, 'editor'>;
|
|
21
25
|
export declare const ToolbarButtonWithPopupMenu: React.FC<ToolbarButtonWithPopupMenuProps>;
|
|
@@ -7,10 +7,10 @@ import { useBooleanState } from '../../react-utils/hooks';
|
|
|
7
7
|
import { ToolbarTooltipDelay } from '../../toolbar';
|
|
8
8
|
import './ToolbarButtonWithPopupMenu.css';
|
|
9
9
|
const b = cn('toolbar-button-with-popup-menu');
|
|
10
|
-
export const ToolbarButtonWithPopupMenu = ({ className, focus, onClick, icon, title, menuItems, }) => {
|
|
10
|
+
export const ToolbarButtonWithPopupMenu = ({ className, focus, onClick, icon, iconClassName, chevronIconClassName, title, menuItems, _selectionType, }) => {
|
|
11
11
|
const buttonRef = React.useRef(null);
|
|
12
12
|
const [open, , hide, toggleOpen] = useBooleanState(false);
|
|
13
|
-
const groups = React.useMemo(() => groupBy(menuItems.map((i) => (Object.assign(Object.assign({}, i), { group: i.group || '' }))), 'group'), [menuItems
|
|
13
|
+
const groups = React.useMemo(() => groupBy(menuItems.map((i) => (Object.assign(Object.assign({}, i), { group: i.group || '' }))), 'group'), [menuItems]);
|
|
14
14
|
const someActive = menuItems.some((item) => !item.ignoreActive && item.action.isActive() === true);
|
|
15
15
|
const everyDisabled = menuItems.every((item) => item.action.isEnable() === false);
|
|
16
16
|
const popupOpen = everyDisabled ? false : open;
|
|
@@ -20,12 +20,18 @@ export const ToolbarButtonWithPopupMenu = ({ className, focus, onClick, icon, ti
|
|
|
20
20
|
hide();
|
|
21
21
|
}
|
|
22
22
|
}, [hide, shouldForceHide]);
|
|
23
|
+
const [btnView, btnSelected] = _selectionType === 'light'
|
|
24
|
+
? [
|
|
25
|
+
popupOpen ? 'normal' : someActive ? 'flat-action' : 'flat',
|
|
26
|
+
popupOpen && someActive,
|
|
27
|
+
]
|
|
28
|
+
: [someActive || popupOpen ? 'normal' : 'flat', someActive];
|
|
23
29
|
return (React.createElement(React.Fragment, null,
|
|
24
30
|
React.createElement(ActionTooltip, { disabled: popupOpen, openDelay: ToolbarTooltipDelay.Open, closeDelay: ToolbarTooltipDelay.Close, title: isFunction(title) ? title() : title },
|
|
25
|
-
React.createElement(Button, { size: "m", ref: buttonRef, view:
|
|
26
|
-
React.createElement(Icon, { data: icon.data, size: icon.size }),
|
|
31
|
+
React.createElement(Button, { size: "m", ref: buttonRef, view: btnView, selected: btnSelected, disabled: everyDisabled, className: b(null, [className]), onClick: toggleOpen },
|
|
32
|
+
React.createElement(Icon, { data: icon.data, size: icon.size, className: iconClassName }),
|
|
27
33
|
'',
|
|
28
|
-
React.createElement(Icon, { data: ChevronDown }))),
|
|
34
|
+
React.createElement(Icon, { data: ChevronDown, className: chevronIconClassName }))),
|
|
29
35
|
React.createElement(Popup, { anchorRef: buttonRef, open: popupOpen, onClose: hide },
|
|
30
36
|
React.createElement(Menu, { size: "l" }, Object.entries(groups).map(([label, items], key) => {
|
|
31
37
|
return (React.createElement(Menu.Group, { label: label, key: key, className: b('menu-group') }, items.map(({ id, icon, iconSize = 16, action, text, iconClassname }) => (React.createElement(Menu.Item, { key: id, icon: React.createElement(Icon, { data: icon, size: iconSize, className: iconClassname }), active: action.isActive(), disabled: !action.isEnable(), onClick: () => {
|
|
@@ -1,21 +1,63 @@
|
|
|
1
|
+
.g-md-toolbar-colors__menu-icon_color_gray {
|
|
2
|
+
color: var(--yfm-colorify-gray);
|
|
3
|
+
}
|
|
4
|
+
.g-md-toolbar-colors__chevron-icon_color_gray {
|
|
5
|
+
color: var(--yfm-colorify-gray);
|
|
6
|
+
}
|
|
1
7
|
.g-md-toolbar-colors__item-icon_color_gray {
|
|
2
8
|
color: var(--yfm-colorify-gray);
|
|
3
9
|
}
|
|
10
|
+
.g-md-toolbar-colors__menu-icon_color_yellow {
|
|
11
|
+
color: var(--yfm-colorify-yellow);
|
|
12
|
+
}
|
|
13
|
+
.g-md-toolbar-colors__chevron-icon_color_yellow {
|
|
14
|
+
color: var(--yfm-colorify-yellow);
|
|
15
|
+
}
|
|
4
16
|
.g-md-toolbar-colors__item-icon_color_yellow {
|
|
5
17
|
color: var(--yfm-colorify-yellow);
|
|
6
18
|
}
|
|
19
|
+
.g-md-toolbar-colors__menu-icon_color_orange {
|
|
20
|
+
color: var(--yfm-colorify-orange);
|
|
21
|
+
}
|
|
22
|
+
.g-md-toolbar-colors__chevron-icon_color_orange {
|
|
23
|
+
color: var(--yfm-colorify-orange);
|
|
24
|
+
}
|
|
7
25
|
.g-md-toolbar-colors__item-icon_color_orange {
|
|
8
26
|
color: var(--yfm-colorify-orange);
|
|
9
27
|
}
|
|
28
|
+
.g-md-toolbar-colors__menu-icon_color_red {
|
|
29
|
+
color: var(--yfm-colorify-red);
|
|
30
|
+
}
|
|
31
|
+
.g-md-toolbar-colors__chevron-icon_color_red {
|
|
32
|
+
color: var(--yfm-colorify-red);
|
|
33
|
+
}
|
|
10
34
|
.g-md-toolbar-colors__item-icon_color_red {
|
|
11
35
|
color: var(--yfm-colorify-red);
|
|
12
36
|
}
|
|
37
|
+
.g-md-toolbar-colors__menu-icon_color_green {
|
|
38
|
+
color: var(--yfm-colorify-green);
|
|
39
|
+
}
|
|
40
|
+
.g-md-toolbar-colors__chevron-icon_color_green {
|
|
41
|
+
color: var(--yfm-colorify-green);
|
|
42
|
+
}
|
|
13
43
|
.g-md-toolbar-colors__item-icon_color_green {
|
|
14
44
|
color: var(--yfm-colorify-green);
|
|
15
45
|
}
|
|
46
|
+
.g-md-toolbar-colors__menu-icon_color_blue {
|
|
47
|
+
color: var(--yfm-colorify-blue);
|
|
48
|
+
}
|
|
49
|
+
.g-md-toolbar-colors__chevron-icon_color_blue {
|
|
50
|
+
color: var(--yfm-colorify-blue);
|
|
51
|
+
}
|
|
16
52
|
.g-md-toolbar-colors__item-icon_color_blue {
|
|
17
53
|
color: var(--yfm-colorify-blue);
|
|
18
54
|
}
|
|
55
|
+
.g-md-toolbar-colors__menu-icon_color_violet {
|
|
56
|
+
color: var(--yfm-colorify-violet);
|
|
57
|
+
}
|
|
58
|
+
.g-md-toolbar-colors__chevron-icon_color_violet {
|
|
59
|
+
color: var(--yfm-colorify-violet);
|
|
60
|
+
}
|
|
19
61
|
.g-md-toolbar-colors__item-icon_color_violet {
|
|
20
62
|
color: var(--yfm-colorify-violet);
|
|
21
63
|
}
|
|
@@ -59,5 +59,5 @@ export const ToolbarColors = (props) => {
|
|
|
59
59
|
},
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
|
-
return (React.createElement(ToolbarButtonWithPopupMenu, Object.assign({}, props, { title: i18n('colorify'), menuItems: items, icon: textColorIcon })));
|
|
62
|
+
return (React.createElement(ToolbarButtonWithPopupMenu, Object.assign({}, props, { title: i18n('colorify'), menuItems: items, icon: textColorIcon, _selectionType: "light", iconClassName: b('menu-icon', { color: currentColor }), chevronIconClassName: b('chevron-icon', { color: currentColor }) })));
|
|
63
63
|
};
|
|
@@ -21,6 +21,16 @@ export declare type ParseInsertedUrlAsImage = (text: string) => {
|
|
|
21
21
|
imageUrl: string;
|
|
22
22
|
title?: string;
|
|
23
23
|
} | null;
|
|
24
|
+
export declare type WysiwygPlaceholderOptions = {
|
|
25
|
+
value?: string | (() => string);
|
|
26
|
+
/** Default – empty-doc
|
|
27
|
+
Values:
|
|
28
|
+
- 'empty-doc' – The placeholder will only be shown when the document is completely empty;
|
|
29
|
+
- 'empty-row-top-level' – The placeholder will be displayed in an empty line that is at the top level of the document structure;
|
|
30
|
+
- 'empty-row' – The placeholder will be shown in any empty line within the document, regardless of its nesting level.
|
|
31
|
+
*/
|
|
32
|
+
behavior?: 'empty-doc' | 'empty-row-top-level' | 'empty-row';
|
|
33
|
+
};
|
|
24
34
|
export declare type MarkdownEditorMdOptions = {
|
|
25
35
|
html?: boolean;
|
|
26
36
|
breaks?: boolean;
|
|
@@ -130,6 +140,7 @@ export declare type MarkdownEditorWysiwygConfig = {
|
|
|
130
140
|
extensions?: Extension;
|
|
131
141
|
extensionOptions?: ExtensionsOptions;
|
|
132
142
|
escapeConfig?: EscapeConfig;
|
|
143
|
+
placeholderOptions?: WysiwygPlaceholderOptions;
|
|
133
144
|
};
|
|
134
145
|
export declare type MarkdownEditorOptions<T extends object = {}> = {
|
|
135
146
|
/**
|
|
@@ -26,7 +26,7 @@ export function useMarkdownEditor(props, deps = []) {
|
|
|
26
26
|
}, onSubmit: () => {
|
|
27
27
|
editor.emit('submit', null);
|
|
28
28
|
return true;
|
|
29
|
-
}, mdBreaks: breaks, fileUploadHandler: uploadFile, needToSetDimensionsForUploadedImages,
|
|
29
|
+
}, placeholderOptions: wysiwygConfig.placeholderOptions, mdBreaks: breaks, fileUploadHandler: uploadFile, needToSetDimensionsForUploadedImages,
|
|
30
30
|
enableNewImageSizeCalculation }));
|
|
31
31
|
{
|
|
32
32
|
const extraExtensions = wysiwygConfig.extensions || props.extraExtensions;
|
|
@@ -4,12 +4,13 @@ import { EditorModeKeymapOptions } from '../extensions/behavior/EditorModeKeymap
|
|
|
4
4
|
import { FullPresetOptions } from '../presets/full';
|
|
5
5
|
import type { DirectiveSyntaxContext } from '../utils/directive';
|
|
6
6
|
import type { FileUploadHandler } from '../utils/upload';
|
|
7
|
-
import type { MarkdownEditorPreset } from './types';
|
|
7
|
+
import type { MarkdownEditorPreset, WysiwygPlaceholderOptions } from './types';
|
|
8
8
|
export declare type ExtensionsOptions = BehaviorPresetOptions & FullPresetOptions;
|
|
9
9
|
export declare type BundlePresetOptions = ExtensionsOptions & EditorModeKeymapOptions & {
|
|
10
10
|
preset: MarkdownEditorPreset;
|
|
11
11
|
mdBreaks?: boolean;
|
|
12
12
|
fileUploadHandler?: FileUploadHandler;
|
|
13
|
+
placeholderOptions?: WysiwygPlaceholderOptions;
|
|
13
14
|
/**
|
|
14
15
|
* If we need to set dimensions for uploaded images
|
|
15
16
|
*
|
|
@@ -19,8 +19,18 @@ export const BundlePreset = (builder, opts) => {
|
|
|
19
19
|
width: 2,
|
|
20
20
|
};
|
|
21
21
|
const zeroOptions = Object.assign(Object.assign({}, opts), { cursor: { dropOptions: dropCursor }, clipboard: Object.assign({ pasteFileHandler: opts.fileUploadHandler }, opts.clipboard), selectionContext: Object.assign({ config: wSelectionMenuConfigByPreset.zero }, opts.selectionContext), commandMenu: Object.assign({ actions: wCommandMenuConfigByPreset.zero }, opts.commandMenu), history: Object.assign({ undoKey: f.toPM(A.Undo), redoKey: f.toPM(A.Redo) }, opts.history), baseSchema: Object.assign({ paragraphKey: f.toPM(A.Text), paragraphPlaceholder: (node, parent) => {
|
|
22
|
-
const
|
|
23
|
-
|
|
22
|
+
const { value, behavior } = opts.placeholderOptions || {};
|
|
23
|
+
const emptyEntries = {
|
|
24
|
+
'empty-row': !node.text,
|
|
25
|
+
'empty-row-top-level': !node.text && (parent === null || parent === void 0 ? void 0 : parent.type.name) === BaseNode.Doc,
|
|
26
|
+
'empty-doc': !node.text && (parent === null || parent === void 0 ? void 0 : parent.type.name) === BaseNode.Doc && parent.childCount === 1,
|
|
27
|
+
};
|
|
28
|
+
const showPlaceholder = emptyEntries[behavior || 'empty-doc'];
|
|
29
|
+
if (!showPlaceholder)
|
|
30
|
+
return null;
|
|
31
|
+
return typeof value === 'function'
|
|
32
|
+
? value()
|
|
33
|
+
: value !== null && value !== void 0 ? value : i18nPlaceholder('doc_empty');
|
|
24
34
|
} }, opts.baseSchema) });
|
|
25
35
|
const commonMarkOptions = Object.assign(Object.assign({}, zeroOptions), { selectionContext: Object.assign({ config: wSelectionMenuConfigByPreset.commonmark }, opts.selectionContext), commandMenu: Object.assign({ actions: wCommandMenuConfigByPreset.commonmark }, opts.commandMenu), breaks: Object.assign({ preferredBreak: (opts.mdBreaks ? 'soft' : 'hard') }, opts.breaks), bold: Object.assign({ boldKey: f.toPM(A.Bold) }, opts.bold), italic: Object.assign({ italicKey: f.toPM(A.Italic) }, opts.italic), code: Object.assign({ codeKey: f.toPM(A.Code) }, opts.code), codeBlock: Object.assign({ codeBlockKey: f.toPM(A.CodeBlock) }, opts.codeBlock), blockquote: Object.assign({ qouteKey: f.toPM(A.Quote) }, opts.blockquote), link: Object.assign({ linkKey: f.toPM(A.Link) }, opts.link), lists: Object.assign({ ulKey: f.toPM(A.BulletList), olKey: f.toPM(A.OrderedList), ulInputRules: { plus: false } }, opts.lists), image: {
|
|
26
36
|
parseInsertedUrlAsImage: (_a = opts.imgSize) === null || _a === void 0 ? void 0 : _a.parseInsertedUrlAsImage,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type WToolbarSingleItemData } from '../../../toolbar';
|
|
2
2
|
export declare const cnGptButton: import("@bem-react/classname").ClassNameFormatter;
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const wGptItemData: WToolbarSingleItemData;
|
|
@@ -4,7 +4,7 @@ import gptIcon from '../../../icons/GPT';
|
|
|
4
4
|
import { ToolbarDataType } from '../../../toolbar';
|
|
5
5
|
import { gptHotKeys } from './constants';
|
|
6
6
|
export const cnGptButton = cn('gpt-button');
|
|
7
|
-
export const
|
|
7
|
+
export const wGptItemData = {
|
|
8
8
|
type: ToolbarDataType.SingleButton,
|
|
9
9
|
id: 'gpt',
|
|
10
10
|
title: () => `${i18n('help-with-text')}`,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DOMSerializer } from 'prosemirror-model';
|
|
2
|
-
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
2
|
+
import { Plugin, PluginKey, TextSelection } from 'prosemirror-state';
|
|
3
3
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
4
4
|
import { isNodeSelection } from '../../../utils/selection';
|
|
5
5
|
import { pType } from '../../base/BaseSchema';
|
|
@@ -25,6 +25,18 @@ export const gapCursor = () => new Plugin({
|
|
|
25
25
|
};
|
|
26
26
|
},
|
|
27
27
|
props: {
|
|
28
|
+
handleKeyPress(view) {
|
|
29
|
+
const { state, state: { selection: sel }, } = view;
|
|
30
|
+
if (isGapCursorSelection(sel)) {
|
|
31
|
+
// Replace GapCursorSelection with empty textblock before run all other handlers.
|
|
32
|
+
// This should be done before all inputRules and other handlers, that handle text input.
|
|
33
|
+
// Thus, entering text into a native textblock and into a "virtual" one – GapCursor – will be the same.
|
|
34
|
+
const tr = state.tr.replaceSelectionWith(pType(state.schema).create());
|
|
35
|
+
tr.setSelection(TextSelection.create(tr.doc, sel.pos + 1));
|
|
36
|
+
view.dispatch(tr.scrollIntoView());
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
},
|
|
28
40
|
decorations: ({ doc, selection }) => {
|
|
29
41
|
if (isGapCursorSelection(selection)) {
|
|
30
42
|
const position = selection.head;
|
|
@@ -2,6 +2,6 @@ import { dropCursor } from 'prosemirror-dropcursor';
|
|
|
2
2
|
import { gapCursor } from './gapcursor';
|
|
3
3
|
export { GapCursorSelection, isGapCursorSelection } from './GapCursorSelection';
|
|
4
4
|
export const Cursor = (builder, opts) => {
|
|
5
|
-
builder.addPlugin(() => gapCursor());
|
|
5
|
+
builder.addPlugin(() => gapCursor(), builder.Priority.Highest);
|
|
6
6
|
builder.addPlugin(() => dropCursor(opts.dropOptions));
|
|
7
7
|
};
|
|
@@ -12,3 +12,6 @@ export declare const CheckboxAttr: {
|
|
|
12
12
|
};
|
|
13
13
|
export declare const idPrefix = "yfm-editor-checkbox";
|
|
14
14
|
export declare const b: import("@bem-react/classname").ClassNameFormatter;
|
|
15
|
+
export declare const checkboxType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
16
|
+
export declare const checkboxLabelType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
17
|
+
export declare const checkboxInputType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { cn } from '../../../../classname';
|
|
2
|
+
import { nodeTypeFactory } from '../../../../utils/schema';
|
|
2
3
|
export var CheckboxNode;
|
|
3
4
|
(function (CheckboxNode) {
|
|
4
5
|
CheckboxNode["Checkbox"] = "checkbox";
|
|
@@ -14,3 +15,6 @@ export const CheckboxAttr = {
|
|
|
14
15
|
};
|
|
15
16
|
export const idPrefix = 'yfm-editor-checkbox';
|
|
16
17
|
export const b = cn('checkbox');
|
|
18
|
+
export const checkboxType = nodeTypeFactory(CheckboxNode.Checkbox);
|
|
19
|
+
export const checkboxLabelType = nodeTypeFactory(CheckboxNode.Label);
|
|
20
|
+
export const checkboxInputType = nodeTypeFactory(CheckboxNode.Input);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import type { NodeSpec } from 'prosemirror-model';
|
|
2
2
|
import type { ExtensionAuto, ExtensionNodeSpec } from '../../../../core';
|
|
3
|
-
export { CheckboxAttr, CheckboxNode } from './const';
|
|
4
|
-
export declare const checkboxType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
5
|
-
export declare const checkboxLabelType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
6
|
-
export declare const checkboxInputType: (schema: import("prosemirror-model").Schema<any, any>) => import("prosemirror-model").NodeType;
|
|
3
|
+
export { CheckboxAttr, CheckboxNode, checkboxType, checkboxLabelType, checkboxInputType, } from './const';
|
|
7
4
|
export declare type CheckboxSpecsOptions = {
|
|
8
5
|
/**
|
|
9
6
|
* @deprecated: use placeholder option in BehaviorPreset instead.
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import checkboxPlugin from '@diplodoc/transform/lib/plugins/checkbox';
|
|
2
|
-
import { nodeTypeFactory } from '../../../../utils/schema';
|
|
3
2
|
import { CheckboxNode, b, idPrefix } from './const';
|
|
4
3
|
import { parserTokens } from './parser';
|
|
5
4
|
import { getSchemaSpecs } from './schema';
|
|
6
5
|
import { serializerTokens } from './serializer';
|
|
7
|
-
export { CheckboxAttr, CheckboxNode } from './const';
|
|
8
|
-
export const checkboxType = nodeTypeFactory(CheckboxNode.Checkbox);
|
|
9
|
-
export const checkboxLabelType = nodeTypeFactory(CheckboxNode.Label);
|
|
10
|
-
export const checkboxInputType = nodeTypeFactory(CheckboxNode.Input);
|
|
6
|
+
export { CheckboxAttr, CheckboxNode, checkboxType, checkboxLabelType, checkboxInputType, } from './const';
|
|
11
7
|
export const CheckboxSpecs = (builder, opts) => {
|
|
12
8
|
const schemaSpecs = getSchemaSpecs(opts, builder.context.get('placeholder'));
|
|
13
9
|
builder
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { PlaceholderOptions } from '../../../../utils/placeholder';
|
|
1
|
+
import { type NodeSpec } from 'prosemirror-model';
|
|
2
|
+
import type { PlaceholderOptions } from '../../../../utils/placeholder';
|
|
3
3
|
import { CheckboxNode } from './const';
|
|
4
4
|
import type { CheckboxSpecsOptions } from './index';
|
|
5
5
|
export declare const getSchemaSpecs: (opts?: Pick<CheckboxSpecsOptions, 'checkboxLabelPlaceholder'>, placeholder?: PlaceholderOptions) => Record<CheckboxNode, NodeSpec>;
|
|
@@ -1,24 +1,54 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Fragment } from 'prosemirror-model';
|
|
2
|
+
import { CheckboxAttr, CheckboxNode, b, checkboxInputType, checkboxLabelType } from './const';
|
|
2
3
|
const DEFAULT_LABEL_PLACEHOLDER = 'Checkbox';
|
|
3
4
|
export const getSchemaSpecs = (opts, placeholder) => {
|
|
4
5
|
var _a, _b;
|
|
5
6
|
return ({
|
|
6
7
|
[CheckboxNode.Checkbox]: {
|
|
7
|
-
group: 'block',
|
|
8
|
+
group: 'block checkbox',
|
|
8
9
|
content: `${CheckboxNode.Input} ${CheckboxNode.Label}`,
|
|
9
10
|
selectable: true,
|
|
10
11
|
allowSelection: false,
|
|
11
|
-
parseDOM: [],
|
|
12
12
|
attrs: {
|
|
13
13
|
[CheckboxAttr.Class]: { default: b() },
|
|
14
14
|
},
|
|
15
|
+
parseDOM: [
|
|
16
|
+
{
|
|
17
|
+
tag: 'div.checkbox',
|
|
18
|
+
priority: 100,
|
|
19
|
+
getContent(node, schema) {
|
|
20
|
+
const input = node.querySelector('input[type=checkbox]');
|
|
21
|
+
const label = node.querySelector('label[for]');
|
|
22
|
+
const checked = (input === null || input === void 0 ? void 0 : input.checked) ? 'true' : null;
|
|
23
|
+
const text = label === null || label === void 0 ? void 0 : label.textContent;
|
|
24
|
+
return Fragment.from([
|
|
25
|
+
checkboxInputType(schema).create({ [CheckboxAttr.Checked]: checked }),
|
|
26
|
+
checkboxLabelType(schema).create(null, text ? schema.text(text) : null),
|
|
27
|
+
]);
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
tag: 'input[type=checkbox]',
|
|
32
|
+
priority: 50,
|
|
33
|
+
getContent(node, schema) {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
const id = node.id;
|
|
36
|
+
const checked = node.checked ? 'true' : null;
|
|
37
|
+
const text = (_b = (_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.querySelector(`label[for=${id}]`)) === null || _b === void 0 ? void 0 : _b.textContent;
|
|
38
|
+
return Fragment.from([
|
|
39
|
+
checkboxInputType(schema).create({ [CheckboxAttr.Checked]: checked }),
|
|
40
|
+
checkboxLabelType(schema).create(null, text ? schema.text(text) : null),
|
|
41
|
+
]);
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
],
|
|
15
45
|
toDOM(node) {
|
|
16
46
|
return ['div', node.attrs, 0];
|
|
17
47
|
},
|
|
18
48
|
complex: 'root',
|
|
19
49
|
},
|
|
20
50
|
[CheckboxNode.Input]: {
|
|
21
|
-
group: 'block',
|
|
51
|
+
group: 'block checkbox',
|
|
22
52
|
parseDOM: [],
|
|
23
53
|
attrs: {
|
|
24
54
|
[CheckboxAttr.Type]: { default: 'checkbox' },
|
|
@@ -34,7 +64,7 @@ export const getSchemaSpecs = (opts, placeholder) => {
|
|
|
34
64
|
},
|
|
35
65
|
[CheckboxNode.Label]: {
|
|
36
66
|
content: 'inline*',
|
|
37
|
-
group: 'block',
|
|
67
|
+
group: 'block checkbox',
|
|
38
68
|
parseDOM: [
|
|
39
69
|
{
|
|
40
70
|
tag: `span[class="${b('label')}"]`,
|
|
@@ -42,6 +72,13 @@ export const getSchemaSpecs = (opts, placeholder) => {
|
|
|
42
72
|
[CheckboxAttr.For]: node.getAttribute(CheckboxAttr.For) || '',
|
|
43
73
|
}),
|
|
44
74
|
},
|
|
75
|
+
{
|
|
76
|
+
// input handled by checkbox node parse rule
|
|
77
|
+
// ignore label
|
|
78
|
+
tag: 'input[type=checkbox] ~ label[for]',
|
|
79
|
+
ignore: true,
|
|
80
|
+
consuming: true,
|
|
81
|
+
},
|
|
45
82
|
],
|
|
46
83
|
attrs: {
|
|
47
84
|
[CheckboxAttr.For]: { default: null },
|
|
@@ -3,6 +3,7 @@ import { CheckboxSpecs } from './CheckboxSpecs';
|
|
|
3
3
|
import { addCheckbox } from './actions';
|
|
4
4
|
import { CheckboxInputView } from './nodeviews';
|
|
5
5
|
import { keymapPlugin } from './plugin';
|
|
6
|
+
import { fixPastePlugin } from './plugins/fix-paste';
|
|
6
7
|
import { checkboxInputType, checkboxType } from './utils';
|
|
7
8
|
import './index.css';
|
|
8
9
|
const checkboxAction = 'addCheckbox';
|
|
@@ -11,6 +12,7 @@ export const Checkbox = (builder, opts) => {
|
|
|
11
12
|
builder.use(CheckboxSpecs, Object.assign(Object.assign({}, opts), { inputView: () => CheckboxInputView.create }));
|
|
12
13
|
builder
|
|
13
14
|
.addPlugin(keymapPlugin, builder.Priority.High)
|
|
15
|
+
.addPlugin(fixPastePlugin)
|
|
14
16
|
.addAction(checkboxAction, () => addCheckbox())
|
|
15
17
|
.addInputRules(({ schema }) => ({
|
|
16
18
|
rules: [
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Slice } from 'prosemirror-model';
|
|
2
|
+
import { Plugin } from 'prosemirror-state';
|
|
3
|
+
import { checkboxType } from '../CheckboxSpecs';
|
|
4
|
+
export const fixPastePlugin = () => new Plugin({
|
|
5
|
+
props: {
|
|
6
|
+
transformPasted(slice) {
|
|
7
|
+
const { firstChild } = slice.content;
|
|
8
|
+
if (firstChild && firstChild.type === checkboxType(firstChild.type.schema)) {
|
|
9
|
+
// When paste html with checkboxes and checkbox is first node,
|
|
10
|
+
// pm creates slice with broken openStart and openEnd.
|
|
11
|
+
// And content is inserted without a container block for checkboxes.
|
|
12
|
+
// It is fixed by create new slice with zeroed openStart and openEnd.
|
|
13
|
+
return new Slice(slice.content, 0, 0);
|
|
14
|
+
}
|
|
15
|
+
return slice;
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Node, NodeType, Schema } from 'prosemirror-model';
|
|
1
|
+
import { Node, type NodeType, type Schema } from 'prosemirror-model';
|
|
2
2
|
export declare const nodeTypeFactory: (nodeName: string) => (schema: Schema) => NodeType;
|
|
3
3
|
export declare const markTypeFactory: (markName: string) => (schema: Schema) => import("prosemirror-model").MarkType;
|
|
4
4
|
export declare function isSameNodeType(a: Node | NodeType, b: Node | NodeType): boolean;
|
package/build/esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** During build process, the current version will be injected here */
|
|
2
|
-
export const VERSION = typeof '14.
|
|
2
|
+
export const VERSION = typeof '14.7.0' !== 'undefined' ? '14.7.0' : 'unknown';
|
package/build/styles.css
CHANGED
|
@@ -607,24 +607,66 @@
|
|
|
607
607
|
display: inline-block;
|
|
608
608
|
margin-top: 8px;
|
|
609
609
|
}
|
|
610
|
+
.g-md-toolbar-colors__menu-icon_color_gray {
|
|
611
|
+
color: var(--yfm-colorify-gray);
|
|
612
|
+
}
|
|
613
|
+
.g-md-toolbar-colors__chevron-icon_color_gray {
|
|
614
|
+
color: var(--yfm-colorify-gray);
|
|
615
|
+
}
|
|
610
616
|
.g-md-toolbar-colors__item-icon_color_gray {
|
|
611
617
|
color: var(--yfm-colorify-gray);
|
|
612
618
|
}
|
|
619
|
+
.g-md-toolbar-colors__menu-icon_color_yellow {
|
|
620
|
+
color: var(--yfm-colorify-yellow);
|
|
621
|
+
}
|
|
622
|
+
.g-md-toolbar-colors__chevron-icon_color_yellow {
|
|
623
|
+
color: var(--yfm-colorify-yellow);
|
|
624
|
+
}
|
|
613
625
|
.g-md-toolbar-colors__item-icon_color_yellow {
|
|
614
626
|
color: var(--yfm-colorify-yellow);
|
|
615
627
|
}
|
|
628
|
+
.g-md-toolbar-colors__menu-icon_color_orange {
|
|
629
|
+
color: var(--yfm-colorify-orange);
|
|
630
|
+
}
|
|
631
|
+
.g-md-toolbar-colors__chevron-icon_color_orange {
|
|
632
|
+
color: var(--yfm-colorify-orange);
|
|
633
|
+
}
|
|
616
634
|
.g-md-toolbar-colors__item-icon_color_orange {
|
|
617
635
|
color: var(--yfm-colorify-orange);
|
|
618
636
|
}
|
|
637
|
+
.g-md-toolbar-colors__menu-icon_color_red {
|
|
638
|
+
color: var(--yfm-colorify-red);
|
|
639
|
+
}
|
|
640
|
+
.g-md-toolbar-colors__chevron-icon_color_red {
|
|
641
|
+
color: var(--yfm-colorify-red);
|
|
642
|
+
}
|
|
619
643
|
.g-md-toolbar-colors__item-icon_color_red {
|
|
620
644
|
color: var(--yfm-colorify-red);
|
|
621
645
|
}
|
|
646
|
+
.g-md-toolbar-colors__menu-icon_color_green {
|
|
647
|
+
color: var(--yfm-colorify-green);
|
|
648
|
+
}
|
|
649
|
+
.g-md-toolbar-colors__chevron-icon_color_green {
|
|
650
|
+
color: var(--yfm-colorify-green);
|
|
651
|
+
}
|
|
622
652
|
.g-md-toolbar-colors__item-icon_color_green {
|
|
623
653
|
color: var(--yfm-colorify-green);
|
|
624
654
|
}
|
|
655
|
+
.g-md-toolbar-colors__menu-icon_color_blue {
|
|
656
|
+
color: var(--yfm-colorify-blue);
|
|
657
|
+
}
|
|
658
|
+
.g-md-toolbar-colors__chevron-icon_color_blue {
|
|
659
|
+
color: var(--yfm-colorify-blue);
|
|
660
|
+
}
|
|
625
661
|
.g-md-toolbar-colors__item-icon_color_blue {
|
|
626
662
|
color: var(--yfm-colorify-blue);
|
|
627
663
|
}
|
|
664
|
+
.g-md-toolbar-colors__menu-icon_color_violet {
|
|
665
|
+
color: var(--yfm-colorify-violet);
|
|
666
|
+
}
|
|
667
|
+
.g-md-toolbar-colors__chevron-icon_color_violet {
|
|
668
|
+
color: var(--yfm-colorify-violet);
|
|
669
|
+
}
|
|
628
670
|
.g-md-toolbar-colors__item-icon_color_violet {
|
|
629
671
|
color: var(--yfm-colorify-violet);
|
|
630
672
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gravity-ui/markdown-editor",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.7.0",
|
|
4
4
|
"description": "Markdown wysiwyg and markup editor",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -170,7 +170,7 @@
|
|
|
170
170
|
"@gravity-ui/i18n": "^1.1.0",
|
|
171
171
|
"@gravity-ui/icons": "^2.10.0",
|
|
172
172
|
"@lezer/highlight": "~1.2.1",
|
|
173
|
-
"@lezer/markdown": "~1.3.
|
|
173
|
+
"@lezer/markdown": "~1.3.2",
|
|
174
174
|
"@types/is-number": "^7.0.1",
|
|
175
175
|
"@types/markdown-it": "^12.2.3",
|
|
176
176
|
"base64-arraybuffer": "1.0.2",
|
|
@@ -300,8 +300,8 @@
|
|
|
300
300
|
"lodash": "^4.17.20",
|
|
301
301
|
"lowlight": "^3.0.0",
|
|
302
302
|
"markdown-it": "^13.0.0",
|
|
303
|
-
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
304
|
-
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
303
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
304
|
+
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
305
305
|
},
|
|
306
306
|
"lint-staged": {
|
|
307
307
|
"*.{css,scss}": [
|