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