@atlaskit/renderer 137.1.3 → 137.1.4
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 +30 -0
- package/dist/cjs/react/index.js +7 -19
- package/dist/cjs/react/utils/EditorMediaClientProvider.js +1 -1
- package/dist/cjs/ui/Expand.js +65 -81
- package/dist/cjs/ui/Renderer/index.js +1 -1
- package/dist/cjs/ui/utils/expand-search-text.js +98 -0
- package/dist/es2019/react/index.js +8 -18
- package/dist/es2019/react/utils/EditorMediaClientProvider.js +1 -1
- package/dist/es2019/ui/Expand.js +42 -61
- package/dist/es2019/ui/Renderer/index.js +1 -1
- package/dist/es2019/ui/utils/expand-search-text.js +84 -0
- package/dist/esm/react/index.js +8 -20
- package/dist/esm/react/utils/EditorMediaClientProvider.js +1 -1
- package/dist/esm/ui/Expand.js +65 -81
- package/dist/esm/ui/Renderer/index.js +1 -1
- package/dist/esm/ui/utils/expand-search-text.js +93 -0
- package/dist/types/ui/Expand.d.ts +8 -2
- package/dist/types/ui/utils/expand-search-text.d.ts +12 -0
- package/package.json +3 -6
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { findChildrenByMark } from '@atlaskit/editor-prosemirror/utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Minimal structural view of an ADF entity. `parameters.nestedContent` holds raw ADF JSON rather
|
|
5
|
+
* than ProseMirror nodes, so it cannot be walked with the model API.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** Separates text from adjacent blocks so phrases cannot fuse across block boundaries. */
|
|
9
|
+
var BLOCK_SEPARATOR = ' ';
|
|
10
|
+
var asText = function asText(value) {
|
|
11
|
+
return typeof value === 'string' ? value : '';
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Extracts text from raw ADF JSON.
|
|
16
|
+
*
|
|
17
|
+
* Needed because some extensions stash a whole ADF subtree in `attrs.parameters.nestedContent`
|
|
18
|
+
* instead of in their node content — Confluence does this when it coerces nesting the schema
|
|
19
|
+
* cannot represent (an expand more than two collapsible layers deep, say). Such a node is a
|
|
20
|
+
* ProseMirror leaf, so the model walk cannot see the subtree even though it renders on the page
|
|
21
|
+
* via a nested renderer. Recurses, because nestedContent routinely holds further nested content.
|
|
22
|
+
*/
|
|
23
|
+
var _adfEntityText = function adfEntityText(entity) {
|
|
24
|
+
var _entity$attrs, _entity$content;
|
|
25
|
+
if (!entity) {
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
var parts = [];
|
|
29
|
+
if (entity.type === 'text') {
|
|
30
|
+
parts.push(asText(entity.text));
|
|
31
|
+
}
|
|
32
|
+
var nestedContent = (_entity$attrs = entity.attrs) === null || _entity$attrs === void 0 || (_entity$attrs = _entity$attrs.parameters) === null || _entity$attrs === void 0 ? void 0 : _entity$attrs.nestedContent;
|
|
33
|
+
if (nestedContent) {
|
|
34
|
+
// Prefer the real subtree over `attrs.text`, which is only a placeholder label for it.
|
|
35
|
+
parts.push(_adfEntityText(nestedContent));
|
|
36
|
+
} else {
|
|
37
|
+
var _entity$attrs2;
|
|
38
|
+
parts.push(asText((_entity$attrs2 = entity.attrs) === null || _entity$attrs2 === void 0 ? void 0 : _entity$attrs2.text));
|
|
39
|
+
}
|
|
40
|
+
(_entity$content = entity.content) === null || _entity$content === void 0 || _entity$content.forEach(function (child) {
|
|
41
|
+
return parts.push(_adfEntityText(child));
|
|
42
|
+
});
|
|
43
|
+
return parts.filter(Boolean).join(BLOCK_SEPARATOR);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* `textBetween` drops every non-text leaf unless the node spec declares `leafText`, and no ADF
|
|
48
|
+
* node does. Leaves carry their visible text in attrs, so recover it here.
|
|
49
|
+
*/
|
|
50
|
+
var leafText = function leafText(leaf) {
|
|
51
|
+
var _leaf$attrs, _leaf$attrs2;
|
|
52
|
+
var nestedContent = (_leaf$attrs = leaf.attrs) === null || _leaf$attrs === void 0 || (_leaf$attrs = _leaf$attrs.parameters) === null || _leaf$attrs === void 0 ? void 0 : _leaf$attrs.nestedContent;
|
|
53
|
+
if (nestedContent) {
|
|
54
|
+
return _adfEntityText(nestedContent);
|
|
55
|
+
}
|
|
56
|
+
return asText((_leaf$attrs2 = leaf.attrs) === null || _leaf$attrs2 === void 0 ? void 0 : _leaf$attrs2.text);
|
|
57
|
+
};
|
|
58
|
+
var hasInlineComment = function hasInlineComment(node) {
|
|
59
|
+
return findChildrenByMark(node, node.type.schema.marks.annotation, true).some(function (annotation) {
|
|
60
|
+
return annotation.node.marks.some(function (mark) {
|
|
61
|
+
return mark.attrs.annotationType === 'inlineComment';
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** `null` is a cached "no mirror for this node", as distinct from `undefined` for a cache miss. */
|
|
67
|
+
var searchTextCache = new WeakMap();
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Plain-text mirror of an expand's body, rendered in its place while collapsed so browser
|
|
71
|
+
* find-in-page can still reach the content.
|
|
72
|
+
*
|
|
73
|
+
* Cached on the node. ProseMirror nodes are immutable and `render-document` memoises
|
|
74
|
+
* `nodeFromJSON`, so the same node instance is reused across renders — including across the
|
|
75
|
+
* serializer rebuilds that invalidate the module-level `memoizeOne` caches.
|
|
76
|
+
*
|
|
77
|
+
* @returns the mirror text, or `undefined` if this expand must keep its body rendered.
|
|
78
|
+
*/
|
|
79
|
+
export var getExpandSearchText = function getExpandSearchText(node) {
|
|
80
|
+
var cached = searchTextCache.get(node);
|
|
81
|
+
if (cached === undefined) {
|
|
82
|
+
cached = hasInlineComment(node) ?
|
|
83
|
+
// Withhold the mirror, which makes Expand keep rendering `children`. Comment
|
|
84
|
+
// navigation walks the DOM to find the annotated node and scrolls it into view, so
|
|
85
|
+
// the annotation has to exist as a real element — a flat text mirror carries no
|
|
86
|
+
// annotation marks and cannot stand in for it. Without this, stepping through
|
|
87
|
+
// comments with the arrow keys silently fails to reach any comment inside a
|
|
88
|
+
// collapsed expand. Costs the lazy-load win for these expands, deliberately.
|
|
89
|
+
null : node.textBetween(0, node.content.size, BLOCK_SEPARATOR, leafText);
|
|
90
|
+
searchTextCache.set(node, cached);
|
|
91
|
+
}
|
|
92
|
+
return cached !== null && cached !== void 0 ? cached : undefined;
|
|
93
|
+
};
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
3
|
import type { WithIntlProps, WrappedComponentProps } from 'react-intl';
|
|
3
4
|
import type { AnalyticsEventPayload } from '../analytics/events';
|
|
4
5
|
import type { RendererAppearance, RendererContentMode } from './Renderer/types';
|
|
5
6
|
export interface ExpandProps {
|
|
6
7
|
children: React.ReactNode;
|
|
7
8
|
fireAnalyticsEvent?: (event: AnalyticsEventPayload) => void;
|
|
8
|
-
loadBodyContent?: boolean;
|
|
9
9
|
localId?: string;
|
|
10
10
|
nestedHeaderIds?: Array<string>;
|
|
11
|
+
/**
|
|
12
|
+
* This expand's ProseMirror node. Supplying it opts the expand into lazy body loading: until the
|
|
13
|
+
* expand is first opened, a plain-text mirror of the body is rendered in place of `children`.
|
|
14
|
+
* Once opened, `children` stay mounted for the rest of the page's life, including after the
|
|
15
|
+
* expand is collapsed again (PGXT-9021). Omit it to keep `children` in the DOM at all times.
|
|
16
|
+
*/
|
|
17
|
+
node?: PMNode;
|
|
11
18
|
nodeType: 'expand' | 'nestedExpand';
|
|
12
19
|
rendererAppearance?: RendererAppearance;
|
|
13
20
|
rendererContentMode?: RendererContentMode;
|
|
14
|
-
searchText?: string;
|
|
15
21
|
title: string;
|
|
16
22
|
}
|
|
17
23
|
declare const _default_1: React.FC<WithIntlProps<ExpandProps & WrappedComponentProps>> & {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
/**
|
|
3
|
+
* Plain-text mirror of an expand's body, rendered in its place while collapsed so browser
|
|
4
|
+
* find-in-page can still reach the content.
|
|
5
|
+
*
|
|
6
|
+
* Cached on the node. ProseMirror nodes are immutable and `render-document` memoises
|
|
7
|
+
* `nodeFromJSON`, so the same node instance is reused across renders — including across the
|
|
8
|
+
* serializer rebuilds that invalidate the module-level `memoizeOne` caches.
|
|
9
|
+
*
|
|
10
|
+
* @returns the mirror text, or `undefined` if this expand must keep its body rendered.
|
|
11
|
+
*/
|
|
12
|
+
export declare const getExpandSearchText: (node: PMNode) => string | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/renderer",
|
|
3
|
-
"version": "137.1.
|
|
3
|
+
"version": "137.1.4",
|
|
4
4
|
"description": "Renderer component",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@atlaskit/button": "^25.2.0",
|
|
41
41
|
"@atlaskit/code": "^19.1.0",
|
|
42
42
|
"@atlaskit/css": "^1.0.0",
|
|
43
|
-
"@atlaskit/editor-card-provider": "^7.
|
|
43
|
+
"@atlaskit/editor-card-provider": "^7.2.0",
|
|
44
44
|
"@atlaskit/editor-json-transformer": "^9.6.0",
|
|
45
45
|
"@atlaskit/editor-palette": "^3.4.0",
|
|
46
46
|
"@atlaskit/editor-prosemirror": "^8.0.0",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"uuid": "^3.1.0"
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
|
-
"@atlaskit/editor-common": "^120.
|
|
88
|
+
"@atlaskit/editor-common": "^120.3.0",
|
|
89
89
|
"@atlaskit/link-provider": "^5.4.0",
|
|
90
90
|
"@atlaskit/media-core": "^38.0.0",
|
|
91
91
|
"react": "^18.2.0",
|
|
@@ -252,9 +252,6 @@
|
|
|
252
252
|
"type": "boolean",
|
|
253
253
|
"referenceOnly": true
|
|
254
254
|
},
|
|
255
|
-
"platform_editor_video_caption_commit": {
|
|
256
|
-
"type": "boolean"
|
|
257
|
-
},
|
|
258
255
|
"platform-dst-lozenge-tag-badge-visual-uplifts": {
|
|
259
256
|
"type": "boolean"
|
|
260
257
|
},
|