braid-text 0.5.7 → 0.5.9
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/client/editor.html +7 -26
- package/client/markdown-editor.html +15 -47
- package/client/myers-diff.js +691 -0
- package/client/simpleton.js +168 -0
- package/client/syncarea.js +221 -0
- package/client/text-client.js +269 -0
- package/package.json +6 -4
- package/server-demo.js +12 -4
- package/server.js +57 -47
- package/client/simpleton-sync.js +0 -508
- package/client/web-utils.js +0 -75
package/server-demo.js
CHANGED
|
@@ -14,15 +14,23 @@ var server = require("http").createServer(async (req, res) => {
|
|
|
14
14
|
if (req.method === 'OPTIONS') return res.end()
|
|
15
15
|
|
|
16
16
|
var q = req.url.split('?').slice(-1)[0]
|
|
17
|
-
if (q === 'editor' || q === 'markdown-editor' || q === 'yjs-editor'
|
|
17
|
+
if (q === 'editor' || q === 'markdown-editor' || q === 'yjs-editor') {
|
|
18
18
|
res.writeHead(200, { "Content-Type": "text/html", "Cache-Control": "no-cache" })
|
|
19
19
|
require("fs").createReadStream(`./client/${q}.html`).pipe(res)
|
|
20
20
|
return
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
var libs = new Set([
|
|
24
|
+
'simpleton.js',
|
|
25
|
+
'text-client.js',
|
|
26
|
+
'yjs-sync.js',
|
|
27
|
+
'cursor-sync.js',
|
|
28
|
+
'textarea-highlights.js',
|
|
29
|
+
'myers-diff.js',
|
|
30
|
+
'syncarea.js'
|
|
31
|
+
])
|
|
32
|
+
|
|
33
|
+
if (libs.has(req.url.substr(1))) {
|
|
26
34
|
res.writeHead(200, { "Content-Type": "text/javascript", "Cache-Control": "no-cache" })
|
|
27
35
|
require("fs").createReadStream("./client" + req.url).pipe(res)
|
|
28
36
|
return
|
package/server.js
CHANGED
|
@@ -93,45 +93,55 @@ function create_braid_text() {
|
|
|
93
93
|
resource.save_meta()
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
//
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
96
|
+
// When we get an ackowledgement that a remote server has a version
|
|
97
|
+
// that we have:
|
|
98
|
+
//
|
|
99
|
+
// - In a PUT acknowledgement
|
|
100
|
+
// - Or a GET response
|
|
101
|
+
//
|
|
102
|
+
// ...then we extend our known fork point "frontier" to include that
|
|
103
|
+
// version.
|
|
104
|
+
function extend_fork_point(update) {
|
|
105
|
+
|
|
106
|
+
// Given a version frontier, incorporate a new update (version +
|
|
107
|
+
// parents) to compute the new frontier. Walks the DT version DAG
|
|
108
|
+
// if needed.
|
|
109
|
+
function extend_frontier(frontier, version, parents) {
|
|
110
|
+
var frontier_set = new Set(frontier)
|
|
111
|
+
// Fast path: if the frontier contains all the update's parents,
|
|
112
|
+
// just swap them out for the new version
|
|
113
|
+
if (parents.length &&
|
|
114
|
+
parents.every(p => frontier_set.has(p))) {
|
|
115
|
+
parents.forEach(p => frontier_set.delete(p))
|
|
116
|
+
for (var event of version) frontier_set.add(event)
|
|
117
|
+
frontier = [...frontier_set.values()]
|
|
118
|
+
} else {
|
|
119
|
+
// Slow path: walk the full DT history to compute the frontier
|
|
120
|
+
var looking_for = frontier_set
|
|
121
|
+
for (var event of version) looking_for.add(event)
|
|
122
|
+
|
|
123
|
+
frontier = []
|
|
124
|
+
var shadow = new Set()
|
|
125
|
+
|
|
126
|
+
var bytes = resource.dt.doc.toBytes()
|
|
127
|
+
var [_, events, parentss] = braid_text.dt_parse([...bytes])
|
|
128
|
+
for (var i = events.length - 1; i >= 0 && looking_for.size; i--) {
|
|
129
|
+
var e = events[i].join('-')
|
|
130
|
+
if (looking_for.has(e)) {
|
|
131
|
+
looking_for.delete(e)
|
|
132
|
+
if (!shadow.has(e)) frontier.push(e)
|
|
133
|
+
shadow.add(e)
|
|
134
|
+
}
|
|
135
|
+
if (shadow.has(e))
|
|
136
|
+
parentss[i].forEach(p => shadow.add(p.join('-')))
|
|
123
137
|
}
|
|
124
|
-
if (shadow.has(e))
|
|
125
|
-
parentss[i].forEach(p => shadow.add(p.join('-')))
|
|
126
138
|
}
|
|
139
|
+
return frontier.sort()
|
|
127
140
|
}
|
|
128
|
-
return frontier.sort()
|
|
129
|
-
}
|
|
130
141
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
update.version, update.parents)
|
|
142
|
+
resource.meta.fork_point = extend_frontier(resource.meta.fork_point,
|
|
143
|
+
update.version,
|
|
144
|
+
update.parents)
|
|
135
145
|
resource.save_meta()
|
|
136
146
|
}
|
|
137
147
|
|
|
@@ -370,8 +380,8 @@ function create_braid_text() {
|
|
|
370
380
|
res.setHeader('Content-Type', `${ct}; charset=utf-8`)
|
|
371
381
|
else if (charset.toLowerCase() !== 'charset=utf-8')
|
|
372
382
|
res.setHeader('Content-Type', ct_parts
|
|
373
|
-
|
|
374
|
-
|
|
383
|
+
.map(p => p.toLowerCase().startsWith('charset=') ? 'charset=utf-8' : p)
|
|
384
|
+
.join('; '))
|
|
375
385
|
|
|
376
386
|
// ── Handle simple methods that don't need further processing ──
|
|
377
387
|
|
|
@@ -407,9 +417,9 @@ function create_braid_text() {
|
|
|
407
417
|
var getting = {
|
|
408
418
|
subscribe: !!req.subscribe,
|
|
409
419
|
history: (has_parents && v_eq(req.parents, resource.version)) ? false
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
420
|
+
: has_parents ? 'since-parents'
|
|
421
|
+
: (req.subscribe || req.parents || req.headers['accept-transfer-encoding']) ? 'up-to-version'
|
|
422
|
+
: false,
|
|
413
423
|
transfer_encoding: req.headers['accept-transfer-encoding'],
|
|
414
424
|
}
|
|
415
425
|
getting.single_snapshot = !getting.subscribe && !getting.history
|
|
@@ -493,8 +503,7 @@ function create_braid_text() {
|
|
|
493
503
|
merge_type,
|
|
494
504
|
signal: aborter.signal,
|
|
495
505
|
accept_encoding:
|
|
496
|
-
req.headers['x-accept-encoding'] ??
|
|
497
|
-
req.headers['accept-encoding'],
|
|
506
|
+
req.headers['x-accept-encoding'] ?? req.headers['accept-encoding'],
|
|
498
507
|
subscribe: update => {
|
|
499
508
|
// Add digest for integrity checking on the client
|
|
500
509
|
if (update.version && v_eq(update.version, resource.version))
|
|
@@ -688,9 +697,9 @@ function create_braid_text() {
|
|
|
688
697
|
// 'up-to-version' = bring client up to current (from scratch)
|
|
689
698
|
// false = no history needed
|
|
690
699
|
history: (has_parents && v_eq(options.parents, version)) ? false
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
700
|
+
: has_parents ? 'since-parents'
|
|
701
|
+
: (options.subscribe || options.parents || options.transfer_encoding) ? 'up-to-version'
|
|
702
|
+
: false,
|
|
694
703
|
transfer_encoding: options.transfer_encoding,
|
|
695
704
|
}
|
|
696
705
|
getting.single_snapshot = !getting.subscribe && !getting.history
|
|
@@ -733,6 +742,7 @@ function create_braid_text() {
|
|
|
733
742
|
return { body: bytes }
|
|
734
743
|
}
|
|
735
744
|
|
|
745
|
+
// Each merge-type has a different way of getting history
|
|
736
746
|
switch (merge_type) {
|
|
737
747
|
|
|
738
748
|
case 'yjs':
|
|
@@ -774,7 +784,7 @@ function create_braid_text() {
|
|
|
774
784
|
|
|
775
785
|
if (getting.history && !getting.subscribe)
|
|
776
786
|
return dt_get_patches(resource.dt.doc,
|
|
777
|
-
|
|
787
|
+
getting.history === 'since-parents' ? options.parents : undefined)
|
|
778
788
|
|
|
779
789
|
if (getting.subscribe) {
|
|
780
790
|
var client = {
|
|
@@ -807,7 +817,7 @@ function create_braid_text() {
|
|
|
807
817
|
|
|
808
818
|
if (getting.history && !getting.subscribe)
|
|
809
819
|
return dt_get_patches(resource.dt.doc,
|
|
810
|
-
|
|
820
|
+
getting.history === 'since-parents' ? options.parents : undefined)
|
|
811
821
|
|
|
812
822
|
if (getting.subscribe) {
|
|
813
823
|
var client = {
|