Comparing version 1.8.5 to 1.8.6
852
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; | ||
} | ||
@@ -161,5 +163,6 @@ return m; | ||
afterUpdate: null, | ||
afterCreateOwner: null | ||
afterCreateOwner: null, | ||
afterCreateSignal: null | ||
}; | ||
const [transPending, setTransPending] = /*@__PURE__*/createSignal(false); | ||
const [transPending, setTransPending] = /*@__PURE__*/ createSignal(false); | ||
function createRoot(fn, detachedOwner) { | ||
@@ -170,16 +173,21 @@ const listener = Listener, | ||
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); | ||
@@ -203,9 +211,11 @@ Owner = root; | ||
}; | ||
if (!options.internal) { | ||
{ | ||
if (options.name) s.name = options.name; | ||
registerGraph(s); | ||
if (DevHooks.afterCreateSignal) DevHooks.afterCreateSignal(s); | ||
if (!options.internal) registerGraph(s); | ||
} | ||
const setter = value => { | ||
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); | ||
} | ||
@@ -217,12 +227,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); | ||
@@ -235,6 +247,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); | ||
@@ -250,3 +268,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; | ||
@@ -268,3 +286,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; | ||
@@ -283,3 +301,3 @@ fetcher = pSource; | ||
scheduled = false, | ||
resolved = ("initialValue" in options), | ||
resolved = "initialValue" in options, | ||
dynamic = typeof source === "function" && createMemo(source); | ||
@@ -296,3 +314,4 @@ const contexts = new Set(), | ||
let v; | ||
if (options.ssrLoadFrom === "initial") initP = options.initialValue;else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v; | ||
if (options.ssrLoadFrom === "initial") initP = options.initialValue; | ||
else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v; | ||
} | ||
@@ -303,5 +322,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; | ||
@@ -337,3 +359,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(); | ||
@@ -357,6 +380,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)) { | ||
@@ -368,7 +396,8 @@ loadEnd(pr, p, undefined, lookup); | ||
if ("value" in p) { | ||
if (p.status === "success") loadEnd(pr, p.value, undefined, lookup);else loadEnd(pr, undefined, undefined, lookup); | ||
if (p.status === "success") loadEnd(pr, p.value, undefined, lookup); | ||
else loadEnd(pr, undefined, undefined, lookup); | ||
return p; | ||
} | ||
scheduled = true; | ||
queueMicrotask(() => scheduled = false); | ||
queueMicrotask(() => (scheduled = false)); | ||
runUpdates(() => { | ||
@@ -378,3 +407,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) | ||
); | ||
} | ||
@@ -403,7 +435,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 | ||
} | ||
]; | ||
} | ||
@@ -413,11 +449,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; | ||
@@ -427,12 +478,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); | ||
@@ -443,3 +502,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(() => { | ||
@@ -450,3 +510,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 | ||
); | ||
}; | ||
@@ -490,3 +553,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; | ||
@@ -545,11 +611,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; | ||
@@ -570,8 +638,14 @@ } | ||
function devComponent(Comp, props) { | ||
const c = createComputation(() => untrack(() => { | ||
Object.assign(Comp, { | ||
[$DEVCOMP]: true | ||
}); | ||
return Comp(props); | ||
}), undefined, true, 0); | ||
const c = createComputation( | ||
() => | ||
untrack(() => { | ||
Object.assign(Comp, { | ||
[$DEVCOMP]: true | ||
}); | ||
return Comp(props); | ||
}), | ||
undefined, | ||
true, | ||
0 | ||
); | ||
c.props = props; | ||
@@ -587,3 +661,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; | ||
@@ -600,3 +675,5 @@ } | ||
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; | ||
} | ||
@@ -607,3 +684,3 @@ function children(fn) { | ||
name: "children" | ||
}) ; | ||
}); | ||
memo.toArray = () => { | ||
@@ -640,3 +717,4 @@ const c = memo(); | ||
if (this.sources && (runningTransition ? this.tState : this.state)) { | ||
if ((runningTransition ? this.tState : this.state) === STALE) updateComputation(this);else { | ||
if ((runningTransition ? this.tState : this.state) === STALE) updateComputation(this); | ||
else { | ||
const updates = Updates; | ||
@@ -669,7 +747,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); | ||
@@ -687,6 +766,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; | ||
} | ||
@@ -706,7 +787,8 @@ if (Updates.length > 10e5) { | ||
cleanNode(node); | ||
const owner = Owner, | ||
listener = Listener, | ||
time = ExecCount; | ||
Listener = Owner = node; | ||
runComputation(node, Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value, time); | ||
const time = ExecCount; | ||
runComputation( | ||
node, | ||
Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value, | ||
time | ||
); | ||
if (Transition && !Transition.running && Transition.sources.has(node)) { | ||
@@ -722,7 +804,8 @@ queueMicrotask(() => { | ||
} | ||
Listener = listener; | ||
Owner = owner; | ||
} | ||
function runComputation(node, value, time) { | ||
let nextValue; | ||
const owner = Owner, | ||
listener = Listener; | ||
Listener = Owner = node; | ||
try { | ||
@@ -744,2 +827,5 @@ nextValue = node.fn(value); | ||
return handleError(err); | ||
} finally { | ||
Listener = listener; | ||
Owner = owner; | ||
} | ||
@@ -774,7 +860,11 @@ if (!node.updatedAt || node.updatedAt <= time) { | ||
} | ||
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); | ||
} | ||
@@ -832,3 +922,4 @@ } | ||
if (!init) Updates = []; | ||
if (Effects) wait = true;else Effects = []; | ||
if (Effects) wait = true; | ||
else Effects = []; | ||
ExecCount++; | ||
@@ -847,3 +938,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; | ||
@@ -888,3 +980,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(); | ||
@@ -917,3 +1010,4 @@ } | ||
const e = queue[i]; | ||
if (!e.user) runTop(e);else queue[userLength++] = e; | ||
if (!e.user) runTop(e); | ||
else queue[userLength++] = e; | ||
} | ||
@@ -936,3 +1030,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) { | ||
@@ -943,3 +1038,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); | ||
@@ -954,4 +1050,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); | ||
@@ -993,3 +1091,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; | ||
@@ -1016,3 +1115,3 @@ } | ||
} catch (e) { | ||
handleError(e, owner && owner.owner || null); | ||
handleError(e, (owner && owner.owner) || null); | ||
} | ||
@@ -1024,8 +1123,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); | ||
} | ||
@@ -1047,9 +1148,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; | ||
@@ -1060,3 +1166,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 = { | ||
@@ -1090,3 +1198,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) { | ||
@@ -1122,3 +1231,3 @@ return { | ||
const unsub = producer.subscribe(v => set(() => v)); | ||
onCleanup(() => "unsubscribe" in unsub ? unsub.unsubscribe() : unsub()); | ||
onCleanup(() => ("unsubscribe" in unsub ? unsub.unsubscribe() : unsub())); | ||
} else { | ||
@@ -1175,4 +1284,3 @@ const clean = producer(set); | ||
} | ||
} | ||
else if (len === 0) { | ||
} else if (len === 0) { | ||
mapped = new Array(newLen); | ||
@@ -1188,4 +1296,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]; | ||
@@ -1224,3 +1340,3 @@ tempdisposers[newEnd] = disposers[end]; | ||
} | ||
mapped = mapped.slice(0, len = newLen); | ||
mapped = mapped.slice(0, (len = newLen)); | ||
items = newItems.slice(0); | ||
@@ -1235,3 +1351,3 @@ } | ||
name: "index" | ||
}) ; | ||
}); | ||
indexes[j] = set; | ||
@@ -1294,3 +1410,3 @@ return mapFn(newItems[j], s); | ||
items = newItems.slice(0); | ||
return mapped = mapped.slice(0, len); | ||
return (mapped = mapped.slice(0, len)); | ||
}); | ||
@@ -1301,3 +1417,3 @@ function mapper(disposer) { | ||
name: "value" | ||
}) ; | ||
}); | ||
signals[i] = set; | ||
@@ -1318,3 +1434,3 @@ return mapFn(s, i); | ||
setHydrateContext(nextHydrateContext()); | ||
const r = devComponent(Comp, props || {}) ; | ||
const r = devComponent(Comp, props || {}); | ||
setHydrateContext(c); | ||
@@ -1368,25 +1484,29 @@ return r; | ||
const s = sources[i]; | ||
proxy = proxy || !!s && $PROXY in s; | ||
sources[i] = typeof s === "function" ? (proxy = true, createMemo(s)) : s; | ||
proxy = proxy || (!!s && $PROXY in s); | ||
sources[i] = typeof s === "function" ? ((proxy = true), createMemo(s)) : s; | ||
} | ||
if (proxy) { | ||
return new Proxy({ | ||
get(property) { | ||
for (let i = sources.length - 1; i >= 0; i--) { | ||
const v = resolveSource(sources[i])[property]; | ||
if (v !== undefined) return v; | ||
return new Proxy( | ||
{ | ||
get(property) { | ||
for (let i = sources.length - 1; i >= 0; i--) { | ||
const v = resolveSource(sources[i])[property]; | ||
if (v !== undefined) return v; | ||
} | ||
}, | ||
has(property) { | ||
for (let i = sources.length - 1; i >= 0; i--) { | ||
if (property in resolveSource(sources[i])) return true; | ||
} | ||
return false; | ||
}, | ||
keys() { | ||
const keys = []; | ||
for (let i = 0; i < sources.length; i++) | ||
keys.push(...Object.keys(resolveSource(sources[i]))); | ||
return [...new Set(keys)]; | ||
} | ||
}, | ||
has(property) { | ||
for (let i = sources.length - 1; i >= 0; i--) { | ||
if (property in resolveSource(sources[i])) return true; | ||
} | ||
return false; | ||
}, | ||
keys() { | ||
const keys = []; | ||
for (let i = 0; i < sources.length; i++) keys.push(...Object.keys(resolveSource(sources[i]))); | ||
return [...new Set(keys)]; | ||
} | ||
}, propTraps); | ||
propTraps | ||
); | ||
} | ||
@@ -1410,3 +1530,3 @@ const target = {}; | ||
configurable: true, | ||
get: resolveSources.bind(sourcesMap[key] = [desc.get.bind(source)]) | ||
get: resolveSources.bind((sourcesMap[key] = [desc.get.bind(source)])) | ||
}); | ||
@@ -1435,25 +1555,33 @@ } else { | ||
const res = keys.map(k => { | ||
return new Proxy({ | ||
get(property) { | ||
return k.includes(property) ? props[property] : undefined; | ||
return new Proxy( | ||
{ | ||
get(property) { | ||
return k.includes(property) ? props[property] : undefined; | ||
}, | ||
has(property) { | ||
return k.includes(property) && property in props; | ||
}, | ||
keys() { | ||
return k.filter(property => property in props); | ||
} | ||
}, | ||
has(property) { | ||
return k.includes(property) && property in props; | ||
propTraps | ||
); | ||
}); | ||
res.push( | ||
new Proxy( | ||
{ | ||
get(property) { | ||
return blocked.has(property) ? undefined : props[property]; | ||
}, | ||
has(property) { | ||
return blocked.has(property) ? false : property in props; | ||
}, | ||
keys() { | ||
return Object.keys(props).filter(k => !blocked.has(k)); | ||
} | ||
}, | ||
keys() { | ||
return k.filter(property => property in props); | ||
} | ||
}, propTraps); | ||
}); | ||
res.push(new Proxy({ | ||
get(property) { | ||
return blocked.has(property) ? undefined : props[property]; | ||
}, | ||
has(property) { | ||
return blocked.has(property) ? false : property in props; | ||
}, | ||
keys() { | ||
return Object.keys(props).filter(k => !blocked.has(k)); | ||
} | ||
}, propTraps)); | ||
propTraps | ||
) | ||
); | ||
return res; | ||
@@ -1465,3 +1593,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; | ||
@@ -1472,3 +1601,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); | ||
} | ||
@@ -1478,3 +1609,5 @@ ++objectIndex; | ||
if (!blocked) { | ||
isDefaultDesc ? otherObject[propName] = desc.value : Object.defineProperty(otherObject, propName, desc); | ||
isDefaultDesc | ||
? (otherObject[propName] = desc.value) | ||
: Object.defineProperty(otherObject, propName, desc); | ||
} | ||
@@ -1505,15 +1638,20 @@ } | ||
let Comp; | ||
return createMemo(() => (Comp = comp()) && untrack(() => { | ||
if (true) Object.assign(Comp, { | ||
[$DEVCOMP]: true | ||
}); | ||
if (!ctx) return Comp(props); | ||
const c = sharedConfig.context; | ||
setHydrateContext(ctx); | ||
const r = Comp(props); | ||
setHydrateContext(c); | ||
return r; | ||
})); | ||
return createMemo( | ||
() => | ||
(Comp = comp()) && | ||
untrack(() => { | ||
if (true) | ||
Object.assign(Comp, { | ||
[$DEVCOMP]: true | ||
}); | ||
if (!ctx) return Comp(props); | ||
const c = sharedConfig.context; | ||
setHydrateContext(ctx); | ||
const r = Comp(props); | ||
setHydrateContext(c); | ||
return r; | ||
}) | ||
); | ||
}; | ||
wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p); | ||
wrap.preload = () => p || ((p = fn()).then(mod => (comp = () => mod.default)), p); | ||
return wrap; | ||
@@ -1527,3 +1665,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) { | ||
@@ -1533,5 +1672,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" | ||
} | ||
); | ||
} | ||
@@ -1542,5 +1685,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" | ||
} | ||
); | ||
} | ||
@@ -1550,51 +1697,80 @@ function Show(props) { | ||
const condition = createMemo(() => props.when, undefined, { | ||
equals: (a, b) => keyed ? a === b : !a === !b, | ||
equals: (a, b) => (keyed ? a === b : !a === !b), | ||
name: "condition" | ||
} ); | ||
return createMemo(() => { | ||
const c = condition(); | ||
if (c) { | ||
const child = props.children; | ||
const fn = typeof child === "function" && child.length > 0; | ||
return fn ? untrack(() => child(keyed ? c : () => { | ||
if (!untrack(condition)) throw narrowedError("Show"); | ||
return props.when; | ||
})) : child; | ||
}); | ||
return createMemo( | ||
() => { | ||
const c = condition(); | ||
if (c) { | ||
const child = props.children; | ||
const fn = typeof child === "function" && child.length > 0; | ||
return fn | ||
? untrack(() => | ||
child( | ||
keyed | ||
? c | ||
: () => { | ||
if (!untrack(condition)) throw narrowedError("Show"); | ||
return props.when; | ||
} | ||
) | ||
) | ||
: child; | ||
} | ||
return props.fallback; | ||
}, | ||
undefined, | ||
{ | ||
name: "value" | ||
} | ||
return props.fallback; | ||
}, undefined, { | ||
name: "value" | ||
} ); | ||
); | ||
} | ||
function Switch(props) { | ||
let keyed = false; | ||
const equals = (a, b) => a[0] === b[0] && (keyed ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]; | ||
const equals = (a, b) => | ||
a[0] === b[0] && (keyed ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]; | ||
const conditions = children(() => props.children), | ||
evalConditions = createMemo(() => { | ||
let conds = conditions(); | ||
if (!Array.isArray(conds)) conds = [conds]; | ||
for (let i = 0; i < conds.length; i++) { | ||
const c = conds[i].when; | ||
if (c) { | ||
keyed = !!conds[i].keyed; | ||
return [i, c, conds[i]]; | ||
evalConditions = createMemo( | ||
() => { | ||
let conds = conditions(); | ||
if (!Array.isArray(conds)) conds = [conds]; | ||
for (let i = 0; i < conds.length; i++) { | ||
const c = conds[i].when; | ||
if (c) { | ||
keyed = !!conds[i].keyed; | ||
return [i, c, conds[i]]; | ||
} | ||
} | ||
return [-1]; | ||
}, | ||
undefined, | ||
{ | ||
equals, | ||
name: "eval conditions" | ||
} | ||
return [-1]; | ||
}, undefined, { | ||
equals, | ||
name: "eval conditions" | ||
} ); | ||
return createMemo(() => { | ||
const [index, when, cond] = evalConditions(); | ||
if (index < 0) return props.fallback; | ||
const c = cond.children; | ||
const fn = typeof c === "function" && c.length > 0; | ||
return fn ? untrack(() => c(keyed ? when : () => { | ||
if (untrack(evalConditions)[0] !== index) throw narrowedError("Match"); | ||
return cond.when; | ||
})) : c; | ||
}, undefined, { | ||
name: "value" | ||
} ); | ||
); | ||
return createMemo( | ||
() => { | ||
const [index, when, cond] = evalConditions(); | ||
if (index < 0) return props.fallback; | ||
const c = cond.children; | ||
const fn = typeof c === "function" && c.length > 0; | ||
return fn | ||
? untrack(() => | ||
c( | ||
keyed | ||
? when | ||
: () => { | ||
if (untrack(evalConditions)[0] !== index) throw narrowedError("Match"); | ||
return cond.when; | ||
} | ||
) | ||
) | ||
: c; | ||
}, | ||
undefined, | ||
{ | ||
name: "value" | ||
} | ||
); | ||
} | ||
@@ -1610,23 +1786,29 @@ function Match(props) { | ||
let err; | ||
if (sharedConfig.context && sharedConfig.load) err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count); | ||
if (sharedConfig.context && sharedConfig.load) | ||
err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count); | ||
const [errored, setErrored] = createSignal(err, { | ||
name: "errored" | ||
} ); | ||
}); | ||
Errors || (Errors = new Set()); | ||
Errors.add(setErrored); | ||
onCleanup(() => Errors.delete(setErrored)); | ||
return createMemo(() => { | ||
let e; | ||
if (e = errored()) { | ||
const f = props.fallback; | ||
if ((typeof f !== "function" || f.length == 0)) console.error(e); | ||
return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored())) : f; | ||
return createMemo( | ||
() => { | ||
let e; | ||
if ((e = errored())) { | ||
const f = props.fallback; | ||
if (typeof f !== "function" || f.length == 0) console.error(e); | ||
return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored())) : f; | ||
} | ||
return catchError(() => props.children, setErrored); | ||
}, | ||
undefined, | ||
{ | ||
name: "value" | ||
} | ||
return catchError(() => props.children, setErrored); | ||
}, undefined, { | ||
name: "value" | ||
} ); | ||
); | ||
} | ||
const suspenseListEquals = (a, b) => a.showContent === b.showContent && a.showFallback === b.showFallback; | ||
const suspenseListEquals = (a, b) => | ||
a.showContent === b.showContent && a.showFallback === b.showFallback; | ||
const SuspenseListContext = createContext(); | ||
@@ -1643,47 +1825,47 @@ function SuspenseList(props) { | ||
} | ||
const resolved = createMemo(prev => { | ||
const reveal = props.revealOrder, | ||
tail = props.tail, | ||
{ | ||
showContent = true, | ||
showFallback = true | ||
} = show ? show() : {}, | ||
reg = registry(), | ||
reverse = reveal === "backwards"; | ||
if (reveal === "together") { | ||
const all = reg.every(inFallback => !inFallback()); | ||
const res = reg.map(() => ({ | ||
showContent: all && showContent, | ||
showFallback | ||
})); | ||
res.inFallback = !all; | ||
return res; | ||
} | ||
let stop = false; | ||
let inFallback = prev.inFallback; | ||
const res = []; | ||
for (let i = 0, len = reg.length; i < len; i++) { | ||
const n = reverse ? len - i - 1 : i, | ||
s = reg[n](); | ||
if (!stop && !s) { | ||
res[n] = { | ||
showContent, | ||
const resolved = createMemo( | ||
prev => { | ||
const reveal = props.revealOrder, | ||
tail = props.tail, | ||
{ showContent = true, showFallback = true } = show ? show() : {}, | ||
reg = registry(), | ||
reverse = reveal === "backwards"; | ||
if (reveal === "together") { | ||
const all = reg.every(inFallback => !inFallback()); | ||
const res = reg.map(() => ({ | ||
showContent: all && showContent, | ||
showFallback | ||
}; | ||
} else { | ||
const next = !stop; | ||
if (next) inFallback = true; | ||
res[n] = { | ||
showContent: next, | ||
showFallback: !tail || next && tail === "collapsed" ? showFallback : false | ||
}; | ||
stop = true; | ||
})); | ||
res.inFallback = !all; | ||
return res; | ||
} | ||
let stop = false; | ||
let inFallback = prev.inFallback; | ||
const res = []; | ||
for (let i = 0, len = reg.length; i < len; i++) { | ||
const n = reverse ? len - i - 1 : i, | ||
s = reg[n](); | ||
if (!stop && !s) { | ||
res[n] = { | ||
showContent, | ||
showFallback | ||
}; | ||
} else { | ||
const next = !stop; | ||
if (next) inFallback = true; | ||
res[n] = { | ||
showContent: next, | ||
showFallback: !tail || (next && tail === "collapsed") ? showFallback : false | ||
}; | ||
stop = true; | ||
} | ||
} | ||
if (!stop) inFallback = false; | ||
res.inFallback = inFallback; | ||
return res; | ||
}, | ||
{ | ||
inFallback: false | ||
} | ||
if (!stop) inFallback = false; | ||
res.inFallback = inFallback; | ||
return res; | ||
}, { | ||
inFallback: false | ||
}); | ||
); | ||
setWrapper(() => resolved); | ||
@@ -1763,3 +1945,3 @@ return createComponent(SuspenseListContext.Provider, { | ||
flicker(); | ||
return flicker = undefined; | ||
return (flicker = undefined); | ||
} | ||
@@ -1770,7 +1952,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; | ||
@@ -1805,7 +1984,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 { | ||
@@ -329,7 +340,9 @@ const clean = producer(set); | ||
function nextHydrateContext() { | ||
return sharedConfig.context ? { | ||
...sharedConfig.context, | ||
id: `${sharedConfig.context.id}${sharedConfig.context.count++}-`, | ||
count: 0 | ||
} : undefined; | ||
return sharedConfig.context | ||
? { | ||
...sharedConfig.context, | ||
id: `${sharedConfig.context.id}${sharedConfig.context.count++}-`, | ||
count: 0 | ||
} | ||
: undefined; | ||
} | ||
@@ -411,3 +424,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 || ""; | ||
} | ||
@@ -449,7 +466,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; | ||
} | ||
); | ||
}); | ||
@@ -484,3 +504,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; | ||
@@ -492,3 +513,6 @@ } | ||
if (resourceContext && p) resourceContext.push(p); | ||
const resolved = options.ssrLoadFrom !== "initial" && sharedConfig.context.async && "data" in sharedConfig.context.resources[id]; | ||
const resolved = | ||
options.ssrLoadFrom !== "initial" && | ||
sharedConfig.context.async && | ||
"data" in sharedConfig.context.resources[id]; | ||
if (!resolved && read.loading) { | ||
@@ -513,3 +537,3 @@ const ctx = useContext(SuspenseContext); | ||
const ctx = sharedConfig.context; | ||
if (!ctx.async) return read.loading = !!(typeof source === "function" ? source() : source); | ||
if (!ctx.async) return (read.loading = !!(typeof source === "function" ? source() : source)); | ||
if (ctx.resources && id in ctx.resources && "data" in ctx.resources[id]) { | ||
@@ -522,5 +546,7 @@ value = ctx.resources[id].data; | ||
if (resourceContext.length) { | ||
p = Promise.all(resourceContext).then(() => fetcher(source(), { | ||
value | ||
})); | ||
p = Promise.all(resourceContext).then(() => | ||
fetcher(source(), { | ||
value | ||
}) | ||
); | ||
} | ||
@@ -537,17 +563,19 @@ resourceContext = null; | ||
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); | ||
@@ -562,6 +590,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) | ||
} | ||
]); | ||
} | ||
@@ -573,3 +604,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; | ||
@@ -583,3 +614,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); | ||
@@ -596,6 +628,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); | ||
}) | ||
); | ||
} | ||
@@ -628,5 +662,8 @@ return ""; | ||
function useTransition() { | ||
return [() => false, fn => { | ||
fn(); | ||
}]; | ||
return [ | ||
() => false, | ||
fn => { | ||
fn(); | ||
} | ||
]; | ||
} | ||
@@ -641,11 +678,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) { | ||
@@ -664,8 +703,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); | ||
} | ||
}) | ||
); | ||
} | ||
@@ -702,2 +743,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; | ||
} | ||
@@ -159,3 +161,3 @@ return m; | ||
let ExecCount = 0; | ||
const [transPending, setTransPending] = /*@__PURE__*/createSignal(false); | ||
const [transPending, setTransPending] = /*@__PURE__*/ createSignal(false); | ||
function createRoot(fn, detachedOwner) { | ||
@@ -166,8 +168,10 @@ const listener = Listener, | ||
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))); | ||
@@ -193,3 +197,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); | ||
} | ||
@@ -202,7 +207,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); | ||
} | ||
@@ -219,6 +226,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); | ||
@@ -251,3 +263,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; | ||
@@ -266,3 +278,3 @@ fetcher = pSource; | ||
scheduled = false, | ||
resolved = ("initialValue" in options), | ||
resolved = "initialValue" in options, | ||
dynamic = typeof source === "function" && createMemo(source); | ||
@@ -279,3 +291,4 @@ const contexts = new Set(), | ||
let v; | ||
if (options.ssrLoadFrom === "initial") initP = options.initialValue;else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v; | ||
if (options.ssrLoadFrom === "initial") initP = options.initialValue; | ||
else if (sharedConfig.load && (v = sharedConfig.load(id))) initP = v; | ||
} | ||
@@ -286,5 +299,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; | ||
@@ -320,3 +336,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(); | ||
@@ -340,6 +357,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)) { | ||
@@ -351,7 +373,8 @@ loadEnd(pr, p, undefined, lookup); | ||
if ("value" in p) { | ||
if (p.status === "success") loadEnd(pr, p.value, undefined, lookup);else loadEnd(pr, undefined, undefined, lookup); | ||
if (p.status === "success") loadEnd(pr, p.value, undefined, lookup); | ||
else loadEnd(pr, undefined, undefined, lookup); | ||
return p; | ||
} | ||
scheduled = true; | ||
queueMicrotask(() => scheduled = false); | ||
queueMicrotask(() => (scheduled = false)); | ||
runUpdates(() => { | ||
@@ -361,3 +384,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) | ||
); | ||
} | ||
@@ -386,7 +412,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 | ||
} | ||
]; | ||
} | ||
@@ -396,11 +426,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; | ||
@@ -410,12 +455,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); | ||
@@ -426,3 +478,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(() => { | ||
@@ -433,3 +486,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 | ||
); | ||
}; | ||
@@ -473,3 +529,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; | ||
@@ -528,11 +586,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; | ||
@@ -561,3 +621,5 @@ } | ||
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; | ||
} | ||
@@ -598,3 +660,4 @@ function children(fn) { | ||
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; | ||
@@ -627,7 +690,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); | ||
@@ -645,10 +709,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(); | ||
@@ -664,7 +730,8 @@ } | ||
cleanNode(node); | ||
const owner = Owner, | ||
listener = Listener, | ||
time = ExecCount; | ||
Listener = Owner = node; | ||
runComputation(node, Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value, time); | ||
const time = ExecCount; | ||
runComputation( | ||
node, | ||
Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value, | ||
time | ||
); | ||
if (Transition && !Transition.running && Transition.sources.has(node)) { | ||
@@ -680,7 +747,8 @@ queueMicrotask(() => { | ||
} | ||
Listener = listener; | ||
Owner = owner; | ||
} | ||
function runComputation(node, value, time) { | ||
let nextValue; | ||
const owner = Owner, | ||
listener = Listener; | ||
Listener = Owner = node; | ||
try { | ||
@@ -702,2 +770,5 @@ nextValue = node.fn(value); | ||
return handleError(err); | ||
} finally { | ||
Listener = listener; | ||
Owner = owner; | ||
} | ||
@@ -732,7 +803,10 @@ if (!node.updatedAt || node.updatedAt <= time) { | ||
} | ||
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); | ||
} | ||
@@ -788,3 +862,4 @@ } | ||
if (!init) Updates = []; | ||
if (Effects) wait = true;else Effects = []; | ||
if (Effects) wait = true; | ||
else Effects = []; | ||
ExecCount++; | ||
@@ -803,3 +878,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; | ||
@@ -872,3 +948,4 @@ } | ||
const e = queue[i]; | ||
if (!e.user) runTop(e);else queue[userLength++] = e; | ||
if (!e.user) runTop(e); | ||
else queue[userLength++] = e; | ||
} | ||
@@ -891,3 +968,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) { | ||
@@ -898,3 +976,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); | ||
@@ -909,4 +988,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); | ||
@@ -948,3 +1029,4 @@ } | ||
} | ||
if (Transition && Transition.running) node.tState = 0;else node.state = 0; | ||
if (Transition && Transition.running) node.tState = 0; | ||
else node.state = 0; | ||
} | ||
@@ -970,3 +1052,3 @@ function reset(node, top) { | ||
} catch (e) { | ||
handleError(e, owner && owner.owner || null); | ||
handleError(e, (owner && owner.owner) || null); | ||
} | ||
@@ -978,8 +1060,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); | ||
} | ||
@@ -1001,9 +1085,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; | ||
@@ -1014,3 +1102,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 = { | ||
@@ -1044,3 +1133,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) { | ||
@@ -1076,3 +1166,3 @@ return { | ||
const unsub = producer.subscribe(v => set(() => v)); | ||
onCleanup(() => "unsubscribe" in unsub ? unsub.unsubscribe() : unsub()); | ||
onCleanup(() => ("unsubscribe" in unsub ? unsub.unsubscribe() : unsub())); | ||
} else { | ||
@@ -1129,4 +1219,3 @@ const clean = producer(set); | ||
} | ||
} | ||
else if (len === 0) { | ||
} else if (len === 0) { | ||
mapped = new Array(newLen); | ||
@@ -1142,4 +1231,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]; | ||
@@ -1178,3 +1275,3 @@ tempdisposers[newEnd] = disposers[end]; | ||
} | ||
mapped = mapped.slice(0, len = newLen); | ||
mapped = mapped.slice(0, (len = newLen)); | ||
items = newItems.slice(0); | ||
@@ -1245,3 +1342,3 @@ } | ||
items = newItems.slice(0); | ||
return mapped = mapped.slice(0, len); | ||
return (mapped = mapped.slice(0, len)); | ||
}); | ||
@@ -1315,25 +1412,29 @@ function mapper(disposer) { | ||
const s = sources[i]; | ||
proxy = proxy || !!s && $PROXY in s; | ||
sources[i] = typeof s === "function" ? (proxy = true, createMemo(s)) : s; | ||
proxy = proxy || (!!s && $PROXY in s); | ||
sources[i] = typeof s === "function" ? ((proxy = true), createMemo(s)) : s; | ||
} | ||
if (proxy) { | ||
return new Proxy({ | ||
get(property) { | ||
for (let i = sources.length - 1; i >= 0; i--) { | ||
const v = resolveSource(sources[i])[property]; | ||
if (v !== undefined) return v; | ||
return new Proxy( | ||
{ | ||
get(property) { | ||
for (let i = sources.length - 1; i >= 0; i--) { | ||
const v = resolveSource(sources[i])[property]; | ||
if (v !== undefined) return v; | ||
} | ||
}, | ||
has(property) { | ||
for (let i = sources.length - 1; i >= 0; i--) { | ||
if (property in resolveSource(sources[i])) return true; | ||
} | ||
return false; | ||
}, | ||
keys() { | ||
const keys = []; | ||
for (let i = 0; i < sources.length; i++) | ||
keys.push(...Object.keys(resolveSource(sources[i]))); | ||
return [...new Set(keys)]; | ||
} | ||
}, | ||
has(property) { | ||
for (let i = sources.length - 1; i >= 0; i--) { | ||
if (property in resolveSource(sources[i])) return true; | ||
} | ||
return false; | ||
}, | ||
keys() { | ||
const keys = []; | ||
for (let i = 0; i < sources.length; i++) keys.push(...Object.keys(resolveSource(sources[i]))); | ||
return [...new Set(keys)]; | ||
} | ||
}, propTraps); | ||
propTraps | ||
); | ||
} | ||
@@ -1357,3 +1458,3 @@ const target = {}; | ||
configurable: true, | ||
get: resolveSources.bind(sourcesMap[key] = [desc.get.bind(source)]) | ||
get: resolveSources.bind((sourcesMap[key] = [desc.get.bind(source)])) | ||
}); | ||
@@ -1382,25 +1483,33 @@ } else { | ||
const res = keys.map(k => { | ||
return new Proxy({ | ||
get(property) { | ||
return k.includes(property) ? props[property] : undefined; | ||
return new Proxy( | ||
{ | ||
get(property) { | ||
return k.includes(property) ? props[property] : undefined; | ||
}, | ||
has(property) { | ||
return k.includes(property) && property in props; | ||
}, | ||
keys() { | ||
return k.filter(property => property in props); | ||
} | ||
}, | ||
has(property) { | ||
return k.includes(property) && property in props; | ||
propTraps | ||
); | ||
}); | ||
res.push( | ||
new Proxy( | ||
{ | ||
get(property) { | ||
return blocked.has(property) ? undefined : props[property]; | ||
}, | ||
has(property) { | ||
return blocked.has(property) ? false : property in props; | ||
}, | ||
keys() { | ||
return Object.keys(props).filter(k => !blocked.has(k)); | ||
} | ||
}, | ||
keys() { | ||
return k.filter(property => property in props); | ||
} | ||
}, propTraps); | ||
}); | ||
res.push(new Proxy({ | ||
get(property) { | ||
return blocked.has(property) ? undefined : props[property]; | ||
}, | ||
has(property) { | ||
return blocked.has(property) ? false : property in props; | ||
}, | ||
keys() { | ||
return Object.keys(props).filter(k => !blocked.has(k)); | ||
} | ||
}, propTraps)); | ||
propTraps | ||
) | ||
); | ||
return res; | ||
@@ -1412,3 +1521,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; | ||
@@ -1419,3 +1529,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); | ||
} | ||
@@ -1425,3 +1537,5 @@ ++objectIndex; | ||
if (!blocked) { | ||
isDefaultDesc ? otherObject[propName] = desc.value : Object.defineProperty(otherObject, propName, desc); | ||
isDefaultDesc | ||
? (otherObject[propName] = desc.value) | ||
: Object.defineProperty(otherObject, propName, desc); | ||
} | ||
@@ -1452,13 +1566,17 @@ } | ||
let Comp; | ||
return createMemo(() => (Comp = comp()) && untrack(() => { | ||
if (false) ; | ||
if (!ctx) return Comp(props); | ||
const c = sharedConfig.context; | ||
setHydrateContext(ctx); | ||
const r = Comp(props); | ||
setHydrateContext(c); | ||
return r; | ||
})); | ||
return createMemo( | ||
() => | ||
(Comp = comp()) && | ||
untrack(() => { | ||
if (false); | ||
if (!ctx) return Comp(props); | ||
const c = sharedConfig.context; | ||
setHydrateContext(ctx); | ||
const r = Comp(props); | ||
setHydrateContext(c); | ||
return r; | ||
}) | ||
); | ||
}; | ||
wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p); | ||
wrap.preload = () => p || ((p = fn()).then(mod => (comp = () => mod.default)), p); | ||
return wrap; | ||
@@ -1488,45 +1606,74 @@ } | ||
const condition = createMemo(() => props.when, undefined, { | ||
equals: (a, b) => keyed ? a === b : !a === !b | ||
equals: (a, b) => (keyed ? a === b : !a === !b) | ||
}); | ||
return createMemo(() => { | ||
const c = condition(); | ||
if (c) { | ||
const child = props.children; | ||
const fn = typeof child === "function" && child.length > 0; | ||
return fn ? untrack(() => child(keyed ? c : () => { | ||
if (!untrack(condition)) throw narrowedError("Show"); | ||
return props.when; | ||
})) : child; | ||
} | ||
return props.fallback; | ||
}, undefined, undefined); | ||
return createMemo( | ||
() => { | ||
const c = condition(); | ||
if (c) { | ||
const child = props.children; | ||
const fn = typeof child === "function" && child.length > 0; | ||
return fn | ||
? untrack(() => | ||
child( | ||
keyed | ||
? c | ||
: () => { | ||
if (!untrack(condition)) throw narrowedError("Show"); | ||
return props.when; | ||
} | ||
) | ||
) | ||
: child; | ||
} | ||
return props.fallback; | ||
}, | ||
undefined, | ||
undefined | ||
); | ||
} | ||
function Switch(props) { | ||
let keyed = false; | ||
const equals = (a, b) => a[0] === b[0] && (keyed ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]; | ||
const equals = (a, b) => | ||
a[0] === b[0] && (keyed ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]; | ||
const conditions = children(() => props.children), | ||
evalConditions = createMemo(() => { | ||
let conds = conditions(); | ||
if (!Array.isArray(conds)) conds = [conds]; | ||
for (let i = 0; i < conds.length; i++) { | ||
const c = conds[i].when; | ||
if (c) { | ||
keyed = !!conds[i].keyed; | ||
return [i, c, conds[i]]; | ||
evalConditions = createMemo( | ||
() => { | ||
let conds = conditions(); | ||
if (!Array.isArray(conds)) conds = [conds]; | ||
for (let i = 0; i < conds.length; i++) { | ||
const c = conds[i].when; | ||
if (c) { | ||
keyed = !!conds[i].keyed; | ||
return [i, c, conds[i]]; | ||
} | ||
} | ||
return [-1]; | ||
}, | ||
undefined, | ||
{ | ||
equals | ||
} | ||
return [-1]; | ||
}, undefined, { | ||
equals | ||
}); | ||
return createMemo(() => { | ||
const [index, when, cond] = evalConditions(); | ||
if (index < 0) return props.fallback; | ||
const c = cond.children; | ||
const fn = typeof c === "function" && c.length > 0; | ||
return fn ? untrack(() => c(keyed ? when : () => { | ||
if (untrack(evalConditions)[0] !== index) throw narrowedError("Match"); | ||
return cond.when; | ||
})) : c; | ||
}, undefined, undefined); | ||
); | ||
return createMemo( | ||
() => { | ||
const [index, when, cond] = evalConditions(); | ||
if (index < 0) return props.fallback; | ||
const c = cond.children; | ||
const fn = typeof c === "function" && c.length > 0; | ||
return fn | ||
? untrack(() => | ||
c( | ||
keyed | ||
? when | ||
: () => { | ||
if (untrack(evalConditions)[0] !== index) throw narrowedError("Match"); | ||
return cond.when; | ||
} | ||
) | ||
) | ||
: c; | ||
}, | ||
undefined, | ||
undefined | ||
); | ||
} | ||
@@ -1542,3 +1689,4 @@ function Match(props) { | ||
let err; | ||
if (sharedConfig.context && sharedConfig.load) err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count); | ||
if (sharedConfig.context && sharedConfig.load) | ||
err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count); | ||
const [errored, setErrored] = createSignal(err, undefined); | ||
@@ -1548,13 +1696,18 @@ Errors || (Errors = new Set()); | ||
onCleanup(() => Errors.delete(setErrored)); | ||
return createMemo(() => { | ||
let e; | ||
if (e = errored()) { | ||
const f = props.fallback; | ||
return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored())) : f; | ||
} | ||
return catchError(() => props.children, setErrored); | ||
}, undefined, undefined); | ||
return createMemo( | ||
() => { | ||
let e; | ||
if ((e = errored())) { | ||
const f = props.fallback; | ||
return typeof f === "function" && f.length ? untrack(() => f(e, () => setErrored())) : f; | ||
} | ||
return catchError(() => props.children, setErrored); | ||
}, | ||
undefined, | ||
undefined | ||
); | ||
} | ||
const suspenseListEquals = (a, b) => a.showContent === b.showContent && a.showFallback === b.showFallback; | ||
const suspenseListEquals = (a, b) => | ||
a.showContent === b.showContent && a.showFallback === b.showFallback; | ||
const SuspenseListContext = createContext(); | ||
@@ -1571,47 +1724,47 @@ function SuspenseList(props) { | ||
} | ||
const resolved = createMemo(prev => { | ||
const reveal = props.revealOrder, | ||
tail = props.tail, | ||
{ | ||
showContent = true, | ||
showFallback = true | ||
} = show ? show() : {}, | ||
reg = registry(), | ||
reverse = reveal === "backwards"; | ||
if (reveal === "together") { | ||
const all = reg.every(inFallback => !inFallback()); | ||
const res = reg.map(() => ({ | ||
showContent: all && showContent, | ||
showFallback | ||
})); | ||
res.inFallback = !all; | ||
return res; | ||
} | ||
let stop = false; | ||
let inFallback = prev.inFallback; | ||
const res = []; | ||
for (let i = 0, len = reg.length; i < len; i++) { | ||
const n = reverse ? len - i - 1 : i, | ||
s = reg[n](); | ||
if (!stop && !s) { | ||
res[n] = { | ||
showContent, | ||
const resolved = createMemo( | ||
prev => { | ||
const reveal = props.revealOrder, | ||
tail = props.tail, | ||
{ showContent = true, showFallback = true } = show ? show() : {}, | ||
reg = registry(), | ||
reverse = reveal === "backwards"; | ||
if (reveal === "together") { | ||
const all = reg.every(inFallback => !inFallback()); | ||
const res = reg.map(() => ({ | ||
showContent: all && showContent, | ||
showFallback | ||
}; | ||
} else { | ||
const next = !stop; | ||
if (next) inFallback = true; | ||
res[n] = { | ||
showContent: next, | ||
showFallback: !tail || next && tail === "collapsed" ? showFallback : false | ||
}; | ||
stop = true; | ||
})); | ||
res.inFallback = !all; | ||
return res; | ||
} | ||
let stop = false; | ||
let inFallback = prev.inFallback; | ||
const res = []; | ||
for (let i = 0, len = reg.length; i < len; i++) { | ||
const n = reverse ? len - i - 1 : i, | ||
s = reg[n](); | ||
if (!stop && !s) { | ||
res[n] = { | ||
showContent, | ||
showFallback | ||
}; | ||
} else { | ||
const next = !stop; | ||
if (next) inFallback = true; | ||
res[n] = { | ||
showContent: next, | ||
showFallback: !tail || (next && tail === "collapsed") ? showFallback : false | ||
}; | ||
stop = true; | ||
} | ||
} | ||
if (!stop) inFallback = false; | ||
res.inFallback = inFallback; | ||
return res; | ||
}, | ||
{ | ||
inFallback: false | ||
} | ||
if (!stop) inFallback = false; | ||
res.inFallback = inFallback; | ||
return res; | ||
}, { | ||
inFallback: false | ||
}); | ||
); | ||
setWrapper(() => resolved); | ||
@@ -1691,3 +1844,3 @@ return createComponent(SuspenseListContext.Provider, { | ||
flicker(); | ||
return flicker = undefined; | ||
return (flicker = undefined); | ||
} | ||
@@ -1698,7 +1851,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; | ||
@@ -1731,2 +1881,57 @@ dispose && dispose(); | ||
export { $DEVCOMP, $PROXY, $TRACK, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, batch, cancelCallback, catchError, children, createComponent, createComputed, createContext, createDeferred, createEffect, createMemo, createReaction, createRenderEffect, createResource, createRoot, createSelector, createSignal, createUniqueId, enableExternalSource, enableHydration, enableScheduling, equalFn, from, getListener, getOwner, indexArray, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, requestCallback, resetErrorBoundaries, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition }; | ||
export { | ||
$DEVCOMP, | ||
$PROXY, | ||
$TRACK, | ||
DEV, | ||
ErrorBoundary, | ||
For, | ||
Index, | ||
Match, | ||
Show, | ||
Suspense, | ||
SuspenseList, | ||
Switch, | ||
batch, | ||
cancelCallback, | ||
catchError, | ||
children, | ||
createComponent, | ||
createComputed, | ||
createContext, | ||
createDeferred, | ||
createEffect, | ||
createMemo, | ||
createReaction, | ||
createRenderEffect, | ||
createResource, | ||
createRoot, | ||
createSelector, | ||
createSignal, | ||
createUniqueId, | ||
enableExternalSource, | ||
enableHydration, | ||
enableScheduling, | ||
equalFn, | ||
from, | ||
getListener, | ||
getOwner, | ||
indexArray, | ||
lazy, | ||
mapArray, | ||
mergeProps, | ||
observable, | ||
on, | ||
onCleanup, | ||
onError, | ||
onMount, | ||
requestCallback, | ||
resetErrorBoundaries, | ||
runWithOwner, | ||
sharedConfig, | ||
splitProps, | ||
startTransition, | ||
untrack, | ||
useContext, | ||
useTransition | ||
}; |
@@ -1,2 +0,9 @@ | ||
import { spread, assign, insert, createComponent, dynamicProperty, SVGElements } from 'solid-js/web'; | ||
import { | ||
spread, | ||
assign, | ||
insert, | ||
createComponent, | ||
dynamicProperty, | ||
SVGElements | ||
} from "solid-js/web"; | ||
@@ -20,5 +27,12 @@ const $ELEMENT = Symbol("hyper-element"); | ||
const type = typeof l; | ||
if (l == null) ;else if ("string" === type) { | ||
if (!e) parseClass(l);else e.appendChild(document.createTextNode(l)); | ||
} else if ("number" === type || "boolean" === type || l instanceof Date || l instanceof RegExp) { | ||
if (l == null); | ||
else if ("string" === type) { | ||
if (!e) parseClass(l); | ||
else e.appendChild(document.createTextNode(l)); | ||
} else if ( | ||
"number" === type || | ||
"boolean" === type || | ||
l instanceof Date || | ||
l instanceof RegExp | ||
) { | ||
e.appendChild(document.createTextNode(l.toString())); | ||
@@ -38,3 +52,5 @@ } else if (Array.isArray(l)) { | ||
} | ||
dynamic ? r.spread(e, l, e instanceof SVGElement, !!args.length) : r.assign(e, l, e instanceof SVGElement, !!args.length); | ||
dynamic | ||
? r.spread(e, l, e instanceof SVGElement, !!args.length) | ||
: r.assign(e, l, e instanceof SVGElement, !!args.length); | ||
} else if ("function" === type) { | ||
@@ -44,3 +60,7 @@ if (!e) { | ||
next = args[0]; | ||
if (next == null || typeof next === "object" && !Array.isArray(next) && !(next instanceof Element)) props = args.shift(); | ||
if ( | ||
next == null || | ||
(typeof next === "object" && !Array.isArray(next) && !(next instanceof Element)) | ||
) | ||
props = args.shift(); | ||
props || (props = {}); | ||
@@ -61,3 +81,4 @@ if (args.length) { | ||
r.dynamicProperty(props, k); | ||
} else if (typeof d[k].value === "function" && !d[k].value.length) r.dynamicProperty(props, k); | ||
} else if (typeof d[k].value === "function" && !d[k].value.length) | ||
r.dynamicProperty(props, k); | ||
} | ||
@@ -79,3 +100,8 @@ e = r.createComponent(l, props); | ||
if (!v) continue; | ||
if (!e) e = r.SVGElements.has(v) ? document.createElementNS("http://www.w3.org/2000/svg", v) : document.createElement(v);else if (v[0] === ".") e.classList.add(s);else if (v[0] === "#") e.setAttribute("id", s); | ||
if (!e) | ||
e = r.SVGElements.has(v) | ||
? document.createElementNS("http://www.w3.org/2000/svg", v) | ||
: document.createElement(v); | ||
else if (v[0] === ".") e.classList.add(s); | ||
else if (v[0] === "#") e.setAttribute("id", s); | ||
} | ||
@@ -82,0 +108,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"; | ||
import type { JSX } from "./jsx"; | ||
declare function Fragment(props: { | ||
children: JSX.Element; | ||
}): JSX.Element; | ||
declare function jsx(type: any, props: any): () => (Node & { | ||
[key: string]: any; | ||
}) | (Node & { | ||
[key: string]: any; | ||
})[]; | ||
declare function Fragment(props: { children: JSX.Element }): JSX.Element; | ||
declare function jsx( | ||
type: any, | ||
props: any | ||
): () => | ||
| (Node & { | ||
[key: string]: any; | ||
}) | ||
| (Node & { | ||
[key: string]: any; | ||
})[]; | ||
export { jsx, jsx as jsxs, jsx as jsxDEV, Fragment }; |
type MountableElement = Element | Document | ShadowRoot | DocumentFragment | Node; | ||
interface Runtime { | ||
insert(parent: MountableElement, accessor: any, marker?: Node | null, init?: any): any; | ||
spread(node: Element, accessor: any, isSVG?: Boolean, skipChildren?: Boolean): void; | ||
assign(node: Element, props: any, isSVG?: Boolean, skipChildren?: Boolean): void; | ||
createComponent(Comp: (props: any) => any, props: any): any; | ||
dynamicProperty(props: any, key: string): any; | ||
SVGElements: Set<string>; | ||
insert(parent: MountableElement, accessor: any, marker?: Node | null, init?: any): any; | ||
spread(node: Element, accessor: any, isSVG?: Boolean, skipChildren?: Boolean): void; | ||
assign(node: Element, props: any, isSVG?: Boolean, skipChildren?: Boolean): void; | ||
createComponent(Comp: (props: any) => any, props: any): any; | ||
dynamicProperty(props: any, key: string): any; | ||
SVGElements: Set<string>; | ||
} | ||
type ExpandableNode = Node & { | ||
[key: string]: any; | ||
[key: string]: any; | ||
}; | ||
export type HyperScript = { | ||
(...args: any[]): () => ExpandableNode | ExpandableNode[]; | ||
Fragment: (props: { | ||
children: (() => ExpandableNode) | (() => ExpandableNode)[]; | ||
}) => ExpandableNode[]; | ||
(...args: any[]): () => ExpandableNode | ExpandableNode[]; | ||
Fragment: (props: { | ||
children: (() => ExpandableNode) | (() => ExpandableNode)[]; | ||
}) => ExpandableNode[]; | ||
}; | ||
export declare function createHyperScript(r: Runtime): HyperScript; | ||
export {}; |
@@ -1,5 +0,27 @@ | ||
import { effect, style, insert, untrack, spread, createComponent, delegateEvents, classList, mergeProps, dynamicProperty, setAttribute, setAttributeNS, addEventListener, Aliases, getPropAlias, Properties, ChildProperties, DelegatedEvents, SVGElements, SVGNamespace } from 'solid-js/web'; | ||
import { | ||
effect, | ||
style, | ||
insert, | ||
untrack, | ||
spread, | ||
createComponent, | ||
delegateEvents, | ||
classList, | ||
mergeProps, | ||
dynamicProperty, | ||
setAttribute, | ||
setAttributeNS, | ||
addEventListener, | ||
Aliases, | ||
getPropAlias, | ||
Properties, | ||
ChildProperties, | ||
DelegatedEvents, | ||
SVGElements, | ||
SVGNamespace | ||
} from "solid-js/web"; | ||
const tagRE = /(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g; | ||
const attrRE = /(?:\s(?<boolean>[^/\s><=]+?)(?=[\s/>]))|(?:(?<name>\S+?)(?:\s*=\s*(?:(['"])(?<quotedValue>[\s\S]*?)\3|(?<unquotedValue>[^\s>]+))))/g; | ||
const attrRE = | ||
/(?:\s(?<boolean>[^/\s><=]+?)(?=[\s/>]))|(?:(?<name>\S+?)(?:\s*=\s*(?:(['"])(?<quotedValue>[\s\S]*?)\3|(?<unquotedValue>[^\s>]+))))/g; | ||
const lookup = { | ||
@@ -23,6 +45,6 @@ area: true, | ||
}; | ||
function parseTag( tag) { | ||
function parseTag(tag) { | ||
const res = { | ||
type: 'tag', | ||
name: '', | ||
type: "tag", | ||
name: "", | ||
voidElement: false, | ||
@@ -35,10 +57,10 @@ attrs: [], | ||
res.name = tagMatch[1]; | ||
if (lookup[tagMatch[1].toLowerCase()] || tag.charAt(tag.length - 2) === '/') { | ||
if (lookup[tagMatch[1].toLowerCase()] || tag.charAt(tag.length - 2) === "/") { | ||
res.voidElement = true; | ||
} | ||
if (res.name.startsWith('!--')) { | ||
const endIndex = tag.indexOf('-->'); | ||
if (res.name.startsWith("!--")) { | ||
const endIndex = tag.indexOf("-->"); | ||
return { | ||
type: 'comment', | ||
comment: endIndex !== -1 ? tag.slice(4, endIndex) : '' | ||
type: "comment", | ||
comment: endIndex !== -1 ? tag.slice(4, endIndex) : "" | ||
}; | ||
@@ -49,13 +71,13 @@ } | ||
for (const match of tag.matchAll(reg)) { | ||
if ((match[1] || match[2]).startsWith('use:')) { | ||
if ((match[1] || match[2]).startsWith("use:")) { | ||
res.attrs.push({ | ||
type: 'directive', | ||
type: "directive", | ||
name: match[1] || match[2], | ||
value: match[4] || match[5] || '' | ||
value: match[4] || match[5] || "" | ||
}); | ||
} else { | ||
res.attrs.push({ | ||
type: 'attr', | ||
type: "attr", | ||
name: match[1] || match[2], | ||
value: match[4] || match[5] || '' | ||
value: match[4] || match[5] || "" | ||
}); | ||
@@ -67,7 +89,7 @@ } | ||
function pushTextNode(list, html, start) { | ||
const end = html.indexOf('<', start); | ||
const end = html.indexOf("<", start); | ||
const content = html.slice(start, end === -1 ? void 0 : end); | ||
if (!/^\s*$/.test(content)) { | ||
list.push({ | ||
type: 'text', | ||
type: "text", | ||
content: content | ||
@@ -78,6 +100,6 @@ }); | ||
function pushCommentNode(list, tag) { | ||
const content = tag.replace('<!--', '').replace('-->', ''); | ||
const content = tag.replace("<!--", "").replace("-->", ""); | ||
if (!/^\s*$/.test(content)) { | ||
list.push({ | ||
type: 'comment', | ||
type: "comment", | ||
content: content | ||
@@ -94,4 +116,4 @@ }); | ||
html.replace(tagRE, (tag, index) => { | ||
const isOpen = tag.charAt(1) !== '/'; | ||
const isComment = tag.slice(0, 4) === '<!--'; | ||
const isOpen = tag.charAt(1) !== "/"; | ||
const isComment = tag.slice(0, 4) === "<!--"; | ||
const start = index + tag.length; | ||
@@ -103,3 +125,3 @@ const nextChar = html.charAt(start); | ||
current = parseTag(tag); | ||
if (!current.voidElement && nextChar && nextChar !== '<') { | ||
if (!current.voidElement && nextChar && nextChar !== "<") { | ||
pushTextNode(current.children, html, start); | ||
@@ -128,3 +150,3 @@ } | ||
} | ||
if (nextChar !== '<' && nextChar) { | ||
if (nextChar !== "<" && nextChar) { | ||
parent = level === -1 ? result : arr[level].children; | ||
@@ -140,21 +162,22 @@ pushTextNode(parent, html, start); | ||
for (const attr of attrs) { | ||
buff.push(attr.name + '="' + attr.value.replace(/"/g, '"') + '"'); | ||
buff.push(attr.name + '="' + attr.value.replace(/"/g, """) + '"'); | ||
} | ||
if (!buff.length) { | ||
return ''; | ||
return ""; | ||
} | ||
return ' ' + buff.join(' '); | ||
return " " + buff.join(" "); | ||
} | ||
function stringifier(buff, doc) { | ||
switch (doc.type) { | ||
case 'text': | ||
case "text": | ||
return buff + doc.content; | ||
case 'tag': | ||
buff += '<' + doc.name + (doc.attrs ? attrString(doc.attrs) : '') + (doc.voidElement ? '/>' : '>'); | ||
case "tag": | ||
buff += | ||
"<" + doc.name + (doc.attrs ? attrString(doc.attrs) : "") + (doc.voidElement ? "/>" : ">"); | ||
if (doc.voidElement) { | ||
return buff; | ||
} | ||
return buff + doc.children.reduce(stringifier, '') + '</' + doc.name + '>'; | ||
case 'comment': | ||
return buff += '<!--' + doc.content + '-->'; | ||
return buff + doc.children.reduce(stringifier, "") + "</" + doc.name + ">"; | ||
case "comment": | ||
return (buff += "<!--" + doc.content + "-->"); | ||
} | ||
@@ -164,14 +187,19 @@ } | ||
return doc.reduce(function (token, rootEl) { | ||
return token + stringifier('', rootEl); | ||
}, ''); | ||
return token + stringifier("", rootEl); | ||
}, ""); | ||
} | ||
const cache = new Map(); | ||
const VOID_ELEMENTS = /^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i; | ||
const VOID_ELEMENTS = | ||
/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i; | ||
const spaces = " \\f\\n\\r\\t"; | ||
const almostEverything = "[^" + spaces + "\\/>\"'=]+"; | ||
const attrName = "[ " + spaces + "]+(?:use:<!--#-->|" + almostEverything + ')'; | ||
const attrName = "[ " + spaces + "]+(?:use:<!--#-->|" + almostEverything + ")"; | ||
const tagName = "<([A-Za-z$#]+[A-Za-z0-9:_-]*)((?:"; | ||
const attrPartials = "(?:\\s*=\\s*(?:'[^']*?'|\"[^\"]*?\"|\\([^)]*?\\)|<[^>]*?>|" + almostEverything + "))?)"; | ||
const attrPartials = | ||
"(?:\\s*=\\s*(?:'[^']*?'|\"[^\"]*?\"|\\([^)]*?\\)|<[^>]*?>|" + almostEverything + "))?)"; | ||
const attrSeeker = new RegExp(tagName + attrName + attrPartials + "+)([ " + spaces + "]*/?>)", "g"); | ||
const findAttributes = new RegExp("(" + attrName + "\\s*=\\s*)(<!--#-->|['\"(]([\\w\\s]*<!--#-->[\\w\\s]*)*['\")])", "gi"); | ||
const findAttributes = new RegExp( | ||
"(" + attrName + "\\s*=\\s*)(<!--#-->|['\"(]([\\w\\s]*<!--#-->[\\w\\s]*)*['\")])", | ||
"gi" | ||
); | ||
const selfClosing = new RegExp(tagName + attrName + attrPartials + "*)([ " + spaces + "]*/>)", "g"); | ||
@@ -184,3 +212,6 @@ const marker = "<!--#-->"; | ||
function replaceAttributes($0, $1, $2) { | ||
return $1.replace(/<!--#-->/g, "###") + ($2[0] === '"' || $2[0] === "'" ? $2.replace(/<!--#-->/g, "###") : '"###"'); | ||
return ( | ||
$1.replace(/<!--#-->/g, "###") + | ||
($2[0] === '"' || $2[0] === "'" ? $2.replace(/<!--#-->/g, "###") : '"###"') | ||
); | ||
} | ||
@@ -194,5 +225,7 @@ function fullClosing($0, $1, $2) { | ||
function parseDirective(name, value, tag, options) { | ||
if (name === 'use:###' && value === '###') { | ||
if (name === "use:###" && value === "###") { | ||
const count = options.counter++; | ||
options.exprs.push(`typeof exprs[${count}] === "function" ? r.use(exprs[${count}], ${tag}, exprs[${options.counter++}]) : (()=>{throw new Error("use:### must be a function")})()`); | ||
options.exprs.push( | ||
`typeof exprs[${count}] === "function" ? r.use(exprs[${count}], ${tag}, exprs[${options.counter++}]) : (()=>{throw new Error("use:### must be a function")})()` | ||
); | ||
} else { | ||
@@ -202,6 +235,6 @@ throw new Error(`Not support syntax ${name} must be use:{function}`); | ||
} | ||
function createHTML(r, { | ||
delegateEvents = true, | ||
functionBuilder = (...args) => new Function(...args) | ||
} = {}) { | ||
function createHTML( | ||
r, | ||
{ delegateEvents = true, functionBuilder = (...args) => new Function(...args) } = {} | ||
) { | ||
let uuid = 1; | ||
@@ -222,3 +255,12 @@ r.wrapProps = props => { | ||
markup = markup + statics[i]; | ||
const replaceList = [[selfClosing, fullClosing], [/<(<!--#-->)/g, "<###"], [/\.\.\.(<!--#-->)/g, "###"], [attrSeeker, attrReplacer], [/>\n+\s*/g, ">"], [/\n+\s*</g, "<"], [/\s+</g, " <"], [/>\s+/g, "> "]]; | ||
const replaceList = [ | ||
[selfClosing, fullClosing], | ||
[/<(<!--#-->)/g, "<###"], | ||
[/\.\.\.(<!--#-->)/g, "###"], | ||
[attrSeeker, attrReplacer], | ||
[/>\n+\s*/g, ">"], | ||
[/\n+\s*</g, "<"], | ||
[/\s+</g, " <"], | ||
[/>\s+/g, "> "] | ||
]; | ||
markup = replaceList.reduce((acc, x) => { | ||
@@ -251,3 +293,15 @@ return acc.replace(x[0], x[1]); | ||
function parseKeyValue(node, tag, name, value, isSVG, isCE, options) { | ||
let expr = value === "###" ? `!doNotWrap ? exprs[${options.counter}]() : exprs[${options.counter++}]` : value.split("###").map((v, i) => i ? ` + (typeof exprs[${options.counter}] === "function" ? exprs[${options.counter}]() : exprs[${options.counter++}]) + "${v}"` : `"${v}"`).join(""), | ||
let expr = | ||
value === "###" | ||
? `!doNotWrap ? exprs[${options.counter}]() : exprs[${options.counter++}]` | ||
: value | ||
.split("###") | ||
.map((v, i) => | ||
i | ||
? ` + (typeof exprs[${options.counter}] === "function" ? exprs[${ | ||
options.counter | ||
}]() : exprs[${options.counter++}]) + "${v}"` | ||
: `"${v}"` | ||
) | ||
.join(""), | ||
parts, | ||
@@ -269,8 +323,17 @@ namespace; | ||
options.exprs.push(`r.classList(${tag},${expr},${prev})`); | ||
} else if (namespace !== "attr" && (isChildProp || !isSVG && (r.getPropAlias(name, node.name.toUpperCase()) || isProp) || isCE || namespace === "prop")) { | ||
} else if ( | ||
namespace !== "attr" && | ||
(isChildProp || | ||
(!isSVG && (r.getPropAlias(name, node.name.toUpperCase()) || isProp)) || | ||
isCE || | ||
namespace === "prop") | ||
) { | ||
if (isCE && !isChildProp && !isProp && namespace !== "prop") name = toPropertyName(name); | ||
options.exprs.push(`${tag}.${r.getPropAlias(name, node.name.toUpperCase()) || name} = ${expr}`); | ||
options.exprs.push( | ||
`${tag}.${r.getPropAlias(name, node.name.toUpperCase()) || name} = ${expr}` | ||
); | ||
} else { | ||
const ns = isSVG && name.indexOf(":") > -1 && r.SVGNamespace[name.split(":")[0]]; | ||
if (ns) options.exprs.push(`r.setAttributeNS(${tag},"${ns}","${name}",${expr})`);else options.exprs.push(`r.setAttribute(${tag},"${r.Aliases[name] || name}",${expr})`); | ||
if (ns) options.exprs.push(`r.setAttributeNS(${tag},"${ns}","${name}",${expr})`); | ||
else options.exprs.push(`r.setAttribute(${tag},"${r.Aliases[name] || name}",${expr})`); | ||
} | ||
@@ -283,7 +346,13 @@ } | ||
const delegate = delegateEvents && r.DelegatedEvents.has(lc); | ||
options.exprs.push(`r.addEventListener(${tag},"${lc}",exprs[${options.counter++}],${delegate})`); | ||
options.exprs.push( | ||
`r.addEventListener(${tag},"${lc}",exprs[${options.counter++}],${delegate})` | ||
); | ||
delegate && options.delegatedEvents.add(lc); | ||
} else { | ||
let capture = name.startsWith("oncapture:"); | ||
options.exprs.push(`${tag}.addEventListener("${name.slice(capture ? 10 : 3)}",exprs[${options.counter++}]${capture ? ",true" : ""})`); | ||
options.exprs.push( | ||
`${tag}.addEventListener("${name.slice(capture ? 10 : 3)}",exprs[${options.counter++}]${ | ||
capture ? ",true" : "" | ||
})` | ||
); | ||
} | ||
@@ -298,5 +367,11 @@ } else if (name === "ref") { | ||
parseKeyValue(node, tag, name, value, isSVG, isCE, childOptions); | ||
options.decl.push(`_fn${count} = (${value === "###" ? "doNotWrap" : ""}) => {\n${childOptions.exprs.join(";\n")};\n}`); | ||
options.decl.push( | ||
`_fn${count} = (${value === "###" ? "doNotWrap" : ""}) => {\n${childOptions.exprs.join( | ||
";\n" | ||
)};\n}` | ||
); | ||
if (value === "###") { | ||
options.exprs.push(`typeof exprs[${count}] === "function" ? r.effect(_fn${count}) : _fn${count}(true)`); | ||
options.exprs.push( | ||
`typeof exprs[${count}] === "function" ? r.effect(_fn${count}) : _fn${count}(true)` | ||
); | ||
} else { | ||
@@ -323,3 +398,6 @@ let check = ""; | ||
const child = node.children[i]; | ||
if (child.type === "comment" && child.content === "#" || child.type === "tag" && child.name === "###") { | ||
if ( | ||
(child.type === "comment" && child.content === "#") || | ||
(child.type === "tag" && child.name === "###") | ||
) { | ||
childOptions.multi = true; | ||
@@ -345,3 +423,5 @@ break; | ||
parseNode(child, childOptions); | ||
if (!childOptions.multi && child.type === "comment" && child.content === "#") node.children.splice(i, 1);else i++; | ||
if (!childOptions.multi && child.type === "comment" && child.content === "#") | ||
node.children.splice(i, 1); | ||
else i++; | ||
} | ||
@@ -368,22 +448,24 @@ options.counter = childOptions.counter; | ||
for (let i = 0; i < keys.length; i++) { | ||
const { | ||
type, | ||
name, | ||
value | ||
} = node.attrs[i]; | ||
if (type === 'attr') { | ||
const { type, name, value } = node.attrs[i]; | ||
if (type === "attr") { | ||
if (name === "###") { | ||
propGroups.push(`exprs[${options.counter++}]`); | ||
propGroups.push(props = []); | ||
propGroups.push((props = [])); | ||
} else if (value === "###") { | ||
props.push(`${name}: exprs[${options.counter++}]`); | ||
} else props.push(`${name}: "${value}"`); | ||
} else if (type === 'directive') { | ||
} else if (type === "directive") { | ||
const tag = `_$el${uuid++}`; | ||
const topDecl = !options.decl.length; | ||
options.decl.push(topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`); | ||
options.decl.push( | ||
topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}` | ||
); | ||
parseDirective(name, value, tag, options); | ||
} | ||
} | ||
if (node.children.length === 1 && node.children[0].type === "comment" && node.children[0].content === "#") { | ||
if ( | ||
node.children.length === 1 && | ||
node.children[0].type === "comment" && | ||
node.children[0].content === "#" | ||
) { | ||
props.push(`children: () => exprs[${options.counter++}]`); | ||
@@ -411,3 +493,16 @@ } else if (node.children.length) { | ||
} | ||
if (options.parent) options.exprs.push(`r.insert(${options.parent}, r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})${tag ? `, ${tag}` : ""})`);else options.exprs.push(`${options.fragment ? "" : "return "}r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})`); | ||
if (options.parent) | ||
options.exprs.push( | ||
`r.insert(${ | ||
options.parent | ||
}, r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})${ | ||
tag ? `, ${tag}` : "" | ||
})` | ||
); | ||
else | ||
options.exprs.push( | ||
`${ | ||
options.fragment ? "" : "return " | ||
}r.createComponent(exprs[${componentIdentifier}],${processComponentProps(propGroups)})` | ||
); | ||
options.path = tag; | ||
@@ -443,3 +538,10 @@ options.first = false; | ||
parseNode(child, childOptions); | ||
parts.push(`function() { ${childOptions.decl.join(",\n") + ";\n" + childOptions.exprs.join(";\n") + `;\nreturn _$el${id};\n`}}()`); | ||
parts.push( | ||
`function() { ${ | ||
childOptions.decl.join(",\n") + | ||
";\n" + | ||
childOptions.exprs.join(";\n") + | ||
`;\nreturn _$el${id};\n` | ||
}}()` | ||
); | ||
options.counter = childOptions.counter; | ||
@@ -450,3 +552,4 @@ options.templateId = childOptions.templateId; | ||
} else if (child.type === "comment") { | ||
if (child.content === "#") parts.push(`exprs[${options.counter++}]`);else if (child.content) { | ||
if (child.content === "#") parts.push(`exprs[${options.counter++}]`); | ||
else if (child.content) { | ||
for (let i = 0; i < child.content.split("###").length - 1; i++) { | ||
@@ -463,3 +566,5 @@ parts.push(`exprs[${options.counter++}]`); | ||
const templateId = options.templateId; | ||
options.decl.push(topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`); | ||
options.decl.push( | ||
topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}` | ||
); | ||
const isSVG = r.SVGElements.has(node.name); | ||
@@ -473,11 +578,9 @@ const isCE = node.name.includes("-"); | ||
for (let i = 0; i < node.attrs.length; i++) { | ||
const { | ||
type, | ||
name, | ||
value | ||
} = node.attrs[i]; | ||
if (type === 'attr') { | ||
const { type, name, value } = node.attrs[i]; | ||
if (type === "attr") { | ||
if (value.includes("###")) { | ||
let count = options.counter++; | ||
current += `${name}: ${name !== "ref" ? `typeof exprs[${count}] === "function" ? exprs[${count}]() : ` : ""}exprs[${count}],`; | ||
current += `${name}: ${ | ||
name !== "ref" ? `typeof exprs[${count}] === "function" ? exprs[${count}]() : ` : "" | ||
}exprs[${count}],`; | ||
} else if (name === "###") { | ||
@@ -492,3 +595,3 @@ if (current.length) { | ||
} | ||
} else if (type === 'directive') { | ||
} else if (type === "directive") { | ||
parseDirective(name, value, tag, options); | ||
@@ -501,11 +604,13 @@ } | ||
} | ||
options.exprs.push(`r.spread(${tag},${spreadArgs.length === 1 ? `typeof ${spreadArgs[0]} === "function" ? r.mergeProps(${spreadArgs[0]}) : ${spreadArgs[0]}` : `r.mergeProps(${spreadArgs.join(",")})`},${isSVG},${!!node.children.length})`); | ||
options.exprs.push( | ||
`r.spread(${tag},${ | ||
spreadArgs.length === 1 | ||
? `typeof ${spreadArgs[0]} === "function" ? r.mergeProps(${spreadArgs[0]}) : ${spreadArgs[0]}` | ||
: `r.mergeProps(${spreadArgs.join(",")})` | ||
},${isSVG},${!!node.children.length})` | ||
); | ||
} else { | ||
for (let i = 0; i < node.attrs.length; i++) { | ||
const { | ||
type, | ||
name, | ||
value | ||
} = node.attrs[i]; | ||
if (type === 'directive') { | ||
const { type, name, value } = node.attrs[i]; | ||
if (type === "directive") { | ||
parseDirective(name, value, tag, options); | ||
@@ -527,3 +632,5 @@ node.attrs.splice(i, 1); | ||
if (topDecl) { | ||
options.decl[0] = options.hasCustomElement ? `const ${tag} = r.untrack(() => document.importNode(tmpls[${templateId}].content.firstChild, true))` : `const ${tag} = tmpls[${templateId}].content.firstChild.cloneNode(true)`; | ||
options.decl[0] = options.hasCustomElement | ||
? `const ${tag} = r.untrack(() => document.importNode(tmpls[${templateId}].content.firstChild, true))` | ||
: `const ${tag} = tmpls[${templateId}].content.firstChild.cloneNode(true)`; | ||
} | ||
@@ -563,6 +670,8 @@ } else if (node.type === "text") { | ||
if (nodes.length > 1) { | ||
nodes = [{ | ||
type: "fragment", | ||
children: nodes | ||
}]; | ||
nodes = [ | ||
{ | ||
type: "fragment", | ||
children: nodes | ||
} | ||
]; | ||
} | ||
@@ -575,8 +684,21 @@ if (nodes[0].name === "###") { | ||
const templateNodes = [origNodes].concat(options.templateNodes); | ||
return [templateNodes.map(t => stringify(t)), funcBuilder("tmpls", "exprs", "r", options.decl.join(",\n") + ";\n" + options.exprs.join(";\n") + (toplevel ? "" : `;\nreturn _$el${id};\n`))]; | ||
return [ | ||
templateNodes.map(t => stringify(t)), | ||
funcBuilder( | ||
"tmpls", | ||
"exprs", | ||
"r", | ||
options.decl.join(",\n") + | ||
";\n" + | ||
options.exprs.join(";\n") + | ||
(toplevel ? "" : `;\nreturn _$el${id};\n`) | ||
) | ||
]; | ||
} | ||
function html(statics, ...args) { | ||
const templates = cache.get(statics) || createTemplate(statics, { | ||
funcBuilder: functionBuilder | ||
}); | ||
const templates = | ||
cache.get(statics) || | ||
createTemplate(statics, { | ||
funcBuilder: functionBuilder | ||
}); | ||
return templates[0].create(templates, args, r); | ||
@@ -583,0 +705,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: () => void, 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: () => void, 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.8.5", | ||
"version": "1.8.6", | ||
"author": "Ryan Carniato", | ||
@@ -83,2 +83,3 @@ "license": "MIT", | ||
"./dist/*": "./dist/*", | ||
"./types/*": "./types/*", | ||
"./jsx-runtime": { | ||
@@ -128,2 +129,3 @@ "types": "./types/jsx.d.ts", | ||
"./store/dist/*": "./store/dist/*", | ||
"./store/types/*": "./store/types/*", | ||
"./web": { | ||
@@ -169,2 +171,3 @@ "worker": { | ||
"./web/dist/*": "./web/dist/*", | ||
"./web/types/*": "./web/types/*", | ||
"./universal": { | ||
@@ -181,2 +184,3 @@ "development": { | ||
"./universal/dist/*": "./universal/dist/*", | ||
"./universal/types/*": "./universal/types/*", | ||
"./h": { | ||
@@ -198,2 +202,3 @@ "types": "./h/types/index.d.ts", | ||
"./h/dist/*": "./h/dist/*", | ||
"./h/types/*": "./h/types/*", | ||
"./html": { | ||
@@ -218,3 +223,3 @@ "types": "./html/types/index.d.ts", | ||
"csstype": "^3.1.0", | ||
"seroval": "^0.12.0" | ||
"seroval": "^0.14.1" | ||
}, | ||
@@ -221,0 +226,0 @@ "scripts": { |
@@ -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)) | ||
}); | ||
@@ -319,3 +362,6 @@ const keys = Object.keys(value), | ||
const unwrappedStore = unwrap(state || {}); | ||
if (typeof unwrappedStore !== "object" && typeof unwrappedStore !== "function") throw new Error(`Unexpected type ${typeof unwrappedStore} received when initializing 'createMutable'. Expected an object.`); | ||
if (typeof unwrappedStore !== "object" && typeof unwrappedStore !== "function") | ||
throw new Error( | ||
`Unexpected type ${typeof unwrappedStore} received when initializing 'createMutable'. Expected an object.` | ||
); | ||
const wrappedStore = wrap(unwrappedStore); | ||
@@ -336,3 +382,6 @@ DEV$1.registerGraph({ | ||
if (target === previous) return; | ||
if (property !== $ROOT && (!isWrappable(target) || !isWrappable(previous) || key && target[key] !== previous[key])) { | ||
if ( | ||
property !== $ROOT && | ||
(!isWrappable(target) || !isWrappable(previous) || (key && target[key] !== previous[key])) | ||
) { | ||
setProperty(parent, property, target); | ||
@@ -342,5 +391,15 @@ return; | ||
if (Array.isArray(target)) { | ||
if (target.length && previous.length && (!merge || key && target[0] && target[0][key] != null)) { | ||
if ( | ||
target.length && | ||
previous.length && | ||
(!merge || (key && target[0] && target[0][key] != null)) | ||
) { | ||
let i, j, start, end, newEnd, item, newIndicesNext, keyVal; | ||
for (start = 0, end = Math.min(previous.length, target.length); start < end && (previous[start] === target[start] || key && previous[start] && target[start] && previous[start][key] === target[start][key]); start++) { | ||
for ( | ||
start = 0, end = Math.min(previous.length, target.length); | ||
start < end && | ||
(previous[start] === target[start] || | ||
(key && previous[start] && target[start] && previous[start][key] === target[start][key])); | ||
start++ | ||
) { | ||
applyState(target[start], previous, start, merge, key); | ||
@@ -350,3 +409,10 @@ } | ||
newIndices = new Map(); | ||
for (end = previous.length - 1, newEnd = target.length - 1; end >= start && newEnd >= start && (previous[end] === target[newEnd] || key && previous[start] && target[start] && previous[end][key] === target[newEnd][key]); end--, newEnd--) { | ||
for ( | ||
end = previous.length - 1, newEnd = target.length - 1; | ||
end >= start && | ||
newEnd >= start && | ||
(previous[end] === target[newEnd] || | ||
(key && previous[start] && target[start] && previous[end][key] === target[newEnd][key])); | ||
end--, newEnd-- | ||
) { | ||
temp[newEnd] = previous[end]; | ||
@@ -405,12 +471,15 @@ } | ||
function reconcile(value, options = {}) { | ||
const { | ||
merge, | ||
key = "id" | ||
} = options, | ||
const { merge, key = "id" } = options, | ||
v = unwrap(value); | ||
return state => { | ||
if (!isWrappable(state) || !isWrappable(v)) return v; | ||
const res = applyState(v, { | ||
[$ROOT]: state | ||
}, $ROOT, merge, key); | ||
const res = applyState( | ||
v, | ||
{ | ||
[$ROOT]: state | ||
}, | ||
$ROOT, | ||
merge, | ||
key | ||
); | ||
return res === undefined ? state : res; | ||
@@ -425,3 +494,6 @@ }; | ||
let proxy; | ||
return isWrappable(value) ? producers.get(value) || (producers.set(value, proxy = new Proxy(value, setterTraps)), proxy) : value; | ||
return isWrappable(value) | ||
? producers.get(value) || | ||
(producers.set(value, (proxy = new Proxy(value, setterTraps))), proxy) | ||
: value; | ||
}, | ||
@@ -442,3 +514,3 @@ set(target, property, value) { | ||
if (!(proxy = producers.get(state))) { | ||
producers.set(state, proxy = new Proxy(state, setterTraps)); | ||
producers.set(state, (proxy = new Proxy(state, setterTraps))); | ||
} | ||
@@ -455,4 +527,4 @@ fn(proxy); | ||
hooks: DevHooks | ||
} ; | ||
}; | ||
export { $RAW, DEV, createMutable, createStore, modifyMutable, produce, reconcile, unwrap }; |
const $RAW = Symbol("state-raw"); | ||
function isWrappable(obj) { | ||
return obj != null && typeof obj === "object" && (Object.getPrototypeOf(obj) === Object.prototype || Array.isArray(obj)); | ||
return ( | ||
obj != null && | ||
typeof obj === "object" && | ||
(Object.getPrototypeOf(obj) === Object.prototype || Array.isArray(obj)) | ||
); | ||
} | ||
@@ -52,7 +56,3 @@ function unwrap(item) { | ||
} else if (isArray && partType === "object") { | ||
const { | ||
from = 0, | ||
to = current.length - 1, | ||
by = 1 | ||
} = part; | ||
const { from = 0, to = current.length - 1, by = 1 } = part; | ||
for (let i = from; i <= to; i += by) { | ||
@@ -75,3 +75,3 @@ updatePath(current, [i].concat(path), traversed); | ||
if (part === undefined && value == undefined) return; | ||
if (part === undefined || isWrappable(next) && isWrappable(value) && !Array.isArray(value)) { | ||
if (part === undefined || (isWrappable(next) && isWrappable(value) && !Array.isArray(value))) { | ||
mergeStoreNode(next, value); | ||
@@ -113,2 +113,13 @@ } else setProperty(current, part, value); | ||
export { $RAW, DEV, createMutable, createStore, isWrappable, produce, reconcile, setProperty, unwrap, updatePath }; | ||
export { | ||
$RAW, | ||
DEV, | ||
createMutable, | ||
createStore, | ||
isWrappable, | ||
produce, | ||
reconcile, | ||
setProperty, | ||
unwrap, | ||
updatePath | ||
}; |
@@ -1,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)) | ||
}); | ||
@@ -318,3 +358,6 @@ const keys = Object.keys(value), | ||
if (target === previous) return; | ||
if (property !== $ROOT && (!isWrappable(target) || !isWrappable(previous) || key && target[key] !== previous[key])) { | ||
if ( | ||
property !== $ROOT && | ||
(!isWrappable(target) || !isWrappable(previous) || (key && target[key] !== previous[key])) | ||
) { | ||
setProperty(parent, property, target); | ||
@@ -324,5 +367,15 @@ return; | ||
if (Array.isArray(target)) { | ||
if (target.length && previous.length && (!merge || key && target[0] && target[0][key] != null)) { | ||
if ( | ||
target.length && | ||
previous.length && | ||
(!merge || (key && target[0] && target[0][key] != null)) | ||
) { | ||
let i, j, start, end, newEnd, item, newIndicesNext, keyVal; | ||
for (start = 0, end = Math.min(previous.length, target.length); start < end && (previous[start] === target[start] || key && previous[start] && target[start] && previous[start][key] === target[start][key]); start++) { | ||
for ( | ||
start = 0, end = Math.min(previous.length, target.length); | ||
start < end && | ||
(previous[start] === target[start] || | ||
(key && previous[start] && target[start] && previous[start][key] === target[start][key])); | ||
start++ | ||
) { | ||
applyState(target[start], previous, start, merge, key); | ||
@@ -332,3 +385,10 @@ } | ||
newIndices = new Map(); | ||
for (end = previous.length - 1, newEnd = target.length - 1; end >= start && newEnd >= start && (previous[end] === target[newEnd] || key && previous[start] && target[start] && previous[end][key] === target[newEnd][key]); end--, newEnd--) { | ||
for ( | ||
end = previous.length - 1, newEnd = target.length - 1; | ||
end >= start && | ||
newEnd >= start && | ||
(previous[end] === target[newEnd] || | ||
(key && previous[start] && target[start] && previous[end][key] === target[newEnd][key])); | ||
end--, newEnd-- | ||
) { | ||
temp[newEnd] = previous[end]; | ||
@@ -387,12 +447,15 @@ } | ||
function reconcile(value, options = {}) { | ||
const { | ||
merge, | ||
key = "id" | ||
} = options, | ||
const { merge, key = "id" } = options, | ||
v = unwrap(value); | ||
return state => { | ||
if (!isWrappable(state) || !isWrappable(v)) return v; | ||
const res = applyState(v, { | ||
[$ROOT]: state | ||
}, $ROOT, merge, key); | ||
const res = applyState( | ||
v, | ||
{ | ||
[$ROOT]: state | ||
}, | ||
$ROOT, | ||
merge, | ||
key | ||
); | ||
return res === undefined ? state : res; | ||
@@ -407,3 +470,6 @@ }; | ||
let proxy; | ||
return isWrappable(value) ? producers.get(value) || (producers.set(value, proxy = new Proxy(value, setterTraps)), proxy) : value; | ||
return isWrappable(value) | ||
? producers.get(value) || | ||
(producers.set(value, (proxy = new Proxy(value, setterTraps))), proxy) | ||
: value; | ||
}, | ||
@@ -424,3 +490,3 @@ set(target, property, value) { | ||
if (!(proxy = producers.get(state))) { | ||
producers.set(state, proxy = new Proxy(state, setterTraps)); | ||
producers.set(state, (proxy = new Proxy(state, setterTraps))); | ||
} | ||
@@ -427,0 +493,0 @@ fn(proxy); |
export { $RAW, createStore, unwrap } from "./store.js"; | ||
export type { ArrayFilterFn, DeepMutable, DeepReadonly, NotWrappable, Part, SetStoreFunction, SolidStore, Store, StoreNode, StorePathRange, StoreSetter } from "./store.js"; | ||
export type { | ||
ArrayFilterFn, | ||
DeepMutable, | ||
DeepReadonly, | ||
NotWrappable, | ||
Part, | ||
SetStoreFunction, | ||
SolidStore, | ||
Store, | ||
StoreNode, | ||
StorePathRange, | ||
StoreSetter | ||
} from "./store.js"; | ||
export * from "./mutable.js"; | ||
export * from "./modifiers.js"; | ||
import { $NODE, isWrappable } from "./store.js"; | ||
export declare const DEV: { | ||
readonly $NODE: typeof $NODE; | ||
readonly isWrappable: typeof isWrappable; | ||
readonly hooks: { | ||
export declare const DEV: | ||
| { | ||
readonly $NODE: typeof $NODE; | ||
readonly isWrappable: typeof isWrappable; | ||
readonly hooks: { | ||
onStoreNodeUpdate: import("./store.js").OnStoreNodeUpdate | null; | ||
}; | ||
} | undefined; | ||
}; | ||
} | ||
| undefined; |
export type ReconcileOptions = { | ||
key?: string | null; | ||
merge?: boolean; | ||
key?: string | null; | ||
merge?: boolean; | ||
}; | ||
export declare function reconcile<T extends U, U>(value: T, options?: ReconcileOptions): (state: U) => T; | ||
export declare function reconcile<T extends U, U>( | ||
value: T, | ||
options?: ReconcileOptions | ||
): (state: U) => T; | ||
export declare function produce<T>(fn: (state: T) => void): (state: T) => T; |
import { StoreNode } from "./store.js"; | ||
export declare function createMutable<T extends StoreNode>(state: T, options?: { | ||
export declare function createMutable<T extends StoreNode>( | ||
state: T, | ||
options?: { | ||
name?: string; | ||
}): T; | ||
} | ||
): T; | ||
export declare function modifyMutable<T>(state: T, modifier: (state: T) => T): void; |
@@ -5,3 +5,8 @@ import type { SetStoreFunction, Store } from "./store.js"; | ||
export declare function unwrap<T>(item: T): T; | ||
export declare function setProperty(state: any, property: PropertyKey, value: any, force?: boolean): void; | ||
export declare function setProperty( | ||
state: any, | ||
property: PropertyKey, | ||
value: any, | ||
force?: boolean | ||
): void; | ||
export declare function updatePath(current: any, path: any[], traversed?: PropertyKey[]): void; | ||
@@ -11,8 +16,11 @@ export declare function createStore<T>(state: T | Store<T>): [Store<T>, SetStoreFunction<T>]; | ||
type ReconcileOptions = { | ||
key?: string | null; | ||
merge?: boolean; | ||
key?: string | null; | ||
merge?: boolean; | ||
}; | ||
export declare function reconcile<T extends U, U extends object>(value: T, options?: ReconcileOptions): (state: U) => T; | ||
export declare function reconcile<T extends U, U extends object>( | ||
value: T, | ||
options?: ReconcileOptions | ||
): (state: U) => T; | ||
export declare function produce<T>(fn: (state: T) => void): (state: T) => T; | ||
export declare const DEV: undefined; | ||
export {}; |
@@ -1,20 +0,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; | ||
}; | ||
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,12 +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; | ||
}; | ||
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,53 +36,57 @@ /** | ||
export declare const DevHooks: { | ||
afterUpdate: (() => void) | null; | ||
afterCreateOwner: ((owner: Owner) => 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; | ||
} | ||
@@ -102,10 +106,12 @@ export type RootFunction<T> = (dispose: () => void) => T; | ||
export type Setter<in out T> = { | ||
<U extends T>(...args: undefined extends T ? [] : [value: (prev: T) => U]): undefined extends T ? undefined : U; | ||
<U extends T>(value: (prev: T) => U): U; | ||
<U extends T>(value: Exclude<U, Function>): U; | ||
<U extends T>(value: Exclude<U, Function> | ((prev: T) => U)): U; | ||
<U extends T>(...args: undefined extends T ? [] : [value: (prev: T) => U]): undefined extends T | ||
? undefined | ||
: U; | ||
<U extends T>(value: (prev: T) => U): U; | ||
<U extends T>(value: Exclude<U, Function>): U; | ||
<U extends T>(value: Exclude<U, Function> | ((prev: T) => U)): U; | ||
}; | ||
export type Signal<T> = [get: Accessor<T>, set: Setter<T>]; | ||
export interface SignalOptions<T> extends MemoOptions<T> { | ||
internal?: boolean; | ||
internal?: boolean; | ||
} | ||
@@ -138,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; | ||
@@ -160,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; | ||
/** | ||
@@ -178,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; | ||
/** | ||
@@ -196,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; | ||
/** | ||
@@ -214,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); | ||
} | ||
@@ -238,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; | ||
} | ||
@@ -279,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> | ||
]; | ||
@@ -335,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; | ||
} | ||
@@ -358,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; | ||
@@ -385,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; | ||
/** | ||
@@ -404,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; | ||
} | ||
@@ -441,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>>; | ||
/** | ||
@@ -499,5 +581,5 @@ * onMount - run an effect only after initial render on mount | ||
export interface DevComponent<T> extends Memo<unknown> { | ||
props: T; | ||
name: string; | ||
component: (props: T) => unknown; | ||
props: T; | ||
name: string; | ||
component: (props: T) => unknown; | ||
} | ||
@@ -507,8 +589,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; | ||
} | ||
@@ -534,3 +616,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>; | ||
@@ -549,3 +634,3 @@ /** | ||
export type ChildrenReturn = Accessor<ResolvedChildren> & { | ||
toArray: () => ResolvedJSXElement[]; | ||
toArray: () => ResolvedJSXElement[]; | ||
}; | ||
@@ -562,12 +647,12 @@ /** | ||
export type SuspenseContextType = { | ||
increment?: () => void; | ||
decrement?: () => void; | ||
inFallback?: () => boolean; | ||
effects?: Computation<any>[]; | ||
resolved?: boolean; | ||
increment?: () => void; | ||
decrement?: () => void; | ||
inFallback?: () => boolean; | ||
effects?: Computation<any>[]; | ||
resolved?: boolean; | ||
}; | ||
type SuspenseContext = Context<SuspenseContextType | undefined> & { | ||
active?(): boolean; | ||
increment?(): void; | ||
decrement?(): void; | ||
active?(): boolean; | ||
increment?(): void; | ||
decrement?(): void; | ||
}; | ||
@@ -578,3 +663,7 @@ declare let SuspenseContext: SuspenseContext; | ||
export declare function readSignal(this: SignalState<any> | Memo<any>): any; | ||
export declare function writeSignal(node: SignalState<any> | Memo<any>, value: any, isComp?: boolean): any; | ||
export declare function writeSignal( | ||
node: SignalState<any> | Memo<any>, | ||
value: any, | ||
isComp?: boolean | ||
): any; | ||
/** | ||
@@ -581,0 +670,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 = {}> = P & { | ||
children?: never; | ||
children?: never; | ||
}; | ||
@@ -29,3 +29,3 @@ /** | ||
export type ParentProps<P = {}> = P & { | ||
children?: JSX.Element; | ||
children?: JSX.Element; | ||
}; | ||
@@ -45,3 +45,3 @@ /** | ||
export type FlowProps<P = {}, C = JSX.Element> = P & { | ||
children: C; | ||
children: C; | ||
}; | ||
@@ -65,3 +65,7 @@ /** | ||
*/ | ||
export type ComponentProps<T extends ValidComponent> = T extends Component<infer P> ? P : T extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[T] : Record<string, unknown>; | ||
export type ComponentProps<T extends ValidComponent> = T extends Component<infer P> | ||
? P | ||
: T extends keyof JSX.IntrinsicElements | ||
? JSX.IntrinsicElements[T] | ||
: Record<string, unknown>; | ||
/** | ||
@@ -75,40 +79,67 @@ * Type of `props.ref`, for use in `Component` or `props` typing. | ||
type DistributeOverride<T, F> = T extends undefined ? F : T; | ||
type Override<T, U> = T extends any ? U extends any ? { | ||
[K in keyof T]: K extends keyof U ? DistributeOverride<U[K], T[K]> : T[K]; | ||
} & { | ||
[K in keyof U]: K extends keyof T ? DistributeOverride<U[K], T[K]> : U[K]; | ||
} : T & U : T & U; | ||
type OverrideSpread<T, U> = T extends any ? { | ||
[K in keyof ({ | ||
type Override<T, U> = T extends any | ||
? U extends any | ||
? { | ||
[K in keyof T]: K extends keyof U ? DistributeOverride<U[K], T[K]> : T[K]; | ||
} & { | ||
[K in keyof U]: K extends keyof T ? DistributeOverride<U[K], T[K]> : U[K]; | ||
} | ||
: T & U | ||
: T & U; | ||
type OverrideSpread<T, U> = T extends any | ||
? { | ||
[K in keyof ({ | ||
[K in keyof T]: any; | ||
} & { | ||
} & { | ||
[K in keyof U]?: any; | ||
} & { | ||
} & { | ||
[K in U extends any ? keyof U : keyof U]?: any; | ||
})]: K extends keyof T ? Exclude<U extends any ? U[K & keyof U] : never, undefined> | T[K] : U extends any ? U[K & keyof U] : never; | ||
} : T & U; | ||
type Simplify<T> = T extends any ? { | ||
[K in keyof T]: T[K]; | ||
} : T; | ||
})]: K extends keyof T | ||
? Exclude<U extends any ? U[K & keyof U] : never, undefined> | T[K] | ||
: U extends any | ||
? U[K & keyof U] | ||
: never; | ||
} | ||
: T & U; | ||
type Simplify<T> = T extends any | ||
? { | ||
[K in keyof T]: T[K]; | ||
} | ||
: T; | ||
type _MergeProps<T extends unknown[], Curr = {}> = T extends [ | ||
infer Next | (() => infer Next), | ||
...infer Rest | ||
] ? _MergeProps<Rest, Override<Curr, Next>> : T extends [...infer Rest, infer Next | (() => infer Next)] ? Override<_MergeProps<Rest, Curr>, Next> : T extends [] ? Curr : T extends (infer I | (() => infer I))[] ? OverrideSpread<Curr, I> : Curr; | ||
infer Next | (() => infer Next), | ||
...infer Rest | ||
] | ||
? _MergeProps<Rest, Override<Curr, Next>> | ||
: T extends [...infer Rest, infer Next | (() => infer Next)] | ||
? Override<_MergeProps<Rest, Curr>, Next> | ||
: T extends [] | ||
? Curr | ||
: T extends (infer I | (() => infer I))[] | ||
? OverrideSpread<Curr, I> | ||
: Curr; | ||
export type MergeProps<T extends unknown[]> = Simplify<_MergeProps<T>>; | ||
export declare function mergeProps<T extends unknown[]>(...sources: T): MergeProps<T>; | ||
export type SplitProps<T, K extends (readonly (keyof T)[])[]> = [ | ||
...{ | ||
[P in keyof K]: P extends `${number}` ? Pick<T, Extract<K[P], readonly (keyof T)[]>[number]> : never; | ||
}, | ||
Omit<T, K[number][number]> | ||
...{ | ||
[P in keyof K]: P extends `${number}` | ||
? Pick<T, Extract<K[P], readonly (keyof T)[]>[number]> | ||
: never; | ||
}, | ||
Omit<T, K[number][number]> | ||
]; | ||
export declare function splitProps<T extends Record<any, any>, K extends [readonly (keyof T)[], ...(readonly (keyof T)[])[]]>(props: T, ...keys: K): SplitProps<T, K>; | ||
export declare function lazy<T extends Component<any>>(fn: () => Promise<{ | ||
export declare function splitProps< | ||
T extends Record<any, any>, | ||
K extends [readonly (keyof T)[], ...(readonly (keyof T)[])[]] | ||
>(props: T, ...keys: K): SplitProps<T, K>; | ||
export declare function lazy<T extends Component<any>>( | ||
fn: () => Promise<{ | ||
default: T; | ||
}>): T & { | ||
preload: () => Promise<{ | ||
default: T; | ||
}>; | ||
}> | ||
): T & { | ||
preload: () => Promise<{ | ||
default: T; | ||
}>; | ||
}; | ||
export declare function createUniqueId(): string; | ||
export {}; |
@@ -17,5 +17,5 @@ import { Accessor } from "../reactive/signal.js"; | ||
export declare function For<T extends readonly any[], U extends JSX.Element>(props: { | ||
each: T | undefined | null | false; | ||
fallback?: JSX.Element; | ||
children: (item: T[number], index: Accessor<number>) => U; | ||
each: T | undefined | null | false; | ||
fallback?: JSX.Element; | ||
children: (item: T[number], index: Accessor<number>) => U; | ||
}): JSX.Element; | ||
@@ -36,5 +36,5 @@ /** | ||
export declare function Index<T extends readonly any[], U extends JSX.Element>(props: { | ||
each: T | undefined | null | false; | ||
fallback?: JSX.Element; | ||
children: (item: Accessor<T[number]>, index: number) => U; | ||
each: T | undefined | null | false; | ||
fallback?: JSX.Element; | ||
children: (item: Accessor<T[number]>, index: number) => U; | ||
}): JSX.Element; | ||
@@ -46,13 +46,19 @@ type RequiredParameter<T> = T extends () => unknown ? never : T; | ||
*/ | ||
export declare function Show<T, TRenderFunction extends (item: Accessor<NonNullable<T>>) => JSX.Element>(props: { | ||
when: T | undefined | null | false; | ||
keyed?: false; | ||
fallback?: JSX.Element; | ||
children: JSX.Element | RequiredParameter<TRenderFunction>; | ||
export declare function Show< | ||
T, | ||
TRenderFunction extends (item: Accessor<NonNullable<T>>) => JSX.Element | ||
>(props: { | ||
when: T | undefined | null | false; | ||
keyed?: false; | ||
fallback?: JSX.Element; | ||
children: JSX.Element | RequiredParameter<TRenderFunction>; | ||
}): JSX.Element; | ||
export declare function Show<T, TRenderFunction extends (item: NonNullable<T>) => JSX.Element>(props: { | ||
when: T | undefined | null | false; | ||
keyed: true; | ||
fallback?: JSX.Element; | ||
children: JSX.Element | RequiredParameter<TRenderFunction>; | ||
export declare function Show< | ||
T, | ||
TRenderFunction extends (item: NonNullable<T>) => JSX.Element | ||
>(props: { | ||
when: T | undefined | null | false; | ||
keyed: true; | ||
fallback?: JSX.Element; | ||
children: JSX.Element | RequiredParameter<TRenderFunction>; | ||
}): JSX.Element; | ||
@@ -74,9 +80,9 @@ /** | ||
export declare function Switch(props: { | ||
fallback?: JSX.Element; | ||
children: JSX.Element; | ||
fallback?: JSX.Element; | ||
children: JSX.Element; | ||
}): JSX.Element; | ||
export type MatchProps<T> = { | ||
when: T | undefined | null | false; | ||
keyed?: boolean; | ||
children: JSX.Element | ((item: NonNullable<T> | Accessor<NonNullable<T>>) => JSX.Element); | ||
when: T | undefined | null | false; | ||
keyed?: boolean; | ||
children: JSX.Element | ((item: NonNullable<T> | Accessor<NonNullable<T>>) => JSX.Element); | ||
}; | ||
@@ -92,11 +98,17 @@ /** | ||
*/ | ||
export declare function Match<T, TRenderFunction extends (item: Accessor<NonNullable<T>>) => JSX.Element>(props: { | ||
when: T | undefined | null | false; | ||
keyed?: false; | ||
children: JSX.Element | RequiredParameter<TRenderFunction>; | ||
export declare function Match< | ||
T, | ||
TRenderFunction extends (item: Accessor<NonNullable<T>>) => JSX.Element | ||
>(props: { | ||
when: T | undefined | null | false; | ||
keyed?: false; | ||
children: JSX.Element | RequiredParameter<TRenderFunction>; | ||
}): JSX.Element; | ||
export declare function Match<T, TRenderFunction extends (item: NonNullable<T>) => JSX.Element>(props: { | ||
when: T | undefined | null | false; | ||
keyed: true; | ||
children: JSX.Element | RequiredParameter<TRenderFunction>; | ||
export declare function Match< | ||
T, | ||
TRenderFunction extends (item: NonNullable<T>) => JSX.Element | ||
>(props: { | ||
when: T | undefined | null | false; | ||
keyed: true; | ||
children: JSX.Element | RequiredParameter<TRenderFunction>; | ||
}): JSX.Element; | ||
@@ -120,5 +132,5 @@ export declare function resetErrorBoundaries(): void; | ||
export declare function ErrorBoundary(props: { | ||
fallback: JSX.Element | ((err: any, reset: () => void) => JSX.Element); | ||
children: JSX.Element; | ||
fallback: JSX.Element | ((err: any, reset: () => void) => JSX.Element); | ||
children: JSX.Element; | ||
}): JSX.Element; | ||
export {}; |
import { Computation } from "../reactive/signal.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>[]; | ||
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>[]; | ||
}; | ||
@@ -19,0 +19,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,5 +19,9 @@ export type FlowComponent<P = {}, C = JSX.Element> = Component<FlowProps<P, C>>; | ||
export type ValidComponent = keyof JSX.IntrinsicElements | Component<any> | (string & {}); | ||
export type ComponentProps<T extends ValidComponent> = T extends Component<infer P> ? P : T extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[T] : Record<string, unknown>; | ||
export type ComponentProps<T extends ValidComponent> = T extends Component<infer P> | ||
? P | ||
: T extends keyof JSX.IntrinsicElements | ||
? JSX.IntrinsicElements[T] | ||
: Record<string, unknown>; | ||
type SharedConfig = { | ||
context?: HydrationContext; | ||
context?: HydrationContext; | ||
}; | ||
@@ -29,24 +33,62 @@ export declare const sharedConfig: SharedConfig; | ||
export declare function mergeProps<T, U, V>(source: T, source1: U, source2: V): T & U & V; | ||
export declare function mergeProps<T, U, V, W>(source: T, source1: U, source2: V, source3: W): T & U & V & W; | ||
export declare function splitProps<T extends object, K1 extends keyof T>(props: T, ...keys: [K1[]]): [Pick<T, K1>, Omit<T, K1>]; | ||
export declare function splitProps<T extends object, K1 extends keyof T, K2 extends keyof T>(props: T, ...keys: [K1[], K2[]]): [Pick<T, K1>, Pick<T, K2>, Omit<T, K1 | K2>]; | ||
export declare function splitProps<T extends object, K1 extends keyof T, K2 extends keyof T, K3 extends keyof T>(props: T, ...keys: [K1[], K2[], K3[]]): [Pick<T, K1>, Pick<T, K2>, Pick<T, K3>, Omit<T, K1 | K2 | K3>]; | ||
export declare function splitProps<T extends object, K1 extends keyof T, K2 extends keyof T, K3 extends keyof T, K4 extends keyof T>(props: T, ...keys: [K1[], K2[], K3[], K4[]]): [Pick<T, K1>, Pick<T, K2>, Pick<T, K3>, Pick<T, K4>, Omit<T, K1 | K2 | K3 | K4>]; | ||
export declare function splitProps<T extends object, K1 extends keyof T, K2 extends keyof T, K3 extends keyof T, K4 extends keyof T, K5 extends keyof T>(props: T, ...keys: [K1[], K2[], K3[], K4[], K5[]]): [ | ||
Pick<T, K1>, | ||
Pick<T, K2>, | ||
Pick<T, K3>, | ||
Pick<T, K4>, | ||
Pick<T, K5>, | ||
Omit<T, K1 | K2 | K3 | K4 | K5> | ||
export declare function mergeProps<T, U, V, W>( | ||
source: T, | ||
source1: U, | ||
source2: V, | ||
source3: W | ||
): T & U & V & W; | ||
export declare function splitProps<T extends object, K1 extends keyof T>( | ||
props: T, | ||
...keys: [K1[]] | ||
): [Pick<T, K1>, Omit<T, K1>]; | ||
export declare function splitProps<T extends object, K1 extends keyof T, K2 extends keyof T>( | ||
props: T, | ||
...keys: [K1[], K2[]] | ||
): [Pick<T, K1>, Pick<T, K2>, Omit<T, K1 | K2>]; | ||
export declare function splitProps< | ||
T extends object, | ||
K1 extends keyof T, | ||
K2 extends keyof T, | ||
K3 extends keyof T | ||
>( | ||
props: T, | ||
...keys: [K1[], K2[], K3[]] | ||
): [Pick<T, K1>, Pick<T, K2>, Pick<T, K3>, Omit<T, K1 | K2 | K3>]; | ||
export declare function splitProps< | ||
T extends object, | ||
K1 extends keyof T, | ||
K2 extends keyof T, | ||
K3 extends keyof T, | ||
K4 extends keyof T | ||
>( | ||
props: T, | ||
...keys: [K1[], K2[], K3[], K4[]] | ||
): [Pick<T, K1>, Pick<T, K2>, Pick<T, K3>, Pick<T, K4>, Omit<T, K1 | K2 | K3 | K4>]; | ||
export declare function splitProps< | ||
T extends object, | ||
K1 extends keyof T, | ||
K2 extends keyof T, | ||
K3 extends keyof T, | ||
K4 extends keyof T, | ||
K5 extends keyof T | ||
>( | ||
props: T, | ||
...keys: [K1[], K2[], K3[], K4[], K5[]] | ||
): [ | ||
Pick<T, K1>, | ||
Pick<T, K2>, | ||
Pick<T, K3>, | ||
Pick<T, K4>, | ||
Pick<T, K5>, | ||
Omit<T, K1 | K2 | K3 | K4 | K5> | ||
]; | ||
export declare function For<T>(props: { | ||
each: T[]; | ||
fallback?: string; | ||
children: (item: T, index: () => number) => string; | ||
each: T[]; | ||
fallback?: string; | ||
children: (item: T, index: () => number) => string; | ||
}): string | any[] | undefined; | ||
export declare function Index<T>(props: { | ||
each: T[]; | ||
fallback?: string; | ||
children: (item: () => T, index: number) => string; | ||
each: T[]; | ||
fallback?: string; | ||
children: (item: () => T, index: number) => string; | ||
}): string | any[] | undefined; | ||
@@ -58,15 +100,15 @@ /** | ||
export declare function Show<T>(props: { | ||
when: T | undefined | null | false; | ||
keyed?: boolean; | ||
fallback?: string; | ||
children: string | ((item: NonNullable<T> | Accessor<NonNullable<T>>) => string); | ||
when: T | undefined | null | false; | ||
keyed?: boolean; | ||
fallback?: string; | ||
children: string | ((item: NonNullable<T> | Accessor<NonNullable<T>>) => string); | ||
}): string; | ||
export declare function Switch(props: { | ||
fallback?: string; | ||
children: MatchProps<unknown> | MatchProps<unknown>[]; | ||
fallback?: string; | ||
children: MatchProps<unknown> | MatchProps<unknown>[]; | ||
}): string; | ||
type MatchProps<T> = { | ||
when: T | false; | ||
keyed?: boolean; | ||
children: string | ((item: NonNullable<T> | Accessor<NonNullable<T>>) => string); | ||
when: T | false; | ||
keyed?: boolean; | ||
children: string | ((item: NonNullable<T> | Accessor<NonNullable<T>>) => string); | ||
}; | ||
@@ -76,24 +118,30 @@ export declare function Match<T>(props: MatchProps<T>): MatchProps<T>; | ||
export declare function ErrorBoundary(props: { | ||
fallback: string | ((err: any, reset: () => void) => string); | ||
children: string; | ||
}): string | ((err: any, reset: () => void) => string) | { | ||
t: string; | ||
}; | ||
fallback: string | ((err: any, reset: () => void) => string); | ||
children: string; | ||
}): | ||
| string | ||
| ((err: any, reset: () => void) => string) | ||
| { | ||
t: string; | ||
}; | ||
export interface Resource<T> { | ||
(): T | undefined; | ||
state: "unresolved" | "pending" | "ready" | "refreshing" | "errored"; | ||
loading: boolean; | ||
error: any; | ||
latest: T | undefined; | ||
(): T | undefined; | ||
state: "unresolved" | "pending" | "ready" | "refreshing" | "errored"; | ||
loading: boolean; | ||
error: any; | ||
latest: T | undefined; | ||
} | ||
type SuspenseContextType = { | ||
resources: Map<string, { | ||
loading: boolean; | ||
error: any; | ||
}>; | ||
completed: () => void; | ||
resources: Map< | ||
string, | ||
{ | ||
loading: boolean; | ||
error: any; | ||
} | ||
>; | ||
completed: () => void; | ||
}; | ||
export type ResourceActions<T> = { | ||
mutate: Setter<T>; | ||
refetch: (info?: unknown) => void; | ||
mutate: Setter<T>; | ||
refetch: (info?: unknown) => void; | ||
}; | ||
@@ -104,30 +152,48 @@ export type ResourceReturn<T> = [Resource<T>, ResourceActions<T>]; | ||
export type ResourceFetcherInfo<T> = { | ||
value: T | undefined; | ||
refetching?: unknown; | ||
value: T | undefined; | ||
refetching?: unknown; | ||
}; | ||
export type ResourceOptions<T> = undefined extends T ? { | ||
initialValue?: T; | ||
name?: string; | ||
deferStream?: boolean; | ||
ssrLoadFrom?: "initial" | "server"; | ||
storage?: () => Signal<T | undefined>; | ||
onHydrated?: <S, T>(k: S, info: ResourceFetcherInfo<T>) => void; | ||
} : { | ||
initialValue: T; | ||
name?: string; | ||
deferStream?: boolean; | ||
ssrLoadFrom?: "initial" | "server"; | ||
storage?: (v?: T) => Signal<T | undefined>; | ||
onHydrated?: <S, T>(k: S, info: ResourceFetcherInfo<T>) => void; | ||
}; | ||
export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): ResourceReturn<T | undefined>; | ||
export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T>; | ||
export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): ResourceReturn<T | undefined>; | ||
export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T>; | ||
export declare function lazy<T extends Component<any>>(fn: () => Promise<{ | ||
export type ResourceOptions<T> = undefined extends T | ||
? { | ||
initialValue?: T; | ||
name?: string; | ||
deferStream?: boolean; | ||
ssrLoadFrom?: "initial" | "server"; | ||
storage?: () => Signal<T | undefined>; | ||
onHydrated?: <S, T>(k: S, info: ResourceFetcherInfo<T>) => void; | ||
} | ||
: { | ||
initialValue: T; | ||
name?: string; | ||
deferStream?: boolean; | ||
ssrLoadFrom?: "initial" | "server"; | ||
storage?: (v?: T) => Signal<T | undefined>; | ||
onHydrated?: <S, T>(k: S, info: ResourceFetcherInfo<T>) => void; | ||
}; | ||
export declare function createResource<T, S = true>( | ||
fetcher: ResourceFetcher<S, T>, | ||
options?: ResourceOptions<undefined> | ||
): ResourceReturn<T | undefined>; | ||
export declare function createResource<T, S = true>( | ||
fetcher: ResourceFetcher<S, T>, | ||
options: ResourceOptions<T> | ||
): ResourceReturn<T>; | ||
export declare function createResource<T, S>( | ||
source: ResourceSource<S>, | ||
fetcher: ResourceFetcher<S, T>, | ||
options?: ResourceOptions<undefined> | ||
): ResourceReturn<T | undefined>; | ||
export declare function createResource<T, S>( | ||
source: ResourceSource<S>, | ||
fetcher: ResourceFetcher<S, T>, | ||
options: ResourceOptions<T> | ||
): ResourceReturn<T>; | ||
export declare function lazy<T extends Component<any>>( | ||
fn: () => Promise<{ | ||
default: T; | ||
}>): T & { | ||
preload: () => Promise<{ | ||
default: T; | ||
}>; | ||
}> | ||
): T & { | ||
preload: () => Promise<{ | ||
default: T; | ||
}>; | ||
}; | ||
@@ -139,25 +205,30 @@ export declare function enableScheduling(): void; | ||
type HydrationContext = { | ||
id: string; | ||
count: number; | ||
serialize: (id: string, v: Promise<any> | any, deferStream?: boolean) => void; | ||
replace: (id: string, replacement: () => any) => void; | ||
block: (p: Promise<any>) => void; | ||
resources: Record<string, any>; | ||
suspense: Record<string, SuspenseContextType>; | ||
registerFragment: (v: string) => (v?: string, err?: any) => boolean; | ||
lazy: Record<string, Promise<any>>; | ||
async?: boolean; | ||
noHydrate: boolean; | ||
id: string; | ||
count: number; | ||
serialize: (id: string, v: Promise<any> | any, deferStream?: boolean) => void; | ||
replace: (id: string, replacement: () => any) => void; | ||
block: (p: Promise<any>) => void; | ||
resources: Record<string, any>; | ||
suspense: Record<string, SuspenseContextType>; | ||
registerFragment: (v: string) => (v?: string, err?: any) => boolean; | ||
lazy: Record<string, Promise<any>>; | ||
async?: boolean; | ||
noHydrate: boolean; | ||
}; | ||
export declare function SuspenseList(props: { | ||
children: string; | ||
revealOrder: "forwards" | "backwards" | "together"; | ||
tail?: "collapsed" | "hidden"; | ||
children: string; | ||
revealOrder: "forwards" | "backwards" | "together"; | ||
tail?: "collapsed" | "hidden"; | ||
}): string; | ||
export declare function Suspense(props: { | ||
fallback?: string; | ||
children: string; | ||
}): string | number | boolean | Node | JSX.ArrayElement | { | ||
t: string; | ||
} | null | undefined; | ||
export declare function Suspense(props: { fallback?: string; children: string }): | ||
| string | ||
| number | ||
| boolean | ||
| Node | ||
| JSX.ArrayElement | ||
| { | ||
t: string; | ||
} | ||
| null | ||
| undefined; | ||
export {}; |
@@ -1,2 +0,9 @@ | ||
import { createRoot, createRenderEffect, mergeProps, createMemo, createComponent, untrack } from 'solid-js'; | ||
import { | ||
createRoot, | ||
createRenderEffect, | ||
mergeProps, | ||
createMemo, | ||
createComponent, | ||
untrack | ||
} from "solid-js"; | ||
@@ -35,3 +42,3 @@ function createRenderer$1({ | ||
if (current !== "" && typeof current === "string") { | ||
replaceText(getFirstChild(parent), current = value); | ||
replaceText(getFirstChild(parent), (current = value)); | ||
} else { | ||
@@ -54,3 +61,5 @@ cleanChildren(parent, current, marker, createTextNode(value)); | ||
if (normalizeIncomingArray(array, value, unwrapArray)) { | ||
createRenderEffect(() => current = insertExpression(parent, array, current, marker, true)); | ||
createRenderEffect( | ||
() => (current = insertExpression(parent, array, current, marker, true)) | ||
); | ||
return () => current; | ||
@@ -60,3 +69,3 @@ } | ||
const replacement = cleanChildren(parent, current, marker); | ||
if (multi) return current = replacement; | ||
if (multi) return (current = replacement); | ||
} else { | ||
@@ -70,3 +79,3 @@ if (Array.isArray(current)) { | ||
} else { | ||
reconcileArrays(parent, multi && current || [getFirstChild(parent)], array); | ||
reconcileArrays(parent, (multi && current) || [getFirstChild(parent)], array); | ||
} | ||
@@ -77,3 +86,3 @@ } | ||
if (Array.isArray(current)) { | ||
if (multi) return current = cleanChildren(parent, current, marker, value); | ||
if (multi) return (current = cleanChildren(parent, current, marker, value)); | ||
cleanChildren(parent, current, null, value); | ||
@@ -92,3 +101,4 @@ } else if (current == null || current === "" || !getFirstChild(parent)) { | ||
t; | ||
if (item == null || item === true || item === false) ; else if (Array.isArray(item)) { | ||
if (item == null || item === true || item === false); | ||
else if (Array.isArray(item)) { | ||
dynamic = normalizeIncomingArray(normalized, item) || dynamic; | ||
@@ -100,3 +110,4 @@ } else if ((t = typeof item) === "string" || t === "number") { | ||
while (typeof item === "function") item = item(); | ||
dynamic = normalizeIncomingArray(normalized, Array.isArray(item) ? item : [item]) || dynamic; | ||
dynamic = | ||
normalizeIncomingArray(normalized, Array.isArray(item) ? item : [item]) || dynamic; | ||
} else { | ||
@@ -129,3 +140,4 @@ normalized.push(item); | ||
if (aEnd === aStart) { | ||
const node = bEnd < bLength ? bStart ? getNextSibling(b[bStart - 1]) : b[bEnd - bStart] : after; | ||
const node = | ||
bEnd < bLength ? (bStart ? getNextSibling(b[bStart - 1]) : b[bEnd - bStart]) : after; | ||
while (bStart < bEnd) insertNode(parentNode, b[bStart++], node); | ||
@@ -170,3 +182,3 @@ } else if (bEnd === bStart) { | ||
let removed; | ||
while (removed = getFirstChild(parent)) removeNode(parent, removed); | ||
while ((removed = getFirstChild(parent))) removeNode(parent, removed); | ||
replacement && insertNode(parent, replacement); | ||
@@ -182,3 +194,5 @@ return ""; | ||
const isParent = getParentNode(el) === parent; | ||
if (!inserted && !i) isParent ? replaceNode(parent, node, el) : insertNode(parent, node, marker);else isParent && removeNode(parent, el); | ||
if (!inserted && !i) | ||
isParent ? replaceNode(parent, node, el) : insertNode(parent, node, marker); | ||
else isParent && removeNode(parent, el); | ||
} else inserted = true; | ||
@@ -199,3 +213,5 @@ } | ||
if (!skipChildren) { | ||
createRenderEffect(() => prevProps.children = insertExpression(node, props.children, prevProps.children)); | ||
createRenderEffect( | ||
() => (prevProps.children = insertExpression(node, props.children, prevProps.children)) | ||
); | ||
} | ||
@@ -202,0 +218,0 @@ createRenderEffect(() => props.ref && props.ref(node)); |
@@ -1,2 +0,9 @@ | ||
import { createRoot, createRenderEffect, mergeProps, createMemo, createComponent, untrack } from 'solid-js'; | ||
import { | ||
createRoot, | ||
createRenderEffect, | ||
mergeProps, | ||
createMemo, | ||
createComponent, | ||
untrack | ||
} from "solid-js"; | ||
@@ -35,3 +42,3 @@ function createRenderer$1({ | ||
if (current !== "" && typeof current === "string") { | ||
replaceText(getFirstChild(parent), current = value); | ||
replaceText(getFirstChild(parent), (current = value)); | ||
} else { | ||
@@ -54,3 +61,5 @@ cleanChildren(parent, current, marker, createTextNode(value)); | ||
if (normalizeIncomingArray(array, value, unwrapArray)) { | ||
createRenderEffect(() => current = insertExpression(parent, array, current, marker, true)); | ||
createRenderEffect( | ||
() => (current = insertExpression(parent, array, current, marker, true)) | ||
); | ||
return () => current; | ||
@@ -60,3 +69,3 @@ } | ||
const replacement = cleanChildren(parent, current, marker); | ||
if (multi) return current = replacement; | ||
if (multi) return (current = replacement); | ||
} else { | ||
@@ -70,3 +79,3 @@ if (Array.isArray(current)) { | ||
} else { | ||
reconcileArrays(parent, multi && current || [getFirstChild(parent)], array); | ||
reconcileArrays(parent, (multi && current) || [getFirstChild(parent)], array); | ||
} | ||
@@ -77,3 +86,3 @@ } | ||
if (Array.isArray(current)) { | ||
if (multi) return current = cleanChildren(parent, current, marker, value); | ||
if (multi) return (current = cleanChildren(parent, current, marker, value)); | ||
cleanChildren(parent, current, null, value); | ||
@@ -92,3 +101,4 @@ } else if (current == null || current === "" || !getFirstChild(parent)) { | ||
t; | ||
if (item == null || item === true || item === false) ; else if (Array.isArray(item)) { | ||
if (item == null || item === true || item === false); | ||
else if (Array.isArray(item)) { | ||
dynamic = normalizeIncomingArray(normalized, item) || dynamic; | ||
@@ -100,3 +110,4 @@ } else if ((t = typeof item) === "string" || t === "number") { | ||
while (typeof item === "function") item = item(); | ||
dynamic = normalizeIncomingArray(normalized, Array.isArray(item) ? item : [item]) || dynamic; | ||
dynamic = | ||
normalizeIncomingArray(normalized, Array.isArray(item) ? item : [item]) || dynamic; | ||
} else { | ||
@@ -129,3 +140,4 @@ normalized.push(item); | ||
if (aEnd === aStart) { | ||
const node = bEnd < bLength ? bStart ? getNextSibling(b[bStart - 1]) : b[bEnd - bStart] : after; | ||
const node = | ||
bEnd < bLength ? (bStart ? getNextSibling(b[bStart - 1]) : b[bEnd - bStart]) : after; | ||
while (bStart < bEnd) insertNode(parentNode, b[bStart++], node); | ||
@@ -170,3 +182,3 @@ } else if (bEnd === bStart) { | ||
let removed; | ||
while (removed = getFirstChild(parent)) removeNode(parent, removed); | ||
while ((removed = getFirstChild(parent))) removeNode(parent, removed); | ||
replacement && insertNode(parent, replacement); | ||
@@ -182,3 +194,5 @@ return ""; | ||
const isParent = getParentNode(el) === parent; | ||
if (!inserted && !i) isParent ? replaceNode(parent, node, el) : insertNode(parent, node, marker);else isParent && removeNode(parent, el); | ||
if (!inserted && !i) | ||
isParent ? replaceNode(parent, node, el) : insertNode(parent, node, marker); | ||
else isParent && removeNode(parent, el); | ||
} else inserted = true; | ||
@@ -199,3 +213,5 @@ } | ||
if (!skipChildren) { | ||
createRenderEffect(() => prevProps.children = insertExpression(node, props.children, prevProps.children)); | ||
createRenderEffect( | ||
() => (prevProps.children = insertExpression(node, props.children, prevProps.children)) | ||
); | ||
} | ||
@@ -202,0 +218,0 @@ createRenderEffect(() => props.ref && props.ref(node)); |
import type { RendererOptions, Renderer } from "./universal.js"; | ||
export declare function createRenderer<NodeType>(options: RendererOptions<NodeType>): Renderer<NodeType>; | ||
export declare function createRenderer<NodeType>( | ||
options: RendererOptions<NodeType> | ||
): Renderer<NodeType>; |
@@ -30,2 +30,1 @@ export interface RendererOptions<NodeType> { | ||
export function createRenderer<NodeType>(options: RendererOptions<NodeType>): Renderer<NodeType>; | ||
@@ -1,12 +0,81 @@ | ||
import { createRoot, sharedConfig, createRenderEffect, untrack, enableHydration, getOwner, createEffect, runWithOwner, createMemo, createSignal, onCleanup, splitProps, $DEVCOMP } from 'solid-js'; | ||
export { ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, createComponent, createRenderEffect as effect, getOwner, createMemo as memo, mergeProps, untrack } from 'solid-js'; | ||
import { | ||
createRoot, | ||
sharedConfig, | ||
createRenderEffect, | ||
untrack, | ||
enableHydration, | ||
getOwner, | ||
createEffect, | ||
runWithOwner, | ||
createMemo, | ||
createSignal, | ||
onCleanup, | ||
splitProps, | ||
$DEVCOMP | ||
} from "solid-js"; | ||
export { | ||
ErrorBoundary, | ||
For, | ||
Index, | ||
Match, | ||
Show, | ||
Suspense, | ||
SuspenseList, | ||
Switch, | ||
createComponent, | ||
createRenderEffect as effect, | ||
getOwner, | ||
createMemo as memo, | ||
mergeProps, | ||
untrack | ||
} from "solid-js"; | ||
const booleans = ["allowfullscreen", "async", "autofocus", "autoplay", "checked", "controls", "default", "disabled", "formnovalidate", "hidden", "indeterminate", "ismap", "loop", "multiple", "muted", "nomodule", "novalidate", "open", "playsinline", "readonly", "required", "reversed", "seamless", "selected"]; | ||
const Properties = /*#__PURE__*/new Set(["className", "value", "readOnly", "formNoValidate", "isMap", "noModule", "playsInline", ...booleans]); | ||
const ChildProperties = /*#__PURE__*/new Set(["innerHTML", "textContent", "innerText", "children"]); | ||
const Aliases = /*#__PURE__*/Object.assign(Object.create(null), { | ||
const booleans = [ | ||
"allowfullscreen", | ||
"async", | ||
"autofocus", | ||
"autoplay", | ||
"checked", | ||
"controls", | ||
"default", | ||
"disabled", | ||
"formnovalidate", | ||
"hidden", | ||
"indeterminate", | ||
"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,106 @@ formnovalidate: { | ||
const a = PropAliases[prop]; | ||
return typeof a === "object" ? a[tagName] ? a["$"] : undefined : a; | ||
return typeof a === "object" ? (a[tagName] ? a["$"] : undefined) : a; | ||
} | ||
const DelegatedEvents = /*#__PURE__*/new Set(["beforeinput", "click", "dblclick", "contextmenu", "focusin", "focusout", "input", "keydown", "keyup", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup", "pointerdown", "pointermove", "pointerout", "pointerover", "pointerup", "touchend", "touchmove", "touchstart"]); | ||
const SVGElements = /*#__PURE__*/new Set([ | ||
"altGlyph", "altGlyphDef", "altGlyphItem", "animate", "animateColor", "animateMotion", "animateTransform", "circle", "clipPath", "color-profile", "cursor", "defs", "desc", "ellipse", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence", "filter", "font", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "foreignObject", "g", "glyph", "glyphRef", "hkern", "image", "line", "linearGradient", "marker", "mask", "metadata", "missing-glyph", "mpath", "path", "pattern", "polygon", "polyline", "radialGradient", "rect", | ||
"set", "stop", | ||
"svg", "switch", "symbol", "text", "textPath", | ||
"tref", "tspan", "use", "view", "vkern"]); | ||
const DelegatedEvents = /*#__PURE__*/ new Set([ | ||
"beforeinput", | ||
"click", | ||
"dblclick", | ||
"contextmenu", | ||
"focusin", | ||
"focusout", | ||
"input", | ||
"keydown", | ||
"keyup", | ||
"mousedown", | ||
"mousemove", | ||
"mouseout", | ||
"mouseover", | ||
"mouseup", | ||
"pointerdown", | ||
"pointermove", | ||
"pointerout", | ||
"pointerover", | ||
"pointerup", | ||
"touchend", | ||
"touchmove", | ||
"touchstart" | ||
]); | ||
const SVGElements = /*#__PURE__*/ new Set([ | ||
"altGlyph", | ||
"altGlyphDef", | ||
"altGlyphItem", | ||
"animate", | ||
"animateColor", | ||
"animateMotion", | ||
"animateTransform", | ||
"circle", | ||
"clipPath", | ||
"color-profile", | ||
"cursor", | ||
"defs", | ||
"desc", | ||
"ellipse", | ||
"feBlend", | ||
"feColorMatrix", | ||
"feComponentTransfer", | ||
"feComposite", | ||
"feConvolveMatrix", | ||
"feDiffuseLighting", | ||
"feDisplacementMap", | ||
"feDistantLight", | ||
"feFlood", | ||
"feFuncA", | ||
"feFuncB", | ||
"feFuncG", | ||
"feFuncR", | ||
"feGaussianBlur", | ||
"feImage", | ||
"feMerge", | ||
"feMergeNode", | ||
"feMorphology", | ||
"feOffset", | ||
"fePointLight", | ||
"feSpecularLighting", | ||
"feSpotLight", | ||
"feTile", | ||
"feTurbulence", | ||
"filter", | ||
"font", | ||
"font-face", | ||
"font-face-format", | ||
"font-face-name", | ||
"font-face-src", | ||
"font-face-uri", | ||
"foreignObject", | ||
"g", | ||
"glyph", | ||
"glyphRef", | ||
"hkern", | ||
"image", | ||
"line", | ||
"linearGradient", | ||
"marker", | ||
"mask", | ||
"metadata", | ||
"missing-glyph", | ||
"mpath", | ||
"path", | ||
"pattern", | ||
"polygon", | ||
"polyline", | ||
"radialGradient", | ||
"rect", | ||
"set", | ||
"stop", | ||
"svg", | ||
"switch", | ||
"symbol", | ||
"text", | ||
"textPath", | ||
"tref", | ||
"tspan", | ||
"use", | ||
"view", | ||
"vkern" | ||
]); | ||
const SVGNamespace = { | ||
@@ -51,3 +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); | ||
@@ -128,3 +575,6 @@ return () => { | ||
const create = () => { | ||
if (sharedConfig.context) throw new Error("Failed attempt to create new DOM elements during hydration. Check that the libraries you are using support hydration."); | ||
if (sharedConfig.context) | ||
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"); | ||
@@ -134,3 +584,5 @@ t.innerHTML = html; | ||
}; | ||
const fn = isCE ? () => untrack(() => document.importNode(node || (node = create()), true)) : () => (node || (node = create())).cloneNode(true); | ||
const fn = isCE | ||
? () => untrack(() => document.importNode(node || (node = create()), true)) | ||
: () => (node || (node = create())).cloneNode(true); | ||
fn.cloneNode = fn; | ||
@@ -160,11 +612,14 @@ return fn; | ||
if (sharedConfig.context) 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 (sharedConfig.context) 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); | ||
} | ||
function className(node, value) { | ||
if (sharedConfig.context) return; | ||
if (value == null) node.removeAttribute("class");else node.className = value; | ||
if (value == null) node.removeAttribute("class"); | ||
else node.className = value; | ||
} | ||
@@ -179,3 +634,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); | ||
@@ -205,3 +660,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); | ||
@@ -227,3 +682,5 @@ prev || (prev = {}); | ||
if (!skipChildren) { | ||
createRenderEffect(() => prevProps.children = insertExpression(node, props.children, prevProps.children)); | ||
createRenderEffect( | ||
() => (prevProps.children = insertExpression(node, props.children, prevProps.children)) | ||
); | ||
} | ||
@@ -287,4 +744,5 @@ createRenderEffect(() => props.ref && props.ref(node)); | ||
let node, key; | ||
if (!sharedConfig.context || !(node = sharedConfig.registry.get(key = getHydrationKey()))) { | ||
if (sharedConfig.context) throw new Error(`Hydration Mismatch. Unable to find DOM nodes for hydration key: ${key}`); | ||
if (!sharedConfig.context || !(node = sharedConfig.registry.get((key = getHydrationKey())))) { | ||
if (sharedConfig.context) | ||
throw new Error(`Hydration Mismatch. Unable to find DOM nodes for hydration key: ${key}`); | ||
return template(); | ||
@@ -308,3 +766,4 @@ } | ||
const v = end.nodeValue; | ||
if (v === "$") count++;else if (v === "/") { | ||
if (v === "$") count++; | ||
else if (v === "/") { | ||
if (count === 0) return [end, current]; | ||
@@ -323,6 +782,3 @@ count--; | ||
queueMicrotask(() => { | ||
const { | ||
completed, | ||
events | ||
} = sharedConfig; | ||
const { completed, events } = sharedConfig; | ||
events.queued = false; | ||
@@ -344,3 +800,4 @@ while (events.length) { | ||
const classNames = key.trim().split(/\s+/); | ||
for (let i = 0, nameLen = classNames.length; i < nameLen; i++) node.classList.toggle(classNames[i], value); | ||
for (let i = 0, nameLen = classNames.length; i < nameLen; i++) | ||
node.classList.toggle(classNames[i], value); | ||
} | ||
@@ -375,3 +832,9 @@ function assignProp(node, prop, value, prev, isSVG, skipRef) { | ||
setAttribute(node, prop.slice(5), value); | ||
} else if ((forceProp = prop.slice(0, 5) === "prop:") || (isChildProp = ChildProperties.has(prop)) || !isSVG && ((propAlias = getPropAlias(prop, node.tagName)) || (isProp = Properties.has(prop))) || (isCE = node.nodeName.includes("-"))) { | ||
} else if ( | ||
(forceProp = prop.slice(0, 5) === "prop:") || | ||
(isChildProp = ChildProperties.has(prop)) || | ||
(!isSVG && | ||
((propAlias = getPropAlias(prop, node.tagName)) || (isProp = Properties.has(prop)))) || | ||
(isCE = node.nodeName.includes("-")) | ||
) { | ||
if (forceProp) { | ||
@@ -381,6 +844,9 @@ prop = prop.slice(5); | ||
} else if (sharedConfig.context) 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); | ||
} | ||
@@ -391,3 +857,3 @@ return value; | ||
const key = `$$${e.type}`; | ||
let node = e.composedPath && e.composedPath()[0] || e.target; | ||
let node = (e.composedPath && e.composedPath()[0]) || e.target; | ||
if (e.target !== node) { | ||
@@ -422,3 +888,4 @@ Object.defineProperty(e, "target", { | ||
const node = current[i]; | ||
if (node.nodeType === 8 && node.data.slice(0, 2) === "!$") node.remove();else cleaned.push(node); | ||
if (node.nodeType === 8 && node.data.slice(0, 2) === "!$") node.remove(); | ||
else cleaned.push(node); | ||
} | ||
@@ -431,3 +898,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") { | ||
@@ -461,3 +928,3 @@ if (sharedConfig.context) return current; | ||
if (normalizeIncomingArray(array, value, current, unwrapArray)) { | ||
createRenderEffect(() => current = insertExpression(parent, array, current, marker, true)); | ||
createRenderEffect(() => (current = insertExpression(parent, array, current, marker, true))); | ||
return () => current; | ||
@@ -471,3 +938,3 @@ } | ||
while ((node = node.nextSibling) !== marker) nodes.push(node); | ||
return current = nodes; | ||
return (current = nodes); | ||
} | ||
@@ -487,5 +954,5 @@ if (array.length === 0) { | ||
} else if (value.nodeType) { | ||
if (sharedConfig.context && value.parentNode) return current = multi ? [value] : value; | ||
if (sharedConfig.context && value.parentNode) return (current = multi ? [value] : value); | ||
if (Array.isArray(current)) { | ||
if (multi) return current = cleanChildren(parent, current, marker, value); | ||
if (multi) return (current = cleanChildren(parent, current, marker, value)); | ||
cleanChildren(parent, current, null, value); | ||
@@ -505,3 +972,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); | ||
@@ -513,3 +981,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 { | ||
@@ -521,3 +994,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)); | ||
} | ||
@@ -531,3 +1005,3 @@ } | ||
function cleanChildren(parent, current, marker, replacement) { | ||
if (marker === undefined) return parent.textContent = ""; | ||
if (marker === undefined) return (parent.textContent = ""); | ||
const node = replacement || document.createTextNode(""); | ||
@@ -540,3 +1014,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; | ||
@@ -552,3 +1028,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); | ||
} | ||
@@ -606,5 +1083,3 @@ } | ||
function Portal(props) { | ||
const { | ||
useShadow | ||
} = props, | ||
const { useShadow } = props, | ||
marker = document.createTextNode(""), | ||
@@ -615,30 +1090,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; | ||
@@ -666,2 +1148,59 @@ } | ||
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, 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, | ||
setProperty, | ||
spread, | ||
ssr, | ||
ssrAttribute, | ||
ssrClassList, | ||
ssrElement, | ||
ssrHydrationKey, | ||
ssrSpread, | ||
ssrStyle, | ||
style, | ||
template, | ||
use, | ||
voidFn as useAssets | ||
}; |
@@ -1,9 +0,51 @@ | ||
import { sharedConfig, createRoot, splitProps } from 'solid-js'; | ||
export { ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, createComponent, mergeProps } from 'solid-js'; | ||
import { Feature, Serializer, GLOBAL_CONTEXT_API_SCRIPT, getCrossReferenceHeader } from 'seroval'; | ||
import { sharedConfig, createRoot, splitProps } from "solid-js"; | ||
export { | ||
ErrorBoundary, | ||
For, | ||
Index, | ||
Match, | ||
Show, | ||
Suspense, | ||
SuspenseList, | ||
Switch, | ||
createComponent, | ||
mergeProps | ||
} from "solid-js"; | ||
import { Feature, Serializer, getCrossReferenceHeader } from "seroval"; | ||
const booleans = ["allowfullscreen", "async", "autofocus", "autoplay", "checked", "controls", "default", "disabled", "formnovalidate", "hidden", "indeterminate", "ismap", "loop", "multiple", "muted", "nomodule", "novalidate", "open", "playsinline", "readonly", "required", "reversed", "seamless", "selected"]; | ||
const BooleanAttributes = /*#__PURE__*/new Set(booleans); | ||
const ChildProperties = /*#__PURE__*/new Set(["innerHTML", "textContent", "innerText", "children"]); | ||
const Aliases = /*#__PURE__*/Object.assign(Object.create(null), { | ||
const booleans = [ | ||
"allowfullscreen", | ||
"async", | ||
"autofocus", | ||
"autoplay", | ||
"checked", | ||
"controls", | ||
"default", | ||
"disabled", | ||
"formnovalidate", | ||
"hidden", | ||
"indeterminate", | ||
"inert", | ||
"ismap", | ||
"loop", | ||
"multiple", | ||
"muted", | ||
"nomodule", | ||
"novalidate", | ||
"open", | ||
"playsinline", | ||
"readonly", | ||
"required", | ||
"reversed", | ||
"seamless", | ||
"selected" | ||
]; | ||
const BooleanAttributes = /*#__PURE__*/ new Set(booleans); | ||
const ChildProperties = /*#__PURE__*/ new Set([ | ||
"innerHTML", | ||
"textContent", | ||
"innerText", | ||
"children" | ||
]); | ||
const Aliases = /*#__PURE__*/ Object.assign(Object.create(null), { | ||
className: "class", | ||
@@ -13,12 +55,5 @@ htmlFor: "for" | ||
const ES2017FLAG = Feature.AggregateError | ||
| Feature.BigInt | ||
| Feature.BigIntTypedArray; | ||
const GLOBAL_IDENTIFIER = '_$HY.r'; | ||
function createSerializer({ | ||
onData, | ||
onDone, | ||
scopeId, | ||
onError | ||
}) { | ||
const ES2017FLAG = Feature.AggregateError | Feature.BigInt | Feature.BigIntTypedArray; | ||
const GLOBAL_IDENTIFIER = "_$HY.r"; | ||
function createSerializer({ onData, onDone, scopeId, onError }) { | ||
return new Serializer({ | ||
@@ -33,5 +68,2 @@ scopeId, | ||
} | ||
function getGlobalHeaderScript() { | ||
return GLOBAL_CONTEXT_API_SCRIPT; | ||
} | ||
function getLocalHeaderScript(id) { | ||
@@ -41,8 +73,7 @@ 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 = ""; | ||
@@ -68,2 +99,8 @@ const serializer = createSerializer({ | ||
!sharedConfig.context.noHydrate && serializer.write(id, p); | ||
}, | ||
pushed: 0, | ||
push(p) { | ||
const id = this.renderId + "i-" + this.pushed++; | ||
this.serialize(id, p); | ||
return id; | ||
} | ||
@@ -82,5 +119,3 @@ }; | ||
function renderToStringAsync(code, options = {}) { | ||
const { | ||
timeoutMs = 30000 | ||
} = options; | ||
const { timeoutMs = 30000 } = options; | ||
let timeoutHandle; | ||
@@ -96,9 +131,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; | ||
@@ -119,7 +148,8 @@ const blockingPromises = []; | ||
writeTasks(); | ||
onCompleteAll && onCompleteAll({ | ||
write(v) { | ||
!completed && buffer.write(v); | ||
} | ||
}); | ||
onCompleteAll && | ||
onCompleteAll({ | ||
write(v) { | ||
!completed && buffer.write(v); | ||
} | ||
}); | ||
writable && writable.end(); | ||
@@ -181,3 +211,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()) | ||
); | ||
}, | ||
@@ -188,16 +221,25 @@ 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); | ||
}, | ||
pushed: 0, | ||
push(p) { | ||
const id = this.renderId + "i-" + this.pushed++; | ||
this.serialize(id, p); | ||
return id; | ||
}, | ||
registerFragment(key) { | ||
if (!registry.has(key)) { | ||
let resolve, reject; | ||
const p = new Promise((r, rej) => (resolve = r, reject = rej)); | ||
const p = new Promise((r, rej) => ((resolve = r), (reject = rej))); | ||
registry.set(key, { | ||
resolve, | ||
reject | ||
resolve: v => queue(() => queue(() => resolve(v))), | ||
reject: e => queue(() => queue(() => reject(e))) | ||
}); | ||
@@ -208,6 +250,3 @@ serializer.write(key, p); | ||
if (registry.has(key)) { | ||
const { | ||
resolve, | ||
reject | ||
} = registry.get(key); | ||
const { resolve, reject } = registry.get(key); | ||
registry.delete(key); | ||
@@ -220,3 +259,3 @@ if (waitForFragments(registry, key)) { | ||
if (!firstFlushed) { | ||
Promise.resolve().then(() => html = replacePlaceholder(html, key, value !== undefined ? value : "")); | ||
queue(() => (html = replacePlaceholder(html, key, value !== undefined ? value : ""))); | ||
error ? reject(error) : resolve(true); | ||
@@ -231,3 +270,3 @@ } else { | ||
} | ||
if (!registry.size) Promise.resolve().then(flushEnd); | ||
if (!registry.size) queue(flushEnd); | ||
return firstFlushed; | ||
@@ -248,7 +287,8 @@ }; | ||
tasks = ""; | ||
onCompleteShell && onCompleteShell({ | ||
write(v) { | ||
!completed && buffer.write(v); | ||
} | ||
}); | ||
onCompleteShell && | ||
onCompleteShell({ | ||
write(v) { | ||
!completed && buffer.write(v); | ||
} | ||
}); | ||
} | ||
@@ -268,3 +308,3 @@ return { | ||
} else onCompleteAll = complete; | ||
if (!registry.size) Promise.resolve().then(flushEnd); | ||
if (!registry.size) queue(flushEnd); | ||
}, | ||
@@ -277,3 +317,4 @@ pipe(w) { | ||
firstFlushed = true; | ||
if (completed) writable.end();else setTimeout(flushEnd); | ||
if (completed) writable.end(); | ||
else setTimeout(flushEnd); | ||
}); | ||
@@ -287,3 +328,3 @@ }, | ||
let resolve; | ||
const p = new Promise(r => resolve = r); | ||
const p = new Promise(r => (resolve = r)); | ||
writable = { | ||
@@ -303,3 +344,4 @@ end() { | ||
firstFlushed = true; | ||
if (completed) writable.end();else setTimeout(flushEnd); | ||
if (completed) writable.end(); | ||
else setTimeout(flushEnd); | ||
return p; | ||
@@ -311,9 +353,9 @@ }); | ||
function HydrationScript(props) { | ||
const { | ||
nonce | ||
} = sharedConfig.context; | ||
return ssr(generateHydrationScript({ | ||
nonce, | ||
...props | ||
})); | ||
const { nonce } = sharedConfig.context; | ||
return ssr( | ||
generateHydrationScript({ | ||
nonce, | ||
...props | ||
}) | ||
); | ||
} | ||
@@ -363,3 +405,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); | ||
@@ -372,3 +415,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; | ||
@@ -382,6 +426,10 @@ } | ||
let n; | ||
result += `class="${escape(((n = props.class) ? n + " " : "") + ((n = props.className) ? n + " " : ""), true) + ssrClassList(props.classList)}"`; | ||
result += `class="${ | ||
escape(((n = props.class) ? n + " " : "") + ((n = props.className) ? n + " " : ""), true) + | ||
ssrClassList(props.classList) | ||
}"`; | ||
classResolved = true; | ||
} else if (BooleanAttributes.has(prop)) { | ||
if (value) result += prop;else continue; | ||
if (value) result += prop; | ||
else continue; | ||
} else if (value == undefined || prop === "ref" || prop.slice(0, 2) === "on") { | ||
@@ -394,5 +442,6 @@ continue; | ||
} | ||
if (skipChildren) return { | ||
t: result + "/>" | ||
}; | ||
if (skipChildren) | ||
return { | ||
t: result + "/>" | ||
}; | ||
if (typeof children === "function") children = children(); | ||
@@ -404,3 +453,3 @@ return { | ||
function ssrAttribute(key, value, isBoolean) { | ||
return isBoolean ? value ? " " + key : "" : value != null ? ` ${key}="${value}"` : ""; | ||
return isBoolean ? (value ? " " + key : "") : value != null ? ` ${key}="${value}"` : ""; | ||
} | ||
@@ -449,8 +498,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; | ||
@@ -467,3 +517,3 @@ } | ||
if (!top && typeof prev !== "object" && typeof node[i] !== "object") mapped += `<!--!$-->`; | ||
mapped += resolveSSRNode(prev = node[i]); | ||
mapped += resolveSSRNode((prev = node[i])); | ||
} | ||
@@ -489,7 +539,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=>{let a=o.composedPath&&o.composedPath()[0]||o.target,s=t(a);s&&!e.completed.has(s)&&e.events.push([s,o])}))))})(_$HY={events:[],completed:new WeakSet,r:{},fe(){}});${getGlobalHeaderScript()}</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=>{let a=o.composedPath&&o.composedPath()[0]||o.target,s=t(a);s&&!e.completed.has(s)&&e.events.push([s,o])}))))})(_$HY={events:[],completed:new WeakSet,r:{},fe(){}});</script><!--xs-->`; | ||
} | ||
@@ -513,2 +564,5 @@ function Hydration(props) { | ||
} | ||
function queue(fn) { | ||
return Promise.resolve().then(fn); | ||
} | ||
function injectAssets(assets, html) { | ||
@@ -551,5 +605,3 @@ if (!assets || !assets.length) return html; | ||
if (options.onReady) { | ||
options.onCompleteShell = ({ | ||
write | ||
}) => { | ||
options.onCompleteShell = ({ write }) => { | ||
options.onReady({ | ||
@@ -568,5 +620,3 @@ write, | ||
if (options.onReady) { | ||
options.onCompleteShell = ({ | ||
write | ||
}) => { | ||
options.onCompleteShell = ({ write }) => { | ||
options.onReady({ | ||
@@ -601,7 +651,15 @@ write, | ||
let n; | ||
result += `class="${(n = props.class) ? n + " " : ""}${(n = props.className) ? n + " " : ""}${ssrClassList(props.classList)}"`; | ||
result += `class="${(n = props.class) ? n + " " : ""}${ | ||
(n = props.className) ? n + " " : "" | ||
}${ssrClassList(props.classList)}"`; | ||
classResolved = true; | ||
} else if (BooleanAttributes.has(prop)) { | ||
if (value) result += prop;else continue; | ||
} else if (value == undefined || prop === "ref" || prop.slice(0, 2) === "on" || prop.slice(0, 5) === "prop:") { | ||
if (value) result += prop; | ||
else continue; | ||
} else if ( | ||
value == undefined || | ||
prop === "ref" || | ||
prop.slice(0, 2) === "on" || | ||
prop.slice(0, 5) === "prop:" | ||
) { | ||
continue; | ||
@@ -630,3 +688,4 @@ } else { | ||
if (comp) { | ||
if (t === "function") return comp(others);else if (t === "string") { | ||
if (t === "function") return comp(others); | ||
else if (t === "string") { | ||
return ssrElement(comp, others, undefined, true); | ||
@@ -640,2 +699,37 @@ } | ||
export { Assets, Dynamic, Hydration, HydrationScript, NoHydration, Portal, RequestContext, addEventListener, delegateEvents, escape, generateHydrationScript, getAssets, getHydrationKey, getRequestEvent, hydrate, insert, isDev, isServer, pipeToNodeWritable, pipeToWritable, render, renderToStream, renderToString, renderToStringAsync, resolveSSRNode, spread, ssr, ssrAttribute, ssrClassList, ssrElement, ssrHydrationKey, ssrSpread, ssrStyle, useAssets }; | ||
export { | ||
Assets, | ||
Dynamic, | ||
Hydration, | ||
HydrationScript, | ||
NoHydration, | ||
Portal, | ||
RequestContext, | ||
addEventListener, | ||
delegateEvents, | ||
escape, | ||
generateHydrationScript, | ||
getAssets, | ||
getHydrationKey, | ||
getRequestEvent, | ||
hydrate, | ||
insert, | ||
isDev, | ||
isServer, | ||
pipeToNodeWritable, | ||
pipeToWritable, | ||
render, | ||
renderToStream, | ||
renderToString, | ||
renderToStringAsync, | ||
resolveSSRNode, | ||
spread, | ||
ssr, | ||
ssrAttribute, | ||
ssrClassList, | ||
ssrElement, | ||
ssrHydrationKey, | ||
ssrSpread, | ||
ssrStyle, | ||
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 @@ } |
@@ -1,12 +0,80 @@ | ||
import { createRoot, sharedConfig, createRenderEffect, untrack, 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, | ||
sharedConfig, | ||
createRenderEffect, | ||
untrack, | ||
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", "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,106 @@ formnovalidate: { | ||
const a = PropAliases[prop]; | ||
return typeof a === "object" ? a[tagName] ? a["$"] : undefined : a; | ||
return typeof a === "object" ? (a[tagName] ? a["$"] : undefined) : a; | ||
} | ||
const DelegatedEvents = /*#__PURE__*/new Set(["beforeinput", "click", "dblclick", "contextmenu", "focusin", "focusout", "input", "keydown", "keyup", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup", "pointerdown", "pointermove", "pointerout", "pointerover", "pointerup", "touchend", "touchmove", "touchstart"]); | ||
const SVGElements = /*#__PURE__*/new Set([ | ||
"altGlyph", "altGlyphDef", "altGlyphItem", "animate", "animateColor", "animateMotion", "animateTransform", "circle", "clipPath", "color-profile", "cursor", "defs", "desc", "ellipse", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence", "filter", "font", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "foreignObject", "g", "glyph", "glyphRef", "hkern", "image", "line", "linearGradient", "marker", "mask", "metadata", "missing-glyph", "mpath", "path", "pattern", "polygon", "polyline", "radialGradient", "rect", | ||
"set", "stop", | ||
"svg", "switch", "symbol", "text", "textPath", | ||
"tref", "tspan", "use", "view", "vkern"]); | ||
const DelegatedEvents = /*#__PURE__*/ new Set([ | ||
"beforeinput", | ||
"click", | ||
"dblclick", | ||
"contextmenu", | ||
"focusin", | ||
"focusout", | ||
"input", | ||
"keydown", | ||
"keyup", | ||
"mousedown", | ||
"mousemove", | ||
"mouseout", | ||
"mouseover", | ||
"mouseup", | ||
"pointerdown", | ||
"pointermove", | ||
"pointerout", | ||
"pointerover", | ||
"pointerup", | ||
"touchend", | ||
"touchmove", | ||
"touchstart" | ||
]); | ||
const SVGElements = /*#__PURE__*/ new Set([ | ||
"altGlyph", | ||
"altGlyphDef", | ||
"altGlyphItem", | ||
"animate", | ||
"animateColor", | ||
"animateMotion", | ||
"animateTransform", | ||
"circle", | ||
"clipPath", | ||
"color-profile", | ||
"cursor", | ||
"defs", | ||
"desc", | ||
"ellipse", | ||
"feBlend", | ||
"feColorMatrix", | ||
"feComponentTransfer", | ||
"feComposite", | ||
"feConvolveMatrix", | ||
"feDiffuseLighting", | ||
"feDisplacementMap", | ||
"feDistantLight", | ||
"feFlood", | ||
"feFuncA", | ||
"feFuncB", | ||
"feFuncG", | ||
"feFuncR", | ||
"feGaussianBlur", | ||
"feImage", | ||
"feMerge", | ||
"feMergeNode", | ||
"feMorphology", | ||
"feOffset", | ||
"fePointLight", | ||
"feSpecularLighting", | ||
"feSpotLight", | ||
"feTile", | ||
"feTurbulence", | ||
"filter", | ||
"font", | ||
"font-face", | ||
"font-face-format", | ||
"font-face-name", | ||
"font-face-src", | ||
"font-face-uri", | ||
"foreignObject", | ||
"g", | ||
"glyph", | ||
"glyphRef", | ||
"hkern", | ||
"image", | ||
"line", | ||
"linearGradient", | ||
"marker", | ||
"mask", | ||
"metadata", | ||
"missing-glyph", | ||
"mpath", | ||
"path", | ||
"pattern", | ||
"polygon", | ||
"polyline", | ||
"radialGradient", | ||
"rect", | ||
"set", | ||
"stop", | ||
"svg", | ||
"switch", | ||
"symbol", | ||
"text", | ||
"textPath", | ||
"tref", | ||
"tspan", | ||
"use", | ||
"view", | ||
"vkern" | ||
]); | ||
const SVGNamespace = { | ||
@@ -51,3 +215,283 @@ xlink: "http://www.w3.org/1999/xlink", | ||
}; | ||
const DOMElements = /*#__PURE__*/new Set(["html", "base", "head", "link", "meta", "style", "title", "body", "address", "article", "aside", "footer", "header", "main", "nav", "section", "body", "blockquote", "dd", "div", "dl", "dt", "figcaption", "figure", "hr", "li", "ol", "p", "pre", "ul", "a", "abbr", "b", "bdi", "bdo", "br", "cite", "code", "data", "dfn", "em", "i", "kbd", "mark", "q", "rp", "rt", "ruby", "s", "samp", "small", "span", "strong", "sub", "sup", "time", "u", "var", "wbr", "area", "audio", "img", "map", "track", "video", "embed", "iframe", "object", "param", "picture", "portal", "source", "svg", "math", "canvas", "noscript", "script", "del", "ins", "caption", "col", "colgroup", "table", "tbody", "td", "tfoot", "th", "thead", "tr", "button", "datalist", "fieldset", "form", "input", "label", "legend", "meter", "optgroup", "option", "output", "progress", "select", "textarea", "details", "dialog", "menu", "summary", "details", "slot", "template", "acronym", "applet", "basefont", "bgsound", "big", "blink", "center", "content", "dir", "font", "frame", "frameset", "hgroup", "image", "keygen", "marquee", "menuitem", "nobr", "noembed", "noframes", "plaintext", "rb", "rtc", "shadow", "spacer", "strike", "tt", "xmp", "a", "abbr", "acronym", "address", "applet", "area", "article", "aside", "audio", "b", "base", "basefont", "bdi", "bdo", "bgsound", "big", "blink", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "content", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "font", "footer", "form", "frame", "frameset", "head", "header", "hgroup", "hr", "html", "i", "iframe", "image", "img", "input", "ins", "kbd", "keygen", "label", "legend", "li", "link", "main", "map", "mark", "marquee", "menu", "menuitem", "meta", "meter", "nav", "nobr", "noembed", "noframes", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "picture", "plaintext", "portal", "pre", "progress", "q", "rb", "rp", "rt", "rtc", "ruby", "s", "samp", "script", "section", "select", "shadow", "slot", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "tt", "u", "ul", "var", "video", "wbr", "xmp", "input", "h1", "h2", "h3", "h4", "h5", "h6"]); | ||
const DOMElements = /*#__PURE__*/ new Set([ | ||
"html", | ||
"base", | ||
"head", | ||
"link", | ||
"meta", | ||
"style", | ||
"title", | ||
"body", | ||
"address", | ||
"article", | ||
"aside", | ||
"footer", | ||
"header", | ||
"main", | ||
"nav", | ||
"section", | ||
"body", | ||
"blockquote", | ||
"dd", | ||
"div", | ||
"dl", | ||
"dt", | ||
"figcaption", | ||
"figure", | ||
"hr", | ||
"li", | ||
"ol", | ||
"p", | ||
"pre", | ||
"ul", | ||
"a", | ||
"abbr", | ||
"b", | ||
"bdi", | ||
"bdo", | ||
"br", | ||
"cite", | ||
"code", | ||
"data", | ||
"dfn", | ||
"em", | ||
"i", | ||
"kbd", | ||
"mark", | ||
"q", | ||
"rp", | ||
"rt", | ||
"ruby", | ||
"s", | ||
"samp", | ||
"small", | ||
"span", | ||
"strong", | ||
"sub", | ||
"sup", | ||
"time", | ||
"u", | ||
"var", | ||
"wbr", | ||
"area", | ||
"audio", | ||
"img", | ||
"map", | ||
"track", | ||
"video", | ||
"embed", | ||
"iframe", | ||
"object", | ||
"param", | ||
"picture", | ||
"portal", | ||
"source", | ||
"svg", | ||
"math", | ||
"canvas", | ||
"noscript", | ||
"script", | ||
"del", | ||
"ins", | ||
"caption", | ||
"col", | ||
"colgroup", | ||
"table", | ||
"tbody", | ||
"td", | ||
"tfoot", | ||
"th", | ||
"thead", | ||
"tr", | ||
"button", | ||
"datalist", | ||
"fieldset", | ||
"form", | ||
"input", | ||
"label", | ||
"legend", | ||
"meter", | ||
"optgroup", | ||
"option", | ||
"output", | ||
"progress", | ||
"select", | ||
"textarea", | ||
"details", | ||
"dialog", | ||
"menu", | ||
"summary", | ||
"details", | ||
"slot", | ||
"template", | ||
"acronym", | ||
"applet", | ||
"basefont", | ||
"bgsound", | ||
"big", | ||
"blink", | ||
"center", | ||
"content", | ||
"dir", | ||
"font", | ||
"frame", | ||
"frameset", | ||
"hgroup", | ||
"image", | ||
"keygen", | ||
"marquee", | ||
"menuitem", | ||
"nobr", | ||
"noembed", | ||
"noframes", | ||
"plaintext", | ||
"rb", | ||
"rtc", | ||
"shadow", | ||
"spacer", | ||
"strike", | ||
"tt", | ||
"xmp", | ||
"a", | ||
"abbr", | ||
"acronym", | ||
"address", | ||
"applet", | ||
"area", | ||
"article", | ||
"aside", | ||
"audio", | ||
"b", | ||
"base", | ||
"basefont", | ||
"bdi", | ||
"bdo", | ||
"bgsound", | ||
"big", | ||
"blink", | ||
"blockquote", | ||
"body", | ||
"br", | ||
"button", | ||
"canvas", | ||
"caption", | ||
"center", | ||
"cite", | ||
"code", | ||
"col", | ||
"colgroup", | ||
"content", | ||
"data", | ||
"datalist", | ||
"dd", | ||
"del", | ||
"details", | ||
"dfn", | ||
"dialog", | ||
"dir", | ||
"div", | ||
"dl", | ||
"dt", | ||
"em", | ||
"embed", | ||
"fieldset", | ||
"figcaption", | ||
"figure", | ||
"font", | ||
"footer", | ||
"form", | ||
"frame", | ||
"frameset", | ||
"head", | ||
"header", | ||
"hgroup", | ||
"hr", | ||
"html", | ||
"i", | ||
"iframe", | ||
"image", | ||
"img", | ||
"input", | ||
"ins", | ||
"kbd", | ||
"keygen", | ||
"label", | ||
"legend", | ||
"li", | ||
"link", | ||
"main", | ||
"map", | ||
"mark", | ||
"marquee", | ||
"menu", | ||
"menuitem", | ||
"meta", | ||
"meter", | ||
"nav", | ||
"nobr", | ||
"noembed", | ||
"noframes", | ||
"noscript", | ||
"object", | ||
"ol", | ||
"optgroup", | ||
"option", | ||
"output", | ||
"p", | ||
"param", | ||
"picture", | ||
"plaintext", | ||
"portal", | ||
"pre", | ||
"progress", | ||
"q", | ||
"rb", | ||
"rp", | ||
"rt", | ||
"rtc", | ||
"ruby", | ||
"s", | ||
"samp", | ||
"script", | ||
"section", | ||
"select", | ||
"shadow", | ||
"slot", | ||
"small", | ||
"source", | ||
"spacer", | ||
"span", | ||
"strike", | ||
"strong", | ||
"style", | ||
"sub", | ||
"summary", | ||
"sup", | ||
"table", | ||
"tbody", | ||
"td", | ||
"template", | ||
"textarea", | ||
"tfoot", | ||
"th", | ||
"thead", | ||
"time", | ||
"title", | ||
"tr", | ||
"track", | ||
"tt", | ||
"u", | ||
"ul", | ||
"var", | ||
"video", | ||
"wbr", | ||
"xmp", | ||
"input", | ||
"h1", | ||
"h2", | ||
"h3", | ||
"h4", | ||
"h5", | ||
"h6" | ||
]); | ||
@@ -73,3 +517,3 @@ function reconcileArrays(parentNode, a, b) { | ||
if (aEnd === aStart) { | ||
const node = bEnd < bLength ? bStart ? b[bStart - 1].nextSibling : b[bEnd - bStart] : after; | ||
const node = bEnd < bLength ? (bStart ? b[bStart - 1].nextSibling : b[bEnd - bStart]) : after; | ||
while (bStart < bEnd) parentNode.insertBefore(b[bStart++], node); | ||
@@ -117,3 +561,5 @@ } else if (bEnd === bStart) { | ||
disposer = dispose; | ||
element === document ? code() : insert(element, code(), element.firstChild ? null : undefined, init); | ||
element === document | ||
? code() | ||
: insert(element, code(), element.firstChild ? null : undefined, init); | ||
}, options.owner); | ||
@@ -132,3 +578,5 @@ return () => { | ||
}; | ||
const fn = isCE ? () => untrack(() => document.importNode(node || (node = create()), true)) : () => (node || (node = create())).cloneNode(true); | ||
const fn = isCE | ||
? () => untrack(() => document.importNode(node || (node = create()), true)) | ||
: () => (node || (node = create())).cloneNode(true); | ||
fn.cloneNode = fn; | ||
@@ -158,11 +606,14 @@ return fn; | ||
if (sharedConfig.context) 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 (sharedConfig.context) 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); | ||
} | ||
function className(node, value) { | ||
if (sharedConfig.context) return; | ||
if (value == null) node.removeAttribute("class");else node.className = value; | ||
if (value == null) node.removeAttribute("class"); | ||
else node.className = value; | ||
} | ||
@@ -177,3 +628,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); | ||
@@ -203,3 +654,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); | ||
@@ -225,3 +676,5 @@ prev || (prev = {}); | ||
if (!skipChildren) { | ||
createRenderEffect(() => prevProps.children = insertExpression(node, props.children, prevProps.children)); | ||
createRenderEffect( | ||
() => (prevProps.children = insertExpression(node, props.children, prevProps.children)) | ||
); | ||
} | ||
@@ -285,3 +738,3 @@ createRenderEffect(() => props.ref && props.ref(node)); | ||
let node, key; | ||
if (!sharedConfig.context || !(node = sharedConfig.registry.get(key = getHydrationKey()))) { | ||
if (!sharedConfig.context || !(node = sharedConfig.registry.get((key = getHydrationKey())))) { | ||
return template(); | ||
@@ -305,3 +758,4 @@ } | ||
const v = end.nodeValue; | ||
if (v === "$") count++;else if (v === "/") { | ||
if (v === "$") count++; | ||
else if (v === "/") { | ||
if (count === 0) return [end, current]; | ||
@@ -320,6 +774,3 @@ count--; | ||
queueMicrotask(() => { | ||
const { | ||
completed, | ||
events | ||
} = sharedConfig; | ||
const { completed, events } = sharedConfig; | ||
events.queued = false; | ||
@@ -341,3 +792,4 @@ while (events.length) { | ||
const classNames = key.trim().split(/\s+/); | ||
for (let i = 0, nameLen = classNames.length; i < nameLen; i++) node.classList.toggle(classNames[i], value); | ||
for (let i = 0, nameLen = classNames.length; i < nameLen; i++) | ||
node.classList.toggle(classNames[i], value); | ||
} | ||
@@ -372,3 +824,9 @@ function assignProp(node, prop, value, prev, isSVG, skipRef) { | ||
setAttribute(node, prop.slice(5), value); | ||
} else if ((forceProp = prop.slice(0, 5) === "prop:") || (isChildProp = ChildProperties.has(prop)) || !isSVG && ((propAlias = getPropAlias(prop, node.tagName)) || (isProp = Properties.has(prop))) || (isCE = node.nodeName.includes("-"))) { | ||
} else if ( | ||
(forceProp = prop.slice(0, 5) === "prop:") || | ||
(isChildProp = ChildProperties.has(prop)) || | ||
(!isSVG && | ||
((propAlias = getPropAlias(prop, node.tagName)) || (isProp = Properties.has(prop)))) || | ||
(isCE = node.nodeName.includes("-")) | ||
) { | ||
if (forceProp) { | ||
@@ -378,6 +836,9 @@ prop = prop.slice(5); | ||
} else if (sharedConfig.context) 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); | ||
} | ||
@@ -388,3 +849,3 @@ return value; | ||
const key = `$$${e.type}`; | ||
let node = e.composedPath && e.composedPath()[0] || e.target; | ||
let node = (e.composedPath && e.composedPath()[0]) || e.target; | ||
if (e.target !== node) { | ||
@@ -419,3 +880,4 @@ Object.defineProperty(e, "target", { | ||
const node = current[i]; | ||
if (node.nodeType === 8 && node.data.slice(0, 2) === "!$") node.remove();else cleaned.push(node); | ||
if (node.nodeType === 8 && node.data.slice(0, 2) === "!$") node.remove(); | ||
else cleaned.push(node); | ||
} | ||
@@ -428,3 +890,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") { | ||
@@ -458,3 +920,3 @@ if (sharedConfig.context) return current; | ||
if (normalizeIncomingArray(array, value, current, unwrapArray)) { | ||
createRenderEffect(() => current = insertExpression(parent, array, current, marker, true)); | ||
createRenderEffect(() => (current = insertExpression(parent, array, current, marker, true))); | ||
return () => current; | ||
@@ -468,3 +930,3 @@ } | ||
while ((node = node.nextSibling) !== marker) nodes.push(node); | ||
return current = nodes; | ||
return (current = nodes); | ||
} | ||
@@ -484,5 +946,5 @@ if (array.length === 0) { | ||
} else if (value.nodeType) { | ||
if (sharedConfig.context && value.parentNode) return current = multi ? [value] : value; | ||
if (sharedConfig.context && value.parentNode) return (current = multi ? [value] : value); | ||
if (Array.isArray(current)) { | ||
if (multi) return current = cleanChildren(parent, current, marker, value); | ||
if (multi) return (current = cleanChildren(parent, current, marker, value)); | ||
cleanChildren(parent, current, null, value); | ||
@@ -493,3 +955,3 @@ } else if (current == null || current === "" || !parent.firstChild) { | ||
current = value; | ||
} else ; | ||
} else; | ||
return current; | ||
@@ -503,3 +965,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); | ||
@@ -511,3 +974,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 { | ||
@@ -519,3 +987,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)); | ||
} | ||
@@ -529,3 +998,3 @@ } | ||
function cleanChildren(parent, current, marker, replacement) { | ||
if (marker === undefined) return parent.textContent = ""; | ||
if (marker === undefined) return (parent.textContent = ""); | ||
const node = replacement || document.createTextNode(""); | ||
@@ -538,3 +1007,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; | ||
@@ -550,3 +1021,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); | ||
} | ||
@@ -604,5 +1076,3 @@ } | ||
function Portal(props) { | ||
const { | ||
useShadow | ||
} = props, | ||
const { useShadow } = props, | ||
marker = document.createTextNode(""), | ||
@@ -613,30 +1083,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; | ||
@@ -661,2 +1138,59 @@ } | ||
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, 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, | ||
setProperty, | ||
spread, | ||
ssr, | ||
ssrAttribute, | ||
ssrClassList, | ||
ssrElement, | ||
ssrHydrationKey, | ||
ssrSpread, | ||
ssrStyle, | ||
style, | ||
template, | ||
use, | ||
voidFn as useAssets | ||
}; |
@@ -60,3 +60,3 @@ import { JSX } from "./jsx.js"; | ||
node: MountableElement, | ||
options?: { renderId?: string, owner?: unknown } | ||
options?: { renderId?: string; owner?: unknown } | ||
): () => void; | ||
@@ -78,2 +78,2 @@ export function getHydrationKey(): string; | ||
export declare const RequestContext: unique symbol; | ||
export function getRequestEvent(): RequestEvent | undefined; | ||
export function getRequestEvent(): RequestEvent | undefined; |
@@ -1,1 +0,10 @@ | ||
export { getOwner, createComponent, createRoot as root, createRenderEffect as effect, createMemo as memo, sharedConfig, untrack, mergeProps } from "solid-js"; | ||
export { | ||
getOwner, | ||
createComponent, | ||
createRoot as root, | ||
createRenderEffect as effect, | ||
createMemo as memo, | ||
sharedConfig, | ||
untrack, | ||
mergeProps | ||
} from "solid-js"; |
import { hydrate as hydrateCore } from "./client.js"; | ||
import { JSX, ComponentProps, ValidComponent } from "solid-js"; | ||
export * from "./client.js"; | ||
export { For, Show, Suspense, SuspenseList, Switch, Match, Index, ErrorBoundary, mergeProps } from "solid-js"; | ||
export { | ||
For, | ||
Show, | ||
Suspense, | ||
SuspenseList, | ||
Switch, | ||
Match, | ||
Index, | ||
ErrorBoundary, | ||
mergeProps | ||
} from "solid-js"; | ||
export * from "./server-mock.js"; | ||
@@ -17,14 +27,21 @@ export declare const isServer: boolean; | ||
export declare function Portal<T extends boolean = false, S extends boolean = false>(props: { | ||
mount?: Node; | ||
useShadow?: T; | ||
isSVG?: S; | ||
ref?: (S extends true ? SVGGElement : HTMLDivElement) | ((el: (T extends true ? { | ||
readonly shadowRoot: ShadowRoot; | ||
} : {}) & (S extends true ? SVGGElement : HTMLDivElement)) => void); | ||
children: JSX.Element; | ||
mount?: Node; | ||
useShadow?: T; | ||
isSVG?: S; | ||
ref?: | ||
| (S extends true ? SVGGElement : HTMLDivElement) | ||
| (( | ||
el: (T extends true | ||
? { | ||
readonly shadowRoot: ShadowRoot; | ||
} | ||
: {}) & | ||
(S extends true ? SVGGElement : HTMLDivElement) | ||
) => void); | ||
children: JSX.Element; | ||
}): Text; | ||
export type DynamicProps<T extends ValidComponent, P = ComponentProps<T>> = { | ||
[K in keyof P]: P[K]; | ||
[K in keyof P]: P[K]; | ||
} & { | ||
component: T | undefined; | ||
component: T | undefined; | ||
}; | ||
@@ -31,0 +48,0 @@ /** |
@@ -1,37 +0,44 @@ | ||
export declare function renderToString<T>(fn: () => T, options?: { | ||
export declare function renderToString<T>( | ||
fn: () => T, | ||
options?: { | ||
nonce?: string; | ||
renderId?: string; | ||
}): string; | ||
export declare function renderToStringAsync<T>(fn: () => T, options?: { | ||
} | ||
): string; | ||
export declare function renderToStringAsync<T>( | ||
fn: () => T, | ||
options?: { | ||
timeoutMs?: number; | ||
nonce?: string; | ||
renderId?: string; | ||
}): Promise<string>; | ||
export declare function renderToStream<T>(fn: () => T, options?: { | ||
} | ||
): Promise<string>; | ||
export declare function renderToStream<T>( | ||
fn: () => T, | ||
options?: { | ||
nonce?: string; | ||
renderId?: string; | ||
onCompleteShell?: (info: { | ||
write: (v: string) => void; | ||
}) => void; | ||
onCompleteAll?: (info: { | ||
write: (v: string) => void; | ||
}) => void; | ||
}): { | ||
pipe: (writable: { | ||
write: (v: string) => void; | ||
}) => void; | ||
pipeTo: (writable: WritableStream) => void; | ||
onCompleteShell?: (info: { write: (v: string) => void }) => void; | ||
onCompleteAll?: (info: { write: (v: string) => void }) => void; | ||
} | ||
): { | ||
pipe: (writable: { write: (v: string) => void }) => void; | ||
pipeTo: (writable: WritableStream) => void; | ||
}; | ||
export declare function ssr(template: string[] | string, ...nodes: any[]): { | ||
t: string; | ||
export declare function ssr( | ||
template: string[] | string, | ||
...nodes: any[] | ||
): { | ||
t: string; | ||
}; | ||
export declare function ssrElement(name: string, props: any, children: any, needsId: boolean): { | ||
t: string; | ||
export declare function ssrElement( | ||
name: string, | ||
props: any, | ||
children: any, | ||
needsId: boolean | ||
): { | ||
t: string; | ||
}; | ||
export declare function ssrClassList(value: { | ||
[k: string]: boolean; | ||
}): string; | ||
export declare function ssrStyle(value: { | ||
[k: string]: string; | ||
}): string; | ||
export declare function ssrClassList(value: { [k: string]: boolean }): string; | ||
export declare function ssrStyle(value: { [k: string]: string }): string; | ||
export declare function ssrAttribute(key: string, value: boolean): string; | ||
@@ -46,3 +53,3 @@ export declare function ssrHydrationKey(): string; | ||
export type LegacyResults = { | ||
startWriting: () => void; | ||
startWriting: () => void; | ||
}; | ||
@@ -52,16 +59,24 @@ /** | ||
*/ | ||
export declare function pipeToWritable<T>(fn: () => T, writable: WritableStream, options?: { | ||
export declare function pipeToWritable<T>( | ||
fn: () => T, | ||
writable: WritableStream, | ||
options?: { | ||
nonce?: string; | ||
onReady?: (res: LegacyResults) => void; | ||
onCompleteAll?: () => void; | ||
}): void; | ||
} | ||
): void; | ||
/** | ||
* @deprecated Replaced by renderToStream | ||
*/ | ||
export declare function pipeToNodeWritable<T>(fn: () => T, writable: { | ||
export declare function pipeToNodeWritable<T>( | ||
fn: () => T, | ||
writable: { | ||
write: (v: string) => void; | ||
}, options?: { | ||
}, | ||
options?: { | ||
nonce?: string; | ||
onReady?: (res: LegacyResults) => void; | ||
onCompleteAll?: () => void; | ||
}): void; | ||
} | ||
): void; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
843994
25970
+ Addedseroval@0.14.1(transitive)
- Removedseroval@0.12.4(transitive)
Updatedseroval@^0.14.1