@atlaskit/editor-plugin-code-block 13.0.1 → 13.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/cjs/codeBlockPlugin.js +13 -1
  3. package/dist/cjs/editor-commands/index.js +179 -5
  4. package/dist/cjs/pm-plugins/actions.js +6 -3
  5. package/dist/cjs/pm-plugins/main.js +17 -1
  6. package/dist/cjs/pm-plugins/toolbar.js +19 -2
  7. package/dist/cjs/ui/FormatCodeErrorFlag.js +70 -0
  8. package/dist/cjs/utils/format-code/format-code-state.js +81 -0
  9. package/dist/cjs/utils/format-code/formatter-impl.js +15 -0
  10. package/dist/cjs/utils/format-code/formatter.js +86 -0
  11. package/dist/es2019/codeBlockPlugin.js +12 -2
  12. package/dist/es2019/editor-commands/index.js +176 -0
  13. package/dist/es2019/pm-plugins/actions.js +6 -3
  14. package/dist/es2019/pm-plugins/main.js +18 -1
  15. package/dist/es2019/pm-plugins/toolbar.js +22 -3
  16. package/dist/es2019/ui/FormatCodeErrorFlag.js +62 -0
  17. package/dist/es2019/utils/format-code/format-code-state.js +82 -0
  18. package/dist/es2019/utils/format-code/formatter-impl.js +10 -0
  19. package/dist/es2019/utils/format-code/formatter.js +47 -0
  20. package/dist/esm/codeBlockPlugin.js +13 -1
  21. package/dist/esm/editor-commands/index.js +178 -4
  22. package/dist/esm/pm-plugins/actions.js +6 -3
  23. package/dist/esm/pm-plugins/main.js +17 -1
  24. package/dist/esm/pm-plugins/toolbar.js +20 -3
  25. package/dist/esm/ui/FormatCodeErrorFlag.js +61 -0
  26. package/dist/esm/utils/format-code/format-code-state.js +74 -0
  27. package/dist/esm/utils/format-code/formatter-impl.js +9 -0
  28. package/dist/esm/utils/format-code/formatter.js +75 -0
  29. package/dist/types/codeBlockPluginType.d.ts +3 -0
  30. package/dist/types/editor-commands/index.d.ts +6 -1
  31. package/dist/types/pm-plugins/actions.d.ts +6 -3
  32. package/dist/types/pm-plugins/main-state.d.ts +16 -0
  33. package/dist/types/ui/FormatCodeErrorFlag.d.ts +6 -0
  34. package/dist/types/utils/format-code/format-code-state.d.ts +4 -0
  35. package/dist/types/utils/format-code/formatter-impl.d.ts +5 -0
  36. package/dist/types/utils/format-code/formatter.d.ts +25 -0
  37. package/dist/types-ts4.5/codeBlockPluginType.d.ts +3 -0
  38. package/dist/types-ts4.5/editor-commands/index.d.ts +6 -1
  39. package/dist/types-ts4.5/pm-plugins/actions.d.ts +6 -3
  40. package/dist/types-ts4.5/pm-plugins/main-state.d.ts +16 -0
  41. package/dist/types-ts4.5/ui/FormatCodeErrorFlag.d.ts +6 -0
  42. package/dist/types-ts4.5/utils/format-code/format-code-state.d.ts +4 -0
  43. package/dist/types-ts4.5/utils/format-code/formatter-impl.d.ts +5 -0
  44. package/dist/types-ts4.5/utils/format-code/formatter.d.ts +32 -0
  45. package/package.json +9 -5
@@ -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,5 @@
1
+ import type { FormatCodeResult } from './formatter';
2
+ export declare const formatCode: ({ content, language, }: {
3
+ content: string;
4
+ language: FormatCodeResult["language"];
5
+ }) => Promise<FormatCodeResult>;
@@ -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
- SET_AUTO_DETECT_ENTRY: string;
6
- REMOVE_AUTO_DETECT_ENTRY: string;
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,5 @@
1
+ import type { FormatCodeResult } from './formatter';
2
+ export declare const formatCode: ({ content, language, }: {
3
+ content: string;
4
+ language: FormatCodeResult["language"];
5
+ }) => Promise<FormatCodeResult>;
@@ -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.0.1",
3
+ "version": "13.1.1",
4
4
  "description": "Code block plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -43,19 +43,20 @@
43
43
  "@atlaskit/editor-prosemirror": "^7.3.0",
44
44
  "@atlaskit/editor-shared-styles": "^3.11.0",
45
45
  "@atlaskit/editor-toolbar": "^1.10.0",
46
+ "@atlaskit/flag": "^17.12.0",
46
47
  "@atlaskit/frontend-utilities": "^3.4.0",
47
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": "^89.0.0",
53
- "@atlaskit/tokens": "^13.1.0",
53
+ "@atlaskit/tmp-editor-statsig": "^89.4.0",
54
+ "@atlaskit/tokens": "^13.3.0",
54
55
  "@babel/runtime": "^7.0.0",
55
- "@compiled/react": "^0.20.0"
56
+ "@compiled/react": "patch:@compiled/react@npm%3A0.20.0#~/.yarn/patches/@compiled-react-npm-0.20.0-a771aa67a6.patch"
56
57
  },
57
58
  "peerDependencies": {
58
- "@atlaskit/editor-common": "^115.2.0",
59
+ "@atlaskit/editor-common": "^115.7.0",
59
60
  "react": "^18.2.0",
60
61
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
61
62
  },
@@ -110,6 +111,9 @@
110
111
  "platform_editor_code_block_add_line_number_button": {
111
112
  "type": "boolean"
112
113
  },
114
+ "platform_editor_code_block_formatting": {
115
+ "type": "boolean"
116
+ },
113
117
  "platform_editor_code_block_language_detection_flow": {
114
118
  "type": "boolean"
115
119
  }