@atlaskit/renderer 137.1.8 → 137.1.10
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 +28 -0
- package/dist/cjs/react/index.js +1 -1
- package/dist/cjs/react/nodes/table/colgroup.js +1 -2
- package/dist/cjs/react/nodes/table/sticky.js +2 -4
- package/dist/cjs/react/nodes/table/table.js +1 -12
- package/dist/cjs/react/nodes/table.js +471 -203
- package/dist/cjs/ui/Expand.js +33 -7
- package/dist/cjs/ui/Renderer/breakout-ssr.js +1 -2
- package/dist/cjs/ui/Renderer/index.js +3 -3
- package/dist/cjs/ui/utils/expand-body.js +218 -0
- package/dist/cjs/ui/utils/expand-search-text.js +39 -1
- package/dist/es2019/react/index.js +1 -1
- package/dist/es2019/react/nodes/table/colgroup.js +1 -2
- package/dist/es2019/react/nodes/table/sticky.js +2 -3
- package/dist/es2019/react/nodes/table/table.js +1 -12
- package/dist/es2019/react/nodes/table.js +457 -190
- package/dist/es2019/ui/Expand.js +33 -7
- package/dist/es2019/ui/Renderer/breakout-ssr.js +1 -2
- package/dist/es2019/ui/Renderer/index.js +3 -3
- package/dist/es2019/ui/utils/expand-body.js +198 -0
- package/dist/es2019/ui/utils/expand-search-text.js +38 -0
- package/dist/esm/react/index.js +1 -1
- package/dist/esm/react/nodes/table/colgroup.js +1 -2
- package/dist/esm/react/nodes/table/sticky.js +2 -4
- package/dist/esm/react/nodes/table/table.js +1 -12
- package/dist/esm/react/nodes/table.js +471 -202
- package/dist/esm/ui/Expand.js +33 -7
- package/dist/esm/ui/Renderer/breakout-ssr.js +1 -2
- package/dist/esm/ui/Renderer/index.js +3 -3
- package/dist/esm/ui/utils/expand-body.js +210 -0
- package/dist/esm/ui/utils/expand-search-text.js +38 -0
- package/dist/types/react/nodes/table/sticky.d.ts +1 -2
- package/dist/types/react/nodes/table.d.ts +78 -8
- package/dist/types/ui/{expand-body.d.ts → utils/expand-body.d.ts} +26 -5
- package/dist/types/ui/utils/expand-search-text.d.ts +14 -0
- package/package.json +6 -9
- package/dist/cjs/react/nodes/tableNew.js +0 -1050
- package/dist/cjs/ui/expand-body.js +0 -122
- package/dist/es2019/react/nodes/tableNew.js +0 -986
- package/dist/es2019/ui/expand-body.js +0 -107
- package/dist/esm/react/nodes/tableNew.js +0 -1044
- package/dist/esm/ui/expand-body.js +0 -114
- package/dist/types/react/nodes/tableNew.d.ts +0 -189
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import React, { createContext, isValidElement, useContext } from 'react';
|
|
2
|
-
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
|
|
3
|
-
import { BLOCK_SEPARATOR, getBlockSearchText, holdsRevealableContent, isExpandNode } from './utils/expand-search-text';
|
|
4
|
-
const ExpandBodyContext = /*#__PURE__*/createContext(null);
|
|
5
|
-
export const ExpandBodyProvider = ExpandBodyContext.Provider;
|
|
6
|
-
export const useExpandBody = () => useContext(ExpandBodyContext);
|
|
7
|
-
/**
|
|
8
|
-
* One or more neighbouring blocks of an expand's body. Shows their text until the expand is
|
|
9
|
-
* opened, then renders them. Falls back to rendering if there is no text, or if there is no
|
|
10
|
-
* expand above it.
|
|
11
|
-
*
|
|
12
|
-
* The text is rendered as-is, with no element around it. Nothing reads it but browser find,
|
|
13
|
-
* which only needs the characters to be in the DOM.
|
|
14
|
-
*/
|
|
15
|
-
export const ExpandBodyBlock = ({
|
|
16
|
-
children,
|
|
17
|
-
searchText
|
|
18
|
-
}) => {
|
|
19
|
-
const body = useExpandBody();
|
|
20
|
-
if (searchText === undefined || body === null || body.revealed) {
|
|
21
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
22
|
-
}
|
|
23
|
-
return searchText;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Called for every node the serializer renders. If the node is a block of an expand's body,
|
|
28
|
-
* wraps it so it can show its text instead of rendering while that expand is collapsed.
|
|
29
|
-
* Everything else is returned untouched.
|
|
30
|
-
*
|
|
31
|
-
* A block holding an expand of its own is also returned untouched, so a table with a nested
|
|
32
|
-
* expand in it, or an extension holding stashed ADF, renders even while collapsed. That
|
|
33
|
-
* expand needs an element of its own, because the element browser find reveals is the only
|
|
34
|
-
* way we learn the match was inside it rather than higher up. We give up the saving on those
|
|
35
|
-
* blocks so the reader searches once instead of once per level.
|
|
36
|
-
*
|
|
37
|
-
* `ancestors` is the node's ancestor chain, nearest last.
|
|
38
|
-
*/
|
|
39
|
-
export const withExpandBodyBlock = (node, ancestors, index, serialized) => {
|
|
40
|
-
const parent = ancestors[ancestors.length - 1];
|
|
41
|
-
if (!parent || !isExpandNode(parent)) {
|
|
42
|
-
return serialized;
|
|
43
|
-
}
|
|
44
|
-
if (!isExperimentEnabled('platform_editor_defer_collapsed_expand_body') || holdsRevealableContent(node)) {
|
|
45
|
-
return serialized;
|
|
46
|
-
}
|
|
47
|
-
const searchText = getBlockSearchText(node);
|
|
48
|
-
if (searchText === undefined) {
|
|
49
|
-
return serialized;
|
|
50
|
-
}
|
|
51
|
-
return /*#__PURE__*/React.createElement(ExpandBodyBlock, {
|
|
52
|
-
key: `expand-body-block-${index}`,
|
|
53
|
-
searchText: searchText
|
|
54
|
-
}, serialized);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/** Whatever the serializer produced for one child: an element, a string, an array of either. */
|
|
58
|
-
|
|
59
|
-
const searchTextOf = child => /*#__PURE__*/isValidElement(child) && child.type === ExpandBodyBlock ? child.props.searchText : undefined;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Joins neighbouring blocks that are showing text into one, so a run of them is a single string in
|
|
63
|
-
* the DOM rather than one per block. A body of twenty paragraphs becomes one text node instead of
|
|
64
|
-
* twenty.
|
|
65
|
-
*
|
|
66
|
-
* A block that is being rendered — a nested expand, say — ends the run, because the text either
|
|
67
|
-
* side of it has to stay either side of it.
|
|
68
|
-
*/
|
|
69
|
-
export const mergeExpandBodyText = children => {
|
|
70
|
-
// Called for every fragment in the document, and only an expand's body has anything to merge, so
|
|
71
|
-
// leave the array alone unless two neighbours are actually showing text.
|
|
72
|
-
const hasRun = children.some((child, index) => index > 0 && searchTextOf(child) !== undefined && searchTextOf(children[index - 1]) !== undefined);
|
|
73
|
-
if (!hasRun) {
|
|
74
|
-
return children;
|
|
75
|
-
}
|
|
76
|
-
const merged = [];
|
|
77
|
-
let run = [];
|
|
78
|
-
const endRun = () => {
|
|
79
|
-
if (run.length === 0) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
if (run.length === 1) {
|
|
83
|
-
merged.push(run[0]);
|
|
84
|
-
} else {
|
|
85
|
-
var _key;
|
|
86
|
-
const text = run.map(searchTextOf).filter(Boolean).join(BLOCK_SEPARATOR);
|
|
87
|
-
// The blocks themselves, not the wrappers around them: nesting the wrappers would show
|
|
88
|
-
// each block's text again inside the joined run.
|
|
89
|
-
const blocks = run.map(child => child.props.children);
|
|
90
|
-
merged.push( /*#__PURE__*/React.createElement(ExpandBodyBlock, {
|
|
91
|
-
key: (_key = run[0].key) !== null && _key !== void 0 ? _key : undefined,
|
|
92
|
-
searchText: text
|
|
93
|
-
}, blocks));
|
|
94
|
-
}
|
|
95
|
-
run = [];
|
|
96
|
-
};
|
|
97
|
-
children.forEach(child => {
|
|
98
|
-
if (searchTextOf(child) === undefined) {
|
|
99
|
-
endRun();
|
|
100
|
-
merged.push(child);
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
run.push(child);
|
|
104
|
-
});
|
|
105
|
-
endRun();
|
|
106
|
-
return merged;
|
|
107
|
-
};
|