microboard-temp 0.13.44 → 0.13.46

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
 
@@ -55389,25 +55490,16 @@ function handleBoardEventMessage(message, board) {
55389
55490
  if (event.order <= log.getLastIndex()) {
55390
55491
  return;
55391
55492
  }
55392
- const eventUserId = parseFloat(event.body.eventId.split(":")[0]);
55393
- const currentUserId = Number(localStorage.getItem("userId") || "0");
55394
- 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;
55395
55496
  if (isEventFromCurrentUser) {
55396
55497
  return;
55397
55498
  }
55398
55499
  if ("operations" in event.body) {
55399
- log.insertEventsFromOtherConnections({
55400
- ...event,
55401
- body: {
55402
- ...event.body,
55403
- userId: Number(message.userId)
55404
- }
55405
- });
55500
+ log.insertEventsFromOtherConnections(event);
55406
55501
  } else {
55407
- log.insertEventsFromOtherConnections({
55408
- ...event,
55409
- userId: Number(message.userId)
55410
- });
55502
+ log.insertEventsFromOtherConnections(event);
55411
55503
  }
55412
55504
  const last = log.getLastConfirmed();
55413
55505
  if (last) {
@@ -55459,11 +55551,11 @@ function tryPublishEvent(board) {
55459
55551
  if (log.pendingEvent) {
55460
55552
  return;
55461
55553
  }
55462
- const unpublishedEvent = log.getUnpublishedEvent();
55463
- if (!unpublishedEvent) {
55554
+ const unpublishedBatch = log.getUnpublishedEvent();
55555
+ if (!unpublishedBatch) {
55464
55556
  return;
55465
55557
  }
55466
- sendBoardEvent(board, unpublishedEvent, log.currentSequenceNumber);
55558
+ sendBoardEvent(board, unpublishedBatch, log.currentSequenceNumber);
55467
55559
  }
55468
55560
  function tryResendEvent(board) {
55469
55561
  const { log } = board.events;
@@ -55480,7 +55572,10 @@ function tryResendEvent(board) {
55480
55572
  board.presence.clear();
55481
55573
  conf.connection?.notifyAboutLostConnection();
55482
55574
  }
55483
- sendBoardEvent(board, log.pendingEvent.event, log.currentSequenceNumber);
55575
+ sendBoardEvent(board, {
55576
+ event: log.pendingEvent.event,
55577
+ sentEventIds: log.pendingEvent.sentEventIds
55578
+ }, log.currentSequenceNumber);
55484
55579
  }
55485
55580
  function handleSnapshotApplication(snapshot, board) {
55486
55581
  const { log } = board.events;
@@ -55505,8 +55600,9 @@ function handleBoardEventListApplication(events, board) {
55505
55600
  board.events.subject.publish(newEvents[0]);
55506
55601
  }
55507
55602
  }
55508
- function sendBoardEvent(board, event, sequenceNumber) {
55603
+ function sendBoardEvent(board, batch, sequenceNumber) {
55509
55604
  const { log } = board.events;
55605
+ const { event, sentEventIds } = batch;
55510
55606
  const toSend = {
55511
55607
  ...event,
55512
55608
  body: {
@@ -55524,6 +55620,7 @@ function sendBoardEvent(board, event, sequenceNumber) {
55524
55620
  const date = Date.now();
55525
55621
  log.pendingEvent = {
55526
55622
  event: toSend,
55623
+ sentEventIds,
55527
55624
  sequenceNumber,
55528
55625
  lastSentTime: date
55529
55626
  };
@@ -55571,7 +55668,7 @@ function handleConfirmation(msg, board) {
55571
55668
  conf.connection?.dismissNotificationAboutLostConnection();
55572
55669
  log.currentSequenceNumber++;
55573
55670
  log.pendingEvent.event.order = msg.order;
55574
- log.confirmSentLocalEvent(log.pendingEvent.event);
55671
+ log.confirmSentLocalEventIds(log.pendingEvent.sentEventIds, msg.order);
55575
55672
  board.subject.publish();
55576
55673
  log.pendingEvent = null;
55577
55674
  log.firstSentTime = null;
@@ -60321,11 +60418,28 @@ class ForceGraphEngine {
60321
60418
  syncTimer = null;
60322
60419
  lastSyncedPositions = new Map;
60323
60420
  activeComponents = new Map;
60421
+ isPhysicsEmit = false;
60324
60422
  TICK_MS = 33;
60325
60423
  SYNC_MS = 300;
60326
60424
  MIN_MOVE_PX = 0.05;
60327
60425
  constructor(board) {
60328
60426
  this.board = board;
60427
+ board.events.subject.subscribe((event) => {
60428
+ if (this.isPhysicsEmit)
60429
+ return;
60430
+ const op = event.body?.operation;
60431
+ if (!op || op.class !== "Transformation" || op.method !== "applyMatrix")
60432
+ return;
60433
+ for (const { id, matrix } of op.items) {
60434
+ const last = this.lastSyncedPositions.get(id);
60435
+ if (last) {
60436
+ this.lastSyncedPositions.set(id, {
60437
+ x: last.x + matrix.translateX,
60438
+ y: last.y + matrix.translateY
60439
+ });
60440
+ }
60441
+ }
60442
+ });
60329
60443
  }
60330
60444
  enableForGraph(startNodeId) {
60331
60445
  if (this.isNodeInActiveGraph(startNodeId))
@@ -60553,8 +60667,8 @@ class ForceGraphEngine {
60553
60667
  }
60554
60668
  vel.vx = (vel.vx + (ax.get(id) ?? 0)) * conf.FG_DAMPING;
60555
60669
  vel.vy = (vel.vy + (ay.get(id) ?? 0)) * conf.FG_DAMPING;
60556
- totalEnergy += Math.abs(vel.vx) + Math.abs(vel.vy);
60557
60670
  if (Math.abs(vel.vx) >= this.MIN_MOVE_PX || Math.abs(vel.vy) >= this.MIN_MOVE_PX) {
60671
+ totalEnergy += Math.abs(vel.vx) + Math.abs(vel.vy);
60558
60672
  item.transformation.applyMatrixSilent({
60559
60673
  translateX: vel.vx,
60560
60674
  translateY: vel.vy,
@@ -60576,26 +60690,33 @@ class ForceGraphEngine {
60576
60690
  const nodes = this.getNodes().filter((item) => activeIds.has(item.getId()) && !draggedIds.has(item.getId()) && !(item.parent !== "Board" && draggedIds.has(item.parent)));
60577
60691
  if (nodes.length === 0)
60578
60692
  return;
60579
- const movedItems = nodes.map((item) => {
60693
+ const toSend = [];
60694
+ for (const item of nodes) {
60580
60695
  const id = item.getId();
60581
60696
  const pos = item.transformation.getTranslation();
60582
60697
  const last = this.lastSyncedPositions.get(id);
60583
60698
  const dx = last ? pos.x - last.x : 0;
60584
60699
  const dy = last ? pos.y - last.y : 0;
60585
- this.lastSyncedPositions.set(id, { x: pos.x, y: pos.y });
60586
- return { id, dx, dy };
60587
- }).filter(({ dx, dy }) => Math.abs(dx) > 0.5 || Math.abs(dy) > 0.5);
60588
- if (movedItems.length === 0)
60700
+ if (Math.abs(dx) > 0.5 || Math.abs(dy) > 0.5) {
60701
+ toSend.push({ id, dx, dy, x: pos.x, y: pos.y });
60702
+ }
60703
+ }
60704
+ if (toSend.length === 0)
60589
60705
  return;
60706
+ for (const { id, x, y } of toSend) {
60707
+ this.lastSyncedPositions.set(id, { x, y });
60708
+ }
60590
60709
  const operation = {
60591
60710
  class: "Transformation",
60592
60711
  method: "applyMatrix",
60593
- items: movedItems.map(({ id, dx, dy }) => ({
60712
+ items: toSend.map(({ id, dx, dy }) => ({
60594
60713
  id,
60595
60714
  matrix: { translateX: dx, translateY: dy, scaleX: 1, scaleY: 1, shearX: 0, shearY: 0 }
60596
60715
  }))
60597
60716
  };
60717
+ this.isPhysicsEmit = true;
60598
60718
  this.board.events.emit(operation);
60719
+ this.isPhysicsEmit = false;
60599
60720
  }
60600
60721
  }
60601
60722