automerge-repo-solid-primitives
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,17 +0,17 @@ | ||
import { createContext as L, useContext as F, createResource as _, createEffect as P, on as $, onCleanup as T, $PROXY as a, $TRACK as N, getListener as j, batch as H, createSignal as W, onMount as z } from "solid-js"; | ||
const I = L(null); | ||
function M() { | ||
const e = F(I); | ||
import { createContext as L, useContext as W, createResource as D, createEffect as P, on as g, onCleanup as T, $PROXY as a, $TRACK as _, getListener as j, batch as F, createSignal as H, getOwner as z, runWithOwner as I } from "solid-js"; | ||
const V = L(null); | ||
function G() { | ||
const e = W(V); | ||
if (!e) throw new Error("Please wrap me in a <RepoContext value={repo}>"); | ||
return e; | ||
} | ||
function G(e) { | ||
let n = M(), [r, { mutate: t }] = _(e, async (i) => { | ||
if (!i) | ||
function M(e) { | ||
let n = G(), [r, { mutate: t }] = D(e, (o) => { | ||
if (!o) | ||
return; | ||
let o = n.find(i); | ||
return await o.whenReady(), o; | ||
let i = n.find(o); | ||
return i.isReady() ? i : i.whenReady().then(() => i); | ||
}); | ||
return P( | ||
$([e], () => { | ||
g([e], () => { | ||
e() || t(); | ||
@@ -21,18 +21,21 @@ }) | ||
} | ||
function oe(e) { | ||
let n = G(e), [r, { refetch: t, mutate: i }] = _(n, (o) => o.doc()); | ||
function ie(e, n) { | ||
let r = M(e), [t, { refetch: o, mutate: i }] = D(r, (f) => f.doc(), { | ||
initialValue: r()?.docSync(), | ||
storage: n?.storage | ||
}); | ||
return P( | ||
$([n], ([o]) => { | ||
o?.on("change", t), o?.on("delete", t), T(() => { | ||
o?.off("change", t), o?.off("delete", t); | ||
g(r, (f) => { | ||
f?.on("change", o), f?.on("delete", o), T(() => { | ||
f?.off("change", o), f?.off("delete", o); | ||
}); | ||
}) | ||
), P($([n], ([o]) => o || i())), P($([e], ([o]) => o || i)), [ | ||
r, | ||
(o, c) => { | ||
n()?.change(o, c); | ||
), P(g(r, (f) => f || i())), P(g(e, (f) => f || i)), [ | ||
t, | ||
(f, c) => { | ||
r()?.change(f, c); | ||
} | ||
]; | ||
} | ||
const S = Symbol("store-raw"), h = Symbol("store-node"), y = Symbol("store-has"), x = Symbol("store-self"); | ||
const $ = Symbol("store-raw"), h = Symbol("store-node"), y = Symbol("store-has"), x = Symbol("store-self"); | ||
function C(e) { | ||
@@ -44,7 +47,7 @@ let n = e[a]; | ||
const r = Object.keys(e), t = Object.getOwnPropertyDescriptors(e); | ||
for (let i = 0, o = r.length; i < o; i++) { | ||
const c = r[i]; | ||
t[c].get && Object.defineProperty(e, c, { | ||
enumerable: t[c].enumerable, | ||
get: t[c].get.bind(n) | ||
for (let o = 0, i = r.length; o < i; o++) { | ||
const f = r[o]; | ||
t[f].get && Object.defineProperty(e, f, { | ||
enumerable: t[f].enumerable, | ||
get: t[f].get.bind(n) | ||
}); | ||
@@ -60,18 +63,18 @@ } | ||
function A(e, n = /* @__PURE__ */ new Set()) { | ||
let r, t, i, o; | ||
if (r = e != null && e[S]) return r; | ||
let r, t, o, i; | ||
if (r = e != null && e[$]) return r; | ||
if (!p(e) || n.has(e)) return e; | ||
if (Array.isArray(e)) { | ||
Object.isFrozen(e) ? e = e.slice(0) : n.add(e); | ||
for (let c = 0, f = e.length; c < f; c++) | ||
i = e[c], (t = A(i, n)) !== i && (e[c] = t); | ||
for (let f = 0, c = e.length; f < c; f++) | ||
o = e[f], (t = A(o, n)) !== o && (e[f] = t); | ||
} else { | ||
Object.isFrozen(e) ? e = Object.assign({}, e) : n.add(e); | ||
const c = Object.keys(e), f = Object.getOwnPropertyDescriptors(e); | ||
for (let s = 0, l = c.length; s < l; s++) | ||
o = c[s], !f[o].get && (i = e[o], (t = A(i, n)) !== i && (e[o] = t)); | ||
const f = Object.keys(e), c = Object.getOwnPropertyDescriptors(e); | ||
for (let s = 0, l = f.length; s < l; s++) | ||
i = f[s], !c[i].get && (o = e[i], (t = A(o, n)) !== o && (e[i] = t)); | ||
} | ||
return e; | ||
} | ||
function g(e, n) { | ||
function S(e, n) { | ||
let r = e[n]; | ||
@@ -84,7 +87,7 @@ return r || Object.defineProperty(e, n, { | ||
if (e[n]) return e[n]; | ||
const [t, i] = W(r, { | ||
const [t, o] = H(r, { | ||
equals: !1, | ||
internal: !0 | ||
}); | ||
return t.$ = i, e[n] = t; | ||
return t.$ = o, e[n] = t; | ||
} | ||
@@ -96,3 +99,3 @@ function X(e, n) { | ||
function m(e) { | ||
j() && E(g(e, h), x)(); | ||
j() && E(S(e, h), x)(); | ||
} | ||
@@ -104,17 +107,17 @@ function Y(e) { | ||
get(e, n, r) { | ||
if (n === S) return e; | ||
if (n === $) return e; | ||
if (n === a) return r; | ||
if (n === N) | ||
if (n === _) | ||
return m(e), r; | ||
const t = g(e, h), i = t[n]; | ||
let o = i ? i() : e[n]; | ||
if (n === h || n === y || n === "__proto__") return o; | ||
if (!i) { | ||
const c = Object.getOwnPropertyDescriptor(e, n); | ||
j() && (typeof o != "function" || e.hasOwnProperty(n)) && !(c && c.get) && (o = E(t, n, o)()); | ||
const t = S(e, h), o = t[n]; | ||
let i = o ? o() : e[n]; | ||
if (n === h || n === y || n === "__proto__") return i; | ||
if (!o) { | ||
const f = Object.getOwnPropertyDescriptor(e, n); | ||
j() && (typeof i != "function" || e.hasOwnProperty(n)) && !(f && f.get) && (i = E(t, n, i)()); | ||
} | ||
return p(o) ? C(o) : o; | ||
return p(i) ? C(i) : i; | ||
}, | ||
has(e, n) { | ||
return n === S || n === a || n === N || n === h || n === y || n === "__proto__" ? !0 : (j() && E(g(e, y), n)(), n in e); | ||
return n === $ || n === a || n === _ || n === h || n === y || n === "__proto__" ? !0 : (j() && E(S(e, y), n)(), n in e); | ||
}, | ||
@@ -130,12 +133,12 @@ set() { | ||
}; | ||
function b(e, n, r, t = !1) { | ||
function O(e, n, r, t = !1) { | ||
if (!t && e[n] === r) return; | ||
const i = e[n], o = e.length; | ||
r === void 0 ? (delete e[n], e[y] && e[y][n] && i !== void 0 && e[y][n].$()) : (e[n] = r, e[y] && e[y][n] && i === void 0 && e[y][n].$()); | ||
let c = g(e, h), f; | ||
if ((f = E(c, n, i)) && f.$(() => r), Array.isArray(e) && e.length !== o) { | ||
for (let s = e.length; s < o; s++) (f = c[s]) && f.$(); | ||
(f = E(c, "length", o)) && f.$(e.length); | ||
const o = e[n], i = e.length; | ||
r === void 0 ? (delete e[n], e[y] && e[y][n] && o !== void 0 && e[y][n].$()) : (e[n] = r, e[y] && e[y][n] && o === void 0 && e[y][n].$()); | ||
let f = S(e, h), c; | ||
if ((c = E(f, n, o)) && c.$(() => r), Array.isArray(e) && e.length !== i) { | ||
for (let s = e.length; s < i; s++) (c = f[s]) && c.$(); | ||
(c = E(f, "length", i)) && c.$(e.length); | ||
} | ||
(f = c[x]) && f.$(); | ||
(c = f[x]) && c.$(); | ||
} | ||
@@ -145,4 +148,4 @@ function q(e, n) { | ||
for (let t = 0; t < r.length; t += 1) { | ||
const i = r[t]; | ||
b(e, i, n[i]); | ||
const o = r[t]; | ||
O(e, o, n[o]); | ||
} | ||
@@ -155,22 +158,22 @@ } | ||
for (; r < t; r++) { | ||
const i = n[r]; | ||
e[r] !== i && b(e, r, i); | ||
const o = n[r]; | ||
e[r] !== o && O(e, r, o); | ||
} | ||
b(e, "length", t); | ||
O(e, "length", t); | ||
} else q(e, n); | ||
} | ||
function O(e, n, r = []) { | ||
let t, i = e; | ||
function b(e, n, r = []) { | ||
let t, o = e; | ||
if (n.length > 1) { | ||
t = n.shift(); | ||
const c = typeof t, f = Array.isArray(e); | ||
const f = typeof t, c = Array.isArray(e); | ||
if (Array.isArray(t)) { | ||
for (let s = 0; s < t.length; s++) | ||
O(e, [t[s]].concat(n), r); | ||
b(e, [t[s]].concat(n), r); | ||
return; | ||
} else if (f && c === "function") { | ||
} else if (c && f === "function") { | ||
for (let s = 0; s < e.length; s++) | ||
t(e[s], s) && O(e, [s].concat(n), r); | ||
t(e[s], s) && b(e, [s].concat(n), r); | ||
return; | ||
} else if (f && c === "object") { | ||
} else if (c && f === "object") { | ||
const { | ||
@@ -182,25 +185,25 @@ from: s = 0, | ||
for (let w = s; w <= l; w += d) | ||
O(e, [w].concat(n), r); | ||
b(e, [w].concat(n), r); | ||
return; | ||
} else if (n.length > 1) { | ||
O(e[t], n, [t].concat(r)); | ||
b(e[t], n, [t].concat(r)); | ||
return; | ||
} | ||
i = e[t], r = [t].concat(r); | ||
o = e[t], r = [t].concat(r); | ||
} | ||
let o = n[0]; | ||
typeof o == "function" && (o = o(i, r), o === i) || t === void 0 && o == null || (o = A(o), t === void 0 || p(i) && p(o) && !Array.isArray(o) ? q(i, o) : b(e, t, o)); | ||
let i = n[0]; | ||
typeof i == "function" && (i = i(o, r), i === o) || t === void 0 && i == null || (i = A(i), t === void 0 || p(o) && p(i) && !Array.isArray(i) ? q(o, i) : O(e, t, i)); | ||
} | ||
function J(...[e, n]) { | ||
const r = A(e || {}), t = Array.isArray(r), i = C(r); | ||
function o(...c) { | ||
H(() => { | ||
t && c.length === 1 ? B(r, c[0]) : O(r, c); | ||
const r = A(e || {}), t = Array.isArray(r), o = C(r); | ||
function i(...f) { | ||
F(() => { | ||
t && f.length === 1 ? B(r, f[0]) : b(r, f); | ||
}); | ||
} | ||
return [i, o]; | ||
return [o, i]; | ||
} | ||
const k = /* @__PURE__ */ new WeakMap(), K = { | ||
get(e, n) { | ||
if (n === S) return e; | ||
if (n === $) return e; | ||
const r = e[n]; | ||
@@ -211,6 +214,6 @@ let t; | ||
set(e, n, r) { | ||
return b(e, n, A(r)), !0; | ||
return O(e, n, A(r)), !0; | ||
}, | ||
deleteProperty(e, n) { | ||
return b(e, n, void 0, !0), !0; | ||
return O(e, n, void 0, !0), !0; | ||
} | ||
@@ -227,11 +230,11 @@ }; | ||
} | ||
function U(e, n, r, t, i) { | ||
let o = n, c = [...e]; | ||
function U(e, n, r, t, o) { | ||
let i = n, f = [...e]; | ||
for (; ; ) { | ||
let f = c.shift(); | ||
if (!c.length) { | ||
if (typeof i == "function" && (t = i(t, f, n, e, o, r)), Array.isArray(r) || typeof r == "number") { | ||
if (typeof f > "u") | ||
let c = f.shift(); | ||
if (!f.length) { | ||
if (typeof o == "function" && (t = o(t, c, n, e, i, r)), Array.isArray(r) || typeof r == "number") { | ||
if (typeof c > "u") | ||
throw new Error("cant treat top level as a seq"); | ||
f = f; | ||
c = c; | ||
let [l, d] = Array.isArray(r) ? r : [r, r + 1]; | ||
@@ -242,7 +245,7 @@ const w = Array.isArray(r) && r.length == 0; | ||
const R = typeof t > "u"; | ||
let D = R ? "del" : w && !R ? "add" : l === d && !R ? "ins" : "replace"; | ||
typeof n[f] > "u" && (typeof t == "string" ? n[f] = "" : n[f] = []); | ||
let u = n[f]; | ||
let N = R ? "del" : w && !R ? "add" : l === d && !R ? "ins" : "replace"; | ||
typeof n[c] > "u" && (typeof t == "string" ? n[c] = "" : n[c] = []); | ||
let u = n[c]; | ||
if (Array.isArray(u)) | ||
switch (D) { | ||
switch (N) { | ||
case "add": { | ||
@@ -265,5 +268,5 @@ Array.isArray(t) ? u.push(...t) : u.push(t); | ||
if (typeof u == "string") | ||
switch (D) { | ||
switch (N) { | ||
case "add": { | ||
n[f] = u + t; | ||
n[c] = u + t; | ||
return; | ||
@@ -273,7 +276,7 @@ } | ||
case "ins": { | ||
n[f] = u.slice(0, l) + t + u.slice(d); | ||
n[c] = u.slice(0, l) + t + u.slice(d); | ||
return; | ||
} | ||
case "del": { | ||
n[f] = u.slice(0, l) + u.slice(d); | ||
n[c] = u.slice(0, l) + u.slice(d); | ||
return; | ||
@@ -286,3 +289,3 @@ } | ||
} | ||
if (typeof f > "u") { | ||
if (typeof c > "u") { | ||
if (typeof r != "string") | ||
@@ -293,22 +296,22 @@ throw new Error(`can't index top-level map with ${r}`); | ||
} | ||
typeof n[f] > "u" && (n[f] = {}), typeof t > "u" ? delete n[f][r] : n[f][r] = t; | ||
typeof n[c] > "u" && (n[c] = {}), typeof t > "u" ? delete n[c][r] : n[c][r] = t; | ||
return; | ||
} | ||
if (typeof f > "u") | ||
if (typeof c > "u") | ||
throw new Error("cant treat top level as a seq"); | ||
f = f; | ||
let s = c[0]; | ||
if (typeof n[f] > "u") | ||
c = c; | ||
let s = f[0]; | ||
if (typeof n[c] > "u") | ||
if (typeof s == "string") | ||
n[f] = {}; | ||
n[c] = {}; | ||
else if (typeof s == "number") | ||
n[f] = []; | ||
n[c] = []; | ||
else | ||
throw new Error(`can't go down this road ${n}.${f}.${s}`); | ||
n = n[f]; | ||
throw new Error(`can't go down this road ${n}.${c}.${s}`); | ||
n = n[c]; | ||
} | ||
} | ||
var V = class extends Error { | ||
var v = class extends Error { | ||
}; | ||
function v(e, n) { | ||
function ee(e, n) { | ||
let r = e.path.slice(0, -1), t = e.path[e.path.length - 1]; | ||
@@ -320,3 +323,3 @@ switch (e.action) { | ||
case "unmark": | ||
throw new V(`can't handle this: ${e.action}`); | ||
throw new v(`can't handle this: ${e.action}`); | ||
case "del": | ||
@@ -332,34 +335,34 @@ return [r, [t, +t + (e.length || 0)]]; | ||
} | ||
function ie(e) { | ||
if (!e()?.isReady()) | ||
throw new Error("please wait until the handle is ready!!!"); | ||
let [n, r] = J( | ||
e().docSync() | ||
); | ||
function t(o) { | ||
e().change(o); | ||
} | ||
function i(o) { | ||
r(ee(o.patches)); | ||
} | ||
return z(() => { | ||
e()?.on("change", i); | ||
}), T(() => { | ||
e()?.off("change", i); | ||
}), [n, t]; | ||
} | ||
function ee(e) { | ||
function ne(e) { | ||
return Q((n) => { | ||
for (let r of e) { | ||
const [t, i, o] = v(r); | ||
U(t, n, i, o); | ||
const [t, o, i] = ee(r); | ||
U(t, n, o, i); | ||
} | ||
}); | ||
} | ||
function fe(e, n) { | ||
let r = z(), [t] = D( | ||
e, | ||
async (o) => { | ||
await o.whenReady(); | ||
let [i, f] = J(o.docSync()); | ||
function c(s) { | ||
f(ne(s.patches)); | ||
} | ||
return o.on("change", c), I(r, () => T(() => o.off("change", c))), i; | ||
}, | ||
{ | ||
initialValue: e()?.docSync(), | ||
storage: n?.storage | ||
} | ||
); | ||
return t; | ||
} | ||
export { | ||
I as RepoContext, | ||
ie as createDocumentStore, | ||
oe as useDocument, | ||
G as useHandle, | ||
M as useRepo | ||
V as RepoContext, | ||
fe as createDocumentStore, | ||
ie as useDocument, | ||
M as useHandle, | ||
G as useRepo | ||
}; |
@@ -1,6 +0,8 @@ | ||
import { AnyDocumentId, ChangeFn, Doc } from '@automerge/automerge-repo/slim'; | ||
import { AnyDocumentId, ChangeFn, Doc, DocHandle } from '@automerge/automerge-repo/slim'; | ||
import { ChangeOptions } from '@automerge/automerge/slim/next'; | ||
import { Resource } from 'solid-js'; | ||
import { Resource, ResourceOptions } from 'solid-js'; | ||
export declare function useDocument<T>(id: () => AnyDocumentId | undefined): [ | ||
export declare function useDocument<T>(id: () => AnyDocumentId | undefined, options?: { | ||
storage?: ResourceOptions<Doc<T>, DocHandle<T>>["storage"]; | ||
}): [ | ||
Resource<Doc<T> | undefined>, | ||
@@ -7,0 +9,0 @@ (changeFn: ChangeFn<T>, options?: ChangeOptions<T> | undefined) => void |
export { useDocument } from './document.ts'; | ||
export { useHandle } from './handle.ts'; | ||
export { RepoContext, useRepo } from './repo.ts'; | ||
export { createDocumentStore } from './create-document-store.ts'; | ||
export { createDocumentStore } from './store/document-store.ts'; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "automerge-repo-solid-primitives", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "automerge-repo primitives for your solidjs app", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41467
1165