Comparing version 1.9.2 to 1.9.3
877
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; | ||
} | ||
@@ -183,16 +185,21 @@ return m; | ||
current = detachedOwner === undefined ? owner : detachedOwner, | ||
root = unowned ? { | ||
owned: null, | ||
cleanups: null, | ||
context: null, | ||
owner: null | ||
} : { | ||
owned: null, | ||
cleanups: null, | ||
context: current ? current.context : null, | ||
owner: current | ||
}, | ||
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: current ? current.context : null, | ||
owner: current | ||
}, | ||
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); | ||
@@ -223,3 +230,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); | ||
} | ||
@@ -231,12 +239,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 && useContext(SuspenseContext); | ||
@@ -249,6 +259,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 && useContext(SuspenseContext); | ||
@@ -264,3 +280,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; | ||
@@ -282,3 +298,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; | ||
@@ -308,3 +324,4 @@ fetcher = pSource; | ||
id = sharedConfig.getNextContextId(); | ||
if (options.ssrLoadFrom === "initial") initP = options.initialValue;else if (sharedConfig.load && sharedConfig.has(id)) initP = sharedConfig.load(id); | ||
if (options.ssrLoadFrom === "initial") initP = options.initialValue; | ||
else if (sharedConfig.load && sharedConfig.has(id)) initP = sharedConfig.load(id); | ||
} | ||
@@ -315,5 +332,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; | ||
@@ -349,3 +369,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(); | ||
@@ -369,6 +390,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 (!isPromise(p)) { | ||
@@ -380,7 +406,8 @@ loadEnd(pr, p, undefined, lookup); | ||
if ("value" in p) { | ||
if (p.status === "success") loadEnd(pr, p.value, undefined, lookup);else loadEnd(pr, undefined, castError(p.value), lookup); | ||
if (p.status === "success") loadEnd(pr, p.value, undefined, lookup); | ||
else loadEnd(pr, undefined, castError(p.value), lookup); | ||
return p; | ||
} | ||
scheduled = true; | ||
queueMicrotask(() => scheduled = false); | ||
queueMicrotask(() => (scheduled = false)); | ||
runUpdates(() => { | ||
@@ -390,3 +417,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) | ||
); | ||
} | ||
@@ -415,7 +445,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 | ||
} | ||
]; | ||
} | ||
@@ -425,11 +459,26 @@ 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 [deferred, setDeferred] = createSignal(Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value, options); | ||
const node = createComputation( | ||
() => { | ||
if (!t || !t.fn) | ||
t = requestCallback( | ||
() => setDeferred(() => node.value), | ||
timeout !== undefined | ||
? { | ||
timeout | ||
} | ||
: undefined | ||
); | ||
return source(); | ||
}, | ||
undefined, | ||
true | ||
); | ||
const [deferred, setDeferred] = createSignal( | ||
Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value, | ||
options | ||
); | ||
updateComputation(node); | ||
setDeferred(() => Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value); | ||
setDeferred(() => | ||
Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value | ||
); | ||
return deferred; | ||
@@ -439,12 +488,20 @@ } | ||
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); | ||
@@ -455,3 +512,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(() => { | ||
@@ -462,3 +520,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 | ||
); | ||
}; | ||
@@ -503,3 +564,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; | ||
@@ -558,11 +622,13 @@ } | ||
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; | ||
@@ -575,3 +641,3 @@ } | ||
} | ||
const [transPending, setTransPending] = /*@__PURE__*/createSignal(false); | ||
const [transPending, setTransPending] = /*@__PURE__*/ createSignal(false); | ||
function useTransition() { | ||
@@ -585,8 +651,14 @@ return [transPending, startTransition]; | ||
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; | ||
@@ -602,3 +674,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; | ||
@@ -616,3 +689,5 @@ } | ||
let value; | ||
return Owner && Owner.context && (value = Owner.context[context.id]) !== undefined ? value : context.defaultValue; | ||
return Owner && Owner.context && (value = Owner.context[context.id]) !== undefined | ||
? value | ||
: context.defaultValue; | ||
} | ||
@@ -623,3 +698,3 @@ function children(fn) { | ||
name: "children" | ||
}) ; | ||
}); | ||
memo.toArray = () => { | ||
@@ -637,6 +712,3 @@ const c = memo(); | ||
if (ExternalSourceConfig) { | ||
const { | ||
factory: oldFactory, | ||
untrack: oldUntrack | ||
} = ExternalSourceConfig; | ||
const { factory: oldFactory, untrack: oldUntrack } = ExternalSourceConfig; | ||
ExternalSourceConfig = { | ||
@@ -666,3 +738,4 @@ factory: (fn, trigger) => { | ||
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; | ||
@@ -695,7 +768,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); | ||
@@ -713,6 +787,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; | ||
} | ||
@@ -733,3 +809,7 @@ if (Updates.length > 10e5) { | ||
const time = ExecCount; | ||
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)) { | ||
@@ -799,7 +879,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); | ||
} | ||
@@ -857,3 +941,4 @@ } | ||
if (!init) Updates = []; | ||
if (Effects) wait = true;else Effects = []; | ||
if (Effects) wait = true; | ||
else Effects = []; | ||
ExecCount++; | ||
@@ -872,3 +957,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; | ||
@@ -913,3 +999,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(); | ||
@@ -942,3 +1029,4 @@ } | ||
const e = queue[i]; | ||
if (!e.user) runTop(e);else queue[userLength++] = e; | ||
if (!e.user) runTop(e); | ||
else queue[userLength++] = e; | ||
} | ||
@@ -962,3 +1050,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) { | ||
@@ -969,3 +1058,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); | ||
@@ -980,4 +1070,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); | ||
@@ -1019,3 +1111,4 @@ } | ||
} | ||
if (Transition && Transition.running) node.tState = 0;else node.state = 0; | ||
if (Transition && Transition.running) node.tState = 0; | ||
else node.state = 0; | ||
delete node.sourceMap; | ||
@@ -1042,3 +1135,3 @@ } | ||
} catch (e) { | ||
handleError(e, owner && owner.owner || null); | ||
handleError(e, (owner && owner.owner) || null); | ||
} | ||
@@ -1050,8 +1143,10 @@ } | ||
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); | ||
} | ||
@@ -1073,9 +1168,14 @@ function resolveChildren(children) { | ||
let res; | ||
createRenderEffect(() => res = untrack(() => { | ||
Owner.context = { | ||
...Owner.context, | ||
[id]: props.value | ||
}; | ||
return children(() => props.children); | ||
}), undefined, options); | ||
createRenderEffect( | ||
() => | ||
(res = untrack(() => { | ||
Owner.context = { | ||
...Owner.context, | ||
[id]: props.value | ||
}; | ||
return children(() => props.children); | ||
})), | ||
undefined, | ||
options | ||
); | ||
return res; | ||
@@ -1086,3 +1186,5 @@ }; | ||
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]) { | ||
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]) { | ||
Owner.context = { | ||
@@ -1116,3 +1218,4 @@ ...Owner.context, | ||
} | ||
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) { | ||
@@ -1148,3 +1251,3 @@ return { | ||
const unsub = producer.subscribe(v => set(() => v)); | ||
onCleanup(() => "unsubscribe" in unsub ? unsub.unsubscribe() : unsub()); | ||
onCleanup(() => ("unsubscribe" in unsub ? unsub.unsubscribe() : unsub())); | ||
} else { | ||
@@ -1193,4 +1296,3 @@ const clean = producer(set); | ||
} | ||
} | ||
else if (len === 0) { | ||
} else if (len === 0) { | ||
mapped = new Array(newLen); | ||
@@ -1206,4 +1308,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]; | ||
@@ -1242,3 +1352,3 @@ tempdisposers[newEnd] = disposers[end]; | ||
} | ||
mapped = mapped.slice(0, len = newLen); | ||
mapped = mapped.slice(0, (len = newLen)); | ||
items = newItems.slice(0); | ||
@@ -1253,3 +1363,3 @@ } | ||
name: "index" | ||
}) ; | ||
}); | ||
indexes[j] = set; | ||
@@ -1313,3 +1423,3 @@ return mapFn(newItems[j], s); | ||
items = newItems.slice(0); | ||
return mapped = mapped.slice(0, len); | ||
return (mapped = mapped.slice(0, len)); | ||
}); | ||
@@ -1320,3 +1430,3 @@ function mapper(disposer) { | ||
name: "value" | ||
}) ; | ||
}); | ||
signals[i] = set; | ||
@@ -1337,3 +1447,3 @@ return mapFn(s, i); | ||
setHydrateContext(nextHydrateContext()); | ||
const r = devComponent(Comp, props || {}) ; | ||
const r = devComponent(Comp, props || {}); | ||
setHydrateContext(c); | ||
@@ -1387,25 +1497,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 (SUPPORTS_PROXY && 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 | ||
); | ||
} | ||
@@ -1423,11 +1537,16 @@ const sourcesMap = {}; | ||
if (!defined[key]) { | ||
defined[key] = desc.get ? { | ||
enumerable: true, | ||
configurable: true, | ||
get: resolveSources.bind(sourcesMap[key] = [desc.get.bind(source)]) | ||
} : desc.value !== undefined ? desc : undefined; | ||
defined[key] = desc.get | ||
? { | ||
enumerable: true, | ||
configurable: true, | ||
get: resolveSources.bind((sourcesMap[key] = [desc.get.bind(source)])) | ||
} | ||
: desc.value !== undefined | ||
? desc | ||
: undefined; | ||
} else { | ||
const sources = sourcesMap[key]; | ||
if (sources) { | ||
if (desc.get) sources.push(desc.get.bind(source));else if (desc.value !== undefined) sources.push(() => desc.value); | ||
if (desc.get) sources.push(desc.get.bind(source)); | ||
else if (desc.value !== undefined) sources.push(() => desc.value); | ||
} | ||
@@ -1442,3 +1561,4 @@ } | ||
desc = defined[key]; | ||
if (desc && desc.get) Object.defineProperty(target, key, desc);else target[key] = desc ? desc.value : undefined; | ||
if (desc && desc.get) Object.defineProperty(target, key, desc); | ||
else target[key] = desc ? desc.value : undefined; | ||
} | ||
@@ -1451,25 +1571,33 @@ return target; | ||
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; | ||
@@ -1481,3 +1609,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; | ||
@@ -1488,3 +1617,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); | ||
} | ||
@@ -1494,3 +1625,5 @@ ++objectIndex; | ||
if (!blocked) { | ||
isDefaultDesc ? otherObject[propName] = desc.value : Object.defineProperty(otherObject, propName, desc); | ||
isDefaultDesc | ||
? (otherObject[propName] = desc.value) | ||
: Object.defineProperty(otherObject, propName, desc); | ||
} | ||
@@ -1521,15 +1654,20 @@ } | ||
let Comp; | ||
return createMemo(() => (Comp = comp()) ? untrack(() => { | ||
if (true) Object.assign(Comp, { | ||
[$DEVCOMP]: true | ||
}); | ||
if (!ctx || sharedConfig.done) 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 || sharedConfig.done) 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; | ||
@@ -1543,3 +1681,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) { | ||
@@ -1549,5 +1688,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" | ||
} | ||
); | ||
} | ||
@@ -1558,5 +1701,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" | ||
} | ||
); | ||
} | ||
@@ -1566,19 +1713,31 @@ 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" | ||
} ); | ||
); | ||
} | ||
@@ -1589,29 +1748,45 @@ function Switch(props) { | ||
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" | ||
} | ||
); | ||
} | ||
@@ -1627,24 +1802,30 @@ function Match(props) { | ||
let err; | ||
if (sharedConfig.context && sharedConfig.load) err = sharedConfig.load(sharedConfig.getContextId()); | ||
if (sharedConfig.context && sharedConfig.load) | ||
err = sharedConfig.load(sharedConfig.getContextId()); | ||
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 SuspenseListContext = /* #__PURE__ */createContext(); | ||
const suspenseListEquals = (a, b) => | ||
a.showContent === b.showContent && a.showFallback === b.showFallback; | ||
const SuspenseListContext = /* #__PURE__ */ createContext(); | ||
function SuspenseList(props) { | ||
@@ -1660,47 +1841,47 @@ let [wrapper, setWrapper] = createSignal(() => ({ | ||
} | ||
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); | ||
@@ -1750,3 +1931,4 @@ return createComponent(SuspenseListContext.Provider, { | ||
if (ref) { | ||
if (typeof ref !== "object" || ref.status !== "success") p = ref;else sharedConfig.gather(key); | ||
if (typeof ref !== "object" || ref.status !== "success") p = ref; | ||
else sharedConfig.gather(key); | ||
} | ||
@@ -1758,12 +1940,15 @@ if (p && p !== "$$f") { | ||
flicker = s; | ||
p.then(() => { | ||
if (sharedConfig.done) return set(); | ||
sharedConfig.gather(key); | ||
setHydrateContext(ctx); | ||
set(); | ||
setHydrateContext(); | ||
}, err => { | ||
error = err; | ||
set(); | ||
}); | ||
p.then( | ||
() => { | ||
if (sharedConfig.done) return set(); | ||
sharedConfig.gather(key); | ||
setHydrateContext(ctx); | ||
set(); | ||
setHydrateContext(); | ||
}, | ||
err => { | ||
error = err; | ||
set(); | ||
} | ||
); | ||
} | ||
@@ -1783,3 +1968,3 @@ } | ||
flicker(); | ||
return flicker = undefined; | ||
return (flicker = undefined); | ||
} | ||
@@ -1790,7 +1975,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; | ||
@@ -1825,7 +2007,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); | ||
} | ||
@@ -47,8 +48,11 @@ return o; | ||
current = detachedOwner === undefined ? owner : detachedOwner, | ||
root = fn.length === 0 ? UNOWNED : { | ||
context: current ? current.context : null, | ||
owner: current, | ||
owned: null, | ||
cleanups: null | ||
}; | ||
root = | ||
fn.length === 0 | ||
? UNOWNED | ||
: { | ||
context: current ? current.context : null, | ||
owner: current, | ||
owned: null, | ||
cleanups: null | ||
}; | ||
Owner = root; | ||
@@ -66,5 +70,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); | ||
} | ||
]; | ||
} | ||
@@ -126,3 +133,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); | ||
} | ||
@@ -168,3 +176,5 @@ return fn; | ||
function useContext(context) { | ||
return Owner && Owner.context && Owner.context[context.id] !== undefined ? Owner.context[context.id] : context.defaultValue; | ||
return Owner && Owner.context && Owner.context[context.id] !== undefined | ||
? Owner.context[context.id] | ||
: context.defaultValue; | ||
} | ||
@@ -246,3 +256,4 @@ function getOwner() { | ||
} | ||
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) { | ||
@@ -276,3 +287,3 @@ return { | ||
const unsub = producer.subscribe(v => set(() => v)); | ||
onCleanup(() => "unsubscribe" in unsub ? unsub.unsubscribe() : unsub()); | ||
onCleanup(() => ("unsubscribe" in unsub ? unsub.unsubscribe() : unsub())); | ||
} else { | ||
@@ -320,3 +331,3 @@ const clean = producer(set); | ||
if (typeof prev !== "object" && typeof node[i] !== "object") mapped += `<!--!$-->`; | ||
mapped += resolveSSRNode(prev = node[i]); | ||
mapped += resolveSSRNode((prev = node[i])); | ||
} | ||
@@ -336,3 +347,4 @@ return mapped; | ||
getNextContextId() { | ||
if (!this.context) throw new Error(`getNextContextId cannot be used under non-hydrating context`); | ||
if (!this.context) | ||
throw new Error(`getNextContextId cannot be used under non-hydrating context`); | ||
return getContextId(this.context.count++); | ||
@@ -350,7 +362,9 @@ } | ||
function nextHydrateContext() { | ||
return sharedConfig.context ? { | ||
...sharedConfig.context, | ||
id: sharedConfig.getNextContextId(), | ||
count: 0 | ||
} : undefined; | ||
return sharedConfig.context | ||
? { | ||
...sharedConfig.context, | ||
id: sharedConfig.getNextContextId(), | ||
count: 0 | ||
} | ||
: undefined; | ||
} | ||
@@ -430,3 +444,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 || ""; | ||
} | ||
@@ -468,7 +486,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; | ||
} | ||
); | ||
}); | ||
@@ -503,3 +524,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; | ||
@@ -510,3 +532,6 @@ } | ||
if (error) throw error; | ||
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 && resourceContext) resourceContext.push(id); | ||
@@ -532,3 +557,3 @@ if (!resolved && read.loading) { | ||
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]) { | ||
@@ -555,17 +580,19 @@ value = ctx.resources[id].data; | ||
read.state = "pending"; | ||
p = 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); | ||
throw error; | ||
}); | ||
p = 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); | ||
throw error; | ||
}); | ||
if (ctx.serialize) ctx.serialize(id, p, options.deferStream); | ||
@@ -580,6 +607,9 @@ return 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) | ||
} | ||
]); | ||
} | ||
@@ -591,3 +621,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; | ||
@@ -601,3 +631,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); | ||
@@ -614,6 +645,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); | ||
}) | ||
); | ||
} | ||
@@ -646,5 +679,8 @@ return ""; | ||
function useTransition() { | ||
return [() => false, fn => { | ||
fn(); | ||
}]; | ||
return [ | ||
() => false, | ||
fn => { | ||
fn(); | ||
} | ||
]; | ||
} | ||
@@ -659,11 +695,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) { | ||
@@ -682,8 +720,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); | ||
} | ||
}) | ||
); | ||
} | ||
@@ -720,2 +760,56 @@ const res = runSuspense(); | ||
export { $DEVCOMP, $PROXY, $TRACK, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, batch, 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, | ||
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 | ||
}; |
@@ -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; | ||
} | ||
@@ -178,8 +180,10 @@ return m; | ||
current = detachedOwner === undefined ? owner : detachedOwner, | ||
root = unowned ? UNOWNED : { | ||
owned: null, | ||
cleanups: null, | ||
context: current ? current.context : null, | ||
owner: current | ||
}, | ||
root = unowned | ||
? UNOWNED | ||
: { | ||
owned: null, | ||
cleanups: null, | ||
context: current ? current.context : null, | ||
owner: current | ||
}, | ||
updateFn = unowned ? fn : () => fn(() => untrack(() => cleanNode(root))); | ||
@@ -205,3 +209,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); | ||
} | ||
@@ -214,7 +219,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); | ||
} | ||
@@ -231,6 +238,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 && useContext(SuspenseContext); | ||
@@ -263,3 +275,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; | ||
@@ -289,3 +301,4 @@ fetcher = pSource; | ||
id = sharedConfig.getNextContextId(); | ||
if (options.ssrLoadFrom === "initial") initP = options.initialValue;else if (sharedConfig.load && sharedConfig.has(id)) initP = sharedConfig.load(id); | ||
if (options.ssrLoadFrom === "initial") initP = options.initialValue; | ||
else if (sharedConfig.load && sharedConfig.has(id)) initP = sharedConfig.load(id); | ||
} | ||
@@ -296,5 +309,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; | ||
@@ -330,3 +346,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(); | ||
@@ -350,6 +367,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 (!isPromise(p)) { | ||
@@ -361,7 +383,8 @@ loadEnd(pr, p, undefined, lookup); | ||
if ("value" in p) { | ||
if (p.status === "success") loadEnd(pr, p.value, undefined, lookup);else loadEnd(pr, undefined, castError(p.value), lookup); | ||
if (p.status === "success") loadEnd(pr, p.value, undefined, lookup); | ||
else loadEnd(pr, undefined, castError(p.value), lookup); | ||
return p; | ||
} | ||
scheduled = true; | ||
queueMicrotask(() => scheduled = false); | ||
queueMicrotask(() => (scheduled = false)); | ||
runUpdates(() => { | ||
@@ -371,3 +394,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) | ||
); | ||
} | ||
@@ -396,7 +422,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 | ||
} | ||
]; | ||
} | ||
@@ -406,11 +436,26 @@ 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 [deferred, setDeferred] = createSignal(Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value, options); | ||
const node = createComputation( | ||
() => { | ||
if (!t || !t.fn) | ||
t = requestCallback( | ||
() => setDeferred(() => node.value), | ||
timeout !== undefined | ||
? { | ||
timeout | ||
} | ||
: undefined | ||
); | ||
return source(); | ||
}, | ||
undefined, | ||
true | ||
); | ||
const [deferred, setDeferred] = createSignal( | ||
Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value, | ||
options | ||
); | ||
updateComputation(node); | ||
setDeferred(() => Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value); | ||
setDeferred(() => | ||
Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value | ||
); | ||
return deferred; | ||
@@ -420,12 +465,19 @@ } | ||
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); | ||
@@ -436,3 +488,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(() => { | ||
@@ -443,3 +496,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 | ||
); | ||
}; | ||
@@ -484,3 +540,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; | ||
@@ -539,11 +597,13 @@ } | ||
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; | ||
@@ -556,3 +616,3 @@ } | ||
} | ||
const [transPending, setTransPending] = /*@__PURE__*/createSignal(false); | ||
const [transPending, setTransPending] = /*@__PURE__*/ createSignal(false); | ||
function useTransition() { | ||
@@ -575,3 +635,5 @@ return [transPending, startTransition]; | ||
let value; | ||
return Owner && Owner.context && (value = Owner.context[context.id]) !== undefined ? value : context.defaultValue; | ||
return Owner && Owner.context && (value = Owner.context[context.id]) !== undefined | ||
? value | ||
: context.defaultValue; | ||
} | ||
@@ -593,6 +655,3 @@ function children(fn) { | ||
if (ExternalSourceConfig) { | ||
const { | ||
factory: oldFactory, | ||
untrack: oldUntrack | ||
} = ExternalSourceConfig; | ||
const { factory: oldFactory, untrack: oldUntrack } = ExternalSourceConfig; | ||
ExternalSourceConfig = { | ||
@@ -622,3 +681,4 @@ factory: (fn, trigger) => { | ||
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; | ||
@@ -651,7 +711,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); | ||
@@ -669,10 +730,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(); | ||
@@ -689,3 +752,7 @@ } | ||
const time = ExecCount; | ||
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)) { | ||
@@ -755,7 +822,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); | ||
} | ||
@@ -811,3 +881,4 @@ } | ||
if (!init) Updates = []; | ||
if (Effects) wait = true;else Effects = []; | ||
if (Effects) wait = true; | ||
else Effects = []; | ||
ExecCount++; | ||
@@ -826,3 +897,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; | ||
@@ -895,3 +967,4 @@ } | ||
const e = queue[i]; | ||
if (!e.user) runTop(e);else queue[userLength++] = e; | ||
if (!e.user) runTop(e); | ||
else queue[userLength++] = e; | ||
} | ||
@@ -915,3 +988,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) { | ||
@@ -922,3 +996,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); | ||
@@ -933,4 +1008,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); | ||
@@ -972,3 +1049,4 @@ } | ||
} | ||
if (Transition && Transition.running) node.tState = 0;else node.state = 0; | ||
if (Transition && Transition.running) node.tState = 0; | ||
else node.state = 0; | ||
} | ||
@@ -994,3 +1072,3 @@ function reset(node, top) { | ||
} catch (e) { | ||
handleError(e, owner && owner.owner || null); | ||
handleError(e, (owner && owner.owner) || null); | ||
} | ||
@@ -1002,8 +1080,10 @@ } | ||
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); | ||
} | ||
@@ -1025,9 +1105,13 @@ function resolveChildren(children) { | ||
let res; | ||
createRenderEffect(() => res = untrack(() => { | ||
Owner.context = { | ||
...Owner.context, | ||
[id]: props.value | ||
}; | ||
return children(() => props.children); | ||
}), undefined); | ||
createRenderEffect( | ||
() => | ||
(res = untrack(() => { | ||
Owner.context = { | ||
...Owner.context, | ||
[id]: props.value | ||
}; | ||
return children(() => props.children); | ||
})), | ||
undefined | ||
); | ||
return res; | ||
@@ -1038,3 +1122,4 @@ }; | ||
ERROR || (ERROR = Symbol("error")); | ||
if (Owner === null) ;else if (Owner.context === null || !Owner.context[ERROR]) { | ||
if (Owner === null); | ||
else if (Owner.context === null || !Owner.context[ERROR]) { | ||
Owner.context = { | ||
@@ -1068,3 +1153,4 @@ ...Owner.context, | ||
} | ||
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) { | ||
@@ -1100,3 +1186,3 @@ return { | ||
const unsub = producer.subscribe(v => set(() => v)); | ||
onCleanup(() => "unsubscribe" in unsub ? unsub.unsubscribe() : unsub()); | ||
onCleanup(() => ("unsubscribe" in unsub ? unsub.unsubscribe() : unsub())); | ||
} else { | ||
@@ -1145,4 +1231,3 @@ const clean = producer(set); | ||
} | ||
} | ||
else if (len === 0) { | ||
} else if (len === 0) { | ||
mapped = new Array(newLen); | ||
@@ -1158,4 +1243,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]; | ||
@@ -1194,3 +1287,3 @@ tempdisposers[newEnd] = disposers[end]; | ||
} | ||
mapped = mapped.slice(0, len = newLen); | ||
mapped = mapped.slice(0, (len = newLen)); | ||
items = newItems.slice(0); | ||
@@ -1262,3 +1355,3 @@ } | ||
items = newItems.slice(0); | ||
return mapped = mapped.slice(0, len); | ||
return (mapped = mapped.slice(0, len)); | ||
}); | ||
@@ -1332,25 +1425,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 (SUPPORTS_PROXY && 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 | ||
); | ||
} | ||
@@ -1368,11 +1465,16 @@ const sourcesMap = {}; | ||
if (!defined[key]) { | ||
defined[key] = desc.get ? { | ||
enumerable: true, | ||
configurable: true, | ||
get: resolveSources.bind(sourcesMap[key] = [desc.get.bind(source)]) | ||
} : desc.value !== undefined ? desc : undefined; | ||
defined[key] = desc.get | ||
? { | ||
enumerable: true, | ||
configurable: true, | ||
get: resolveSources.bind((sourcesMap[key] = [desc.get.bind(source)])) | ||
} | ||
: desc.value !== undefined | ||
? desc | ||
: undefined; | ||
} else { | ||
const sources = sourcesMap[key]; | ||
if (sources) { | ||
if (desc.get) sources.push(desc.get.bind(source));else if (desc.value !== undefined) sources.push(() => desc.value); | ||
if (desc.get) sources.push(desc.get.bind(source)); | ||
else if (desc.value !== undefined) sources.push(() => desc.value); | ||
} | ||
@@ -1387,3 +1489,4 @@ } | ||
desc = defined[key]; | ||
if (desc && desc.get) Object.defineProperty(target, key, desc);else target[key] = desc ? desc.value : undefined; | ||
if (desc && desc.get) Object.defineProperty(target, key, desc); | ||
else target[key] = desc ? desc.value : undefined; | ||
} | ||
@@ -1396,25 +1499,33 @@ return target; | ||
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; | ||
@@ -1426,3 +1537,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; | ||
@@ -1433,3 +1545,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); | ||
} | ||
@@ -1439,3 +1553,5 @@ ++objectIndex; | ||
if (!blocked) { | ||
isDefaultDesc ? otherObject[propName] = desc.value : Object.defineProperty(otherObject, propName, desc); | ||
isDefaultDesc | ||
? (otherObject[propName] = desc.value) | ||
: Object.defineProperty(otherObject, propName, desc); | ||
} | ||
@@ -1466,13 +1582,17 @@ } | ||
let Comp; | ||
return createMemo(() => (Comp = comp()) ? untrack(() => { | ||
if (false) ; | ||
if (!ctx || sharedConfig.done) 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 || sharedConfig.done) 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; | ||
@@ -1502,16 +1622,28 @@ } | ||
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 | ||
); | ||
} | ||
@@ -1522,26 +1654,42 @@ function Switch(props) { | ||
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 | ||
); | ||
} | ||
@@ -1557,3 +1705,4 @@ function Match(props) { | ||
let err; | ||
if (sharedConfig.context && sharedConfig.load) err = sharedConfig.load(sharedConfig.getContextId()); | ||
if (sharedConfig.context && sharedConfig.load) | ||
err = sharedConfig.load(sharedConfig.getContextId()); | ||
const [errored, setErrored] = createSignal(err, undefined); | ||
@@ -1563,14 +1712,19 @@ 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 SuspenseListContext = /* #__PURE__ */createContext(); | ||
const suspenseListEquals = (a, b) => | ||
a.showContent === b.showContent && a.showFallback === b.showFallback; | ||
const SuspenseListContext = /* #__PURE__ */ createContext(); | ||
function SuspenseList(props) { | ||
@@ -1586,47 +1740,47 @@ let [wrapper, setWrapper] = createSignal(() => ({ | ||
} | ||
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); | ||
@@ -1676,3 +1830,4 @@ return createComponent(SuspenseListContext.Provider, { | ||
if (ref) { | ||
if (typeof ref !== "object" || ref.status !== "success") p = ref;else sharedConfig.gather(key); | ||
if (typeof ref !== "object" || ref.status !== "success") p = ref; | ||
else sharedConfig.gather(key); | ||
} | ||
@@ -1684,12 +1839,15 @@ if (p && p !== "$$f") { | ||
flicker = s; | ||
p.then(() => { | ||
if (sharedConfig.done) return set(); | ||
sharedConfig.gather(key); | ||
setHydrateContext(ctx); | ||
set(); | ||
setHydrateContext(); | ||
}, err => { | ||
error = err; | ||
set(); | ||
}); | ||
p.then( | ||
() => { | ||
if (sharedConfig.done) return set(); | ||
sharedConfig.gather(key); | ||
setHydrateContext(ctx); | ||
set(); | ||
setHydrateContext(); | ||
}, | ||
err => { | ||
error = err; | ||
set(); | ||
} | ||
); | ||
} | ||
@@ -1709,3 +1867,3 @@ } | ||
flicker(); | ||
return flicker = undefined; | ||
return (flicker = undefined); | ||
} | ||
@@ -1716,7 +1874,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; | ||
@@ -1749,2 +1904,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"; | ||
@@ -22,5 +29,14 @@ 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 || "bigint" === type || "symbol" === 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 || | ||
"bigint" === type || | ||
"symbol" === type || | ||
l instanceof Date || | ||
l instanceof RegExp | ||
) { | ||
e.appendChild(document.createTextNode(l.toString())); | ||
@@ -37,3 +53,6 @@ } else if (Array.isArray(l)) { | ||
const fixedClasses = classes.join(" "), | ||
value = typeof d["class"].value === "function" ? () => fixedClasses + " " + d["class"].value() : fixedClasses + " " + l["class"]; | ||
value = | ||
typeof d["class"].value === "function" | ||
? () => fixedClasses + " " + d["class"].value() | ||
: fixedClasses + " " + l["class"]; | ||
Object.defineProperty(l, "class", { | ||
@@ -50,3 +69,5 @@ ...d[k], | ||
} | ||
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) { | ||
@@ -56,3 +77,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 = {}); | ||
@@ -73,3 +98,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); | ||
} | ||
@@ -91,3 +117,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] === ".") classes.push(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] === ".") classes.push(s); | ||
else if (v[0] === "#") e.setAttribute("id", s); | ||
} | ||
@@ -94,0 +125,0 @@ } |
@@ -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.d.ts"; | ||
import type { JSX } from "./jsx.d.ts"; | ||
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,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 = { | ||
@@ -25,4 +47,4 @@ area: true, | ||
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++; | ||
} | ||
@@ -369,22 +449,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++}]`); | ||
@@ -412,3 +494,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; | ||
@@ -444,3 +539,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; | ||
@@ -451,3 +553,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++) { | ||
@@ -464,7 +567,11 @@ 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); | ||
const isCE = node.name.includes("-") || node.attrs.some(e => e.name === "is"); | ||
options.hasCustomElement = isCE; | ||
options.isImportNode = (node.name === 'img' || node.name === 'iframe') && node.attrs.some(e => e.name === "loading" && e.value === 'lazy'); | ||
options.isImportNode = | ||
(node.name === "img" || node.name === "iframe") && | ||
node.attrs.some(e => e.name === "loading" && e.value === "lazy"); | ||
if (node.attrs.some(e => e.name === "###")) { | ||
@@ -475,11 +582,9 @@ const spreadArgs = []; | ||
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 === "###") { | ||
@@ -494,3 +599,3 @@ if (current.length) { | ||
} | ||
} else if (type === 'directive') { | ||
} else if (type === "directive") { | ||
parseDirective(name, value, tag, options); | ||
@@ -503,11 +608,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); | ||
@@ -529,3 +636,6 @@ node.attrs.splice(i, 1); | ||
if (topDecl) { | ||
options.decl[0] = options.hasCustomElement || options.isImportNode ? `const ${tag} = r.untrack(() => document.importNode(tmpls[${templateId}].content.firstChild, true))` : `const ${tag} = tmpls[${templateId}].content.firstChild.cloneNode(true)`; | ||
options.decl[0] = | ||
options.hasCustomElement || options.isImportNode | ||
? `const ${tag} = r.untrack(() => document.importNode(tmpls[${templateId}].content.firstChild, true))` | ||
: `const ${tag} = tmpls[${templateId}].content.firstChild.cloneNode(true)`; | ||
} | ||
@@ -565,6 +675,8 @@ } else if (node.type === "text") { | ||
if (nodes.length > 1) { | ||
nodes = [{ | ||
type: "fragment", | ||
children: nodes | ||
}]; | ||
nodes = [ | ||
{ | ||
type: "fragment", | ||
children: nodes | ||
} | ||
]; | ||
} | ||
@@ -577,8 +689,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); | ||
@@ -585,0 +710,0 @@ } |
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: EventListener | EventListenerObject | (EventListenerObject & AddEventListenerOptions), delegate: boolean): void; | ||
delegateEvents(eventNames: string[]): void; | ||
classList(node: Element, value: { | ||
[k: string]: boolean; | ||
}, prev?: { | ||
[k: string]: boolean; | ||
}): { | ||
[k: string]: boolean; | ||
}; | ||
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: EventListener | EventListenerObject | (EventListenerObject & AddEventListenerOptions), | ||
delegate: boolean | ||
): void; | ||
delegateEvents(eventNames: string[]): void; | ||
classList( | ||
node: Element, | ||
value: { | ||
[k: string]: boolean; | ||
}, | ||
prev?: { | ||
[k: string]: boolean; | ||
} | ||
): { | ||
[k: string]: boolean; | ||
}; | ||
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.9.2", | ||
"version": "1.9.3", | ||
"author": "Ryan Carniato", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -1,2 +0,2 @@ | ||
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"; | ||
@@ -14,3 +14,3 @@ const $RAW = Symbol("store-raw"), | ||
Object.defineProperty(value, $PROXY, { | ||
value: p = new Proxy(value, proxyTraps$1) | ||
value: (p = new Proxy(value, proxyTraps$1)) | ||
}); | ||
@@ -35,10 +35,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++) { | ||
@@ -49,3 +57,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), | ||
@@ -64,5 +73,6 @@ desc = Object.getOwnPropertyDescriptors(item); | ||
let nodes = target[symbol]; | ||
if (!nodes) Object.defineProperty(target, symbol, { | ||
value: nodes = Object.create(null) | ||
}); | ||
if (!nodes) | ||
Object.defineProperty(target, symbol, { | ||
value: (nodes = Object.create(null)) | ||
}); | ||
return nodes; | ||
@@ -77,7 +87,8 @@ } | ||
s.$ = set; | ||
return nodes[property] = s; | ||
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; | ||
@@ -109,3 +120,8 @@ delete desc.writable; | ||
const desc = Object.getOwnPropertyDescriptor(target, property); | ||
if (getListener() && (typeof value !== "function" || target.hasOwnProperty(property)) && !(desc && desc.get)) value = getNode(nodes, property, value)(); | ||
if ( | ||
getListener() && | ||
(typeof value !== "function" || target.hasOwnProperty(property)) && | ||
!(desc && desc.get) | ||
) | ||
value = getNode(nodes, property, value)(); | ||
} | ||
@@ -115,3 +131,11 @@ return isWrappable(value) ? wrap$1(value) : value; | ||
has(target, property) { | ||
if (property === $RAW || property === $PROXY || property === $TRACK || property === $NODE || property === $HAS || property === "__proto__") return true; | ||
if ( | ||
property === $RAW || | ||
property === $PROXY || | ||
property === $TRACK || | ||
property === $NODE || | ||
property === $HAS || | ||
property === "__proto__" | ||
) | ||
return true; | ||
getListener() && getNode(getNodes(target, $HAS), property)(); | ||
@@ -145,3 +169,3 @@ return property in target; | ||
node; | ||
if (node = getNode(nodes, property, prev)) node.$(() => value); | ||
if ((node = getNode(nodes, property, prev))) node.$(() => value); | ||
if (Array.isArray(state) && state.length !== len) { | ||
@@ -192,7 +216,3 @@ for (let i = state.length; i < len; i++) (node = nodes[i]) && 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) { | ||
@@ -216,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); | ||
@@ -224,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); | ||
@@ -233,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); | ||
}); | ||
@@ -242,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; | ||
@@ -265,3 +298,5 @@ } | ||
const isFunction = typeof value === "function"; | ||
if (getListener() && (!isFunction || target.hasOwnProperty(property)) && !(desc && desc.get)) value = getNode(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)); | ||
@@ -273,3 +308,11 @@ } | ||
has(target, property) { | ||
if (property === $RAW || property === $PROXY || property === $TRACK || property === $NODE || property === $HAS || property === "__proto__") return true; | ||
if ( | ||
property === $RAW || | ||
property === $PROXY || | ||
property === $TRACK || | ||
property === $NODE || | ||
property === $HAS || | ||
property === "__proto__" | ||
) | ||
return true; | ||
getListener() && getNode(getNodes(target, $HAS), property)(); | ||
@@ -293,3 +336,3 @@ return property in target; | ||
Object.defineProperty(value, $PROXY, { | ||
value: p = new Proxy(value, proxyTraps) | ||
value: (p = new Proxy(value, proxyTraps)) | ||
}); | ||
@@ -299,3 +342,8 @@ const keys = Object.keys(value), | ||
const proto = Object.getPrototypeOf(value); | ||
const isClass = proto !== null && value !== null && typeof value === "object" && !Array.isArray(value) && proto !== Object.prototype; | ||
const isClass = | ||
proto !== null && | ||
value !== null && | ||
typeof value === "object" && | ||
!Array.isArray(value) && | ||
proto !== Object.prototype; | ||
if (isClass) { | ||
@@ -330,3 +378,6 @@ const descriptors = Object.getOwnPropertyDescriptors(proto); | ||
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); | ||
@@ -348,3 +399,9 @@ DEV$1.registerGraph({ | ||
const isArray = Array.isArray(target); | ||
if (property !== $ROOT && (!isWrappable(target) || !isWrappable(previous) || isArray !== Array.isArray(previous) || key && target[key] !== previous[key])) { | ||
if ( | ||
property !== $ROOT && | ||
(!isWrappable(target) || | ||
!isWrappable(previous) || | ||
isArray !== Array.isArray(previous) || | ||
(key && target[key] !== previous[key])) | ||
) { | ||
setProperty(parent, property, target); | ||
@@ -354,5 +411,15 @@ return; | ||
if (isArray) { | ||
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); | ||
@@ -362,3 +429,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]; | ||
@@ -417,12 +491,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; | ||
@@ -437,3 +514,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; | ||
}, | ||
@@ -454,3 +534,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))); | ||
} | ||
@@ -467,4 +547,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); | ||
@@ -116,2 +116,14 @@ } else setProperty(current, part, value); | ||
export { $RAW, DEV, createMutable, createStore, isWrappable, modifyMutable, produce, reconcile, setProperty, unwrap, updatePath }; | ||
export { | ||
$RAW, | ||
DEV, | ||
createMutable, | ||
createStore, | ||
isWrappable, | ||
modifyMutable, | ||
produce, | ||
reconcile, | ||
setProperty, | ||
unwrap, | ||
updatePath | ||
}; |
@@ -1,2 +0,2 @@ | ||
import { $PROXY, $TRACK, getListener, batch, createSignal } from 'solid-js'; | ||
import { $PROXY, $TRACK, getListener, batch, createSignal } from "solid-js"; | ||
@@ -11,3 +11,3 @@ const $RAW = Symbol("store-raw"), | ||
Object.defineProperty(value, $PROXY, { | ||
value: p = new Proxy(value, proxyTraps$1) | ||
value: (p = new Proxy(value, proxyTraps$1)) | ||
}); | ||
@@ -32,10 +32,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++) { | ||
@@ -46,3 +54,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), | ||
@@ -61,5 +70,6 @@ desc = Object.getOwnPropertyDescriptors(item); | ||
let nodes = target[symbol]; | ||
if (!nodes) Object.defineProperty(target, symbol, { | ||
value: nodes = Object.create(null) | ||
}); | ||
if (!nodes) | ||
Object.defineProperty(target, symbol, { | ||
value: (nodes = Object.create(null)) | ||
}); | ||
return nodes; | ||
@@ -74,7 +84,8 @@ } | ||
s.$ = set; | ||
return nodes[property] = s; | ||
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; | ||
@@ -106,3 +117,8 @@ delete desc.writable; | ||
const desc = Object.getOwnPropertyDescriptor(target, property); | ||
if (getListener() && (typeof value !== "function" || target.hasOwnProperty(property)) && !(desc && desc.get)) value = getNode(nodes, property, value)(); | ||
if ( | ||
getListener() && | ||
(typeof value !== "function" || target.hasOwnProperty(property)) && | ||
!(desc && desc.get) | ||
) | ||
value = getNode(nodes, property, value)(); | ||
} | ||
@@ -112,3 +128,11 @@ return isWrappable(value) ? wrap$1(value) : value; | ||
has(target, property) { | ||
if (property === $RAW || property === $PROXY || property === $TRACK || property === $NODE || property === $HAS || property === "__proto__") return true; | ||
if ( | ||
property === $RAW || | ||
property === $PROXY || | ||
property === $TRACK || | ||
property === $NODE || | ||
property === $HAS || | ||
property === "__proto__" | ||
) | ||
return true; | ||
getListener() && getNode(getNodes(target, $HAS), property)(); | ||
@@ -139,3 +163,3 @@ return property in target; | ||
node; | ||
if (node = getNode(nodes, property, prev)) node.$(() => value); | ||
if ((node = getNode(nodes, property, prev))) node.$(() => value); | ||
if (Array.isArray(state) && state.length !== len) { | ||
@@ -186,7 +210,3 @@ for (let i = state.length; i < len; i++) (node = nodes[i]) && 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) { | ||
@@ -210,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); | ||
@@ -221,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); | ||
}); | ||
@@ -230,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; | ||
@@ -253,3 +283,5 @@ } | ||
const isFunction = typeof value === "function"; | ||
if (getListener() && (!isFunction || target.hasOwnProperty(property)) && !(desc && desc.get)) value = getNode(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)); | ||
@@ -261,3 +293,11 @@ } | ||
has(target, property) { | ||
if (property === $RAW || property === $PROXY || property === $TRACK || property === $NODE || property === $HAS || property === "__proto__") return true; | ||
if ( | ||
property === $RAW || | ||
property === $PROXY || | ||
property === $TRACK || | ||
property === $NODE || | ||
property === $HAS || | ||
property === "__proto__" | ||
) | ||
return true; | ||
getListener() && getNode(getNodes(target, $HAS), property)(); | ||
@@ -281,3 +321,3 @@ return property in target; | ||
Object.defineProperty(value, $PROXY, { | ||
value: p = new Proxy(value, proxyTraps) | ||
value: (p = new Proxy(value, proxyTraps)) | ||
}); | ||
@@ -287,3 +327,8 @@ const keys = Object.keys(value), | ||
const proto = Object.getPrototypeOf(value); | ||
const isClass = proto !== null && value !== null && typeof value === "object" && !Array.isArray(value) && proto !== Object.prototype; | ||
const isClass = | ||
proto !== null && | ||
value !== null && | ||
typeof value === "object" && | ||
!Array.isArray(value) && | ||
proto !== Object.prototype; | ||
if (isClass) { | ||
@@ -330,3 +375,9 @@ const descriptors = Object.getOwnPropertyDescriptors(proto); | ||
const isArray = Array.isArray(target); | ||
if (property !== $ROOT && (!isWrappable(target) || !isWrappable(previous) || isArray !== Array.isArray(previous) || key && target[key] !== previous[key])) { | ||
if ( | ||
property !== $ROOT && | ||
(!isWrappable(target) || | ||
!isWrappable(previous) || | ||
isArray !== Array.isArray(previous) || | ||
(key && target[key] !== previous[key])) | ||
) { | ||
setProperty(parent, property, target); | ||
@@ -336,5 +387,15 @@ return; | ||
if (isArray) { | ||
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); | ||
@@ -344,3 +405,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]; | ||
@@ -399,12 +467,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; | ||
@@ -419,3 +490,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; | ||
}, | ||
@@ -436,3 +510,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))); | ||
} | ||
@@ -439,0 +513,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; |
import type { SetStoreFunction, Store } 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 declare const $RAW: unique symbol; | ||
export declare function isWrappable(obj: any): boolean; | ||
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; | ||
@@ -12,7 +29,10 @@ 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; |
@@ -1,20 +0,36 @@ | ||
export declare const $RAW: unique symbol, $NODE: unique symbol, $HAS: unique symbol, $SELF: unique symbol; | ||
export declare const $RAW: unique symbol, | ||
$NODE: unique symbol, | ||
$HAS: unique symbol, | ||
$SELF: unique symbol; | ||
export declare const DevHooks: { | ||
onStoreNodeUpdate: OnStoreNodeUpdate | null; | ||
onStoreNodeUpdate: OnStoreNodeUpdate | null; | ||
}; | ||
type DataNode = { | ||
(): any; | ||
$(value?: any): void; | ||
(): any; | ||
$(value?: any): void; | ||
}; | ||
export 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; | ||
@@ -36,61 +52,192 @@ export declare function isWrappable<T>(obj: T | NotWrappable): obj is T; | ||
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 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 +249,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,64 @@ | ||
export { $DEVCOMP, $PROXY, $TRACK, batch, catchError, children, createComputed, createContext, createDeferred, createEffect, createMemo, createReaction, createRenderEffect, createResource, createRoot, createSelector, createSignal, enableExternalSource, enableScheduling, equalFn, getListener, getOwner, on, onCleanup, onError, onMount, runWithOwner, startTransition, untrack, useContext, useTransition } from "./reactive/signal.js"; | ||
export type { Accessor, AccessorArray, ChildrenReturn, Context, ContextProviderComponent, EffectFunction, EffectOptions, InitializedResource, InitializedResourceOptions, InitializedResourceReturn, MemoOptions, NoInfer, OnEffectFunction, OnOptions, Owner, ResolvedChildren, ResolvedJSXElement, Resource, ResourceActions, ResourceFetcher, ResourceFetcherInfo, ResourceOptions, ResourceReturn, ResourceSource, ReturnTypes, Setter, Signal, SignalOptions } from "./reactive/signal.js"; | ||
export { | ||
$DEVCOMP, | ||
$PROXY, | ||
$TRACK, | ||
batch, | ||
catchError, | ||
children, | ||
createComputed, | ||
createContext, | ||
createDeferred, | ||
createEffect, | ||
createMemo, | ||
createReaction, | ||
createRenderEffect, | ||
createResource, | ||
createRoot, | ||
createSelector, | ||
createSignal, | ||
enableExternalSource, | ||
enableScheduling, | ||
equalFn, | ||
getListener, | ||
getOwner, | ||
on, | ||
onCleanup, | ||
onError, | ||
onMount, | ||
runWithOwner, | ||
startTransition, | ||
untrack, | ||
useContext, | ||
useTransition | ||
} from "./reactive/signal.js"; | ||
export type { | ||
Accessor, | ||
AccessorArray, | ||
ChildrenReturn, | ||
Context, | ||
ContextProviderComponent, | ||
EffectFunction, | ||
EffectOptions, | ||
InitializedResource, | ||
InitializedResourceOptions, | ||
InitializedResourceReturn, | ||
MemoOptions, | ||
NoInfer, | ||
OnEffectFunction, | ||
OnOptions, | ||
Owner, | ||
ResolvedChildren, | ||
ResolvedJSXElement, | ||
Resource, | ||
ResourceActions, | ||
ResourceFetcher, | ||
ResourceFetcherInfo, | ||
ResourceOptions, | ||
ResourceReturn, | ||
ResourceSource, | ||
ReturnTypes, | ||
Setter, | ||
Signal, | ||
SignalOptions | ||
} from "./reactive/signal.js"; | ||
export * from "./reactive/observable.js"; | ||
@@ -11,13 +72,17 @@ 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; | ||
afterCreateSignal: ((signal: import("./reactive/signal.js").SignalState<any>) => void) | null; | ||
}; | ||
readonly writeSignal: typeof writeSignal; | ||
readonly registerGraph: typeof registerGraph; | ||
} | undefined; | ||
afterCreateSignal: | ||
| ((signal: import("./reactive/signal.js").SignalState<any>) => void) | ||
| null; | ||
}; | ||
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,54 +36,57 @@ /** | ||
export declare const DevHooks: { | ||
afterUpdate: (() => void) | null; | ||
afterCreateOwner: ((owner: Owner) => void) | null; | ||
afterCreateSignal: ((signal: SignalState<any>) => void) | null; | ||
afterUpdate: (() => void) | null; | ||
afterCreateOwner: ((owner: Owner) => void) | null; | ||
afterCreateSignal: ((signal: SignalState<any>) => 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; | ||
} | ||
@@ -103,10 +106,12 @@ export type RootFunction<T> = (dispose: () => void) => T; | ||
export type Setter<in out T> = { | ||
<U extends T>(value: Exclude<U, Function> | ((prev: T) => U)): U; | ||
<U extends T>(...args: undefined extends T ? [] : [value: Exclude<U, Function> | ((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>( | ||
...args: undefined extends T ? [] : [value: Exclude<U, Function> | ((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; | ||
} | ||
@@ -139,7 +144,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; | ||
@@ -161,4 +165,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; | ||
/** | ||
@@ -179,4 +189,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; | ||
/** | ||
@@ -197,6 +213,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; | ||
/** | ||
@@ -215,9 +237,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); | ||
} | ||
@@ -239,38 +264,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; | ||
} | ||
@@ -280,28 +311,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> | ||
]; | ||
@@ -336,10 +373,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; | ||
} | ||
@@ -359,3 +410,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; | ||
@@ -386,3 +440,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; | ||
/** | ||
@@ -405,11 +463,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; | ||
} | ||
@@ -442,8 +513,18 @@ /** | ||
*/ | ||
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 | { | ||
defer: true; | ||
}): EffectFunction<undefined | NoInfer<Next>>; | ||
} | ||
): 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>>; | ||
/** | ||
@@ -502,5 +583,5 @@ * Runs 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; | ||
} | ||
@@ -510,8 +591,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; | ||
} | ||
@@ -537,3 +618,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>; | ||
@@ -552,3 +636,3 @@ /** | ||
export type ChildrenReturn = Accessor<ResolvedChildren> & { | ||
toArray: () => ResolvedJSXElement[]; | ||
toArray: () => ResolvedJSXElement[]; | ||
}; | ||
@@ -565,18 +649,25 @@ /** | ||
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 | undefined> & { | ||
active?(): boolean; | ||
increment?(): void; | ||
decrement?(): void; | ||
active?(): boolean; | ||
increment?(): void; | ||
decrement?(): void; | ||
}; | ||
declare let SuspenseContext: SuspenseContext; | ||
export declare function getSuspenseContext(): SuspenseContext; | ||
export declare function enableExternalSource(factory: ExternalSourceFactory, untrack?: <V>(fn: () => V) => V): void; | ||
export declare function enableExternalSource( | ||
factory: ExternalSourceFactory, | ||
untrack?: <V>(fn: () => V) => V | ||
): void; | ||
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; | ||
/** | ||
@@ -583,0 +674,0 @@ * @deprecated since version 1.7.0 and will be removed in next major - use catchError instead |
@@ -14,3 +14,3 @@ import type { JSX } from "../jsx.js"; | ||
export type VoidProps<P extends Record<string, any> = {}> = P & { | ||
children?: never; | ||
children?: never; | ||
}; | ||
@@ -29,3 +29,3 @@ /** | ||
export type ParentProps<P extends Record<string, any> = {}> = P & { | ||
children?: JSX.Element; | ||
children?: JSX.Element; | ||
}; | ||
@@ -45,3 +45,3 @@ /** | ||
export type FlowProps<P extends Record<string, any> = {}, C = JSX.Element> = P & { | ||
children: C; | ||
children: C; | ||
}; | ||
@@ -54,3 +54,5 @@ /** | ||
*/ | ||
export type FlowComponent<P extends Record<string, any> = {}, C = JSX.Element> = Component<FlowProps<P, C>>; | ||
export type FlowComponent<P extends Record<string, any> = {}, C = JSX.Element> = Component< | ||
FlowProps<P, C> | ||
>; | ||
/** @deprecated: use `ParentProps` instead */ | ||
@@ -66,3 +68,7 @@ export type PropsWithChildren<P extends Record<string, any> = {}> = ParentProps<P>; | ||
*/ | ||
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>; | ||
/** | ||
@@ -74,44 +80,74 @@ * Type of `props.ref`, for use in `Component` or `props` typing. | ||
export type Ref<T> = T | ((val: T) => void); | ||
export declare function createComponent<T extends Record<string, any>>(Comp: Component<T>, props: T): JSX.Element; | ||
export declare function createComponent<T extends Record<string, any>>( | ||
Comp: Component<T>, | ||
props: T | ||
): JSX.Element; | ||
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; | ||
}, | ||
{ | ||
[P in keyof T as Exclude<P, K[number][number]>]: T[P]; | ||
} | ||
...{ | ||
[P in keyof K]: P extends `${number}` | ||
? Pick<T, Extract<K[P], readonly (keyof T)[]>[number]> | ||
: never; | ||
}, | ||
{ | ||
[P in keyof T as Exclude<P, K[number][number]>]: T[P]; | ||
} | ||
]; | ||
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.js"; | ||
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; | ||
has?: (id: string) => boolean; | ||
gather?: (key: string) => void; | ||
registry?: Map<string, Element>; | ||
done?: boolean; | ||
count?: number; | ||
effects?: Computation<any, any>[]; | ||
getContextId(): string; | ||
getNextContextId(): string; | ||
context?: HydrationContext; | ||
resources?: { | ||
[key: string]: any; | ||
}; | ||
load?: (id: string) => Promise<any> | any; | ||
has?: (id: string) => boolean; | ||
gather?: (key: string) => void; | ||
registry?: Map<string, Element>; | ||
done?: boolean; | ||
count?: number; | ||
effects?: Computation<any, any>[]; | ||
getContextId(): string; | ||
getNextContextId(): string; | ||
}; | ||
@@ -21,0 +21,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,58 @@ | ||
export { catchError, createRoot, createSignal, createComputed, createRenderEffect, createEffect, createReaction, createDeferred, createSelector, createMemo, getListener, onMount, onCleanup, onError, untrack, batch, on, children, createContext, useContext, getOwner, runWithOwner, equalFn, requestCallback, mapArray, indexArray, 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 { | ||
catchError, | ||
createRoot, | ||
createSignal, | ||
createComputed, | ||
createRenderEffect, | ||
createEffect, | ||
createReaction, | ||
createDeferred, | ||
createSelector, | ||
createMemo, | ||
getListener, | ||
onMount, | ||
onCleanup, | ||
onError, | ||
untrack, | ||
batch, | ||
on, | ||
children, | ||
createContext, | ||
useContext, | ||
getOwner, | ||
runWithOwner, | ||
equalFn, | ||
requestCallback, | ||
mapArray, | ||
indexArray, | ||
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; | ||
@@ -44,8 +59,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; | ||
} | ||
@@ -56,3 +68,3 @@ export declare function createContext<T>(defaultValue?: T): Context<T>; | ||
type ChildrenReturn = Accessor<any> & { | ||
toArray: () => any[]; | ||
toArray: () => any[]; | ||
}; | ||
@@ -62,33 +74,52 @@ 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: 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[]; | ||
export declare function indexArray<T, U>(list: Accessor<readonly T[] | undefined | null | false>, mapFn: (v: Accessor<T>, i: number) => U, options?: { | ||
} | ||
): () => U[]; | ||
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[]; | ||
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; | ||
@@ -95,0 +126,0 @@ /** |
@@ -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,7 +19,11 @@ 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; | ||
getContextId(): string; | ||
getNextContextId(): string; | ||
context?: HydrationContext; | ||
getContextId(): string; | ||
getNextContextId(): string; | ||
}; | ||
@@ -31,24 +35,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; | ||
@@ -60,15 +102,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); | ||
}; | ||
@@ -78,24 +120,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; | ||
}; | ||
@@ -106,30 +154,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; | ||
}>; | ||
}; | ||
@@ -141,26 +207,31 @@ export declare function enableScheduling(): void; | ||
type HydrationContext = { | ||
id: string; | ||
count: number; | ||
serialize: (id: string, v: Promise<any> | any, deferStream?: boolean) => void; | ||
nextRoot: (v: any) => string; | ||
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; | ||
serialize: (id: string, v: Promise<any> | any, deferStream?: boolean) => void; | ||
nextRoot: (v: any) => string; | ||
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,81 @@ | ||
import { createRoot, createRenderEffect, untrack, sharedConfig, 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, | ||
untrack, | ||
sharedConfig, | ||
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", "inert", "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", | ||
"inert", | ||
"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 +107,107 @@ 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", "feDropShadow", "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", | ||
"feDropShadow", | ||
"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 +217,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 +519,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); | ||
@@ -115,3 +561,5 @@ } else if (bEnd === bStart) { | ||
if (!element) { | ||
throw new Error("The `element` passed to `render(..., element)` doesn't exist. Make sure `element` exists in the document."); | ||
throw new Error( | ||
"The `element` passed to `render(..., element)` doesn't exist. Make sure `element` exists in the document." | ||
); | ||
} | ||
@@ -121,3 +569,5 @@ let disposer; | ||
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 +582,6 @@ return () => { | ||
const create = () => { | ||
if (isHydrating()) throw new Error("Failed attempt to create new DOM elements during hydration. Check that the libraries you are using support hydration."); | ||
if (isHydrating()) | ||
throw new Error( | ||
"Failed attempt to create new DOM elements during hydration. Check that the libraries you are using support hydration." | ||
); | ||
const t = document.createElement("template"); | ||
@@ -138,3 +591,5 @@ t.innerHTML = html; | ||
}; | ||
const fn = isImportNode ? () => untrack(() => document.importNode(node || (node = create()), true)) : () => (node || (node = create())).cloneNode(true); | ||
const fn = isImportNode | ||
? () => untrack(() => document.importNode(node || (node = create()), true)) | ||
: () => (node || (node = create())).cloneNode(true); | ||
fn.cloneNode = fn; | ||
@@ -165,7 +620,9 @@ return fn; | ||
if (isHydrating(node)) return; | ||
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 (isHydrating(node)) return; | ||
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); | ||
} | ||
@@ -178,3 +635,4 @@ function setBoolAttribute(node, name, value) { | ||
if (isHydrating(node)) return; | ||
if (value == null) node.removeAttribute("class");else node.className = value; | ||
if (value == null) node.removeAttribute("class"); | ||
else node.className = value; | ||
} | ||
@@ -189,3 +647,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, typeof handler !== "function" && handler); | ||
@@ -215,3 +673,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); | ||
@@ -237,3 +695,5 @@ prev || (prev = {}); | ||
if (!skipChildren) { | ||
createRenderEffect(() => prevProps.children = insertExpression(node, props.children, prevProps.children)); | ||
createRenderEffect( | ||
() => (prevProps.children = insertExpression(node, props.children, prevProps.children)) | ||
); | ||
} | ||
@@ -302,6 +762,10 @@ createRenderEffect(() => typeof props.ref === "function" && use(props.ref, node)); | ||
hydrating = isHydrating(); | ||
if (!hydrating || !(node = sharedConfig.registry.get(key = getHydrationKey()))) { | ||
if (!hydrating || !(node = sharedConfig.registry.get((key = getHydrationKey())))) { | ||
if (hydrating) { | ||
sharedConfig.done = true; | ||
throw new Error(`Hydration Mismatch. Unable to find DOM nodes for hydration key: ${key}\n${template ? template().outerHTML : ""}`); | ||
throw new Error( | ||
`Hydration Mismatch. Unable to find DOM nodes for hydration key: ${key}\n${ | ||
template ? template().outerHTML : "" | ||
}` | ||
); | ||
} | ||
@@ -326,3 +790,4 @@ return template(); | ||
const v = end.nodeValue; | ||
if (v === "$") count++;else if (v === "/") { | ||
if (v === "$") count++; | ||
else if (v === "/") { | ||
if (count === 0) return [end, current]; | ||
@@ -341,6 +806,3 @@ count--; | ||
queueMicrotask(() => { | ||
const { | ||
completed, | ||
events | ||
} = sharedConfig; | ||
const { completed, events } = sharedConfig; | ||
if (!events) return; | ||
@@ -370,3 +832,4 @@ events.queued = false; | ||
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); | ||
} | ||
@@ -403,3 +866,9 @@ function assignProp(node, prop, value, prev, isSVG, skipRef, props) { | ||
setBoolAttribute(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("-") || 'is' in props)) { | ||
} 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("-") || "is" in props) | ||
) { | ||
if (forceProp) { | ||
@@ -409,6 +878,9 @@ prop = prop.slice(5); | ||
} else if (isHydrating(node)) return value; | ||
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); | ||
} | ||
@@ -425,6 +897,7 @@ return value; | ||
const oriCurrentTarget = e.currentTarget; | ||
const retarget = value => Object.defineProperty(e, "target", { | ||
configurable: true, | ||
value | ||
}); | ||
const retarget = value => | ||
Object.defineProperty(e, "target", { | ||
configurable: true, | ||
value | ||
}); | ||
const handleNode = () => { | ||
@@ -437,3 +910,7 @@ const handler = node[key]; | ||
} | ||
node.host && typeof node.host !== "string" && !node.host._$host && node.contains(e.target) && retarget(node.host); | ||
node.host && | ||
typeof node.host !== "string" && | ||
!node.host._$host && | ||
node.contains(e.target) && | ||
retarget(node.host); | ||
return true; | ||
@@ -466,4 +943,3 @@ }; | ||
} | ||
} | ||
else walkUpTree(); | ||
} else walkUpTree(); | ||
retarget(oriTarget); | ||
@@ -478,3 +954,4 @@ } | ||
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); | ||
} | ||
@@ -487,3 +964,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") { | ||
@@ -520,3 +997,3 @@ if (hydrating) 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; | ||
@@ -526,3 +1003,3 @@ } | ||
if (!array.length) return current; | ||
if (marker === undefined) return current = [...parent.childNodes]; | ||
if (marker === undefined) return (current = [...parent.childNodes]); | ||
let node = array[0]; | ||
@@ -532,3 +1009,3 @@ if (node.parentNode !== parent) return current; | ||
while ((node = node.nextSibling) !== marker) nodes.push(node); | ||
return current = nodes; | ||
return (current = nodes); | ||
} | ||
@@ -548,5 +1025,5 @@ if (array.length === 0) { | ||
} else if (value.nodeType) { | ||
if (hydrating && value.parentNode) return current = multi ? [value] : value; | ||
if (hydrating && 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); | ||
@@ -566,3 +1043,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); | ||
@@ -574,3 +1052,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 { | ||
@@ -582,3 +1065,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)); | ||
} | ||
@@ -592,3 +1076,3 @@ } | ||
function cleanChildren(parent, current, marker, replacement) { | ||
if (marker === undefined) return parent.textContent = ""; | ||
if (marker === undefined) return (parent.textContent = ""); | ||
const node = replacement || document.createTextNode(""); | ||
@@ -601,3 +1085,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; | ||
@@ -613,3 +1099,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); | ||
} | ||
@@ -666,5 +1153,3 @@ } | ||
function Portal(props) { | ||
const { | ||
useShadow | ||
} = props, | ||
const { useShadow } = props, | ||
marker = document.createTextNode(""), | ||
@@ -675,30 +1160,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; | ||
@@ -726,2 +1218,60 @@ } | ||
export { Aliases, voidFn as Assets, ChildProperties, DOMElements, DelegatedEvents, Dynamic, Hydration, voidFn as HydrationScript, NoHydration, Portal, Properties, RequestContext, SVGElements, SVGNamespace, addEventListener, assign, classList, className, clearDelegatedEvents, delegateEvents, dynamicProperty, escape, voidFn as generateHydrationScript, voidFn as getAssets, getHydrationKey, getNextElement, getNextMarker, getNextMatch, getPropAlias, voidFn as getRequestEvent, hydrate, innerHTML, insert, isDev, isServer, render, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, runHydrationEvents, setAttribute, setAttributeNS, setBoolAttribute, setProperty, 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, | ||
RequestContext, | ||
SVGElements, | ||
SVGNamespace, | ||
addEventListener, | ||
assign, | ||
classList, | ||
className, | ||
clearDelegatedEvents, | ||
delegateEvents, | ||
dynamicProperty, | ||
escape, | ||
voidFn as generateHydrationScript, | ||
voidFn as getAssets, | ||
getHydrationKey, | ||
getNextElement, | ||
getNextMarker, | ||
getNextMatch, | ||
getPropAlias, | ||
voidFn as getRequestEvent, | ||
hydrate, | ||
innerHTML, | ||
insert, | ||
isDev, | ||
isServer, | ||
render, | ||
renderToStream, | ||
renderToString, | ||
renderToStringAsync, | ||
resolveSSRNode, | ||
runHydrationEvents, | ||
setAttribute, | ||
setAttributeNS, | ||
setBoolAttribute, | ||
setProperty, | ||
spread, | ||
ssr, | ||
ssrAttribute, | ||
ssrClassList, | ||
ssrElement, | ||
ssrHydrationKey, | ||
ssrSpread, | ||
ssrStyle, | ||
style, | ||
template, | ||
use, | ||
voidFn as useAssets | ||
}; |
@@ -1,15 +0,81 @@ | ||
import { sharedConfig, createRoot, splitProps } 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 { Feature, Serializer, getCrossReferenceHeader } from 'seroval'; | ||
import { CustomEventPlugin, DOMExceptionPlugin, EventPlugin, FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin } from 'seroval-plugins/web'; | ||
import { sharedConfig, createRoot, splitProps } 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 { Feature, Serializer, getCrossReferenceHeader } from "seroval"; | ||
import { | ||
CustomEventPlugin, | ||
DOMExceptionPlugin, | ||
EventPlugin, | ||
FormDataPlugin, | ||
HeadersPlugin, | ||
ReadableStreamPlugin, | ||
RequestPlugin, | ||
ResponsePlugin, | ||
URLSearchParamsPlugin, | ||
URLPlugin | ||
} from "seroval-plugins/web"; | ||
const booleans = ["allowfullscreen", "async", "autofocus", "autoplay", "checked", "controls", "default", "disabled", "formnovalidate", "hidden", "indeterminate", "inert", "ismap", "loop", "multiple", "muted", "nomodule", "novalidate", "open", "playsinline", "readonly", "required", "reversed", "seamless", "selected"]; | ||
const BooleanAttributes = /*#__PURE__*/new Set(booleans); | ||
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", | ||
"inert", | ||
"ismap", | ||
"loop", | ||
"multiple", | ||
"muted", | ||
"nomodule", | ||
"novalidate", | ||
"open", | ||
"playsinline", | ||
"readonly", | ||
"required", | ||
"reversed", | ||
"seamless", | ||
"selected" | ||
]; | ||
const BooleanAttributes = /*#__PURE__*/ new Set(booleans); | ||
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", | ||
@@ -41,10 +107,107 @@ 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", "feDropShadow", "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", | ||
"feDropShadow", | ||
"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 = { | ||
@@ -54,18 +217,301 @@ 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" | ||
]); | ||
const ES2017FLAG = Feature.AggregateError | ||
| Feature.BigIntTypedArray; | ||
const GLOBAL_IDENTIFIER = '_$HY.r'; | ||
function createSerializer({ | ||
onData, | ||
onDone, | ||
scopeId, | ||
onError | ||
}) { | ||
const ES2017FLAG = Feature.AggregateError | Feature.BigIntTypedArray; | ||
const GLOBAL_IDENTIFIER = "_$HY.r"; | ||
function createSerializer({ onData, onDone, scopeId, onError }) { | ||
return new Serializer({ | ||
scopeId, | ||
plugins: [ | ||
CustomEventPlugin, DOMExceptionPlugin, EventPlugin, | ||
FormDataPlugin, HeadersPlugin, ReadableStreamPlugin, RequestPlugin, ResponsePlugin, URLSearchParamsPlugin, URLPlugin], | ||
CustomEventPlugin, | ||
DOMExceptionPlugin, | ||
EventPlugin, | ||
FormDataPlugin, | ||
HeadersPlugin, | ||
ReadableStreamPlugin, | ||
RequestPlugin, | ||
ResponsePlugin, | ||
URLSearchParamsPlugin, | ||
URLPlugin | ||
], | ||
globalIdentifier: GLOBAL_IDENTIFIER, | ||
@@ -79,11 +525,10 @@ disabledFeatures: ES2017FLAG, | ||
function getLocalHeaderScript(id) { | ||
return getCrossReferenceHeader(id) + ';'; | ||
return getCrossReferenceHeader(id) + ";"; | ||
} | ||
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,o,t){if(n=document.getElementById(e),o=document.getElementById("pl-"+e)){for(;o&&8!==o.nodeType&&o.nodeValue!=="pl-"+e;)t=o.nextSibling,o.remove(),o=t;_$HY.done?o.remove():o.replaceWith(n.content)}n.remove(),_$HY.fe(e)}`; | ||
function renderToString(code, options = {}) { | ||
const { | ||
renderId | ||
} = options; | ||
const { renderId } = options; | ||
let scripts = ""; | ||
@@ -126,5 +571,3 @@ const serializer = createSerializer({ | ||
function renderToStringAsync(code, options = {}) { | ||
const { | ||
timeoutMs = 30000 | ||
} = options; | ||
const { timeoutMs = 30000 } = options; | ||
let timeoutHandle; | ||
@@ -140,9 +583,3 @@ const timeout = new Promise((_, reject) => { | ||
function renderToStream(code, options = {}) { | ||
let { | ||
nonce, | ||
onCompleteShell, | ||
onCompleteAll, | ||
renderId, | ||
noScripts | ||
} = options; | ||
let { nonce, onCompleteShell, onCompleteAll, renderId, noScripts } = options; | ||
let dispose; | ||
@@ -163,7 +600,8 @@ const blockingPromises = []; | ||
doShell(); | ||
onCompleteAll && onCompleteAll({ | ||
write(v) { | ||
!completed && buffer.write(v); | ||
} | ||
}); | ||
onCompleteAll && | ||
onCompleteAll({ | ||
write(v) { | ||
!completed && buffer.write(v); | ||
} | ||
}); | ||
writable && writable.end(); | ||
@@ -225,3 +663,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()) | ||
); | ||
}, | ||
@@ -232,7 +673,10 @@ serialize(id, p, wait) { | ||
blockingPromises.push(p); | ||
!serverOnly && p.then(d => { | ||
serializer.write(id, d); | ||
}).catch(e => { | ||
serializer.write(id, e); | ||
}); | ||
!serverOnly && | ||
p | ||
.then(d => { | ||
serializer.write(id, d); | ||
}) | ||
.catch(e => { | ||
serializer.write(id, e); | ||
}); | ||
} else if (!serverOnly) serializer.write(id, p); | ||
@@ -247,7 +691,11 @@ }, | ||
let resolve, reject; | ||
const p = new Promise((r, rej) => (resolve = r, reject = rej)); | ||
registry.set(key, err => queue(() => queue(() => { | ||
err ? reject(err) : resolve(true); | ||
queue(flushEnd); | ||
}))); | ||
const p = new Promise((r, rej) => ((resolve = r), (reject = rej))); | ||
registry.set(key, err => | ||
queue(() => | ||
queue(() => { | ||
err ? reject(err) : resolve(true); | ||
queue(flushEnd); | ||
}) | ||
) | ||
); | ||
serializer.write(key, p); | ||
@@ -265,3 +713,3 @@ } | ||
if (!firstFlushed) { | ||
queue(() => html = replacePlaceholder(html, key, value !== undefined ? value : "")); | ||
queue(() => (html = replacePlaceholder(html, key, value !== undefined ? value : ""))); | ||
resolve(error); | ||
@@ -292,7 +740,8 @@ } else { | ||
tasks = ""; | ||
onCompleteShell && onCompleteShell({ | ||
write(v) { | ||
!completed && buffer.write(v); | ||
} | ||
}); | ||
onCompleteShell && | ||
onCompleteShell({ | ||
write(v) { | ||
!completed && buffer.write(v); | ||
} | ||
}); | ||
shellCompleted = true; | ||
@@ -332,3 +781,3 @@ } | ||
let resolve; | ||
const p = new Promise(r => resolve = r); | ||
const p = new Promise(r => (resolve = r)); | ||
setTimeout(() => { | ||
@@ -363,9 +812,9 @@ doShell(); | ||
function HydrationScript(props) { | ||
const { | ||
nonce | ||
} = sharedConfig.context; | ||
return ssr(generateHydrationScript({ | ||
nonce, | ||
...props | ||
})); | ||
const { nonce } = sharedConfig.context; | ||
return ssr( | ||
generateHydrationScript({ | ||
nonce, | ||
...props | ||
}) | ||
); | ||
} | ||
@@ -415,3 +864,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); | ||
@@ -424,3 +874,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; | ||
@@ -434,8 +885,22 @@ } | ||
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; | ||
} else if (value == undefined || prop === "ref" || prop.slice(0, 2) === "on") { | ||
if (value) result += prop; | ||
else continue; | ||
} else if ( | ||
value == undefined || | ||
prop === "ref" || | ||
prop.slice(0, 2) === "on" || | ||
prop.slice(0, 5) === "prop:" | ||
) { | ||
continue; | ||
} else if (prop.slice(0, 5) === "bool:") { | ||
if (!value) continue; | ||
result += escape(prop.slice(5)); | ||
} else if (prop.slice(0, 5) === "attr:") { | ||
result += `${escape(prop.slice(5))}="${escape(value, true)}"`; | ||
} else { | ||
@@ -446,5 +911,6 @@ result += `${Aliases[prop] || escape(prop)}="${escape(value, true)}"`; | ||
} | ||
if (skipChildren) return { | ||
t: result + "/>" | ||
}; | ||
if (skipChildren) | ||
return { | ||
t: result + "/>" | ||
}; | ||
if (typeof children === "function") children = children(); | ||
@@ -456,3 +922,3 @@ return { | ||
function ssrAttribute(key, value, isBoolean) { | ||
return isBoolean ? value ? " " + key : "" : value != null ? ` ${key}="${value}"` : ""; | ||
return isBoolean ? (value ? " " + key : "") : value != null ? ` ${key}="${value}"` : ""; | ||
} | ||
@@ -501,8 +967,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; | ||
@@ -519,3 +986,3 @@ } | ||
if (!top && typeof prev !== "object" && typeof node[i] !== "object") mapped += `<!--!$-->`; | ||
mapped += resolveSSRNode(prev = node[i]); | ||
mapped += resolveSSRNode((prev = node[i])); | ||
} | ||
@@ -541,7 +1008,8 @@ return mapped; | ||
} | ||
function generateHydrationScript({ | ||
eventNames = ["click", "input"], | ||
nonce | ||
} = {}) { | ||
return `<script${nonce ? ` nonce="${nonce}"` : ""}>window._$HY||(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=>{if(!e.events)return;let s=t(o.composedPath&&o.composedPath()[0]||o.target);s&&!e.completed.has(s)&&e.events.push([s,o])}))))})(_$HY={events:[],completed:new WeakSet,r:{},fe(){}});</script><!--xs-->`; | ||
function generateHydrationScript({ eventNames = ["click", "input"], nonce } = {}) { | ||
return `<script${ | ||
nonce ? ` nonce="${nonce}"` : "" | ||
}>window._$HY||(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=>{if(!e.events)return;let s=t(o.composedPath&&o.composedPath()[0]||o.target);s&&!e.completed.has(s)&&e.events.push([s,o])}))))})(_$HY={events:[],completed:new WeakSet,r:{},fe(){}});</script><!--xs-->`; | ||
} | ||
@@ -562,3 +1030,3 @@ function Hydration(props) { | ||
function NoHydration(props) { | ||
sharedConfig.context.noHydrate = true; | ||
if (sharedConfig.context) sharedConfig.context.noHydrate = true; | ||
return props.children; | ||
@@ -606,3 +1074,9 @@ } | ||
function getRequestEvent() { | ||
return globalThis[RequestContext] ? globalThis[RequestContext].getStore() || sharedConfig.context && sharedConfig.context.event || console.log("RequestEvent is missing. This is most likely due to accessing `getRequestEvent` non-managed async scope in a partially polyfilled environment. Try moving it above all `await` calls.") : undefined; | ||
return globalThis[RequestContext] | ||
? globalThis[RequestContext].getStore() || | ||
(sharedConfig.context && sharedConfig.context.event) || | ||
console.log( | ||
"RequestEvent is missing. This is most likely due to accessing `getRequestEvent` non-managed async scope in a partially polyfilled environment. Try moving it above all `await` calls." | ||
) | ||
: undefined; | ||
} | ||
@@ -614,5 +1088,3 @@ function Assets(props) { | ||
if (options.onReady) { | ||
options.onCompleteShell = ({ | ||
write | ||
}) => { | ||
options.onCompleteShell = ({ write }) => { | ||
options.onReady({ | ||
@@ -631,5 +1103,3 @@ write, | ||
if (options.onReady) { | ||
options.onCompleteShell = ({ | ||
write | ||
}) => { | ||
options.onCompleteShell = ({ write }) => { | ||
options.onReady({ | ||
@@ -664,17 +1134,23 @@ 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 (prop !== "value" && Properties.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; | ||
} else if (prop.slice(0, 5) === "bool:") { | ||
if (!value) continue; | ||
result += escape(prop.slice(5)); | ||
} else if (prop.slice(0, 5) === "attr:") { | ||
result += `${escape(prop.slice(5))}="${escape(value, true)}"`; | ||
} else { | ||
if (prop.slice(0, 5) === "bool:") { | ||
if (!value) continue; | ||
prop = prop.slice(5); | ||
result += `${escape(prop)}`; | ||
} else { | ||
if (prop.slice(0, 5) === "attr:") prop = prop.slice(5); | ||
result += `${Aliases[prop] || escape(prop)}="${escape(value, true)}"`; | ||
} | ||
result += `${Aliases[prop] || escape(prop)}="${escape(value, true)}"`; | ||
} | ||
@@ -686,3 +1162,5 @@ if (i !== keys.length - 1) result += " "; | ||
function notSup() { | ||
throw new Error("Client-only API called on the server side. Run client-only code in onMount, or conditionally run client-only component with <Show>."); | ||
throw new Error( | ||
"Client-only API called on the server side. Run client-only code in onMount, or conditionally run client-only component with <Show>." | ||
); | ||
} | ||
@@ -697,3 +1175,4 @@ | ||
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); | ||
@@ -707,2 +1186,58 @@ } | ||
export { Aliases, Assets, ChildProperties, DOMElements, DelegatedEvents, Dynamic, Hydration, HydrationScript, NoHydration, Portal, Properties, RequestContext, SVGElements, SVGNamespace, notSup as addEventListener, notSup as assign, notSup as classList, notSup as className, notSup as delegateEvents, notSup as dynamicProperty, escape, generateHydrationScript, getAssets, getHydrationKey, notSup as getNextElement, notSup as getNextMarker, notSup as getNextMatch, getPropAlias, getRequestEvent, notSup as hydrate, notSup as insert, isDev, isServer, pipeToNodeWritable, pipeToWritable, notSup as render, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, notSup as runHydrationEvents, notSup as setAttribute, notSup as setAttributeNS, notSup as setProperty, notSup as spread, ssr, ssrAttribute, ssrClassList, ssrElement, ssrHydrationKey, ssrSpread, ssrStyle, notSup as style, notSup as template, useAssets }; | ||
export { | ||
Aliases, | ||
Assets, | ||
ChildProperties, | ||
DOMElements, | ||
DelegatedEvents, | ||
Dynamic, | ||
Hydration, | ||
HydrationScript, | ||
NoHydration, | ||
Portal, | ||
Properties, | ||
RequestContext, | ||
SVGElements, | ||
SVGNamespace, | ||
notSup as addEventListener, | ||
notSup as assign, | ||
notSup as classList, | ||
notSup as className, | ||
notSup as delegateEvents, | ||
notSup as dynamicProperty, | ||
escape, | ||
generateHydrationScript, | ||
getAssets, | ||
getHydrationKey, | ||
notSup as getNextElement, | ||
notSup as getNextMarker, | ||
notSup as getNextMatch, | ||
getPropAlias, | ||
getRequestEvent, | ||
notSup as hydrate, | ||
notSup as insert, | ||
isDev, | ||
isServer, | ||
pipeToNodeWritable, | ||
pipeToWritable, | ||
notSup as render, | ||
renderToStream, | ||
renderToString, | ||
renderToStringAsync, | ||
resolveSSRNode, | ||
notSup as runHydrationEvents, | ||
notSup as setAttribute, | ||
notSup as setAttributeNS, | ||
notSup as setProperty, | ||
notSup as spread, | ||
ssr, | ||
ssrAttribute, | ||
ssrClassList, | ||
ssrElement, | ||
ssrHydrationKey, | ||
ssrSpread, | ||
ssrStyle, | ||
notSup as style, | ||
notSup as template, | ||
useAssets | ||
}; |
@@ -1,12 +0,80 @@ | ||
import { createRoot, createRenderEffect, untrack, sharedConfig, enableHydration, getOwner, createEffect, runWithOwner, createMemo, createSignal, onCleanup, splitProps } 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, | ||
untrack, | ||
sharedConfig, | ||
enableHydration, | ||
getOwner, | ||
createEffect, | ||
runWithOwner, | ||
createMemo, | ||
createSignal, | ||
onCleanup, | ||
splitProps | ||
} 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", "inert", "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", | ||
"inert", | ||
"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,107 @@ 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", "feDropShadow", "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", | ||
"feDropShadow", | ||
"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 +216,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 +518,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 +562,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 +579,5 @@ return () => { | ||
}; | ||
const fn = isImportNode ? () => untrack(() => document.importNode(node || (node = create()), true)) : () => (node || (node = create())).cloneNode(true); | ||
const fn = isImportNode | ||
? () => untrack(() => document.importNode(node || (node = create()), true)) | ||
: () => (node || (node = create())).cloneNode(true); | ||
fn.cloneNode = fn; | ||
@@ -159,7 +608,9 @@ return fn; | ||
if (isHydrating(node)) return; | ||
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 (isHydrating(node)) return; | ||
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); | ||
} | ||
@@ -172,3 +623,4 @@ function setBoolAttribute(node, name, value) { | ||
if (isHydrating(node)) return; | ||
if (value == null) node.removeAttribute("class");else node.className = value; | ||
if (value == null) node.removeAttribute("class"); | ||
else node.className = value; | ||
} | ||
@@ -183,3 +635,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, typeof handler !== "function" && handler); | ||
@@ -209,3 +661,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); | ||
@@ -231,3 +683,5 @@ prev || (prev = {}); | ||
if (!skipChildren) { | ||
createRenderEffect(() => prevProps.children = insertExpression(node, props.children, prevProps.children)); | ||
createRenderEffect( | ||
() => (prevProps.children = insertExpression(node, props.children, prevProps.children)) | ||
); | ||
} | ||
@@ -296,3 +750,3 @@ createRenderEffect(() => typeof props.ref === "function" && use(props.ref, node)); | ||
hydrating = isHydrating(); | ||
if (!hydrating || !(node = sharedConfig.registry.get(key = getHydrationKey()))) { | ||
if (!hydrating || !(node = sharedConfig.registry.get((key = getHydrationKey())))) { | ||
return template(); | ||
@@ -316,3 +770,4 @@ } | ||
const v = end.nodeValue; | ||
if (v === "$") count++;else if (v === "/") { | ||
if (v === "$") count++; | ||
else if (v === "/") { | ||
if (count === 0) return [end, current]; | ||
@@ -331,6 +786,3 @@ count--; | ||
queueMicrotask(() => { | ||
const { | ||
completed, | ||
events | ||
} = sharedConfig; | ||
const { completed, events } = sharedConfig; | ||
if (!events) return; | ||
@@ -360,3 +812,4 @@ events.queued = false; | ||
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); | ||
} | ||
@@ -393,3 +846,9 @@ function assignProp(node, prop, value, prev, isSVG, skipRef, props) { | ||
setBoolAttribute(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("-") || 'is' in props)) { | ||
} 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("-") || "is" in props) | ||
) { | ||
if (forceProp) { | ||
@@ -399,6 +858,9 @@ prop = prop.slice(5); | ||
} else if (isHydrating(node)) return value; | ||
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); | ||
} | ||
@@ -415,6 +877,7 @@ return value; | ||
const oriCurrentTarget = e.currentTarget; | ||
const retarget = value => Object.defineProperty(e, "target", { | ||
configurable: true, | ||
value | ||
}); | ||
const retarget = value => | ||
Object.defineProperty(e, "target", { | ||
configurable: true, | ||
value | ||
}); | ||
const handleNode = () => { | ||
@@ -427,3 +890,7 @@ const handler = node[key]; | ||
} | ||
node.host && typeof node.host !== "string" && !node.host._$host && node.contains(e.target) && retarget(node.host); | ||
node.host && | ||
typeof node.host !== "string" && | ||
!node.host._$host && | ||
node.contains(e.target) && | ||
retarget(node.host); | ||
return true; | ||
@@ -456,4 +923,3 @@ }; | ||
} | ||
} | ||
else walkUpTree(); | ||
} else walkUpTree(); | ||
retarget(oriTarget); | ||
@@ -468,3 +934,4 @@ } | ||
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); | ||
} | ||
@@ -477,3 +944,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") { | ||
@@ -510,3 +977,3 @@ if (hydrating) 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; | ||
@@ -516,3 +983,3 @@ } | ||
if (!array.length) return current; | ||
if (marker === undefined) return current = [...parent.childNodes]; | ||
if (marker === undefined) return (current = [...parent.childNodes]); | ||
let node = array[0]; | ||
@@ -522,3 +989,3 @@ if (node.parentNode !== parent) return current; | ||
while ((node = node.nextSibling) !== marker) nodes.push(node); | ||
return current = nodes; | ||
return (current = nodes); | ||
} | ||
@@ -538,5 +1005,5 @@ if (array.length === 0) { | ||
} else if (value.nodeType) { | ||
if (hydrating && value.parentNode) return current = multi ? [value] : value; | ||
if (hydrating && 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); | ||
@@ -547,3 +1014,3 @@ } else if (current == null || current === "" || !parent.firstChild) { | ||
current = value; | ||
} else ; | ||
} else; | ||
return current; | ||
@@ -557,3 +1024,4 @@ } | ||
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); | ||
@@ -565,3 +1033,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 { | ||
@@ -573,3 +1046,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)); | ||
} | ||
@@ -583,3 +1057,3 @@ } | ||
function cleanChildren(parent, current, marker, replacement) { | ||
if (marker === undefined) return parent.textContent = ""; | ||
if (marker === undefined) return (parent.textContent = ""); | ||
const node = replacement || document.createTextNode(""); | ||
@@ -592,3 +1066,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; | ||
@@ -604,3 +1080,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); | ||
} | ||
@@ -657,5 +1134,3 @@ } | ||
function Portal(props) { | ||
const { | ||
useShadow | ||
} = props, | ||
const { useShadow } = props, | ||
marker = document.createTextNode(""), | ||
@@ -666,30 +1141,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; | ||
@@ -714,2 +1196,60 @@ } | ||
export { Aliases, voidFn as Assets, ChildProperties, DOMElements, DelegatedEvents, Dynamic, Hydration, voidFn as HydrationScript, NoHydration, Portal, Properties, RequestContext, SVGElements, SVGNamespace, addEventListener, assign, classList, className, clearDelegatedEvents, delegateEvents, dynamicProperty, escape, voidFn as generateHydrationScript, voidFn as getAssets, getHydrationKey, getNextElement, getNextMarker, getNextMatch, getPropAlias, voidFn as getRequestEvent, hydrate, innerHTML, insert, isDev, isServer, render, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, runHydrationEvents, setAttribute, setAttributeNS, setBoolAttribute, setProperty, 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, | ||
RequestContext, | ||
SVGElements, | ||
SVGNamespace, | ||
addEventListener, | ||
assign, | ||
classList, | ||
className, | ||
clearDelegatedEvents, | ||
delegateEvents, | ||
dynamicProperty, | ||
escape, | ||
voidFn as generateHydrationScript, | ||
voidFn as getAssets, | ||
getHydrationKey, | ||
getNextElement, | ||
getNextMarker, | ||
getNextMatch, | ||
getPropAlias, | ||
voidFn as getRequestEvent, | ||
hydrate, | ||
innerHTML, | ||
insert, | ||
isDev, | ||
isServer, | ||
render, | ||
renderToStream, | ||
renderToString, | ||
renderToStringAsync, | ||
resolveSSRNode, | ||
runHydrationEvents, | ||
setAttribute, | ||
setAttributeNS, | ||
setBoolAttribute, | ||
setProperty, | ||
spread, | ||
ssr, | ||
ssrAttribute, | ||
ssrClassList, | ||
ssrElement, | ||
ssrHydrationKey, | ||
ssrSpread, | ||
ssrStyle, | ||
style, | ||
template, | ||
use, | ||
voidFn as useAssets | ||
}; |
@@ -1,7 +0,7 @@ | ||
import { AsyncLocalStorage } from 'node:async_hooks'; | ||
import { isServer, RequestContext } from 'solid-js/web'; | ||
import { AsyncLocalStorage } from "node:async_hooks"; | ||
import { isServer, RequestContext } from "solid-js/web"; | ||
function provideRequestEvent(init, cb) { | ||
if (!isServer) throw new Error("Attempting to use server context in non-server build"); | ||
const ctx = globalThis[RequestContext] = globalThis[RequestContext] || new AsyncLocalStorage(); | ||
const ctx = (globalThis[RequestContext] = globalThis[RequestContext] || new AsyncLocalStorage()); | ||
return ctx.run(init, cb); | ||
@@ -8,0 +8,0 @@ } |
@@ -28,3 +28,3 @@ import { JSX } from "./jsx.js"; | ||
node: Element, | ||
accessor: (() => T) | T, | ||
accessor: T, | ||
isSVG?: Boolean, | ||
@@ -31,0 +31,0 @@ skipChildren?: Boolean |
@@ -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; |
@@ -132,3 +132,3 @@ import { JSX } from "./jsx.js"; | ||
node: Element, | ||
accessor: (() => T) | T, | ||
accessor: T, | ||
isSVG?: Boolean, | ||
@@ -135,0 +135,0 @@ skipChildren?: Boolean |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
887231
26829