@atlaskit/editor-plugin-code-block 14.0.6 → 14.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.
- package/CHANGELOG.md +33 -0
- package/dist/cjs/codeBlockPlugin.js +2 -3
- package/dist/cjs/editor-commands/index.js +3 -0
- package/dist/cjs/pm-plugins/main.js +3 -2
- package/dist/cjs/pm-plugins/toolbar.js +6 -4
- package/dist/cjs/ui/CodeBlockLanguagePicker.js +13 -3
- package/dist/cjs/ui/CodeBlockMenuItem.js +7 -2
- package/dist/cjs/ui/LanguagePicker.js +72 -12
- package/dist/cjs/utils/auto-detect-view.js +21 -11
- package/dist/cjs/utils/language-detect.js +5 -1
- package/dist/es2019/codeBlockPlugin.js +2 -3
- package/dist/es2019/editor-commands/index.js +3 -0
- package/dist/es2019/pm-plugins/main.js +3 -2
- package/dist/es2019/pm-plugins/toolbar.js +6 -4
- package/dist/es2019/ui/CodeBlockLanguagePicker.js +13 -3
- package/dist/es2019/ui/CodeBlockMenuItem.js +8 -3
- package/dist/es2019/ui/LanguagePicker.js +61 -7
- package/dist/es2019/utils/auto-detect-view.js +22 -11
- package/dist/es2019/utils/language-detect.js +3 -2
- package/dist/esm/codeBlockPlugin.js +2 -3
- package/dist/esm/editor-commands/index.js +3 -0
- package/dist/esm/pm-plugins/main.js +3 -2
- package/dist/esm/pm-plugins/toolbar.js +6 -4
- package/dist/esm/ui/CodeBlockLanguagePicker.js +13 -3
- package/dist/esm/ui/CodeBlockMenuItem.js +7 -2
- package/dist/esm/ui/LanguagePicker.js +72 -12
- package/dist/esm/utils/auto-detect-view.js +21 -11
- package/dist/esm/utils/language-detect.js +5 -2
- package/dist/types/ui/CodeBlockLanguagePicker.d.ts +1 -1
- package/dist/types/ui/CodeBlockMenuItem.d.ts +2 -1
- package/dist/types/ui/LanguagePicker.d.ts +2 -1
- package/package.json +11 -8
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
3
|
/* eslint-disable require-unicode-regexp */
|
|
4
|
-
|
|
4
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
5
5
|
// Conservative weighted-regex heuristic for common high-confidence snippets, not a full classifier.
|
|
6
6
|
// Ambiguous snippets intentionally return null so users can select the language manually.
|
|
7
7
|
var MAX_DETECTION_CHARS = 10000;
|
|
@@ -21,6 +21,9 @@ var scorePatterns = function scorePatterns(code, patterns) {
|
|
|
21
21
|
return score + (hasPattern(code, pattern) ? value : 0);
|
|
22
22
|
}, 0);
|
|
23
23
|
};
|
|
24
|
+
var scoreEnhancedTypeScriptPatterns = function scoreEnhancedTypeScriptPatterns(code) {
|
|
25
|
+
return fg('platform_editor_code_block_dogfooding_patch') ? scorePatterns(code, [[/\b(?:private|protected|public|readonly)\s+[\w$]+\s*=/, 5], [/\([^)]{0,500}\b[\w$]+\??:\s*[A-Za-z_$][\w$<>{}\[\]|&,\s.?]{0,200}[^)]{0,500}\)\s*(?::\s*[A-Za-z_$][\w$<>{}\[\]|&,\s.?]{0,200})?\s*=>/, 5]]) : 0;
|
|
26
|
+
};
|
|
24
27
|
var looksLikeHtmlTagPair = function looksLikeHtmlTagPair(code) {
|
|
25
28
|
var openTags = new Set();
|
|
26
29
|
var tagPattern = /<\/?([a-z][a-z0-9-]*)\b[^<>]{0,500}>/gi;
|
|
@@ -70,7 +73,7 @@ var getLanguageScores = function getLanguageScores(code) {
|
|
|
70
73
|
score: scorePatterns(code, [[/\bSELECT\b[\s\S]+\bFROM\b/i, 5], [/\b(?:INSERT\s+INTO|UPDATE\b[\s\S]+\bSET\b|DELETE\s+FROM|CREATE\s+TABLE|ALTER\s+TABLE)\b/i, 5], [/\b(?:JOIN|WHERE|GROUP\s+BY|ORDER\s+BY|LIMIT)\b/i, 2]])
|
|
71
74
|
}, {
|
|
72
75
|
language: 'typescript',
|
|
73
|
-
score: scorePatterns(code, [[/\b(?:interface|type)\s+[A-Z_$][\w$]*(?:\s*[=<{])/, 5], [/\bimport\s+type\b|\bexport\s+type\b/, 4], [/\b(?:const|let|var)\s+[\w$]+\s*:\s*[A-Za-z_$][\w$<>|\[\],\s]*/, 4], [/\)\s*:\s*(?:Promise<)?[A-Za-z_$][\w$<>|\[\],\s]*(?:>|\s)?\s*=>?\s*[{;]/, 3], [/\b(?:as\s+const|implements\s+[A-Z_$]|enum\s+[A-Z_$])/, 3]])
|
|
76
|
+
score: scorePatterns(code, [[/\b(?:interface|type)\s+[A-Z_$][\w$]*(?:\s*[=<{])/, 5], [/\bimport\s+type\b|\bexport\s+type\b/, 4], [/\b(?:const|let|var)\s+[\w$]+\s*:\s*[A-Za-z_$][\w$<>|\[\],\s]*/, 4], [/\)\s*:\s*(?:Promise<)?[A-Za-z_$][\w$<>|\[\],\s]*(?:>|\s)?\s*=>?\s*[{;]/, 3], [/\b(?:as\s+const|implements\s+[A-Z_$]|enum\s+[A-Z_$])/, 3]]) + scoreEnhancedTypeScriptPatterns(code)
|
|
74
77
|
}, {
|
|
75
78
|
language: 'javascript',
|
|
76
79
|
score: scorePatterns(code, [[/\b(?:const|let|var)\s+[\w$]+\s*=/, 3], [/\bfunction\s*[\w$]*\s*\([^)]*\)\s*\{/, 3], [/=>\s*(?:\{|[\w$'"`(])/, 3], [/\b(?:import|export)\s+(?:[\w${}*,\s]+\s+from\s+)?['"][^'"]+['"]/, 3], [/\b(?:console\.log|document\.|window\.|require\()|\bmodule\.exports\b/, 3]])
|
|
@@ -7,5 +7,5 @@ type CodeBlockLanguagePickerProps = Omit<LanguagePickerProps, 'recentLanguageVal
|
|
|
7
7
|
api: ExtractInjectionAPI<CodeBlockPlugin> | undefined;
|
|
8
8
|
editorView: EditorView;
|
|
9
9
|
};
|
|
10
|
-
export declare const CodeBlockLanguagePicker: ({ api, defaultValue, editorView, filterOption, formatMessage, languagePickerOptions, }: CodeBlockLanguagePickerProps) => React.JSX.Element;
|
|
10
|
+
export declare const CodeBlockLanguagePicker: ({ api, defaultValue, editorView, filterOption, formatMessage, languagePickerOptions, triggerSpacing, }: CodeBlockLanguagePickerProps) => React.JSX.Element;
|
|
11
11
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { BlockMenuItemComponentProps } from '@atlaskit/editor-plugin-block-menu/blockMenuPluginType';
|
|
3
4
|
import type { CodeBlockPlugin } from '../codeBlockPluginType';
|
|
4
|
-
export declare const createCodeBlockMenuItem: (api: ExtractInjectionAPI<CodeBlockPlugin> | undefined) => () => React.JSX.Element;
|
|
5
|
+
export declare const createCodeBlockMenuItem: (api: ExtractInjectionAPI<CodeBlockPlugin> | undefined) => ({ isSuggested }?: BlockMenuItemComponentProps) => React.JSX.Element;
|
|
@@ -14,5 +14,6 @@ export type LanguagePickerProps = {
|
|
|
14
14
|
onMenuOpen?: () => void;
|
|
15
15
|
onSelection: (option: LanguagePickerOption, selectionSource: LanguagePickerSelectionSource) => void;
|
|
16
16
|
recentLanguageValues?: string[];
|
|
17
|
+
triggerSpacing?: 'default' | 'compact';
|
|
17
18
|
};
|
|
18
|
-
export declare const LanguagePicker: ({ defaultValue, filterOption, formatMessage, languagePickerOptions, recentLanguageValues, onMenuOpen, onSelection, }: LanguagePickerProps) => React.JSX.Element;
|
|
19
|
+
export declare const LanguagePicker: ({ defaultValue, filterOption, formatMessage, languagePickerOptions, recentLanguageValues, onMenuOpen, onSelection, triggerSpacing, }: LanguagePickerProps) => React.JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-code-block",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.1.1",
|
|
4
4
|
"description": "Code block plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
"@atlaskit/code": "^18.0.0",
|
|
25
25
|
"@atlaskit/css": "^1.0.0",
|
|
26
26
|
"@atlaskit/editor-plugin-analytics": "^12.0.0",
|
|
27
|
-
"@atlaskit/editor-plugin-block-menu": "^11.
|
|
27
|
+
"@atlaskit/editor-plugin-block-menu": "^11.1.0",
|
|
28
28
|
"@atlaskit/editor-plugin-composition": "^11.0.0",
|
|
29
29
|
"@atlaskit/editor-plugin-decorations": "^12.0.0",
|
|
30
30
|
"@atlaskit/editor-plugin-editor-disabled": "^12.0.0",
|
|
31
31
|
"@atlaskit/editor-plugin-editor-viewmode": "^14.0.0",
|
|
32
|
-
"@atlaskit/editor-plugin-interaction": "^
|
|
32
|
+
"@atlaskit/editor-plugin-interaction": "^22.0.0",
|
|
33
33
|
"@atlaskit/editor-plugin-selection": "^12.0.0",
|
|
34
34
|
"@atlaskit/editor-plugin-toolbar": "^9.0.0",
|
|
35
35
|
"@atlaskit/editor-prosemirror": "^8.0.0",
|
|
@@ -41,14 +41,14 @@
|
|
|
41
41
|
"@atlaskit/platform-feature-flags": "^2.0.0",
|
|
42
42
|
"@atlaskit/primitives": "^20.0.0",
|
|
43
43
|
"@atlaskit/prosemirror-input-rules": "^4.0.0",
|
|
44
|
-
"@atlaskit/select": "^22.
|
|
45
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
46
|
-
"@atlaskit/tokens": "^
|
|
44
|
+
"@atlaskit/select": "^22.1.0",
|
|
45
|
+
"@atlaskit/tmp-editor-statsig": "^111.0.0",
|
|
46
|
+
"@atlaskit/tokens": "^15.0.0",
|
|
47
47
|
"@babel/runtime": "^7.0.0",
|
|
48
48
|
"@compiled/react": "^0.20.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@atlaskit/editor-common": "^116.
|
|
51
|
+
"@atlaskit/editor-common": "^116.11.0",
|
|
52
52
|
"react": "^18.2.0",
|
|
53
53
|
"react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
|
|
54
54
|
},
|
|
@@ -103,12 +103,15 @@
|
|
|
103
103
|
"platform_editor_code_block_add_line_number_button": {
|
|
104
104
|
"type": "boolean"
|
|
105
105
|
},
|
|
106
|
+
"platform_editor_code_block_dogfooding_patch": {
|
|
107
|
+
"type": "boolean"
|
|
108
|
+
},
|
|
106
109
|
"platform_editor_code_block_language_detection_flow": {
|
|
107
110
|
"type": "boolean"
|
|
108
111
|
}
|
|
109
112
|
},
|
|
110
113
|
"devDependencies": {
|
|
111
114
|
"react": "^18.2.0",
|
|
112
|
-
"react-intl": "^
|
|
115
|
+
"react-intl": "^7.0.0"
|
|
113
116
|
}
|
|
114
117
|
}
|