@itrocks/sync 0.0.0-stage → 0.1.0

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.
Files changed (156) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +249 -2
  3. package/config.yaml +2 -0
  4. package/demo/src/demo.css +458 -0
  5. package/dist/client/author-background.d.ts +2 -0
  6. package/dist/client/author-background.js +28 -0
  7. package/dist/client/clock.d.ts +10 -0
  8. package/dist/client/clock.js +30 -0
  9. package/dist/client/collections/order.d.ts +10 -0
  10. package/dist/client/collections/order.js +77 -0
  11. package/dist/client/collections/reorder-nodes.d.ts +2 -0
  12. package/dist/client/collections/reorder-nodes.js +67 -0
  13. package/dist/client/collections/row-changes.d.ts +12 -0
  14. package/dist/client/collections/row-changes.js +26 -0
  15. package/dist/client/collections/row-history.d.ts +16 -0
  16. package/dist/client/collections/row-history.js +61 -0
  17. package/dist/client/collections/table-columns.d.ts +19 -0
  18. package/dist/client/collections/table-columns.js +200 -0
  19. package/dist/client/collections.d.ts +54 -0
  20. package/dist/client/collections.js +262 -0
  21. package/dist/client/discovery.d.ts +1 -0
  22. package/dist/client/discovery.js +57 -0
  23. package/dist/client/field-address.d.ts +38 -0
  24. package/dist/client/field-address.js +225 -0
  25. package/dist/client/field-value.d.ts +7 -0
  26. package/dist/client/field-value.js +105 -0
  27. package/dist/client/form-identity.d.ts +1 -0
  28. package/dist/client/form-identity.js +43 -0
  29. package/dist/client/form-session.d.ts +53 -0
  30. package/dist/client/form-session.js +218 -0
  31. package/dist/client/identity.d.ts +3 -0
  32. package/dist/client/identity.js +27 -0
  33. package/dist/client/index.d.ts +43 -0
  34. package/dist/client/index.js +109 -0
  35. package/dist/client/journal.d.ts +13 -0
  36. package/dist/client/journal.js +59 -0
  37. package/dist/client/lifecycle.d.ts +26 -0
  38. package/dist/client/lifecycle.js +112 -0
  39. package/dist/client/observation.d.ts +11 -0
  40. package/dist/client/observation.js +46 -0
  41. package/dist/client/outbox.d.ts +15 -0
  42. package/dist/client/outbox.js +71 -0
  43. package/dist/client/plugin.d.ts +42 -0
  44. package/dist/client/plugin.js +1 -0
  45. package/dist/client/plugins/column-order/apply.d.ts +2 -0
  46. package/dist/client/plugins/column-order/apply.js +30 -0
  47. package/dist/client/plugins/column-order/colgroups.d.ts +2 -0
  48. package/dist/client/plugins/column-order/colgroups.js +78 -0
  49. package/dist/client/plugins/column-order/index.d.ts +2 -0
  50. package/dist/client/plugins/column-order/index.js +98 -0
  51. package/dist/client/plugins/cursor/editable.d.ts +16 -0
  52. package/dist/client/plugins/cursor/editable.js +67 -0
  53. package/dist/client/plugins/cursor/geometry.d.ts +16 -0
  54. package/dist/client/plugins/cursor/geometry.js +122 -0
  55. package/dist/client/plugins/cursor/index.d.ts +4 -0
  56. package/dist/client/plugins/cursor/index.js +13 -0
  57. package/dist/client/plugins/cursor/indicators.d.ts +31 -0
  58. package/dist/client/plugins/cursor/indicators.js +144 -0
  59. package/dist/client/plugins/cursor/local-selection.d.ts +19 -0
  60. package/dist/client/plugins/cursor/local-selection.js +234 -0
  61. package/dist/client/plugins/cursor/selection.d.ts +9 -0
  62. package/dist/client/plugins/cursor/selection.js +49 -0
  63. package/dist/client/plugins/cursor/text-presence.d.ts +15 -0
  64. package/dist/client/plugins/cursor/text-presence.js +95 -0
  65. package/dist/client/plugins/fields/author.d.ts +7 -0
  66. package/dist/client/plugins/fields/author.js +22 -0
  67. package/dist/client/plugins/fields/index.d.ts +4 -0
  68. package/dist/client/plugins/fields/index.js +192 -0
  69. package/dist/client/plugins/fields/writes.d.ts +19 -0
  70. package/dist/client/plugins/fields/writes.js +51 -0
  71. package/dist/client/plugins/focus/index.d.ts +9 -0
  72. package/dist/client/plugins/focus/index.js +92 -0
  73. package/dist/client/plugins/focus/indicators.d.ts +19 -0
  74. package/dist/client/plugins/focus/indicators.js +163 -0
  75. package/dist/client/plugins/naming/algorithm.d.ts +7 -0
  76. package/dist/client/plugins/naming/algorithm.js +65 -0
  77. package/dist/client/plugins/naming/attributes.d.ts +16 -0
  78. package/dist/client/plugins/naming/attributes.js +195 -0
  79. package/dist/client/plugins/naming/index.d.ts +5 -0
  80. package/dist/client/plugins/naming/index.js +185 -0
  81. package/dist/client/plugins/range/index.d.ts +4 -0
  82. package/dist/client/plugins/range/index.js +15 -0
  83. package/dist/client/plugins/reconciliation/index.d.ts +6 -0
  84. package/dist/client/plugins/reconciliation/index.js +282 -0
  85. package/dist/client/plugins/reconciliation/matching.d.ts +12 -0
  86. package/dist/client/plugins/reconciliation/matching.js +37 -0
  87. package/dist/client/plugins/reconciliation/proposals.d.ts +11 -0
  88. package/dist/client/plugins/reconciliation/proposals.js +32 -0
  89. package/dist/client/plugins/row-order/index.d.ts +2 -0
  90. package/dist/client/plugins/row-order/index.js +99 -0
  91. package/dist/client/plugins/rows/clone.d.ts +2 -0
  92. package/dist/client/plugins/rows/clone.js +123 -0
  93. package/dist/client/plugins/rows/index.d.ts +2 -0
  94. package/dist/client/plugins/rows/index.js +191 -0
  95. package/dist/client/plugins/rows/materialize.d.ts +4 -0
  96. package/dist/client/plugins/rows/materialize.js +43 -0
  97. package/dist/client/plugins/rows/remove.d.ts +1 -0
  98. package/dist/client/plugins/rows/remove.js +13 -0
  99. package/dist/client/plugins/rows/template.d.ts +2 -0
  100. package/dist/client/plugins/rows/template.js +21 -0
  101. package/dist/client/transport.d.ts +23 -0
  102. package/dist/client/transport.js +128 -0
  103. package/dist/client/user-colour.d.ts +3 -0
  104. package/dist/client/user-colour.js +11 -0
  105. package/dist/server/acknowledgments.d.ts +3 -0
  106. package/dist/server/acknowledgments.js +8 -0
  107. package/dist/server/broadcast.d.ts +3 -0
  108. package/dist/server/broadcast.js +7 -0
  109. package/dist/server/cli.d.ts +2 -0
  110. package/dist/server/cli.js +44 -0
  111. package/dist/server/clock.d.ts +2 -0
  112. package/dist/server/clock.js +3 -0
  113. package/dist/server/configuration.d.ts +3 -0
  114. package/dist/server/configuration.js +7 -0
  115. package/dist/server/connection.d.ts +13 -0
  116. package/dist/server/connection.js +1 -0
  117. package/dist/server/express.d.ts +2 -0
  118. package/dist/server/express.js +1 -0
  119. package/dist/server/fastify.d.ts +10 -0
  120. package/dist/server/fastify.js +15 -0
  121. package/dist/server/index.d.ts +7 -0
  122. package/dist/server/index.js +1 -0
  123. package/dist/server/journal.d.ts +7 -0
  124. package/dist/server/journal.js +16 -0
  125. package/dist/server/messages.d.ts +4 -0
  126. package/dist/server/messages.js +106 -0
  127. package/dist/server/participants.d.ts +9 -0
  128. package/dist/server/participants.js +7 -0
  129. package/dist/server/receipts.d.ts +13 -0
  130. package/dist/server/receipts.js +28 -0
  131. package/dist/server/recovery.d.ts +3 -0
  132. package/dist/server/recovery.js +9 -0
  133. package/dist/server/server.d.ts +34 -0
  134. package/dist/server/server.js +189 -0
  135. package/dist/server/sessions.d.ts +16 -0
  136. package/dist/server/sessions.js +37 -0
  137. package/dist/server/standalone.d.ts +9 -0
  138. package/dist/server/standalone.js +12 -0
  139. package/dist/server/transactions.d.ts +15 -0
  140. package/dist/server/transactions.js +50 -0
  141. package/dist/server/websocket-connection.d.ts +3 -0
  142. package/dist/server/websocket-connection.js +38 -0
  143. package/dist/server/websocket.d.ts +11 -0
  144. package/dist/server/websocket.js +26 -0
  145. package/dist/shared/field-update.d.ts +12 -0
  146. package/dist/shared/field-update.js +18 -0
  147. package/dist/shared/journal-entries.d.ts +9 -0
  148. package/dist/shared/journal-entries.js +33 -0
  149. package/dist/shared/protocol.d.ts +105 -0
  150. package/dist/shared/protocol.js +15 -0
  151. package/docs/dependencies.md +130 -0
  152. package/docs/spec-addendum-dependencies.md +10 -0
  153. package/docs/spec-addendum.md +717 -0
  154. package/docs/spec.md +1165 -0
  155. package/docs/testing.md +39 -0
  156. package/package.json +96 -5
@@ -0,0 +1,195 @@
1
+ const references = [
2
+ 'aria-activedescendant',
3
+ 'aria-controls',
4
+ 'aria-describedby',
5
+ 'aria-details',
6
+ 'aria-errormessage',
7
+ 'aria-flowto',
8
+ 'aria-labelledby',
9
+ 'aria-owns',
10
+ 'commandfor',
11
+ 'for',
12
+ 'form',
13
+ 'headers',
14
+ 'href',
15
+ 'list',
16
+ 'popovertarget'
17
+ ];
18
+ const attributes = [...references, 'id', 'name'];
19
+ export function applyNames(row, names) {
20
+ const elements = rowElements(row);
21
+ const matches = new Map();
22
+ for (const element of elements) {
23
+ const key = elementKey(element);
24
+ const group = matches.get(key);
25
+ if (group) {
26
+ group.push(element);
27
+ }
28
+ else {
29
+ matches.set(key, [element]);
30
+ }
31
+ }
32
+ for (const { attributes, index, key, occurrence, tag } of names) {
33
+ const element = matches.get(key)?.[occurrence] ?? elements[index];
34
+ if (element?.localName !== tag)
35
+ continue;
36
+ for (const [attribute, value] of Object.entries(attributes)) {
37
+ if (element.getAttribute(attribute) !== value) {
38
+ element.setAttribute(attribute, value);
39
+ }
40
+ }
41
+ }
42
+ }
43
+ export function controlNames(row) {
44
+ return rowElements(row).flatMap(element => element.getAttribute('name') || []);
45
+ }
46
+ export function indexOverlaps(row, names, naming) {
47
+ return controlNames(row).some(name => names.has(name) && isIndex(name, naming));
48
+ }
49
+ export function namesOverlap(row, names, ids) {
50
+ return rowElements(row).some(element => names.has(element.getAttribute('name') ?? '')
51
+ || ids.has(element.id));
52
+ }
53
+ export function parseNames(value) {
54
+ if (!Array.isArray(value))
55
+ return;
56
+ const names = [];
57
+ for (const entry of value) {
58
+ if (!entry || (typeof entry !== 'object')
59
+ || (typeof entry.tag !== 'string') || (typeof entry.key !== 'string')
60
+ || !Number.isSafeInteger(entry.index) || (entry.index < 0)
61
+ || !Number.isSafeInteger(entry.occurrence) || (entry.occurrence < 0)
62
+ || !entry.attributes || (typeof entry.attributes !== 'object'))
63
+ return;
64
+ const properties = Object.fromEntries(Object.entries(entry.attributes).filter(([attribute, value]) => attributes.includes(attribute) && (typeof value === 'string')
65
+ && ((attribute !== 'href') || value.startsWith('#'))));
66
+ names.push({
67
+ attributes: properties,
68
+ index: entry.index,
69
+ key: entry.key,
70
+ occurrence: entry.occurrence,
71
+ tag: entry.tag
72
+ });
73
+ }
74
+ return names;
75
+ }
76
+ export function readNames(row) {
77
+ const names = [];
78
+ const occurrences = new Map();
79
+ for (const [index, element] of rowElements(row).entries()) {
80
+ const key = elementKey(element);
81
+ const occurrence = occurrences.get(key) ?? 0;
82
+ const values = readAttributes(element);
83
+ occurrences.set(key, occurrence + 1);
84
+ if (Object.keys(values).length) {
85
+ names.push({ attributes: values, index, key, occurrence, tag: element.localName });
86
+ }
87
+ }
88
+ return names;
89
+ }
90
+ export function rememberNames(row, names, ids) {
91
+ for (const element of rowElements(row)) {
92
+ const name = element.getAttribute('name');
93
+ if (name) {
94
+ names.add(name);
95
+ }
96
+ if (element.id) {
97
+ ids.add(element.id);
98
+ }
99
+ }
100
+ }
101
+ export function renameRow(row, naming, collisions, id) {
102
+ const changed = new Map();
103
+ const elements = rowElements(row);
104
+ const reserved = new Set([...collisions, ...elements.map(element => element.id)]);
105
+ for (const element of elements) {
106
+ const name = element.getAttribute('name');
107
+ if (naming && name && isIndex(name, naming)) {
108
+ element.setAttribute('name', indexedValue(name, naming.prefix.length, naming));
109
+ }
110
+ if (!element.id)
111
+ continue;
112
+ const previous = element.id;
113
+ const collision = collisions.has(previous);
114
+ const indexed = naming && indexedId(previous, naming, collision);
115
+ const expected = indexed ?? previous;
116
+ const next = (collision || (expected !== previous)) && reserved.has(expected)
117
+ ? uniqueId(expected, id, reserved)
118
+ : expected;
119
+ if (next !== previous) {
120
+ element.id = next;
121
+ reserved.add(next);
122
+ changed.set(previous, next);
123
+ }
124
+ }
125
+ for (const element of elements) {
126
+ for (const attribute of references) {
127
+ const value = element.getAttribute(attribute);
128
+ if (!value)
129
+ continue;
130
+ const next = (attribute === 'href')
131
+ ? replaceAnchor(value, changed)
132
+ : value.replace(/[^\s]+/g, key => changed.get(key) ?? key);
133
+ if (next !== value) {
134
+ element.setAttribute(attribute, next);
135
+ }
136
+ }
137
+ }
138
+ }
139
+ function elementKey(element) {
140
+ const identity = element.getAttribute('name') ?? element.getAttribute('id') ?? element.getAttribute('for');
141
+ return element.localName + '#' + (identity?.replace(/(^|[.\[\]_-])\d+(?=$|[.\[\]_-])/g, '$1*') ?? '');
142
+ }
143
+ function indexedId(value, naming, collision) {
144
+ const parts = [...value.matchAll(/[^.\[\]_-]+/g)];
145
+ const scope = naming.prefix.match(/[^.\[\]_-]+/g) ?? [];
146
+ const slots = parts.filter(part => part[0] === naming.previous);
147
+ const slot = parts.find((part, index) => (part[0] === naming.previous)
148
+ && (index >= scope.length)
149
+ && scope.every((label, offset) => label === parts[index - scope.length + offset][0]))
150
+ ?? ((collision && (slots.length === 1)) ? slots[0] : undefined);
151
+ if (slot) {
152
+ return indexedValue(value, slot.index, naming);
153
+ }
154
+ }
155
+ function indexedValue(value, offset, naming) {
156
+ return value.slice(0, offset) + naming.index + value.slice(offset + naming.previous.length);
157
+ }
158
+ function isIndex(value, naming) {
159
+ const prefix = naming.prefix + naming.previous;
160
+ if (!value.startsWith(prefix))
161
+ return false;
162
+ const suffix = value.slice(prefix.length);
163
+ return naming.prefix.endsWith('[')
164
+ ? suffix.startsWith(']')
165
+ : ((suffix === '') || /^[.\[]/.test(suffix));
166
+ }
167
+ function readAttributes(element) {
168
+ const values = {};
169
+ for (const attribute of attributes) {
170
+ const value = element.getAttribute(attribute);
171
+ if ((value !== null) && ((attribute !== 'href') || value.startsWith('#'))) {
172
+ values[attribute] = value;
173
+ }
174
+ }
175
+ return values;
176
+ }
177
+ function replaceAnchor(value, changed) {
178
+ if (!value.startsWith('#'))
179
+ return value;
180
+ const id = changed.get(value.slice(1));
181
+ return id ? ('#' + id) : value;
182
+ }
183
+ function rowElements(row) {
184
+ return [row, ...row.querySelectorAll('*')];
185
+ }
186
+ function uniqueId(previous, row, collisions) {
187
+ const prefix = previous + '-' + row.replace(/[^a-z\d_-]/gi, '_');
188
+ let suffix = '';
189
+ let index = 0;
190
+ while (collisions.has(prefix + suffix)) {
191
+ index++;
192
+ suffix = '-' + index;
193
+ }
194
+ return prefix + suffix;
195
+ }
@@ -0,0 +1,5 @@
1
+ import type { Plugin } from '../../plugin.js';
2
+ import type { FindNamingIndex } from './algorithm.js';
3
+ export type { FindNamingIndex } from './algorithm.js';
4
+ export type { NamingIndex } from './algorithm.js';
5
+ export declare function naming(algorithm?: FindNamingIndex): Plugin;
@@ -0,0 +1,185 @@
1
+ import { compareTransactions } from '../../../shared/protocol.js';
2
+ import { findNamingIndex } from './algorithm.js';
3
+ import { applyNames } from './attributes.js';
4
+ import { controlNames } from './attributes.js';
5
+ import { indexOverlaps } from './attributes.js';
6
+ import { namesOverlap } from './attributes.js';
7
+ import { parseNames } from './attributes.js';
8
+ import { readNames } from './attributes.js';
9
+ import { rememberNames } from './attributes.js';
10
+ import { renameRow } from './attributes.js';
11
+ const transactionType = 'name-row';
12
+ export function naming(algorithm = findNamingIndex) {
13
+ return {
14
+ name: 'naming',
15
+ init(context) {
16
+ const state = new Naming(context, algorithm);
17
+ context.collections.managedNaming = true;
18
+ return {
19
+ destroy: () => state.destroy(),
20
+ flush: () => state.flush(),
21
+ observe: records => state.observe(records),
22
+ receive: transaction => state.receive(transaction)
23
+ };
24
+ }
25
+ };
26
+ }
27
+ function compareRows(first, second) {
28
+ if (first.initial !== second.initial)
29
+ return first.initial ? -1 : 1;
30
+ if (first.creator !== second.creator)
31
+ return (first.creator < second.creator) ? -1 : 1;
32
+ if (first.id !== second.id)
33
+ return (first.id < second.id) ? -1 : 1;
34
+ return 0;
35
+ }
36
+ function namesSignature(attributes) {
37
+ return JSON.stringify(attributes.map(({ attributes, key, occurrence }) => JSON.stringify([key, occurrence, attributes])).sort());
38
+ }
39
+ function occupiedNames(rows) {
40
+ const ids = new Set();
41
+ const names = new Set();
42
+ for (const row of rows) {
43
+ rememberNames(row.element, names, ids);
44
+ }
45
+ return { ids, names };
46
+ }
47
+ function rowKey(row, creator) {
48
+ return JSON.stringify([row, creator]);
49
+ }
50
+ class Naming {
51
+ context;
52
+ algorithm;
53
+ #applied = new WeakMap();
54
+ #dirty = true;
55
+ #known = new WeakSet();
56
+ #mounted = new WeakMap();
57
+ #pending = new Set();
58
+ #sent = new WeakMap();
59
+ #updates = new Map();
60
+ constructor(context, algorithm) {
61
+ this.context = context;
62
+ this.algorithm = algorithm;
63
+ }
64
+ destroy() {
65
+ this.context.collections.managedNaming = false;
66
+ this.#pending.clear();
67
+ this.#updates.clear();
68
+ }
69
+ flush() {
70
+ const { collections } = this.context;
71
+ const dirty = this.#dirty;
72
+ const pending = this.#pending;
73
+ this.#dirty = false;
74
+ this.#pending = new Set();
75
+ for (const collection of collections.states()) {
76
+ const elements = collection.items();
77
+ if (!dirty && !pending.has(collection.id) && this.#sameRows(collection, elements))
78
+ continue;
79
+ const initial = new Set(collection.initial.map(id => collections.canonical(collection.id, id)));
80
+ const rows = elements.map(element => {
81
+ const id = collections.identify(collection, element);
82
+ return {
83
+ creator: collections.creator(collection.id, id) ?? this.context.client,
84
+ element,
85
+ id,
86
+ initial: initial.has(id)
87
+ };
88
+ });
89
+ this.#mounted.set(collection, rows);
90
+ const ordered = [...rows].sort(compareRows);
91
+ const updates = this.#latest(collection);
92
+ this.context.mute(() => this.#applyCollection(collection, ordered, updates));
93
+ }
94
+ }
95
+ observe(records) {
96
+ this.#dirty ||= records.some(record => (record.type === 'attributes') || ((record.type === 'childList')
97
+ && [...record.addedNodes, ...record.removedNodes].some(node => node.nodeType === Node.ELEMENT_NODE)));
98
+ }
99
+ receive(transaction) {
100
+ if (transaction.type !== transactionType) {
101
+ if (transaction.type !== 'field')
102
+ this.#dirty = true;
103
+ return;
104
+ }
105
+ const data = transaction.data;
106
+ if (!data || (typeof data.collection !== 'string') || (typeof data.row !== 'string'))
107
+ return;
108
+ const attributes = parseNames(data.attributes);
109
+ if (!attributes)
110
+ return;
111
+ const updates = this.#updates.get(data.collection) ?? new Map();
112
+ const key = rowKey(data.row, transaction.client);
113
+ const current = updates.get(key);
114
+ if (!current || (compareTransactions(transaction, current.transaction) > 0)) {
115
+ updates.set(key, { attributes, row: data.row, transaction });
116
+ this.#updates.set(data.collection, updates);
117
+ this.#pending.add(data.collection);
118
+ }
119
+ }
120
+ #applyCollection(collection, rows, updates) {
121
+ const ids = new Set();
122
+ const names = new Set();
123
+ for (const row of rows) {
124
+ if (!row.initial && (row.creator !== this.context.client)) {
125
+ const update = updates.get(rowKey(row.id, row.creator));
126
+ if (update) {
127
+ if (this.#applied.get(row.element) !== update.transaction) {
128
+ applyNames(row.element, update.attributes);
129
+ this.#applied.set(row.element, update.transaction);
130
+ }
131
+ }
132
+ else if (!this.#known.has(row.element)) {
133
+ const siblings = rows.filter(other => other !== row);
134
+ this.#rename(collection, row, siblings, occupiedNames(siblings), true);
135
+ }
136
+ }
137
+ else if (!row.initial) {
138
+ if (namesOverlap(row.element, names, ids)) {
139
+ this.#rename(collection, row, rows.filter(other => other !== row), { ids, names });
140
+ }
141
+ const attributes = readNames(row.element);
142
+ const signature = namesSignature(attributes);
143
+ if (signature !== this.#sent.get(row.element)) {
144
+ this.#sent.set(row.element, signature);
145
+ if (attributes.length) {
146
+ this.context.publish(transactionType, { attributes, collection: collection.id, row: row.id });
147
+ }
148
+ }
149
+ }
150
+ rememberNames(row.element, names, ids);
151
+ this.#known.add(row.element);
152
+ }
153
+ }
154
+ #latest(collection) {
155
+ const latest = new Map();
156
+ for (const update of this.#updates.get(collection.id)?.values() ?? []) {
157
+ const row = this.context.collections.canonical(collection.id, update.row);
158
+ const key = rowKey(row, update.transaction.client);
159
+ const previous = latest.get(key);
160
+ if (!previous || (compareTransactions(update.transaction, previous.transaction) > 0)) {
161
+ latest.set(key, update);
162
+ }
163
+ }
164
+ return latest;
165
+ }
166
+ #rename(collection, row, siblings, occupied, fresh = false) {
167
+ const callback = collection.options.naming;
168
+ if (callback) {
169
+ callback(row.element, collection.element);
170
+ return;
171
+ }
172
+ const detected = this.algorithm(controlNames(row.element), siblings.map(other => controlNames(other.element)));
173
+ const index = (detected && ((fresh && siblings.length) || indexOverlaps(row.element, occupied.names, detected)))
174
+ ? detected
175
+ : undefined;
176
+ renameRow(row.element, index, occupied.ids, row.id);
177
+ }
178
+ #sameRows(collection, elements) {
179
+ const previous = this.#mounted.get(collection);
180
+ if (previous?.length !== elements.length)
181
+ return false;
182
+ return previous.every(({ element, id }, index) => (element === elements[index])
183
+ && (this.context.collections.identify(collection, element) === id));
184
+ }
185
+ }
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from '../../plugin.js';
2
+ import type { SelectionSource } from '../cursor/local-selection.js';
3
+ export declare function range(): Plugin;
4
+ export declare function rememberedRange(source?: SelectionSource): Plugin;
@@ -0,0 +1,15 @@
1
+ import { rangesOf } from '../cursor/selection.js';
2
+ import { textPresence } from '../cursor/text-presence.js';
3
+ export function range() {
4
+ return rememberedRange();
5
+ }
6
+ export function rememberedRange(source) {
7
+ return textPresence('range', {
8
+ local(field, { offsets }) {
9
+ const ranges = rangesOf(offsets);
10
+ return ranges.length ? { field, ranges } : null;
11
+ },
12
+ remote: participant => participant.range,
13
+ send: (context, selection) => context.range(selection)
14
+ }, source);
15
+ }
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from '../../plugin.js';
2
+ import type { MatchRows } from './matching.js';
3
+ export type { MatchRows } from './matching.js';
4
+ export type { RowAssociation } from './matching.js';
5
+ export type { RowSnapshot } from './matching.js';
6
+ export declare function reconciliation(algorithm?: MatchRows): Plugin;