@atlaskit/editor-plugin-code-block 3.6.1 → 3.6.2
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 +12 -0
- package/dist/cjs/codeBlockPlugin.js +3 -7
- package/dist/cjs/editor-commands/index.js +5 -13
- package/dist/cjs/pm-plugins/input-rule.js +4 -4
- package/dist/cjs/pm-plugins/transform-to-code-block.js +1 -12
- package/dist/es2019/codeBlockPlugin.js +3 -7
- package/dist/es2019/editor-commands/index.js +5 -12
- package/dist/es2019/pm-plugins/input-rule.js +4 -4
- package/dist/es2019/pm-plugins/transform-to-code-block.js +1 -12
- package/dist/esm/codeBlockPlugin.js +3 -7
- package/dist/esm/editor-commands/index.js +5 -13
- package/dist/esm/pm-plugins/input-rule.js +4 -4
- package/dist/esm/pm-plugins/transform-to-code-block.js +1 -12
- package/dist/types/editor-commands/index.d.ts +2 -3
- package/dist/types/pm-plugins/input-rule.d.ts +1 -1
- package/dist/types/pm-plugins/transform-to-code-block.d.ts +1 -1
- package/dist/types/ui/icons/WrapIcon.d.ts +2 -2
- package/dist/types-ts4.5/editor-commands/index.d.ts +2 -3
- package/dist/types-ts4.5/pm-plugins/input-rule.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/transform-to-code-block.d.ts +1 -1
- package/dist/types-ts4.5/ui/icons/WrapIcon.d.ts +2 -2
- package/package.json +2 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-code-block
|
|
2
2
|
|
|
3
|
+
## 3.6.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#107782](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/107782)
|
|
8
|
+
[`bc422d0adbbb5`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/bc422d0adbbb5) -
|
|
9
|
+
[ux] ED-26378 remove editor_nest_media_and_codeblock_in_quotes_jira
|
|
10
|
+
- [#107782](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/107782)
|
|
11
|
+
[`cccc7a8347929`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/cccc7a8347929) -
|
|
12
|
+
[ux] ED-26378 Remove editor_nest_media_and_codeblock_in_quotes_jira and
|
|
13
|
+
nestMediaAndCodeblockInQuote
|
|
14
|
+
|
|
3
15
|
## 3.6.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -11,7 +11,6 @@ var _adfSchema = require("@atlaskit/adf-schema");
|
|
|
11
11
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
12
12
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
13
13
|
var _quickInsert = require("@atlaskit/editor-common/quick-insert");
|
|
14
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
15
14
|
var _editorCommands = require("./editor-commands");
|
|
16
15
|
var _codeBlockAutoFullStopTransformPlugin = require("./pm-plugins/codeBlockAutoFullStopTransformPlugin");
|
|
17
16
|
var _codeBlockCopySelectionPlugin = require("./pm-plugins/codeBlockCopySelectionPlugin");
|
|
@@ -24,10 +23,8 @@ var _toolbar = require("./pm-plugins/toolbar");
|
|
|
24
23
|
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; }
|
|
25
24
|
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) { (0, _defineProperty2.default)(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; }
|
|
26
25
|
var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
27
|
-
var _api$featureFlags;
|
|
28
26
|
var options = _ref.config,
|
|
29
27
|
api = _ref.api;
|
|
30
|
-
var isNestingInQuoteSupported = (api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 || (_api$featureFlags = _api$featureFlags.sharedState.currentState()) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.nestMediaAndCodeblockInQuote) || (0, _platformFeatureFlags.fg)('editor_nest_media_and_codeblock_in_quotes_jira');
|
|
31
28
|
return {
|
|
32
29
|
name: 'codeBlock',
|
|
33
30
|
nodes: function nodes() {
|
|
@@ -59,7 +56,7 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
|
59
56
|
plugin: function plugin(_ref3) {
|
|
60
57
|
var _api$analytics;
|
|
61
58
|
var schema = _ref3.schema;
|
|
62
|
-
return (0, _inputRule.createCodeBlockInputRule)(schema, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions
|
|
59
|
+
return (0, _inputRule.createCodeBlockInputRule)(schema, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
|
|
63
60
|
}
|
|
64
61
|
}, {
|
|
65
62
|
name: 'codeBlockIDEKeyBindings',
|
|
@@ -95,7 +92,7 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
|
95
92
|
*/
|
|
96
93
|
insertCodeBlock: function insertCodeBlock(inputMethod) {
|
|
97
94
|
var _api$analytics2;
|
|
98
|
-
return (0, _editorCommands.insertCodeBlockWithAnalytics)(inputMethod, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions
|
|
95
|
+
return (0, _editorCommands.insertCodeBlockWithAnalytics)(inputMethod, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
|
|
99
96
|
}
|
|
100
97
|
},
|
|
101
98
|
pluginsOptions: {
|
|
@@ -114,8 +111,7 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
|
114
111
|
action: function action(_insert, state) {
|
|
115
112
|
var _api$analytics3;
|
|
116
113
|
var tr = (0, _editorCommands.createInsertCodeBlockTransaction)({
|
|
117
|
-
state: state
|
|
118
|
-
isNestingInQuoteSupported: isNestingInQuoteSupported
|
|
114
|
+
state: state
|
|
119
115
|
});
|
|
120
116
|
api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 || _api$analytics3.actions.attachAnalyticsEvent({
|
|
121
117
|
action: _analytics.ACTION.INSERTED,
|
|
@@ -138,12 +138,9 @@ var resetShouldIgnoreFollowingMutations = exports.resetShouldIgnoreFollowingMuta
|
|
|
138
138
|
* append the codeblock to the end of the document.
|
|
139
139
|
*/
|
|
140
140
|
function createInsertCodeBlockTransaction(_ref) {
|
|
141
|
-
var state = _ref.state
|
|
142
|
-
isNestingInQuoteSupported = _ref.isNestingInQuoteSupported;
|
|
141
|
+
var state = _ref.state;
|
|
143
142
|
var tr = state.tr;
|
|
144
|
-
var
|
|
145
|
-
from = _state$selection.from,
|
|
146
|
-
$from = _state$selection.$from;
|
|
143
|
+
var from = state.selection.from;
|
|
147
144
|
var codeBlock = state.schema.nodes.codeBlock;
|
|
148
145
|
var grandParentNode = state.selection.$from.node(-1);
|
|
149
146
|
var grandParentNodeType = grandParentNode === null || grandParentNode === void 0 ? void 0 : grandParentNode.type;
|
|
@@ -160,17 +157,13 @@ function createInsertCodeBlockTransaction(_ref) {
|
|
|
160
157
|
content: codeBlock.createAndFill()
|
|
161
158
|
}) && (0, _insert.contentAllowedInCodeBlock)(state);
|
|
162
159
|
if (canInsertCodeBlock) {
|
|
163
|
-
tr = (0, _transformToCodeBlock.transformToCodeBlockAction)(state, from, undefined
|
|
164
|
-
} else if (!isNestingInQuoteSupported && (grandParentNodeType === null || grandParentNodeType === void 0 ? void 0 : grandParentNodeType.name) === 'blockquote') {
|
|
165
|
-
/** we only allow the insertion of a codeblock inside a blockquote if nesting in quotes is supported */
|
|
166
|
-
var grandparentEndPos = $from.start(-1) + grandParentNode.nodeSize - 1;
|
|
167
|
-
(0, _utils.safeInsert)(codeBlock.createAndFill(), grandparentEndPos)(tr).scrollIntoView();
|
|
160
|
+
tr = (0, _transformToCodeBlock.transformToCodeBlockAction)(state, from, undefined);
|
|
168
161
|
} else {
|
|
169
162
|
(0, _utils.safeInsert)(codeBlock.createAndFill())(tr).scrollIntoView();
|
|
170
163
|
}
|
|
171
164
|
return tr;
|
|
172
165
|
}
|
|
173
|
-
function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI
|
|
166
|
+
function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI) {
|
|
174
167
|
return (0, _editorAnalytics.withAnalytics)(analyticsAPI, {
|
|
175
168
|
action: _analytics.ACTION.INSERTED,
|
|
176
169
|
actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
|
|
@@ -181,8 +174,7 @@ function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI, isNestingInQuot
|
|
|
181
174
|
eventType: _analytics.EVENT_TYPE.TRACK
|
|
182
175
|
})(function (state, dispatch) {
|
|
183
176
|
var tr = createInsertCodeBlockTransaction({
|
|
184
|
-
state: state
|
|
185
|
-
isNestingInQuoteSupported: isNestingInQuoteSupported
|
|
177
|
+
state: state
|
|
186
178
|
});
|
|
187
179
|
if (dispatch) {
|
|
188
180
|
dispatch(tr);
|
|
@@ -11,8 +11,8 @@ var _utils = require("@atlaskit/editor-common/utils");
|
|
|
11
11
|
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
12
12
|
var _prosemirrorInputRules = require("@atlaskit/prosemirror-input-rules");
|
|
13
13
|
var _transformToCodeBlock = require("./transform-to-code-block");
|
|
14
|
-
function createCodeBlockInputRule(schema, editorAnalyticsAPI
|
|
15
|
-
var rules = getCodeBlockRules(editorAnalyticsAPI, schema
|
|
14
|
+
function createCodeBlockInputRule(schema, editorAnalyticsAPI) {
|
|
15
|
+
var rules = getCodeBlockRules(editorAnalyticsAPI, schema);
|
|
16
16
|
return new _safePlugin.SafePlugin((0, _prosemirrorInputRules.createPlugin)('code-block-input-rule', rules, {
|
|
17
17
|
isBlockNodeRule: true
|
|
18
18
|
}));
|
|
@@ -24,7 +24,7 @@ function createCodeBlockInputRule(schema, editorAnalyticsAPI, isNestingInQuoteSu
|
|
|
24
24
|
* @param {Schema} schema
|
|
25
25
|
* @returns {InputRuleWithHandler[]}
|
|
26
26
|
*/
|
|
27
|
-
function getCodeBlockRules(editorAnalyticsAPI, schema
|
|
27
|
+
function getCodeBlockRules(editorAnalyticsAPI, schema) {
|
|
28
28
|
var ruleAnalytics = (0, _utils.inputRuleWithAnalytics)({
|
|
29
29
|
action: _analytics.ACTION.INSERTED,
|
|
30
30
|
actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
|
|
@@ -51,7 +51,7 @@ function getCodeBlockRules(editorAnalyticsAPI, schema, isNestingInQuoteSupported
|
|
|
51
51
|
attributes.language = match[4];
|
|
52
52
|
}
|
|
53
53
|
if ((0, _transformToCodeBlock.isConvertableToCodeBlock)(state)) {
|
|
54
|
-
return (0, _transformToCodeBlock.transformToCodeBlockAction)(state, start, attributes
|
|
54
|
+
return (0, _transformToCodeBlock.transformToCodeBlockAction)(state, start, attributes);
|
|
55
55
|
}
|
|
56
56
|
var tr = state.tr;
|
|
57
57
|
tr.delete(start, end);
|
|
@@ -9,11 +9,10 @@ var _selection = require("@atlaskit/editor-common/selection");
|
|
|
9
9
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
10
10
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
11
11
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
12
|
-
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
13
12
|
function transformToCodeBlockAction(state, start,
|
|
14
13
|
// Ignored via go/ees005
|
|
15
14
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
-
attrs
|
|
15
|
+
attrs) {
|
|
17
16
|
var startOfCodeBlockText = state.selection.$from;
|
|
18
17
|
var endPosition = state.selection.empty && !(state.selection instanceof _selection.GapCursorSelection) ? startOfCodeBlockText.end() : state.selection.$to.pos;
|
|
19
18
|
var startLinePosition = startOfCodeBlockText.start();
|
|
@@ -61,16 +60,6 @@ attrs, isNestingInQuoteSupported) {
|
|
|
61
60
|
var startMapped = startLinePosition === start ? parentStartPosition : start;
|
|
62
61
|
var codeBlock = state.schema.nodes.codeBlock;
|
|
63
62
|
var codeBlockNode = codeBlock.createChecked(attrs, codeBlockSlice.content);
|
|
64
|
-
|
|
65
|
-
/** we only allow the insertion of a codeblock inside a blockquote if nesting in quotes is supported */
|
|
66
|
-
var grandParentNode = state.selection.$from.node(-1);
|
|
67
|
-
var grandParentNodeType = grandParentNode === null || grandParentNode === void 0 ? void 0 : grandParentNode.type.name;
|
|
68
|
-
if (grandParentNodeType === 'blockquote' && !isNestingInQuoteSupported) {
|
|
69
|
-
var grandparentEndPos = startOfCodeBlockText.start(-1) + grandParentNode.nodeSize - 1;
|
|
70
|
-
(0, _utils2.safeInsert)(codeBlock.createChecked(attrs, codeBlockSlice.content), grandparentEndPos)(tr).scrollIntoView();
|
|
71
|
-
tr.delete(startMapped, Math.min(endPosition, tr.doc.content.size));
|
|
72
|
-
return tr;
|
|
73
|
-
}
|
|
74
63
|
tr.replaceWith(startMapped, Math.min(endPosition, tr.doc.content.size), codeBlockNode);
|
|
75
64
|
|
|
76
65
|
// Reposition cursor when inserting into layouts or table headers
|
|
@@ -3,7 +3,6 @@ import { codeBlock } from '@atlaskit/adf-schema';
|
|
|
3
3
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
4
4
|
import { blockTypeMessages } from '@atlaskit/editor-common/messages';
|
|
5
5
|
import { IconCode } from '@atlaskit/editor-common/quick-insert';
|
|
6
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
7
6
|
import { createInsertCodeBlockTransaction, insertCodeBlockWithAnalytics } from './editor-commands';
|
|
8
7
|
import { codeBlockAutoFullStopTransformPlugin } from './pm-plugins/codeBlockAutoFullStopTransformPlugin';
|
|
9
8
|
import { codeBlockCopySelectionPlugin, copySelectionPluginKey } from './pm-plugins/codeBlockCopySelectionPlugin';
|
|
@@ -17,8 +16,6 @@ const codeBlockPlugin = ({
|
|
|
17
16
|
config: options,
|
|
18
17
|
api
|
|
19
18
|
}) => {
|
|
20
|
-
var _api$featureFlags, _api$featureFlags$sha;
|
|
21
|
-
const isNestingInQuoteSupported = (api === null || api === void 0 ? void 0 : (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : (_api$featureFlags$sha = _api$featureFlags.sharedState.currentState()) === null || _api$featureFlags$sha === void 0 ? void 0 : _api$featureFlags$sha.nestMediaAndCodeblockInQuote) || fg('editor_nest_media_and_codeblock_in_quotes_jira');
|
|
22
19
|
return {
|
|
23
20
|
name: 'codeBlock',
|
|
24
21
|
nodes() {
|
|
@@ -51,7 +48,7 @@ const codeBlockPlugin = ({
|
|
|
51
48
|
schema
|
|
52
49
|
}) => {
|
|
53
50
|
var _api$analytics;
|
|
54
|
-
return createCodeBlockInputRule(schema, api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions
|
|
51
|
+
return createCodeBlockInputRule(schema, api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
|
|
55
52
|
}
|
|
56
53
|
}, {
|
|
57
54
|
name: 'codeBlockIDEKeyBindings',
|
|
@@ -80,7 +77,7 @@ const codeBlockPlugin = ({
|
|
|
80
77
|
*/
|
|
81
78
|
insertCodeBlock: inputMethod => {
|
|
82
79
|
var _api$analytics2;
|
|
83
|
-
return insertCodeBlockWithAnalytics(inputMethod, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions
|
|
80
|
+
return insertCodeBlockWithAnalytics(inputMethod, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
|
|
84
81
|
}
|
|
85
82
|
},
|
|
86
83
|
pluginsOptions: {
|
|
@@ -97,8 +94,7 @@ const codeBlockPlugin = ({
|
|
|
97
94
|
action(_insert, state) {
|
|
98
95
|
var _api$analytics3;
|
|
99
96
|
const tr = createInsertCodeBlockTransaction({
|
|
100
|
-
state
|
|
101
|
-
isNestingInQuoteSupported
|
|
97
|
+
state
|
|
102
98
|
});
|
|
103
99
|
api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions.attachAnalyticsEvent({
|
|
104
100
|
action: ACTION.INSERTED,
|
|
@@ -140,15 +140,13 @@ export const resetShouldIgnoreFollowingMutations = (state, dispatch) => {
|
|
|
140
140
|
* append the codeblock to the end of the document.
|
|
141
141
|
*/
|
|
142
142
|
export function createInsertCodeBlockTransaction({
|
|
143
|
-
state
|
|
144
|
-
isNestingInQuoteSupported
|
|
143
|
+
state
|
|
145
144
|
}) {
|
|
146
145
|
let {
|
|
147
146
|
tr
|
|
148
147
|
} = state;
|
|
149
148
|
const {
|
|
150
|
-
from
|
|
151
|
-
$from
|
|
149
|
+
from
|
|
152
150
|
} = state.selection;
|
|
153
151
|
const {
|
|
154
152
|
codeBlock
|
|
@@ -168,17 +166,13 @@ export function createInsertCodeBlockTransaction({
|
|
|
168
166
|
content: codeBlock.createAndFill()
|
|
169
167
|
}) && contentAllowedInCodeBlock(state);
|
|
170
168
|
if (canInsertCodeBlock) {
|
|
171
|
-
tr = transformToCodeBlockAction(state, from, undefined
|
|
172
|
-
} else if (!isNestingInQuoteSupported && (grandParentNodeType === null || grandParentNodeType === void 0 ? void 0 : grandParentNodeType.name) === 'blockquote') {
|
|
173
|
-
/** we only allow the insertion of a codeblock inside a blockquote if nesting in quotes is supported */
|
|
174
|
-
const grandparentEndPos = $from.start(-1) + grandParentNode.nodeSize - 1;
|
|
175
|
-
safeInsert(codeBlock.createAndFill(), grandparentEndPos)(tr).scrollIntoView();
|
|
169
|
+
tr = transformToCodeBlockAction(state, from, undefined);
|
|
176
170
|
} else {
|
|
177
171
|
safeInsert(codeBlock.createAndFill())(tr).scrollIntoView();
|
|
178
172
|
}
|
|
179
173
|
return tr;
|
|
180
174
|
}
|
|
181
|
-
export function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI
|
|
175
|
+
export function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI) {
|
|
182
176
|
return withAnalytics(analyticsAPI, {
|
|
183
177
|
action: ACTION.INSERTED,
|
|
184
178
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
@@ -189,8 +183,7 @@ export function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI, isNestin
|
|
|
189
183
|
eventType: EVENT_TYPE.TRACK
|
|
190
184
|
})(function (state, dispatch) {
|
|
191
185
|
const tr = createInsertCodeBlockTransaction({
|
|
192
|
-
state
|
|
193
|
-
isNestingInQuoteSupported
|
|
186
|
+
state
|
|
194
187
|
});
|
|
195
188
|
if (dispatch) {
|
|
196
189
|
dispatch(tr);
|
|
@@ -5,8 +5,8 @@ import { createRule, inputRuleWithAnalytics } from '@atlaskit/editor-common/util
|
|
|
5
5
|
import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
6
6
|
import { createPlugin, leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
|
|
7
7
|
import { isConvertableToCodeBlock, transformToCodeBlockAction } from './transform-to-code-block';
|
|
8
|
-
export function createCodeBlockInputRule(schema, editorAnalyticsAPI
|
|
9
|
-
const rules = getCodeBlockRules(editorAnalyticsAPI, schema
|
|
8
|
+
export function createCodeBlockInputRule(schema, editorAnalyticsAPI) {
|
|
9
|
+
const rules = getCodeBlockRules(editorAnalyticsAPI, schema);
|
|
10
10
|
return new SafePlugin(createPlugin('code-block-input-rule', rules, {
|
|
11
11
|
isBlockNodeRule: true
|
|
12
12
|
}));
|
|
@@ -18,7 +18,7 @@ export function createCodeBlockInputRule(schema, editorAnalyticsAPI, isNestingIn
|
|
|
18
18
|
* @param {Schema} schema
|
|
19
19
|
* @returns {InputRuleWithHandler[]}
|
|
20
20
|
*/
|
|
21
|
-
function getCodeBlockRules(editorAnalyticsAPI, schema
|
|
21
|
+
function getCodeBlockRules(editorAnalyticsAPI, schema) {
|
|
22
22
|
const ruleAnalytics = inputRuleWithAnalytics({
|
|
23
23
|
action: ACTION.INSERTED,
|
|
24
24
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
@@ -43,7 +43,7 @@ function getCodeBlockRules(editorAnalyticsAPI, schema, isNestingInQuoteSupported
|
|
|
43
43
|
attributes.language = match[4];
|
|
44
44
|
}
|
|
45
45
|
if (isConvertableToCodeBlock(state)) {
|
|
46
|
-
return transformToCodeBlockAction(state, start, attributes
|
|
46
|
+
return transformToCodeBlockAction(state, start, attributes);
|
|
47
47
|
}
|
|
48
48
|
const tr = state.tr;
|
|
49
49
|
tr.delete(start, end);
|
|
@@ -2,11 +2,10 @@ import { GapCursorSelection } from '@atlaskit/editor-common/selection';
|
|
|
2
2
|
import { mapSlice, timestampToString } from '@atlaskit/editor-common/utils';
|
|
3
3
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
4
4
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
-
import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
6
5
|
export function transformToCodeBlockAction(state, start,
|
|
7
6
|
// Ignored via go/ees005
|
|
8
7
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
-
attrs
|
|
8
|
+
attrs) {
|
|
10
9
|
const startOfCodeBlockText = state.selection.$from;
|
|
11
10
|
const endPosition = state.selection.empty && !(state.selection instanceof GapCursorSelection) ? startOfCodeBlockText.end() : state.selection.$to.pos;
|
|
12
11
|
const startLinePosition = startOfCodeBlockText.start();
|
|
@@ -54,16 +53,6 @@ attrs, isNestingInQuoteSupported) {
|
|
|
54
53
|
const startMapped = startLinePosition === start ? parentStartPosition : start;
|
|
55
54
|
const codeBlock = state.schema.nodes.codeBlock;
|
|
56
55
|
const codeBlockNode = codeBlock.createChecked(attrs, codeBlockSlice.content);
|
|
57
|
-
|
|
58
|
-
/** we only allow the insertion of a codeblock inside a blockquote if nesting in quotes is supported */
|
|
59
|
-
const grandParentNode = state.selection.$from.node(-1);
|
|
60
|
-
const grandParentNodeType = grandParentNode === null || grandParentNode === void 0 ? void 0 : grandParentNode.type.name;
|
|
61
|
-
if (grandParentNodeType === 'blockquote' && !isNestingInQuoteSupported) {
|
|
62
|
-
const grandparentEndPos = startOfCodeBlockText.start(-1) + grandParentNode.nodeSize - 1;
|
|
63
|
-
safeInsert(codeBlock.createChecked(attrs, codeBlockSlice.content), grandparentEndPos)(tr).scrollIntoView();
|
|
64
|
-
tr.delete(startMapped, Math.min(endPosition, tr.doc.content.size));
|
|
65
|
-
return tr;
|
|
66
|
-
}
|
|
67
56
|
tr.replaceWith(startMapped, Math.min(endPosition, tr.doc.content.size), codeBlockNode);
|
|
68
57
|
|
|
69
58
|
// Reposition cursor when inserting into layouts or table headers
|
|
@@ -6,7 +6,6 @@ import { codeBlock } from '@atlaskit/adf-schema';
|
|
|
6
6
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
7
7
|
import { blockTypeMessages } from '@atlaskit/editor-common/messages';
|
|
8
8
|
import { IconCode } from '@atlaskit/editor-common/quick-insert';
|
|
9
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
10
9
|
import { createInsertCodeBlockTransaction, insertCodeBlockWithAnalytics } from './editor-commands';
|
|
11
10
|
import { codeBlockAutoFullStopTransformPlugin } from './pm-plugins/codeBlockAutoFullStopTransformPlugin';
|
|
12
11
|
import { codeBlockCopySelectionPlugin, copySelectionPluginKey } from './pm-plugins/codeBlockCopySelectionPlugin';
|
|
@@ -17,10 +16,8 @@ import { createPlugin } from './pm-plugins/main';
|
|
|
17
16
|
import refreshBrowserSelectionOnChange from './pm-plugins/refresh-browser-selection';
|
|
18
17
|
import { getToolbarConfig } from './pm-plugins/toolbar';
|
|
19
18
|
var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
20
|
-
var _api$featureFlags;
|
|
21
19
|
var options = _ref.config,
|
|
22
20
|
api = _ref.api;
|
|
23
|
-
var isNestingInQuoteSupported = (api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 || (_api$featureFlags = _api$featureFlags.sharedState.currentState()) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.nestMediaAndCodeblockInQuote) || fg('editor_nest_media_and_codeblock_in_quotes_jira');
|
|
24
21
|
return {
|
|
25
22
|
name: 'codeBlock',
|
|
26
23
|
nodes: function nodes() {
|
|
@@ -52,7 +49,7 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
|
52
49
|
plugin: function plugin(_ref3) {
|
|
53
50
|
var _api$analytics;
|
|
54
51
|
var schema = _ref3.schema;
|
|
55
|
-
return createCodeBlockInputRule(schema, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions
|
|
52
|
+
return createCodeBlockInputRule(schema, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
|
|
56
53
|
}
|
|
57
54
|
}, {
|
|
58
55
|
name: 'codeBlockIDEKeyBindings',
|
|
@@ -88,7 +85,7 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
|
88
85
|
*/
|
|
89
86
|
insertCodeBlock: function insertCodeBlock(inputMethod) {
|
|
90
87
|
var _api$analytics2;
|
|
91
|
-
return insertCodeBlockWithAnalytics(inputMethod, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions
|
|
88
|
+
return insertCodeBlockWithAnalytics(inputMethod, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
|
|
92
89
|
}
|
|
93
90
|
},
|
|
94
91
|
pluginsOptions: {
|
|
@@ -107,8 +104,7 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
|
107
104
|
action: function action(_insert, state) {
|
|
108
105
|
var _api$analytics3;
|
|
109
106
|
var tr = createInsertCodeBlockTransaction({
|
|
110
|
-
state: state
|
|
111
|
-
isNestingInQuoteSupported: isNestingInQuoteSupported
|
|
107
|
+
state: state
|
|
112
108
|
});
|
|
113
109
|
api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 || _api$analytics3.actions.attachAnalyticsEvent({
|
|
114
110
|
action: ACTION.INSERTED,
|
|
@@ -128,12 +128,9 @@ export var resetShouldIgnoreFollowingMutations = function resetShouldIgnoreFollo
|
|
|
128
128
|
* append the codeblock to the end of the document.
|
|
129
129
|
*/
|
|
130
130
|
export function createInsertCodeBlockTransaction(_ref) {
|
|
131
|
-
var state = _ref.state
|
|
132
|
-
isNestingInQuoteSupported = _ref.isNestingInQuoteSupported;
|
|
131
|
+
var state = _ref.state;
|
|
133
132
|
var tr = state.tr;
|
|
134
|
-
var
|
|
135
|
-
from = _state$selection.from,
|
|
136
|
-
$from = _state$selection.$from;
|
|
133
|
+
var from = state.selection.from;
|
|
137
134
|
var codeBlock = state.schema.nodes.codeBlock;
|
|
138
135
|
var grandParentNode = state.selection.$from.node(-1);
|
|
139
136
|
var grandParentNodeType = grandParentNode === null || grandParentNode === void 0 ? void 0 : grandParentNode.type;
|
|
@@ -150,17 +147,13 @@ export function createInsertCodeBlockTransaction(_ref) {
|
|
|
150
147
|
content: codeBlock.createAndFill()
|
|
151
148
|
}) && contentAllowedInCodeBlock(state);
|
|
152
149
|
if (canInsertCodeBlock) {
|
|
153
|
-
tr = transformToCodeBlockAction(state, from, undefined
|
|
154
|
-
} else if (!isNestingInQuoteSupported && (grandParentNodeType === null || grandParentNodeType === void 0 ? void 0 : grandParentNodeType.name) === 'blockquote') {
|
|
155
|
-
/** we only allow the insertion of a codeblock inside a blockquote if nesting in quotes is supported */
|
|
156
|
-
var grandparentEndPos = $from.start(-1) + grandParentNode.nodeSize - 1;
|
|
157
|
-
safeInsert(codeBlock.createAndFill(), grandparentEndPos)(tr).scrollIntoView();
|
|
150
|
+
tr = transformToCodeBlockAction(state, from, undefined);
|
|
158
151
|
} else {
|
|
159
152
|
safeInsert(codeBlock.createAndFill())(tr).scrollIntoView();
|
|
160
153
|
}
|
|
161
154
|
return tr;
|
|
162
155
|
}
|
|
163
|
-
export function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI
|
|
156
|
+
export function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI) {
|
|
164
157
|
return withAnalytics(analyticsAPI, {
|
|
165
158
|
action: ACTION.INSERTED,
|
|
166
159
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
@@ -171,8 +164,7 @@ export function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI, isNestin
|
|
|
171
164
|
eventType: EVENT_TYPE.TRACK
|
|
172
165
|
})(function (state, dispatch) {
|
|
173
166
|
var tr = createInsertCodeBlockTransaction({
|
|
174
|
-
state: state
|
|
175
|
-
isNestingInQuoteSupported: isNestingInQuoteSupported
|
|
167
|
+
state: state
|
|
176
168
|
});
|
|
177
169
|
if (dispatch) {
|
|
178
170
|
dispatch(tr);
|
|
@@ -5,8 +5,8 @@ import { createRule, inputRuleWithAnalytics } from '@atlaskit/editor-common/util
|
|
|
5
5
|
import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
6
6
|
import { createPlugin, leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
|
|
7
7
|
import { isConvertableToCodeBlock, transformToCodeBlockAction } from './transform-to-code-block';
|
|
8
|
-
export function createCodeBlockInputRule(schema, editorAnalyticsAPI
|
|
9
|
-
var rules = getCodeBlockRules(editorAnalyticsAPI, schema
|
|
8
|
+
export function createCodeBlockInputRule(schema, editorAnalyticsAPI) {
|
|
9
|
+
var rules = getCodeBlockRules(editorAnalyticsAPI, schema);
|
|
10
10
|
return new SafePlugin(createPlugin('code-block-input-rule', rules, {
|
|
11
11
|
isBlockNodeRule: true
|
|
12
12
|
}));
|
|
@@ -18,7 +18,7 @@ export function createCodeBlockInputRule(schema, editorAnalyticsAPI, isNestingIn
|
|
|
18
18
|
* @param {Schema} schema
|
|
19
19
|
* @returns {InputRuleWithHandler[]}
|
|
20
20
|
*/
|
|
21
|
-
function getCodeBlockRules(editorAnalyticsAPI, schema
|
|
21
|
+
function getCodeBlockRules(editorAnalyticsAPI, schema) {
|
|
22
22
|
var ruleAnalytics = inputRuleWithAnalytics({
|
|
23
23
|
action: ACTION.INSERTED,
|
|
24
24
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
@@ -45,7 +45,7 @@ function getCodeBlockRules(editorAnalyticsAPI, schema, isNestingInQuoteSupported
|
|
|
45
45
|
attributes.language = match[4];
|
|
46
46
|
}
|
|
47
47
|
if (isConvertableToCodeBlock(state)) {
|
|
48
|
-
return transformToCodeBlockAction(state, start, attributes
|
|
48
|
+
return transformToCodeBlockAction(state, start, attributes);
|
|
49
49
|
}
|
|
50
50
|
var tr = state.tr;
|
|
51
51
|
tr.delete(start, end);
|
|
@@ -2,11 +2,10 @@ import { GapCursorSelection } from '@atlaskit/editor-common/selection';
|
|
|
2
2
|
import { mapSlice, timestampToString } from '@atlaskit/editor-common/utils';
|
|
3
3
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
4
4
|
import { TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
-
import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
6
5
|
export function transformToCodeBlockAction(state, start,
|
|
7
6
|
// Ignored via go/ees005
|
|
8
7
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
-
attrs
|
|
8
|
+
attrs) {
|
|
10
9
|
var startOfCodeBlockText = state.selection.$from;
|
|
11
10
|
var endPosition = state.selection.empty && !(state.selection instanceof GapCursorSelection) ? startOfCodeBlockText.end() : state.selection.$to.pos;
|
|
12
11
|
var startLinePosition = startOfCodeBlockText.start();
|
|
@@ -54,16 +53,6 @@ attrs, isNestingInQuoteSupported) {
|
|
|
54
53
|
var startMapped = startLinePosition === start ? parentStartPosition : start;
|
|
55
54
|
var codeBlock = state.schema.nodes.codeBlock;
|
|
56
55
|
var codeBlockNode = codeBlock.createChecked(attrs, codeBlockSlice.content);
|
|
57
|
-
|
|
58
|
-
/** we only allow the insertion of a codeblock inside a blockquote if nesting in quotes is supported */
|
|
59
|
-
var grandParentNode = state.selection.$from.node(-1);
|
|
60
|
-
var grandParentNodeType = grandParentNode === null || grandParentNode === void 0 ? void 0 : grandParentNode.type.name;
|
|
61
|
-
if (grandParentNodeType === 'blockquote' && !isNestingInQuoteSupported) {
|
|
62
|
-
var grandparentEndPos = startOfCodeBlockText.start(-1) + grandParentNode.nodeSize - 1;
|
|
63
|
-
safeInsert(codeBlock.createChecked(attrs, codeBlockSlice.content), grandparentEndPos)(tr).scrollIntoView();
|
|
64
|
-
tr.delete(startMapped, Math.min(endPosition, tr.doc.content.size));
|
|
65
|
-
return tr;
|
|
66
|
-
}
|
|
67
56
|
tr.replaceWith(startMapped, Math.min(endPosition, tr.doc.content.size), codeBlockNode);
|
|
68
57
|
|
|
69
58
|
// Reposition cursor when inserting into layouts or table headers
|
|
@@ -12,11 +12,10 @@ export declare const resetShouldIgnoreFollowingMutations: Command;
|
|
|
12
12
|
* if there is text selected it will wrap the current selection if not it will
|
|
13
13
|
* append the codeblock to the end of the document.
|
|
14
14
|
*/
|
|
15
|
-
export declare function createInsertCodeBlockTransaction({ state
|
|
15
|
+
export declare function createInsertCodeBlockTransaction({ state }: {
|
|
16
16
|
state: EditorState;
|
|
17
|
-
isNestingInQuoteSupported?: boolean;
|
|
18
17
|
}): import("prosemirror-state").Transaction;
|
|
19
|
-
export declare function insertCodeBlockWithAnalytics(inputMethod: INPUT_METHOD, analyticsAPI?: EditorAnalyticsAPI
|
|
18
|
+
export declare function insertCodeBlockWithAnalytics(inputMethod: INPUT_METHOD, analyticsAPI?: EditorAnalyticsAPI): Command;
|
|
20
19
|
/**
|
|
21
20
|
* Add the given node to the codeBlockWrappedStates WeakMap with the toggle boolean value.
|
|
22
21
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
3
|
import type { Schema } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
-
export declare function createCodeBlockInputRule(schema: Schema, editorAnalyticsAPI?: EditorAnalyticsAPI
|
|
4
|
+
export declare function createCodeBlockInputRule(schema: Schema, editorAnalyticsAPI?: EditorAnalyticsAPI): SafePlugin<any>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
export declare function transformToCodeBlockAction(state: EditorState, start: number, attrs?: any
|
|
2
|
+
export declare function transformToCodeBlockAction(state: EditorState, start: number, attrs?: any): Transaction;
|
|
3
3
|
export declare function isConvertableToCodeBlock(state: EditorState): boolean;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const WrapIcon: () => JSX.Element;
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare const WrapIcon: () => React.JSX.Element;
|
|
@@ -12,11 +12,10 @@ export declare const resetShouldIgnoreFollowingMutations: Command;
|
|
|
12
12
|
* if there is text selected it will wrap the current selection if not it will
|
|
13
13
|
* append the codeblock to the end of the document.
|
|
14
14
|
*/
|
|
15
|
-
export declare function createInsertCodeBlockTransaction({ state
|
|
15
|
+
export declare function createInsertCodeBlockTransaction({ state }: {
|
|
16
16
|
state: EditorState;
|
|
17
|
-
isNestingInQuoteSupported?: boolean;
|
|
18
17
|
}): import("prosemirror-state").Transaction;
|
|
19
|
-
export declare function insertCodeBlockWithAnalytics(inputMethod: INPUT_METHOD, analyticsAPI?: EditorAnalyticsAPI
|
|
18
|
+
export declare function insertCodeBlockWithAnalytics(inputMethod: INPUT_METHOD, analyticsAPI?: EditorAnalyticsAPI): Command;
|
|
20
19
|
/**
|
|
21
20
|
* Add the given node to the codeBlockWrappedStates WeakMap with the toggle boolean value.
|
|
22
21
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
3
|
import type { Schema } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
-
export declare function createCodeBlockInputRule(schema: Schema, editorAnalyticsAPI?: EditorAnalyticsAPI
|
|
4
|
+
export declare function createCodeBlockInputRule(schema: Schema, editorAnalyticsAPI?: EditorAnalyticsAPI): SafePlugin<any>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
2
|
-
export declare function transformToCodeBlockAction(state: EditorState, start: number, attrs?: any
|
|
2
|
+
export declare function transformToCodeBlockAction(state: EditorState, start: number, attrs?: any): Transaction;
|
|
3
3
|
export declare function isConvertableToCodeBlock(state: EditorState): boolean;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const WrapIcon: () => JSX.Element;
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare const WrapIcon: () => React.JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-code-block",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.2",
|
|
4
4
|
"description": "Code block plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@atlaskit/adf-schema": "^46.1.0",
|
|
35
35
|
"@atlaskit/code": "^15.7.0",
|
|
36
|
-
"@atlaskit/editor-common": "^99.
|
|
36
|
+
"@atlaskit/editor-common": "^99.8.0",
|
|
37
37
|
"@atlaskit/editor-plugin-analytics": "^1.11.0",
|
|
38
38
|
"@atlaskit/editor-plugin-composition": "^1.2.0",
|
|
39
39
|
"@atlaskit/editor-plugin-decorations": "^1.4.0",
|
|
@@ -96,9 +96,6 @@
|
|
|
96
96
|
"code_block_auto_insertion_bug_fix": {
|
|
97
97
|
"type": "boolean"
|
|
98
98
|
},
|
|
99
|
-
"editor_nest_media_and_codeblock_in_quotes_jira": {
|
|
100
|
-
"type": "boolean"
|
|
101
|
-
},
|
|
102
99
|
"editor_code_wrapping_perf_improvement_ed-25141": {
|
|
103
100
|
"type": "boolean"
|
|
104
101
|
}
|