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/esm/node.js CHANGED
@@ -4135,277 +4135,6 @@ var init_Color = __esm(() => {
4135
4135
  init_resolveColor();
4136
4136
  });
4137
4137
 
4138
- // src/Events/SyncLog.ts
4139
- function createSyncLog() {
4140
- const log = [];
4141
- const subject = new Subject;
4142
- log.push = function(...msgs) {
4143
- let newLength = log.length;
4144
- for (const msg of msgs) {
4145
- const lastItem = log[log.length - 1];
4146
- if (lastItem && lastItem.msg === msg.msg) {
4147
- lastItem.records = lastItem.records.concat(msg.records);
4148
- } else {
4149
- newLength = Array.prototype.push.call(log, msg);
4150
- }
4151
- }
4152
- subject.publish(log);
4153
- return newLength;
4154
- };
4155
- return {
4156
- log,
4157
- subject
4158
- };
4159
- }
4160
- var init_SyncLog = () => {};
4161
-
4162
- // src/Events/Log/createEventsList.ts
4163
- function createEventsList(commandFactory) {
4164
- const confirmedRecords = [];
4165
- const recordsToSend = [];
4166
- const newRecords = [];
4167
- const justConfirmed = [];
4168
- const { log: syncLog, subject: syncLogSubject } = createSyncLog();
4169
- let snapshotLastIndex = 0;
4170
- function revert(records) {
4171
- for (let i = records.length - 1;i >= 0; i--) {
4172
- records[i].command.revert();
4173
- }
4174
- }
4175
- function getOpItems(op) {
4176
- if ("item" in op) {
4177
- const item = op.item;
4178
- if (Array.isArray(item))
4179
- return item;
4180
- if (typeof item === "string")
4181
- return [item];
4182
- if (item && typeof item === "object")
4183
- return Object.keys(item);
4184
- }
4185
- if ("itemsMap" in op && op.itemsMap)
4186
- return Object.keys(op.itemsMap);
4187
- if ("items" in op) {
4188
- const items = op.items;
4189
- if (Array.isArray(items)) {
4190
- return items.map((i) => typeof i === "string" ? i : i.id).filter(Boolean);
4191
- }
4192
- if (items && typeof items === "object" && items !== null)
4193
- return Object.keys(items);
4194
- }
4195
- if ("itemsOps" in op) {
4196
- const itemsOps = op.itemsOps;
4197
- return itemsOps.map((io) => io.item);
4198
- }
4199
- return [];
4200
- }
4201
- return {
4202
- commandFactory,
4203
- addConfirmedRecords(records) {
4204
- confirmedRecords.push(...records);
4205
- syncLog.push({ msg: "confirmed", records });
4206
- },
4207
- addNewRecords(records) {
4208
- newRecords.push(...records);
4209
- syncLog.push({ msg: "addedNew", records });
4210
- },
4211
- confirmSentRecords(events) {
4212
- for (const event of events) {
4213
- const index = recordsToSend.findIndex((r) => r.event.body.eventId === event.body.eventId);
4214
- if (index !== -1) {
4215
- const [record] = recordsToSend.splice(index, 1);
4216
- confirmedRecords.push(record);
4217
- syncLog.push({ msg: "confirmed", records: [record] });
4218
- }
4219
- }
4220
- },
4221
- getConfirmedRecords() {
4222
- return confirmedRecords;
4223
- },
4224
- getRecordsToSend() {
4225
- return recordsToSend;
4226
- },
4227
- getNewRecords() {
4228
- return newRecords;
4229
- },
4230
- getAllRecords() {
4231
- return [...confirmedRecords, ...recordsToSend, ...newRecords];
4232
- },
4233
- prepareRecordsToSend() {
4234
- const records = [...newRecords];
4235
- recordsToSend.push(...records);
4236
- newRecords.length = 0;
4237
- syncLog.push({ msg: "toSend", records });
4238
- return records;
4239
- },
4240
- forwardIterable() {
4241
- return function* () {
4242
- yield* confirmedRecords;
4243
- yield* recordsToSend;
4244
- yield* newRecords;
4245
- }();
4246
- },
4247
- backwardIterable() {
4248
- return function* () {
4249
- for (let i = newRecords.length - 1;i >= 0; i--)
4250
- yield newRecords[i];
4251
- for (let i = recordsToSend.length - 1;i >= 0; i--)
4252
- yield recordsToSend[i];
4253
- for (let i = confirmedRecords.length - 1;i >= 0; i--)
4254
- yield confirmedRecords[i];
4255
- }();
4256
- },
4257
- revertUnconfirmed(predicate) {
4258
- const toRevert = [...recordsToSend, ...newRecords].filter(predicate || (() => true));
4259
- revert(toRevert);
4260
- syncLog.push({ msg: "revertUnconfirmed", records: toRevert });
4261
- },
4262
- applyUnconfirmed(predicate) {
4263
- const unconfirmed = [...recordsToSend, ...newRecords].filter(predicate || (() => true));
4264
- for (const record of unconfirmed) {
4265
- record.command.apply();
4266
- }
4267
- syncLog.push({ msg: "applyUnconfirmed", records: unconfirmed });
4268
- },
4269
- justConfirmed,
4270
- getSyncLog() {
4271
- return syncLog;
4272
- },
4273
- syncLogSubject,
4274
- clear() {
4275
- confirmedRecords.length = 0;
4276
- recordsToSend.length = 0;
4277
- newRecords.length = 0;
4278
- syncLog.length = 0;
4279
- syncLogSubject.publish(syncLog);
4280
- },
4281
- clearConfirmedRecords() {
4282
- confirmedRecords.length = 0;
4283
- syncLog.length = 0;
4284
- syncLogSubject.publish(syncLog);
4285
- },
4286
- removeUnconfirmedEventsByItems(itemIds) {
4287
- const itemIdSet = new Set(itemIds);
4288
- const filter = (record) => {
4289
- const opItems = getOpItems(record.event.body.operation);
4290
- return !opItems.some((id) => itemIdSet.has(id));
4291
- };
4292
- const filteredNewRecords = newRecords.filter(filter);
4293
- newRecords.length = 0;
4294
- newRecords.push(...filteredNewRecords);
4295
- const filteredRecordsToSend = recordsToSend.filter(filter);
4296
- recordsToSend.length = 0;
4297
- recordsToSend.push(...filteredRecordsToSend);
4298
- syncLog.length = 0;
4299
- syncLog.push({ msg: "confirmed", records: confirmedRecords });
4300
- syncLog.push({ msg: "toSend", records: recordsToSend });
4301
- syncLog.push({ msg: "addedNew", records: newRecords });
4302
- syncLogSubject.publish(syncLog);
4303
- },
4304
- isAllEventsConfirmed() {
4305
- return recordsToSend.length === 0 && newRecords.length === 0;
4306
- },
4307
- setSnapshotLastIndex(index) {
4308
- snapshotLastIndex = index;
4309
- },
4310
- getSnapshotLastIndex() {
4311
- return snapshotLastIndex;
4312
- }
4313
- };
4314
- }
4315
- var init_createEventsList = __esm(() => {
4316
- init_SyncLog();
4317
- });
4318
-
4319
- // src/Events/Log/getRecordByIdFromList.ts
4320
- function getRecordByIdFromList(id, list) {
4321
- for (const record of list.forwardIterable()) {
4322
- if (record.event.body.eventId === id) {
4323
- return record;
4324
- }
4325
- }
4326
- return;
4327
- }
4328
-
4329
- // src/Events/Log/shouldSkipEvent.ts
4330
- function shouldSkipEvent(record, userId) {
4331
- const { operation } = record.event.body;
4332
- return record.event.body.userId !== userId || operation.method === "updateVideoData" || operation.class === "Audio" && operation.method === "setUrl";
4333
- }
4334
-
4335
- // src/Events/Log/getRedoRecordFromList.ts
4336
- function getRedoRecordFromList(userId, list) {
4337
- let counter = 0;
4338
- for (const record of list.backwardIterable()) {
4339
- if (shouldSkipEvent(record, userId)) {
4340
- continue;
4341
- }
4342
- if (record.event.body.operation.method !== "undo" && record.event.body.operation.method !== "redo") {
4343
- return null;
4344
- }
4345
- const { method } = record.event.body.operation;
4346
- if (method === "redo") {
4347
- counter++;
4348
- } else if (method === "undo") {
4349
- if (counter > 0) {
4350
- counter--;
4351
- } else if (counter === 0) {
4352
- return record;
4353
- }
4354
- }
4355
- }
4356
- return null;
4357
- }
4358
- var init_getRedoRecordFromList = () => {};
4359
-
4360
- // src/Events/Log/getUndoRecordFromList.ts
4361
- function getUndoRecordFromList(userId, list) {
4362
- let counter = 0;
4363
- const isAllEventsConfirmed = list.isAllEventsConfirmed();
4364
- if (!isAllEventsConfirmed) {
4365
- return null;
4366
- }
4367
- for (const record of list.getConfirmedRecords().slice().reverse()) {
4368
- if (shouldSkipEvent(record, userId)) {
4369
- continue;
4370
- }
4371
- if (record.event.body.operation.method === "undo") {
4372
- counter++;
4373
- } else if (counter === 0) {
4374
- return record;
4375
- } else {
4376
- counter--;
4377
- }
4378
- }
4379
- return null;
4380
- }
4381
- var init_getUndoRecordFromList = () => {};
4382
-
4383
- // src/Events/Log/getUnpublishedEventFromList.ts
4384
- function getUnpublishedEventFromList(list) {
4385
- const recordsToSend = list.prepareRecordsToSend();
4386
- if (recordsToSend.length === 0) {
4387
- return null;
4388
- }
4389
- const operations = getOperationsFromEventRecords(recordsToSend);
4390
- return combineOperationsIntoPack(recordsToSend[0].event, operations);
4391
- }
4392
- function getOperationsFromEventRecords(records) {
4393
- return records.map((record) => ({
4394
- ...record.event.body.operation,
4395
- actualId: record.event.body.eventId
4396
- }));
4397
- }
4398
- function combineOperationsIntoPack(baseEvent, operations) {
4399
- const { operation, ...bodyWithoutOperation } = baseEvent.body;
4400
- return {
4401
- ...baseEvent,
4402
- body: {
4403
- ...bodyWithoutOperation,
4404
- operations
4405
- }
4406
- };
4407
- }
4408
-
4409
4138
  // src/Events/EventsOperations.ts
4410
4139
  function isTransformation(op) {
4411
4140
  return op.class === "Transformation";
@@ -4732,41 +4461,69 @@ function mergeBoardOperations(opA, opB) {
4732
4461
  }
4733
4462
  var init_Merge = () => {};
4734
4463
 
4735
- // src/Events/mergeEvents.ts
4736
- function mergeEvents(events) {
4737
- if (events.length < 2) {
4738
- return events;
4464
+ // src/Events/mergeRecords.ts
4465
+ function mergeRecords(records) {
4466
+ if (records.length < 2) {
4467
+ return records;
4739
4468
  }
4740
- const mergedEvents = [];
4469
+ const mergedRecords = [];
4741
4470
  let previous = null;
4742
- for (const event of events) {
4471
+ for (const record of records) {
4743
4472
  if (!previous) {
4744
- previous = event;
4473
+ previous = record;
4745
4474
  continue;
4746
4475
  }
4747
- const mergedOperation = mergeOperations(previous.body.operation, event.body.operation);
4748
- if (!mergedOperation) {
4749
- mergedEvents.push(previous);
4750
- previous = event;
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
- ...event,
4754
- body: {
4755
- ...event.body,
4756
- operation: mergedOperation
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
- mergedEvents.push(previous);
4495
+ mergedRecords.push(previous);
4763
4496
  }
4764
- return mergedEvents;
4497
+ return mergedRecords;
4765
4498
  }
4766
- var init_mergeEvents = __esm(() => {
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
  import { Path as Path2 } from "slate";
4772
4529
  function removeText_removeText(confirmed, toTransform) {
@@ -5850,6 +5607,346 @@ var init_transformEvents = __esm(() => {
5850
5607
  init_Transform2();
5851
5608
  });
5852
5609
 
5610
+ // src/Events/Log/createEventsList.ts
5611
+ function createEventsList(commandFactory) {
5612
+ const confirmedRecords = [];
5613
+ const recordsToSend = [];
5614
+ const newRecords = [];
5615
+ const justConfirmed = [];
5616
+ const { log: syncLog, subject: syncLogSubject } = createSyncLog();
5617
+ let snapshotLastIndex = 0;
5618
+ function revert(records) {
5619
+ for (let i = records.length - 1;i >= 0; i--) {
5620
+ records[i].command.revert();
5621
+ }
5622
+ }
5623
+ function apply(records) {
5624
+ for (const record of records) {
5625
+ record.command = commandFactory(record.event.body.operation);
5626
+ record.command.apply();
5627
+ }
5628
+ }
5629
+ function mergeAndPushConfirmedRecords(records) {
5630
+ const lastConfirmedRecord = confirmedRecords.pop();
5631
+ const recordsToMerge = lastConfirmedRecord ? [lastConfirmedRecord, ...records] : records;
5632
+ const mergedRecords = mergeRecords(recordsToMerge);
5633
+ confirmedRecords.push(...mergedRecords);
5634
+ }
5635
+ return {
5636
+ commandFactory,
5637
+ addConfirmedRecords(records) {
5638
+ syncLog.push({ msg: "confirmed", records });
5639
+ mergeAndPushConfirmedRecords(records);
5640
+ },
5641
+ addNewRecords(records) {
5642
+ for (const record of records) {
5643
+ if (newRecords.length > 0) {
5644
+ const lastRecord = newRecords[newRecords.length - 1];
5645
+ const mergedOperation = mergeOperations(lastRecord.event.body.operation, record.event.body.operation);
5646
+ if (mergedOperation) {
5647
+ lastRecord.event = {
5648
+ ...lastRecord.event,
5649
+ body: {
5650
+ ...lastRecord.event.body,
5651
+ operation: mergedOperation
5652
+ }
5653
+ };
5654
+ lastRecord.command = commandFactory(mergedOperation);
5655
+ continue;
5656
+ }
5657
+ }
5658
+ newRecords.push(record);
5659
+ syncLog.push({ msg: "addedNew", records: [record] });
5660
+ }
5661
+ },
5662
+ confirmSentRecords(events) {
5663
+ const records = recordsToSend;
5664
+ if (records.length !== events.length) {
5665
+ console.error("Mismatch between records and events length");
5666
+ return;
5667
+ }
5668
+ for (let i = 0;i < records.length; i++) {
5669
+ records[i].event.order = events[i].order;
5670
+ }
5671
+ syncLog.push({ msg: "confirmed", records: [...records] });
5672
+ mergeAndPushConfirmedRecords(records);
5673
+ recordsToSend.splice(0, records.length);
5674
+ },
5675
+ confirmSentRecordIds(eventIds, order) {
5676
+ const confirmedRecordsById = [];
5677
+ for (const eventId of eventIds) {
5678
+ const index = recordsToSend.findIndex((record2) => record2.event.body.eventId === eventId);
5679
+ if (index === -1) {
5680
+ continue;
5681
+ }
5682
+ const [record] = recordsToSend.splice(index, 1);
5683
+ record.event.order = order;
5684
+ confirmedRecordsById.push(record);
5685
+ }
5686
+ if (confirmedRecordsById.length === 0) {
5687
+ return;
5688
+ }
5689
+ syncLog.push({ msg: "confirmed", records: confirmedRecordsById });
5690
+ mergeAndPushConfirmedRecords(confirmedRecordsById);
5691
+ },
5692
+ getConfirmedRecords() {
5693
+ return confirmedRecords;
5694
+ },
5695
+ getRecordsToSend() {
5696
+ return recordsToSend;
5697
+ },
5698
+ getNewRecords() {
5699
+ return newRecords;
5700
+ },
5701
+ getAllRecords() {
5702
+ return [...confirmedRecords, ...recordsToSend, ...newRecords];
5703
+ },
5704
+ prepareRecordsToSend() {
5705
+ if (recordsToSend.length === 0 && newRecords.length > 0) {
5706
+ const records = [...newRecords];
5707
+ recordsToSend.push(...records);
5708
+ newRecords.length = 0;
5709
+ syncLog.push({ msg: "toSend", records });
5710
+ }
5711
+ return recordsToSend;
5712
+ },
5713
+ forwardIterable() {
5714
+ return function* () {
5715
+ yield* confirmedRecords;
5716
+ yield* recordsToSend;
5717
+ yield* newRecords;
5718
+ }();
5719
+ },
5720
+ backwardIterable() {
5721
+ return function* () {
5722
+ for (let i = newRecords.length - 1;i >= 0; i--)
5723
+ yield newRecords[i];
5724
+ for (let i = recordsToSend.length - 1;i >= 0; i--)
5725
+ yield recordsToSend[i];
5726
+ for (let i = confirmedRecords.length - 1;i >= 0; i--)
5727
+ yield confirmedRecords[i];
5728
+ }();
5729
+ },
5730
+ revertUnconfirmed(predicate) {
5731
+ const toRevert = [...recordsToSend, ...newRecords].filter(predicate || (() => true));
5732
+ revert(toRevert);
5733
+ syncLog.push({ msg: "revertUnconfirmed", records: toRevert });
5734
+ },
5735
+ applyUnconfirmed(predicate) {
5736
+ const filter = predicate || (() => true);
5737
+ if (justConfirmed.length > 0) {
5738
+ const confirmedEvents = justConfirmed.map((record) => record.event);
5739
+ const transformedSend = transformEvents(confirmedEvents, recordsToSend.map((record) => record.event));
5740
+ const transformedNew = transformEvents(confirmedEvents, newRecords.map((record) => record.event));
5741
+ const updatedRecordsToSend = transformedSend.map((event) => ({
5742
+ event,
5743
+ command: commandFactory(event.body.operation)
5744
+ }));
5745
+ const updatedNewRecords = transformedNew.map((event) => ({
5746
+ event,
5747
+ command: commandFactory(event.body.operation)
5748
+ }));
5749
+ recordsToSend.length = 0;
5750
+ recordsToSend.push(...updatedRecordsToSend);
5751
+ newRecords.length = 0;
5752
+ newRecords.push(...updatedNewRecords);
5753
+ justConfirmed.length = 0;
5754
+ }
5755
+ const unconfirmed = [...recordsToSend, ...newRecords].filter(filter);
5756
+ apply(unconfirmed);
5757
+ syncLog.push({ msg: "applyUnconfirmed", records: unconfirmed });
5758
+ },
5759
+ justConfirmed,
5760
+ getSyncLog() {
5761
+ return syncLog;
5762
+ },
5763
+ syncLogSubject,
5764
+ clear() {
5765
+ confirmedRecords.length = 0;
5766
+ recordsToSend.length = 0;
5767
+ newRecords.length = 0;
5768
+ syncLog.length = 0;
5769
+ syncLogSubject.publish(syncLog);
5770
+ },
5771
+ clearConfirmedRecords() {
5772
+ confirmedRecords.length = 0;
5773
+ syncLog.length = 0;
5774
+ syncLogSubject.publish(syncLog);
5775
+ },
5776
+ removeUnconfirmedEventsByItems(itemIds) {
5777
+ function shouldRemoveEvent(operation, ids) {
5778
+ if (operation.method === "add" && operation.class === "Board") {
5779
+ if (Array.isArray(operation.item)) {
5780
+ return operation.item.some((id) => ids.includes(id));
5781
+ }
5782
+ return ids.includes(operation.item);
5783
+ }
5784
+ if (operation.method === "remove" && operation.class === "Board") {
5785
+ return operation.item.some((id) => ids.includes(id));
5786
+ }
5787
+ return false;
5788
+ }
5789
+ const nextRecordsToSend = recordsToSend.filter((record) => !shouldRemoveEvent(record.event.body.operation, itemIds));
5790
+ if (nextRecordsToSend.length !== recordsToSend.length) {
5791
+ recordsToSend.length = 0;
5792
+ recordsToSend.push(...nextRecordsToSend);
5793
+ }
5794
+ const nextNewRecords = newRecords.filter((record) => !shouldRemoveEvent(record.event.body.operation, itemIds));
5795
+ if (nextNewRecords.length !== newRecords.length) {
5796
+ newRecords.length = 0;
5797
+ newRecords.push(...nextNewRecords);
5798
+ }
5799
+ },
5800
+ isAllEventsConfirmed() {
5801
+ return recordsToSend.length === 0 && newRecords.length === 0;
5802
+ },
5803
+ setSnapshotLastIndex(index) {
5804
+ snapshotLastIndex = index;
5805
+ },
5806
+ getSnapshotLastIndex() {
5807
+ return snapshotLastIndex;
5808
+ }
5809
+ };
5810
+ }
5811
+ var init_createEventsList = __esm(() => {
5812
+ init_Merge();
5813
+ init_mergeRecords();
5814
+ init_SyncLog();
5815
+ init_transformEvents();
5816
+ });
5817
+
5818
+ // src/Events/Log/getRecordByIdFromList.ts
5819
+ function getRecordByIdFromList(id, list) {
5820
+ for (const record of list.forwardIterable()) {
5821
+ if (record.event.body.eventId === id) {
5822
+ return record;
5823
+ }
5824
+ }
5825
+ return;
5826
+ }
5827
+
5828
+ // src/Events/Log/shouldSkipEvent.ts
5829
+ function shouldSkipEvent(record, userId) {
5830
+ const { operation } = record.event.body;
5831
+ return record.event.body.userId !== userId || operation.method === "updateVideoData" || operation.class === "Audio" && operation.method === "setUrl";
5832
+ }
5833
+
5834
+ // src/Events/Log/getRedoRecordFromList.ts
5835
+ function getRedoRecordFromList(userId, list) {
5836
+ let counter = 0;
5837
+ for (const record of list.backwardIterable()) {
5838
+ if (shouldSkipEvent(record, userId)) {
5839
+ continue;
5840
+ }
5841
+ if (record.event.body.operation.method !== "undo" && record.event.body.operation.method !== "redo") {
5842
+ return null;
5843
+ }
5844
+ const { method } = record.event.body.operation;
5845
+ if (method === "redo") {
5846
+ counter++;
5847
+ } else if (method === "undo") {
5848
+ if (counter > 0) {
5849
+ counter--;
5850
+ } else if (counter === 0) {
5851
+ return record;
5852
+ }
5853
+ }
5854
+ }
5855
+ return null;
5856
+ }
5857
+ var init_getRedoRecordFromList = () => {};
5858
+
5859
+ // src/Events/Log/getUndoRecordFromList.ts
5860
+ function getUndoRecordFromList(userId, list) {
5861
+ let counter = 0;
5862
+ const isAllEventsConfirmed = list.isAllEventsConfirmed();
5863
+ if (!isAllEventsConfirmed) {
5864
+ return null;
5865
+ }
5866
+ for (const record of list.getConfirmedRecords().slice().reverse()) {
5867
+ if (shouldSkipEvent(record, userId)) {
5868
+ continue;
5869
+ }
5870
+ if (record.event.body.operation.method === "undo") {
5871
+ counter++;
5872
+ } else if (counter === 0) {
5873
+ return record;
5874
+ } else {
5875
+ counter--;
5876
+ }
5877
+ }
5878
+ return null;
5879
+ }
5880
+ var init_getUndoRecordFromList = () => {};
5881
+
5882
+ // src/Events/Log/getUnpublishedEventFromList.ts
5883
+ function getUnpublishedEventFromList(list) {
5884
+ const recordsToSend = list.prepareRecordsToSend();
5885
+ if (recordsToSend.length === 0) {
5886
+ return null;
5887
+ }
5888
+ const mergedRecords = mergeRecords(recordsToSend);
5889
+ const operations = getOperationsFromEventRecords(mergedRecords);
5890
+ return {
5891
+ event: combineOperationsIntoPack(recordsToSend[0].event, operations),
5892
+ sentEventIds: recordsToSend.map((record) => record.event.body.eventId)
5893
+ };
5894
+ }
5895
+ function getOperationsFromEventRecords(records) {
5896
+ return records.map((record) => ({
5897
+ ...record.event.body.operation,
5898
+ actualId: record.event.body.eventId
5899
+ }));
5900
+ }
5901
+ function combineOperationsIntoPack(baseEvent, operations) {
5902
+ const { operation, ...bodyWithoutOperation } = baseEvent.body;
5903
+ return {
5904
+ ...baseEvent,
5905
+ body: {
5906
+ ...bodyWithoutOperation,
5907
+ operations
5908
+ }
5909
+ };
5910
+ }
5911
+ var init_getUnpublishedEventFromList = __esm(() => {
5912
+ init_mergeRecords();
5913
+ });
5914
+
5915
+ // src/Events/mergeEvents.ts
5916
+ function mergeEvents(events) {
5917
+ if (events.length < 2) {
5918
+ return events;
5919
+ }
5920
+ const mergedEvents = [];
5921
+ let previous = null;
5922
+ for (const event of events) {
5923
+ if (!previous) {
5924
+ previous = event;
5925
+ continue;
5926
+ }
5927
+ const mergedOperation = mergeOperations(previous.body.operation, event.body.operation);
5928
+ if (!mergedOperation) {
5929
+ mergedEvents.push(previous);
5930
+ previous = event;
5931
+ } else {
5932
+ previous = {
5933
+ ...event,
5934
+ body: {
5935
+ ...event.body,
5936
+ operation: mergedOperation
5937
+ }
5938
+ };
5939
+ }
5940
+ }
5941
+ if (previous) {
5942
+ mergedEvents.push(previous);
5943
+ }
5944
+ return mergedEvents;
5945
+ }
5946
+ var init_mergeEvents = __esm(() => {
5947
+ init_Merge();
5948
+ });
5949
+
5853
5950
  // src/Events/Log/expandEvents.ts
5854
5951
  function expandEvents(events) {
5855
5952
  return events.flatMap((event) => {
@@ -6063,6 +6160,9 @@ class EventsLog {
6063
6160
  const events = expandEvents([event]);
6064
6161
  this.list.confirmSentRecords(events);
6065
6162
  }
6163
+ confirmSentLocalEventIds(eventIds, order) {
6164
+ this.list.confirmSentRecordIds(eventIds, order);
6165
+ }
6066
6166
  getUnorderedRecords() {
6067
6167
  return this.list.getRecordsToSend().concat(this.list.getNewRecords());
6068
6168
  }
@@ -6105,6 +6205,7 @@ var init_EventsLog = __esm(() => {
6105
6205
  init_createEventsList();
6106
6206
  init_getRedoRecordFromList();
6107
6207
  init_getUndoRecordFromList();
6208
+ init_getUnpublishedEventFromList();
6108
6209
  init_insertEventsFromOtherConnectionsIntoList();
6109
6210
  });
6110
6211
 
@@ -12052,6 +12153,9 @@ class SpatialIndex {
12052
12153
  this.Mbr = new Mbr;
12053
12154
  }
12054
12155
  insert(item) {
12156
+ if (this.itemsArray.includes(item) || this.getById(item.getId())) {
12157
+ return;
12158
+ }
12055
12159
  this.itemsArray.push(item);
12056
12160
  this.itemsIndex.insert(item);
12057
12161
  if (conf.isNode()) {
@@ -12649,6 +12753,9 @@ class SimpleSpatialIndex {
12649
12753
  this.Mbr = new Mbr;
12650
12754
  }
12651
12755
  insert(item) {
12756
+ if (this.itemsArray.includes(item) || this.getById(item.getId())) {
12757
+ return;
12758
+ }
12652
12759
  this.itemsArray.push(item);
12653
12760
  if (this.Mbr.getWidth() === 0 && this.Mbr.getHeight() === 0) {
12654
12761
  this.Mbr = item.getMbr().copy();
@@ -13075,7 +13182,10 @@ var init_BaseItem = __esm(() => {
13075
13182
  if (this.parent !== childId && this.getId() !== childId && !this.hasAncestor(childId)) {
13076
13183
  if (!this.index?.getById(childId) && foundItem) {
13077
13184
  const localMatrix = foundItem.transformation.toMatrix().toLocalOf(containerNestingMatrix);
13078
- this.board.items.index.remove(foundItem, true);
13185
+ const currentParentId = foundItem.parent;
13186
+ const currentParent = currentParentId !== "Board" ? this.board.items.getById(currentParentId) : undefined;
13187
+ const sourceIndex = currentParent?.index || this.board.items.index;
13188
+ sourceIndex.remove(foundItem, true);
13079
13189
  foundItem.parent = this.getId();
13080
13190
  foundItem.onParentChanged(this.getId());
13081
13191
  foundItem.transformation.setLocalMatrix(localMatrix);
@@ -16737,7 +16847,7 @@ var init_getListTypeAtSelectionStart = __esm(() => {
16737
16847
  });
16738
16848
 
16739
16849
  // src/Items/RichText/editorHelpers/links/setLink.ts
16740
- import { Editor as Editor11, Transforms as Transforms10 } from "slate";
16850
+ import { Editor as Editor11, Transforms as Transforms10, Text as Text6 } from "slate";
16741
16851
  var setLink = (editor, link, selection) => {
16742
16852
  if (!selection) {
16743
16853
  selectWholeText(editor);
@@ -16749,15 +16859,15 @@ var setLink = (editor, link, selection) => {
16749
16859
  }
16750
16860
  const format = link ? "rgba(71, 120, 245, 1)" : "rgb(20, 21, 26)";
16751
16861
  Transforms10.setNodes(editor, { fontColor: format }, {
16752
- match: (n) => !Editor11.isEditor(n) && n.type === "text",
16862
+ match: (n) => Text6.isText(n),
16753
16863
  split: true
16754
16864
  });
16755
- for (const [node, path2] of Editor11.nodes(editor, {
16756
- match: (n) => !Editor11.isEditor(n) && n.type === "text"
16865
+ for (const [, path2] of Editor11.nodes(editor, {
16866
+ match: (n) => Text6.isText(n)
16757
16867
  })) {
16758
16868
  const nodeRange = Editor11.range(editor, path2);
16759
16869
  Transforms10.select(editor, nodeRange);
16760
- Transforms10.setNodes(editor, { link }, { split: false, match: (n) => !Editor11.isEditor(n) && n.type === "text" });
16870
+ Transforms10.setNodes(editor, { link }, { split: false, match: (n) => Text6.isText(n) });
16761
16871
  }
16762
16872
  };
16763
16873
  var init_setLink = __esm(() => {
@@ -27441,7 +27551,7 @@ var init_setEditorFocus = () => {};
27441
27551
  import {
27442
27552
  Editor as Editor30,
27443
27553
  Element as Element9,
27444
- Text as Text6,
27554
+ Text as Text7,
27445
27555
  Transforms as Transforms20
27446
27556
  } from "slate";
27447
27557
  var isEditInProcessValue = false, counter = 0, RichText;
@@ -28009,7 +28119,7 @@ var init_RichText = __esm(() => {
28009
28119
  }
28010
28120
  getMinFontSize() {
28011
28121
  const textNodes = Editor30.nodes(this.editor.editor, {
28012
- match: (n) => Text6.isText(n),
28122
+ match: (n) => Text7.isText(n),
28013
28123
  at: []
28014
28124
  });
28015
28125
  const fontSizes = [];
@@ -57782,25 +57892,16 @@ function handleBoardEventMessage(message, board) {
57782
57892
  if (event.order <= log.getLastIndex()) {
57783
57893
  return;
57784
57894
  }
57785
- const eventUserId = parseFloat(event.body.eventId.split(":")[0]);
57786
- const currentUserId = Number(localStorage.getItem("userId") || "0");
57787
- const isEventFromCurrentUser = eventUserId === currentUserId;
57895
+ const eventConnectionId = Number(event.body.eventId.split(":")[0]);
57896
+ const currentConnectionId = board.events.connection?.connectionId;
57897
+ const isEventFromCurrentUser = currentConnectionId !== undefined && eventConnectionId === currentConnectionId;
57788
57898
  if (isEventFromCurrentUser) {
57789
57899
  return;
57790
57900
  }
57791
57901
  if ("operations" in event.body) {
57792
- log.insertEventsFromOtherConnections({
57793
- ...event,
57794
- body: {
57795
- ...event.body,
57796
- userId: Number(message.userId)
57797
- }
57798
- });
57902
+ log.insertEventsFromOtherConnections(event);
57799
57903
  } else {
57800
- log.insertEventsFromOtherConnections({
57801
- ...event,
57802
- userId: Number(message.userId)
57803
- });
57904
+ log.insertEventsFromOtherConnections(event);
57804
57905
  }
57805
57906
  const last = log.getLastConfirmed();
57806
57907
  if (last) {
@@ -57852,11 +57953,11 @@ function tryPublishEvent(board) {
57852
57953
  if (log.pendingEvent) {
57853
57954
  return;
57854
57955
  }
57855
- const unpublishedEvent = log.getUnpublishedEvent();
57856
- if (!unpublishedEvent) {
57956
+ const unpublishedBatch = log.getUnpublishedEvent();
57957
+ if (!unpublishedBatch) {
57857
57958
  return;
57858
57959
  }
57859
- sendBoardEvent(board, unpublishedEvent, log.currentSequenceNumber);
57960
+ sendBoardEvent(board, unpublishedBatch, log.currentSequenceNumber);
57860
57961
  }
57861
57962
  function tryResendEvent(board) {
57862
57963
  const { log } = board.events;
@@ -57873,7 +57974,10 @@ function tryResendEvent(board) {
57873
57974
  board.presence.clear();
57874
57975
  conf.connection?.notifyAboutLostConnection();
57875
57976
  }
57876
- sendBoardEvent(board, log.pendingEvent.event, log.currentSequenceNumber);
57977
+ sendBoardEvent(board, {
57978
+ event: log.pendingEvent.event,
57979
+ sentEventIds: log.pendingEvent.sentEventIds
57980
+ }, log.currentSequenceNumber);
57877
57981
  }
57878
57982
  function handleSnapshotApplication(snapshot, board) {
57879
57983
  const { log } = board.events;
@@ -57898,8 +58002,9 @@ function handleBoardEventListApplication(events, board) {
57898
58002
  board.events.subject.publish(newEvents[0]);
57899
58003
  }
57900
58004
  }
57901
- function sendBoardEvent(board, event, sequenceNumber) {
58005
+ function sendBoardEvent(board, batch, sequenceNumber) {
57902
58006
  const { log } = board.events;
58007
+ const { event, sentEventIds } = batch;
57903
58008
  const toSend = {
57904
58009
  ...event,
57905
58010
  body: {
@@ -57917,6 +58022,7 @@ function sendBoardEvent(board, event, sequenceNumber) {
57917
58022
  const date = Date.now();
57918
58023
  log.pendingEvent = {
57919
58024
  event: toSend,
58025
+ sentEventIds,
57920
58026
  sequenceNumber,
57921
58027
  lastSentTime: date
57922
58028
  };
@@ -57964,7 +58070,7 @@ function handleConfirmation(msg, board) {
57964
58070
  conf.connection?.dismissNotificationAboutLostConnection();
57965
58071
  log.currentSequenceNumber++;
57966
58072
  log.pendingEvent.event.order = msg.order;
57967
- log.confirmSentLocalEvent(log.pendingEvent.event);
58073
+ log.confirmSentLocalEventIds(log.pendingEvent.sentEventIds, msg.order);
57968
58074
  board.subject.publish();
57969
58075
  log.pendingEvent = null;
57970
58076
  log.firstSentTime = null;