@atlaskit/editor-plugin-code-block 13.0.0 → 13.1.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/CHANGELOG.md +20 -0
- package/dist/cjs/codeBlockPlugin.js +14 -2
- package/dist/cjs/editor-commands/index.js +182 -7
- package/dist/cjs/pm-plugins/actions.js +6 -3
- package/dist/cjs/pm-plugins/main.js +17 -1
- package/dist/cjs/pm-plugins/toolbar.js +20 -3
- package/dist/cjs/ui/CodeBlockLanguagePicker.js +2 -2
- package/dist/cjs/ui/FormatCodeErrorFlag.js +70 -0
- package/dist/cjs/ui/language-picker-options.js +2 -2
- package/dist/cjs/utils/format-code/format-code-state.js +81 -0
- package/dist/cjs/utils/format-code/formatter-impl.js +15 -0
- package/dist/cjs/utils/format-code/formatter.js +86 -0
- package/dist/es2019/codeBlockPlugin.js +13 -3
- package/dist/es2019/editor-commands/index.js +179 -2
- package/dist/es2019/pm-plugins/actions.js +6 -3
- package/dist/es2019/pm-plugins/main.js +18 -1
- package/dist/es2019/pm-plugins/toolbar.js +21 -4
- package/dist/es2019/ui/CodeBlockLanguagePicker.js +2 -2
- package/dist/es2019/ui/FormatCodeErrorFlag.js +62 -0
- package/dist/es2019/ui/language-picker-options.js +2 -2
- package/dist/es2019/utils/format-code/format-code-state.js +82 -0
- package/dist/es2019/utils/format-code/formatter-impl.js +10 -0
- package/dist/es2019/utils/format-code/formatter.js +47 -0
- package/dist/esm/codeBlockPlugin.js +14 -2
- package/dist/esm/editor-commands/index.js +181 -6
- package/dist/esm/pm-plugins/actions.js +6 -3
- package/dist/esm/pm-plugins/main.js +17 -1
- package/dist/esm/pm-plugins/toolbar.js +21 -4
- package/dist/esm/ui/CodeBlockLanguagePicker.js +2 -2
- package/dist/esm/ui/FormatCodeErrorFlag.js +61 -0
- package/dist/esm/ui/language-picker-options.js +2 -2
- package/dist/esm/utils/format-code/format-code-state.js +74 -0
- package/dist/esm/utils/format-code/formatter-impl.js +9 -0
- package/dist/esm/utils/format-code/formatter.js +75 -0
- package/dist/types/codeBlockPluginType.d.ts +3 -0
- package/dist/types/editor-commands/index.d.ts +6 -1
- package/dist/types/pm-plugins/actions.d.ts +6 -3
- package/dist/types/pm-plugins/main-state.d.ts +16 -0
- package/dist/types/ui/FormatCodeErrorFlag.d.ts +6 -0
- package/dist/types/utils/format-code/format-code-state.d.ts +4 -0
- package/dist/types/utils/format-code/formatter-impl.d.ts +5 -0
- package/dist/types/utils/format-code/formatter.d.ts +25 -0
- package/dist/types-ts4.5/codeBlockPluginType.d.ts +3 -0
- package/dist/types-ts4.5/editor-commands/index.d.ts +6 -1
- package/dist/types-ts4.5/pm-plugins/actions.d.ts +6 -3
- package/dist/types-ts4.5/pm-plugins/main-state.d.ts +16 -0
- package/dist/types-ts4.5/ui/FormatCodeErrorFlag.d.ts +6 -0
- package/dist/types-ts4.5/utils/format-code/format-code-state.d.ts +4 -0
- package/dist/types-ts4.5/utils/format-code/formatter-impl.d.ts +5 -0
- package/dist/types-ts4.5/utils/format-code/formatter.d.ts +32 -0
- package/package.json +12 -8
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
+
import { ACTIONS } from '../../pm-plugins/actions';
|
|
6
|
+
export var mapPendingFormats = function mapPendingFormats(pendingFormats, tr, newState) {
|
|
7
|
+
var entries = Object.entries(pendingFormats);
|
|
8
|
+
if (entries.length === 0) {
|
|
9
|
+
return pendingFormats;
|
|
10
|
+
}
|
|
11
|
+
var nextPendingFormats = pendingFormats;
|
|
12
|
+
entries.forEach(function (_ref) {
|
|
13
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
14
|
+
localId = _ref2[0],
|
|
15
|
+
pendingFormat = _ref2[1];
|
|
16
|
+
var _tr$mapping$mapResult = tr.mapping.mapResult(pendingFormat.pos, 1),
|
|
17
|
+
deleted = _tr$mapping$mapResult.deleted,
|
|
18
|
+
pos = _tr$mapping$mapResult.pos;
|
|
19
|
+
var codeBlockNode = newState.doc.nodeAt(pos);
|
|
20
|
+
var shouldRemovePendingFormat = deleted || (codeBlockNode === null || codeBlockNode === void 0 ? void 0 : codeBlockNode.type) !== newState.schema.nodes.codeBlock || (codeBlockNode === null || codeBlockNode === void 0 ? void 0 : codeBlockNode.attrs.localId) !== localId;
|
|
21
|
+
var shouldUpdatePendingFormat = pos !== pendingFormat.pos;
|
|
22
|
+
if (shouldRemovePendingFormat || shouldUpdatePendingFormat) {
|
|
23
|
+
if (nextPendingFormats === pendingFormats) {
|
|
24
|
+
nextPendingFormats = _objectSpread({}, pendingFormats);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (shouldRemovePendingFormat) {
|
|
28
|
+
delete nextPendingFormats[localId];
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (shouldUpdatePendingFormat) {
|
|
32
|
+
nextPendingFormats[localId] = _objectSpread(_objectSpread({}, pendingFormat), {}, {
|
|
33
|
+
pos: pos
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return nextPendingFormats;
|
|
38
|
+
};
|
|
39
|
+
function removeRecordEntry(record, key) {
|
|
40
|
+
var nextRecord = _objectSpread({}, record);
|
|
41
|
+
delete nextRecord[key];
|
|
42
|
+
return nextRecord;
|
|
43
|
+
}
|
|
44
|
+
export var applyFormatCodeMeta = function applyFormatCodeMeta(pluginState, meta) {
|
|
45
|
+
switch (meta === null || meta === void 0 ? void 0 : meta.type) {
|
|
46
|
+
case ACTIONS.START_FORMAT_CODE:
|
|
47
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
48
|
+
pendingFormats: _objectSpread(_objectSpread({}, pluginState.pendingFormats), {}, _defineProperty({}, meta.data.localId, {
|
|
49
|
+
languageSource: meta.data.languageSource,
|
|
50
|
+
pos: meta.data.pos,
|
|
51
|
+
requestId: meta.data.requestId
|
|
52
|
+
}))
|
|
53
|
+
});
|
|
54
|
+
case ACTIONS.RESOLVE_FORMAT_CODE:
|
|
55
|
+
{
|
|
56
|
+
var pendingFormats = removeRecordEntry(pluginState.pendingFormats, meta.data.localId);
|
|
57
|
+
var formatCodeErrors = removeRecordEntry(pluginState.formatCodeErrors, meta.data.localId);
|
|
58
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
59
|
+
formatCodeErrors: meta.data.outcome === 'failed' ? _objectSpread(_objectSpread({}, formatCodeErrors), {}, _defineProperty({}, meta.data.localId, {
|
|
60
|
+
errorType: meta.data.errorType,
|
|
61
|
+
localId: meta.data.localId,
|
|
62
|
+
languageSource: meta.data.languageSource
|
|
63
|
+
})) : formatCodeErrors,
|
|
64
|
+
pendingFormats: pendingFormats
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
case ACTIONS.CLEAR_FORMAT_CODE_ERROR:
|
|
68
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
69
|
+
formatCodeErrors: removeRecordEntry(pluginState.formatCodeErrors, meta.data.localId)
|
|
70
|
+
});
|
|
71
|
+
default:
|
|
72
|
+
return pluginState;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
var supportedFormatLanguages = ['json', 'javascript', 'jsx', 'typescript', 'tsx', 'sql'];
|
|
4
|
+
export var isSupportedFormatLanguage = function isSupportedFormatLanguage(language) {
|
|
5
|
+
return supportedFormatLanguages.includes(language);
|
|
6
|
+
};
|
|
7
|
+
var formatterModulePromise;
|
|
8
|
+
export var preloadFormatterModule = function preloadFormatterModule() {
|
|
9
|
+
if (!formatterModulePromise) {
|
|
10
|
+
formatterModulePromise = import( /* webpackChunkName: "@atlaskit-internal_editor-plugin-code-block-formatter" */'./formatter-impl').catch(function (error) {
|
|
11
|
+
formatterModulePromise = undefined;
|
|
12
|
+
throw error;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return formatterModulePromise;
|
|
16
|
+
};
|
|
17
|
+
export var preloadFormatterOnIntent = function preloadFormatterOnIntent() {
|
|
18
|
+
return function (_state, dispatch) {
|
|
19
|
+
if (!dispatch) {
|
|
20
|
+
// Hover/focus handlers are command-shaped; keep dry-runs side-effect free.
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
void preloadFormatterModule();
|
|
24
|
+
return false;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export var formatCode = /*#__PURE__*/function () {
|
|
28
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
|
|
29
|
+
var content, language, formatterModule, _t, _t2;
|
|
30
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
31
|
+
while (1) switch (_context.prev = _context.next) {
|
|
32
|
+
case 0:
|
|
33
|
+
content = _ref.content, language = _ref.language;
|
|
34
|
+
_context.prev = 1;
|
|
35
|
+
_context.next = 2;
|
|
36
|
+
return preloadFormatterModule();
|
|
37
|
+
case 2:
|
|
38
|
+
formatterModule = _context.sent;
|
|
39
|
+
_context.next = 4;
|
|
40
|
+
break;
|
|
41
|
+
case 3:
|
|
42
|
+
_context.prev = 3;
|
|
43
|
+
_t = _context["catch"](1);
|
|
44
|
+
return _context.abrupt("return", {
|
|
45
|
+
errorType: 'formatter-load-failed',
|
|
46
|
+
language: language,
|
|
47
|
+
status: 'failed'
|
|
48
|
+
});
|
|
49
|
+
case 4:
|
|
50
|
+
_context.prev = 4;
|
|
51
|
+
_context.next = 5;
|
|
52
|
+
return formatterModule.formatCode({
|
|
53
|
+
content: content,
|
|
54
|
+
language: language
|
|
55
|
+
});
|
|
56
|
+
case 5:
|
|
57
|
+
return _context.abrupt("return", _context.sent);
|
|
58
|
+
case 6:
|
|
59
|
+
_context.prev = 6;
|
|
60
|
+
_t2 = _context["catch"](4);
|
|
61
|
+
return _context.abrupt("return", {
|
|
62
|
+
errorType: 'formatter-execution-failed',
|
|
63
|
+
language: language,
|
|
64
|
+
status: 'failed'
|
|
65
|
+
});
|
|
66
|
+
case 7:
|
|
67
|
+
case "end":
|
|
68
|
+
return _context.stop();
|
|
69
|
+
}
|
|
70
|
+
}, _callee, null, [[1, 3], [4, 6]]);
|
|
71
|
+
}));
|
|
72
|
+
return function formatCode(_x) {
|
|
73
|
+
return _ref2.apply(this, arguments);
|
|
74
|
+
};
|
|
75
|
+
}();
|
|
@@ -11,6 +11,7 @@ import type { InteractionPlugin } from '@atlaskit/editor-plugin-interaction';
|
|
|
11
11
|
import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
12
12
|
import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar';
|
|
13
13
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
14
|
+
import type { CodeBlockState } from './pm-plugins/main-state';
|
|
14
15
|
import type { CodeBlockPluginOptions } from './types';
|
|
15
16
|
type CodeBlockDependencies = [
|
|
16
17
|
DecorationsPlugin,
|
|
@@ -32,6 +33,8 @@ export type CodeBlockPlugin = NextEditorPlugin<'codeBlock', {
|
|
|
32
33
|
pluginConfiguration: CodeBlockPluginOptions | undefined;
|
|
33
34
|
sharedState: {
|
|
34
35
|
copyButtonHoverNode: PMNode;
|
|
36
|
+
formatCodeErrors: CodeBlockState['formatCodeErrors'];
|
|
37
|
+
pendingFormats: CodeBlockState['pendingFormats'];
|
|
35
38
|
} | undefined;
|
|
36
39
|
}>;
|
|
37
40
|
export {};
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
3
|
-
import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { Command, EditorCommand, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
4
4
|
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import type { CodeBlockPlugin } from '../codeBlockPluginType';
|
|
5
6
|
import type { LanguagePickerSelectionSource } from '../ui/language-picker-options';
|
|
6
7
|
export declare const removeCodeBlockWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
|
|
7
8
|
export declare const removeCodeBlock: Command;
|
|
8
9
|
export declare const changeLanguage: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (language: string | null, selectionSource?: LanguagePickerSelectionSource) => Command;
|
|
9
10
|
/** Queue auto-detection for selected code block. */
|
|
10
11
|
export declare const detectLanguage: () => Command;
|
|
12
|
+
export declare const createFormatCodeOnClick: ({ api, editorAnalyticsAPI, }: {
|
|
13
|
+
api?: ExtractInjectionAPI<CodeBlockPlugin>;
|
|
14
|
+
editorAnalyticsAPI: EditorAnalyticsAPI | undefined;
|
|
15
|
+
}) => Command;
|
|
11
16
|
export declare const copyContentToClipboardWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
|
|
12
17
|
export declare const copyContentToClipboard: Command;
|
|
13
18
|
export declare const resetCopiedState: Command;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export declare const ACTIONS: {
|
|
2
|
+
CLEAR_FORMAT_CODE_ERROR: string;
|
|
3
|
+
REMOVE_AUTO_DETECT_ENTRY: string;
|
|
4
|
+
RESOLVE_FORMAT_CODE: string;
|
|
5
|
+
SET_AUTO_DETECT_ENTRY: string;
|
|
2
6
|
SET_COPIED_TO_CLIPBOARD: string;
|
|
3
|
-
SET_SHOULD_IGNORE_FOLLOWING_MUTATIONS: string;
|
|
4
7
|
SET_IS_WRAPPED: string;
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
SET_SHOULD_IGNORE_FOLLOWING_MUTATIONS: string;
|
|
9
|
+
START_FORMAT_CODE: string;
|
|
7
10
|
};
|
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
2
2
|
import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
import type { FormatCodeResult, LanguageSource } from '../utils/format-code/formatter';
|
|
4
|
+
export type PendingFormatRequest = {
|
|
5
|
+
languageSource: LanguageSource;
|
|
6
|
+
pos: number;
|
|
7
|
+
requestId: string;
|
|
8
|
+
};
|
|
9
|
+
export type ResolveFormatCodeOutcome = 'failed' | 'formatted' | 'unchanged';
|
|
10
|
+
export type FormatCodeErrorState = {
|
|
11
|
+
errorType: Extract<FormatCodeResult, {
|
|
12
|
+
status: 'failed';
|
|
13
|
+
}>['errorType'];
|
|
14
|
+
languageSource: LanguageSource;
|
|
15
|
+
localId: string;
|
|
16
|
+
};
|
|
3
17
|
export type CodeBlockState = {
|
|
4
18
|
contentCopied: boolean;
|
|
5
19
|
decorations: DecorationSet;
|
|
20
|
+
formatCodeErrors: Record<string, FormatCodeErrorState>;
|
|
6
21
|
isNodeSelected: boolean;
|
|
22
|
+
pendingFormats: Record<string, PendingFormatRequest>;
|
|
7
23
|
pos: number | null;
|
|
8
24
|
shouldIgnoreFollowingMutations: boolean;
|
|
9
25
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { CodeBlockPlugin } from '../index';
|
|
4
|
+
export declare const FormatCodeErrorFlag: ({ api, }: {
|
|
5
|
+
api?: ExtractInjectionAPI<CodeBlockPlugin>;
|
|
6
|
+
}) => React.JSX.Element | null;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { EditorState, ReadonlyTransaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import type { CodeBlockState } from '../../pm-plugins/main-state';
|
|
3
|
+
export declare const mapPendingFormats: (pendingFormats: CodeBlockState["pendingFormats"], tr: ReadonlyTransaction, newState: EditorState) => CodeBlockState["pendingFormats"];
|
|
4
|
+
export declare const applyFormatCodeMeta: (pluginState: CodeBlockState, meta: ReturnType<ReadonlyTransaction["getMeta"]>) => CodeBlockState;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Command } from '@atlaskit/editor-common/types';
|
|
2
|
+
declare const supportedFormatLanguages: readonly ["json", "javascript", "jsx", "typescript", "tsx", "sql"];
|
|
3
|
+
type FormatCodeLanguage = (typeof supportedFormatLanguages)[number];
|
|
4
|
+
export type FormatCodeResult = {
|
|
5
|
+
content: string;
|
|
6
|
+
language: FormatCodeLanguage;
|
|
7
|
+
status: 'formatted' | 'unchanged';
|
|
8
|
+
} | {
|
|
9
|
+
errorType: 'formatter-execution-failed' | 'formatter-load-failed';
|
|
10
|
+
language: FormatCodeLanguage;
|
|
11
|
+
status: 'failed';
|
|
12
|
+
};
|
|
13
|
+
export type LanguageSource = 'auto-detected' | 'selected';
|
|
14
|
+
type FormatCode = (args: {
|
|
15
|
+
content: string;
|
|
16
|
+
language: FormatCodeLanguage;
|
|
17
|
+
}) => Promise<FormatCodeResult>;
|
|
18
|
+
type FormatterModule = {
|
|
19
|
+
formatCode: FormatCode;
|
|
20
|
+
};
|
|
21
|
+
export declare const isSupportedFormatLanguage: (language: string | null | undefined) => language is FormatCodeLanguage;
|
|
22
|
+
export declare const preloadFormatterModule: () => Promise<FormatterModule>;
|
|
23
|
+
export declare const preloadFormatterOnIntent: () => Command;
|
|
24
|
+
export declare const formatCode: FormatCode;
|
|
25
|
+
export {};
|
|
@@ -11,6 +11,7 @@ import type { InteractionPlugin } from '@atlaskit/editor-plugin-interaction';
|
|
|
11
11
|
import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
|
|
12
12
|
import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar';
|
|
13
13
|
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
14
|
+
import type { CodeBlockState } from './pm-plugins/main-state';
|
|
14
15
|
import type { CodeBlockPluginOptions } from './types';
|
|
15
16
|
type CodeBlockDependencies = [
|
|
16
17
|
DecorationsPlugin,
|
|
@@ -32,6 +33,8 @@ export type CodeBlockPlugin = NextEditorPlugin<'codeBlock', {
|
|
|
32
33
|
pluginConfiguration: CodeBlockPluginOptions | undefined;
|
|
33
34
|
sharedState: {
|
|
34
35
|
copyButtonHoverNode: PMNode;
|
|
36
|
+
formatCodeErrors: CodeBlockState['formatCodeErrors'];
|
|
37
|
+
pendingFormats: CodeBlockState['pendingFormats'];
|
|
35
38
|
} | undefined;
|
|
36
39
|
}>;
|
|
37
40
|
export {};
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
3
|
-
import type { Command, EditorCommand } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { Command, EditorCommand, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
4
4
|
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
+
import type { CodeBlockPlugin } from '../codeBlockPluginType';
|
|
5
6
|
import type { LanguagePickerSelectionSource } from '../ui/language-picker-options';
|
|
6
7
|
export declare const removeCodeBlockWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
|
|
7
8
|
export declare const removeCodeBlock: Command;
|
|
8
9
|
export declare const changeLanguage: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (language: string | null, selectionSource?: LanguagePickerSelectionSource) => Command;
|
|
9
10
|
/** Queue auto-detection for selected code block. */
|
|
10
11
|
export declare const detectLanguage: () => Command;
|
|
12
|
+
export declare const createFormatCodeOnClick: ({ api, editorAnalyticsAPI, }: {
|
|
13
|
+
api?: ExtractInjectionAPI<CodeBlockPlugin>;
|
|
14
|
+
editorAnalyticsAPI: EditorAnalyticsAPI | undefined;
|
|
15
|
+
}) => Command;
|
|
11
16
|
export declare const copyContentToClipboardWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => Command;
|
|
12
17
|
export declare const copyContentToClipboard: Command;
|
|
13
18
|
export declare const resetCopiedState: Command;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export declare const ACTIONS: {
|
|
2
|
+
CLEAR_FORMAT_CODE_ERROR: string;
|
|
3
|
+
REMOVE_AUTO_DETECT_ENTRY: string;
|
|
4
|
+
RESOLVE_FORMAT_CODE: string;
|
|
5
|
+
SET_AUTO_DETECT_ENTRY: string;
|
|
2
6
|
SET_COPIED_TO_CLIPBOARD: string;
|
|
3
|
-
SET_SHOULD_IGNORE_FOLLOWING_MUTATIONS: string;
|
|
4
7
|
SET_IS_WRAPPED: string;
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
SET_SHOULD_IGNORE_FOLLOWING_MUTATIONS: string;
|
|
9
|
+
START_FORMAT_CODE: string;
|
|
7
10
|
};
|
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
2
2
|
import type { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
import type { FormatCodeResult, LanguageSource } from '../utils/format-code/formatter';
|
|
4
|
+
export type PendingFormatRequest = {
|
|
5
|
+
languageSource: LanguageSource;
|
|
6
|
+
pos: number;
|
|
7
|
+
requestId: string;
|
|
8
|
+
};
|
|
9
|
+
export type ResolveFormatCodeOutcome = 'failed' | 'formatted' | 'unchanged';
|
|
10
|
+
export type FormatCodeErrorState = {
|
|
11
|
+
errorType: Extract<FormatCodeResult, {
|
|
12
|
+
status: 'failed';
|
|
13
|
+
}>['errorType'];
|
|
14
|
+
languageSource: LanguageSource;
|
|
15
|
+
localId: string;
|
|
16
|
+
};
|
|
3
17
|
export type CodeBlockState = {
|
|
4
18
|
contentCopied: boolean;
|
|
5
19
|
decorations: DecorationSet;
|
|
20
|
+
formatCodeErrors: Record<string, FormatCodeErrorState>;
|
|
6
21
|
isNodeSelected: boolean;
|
|
22
|
+
pendingFormats: Record<string, PendingFormatRequest>;
|
|
7
23
|
pos: number | null;
|
|
8
24
|
shouldIgnoreFollowingMutations: boolean;
|
|
9
25
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { CodeBlockPlugin } from '../index';
|
|
4
|
+
export declare const FormatCodeErrorFlag: ({ api, }: {
|
|
5
|
+
api?: ExtractInjectionAPI<CodeBlockPlugin>;
|
|
6
|
+
}) => React.JSX.Element | null;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { EditorState, ReadonlyTransaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
+
import type { CodeBlockState } from '../../pm-plugins/main-state';
|
|
3
|
+
export declare const mapPendingFormats: (pendingFormats: CodeBlockState["pendingFormats"], tr: ReadonlyTransaction, newState: EditorState) => CodeBlockState["pendingFormats"];
|
|
4
|
+
export declare const applyFormatCodeMeta: (pluginState: CodeBlockState, meta: ReturnType<ReadonlyTransaction["getMeta"]>) => CodeBlockState;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Command } from '@atlaskit/editor-common/types';
|
|
2
|
+
declare const supportedFormatLanguages: readonly [
|
|
3
|
+
"json",
|
|
4
|
+
"javascript",
|
|
5
|
+
"jsx",
|
|
6
|
+
"typescript",
|
|
7
|
+
"tsx",
|
|
8
|
+
"sql"
|
|
9
|
+
];
|
|
10
|
+
type FormatCodeLanguage = (typeof supportedFormatLanguages)[number];
|
|
11
|
+
export type FormatCodeResult = {
|
|
12
|
+
content: string;
|
|
13
|
+
language: FormatCodeLanguage;
|
|
14
|
+
status: 'formatted' | 'unchanged';
|
|
15
|
+
} | {
|
|
16
|
+
errorType: 'formatter-execution-failed' | 'formatter-load-failed';
|
|
17
|
+
language: FormatCodeLanguage;
|
|
18
|
+
status: 'failed';
|
|
19
|
+
};
|
|
20
|
+
export type LanguageSource = 'auto-detected' | 'selected';
|
|
21
|
+
type FormatCode = (args: {
|
|
22
|
+
content: string;
|
|
23
|
+
language: FormatCodeLanguage;
|
|
24
|
+
}) => Promise<FormatCodeResult>;
|
|
25
|
+
type FormatterModule = {
|
|
26
|
+
formatCode: FormatCode;
|
|
27
|
+
};
|
|
28
|
+
export declare const isSupportedFormatLanguage: (language: string | null | undefined) => language is FormatCodeLanguage;
|
|
29
|
+
export declare const preloadFormatterModule: () => Promise<FormatterModule>;
|
|
30
|
+
export declare const preloadFormatterOnIntent: () => Command;
|
|
31
|
+
export declare const formatCode: FormatCode;
|
|
32
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-code-block",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.1.0",
|
|
4
4
|
"description": "Code block plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"atlaskit:src": "src/index.ts",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@atlaskit/adf-schema": "^52.
|
|
30
|
+
"@atlaskit/adf-schema": "^52.16.0",
|
|
31
31
|
"@atlaskit/button": "^23.11.0",
|
|
32
32
|
"@atlaskit/code": "^17.5.0",
|
|
33
33
|
"@atlaskit/css": "^0.19.0",
|
|
34
34
|
"@atlaskit/editor-plugin-analytics": "^11.0.0",
|
|
35
|
-
"@atlaskit/editor-plugin-block-menu": "^10.
|
|
35
|
+
"@atlaskit/editor-plugin-block-menu": "^10.1.0",
|
|
36
36
|
"@atlaskit/editor-plugin-composition": "^10.0.0",
|
|
37
37
|
"@atlaskit/editor-plugin-decorations": "^11.0.0",
|
|
38
38
|
"@atlaskit/editor-plugin-editor-disabled": "^11.0.0",
|
|
@@ -42,20 +42,21 @@
|
|
|
42
42
|
"@atlaskit/editor-plugin-toolbar": "^8.0.0",
|
|
43
43
|
"@atlaskit/editor-prosemirror": "^7.3.0",
|
|
44
44
|
"@atlaskit/editor-shared-styles": "^3.11.0",
|
|
45
|
-
"@atlaskit/editor-toolbar": "^1.
|
|
46
|
-
"@atlaskit/
|
|
47
|
-
"@atlaskit/
|
|
45
|
+
"@atlaskit/editor-toolbar": "^1.10.0",
|
|
46
|
+
"@atlaskit/flag": "^17.12.0",
|
|
47
|
+
"@atlaskit/frontend-utilities": "^3.4.0",
|
|
48
|
+
"@atlaskit/icon": "^35.4.0",
|
|
48
49
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
49
50
|
"@atlaskit/primitives": "^19.0.0",
|
|
50
51
|
"@atlaskit/prosemirror-input-rules": "^3.7.0",
|
|
51
52
|
"@atlaskit/select": "^21.12.0",
|
|
52
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
53
|
+
"@atlaskit/tmp-editor-statsig": "^89.0.0",
|
|
53
54
|
"@atlaskit/tokens": "^13.1.0",
|
|
54
55
|
"@babel/runtime": "^7.0.0",
|
|
55
56
|
"@compiled/react": "^0.20.0"
|
|
56
57
|
},
|
|
57
58
|
"peerDependencies": {
|
|
58
|
-
"@atlaskit/editor-common": "^115.
|
|
59
|
+
"@atlaskit/editor-common": "^115.5.0",
|
|
59
60
|
"react": "^18.2.0",
|
|
60
61
|
"react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
|
|
61
62
|
},
|
|
@@ -109,6 +110,9 @@
|
|
|
109
110
|
},
|
|
110
111
|
"platform_editor_code_block_add_line_number_button": {
|
|
111
112
|
"type": "boolean"
|
|
113
|
+
},
|
|
114
|
+
"platform_editor_code_block_language_detection_flow": {
|
|
115
|
+
"type": "boolean"
|
|
112
116
|
}
|
|
113
117
|
},
|
|
114
118
|
"devDependencies": {
|