@atlaskit/editor-plugin-code-block-advanced 10.0.20 → 10.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 +19 -0
- package/codeBlockAdvancedPlugin/package.json +15 -0
- package/codeBlockAdvancedPluginType/package.json +15 -0
- package/dist/cjs/entry-points/codeBlockAdvancedPlugin.js +12 -0
- package/dist/cjs/entry-points/codeBlockAdvancedPluginType.js +1 -0
- package/dist/cjs/nodeviews/codeBlockAdvanced.js +47 -19
- package/dist/cjs/nodeviews/codeBlockNodeWithToDOMFixed.js +61 -27
- package/dist/cjs/ui/theme.js +12 -2
- package/dist/es2019/entry-points/codeBlockAdvancedPlugin.js +2 -0
- package/dist/es2019/entry-points/codeBlockAdvancedPluginType.js +0 -0
- package/dist/es2019/nodeviews/codeBlockAdvanced.js +39 -18
- package/dist/es2019/nodeviews/codeBlockNodeWithToDOMFixed.js +53 -25
- package/dist/es2019/ui/theme.js +8 -1
- package/dist/esm/entry-points/codeBlockAdvancedPlugin.js +2 -0
- package/dist/esm/entry-points/codeBlockAdvancedPluginType.js +0 -0
- package/dist/esm/nodeviews/codeBlockAdvanced.js +48 -20
- package/dist/esm/nodeviews/codeBlockNodeWithToDOMFixed.js +61 -27
- package/dist/esm/ui/theme.js +11 -2
- package/dist/types/entry-points/codeBlockAdvancedPlugin.d.ts +1 -0
- package/dist/types/entry-points/codeBlockAdvancedPluginType.d.ts +1 -0
- package/dist/types/nodeviews/codeBlockAdvanced.d.ts +6 -0
- package/dist/types-ts4.5/entry-points/codeBlockAdvancedPlugin.d.ts +1 -0
- package/dist/types-ts4.5/entry-points/codeBlockAdvancedPluginType.d.ts +1 -0
- package/dist/types-ts4.5/nodeviews/codeBlockAdvanced.d.ts +6 -0
- package/docs/0-intro.tsx +1 -1
- package/package.json +8 -8
- package/src/entry-points/codeBlockAdvancedPlugin.tsx +2 -0
- package/src/entry-points/codeBlockAdvancedPluginType.ts +5 -0
- package/src/nodeviews/codeBlockAdvanced.ts +64 -19
- package/src/nodeviews/codeBlockNodeWithToDOMFixed.ts +74 -33
- package/src/ui/theme.ts +7 -0
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
codeBlockWithExtendedAttributes,
|
|
4
4
|
codeBlockWithLocalId,
|
|
5
5
|
} from '@atlaskit/adf-schema';
|
|
6
|
+
import { areCodeBlockLineNumbersHidden } from '@atlaskit/editor-common/code-block';
|
|
6
7
|
import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
|
|
7
8
|
import { CodeBlockSharedCssClassName } from '@atlaskit/editor-common/styles';
|
|
8
9
|
import type { NodeSpec, DOMOutputSpec, Node } from '@atlaskit/editor-prosemirror/model';
|
|
@@ -31,6 +32,75 @@ const getFontSize = () =>
|
|
|
31
32
|
? '0.875em'
|
|
32
33
|
: '0.875rem';
|
|
33
34
|
|
|
35
|
+
const getGutterBaseStyle = () => ({
|
|
36
|
+
backgroundColor: token('color.background.neutral'),
|
|
37
|
+
position: 'relative',
|
|
38
|
+
flexShrink: 0,
|
|
39
|
+
// eslint-disable-next-line @atlaskit/design-system/use-tokens-typography
|
|
40
|
+
fontSize: getFontSize(),
|
|
41
|
+
boxSizing: 'content-box',
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const getGutterPadding = (allowCodeFolding: boolean) =>
|
|
45
|
+
allowCodeFolding
|
|
46
|
+
? `${token('space.100')} ${token('space.250')} ${token('space.100')} ${token('space.075')}`
|
|
47
|
+
: token('space.100');
|
|
48
|
+
|
|
49
|
+
const getGuttersWithLineNumbers = (content: string, config: Config): DOMOutputSpec => [
|
|
50
|
+
'div',
|
|
51
|
+
{
|
|
52
|
+
// Based on packages/editor/editor-common/src/styles/shared/code-block.ts
|
|
53
|
+
// But we can't reuse that class as it adds a ::before that intefers with this approach
|
|
54
|
+
style: convertToInlineCss({
|
|
55
|
+
...getGutterBaseStyle(),
|
|
56
|
+
width: 'var(--lineNumberGutterWidth, 2rem)',
|
|
57
|
+
/* top and bottom | left and right */
|
|
58
|
+
padding: getGutterPadding(config.allowCodeFolding),
|
|
59
|
+
}),
|
|
60
|
+
contenteditable: 'false',
|
|
61
|
+
},
|
|
62
|
+
[
|
|
63
|
+
'div',
|
|
64
|
+
{
|
|
65
|
+
class: 'code-block-gutter-pseudo-element',
|
|
66
|
+
style: convertToInlineCss({
|
|
67
|
+
textAlign: 'right',
|
|
68
|
+
color: token('color.text.subtlest'),
|
|
69
|
+
fontFamily: token('font.family.code'),
|
|
70
|
+
whiteSpace: 'pre-wrap',
|
|
71
|
+
}),
|
|
72
|
+
'data-label': content,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
const getFoldOnlyGutter = (): DOMOutputSpec => [
|
|
78
|
+
'div',
|
|
79
|
+
{
|
|
80
|
+
style: convertToInlineCss({
|
|
81
|
+
...getGutterBaseStyle(),
|
|
82
|
+
padding: `${token('space.100')} ${token('space.150')} ${token('space.100')} ${token('space.100')}`,
|
|
83
|
+
}),
|
|
84
|
+
contenteditable: 'false',
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
const getGutters = (
|
|
89
|
+
content: string,
|
|
90
|
+
config: Config,
|
|
91
|
+
hideLineNumbers: boolean,
|
|
92
|
+
): DOMOutputSpec[] => {
|
|
93
|
+
if (!hideLineNumbers) {
|
|
94
|
+
return [getGuttersWithLineNumbers(content, config)];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (config.allowCodeFolding) {
|
|
98
|
+
return [getFoldOnlyGutter()];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return [];
|
|
102
|
+
};
|
|
103
|
+
|
|
34
104
|
// Based on: `packages/editor/editor-plugin-code-block/src/nodeviews/code-block.ts`
|
|
35
105
|
const toDOM = (node: Node, formattedAriaLabel: string, config: Config): DOMOutputSpec => {
|
|
36
106
|
let totalLineCount = 1;
|
|
@@ -42,12 +112,14 @@ const toDOM = (node: Node, formattedAriaLabel: string, config: Config): DOMOutpu
|
|
|
42
112
|
}
|
|
43
113
|
});
|
|
44
114
|
|
|
115
|
+
const hideLineNumbers = areCodeBlockLineNumbersHidden(node);
|
|
45
116
|
const maxDigits = totalLineCount.toString().length;
|
|
46
117
|
|
|
47
118
|
const content = node.textContent
|
|
48
119
|
.split('\n')
|
|
49
120
|
.map((_, i) => i + 1)
|
|
50
121
|
.join('\n');
|
|
122
|
+
const gutters = getGutters(content, config, hideLineNumbers);
|
|
51
123
|
|
|
52
124
|
return [
|
|
53
125
|
'pre',
|
|
@@ -57,6 +129,7 @@ const toDOM = (node: Node, formattedAriaLabel: string, config: Config): DOMOutpu
|
|
|
57
129
|
'data-language': node.attrs.language || '',
|
|
58
130
|
...(expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true) && {
|
|
59
131
|
'data-wrap': node.attrs.wrap ? 'true' : 'false',
|
|
132
|
+
...(hideLineNumbers && { 'data-hide-line-numbers': 'true' }),
|
|
60
133
|
}),
|
|
61
134
|
},
|
|
62
135
|
['div', { class: codeBlockClassNames.start, contenteditable: 'false' }],
|
|
@@ -65,39 +138,7 @@ const toDOM = (node: Node, formattedAriaLabel: string, config: Config): DOMOutpu
|
|
|
65
138
|
{
|
|
66
139
|
class: codeBlockClassNames.contentWrapper,
|
|
67
140
|
},
|
|
68
|
-
|
|
69
|
-
'div',
|
|
70
|
-
{
|
|
71
|
-
// Based on packages/editor/editor-common/src/styles/shared/code-block.ts
|
|
72
|
-
// But we can't reuse that class as it adds a ::before that intefers with this approach
|
|
73
|
-
style: convertToInlineCss({
|
|
74
|
-
backgroundColor: token('color.background.neutral'),
|
|
75
|
-
position: 'relative',
|
|
76
|
-
width: 'var(--lineNumberGutterWidth, 2rem)',
|
|
77
|
-
/* top and bottom | left and right */
|
|
78
|
-
padding: config.allowCodeFolding
|
|
79
|
-
? `${token('space.100')} ${token('space.250')} ${token('space.100')} ${token('space.075')}`
|
|
80
|
-
: token('space.100'),
|
|
81
|
-
flexShrink: 0,
|
|
82
|
-
fontSize: getFontSize(),
|
|
83
|
-
boxSizing: 'content-box',
|
|
84
|
-
}),
|
|
85
|
-
contenteditable: 'false',
|
|
86
|
-
},
|
|
87
|
-
[
|
|
88
|
-
'div',
|
|
89
|
-
{
|
|
90
|
-
class: 'code-block-gutter-pseudo-element',
|
|
91
|
-
style: convertToInlineCss({
|
|
92
|
-
textAlign: 'right',
|
|
93
|
-
color: token('color.text.subtlest'),
|
|
94
|
-
fontFamily: token('font.family.code'),
|
|
95
|
-
whiteSpace: 'pre-wrap',
|
|
96
|
-
}),
|
|
97
|
-
'data-label': content,
|
|
98
|
-
},
|
|
99
|
-
],
|
|
100
|
-
],
|
|
141
|
+
...gutters,
|
|
101
142
|
[
|
|
102
143
|
'div',
|
|
103
144
|
{
|
package/src/ui/theme.ts
CHANGED
|
@@ -75,6 +75,13 @@ export const cmTheme = (options?: ThemeOptions): Extension =>
|
|
|
75
75
|
border: 'none',
|
|
76
76
|
padding: token('space.0'),
|
|
77
77
|
color: token('color.text.subtlest'),
|
|
78
|
+
...(expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true) && {
|
|
79
|
+
// CodeMirror defaults this to height: 100%, which can resolve against an indefinite
|
|
80
|
+
// parent height in content-height editor and prevent flex stretching when gutter
|
|
81
|
+
// content is sparse, such as fold-only gutters.
|
|
82
|
+
height: 'unset',
|
|
83
|
+
alignSelf: 'stretch',
|
|
84
|
+
}),
|
|
78
85
|
},
|
|
79
86
|
'.cm-lineNumbers .cm-gutterElement': {
|
|
80
87
|
paddingLeft: token('space.0'),
|