Comparing version 1.7.8 to 1.7.9
830
dist/dev.js
@@ -55,5 +55,7 @@ let taskIdCounter = 1, | ||
while (m <= n) { | ||
const k = n + m >> 1; | ||
const k = (n + m) >> 1; | ||
const cmp = task.expirationTime - taskQueue[k].expirationTime; | ||
if (cmp > 0) m = k + 1;else if (cmp < 0) n = k - 1;else return k; | ||
if (cmp > 0) m = k + 1; | ||
else if (cmp < 0) n = k - 1; | ||
else return k; | ||
} | ||
@@ -163,3 +165,3 @@ return m; | ||
}; | ||
const [transPending, setTransPending] = /*@__PURE__*/createSignal(false); | ||
const [transPending, setTransPending] = /*@__PURE__*/ createSignal(false); | ||
function createRoot(fn, detachedOwner) { | ||
@@ -169,16 +171,21 @@ const listener = Listener, | ||
unowned = fn.length === 0, | ||
root = unowned ? { | ||
owned: null, | ||
cleanups: null, | ||
context: null, | ||
owner: null | ||
} : { | ||
owned: null, | ||
cleanups: null, | ||
context: null, | ||
owner: detachedOwner === undefined ? owner : detachedOwner | ||
}, | ||
updateFn = unowned ? () => fn(() => { | ||
throw new Error("Dispose method must be an explicit argument to createRoot function"); | ||
}) : () => fn(() => untrack(() => cleanNode(root))); | ||
root = unowned | ||
? { | ||
owned: null, | ||
cleanups: null, | ||
context: null, | ||
owner: null | ||
} | ||
: { | ||
owned: null, | ||
cleanups: null, | ||
context: null, | ||
owner: detachedOwner === undefined ? owner : detachedOwner | ||
}, | ||
updateFn = unowned | ||
? () => | ||
fn(() => { | ||
throw new Error("Dispose method must be an explicit argument to createRoot function"); | ||
}) | ||
: () => fn(() => untrack(() => cleanNode(root))); | ||
DevHooks.afterCreateOwner && DevHooks.afterCreateOwner(root); | ||
@@ -208,3 +215,4 @@ Owner = root; | ||
if (typeof value === "function") { | ||
if (Transition && Transition.running && Transition.sources.has(s)) value = value(s.tValue);else value = value(s.value); | ||
if (Transition && Transition.running && Transition.sources.has(s)) value = value(s.tValue); | ||
else value = value(s.value); | ||
} | ||
@@ -216,12 +224,14 @@ return writeSignal(s, value); | ||
function createComputed(fn, value, options) { | ||
const c = createComputation(fn, value, true, STALE, options ); | ||
if (Scheduler && Transition && Transition.running) Updates.push(c);else updateComputation(c); | ||
const c = createComputation(fn, value, true, STALE, options); | ||
if (Scheduler && Transition && Transition.running) Updates.push(c); | ||
else updateComputation(c); | ||
} | ||
function createRenderEffect(fn, value, options) { | ||
const c = createComputation(fn, value, false, STALE, options ); | ||
if (Scheduler && Transition && Transition.running) Updates.push(c);else updateComputation(c); | ||
const c = createComputation(fn, value, false, STALE, options); | ||
if (Scheduler && Transition && Transition.running) Updates.push(c); | ||
else updateComputation(c); | ||
} | ||
function createEffect(fn, value, options) { | ||
runEffects = runUserEffects; | ||
const c = createComputation(fn, value, false, STALE, options ), | ||
const c = createComputation(fn, value, false, STALE, options), | ||
s = SuspenseContext && lookup(Owner, SuspenseContext.id); | ||
@@ -234,6 +244,12 @@ if (s) c.suspense = s; | ||
let fn; | ||
const c = createComputation(() => { | ||
fn ? fn() : untrack(onInvalidate); | ||
fn = undefined; | ||
}, undefined, false, 0, options ), | ||
const c = createComputation( | ||
() => { | ||
fn ? fn() : untrack(onInvalidate); | ||
fn = undefined; | ||
}, | ||
undefined, | ||
false, | ||
0, | ||
options | ||
), | ||
s = SuspenseContext && lookup(Owner, SuspenseContext.id); | ||
@@ -249,3 +265,3 @@ if (s) c.suspense = s; | ||
options = options ? Object.assign({}, signalOptions, options) : signalOptions; | ||
const c = createComputation(fn, value, true, 0, options ); | ||
const c = createComputation(fn, value, true, 0, options); | ||
c.observers = null; | ||
@@ -264,3 +280,3 @@ c.observerSlots = null; | ||
let options; | ||
if (arguments.length === 2 && typeof pFetcher === "object" || arguments.length === 1) { | ||
if ((arguments.length === 2 && typeof pFetcher === "object") || arguments.length === 1) { | ||
source = true; | ||
@@ -279,3 +295,3 @@ fetcher = pSource; | ||
scheduled = false, | ||
resolved = ("initialValue" in options), | ||
resolved = "initialValue" in options, | ||
dynamic = typeof source === "function" && createMemo(source); | ||
@@ -292,3 +308,4 @@ const contexts = new Set(), | ||
let v; | ||
if (options.ssrLoadFrom === "initial") initP = options.initialValue;else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v[0]; | ||
if (options.ssrLoadFrom === "initial") initP = options.initialValue; | ||
else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v[0]; | ||
} | ||
@@ -299,5 +316,8 @@ function loadEnd(p, v, error, key) { | ||
key !== undefined && (resolved = true); | ||
if ((p === initP || v === initP) && options.onHydrated) queueMicrotask(() => options.onHydrated(key, { | ||
value: v | ||
})); | ||
if ((p === initP || v === initP) && options.onHydrated) | ||
queueMicrotask(() => | ||
options.onHydrated(key, { | ||
value: v | ||
}) | ||
); | ||
initP = NO_INIT; | ||
@@ -333,3 +353,4 @@ if (Transition && p && loadedUnderTransition) { | ||
if (pr) { | ||
if (c.resolved && Transition && loadedUnderTransition) Transition.promises.add(pr);else if (!contexts.has(c)) { | ||
if (c.resolved && Transition && loadedUnderTransition) Transition.promises.add(pr); | ||
else if (!contexts.has(c)) { | ||
c.increment(); | ||
@@ -353,6 +374,11 @@ contexts.add(c); | ||
if (Transition && pr) Transition.promises.delete(pr); | ||
const p = initP !== NO_INIT ? initP : untrack(() => fetcher(lookup, { | ||
value: value(), | ||
refetching | ||
})); | ||
const p = | ||
initP !== NO_INIT | ||
? initP | ||
: untrack(() => | ||
fetcher(lookup, { | ||
value: value(), | ||
refetching | ||
}) | ||
); | ||
if (typeof p !== "object" || !(p && "then" in p)) { | ||
@@ -364,3 +390,3 @@ loadEnd(pr, p, undefined, lookup); | ||
scheduled = true; | ||
queueMicrotask(() => scheduled = false); | ||
queueMicrotask(() => (scheduled = false)); | ||
runUpdates(() => { | ||
@@ -370,3 +396,6 @@ setState(resolved ? "refreshing" : "pending"); | ||
}, false); | ||
return p.then(v => loadEnd(p, v, undefined, lookup), e => loadEnd(p, undefined, castError(e), lookup)); | ||
return p.then( | ||
v => loadEnd(p, v, undefined, lookup), | ||
e => loadEnd(p, undefined, castError(e), lookup) | ||
); | ||
} | ||
@@ -395,7 +424,11 @@ Object.defineProperties(read, { | ||
}); | ||
if (dynamic) createComputed(() => load(false));else load(false); | ||
return [read, { | ||
refetch: load, | ||
mutate: setValue | ||
}]; | ||
if (dynamic) createComputed(() => load(false)); | ||
else load(false); | ||
return [ | ||
read, | ||
{ | ||
refetch: load, | ||
mutate: setValue | ||
} | ||
]; | ||
} | ||
@@ -405,8 +438,18 @@ function createDeferred(source, options) { | ||
timeout = options ? options.timeoutMs : undefined; | ||
const node = createComputation(() => { | ||
if (!t || !t.fn) t = requestCallback(() => setDeferred(() => node.value), timeout !== undefined ? { | ||
timeout | ||
} : undefined); | ||
return source(); | ||
}, undefined, true); | ||
const node = createComputation( | ||
() => { | ||
if (!t || !t.fn) | ||
t = requestCallback( | ||
() => setDeferred(() => node.value), | ||
timeout !== undefined | ||
? { | ||
timeout | ||
} | ||
: undefined | ||
); | ||
return source(); | ||
}, | ||
undefined, | ||
true | ||
); | ||
const [deferred, setDeferred] = createSignal(node.value, options); | ||
@@ -419,12 +462,20 @@ updateComputation(node); | ||
const subs = new Map(); | ||
const node = createComputation(p => { | ||
const v = source(); | ||
for (const [key, val] of subs.entries()) if (fn(key, v) !== fn(key, p)) { | ||
for (const c of val.values()) { | ||
c.state = STALE; | ||
if (c.pure) Updates.push(c);else Effects.push(c); | ||
} | ||
} | ||
return v; | ||
}, undefined, true, STALE, options ); | ||
const node = createComputation( | ||
p => { | ||
const v = source(); | ||
for (const [key, val] of subs.entries()) | ||
if (fn(key, v) !== fn(key, p)) { | ||
for (const c of val.values()) { | ||
c.state = STALE; | ||
if (c.pure) Updates.push(c); | ||
else Effects.push(c); | ||
} | ||
} | ||
return v; | ||
}, | ||
undefined, | ||
true, | ||
STALE, | ||
options | ||
); | ||
updateComputation(node); | ||
@@ -435,3 +486,4 @@ return key => { | ||
let l; | ||
if (l = subs.get(key)) l.add(listener);else subs.set(key, l = new Set([listener])); | ||
if ((l = subs.get(key))) l.add(listener); | ||
else subs.set(key, (l = new Set([listener]))); | ||
onCleanup(() => { | ||
@@ -442,3 +494,6 @@ l.delete(listener); | ||
} | ||
return fn(key, Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value); | ||
return fn( | ||
key, | ||
Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value | ||
); | ||
}; | ||
@@ -482,3 +537,6 @@ } | ||
function onCleanup(fn) { | ||
if (Owner === null) console.warn("cleanups created outside a `createRoot` or `render` will never be run");else if (Owner.cleanups === null) Owner.cleanups = [fn];else Owner.cleanups.push(fn); | ||
if (Owner === null) | ||
console.warn("cleanups created outside a `createRoot` or `render` will never be run"); | ||
else if (Owner.cleanups === null) Owner.cleanups = [fn]; | ||
else Owner.cleanups.push(fn); | ||
return fn; | ||
@@ -503,5 +561,10 @@ } | ||
ERROR || (ERROR = Symbol("error")); | ||
if (Owner === null) console.warn("error handlers created outside a `createRoot` or `render` will never be run");else if (Owner.context === null) Owner.context = { | ||
[ERROR]: [fn] | ||
};else if (!Owner.context[ERROR]) Owner.context[ERROR] = [fn];else Owner.context[ERROR].push(fn); | ||
if (Owner === null) | ||
console.warn("error handlers created outside a `createRoot` or `render` will never be run"); | ||
else if (Owner.context === null) | ||
Owner.context = { | ||
[ERROR]: [fn] | ||
}; | ||
else if (!Owner.context[ERROR]) Owner.context[ERROR] = [fn]; | ||
else Owner.context[ERROR].push(fn); | ||
} | ||
@@ -543,11 +606,13 @@ function getListener() { | ||
if (Scheduler || SuspenseContext) { | ||
t = Transition || (Transition = { | ||
sources: new Set(), | ||
effects: [], | ||
promises: new Set(), | ||
disposed: new Set(), | ||
queue: new Set(), | ||
running: true | ||
}); | ||
t.done || (t.done = new Promise(res => t.resolve = res)); | ||
t = | ||
Transition || | ||
(Transition = { | ||
sources: new Set(), | ||
effects: [], | ||
promises: new Set(), | ||
disposed: new Set(), | ||
queue: new Set(), | ||
running: true | ||
}); | ||
t.done || (t.done = new Promise(res => (t.resolve = res))); | ||
t.running = true; | ||
@@ -568,8 +633,14 @@ } | ||
function devComponent(Comp, props) { | ||
const c = createComputation(() => untrack(() => { | ||
Object.assign(Comp, { | ||
[$DEVCOMP]: true | ||
}); | ||
return Comp(props); | ||
}), undefined, true, 0); | ||
const c = createComputation( | ||
() => | ||
untrack(() => { | ||
Object.assign(Comp, { | ||
[$DEVCOMP]: true | ||
}); | ||
return Comp(props); | ||
}), | ||
undefined, | ||
true, | ||
0 | ||
); | ||
c.props = props; | ||
@@ -585,3 +656,4 @@ c.observers = null; | ||
if (!Owner) return; | ||
if (Owner.sourceMap) Owner.sourceMap.push(value);else Owner.sourceMap = [value]; | ||
if (Owner.sourceMap) Owner.sourceMap.push(value); | ||
else Owner.sourceMap = [value]; | ||
value.graph = Owner; | ||
@@ -605,3 +677,3 @@ } | ||
name: "children" | ||
}) ; | ||
}); | ||
memo.toArray = () => { | ||
@@ -638,3 +710,4 @@ const c = memo(); | ||
if (this.sources && (runningTransition ? this.tState : this.state)) { | ||
if ((runningTransition ? this.tState : this.state) === STALE) updateComputation(this);else { | ||
if ((runningTransition ? this.tState : this.state) === STALE) updateComputation(this); | ||
else { | ||
const updates = Updates; | ||
@@ -667,7 +740,8 @@ Updates = null; | ||
function writeSignal(node, value, isComp) { | ||
let current = Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value; | ||
let current = | ||
Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value; | ||
if (!node.comparator || !node.comparator(current, value)) { | ||
if (Transition) { | ||
const TransitionRunning = Transition.running; | ||
if (TransitionRunning || !isComp && Transition.sources.has(node)) { | ||
if (TransitionRunning || (!isComp && Transition.sources.has(node))) { | ||
Transition.sources.add(node); | ||
@@ -685,6 +759,8 @@ node.tValue = value; | ||
if (TransitionRunning ? !o.tState : !o.state) { | ||
if (o.pure) Updates.push(o);else Effects.push(o); | ||
if (o.pure) Updates.push(o); | ||
else Effects.push(o); | ||
if (o.observers) markDownstream(o); | ||
} | ||
if (!TransitionRunning) o.state = STALE;else o.tState = STALE; | ||
if (!TransitionRunning) o.state = STALE; | ||
else o.tState = STALE; | ||
} | ||
@@ -708,3 +784,7 @@ if (Updates.length > 10e5) { | ||
Listener = Owner = node; | ||
runComputation(node, Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value, time); | ||
runComputation( | ||
node, | ||
Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value, | ||
time | ||
); | ||
if (Transition && !Transition.running && Transition.sources.has(node)) { | ||
@@ -770,7 +850,11 @@ queueMicrotask(() => { | ||
} | ||
if (Owner === null) console.warn("computations created outside a `createRoot` or `render` will never be disposed");else if (Owner !== UNOWNED) { | ||
if (Owner === null) | ||
console.warn("computations created outside a `createRoot` or `render` will never be disposed"); | ||
else if (Owner !== UNOWNED) { | ||
if (Transition && Transition.running && Owner.pure) { | ||
if (!Owner.tOwned) Owner.tOwned = [c];else Owner.tOwned.push(c); | ||
if (!Owner.tOwned) Owner.tOwned = [c]; | ||
else Owner.tOwned.push(c); | ||
} else { | ||
if (!Owner.owned) Owner.owned = [c];else Owner.owned.push(c); | ||
if (!Owner.owned) Owner.owned = [c]; | ||
else Owner.owned.push(c); | ||
} | ||
@@ -828,3 +912,4 @@ } | ||
if (!init) Updates = []; | ||
if (Effects) wait = true;else Effects = []; | ||
if (Effects) wait = true; | ||
else Effects = []; | ||
ExecCount++; | ||
@@ -843,3 +928,4 @@ try { | ||
if (Updates) { | ||
if (Scheduler && Transition && Transition.running) scheduleQueue(Updates);else runQueue(Updates); | ||
if (Scheduler && Transition && Transition.running) scheduleQueue(Updates); | ||
else runQueue(Updates); | ||
Updates = null; | ||
@@ -884,3 +970,4 @@ } | ||
Effects = null; | ||
if (e.length) runUpdates(() => runEffects(e), false);else DevHooks.afterUpdate && DevHooks.afterUpdate(); | ||
if (e.length) runUpdates(() => runEffects(e), false); | ||
else DevHooks.afterUpdate && DevHooks.afterUpdate(); | ||
if (res) res(); | ||
@@ -913,3 +1000,4 @@ } | ||
const e = queue[i]; | ||
if (!e.user) runTop(e);else queue[userLength++] = e; | ||
if (!e.user) runTop(e); | ||
else queue[userLength++] = e; | ||
} | ||
@@ -932,3 +1020,4 @@ if (sharedConfig.context) { | ||
const runningTransition = Transition && Transition.running; | ||
if (runningTransition) node.tState = 0;else node.state = 0; | ||
if (runningTransition) node.tState = 0; | ||
else node.state = 0; | ||
for (let i = 0; i < node.sources.length; i += 1) { | ||
@@ -939,3 +1028,4 @@ const source = node.sources[i]; | ||
if (state === STALE) { | ||
if (source !== ignore && (!source.updatedAt || source.updatedAt < ExecCount)) runTop(source); | ||
if (source !== ignore && (!source.updatedAt || source.updatedAt < ExecCount)) | ||
runTop(source); | ||
} else if (state === PENDING) lookUpstream(source, ignore); | ||
@@ -950,4 +1040,6 @@ } | ||
if (runningTransition ? !o.tState : !o.state) { | ||
if (runningTransition) o.tState = PENDING;else o.state = PENDING; | ||
if (o.pure) Updates.push(o);else Effects.push(o); | ||
if (runningTransition) o.tState = PENDING; | ||
else o.state = PENDING; | ||
if (o.pure) Updates.push(o); | ||
else Effects.push(o); | ||
o.observers && markDownstream(o); | ||
@@ -989,3 +1081,4 @@ } | ||
} | ||
if (Transition && Transition.running) node.tState = 0;else node.state = 0; | ||
if (Transition && Transition.running) node.tState = 0; | ||
else node.state = 0; | ||
node.context = null; | ||
@@ -1013,3 +1106,3 @@ delete node.sourceMap; | ||
} catch (e) { | ||
handleError(e, owner && owner.owner || null); | ||
handleError(e, (owner && owner.owner) || null); | ||
} | ||
@@ -1021,11 +1114,17 @@ } | ||
if (!fns) throw error; | ||
if (Effects) Effects.push({ | ||
fn() { | ||
runErrors(error, fns, owner); | ||
}, | ||
state: STALE | ||
});else runErrors(error, fns, owner); | ||
if (Effects) | ||
Effects.push({ | ||
fn() { | ||
runErrors(error, fns, owner); | ||
}, | ||
state: STALE | ||
}); | ||
else runErrors(error, fns, owner); | ||
} | ||
function lookup(owner, key) { | ||
return owner ? owner.context && owner.context[key] !== undefined ? owner.context[key] : lookup(owner.owner, key) : undefined; | ||
return owner | ||
? owner.context && owner.context[key] !== undefined | ||
? owner.context[key] | ||
: lookup(owner.owner, key) | ||
: undefined; | ||
} | ||
@@ -1047,8 +1146,13 @@ function resolveChildren(children) { | ||
let res; | ||
createRenderEffect(() => res = untrack(() => { | ||
Owner.context = { | ||
[id]: props.value | ||
}; | ||
return children(() => props.children); | ||
}), undefined, options); | ||
createRenderEffect( | ||
() => | ||
(res = untrack(() => { | ||
Owner.context = { | ||
[id]: props.value | ||
}; | ||
return children(() => props.children); | ||
})), | ||
undefined, | ||
options | ||
); | ||
return res; | ||
@@ -1064,3 +1168,4 @@ }; | ||
} | ||
const handler = typeof observer === "function" ? observer : observer.next && observer.next.bind(observer); | ||
const handler = | ||
typeof observer === "function" ? observer : observer.next && observer.next.bind(observer); | ||
if (!handler) { | ||
@@ -1096,3 +1201,3 @@ return { | ||
const unsub = producer.subscribe(v => set(() => v)); | ||
onCleanup(() => "unsubscribe" in unsub ? unsub.unsubscribe() : unsub()); | ||
onCleanup(() => ("unsubscribe" in unsub ? unsub.unsubscribe() : unsub())); | ||
} else { | ||
@@ -1149,4 +1254,3 @@ const clean = producer(set); | ||
} | ||
} | ||
else if (len === 0) { | ||
} else if (len === 0) { | ||
mapped = new Array(newLen); | ||
@@ -1162,4 +1266,12 @@ for (j = 0; j < newLen; j++) { | ||
indexes && (tempIndexes = new Array(newLen)); | ||
for (start = 0, end = Math.min(len, newLen); start < end && items[start] === newItems[start]; start++); | ||
for (end = len - 1, newEnd = newLen - 1; end >= start && newEnd >= start && items[end] === newItems[newEnd]; end--, newEnd--) { | ||
for ( | ||
start = 0, end = Math.min(len, newLen); | ||
start < end && items[start] === newItems[start]; | ||
start++ | ||
); | ||
for ( | ||
end = len - 1, newEnd = newLen - 1; | ||
end >= start && newEnd >= start && items[end] === newItems[newEnd]; | ||
end--, newEnd-- | ||
) { | ||
temp[newEnd] = mapped[end]; | ||
@@ -1198,3 +1310,3 @@ tempdisposers[newEnd] = disposers[end]; | ||
} | ||
mapped = mapped.slice(0, len = newLen); | ||
mapped = mapped.slice(0, (len = newLen)); | ||
items = newItems.slice(0); | ||
@@ -1209,3 +1321,3 @@ } | ||
name: "index" | ||
}) ; | ||
}); | ||
indexes[j] = set; | ||
@@ -1268,3 +1380,3 @@ return mapFn(newItems[j], s); | ||
items = newItems.slice(0); | ||
return mapped = mapped.slice(0, len); | ||
return (mapped = mapped.slice(0, len)); | ||
}); | ||
@@ -1275,3 +1387,3 @@ function mapper(disposer) { | ||
name: "value" | ||
}) ; | ||
}); | ||
signals[i] = set; | ||
@@ -1292,3 +1404,3 @@ return mapFn(s, i); | ||
setHydrateContext(nextHydrateContext()); | ||
const r = devComponent(Comp, props || {}) ; | ||
const r = devComponent(Comp, props || {}); | ||
setHydrateContext(c); | ||
@@ -1342,25 +1454,29 @@ return r; | ||
const s = sources[i]; | ||
proxy = proxy || !!s && $PROXY in s; | ||
sources[i] = typeof s === "function" ? (proxy = true, createMemo(s)) : s; | ||
proxy = proxy || (!!s && $PROXY in s); | ||
sources[i] = typeof s === "function" ? ((proxy = true), createMemo(s)) : s; | ||
} | ||
if (proxy) { | ||
return new Proxy({ | ||
get(property) { | ||
for (let i = sources.length - 1; i >= 0; i--) { | ||
const v = resolveSource(sources[i])[property]; | ||
if (v !== undefined) return v; | ||
return new Proxy( | ||
{ | ||
get(property) { | ||
for (let i = sources.length - 1; i >= 0; i--) { | ||
const v = resolveSource(sources[i])[property]; | ||
if (v !== undefined) return v; | ||
} | ||
}, | ||
has(property) { | ||
for (let i = sources.length - 1; i >= 0; i--) { | ||
if (property in resolveSource(sources[i])) return true; | ||
} | ||
return false; | ||
}, | ||
keys() { | ||
const keys = []; | ||
for (let i = 0; i < sources.length; i++) | ||
keys.push(...Object.keys(resolveSource(sources[i]))); | ||
return [...new Set(keys)]; | ||
} | ||
}, | ||
has(property) { | ||
for (let i = sources.length - 1; i >= 0; i--) { | ||
if (property in resolveSource(sources[i])) return true; | ||
} | ||
return false; | ||
}, | ||
keys() { | ||
const keys = []; | ||
for (let i = 0; i < sources.length; i++) keys.push(...Object.keys(resolveSource(sources[i]))); | ||
return [...new Set(keys)]; | ||
} | ||
}, propTraps); | ||
propTraps | ||
); | ||
} | ||
@@ -1384,3 +1500,3 @@ const target = {}; | ||
configurable: true, | ||
get: resolveSources.bind(sourcesMap[key] = [desc.get.bind(source)]) | ||
get: resolveSources.bind((sourcesMap[key] = [desc.get.bind(source)])) | ||
}); | ||
@@ -1409,25 +1525,33 @@ } else { | ||
const res = keys.map(k => { | ||
return new Proxy({ | ||
get(property) { | ||
return k.includes(property) ? props[property] : undefined; | ||
return new Proxy( | ||
{ | ||
get(property) { | ||
return k.includes(property) ? props[property] : undefined; | ||
}, | ||
has(property) { | ||
return k.includes(property) && property in props; | ||
}, | ||
keys() { | ||
return k.filter(property => property in props); | ||
} | ||
}, | ||
has(property) { | ||
return k.includes(property) && property in props; | ||
propTraps | ||
); | ||
}); | ||
res.push( | ||
new Proxy( | ||
{ | ||
get(property) { | ||
return blocked.has(property) ? undefined : props[property]; | ||
}, | ||
has(property) { | ||
return blocked.has(property) ? false : property in props; | ||
}, | ||
keys() { | ||
return Object.keys(props).filter(k => !blocked.has(k)); | ||
} | ||
}, | ||
keys() { | ||
return k.filter(property => property in props); | ||
} | ||
}, propTraps); | ||
}); | ||
res.push(new Proxy({ | ||
get(property) { | ||
return blocked.has(property) ? undefined : props[property]; | ||
}, | ||
has(property) { | ||
return blocked.has(property) ? false : property in props; | ||
}, | ||
keys() { | ||
return Object.keys(props).filter(k => !blocked.has(k)); | ||
} | ||
}, propTraps)); | ||
propTraps | ||
) | ||
); | ||
return res; | ||
@@ -1439,3 +1563,4 @@ } | ||
const desc = Object.getOwnPropertyDescriptor(props, propName); | ||
const isDefaultDesc = !desc.get && !desc.set && desc.enumerable && desc.writable && desc.configurable; | ||
const isDefaultDesc = | ||
!desc.get && !desc.set && desc.enumerable && desc.writable && desc.configurable; | ||
let blocked = false; | ||
@@ -1446,3 +1571,5 @@ let objectIndex = 0; | ||
blocked = true; | ||
isDefaultDesc ? objects[objectIndex][propName] = desc.value : Object.defineProperty(objects[objectIndex], propName, desc); | ||
isDefaultDesc | ||
? (objects[objectIndex][propName] = desc.value) | ||
: Object.defineProperty(objects[objectIndex], propName, desc); | ||
} | ||
@@ -1452,3 +1579,5 @@ ++objectIndex; | ||
if (!blocked) { | ||
isDefaultDesc ? otherObject[propName] = desc.value : Object.defineProperty(otherObject, propName, desc); | ||
isDefaultDesc | ||
? (otherObject[propName] = desc.value) | ||
: Object.defineProperty(otherObject, propName, desc); | ||
} | ||
@@ -1479,15 +1608,20 @@ } | ||
let Comp; | ||
return createMemo(() => (Comp = comp()) && untrack(() => { | ||
if (true) Object.assign(Comp, { | ||
[$DEVCOMP]: true | ||
}); | ||
if (!ctx) return Comp(props); | ||
const c = sharedConfig.context; | ||
setHydrateContext(ctx); | ||
const r = Comp(props); | ||
setHydrateContext(c); | ||
return r; | ||
})); | ||
return createMemo( | ||
() => | ||
(Comp = comp()) && | ||
untrack(() => { | ||
if (true) | ||
Object.assign(Comp, { | ||
[$DEVCOMP]: true | ||
}); | ||
if (!ctx) return Comp(props); | ||
const c = sharedConfig.context; | ||
setHydrateContext(ctx); | ||
const r = Comp(props); | ||
setHydrateContext(c); | ||
return r; | ||
}) | ||
); | ||
}; | ||
wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p); | ||
wrap.preload = () => p || ((p = fn()).then(mod => (comp = () => mod.default)), p); | ||
return wrap; | ||
@@ -1501,3 +1635,4 @@ } | ||
const narrowedError = name => `Attempting to access a stale value from <${name}> that could possibly be undefined. This may occur because you are reading the accessor returned from the component at a time where it has already been unmounted. We recommend cleaning up any stale timers or async, or reading from the initial condition.` ; | ||
const narrowedError = name => | ||
`Attempting to access a stale value from <${name}> that could possibly be undefined. This may occur because you are reading the accessor returned from the component at a time where it has already been unmounted. We recommend cleaning up any stale timers or async, or reading from the initial condition.`; | ||
function For(props) { | ||
@@ -1507,5 +1642,9 @@ const fallback = "fallback" in props && { | ||
}; | ||
return createMemo(mapArray(() => props.each, props.children, fallback || undefined), undefined, { | ||
name: "value" | ||
}) ; | ||
return createMemo( | ||
mapArray(() => props.each, props.children, fallback || undefined), | ||
undefined, | ||
{ | ||
name: "value" | ||
} | ||
); | ||
} | ||
@@ -1516,5 +1655,9 @@ function Index(props) { | ||
}; | ||
return createMemo(indexArray(() => props.each, props.children, fallback || undefined), undefined, { | ||
name: "value" | ||
}) ; | ||
return createMemo( | ||
indexArray(() => props.each, props.children, fallback || undefined), | ||
undefined, | ||
{ | ||
name: "value" | ||
} | ||
); | ||
} | ||
@@ -1524,51 +1667,80 @@ function Show(props) { | ||
const condition = createMemo(() => props.when, undefined, { | ||
equals: (a, b) => keyed ? a === b : !a === !b, | ||
equals: (a, b) => (keyed ? a === b : !a === !b), | ||
name: "condition" | ||
} ); | ||
return createMemo(() => { | ||
const c = condition(); | ||
if (c) { | ||
const child = props.children; | ||
const fn = typeof child === "function" && child.length > 0; | ||
return fn ? untrack(() => child(keyed ? c : () => { | ||
if (!untrack(condition)) throw narrowedError("Show"); | ||
return props.when; | ||
})) : child; | ||
}); | ||
return createMemo( | ||
() => { | ||
const c = condition(); | ||
if (c) { | ||
const child = props.children; | ||
const fn = typeof child === "function" && child.length > 0; | ||
return fn | ||
? untrack(() => | ||
child( | ||
keyed | ||
? c | ||
: () => { | ||
if (!untrack(condition)) throw narrowedError("Show"); | ||
return props.when; | ||
} | ||
) | ||
) | ||
: child; | ||
} | ||
return props.fallback; | ||
}, | ||
undefined, | ||
{ | ||
name: "value" | ||
} | ||
return props.fallback; | ||
}, undefined, { | ||
name: "value" | ||
} ); | ||
); | ||
} | ||
function Switch(props) { | ||
let keyed = false; | ||
const equals = (a, b) => a[0] === b[0] && (keyed ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]; | ||
const equals = (a, b) => | ||
a[0] === b[0] && (keyed ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]; | ||
const conditions = children(() => props.children), | ||
evalConditions = createMemo(() => { | ||
let conds = conditions(); | ||
if (!Array.isArray(conds)) conds = [conds]; | ||
for (let i = 0; i < conds.length; i++) { | ||
const c = conds[i].when; | ||
if (c) { | ||
keyed = !!conds[i].keyed; | ||
return [i, c, conds[i]]; | ||
evalConditions = createMemo( | ||
() => { | ||
let conds = conditions(); | ||
if (!Array.isArray(conds)) conds = [conds]; | ||
for (let i = 0; i < conds.length; i++) { | ||
const c = conds[i].when; | ||
if (c) { | ||
keyed = !!conds[i].keyed; | ||
return [i, c, conds[i]]; | ||
} | ||
} | ||
return [-1]; | ||
}, | ||
undefined, | ||
{ | ||
equals, | ||
name: "eval conditions" | ||
} | ||
return [-1]; | ||
}, undefined, { | ||
equals, | ||
name: "eval conditions" | ||
} ); | ||
return createMemo(() => { | ||
const [index, when, cond] = evalConditions(); | ||
if (index < 0) return props.fallback; | ||
const c = cond.children; | ||
const fn = typeof c === "function" && c.length > 0; | ||
return fn ? untrack(() => c(keyed ? when : () => { | ||
if (untrack(evalConditions)[0] !== index) throw narrowedError("Match"); | ||
return cond.when; | ||
})) : c; | ||
}, undefined, { | ||
name: "value" | ||
} ); | ||
); | ||
return createMemo( | ||
() => { | ||
const [index, when, cond] = evalConditions(); | ||
if (index < 0) return props.fallback; | ||
const c = cond.children; | ||
const fn = typeof c === "function" && c.length > 0; | ||
return fn | ||
? untrack(() => | ||
c( | ||
keyed | ||
? when | ||
: () => { | ||
if (untrack(evalConditions)[0] !== index) throw narrowedError("Match"); | ||
return cond.when; | ||
} | ||
) | ||
) | ||
: c; | ||
}, | ||
undefined, | ||
{ | ||
name: "value" | ||
} | ||
); | ||
} | ||
@@ -1585,23 +1757,33 @@ function Match(props) { | ||
let v; | ||
if (sharedConfig.context && sharedConfig.load && (v = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count))) err = v[0]; | ||
if ( | ||
sharedConfig.context && | ||
sharedConfig.load && | ||
(v = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count)) | ||
) | ||
err = v[0]; | ||
const [errored, setErrored] = createSignal(err, { | ||
name: "errored" | ||
} ); | ||
}); | ||
Errors || (Errors = new Set()); | ||
Errors.add(setErrored); | ||
onCleanup(() => Errors.delete(setErrored)); | ||
return createMemo(() => { | ||
let e; | ||
if (e = errored()) { | ||
const f = props.fallback; | ||
if ((typeof f !== "function" || f.length == 0)) console.error(e); | ||
return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored())) : f; | ||
return createMemo( | ||
() => { | ||
let e; | ||
if ((e = errored())) { | ||
const f = props.fallback; | ||
if (typeof f !== "function" || f.length == 0) console.error(e); | ||
return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored())) : f; | ||
} | ||
return catchError(() => props.children, setErrored); | ||
}, | ||
undefined, | ||
{ | ||
name: "value" | ||
} | ||
return catchError(() => props.children, setErrored); | ||
}, undefined, { | ||
name: "value" | ||
} ); | ||
); | ||
} | ||
const suspenseListEquals = (a, b) => a.showContent === b.showContent && a.showFallback === b.showFallback; | ||
const suspenseListEquals = (a, b) => | ||
a.showContent === b.showContent && a.showFallback === b.showFallback; | ||
const SuspenseListContext = createContext(); | ||
@@ -1618,47 +1800,47 @@ function SuspenseList(props) { | ||
} | ||
const resolved = createMemo(prev => { | ||
const reveal = props.revealOrder, | ||
tail = props.tail, | ||
{ | ||
showContent = true, | ||
showFallback = true | ||
} = show ? show() : {}, | ||
reg = registry(), | ||
reverse = reveal === "backwards"; | ||
if (reveal === "together") { | ||
const all = reg.every(inFallback => !inFallback()); | ||
const res = reg.map(() => ({ | ||
showContent: all && showContent, | ||
showFallback | ||
})); | ||
res.inFallback = !all; | ||
return res; | ||
} | ||
let stop = false; | ||
let inFallback = prev.inFallback; | ||
const res = []; | ||
for (let i = 0, len = reg.length; i < len; i++) { | ||
const n = reverse ? len - i - 1 : i, | ||
s = reg[n](); | ||
if (!stop && !s) { | ||
res[n] = { | ||
showContent, | ||
const resolved = createMemo( | ||
prev => { | ||
const reveal = props.revealOrder, | ||
tail = props.tail, | ||
{ showContent = true, showFallback = true } = show ? show() : {}, | ||
reg = registry(), | ||
reverse = reveal === "backwards"; | ||
if (reveal === "together") { | ||
const all = reg.every(inFallback => !inFallback()); | ||
const res = reg.map(() => ({ | ||
showContent: all && showContent, | ||
showFallback | ||
}; | ||
} else { | ||
const next = !stop; | ||
if (next) inFallback = true; | ||
res[n] = { | ||
showContent: next, | ||
showFallback: !tail || next && tail === "collapsed" ? showFallback : false | ||
}; | ||
stop = true; | ||
})); | ||
res.inFallback = !all; | ||
return res; | ||
} | ||
let stop = false; | ||
let inFallback = prev.inFallback; | ||
const res = []; | ||
for (let i = 0, len = reg.length; i < len; i++) { | ||
const n = reverse ? len - i - 1 : i, | ||
s = reg[n](); | ||
if (!stop && !s) { | ||
res[n] = { | ||
showContent, | ||
showFallback | ||
}; | ||
} else { | ||
const next = !stop; | ||
if (next) inFallback = true; | ||
res[n] = { | ||
showContent: next, | ||
showFallback: !tail || (next && tail === "collapsed") ? showFallback : false | ||
}; | ||
stop = true; | ||
} | ||
} | ||
if (!stop) inFallback = false; | ||
res.inFallback = inFallback; | ||
return res; | ||
}, | ||
{ | ||
inFallback: false | ||
} | ||
if (!stop) inFallback = false; | ||
res.inFallback = inFallback; | ||
return res; | ||
}, { | ||
inFallback: false | ||
}); | ||
); | ||
setWrapper(() => resolved); | ||
@@ -1737,3 +1919,3 @@ return createComponent(SuspenseListContext.Provider, { | ||
flicker(); | ||
return flicker = undefined; | ||
return (flicker = undefined); | ||
} | ||
@@ -1744,7 +1926,4 @@ if (ctx && p === "$$f") setHydrateContext(); | ||
const inFallback = store.inFallback(), | ||
{ | ||
showContent = true, | ||
showFallback = true | ||
} = show ? show() : {}; | ||
if ((!inFallback || p && p !== "$$f") && showContent) { | ||
{ showContent = true, showFallback = true } = show ? show() : {}; | ||
if ((!inFallback || (p && p !== "$$f")) && showContent) { | ||
store.resolved = true; | ||
@@ -1779,7 +1958,66 @@ dispose && dispose(); | ||
registerGraph | ||
} ; | ||
}; | ||
if (globalThis) { | ||
if (!globalThis.Solid$$) globalThis.Solid$$ = true;else console.warn("You appear to have multiple instances of Solid. This can lead to unexpected behavior."); | ||
if (!globalThis.Solid$$) globalThis.Solid$$ = true; | ||
else | ||
console.warn( | ||
"You appear to have multiple instances of Solid. This can lead to unexpected behavior." | ||
); | ||
} | ||
export { $DEVCOMP, $PROXY, $TRACK, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, batch, cancelCallback, catchError, children, createComponent, createComputed, createContext, createDeferred, createEffect, createMemo, createReaction, createRenderEffect, createResource, createRoot, createSelector, createSignal, createUniqueId, enableExternalSource, enableHydration, enableScheduling, equalFn, from, getListener, getOwner, indexArray, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, requestCallback, resetErrorBoundaries, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition }; | ||
export { | ||
$DEVCOMP, | ||
$PROXY, | ||
$TRACK, | ||
DEV, | ||
ErrorBoundary, | ||
For, | ||
Index, | ||
Match, | ||
Show, | ||
Suspense, | ||
SuspenseList, | ||
Switch, | ||
batch, | ||
cancelCallback, | ||
catchError, | ||
children, | ||
createComponent, | ||
createComputed, | ||
createContext, | ||
createDeferred, | ||
createEffect, | ||
createMemo, | ||
createReaction, | ||
createRenderEffect, | ||
createResource, | ||
createRoot, | ||
createSelector, | ||
createSignal, | ||
createUniqueId, | ||
enableExternalSource, | ||
enableHydration, | ||
enableScheduling, | ||
equalFn, | ||
from, | ||
getListener, | ||
getOwner, | ||
indexArray, | ||
lazy, | ||
mapArray, | ||
mergeProps, | ||
observable, | ||
on, | ||
onCleanup, | ||
onError, | ||
onMount, | ||
requestCallback, | ||
resetErrorBoundaries, | ||
runWithOwner, | ||
sharedConfig, | ||
splitProps, | ||
startTransition, | ||
untrack, | ||
useContext, | ||
useTransition | ||
}; |
@@ -20,3 +20,3 @@ const equalFn = (a, b) => a === b; | ||
} catch (e) { | ||
handleError(e, owner && owner.owner || null); | ||
handleError(e, (owner && owner.owner) || null); | ||
} | ||
@@ -39,3 +39,4 @@ } | ||
if (Owner) { | ||
if (!Owner.owned) Owner.owned = [o];else Owner.owned.push(o); | ||
if (!Owner.owned) Owner.owned = [o]; | ||
else Owner.owned.push(o); | ||
} | ||
@@ -46,8 +47,11 @@ return o; | ||
const owner = Owner, | ||
root = fn.length === 0 ? UNOWNED : { | ||
context: null, | ||
owner: detachedOwner === undefined ? owner : detachedOwner, | ||
owned: null, | ||
cleanups: null | ||
}; | ||
root = | ||
fn.length === 0 | ||
? UNOWNED | ||
: { | ||
context: null, | ||
owner: detachedOwner === undefined ? owner : detachedOwner, | ||
owned: null, | ||
cleanups: null | ||
}; | ||
Owner = root; | ||
@@ -65,5 +69,8 @@ let result; | ||
function createSignal(value, options) { | ||
return [() => value, v => { | ||
return value = typeof v === "function" ? v(value) : v; | ||
}]; | ||
return [ | ||
() => value, | ||
v => { | ||
return (value = typeof v === "function" ? v(value) : v); | ||
} | ||
]; | ||
} | ||
@@ -125,3 +132,4 @@ function createComputed(fn, value) { | ||
if (Owner) { | ||
if (!Owner.cleanups) Owner.cleanups = [fn];else Owner.cleanups.push(fn); | ||
if (!Owner.cleanups) Owner.cleanups = [fn]; | ||
else Owner.cleanups.push(fn); | ||
} | ||
@@ -159,5 +167,8 @@ return fn; | ||
if (Owner) { | ||
if (Owner.context === null) Owner.context = { | ||
[ERROR]: [fn] | ||
};else if (!Owner.context[ERROR]) Owner.context[ERROR] = [fn];else Owner.context[ERROR].push(fn); | ||
if (Owner.context === null) | ||
Owner.context = { | ||
[ERROR]: [fn] | ||
}; | ||
else if (!Owner.context[ERROR]) Owner.context[ERROR] = [fn]; | ||
else Owner.context[ERROR].push(fn); | ||
} | ||
@@ -203,3 +214,7 @@ } | ||
function lookup(owner, key) { | ||
return owner ? owner.context && owner.context[key] !== undefined ? owner.context[key] : lookup(owner.owner, key) : undefined; | ||
return owner | ||
? owner.context && owner.context[key] !== undefined | ||
? owner.context[key] | ||
: lookup(owner.owner, key) | ||
: undefined; | ||
} | ||
@@ -250,3 +265,4 @@ function resolveChildren(children) { | ||
} | ||
const handler = typeof observer === "function" ? observer : observer.next && observer.next.bind(observer); | ||
const handler = | ||
typeof observer === "function" ? observer : observer.next && observer.next.bind(observer); | ||
if (!handler) { | ||
@@ -280,3 +296,3 @@ return { | ||
const unsub = producer.subscribe(v => set(() => v)); | ||
onCleanup(() => "unsubscribe" in unsub ? unsub.unsubscribe() : unsub()); | ||
onCleanup(() => ("unsubscribe" in unsub ? unsub.unsubscribe() : unsub())); | ||
} else { | ||
@@ -308,7 +324,9 @@ const clean = producer(set); | ||
function nextHydrateContext() { | ||
return sharedConfig.context ? { | ||
...sharedConfig.context, | ||
id: `${sharedConfig.context.id}${sharedConfig.context.count++}-`, | ||
count: 0 | ||
} : undefined; | ||
return sharedConfig.context | ||
? { | ||
...sharedConfig.context, | ||
id: `${sharedConfig.context.id}${sharedConfig.context.count++}-`, | ||
count: 0 | ||
} | ||
: undefined; | ||
} | ||
@@ -389,3 +407,7 @@ function createUniqueId() { | ||
let c; | ||
return props.when ? typeof (c = props.children) === "function" ? c(props.keyed ? props.when : () => props.when) : c : props.fallback || ""; | ||
return props.when | ||
? typeof (c = props.children) === "function" | ||
? c(props.keyed ? props.when : () => props.when) | ||
: c | ||
: props.fallback || ""; | ||
} | ||
@@ -427,7 +449,10 @@ function Switch(props) { | ||
clean = Owner; | ||
return catchError(() => res = props.children, err => { | ||
error = err; | ||
!sync && ctx.replace("e" + id, displayFallback); | ||
sync = true; | ||
}); | ||
return catchError( | ||
() => (res = props.children), | ||
err => { | ||
error = err; | ||
!sync && ctx.replace("e" + id, displayFallback); | ||
sync = true; | ||
} | ||
); | ||
}); | ||
@@ -462,3 +487,4 @@ if (error) return displayFallback(); | ||
if (resource.ref) { | ||
if (!resource.data && !resource.ref[0].loading && !resource.ref[0].error) resource.ref[1].refetch(); | ||
if (!resource.data && !resource.ref[0].loading && !resource.ref[0].error) | ||
resource.ref[1].refetch(); | ||
return resource.ref; | ||
@@ -470,3 +496,6 @@ } | ||
if (resourceContext && p) resourceContext.push(p); | ||
const resolved = options.ssrLoadFrom !== "initial" && sharedConfig.context.async && "data" in sharedConfig.context.resources[id]; | ||
const resolved = | ||
options.ssrLoadFrom !== "initial" && | ||
sharedConfig.context.async && | ||
"data" in sharedConfig.context.resources[id]; | ||
if (!resolved && read.loading) { | ||
@@ -491,3 +520,3 @@ const ctx = useContext(SuspenseContext); | ||
const ctx = sharedConfig.context; | ||
if (!ctx.async) return read.loading = !!(typeof source === "function" ? source() : source); | ||
if (!ctx.async) return (read.loading = !!(typeof source === "function" ? source() : source)); | ||
if (ctx.resources && id in ctx.resources && "data" in ctx.resources[id]) { | ||
@@ -500,5 +529,7 @@ value = ctx.resources[id].data; | ||
if (resourceContext.length) { | ||
p = Promise.all(resourceContext).then(() => fetcher(source(), { | ||
value | ||
})); | ||
p = Promise.all(resourceContext).then(() => | ||
fetcher(source(), { | ||
value | ||
}) | ||
); | ||
} | ||
@@ -516,16 +547,18 @@ resourceContext = null; | ||
if (ctx.writeResource) ctx.writeResource(id, p, undefined, options.deferStream); | ||
return p.then(res => { | ||
read.loading = false; | ||
read.state = "ready"; | ||
ctx.resources[id].data = res; | ||
p = null; | ||
notifySuspense(contexts); | ||
return res; | ||
}).catch(err => { | ||
read.loading = false; | ||
read.state = "errored"; | ||
read.error = error = castError(err); | ||
p = null; | ||
notifySuspense(contexts); | ||
}); | ||
return p | ||
.then(res => { | ||
read.loading = false; | ||
read.state = "ready"; | ||
ctx.resources[id].data = res; | ||
p = null; | ||
notifySuspense(contexts); | ||
return res; | ||
}) | ||
.catch(err => { | ||
read.loading = false; | ||
read.state = "errored"; | ||
read.error = error = castError(err); | ||
p = null; | ||
notifySuspense(contexts); | ||
}); | ||
} | ||
@@ -538,6 +571,9 @@ ctx.resources[id].data = p; | ||
if (options.ssrLoadFrom !== "initial") load(); | ||
return resource.ref = [read, { | ||
refetch: load, | ||
mutate: v => value = v | ||
}]; | ||
return (resource.ref = [ | ||
read, | ||
{ | ||
refetch: load, | ||
mutate: v => (value = v) | ||
} | ||
]); | ||
} | ||
@@ -549,3 +585,3 @@ function lazy(fn) { | ||
p = fn(); | ||
p.then(mod => p.resolved = mod.default); | ||
p.then(mod => (p.resolved = mod.default)); | ||
if (id) sharedConfig.context.lazy[id] = p; | ||
@@ -559,3 +595,4 @@ } | ||
let ref = sharedConfig.context.lazy[id]; | ||
if (ref) p = ref;else load(id); | ||
if (ref) p = ref; | ||
else load(id); | ||
if (p.resolved) return p.resolved(props); | ||
@@ -572,6 +609,8 @@ const ctx = useContext(SuspenseContext); | ||
if (sharedConfig.context.async) { | ||
sharedConfig.context.block(p.then(() => { | ||
track.loading = false; | ||
notifySuspense(contexts); | ||
})); | ||
sharedConfig.context.block( | ||
p.then(() => { | ||
track.loading = false; | ||
notifySuspense(contexts); | ||
}) | ||
); | ||
} | ||
@@ -604,5 +643,8 @@ return ""; | ||
function useTransition() { | ||
return [() => false, fn => { | ||
fn(); | ||
}]; | ||
return [ | ||
() => false, | ||
fn => { | ||
fn(); | ||
} | ||
]; | ||
} | ||
@@ -617,11 +659,13 @@ function SuspenseList(props) { | ||
const o = createOwner(); | ||
const value = ctx.suspense[id] || (ctx.suspense[id] = { | ||
resources: new Map(), | ||
completed: () => { | ||
const res = runSuspense(); | ||
if (suspenseComplete(value)) { | ||
done(resolveSSRNode(res)); | ||
const value = | ||
ctx.suspense[id] || | ||
(ctx.suspense[id] = { | ||
resources: new Map(), | ||
completed: () => { | ||
const res = runSuspense(); | ||
if (suspenseComplete(value)) { | ||
done(resolveSSRNode(res)); | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
function suspenseError(err) { | ||
@@ -640,8 +684,10 @@ if (!done || !done(undefined, err)) { | ||
cleanNode(o); | ||
return runWithOwner(o, () => createComponent(SuspenseContext.Provider, { | ||
value, | ||
get children() { | ||
return catchError(() => props.children, suspenseError); | ||
} | ||
})); | ||
return runWithOwner(o, () => | ||
createComponent(SuspenseContext.Provider, { | ||
value, | ||
get children() { | ||
return catchError(() => props.children, suspenseError); | ||
} | ||
}) | ||
); | ||
} | ||
@@ -675,2 +721,54 @@ const res = runSuspense(); | ||
export { $DEVCOMP, $PROXY, $TRACK, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, batch, children, createComponent, createComputed, createContext, createDeferred, createEffect, createMemo, createReaction, createRenderEffect, createResource, createRoot, createSelector, createSignal, createUniqueId, enableExternalSource, enableHydration, enableScheduling, equalFn, from, getListener, getOwner, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, requestCallback, resetErrorBoundaries, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition }; | ||
export { | ||
$DEVCOMP, | ||
$PROXY, | ||
$TRACK, | ||
DEV, | ||
ErrorBoundary, | ||
For, | ||
Index, | ||
Match, | ||
Show, | ||
Suspense, | ||
SuspenseList, | ||
Switch, | ||
batch, | ||
children, | ||
createComponent, | ||
createComputed, | ||
createContext, | ||
createDeferred, | ||
createEffect, | ||
createMemo, | ||
createReaction, | ||
createRenderEffect, | ||
createResource, | ||
createRoot, | ||
createSelector, | ||
createSignal, | ||
createUniqueId, | ||
enableExternalSource, | ||
enableHydration, | ||
enableScheduling, | ||
equalFn, | ||
from, | ||
getListener, | ||
getOwner, | ||
lazy, | ||
mapArray, | ||
mergeProps, | ||
observable, | ||
on, | ||
onCleanup, | ||
onError, | ||
onMount, | ||
requestCallback, | ||
resetErrorBoundaries, | ||
runWithOwner, | ||
sharedConfig, | ||
splitProps, | ||
startTransition, | ||
untrack, | ||
useContext, | ||
useTransition | ||
}; |
@@ -55,5 +55,7 @@ let taskIdCounter = 1, | ||
while (m <= n) { | ||
const k = n + m >> 1; | ||
const k = (n + m) >> 1; | ||
const cmp = task.expirationTime - taskQueue[k].expirationTime; | ||
if (cmp > 0) m = k + 1;else if (cmp < 0) n = k - 1;else return k; | ||
if (cmp > 0) m = k + 1; | ||
else if (cmp < 0) n = k - 1; | ||
else return k; | ||
} | ||
@@ -159,3 +161,3 @@ return m; | ||
let ExecCount = 0; | ||
const [transPending, setTransPending] = /*@__PURE__*/createSignal(false); | ||
const [transPending, setTransPending] = /*@__PURE__*/ createSignal(false); | ||
function createRoot(fn, detachedOwner) { | ||
@@ -165,8 +167,10 @@ const listener = Listener, | ||
unowned = fn.length === 0, | ||
root = unowned ? UNOWNED : { | ||
owned: null, | ||
cleanups: null, | ||
context: null, | ||
owner: detachedOwner === undefined ? owner : detachedOwner | ||
}, | ||
root = unowned | ||
? UNOWNED | ||
: { | ||
owned: null, | ||
cleanups: null, | ||
context: null, | ||
owner: detachedOwner === undefined ? owner : detachedOwner | ||
}, | ||
updateFn = unowned ? fn : () => fn(() => untrack(() => cleanNode(root))); | ||
@@ -192,3 +196,4 @@ Owner = root; | ||
if (typeof value === "function") { | ||
if (Transition && Transition.running && Transition.sources.has(s)) value = value(s.tValue);else value = value(s.value); | ||
if (Transition && Transition.running && Transition.sources.has(s)) value = value(s.tValue); | ||
else value = value(s.value); | ||
} | ||
@@ -201,7 +206,9 @@ return writeSignal(s, value); | ||
const c = createComputation(fn, value, true, STALE); | ||
if (Scheduler && Transition && Transition.running) Updates.push(c);else updateComputation(c); | ||
if (Scheduler && Transition && Transition.running) Updates.push(c); | ||
else updateComputation(c); | ||
} | ||
function createRenderEffect(fn, value, options) { | ||
const c = createComputation(fn, value, false, STALE); | ||
if (Scheduler && Transition && Transition.running) Updates.push(c);else updateComputation(c); | ||
if (Scheduler && Transition && Transition.running) Updates.push(c); | ||
else updateComputation(c); | ||
} | ||
@@ -218,6 +225,11 @@ function createEffect(fn, value, options) { | ||
let fn; | ||
const c = createComputation(() => { | ||
fn ? fn() : untrack(onInvalidate); | ||
fn = undefined; | ||
}, undefined, false, 0), | ||
const c = createComputation( | ||
() => { | ||
fn ? fn() : untrack(onInvalidate); | ||
fn = undefined; | ||
}, | ||
undefined, | ||
false, | ||
0 | ||
), | ||
s = SuspenseContext && lookup(Owner, SuspenseContext.id); | ||
@@ -247,3 +259,3 @@ if (s) c.suspense = s; | ||
let options; | ||
if (arguments.length === 2 && typeof pFetcher === "object" || arguments.length === 1) { | ||
if ((arguments.length === 2 && typeof pFetcher === "object") || arguments.length === 1) { | ||
source = true; | ||
@@ -262,3 +274,3 @@ fetcher = pSource; | ||
scheduled = false, | ||
resolved = ("initialValue" in options), | ||
resolved = "initialValue" in options, | ||
dynamic = typeof source === "function" && createMemo(source); | ||
@@ -275,3 +287,4 @@ const contexts = new Set(), | ||
let v; | ||
if (options.ssrLoadFrom === "initial") initP = options.initialValue;else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v[0]; | ||
if (options.ssrLoadFrom === "initial") initP = options.initialValue; | ||
else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v[0]; | ||
} | ||
@@ -282,5 +295,8 @@ function loadEnd(p, v, error, key) { | ||
key !== undefined && (resolved = true); | ||
if ((p === initP || v === initP) && options.onHydrated) queueMicrotask(() => options.onHydrated(key, { | ||
value: v | ||
})); | ||
if ((p === initP || v === initP) && options.onHydrated) | ||
queueMicrotask(() => | ||
options.onHydrated(key, { | ||
value: v | ||
}) | ||
); | ||
initP = NO_INIT; | ||
@@ -316,3 +332,4 @@ if (Transition && p && loadedUnderTransition) { | ||
if (pr) { | ||
if (c.resolved && Transition && loadedUnderTransition) Transition.promises.add(pr);else if (!contexts.has(c)) { | ||
if (c.resolved && Transition && loadedUnderTransition) Transition.promises.add(pr); | ||
else if (!contexts.has(c)) { | ||
c.increment(); | ||
@@ -336,6 +353,11 @@ contexts.add(c); | ||
if (Transition && pr) Transition.promises.delete(pr); | ||
const p = initP !== NO_INIT ? initP : untrack(() => fetcher(lookup, { | ||
value: value(), | ||
refetching | ||
})); | ||
const p = | ||
initP !== NO_INIT | ||
? initP | ||
: untrack(() => | ||
fetcher(lookup, { | ||
value: value(), | ||
refetching | ||
}) | ||
); | ||
if (typeof p !== "object" || !(p && "then" in p)) { | ||
@@ -347,3 +369,3 @@ loadEnd(pr, p, undefined, lookup); | ||
scheduled = true; | ||
queueMicrotask(() => scheduled = false); | ||
queueMicrotask(() => (scheduled = false)); | ||
runUpdates(() => { | ||
@@ -353,3 +375,6 @@ setState(resolved ? "refreshing" : "pending"); | ||
}, false); | ||
return p.then(v => loadEnd(p, v, undefined, lookup), e => loadEnd(p, undefined, castError(e), lookup)); | ||
return p.then( | ||
v => loadEnd(p, v, undefined, lookup), | ||
e => loadEnd(p, undefined, castError(e), lookup) | ||
); | ||
} | ||
@@ -378,7 +403,11 @@ Object.defineProperties(read, { | ||
}); | ||
if (dynamic) createComputed(() => load(false));else load(false); | ||
return [read, { | ||
refetch: load, | ||
mutate: setValue | ||
}]; | ||
if (dynamic) createComputed(() => load(false)); | ||
else load(false); | ||
return [ | ||
read, | ||
{ | ||
refetch: load, | ||
mutate: setValue | ||
} | ||
]; | ||
} | ||
@@ -388,8 +417,18 @@ function createDeferred(source, options) { | ||
timeout = options ? options.timeoutMs : undefined; | ||
const node = createComputation(() => { | ||
if (!t || !t.fn) t = requestCallback(() => setDeferred(() => node.value), timeout !== undefined ? { | ||
timeout | ||
} : undefined); | ||
return source(); | ||
}, undefined, true); | ||
const node = createComputation( | ||
() => { | ||
if (!t || !t.fn) | ||
t = requestCallback( | ||
() => setDeferred(() => node.value), | ||
timeout !== undefined | ||
? { | ||
timeout | ||
} | ||
: undefined | ||
); | ||
return source(); | ||
}, | ||
undefined, | ||
true | ||
); | ||
const [deferred, setDeferred] = createSignal(node.value, options); | ||
@@ -402,12 +441,19 @@ updateComputation(node); | ||
const subs = new Map(); | ||
const node = createComputation(p => { | ||
const v = source(); | ||
for (const [key, val] of subs.entries()) if (fn(key, v) !== fn(key, p)) { | ||
for (const c of val.values()) { | ||
c.state = STALE; | ||
if (c.pure) Updates.push(c);else Effects.push(c); | ||
} | ||
} | ||
return v; | ||
}, undefined, true, STALE); | ||
const node = createComputation( | ||
p => { | ||
const v = source(); | ||
for (const [key, val] of subs.entries()) | ||
if (fn(key, v) !== fn(key, p)) { | ||
for (const c of val.values()) { | ||
c.state = STALE; | ||
if (c.pure) Updates.push(c); | ||
else Effects.push(c); | ||
} | ||
} | ||
return v; | ||
}, | ||
undefined, | ||
true, | ||
STALE | ||
); | ||
updateComputation(node); | ||
@@ -418,3 +464,4 @@ return key => { | ||
let l; | ||
if (l = subs.get(key)) l.add(listener);else subs.set(key, l = new Set([listener])); | ||
if ((l = subs.get(key))) l.add(listener); | ||
else subs.set(key, (l = new Set([listener]))); | ||
onCleanup(() => { | ||
@@ -425,3 +472,6 @@ l.delete(listener); | ||
} | ||
return fn(key, Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value); | ||
return fn( | ||
key, | ||
Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value | ||
); | ||
}; | ||
@@ -465,3 +515,5 @@ } | ||
function onCleanup(fn) { | ||
if (Owner === null) ;else if (Owner.cleanups === null) Owner.cleanups = [fn];else Owner.cleanups.push(fn); | ||
if (Owner === null); | ||
else if (Owner.cleanups === null) Owner.cleanups = [fn]; | ||
else Owner.cleanups.push(fn); | ||
return fn; | ||
@@ -486,5 +538,9 @@ } | ||
ERROR || (ERROR = Symbol("error")); | ||
if (Owner === null) ;else if (Owner.context === null) Owner.context = { | ||
[ERROR]: [fn] | ||
};else if (!Owner.context[ERROR]) Owner.context[ERROR] = [fn];else Owner.context[ERROR].push(fn); | ||
if (Owner === null); | ||
else if (Owner.context === null) | ||
Owner.context = { | ||
[ERROR]: [fn] | ||
}; | ||
else if (!Owner.context[ERROR]) Owner.context[ERROR] = [fn]; | ||
else Owner.context[ERROR].push(fn); | ||
} | ||
@@ -526,11 +582,13 @@ function getListener() { | ||
if (Scheduler || SuspenseContext) { | ||
t = Transition || (Transition = { | ||
sources: new Set(), | ||
effects: [], | ||
promises: new Set(), | ||
disposed: new Set(), | ||
queue: new Set(), | ||
running: true | ||
}); | ||
t.done || (t.done = new Promise(res => t.resolve = res)); | ||
t = | ||
Transition || | ||
(Transition = { | ||
sources: new Set(), | ||
effects: [], | ||
promises: new Set(), | ||
disposed: new Set(), | ||
queue: new Set(), | ||
running: true | ||
}); | ||
t.done || (t.done = new Promise(res => (t.resolve = res))); | ||
t.running = true; | ||
@@ -596,3 +654,4 @@ } | ||
if (this.sources && (runningTransition ? this.tState : this.state)) { | ||
if ((runningTransition ? this.tState : this.state) === STALE) updateComputation(this);else { | ||
if ((runningTransition ? this.tState : this.state) === STALE) updateComputation(this); | ||
else { | ||
const updates = Updates; | ||
@@ -625,7 +684,8 @@ Updates = null; | ||
function writeSignal(node, value, isComp) { | ||
let current = Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value; | ||
let current = | ||
Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value; | ||
if (!node.comparator || !node.comparator(current, value)) { | ||
if (Transition) { | ||
const TransitionRunning = Transition.running; | ||
if (TransitionRunning || !isComp && Transition.sources.has(node)) { | ||
if (TransitionRunning || (!isComp && Transition.sources.has(node))) { | ||
Transition.sources.add(node); | ||
@@ -643,10 +703,12 @@ node.tValue = value; | ||
if (TransitionRunning ? !o.tState : !o.state) { | ||
if (o.pure) Updates.push(o);else Effects.push(o); | ||
if (o.pure) Updates.push(o); | ||
else Effects.push(o); | ||
if (o.observers) markDownstream(o); | ||
} | ||
if (!TransitionRunning) o.state = STALE;else o.tState = STALE; | ||
if (!TransitionRunning) o.state = STALE; | ||
else o.tState = STALE; | ||
} | ||
if (Updates.length > 10e5) { | ||
Updates = []; | ||
if (false) ; | ||
if (false); | ||
throw new Error(); | ||
@@ -666,3 +728,7 @@ } | ||
Listener = Owner = node; | ||
runComputation(node, Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value, time); | ||
runComputation( | ||
node, | ||
Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value, | ||
time | ||
); | ||
if (Transition && !Transition.running && Transition.sources.has(node)) { | ||
@@ -728,7 +794,10 @@ queueMicrotask(() => { | ||
} | ||
if (Owner === null) ;else if (Owner !== UNOWNED) { | ||
if (Owner === null); | ||
else if (Owner !== UNOWNED) { | ||
if (Transition && Transition.running && Owner.pure) { | ||
if (!Owner.tOwned) Owner.tOwned = [c];else Owner.tOwned.push(c); | ||
if (!Owner.tOwned) Owner.tOwned = [c]; | ||
else Owner.tOwned.push(c); | ||
} else { | ||
if (!Owner.owned) Owner.owned = [c];else Owner.owned.push(c); | ||
if (!Owner.owned) Owner.owned = [c]; | ||
else Owner.owned.push(c); | ||
} | ||
@@ -784,3 +853,4 @@ } | ||
if (!init) Updates = []; | ||
if (Effects) wait = true;else Effects = []; | ||
if (Effects) wait = true; | ||
else Effects = []; | ||
ExecCount++; | ||
@@ -799,3 +869,4 @@ try { | ||
if (Updates) { | ||
if (Scheduler && Transition && Transition.running) scheduleQueue(Updates);else runQueue(Updates); | ||
if (Scheduler && Transition && Transition.running) scheduleQueue(Updates); | ||
else runQueue(Updates); | ||
Updates = null; | ||
@@ -868,3 +939,4 @@ } | ||
const e = queue[i]; | ||
if (!e.user) runTop(e);else queue[userLength++] = e; | ||
if (!e.user) runTop(e); | ||
else queue[userLength++] = e; | ||
} | ||
@@ -887,3 +959,4 @@ if (sharedConfig.context) { | ||
const runningTransition = Transition && Transition.running; | ||
if (runningTransition) node.tState = 0;else node.state = 0; | ||
if (runningTransition) node.tState = 0; | ||
else node.state = 0; | ||
for (let i = 0; i < node.sources.length; i += 1) { | ||
@@ -894,3 +967,4 @@ const source = node.sources[i]; | ||
if (state === STALE) { | ||
if (source !== ignore && (!source.updatedAt || source.updatedAt < ExecCount)) runTop(source); | ||
if (source !== ignore && (!source.updatedAt || source.updatedAt < ExecCount)) | ||
runTop(source); | ||
} else if (state === PENDING) lookUpstream(source, ignore); | ||
@@ -905,4 +979,6 @@ } | ||
if (runningTransition ? !o.tState : !o.state) { | ||
if (runningTransition) o.tState = PENDING;else o.state = PENDING; | ||
if (o.pure) Updates.push(o);else Effects.push(o); | ||
if (runningTransition) o.tState = PENDING; | ||
else o.state = PENDING; | ||
if (o.pure) Updates.push(o); | ||
else Effects.push(o); | ||
o.observers && markDownstream(o); | ||
@@ -944,3 +1020,4 @@ } | ||
} | ||
if (Transition && Transition.running) node.tState = 0;else node.state = 0; | ||
if (Transition && Transition.running) node.tState = 0; | ||
else node.state = 0; | ||
node.context = null; | ||
@@ -967,3 +1044,3 @@ } | ||
} catch (e) { | ||
handleError(e, owner && owner.owner || null); | ||
handleError(e, (owner && owner.owner) || null); | ||
} | ||
@@ -975,11 +1052,17 @@ } | ||
if (!fns) throw error; | ||
if (Effects) Effects.push({ | ||
fn() { | ||
runErrors(error, fns, owner); | ||
}, | ||
state: STALE | ||
});else runErrors(error, fns, owner); | ||
if (Effects) | ||
Effects.push({ | ||
fn() { | ||
runErrors(error, fns, owner); | ||
}, | ||
state: STALE | ||
}); | ||
else runErrors(error, fns, owner); | ||
} | ||
function lookup(owner, key) { | ||
return owner ? owner.context && owner.context[key] !== undefined ? owner.context[key] : lookup(owner.owner, key) : undefined; | ||
return owner | ||
? owner.context && owner.context[key] !== undefined | ||
? owner.context[key] | ||
: lookup(owner.owner, key) | ||
: undefined; | ||
} | ||
@@ -1001,8 +1084,12 @@ function resolveChildren(children) { | ||
let res; | ||
createRenderEffect(() => res = untrack(() => { | ||
Owner.context = { | ||
[id]: props.value | ||
}; | ||
return children(() => props.children); | ||
}), undefined); | ||
createRenderEffect( | ||
() => | ||
(res = untrack(() => { | ||
Owner.context = { | ||
[id]: props.value | ||
}; | ||
return children(() => props.children); | ||
})), | ||
undefined | ||
); | ||
return res; | ||
@@ -1018,3 +1105,4 @@ }; | ||
} | ||
const handler = typeof observer === "function" ? observer : observer.next && observer.next.bind(observer); | ||
const handler = | ||
typeof observer === "function" ? observer : observer.next && observer.next.bind(observer); | ||
if (!handler) { | ||
@@ -1050,3 +1138,3 @@ return { | ||
const unsub = producer.subscribe(v => set(() => v)); | ||
onCleanup(() => "unsubscribe" in unsub ? unsub.unsubscribe() : unsub()); | ||
onCleanup(() => ("unsubscribe" in unsub ? unsub.unsubscribe() : unsub())); | ||
} else { | ||
@@ -1103,4 +1191,3 @@ const clean = producer(set); | ||
} | ||
} | ||
else if (len === 0) { | ||
} else if (len === 0) { | ||
mapped = new Array(newLen); | ||
@@ -1116,4 +1203,12 @@ for (j = 0; j < newLen; j++) { | ||
indexes && (tempIndexes = new Array(newLen)); | ||
for (start = 0, end = Math.min(len, newLen); start < end && items[start] === newItems[start]; start++); | ||
for (end = len - 1, newEnd = newLen - 1; end >= start && newEnd >= start && items[end] === newItems[newEnd]; end--, newEnd--) { | ||
for ( | ||
start = 0, end = Math.min(len, newLen); | ||
start < end && items[start] === newItems[start]; | ||
start++ | ||
); | ||
for ( | ||
end = len - 1, newEnd = newLen - 1; | ||
end >= start && newEnd >= start && items[end] === newItems[newEnd]; | ||
end--, newEnd-- | ||
) { | ||
temp[newEnd] = mapped[end]; | ||
@@ -1152,3 +1247,3 @@ tempdisposers[newEnd] = disposers[end]; | ||
} | ||
mapped = mapped.slice(0, len = newLen); | ||
mapped = mapped.slice(0, (len = newLen)); | ||
items = newItems.slice(0); | ||
@@ -1219,3 +1314,3 @@ } | ||
items = newItems.slice(0); | ||
return mapped = mapped.slice(0, len); | ||
return (mapped = mapped.slice(0, len)); | ||
}); | ||
@@ -1289,25 +1384,29 @@ function mapper(disposer) { | ||
const s = sources[i]; | ||
proxy = proxy || !!s && $PROXY in s; | ||
sources[i] = typeof s === "function" ? (proxy = true, createMemo(s)) : s; | ||
proxy = proxy || (!!s && $PROXY in s); | ||
sources[i] = typeof s === "function" ? ((proxy = true), createMemo(s)) : s; | ||
} | ||
if (proxy) { | ||
return new Proxy({ | ||
get(property) { | ||
for (let i = sources.length - 1; i >= 0; i--) { | ||
const v = resolveSource(sources[i])[property]; | ||
if (v !== undefined) return v; | ||
return new Proxy( | ||
{ | ||
get(property) { | ||
for (let i = sources.length - 1; i >= 0; i--) { | ||
const v = resolveSource(sources[i])[property]; | ||
if (v !== undefined) return v; | ||
} | ||
}, | ||
has(property) { | ||
for (let i = sources.length - 1; i >= 0; i--) { | ||
if (property in resolveSource(sources[i])) return true; | ||
} | ||
return false; | ||
}, | ||
keys() { | ||
const keys = []; | ||
for (let i = 0; i < sources.length; i++) | ||
keys.push(...Object.keys(resolveSource(sources[i]))); | ||
return [...new Set(keys)]; | ||
} | ||
}, | ||
has(property) { | ||
for (let i = sources.length - 1; i >= 0; i--) { | ||
if (property in resolveSource(sources[i])) return true; | ||
} | ||
return false; | ||
}, | ||
keys() { | ||
const keys = []; | ||
for (let i = 0; i < sources.length; i++) keys.push(...Object.keys(resolveSource(sources[i]))); | ||
return [...new Set(keys)]; | ||
} | ||
}, propTraps); | ||
propTraps | ||
); | ||
} | ||
@@ -1331,3 +1430,3 @@ const target = {}; | ||
configurable: true, | ||
get: resolveSources.bind(sourcesMap[key] = [desc.get.bind(source)]) | ||
get: resolveSources.bind((sourcesMap[key] = [desc.get.bind(source)])) | ||
}); | ||
@@ -1356,25 +1455,33 @@ } else { | ||
const res = keys.map(k => { | ||
return new Proxy({ | ||
get(property) { | ||
return k.includes(property) ? props[property] : undefined; | ||
return new Proxy( | ||
{ | ||
get(property) { | ||
return k.includes(property) ? props[property] : undefined; | ||
}, | ||
has(property) { | ||
return k.includes(property) && property in props; | ||
}, | ||
keys() { | ||
return k.filter(property => property in props); | ||
} | ||
}, | ||
has(property) { | ||
return k.includes(property) && property in props; | ||
propTraps | ||
); | ||
}); | ||
res.push( | ||
new Proxy( | ||
{ | ||
get(property) { | ||
return blocked.has(property) ? undefined : props[property]; | ||
}, | ||
has(property) { | ||
return blocked.has(property) ? false : property in props; | ||
}, | ||
keys() { | ||
return Object.keys(props).filter(k => !blocked.has(k)); | ||
} | ||
}, | ||
keys() { | ||
return k.filter(property => property in props); | ||
} | ||
}, propTraps); | ||
}); | ||
res.push(new Proxy({ | ||
get(property) { | ||
return blocked.has(property) ? undefined : props[property]; | ||
}, | ||
has(property) { | ||
return blocked.has(property) ? false : property in props; | ||
}, | ||
keys() { | ||
return Object.keys(props).filter(k => !blocked.has(k)); | ||
} | ||
}, propTraps)); | ||
propTraps | ||
) | ||
); | ||
return res; | ||
@@ -1386,3 +1493,4 @@ } | ||
const desc = Object.getOwnPropertyDescriptor(props, propName); | ||
const isDefaultDesc = !desc.get && !desc.set && desc.enumerable && desc.writable && desc.configurable; | ||
const isDefaultDesc = | ||
!desc.get && !desc.set && desc.enumerable && desc.writable && desc.configurable; | ||
let blocked = false; | ||
@@ -1393,3 +1501,5 @@ let objectIndex = 0; | ||
blocked = true; | ||
isDefaultDesc ? objects[objectIndex][propName] = desc.value : Object.defineProperty(objects[objectIndex], propName, desc); | ||
isDefaultDesc | ||
? (objects[objectIndex][propName] = desc.value) | ||
: Object.defineProperty(objects[objectIndex], propName, desc); | ||
} | ||
@@ -1399,3 +1509,5 @@ ++objectIndex; | ||
if (!blocked) { | ||
isDefaultDesc ? otherObject[propName] = desc.value : Object.defineProperty(otherObject, propName, desc); | ||
isDefaultDesc | ||
? (otherObject[propName] = desc.value) | ||
: Object.defineProperty(otherObject, propName, desc); | ||
} | ||
@@ -1426,13 +1538,17 @@ } | ||
let Comp; | ||
return createMemo(() => (Comp = comp()) && untrack(() => { | ||
if (false) ; | ||
if (!ctx) return Comp(props); | ||
const c = sharedConfig.context; | ||
setHydrateContext(ctx); | ||
const r = Comp(props); | ||
setHydrateContext(c); | ||
return r; | ||
})); | ||
return createMemo( | ||
() => | ||
(Comp = comp()) && | ||
untrack(() => { | ||
if (false); | ||
if (!ctx) return Comp(props); | ||
const c = sharedConfig.context; | ||
setHydrateContext(ctx); | ||
const r = Comp(props); | ||
setHydrateContext(c); | ||
return r; | ||
}) | ||
); | ||
}; | ||
wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p); | ||
wrap.preload = () => p || ((p = fn()).then(mod => (comp = () => mod.default)), p); | ||
return wrap; | ||
@@ -1462,45 +1578,74 @@ } | ||
const condition = createMemo(() => props.when, undefined, { | ||
equals: (a, b) => keyed ? a === b : !a === !b | ||
equals: (a, b) => (keyed ? a === b : !a === !b) | ||
}); | ||
return createMemo(() => { | ||
const c = condition(); | ||
if (c) { | ||
const child = props.children; | ||
const fn = typeof child === "function" && child.length > 0; | ||
return fn ? untrack(() => child(keyed ? c : () => { | ||
if (!untrack(condition)) throw narrowedError("Show"); | ||
return props.when; | ||
})) : child; | ||
} | ||
return props.fallback; | ||
}, undefined, undefined); | ||
return createMemo( | ||
() => { | ||
const c = condition(); | ||
if (c) { | ||
const child = props.children; | ||
const fn = typeof child === "function" && child.length > 0; | ||
return fn | ||
? untrack(() => | ||
child( | ||
keyed | ||
? c | ||
: () => { | ||
if (!untrack(condition)) throw narrowedError("Show"); | ||
return props.when; | ||
} | ||
) | ||
) | ||
: child; | ||
} | ||
return props.fallback; | ||
}, | ||
undefined, | ||
undefined | ||
); | ||
} | ||
function Switch(props) { | ||
let keyed = false; | ||
const equals = (a, b) => a[0] === b[0] && (keyed ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]; | ||
const equals = (a, b) => | ||
a[0] === b[0] && (keyed ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]; | ||
const conditions = children(() => props.children), | ||
evalConditions = createMemo(() => { | ||
let conds = conditions(); | ||
if (!Array.isArray(conds)) conds = [conds]; | ||
for (let i = 0; i < conds.length; i++) { | ||
const c = conds[i].when; | ||
if (c) { | ||
keyed = !!conds[i].keyed; | ||
return [i, c, conds[i]]; | ||
evalConditions = createMemo( | ||
() => { | ||
let conds = conditions(); | ||
if (!Array.isArray(conds)) conds = [conds]; | ||
for (let i = 0; i < conds.length; i++) { | ||
const c = conds[i].when; | ||
if (c) { | ||
keyed = !!conds[i].keyed; | ||
return [i, c, conds[i]]; | ||
} | ||
} | ||
return [-1]; | ||
}, | ||
undefined, | ||
{ | ||
equals | ||
} | ||
return [-1]; | ||
}, undefined, { | ||
equals | ||
}); | ||
return createMemo(() => { | ||
const [index, when, cond] = evalConditions(); | ||
if (index < 0) return props.fallback; | ||
const c = cond.children; | ||
const fn = typeof c === "function" && c.length > 0; | ||
return fn ? untrack(() => c(keyed ? when : () => { | ||
if (untrack(evalConditions)[0] !== index) throw narrowedError("Match"); | ||
return cond.when; | ||
})) : c; | ||
}, undefined, undefined); | ||
); | ||
return createMemo( | ||
() => { | ||
const [index, when, cond] = evalConditions(); | ||
if (index < 0) return props.fallback; | ||
const c = cond.children; | ||
const fn = typeof c === "function" && c.length > 0; | ||
return fn | ||
? untrack(() => | ||
c( | ||
keyed | ||
? when | ||
: () => { | ||
if (untrack(evalConditions)[0] !== index) throw narrowedError("Match"); | ||
return cond.when; | ||
} | ||
) | ||
) | ||
: c; | ||
}, | ||
undefined, | ||
undefined | ||
); | ||
} | ||
@@ -1517,3 +1662,8 @@ function Match(props) { | ||
let v; | ||
if (sharedConfig.context && sharedConfig.load && (v = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count))) err = v[0]; | ||
if ( | ||
sharedConfig.context && | ||
sharedConfig.load && | ||
(v = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count)) | ||
) | ||
err = v[0]; | ||
const [errored, setErrored] = createSignal(err, undefined); | ||
@@ -1523,13 +1673,18 @@ Errors || (Errors = new Set()); | ||
onCleanup(() => Errors.delete(setErrored)); | ||
return createMemo(() => { | ||
let e; | ||
if (e = errored()) { | ||
const f = props.fallback; | ||
return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored())) : f; | ||
} | ||
return catchError(() => props.children, setErrored); | ||
}, undefined, undefined); | ||
return createMemo( | ||
() => { | ||
let e; | ||
if ((e = errored())) { | ||
const f = props.fallback; | ||
return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored())) : f; | ||
} | ||
return catchError(() => props.children, setErrored); | ||
}, | ||
undefined, | ||
undefined | ||
); | ||
} | ||
const suspenseListEquals = (a, b) => a.showContent === b.showContent && a.showFallback === b.showFallback; | ||
const suspenseListEquals = (a, b) => | ||
a.showContent === b.showContent && a.showFallback === b.showFallback; | ||
const SuspenseListContext = createContext(); | ||
@@ -1546,47 +1701,47 @@ function SuspenseList(props) { | ||
} | ||
const resolved = createMemo(prev => { | ||
const reveal = props.revealOrder, | ||
tail = props.tail, | ||
{ | ||
showContent = true, | ||
showFallback = true | ||
} = show ? show() : {}, | ||
reg = registry(), | ||
reverse = reveal === "backwards"; | ||
if (reveal === "together") { | ||
const all = reg.every(inFallback => !inFallback()); | ||
const res = reg.map(() => ({ | ||
showContent: all && showContent, | ||
showFallback | ||
})); | ||
res.inFallback = !all; | ||
return res; | ||
} | ||
let stop = false; | ||
let inFallback = prev.inFallback; | ||
const res = []; | ||
for (let i = 0, len = reg.length; i < len; i++) { | ||
const n = reverse ? len - i - 1 : i, | ||
s = reg[n](); | ||
if (!stop && !s) { | ||
res[n] = { | ||
showContent, | ||
const resolved = createMemo( | ||
prev => { | ||
const reveal = props.revealOrder, | ||
tail = props.tail, | ||
{ showContent = true, showFallback = true } = show ? show() : {}, | ||
reg = registry(), | ||
reverse = reveal === "backwards"; | ||
if (reveal === "together") { | ||
const all = reg.every(inFallback => !inFallback()); | ||
const res = reg.map(() => ({ | ||
showContent: all && showContent, | ||
showFallback | ||
}; | ||
} else { | ||
const next = !stop; | ||
if (next) inFallback = true; | ||
res[n] = { | ||
showContent: next, | ||
showFallback: !tail || next && tail === "collapsed" ? showFallback : false | ||
}; | ||
stop = true; | ||
})); | ||
res.inFallback = !all; | ||
return res; | ||
} | ||
let stop = false; | ||
let inFallback = prev.inFallback; | ||
const res = []; | ||
for (let i = 0, len = reg.length; i < len; i++) { | ||
const n = reverse ? len - i - 1 : i, | ||
s = reg[n](); | ||
if (!stop && !s) { | ||
res[n] = { | ||
showContent, | ||
showFallback | ||
}; | ||
} else { | ||
const next = !stop; | ||
if (next) inFallback = true; | ||
res[n] = { | ||
showContent: next, | ||
showFallback: !tail || (next && tail === "collapsed") ? showFallback : false | ||
}; | ||
stop = true; | ||
} | ||
} | ||
if (!stop) inFallback = false; | ||
res.inFallback = inFallback; | ||
return res; | ||
}, | ||
{ | ||
inFallback: false | ||
} | ||
if (!stop) inFallback = false; | ||
res.inFallback = inFallback; | ||
return res; | ||
}, { | ||
inFallback: false | ||
}); | ||
); | ||
setWrapper(() => resolved); | ||
@@ -1665,3 +1820,3 @@ return createComponent(SuspenseListContext.Provider, { | ||
flicker(); | ||
return flicker = undefined; | ||
return (flicker = undefined); | ||
} | ||
@@ -1672,7 +1827,4 @@ if (ctx && p === "$$f") setHydrateContext(); | ||
const inFallback = store.inFallback(), | ||
{ | ||
showContent = true, | ||
showFallback = true | ||
} = show ? show() : {}; | ||
if ((!inFallback || p && p !== "$$f") && showContent) { | ||
{ showContent = true, showFallback = true } = show ? show() : {}; | ||
if ((!inFallback || (p && p !== "$$f")) && showContent) { | ||
store.resolved = true; | ||
@@ -1705,2 +1857,57 @@ dispose && dispose(); | ||
export { $DEVCOMP, $PROXY, $TRACK, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, batch, cancelCallback, catchError, children, createComponent, createComputed, createContext, createDeferred, createEffect, createMemo, createReaction, createRenderEffect, createResource, createRoot, createSelector, createSignal, createUniqueId, enableExternalSource, enableHydration, enableScheduling, equalFn, from, getListener, getOwner, indexArray, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, requestCallback, resetErrorBoundaries, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition }; | ||
export { | ||
$DEVCOMP, | ||
$PROXY, | ||
$TRACK, | ||
DEV, | ||
ErrorBoundary, | ||
For, | ||
Index, | ||
Match, | ||
Show, | ||
Suspense, | ||
SuspenseList, | ||
Switch, | ||
batch, | ||
cancelCallback, | ||
catchError, | ||
children, | ||
createComponent, | ||
createComputed, | ||
createContext, | ||
createDeferred, | ||
createEffect, | ||
createMemo, | ||
createReaction, | ||
createRenderEffect, | ||
createResource, | ||
createRoot, | ||
createSelector, | ||
createSignal, | ||
createUniqueId, | ||
enableExternalSource, | ||
enableHydration, | ||
enableScheduling, | ||
equalFn, | ||
from, | ||
getListener, | ||
getOwner, | ||
indexArray, | ||
lazy, | ||
mapArray, | ||
mergeProps, | ||
observable, | ||
on, | ||
onCleanup, | ||
onError, | ||
onMount, | ||
requestCallback, | ||
resetErrorBoundaries, | ||
runWithOwner, | ||
sharedConfig, | ||
splitProps, | ||
startTransition, | ||
untrack, | ||
useContext, | ||
useTransition | ||
}; |
@@ -1,2 +0,9 @@ | ||
import { spread, assign, insert, createComponent, dynamicProperty, SVGElements } from 'solid-js/web'; | ||
import { | ||
spread, | ||
assign, | ||
insert, | ||
createComponent, | ||
dynamicProperty, | ||
SVGElements | ||
} from "solid-js/web"; | ||
@@ -20,5 +27,12 @@ const $ELEMENT = Symbol("hyper-element"); | ||
const type = typeof l; | ||
if (l == null) ;else if ("string" === type) { | ||
if (!e) parseClass(l);else e.appendChild(document.createTextNode(l)); | ||
} else if ("number" === type || "boolean" === type || l instanceof Date || l instanceof RegExp) { | ||
if (l == null); | ||
else if ("string" === type) { | ||
if (!e) parseClass(l); | ||
else e.appendChild(document.createTextNode(l)); | ||
} else if ( | ||
"number" === type || | ||
"boolean" === type || | ||
l instanceof Date || | ||
l instanceof RegExp | ||
) { | ||
e.appendChild(document.createTextNode(l.toString())); | ||
@@ -38,3 +52,5 @@ } else if (Array.isArray(l)) { | ||
} | ||
dynamic ? r.spread(e, l, e instanceof SVGElement, !!args.length) : r.assign(e, l, e instanceof SVGElement, !!args.length); | ||
dynamic | ||
? r.spread(e, l, e instanceof SVGElement, !!args.length) | ||
: r.assign(e, l, e instanceof SVGElement, !!args.length); | ||
} else if ("function" === type) { | ||
@@ -44,3 +60,7 @@ if (!e) { | ||
next = args[0]; | ||
if (next == null || typeof next === "object" && !Array.isArray(next) && !(next instanceof Element)) props = args.shift(); | ||
if ( | ||
next == null || | ||
(typeof next === "object" && !Array.isArray(next) && !(next instanceof Element)) | ||
) | ||
props = args.shift(); | ||
props || (props = {}); | ||
@@ -61,3 +81,4 @@ if (args.length) { | ||
r.dynamicProperty(props, k); | ||
} else if (typeof d[k].value === "function" && !d[k].value.length) r.dynamicProperty(props, k); | ||
} else if (typeof d[k].value === "function" && !d[k].value.length) | ||
r.dynamicProperty(props, k); | ||
} | ||
@@ -79,3 +100,8 @@ e = r.createComponent(l, props); | ||
if (!v) continue; | ||
if (!e) e = r.SVGElements.has(v) ? document.createElementNS("http://www.w3.org/2000/svg", v) : document.createElement(v);else if (v[0] === ".") e.classList.add(s);else if (v[0] === "#") e.setAttribute("id", s); | ||
if (!e) | ||
e = r.SVGElements.has(v) | ||
? document.createElementNS("http://www.w3.org/2000/svg", v) | ||
: document.createElement(v); | ||
else if (v[0] === ".") e.classList.add(s); | ||
else if (v[0] === "#") e.setAttribute("id", s); | ||
} | ||
@@ -98,3 +124,3 @@ } | ||
var index = createHyperScript({ | ||
const h = createHyperScript({ | ||
spread, | ||
@@ -108,2 +134,2 @@ assign, | ||
export { index as default }; | ||
export { h as default }; |
@@ -1,2 +0,2 @@ | ||
import h from 'solid-js/h'; | ||
import h from "solid-js/h"; | ||
@@ -3,0 +3,0 @@ function Fragment(props) { |
export type { JSX } from "./jsx"; | ||
import type { JSX } from "./jsx"; | ||
declare function Fragment(props: { | ||
children: JSX.Element; | ||
}): JSX.Element; | ||
declare function jsx(type: any, props: any): () => (Node & { | ||
[key: string]: any; | ||
}) | (Node & { | ||
[key: string]: any; | ||
})[]; | ||
declare function Fragment(props: { children: JSX.Element }): JSX.Element; | ||
declare function jsx( | ||
type: any, | ||
props: any | ||
): () => | ||
| (Node & { | ||
[key: string]: any; | ||
}) | ||
| (Node & { | ||
[key: string]: any; | ||
})[]; | ||
export { jsx, jsx as jsxs, jsx as jsxDEV, Fragment }; |
type MountableElement = Element | Document | ShadowRoot | DocumentFragment | Node; | ||
interface Runtime { | ||
insert(parent: MountableElement, accessor: any, marker?: Node | null, init?: any): any; | ||
spread(node: Element, accessor: any, isSVG?: Boolean, skipChildren?: Boolean): void; | ||
assign(node: Element, props: any, isSVG?: Boolean, skipChildren?: Boolean): void; | ||
createComponent(Comp: (props: any) => any, props: any): any; | ||
dynamicProperty(props: any, key: string): any; | ||
SVGElements: Set<string>; | ||
insert(parent: MountableElement, accessor: any, marker?: Node | null, init?: any): any; | ||
spread(node: Element, accessor: any, isSVG?: Boolean, skipChildren?: Boolean): void; | ||
assign(node: Element, props: any, isSVG?: Boolean, skipChildren?: Boolean): void; | ||
createComponent(Comp: (props: any) => any, props: any): any; | ||
dynamicProperty(props: any, key: string): any; | ||
SVGElements: Set<string>; | ||
} | ||
type ExpandableNode = Node & { | ||
[key: string]: any; | ||
[key: string]: any; | ||
}; | ||
export type HyperScript = { | ||
(...args: any[]): () => ExpandableNode | ExpandableNode[]; | ||
Fragment: (props: { | ||
children: (() => ExpandableNode) | (() => ExpandableNode)[]; | ||
}) => ExpandableNode[]; | ||
(...args: any[]): () => ExpandableNode | ExpandableNode[]; | ||
Fragment: (props: { | ||
children: (() => ExpandableNode) | (() => ExpandableNode)[]; | ||
}) => ExpandableNode[]; | ||
}; | ||
export declare function createHyperScript(r: Runtime): HyperScript; | ||
export {}; |
@@ -1,2 +0,3 @@ | ||
declare const _default: import("hyper-dom-expressions").HyperScript; | ||
export default _default; | ||
import type { HyperScript } from "./hyperscript"; | ||
declare const h: HyperScript; | ||
export default h; |
@@ -1,5 +0,27 @@ | ||
import { effect, style, insert, untrack, spread, createComponent, delegateEvents, classList, mergeProps, dynamicProperty, setAttribute, setAttributeNS, addEventListener, Aliases, getPropAlias, Properties, ChildProperties, DelegatedEvents, SVGElements, SVGNamespace } from 'solid-js/web'; | ||
import { | ||
effect, | ||
style, | ||
insert, | ||
untrack, | ||
spread, | ||
createComponent, | ||
delegateEvents, | ||
classList, | ||
mergeProps, | ||
dynamicProperty, | ||
setAttribute, | ||
setAttributeNS, | ||
addEventListener, | ||
Aliases, | ||
getPropAlias, | ||
Properties, | ||
ChildProperties, | ||
DelegatedEvents, | ||
SVGElements, | ||
SVGNamespace | ||
} from "solid-js/web"; | ||
const tagRE = /(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g; | ||
const attrRE = /(?:\s(?<boolean>[^/\s><=]+?)(?=[\s/>]))|(?:(?<name>\S+?)(?:\s*=\s*(?:(['"])(?<quotedValue>[\s\S]*?)\3|(?<unquotedValue>[^\s>]+))))/g; | ||
const attrRE = | ||
/(?:\s(?<boolean>[^/\s><=]+?)(?=[\s/>]))|(?:(?<name>\S+?)(?:\s*=\s*(?:(['"])(?<quotedValue>[\s\S]*?)\3|(?<unquotedValue>[^\s>]+))))/g; | ||
const lookup = { | ||
@@ -23,6 +45,6 @@ area: true, | ||
}; | ||
function parseTag( tag) { | ||
function parseTag(tag) { | ||
const res = { | ||
type: 'tag', | ||
name: '', | ||
type: "tag", | ||
name: "", | ||
voidElement: false, | ||
@@ -35,10 +57,10 @@ attrs: [], | ||
res.name = tagMatch[1]; | ||
if (lookup[tagMatch[1].toLowerCase()] || tag.charAt(tag.length - 2) === '/') { | ||
if (lookup[tagMatch[1].toLowerCase()] || tag.charAt(tag.length - 2) === "/") { | ||
res.voidElement = true; | ||
} | ||
if (res.name.startsWith('!--')) { | ||
const endIndex = tag.indexOf('-->'); | ||
if (res.name.startsWith("!--")) { | ||
const endIndex = tag.indexOf("-->"); | ||
return { | ||
type: 'comment', | ||
comment: endIndex !== -1 ? tag.slice(4, endIndex) : '' | ||
type: "comment", | ||
comment: endIndex !== -1 ? tag.slice(4, endIndex) : "" | ||
}; | ||
@@ -49,13 +71,13 @@ } | ||
for (const match of tag.matchAll(reg)) { | ||
if ((match[1] || match[2]).startsWith('use:')) { | ||
if ((match[1] || match[2]).startsWith("use:")) { | ||
res.attrs.push({ | ||
type: 'directive', | ||
type: "directive", | ||
name: match[1] || match[2], | ||
value: match[4] || match[5] || '' | ||
value: match[4] || match[5] || "" | ||
}); | ||
} else { | ||
res.attrs.push({ | ||
type: 'attr', | ||
type: "attr", | ||
name: match[1] || match[2], | ||
value: match[4] || match[5] || '' | ||
value: match[4] || match[5] || "" | ||
}); | ||
@@ -67,7 +89,7 @@ } | ||
function pushTextNode(list, html, start) { | ||
const end = html.indexOf('<', start); | ||
const end = html.indexOf("<", start); | ||
const content = html.slice(start, end === -1 ? void 0 : end); | ||
if (!/^\s*$/.test(content)) { | ||
list.push({ | ||
type: 'text', | ||
type: "text", | ||
content: content | ||
@@ -78,6 +100,6 @@ }); | ||
function pushCommentNode(list, tag) { | ||
const content = tag.replace('<!--', '').replace('-->', ''); | ||
const content = tag.replace("<!--", "").replace("-->", ""); | ||
if (!/^\s*$/.test(content)) { | ||
list.push({ | ||
type: 'comment', | ||
type: "comment", | ||
content: content | ||
@@ -94,4 +116,4 @@ }); | ||
html.replace(tagRE, (tag, index) => { | ||
const isOpen = tag.charAt(1) !== '/'; | ||
const isComment = tag.slice(0, 4) === '<!--'; | ||
const isOpen = tag.charAt(1) !== "/"; | ||
const isComment = tag.slice(0, 4) === "<!--"; | ||
const start = index + tag.length; | ||
@@ -103,3 +125,3 @@ const nextChar = html.charAt(start); | ||
current = parseTag(tag); | ||
if (!current.voidElement && nextChar && nextChar !== '<') { | ||
if (!current.voidElement && nextChar && nextChar !== "<") { | ||
pushTextNode(current.children, html, start); | ||
@@ -128,3 +150,3 @@ } | ||
} | ||
if (nextChar !== '<' && nextChar) { | ||
if (nextChar !== "<" && nextChar) { | ||
parent = level === -1 ? result : arr[level].children; | ||
@@ -140,21 +162,22 @@ pushTextNode(parent, html, start); | ||
for (const attr of attrs) { | ||
buff.push(attr.name + '="' + attr.value.replace(/"/g, '"') + '"'); | ||
buff.push(attr.name + '="' + attr.value.replace(/"/g, """) + '"'); | ||
} | ||
if (!buff.length) { | ||
return ''; | ||
return ""; | ||
} | ||
return ' ' + buff.join(' '); | ||
return " " + buff.join(" "); | ||
} | ||
function stringifier(buff, doc) { | ||
switch (doc.type) { | ||
case 'text': | ||
case "text": | ||
return buff + doc.content; | ||
case 'tag': | ||
buff += '<' + doc.name + (doc.attrs ? attrString(doc.attrs) : '') + (doc.voidElement ? '/>' : '>'); | ||
case "tag": | ||
buff += | ||
"<" + doc.name + (doc.attrs ? attrString(doc.attrs) : "") + (doc.voidElement ? "/>" : ">"); | ||
if (doc.voidElement) { | ||
return buff; | ||
} | ||
return buff + doc.children.reduce(stringifier, '') + '</' + doc.name + '>'; | ||
case 'comment': | ||
return buff += '<!--' + doc.content + '-->'; | ||
return buff + doc.children.reduce(stringifier, "") + "</" + doc.name + ">"; | ||
case "comment": | ||
return (buff += "<!--" + doc.content + "-->"); | ||
} | ||
@@ -164,14 +187,19 @@ } | ||
return doc.reduce(function (token, rootEl) { | ||
return token + stringifier('', rootEl); | ||
}, ''); | ||
return token + stringifier("", rootEl); | ||
}, ""); | ||
} | ||
const cache = new Map(); | ||
const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i; | ||
const VOID_ELEMENTS = | ||
/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i; | ||
const spaces = " \\f\\n\\r\\t"; | ||
const almostEverything = "[^" + spaces + "\\/>\"'=]+"; | ||
const attrName = "[ " + spaces + "]+(?:use:<!--#-->|" + almostEverything + ')'; | ||
const attrName = "[ " + spaces + "]+(?:use:<!--#-->|" + almostEverything + ")"; | ||
const tagName = "<([A-Za-z$#]+[A-Za-z0-9:_-]*)((?:"; | ||
const attrPartials = "(?:\\s*=\\s*(?:'[^']*?'|\"[^\"]*?\"|\\([^)]*?\\)|<[^>]*?>|" + almostEverything + "))?)"; | ||
const attrPartials = | ||
"(?:\\s*=\\s*(?:'[^']*?'|\"[^\"]*?\"|\\([^)]*?\\)|<[^>]*?>|" + almostEverything + "))?)"; | ||
const attrSeeker = new RegExp(tagName + attrName + attrPartials + "+)([ " + spaces + "]*/?>)", "g"); | ||
const findAttributes = new RegExp("(" + attrName + "\\s*=\\s*)(<!--#-->|['\"(]([\\w\\s]*<!--#-->[\\w\\s]*)*['\")])", "gi"); | ||
const findAttributes = new RegExp( | ||
"(" + attrName + "\\s*=\\s*)(<!--#-->|['\"(]([\\w\\s]*<!--#-->[\\w\\s]*)*['\")])", | ||
"gi" | ||
); | ||
const selfClosing = new RegExp(tagName + attrName + attrPartials + "*)([ " + spaces + "]*/>)", "g"); | ||
@@ -184,3 +212,6 @@ const marker = "<!--#-->"; | ||
function replaceAttributes($0, $1, $2) { | ||
return $1.replace(/<!--#-->/g, "###") + ($2[0] === '"' || $2[0] === "'" ? $2.replace(/<!--#-->/g, "###") : '"###"'); | ||
return ( | ||
$1.replace(/<!--#-->/g, "###") + | ||
($2[0] === '"' || $2[0] === "'" ? $2.replace(/<!--#-->/g, "###") : '"###"') | ||
); | ||
} | ||
@@ -194,5 +225,7 @@ function fullClosing($0, $1, $2) { | ||
function parseDirective(name, value, tag, options) { | ||
if (name === 'use:###' && value === '###') { | ||
if (name === "use:###" && value === "###") { | ||
const count = options.counter++; | ||
options.exprs.push(`typeof exprs[${count}] === "function" ? r.use(exprs[${count}], ${tag}, exprs[${options.counter++}]) : (()=>{throw new Error("use:### must be a function")})()`); | ||
options.exprs.push( | ||
`typeof exprs[${count}] === "function" ? r.use(exprs[${count}], ${tag}, exprs[${options.counter++}]) : (()=>{throw new Error("use:### must be a function")})()` | ||
); | ||
} else { | ||
@@ -202,6 +235,6 @@ throw new Error(`Not support syntax ${name} must be use:{function}`); | ||
} | ||
function createHTML(r, { | ||
delegateEvents = true, | ||
functionBuilder = (...args) => new Function(...args) | ||
} = {}) { | ||
function createHTML( | ||
r, | ||
{ delegateEvents = true, functionBuilder = (...args) => new Function(...args) } = {} | ||
) { | ||
let uuid = 1; | ||
@@ -222,3 +255,12 @@ r.wrapProps = props => { | ||
markup = markup + statics[i]; | ||
const replaceList = [[selfClosing, fullClosing], [/<(<!--#-->)/g, "<###"], [/\.\.\.(<!--#-->)/g, "###"], [attrSeeker, attrReplacer], [/>\n+\s*/g, ">"], [/\n+\s*</g, "<"], [/\s+</g, " <"], [/>\s+/g, "> "]]; | ||
const replaceList = [ | ||
[selfClosing, fullClosing], | ||
[/<(<!--#-->)/g, "<###"], | ||
[/\.\.\.(<!--#-->)/g, "###"], | ||
[attrSeeker, attrReplacer], | ||
[/>\n+\s*/g, ">"], | ||
[/\n+\s*</g, "<"], | ||
[/\s+</g, " <"], | ||
[/>\s+/g, "> "] | ||
]; | ||
markup = replaceList.reduce((acc, x) => { | ||
@@ -251,3 +293,15 @@ return acc.replace(x[0], x[1]); | ||
function parseKeyValue(node, tag, name, value, isSVG, isCE, options) { | ||
let expr = value === "###" ? `!doNotWrap ? exprs[${options.counter}]() : exprs[${options.counter++}]` : value.split("###").map((v, i) => i ? ` + (typeof exprs[${options.counter}] === "function" ? exprs[${options.counter}]() : exprs[${options.counter++}]) + "${v}"` : `"${v}"`).join(""), | ||
let expr = | ||
value === "###" | ||
? `!doNotWrap ? exprs[${options.counter}]() : exprs[${options.counter++}]` | ||
: value | ||
.split("###") | ||
.map((v, i) => | ||
i | ||
? ` + (typeof exprs[${options.counter}] === "function" ? exprs[${ | ||
options.counter | ||
}]() : exprs[${options.counter++}]) + "${v}"` | ||
: `"${v}"` | ||
) | ||
.join(""), | ||
parts, | ||
@@ -269,8 +323,17 @@ namespace; | ||
options.exprs.push(`r.classList(${tag},${expr},${prev})`); | ||
} else if (namespace !== "attr" && (isChildProp || !isSVG && (r.getPropAlias(name, node.name.toUpperCase()) || isProp) || isCE || namespace === "prop")) { | ||
} else if ( | ||
namespace !== "attr" && | ||
(isChildProp || | ||
(!isSVG && (r.getPropAlias(name, node.name.toUpperCase()) || isProp)) || | ||
isCE || | ||
namespace === "prop") | ||
) { | ||
if (isCE && !isChildProp && !isProp && namespace !== "prop") name = toPropertyName(name); | ||
options.exprs.push(`${tag}.${r.getPropAlias(name, node.name.toUpperCase()) || name} = ${expr}`); | ||
options.exprs.push( | ||
`${tag}.${r.getPropAlias(name, node.name.toUpperCase()) || name} = ${expr}` | ||
); | ||
} else { | ||
const ns = isSVG && name.indexOf(":") > -1 && r.SVGNamespace[name.split(":")[0]]; | ||
if (ns) options.exprs.push(`r.setAttributeNS(${tag},"${ns}","${name}",${expr})`);else options.exprs.push(`r.setAttribute(${tag},"${r.Aliases[name] || name}",${expr})`); | ||
if (ns) options.exprs.push(`r.setAttributeNS(${tag},"${ns}","${name}",${expr})`); | ||
else options.exprs.push(`r.setAttribute(${tag},"${r.Aliases[name] || name}",${expr})`); | ||
} | ||
@@ -283,7 +346,13 @@ } | ||
const delegate = delegateEvents && r.DelegatedEvents.has(lc); | ||
options.exprs.push(`r.addEventListener(${tag},"${lc}",exprs[${options.counter++}],${delegate})`); | ||
options.exprs.push( | ||
`r.addEventListener(${tag},"${lc}",exprs[${options.counter++}],${delegate})` | ||
); | ||
delegate && options.delegatedEvents.add(lc); | ||
} else { | ||
let capture = name.startsWith("oncapture:"); | ||
options.exprs.push(`${tag}.addEventListener("${name.slice(capture ? 10 : 3)}",exprs[${options.counter++}]${capture ? ",true" : ""})`); | ||
options.exprs.push( | ||
`${tag}.addEventListener("${name.slice(capture ? 10 : 3)}",exprs[${options.counter++}]${ | ||
capture ? ",true" : "" | ||
})` | ||
); | ||
} | ||
@@ -298,5 +367,11 @@ } else if (name === "ref") { | ||
parseKeyValue(node, tag, name, value, isSVG, isCE, childOptions); | ||
options.decl.push(`_fn${count} = (${value === "###" ? "doNotWrap" : ""}) => {\n${childOptions.exprs.join(";\n")};\n}`); | ||
options.decl.push( | ||
`_fn${count} = (${value === "###" ? "doNotWrap" : ""}) => {\n${childOptions.exprs.join( | ||
";\n" | ||
)};\n}` | ||
); | ||
if (value === "###") { | ||
options.exprs.push(`typeof exprs[${count}] === "function" ? r.effect(_fn${count}) : _fn${count}(true)`); | ||
options.exprs.push( | ||
`typeof exprs[${count}] === "function" ? r.effect(_fn${count}) : _fn${count}(true)` | ||
); | ||
} else { | ||
@@ -323,3 +398,6 @@ let check = ""; | ||
const child = node.children[i]; | ||
if (child.type === "comment" && child.content === "#" || child.type === "tag" && child.name === "###") { | ||
if ( | ||
(child.type === "comment" && child.content === "#") || | ||
(child.type === "tag" && child.name === "###") | ||
) { | ||
childOptions.multi = true; | ||
@@ -345,3 +423,5 @@ break; | ||
parseNode(child, childOptions); | ||
if (!childOptions.multi && child.type === "comment" && child.content === "#") node.children.splice(i, 1);else i++; | ||
if (!childOptions.multi && child.type === "comment" && child.content === "#") | ||
node.children.splice(i, 1); | ||
else i++; | ||
} | ||
@@ -368,22 +448,24 @@ options.counter = childOptions.counter; | ||
for (let i = 0; i < keys.length; i++) { | ||
const { | ||
type, | ||
name, | ||
value | ||
} = node.attrs[i]; | ||
if (type === 'attr') { | ||
const { type, name, value } = node.attrs[i]; | ||
if (type === "attr") { | ||
if (name === "###") { | ||
propGroups.push(`exprs[${options.counter++}]`); | ||
propGroups.push(props = []); | ||
propGroups.push((props = [])); | ||
} else if (value === "###") { | ||
props.push(`${name}: exprs[${options.counter++}]`); | ||
} else props.push(`${name}: "${value}"`); | ||
} else if (type === 'directive') { | ||
} else if (type === "directive") { | ||
const tag = `_$el${uuid++}`; | ||
const topDecl = !options.decl.length; | ||
options.decl.push(topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`); | ||
options.decl.push( | ||
topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}` | ||
); | ||
parseDirective(name, value, tag, options); | ||
} | ||
} | ||
if (node.children.length === 1 && node.children[0].type === "comment" && node.children[0].content === "#") { | ||
if ( | ||
node.children.length === 1 && | ||
node.children[0].type === "comment" && | ||
node.children[0].content === "#" | ||
) { | ||
props.push(`children: () => exprs[${options.counter++}]`); | ||
@@ -411,3 +493,16 @@ } else if (node.children.length) { | ||
} | ||
if (options.parent) options.exprs.push(`r.insert(${options.parent}, r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})${tag ? `, ${tag}` : ""})`);else options.exprs.push(`${options.fragment ? "" : "return "}r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})`); | ||
if (options.parent) | ||
options.exprs.push( | ||
`r.insert(${ | ||
options.parent | ||
}, r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})${ | ||
tag ? `, ${tag}` : "" | ||
})` | ||
); | ||
else | ||
options.exprs.push( | ||
`${ | ||
options.fragment ? "" : "return " | ||
}r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})` | ||
); | ||
options.path = tag; | ||
@@ -443,3 +538,10 @@ options.first = false; | ||
parseNode(child, childOptions); | ||
parts.push(`function() { ${childOptions.decl.join(",\n") + ";\n" + childOptions.exprs.join(";\n") + `;\nreturn _$el${id};\n`}}()`); | ||
parts.push( | ||
`function() { ${ | ||
childOptions.decl.join(",\n") + | ||
";\n" + | ||
childOptions.exprs.join(";\n") + | ||
`;\nreturn _$el${id};\n` | ||
}}()` | ||
); | ||
options.counter = childOptions.counter; | ||
@@ -450,3 +552,4 @@ options.templateId = childOptions.templateId; | ||
} else if (child.type === "comment") { | ||
if (child.content === "#") parts.push(`exprs[${options.counter++}]`);else if (child.content) { | ||
if (child.content === "#") parts.push(`exprs[${options.counter++}]`); | ||
else if (child.content) { | ||
for (let i = 0; i < child.content.split("###").length - 1; i++) { | ||
@@ -463,3 +566,5 @@ parts.push(`exprs[${options.counter++}]`); | ||
const templateId = options.templateId; | ||
options.decl.push(topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`); | ||
options.decl.push( | ||
topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}` | ||
); | ||
const isSVG = r.SVGElements.has(node.name); | ||
@@ -473,11 +578,9 @@ const isCE = node.name.includes("-"); | ||
for (let i = 0; i < node.attrs.length; i++) { | ||
const { | ||
type, | ||
name, | ||
value | ||
} = node.attrs[i]; | ||
if (type === 'attr') { | ||
const { type, name, value } = node.attrs[i]; | ||
if (type === "attr") { | ||
if (value.includes("###")) { | ||
let count = options.counter++; | ||
current += `${name}: ${name !== "ref" ? `typeof exprs[${count}] === "function" ? exprs[${count}]() : ` : ""}exprs[${count}],`; | ||
current += `${name}: ${ | ||
name !== "ref" ? `typeof exprs[${count}] === "function" ? exprs[${count}]() : ` : "" | ||
}exprs[${count}],`; | ||
} else if (name === "###") { | ||
@@ -492,3 +595,3 @@ if (current.length) { | ||
} | ||
} else if (type === 'directive') { | ||
} else if (type === "directive") { | ||
parseDirective(name, value, tag, options); | ||
@@ -501,11 +604,13 @@ } | ||
} | ||
options.exprs.push(`r.spread(${tag},${spreadArgs.length === 1 ? `typeof ${spreadArgs[0]} === "function" ? r.mergeProps(${spreadArgs[0]}) : ${spreadArgs[0]}` : `r.mergeProps(${spreadArgs.join(",")})`},${isSVG},${!!node.children.length})`); | ||
options.exprs.push( | ||
`r.spread(${tag},${ | ||
spreadArgs.length === 1 | ||
? `typeof ${spreadArgs[0]} === "function" ? r.mergeProps(${spreadArgs[0]}) : ${spreadArgs[0]}` | ||
: `r.mergeProps(${spreadArgs.join(",")})` | ||
},${isSVG},${!!node.children.length})` | ||
); | ||
} else { | ||
for (let i = 0; i < node.attrs.length; i++) { | ||
const { | ||
type, | ||
name, | ||
value | ||
} = node.attrs[i]; | ||
if (type === 'directive') { | ||
const { type, name, value } = node.attrs[i]; | ||
if (type === "directive") { | ||
parseDirective(name, value, tag, options); | ||
@@ -527,3 +632,5 @@ node.attrs.splice(i, 1); | ||
if (topDecl) { | ||
options.decl[0] = options.hasCustomElement ? `const ${tag} = r.untrack(() => document.importNode(tmpls[${templateId}].content.firstChild, true))` : `const ${tag} = tmpls[${templateId}].content.firstChild.cloneNode(true)`; | ||
options.decl[0] = options.hasCustomElement | ||
? `const ${tag} = r.untrack(() => document.importNode(tmpls[${templateId}].content.firstChild, true))` | ||
: `const ${tag} = tmpls[${templateId}].content.firstChild.cloneNode(true)`; | ||
} | ||
@@ -563,6 +670,8 @@ } else if (node.type === "text") { | ||
if (nodes.length > 1) { | ||
nodes = [{ | ||
type: "fragment", | ||
children: nodes | ||
}]; | ||
nodes = [ | ||
{ | ||
type: "fragment", | ||
children: nodes | ||
} | ||
]; | ||
} | ||
@@ -575,8 +684,21 @@ if (nodes[0].name === "###") { | ||
const templateNodes = [origNodes].concat(options.templateNodes); | ||
return [templateNodes.map(t => stringify(t)), funcBuilder("tmpls", "exprs", "r", options.decl.join(",\n") + ";\n" + options.exprs.join(";\n") + (toplevel ? "" : `;\nreturn _$el${id};\n`))]; | ||
return [ | ||
templateNodes.map(t => stringify(t)), | ||
funcBuilder( | ||
"tmpls", | ||
"exprs", | ||
"r", | ||
options.decl.join(",\n") + | ||
";\n" + | ||
options.exprs.join(";\n") + | ||
(toplevel ? "" : `;\nreturn _$el${id};\n`) | ||
) | ||
]; | ||
} | ||
function html(statics, ...args) { | ||
const templates = cache.get(statics) || createTemplate(statics, { | ||
funcBuilder: functionBuilder | ||
}); | ||
const templates = | ||
cache.get(statics) || | ||
createTemplate(statics, { | ||
funcBuilder: functionBuilder | ||
}); | ||
return templates[0].create(templates, args, r); | ||
@@ -587,3 +709,3 @@ } | ||
var index = createHTML({ | ||
const html = createHTML({ | ||
effect, | ||
@@ -611,2 +733,2 @@ style, | ||
export { index as default }; | ||
export { html as default }; |
@@ -1,2 +0,3 @@ | ||
declare const _default: import("lit-dom-expressions").HTMLTag; | ||
export default _default; | ||
import type { HTMLTag } from "./lit"; | ||
declare const html: HTMLTag; | ||
export default html; |
type MountableElement = Element | Document | ShadowRoot | DocumentFragment | Node; | ||
interface Runtime { | ||
effect<T>(fn: (prev?: T) => T, init?: T): any; | ||
untrack<T>(fn: () => T): T; | ||
insert(parent: MountableElement, accessor: any, marker?: Node | null, init?: any): any; | ||
spread<T>(node: Element, accessor: (() => T) | T, isSVG?: Boolean, skipChildren?: Boolean): void; | ||
createComponent(Comp: (props: any) => any, props: any): any; | ||
addEventListener(node: Element, name: string, handler: () => void, delegate: boolean): void; | ||
delegateEvents(eventNames: string[]): void; | ||
classList(node: Element, value: { | ||
[k: string]: boolean; | ||
}, prev?: { | ||
[k: string]: boolean; | ||
}): void; | ||
style(node: Element, value: { | ||
[k: string]: string; | ||
}, prev?: { | ||
[k: string]: string; | ||
}): void; | ||
mergeProps(...sources: unknown[]): unknown; | ||
dynamicProperty(props: any, key: string): any; | ||
setAttribute(node: Element, name: string, value: any): void; | ||
setAttributeNS(node: Element, namespace: string, name: string, value: any): void; | ||
Aliases: Record<string, string>; | ||
getPropAlias(prop: string, tagName: string): string | undefined; | ||
Properties: Set<string>; | ||
ChildProperties: Set<string>; | ||
DelegatedEvents: Set<string>; | ||
SVGElements: Set<string>; | ||
SVGNamespace: Record<string, string>; | ||
effect<T>(fn: (prev?: T) => T, init?: T): any; | ||
untrack<T>(fn: () => T): T; | ||
insert(parent: MountableElement, accessor: any, marker?: Node | null, init?: any): any; | ||
spread<T>(node: Element, accessor: (() => T) | T, isSVG?: Boolean, skipChildren?: Boolean): void; | ||
createComponent(Comp: (props: any) => any, props: any): any; | ||
addEventListener(node: Element, name: string, handler: () => void, delegate: boolean): void; | ||
delegateEvents(eventNames: string[]): void; | ||
classList( | ||
node: Element, | ||
value: { | ||
[k: string]: boolean; | ||
}, | ||
prev?: { | ||
[k: string]: boolean; | ||
} | ||
): void; | ||
style( | ||
node: Element, | ||
value: { | ||
[k: string]: string; | ||
}, | ||
prev?: { | ||
[k: string]: string; | ||
} | ||
): void; | ||
mergeProps(...sources: unknown[]): unknown; | ||
dynamicProperty(props: any, key: string): any; | ||
setAttribute(node: Element, name: string, value: any): void; | ||
setAttributeNS(node: Element, namespace: string, name: string, value: any): void; | ||
Aliases: Record<string, string>; | ||
getPropAlias(prop: string, tagName: string): string | undefined; | ||
Properties: Set<string>; | ||
ChildProperties: Set<string>; | ||
DelegatedEvents: Set<string>; | ||
SVGElements: Set<string>; | ||
SVGNamespace: Record<string, string>; | ||
} | ||
export type HTMLTag = { | ||
(statics: TemplateStringsArray, ...args: unknown[]): Node | Node[]; | ||
(statics: TemplateStringsArray, ...args: unknown[]): Node | Node[]; | ||
}; | ||
export declare function createHTML(r: Runtime, { delegateEvents, functionBuilder }?: { | ||
export declare function createHTML( | ||
r: Runtime, | ||
{ | ||
delegateEvents, | ||
functionBuilder | ||
}?: { | ||
delegateEvents?: boolean; | ||
functionBuilder?: (...args: string[]) => Function; | ||
}): HTMLTag; | ||
} | ||
): HTMLTag; | ||
export {}; |
{ | ||
"name": "solid-js", | ||
"description": "A declarative JavaScript library for building user interfaces.", | ||
"version": "1.7.8", | ||
"version": "1.7.9", | ||
"author": "Ryan Carniato", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -1,5 +0,6 @@ | ||
import { DEV as DEV$1, $PROXY, $TRACK, getListener, batch, createSignal } from 'solid-js'; | ||
import { DEV as DEV$1, $PROXY, $TRACK, getListener, batch, createSignal } from "solid-js"; | ||
const $RAW = Symbol("store-raw"), | ||
$NODE = Symbol("store-node"); | ||
$NODE = Symbol("store-node"), | ||
$HAS = Symbol("store-has"); | ||
const DevHooks = { | ||
@@ -12,3 +13,3 @@ onStoreNodeUpdate: null | ||
Object.defineProperty(value, $PROXY, { | ||
value: p = new Proxy(value, proxyTraps$1) | ||
value: (p = new Proxy(value, proxyTraps$1)) | ||
}); | ||
@@ -33,10 +34,18 @@ if (!Array.isArray(value)) { | ||
let proto; | ||
return obj != null && typeof obj === "object" && (obj[$PROXY] || !(proto = Object.getPrototypeOf(obj)) || proto === Object.prototype || Array.isArray(obj)); | ||
return ( | ||
obj != null && | ||
typeof obj === "object" && | ||
(obj[$PROXY] || | ||
!(proto = Object.getPrototypeOf(obj)) || | ||
proto === Object.prototype || | ||
Array.isArray(obj)) | ||
); | ||
} | ||
function unwrap(item, set = new Set()) { | ||
let result, unwrapped, v, prop; | ||
if (result = item != null && item[$RAW]) return result; | ||
if ((result = item != null && item[$RAW])) return result; | ||
if (!isWrappable(item) || set.has(item)) return item; | ||
if (Array.isArray(item)) { | ||
if (Object.isFrozen(item)) item = item.slice(0);else set.add(item); | ||
if (Object.isFrozen(item)) item = item.slice(0); | ||
else set.add(item); | ||
for (let i = 0, l = item.length; i < l; i++) { | ||
@@ -47,3 +56,4 @@ v = item[i]; | ||
} else { | ||
if (Object.isFrozen(item)) item = Object.assign({}, item);else set.add(item); | ||
if (Object.isFrozen(item)) item = Object.assign({}, item); | ||
else set.add(item); | ||
const keys = Object.keys(item), | ||
@@ -60,15 +70,23 @@ desc = Object.getOwnPropertyDescriptors(item); | ||
} | ||
function getDataNodes(target) { | ||
let nodes = target[$NODE]; | ||
if (!nodes) Object.defineProperty(target, $NODE, { | ||
value: nodes = Object.create(null) | ||
}); | ||
function getNodes(target, symbol) { | ||
let nodes = target[symbol]; | ||
if (!nodes) | ||
Object.defineProperty(target, symbol, { | ||
value: (nodes = Object.create(null)) | ||
}); | ||
return nodes; | ||
} | ||
function getDataNode(nodes, property, value) { | ||
return nodes[property] || (nodes[property] = createDataNode(value)); | ||
function getNode(nodes, property, value) { | ||
if (nodes[property]) return nodes[property]; | ||
const [s, set] = createSignal(value, { | ||
equals: false, | ||
internal: true | ||
}); | ||
s.$ = set; | ||
return (nodes[property] = s); | ||
} | ||
function proxyDescriptor$1(target, property) { | ||
const desc = Reflect.getOwnPropertyDescriptor(target, property); | ||
if (!desc || desc.get || !desc.configurable || property === $PROXY || property === $NODE) return desc; | ||
if (!desc || desc.get || !desc.configurable || property === $PROXY || property === $NODE) | ||
return desc; | ||
delete desc.value; | ||
@@ -80,6 +98,3 @@ delete desc.writable; | ||
function trackSelf(target) { | ||
if (getListener()) { | ||
const nodes = getDataNodes(target); | ||
(nodes._ || (nodes._ = createDataNode()))(); | ||
} | ||
getListener() && getNode(getNodes(target, $NODE), "_")(); | ||
} | ||
@@ -90,10 +105,2 @@ function ownKeys(target) { | ||
} | ||
function createDataNode(value) { | ||
const [s, set] = createSignal(value, { | ||
equals: false, | ||
internal: true | ||
}); | ||
s.$ = set; | ||
return s; | ||
} | ||
const proxyTraps$1 = { | ||
@@ -107,9 +114,14 @@ get(target, property, receiver) { | ||
} | ||
const nodes = getDataNodes(target); | ||
const nodes = getNodes(target, $NODE); | ||
const tracked = nodes[property]; | ||
let value = tracked ? tracked() : target[property]; | ||
if (property === $NODE || property === "__proto__") return value; | ||
if (property === $NODE || property === $HAS || property === "__proto__") return value; | ||
if (!tracked) { | ||
const desc = Object.getOwnPropertyDescriptor(target, property); | ||
if (getListener() && (typeof value !== "function" || target.hasOwnProperty(property)) && !(desc && desc.get)) value = getDataNode(nodes, property, value)(); | ||
if ( | ||
getListener() && | ||
(typeof value !== "function" || target.hasOwnProperty(property)) && | ||
!(desc && desc.get) | ||
) | ||
value = getNode(nodes, property, value)(); | ||
} | ||
@@ -119,4 +131,12 @@ return isWrappable(value) ? wrap$1(value) : value; | ||
has(target, property) { | ||
if (property === $RAW || property === $PROXY || property === $TRACK || property === $NODE || property === "__proto__") return true; | ||
this.get(target, property, target); | ||
if ( | ||
property === $RAW || | ||
property === $PROXY || | ||
property === $TRACK || | ||
property === $NODE || | ||
property === $HAS || | ||
property === "__proto__" | ||
) | ||
return true; | ||
getListener() && getNode(getNodes(target, $HAS), property)(); | ||
return property in target; | ||
@@ -140,9 +160,15 @@ }, | ||
DevHooks.onStoreNodeUpdate && DevHooks.onStoreNodeUpdate(state, property, value, prev); | ||
if (value === undefined) delete state[property];else state[property] = value; | ||
let nodes = getDataNodes(state), | ||
if (value === undefined) { | ||
delete state[property]; | ||
if (state[$HAS] && state[$HAS][property] && prev !== undefined) state[$HAS][property].$(); | ||
} else { | ||
state[property] = value; | ||
if (state[$HAS] && state[$HAS][property] && prev === undefined) state[$HAS][property].$(); | ||
} | ||
let nodes = getNodes(state, $NODE), | ||
node; | ||
if (node = getDataNode(nodes, property, prev)) node.$(() => value); | ||
if ((node = getNode(nodes, property, prev))) node.$(() => value); | ||
if (Array.isArray(state) && state.length !== len) { | ||
for (let i = state.length; i < len; i++) (node = nodes[i]) && node.$(); | ||
(node = getDataNode(nodes, "length", len)) && node.$(state.length); | ||
(node = getNode(nodes, "length", len)) && node.$(state.length); | ||
} | ||
@@ -190,7 +216,3 @@ (node = nodes._) && node.$(); | ||
} else if (isArray && partType === "object") { | ||
const { | ||
from = 0, | ||
to = current.length - 1, | ||
by = 1 | ||
} = part; | ||
const { from = 0, to = current.length - 1, by = 1 } = part; | ||
for (let i = from; i <= to; i += by) { | ||
@@ -214,3 +236,3 @@ updatePath(current, [i].concat(path), traversed); | ||
value = unwrap(value); | ||
if (part === undefined || isWrappable(prev) && isWrappable(value) && !Array.isArray(value)) { | ||
if (part === undefined || (isWrappable(prev) && isWrappable(value) && !Array.isArray(value))) { | ||
mergeStoreNode(prev, value); | ||
@@ -222,3 +244,6 @@ } else setProperty(current, part, value); | ||
const isArray = Array.isArray(unwrappedStore); | ||
if (typeof unwrappedStore !== "object" && typeof unwrappedStore !== "function") throw new Error(`Unexpected type ${typeof unwrappedStore} received when initializing 'createStore'. Expected an object.`); | ||
if (typeof unwrappedStore !== "object" && typeof unwrappedStore !== "function") | ||
throw new Error( | ||
`Unexpected type ${typeof unwrappedStore} received when initializing 'createStore'. Expected an object.` | ||
); | ||
const wrappedStore = wrap$1(unwrappedStore); | ||
@@ -231,3 +256,5 @@ DEV$1.registerGraph({ | ||
batch(() => { | ||
isArray && args.length === 1 ? updateArray(unwrappedStore, args[0]) : updatePath(unwrappedStore, args); | ||
isArray && args.length === 1 | ||
? updateArray(unwrappedStore, args[0]) | ||
: updatePath(unwrappedStore, args); | ||
}); | ||
@@ -240,7 +267,15 @@ } | ||
const desc = Reflect.getOwnPropertyDescriptor(target, property); | ||
if (!desc || desc.get || desc.set || !desc.configurable || property === $PROXY || property === $NODE) return desc; | ||
if ( | ||
!desc || | ||
desc.get || | ||
desc.set || | ||
!desc.configurable || | ||
property === $PROXY || | ||
property === $NODE | ||
) | ||
return desc; | ||
delete desc.value; | ||
delete desc.writable; | ||
desc.get = () => target[$PROXY][property]; | ||
desc.set = v => target[$PROXY][property] = v; | ||
desc.set = v => (target[$PROXY][property] = v); | ||
return desc; | ||
@@ -256,10 +291,12 @@ } | ||
} | ||
const nodes = getDataNodes(target); | ||
const nodes = getNodes(target, $NODE); | ||
const tracked = nodes[property]; | ||
let value = tracked ? tracked() : target[property]; | ||
if (property === $NODE || property === "__proto__") return value; | ||
if (property === $NODE || property === $HAS || property === "__proto__") return value; | ||
if (!tracked) { | ||
const desc = Object.getOwnPropertyDescriptor(target, property); | ||
const isFunction = typeof value === "function"; | ||
if (getListener() && (!isFunction || target.hasOwnProperty(property)) && !(desc && desc.get)) value = getDataNode(nodes, property, value)();else if (value != null && isFunction && value === Array.prototype[property]) { | ||
if (getListener() && (!isFunction || target.hasOwnProperty(property)) && !(desc && desc.get)) | ||
value = getNode(nodes, property, value)(); | ||
else if (value != null && isFunction && value === Array.prototype[property]) { | ||
return (...args) => batch(() => Array.prototype[property].apply(receiver, args)); | ||
@@ -271,4 +308,12 @@ } | ||
has(target, property) { | ||
if (property === $RAW || property === $PROXY || property === $TRACK || property === $NODE || property === "__proto__") return true; | ||
this.get(target, property, target); | ||
if ( | ||
property === $RAW || | ||
property === $PROXY || | ||
property === $TRACK || | ||
property === $NODE || | ||
property === $HAS || | ||
property === "__proto__" | ||
) | ||
return true; | ||
getListener() && getNode(getNodes(target, $HAS), property)(); | ||
return property in target; | ||
@@ -291,3 +336,3 @@ }, | ||
Object.defineProperty(value, $PROXY, { | ||
value: p = new Proxy(value, proxyTraps) | ||
value: (p = new Proxy(value, proxyTraps)) | ||
}); | ||
@@ -317,3 +362,6 @@ const keys = Object.keys(value), | ||
const unwrappedStore = unwrap(state || {}); | ||
if (typeof unwrappedStore !== "object" && typeof unwrappedStore !== "function") throw new Error(`Unexpected type ${typeof unwrappedStore} received when initializing 'createMutable'. Expected an object.`); | ||
if (typeof unwrappedStore !== "object" && typeof unwrappedStore !== "function") | ||
throw new Error( | ||
`Unexpected type ${typeof unwrappedStore} received when initializing 'createMutable'. Expected an object.` | ||
); | ||
const wrappedStore = wrap(unwrappedStore); | ||
@@ -334,3 +382,6 @@ DEV$1.registerGraph({ | ||
if (target === previous) return; | ||
if (property !== $ROOT && (!isWrappable(target) || !isWrappable(previous) || key && target[key] !== previous[key])) { | ||
if ( | ||
property !== $ROOT && | ||
(!isWrappable(target) || !isWrappable(previous) || (key && target[key] !== previous[key])) | ||
) { | ||
setProperty(parent, property, target); | ||
@@ -340,5 +391,15 @@ return; | ||
if (Array.isArray(target)) { | ||
if (target.length && previous.length && (!merge || key && target[0] && target[0][key] != null)) { | ||
if ( | ||
target.length && | ||
previous.length && | ||
(!merge || (key && target[0] && target[0][key] != null)) | ||
) { | ||
let i, j, start, end, newEnd, item, newIndicesNext, keyVal; | ||
for (start = 0, end = Math.min(previous.length, target.length); start < end && (previous[start] === target[start] || key && previous[start] && target[start] && previous[start][key] === target[start][key]); start++) { | ||
for ( | ||
start = 0, end = Math.min(previous.length, target.length); | ||
start < end && | ||
(previous[start] === target[start] || | ||
(key && previous[start] && target[start] && previous[start][key] === target[start][key])); | ||
start++ | ||
) { | ||
applyState(target[start], previous, start, merge, key); | ||
@@ -348,3 +409,10 @@ } | ||
newIndices = new Map(); | ||
for (end = previous.length - 1, newEnd = target.length - 1; end >= start && newEnd >= start && (previous[end] === target[newEnd] || key && previous[start] && target[start] && previous[end][key] === target[newEnd][key]); end--, newEnd--) { | ||
for ( | ||
end = previous.length - 1, newEnd = target.length - 1; | ||
end >= start && | ||
newEnd >= start && | ||
(previous[end] === target[newEnd] || | ||
(key && previous[start] && target[start] && previous[end][key] === target[newEnd][key])); | ||
end--, newEnd-- | ||
) { | ||
temp[newEnd] = previous[end]; | ||
@@ -403,12 +471,15 @@ } | ||
function reconcile(value, options = {}) { | ||
const { | ||
merge, | ||
key = "id" | ||
} = options, | ||
const { merge, key = "id" } = options, | ||
v = unwrap(value); | ||
return state => { | ||
if (!isWrappable(state) || !isWrappable(v)) return v; | ||
const res = applyState(v, { | ||
[$ROOT]: state | ||
}, $ROOT, merge, key); | ||
const res = applyState( | ||
v, | ||
{ | ||
[$ROOT]: state | ||
}, | ||
$ROOT, | ||
merge, | ||
key | ||
); | ||
return res === undefined ? state : res; | ||
@@ -423,3 +494,6 @@ }; | ||
let proxy; | ||
return isWrappable(value) ? producers.get(value) || (producers.set(value, proxy = new Proxy(value, setterTraps)), proxy) : value; | ||
return isWrappable(value) | ||
? producers.get(value) || | ||
(producers.set(value, (proxy = new Proxy(value, setterTraps))), proxy) | ||
: value; | ||
}, | ||
@@ -440,3 +514,3 @@ set(target, property, value) { | ||
if (!(proxy = producers.get(state))) { | ||
producers.set(state, proxy = new Proxy(state, setterTraps)); | ||
producers.set(state, (proxy = new Proxy(state, setterTraps))); | ||
} | ||
@@ -453,4 +527,4 @@ fn(proxy); | ||
hooks: DevHooks | ||
} ; | ||
}; | ||
export { $RAW, DEV, createMutable, createStore, modifyMutable, produce, reconcile, unwrap }; |
const $RAW = Symbol("state-raw"); | ||
function isWrappable(obj) { | ||
return obj != null && typeof obj === "object" && (Object.getPrototypeOf(obj) === Object.prototype || Array.isArray(obj)); | ||
return ( | ||
obj != null && | ||
typeof obj === "object" && | ||
(Object.getPrototypeOf(obj) === Object.prototype || Array.isArray(obj)) | ||
); | ||
} | ||
@@ -52,7 +56,3 @@ function unwrap(item) { | ||
} else if (isArray && partType === "object") { | ||
const { | ||
from = 0, | ||
to = current.length - 1, | ||
by = 1 | ||
} = part; | ||
const { from = 0, to = current.length - 1, by = 1 } = part; | ||
for (let i = from; i <= to; i += by) { | ||
@@ -75,3 +75,3 @@ updatePath(current, [i].concat(path), traversed); | ||
if (part === undefined && value == undefined) return; | ||
if (part === undefined || isWrappable(next) && isWrappable(value) && !Array.isArray(value)) { | ||
if (part === undefined || (isWrappable(next) && isWrappable(value) && !Array.isArray(value))) { | ||
mergeStoreNode(next, value); | ||
@@ -113,2 +113,13 @@ } else setProperty(current, part, value); | ||
export { $RAW, DEV, createMutable, createStore, isWrappable, produce, reconcile, setProperty, unwrap, updatePath }; | ||
export { | ||
$RAW, | ||
DEV, | ||
createMutable, | ||
createStore, | ||
isWrappable, | ||
produce, | ||
reconcile, | ||
setProperty, | ||
unwrap, | ||
updatePath | ||
}; |
@@ -1,5 +0,6 @@ | ||
import { $PROXY, $TRACK, getListener, batch, createSignal } from 'solid-js'; | ||
import { $PROXY, $TRACK, getListener, batch, createSignal } from "solid-js"; | ||
const $RAW = Symbol("store-raw"), | ||
$NODE = Symbol("store-node"); | ||
$NODE = Symbol("store-node"), | ||
$HAS = Symbol("store-has"); | ||
function wrap$1(value) { | ||
@@ -9,3 +10,3 @@ let p = value[$PROXY]; | ||
Object.defineProperty(value, $PROXY, { | ||
value: p = new Proxy(value, proxyTraps$1) | ||
value: (p = new Proxy(value, proxyTraps$1)) | ||
}); | ||
@@ -30,10 +31,18 @@ if (!Array.isArray(value)) { | ||
let proto; | ||
return obj != null && typeof obj === "object" && (obj[$PROXY] || !(proto = Object.getPrototypeOf(obj)) || proto === Object.prototype || Array.isArray(obj)); | ||
return ( | ||
obj != null && | ||
typeof obj === "object" && | ||
(obj[$PROXY] || | ||
!(proto = Object.getPrototypeOf(obj)) || | ||
proto === Object.prototype || | ||
Array.isArray(obj)) | ||
); | ||
} | ||
function unwrap(item, set = new Set()) { | ||
let result, unwrapped, v, prop; | ||
if (result = item != null && item[$RAW]) return result; | ||
if ((result = item != null && item[$RAW])) return result; | ||
if (!isWrappable(item) || set.has(item)) return item; | ||
if (Array.isArray(item)) { | ||
if (Object.isFrozen(item)) item = item.slice(0);else set.add(item); | ||
if (Object.isFrozen(item)) item = item.slice(0); | ||
else set.add(item); | ||
for (let i = 0, l = item.length; i < l; i++) { | ||
@@ -44,3 +53,4 @@ v = item[i]; | ||
} else { | ||
if (Object.isFrozen(item)) item = Object.assign({}, item);else set.add(item); | ||
if (Object.isFrozen(item)) item = Object.assign({}, item); | ||
else set.add(item); | ||
const keys = Object.keys(item), | ||
@@ -57,15 +67,23 @@ desc = Object.getOwnPropertyDescriptors(item); | ||
} | ||
function getDataNodes(target) { | ||
let nodes = target[$NODE]; | ||
if (!nodes) Object.defineProperty(target, $NODE, { | ||
value: nodes = Object.create(null) | ||
}); | ||
function getNodes(target, symbol) { | ||
let nodes = target[symbol]; | ||
if (!nodes) | ||
Object.defineProperty(target, symbol, { | ||
value: (nodes = Object.create(null)) | ||
}); | ||
return nodes; | ||
} | ||
function getDataNode(nodes, property, value) { | ||
return nodes[property] || (nodes[property] = createDataNode(value)); | ||
function getNode(nodes, property, value) { | ||
if (nodes[property]) return nodes[property]; | ||
const [s, set] = createSignal(value, { | ||
equals: false, | ||
internal: true | ||
}); | ||
s.$ = set; | ||
return (nodes[property] = s); | ||
} | ||
function proxyDescriptor$1(target, property) { | ||
const desc = Reflect.getOwnPropertyDescriptor(target, property); | ||
if (!desc || desc.get || !desc.configurable || property === $PROXY || property === $NODE) return desc; | ||
if (!desc || desc.get || !desc.configurable || property === $PROXY || property === $NODE) | ||
return desc; | ||
delete desc.value; | ||
@@ -77,6 +95,3 @@ delete desc.writable; | ||
function trackSelf(target) { | ||
if (getListener()) { | ||
const nodes = getDataNodes(target); | ||
(nodes._ || (nodes._ = createDataNode()))(); | ||
} | ||
getListener() && getNode(getNodes(target, $NODE), "_")(); | ||
} | ||
@@ -87,10 +102,2 @@ function ownKeys(target) { | ||
} | ||
function createDataNode(value) { | ||
const [s, set] = createSignal(value, { | ||
equals: false, | ||
internal: true | ||
}); | ||
s.$ = set; | ||
return s; | ||
} | ||
const proxyTraps$1 = { | ||
@@ -104,9 +111,14 @@ get(target, property, receiver) { | ||
} | ||
const nodes = getDataNodes(target); | ||
const nodes = getNodes(target, $NODE); | ||
const tracked = nodes[property]; | ||
let value = tracked ? tracked() : target[property]; | ||
if (property === $NODE || property === "__proto__") return value; | ||
if (property === $NODE || property === $HAS || property === "__proto__") return value; | ||
if (!tracked) { | ||
const desc = Object.getOwnPropertyDescriptor(target, property); | ||
if (getListener() && (typeof value !== "function" || target.hasOwnProperty(property)) && !(desc && desc.get)) value = getDataNode(nodes, property, value)(); | ||
if ( | ||
getListener() && | ||
(typeof value !== "function" || target.hasOwnProperty(property)) && | ||
!(desc && desc.get) | ||
) | ||
value = getNode(nodes, property, value)(); | ||
} | ||
@@ -116,4 +128,12 @@ return isWrappable(value) ? wrap$1(value) : value; | ||
has(target, property) { | ||
if (property === $RAW || property === $PROXY || property === $TRACK || property === $NODE || property === "__proto__") return true; | ||
this.get(target, property, target); | ||
if ( | ||
property === $RAW || | ||
property === $PROXY || | ||
property === $TRACK || | ||
property === $NODE || | ||
property === $HAS || | ||
property === "__proto__" | ||
) | ||
return true; | ||
getListener() && getNode(getNodes(target, $HAS), property)(); | ||
return property in target; | ||
@@ -134,9 +154,15 @@ }, | ||
len = state.length; | ||
if (value === undefined) delete state[property];else state[property] = value; | ||
let nodes = getDataNodes(state), | ||
if (value === undefined) { | ||
delete state[property]; | ||
if (state[$HAS] && state[$HAS][property] && prev !== undefined) state[$HAS][property].$(); | ||
} else { | ||
state[property] = value; | ||
if (state[$HAS] && state[$HAS][property] && prev === undefined) state[$HAS][property].$(); | ||
} | ||
let nodes = getNodes(state, $NODE), | ||
node; | ||
if (node = getDataNode(nodes, property, prev)) node.$(() => value); | ||
if ((node = getNode(nodes, property, prev))) node.$(() => value); | ||
if (Array.isArray(state) && state.length !== len) { | ||
for (let i = state.length; i < len; i++) (node = nodes[i]) && node.$(); | ||
(node = getDataNode(nodes, "length", len)) && node.$(state.length); | ||
(node = getNode(nodes, "length", len)) && node.$(state.length); | ||
} | ||
@@ -184,7 +210,3 @@ (node = nodes._) && node.$(); | ||
} else if (isArray && partType === "object") { | ||
const { | ||
from = 0, | ||
to = current.length - 1, | ||
by = 1 | ||
} = part; | ||
const { from = 0, to = current.length - 1, by = 1 } = part; | ||
for (let i = from; i <= to; i += by) { | ||
@@ -208,3 +230,3 @@ updatePath(current, [i].concat(path), traversed); | ||
value = unwrap(value); | ||
if (part === undefined || isWrappable(prev) && isWrappable(value) && !Array.isArray(value)) { | ||
if (part === undefined || (isWrappable(prev) && isWrappable(value) && !Array.isArray(value))) { | ||
mergeStoreNode(prev, value); | ||
@@ -219,3 +241,5 @@ } else setProperty(current, part, value); | ||
batch(() => { | ||
isArray && args.length === 1 ? updateArray(unwrappedStore, args[0]) : updatePath(unwrappedStore, args); | ||
isArray && args.length === 1 | ||
? updateArray(unwrappedStore, args[0]) | ||
: updatePath(unwrappedStore, args); | ||
}); | ||
@@ -228,7 +252,15 @@ } | ||
const desc = Reflect.getOwnPropertyDescriptor(target, property); | ||
if (!desc || desc.get || desc.set || !desc.configurable || property === $PROXY || property === $NODE) return desc; | ||
if ( | ||
!desc || | ||
desc.get || | ||
desc.set || | ||
!desc.configurable || | ||
property === $PROXY || | ||
property === $NODE | ||
) | ||
return desc; | ||
delete desc.value; | ||
delete desc.writable; | ||
desc.get = () => target[$PROXY][property]; | ||
desc.set = v => target[$PROXY][property] = v; | ||
desc.set = v => (target[$PROXY][property] = v); | ||
return desc; | ||
@@ -244,10 +276,12 @@ } | ||
} | ||
const nodes = getDataNodes(target); | ||
const nodes = getNodes(target, $NODE); | ||
const tracked = nodes[property]; | ||
let value = tracked ? tracked() : target[property]; | ||
if (property === $NODE || property === "__proto__") return value; | ||
if (property === $NODE || property === $HAS || property === "__proto__") return value; | ||
if (!tracked) { | ||
const desc = Object.getOwnPropertyDescriptor(target, property); | ||
const isFunction = typeof value === "function"; | ||
if (getListener() && (!isFunction || target.hasOwnProperty(property)) && !(desc && desc.get)) value = getDataNode(nodes, property, value)();else if (value != null && isFunction && value === Array.prototype[property]) { | ||
if (getListener() && (!isFunction || target.hasOwnProperty(property)) && !(desc && desc.get)) | ||
value = getNode(nodes, property, value)(); | ||
else if (value != null && isFunction && value === Array.prototype[property]) { | ||
return (...args) => batch(() => Array.prototype[property].apply(receiver, args)); | ||
@@ -259,4 +293,12 @@ } | ||
has(target, property) { | ||
if (property === $RAW || property === $PROXY || property === $TRACK || property === $NODE || property === "__proto__") return true; | ||
this.get(target, property, target); | ||
if ( | ||
property === $RAW || | ||
property === $PROXY || | ||
property === $TRACK || | ||
property === $NODE || | ||
property === $HAS || | ||
property === "__proto__" | ||
) | ||
return true; | ||
getListener() && getNode(getNodes(target, $HAS), property)(); | ||
return property in target; | ||
@@ -279,3 +321,3 @@ }, | ||
Object.defineProperty(value, $PROXY, { | ||
value: p = new Proxy(value, proxyTraps) | ||
value: (p = new Proxy(value, proxyTraps)) | ||
}); | ||
@@ -316,3 +358,6 @@ const keys = Object.keys(value), | ||
if (target === previous) return; | ||
if (property !== $ROOT && (!isWrappable(target) || !isWrappable(previous) || key && target[key] !== previous[key])) { | ||
if ( | ||
property !== $ROOT && | ||
(!isWrappable(target) || !isWrappable(previous) || (key && target[key] !== previous[key])) | ||
) { | ||
setProperty(parent, property, target); | ||
@@ -322,5 +367,15 @@ return; | ||
if (Array.isArray(target)) { | ||
if (target.length && previous.length && (!merge || key && target[0] && target[0][key] != null)) { | ||
if ( | ||
target.length && | ||
previous.length && | ||
(!merge || (key && target[0] && target[0][key] != null)) | ||
) { | ||
let i, j, start, end, newEnd, item, newIndicesNext, keyVal; | ||
for (start = 0, end = Math.min(previous.length, target.length); start < end && (previous[start] === target[start] || key && previous[start] && target[start] && previous[start][key] === target[start][key]); start++) { | ||
for ( | ||
start = 0, end = Math.min(previous.length, target.length); | ||
start < end && | ||
(previous[start] === target[start] || | ||
(key && previous[start] && target[start] && previous[start][key] === target[start][key])); | ||
start++ | ||
) { | ||
applyState(target[start], previous, start, merge, key); | ||
@@ -330,3 +385,10 @@ } | ||
newIndices = new Map(); | ||
for (end = previous.length - 1, newEnd = target.length - 1; end >= start && newEnd >= start && (previous[end] === target[newEnd] || key && previous[start] && target[start] && previous[end][key] === target[newEnd][key]); end--, newEnd--) { | ||
for ( | ||
end = previous.length - 1, newEnd = target.length - 1; | ||
end >= start && | ||
newEnd >= start && | ||
(previous[end] === target[newEnd] || | ||
(key && previous[start] && target[start] && previous[end][key] === target[newEnd][key])); | ||
end--, newEnd-- | ||
) { | ||
temp[newEnd] = previous[end]; | ||
@@ -385,12 +447,15 @@ } | ||
function reconcile(value, options = {}) { | ||
const { | ||
merge, | ||
key = "id" | ||
} = options, | ||
const { merge, key = "id" } = options, | ||
v = unwrap(value); | ||
return state => { | ||
if (!isWrappable(state) || !isWrappable(v)) return v; | ||
const res = applyState(v, { | ||
[$ROOT]: state | ||
}, $ROOT, merge, key); | ||
const res = applyState( | ||
v, | ||
{ | ||
[$ROOT]: state | ||
}, | ||
$ROOT, | ||
merge, | ||
key | ||
); | ||
return res === undefined ? state : res; | ||
@@ -405,3 +470,6 @@ }; | ||
let proxy; | ||
return isWrappable(value) ? producers.get(value) || (producers.set(value, proxy = new Proxy(value, setterTraps)), proxy) : value; | ||
return isWrappable(value) | ||
? producers.get(value) || | ||
(producers.set(value, (proxy = new Proxy(value, setterTraps))), proxy) | ||
: value; | ||
}, | ||
@@ -422,3 +490,3 @@ set(target, property, value) { | ||
if (!(proxy = producers.get(state))) { | ||
producers.set(state, proxy = new Proxy(state, setterTraps)); | ||
producers.set(state, (proxy = new Proxy(state, setterTraps))); | ||
} | ||
@@ -425,0 +493,0 @@ fn(proxy); |
export { $RAW, createStore, unwrap } from "./store.js"; | ||
export type { ArrayFilterFn, DeepMutable, DeepReadonly, NotWrappable, Part, SetStoreFunction, SolidStore, Store, StoreNode, StorePathRange, StoreSetter } from "./store.js"; | ||
export type { | ||
ArrayFilterFn, | ||
DeepMutable, | ||
DeepReadonly, | ||
NotWrappable, | ||
Part, | ||
SetStoreFunction, | ||
SolidStore, | ||
Store, | ||
StoreNode, | ||
StorePathRange, | ||
StoreSetter | ||
} from "./store.js"; | ||
export * from "./mutable.js"; | ||
export * from "./modifiers.js"; | ||
import { $NODE, isWrappable } from "./store.js"; | ||
export declare const DEV: { | ||
readonly $NODE: typeof $NODE; | ||
readonly isWrappable: typeof isWrappable; | ||
readonly hooks: { | ||
export declare const DEV: | ||
| { | ||
readonly $NODE: typeof $NODE; | ||
readonly isWrappable: typeof isWrappable; | ||
readonly hooks: { | ||
onStoreNodeUpdate: import("./store.js").OnStoreNodeUpdate | null; | ||
}; | ||
} | undefined; | ||
}; | ||
} | ||
| undefined; |
export type ReconcileOptions = { | ||
key?: string | null; | ||
merge?: boolean; | ||
key?: string | null; | ||
merge?: boolean; | ||
}; | ||
export declare function reconcile<T extends U, U>(value: T, options?: ReconcileOptions): (state: U) => T; | ||
export declare function reconcile<T extends U, U>( | ||
value: T, | ||
options?: ReconcileOptions | ||
): (state: U) => T; | ||
export declare function produce<T>(fn: (state: T) => void): (state: T) => T; |
import { StoreNode } from "./store.js"; | ||
export declare function createMutable<T extends StoreNode>(state: T, options?: { | ||
export declare function createMutable<T extends StoreNode>( | ||
state: T, | ||
options?: { | ||
name?: string; | ||
}): T; | ||
} | ||
): T; | ||
export declare function modifyMutable<T>(state: T, modifier: (state: T) => T): void; |
@@ -5,3 +5,8 @@ import type { SetStoreFunction, Store } from "./store.js"; | ||
export declare function unwrap<T>(item: T): T; | ||
export declare function setProperty(state: any, property: PropertyKey, value: any, force?: boolean): void; | ||
export declare function setProperty( | ||
state: any, | ||
property: PropertyKey, | ||
value: any, | ||
force?: boolean | ||
): void; | ||
export declare function updatePath(current: any, path: any[], traversed?: PropertyKey[]): void; | ||
@@ -11,8 +16,11 @@ export declare function createStore<T>(state: T | Store<T>): [Store<T>, SetStoreFunction<T>]; | ||
type ReconcileOptions = { | ||
key?: string | null; | ||
merge?: boolean; | ||
key?: string | null; | ||
merge?: boolean; | ||
}; | ||
export declare function reconcile<T extends U, U extends object>(value: T, options?: ReconcileOptions): (state: U) => T; | ||
export declare function reconcile<T extends U, U extends object>( | ||
value: T, | ||
options?: ReconcileOptions | ||
): (state: U) => T; | ||
export declare function produce<T>(fn: (state: T) => void): (state: T) => T; | ||
export declare const DEV: undefined; | ||
export {}; |
@@ -1,20 +0,33 @@ | ||
export declare const $RAW: unique symbol, $NODE: unique symbol; | ||
export declare const $RAW: unique symbol, $NODE: unique symbol, $HAS: unique symbol; | ||
export declare const DevHooks: { | ||
onStoreNodeUpdate: OnStoreNodeUpdate | null; | ||
onStoreNodeUpdate: OnStoreNodeUpdate | null; | ||
}; | ||
type DataNode = { | ||
(): any; | ||
$(value?: any): void; | ||
(): any; | ||
$(value?: any): void; | ||
}; | ||
type DataNodes = Record<PropertyKey, DataNode | undefined>; | ||
export type OnStoreNodeUpdate = (state: StoreNode, property: PropertyKey, value: StoreNode | NotWrappable, prev: StoreNode | NotWrappable) => void; | ||
export type OnStoreNodeUpdate = ( | ||
state: StoreNode, | ||
property: PropertyKey, | ||
value: StoreNode | NotWrappable, | ||
prev: StoreNode | NotWrappable | ||
) => void; | ||
export interface StoreNode { | ||
[$NODE]?: DataNodes; | ||
[key: PropertyKey]: any; | ||
[$NODE]?: DataNodes; | ||
[key: PropertyKey]: any; | ||
} | ||
export declare namespace SolidStore { | ||
interface Unwrappable { | ||
} | ||
interface Unwrappable {} | ||
} | ||
export type NotWrappable = string | number | bigint | symbol | boolean | Function | null | undefined | SolidStore.Unwrappable[keyof SolidStore.Unwrappable]; | ||
export type NotWrappable = | ||
| string | ||
| number | ||
| bigint | ||
| symbol | ||
| boolean | ||
| Function | ||
| null | ||
| undefined | ||
| SolidStore.Unwrappable[keyof SolidStore.Unwrappable]; | ||
export type Store<T> = T; | ||
@@ -34,63 +47,194 @@ export declare function isWrappable<T>(obj: T | NotWrappable): obj is T; | ||
export declare function unwrap<T>(item: T, set?: Set<unknown>): T; | ||
export declare function getDataNodes(target: StoreNode): DataNodes; | ||
export declare function getDataNode(nodes: DataNodes, property: PropertyKey, value: any): DataNode; | ||
export declare function proxyDescriptor(target: StoreNode, property: PropertyKey): TypedPropertyDescriptor<any> | undefined; | ||
export declare function getNodes(target: StoreNode, symbol: typeof $NODE | typeof $HAS): DataNodes; | ||
export declare function getNode(nodes: DataNodes, property: PropertyKey, value?: any): DataNode; | ||
export declare function proxyDescriptor( | ||
target: StoreNode, | ||
property: PropertyKey | ||
): TypedPropertyDescriptor<any> | undefined; | ||
export declare function trackSelf(target: StoreNode): void; | ||
export declare function ownKeys(target: StoreNode): (string | symbol)[]; | ||
export declare function setProperty(state: StoreNode, property: PropertyKey, value: any, deleting?: boolean): void; | ||
export declare function updatePath(current: StoreNode, path: any[], traversed?: PropertyKey[]): void; | ||
export declare function setProperty( | ||
state: StoreNode, | ||
property: PropertyKey, | ||
value: any, | ||
deleting?: boolean | ||
): void; | ||
export declare function updatePath( | ||
current: StoreNode, | ||
path: any[], | ||
traversed?: PropertyKey[] | ||
): void; | ||
/** @deprecated */ | ||
export type DeepReadonly<T> = 0 extends 1 & T ? T : T extends NotWrappable ? T : { | ||
readonly [K in keyof T]: DeepReadonly<T[K]>; | ||
}; | ||
export type DeepReadonly<T> = 0 extends 1 & T | ||
? T | ||
: T extends NotWrappable | ||
? T | ||
: { | ||
readonly [K in keyof T]: DeepReadonly<T[K]>; | ||
}; | ||
/** @deprecated */ | ||
export type DeepMutable<T> = 0 extends 1 & T ? T : T extends NotWrappable ? T : { | ||
-readonly [K in keyof T]: DeepMutable<T[K]>; | ||
}; | ||
export type CustomPartial<T> = T extends readonly unknown[] ? "0" extends keyof T ? { | ||
[K in Extract<keyof T, `${number}`>]?: T[K]; | ||
} : { | ||
[x: number]: T[number]; | ||
} : Partial<T>; | ||
export type DeepMutable<T> = 0 extends 1 & T | ||
? T | ||
: T extends NotWrappable | ||
? T | ||
: { | ||
-readonly [K in keyof T]: DeepMutable<T[K]>; | ||
}; | ||
export type CustomPartial<T> = T extends readonly unknown[] | ||
? "0" extends keyof T | ||
? { | ||
[K in Extract<keyof T, `${number}`>]?: T[K]; | ||
} | ||
: { | ||
[x: number]: T[number]; | ||
} | ||
: Partial<T>; | ||
export type PickMutable<T> = { | ||
[K in keyof T as (<U>() => U extends { | ||
[V in K]: T[V]; | ||
} ? 1 : 2) extends <U>() => U extends { | ||
-readonly [V in K]: T[V]; | ||
} ? 1 : 2 ? K : never]: T[K]; | ||
[K in keyof T as (<U>() => U extends { | ||
[V in K]: T[V]; | ||
} | ||
? 1 | ||
: 2) extends <U>() => U extends { | ||
-readonly [V in K]: T[V]; | ||
} | ||
? 1 | ||
: 2 | ||
? K | ||
: never]: T[K]; | ||
}; | ||
export type StorePathRange = { | ||
from?: number; | ||
to?: number; | ||
by?: number; | ||
from?: number; | ||
to?: number; | ||
by?: number; | ||
}; | ||
export type ArrayFilterFn<T> = (item: T, index: number) => boolean; | ||
export type StoreSetter<T, U extends PropertyKey[] = []> = T | CustomPartial<T> | ((prevState: T, traversed: U) => T | CustomPartial<T>); | ||
export type Part<T, K extends KeyOf<T> = KeyOf<T>> = K | ([K] extends [never] ? never : readonly K[]) | ([T] extends [readonly unknown[]] ? ArrayFilterFn<T[number]> | StorePathRange : never); | ||
export type StoreSetter<T, U extends PropertyKey[] = []> = | ||
| T | ||
| CustomPartial<T> | ||
| ((prevState: T, traversed: U) => T | CustomPartial<T>); | ||
export type Part<T, K extends KeyOf<T> = KeyOf<T>> = | ||
| K | ||
| ([K] extends [never] ? never : readonly K[]) | ||
| ([T] extends [readonly unknown[]] ? ArrayFilterFn<T[number]> | StorePathRange : never); | ||
type W<T> = Exclude<T, NotWrappable>; | ||
type KeyOf<T> = number extends keyof T ? 0 extends 1 & T ? keyof T : [T] extends [never] ? never : [ | ||
T | ||
] extends [readonly unknown[]] ? number : keyof T : keyof T; | ||
type KeyOf<T> = number extends keyof T | ||
? 0 extends 1 & T | ||
? keyof T | ||
: [T] extends [never] | ||
? never | ||
: [T] extends [readonly unknown[]] | ||
? number | ||
: keyof T | ||
: keyof T; | ||
type MutableKeyOf<T> = KeyOf<T> & keyof PickMutable<T>; | ||
type Rest<T, U extends PropertyKey[], K extends KeyOf<T> = KeyOf<T>> = [T] extends [never] ? never : K extends MutableKeyOf<T> ? [Part<T, K>, ...RestSetterOrContinue<T[K], [K, ...U]>] : K extends KeyOf<T> ? [Part<T, K>, ...RestContinue<T[K], [K, ...U]>] : never; | ||
type RestContinue<T, U extends PropertyKey[]> = 0 extends 1 & T ? [...Part<any>[], StoreSetter<any, PropertyKey[]>] : Rest<W<T>, U>; | ||
type Rest<T, U extends PropertyKey[], K extends KeyOf<T> = KeyOf<T>> = [T] extends [never] | ||
? never | ||
: K extends MutableKeyOf<T> | ||
? [Part<T, K>, ...RestSetterOrContinue<T[K], [K, ...U]>] | ||
: K extends KeyOf<T> | ||
? [Part<T, K>, ...RestContinue<T[K], [K, ...U]>] | ||
: never; | ||
type RestContinue<T, U extends PropertyKey[]> = 0 extends 1 & T | ||
? [...Part<any>[], StoreSetter<any, PropertyKey[]>] | ||
: Rest<W<T>, U>; | ||
type RestSetterOrContinue<T, U extends PropertyKey[]> = [StoreSetter<T, U>] | RestContinue<T, U>; | ||
export interface SetStoreFunction<T> { | ||
<K1 extends KeyOf<W<T>>, K2 extends KeyOf<W<W<T>[K1]>>, K3 extends KeyOf<W<W<W<T>[K1]>[K2]>>, K4 extends KeyOf<W<W<W<W<T>[K1]>[K2]>[K3]>>, K5 extends KeyOf<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>>, K6 extends KeyOf<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>>, K7 extends MutableKeyOf<W<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6]>>>(k1: Part<W<T>, K1>, k2: Part<W<W<T>[K1]>, K2>, k3: Part<W<W<W<T>[K1]>[K2]>, K3>, k4: Part<W<W<W<W<T>[K1]>[K2]>[K3]>, K4>, k5: Part<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>, K5>, k6: Part<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>, K6>, k7: Part<W<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6]>, K7>, setter: StoreSetter<W<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6]>[K7], [ | ||
K7, | ||
K6, | ||
K5, | ||
K4, | ||
K3, | ||
K2, | ||
K1 | ||
]>): void; | ||
<K1 extends KeyOf<W<T>>, K2 extends KeyOf<W<W<T>[K1]>>, K3 extends KeyOf<W<W<W<T>[K1]>[K2]>>, K4 extends KeyOf<W<W<W<W<T>[K1]>[K2]>[K3]>>, K5 extends KeyOf<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>>, K6 extends MutableKeyOf<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>>>(k1: Part<W<T>, K1>, k2: Part<W<W<T>[K1]>, K2>, k3: Part<W<W<W<T>[K1]>[K2]>, K3>, k4: Part<W<W<W<W<T>[K1]>[K2]>[K3]>, K4>, k5: Part<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>, K5>, k6: Part<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>, K6>, setter: StoreSetter<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6], [K6, K5, K4, K3, K2, K1]>): void; | ||
<K1 extends KeyOf<W<T>>, K2 extends KeyOf<W<W<T>[K1]>>, K3 extends KeyOf<W<W<W<T>[K1]>[K2]>>, K4 extends KeyOf<W<W<W<W<T>[K1]>[K2]>[K3]>>, K5 extends MutableKeyOf<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>>>(k1: Part<W<T>, K1>, k2: Part<W<W<T>[K1]>, K2>, k3: Part<W<W<W<T>[K1]>[K2]>, K3>, k4: Part<W<W<W<W<T>[K1]>[K2]>[K3]>, K4>, k5: Part<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>, K5>, setter: StoreSetter<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5], [K5, K4, K3, K2, K1]>): void; | ||
<K1 extends KeyOf<W<T>>, K2 extends KeyOf<W<W<T>[K1]>>, K3 extends KeyOf<W<W<W<T>[K1]>[K2]>>, K4 extends MutableKeyOf<W<W<W<W<T>[K1]>[K2]>[K3]>>>(k1: Part<W<T>, K1>, k2: Part<W<W<T>[K1]>, K2>, k3: Part<W<W<W<T>[K1]>[K2]>, K3>, k4: Part<W<W<W<W<T>[K1]>[K2]>[K3]>, K4>, setter: StoreSetter<W<W<W<W<T>[K1]>[K2]>[K3]>[K4], [K4, K3, K2, K1]>): void; | ||
<K1 extends KeyOf<W<T>>, K2 extends KeyOf<W<W<T>[K1]>>, K3 extends MutableKeyOf<W<W<W<T>[K1]>[K2]>>>(k1: Part<W<T>, K1>, k2: Part<W<W<T>[K1]>, K2>, k3: Part<W<W<W<T>[K1]>[K2]>, K3>, setter: StoreSetter<W<W<W<T>[K1]>[K2]>[K3], [K3, K2, K1]>): void; | ||
<K1 extends KeyOf<W<T>>, K2 extends MutableKeyOf<W<W<T>[K1]>>>(k1: Part<W<T>, K1>, k2: Part<W<W<T>[K1]>, K2>, setter: StoreSetter<W<W<T>[K1]>[K2], [K2, K1]>): void; | ||
<K1 extends MutableKeyOf<W<T>>>(k1: Part<W<T>, K1>, setter: StoreSetter<W<T>[K1], [K1]>): void; | ||
(setter: StoreSetter<T, []>): void; | ||
<K1 extends KeyOf<W<T>>, K2 extends KeyOf<W<W<T>[K1]>>, K3 extends KeyOf<W<W<W<T>[K1]>[K2]>>, K4 extends KeyOf<W<W<W<W<T>[K1]>[K2]>[K3]>>, K5 extends KeyOf<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>>, K6 extends KeyOf<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>>, K7 extends KeyOf<W<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6]>>>(k1: Part<W<T>, K1>, k2: Part<W<W<T>[K1]>, K2>, k3: Part<W<W<W<T>[K1]>[K2]>, K3>, k4: Part<W<W<W<W<T>[K1]>[K2]>[K3]>, K4>, k5: Part<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>, K5>, k6: Part<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>, K6>, k7: Part<W<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6]>, K7>, ...rest: Rest<W<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6]>[K7], [K7, K6, K5, K4, K3, K2, K1]>): void; | ||
< | ||
K1 extends KeyOf<W<T>>, | ||
K2 extends KeyOf<W<W<T>[K1]>>, | ||
K3 extends KeyOf<W<W<W<T>[K1]>[K2]>>, | ||
K4 extends KeyOf<W<W<W<W<T>[K1]>[K2]>[K3]>>, | ||
K5 extends KeyOf<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>>, | ||
K6 extends KeyOf<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>>, | ||
K7 extends MutableKeyOf<W<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6]>> | ||
>( | ||
k1: Part<W<T>, K1>, | ||
k2: Part<W<W<T>[K1]>, K2>, | ||
k3: Part<W<W<W<T>[K1]>[K2]>, K3>, | ||
k4: Part<W<W<W<W<T>[K1]>[K2]>[K3]>, K4>, | ||
k5: Part<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>, K5>, | ||
k6: Part<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>, K6>, | ||
k7: Part<W<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6]>, K7>, | ||
setter: StoreSetter< | ||
W<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6]>[K7], | ||
[K7, K6, K5, K4, K3, K2, K1] | ||
> | ||
): void; | ||
< | ||
K1 extends KeyOf<W<T>>, | ||
K2 extends KeyOf<W<W<T>[K1]>>, | ||
K3 extends KeyOf<W<W<W<T>[K1]>[K2]>>, | ||
K4 extends KeyOf<W<W<W<W<T>[K1]>[K2]>[K3]>>, | ||
K5 extends KeyOf<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>>, | ||
K6 extends MutableKeyOf<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>> | ||
>( | ||
k1: Part<W<T>, K1>, | ||
k2: Part<W<W<T>[K1]>, K2>, | ||
k3: Part<W<W<W<T>[K1]>[K2]>, K3>, | ||
k4: Part<W<W<W<W<T>[K1]>[K2]>[K3]>, K4>, | ||
k5: Part<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>, K5>, | ||
k6: Part<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>, K6>, | ||
setter: StoreSetter<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6], [K6, K5, K4, K3, K2, K1]> | ||
): void; | ||
< | ||
K1 extends KeyOf<W<T>>, | ||
K2 extends KeyOf<W<W<T>[K1]>>, | ||
K3 extends KeyOf<W<W<W<T>[K1]>[K2]>>, | ||
K4 extends KeyOf<W<W<W<W<T>[K1]>[K2]>[K3]>>, | ||
K5 extends MutableKeyOf<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>> | ||
>( | ||
k1: Part<W<T>, K1>, | ||
k2: Part<W<W<T>[K1]>, K2>, | ||
k3: Part<W<W<W<T>[K1]>[K2]>, K3>, | ||
k4: Part<W<W<W<W<T>[K1]>[K2]>[K3]>, K4>, | ||
k5: Part<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>, K5>, | ||
setter: StoreSetter<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5], [K5, K4, K3, K2, K1]> | ||
): void; | ||
< | ||
K1 extends KeyOf<W<T>>, | ||
K2 extends KeyOf<W<W<T>[K1]>>, | ||
K3 extends KeyOf<W<W<W<T>[K1]>[K2]>>, | ||
K4 extends MutableKeyOf<W<W<W<W<T>[K1]>[K2]>[K3]>> | ||
>( | ||
k1: Part<W<T>, K1>, | ||
k2: Part<W<W<T>[K1]>, K2>, | ||
k3: Part<W<W<W<T>[K1]>[K2]>, K3>, | ||
k4: Part<W<W<W<W<T>[K1]>[K2]>[K3]>, K4>, | ||
setter: StoreSetter<W<W<W<W<T>[K1]>[K2]>[K3]>[K4], [K4, K3, K2, K1]> | ||
): void; | ||
< | ||
K1 extends KeyOf<W<T>>, | ||
K2 extends KeyOf<W<W<T>[K1]>>, | ||
K3 extends MutableKeyOf<W<W<W<T>[K1]>[K2]>> | ||
>( | ||
k1: Part<W<T>, K1>, | ||
k2: Part<W<W<T>[K1]>, K2>, | ||
k3: Part<W<W<W<T>[K1]>[K2]>, K3>, | ||
setter: StoreSetter<W<W<W<T>[K1]>[K2]>[K3], [K3, K2, K1]> | ||
): void; | ||
<K1 extends KeyOf<W<T>>, K2 extends MutableKeyOf<W<W<T>[K1]>>>( | ||
k1: Part<W<T>, K1>, | ||
k2: Part<W<W<T>[K1]>, K2>, | ||
setter: StoreSetter<W<W<T>[K1]>[K2], [K2, K1]> | ||
): void; | ||
<K1 extends MutableKeyOf<W<T>>>(k1: Part<W<T>, K1>, setter: StoreSetter<W<T>[K1], [K1]>): void; | ||
(setter: StoreSetter<T, []>): void; | ||
< | ||
K1 extends KeyOf<W<T>>, | ||
K2 extends KeyOf<W<W<T>[K1]>>, | ||
K3 extends KeyOf<W<W<W<T>[K1]>[K2]>>, | ||
K4 extends KeyOf<W<W<W<W<T>[K1]>[K2]>[K3]>>, | ||
K5 extends KeyOf<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>>, | ||
K6 extends KeyOf<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>>, | ||
K7 extends KeyOf<W<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6]>> | ||
>( | ||
k1: Part<W<T>, K1>, | ||
k2: Part<W<W<T>[K1]>, K2>, | ||
k3: Part<W<W<W<T>[K1]>[K2]>, K3>, | ||
k4: Part<W<W<W<W<T>[K1]>[K2]>[K3]>, K4>, | ||
k5: Part<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>, K5>, | ||
k6: Part<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>, K6>, | ||
k7: Part<W<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6]>, K7>, | ||
...rest: Rest<W<W<W<W<W<W<W<T>[K1]>[K2]>[K3]>[K4]>[K5]>[K6]>[K7], [K7, K6, K5, K4, K3, K2, K1]> | ||
): void; | ||
} | ||
@@ -102,7 +246,17 @@ /** | ||
*/ | ||
export declare function createStore<T extends object = {}>(...[store, options]: {} extends T ? [store?: T | Store<T>, options?: { | ||
name?: string; | ||
}] : [store: T | Store<T>, options?: { | ||
name?: string; | ||
}]): [get: Store<T>, set: SetStoreFunction<T>]; | ||
export declare function createStore<T extends object = {}>( | ||
...[store, options]: {} extends T | ||
? [ | ||
store?: T | Store<T>, | ||
options?: { | ||
name?: string; | ||
} | ||
] | ||
: [ | ||
store: T | Store<T>, | ||
options?: { | ||
name?: string; | ||
} | ||
] | ||
): [get: Store<T>, set: SetStoreFunction<T>]; | ||
export {}; |
@@ -1,3 +0,61 @@ | ||
export { $DEVCOMP, $PROXY, $TRACK, batch, children, createComputed, createContext, createDeferred, createEffect, createMemo, createReaction, createRenderEffect, createResource, createRoot, createSelector, createSignal, enableExternalSource, enableScheduling, equalFn, getListener, getOwner, on, onCleanup, onError, catchError, onMount, runWithOwner, startTransition, untrack, useContext, useTransition } from "./reactive/signal.js"; | ||
export type { Accessor, AccessorArray, ChildrenReturn, Context, EffectFunction, EffectOptions, InitializedResource, InitializedResourceOptions, InitializedResourceReturn, MemoOptions, NoInfer, OnEffectFunction, OnOptions, Owner, Resource, ResourceActions, ResourceFetcher, ResourceFetcherInfo, ResourceOptions, ResourceReturn, ResourceSource, ReturnTypes, Setter, Signal, SignalOptions } from "./reactive/signal.js"; | ||
export { | ||
$DEVCOMP, | ||
$PROXY, | ||
$TRACK, | ||
batch, | ||
children, | ||
createComputed, | ||
createContext, | ||
createDeferred, | ||
createEffect, | ||
createMemo, | ||
createReaction, | ||
createRenderEffect, | ||
createResource, | ||
createRoot, | ||
createSelector, | ||
createSignal, | ||
enableExternalSource, | ||
enableScheduling, | ||
equalFn, | ||
getListener, | ||
getOwner, | ||
on, | ||
onCleanup, | ||
onError, | ||
catchError, | ||
onMount, | ||
runWithOwner, | ||
startTransition, | ||
untrack, | ||
useContext, | ||
useTransition | ||
} from "./reactive/signal.js"; | ||
export type { | ||
Accessor, | ||
AccessorArray, | ||
ChildrenReturn, | ||
Context, | ||
EffectFunction, | ||
EffectOptions, | ||
InitializedResource, | ||
InitializedResourceOptions, | ||
InitializedResourceReturn, | ||
MemoOptions, | ||
NoInfer, | ||
OnEffectFunction, | ||
OnOptions, | ||
Owner, | ||
Resource, | ||
ResourceActions, | ||
ResourceFetcher, | ||
ResourceFetcherInfo, | ||
ResourceOptions, | ||
ResourceReturn, | ||
ResourceSource, | ||
ReturnTypes, | ||
Setter, | ||
Signal, | ||
SignalOptions | ||
} from "./reactive/signal.js"; | ||
export * from "./reactive/observable.js"; | ||
@@ -11,12 +69,14 @@ export * from "./reactive/scheduler.js"; | ||
import { registerGraph, writeSignal } from "./reactive/signal.js"; | ||
export declare const DEV: { | ||
readonly hooks: { | ||
export declare const DEV: | ||
| { | ||
readonly hooks: { | ||
afterUpdate: (() => void) | null; | ||
afterCreateOwner: ((owner: import("./reactive/signal.js").Owner) => void) | null; | ||
}; | ||
readonly writeSignal: typeof writeSignal; | ||
readonly registerGraph: typeof registerGraph; | ||
} | undefined; | ||
}; | ||
readonly writeSignal: typeof writeSignal; | ||
readonly registerGraph: typeof registerGraph; | ||
} | ||
| undefined; | ||
declare global { | ||
var Solid$$: boolean; | ||
var Solid$$: boolean; | ||
} |
@@ -32,5 +32,9 @@ import { Accessor } from "./signal.js"; | ||
*/ | ||
export declare function mapArray<T, U>(list: Accessor<readonly T[] | undefined | null | false>, mapFn: (v: T, i: Accessor<number>) => U, options?: { | ||
export declare function mapArray<T, U>( | ||
list: Accessor<readonly T[] | undefined | null | false>, | ||
mapFn: (v: T, i: Accessor<number>) => U, | ||
options?: { | ||
fallback?: Accessor<any>; | ||
}): () => U[]; | ||
} | ||
): () => U[]; | ||
/** | ||
@@ -43,4 +47,8 @@ * reactively maps arrays by index instead of value - underlying helper for the `<Index>` control flow | ||
*/ | ||
export declare function indexArray<T, U>(list: Accessor<readonly T[] | undefined | null | false>, mapFn: (v: Accessor<T>, i: number) => U, options?: { | ||
export declare function indexArray<T, U>( | ||
list: Accessor<readonly T[] | undefined | null | false>, | ||
mapFn: (v: Accessor<T>, i: number) => U, | ||
options?: { | ||
fallback?: Accessor<any>; | ||
}): () => U[]; | ||
} | ||
): () => U[]; |
import { Accessor, Setter } from "./signal.js"; | ||
declare global { | ||
interface SymbolConstructor { | ||
readonly observable: symbol; | ||
} | ||
interface SymbolConstructor { | ||
readonly observable: symbol; | ||
} | ||
} | ||
interface Observable<T> { | ||
subscribe(observer: ObservableObserver<T>): { | ||
unsubscribe(): void; | ||
subscribe(observer: ObservableObserver<T>): { | ||
unsubscribe(): void; | ||
}; | ||
[Symbol.observable](): Observable<T>; | ||
} | ||
export type ObservableObserver<T> = | ||
| ((v: T) => void) | ||
| { | ||
next?: (v: T) => void; | ||
error?: (v: any) => void; | ||
complete?: (v: boolean) => void; | ||
}; | ||
[Symbol.observable](): Observable<T>; | ||
} | ||
export type ObservableObserver<T> = ((v: T) => void) | { | ||
next?: (v: T) => void; | ||
error?: (v: any) => void; | ||
complete?: (v: boolean) => void; | ||
}; | ||
/** | ||
@@ -29,7 +31,13 @@ * creates a simple observable from a signal's accessor to be used with the `from` operator of observable libraries like e.g. rxjs | ||
export declare function observable<T>(input: Accessor<T>): Observable<T>; | ||
export declare function from<T>(producer: ((setter: Setter<T | undefined>) => () => void) | { | ||
subscribe: (fn: (v: T) => void) => (() => void) | { | ||
unsubscribe: () => void; | ||
}; | ||
}): Accessor<T | undefined>; | ||
export declare function from<T>( | ||
producer: | ||
| ((setter: Setter<T | undefined>) => () => void) | ||
| { | ||
subscribe: (fn: (v: T) => void) => | ||
| (() => void) | ||
| { | ||
unsubscribe: () => void; | ||
}; | ||
} | ||
): Accessor<T | undefined>; | ||
export {}; |
export interface Task { | ||
id: number; | ||
fn: ((didTimeout: boolean) => void) | null; | ||
startTime: number; | ||
expirationTime: number; | ||
id: number; | ||
fn: ((didTimeout: boolean) => void) | null; | ||
startTime: number; | ||
expirationTime: number; | ||
} | ||
export declare function requestCallback(fn: () => void, options?: { | ||
export declare function requestCallback( | ||
fn: () => void, | ||
options?: { | ||
timeout: number; | ||
}): Task; | ||
} | ||
): Task; | ||
export declare function cancelCallback(task: Task): void; |
@@ -36,53 +36,56 @@ /** | ||
export declare const DevHooks: { | ||
afterUpdate: (() => void) | null; | ||
afterCreateOwner: ((owner: Owner) => void) | null; | ||
afterUpdate: (() => void) | null; | ||
afterCreateOwner: ((owner: Owner) => void) | null; | ||
}; | ||
export type ComputationState = 0 | 1 | 2; | ||
export interface SourceMapValue { | ||
value: unknown; | ||
name?: string; | ||
graph?: Owner; | ||
value: unknown; | ||
name?: string; | ||
graph?: Owner; | ||
} | ||
export interface SignalState<T> extends SourceMapValue { | ||
value: T; | ||
observers: Computation<any>[] | null; | ||
observerSlots: number[] | null; | ||
tValue?: T; | ||
comparator?: (prev: T, next: T) => boolean; | ||
value: T; | ||
observers: Computation<any>[] | null; | ||
observerSlots: number[] | null; | ||
tValue?: T; | ||
comparator?: (prev: T, next: T) => boolean; | ||
} | ||
export interface Owner { | ||
owned: Computation<any>[] | null; | ||
cleanups: (() => void)[] | null; | ||
owner: Owner | null; | ||
context: any | null; | ||
sourceMap?: SourceMapValue[]; | ||
name?: string; | ||
owned: Computation<any>[] | null; | ||
cleanups: (() => void)[] | null; | ||
owner: Owner | null; | ||
context: any | null; | ||
sourceMap?: SourceMapValue[]; | ||
name?: string; | ||
} | ||
export interface Computation<Init, Next extends Init = Init> extends Owner { | ||
fn: EffectFunction<Init, Next>; | ||
state: ComputationState; | ||
tState?: ComputationState; | ||
sources: SignalState<Next>[] | null; | ||
sourceSlots: number[] | null; | ||
value?: Init; | ||
updatedAt: number | null; | ||
pure: boolean; | ||
user?: boolean; | ||
suspense?: SuspenseContextType; | ||
fn: EffectFunction<Init, Next>; | ||
state: ComputationState; | ||
tState?: ComputationState; | ||
sources: SignalState<Next>[] | null; | ||
sourceSlots: number[] | null; | ||
value?: Init; | ||
updatedAt: number | null; | ||
pure: boolean; | ||
user?: boolean; | ||
suspense?: SuspenseContextType; | ||
} | ||
export interface TransitionState { | ||
sources: Set<SignalState<any>>; | ||
effects: Computation<any>[]; | ||
promises: Set<Promise<any>>; | ||
disposed: Set<Computation<any>>; | ||
queue: Set<Computation<any>>; | ||
scheduler?: (fn: () => void) => unknown; | ||
running: boolean; | ||
done?: Promise<void>; | ||
resolve?: () => void; | ||
sources: Set<SignalState<any>>; | ||
effects: Computation<any>[]; | ||
promises: Set<Promise<any>>; | ||
disposed: Set<Computation<any>>; | ||
queue: Set<Computation<any>>; | ||
scheduler?: (fn: () => void) => unknown; | ||
running: boolean; | ||
done?: Promise<void>; | ||
resolve?: () => void; | ||
} | ||
type ExternalSourceFactory = <Prev, Next extends Prev = Prev>(fn: EffectFunction<Prev, Next>, trigger: () => void) => ExternalSource; | ||
type ExternalSourceFactory = <Prev, Next extends Prev = Prev>( | ||
fn: EffectFunction<Prev, Next>, | ||
trigger: () => void | ||
) => ExternalSource; | ||
export interface ExternalSource { | ||
track: EffectFunction<any, any>; | ||
dispose: () => void; | ||
track: EffectFunction<any, any>; | ||
dispose: () => void; | ||
} | ||
@@ -101,6 +104,13 @@ export type RootFunction<T> = (dispose: () => void) => T; | ||
export type Accessor<T> = () => T; | ||
export type Setter<T> = (undefined extends T ? () => undefined : {}) & (<U extends T>(value: (prev: T) => U) => U) & (<U extends T>(value: Exclude<U, Function>) => U) & (<U extends T>(value: Exclude<U, Function> | ((prev: T) => U)) => U); | ||
export type Setter<in out T> = { | ||
<U extends T>(...args: undefined extends T ? [] : [value: (prev: T) => U]): undefined extends T | ||
? undefined | ||
: U; | ||
<U extends T>(value: (prev: T) => U): U; | ||
<U extends T>(value: Exclude<U, Function>): U; | ||
<U extends T>(value: Exclude<U, Function> | ((prev: T) => U)): U; | ||
}; | ||
export type Signal<T> = [get: Accessor<T>, set: Setter<T>]; | ||
export interface SignalOptions<T> extends MemoOptions<T> { | ||
internal?: boolean; | ||
internal?: boolean; | ||
} | ||
@@ -133,7 +143,6 @@ /** | ||
export interface BaseOptions { | ||
name?: string; | ||
name?: string; | ||
} | ||
export type NoInfer<T extends any> = [T][T extends any ? 0 : never]; | ||
export interface EffectOptions extends BaseOptions { | ||
} | ||
export interface EffectOptions extends BaseOptions {} | ||
export type EffectFunction<Prev, Next extends Prev = Prev> = (v: Prev) => Next; | ||
@@ -155,4 +164,10 @@ /** | ||
*/ | ||
export declare function createComputed<Next>(fn: EffectFunction<undefined | NoInfer<Next>, Next>): void; | ||
export declare function createComputed<Next, Init = Next>(fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions): void; | ||
export declare function createComputed<Next>( | ||
fn: EffectFunction<undefined | NoInfer<Next>, Next> | ||
): void; | ||
export declare function createComputed<Next, Init = Next>( | ||
fn: EffectFunction<Init | Next, Next>, | ||
value: Init, | ||
options?: EffectOptions | ||
): void; | ||
/** | ||
@@ -173,4 +188,10 @@ * Creates a reactive computation that runs during the render phase as DOM elements are created and updated but not necessarily connected | ||
*/ | ||
export declare function createRenderEffect<Next>(fn: EffectFunction<undefined | NoInfer<Next>, Next>): void; | ||
export declare function createRenderEffect<Next, Init = Next>(fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions): void; | ||
export declare function createRenderEffect<Next>( | ||
fn: EffectFunction<undefined | NoInfer<Next>, Next> | ||
): void; | ||
export declare function createRenderEffect<Next, Init = Next>( | ||
fn: EffectFunction<Init | Next, Next>, | ||
value: Init, | ||
options?: EffectOptions | ||
): void; | ||
/** | ||
@@ -191,6 +212,12 @@ * Creates a reactive computation that runs after the render phase | ||
*/ | ||
export declare function createEffect<Next>(fn: EffectFunction<undefined | NoInfer<Next>, Next>): void; | ||
export declare function createEffect<Next, Init = Next>(fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions & { | ||
export declare function createEffect<Next>( | ||
fn: EffectFunction<undefined | NoInfer<Next>, Next> | ||
): void; | ||
export declare function createEffect<Next, Init = Next>( | ||
fn: EffectFunction<Init | Next, Next>, | ||
value: Init, | ||
options?: EffectOptions & { | ||
render?: boolean; | ||
}): void; | ||
} | ||
): void; | ||
/** | ||
@@ -209,9 +236,12 @@ * Creates a reactive computation that runs after the render phase with flexible tracking | ||
*/ | ||
export declare function createReaction(onInvalidate: () => void, options?: EffectOptions): (tracking: () => void) => void; | ||
export declare function createReaction( | ||
onInvalidate: () => void, | ||
options?: EffectOptions | ||
): (tracking: () => void) => void; | ||
export interface Memo<Prev, Next = Prev> extends SignalState<Next>, Computation<Next> { | ||
value: Next; | ||
tOwned?: Computation<Prev | Next, Next>[]; | ||
value: Next; | ||
tOwned?: Computation<Prev | Next, Next>[]; | ||
} | ||
export interface MemoOptions<T> extends EffectOptions { | ||
equals?: false | ((prev: T, next: T) => boolean); | ||
equals?: false | ((prev: T, next: T) => boolean); | ||
} | ||
@@ -233,38 +263,44 @@ /** | ||
*/ | ||
export declare function createMemo<Next extends Prev, Prev = Next>(fn: EffectFunction<undefined | NoInfer<Prev>, Next>): Accessor<Next>; | ||
export declare function createMemo<Next extends Prev, Init = Next, Prev = Next>(fn: EffectFunction<Init | Prev, Next>, value: Init, options?: MemoOptions<Next>): Accessor<Next>; | ||
export declare function createMemo<Next extends Prev, Prev = Next>( | ||
fn: EffectFunction<undefined | NoInfer<Prev>, Next> | ||
): Accessor<Next>; | ||
export declare function createMemo<Next extends Prev, Init = Next, Prev = Next>( | ||
fn: EffectFunction<Init | Prev, Next>, | ||
value: Init, | ||
options?: MemoOptions<Next> | ||
): Accessor<Next>; | ||
interface Unresolved { | ||
state: "unresolved"; | ||
loading: false; | ||
error: undefined; | ||
latest: undefined; | ||
(): undefined; | ||
state: "unresolved"; | ||
loading: false; | ||
error: undefined; | ||
latest: undefined; | ||
(): undefined; | ||
} | ||
interface Pending { | ||
state: "pending"; | ||
loading: true; | ||
error: undefined; | ||
latest: undefined; | ||
(): undefined; | ||
state: "pending"; | ||
loading: true; | ||
error: undefined; | ||
latest: undefined; | ||
(): undefined; | ||
} | ||
interface Ready<T> { | ||
state: "ready"; | ||
loading: false; | ||
error: undefined; | ||
latest: T; | ||
(): T; | ||
state: "ready"; | ||
loading: false; | ||
error: undefined; | ||
latest: T; | ||
(): T; | ||
} | ||
interface Refreshing<T> { | ||
state: "refreshing"; | ||
loading: true; | ||
error: undefined; | ||
latest: T; | ||
(): T; | ||
state: "refreshing"; | ||
loading: true; | ||
error: undefined; | ||
latest: T; | ||
(): T; | ||
} | ||
interface Errored { | ||
state: "errored"; | ||
loading: false; | ||
error: any; | ||
latest: never; | ||
(): never; | ||
state: "errored"; | ||
loading: false; | ||
error: any; | ||
latest: never; | ||
(): never; | ||
} | ||
@@ -274,28 +310,34 @@ export type Resource<T> = Unresolved | Pending | Ready<T> | Refreshing<T> | Errored; | ||
export type ResourceActions<T, R = unknown> = { | ||
mutate: Setter<T>; | ||
refetch: (info?: R) => T | Promise<T> | undefined | null; | ||
mutate: Setter<T>; | ||
refetch: (info?: R) => T | Promise<T> | undefined | null; | ||
}; | ||
export type ResourceSource<S> = S | false | null | undefined | (() => S | false | null | undefined); | ||
export type ResourceFetcher<S, T, R = unknown> = (k: S, info: ResourceFetcherInfo<T, R>) => T | Promise<T>; | ||
export type ResourceFetcher<S, T, R = unknown> = ( | ||
k: S, | ||
info: ResourceFetcherInfo<T, R> | ||
) => T | Promise<T>; | ||
export type ResourceFetcherInfo<T, R = unknown> = { | ||
value: T | undefined; | ||
refetching: R | boolean; | ||
value: T | undefined; | ||
refetching: R | boolean; | ||
}; | ||
export type ResourceOptions<T, S = unknown> = { | ||
initialValue?: T; | ||
name?: string; | ||
deferStream?: boolean; | ||
ssrLoadFrom?: "initial" | "server"; | ||
storage?: (init: T | undefined) => [Accessor<T | undefined>, Setter<T | undefined>]; | ||
onHydrated?: (k: S | undefined, info: { | ||
value: T | undefined; | ||
}) => void; | ||
initialValue?: T; | ||
name?: string; | ||
deferStream?: boolean; | ||
ssrLoadFrom?: "initial" | "server"; | ||
storage?: (init: T | undefined) => [Accessor<T | undefined>, Setter<T | undefined>]; | ||
onHydrated?: ( | ||
k: S | undefined, | ||
info: { | ||
value: T | undefined; | ||
} | ||
) => void; | ||
}; | ||
export type InitializedResourceOptions<T, S = unknown> = ResourceOptions<T, S> & { | ||
initialValue: T; | ||
initialValue: T; | ||
}; | ||
export type ResourceReturn<T, R = unknown> = [Resource<T>, ResourceActions<T | undefined, R>]; | ||
export type InitializedResourceReturn<T, R = unknown> = [ | ||
InitializedResource<T>, | ||
ResourceActions<T, R> | ||
InitializedResource<T>, | ||
ResourceActions<T, R> | ||
]; | ||
@@ -330,10 +372,24 @@ /** | ||
*/ | ||
export declare function createResource<T, R = unknown>(fetcher: ResourceFetcher<true, T, R>, options: InitializedResourceOptions<NoInfer<T>, true>): InitializedResourceReturn<T, R>; | ||
export declare function createResource<T, R = unknown>(fetcher: ResourceFetcher<true, T, R>, options?: ResourceOptions<NoInfer<T>, true>): ResourceReturn<T, R>; | ||
export declare function createResource<T, S, R = unknown>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T, R>, options: InitializedResourceOptions<NoInfer<T>, S>): InitializedResourceReturn<T, R>; | ||
export declare function createResource<T, S, R = unknown>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T, R>, options?: ResourceOptions<NoInfer<T>, S>): ResourceReturn<T, R>; | ||
export declare function createResource<T, R = unknown>( | ||
fetcher: ResourceFetcher<true, T, R>, | ||
options: InitializedResourceOptions<NoInfer<T>, true> | ||
): InitializedResourceReturn<T, R>; | ||
export declare function createResource<T, R = unknown>( | ||
fetcher: ResourceFetcher<true, T, R>, | ||
options?: ResourceOptions<NoInfer<T>, true> | ||
): ResourceReturn<T, R>; | ||
export declare function createResource<T, S, R = unknown>( | ||
source: ResourceSource<S>, | ||
fetcher: ResourceFetcher<S, T, R>, | ||
options: InitializedResourceOptions<NoInfer<T>, S> | ||
): InitializedResourceReturn<T, R>; | ||
export declare function createResource<T, S, R = unknown>( | ||
source: ResourceSource<S>, | ||
fetcher: ResourceFetcher<S, T, R>, | ||
options?: ResourceOptions<NoInfer<T>, S> | ||
): ResourceReturn<T, R>; | ||
export interface DeferredOptions<T> { | ||
equals?: false | ((prev: T, next: T) => boolean); | ||
name?: string; | ||
timeoutMs?: number; | ||
equals?: false | ((prev: T, next: T) => boolean); | ||
name?: string; | ||
timeoutMs?: number; | ||
} | ||
@@ -353,3 +409,6 @@ /** | ||
*/ | ||
export declare function createDeferred<T>(source: Accessor<T>, options?: DeferredOptions<T>): Accessor<T>; | ||
export declare function createDeferred<T>( | ||
source: Accessor<T>, | ||
options?: DeferredOptions<T> | ||
): Accessor<T>; | ||
export type EqualityCheckerFunction<T, U> = (a: U, b: T) => boolean; | ||
@@ -380,3 +439,7 @@ /** | ||
*/ | ||
export declare function createSelector<T, U = T>(source: Accessor<T>, fn?: EqualityCheckerFunction<T, U>, options?: BaseOptions): (key: U) => boolean; | ||
export declare function createSelector<T, U = T>( | ||
source: Accessor<T>, | ||
fn?: EqualityCheckerFunction<T, U>, | ||
options?: BaseOptions | ||
): (key: U) => boolean; | ||
/** | ||
@@ -399,11 +462,24 @@ * Holds changes inside the block before the reactive context is updated | ||
/** @deprecated */ | ||
export type ReturnTypes<T> = T extends readonly Accessor<unknown>[] ? { | ||
[K in keyof T]: T[K] extends Accessor<infer I> ? I : never; | ||
} : T extends Accessor<infer I> ? I : never; | ||
export type AccessorArray<T> = [...Extract<{ | ||
[K in keyof T]: Accessor<T[K]>; | ||
}, readonly unknown[]>]; | ||
export type OnEffectFunction<S, Prev, Next extends Prev = Prev> = (input: S, prevInput: S | undefined, prev: Prev) => Next; | ||
export type ReturnTypes<T> = T extends readonly Accessor<unknown>[] | ||
? { | ||
[K in keyof T]: T[K] extends Accessor<infer I> ? I : never; | ||
} | ||
: T extends Accessor<infer I> | ||
? I | ||
: never; | ||
export type AccessorArray<T> = [ | ||
...Extract< | ||
{ | ||
[K in keyof T]: Accessor<T[K]>; | ||
}, | ||
readonly unknown[] | ||
> | ||
]; | ||
export type OnEffectFunction<S, Prev, Next extends Prev = Prev> = ( | ||
input: S, | ||
prevInput: S | undefined, | ||
prev: Prev | ||
) => Next; | ||
export interface OnOptions { | ||
defer?: boolean; | ||
defer?: boolean; | ||
} | ||
@@ -436,8 +512,16 @@ /** | ||
*/ | ||
export declare function on<S, Next extends Prev, Prev = Next>(deps: AccessorArray<S> | Accessor<S>, fn: OnEffectFunction<S, undefined | NoInfer<Prev>, Next>, options?: OnOptions & { | ||
export declare function on<S, Next extends Prev, Prev = Next>( | ||
deps: AccessorArray<S> | Accessor<S>, | ||
fn: OnEffectFunction<S, undefined | NoInfer<Prev>, Next>, | ||
options?: OnOptions & { | ||
defer?: false; | ||
}): EffectFunction<undefined | NoInfer<Next>, NoInfer<Next>>; | ||
export declare function on<S, Next extends Prev, Prev = Next>(deps: AccessorArray<S> | Accessor<S>, fn: OnEffectFunction<S, undefined | NoInfer<Prev>, Next>, options: OnOptions & { | ||
} | ||
): EffectFunction<undefined | NoInfer<Next>, NoInfer<Next>>; | ||
export declare function on<S, Next extends Prev, Prev = Next>( | ||
deps: AccessorArray<S> | Accessor<S>, | ||
fn: OnEffectFunction<S, undefined | NoInfer<Prev>, Next>, | ||
options: OnOptions & { | ||
defer: true; | ||
}): EffectFunction<undefined | NoInfer<Next>>; | ||
} | ||
): EffectFunction<undefined | NoInfer<Next>>; | ||
/** | ||
@@ -504,5 +588,5 @@ * onMount - run an effect only after initial render on mount | ||
export interface DevComponent<T> extends Memo<unknown> { | ||
props: T; | ||
name: string; | ||
component: (props: T) => unknown; | ||
props: T; | ||
name: string; | ||
component: (props: T) => unknown; | ||
} | ||
@@ -512,8 +596,8 @@ export declare function devComponent<P, V>(Comp: (props: P) => V, props: P): V; | ||
export type ContextProviderComponent<T> = FlowComponent<{ | ||
value: T; | ||
value: T; | ||
}>; | ||
export interface Context<T> { | ||
id: symbol; | ||
Provider: ContextProviderComponent<T>; | ||
defaultValue: T; | ||
id: symbol; | ||
Provider: ContextProviderComponent<T>; | ||
defaultValue: T; | ||
} | ||
@@ -539,3 +623,6 @@ /** | ||
*/ | ||
export declare function createContext<T>(defaultValue?: undefined, options?: EffectOptions): Context<T | undefined>; | ||
export declare function createContext<T>( | ||
defaultValue?: undefined, | ||
options?: EffectOptions | ||
): Context<T | undefined>; | ||
export declare function createContext<T>(defaultValue: T, options?: EffectOptions): Context<T>; | ||
@@ -554,3 +641,3 @@ /** | ||
export type ChildrenReturn = Accessor<ResolvedChildren> & { | ||
toArray: () => ResolvedJSXElement[]; | ||
toArray: () => ResolvedJSXElement[]; | ||
}; | ||
@@ -567,12 +654,12 @@ /** | ||
export type SuspenseContextType = { | ||
increment?: () => void; | ||
decrement?: () => void; | ||
inFallback?: () => boolean; | ||
effects?: Computation<any>[]; | ||
resolved?: boolean; | ||
increment?: () => void; | ||
decrement?: () => void; | ||
inFallback?: () => boolean; | ||
effects?: Computation<any>[]; | ||
resolved?: boolean; | ||
}; | ||
type SuspenseContext = Context<SuspenseContextType> & { | ||
active?(): boolean; | ||
increment?(): void; | ||
decrement?(): void; | ||
active?(): boolean; | ||
increment?(): void; | ||
decrement?(): void; | ||
}; | ||
@@ -583,3 +670,7 @@ declare let SuspenseContext: SuspenseContext; | ||
export declare function readSignal(this: SignalState<any> | Memo<any>): any; | ||
export declare function writeSignal(node: SignalState<any> | Memo<any>, value: any, isComp?: boolean): any; | ||
export declare function writeSignal( | ||
node: SignalState<any> | Memo<any>, | ||
value: any, | ||
isComp?: boolean | ||
): any; | ||
export {}; |
@@ -14,3 +14,3 @@ import type { JSX } from "../jsx.js"; | ||
export type VoidProps<P = {}> = P & { | ||
children?: never; | ||
children?: never; | ||
}; | ||
@@ -29,3 +29,3 @@ /** | ||
export type ParentProps<P = {}> = P & { | ||
children?: JSX.Element; | ||
children?: JSX.Element; | ||
}; | ||
@@ -45,3 +45,3 @@ /** | ||
export type FlowProps<P = {}, C = JSX.Element> = P & { | ||
children: C; | ||
children: C; | ||
}; | ||
@@ -65,3 +65,7 @@ /** | ||
*/ | ||
export type ComponentProps<T extends ValidComponent> = T extends Component<infer P> ? P : T extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[T] : Record<string, unknown>; | ||
export type ComponentProps<T extends ValidComponent> = T extends Component<infer P> | ||
? P | ||
: T extends keyof JSX.IntrinsicElements | ||
? JSX.IntrinsicElements[T] | ||
: Record<string, unknown>; | ||
/** | ||
@@ -75,40 +79,67 @@ * Type of `props.ref`, for use in `Component` or `props` typing. | ||
type DistributeOverride<T, F> = T extends undefined ? F : T; | ||
type Override<T, U> = T extends any ? U extends any ? { | ||
[K in keyof T]: K extends keyof U ? DistributeOverride<U[K], T[K]> : T[K]; | ||
} & { | ||
[K in keyof U]: K extends keyof T ? DistributeOverride<U[K], T[K]> : U[K]; | ||
} : T & U : T & U; | ||
type OverrideSpread<T, U> = T extends any ? { | ||
[K in keyof ({ | ||
type Override<T, U> = T extends any | ||
? U extends any | ||
? { | ||
[K in keyof T]: K extends keyof U ? DistributeOverride<U[K], T[K]> : T[K]; | ||
} & { | ||
[K in keyof U]: K extends keyof T ? DistributeOverride<U[K], T[K]> : U[K]; | ||
} | ||
: T & U | ||
: T & U; | ||
type OverrideSpread<T, U> = T extends any | ||
? { | ||
[K in keyof ({ | ||
[K in keyof T]: any; | ||
} & { | ||
} & { | ||
[K in keyof U]?: any; | ||
} & { | ||
} & { | ||
[K in U extends any ? keyof U : keyof U]?: any; | ||
})]: K extends keyof T ? Exclude<U extends any ? U[K & keyof U] : never, undefined> | T[K] : U extends any ? U[K & keyof U] : never; | ||
} : T & U; | ||
type Simplify<T> = T extends any ? { | ||
[K in keyof T]: T[K]; | ||
} : T; | ||
})]: K extends keyof T | ||
? Exclude<U extends any ? U[K & keyof U] : never, undefined> | T[K] | ||
: U extends any | ||
? U[K & keyof U] | ||
: never; | ||
} | ||
: T & U; | ||
type Simplify<T> = T extends any | ||
? { | ||
[K in keyof T]: T[K]; | ||
} | ||
: T; | ||
type _MergeProps<T extends unknown[], Curr = {}> = T extends [ | ||
infer Next | (() => infer Next), | ||
...infer Rest | ||
] ? _MergeProps<Rest, Override<Curr, Next>> : T extends [...infer Rest, infer Next | (() => infer Next)] ? Override<_MergeProps<Rest, Curr>, Next> : T extends [] ? Curr : T extends (infer I | (() => infer I))[] ? OverrideSpread<Curr, I> : Curr; | ||
infer Next | (() => infer Next), | ||
...infer Rest | ||
] | ||
? _MergeProps<Rest, Override<Curr, Next>> | ||
: T extends [...infer Rest, infer Next | (() => infer Next)] | ||
? Override<_MergeProps<Rest, Curr>, Next> | ||
: T extends [] | ||
? Curr | ||
: T extends (infer I | (() => infer I))[] | ||
? OverrideSpread<Curr, I> | ||
: Curr; | ||
export type MergeProps<T extends unknown[]> = Simplify<_MergeProps<T>>; | ||
export declare function mergeProps<T extends unknown[]>(...sources: T): MergeProps<T>; | ||
export type SplitProps<T, K extends (readonly (keyof T)[])[]> = [ | ||
...{ | ||
[P in keyof K]: P extends `${number}` ? Pick<T, Extract<K[P], readonly (keyof T)[]>[number]> : never; | ||
}, | ||
Omit<T, K[number][number]> | ||
...{ | ||
[P in keyof K]: P extends `${number}` | ||
? Pick<T, Extract<K[P], readonly (keyof T)[]>[number]> | ||
: never; | ||
}, | ||
Omit<T, K[number][number]> | ||
]; | ||
export declare function splitProps<T extends Record<any, any>, K extends [readonly (keyof T)[], ...(readonly (keyof T)[])[]]>(props: T, ...keys: K): SplitProps<T, K>; | ||
export declare function lazy<T extends Component<any>>(fn: () => Promise<{ | ||
export declare function splitProps< | ||
T extends Record<any, any>, | ||
K extends [readonly (keyof T)[], ...(readonly (keyof T)[])[]] | ||
>(props: T, ...keys: K): SplitProps<T, K>; | ||
export declare function lazy<T extends Component<any>>( | ||
fn: () => Promise<{ | ||
default: T; | ||
}>): T & { | ||
preload: () => Promise<{ | ||
default: T; | ||
}>; | ||
}> | ||
): T & { | ||
preload: () => Promise<{ | ||
default: T; | ||
}>; | ||
}; | ||
export declare function createUniqueId(): string; | ||
export {}; |
@@ -17,5 +17,5 @@ import { Accessor } from "../reactive/signal.js"; | ||
export declare function For<T extends readonly any[], U extends JSX.Element>(props: { | ||
each: T | undefined | null | false; | ||
fallback?: JSX.Element; | ||
children: (item: T[number], index: Accessor<number>) => U; | ||
each: T | undefined | null | false; | ||
fallback?: JSX.Element; | ||
children: (item: T[number], index: Accessor<number>) => U; | ||
}): JSX.Element; | ||
@@ -36,5 +36,5 @@ /** | ||
export declare function Index<T extends readonly any[], U extends JSX.Element>(props: { | ||
each: T | undefined | null | false; | ||
fallback?: JSX.Element; | ||
children: (item: Accessor<T[number]>, index: number) => U; | ||
each: T | undefined | null | false; | ||
fallback?: JSX.Element; | ||
children: (item: Accessor<T[number]>, index: number) => U; | ||
}): JSX.Element; | ||
@@ -46,13 +46,19 @@ type RequiredParameter<T> = T extends () => unknown ? never : T; | ||
*/ | ||
export declare function Show<T, TRenderFunction extends (item: Accessor<NonNullable<T>>) => JSX.Element>(props: { | ||
when: T | undefined | null | false; | ||
keyed?: false; | ||
fallback?: JSX.Element; | ||
children: JSX.Element | RequiredParameter<TRenderFunction>; | ||
export declare function Show< | ||
T, | ||
TRenderFunction extends (item: Accessor<NonNullable<T>>) => JSX.Element | ||
>(props: { | ||
when: T | undefined | null | false; | ||
keyed?: false; | ||
fallback?: JSX.Element; | ||
children: JSX.Element | RequiredParameter<TRenderFunction>; | ||
}): JSX.Element; | ||
export declare function Show<T, TRenderFunction extends (item: NonNullable<T>) => JSX.Element>(props: { | ||
when: T | undefined | null | false; | ||
keyed: true; | ||
fallback?: JSX.Element; | ||
children: JSX.Element | RequiredParameter<TRenderFunction>; | ||
export declare function Show< | ||
T, | ||
TRenderFunction extends (item: NonNullable<T>) => JSX.Element | ||
>(props: { | ||
when: T | undefined | null | false; | ||
keyed: true; | ||
fallback?: JSX.Element; | ||
children: JSX.Element | RequiredParameter<TRenderFunction>; | ||
}): JSX.Element; | ||
@@ -74,9 +80,9 @@ /** | ||
export declare function Switch(props: { | ||
fallback?: JSX.Element; | ||
children: JSX.Element; | ||
fallback?: JSX.Element; | ||
children: JSX.Element; | ||
}): JSX.Element; | ||
export type MatchProps<T> = { | ||
when: T | undefined | null | false; | ||
keyed?: boolean; | ||
children: JSX.Element | ((item: NonNullable<T> | Accessor<NonNullable<T>>) => JSX.Element); | ||
when: T | undefined | null | false; | ||
keyed?: boolean; | ||
children: JSX.Element | ((item: NonNullable<T> | Accessor<NonNullable<T>>) => JSX.Element); | ||
}; | ||
@@ -92,11 +98,17 @@ /** | ||
*/ | ||
export declare function Match<T, TRenderFunction extends (item: Accessor<NonNullable<T>>) => JSX.Element>(props: { | ||
when: T | undefined | null | false; | ||
keyed?: false; | ||
children: JSX.Element | RequiredParameter<TRenderFunction>; | ||
export declare function Match< | ||
T, | ||
TRenderFunction extends (item: Accessor<NonNullable<T>>) => JSX.Element | ||
>(props: { | ||
when: T | undefined | null | false; | ||
keyed?: false; | ||
children: JSX.Element | RequiredParameter<TRenderFunction>; | ||
}): JSX.Element; | ||
export declare function Match<T, TRenderFunction extends (item: NonNullable<T>) => JSX.Element>(props: { | ||
when: T | undefined | null | false; | ||
keyed: true; | ||
children: JSX.Element | RequiredParameter<TRenderFunction>; | ||
export declare function Match< | ||
T, | ||
TRenderFunction extends (item: NonNullable<T>) => JSX.Element | ||
>(props: { | ||
when: T | undefined | null | false; | ||
keyed: true; | ||
children: JSX.Element | RequiredParameter<TRenderFunction>; | ||
}): JSX.Element; | ||
@@ -120,5 +132,5 @@ export declare function resetErrorBoundaries(): void; | ||
export declare function ErrorBoundary(props: { | ||
fallback: JSX.Element | ((err: any, reset: () => void) => JSX.Element); | ||
children: JSX.Element; | ||
fallback: JSX.Element | ((err: any, reset: () => void) => JSX.Element); | ||
children: JSX.Element; | ||
}): JSX.Element; | ||
export {}; |
import { Computation } from "../reactive/signal"; | ||
export type HydrationContext = { | ||
id: string; | ||
count: number; | ||
id: string; | ||
count: number; | ||
}; | ||
type SharedConfig = { | ||
context?: HydrationContext; | ||
resources?: { | ||
[key: string]: any; | ||
}; | ||
load?: (id: string) => Promise<any> | any | undefined; | ||
gather?: (key: string) => void; | ||
registry?: Map<string, Element>; | ||
done?: boolean; | ||
count?: number; | ||
effects?: Computation<any, any>[]; | ||
context?: HydrationContext; | ||
resources?: { | ||
[key: string]: any; | ||
}; | ||
load?: (id: string) => Promise<any> | any | undefined; | ||
gather?: (key: string) => void; | ||
registry?: Map<string, Element>; | ||
done?: boolean; | ||
count?: number; | ||
effects?: Computation<any, any>[]; | ||
}; | ||
@@ -18,0 +18,0 @@ export declare const sharedConfig: SharedConfig; |
@@ -8,5 +8,5 @@ import type { JSX } from "../jsx.js"; | ||
export declare function SuspenseList(props: { | ||
children: JSX.Element; | ||
revealOrder: "forwards" | "backwards" | "together"; | ||
tail?: "collapsed" | "hidden"; | ||
children: JSX.Element; | ||
revealOrder: "forwards" | "backwards" | "together"; | ||
tail?: "collapsed" | "hidden"; | ||
}): JSX.Element; | ||
@@ -25,4 +25,4 @@ /** | ||
export declare function Suspense(props: { | ||
fallback?: JSX.Element; | ||
children: JSX.Element; | ||
fallback?: JSX.Element; | ||
children: JSX.Element; | ||
}): JSX.Element; |
@@ -1,3 +0,56 @@ | ||
export { createRoot, createSignal, createComputed, createRenderEffect, createEffect, createReaction, createDeferred, createSelector, createMemo, getListener, onMount, onCleanup, onError, untrack, batch, on, children, createContext, useContext, getOwner, runWithOwner, equalFn, requestCallback, mapArray, observable, from, $PROXY, $DEVCOMP, $TRACK, DEV, enableExternalSource } from "./reactive.js"; | ||
export { mergeProps, splitProps, createComponent, For, Index, Show, Switch, Match, ErrorBoundary, Suspense, SuspenseList, createResource, resetErrorBoundaries, enableScheduling, enableHydration, startTransition, useTransition, createUniqueId, lazy, sharedConfig } from "./rendering.js"; | ||
export { | ||
createRoot, | ||
createSignal, | ||
createComputed, | ||
createRenderEffect, | ||
createEffect, | ||
createReaction, | ||
createDeferred, | ||
createSelector, | ||
createMemo, | ||
getListener, | ||
onMount, | ||
onCleanup, | ||
onError, | ||
untrack, | ||
batch, | ||
on, | ||
children, | ||
createContext, | ||
useContext, | ||
getOwner, | ||
runWithOwner, | ||
equalFn, | ||
requestCallback, | ||
mapArray, | ||
observable, | ||
from, | ||
$PROXY, | ||
$DEVCOMP, | ||
$TRACK, | ||
DEV, | ||
enableExternalSource | ||
} from "./reactive.js"; | ||
export { | ||
mergeProps, | ||
splitProps, | ||
createComponent, | ||
For, | ||
Index, | ||
Show, | ||
Switch, | ||
Match, | ||
ErrorBoundary, | ||
Suspense, | ||
SuspenseList, | ||
createResource, | ||
resetErrorBoundaries, | ||
enableScheduling, | ||
enableHydration, | ||
startTransition, | ||
useTransition, | ||
createUniqueId, | ||
lazy, | ||
sharedConfig | ||
} from "./rendering.js"; | ||
export type { Component, Resource } from "./rendering.js"; |
@@ -7,3 +7,5 @@ export declare const equalFn: <T>(a: T, b: T) => boolean; | ||
export type Accessor<T> = () => T; | ||
export type Setter<T> = undefined extends T ? <U extends T>(value?: (U extends Function ? never : U) | ((prev?: T) => U)) => U : <U extends T>(value: (U extends Function ? never : U) | ((prev: T) => U)) => U; | ||
export type Setter<T> = undefined extends T | ||
? <U extends T>(value?: (U extends Function ? never : U) | ((prev?: T) => U)) => U | ||
: <U extends T>(value: (U extends Function ? never : U) | ((prev: T) => U)) => U; | ||
export type Signal<T> = [get: Accessor<T>, set: Setter<T>]; | ||
@@ -13,13 +15,19 @@ export declare function castError(err: unknown): Error; | ||
interface Owner { | ||
owner: Owner | null; | ||
context: any | null; | ||
owned: Owner[] | null; | ||
cleanups: (() => void)[] | null; | ||
owner: Owner | null; | ||
context: any | null; | ||
owned: Owner[] | null; | ||
cleanups: (() => void)[] | null; | ||
} | ||
export declare function createOwner(): Owner; | ||
export declare function createRoot<T>(fn: (dispose: () => void) => T, detachedOwner?: typeof Owner): T; | ||
export declare function createSignal<T>(value: T, options?: { | ||
export declare function createRoot<T>( | ||
fn: (dispose: () => void) => T, | ||
detachedOwner?: typeof Owner | ||
): T; | ||
export declare function createSignal<T>( | ||
value: T, | ||
options?: { | ||
equals?: false | ((prev: T, next: T) => boolean); | ||
name?: string; | ||
}): [get: () => T, set: (v: (T extends Function ? never : T) | ((prev: T) => T)) => T]; | ||
} | ||
): [get: () => T, set: (v: (T extends Function ? never : T) | ((prev: T) => T)) => T]; | ||
export declare function createComputed<T>(fn: (v?: T) => T, value?: T): void; | ||
@@ -31,8 +39,15 @@ export declare const createRenderEffect: typeof createComputed; | ||
export declare function createDeferred<T>(source: () => T): () => T; | ||
export declare function createSelector<T>(source: () => T, fn?: (k: T, value: T) => boolean): (k: T) => boolean; | ||
export declare function createSelector<T>( | ||
source: () => T, | ||
fn?: (k: T, value: T) => boolean | ||
): (k: T) => boolean; | ||
export declare function batch<T>(fn: () => T): T; | ||
export declare const untrack: typeof batch; | ||
export declare function on<T, U>(deps: Array<() => T> | (() => T), fn: (value: Array<T> | T, prev?: Array<T> | T, prevResults?: U) => U, options?: { | ||
export declare function on<T, U>( | ||
deps: Array<() => T> | (() => T), | ||
fn: (value: Array<T> | T, prev?: Array<T> | T, prevResults?: U) => U, | ||
options?: { | ||
defer?: boolean; | ||
}): (prev?: U) => U | undefined; | ||
} | ||
): (prev?: U) => U | undefined; | ||
export declare function onMount(fn: () => void): void; | ||
@@ -48,8 +63,5 @@ export declare function onCleanup(fn: () => void): () => void; | ||
export interface Context<T> { | ||
id: symbol; | ||
Provider: (props: { | ||
value: T; | ||
children: any; | ||
}) => any; | ||
defaultValue?: T; | ||
id: symbol; | ||
Provider: (props: { value: T; children: any }) => any; | ||
defaultValue?: T; | ||
} | ||
@@ -60,3 +72,3 @@ export declare function createContext<T>(defaultValue?: T): Context<T>; | ||
type ChildrenReturn = Accessor<any> & { | ||
toArray: () => any[]; | ||
toArray: () => any[]; | ||
}; | ||
@@ -67,31 +79,46 @@ export declare function children(fn: () => any): ChildrenReturn; | ||
export interface Task { | ||
id: number; | ||
fn: ((didTimeout: boolean) => void) | null; | ||
startTime: number; | ||
expirationTime: number; | ||
id: number; | ||
fn: ((didTimeout: boolean) => void) | null; | ||
startTime: number; | ||
expirationTime: number; | ||
} | ||
export declare function requestCallback(fn: () => void, options?: { | ||
export declare function requestCallback( | ||
fn: () => void, | ||
options?: { | ||
timeout: number; | ||
}): Task; | ||
} | ||
): Task; | ||
export declare function cancelCallback(task: Task): void; | ||
export declare function mapArray<T, U>(list: () => T[], mapFn: (v: T, i: () => number) => U, options?: { | ||
export declare function mapArray<T, U>( | ||
list: () => T[], | ||
mapFn: (v: T, i: () => number) => U, | ||
options?: { | ||
fallback?: () => any; | ||
}): () => U[]; | ||
export type ObservableObserver<T> = ((v: T) => void) | { | ||
next: (v: T) => void; | ||
error?: (v: any) => void; | ||
complete?: (v: boolean) => void; | ||
}; | ||
} | ||
): () => U[]; | ||
export type ObservableObserver<T> = | ||
| ((v: T) => void) | ||
| { | ||
next: (v: T) => void; | ||
error?: (v: any) => void; | ||
complete?: (v: boolean) => void; | ||
}; | ||
export declare function observable<T>(input: Accessor<T>): { | ||
subscribe(observer: ObservableObserver<T>): { | ||
unsubscribe(): void; | ||
}; | ||
[Symbol.observable](): any; | ||
subscribe(observer: ObservableObserver<T>): { | ||
unsubscribe(): void; | ||
}; | ||
[Symbol.observable](): any; | ||
}; | ||
export declare function from<T>(producer: ((setter: Setter<T>) => () => void) | { | ||
subscribe: (fn: (v: T) => void) => (() => void) | { | ||
unsubscribe: () => void; | ||
}; | ||
}): Accessor<T>; | ||
export declare function from<T>( | ||
producer: | ||
| ((setter: Setter<T>) => () => void) | ||
| { | ||
subscribe: (fn: (v: T) => void) => | ||
| (() => void) | ||
| { | ||
unsubscribe: () => void; | ||
}; | ||
} | ||
): Accessor<T>; | ||
export declare function enableExternalSource(factory: any): void; | ||
export {}; |
@@ -5,11 +5,11 @@ import { Accessor, Setter, Signal } from "./reactive.js"; | ||
export type VoidProps<P = {}> = P & { | ||
children?: never; | ||
children?: never; | ||
}; | ||
export type VoidComponent<P = {}> = Component<VoidProps<P>>; | ||
export type ParentProps<P = {}> = P & { | ||
children?: JSX.Element; | ||
children?: JSX.Element; | ||
}; | ||
export type ParentComponent<P = {}> = Component<ParentProps<P>>; | ||
export type FlowProps<P = {}, C = JSX.Element> = P & { | ||
children: C; | ||
children: C; | ||
}; | ||
@@ -19,5 +19,9 @@ export type FlowComponent<P = {}, C = JSX.Element> = Component<FlowProps<P, C>>; | ||
export type ValidComponent = keyof JSX.IntrinsicElements | Component<any> | (string & {}); | ||
export type ComponentProps<T extends ValidComponent> = T extends Component<infer P> ? P : T extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[T] : Record<string, unknown>; | ||
export type ComponentProps<T extends ValidComponent> = T extends Component<infer P> | ||
? P | ||
: T extends keyof JSX.IntrinsicElements | ||
? JSX.IntrinsicElements[T] | ||
: Record<string, unknown>; | ||
type SharedConfig = { | ||
context?: HydrationContext; | ||
context?: HydrationContext; | ||
}; | ||
@@ -29,24 +33,62 @@ export declare const sharedConfig: SharedConfig; | ||
export declare function mergeProps<T, U, V>(source: T, source1: U, source2: V): T & U & V; | ||
export declare function mergeProps<T, U, V, W>(source: T, source1: U, source2: V, source3: W): T & U & V & W; | ||
export declare function splitProps<T extends object, K1 extends keyof T>(props: T, ...keys: [K1[]]): [Pick<T, K1>, Omit<T, K1>]; | ||
export declare function splitProps<T extends object, K1 extends keyof T, K2 extends keyof T>(props: T, ...keys: [K1[], K2[]]): [Pick<T, K1>, Pick<T, K2>, Omit<T, K1 | K2>]; | ||
export declare function splitProps<T extends object, K1 extends keyof T, K2 extends keyof T, K3 extends keyof T>(props: T, ...keys: [K1[], K2[], K3[]]): [Pick<T, K1>, Pick<T, K2>, Pick<T, K3>, Omit<T, K1 | K2 | K3>]; | ||
export declare function splitProps<T extends object, K1 extends keyof T, K2 extends keyof T, K3 extends keyof T, K4 extends keyof T>(props: T, ...keys: [K1[], K2[], K3[], K4[]]): [Pick<T, K1>, Pick<T, K2>, Pick<T, K3>, Pick<T, K4>, Omit<T, K1 | K2 | K3 | K4>]; | ||
export declare function splitProps<T extends object, K1 extends keyof T, K2 extends keyof T, K3 extends keyof T, K4 extends keyof T, K5 extends keyof T>(props: T, ...keys: [K1[], K2[], K3[], K4[], K5[]]): [ | ||
Pick<T, K1>, | ||
Pick<T, K2>, | ||
Pick<T, K3>, | ||
Pick<T, K4>, | ||
Pick<T, K5>, | ||
Omit<T, K1 | K2 | K3 | K4 | K5> | ||
export declare function mergeProps<T, U, V, W>( | ||
source: T, | ||
source1: U, | ||
source2: V, | ||
source3: W | ||
): T & U & V & W; | ||
export declare function splitProps<T extends object, K1 extends keyof T>( | ||
props: T, | ||
...keys: [K1[]] | ||
): [Pick<T, K1>, Omit<T, K1>]; | ||
export declare function splitProps<T extends object, K1 extends keyof T, K2 extends keyof T>( | ||
props: T, | ||
...keys: [K1[], K2[]] | ||
): [Pick<T, K1>, Pick<T, K2>, Omit<T, K1 | K2>]; | ||
export declare function splitProps< | ||
T extends object, | ||
K1 extends keyof T, | ||
K2 extends keyof T, | ||
K3 extends keyof T | ||
>( | ||
props: T, | ||
...keys: [K1[], K2[], K3[]] | ||
): [Pick<T, K1>, Pick<T, K2>, Pick<T, K3>, Omit<T, K1 | K2 | K3>]; | ||
export declare function splitProps< | ||
T extends object, | ||
K1 extends keyof T, | ||
K2 extends keyof T, | ||
K3 extends keyof T, | ||
K4 extends keyof T | ||
>( | ||
props: T, | ||
...keys: [K1[], K2[], K3[], K4[]] | ||
): [Pick<T, K1>, Pick<T, K2>, Pick<T, K3>, Pick<T, K4>, Omit<T, K1 | K2 | K3 | K4>]; | ||
export declare function splitProps< | ||
T extends object, | ||
K1 extends keyof T, | ||
K2 extends keyof T, | ||
K3 extends keyof T, | ||
K4 extends keyof T, | ||
K5 extends keyof T | ||
>( | ||
props: T, | ||
...keys: [K1[], K2[], K3[], K4[], K5[]] | ||
): [ | ||
Pick<T, K1>, | ||
Pick<T, K2>, | ||
Pick<T, K3>, | ||
Pick<T, K4>, | ||
Pick<T, K5>, | ||
Omit<T, K1 | K2 | K3 | K4 | K5> | ||
]; | ||
export declare function For<T>(props: { | ||
each: T[]; | ||
fallback?: string; | ||
children: (item: T, index: () => number) => string; | ||
each: T[]; | ||
fallback?: string; | ||
children: (item: T, index: () => number) => string; | ||
}): string | any[] | undefined; | ||
export declare function Index<T>(props: { | ||
each: T[]; | ||
fallback?: string; | ||
children: (item: () => T, index: number) => string; | ||
each: T[]; | ||
fallback?: string; | ||
children: (item: () => T, index: number) => string; | ||
}): string | any[] | undefined; | ||
@@ -58,15 +100,15 @@ /** | ||
export declare function Show<T>(props: { | ||
when: T | undefined | null | false; | ||
keyed?: boolean; | ||
fallback?: string; | ||
children: string | ((item: NonNullable<T> | Accessor<NonNullable<T>>) => string); | ||
when: T | undefined | null | false; | ||
keyed?: boolean; | ||
fallback?: string; | ||
children: string | ((item: NonNullable<T> | Accessor<NonNullable<T>>) => string); | ||
}): string; | ||
export declare function Switch(props: { | ||
fallback?: string; | ||
children: MatchProps<unknown> | MatchProps<unknown>[]; | ||
fallback?: string; | ||
children: MatchProps<unknown> | MatchProps<unknown>[]; | ||
}): string; | ||
type MatchProps<T> = { | ||
when: T | false; | ||
keyed?: boolean; | ||
children: string | ((item: NonNullable<T> | Accessor<NonNullable<T>>) => string); | ||
when: T | false; | ||
keyed?: boolean; | ||
children: string | ((item: NonNullable<T> | Accessor<NonNullable<T>>) => string); | ||
}; | ||
@@ -76,24 +118,30 @@ export declare function Match<T>(props: MatchProps<T>): MatchProps<T>; | ||
export declare function ErrorBoundary(props: { | ||
fallback: string | ((err: any, reset: () => void) => string); | ||
children: string; | ||
}): string | ((err: any, reset: () => void) => string) | { | ||
t: string; | ||
}; | ||
fallback: string | ((err: any, reset: () => void) => string); | ||
children: string; | ||
}): | ||
| string | ||
| ((err: any, reset: () => void) => string) | ||
| { | ||
t: string; | ||
}; | ||
export interface Resource<T> { | ||
(): T | undefined; | ||
state: "unresolved" | "pending" | "ready" | "refreshing" | "errored"; | ||
loading: boolean; | ||
error: any; | ||
latest: T | undefined; | ||
(): T | undefined; | ||
state: "unresolved" | "pending" | "ready" | "refreshing" | "errored"; | ||
loading: boolean; | ||
error: any; | ||
latest: T | undefined; | ||
} | ||
type SuspenseContextType = { | ||
resources: Map<string, { | ||
loading: boolean; | ||
error: any; | ||
}>; | ||
completed: () => void; | ||
resources: Map< | ||
string, | ||
{ | ||
loading: boolean; | ||
error: any; | ||
} | ||
>; | ||
completed: () => void; | ||
}; | ||
export type ResourceActions<T> = { | ||
mutate: Setter<T>; | ||
refetch: (info?: unknown) => void; | ||
mutate: Setter<T>; | ||
refetch: (info?: unknown) => void; | ||
}; | ||
@@ -104,30 +152,48 @@ export type ResourceReturn<T> = [Resource<T>, ResourceActions<T>]; | ||
export type ResourceFetcherInfo<T> = { | ||
value: T | undefined; | ||
refetching?: unknown; | ||
value: T | undefined; | ||
refetching?: unknown; | ||
}; | ||
export type ResourceOptions<T> = undefined extends T ? { | ||
initialValue?: T; | ||
name?: string; | ||
deferStream?: boolean; | ||
ssrLoadFrom?: "initial" | "server"; | ||
storage?: () => Signal<T | undefined>; | ||
onHydrated?: <S, T>(k: S, info: ResourceFetcherInfo<T>) => void; | ||
} : { | ||
initialValue: T; | ||
name?: string; | ||
deferStream?: boolean; | ||
ssrLoadFrom?: "initial" | "server"; | ||
storage?: (v?: T) => Signal<T | undefined>; | ||
onHydrated?: <S, T>(k: S, info: ResourceFetcherInfo<T>) => void; | ||
}; | ||
export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): ResourceReturn<T | undefined>; | ||
export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T>; | ||
export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): ResourceReturn<T | undefined>; | ||
export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T>; | ||
export declare function lazy<T extends Component<any>>(fn: () => Promise<{ | ||
export type ResourceOptions<T> = undefined extends T | ||
? { | ||
initialValue?: T; | ||
name?: string; | ||
deferStream?: boolean; | ||
ssrLoadFrom?: "initial" | "server"; | ||
storage?: () => Signal<T | undefined>; | ||
onHydrated?: <S, T>(k: S, info: ResourceFetcherInfo<T>) => void; | ||
} | ||
: { | ||
initialValue: T; | ||
name?: string; | ||
deferStream?: boolean; | ||
ssrLoadFrom?: "initial" | "server"; | ||
storage?: (v?: T) => Signal<T | undefined>; | ||
onHydrated?: <S, T>(k: S, info: ResourceFetcherInfo<T>) => void; | ||
}; | ||
export declare function createResource<T, S = true>( | ||
fetcher: ResourceFetcher<S, T>, | ||
options?: ResourceOptions<undefined> | ||
): ResourceReturn<T | undefined>; | ||
export declare function createResource<T, S = true>( | ||
fetcher: ResourceFetcher<S, T>, | ||
options: ResourceOptions<T> | ||
): ResourceReturn<T>; | ||
export declare function createResource<T, S>( | ||
source: ResourceSource<S>, | ||
fetcher: ResourceFetcher<S, T>, | ||
options?: ResourceOptions<undefined> | ||
): ResourceReturn<T | undefined>; | ||
export declare function createResource<T, S>( | ||
source: ResourceSource<S>, | ||
fetcher: ResourceFetcher<S, T>, | ||
options: ResourceOptions<T> | ||
): ResourceReturn<T>; | ||
export declare function lazy<T extends Component<any>>( | ||
fn: () => Promise<{ | ||
default: T; | ||
}>): T & { | ||
preload: () => Promise<{ | ||
default: T; | ||
}>; | ||
}> | ||
): T & { | ||
preload: () => Promise<{ | ||
default: T; | ||
}>; | ||
}; | ||
@@ -139,25 +205,35 @@ export declare function enableScheduling(): void; | ||
type HydrationContext = { | ||
id: string; | ||
count: number; | ||
writeResource: (id: string, v: Promise<any> | any, error?: boolean, deferStream?: boolean) => void; | ||
replace: (id: string, replacement: () => any) => void; | ||
block: (p: Promise<any>) => void; | ||
resources: Record<string, any>; | ||
suspense: Record<string, SuspenseContextType>; | ||
registerFragment: (v: string) => (v?: string, err?: any) => boolean; | ||
lazy: Record<string, Promise<any>>; | ||
async?: boolean; | ||
noHydrate: boolean; | ||
id: string; | ||
count: number; | ||
writeResource: ( | ||
id: string, | ||
v: Promise<any> | any, | ||
error?: boolean, | ||
deferStream?: boolean | ||
) => void; | ||
replace: (id: string, replacement: () => any) => void; | ||
block: (p: Promise<any>) => void; | ||
resources: Record<string, any>; | ||
suspense: Record<string, SuspenseContextType>; | ||
registerFragment: (v: string) => (v?: string, err?: any) => boolean; | ||
lazy: Record<string, Promise<any>>; | ||
async?: boolean; | ||
noHydrate: boolean; | ||
}; | ||
export declare function SuspenseList(props: { | ||
children: string; | ||
revealOrder: "forwards" | "backwards" | "together"; | ||
tail?: "collapsed" | "hidden"; | ||
children: string; | ||
revealOrder: "forwards" | "backwards" | "together"; | ||
tail?: "collapsed" | "hidden"; | ||
}): string; | ||
export declare function Suspense(props: { | ||
fallback?: string; | ||
children: string; | ||
}): string | number | boolean | Node | JSX.ArrayElement | { | ||
t: string; | ||
} | null | undefined; | ||
export declare function Suspense(props: { fallback?: string; children: string }): | ||
| string | ||
| number | ||
| boolean | ||
| Node | ||
| JSX.ArrayElement | ||
| { | ||
t: string; | ||
} | ||
| null | ||
| undefined; | ||
export {}; |
@@ -1,2 +0,9 @@ | ||
import { createRoot, createRenderEffect, mergeProps, createMemo, createComponent, untrack } from 'solid-js'; | ||
import { | ||
createRoot, | ||
createRenderEffect, | ||
mergeProps, | ||
createMemo, | ||
createComponent, | ||
untrack | ||
} from "solid-js"; | ||
@@ -35,3 +42,3 @@ function createRenderer$1({ | ||
if (current !== "" && typeof current === "string") { | ||
replaceText(getFirstChild(parent), current = value); | ||
replaceText(getFirstChild(parent), (current = value)); | ||
} else { | ||
@@ -54,3 +61,5 @@ cleanChildren(parent, current, marker, createTextNode(value)); | ||
if (normalizeIncomingArray(array, value, unwrapArray)) { | ||
createRenderEffect(() => current = insertExpression(parent, array, current, marker, true)); | ||
createRenderEffect( | ||
() => (current = insertExpression(parent, array, current, marker, true)) | ||
); | ||
return () => current; | ||
@@ -60,3 +69,3 @@ } | ||
const replacement = cleanChildren(parent, current, marker); | ||
if (multi) return current = replacement; | ||
if (multi) return (current = replacement); | ||
} else { | ||
@@ -70,3 +79,3 @@ if (Array.isArray(current)) { | ||
} else { | ||
reconcileArrays(parent, multi && current || [getFirstChild(parent)], array); | ||
reconcileArrays(parent, (multi && current) || [getFirstChild(parent)], array); | ||
} | ||
@@ -77,3 +86,3 @@ } | ||
if (Array.isArray(current)) { | ||
if (multi) return current = cleanChildren(parent, current, marker, value); | ||
if (multi) return (current = cleanChildren(parent, current, marker, value)); | ||
cleanChildren(parent, current, null, value); | ||
@@ -92,3 +101,4 @@ } else if (current == null || current === "" || !getFirstChild(parent)) { | ||
t; | ||
if (item == null || item === true || item === false) ; else if (Array.isArray(item)) { | ||
if (item == null || item === true || item === false); | ||
else if (Array.isArray(item)) { | ||
dynamic = normalizeIncomingArray(normalized, item) || dynamic; | ||
@@ -100,3 +110,4 @@ } else if ((t = typeof item) === "string" || t === "number") { | ||
while (typeof item === "function") item = item(); | ||
dynamic = normalizeIncomingArray(normalized, Array.isArray(item) ? item : [item]) || dynamic; | ||
dynamic = | ||
normalizeIncomingArray(normalized, Array.isArray(item) ? item : [item]) || dynamic; | ||
} else { | ||
@@ -129,3 +140,4 @@ normalized.push(item); | ||
if (aEnd === aStart) { | ||
const node = bEnd < bLength ? bStart ? getNextSibling(b[bStart - 1]) : b[bEnd - bStart] : after; | ||
const node = | ||
bEnd < bLength ? (bStart ? getNextSibling(b[bStart - 1]) : b[bEnd - bStart]) : after; | ||
while (bStart < bEnd) insertNode(parentNode, b[bStart++], node); | ||
@@ -170,3 +182,3 @@ } else if (bEnd === bStart) { | ||
let removed; | ||
while (removed = getFirstChild(parent)) removeNode(parent, removed); | ||
while ((removed = getFirstChild(parent))) removeNode(parent, removed); | ||
replacement && insertNode(parent, replacement); | ||
@@ -182,3 +194,5 @@ return ""; | ||
const isParent = getParentNode(el) === parent; | ||
if (!inserted && !i) isParent ? replaceNode(parent, node, el) : insertNode(parent, node, marker);else isParent && removeNode(parent, el); | ||
if (!inserted && !i) | ||
isParent ? replaceNode(parent, node, el) : insertNode(parent, node, marker); | ||
else isParent && removeNode(parent, el); | ||
} else inserted = true; | ||
@@ -199,3 +213,5 @@ } | ||
if (!skipChildren) { | ||
createRenderEffect(() => prevProps.children = insertExpression(node, props.children, prevProps.children)); | ||
createRenderEffect( | ||
() => (prevProps.children = insertExpression(node, props.children, prevProps.children)) | ||
); | ||
} | ||
@@ -202,0 +218,0 @@ createRenderEffect(() => props.ref && props.ref(node)); |
@@ -1,2 +0,9 @@ | ||
import { createRoot, createRenderEffect, mergeProps, createMemo, createComponent, untrack } from 'solid-js'; | ||
import { | ||
createRoot, | ||
createRenderEffect, | ||
mergeProps, | ||
createMemo, | ||
createComponent, | ||
untrack | ||
} from "solid-js"; | ||
@@ -35,3 +42,3 @@ function createRenderer$1({ | ||
if (current !== "" && typeof current === "string") { | ||
replaceText(getFirstChild(parent), current = value); | ||
replaceText(getFirstChild(parent), (current = value)); | ||
} else { | ||
@@ -54,3 +61,5 @@ cleanChildren(parent, current, marker, createTextNode(value)); | ||
if (normalizeIncomingArray(array, value, unwrapArray)) { | ||
createRenderEffect(() => current = insertExpression(parent, array, current, marker, true)); | ||
createRenderEffect( | ||
() => (current = insertExpression(parent, array, current, marker, true)) | ||
); | ||
return () => current; | ||
@@ -60,3 +69,3 @@ } | ||
const replacement = cleanChildren(parent, current, marker); | ||
if (multi) return current = replacement; | ||
if (multi) return (current = replacement); | ||
} else { | ||
@@ -70,3 +79,3 @@ if (Array.isArray(current)) { | ||
} else { | ||
reconcileArrays(parent, multi && current || [getFirstChild(parent)], array); | ||
reconcileArrays(parent, (multi && current) || [getFirstChild(parent)], array); | ||
} | ||
@@ -77,3 +86,3 @@ } | ||
if (Array.isArray(current)) { | ||
if (multi) return current = cleanChildren(parent, current, marker, value); | ||
if (multi) return (current = cleanChildren(parent, current, marker, value)); | ||
cleanChildren(parent, current, null, value); | ||
@@ -92,3 +101,4 @@ } else if (current == null || current === "" || !getFirstChild(parent)) { | ||
t; | ||
if (item == null || item === true || item === false) ; else if (Array.isArray(item)) { | ||
if (item == null || item === true || item === false); | ||
else if (Array.isArray(item)) { | ||
dynamic = normalizeIncomingArray(normalized, item) || dynamic; | ||
@@ -100,3 +110,4 @@ } else if ((t = typeof item) === "string" || t === "number") { | ||
while (typeof item === "function") item = item(); | ||
dynamic = normalizeIncomingArray(normalized, Array.isArray(item) ? item : [item]) || dynamic; | ||
dynamic = | ||
normalizeIncomingArray(normalized, Array.isArray(item) ? item : [item]) || dynamic; | ||
} else { | ||
@@ -129,3 +140,4 @@ normalized.push(item); | ||
if (aEnd === aStart) { | ||
const node = bEnd < bLength ? bStart ? getNextSibling(b[bStart - 1]) : b[bEnd - bStart] : after; | ||
const node = | ||
bEnd < bLength ? (bStart ? getNextSibling(b[bStart - 1]) : b[bEnd - bStart]) : after; | ||
while (bStart < bEnd) insertNode(parentNode, b[bStart++], node); | ||
@@ -170,3 +182,3 @@ } else if (bEnd === bStart) { | ||
let removed; | ||
while (removed = getFirstChild(parent)) removeNode(parent, removed); | ||
while ((removed = getFirstChild(parent))) removeNode(parent, removed); | ||
replacement && insertNode(parent, replacement); | ||
@@ -182,3 +194,5 @@ return ""; | ||
const isParent = getParentNode(el) === parent; | ||
if (!inserted && !i) isParent ? replaceNode(parent, node, el) : insertNode(parent, node, marker);else isParent && removeNode(parent, el); | ||
if (!inserted && !i) | ||
isParent ? replaceNode(parent, node, el) : insertNode(parent, node, marker); | ||
else isParent && removeNode(parent, el); | ||
} else inserted = true; | ||
@@ -199,3 +213,5 @@ } | ||
if (!skipChildren) { | ||
createRenderEffect(() => prevProps.children = insertExpression(node, props.children, prevProps.children)); | ||
createRenderEffect( | ||
() => (prevProps.children = insertExpression(node, props.children, prevProps.children)) | ||
); | ||
} | ||
@@ -202,0 +218,0 @@ createRenderEffect(() => props.ref && props.ref(node)); |
import type { RendererOptions, Renderer } from "./universal.js"; | ||
export declare function createRenderer<NodeType>(options: RendererOptions<NodeType>): Renderer<NodeType>; | ||
export declare function createRenderer<NodeType>( | ||
options: RendererOptions<NodeType> | ||
): Renderer<NodeType>; |
@@ -30,2 +30,1 @@ export interface RendererOptions<NodeType> { | ||
export function createRenderer<NodeType>(options: RendererOptions<NodeType>): Renderer<NodeType>; | ||
@@ -1,12 +0,80 @@ | ||
import { createRoot, createRenderEffect, sharedConfig, untrack, enableHydration, getOwner, createEffect, runWithOwner, createMemo, createSignal, onCleanup, splitProps, $DEVCOMP } from 'solid-js'; | ||
export { ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, createComponent, createRenderEffect as effect, getOwner, createMemo as memo, mergeProps, untrack } from 'solid-js'; | ||
import { | ||
createRoot, | ||
createRenderEffect, | ||
sharedConfig, | ||
untrack, | ||
enableHydration, | ||
getOwner, | ||
createEffect, | ||
runWithOwner, | ||
createMemo, | ||
createSignal, | ||
onCleanup, | ||
splitProps, | ||
$DEVCOMP | ||
} from "solid-js"; | ||
export { | ||
ErrorBoundary, | ||
For, | ||
Index, | ||
Match, | ||
Show, | ||
Suspense, | ||
SuspenseList, | ||
Switch, | ||
createComponent, | ||
createRenderEffect as effect, | ||
getOwner, | ||
createMemo as memo, | ||
mergeProps, | ||
untrack | ||
} from "solid-js"; | ||
const booleans = ["allowfullscreen", "async", "autofocus", "autoplay", "checked", "controls", "default", "disabled", "formnovalidate", "hidden", "indeterminate", "ismap", "loop", "multiple", "muted", "nomodule", "novalidate", "open", "playsinline", "readonly", "required", "reversed", "seamless", "selected"]; | ||
const Properties = /*#__PURE__*/new Set(["className", "value", "readOnly", "formNoValidate", "isMap", "noModule", "playsInline", ...booleans]); | ||
const ChildProperties = /*#__PURE__*/new Set(["innerHTML", "textContent", "innerText", "children"]); | ||
const Aliases = /*#__PURE__*/Object.assign(Object.create(null), { | ||
const booleans = [ | ||
"allowfullscreen", | ||
"async", | ||
"autofocus", | ||
"autoplay", | ||
"checked", | ||
"controls", | ||
"default", | ||
"disabled", | ||
"formnovalidate", | ||
"hidden", | ||
"indeterminate", | ||
"ismap", | ||
"loop", | ||
"multiple", | ||
"muted", | ||
"nomodule", | ||
"novalidate", | ||
"open", | ||
"playsinline", | ||
"readonly", | ||
"required", | ||
"reversed", | ||
"seamless", | ||
"selected" | ||
]; | ||
const Properties = /*#__PURE__*/ new Set([ | ||
"className", | ||
"value", | ||
"readOnly", | ||
"formNoValidate", | ||
"isMap", | ||
"noModule", | ||
"playsInline", | ||
...booleans | ||
]); | ||
const ChildProperties = /*#__PURE__*/ new Set([ | ||
"innerHTML", | ||
"textContent", | ||
"innerText", | ||
"children" | ||
]); | ||
const Aliases = /*#__PURE__*/ Object.assign(Object.create(null), { | ||
className: "class", | ||
htmlFor: "for" | ||
}); | ||
const PropAliases = /*#__PURE__*/Object.assign(Object.create(null), { | ||
const PropAliases = /*#__PURE__*/ Object.assign(Object.create(null), { | ||
class: "className", | ||
@@ -38,10 +106,106 @@ formnovalidate: { | ||
const a = PropAliases[prop]; | ||
return typeof a === "object" ? a[tagName] ? a["$"] : undefined : a; | ||
return typeof a === "object" ? (a[tagName] ? a["$"] : undefined) : a; | ||
} | ||
const DelegatedEvents = /*#__PURE__*/new Set(["beforeinput", "click", "dblclick", "contextmenu", "focusin", "focusout", "input", "keydown", "keyup", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup", "pointerdown", "pointermove", "pointerout", "pointerover", "pointerup", "touchend", "touchmove", "touchstart"]); | ||
const SVGElements = /*#__PURE__*/new Set([ | ||
"altGlyph", "altGlyphDef", "altGlyphItem", "animate", "animateColor", "animateMotion", "animateTransform", "circle", "clipPath", "color-profile", "cursor", "defs", "desc", "ellipse", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence", "filter", "font", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "foreignObject", "g", "glyph", "glyphRef", "hkern", "image", "line", "linearGradient", "marker", "mask", "metadata", "missing-glyph", "mpath", "path", "pattern", "polygon", "polyline", "radialGradient", "rect", | ||
"set", "stop", | ||
"svg", "switch", "symbol", "text", "textPath", | ||
"tref", "tspan", "use", "view", "vkern"]); | ||
const DelegatedEvents = /*#__PURE__*/ new Set([ | ||
"beforeinput", | ||
"click", | ||
"dblclick", | ||
"contextmenu", | ||
"focusin", | ||
"focusout", | ||
"input", | ||
"keydown", | ||
"keyup", | ||
"mousedown", | ||
"mousemove", | ||
"mouseout", | ||
"mouseover", | ||
"mouseup", | ||
"pointerdown", | ||
"pointermove", | ||
"pointerout", | ||
"pointerover", | ||
"pointerup", | ||
"touchend", | ||
"touchmove", | ||
"touchstart" | ||
]); | ||
const SVGElements = /*#__PURE__*/ new Set([ | ||
"altGlyph", | ||
"altGlyphDef", | ||
"altGlyphItem", | ||
"animate", | ||
"animateColor", | ||
"animateMotion", | ||
"animateTransform", | ||
"circle", | ||
"clipPath", | ||
"color-profile", | ||
"cursor", | ||
"defs", | ||
"desc", | ||
"ellipse", | ||
"feBlend", | ||
"feColorMatrix", | ||
"feComponentTransfer", | ||
"feComposite", | ||
"feConvolveMatrix", | ||
"feDiffuseLighting", | ||
"feDisplacementMap", | ||
"feDistantLight", | ||
"feFlood", | ||
"feFuncA", | ||
"feFuncB", | ||
"feFuncG", | ||
"feFuncR", | ||
"feGaussianBlur", | ||
"feImage", | ||
"feMerge", | ||
"feMergeNode", | ||
"feMorphology", | ||
"feOffset", | ||
"fePointLight", | ||
"feSpecularLighting", | ||
"feSpotLight", | ||
"feTile", | ||
"feTurbulence", | ||
"filter", | ||
"font", | ||
"font-face", | ||
"font-face-format", | ||
"font-face-name", | ||
"font-face-src", | ||
"font-face-uri", | ||
"foreignObject", | ||
"g", | ||
"glyph", | ||
"glyphRef", | ||
"hkern", | ||
"image", | ||
"line", | ||
"linearGradient", | ||
"marker", | ||
"mask", | ||
"metadata", | ||
"missing-glyph", | ||
"mpath", | ||
"path", | ||
"pattern", | ||
"polygon", | ||
"polyline", | ||
"radialGradient", | ||
"rect", | ||
"set", | ||
"stop", | ||
"svg", | ||
"switch", | ||
"symbol", | ||
"text", | ||
"textPath", | ||
"tref", | ||
"tspan", | ||
"use", | ||
"view", | ||
"vkern" | ||
]); | ||
const SVGNamespace = { | ||
@@ -51,3 +215,283 @@ xlink: "http://www.w3.org/1999/xlink", | ||
}; | ||
const DOMElements = /*#__PURE__*/new Set(["html", "base", "head", "link", "meta", "style", "title", "body", "address", "article", "aside", "footer", "header", "main", "nav", "section", "body", "blockquote", "dd", "div", "dl", "dt", "figcaption", "figure", "hr", "li", "ol", "p", "pre", "ul", "a", "abbr", "b", "bdi", "bdo", "br", "cite", "code", "data", "dfn", "em", "i", "kbd", "mark", "q", "rp", "rt", "ruby", "s", "samp", "small", "span", "strong", "sub", "sup", "time", "u", "var", "wbr", "area", "audio", "img", "map", "track", "video", "embed", "iframe", "object", "param", "picture", "portal", "source", "svg", "math", "canvas", "noscript", "script", "del", "ins", "caption", "col", "colgroup", "table", "tbody", "td", "tfoot", "th", "thead", "tr", "button", "datalist", "fieldset", "form", "input", "label", "legend", "meter", "optgroup", "option", "output", "progress", "select", "textarea", "details", "dialog", "menu", "summary", "details", "slot", "template", "acronym", "applet", "basefont", "bgsound", "big", "blink", "center", "content", "dir", "font", "frame", "frameset", "hgroup", "image", "keygen", "marquee", "menuitem", "nobr", "noembed", "noframes", "plaintext", "rb", "rtc", "shadow", "spacer", "strike", "tt", "xmp", "a", "abbr", "acronym", "address", "applet", "area", "article", "aside", "audio", "b", "base", "basefont", "bdi", "bdo", "bgsound", "big", "blink", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "content", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "font", "footer", "form", "frame", "frameset", "head", "header", "hgroup", "hr", "html", "i", "iframe", "image", "img", "input", "ins", "kbd", "keygen", "label", "legend", "li", "link", "main", "map", "mark", "marquee", "menu", "menuitem", "meta", "meter", "nav", "nobr", "noembed", "noframes", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "picture", "plaintext", "portal", "pre", "progress", "q", "rb", "rp", "rt", "rtc", "ruby", "s", "samp", "script", "section", "select", "shadow", "slot", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "tt", "u", "ul", "var", "video", "wbr", "xmp", "input", "h1", "h2", "h3", "h4", "h5", "h6"]); | ||
const DOMElements = /*#__PURE__*/ new Set([ | ||
"html", | ||
"base", | ||
"head", | ||
"link", | ||
"meta", | ||
"style", | ||
"title", | ||
"body", | ||
"address", | ||
"article", | ||
"aside", | ||
"footer", | ||
"header", | ||
"main", | ||
"nav", | ||
"section", | ||
"body", | ||
"blockquote", | ||
"dd", | ||
"div", | ||
"dl", | ||
"dt", | ||
"figcaption", | ||
"figure", | ||
"hr", | ||
"li", | ||
"ol", | ||
"p", | ||
"pre", | ||
"ul", | ||
"a", | ||
"abbr", | ||
"b", | ||
"bdi", | ||
"bdo", | ||
"br", | ||
"cite", | ||
"code", | ||
"data", | ||
"dfn", | ||
"em", | ||
"i", | ||
"kbd", | ||
"mark", | ||
"q", | ||
"rp", | ||
"rt", | ||
"ruby", | ||
"s", | ||
"samp", | ||
"small", | ||
"span", | ||
"strong", | ||
"sub", | ||
"sup", | ||
"time", | ||
"u", | ||
"var", | ||
"wbr", | ||
"area", | ||
"audio", | ||
"img", | ||
"map", | ||
"track", | ||
"video", | ||
"embed", | ||
"iframe", | ||
"object", | ||
"param", | ||
"picture", | ||
"portal", | ||
"source", | ||
"svg", | ||
"math", | ||
"canvas", | ||
"noscript", | ||
"script", | ||
"del", | ||
"ins", | ||
"caption", | ||
"col", | ||
"colgroup", | ||
"table", | ||
"tbody", | ||
"td", | ||
"tfoot", | ||
"th", | ||
"thead", | ||
"tr", | ||
"button", | ||
"datalist", | ||
"fieldset", | ||
"form", | ||
"input", | ||
"label", | ||
"legend", | ||
"meter", | ||
"optgroup", | ||
"option", | ||
"output", | ||
"progress", | ||
"select", | ||
"textarea", | ||
"details", | ||
"dialog", | ||
"menu", | ||
"summary", | ||
"details", | ||
"slot", | ||
"template", | ||
"acronym", | ||
"applet", | ||
"basefont", | ||
"bgsound", | ||
"big", | ||
"blink", | ||
"center", | ||
"content", | ||
"dir", | ||
"font", | ||
"frame", | ||
"frameset", | ||
"hgroup", | ||
"image", | ||
"keygen", | ||
"marquee", | ||
"menuitem", | ||
"nobr", | ||
"noembed", | ||
"noframes", | ||
"plaintext", | ||
"rb", | ||
"rtc", | ||
"shadow", | ||
"spacer", | ||
"strike", | ||
"tt", | ||
"xmp", | ||
"a", | ||
"abbr", | ||
"acronym", | ||
"address", | ||
"applet", | ||
"area", | ||
"article", | ||
"aside", | ||
"audio", | ||
"b", | ||
"base", | ||
"basefont", | ||
"bdi", | ||
"bdo", | ||
"bgsound", | ||
"big", | ||
"blink", | ||
"blockquote", | ||
"body", | ||
"br", | ||
"button", | ||
"canvas", | ||
"caption", | ||
"center", | ||
"cite", | ||
"code", | ||
"col", | ||
"colgroup", | ||
"content", | ||
"data", | ||
"datalist", | ||
"dd", | ||
"del", | ||
"details", | ||
"dfn", | ||
"dialog", | ||
"dir", | ||
"div", | ||
"dl", | ||
"dt", | ||
"em", | ||
"embed", | ||
"fieldset", | ||
"figcaption", | ||
"figure", | ||
"font", | ||
"footer", | ||
"form", | ||
"frame", | ||
"frameset", | ||
"head", | ||
"header", | ||
"hgroup", | ||
"hr", | ||
"html", | ||
"i", | ||
"iframe", | ||
"image", | ||
"img", | ||
"input", | ||
"ins", | ||
"kbd", | ||
"keygen", | ||
"label", | ||
"legend", | ||
"li", | ||
"link", | ||
"main", | ||
"map", | ||
"mark", | ||
"marquee", | ||
"menu", | ||
"menuitem", | ||
"meta", | ||
"meter", | ||
"nav", | ||
"nobr", | ||
"noembed", | ||
"noframes", | ||
"noscript", | ||
"object", | ||
"ol", | ||
"optgroup", | ||
"option", | ||
"output", | ||
"p", | ||
"param", | ||
"picture", | ||
"plaintext", | ||
"portal", | ||
"pre", | ||
"progress", | ||
"q", | ||
"rb", | ||
"rp", | ||
"rt", | ||
"rtc", | ||
"ruby", | ||
"s", | ||
"samp", | ||
"script", | ||
"section", | ||
"select", | ||
"shadow", | ||
"slot", | ||
"small", | ||
"source", | ||
"spacer", | ||
"span", | ||
"strike", | ||
"strong", | ||
"style", | ||
"sub", | ||
"summary", | ||
"sup", | ||
"table", | ||
"tbody", | ||
"td", | ||
"template", | ||
"textarea", | ||
"tfoot", | ||
"th", | ||
"thead", | ||
"time", | ||
"title", | ||
"tr", | ||
"track", | ||
"tt", | ||
"u", | ||
"ul", | ||
"var", | ||
"video", | ||
"wbr", | ||
"xmp", | ||
"input", | ||
"h1", | ||
"h2", | ||
"h3", | ||
"h4", | ||
"h5", | ||
"h6" | ||
]); | ||
@@ -73,3 +517,3 @@ function reconcileArrays(parentNode, a, b) { | ||
if (aEnd === aStart) { | ||
const node = bEnd < bLength ? bStart ? b[bStart - 1].nextSibling : b[bEnd - bStart] : after; | ||
const node = bEnd < bLength ? (bStart ? b[bStart - 1].nextSibling : b[bEnd - bStart]) : after; | ||
while (bStart < bEnd) parentNode.insertBefore(b[bStart++], node); | ||
@@ -117,3 +561,5 @@ } else if (bEnd === bStart) { | ||
disposer = dispose; | ||
element === document ? code() : insert(element, code(), element.firstChild ? null : undefined, init); | ||
element === document | ||
? code() | ||
: insert(element, code(), element.firstChild ? null : undefined, init); | ||
}, options.owner); | ||
@@ -132,3 +578,5 @@ return () => { | ||
}; | ||
const fn = isCE ? () => untrack(() => document.importNode(node || (node = create()), true)) : () => (node || (node = create())).cloneNode(true); | ||
const fn = isCE | ||
? () => untrack(() => document.importNode(node || (node = create()), true)) | ||
: () => (node || (node = create())).cloneNode(true); | ||
fn.cloneNode = fn; | ||
@@ -154,9 +602,12 @@ return fn; | ||
function setAttribute(node, name, value) { | ||
if (value == null) node.removeAttribute(name);else node.setAttribute(name, value); | ||
if (value == null) node.removeAttribute(name); | ||
else node.setAttribute(name, value); | ||
} | ||
function setAttributeNS(node, namespace, name, value) { | ||
if (value == null) node.removeAttributeNS(namespace, name);else node.setAttributeNS(namespace, name, value); | ||
if (value == null) node.removeAttributeNS(namespace, name); | ||
else node.setAttributeNS(namespace, name, value); | ||
} | ||
function className(node, value) { | ||
if (value == null) node.removeAttribute("class");else node.className = value; | ||
if (value == null) node.removeAttribute("class"); | ||
else node.className = value; | ||
} | ||
@@ -171,3 +622,3 @@ function addEventListener(node, name, handler, delegate) { | ||
const handlerFn = handler[0]; | ||
node.addEventListener(name, handler[0] = e => handlerFn.call(node, handler[1], e)); | ||
node.addEventListener(name, (handler[0] = e => handlerFn.call(node, handler[1], e))); | ||
} else node.addEventListener(name, handler); | ||
@@ -197,3 +648,3 @@ } | ||
const nodeStyle = node.style; | ||
if (typeof value === "string") return nodeStyle.cssText = value; | ||
if (typeof value === "string") return (nodeStyle.cssText = value); | ||
typeof prev === "string" && (nodeStyle.cssText = prev = undefined); | ||
@@ -219,3 +670,5 @@ prev || (prev = {}); | ||
if (!skipChildren) { | ||
createRenderEffect(() => prevProps.children = insertExpression(node, props.children, prevProps.children)); | ||
createRenderEffect( | ||
() => (prevProps.children = insertExpression(node, props.children, prevProps.children)) | ||
); | ||
} | ||
@@ -281,3 +734,3 @@ createRenderEffect(() => props.ref && props.ref(node)); | ||
let node, key; | ||
if (!sharedConfig.context || !(node = sharedConfig.registry.get(key = getHydrationKey()))) { | ||
if (!sharedConfig.context || !(node = sharedConfig.registry.get((key = getHydrationKey())))) { | ||
if (sharedConfig.context) console.warn("Unable to find DOM nodes for hydration key:", key); | ||
@@ -303,3 +756,4 @@ if (!template) throw new Error("Unrecoverable Hydration Mismatch. No template for key: " + key); | ||
const v = end.nodeValue; | ||
if (v === "#") count++;else if (v === "/") { | ||
if (v === "#") count++; | ||
else if (v === "/") { | ||
if (count === 0) return [end, current]; | ||
@@ -318,6 +772,3 @@ count--; | ||
queueMicrotask(() => { | ||
const { | ||
completed, | ||
events | ||
} = sharedConfig; | ||
const { completed, events } = sharedConfig; | ||
events.queued = false; | ||
@@ -339,3 +790,4 @@ while (events.length) { | ||
const classNames = key.trim().split(/\s+/); | ||
for (let i = 0, nameLen = classNames.length; i < nameLen; i++) node.classList.toggle(classNames[i], value); | ||
for (let i = 0, nameLen = classNames.length; i < nameLen; i++) | ||
node.classList.toggle(classNames[i], value); | ||
} | ||
@@ -370,3 +822,9 @@ function assignProp(node, prop, value, prev, isSVG, skipRef) { | ||
setAttribute(node, prop.slice(5), value); | ||
} else if ((forceProp = prop.slice(0, 5) === "prop:") || (isChildProp = ChildProperties.has(prop)) || !isSVG && ((propAlias = getPropAlias(prop, node.tagName)) || (isProp = Properties.has(prop))) || (isCE = node.nodeName.includes("-"))) { | ||
} else if ( | ||
(forceProp = prop.slice(0, 5) === "prop:") || | ||
(isChildProp = ChildProperties.has(prop)) || | ||
(!isSVG && | ||
((propAlias = getPropAlias(prop, node.tagName)) || (isProp = Properties.has(prop)))) || | ||
(isCE = node.nodeName.includes("-")) | ||
) { | ||
if (forceProp) { | ||
@@ -376,6 +834,9 @@ prop = prop.slice(5); | ||
} | ||
if (prop === "class" || prop === "className") className(node, value);else if (isCE && !isProp && !isChildProp) node[toPropertyName(prop)] = value;else node[propAlias || prop] = value; | ||
if (prop === "class" || prop === "className") className(node, value); | ||
else if (isCE && !isProp && !isChildProp) node[toPropertyName(prop)] = value; | ||
else node[propAlias || prop] = value; | ||
} else { | ||
const ns = isSVG && prop.indexOf(":") > -1 && SVGNamespace[prop.split(":")[0]]; | ||
if (ns) setAttributeNS(node, ns, prop, value);else setAttribute(node, Aliases[prop] || prop, value); | ||
if (ns) setAttributeNS(node, ns, prop, value); | ||
else setAttribute(node, Aliases[prop] || prop, value); | ||
} | ||
@@ -386,3 +847,3 @@ return value; | ||
const key = `$$${e.type}`; | ||
let node = e.composedPath && e.composedPath()[0] || e.target; | ||
let node = (e.composedPath && e.composedPath()[0]) || e.target; | ||
if (e.target !== node) { | ||
@@ -417,3 +878,4 @@ Object.defineProperty(e, "target", { | ||
const node = current[i]; | ||
if (node.nodeType === 8 && node.data.slice(0, 2) === "!$") node.remove();else cleaned.push(node); | ||
if (node.nodeType === 8 && node.data.slice(0, 2) === "!$") node.remove(); | ||
else cleaned.push(node); | ||
} | ||
@@ -426,3 +888,3 @@ current = cleaned; | ||
multi = marker !== undefined; | ||
parent = multi && current[0] && current[0].parentNode || parent; | ||
parent = (multi && current[0] && current[0].parentNode) || parent; | ||
if (t === "string" || t === "number") { | ||
@@ -456,3 +918,3 @@ if (sharedConfig.context) return current; | ||
if (normalizeIncomingArray(array, value, current, unwrapArray)) { | ||
createRenderEffect(() => current = insertExpression(parent, array, current, marker, true)); | ||
createRenderEffect(() => (current = insertExpression(parent, array, current, marker, true))); | ||
return () => current; | ||
@@ -463,3 +925,3 @@ } | ||
for (let i = 0; i < array.length; i++) { | ||
if (array[i].parentNode) return current = array; | ||
if (array[i].parentNode) return (current = array); | ||
} | ||
@@ -480,5 +942,5 @@ } | ||
} else if (value.nodeType) { | ||
if (sharedConfig.context && value.parentNode) return current = multi ? [value] : value; | ||
if (sharedConfig.context && value.parentNode) return (current = multi ? [value] : value); | ||
if (Array.isArray(current)) { | ||
if (multi) return current = cleanChildren(parent, current, marker, value); | ||
if (multi) return (current = cleanChildren(parent, current, marker, value)); | ||
cleanChildren(parent, current, null, value); | ||
@@ -498,3 +960,4 @@ } else if (current == null || current === "" || !parent.firstChild) { | ||
t; | ||
if (item == null || item === true || item === false) ; else if ((t = typeof item) === "object" && item.nodeType) { | ||
if (item == null || item === true || item === false); | ||
else if ((t = typeof item) === "object" && item.nodeType) { | ||
normalized.push(item); | ||
@@ -506,3 +969,8 @@ } else if (Array.isArray(item)) { | ||
while (typeof item === "function") item = item(); | ||
dynamic = normalizeIncomingArray(normalized, Array.isArray(item) ? item : [item], Array.isArray(prev) ? prev : [prev]) || dynamic; | ||
dynamic = | ||
normalizeIncomingArray( | ||
normalized, | ||
Array.isArray(item) ? item : [item], | ||
Array.isArray(prev) ? prev : [prev] | ||
) || dynamic; | ||
} else { | ||
@@ -514,3 +982,4 @@ normalized.push(item); | ||
const value = String(item); | ||
if (prev && prev.nodeType === 3 && prev.data === value) normalized.push(prev);else normalized.push(document.createTextNode(value)); | ||
if (prev && prev.nodeType === 3 && prev.data === value) normalized.push(prev); | ||
else normalized.push(document.createTextNode(value)); | ||
} | ||
@@ -524,3 +993,3 @@ } | ||
function cleanChildren(parent, current, marker, replacement) { | ||
if (marker === undefined) return parent.textContent = ""; | ||
if (marker === undefined) return (parent.textContent = ""); | ||
const node = replacement || document.createTextNode(""); | ||
@@ -533,3 +1002,5 @@ if (current.length) { | ||
const isParent = el.parentNode === parent; | ||
if (!inserted && !i) isParent ? parent.replaceChild(node, el) : parent.insertBefore(node, marker);else isParent && el.remove(); | ||
if (!inserted && !i) | ||
isParent ? parent.replaceChild(node, el) : parent.insertBefore(node, marker); | ||
else isParent && el.remove(); | ||
} else inserted = true; | ||
@@ -545,3 +1016,4 @@ } | ||
const key = node.getAttribute("data-hk"); | ||
if ((!root || key.startsWith(root)) && !sharedConfig.registry.has(key)) sharedConfig.registry.set(key, node); | ||
if ((!root || key.startsWith(root)) && !sharedConfig.registry.has(key)) | ||
sharedConfig.registry.set(key, node); | ||
} | ||
@@ -595,5 +1067,3 @@ } | ||
function Portal(props) { | ||
const { | ||
useShadow | ||
} = props, | ||
const { useShadow } = props, | ||
marker = document.createTextNode(""), | ||
@@ -604,30 +1074,37 @@ mount = () => props.mount || document.body, | ||
let hydrating = !!sharedConfig.context; | ||
createEffect(() => { | ||
if (hydrating) getOwner().user = hydrating = false; | ||
content || (content = runWithOwner(owner, () => createMemo(() => props.children))); | ||
const el = mount(); | ||
if (el instanceof HTMLHeadElement) { | ||
const [clean, setClean] = createSignal(false); | ||
const cleanup = () => setClean(true); | ||
createRoot(dispose => insert(el, () => !clean() ? content() : dispose(), null)); | ||
onCleanup(cleanup); | ||
} else { | ||
const container = createElement(props.isSVG ? "g" : "div", props.isSVG), | ||
renderRoot = useShadow && container.attachShadow ? container.attachShadow({ | ||
mode: "open" | ||
}) : container; | ||
Object.defineProperty(container, "_$host", { | ||
get() { | ||
return marker.parentNode; | ||
}, | ||
configurable: true | ||
}); | ||
insert(renderRoot, content); | ||
el.appendChild(container); | ||
props.ref && props.ref(container); | ||
onCleanup(() => el.removeChild(container)); | ||
createEffect( | ||
() => { | ||
if (hydrating) getOwner().user = hydrating = false; | ||
content || (content = runWithOwner(owner, () => createMemo(() => props.children))); | ||
const el = mount(); | ||
if (el instanceof HTMLHeadElement) { | ||
const [clean, setClean] = createSignal(false); | ||
const cleanup = () => setClean(true); | ||
createRoot(dispose => insert(el, () => (!clean() ? content() : dispose()), null)); | ||
onCleanup(cleanup); | ||
} else { | ||
const container = createElement(props.isSVG ? "g" : "div", props.isSVG), | ||
renderRoot = | ||
useShadow && container.attachShadow | ||
? container.attachShadow({ | ||
mode: "open" | ||
}) | ||
: container; | ||
Object.defineProperty(container, "_$host", { | ||
get() { | ||
return marker.parentNode; | ||
}, | ||
configurable: true | ||
}); | ||
insert(renderRoot, content); | ||
el.appendChild(container); | ||
props.ref && props.ref(container); | ||
onCleanup(() => el.removeChild(container)); | ||
} | ||
}, | ||
undefined, | ||
{ | ||
render: !hydrating | ||
} | ||
}, undefined, { | ||
render: !hydrating | ||
}); | ||
); | ||
return marker; | ||
@@ -655,2 +1132,56 @@ } | ||
export { Aliases, voidFn as Assets, ChildProperties, DOMElements, DelegatedEvents, Dynamic, Hydration, voidFn as HydrationScript, NoHydration, Portal, Properties, SVGElements, SVGNamespace, addEventListener, assign, classList, className, clearDelegatedEvents, delegateEvents, dynamicProperty, escape, voidFn as generateHydrationScript, voidFn as getAssets, getHydrationKey, getNextElement, getNextMarker, getNextMatch, getPropAlias, hydrate, innerHTML, insert, isDev, isServer, render, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, runHydrationEvents, setAttribute, setAttributeNS, spread, ssr, ssrAttribute, ssrClassList, ssrElement, ssrHydrationKey, ssrSpread, ssrStyle, style, template, use, voidFn as useAssets }; | ||
export { | ||
Aliases, | ||
voidFn as Assets, | ||
ChildProperties, | ||
DOMElements, | ||
DelegatedEvents, | ||
Dynamic, | ||
Hydration, | ||
voidFn as HydrationScript, | ||
NoHydration, | ||
Portal, | ||
Properties, | ||
SVGElements, | ||
SVGNamespace, | ||
addEventListener, | ||
assign, | ||
classList, | ||
className, | ||
clearDelegatedEvents, | ||
delegateEvents, | ||
dynamicProperty, | ||
escape, | ||
voidFn as generateHydrationScript, | ||
voidFn as getAssets, | ||
getHydrationKey, | ||
getNextElement, | ||
getNextMarker, | ||
getNextMatch, | ||
getPropAlias, | ||
hydrate, | ||
innerHTML, | ||
insert, | ||
isDev, | ||
isServer, | ||
render, | ||
renderToStream, | ||
renderToString, | ||
renderToStringAsync, | ||
resolveSSRNode, | ||
runHydrationEvents, | ||
setAttribute, | ||
setAttributeNS, | ||
spread, | ||
ssr, | ||
ssrAttribute, | ||
ssrClassList, | ||
ssrElement, | ||
ssrHydrationKey, | ||
ssrSpread, | ||
ssrStyle, | ||
style, | ||
template, | ||
use, | ||
voidFn as useAssets | ||
}; |
@@ -1,9 +0,50 @@ | ||
import { sharedConfig, createRoot, splitProps } from 'solid-js'; | ||
export { ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, createComponent, mergeProps } from 'solid-js'; | ||
import { serialize, Feature } from 'seroval'; | ||
import { sharedConfig, createRoot, splitProps } from "solid-js"; | ||
export { | ||
ErrorBoundary, | ||
For, | ||
Index, | ||
Match, | ||
Show, | ||
Suspense, | ||
SuspenseList, | ||
Switch, | ||
createComponent, | ||
mergeProps | ||
} from "solid-js"; | ||
import { serialize, Feature } from "seroval"; | ||
const booleans = ["allowfullscreen", "async", "autofocus", "autoplay", "checked", "controls", "default", "disabled", "formnovalidate", "hidden", "indeterminate", "ismap", "loop", "multiple", "muted", "nomodule", "novalidate", "open", "playsinline", "readonly", "required", "reversed", "seamless", "selected"]; | ||
const BooleanAttributes = /*#__PURE__*/new Set(booleans); | ||
const ChildProperties = /*#__PURE__*/new Set(["innerHTML", "textContent", "innerText", "children"]); | ||
const Aliases = /*#__PURE__*/Object.assign(Object.create(null), { | ||
const booleans = [ | ||
"allowfullscreen", | ||
"async", | ||
"autofocus", | ||
"autoplay", | ||
"checked", | ||
"controls", | ||
"default", | ||
"disabled", | ||
"formnovalidate", | ||
"hidden", | ||
"indeterminate", | ||
"ismap", | ||
"loop", | ||
"multiple", | ||
"muted", | ||
"nomodule", | ||
"novalidate", | ||
"open", | ||
"playsinline", | ||
"readonly", | ||
"required", | ||
"reversed", | ||
"seamless", | ||
"selected" | ||
]; | ||
const BooleanAttributes = /*#__PURE__*/ new Set(booleans); | ||
const ChildProperties = /*#__PURE__*/ new Set([ | ||
"innerHTML", | ||
"textContent", | ||
"innerText", | ||
"children" | ||
]); | ||
const Aliases = /*#__PURE__*/ Object.assign(Object.create(null), { | ||
className: "class", | ||
@@ -13,5 +54,3 @@ htmlFor: "for" | ||
const ES2017FLAG = Feature.AggregateError | ||
| Feature.BigInt | ||
| Feature.BigIntTypedArray; | ||
const ES2017FLAG = Feature.AggregateError | Feature.BigInt | Feature.BigIntTypedArray; | ||
function stringify(data) { | ||
@@ -23,3 +62,4 @@ return serialize(data, { | ||
const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i; | ||
const VOID_ELEMENTS = | ||
/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i; | ||
const REPLACE_SCRIPT = `function $df(e,n,t,o,d){if(t=document.getElementById(e),o=document.getElementById("pl-"+e)){for(;o&&8!==o.nodeType&&o.nodeValue!=="pl-"+e;)d=o.nextSibling,o.remove(),o=d;_$HY.done?o.remove():o.replaceWith(t.content)}t.remove(),_$HY.set(e,n),_$HY.fe(e)}`; | ||
@@ -37,3 +77,3 @@ function renderToString(code, options = {}) { | ||
if (sharedConfig.context.noHydrate) return; | ||
if (error) return scripts += `_$HY.set("${id}", ${stringify(p)});`; | ||
if (error) return (scripts += `_$HY.set("${id}", ${stringify(p)});`); | ||
scripts += `_$HY.set("${id}", ${stringify(p)});`; | ||
@@ -52,5 +92,3 @@ } | ||
function renderToStringAsync(code, options = {}) { | ||
const { | ||
timeoutMs = 30000 | ||
} = options; | ||
const { timeoutMs = 30000 } = options; | ||
let timeoutHandle; | ||
@@ -66,8 +104,3 @@ const timeout = new Promise((_, reject) => { | ||
function renderToStream(code, options = {}) { | ||
let { | ||
nonce, | ||
onCompleteShell, | ||
onCompleteAll, | ||
renderId | ||
} = options; | ||
let { nonce, onCompleteShell, onCompleteAll, renderId } = options; | ||
let dispose; | ||
@@ -80,7 +113,8 @@ const blockingResources = []; | ||
writeTasks(); | ||
onCompleteAll && onCompleteAll({ | ||
write(v) { | ||
!completed && buffer.write(v); | ||
} | ||
}); | ||
onCompleteAll && | ||
onCompleteAll({ | ||
write(v) { | ||
!completed && buffer.write(v); | ||
} | ||
}); | ||
writable && writable.end(); | ||
@@ -136,3 +170,6 @@ completed = true; | ||
const last = html.indexOf(`<!--!$/${id}-->`, first + placeholder.length); | ||
html = html.replace(html.slice(first, last + placeholder.length + 1), resolveSSRNode(payloadFn())); | ||
html = html.replace( | ||
html.slice(first, last + placeholder.length + 1), | ||
resolveSSRNode(payloadFn()) | ||
); | ||
}, | ||
@@ -142,4 +179,6 @@ writeResource(id, p, error, wait) { | ||
if (error) return !serverOnly && pushTask(serializeSet(dedupe, id, p)); | ||
if (!p || typeof p !== "object" || !("then" in p)) return !serverOnly && pushTask(serializeSet(dedupe, id, p)); | ||
if (!firstFlushed) wait && blockingResources.push(p);else !serverOnly && pushTask(`_$HY.init("${id}")`); | ||
if (!p || typeof p !== "object" || !("then" in p)) | ||
return !serverOnly && pushTask(serializeSet(dedupe, id, p)); | ||
if (!firstFlushed) wait && blockingResources.push(p); | ||
else !serverOnly && pushTask(`_$HY.init("${id}")`); | ||
if (serverOnly) return; | ||
@@ -164,7 +203,15 @@ p.then(d => { | ||
if (!firstFlushed) { | ||
Promise.resolve().then(() => html = replacePlaceholder(html, key, value !== undefined ? value : "")); | ||
Promise.resolve().then( | ||
() => (html = replacePlaceholder(html, key, value !== undefined ? value : "")) | ||
); | ||
error && pushTask(serializeSet(dedupe, key, error)); | ||
} else { | ||
buffer.write(`<template id="${key}">${value !== undefined ? value : " "}</template>`); | ||
pushTask(`${keys.length ? keys.map(k => `_$HY.unset("${k}")`).join(";") + ";" : ""}$df("${key}"${error ? "," + stringify(error) : ""})${!scriptFlushed ? ";" + REPLACE_SCRIPT : ""}`); | ||
pushTask( | ||
`${ | ||
keys.length ? keys.map(k => `_$HY.unset("${k}")`).join(";") + ";" : "" | ||
}$df("${key}"${error ? "," + stringify(error) : ""})${ | ||
!scriptFlushed ? ";" + REPLACE_SCRIPT : "" | ||
}` | ||
); | ||
scriptFlushed = true; | ||
@@ -188,3 +235,4 @@ } | ||
for (const key in context.resources) { | ||
if (!("data" in context.resources[key] || context.resources[key].ref[0].error)) pushTask(`_$HY.init("${key}")`); | ||
if (!("data" in context.resources[key] || context.resources[key].ref[0].error)) | ||
pushTask(`_$HY.init("${key}")`); | ||
} | ||
@@ -196,7 +244,8 @@ for (const key of registry.keys()) pushTask(`_$HY.init("${key}")`); | ||
scheduled = false; | ||
onCompleteShell && onCompleteShell({ | ||
write(v) { | ||
!completed && buffer.write(v); | ||
} | ||
}); | ||
onCompleteShell && | ||
onCompleteShell({ | ||
write(v) { | ||
!completed && buffer.write(v); | ||
} | ||
}); | ||
} | ||
@@ -224,3 +273,4 @@ return { | ||
firstFlushed = true; | ||
if (completed) writable.end();else setTimeout(checkEnd); | ||
if (completed) writable.end(); | ||
else setTimeout(checkEnd); | ||
}); | ||
@@ -246,3 +296,4 @@ }, | ||
firstFlushed = true; | ||
if (completed) writable.end();else setTimeout(checkEnd); | ||
if (completed) writable.end(); | ||
else setTimeout(checkEnd); | ||
}); | ||
@@ -253,9 +304,9 @@ } | ||
function HydrationScript(props) { | ||
const { | ||
nonce | ||
} = sharedConfig.context; | ||
return ssr(generateHydrationScript({ | ||
nonce, | ||
...props | ||
})); | ||
const { nonce } = sharedConfig.context; | ||
return ssr( | ||
generateHydrationScript({ | ||
nonce, | ||
...props | ||
}) | ||
); | ||
} | ||
@@ -305,3 +356,4 @@ function ssr(t, ...nodes) { | ||
function ssrElement(tag, props, children, needsId) { | ||
if (props == null) props = {};else if (typeof props === "function") props = props(); | ||
if (props == null) props = {}; | ||
else if (typeof props === "function") props = props(); | ||
const skipChildren = VOID_ELEMENTS.test(tag); | ||
@@ -314,3 +366,4 @@ const keys = Object.keys(props); | ||
if (ChildProperties.has(prop)) { | ||
if (children === undefined && !skipChildren) children = prop === "innerHTML" ? props[prop] : escape(props[prop]); | ||
if (children === undefined && !skipChildren) | ||
children = prop === "innerHTML" ? props[prop] : escape(props[prop]); | ||
continue; | ||
@@ -324,6 +377,10 @@ } | ||
let n; | ||
result += `class="${escape(((n = props.class) ? n + " " : "") + ((n = props.className) ? n + " " : ""), true) + ssrClassList(props.classList)}"`; | ||
result += `class="${ | ||
escape(((n = props.class) ? n + " " : "") + ((n = props.className) ? n + " " : ""), true) + | ||
ssrClassList(props.classList) | ||
}"`; | ||
classResolved = true; | ||
} else if (BooleanAttributes.has(prop)) { | ||
if (value) result += prop;else continue; | ||
if (value) result += prop; | ||
else continue; | ||
} else if (value == undefined || prop === "ref" || prop.slice(0, 2) === "on") { | ||
@@ -336,5 +393,6 @@ continue; | ||
} | ||
if (skipChildren) return { | ||
t: result + "/>" | ||
}; | ||
if (skipChildren) | ||
return { | ||
t: result + "/>" | ||
}; | ||
if (typeof children === "function") children = children(); | ||
@@ -346,3 +404,3 @@ return { | ||
function ssrAttribute(key, value, isBoolean) { | ||
return isBoolean ? value ? " " + key : "" : value != null ? ` ${key}="${value}"` : ""; | ||
return isBoolean ? (value ? " " + key : "") : value != null ? ` ${key}="${value}"` : ""; | ||
} | ||
@@ -391,8 +449,9 @@ function ssrHydrationKey() { | ||
} while (iDelim >= 0); | ||
} else while (iAmp >= 0) { | ||
if (left < iAmp) out += s.substring(left, iAmp); | ||
out += "&"; | ||
left = iAmp + 1; | ||
iAmp = s.indexOf("&", left); | ||
} | ||
} else | ||
while (iAmp >= 0) { | ||
if (left < iAmp) out += s.substring(left, iAmp); | ||
out += "&"; | ||
left = iAmp + 1; | ||
iAmp = s.indexOf("&", left); | ||
} | ||
return left < s.length ? out + s.substring(left) : out; | ||
@@ -409,3 +468,3 @@ } | ||
if (!top && typeof prev !== "object" && typeof node[i] !== "object") mapped += `<!--!$-->`; | ||
mapped += resolveSSRNode(prev = node[i]); | ||
mapped += resolveSSRNode((prev = node[i])); | ||
} | ||
@@ -431,7 +490,8 @@ return mapped; | ||
} | ||
function generateHydrationScript({ | ||
eventNames = ["click", "input"], | ||
nonce | ||
} = {}) { | ||
return `<script${nonce ? ` nonce="${nonce}"` : ""}>(e=>{let t=e=>e&&e.hasAttribute&&(e.hasAttribute("data-hk")?e:t(e.host&&e.host.nodeType?e.host:e.parentNode));["${eventNames.join('", "')}"].forEach((o=>document.addEventListener(o,(o=>{let s=o.composedPath&&o.composedPath()[0]||o.target,a=t(s);a&&!e.completed.has(a)&&e.events.push([a,o])}))))})(window._$HY||(_$HY={events:[],completed:new WeakSet,r:{},fe(){},init(e,t){_$HY.r[e]=[new Promise((e=>t=e)),t]},set(e,t,o){(o=_$HY.r[e])&&o[1](t),_$HY.r[e]=[t]},unset(e){delete _$HY.r[e]},load:e=>_$HY.r[e]}));</script><!--xs-->`; | ||
function generateHydrationScript({ eventNames = ["click", "input"], nonce } = {}) { | ||
return `<script${ | ||
nonce ? ` nonce="${nonce}"` : "" | ||
}>(e=>{let t=e=>e&&e.hasAttribute&&(e.hasAttribute("data-hk")?e:t(e.host&&e.host.nodeType?e.host:e.parentNode));["${eventNames.join( | ||
'", "' | ||
)}"].forEach((o=>document.addEventListener(o,(o=>{let s=o.composedPath&&o.composedPath()[0]||o.target,a=t(s);a&&!e.completed.has(a)&&e.events.push([a,o])}))))})(window._$HY||(_$HY={events:[],completed:new WeakSet,r:{},fe(){},init(e,t){_$HY.r[e]=[new Promise((e=>t=e)),t]},set(e,t,o){(o=_$HY.r[e])&&o[1](t),_$HY.r[e]=[t]},unset(e){delete _$HY.r[e]},load:e=>_$HY.r[e]}));</script><!--xs-->`; | ||
} | ||
@@ -497,5 +557,3 @@ function Hydration(props) { | ||
if (options.onReady) { | ||
options.onCompleteShell = ({ | ||
write | ||
}) => { | ||
options.onCompleteShell = ({ write }) => { | ||
options.onReady({ | ||
@@ -514,5 +572,3 @@ write, | ||
if (options.onReady) { | ||
options.onCompleteShell = ({ | ||
write | ||
}) => { | ||
options.onCompleteShell = ({ write }) => { | ||
options.onReady({ | ||
@@ -547,7 +603,15 @@ write, | ||
let n; | ||
result += `class="${(n = props.class) ? n + " " : ""}${(n = props.className) ? n + " " : ""}${ssrClassList(props.classList)}"`; | ||
result += `class="${(n = props.class) ? n + " " : ""}${ | ||
(n = props.className) ? n + " " : "" | ||
}${ssrClassList(props.classList)}"`; | ||
classResolved = true; | ||
} else if (BooleanAttributes.has(prop)) { | ||
if (value) result += prop;else continue; | ||
} else if (value == undefined || prop === "ref" || prop.slice(0, 2) === "on" || prop.slice(0, 5) === "prop:") { | ||
if (value) result += prop; | ||
else continue; | ||
} else if ( | ||
value == undefined || | ||
prop === "ref" || | ||
prop.slice(0, 2) === "on" || | ||
prop.slice(0, 5) === "prop:" | ||
) { | ||
continue; | ||
@@ -576,3 +640,4 @@ } else { | ||
if (comp) { | ||
if (t === "function") return comp(others);else if (t === "string") { | ||
if (t === "function") return comp(others); | ||
else if (t === "string") { | ||
return ssrElement(comp, others, undefined, true); | ||
@@ -586,2 +651,36 @@ } | ||
export { Assets, Dynamic, Hydration, HydrationScript, NoHydration, Portal, addEventListener, delegateEvents, escape, generateHydrationScript, getAssets, getHydrationKey, hydrate, insert, isDev, isServer, pipeToNodeWritable, pipeToWritable, render, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, spread, ssr, ssrAttribute, ssrClassList, ssrElement, ssrHydrationKey, ssrSpread, ssrStyle, stringify, useAssets }; | ||
export { | ||
Assets, | ||
Dynamic, | ||
Hydration, | ||
HydrationScript, | ||
NoHydration, | ||
Portal, | ||
addEventListener, | ||
delegateEvents, | ||
escape, | ||
generateHydrationScript, | ||
getAssets, | ||
getHydrationKey, | ||
hydrate, | ||
insert, | ||
isDev, | ||
isServer, | ||
pipeToNodeWritable, | ||
pipeToWritable, | ||
render, | ||
renderToStream, | ||
renderToString, | ||
renderToStringAsync, | ||
resolveSSRNode, | ||
spread, | ||
ssr, | ||
ssrAttribute, | ||
ssrClassList, | ||
ssrElement, | ||
ssrHydrationKey, | ||
ssrSpread, | ||
ssrStyle, | ||
stringify, | ||
useAssets | ||
}; |
@@ -1,12 +0,80 @@ | ||
import { createRoot, createRenderEffect, sharedConfig, untrack, enableHydration, getOwner, createEffect, runWithOwner, createMemo, createSignal, onCleanup, splitProps, $DEVCOMP } from 'solid-js'; | ||
export { ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, createComponent, createRenderEffect as effect, getOwner, createMemo as memo, mergeProps, untrack } from 'solid-js'; | ||
import { | ||
createRoot, | ||
createRenderEffect, | ||
sharedConfig, | ||
untrack, | ||
enableHydration, | ||
getOwner, | ||
createEffect, | ||
runWithOwner, | ||
createMemo, | ||
createSignal, | ||
onCleanup, | ||
splitProps, | ||
$DEVCOMP | ||
} from "solid-js"; | ||
export { | ||
ErrorBoundary, | ||
For, | ||
Index, | ||
Match, | ||
Show, | ||
Suspense, | ||
SuspenseList, | ||
Switch, | ||
createComponent, | ||
createRenderEffect as effect, | ||
getOwner, | ||
createMemo as memo, | ||
mergeProps, | ||
untrack | ||
} from "solid-js"; | ||
const booleans = ["allowfullscreen", "async", "autofocus", "autoplay", "checked", "controls", "default", "disabled", "formnovalidate", "hidden", "indeterminate", "ismap", "loop", "multiple", "muted", "nomodule", "novalidate", "open", "playsinline", "readonly", "required", "reversed", "seamless", "selected"]; | ||
const Properties = /*#__PURE__*/new Set(["className", "value", "readOnly", "formNoValidate", "isMap", "noModule", "playsInline", ...booleans]); | ||
const ChildProperties = /*#__PURE__*/new Set(["innerHTML", "textContent", "innerText", "children"]); | ||
const Aliases = /*#__PURE__*/Object.assign(Object.create(null), { | ||
const booleans = [ | ||
"allowfullscreen", | ||
"async", | ||
"autofocus", | ||
"autoplay", | ||
"checked", | ||
"controls", | ||
"default", | ||
"disabled", | ||
"formnovalidate", | ||
"hidden", | ||
"indeterminate", | ||
"ismap", | ||
"loop", | ||
"multiple", | ||
"muted", | ||
"nomodule", | ||
"novalidate", | ||
"open", | ||
"playsinline", | ||
"readonly", | ||
"required", | ||
"reversed", | ||
"seamless", | ||
"selected" | ||
]; | ||
const Properties = /*#__PURE__*/ new Set([ | ||
"className", | ||
"value", | ||
"readOnly", | ||
"formNoValidate", | ||
"isMap", | ||
"noModule", | ||
"playsInline", | ||
...booleans | ||
]); | ||
const ChildProperties = /*#__PURE__*/ new Set([ | ||
"innerHTML", | ||
"textContent", | ||
"innerText", | ||
"children" | ||
]); | ||
const Aliases = /*#__PURE__*/ Object.assign(Object.create(null), { | ||
className: "class", | ||
htmlFor: "for" | ||
}); | ||
const PropAliases = /*#__PURE__*/Object.assign(Object.create(null), { | ||
const PropAliases = /*#__PURE__*/ Object.assign(Object.create(null), { | ||
class: "className", | ||
@@ -38,10 +106,106 @@ formnovalidate: { | ||
const a = PropAliases[prop]; | ||
return typeof a === "object" ? a[tagName] ? a["$"] : undefined : a; | ||
return typeof a === "object" ? (a[tagName] ? a["$"] : undefined) : a; | ||
} | ||
const DelegatedEvents = /*#__PURE__*/new Set(["beforeinput", "click", "dblclick", "contextmenu", "focusin", "focusout", "input", "keydown", "keyup", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup", "pointerdown", "pointermove", "pointerout", "pointerover", "pointerup", "touchend", "touchmove", "touchstart"]); | ||
const SVGElements = /*#__PURE__*/new Set([ | ||
"altGlyph", "altGlyphDef", "altGlyphItem", "animate", "animateColor", "animateMotion", "animateTransform", "circle", "clipPath", "color-profile", "cursor", "defs", "desc", "ellipse", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence", "filter", "font", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "foreignObject", "g", "glyph", "glyphRef", "hkern", "image", "line", "linearGradient", "marker", "mask", "metadata", "missing-glyph", "mpath", "path", "pattern", "polygon", "polyline", "radialGradient", "rect", | ||
"set", "stop", | ||
"svg", "switch", "symbol", "text", "textPath", | ||
"tref", "tspan", "use", "view", "vkern"]); | ||
const DelegatedEvents = /*#__PURE__*/ new Set([ | ||
"beforeinput", | ||
"click", | ||
"dblclick", | ||
"contextmenu", | ||
"focusin", | ||
"focusout", | ||
"input", | ||
"keydown", | ||
"keyup", | ||
"mousedown", | ||
"mousemove", | ||
"mouseout", | ||
"mouseover", | ||
"mouseup", | ||
"pointerdown", | ||
"pointermove", | ||
"pointerout", | ||
"pointerover", | ||
"pointerup", | ||
"touchend", | ||
"touchmove", | ||
"touchstart" | ||
]); | ||
const SVGElements = /*#__PURE__*/ new Set([ | ||
"altGlyph", | ||
"altGlyphDef", | ||
"altGlyphItem", | ||
"animate", | ||
"animateColor", | ||
"animateMotion", | ||
"animateTransform", | ||
"circle", | ||
"clipPath", | ||
"color-profile", | ||
"cursor", | ||
"defs", | ||
"desc", | ||
"ellipse", | ||
"feBlend", | ||
"feColorMatrix", | ||
"feComponentTransfer", | ||
"feComposite", | ||
"feConvolveMatrix", | ||
"feDiffuseLighting", | ||
"feDisplacementMap", | ||
"feDistantLight", | ||
"feFlood", | ||
"feFuncA", | ||
"feFuncB", | ||
"feFuncG", | ||
"feFuncR", | ||
"feGaussianBlur", | ||
"feImage", | ||
"feMerge", | ||
"feMergeNode", | ||
"feMorphology", | ||
"feOffset", | ||
"fePointLight", | ||
"feSpecularLighting", | ||
"feSpotLight", | ||
"feTile", | ||
"feTurbulence", | ||
"filter", | ||
"font", | ||
"font-face", | ||
"font-face-format", | ||
"font-face-name", | ||
"font-face-src", | ||
"font-face-uri", | ||
"foreignObject", | ||
"g", | ||
"glyph", | ||
"glyphRef", | ||
"hkern", | ||
"image", | ||
"line", | ||
"linearGradient", | ||
"marker", | ||
"mask", | ||
"metadata", | ||
"missing-glyph", | ||
"mpath", | ||
"path", | ||
"pattern", | ||
"polygon", | ||
"polyline", | ||
"radialGradient", | ||
"rect", | ||
"set", | ||
"stop", | ||
"svg", | ||
"switch", | ||
"symbol", | ||
"text", | ||
"textPath", | ||
"tref", | ||
"tspan", | ||
"use", | ||
"view", | ||
"vkern" | ||
]); | ||
const SVGNamespace = { | ||
@@ -51,3 +215,283 @@ xlink: "http://www.w3.org/1999/xlink", | ||
}; | ||
const DOMElements = /*#__PURE__*/new Set(["html", "base", "head", "link", "meta", "style", "title", "body", "address", "article", "aside", "footer", "header", "main", "nav", "section", "body", "blockquote", "dd", "div", "dl", "dt", "figcaption", "figure", "hr", "li", "ol", "p", "pre", "ul", "a", "abbr", "b", "bdi", "bdo", "br", "cite", "code", "data", "dfn", "em", "i", "kbd", "mark", "q", "rp", "rt", "ruby", "s", "samp", "small", "span", "strong", "sub", "sup", "time", "u", "var", "wbr", "area", "audio", "img", "map", "track", "video", "embed", "iframe", "object", "param", "picture", "portal", "source", "svg", "math", "canvas", "noscript", "script", "del", "ins", "caption", "col", "colgroup", "table", "tbody", "td", "tfoot", "th", "thead", "tr", "button", "datalist", "fieldset", "form", "input", "label", "legend", "meter", "optgroup", "option", "output", "progress", "select", "textarea", "details", "dialog", "menu", "summary", "details", "slot", "template", "acronym", "applet", "basefont", "bgsound", "big", "blink", "center", "content", "dir", "font", "frame", "frameset", "hgroup", "image", "keygen", "marquee", "menuitem", "nobr", "noembed", "noframes", "plaintext", "rb", "rtc", "shadow", "spacer", "strike", "tt", "xmp", "a", "abbr", "acronym", "address", "applet", "area", "article", "aside", "audio", "b", "base", "basefont", "bdi", "bdo", "bgsound", "big", "blink", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "content", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "font", "footer", "form", "frame", "frameset", "head", "header", "hgroup", "hr", "html", "i", "iframe", "image", "img", "input", "ins", "kbd", "keygen", "label", "legend", "li", "link", "main", "map", "mark", "marquee", "menu", "menuitem", "meta", "meter", "nav", "nobr", "noembed", "noframes", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "picture", "plaintext", "portal", "pre", "progress", "q", "rb", "rp", "rt", "rtc", "ruby", "s", "samp", "script", "section", "select", "shadow", "slot", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "tt", "u", "ul", "var", "video", "wbr", "xmp", "input", "h1", "h2", "h3", "h4", "h5", "h6"]); | ||
const DOMElements = /*#__PURE__*/ new Set([ | ||
"html", | ||
"base", | ||
"head", | ||
"link", | ||
"meta", | ||
"style", | ||
"title", | ||
"body", | ||
"address", | ||
"article", | ||
"aside", | ||
"footer", | ||
"header", | ||
"main", | ||
"nav", | ||
"section", | ||
"body", | ||
"blockquote", | ||
"dd", | ||
"div", | ||
"dl", | ||
"dt", | ||
"figcaption", | ||
"figure", | ||
"hr", | ||
"li", | ||
"ol", | ||
"p", | ||
"pre", | ||
"ul", | ||
"a", | ||
"abbr", | ||
"b", | ||
"bdi", | ||
"bdo", | ||
"br", | ||
"cite", | ||
"code", | ||
"data", | ||
"dfn", | ||
"em", | ||
"i", | ||
"kbd", | ||
"mark", | ||
"q", | ||
"rp", | ||
"rt", | ||
"ruby", | ||
"s", | ||
"samp", | ||
"small", | ||
"span", | ||
"strong", | ||
"sub", | ||
"sup", | ||
"time", | ||
"u", | ||
"var", | ||
"wbr", | ||
"area", | ||
"audio", | ||
"img", | ||
"map", | ||
"track", | ||
"video", | ||
"embed", | ||
"iframe", | ||
"object", | ||
"param", | ||
"picture", | ||
"portal", | ||
"source", | ||
"svg", | ||
"math", | ||
"canvas", | ||
"noscript", | ||
"script", | ||
"del", | ||
"ins", | ||
"caption", | ||
"col", | ||
"colgroup", | ||
"table", | ||
"tbody", | ||
"td", | ||
"tfoot", | ||
"th", | ||
"thead", | ||
"tr", | ||
"button", | ||
"datalist", | ||
"fieldset", | ||
"form", | ||
"input", | ||
"label", | ||
"legend", | ||
"meter", | ||
"optgroup", | ||
"option", | ||
"output", | ||
"progress", | ||
"select", | ||
"textarea", | ||
"details", | ||
"dialog", | ||
"menu", | ||
"summary", | ||
"details", | ||
"slot", | ||
"template", | ||
"acronym", | ||
"applet", | ||
"basefont", | ||
"bgsound", | ||
"big", | ||
"blink", | ||
"center", | ||
"content", | ||
"dir", | ||
"font", | ||
"frame", | ||
"frameset", | ||
"hgroup", | ||
"image", | ||
"keygen", | ||
"marquee", | ||
"menuitem", | ||
"nobr", | ||
"noembed", | ||
"noframes", | ||
"plaintext", | ||
"rb", | ||
"rtc", | ||
"shadow", | ||
"spacer", | ||
"strike", | ||
"tt", | ||
"xmp", | ||
"a", | ||
"abbr", | ||
"acronym", | ||
"address", | ||
"applet", | ||
"area", | ||
"article", | ||
"aside", | ||
"audio", | ||
"b", | ||
"base", | ||
"basefont", | ||
"bdi", | ||
"bdo", | ||
"bgsound", | ||
"big", | ||
"blink", | ||
"blockquote", | ||
"body", | ||
"br", | ||
"button", | ||
"canvas", | ||
"caption", | ||
"center", | ||
"cite", | ||
"code", | ||
"col", | ||
"colgroup", | ||
"content", | ||
"data", | ||
"datalist", | ||
"dd", | ||
"del", | ||
"details", | ||
"dfn", | ||
"dialog", | ||
"dir", | ||
"div", | ||
"dl", | ||
"dt", | ||
"em", | ||
"embed", | ||
"fieldset", | ||
"figcaption", | ||
"figure", | ||
"font", | ||
"footer", | ||
"form", | ||
"frame", | ||
"frameset", | ||
"head", | ||
"header", | ||
"hgroup", | ||
"hr", | ||
"html", | ||
"i", | ||
"iframe", | ||
"image", | ||
"img", | ||
"input", | ||
"ins", | ||
"kbd", | ||
"keygen", | ||
"label", | ||
"legend", | ||
"li", | ||
"link", | ||
"main", | ||
"map", | ||
"mark", | ||
"marquee", | ||
"menu", | ||
"menuitem", | ||
"meta", | ||
"meter", | ||
"nav", | ||
"nobr", | ||
"noembed", | ||
"noframes", | ||
"noscript", | ||
"object", | ||
"ol", | ||
"optgroup", | ||
"option", | ||
"output", | ||
"p", | ||
"param", | ||
"picture", | ||
"plaintext", | ||
"portal", | ||
"pre", | ||
"progress", | ||
"q", | ||
"rb", | ||
"rp", | ||
"rt", | ||
"rtc", | ||
"ruby", | ||
"s", | ||
"samp", | ||
"script", | ||
"section", | ||
"select", | ||
"shadow", | ||
"slot", | ||
"small", | ||
"source", | ||
"spacer", | ||
"span", | ||
"strike", | ||
"strong", | ||
"style", | ||
"sub", | ||
"summary", | ||
"sup", | ||
"table", | ||
"tbody", | ||
"td", | ||
"template", | ||
"textarea", | ||
"tfoot", | ||
"th", | ||
"thead", | ||
"time", | ||
"title", | ||
"tr", | ||
"track", | ||
"tt", | ||
"u", | ||
"ul", | ||
"var", | ||
"video", | ||
"wbr", | ||
"xmp", | ||
"input", | ||
"h1", | ||
"h2", | ||
"h3", | ||
"h4", | ||
"h5", | ||
"h6" | ||
]); | ||
@@ -73,3 +517,3 @@ function reconcileArrays(parentNode, a, b) { | ||
if (aEnd === aStart) { | ||
const node = bEnd < bLength ? bStart ? b[bStart - 1].nextSibling : b[bEnd - bStart] : after; | ||
const node = bEnd < bLength ? (bStart ? b[bStart - 1].nextSibling : b[bEnd - bStart]) : after; | ||
while (bStart < bEnd) parentNode.insertBefore(b[bStart++], node); | ||
@@ -117,3 +561,5 @@ } else if (bEnd === bStart) { | ||
disposer = dispose; | ||
element === document ? code() : insert(element, code(), element.firstChild ? null : undefined, init); | ||
element === document | ||
? code() | ||
: insert(element, code(), element.firstChild ? null : undefined, init); | ||
}, options.owner); | ||
@@ -132,3 +578,5 @@ return () => { | ||
}; | ||
const fn = isCE ? () => untrack(() => document.importNode(node || (node = create()), true)) : () => (node || (node = create())).cloneNode(true); | ||
const fn = isCE | ||
? () => untrack(() => document.importNode(node || (node = create()), true)) | ||
: () => (node || (node = create())).cloneNode(true); | ||
fn.cloneNode = fn; | ||
@@ -154,9 +602,12 @@ return fn; | ||
function setAttribute(node, name, value) { | ||
if (value == null) node.removeAttribute(name);else node.setAttribute(name, value); | ||
if (value == null) node.removeAttribute(name); | ||
else node.setAttribute(name, value); | ||
} | ||
function setAttributeNS(node, namespace, name, value) { | ||
if (value == null) node.removeAttributeNS(namespace, name);else node.setAttributeNS(namespace, name, value); | ||
if (value == null) node.removeAttributeNS(namespace, name); | ||
else node.setAttributeNS(namespace, name, value); | ||
} | ||
function className(node, value) { | ||
if (value == null) node.removeAttribute("class");else node.className = value; | ||
if (value == null) node.removeAttribute("class"); | ||
else node.className = value; | ||
} | ||
@@ -171,3 +622,3 @@ function addEventListener(node, name, handler, delegate) { | ||
const handlerFn = handler[0]; | ||
node.addEventListener(name, handler[0] = e => handlerFn.call(node, handler[1], e)); | ||
node.addEventListener(name, (handler[0] = e => handlerFn.call(node, handler[1], e))); | ||
} else node.addEventListener(name, handler); | ||
@@ -197,3 +648,3 @@ } | ||
const nodeStyle = node.style; | ||
if (typeof value === "string") return nodeStyle.cssText = value; | ||
if (typeof value === "string") return (nodeStyle.cssText = value); | ||
typeof prev === "string" && (nodeStyle.cssText = prev = undefined); | ||
@@ -219,3 +670,5 @@ prev || (prev = {}); | ||
if (!skipChildren) { | ||
createRenderEffect(() => prevProps.children = insertExpression(node, props.children, prevProps.children)); | ||
createRenderEffect( | ||
() => (prevProps.children = insertExpression(node, props.children, prevProps.children)) | ||
); | ||
} | ||
@@ -281,3 +734,3 @@ createRenderEffect(() => props.ref && props.ref(node)); | ||
let node, key; | ||
if (!sharedConfig.context || !(node = sharedConfig.registry.get(key = getHydrationKey()))) { | ||
if (!sharedConfig.context || !(node = sharedConfig.registry.get((key = getHydrationKey())))) { | ||
if (sharedConfig.context) console.warn("Unable to find DOM nodes for hydration key:", key); | ||
@@ -303,3 +756,4 @@ if (!template) throw new Error("Unrecoverable Hydration Mismatch. No template for key: " + key); | ||
const v = end.nodeValue; | ||
if (v === "#") count++;else if (v === "/") { | ||
if (v === "#") count++; | ||
else if (v === "/") { | ||
if (count === 0) return [end, current]; | ||
@@ -318,6 +772,3 @@ count--; | ||
queueMicrotask(() => { | ||
const { | ||
completed, | ||
events | ||
} = sharedConfig; | ||
const { completed, events } = sharedConfig; | ||
events.queued = false; | ||
@@ -339,3 +790,4 @@ while (events.length) { | ||
const classNames = key.trim().split(/\s+/); | ||
for (let i = 0, nameLen = classNames.length; i < nameLen; i++) node.classList.toggle(classNames[i], value); | ||
for (let i = 0, nameLen = classNames.length; i < nameLen; i++) | ||
node.classList.toggle(classNames[i], value); | ||
} | ||
@@ -370,3 +822,9 @@ function assignProp(node, prop, value, prev, isSVG, skipRef) { | ||
setAttribute(node, prop.slice(5), value); | ||
} else if ((forceProp = prop.slice(0, 5) === "prop:") || (isChildProp = ChildProperties.has(prop)) || !isSVG && ((propAlias = getPropAlias(prop, node.tagName)) || (isProp = Properties.has(prop))) || (isCE = node.nodeName.includes("-"))) { | ||
} else if ( | ||
(forceProp = prop.slice(0, 5) === "prop:") || | ||
(isChildProp = ChildProperties.has(prop)) || | ||
(!isSVG && | ||
((propAlias = getPropAlias(prop, node.tagName)) || (isProp = Properties.has(prop)))) || | ||
(isCE = node.nodeName.includes("-")) | ||
) { | ||
if (forceProp) { | ||
@@ -376,6 +834,9 @@ prop = prop.slice(5); | ||
} | ||
if (prop === "class" || prop === "className") className(node, value);else if (isCE && !isProp && !isChildProp) node[toPropertyName(prop)] = value;else node[propAlias || prop] = value; | ||
if (prop === "class" || prop === "className") className(node, value); | ||
else if (isCE && !isProp && !isChildProp) node[toPropertyName(prop)] = value; | ||
else node[propAlias || prop] = value; | ||
} else { | ||
const ns = isSVG && prop.indexOf(":") > -1 && SVGNamespace[prop.split(":")[0]]; | ||
if (ns) setAttributeNS(node, ns, prop, value);else setAttribute(node, Aliases[prop] || prop, value); | ||
if (ns) setAttributeNS(node, ns, prop, value); | ||
else setAttribute(node, Aliases[prop] || prop, value); | ||
} | ||
@@ -386,3 +847,3 @@ return value; | ||
const key = `$$${e.type}`; | ||
let node = e.composedPath && e.composedPath()[0] || e.target; | ||
let node = (e.composedPath && e.composedPath()[0]) || e.target; | ||
if (e.target !== node) { | ||
@@ -417,3 +878,4 @@ Object.defineProperty(e, "target", { | ||
const node = current[i]; | ||
if (node.nodeType === 8 && node.data.slice(0, 2) === "!$") node.remove();else cleaned.push(node); | ||
if (node.nodeType === 8 && node.data.slice(0, 2) === "!$") node.remove(); | ||
else cleaned.push(node); | ||
} | ||
@@ -426,3 +888,3 @@ current = cleaned; | ||
multi = marker !== undefined; | ||
parent = multi && current[0] && current[0].parentNode || parent; | ||
parent = (multi && current[0] && current[0].parentNode) || parent; | ||
if (t === "string" || t === "number") { | ||
@@ -456,3 +918,3 @@ if (sharedConfig.context) return current; | ||
if (normalizeIncomingArray(array, value, current, unwrapArray)) { | ||
createRenderEffect(() => current = insertExpression(parent, array, current, marker, true)); | ||
createRenderEffect(() => (current = insertExpression(parent, array, current, marker, true))); | ||
return () => current; | ||
@@ -463,3 +925,3 @@ } | ||
for (let i = 0; i < array.length; i++) { | ||
if (array[i].parentNode) return current = array; | ||
if (array[i].parentNode) return (current = array); | ||
} | ||
@@ -480,5 +942,5 @@ } | ||
} else if (value.nodeType) { | ||
if (sharedConfig.context && value.parentNode) return current = multi ? [value] : value; | ||
if (sharedConfig.context && value.parentNode) return (current = multi ? [value] : value); | ||
if (Array.isArray(current)) { | ||
if (multi) return current = cleanChildren(parent, current, marker, value); | ||
if (multi) return (current = cleanChildren(parent, current, marker, value)); | ||
cleanChildren(parent, current, null, value); | ||
@@ -498,3 +960,4 @@ } else if (current == null || current === "" || !parent.firstChild) { | ||
t; | ||
if (item == null || item === true || item === false) ; else if ((t = typeof item) === "object" && item.nodeType) { | ||
if (item == null || item === true || item === false); | ||
else if ((t = typeof item) === "object" && item.nodeType) { | ||
normalized.push(item); | ||
@@ -506,3 +969,8 @@ } else if (Array.isArray(item)) { | ||
while (typeof item === "function") item = item(); | ||
dynamic = normalizeIncomingArray(normalized, Array.isArray(item) ? item : [item], Array.isArray(prev) ? prev : [prev]) || dynamic; | ||
dynamic = | ||
normalizeIncomingArray( | ||
normalized, | ||
Array.isArray(item) ? item : [item], | ||
Array.isArray(prev) ? prev : [prev] | ||
) || dynamic; | ||
} else { | ||
@@ -514,3 +982,4 @@ normalized.push(item); | ||
const value = String(item); | ||
if (prev && prev.nodeType === 3 && prev.data === value) normalized.push(prev);else normalized.push(document.createTextNode(value)); | ||
if (prev && prev.nodeType === 3 && prev.data === value) normalized.push(prev); | ||
else normalized.push(document.createTextNode(value)); | ||
} | ||
@@ -524,3 +993,3 @@ } | ||
function cleanChildren(parent, current, marker, replacement) { | ||
if (marker === undefined) return parent.textContent = ""; | ||
if (marker === undefined) return (parent.textContent = ""); | ||
const node = replacement || document.createTextNode(""); | ||
@@ -533,3 +1002,5 @@ if (current.length) { | ||
const isParent = el.parentNode === parent; | ||
if (!inserted && !i) isParent ? parent.replaceChild(node, el) : parent.insertBefore(node, marker);else isParent && el.remove(); | ||
if (!inserted && !i) | ||
isParent ? parent.replaceChild(node, el) : parent.insertBefore(node, marker); | ||
else isParent && el.remove(); | ||
} else inserted = true; | ||
@@ -545,3 +1016,4 @@ } | ||
const key = node.getAttribute("data-hk"); | ||
if ((!root || key.startsWith(root)) && !sharedConfig.registry.has(key)) sharedConfig.registry.set(key, node); | ||
if ((!root || key.startsWith(root)) && !sharedConfig.registry.has(key)) | ||
sharedConfig.registry.set(key, node); | ||
} | ||
@@ -595,5 +1067,3 @@ } | ||
function Portal(props) { | ||
const { | ||
useShadow | ||
} = props, | ||
const { useShadow } = props, | ||
marker = document.createTextNode(""), | ||
@@ -604,30 +1074,37 @@ mount = () => props.mount || document.body, | ||
let hydrating = !!sharedConfig.context; | ||
createEffect(() => { | ||
if (hydrating) getOwner().user = hydrating = false; | ||
content || (content = runWithOwner(owner, () => createMemo(() => props.children))); | ||
const el = mount(); | ||
if (el instanceof HTMLHeadElement) { | ||
const [clean, setClean] = createSignal(false); | ||
const cleanup = () => setClean(true); | ||
createRoot(dispose => insert(el, () => !clean() ? content() : dispose(), null)); | ||
onCleanup(cleanup); | ||
} else { | ||
const container = createElement(props.isSVG ? "g" : "div", props.isSVG), | ||
renderRoot = useShadow && container.attachShadow ? container.attachShadow({ | ||
mode: "open" | ||
}) : container; | ||
Object.defineProperty(container, "_$host", { | ||
get() { | ||
return marker.parentNode; | ||
}, | ||
configurable: true | ||
}); | ||
insert(renderRoot, content); | ||
el.appendChild(container); | ||
props.ref && props.ref(container); | ||
onCleanup(() => el.removeChild(container)); | ||
createEffect( | ||
() => { | ||
if (hydrating) getOwner().user = hydrating = false; | ||
content || (content = runWithOwner(owner, () => createMemo(() => props.children))); | ||
const el = mount(); | ||
if (el instanceof HTMLHeadElement) { | ||
const [clean, setClean] = createSignal(false); | ||
const cleanup = () => setClean(true); | ||
createRoot(dispose => insert(el, () => (!clean() ? content() : dispose()), null)); | ||
onCleanup(cleanup); | ||
} else { | ||
const container = createElement(props.isSVG ? "g" : "div", props.isSVG), | ||
renderRoot = | ||
useShadow && container.attachShadow | ||
? container.attachShadow({ | ||
mode: "open" | ||
}) | ||
: container; | ||
Object.defineProperty(container, "_$host", { | ||
get() { | ||
return marker.parentNode; | ||
}, | ||
configurable: true | ||
}); | ||
insert(renderRoot, content); | ||
el.appendChild(container); | ||
props.ref && props.ref(container); | ||
onCleanup(() => el.removeChild(container)); | ||
} | ||
}, | ||
undefined, | ||
{ | ||
render: !hydrating | ||
} | ||
}, undefined, { | ||
render: !hydrating | ||
}); | ||
); | ||
return marker; | ||
@@ -655,2 +1132,56 @@ } | ||
export { Aliases, voidFn as Assets, ChildProperties, DOMElements, DelegatedEvents, Dynamic, Hydration, voidFn as HydrationScript, NoHydration, Portal, Properties, SVGElements, SVGNamespace, addEventListener, assign, classList, className, clearDelegatedEvents, delegateEvents, dynamicProperty, escape, voidFn as generateHydrationScript, voidFn as getAssets, getHydrationKey, getNextElement, getNextMarker, getNextMatch, getPropAlias, hydrate, innerHTML, insert, isDev, isServer, render, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, runHydrationEvents, setAttribute, setAttributeNS, spread, ssr, ssrAttribute, ssrClassList, ssrElement, ssrHydrationKey, ssrSpread, ssrStyle, style, template, use, voidFn as useAssets }; | ||
export { | ||
Aliases, | ||
voidFn as Assets, | ||
ChildProperties, | ||
DOMElements, | ||
DelegatedEvents, | ||
Dynamic, | ||
Hydration, | ||
voidFn as HydrationScript, | ||
NoHydration, | ||
Portal, | ||
Properties, | ||
SVGElements, | ||
SVGNamespace, | ||
addEventListener, | ||
assign, | ||
classList, | ||
className, | ||
clearDelegatedEvents, | ||
delegateEvents, | ||
dynamicProperty, | ||
escape, | ||
voidFn as generateHydrationScript, | ||
voidFn as getAssets, | ||
getHydrationKey, | ||
getNextElement, | ||
getNextMarker, | ||
getNextMatch, | ||
getPropAlias, | ||
hydrate, | ||
innerHTML, | ||
insert, | ||
isDev, | ||
isServer, | ||
render, | ||
renderToStream, | ||
renderToString, | ||
renderToStringAsync, | ||
resolveSSRNode, | ||
runHydrationEvents, | ||
setAttribute, | ||
setAttributeNS, | ||
spread, | ||
ssr, | ||
ssrAttribute, | ||
ssrClassList, | ||
ssrElement, | ||
ssrHydrationKey, | ||
ssrSpread, | ||
ssrStyle, | ||
style, | ||
template, | ||
use, | ||
voidFn as useAssets | ||
}; |
@@ -60,3 +60,3 @@ import { JSX } from "./jsx.js"; | ||
node: MountableElement, | ||
options?: { renderId?: string, owner?: unknown } | ||
options?: { renderId?: string; owner?: unknown } | ||
): () => void; | ||
@@ -73,2 +73,2 @@ export function getHydrationKey(): string; | ||
export function Hydration(props: { children?: JSX.Element }): JSX.Element; | ||
export function NoHydration(props: { children?: JSX.Element }): JSX.Element; | ||
export function NoHydration(props: { children?: JSX.Element }): JSX.Element; |
@@ -1,1 +0,10 @@ | ||
export { getOwner, createComponent, createRoot as root, createRenderEffect as effect, createMemo as memo, sharedConfig, untrack, mergeProps } from "solid-js"; | ||
export { | ||
getOwner, | ||
createComponent, | ||
createRoot as root, | ||
createRenderEffect as effect, | ||
createMemo as memo, | ||
sharedConfig, | ||
untrack, | ||
mergeProps | ||
} from "solid-js"; |
import { hydrate as hydrateCore } from "./client.js"; | ||
import { JSX, ComponentProps, ValidComponent } from "solid-js"; | ||
export * from "./client.js"; | ||
export { For, Show, Suspense, SuspenseList, Switch, Match, Index, ErrorBoundary, mergeProps } from "solid-js"; | ||
export { | ||
For, | ||
Show, | ||
Suspense, | ||
SuspenseList, | ||
Switch, | ||
Match, | ||
Index, | ||
ErrorBoundary, | ||
mergeProps | ||
} from "solid-js"; | ||
export * from "./server-mock.js"; | ||
@@ -17,14 +27,21 @@ export declare const isServer: boolean; | ||
export declare function Portal<T extends boolean = false, S extends boolean = false>(props: { | ||
mount?: Node; | ||
useShadow?: T; | ||
isSVG?: S; | ||
ref?: (S extends true ? SVGGElement : HTMLDivElement) | ((el: (T extends true ? { | ||
readonly shadowRoot: ShadowRoot; | ||
} : {}) & (S extends true ? SVGGElement : HTMLDivElement)) => void); | ||
children: JSX.Element; | ||
mount?: Node; | ||
useShadow?: T; | ||
isSVG?: S; | ||
ref?: | ||
| (S extends true ? SVGGElement : HTMLDivElement) | ||
| (( | ||
el: (T extends true | ||
? { | ||
readonly shadowRoot: ShadowRoot; | ||
} | ||
: {}) & | ||
(S extends true ? SVGGElement : HTMLDivElement) | ||
) => void); | ||
children: JSX.Element; | ||
}): Text; | ||
export type DynamicProps<T extends ValidComponent, P = ComponentProps<T>> = { | ||
[K in keyof P]: P[K]; | ||
[K in keyof P]: P[K]; | ||
} & { | ||
component: T | undefined; | ||
component: T | undefined; | ||
}; | ||
@@ -31,0 +48,0 @@ /** |
@@ -1,37 +0,44 @@ | ||
export declare function renderToString<T>(fn: () => T, options?: { | ||
export declare function renderToString<T>( | ||
fn: () => T, | ||
options?: { | ||
nonce?: string; | ||
renderId?: string; | ||
}): string; | ||
export declare function renderToStringAsync<T>(fn: () => T, options?: { | ||
} | ||
): string; | ||
export declare function renderToStringAsync<T>( | ||
fn: () => T, | ||
options?: { | ||
timeoutMs?: number; | ||
nonce?: string; | ||
renderId?: string; | ||
}): Promise<string>; | ||
export declare function renderToStream<T>(fn: () => T, options?: { | ||
} | ||
): Promise<string>; | ||
export declare function renderToStream<T>( | ||
fn: () => T, | ||
options?: { | ||
nonce?: string; | ||
renderId?: string; | ||
onCompleteShell?: (info: { | ||
write: (v: string) => void; | ||
}) => void; | ||
onCompleteAll?: (info: { | ||
write: (v: string) => void; | ||
}) => void; | ||
}): { | ||
pipe: (writable: { | ||
write: (v: string) => void; | ||
}) => void; | ||
pipeTo: (writable: WritableStream) => void; | ||
onCompleteShell?: (info: { write: (v: string) => void }) => void; | ||
onCompleteAll?: (info: { write: (v: string) => void }) => void; | ||
} | ||
): { | ||
pipe: (writable: { write: (v: string) => void }) => void; | ||
pipeTo: (writable: WritableStream) => void; | ||
}; | ||
export declare function ssr(template: string[] | string, ...nodes: any[]): { | ||
t: string; | ||
export declare function ssr( | ||
template: string[] | string, | ||
...nodes: any[] | ||
): { | ||
t: string; | ||
}; | ||
export declare function ssrElement(name: string, props: any, children: any, needsId: boolean): { | ||
t: string; | ||
export declare function ssrElement( | ||
name: string, | ||
props: any, | ||
children: any, | ||
needsId: boolean | ||
): { | ||
t: string; | ||
}; | ||
export declare function ssrClassList(value: { | ||
[k: string]: boolean; | ||
}): string; | ||
export declare function ssrStyle(value: { | ||
[k: string]: string; | ||
}): string; | ||
export declare function ssrClassList(value: { [k: string]: boolean }): string; | ||
export declare function ssrStyle(value: { [k: string]: string }): string; | ||
export declare function ssrAttribute(key: string, value: boolean): string; | ||
@@ -46,3 +53,3 @@ export declare function ssrHydrationKey(): string; | ||
export type LegacyResults = { | ||
startWriting: () => void; | ||
startWriting: () => void; | ||
}; | ||
@@ -52,16 +59,24 @@ /** | ||
*/ | ||
export declare function pipeToWritable<T>(fn: () => T, writable: WritableStream, options?: { | ||
export declare function pipeToWritable<T>( | ||
fn: () => T, | ||
writable: WritableStream, | ||
options?: { | ||
nonce?: string; | ||
onReady?: (res: LegacyResults) => void; | ||
onCompleteAll?: () => void; | ||
}): void; | ||
} | ||
): void; | ||
/** | ||
* @deprecated Replaced by renderToStream | ||
*/ | ||
export declare function pipeToNodeWritable<T>(fn: () => T, writable: { | ||
export declare function pipeToNodeWritable<T>( | ||
fn: () => T, | ||
writable: { | ||
write: (v: string) => void; | ||
}, options?: { | ||
}, | ||
options?: { | ||
nonce?: string; | ||
onReady?: (res: LegacyResults) => void; | ||
onCompleteAll?: () => void; | ||
}): void; | ||
} | ||
): void; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
Sorry, the diff of this file is too big to display
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
830435
25545