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.
@@ -4133,277 +4133,6 @@ var init_Color = __esm(() => {
4133
4133
  init_resolveColor();
4134
4134
  });
4135
4135
 
4136
- // src/Events/SyncLog.ts
4137
- function createSyncLog() {
4138
- const log = [];
4139
- const subject = new Subject;
4140
- log.push = function(...msgs) {
4141
- let newLength = log.length;
4142
- for (const msg of msgs) {
4143
- const lastItem = log[log.length - 1];
4144
- if (lastItem && lastItem.msg === msg.msg) {
4145
- lastItem.records = lastItem.records.concat(msg.records);
4146
- } else {
4147
- newLength = Array.prototype.push.call(log, msg);
4148
- }
4149
- }
4150
- subject.publish(log);
4151
- return newLength;
4152
- };
4153
- return {
4154
- log,
4155
- subject
4156
- };
4157
- }
4158
- var init_SyncLog = () => {};
4159
-
4160
- // src/Events/Log/createEventsList.ts
4161
- function createEventsList(commandFactory) {
4162
- const confirmedRecords = [];
4163
- const recordsToSend = [];
4164
- const newRecords = [];
4165
- const justConfirmed = [];
4166
- const { log: syncLog, subject: syncLogSubject } = createSyncLog();
4167
- let snapshotLastIndex = 0;
4168
- function revert(records) {
4169
- for (let i = records.length - 1;i >= 0; i--) {
4170
- records[i].command.revert();
4171
- }
4172
- }
4173
- function getOpItems(op) {
4174
- if ("item" in op) {
4175
- const item = op.item;
4176
- if (Array.isArray(item))
4177
- return item;
4178
- if (typeof item === "string")
4179
- return [item];
4180
- if (item && typeof item === "object")
4181
- return Object.keys(item);
4182
- }
4183
- if ("itemsMap" in op && op.itemsMap)
4184
- return Object.keys(op.itemsMap);
4185
- if ("items" in op) {
4186
- const items = op.items;
4187
- if (Array.isArray(items)) {
4188
- return items.map((i) => typeof i === "string" ? i : i.id).filter(Boolean);
4189
- }
4190
- if (items && typeof items === "object" && items !== null)
4191
- return Object.keys(items);
4192
- }
4193
- if ("itemsOps" in op) {
4194
- const itemsOps = op.itemsOps;
4195
- return itemsOps.map((io) => io.item);
4196
- }
4197
- return [];
4198
- }
4199
- return {
4200
- commandFactory,
4201
- addConfirmedRecords(records) {
4202
- confirmedRecords.push(...records);
4203
- syncLog.push({ msg: "confirmed", records });
4204
- },
4205
- addNewRecords(records) {
4206
- newRecords.push(...records);
4207
- syncLog.push({ msg: "addedNew", records });
4208
- },
4209
- confirmSentRecords(events) {
4210
- for (const event of events) {
4211
- const index = recordsToSend.findIndex((r) => r.event.body.eventId === event.body.eventId);
4212
- if (index !== -1) {
4213
- const [record] = recordsToSend.splice(index, 1);
4214
- confirmedRecords.push(record);
4215
- syncLog.push({ msg: "confirmed", records: [record] });
4216
- }
4217
- }
4218
- },
4219
- getConfirmedRecords() {
4220
- return confirmedRecords;
4221
- },
4222
- getRecordsToSend() {
4223
- return recordsToSend;
4224
- },
4225
- getNewRecords() {
4226
- return newRecords;
4227
- },
4228
- getAllRecords() {
4229
- return [...confirmedRecords, ...recordsToSend, ...newRecords];
4230
- },
4231
- prepareRecordsToSend() {
4232
- const records = [...newRecords];
4233
- recordsToSend.push(...records);
4234
- newRecords.length = 0;
4235
- syncLog.push({ msg: "toSend", records });
4236
- return records;
4237
- },
4238
- forwardIterable() {
4239
- return function* () {
4240
- yield* confirmedRecords;
4241
- yield* recordsToSend;
4242
- yield* newRecords;
4243
- }();
4244
- },
4245
- backwardIterable() {
4246
- return function* () {
4247
- for (let i = newRecords.length - 1;i >= 0; i--)
4248
- yield newRecords[i];
4249
- for (let i = recordsToSend.length - 1;i >= 0; i--)
4250
- yield recordsToSend[i];
4251
- for (let i = confirmedRecords.length - 1;i >= 0; i--)
4252
- yield confirmedRecords[i];
4253
- }();
4254
- },
4255
- revertUnconfirmed(predicate) {
4256
- const toRevert = [...recordsToSend, ...newRecords].filter(predicate || (() => true));
4257
- revert(toRevert);
4258
- syncLog.push({ msg: "revertUnconfirmed", records: toRevert });
4259
- },
4260
- applyUnconfirmed(predicate) {
4261
- const unconfirmed = [...recordsToSend, ...newRecords].filter(predicate || (() => true));
4262
- for (const record of unconfirmed) {
4263
- record.command.apply();
4264
- }
4265
- syncLog.push({ msg: "applyUnconfirmed", records: unconfirmed });
4266
- },
4267
- justConfirmed,
4268
- getSyncLog() {
4269
- return syncLog;
4270
- },
4271
- syncLogSubject,
4272
- clear() {
4273
- confirmedRecords.length = 0;
4274
- recordsToSend.length = 0;
4275
- newRecords.length = 0;
4276
- syncLog.length = 0;
4277
- syncLogSubject.publish(syncLog);
4278
- },
4279
- clearConfirmedRecords() {
4280
- confirmedRecords.length = 0;
4281
- syncLog.length = 0;
4282
- syncLogSubject.publish(syncLog);
4283
- },
4284
- removeUnconfirmedEventsByItems(itemIds) {
4285
- const itemIdSet = new Set(itemIds);
4286
- const filter = (record) => {
4287
- const opItems = getOpItems(record.event.body.operation);
4288
- return !opItems.some((id) => itemIdSet.has(id));
4289
- };
4290
- const filteredNewRecords = newRecords.filter(filter);
4291
- newRecords.length = 0;
4292
- newRecords.push(...filteredNewRecords);
4293
- const filteredRecordsToSend = recordsToSend.filter(filter);
4294
- recordsToSend.length = 0;
4295
- recordsToSend.push(...filteredRecordsToSend);
4296
- syncLog.length = 0;
4297
- syncLog.push({ msg: "confirmed", records: confirmedRecords });
4298
- syncLog.push({ msg: "toSend", records: recordsToSend });
4299
- syncLog.push({ msg: "addedNew", records: newRecords });
4300
- syncLogSubject.publish(syncLog);
4301
- },
4302
- isAllEventsConfirmed() {
4303
- return recordsToSend.length === 0 && newRecords.length === 0;
4304
- },
4305
- setSnapshotLastIndex(index) {
4306
- snapshotLastIndex = index;
4307
- },
4308
- getSnapshotLastIndex() {
4309
- return snapshotLastIndex;
4310
- }
4311
- };
4312
- }
4313
- var init_createEventsList = __esm(() => {
4314
- init_SyncLog();
4315
- });
4316
-
4317
- // src/Events/Log/getRecordByIdFromList.ts
4318
- function getRecordByIdFromList(id, list) {
4319
- for (const record of list.forwardIterable()) {
4320
- if (record.event.body.eventId === id) {
4321
- return record;
4322
- }
4323
- }
4324
- return;
4325
- }
4326
-
4327
- // src/Events/Log/shouldSkipEvent.ts
4328
- function shouldSkipEvent(record, userId) {
4329
- const { operation } = record.event.body;
4330
- return record.event.body.userId !== userId || operation.method === "updateVideoData" || operation.class === "Audio" && operation.method === "setUrl";
4331
- }
4332
-
4333
- // src/Events/Log/getRedoRecordFromList.ts
4334
- function getRedoRecordFromList(userId, list) {
4335
- let counter = 0;
4336
- for (const record of list.backwardIterable()) {
4337
- if (shouldSkipEvent(record, userId)) {
4338
- continue;
4339
- }
4340
- if (record.event.body.operation.method !== "undo" && record.event.body.operation.method !== "redo") {
4341
- return null;
4342
- }
4343
- const { method } = record.event.body.operation;
4344
- if (method === "redo") {
4345
- counter++;
4346
- } else if (method === "undo") {
4347
- if (counter > 0) {
4348
- counter--;
4349
- } else if (counter === 0) {
4350
- return record;
4351
- }
4352
- }
4353
- }
4354
- return null;
4355
- }
4356
- var init_getRedoRecordFromList = () => {};
4357
-
4358
- // src/Events/Log/getUndoRecordFromList.ts
4359
- function getUndoRecordFromList(userId, list) {
4360
- let counter = 0;
4361
- const isAllEventsConfirmed = list.isAllEventsConfirmed();
4362
- if (!isAllEventsConfirmed) {
4363
- return null;
4364
- }
4365
- for (const record of list.getConfirmedRecords().slice().reverse()) {
4366
- if (shouldSkipEvent(record, userId)) {
4367
- continue;
4368
- }
4369
- if (record.event.body.operation.method === "undo") {
4370
- counter++;
4371
- } else if (counter === 0) {
4372
- return record;
4373
- } else {
4374
- counter--;
4375
- }
4376
- }
4377
- return null;
4378
- }
4379
- var init_getUndoRecordFromList = () => {};
4380
-
4381
- // src/Events/Log/getUnpublishedEventFromList.ts
4382
- function getUnpublishedEventFromList(list) {
4383
- const recordsToSend = list.prepareRecordsToSend();
4384
- if (recordsToSend.length === 0) {
4385
- return null;
4386
- }
4387
- const operations = getOperationsFromEventRecords(recordsToSend);
4388
- return combineOperationsIntoPack(recordsToSend[0].event, operations);
4389
- }
4390
- function getOperationsFromEventRecords(records) {
4391
- return records.map((record) => ({
4392
- ...record.event.body.operation,
4393
- actualId: record.event.body.eventId
4394
- }));
4395
- }
4396
- function combineOperationsIntoPack(baseEvent, operations) {
4397
- const { operation, ...bodyWithoutOperation } = baseEvent.body;
4398
- return {
4399
- ...baseEvent,
4400
- body: {
4401
- ...bodyWithoutOperation,
4402
- operations
4403
- }
4404
- };
4405
- }
4406
-
4407
4136
  // src/Events/EventsOperations.ts
4408
4137
  function isTransformation(op) {
4409
4138
  return op.class === "Transformation";
@@ -4732,41 +4461,69 @@ var init_Merge = __esm(() => {
4732
4461
  import_slate = require("slate");
4733
4462
  });
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
  function removeText_removeText(confirmed, toTransform) {
4772
4529
  const transformed = { ...toTransform };
@@ -5883,6 +5640,346 @@ var init_transformEvents = __esm(() => {
5883
5640
  init_Transform2();
5884
5641
  });
5885
5642
 
5643
+ // src/Events/Log/createEventsList.ts
5644
+ function createEventsList(commandFactory) {
5645
+ const confirmedRecords = [];
5646
+ const recordsToSend = [];
5647
+ const newRecords = [];
5648
+ const justConfirmed = [];
5649
+ const { log: syncLog, subject: syncLogSubject } = createSyncLog();
5650
+ let snapshotLastIndex = 0;
5651
+ function revert(records) {
5652
+ for (let i = records.length - 1;i >= 0; i--) {
5653
+ records[i].command.revert();
5654
+ }
5655
+ }
5656
+ function apply(records) {
5657
+ for (const record of records) {
5658
+ record.command = commandFactory(record.event.body.operation);
5659
+ record.command.apply();
5660
+ }
5661
+ }
5662
+ function mergeAndPushConfirmedRecords(records) {
5663
+ const lastConfirmedRecord = confirmedRecords.pop();
5664
+ const recordsToMerge = lastConfirmedRecord ? [lastConfirmedRecord, ...records] : records;
5665
+ const mergedRecords = mergeRecords(recordsToMerge);
5666
+ confirmedRecords.push(...mergedRecords);
5667
+ }
5668
+ return {
5669
+ commandFactory,
5670
+ addConfirmedRecords(records) {
5671
+ syncLog.push({ msg: "confirmed", records });
5672
+ mergeAndPushConfirmedRecords(records);
5673
+ },
5674
+ addNewRecords(records) {
5675
+ for (const record of records) {
5676
+ if (newRecords.length > 0) {
5677
+ const lastRecord = newRecords[newRecords.length - 1];
5678
+ const mergedOperation = mergeOperations(lastRecord.event.body.operation, record.event.body.operation);
5679
+ if (mergedOperation) {
5680
+ lastRecord.event = {
5681
+ ...lastRecord.event,
5682
+ body: {
5683
+ ...lastRecord.event.body,
5684
+ operation: mergedOperation
5685
+ }
5686
+ };
5687
+ lastRecord.command = commandFactory(mergedOperation);
5688
+ continue;
5689
+ }
5690
+ }
5691
+ newRecords.push(record);
5692
+ syncLog.push({ msg: "addedNew", records: [record] });
5693
+ }
5694
+ },
5695
+ confirmSentRecords(events) {
5696
+ const records = recordsToSend;
5697
+ if (records.length !== events.length) {
5698
+ console.error("Mismatch between records and events length");
5699
+ return;
5700
+ }
5701
+ for (let i = 0;i < records.length; i++) {
5702
+ records[i].event.order = events[i].order;
5703
+ }
5704
+ syncLog.push({ msg: "confirmed", records: [...records] });
5705
+ mergeAndPushConfirmedRecords(records);
5706
+ recordsToSend.splice(0, records.length);
5707
+ },
5708
+ confirmSentRecordIds(eventIds, order) {
5709
+ const confirmedRecordsById = [];
5710
+ for (const eventId of eventIds) {
5711
+ const index = recordsToSend.findIndex((record2) => record2.event.body.eventId === eventId);
5712
+ if (index === -1) {
5713
+ continue;
5714
+ }
5715
+ const [record] = recordsToSend.splice(index, 1);
5716
+ record.event.order = order;
5717
+ confirmedRecordsById.push(record);
5718
+ }
5719
+ if (confirmedRecordsById.length === 0) {
5720
+ return;
5721
+ }
5722
+ syncLog.push({ msg: "confirmed", records: confirmedRecordsById });
5723
+ mergeAndPushConfirmedRecords(confirmedRecordsById);
5724
+ },
5725
+ getConfirmedRecords() {
5726
+ return confirmedRecords;
5727
+ },
5728
+ getRecordsToSend() {
5729
+ return recordsToSend;
5730
+ },
5731
+ getNewRecords() {
5732
+ return newRecords;
5733
+ },
5734
+ getAllRecords() {
5735
+ return [...confirmedRecords, ...recordsToSend, ...newRecords];
5736
+ },
5737
+ prepareRecordsToSend() {
5738
+ if (recordsToSend.length === 0 && newRecords.length > 0) {
5739
+ const records = [...newRecords];
5740
+ recordsToSend.push(...records);
5741
+ newRecords.length = 0;
5742
+ syncLog.push({ msg: "toSend", records });
5743
+ }
5744
+ return recordsToSend;
5745
+ },
5746
+ forwardIterable() {
5747
+ return function* () {
5748
+ yield* confirmedRecords;
5749
+ yield* recordsToSend;
5750
+ yield* newRecords;
5751
+ }();
5752
+ },
5753
+ backwardIterable() {
5754
+ return function* () {
5755
+ for (let i = newRecords.length - 1;i >= 0; i--)
5756
+ yield newRecords[i];
5757
+ for (let i = recordsToSend.length - 1;i >= 0; i--)
5758
+ yield recordsToSend[i];
5759
+ for (let i = confirmedRecords.length - 1;i >= 0; i--)
5760
+ yield confirmedRecords[i];
5761
+ }();
5762
+ },
5763
+ revertUnconfirmed(predicate) {
5764
+ const toRevert = [...recordsToSend, ...newRecords].filter(predicate || (() => true));
5765
+ revert(toRevert);
5766
+ syncLog.push({ msg: "revertUnconfirmed", records: toRevert });
5767
+ },
5768
+ applyUnconfirmed(predicate) {
5769
+ const filter = predicate || (() => true);
5770
+ if (justConfirmed.length > 0) {
5771
+ const confirmedEvents = justConfirmed.map((record) => record.event);
5772
+ const transformedSend = transformEvents(confirmedEvents, recordsToSend.map((record) => record.event));
5773
+ const transformedNew = transformEvents(confirmedEvents, newRecords.map((record) => record.event));
5774
+ const updatedRecordsToSend = transformedSend.map((event) => ({
5775
+ event,
5776
+ command: commandFactory(event.body.operation)
5777
+ }));
5778
+ const updatedNewRecords = transformedNew.map((event) => ({
5779
+ event,
5780
+ command: commandFactory(event.body.operation)
5781
+ }));
5782
+ recordsToSend.length = 0;
5783
+ recordsToSend.push(...updatedRecordsToSend);
5784
+ newRecords.length = 0;
5785
+ newRecords.push(...updatedNewRecords);
5786
+ justConfirmed.length = 0;
5787
+ }
5788
+ const unconfirmed = [...recordsToSend, ...newRecords].filter(filter);
5789
+ apply(unconfirmed);
5790
+ syncLog.push({ msg: "applyUnconfirmed", records: unconfirmed });
5791
+ },
5792
+ justConfirmed,
5793
+ getSyncLog() {
5794
+ return syncLog;
5795
+ },
5796
+ syncLogSubject,
5797
+ clear() {
5798
+ confirmedRecords.length = 0;
5799
+ recordsToSend.length = 0;
5800
+ newRecords.length = 0;
5801
+ syncLog.length = 0;
5802
+ syncLogSubject.publish(syncLog);
5803
+ },
5804
+ clearConfirmedRecords() {
5805
+ confirmedRecords.length = 0;
5806
+ syncLog.length = 0;
5807
+ syncLogSubject.publish(syncLog);
5808
+ },
5809
+ removeUnconfirmedEventsByItems(itemIds) {
5810
+ function shouldRemoveEvent(operation, ids) {
5811
+ if (operation.method === "add" && operation.class === "Board") {
5812
+ if (Array.isArray(operation.item)) {
5813
+ return operation.item.some((id) => ids.includes(id));
5814
+ }
5815
+ return ids.includes(operation.item);
5816
+ }
5817
+ if (operation.method === "remove" && operation.class === "Board") {
5818
+ return operation.item.some((id) => ids.includes(id));
5819
+ }
5820
+ return false;
5821
+ }
5822
+ const nextRecordsToSend = recordsToSend.filter((record) => !shouldRemoveEvent(record.event.body.operation, itemIds));
5823
+ if (nextRecordsToSend.length !== recordsToSend.length) {
5824
+ recordsToSend.length = 0;
5825
+ recordsToSend.push(...nextRecordsToSend);
5826
+ }
5827
+ const nextNewRecords = newRecords.filter((record) => !shouldRemoveEvent(record.event.body.operation, itemIds));
5828
+ if (nextNewRecords.length !== newRecords.length) {
5829
+ newRecords.length = 0;
5830
+ newRecords.push(...nextNewRecords);
5831
+ }
5832
+ },
5833
+ isAllEventsConfirmed() {
5834
+ return recordsToSend.length === 0 && newRecords.length === 0;
5835
+ },
5836
+ setSnapshotLastIndex(index) {
5837
+ snapshotLastIndex = index;
5838
+ },
5839
+ getSnapshotLastIndex() {
5840
+ return snapshotLastIndex;
5841
+ }
5842
+ };
5843
+ }
5844
+ var init_createEventsList = __esm(() => {
5845
+ init_Merge();
5846
+ init_mergeRecords();
5847
+ init_SyncLog();
5848
+ init_transformEvents();
5849
+ });
5850
+
5851
+ // src/Events/Log/getRecordByIdFromList.ts
5852
+ function getRecordByIdFromList(id, list) {
5853
+ for (const record of list.forwardIterable()) {
5854
+ if (record.event.body.eventId === id) {
5855
+ return record;
5856
+ }
5857
+ }
5858
+ return;
5859
+ }
5860
+
5861
+ // src/Events/Log/shouldSkipEvent.ts
5862
+ function shouldSkipEvent(record, userId) {
5863
+ const { operation } = record.event.body;
5864
+ return record.event.body.userId !== userId || operation.method === "updateVideoData" || operation.class === "Audio" && operation.method === "setUrl";
5865
+ }
5866
+
5867
+ // src/Events/Log/getRedoRecordFromList.ts
5868
+ function getRedoRecordFromList(userId, list) {
5869
+ let counter = 0;
5870
+ for (const record of list.backwardIterable()) {
5871
+ if (shouldSkipEvent(record, userId)) {
5872
+ continue;
5873
+ }
5874
+ if (record.event.body.operation.method !== "undo" && record.event.body.operation.method !== "redo") {
5875
+ return null;
5876
+ }
5877
+ const { method } = record.event.body.operation;
5878
+ if (method === "redo") {
5879
+ counter++;
5880
+ } else if (method === "undo") {
5881
+ if (counter > 0) {
5882
+ counter--;
5883
+ } else if (counter === 0) {
5884
+ return record;
5885
+ }
5886
+ }
5887
+ }
5888
+ return null;
5889
+ }
5890
+ var init_getRedoRecordFromList = () => {};
5891
+
5892
+ // src/Events/Log/getUndoRecordFromList.ts
5893
+ function getUndoRecordFromList(userId, list) {
5894
+ let counter = 0;
5895
+ const isAllEventsConfirmed = list.isAllEventsConfirmed();
5896
+ if (!isAllEventsConfirmed) {
5897
+ return null;
5898
+ }
5899
+ for (const record of list.getConfirmedRecords().slice().reverse()) {
5900
+ if (shouldSkipEvent(record, userId)) {
5901
+ continue;
5902
+ }
5903
+ if (record.event.body.operation.method === "undo") {
5904
+ counter++;
5905
+ } else if (counter === 0) {
5906
+ return record;
5907
+ } else {
5908
+ counter--;
5909
+ }
5910
+ }
5911
+ return null;
5912
+ }
5913
+ var init_getUndoRecordFromList = () => {};
5914
+
5915
+ // src/Events/Log/getUnpublishedEventFromList.ts
5916
+ function getUnpublishedEventFromList(list) {
5917
+ const recordsToSend = list.prepareRecordsToSend();
5918
+ if (recordsToSend.length === 0) {
5919
+ return null;
5920
+ }
5921
+ const mergedRecords = mergeRecords(recordsToSend);
5922
+ const operations = getOperationsFromEventRecords(mergedRecords);
5923
+ return {
5924
+ event: combineOperationsIntoPack(recordsToSend[0].event, operations),
5925
+ sentEventIds: recordsToSend.map((record) => record.event.body.eventId)
5926
+ };
5927
+ }
5928
+ function getOperationsFromEventRecords(records) {
5929
+ return records.map((record) => ({
5930
+ ...record.event.body.operation,
5931
+ actualId: record.event.body.eventId
5932
+ }));
5933
+ }
5934
+ function combineOperationsIntoPack(baseEvent, operations) {
5935
+ const { operation, ...bodyWithoutOperation } = baseEvent.body;
5936
+ return {
5937
+ ...baseEvent,
5938
+ body: {
5939
+ ...bodyWithoutOperation,
5940
+ operations
5941
+ }
5942
+ };
5943
+ }
5944
+ var init_getUnpublishedEventFromList = __esm(() => {
5945
+ init_mergeRecords();
5946
+ });
5947
+
5948
+ // src/Events/mergeEvents.ts
5949
+ function mergeEvents(events) {
5950
+ if (events.length < 2) {
5951
+ return events;
5952
+ }
5953
+ const mergedEvents = [];
5954
+ let previous = null;
5955
+ for (const event of events) {
5956
+ if (!previous) {
5957
+ previous = event;
5958
+ continue;
5959
+ }
5960
+ const mergedOperation = mergeOperations(previous.body.operation, event.body.operation);
5961
+ if (!mergedOperation) {
5962
+ mergedEvents.push(previous);
5963
+ previous = event;
5964
+ } else {
5965
+ previous = {
5966
+ ...event,
5967
+ body: {
5968
+ ...event.body,
5969
+ operation: mergedOperation
5970
+ }
5971
+ };
5972
+ }
5973
+ }
5974
+ if (previous) {
5975
+ mergedEvents.push(previous);
5976
+ }
5977
+ return mergedEvents;
5978
+ }
5979
+ var init_mergeEvents = __esm(() => {
5980
+ init_Merge();
5981
+ });
5982
+
5886
5983
  // src/Events/Log/expandEvents.ts
5887
5984
  function expandEvents(events) {
5888
5985
  return events.flatMap((event) => {
@@ -6096,6 +6193,9 @@ class EventsLog {
6096
6193
  const events = expandEvents([event]);
6097
6194
  this.list.confirmSentRecords(events);
6098
6195
  }
6196
+ confirmSentLocalEventIds(eventIds, order) {
6197
+ this.list.confirmSentRecordIds(eventIds, order);
6198
+ }
6099
6199
  getUnorderedRecords() {
6100
6200
  return this.list.getRecordsToSend().concat(this.list.getNewRecords());
6101
6201
  }
@@ -6138,6 +6238,7 @@ var init_EventsLog = __esm(() => {
6138
6238
  init_createEventsList();
6139
6239
  init_getRedoRecordFromList();
6140
6240
  init_getUndoRecordFromList();
6241
+ init_getUnpublishedEventFromList();
6141
6242
  init_insertEventsFromOtherConnectionsIntoList();
6142
6243
  });
6143
6244
 
@@ -55451,25 +55552,16 @@ function handleBoardEventMessage(message, board) {
55451
55552
  if (event.order <= log.getLastIndex()) {
55452
55553
  return;
55453
55554
  }
55454
- const eventUserId = parseFloat(event.body.eventId.split(":")[0]);
55455
- const currentUserId = Number(localStorage.getItem("userId") || "0");
55456
- const isEventFromCurrentUser = eventUserId === currentUserId;
55555
+ const eventConnectionId = Number(event.body.eventId.split(":")[0]);
55556
+ const currentConnectionId = board.events.connection?.connectionId;
55557
+ const isEventFromCurrentUser = currentConnectionId !== undefined && eventConnectionId === currentConnectionId;
55457
55558
  if (isEventFromCurrentUser) {
55458
55559
  return;
55459
55560
  }
55460
55561
  if ("operations" in event.body) {
55461
- log.insertEventsFromOtherConnections({
55462
- ...event,
55463
- body: {
55464
- ...event.body,
55465
- userId: Number(message.userId)
55466
- }
55467
- });
55562
+ log.insertEventsFromOtherConnections(event);
55468
55563
  } else {
55469
- log.insertEventsFromOtherConnections({
55470
- ...event,
55471
- userId: Number(message.userId)
55472
- });
55564
+ log.insertEventsFromOtherConnections(event);
55473
55565
  }
55474
55566
  const last = log.getLastConfirmed();
55475
55567
  if (last) {
@@ -55521,11 +55613,11 @@ function tryPublishEvent(board) {
55521
55613
  if (log.pendingEvent) {
55522
55614
  return;
55523
55615
  }
55524
- const unpublishedEvent = log.getUnpublishedEvent();
55525
- if (!unpublishedEvent) {
55616
+ const unpublishedBatch = log.getUnpublishedEvent();
55617
+ if (!unpublishedBatch) {
55526
55618
  return;
55527
55619
  }
55528
- sendBoardEvent(board, unpublishedEvent, log.currentSequenceNumber);
55620
+ sendBoardEvent(board, unpublishedBatch, log.currentSequenceNumber);
55529
55621
  }
55530
55622
  function tryResendEvent(board) {
55531
55623
  const { log } = board.events;
@@ -55542,7 +55634,10 @@ function tryResendEvent(board) {
55542
55634
  board.presence.clear();
55543
55635
  conf.connection?.notifyAboutLostConnection();
55544
55636
  }
55545
- sendBoardEvent(board, log.pendingEvent.event, log.currentSequenceNumber);
55637
+ sendBoardEvent(board, {
55638
+ event: log.pendingEvent.event,
55639
+ sentEventIds: log.pendingEvent.sentEventIds
55640
+ }, log.currentSequenceNumber);
55546
55641
  }
55547
55642
  function handleSnapshotApplication(snapshot, board) {
55548
55643
  const { log } = board.events;
@@ -55567,8 +55662,9 @@ function handleBoardEventListApplication(events, board) {
55567
55662
  board.events.subject.publish(newEvents[0]);
55568
55663
  }
55569
55664
  }
55570
- function sendBoardEvent(board, event, sequenceNumber) {
55665
+ function sendBoardEvent(board, batch, sequenceNumber) {
55571
55666
  const { log } = board.events;
55667
+ const { event, sentEventIds } = batch;
55572
55668
  const toSend = {
55573
55669
  ...event,
55574
55670
  body: {
@@ -55586,6 +55682,7 @@ function sendBoardEvent(board, event, sequenceNumber) {
55586
55682
  const date = Date.now();
55587
55683
  log.pendingEvent = {
55588
55684
  event: toSend,
55685
+ sentEventIds,
55589
55686
  sequenceNumber,
55590
55687
  lastSentTime: date
55591
55688
  };
@@ -55633,7 +55730,7 @@ function handleConfirmation(msg, board) {
55633
55730
  conf.connection?.dismissNotificationAboutLostConnection();
55634
55731
  log.currentSequenceNumber++;
55635
55732
  log.pendingEvent.event.order = msg.order;
55636
- log.confirmSentLocalEvent(log.pendingEvent.event);
55733
+ log.confirmSentLocalEventIds(log.pendingEvent.sentEventIds, msg.order);
55637
55734
  board.subject.publish();
55638
55735
  log.pendingEvent = null;
55639
55736
  log.firstSentTime = null;
@@ -60578,11 +60675,28 @@ class ForceGraphEngine {
60578
60675
  syncTimer = null;
60579
60676
  lastSyncedPositions = new Map;
60580
60677
  activeComponents = new Map;
60678
+ isPhysicsEmit = false;
60581
60679
  TICK_MS = 33;
60582
60680
  SYNC_MS = 300;
60583
60681
  MIN_MOVE_PX = 0.05;
60584
60682
  constructor(board) {
60585
60683
  this.board = board;
60684
+ board.events.subject.subscribe((event) => {
60685
+ if (this.isPhysicsEmit)
60686
+ return;
60687
+ const op = event.body?.operation;
60688
+ if (!op || op.class !== "Transformation" || op.method !== "applyMatrix")
60689
+ return;
60690
+ for (const { id, matrix } of op.items) {
60691
+ const last = this.lastSyncedPositions.get(id);
60692
+ if (last) {
60693
+ this.lastSyncedPositions.set(id, {
60694
+ x: last.x + matrix.translateX,
60695
+ y: last.y + matrix.translateY
60696
+ });
60697
+ }
60698
+ }
60699
+ });
60586
60700
  }
60587
60701
  enableForGraph(startNodeId) {
60588
60702
  if (this.isNodeInActiveGraph(startNodeId))
@@ -60810,8 +60924,8 @@ class ForceGraphEngine {
60810
60924
  }
60811
60925
  vel.vx = (vel.vx + (ax.get(id) ?? 0)) * conf.FG_DAMPING;
60812
60926
  vel.vy = (vel.vy + (ay.get(id) ?? 0)) * conf.FG_DAMPING;
60813
- totalEnergy += Math.abs(vel.vx) + Math.abs(vel.vy);
60814
60927
  if (Math.abs(vel.vx) >= this.MIN_MOVE_PX || Math.abs(vel.vy) >= this.MIN_MOVE_PX) {
60928
+ totalEnergy += Math.abs(vel.vx) + Math.abs(vel.vy);
60815
60929
  item.transformation.applyMatrixSilent({
60816
60930
  translateX: vel.vx,
60817
60931
  translateY: vel.vy,
@@ -60833,26 +60947,33 @@ class ForceGraphEngine {
60833
60947
  const nodes = this.getNodes().filter((item) => activeIds.has(item.getId()) && !draggedIds.has(item.getId()) && !(item.parent !== "Board" && draggedIds.has(item.parent)));
60834
60948
  if (nodes.length === 0)
60835
60949
  return;
60836
- const movedItems = nodes.map((item) => {
60950
+ const toSend = [];
60951
+ for (const item of nodes) {
60837
60952
  const id = item.getId();
60838
60953
  const pos = item.transformation.getTranslation();
60839
60954
  const last = this.lastSyncedPositions.get(id);
60840
60955
  const dx = last ? pos.x - last.x : 0;
60841
60956
  const dy = last ? pos.y - last.y : 0;
60842
- this.lastSyncedPositions.set(id, { x: pos.x, y: pos.y });
60843
- return { id, dx, dy };
60844
- }).filter(({ dx, dy }) => Math.abs(dx) > 0.5 || Math.abs(dy) > 0.5);
60845
- if (movedItems.length === 0)
60957
+ if (Math.abs(dx) > 0.5 || Math.abs(dy) > 0.5) {
60958
+ toSend.push({ id, dx, dy, x: pos.x, y: pos.y });
60959
+ }
60960
+ }
60961
+ if (toSend.length === 0)
60846
60962
  return;
60963
+ for (const { id, x, y } of toSend) {
60964
+ this.lastSyncedPositions.set(id, { x, y });
60965
+ }
60847
60966
  const operation = {
60848
60967
  class: "Transformation",
60849
60968
  method: "applyMatrix",
60850
- items: movedItems.map(({ id, dx, dy }) => ({
60969
+ items: toSend.map(({ id, dx, dy }) => ({
60851
60970
  id,
60852
60971
  matrix: { translateX: dx, translateY: dy, scaleX: 1, scaleY: 1, shearX: 0, shearY: 0 }
60853
60972
  }))
60854
60973
  };
60974
+ this.isPhysicsEmit = true;
60855
60975
  this.board.events.emit(operation);
60976
+ this.isPhysicsEmit = false;
60856
60977
  }
60857
60978
  }
60858
60979