@atlaskit/editor-plugin-block-controls 20.0.3 → 20.1.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 +19 -0
- package/dist/cjs/blockControlsPlugin.js +53 -17
- package/dist/cjs/editor-commands/show-drag-handle.js +17 -5
- package/dist/cjs/pm-plugins/decorations-anchor.js +2 -1
- package/dist/cjs/pm-plugins/decorations-drop-target-active.js +2 -1
- package/dist/cjs/pm-plugins/decorations-drop-target.js +2 -1
- package/dist/cjs/pm-plugins/decorations-surface-anchor.js +72 -0
- package/dist/cjs/pm-plugins/handle-mouse-down.js +2 -1
- package/dist/cjs/pm-plugins/handle-mouse-over.js +3 -2
- package/dist/cjs/pm-plugins/handle-sparse-mouse-over.js +125 -0
- package/dist/cjs/pm-plugins/main.js +66 -54
- package/dist/cjs/pm-plugins/sparse-surfaces.js +49 -0
- package/dist/cjs/pm-plugins/utils/sparse-surface-candidates.js +419 -0
- package/dist/cjs/pm-plugins/utils/sparse-surfaces-mapping.js +108 -0
- package/dist/cjs/pm-plugins/utils/sparse-surfaces-state.js +53 -0
- package/dist/cjs/pm-plugins/utils/sparse-surfaces-view.js +134 -0
- package/dist/cjs/pm-plugins/utils/surface-viewport.js +223 -0
- package/dist/cjs/pm-plugins/utils/transactions.js +5 -0
- package/dist/cjs/ui/block-controls-left-surfaces.js +31 -25
- package/dist/cjs/ui/block-controls-right-surfaces.js +31 -25
- package/dist/cjs/ui/block-controls-surface-context.js +1 -0
- package/dist/cjs/ui/block-controls-surface-drag-handle-registration.js +6 -7
- package/dist/cjs/ui/block-controls-surface-drag-handle.js +6 -2
- package/dist/cjs/ui/drag-handle.js +5 -3
- package/dist/cjs/ui/drop-target-layout.js +3 -2
- package/dist/cjs/ui/drop-target.js +3 -2
- package/dist/cjs/ui/global-styles.js +69 -27
- package/dist/cjs/ui/inline-drop-target.js +6 -5
- package/dist/cjs/ui/utils/anchor-name.js +2 -1
- package/dist/cjs/ui/utils/dom-attr-name.js +3 -2
- package/dist/cjs/ui/utils/get-surface-placement.js +2 -1
- package/dist/es2019/blockControlsPlugin.js +42 -8
- package/dist/es2019/editor-commands/show-drag-handle.js +14 -2
- package/dist/es2019/pm-plugins/decorations-anchor.js +2 -1
- package/dist/es2019/pm-plugins/decorations-drop-target-active.js +2 -1
- package/dist/es2019/pm-plugins/decorations-drop-target.js +2 -1
- package/dist/es2019/pm-plugins/decorations-surface-anchor.js +56 -0
- package/dist/es2019/pm-plugins/handle-mouse-down.js +2 -1
- package/dist/es2019/pm-plugins/handle-mouse-over.js +3 -2
- package/dist/es2019/pm-plugins/handle-sparse-mouse-over.js +116 -0
- package/dist/es2019/pm-plugins/main.js +70 -54
- package/dist/es2019/pm-plugins/sparse-surfaces.js +37 -0
- package/dist/es2019/pm-plugins/utils/sparse-surface-candidates.js +305 -0
- package/dist/es2019/pm-plugins/utils/sparse-surfaces-mapping.js +78 -0
- package/dist/es2019/pm-plugins/utils/sparse-surfaces-state.js +39 -0
- package/dist/es2019/pm-plugins/utils/sparse-surfaces-view.js +121 -0
- package/dist/es2019/pm-plugins/utils/surface-viewport.js +192 -0
- package/dist/es2019/pm-plugins/utils/transactions.js +5 -0
- package/dist/es2019/ui/block-controls-left-surfaces.js +21 -14
- package/dist/es2019/ui/block-controls-right-surfaces.js +21 -14
- package/dist/es2019/ui/block-controls-surface-context.js +1 -0
- package/dist/es2019/ui/block-controls-surface-drag-handle-registration.js +4 -5
- package/dist/es2019/ui/block-controls-surface-drag-handle.js +6 -2
- package/dist/es2019/ui/drag-handle.js +5 -3
- package/dist/es2019/ui/drop-target-layout.js +3 -2
- package/dist/es2019/ui/drop-target.js +3 -2
- package/dist/es2019/ui/global-styles.js +67 -28
- package/dist/es2019/ui/inline-drop-target.js +6 -5
- package/dist/es2019/ui/utils/anchor-name.js +2 -1
- package/dist/es2019/ui/utils/dom-attr-name.js +3 -2
- package/dist/es2019/ui/utils/get-surface-placement.js +2 -1
- package/dist/esm/blockControlsPlugin.js +53 -17
- package/dist/esm/editor-commands/show-drag-handle.js +17 -5
- package/dist/esm/pm-plugins/decorations-anchor.js +2 -1
- package/dist/esm/pm-plugins/decorations-drop-target-active.js +2 -1
- package/dist/esm/pm-plugins/decorations-drop-target.js +2 -1
- package/dist/esm/pm-plugins/decorations-surface-anchor.js +65 -0
- package/dist/esm/pm-plugins/handle-mouse-down.js +2 -1
- package/dist/esm/pm-plugins/handle-mouse-over.js +3 -2
- package/dist/esm/pm-plugins/handle-sparse-mouse-over.js +119 -0
- package/dist/esm/pm-plugins/main.js +66 -54
- package/dist/esm/pm-plugins/sparse-surfaces.js +43 -0
- package/dist/esm/pm-plugins/utils/sparse-surface-candidates.js +413 -0
- package/dist/esm/pm-plugins/utils/sparse-surfaces-mapping.js +101 -0
- package/dist/esm/pm-plugins/utils/sparse-surfaces-state.js +46 -0
- package/dist/esm/pm-plugins/utils/sparse-surfaces-view.js +127 -0
- package/dist/esm/pm-plugins/utils/surface-viewport.js +217 -0
- package/dist/esm/pm-plugins/utils/transactions.js +5 -0
- package/dist/esm/ui/block-controls-left-surfaces.js +33 -27
- package/dist/esm/ui/block-controls-right-surfaces.js +33 -27
- package/dist/esm/ui/block-controls-surface-context.js +1 -0
- package/dist/esm/ui/block-controls-surface-drag-handle-registration.js +7 -8
- package/dist/esm/ui/block-controls-surface-drag-handle.js +6 -2
- package/dist/esm/ui/drag-handle.js +5 -3
- package/dist/esm/ui/drop-target-layout.js +3 -2
- package/dist/esm/ui/drop-target.js +3 -2
- package/dist/esm/ui/global-styles.js +70 -28
- package/dist/esm/ui/inline-drop-target.js +6 -5
- package/dist/esm/ui/utils/anchor-name.js +2 -1
- package/dist/esm/ui/utils/dom-attr-name.js +3 -2
- package/dist/esm/ui/utils/get-surface-placement.js +2 -1
- package/dist/types/blockControlsPluginType.d.ts +10 -3
- package/dist/types/pm-plugins/decorations-surface-anchor.d.ts +22 -0
- package/dist/types/pm-plugins/handle-sparse-mouse-over.d.ts +5 -0
- package/dist/types/pm-plugins/main.d.ts +2 -9
- package/dist/types/pm-plugins/sparse-surfaces.d.ts +8 -0
- package/dist/types/pm-plugins/utils/sparse-surface-candidates.d.ts +89 -0
- package/dist/types/pm-plugins/utils/sparse-surfaces-mapping.d.ts +20 -0
- package/dist/types/pm-plugins/utils/sparse-surfaces-state.d.ts +27 -0
- package/dist/types/pm-plugins/utils/sparse-surfaces-view.d.ts +15 -0
- package/dist/types/pm-plugins/utils/surface-viewport.d.ts +10 -0
- package/dist/types/ui/utils/get-surface-placement.d.ts +3 -2
- package/package.json +5 -5
- package/dist/cjs/pm-plugins/utils/surface-node-positions.js +0 -100
- package/dist/es2019/pm-plugins/utils/surface-node-positions.js +0 -78
- package/dist/esm/pm-plugins/utils/surface-node-positions.js +0 -93
- package/dist/types/pm-plugins/utils/surface-node-positions.d.ts +0 -14
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
|
+
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; }
|
|
5
|
+
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) { _defineProperty(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; }
|
|
6
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
7
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
8
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
9
|
+
import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls/block-control-ui-context';
|
|
10
|
+
import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/create-surface-context';
|
|
11
|
+
import { willComponentRender } from '@atlaskit/editor-ui-control-model/surface-renderer';
|
|
12
|
+
import { createBlockControlsSurfaceContextForPosition } from '../../ui/block-controls-surface-context';
|
|
13
|
+
import { hasSurfaceControls } from '../../ui/utils/has-surface-controls';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Viewport positions are post-transaction positions supplied by the DOM observer. The reducer
|
|
17
|
+
* never needs to inspect DOM or search document IDs for viewport discovery.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
var NO_ACTIVE = 'none';
|
|
21
|
+
var EMPTY_CANDIDATES = new Map();
|
|
22
|
+
var EMPTY_POSITIONS = [];
|
|
23
|
+
var EMPTY_PROTECTED_POSITIONS = [];
|
|
24
|
+
export var emptySparseSurfaceCandidateState = {
|
|
25
|
+
activeRevision: NO_ACTIVE,
|
|
26
|
+
candidates: EMPTY_CANDIDATES,
|
|
27
|
+
positions: EMPTY_POSITIONS,
|
|
28
|
+
protectedPositions: EMPTY_PROTECTED_POSITIONS,
|
|
29
|
+
visiblePositions: EMPTY_POSITIONS
|
|
30
|
+
};
|
|
31
|
+
var getActiveRevision = function getActiveRevision(activeNode) {
|
|
32
|
+
var _activeNode$rootPos, _activeNode$rootNodeT;
|
|
33
|
+
return activeNode ? [activeNode.pos, activeNode.nodeType, (_activeNode$rootPos = activeNode.rootPos) !== null && _activeNode$rootPos !== void 0 ? _activeNode$rootPos : activeNode.pos, (_activeNode$rootNodeT = activeNode.rootNodeType) !== null && _activeNode$rootNodeT !== void 0 ? _activeNode$rootNodeT : ''].join(':') : NO_ACTIVE;
|
|
34
|
+
};
|
|
35
|
+
var isInRange = function isInRange(position, range) {
|
|
36
|
+
return position >= range.from && position <= range.to;
|
|
37
|
+
};
|
|
38
|
+
var normalizeRange = function normalizeRange(range, contentSize) {
|
|
39
|
+
return {
|
|
40
|
+
from: Math.max(0, Math.min(contentSize, Math.min(range.from, range.to))),
|
|
41
|
+
to: Math.max(0, Math.min(contentSize, Math.max(range.from, range.to)))
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
var getSurfaces = function getSurfaces(resolvedSurfaces) {
|
|
45
|
+
return resolvedSurfaces.flatMap(function (_ref) {
|
|
46
|
+
var childrenMap = _ref.childrenMap,
|
|
47
|
+
components = _ref.components,
|
|
48
|
+
root = _ref.root;
|
|
49
|
+
return root && hasSurfaceControls(components) ? [{
|
|
50
|
+
childrenMap: childrenMap,
|
|
51
|
+
root: root
|
|
52
|
+
}] : [];
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
var getNodeId = function getNodeId(node) {
|
|
56
|
+
var _node$attrs;
|
|
57
|
+
var localId = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.localId;
|
|
58
|
+
return typeof localId === 'string' ? localId : undefined;
|
|
59
|
+
};
|
|
60
|
+
var sameCandidate = function sameCandidate(first, second) {
|
|
61
|
+
return (first === null || first === void 0 ? void 0 : first.id) === (second === null || second === void 0 ? void 0 : second.id) && (first === null || first === void 0 ? void 0 : first.contextRevision) === (second === null || second === void 0 ? void 0 : second.contextRevision) && (first === null || first === void 0 ? void 0 : first.isPersistent) === (second === null || second === void 0 ? void 0 : second.isPersistent) && (first === null || first === void 0 ? void 0 : first.nodeRef) === (second === null || second === void 0 ? void 0 : second.nodeRef) && (first === null || first === void 0 ? void 0 : first.nodeType) === (second === null || second === void 0 ? void 0 : second.nodeType) && (first === null || first === void 0 ? void 0 : first.nodeSize) === (second === null || second === void 0 ? void 0 : second.nodeSize) && (first === null || first === void 0 ? void 0 : first.pos) === (second === null || second === void 0 ? void 0 : second.pos) && (first === null || first === void 0 ? void 0 : first.renders) === (second === null || second === void 0 ? void 0 : second.renders);
|
|
62
|
+
};
|
|
63
|
+
var sameCandidateMap = function sameCandidateMap(first, second) {
|
|
64
|
+
if (first.size !== second.size) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
var _iterator = _createForOfIteratorHelper(first),
|
|
68
|
+
_step;
|
|
69
|
+
try {
|
|
70
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
71
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
72
|
+
position = _step$value[0],
|
|
73
|
+
candidate = _step$value[1];
|
|
74
|
+
if (!sameCandidate(candidate, second.get(position))) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
} catch (err) {
|
|
79
|
+
_iterator.e(err);
|
|
80
|
+
} finally {
|
|
81
|
+
_iterator.f();
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
};
|
|
85
|
+
var samePositions = function samePositions(first, second) {
|
|
86
|
+
return first.length === second.length && first.every(function (position, index) {
|
|
87
|
+
return position === second[index];
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
var normalizePositions = function normalizePositions(positions) {
|
|
91
|
+
return Array.from(new Set(positions)).sort(function (first, second) {
|
|
92
|
+
return first - second;
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
var mapPositions = function mapPositions(positions, tr) {
|
|
96
|
+
return normalizePositions(positions.map(function (position) {
|
|
97
|
+
return tr.docChanged ? tr.mapping.mapResult(position, 1) : {
|
|
98
|
+
deleted: false,
|
|
99
|
+
pos: position
|
|
100
|
+
};
|
|
101
|
+
}).filter(function (result) {
|
|
102
|
+
return !result.deleted;
|
|
103
|
+
}).map(function (result) {
|
|
104
|
+
return result.pos;
|
|
105
|
+
}));
|
|
106
|
+
};
|
|
107
|
+
var createSurfaceContextAtPosition = function createSurfaceContextAtPosition(state, position, activeNode) {
|
|
108
|
+
var blockControlsContext = createBlockControlsSurfaceContextForPosition(state, position, activeNode);
|
|
109
|
+
return blockControlsContext ? createSurfaceContext(BLOCK_CONTROL_UI_CONTEXT, blockControlsContext) : undefined;
|
|
110
|
+
};
|
|
111
|
+
var willAnySurfaceRenderAt = function willAnySurfaceRenderAt(surfaces, state, position, activeNode) {
|
|
112
|
+
var surfaceContext = createSurfaceContextAtPosition(state, position, activeNode);
|
|
113
|
+
return surfaces.some(function (_ref2) {
|
|
114
|
+
var childrenMap = _ref2.childrenMap,
|
|
115
|
+
root = _ref2.root;
|
|
116
|
+
return willComponentRender(root, childrenMap, surfaceContext);
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
var addCandidateAt = function addCandidateAt(_ref3) {
|
|
120
|
+
var candidates = _ref3.candidates,
|
|
121
|
+
position = _ref3.position,
|
|
122
|
+
state = _ref3.state,
|
|
123
|
+
surfaces = _ref3.surfaces,
|
|
124
|
+
activeNode = _ref3.activeNode;
|
|
125
|
+
var node = state.doc.nodeAt(position);
|
|
126
|
+
if (!(node !== null && node !== void 0 && node.isBlock)) {
|
|
127
|
+
candidates.delete(position);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
var isPersistent = willAnySurfaceRenderAt(surfaces, state, position, undefined);
|
|
131
|
+
var renders = isPersistent || activeNode !== undefined && willAnySurfaceRenderAt(surfaces, state, position, activeNode);
|
|
132
|
+
candidates.set(position, {
|
|
133
|
+
contextRevision: getActiveRevision(activeNode),
|
|
134
|
+
id: getNodeId(node),
|
|
135
|
+
isPersistent: isPersistent,
|
|
136
|
+
nodeRef: node,
|
|
137
|
+
nodeType: node.type.name,
|
|
138
|
+
nodeSize: node.nodeSize,
|
|
139
|
+
renders: renders,
|
|
140
|
+
pos: position
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
var isInvalidated = function isInvalidated(candidate, position, invalidation, changedRange) {
|
|
144
|
+
var _invalidation$ids, _invalidation$positio, _invalidation$ranges;
|
|
145
|
+
if (invalidation !== null && invalidation !== void 0 && invalidation.all) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
if (invalidation !== null && invalidation !== void 0 && (_invalidation$ids = invalidation.ids) !== null && _invalidation$ids !== void 0 && _invalidation$ids.some(function (id) {
|
|
149
|
+
return id === candidate.id;
|
|
150
|
+
})) {
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
if (invalidation !== null && invalidation !== void 0 && (_invalidation$positio = invalidation.positions) !== null && _invalidation$positio !== void 0 && _invalidation$positio.includes(position)) {
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
return Boolean(changedRange && isInRange(position, changedRange) || (invalidation === null || invalidation === void 0 || (_invalidation$ranges = invalidation.ranges) === null || _invalidation$ranges === void 0 ? void 0 : _invalidation$ranges.some(function (range) {
|
|
157
|
+
return isInRange(position, range);
|
|
158
|
+
})));
|
|
159
|
+
};
|
|
160
|
+
var getPositions = function getPositions(candidates) {
|
|
161
|
+
return Array.from(candidates.values()).filter(function (candidate) {
|
|
162
|
+
return candidate.renders;
|
|
163
|
+
}).map(function (candidate) {
|
|
164
|
+
return candidate.pos;
|
|
165
|
+
}).sort(function (first, second) {
|
|
166
|
+
return first - second;
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
var mapCandidates = function mapCandidates(state, tr, retain) {
|
|
170
|
+
var mapped = new Map();
|
|
171
|
+
var _iterator2 = _createForOfIteratorHelper(state.candidates.values()),
|
|
172
|
+
_step2;
|
|
173
|
+
try {
|
|
174
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
175
|
+
var candidate = _step2.value;
|
|
176
|
+
var result = tr.docChanged ? tr.mapping.mapResult(candidate.pos, 1) : {
|
|
177
|
+
deleted: false,
|
|
178
|
+
pos: candidate.pos
|
|
179
|
+
};
|
|
180
|
+
if (!result.deleted && retain(result.pos, candidate)) {
|
|
181
|
+
mapped.set(result.pos, result.pos === candidate.pos ? candidate : _objectSpread(_objectSpread({}, candidate), {}, {
|
|
182
|
+
pos: result.pos
|
|
183
|
+
}));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
} catch (err) {
|
|
187
|
+
_iterator2.e(err);
|
|
188
|
+
} finally {
|
|
189
|
+
_iterator2.f();
|
|
190
|
+
}
|
|
191
|
+
return mapped;
|
|
192
|
+
};
|
|
193
|
+
/** Map cache state during PM apply. This phase never calls isHidden or scans doc. */
|
|
194
|
+
export var mapSparseSurfaceCandidates = function mapSparseSurfaceCandidates(_ref4) {
|
|
195
|
+
var newState = _ref4.newState,
|
|
196
|
+
previousState = _ref4.previousState,
|
|
197
|
+
tr = _ref4.tr;
|
|
198
|
+
if (!tr.docChanged) {
|
|
199
|
+
return previousState;
|
|
200
|
+
}
|
|
201
|
+
var candidates = new Map();
|
|
202
|
+
var _iterator3 = _createForOfIteratorHelper(previousState.candidates.values()),
|
|
203
|
+
_step3;
|
|
204
|
+
try {
|
|
205
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
206
|
+
var candidate = _step3.value;
|
|
207
|
+
var result = tr.mapping.mapResult(candidate.pos, 1);
|
|
208
|
+
if (!result.deleted) {
|
|
209
|
+
candidates.set(result.pos, result.pos === candidate.pos ? candidate : _objectSpread(_objectSpread({}, candidate), {}, {
|
|
210
|
+
pos: result.pos
|
|
211
|
+
}));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
} catch (err) {
|
|
215
|
+
_iterator3.e(err);
|
|
216
|
+
} finally {
|
|
217
|
+
_iterator3.f();
|
|
218
|
+
}
|
|
219
|
+
var protectedPositions = normalizePositions(previousState.protectedPositions.map(function (position) {
|
|
220
|
+
return tr.mapping.mapResult(position, 1);
|
|
221
|
+
}).filter(function (result) {
|
|
222
|
+
return !result.deleted;
|
|
223
|
+
}).map(function (result) {
|
|
224
|
+
return result.pos;
|
|
225
|
+
}));
|
|
226
|
+
var visiblePositions = mapPositions(previousState.visiblePositions, tr);
|
|
227
|
+
var positions = getPositions(candidates);
|
|
228
|
+
var candidatesUnchanged = sameCandidateMap(previousState.candidates, candidates);
|
|
229
|
+
var positionsUnchanged = samePositions(previousState.positions, positions);
|
|
230
|
+
var protectedUnchanged = samePositions(previousState.protectedPositions, protectedPositions);
|
|
231
|
+
if (candidatesUnchanged && positionsUnchanged && protectedUnchanged && samePositions(previousState.visiblePositions, visiblePositions)) {
|
|
232
|
+
return previousState;
|
|
233
|
+
}
|
|
234
|
+
return _objectSpread(_objectSpread({}, previousState), {}, {
|
|
235
|
+
candidates: candidatesUnchanged ? previousState.candidates : candidates,
|
|
236
|
+
positions: positionsUnchanged ? previousState.positions : positions,
|
|
237
|
+
protectedPositions: protectedUnchanged ? previousState.protectedPositions : protectedPositions,
|
|
238
|
+
visiblePositions: visiblePositions
|
|
239
|
+
});
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* Reconcile after view state is current. Predicate work stays bounded to cache,
|
|
243
|
+
* exact visible positions, explicit ranges, and protected active/menu positions.
|
|
244
|
+
*/
|
|
245
|
+
export var reconcileSparseSurfaceCandidates = function reconcileSparseSurfaceCandidates(_ref5) {
|
|
246
|
+
var activeNodesByPosition = _ref5.activeNodesByPosition,
|
|
247
|
+
activeNode = _ref5.activeNode,
|
|
248
|
+
changedRange = _ref5.changedRange,
|
|
249
|
+
_ref5$documentChanged = _ref5.documentChanged,
|
|
250
|
+
documentChanged = _ref5$documentChanged === void 0 ? false : _ref5$documentChanged,
|
|
251
|
+
invalidation = _ref5.invalidation,
|
|
252
|
+
newState = _ref5.newState,
|
|
253
|
+
protectedPositions = _ref5.protectedPositions,
|
|
254
|
+
resolvedSurfaces = _ref5.resolvedSurfaces,
|
|
255
|
+
state = _ref5.state,
|
|
256
|
+
visiblePositions = _ref5.visiblePositions;
|
|
257
|
+
return reduceSparseSurfaceCandidates({
|
|
258
|
+
activeNode: activeNode,
|
|
259
|
+
meta: {
|
|
260
|
+
activeNodesByPosition: activeNodesByPosition,
|
|
261
|
+
changedRange: changedRange,
|
|
262
|
+
documentChanged: documentChanged,
|
|
263
|
+
invalidation: invalidation,
|
|
264
|
+
protectedPositions: protectedPositions,
|
|
265
|
+
visiblePositions: visiblePositions
|
|
266
|
+
},
|
|
267
|
+
newState: newState,
|
|
268
|
+
previousState: state,
|
|
269
|
+
resolvedSurfaces: resolvedSurfaces,
|
|
270
|
+
tr: newState.tr
|
|
271
|
+
});
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Update sparse candidates. Viewport and invalidation metadata are the only
|
|
276
|
+
* discovery inputs; active changes re-evaluate retained cache, never document.
|
|
277
|
+
*/
|
|
278
|
+
export var reduceSparseSurfaceCandidates = function reduceSparseSurfaceCandidates(_ref6) {
|
|
279
|
+
var _meta$visiblePosition, _meta$protectedPositi, _meta$documentChanged, _invalidation$positio2;
|
|
280
|
+
var activeNode = _ref6.activeNode,
|
|
281
|
+
meta = _ref6.meta,
|
|
282
|
+
newState = _ref6.newState,
|
|
283
|
+
previousState = _ref6.previousState,
|
|
284
|
+
resolvedSurfaces = _ref6.resolvedSurfaces,
|
|
285
|
+
tr = _ref6.tr;
|
|
286
|
+
var activeRevision = getActiveRevision(activeNode);
|
|
287
|
+
var activeChanged = activeRevision !== previousState.activeRevision;
|
|
288
|
+
var hasVisiblePositionsUpdate = Boolean(meta && Object.prototype.hasOwnProperty.call(meta, 'visiblePositions'));
|
|
289
|
+
var visiblePositions = hasVisiblePositionsUpdate ? normalizePositions((_meta$visiblePosition = meta === null || meta === void 0 ? void 0 : meta.visiblePositions) !== null && _meta$visiblePosition !== void 0 ? _meta$visiblePosition : EMPTY_POSITIONS) : tr.docChanged ? mapPositions(previousState.visiblePositions, tr) : previousState.visiblePositions;
|
|
290
|
+
var visiblePositionsChanged = !samePositions(visiblePositions, previousState.visiblePositions);
|
|
291
|
+
var requestedProtectedPositions = normalizePositions((_meta$protectedPositi = meta === null || meta === void 0 ? void 0 : meta.protectedPositions) !== null && _meta$protectedPositi !== void 0 ? _meta$protectedPositi : previousState.protectedPositions);
|
|
292
|
+
var protectedPositions = samePositions(previousState.protectedPositions, requestedProtectedPositions) ? previousState.protectedPositions : requestedProtectedPositions;
|
|
293
|
+
var protectedSet = new Set(protectedPositions);
|
|
294
|
+
if (activeNode) {
|
|
295
|
+
var _activeNode$rootPos2;
|
|
296
|
+
protectedSet.add(activeNode.pos);
|
|
297
|
+
protectedSet.add((_activeNode$rootPos2 = activeNode.rootPos) !== null && _activeNode$rootPos2 !== void 0 ? _activeNode$rootPos2 : activeNode.pos);
|
|
298
|
+
}
|
|
299
|
+
var visibleSet = new Set(visiblePositions);
|
|
300
|
+
var retain = function retain(position, candidate) {
|
|
301
|
+
return ((candidate === null || candidate === void 0 ? void 0 : candidate.isPersistent) || protectedSet.has(position) || visibleSet.has(position)) && position >= 0 && position <= newState.doc.content.size;
|
|
302
|
+
};
|
|
303
|
+
var surfaces = getSurfaces(resolvedSurfaces);
|
|
304
|
+
var activeNodeAt = function activeNodeAt(position) {
|
|
305
|
+
var _ref7, _meta$activeNodesByPo, _meta$activeNodesByPo2;
|
|
306
|
+
return (_ref7 = (_meta$activeNodesByPo = meta === null || meta === void 0 || (_meta$activeNodesByPo2 = meta.activeNodesByPosition) === null || _meta$activeNodesByPo2 === void 0 ? void 0 : _meta$activeNodesByPo2.get(position)) !== null && _meta$activeNodesByPo !== void 0 ? _meta$activeNodesByPo : activeNode) !== null && _ref7 !== void 0 ? _ref7 : undefined;
|
|
307
|
+
};
|
|
308
|
+
var changedRange = meta !== null && meta !== void 0 && meta.changedRange ? normalizeRange(meta.changedRange, newState.doc.content.size) : undefined;
|
|
309
|
+
var invalidation = meta === null || meta === void 0 ? void 0 : meta.invalidation;
|
|
310
|
+
var documentChanged = (_meta$documentChanged = meta === null || meta === void 0 ? void 0 : meta.documentChanged) !== null && _meta$documentChanged !== void 0 ? _meta$documentChanged : tr.docChanged;
|
|
311
|
+
var previousCandidates = mapCandidates(previousState, tr, retain);
|
|
312
|
+
var dirty = function dirty(candidate, position) {
|
|
313
|
+
var currentNode = newState.doc.nodeAt(position);
|
|
314
|
+
var currentContextRevision = getActiveRevision(activeNodeAt(position));
|
|
315
|
+
return activeChanged || candidate.contextRevision !== currentContextRevision || candidate.nodeRef !== currentNode || isInvalidated(candidate, position, invalidation, changedRange);
|
|
316
|
+
};
|
|
317
|
+
if (surfaces.length === 0) {
|
|
318
|
+
var noCandidates = previousCandidates.size === 0;
|
|
319
|
+
if (noCandidates && previousState.positions.length === 0 && samePositions(visiblePositions, previousState.visiblePositions) && activeRevision === previousState.activeRevision && protectedPositions === previousState.protectedPositions) {
|
|
320
|
+
return previousState;
|
|
321
|
+
}
|
|
322
|
+
return {
|
|
323
|
+
activeRevision: activeRevision,
|
|
324
|
+
candidates: noCandidates ? previousState.candidates : EMPTY_CANDIDATES,
|
|
325
|
+
positions: EMPTY_POSITIONS,
|
|
326
|
+
protectedPositions: protectedPositions,
|
|
327
|
+
visiblePositions: visiblePositions
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
var _iterator4 = _createForOfIteratorHelper(previousCandidates),
|
|
331
|
+
_step4;
|
|
332
|
+
try {
|
|
333
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
334
|
+
var _step4$value = _slicedToArray(_step4.value, 2),
|
|
335
|
+
_position = _step4$value[0],
|
|
336
|
+
candidate = _step4$value[1];
|
|
337
|
+
if (dirty(candidate, _position)) {
|
|
338
|
+
addCandidateAt({
|
|
339
|
+
candidates: previousCandidates,
|
|
340
|
+
position: _position,
|
|
341
|
+
state: newState,
|
|
342
|
+
surfaces: surfaces,
|
|
343
|
+
activeNode: activeNodeAt(_position)
|
|
344
|
+
});
|
|
345
|
+
var updatedCandidate = previousCandidates.get(_position);
|
|
346
|
+
if (updatedCandidate && !retain(_position, updatedCandidate)) {
|
|
347
|
+
previousCandidates.delete(_position);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// IO supplies exact visible positions. Iterate those positions directly so a long visible
|
|
353
|
+
// container cannot cause a traversal of its entire nested document.
|
|
354
|
+
} catch (err) {
|
|
355
|
+
_iterator4.e(err);
|
|
356
|
+
} finally {
|
|
357
|
+
_iterator4.f();
|
|
358
|
+
}
|
|
359
|
+
if (visiblePositionsChanged || documentChanged || invalidation !== null && invalidation !== void 0 && invalidation.all || changedRange) {
|
|
360
|
+
var _iterator5 = _createForOfIteratorHelper(visiblePositions),
|
|
361
|
+
_step5;
|
|
362
|
+
try {
|
|
363
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
364
|
+
var position = _step5.value;
|
|
365
|
+
if (!previousCandidates.has(position)) {
|
|
366
|
+
addCandidateAt({
|
|
367
|
+
candidates: previousCandidates,
|
|
368
|
+
position: position,
|
|
369
|
+
state: newState,
|
|
370
|
+
surfaces: surfaces,
|
|
371
|
+
activeNode: activeNodeAt(position)
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
} catch (err) {
|
|
376
|
+
_iterator5.e(err);
|
|
377
|
+
} finally {
|
|
378
|
+
_iterator5.f();
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
var directPositions = new Set([].concat(_toConsumableArray(protectedSet), _toConsumableArray((_invalidation$positio2 = invalidation === null || invalidation === void 0 ? void 0 : invalidation.positions) !== null && _invalidation$positio2 !== void 0 ? _invalidation$positio2 : [])));
|
|
382
|
+
var _iterator6 = _createForOfIteratorHelper(directPositions),
|
|
383
|
+
_step6;
|
|
384
|
+
try {
|
|
385
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
386
|
+
var _position2 = _step6.value;
|
|
387
|
+
if (retain(_position2) && !previousCandidates.has(_position2)) {
|
|
388
|
+
addCandidateAt({
|
|
389
|
+
candidates: previousCandidates,
|
|
390
|
+
position: _position2,
|
|
391
|
+
state: newState,
|
|
392
|
+
surfaces: surfaces,
|
|
393
|
+
activeNode: activeNodeAt(_position2)
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
} catch (err) {
|
|
398
|
+
_iterator6.e(err);
|
|
399
|
+
} finally {
|
|
400
|
+
_iterator6.f();
|
|
401
|
+
}
|
|
402
|
+
var positions = getPositions(previousCandidates);
|
|
403
|
+
if (sameCandidateMap(previousState.candidates, previousCandidates) && samePositions(previousState.positions, positions) && samePositions(previousState.visiblePositions, visiblePositions) && activeRevision === previousState.activeRevision && protectedPositions === previousState.protectedPositions) {
|
|
404
|
+
return previousState;
|
|
405
|
+
}
|
|
406
|
+
return {
|
|
407
|
+
activeRevision: activeRevision,
|
|
408
|
+
candidates: sameCandidateMap(previousState.candidates, previousCandidates) ? previousState.candidates : previousCandidates,
|
|
409
|
+
positions: samePositions(previousState.positions, positions) ? previousState.positions : positions,
|
|
410
|
+
protectedPositions: protectedPositions,
|
|
411
|
+
visiblePositions: visiblePositions
|
|
412
|
+
};
|
|
413
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
4
|
+
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; }
|
|
5
|
+
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) { _defineProperty(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; }
|
|
6
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
7
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
8
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
9
|
+
import { mapSparseSurfaceCandidates } from './sparse-surface-candidates';
|
|
10
|
+
var mergeInvalidation = function mergeInvalidation(_ref) {
|
|
11
|
+
var _current$ids, _incoming$ids, _current$positions, _incoming$positions, _current$ranges, _incoming$ranges;
|
|
12
|
+
var current = _ref.current,
|
|
13
|
+
incoming = _ref.incoming,
|
|
14
|
+
tr = _ref.tr;
|
|
15
|
+
if (!current && !incoming) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
if (!incoming && !tr.docChanged) {
|
|
19
|
+
return current;
|
|
20
|
+
}
|
|
21
|
+
var ids = [].concat(_toConsumableArray((_current$ids = current === null || current === void 0 ? void 0 : current.ids) !== null && _current$ids !== void 0 ? _current$ids : []), _toConsumableArray((_incoming$ids = incoming === null || incoming === void 0 ? void 0 : incoming.ids) !== null && _incoming$ids !== void 0 ? _incoming$ids : []));
|
|
22
|
+
var positions = [].concat(_toConsumableArray(((_current$positions = current === null || current === void 0 ? void 0 : current.positions) !== null && _current$positions !== void 0 ? _current$positions : []).map(function (position) {
|
|
23
|
+
return tr.mapping.map(position, 1);
|
|
24
|
+
})), _toConsumableArray((_incoming$positions = incoming === null || incoming === void 0 ? void 0 : incoming.positions) !== null && _incoming$positions !== void 0 ? _incoming$positions : []));
|
|
25
|
+
var ranges = [].concat(_toConsumableArray(((_current$ranges = current === null || current === void 0 ? void 0 : current.ranges) !== null && _current$ranges !== void 0 ? _current$ranges : []).map(function (_ref2) {
|
|
26
|
+
var from = _ref2.from,
|
|
27
|
+
to = _ref2.to;
|
|
28
|
+
return {
|
|
29
|
+
from: tr.mapping.map(from, -1),
|
|
30
|
+
to: tr.mapping.map(to, 1)
|
|
31
|
+
};
|
|
32
|
+
})), _toConsumableArray((_incoming$ranges = incoming === null || incoming === void 0 ? void 0 : incoming.ranges) !== null && _incoming$ranges !== void 0 ? _incoming$ranges : []));
|
|
33
|
+
return ids.length || positions.length || ranges.length ? {
|
|
34
|
+
ids: ids,
|
|
35
|
+
positions: positions,
|
|
36
|
+
ranges: ranges
|
|
37
|
+
} : undefined;
|
|
38
|
+
};
|
|
39
|
+
var mapAnchors = function mapAnchors(anchors, tr) {
|
|
40
|
+
if (!tr.docChanged || anchors.size === 0) {
|
|
41
|
+
return anchors;
|
|
42
|
+
}
|
|
43
|
+
var changed = false;
|
|
44
|
+
var mappedAnchors = new Map();
|
|
45
|
+
var _iterator = _createForOfIteratorHelper(anchors),
|
|
46
|
+
_step;
|
|
47
|
+
try {
|
|
48
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
49
|
+
var _step$value = _slicedToArray(_step.value, 2),
|
|
50
|
+
position = _step$value[0],
|
|
51
|
+
name = _step$value[1];
|
|
52
|
+
var mapped = tr.mapping.mapResult(position, 1);
|
|
53
|
+
if (!mapped.deleted) {
|
|
54
|
+
mappedAnchors.set(mapped.pos, name);
|
|
55
|
+
changed || (changed = mapped.pos !== position);
|
|
56
|
+
} else {
|
|
57
|
+
changed = true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
} catch (err) {
|
|
61
|
+
_iterator.e(err);
|
|
62
|
+
} finally {
|
|
63
|
+
_iterator.f();
|
|
64
|
+
}
|
|
65
|
+
return changed ? mappedAnchors : anchors;
|
|
66
|
+
};
|
|
67
|
+
export var reducePendingState = function reducePendingState(_ref3) {
|
|
68
|
+
var invalidation = _ref3.invalidation,
|
|
69
|
+
previous = _ref3.previous,
|
|
70
|
+
tr = _ref3.tr;
|
|
71
|
+
return {
|
|
72
|
+
invalidation: mergeInvalidation({
|
|
73
|
+
current: previous.invalidation,
|
|
74
|
+
incoming: invalidation,
|
|
75
|
+
tr: tr
|
|
76
|
+
})
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
export var isUnchangedTransaction = function isUnchangedTransaction(_ref4) {
|
|
80
|
+
var pending = _ref4.pending,
|
|
81
|
+
previous = _ref4.previous,
|
|
82
|
+
tr = _ref4.tr;
|
|
83
|
+
return !tr.docChanged && pending.invalidation === previous.invalidation;
|
|
84
|
+
};
|
|
85
|
+
export var mapTransactionState = function mapTransactionState(_ref5) {
|
|
86
|
+
var newState = _ref5.newState,
|
|
87
|
+
pending = _ref5.pending,
|
|
88
|
+
previous = _ref5.previous,
|
|
89
|
+
tr = _ref5.tr;
|
|
90
|
+
return _objectSpread(_objectSpread({}, previous), {}, {
|
|
91
|
+
anchors: mapAnchors(previous.anchors, tr),
|
|
92
|
+
candidates: tr.docChanged ? mapSparseSurfaceCandidates({
|
|
93
|
+
newState: newState,
|
|
94
|
+
previousState: previous.candidates,
|
|
95
|
+
tr: tr
|
|
96
|
+
}) : previous.candidates,
|
|
97
|
+
decorations: tr.docChanged ? previous.decorations.map(tr.mapping, tr.doc) : previous.decorations,
|
|
98
|
+
documentChanged: previous.documentChanged || tr.docChanged,
|
|
99
|
+
invalidation: pending.invalidation
|
|
100
|
+
});
|
|
101
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
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; }
|
|
3
|
+
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) { _defineProperty(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; }
|
|
4
|
+
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
5
|
+
import { isUnchangedTransaction, mapTransactionState, reducePendingState } from './sparse-surfaces-mapping';
|
|
6
|
+
export var createInitialSparseSurfacesState = function createInitialSparseSurfacesState(candidates) {
|
|
7
|
+
return {
|
|
8
|
+
activeNodesByPosition: new Map(),
|
|
9
|
+
anchors: new Map(),
|
|
10
|
+
candidates: candidates,
|
|
11
|
+
decorations: DecorationSet.empty,
|
|
12
|
+
documentChanged: false
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
var isReconciliationCommit = function isReconciliationCommit(meta) {
|
|
16
|
+
return (meta === null || meta === void 0 ? void 0 : meta.type) === 'commitReconciliation';
|
|
17
|
+
};
|
|
18
|
+
var commitReconciliation = function commitReconciliation(previous, meta) {
|
|
19
|
+
return _objectSpread(_objectSpread(_objectSpread({}, previous), meta.reconciliation), {}, {
|
|
20
|
+
documentChanged: false,
|
|
21
|
+
invalidation: undefined
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
export var applySparseSurfacesTransaction = function applySparseSurfacesTransaction(input) {
|
|
25
|
+
if (isReconciliationCommit(input.meta)) {
|
|
26
|
+
return commitReconciliation(input.previous, input.meta);
|
|
27
|
+
}
|
|
28
|
+
var pending = reducePendingState({
|
|
29
|
+
invalidation: input.invalidation,
|
|
30
|
+
previous: input.previous,
|
|
31
|
+
tr: input.tr
|
|
32
|
+
});
|
|
33
|
+
if (isUnchangedTransaction({
|
|
34
|
+
pending: pending,
|
|
35
|
+
previous: input.previous,
|
|
36
|
+
tr: input.tr
|
|
37
|
+
})) {
|
|
38
|
+
return input.previous;
|
|
39
|
+
}
|
|
40
|
+
return mapTransactionState({
|
|
41
|
+
newState: input.newState,
|
|
42
|
+
pending: pending,
|
|
43
|
+
previous: input.previous,
|
|
44
|
+
tr: input.tr
|
|
45
|
+
});
|
|
46
|
+
};
|