microboard-temp 0.13.43 → 0.13.45
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/dist/cjs/browser.js +421 -315
- package/dist/cjs/index.js +421 -315
- package/dist/cjs/node.js +421 -315
- package/dist/esm/browser.js +424 -318
- package/dist/esm/index.js +424 -318
- package/dist/esm/node.js +424 -318
- package/dist/types/Events/Log/EventsLog.d.ts +6 -1
- package/dist/types/Events/Log/createEventsList.d.ts +1 -0
- package/dist/types/Events/Log/getUnpublishedEventFromList.d.ts +4 -1
- package/dist/types/Items/RichText/CanvasText/index.d.ts +2 -0
- package/dist/types/Items/RichText/EditorContainer.d.ts +3 -2
- package/dist/types/Items/RichText/editorHelpers/selectionOps/setSelectionFontColor.d.ts +2 -1
- package/package.json +1 -1
package/dist/cjs/node.js
CHANGED
|
@@ -4133,277 +4133,6 @@ var init_Color = __esm(() => {
|
|
|
4133
4133
|
init_resolveColor();
|
|
4134
4134
|
});
|
|
4135
4135
|
|
|
4136
|
-
// src/Events/SyncLog.ts
|
|
4137
|
-
function createSyncLog() {
|
|
4138
|
-
const log = [];
|
|
4139
|
-
const subject = new Subject;
|
|
4140
|
-
log.push = function(...msgs) {
|
|
4141
|
-
let newLength = log.length;
|
|
4142
|
-
for (const msg of msgs) {
|
|
4143
|
-
const lastItem = log[log.length - 1];
|
|
4144
|
-
if (lastItem && lastItem.msg === msg.msg) {
|
|
4145
|
-
lastItem.records = lastItem.records.concat(msg.records);
|
|
4146
|
-
} else {
|
|
4147
|
-
newLength = Array.prototype.push.call(log, msg);
|
|
4148
|
-
}
|
|
4149
|
-
}
|
|
4150
|
-
subject.publish(log);
|
|
4151
|
-
return newLength;
|
|
4152
|
-
};
|
|
4153
|
-
return {
|
|
4154
|
-
log,
|
|
4155
|
-
subject
|
|
4156
|
-
};
|
|
4157
|
-
}
|
|
4158
|
-
var init_SyncLog = () => {};
|
|
4159
|
-
|
|
4160
|
-
// src/Events/Log/createEventsList.ts
|
|
4161
|
-
function createEventsList(commandFactory) {
|
|
4162
|
-
const confirmedRecords = [];
|
|
4163
|
-
const recordsToSend = [];
|
|
4164
|
-
const newRecords = [];
|
|
4165
|
-
const justConfirmed = [];
|
|
4166
|
-
const { log: syncLog, subject: syncLogSubject } = createSyncLog();
|
|
4167
|
-
let snapshotLastIndex = 0;
|
|
4168
|
-
function revert(records) {
|
|
4169
|
-
for (let i = records.length - 1;i >= 0; i--) {
|
|
4170
|
-
records[i].command.revert();
|
|
4171
|
-
}
|
|
4172
|
-
}
|
|
4173
|
-
function getOpItems(op) {
|
|
4174
|
-
if ("item" in op) {
|
|
4175
|
-
const item = op.item;
|
|
4176
|
-
if (Array.isArray(item))
|
|
4177
|
-
return item;
|
|
4178
|
-
if (typeof item === "string")
|
|
4179
|
-
return [item];
|
|
4180
|
-
if (item && typeof item === "object")
|
|
4181
|
-
return Object.keys(item);
|
|
4182
|
-
}
|
|
4183
|
-
if ("itemsMap" in op && op.itemsMap)
|
|
4184
|
-
return Object.keys(op.itemsMap);
|
|
4185
|
-
if ("items" in op) {
|
|
4186
|
-
const items = op.items;
|
|
4187
|
-
if (Array.isArray(items)) {
|
|
4188
|
-
return items.map((i) => typeof i === "string" ? i : i.id).filter(Boolean);
|
|
4189
|
-
}
|
|
4190
|
-
if (items && typeof items === "object" && items !== null)
|
|
4191
|
-
return Object.keys(items);
|
|
4192
|
-
}
|
|
4193
|
-
if ("itemsOps" in op) {
|
|
4194
|
-
const itemsOps = op.itemsOps;
|
|
4195
|
-
return itemsOps.map((io) => io.item);
|
|
4196
|
-
}
|
|
4197
|
-
return [];
|
|
4198
|
-
}
|
|
4199
|
-
return {
|
|
4200
|
-
commandFactory,
|
|
4201
|
-
addConfirmedRecords(records) {
|
|
4202
|
-
confirmedRecords.push(...records);
|
|
4203
|
-
syncLog.push({ msg: "confirmed", records });
|
|
4204
|
-
},
|
|
4205
|
-
addNewRecords(records) {
|
|
4206
|
-
newRecords.push(...records);
|
|
4207
|
-
syncLog.push({ msg: "addedNew", records });
|
|
4208
|
-
},
|
|
4209
|
-
confirmSentRecords(events) {
|
|
4210
|
-
for (const event of events) {
|
|
4211
|
-
const index = recordsToSend.findIndex((r) => r.event.body.eventId === event.body.eventId);
|
|
4212
|
-
if (index !== -1) {
|
|
4213
|
-
const [record] = recordsToSend.splice(index, 1);
|
|
4214
|
-
confirmedRecords.push(record);
|
|
4215
|
-
syncLog.push({ msg: "confirmed", records: [record] });
|
|
4216
|
-
}
|
|
4217
|
-
}
|
|
4218
|
-
},
|
|
4219
|
-
getConfirmedRecords() {
|
|
4220
|
-
return confirmedRecords;
|
|
4221
|
-
},
|
|
4222
|
-
getRecordsToSend() {
|
|
4223
|
-
return recordsToSend;
|
|
4224
|
-
},
|
|
4225
|
-
getNewRecords() {
|
|
4226
|
-
return newRecords;
|
|
4227
|
-
},
|
|
4228
|
-
getAllRecords() {
|
|
4229
|
-
return [...confirmedRecords, ...recordsToSend, ...newRecords];
|
|
4230
|
-
},
|
|
4231
|
-
prepareRecordsToSend() {
|
|
4232
|
-
const records = [...newRecords];
|
|
4233
|
-
recordsToSend.push(...records);
|
|
4234
|
-
newRecords.length = 0;
|
|
4235
|
-
syncLog.push({ msg: "toSend", records });
|
|
4236
|
-
return records;
|
|
4237
|
-
},
|
|
4238
|
-
forwardIterable() {
|
|
4239
|
-
return function* () {
|
|
4240
|
-
yield* confirmedRecords;
|
|
4241
|
-
yield* recordsToSend;
|
|
4242
|
-
yield* newRecords;
|
|
4243
|
-
}();
|
|
4244
|
-
},
|
|
4245
|
-
backwardIterable() {
|
|
4246
|
-
return function* () {
|
|
4247
|
-
for (let i = newRecords.length - 1;i >= 0; i--)
|
|
4248
|
-
yield newRecords[i];
|
|
4249
|
-
for (let i = recordsToSend.length - 1;i >= 0; i--)
|
|
4250
|
-
yield recordsToSend[i];
|
|
4251
|
-
for (let i = confirmedRecords.length - 1;i >= 0; i--)
|
|
4252
|
-
yield confirmedRecords[i];
|
|
4253
|
-
}();
|
|
4254
|
-
},
|
|
4255
|
-
revertUnconfirmed(predicate) {
|
|
4256
|
-
const toRevert = [...recordsToSend, ...newRecords].filter(predicate || (() => true));
|
|
4257
|
-
revert(toRevert);
|
|
4258
|
-
syncLog.push({ msg: "revertUnconfirmed", records: toRevert });
|
|
4259
|
-
},
|
|
4260
|
-
applyUnconfirmed(predicate) {
|
|
4261
|
-
const unconfirmed = [...recordsToSend, ...newRecords].filter(predicate || (() => true));
|
|
4262
|
-
for (const record of unconfirmed) {
|
|
4263
|
-
record.command.apply();
|
|
4264
|
-
}
|
|
4265
|
-
syncLog.push({ msg: "applyUnconfirmed", records: unconfirmed });
|
|
4266
|
-
},
|
|
4267
|
-
justConfirmed,
|
|
4268
|
-
getSyncLog() {
|
|
4269
|
-
return syncLog;
|
|
4270
|
-
},
|
|
4271
|
-
syncLogSubject,
|
|
4272
|
-
clear() {
|
|
4273
|
-
confirmedRecords.length = 0;
|
|
4274
|
-
recordsToSend.length = 0;
|
|
4275
|
-
newRecords.length = 0;
|
|
4276
|
-
syncLog.length = 0;
|
|
4277
|
-
syncLogSubject.publish(syncLog);
|
|
4278
|
-
},
|
|
4279
|
-
clearConfirmedRecords() {
|
|
4280
|
-
confirmedRecords.length = 0;
|
|
4281
|
-
syncLog.length = 0;
|
|
4282
|
-
syncLogSubject.publish(syncLog);
|
|
4283
|
-
},
|
|
4284
|
-
removeUnconfirmedEventsByItems(itemIds) {
|
|
4285
|
-
const itemIdSet = new Set(itemIds);
|
|
4286
|
-
const filter = (record) => {
|
|
4287
|
-
const opItems = getOpItems(record.event.body.operation);
|
|
4288
|
-
return !opItems.some((id) => itemIdSet.has(id));
|
|
4289
|
-
};
|
|
4290
|
-
const filteredNewRecords = newRecords.filter(filter);
|
|
4291
|
-
newRecords.length = 0;
|
|
4292
|
-
newRecords.push(...filteredNewRecords);
|
|
4293
|
-
const filteredRecordsToSend = recordsToSend.filter(filter);
|
|
4294
|
-
recordsToSend.length = 0;
|
|
4295
|
-
recordsToSend.push(...filteredRecordsToSend);
|
|
4296
|
-
syncLog.length = 0;
|
|
4297
|
-
syncLog.push({ msg: "confirmed", records: confirmedRecords });
|
|
4298
|
-
syncLog.push({ msg: "toSend", records: recordsToSend });
|
|
4299
|
-
syncLog.push({ msg: "addedNew", records: newRecords });
|
|
4300
|
-
syncLogSubject.publish(syncLog);
|
|
4301
|
-
},
|
|
4302
|
-
isAllEventsConfirmed() {
|
|
4303
|
-
return recordsToSend.length === 0 && newRecords.length === 0;
|
|
4304
|
-
},
|
|
4305
|
-
setSnapshotLastIndex(index) {
|
|
4306
|
-
snapshotLastIndex = index;
|
|
4307
|
-
},
|
|
4308
|
-
getSnapshotLastIndex() {
|
|
4309
|
-
return snapshotLastIndex;
|
|
4310
|
-
}
|
|
4311
|
-
};
|
|
4312
|
-
}
|
|
4313
|
-
var init_createEventsList = __esm(() => {
|
|
4314
|
-
init_SyncLog();
|
|
4315
|
-
});
|
|
4316
|
-
|
|
4317
|
-
// src/Events/Log/getRecordByIdFromList.ts
|
|
4318
|
-
function getRecordByIdFromList(id, list) {
|
|
4319
|
-
for (const record of list.forwardIterable()) {
|
|
4320
|
-
if (record.event.body.eventId === id) {
|
|
4321
|
-
return record;
|
|
4322
|
-
}
|
|
4323
|
-
}
|
|
4324
|
-
return;
|
|
4325
|
-
}
|
|
4326
|
-
|
|
4327
|
-
// src/Events/Log/shouldSkipEvent.ts
|
|
4328
|
-
function shouldSkipEvent(record, userId) {
|
|
4329
|
-
const { operation } = record.event.body;
|
|
4330
|
-
return record.event.body.userId !== userId || operation.method === "updateVideoData" || operation.class === "Audio" && operation.method === "setUrl";
|
|
4331
|
-
}
|
|
4332
|
-
|
|
4333
|
-
// src/Events/Log/getRedoRecordFromList.ts
|
|
4334
|
-
function getRedoRecordFromList(userId, list) {
|
|
4335
|
-
let counter = 0;
|
|
4336
|
-
for (const record of list.backwardIterable()) {
|
|
4337
|
-
if (shouldSkipEvent(record, userId)) {
|
|
4338
|
-
continue;
|
|
4339
|
-
}
|
|
4340
|
-
if (record.event.body.operation.method !== "undo" && record.event.body.operation.method !== "redo") {
|
|
4341
|
-
return null;
|
|
4342
|
-
}
|
|
4343
|
-
const { method } = record.event.body.operation;
|
|
4344
|
-
if (method === "redo") {
|
|
4345
|
-
counter++;
|
|
4346
|
-
} else if (method === "undo") {
|
|
4347
|
-
if (counter > 0) {
|
|
4348
|
-
counter--;
|
|
4349
|
-
} else if (counter === 0) {
|
|
4350
|
-
return record;
|
|
4351
|
-
}
|
|
4352
|
-
}
|
|
4353
|
-
}
|
|
4354
|
-
return null;
|
|
4355
|
-
}
|
|
4356
|
-
var init_getRedoRecordFromList = () => {};
|
|
4357
|
-
|
|
4358
|
-
// src/Events/Log/getUndoRecordFromList.ts
|
|
4359
|
-
function getUndoRecordFromList(userId, list) {
|
|
4360
|
-
let counter = 0;
|
|
4361
|
-
const isAllEventsConfirmed = list.isAllEventsConfirmed();
|
|
4362
|
-
if (!isAllEventsConfirmed) {
|
|
4363
|
-
return null;
|
|
4364
|
-
}
|
|
4365
|
-
for (const record of list.getConfirmedRecords().slice().reverse()) {
|
|
4366
|
-
if (shouldSkipEvent(record, userId)) {
|
|
4367
|
-
continue;
|
|
4368
|
-
}
|
|
4369
|
-
if (record.event.body.operation.method === "undo") {
|
|
4370
|
-
counter++;
|
|
4371
|
-
} else if (counter === 0) {
|
|
4372
|
-
return record;
|
|
4373
|
-
} else {
|
|
4374
|
-
counter--;
|
|
4375
|
-
}
|
|
4376
|
-
}
|
|
4377
|
-
return null;
|
|
4378
|
-
}
|
|
4379
|
-
var init_getUndoRecordFromList = () => {};
|
|
4380
|
-
|
|
4381
|
-
// src/Events/Log/getUnpublishedEventFromList.ts
|
|
4382
|
-
function getUnpublishedEventFromList(list) {
|
|
4383
|
-
const recordsToSend = list.prepareRecordsToSend();
|
|
4384
|
-
if (recordsToSend.length === 0) {
|
|
4385
|
-
return null;
|
|
4386
|
-
}
|
|
4387
|
-
const operations = getOperationsFromEventRecords(recordsToSend);
|
|
4388
|
-
return combineOperationsIntoPack(recordsToSend[0].event, operations);
|
|
4389
|
-
}
|
|
4390
|
-
function getOperationsFromEventRecords(records) {
|
|
4391
|
-
return records.map((record) => ({
|
|
4392
|
-
...record.event.body.operation,
|
|
4393
|
-
actualId: record.event.body.eventId
|
|
4394
|
-
}));
|
|
4395
|
-
}
|
|
4396
|
-
function combineOperationsIntoPack(baseEvent, operations) {
|
|
4397
|
-
const { operation, ...bodyWithoutOperation } = baseEvent.body;
|
|
4398
|
-
return {
|
|
4399
|
-
...baseEvent,
|
|
4400
|
-
body: {
|
|
4401
|
-
...bodyWithoutOperation,
|
|
4402
|
-
operations
|
|
4403
|
-
}
|
|
4404
|
-
};
|
|
4405
|
-
}
|
|
4406
|
-
|
|
4407
4136
|
// src/Events/EventsOperations.ts
|
|
4408
4137
|
function isTransformation(op) {
|
|
4409
4138
|
return op.class === "Transformation";
|
|
@@ -4732,41 +4461,69 @@ var init_Merge = __esm(() => {
|
|
|
4732
4461
|
import_slate = require("slate");
|
|
4733
4462
|
});
|
|
4734
4463
|
|
|
4735
|
-
// src/Events/
|
|
4736
|
-
function
|
|
4737
|
-
if (
|
|
4738
|
-
return
|
|
4464
|
+
// src/Events/mergeRecords.ts
|
|
4465
|
+
function mergeRecords(records) {
|
|
4466
|
+
if (records.length < 2) {
|
|
4467
|
+
return records;
|
|
4739
4468
|
}
|
|
4740
|
-
const
|
|
4469
|
+
const mergedRecords = [];
|
|
4741
4470
|
let previous = null;
|
|
4742
|
-
for (const
|
|
4471
|
+
for (const record of records) {
|
|
4743
4472
|
if (!previous) {
|
|
4744
|
-
previous =
|
|
4473
|
+
previous = record;
|
|
4745
4474
|
continue;
|
|
4746
4475
|
}
|
|
4747
|
-
const
|
|
4748
|
-
if (!
|
|
4749
|
-
|
|
4750
|
-
previous =
|
|
4476
|
+
const mergedEventOperation = mergeOperations(previous.event.body.operation, record.event.body.operation);
|
|
4477
|
+
if (!mergedEventOperation) {
|
|
4478
|
+
mergedRecords.push(previous);
|
|
4479
|
+
previous = record;
|
|
4751
4480
|
} else {
|
|
4481
|
+
const mergedCommand = record.command.merge ? previous.command.merge(mergedEventOperation) : previous.command;
|
|
4752
4482
|
previous = {
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4483
|
+
event: {
|
|
4484
|
+
...record.event,
|
|
4485
|
+
body: {
|
|
4486
|
+
...record.event.body,
|
|
4487
|
+
operation: mergedEventOperation
|
|
4488
|
+
}
|
|
4489
|
+
},
|
|
4490
|
+
command: mergedCommand
|
|
4758
4491
|
};
|
|
4759
4492
|
}
|
|
4760
4493
|
}
|
|
4761
4494
|
if (previous) {
|
|
4762
|
-
|
|
4495
|
+
mergedRecords.push(previous);
|
|
4763
4496
|
}
|
|
4764
|
-
return
|
|
4497
|
+
return mergedRecords;
|
|
4765
4498
|
}
|
|
4766
|
-
var
|
|
4499
|
+
var init_mergeRecords = __esm(() => {
|
|
4767
4500
|
init_Merge();
|
|
4768
4501
|
});
|
|
4769
4502
|
|
|
4503
|
+
// src/Events/SyncLog.ts
|
|
4504
|
+
function createSyncLog() {
|
|
4505
|
+
const log = [];
|
|
4506
|
+
const subject = new Subject;
|
|
4507
|
+
log.push = function(...msgs) {
|
|
4508
|
+
let newLength = log.length;
|
|
4509
|
+
for (const msg of msgs) {
|
|
4510
|
+
const lastItem = log[log.length - 1];
|
|
4511
|
+
if (lastItem && lastItem.msg === msg.msg) {
|
|
4512
|
+
lastItem.records = lastItem.records.concat(msg.records);
|
|
4513
|
+
} else {
|
|
4514
|
+
newLength = Array.prototype.push.call(log, msg);
|
|
4515
|
+
}
|
|
4516
|
+
}
|
|
4517
|
+
subject.publish(log);
|
|
4518
|
+
return newLength;
|
|
4519
|
+
};
|
|
4520
|
+
return {
|
|
4521
|
+
log,
|
|
4522
|
+
subject
|
|
4523
|
+
};
|
|
4524
|
+
}
|
|
4525
|
+
var init_SyncLog = () => {};
|
|
4526
|
+
|
|
4770
4527
|
// src/Events/Transform/removeText_removeText.ts
|
|
4771
4528
|
function removeText_removeText(confirmed, toTransform) {
|
|
4772
4529
|
const transformed = { ...toTransform };
|
|
@@ -5883,6 +5640,346 @@ var init_transformEvents = __esm(() => {
|
|
|
5883
5640
|
init_Transform2();
|
|
5884
5641
|
});
|
|
5885
5642
|
|
|
5643
|
+
// src/Events/Log/createEventsList.ts
|
|
5644
|
+
function createEventsList(commandFactory) {
|
|
5645
|
+
const confirmedRecords = [];
|
|
5646
|
+
const recordsToSend = [];
|
|
5647
|
+
const newRecords = [];
|
|
5648
|
+
const justConfirmed = [];
|
|
5649
|
+
const { log: syncLog, subject: syncLogSubject } = createSyncLog();
|
|
5650
|
+
let snapshotLastIndex = 0;
|
|
5651
|
+
function revert(records) {
|
|
5652
|
+
for (let i = records.length - 1;i >= 0; i--) {
|
|
5653
|
+
records[i].command.revert();
|
|
5654
|
+
}
|
|
5655
|
+
}
|
|
5656
|
+
function apply(records) {
|
|
5657
|
+
for (const record of records) {
|
|
5658
|
+
record.command = commandFactory(record.event.body.operation);
|
|
5659
|
+
record.command.apply();
|
|
5660
|
+
}
|
|
5661
|
+
}
|
|
5662
|
+
function mergeAndPushConfirmedRecords(records) {
|
|
5663
|
+
const lastConfirmedRecord = confirmedRecords.pop();
|
|
5664
|
+
const recordsToMerge = lastConfirmedRecord ? [lastConfirmedRecord, ...records] : records;
|
|
5665
|
+
const mergedRecords = mergeRecords(recordsToMerge);
|
|
5666
|
+
confirmedRecords.push(...mergedRecords);
|
|
5667
|
+
}
|
|
5668
|
+
return {
|
|
5669
|
+
commandFactory,
|
|
5670
|
+
addConfirmedRecords(records) {
|
|
5671
|
+
syncLog.push({ msg: "confirmed", records });
|
|
5672
|
+
mergeAndPushConfirmedRecords(records);
|
|
5673
|
+
},
|
|
5674
|
+
addNewRecords(records) {
|
|
5675
|
+
for (const record of records) {
|
|
5676
|
+
if (newRecords.length > 0) {
|
|
5677
|
+
const lastRecord = newRecords[newRecords.length - 1];
|
|
5678
|
+
const mergedOperation = mergeOperations(lastRecord.event.body.operation, record.event.body.operation);
|
|
5679
|
+
if (mergedOperation) {
|
|
5680
|
+
lastRecord.event = {
|
|
5681
|
+
...lastRecord.event,
|
|
5682
|
+
body: {
|
|
5683
|
+
...lastRecord.event.body,
|
|
5684
|
+
operation: mergedOperation
|
|
5685
|
+
}
|
|
5686
|
+
};
|
|
5687
|
+
lastRecord.command = commandFactory(mergedOperation);
|
|
5688
|
+
continue;
|
|
5689
|
+
}
|
|
5690
|
+
}
|
|
5691
|
+
newRecords.push(record);
|
|
5692
|
+
syncLog.push({ msg: "addedNew", records: [record] });
|
|
5693
|
+
}
|
|
5694
|
+
},
|
|
5695
|
+
confirmSentRecords(events) {
|
|
5696
|
+
const records = recordsToSend;
|
|
5697
|
+
if (records.length !== events.length) {
|
|
5698
|
+
console.error("Mismatch between records and events length");
|
|
5699
|
+
return;
|
|
5700
|
+
}
|
|
5701
|
+
for (let i = 0;i < records.length; i++) {
|
|
5702
|
+
records[i].event.order = events[i].order;
|
|
5703
|
+
}
|
|
5704
|
+
syncLog.push({ msg: "confirmed", records: [...records] });
|
|
5705
|
+
mergeAndPushConfirmedRecords(records);
|
|
5706
|
+
recordsToSend.splice(0, records.length);
|
|
5707
|
+
},
|
|
5708
|
+
confirmSentRecordIds(eventIds, order) {
|
|
5709
|
+
const confirmedRecordsById = [];
|
|
5710
|
+
for (const eventId of eventIds) {
|
|
5711
|
+
const index = recordsToSend.findIndex((record2) => record2.event.body.eventId === eventId);
|
|
5712
|
+
if (index === -1) {
|
|
5713
|
+
continue;
|
|
5714
|
+
}
|
|
5715
|
+
const [record] = recordsToSend.splice(index, 1);
|
|
5716
|
+
record.event.order = order;
|
|
5717
|
+
confirmedRecordsById.push(record);
|
|
5718
|
+
}
|
|
5719
|
+
if (confirmedRecordsById.length === 0) {
|
|
5720
|
+
return;
|
|
5721
|
+
}
|
|
5722
|
+
syncLog.push({ msg: "confirmed", records: confirmedRecordsById });
|
|
5723
|
+
mergeAndPushConfirmedRecords(confirmedRecordsById);
|
|
5724
|
+
},
|
|
5725
|
+
getConfirmedRecords() {
|
|
5726
|
+
return confirmedRecords;
|
|
5727
|
+
},
|
|
5728
|
+
getRecordsToSend() {
|
|
5729
|
+
return recordsToSend;
|
|
5730
|
+
},
|
|
5731
|
+
getNewRecords() {
|
|
5732
|
+
return newRecords;
|
|
5733
|
+
},
|
|
5734
|
+
getAllRecords() {
|
|
5735
|
+
return [...confirmedRecords, ...recordsToSend, ...newRecords];
|
|
5736
|
+
},
|
|
5737
|
+
prepareRecordsToSend() {
|
|
5738
|
+
if (recordsToSend.length === 0 && newRecords.length > 0) {
|
|
5739
|
+
const records = [...newRecords];
|
|
5740
|
+
recordsToSend.push(...records);
|
|
5741
|
+
newRecords.length = 0;
|
|
5742
|
+
syncLog.push({ msg: "toSend", records });
|
|
5743
|
+
}
|
|
5744
|
+
return recordsToSend;
|
|
5745
|
+
},
|
|
5746
|
+
forwardIterable() {
|
|
5747
|
+
return function* () {
|
|
5748
|
+
yield* confirmedRecords;
|
|
5749
|
+
yield* recordsToSend;
|
|
5750
|
+
yield* newRecords;
|
|
5751
|
+
}();
|
|
5752
|
+
},
|
|
5753
|
+
backwardIterable() {
|
|
5754
|
+
return function* () {
|
|
5755
|
+
for (let i = newRecords.length - 1;i >= 0; i--)
|
|
5756
|
+
yield newRecords[i];
|
|
5757
|
+
for (let i = recordsToSend.length - 1;i >= 0; i--)
|
|
5758
|
+
yield recordsToSend[i];
|
|
5759
|
+
for (let i = confirmedRecords.length - 1;i >= 0; i--)
|
|
5760
|
+
yield confirmedRecords[i];
|
|
5761
|
+
}();
|
|
5762
|
+
},
|
|
5763
|
+
revertUnconfirmed(predicate) {
|
|
5764
|
+
const toRevert = [...recordsToSend, ...newRecords].filter(predicate || (() => true));
|
|
5765
|
+
revert(toRevert);
|
|
5766
|
+
syncLog.push({ msg: "revertUnconfirmed", records: toRevert });
|
|
5767
|
+
},
|
|
5768
|
+
applyUnconfirmed(predicate) {
|
|
5769
|
+
const filter = predicate || (() => true);
|
|
5770
|
+
if (justConfirmed.length > 0) {
|
|
5771
|
+
const confirmedEvents = justConfirmed.map((record) => record.event);
|
|
5772
|
+
const transformedSend = transformEvents(confirmedEvents, recordsToSend.map((record) => record.event));
|
|
5773
|
+
const transformedNew = transformEvents(confirmedEvents, newRecords.map((record) => record.event));
|
|
5774
|
+
const updatedRecordsToSend = transformedSend.map((event) => ({
|
|
5775
|
+
event,
|
|
5776
|
+
command: commandFactory(event.body.operation)
|
|
5777
|
+
}));
|
|
5778
|
+
const updatedNewRecords = transformedNew.map((event) => ({
|
|
5779
|
+
event,
|
|
5780
|
+
command: commandFactory(event.body.operation)
|
|
5781
|
+
}));
|
|
5782
|
+
recordsToSend.length = 0;
|
|
5783
|
+
recordsToSend.push(...updatedRecordsToSend);
|
|
5784
|
+
newRecords.length = 0;
|
|
5785
|
+
newRecords.push(...updatedNewRecords);
|
|
5786
|
+
justConfirmed.length = 0;
|
|
5787
|
+
}
|
|
5788
|
+
const unconfirmed = [...recordsToSend, ...newRecords].filter(filter);
|
|
5789
|
+
apply(unconfirmed);
|
|
5790
|
+
syncLog.push({ msg: "applyUnconfirmed", records: unconfirmed });
|
|
5791
|
+
},
|
|
5792
|
+
justConfirmed,
|
|
5793
|
+
getSyncLog() {
|
|
5794
|
+
return syncLog;
|
|
5795
|
+
},
|
|
5796
|
+
syncLogSubject,
|
|
5797
|
+
clear() {
|
|
5798
|
+
confirmedRecords.length = 0;
|
|
5799
|
+
recordsToSend.length = 0;
|
|
5800
|
+
newRecords.length = 0;
|
|
5801
|
+
syncLog.length = 0;
|
|
5802
|
+
syncLogSubject.publish(syncLog);
|
|
5803
|
+
},
|
|
5804
|
+
clearConfirmedRecords() {
|
|
5805
|
+
confirmedRecords.length = 0;
|
|
5806
|
+
syncLog.length = 0;
|
|
5807
|
+
syncLogSubject.publish(syncLog);
|
|
5808
|
+
},
|
|
5809
|
+
removeUnconfirmedEventsByItems(itemIds) {
|
|
5810
|
+
function shouldRemoveEvent(operation, ids) {
|
|
5811
|
+
if (operation.method === "add" && operation.class === "Board") {
|
|
5812
|
+
if (Array.isArray(operation.item)) {
|
|
5813
|
+
return operation.item.some((id) => ids.includes(id));
|
|
5814
|
+
}
|
|
5815
|
+
return ids.includes(operation.item);
|
|
5816
|
+
}
|
|
5817
|
+
if (operation.method === "remove" && operation.class === "Board") {
|
|
5818
|
+
return operation.item.some((id) => ids.includes(id));
|
|
5819
|
+
}
|
|
5820
|
+
return false;
|
|
5821
|
+
}
|
|
5822
|
+
const nextRecordsToSend = recordsToSend.filter((record) => !shouldRemoveEvent(record.event.body.operation, itemIds));
|
|
5823
|
+
if (nextRecordsToSend.length !== recordsToSend.length) {
|
|
5824
|
+
recordsToSend.length = 0;
|
|
5825
|
+
recordsToSend.push(...nextRecordsToSend);
|
|
5826
|
+
}
|
|
5827
|
+
const nextNewRecords = newRecords.filter((record) => !shouldRemoveEvent(record.event.body.operation, itemIds));
|
|
5828
|
+
if (nextNewRecords.length !== newRecords.length) {
|
|
5829
|
+
newRecords.length = 0;
|
|
5830
|
+
newRecords.push(...nextNewRecords);
|
|
5831
|
+
}
|
|
5832
|
+
},
|
|
5833
|
+
isAllEventsConfirmed() {
|
|
5834
|
+
return recordsToSend.length === 0 && newRecords.length === 0;
|
|
5835
|
+
},
|
|
5836
|
+
setSnapshotLastIndex(index) {
|
|
5837
|
+
snapshotLastIndex = index;
|
|
5838
|
+
},
|
|
5839
|
+
getSnapshotLastIndex() {
|
|
5840
|
+
return snapshotLastIndex;
|
|
5841
|
+
}
|
|
5842
|
+
};
|
|
5843
|
+
}
|
|
5844
|
+
var init_createEventsList = __esm(() => {
|
|
5845
|
+
init_Merge();
|
|
5846
|
+
init_mergeRecords();
|
|
5847
|
+
init_SyncLog();
|
|
5848
|
+
init_transformEvents();
|
|
5849
|
+
});
|
|
5850
|
+
|
|
5851
|
+
// src/Events/Log/getRecordByIdFromList.ts
|
|
5852
|
+
function getRecordByIdFromList(id, list) {
|
|
5853
|
+
for (const record of list.forwardIterable()) {
|
|
5854
|
+
if (record.event.body.eventId === id) {
|
|
5855
|
+
return record;
|
|
5856
|
+
}
|
|
5857
|
+
}
|
|
5858
|
+
return;
|
|
5859
|
+
}
|
|
5860
|
+
|
|
5861
|
+
// src/Events/Log/shouldSkipEvent.ts
|
|
5862
|
+
function shouldSkipEvent(record, userId) {
|
|
5863
|
+
const { operation } = record.event.body;
|
|
5864
|
+
return record.event.body.userId !== userId || operation.method === "updateVideoData" || operation.class === "Audio" && operation.method === "setUrl";
|
|
5865
|
+
}
|
|
5866
|
+
|
|
5867
|
+
// src/Events/Log/getRedoRecordFromList.ts
|
|
5868
|
+
function getRedoRecordFromList(userId, list) {
|
|
5869
|
+
let counter = 0;
|
|
5870
|
+
for (const record of list.backwardIterable()) {
|
|
5871
|
+
if (shouldSkipEvent(record, userId)) {
|
|
5872
|
+
continue;
|
|
5873
|
+
}
|
|
5874
|
+
if (record.event.body.operation.method !== "undo" && record.event.body.operation.method !== "redo") {
|
|
5875
|
+
return null;
|
|
5876
|
+
}
|
|
5877
|
+
const { method } = record.event.body.operation;
|
|
5878
|
+
if (method === "redo") {
|
|
5879
|
+
counter++;
|
|
5880
|
+
} else if (method === "undo") {
|
|
5881
|
+
if (counter > 0) {
|
|
5882
|
+
counter--;
|
|
5883
|
+
} else if (counter === 0) {
|
|
5884
|
+
return record;
|
|
5885
|
+
}
|
|
5886
|
+
}
|
|
5887
|
+
}
|
|
5888
|
+
return null;
|
|
5889
|
+
}
|
|
5890
|
+
var init_getRedoRecordFromList = () => {};
|
|
5891
|
+
|
|
5892
|
+
// src/Events/Log/getUndoRecordFromList.ts
|
|
5893
|
+
function getUndoRecordFromList(userId, list) {
|
|
5894
|
+
let counter = 0;
|
|
5895
|
+
const isAllEventsConfirmed = list.isAllEventsConfirmed();
|
|
5896
|
+
if (!isAllEventsConfirmed) {
|
|
5897
|
+
return null;
|
|
5898
|
+
}
|
|
5899
|
+
for (const record of list.getConfirmedRecords().slice().reverse()) {
|
|
5900
|
+
if (shouldSkipEvent(record, userId)) {
|
|
5901
|
+
continue;
|
|
5902
|
+
}
|
|
5903
|
+
if (record.event.body.operation.method === "undo") {
|
|
5904
|
+
counter++;
|
|
5905
|
+
} else if (counter === 0) {
|
|
5906
|
+
return record;
|
|
5907
|
+
} else {
|
|
5908
|
+
counter--;
|
|
5909
|
+
}
|
|
5910
|
+
}
|
|
5911
|
+
return null;
|
|
5912
|
+
}
|
|
5913
|
+
var init_getUndoRecordFromList = () => {};
|
|
5914
|
+
|
|
5915
|
+
// src/Events/Log/getUnpublishedEventFromList.ts
|
|
5916
|
+
function getUnpublishedEventFromList(list) {
|
|
5917
|
+
const recordsToSend = list.prepareRecordsToSend();
|
|
5918
|
+
if (recordsToSend.length === 0) {
|
|
5919
|
+
return null;
|
|
5920
|
+
}
|
|
5921
|
+
const mergedRecords = mergeRecords(recordsToSend);
|
|
5922
|
+
const operations = getOperationsFromEventRecords(mergedRecords);
|
|
5923
|
+
return {
|
|
5924
|
+
event: combineOperationsIntoPack(recordsToSend[0].event, operations),
|
|
5925
|
+
sentEventIds: recordsToSend.map((record) => record.event.body.eventId)
|
|
5926
|
+
};
|
|
5927
|
+
}
|
|
5928
|
+
function getOperationsFromEventRecords(records) {
|
|
5929
|
+
return records.map((record) => ({
|
|
5930
|
+
...record.event.body.operation,
|
|
5931
|
+
actualId: record.event.body.eventId
|
|
5932
|
+
}));
|
|
5933
|
+
}
|
|
5934
|
+
function combineOperationsIntoPack(baseEvent, operations) {
|
|
5935
|
+
const { operation, ...bodyWithoutOperation } = baseEvent.body;
|
|
5936
|
+
return {
|
|
5937
|
+
...baseEvent,
|
|
5938
|
+
body: {
|
|
5939
|
+
...bodyWithoutOperation,
|
|
5940
|
+
operations
|
|
5941
|
+
}
|
|
5942
|
+
};
|
|
5943
|
+
}
|
|
5944
|
+
var init_getUnpublishedEventFromList = __esm(() => {
|
|
5945
|
+
init_mergeRecords();
|
|
5946
|
+
});
|
|
5947
|
+
|
|
5948
|
+
// src/Events/mergeEvents.ts
|
|
5949
|
+
function mergeEvents(events) {
|
|
5950
|
+
if (events.length < 2) {
|
|
5951
|
+
return events;
|
|
5952
|
+
}
|
|
5953
|
+
const mergedEvents = [];
|
|
5954
|
+
let previous = null;
|
|
5955
|
+
for (const event of events) {
|
|
5956
|
+
if (!previous) {
|
|
5957
|
+
previous = event;
|
|
5958
|
+
continue;
|
|
5959
|
+
}
|
|
5960
|
+
const mergedOperation = mergeOperations(previous.body.operation, event.body.operation);
|
|
5961
|
+
if (!mergedOperation) {
|
|
5962
|
+
mergedEvents.push(previous);
|
|
5963
|
+
previous = event;
|
|
5964
|
+
} else {
|
|
5965
|
+
previous = {
|
|
5966
|
+
...event,
|
|
5967
|
+
body: {
|
|
5968
|
+
...event.body,
|
|
5969
|
+
operation: mergedOperation
|
|
5970
|
+
}
|
|
5971
|
+
};
|
|
5972
|
+
}
|
|
5973
|
+
}
|
|
5974
|
+
if (previous) {
|
|
5975
|
+
mergedEvents.push(previous);
|
|
5976
|
+
}
|
|
5977
|
+
return mergedEvents;
|
|
5978
|
+
}
|
|
5979
|
+
var init_mergeEvents = __esm(() => {
|
|
5980
|
+
init_Merge();
|
|
5981
|
+
});
|
|
5982
|
+
|
|
5886
5983
|
// src/Events/Log/expandEvents.ts
|
|
5887
5984
|
function expandEvents(events) {
|
|
5888
5985
|
return events.flatMap((event) => {
|
|
@@ -6096,6 +6193,9 @@ class EventsLog {
|
|
|
6096
6193
|
const events = expandEvents([event]);
|
|
6097
6194
|
this.list.confirmSentRecords(events);
|
|
6098
6195
|
}
|
|
6196
|
+
confirmSentLocalEventIds(eventIds, order) {
|
|
6197
|
+
this.list.confirmSentRecordIds(eventIds, order);
|
|
6198
|
+
}
|
|
6099
6199
|
getUnorderedRecords() {
|
|
6100
6200
|
return this.list.getRecordsToSend().concat(this.list.getNewRecords());
|
|
6101
6201
|
}
|
|
@@ -6138,6 +6238,7 @@ var init_EventsLog = __esm(() => {
|
|
|
6138
6238
|
init_createEventsList();
|
|
6139
6239
|
init_getRedoRecordFromList();
|
|
6140
6240
|
init_getUndoRecordFromList();
|
|
6241
|
+
init_getUnpublishedEventFromList();
|
|
6141
6242
|
init_insertEventsFromOtherConnectionsIntoList();
|
|
6142
6243
|
});
|
|
6143
6244
|
|
|
@@ -12085,6 +12186,9 @@ class SpatialIndex {
|
|
|
12085
12186
|
this.Mbr = new Mbr;
|
|
12086
12187
|
}
|
|
12087
12188
|
insert(item) {
|
|
12189
|
+
if (this.itemsArray.includes(item) || this.getById(item.getId())) {
|
|
12190
|
+
return;
|
|
12191
|
+
}
|
|
12088
12192
|
this.itemsArray.push(item);
|
|
12089
12193
|
this.itemsIndex.insert(item);
|
|
12090
12194
|
if (conf.isNode()) {
|
|
@@ -12682,6 +12786,9 @@ class SimpleSpatialIndex {
|
|
|
12682
12786
|
this.Mbr = new Mbr;
|
|
12683
12787
|
}
|
|
12684
12788
|
insert(item) {
|
|
12789
|
+
if (this.itemsArray.includes(item) || this.getById(item.getId())) {
|
|
12790
|
+
return;
|
|
12791
|
+
}
|
|
12685
12792
|
this.itemsArray.push(item);
|
|
12686
12793
|
if (this.Mbr.getWidth() === 0 && this.Mbr.getHeight() === 0) {
|
|
12687
12794
|
this.Mbr = item.getMbr().copy();
|
|
@@ -13108,7 +13215,10 @@ var init_BaseItem = __esm(() => {
|
|
|
13108
13215
|
if (this.parent !== childId && this.getId() !== childId && !this.hasAncestor(childId)) {
|
|
13109
13216
|
if (!this.index?.getById(childId) && foundItem) {
|
|
13110
13217
|
const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
|
|
13111
|
-
|
|
13218
|
+
const currentParentId = foundItem.parent;
|
|
13219
|
+
const currentParent = currentParentId !== "Board" ? this.board.items.getById(currentParentId) : undefined;
|
|
13220
|
+
const sourceIndex = currentParent?.index || this.board.items.index;
|
|
13221
|
+
sourceIndex.remove(foundItem, true);
|
|
13112
13222
|
foundItem.parent = this.getId();
|
|
13113
13223
|
foundItem.onParentChanged(this.getId());
|
|
13114
13224
|
foundItem.transformation.setLocalMatrix(localMatrix);
|
|
@@ -16808,15 +16918,15 @@ var import_slate40, setLink = (editor, link, selection) => {
|
|
|
16808
16918
|
}
|
|
16809
16919
|
const format = link ? "rgba(71, 120, 245, 1)" : "rgb(20, 21, 26)";
|
|
16810
16920
|
import_slate40.Transforms.setNodes(editor, { fontColor: format }, {
|
|
16811
|
-
match: (n) =>
|
|
16921
|
+
match: (n) => import_slate40.Text.isText(n),
|
|
16812
16922
|
split: true
|
|
16813
16923
|
});
|
|
16814
|
-
for (const [
|
|
16815
|
-
match: (n) =>
|
|
16924
|
+
for (const [, path2] of import_slate40.Editor.nodes(editor, {
|
|
16925
|
+
match: (n) => import_slate40.Text.isText(n)
|
|
16816
16926
|
})) {
|
|
16817
16927
|
const nodeRange = import_slate40.Editor.range(editor, path2);
|
|
16818
16928
|
import_slate40.Transforms.select(editor, nodeRange);
|
|
16819
|
-
import_slate40.Transforms.setNodes(editor, { link }, { split: false, match: (n) =>
|
|
16929
|
+
import_slate40.Transforms.setNodes(editor, { link }, { split: false, match: (n) => import_slate40.Text.isText(n) });
|
|
16820
16930
|
}
|
|
16821
16931
|
};
|
|
16822
16932
|
var init_setLink = __esm(() => {
|
|
@@ -57862,25 +57972,16 @@ function handleBoardEventMessage(message, board) {
|
|
|
57862
57972
|
if (event.order <= log.getLastIndex()) {
|
|
57863
57973
|
return;
|
|
57864
57974
|
}
|
|
57865
|
-
const
|
|
57866
|
-
const
|
|
57867
|
-
const isEventFromCurrentUser =
|
|
57975
|
+
const eventConnectionId = Number(event.body.eventId.split(":")[0]);
|
|
57976
|
+
const currentConnectionId = board.events.connection?.connectionId;
|
|
57977
|
+
const isEventFromCurrentUser = currentConnectionId !== undefined && eventConnectionId === currentConnectionId;
|
|
57868
57978
|
if (isEventFromCurrentUser) {
|
|
57869
57979
|
return;
|
|
57870
57980
|
}
|
|
57871
57981
|
if ("operations" in event.body) {
|
|
57872
|
-
log.insertEventsFromOtherConnections(
|
|
57873
|
-
...event,
|
|
57874
|
-
body: {
|
|
57875
|
-
...event.body,
|
|
57876
|
-
userId: Number(message.userId)
|
|
57877
|
-
}
|
|
57878
|
-
});
|
|
57982
|
+
log.insertEventsFromOtherConnections(event);
|
|
57879
57983
|
} else {
|
|
57880
|
-
log.insertEventsFromOtherConnections(
|
|
57881
|
-
...event,
|
|
57882
|
-
userId: Number(message.userId)
|
|
57883
|
-
});
|
|
57984
|
+
log.insertEventsFromOtherConnections(event);
|
|
57884
57985
|
}
|
|
57885
57986
|
const last = log.getLastConfirmed();
|
|
57886
57987
|
if (last) {
|
|
@@ -57932,11 +58033,11 @@ function tryPublishEvent(board) {
|
|
|
57932
58033
|
if (log.pendingEvent) {
|
|
57933
58034
|
return;
|
|
57934
58035
|
}
|
|
57935
|
-
const
|
|
57936
|
-
if (!
|
|
58036
|
+
const unpublishedBatch = log.getUnpublishedEvent();
|
|
58037
|
+
if (!unpublishedBatch) {
|
|
57937
58038
|
return;
|
|
57938
58039
|
}
|
|
57939
|
-
sendBoardEvent(board,
|
|
58040
|
+
sendBoardEvent(board, unpublishedBatch, log.currentSequenceNumber);
|
|
57940
58041
|
}
|
|
57941
58042
|
function tryResendEvent(board) {
|
|
57942
58043
|
const { log } = board.events;
|
|
@@ -57953,7 +58054,10 @@ function tryResendEvent(board) {
|
|
|
57953
58054
|
board.presence.clear();
|
|
57954
58055
|
conf.connection?.notifyAboutLostConnection();
|
|
57955
58056
|
}
|
|
57956
|
-
sendBoardEvent(board,
|
|
58057
|
+
sendBoardEvent(board, {
|
|
58058
|
+
event: log.pendingEvent.event,
|
|
58059
|
+
sentEventIds: log.pendingEvent.sentEventIds
|
|
58060
|
+
}, log.currentSequenceNumber);
|
|
57957
58061
|
}
|
|
57958
58062
|
function handleSnapshotApplication(snapshot, board) {
|
|
57959
58063
|
const { log } = board.events;
|
|
@@ -57978,8 +58082,9 @@ function handleBoardEventListApplication(events, board) {
|
|
|
57978
58082
|
board.events.subject.publish(newEvents[0]);
|
|
57979
58083
|
}
|
|
57980
58084
|
}
|
|
57981
|
-
function sendBoardEvent(board,
|
|
58085
|
+
function sendBoardEvent(board, batch, sequenceNumber) {
|
|
57982
58086
|
const { log } = board.events;
|
|
58087
|
+
const { event, sentEventIds } = batch;
|
|
57983
58088
|
const toSend = {
|
|
57984
58089
|
...event,
|
|
57985
58090
|
body: {
|
|
@@ -57997,6 +58102,7 @@ function sendBoardEvent(board, event, sequenceNumber) {
|
|
|
57997
58102
|
const date = Date.now();
|
|
57998
58103
|
log.pendingEvent = {
|
|
57999
58104
|
event: toSend,
|
|
58105
|
+
sentEventIds,
|
|
58000
58106
|
sequenceNumber,
|
|
58001
58107
|
lastSentTime: date
|
|
58002
58108
|
};
|
|
@@ -58044,7 +58150,7 @@ function handleConfirmation(msg, board) {
|
|
|
58044
58150
|
conf.connection?.dismissNotificationAboutLostConnection();
|
|
58045
58151
|
log.currentSequenceNumber++;
|
|
58046
58152
|
log.pendingEvent.event.order = msg.order;
|
|
58047
|
-
log.
|
|
58153
|
+
log.confirmSentLocalEventIds(log.pendingEvent.sentEventIds, msg.order);
|
|
58048
58154
|
board.subject.publish();
|
|
58049
58155
|
log.pendingEvent = null;
|
|
58050
58156
|
log.firstSentTime = null;
|