@atlaskit/editor-plugin-code-block 14.1.20 → 14.1.21

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # @atlaskit/editor-plugin-code-block
2
2
 
3
+ ## 14.1.21
4
+
5
+ ### Patch Changes
6
+
7
+ - [`eea5a45d85ede`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/eea5a45d85ede) -
8
+ Clean up feature gate `platform_editor_code_block_dogfooding_patch`
9
+
3
10
  ## 14.1.20
4
11
 
5
12
  ### Patch Changes
@@ -483,10 +483,7 @@ var toggleWordWrapStateForCodeBlockNode = exports.toggleWordWrapStateForCodeBloc
483
483
  if ((0, _expValEquals.expValEquals)('platform_editor_code_block_q4_lovability', 'isEnabled', true)) {
484
484
  tr.setNodeMarkup(codeBlock.pos, undefined, _objectSpread(_objectSpread({}, codeBlockNode.attrs), {}, {
485
485
  wrap: updatedToggleState
486
- }));
487
- if ((0, _platformFeatureFlags.fg)('platform_editor_code_block_dogfooding_patch')) {
488
- tr.setMeta('scrollIntoView', false);
489
- }
486
+ })).setMeta('scrollIntoView', false);
490
487
  } else {
491
488
  _codeBlock.codeBlockWrappedStates.set(codeBlockNode, updatedToggleState);
492
489
  }
@@ -168,7 +168,7 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig() {
168
168
  filterOption: languageListFilter,
169
169
  formatMessage: formatMessage,
170
170
  languagePickerOptions: languagePickerOptions,
171
- triggerSpacing: !areAnyNewToolbarFlagsEnabled && (0, _platformFeatureFlags.fg)('platform_editor_code_block_dogfooding_patch') ? 'compact' : 'default'
171
+ triggerSpacing: !areAnyNewToolbarFlagsEnabled ? 'compact' : 'default'
172
172
  });
173
173
  }
174
174
  };
@@ -37,25 +37,23 @@ var CodeBlockLanguagePicker = exports.CodeBlockLanguagePicker = function CodeBlo
37
37
  var isDetectLanguageSelected = option.value === _languagePickerOptions.DETECT_LANGUAGE_VALUE;
38
38
  var command = isDetectLanguageSelected && ((0, _platformFeatureFlags.fg)('platform_editor_code_block_ga_patch_1') || (0, _platformFeatureFlags.fg)('platform_editor_code_block_language_detection_flow')) ? (0, _editorCommands.detectLanguage)() : (0, _editorCommands.changeLanguage)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(option.value, selectionSource);
39
39
  var commandSucceeded = command(editorView.state, editorView.dispatch);
40
- if ((0, _platformFeatureFlags.fg)('platform_editor_code_block_dogfooding_patch')) {
41
- if ((0, _platformFeatureFlags.fg)('platform_editor_code_block_ga_patch_1')) {
42
- if (interactionMethod === 'mouse') {
43
- requestAnimationFrame(function () {
44
- // Mouse-opened picker should return editing focus to the code block. Keyboard-opened
45
- // picker keeps focus on the trigger to avoid CodeMirror DOM focus without cm.hasFocus.
46
- api === null || api === void 0 || api.core.actions.focus({
47
- scrollIntoView: false
48
- });
49
- });
50
- }
51
- } else {
40
+ if ((0, _platformFeatureFlags.fg)('platform_editor_code_block_ga_patch_1')) {
41
+ if (interactionMethod === 'mouse') {
52
42
  requestAnimationFrame(function () {
53
- // Let PopupSelect/FocusLock finish returning focus to the trigger, then restore the editor.
43
+ // Mouse-opened picker should return editing focus to the code block. Keyboard-opened
44
+ // picker keeps focus on the trigger to avoid CodeMirror DOM focus without cm.hasFocus.
54
45
  api === null || api === void 0 || api.core.actions.focus({
55
46
  scrollIntoView: false
56
47
  });
57
48
  });
58
49
  }
50
+ } else {
51
+ requestAnimationFrame(function () {
52
+ // Let PopupSelect/FocusLock finish returning focus to the trigger, then restore the editor.
53
+ api === null || api === void 0 || api.core.actions.focus({
54
+ scrollIntoView: false
55
+ });
56
+ });
59
57
  }
60
58
  if (commandSucceeded && (option.value !== _languagePickerOptions.DETECT_LANGUAGE_VALUE || (0, _platformFeatureFlags.fg)('platform_editor_code_block_ga_patch_1'))) {
61
59
  (0, _recentLanguages.saveRecentLanguage)(option.value);
@@ -52,17 +52,6 @@ var popupSelectComponents = {
52
52
  Group: CustomGroup,
53
53
  Option: CustomOption
54
54
  };
55
- var menuPopperProps = {
56
- modifiers: [{
57
- name: 'offset',
58
- options: {
59
- offset: [0, 8]
60
- }
61
- }, {
62
- name: 'preventOverflow',
63
- enabled: false
64
- }]
65
- };
66
55
  var focusWithoutScrolling = function focusWithoutScrolling(element) {
67
56
  element.focus({
68
57
  preventScroll: true
@@ -176,30 +165,24 @@ var LanguagePicker = exports.LanguagePicker = function LanguagePicker(_ref) {
176
165
  var isInputChange = !actionMeta || actionMeta.action === 'input-change';
177
166
  if (isInputChange) {
178
167
  inputValueRef.current = newInputValue;
179
- }
180
- if (isInputChange || !(0, _platformFeatureFlags.fg)('platform_editor_code_block_dogfooding_patch')) {
181
168
  setHasSearchQuery(newInputValue.trim().length > 0);
182
169
  return newInputValue;
183
170
  }
184
171
  return inputValueRef.current;
185
172
  }, []);
186
173
  var handleMenuOpen = (0, _react.useCallback)(function () {
187
- if ((0, _platformFeatureFlags.fg)('platform_editor_code_block_dogfooding_patch')) {
188
- inputValueRef.current = '';
189
- setHasSearchQuery(false);
190
- setLockedPopperPlacement(undefined);
191
- }
174
+ inputValueRef.current = '';
175
+ setHasSearchQuery(false);
176
+ setLockedPopperPlacement(undefined);
192
177
  onMenuOpen === null || onMenuOpen === void 0 || onMenuOpen();
193
178
  }, [onMenuOpen]);
194
179
  var handleTriggerMouseDown = (0, _react.useCallback)(function (event) {
195
- if ((0, _platformFeatureFlags.fg)('platform_editor_code_block_dogfooding_patch')) {
196
- // PopupSelect's FocusLock returns focus to the element that was focused before the
197
- // picker opened. If that is the editor/code block, closing the picker can scroll the
198
- // whole code block into view. Focus the trigger first without scrolling so FocusLock
199
- // returns to the trigger; see CodeBlockLanguagePicker's handleSelection for restoring
200
- // editor focus.
201
- focusWithoutScrolling(event.currentTarget);
202
- }
180
+ // PopupSelect's FocusLock returns focus to the element that was focused before the
181
+ // picker opened. If that is the editor/code block, closing the picker can scroll the
182
+ // whole code block into view. Focus the trigger first without scrolling so FocusLock
183
+ // returns to the trigger; see CodeBlockLanguagePicker's handleSelection for restoring
184
+ // editor focus.
185
+ focusWithoutScrolling(event.currentTarget);
203
186
  }, []);
204
187
  var handleTriggerMouseUp = (0, _react.useCallback)(function (event) {
205
188
  if ((0, _platformFeatureFlags.fg)('platform_editor_code_block_ga_patch_1')) {
@@ -250,7 +233,7 @@ var LanguagePicker = exports.LanguagePicker = function LanguagePicker(_ref) {
250
233
  onInputChange: handleInputChange,
251
234
  onMenuOpen: handleMenuOpen,
252
235
  options: hasSearchQuery ? searchOptions : options,
253
- popperProps: (0, _platformFeatureFlags.fg)('platform_editor_code_block_dogfooding_patch') ? stableMenuPopperProps : menuPopperProps,
236
+ popperProps: stableMenuPopperProps,
254
237
  searchThreshold: -1,
255
238
  target: renderTarget,
256
239
  testId: "code-block-language-picker",
@@ -8,7 +8,6 @@ exports.syncPendingDetectionTimers = void 0;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
10
  var _analytics = require("@atlaskit/editor-common/analytics");
11
- var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
12
11
  var _actions = require("../pm-plugins/actions");
13
12
  var _autoDetectState = require("../pm-plugins/auto-detect-state");
14
13
  var _autoDetectState2 = require("./auto-detect-state");
@@ -51,41 +50,34 @@ var runPendingDetection = function runPendingDetection(view, localId, api) {
51
50
  detectionResult: detectionResult,
52
51
  autoDetectedLanguage: detectedLanguage !== null && detectedLanguage !== void 0 ? detectedLanguage : entry.autoDetectedLanguage
53
52
  });
54
-
55
- // If there is no confident detection, record the result without clearing user-visible language.
56
- var shouldOnlyUpdateDetectionState = !detectedLanguage && (!found.node.attrs.language || shouldPreserveAutoDetectedLanguage);
57
53
  var hasDetectedLanguageChange = Boolean(detectedLanguage) && found.node.attrs.language !== detectedLanguage;
58
54
  var shouldClearStaleLanguage = !detectedLanguage && Boolean(found.node.attrs.language) && !shouldPreserveAutoDetectedLanguage;
59
- var shouldUpdateNodeLanguage = (0, _platformFeatureFlags.fg)('platform_editor_code_block_dogfooding_patch') ? hasDetectedLanguageChange || shouldClearStaleLanguage : !shouldOnlyUpdateDetectionState;
55
+ var shouldUpdateNodeLanguage = hasDetectedLanguageChange || shouldClearStaleLanguage;
60
56
  api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref) {
61
57
  var tr = _ref.tr;
62
58
  if (shouldUpdateNodeLanguage) {
59
+ var _api$analytics;
63
60
  tr.setNodeMarkup(found.pos, undefined, _objectSpread(_objectSpread({}, found.node.attrs), {}, {
64
61
  language: detectedLanguage
65
62
  }), found.node.marks);
66
- }
67
- tr.setMeta(_autoDetectState.autoDetectPluginKey, {
68
- type: _actions.ACTIONS.SET_AUTO_DETECT_ENTRY,
69
- data: {
70
- localId: localId,
71
- entry: nextEntry
72
- }
73
- });
74
- // When platform_editor_code_block_dogfooding_patch is cleaned up, merge this with the previous shouldUpdateNodeLanguage check.
75
- if (!(0, _platformFeatureFlags.fg)('platform_editor_code_block_dogfooding_patch') || shouldUpdateNodeLanguage) {
76
- var _api$analytics;
77
63
  api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
78
64
  action: _analytics.ACTION.LANGUAGE_AUTO_DETECTED,
79
65
  actionSubject: _analytics.ACTION_SUBJECT.CODE_BLOCK,
80
- attributes: _objectSpread({
66
+ attributes: {
81
67
  language: detectedLanguage !== null && detectedLanguage !== void 0 ? detectedLanguage : 'none',
82
- detectionResult: detectionResult
83
- }, (0, _platformFeatureFlags.fg)('platform_editor_code_block_dogfooding_patch') ? {
68
+ detectionResult: detectionResult,
84
69
  detectionPhase: detectionPhase
85
- } : {}),
70
+ },
86
71
  eventType: _analytics.EVENT_TYPE.TRACK
87
72
  })(tr);
88
73
  }
74
+ tr.setMeta(_autoDetectState.autoDetectPluginKey, {
75
+ type: _actions.ACTIONS.SET_AUTO_DETECT_ENTRY,
76
+ data: {
77
+ localId: localId,
78
+ entry: nextEntry
79
+ }
80
+ });
89
81
  // Language detection runs in the background and should not move the viewport.
90
82
  return tr.setMeta('scrollIntoView', false);
91
83
  });
@@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.detectLanguage = void 0;
8
8
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
- var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
10
  /* eslint-disable require-unicode-regexp */
12
11
 
13
12
  // Conservative weighted-regex heuristic for common high-confidence snippets, not a full classifier.
@@ -102,9 +101,6 @@ var scorePatterns = function scorePatterns(code, patterns) {
102
101
  return score + (hasPattern(code, pattern) ? value : 0);
103
102
  }, 0);
104
103
  };
105
- var scoreEnhancedTypeScriptPatterns = function scoreEnhancedTypeScriptPatterns(code) {
106
- return (0, _platformFeatureFlags.fg)('platform_editor_code_block_dogfooding_patch') ? scorePatterns(code, [[TS_ACCESS_MODIFIER_REGEX, 5], [TS_TYPED_ARROW_PARAM_REGEX, 5]]) : 0;
107
- };
108
104
  var looksLikeHtmlTagPair = function looksLikeHtmlTagPair(code) {
109
105
  var openTags = new Set();
110
106
  // Ignored via go/ees019
@@ -156,7 +152,7 @@ var getLanguageScores = function getLanguageScores(code) {
156
152
  score: scorePatterns(code, [[SQL_SELECT_FROM_REGEX, 5], [SQL_DML_REGEX, 5], [SQL_CLAUSE_REGEX, 2]])
157
153
  }, {
158
154
  language: 'typescript',
159
- score: scorePatterns(code, [[TS_INTERFACE_TYPE_REGEX, 5], [TS_IMPORT_EXPORT_TYPE_REGEX, 4], [TS_TYPED_VAR_REGEX, 4], [TS_RETURN_TYPE_REGEX, 3], [TS_ADVANCED_REGEX, 3]]) + scoreEnhancedTypeScriptPatterns(code)
155
+ score: scorePatterns(code, [[TS_INTERFACE_TYPE_REGEX, 5], [TS_IMPORT_EXPORT_TYPE_REGEX, 4], [TS_TYPED_VAR_REGEX, 4], [TS_RETURN_TYPE_REGEX, 3], [TS_ADVANCED_REGEX, 3], [TS_ACCESS_MODIFIER_REGEX, 5], [TS_TYPED_ARROW_PARAM_REGEX, 5]])
160
156
  }, {
161
157
  language: 'javascript',
162
158
  score: scorePatterns(code, [[JS_VAR_REGEX, 3], [JS_FUNCTION_REGEX, 3], [JS_ARROW_REGEX, 3], [JS_IMPORT_EXPORT_REGEX, 3], [JS_COMMON_API_REGEX, 3]])
@@ -494,10 +494,7 @@ export const toggleWordWrapStateForCodeBlockNode = editorAnalyticsAPI => (state,
494
494
  tr.setNodeMarkup(codeBlock.pos, undefined, {
495
495
  ...codeBlockNode.attrs,
496
496
  wrap: updatedToggleState
497
- });
498
- if (fg('platform_editor_code_block_dogfooding_patch')) {
499
- tr.setMeta('scrollIntoView', false);
500
- }
497
+ }).setMeta('scrollIntoView', false);
501
498
  } else {
502
499
  codeBlockWrappedStates.set(codeBlockNode, updatedToggleState);
503
500
  }
@@ -138,7 +138,7 @@ export const getToolbarConfig = (allowCopyToClipboard = false, api, overrideLang
138
138
  filterOption: languageListFilter,
139
139
  formatMessage: formatMessage,
140
140
  languagePickerOptions: languagePickerOptions,
141
- triggerSpacing: !areAnyNewToolbarFlagsEnabled && fg('platform_editor_code_block_dogfooding_patch') ? 'compact' : 'default'
141
+ triggerSpacing: !areAnyNewToolbarFlagsEnabled ? 'compact' : 'default'
142
142
  });
143
143
  }
144
144
  };
@@ -23,25 +23,23 @@ export const CodeBlockLanguagePicker = ({
23
23
  const isDetectLanguageSelected = option.value === DETECT_LANGUAGE_VALUE;
24
24
  const command = isDetectLanguageSelected && (fg('platform_editor_code_block_ga_patch_1') || fg('platform_editor_code_block_language_detection_flow')) ? detectLanguage() : changeLanguage(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(option.value, selectionSource);
25
25
  const commandSucceeded = command(editorView.state, editorView.dispatch);
26
- if (fg('platform_editor_code_block_dogfooding_patch')) {
27
- if (fg('platform_editor_code_block_ga_patch_1')) {
28
- if (interactionMethod === 'mouse') {
29
- requestAnimationFrame(() => {
30
- // Mouse-opened picker should return editing focus to the code block. Keyboard-opened
31
- // picker keeps focus on the trigger to avoid CodeMirror DOM focus without cm.hasFocus.
32
- api === null || api === void 0 ? void 0 : api.core.actions.focus({
33
- scrollIntoView: false
34
- });
35
- });
36
- }
37
- } else {
26
+ if (fg('platform_editor_code_block_ga_patch_1')) {
27
+ if (interactionMethod === 'mouse') {
38
28
  requestAnimationFrame(() => {
39
- // Let PopupSelect/FocusLock finish returning focus to the trigger, then restore the editor.
29
+ // Mouse-opened picker should return editing focus to the code block. Keyboard-opened
30
+ // picker keeps focus on the trigger to avoid CodeMirror DOM focus without cm.hasFocus.
40
31
  api === null || api === void 0 ? void 0 : api.core.actions.focus({
41
32
  scrollIntoView: false
42
33
  });
43
34
  });
44
35
  }
36
+ } else {
37
+ requestAnimationFrame(() => {
38
+ // Let PopupSelect/FocusLock finish returning focus to the trigger, then restore the editor.
39
+ api === null || api === void 0 ? void 0 : api.core.actions.focus({
40
+ scrollIntoView: false
41
+ });
42
+ });
45
43
  }
46
44
  if (commandSucceeded && (option.value !== DETECT_LANGUAGE_VALUE || fg('platform_editor_code_block_ga_patch_1'))) {
47
45
  saveRecentLanguage(option.value);
@@ -38,17 +38,6 @@ const popupSelectComponents = {
38
38
  Group: CustomGroup,
39
39
  Option: CustomOption
40
40
  };
41
- const menuPopperProps = {
42
- modifiers: [{
43
- name: 'offset',
44
- options: {
45
- offset: [0, 8]
46
- }
47
- }, {
48
- name: 'preventOverflow',
49
- enabled: false
50
- }]
51
- };
52
41
  const focusWithoutScrolling = element => {
53
42
  element.focus({
54
43
  preventScroll: true
@@ -133,30 +122,24 @@ export const LanguagePicker = ({
133
122
  const isInputChange = !actionMeta || actionMeta.action === 'input-change';
134
123
  if (isInputChange) {
135
124
  inputValueRef.current = newInputValue;
136
- }
137
- if (isInputChange || !fg('platform_editor_code_block_dogfooding_patch')) {
138
125
  setHasSearchQuery(newInputValue.trim().length > 0);
139
126
  return newInputValue;
140
127
  }
141
128
  return inputValueRef.current;
142
129
  }, []);
143
130
  const handleMenuOpen = useCallback(() => {
144
- if (fg('platform_editor_code_block_dogfooding_patch')) {
145
- inputValueRef.current = '';
146
- setHasSearchQuery(false);
147
- setLockedPopperPlacement(undefined);
148
- }
131
+ inputValueRef.current = '';
132
+ setHasSearchQuery(false);
133
+ setLockedPopperPlacement(undefined);
149
134
  onMenuOpen === null || onMenuOpen === void 0 ? void 0 : onMenuOpen();
150
135
  }, [onMenuOpen]);
151
136
  const handleTriggerMouseDown = useCallback(event => {
152
- if (fg('platform_editor_code_block_dogfooding_patch')) {
153
- // PopupSelect's FocusLock returns focus to the element that was focused before the
154
- // picker opened. If that is the editor/code block, closing the picker can scroll the
155
- // whole code block into view. Focus the trigger first without scrolling so FocusLock
156
- // returns to the trigger; see CodeBlockLanguagePicker's handleSelection for restoring
157
- // editor focus.
158
- focusWithoutScrolling(event.currentTarget);
159
- }
137
+ // PopupSelect's FocusLock returns focus to the element that was focused before the
138
+ // picker opened. If that is the editor/code block, closing the picker can scroll the
139
+ // whole code block into view. Focus the trigger first without scrolling so FocusLock
140
+ // returns to the trigger; see CodeBlockLanguagePicker's handleSelection for restoring
141
+ // editor focus.
142
+ focusWithoutScrolling(event.currentTarget);
160
143
  }, []);
161
144
  const handleTriggerMouseUp = useCallback(event => {
162
145
  if (fg('platform_editor_code_block_ga_patch_1')) {
@@ -206,7 +189,7 @@ export const LanguagePicker = ({
206
189
  onInputChange: handleInputChange,
207
190
  onMenuOpen: handleMenuOpen,
208
191
  options: hasSearchQuery ? searchOptions : options,
209
- popperProps: fg('platform_editor_code_block_dogfooding_patch') ? stableMenuPopperProps : menuPopperProps,
192
+ popperProps: stableMenuPopperProps,
210
193
  searchThreshold: -1,
211
194
  target: renderTarget,
212
195
  testId: "code-block-language-picker",
@@ -1,5 +1,4 @@
1
1
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
- import { fg } from '@atlaskit/platform-feature-flags';
3
2
  import { ACTIONS } from '../pm-plugins/actions';
4
3
  import { autoDetectPluginKey } from '../pm-plugins/auto-detect-state';
5
4
  import { createAutoDetectEntry } from './auto-detect-state';
@@ -41,44 +40,36 @@ const runPendingDetection = (view, localId, api) => {
41
40
  detectionResult,
42
41
  autoDetectedLanguage: detectedLanguage !== null && detectedLanguage !== void 0 ? detectedLanguage : entry.autoDetectedLanguage
43
42
  };
44
-
45
- // If there is no confident detection, record the result without clearing user-visible language.
46
- const shouldOnlyUpdateDetectionState = !detectedLanguage && (!found.node.attrs.language || shouldPreserveAutoDetectedLanguage);
47
43
  const hasDetectedLanguageChange = Boolean(detectedLanguage) && found.node.attrs.language !== detectedLanguage;
48
44
  const shouldClearStaleLanguage = !detectedLanguage && Boolean(found.node.attrs.language) && !shouldPreserveAutoDetectedLanguage;
49
- const shouldUpdateNodeLanguage = fg('platform_editor_code_block_dogfooding_patch') ? hasDetectedLanguageChange || shouldClearStaleLanguage : !shouldOnlyUpdateDetectionState;
45
+ const shouldUpdateNodeLanguage = hasDetectedLanguageChange || shouldClearStaleLanguage;
50
46
  api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(({
51
47
  tr
52
48
  }) => {
53
49
  if (shouldUpdateNodeLanguage) {
50
+ var _api$analytics;
54
51
  tr.setNodeMarkup(found.pos, undefined, {
55
52
  ...found.node.attrs,
56
53
  language: detectedLanguage
57
54
  }, found.node.marks);
58
- }
59
- tr.setMeta(autoDetectPluginKey, {
60
- type: ACTIONS.SET_AUTO_DETECT_ENTRY,
61
- data: {
62
- localId,
63
- entry: nextEntry
64
- }
65
- });
66
- // When platform_editor_code_block_dogfooding_patch is cleaned up, merge this with the previous shouldUpdateNodeLanguage check.
67
- if (!fg('platform_editor_code_block_dogfooding_patch') || shouldUpdateNodeLanguage) {
68
- var _api$analytics;
69
55
  api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.attachAnalyticsEvent({
70
56
  action: ACTION.LANGUAGE_AUTO_DETECTED,
71
57
  actionSubject: ACTION_SUBJECT.CODE_BLOCK,
72
58
  attributes: {
73
59
  language: detectedLanguage !== null && detectedLanguage !== void 0 ? detectedLanguage : 'none',
74
60
  detectionResult,
75
- ...(fg('platform_editor_code_block_dogfooding_patch') ? {
76
- detectionPhase
77
- } : {})
61
+ detectionPhase
78
62
  },
79
63
  eventType: EVENT_TYPE.TRACK
80
64
  })(tr);
81
65
  }
66
+ tr.setMeta(autoDetectPluginKey, {
67
+ type: ACTIONS.SET_AUTO_DETECT_ENTRY,
68
+ data: {
69
+ localId,
70
+ entry: nextEntry
71
+ }
72
+ });
82
73
  // Language detection runs in the background and should not move the viewport.
83
74
  return tr.setMeta('scrollIntoView', false);
84
75
  });
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable require-unicode-regexp */
2
- import { fg } from '@atlaskit/platform-feature-flags';
2
+
3
3
  // Conservative weighted-regex heuristic for common high-confidence snippets, not a full classifier.
4
4
  // Ambiguous snippets intentionally return null so users can select the language manually.
5
5
  const MAX_DETECTION_CHARS = 10_000;
@@ -85,7 +85,6 @@ const hasPattern = (code, pattern) => {
85
85
  return pattern.test(code);
86
86
  };
87
87
  const scorePatterns = (code, patterns) => patterns.reduce((score, [pattern, value]) => score + (hasPattern(code, pattern) ? value : 0), 0);
88
- const scoreEnhancedTypeScriptPatterns = code => fg('platform_editor_code_block_dogfooding_patch') ? scorePatterns(code, [[TS_ACCESS_MODIFIER_REGEX, 5], [TS_TYPED_ARROW_PARAM_REGEX, 5]]) : 0;
89
88
  const looksLikeHtmlTagPair = code => {
90
89
  const openTags = new Set();
91
90
  // Ignored via go/ees019
@@ -133,7 +132,7 @@ const getLanguageScores = code => [{
133
132
  score: scorePatterns(code, [[SQL_SELECT_FROM_REGEX, 5], [SQL_DML_REGEX, 5], [SQL_CLAUSE_REGEX, 2]])
134
133
  }, {
135
134
  language: 'typescript',
136
- score: scorePatterns(code, [[TS_INTERFACE_TYPE_REGEX, 5], [TS_IMPORT_EXPORT_TYPE_REGEX, 4], [TS_TYPED_VAR_REGEX, 4], [TS_RETURN_TYPE_REGEX, 3], [TS_ADVANCED_REGEX, 3]]) + scoreEnhancedTypeScriptPatterns(code)
135
+ score: scorePatterns(code, [[TS_INTERFACE_TYPE_REGEX, 5], [TS_IMPORT_EXPORT_TYPE_REGEX, 4], [TS_TYPED_VAR_REGEX, 4], [TS_RETURN_TYPE_REGEX, 3], [TS_ADVANCED_REGEX, 3], [TS_ACCESS_MODIFIER_REGEX, 5], [TS_TYPED_ARROW_PARAM_REGEX, 5]])
137
136
  }, {
138
137
  language: 'javascript',
139
138
  score: scorePatterns(code, [[JS_VAR_REGEX, 3], [JS_FUNCTION_REGEX, 3], [JS_ARROW_REGEX, 3], [JS_IMPORT_EXPORT_REGEX, 3], [JS_COMMON_API_REGEX, 3]])
@@ -472,10 +472,7 @@ export var toggleWordWrapStateForCodeBlockNode = function toggleWordWrapStateFor
472
472
  if (expValEquals('platform_editor_code_block_q4_lovability', 'isEnabled', true)) {
473
473
  tr.setNodeMarkup(codeBlock.pos, undefined, _objectSpread(_objectSpread({}, codeBlockNode.attrs), {}, {
474
474
  wrap: updatedToggleState
475
- }));
476
- if (fg('platform_editor_code_block_dogfooding_patch')) {
477
- tr.setMeta('scrollIntoView', false);
478
- }
475
+ })).setMeta('scrollIntoView', false);
479
476
  } else {
480
477
  codeBlockWrappedStates.set(codeBlockNode, updatedToggleState);
481
478
  }
@@ -159,7 +159,7 @@ export var getToolbarConfig = function getToolbarConfig() {
159
159
  filterOption: languageListFilter,
160
160
  formatMessage: formatMessage,
161
161
  languagePickerOptions: languagePickerOptions,
162
- triggerSpacing: !areAnyNewToolbarFlagsEnabled && fg('platform_editor_code_block_dogfooding_patch') ? 'compact' : 'default'
162
+ triggerSpacing: !areAnyNewToolbarFlagsEnabled ? 'compact' : 'default'
163
163
  });
164
164
  }
165
165
  };
@@ -28,25 +28,23 @@ export var CodeBlockLanguagePicker = function CodeBlockLanguagePicker(_ref) {
28
28
  var isDetectLanguageSelected = option.value === DETECT_LANGUAGE_VALUE;
29
29
  var command = isDetectLanguageSelected && (fg('platform_editor_code_block_ga_patch_1') || fg('platform_editor_code_block_language_detection_flow')) ? detectLanguage() : changeLanguage(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(option.value, selectionSource);
30
30
  var commandSucceeded = command(editorView.state, editorView.dispatch);
31
- if (fg('platform_editor_code_block_dogfooding_patch')) {
32
- if (fg('platform_editor_code_block_ga_patch_1')) {
33
- if (interactionMethod === 'mouse') {
34
- requestAnimationFrame(function () {
35
- // Mouse-opened picker should return editing focus to the code block. Keyboard-opened
36
- // picker keeps focus on the trigger to avoid CodeMirror DOM focus without cm.hasFocus.
37
- api === null || api === void 0 || api.core.actions.focus({
38
- scrollIntoView: false
39
- });
40
- });
41
- }
42
- } else {
31
+ if (fg('platform_editor_code_block_ga_patch_1')) {
32
+ if (interactionMethod === 'mouse') {
43
33
  requestAnimationFrame(function () {
44
- // Let PopupSelect/FocusLock finish returning focus to the trigger, then restore the editor.
34
+ // Mouse-opened picker should return editing focus to the code block. Keyboard-opened
35
+ // picker keeps focus on the trigger to avoid CodeMirror DOM focus without cm.hasFocus.
45
36
  api === null || api === void 0 || api.core.actions.focus({
46
37
  scrollIntoView: false
47
38
  });
48
39
  });
49
40
  }
41
+ } else {
42
+ requestAnimationFrame(function () {
43
+ // Let PopupSelect/FocusLock finish returning focus to the trigger, then restore the editor.
44
+ api === null || api === void 0 || api.core.actions.focus({
45
+ scrollIntoView: false
46
+ });
47
+ });
50
48
  }
51
49
  if (commandSucceeded && (option.value !== DETECT_LANGUAGE_VALUE || fg('platform_editor_code_block_ga_patch_1'))) {
52
50
  saveRecentLanguage(option.value);
@@ -43,17 +43,6 @@ var popupSelectComponents = {
43
43
  Group: CustomGroup,
44
44
  Option: CustomOption
45
45
  };
46
- var menuPopperProps = {
47
- modifiers: [{
48
- name: 'offset',
49
- options: {
50
- offset: [0, 8]
51
- }
52
- }, {
53
- name: 'preventOverflow',
54
- enabled: false
55
- }]
56
- };
57
46
  var focusWithoutScrolling = function focusWithoutScrolling(element) {
58
47
  element.focus({
59
48
  preventScroll: true
@@ -167,30 +156,24 @@ export var LanguagePicker = function LanguagePicker(_ref) {
167
156
  var isInputChange = !actionMeta || actionMeta.action === 'input-change';
168
157
  if (isInputChange) {
169
158
  inputValueRef.current = newInputValue;
170
- }
171
- if (isInputChange || !fg('platform_editor_code_block_dogfooding_patch')) {
172
159
  setHasSearchQuery(newInputValue.trim().length > 0);
173
160
  return newInputValue;
174
161
  }
175
162
  return inputValueRef.current;
176
163
  }, []);
177
164
  var handleMenuOpen = useCallback(function () {
178
- if (fg('platform_editor_code_block_dogfooding_patch')) {
179
- inputValueRef.current = '';
180
- setHasSearchQuery(false);
181
- setLockedPopperPlacement(undefined);
182
- }
165
+ inputValueRef.current = '';
166
+ setHasSearchQuery(false);
167
+ setLockedPopperPlacement(undefined);
183
168
  onMenuOpen === null || onMenuOpen === void 0 || onMenuOpen();
184
169
  }, [onMenuOpen]);
185
170
  var handleTriggerMouseDown = useCallback(function (event) {
186
- if (fg('platform_editor_code_block_dogfooding_patch')) {
187
- // PopupSelect's FocusLock returns focus to the element that was focused before the
188
- // picker opened. If that is the editor/code block, closing the picker can scroll the
189
- // whole code block into view. Focus the trigger first without scrolling so FocusLock
190
- // returns to the trigger; see CodeBlockLanguagePicker's handleSelection for restoring
191
- // editor focus.
192
- focusWithoutScrolling(event.currentTarget);
193
- }
171
+ // PopupSelect's FocusLock returns focus to the element that was focused before the
172
+ // picker opened. If that is the editor/code block, closing the picker can scroll the
173
+ // whole code block into view. Focus the trigger first without scrolling so FocusLock
174
+ // returns to the trigger; see CodeBlockLanguagePicker's handleSelection for restoring
175
+ // editor focus.
176
+ focusWithoutScrolling(event.currentTarget);
194
177
  }, []);
195
178
  var handleTriggerMouseUp = useCallback(function (event) {
196
179
  if (fg('platform_editor_code_block_ga_patch_1')) {
@@ -241,7 +224,7 @@ export var LanguagePicker = function LanguagePicker(_ref) {
241
224
  onInputChange: handleInputChange,
242
225
  onMenuOpen: handleMenuOpen,
243
226
  options: hasSearchQuery ? searchOptions : options,
244
- popperProps: fg('platform_editor_code_block_dogfooding_patch') ? stableMenuPopperProps : menuPopperProps,
227
+ popperProps: stableMenuPopperProps,
245
228
  searchThreshold: -1,
246
229
  target: renderTarget,
247
230
  testId: "code-block-language-picker",
@@ -3,7 +3,6 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  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; }
4
4
  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) { _defineProperty(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; }
5
5
  import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
6
- import { fg } from '@atlaskit/platform-feature-flags';
7
6
  import { ACTIONS } from '../pm-plugins/actions';
8
7
  import { autoDetectPluginKey } from '../pm-plugins/auto-detect-state';
9
8
  import { createAutoDetectEntry } from './auto-detect-state';
@@ -44,41 +43,34 @@ var runPendingDetection = function runPendingDetection(view, localId, api) {
44
43
  detectionResult: detectionResult,
45
44
  autoDetectedLanguage: detectedLanguage !== null && detectedLanguage !== void 0 ? detectedLanguage : entry.autoDetectedLanguage
46
45
  });
47
-
48
- // If there is no confident detection, record the result without clearing user-visible language.
49
- var shouldOnlyUpdateDetectionState = !detectedLanguage && (!found.node.attrs.language || shouldPreserveAutoDetectedLanguage);
50
46
  var hasDetectedLanguageChange = Boolean(detectedLanguage) && found.node.attrs.language !== detectedLanguage;
51
47
  var shouldClearStaleLanguage = !detectedLanguage && Boolean(found.node.attrs.language) && !shouldPreserveAutoDetectedLanguage;
52
- var shouldUpdateNodeLanguage = fg('platform_editor_code_block_dogfooding_patch') ? hasDetectedLanguageChange || shouldClearStaleLanguage : !shouldOnlyUpdateDetectionState;
48
+ var shouldUpdateNodeLanguage = hasDetectedLanguageChange || shouldClearStaleLanguage;
53
49
  api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref) {
54
50
  var tr = _ref.tr;
55
51
  if (shouldUpdateNodeLanguage) {
52
+ var _api$analytics;
56
53
  tr.setNodeMarkup(found.pos, undefined, _objectSpread(_objectSpread({}, found.node.attrs), {}, {
57
54
  language: detectedLanguage
58
55
  }), found.node.marks);
59
- }
60
- tr.setMeta(autoDetectPluginKey, {
61
- type: ACTIONS.SET_AUTO_DETECT_ENTRY,
62
- data: {
63
- localId: localId,
64
- entry: nextEntry
65
- }
66
- });
67
- // When platform_editor_code_block_dogfooding_patch is cleaned up, merge this with the previous shouldUpdateNodeLanguage check.
68
- if (!fg('platform_editor_code_block_dogfooding_patch') || shouldUpdateNodeLanguage) {
69
- var _api$analytics;
70
56
  api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.attachAnalyticsEvent({
71
57
  action: ACTION.LANGUAGE_AUTO_DETECTED,
72
58
  actionSubject: ACTION_SUBJECT.CODE_BLOCK,
73
- attributes: _objectSpread({
59
+ attributes: {
74
60
  language: detectedLanguage !== null && detectedLanguage !== void 0 ? detectedLanguage : 'none',
75
- detectionResult: detectionResult
76
- }, fg('platform_editor_code_block_dogfooding_patch') ? {
61
+ detectionResult: detectionResult,
77
62
  detectionPhase: detectionPhase
78
- } : {}),
63
+ },
79
64
  eventType: EVENT_TYPE.TRACK
80
65
  })(tr);
81
66
  }
67
+ tr.setMeta(autoDetectPluginKey, {
68
+ type: ACTIONS.SET_AUTO_DETECT_ENTRY,
69
+ data: {
70
+ localId: localId,
71
+ entry: nextEntry
72
+ }
73
+ });
82
74
  // Language detection runs in the background and should not move the viewport.
83
75
  return tr.setMeta('scrollIntoView', false);
84
76
  });
@@ -1,7 +1,7 @@
1
1
  import _typeof from "@babel/runtime/helpers/typeof";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
  /* eslint-disable require-unicode-regexp */
4
- import { fg } from '@atlaskit/platform-feature-flags';
4
+
5
5
  // Conservative weighted-regex heuristic for common high-confidence snippets, not a full classifier.
6
6
  // Ambiguous snippets intentionally return null so users can select the language manually.
7
7
  var MAX_DETECTION_CHARS = 10000;
@@ -94,9 +94,6 @@ var scorePatterns = function scorePatterns(code, patterns) {
94
94
  return score + (hasPattern(code, pattern) ? value : 0);
95
95
  }, 0);
96
96
  };
97
- var scoreEnhancedTypeScriptPatterns = function scoreEnhancedTypeScriptPatterns(code) {
98
- return fg('platform_editor_code_block_dogfooding_patch') ? scorePatterns(code, [[TS_ACCESS_MODIFIER_REGEX, 5], [TS_TYPED_ARROW_PARAM_REGEX, 5]]) : 0;
99
- };
100
97
  var looksLikeHtmlTagPair = function looksLikeHtmlTagPair(code) {
101
98
  var openTags = new Set();
102
99
  // Ignored via go/ees019
@@ -148,7 +145,7 @@ var getLanguageScores = function getLanguageScores(code) {
148
145
  score: scorePatterns(code, [[SQL_SELECT_FROM_REGEX, 5], [SQL_DML_REGEX, 5], [SQL_CLAUSE_REGEX, 2]])
149
146
  }, {
150
147
  language: 'typescript',
151
- score: scorePatterns(code, [[TS_INTERFACE_TYPE_REGEX, 5], [TS_IMPORT_EXPORT_TYPE_REGEX, 4], [TS_TYPED_VAR_REGEX, 4], [TS_RETURN_TYPE_REGEX, 3], [TS_ADVANCED_REGEX, 3]]) + scoreEnhancedTypeScriptPatterns(code)
148
+ score: scorePatterns(code, [[TS_INTERFACE_TYPE_REGEX, 5], [TS_IMPORT_EXPORT_TYPE_REGEX, 4], [TS_TYPED_VAR_REGEX, 4], [TS_RETURN_TYPE_REGEX, 3], [TS_ADVANCED_REGEX, 3], [TS_ACCESS_MODIFIER_REGEX, 5], [TS_TYPED_ARROW_PARAM_REGEX, 5]])
152
149
  }, {
153
150
  language: 'javascript',
154
151
  score: scorePatterns(code, [[JS_VAR_REGEX, 3], [JS_FUNCTION_REGEX, 3], [JS_ARROW_REGEX, 3], [JS_IMPORT_EXPORT_REGEX, 3], [JS_COMMON_API_REGEX, 3]])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-code-block",
3
- "version": "14.1.20",
3
+ "version": "14.1.21",
4
4
  "description": "Code block plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -34,21 +34,21 @@
34
34
  "@atlaskit/editor-plugin-toolbar": "^9.0.0",
35
35
  "@atlaskit/editor-prosemirror": "^8.0.0",
36
36
  "@atlaskit/editor-shared-styles": "^4.0.0",
37
- "@atlaskit/editor-toolbar": "^2.1.0",
37
+ "@atlaskit/editor-toolbar": "^2.2.0",
38
38
  "@atlaskit/flag": "^18.1.0",
39
39
  "@atlaskit/frontend-utilities": "^4.1.0",
40
40
  "@atlaskit/icon": "^37.0.0",
41
41
  "@atlaskit/platform-feature-flags": "^2.0.0",
42
- "@atlaskit/primitives": "^20.5.0",
42
+ "@atlaskit/primitives": "^20.6.0",
43
43
  "@atlaskit/prosemirror-input-rules": "^4.0.0",
44
44
  "@atlaskit/select": "^22.5.0",
45
45
  "@atlaskit/tmp-editor-statsig": "^124.1.0",
46
- "@atlaskit/tokens": "^15.5.0",
46
+ "@atlaskit/tokens": "^15.6.0",
47
47
  "@babel/runtime": "^7.0.0",
48
48
  "@compiled/react": "^0.20.0"
49
49
  },
50
50
  "peerDependencies": {
51
- "@atlaskit/editor-common": "^116.25.0",
51
+ "@atlaskit/editor-common": "^116.26.0",
52
52
  "react": "^18.2.0",
53
53
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
54
54
  },
@@ -103,9 +103,6 @@
103
103
  "platform_editor_code_block_add_line_number_button": {
104
104
  "type": "boolean"
105
105
  },
106
- "platform_editor_code_block_dogfooding_patch": {
107
- "type": "boolean"
108
- },
109
106
  "platform_editor_code_block_ga_patch_1": {
110
107
  "type": "boolean"
111
108
  },