@atlaskit/renderer 109.11.1 → 109.12.0

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,21 @@
1
1
  # @atlaskit/renderer
2
2
 
3
+ ## 109.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#85610](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/85610) [`9e962c72289e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9e962c72289e) - Adding UNSTABLE_textHighlight API to renderer. It allows to wrap text that matches a RegEx in a provided React Component.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+
13
+ ## 109.11.2
14
+
15
+ ### Patch Changes
16
+
17
+ - [#84404](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/84404) [`eb8c1300b8ee`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/eb8c1300b8ee) - Click on media with annotation will no longer open the annotation view behind the media preview
18
+
3
19
  ## 109.11.1
4
20
 
5
21
  ### Patch Changes
@@ -23,6 +23,7 @@ var _utils2 = require("../utils");
23
23
  var _utils3 = require("@atlaskit/editor-prosemirror/utils");
24
24
  var _rendererNode = require("./renderer-node");
25
25
  var _code = require("./marks/code");
26
+ var _segmentText = require("./utils/segment-text");
26
27
  var _excluded = ["key"];
27
28
  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; }
28
29
  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; }
@@ -182,6 +183,7 @@ var ReactSerializer = exports.default = /*#__PURE__*/function () {
182
183
  this.nodeComponents = init.nodeComponents;
183
184
  this.allowWindowedCodeBlock = init.allowWindowedCodeBlock;
184
185
  this.isInsideOfInlineExtension = init.isInsideOfInlineExtension;
186
+ this.textHighlighter = init.textHighlighter;
185
187
  }
186
188
  (0, _createClass2.default)(ReactSerializer, [{
187
189
  key: "resetState",
@@ -302,19 +304,43 @@ var ReactSerializer = exports.default = /*#__PURE__*/function () {
302
304
  var markKey = "".concat(mark.type.name, "-component__").concat(this.startPos, "__").concat(parentMark.path.length);
303
305
  return this.renderMark((0, _marks.toReact)(mark), this.getMarkProps(mark, parentMark.path), markKey, content);
304
306
  }
307
+ var segments = (0, _segmentText.segmentText)(mark.text, this.textHighlighter);
305
308
  var startPos = this.startPos;
306
309
  var endPos = startPos + mark.nodeSize;
307
310
  this.startPos = endPos;
311
+ var textKey = "text-wrapper_".concat(this.startPos);
308
312
  if (this.surroundTextNodesWithTextWrapper) {
309
- var textKey = "text-wrapper_".concat(this.startPos);
310
313
  var parentDepth = Math.max(parentNode.path.length - 1, 0);
311
314
  return /*#__PURE__*/_react.default.createElement(_textWrapper.default, {
312
315
  key: textKey,
313
316
  startPos: startPos + parentDepth,
314
317
  endPos: endPos + parentDepth
315
- }, mark.text);
318
+ }, this.renderTextSegments(segments, textKey));
316
319
  }
317
- return mark.text || '';
320
+ return this.renderTextSegments(segments, textKey);
321
+ }
322
+ }, {
323
+ key: "renderTextSegments",
324
+ value: function renderTextSegments(segments, key) {
325
+ var _this$textHighlighter;
326
+ var Component = (_this$textHighlighter = this.textHighlighter) === null || _this$textHighlighter === void 0 ? void 0 : _this$textHighlighter.component;
327
+ function renderSegment(segment) {
328
+ var idx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
329
+ if (segment.type === 'plain' || !Component) {
330
+ return segment.text;
331
+ }
332
+ return /*#__PURE__*/_react.default.createElement(Component, {
333
+ match: segment.text,
334
+ groups: segment.groups,
335
+ key: "".concat(segment.text, "_").concat(idx)
336
+ }, segment.text);
337
+ }
338
+ if (segments.length === 1) {
339
+ return renderSegment(segments[0]);
340
+ }
341
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
342
+ key: key
343
+ }, segments.map(renderSegment));
318
344
  }
319
345
  }, {
320
346
  key: "renderNode",
@@ -37,6 +37,7 @@ function CodeBlock(props) {
37
37
  text: text,
38
38
  wrapLongLines: wrapLongLines
39
39
  }, (0, _react2.jsx)(_code.CodeBlock, {
40
+ testId: "renderer-code-block",
40
41
  language: language,
41
42
  text: text,
42
43
  codeBidiWarningLabel: codeBidiWarningLabel,
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.segmentText = segmentText;
7
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
8
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
9
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
10
+ function segmentText(text, highlighter) {
11
+ if (!highlighter || !text) {
12
+ return [{
13
+ type: 'plain',
14
+ text: text !== null && text !== void 0 ? text : ''
15
+ }];
16
+ }
17
+ var segments = [];
18
+ var pos = 0;
19
+ try {
20
+ var markTextSeggmentMatches = text.matchAll(highlighter.pattern);
21
+ var _iterator = _createForOfIteratorHelper(markTextSeggmentMatches),
22
+ _step;
23
+ try {
24
+ var _loop = function _loop() {
25
+ var markTextMatch = _step.value;
26
+ if (markTextMatch.index !== 0) {
27
+ segments.push({
28
+ type: 'plain',
29
+ text: text.substring(pos, markTextMatch.index)
30
+ });
31
+ }
32
+ segments.push({
33
+ type: 'match',
34
+ text: markTextMatch[0],
35
+ groups: markTextMatch.groups && Object.keys(markTextMatch.groups).filter(function (key) {
36
+ return markTextMatch.groups[key];
37
+ })
38
+ });
39
+ pos = markTextMatch.index + markTextMatch[0].length;
40
+ };
41
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
42
+ _loop();
43
+ }
44
+ } catch (err) {
45
+ _iterator.e(err);
46
+ } finally {
47
+ _iterator.f();
48
+ }
49
+ if (pos < text.length - 1) {
50
+ segments.push({
51
+ type: 'plain',
52
+ text: text.substring(pos)
53
+ });
54
+ }
55
+ return segments;
56
+ } catch (_e) {}
57
+ return [{
58
+ type: 'plain',
59
+ text: text
60
+ }];
61
+ }
@@ -55,7 +55,7 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
55
55
  var NORMAL_SEVERITY_THRESHOLD = exports.NORMAL_SEVERITY_THRESHOLD = 2000;
56
56
  var DEGRADED_SEVERITY_THRESHOLD = exports.DEGRADED_SEVERITY_THRESHOLD = 3000;
57
57
  var packageName = "@atlaskit/renderer";
58
- var packageVersion = "109.11.1";
58
+ var packageVersion = "109.12.0";
59
59
  var Renderer = exports.Renderer = /*#__PURE__*/function (_PureComponent) {
60
60
  (0, _inherits2.default)(Renderer, _PureComponent);
61
61
  var _super = _createSuper(Renderer);
@@ -281,7 +281,8 @@ var Renderer = exports.Renderer = /*#__PURE__*/function (_PureComponent) {
281
281
  nodeComponents: props.nodeComponents,
282
282
  // does not currently support SSR, should not be enabled in environments where Renderer is SSR-ed
283
283
  allowWindowedCodeBlock: featureFlags === null || featureFlags === void 0 ? void 0 : featureFlags.allowWindowedCodeBlock,
284
- isInsideOfInlineExtension: (0, _platformFeatureFlags.getBooleanFF)('platform.editor.inline_extension.extended_lcqdn') && props.isInsideOfInlineExtension
284
+ isInsideOfInlineExtension: (0, _platformFeatureFlags.getBooleanFF)('platform.editor.inline_extension.extended_lcqdn') && props.isInsideOfInlineExtension,
285
+ textHighlighter: props.UNSTABLE_textHighlighter
285
286
  };
286
287
  }
287
288
  }, {
@@ -32,13 +32,16 @@ var MarkElement = exports.MarkElement = function MarkElement(_ref) {
32
32
  if (!updateSubscriber) {
33
33
  return;
34
34
  }
35
+ if (useBlockLevel) {
36
+ return;
37
+ }
35
38
  var eventTarget = props.eventTarget,
36
39
  annotationIds = props.annotationIds;
37
40
  updateSubscriber.emit(_types.AnnotationUpdateEvent.ON_ANNOTATION_CLICK, {
38
41
  annotationIds: annotationIds,
39
42
  eventTarget: eventTarget
40
43
  });
41
- }, [updateSubscriber]);
44
+ }, [updateSubscriber, useBlockLevel]);
42
45
  var activeParentIds = (0, _hooks.useInlineCommentsFilter)({
43
46
  annotationIds: annotationParentIds,
44
47
  filter: {
@@ -12,6 +12,7 @@ import { getText } from '../utils';
12
12
  import { findChildrenByType } from '@atlaskit/editor-prosemirror/utils';
13
13
  import { insideBlockNode, insideBreakoutLayout, insideMultiBodiedExtension } from './renderer-node';
14
14
  import { isCodeMark } from './marks/code';
15
+ import { segmentText } from './utils/segment-text';
15
16
  function mergeMarks(marksAndNodes) {
16
17
  return marksAndNodes.reduce((acc, markOrNode) => {
17
18
  const prev = acc.length && acc[acc.length - 1] || null;
@@ -167,6 +168,7 @@ export default class ReactSerializer {
167
168
  this.nodeComponents = init.nodeComponents;
168
169
  this.allowWindowedCodeBlock = init.allowWindowedCodeBlock;
169
170
  this.isInsideOfInlineExtension = init.isInsideOfInlineExtension;
171
+ this.textHighlighter = init.textHighlighter;
170
172
  }
171
173
  resetState() {
172
174
  this.headingIds = [];
@@ -270,19 +272,40 @@ export default class ReactSerializer {
270
272
  const markKey = `${mark.type.name}-component__${this.startPos}__${parentMark.path.length}`;
271
273
  return this.renderMark(markToReact(mark), this.getMarkProps(mark, parentMark.path), markKey, content);
272
274
  }
275
+ const segments = segmentText(mark.text, this.textHighlighter);
273
276
  const startPos = this.startPos;
274
277
  const endPos = startPos + mark.nodeSize;
275
278
  this.startPos = endPos;
279
+ const textKey = `text-wrapper_${this.startPos}`;
276
280
  if (this.surroundTextNodesWithTextWrapper) {
277
- const textKey = `text-wrapper_${this.startPos}`;
278
281
  const parentDepth = Math.max(parentNode.path.length - 1, 0);
279
282
  return /*#__PURE__*/React.createElement(TextWrapperComponent, {
280
283
  key: textKey,
281
284
  startPos: startPos + parentDepth,
282
285
  endPos: endPos + parentDepth
283
- }, mark.text);
286
+ }, this.renderTextSegments(segments, textKey));
284
287
  }
285
- return mark.text || '';
288
+ return this.renderTextSegments(segments, textKey);
289
+ }
290
+ renderTextSegments(segments, key) {
291
+ var _this$textHighlighter;
292
+ const Component = (_this$textHighlighter = this.textHighlighter) === null || _this$textHighlighter === void 0 ? void 0 : _this$textHighlighter.component;
293
+ function renderSegment(segment, idx = 0) {
294
+ if (segment.type === 'plain' || !Component) {
295
+ return segment.text;
296
+ }
297
+ return /*#__PURE__*/React.createElement(Component, {
298
+ match: segment.text,
299
+ groups: segment.groups,
300
+ key: `${segment.text}_${idx}`
301
+ }, segment.text);
302
+ }
303
+ if (segments.length === 1) {
304
+ return renderSegment(segments[0]);
305
+ }
306
+ return /*#__PURE__*/React.createElement(React.Fragment, {
307
+ key: key
308
+ }, segments.map(renderSegment));
286
309
  }
287
310
  renderNode(NodeComponent, props, key, content) {
288
311
  return /*#__PURE__*/React.createElement(NodeComponent, _extends({
@@ -25,6 +25,7 @@ function CodeBlock(props) {
25
25
  text: text,
26
26
  wrapLongLines: wrapLongLines
27
27
  }, jsx(AkCodeBlock, {
28
+ testId: "renderer-code-block",
28
29
  language: language,
29
30
  text: text,
30
31
  codeBidiWarningLabel: codeBidiWarningLabel,
@@ -0,0 +1,38 @@
1
+ export function segmentText(text, highlighter) {
2
+ if (!highlighter || !text) {
3
+ return [{
4
+ type: 'plain',
5
+ text: text !== null && text !== void 0 ? text : ''
6
+ }];
7
+ }
8
+ const segments = [];
9
+ let pos = 0;
10
+ try {
11
+ const markTextSeggmentMatches = text.matchAll(highlighter.pattern);
12
+ for (const markTextMatch of markTextSeggmentMatches) {
13
+ if (markTextMatch.index !== 0) {
14
+ segments.push({
15
+ type: 'plain',
16
+ text: text.substring(pos, markTextMatch.index)
17
+ });
18
+ }
19
+ segments.push({
20
+ type: 'match',
21
+ text: markTextMatch[0],
22
+ groups: markTextMatch.groups && Object.keys(markTextMatch.groups).filter(key => markTextMatch.groups[key])
23
+ });
24
+ pos = markTextMatch.index + markTextMatch[0].length;
25
+ }
26
+ if (pos < text.length - 1) {
27
+ segments.push({
28
+ type: 'plain',
29
+ text: text.substring(pos)
30
+ });
31
+ }
32
+ return segments;
33
+ } catch (_e) {}
34
+ return [{
35
+ type: 'plain',
36
+ text
37
+ }];
38
+ }
@@ -36,7 +36,7 @@ import { EditorMediaClientProvider } from '../../react/utils/EditorMediaClientPr
36
36
  export const NORMAL_SEVERITY_THRESHOLD = 2000;
37
37
  export const DEGRADED_SEVERITY_THRESHOLD = 3000;
38
38
  const packageName = "@atlaskit/renderer";
39
- const packageVersion = "109.11.1";
39
+ const packageVersion = "109.12.0";
40
40
  export class Renderer extends PureComponent {
41
41
  constructor(props) {
42
42
  super(props);
@@ -260,7 +260,8 @@ export class Renderer extends PureComponent {
260
260
  nodeComponents: props.nodeComponents,
261
261
  // does not currently support SSR, should not be enabled in environments where Renderer is SSR-ed
262
262
  allowWindowedCodeBlock: featureFlags === null || featureFlags === void 0 ? void 0 : featureFlags.allowWindowedCodeBlock,
263
- isInsideOfInlineExtension: getBooleanFF('platform.editor.inline_extension.extended_lcqdn') && props.isInsideOfInlineExtension
263
+ isInsideOfInlineExtension: getBooleanFF('platform.editor.inline_extension.extended_lcqdn') && props.isInsideOfInlineExtension,
264
+ textHighlighter: props.UNSTABLE_textHighlighter
264
265
  };
265
266
  }
266
267
  render() {
@@ -22,6 +22,9 @@ const MarkElement = ({
22
22
  if (!updateSubscriber) {
23
23
  return;
24
24
  }
25
+ if (useBlockLevel) {
26
+ return;
27
+ }
25
28
  const {
26
29
  eventTarget,
27
30
  annotationIds
@@ -30,7 +33,7 @@ const MarkElement = ({
30
33
  annotationIds,
31
34
  eventTarget
32
35
  });
33
- }, [updateSubscriber]);
36
+ }, [updateSubscriber, useBlockLevel]);
34
37
  const activeParentIds = useInlineCommentsFilter({
35
38
  annotationIds: annotationParentIds,
36
39
  filter: {
@@ -19,6 +19,7 @@ import { getText } from '../utils';
19
19
  import { findChildrenByType } from '@atlaskit/editor-prosemirror/utils';
20
20
  import { insideBlockNode, insideBreakoutLayout, insideMultiBodiedExtension } from './renderer-node';
21
21
  import { isCodeMark } from './marks/code';
22
+ import { segmentText } from './utils/segment-text';
22
23
  function mergeMarks(marksAndNodes) {
23
24
  return marksAndNodes.reduce(function (acc, markOrNode) {
24
25
  var prev = acc.length && acc[acc.length - 1] || null;
@@ -175,6 +176,7 @@ var ReactSerializer = /*#__PURE__*/function () {
175
176
  this.nodeComponents = init.nodeComponents;
176
177
  this.allowWindowedCodeBlock = init.allowWindowedCodeBlock;
177
178
  this.isInsideOfInlineExtension = init.isInsideOfInlineExtension;
179
+ this.textHighlighter = init.textHighlighter;
178
180
  }
179
181
  _createClass(ReactSerializer, [{
180
182
  key: "resetState",
@@ -295,19 +297,43 @@ var ReactSerializer = /*#__PURE__*/function () {
295
297
  var markKey = "".concat(mark.type.name, "-component__").concat(this.startPos, "__").concat(parentMark.path.length);
296
298
  return this.renderMark(markToReact(mark), this.getMarkProps(mark, parentMark.path), markKey, content);
297
299
  }
300
+ var segments = segmentText(mark.text, this.textHighlighter);
298
301
  var startPos = this.startPos;
299
302
  var endPos = startPos + mark.nodeSize;
300
303
  this.startPos = endPos;
304
+ var textKey = "text-wrapper_".concat(this.startPos);
301
305
  if (this.surroundTextNodesWithTextWrapper) {
302
- var textKey = "text-wrapper_".concat(this.startPos);
303
306
  var parentDepth = Math.max(parentNode.path.length - 1, 0);
304
307
  return /*#__PURE__*/React.createElement(TextWrapperComponent, {
305
308
  key: textKey,
306
309
  startPos: startPos + parentDepth,
307
310
  endPos: endPos + parentDepth
308
- }, mark.text);
311
+ }, this.renderTextSegments(segments, textKey));
309
312
  }
310
- return mark.text || '';
313
+ return this.renderTextSegments(segments, textKey);
314
+ }
315
+ }, {
316
+ key: "renderTextSegments",
317
+ value: function renderTextSegments(segments, key) {
318
+ var _this$textHighlighter;
319
+ var Component = (_this$textHighlighter = this.textHighlighter) === null || _this$textHighlighter === void 0 ? void 0 : _this$textHighlighter.component;
320
+ function renderSegment(segment) {
321
+ var idx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
322
+ if (segment.type === 'plain' || !Component) {
323
+ return segment.text;
324
+ }
325
+ return /*#__PURE__*/React.createElement(Component, {
326
+ match: segment.text,
327
+ groups: segment.groups,
328
+ key: "".concat(segment.text, "_").concat(idx)
329
+ }, segment.text);
330
+ }
331
+ if (segments.length === 1) {
332
+ return renderSegment(segments[0]);
333
+ }
334
+ return /*#__PURE__*/React.createElement(React.Fragment, {
335
+ key: key
336
+ }, segments.map(renderSegment));
311
337
  }
312
338
  }, {
313
339
  key: "renderNode",
@@ -29,6 +29,7 @@ function CodeBlock(props) {
29
29
  text: text,
30
30
  wrapLongLines: wrapLongLines
31
31
  }, jsx(AkCodeBlock, {
32
+ testId: "renderer-code-block",
32
33
  language: language,
33
34
  text: text,
34
35
  codeBidiWarningLabel: codeBidiWarningLabel,
@@ -0,0 +1,55 @@
1
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
3
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
4
+ export function segmentText(text, highlighter) {
5
+ if (!highlighter || !text) {
6
+ return [{
7
+ type: 'plain',
8
+ text: text !== null && text !== void 0 ? text : ''
9
+ }];
10
+ }
11
+ var segments = [];
12
+ var pos = 0;
13
+ try {
14
+ var markTextSeggmentMatches = text.matchAll(highlighter.pattern);
15
+ var _iterator = _createForOfIteratorHelper(markTextSeggmentMatches),
16
+ _step;
17
+ try {
18
+ var _loop = function _loop() {
19
+ var markTextMatch = _step.value;
20
+ if (markTextMatch.index !== 0) {
21
+ segments.push({
22
+ type: 'plain',
23
+ text: text.substring(pos, markTextMatch.index)
24
+ });
25
+ }
26
+ segments.push({
27
+ type: 'match',
28
+ text: markTextMatch[0],
29
+ groups: markTextMatch.groups && Object.keys(markTextMatch.groups).filter(function (key) {
30
+ return markTextMatch.groups[key];
31
+ })
32
+ });
33
+ pos = markTextMatch.index + markTextMatch[0].length;
34
+ };
35
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
36
+ _loop();
37
+ }
38
+ } catch (err) {
39
+ _iterator.e(err);
40
+ } finally {
41
+ _iterator.f();
42
+ }
43
+ if (pos < text.length - 1) {
44
+ segments.push({
45
+ type: 'plain',
46
+ text: text.substring(pos)
47
+ });
48
+ }
49
+ return segments;
50
+ } catch (_e) {}
51
+ return [{
52
+ type: 'plain',
53
+ text: text
54
+ }];
55
+ }
@@ -46,7 +46,7 @@ import { EditorMediaClientProvider } from '../../react/utils/EditorMediaClientPr
46
46
  export var NORMAL_SEVERITY_THRESHOLD = 2000;
47
47
  export var DEGRADED_SEVERITY_THRESHOLD = 3000;
48
48
  var packageName = "@atlaskit/renderer";
49
- var packageVersion = "109.11.1";
49
+ var packageVersion = "109.12.0";
50
50
  export var Renderer = /*#__PURE__*/function (_PureComponent) {
51
51
  _inherits(Renderer, _PureComponent);
52
52
  var _super = _createSuper(Renderer);
@@ -272,7 +272,8 @@ export var Renderer = /*#__PURE__*/function (_PureComponent) {
272
272
  nodeComponents: props.nodeComponents,
273
273
  // does not currently support SSR, should not be enabled in environments where Renderer is SSR-ed
274
274
  allowWindowedCodeBlock: featureFlags === null || featureFlags === void 0 ? void 0 : featureFlags.allowWindowedCodeBlock,
275
- isInsideOfInlineExtension: getBooleanFF('platform.editor.inline_extension.extended_lcqdn') && props.isInsideOfInlineExtension
275
+ isInsideOfInlineExtension: getBooleanFF('platform.editor.inline_extension.extended_lcqdn') && props.isInsideOfInlineExtension,
276
+ textHighlighter: props.UNSTABLE_textHighlighter
276
277
  };
277
278
  }
278
279
  }, {
@@ -23,13 +23,16 @@ var MarkElement = function MarkElement(_ref) {
23
23
  if (!updateSubscriber) {
24
24
  return;
25
25
  }
26
+ if (useBlockLevel) {
27
+ return;
28
+ }
26
29
  var eventTarget = props.eventTarget,
27
30
  annotationIds = props.annotationIds;
28
31
  updateSubscriber.emit(AnnotationUpdateEvent.ON_ANNOTATION_CLICK, {
29
32
  annotationIds: annotationIds,
30
33
  eventTarget: eventTarget
31
34
  });
32
- }, [updateSubscriber]);
35
+ }, [updateSubscriber, useBlockLevel]);
33
36
  var activeParentIds = useInlineCommentsFilter({
34
37
  annotationIds: annotationParentIds,
35
38
  filter: {
@@ -7,7 +7,7 @@ import type { TextWrapper } from './nodes';
7
7
  import type { ExtensionHandlers } from '@atlaskit/editor-common/extensions';
8
8
  import type { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
9
9
  import type { EventHandlers } from '@atlaskit/editor-common/ui';
10
- import type { RendererContext } from './types';
10
+ import type { RendererContext, TextHighlighter } from './types';
11
11
  import type { MediaOptions } from '../types/mediaOptions';
12
12
  import type { SmartLinksOptions } from '../types/smartLinksOptions';
13
13
  import type { EmojiResourceConfig } from '@atlaskit/emoji/resource';
@@ -40,6 +40,7 @@ export interface ReactSerializerInit {
40
40
  nodeComponents?: NodeComponentsProps;
41
41
  allowWindowedCodeBlock?: boolean;
42
42
  isInsideOfInlineExtension?: boolean;
43
+ textHighlighter?: TextHighlighter;
43
44
  }
44
45
  interface ParentInfo {
45
46
  parentIsIncompleteTask: boolean;
@@ -86,6 +87,7 @@ export default class ReactSerializer implements Serializer<JSX.Element> {
86
87
  private nodeComponents?;
87
88
  private allowWindowedCodeBlock?;
88
89
  private isInsideOfInlineExtension?;
90
+ private textHighlighter?;
89
91
  constructor(init: ReactSerializerInit);
90
92
  private resetState;
91
93
  private getNodeProps;
@@ -94,6 +96,7 @@ export default class ReactSerializer implements Serializer<JSX.Element> {
94
96
  private withMediaMarkProps;
95
97
  private serializeTextWrapper;
96
98
  private serializeMark;
99
+ private renderTextSegments;
97
100
  private renderNode;
98
101
  private renderMark;
99
102
  private getTableChildrenProps;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { WrappedComponentProps } from 'react-intl-next';
2
+ import type { WrappedComponentProps } from 'react-intl-next';
3
3
  import type { SupportedLanguages } from '@atlaskit/code';
4
4
  export interface Props {
5
5
  text: string;
@@ -57,3 +57,11 @@ export interface AnnotationMarkMeta extends MarkMeta {
57
57
  }
58
58
  export type NodeProps<NodeAttrs = {}> = NodeAttrs & PropsWithChildren<NodeMeta>;
59
59
  export type MarkProps<MarkAttrs = {}> = MarkAttrs & PropsWithChildren<MarkMeta>;
60
+ export type TextHighlighter = {
61
+ pattern: RegExp;
62
+ component: React.ComponentType<{
63
+ children: React.ReactNode;
64
+ match: string;
65
+ groups: Array<string> | undefined;
66
+ }>;
67
+ };
@@ -0,0 +1,10 @@
1
+ import type { TextHighlighter } from '../types';
2
+ export type TextSegment = {
3
+ type: 'plain';
4
+ text: string;
5
+ } | {
6
+ type: 'match';
7
+ text: string;
8
+ groups: Array<string> | undefined;
9
+ };
10
+ export declare function segmentText(text: string | undefined, highlighter: TextHighlighter | undefined): Array<TextSegment>;
@@ -15,6 +15,7 @@ import type { MediaOptions } from '../types/mediaOptions';
15
15
  import type { SmartLinksOptions } from '../types/smartLinksOptions';
16
16
  import type { ACTION_SUBJECT } from '@atlaskit/editor-common/analytics';
17
17
  import type { DocNode } from '@atlaskit/adf-schema';
18
+ import type { TextHighlighter } from '../react/types';
18
19
  export interface RawObjectFeatureFlags {
19
20
  ['renderer-render-tracking']: string;
20
21
  }
@@ -113,4 +114,5 @@ export interface RendererProps {
113
114
  featureFlags?: {
114
115
  [featureFlag: string]: boolean;
115
116
  } | Partial<RawObjectFeatureFlags>;
117
+ UNSTABLE_textHighlighter?: TextHighlighter;
116
118
  }
@@ -7,7 +7,7 @@ import type { TextWrapper } from './nodes';
7
7
  import type { ExtensionHandlers } from '@atlaskit/editor-common/extensions';
8
8
  import type { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
9
9
  import type { EventHandlers } from '@atlaskit/editor-common/ui';
10
- import type { RendererContext } from './types';
10
+ import type { RendererContext, TextHighlighter } from './types';
11
11
  import type { MediaOptions } from '../types/mediaOptions';
12
12
  import type { SmartLinksOptions } from '../types/smartLinksOptions';
13
13
  import type { EmojiResourceConfig } from '@atlaskit/emoji/resource';
@@ -40,6 +40,7 @@ export interface ReactSerializerInit {
40
40
  nodeComponents?: NodeComponentsProps;
41
41
  allowWindowedCodeBlock?: boolean;
42
42
  isInsideOfInlineExtension?: boolean;
43
+ textHighlighter?: TextHighlighter;
43
44
  }
44
45
  interface ParentInfo {
45
46
  parentIsIncompleteTask: boolean;
@@ -86,6 +87,7 @@ export default class ReactSerializer implements Serializer<JSX.Element> {
86
87
  private nodeComponents?;
87
88
  private allowWindowedCodeBlock?;
88
89
  private isInsideOfInlineExtension?;
90
+ private textHighlighter?;
89
91
  constructor(init: ReactSerializerInit);
90
92
  private resetState;
91
93
  private getNodeProps;
@@ -94,6 +96,7 @@ export default class ReactSerializer implements Serializer<JSX.Element> {
94
96
  private withMediaMarkProps;
95
97
  private serializeTextWrapper;
96
98
  private serializeMark;
99
+ private renderTextSegments;
97
100
  private renderNode;
98
101
  private renderMark;
99
102
  private getTableChildrenProps;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { WrappedComponentProps } from 'react-intl-next';
2
+ import type { WrappedComponentProps } from 'react-intl-next';
3
3
  import type { SupportedLanguages } from '@atlaskit/code';
4
4
  export interface Props {
5
5
  text: string;
@@ -57,3 +57,11 @@ export interface AnnotationMarkMeta extends MarkMeta {
57
57
  }
58
58
  export type NodeProps<NodeAttrs = {}> = NodeAttrs & PropsWithChildren<NodeMeta>;
59
59
  export type MarkProps<MarkAttrs = {}> = MarkAttrs & PropsWithChildren<MarkMeta>;
60
+ export type TextHighlighter = {
61
+ pattern: RegExp;
62
+ component: React.ComponentType<{
63
+ children: React.ReactNode;
64
+ match: string;
65
+ groups: Array<string> | undefined;
66
+ }>;
67
+ };
@@ -0,0 +1,10 @@
1
+ import type { TextHighlighter } from '../types';
2
+ export type TextSegment = {
3
+ type: 'plain';
4
+ text: string;
5
+ } | {
6
+ type: 'match';
7
+ text: string;
8
+ groups: Array<string> | undefined;
9
+ };
10
+ export declare function segmentText(text: string | undefined, highlighter: TextHighlighter | undefined): Array<TextSegment>;
@@ -15,6 +15,7 @@ import type { MediaOptions } from '../types/mediaOptions';
15
15
  import type { SmartLinksOptions } from '../types/smartLinksOptions';
16
16
  import type { ACTION_SUBJECT } from '@atlaskit/editor-common/analytics';
17
17
  import type { DocNode } from '@atlaskit/adf-schema';
18
+ import type { TextHighlighter } from '../react/types';
18
19
  export interface RawObjectFeatureFlags {
19
20
  ['renderer-render-tracking']: string;
20
21
  }
@@ -113,4 +114,5 @@ export interface RendererProps {
113
114
  featureFlags?: {
114
115
  [featureFlag: string]: boolean;
115
116
  } | Partial<RawObjectFeatureFlags>;
117
+ UNSTABLE_textHighlighter?: TextHighlighter;
116
118
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/renderer",
3
- "version": "109.11.1",
3
+ "version": "109.12.0",
4
4
  "description": "Renderer component",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -29,9 +29,9 @@
29
29
  "@atlaskit/analytics-listeners": "^8.9.0",
30
30
  "@atlaskit/analytics-namespaced-context": "^6.9.0",
31
31
  "@atlaskit/analytics-next": "^9.2.0",
32
- "@atlaskit/button": "^17.7.0",
32
+ "@atlaskit/button": "^17.8.0",
33
33
  "@atlaskit/code": "^15.1.0",
34
- "@atlaskit/editor-common": "^78.21.0",
34
+ "@atlaskit/editor-common": "^78.22.0",
35
35
  "@atlaskit/editor-json-transformer": "^8.10.0",
36
36
  "@atlaskit/editor-palette": "1.5.3",
37
37
  "@atlaskit/editor-prosemirror": "3.0.0",