@atlaskit/renderer 109.11.2 → 109.12.1
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 +16 -0
- package/dist/cjs/react/index.js +35 -5
- package/dist/cjs/react/nodes/codeBlock/codeBlock.js +1 -0
- package/dist/cjs/react/utils/segment-text.js +61 -0
- package/dist/cjs/ui/Renderer/index.js +3 -2
- package/dist/es2019/react/index.js +30 -5
- package/dist/es2019/react/nodes/codeBlock/codeBlock.js +1 -0
- package/dist/es2019/react/utils/segment-text.js +38 -0
- package/dist/es2019/ui/Renderer/index.js +3 -2
- package/dist/esm/react/index.js +35 -5
- package/dist/esm/react/nodes/codeBlock/codeBlock.js +1 -0
- package/dist/esm/react/utils/segment-text.js +55 -0
- package/dist/esm/ui/Renderer/index.js +3 -2
- package/dist/types/react/index.d.ts +4 -1
- package/dist/types/react/nodes/codeBlock/codeBlock.d.ts +1 -1
- package/dist/types/react/types.d.ts +9 -0
- package/dist/types/react/utils/segment-text.d.ts +10 -0
- package/dist/types/ui/renderer-props.d.ts +2 -0
- package/dist/types-ts4.5/react/index.d.ts +4 -1
- package/dist/types-ts4.5/react/nodes/codeBlock/codeBlock.d.ts +1 -1
- package/dist/types-ts4.5/react/types.d.ts +9 -0
- package/dist/types-ts4.5/react/utils/segment-text.d.ts +10 -0
- package/dist/types-ts4.5/ui/renderer-props.d.ts +2 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/renderer
|
|
2
2
|
|
|
3
|
+
## 109.12.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#85780](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/85780) [`f9127d5f97ed`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/f9127d5f97ed) - Add marks to TextHighlighter component
|
|
8
|
+
|
|
9
|
+
## 109.12.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#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.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 109.11.2
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/cjs/react/index.js
CHANGED
|
@@ -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,47 @@ 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
|
|
318
|
+
}, this.renderTextSegments(segments, textKey, mark));
|
|
316
319
|
}
|
|
317
|
-
return
|
|
320
|
+
return this.renderTextSegments(segments, textKey, mark);
|
|
321
|
+
}
|
|
322
|
+
}, {
|
|
323
|
+
key: "renderTextSegments",
|
|
324
|
+
value: function renderTextSegments(segments, key, text) {
|
|
325
|
+
var _this$textHighlighter;
|
|
326
|
+
var Component = (_this$textHighlighter = this.textHighlighter) === null || _this$textHighlighter === void 0 ? void 0 : _this$textHighlighter.component;
|
|
327
|
+
var marks = new Set(text.marks.map(function (m) {
|
|
328
|
+
return m.type.name;
|
|
329
|
+
}));
|
|
330
|
+
function renderSegment(segment) {
|
|
331
|
+
var idx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
332
|
+
if (segment.type === 'plain' || !Component) {
|
|
333
|
+
return segment.text;
|
|
334
|
+
}
|
|
335
|
+
return /*#__PURE__*/_react.default.createElement(Component, {
|
|
336
|
+
match: segment.text,
|
|
337
|
+
groups: segment.groups,
|
|
338
|
+
marks: marks,
|
|
339
|
+
key: "".concat(segment.text, "_").concat(idx)
|
|
340
|
+
}, segment.text);
|
|
341
|
+
}
|
|
342
|
+
if (segments.length === 1) {
|
|
343
|
+
return renderSegment(segments[0]);
|
|
344
|
+
}
|
|
345
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
|
|
346
|
+
key: key
|
|
347
|
+
}, segments.map(renderSegment));
|
|
318
348
|
}
|
|
319
349
|
}, {
|
|
320
350
|
key: "renderNode",
|
|
@@ -344,14 +374,14 @@ var ReactSerializer = exports.default = /*#__PURE__*/function () {
|
|
|
344
374
|
// TODO: https://product-fabric.atlassian.net/browse/CEMS-1048
|
|
345
375
|
var stickyHeaders = !(0, _rendererNode.insideBreakoutLayout)(path) ? this.stickyHeaders : undefined;
|
|
346
376
|
var isInsideOfBlockNode = (0, _rendererNode.insideBlockNode)(path, node.type.schema);
|
|
347
|
-
var
|
|
377
|
+
var isInsideMultiBodiedExtension = (0, _rendererNode.insideMultiBodiedExtension)(path, node.type.schema);
|
|
348
378
|
return _objectSpread(_objectSpread({}, this.getProps(node)), {}, {
|
|
349
379
|
allowColumnSorting: this.allowColumnSorting,
|
|
350
380
|
columnWidths: (0, _utils.calcTableColumnWidths)(node),
|
|
351
381
|
tableNode: node,
|
|
352
382
|
stickyHeaders: stickyHeaders,
|
|
353
383
|
isInsideOfBlockNode: isInsideOfBlockNode,
|
|
354
|
-
|
|
384
|
+
isInsideMultiBodiedExtension: isInsideMultiBodiedExtension
|
|
355
385
|
});
|
|
356
386
|
}
|
|
357
387
|
}, {
|
|
@@ -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 markTextSegmentMatches = text.matchAll(highlighter.pattern);
|
|
21
|
+
var _iterator = _createForOfIteratorHelper(markTextSegmentMatches),
|
|
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.
|
|
58
|
+
var packageVersion = "109.12.1";
|
|
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
|
}, {
|
|
@@ -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,42 @@ 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
|
|
286
|
+
}, this.renderTextSegments(segments, textKey, mark));
|
|
284
287
|
}
|
|
285
|
-
return
|
|
288
|
+
return this.renderTextSegments(segments, textKey, mark);
|
|
289
|
+
}
|
|
290
|
+
renderTextSegments(segments, key, text) {
|
|
291
|
+
var _this$textHighlighter;
|
|
292
|
+
const Component = (_this$textHighlighter = this.textHighlighter) === null || _this$textHighlighter === void 0 ? void 0 : _this$textHighlighter.component;
|
|
293
|
+
const marks = new Set(text.marks.map(m => m.type.name));
|
|
294
|
+
function renderSegment(segment, idx = 0) {
|
|
295
|
+
if (segment.type === 'plain' || !Component) {
|
|
296
|
+
return segment.text;
|
|
297
|
+
}
|
|
298
|
+
return /*#__PURE__*/React.createElement(Component, {
|
|
299
|
+
match: segment.text,
|
|
300
|
+
groups: segment.groups,
|
|
301
|
+
marks: marks,
|
|
302
|
+
key: `${segment.text}_${idx}`
|
|
303
|
+
}, segment.text);
|
|
304
|
+
}
|
|
305
|
+
if (segments.length === 1) {
|
|
306
|
+
return renderSegment(segments[0]);
|
|
307
|
+
}
|
|
308
|
+
return /*#__PURE__*/React.createElement(React.Fragment, {
|
|
309
|
+
key: key
|
|
310
|
+
}, segments.map(renderSegment));
|
|
286
311
|
}
|
|
287
312
|
renderNode(NodeComponent, props, key, content) {
|
|
288
313
|
return /*#__PURE__*/React.createElement(NodeComponent, _extends({
|
|
@@ -304,7 +329,7 @@ export default class ReactSerializer {
|
|
|
304
329
|
// TODO: https://product-fabric.atlassian.net/browse/CEMS-1048
|
|
305
330
|
const stickyHeaders = !insideBreakoutLayout(path) ? this.stickyHeaders : undefined;
|
|
306
331
|
const isInsideOfBlockNode = insideBlockNode(path, node.type.schema);
|
|
307
|
-
const
|
|
332
|
+
const isInsideMultiBodiedExtension = insideMultiBodiedExtension(path, node.type.schema);
|
|
308
333
|
return {
|
|
309
334
|
...this.getProps(node),
|
|
310
335
|
allowColumnSorting: this.allowColumnSorting,
|
|
@@ -312,7 +337,7 @@ export default class ReactSerializer {
|
|
|
312
337
|
tableNode: node,
|
|
313
338
|
stickyHeaders,
|
|
314
339
|
isInsideOfBlockNode,
|
|
315
|
-
|
|
340
|
+
isInsideMultiBodiedExtension
|
|
316
341
|
};
|
|
317
342
|
}
|
|
318
343
|
getDateProps(node, parentInfo) {
|
|
@@ -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 markTextSegmentMatches = text.matchAll(highlighter.pattern);
|
|
12
|
+
for (const markTextMatch of markTextSegmentMatches) {
|
|
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.
|
|
39
|
+
const packageVersion = "109.12.1";
|
|
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() {
|
package/dist/esm/react/index.js
CHANGED
|
@@ -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,47 @@ 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
|
|
311
|
+
}, this.renderTextSegments(segments, textKey, mark));
|
|
309
312
|
}
|
|
310
|
-
return
|
|
313
|
+
return this.renderTextSegments(segments, textKey, mark);
|
|
314
|
+
}
|
|
315
|
+
}, {
|
|
316
|
+
key: "renderTextSegments",
|
|
317
|
+
value: function renderTextSegments(segments, key, text) {
|
|
318
|
+
var _this$textHighlighter;
|
|
319
|
+
var Component = (_this$textHighlighter = this.textHighlighter) === null || _this$textHighlighter === void 0 ? void 0 : _this$textHighlighter.component;
|
|
320
|
+
var marks = new Set(text.marks.map(function (m) {
|
|
321
|
+
return m.type.name;
|
|
322
|
+
}));
|
|
323
|
+
function renderSegment(segment) {
|
|
324
|
+
var idx = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
325
|
+
if (segment.type === 'plain' || !Component) {
|
|
326
|
+
return segment.text;
|
|
327
|
+
}
|
|
328
|
+
return /*#__PURE__*/React.createElement(Component, {
|
|
329
|
+
match: segment.text,
|
|
330
|
+
groups: segment.groups,
|
|
331
|
+
marks: marks,
|
|
332
|
+
key: "".concat(segment.text, "_").concat(idx)
|
|
333
|
+
}, segment.text);
|
|
334
|
+
}
|
|
335
|
+
if (segments.length === 1) {
|
|
336
|
+
return renderSegment(segments[0]);
|
|
337
|
+
}
|
|
338
|
+
return /*#__PURE__*/React.createElement(React.Fragment, {
|
|
339
|
+
key: key
|
|
340
|
+
}, segments.map(renderSegment));
|
|
311
341
|
}
|
|
312
342
|
}, {
|
|
313
343
|
key: "renderNode",
|
|
@@ -337,14 +367,14 @@ var ReactSerializer = /*#__PURE__*/function () {
|
|
|
337
367
|
// TODO: https://product-fabric.atlassian.net/browse/CEMS-1048
|
|
338
368
|
var stickyHeaders = !insideBreakoutLayout(path) ? this.stickyHeaders : undefined;
|
|
339
369
|
var isInsideOfBlockNode = insideBlockNode(path, node.type.schema);
|
|
340
|
-
var
|
|
370
|
+
var isInsideMultiBodiedExtension = insideMultiBodiedExtension(path, node.type.schema);
|
|
341
371
|
return _objectSpread(_objectSpread({}, this.getProps(node)), {}, {
|
|
342
372
|
allowColumnSorting: this.allowColumnSorting,
|
|
343
373
|
columnWidths: calcTableColumnWidths(node),
|
|
344
374
|
tableNode: node,
|
|
345
375
|
stickyHeaders: stickyHeaders,
|
|
346
376
|
isInsideOfBlockNode: isInsideOfBlockNode,
|
|
347
|
-
|
|
377
|
+
isInsideMultiBodiedExtension: isInsideMultiBodiedExtension
|
|
348
378
|
});
|
|
349
379
|
}
|
|
350
380
|
}, {
|
|
@@ -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 markTextSegmentMatches = text.matchAll(highlighter.pattern);
|
|
15
|
+
var _iterator = _createForOfIteratorHelper(markTextSegmentMatches),
|
|
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.
|
|
49
|
+
var packageVersion = "109.12.1";
|
|
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
|
}, {
|
|
@@ -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;
|
|
@@ -57,3 +57,12 @@ 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
|
+
marks: Set<string>;
|
|
66
|
+
groups: Array<string> | undefined;
|
|
67
|
+
}>;
|
|
68
|
+
};
|
|
@@ -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;
|
|
@@ -57,3 +57,12 @@ 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
|
+
marks: Set<string>;
|
|
66
|
+
groups: Array<string> | undefined;
|
|
67
|
+
}>;
|
|
68
|
+
};
|
|
@@ -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.
|
|
3
|
+
"version": "109.12.1",
|
|
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.
|
|
32
|
+
"@atlaskit/button": "^17.8.0",
|
|
33
33
|
"@atlaskit/code": "^15.1.0",
|
|
34
|
-
"@atlaskit/editor-common": "^78.
|
|
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",
|