@liveblocks/client 0.17.5 → 0.17.6

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2021 LIVEBLOCKS PTY LTD
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -29,22 +29,22 @@ npm install @liveblocks/client
29
29
 
30
30
  ## Documentation
31
31
 
32
- - [Read the documentation](https://liveblocks.io/docs) to start using
33
- Liveblocks.
34
- - Explore the
35
- [API Reference](https://liveblocks.io/docs/api-reference/liveblocks-client).
32
+ Read the [documentation](https://liveblocks.io/docs) for guides and API
33
+ references.
36
34
 
37
35
  ## Examples
38
36
 
39
- - Browse our gallery of collaborative UI patterns.
40
- [View examples gallery](https://liveblocks.io/examples)
41
- - Explore and clone any of our open-source examples.
42
- [View code examples](https://github.com/liveblocks/liveblocks/tree/main/examples)
37
+ Explore our [collaborative examples](https://liveblocks.io/examples) to help you
38
+ get started.
39
+
40
+ > All examples are open-source and live in this repository, within
41
+ > [`/examples`](../../examples).
43
42
 
44
43
  ## Releases
45
44
 
46
- For changelog, visit
47
- [https://github.com/liveblocks/liveblocks/releases](https://github.com/liveblocks/liveblocks/releases).
45
+ See the [latest changes](https://github.com/liveblocks/liveblocks/releases) or
46
+ learn more about
47
+ [upcoming releases](https://github.com/liveblocks/liveblocks/milestones).
48
48
 
49
49
  ## Community
50
50
 
package/index.js CHANGED
@@ -414,7 +414,7 @@ function makeStateMachine(state, context, mockedEffects) {
414
414
  var ws = WebSocketPolyfill || WebSocket;
415
415
  return function (token) {
416
416
  return new ws(
417
- liveblocksServer + "/?token=" + token + "&version=0.17.5"
417
+ liveblocksServer + "/?token=" + token + "&version=0.17.6"
418
418
  );
419
419
  };
420
420
  })(
package/index.mjs CHANGED
@@ -337,7 +337,7 @@ function makeStateMachine(state, context, mockedEffects) {
337
337
  );
338
338
  const ws = WebSocketPolyfill || WebSocket;
339
339
  return (token) =>
340
- new ws(`${liveblocksServer}/?token=${token}&version=0.17.5`);
340
+ new ws(`${liveblocksServer}/?token=${token}&version=0.17.6`);
341
341
  })(
342
342
  context.liveblocksServer,
343
343
  null !==
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/client",
3
- "version": "0.17.5",
3
+ "version": "0.17.6",
4
4
  "description": "A client that lets you interact with Liveblocks servers.",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
@@ -17,9 +17,6 @@
17
17
  "import": "./index.mjs"
18
18
  }
19
19
  },
20
- "files": [
21
- "**"
22
- ],
23
20
  "keywords": [
24
21
  "liveblocks",
25
22
  "multiplayer",
@@ -29,47 +26,7 @@
29
26
  "bugs": {
30
27
  "url": "https://github.com/liveblocks/liveblocks/issues"
31
28
  },
32
- "scripts": {
33
- "build": "rollup -c && cp ./package.json ./README.md ./lib",
34
- "format": "eslint --fix src/ test/ && prettier --write src/ test/",
35
- "lint": "eslint src/ test/",
36
- "test": "jest --watch --silent --verbose --config=./jest.config.js",
37
- "test-ci": "jest --silent --verbose",
38
- "test-e2e": "jest --silent --verbose --config=./jest.config.e2e.js"
39
- },
40
29
  "license": "Apache-2.0",
41
- "devDependencies": {
42
- "@babel/core": "^7.17.10",
43
- "@babel/preset-env": "^7.17.10",
44
- "@babel/preset-typescript": "^7.16.7",
45
- "@rollup/plugin-babel": "^5.3.1",
46
- "@rollup/plugin-node-resolve": "^13.1.3",
47
- "@rollup/plugin-replace": "^4.0.0",
48
- "@rollup/plugin-typescript": "^8.3.1",
49
- "@types/jest": "^26.0.24",
50
- "@types/node-fetch": "^2.6.1",
51
- "@types/ws": "^8.5.3",
52
- "@typescript-eslint/eslint-plugin": "^5.26.0",
53
- "@typescript-eslint/parser": "^5.26.0",
54
- "dotenv": "^16.0.0",
55
- "eslint": "^8.12.0",
56
- "eslint-plugin-import": "^2.26.0",
57
- "eslint-plugin-simple-import-sort": "^7.0.0",
58
- "jest": "^28.0.3",
59
- "jest-each": "^27.5.1",
60
- "jest-environment-jsdom": "^28.1.0",
61
- "msw": "^0.39.1",
62
- "node-fetch": "2.6.7",
63
- "regenerator-runtime": "^0.13.9",
64
- "rollup": "^2.68.0",
65
- "rollup-plugin-command": "^1.1.3",
66
- "rollup-plugin-dts": "^4.2.2",
67
- "rollup-plugin-prettier": "^2.2.2",
68
- "rollup-plugin-terser": "^7.0.2",
69
- "typescript": "^4.7.2",
70
- "whatwg-fetch": "^3.6.2",
71
- "ws": "^8.5.0"
72
- },
73
30
  "repository": {
74
31
  "type": "git",
75
32
  "url": "https://github.com/liveblocks/liveblocks.git",
package/shared.js CHANGED
@@ -571,6 +571,12 @@ function comparePosition(posA, posB) {
571
571
  'Impossible to compare similar position "' + posA + '" and "' + posB + '"'
572
572
  );
573
573
  }
574
+ function compareNodePosition(itemA, itemB) {
575
+ return comparePosition(
576
+ itemA._getParentKeyOrThrow(),
577
+ itemB._getParentKeyOrThrow()
578
+ );
579
+ }
574
580
  _Symbol$iterator$1 = Symbol.iterator;
575
581
  var LiveList = (function (_AbstractCrdt) {
576
582
  function LiveList(items) {
@@ -607,9 +613,7 @@ var LiveList = (function (_AbstractCrdt) {
607
613
  _id = _step$value[0],
608
614
  crdt = _step$value[1],
609
615
  child = deserialize([_id, crdt], parentToChildren, doc);
610
- child._setParentLink(list, crdt.parentKey),
611
- list._items.push(child),
612
- sortListItem(list._items);
616
+ child._setParentLink(list, crdt.parentKey), list._insertAndSort(child);
613
617
  }
614
618
  return list;
615
619
  });
@@ -640,6 +644,12 @@ var LiveList = (function (_AbstractCrdt) {
640
644
  }
641
645
  return ops;
642
646
  }),
647
+ (_proto._insertAndSort = function (item) {
648
+ this._items.push(item), this._sortItems();
649
+ }),
650
+ (_proto._sortItems = function () {
651
+ this._items.sort(compareNodePosition);
652
+ }),
643
653
  (_proto._indexOfPosition = function (position) {
644
654
  return this._items.findIndex(function (item) {
645
655
  return item._getParentKeyOrThrow() === position;
@@ -700,8 +710,7 @@ var LiveList = (function (_AbstractCrdt) {
700
710
  _deleteDelta2 = this._detachItemAssociatedToSetOperation(op.deletedId);
701
711
  return (
702
712
  _deleteDelta2 && updates.push(_deleteDelta2),
703
- this._items.push(child),
704
- sortListItem(this._items),
713
+ this._insertAndSort(child),
705
714
  updates.push(insertDelta(this._indexOfPosition(key), child)),
706
715
  { reverse: [], modified: makeUpdate(this, updates) }
707
716
  );
@@ -737,8 +746,7 @@ var LiveList = (function (_AbstractCrdt) {
737
746
  this._items.splice(indexOfItemWithSamePosition, 1),
738
747
  delta.push(deleteDelta(indexOfItemWithSamePosition)));
739
748
  var previousIndex = this._items.indexOf(existingItem);
740
- existingItem._setParentLink(this, op.parentKey),
741
- sortListItem(this._items);
749
+ existingItem._setParentLink(this, op.parentKey), this._sortItems();
742
750
  var newIndex = this._items.indexOf(existingItem);
743
751
  return (
744
752
  newIndex !== previousIndex &&
@@ -750,8 +758,7 @@ var LiveList = (function (_AbstractCrdt) {
750
758
  if (orphan && this._implicitlyDeletedItems.has(orphan)) {
751
759
  orphan._setParentLink(this, op.parentKey),
752
760
  this._implicitlyDeletedItems.delete(orphan),
753
- this._items.push(orphan),
754
- sortListItem(this._items);
761
+ this._insertAndSort(orphan);
755
762
  var recreatedItemIndex = this._items.indexOf(orphan);
756
763
  return {
757
764
  modified: makeUpdate(
@@ -820,7 +827,7 @@ var LiveList = (function (_AbstractCrdt) {
820
827
  -1 !== itemIndexAtPosition &&
821
828
  this._shiftItemPosition(itemIndexAtPosition, key),
822
829
  existingItem._setParentLink(this, key),
823
- sortListItem(this._items);
830
+ this._sortItems();
824
831
  var newIndex = this._indexOfPosition(key);
825
832
  return newIndex === oldPositionIndex
826
833
  ? { modified: !1 }
@@ -836,8 +843,7 @@ var LiveList = (function (_AbstractCrdt) {
836
843
  return (
837
844
  orphan._setParentLink(this, key),
838
845
  this._implicitlyDeletedItems.delete(orphan),
839
- this._items.push(orphan),
840
- sortListItem(this._items),
846
+ this._insertAndSort(orphan),
841
847
  {
842
848
  modified: makeUpdate(this, [
843
849
  insertDelta(this._indexOfPosition(key), orphan),
@@ -880,8 +886,7 @@ var LiveList = (function (_AbstractCrdt) {
880
886
  )),
881
887
  child._setParentLink(this, newKey));
882
888
  return (
883
- this._items.push(child),
884
- sortListItem(this._items),
889
+ this._insertAndSort(child),
885
890
  {
886
891
  modified: makeUpdate(this, [
887
892
  insertDelta(this._indexOfPosition(newKey), child),
@@ -916,8 +921,7 @@ var LiveList = (function (_AbstractCrdt) {
916
921
  { modified: makeUpdate(this, delta), reverse: reverse }
917
922
  );
918
923
  }
919
- this._items.push(child),
920
- sortListItem(this._items),
924
+ this._insertAndSort(child),
921
925
  this._detachItemAssociatedToSetOperation(op.deletedId);
922
926
  var newIndex = this._indexOfPosition(newKey);
923
927
  return {
@@ -961,8 +965,7 @@ var LiveList = (function (_AbstractCrdt) {
961
965
  return (
962
966
  this._implicitlyDeletedItems.delete(child),
963
967
  child._setParentLink(this, newKey),
964
- this._items.push(child),
965
- sortListItem(this._items),
968
+ this._insertAndSort(child),
966
969
  {
967
970
  modified: makeUpdate(this, [
968
971
  insertDelta(this._items.indexOf(child), child),
@@ -975,7 +978,7 @@ var LiveList = (function (_AbstractCrdt) {
975
978
  existingItemIndex = this._indexOfPosition(newKey);
976
979
  if (-1 === existingItemIndex) {
977
980
  var previousIndex = this._items.indexOf(child);
978
- child._setParentLink(this, newKey), sortListItem(this._items);
981
+ child._setParentLink(this, newKey), this._sortItems();
979
982
  var _newIndex4 = this._items.indexOf(child);
980
983
  return _newIndex4 === previousIndex
981
984
  ? { modified: !1 }
@@ -996,7 +999,7 @@ var LiveList = (function (_AbstractCrdt) {
996
999
  )
997
1000
  );
998
1001
  var _previousIndex = this._items.indexOf(child);
999
- child._setParentLink(this, newKey), sortListItem(this._items);
1002
+ child._setParentLink(this, newKey), this._sortItems();
1000
1003
  var _newIndex5 = this._items.indexOf(child);
1001
1004
  return _newIndex5 === _previousIndex
1002
1005
  ? { modified: !1 }
@@ -1026,8 +1029,7 @@ var LiveList = (function (_AbstractCrdt) {
1026
1029
  );
1027
1030
  return (
1028
1031
  child._setParentLink(this, newKey),
1029
- this._items.push(child),
1030
- sortListItem(this._items),
1032
+ this._insertAndSort(child),
1031
1033
  { modified: !1 }
1032
1034
  );
1033
1035
  }
@@ -1046,7 +1048,7 @@ var LiveList = (function (_AbstractCrdt) {
1046
1048
  )
1047
1049
  ),
1048
1050
  child._setParentLink(this, newKey),
1049
- sortListItem(this._items);
1051
+ this._sortItems();
1050
1052
  var newIndex = this._items.indexOf(child);
1051
1053
  return previousIndex === newIndex
1052
1054
  ? { modified: !1 }
@@ -1072,7 +1074,7 @@ var LiveList = (function (_AbstractCrdt) {
1072
1074
  : _this$_items4._getParentKeyOrThrow()
1073
1075
  )
1074
1076
  );
1075
- child._setParentLink(this, newKey), sortListItem(this._items);
1077
+ child._setParentLink(this, newKey), this._sortItems();
1076
1078
  var newIndex = this._items.indexOf(child);
1077
1079
  return previousIndex === newIndex
1078
1080
  ? { modified: !1 }
@@ -1130,8 +1132,7 @@ var LiveList = (function (_AbstractCrdt) {
1130
1132
  value = lsonToLiveNode(element);
1131
1133
  if (
1132
1134
  (value._setParentLink(this, position),
1133
- this._items.push(value),
1134
- sortListItem(this._items),
1135
+ this._insertAndSort(value),
1135
1136
  this._doc && this._id)
1136
1137
  ) {
1137
1138
  var id = this._doc.generateId();
@@ -1172,7 +1173,7 @@ var LiveList = (function (_AbstractCrdt) {
1172
1173
  previousPosition = item._getParentKeyOrThrow();
1173
1174
  if (
1174
1175
  (item._setParentLink(this, position),
1175
- sortListItem(this._items),
1176
+ this._sortItems(),
1176
1177
  this._doc && this._id)
1177
1178
  ) {
1178
1179
  var storageUpdates = new Map([
@@ -1349,8 +1350,7 @@ var LiveList = (function (_AbstractCrdt) {
1349
1350
  return (
1350
1351
  newItem._attach(op.id, nn(this._doc)),
1351
1352
  newItem._setParentLink(this, key),
1352
- this._items.push(newItem),
1353
- sortListItem(this._items),
1353
+ this._insertAndSort(newItem),
1354
1354
  { newItem: newItem, newIndex: this._indexOfPosition(key) }
1355
1355
  );
1356
1356
  }),
@@ -1426,14 +1426,6 @@ function moveDelta(previousIndex, index, item) {
1426
1426
  item: item instanceof LiveRegister ? item.data : item,
1427
1427
  };
1428
1428
  }
1429
- function sortListItem(items) {
1430
- items.sort(function (itemA, itemB) {
1431
- return comparePosition(
1432
- itemA._getParentKeyOrThrow(),
1433
- itemB._getParentKeyOrThrow()
1434
- );
1435
- });
1436
- }
1437
1429
  function addIntentAndDeletedIdToOperation(ops, deletedId) {
1438
1430
  if (0 === ops.length)
1439
1431
  throw new Error(
package/shared.mjs CHANGED
@@ -363,6 +363,12 @@ function comparePosition(posA, posB) {
363
363
  `Impossible to compare similar position "${posA}" and "${posB}"`
364
364
  );
365
365
  }
366
+ function compareNodePosition(itemA, itemB) {
367
+ return comparePosition(
368
+ itemA._getParentKeyOrThrow(),
369
+ itemB._getParentKeyOrThrow()
370
+ );
371
+ }
366
372
  class LiveList extends AbstractCrdt {
367
373
  constructor(items = []) {
368
374
  let position;
@@ -385,9 +391,7 @@ class LiveList extends AbstractCrdt {
385
391
  if (null == children) return list;
386
392
  for (const [id, crdt] of children) {
387
393
  const child = deserialize([id, crdt], parentToChildren, doc);
388
- child._setParentLink(list, crdt.parentKey),
389
- list._items.push(child),
390
- sortListItem(list._items);
394
+ child._setParentLink(list, crdt.parentKey), list._insertAndSort(child);
391
395
  }
392
396
  return list;
393
397
  }
@@ -407,6 +411,12 @@ class LiveList extends AbstractCrdt {
407
411
  ops.push(...item._serialize(this._id, item._getParentKeyOrThrow(), doc));
408
412
  return ops;
409
413
  }
414
+ _insertAndSort(item) {
415
+ this._items.push(item), this._sortItems();
416
+ }
417
+ _sortItems() {
418
+ this._items.sort(compareNodePosition);
419
+ }
410
420
  _indexOfPosition(position) {
411
421
  return this._items.findIndex(
412
422
  (item) => item._getParentKeyOrThrow() === position
@@ -457,8 +467,7 @@ class LiveList extends AbstractCrdt {
457
467
  deleteDelta = this._detachItemAssociatedToSetOperation(op.deletedId);
458
468
  return (
459
469
  deleteDelta && updates.push(deleteDelta),
460
- this._items.push(child),
461
- sortListItem(this._items),
470
+ this._insertAndSort(child),
462
471
  updates.push(insertDelta(this._indexOfPosition(key), child)),
463
472
  { reverse: [], modified: makeUpdate(this, updates) }
464
473
  );
@@ -493,8 +502,7 @@ class LiveList extends AbstractCrdt {
493
502
  this._items.splice(indexOfItemWithSamePosition, 1),
494
503
  delta.push(deleteDelta(indexOfItemWithSamePosition)));
495
504
  const previousIndex = this._items.indexOf(existingItem);
496
- existingItem._setParentLink(this, op.parentKey),
497
- sortListItem(this._items);
505
+ existingItem._setParentLink(this, op.parentKey), this._sortItems();
498
506
  const newIndex = this._items.indexOf(existingItem);
499
507
  return (
500
508
  newIndex !== previousIndex &&
@@ -507,8 +515,7 @@ class LiveList extends AbstractCrdt {
507
515
  if (orphan && this._implicitlyDeletedItems.has(orphan)) {
508
516
  orphan._setParentLink(this, op.parentKey),
509
517
  this._implicitlyDeletedItems.delete(orphan),
510
- this._items.push(orphan),
511
- sortListItem(this._items);
518
+ this._insertAndSort(orphan);
512
519
  const recreatedItemIndex = this._items.indexOf(orphan);
513
520
  return {
514
521
  modified: makeUpdate(this, [
@@ -568,7 +575,7 @@ class LiveList extends AbstractCrdt {
568
575
  -1 !== itemIndexAtPosition &&
569
576
  this._shiftItemPosition(itemIndexAtPosition, key),
570
577
  existingItem._setParentLink(this, key),
571
- sortListItem(this._items);
578
+ this._sortItems();
572
579
  const newIndex = this._indexOfPosition(key);
573
580
  return newIndex === oldPositionIndex
574
581
  ? { modified: !1 }
@@ -585,8 +592,7 @@ class LiveList extends AbstractCrdt {
585
592
  if (orphan && this._implicitlyDeletedItems.has(orphan)) {
586
593
  orphan._setParentLink(this, key),
587
594
  this._implicitlyDeletedItems.delete(orphan),
588
- this._items.push(orphan),
589
- sortListItem(this._items);
595
+ this._insertAndSort(orphan);
590
596
  return {
591
597
  modified: makeUpdate(this, [
592
598
  insertDelta(this._indexOfPosition(key), orphan),
@@ -629,7 +635,7 @@ class LiveList extends AbstractCrdt {
629
635
  )),
630
636
  child._setParentLink(this, newKey);
631
637
  }
632
- this._items.push(child), sortListItem(this._items);
638
+ this._insertAndSort(child);
633
639
  return {
634
640
  modified: makeUpdate(this, [
635
641
  insertDelta(this._indexOfPosition(newKey), child),
@@ -663,8 +669,7 @@ class LiveList extends AbstractCrdt {
663
669
  );
664
670
  }
665
671
  {
666
- this._items.push(child),
667
- sortListItem(this._items),
672
+ this._insertAndSort(child),
668
673
  this._detachItemAssociatedToSetOperation(op.deletedId);
669
674
  const newIndex = this._indexOfPosition(newKey);
670
675
  return {
@@ -709,8 +714,7 @@ class LiveList extends AbstractCrdt {
709
714
  if (this._implicitlyDeletedItems.has(child)) {
710
715
  this._implicitlyDeletedItems.delete(child),
711
716
  child._setParentLink(this, newKey),
712
- this._items.push(child),
713
- sortListItem(this._items);
717
+ this._insertAndSort(child);
714
718
  return {
715
719
  modified: makeUpdate(this, [
716
720
  insertDelta(this._items.indexOf(child), child),
@@ -722,7 +726,7 @@ class LiveList extends AbstractCrdt {
722
726
  const existingItemIndex = this._indexOfPosition(newKey);
723
727
  if (-1 === existingItemIndex) {
724
728
  const previousIndex = this._items.indexOf(child);
725
- child._setParentLink(this, newKey), sortListItem(this._items);
729
+ child._setParentLink(this, newKey), this._sortItems();
726
730
  const newIndex = this._items.indexOf(child);
727
731
  return newIndex === previousIndex
728
732
  ? { modified: !1 }
@@ -744,7 +748,7 @@ class LiveList extends AbstractCrdt {
744
748
  )
745
749
  );
746
750
  const previousIndex = this._items.indexOf(child);
747
- child._setParentLink(this, newKey), sortListItem(this._items);
751
+ child._setParentLink(this, newKey), this._sortItems();
748
752
  const newIndex = this._items.indexOf(child);
749
753
  return newIndex === previousIndex
750
754
  ? { modified: !1 }
@@ -775,8 +779,7 @@ class LiveList extends AbstractCrdt {
775
779
  )
776
780
  ),
777
781
  child._setParentLink(this, newKey),
778
- this._items.push(child),
779
- sortListItem(this._items),
782
+ this._insertAndSort(child),
780
783
  { modified: !1 }
781
784
  );
782
785
  }
@@ -795,7 +798,7 @@ class LiveList extends AbstractCrdt {
795
798
  )
796
799
  ),
797
800
  child._setParentLink(this, newKey),
798
- sortListItem(this._items);
801
+ this._sortItems();
799
802
  const newIndex = this._items.indexOf(child);
800
803
  return previousIndex === newIndex
801
804
  ? { modified: !1 }
@@ -823,7 +826,7 @@ class LiveList extends AbstractCrdt {
823
826
  )
824
827
  ),
825
828
  child._setParentLink(this, newKey),
826
- sortListItem(this._items);
829
+ this._sortItems();
827
830
  const newIndex = this._items.indexOf(child);
828
831
  return previousIndex === newIndex
829
832
  ? { modified: !1 }
@@ -879,8 +882,7 @@ class LiveList extends AbstractCrdt {
879
882
  value = lsonToLiveNode(element);
880
883
  if (
881
884
  (value._setParentLink(this, position),
882
- this._items.push(value),
883
- sortListItem(this._items),
885
+ this._insertAndSort(value),
884
886
  this._doc && this._id)
885
887
  ) {
886
888
  const id = this._doc.generateId();
@@ -919,7 +921,7 @@ class LiveList extends AbstractCrdt {
919
921
  previousPosition = item._getParentKeyOrThrow();
920
922
  if (
921
923
  (item._setParentLink(this, position),
922
- sortListItem(this._items),
924
+ this._sortItems(),
923
925
  this._doc && this._id)
924
926
  ) {
925
927
  const storageUpdates = new Map([
@@ -1073,8 +1075,7 @@ class LiveList extends AbstractCrdt {
1073
1075
  const newItem = creationOpToLiveNode(op);
1074
1076
  newItem._attach(op.id, nn(this._doc)),
1075
1077
  newItem._setParentLink(this, key),
1076
- this._items.push(newItem),
1077
- sortListItem(this._items);
1078
+ this._insertAndSort(newItem);
1078
1079
  return { newItem: newItem, newIndex: this._indexOfPosition(key) };
1079
1080
  }
1080
1081
  _shiftItemPosition(index, key) {
@@ -1131,11 +1132,6 @@ function moveDelta(previousIndex, index, item) {
1131
1132
  item: item instanceof LiveRegister ? item.data : item,
1132
1133
  };
1133
1134
  }
1134
- function sortListItem(items) {
1135
- items.sort((itemA, itemB) =>
1136
- comparePosition(itemA._getParentKeyOrThrow(), itemB._getParentKeyOrThrow())
1137
- );
1138
- }
1139
1135
  function addIntentAndDeletedIdToOperation(ops, deletedId) {
1140
1136
  if (0 === ops.length)
1141
1137
  throw new Error(