instadash-embed 0.1.0 → 0.2.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 (2) hide show
  1. package/embed.html +39 -18
  2. package/package.json +1 -1
package/embed.html CHANGED
@@ -272,25 +272,46 @@ td.bool .f{color:var(--fg-3)}
272
272
  document.getElementById('root').innerHTML = html
273
273
  }
274
274
 
275
- // ── Fetch ───────────────────────────────────────────────────
276
- Promise.all([
277
- fetch(gridUrl + '/rows?limit=2000').then(function(r) {
278
- return r.ok ? r.json() : Promise.reject('HTTP ' + r.status)
279
- }),
280
- fetch(gridUrl + '/meta').then(function(r) {
281
- return r.ok ? r.json() : null
282
- }).catch(function() { return null }),
283
- ])
284
- .then(function(res) { renderTable(res[0].rows || [], res[1]) })
285
- .catch(function(e) {
286
- setRoot(
287
- '<div class="state">' +
288
- '<span class="err">Could not load grid</span>' +
289
- '<span>' + esc(handle + '/' + slug) + ' · ' + esc(String(e)) + '</span>' +
290
- '<a href="' + esc(gridUrl) + '" target="_blank" rel="noopener">open in instadash ↗</a>' +
291
- '</div>'
292
- )
275
+ // ── Data loading: postMessage first, fetch as fallback ──────
276
+ // In sandboxed contexts (e.g. Claude.ai artifacts) cross-origin
277
+ // fetch is blocked. The parent artifact sends rows via postMessage.
278
+ // Outside sandboxes (direct browser use) we fall back to fetch.
279
+ var loaded = false
280
+
281
+ window.addEventListener('message', function(e) {
282
+ if (loaded) return
283
+ if (!e.data || e.data.type !== 'instadash-data') return
284
+ loaded = true
285
+ renderTable(e.data.rows || [], e.data.meta || null)
293
286
  })
287
+
288
+ // Give postMessage 600ms to arrive before falling back to fetch
289
+ setTimeout(function() {
290
+ if (loaded) return
291
+ Promise.all([
292
+ fetch(gridUrl + '/rows?limit=2000').then(function(r) {
293
+ return r.ok ? r.json() : Promise.reject('HTTP ' + r.status)
294
+ }),
295
+ fetch(gridUrl + '/meta').then(function(r) {
296
+ return r.ok ? r.json() : null
297
+ }).catch(function() { return null }),
298
+ ])
299
+ .then(function(res) {
300
+ if (loaded) return
301
+ loaded = true
302
+ renderTable(res[0].rows || [], res[1])
303
+ })
304
+ .catch(function(e) {
305
+ if (loaded) return
306
+ setRoot(
307
+ '<div class="state">' +
308
+ '<span class="err">Could not load grid</span>' +
309
+ '<span>' + esc(handle + '/' + slug) + ' · ' + esc(String(e)) + '</span>' +
310
+ '<a href="' + esc(gridUrl) + '" target="_blank" rel="noopener">open in instadash ↗</a>' +
311
+ '</div>'
312
+ )
313
+ })
314
+ }, 600)
294
315
  })()
295
316
  </script>
296
317
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instadash-embed",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Self-contained grid embed widget for instadash.io — works in Claude.ai artifacts via cdn.jsdelivr.net",
5
5
  "license": "MIT",
6
6
  "files": [