@univerjs/drawing 0.5.4 → 0.5.5-experimental.20250123-34738ff
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/lib/cjs/index.js +1 -1
- package/lib/es/index.js +1530 -1481
- package/lib/umd/index.js +1 -1
- package/package.json +4 -4
- package/LICENSE +0 -176
package/lib/es/index.js
CHANGED
|
@@ -1,123 +1,131 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
5
|
+
import { sortRules, sortRulesByDesc, createIdentifier, CommandType, ImageSourceType, ImageUploadStatusType, Tools, Inject, Injector, Plugin, merge, mergeOverrideWithDependencies, IConfigService, ICommandService, IImageIoService } from "@univerjs/core";
|
|
6
|
+
import { IImageIoService as IImageIoService2, ImageSourceType as ImageSourceType2, ImageUploadStatusType as ImageUploadStatusType2 } from "@univerjs/core";
|
|
7
|
+
import { Subject } from "rxjs";
|
|
8
|
+
const DRAWING_IMAGE_WIDTH_LIMIT = 500, DRAWING_IMAGE_HEIGHT_LIMIT = 500, DRAWING_IMAGE_COUNT_LIMIT = 10, DRAWING_IMAGE_ALLOW_SIZE = 5 * 1024 * 1024, DRAWING_IMAGE_ALLOW_IMAGE_LIST = ["image/png", "image/jpeg", "image/jpg", "image/gif", "image/bmp"];
|
|
9
|
+
var dist$1 = {}, json1_release = {}, deepEqual = {}, hasRequiredDeepEqual;
|
|
10
|
+
function requireDeepEqual() {
|
|
11
|
+
if (hasRequiredDeepEqual) return deepEqual;
|
|
12
|
+
hasRequiredDeepEqual = 1, Object.defineProperty(deepEqual, "__esModule", { value: !0 });
|
|
13
|
+
function eqObj(a, b) {
|
|
14
|
+
if (Array.isArray(b))
|
|
14
15
|
return !1;
|
|
15
|
-
for (let
|
|
16
|
-
if (!
|
|
16
|
+
for (let k in a)
|
|
17
|
+
if (!deepEqual$1(a[k], b[k]))
|
|
17
18
|
return !1;
|
|
18
|
-
for (let
|
|
19
|
-
if (
|
|
19
|
+
for (let k in b)
|
|
20
|
+
if (a[k] === void 0)
|
|
20
21
|
return !1;
|
|
21
22
|
return !0;
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
__name(eqObj, "eqObj");
|
|
25
|
+
function eqArr(a, b) {
|
|
26
|
+
if (!Array.isArray(b) || a.length !== b.length)
|
|
25
27
|
return !1;
|
|
26
|
-
for (let
|
|
27
|
-
if (!
|
|
28
|
+
for (let i = 0; i < a.length; i++)
|
|
29
|
+
if (!deepEqual$1(a[i], b[i]))
|
|
28
30
|
return !1;
|
|
29
31
|
return !0;
|
|
30
32
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
__name(eqArr, "eqArr");
|
|
34
|
+
function deepEqual$1(a, b) {
|
|
35
|
+
return a === b ? !0 : a === null || b === null || typeof a != "object" || typeof b != "object" ? !1 : Array.isArray(a) ? eqArr(a, b) : eqObj(a, b);
|
|
33
36
|
}
|
|
34
|
-
return
|
|
37
|
+
return __name(deepEqual$1, "deepEqual$1"), deepEqual.default = deepEqual$1, deepEqual;
|
|
35
38
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
__name(requireDeepEqual, "requireDeepEqual");
|
|
40
|
+
var deepClone = {}, hasRequiredDeepClone;
|
|
41
|
+
function requireDeepClone() {
|
|
42
|
+
if (hasRequiredDeepClone) return deepClone;
|
|
43
|
+
hasRequiredDeepClone = 1, Object.defineProperty(deepClone, "__esModule", { value: !0 });
|
|
44
|
+
function deepClone$1(old) {
|
|
45
|
+
if (old === null)
|
|
42
46
|
return null;
|
|
43
|
-
if (Array.isArray(
|
|
44
|
-
return
|
|
45
|
-
if (typeof
|
|
46
|
-
const
|
|
47
|
-
for (let
|
|
48
|
-
|
|
49
|
-
return
|
|
47
|
+
if (Array.isArray(old))
|
|
48
|
+
return old.map(deepClone$1);
|
|
49
|
+
if (typeof old == "object") {
|
|
50
|
+
const o = {};
|
|
51
|
+
for (let k in old)
|
|
52
|
+
o[k] = deepClone$1(old[k]);
|
|
53
|
+
return o;
|
|
50
54
|
} else
|
|
51
|
-
return
|
|
55
|
+
return old;
|
|
52
56
|
}
|
|
53
|
-
return
|
|
57
|
+
return __name(deepClone$1, "deepClone$1"), deepClone.default = deepClone$1, deepClone;
|
|
54
58
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
__name(requireDeepClone, "requireDeepClone");
|
|
60
|
+
var cursor = {}, hasRequiredCursor;
|
|
61
|
+
function requireCursor() {
|
|
62
|
+
return hasRequiredCursor || (hasRequiredCursor = 1, function(exports) {
|
|
63
|
+
Object.defineProperty(exports, "__esModule", { value: !0 }), exports.eachChildOf = exports.advancer = exports.readCursor = exports.writeCursor = exports.WriteCursor = exports.ReadCursor = exports.isValidPathItem = void 0;
|
|
64
|
+
function assert(pred, msg) {
|
|
65
|
+
if (!pred)
|
|
66
|
+
throw new Error(msg);
|
|
62
67
|
}
|
|
63
|
-
|
|
68
|
+
__name(assert, "assert");
|
|
69
|
+
const isObject = /* @__PURE__ */ __name((o) => o != null && typeof o == "object" && !Array.isArray(o), "isObject"), isGreaterKey = /* @__PURE__ */ __name((a, b) => (
|
|
64
70
|
// All the numbers, then all the letters. Just as the gods of ascii intended.
|
|
65
|
-
typeof
|
|
66
|
-
);
|
|
67
|
-
function
|
|
68
|
-
for (let
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
+
typeof a == typeof b ? a > b : typeof a == "string" && typeof b == "number"
|
|
72
|
+
), "isGreaterKey");
|
|
73
|
+
function copyAll(c, w) {
|
|
74
|
+
for (let _k in c) {
|
|
75
|
+
const k = _k;
|
|
76
|
+
w.write(k, c[k]);
|
|
71
77
|
}
|
|
72
78
|
}
|
|
73
|
-
|
|
74
|
-
class
|
|
75
|
-
constructor(
|
|
76
|
-
this.parents = [], this.indexes = [], this.lcIdx = -1, this.idx = -1, this.container =
|
|
79
|
+
__name(copyAll, "copyAll"), exports.isValidPathItem = (k) => typeof k == "number" || typeof k == "string" && k !== "__proto__";
|
|
80
|
+
const _Cursor = class _Cursor {
|
|
81
|
+
constructor(op = null) {
|
|
82
|
+
this.parents = [], this.indexes = [], this.lcIdx = -1, this.idx = -1, this.container = op;
|
|
77
83
|
}
|
|
78
84
|
ascend() {
|
|
79
|
-
|
|
85
|
+
assert(this.parents.length === this.indexes.length / 2), this.idx === 0 ? this.parents.length ? (this.lcIdx = this.indexes.pop(), this.container = this.parents.pop(), this.idx = this.indexes.pop()) : (this.lcIdx = 0, this.idx = -1) : (assert(this.idx > 0), this.idx--, isObject(this.container[this.idx]) && this.idx--);
|
|
80
86
|
}
|
|
81
87
|
getPath() {
|
|
82
|
-
const
|
|
83
|
-
let
|
|
84
|
-
for (;
|
|
85
|
-
|
|
86
|
-
return
|
|
88
|
+
const path = [];
|
|
89
|
+
let c = this.container, p = this.parents.length - 1, i = this.idx;
|
|
90
|
+
for (; i >= 0; )
|
|
91
|
+
path.unshift(c[i]), i === 0 ? (i = this.indexes[p * 2], c = this.parents[p--]) : i -= isObject(c[i - 1]) ? 2 : 1;
|
|
92
|
+
return path;
|
|
87
93
|
}
|
|
88
|
-
}
|
|
89
|
-
|
|
94
|
+
};
|
|
95
|
+
__name(_Cursor, "Cursor");
|
|
96
|
+
let Cursor = _Cursor;
|
|
97
|
+
const _ReadCursor = class _ReadCursor extends Cursor {
|
|
90
98
|
get() {
|
|
91
99
|
return this.container ? this.container.slice(this.idx + 1) : null;
|
|
92
100
|
}
|
|
93
101
|
// Its only valid to call this after descending into a child.
|
|
94
102
|
getKey() {
|
|
95
|
-
return
|
|
103
|
+
return assert(this.container != null, "Invalid call to getKey before cursor descended"), this.container[this.idx];
|
|
96
104
|
}
|
|
97
105
|
getComponent() {
|
|
98
|
-
let
|
|
99
|
-
return this.container && this.container.length > this.idx + 1 &&
|
|
106
|
+
let c;
|
|
107
|
+
return this.container && this.container.length > this.idx + 1 && isObject(c = this.container[this.idx + 1]) ? c : null;
|
|
100
108
|
}
|
|
101
109
|
descendFirst() {
|
|
102
|
-
let
|
|
103
|
-
if (!this.container ||
|
|
110
|
+
let i = this.idx + 1;
|
|
111
|
+
if (!this.container || i >= this.container.length || isObject(this.container[i]) && i + 1 >= this.container.length)
|
|
104
112
|
return !1;
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
return Array.isArray(
|
|
113
|
+
isObject(this.container[i]) && i++;
|
|
114
|
+
const firstChild = this.container[i];
|
|
115
|
+
return Array.isArray(firstChild) ? (this.indexes.push(this.idx), this.parents.push(this.container), this.indexes.push(i), this.idx = 0, this.container = firstChild) : this.idx = i, !0;
|
|
108
116
|
}
|
|
109
117
|
nextSibling() {
|
|
110
|
-
if (
|
|
118
|
+
if (assert(this.parents.length === this.indexes.length / 2), this.idx > 0 || this.parents.length === 0)
|
|
111
119
|
return !1;
|
|
112
|
-
const
|
|
113
|
-
return
|
|
120
|
+
const i = this.indexes[this.indexes.length - 1] + 1, c = this.parents[this.parents.length - 1];
|
|
121
|
+
return i >= c.length ? !1 : (assert(!isNaN(i)), this.indexes[this.indexes.length - 1] = i, this.container = c[i], !0);
|
|
114
122
|
}
|
|
115
|
-
_init(
|
|
116
|
-
this.container =
|
|
123
|
+
_init(_container, _idx, _parents, _indexes) {
|
|
124
|
+
this.container = _container, this.idx = _idx, this.parents = _parents.slice(), this.indexes = _indexes.slice();
|
|
117
125
|
}
|
|
118
126
|
clone() {
|
|
119
|
-
const
|
|
120
|
-
return
|
|
127
|
+
const c = new _ReadCursor();
|
|
128
|
+
return c._init(this.container, this.idx, this.parents, this.indexes), c;
|
|
121
129
|
}
|
|
122
130
|
*[Symbol.iterator]() {
|
|
123
131
|
if (this.descendFirst()) {
|
|
@@ -130,49 +138,51 @@ function Mt() {
|
|
|
130
138
|
// TODO(cleanup): Consider moving these functions out of cursor, since
|
|
131
139
|
// they're really just helper methods.
|
|
132
140
|
// It'd be really nice to do this using generators.
|
|
133
|
-
traverse(
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
for (const
|
|
137
|
-
|
|
141
|
+
traverse(w, fn) {
|
|
142
|
+
const c = this.getComponent();
|
|
143
|
+
c && fn(c, w);
|
|
144
|
+
for (const key of this)
|
|
145
|
+
w && w.descend(key), this.traverse(w, fn), w && w.ascend();
|
|
138
146
|
}
|
|
139
|
-
eachPick(
|
|
140
|
-
this.traverse(
|
|
141
|
-
|
|
147
|
+
eachPick(w, fn) {
|
|
148
|
+
this.traverse(w, (c, w2) => {
|
|
149
|
+
c.p != null && fn(c.p, w2);
|
|
142
150
|
});
|
|
143
151
|
}
|
|
144
|
-
eachDrop(
|
|
145
|
-
this.traverse(
|
|
146
|
-
|
|
152
|
+
eachDrop(w, fn) {
|
|
153
|
+
this.traverse(w, (c, w2) => {
|
|
154
|
+
c.d != null && fn(c.d, w2);
|
|
147
155
|
});
|
|
148
156
|
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
157
|
+
};
|
|
158
|
+
__name(_ReadCursor, "ReadCursor");
|
|
159
|
+
let ReadCursor = _ReadCursor;
|
|
160
|
+
exports.ReadCursor = ReadCursor;
|
|
161
|
+
const _WriteCursor = class _WriteCursor extends Cursor {
|
|
162
|
+
constructor(op = null) {
|
|
163
|
+
super(op), this.pendingDescent = [], this._op = op;
|
|
154
164
|
}
|
|
155
165
|
flushDescent() {
|
|
156
|
-
|
|
157
|
-
for (let
|
|
158
|
-
const
|
|
159
|
-
let
|
|
160
|
-
if (
|
|
161
|
-
this.container.push(
|
|
162
|
-
else if (this.container[
|
|
163
|
-
this.idx =
|
|
166
|
+
assert(this.parents.length === this.indexes.length / 2), this.container === null && (this._op = this.container = []);
|
|
167
|
+
for (let j = 0; j < this.pendingDescent.length; j++) {
|
|
168
|
+
const k = this.pendingDescent[j];
|
|
169
|
+
let i = this.idx + 1;
|
|
170
|
+
if (i < this.container.length && isObject(this.container[i]) && i++, assert(i === this.container.length || !isObject(this.container[i])), i === this.container.length)
|
|
171
|
+
this.container.push(k), this.idx = i;
|
|
172
|
+
else if (this.container[i] === k)
|
|
173
|
+
this.idx = i;
|
|
164
174
|
else {
|
|
165
|
-
if (!Array.isArray(this.container[
|
|
166
|
-
const
|
|
167
|
-
this.container.push(
|
|
175
|
+
if (!Array.isArray(this.container[i])) {
|
|
176
|
+
const oldChild = this.container.splice(i, this.container.length - i);
|
|
177
|
+
this.container.push(oldChild), this.lcIdx > -1 && (this.lcIdx = i);
|
|
168
178
|
}
|
|
169
|
-
for (this.indexes.push(this.idx), this.parents.push(this.container), this.lcIdx !== -1 && (
|
|
170
|
-
|
|
171
|
-
if (this.indexes.push(
|
|
172
|
-
this.container = this.container[
|
|
179
|
+
for (this.indexes.push(this.idx), this.parents.push(this.container), this.lcIdx !== -1 && (assert(isGreaterKey(k, this.container[this.lcIdx][0])), i = this.lcIdx + 1, this.lcIdx = -1); i < this.container.length && isGreaterKey(k, this.container[i][0]); )
|
|
180
|
+
i++;
|
|
181
|
+
if (this.indexes.push(i), this.idx = 0, i < this.container.length && this.container[i][0] === k)
|
|
182
|
+
this.container = this.container[i];
|
|
173
183
|
else {
|
|
174
|
-
const
|
|
175
|
-
this.container.splice(
|
|
184
|
+
const child = [k];
|
|
185
|
+
this.container.splice(i, 0, child), this.container = child;
|
|
176
186
|
}
|
|
177
187
|
}
|
|
178
188
|
}
|
|
@@ -186,442 +196,455 @@ function Mt() {
|
|
|
186
196
|
// components.
|
|
187
197
|
getComponent() {
|
|
188
198
|
this.flushDescent();
|
|
189
|
-
const
|
|
190
|
-
if (
|
|
191
|
-
return this.container[
|
|
199
|
+
const i = this.idx + 1;
|
|
200
|
+
if (i < this.container.length && isObject(this.container[i]))
|
|
201
|
+
return this.container[i];
|
|
192
202
|
{
|
|
193
|
-
const
|
|
194
|
-
return this.container.splice(
|
|
203
|
+
const component = {};
|
|
204
|
+
return this.container.splice(i, 0, component), component;
|
|
195
205
|
}
|
|
196
206
|
}
|
|
197
|
-
write(
|
|
198
|
-
const
|
|
199
|
-
|
|
207
|
+
write(key, value) {
|
|
208
|
+
const component = this.getComponent();
|
|
209
|
+
assert(component[key] == null || component[key] === value, "Internal consistency error: Overwritten component. File a bug"), component[key] = value;
|
|
200
210
|
}
|
|
201
211
|
get() {
|
|
202
212
|
return this._op;
|
|
203
213
|
}
|
|
204
|
-
descend(
|
|
205
|
-
if (!
|
|
214
|
+
descend(key) {
|
|
215
|
+
if (!exports.isValidPathItem(key))
|
|
206
216
|
throw Error("Invalid JSON key");
|
|
207
|
-
this.pendingDescent.push(
|
|
217
|
+
this.pendingDescent.push(key);
|
|
208
218
|
}
|
|
209
|
-
descendPath(
|
|
210
|
-
return this.pendingDescent.push(...
|
|
219
|
+
descendPath(path) {
|
|
220
|
+
return this.pendingDescent.push(...path), this;
|
|
211
221
|
}
|
|
212
222
|
ascend() {
|
|
213
223
|
this.pendingDescent.length ? this.pendingDescent.pop() : super.ascend();
|
|
214
224
|
}
|
|
215
|
-
mergeTree(
|
|
216
|
-
if (
|
|
225
|
+
mergeTree(data, mergeFn = copyAll) {
|
|
226
|
+
if (data === null)
|
|
217
227
|
return;
|
|
218
|
-
if (
|
|
228
|
+
if (assert(Array.isArray(data)), data === this._op)
|
|
219
229
|
throw Error("Cannot merge into my own tree");
|
|
220
|
-
const
|
|
221
|
-
let
|
|
222
|
-
for (let
|
|
223
|
-
const
|
|
224
|
-
typeof
|
|
230
|
+
const _lcIdx = this.lcIdx, oldDepth = this.parents.length;
|
|
231
|
+
let depth = 0;
|
|
232
|
+
for (let i = 0; i < data.length; i++) {
|
|
233
|
+
const c = data[i];
|
|
234
|
+
typeof c == "string" || typeof c == "number" ? (depth++, this.descend(c)) : Array.isArray(c) ? this.mergeTree(c, mergeFn) : typeof c == "object" && mergeFn(c, this);
|
|
225
235
|
}
|
|
226
|
-
for (;
|
|
236
|
+
for (; depth--; )
|
|
227
237
|
this.ascend();
|
|
228
|
-
this.lcIdx = this.parents.length ===
|
|
238
|
+
this.lcIdx = this.parents.length === oldDepth ? _lcIdx : -1;
|
|
229
239
|
}
|
|
230
|
-
at(
|
|
231
|
-
this.descendPath(
|
|
232
|
-
for (let
|
|
240
|
+
at(path, fn) {
|
|
241
|
+
this.descendPath(path), fn(this);
|
|
242
|
+
for (let i = 0; i < path.length; i++)
|
|
233
243
|
this.ascend();
|
|
234
244
|
return this;
|
|
235
245
|
}
|
|
236
246
|
// This is used by helpers, so the strict ordering guarantees are
|
|
237
247
|
// relaxed.
|
|
238
|
-
writeAtPath(
|
|
239
|
-
return this.at(
|
|
248
|
+
writeAtPath(path, key, value) {
|
|
249
|
+
return this.at(path, () => this.write(key, value)), this.reset(), this;
|
|
240
250
|
}
|
|
241
|
-
writeMove(
|
|
242
|
-
return this.writeAtPath(
|
|
251
|
+
writeMove(path1, path2, slot = 0) {
|
|
252
|
+
return this.writeAtPath(path1, "p", slot).writeAtPath(path2, "d", slot);
|
|
243
253
|
}
|
|
244
254
|
getPath() {
|
|
245
|
-
const
|
|
246
|
-
return
|
|
255
|
+
const path = super.getPath();
|
|
256
|
+
return path.push(...this.pendingDescent), path;
|
|
247
257
|
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
258
|
+
};
|
|
259
|
+
__name(_WriteCursor, "WriteCursor");
|
|
260
|
+
let WriteCursor = _WriteCursor;
|
|
261
|
+
exports.WriteCursor = WriteCursor, exports.writeCursor = () => new WriteCursor(), exports.readCursor = (op) => new ReadCursor(op);
|
|
262
|
+
function advancer(r, listMap, listAdv) {
|
|
263
|
+
let didDescend, valid;
|
|
264
|
+
valid = didDescend = r ? r.descendFirst() : !1;
|
|
265
|
+
function adv(ktarget) {
|
|
266
|
+
let k2_;
|
|
267
|
+
for (; valid; ) {
|
|
268
|
+
const k2 = k2_ = r.getKey();
|
|
269
|
+
if (ktarget != null) {
|
|
270
|
+
let skip = !1;
|
|
271
|
+
if (listMap && typeof k2 == "number" && (k2_ = listMap(k2, r.getComponent()), k2_ < 0 && (k2_ = ~k2_, skip = !0)), isGreaterKey(k2_, ktarget))
|
|
260
272
|
return null;
|
|
261
|
-
if (
|
|
262
|
-
return
|
|
273
|
+
if (k2_ === ktarget && !skip)
|
|
274
|
+
return r;
|
|
263
275
|
}
|
|
264
|
-
|
|
276
|
+
listAdv && typeof k2_ == "number" && listAdv(k2_, r.getComponent()), valid = r.nextSibling();
|
|
265
277
|
}
|
|
266
278
|
return null;
|
|
267
279
|
}
|
|
268
|
-
return
|
|
269
|
-
|
|
270
|
-
},
|
|
280
|
+
return __name(adv, "adv"), adv.end = () => {
|
|
281
|
+
didDescend && r.ascend();
|
|
282
|
+
}, adv;
|
|
271
283
|
}
|
|
272
|
-
|
|
273
|
-
function
|
|
274
|
-
let
|
|
275
|
-
for (
|
|
276
|
-
let
|
|
277
|
-
|
|
284
|
+
__name(advancer, "advancer"), exports.advancer = advancer;
|
|
285
|
+
function eachChildOf(r1, r2, fn) {
|
|
286
|
+
let hasChild1, descended1, hasChild2, descended2;
|
|
287
|
+
for (hasChild1 = descended1 = r1 && r1.descendFirst(), hasChild2 = descended2 = r2 && r2.descendFirst(); hasChild1 || hasChild2; ) {
|
|
288
|
+
let k1 = hasChild1 ? r1.getKey() : null, k2 = hasChild2 ? r2.getKey() : null;
|
|
289
|
+
k1 !== null && k2 !== null && (isGreaterKey(k2, k1) ? k2 = null : k1 !== k2 && (k1 = null)), fn(k1 == null ? k2 : k1, k1 != null ? r1 : null, k2 != null ? r2 : null), k1 != null && hasChild1 && (hasChild1 = r1.nextSibling()), k2 != null && hasChild2 && (hasChild2 = r2.nextSibling());
|
|
278
290
|
}
|
|
279
|
-
|
|
291
|
+
descended1 && r1.ascend(), descended2 && r2.ascend();
|
|
280
292
|
}
|
|
281
|
-
|
|
282
|
-
}(
|
|
293
|
+
__name(eachChildOf, "eachChildOf"), exports.eachChildOf = eachChildOf;
|
|
294
|
+
}(cursor)), cursor;
|
|
283
295
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
296
|
+
__name(requireCursor, "requireCursor");
|
|
297
|
+
var types = {}, hasRequiredTypes;
|
|
298
|
+
function requireTypes() {
|
|
299
|
+
return hasRequiredTypes || (hasRequiredTypes = 1, function(exports) {
|
|
300
|
+
Object.defineProperty(exports, "__esModule", { value: !0 }), exports.ConflictType = void 0, function(ConflictType) {
|
|
301
|
+
ConflictType[ConflictType.RM_UNEXPECTED_CONTENT = 1] = "RM_UNEXPECTED_CONTENT", ConflictType[ConflictType.DROP_COLLISION = 2] = "DROP_COLLISION", ConflictType[ConflictType.BLACKHOLE = 3] = "BLACKHOLE";
|
|
302
|
+
}(exports.ConflictType || (exports.ConflictType = {}));
|
|
303
|
+
}(types)), types;
|
|
291
304
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
305
|
+
__name(requireTypes, "requireTypes");
|
|
306
|
+
var dist = {}, unicount = {}, hasRequiredUnicount;
|
|
307
|
+
function requireUnicount() {
|
|
308
|
+
return hasRequiredUnicount || (hasRequiredUnicount = 1, Object.defineProperty(unicount, "__esModule", { value: !0 }), unicount.uniToStrPos = unicount.strPosToUni = void 0, unicount.strPosToUni = (s, strOffset = s.length) => {
|
|
309
|
+
let pairs = 0, i = 0;
|
|
310
|
+
for (; i < strOffset; i++) {
|
|
311
|
+
const code = s.charCodeAt(i);
|
|
312
|
+
code >= 55296 && code <= 57343 && (pairs++, i++);
|
|
299
313
|
}
|
|
300
|
-
if (
|
|
314
|
+
if (i !== strOffset)
|
|
301
315
|
throw Error("Invalid offset - splits unicode bytes");
|
|
302
|
-
return
|
|
303
|
-
},
|
|
304
|
-
let
|
|
305
|
-
for (;
|
|
306
|
-
const
|
|
307
|
-
|
|
316
|
+
return i - pairs;
|
|
317
|
+
}, unicount.uniToStrPos = (s, uniOffset) => {
|
|
318
|
+
let pos = 0;
|
|
319
|
+
for (; uniOffset > 0; uniOffset--) {
|
|
320
|
+
const code = s.charCodeAt(pos);
|
|
321
|
+
pos += code >= 55296 && code <= 57343 ? 2 : 1;
|
|
308
322
|
}
|
|
309
|
-
return
|
|
310
|
-
}),
|
|
323
|
+
return pos;
|
|
324
|
+
}), unicount;
|
|
311
325
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
326
|
+
__name(requireUnicount, "requireUnicount");
|
|
327
|
+
var type = {}, hasRequiredType;
|
|
328
|
+
function requireType() {
|
|
329
|
+
return hasRequiredType || (hasRequiredType = 1, function(exports) {
|
|
330
|
+
Object.defineProperty(exports, "__esModule", { value: !0 }), exports.uniSlice = exports.dlen = exports.eachOp = void 0;
|
|
331
|
+
const unicount_1 = requireUnicount(), checkOp = /* @__PURE__ */ __name((op) => {
|
|
332
|
+
if (!Array.isArray(op))
|
|
318
333
|
throw Error("Op must be an array of components");
|
|
319
|
-
let
|
|
320
|
-
for (let
|
|
321
|
-
const
|
|
322
|
-
switch (typeof
|
|
334
|
+
let last = null;
|
|
335
|
+
for (let i = 0; i < op.length; i++) {
|
|
336
|
+
const c = op[i];
|
|
337
|
+
switch (typeof c) {
|
|
323
338
|
case "object":
|
|
324
|
-
if (typeof
|
|
339
|
+
if (typeof c.d != "number" && typeof c.d != "string")
|
|
325
340
|
throw Error("Delete must be number or string");
|
|
326
|
-
if (
|
|
341
|
+
if (exports.dlen(c.d) <= 0)
|
|
327
342
|
throw Error("Deletes must not be empty");
|
|
328
343
|
break;
|
|
329
344
|
case "string":
|
|
330
|
-
if (!(
|
|
345
|
+
if (!(c.length > 0))
|
|
331
346
|
throw Error("Inserts cannot be empty");
|
|
332
347
|
break;
|
|
333
348
|
case "number":
|
|
334
|
-
if (!(
|
|
349
|
+
if (!(c > 0))
|
|
335
350
|
throw Error("Skip components must be >0");
|
|
336
|
-
if (typeof
|
|
351
|
+
if (typeof last == "number")
|
|
337
352
|
throw Error("Adjacent skip components should be combined");
|
|
338
353
|
break;
|
|
339
354
|
}
|
|
340
|
-
|
|
355
|
+
last = c;
|
|
341
356
|
}
|
|
342
|
-
if (typeof
|
|
357
|
+
if (typeof last == "number")
|
|
343
358
|
throw Error("Op has a trailing skip");
|
|
344
|
-
};
|
|
345
|
-
function
|
|
346
|
-
let
|
|
347
|
-
for (let
|
|
348
|
-
const
|
|
349
|
-
switch (
|
|
359
|
+
}, "checkOp");
|
|
360
|
+
function eachOp(op, fn) {
|
|
361
|
+
let prePos = 0, postPos = 0;
|
|
362
|
+
for (let i = 0; i < op.length; i++) {
|
|
363
|
+
const c = op[i];
|
|
364
|
+
switch (fn(c, prePos, postPos), typeof c) {
|
|
350
365
|
case "object":
|
|
351
|
-
|
|
366
|
+
prePos += exports.dlen(c.d);
|
|
352
367
|
break;
|
|
353
368
|
case "string":
|
|
354
|
-
|
|
369
|
+
postPos += unicount_1.strPosToUni(c);
|
|
355
370
|
break;
|
|
356
371
|
case "number":
|
|
357
|
-
|
|
372
|
+
prePos += c, postPos += c;
|
|
358
373
|
break;
|
|
359
374
|
}
|
|
360
375
|
}
|
|
361
376
|
}
|
|
362
|
-
|
|
363
|
-
function
|
|
364
|
-
const
|
|
365
|
-
return
|
|
366
|
-
|
|
367
|
-
}),
|
|
377
|
+
__name(eachOp, "eachOp"), exports.eachOp = eachOp;
|
|
378
|
+
function mapOp(op, fn) {
|
|
379
|
+
const newOp = [], append = makeAppend(newOp);
|
|
380
|
+
return eachOp(op, (c, prePos, postPos) => {
|
|
381
|
+
append(fn(c, prePos, postPos));
|
|
382
|
+
}), trim(newOp);
|
|
368
383
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
384
|
+
__name(mapOp, "mapOp");
|
|
385
|
+
const id = /* @__PURE__ */ __name((x) => x, "id"), normalize = /* @__PURE__ */ __name((op) => mapOp(op, id), "normalize");
|
|
386
|
+
exports.dlen = (d) => typeof d == "number" ? d : unicount_1.strPosToUni(d);
|
|
387
|
+
const makeAppend = /* @__PURE__ */ __name((op) => (component) => {
|
|
388
|
+
if (!(!component || component.d === 0 || component.d === "")) if (op.length === 0)
|
|
389
|
+
op.push(component);
|
|
390
|
+
else if (typeof component == typeof op[op.length - 1])
|
|
391
|
+
if (typeof component == "object") {
|
|
392
|
+
const last = op[op.length - 1];
|
|
393
|
+
last.d = typeof last.d == "string" && typeof component.d == "string" ? last.d + component.d : exports.dlen(last.d) + exports.dlen(component.d);
|
|
378
394
|
} else
|
|
379
|
-
|
|
395
|
+
op[op.length - 1] += component;
|
|
380
396
|
else
|
|
381
|
-
|
|
382
|
-
},
|
|
383
|
-
|
|
384
|
-
const
|
|
385
|
-
return
|
|
397
|
+
op.push(component);
|
|
398
|
+
}, "makeAppend"), componentLength = /* @__PURE__ */ __name((c) => typeof c == "number" ? c : typeof c == "string" ? unicount_1.strPosToUni(c) : typeof c.d == "number" ? c.d : unicount_1.strPosToUni(c.d), "componentLength");
|
|
399
|
+
exports.uniSlice = (s, startUni, endUni) => {
|
|
400
|
+
const start = unicount_1.uniToStrPos(s, startUni), end = endUni == null ? 1 / 0 : unicount_1.uniToStrPos(s, endUni);
|
|
401
|
+
return s.slice(start, end);
|
|
386
402
|
};
|
|
387
|
-
const
|
|
388
|
-
let
|
|
389
|
-
return { take: (
|
|
390
|
-
if (
|
|
391
|
-
return
|
|
392
|
-
const
|
|
393
|
-
let
|
|
394
|
-
if (typeof
|
|
395
|
-
return
|
|
396
|
-
if (typeof
|
|
397
|
-
if (
|
|
398
|
-
return
|
|
403
|
+
const dslice = /* @__PURE__ */ __name((d, start, end) => typeof d == "number" ? end == null ? d - start : Math.min(d, end) - start : exports.uniSlice(d, start, end), "dslice"), makeTake = /* @__PURE__ */ __name((op) => {
|
|
404
|
+
let idx = 0, offset = 0;
|
|
405
|
+
return { take: /* @__PURE__ */ __name((n, indivisableField) => {
|
|
406
|
+
if (idx === op.length)
|
|
407
|
+
return n === -1 ? null : n;
|
|
408
|
+
const c = op[idx];
|
|
409
|
+
let part;
|
|
410
|
+
if (typeof c == "number")
|
|
411
|
+
return n === -1 || c - offset <= n ? (part = c - offset, ++idx, offset = 0, part) : (offset += n, n);
|
|
412
|
+
if (typeof c == "string") {
|
|
413
|
+
if (n === -1 || indivisableField === "i" || unicount_1.strPosToUni(c.slice(offset)) <= n)
|
|
414
|
+
return part = c.slice(offset), ++idx, offset = 0, part;
|
|
399
415
|
{
|
|
400
|
-
const
|
|
401
|
-
return
|
|
416
|
+
const offset2 = offset + unicount_1.uniToStrPos(c.slice(offset), n);
|
|
417
|
+
return part = c.slice(offset, offset2), offset = offset2, part;
|
|
402
418
|
}
|
|
403
419
|
} else {
|
|
404
|
-
if (
|
|
405
|
-
return
|
|
420
|
+
if (n === -1 || indivisableField === "d" || exports.dlen(c.d) - offset <= n)
|
|
421
|
+
return part = { d: dslice(c.d, offset) }, ++idx, offset = 0, part;
|
|
406
422
|
{
|
|
407
|
-
let
|
|
408
|
-
return
|
|
423
|
+
let result = dslice(c.d, offset, offset + n);
|
|
424
|
+
return offset += n, { d: result };
|
|
409
425
|
}
|
|
410
426
|
}
|
|
411
|
-
}, peek: () =>
|
|
412
|
-
},
|
|
413
|
-
function
|
|
414
|
-
if (
|
|
415
|
-
throw Error("side (" +
|
|
416
|
-
|
|
417
|
-
const
|
|
418
|
-
for (let
|
|
419
|
-
const
|
|
420
|
-
let
|
|
421
|
-
switch (typeof
|
|
427
|
+
}, "take"), peek: /* @__PURE__ */ __name(() => op[idx], "peek") };
|
|
428
|
+
}, "makeTake"), trim = /* @__PURE__ */ __name((op) => (op.length > 0 && typeof op[op.length - 1] == "number" && op.pop(), op), "trim");
|
|
429
|
+
function transform(op1, op2, side) {
|
|
430
|
+
if (side !== "left" && side !== "right")
|
|
431
|
+
throw Error("side (" + side + ") must be 'left' or 'right'");
|
|
432
|
+
checkOp(op1), checkOp(op2);
|
|
433
|
+
const newOp = [], append = makeAppend(newOp), { take, peek } = makeTake(op1);
|
|
434
|
+
for (let i = 0; i < op2.length; i++) {
|
|
435
|
+
const c2 = op2[i];
|
|
436
|
+
let length, c1;
|
|
437
|
+
switch (typeof c2) {
|
|
422
438
|
case "number":
|
|
423
|
-
for (
|
|
424
|
-
|
|
439
|
+
for (length = c2; length > 0; )
|
|
440
|
+
c1 = take(length, "i"), append(c1), typeof c1 != "string" && (length -= componentLength(c1));
|
|
425
441
|
break;
|
|
426
442
|
case "string":
|
|
427
|
-
|
|
443
|
+
side === "left" && typeof peek() == "string" && append(take(-1)), append(unicount_1.strPosToUni(c2));
|
|
428
444
|
break;
|
|
429
445
|
case "object":
|
|
430
|
-
for (
|
|
431
|
-
switch (
|
|
446
|
+
for (length = exports.dlen(c2.d); length > 0; )
|
|
447
|
+
switch (c1 = take(length, "i"), typeof c1) {
|
|
432
448
|
case "number":
|
|
433
|
-
|
|
449
|
+
length -= c1;
|
|
434
450
|
break;
|
|
435
451
|
case "string":
|
|
436
|
-
|
|
452
|
+
append(c1);
|
|
437
453
|
break;
|
|
438
454
|
case "object":
|
|
439
|
-
|
|
455
|
+
length -= exports.dlen(c1.d);
|
|
440
456
|
}
|
|
441
457
|
break;
|
|
442
458
|
}
|
|
443
459
|
}
|
|
444
|
-
let
|
|
445
|
-
for (;
|
|
446
|
-
|
|
447
|
-
return
|
|
460
|
+
let c;
|
|
461
|
+
for (; c = take(-1); )
|
|
462
|
+
append(c);
|
|
463
|
+
return trim(newOp);
|
|
448
464
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
465
|
+
__name(transform, "transform");
|
|
466
|
+
function compose(op1, op2) {
|
|
467
|
+
checkOp(op1), checkOp(op2);
|
|
468
|
+
const result = [], append = makeAppend(result), { take } = makeTake(op1);
|
|
469
|
+
for (let i = 0; i < op2.length; i++) {
|
|
470
|
+
const component = op2[i];
|
|
471
|
+
let length, chunk;
|
|
472
|
+
switch (typeof component) {
|
|
456
473
|
case "number":
|
|
457
|
-
for (
|
|
458
|
-
|
|
474
|
+
for (length = component; length > 0; )
|
|
475
|
+
chunk = take(length, "d"), append(chunk), typeof chunk != "object" && (length -= componentLength(chunk));
|
|
459
476
|
break;
|
|
460
477
|
case "string":
|
|
461
|
-
|
|
478
|
+
append(component);
|
|
462
479
|
break;
|
|
463
480
|
case "object":
|
|
464
|
-
|
|
465
|
-
let
|
|
466
|
-
for (;
|
|
467
|
-
switch (
|
|
481
|
+
length = exports.dlen(component.d);
|
|
482
|
+
let offset = 0;
|
|
483
|
+
for (; offset < length; )
|
|
484
|
+
switch (chunk = take(length - offset, "d"), typeof chunk) {
|
|
468
485
|
case "number":
|
|
469
|
-
|
|
486
|
+
append({ d: dslice(component.d, offset, offset + chunk) }), offset += chunk;
|
|
470
487
|
break;
|
|
471
488
|
case "string":
|
|
472
|
-
|
|
489
|
+
offset += unicount_1.strPosToUni(chunk);
|
|
473
490
|
break;
|
|
474
491
|
case "object":
|
|
475
|
-
|
|
492
|
+
append(chunk);
|
|
476
493
|
}
|
|
477
494
|
break;
|
|
478
495
|
}
|
|
479
496
|
}
|
|
480
|
-
let
|
|
481
|
-
for (;
|
|
482
|
-
|
|
483
|
-
return
|
|
497
|
+
let c;
|
|
498
|
+
for (; c = take(-1); )
|
|
499
|
+
append(c);
|
|
500
|
+
return trim(result);
|
|
484
501
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
502
|
+
__name(compose, "compose");
|
|
503
|
+
const transformPosition = /* @__PURE__ */ __name((cursor2, op) => {
|
|
504
|
+
let pos = 0;
|
|
505
|
+
for (let i = 0; i < op.length && cursor2 > pos; i++) {
|
|
506
|
+
const c = op[i];
|
|
507
|
+
switch (typeof c) {
|
|
490
508
|
case "number": {
|
|
491
|
-
|
|
509
|
+
pos += c;
|
|
492
510
|
break;
|
|
493
511
|
}
|
|
494
512
|
case "string":
|
|
495
|
-
const
|
|
496
|
-
|
|
513
|
+
const offset = unicount_1.strPosToUni(c);
|
|
514
|
+
pos += offset, cursor2 += offset;
|
|
497
515
|
break;
|
|
498
516
|
case "object":
|
|
499
|
-
|
|
517
|
+
cursor2 -= Math.min(exports.dlen(c.d), cursor2 - pos);
|
|
500
518
|
break;
|
|
501
519
|
}
|
|
502
520
|
}
|
|
503
|
-
return
|
|
504
|
-
},
|
|
505
|
-
function
|
|
506
|
-
return
|
|
521
|
+
return cursor2;
|
|
522
|
+
}, "transformPosition"), transformSelection = /* @__PURE__ */ __name((selection, op) => typeof selection == "number" ? transformPosition(selection, op) : selection.map((s) => transformPosition(s, op)), "transformSelection");
|
|
523
|
+
function makeInvertible(op, doc, ropeImpl) {
|
|
524
|
+
return mapOp(op, (c, prePos) => typeof c == "object" && typeof c.d == "number" ? { d: ropeImpl.slice(doc, prePos, prePos + c.d) } : c);
|
|
507
525
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
526
|
+
__name(makeInvertible, "makeInvertible");
|
|
527
|
+
function invert(op) {
|
|
528
|
+
return mapOp(op, (c) => {
|
|
529
|
+
switch (typeof c) {
|
|
511
530
|
case "object":
|
|
512
|
-
if (typeof
|
|
531
|
+
if (typeof c.d == "number")
|
|
513
532
|
throw Error("Cannot invert text op: Deleted characters missing from operation. makeInvertible must be called first.");
|
|
514
|
-
return
|
|
533
|
+
return c.d;
|
|
515
534
|
// delete -> insert
|
|
516
535
|
case "string":
|
|
517
|
-
return { d:
|
|
536
|
+
return { d: c };
|
|
518
537
|
// Insert -> delete
|
|
519
538
|
case "number":
|
|
520
|
-
return
|
|
539
|
+
return c;
|
|
521
540
|
}
|
|
522
541
|
});
|
|
523
542
|
}
|
|
524
|
-
|
|
525
|
-
|
|
543
|
+
__name(invert, "invert");
|
|
544
|
+
function stripInvertible(op) {
|
|
545
|
+
return mapOp(op, (c) => typeof c == "object" && typeof c.d == "string" ? { d: unicount_1.strPosToUni(c.d) } : c);
|
|
526
546
|
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
547
|
+
__name(stripInvertible, "stripInvertible");
|
|
548
|
+
function isInvertible(op) {
|
|
549
|
+
let invertible = !0;
|
|
550
|
+
return eachOp(op, (c) => {
|
|
551
|
+
typeof c == "object" && typeof c.d == "number" && (invertible = !1);
|
|
552
|
+
}), invertible;
|
|
532
553
|
}
|
|
533
|
-
|
|
554
|
+
__name(isInvertible, "isInvertible");
|
|
555
|
+
function makeType(ropeImpl) {
|
|
534
556
|
return {
|
|
535
557
|
name: "text-unicode",
|
|
536
558
|
uri: "http://sharejs.org/types/text-unicode",
|
|
537
|
-
trim
|
|
538
|
-
normalize
|
|
539
|
-
checkOp
|
|
559
|
+
trim,
|
|
560
|
+
normalize,
|
|
561
|
+
checkOp,
|
|
540
562
|
/** Create a new text snapshot.
|
|
541
563
|
*
|
|
542
564
|
* @param {string} initial - initial snapshot data. Optional. Defaults to ''.
|
|
543
565
|
* @returns {Snap} Initial document snapshot object
|
|
544
566
|
*/
|
|
545
|
-
create(
|
|
546
|
-
if (typeof
|
|
567
|
+
create(initial = "") {
|
|
568
|
+
if (typeof initial != "string")
|
|
547
569
|
throw Error("Initial data must be a string");
|
|
548
|
-
return
|
|
570
|
+
return ropeImpl.create(initial);
|
|
549
571
|
},
|
|
550
572
|
/** Apply an operation to a document snapshot
|
|
551
573
|
*/
|
|
552
|
-
apply(
|
|
553
|
-
|
|
554
|
-
const
|
|
555
|
-
for (let
|
|
556
|
-
const
|
|
557
|
-
switch (typeof
|
|
574
|
+
apply(str, op) {
|
|
575
|
+
checkOp(op);
|
|
576
|
+
const builder = ropeImpl.builder(str);
|
|
577
|
+
for (let i = 0; i < op.length; i++) {
|
|
578
|
+
const component = op[i];
|
|
579
|
+
switch (typeof component) {
|
|
558
580
|
case "number":
|
|
559
|
-
|
|
581
|
+
builder.skip(component);
|
|
560
582
|
break;
|
|
561
583
|
case "string":
|
|
562
|
-
|
|
584
|
+
builder.append(component);
|
|
563
585
|
break;
|
|
564
586
|
case "object":
|
|
565
|
-
|
|
587
|
+
builder.del(exports.dlen(component.d));
|
|
566
588
|
break;
|
|
567
589
|
}
|
|
568
590
|
}
|
|
569
|
-
return
|
|
591
|
+
return builder.build();
|
|
570
592
|
},
|
|
571
|
-
transform
|
|
572
|
-
compose
|
|
573
|
-
transformPosition
|
|
574
|
-
transformSelection
|
|
575
|
-
isInvertible
|
|
576
|
-
makeInvertible(
|
|
577
|
-
return
|
|
593
|
+
transform,
|
|
594
|
+
compose,
|
|
595
|
+
transformPosition,
|
|
596
|
+
transformSelection,
|
|
597
|
+
isInvertible,
|
|
598
|
+
makeInvertible(op, doc) {
|
|
599
|
+
return makeInvertible(op, doc, ropeImpl);
|
|
578
600
|
},
|
|
579
|
-
stripInvertible
|
|
580
|
-
invert
|
|
581
|
-
invertWithDoc(
|
|
582
|
-
return
|
|
601
|
+
stripInvertible,
|
|
602
|
+
invert,
|
|
603
|
+
invertWithDoc(op, doc) {
|
|
604
|
+
return invert(makeInvertible(op, doc, ropeImpl));
|
|
583
605
|
},
|
|
584
|
-
isNoop: (
|
|
606
|
+
isNoop: /* @__PURE__ */ __name((op) => op.length === 0, "isNoop")
|
|
585
607
|
};
|
|
586
608
|
}
|
|
587
|
-
|
|
588
|
-
}(
|
|
609
|
+
__name(makeType, "makeType"), exports.default = makeType;
|
|
610
|
+
}(type)), type;
|
|
589
611
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
612
|
+
__name(requireType, "requireType");
|
|
613
|
+
var api = {}, hasRequiredApi;
|
|
614
|
+
function requireApi() {
|
|
615
|
+
if (hasRequiredApi) return api;
|
|
616
|
+
hasRequiredApi = 1, Object.defineProperty(api, "__esModule", { value: !0 });
|
|
617
|
+
const type_1 = requireType(), unicount_1 = requireUnicount();
|
|
618
|
+
function api$1(getSnapshot, submitOp) {
|
|
596
619
|
return {
|
|
597
620
|
// Returns the text content of the document
|
|
598
|
-
get:
|
|
621
|
+
get: getSnapshot,
|
|
599
622
|
// Returns the number of characters in the string
|
|
600
623
|
getLength() {
|
|
601
|
-
return
|
|
624
|
+
return getSnapshot().length;
|
|
602
625
|
},
|
|
603
626
|
// Insert the specified text at the given position in the document
|
|
604
|
-
insert(
|
|
605
|
-
const
|
|
606
|
-
return
|
|
627
|
+
insert(pos, text, callback) {
|
|
628
|
+
const uniPos = unicount_1.strPosToUni(getSnapshot(), pos);
|
|
629
|
+
return submitOp([uniPos, text], callback);
|
|
607
630
|
},
|
|
608
|
-
remove(
|
|
609
|
-
const
|
|
610
|
-
return
|
|
631
|
+
remove(pos, lengthOrContent, callback) {
|
|
632
|
+
const uniPos = unicount_1.strPosToUni(getSnapshot(), pos);
|
|
633
|
+
return submitOp([uniPos, { d: lengthOrContent }], callback);
|
|
611
634
|
},
|
|
612
635
|
// When you use this API, you should implement these two methods
|
|
613
636
|
// in your editing context.
|
|
614
637
|
//onInsert: function(pos, text) {},
|
|
615
638
|
//onRemove: function(pos, removedLength) {},
|
|
616
|
-
_onOp(
|
|
617
|
-
|
|
618
|
-
switch (typeof
|
|
639
|
+
_onOp(op) {
|
|
640
|
+
type_1.eachOp(op, (component, prePos, postPos) => {
|
|
641
|
+
switch (typeof component) {
|
|
619
642
|
case "string":
|
|
620
|
-
this.onInsert && this.onInsert(
|
|
643
|
+
this.onInsert && this.onInsert(postPos, component);
|
|
621
644
|
break;
|
|
622
645
|
case "object":
|
|
623
|
-
const
|
|
624
|
-
this.onRemove && this.onRemove(
|
|
646
|
+
const dl = type_1.dlen(component.d);
|
|
647
|
+
this.onRemove && this.onRemove(postPos, dl);
|
|
625
648
|
}
|
|
626
649
|
});
|
|
627
650
|
},
|
|
@@ -629,1051 +652,1071 @@ function tn() {
|
|
|
629
652
|
onRemove: null
|
|
630
653
|
};
|
|
631
654
|
}
|
|
632
|
-
return
|
|
655
|
+
return __name(api$1, "api$1"), api.default = api$1, api$1.provides = { text: !0 }, api;
|
|
633
656
|
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
657
|
+
__name(requireApi, "requireApi");
|
|
658
|
+
var hasRequiredDist$1;
|
|
659
|
+
function requireDist$1() {
|
|
660
|
+
return hasRequiredDist$1 || (hasRequiredDist$1 = 1, function(exports) {
|
|
661
|
+
var __createBinding = dist.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
662
|
+
k2 === void 0 && (k2 = k), Object.defineProperty(o, k2, { enumerable: !0, get: /* @__PURE__ */ __name(function() {
|
|
663
|
+
return m[k];
|
|
664
|
+
}, "get") });
|
|
665
|
+
} : function(o, m, k, k2) {
|
|
666
|
+
k2 === void 0 && (k2 = k), o[k2] = m[k];
|
|
667
|
+
}), __setModuleDefault = dist.__setModuleDefault || (Object.create ? function(o, v) {
|
|
668
|
+
Object.defineProperty(o, "default", { enumerable: !0, value: v });
|
|
669
|
+
} : function(o, v) {
|
|
670
|
+
o.default = v;
|
|
671
|
+
}), __importStar = dist.__importStar || function(mod) {
|
|
672
|
+
if (mod && mod.__esModule) return mod;
|
|
673
|
+
var result = {};
|
|
674
|
+
if (mod != null) for (var k in mod) Object.hasOwnProperty.call(mod, k) && __createBinding(result, mod, k);
|
|
675
|
+
return __setModuleDefault(result, mod), result;
|
|
676
|
+
}, __importDefault = dist.__importDefault || function(mod) {
|
|
677
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
654
678
|
};
|
|
655
|
-
Object.defineProperty(
|
|
656
|
-
const
|
|
657
|
-
create(
|
|
658
|
-
return
|
|
679
|
+
Object.defineProperty(exports, "__esModule", { value: !0 }), exports.type = exports.remove = exports.insert = void 0;
|
|
680
|
+
const unicount_1 = requireUnicount(), type_1 = __importStar(requireType()), api_1 = __importDefault(requireApi()), ropeImplUnicodeString = {
|
|
681
|
+
create(s) {
|
|
682
|
+
return s;
|
|
659
683
|
},
|
|
660
|
-
toString(
|
|
661
|
-
return
|
|
684
|
+
toString(s) {
|
|
685
|
+
return s;
|
|
662
686
|
},
|
|
663
|
-
builder(
|
|
664
|
-
if (typeof
|
|
665
|
-
throw Error("Invalid document snapshot: " +
|
|
666
|
-
const
|
|
687
|
+
builder(oldDoc) {
|
|
688
|
+
if (typeof oldDoc != "string")
|
|
689
|
+
throw Error("Invalid document snapshot: " + oldDoc);
|
|
690
|
+
const newDoc = [];
|
|
667
691
|
return {
|
|
668
|
-
skip(
|
|
669
|
-
let
|
|
670
|
-
if (
|
|
692
|
+
skip(n) {
|
|
693
|
+
let offset = unicount_1.uniToStrPos(oldDoc, n);
|
|
694
|
+
if (offset > oldDoc.length)
|
|
671
695
|
throw Error("The op is too long for this document");
|
|
672
|
-
|
|
696
|
+
newDoc.push(oldDoc.slice(0, offset)), oldDoc = oldDoc.slice(offset);
|
|
673
697
|
},
|
|
674
|
-
append(
|
|
675
|
-
|
|
698
|
+
append(s) {
|
|
699
|
+
newDoc.push(s);
|
|
676
700
|
},
|
|
677
|
-
del(
|
|
678
|
-
|
|
701
|
+
del(n) {
|
|
702
|
+
oldDoc = oldDoc.slice(unicount_1.uniToStrPos(oldDoc, n));
|
|
679
703
|
},
|
|
680
704
|
build() {
|
|
681
|
-
return
|
|
705
|
+
return newDoc.join("") + oldDoc;
|
|
682
706
|
}
|
|
683
707
|
};
|
|
684
708
|
},
|
|
685
|
-
slice:
|
|
686
|
-
},
|
|
687
|
-
|
|
688
|
-
var
|
|
689
|
-
Object.defineProperty(
|
|
690
|
-
return
|
|
691
|
-
} });
|
|
692
|
-
}(
|
|
709
|
+
slice: type_1.uniSlice
|
|
710
|
+
}, textString = type_1.default(ropeImplUnicodeString), type2 = Object.assign(Object.assign({}, textString), { api: api_1.default });
|
|
711
|
+
exports.type = type2, exports.insert = (pos, text) => text.length === 0 ? [] : pos === 0 ? [text] : [pos, text], exports.remove = (pos, textOrLen) => type_1.dlen(textOrLen) === 0 ? [] : pos === 0 ? [{ d: textOrLen }] : [pos, { d: textOrLen }];
|
|
712
|
+
var type_2 = requireType();
|
|
713
|
+
Object.defineProperty(exports, "makeType", { enumerable: !0, get: /* @__PURE__ */ __name(function() {
|
|
714
|
+
return type_2.default;
|
|
715
|
+
}, "get") });
|
|
716
|
+
}(dist)), dist;
|
|
693
717
|
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
718
|
+
__name(requireDist$1, "requireDist$1");
|
|
719
|
+
var hasRequiredJson1_release;
|
|
720
|
+
function requireJson1_release() {
|
|
721
|
+
return hasRequiredJson1_release || (hasRequiredJson1_release = 1, function(exports) {
|
|
722
|
+
var __importDefault = json1_release.__importDefault || function(mod) {
|
|
723
|
+
return mod && mod.__esModule ? mod : {
|
|
724
|
+
default: mod
|
|
700
725
|
};
|
|
701
726
|
};
|
|
702
|
-
Object.defineProperty(
|
|
727
|
+
Object.defineProperty(exports, "__esModule", {
|
|
703
728
|
value: !0
|
|
704
|
-
}),
|
|
705
|
-
const
|
|
706
|
-
function
|
|
707
|
-
if (!
|
|
729
|
+
}), exports.editOp = exports.replaceOp = exports.insertOp = exports.moveOp = exports.removeOp = exports.type = void 0;
|
|
730
|
+
const deepEqual_js_1 = __importDefault(requireDeepEqual()), deepClone_js_1 = __importDefault(requireDeepClone()), cursor_js_1 = requireCursor(), types_js_1 = requireTypes();
|
|
731
|
+
function assert(pred, msg) {
|
|
732
|
+
if (!pred) throw new Error(msg);
|
|
708
733
|
}
|
|
709
|
-
|
|
734
|
+
__name(assert, "assert"), exports.type = {
|
|
710
735
|
name: "json1",
|
|
711
736
|
uri: "http://sharejs.org/types/JSONv1",
|
|
712
|
-
readCursor:
|
|
713
|
-
writeCursor:
|
|
714
|
-
create: (
|
|
715
|
-
isNoop: (
|
|
716
|
-
setDebug(
|
|
737
|
+
readCursor: cursor_js_1.readCursor,
|
|
738
|
+
writeCursor: cursor_js_1.writeCursor,
|
|
739
|
+
create: /* @__PURE__ */ __name((data) => data, "create"),
|
|
740
|
+
isNoop: /* @__PURE__ */ __name((op) => op == null, "isNoop"),
|
|
741
|
+
setDebug(val) {
|
|
717
742
|
},
|
|
718
|
-
registerSubtype
|
|
719
|
-
checkValidOp
|
|
720
|
-
normalize
|
|
721
|
-
apply
|
|
722
|
-
transformPosition
|
|
723
|
-
compose
|
|
724
|
-
tryTransform
|
|
725
|
-
transform
|
|
726
|
-
makeInvertible
|
|
727
|
-
invert
|
|
728
|
-
invertWithDoc
|
|
729
|
-
RM_UNEXPECTED_CONTENT:
|
|
730
|
-
DROP_COLLISION:
|
|
731
|
-
BLACKHOLE:
|
|
732
|
-
transformNoConflict: (
|
|
733
|
-
typeAllowingConflictsPred: (
|
|
734
|
-
transform: (
|
|
735
|
-
})
|
|
743
|
+
registerSubtype,
|
|
744
|
+
checkValidOp,
|
|
745
|
+
normalize,
|
|
746
|
+
apply,
|
|
747
|
+
transformPosition,
|
|
748
|
+
compose,
|
|
749
|
+
tryTransform,
|
|
750
|
+
transform,
|
|
751
|
+
makeInvertible,
|
|
752
|
+
invert,
|
|
753
|
+
invertWithDoc,
|
|
754
|
+
RM_UNEXPECTED_CONTENT: types_js_1.ConflictType.RM_UNEXPECTED_CONTENT,
|
|
755
|
+
DROP_COLLISION: types_js_1.ConflictType.DROP_COLLISION,
|
|
756
|
+
BLACKHOLE: types_js_1.ConflictType.BLACKHOLE,
|
|
757
|
+
transformNoConflict: /* @__PURE__ */ __name((op1, op2, side) => transformWithConflictsPred(() => !0, op1, op2, side), "transformNoConflict"),
|
|
758
|
+
typeAllowingConflictsPred: /* @__PURE__ */ __name((allowConflict) => Object.assign(Object.assign({}, exports.type), {
|
|
759
|
+
transform: /* @__PURE__ */ __name((op1, op2, side) => transformWithConflictsPred(allowConflict, op1, op2, side), "transform")
|
|
760
|
+
}), "typeAllowingConflictsPred")
|
|
736
761
|
};
|
|
737
|
-
const
|
|
738
|
-
function
|
|
739
|
-
return
|
|
762
|
+
const getComponent = /* @__PURE__ */ __name((r) => r ? r.getComponent() : null, "getComponent");
|
|
763
|
+
function isObject(o) {
|
|
764
|
+
return o && typeof o == "object" && !Array.isArray(o);
|
|
740
765
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
766
|
+
__name(isObject, "isObject");
|
|
767
|
+
const shallowClone = /* @__PURE__ */ __name((obj) => Array.isArray(obj) ? obj.slice() : obj !== null && typeof obj == "object" ? Object.assign({}, obj) : obj, "shallowClone"), hasPick = /* @__PURE__ */ __name((c) => c && (c.p != null || c.r !== void 0), "hasPick"), hasDrop = /* @__PURE__ */ __name((c) => c && (c.d != null || c.i !== void 0), "hasDrop");
|
|
768
|
+
function removeChild(container, key) {
|
|
769
|
+
return assert(container != null), typeof key == "number" ? (assert(Array.isArray(container), "Invalid key - child is not an array"), (container = container.slice()).splice(key, 1)) : (assert(isObject(container), "Invalid key - child is not an object"), delete (container = Object.assign({}, container))[key]), container;
|
|
744
770
|
}
|
|
745
|
-
|
|
746
|
-
|
|
771
|
+
__name(removeChild, "removeChild");
|
|
772
|
+
function insertChildMut(container, key, value) {
|
|
773
|
+
return typeof key == "number" ? (assert(container != null, "Container is missing for key"), assert(Array.isArray(container), "Cannot use numerical key for object container"), assert(container.length >= key, "Cannot insert into out of bounds index"), container.splice(key, 0, value)) : (assert(isObject(container), "Cannot insert into missing item"), assert(container[key] === void 0, "Trying to overwrite value at key. Your op needs to remove it first"), container[key] = value), value;
|
|
747
774
|
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
}).get(),
|
|
751
|
-
const
|
|
752
|
-
function
|
|
753
|
-
let
|
|
754
|
-
|
|
775
|
+
__name(insertChildMut, "insertChildMut"), exports.removeOp = (path, value = !0) => cursor_js_1.writeCursor().writeAtPath(path, "r", value).get(), exports.moveOp = (from, to) => cursor_js_1.writeCursor().writeMove(from, to).get(), exports.insertOp = (path, value) => cursor_js_1.writeCursor().writeAtPath(path, "i", value).get(), exports.replaceOp = (path, oldVal, newVal) => cursor_js_1.writeCursor().at(path, (w) => {
|
|
776
|
+
w.write("r", oldVal), w.write("i", newVal);
|
|
777
|
+
}).get(), exports.editOp = (path, type2, subOp, preserveNoop = !1) => cursor_js_1.writeCursor().at(path, (w) => writeEdit(w, type2, subOp, preserveNoop)).get();
|
|
778
|
+
const isValidKey = /* @__PURE__ */ __name((container, key) => container != null && (typeof key == "number" ? Array.isArray(container) : typeof container == "object"), "isValidKey"), maybeGetChild = /* @__PURE__ */ __name((container, key) => isValidKey(container, key) ? container[key] : void 0, "maybeGetChild"), subtypes = {};
|
|
779
|
+
function registerSubtype(subtype) {
|
|
780
|
+
let _subtype = subtype.type ? subtype.type : subtype;
|
|
781
|
+
_subtype.name && (subtypes[_subtype.name] = _subtype), _subtype.uri && (subtypes[_subtype.uri] = _subtype);
|
|
755
782
|
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
783
|
+
__name(registerSubtype, "registerSubtype");
|
|
784
|
+
const typeOrThrow = /* @__PURE__ */ __name((name) => {
|
|
785
|
+
const type2 = subtypes[name];
|
|
786
|
+
if (type2) return type2;
|
|
787
|
+
throw Error("Missing type: " + name);
|
|
788
|
+
}, "typeOrThrow");
|
|
789
|
+
registerSubtype(requireDist$1());
|
|
790
|
+
const add = /* @__PURE__ */ __name((a, b) => a + b, "add");
|
|
791
|
+
registerSubtype({
|
|
764
792
|
name: "number",
|
|
765
|
-
apply:
|
|
766
|
-
compose:
|
|
767
|
-
invert: (
|
|
768
|
-
transform: (
|
|
793
|
+
apply: add,
|
|
794
|
+
compose: add,
|
|
795
|
+
invert: /* @__PURE__ */ __name((n) => -n, "invert"),
|
|
796
|
+
transform: /* @__PURE__ */ __name((a) => a, "transform")
|
|
769
797
|
});
|
|
770
|
-
const
|
|
771
|
-
const [
|
|
772
|
-
!
|
|
773
|
-
};
|
|
774
|
-
function
|
|
775
|
-
|
|
798
|
+
const getEditType = /* @__PURE__ */ __name((c) => c == null ? null : c.et ? typeOrThrow(c.et) : c.es ? subtypes["text-unicode"] : c.ena != null ? subtypes.number : null, "getEditType"), getEdit = /* @__PURE__ */ __name((c) => c.es ? c.es : c.ena != null ? c.ena : c.e, "getEdit"), writeEdit = /* @__PURE__ */ __name((w, typeOrName, edit, preserveNoop = !1) => {
|
|
799
|
+
const [type2, name] = typeof typeOrName == "string" ? [typeOrThrow(typeOrName), typeOrName] : [typeOrName, typeOrName.name];
|
|
800
|
+
!preserveNoop && type2.isNoop && type2.isNoop(edit) || (name === "number" ? w.write("ena", edit) : name === "text-unicode" ? w.write("es", edit) : (w.write("et", name), w.write("e", edit)));
|
|
801
|
+
}, "writeEdit");
|
|
802
|
+
function checkNonNegInteger(n) {
|
|
803
|
+
assert(typeof n == "number"), assert(n >= 0), assert(n === (0 | n));
|
|
776
804
|
}
|
|
777
|
-
|
|
778
|
-
|
|
805
|
+
__name(checkNonNegInteger, "checkNonNegInteger");
|
|
806
|
+
function checkScalar(s) {
|
|
807
|
+
typeof s == "number" ? checkNonNegInteger(s) : assert(typeof s == "string");
|
|
779
808
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
else if (
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
809
|
+
__name(checkScalar, "checkScalar");
|
|
810
|
+
function checkValidOp(op) {
|
|
811
|
+
if (op === null) return;
|
|
812
|
+
const pickedSlots = /* @__PURE__ */ new Set(), droppedSlots = /* @__PURE__ */ new Set(), checkComponent = /* @__PURE__ */ __name((e) => {
|
|
813
|
+
let empty = !0, hasEdit = !1;
|
|
814
|
+
for (let k in e) {
|
|
815
|
+
const v = e[k];
|
|
816
|
+
if (empty = !1, assert(k === "p" || k === "r" || k === "d" || k === "i" || k === "e" || k === "es" || k === "ena" || k === "et", "Invalid component item '" + k + "'"), k === "p") checkNonNegInteger(v), assert(!pickedSlots.has(v)), pickedSlots.add(v), assert(e.r === void 0);
|
|
817
|
+
else if (k === "d") checkNonNegInteger(v), assert(!droppedSlots.has(v)), droppedSlots.add(v), assert(e.i === void 0);
|
|
818
|
+
else if (k === "e" || k === "es" || k === "ena") {
|
|
819
|
+
assert(!hasEdit), hasEdit = !0;
|
|
820
|
+
const t = getEditType(e);
|
|
821
|
+
assert(t, "Missing type in edit"), t.checkValidOp && t.checkValidOp(getEdit(e));
|
|
792
822
|
}
|
|
793
823
|
}
|
|
794
|
-
|
|
795
|
-
},
|
|
796
|
-
if (!Array.isArray(
|
|
797
|
-
if (
|
|
798
|
-
|
|
799
|
-
let
|
|
800
|
-
for (let
|
|
801
|
-
const
|
|
802
|
-
if (
|
|
803
|
-
const
|
|
804
|
-
if (
|
|
805
|
-
const
|
|
806
|
-
|
|
824
|
+
assert(!empty);
|
|
825
|
+
}, "checkComponent"), checkDescent = /* @__PURE__ */ __name((descent, isRoot, removed) => {
|
|
826
|
+
if (!Array.isArray(descent)) throw Error("Op must be null or a list");
|
|
827
|
+
if (descent.length === 0) throw Error("Empty descent");
|
|
828
|
+
isRoot || checkScalar(descent[0]);
|
|
829
|
+
let last = 1, numDescents = 0, lastKey = 0;
|
|
830
|
+
for (let i = 0; i < descent.length; i++) {
|
|
831
|
+
const d = descent[i];
|
|
832
|
+
if (assert(d != null), Array.isArray(d)) {
|
|
833
|
+
const key = checkDescent(d, !1);
|
|
834
|
+
if (numDescents) {
|
|
835
|
+
const t1 = typeof lastKey, t2 = typeof key;
|
|
836
|
+
t1 === t2 ? assert(lastKey < key, "descent keys are not in order") : assert(t1 === "number" && t2 === "string");
|
|
807
837
|
}
|
|
808
|
-
|
|
809
|
-
} else typeof
|
|
838
|
+
lastKey = key, numDescents++, last = 3;
|
|
839
|
+
} else typeof d == "object" ? (assert(last === 1, `Prev not scalar - instead ${last}`), checkComponent(d), last = 2) : (assert(last !== 3), checkScalar(d), assert(cursor_js_1.isValidPathItem(d), "Invalid path key"), last = 1);
|
|
810
840
|
}
|
|
811
|
-
return
|
|
812
|
-
};
|
|
813
|
-
|
|
814
|
-
for (let
|
|
841
|
+
return assert(numDescents !== 1, "Operation makes multiple descents. Remove some []"), assert(last === 2 || last === 3), descent[0];
|
|
842
|
+
}, "checkDescent");
|
|
843
|
+
checkDescent(op, !0), assert(pickedSlots.size === droppedSlots.size, "Mismatched picks and drops in op");
|
|
844
|
+
for (let i = 0; i < pickedSlots.size; i++) assert(pickedSlots.has(i)), assert(droppedSlots.has(i));
|
|
815
845
|
}
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
846
|
+
__name(checkValidOp, "checkValidOp");
|
|
847
|
+
function normalize(op) {
|
|
848
|
+
let nextSlot = 0, slotMap = [];
|
|
849
|
+
const w = cursor_js_1.writeCursor();
|
|
850
|
+
return w.mergeTree(op, (c, w2) => {
|
|
851
|
+
const t = getEditType(c);
|
|
852
|
+
if (t) {
|
|
853
|
+
const op2 = getEdit(c);
|
|
854
|
+
writeEdit(w2, t, t.normalize ? t.normalize(op2) : op2);
|
|
824
855
|
}
|
|
825
|
-
for (const
|
|
826
|
-
const
|
|
827
|
-
|
|
856
|
+
for (const k of ["r", "p", "i", "d"]) if (c[k] !== void 0) {
|
|
857
|
+
const r = k === "p" || k === "d" ? (inSlot = c[k], slotMap[inSlot] == null && (slotMap[inSlot] = nextSlot++), slotMap[inSlot]) : c[k];
|
|
858
|
+
w2.write(k, r);
|
|
828
859
|
}
|
|
829
|
-
var
|
|
830
|
-
}),
|
|
860
|
+
var inSlot;
|
|
861
|
+
}), w.get();
|
|
831
862
|
}
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
863
|
+
__name(normalize, "normalize");
|
|
864
|
+
function apply(snapshot, op) {
|
|
865
|
+
if (checkValidOp(op), op === null) return snapshot;
|
|
866
|
+
const held = [];
|
|
867
|
+
return (/* @__PURE__ */ __name(function drop(root, descent) {
|
|
868
|
+
let subDoc = root, i = 0, rootContainer = {
|
|
869
|
+
root
|
|
870
|
+
}, m = 0, container = rootContainer, key = "root";
|
|
871
|
+
function mut() {
|
|
872
|
+
for (; m < i; m++) {
|
|
873
|
+
let d = descent[m];
|
|
874
|
+
typeof d != "object" && (assert(isValidKey(container, key)), container = container[key] = shallowClone(container[key]), key = d);
|
|
843
875
|
}
|
|
844
876
|
}
|
|
845
|
-
for (;
|
|
846
|
-
const
|
|
847
|
-
if (Array.isArray(
|
|
848
|
-
const
|
|
849
|
-
|
|
850
|
-
} else if (typeof
|
|
851
|
-
|
|
852
|
-
const
|
|
853
|
-
if (
|
|
854
|
-
else if (
|
|
855
|
-
} else
|
|
877
|
+
for (__name(mut, "mut"); i < descent.length; i++) {
|
|
878
|
+
const d = descent[i];
|
|
879
|
+
if (Array.isArray(d)) {
|
|
880
|
+
const child = drop(subDoc, d);
|
|
881
|
+
child !== subDoc && child !== void 0 && (mut(), subDoc = container[key] = child);
|
|
882
|
+
} else if (typeof d == "object") {
|
|
883
|
+
d.d != null ? (mut(), subDoc = insertChildMut(container, key, held[d.d])) : d.i !== void 0 && (mut(), subDoc = insertChildMut(container, key, d.i));
|
|
884
|
+
const t = getEditType(d);
|
|
885
|
+
if (t) mut(), subDoc = container[key] = t.apply(subDoc, getEdit(d));
|
|
886
|
+
else if (d.e !== void 0) throw Error("Subtype " + d.et + " undefined");
|
|
887
|
+
} else subDoc = maybeGetChild(subDoc, d);
|
|
856
888
|
}
|
|
857
|
-
return
|
|
858
|
-
}(
|
|
859
|
-
const
|
|
860
|
-
let
|
|
861
|
-
for (;
|
|
862
|
-
const
|
|
863
|
-
if (Array.isArray(
|
|
864
|
-
typeof
|
|
889
|
+
return rootContainer.root;
|
|
890
|
+
}, "drop"))(snapshot = (/* @__PURE__ */ __name(function pick(subDoc, descent) {
|
|
891
|
+
const stack = [];
|
|
892
|
+
let i = 0;
|
|
893
|
+
for (; i < descent.length; i++) {
|
|
894
|
+
const d = descent[i];
|
|
895
|
+
if (Array.isArray(d)) break;
|
|
896
|
+
typeof d != "object" && (stack.push(subDoc), subDoc = maybeGetChild(subDoc, d));
|
|
865
897
|
}
|
|
866
|
-
for (let
|
|
867
|
-
for (
|
|
868
|
-
const
|
|
869
|
-
if (typeof
|
|
870
|
-
const
|
|
871
|
-
|
|
872
|
-
} else
|
|
898
|
+
for (let j = descent.length - 1; j >= i; j--) subDoc = pick(subDoc, descent[j]);
|
|
899
|
+
for (--i; i >= 0; i--) {
|
|
900
|
+
const d = descent[i];
|
|
901
|
+
if (typeof d != "object") {
|
|
902
|
+
const container = stack.pop();
|
|
903
|
+
subDoc = subDoc === maybeGetChild(container, d) ? container : subDoc === void 0 ? removeChild(container, d) : (k = d, v = subDoc, (obj = shallowClone(obj = container))[k] = v, obj);
|
|
904
|
+
} else hasPick(d) && (assert(subDoc !== void 0, "Cannot pick up or remove undefined"), d.p != null && (held[d.p] = subDoc), subDoc = void 0);
|
|
873
905
|
}
|
|
874
|
-
var
|
|
875
|
-
return
|
|
876
|
-
}(
|
|
906
|
+
var obj, k, v;
|
|
907
|
+
return subDoc;
|
|
908
|
+
}, "pick"))(snapshot, op), op);
|
|
877
909
|
}
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
910
|
+
__name(apply, "apply");
|
|
911
|
+
function transformPosition(path, op) {
|
|
912
|
+
path = path.slice(), checkValidOp(op);
|
|
913
|
+
const r = cursor_js_1.readCursor(op);
|
|
914
|
+
let pickedAtSlot, pickIndex, removed = !1;
|
|
915
|
+
const advStack = [];
|
|
916
|
+
for (let i = 0; ; i++) {
|
|
917
|
+
const k = path[i], c = r.getComponent();
|
|
918
|
+
if (c && (c.r !== void 0 ? removed = !0 : c.p != null && (removed = !1, pickedAtSlot = c.p, pickIndex = i)), i >= path.length) break;
|
|
919
|
+
let pickOffset = 0;
|
|
920
|
+
const pickAdv = cursor_js_1.advancer(r, void 0, (k2, c2) => {
|
|
921
|
+
hasPick(c2) && pickOffset++;
|
|
889
922
|
});
|
|
890
|
-
|
|
891
|
-
const
|
|
892
|
-
if (typeof
|
|
923
|
+
advStack.unshift(pickAdv);
|
|
924
|
+
const hasNext = pickAdv(k);
|
|
925
|
+
if (typeof k == "number" && (path[i] -= pickOffset), !hasNext) break;
|
|
893
926
|
}
|
|
894
|
-
if (
|
|
895
|
-
const
|
|
896
|
-
let
|
|
897
|
-
if (
|
|
898
|
-
const
|
|
899
|
-
|
|
927
|
+
if (advStack.forEach((pickAdv) => pickAdv.end()), removed) return null;
|
|
928
|
+
const handleDrop = /* @__PURE__ */ __name(() => {
|
|
929
|
+
let i = 0;
|
|
930
|
+
if (pickedAtSlot != null) {
|
|
931
|
+
const rPath = r.getPath();
|
|
932
|
+
i = rPath.length, path = rPath.concat(path.slice(pickIndex));
|
|
900
933
|
}
|
|
901
|
-
for (;
|
|
902
|
-
const
|
|
903
|
-
if (
|
|
904
|
-
const
|
|
905
|
-
|
|
934
|
+
for (; i < path.length; i++) {
|
|
935
|
+
const k = path[i], c = getComponent(r), et = getEditType(c);
|
|
936
|
+
if (et) {
|
|
937
|
+
const e = getEdit(c);
|
|
938
|
+
et.transformPosition && (path[i] = et.transformPosition(path[i], e));
|
|
906
939
|
break;
|
|
907
940
|
}
|
|
908
|
-
let
|
|
909
|
-
const
|
|
910
|
-
|
|
911
|
-
})(
|
|
912
|
-
if (typeof
|
|
941
|
+
let dropOffset = 0;
|
|
942
|
+
const hasNext = cursor_js_1.advancer(r, (k2, c2) => hasDrop(c2) ? ~(k2 - dropOffset) : k2 - dropOffset, (k2, c2) => {
|
|
943
|
+
hasDrop(c2) && dropOffset++;
|
|
944
|
+
})(k);
|
|
945
|
+
if (typeof k == "number" && (path[i] += dropOffset), !hasNext) break;
|
|
913
946
|
}
|
|
914
|
-
};
|
|
915
|
-
return
|
|
916
|
-
|
|
917
|
-
}) :
|
|
947
|
+
}, "handleDrop");
|
|
948
|
+
return pickedAtSlot != null ? r.eachDrop(null, (slot) => {
|
|
949
|
+
slot === pickedAtSlot && handleDrop();
|
|
950
|
+
}) : handleDrop(), path;
|
|
918
951
|
}
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
if (
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
952
|
+
__name(transformPosition, "transformPosition");
|
|
953
|
+
function compose(op1, op2) {
|
|
954
|
+
if (checkValidOp(op1), checkValidOp(op2), op1 == null) return op2;
|
|
955
|
+
if (op2 == null) return op1;
|
|
956
|
+
let nextSlot = 0;
|
|
957
|
+
const r1 = cursor_js_1.readCursor(op1), r2 = cursor_js_1.readCursor(op2), w = cursor_js_1.writeCursor(), heldPickWrites = [], heldDropWrites = [], held1Pick = [], held2Drop = [], p1SlotMap = [], p2SlotMap = [], visitedOp2EditCs = /* @__PURE__ */ new Set();
|
|
958
|
+
r1.traverse(null, (c) => {
|
|
959
|
+
c.p != null && (held1Pick[c.p] = r1.clone());
|
|
960
|
+
}), r2.traverse(null, (c) => {
|
|
961
|
+
c.d != null && (held2Drop[c.d] = r2.clone());
|
|
928
962
|
});
|
|
929
|
-
const
|
|
930
|
-
return function
|
|
931
|
-
|
|
932
|
-
const
|
|
933
|
-
if (
|
|
934
|
-
else if (
|
|
963
|
+
const w2 = cursor_js_1.writeCursor();
|
|
964
|
+
return (/* @__PURE__ */ __name(function xfBoundary(r1Pick, r1Drop, r2Pick, r2Drop, litIn, rmParent, wd, wp) {
|
|
965
|
+
assert(r1Drop || r2Pick);
|
|
966
|
+
const c1d = getComponent(r1Drop), c2p = getComponent(r2Pick), rmHere = !!c2p && c2p.r !== void 0, insHere = !!c1d && c1d.i !== void 0, drop1Slot = c1d ? c1d.d : null, pick2Slot = c2p ? c2p.p : null, rmChildren = (rmParent || rmHere) && pick2Slot == null;
|
|
967
|
+
if (pick2Slot != null) r2Drop = held2Drop[pick2Slot], wd = heldDropWrites[pick2Slot] = new cursor_js_1.WriteCursor();
|
|
968
|
+
else if (c2p && c2p.r !== void 0) r2Drop = null;
|
|
935
969
|
else {
|
|
936
|
-
const
|
|
937
|
-
|
|
970
|
+
const c2d2 = getComponent(r2Drop);
|
|
971
|
+
c2d2 && c2d2.d != null && (r2Drop = null);
|
|
938
972
|
}
|
|
939
|
-
const
|
|
940
|
-
if (
|
|
973
|
+
const c2d = getComponent(r2Drop);
|
|
974
|
+
if (drop1Slot != null) if (r1Pick = held1Pick[drop1Slot], wp = heldPickWrites[drop1Slot] = new cursor_js_1.WriteCursor(), rmChildren) rmParent && !rmHere && wp.write("r", !0);
|
|
941
975
|
else {
|
|
942
|
-
const
|
|
943
|
-
|
|
976
|
+
const slot = p1SlotMap[drop1Slot] = nextSlot++;
|
|
977
|
+
wd.write("d", slot);
|
|
944
978
|
}
|
|
945
|
-
else if (
|
|
979
|
+
else if (c1d && c1d.i !== void 0) r1Pick = null;
|
|
946
980
|
else {
|
|
947
|
-
const
|
|
948
|
-
|
|
981
|
+
const c1p = getComponent(r1Pick);
|
|
982
|
+
c1p && c1p.p != null && (r1Pick = null);
|
|
949
983
|
}
|
|
950
|
-
let
|
|
951
|
-
|
|
952
|
-
const
|
|
953
|
-
if (
|
|
954
|
-
if (!(
|
|
955
|
-
const
|
|
956
|
-
|
|
984
|
+
let litOut;
|
|
985
|
+
insHere ? (assert(litIn === void 0), litOut = c1d.i) : litOut = litIn;
|
|
986
|
+
const insComponent = (pick2Slot == null ? !insHere || rmParent || rmHere : litOut === void 0) ? null : wd.getComponent();
|
|
987
|
+
if (pick2Slot != null) {
|
|
988
|
+
if (!(litIn !== void 0 || insHere)) {
|
|
989
|
+
const slot = drop1Slot != null ? p1SlotMap[drop1Slot] : nextSlot++;
|
|
990
|
+
p2SlotMap[pick2Slot] = slot, wp.write("p", slot);
|
|
957
991
|
}
|
|
958
|
-
} else
|
|
959
|
-
const
|
|
960
|
-
if ((
|
|
961
|
-
|
|
962
|
-
const
|
|
963
|
-
|
|
964
|
-
} else
|
|
965
|
-
const
|
|
966
|
-
let
|
|
967
|
-
const
|
|
968
|
-
|
|
969
|
-
}),
|
|
970
|
-
|
|
992
|
+
} else rmHere && (insHere || litIn !== void 0 || (c2p.r, wp.write("r", c2p.r)));
|
|
993
|
+
const type1 = rmChildren ? null : getEditType(c1d), type2 = getEditType(c2d);
|
|
994
|
+
if ((type1 || type2) && (type1 && type1.name, type2 && type2.name), type1 && type2) {
|
|
995
|
+
assert(type1 === type2);
|
|
996
|
+
const e1 = getEdit(c1d), e2 = getEdit(c2d), r = type1.compose(e1, e2);
|
|
997
|
+
writeEdit(wd, type1, r), visitedOp2EditCs.add(c2d);
|
|
998
|
+
} else type1 ? writeEdit(wd, type1, getEdit(c1d)) : type2 && (writeEdit(wd, type2, getEdit(c2d)), visitedOp2EditCs.add(c2d));
|
|
999
|
+
const hasContainerLiteral = typeof litOut == "object" && litOut != null;
|
|
1000
|
+
let isCloned = !1, p1PickOff = 0, p1DropOff = 0, p2PickOff = 0, p2DropOff = 0, litOff = 0;
|
|
1001
|
+
const p2DropAdv = cursor_js_1.advancer(r2Drop, (k, c) => hasDrop(c) ? p2DropOff - k - 1 : k - p2DropOff, (k, c) => {
|
|
1002
|
+
hasDrop(c) && p2DropOff++;
|
|
1003
|
+
}), p1PickAdv = cursor_js_1.advancer(r1Pick, (k, c) => hasPick(c) ? p1PickOff - k - 1 : k - p1PickOff, (k, c) => {
|
|
1004
|
+
hasPick(c) && p1PickOff++;
|
|
971
1005
|
});
|
|
972
|
-
if (
|
|
973
|
-
let
|
|
974
|
-
if (typeof
|
|
975
|
-
let
|
|
976
|
-
|
|
977
|
-
let
|
|
978
|
-
|
|
979
|
-
const
|
|
980
|
-
(
|
|
981
|
-
} else
|
|
982
|
-
|
|
983
|
-
const
|
|
984
|
-
var
|
|
985
|
-
|
|
986
|
-
}),
|
|
987
|
-
else if (
|
|
988
|
-
}(
|
|
989
|
-
const
|
|
990
|
-
if (
|
|
991
|
-
const
|
|
992
|
-
|
|
993
|
-
const
|
|
994
|
-
|
|
995
|
-
} else
|
|
996
|
-
}),
|
|
997
|
-
const
|
|
998
|
-
if (
|
|
999
|
-
const
|
|
1000
|
-
|
|
1001
|
-
const
|
|
1002
|
-
|
|
1003
|
-
} else
|
|
1004
|
-
const
|
|
1005
|
-
|
|
1006
|
-
}),
|
|
1006
|
+
if (cursor_js_1.eachChildOf(r1Drop, r2Pick, (inKey, _p1Drop, _p2Pick) => {
|
|
1007
|
+
let _p1Pick, _p2Drop, p1PickKey = inKey, p2DropKey = inKey, litKey = inKey;
|
|
1008
|
+
if (typeof inKey == "number") {
|
|
1009
|
+
let p2Mid = inKey + p2PickOff;
|
|
1010
|
+
_p2Drop = p2DropAdv(p2Mid), p2DropKey = p2Mid + p2DropOff;
|
|
1011
|
+
let p1Mid = inKey + p1DropOff;
|
|
1012
|
+
_p1Pick = p1PickAdv(p1Mid), hasDrop(getComponent(_p2Drop)) && (_p1Pick = null), p1PickKey = p1Mid + p1PickOff, litKey = inKey + litOff, assert(p1PickKey >= 0, "p1PickKey is negative"), assert(p2DropKey >= 0, "p2DropKey is negative");
|
|
1013
|
+
const hd1 = hasDrop(getComponent(_p1Drop)), hp2 = hasPick(getComponent(_p2Pick));
|
|
1014
|
+
(hd1 || hp2 && !rmChildren) && litOff--, hd1 && p1DropOff--, hp2 && p2PickOff--;
|
|
1015
|
+
} else _p1Pick = p1PickAdv(inKey), _p2Drop = p2DropAdv(inKey);
|
|
1016
|
+
wp.descend(p1PickKey), wd.descend(p2DropKey);
|
|
1017
|
+
const _lit = hasContainerLiteral && !hasDrop(getComponent(_p1Drop)) ? litOut[litKey] : void 0, _litResult = xfBoundary(_p1Pick, _p1Drop, _p2Pick, _p2Drop, _lit, rmChildren, wd, wp);
|
|
1018
|
+
var container, key, child;
|
|
1019
|
+
hasContainerLiteral && !rmChildren ? _lit !== _litResult && (isCloned || (litOut = Array.isArray(litOut) ? litOut.slice() : Object.assign({}, litOut), isCloned = !0), container = litOut, child = _litResult, typeof (key = litKey) == "number" ? (assert(Array.isArray(container)), assert(key < container.length)) : (assert(!Array.isArray(container)), assert(container[key] !== void 0)), child === void 0 ? typeof key == "number" ? container.splice(key, 1) : delete container[key] : container[key] = child) : assert(_litResult === void 0), wd.ascend(), wp.ascend();
|
|
1020
|
+
}), p1PickAdv.end(), p2DropAdv.end(), insComponent != null) insComponent.i = litOut;
|
|
1021
|
+
else if (!rmParent && !rmHere && pick2Slot == null) return litOut;
|
|
1022
|
+
}, "xfBoundary"))(r1, r1.clone(), r2, r2.clone(), void 0, !1, w, w2), w.reset(), w.mergeTree(w2.get()), w.reset(), w.get(), heldPickWrites.map((w3) => w3.get()), heldDropWrites.map((w3) => w3.get()), r1.traverse(w, (c, w3) => {
|
|
1023
|
+
const slot1 = c.p;
|
|
1024
|
+
if (slot1 != null) {
|
|
1025
|
+
const slot = p1SlotMap[slot1];
|
|
1026
|
+
slot != null && w3.write("p", slot);
|
|
1027
|
+
const _w = heldPickWrites[slot1];
|
|
1028
|
+
_w && _w.get(), _w && w3.mergeTree(_w.get());
|
|
1029
|
+
} else c.r !== void 0 && w3.write("r", c.r);
|
|
1030
|
+
}), w.reset(), w.get(), r2.traverse(w, (c, w3) => {
|
|
1031
|
+
const slot2 = c.d;
|
|
1032
|
+
if (slot2 != null) {
|
|
1033
|
+
const slot = p2SlotMap[slot2];
|
|
1034
|
+
slot != null && w3.write("d", slot);
|
|
1035
|
+
const _w = heldDropWrites[slot2];
|
|
1036
|
+
_w && w3.mergeTree(_w.get());
|
|
1037
|
+
} else c.i !== void 0 && w3.write("i", c.i);
|
|
1038
|
+
const t = getEditType(c);
|
|
1039
|
+
t && !visitedOp2EditCs.has(c) && writeEdit(w3, t, getEdit(c));
|
|
1040
|
+
}), w.get();
|
|
1007
1041
|
}
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1042
|
+
__name(compose, "compose");
|
|
1043
|
+
function invert(op) {
|
|
1044
|
+
if (op == null) return null;
|
|
1045
|
+
const r = new cursor_js_1.ReadCursor(op), w = new cursor_js_1.WriteCursor();
|
|
1046
|
+
let editsToTransform;
|
|
1047
|
+
const heldPick = [], heldWrites = [];
|
|
1048
|
+
return (/* @__PURE__ */ __name(function invertSimple(r2, w2, subDoc) {
|
|
1049
|
+
const c = r2.getComponent();
|
|
1050
|
+
let insertHere, subdocModified = !1;
|
|
1051
|
+
if (c) {
|
|
1052
|
+
c.p != null && (w2.write("d", c.p), heldPick[c.p] = r2.clone()), c.r !== void 0 && w2.write("i", c.r), c.d != null && (w2.write("p", c.d), subDoc = void 0), c.i !== void 0 && (subDoc = insertHere = c.i);
|
|
1053
|
+
const t = getEditType(c);
|
|
1054
|
+
t && (subDoc === void 0 ? (editsToTransform || (editsToTransform = /* @__PURE__ */ new Set()), editsToTransform.add(c)) : (getEdit(c), subDoc = t.apply(subDoc, getEdit(c)), subdocModified = !0));
|
|
1020
1055
|
}
|
|
1021
|
-
let
|
|
1022
|
-
for (const
|
|
1023
|
-
|
|
1024
|
-
const
|
|
1025
|
-
|
|
1026
|
-
const
|
|
1027
|
-
if (
|
|
1028
|
-
if (
|
|
1029
|
-
|
|
1056
|
+
let dropOff = 0;
|
|
1057
|
+
for (const key of r2) {
|
|
1058
|
+
w2.descend(key);
|
|
1059
|
+
const raw = typeof key == "number" ? key - dropOff : key, childIn = maybeGetChild(subDoc, raw);
|
|
1060
|
+
hasDrop(r2.getComponent()) && dropOff++;
|
|
1061
|
+
const childOut = invertSimple(r2, w2, childIn);
|
|
1062
|
+
if (subDoc !== void 0 && childOut !== void 0) {
|
|
1063
|
+
if (subdocModified || (subdocModified = !0, subDoc = shallowClone(subDoc)), !isValidKey(subDoc, raw)) throw Error("Cannot modify child - invalid operation");
|
|
1064
|
+
subDoc[raw] = childOut;
|
|
1030
1065
|
}
|
|
1031
|
-
|
|
1066
|
+
w2.ascend();
|
|
1032
1067
|
}
|
|
1033
|
-
if (
|
|
1034
|
-
|
|
1035
|
-
}(
|
|
1036
|
-
const
|
|
1037
|
-
if (
|
|
1038
|
-
const
|
|
1039
|
-
if (
|
|
1040
|
-
const
|
|
1041
|
-
if (!
|
|
1042
|
-
|
|
1068
|
+
if (insertHere === void 0) return subdocModified ? subDoc : void 0;
|
|
1069
|
+
w2.write("r", subDoc);
|
|
1070
|
+
}, "invertSimple"))(r, w, void 0), editsToTransform && (w.reset(), (/* @__PURE__ */ __name(function transformEdits(rPick, rDrop, w2) {
|
|
1071
|
+
const cd = rDrop.getComponent();
|
|
1072
|
+
if (cd) {
|
|
1073
|
+
const dropSlot = cd.d;
|
|
1074
|
+
if (dropSlot != null && (rPick = heldPick[dropSlot], w2 = heldWrites[dropSlot] = cursor_js_1.writeCursor()), editsToTransform.has(cd)) {
|
|
1075
|
+
const t = getEditType(cd);
|
|
1076
|
+
if (!t.invert) throw Error(`Cannot invert subtype ${t.name}`);
|
|
1077
|
+
writeEdit(w2, t, t.invert(getEdit(cd)));
|
|
1043
1078
|
}
|
|
1044
1079
|
}
|
|
1045
|
-
let
|
|
1046
|
-
const
|
|
1047
|
-
|
|
1080
|
+
let pickOff = 0, dropOff = 0;
|
|
1081
|
+
const ap = cursor_js_1.advancer(rPick, (k, c) => hasPick(c) ? pickOff - k - 1 : k - pickOff, (k, c) => {
|
|
1082
|
+
hasPick(c) && pickOff++;
|
|
1048
1083
|
});
|
|
1049
|
-
for (const
|
|
1050
|
-
const
|
|
1051
|
-
|
|
1052
|
-
} else
|
|
1053
|
-
|
|
1054
|
-
}(
|
|
1055
|
-
const
|
|
1056
|
-
if (
|
|
1057
|
-
const
|
|
1058
|
-
|
|
1084
|
+
for (const key of rDrop) if (typeof key == "number") {
|
|
1085
|
+
const mid = key - dropOff, _rPick = ap(mid), raw = mid + pickOff;
|
|
1086
|
+
w2.descend(raw), transformEdits(_rPick, rDrop, w2), hasDrop(rDrop.getComponent()) && dropOff++, w2.ascend();
|
|
1087
|
+
} else w2.descend(key), transformEdits(ap(key), rDrop, w2), w2.ascend();
|
|
1088
|
+
ap.end();
|
|
1089
|
+
}, "transformEdits"))(r.clone(), r, w), heldWrites.length && (w.reset(), r.traverse(w, (c, w2) => {
|
|
1090
|
+
const slot = c.p;
|
|
1091
|
+
if (slot != null) {
|
|
1092
|
+
const _w = heldWrites[slot];
|
|
1093
|
+
_w && _w.get(), _w && w2.mergeTree(_w.get());
|
|
1059
1094
|
}
|
|
1060
|
-
}))),
|
|
1095
|
+
}))), w.get();
|
|
1061
1096
|
}
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1097
|
+
__name(invert, "invert");
|
|
1098
|
+
const anyComponent = /* @__PURE__ */ __name((op, fn) => op.some((c) => typeof c == "object" && (Array.isArray(c) ? anyComponent(c, fn) : fn(c))), "anyComponent");
|
|
1099
|
+
function makeInvertible(op, doc) {
|
|
1100
|
+
if (op == null || !anyComponent(op, (c) => {
|
|
1101
|
+
var _a2;
|
|
1102
|
+
return c.r !== void 0 || ((_a2 = getEditType(c)) === null || _a2 === void 0 ? void 0 : _a2.makeInvertible) != null;
|
|
1103
|
+
})) return op;
|
|
1104
|
+
const r = new cursor_js_1.ReadCursor(op), w = new cursor_js_1.WriteCursor();
|
|
1105
|
+
let hasEdits = !1;
|
|
1106
|
+
const heldPick = [], heldDoc = [], traversePick = /* @__PURE__ */ __name((r2, w2, subDoc) => {
|
|
1107
|
+
const c = r2.getComponent();
|
|
1108
|
+
let modified = !1;
|
|
1109
|
+
if (c) {
|
|
1110
|
+
c.d != null && w2.write("d", c.d), c.i !== void 0 && w2.write("i", c.i);
|
|
1111
|
+
const pickSlot = c.p;
|
|
1112
|
+
if (pickSlot != null && (heldPick[pickSlot] = r2.clone(), assert(subDoc !== void 0, "Operation picks up at an invalid key"), heldDoc[pickSlot] = subDoc, w2.write("p", c.p)), c.r !== void 0 && subDoc === void 0) throw Error("Invalid doc / op in makeInvertible: removed item missing from doc");
|
|
1113
|
+
const t = getEditType(c);
|
|
1114
|
+
t && (t.makeInvertible ? hasEdits = !0 : writeEdit(w2, t, getEdit(c), !0));
|
|
1079
1115
|
}
|
|
1080
|
-
let
|
|
1081
|
-
for (const
|
|
1082
|
-
|
|
1083
|
-
const
|
|
1084
|
-
|
|
1116
|
+
let listOff = 0;
|
|
1117
|
+
for (const key of r2) {
|
|
1118
|
+
w2.descend(key);
|
|
1119
|
+
const keyRaw = typeof key == "number" ? key - listOff : key, childIn = maybeGetChild(subDoc, keyRaw), childOut = traversePick(r2, w2, childIn);
|
|
1120
|
+
childIn !== childOut && (modified || (modified = !0, subDoc = shallowClone(subDoc)), childOut === void 0 ? (subDoc = removeChild(subDoc, keyRaw), typeof key == "number" && listOff++) : subDoc[keyRaw] = childOut), w2.ascend();
|
|
1085
1121
|
}
|
|
1086
|
-
return
|
|
1087
|
-
};
|
|
1088
|
-
return
|
|
1089
|
-
const
|
|
1090
|
-
if (
|
|
1091
|
-
|
|
1092
|
-
let
|
|
1093
|
-
if (
|
|
1094
|
-
const
|
|
1095
|
-
|
|
1122
|
+
return c && (c.r !== void 0 ? (w2.write("r", deepClone_js_1.default(subDoc)), subDoc = void 0) : c.p != null && (subDoc = void 0)), subDoc;
|
|
1123
|
+
}, "traversePick");
|
|
1124
|
+
return traversePick(r, w, doc), w.get(), hasEdits && (w.reset(), (/* @__PURE__ */ __name(function traverseDrop(rPick, rDrop, w2, subDoc, isLiteral) {
|
|
1125
|
+
const c = rDrop.getComponent();
|
|
1126
|
+
if (c) {
|
|
1127
|
+
c.i !== void 0 ? (subDoc = c.i, isLiteral = !0) : c.d != null && (subDoc = heldDoc[c.d], rPick = heldPick[c.d], isLiteral = !1, c.d);
|
|
1128
|
+
let t = getEditType(c);
|
|
1129
|
+
if (t && t.makeInvertible) {
|
|
1130
|
+
const edit = getEdit(c);
|
|
1131
|
+
writeEdit(w2, t, t.makeInvertible(edit, subDoc), !0);
|
|
1096
1132
|
}
|
|
1097
1133
|
}
|
|
1098
|
-
let
|
|
1099
|
-
const
|
|
1100
|
-
|
|
1134
|
+
let pickOff = 0, dropOff = 0;
|
|
1135
|
+
const ap = cursor_js_1.advancer(rPick, (k, c2) => hasPick(c2) ? pickOff - k - 1 : k - pickOff, (k, c2) => {
|
|
1136
|
+
hasPick(c2) && pickOff++;
|
|
1101
1137
|
});
|
|
1102
|
-
for (const
|
|
1103
|
-
const
|
|
1104
|
-
|
|
1138
|
+
for (const key of rDrop) if (typeof key == "number") {
|
|
1139
|
+
const mid = key - dropOff, _rPick = ap(mid), raw = mid + pickOff, child = maybeGetChild(subDoc, isLiteral ? mid : raw);
|
|
1140
|
+
w2.descend(key), traverseDrop(_rPick, rDrop, w2, child, isLiteral), hasDrop(rDrop.getComponent()) && dropOff++, w2.ascend();
|
|
1105
1141
|
} else {
|
|
1106
|
-
const
|
|
1107
|
-
|
|
1142
|
+
const child = maybeGetChild(subDoc, key);
|
|
1143
|
+
w2.descend(key), traverseDrop(ap(key), rDrop, w2, child, isLiteral), w2.ascend();
|
|
1108
1144
|
}
|
|
1109
|
-
|
|
1110
|
-
}(
|
|
1145
|
+
ap.end();
|
|
1146
|
+
}, "traverseDrop"))(r.clone(), r, w, doc, !1)), w.get();
|
|
1111
1147
|
}
|
|
1112
|
-
|
|
1113
|
-
|
|
1148
|
+
__name(makeInvertible, "makeInvertible");
|
|
1149
|
+
function invertWithDoc(op, doc) {
|
|
1150
|
+
return invert(makeInvertible(op, doc));
|
|
1114
1151
|
}
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1152
|
+
__name(invertWithDoc, "invertWithDoc");
|
|
1153
|
+
const shallowCloneOp = /* @__PURE__ */ __name((op) => {
|
|
1154
|
+
if (op == null) return null;
|
|
1155
|
+
const result = op.slice();
|
|
1156
|
+
for (let i = 0; i < op.length; i++) {
|
|
1157
|
+
const c = result[i];
|
|
1158
|
+
Array.isArray(c) && (result[i] = shallowCloneOp(c));
|
|
1121
1159
|
}
|
|
1122
|
-
return
|
|
1123
|
-
};
|
|
1124
|
-
function
|
|
1125
|
-
|
|
1126
|
-
const
|
|
1127
|
-
if (
|
|
1160
|
+
return result;
|
|
1161
|
+
}, "shallowCloneOp");
|
|
1162
|
+
function tryTransform(op1, op2, direction) {
|
|
1163
|
+
assert(direction === "left" || direction === "right", "Direction must be left or right");
|
|
1164
|
+
const side = direction === "left" ? 0 : 1;
|
|
1165
|
+
if (op2 == null) return {
|
|
1128
1166
|
ok: !0,
|
|
1129
|
-
result:
|
|
1167
|
+
result: op1
|
|
1130
1168
|
};
|
|
1131
|
-
|
|
1132
|
-
let
|
|
1133
|
-
const
|
|
1134
|
-
let
|
|
1135
|
-
const
|
|
1136
|
-
if (function
|
|
1137
|
-
const
|
|
1138
|
-
|
|
1139
|
-
const
|
|
1140
|
-
let
|
|
1141
|
-
|
|
1142
|
-
const
|
|
1143
|
-
for (const
|
|
1144
|
-
|
|
1145
|
-
}(
|
|
1146
|
-
const
|
|
1147
|
-
let
|
|
1148
|
-
|
|
1149
|
-
type:
|
|
1150
|
-
op1:
|
|
1151
|
-
op2:
|
|
1152
|
-
}),
|
|
1153
|
-
type:
|
|
1154
|
-
op1:
|
|
1155
|
-
op2:
|
|
1169
|
+
checkValidOp(op1), checkValidOp(op2);
|
|
1170
|
+
let conflict = null;
|
|
1171
|
+
const heldOp1PickByOp1 = [], heldOp1DropByOp1 = [], heldOp2PickByOp2 = [], heldOp2DropByOp2 = [], heldOp1PickByOp2 = [], heldOp2PickByOp1 = [], heldOp2DropByOp1 = [], heldOp2RmForOp1 = [], heldOp1RmForOp2 = [], cancelledOp2 = [], discardedOp2Drop = [], heldPickWrites = [], heldDropWrites = [], op1PickAtOp2Pick = [], op1PicksOp2DropSlots = [];
|
|
1172
|
+
let nextSlot = 0;
|
|
1173
|
+
const r1 = cursor_js_1.readCursor(op1), r2 = cursor_js_1.readCursor(op2), w = cursor_js_1.writeCursor();
|
|
1174
|
+
if ((/* @__PURE__ */ __name(function scanOp2Pick(r2Pick, r1Pick = null, removed1) {
|
|
1175
|
+
const c1 = getComponent(r1Pick);
|
|
1176
|
+
c1 && (c1.r !== void 0 ? removed1 = r1Pick.clone() : c1.p != null && (removed1 = null, heldOp2PickByOp1[c1.p] = r2Pick.clone()));
|
|
1177
|
+
const c2 = r2Pick.getComponent();
|
|
1178
|
+
let slot2;
|
|
1179
|
+
c2 && (slot2 = c2.p) != null && (heldOp1PickByOp2[slot2] = r1Pick ? r1Pick.clone() : null, heldOp2PickByOp2[slot2] = r2Pick.clone(), removed1 && (cancelledOp2[slot2] = !0, heldOp1RmForOp2[slot2] = removed1), c1 && c1.p != null && (op1PickAtOp2Pick[slot2] = c1.p));
|
|
1180
|
+
const ap1 = cursor_js_1.advancer(r1Pick);
|
|
1181
|
+
for (const key of r2Pick) scanOp2Pick(r2Pick, ap1(key), removed1);
|
|
1182
|
+
ap1.end();
|
|
1183
|
+
}, "scanOp2Pick"))(r2, r1, null), (/* @__PURE__ */ __name(function scanOp2Drop(r1Pick, r2Pick, r2Drop, pickSlot1, removed1) {
|
|
1184
|
+
const c2d = r2Drop.getComponent();
|
|
1185
|
+
let slot2, droppedHere = !1;
|
|
1186
|
+
c2d && ((slot2 = c2d.d) != null ? (heldOp2DropByOp2[slot2] = r2Drop.clone(), pickSlot1 != null && (op1PicksOp2DropSlots[pickSlot1] == null && (op1PicksOp2DropSlots[pickSlot1] = []), op1PicksOp2DropSlots[pickSlot1].push(slot2)), cancelledOp2[slot2], r1Pick = heldOp1PickByOp2[slot2] || null, r2Pick = heldOp2PickByOp2[slot2] || null, cancelledOp2[slot2] ? (removed1 && (discardedOp2Drop[slot2] = !0), removed1 = heldOp1RmForOp2[slot2] || null) : !removed1 || side !== 1 && op1PickAtOp2Pick[slot2] != null || conflict == null && (conflict = {
|
|
1187
|
+
type: types_js_1.ConflictType.RM_UNEXPECTED_CONTENT,
|
|
1188
|
+
op1: exports.removeOp(removed1.getPath()),
|
|
1189
|
+
op2: exports.moveOp(r2Pick.getPath(), r2Drop.getPath())
|
|
1190
|
+
}), droppedHere = !0) : c2d.i !== void 0 && (r1Pick = r2Pick = null, droppedHere = !0, removed1 && conflict == null && (conflict = {
|
|
1191
|
+
type: types_js_1.ConflictType.RM_UNEXPECTED_CONTENT,
|
|
1192
|
+
op1: exports.removeOp(removed1.getPath()),
|
|
1193
|
+
op2: exports.insertOp(r2Drop.getPath(), c2d.i)
|
|
1156
1194
|
})));
|
|
1157
|
-
const
|
|
1158
|
-
|
|
1159
|
-
const
|
|
1160
|
-
|
|
1161
|
-
type:
|
|
1162
|
-
op1:
|
|
1163
|
-
op2:
|
|
1195
|
+
const c1p = getComponent(r1Pick);
|
|
1196
|
+
c1p && (c1p.r !== void 0 ? removed1 = r1Pick.clone() : c1p.p != null && (c1p.p, pickSlot1 = c1p.p, removed1 = null));
|
|
1197
|
+
const t2 = getEditType(c2d);
|
|
1198
|
+
t2 && removed1 && conflict == null && (conflict = {
|
|
1199
|
+
type: types_js_1.ConflictType.RM_UNEXPECTED_CONTENT,
|
|
1200
|
+
op1: exports.removeOp(removed1.getPath()),
|
|
1201
|
+
op2: exports.editOp(r2Drop.getPath(), t2, getEdit(c2d), !0)
|
|
1164
1202
|
});
|
|
1165
|
-
let
|
|
1166
|
-
const
|
|
1167
|
-
|
|
1168
|
-
}),
|
|
1169
|
-
for (const
|
|
1170
|
-
const
|
|
1171
|
-
|
|
1203
|
+
let p2PickOff = 0, p2DropOff = 0;
|
|
1204
|
+
const ap2 = cursor_js_1.advancer(r2Pick, (k, c) => hasPick(c) ? p2PickOff - k - 1 : k - p2PickOff, (k, c) => {
|
|
1205
|
+
hasPick(c) && p2PickOff++;
|
|
1206
|
+
}), ap1 = cursor_js_1.advancer(r1Pick);
|
|
1207
|
+
for (const key of r2Drop) if (typeof key == "number") {
|
|
1208
|
+
const p2Mid = key - p2DropOff, _p2Pick = ap2(p2Mid);
|
|
1209
|
+
p2DropOff += +scanOp2Drop(ap1(p2Mid + p2PickOff), _p2Pick, r2Drop, pickSlot1, removed1);
|
|
1172
1210
|
} else {
|
|
1173
|
-
const
|
|
1174
|
-
|
|
1211
|
+
const _p2Pick = ap2(key);
|
|
1212
|
+
scanOp2Drop(ap1(key), _p2Pick, r2Drop, pickSlot1, removed1);
|
|
1175
1213
|
}
|
|
1176
|
-
return
|
|
1177
|
-
}(
|
|
1214
|
+
return ap2.end(), ap1.end(), droppedHere;
|
|
1215
|
+
}, "scanOp2Drop"))(r1, r2, r2.clone(), null, null), heldOp2DropByOp2.map((x) => x && x.get()), conflict) return {
|
|
1178
1216
|
ok: !1,
|
|
1179
|
-
conflict
|
|
1217
|
+
conflict
|
|
1180
1218
|
};
|
|
1181
|
-
|
|
1182
|
-
const
|
|
1183
|
-
let
|
|
1184
|
-
(function
|
|
1185
|
-
let
|
|
1186
|
-
const
|
|
1187
|
-
if (
|
|
1188
|
-
const
|
|
1189
|
-
|
|
1190
|
-
} else
|
|
1191
|
-
const
|
|
1192
|
-
if (
|
|
1193
|
-
const
|
|
1194
|
-
|
|
1219
|
+
discardedOp2Drop.map((x) => !!x);
|
|
1220
|
+
const pickComponents = [];
|
|
1221
|
+
let cancelledRemoves = null;
|
|
1222
|
+
(/* @__PURE__ */ __name(function writeOp1Pick(r1Pick, r2Pick, r2Drop, w2, removed2) {
|
|
1223
|
+
let iAmMoved = !1;
|
|
1224
|
+
const c2p = getComponent(r2Pick);
|
|
1225
|
+
if (hasPick(c2p)) {
|
|
1226
|
+
const slot2 = c2p.p;
|
|
1227
|
+
slot2 != null ? (r2Drop = heldOp2DropByOp2[slot2], w2 = heldPickWrites[slot2] = cursor_js_1.writeCursor(), iAmMoved = !0, removed2 = null) : (r2Drop = null, removed2 = r2Pick.clone());
|
|
1228
|
+
} else hasDrop(getComponent(r2Drop)) && (r2Drop = null);
|
|
1229
|
+
const c1 = r1Pick.getComponent();
|
|
1230
|
+
if (c1) {
|
|
1231
|
+
const slot1 = c1.p;
|
|
1232
|
+
slot1 != null ? (removed2 && (heldOp2RmForOp1[slot1] = removed2), pickComponents[slot1] = removed2 || side === 1 && iAmMoved ? null : w2.getComponent(), heldOp1PickByOp1[slot1] = r1Pick.clone(), r2Drop && (heldOp2DropByOp1[slot1] = r2Drop.clone())) : c1.r !== void 0 && (removed2 || w2.write("r", !0), (removed2 || iAmMoved) && (cancelledRemoves == null && (cancelledRemoves = /* @__PURE__ */ new Set()), cancelledRemoves.add(c1)));
|
|
1195
1233
|
}
|
|
1196
|
-
let
|
|
1197
|
-
const
|
|
1198
|
-
|
|
1199
|
-
}),
|
|
1200
|
-
|
|
1234
|
+
let p2PickOff = 0, p2DropOff = 0;
|
|
1235
|
+
const ap2Pick = cursor_js_1.advancer(r2Pick, void 0, (k, c) => {
|
|
1236
|
+
hasPick(c) && p2PickOff++;
|
|
1237
|
+
}), ap2Drop = cursor_js_1.advancer(r2Drop, (k, c) => hasDrop(c) ? ~(k - p2DropOff) : k - p2DropOff, (k, c) => {
|
|
1238
|
+
hasDrop(c) && p2DropOff++;
|
|
1201
1239
|
});
|
|
1202
|
-
if (
|
|
1203
|
-
const
|
|
1204
|
-
|
|
1240
|
+
if (r1Pick) for (const key of r1Pick) if (typeof key == "string") {
|
|
1241
|
+
const p2Pick_ = ap2Pick(key), p2Drop_ = ap2Drop(key);
|
|
1242
|
+
w2.descend(key), writeOp1Pick(r1Pick, p2Pick_, p2Drop_, w2, removed2), w2.ascend();
|
|
1205
1243
|
} else {
|
|
1206
|
-
const
|
|
1207
|
-
|
|
1244
|
+
const p2Pick_ = ap2Pick(key), p2Mid = key - p2PickOff, p2Drop_ = hasPick(getComponent(p2Pick_)) ? null : ap2Drop(p2Mid), finalKey = p2Mid + p2DropOff;
|
|
1245
|
+
assert(finalKey >= 0), w2.descend(finalKey), writeOp1Pick(r1Pick, p2Pick_, p2Drop_, w2, removed2), w2.ascend();
|
|
1208
1246
|
}
|
|
1209
|
-
|
|
1210
|
-
})(
|
|
1211
|
-
let
|
|
1212
|
-
if (function
|
|
1213
|
-
|
|
1214
|
-
const
|
|
1215
|
-
let
|
|
1216
|
-
const
|
|
1217
|
-
if (
|
|
1218
|
-
const
|
|
1219
|
-
|
|
1220
|
-
const
|
|
1221
|
-
let
|
|
1222
|
-
if (
|
|
1223
|
-
let
|
|
1224
|
-
|
|
1225
|
-
type:
|
|
1226
|
-
op1:
|
|
1227
|
-
op2:
|
|
1228
|
-
})),
|
|
1229
|
-
type:
|
|
1230
|
-
op1:
|
|
1231
|
-
op2:
|
|
1232
|
-
}) : (
|
|
1233
|
-
} else if (
|
|
1234
|
-
const
|
|
1235
|
-
|
|
1247
|
+
ap2Pick.end(), ap2Drop.end();
|
|
1248
|
+
}, "writeOp1Pick"))(r1, r2, r2.clone(), w, null), w.reset();
|
|
1249
|
+
let outputSlotMap = [];
|
|
1250
|
+
if ((/* @__PURE__ */ __name(function writeOp1Drop(p1Pick, p1Drop, p2Pick, p2Drop, w2, removed2) {
|
|
1251
|
+
assert(p1Drop);
|
|
1252
|
+
const c1d = p1Drop.getComponent();
|
|
1253
|
+
let c2d = getComponent(p2Drop), droppedHere = !1;
|
|
1254
|
+
const insOrMv = /* @__PURE__ */ __name((r12, r22, c) => r12 ? exports.moveOp(r12.getPath(), r22.getPath()) : exports.insertOp(r22.getPath(), c.i), "insOrMv");
|
|
1255
|
+
if (hasDrop(c1d)) {
|
|
1256
|
+
const slot1 = c1d.d;
|
|
1257
|
+
slot1 != null && (heldOp1DropByOp1[slot1] = p1Drop.clone());
|
|
1258
|
+
const pc = slot1 != null ? pickComponents[slot1] : null;
|
|
1259
|
+
let identical = !1;
|
|
1260
|
+
if (c1d.i !== void 0 || slot1 != null && pc) {
|
|
1261
|
+
let slot2;
|
|
1262
|
+
c2d && (c2d.i !== void 0 || (slot2 = c2d.d) != null && !cancelledOp2[slot2]) && (identical = slot2 != null ? slot1 != null && slot1 === op1PickAtOp2Pick[slot2] : deepEqual_js_1.default(c2d.i, c1d.i), identical || slot2 != null && side !== 1 && op1PickAtOp2Pick[slot2] != null || conflict == null && (conflict = {
|
|
1263
|
+
type: types_js_1.ConflictType.DROP_COLLISION,
|
|
1264
|
+
op1: insOrMv(slot1 != null ? heldOp1PickByOp1[slot1] : null, p1Drop, c1d),
|
|
1265
|
+
op2: insOrMv(slot2 != null ? heldOp2PickByOp2[slot2] : null, p2Drop, c2d)
|
|
1266
|
+
})), identical || (removed2 ? conflict == null && (conflict = {
|
|
1267
|
+
type: types_js_1.ConflictType.RM_UNEXPECTED_CONTENT,
|
|
1268
|
+
op1: insOrMv(slot1 != null ? heldOp1PickByOp1[slot1] : null, p1Drop, c1d),
|
|
1269
|
+
op2: exports.removeOp(removed2.getPath())
|
|
1270
|
+
}) : (slot1 != null ? (outputSlotMap[nextSlot] = slot1, w2.write("d", pc.p = nextSlot++)) : w2.write("i", deepClone_js_1.default(c1d.i)), droppedHere = !0));
|
|
1271
|
+
} else if (slot1 != null && !pc) {
|
|
1272
|
+
const h = heldOp2RmForOp1[slot1];
|
|
1273
|
+
h && (removed2 = h.clone());
|
|
1236
1274
|
}
|
|
1237
|
-
|
|
1238
|
-
} else
|
|
1239
|
-
const
|
|
1240
|
-
if (
|
|
1241
|
-
const
|
|
1242
|
-
|
|
1243
|
-
} else !
|
|
1244
|
-
|
|
1245
|
-
const
|
|
1246
|
-
if (
|
|
1247
|
-
const
|
|
1248
|
-
if (
|
|
1249
|
-
type:
|
|
1250
|
-
op1:
|
|
1251
|
-
op2:
|
|
1275
|
+
slot1 != null ? (p1Pick = heldOp1PickByOp1[slot1], p2Pick = heldOp2PickByOp1[slot1], p2Drop = heldOp2DropByOp1[slot1]) : c1d.i !== void 0 && (p1Pick = p2Pick = null, identical || (p2Drop = null));
|
|
1276
|
+
} else hasPick(getComponent(p1Pick)) && (p1Pick = p2Pick = p2Drop = null);
|
|
1277
|
+
const c1p = getComponent(p1Pick), c2p = getComponent(p2Pick);
|
|
1278
|
+
if (hasPick(c2p)) {
|
|
1279
|
+
const slot2 = c2p.p;
|
|
1280
|
+
c2p.r !== void 0 && (!c1p || c1p.r === void 0) || cancelledOp2[slot2] ? (p2Drop = null, removed2 = p2Pick.clone()) : slot2 != null && (p2Drop = heldOp2DropByOp2[slot2], side !== 1 && op1PickAtOp2Pick[slot2] != null || ((w2 = heldDropWrites[slot2]) || (w2 = heldDropWrites[slot2] = cursor_js_1.writeCursor()), w2.reset(), removed2 = null));
|
|
1281
|
+
} else !hasDrop(c1d) && hasDrop(c2d) && (p2Drop = null);
|
|
1282
|
+
c2d = p2Drop != null ? p2Drop.getComponent() : null;
|
|
1283
|
+
const t1 = getEditType(c1d);
|
|
1284
|
+
if (t1) {
|
|
1285
|
+
const e1 = getEdit(c1d);
|
|
1286
|
+
if (removed2) conflict == null && (conflict = {
|
|
1287
|
+
type: types_js_1.ConflictType.RM_UNEXPECTED_CONTENT,
|
|
1288
|
+
op1: exports.editOp(p1Drop.getPath(), t1, e1, !0),
|
|
1289
|
+
op2: exports.removeOp(removed2.getPath())
|
|
1252
1290
|
});
|
|
1253
1291
|
else {
|
|
1254
|
-
const
|
|
1255
|
-
let
|
|
1256
|
-
if (
|
|
1257
|
-
if (
|
|
1258
|
-
const
|
|
1259
|
-
|
|
1260
|
-
} else
|
|
1261
|
-
|
|
1292
|
+
const t2 = getEditType(c2d);
|
|
1293
|
+
let e;
|
|
1294
|
+
if (t2) {
|
|
1295
|
+
if (t1 !== t2) throw Error("Transforming incompatible types");
|
|
1296
|
+
const e2 = getEdit(c2d);
|
|
1297
|
+
e = t1.transform(e1, e2, direction);
|
|
1298
|
+
} else e = deepClone_js_1.default(e1);
|
|
1299
|
+
writeEdit(w2, t1, e);
|
|
1262
1300
|
}
|
|
1263
1301
|
}
|
|
1264
|
-
let
|
|
1265
|
-
const
|
|
1266
|
-
|
|
1302
|
+
let p1PickOff = 0, p1DropOff = 0, p2PickOff = 0, p2DropOff = 0, outPickOff = 0, outDropOff = 0, p1pValid = p1Pick != null && p1Pick.descendFirst(), p1pDidDescend = p1pValid;
|
|
1303
|
+
const ap2p = cursor_js_1.advancer(p2Pick, void 0, (k, c) => {
|
|
1304
|
+
hasPick(c) && p2PickOff++;
|
|
1267
1305
|
});
|
|
1268
|
-
let
|
|
1269
|
-
for (const
|
|
1270
|
-
let
|
|
1271
|
-
const
|
|
1306
|
+
let p2dValid = p2Drop != null && p2Drop.descendFirst(), p2dDidDescend = p2dValid;
|
|
1307
|
+
for (const key of p1Drop) if (typeof key == "number") {
|
|
1308
|
+
let _p1Pick;
|
|
1309
|
+
const hd1 = hasDrop(p1Drop.getComponent()), k1Mid = key - p1DropOff;
|
|
1272
1310
|
{
|
|
1273
|
-
let
|
|
1274
|
-
for (;
|
|
1275
|
-
|
|
1276
|
-
const
|
|
1277
|
-
if (
|
|
1278
|
-
if (
|
|
1279
|
-
|
|
1280
|
-
const
|
|
1281
|
-
|
|
1311
|
+
let p1k;
|
|
1312
|
+
for (; p1pValid && typeof (p1k = p1Pick.getKey()) == "number"; ) {
|
|
1313
|
+
p1k += p1PickOff;
|
|
1314
|
+
const c = p1Pick.getComponent(), hp = hasPick(c);
|
|
1315
|
+
if (p1k > k1Mid || p1k === k1Mid && (!hp || side === 0 && hd1)) break;
|
|
1316
|
+
if (hp) {
|
|
1317
|
+
p1PickOff--;
|
|
1318
|
+
const slot1 = c.p;
|
|
1319
|
+
op1PickAtOp2Pick.includes(slot1), c.d, getComponent(heldDropWrites[c.d]), hasPick(getComponent(heldDropWrites[c.d])), (c.r === void 0 || cancelledRemoves && cancelledRemoves.has(c)) && (slot1 == null || !pickComponents[slot1] || side !== 1 && op1PickAtOp2Pick.includes(slot1)) || outPickOff--;
|
|
1282
1320
|
}
|
|
1283
|
-
|
|
1321
|
+
p1pValid = p1Pick.nextSibling();
|
|
1284
1322
|
}
|
|
1285
|
-
|
|
1323
|
+
_p1Pick = p1pValid && p1k === k1Mid ? p1Pick : null;
|
|
1286
1324
|
}
|
|
1287
|
-
const
|
|
1288
|
-
let
|
|
1289
|
-
const
|
|
1290
|
-
let
|
|
1325
|
+
const raw = k1Mid - p1PickOff;
|
|
1326
|
+
let _p2Pick = ap2p(raw);
|
|
1327
|
+
const k2Mid = raw - p2PickOff;
|
|
1328
|
+
let _p2Drop = null;
|
|
1291
1329
|
{
|
|
1292
|
-
let
|
|
1293
|
-
for (;
|
|
1294
|
-
|
|
1295
|
-
const
|
|
1296
|
-
if (
|
|
1297
|
-
if (
|
|
1298
|
-
if (!
|
|
1299
|
-
|
|
1330
|
+
let p2dk, op2Mid;
|
|
1331
|
+
for (; p2dValid && typeof (p2dk = p2Drop.getKey()) == "number"; ) {
|
|
1332
|
+
op2Mid = p2dk - p2DropOff;
|
|
1333
|
+
const c = p2Drop.getComponent(), hd2 = hasDrop(c);
|
|
1334
|
+
if (op2Mid > k2Mid) break;
|
|
1335
|
+
if (op2Mid === k2Mid) {
|
|
1336
|
+
if (!hd2) {
|
|
1337
|
+
_p2Drop = p2Drop;
|
|
1300
1338
|
break;
|
|
1301
1339
|
}
|
|
1302
1340
|
{
|
|
1303
|
-
if (
|
|
1304
|
-
|
|
1341
|
+
if (side === 0 && hd1) {
|
|
1342
|
+
_p2Drop = p2Drop;
|
|
1305
1343
|
break;
|
|
1306
1344
|
}
|
|
1307
|
-
const
|
|
1308
|
-
if (
|
|
1345
|
+
const hp2 = _p2Pick && hasPick(_p2Pick.getComponent());
|
|
1346
|
+
if (side === 0 && hp2) break;
|
|
1309
1347
|
}
|
|
1310
1348
|
}
|
|
1311
|
-
if (
|
|
1312
|
-
const
|
|
1313
|
-
|
|
1349
|
+
if (hd2) {
|
|
1350
|
+
const slot2 = c.d;
|
|
1351
|
+
cancelledOp2[slot2], op1PickAtOp2Pick[slot2], c.i === void 0 && (cancelledOp2[slot2] || op1PickAtOp2Pick[slot2] != null && side !== 1) ? (cancelledOp2[slot2] || op1PickAtOp2Pick[slot2] != null && side === 0) && (p2DropOff++, outDropOff--) : p2DropOff++;
|
|
1314
1352
|
}
|
|
1315
|
-
|
|
1353
|
+
p2dValid = p2Drop.nextSibling();
|
|
1316
1354
|
}
|
|
1317
1355
|
}
|
|
1318
|
-
const
|
|
1319
|
-
|
|
1356
|
+
const descend = k2Mid + p2DropOff + outPickOff + outDropOff;
|
|
1357
|
+
assert(descend >= 0, "trying to descend to a negative index"), w2.descend(descend), hd1 && (_p1Pick = _p2Pick = _p2Drop = null, p1DropOff++), writeOp1Drop(_p1Pick, p1Drop, _p2Pick, _p2Drop, w2, removed2) && outDropOff++, w2.ascend();
|
|
1320
1358
|
} else {
|
|
1321
|
-
let
|
|
1322
|
-
for (;
|
|
1323
|
-
const
|
|
1324
|
-
let
|
|
1325
|
-
for (;
|
|
1326
|
-
const
|
|
1327
|
-
|
|
1359
|
+
let p1k;
|
|
1360
|
+
for (; p1pValid && (p1k = p1Pick.getKey(), typeof p1k != "string" || !(p1k > key || p1k === key)); ) p1pValid = p1Pick.nextSibling();
|
|
1361
|
+
const _p1Pick = p1pValid && p1k === key ? p1Pick : null, _p2Pick = ap2p(key);
|
|
1362
|
+
let p2dk;
|
|
1363
|
+
for (; p2dValid && (p2dk = p2Drop.getKey(), typeof p2dk != "string" || !(p2dk > key || p2dk === key)); ) p2dValid = p2Drop.nextSibling();
|
|
1364
|
+
const _p2Drop = p2dValid && p2dk === key ? p2Drop : null;
|
|
1365
|
+
w2.descend(key), writeOp1Drop(_p1Pick, p1Drop, _p2Pick, _p2Drop, w2, removed2), w2.ascend();
|
|
1328
1366
|
}
|
|
1329
|
-
return
|
|
1330
|
-
}(
|
|
1367
|
+
return ap2p.end(), p1pDidDescend && p1Pick.ascend(), p2dDidDescend && p2Drop.ascend(), droppedHere;
|
|
1368
|
+
}, "writeOp1Drop"))(r1, r1.clone(), r2, r2.clone(), w, null), conflict) return {
|
|
1331
1369
|
ok: !1,
|
|
1332
|
-
conflict
|
|
1370
|
+
conflict
|
|
1333
1371
|
};
|
|
1334
|
-
|
|
1335
|
-
const
|
|
1336
|
-
|
|
1337
|
-
});
|
|
1338
|
-
(
|
|
1339
|
-
|
|
1340
|
-
}),
|
|
1341
|
-
const
|
|
1342
|
-
if ((
|
|
1343
|
-
const
|
|
1344
|
-
if (
|
|
1345
|
-
|
|
1346
|
-
}),
|
|
1347
|
-
|
|
1348
|
-
|
|
1372
|
+
w.reset();
|
|
1373
|
+
const eachDrop = /* @__PURE__ */ __name((r, w2, fn) => r.traverse(w2, (c, w3) => {
|
|
1374
|
+
c.d != null && fn(c.d, r, w3);
|
|
1375
|
+
}), "eachDrop");
|
|
1376
|
+
(cancelledOp2.length || heldPickWrites.length) && (eachDrop(r2, w, (slot2, r, w2) => {
|
|
1377
|
+
cancelledOp2[slot2] && !discardedOp2Drop[slot2] && w2.write("r", !0), heldPickWrites[slot2] && w2.mergeTree(heldPickWrites[slot2].get());
|
|
1378
|
+
}), w.reset());
|
|
1379
|
+
const heldOutDropRead = [], heldOutDropWrites = [];
|
|
1380
|
+
if ((heldDropWrites.length || cancelledOp2.length) && !conflict) {
|
|
1381
|
+
const rOut = cursor_js_1.readCursor(shallowCloneOp(w.get()));
|
|
1382
|
+
if (eachDrop(rOut, null, (slotOut, r) => {
|
|
1383
|
+
heldOutDropRead[slotOut] = r.clone();
|
|
1384
|
+
}), heldDropWrites.forEach((hdw) => {
|
|
1385
|
+
hdw && eachDrop(cursor_js_1.readCursor(hdw.get()), null, (slotOut, r) => {
|
|
1386
|
+
heldOutDropRead[slotOut] = r.clone();
|
|
1349
1387
|
});
|
|
1350
|
-
}), function
|
|
1351
|
-
const
|
|
1352
|
-
if (
|
|
1353
|
-
const
|
|
1354
|
-
|
|
1355
|
-
} else
|
|
1356
|
-
else
|
|
1357
|
-
const
|
|
1358
|
-
if (
|
|
1359
|
-
let
|
|
1360
|
-
if ((
|
|
1361
|
-
const
|
|
1362
|
-
|
|
1388
|
+
}), (/* @__PURE__ */ __name(function writeHeldOp2Drop(p2Drop, outPick, outDrop, w2, parentC, removedOut) {
|
|
1389
|
+
const coutp = getComponent(outPick);
|
|
1390
|
+
if (coutp && hasPick(coutp)) if (coutp.p != null) {
|
|
1391
|
+
const slot = coutp.p;
|
|
1392
|
+
heldOutDropRead[slot].getPath(), outDrop = heldOutDropRead[slot], w2 = heldOutDropWrites[slot] = cursor_js_1.writeCursor();
|
|
1393
|
+
} else coutp.r !== void 0 && (outDrop = null);
|
|
1394
|
+
else hasDrop(getComponent(outDrop)) && (outDrop = null);
|
|
1395
|
+
const c2 = p2Drop.getComponent();
|
|
1396
|
+
if (c2) {
|
|
1397
|
+
let slot2;
|
|
1398
|
+
if ((slot2 = c2.d) != null) {
|
|
1399
|
+
const _w = heldDropWrites[slot2];
|
|
1400
|
+
_w && (_w.get(), w2.mergeTree(_w.get()), outDrop = cursor_js_1.readCursor(_w.get()));
|
|
1363
1401
|
}
|
|
1364
1402
|
}
|
|
1365
|
-
let
|
|
1366
|
-
const
|
|
1367
|
-
|
|
1368
|
-
}),
|
|
1369
|
-
|
|
1403
|
+
let outPickOff = 0, outDropOff = 0;
|
|
1404
|
+
const oPickAdv = cursor_js_1.advancer(outPick, void 0, (k, c) => {
|
|
1405
|
+
hasPick(c) && outPickOff--;
|
|
1406
|
+
}), oDropAdv = cursor_js_1.advancer(outDrop, (k, c) => hasDrop(c) ? -(k - outDropOff) - 1 : k - outDropOff, (k, c) => {
|
|
1407
|
+
hasDrop(c) && outDropOff++;
|
|
1370
1408
|
});
|
|
1371
|
-
for (const
|
|
1372
|
-
const
|
|
1373
|
-
|
|
1374
|
-
} else
|
|
1375
|
-
|
|
1376
|
-
}(
|
|
1409
|
+
for (const o2dk of p2Drop) if (typeof o2dk == "number") {
|
|
1410
|
+
const _outPick = oPickAdv(o2dk), rmid = o2dk + outPickOff, _outDrop = oDropAdv(rmid), rfinal = rmid + outDropOff;
|
|
1411
|
+
w2.descend(rfinal), writeHeldOp2Drop(p2Drop, _outPick, _outDrop, w2), w2.ascend();
|
|
1412
|
+
} else w2.descend(o2dk), writeHeldOp2Drop(p2Drop, oPickAdv(o2dk), oDropAdv(o2dk), w2), w2.ascend();
|
|
1413
|
+
oPickAdv.end(), oDropAdv.end();
|
|
1414
|
+
}, "writeHeldOp2Drop"))(r2, rOut, rOut.clone(), w), w.reset(), conflict) return {
|
|
1377
1415
|
ok: !1,
|
|
1378
|
-
conflict
|
|
1416
|
+
conflict
|
|
1379
1417
|
};
|
|
1380
|
-
if (
|
|
1381
|
-
const
|
|
1382
|
-
if (
|
|
1383
|
-
const
|
|
1384
|
-
|
|
1385
|
-
}),
|
|
1386
|
-
const
|
|
1387
|
-
let
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
const
|
|
1391
|
-
|
|
1392
|
-
const
|
|
1393
|
-
|
|
1394
|
-
|
|
1418
|
+
if (w.get(), heldOutDropWrites.length) {
|
|
1419
|
+
const heldOutDropContent = heldOutDropWrites.map((w2) => w2 ? w2.get() : null), rOut2 = cursor_js_1.readCursor(shallowCloneOp(w.get()));
|
|
1420
|
+
if (eachDrop(rOut2, w, (slotOut, r, w2) => {
|
|
1421
|
+
const data = heldOutDropContent[slotOut];
|
|
1422
|
+
data && (w2.mergeTree(data), heldOutDropContent[slotOut] = null);
|
|
1423
|
+
}), heldOutDropContent.find((x) => x)) {
|
|
1424
|
+
const w1 = cursor_js_1.writeCursor(), w2 = cursor_js_1.writeCursor();
|
|
1425
|
+
let nextSlot1 = 0, nextSlot2 = 0;
|
|
1426
|
+
heldOutDropContent.forEach((data) => {
|
|
1427
|
+
data != null && eachDrop(cursor_js_1.readCursor(data), null, (c) => {
|
|
1428
|
+
const slot1 = outputSlotMap[c];
|
|
1429
|
+
w1.writeMove(heldOp1PickByOp1[slot1].getPath(), heldOp1DropByOp1[slot1].getPath(), nextSlot1++);
|
|
1430
|
+
const slot2s = op1PicksOp2DropSlots[slot1];
|
|
1431
|
+
slot2s && slot2s.forEach((slot2) => {
|
|
1432
|
+
cancelledOp2[slot2] || side !== 1 && op1PickAtOp2Pick[slot2] != null || w2.writeMove(heldOp2PickByOp2[slot2].getPath(), heldOp2DropByOp2[slot2].getPath(), nextSlot2++);
|
|
1395
1433
|
});
|
|
1396
1434
|
});
|
|
1397
|
-
}),
|
|
1398
|
-
type:
|
|
1399
|
-
op1:
|
|
1400
|
-
op2:
|
|
1435
|
+
}), conflict = {
|
|
1436
|
+
type: types_js_1.ConflictType.BLACKHOLE,
|
|
1437
|
+
op1: w1.get(),
|
|
1438
|
+
op2: w2.get()
|
|
1401
1439
|
};
|
|
1402
1440
|
}
|
|
1403
1441
|
}
|
|
1404
1442
|
}
|
|
1405
|
-
return
|
|
1443
|
+
return conflict ? {
|
|
1406
1444
|
ok: !1,
|
|
1407
|
-
conflict
|
|
1445
|
+
conflict
|
|
1408
1446
|
} : {
|
|
1409
1447
|
ok: !0,
|
|
1410
|
-
result:
|
|
1448
|
+
result: w.get()
|
|
1411
1449
|
};
|
|
1412
1450
|
}
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1451
|
+
__name(tryTransform, "tryTransform");
|
|
1452
|
+
const throwConflictErr = /* @__PURE__ */ __name((conflict) => {
|
|
1453
|
+
const err = new Error("Transform detected write conflict");
|
|
1454
|
+
throw err.conflict = conflict, err.type = err.name = "writeConflict", err;
|
|
1455
|
+
}, "throwConflictErr");
|
|
1456
|
+
function transform(op1, op2, side) {
|
|
1457
|
+
const res = tryTransform(op1, op2, side);
|
|
1458
|
+
if (res.ok) return res.result;
|
|
1459
|
+
throwConflictErr(res.conflict);
|
|
1421
1460
|
}
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1461
|
+
__name(transform, "transform");
|
|
1462
|
+
const opThatRemovesDE = /* @__PURE__ */ __name((op) => {
|
|
1463
|
+
const w = cursor_js_1.writeCursor();
|
|
1464
|
+
return cursor_js_1.readCursor(op).traverse(w, (c, w2) => {
|
|
1465
|
+
(hasDrop(c) || getEditType(c)) && w2.write("r", !0);
|
|
1466
|
+
}), w.get();
|
|
1467
|
+
}, "opThatRemovesDE"), resolveConflict = /* @__PURE__ */ __name((conflict, side) => {
|
|
1468
|
+
const { type: type2, op1, op2 } = conflict;
|
|
1469
|
+
switch (type2) {
|
|
1470
|
+
case types_js_1.ConflictType.DROP_COLLISION:
|
|
1471
|
+
return side === "left" ? [null, opThatRemovesDE(op2)] : [opThatRemovesDE(op1), null];
|
|
1472
|
+
case types_js_1.ConflictType.RM_UNEXPECTED_CONTENT:
|
|
1473
|
+
let op1HasRemove = !1;
|
|
1474
|
+
return cursor_js_1.readCursor(op1).traverse(null, (c) => {
|
|
1475
|
+
c.r !== void 0 && (op1HasRemove = !0);
|
|
1476
|
+
}), op1HasRemove ? [null, opThatRemovesDE(op2)] : [opThatRemovesDE(op1), null];
|
|
1477
|
+
case types_js_1.ConflictType.BLACKHOLE:
|
|
1478
|
+
return [opThatRemovesDE(op1), opThatRemovesDE(op2)];
|
|
1439
1479
|
default:
|
|
1440
|
-
throw Error("Unrecognised conflict: " +
|
|
1480
|
+
throw Error("Unrecognised conflict: " + type2);
|
|
1441
1481
|
}
|
|
1442
|
-
};
|
|
1443
|
-
function
|
|
1444
|
-
let
|
|
1482
|
+
}, "resolveConflict");
|
|
1483
|
+
function transformWithConflictsPred(allowConflict, op1, op2, side) {
|
|
1484
|
+
let r2Aggregate = null;
|
|
1445
1485
|
for (; ; ) {
|
|
1446
|
-
const
|
|
1447
|
-
if (
|
|
1486
|
+
const res = tryTransform(op1, op2, side);
|
|
1487
|
+
if (res.ok) return compose(r2Aggregate, res.result);
|
|
1448
1488
|
{
|
|
1449
|
-
const { conflict
|
|
1450
|
-
|
|
1451
|
-
const [
|
|
1452
|
-
|
|
1489
|
+
const { conflict } = res;
|
|
1490
|
+
allowConflict(conflict) || throwConflictErr(conflict);
|
|
1491
|
+
const [r1, r2] = resolveConflict(conflict, side);
|
|
1492
|
+
op1 = compose(normalize(op1), r1), op2 = compose(normalize(op2), r2), r2Aggregate = compose(r2Aggregate, r2);
|
|
1453
1493
|
}
|
|
1454
1494
|
}
|
|
1455
1495
|
}
|
|
1456
|
-
|
|
1496
|
+
__name(transformWithConflictsPred, "transformWithConflictsPred");
|
|
1497
|
+
}(json1_release)), json1_release;
|
|
1457
1498
|
}
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1499
|
+
__name(requireJson1_release, "requireJson1_release");
|
|
1500
|
+
var hasRequiredDist;
|
|
1501
|
+
function requireDist() {
|
|
1502
|
+
return hasRequiredDist || (hasRequiredDist = 1, function(exports) {
|
|
1503
|
+
var __createBinding = dist$1.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
1504
|
+
k2 === void 0 && (k2 = k), Object.defineProperty(o, k2, { enumerable: !0, get: /* @__PURE__ */ __name(function() {
|
|
1505
|
+
return m[k];
|
|
1506
|
+
}, "get") });
|
|
1507
|
+
} : function(o, m, k, k2) {
|
|
1508
|
+
k2 === void 0 && (k2 = k), o[k2] = m[k];
|
|
1509
|
+
}), __exportStar = dist$1.__exportStar || function(m, exports2) {
|
|
1510
|
+
for (var p in m) p !== "default" && !exports2.hasOwnProperty(p) && __createBinding(exports2, m, p);
|
|
1469
1511
|
};
|
|
1470
|
-
Object.defineProperty(
|
|
1471
|
-
var
|
|
1472
|
-
Object.defineProperty(
|
|
1473
|
-
return
|
|
1474
|
-
} }), Object.defineProperty(
|
|
1475
|
-
return
|
|
1476
|
-
} });
|
|
1477
|
-
var
|
|
1478
|
-
Object.defineProperty(
|
|
1479
|
-
return
|
|
1480
|
-
} });
|
|
1481
|
-
}(
|
|
1512
|
+
Object.defineProperty(exports, "__esModule", { value: !0 }), __exportStar(requireJson1_release(), exports);
|
|
1513
|
+
var cursor_js_1 = requireCursor();
|
|
1514
|
+
Object.defineProperty(exports, "ReadCursor", { enumerable: !0, get: /* @__PURE__ */ __name(function() {
|
|
1515
|
+
return cursor_js_1.ReadCursor;
|
|
1516
|
+
}, "get") }), Object.defineProperty(exports, "WriteCursor", { enumerable: !0, get: /* @__PURE__ */ __name(function() {
|
|
1517
|
+
return cursor_js_1.WriteCursor;
|
|
1518
|
+
}, "get") });
|
|
1519
|
+
var types_1 = requireTypes();
|
|
1520
|
+
Object.defineProperty(exports, "ConflictType", { enumerable: !0, get: /* @__PURE__ */ __name(function() {
|
|
1521
|
+
return types_1.ConflictType;
|
|
1522
|
+
}, "get") });
|
|
1523
|
+
}(dist$1)), dist$1;
|
|
1482
1524
|
}
|
|
1483
|
-
|
|
1484
|
-
|
|
1525
|
+
__name(requireDist, "requireDist");
|
|
1526
|
+
var distExports = requireDist();
|
|
1527
|
+
const _UnitDrawingService = class _UnitDrawingService {
|
|
1485
1528
|
constructor() {
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1529
|
+
__publicField(this, "drawingManagerData", {});
|
|
1530
|
+
__publicField(this, "_oldDrawingManagerData", {});
|
|
1531
|
+
__publicField(this, "_focusDrawings", []);
|
|
1532
|
+
__publicField(this, "_remove$", new Subject());
|
|
1533
|
+
__publicField(this, "remove$", this._remove$.asObservable());
|
|
1534
|
+
__publicField(this, "_add$", new Subject());
|
|
1535
|
+
__publicField(this, "add$", this._add$.asObservable());
|
|
1536
|
+
__publicField(this, "_update$", new Subject());
|
|
1537
|
+
__publicField(this, "update$", this._update$.asObservable());
|
|
1538
|
+
__publicField(this, "_order$", new Subject());
|
|
1539
|
+
__publicField(this, "order$", this._order$.asObservable());
|
|
1540
|
+
__publicField(this, "_group$", new Subject());
|
|
1541
|
+
__publicField(this, "group$", this._group$.asObservable());
|
|
1542
|
+
__publicField(this, "_ungroup$", new Subject());
|
|
1543
|
+
__publicField(this, "ungroup$", this._ungroup$.asObservable());
|
|
1544
|
+
__publicField(this, "_refreshTransform$", new Subject());
|
|
1545
|
+
__publicField(this, "refreshTransform$", this._refreshTransform$.asObservable());
|
|
1546
|
+
__publicField(this, "_visible$", new Subject());
|
|
1547
|
+
__publicField(this, "visible$", this._visible$.asObservable());
|
|
1505
1548
|
// private readonly _externalUpdate$ = new Subject<T[]>();
|
|
1506
1549
|
// readonly externalUpdate$ = this._externalUpdate$.asObservable();
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1550
|
+
__publicField(this, "_focus$", new Subject());
|
|
1551
|
+
__publicField(this, "focus$", this._focus$.asObservable());
|
|
1552
|
+
__publicField(this, "_featurePluginUpdate$", new Subject());
|
|
1553
|
+
__publicField(this, "featurePluginUpdate$", this._featurePluginUpdate$.asObservable());
|
|
1554
|
+
__publicField(this, "_featurePluginAdd$", new Subject());
|
|
1555
|
+
__publicField(this, "featurePluginAdd$", this._featurePluginAdd$.asObservable());
|
|
1556
|
+
__publicField(this, "_featurePluginRemove$", new Subject());
|
|
1557
|
+
__publicField(this, "featurePluginRemove$", this._featurePluginRemove$.asObservable());
|
|
1558
|
+
__publicField(this, "_featurePluginOrderUpdate$", new Subject());
|
|
1559
|
+
__publicField(this, "featurePluginOrderUpdate$", this._featurePluginOrderUpdate$.asObservable());
|
|
1560
|
+
__publicField(this, "_featurePluginGroupUpdate$", new Subject());
|
|
1561
|
+
__publicField(this, "featurePluginGroupUpdate$", this._featurePluginGroupUpdate$.asObservable());
|
|
1562
|
+
__publicField(this, "_featurePluginUngroupUpdate$", new Subject());
|
|
1563
|
+
__publicField(this, "featurePluginUngroupUpdate$", this._featurePluginUngroupUpdate$.asObservable());
|
|
1564
|
+
__publicField(this, "_visible", !0);
|
|
1565
|
+
__publicField(this, "_editable", !0);
|
|
1523
1566
|
}
|
|
1524
1567
|
dispose() {
|
|
1525
1568
|
this._remove$.complete(), this._add$.complete(), this._update$.complete(), this._order$.complete(), this._focus$.complete(), this._featurePluginUpdate$.complete(), this._featurePluginAdd$.complete(), this._featurePluginRemove$.complete(), this._featurePluginOrderUpdate$.complete(), this.drawingManagerData = {}, this._oldDrawingManagerData = {};
|
|
1526
1569
|
}
|
|
1527
|
-
visibleNotification(
|
|
1528
|
-
this._visible$.next(
|
|
1570
|
+
visibleNotification(visibleParams) {
|
|
1571
|
+
this._visible$.next(visibleParams);
|
|
1529
1572
|
}
|
|
1530
|
-
refreshTransform(
|
|
1531
|
-
|
|
1532
|
-
const
|
|
1533
|
-
|
|
1534
|
-
}), this.refreshTransformNotification(
|
|
1573
|
+
refreshTransform(updateParams) {
|
|
1574
|
+
updateParams.forEach((updateParam) => {
|
|
1575
|
+
const param = this._getCurrentBySearch(updateParam);
|
|
1576
|
+
param != null && (param.transform = updateParam.transform, param.transforms = updateParam.transforms, param.isMultiTransform = updateParam.isMultiTransform);
|
|
1577
|
+
}), this.refreshTransformNotification(updateParams);
|
|
1535
1578
|
}
|
|
1536
|
-
getDrawingDataForUnit(
|
|
1537
|
-
return this.drawingManagerData[
|
|
1579
|
+
getDrawingDataForUnit(unitId) {
|
|
1580
|
+
return this.drawingManagerData[unitId] || {};
|
|
1538
1581
|
}
|
|
1539
|
-
removeDrawingDataForUnit(
|
|
1540
|
-
const
|
|
1541
|
-
if (
|
|
1582
|
+
removeDrawingDataForUnit(unitId) {
|
|
1583
|
+
const subUnits = this.drawingManagerData[unitId];
|
|
1584
|
+
if (subUnits == null)
|
|
1542
1585
|
return;
|
|
1543
|
-
delete this.drawingManagerData[
|
|
1544
|
-
const
|
|
1545
|
-
Object.keys(
|
|
1546
|
-
const
|
|
1547
|
-
(
|
|
1548
|
-
|
|
1586
|
+
delete this.drawingManagerData[unitId];
|
|
1587
|
+
const drawings = [];
|
|
1588
|
+
Object.keys(subUnits).forEach((subUnitId) => {
|
|
1589
|
+
const subUnit = subUnits[subUnitId];
|
|
1590
|
+
(subUnit == null ? void 0 : subUnit.data) != null && Object.keys(subUnit.data).forEach((drawingId) => {
|
|
1591
|
+
drawings.push({ unitId, subUnitId, drawingId });
|
|
1549
1592
|
});
|
|
1550
|
-
}),
|
|
1551
|
-
}
|
|
1552
|
-
registerDrawingData(
|
|
1553
|
-
this.drawingManagerData[
|
|
1554
|
-
}
|
|
1555
|
-
initializeNotification(
|
|
1556
|
-
const
|
|
1557
|
-
|
|
1558
|
-
this._establishDrawingMap(
|
|
1559
|
-
const
|
|
1560
|
-
Object.keys(
|
|
1561
|
-
const
|
|
1562
|
-
|
|
1593
|
+
}), drawings.length > 0 && this.removeNotification(drawings);
|
|
1594
|
+
}
|
|
1595
|
+
registerDrawingData(unitId, data) {
|
|
1596
|
+
this.drawingManagerData[unitId] = data;
|
|
1597
|
+
}
|
|
1598
|
+
initializeNotification(unitId) {
|
|
1599
|
+
const drawings = [], data = this.drawingManagerData[unitId];
|
|
1600
|
+
data != null && (Object.keys(data).forEach((subUnitId) => {
|
|
1601
|
+
this._establishDrawingMap(unitId, subUnitId);
|
|
1602
|
+
const subUnitData = data[subUnitId];
|
|
1603
|
+
Object.keys(subUnitData.data).forEach((drawingId) => {
|
|
1604
|
+
const drawing = subUnitData.data[drawingId];
|
|
1605
|
+
drawing.unitId = unitId, drawing.subUnitId = subUnitId, drawings.push(drawing);
|
|
1563
1606
|
});
|
|
1564
|
-
}),
|
|
1607
|
+
}), drawings.length > 0 && this.addNotification(drawings));
|
|
1565
1608
|
}
|
|
1566
|
-
getDrawingData(
|
|
1567
|
-
return this._getDrawingData(
|
|
1609
|
+
getDrawingData(unitId, subUnitId) {
|
|
1610
|
+
return this._getDrawingData(unitId, subUnitId);
|
|
1568
1611
|
}
|
|
1569
1612
|
// Use in doc only.
|
|
1570
|
-
setDrawingData(
|
|
1571
|
-
this.drawingManagerData[
|
|
1572
|
-
}
|
|
1573
|
-
getBatchAddOp(
|
|
1574
|
-
const
|
|
1575
|
-
|
|
1576
|
-
const { op:
|
|
1577
|
-
|
|
1613
|
+
setDrawingData(unitId, subUnitId, data) {
|
|
1614
|
+
this.drawingManagerData[unitId][subUnitId].data = data;
|
|
1615
|
+
}
|
|
1616
|
+
getBatchAddOp(insertParams) {
|
|
1617
|
+
const objects = [], ops = [], invertOps = [];
|
|
1618
|
+
insertParams.forEach((insertParam) => {
|
|
1619
|
+
const { op: op2, invertOp: invertOp2 } = this._addByParam(insertParam);
|
|
1620
|
+
objects.push({ unitId: insertParam.unitId, subUnitId: insertParam.subUnitId, drawingId: insertParam.drawingId }), ops.push(op2), invertOps.push(invertOp2);
|
|
1578
1621
|
});
|
|
1579
|
-
const
|
|
1580
|
-
return { undo:
|
|
1581
|
-
}
|
|
1582
|
-
getBatchRemoveOp(
|
|
1583
|
-
const
|
|
1584
|
-
|
|
1585
|
-
const { op:
|
|
1586
|
-
|
|
1622
|
+
const op = ops.reduce(distExports.type.compose, null), invertOp = invertOps.reduce(distExports.type.compose, null), { unitId, subUnitId } = insertParams[0];
|
|
1623
|
+
return { undo: invertOp, redo: op, unitId, subUnitId, objects };
|
|
1624
|
+
}
|
|
1625
|
+
getBatchRemoveOp(removeParams) {
|
|
1626
|
+
const ops = [], invertOps = [];
|
|
1627
|
+
removeParams.forEach((removeParam) => {
|
|
1628
|
+
const { op: op2, invertOp: invertOp2 } = this._removeByParam(removeParam);
|
|
1629
|
+
ops.unshift(op2), invertOps.push(invertOp2);
|
|
1587
1630
|
});
|
|
1588
|
-
const
|
|
1589
|
-
return { undo:
|
|
1590
|
-
}
|
|
1591
|
-
getBatchUpdateOp(
|
|
1592
|
-
const
|
|
1593
|
-
|
|
1594
|
-
const { op:
|
|
1595
|
-
|
|
1631
|
+
const op = ops.reduce(distExports.type.compose, null), invertOp = invertOps.reduce(distExports.type.compose, null), { unitId, subUnitId } = removeParams[0];
|
|
1632
|
+
return { undo: invertOp, redo: op, unitId, subUnitId, objects: removeParams };
|
|
1633
|
+
}
|
|
1634
|
+
getBatchUpdateOp(updateParams) {
|
|
1635
|
+
const objects = [], ops = [], invertOps = [];
|
|
1636
|
+
updateParams.forEach((updateParam) => {
|
|
1637
|
+
const { op: op2, invertOp: invertOp2 } = this._updateByParam(updateParam);
|
|
1638
|
+
objects.push({ unitId: updateParam.unitId, subUnitId: updateParam.subUnitId, drawingId: updateParam.drawingId }), ops.push(op2), invertOps.push(invertOp2);
|
|
1596
1639
|
});
|
|
1597
|
-
const
|
|
1598
|
-
return { undo:
|
|
1640
|
+
const op = ops.reduce(distExports.type.compose, null), invertOp = invertOps.reduce(distExports.type.compose, null), { unitId, subUnitId } = updateParams[0];
|
|
1641
|
+
return { undo: invertOp, redo: op, unitId, subUnitId, objects };
|
|
1599
1642
|
}
|
|
1600
|
-
removeNotification(
|
|
1601
|
-
this._remove$.next(
|
|
1643
|
+
removeNotification(removeParams) {
|
|
1644
|
+
this._remove$.next(removeParams);
|
|
1602
1645
|
}
|
|
1603
|
-
addNotification(
|
|
1604
|
-
this._add$.next(
|
|
1646
|
+
addNotification(insertParams) {
|
|
1647
|
+
this._add$.next(insertParams);
|
|
1605
1648
|
}
|
|
1606
|
-
updateNotification(
|
|
1607
|
-
this._update$.next(
|
|
1649
|
+
updateNotification(updateParams) {
|
|
1650
|
+
this._update$.next(updateParams);
|
|
1608
1651
|
}
|
|
1609
|
-
orderNotification(
|
|
1610
|
-
this._order$.next(
|
|
1652
|
+
orderNotification(orderParams) {
|
|
1653
|
+
this._order$.next(orderParams);
|
|
1611
1654
|
}
|
|
1612
|
-
groupUpdateNotification(
|
|
1613
|
-
this._group$.next(
|
|
1655
|
+
groupUpdateNotification(groupParams) {
|
|
1656
|
+
this._group$.next(groupParams);
|
|
1614
1657
|
}
|
|
1615
|
-
ungroupUpdateNotification(
|
|
1616
|
-
this._ungroup$.next(
|
|
1658
|
+
ungroupUpdateNotification(groupParams) {
|
|
1659
|
+
this._ungroup$.next(groupParams);
|
|
1617
1660
|
}
|
|
1618
|
-
refreshTransformNotification(
|
|
1619
|
-
this._refreshTransform$.next(
|
|
1661
|
+
refreshTransformNotification(refreshParams) {
|
|
1662
|
+
this._refreshTransform$.next(refreshParams);
|
|
1620
1663
|
}
|
|
1621
|
-
getGroupDrawingOp(
|
|
1622
|
-
const
|
|
1623
|
-
|
|
1624
|
-
|
|
1664
|
+
getGroupDrawingOp(groupParams) {
|
|
1665
|
+
const ops = [], { unitId, subUnitId } = groupParams[0].parent;
|
|
1666
|
+
groupParams.forEach((groupParam) => {
|
|
1667
|
+
ops.push(this._getGroupDrawingOp(groupParam));
|
|
1625
1668
|
});
|
|
1626
|
-
const
|
|
1627
|
-
return { undo:
|
|
1669
|
+
const op = ops.reduce(distExports.type.compose, null);
|
|
1670
|
+
return { undo: distExports.type.invertWithDoc(op, this.drawingManagerData), redo: op, unitId, subUnitId, objects: groupParams };
|
|
1628
1671
|
}
|
|
1629
|
-
getUngroupDrawingOp(
|
|
1630
|
-
const
|
|
1631
|
-
|
|
1632
|
-
|
|
1672
|
+
getUngroupDrawingOp(groupParams) {
|
|
1673
|
+
const ops = [], { unitId, subUnitId } = groupParams[0].parent;
|
|
1674
|
+
groupParams.forEach((groupParam) => {
|
|
1675
|
+
ops.push(this._getUngroupDrawingOp(groupParam));
|
|
1633
1676
|
});
|
|
1634
|
-
const
|
|
1635
|
-
return { undo:
|
|
1677
|
+
const op = ops.reduce(distExports.type.compose, null);
|
|
1678
|
+
return { undo: distExports.type.invertWithDoc(op, this.drawingManagerData), redo: op, unitId, subUnitId, objects: groupParams };
|
|
1636
1679
|
}
|
|
1637
|
-
getDrawingsByGroup(
|
|
1638
|
-
const { unitId
|
|
1639
|
-
if (this.getDrawingByParam({ unitId
|
|
1680
|
+
getDrawingsByGroup(groupParam) {
|
|
1681
|
+
const { unitId, subUnitId, drawingId } = groupParam;
|
|
1682
|
+
if (this.getDrawingByParam({ unitId, subUnitId, drawingId }) == null)
|
|
1640
1683
|
return [];
|
|
1641
|
-
const
|
|
1642
|
-
return Object.keys(
|
|
1643
|
-
const
|
|
1644
|
-
|
|
1645
|
-
}),
|
|
1646
|
-
}
|
|
1647
|
-
_getGroupDrawingOp(
|
|
1648
|
-
const { parent
|
|
1649
|
-
|
|
1650
|
-
|
|
1684
|
+
const drawings = this._getDrawingData(unitId, subUnitId), children = [];
|
|
1685
|
+
return Object.keys(drawings).forEach((key) => {
|
|
1686
|
+
const drawing = drawings[key];
|
|
1687
|
+
drawing.groupId === drawingId && children.push(drawing);
|
|
1688
|
+
}), children;
|
|
1689
|
+
}
|
|
1690
|
+
_getGroupDrawingOp(groupParam) {
|
|
1691
|
+
const { parent, children } = groupParam, { unitId: groupUnitId, subUnitId: groupSubUnitId, drawingId: groupDrawingId } = parent, ops = [];
|
|
1692
|
+
ops.push(
|
|
1693
|
+
distExports.insertOp([groupUnitId, groupSubUnitId, "data", groupDrawingId], parent)
|
|
1651
1694
|
);
|
|
1652
|
-
let
|
|
1653
|
-
return
|
|
1654
|
-
const { unitId
|
|
1655
|
-
|
|
1656
|
-
...this._getUpdateParamCompareOp(
|
|
1695
|
+
let maxChildIndex = Number.NEGATIVE_INFINITY;
|
|
1696
|
+
return children.forEach((child) => {
|
|
1697
|
+
const { unitId, subUnitId, drawingId } = child, index = this._hasDrawingOrder({ unitId, subUnitId, drawingId });
|
|
1698
|
+
maxChildIndex = Math.max(maxChildIndex, index), ops.push(
|
|
1699
|
+
...this._getUpdateParamCompareOp(child, this.getDrawingByParam({ unitId, subUnitId, drawingId }))
|
|
1657
1700
|
);
|
|
1658
|
-
}),
|
|
1659
|
-
|
|
1660
|
-
),
|
|
1661
|
-
}
|
|
1662
|
-
_getUngroupDrawingOp(
|
|
1663
|
-
const { parent
|
|
1664
|
-
return
|
|
1665
|
-
const { unitId
|
|
1666
|
-
|
|
1667
|
-
...this._getUpdateParamCompareOp(
|
|
1701
|
+
}), maxChildIndex === Number.NEGATIVE_INFINITY && (maxChildIndex = this._getDrawingOrder(groupUnitId, groupSubUnitId).length), ops.push(
|
|
1702
|
+
distExports.insertOp([groupUnitId, groupSubUnitId, "order", maxChildIndex], groupDrawingId)
|
|
1703
|
+
), ops.reduce(distExports.type.compose, null);
|
|
1704
|
+
}
|
|
1705
|
+
_getUngroupDrawingOp(groupParam) {
|
|
1706
|
+
const { parent, children } = groupParam, { unitId: groupUnitId, subUnitId: groupSubUnitId, drawingId: groupDrawingId } = parent, ops = [];
|
|
1707
|
+
return children.forEach((child) => {
|
|
1708
|
+
const { unitId, subUnitId, drawingId } = child;
|
|
1709
|
+
ops.push(
|
|
1710
|
+
...this._getUpdateParamCompareOp(child, this.getDrawingByParam({ unitId, subUnitId, drawingId }))
|
|
1668
1711
|
);
|
|
1669
|
-
}),
|
|
1670
|
-
|
|
1671
|
-
),
|
|
1672
|
-
|
|
1673
|
-
),
|
|
1712
|
+
}), ops.push(
|
|
1713
|
+
distExports.removeOp([groupUnitId, groupSubUnitId, "data", groupDrawingId], !0)
|
|
1714
|
+
), ops.push(
|
|
1715
|
+
distExports.removeOp([groupUnitId, groupSubUnitId, "order", this._getDrawingOrder(groupUnitId, groupSubUnitId).indexOf(groupDrawingId)], !0)
|
|
1716
|
+
), ops.reduce(distExports.type.compose, null);
|
|
1674
1717
|
}
|
|
1675
|
-
applyJson1(
|
|
1676
|
-
this._establishDrawingMap(
|
|
1718
|
+
applyJson1(unitId, subUnitId, jsonOp) {
|
|
1719
|
+
this._establishDrawingMap(unitId, subUnitId), this._oldDrawingManagerData = { ...this.drawingManagerData }, this.drawingManagerData = distExports.type.apply(this.drawingManagerData, jsonOp);
|
|
1677
1720
|
}
|
|
1678
1721
|
// private _fillMissingFields(jsonOp: JSONOp) {
|
|
1679
1722
|
// if (jsonOp == null) {
|
|
@@ -1695,163 +1738,163 @@ class on {
|
|
|
1695
1738
|
// }
|
|
1696
1739
|
// }
|
|
1697
1740
|
// }
|
|
1698
|
-
featurePluginUpdateNotification(
|
|
1699
|
-
this._featurePluginUpdate$.next(
|
|
1741
|
+
featurePluginUpdateNotification(updateParams) {
|
|
1742
|
+
this._featurePluginUpdate$.next(updateParams);
|
|
1700
1743
|
}
|
|
1701
|
-
featurePluginOrderUpdateNotification(
|
|
1702
|
-
this._featurePluginOrderUpdate$.next(
|
|
1744
|
+
featurePluginOrderUpdateNotification(drawingOrderUpdateParam) {
|
|
1745
|
+
this._featurePluginOrderUpdate$.next(drawingOrderUpdateParam);
|
|
1703
1746
|
}
|
|
1704
|
-
featurePluginAddNotification(
|
|
1705
|
-
this._featurePluginAdd$.next(
|
|
1747
|
+
featurePluginAddNotification(insertParams) {
|
|
1748
|
+
this._featurePluginAdd$.next(insertParams);
|
|
1706
1749
|
}
|
|
1707
|
-
featurePluginRemoveNotification(
|
|
1708
|
-
this._featurePluginRemove$.next(
|
|
1750
|
+
featurePluginRemoveNotification(removeParams) {
|
|
1751
|
+
this._featurePluginRemove$.next(removeParams);
|
|
1709
1752
|
}
|
|
1710
|
-
featurePluginGroupUpdateNotification(
|
|
1711
|
-
this._featurePluginGroupUpdate$.next(
|
|
1753
|
+
featurePluginGroupUpdateNotification(groupParams) {
|
|
1754
|
+
this._featurePluginGroupUpdate$.next(groupParams);
|
|
1712
1755
|
}
|
|
1713
|
-
featurePluginUngroupUpdateNotification(
|
|
1714
|
-
this._featurePluginUngroupUpdate$.next(
|
|
1756
|
+
featurePluginUngroupUpdateNotification(groupParams) {
|
|
1757
|
+
this._featurePluginUngroupUpdate$.next(groupParams);
|
|
1715
1758
|
}
|
|
1716
|
-
getDrawingByParam(
|
|
1717
|
-
return this._getCurrentBySearch(
|
|
1759
|
+
getDrawingByParam(param) {
|
|
1760
|
+
return this._getCurrentBySearch(param);
|
|
1718
1761
|
}
|
|
1719
|
-
getOldDrawingByParam(
|
|
1720
|
-
return this._getOldBySearch(
|
|
1762
|
+
getOldDrawingByParam(param) {
|
|
1763
|
+
return this._getOldBySearch(param);
|
|
1721
1764
|
}
|
|
1722
|
-
getDrawingOKey(
|
|
1723
|
-
const [
|
|
1724
|
-
return this._getCurrentBySearch({ unitId
|
|
1765
|
+
getDrawingOKey(oKey) {
|
|
1766
|
+
const [unitId, subUnitId, drawingId] = oKey.split("#-#");
|
|
1767
|
+
return this._getCurrentBySearch({ unitId, subUnitId, drawingId });
|
|
1725
1768
|
}
|
|
1726
|
-
focusDrawing(
|
|
1727
|
-
if (
|
|
1769
|
+
focusDrawing(params) {
|
|
1770
|
+
if (params == null || params.length === 0) {
|
|
1728
1771
|
this._focusDrawings = [], this._focus$.next([]);
|
|
1729
1772
|
return;
|
|
1730
1773
|
}
|
|
1731
|
-
const
|
|
1732
|
-
|
|
1733
|
-
var
|
|
1734
|
-
const { unitId
|
|
1735
|
-
|
|
1736
|
-
}),
|
|
1774
|
+
const drawingParams = [];
|
|
1775
|
+
params.forEach((param) => {
|
|
1776
|
+
var _a2;
|
|
1777
|
+
const { unitId, subUnitId, drawingId } = param, item = (_a2 = this._getDrawingData(unitId, subUnitId)) == null ? void 0 : _a2[drawingId];
|
|
1778
|
+
item != null && drawingParams.push(item);
|
|
1779
|
+
}), drawingParams.length > 0 && (this._focusDrawings = drawingParams, this._focus$.next(drawingParams));
|
|
1737
1780
|
}
|
|
1738
1781
|
getFocusDrawings() {
|
|
1739
|
-
const
|
|
1740
|
-
return this._focusDrawings.forEach((
|
|
1741
|
-
var
|
|
1742
|
-
const { unitId
|
|
1743
|
-
|
|
1744
|
-
}),
|
|
1782
|
+
const drawingParams = [];
|
|
1783
|
+
return this._focusDrawings.forEach((param) => {
|
|
1784
|
+
var _a2;
|
|
1785
|
+
const { unitId, subUnitId, drawingId } = param, item = (_a2 = this._getDrawingData(unitId, subUnitId)) == null ? void 0 : _a2[drawingId];
|
|
1786
|
+
item != null && drawingParams.push(item);
|
|
1787
|
+
}), drawingParams;
|
|
1745
1788
|
}
|
|
1746
|
-
getDrawingOrder(
|
|
1747
|
-
return this._getDrawingOrder(
|
|
1789
|
+
getDrawingOrder(unitId, subUnitId) {
|
|
1790
|
+
return this._getDrawingOrder(unitId, subUnitId);
|
|
1748
1791
|
}
|
|
1749
1792
|
// Use in doc only.
|
|
1750
|
-
setDrawingOrder(
|
|
1751
|
-
this.drawingManagerData[
|
|
1793
|
+
setDrawingOrder(unitId, subUnitId, order) {
|
|
1794
|
+
this.drawingManagerData[unitId][subUnitId].order = order;
|
|
1752
1795
|
}
|
|
1753
|
-
orderUpdateNotification(
|
|
1754
|
-
this._order$.next(
|
|
1796
|
+
orderUpdateNotification(orderParams) {
|
|
1797
|
+
this._order$.next(orderParams);
|
|
1755
1798
|
}
|
|
1756
|
-
getForwardDrawingsOp(
|
|
1757
|
-
const { unitId
|
|
1758
|
-
|
|
1759
|
-
const
|
|
1760
|
-
if (
|
|
1799
|
+
getForwardDrawingsOp(orderParams) {
|
|
1800
|
+
const { unitId, subUnitId, drawingIds } = orderParams, ops = [], orders = this.getDrawingOrder(unitId, subUnitId), newIds = [...drawingIds];
|
|
1801
|
+
drawingIds.forEach((drawingId) => {
|
|
1802
|
+
const index = this._hasDrawingOrder({ unitId, subUnitId, drawingId });
|
|
1803
|
+
if (index === -1 || index === orders.length - 1)
|
|
1761
1804
|
return;
|
|
1762
|
-
const
|
|
1763
|
-
|
|
1805
|
+
const op2 = distExports.moveOp([unitId, subUnitId, "order", index], [unitId, subUnitId, "order", index + 1]);
|
|
1806
|
+
ops.push(op2), newIds.includes(orders[index + 1]) || newIds.push(orders[index + 1]);
|
|
1764
1807
|
});
|
|
1765
|
-
const
|
|
1766
|
-
return { undo:
|
|
1767
|
-
}
|
|
1768
|
-
getBackwardDrawingOp(
|
|
1769
|
-
const { unitId
|
|
1770
|
-
|
|
1771
|
-
const
|
|
1772
|
-
if (
|
|
1808
|
+
const op = ops.reduce(distExports.type.compose, null);
|
|
1809
|
+
return { undo: distExports.type.invertWithDoc(op, this.drawingManagerData), redo: op, unitId, subUnitId, objects: { ...orderParams, drawingIds: newIds } };
|
|
1810
|
+
}
|
|
1811
|
+
getBackwardDrawingOp(orderParams) {
|
|
1812
|
+
const { unitId, subUnitId, drawingIds } = orderParams, ops = [], orders = this.getDrawingOrder(unitId, subUnitId), newIds = [...drawingIds];
|
|
1813
|
+
drawingIds.forEach((drawingId) => {
|
|
1814
|
+
const index = this._hasDrawingOrder({ unitId, subUnitId, drawingId });
|
|
1815
|
+
if (index === -1 || index === 0)
|
|
1773
1816
|
return;
|
|
1774
|
-
const
|
|
1775
|
-
|
|
1817
|
+
const op2 = distExports.moveOp([unitId, subUnitId, "order", index], [unitId, subUnitId, "order", index - 1]);
|
|
1818
|
+
ops.push(op2), newIds.includes(orders[index - 1]) || newIds.push(orders[index - 1]);
|
|
1776
1819
|
});
|
|
1777
|
-
const
|
|
1778
|
-
return { undo:
|
|
1779
|
-
}
|
|
1780
|
-
getFrontDrawingsOp(
|
|
1781
|
-
const { unitId
|
|
1782
|
-
|
|
1783
|
-
const { drawingId
|
|
1784
|
-
|
|
1820
|
+
const op = ops.reduce(distExports.type.compose, null);
|
|
1821
|
+
return { undo: distExports.type.invertWithDoc(op, this.drawingManagerData), redo: op, unitId, subUnitId, objects: { ...orderParams, drawingIds: newIds } };
|
|
1822
|
+
}
|
|
1823
|
+
getFrontDrawingsOp(orderParams) {
|
|
1824
|
+
const { unitId, subUnitId, drawingIds } = orderParams, orderDrawingIds = this._getOrderFromSearchParams(unitId, subUnitId, drawingIds), newIds = [...drawingIds], orders = this.getDrawingOrder(unitId, subUnitId), ops = [];
|
|
1825
|
+
orderDrawingIds.forEach((orderDrawingId) => {
|
|
1826
|
+
const { drawingId } = orderDrawingId, index = this._getDrawingCount(unitId, subUnitId) - 1, op2 = distExports.moveOp([unitId, subUnitId, "order", this._getDrawingOrder(unitId, subUnitId).indexOf(drawingId)], [unitId, subUnitId, "order", index]);
|
|
1827
|
+
ops.push(op2), newIds.includes(orders[index]) || newIds.push(orders[index]);
|
|
1785
1828
|
});
|
|
1786
|
-
const
|
|
1787
|
-
return { undo:
|
|
1788
|
-
}
|
|
1789
|
-
getBackDrawingsOp(
|
|
1790
|
-
const { unitId
|
|
1791
|
-
|
|
1792
|
-
const { drawingId
|
|
1793
|
-
|
|
1829
|
+
const op = ops.reduce(distExports.type.compose, null);
|
|
1830
|
+
return { undo: distExports.type.invertWithDoc(op, this.drawingManagerData), redo: op, unitId, subUnitId, objects: { ...orderParams, drawingIds: newIds } };
|
|
1831
|
+
}
|
|
1832
|
+
getBackDrawingsOp(orderParams) {
|
|
1833
|
+
const { unitId, subUnitId, drawingIds } = orderParams, orderSearchParams = this._getOrderFromSearchParams(unitId, subUnitId, drawingIds, !0), newIds = [...drawingIds], orders = this.getDrawingOrder(unitId, subUnitId), ops = [];
|
|
1834
|
+
orderSearchParams.forEach((orderSearchParam) => {
|
|
1835
|
+
const { drawingId } = orderSearchParam, op2 = distExports.moveOp([unitId, subUnitId, "order", this._getDrawingOrder(unitId, subUnitId).indexOf(drawingId)], [unitId, subUnitId, "order", 0]);
|
|
1836
|
+
ops.push(op2), newIds.includes(orders[0]) || newIds.push(orders[0]);
|
|
1794
1837
|
});
|
|
1795
|
-
const
|
|
1796
|
-
return { undo:
|
|
1838
|
+
const op = ops.reduce(distExports.type.compose, null);
|
|
1839
|
+
return { undo: distExports.type.invertWithDoc(op, this.drawingManagerData), redo: op, unitId, subUnitId, objects: { ...orderParams, drawingIds: newIds } };
|
|
1797
1840
|
}
|
|
1798
|
-
_getDrawingCount(
|
|
1799
|
-
return this.getDrawingOrder(
|
|
1841
|
+
_getDrawingCount(unitId, subUnitId) {
|
|
1842
|
+
return this.getDrawingOrder(unitId, subUnitId).length || 0;
|
|
1800
1843
|
}
|
|
1801
|
-
_getOrderFromSearchParams(
|
|
1802
|
-
return
|
|
1803
|
-
const
|
|
1804
|
-
return { drawingId
|
|
1805
|
-
}).sort(
|
|
1844
|
+
_getOrderFromSearchParams(unitId, subUnitId, drawingIds, isDesc = !1) {
|
|
1845
|
+
return drawingIds.map((drawingId) => {
|
|
1846
|
+
const zIndex = this._hasDrawingOrder({ unitId, subUnitId, drawingId });
|
|
1847
|
+
return { drawingId, zIndex };
|
|
1848
|
+
}).sort(isDesc === !1 ? sortRules : sortRulesByDesc);
|
|
1806
1849
|
}
|
|
1807
|
-
_hasDrawingOrder(
|
|
1808
|
-
if (
|
|
1850
|
+
_hasDrawingOrder(searchParam) {
|
|
1851
|
+
if (searchParam == null)
|
|
1809
1852
|
return -1;
|
|
1810
|
-
const { unitId
|
|
1811
|
-
return this._establishDrawingMap(
|
|
1853
|
+
const { unitId, subUnitId, drawingId } = searchParam;
|
|
1854
|
+
return this._establishDrawingMap(unitId, subUnitId), this._getDrawingOrder(unitId, subUnitId).indexOf(drawingId);
|
|
1812
1855
|
}
|
|
1813
|
-
_getCurrentBySearch(
|
|
1814
|
-
var
|
|
1815
|
-
if (
|
|
1856
|
+
_getCurrentBySearch(searchParam) {
|
|
1857
|
+
var _a2, _b, _c;
|
|
1858
|
+
if (searchParam == null)
|
|
1816
1859
|
return;
|
|
1817
|
-
const { unitId
|
|
1818
|
-
return (
|
|
1860
|
+
const { unitId, subUnitId, drawingId } = searchParam;
|
|
1861
|
+
return (_c = (_b = (_a2 = this.drawingManagerData[unitId]) == null ? void 0 : _a2[subUnitId]) == null ? void 0 : _b.data) == null ? void 0 : _c[drawingId];
|
|
1819
1862
|
}
|
|
1820
|
-
_getOldBySearch(
|
|
1821
|
-
var
|
|
1822
|
-
if (
|
|
1863
|
+
_getOldBySearch(searchParam) {
|
|
1864
|
+
var _a2, _b, _c;
|
|
1865
|
+
if (searchParam == null)
|
|
1823
1866
|
return;
|
|
1824
|
-
const { unitId
|
|
1825
|
-
return (
|
|
1867
|
+
const { unitId, subUnitId, drawingId } = searchParam;
|
|
1868
|
+
return (_c = (_b = (_a2 = this._oldDrawingManagerData[unitId]) == null ? void 0 : _a2[subUnitId]) == null ? void 0 : _b.data) == null ? void 0 : _c[drawingId];
|
|
1826
1869
|
}
|
|
1827
|
-
_establishDrawingMap(
|
|
1828
|
-
var
|
|
1829
|
-
return this.drawingManagerData[
|
|
1870
|
+
_establishDrawingMap(unitId, subUnitId, drawingId) {
|
|
1871
|
+
var _a2;
|
|
1872
|
+
return this.drawingManagerData[unitId] || (this.drawingManagerData[unitId] = {}), this.drawingManagerData[unitId][subUnitId] || (this.drawingManagerData[unitId][subUnitId] = {
|
|
1830
1873
|
data: {},
|
|
1831
1874
|
order: []
|
|
1832
|
-
}),
|
|
1875
|
+
}), drawingId == null ? null : (_a2 = this.drawingManagerData[unitId][subUnitId].data) == null ? void 0 : _a2[drawingId];
|
|
1833
1876
|
}
|
|
1834
|
-
_addByParam(
|
|
1835
|
-
const { unitId
|
|
1836
|
-
this._establishDrawingMap(
|
|
1837
|
-
const
|
|
1838
|
-
return { op
|
|
1877
|
+
_addByParam(insertParam) {
|
|
1878
|
+
const { unitId, subUnitId, drawingId } = insertParam;
|
|
1879
|
+
this._establishDrawingMap(unitId, subUnitId, drawingId);
|
|
1880
|
+
const op1 = distExports.insertOp([unitId, subUnitId, "data", drawingId], insertParam), op2 = distExports.insertOp([unitId, subUnitId, "order", this._getDrawingOrder(unitId, subUnitId).length], drawingId), op = [op1, op2].reduce(distExports.type.compose, null), invertOp = distExports.type.invertWithDoc(op, this.drawingManagerData);
|
|
1881
|
+
return { op, invertOp };
|
|
1839
1882
|
}
|
|
1840
|
-
_removeByParam(
|
|
1841
|
-
if (
|
|
1883
|
+
_removeByParam(searchParam) {
|
|
1884
|
+
if (searchParam == null)
|
|
1842
1885
|
return { op: [], invertOp: [] };
|
|
1843
|
-
const { unitId
|
|
1844
|
-
if (this._establishDrawingMap(
|
|
1886
|
+
const { unitId, subUnitId, drawingId } = searchParam;
|
|
1887
|
+
if (this._establishDrawingMap(unitId, subUnitId, drawingId) == null)
|
|
1845
1888
|
return { op: [], invertOp: [] };
|
|
1846
|
-
const
|
|
1847
|
-
return { op
|
|
1889
|
+
const op1 = distExports.removeOp([unitId, subUnitId, "data", drawingId], !0), op2 = distExports.removeOp([unitId, subUnitId, "order", this._getDrawingOrder(unitId, subUnitId).indexOf(drawingId)], !0), op = [op1, op2].reduce(distExports.type.compose, null), invertOp = distExports.type.invertWithDoc(op, this.drawingManagerData);
|
|
1890
|
+
return { op, invertOp };
|
|
1848
1891
|
}
|
|
1849
|
-
_updateByParam(
|
|
1850
|
-
const { unitId
|
|
1851
|
-
if (
|
|
1892
|
+
_updateByParam(updateParam) {
|
|
1893
|
+
const { unitId, subUnitId, drawingId } = updateParam, object = this._establishDrawingMap(unitId, subUnitId, drawingId);
|
|
1894
|
+
if (object == null)
|
|
1852
1895
|
return { op: [], invertOp: [] };
|
|
1853
|
-
const
|
|
1854
|
-
return { op
|
|
1896
|
+
const op = this._getUpdateParamCompareOp(updateParam, object).reduce(distExports.type.compose, null), invertOp = distExports.type.invertWithDoc(op, this.drawingManagerData);
|
|
1897
|
+
return { op, invertOp };
|
|
1855
1898
|
}
|
|
1856
1899
|
// private _initializeDrawingData(updateParam: T, oldParam: T) {
|
|
1857
1900
|
// Object.keys(updateParam).forEach((key) => {
|
|
@@ -1860,22 +1903,22 @@ class on {
|
|
|
1860
1903
|
// }
|
|
1861
1904
|
// });
|
|
1862
1905
|
// }
|
|
1863
|
-
_getUpdateParamCompareOp(
|
|
1864
|
-
const { unitId
|
|
1865
|
-
return Object.keys(
|
|
1866
|
-
const
|
|
1867
|
-
|
|
1868
|
-
|
|
1906
|
+
_getUpdateParamCompareOp(newParam, oldParam) {
|
|
1907
|
+
const { unitId, subUnitId, drawingId } = newParam, ops = [];
|
|
1908
|
+
return Object.keys(newParam).forEach((key) => {
|
|
1909
|
+
const newVal = newParam[key], oldVal = oldParam[key];
|
|
1910
|
+
oldVal !== newVal && ops.push(
|
|
1911
|
+
distExports.replaceOp([unitId, subUnitId, "data", drawingId, key], oldVal, newVal)
|
|
1869
1912
|
);
|
|
1870
|
-
}),
|
|
1913
|
+
}), ops;
|
|
1871
1914
|
}
|
|
1872
|
-
_getDrawingData(
|
|
1873
|
-
var
|
|
1874
|
-
return ((
|
|
1915
|
+
_getDrawingData(unitId, subUnitId) {
|
|
1916
|
+
var _a2, _b;
|
|
1917
|
+
return ((_b = (_a2 = this.drawingManagerData[unitId]) == null ? void 0 : _a2[subUnitId]) == null ? void 0 : _b.data) || {};
|
|
1875
1918
|
}
|
|
1876
|
-
_getDrawingOrder(
|
|
1877
|
-
var
|
|
1878
|
-
return ((
|
|
1919
|
+
_getDrawingOrder(unitId, subUnitId) {
|
|
1920
|
+
var _a2, _b;
|
|
1921
|
+
return ((_b = (_a2 = this.drawingManagerData[unitId]) == null ? void 0 : _a2[subUnitId]) == null ? void 0 : _b.order) || [];
|
|
1879
1922
|
}
|
|
1880
1923
|
getDrawingVisible() {
|
|
1881
1924
|
return this._visible;
|
|
@@ -1883,85 +1926,89 @@ class on {
|
|
|
1883
1926
|
getDrawingEditable() {
|
|
1884
1927
|
return this._editable;
|
|
1885
1928
|
}
|
|
1886
|
-
setDrawingVisible(
|
|
1887
|
-
this._visible =
|
|
1929
|
+
setDrawingVisible(visible) {
|
|
1930
|
+
this._visible = visible;
|
|
1888
1931
|
}
|
|
1889
|
-
setDrawingEditable(
|
|
1890
|
-
this._editable =
|
|
1932
|
+
setDrawingEditable(editable) {
|
|
1933
|
+
this._editable = editable;
|
|
1891
1934
|
}
|
|
1935
|
+
};
|
|
1936
|
+
__name(_UnitDrawingService, "UnitDrawingService");
|
|
1937
|
+
let UnitDrawingService = _UnitDrawingService;
|
|
1938
|
+
const _DrawingManagerService = class _DrawingManagerService extends UnitDrawingService {
|
|
1939
|
+
};
|
|
1940
|
+
__name(_DrawingManagerService, "DrawingManagerService");
|
|
1941
|
+
let DrawingManagerService = _DrawingManagerService;
|
|
1942
|
+
function getDrawingShapeKeyByDrawingSearch({ unitId, subUnitId, drawingId }, index) {
|
|
1943
|
+
return typeof index == "number" ? `${unitId}#-#${subUnitId}#-#${drawingId}#-#${index}` : `${unitId}#-#${subUnitId}#-#${drawingId}`;
|
|
1892
1944
|
}
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
e({
|
|
1902
|
-
width: t.width,
|
|
1903
|
-
height: t.height,
|
|
1904
|
-
image: t
|
|
1945
|
+
__name(getDrawingShapeKeyByDrawingSearch, "getDrawingShapeKeyByDrawingSearch");
|
|
1946
|
+
const getImageSize = /* @__PURE__ */ __name(async (src) => new Promise((resolve, reject) => {
|
|
1947
|
+
const image = new Image();
|
|
1948
|
+
image.src = src, image.onload = () => {
|
|
1949
|
+
resolve({
|
|
1950
|
+
width: image.width,
|
|
1951
|
+
height: image.height,
|
|
1952
|
+
image
|
|
1905
1953
|
});
|
|
1906
|
-
},
|
|
1907
|
-
|
|
1954
|
+
}, image.onerror = (error) => {
|
|
1955
|
+
reject(error);
|
|
1908
1956
|
};
|
|
1909
|
-
}),
|
|
1957
|
+
}), "getImageSize"), IDrawingManagerService = createIdentifier("univer.drawing-manager.service"), SetDrawingSelectedOperation = {
|
|
1910
1958
|
id: "drawing.operation.set-drawing-selected",
|
|
1911
|
-
type:
|
|
1912
|
-
handler: (
|
|
1913
|
-
const
|
|
1914
|
-
return
|
|
1915
|
-
}
|
|
1916
|
-
},
|
|
1917
|
-
class dn {
|
|
1959
|
+
type: CommandType.OPERATION,
|
|
1960
|
+
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
1961
|
+
const drawingManagerService = accessor.get(IDrawingManagerService);
|
|
1962
|
+
return params == null ? !1 : (drawingManagerService.focusDrawing(params), !0);
|
|
1963
|
+
}, "handler")
|
|
1964
|
+
}, DRAWING_PLUGIN_CONFIG_KEY = "drawing.config", defaultPluginConfig = {}, _ImageIoService = class _ImageIoService {
|
|
1918
1965
|
constructor() {
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
}
|
|
1924
|
-
setWaitCount(
|
|
1925
|
-
this._waitCount =
|
|
1926
|
-
}
|
|
1927
|
-
getImageSourceCache(
|
|
1928
|
-
if (
|
|
1929
|
-
const
|
|
1930
|
-
return
|
|
1966
|
+
__publicField(this, "_waitCount", 0);
|
|
1967
|
+
__publicField(this, "_change$", new Subject());
|
|
1968
|
+
__publicField(this, "change$", this._change$);
|
|
1969
|
+
__publicField(this, "_imageSourceCache", /* @__PURE__ */ new Map());
|
|
1970
|
+
}
|
|
1971
|
+
setWaitCount(count) {
|
|
1972
|
+
this._waitCount = count, this._change$.next(count);
|
|
1973
|
+
}
|
|
1974
|
+
getImageSourceCache(source, imageSourceType) {
|
|
1975
|
+
if (imageSourceType === ImageSourceType.BASE64) {
|
|
1976
|
+
const image = new Image();
|
|
1977
|
+
return image.src = source, image;
|
|
1931
1978
|
}
|
|
1932
|
-
return this._imageSourceCache.get(
|
|
1979
|
+
return this._imageSourceCache.get(source);
|
|
1933
1980
|
}
|
|
1934
|
-
addImageSourceCache(
|
|
1935
|
-
|
|
1981
|
+
addImageSourceCache(source, imageSourceType, imageSource) {
|
|
1982
|
+
imageSourceType === ImageSourceType.BASE64 || imageSource == null || this._imageSourceCache.set(source, imageSource);
|
|
1936
1983
|
}
|
|
1937
|
-
async getImage(
|
|
1938
|
-
return Promise.resolve(
|
|
1984
|
+
async getImage(imageId) {
|
|
1985
|
+
return Promise.resolve(imageId);
|
|
1939
1986
|
}
|
|
1940
|
-
async saveImage(
|
|
1941
|
-
return new Promise((
|
|
1942
|
-
if (!
|
|
1943
|
-
|
|
1987
|
+
async saveImage(imageFile) {
|
|
1988
|
+
return new Promise((resolve, reject) => {
|
|
1989
|
+
if (!DRAWING_IMAGE_ALLOW_IMAGE_LIST.includes(imageFile.type)) {
|
|
1990
|
+
reject(new Error(ImageUploadStatusType.ERROR_IMAGE_TYPE)), this._decreaseWaiting();
|
|
1944
1991
|
return;
|
|
1945
1992
|
}
|
|
1946
|
-
if (
|
|
1947
|
-
|
|
1993
|
+
if (imageFile.size > DRAWING_IMAGE_ALLOW_SIZE) {
|
|
1994
|
+
reject(new Error(ImageUploadStatusType.ERROR_EXCEED_SIZE)), this._decreaseWaiting();
|
|
1948
1995
|
return;
|
|
1949
1996
|
}
|
|
1950
|
-
const
|
|
1951
|
-
|
|
1952
|
-
var
|
|
1953
|
-
const
|
|
1954
|
-
if (
|
|
1955
|
-
|
|
1997
|
+
const reader = new FileReader();
|
|
1998
|
+
reader.readAsDataURL(imageFile), reader.onload = (evt) => {
|
|
1999
|
+
var _a2;
|
|
2000
|
+
const replaceSrc = (_a2 = evt.target) == null ? void 0 : _a2.result;
|
|
2001
|
+
if (replaceSrc == null) {
|
|
2002
|
+
reject(new Error(ImageUploadStatusType.ERROR_IMAGE)), this._decreaseWaiting();
|
|
1956
2003
|
return;
|
|
1957
2004
|
}
|
|
1958
|
-
const
|
|
1959
|
-
|
|
1960
|
-
imageId
|
|
1961
|
-
imageSourceType:
|
|
1962
|
-
source:
|
|
1963
|
-
base64Cache:
|
|
1964
|
-
status:
|
|
2005
|
+
const imageId = Tools.generateRandomId(6);
|
|
2006
|
+
resolve({
|
|
2007
|
+
imageId,
|
|
2008
|
+
imageSourceType: ImageSourceType.BASE64,
|
|
2009
|
+
source: replaceSrc,
|
|
2010
|
+
base64Cache: replaceSrc,
|
|
2011
|
+
status: ImageUploadStatusType.SUCCUSS
|
|
1965
2012
|
}), this._decreaseWaiting();
|
|
1966
2013
|
};
|
|
1967
2014
|
});
|
|
@@ -1969,60 +2016,62 @@ class dn {
|
|
|
1969
2016
|
_decreaseWaiting() {
|
|
1970
2017
|
this._waitCount -= 1, this._change$.next(this._waitCount);
|
|
1971
2018
|
}
|
|
1972
|
-
}
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
2019
|
+
};
|
|
2020
|
+
__name(_ImageIoService, "ImageIoService");
|
|
2021
|
+
let ImageIoService = _ImageIoService;
|
|
2022
|
+
var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
2023
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
2024
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
2025
|
+
return kind && result && __defProp2(target, key, result), result;
|
|
2026
|
+
}, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam");
|
|
2027
|
+
const PLUGIN_NAME = "UNIVER_DRAWING_PLUGIN";
|
|
2028
|
+
var _a;
|
|
2029
|
+
let UniverDrawingPlugin = (_a = class extends Plugin {
|
|
2030
|
+
constructor(_config = defaultPluginConfig, _injector, _configService, _commandService) {
|
|
2031
|
+
super(), this._config = _config, this._injector = _injector, this._configService = _configService, this._commandService = _commandService;
|
|
2032
|
+
const { ...rest } = merge(
|
|
1984
2033
|
{},
|
|
1985
|
-
|
|
2034
|
+
defaultPluginConfig,
|
|
1986
2035
|
this._config
|
|
1987
2036
|
);
|
|
1988
|
-
this._configService.setConfig(
|
|
2037
|
+
this._configService.setConfig(DRAWING_PLUGIN_CONFIG_KEY, rest);
|
|
1989
2038
|
}
|
|
1990
2039
|
onStarting() {
|
|
1991
2040
|
this._initCommands(), this._initDependencies();
|
|
1992
2041
|
}
|
|
1993
2042
|
_initDependencies() {
|
|
1994
|
-
var
|
|
1995
|
-
|
|
1996
|
-
[
|
|
1997
|
-
[
|
|
1998
|
-
], (
|
|
2043
|
+
var _a2;
|
|
2044
|
+
mergeOverrideWithDependencies([
|
|
2045
|
+
[IImageIoService, { useClass: ImageIoService }],
|
|
2046
|
+
[IDrawingManagerService, { useClass: DrawingManagerService }]
|
|
2047
|
+
], (_a2 = this._config) == null ? void 0 : _a2.override).forEach((d) => this._injector.add(d));
|
|
1999
2048
|
}
|
|
2000
2049
|
_initCommands() {
|
|
2001
2050
|
[
|
|
2002
|
-
|
|
2003
|
-
].forEach((
|
|
2004
|
-
}
|
|
2005
|
-
},
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
],
|
|
2051
|
+
SetDrawingSelectedOperation
|
|
2052
|
+
].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
|
|
2053
|
+
}
|
|
2054
|
+
}, __name(_a, "UniverDrawingPlugin"), __publicField(_a, "pluginName", PLUGIN_NAME), _a);
|
|
2055
|
+
UniverDrawingPlugin = __decorateClass([
|
|
2056
|
+
__decorateParam(1, Inject(Injector)),
|
|
2057
|
+
__decorateParam(2, IConfigService),
|
|
2058
|
+
__decorateParam(3, ICommandService)
|
|
2059
|
+
], UniverDrawingPlugin);
|
|
2011
2060
|
export {
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2061
|
+
DRAWING_IMAGE_ALLOW_IMAGE_LIST,
|
|
2062
|
+
DRAWING_IMAGE_ALLOW_SIZE,
|
|
2063
|
+
DRAWING_IMAGE_COUNT_LIMIT,
|
|
2064
|
+
DRAWING_IMAGE_HEIGHT_LIMIT,
|
|
2065
|
+
DRAWING_IMAGE_WIDTH_LIMIT,
|
|
2066
|
+
DrawingManagerService,
|
|
2067
|
+
IDrawingManagerService,
|
|
2068
|
+
IImageIoService2 as IImageIoService,
|
|
2069
|
+
ImageIoService,
|
|
2070
|
+
ImageSourceType2 as ImageSourceType,
|
|
2071
|
+
ImageUploadStatusType2 as ImageUploadStatusType,
|
|
2072
|
+
SetDrawingSelectedOperation,
|
|
2073
|
+
UnitDrawingService,
|
|
2074
|
+
UniverDrawingPlugin,
|
|
2075
|
+
getDrawingShapeKeyByDrawingSearch,
|
|
2076
|
+
getImageSize
|
|
2028
2077
|
};
|