braid-blob 0.0.74 → 0.0.76

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 (3) hide show
  1. package/client.js +2 -2
  2. package/img-live.js +14 -10
  3. package/package.json +1 -1
package/client.js CHANGED
@@ -4,7 +4,7 @@
4
4
  // Usage:
5
5
  // var blob = braid_blob_client(url, {
6
6
  // peer: 'my-peer-id', // optional, random if not set
7
- // on_update: (body, content_type, version) => {
7
+ // on_update: (body, content_type, version, from_local_update) => {
8
8
  // // Called whenever there's a new version of the blob
9
9
  // console.log('New blob:', body, content_type, version)
10
10
  // },
@@ -53,7 +53,7 @@ function braid_blob_client(url, params = {}) {
53
53
  update: async (body, content_type) => {
54
54
  current_version = [create_event(current_version?.[0])]
55
55
 
56
- params.on_update?.(body, content_type, current_version)
56
+ params.on_update?.(body, content_type, current_version, true)
57
57
 
58
58
  await braid_fetch(url, {
59
59
  method: 'PUT',
package/img-live.js CHANGED
@@ -15,12 +15,18 @@ function sync(img) {
15
15
  var ac = new AbortController()
16
16
  var client = braid_blob_client(url, {
17
17
  signal: ac.signal,
18
- on_update: (body, content_type) => {
19
- var blob = new Blob([body], { type: content_type || 'image/png' })
20
- img.src = URL.createObjectURL(blob)
18
+ on_update: (body, content_type, version, from_local_update) => {
19
+ if (from_local_update) {
20
+ var blob = new Blob([body], { type: content_type || 'image/png' })
21
+ img.src = URL.createObjectURL(blob)
22
+ } else {
23
+ img.src = ''
24
+ img.src = url
25
+ }
21
26
  },
22
27
  on_delete: () => {
23
- img.src = URL.createObjectURL(new Blob([]))
28
+ img.src = ''
29
+ img.src = url
24
30
  },
25
31
  on_error: (error) => {
26
32
  console.error('Live image error for', url, error)
@@ -53,8 +59,9 @@ function sync(img) {
53
59
  if (!file || !file.type.startsWith('image/')) return
54
60
 
55
61
  var reader = new FileReader()
56
- reader.onload = function() {
57
- client.update(reader.result, file.type)
62
+ reader.onload = async function() {
63
+ await client.update(reader.result, file.type)
64
+ img.src = url
58
65
  }
59
66
  reader.readAsArrayBuffer(file)
60
67
  })
@@ -86,9 +93,6 @@ var observer = new MutationObserver(function(mutations) {
86
93
  }
87
94
  })
88
95
  if (mutation.type === 'attributes' && mutation.target.tagName === 'IMG') {
89
- // Ignore src changes to blob: URLs (our own updates)
90
- if (mutation.attributeName === 'src' && mutation.target.src.startsWith('blob:'))
91
- return
92
96
  if (mutation.target.hasAttribute('live'))
93
97
  sync(mutation.target)
94
98
  else if (mutation.attributeName === 'live')
@@ -107,7 +111,7 @@ function init() {
107
111
  childList: true,
108
112
  subtree: true,
109
113
  attributes: true,
110
- attributeFilter: ['live', 'droppable', 'src']
114
+ attributeFilter: ['live', 'droppable']
111
115
  })
112
116
 
113
117
  document.querySelectorAll('img[live]').forEach(sync)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-blob",
3
- "version": "0.0.74",
3
+ "version": "0.0.76",
4
4
  "description": "Library for collaborative blobs over http using braid.",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braid-blob",