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.
@@ -4140,277 +4140,6 @@ var init_Color = __esm(() => {
4140
4140
  init_resolveColor();
4141
4141
  });
4142
4142
 
4143
- // src/Events/SyncLog.ts
4144
- function createSyncLog() {
4145
- const log = [];
4146
- const subject = new Subject;
4147
- log.push = function(...msgs) {
4148
- let newLength = log.length;
4149
- for (const msg of msgs) {
4150
- const lastItem = log[log.length - 1];
4151
- if (lastItem && lastItem.msg === msg.msg) {
4152
- lastItem.records = lastItem.records.concat(msg.records);
4153
- } else {
4154
- newLength = Array.prototype.push.call(log, msg);
4155
- }
4156
- }
4157
- subject.publish(log);
4158
- return newLength;
4159
- };
4160
- return {
4161
- log,
4162
- subject
4163
- };
4164
- }
4165
- var init_SyncLog = () => {};
4166
-
4167
- // src/Events/Log/createEventsList.ts
4168
- function createEventsList(commandFactory) {
4169
- const confirmedRecords = [];
4170
- const recordsToSend = [];
4171
- const newRecords = [];
4172
- const justConfirmed = [];
4173
- const { log: syncLog, subject: syncLogSubject } = createSyncLog();
4174
- let snapshotLastIndex = 0;
4175
- function revert(records) {
4176
- for (let i = records.length - 1;i >= 0; i--) {
4177
- records[i].command.revert();
4178
- }
4179
- }
4180
- function getOpItems(op) {
4181
- if ("item" in op) {
4182
- const item = op.item;
4183
- if (Array.isArray(item))
4184
- return item;
4185
- if (typeof item === "string")
4186
- return [item];
4187
- if (item && typeof item === "object")
4188
- return Object.keys(item);
4189
- }
4190
- if ("itemsMap" in op && op.itemsMap)
4191
- return Object.keys(op.itemsMap);
4192
- if ("items" in op) {
4193
- const items = op.items;
4194
- if (Array.isArray(items)) {
4195
- return items.map((i) => typeof i === "string" ? i : i.id).filter(Boolean);
4196
- }
4197
- if (items && typeof items === "object" && items !== null)
4198
- return Object.keys(items);
4199
- }
4200
- if ("itemsOps" in op) {
4201
- const itemsOps = op.itemsOps;
4202
- return itemsOps.map((io) => io.item);
4203
- }
4204
- return [];
4205
- }
4206
- return {
4207
- commandFactory,
4208
- addConfirmedRecords(records) {
4209
- confirmedRecords.push(...records);
4210
- syncLog.push({ msg: "confirmed", records });
4211
- },
4212
- addNewRecords(records) {
4213
- newRecords.push(...records);
4214
- syncLog.push({ msg: "addedNew", records });
4215
- },
4216
- confirmSentRecords(events) {
4217
- for (const event of events) {
4218
- const index = recordsToSend.findIndex((r) => r.event.body.eventId === event.body.eventId);
4219
- if (index !== -1) {
4220
- const [record] = recordsToSend.splice(index, 1);
4221
- confirmedRecords.push(record);
4222
- syncLog.push({ msg: "confirmed", records: [record] });
4223
- }
4224
- }
4225
- },
4226
- getConfirmedRecords() {
4227
- return confirmedRecords;
4228
- },
4229
- getRecordsToSend() {
4230
- return recordsToSend;
4231
- },
4232
- getNewRecords() {
4233
- return newRecords;
4234
- },
4235
- getAllRecords() {
4236
- return [...confirmedRecords, ...recordsToSend, ...newRecords];
4237
- },
4238
- prepareRecordsToSend() {
4239
- const records = [...newRecords];
4240
- recordsToSend.push(...records);
4241
- newRecords.length = 0;
4242
- syncLog.push({ msg: "toSend", records });
4243
- return records;
4244
- },
4245
- forwardIterable() {
4246
- return function* () {
4247
- yield* confirmedRecords;
4248
- yield* recordsToSend;
4249
- yield* newRecords;
4250
- }();
4251
- },
4252
- backwardIterable() {
4253
- return function* () {
4254
- for (let i = newRecords.length - 1;i >= 0; i--)
4255
- yield newRecords[i];
4256
- for (let i = recordsToSend.length - 1;i >= 0; i--)
4257
- yield recordsToSend[i];
4258
- for (let i = confirmedRecords.length - 1;i >= 0; i--)
4259
- yield confirmedRecords[i];
4260
- }();
4261
- },
4262
- revertUnconfirmed(predicate) {
4263
- const toRevert = [...recordsToSend, ...newRecords].filter(predicate || (() => true));
4264
- revert(toRevert);
4265
- syncLog.push({ msg: "revertUnconfirmed", records: toRevert });
4266
- },
4267
- applyUnconfirmed(predicate) {
4268
- const unconfirmed = [...recordsToSend, ...newRecords].filter(predicate || (() => true));
4269
- for (const record of unconfirmed) {
4270
- record.command.apply();
4271
- }
4272
- syncLog.push({ msg: "applyUnconfirmed", records: unconfirmed });
4273
- },
4274
- justConfirmed,
4275
- getSyncLog() {
4276
- return syncLog;
4277
- },
4278
- syncLogSubject,
4279
- clear() {
4280
- confirmedRecords.length = 0;
4281
- recordsToSend.length = 0;
4282
- newRecords.length = 0;
4283
- syncLog.length = 0;
4284
- syncLogSubject.publish(syncLog);
4285
- },
4286
- clearConfirmedRecords() {
4287
- confirmedRecords.length = 0;
4288
- syncLog.length = 0;
4289
- syncLogSubject.publish(syncLog);
4290
- },
4291
- removeUnconfirmedEventsByItems(itemIds) {
4292
- const itemIdSet = new Set(itemIds);
4293
- const filter = (record) => {
4294
- const opItems = getOpItems(record.event.body.operation);
4295
- return !opItems.some((id) => itemIdSet.has(id));
4296
- };
4297
- const filteredNewRecords = newRecords.filter(filter);
4298
- newRecords.length = 0;
4299
- newRecords.push(...filteredNewRecords);
4300
- const filteredRecordsToSend = recordsToSend.filter(filter);
4301
- recordsToSend.length = 0;
4302
- recordsToSend.push(...filteredRecordsToSend);
4303
- syncLog.length = 0;
4304
- syncLog.push({ msg: "confirmed", records: confirmedRecords });
4305
- syncLog.push({ msg: "toSend", records: recordsToSend });
4306
- syncLog.push({ msg: "addedNew", records: newRecords });
4307
- syncLogSubject.publish(syncLog);
4308
- },
4309
- isAllEventsConfirmed() {
4310
- return recordsToSend.length === 0 && newRecords.length === 0;
4311
- },
4312
- setSnapshotLastIndex(index) {
4313
- snapshotLastIndex = index;
4314
- },
4315
- getSnapshotLastIndex() {
4316
- return snapshotLastIndex;
4317
- }
4318
- };
4319
- }
4320
- var init_createEventsList = __esm(() => {
4321
- init_SyncLog();
4322
- });
4323
-
4324
- // src/Events/Log/getRecordByIdFromList.ts
4325
- function getRecordByIdFromList(id, list) {
4326
- for (const record of list.forwardIterable()) {
4327
- if (record.event.body.eventId === id) {
4328
- return record;
4329
- }
4330
- }
4331
- return;
4332
- }
4333
-
4334
- // src/Events/Log/shouldSkipEvent.ts
4335
- function shouldSkipEvent(record, userId) {
4336
- const { operation } = record.event.body;
4337
- return record.event.body.userId !== userId || operation.method === "updateVideoData" || operation.class === "Audio" && operation.method === "setUrl";
4338
- }
4339
-
4340
- // src/Events/Log/getRedoRecordFromList.ts
4341
- function getRedoRecordFromList(userId, list) {
4342
- let counter = 0;
4343
- for (const record of list.backwardIterable()) {
4344
- if (shouldSkipEvent(record, userId)) {
4345
- continue;
4346
- }
4347
- if (record.event.body.operation.method !== "undo" && record.event.body.operation.method !== "redo") {
4348
- return null;
4349
- }
4350
- const { method } = record.event.body.operation;
4351
- if (method === "redo") {
4352
- counter++;
4353
- } else if (method === "undo") {
4354
- if (counter > 0) {
4355
- counter--;
4356
- } else if (counter === 0) {
4357
- return record;
4358
- }
4359
- }
4360
- }
4361
- return null;
4362
- }
4363
- var init_getRedoRecordFromList = () => {};
4364
-
4365
- // src/Events/Log/getUndoRecordFromList.ts
4366
- function getUndoRecordFromList(userId, list) {
4367
- let counter = 0;
4368
- const isAllEventsConfirmed = list.isAllEventsConfirmed();
4369
- if (!isAllEventsConfirmed) {
4370
- return null;
4371
- }
4372
- for (const record of list.getConfirmedRecords().slice().reverse()) {
4373
- if (shouldSkipEvent(record, userId)) {
4374
- continue;
4375
- }
4376
- if (record.event.body.operation.method === "undo") {
4377
- counter++;
4378
- } else if (counter === 0) {
4379
- return record;
4380
- } else {
4381
- counter--;
4382
- }
4383
- }
4384
- return null;
4385
- }
4386
- var init_getUndoRecordFromList = () => {};
4387
-
4388
- // src/Events/Log/getUnpublishedEventFromList.ts
4389
- function getUnpublishedEventFromList(list) {
4390
- const recordsToSend = list.prepareRecordsToSend();
4391
- if (recordsToSend.length === 0) {
4392
- return null;
4393
- }
4394
- const operations = getOperationsFromEventRecords(recordsToSend);
4395
- return combineOperationsIntoPack(recordsToSend[0].event, operations);
4396
- }
4397
- function getOperationsFromEventRecords(records) {
4398
- return records.map((record) => ({
4399
- ...record.event.body.operation,
4400
- actualId: record.event.body.eventId
4401
- }));
4402
- }
4403
- function combineOperationsIntoPack(baseEvent, operations) {
4404
- const { operation, ...bodyWithoutOperation } = baseEvent.body;
4405
- return {
4406
- ...baseEvent,
4407
- body: {
4408
- ...bodyWithoutOperation,
4409
- operations
4410
- }
4411
- };
4412
- }
4413
-
4414
4143
  // src/Events/EventsOperations.ts
4415
4144
  function isTransformation(op) {
4416
4145
  return op.class === "Transformation";
@@ -4737,41 +4466,69 @@ function mergeBoardOperations(opA, opB) {
4737
4466
  }
4738
4467
  var init_Merge = () => {};
4739
4468
 
4740
- // src/Events/mergeEvents.ts
4741
- function mergeEvents(events) {
4742
- if (events.length < 2) {
4743
- return events;
4469
+ // src/Events/mergeRecords.ts
4470
+ function mergeRecords(records) {
4471
+ if (records.length < 2) {
4472
+ return records;
4744
4473
  }
4745
- const mergedEvents = [];
4474
+ const mergedRecords = [];
4746
4475
  let previous = null;
4747
- for (const event of events) {
4476
+ for (const record of records) {
4748
4477
  if (!previous) {
4749
- previous = event;
4478
+ previous = record;
4750
4479
  continue;
4751
4480
  }
4752
- const mergedOperation = mergeOperations(previous.body.operation, event.body.operation);
4753
- if (!mergedOperation) {
4754
- mergedEvents.push(previous);
4755
- previous = event;
4481
+ const mergedEventOperation = mergeOperations(previous.event.body.operation, record.event.body.operation);
4482
+ if (!mergedEventOperation) {
4483
+ mergedRecords.push(previous);
4484
+ previous = record;
4756
4485
  } else {
4486
+ const mergedCommand = record.command.merge ? previous.command.merge(mergedEventOperation) : previous.command;
4757
4487
  previous = {
4758
- ...event,
4759
- body: {
4760
- ...event.body,
4761
- operation: mergedOperation
4762
- }
4488
+ event: {
4489
+ ...record.event,
4490
+ body: {
4491
+ ...record.event.body,
4492
+ operation: mergedEventOperation
4493
+ }
4494
+ },
4495
+ command: mergedCommand
4763
4496
  };
4764
4497
  }
4765
4498
  }
4766
4499
  if (previous) {
4767
- mergedEvents.push(previous);
4500
+ mergedRecords.push(previous);
4768
4501
  }
4769
- return mergedEvents;
4502
+ return mergedRecords;
4770
4503
  }
4771
- var init_mergeEvents = __esm(() => {
4504
+ var init_mergeRecords = __esm(() => {
4772
4505
  init_Merge();
4773
4506
  });
4774
4507
 
4508
+ // src/Events/SyncLog.ts
4509
+ function createSyncLog() {
4510
+ const log = [];
4511
+ const subject = new Subject;
4512
+ log.push = function(...msgs) {
4513
+ let newLength = log.length;
4514
+ for (const msg of msgs) {
4515
+ const lastItem = log[log.length - 1];
4516
+ if (lastItem && lastItem.msg === msg.msg) {
4517
+ lastItem.records = lastItem.records.concat(msg.records);
4518
+ } else {
4519
+ newLength = Array.prototype.push.call(log, msg);
4520
+ }
4521
+ }
4522
+ subject.publish(log);
4523
+ return newLength;
4524
+ };
4525
+ return {
4526
+ log,
4527
+ subject
4528
+ };
4529
+ }
4530
+ var init_SyncLog = () => {};
4531
+
4775
4532
  // src/Events/Transform/removeText_removeText.ts
4776
4533
  import { Path as Path2 } from "slate";
4777
4534
  function removeText_removeText(confirmed, toTransform) {
@@ -5855,6 +5612,346 @@ var init_transformEvents = __esm(() => {
5855
5612
  init_Transform2();
5856
5613
  });
5857
5614
 
5615
+ // src/Events/Log/createEventsList.ts
5616
+ function createEventsList(commandFactory) {
5617
+ const confirmedRecords = [];
5618
+ const recordsToSend = [];
5619
+ const newRecords = [];
5620
+ const justConfirmed = [];
5621
+ const { log: syncLog, subject: syncLogSubject } = createSyncLog();
5622
+ let snapshotLastIndex = 0;
5623
+ function revert(records) {
5624
+ for (let i = records.length - 1;i >= 0; i--) {
5625
+ records[i].command.revert();
5626
+ }
5627
+ }
5628
+ function apply(records) {
5629
+ for (const record of records) {
5630
+ record.command = commandFactory(record.event.body.operation);
5631
+ record.command.apply();
5632
+ }
5633
+ }
5634
+ function mergeAndPushConfirmedRecords(records) {
5635
+ const lastConfirmedRecord = confirmedRecords.pop();
5636
+ const recordsToMerge = lastConfirmedRecord ? [lastConfirmedRecord, ...records] : records;
5637
+ const mergedRecords = mergeRecords(recordsToMerge);
5638
+ confirmedRecords.push(...mergedRecords);
5639
+ }
5640
+ return {
5641
+ commandFactory,
5642
+ addConfirmedRecords(records) {
5643
+ syncLog.push({ msg: "confirmed", records });
5644
+ mergeAndPushConfirmedRecords(records);
5645
+ },
5646
+ addNewRecords(records) {
5647
+ for (const record of records) {
5648
+ if (newRecords.length > 0) {
5649
+ const lastRecord = newRecords[newRecords.length - 1];
5650
+ const mergedOperation = mergeOperations(lastRecord.event.body.operation, record.event.body.operation);
5651
+ if (mergedOperation) {
5652
+ lastRecord.event = {
5653
+ ...lastRecord.event,
5654
+ body: {
5655
+ ...lastRecord.event.body,
5656
+ operation: mergedOperation
5657
+ }
5658
+ };
5659
+ lastRecord.command = commandFactory(mergedOperation);
5660
+ continue;
5661
+ }
5662
+ }
5663
+ newRecords.push(record);
5664
+ syncLog.push({ msg: "addedNew", records: [record] });
5665
+ }
5666
+ },
5667
+ confirmSentRecords(events) {
5668
+ const records = recordsToSend;
5669
+ if (records.length !== events.length) {
5670
+ console.error("Mismatch between records and events length");
5671
+ return;
5672
+ }
5673
+ for (let i = 0;i < records.length; i++) {
5674
+ records[i].event.order = events[i].order;
5675
+ }
5676
+ syncLog.push({ msg: "confirmed", records: [...records] });
5677
+ mergeAndPushConfirmedRecords(records);
5678
+ recordsToSend.splice(0, records.length);
5679
+ },
5680
+ confirmSentRecordIds(eventIds, order) {
5681
+ const confirmedRecordsById = [];
5682
+ for (const eventId of eventIds) {
5683
+ const index = recordsToSend.findIndex((record2) => record2.event.body.eventId === eventId);
5684
+ if (index === -1) {
5685
+ continue;
5686
+ }
5687
+ const [record] = recordsToSend.splice(index, 1);
5688
+ record.event.order = order;
5689
+ confirmedRecordsById.push(record);
5690
+ }
5691
+ if (confirmedRecordsById.length === 0) {
5692
+ return;
5693
+ }
5694
+ syncLog.push({ msg: "confirmed", records: confirmedRecordsById });
5695
+ mergeAndPushConfirmedRecords(confirmedRecordsById);
5696
+ },
5697
+ getConfirmedRecords() {
5698
+ return confirmedRecords;
5699
+ },
5700
+ getRecordsToSend() {
5701
+ return recordsToSend;
5702
+ },
5703
+ getNewRecords() {
5704
+ return newRecords;
5705
+ },
5706
+ getAllRecords() {
5707
+ return [...confirmedRecords, ...recordsToSend, ...newRecords];
5708
+ },
5709
+ prepareRecordsToSend() {
5710
+ if (recordsToSend.length === 0 && newRecords.length > 0) {
5711
+ const records = [...newRecords];
5712
+ recordsToSend.push(...records);
5713
+ newRecords.length = 0;
5714
+ syncLog.push({ msg: "toSend", records });
5715
+ }
5716
+ return recordsToSend;
5717
+ },
5718
+ forwardIterable() {
5719
+ return function* () {
5720
+ yield* confirmedRecords;
5721
+ yield* recordsToSend;
5722
+ yield* newRecords;
5723
+ }();
5724
+ },
5725
+ backwardIterable() {
5726
+ return function* () {
5727
+ for (let i = newRecords.length - 1;i >= 0; i--)
5728
+ yield newRecords[i];
5729
+ for (let i = recordsToSend.length - 1;i >= 0; i--)
5730
+ yield recordsToSend[i];
5731
+ for (let i = confirmedRecords.length - 1;i >= 0; i--)
5732
+ yield confirmedRecords[i];
5733
+ }();
5734
+ },
5735
+ revertUnconfirmed(predicate) {
5736
+ const toRevert = [...recordsToSend, ...newRecords].filter(predicate || (() => true));
5737
+ revert(toRevert);
5738
+ syncLog.push({ msg: "revertUnconfirmed", records: toRevert });
5739
+ },
5740
+ applyUnconfirmed(predicate) {
5741
+ const filter = predicate || (() => true);
5742
+ if (justConfirmed.length > 0) {
5743
+ const confirmedEvents = justConfirmed.map((record) => record.event);
5744
+ const transformedSend = transformEvents(confirmedEvents, recordsToSend.map((record) => record.event));
5745
+ const transformedNew = transformEvents(confirmedEvents, newRecords.map((record) => record.event));
5746
+ const updatedRecordsToSend = transformedSend.map((event) => ({
5747
+ event,
5748
+ command: commandFactory(event.body.operation)
5749
+ }));
5750
+ const updatedNewRecords = transformedNew.map((event) => ({
5751
+ event,
5752
+ command: commandFactory(event.body.operation)
5753
+ }));
5754
+ recordsToSend.length = 0;
5755
+ recordsToSend.push(...updatedRecordsToSend);
5756
+ newRecords.length = 0;
5757
+ newRecords.push(...updatedNewRecords);
5758
+ justConfirmed.length = 0;
5759
+ }
5760
+ const unconfirmed = [...recordsToSend, ...newRecords].filter(filter);
5761
+ apply(unconfirmed);
5762
+ syncLog.push({ msg: "applyUnconfirmed", records: unconfirmed });
5763
+ },
5764
+ justConfirmed,
5765
+ getSyncLog() {
5766
+ return syncLog;
5767
+ },
5768
+ syncLogSubject,
5769
+ clear() {
5770
+ confirmedRecords.length = 0;
5771
+ recordsToSend.length = 0;
5772
+ newRecords.length = 0;
5773
+ syncLog.length = 0;
5774
+ syncLogSubject.publish(syncLog);
5775
+ },
5776
+ clearConfirmedRecords() {
5777
+ confirmedRecords.length = 0;
5778
+ syncLog.length = 0;
5779
+ syncLogSubject.publish(syncLog);
5780
+ },
5781
+ removeUnconfirmedEventsByItems(itemIds) {
5782
+ function shouldRemoveEvent(operation, ids) {
5783
+ if (operation.method === "add" && operation.class === "Board") {
5784
+ if (Array.isArray(operation.item)) {
5785
+ return operation.item.some((id) => ids.includes(id));
5786
+ }
5787
+ return ids.includes(operation.item);
5788
+ }
5789
+ if (operation.method === "remove" && operation.class === "Board") {
5790
+ return operation.item.some((id) => ids.includes(id));
5791
+ }
5792
+ return false;
5793
+ }
5794
+ const nextRecordsToSend = recordsToSend.filter((record) => !shouldRemoveEvent(record.event.body.operation, itemIds));
5795
+ if (nextRecordsToSend.length !== recordsToSend.length) {
5796
+ recordsToSend.length = 0;
5797
+ recordsToSend.push(...nextRecordsToSend);
5798
+ }
5799
+ const nextNewRecords = newRecords.filter((record) => !shouldRemoveEvent(record.event.body.operation, itemIds));
5800
+ if (nextNewRecords.length !== newRecords.length) {
5801
+ newRecords.length = 0;
5802
+ newRecords.push(...nextNewRecords);
5803
+ }
5804
+ },
5805
+ isAllEventsConfirmed() {
5806
+ return recordsToSend.length === 0 && newRecords.length === 0;
5807
+ },
5808
+ setSnapshotLastIndex(index) {
5809
+ snapshotLastIndex = index;
5810
+ },
5811
+ getSnapshotLastIndex() {
5812
+ return snapshotLastIndex;
5813
+ }
5814
+ };
5815
+ }
5816
+ var init_createEventsList = __esm(() => {
5817
+ init_Merge();
5818
+ init_mergeRecords();
5819
+ init_SyncLog();
5820
+ init_transformEvents();
5821
+ });
5822
+
5823
+ // src/Events/Log/getRecordByIdFromList.ts
5824
+ function getRecordByIdFromList(id, list) {
5825
+ for (const record of list.forwardIterable()) {
5826
+ if (record.event.body.eventId === id) {
5827
+ return record;
5828
+ }
5829
+ }
5830
+ return;
5831
+ }
5832
+
5833
+ // src/Events/Log/shouldSkipEvent.ts
5834
+ function shouldSkipEvent(record, userId) {
5835
+ const { operation } = record.event.body;
5836
+ return record.event.body.userId !== userId || operation.method === "updateVideoData" || operation.class === "Audio" && operation.method === "setUrl";
5837
+ }
5838
+
5839
+ // src/Events/Log/getRedoRecordFromList.ts
5840
+ function getRedoRecordFromList(userId, list) {
5841
+ let counter = 0;
5842
+ for (const record of list.backwardIterable()) {
5843
+ if (shouldSkipEvent(record, userId)) {
5844
+ continue;
5845
+ }
5846
+ if (record.event.body.operation.method !== "undo" && record.event.body.operation.method !== "redo") {
5847
+ return null;
5848
+ }
5849
+ const { method } = record.event.body.operation;
5850
+ if (method === "redo") {
5851
+ counter++;
5852
+ } else if (method === "undo") {
5853
+ if (counter > 0) {
5854
+ counter--;
5855
+ } else if (counter === 0) {
5856
+ return record;
5857
+ }
5858
+ }
5859
+ }
5860
+ return null;
5861
+ }
5862
+ var init_getRedoRecordFromList = () => {};
5863
+
5864
+ // src/Events/Log/getUndoRecordFromList.ts
5865
+ function getUndoRecordFromList(userId, list) {
5866
+ let counter = 0;
5867
+ const isAllEventsConfirmed = list.isAllEventsConfirmed();
5868
+ if (!isAllEventsConfirmed) {
5869
+ return null;
5870
+ }
5871
+ for (const record of list.getConfirmedRecords().slice().reverse()) {
5872
+ if (shouldSkipEvent(record, userId)) {
5873
+ continue;
5874
+ }
5875
+ if (record.event.body.operation.method === "undo") {
5876
+ counter++;
5877
+ } else if (counter === 0) {
5878
+ return record;
5879
+ } else {
5880
+ counter--;
5881
+ }
5882
+ }
5883
+ return null;
5884
+ }
5885
+ var init_getUndoRecordFromList = () => {};
5886
+
5887
+ // src/Events/Log/getUnpublishedEventFromList.ts
5888
+ function getUnpublishedEventFromList(list) {
5889
+ const recordsToSend = list.prepareRecordsToSend();
5890
+ if (recordsToSend.length === 0) {
5891
+ return null;
5892
+ }
5893
+ const mergedRecords = mergeRecords(recordsToSend);
5894
+ const operations = getOperationsFromEventRecords(mergedRecords);
5895
+ return {
5896
+ event: combineOperationsIntoPack(recordsToSend[0].event, operations),
5897
+ sentEventIds: recordsToSend.map((record) => record.event.body.eventId)
5898
+ };
5899
+ }
5900
+ function getOperationsFromEventRecords(records) {
5901
+ return records.map((record) => ({
5902
+ ...record.event.body.operation,
5903
+ actualId: record.event.body.eventId
5904
+ }));
5905
+ }
5906
+ function combineOperationsIntoPack(baseEvent, operations) {
5907
+ const { operation, ...bodyWithoutOperation } = baseEvent.body;
5908
+ return {
5909
+ ...baseEvent,
5910
+ body: {
5911
+ ...bodyWithoutOperation,
5912
+ operations
5913
+ }
5914
+ };
5915
+ }
5916
+ var init_getUnpublishedEventFromList = __esm(() => {
5917
+ init_mergeRecords();
5918
+ });
5919
+
5920
+ // src/Events/mergeEvents.ts
5921
+ function mergeEvents(events) {
5922
+ if (events.length < 2) {
5923
+ return events;
5924
+ }
5925
+ const mergedEvents = [];
5926
+ let previous = null;
5927
+ for (const event of events) {
5928
+ if (!previous) {
5929
+ previous = event;
5930
+ continue;
5931
+ }
5932
+ const mergedOperation = mergeOperations(previous.body.operation, event.body.operation);
5933
+ if (!mergedOperation) {
5934
+ mergedEvents.push(previous);
5935
+ previous = event;
5936
+ } else {
5937
+ previous = {
5938
+ ...event,
5939
+ body: {
5940
+ ...event.body,
5941
+ operation: mergedOperation
5942
+ }
5943
+ };
5944
+ }
5945
+ }
5946
+ if (previous) {
5947
+ mergedEvents.push(previous);
5948
+ }
5949
+ return mergedEvents;
5950
+ }
5951
+ var init_mergeEvents = __esm(() => {
5952
+ init_Merge();
5953
+ });
5954
+
5858
5955
  // src/Events/Log/expandEvents.ts
5859
5956
  function expandEvents(events) {
5860
5957
  return events.flatMap((event) => {
@@ -6068,6 +6165,9 @@ class EventsLog {
6068
6165
  const events = expandEvents([event]);
6069
6166
  this.list.confirmSentRecords(events);
6070
6167
  }
6168
+ confirmSentLocalEventIds(eventIds, order) {
6169
+ this.list.confirmSentRecordIds(eventIds, order);
6170
+ }
6071
6171
  getUnorderedRecords() {
6072
6172
  return this.list.getRecordsToSend().concat(this.list.getNewRecords());
6073
6173
  }
@@ -6110,6 +6210,7 @@ var init_EventsLog = __esm(() => {
6110
6210
  init_createEventsList();
6111
6211
  init_getRedoRecordFromList();
6112
6212
  init_getUndoRecordFromList();
6213
+ init_getUnpublishedEventFromList();
6113
6214
  init_insertEventsFromOtherConnectionsIntoList();
6114
6215
  });
6115
6216
 
@@ -12037,6 +12138,9 @@ class SpatialIndex {
12037
12138
  this.Mbr = new Mbr;
12038
12139
  }
12039
12140
  insert(item) {
12141
+ if (this.itemsArray.includes(item) || this.getById(item.getId())) {
12142
+ return;
12143
+ }
12040
12144
  this.itemsArray.push(item);
12041
12145
  this.itemsIndex.insert(item);
12042
12146
  if (conf.isNode()) {
@@ -12634,6 +12738,9 @@ class SimpleSpatialIndex {
12634
12738
  this.Mbr = new Mbr;
12635
12739
  }
12636
12740
  insert(item) {
12741
+ if (this.itemsArray.includes(item) || this.getById(item.getId())) {
12742
+ return;
12743
+ }
12637
12744
  this.itemsArray.push(item);
12638
12745
  if (this.Mbr.getWidth() === 0 && this.Mbr.getHeight() === 0) {
12639
12746
  this.Mbr = item.getMbr().copy();
@@ -13060,7 +13167,10 @@ var init_BaseItem = __esm(() => {
13060
13167
  if (this.parent !== childId && this.getId() !== childId && !this.hasAncestor(childId)) {
13061
13168
  if (!this.index?.getById(childId) && foundItem) {
13062
13169
  const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
13063
- this.board.items.index.remove(foundItem, true);
13170
+ const currentParentId = foundItem.parent;
13171
+ const currentParent = currentParentId !== "Board" ? this.board.items.getById(currentParentId) : undefined;
13172
+ const sourceIndex = currentParent?.index || this.board.items.index;
13173
+ sourceIndex.remove(foundItem, true);
13064
13174
  foundItem.parent = this.getId();
13065
13175
  foundItem.onParentChanged(this.getId());
13066
13176
  foundItem.transformation.setLocalMatrix(localMatrix);
@@ -16659,7 +16769,7 @@ var init_getListTypeAtSelectionStart = __esm(() => {
16659
16769
  });
16660
16770
 
16661
16771
  // src/Items/RichText/editorHelpers/links/setLink.ts
16662
- import { Editor as Editor12, Transforms as Transforms11 } from "slate";
16772
+ import { Editor as Editor12, Transforms as Transforms11, Text as Text6 } from "slate";
16663
16773
  var setLink = (editor, link, selection) => {
16664
16774
  if (!selection) {
16665
16775
  selectWholeText(editor);
@@ -16671,15 +16781,15 @@ var setLink = (editor, link, selection) => {
16671
16781
  }
16672
16782
  const format = link ? "rgba(71, 120, 245, 1)" : "rgb(20, 21, 26)";
16673
16783
  Transforms11.setNodes(editor, { fontColor: format }, {
16674
- match: (n) => !Editor12.isEditor(n) && n.type === "text",
16784
+ match: (n) => Text6.isText(n),
16675
16785
  split: true
16676
16786
  });
16677
- for (const [node, path2] of Editor12.nodes(editor, {
16678
- match: (n) => !Editor12.isEditor(n) && n.type === "text"
16787
+ for (const [, path2] of Editor12.nodes(editor, {
16788
+ match: (n) => Text6.isText(n)
16679
16789
  })) {
16680
16790
  const nodeRange = Editor12.range(editor, path2);
16681
16791
  Transforms11.select(editor, nodeRange);
16682
- Transforms11.setNodes(editor, { link }, { split: false, match: (n) => !Editor12.isEditor(n) && n.type === "text" });
16792
+ Transforms11.setNodes(editor, { link }, { split: false, match: (n) => Text6.isText(n) });
16683
16793
  }
16684
16794
  };
16685
16795
  var init_setLink = __esm(() => {
@@ -25039,7 +25149,7 @@ var init_setEditorFocus = () => {};
25039
25149
  import {
25040
25150
  Editor as Editor31,
25041
25151
  Element as Element9,
25042
- Text as Text6,
25152
+ Text as Text7,
25043
25153
  Transforms as Transforms21
25044
25154
  } from "slate";
25045
25155
  var isEditInProcessValue = false, counter = 0, RichText;
@@ -25607,7 +25717,7 @@ var init_RichText = __esm(() => {
25607
25717
  }
25608
25718
  getMinFontSize() {
25609
25719
  const textNodes = Editor31.nodes(this.editor.editor, {
25610
- match: (n) => Text6.isText(n),
25720
+ match: (n) => Text7.isText(n),
25611
25721
  at: []
25612
25722
  });
25613
25723
  const fontSizes = [];
@@ -55380,25 +55490,16 @@ function handleBoardEventMessage(message, board) {
55380
55490
  if (event.order <= log.getLastIndex()) {
55381
55491
  return;
55382
55492
  }
55383
- const eventUserId = parseFloat(event.body.eventId.split(":")[0]);
55384
- const currentUserId = Number(localStorage.getItem("userId") || "0");
55385
- const isEventFromCurrentUser = eventUserId === currentUserId;
55493
+ const eventConnectionId = Number(event.body.eventId.split(":")[0]);
55494
+ const currentConnectionId = board.events.connection?.connectionId;
55495
+ const isEventFromCurrentUser = currentConnectionId !== undefined && eventConnectionId === currentConnectionId;
55386
55496
  if (isEventFromCurrentUser) {
55387
55497
  return;
55388
55498
  }
55389
55499
  if ("operations" in event.body) {
55390
- log.insertEventsFromOtherConnections({
55391
- ...event,
55392
- body: {
55393
- ...event.body,
55394
- userId: Number(message.userId)
55395
- }
55396
- });
55500
+ log.insertEventsFromOtherConnections(event);
55397
55501
  } else {
55398
- log.insertEventsFromOtherConnections({
55399
- ...event,
55400
- userId: Number(message.userId)
55401
- });
55502
+ log.insertEventsFromOtherConnections(event);
55402
55503
  }
55403
55504
  const last = log.getLastConfirmed();
55404
55505
  if (last) {
@@ -55450,11 +55551,11 @@ function tryPublishEvent(board) {
55450
55551
  if (log.pendingEvent) {
55451
55552
  return;
55452
55553
  }
55453
- const unpublishedEvent = log.getUnpublishedEvent();
55454
- if (!unpublishedEvent) {
55554
+ const unpublishedBatch = log.getUnpublishedEvent();
55555
+ if (!unpublishedBatch) {
55455
55556
  return;
55456
55557
  }
55457
- sendBoardEvent(board, unpublishedEvent, log.currentSequenceNumber);
55558
+ sendBoardEvent(board, unpublishedBatch, log.currentSequenceNumber);
55458
55559
  }
55459
55560
  function tryResendEvent(board) {
55460
55561
  const { log } = board.events;
@@ -55471,7 +55572,10 @@ function tryResendEvent(board) {
55471
55572
  board.presence.clear();
55472
55573
  conf.connection?.notifyAboutLostConnection();
55473
55574
  }
55474
- sendBoardEvent(board, log.pendingEvent.event, log.currentSequenceNumber);
55575
+ sendBoardEvent(board, {
55576
+ event: log.pendingEvent.event,
55577
+ sentEventIds: log.pendingEvent.sentEventIds
55578
+ }, log.currentSequenceNumber);
55475
55579
  }
55476
55580
  function handleSnapshotApplication(snapshot, board) {
55477
55581
  const { log } = board.events;
@@ -55496,8 +55600,9 @@ function handleBoardEventListApplication(events, board) {
55496
55600
  board.events.subject.publish(newEvents[0]);
55497
55601
  }
55498
55602
  }
55499
- function sendBoardEvent(board, event, sequenceNumber) {
55603
+ function sendBoardEvent(board, batch, sequenceNumber) {
55500
55604
  const { log } = board.events;
55605
+ const { event, sentEventIds } = batch;
55501
55606
  const toSend = {
55502
55607
  ...event,
55503
55608
  body: {
@@ -55515,6 +55620,7 @@ function sendBoardEvent(board, event, sequenceNumber) {
55515
55620
  const date = Date.now();
55516
55621
  log.pendingEvent = {
55517
55622
  event: toSend,
55623
+ sentEventIds,
55518
55624
  sequenceNumber,
55519
55625
  lastSentTime: date
55520
55626
  };
@@ -55562,7 +55668,7 @@ function handleConfirmation(msg, board) {
55562
55668
  conf.connection?.dismissNotificationAboutLostConnection();
55563
55669
  log.currentSequenceNumber++;
55564
55670
  log.pendingEvent.event.order = msg.order;
55565
- log.confirmSentLocalEvent(log.pendingEvent.event);
55671
+ log.confirmSentLocalEventIds(log.pendingEvent.sentEventIds, msg.order);
55566
55672
  board.subject.publish();
55567
55673
  log.pendingEvent = null;
55568
55674
  log.firstSentTime = null;