@atlaskit/editor-plugin-placeholder 12.0.33 → 12.0.35

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.
@@ -1,171 +0,0 @@
1
- import { placeholderTextMessages as messages } from '@atlaskit/editor-common/messages';
2
- import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
3
- import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
4
- import { nodeTypesWithMultiBodiedExtensionPlaceholderText, placeholderTestId } from './constants';
5
- var isMultiBodiedExtensionPlaceholderEnabled = function isMultiBodiedExtensionPlaceholderEnabled() {
6
- return expValEquals('confluence_native_tabs_experiment', 'isEnabled', true);
7
- };
8
-
9
- // Empty MBE bodies are represented as extensionFrame -> empty paragraph.
10
- // The paragraph gives the cursor a valid textblock, but there is no authored content yet.
11
- var isEmptyExtensionFrame = function isEmptyExtensionFrame(node) {
12
- var _node$firstChild, _node$firstChild2;
13
- return nodeTypesWithMultiBodiedExtensionPlaceholderText.includes(node.type.name) && node.childCount === 1 && ((_node$firstChild = node.firstChild) === null || _node$firstChild === void 0 ? void 0 : _node$firstChild.content.size) === 0 && ((_node$firstChild2 = node.firstChild) === null || _node$firstChild2 === void 0 ? void 0 : _node$firstChild2.type.name) === 'paragraph';
14
- };
15
-
16
- // Keep this generic for any MBE extension by checking the node shape rather
17
- // than a product-specific extensionKey.
18
- var isExtensionFrameInMultiBodiedExtension = function isExtensionFrameInMultiBodiedExtension(node, parent) {
19
- return nodeTypesWithMultiBodiedExtensionPlaceholderText.includes(node.type.name) && (parent === null || parent === void 0 ? void 0 : parent.type.name) === 'multiBodiedExtension';
20
- };
21
- var isEmptyExtensionFrameInMultiBodiedExtension = function isEmptyExtensionFrameInMultiBodiedExtension(node, parent) {
22
- return isExtensionFrameInMultiBodiedExtension(node, parent) && isEmptyExtensionFrame(node);
23
- };
24
-
25
- // Widget decorations render UI without adding real content to the document.
26
- var createMultiBodiedExtensionPlaceholderElement = function createMultiBodiedExtensionPlaceholderElement(intl) {
27
- var placeholderDecoration = document.createElement('span');
28
- placeholderDecoration.setAttribute('data-testid', placeholderTestId);
29
- placeholderDecoration.className = 'placeholder-decoration';
30
- placeholderDecoration.setAttribute('aria-hidden', 'true');
31
- placeholderDecoration.textContent = intl.formatMessage(messages.multiBodiedExtensionPlaceholderText);
32
- return placeholderDecoration;
33
- };
34
-
35
- // `pos` is before extensionFrame; `pos + 2` is inside its paragraph, where
36
- // typing starts and where the placeholder should render.
37
- var createMultiBodiedExtensionPlaceholderDecoration = function createMultiBodiedExtensionPlaceholderDecoration(pos, intl) {
38
- return Decoration.widget(pos + 2, function () {
39
- return createMultiBodiedExtensionPlaceholderElement(intl);
40
- }, {
41
- side: 0,
42
- key: "multi-bodied-extension-placeholder-".concat(pos)
43
- });
44
- };
45
- // Convert changed step ranges into final-document positions. A transaction can
46
- // contain multiple steps, and each step can shift positions for later steps.
47
- var getChangedRanges = function getChangedRanges(tr) {
48
- var ranges = [];
49
- tr.mapping.maps.forEach(function (stepMap, index) {
50
- stepMap.forEach(function (_oldStart, _oldEnd, newStart, newEnd) {
51
- var mappingAfterStep = tr.mapping.slice(index + 1);
52
- ranges.push({
53
- from: mappingAfterStep.map(newStart, -1),
54
- to: mappingAfterStep.map(newEnd, 1)
55
- });
56
- });
57
- });
58
- return ranges;
59
- };
60
-
61
- // Walk from a changed position up to its containing MBE frame. The frame may no
62
- // longer be empty after the change, but we still need its range to remove stale decorations.
63
- var getMultiBodiedExtensionFrameRange = function getMultiBodiedExtensionFrameRange(doc, pos) {
64
- var resolvedPos = doc.resolve(Math.max(0, Math.min(pos, doc.content.size)));
65
- for (var depth = resolvedPos.depth; depth > 0; depth--) {
66
- var node = resolvedPos.node(depth);
67
- var parent = depth > 0 ? resolvedPos.node(depth - 1) : undefined;
68
- if (isExtensionFrameInMultiBodiedExtension(node, parent)) {
69
- return {
70
- from: resolvedPos.before(depth),
71
- to: resolvedPos.after(depth)
72
- };
73
- }
74
- }
75
- return;
76
- };
77
-
78
- // Resolve just inside a frame to recover its parent; `doc.nodeAt(framePos)` only
79
- // gives the frame node itself.
80
- var getMultiBodiedExtensionFrameParent = function getMultiBodiedExtensionFrameParent(doc, framePos) {
81
- var resolvedPos = doc.resolve(Math.max(0, Math.min(framePos + 1, doc.content.size)));
82
- for (var depth = resolvedPos.depth; depth > 0; depth--) {
83
- if (resolvedPos.before(depth) === framePos) {
84
- return resolvedPos.node(depth - 1);
85
- }
86
- }
87
- return;
88
- };
89
-
90
- // Only update MBE frames touched by this transaction: either the change happened
91
- // inside a frame, or the transaction inserted/replaced an empty frame.
92
- var getAffectedMultiBodiedExtensionFrameRanges = function getAffectedMultiBodiedExtensionFrameRanges(doc, ranges) {
93
- var affectedRanges = new Map();
94
- ranges.forEach(function (_ref) {
95
- var from = _ref.from,
96
- to = _ref.to;
97
- [from, to].forEach(function (pos) {
98
- var multiBodiedExtensionFrameRange = getMultiBodiedExtensionFrameRange(doc, pos);
99
- if (multiBodiedExtensionFrameRange) {
100
- affectedRanges.set("".concat(multiBodiedExtensionFrameRange.from, "-").concat(multiBodiedExtensionFrameRange.to), multiBodiedExtensionFrameRange);
101
- }
102
- });
103
- doc.nodesBetween(from, to, function (node, pos, parent) {
104
- if (isEmptyExtensionFrameInMultiBodiedExtension(node, parent)) {
105
- var multiBodiedExtensionFrameRange = {
106
- from: pos,
107
- to: pos + node.nodeSize
108
- };
109
- affectedRanges.set("".concat(multiBodiedExtensionFrameRange.from, "-").concat(multiBodiedExtensionFrameRange.to), multiBodiedExtensionFrameRange);
110
- return false;
111
- }
112
- return true;
113
- });
114
- });
115
- return Array.from(affectedRanges.values());
116
- };
117
-
118
- // Initial creation scans the full document once. Later updates use affected
119
- // ranges, and inactive tab frames stay hidden by the MBE renderer.
120
- export function createMultiBodiedExtensionPlaceholderDecorations(editorState, intl) {
121
- if (!isMultiBodiedExtensionPlaceholderEnabled()) {
122
- return;
123
- }
124
- var decorations = [];
125
- editorState.doc.descendants(function (node, pos, parent) {
126
- if (isEmptyExtensionFrameInMultiBodiedExtension(node, parent)) {
127
- decorations.push(createMultiBodiedExtensionPlaceholderDecoration(pos, intl));
128
- return false;
129
- }
130
- return true;
131
- });
132
- return decorations.length > 0 ? DecorationSet.create(editorState.doc, decorations) : DecorationSet.empty;
133
- }
134
- export function updateMultiBodiedExtensionPlaceholderDecorations(_ref2) {
135
- var currentDecorationSet = _ref2.currentDecorationSet,
136
- intl = _ref2.intl,
137
- newEditorState = _ref2.newEditorState,
138
- tr = _ref2.tr;
139
- if (!isMultiBodiedExtensionPlaceholderEnabled()) {
140
- return;
141
- }
142
- if (!currentDecorationSet) {
143
- return createMultiBodiedExtensionPlaceholderDecorations(newEditorState, intl);
144
- }
145
-
146
- // No document change means no empty/non-empty frame state change; remap
147
- // existing decorations only if ProseMirror reports positional mapping.
148
- if (!tr.docChanged) {
149
- return tr.mapping.maps.length > 0 ? currentDecorationSet.map(tr.mapping, newEditorState.doc) : currentDecorationSet;
150
- }
151
- var mappedDecorationSet = currentDecorationSet.map(tr.mapping, newEditorState.doc);
152
- var affectedRanges = getAffectedMultiBodiedExtensionFrameRanges(newEditorState.doc, getChangedRanges(tr));
153
- if (affectedRanges.length === 0) {
154
- return mappedDecorationSet;
155
- }
156
-
157
- // Remove placeholders in affected frames, then re-add only for frames that
158
- // still have the empty extensionFrame -> paragraph shape.
159
- var decorationsToRemove = affectedRanges.flatMap(function (_ref3) {
160
- var from = _ref3.from,
161
- to = _ref3.to;
162
- return mappedDecorationSet.find(from, to);
163
- });
164
- var decorationsToAdd = affectedRanges.flatMap(function (_ref4) {
165
- var from = _ref4.from;
166
- var node = newEditorState.doc.nodeAt(from);
167
- var parent = getMultiBodiedExtensionFrameParent(newEditorState.doc, from);
168
- return node && isEmptyExtensionFrameInMultiBodiedExtension(node, parent) ? [createMultiBodiedExtensionPlaceholderDecoration(from, intl)] : [];
169
- });
170
- return mappedDecorationSet.remove(decorationsToRemove).add(newEditorState.doc, decorationsToAdd);
171
- }
@@ -1,125 +0,0 @@
1
- import { placeholderTextMessages as messages } from '@atlaskit/editor-common/messages';
2
- import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
3
- import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
4
- import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
5
- import { nodeTypesWithSyncBlockPlaceholderText, placeholderTestId } from './constants';
6
- var isEmptySourceSyncBlock = function isEmptySourceSyncBlock(node) {
7
- var _node$firstChild, _node$firstChild2;
8
- return nodeTypesWithSyncBlockPlaceholderText.includes(node.type.name) && node.childCount === 1 && ((_node$firstChild = node.firstChild) === null || _node$firstChild === void 0 ? void 0 : _node$firstChild.content.size) === 0 && ((_node$firstChild2 = node.firstChild) === null || _node$firstChild2 === void 0 ? void 0 : _node$firstChild2.type.name) === 'paragraph';
9
- };
10
- var createSourceSyncBlockPlaceholderElement = function createSourceSyncBlockPlaceholderElement(intl) {
11
- var placeholderDecoration = document.createElement('span');
12
- placeholderDecoration.setAttribute('data-testid', placeholderTestId);
13
- placeholderDecoration.className = 'placeholder-decoration';
14
- placeholderDecoration.setAttribute('aria-hidden', 'true');
15
- placeholderDecoration.textContent = intl.formatMessage(messages.sourceSyncBlockPlaceholderText);
16
- return placeholderDecoration;
17
- };
18
- var createSourceSyncBlockPlaceholderDecoration = function createSourceSyncBlockPlaceholderDecoration(pos, intl) {
19
- return Decoration.widget(pos + 2, function () {
20
- return createSourceSyncBlockPlaceholderElement(intl);
21
- }, {
22
- side: 0,
23
- key: "source-sync-block-placeholder-".concat(pos)
24
- });
25
- };
26
- var isSourceSyncBlockPlaceholderEnabled = function isSourceSyncBlockPlaceholderEnabled() {
27
- return expValEquals('platform_editor_sync_block_activation', 'isEnabled', true) && editorExperiment('platform_synced_block', true);
28
- };
29
- var getChangedRanges = function getChangedRanges(tr) {
30
- var ranges = [];
31
- tr.mapping.maps.forEach(function (stepMap, index) {
32
- stepMap.forEach(function (_oldStart, _oldEnd, newStart, newEnd) {
33
- var mappingAfterStep = tr.mapping.slice(index + 1);
34
- ranges.push({
35
- from: mappingAfterStep.map(newStart, -1),
36
- to: mappingAfterStep.map(newEnd, 1)
37
- });
38
- });
39
- });
40
- return ranges;
41
- };
42
- var getSourceSyncBlockRange = function getSourceSyncBlockRange(doc, pos) {
43
- var resolvedPos = doc.resolve(Math.max(0, Math.min(pos, doc.content.size)));
44
- for (var depth = resolvedPos.depth; depth > 0; depth--) {
45
- var node = resolvedPos.node(depth);
46
- if (nodeTypesWithSyncBlockPlaceholderText.includes(node.type.name)) {
47
- return {
48
- from: resolvedPos.before(depth),
49
- to: resolvedPos.after(depth)
50
- };
51
- }
52
- }
53
- return;
54
- };
55
- var getAffectedSourceSyncBlockRanges = function getAffectedSourceSyncBlockRanges(doc, ranges) {
56
- var affectedRanges = new Map();
57
- ranges.forEach(function (_ref) {
58
- var from = _ref.from,
59
- to = _ref.to;
60
- [from, to].forEach(function (pos) {
61
- var sourceSyncBlockRange = getSourceSyncBlockRange(doc, pos);
62
- if (sourceSyncBlockRange) {
63
- affectedRanges.set("".concat(sourceSyncBlockRange.from, "-").concat(sourceSyncBlockRange.to), sourceSyncBlockRange);
64
- }
65
- });
66
- doc.nodesBetween(from, to, function (node, pos) {
67
- if (nodeTypesWithSyncBlockPlaceholderText.includes(node.type.name)) {
68
- var sourceSyncBlockRange = {
69
- from: pos,
70
- to: pos + node.nodeSize
71
- };
72
- affectedRanges.set("".concat(sourceSyncBlockRange.from, "-").concat(sourceSyncBlockRange.to), sourceSyncBlockRange);
73
- return false;
74
- }
75
- return true;
76
- });
77
- });
78
- return Array.from(affectedRanges.values());
79
- };
80
- export function createSourceSyncBlockPlaceholderDecorations(editorState, intl) {
81
- if (!isSourceSyncBlockPlaceholderEnabled()) {
82
- return;
83
- }
84
- var decorations = [];
85
- editorState.doc.descendants(function (node, pos) {
86
- if (isEmptySourceSyncBlock(node)) {
87
- decorations.push(createSourceSyncBlockPlaceholderDecoration(pos, intl));
88
- return false;
89
- }
90
- return true;
91
- });
92
- return decorations.length > 0 ? DecorationSet.create(editorState.doc, decorations) : DecorationSet.empty;
93
- }
94
- export function updateSourceSyncBlockPlaceholderDecorations(_ref2) {
95
- var currentDecorationSet = _ref2.currentDecorationSet,
96
- intl = _ref2.intl,
97
- newEditorState = _ref2.newEditorState,
98
- oldEditorState = _ref2.oldEditorState,
99
- tr = _ref2.tr;
100
- if (!isSourceSyncBlockPlaceholderEnabled()) {
101
- return;
102
- }
103
- if (!currentDecorationSet) {
104
- return createSourceSyncBlockPlaceholderDecorations(newEditorState, intl);
105
- }
106
- if (!tr.docChanged) {
107
- return tr.mapping.maps.length > 0 ? currentDecorationSet.map(tr.mapping, newEditorState.doc) : currentDecorationSet;
108
- }
109
- var mappedDecorationSet = currentDecorationSet.map(tr.mapping, newEditorState.doc);
110
- var affectedRanges = getAffectedSourceSyncBlockRanges(newEditorState.doc, getChangedRanges(tr));
111
- if (affectedRanges.length === 0) {
112
- return mappedDecorationSet;
113
- }
114
- var decorationsToRemove = affectedRanges.flatMap(function (_ref3) {
115
- var from = _ref3.from,
116
- to = _ref3.to;
117
- return mappedDecorationSet.find(from, to);
118
- });
119
- var decorationsToAdd = affectedRanges.flatMap(function (_ref4) {
120
- var from = _ref4.from;
121
- var node = newEditorState.doc.nodeAt(from);
122
- return node && isEmptySourceSyncBlock(node) ? [createSourceSyncBlockPlaceholderDecoration(from, intl)] : [];
123
- });
124
- return mappedDecorationSet.remove(decorationsToRemove).add(newEditorState.doc, decorationsToAdd);
125
- }
@@ -1,16 +0,0 @@
1
- import type { IntlShape } from 'react-intl';
2
- import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
- import type { Mapping } from '@atlaskit/editor-prosemirror/transform';
4
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
5
- type MultiBodiedExtensionPlaceholderTransaction = {
6
- docChanged: boolean;
7
- mapping: Mapping;
8
- };
9
- export declare function createMultiBodiedExtensionPlaceholderDecorations(editorState: EditorState, intl: IntlShape): DecorationSet | undefined;
10
- export declare function updateMultiBodiedExtensionPlaceholderDecorations({ currentDecorationSet, intl, newEditorState, tr, }: {
11
- currentDecorationSet?: DecorationSet;
12
- intl: IntlShape;
13
- newEditorState: EditorState;
14
- tr: MultiBodiedExtensionPlaceholderTransaction;
15
- }): DecorationSet | undefined;
16
- export {};
@@ -1,17 +0,0 @@
1
- import type { IntlShape } from 'react-intl';
2
- import type { EditorState } from '@atlaskit/editor-prosemirror/state';
3
- import type { Mapping } from '@atlaskit/editor-prosemirror/transform';
4
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
5
- type SourceSyncBlockPlaceholderTransaction = {
6
- mapping: Mapping;
7
- docChanged: boolean;
8
- };
9
- export declare function createSourceSyncBlockPlaceholderDecorations(editorState: EditorState, intl: IntlShape): DecorationSet | undefined;
10
- export declare function updateSourceSyncBlockPlaceholderDecorations({ currentDecorationSet, intl, newEditorState, oldEditorState, tr, }: {
11
- currentDecorationSet?: DecorationSet;
12
- intl: IntlShape;
13
- newEditorState: EditorState;
14
- oldEditorState: EditorState;
15
- tr: SourceSyncBlockPlaceholderTransaction;
16
- }): DecorationSet | undefined;
17
- export {};