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.
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
 
@@ -57791,25 +57892,16 @@ function handleBoardEventMessage(message, board) {
57791
57892
  if (event.order <= log.getLastIndex()) {
57792
57893
  return;
57793
57894
  }
57794
- const eventUserId = parseFloat(event.body.eventId.split(":")[0]);
57795
- const currentUserId = Number(localStorage.getItem("userId") || "0");
57796
- 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;
57797
57898
  if (isEventFromCurrentUser) {
57798
57899
  return;
57799
57900
  }
57800
57901
  if ("operations" in event.body) {
57801
- log.insertEventsFromOtherConnections({
57802
- ...event,
57803
- body: {
57804
- ...event.body,
57805
- userId: Number(message.userId)
57806
- }
57807
- });
57902
+ log.insertEventsFromOtherConnections(event);
57808
57903
  } else {
57809
- log.insertEventsFromOtherConnections({
57810
- ...event,
57811
- userId: Number(message.userId)
57812
- });
57904
+ log.insertEventsFromOtherConnections(event);
57813
57905
  }
57814
57906
  const last = log.getLastConfirmed();
57815
57907
  if (last) {
@@ -57861,11 +57953,11 @@ function tryPublishEvent(board) {
57861
57953
  if (log.pendingEvent) {
57862
57954
  return;
57863
57955
  }
57864
- const unpublishedEvent = log.getUnpublishedEvent();
57865
- if (!unpublishedEvent) {
57956
+ const unpublishedBatch = log.getUnpublishedEvent();
57957
+ if (!unpublishedBatch) {
57866
57958
  return;
57867
57959
  }
57868
- sendBoardEvent(board, unpublishedEvent, log.currentSequenceNumber);
57960
+ sendBoardEvent(board, unpublishedBatch, log.currentSequenceNumber);
57869
57961
  }
57870
57962
  function tryResendEvent(board) {
57871
57963
  const { log } = board.events;
@@ -57882,7 +57974,10 @@ function tryResendEvent(board) {
57882
57974
  board.presence.clear();
57883
57975
  conf.connection?.notifyAboutLostConnection();
57884
57976
  }
57885
- sendBoardEvent(board, log.pendingEvent.event, log.currentSequenceNumber);
57977
+ sendBoardEvent(board, {
57978
+ event: log.pendingEvent.event,
57979
+ sentEventIds: log.pendingEvent.sentEventIds
57980
+ }, log.currentSequenceNumber);
57886
57981
  }
57887
57982
  function handleSnapshotApplication(snapshot, board) {
57888
57983
  const { log } = board.events;
@@ -57907,8 +58002,9 @@ function handleBoardEventListApplication(events, board) {
57907
58002
  board.events.subject.publish(newEvents[0]);
57908
58003
  }
57909
58004
  }
57910
- function sendBoardEvent(board, event, sequenceNumber) {
58005
+ function sendBoardEvent(board, batch, sequenceNumber) {
57911
58006
  const { log } = board.events;
58007
+ const { event, sentEventIds } = batch;
57912
58008
  const toSend = {
57913
58009
  ...event,
57914
58010
  body: {
@@ -57926,6 +58022,7 @@ function sendBoardEvent(board, event, sequenceNumber) {
57926
58022
  const date = Date.now();
57927
58023
  log.pendingEvent = {
57928
58024
  event: toSend,
58025
+ sentEventIds,
57929
58026
  sequenceNumber,
57930
58027
  lastSentTime: date
57931
58028
  };
@@ -57973,7 +58070,7 @@ function handleConfirmation(msg, board) {
57973
58070
  conf.connection?.dismissNotificationAboutLostConnection();
57974
58071
  log.currentSequenceNumber++;
57975
58072
  log.pendingEvent.event.order = msg.order;
57976
- log.confirmSentLocalEvent(log.pendingEvent.event);
58073
+ log.confirmSentLocalEventIds(log.pendingEvent.sentEventIds, msg.order);
57977
58074
  board.subject.publish();
57978
58075
  log.pendingEvent = null;
57979
58076
  log.firstSentTime = null;
@@ -62778,11 +62875,28 @@ class ForceGraphEngine {
62778
62875
  syncTimer = null;
62779
62876
  lastSyncedPositions = new Map;
62780
62877
  activeComponents = new Map;
62878
+ isPhysicsEmit = false;
62781
62879
  TICK_MS = 33;
62782
62880
  SYNC_MS = 300;
62783
62881
  MIN_MOVE_PX = 0.05;
62784
62882
  constructor(board) {
62785
62883
  this.board = board;
62884
+ board.events.subject.subscribe((event) => {
62885
+ if (this.isPhysicsEmit)
62886
+ return;
62887
+ const op = event.body?.operation;
62888
+ if (!op || op.class !== "Transformation" || op.method !== "applyMatrix")
62889
+ return;
62890
+ for (const { id, matrix } of op.items) {
62891
+ const last = this.lastSyncedPositions.get(id);
62892
+ if (last) {
62893
+ this.lastSyncedPositions.set(id, {
62894
+ x: last.x + matrix.translateX,
62895
+ y: last.y + matrix.translateY
62896
+ });
62897
+ }
62898
+ }
62899
+ });
62786
62900
  }
62787
62901
  enableForGraph(startNodeId) {
62788
62902
  if (this.isNodeInActiveGraph(startNodeId))
@@ -63010,8 +63124,8 @@ class ForceGraphEngine {
63010
63124
  }
63011
63125
  vel.vx = (vel.vx + (ax.get(id) ?? 0)) * conf.FG_DAMPING;
63012
63126
  vel.vy = (vel.vy + (ay.get(id) ?? 0)) * conf.FG_DAMPING;
63013
- totalEnergy += Math.abs(vel.vx) + Math.abs(vel.vy);
63014
63127
  if (Math.abs(vel.vx) >= this.MIN_MOVE_PX || Math.abs(vel.vy) >= this.MIN_MOVE_PX) {
63128
+ totalEnergy += Math.abs(vel.vx) + Math.abs(vel.vy);
63015
63129
  item.transformation.applyMatrixSilent({
63016
63130
  translateX: vel.vx,
63017
63131
  translateY: vel.vy,
@@ -63033,26 +63147,33 @@ class ForceGraphEngine {
63033
63147
  const nodes = this.getNodes().filter((item) => activeIds.has(item.getId()) && !draggedIds.has(item.getId()) && !(item.parent !== "Board" && draggedIds.has(item.parent)));
63034
63148
  if (nodes.length === 0)
63035
63149
  return;
63036
- const movedItems = nodes.map((item) => {
63150
+ const toSend = [];
63151
+ for (const item of nodes) {
63037
63152
  const id = item.getId();
63038
63153
  const pos = item.transformation.getTranslation();
63039
63154
  const last = this.lastSyncedPositions.get(id);
63040
63155
  const dx = last ? pos.x - last.x : 0;
63041
63156
  const dy = last ? pos.y - last.y : 0;
63042
- this.lastSyncedPositions.set(id, { x: pos.x, y: pos.y });
63043
- return { id, dx, dy };
63044
- }).filter(({ dx, dy }) => Math.abs(dx) > 0.5 || Math.abs(dy) > 0.5);
63045
- if (movedItems.length === 0)
63157
+ if (Math.abs(dx) > 0.5 || Math.abs(dy) > 0.5) {
63158
+ toSend.push({ id, dx, dy, x: pos.x, y: pos.y });
63159
+ }
63160
+ }
63161
+ if (toSend.length === 0)
63046
63162
  return;
63163
+ for (const { id, x, y } of toSend) {
63164
+ this.lastSyncedPositions.set(id, { x, y });
63165
+ }
63047
63166
  const operation = {
63048
63167
  class: "Transformation",
63049
63168
  method: "applyMatrix",
63050
- items: movedItems.map(({ id, dx, dy }) => ({
63169
+ items: toSend.map(({ id, dx, dy }) => ({
63051
63170
  id,
63052
63171
  matrix: { translateX: dx, translateY: dy, scaleX: 1, scaleY: 1, shearX: 0, shearY: 0 }
63053
63172
  }))
63054
63173
  };
63174
+ this.isPhysicsEmit = true;
63055
63175
  this.board.events.emit(operation);
63176
+ this.isPhysicsEmit = false;
63056
63177
  }
63057
63178
  }
63058
63179