microboard-temp 0.13.44 → 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/esm/index.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";
@@ -4730,41 +4459,69 @@ function mergeBoardOperations(opA, opB) {
4730
4459
  }
4731
4460
  var init_Merge = () => {};
4732
4461
 
4733
- // src/Events/mergeEvents.ts
4734
- function mergeEvents(events) {
4735
- if (events.length < 2) {
4736
- return events;
4462
+ // src/Events/mergeRecords.ts
4463
+ function mergeRecords(records) {
4464
+ if (records.length < 2) {
4465
+ return records;
4737
4466
  }
4738
- const mergedEvents = [];
4467
+ const mergedRecords = [];
4739
4468
  let previous = null;
4740
- for (const event of events) {
4469
+ for (const record of records) {
4741
4470
  if (!previous) {
4742
- previous = event;
4471
+ previous = record;
4743
4472
  continue;
4744
4473
  }
4745
- const mergedOperation = mergeOperations(previous.body.operation, event.body.operation);
4746
- if (!mergedOperation) {
4747
- mergedEvents.push(previous);
4748
- previous = event;
4474
+ const mergedEventOperation = mergeOperations(previous.event.body.operation, record.event.body.operation);
4475
+ if (!mergedEventOperation) {
4476
+ mergedRecords.push(previous);
4477
+ previous = record;
4749
4478
  } else {
4479
+ const mergedCommand = record.command.merge ? previous.command.merge(mergedEventOperation) : previous.command;
4750
4480
  previous = {
4751
- ...event,
4752
- body: {
4753
- ...event.body,
4754
- operation: mergedOperation
4755
- }
4481
+ event: {
4482
+ ...record.event,
4483
+ body: {
4484
+ ...record.event.body,
4485
+ operation: mergedEventOperation
4486
+ }
4487
+ },
4488
+ command: mergedCommand
4756
4489
  };
4757
4490
  }
4758
4491
  }
4759
4492
  if (previous) {
4760
- mergedEvents.push(previous);
4493
+ mergedRecords.push(previous);
4761
4494
  }
4762
- return mergedEvents;
4495
+ return mergedRecords;
4763
4496
  }
4764
- var init_mergeEvents = __esm(() => {
4497
+ var init_mergeRecords = __esm(() => {
4765
4498
  init_Merge();
4766
4499
  });
4767
4500
 
4501
+ // src/Events/SyncLog.ts
4502
+ function createSyncLog() {
4503
+ const log = [];
4504
+ const subject = new Subject;
4505
+ log.push = function(...msgs) {
4506
+ let newLength = log.length;
4507
+ for (const msg of msgs) {
4508
+ const lastItem = log[log.length - 1];
4509
+ if (lastItem && lastItem.msg === msg.msg) {
4510
+ lastItem.records = lastItem.records.concat(msg.records);
4511
+ } else {
4512
+ newLength = Array.prototype.push.call(log, msg);
4513
+ }
4514
+ }
4515
+ subject.publish(log);
4516
+ return newLength;
4517
+ };
4518
+ return {
4519
+ log,
4520
+ subject
4521
+ };
4522
+ }
4523
+ var init_SyncLog = () => {};
4524
+
4768
4525
  // src/Events/Transform/removeText_removeText.ts
4769
4526
  import { Path as Path2 } from "slate";
4770
4527
  function removeText_removeText(confirmed, toTransform) {
@@ -5848,6 +5605,346 @@ var init_transformEvents = __esm(() => {
5848
5605
  init_Transform2();
5849
5606
  });
5850
5607
 
5608
+ // src/Events/Log/createEventsList.ts
5609
+ function createEventsList(commandFactory) {
5610
+ const confirmedRecords = [];
5611
+ const recordsToSend = [];
5612
+ const newRecords = [];
5613
+ const justConfirmed = [];
5614
+ const { log: syncLog, subject: syncLogSubject } = createSyncLog();
5615
+ let snapshotLastIndex = 0;
5616
+ function revert(records) {
5617
+ for (let i = records.length - 1;i >= 0; i--) {
5618
+ records[i].command.revert();
5619
+ }
5620
+ }
5621
+ function apply(records) {
5622
+ for (const record of records) {
5623
+ record.command = commandFactory(record.event.body.operation);
5624
+ record.command.apply();
5625
+ }
5626
+ }
5627
+ function mergeAndPushConfirmedRecords(records) {
5628
+ const lastConfirmedRecord = confirmedRecords.pop();
5629
+ const recordsToMerge = lastConfirmedRecord ? [lastConfirmedRecord, ...records] : records;
5630
+ const mergedRecords = mergeRecords(recordsToMerge);
5631
+ confirmedRecords.push(...mergedRecords);
5632
+ }
5633
+ return {
5634
+ commandFactory,
5635
+ addConfirmedRecords(records) {
5636
+ syncLog.push({ msg: "confirmed", records });
5637
+ mergeAndPushConfirmedRecords(records);
5638
+ },
5639
+ addNewRecords(records) {
5640
+ for (const record of records) {
5641
+ if (newRecords.length > 0) {
5642
+ const lastRecord = newRecords[newRecords.length - 1];
5643
+ const mergedOperation = mergeOperations(lastRecord.event.body.operation, record.event.body.operation);
5644
+ if (mergedOperation) {
5645
+ lastRecord.event = {
5646
+ ...lastRecord.event,
5647
+ body: {
5648
+ ...lastRecord.event.body,
5649
+ operation: mergedOperation
5650
+ }
5651
+ };
5652
+ lastRecord.command = commandFactory(mergedOperation);
5653
+ continue;
5654
+ }
5655
+ }
5656
+ newRecords.push(record);
5657
+ syncLog.push({ msg: "addedNew", records: [record] });
5658
+ }
5659
+ },
5660
+ confirmSentRecords(events) {
5661
+ const records = recordsToSend;
5662
+ if (records.length !== events.length) {
5663
+ console.error("Mismatch between records and events length");
5664
+ return;
5665
+ }
5666
+ for (let i = 0;i < records.length; i++) {
5667
+ records[i].event.order = events[i].order;
5668
+ }
5669
+ syncLog.push({ msg: "confirmed", records: [...records] });
5670
+ mergeAndPushConfirmedRecords(records);
5671
+ recordsToSend.splice(0, records.length);
5672
+ },
5673
+ confirmSentRecordIds(eventIds, order) {
5674
+ const confirmedRecordsById = [];
5675
+ for (const eventId of eventIds) {
5676
+ const index = recordsToSend.findIndex((record2) => record2.event.body.eventId === eventId);
5677
+ if (index === -1) {
5678
+ continue;
5679
+ }
5680
+ const [record] = recordsToSend.splice(index, 1);
5681
+ record.event.order = order;
5682
+ confirmedRecordsById.push(record);
5683
+ }
5684
+ if (confirmedRecordsById.length === 0) {
5685
+ return;
5686
+ }
5687
+ syncLog.push({ msg: "confirmed", records: confirmedRecordsById });
5688
+ mergeAndPushConfirmedRecords(confirmedRecordsById);
5689
+ },
5690
+ getConfirmedRecords() {
5691
+ return confirmedRecords;
5692
+ },
5693
+ getRecordsToSend() {
5694
+ return recordsToSend;
5695
+ },
5696
+ getNewRecords() {
5697
+ return newRecords;
5698
+ },
5699
+ getAllRecords() {
5700
+ return [...confirmedRecords, ...recordsToSend, ...newRecords];
5701
+ },
5702
+ prepareRecordsToSend() {
5703
+ if (recordsToSend.length === 0 && newRecords.length > 0) {
5704
+ const records = [...newRecords];
5705
+ recordsToSend.push(...records);
5706
+ newRecords.length = 0;
5707
+ syncLog.push({ msg: "toSend", records });
5708
+ }
5709
+ return recordsToSend;
5710
+ },
5711
+ forwardIterable() {
5712
+ return function* () {
5713
+ yield* confirmedRecords;
5714
+ yield* recordsToSend;
5715
+ yield* newRecords;
5716
+ }();
5717
+ },
5718
+ backwardIterable() {
5719
+ return function* () {
5720
+ for (let i = newRecords.length - 1;i >= 0; i--)
5721
+ yield newRecords[i];
5722
+ for (let i = recordsToSend.length - 1;i >= 0; i--)
5723
+ yield recordsToSend[i];
5724
+ for (let i = confirmedRecords.length - 1;i >= 0; i--)
5725
+ yield confirmedRecords[i];
5726
+ }();
5727
+ },
5728
+ revertUnconfirmed(predicate) {
5729
+ const toRevert = [...recordsToSend, ...newRecords].filter(predicate || (() => true));
5730
+ revert(toRevert);
5731
+ syncLog.push({ msg: "revertUnconfirmed", records: toRevert });
5732
+ },
5733
+ applyUnconfirmed(predicate) {
5734
+ const filter = predicate || (() => true);
5735
+ if (justConfirmed.length > 0) {
5736
+ const confirmedEvents = justConfirmed.map((record) => record.event);
5737
+ const transformedSend = transformEvents(confirmedEvents, recordsToSend.map((record) => record.event));
5738
+ const transformedNew = transformEvents(confirmedEvents, newRecords.map((record) => record.event));
5739
+ const updatedRecordsToSend = transformedSend.map((event) => ({
5740
+ event,
5741
+ command: commandFactory(event.body.operation)
5742
+ }));
5743
+ const updatedNewRecords = transformedNew.map((event) => ({
5744
+ event,
5745
+ command: commandFactory(event.body.operation)
5746
+ }));
5747
+ recordsToSend.length = 0;
5748
+ recordsToSend.push(...updatedRecordsToSend);
5749
+ newRecords.length = 0;
5750
+ newRecords.push(...updatedNewRecords);
5751
+ justConfirmed.length = 0;
5752
+ }
5753
+ const unconfirmed = [...recordsToSend, ...newRecords].filter(filter);
5754
+ apply(unconfirmed);
5755
+ syncLog.push({ msg: "applyUnconfirmed", records: unconfirmed });
5756
+ },
5757
+ justConfirmed,
5758
+ getSyncLog() {
5759
+ return syncLog;
5760
+ },
5761
+ syncLogSubject,
5762
+ clear() {
5763
+ confirmedRecords.length = 0;
5764
+ recordsToSend.length = 0;
5765
+ newRecords.length = 0;
5766
+ syncLog.length = 0;
5767
+ syncLogSubject.publish(syncLog);
5768
+ },
5769
+ clearConfirmedRecords() {
5770
+ confirmedRecords.length = 0;
5771
+ syncLog.length = 0;
5772
+ syncLogSubject.publish(syncLog);
5773
+ },
5774
+ removeUnconfirmedEventsByItems(itemIds) {
5775
+ function shouldRemoveEvent(operation, ids) {
5776
+ if (operation.method === "add" && operation.class === "Board") {
5777
+ if (Array.isArray(operation.item)) {
5778
+ return operation.item.some((id) => ids.includes(id));
5779
+ }
5780
+ return ids.includes(operation.item);
5781
+ }
5782
+ if (operation.method === "remove" && operation.class === "Board") {
5783
+ return operation.item.some((id) => ids.includes(id));
5784
+ }
5785
+ return false;
5786
+ }
5787
+ const nextRecordsToSend = recordsToSend.filter((record) => !shouldRemoveEvent(record.event.body.operation, itemIds));
5788
+ if (nextRecordsToSend.length !== recordsToSend.length) {
5789
+ recordsToSend.length = 0;
5790
+ recordsToSend.push(...nextRecordsToSend);
5791
+ }
5792
+ const nextNewRecords = newRecords.filter((record) => !shouldRemoveEvent(record.event.body.operation, itemIds));
5793
+ if (nextNewRecords.length !== newRecords.length) {
5794
+ newRecords.length = 0;
5795
+ newRecords.push(...nextNewRecords);
5796
+ }
5797
+ },
5798
+ isAllEventsConfirmed() {
5799
+ return recordsToSend.length === 0 && newRecords.length === 0;
5800
+ },
5801
+ setSnapshotLastIndex(index) {
5802
+ snapshotLastIndex = index;
5803
+ },
5804
+ getSnapshotLastIndex() {
5805
+ return snapshotLastIndex;
5806
+ }
5807
+ };
5808
+ }
5809
+ var init_createEventsList = __esm(() => {
5810
+ init_Merge();
5811
+ init_mergeRecords();
5812
+ init_SyncLog();
5813
+ init_transformEvents();
5814
+ });
5815
+
5816
+ // src/Events/Log/getRecordByIdFromList.ts
5817
+ function getRecordByIdFromList(id, list) {
5818
+ for (const record of list.forwardIterable()) {
5819
+ if (record.event.body.eventId === id) {
5820
+ return record;
5821
+ }
5822
+ }
5823
+ return;
5824
+ }
5825
+
5826
+ // src/Events/Log/shouldSkipEvent.ts
5827
+ function shouldSkipEvent(record, userId) {
5828
+ const { operation } = record.event.body;
5829
+ return record.event.body.userId !== userId || operation.method === "updateVideoData" || operation.class === "Audio" && operation.method === "setUrl";
5830
+ }
5831
+
5832
+ // src/Events/Log/getRedoRecordFromList.ts
5833
+ function getRedoRecordFromList(userId, list) {
5834
+ let counter = 0;
5835
+ for (const record of list.backwardIterable()) {
5836
+ if (shouldSkipEvent(record, userId)) {
5837
+ continue;
5838
+ }
5839
+ if (record.event.body.operation.method !== "undo" && record.event.body.operation.method !== "redo") {
5840
+ return null;
5841
+ }
5842
+ const { method } = record.event.body.operation;
5843
+ if (method === "redo") {
5844
+ counter++;
5845
+ } else if (method === "undo") {
5846
+ if (counter > 0) {
5847
+ counter--;
5848
+ } else if (counter === 0) {
5849
+ return record;
5850
+ }
5851
+ }
5852
+ }
5853
+ return null;
5854
+ }
5855
+ var init_getRedoRecordFromList = () => {};
5856
+
5857
+ // src/Events/Log/getUndoRecordFromList.ts
5858
+ function getUndoRecordFromList(userId, list) {
5859
+ let counter = 0;
5860
+ const isAllEventsConfirmed = list.isAllEventsConfirmed();
5861
+ if (!isAllEventsConfirmed) {
5862
+ return null;
5863
+ }
5864
+ for (const record of list.getConfirmedRecords().slice().reverse()) {
5865
+ if (shouldSkipEvent(record, userId)) {
5866
+ continue;
5867
+ }
5868
+ if (record.event.body.operation.method === "undo") {
5869
+ counter++;
5870
+ } else if (counter === 0) {
5871
+ return record;
5872
+ } else {
5873
+ counter--;
5874
+ }
5875
+ }
5876
+ return null;
5877
+ }
5878
+ var init_getUndoRecordFromList = () => {};
5879
+
5880
+ // src/Events/Log/getUnpublishedEventFromList.ts
5881
+ function getUnpublishedEventFromList(list) {
5882
+ const recordsToSend = list.prepareRecordsToSend();
5883
+ if (recordsToSend.length === 0) {
5884
+ return null;
5885
+ }
5886
+ const mergedRecords = mergeRecords(recordsToSend);
5887
+ const operations = getOperationsFromEventRecords(mergedRecords);
5888
+ return {
5889
+ event: combineOperationsIntoPack(recordsToSend[0].event, operations),
5890
+ sentEventIds: recordsToSend.map((record) => record.event.body.eventId)
5891
+ };
5892
+ }
5893
+ function getOperationsFromEventRecords(records) {
5894
+ return records.map((record) => ({
5895
+ ...record.event.body.operation,
5896
+ actualId: record.event.body.eventId
5897
+ }));
5898
+ }
5899
+ function combineOperationsIntoPack(baseEvent, operations) {
5900
+ const { operation, ...bodyWithoutOperation } = baseEvent.body;
5901
+ return {
5902
+ ...baseEvent,
5903
+ body: {
5904
+ ...bodyWithoutOperation,
5905
+ operations
5906
+ }
5907
+ };
5908
+ }
5909
+ var init_getUnpublishedEventFromList = __esm(() => {
5910
+ init_mergeRecords();
5911
+ });
5912
+
5913
+ // src/Events/mergeEvents.ts
5914
+ function mergeEvents(events) {
5915
+ if (events.length < 2) {
5916
+ return events;
5917
+ }
5918
+ const mergedEvents = [];
5919
+ let previous = null;
5920
+ for (const event of events) {
5921
+ if (!previous) {
5922
+ previous = event;
5923
+ continue;
5924
+ }
5925
+ const mergedOperation = mergeOperations(previous.body.operation, event.body.operation);
5926
+ if (!mergedOperation) {
5927
+ mergedEvents.push(previous);
5928
+ previous = event;
5929
+ } else {
5930
+ previous = {
5931
+ ...event,
5932
+ body: {
5933
+ ...event.body,
5934
+ operation: mergedOperation
5935
+ }
5936
+ };
5937
+ }
5938
+ }
5939
+ if (previous) {
5940
+ mergedEvents.push(previous);
5941
+ }
5942
+ return mergedEvents;
5943
+ }
5944
+ var init_mergeEvents = __esm(() => {
5945
+ init_Merge();
5946
+ });
5947
+
5851
5948
  // src/Events/Log/expandEvents.ts
5852
5949
  function expandEvents(events) {
5853
5950
  return events.flatMap((event) => {
@@ -6061,6 +6158,9 @@ class EventsLog {
6061
6158
  const events = expandEvents([event]);
6062
6159
  this.list.confirmSentRecords(events);
6063
6160
  }
6161
+ confirmSentLocalEventIds(eventIds, order) {
6162
+ this.list.confirmSentRecordIds(eventIds, order);
6163
+ }
6064
6164
  getUnorderedRecords() {
6065
6165
  return this.list.getRecordsToSend().concat(this.list.getNewRecords());
6066
6166
  }
@@ -6103,6 +6203,7 @@ var init_EventsLog = __esm(() => {
6103
6203
  init_createEventsList();
6104
6204
  init_getRedoRecordFromList();
6105
6205
  init_getUndoRecordFromList();
6206
+ init_getUnpublishedEventFromList();
6106
6207
  init_insertEventsFromOtherConnectionsIntoList();
6107
6208
  });
6108
6209
 
@@ -55382,25 +55483,16 @@ function handleBoardEventMessage(message, board) {
55382
55483
  if (event.order <= log.getLastIndex()) {
55383
55484
  return;
55384
55485
  }
55385
- const eventUserId = parseFloat(event.body.eventId.split(":")[0]);
55386
- const currentUserId = Number(localStorage.getItem("userId") || "0");
55387
- const isEventFromCurrentUser = eventUserId === currentUserId;
55486
+ const eventConnectionId = Number(event.body.eventId.split(":")[0]);
55487
+ const currentConnectionId = board.events.connection?.connectionId;
55488
+ const isEventFromCurrentUser = currentConnectionId !== undefined && eventConnectionId === currentConnectionId;
55388
55489
  if (isEventFromCurrentUser) {
55389
55490
  return;
55390
55491
  }
55391
55492
  if ("operations" in event.body) {
55392
- log.insertEventsFromOtherConnections({
55393
- ...event,
55394
- body: {
55395
- ...event.body,
55396
- userId: Number(message.userId)
55397
- }
55398
- });
55493
+ log.insertEventsFromOtherConnections(event);
55399
55494
  } else {
55400
- log.insertEventsFromOtherConnections({
55401
- ...event,
55402
- userId: Number(message.userId)
55403
- });
55495
+ log.insertEventsFromOtherConnections(event);
55404
55496
  }
55405
55497
  const last = log.getLastConfirmed();
55406
55498
  if (last) {
@@ -55452,11 +55544,11 @@ function tryPublishEvent(board) {
55452
55544
  if (log.pendingEvent) {
55453
55545
  return;
55454
55546
  }
55455
- const unpublishedEvent = log.getUnpublishedEvent();
55456
- if (!unpublishedEvent) {
55547
+ const unpublishedBatch = log.getUnpublishedEvent();
55548
+ if (!unpublishedBatch) {
55457
55549
  return;
55458
55550
  }
55459
- sendBoardEvent(board, unpublishedEvent, log.currentSequenceNumber);
55551
+ sendBoardEvent(board, unpublishedBatch, log.currentSequenceNumber);
55460
55552
  }
55461
55553
  function tryResendEvent(board) {
55462
55554
  const { log } = board.events;
@@ -55473,7 +55565,10 @@ function tryResendEvent(board) {
55473
55565
  board.presence.clear();
55474
55566
  conf.connection?.notifyAboutLostConnection();
55475
55567
  }
55476
- sendBoardEvent(board, log.pendingEvent.event, log.currentSequenceNumber);
55568
+ sendBoardEvent(board, {
55569
+ event: log.pendingEvent.event,
55570
+ sentEventIds: log.pendingEvent.sentEventIds
55571
+ }, log.currentSequenceNumber);
55477
55572
  }
55478
55573
  function handleSnapshotApplication(snapshot, board) {
55479
55574
  const { log } = board.events;
@@ -55498,8 +55593,9 @@ function handleBoardEventListApplication(events, board) {
55498
55593
  board.events.subject.publish(newEvents[0]);
55499
55594
  }
55500
55595
  }
55501
- function sendBoardEvent(board, event, sequenceNumber) {
55596
+ function sendBoardEvent(board, batch, sequenceNumber) {
55502
55597
  const { log } = board.events;
55598
+ const { event, sentEventIds } = batch;
55503
55599
  const toSend = {
55504
55600
  ...event,
55505
55601
  body: {
@@ -55517,6 +55613,7 @@ function sendBoardEvent(board, event, sequenceNumber) {
55517
55613
  const date = Date.now();
55518
55614
  log.pendingEvent = {
55519
55615
  event: toSend,
55616
+ sentEventIds,
55520
55617
  sequenceNumber,
55521
55618
  lastSentTime: date
55522
55619
  };
@@ -55564,7 +55661,7 @@ function handleConfirmation(msg, board) {
55564
55661
  conf.connection?.dismissNotificationAboutLostConnection();
55565
55662
  log.currentSequenceNumber++;
55566
55663
  log.pendingEvent.event.order = msg.order;
55567
- log.confirmSentLocalEvent(log.pendingEvent.event);
55664
+ log.confirmSentLocalEventIds(log.pendingEvent.sentEventIds, msg.order);
55568
55665
  board.subject.publish();
55569
55666
  log.pendingEvent = null;
55570
55667
  log.firstSentTime = null;