@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.
- package/LICENSE +165 -0
- package/README.md +249 -2
- package/config.yaml +2 -0
- package/demo/src/demo.css +458 -0
- package/dist/client/author-background.d.ts +2 -0
- package/dist/client/author-background.js +28 -0
- package/dist/client/clock.d.ts +10 -0
- package/dist/client/clock.js +30 -0
- package/dist/client/collections/order.d.ts +10 -0
- package/dist/client/collections/order.js +77 -0
- package/dist/client/collections/reorder-nodes.d.ts +2 -0
- package/dist/client/collections/reorder-nodes.js +67 -0
- package/dist/client/collections/row-changes.d.ts +12 -0
- package/dist/client/collections/row-changes.js +26 -0
- package/dist/client/collections/row-history.d.ts +16 -0
- package/dist/client/collections/row-history.js +61 -0
- package/dist/client/collections/table-columns.d.ts +19 -0
- package/dist/client/collections/table-columns.js +200 -0
- package/dist/client/collections.d.ts +54 -0
- package/dist/client/collections.js +262 -0
- package/dist/client/discovery.d.ts +1 -0
- package/dist/client/discovery.js +57 -0
- package/dist/client/field-address.d.ts +38 -0
- package/dist/client/field-address.js +225 -0
- package/dist/client/field-value.d.ts +7 -0
- package/dist/client/field-value.js +105 -0
- package/dist/client/form-identity.d.ts +1 -0
- package/dist/client/form-identity.js +43 -0
- package/dist/client/form-session.d.ts +53 -0
- package/dist/client/form-session.js +218 -0
- package/dist/client/identity.d.ts +3 -0
- package/dist/client/identity.js +27 -0
- package/dist/client/index.d.ts +43 -0
- package/dist/client/index.js +109 -0
- package/dist/client/journal.d.ts +13 -0
- package/dist/client/journal.js +59 -0
- package/dist/client/lifecycle.d.ts +26 -0
- package/dist/client/lifecycle.js +112 -0
- package/dist/client/observation.d.ts +11 -0
- package/dist/client/observation.js +46 -0
- package/dist/client/outbox.d.ts +15 -0
- package/dist/client/outbox.js +71 -0
- package/dist/client/plugin.d.ts +42 -0
- package/dist/client/plugin.js +1 -0
- package/dist/client/plugins/column-order/apply.d.ts +2 -0
- package/dist/client/plugins/column-order/apply.js +30 -0
- package/dist/client/plugins/column-order/colgroups.d.ts +2 -0
- package/dist/client/plugins/column-order/colgroups.js +78 -0
- package/dist/client/plugins/column-order/index.d.ts +2 -0
- package/dist/client/plugins/column-order/index.js +98 -0
- package/dist/client/plugins/cursor/editable.d.ts +16 -0
- package/dist/client/plugins/cursor/editable.js +67 -0
- package/dist/client/plugins/cursor/geometry.d.ts +16 -0
- package/dist/client/plugins/cursor/geometry.js +122 -0
- package/dist/client/plugins/cursor/index.d.ts +4 -0
- package/dist/client/plugins/cursor/index.js +13 -0
- package/dist/client/plugins/cursor/indicators.d.ts +31 -0
- package/dist/client/plugins/cursor/indicators.js +144 -0
- package/dist/client/plugins/cursor/local-selection.d.ts +19 -0
- package/dist/client/plugins/cursor/local-selection.js +234 -0
- package/dist/client/plugins/cursor/selection.d.ts +9 -0
- package/dist/client/plugins/cursor/selection.js +49 -0
- package/dist/client/plugins/cursor/text-presence.d.ts +15 -0
- package/dist/client/plugins/cursor/text-presence.js +95 -0
- package/dist/client/plugins/fields/author.d.ts +7 -0
- package/dist/client/plugins/fields/author.js +22 -0
- package/dist/client/plugins/fields/index.d.ts +4 -0
- package/dist/client/plugins/fields/index.js +192 -0
- package/dist/client/plugins/fields/writes.d.ts +19 -0
- package/dist/client/plugins/fields/writes.js +51 -0
- package/dist/client/plugins/focus/index.d.ts +9 -0
- package/dist/client/plugins/focus/index.js +92 -0
- package/dist/client/plugins/focus/indicators.d.ts +19 -0
- package/dist/client/plugins/focus/indicators.js +163 -0
- package/dist/client/plugins/naming/algorithm.d.ts +7 -0
- package/dist/client/plugins/naming/algorithm.js +65 -0
- package/dist/client/plugins/naming/attributes.d.ts +16 -0
- package/dist/client/plugins/naming/attributes.js +195 -0
- package/dist/client/plugins/naming/index.d.ts +5 -0
- package/dist/client/plugins/naming/index.js +185 -0
- package/dist/client/plugins/range/index.d.ts +4 -0
- package/dist/client/plugins/range/index.js +15 -0
- package/dist/client/plugins/reconciliation/index.d.ts +6 -0
- package/dist/client/plugins/reconciliation/index.js +282 -0
- package/dist/client/plugins/reconciliation/matching.d.ts +12 -0
- package/dist/client/plugins/reconciliation/matching.js +37 -0
- package/dist/client/plugins/reconciliation/proposals.d.ts +11 -0
- package/dist/client/plugins/reconciliation/proposals.js +32 -0
- package/dist/client/plugins/row-order/index.d.ts +2 -0
- package/dist/client/plugins/row-order/index.js +99 -0
- package/dist/client/plugins/rows/clone.d.ts +2 -0
- package/dist/client/plugins/rows/clone.js +123 -0
- package/dist/client/plugins/rows/index.d.ts +2 -0
- package/dist/client/plugins/rows/index.js +191 -0
- package/dist/client/plugins/rows/materialize.d.ts +4 -0
- package/dist/client/plugins/rows/materialize.js +43 -0
- package/dist/client/plugins/rows/remove.d.ts +1 -0
- package/dist/client/plugins/rows/remove.js +13 -0
- package/dist/client/plugins/rows/template.d.ts +2 -0
- package/dist/client/plugins/rows/template.js +21 -0
- package/dist/client/transport.d.ts +23 -0
- package/dist/client/transport.js +128 -0
- package/dist/client/user-colour.d.ts +3 -0
- package/dist/client/user-colour.js +11 -0
- package/dist/server/acknowledgments.d.ts +3 -0
- package/dist/server/acknowledgments.js +8 -0
- package/dist/server/broadcast.d.ts +3 -0
- package/dist/server/broadcast.js +7 -0
- package/dist/server/cli.d.ts +2 -0
- package/dist/server/cli.js +44 -0
- package/dist/server/clock.d.ts +2 -0
- package/dist/server/clock.js +3 -0
- package/dist/server/configuration.d.ts +3 -0
- package/dist/server/configuration.js +7 -0
- package/dist/server/connection.d.ts +13 -0
- package/dist/server/connection.js +1 -0
- package/dist/server/express.d.ts +2 -0
- package/dist/server/express.js +1 -0
- package/dist/server/fastify.d.ts +10 -0
- package/dist/server/fastify.js +15 -0
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.js +1 -0
- package/dist/server/journal.d.ts +7 -0
- package/dist/server/journal.js +16 -0
- package/dist/server/messages.d.ts +4 -0
- package/dist/server/messages.js +106 -0
- package/dist/server/participants.d.ts +9 -0
- package/dist/server/participants.js +7 -0
- package/dist/server/receipts.d.ts +13 -0
- package/dist/server/receipts.js +28 -0
- package/dist/server/recovery.d.ts +3 -0
- package/dist/server/recovery.js +9 -0
- package/dist/server/server.d.ts +34 -0
- package/dist/server/server.js +189 -0
- package/dist/server/sessions.d.ts +16 -0
- package/dist/server/sessions.js +37 -0
- package/dist/server/standalone.d.ts +9 -0
- package/dist/server/standalone.js +12 -0
- package/dist/server/transactions.d.ts +15 -0
- package/dist/server/transactions.js +50 -0
- package/dist/server/websocket-connection.d.ts +3 -0
- package/dist/server/websocket-connection.js +38 -0
- package/dist/server/websocket.d.ts +11 -0
- package/dist/server/websocket.js +26 -0
- package/dist/shared/field-update.d.ts +12 -0
- package/dist/shared/field-update.js +18 -0
- package/dist/shared/journal-entries.d.ts +9 -0
- package/dist/shared/journal-entries.js +33 -0
- package/dist/shared/protocol.d.ts +105 -0
- package/dist/shared/protocol.js +15 -0
- package/docs/dependencies.md +130 -0
- package/docs/spec-addendum-dependencies.md +10 -0
- package/docs/spec-addendum.md +717 -0
- package/docs/spec.md +1165 -0
- package/docs/testing.md +39 -0
- package/package.json +96 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
package/README.md
CHANGED
|
@@ -1,3 +1,250 @@
|
|
|
1
|
-
|
|
1
|
+
[](https://www.npmjs.org/package/@itrocks/sync)
|
|
2
|
+
[](https://www.npmjs.org/package/@itrocks/sync)
|
|
3
|
+
[](https://github.com/itrocks-ts/sync)
|
|
4
|
+
[](https://github.com/itrocks-ts/sync/issues)
|
|
5
|
+
[](https://25.re/ditr)
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
# sync
|
|
8
|
+
|
|
9
|
+
Lets people on different devices edit the same HTML form together in real time.
|
|
10
|
+
It is designed to work independently of the host framework.
|
|
11
|
+
|
|
12
|
+
*This documentation was written by an artificial intelligence and may contain errors or approximations.
|
|
13
|
+
It has not yet been fully reviewed by a human. If anything seems unclear or incomplete,
|
|
14
|
+
please feel free to contact the author of this package.*
|
|
15
|
+
|
|
16
|
+
## Install and connect
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install @itrocks/sync
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Start the [standalone server](#standalone-applications) or connect the sync server to your HTTP application with the
|
|
23
|
+
[server setup](docs/dependencies.md). Add this to a browser module on the pages you want to synchronise.
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import { sync } from '@itrocks/sync/client'
|
|
27
|
+
|
|
28
|
+
const collaboration = sync()
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Open the page in two browsers and edit the same form. By default, the client watches all forms and connects to
|
|
32
|
+
`/@itrocks/sync` on the current origin over WebSocket. Integrated servers use the application's authenticated user.
|
|
33
|
+
Forms are discovered automatically after a partial page update. Call `collaboration.destroy()` to stop the client,
|
|
34
|
+
remove its indicators and close its connection.
|
|
35
|
+
|
|
36
|
+
The page identity includes its origin and pathname. Forms use their name, ID, action or DOM position to distinguish them
|
|
37
|
+
on a page. Give forms stable, distinct identifiers if their position or surrounding markup varies between participants.
|
|
38
|
+
The client shares editable input values, checkboxes, radio groups, selects, textareas and contenteditable plain text.
|
|
39
|
+
File, password, hidden and button inputs remain local by default. A programmatic value assignment can be shared by
|
|
40
|
+
dispatching an `input` or `change` event. Native form resets are observed automatically.
|
|
41
|
+
|
|
42
|
+
## Choose plugins and collections
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
import { cursor, fields, focus, naming, range, rows, sync } from '@itrocks/sync/client'
|
|
46
|
+
|
|
47
|
+
sync({
|
|
48
|
+
endpoint: '/workshop/@itrocks/sync',
|
|
49
|
+
plugins: [cursor(), fields(), focus(), range(), rows(), naming()]
|
|
50
|
+
})
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
All options are optional. `endpoint` accepts a path on the page's origin or a complete WebSocket URL. The default
|
|
54
|
+
connects to `/@itrocks/sync` on the same host and port as the page. `server` is an alias for `endpoint`.
|
|
55
|
+
`selector` filters forms and defaults to `form`.
|
|
56
|
+
`debounce` defaults to `0`.
|
|
57
|
+
Set a positive number of milliseconds to group successive edits to the same field before sending.
|
|
58
|
+
`onStatus(status)` receives `connecting`, `connected` and `disconnected` as
|
|
59
|
+
the WebSocket connection changes. Leave `plugins` out to enable all seven, or pass an empty array to disable all
|
|
60
|
+
functional plugins. `ignore` is a CSS selector for controls to exclude. Set `session(form)` when the
|
|
61
|
+
application already has a stable room identifier for the selected form. Return an empty string to skip that form.
|
|
62
|
+
|
|
63
|
+
Use `inputPairs: '.object-lookup'` to share a text or search input with its adjacent named hidden input. Sync sends
|
|
64
|
+
the displayed label and hidden value together, and uses the hidden input's name when the visible input has no name.
|
|
65
|
+
The selector identifies which hidden values the application wants to share. The focus badge follows the first bordered
|
|
66
|
+
element from the field up to its table cell or collection item.
|
|
67
|
+
Pass `inputPairs: { selector, applied(input) { /* update the widget */ } }` if a widget needs to redraw after both
|
|
68
|
+
values are applied.
|
|
69
|
+
|
|
70
|
+
| Factory | Behaviour |
|
|
71
|
+
| ------------------ | ---------------------------------------------------------------------------------------- |
|
|
72
|
+
| `fields()` | Shares values. Set `fields({ authors: false })` to turn off the last editor's tint. |
|
|
73
|
+
| `focus()` | Displays remote focus as a coloured border and a badge with the user's initials. |
|
|
74
|
+
| `cursor()` | Shows the precise text cursor position of each remote user. Optional. |
|
|
75
|
+
| `range()` | Highlights the text ranges selected by remote users. Optional. |
|
|
76
|
+
| `rows()` | Shares row insertion and removal. `fields()` populates shared values on new rows. |
|
|
77
|
+
| `rowOrder()` | Shares the order of existing rows independently of insertion and removal. |
|
|
78
|
+
| `columnOrder()` | Shares the order of columns independently of row order. |
|
|
79
|
+
| `naming()` | Allocates HTML indices, updates label and ID references, and resolves naming collisions. |
|
|
80
|
+
| `reconciliation()` | Matches historical identities against the complete editable values of reloaded rows. |
|
|
81
|
+
|
|
82
|
+
Configure the local display with `focus({ badge: true, border: false, caret: false })`. The three options default to
|
|
83
|
+
`true`. `badge` shows initials and a name tooltip, `border` shows the coloured border, and `caret` controls the
|
|
84
|
+
blinking text cursor when `cursor()` is enabled. Selection highlights and outgoing presence keep working with these
|
|
85
|
+
options. Use `onPresence(participants, form)` to receive presence updates for the form.
|
|
86
|
+
|
|
87
|
+
Enable `cursor()` and `range()` independently or add both with `[...defaultPlugins(), cursor(), range()]`. Both work
|
|
88
|
+
in text inputs, textareas and contenteditable controls. The cursor disappears when its field or window loses focus.
|
|
89
|
+
It blinks unless the browser requests reduced motion. Hold Ctrl or Command while dragging to add a separate range in
|
|
90
|
+
the same field. Sync shares every range and draws any extra highlights the browser does not display. Multiple ranges
|
|
91
|
+
stay shared when switching windows. A single range clears when its window loses focus. Cursors and selections clear
|
|
92
|
+
on disconnect and stay out of the edit journal.
|
|
93
|
+
|
|
94
|
+
`sync.autoCollections` is the default when `collections` is omitted. It detects table bodies and lists. Lists must
|
|
95
|
+
contain form controls or sit next to a row template. Items are direct `tr` children of a `tbody` and direct `li`
|
|
96
|
+
children of a `ul` or `ol`. Sync looks for `data-key` or `data-id` on the item, then for an input whose name ends in
|
|
97
|
+
`.id` or `[id]`, preferring hidden inputs. New rows without a business key receive a UUID.
|
|
98
|
+
|
|
99
|
+
For custom markup, pass an array of collection options. Set `selector` to match containers and optionally use
|
|
100
|
+
`items` to filter their children or `key` to select the element carrying the business identifier. Custom containers
|
|
101
|
+
use their direct children by default, with the same `tr` and `li` rules for table sections and lists.
|
|
102
|
+
For stable column identities when headings can change or repeat, give corresponding headers and cells a
|
|
103
|
+
`data-sync-column` identifier. An order that would split a merged table cell into noncontiguous columns is
|
|
104
|
+
left unapplied on that table.
|
|
105
|
+
|
|
106
|
+
Sync makes a blank clone of an existing row. For an empty collection, place a `<template>` containing one item next
|
|
107
|
+
to the list or table. `create` can select a template elsewhere or provide a `create(collection, change)` callback.
|
|
108
|
+
The callback may return an element, a single HTML element as a string, or insert a matching item. `change` provides
|
|
109
|
+
`collection`, `row`, `after` and `values`. The independent
|
|
110
|
+
`naming(row, collection)` option replaces automatic HTML naming when the naming plugin is active. The default
|
|
111
|
+
algorithm recognises variable indices in bracketed or dotted names. `naming(algorithm)` and
|
|
112
|
+
`reconciliation(algorithm)` accept the alternate algorithms described by their exported TypeScript types.
|
|
113
|
+
|
|
114
|
+
### Reconnection and saving
|
|
115
|
+
|
|
116
|
+
Values use the latest corrected timestamp, with a deterministic tie-break. Two people can type into the same field.
|
|
117
|
+
The current winner is applied while the field is focused and the client preserves the selection when the control
|
|
118
|
+
supports it. Concurrent edits to the same text can replace each other.
|
|
119
|
+
|
|
120
|
+
Transactions are deduplicated by UUID. Each browser journal keeps the latest confirmed write per raw field address.
|
|
121
|
+
The server keeps the latest write per raw field address and sends that value to joining browsers that need it.
|
|
122
|
+
On reconnection the browser and server exchange the parts of their journals that the other side is missing.
|
|
123
|
+
A form can disappear with writes still pending, for example during partial navigation.
|
|
124
|
+
The outbox keeps those writes until acknowledgement while releasing the old form's DOM and active journal.
|
|
125
|
+
The server stores journals in memory and briefly retains a journal for a detached write after the last peer leaves.
|
|
126
|
+
At least one surviving browser journal is needed to rebuild history that has
|
|
127
|
+
also been lost on the server.
|
|
128
|
+
|
|
129
|
+
Save the form normally through the application. When a browser reloads a saved row with a business identifier,
|
|
130
|
+
the reconciliation plugin compares its full editable values against historical values from the same collection.
|
|
131
|
+
Identical candidates are matched one at a time in stable identity order. Use business keys on existing records when
|
|
132
|
+
possible to make the identity independent of editable values and their ordering.
|
|
133
|
+
|
|
134
|
+
## it.rocks integration
|
|
135
|
+
|
|
136
|
+
Install `@itrocks/sync` in a standard it.rocks application running a framework version with Sync support.
|
|
137
|
+
The framework applies collaboration with cursors and selections to existing record editors using their existing
|
|
138
|
+
selectors, Fastify server and authenticated session. See the [it.rocks setup](docs/dependencies.md#itrocks) for
|
|
139
|
+
configuration.
|
|
140
|
+
|
|
141
|
+
## Standalone applications
|
|
142
|
+
|
|
143
|
+
With Node.js 24 or later, run the standalone WebSocket server from the installed package.
|
|
144
|
+
|
|
145
|
+
```sh
|
|
146
|
+
npx sync-server --port 3001
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
You can also run `npx @itrocks/sync --port 3001` without installing the package in a project. The command prints
|
|
150
|
+
the listening WebSocket URL and exits with a non-zero status if the server fails to start. The port defaults to
|
|
151
|
+
`3001`, and the WebSocket path defaults to `/@itrocks/sync`. Pass `--port 0` to pick an available port, `--host`
|
|
152
|
+
to change the listening address from `127.0.0.1`, or `--path /collaboration` to choose another WebSocket route.
|
|
153
|
+
|
|
154
|
+
If your forms are served on a different origin, point their browser module to the WebSocket server directly.
|
|
155
|
+
|
|
156
|
+
```js
|
|
157
|
+
import { sync } from '@itrocks/sync/client'
|
|
158
|
+
|
|
159
|
+
sync({ endpoint: 'ws://127.0.0.1:3001/@itrocks/sync' })
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
For clients on the same local network, start the server with `--host 0.0.0.0` and use the server's LAN address
|
|
163
|
+
in the browser module. The standalone server assigns a separate guest identity to each connection and keeps its
|
|
164
|
+
journal in memory. It accepts guest connections from any origin and exposes no ordinary HTTP pages. For HTTPS pages,
|
|
165
|
+
use a reverse proxy that supports WebSocket upgrades and set the browser URL to `wss:`.
|
|
166
|
+
|
|
167
|
+
See [server setup](docs/dependencies.md) for programmatic standalone, Node HTTP, Express and Fastify examples and
|
|
168
|
+
the generic transport contract. The native HTTP adapter uses `ws`. The Fastify adapter uses Fastify and the
|
|
169
|
+
optional `@fastify/websocket` dependency.
|
|
170
|
+
|
|
171
|
+
From a source checkout, `npm run build` compiles the package and `npm start -- --port 3001` runs the compiled
|
|
172
|
+
standalone server. `npm run dev -- --port 3001` runs it with a watcher for TypeScript edits.
|
|
173
|
+
|
|
174
|
+
## Interactive demo and development
|
|
175
|
+
|
|
176
|
+
From a source checkout with Node.js 24 or later, run:
|
|
177
|
+
|
|
178
|
+
```sh
|
|
179
|
+
cd demo
|
|
180
|
+
npm install
|
|
181
|
+
npm run build
|
|
182
|
+
npm start
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Run `npm run build:demo` from the package root to compile the TypeScript and copy the client and server pages
|
|
186
|
+
and styles from `demo/src/` to `demo/dist/`. The dashboard opens from `demo/index.html`.
|
|
187
|
+
To start the demo launcher from the package root, run `npm run start:demo`.
|
|
188
|
+
|
|
189
|
+
Open the printed URL, normally `http://127.0.0.1:3001/`. Three clients share a supplies request in the grid.
|
|
190
|
+
Change its title in one client and check it in the others. The **Server** panel lists and counts the clients connected
|
|
191
|
+
to the session. Open **Server code** and choose JS or TS with Fastify, Express or Standalone to see a runnable example.
|
|
192
|
+
|
|
193
|
+
To run the example on its own, copy **Server code** to `server.mjs` or `server.mts` and follow the commands in it.
|
|
194
|
+
Copy **Client code** as `client.js`, or save the TS example as `client.ts` and compile it to `client.js`.
|
|
195
|
+
Copy the **HTML** example as `index.html` in the same directory. With the example server running, open
|
|
196
|
+
`http://127.0.0.1:3001/` or open `index.html` directly from your file manager. Both share the same form.
|
|
197
|
+
The example server supplies the form, browser modules and the stylesheet packaged as `@itrocks/sync/demo.css`.
|
|
198
|
+
|
|
199
|
+
Choose **1**, **2** or **4** in the layout selector. The two-panel view starts with clients 1 and 2, one above
|
|
200
|
+
the other at full panel width. **Add client** uses the first available client number and vacant panel.
|
|
201
|
+
Click a panel, including an empty one, to select its position. Choose a tab to show it in the selected empty panel.
|
|
202
|
+
In a full grid, selecting a hidden tab brings it into the selected position. Visible panels can swap positions in the grid.
|
|
203
|
+
|
|
204
|
+
**Open in new window** moves a panel to its own window. **Bring back here** returns it to the dashboard.
|
|
205
|
+
Double-click or hold a client's **Open in new window** button to offer to open all hidden clients in a single window
|
|
206
|
+
with one tab per client. Closing a client with its cross or closing its window removes its dashboard tab.
|
|
207
|
+
Double-click or hold a cross to offer to close every client and the server view. The browser's pop-up settings may
|
|
208
|
+
require permission to open a separate window.
|
|
209
|
+
|
|
210
|
+
The dashboard URL keeps the selected plugins and panel positions. **Copy demo link to clipboard** in the
|
|
211
|
+
top-right corner shares these settings. `c1=1` places client 1 in the first panel, `c8=` leaves client 8 out
|
|
212
|
+
of view and `w2` opens client 2 in a separate window. `s=4` places the server in the fourth panel and `ws`
|
|
213
|
+
opens it in its own window. The link restores the clients listed in it. If the browser blocks
|
|
214
|
+
restored pop-ups, select **Open saved windows**.
|
|
215
|
+
Opening the copied link starts a new collaboration room with those settings.
|
|
216
|
+
|
|
217
|
+
Select plugins independently in the dashboard's left-hand menu. The selection applies to its embedded and detached
|
|
218
|
+
clients. **focus** shows the field, **cursor** shows the exact position in the text, and **range** highlights selected
|
|
219
|
+
text. Try these plugins in the request title, notes or delivery details.
|
|
220
|
+
Hold Ctrl or Command while dragging to add a separate range. The demo keeps sharing all ranges when you switch
|
|
221
|
+
panels. Collection plugins
|
|
222
|
+
show a table of requested items and a list of delivery instructions. Use **Client code** to see the current
|
|
223
|
+
configuration. On the same browser origin, the `programmingLanguage` storage key shares the JS, TS or HTML preference
|
|
224
|
+
with the table and edit-components demos. The server adapter choice uses `webServer`. Select the **Server** tab to
|
|
225
|
+
reopen its view. The dashboard can hold up to 100 client tabs.
|
|
226
|
+
|
|
227
|
+
Drag a column header to reorder the items table. With `columnOrder` enabled, the new order appears in the
|
|
228
|
+
other clients.
|
|
229
|
+
|
|
230
|
+
The local dashboard keeps its HTTP address while the active launcher picks an available WebSocket port on
|
|
231
|
+
`localhost`. Launching another copy from the same checkout leaves it on standby. Its terminal prints a link to
|
|
232
|
+
its server view. If the active launcher stops, a standby takes over, publishes its port and existing browser
|
|
233
|
+
clients reconnect. Each launcher's server view reports its status and explains any inactivity. The browser shares
|
|
234
|
+
the published address through `localStorage` on the dashboard's origin.
|
|
235
|
+
|
|
236
|
+
With a local static web server such as Apache, serve the package checkout and open `demo/` over HTTP
|
|
237
|
+
on `localhost`. Keep `npm run start:demo` running. The page discovers the local launcher and connects directly to its
|
|
238
|
+
WebSocket port.
|
|
239
|
+
|
|
240
|
+
For a second device on the same network, run `HOST=0.0.0.0 PORT=3001 npm run start:demo`. Open the dashboard through the
|
|
241
|
+
server's LAN address and share the full dashboard URL, including its session identifier, with the other device.
|
|
242
|
+
New visits without a session identifier start separate sessions. For an online demo, serve the page and the
|
|
243
|
+
`/@itrocks/sync` WebSocket route through the same HTTPS origin. If a reverse proxy serves the demo, forward
|
|
244
|
+
the `server-runtime` and `server-status` HTTP routes as well as the WebSocket upgrade to the Node dashboard
|
|
245
|
+
listener. The demo uses sample participant identities.
|
|
246
|
+
|
|
247
|
+
See [test suites](docs/testing.md) for the fast regression checks, full matrix, visual checks and browser setup.
|
|
248
|
+
|
|
249
|
+
[Main specification](docs/spec.md) · [Architectural addendum](docs/spec-addendum.md) ·
|
|
250
|
+
[Dependency addendum](docs/spec-addendum-dependencies.md)
|
package/config.yaml
ADDED