braid-text 0.1.4 → 0.2.1
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/editor.html +1 -1
- package/index.js +2 -1
- package/markdown-editor.html +1 -1
- package/package.json +2 -2
- package/simpleton-client.js +6 -3
- package/test.html +45 -1
- package/test.js +1 -1
package/editor.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
></textarea>
|
|
6
6
|
</body>
|
|
7
7
|
<script src="https://braid.org/code/myers-diff1.js"></script>
|
|
8
|
-
<script src="https://unpkg.com/braid-http@~1.
|
|
8
|
+
<script src="https://unpkg.com/braid-http@~1.3/braid-http-client.js"></script>
|
|
9
9
|
<script src="/simpleton-client.js"></script>
|
|
10
10
|
<script>
|
|
11
11
|
let simpleton = simpleton_client(location.pathname, {
|
package/index.js
CHANGED
|
@@ -148,6 +148,7 @@ braid_text.serve = async (req, res, options = {}) => {
|
|
|
148
148
|
let ee = null
|
|
149
149
|
try {
|
|
150
150
|
patches = await req.patches()
|
|
151
|
+
for (let p of patches) p.content = p.content_text
|
|
151
152
|
} catch (e) { ee = e }
|
|
152
153
|
await my_prev_put_p
|
|
153
154
|
|
|
@@ -310,7 +311,7 @@ braid_text.put = async (key, options) => {
|
|
|
310
311
|
|
|
311
312
|
let x = JSON.parse(resource.doc.get())
|
|
312
313
|
for (let p of patches)
|
|
313
|
-
apply_patch(x, p.range, JSON.parse(p.content))
|
|
314
|
+
apply_patch(x, p.range, p.content === '' ? undefined : JSON.parse(p.content))
|
|
314
315
|
|
|
315
316
|
return await braid_text.put(key, {
|
|
316
317
|
body: JSON.stringify(x, null, 4)
|
package/markdown-editor.html
CHANGED
|
@@ -12,7 +12,7 @@ dom.BODY = -> DIV(WIKI())
|
|
|
12
12
|
window.statebus_fetch = window.fetch
|
|
13
13
|
window.fetch = window.og_fetch
|
|
14
14
|
</script>
|
|
15
|
-
<script src="https://unpkg.com/braid-http@~1.
|
|
15
|
+
<script src="https://unpkg.com/braid-http@~1.3/braid-http-client.js"></script>
|
|
16
16
|
<script>
|
|
17
17
|
window.fetch = window.statebus_fetch
|
|
18
18
|
</script>
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "braid-text",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Library for collaborative text over http using braid.",
|
|
5
5
|
"author": "Braid Working Group",
|
|
6
6
|
"repository": "braid-org/braidjs",
|
|
7
7
|
"homepage": "https://braid.org",
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"diamond-types-node": "^1.0.2",
|
|
10
|
-
"braid-http": "^1.
|
|
10
|
+
"braid-http": "^1.3.4"
|
|
11
11
|
}
|
|
12
12
|
}
|
package/simpleton-client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// requires braid-http@~1.
|
|
1
|
+
// requires braid-http@~1.3/braid-http-client.js
|
|
2
2
|
//
|
|
3
3
|
// url: resource endpoint
|
|
4
4
|
//
|
|
@@ -41,10 +41,13 @@ function simpleton_client(url, { apply_remote_update, generate_local_diff_update
|
|
|
41
41
|
if (current_version.length === update.parents.length
|
|
42
42
|
&& current_version.every((v, i) => v === update.parents[i])) {
|
|
43
43
|
current_version = update.version.sort()
|
|
44
|
-
update.state = update.
|
|
44
|
+
update.state = update.body_text
|
|
45
45
|
|
|
46
46
|
if (update.patches) {
|
|
47
|
-
for (let p of update.patches)
|
|
47
|
+
for (let p of update.patches) {
|
|
48
|
+
p.range = p.range.match(/\d+/g).map((x) => 1 * x)
|
|
49
|
+
p.content = p.content_text
|
|
50
|
+
}
|
|
48
51
|
update.patches.sort((a, b) => a.range[0] - b.range[0])
|
|
49
52
|
|
|
50
53
|
// convert from code-points to js-indicies
|
package/test.html
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
background-color: #ffebee;
|
|
20
20
|
}
|
|
21
21
|
</style>
|
|
22
|
-
<script src="https://unpkg.com/braid-http@~1.
|
|
22
|
+
<script src="https://unpkg.com/braid-http@~1.3/braid-http-client.js"></script>
|
|
23
23
|
<div id="testContainer"></div>
|
|
24
24
|
<script type=module>
|
|
25
25
|
|
|
@@ -61,6 +61,27 @@ async function runTest(testName, testFunction, expectedResult) {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
runTest(
|
|
65
|
+
"test getting a binary update from a subscription",
|
|
66
|
+
async () => {
|
|
67
|
+
return await new Promise(async (done, fail) => {
|
|
68
|
+
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
69
|
+
|
|
70
|
+
await fetch(`/${key}`, {
|
|
71
|
+
method: 'PUT',
|
|
72
|
+
body: JSON.stringify({a: 5, b: 6}, null, 4)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
let r = await braid_fetch(`/${key}`, {
|
|
76
|
+
subscribe: true
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
r.subscribe(update => done(update.body_text), fail)
|
|
80
|
+
})
|
|
81
|
+
},
|
|
82
|
+
JSON.stringify({a: 5, b: 6}, null, 4)
|
|
83
|
+
)
|
|
84
|
+
|
|
64
85
|
runTest(
|
|
65
86
|
"test sending a json patch to some json-text",
|
|
66
87
|
async () => {
|
|
@@ -115,4 +136,27 @@ runTest(
|
|
|
115
136
|
JSON.stringify({a: 55, b: 66, c: 7}, null, 4)
|
|
116
137
|
)
|
|
117
138
|
|
|
139
|
+
runTest(
|
|
140
|
+
"test deleting something using a json patch",
|
|
141
|
+
async () => {
|
|
142
|
+
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
143
|
+
|
|
144
|
+
await fetch(`/${key}`, {
|
|
145
|
+
method: 'PUT',
|
|
146
|
+
body: JSON.stringify({a: 5, b: 6}, null, 4)
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
await fetch(`/${key}`, {
|
|
150
|
+
method: 'PUT',
|
|
151
|
+
headers: { 'Content-Range': 'json a' },
|
|
152
|
+
body: ''
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
let r = await fetch(`/${key}`)
|
|
156
|
+
|
|
157
|
+
return await r.text()
|
|
158
|
+
},
|
|
159
|
+
JSON.stringify({b: 6}, null, 4)
|
|
160
|
+
)
|
|
161
|
+
|
|
118
162
|
</script>
|
package/test.js
CHANGED