@atlaskit/editor-plugin-text-formatting 6.1.4 → 6.1.6

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,19 @@
1
1
  # @atlaskit/editor-plugin-text-formatting
2
2
 
3
+ ## 6.1.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [`3c501a06f7c8b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3c501a06f7c8b) -
8
+ [ux] [EDITOR-2460] detect and format backticks that close strings on the LHS
9
+ - Updated dependencies
10
+
11
+ ## 6.1.5
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies
16
+
3
17
  ## 6.1.4
4
18
 
5
19
  ### Patch Changes
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.default = exports.codeRegex = exports.ValidCombinations = void 0;
7
+ exports.default = exports.codeRegexWithBackwardMatch = exports.codeRegex = exports.ValidCombinations = void 0;
8
8
  exports.inputRulePlugin = inputRulePlugin;
9
9
  exports.strongRegex2 = exports.strongRegex1 = exports.strikeRegex = exports.italicRegex2 = exports.italicRegex1 = void 0;
10
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
@@ -22,6 +22,7 @@ var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
22
22
  var _utils = require("@atlaskit/editor-common/utils");
23
23
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
24
24
  var _prosemirrorInputRules = require("@atlaskit/prosemirror-input-rules");
25
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
25
26
  function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
26
27
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
27
28
  function _superPropGet(t, o, e, r) { var p = (0, _get2.default)((0, _getPrototypeOf2.default)(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
@@ -72,7 +73,14 @@ function addMark(markType, _schema, char, api) {
72
73
  // fixes the following case: my `*name` is *
73
74
  // expected result: should ignore special characters inside "code"
74
75
  if (textPrefix !== char || schema !== null && schema !== void 0 && (_schema$marks = schema.marks) !== null && _schema$marks !== void 0 && (_schema$marks = _schema$marks.code) !== null && _schema$marks !== void 0 && _schema$marks.isInSet(doc.resolve(start + 1).marks())) {
75
- return null;
76
+ if (!(0, _expValEquals.expValEquals)('platform_editor_lovability_inline_code', 'isEnabled', true)) {
77
+ return null;
78
+ }
79
+ // if the prefix is not a character but the suffix is, continue
80
+ var suffix = state.doc.textBetween(end - char.length, end);
81
+ if (suffix !== char) {
82
+ return null;
83
+ }
76
84
  }
77
85
 
78
86
  // Prevent autoformatting across hardbreaks
@@ -170,12 +178,39 @@ var buildRegex = function buildRegex(char) {
170
178
  baseRegex.replace(/X/g, escapedChar);
171
179
  return new ReverseRegexExp(replacedRegex);
172
180
  };
181
+ var buildRegexNew = function buildRegexNew(char) {
182
+ var allowsBackwardMatch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
183
+ // Ignored via go/ees005
184
+ // eslint-disable-next-line require-unicode-regexp
185
+ var escapedChar = char.replace(/(\W)/g, '\\$1');
186
+ // Ignored via go/ees005
187
+ // eslint-disable-next-line require-unicode-regexp
188
+ var combinations = ValidCombinations[char].map(function (c) {
189
+ return c.replace(/(\W)/g, '\\$1');
190
+ }).join('|');
191
+
192
+ // Single X - https://regex101.com/r/McT3yq/14/
193
+ // Double X - https://regex101.com/r/pQUgjx/1/
194
+ // if backwards matches are allowed, do not prefix the regex with an anchor (^)
195
+ var maybeAnchor = allowsBackwardMatch ? '' : '^';
196
+ var orCombinations = combinations ? "|".concat(combinations) : '';
197
+ var baseRegex = "".concat(maybeAnchor, "X(?=[^X\\s]).*?[^\\sX]X(?=[\\s").concat(_prosemirrorInputRules.leafNodeReplacementCharacter, "]").concat(orCombinations, "|$)");
198
+ var replacedRegex = String.prototype.hasOwnProperty('replaceAll') ?
199
+ // Ignored via go/ees005
200
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
201
+ baseRegex.replaceAll('X', escapedChar) :
202
+ // Ignored via go/ees005
203
+ // eslint-disable-next-line require-unicode-regexp
204
+ baseRegex.replace(/X/g, escapedChar);
205
+ return new ReverseRegexExp(replacedRegex);
206
+ };
173
207
  var strongRegex1 = exports.strongRegex1 = buildRegex(ValidAutoformatChars.STRONG);
174
208
  var strongRegex2 = exports.strongRegex2 = buildRegex(ValidAutoformatChars.STRONG_MARKDOWN);
175
209
  var italicRegex1 = exports.italicRegex1 = buildRegex(ValidAutoformatChars.ITALIC);
176
210
  var italicRegex2 = exports.italicRegex2 = buildRegex(ValidAutoformatChars.ITALIC_MARKDOWN);
177
211
  var strikeRegex = exports.strikeRegex = buildRegex(ValidAutoformatChars.STRIKE);
178
212
  var codeRegex = exports.codeRegex = buildRegex(ValidAutoformatChars.CODE);
213
+ var codeRegexWithBackwardMatch = exports.codeRegexWithBackwardMatch = buildRegexNew(ValidAutoformatChars.CODE, true);
179
214
 
180
215
  /**
181
216
  * Create input rules for strong mark
@@ -256,7 +291,8 @@ function getCodeInputRules(schema, editorAnalyticsAPI, api) {
256
291
  inputMethod: _analytics.INPUT_METHOD.FORMATTING
257
292
  }
258
293
  }, editorAnalyticsAPI);
259
- var backTickRule = (0, _utils.createRule)(codeRegex, addMark(schema.marks.code, schema, ValidAutoformatChars.CODE, api));
294
+ var allowsBackwardMatch = (0, _expValEquals.expValEquals)('platform_editor_lovability_inline_code', 'isEnabled', true);
295
+ var backTickRule = (0, _utils.createRule)(allowsBackwardMatch ? codeRegexWithBackwardMatch : codeRegex, addMark(schema.marks.code, schema, ValidAutoformatChars.CODE, api), allowsBackwardMatch);
260
296
  return [ruleWithCodeAnalytics(backTickRule)];
261
297
  }
262
298
  function inputRulePlugin(schema, editorAnalyticsAPI, api) {
@@ -4,6 +4,7 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
4
  import { createRule, inputRuleWithAnalytics } from '@atlaskit/editor-common/utils';
5
5
  import { fg } from '@atlaskit/platform-feature-flags';
6
6
  import { createPlugin, leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
7
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
7
8
  var ValidAutoformatChars = /*#__PURE__*/function (ValidAutoformatChars) {
8
9
  ValidAutoformatChars["STRONG"] = "__";
9
10
  ValidAutoformatChars["STRIKE"] = "~~";
@@ -60,7 +61,14 @@ function addMark(markType, _schema, char, api) {
60
61
  // fixes the following case: my `*name` is *
61
62
  // expected result: should ignore special characters inside "code"
62
63
  if (textPrefix !== char || schema !== null && schema !== void 0 && (_schema$marks = schema.marks) !== null && _schema$marks !== void 0 && (_schema$marks$code = _schema$marks.code) !== null && _schema$marks$code !== void 0 && _schema$marks$code.isInSet(doc.resolve(start + 1).marks())) {
63
- return null;
64
+ if (!expValEquals('platform_editor_lovability_inline_code', 'isEnabled', true)) {
65
+ return null;
66
+ }
67
+ // if the prefix is not a character but the suffix is, continue
68
+ const suffix = state.doc.textBetween(end - char.length, end);
69
+ if (suffix !== char) {
70
+ return null;
71
+ }
64
72
  }
65
73
 
66
74
  // Prevent autoformatting across hardbreaks
@@ -148,12 +156,36 @@ const buildRegex = char => {
148
156
  baseRegex.replace(/X/g, escapedChar);
149
157
  return new ReverseRegexExp(replacedRegex);
150
158
  };
159
+ const buildRegexNew = (char, allowsBackwardMatch = false) => {
160
+ // Ignored via go/ees005
161
+ // eslint-disable-next-line require-unicode-regexp
162
+ const escapedChar = char.replace(/(\W)/g, '\\$1');
163
+ // Ignored via go/ees005
164
+ // eslint-disable-next-line require-unicode-regexp
165
+ const combinations = ValidCombinations[char].map(c => c.replace(/(\W)/g, '\\$1')).join('|');
166
+
167
+ // Single X - https://regex101.com/r/McT3yq/14/
168
+ // Double X - https://regex101.com/r/pQUgjx/1/
169
+ // if backwards matches are allowed, do not prefix the regex with an anchor (^)
170
+ const maybeAnchor = allowsBackwardMatch ? '' : '^';
171
+ const orCombinations = combinations ? `|${combinations}` : '';
172
+ const baseRegex = `${maybeAnchor}X(?=[^X\\s]).*?[^\\sX]X(?=[\\s${leafNodeReplacementCharacter}]${orCombinations}|$)`;
173
+ const replacedRegex = String.prototype.hasOwnProperty('replaceAll') ?
174
+ // Ignored via go/ees005
175
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
176
+ baseRegex.replaceAll('X', escapedChar) :
177
+ // Ignored via go/ees005
178
+ // eslint-disable-next-line require-unicode-regexp
179
+ baseRegex.replace(/X/g, escapedChar);
180
+ return new ReverseRegexExp(replacedRegex);
181
+ };
151
182
  export const strongRegex1 = buildRegex(ValidAutoformatChars.STRONG);
152
183
  export const strongRegex2 = buildRegex(ValidAutoformatChars.STRONG_MARKDOWN);
153
184
  export const italicRegex1 = buildRegex(ValidAutoformatChars.ITALIC);
154
185
  export const italicRegex2 = buildRegex(ValidAutoformatChars.ITALIC_MARKDOWN);
155
186
  export const strikeRegex = buildRegex(ValidAutoformatChars.STRIKE);
156
187
  export const codeRegex = buildRegex(ValidAutoformatChars.CODE);
188
+ export const codeRegexWithBackwardMatch = buildRegexNew(ValidAutoformatChars.CODE, true);
157
189
 
158
190
  /**
159
191
  * Create input rules for strong mark
@@ -234,7 +266,8 @@ function getCodeInputRules(schema, editorAnalyticsAPI, api) {
234
266
  inputMethod: INPUT_METHOD.FORMATTING
235
267
  }
236
268
  }, editorAnalyticsAPI);
237
- const backTickRule = createRule(codeRegex, addMark(schema.marks.code, schema, ValidAutoformatChars.CODE, api));
269
+ const allowsBackwardMatch = expValEquals('platform_editor_lovability_inline_code', 'isEnabled', true);
270
+ const backTickRule = createRule(allowsBackwardMatch ? codeRegexWithBackwardMatch : codeRegex, addMark(schema.marks.code, schema, ValidAutoformatChars.CODE, api), allowsBackwardMatch);
238
271
  return [ruleWithCodeAnalytics(backTickRule)];
239
272
  }
240
273
  export function inputRulePlugin(schema, editorAnalyticsAPI, api) {
@@ -16,6 +16,7 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
16
16
  import { createRule, inputRuleWithAnalytics } from '@atlaskit/editor-common/utils';
17
17
  import { fg } from '@atlaskit/platform-feature-flags';
18
18
  import { createPlugin, leafNodeReplacementCharacter } from '@atlaskit/prosemirror-input-rules';
19
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
19
20
  var ValidAutoformatChars = /*#__PURE__*/function (ValidAutoformatChars) {
20
21
  ValidAutoformatChars["STRONG"] = "__";
21
22
  ValidAutoformatChars["STRIKE"] = "~~";
@@ -63,7 +64,14 @@ function addMark(markType, _schema, char, api) {
63
64
  // fixes the following case: my `*name` is *
64
65
  // expected result: should ignore special characters inside "code"
65
66
  if (textPrefix !== char || schema !== null && schema !== void 0 && (_schema$marks = schema.marks) !== null && _schema$marks !== void 0 && (_schema$marks = _schema$marks.code) !== null && _schema$marks !== void 0 && _schema$marks.isInSet(doc.resolve(start + 1).marks())) {
66
- return null;
67
+ if (!expValEquals('platform_editor_lovability_inline_code', 'isEnabled', true)) {
68
+ return null;
69
+ }
70
+ // if the prefix is not a character but the suffix is, continue
71
+ var suffix = state.doc.textBetween(end - char.length, end);
72
+ if (suffix !== char) {
73
+ return null;
74
+ }
67
75
  }
68
76
 
69
77
  // Prevent autoformatting across hardbreaks
@@ -161,12 +169,39 @@ var buildRegex = function buildRegex(char) {
161
169
  baseRegex.replace(/X/g, escapedChar);
162
170
  return new ReverseRegexExp(replacedRegex);
163
171
  };
172
+ var buildRegexNew = function buildRegexNew(char) {
173
+ var allowsBackwardMatch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
174
+ // Ignored via go/ees005
175
+ // eslint-disable-next-line require-unicode-regexp
176
+ var escapedChar = char.replace(/(\W)/g, '\\$1');
177
+ // Ignored via go/ees005
178
+ // eslint-disable-next-line require-unicode-regexp
179
+ var combinations = ValidCombinations[char].map(function (c) {
180
+ return c.replace(/(\W)/g, '\\$1');
181
+ }).join('|');
182
+
183
+ // Single X - https://regex101.com/r/McT3yq/14/
184
+ // Double X - https://regex101.com/r/pQUgjx/1/
185
+ // if backwards matches are allowed, do not prefix the regex with an anchor (^)
186
+ var maybeAnchor = allowsBackwardMatch ? '' : '^';
187
+ var orCombinations = combinations ? "|".concat(combinations) : '';
188
+ var baseRegex = "".concat(maybeAnchor, "X(?=[^X\\s]).*?[^\\sX]X(?=[\\s").concat(leafNodeReplacementCharacter, "]").concat(orCombinations, "|$)");
189
+ var replacedRegex = String.prototype.hasOwnProperty('replaceAll') ?
190
+ // Ignored via go/ees005
191
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
192
+ baseRegex.replaceAll('X', escapedChar) :
193
+ // Ignored via go/ees005
194
+ // eslint-disable-next-line require-unicode-regexp
195
+ baseRegex.replace(/X/g, escapedChar);
196
+ return new ReverseRegexExp(replacedRegex);
197
+ };
164
198
  export var strongRegex1 = buildRegex(ValidAutoformatChars.STRONG);
165
199
  export var strongRegex2 = buildRegex(ValidAutoformatChars.STRONG_MARKDOWN);
166
200
  export var italicRegex1 = buildRegex(ValidAutoformatChars.ITALIC);
167
201
  export var italicRegex2 = buildRegex(ValidAutoformatChars.ITALIC_MARKDOWN);
168
202
  export var strikeRegex = buildRegex(ValidAutoformatChars.STRIKE);
169
203
  export var codeRegex = buildRegex(ValidAutoformatChars.CODE);
204
+ export var codeRegexWithBackwardMatch = buildRegexNew(ValidAutoformatChars.CODE, true);
170
205
 
171
206
  /**
172
207
  * Create input rules for strong mark
@@ -247,7 +282,8 @@ function getCodeInputRules(schema, editorAnalyticsAPI, api) {
247
282
  inputMethod: INPUT_METHOD.FORMATTING
248
283
  }
249
284
  }, editorAnalyticsAPI);
250
- var backTickRule = createRule(codeRegex, addMark(schema.marks.code, schema, ValidAutoformatChars.CODE, api));
285
+ var allowsBackwardMatch = expValEquals('platform_editor_lovability_inline_code', 'isEnabled', true);
286
+ var backTickRule = createRule(allowsBackwardMatch ? codeRegexWithBackwardMatch : codeRegex, addMark(schema.marks.code, schema, ValidAutoformatChars.CODE, api), allowsBackwardMatch);
251
287
  return [ruleWithCodeAnalytics(backTickRule)];
252
288
  }
253
289
  export function inputRulePlugin(schema, editorAnalyticsAPI, api) {
@@ -21,5 +21,6 @@ export declare const italicRegex1: ReverseRegexExp;
21
21
  export declare const italicRegex2: ReverseRegexExp;
22
22
  export declare const strikeRegex: ReverseRegexExp;
23
23
  export declare const codeRegex: ReverseRegexExp;
24
+ export declare const codeRegexWithBackwardMatch: ReverseRegexExp;
24
25
  export declare function inputRulePlugin(schema: Schema, editorAnalyticsAPI: EditorAnalyticsAPI | undefined, api: ExtractInjectionAPI<TextFormattingPlugin> | undefined): SafePlugin | undefined;
25
26
  export default inputRulePlugin;
@@ -21,5 +21,6 @@ export declare const italicRegex1: ReverseRegexExp;
21
21
  export declare const italicRegex2: ReverseRegexExp;
22
22
  export declare const strikeRegex: ReverseRegexExp;
23
23
  export declare const codeRegex: ReverseRegexExp;
24
+ export declare const codeRegexWithBackwardMatch: ReverseRegexExp;
24
25
  export declare function inputRulePlugin(schema: Schema, editorAnalyticsAPI: EditorAnalyticsAPI | undefined, api: ExtractInjectionAPI<TextFormattingPlugin> | undefined): SafePlugin | undefined;
25
26
  export default inputRulePlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-text-formatting",
3
- "version": "6.1.4",
3
+ "version": "6.1.6",
4
4
  "description": "Text-formatting plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -38,19 +38,19 @@
38
38
  "@atlaskit/editor-prosemirror": "7.0.0",
39
39
  "@atlaskit/editor-shared-styles": "^3.8.0",
40
40
  "@atlaskit/editor-tables": "^2.9.0",
41
- "@atlaskit/editor-toolbar": "^0.16.0",
41
+ "@atlaskit/editor-toolbar": "^0.17.0",
42
42
  "@atlaskit/editor-toolbar-model": "^0.2.0",
43
43
  "@atlaskit/icon": "^28.5.0",
44
44
  "@atlaskit/platform-feature-flags": "^1.1.0",
45
- "@atlaskit/prosemirror-input-rules": "^3.5.0",
46
- "@atlaskit/tmp-editor-statsig": "^13.18.0",
47
- "@atlaskit/tokens": "^7.0.0",
45
+ "@atlaskit/prosemirror-input-rules": "^3.6.0",
46
+ "@atlaskit/tmp-editor-statsig": "^13.27.0",
47
+ "@atlaskit/tokens": "^7.1.0",
48
48
  "@babel/runtime": "^7.0.0",
49
49
  "@emotion/react": "^11.7.1",
50
50
  "react-intl-next": "npm:react-intl@^5.18.1"
51
51
  },
52
52
  "peerDependencies": {
53
- "@atlaskit/editor-common": "^110.18.0",
53
+ "@atlaskit/editor-common": "^110.22.0",
54
54
  "react": "^18.2.0"
55
55
  },
56
56
  "devDependencies": {