@atlaskit/editor-plugin-code-block 3.3.16 → 3.3.17
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 +9 -0
- package/dist/cjs/actions.js +15 -7
- package/dist/cjs/plugin.js +7 -3
- package/dist/cjs/pm-plugins/input-rule.js +4 -4
- package/dist/cjs/transform-to-code-block.js +12 -1
- package/dist/es2019/actions.js +14 -7
- package/dist/es2019/plugin.js +91 -85
- package/dist/es2019/pm-plugins/input-rule.js +5 -6
- package/dist/es2019/transform-to-code-block.js +12 -1
- package/dist/esm/actions.js +15 -7
- package/dist/esm/plugin.js +7 -3
- package/dist/esm/pm-plugins/input-rule.js +5 -6
- package/dist/esm/transform-to-code-block.js +12 -1
- package/dist/types/actions.d.ts +3 -2
- package/dist/types/plugin.d.ts +3 -1
- package/dist/types/pm-plugins/input-rule.d.ts +1 -1
- package/dist/types/pm-plugins/main.d.ts +4 -1
- package/dist/types/transform-to-code-block.d.ts +1 -1
- package/dist/types-ts4.5/actions.d.ts +3 -2
- package/dist/types-ts4.5/plugin.d.ts +3 -1
- package/dist/types-ts4.5/pm-plugins/input-rule.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/main.d.ts +5 -1
- package/dist/types-ts4.5/transform-to-code-block.d.ts +1 -1
- package/package.json +6 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-code-block
|
|
2
2
|
|
|
3
|
+
## 3.3.17
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#141594](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/141594)
|
|
8
|
+
[`3f6b2eb7bd493`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3f6b2eb7bd493) -
|
|
9
|
+
[ux] [ED-24867] This change moves nesting codeblocks and media in blockquotes via insertion
|
|
10
|
+
methods behind an experiment gate.
|
|
11
|
+
|
|
3
12
|
## 3.3.16
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/cjs/actions.js
CHANGED
|
@@ -139,12 +139,15 @@ var resetShouldIgnoreFollowingMutations = exports.resetShouldIgnoreFollowingMuta
|
|
|
139
139
|
* append the codeblock to the end of the document.
|
|
140
140
|
*/
|
|
141
141
|
function createInsertCodeBlockTransaction(_ref) {
|
|
142
|
-
var
|
|
143
|
-
|
|
142
|
+
var state = _ref.state,
|
|
143
|
+
isNestingInQuoteSupported = _ref.isNestingInQuoteSupported;
|
|
144
144
|
var tr = state.tr;
|
|
145
|
-
var
|
|
145
|
+
var _state$selection = state.selection,
|
|
146
|
+
from = _state$selection.from,
|
|
147
|
+
$from = _state$selection.$from;
|
|
146
148
|
var codeBlock = state.schema.nodes.codeBlock;
|
|
147
|
-
var
|
|
149
|
+
var grandParentNode = state.selection.$from.node(-1);
|
|
150
|
+
var grandParentNodeType = grandParentNode === null || grandParentNode === void 0 ? void 0 : grandParentNode.type;
|
|
148
151
|
var parentNodeType = state.selection.$from.parent.type;
|
|
149
152
|
|
|
150
153
|
/** We always want to append a codeBlock unless we're inserting into a paragraph
|
|
@@ -158,13 +161,17 @@ function createInsertCodeBlockTransaction(_ref) {
|
|
|
158
161
|
content: codeBlock.createAndFill()
|
|
159
162
|
}) && (0, _insert.contentAllowedInCodeBlock)(state);
|
|
160
163
|
if (canInsertCodeBlock) {
|
|
161
|
-
tr = (0, _transformToCodeBlock.transformToCodeBlockAction)(state, from);
|
|
164
|
+
tr = (0, _transformToCodeBlock.transformToCodeBlockAction)(state, from, undefined, isNestingInQuoteSupported);
|
|
165
|
+
} else if (!isNestingInQuoteSupported && (grandParentNodeType === null || grandParentNodeType === void 0 ? void 0 : grandParentNodeType.name) === 'blockquote') {
|
|
166
|
+
/** we only allow the insertion of a codeblock inside a blockquote if nesting in quotes is supported */
|
|
167
|
+
var grandparentEndPos = $from.start(-1) + grandParentNode.nodeSize - 1;
|
|
168
|
+
(0, _utils.safeInsert)(codeBlock.createAndFill(), grandparentEndPos)(tr).scrollIntoView();
|
|
162
169
|
} else {
|
|
163
170
|
(0, _utils.safeInsert)(codeBlock.createAndFill())(tr).scrollIntoView();
|
|
164
171
|
}
|
|
165
172
|
return tr;
|
|
166
173
|
}
|
|
167
|
-
function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI) {
|
|
174
|
+
function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI, isNestingInQuoteSupported) {
|
|
168
175
|
return (0, _editorAnalytics.withAnalytics)(analyticsAPI, {
|
|
169
176
|
action: _analytics.ACTION.INSERTED,
|
|
170
177
|
actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
|
|
@@ -175,7 +182,8 @@ function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI) {
|
|
|
175
182
|
eventType: _analytics.EVENT_TYPE.TRACK
|
|
176
183
|
})(function (state, dispatch) {
|
|
177
184
|
var tr = createInsertCodeBlockTransaction({
|
|
178
|
-
state: state
|
|
185
|
+
state: state,
|
|
186
|
+
isNestingInQuoteSupported: isNestingInQuoteSupported
|
|
179
187
|
});
|
|
180
188
|
if (dispatch) {
|
|
181
189
|
dispatch(tr);
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -11,6 +11,7 @@ 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");
|
|
14
15
|
var _actions = require("./actions");
|
|
15
16
|
var _codeBlockAutoFullStopTransformPlugin = require("./pm-plugins/codeBlockAutoFullStopTransformPlugin");
|
|
16
17
|
var _codeBlockCopySelectionPlugin = require("./pm-plugins/codeBlockCopySelectionPlugin");
|
|
@@ -23,8 +24,10 @@ var _toolbar = require("./toolbar");
|
|
|
23
24
|
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; }
|
|
24
25
|
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; }
|
|
25
26
|
var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
27
|
+
var _api$featureFlags;
|
|
26
28
|
var options = _ref.config,
|
|
27
29
|
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');
|
|
28
31
|
return {
|
|
29
32
|
name: 'codeBlock',
|
|
30
33
|
nodes: function nodes() {
|
|
@@ -48,7 +51,7 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
|
48
51
|
plugin: function plugin(_ref3) {
|
|
49
52
|
var _api$analytics;
|
|
50
53
|
var schema = _ref3.schema;
|
|
51
|
-
return (0, _inputRule.createCodeBlockInputRule)(schema, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
|
|
54
|
+
return (0, _inputRule.createCodeBlockInputRule)(schema, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, isNestingInQuoteSupported);
|
|
52
55
|
}
|
|
53
56
|
}, {
|
|
54
57
|
name: 'codeBlockIDEKeyBindings',
|
|
@@ -84,7 +87,7 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
|
84
87
|
*/
|
|
85
88
|
insertCodeBlock: function insertCodeBlock(inputMethod) {
|
|
86
89
|
var _api$analytics2;
|
|
87
|
-
return (0, _actions.insertCodeBlockWithAnalytics)(inputMethod, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
|
|
90
|
+
return (0, _actions.insertCodeBlockWithAnalytics)(inputMethod, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, isNestingInQuoteSupported);
|
|
88
91
|
}
|
|
89
92
|
},
|
|
90
93
|
pluginsOptions: {
|
|
@@ -103,7 +106,8 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
|
103
106
|
action: function action(_insert, state) {
|
|
104
107
|
var _api$analytics3;
|
|
105
108
|
var tr = (0, _actions.createInsertCodeBlockTransaction)({
|
|
106
|
-
state: state
|
|
109
|
+
state: state,
|
|
110
|
+
isNestingInQuoteSupported: isNestingInQuoteSupported
|
|
107
111
|
});
|
|
108
112
|
api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 || _api$analytics3.actions.attachAnalyticsEvent({
|
|
109
113
|
action: _analytics.ACTION.INSERTED,
|
|
@@ -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, isNestingInQuoteSupported) {
|
|
15
|
+
var rules = getCodeBlockRules(editorAnalyticsAPI, schema, isNestingInQuoteSupported);
|
|
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) {
|
|
|
24
24
|
* @param {Schema} schema
|
|
25
25
|
* @returns {InputRuleWithHandler[]}
|
|
26
26
|
*/
|
|
27
|
-
function getCodeBlockRules(editorAnalyticsAPI, schema) {
|
|
27
|
+
function getCodeBlockRules(editorAnalyticsAPI, schema, isNestingInQuoteSupported) {
|
|
28
28
|
var ruleAnalytics = (0, _utils.inputRuleWithAnalytics)({
|
|
29
29
|
action: _analytics.ACTION.INSERTED,
|
|
30
30
|
actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
|
|
@@ -46,7 +46,7 @@ function getCodeBlockRules(editorAnalyticsAPI, schema) {
|
|
|
46
46
|
attributes.language = match[4];
|
|
47
47
|
}
|
|
48
48
|
if ((0, _transformToCodeBlock.isConvertableToCodeBlock)(state)) {
|
|
49
|
-
return (0, _transformToCodeBlock.transformToCodeBlockAction)(state, start, attributes);
|
|
49
|
+
return (0, _transformToCodeBlock.transformToCodeBlockAction)(state, start, attributes, isNestingInQuoteSupported);
|
|
50
50
|
}
|
|
51
51
|
var tr = state.tr;
|
|
52
52
|
tr.delete(start, end);
|
|
@@ -9,7 +9,8 @@ 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
|
-
|
|
12
|
+
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
13
|
+
function transformToCodeBlockAction(state, start, attrs, isNestingInQuoteSupported) {
|
|
13
14
|
var startOfCodeBlockText = state.selection.$from;
|
|
14
15
|
var endPosition = state.selection.empty && !(state.selection instanceof _selection.GapCursorSelection) ? startOfCodeBlockText.end() : state.selection.$to.pos;
|
|
15
16
|
var startLinePosition = startOfCodeBlockText.start();
|
|
@@ -57,6 +58,16 @@ function transformToCodeBlockAction(state, start, attrs) {
|
|
|
57
58
|
var startMapped = startLinePosition === start ? parentStartPosition : start;
|
|
58
59
|
var codeBlock = state.schema.nodes.codeBlock;
|
|
59
60
|
var codeBlockNode = codeBlock.createChecked(attrs, codeBlockSlice.content);
|
|
61
|
+
|
|
62
|
+
/** we only allow the insertion of a codeblock inside a blockquote if nesting in quotes is supported */
|
|
63
|
+
var grandParentNode = state.selection.$from.node(-1);
|
|
64
|
+
var grandParentNodeType = grandParentNode === null || grandParentNode === void 0 ? void 0 : grandParentNode.type.name;
|
|
65
|
+
if (grandParentNodeType === 'blockquote' && !isNestingInQuoteSupported) {
|
|
66
|
+
var grandparentEndPos = startOfCodeBlockText.start(-1) + grandParentNode.nodeSize - 1;
|
|
67
|
+
(0, _utils2.safeInsert)(codeBlock.createChecked(attrs, codeBlockSlice.content), grandparentEndPos)(tr).scrollIntoView();
|
|
68
|
+
tr.delete(startMapped, Math.min(endPosition, tr.doc.content.size));
|
|
69
|
+
return tr;
|
|
70
|
+
}
|
|
60
71
|
tr.replaceWith(startMapped, Math.min(endPosition, tr.doc.content.size), codeBlockNode);
|
|
61
72
|
|
|
62
73
|
// Reposition cursor when inserting into layouts or table headers
|
package/dist/es2019/actions.js
CHANGED
|
@@ -141,19 +141,21 @@ export const resetShouldIgnoreFollowingMutations = (state, dispatch) => {
|
|
|
141
141
|
* append the codeblock to the end of the document.
|
|
142
142
|
*/
|
|
143
143
|
export function createInsertCodeBlockTransaction({
|
|
144
|
-
state
|
|
144
|
+
state,
|
|
145
|
+
isNestingInQuoteSupported
|
|
145
146
|
}) {
|
|
146
|
-
var _state$selection$$fro;
|
|
147
147
|
let {
|
|
148
148
|
tr
|
|
149
149
|
} = state;
|
|
150
150
|
const {
|
|
151
|
-
from
|
|
151
|
+
from,
|
|
152
|
+
$from
|
|
152
153
|
} = state.selection;
|
|
153
154
|
const {
|
|
154
155
|
codeBlock
|
|
155
156
|
} = state.schema.nodes;
|
|
156
|
-
const
|
|
157
|
+
const grandParentNode = state.selection.$from.node(-1);
|
|
158
|
+
const grandParentNodeType = grandParentNode === null || grandParentNode === void 0 ? void 0 : grandParentNode.type;
|
|
157
159
|
const parentNodeType = state.selection.$from.parent.type;
|
|
158
160
|
|
|
159
161
|
/** We always want to append a codeBlock unless we're inserting into a paragraph
|
|
@@ -167,13 +169,17 @@ export function createInsertCodeBlockTransaction({
|
|
|
167
169
|
content: codeBlock.createAndFill()
|
|
168
170
|
}) && contentAllowedInCodeBlock(state);
|
|
169
171
|
if (canInsertCodeBlock) {
|
|
170
|
-
tr = transformToCodeBlockAction(state, from);
|
|
172
|
+
tr = transformToCodeBlockAction(state, from, undefined, isNestingInQuoteSupported);
|
|
173
|
+
} else if (!isNestingInQuoteSupported && (grandParentNodeType === null || grandParentNodeType === void 0 ? void 0 : grandParentNodeType.name) === 'blockquote') {
|
|
174
|
+
/** we only allow the insertion of a codeblock inside a blockquote if nesting in quotes is supported */
|
|
175
|
+
const grandparentEndPos = $from.start(-1) + grandParentNode.nodeSize - 1;
|
|
176
|
+
safeInsert(codeBlock.createAndFill(), grandparentEndPos)(tr).scrollIntoView();
|
|
171
177
|
} else {
|
|
172
178
|
safeInsert(codeBlock.createAndFill())(tr).scrollIntoView();
|
|
173
179
|
}
|
|
174
180
|
return tr;
|
|
175
181
|
}
|
|
176
|
-
export function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI) {
|
|
182
|
+
export function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI, isNestingInQuoteSupported) {
|
|
177
183
|
return withAnalytics(analyticsAPI, {
|
|
178
184
|
action: ACTION.INSERTED,
|
|
179
185
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
@@ -184,7 +190,8 @@ export function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI) {
|
|
|
184
190
|
eventType: EVENT_TYPE.TRACK
|
|
185
191
|
})(function (state, dispatch) {
|
|
186
192
|
let tr = createInsertCodeBlockTransaction({
|
|
187
|
-
state
|
|
193
|
+
state,
|
|
194
|
+
isNestingInQuoteSupported
|
|
188
195
|
});
|
|
189
196
|
if (dispatch) {
|
|
190
197
|
dispatch(tr);
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -3,6 +3,7 @@ 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';
|
|
6
7
|
import { createInsertCodeBlockTransaction, insertCodeBlockWithAnalytics } from './actions';
|
|
7
8
|
import { codeBlockAutoFullStopTransformPlugin } from './pm-plugins/codeBlockAutoFullStopTransformPlugin';
|
|
8
9
|
import { codeBlockCopySelectionPlugin } from './pm-plugins/codeBlockCopySelectionPlugin';
|
|
@@ -15,91 +16,96 @@ import { getToolbarConfig } from './toolbar';
|
|
|
15
16
|
const codeBlockPlugin = ({
|
|
16
17
|
config: options,
|
|
17
18
|
api
|
|
18
|
-
}) =>
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
19
|
+
}) => {
|
|
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
|
+
return {
|
|
23
|
+
name: 'codeBlock',
|
|
24
|
+
nodes() {
|
|
25
|
+
return [{
|
|
26
|
+
name: 'codeBlock',
|
|
27
|
+
node: codeBlock
|
|
28
|
+
}];
|
|
29
|
+
},
|
|
30
|
+
pmPlugins() {
|
|
31
|
+
return [{
|
|
32
|
+
name: 'codeBlock',
|
|
33
|
+
plugin: ({
|
|
34
|
+
getIntl
|
|
35
|
+
}) => createPlugin({
|
|
36
|
+
...options,
|
|
37
|
+
getIntl,
|
|
38
|
+
api
|
|
39
|
+
})
|
|
40
|
+
}, {
|
|
41
|
+
name: 'codeBlockInputRule',
|
|
42
|
+
plugin: ({
|
|
43
|
+
schema
|
|
44
|
+
}) => {
|
|
45
|
+
var _api$analytics;
|
|
46
|
+
return createCodeBlockInputRule(schema, api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, isNestingInQuoteSupported);
|
|
47
|
+
}
|
|
48
|
+
}, {
|
|
49
|
+
name: 'codeBlockIDEKeyBindings',
|
|
50
|
+
plugin: () => ideUX(api)
|
|
51
|
+
}, {
|
|
52
|
+
name: 'codeBlockKeyMap',
|
|
53
|
+
plugin: ({
|
|
54
|
+
schema
|
|
55
|
+
}) => keymap(schema)
|
|
56
|
+
}, {
|
|
57
|
+
name: 'codeBlockCopySelection',
|
|
58
|
+
plugin: () => codeBlockCopySelectionPlugin()
|
|
59
|
+
}, {
|
|
60
|
+
name: 'codeBlockAutoFullStopTransform',
|
|
61
|
+
plugin: () => codeBlockAutoFullStopTransformPlugin()
|
|
62
|
+
}];
|
|
63
|
+
},
|
|
64
|
+
// Workaround for a firefox issue where dom selection is off sync
|
|
65
|
+
// https://product-fabric.atlassian.net/browse/ED-12442
|
|
66
|
+
onEditorViewStateUpdated(props) {
|
|
67
|
+
refreshBrowserSelectionOnChange(props.originalTransaction, props.newEditorState);
|
|
68
|
+
},
|
|
69
|
+
actions: {
|
|
70
|
+
/*
|
|
71
|
+
* Function will insert code block at current selection if block is empty or below current selection and set focus on it.
|
|
72
|
+
*/
|
|
73
|
+
insertCodeBlock: inputMethod => {
|
|
74
|
+
var _api$analytics2;
|
|
75
|
+
return insertCodeBlockWithAnalytics(inputMethod, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, isNestingInQuoteSupported);
|
|
43
76
|
}
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
},
|
|
78
|
+
pluginsOptions: {
|
|
79
|
+
quickInsert: ({
|
|
80
|
+
formatMessage
|
|
81
|
+
}) => [{
|
|
82
|
+
id: 'codeblock',
|
|
83
|
+
title: formatMessage(blockTypeMessages.codeblock),
|
|
84
|
+
description: formatMessage(blockTypeMessages.codeblockDescription),
|
|
85
|
+
keywords: ['code block'],
|
|
86
|
+
priority: 700,
|
|
87
|
+
keyshortcut: '```',
|
|
88
|
+
icon: () => /*#__PURE__*/React.createElement(IconCode, null),
|
|
89
|
+
action(_insert, state) {
|
|
90
|
+
var _api$analytics3;
|
|
91
|
+
const tr = createInsertCodeBlockTransaction({
|
|
92
|
+
state,
|
|
93
|
+
isNestingInQuoteSupported
|
|
94
|
+
});
|
|
95
|
+
api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions.attachAnalyticsEvent({
|
|
96
|
+
action: ACTION.INSERTED,
|
|
97
|
+
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
98
|
+
actionSubjectId: ACTION_SUBJECT_ID.CODE_BLOCK,
|
|
99
|
+
attributes: {
|
|
100
|
+
inputMethod: INPUT_METHOD.QUICK_INSERT
|
|
101
|
+
},
|
|
102
|
+
eventType: EVENT_TYPE.TRACK
|
|
103
|
+
})(tr);
|
|
104
|
+
return tr;
|
|
105
|
+
}
|
|
106
|
+
}],
|
|
107
|
+
floatingToolbar: getToolbarConfig(options === null || options === void 0 ? void 0 : options.allowCopyToClipboard, api)
|
|
72
108
|
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
quickInsert: ({
|
|
76
|
-
formatMessage
|
|
77
|
-
}) => [{
|
|
78
|
-
id: 'codeblock',
|
|
79
|
-
title: formatMessage(blockTypeMessages.codeblock),
|
|
80
|
-
description: formatMessage(blockTypeMessages.codeblockDescription),
|
|
81
|
-
keywords: ['code block'],
|
|
82
|
-
priority: 700,
|
|
83
|
-
keyshortcut: '```',
|
|
84
|
-
icon: () => /*#__PURE__*/React.createElement(IconCode, null),
|
|
85
|
-
action(_insert, state) {
|
|
86
|
-
var _api$analytics3;
|
|
87
|
-
const tr = createInsertCodeBlockTransaction({
|
|
88
|
-
state
|
|
89
|
-
});
|
|
90
|
-
api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions.attachAnalyticsEvent({
|
|
91
|
-
action: ACTION.INSERTED,
|
|
92
|
-
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
93
|
-
actionSubjectId: ACTION_SUBJECT_ID.CODE_BLOCK,
|
|
94
|
-
attributes: {
|
|
95
|
-
inputMethod: INPUT_METHOD.QUICK_INSERT
|
|
96
|
-
},
|
|
97
|
-
eventType: EVENT_TYPE.TRACK
|
|
98
|
-
})(tr);
|
|
99
|
-
return tr;
|
|
100
|
-
}
|
|
101
|
-
}],
|
|
102
|
-
floatingToolbar: getToolbarConfig(options === null || options === void 0 ? void 0 : options.allowCopyToClipboard, api)
|
|
103
|
-
}
|
|
104
|
-
});
|
|
109
|
+
};
|
|
110
|
+
};
|
|
105
111
|
export default codeBlockPlugin;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import { insertBlock } from '@atlaskit/editor-common/commands';
|
|
3
3
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
|
-
import { inputRuleWithAnalytics } from '@atlaskit/editor-common/utils';
|
|
5
|
-
import { createRule } from '@atlaskit/editor-common/utils';
|
|
4
|
+
import { createRule, inputRuleWithAnalytics } from '@atlaskit/editor-common/utils';
|
|
6
5
|
import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
7
6
|
import { createPlugin, leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
|
|
8
7
|
import { isConvertableToCodeBlock, transformToCodeBlockAction } from '../transform-to-code-block';
|
|
9
|
-
export function createCodeBlockInputRule(schema, editorAnalyticsAPI) {
|
|
10
|
-
const rules = getCodeBlockRules(editorAnalyticsAPI, schema);
|
|
8
|
+
export function createCodeBlockInputRule(schema, editorAnalyticsAPI, isNestingInQuoteSupported) {
|
|
9
|
+
const rules = getCodeBlockRules(editorAnalyticsAPI, schema, isNestingInQuoteSupported);
|
|
11
10
|
return new SafePlugin(createPlugin('code-block-input-rule', rules, {
|
|
12
11
|
isBlockNodeRule: true
|
|
13
12
|
}));
|
|
@@ -19,7 +18,7 @@ export function createCodeBlockInputRule(schema, editorAnalyticsAPI) {
|
|
|
19
18
|
* @param {Schema} schema
|
|
20
19
|
* @returns {InputRuleWithHandler[]}
|
|
21
20
|
*/
|
|
22
|
-
function getCodeBlockRules(editorAnalyticsAPI, schema) {
|
|
21
|
+
function getCodeBlockRules(editorAnalyticsAPI, schema, isNestingInQuoteSupported) {
|
|
23
22
|
const ruleAnalytics = inputRuleWithAnalytics({
|
|
24
23
|
action: ACTION.INSERTED,
|
|
25
24
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
@@ -39,7 +38,7 @@ function getCodeBlockRules(editorAnalyticsAPI, schema) {
|
|
|
39
38
|
attributes.language = match[4];
|
|
40
39
|
}
|
|
41
40
|
if (isConvertableToCodeBlock(state)) {
|
|
42
|
-
return transformToCodeBlockAction(state, start, attributes);
|
|
41
|
+
return transformToCodeBlockAction(state, start, attributes, isNestingInQuoteSupported);
|
|
43
42
|
}
|
|
44
43
|
const tr = state.tr;
|
|
45
44
|
tr.delete(start, end);
|
|
@@ -2,7 +2,8 @@ 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
|
-
|
|
5
|
+
import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
6
|
+
export function transformToCodeBlockAction(state, start, attrs, isNestingInQuoteSupported) {
|
|
6
7
|
const startOfCodeBlockText = state.selection.$from;
|
|
7
8
|
const endPosition = state.selection.empty && !(state.selection instanceof GapCursorSelection) ? startOfCodeBlockText.end() : state.selection.$to.pos;
|
|
8
9
|
const startLinePosition = startOfCodeBlockText.start();
|
|
@@ -50,6 +51,16 @@ export function transformToCodeBlockAction(state, start, attrs) {
|
|
|
50
51
|
const startMapped = startLinePosition === start ? parentStartPosition : start;
|
|
51
52
|
const codeBlock = state.schema.nodes.codeBlock;
|
|
52
53
|
const codeBlockNode = codeBlock.createChecked(attrs, codeBlockSlice.content);
|
|
54
|
+
|
|
55
|
+
/** we only allow the insertion of a codeblock inside a blockquote if nesting in quotes is supported */
|
|
56
|
+
const grandParentNode = state.selection.$from.node(-1);
|
|
57
|
+
const grandParentNodeType = grandParentNode === null || grandParentNode === void 0 ? void 0 : grandParentNode.type.name;
|
|
58
|
+
if (grandParentNodeType === 'blockquote' && !isNestingInQuoteSupported) {
|
|
59
|
+
const grandparentEndPos = startOfCodeBlockText.start(-1) + grandParentNode.nodeSize - 1;
|
|
60
|
+
safeInsert(codeBlock.createChecked(attrs, codeBlockSlice.content), grandparentEndPos)(tr).scrollIntoView();
|
|
61
|
+
tr.delete(startMapped, Math.min(endPosition, tr.doc.content.size));
|
|
62
|
+
return tr;
|
|
63
|
+
}
|
|
53
64
|
tr.replaceWith(startMapped, Math.min(endPosition, tr.doc.content.size), codeBlockNode);
|
|
54
65
|
|
|
55
66
|
// Reposition cursor when inserting into layouts or table headers
|
package/dist/esm/actions.js
CHANGED
|
@@ -129,12 +129,15 @@ export var resetShouldIgnoreFollowingMutations = function resetShouldIgnoreFollo
|
|
|
129
129
|
* append the codeblock to the end of the document.
|
|
130
130
|
*/
|
|
131
131
|
export function createInsertCodeBlockTransaction(_ref) {
|
|
132
|
-
var
|
|
133
|
-
|
|
132
|
+
var state = _ref.state,
|
|
133
|
+
isNestingInQuoteSupported = _ref.isNestingInQuoteSupported;
|
|
134
134
|
var tr = state.tr;
|
|
135
|
-
var
|
|
135
|
+
var _state$selection = state.selection,
|
|
136
|
+
from = _state$selection.from,
|
|
137
|
+
$from = _state$selection.$from;
|
|
136
138
|
var codeBlock = state.schema.nodes.codeBlock;
|
|
137
|
-
var
|
|
139
|
+
var grandParentNode = state.selection.$from.node(-1);
|
|
140
|
+
var grandParentNodeType = grandParentNode === null || grandParentNode === void 0 ? void 0 : grandParentNode.type;
|
|
138
141
|
var parentNodeType = state.selection.$from.parent.type;
|
|
139
142
|
|
|
140
143
|
/** We always want to append a codeBlock unless we're inserting into a paragraph
|
|
@@ -148,13 +151,17 @@ export function createInsertCodeBlockTransaction(_ref) {
|
|
|
148
151
|
content: codeBlock.createAndFill()
|
|
149
152
|
}) && contentAllowedInCodeBlock(state);
|
|
150
153
|
if (canInsertCodeBlock) {
|
|
151
|
-
tr = transformToCodeBlockAction(state, from);
|
|
154
|
+
tr = transformToCodeBlockAction(state, from, undefined, isNestingInQuoteSupported);
|
|
155
|
+
} else if (!isNestingInQuoteSupported && (grandParentNodeType === null || grandParentNodeType === void 0 ? void 0 : grandParentNodeType.name) === 'blockquote') {
|
|
156
|
+
/** we only allow the insertion of a codeblock inside a blockquote if nesting in quotes is supported */
|
|
157
|
+
var grandparentEndPos = $from.start(-1) + grandParentNode.nodeSize - 1;
|
|
158
|
+
safeInsert(codeBlock.createAndFill(), grandparentEndPos)(tr).scrollIntoView();
|
|
152
159
|
} else {
|
|
153
160
|
safeInsert(codeBlock.createAndFill())(tr).scrollIntoView();
|
|
154
161
|
}
|
|
155
162
|
return tr;
|
|
156
163
|
}
|
|
157
|
-
export function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI) {
|
|
164
|
+
export function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI, isNestingInQuoteSupported) {
|
|
158
165
|
return withAnalytics(analyticsAPI, {
|
|
159
166
|
action: ACTION.INSERTED,
|
|
160
167
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
@@ -165,7 +172,8 @@ export function insertCodeBlockWithAnalytics(inputMethod, analyticsAPI) {
|
|
|
165
172
|
eventType: EVENT_TYPE.TRACK
|
|
166
173
|
})(function (state, dispatch) {
|
|
167
174
|
var tr = createInsertCodeBlockTransaction({
|
|
168
|
-
state: state
|
|
175
|
+
state: state,
|
|
176
|
+
isNestingInQuoteSupported: isNestingInQuoteSupported
|
|
169
177
|
});
|
|
170
178
|
if (dispatch) {
|
|
171
179
|
dispatch(tr);
|
package/dist/esm/plugin.js
CHANGED
|
@@ -6,6 +6,7 @@ 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';
|
|
9
10
|
import { createInsertCodeBlockTransaction, insertCodeBlockWithAnalytics } from './actions';
|
|
10
11
|
import { codeBlockAutoFullStopTransformPlugin } from './pm-plugins/codeBlockAutoFullStopTransformPlugin';
|
|
11
12
|
import { codeBlockCopySelectionPlugin } from './pm-plugins/codeBlockCopySelectionPlugin';
|
|
@@ -16,8 +17,10 @@ import { createPlugin } from './pm-plugins/main';
|
|
|
16
17
|
import refreshBrowserSelectionOnChange from './refresh-browser-selection';
|
|
17
18
|
import { getToolbarConfig } from './toolbar';
|
|
18
19
|
var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
20
|
+
var _api$featureFlags;
|
|
19
21
|
var options = _ref.config,
|
|
20
22
|
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');
|
|
21
24
|
return {
|
|
22
25
|
name: 'codeBlock',
|
|
23
26
|
nodes: function nodes() {
|
|
@@ -41,7 +44,7 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
|
41
44
|
plugin: function plugin(_ref3) {
|
|
42
45
|
var _api$analytics;
|
|
43
46
|
var schema = _ref3.schema;
|
|
44
|
-
return createCodeBlockInputRule(schema, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
|
|
47
|
+
return createCodeBlockInputRule(schema, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions, isNestingInQuoteSupported);
|
|
45
48
|
}
|
|
46
49
|
}, {
|
|
47
50
|
name: 'codeBlockIDEKeyBindings',
|
|
@@ -77,7 +80,7 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
|
77
80
|
*/
|
|
78
81
|
insertCodeBlock: function insertCodeBlock(inputMethod) {
|
|
79
82
|
var _api$analytics2;
|
|
80
|
-
return insertCodeBlockWithAnalytics(inputMethod, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
|
|
83
|
+
return insertCodeBlockWithAnalytics(inputMethod, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, isNestingInQuoteSupported);
|
|
81
84
|
}
|
|
82
85
|
},
|
|
83
86
|
pluginsOptions: {
|
|
@@ -96,7 +99,8 @@ var codeBlockPlugin = function codeBlockPlugin(_ref) {
|
|
|
96
99
|
action: function action(_insert, state) {
|
|
97
100
|
var _api$analytics3;
|
|
98
101
|
var tr = createInsertCodeBlockTransaction({
|
|
99
|
-
state: state
|
|
102
|
+
state: state,
|
|
103
|
+
isNestingInQuoteSupported: isNestingInQuoteSupported
|
|
100
104
|
});
|
|
101
105
|
api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 || _api$analytics3.actions.attachAnalyticsEvent({
|
|
102
106
|
action: ACTION.INSERTED,
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import { insertBlock } from '@atlaskit/editor-common/commands';
|
|
3
3
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
|
-
import { inputRuleWithAnalytics } from '@atlaskit/editor-common/utils';
|
|
5
|
-
import { createRule } from '@atlaskit/editor-common/utils';
|
|
4
|
+
import { createRule, inputRuleWithAnalytics } from '@atlaskit/editor-common/utils';
|
|
6
5
|
import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
7
6
|
import { createPlugin, leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
|
|
8
7
|
import { isConvertableToCodeBlock, transformToCodeBlockAction } from '../transform-to-code-block';
|
|
9
|
-
export function createCodeBlockInputRule(schema, editorAnalyticsAPI) {
|
|
10
|
-
var rules = getCodeBlockRules(editorAnalyticsAPI, schema);
|
|
8
|
+
export function createCodeBlockInputRule(schema, editorAnalyticsAPI, isNestingInQuoteSupported) {
|
|
9
|
+
var rules = getCodeBlockRules(editorAnalyticsAPI, schema, isNestingInQuoteSupported);
|
|
11
10
|
return new SafePlugin(createPlugin('code-block-input-rule', rules, {
|
|
12
11
|
isBlockNodeRule: true
|
|
13
12
|
}));
|
|
@@ -19,7 +18,7 @@ export function createCodeBlockInputRule(schema, editorAnalyticsAPI) {
|
|
|
19
18
|
* @param {Schema} schema
|
|
20
19
|
* @returns {InputRuleWithHandler[]}
|
|
21
20
|
*/
|
|
22
|
-
function getCodeBlockRules(editorAnalyticsAPI, schema) {
|
|
21
|
+
function getCodeBlockRules(editorAnalyticsAPI, schema, isNestingInQuoteSupported) {
|
|
23
22
|
var ruleAnalytics = inputRuleWithAnalytics({
|
|
24
23
|
action: ACTION.INSERTED,
|
|
25
24
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
@@ -41,7 +40,7 @@ function getCodeBlockRules(editorAnalyticsAPI, schema) {
|
|
|
41
40
|
attributes.language = match[4];
|
|
42
41
|
}
|
|
43
42
|
if (isConvertableToCodeBlock(state)) {
|
|
44
|
-
return transformToCodeBlockAction(state, start, attributes);
|
|
43
|
+
return transformToCodeBlockAction(state, start, attributes, isNestingInQuoteSupported);
|
|
45
44
|
}
|
|
46
45
|
var tr = state.tr;
|
|
47
46
|
tr.delete(start, end);
|
|
@@ -2,7 +2,8 @@ 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
|
-
|
|
5
|
+
import { safeInsert } from '@atlaskit/editor-prosemirror/utils';
|
|
6
|
+
export function transformToCodeBlockAction(state, start, attrs, isNestingInQuoteSupported) {
|
|
6
7
|
var startOfCodeBlockText = state.selection.$from;
|
|
7
8
|
var endPosition = state.selection.empty && !(state.selection instanceof GapCursorSelection) ? startOfCodeBlockText.end() : state.selection.$to.pos;
|
|
8
9
|
var startLinePosition = startOfCodeBlockText.start();
|
|
@@ -50,6 +51,16 @@ export function transformToCodeBlockAction(state, start, attrs) {
|
|
|
50
51
|
var startMapped = startLinePosition === start ? parentStartPosition : start;
|
|
51
52
|
var codeBlock = state.schema.nodes.codeBlock;
|
|
52
53
|
var codeBlockNode = codeBlock.createChecked(attrs, codeBlockSlice.content);
|
|
54
|
+
|
|
55
|
+
/** we only allow the insertion of a codeblock inside a blockquote if nesting in quotes is supported */
|
|
56
|
+
var grandParentNode = state.selection.$from.node(-1);
|
|
57
|
+
var grandParentNodeType = grandParentNode === null || grandParentNode === void 0 ? void 0 : grandParentNode.type.name;
|
|
58
|
+
if (grandParentNodeType === 'blockquote' && !isNestingInQuoteSupported) {
|
|
59
|
+
var grandparentEndPos = startOfCodeBlockText.start(-1) + grandParentNode.nodeSize - 1;
|
|
60
|
+
safeInsert(codeBlock.createChecked(attrs, codeBlockSlice.content), grandparentEndPos)(tr).scrollIntoView();
|
|
61
|
+
tr.delete(startMapped, Math.min(endPosition, tr.doc.content.size));
|
|
62
|
+
return tr;
|
|
63
|
+
}
|
|
53
64
|
tr.replaceWith(startMapped, Math.min(endPosition, tr.doc.content.size), codeBlockNode);
|
|
54
65
|
|
|
55
66
|
// Reposition cursor when inserting into layouts or table headers
|
package/dist/types/actions.d.ts
CHANGED
|
@@ -12,10 +12,11 @@ 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, isNestingInQuoteSupported, }: {
|
|
16
16
|
state: EditorState;
|
|
17
|
+
isNestingInQuoteSupported?: boolean;
|
|
17
18
|
}): import("prosemirror-state").Transaction;
|
|
18
|
-
export declare function insertCodeBlockWithAnalytics(inputMethod: INPUT_METHOD, analyticsAPI?: EditorAnalyticsAPI): Command;
|
|
19
|
+
export declare function insertCodeBlockWithAnalytics(inputMethod: INPUT_METHOD, analyticsAPI?: EditorAnalyticsAPI, isNestingInQuoteSupported?: boolean): Command;
|
|
19
20
|
/**
|
|
20
21
|
* Add the given node to the codeBlockWrappedStates WeakMap with the toggle boolean value.
|
|
21
22
|
*/
|
package/dist/types/plugin.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
|
4
4
|
import type { CompositionPlugin } from '@atlaskit/editor-plugin-composition';
|
|
5
5
|
import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
|
|
6
6
|
import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled';
|
|
7
|
+
import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
|
|
7
8
|
import type { CodeBlockOptions } from './types';
|
|
8
9
|
export type CodeBlockPlugin = NextEditorPlugin<'codeBlock', {
|
|
9
10
|
pluginConfiguration: CodeBlockOptions | undefined;
|
|
@@ -11,7 +12,8 @@ export type CodeBlockPlugin = NextEditorPlugin<'codeBlock', {
|
|
|
11
12
|
DecorationsPlugin,
|
|
12
13
|
CompositionPlugin,
|
|
13
14
|
OptionalPlugin<AnalyticsPlugin>,
|
|
14
|
-
OptionalPlugin<EditorDisabledPlugin
|
|
15
|
+
OptionalPlugin<EditorDisabledPlugin>,
|
|
16
|
+
OptionalPlugin<FeatureFlagsPlugin>
|
|
15
17
|
];
|
|
16
18
|
actions: {
|
|
17
19
|
insertCodeBlock: (inputMethod: INPUT_METHOD) => Command;
|
|
@@ -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): SafePlugin<any>;
|
|
4
|
+
export declare function createCodeBlockInputRule(schema: Schema, editorAnalyticsAPI?: EditorAnalyticsAPI, isNestingInQuoteSupported?: boolean): SafePlugin<any>;
|
|
@@ -32,7 +32,10 @@ export declare const createPlugin: ({ useLongPressSelection, getIntl, allowCompo
|
|
|
32
32
|
actions: import("@atlaskit/editor-common/analytics").EditorAnalyticsAPI;
|
|
33
33
|
}, import("@atlaskit/editor-plugin-analytics").AnalyticsPluginOptions>>, import("@atlaskit/editor-common/types").OptionalPlugin<import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"editorDisabled", {
|
|
34
34
|
sharedState: import("@atlaskit/editor-plugin-editor-disabled").EditorDisabledPluginState;
|
|
35
|
-
}, undefined
|
|
35
|
+
}, undefined>>, import("@atlaskit/editor-common/types").OptionalPlugin<import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"featureFlags", {
|
|
36
|
+
pluginConfiguration: import("@atlaskit/editor-common/types").FeatureFlags;
|
|
37
|
+
sharedState: import("@atlaskit/editor-common/types").FeatureFlags;
|
|
38
|
+
}, import("@atlaskit/editor-common/types").FeatureFlags>>];
|
|
36
39
|
actions: {
|
|
37
40
|
insertCodeBlock: (inputMethod: import("@atlaskit/editor-common/analytics").INPUT_METHOD) => import("@atlaskit/editor-common/types").Command;
|
|
38
41
|
};
|
|
@@ -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): Transaction;
|
|
2
|
+
export declare function transformToCodeBlockAction(state: EditorState, start: number, attrs?: any, isNestingInQuoteSupported?: boolean): Transaction;
|
|
3
3
|
export declare function isConvertableToCodeBlock(state: EditorState): boolean;
|
|
@@ -12,10 +12,11 @@ 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, isNestingInQuoteSupported, }: {
|
|
16
16
|
state: EditorState;
|
|
17
|
+
isNestingInQuoteSupported?: boolean;
|
|
17
18
|
}): import("prosemirror-state").Transaction;
|
|
18
|
-
export declare function insertCodeBlockWithAnalytics(inputMethod: INPUT_METHOD, analyticsAPI?: EditorAnalyticsAPI): Command;
|
|
19
|
+
export declare function insertCodeBlockWithAnalytics(inputMethod: INPUT_METHOD, analyticsAPI?: EditorAnalyticsAPI, isNestingInQuoteSupported?: boolean): Command;
|
|
19
20
|
/**
|
|
20
21
|
* Add the given node to the codeBlockWrappedStates WeakMap with the toggle boolean value.
|
|
21
22
|
*/
|
|
@@ -4,6 +4,7 @@ import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
|
4
4
|
import type { CompositionPlugin } from '@atlaskit/editor-plugin-composition';
|
|
5
5
|
import type { DecorationsPlugin } from '@atlaskit/editor-plugin-decorations';
|
|
6
6
|
import type { EditorDisabledPlugin } from '@atlaskit/editor-plugin-editor-disabled';
|
|
7
|
+
import type { FeatureFlagsPlugin } from '@atlaskit/editor-plugin-feature-flags';
|
|
7
8
|
import type { CodeBlockOptions } from './types';
|
|
8
9
|
export type CodeBlockPlugin = NextEditorPlugin<'codeBlock', {
|
|
9
10
|
pluginConfiguration: CodeBlockOptions | undefined;
|
|
@@ -11,7 +12,8 @@ export type CodeBlockPlugin = NextEditorPlugin<'codeBlock', {
|
|
|
11
12
|
DecorationsPlugin,
|
|
12
13
|
CompositionPlugin,
|
|
13
14
|
OptionalPlugin<AnalyticsPlugin>,
|
|
14
|
-
OptionalPlugin<EditorDisabledPlugin
|
|
15
|
+
OptionalPlugin<EditorDisabledPlugin>,
|
|
16
|
+
OptionalPlugin<FeatureFlagsPlugin>
|
|
15
17
|
];
|
|
16
18
|
actions: {
|
|
17
19
|
insertCodeBlock: (inputMethod: INPUT_METHOD) => Command;
|
|
@@ -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): SafePlugin<any>;
|
|
4
|
+
export declare function createCodeBlockInputRule(schema: Schema, editorAnalyticsAPI?: EditorAnalyticsAPI, isNestingInQuoteSupported?: boolean): SafePlugin<any>;
|
|
@@ -38,7 +38,11 @@ export declare const createPlugin: ({ useLongPressSelection, getIntl, allowCompo
|
|
|
38
38
|
}, import("@atlaskit/editor-plugin-analytics").AnalyticsPluginOptions>>,
|
|
39
39
|
import("@atlaskit/editor-common/types").OptionalPlugin<import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"editorDisabled", {
|
|
40
40
|
sharedState: import("@atlaskit/editor-plugin-editor-disabled").EditorDisabledPluginState;
|
|
41
|
-
}, undefined
|
|
41
|
+
}, undefined>>,
|
|
42
|
+
import("@atlaskit/editor-common/types").OptionalPlugin<import("@atlaskit/editor-common/types").NextEditorPluginFunctionOptionalConfigDefinition<"featureFlags", {
|
|
43
|
+
pluginConfiguration: import("@atlaskit/editor-common/types").FeatureFlags;
|
|
44
|
+
sharedState: import("@atlaskit/editor-common/types").FeatureFlags;
|
|
45
|
+
}, import("@atlaskit/editor-common/types").FeatureFlags>>
|
|
42
46
|
];
|
|
43
47
|
actions: {
|
|
44
48
|
insertCodeBlock: (inputMethod: import("@atlaskit/editor-common/analytics").INPUT_METHOD) => import("@atlaskit/editor-common/types").Command;
|
|
@@ -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): Transaction;
|
|
2
|
+
export declare function transformToCodeBlockAction(state: EditorState, start: number, attrs?: any, isNestingInQuoteSupported?: boolean): Transaction;
|
|
3
3
|
export declare function isConvertableToCodeBlock(state: EditorState): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-code-block",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.17",
|
|
4
4
|
"description": "Code block plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@atlaskit/adf-schema": "^40.9.0",
|
|
35
35
|
"@atlaskit/code": "^15.6.0",
|
|
36
|
-
"@atlaskit/editor-common": "^89.
|
|
36
|
+
"@atlaskit/editor-common": "^89.2.0",
|
|
37
37
|
"@atlaskit/editor-plugin-analytics": "^1.8.0",
|
|
38
38
|
"@atlaskit/editor-plugin-composition": "^1.2.0",
|
|
39
39
|
"@atlaskit/editor-plugin-decorations": "^1.3.0",
|
|
40
40
|
"@atlaskit/editor-plugin-editor-disabled": "^1.3.0",
|
|
41
41
|
"@atlaskit/editor-prosemirror": "6.0.0",
|
|
42
|
-
"@atlaskit/icon": "^22.
|
|
42
|
+
"@atlaskit/icon": "^22.18.0",
|
|
43
43
|
"@atlaskit/platform-feature-flags": "^0.3.0",
|
|
44
44
|
"@atlaskit/prosemirror-input-rules": "^3.2.0",
|
|
45
45
|
"@babel/runtime": "^7.0.0",
|
|
@@ -102,6 +102,9 @@
|
|
|
102
102
|
},
|
|
103
103
|
"platform.editor.live-view.disable-editing-in-view-mode_fi1rx": {
|
|
104
104
|
"type": "boolean"
|
|
105
|
+
},
|
|
106
|
+
"editor_nest_media_and_codeblock_in_quotes_jira": {
|
|
107
|
+
"type": "boolean"
|
|
105
108
|
}
|
|
106
109
|
}
|
|
107
110
|
}
|