art-bd-ui 1.0.37 → 1.0.39
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/dist/cjs/_virtual/index5.js +2 -8
- package/dist/cjs/_virtual/index6.js +4 -4
- package/dist/cjs/_virtual/index7.js +8 -2
- package/dist/cjs/components/quiz/runner/question/question.js +9 -2
- package/dist/cjs/components/ui/rich-editor/bubble-menus/code-block-bubble-menu.js +21 -8
- package/dist/cjs/components/ui/rich-editor/extensions/carousel/extension.js +5 -0
- package/dist/cjs/components/ui/rich-editor/extensions/carousel/view.js +2 -1
- package/dist/cjs/components/ui/rich-editor/extensions/code-block/index.js +26 -0
- package/dist/cjs/components/ui/rich-editor/extensions/code-block/lowlight-base.js +108 -0
- package/dist/cjs/components/ui/rich-editor/extensions/code-block/node-view.js +63 -0
- package/dist/cjs/components/ui/rich-editor/extensions/code-block/utils.js +159 -0
- package/dist/cjs/components/ui/rich-editor/extensions/columns/extension.js +243 -0
- package/dist/cjs/components/ui/rich-editor/extensions/columns/node-view.js +12 -0
- package/dist/cjs/components/ui/rich-editor/extensions/columns/utils.js +76 -0
- package/dist/cjs/components/ui/rich-editor/extensions/columns.js +4 -10
- package/dist/cjs/components/ui/rich-editor/extensions/table/kit.js +58 -0
- package/dist/cjs/components/ui/rich-editor/extensions/table/table-cell.js +20 -0
- package/dist/cjs/components/ui/rich-editor/extensions/table/table-floating-controls.js +20 -4
- package/dist/cjs/components/ui/rich-editor/extensions/table/table-header.js +20 -0
- package/dist/cjs/components/ui/rich-editor/extensions/table/table-row.js +14 -0
- package/dist/cjs/components/ui/rich-editor/extensions/table/table.js +22 -0
- package/dist/cjs/components/ui/rich-editor/extensions.js +28 -9
- package/dist/cjs/components/ui/rich-editor/rich-editor.js +6 -6
- package/dist/cjs/node_modules/@ckeditor/ckeditor5-mention/dist/index.js +1 -1
- package/dist/cjs/node_modules/@ckeditor/ckeditor5-paragraph/dist/index.js +1 -1
- package/dist/cjs/node_modules/@ckeditor/ckeditor5-ui/dist/index.js +1 -1
- package/dist/cjs/node_modules/color-parse/index.js +1 -1
- package/dist/cjs/node_modules/prop-types/index.js +1 -1
- package/dist/esm/_virtual/index5.js +2 -6
- package/dist/esm/_virtual/index6.js +4 -4
- package/dist/esm/_virtual/index7.js +6 -2
- package/dist/esm/components/quiz/runner/question/question.js +9 -2
- package/dist/esm/components/ui/rich-editor/bubble-menus/code-block-bubble-menu.js +15 -2
- package/dist/esm/components/ui/rich-editor/extensions/carousel/extension.js +5 -0
- package/dist/esm/components/ui/rich-editor/extensions/carousel/view.js +2 -1
- package/dist/esm/components/ui/rich-editor/extensions/code-block/index.js +12 -0
- package/dist/esm/components/ui/rich-editor/extensions/code-block/lowlight-base.js +106 -0
- package/dist/esm/components/ui/rich-editor/extensions/code-block/node-view.js +42 -0
- package/dist/esm/components/ui/rich-editor/extensions/code-block/utils.js +148 -0
- package/dist/esm/components/ui/rich-editor/extensions/columns/extension.js +240 -0
- package/dist/esm/components/ui/rich-editor/extensions/columns/node-view.js +10 -0
- package/dist/esm/components/ui/rich-editor/extensions/columns/utils.js +73 -0
- package/dist/esm/components/ui/rich-editor/extensions/columns.js +4 -10
- package/dist/esm/components/ui/rich-editor/extensions/table/kit.js +56 -0
- package/dist/esm/components/ui/rich-editor/extensions/table/table-cell.js +18 -0
- package/dist/esm/components/ui/rich-editor/extensions/table/table-floating-controls.js +20 -4
- package/dist/esm/components/ui/rich-editor/extensions/table/table-header.js +18 -0
- package/dist/esm/components/ui/rich-editor/extensions/table/table-row.js +12 -0
- package/dist/esm/components/ui/rich-editor/extensions/table/table.js +20 -0
- package/dist/esm/components/ui/rich-editor/extensions.js +23 -4
- package/dist/esm/components/ui/rich-editor/rich-editor.js +1 -1
- package/dist/esm/node_modules/@ckeditor/ckeditor5-mention/dist/index.js +1 -1
- package/dist/esm/node_modules/@ckeditor/ckeditor5-paragraph/dist/index.js +1 -1
- package/dist/esm/node_modules/@ckeditor/ckeditor5-ui/dist/index.js +1 -1
- package/dist/esm/node_modules/color-parse/index.js +1 -1
- package/dist/esm/node_modules/prop-types/index.js +1 -1
- package/dist/types/index.d.ts +20 -20
- package/package.json +1 -1
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
var propTypes = {exports: {}};
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
var index = require('../node_modules/color-name/index.js');
|
|
7
|
-
|
|
8
|
-
var colorNameExports = index.__require();
|
|
9
|
-
var names = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(colorNameExports);
|
|
10
|
-
|
|
11
|
-
exports.default = names;
|
|
5
|
+
exports.__module = propTypes;
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var _commonjsHelpers = require('./_commonjsHelpers.js');
|
|
6
|
-
var index
|
|
6
|
+
var index = require('../node_modules/color-name/index.js');
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
var
|
|
8
|
+
var colorNameExports = index.__require();
|
|
9
|
+
var names = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(colorNameExports);
|
|
10
10
|
|
|
11
|
-
exports.default =
|
|
11
|
+
exports.default = names;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
var _commonjsHelpers = require('./_commonjsHelpers.js');
|
|
6
|
+
var index$1 = require('../node_modules/color-convert/index.js');
|
|
7
|
+
|
|
8
|
+
var colorConvertExports = index$1.__require();
|
|
9
|
+
var index = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(colorConvertExports);
|
|
10
|
+
|
|
11
|
+
exports.default = index;
|
|
@@ -13,7 +13,7 @@ require('../../../ui/rich-editor/extensions/carousel/extension.js');
|
|
|
13
13
|
require('../../../ui/rich-editor/extensions/carousel/editor.js');
|
|
14
14
|
require('../../../ui/carousel/carousel.js');
|
|
15
15
|
require('../../../forms/file-upload/file-upload.js');
|
|
16
|
-
require('../../../ui/rich-editor/extensions/code-block
|
|
16
|
+
require('../../../ui/rich-editor/extensions/code-block/index.js');
|
|
17
17
|
require('../../../ui/rich-editor/extensions.js');
|
|
18
18
|
require('react-dom');
|
|
19
19
|
require('../../../../node_modules/prosemirror-tables/dist/index.js');
|
|
@@ -29,7 +29,14 @@ require('../../../ui/rich-editor/toolbar/dropdowns.js');
|
|
|
29
29
|
require('../../../forms/label/label.js');
|
|
30
30
|
require('../../../utility/separator/separator.js');
|
|
31
31
|
require('../../../popovers/shared/icon-close.js');
|
|
32
|
-
require('../../../ui/rich-editor/extensions/code-block
|
|
32
|
+
require('../../../ui/rich-editor/extensions/code-block/utils.js');
|
|
33
|
+
require('../../../ui/rich-editor/extensions/table/table.js');
|
|
34
|
+
require('../../../../node_modules/@tiptap/extension-table/dist/index.js');
|
|
35
|
+
require('../../../ui/rich-editor/extensions/table/table-header.js');
|
|
36
|
+
require('../../../ui/rich-editor/extensions/table/table-cell.js');
|
|
37
|
+
require('../../../ui/rich-editor/extensions/table/table-cell-style.js');
|
|
38
|
+
require('../../../ui/rich-editor/extensions/table/kit.js');
|
|
39
|
+
require('../../../ui/rich-editor/extensions/table/table-actions-extension.js');
|
|
33
40
|
require('../../../ui/rich-editor/extensions/table/table-selection-overlay.js');
|
|
34
41
|
require('../../../ui/rich-editor/bubble-menus/shared.js');
|
|
35
42
|
require('../../../forms/select/select.js');
|
|
@@ -4,10 +4,23 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
4
4
|
var React = require('react');
|
|
5
5
|
var index = require('../../../../node_modules/@tiptap/react/dist/index.js');
|
|
6
6
|
var index$1 = require('../../../../node_modules/@tiptap/react/dist/menus/index.js');
|
|
7
|
-
var
|
|
7
|
+
var utils = require('../extensions/code-block/utils.js');
|
|
8
|
+
require('../extensions/table/table.js');
|
|
9
|
+
require('../../../../node_modules/@tiptap/extension-table/dist/index.js');
|
|
10
|
+
require('../extensions/table/table-header.js');
|
|
11
|
+
require('../extensions/table/table-cell.js');
|
|
12
|
+
require('../extensions/table/table-cell-style.js');
|
|
13
|
+
require('../extensions/table/kit.js');
|
|
14
|
+
require('../extensions/table/table-actions-extension.js');
|
|
8
15
|
var tableSelectionOverlay = require('../extensions/table/table-selection-overlay.js');
|
|
9
|
-
|
|
16
|
+
require('../extensions/table/table-hover-extension.js');
|
|
17
|
+
require('react-dom');
|
|
18
|
+
require('../../../../node_modules/prosemirror-tables/dist/index.js');
|
|
19
|
+
require('../../dropdown-menu/dropdown-menu.js');
|
|
10
20
|
var button = require('../../../buttons/button/button.js');
|
|
21
|
+
require('../../../popovers/popover/popover.js');
|
|
22
|
+
require('../../../forms/input/input.js');
|
|
23
|
+
var shared = require('./shared.js');
|
|
11
24
|
var select = require('../../../forms/select/select.js');
|
|
12
25
|
var separator = require('../../../utility/separator/separator.js');
|
|
13
26
|
var wandSparkles = require('../../../../node_modules/lucide-react/dist/esm/icons/wand-sparkles.js');
|
|
@@ -21,14 +34,14 @@ function CodeBlockBubbleMenu({ editor }) {
|
|
|
21
34
|
const codeBlockAttrs = editor.getAttributes("codeBlock");
|
|
22
35
|
const rawCodeBlockLanguage = typeof codeBlockAttrs.language === "string" ? codeBlockAttrs.language : null;
|
|
23
36
|
const rawCodeBlockTheme = typeof codeBlockAttrs.theme === "string" ? codeBlockAttrs.theme : null;
|
|
24
|
-
const resolvedCodeBlockLanguage =
|
|
37
|
+
const resolvedCodeBlockLanguage = utils.resolveCodeBlockLanguage(rawCodeBlockLanguage);
|
|
25
38
|
const activeCodeBlockLanguage = resolvedCodeBlockLanguage && resolvedCodeBlockLanguage !== "plaintext"
|
|
26
39
|
? resolvedCodeBlockLanguage
|
|
27
40
|
: shared.PLAIN_CODE_BLOCK_LANGUAGE_VALUE;
|
|
28
41
|
return {
|
|
29
42
|
activeCodeBlockLanguage,
|
|
30
|
-
activeCodeBlockTheme:
|
|
31
|
-
canPrettifyActiveCodeBlock: editor.isActive("codeBlock") &&
|
|
43
|
+
activeCodeBlockTheme: utils.resolveCodeBlockTheme(rawCodeBlockTheme),
|
|
44
|
+
canPrettifyActiveCodeBlock: editor.isActive("codeBlock") && utils.canPrettifyCodeLanguage(rawCodeBlockLanguage),
|
|
32
45
|
};
|
|
33
46
|
},
|
|
34
47
|
});
|
|
@@ -60,15 +73,15 @@ function CodeBlockBubbleMenu({ editor }) {
|
|
|
60
73
|
language: value === shared.PLAIN_CODE_BLOCK_LANGUAGE_VALUE ? null : value,
|
|
61
74
|
})
|
|
62
75
|
.run();
|
|
63
|
-
}, children: [jsxRuntime.jsx(select.SelectTrigger, { className: "h-8 w-[170px] gap-1 border-0 bg-transparent px-2 text-xs font-medium text-muted-foreground shadow-none focus:ring-0 focus-visible:ring-0", children: jsxRuntime.jsx(select.SelectValue, { placeholder: "Plain text" }) }), jsxRuntime.jsxs(select.SelectContent, { portal: false, align: "start", className: "max-h-64", children: [jsxRuntime.jsx(select.SelectItem, { value: shared.PLAIN_CODE_BLOCK_LANGUAGE_VALUE, className: "text-xs", children: "Plain text" }),
|
|
76
|
+
}, children: [jsxRuntime.jsx(select.SelectTrigger, { className: "h-8 w-[170px] gap-1 border-0 bg-transparent px-2 text-xs font-medium text-muted-foreground shadow-none focus:ring-0 focus-visible:ring-0", children: jsxRuntime.jsx(select.SelectValue, { placeholder: "Plain text" }) }), jsxRuntime.jsxs(select.SelectContent, { portal: false, align: "start", className: "max-h-64", children: [jsxRuntime.jsx(select.SelectItem, { value: shared.PLAIN_CODE_BLOCK_LANGUAGE_VALUE, className: "text-xs", children: "Plain text" }), utils.CODE_BLOCK_LANGUAGE_OPTIONS.filter((option) => option.value !== "plaintext").map((option) => (jsxRuntime.jsx(select.SelectItem, { value: option.value, className: "text-xs", children: option.label }, option.value)))] })] }), jsxRuntime.jsxs(select.Select, { value: activeCodeBlockTheme, disabled: !editor.isEditable, onOpenChange: setThemeMenuOpen, onValueChange: (value) => {
|
|
64
77
|
editor
|
|
65
78
|
.chain()
|
|
66
79
|
.focus()
|
|
67
80
|
.updateAttributes("codeBlock", {
|
|
68
|
-
theme:
|
|
81
|
+
theme: utils.resolveCodeBlockTheme(value),
|
|
69
82
|
})
|
|
70
83
|
.run();
|
|
71
|
-
}, children: [jsxRuntime.jsx(select.SelectTrigger, { className: "h-8 w-[145px] gap-1 border-0 bg-transparent px-2 text-xs font-medium text-muted-foreground shadow-none focus:ring-0 focus-visible:ring-0", children: jsxRuntime.jsx(select.SelectValue, { placeholder: "Theme" }) }), jsxRuntime.jsx(select.SelectContent, { portal: false, align: "start", children:
|
|
84
|
+
}, children: [jsxRuntime.jsx(select.SelectTrigger, { className: "h-8 w-[145px] gap-1 border-0 bg-transparent px-2 text-xs font-medium text-muted-foreground shadow-none focus:ring-0 focus-visible:ring-0", children: jsxRuntime.jsx(select.SelectValue, { placeholder: "Theme" }) }), jsxRuntime.jsx(select.SelectContent, { portal: false, align: "start", children: utils.CODE_BLOCK_THEME_OPTIONS.map((option) => (jsxRuntime.jsx(select.SelectItem, { value: option.value, className: "text-xs", children: option.label }, option.value))) })] }), jsxRuntime.jsx(separator.Separator, { orientation: "vertical", className: "mx-1 h-5" }), jsxRuntime.jsx(button.Button, { type: "button", variant: "ghost", size: "icon-sm", className: "size-8", onClick: () => editor.commands.formatCodeBlock(), disabled: !editor.isEditable || !canPrettifyActiveCodeBlock, "aria-label": "Prettify code", title: canPrettifyActiveCodeBlock ? "Prettify code (⌘S)" : "Prettify not available for this language", children: jsxRuntime.jsx(wandSparkles.default, { className: "size-4" }) })] }) }));
|
|
72
85
|
}
|
|
73
86
|
|
|
74
87
|
exports.CodeBlockBubbleMenu = CodeBlockBubbleMenu;
|
|
@@ -4,7 +4,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var tslib_es6 = require('../../../../../node_modules/tslib/tslib.es6.js');
|
|
6
6
|
var index = require('../../../../../node_modules/@tiptap/core/dist/index.js');
|
|
7
|
+
var index$1 = require('../../../../../node_modules/@tiptap/react/dist/index.js');
|
|
7
8
|
var config = require('./config.js');
|
|
9
|
+
var view = require('./view.js');
|
|
8
10
|
|
|
9
11
|
function parseDataValue(element, key) {
|
|
10
12
|
const value = element.getAttribute(key);
|
|
@@ -112,6 +114,9 @@ const Carousel = index.Node.create({
|
|
|
112
114
|
{ "data-peek-amount": `${rest.partialVisiblePercent}%` }, { "data-pagination": String(rest.showThumbnails) }),
|
|
113
115
|
];
|
|
114
116
|
},
|
|
117
|
+
addNodeView() {
|
|
118
|
+
return index$1.ReactNodeViewRenderer(view.CarouselView);
|
|
119
|
+
},
|
|
115
120
|
});
|
|
116
121
|
|
|
117
122
|
exports.Carousel = Carousel;
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var React = require('react');
|
|
5
|
+
var index = require('../../../../../node_modules/@tiptap/react/dist/index.js');
|
|
5
6
|
var config = require('./config.js');
|
|
6
7
|
var shared = require('./shared.js');
|
|
7
8
|
|
|
8
9
|
const CarouselView = ({ node }) => {
|
|
9
10
|
const attrs = React.useMemo(() => config.normalizeCarouselAttrs((node.attrs || {})), [node.attrs]);
|
|
10
|
-
return jsxRuntime.jsx(shared.SharedCarousel, { images: attrs.images, opts: attrs });
|
|
11
|
+
return (jsxRuntime.jsx(index.NodeViewWrapper, { children: jsxRuntime.jsx(shared.SharedCarousel, { images: attrs.images, opts: attrs }) }));
|
|
11
12
|
};
|
|
12
13
|
|
|
13
14
|
exports.CarouselView = CarouselView;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('./utils.js');
|
|
4
|
+
var lowlightBase = require('./lowlight-base.js');
|
|
5
|
+
var nodeView = require('./node-view.js');
|
|
6
|
+
var index = require('../../../../../node_modules/@tiptap/react/dist/index.js');
|
|
7
|
+
|
|
8
|
+
const CodeBlockLowlight = lowlightBase.CodeBlockLowlightBase.extend({
|
|
9
|
+
addNodeView() {
|
|
10
|
+
return index.ReactNodeViewRenderer(nodeView.CodeBlockNodeView);
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
exports.CODE_BLOCK_LANGUAGE_OPTIONS = utils.CODE_BLOCK_LANGUAGE_OPTIONS;
|
|
15
|
+
exports.CODE_BLOCK_THEME_OPTIONS = utils.CODE_BLOCK_THEME_OPTIONS;
|
|
16
|
+
exports.DEFAULT_CODE_BLOCK_THEME = utils.DEFAULT_CODE_BLOCK_THEME;
|
|
17
|
+
exports.GITHUB_CODE_BLOCK_CLASS = utils.GITHUB_CODE_BLOCK_CLASS;
|
|
18
|
+
exports.canPrettifyCodeLanguage = utils.canPrettifyCodeLanguage;
|
|
19
|
+
exports.codeBlockLowlight = utils.codeBlockLowlight;
|
|
20
|
+
exports.codeBlockThemeClassName = utils.codeBlockThemeClassName;
|
|
21
|
+
exports.prettifyCode = utils.prettifyCode;
|
|
22
|
+
exports.resolveCodeBlockLanguage = utils.resolveCodeBlockLanguage;
|
|
23
|
+
exports.resolveCodeBlockTheme = utils.resolveCodeBlockTheme;
|
|
24
|
+
exports.CodeBlockLowlightBase = lowlightBase.CodeBlockLowlightBase;
|
|
25
|
+
exports.CodeBlockNodeView = nodeView.CodeBlockNodeView;
|
|
26
|
+
exports.CodeBlockLowlight = CodeBlockLowlight;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tslib_es6 = require('../../../../../node_modules/tslib/tslib.es6.js');
|
|
4
|
+
var index = require('../../../../../node_modules/@tiptap/extension-code-block-lowlight/dist/index.js');
|
|
5
|
+
var index$1 = require('../../../../../node_modules/prosemirror-state/dist/index.js');
|
|
6
|
+
var utils = require('./utils.js');
|
|
7
|
+
|
|
8
|
+
const CodeBlockLowlightBase = index.default.extend({
|
|
9
|
+
addAttributes() {
|
|
10
|
+
var _a;
|
|
11
|
+
return Object.assign(Object.assign({}, (_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this)), { theme: {
|
|
12
|
+
default: utils.DEFAULT_CODE_BLOCK_THEME,
|
|
13
|
+
parseHTML: (element) => {
|
|
14
|
+
var _a;
|
|
15
|
+
const rawTheme = (_a = element === null || element === void 0 ? void 0 : element.getAttribute) === null || _a === void 0 ? void 0 : _a.call(element, "data-theme");
|
|
16
|
+
return utils.resolveCodeBlockTheme(rawTheme);
|
|
17
|
+
},
|
|
18
|
+
renderHTML: (attributes) => {
|
|
19
|
+
const theme = utils.resolveCodeBlockTheme(attributes.theme);
|
|
20
|
+
return {
|
|
21
|
+
"data-theme": theme,
|
|
22
|
+
class: utils.codeBlockThemeClassName(theme),
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
} });
|
|
26
|
+
},
|
|
27
|
+
addCommands() {
|
|
28
|
+
var _a;
|
|
29
|
+
return Object.assign(Object.assign({}, (_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this)), { formatCodeBlock: () => ({ state }) => {
|
|
30
|
+
const currentCodeBlock = findCodeBlockAtSelection(state);
|
|
31
|
+
if (!currentCodeBlock) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const code = currentCodeBlock.node.textContent || "";
|
|
35
|
+
const language = currentCodeBlock.node.attrs.language;
|
|
36
|
+
if (!code.trim()) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
if (!utils.canPrettifyCodeLanguage(language)) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
const codeBlockPos = currentCodeBlock.pos;
|
|
43
|
+
void (() => tslib_es6.__awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
try {
|
|
45
|
+
const formattedCode = yield utils.prettifyCode(code, language);
|
|
46
|
+
if (!formattedCode || formattedCode === code || this.editor.isDestroyed) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const currentSelection = this.editor.state.selection;
|
|
50
|
+
const relativePos = Math.max(0, currentSelection.from - codeBlockPos - 1);
|
|
51
|
+
const from = codeBlockPos;
|
|
52
|
+
const to = from + currentCodeBlock.node.nodeSize;
|
|
53
|
+
const newTr = this.editor.state.tr;
|
|
54
|
+
newTr.replaceRangeWith(from, to, this.editor.state.schema.nodes.codeBlock.create(currentCodeBlock.node.attrs, this.editor.state.schema.text(formattedCode)));
|
|
55
|
+
const newCursorPos = from + 1 + Math.min(relativePos, formattedCode.length);
|
|
56
|
+
newTr.setSelection(index$1.TextSelection.near(newTr.doc.resolve(newCursorPos)));
|
|
57
|
+
this.editor.view.dispatch(newTr);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.error("Format error:", error);
|
|
61
|
+
}
|
|
62
|
+
}))();
|
|
63
|
+
return true;
|
|
64
|
+
} });
|
|
65
|
+
},
|
|
66
|
+
addKeyboardShortcuts() {
|
|
67
|
+
var _a;
|
|
68
|
+
return Object.assign(Object.assign({}, (_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this)), { "Mod-s": () => {
|
|
69
|
+
const currentCodeBlock = findCodeBlockAtSelection(this.editor.state);
|
|
70
|
+
const language = currentCodeBlock === null || currentCodeBlock === void 0 ? void 0 : currentCodeBlock.node.attrs.language;
|
|
71
|
+
if (!currentCodeBlock || !utils.canPrettifyCodeLanguage(language)) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
return this.editor.commands.formatCodeBlock();
|
|
75
|
+
} });
|
|
76
|
+
},
|
|
77
|
+
}).configure({
|
|
78
|
+
lowlight: utils.codeBlockLowlight,
|
|
79
|
+
enableTabIndentation: true,
|
|
80
|
+
HTMLAttributes: {
|
|
81
|
+
class: `${utils.GITHUB_CODE_BLOCK_CLASS} ${utils.codeBlockThemeClassName(utils.DEFAULT_CODE_BLOCK_THEME)} not-prose my-4 overflow-x-auto rounded-lg border px-4 py-3 font-mono text-[13px] leading-6`,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
function findCodeBlockAtSelection(state) {
|
|
85
|
+
const codeBlockNodeType = state.schema.nodes.codeBlock;
|
|
86
|
+
if (!codeBlockNodeType)
|
|
87
|
+
return null;
|
|
88
|
+
const selectedNode = state.selection.node;
|
|
89
|
+
if ((selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.type) === codeBlockNodeType) {
|
|
90
|
+
return {
|
|
91
|
+
node: selectedNode,
|
|
92
|
+
pos: state.selection.from,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const { $from } = state.selection;
|
|
96
|
+
for (let depth = $from.depth; depth > 0; depth -= 1) {
|
|
97
|
+
const node = $from.node(depth);
|
|
98
|
+
if (node.type === codeBlockNodeType) {
|
|
99
|
+
return {
|
|
100
|
+
node,
|
|
101
|
+
pos: $from.before(depth),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
exports.CodeBlockLowlightBase = CodeBlockLowlightBase;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var tslib_es6 = require('../../../../../node_modules/tslib/tslib.es6.js');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var index = require('../../../../../node_modules/@tiptap/react/dist/index.js');
|
|
8
|
+
var utils$1 = require('./utils.js');
|
|
9
|
+
var utils = require('../../../../../lib/utils.js');
|
|
10
|
+
var check = require('../../../../../node_modules/lucide-react/dist/esm/icons/check.js');
|
|
11
|
+
var clipboard = require('../../../../../node_modules/lucide-react/dist/esm/icons/clipboard.js');
|
|
12
|
+
|
|
13
|
+
function _interopNamespaceDefault(e) {
|
|
14
|
+
var n = Object.create(null);
|
|
15
|
+
if (e) {
|
|
16
|
+
Object.keys(e).forEach(function (k) {
|
|
17
|
+
if (k !== 'default') {
|
|
18
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return e[k]; }
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
n.default = e;
|
|
27
|
+
return Object.freeze(n);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
31
|
+
|
|
32
|
+
function CodeBlockNodeView({ node, selected }) {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
const languageAttr = (_a = node.attrs.language) !== null && _a !== void 0 ? _a : null;
|
|
35
|
+
const themeAttr = (_b = node.attrs.theme) !== null && _b !== void 0 ? _b : null;
|
|
36
|
+
const [copied, setCopied] = React__namespace.useState(false);
|
|
37
|
+
React__namespace.useEffect(() => {
|
|
38
|
+
if (!copied)
|
|
39
|
+
return;
|
|
40
|
+
const timeout = window.setTimeout(() => setCopied(false), 1500);
|
|
41
|
+
return () => window.clearTimeout(timeout);
|
|
42
|
+
}, [copied]);
|
|
43
|
+
const handleCopy = React__namespace.useCallback(() => tslib_es6.__awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
var _a;
|
|
45
|
+
const text = node.textContent || "";
|
|
46
|
+
if (!text.trim()) {
|
|
47
|
+
setCopied(false);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
if (typeof navigator !== "undefined" && ((_a = navigator.clipboard) === null || _a === void 0 ? void 0 : _a.writeText)) {
|
|
52
|
+
yield navigator.clipboard.writeText(text);
|
|
53
|
+
setCopied(true);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (_b) {
|
|
57
|
+
setCopied(false);
|
|
58
|
+
}
|
|
59
|
+
}), [node]);
|
|
60
|
+
return (jsxRuntime.jsxs(index.NodeViewWrapper, { className: utils.cn(`${utils$1.GITHUB_CODE_BLOCK_CLASS} ${utils$1.codeBlockThemeClassName(themeAttr)} group relative my-4 overflow-hidden rounded-lg border`, selected ? "ring-2 ring-ring" : undefined), "data-drag-handle": true, children: [jsxRuntime.jsxs("button", { type: "button", className: "absolute right-2.5 top-2.5 z-10 inline-flex h-6 items-center gap-1 rounded-md border bg-background/95 px-1.5 text-[11px] font-medium text-foreground opacity-0 shadow-sm transition-opacity hover:bg-background focus-visible:opacity-100 group-hover:opacity-100 group-focus-within:opacity-100", onClick: handleCopy, "aria-label": copied ? "Copied" : "Copy code", children: [copied ? jsxRuntime.jsx(check.default, { className: "size-3.5" }) : jsxRuntime.jsx(clipboard.default, { className: "size-3.5" }), jsxRuntime.jsx("span", { children: copied ? "Copied" : "Copy" })] }), jsxRuntime.jsx("pre", { className: "m-0 overflow-x-auto bg-transparent px-4 py-3 text-[13px] leading-6", children: jsxRuntime.jsx(index.NodeViewContent, { className: utils.cn("hljs block min-h-[76px] w-full font-mono text-[13px] leading-6 focus:outline-none", languageAttr ? `language-${languageAttr}` : undefined) }) })] }));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
exports.CodeBlockNodeView = CodeBlockNodeView;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tslib_es6 = require('../../../../../node_modules/tslib/tslib.es6.js');
|
|
4
|
+
var standalone = require('../../../../../node_modules/prettier/standalone.js');
|
|
5
|
+
var index = require('../../../../../node_modules/lowlight/lib/index.js');
|
|
6
|
+
var common = require('../../../../../node_modules/lowlight/lib/common.js');
|
|
7
|
+
|
|
8
|
+
const CODE_BLOCK_LANGUAGE_OPTIONS = [
|
|
9
|
+
{ value: "plaintext", label: "Plain text" },
|
|
10
|
+
{ value: "javascript", label: "JavaScript" },
|
|
11
|
+
{ value: "typescript", label: "TypeScript" },
|
|
12
|
+
{ value: "jsx", label: "React (JSX)" },
|
|
13
|
+
{ value: "tsx", label: "React (TSX)" },
|
|
14
|
+
{ value: "nodejs", label: "Node.js" },
|
|
15
|
+
{ value: "html", label: "HTML" },
|
|
16
|
+
{ value: "angular", label: "Angular (HTML Template)" },
|
|
17
|
+
{ value: "vue", label: "Vue" },
|
|
18
|
+
{ value: "css", label: "CSS" },
|
|
19
|
+
{ value: "scss", label: "SCSS" },
|
|
20
|
+
{ value: "less", label: "LESS" },
|
|
21
|
+
{ value: "json", label: "JSON" },
|
|
22
|
+
{ value: "bash", label: "Bash / Shell" },
|
|
23
|
+
{ value: "python", label: "Python" },
|
|
24
|
+
{ value: "java", label: "Java" },
|
|
25
|
+
{ value: "csharp", label: "C#" },
|
|
26
|
+
{ value: "php", label: "PHP" },
|
|
27
|
+
{ value: "markdown", label: "Markdown" },
|
|
28
|
+
{ value: "yaml", label: "YAML" },
|
|
29
|
+
];
|
|
30
|
+
const CODE_BLOCK_THEME_OPTIONS = [
|
|
31
|
+
{ value: "light", label: "Classic Light" },
|
|
32
|
+
{ value: "midnight", label: "Midnight" },
|
|
33
|
+
{ value: "dracula", label: "Dracula" },
|
|
34
|
+
];
|
|
35
|
+
const DEFAULT_CODE_BLOCK_THEME = "light";
|
|
36
|
+
const LANGUAGE_ALIASES = {
|
|
37
|
+
plain: "plaintext",
|
|
38
|
+
text: "plaintext",
|
|
39
|
+
js: "javascript",
|
|
40
|
+
ts: "typescript",
|
|
41
|
+
react: "jsx",
|
|
42
|
+
reactjs: "jsx",
|
|
43
|
+
reacttsx: "tsx",
|
|
44
|
+
node: "nodejs",
|
|
45
|
+
"node.js": "nodejs",
|
|
46
|
+
sh: "bash",
|
|
47
|
+
shell: "bash",
|
|
48
|
+
py: "python",
|
|
49
|
+
cs: "csharp",
|
|
50
|
+
"c#": "csharp",
|
|
51
|
+
md: "markdown",
|
|
52
|
+
yml: "yaml",
|
|
53
|
+
xml: "html",
|
|
54
|
+
};
|
|
55
|
+
const ALLOWED_LANGUAGES = new Set(CODE_BLOCK_LANGUAGE_OPTIONS.map((option) => option.value));
|
|
56
|
+
const ALLOWED_THEMES = new Set(CODE_BLOCK_THEME_OPTIONS.map((option) => option.value));
|
|
57
|
+
const codeBlockLowlight = index.createLowlight(common.grammars);
|
|
58
|
+
new Set(codeBlockLowlight.listLanguages());
|
|
59
|
+
const GITHUB_CODE_BLOCK_CLASS = "gear-code-block-github";
|
|
60
|
+
const resolveCodeBlockTheme = (theme) => {
|
|
61
|
+
if (!theme)
|
|
62
|
+
return DEFAULT_CODE_BLOCK_THEME;
|
|
63
|
+
const normalizedTheme = theme.trim().toLowerCase();
|
|
64
|
+
if (ALLOWED_THEMES.has(normalizedTheme)) {
|
|
65
|
+
return normalizedTheme;
|
|
66
|
+
}
|
|
67
|
+
return DEFAULT_CODE_BLOCK_THEME;
|
|
68
|
+
};
|
|
69
|
+
const codeBlockThemeClassName = (theme) => `gear-code-block-theme-${resolveCodeBlockTheme(theme)}`;
|
|
70
|
+
const PRETTIER_CONFIG_BY_LANGUAGE = {
|
|
71
|
+
javascript: { parser: "babel", plugins: ["babel", "estree"] },
|
|
72
|
+
nodejs: { parser: "babel", plugins: ["babel", "estree"] },
|
|
73
|
+
jsx: { parser: "babel", plugins: ["babel", "estree"] },
|
|
74
|
+
typescript: { parser: "typescript", plugins: ["typescript", "estree"] },
|
|
75
|
+
tsx: { parser: "typescript", plugins: ["typescript", "estree"] },
|
|
76
|
+
json: { parser: "json", plugins: ["babel", "estree"] },
|
|
77
|
+
css: { parser: "css", plugins: ["postcss"] },
|
|
78
|
+
scss: { parser: "scss", plugins: ["postcss"] },
|
|
79
|
+
less: { parser: "less", plugins: ["postcss"] },
|
|
80
|
+
html: { parser: "html", plugins: ["html"] },
|
|
81
|
+
angular: { parser: "angular", plugins: ["html"] },
|
|
82
|
+
vue: { parser: "vue", plugins: ["html"] },
|
|
83
|
+
markdown: { parser: "markdown", plugins: ["markdown"] },
|
|
84
|
+
yaml: { parser: "yaml", plugins: ["yaml"] },
|
|
85
|
+
};
|
|
86
|
+
const PRETTIER_PLUGIN_LOADERS = {
|
|
87
|
+
babel: () => Promise.resolve().then(function () { return require('../../../../../node_modules/prettier/plugins/babel.js'); }),
|
|
88
|
+
typescript: () => Promise.resolve().then(function () { return require('../../../../../node_modules/prettier/plugins/typescript.js'); }),
|
|
89
|
+
estree: () => Promise.resolve().then(function () { return require('../../../../../node_modules/prettier/plugins/estree.js'); }),
|
|
90
|
+
postcss: () => Promise.resolve().then(function () { return require('../../../../../node_modules/prettier/plugins/postcss.js'); }),
|
|
91
|
+
html: () => Promise.resolve().then(function () { return require('../../../../../node_modules/prettier/plugins/html.js'); }),
|
|
92
|
+
markdown: () => Promise.resolve().then(function () { return require('../../../../../node_modules/prettier/plugins/markdown.js'); }),
|
|
93
|
+
yaml: () => Promise.resolve().then(function () { return require('../../../../../node_modules/prettier/plugins/yaml.js'); }),
|
|
94
|
+
};
|
|
95
|
+
const pluginCache = new Map();
|
|
96
|
+
const loadPrettierPlugin = (pluginKey) => {
|
|
97
|
+
if (!pluginCache.has(pluginKey)) {
|
|
98
|
+
pluginCache.set(pluginKey, PRETTIER_PLUGIN_LOADERS[pluginKey]().then((module) => { var _a; return ((_a = module.default) !== null && _a !== void 0 ? _a : module); }));
|
|
99
|
+
}
|
|
100
|
+
return pluginCache.get(pluginKey);
|
|
101
|
+
};
|
|
102
|
+
const normalizeCode = (code) => code
|
|
103
|
+
.replace(/\r\n?/g, "\n")
|
|
104
|
+
.split("\n")
|
|
105
|
+
.map((line) => line.replace(/[ \t]+$/g, ""))
|
|
106
|
+
.join("\n")
|
|
107
|
+
.trimEnd();
|
|
108
|
+
const resolveCodeBlockLanguage = (language) => {
|
|
109
|
+
var _a;
|
|
110
|
+
if (!language)
|
|
111
|
+
return null;
|
|
112
|
+
const normalizedLanguage = language.trim().toLowerCase();
|
|
113
|
+
const resolvedLanguage = (_a = LANGUAGE_ALIASES[normalizedLanguage]) !== null && _a !== void 0 ? _a : normalizedLanguage;
|
|
114
|
+
return ALLOWED_LANGUAGES.has(resolvedLanguage) ? resolvedLanguage : null;
|
|
115
|
+
};
|
|
116
|
+
const canPrettifyCodeLanguage = (language) => {
|
|
117
|
+
const resolvedLanguage = resolveCodeBlockLanguage(language);
|
|
118
|
+
return Boolean(resolvedLanguage && resolvedLanguage !== "plaintext");
|
|
119
|
+
};
|
|
120
|
+
const prettifyCode = (code, language) => tslib_es6.__awaiter(void 0, void 0, void 0, function* () {
|
|
121
|
+
const resolvedLanguage = resolveCodeBlockLanguage(language);
|
|
122
|
+
const normalizedCode = normalizeCode(code);
|
|
123
|
+
if (!resolvedLanguage || resolvedLanguage === "plaintext") {
|
|
124
|
+
return normalizedCode;
|
|
125
|
+
}
|
|
126
|
+
const prettierConfig = PRETTIER_CONFIG_BY_LANGUAGE[resolvedLanguage];
|
|
127
|
+
if (!prettierConfig) {
|
|
128
|
+
return normalizedCode;
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
const plugins = yield Promise.all(prettierConfig.plugins.map(loadPrettierPlugin));
|
|
132
|
+
const formattedCode = yield standalone.format(normalizedCode, {
|
|
133
|
+
parser: prettierConfig.parser,
|
|
134
|
+
plugins,
|
|
135
|
+
printWidth: 100,
|
|
136
|
+
tabWidth: 2,
|
|
137
|
+
semi: true,
|
|
138
|
+
singleQuote: true,
|
|
139
|
+
trailingComma: "all",
|
|
140
|
+
bracketSpacing: true,
|
|
141
|
+
arrowParens: "always",
|
|
142
|
+
});
|
|
143
|
+
return formattedCode.trimEnd();
|
|
144
|
+
}
|
|
145
|
+
catch (_a) {
|
|
146
|
+
return normalizedCode;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
exports.CODE_BLOCK_LANGUAGE_OPTIONS = CODE_BLOCK_LANGUAGE_OPTIONS;
|
|
151
|
+
exports.CODE_BLOCK_THEME_OPTIONS = CODE_BLOCK_THEME_OPTIONS;
|
|
152
|
+
exports.DEFAULT_CODE_BLOCK_THEME = DEFAULT_CODE_BLOCK_THEME;
|
|
153
|
+
exports.GITHUB_CODE_BLOCK_CLASS = GITHUB_CODE_BLOCK_CLASS;
|
|
154
|
+
exports.canPrettifyCodeLanguage = canPrettifyCodeLanguage;
|
|
155
|
+
exports.codeBlockLowlight = codeBlockLowlight;
|
|
156
|
+
exports.codeBlockThemeClassName = codeBlockThemeClassName;
|
|
157
|
+
exports.prettifyCode = prettifyCode;
|
|
158
|
+
exports.resolveCodeBlockLanguage = resolveCodeBlockLanguage;
|
|
159
|
+
exports.resolveCodeBlockTheme = resolveCodeBlockTheme;
|