first
This commit is contained in:
commit
f4be03ceba
1826 changed files with 830924 additions and 0 deletions
169
frontend/node_modules/svelte/src/store/index-client.js
generated
vendored
Normal file
169
frontend/node_modules/svelte/src/store/index-client.js
generated
vendored
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
/** @import { Readable, Writable } from './public.js' */
|
||||
import {
|
||||
effect_root,
|
||||
effect_tracking,
|
||||
render_effect
|
||||
} from '../internal/client/reactivity/effects.js';
|
||||
import { get, writable } from './shared/index.js';
|
||||
import { createSubscriber } from '../reactivity/create-subscriber.js';
|
||||
import {
|
||||
active_effect,
|
||||
active_reaction,
|
||||
set_active_effect,
|
||||
set_active_reaction
|
||||
} from '../internal/client/runtime.js';
|
||||
|
||||
export { derived, get, readable, readonly, writable } from './shared/index.js';
|
||||
|
||||
/**
|
||||
* @template V
|
||||
* @overload
|
||||
* @param {() => V} get
|
||||
* @param {(v: V) => void} set
|
||||
* @returns {Writable<V>}
|
||||
*/
|
||||
/**
|
||||
* @template V
|
||||
* @overload
|
||||
* @param {() => V} get
|
||||
* @returns {Readable<V>}
|
||||
*/
|
||||
/**
|
||||
* Create a store from a function that returns state, and (to make a writable store), an
|
||||
* optional second function that sets state.
|
||||
*
|
||||
* ```ts
|
||||
* import { toStore } from 'svelte/store';
|
||||
*
|
||||
* let count = $state(0);
|
||||
*
|
||||
* const store = toStore(() => count, (v) => (count = v));
|
||||
* ```
|
||||
* @template V
|
||||
* @param {() => V} get
|
||||
* @param {(v: V) => void} [set]
|
||||
* @returns {Writable<V> | Readable<V>}
|
||||
*/
|
||||
export function toStore(get, set) {
|
||||
var effect = active_effect;
|
||||
var reaction = active_reaction;
|
||||
var init_value = get();
|
||||
|
||||
const store = writable(init_value, (set) => {
|
||||
// If the value has changed before we call subscribe, then
|
||||
// we need to treat the value as already having run
|
||||
var ran = init_value !== get();
|
||||
|
||||
// TODO do we need a different implementation on the server?
|
||||
var teardown;
|
||||
// Apply the reaction and effect at the time of toStore being called
|
||||
var previous_reaction = active_reaction;
|
||||
var previous_effect = active_effect;
|
||||
set_active_reaction(reaction);
|
||||
set_active_effect(effect);
|
||||
|
||||
try {
|
||||
teardown = effect_root(() => {
|
||||
render_effect(() => {
|
||||
const value = get();
|
||||
if (ran) set(value);
|
||||
});
|
||||
});
|
||||
} finally {
|
||||
set_active_reaction(previous_reaction);
|
||||
set_active_effect(previous_effect);
|
||||
}
|
||||
|
||||
ran = true;
|
||||
|
||||
return teardown;
|
||||
});
|
||||
|
||||
if (set) {
|
||||
return {
|
||||
set,
|
||||
update: (fn) => set(fn(get())),
|
||||
subscribe: store.subscribe
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
subscribe: store.subscribe
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @template V
|
||||
* @overload
|
||||
* @param {Writable<V>} store
|
||||
* @returns {{ current: V }}
|
||||
*/
|
||||
/**
|
||||
* @template V
|
||||
* @overload
|
||||
* @param {Readable<V>} store
|
||||
* @returns {{ readonly current: V }}
|
||||
*/
|
||||
/**
|
||||
* Convert a store to an object with a reactive `current` property. If `store`
|
||||
* is a readable store, `current` will be a readonly property.
|
||||
*
|
||||
* ```ts
|
||||
* import { fromStore, get, writable } from 'svelte/store';
|
||||
*
|
||||
* const store = writable(0);
|
||||
*
|
||||
* const count = fromStore(store);
|
||||
*
|
||||
* count.current; // 0;
|
||||
* store.set(1);
|
||||
* count.current; // 1
|
||||
*
|
||||
* count.current += 1;
|
||||
* get(store); // 2
|
||||
* ```
|
||||
* @template V
|
||||
* @param {Writable<V> | Readable<V>} store
|
||||
*/
|
||||
export function fromStore(store) {
|
||||
let value = /** @type {V} */ (undefined);
|
||||
|
||||
const subscribe = createSubscriber((update) => {
|
||||
let ran = false;
|
||||
|
||||
const unsubscribe = store.subscribe((v) => {
|
||||
value = v;
|
||||
if (ran) update();
|
||||
});
|
||||
|
||||
ran = true;
|
||||
|
||||
return unsubscribe;
|
||||
});
|
||||
|
||||
function current() {
|
||||
if (effect_tracking()) {
|
||||
subscribe();
|
||||
return value;
|
||||
}
|
||||
|
||||
return get(store);
|
||||
}
|
||||
|
||||
if ('set' in store) {
|
||||
return {
|
||||
get current() {
|
||||
return current();
|
||||
},
|
||||
set current(v) {
|
||||
store.set(v);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
get current() {
|
||||
return current();
|
||||
}
|
||||
};
|
||||
}
|
||||
101
frontend/node_modules/svelte/src/store/index-server.js
generated
vendored
Normal file
101
frontend/node_modules/svelte/src/store/index-server.js
generated
vendored
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
/** @import { Readable, Writable } from './public.js' */
|
||||
import { get, writable } from './shared/index.js';
|
||||
|
||||
export { derived, get, readable, readonly, writable } from './shared/index.js';
|
||||
|
||||
/**
|
||||
* @template V
|
||||
* @overload
|
||||
* @param {() => V} get
|
||||
* @param {(v: V) => void} set
|
||||
* @returns {Writable<V>}
|
||||
*/
|
||||
/**
|
||||
* @template V
|
||||
* @overload
|
||||
* @param {() => V} get
|
||||
* @returns {Readable<V>}
|
||||
*/
|
||||
/**
|
||||
* Create a store from a function that returns state, and (to make a writable store), an
|
||||
* optional second function that sets state.
|
||||
*
|
||||
* ```ts
|
||||
* import { toStore } from 'svelte/store';
|
||||
*
|
||||
* let count = $state(0);
|
||||
*
|
||||
* const store = toStore(() => count, (v) => (count = v));
|
||||
* ```
|
||||
* @template V
|
||||
* @param {() => V} get
|
||||
* @param {(v: V) => void} [set]
|
||||
* @returns {Writable<V> | Readable<V>}
|
||||
*/
|
||||
export function toStore(get, set) {
|
||||
const store = writable(get());
|
||||
|
||||
if (set) {
|
||||
return {
|
||||
set,
|
||||
update: (fn) => set(fn(get())),
|
||||
subscribe: store.subscribe
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
subscribe: store.subscribe
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @template V
|
||||
* @overload
|
||||
* @param {Writable<V>} store
|
||||
* @returns {{ current: V }}
|
||||
*/
|
||||
/**
|
||||
* @template V
|
||||
* @overload
|
||||
* @param {Readable<V>} store
|
||||
* @returns {{ readonly current: V }}
|
||||
*/
|
||||
/**
|
||||
* Convert a store to an object with a reactive `current` property. If `store`
|
||||
* is a readable store, `current` will be a readonly property.
|
||||
*
|
||||
* ```ts
|
||||
* import { fromStore, get, writable } from 'svelte/store';
|
||||
*
|
||||
* const store = writable(0);
|
||||
*
|
||||
* const count = fromStore(store);
|
||||
*
|
||||
* count.current; // 0;
|
||||
* store.set(1);
|
||||
* count.current; // 1
|
||||
*
|
||||
* count.current += 1;
|
||||
* get(store); // 2
|
||||
* ```
|
||||
* @template V
|
||||
* @param {Writable<V> | Readable<V>} store
|
||||
*/
|
||||
export function fromStore(store) {
|
||||
if ('set' in store) {
|
||||
return {
|
||||
get current() {
|
||||
return get(store);
|
||||
},
|
||||
set current(v) {
|
||||
store.set(v);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
get current() {
|
||||
return get(store);
|
||||
}
|
||||
};
|
||||
}
|
||||
209
frontend/node_modules/svelte/src/store/shared/index.js
generated
vendored
Normal file
209
frontend/node_modules/svelte/src/store/shared/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
/** @import { Readable, StartStopNotifier, Subscriber, Unsubscriber, Updater, Writable } from '../public.js' */
|
||||
/** @import { Stores, StoresValues, SubscribeInvalidateTuple } from '../private.js' */
|
||||
import { noop, run_all } from '../../internal/shared/utils.js';
|
||||
import { safe_not_equal } from '../../internal/client/reactivity/equality.js';
|
||||
import { subscribe_to_store } from '../utils.js';
|
||||
|
||||
/**
|
||||
* @type {Array<SubscribeInvalidateTuple<any> | any>}
|
||||
*/
|
||||
const subscriber_queue = [];
|
||||
|
||||
/**
|
||||
* Creates a `Readable` store that allows reading by subscription.
|
||||
*
|
||||
* @template T
|
||||
* @param {T} [value] initial value
|
||||
* @param {StartStopNotifier<T>} [start]
|
||||
* @returns {Readable<T>}
|
||||
*/
|
||||
export function readable(value, start) {
|
||||
return {
|
||||
subscribe: writable(value, start).subscribe
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a `Writable` store that allows both updating and reading by subscription.
|
||||
*
|
||||
* @template T
|
||||
* @param {T} [value] initial value
|
||||
* @param {StartStopNotifier<T>} [start]
|
||||
* @returns {Writable<T>}
|
||||
*/
|
||||
export function writable(value, start = noop) {
|
||||
/** @type {Unsubscriber | null} */
|
||||
let stop = null;
|
||||
|
||||
/** @type {Set<SubscribeInvalidateTuple<T>>} */
|
||||
const subscribers = new Set();
|
||||
|
||||
/**
|
||||
* @param {T} new_value
|
||||
* @returns {void}
|
||||
*/
|
||||
function set(new_value) {
|
||||
if (safe_not_equal(value, new_value)) {
|
||||
value = new_value;
|
||||
if (stop) {
|
||||
// store is ready
|
||||
const run_queue = !subscriber_queue.length;
|
||||
for (const subscriber of subscribers) {
|
||||
subscriber[1]();
|
||||
subscriber_queue.push(subscriber, value);
|
||||
}
|
||||
if (run_queue) {
|
||||
for (let i = 0; i < subscriber_queue.length; i += 2) {
|
||||
subscriber_queue[i][0](subscriber_queue[i + 1]);
|
||||
}
|
||||
subscriber_queue.length = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Updater<T>} fn
|
||||
* @returns {void}
|
||||
*/
|
||||
function update(fn) {
|
||||
set(fn(/** @type {T} */ (value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Subscriber<T>} run
|
||||
* @param {() => void} [invalidate]
|
||||
* @returns {Unsubscriber}
|
||||
*/
|
||||
function subscribe(run, invalidate = noop) {
|
||||
/** @type {SubscribeInvalidateTuple<T>} */
|
||||
const subscriber = [run, invalidate];
|
||||
subscribers.add(subscriber);
|
||||
if (subscribers.size === 1) {
|
||||
stop = start(set, update) || noop;
|
||||
}
|
||||
run(/** @type {T} */ (value));
|
||||
return () => {
|
||||
subscribers.delete(subscriber);
|
||||
if (subscribers.size === 0 && stop) {
|
||||
stop();
|
||||
stop = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
return { set, update, subscribe };
|
||||
}
|
||||
|
||||
/**
|
||||
* Derived value store by synchronizing one or more readable stores and
|
||||
* applying an aggregation function over its input values.
|
||||
*
|
||||
* @template {Stores} S
|
||||
* @template T
|
||||
* @overload
|
||||
* @param {S} stores
|
||||
* @param {(values: StoresValues<S>, set: (value: T) => void, update: (fn: Updater<T>) => void) => Unsubscriber | void} fn
|
||||
* @param {T} [initial_value]
|
||||
* @returns {Readable<T>}
|
||||
*/
|
||||
/**
|
||||
* Derived value store by synchronizing one or more readable stores and
|
||||
* applying an aggregation function over its input values.
|
||||
*
|
||||
* @template {Stores} S
|
||||
* @template T
|
||||
* @overload
|
||||
* @param {S} stores
|
||||
* @param {(values: StoresValues<S>) => T} fn
|
||||
* @param {T} [initial_value]
|
||||
* @returns {Readable<T>}
|
||||
*/
|
||||
/**
|
||||
* @template {Stores} S
|
||||
* @template T
|
||||
* @param {S} stores
|
||||
* @param {Function} fn
|
||||
* @param {T} [initial_value]
|
||||
* @returns {Readable<T>}
|
||||
*/
|
||||
export function derived(stores, fn, initial_value) {
|
||||
const single = !Array.isArray(stores);
|
||||
/** @type {Array<Readable<any>>} */
|
||||
const stores_array = single ? [stores] : stores;
|
||||
if (!stores_array.every(Boolean)) {
|
||||
throw new Error('derived() expects stores as input, got a falsy value');
|
||||
}
|
||||
const auto = fn.length < 2;
|
||||
return readable(initial_value, (set, update) => {
|
||||
let started = false;
|
||||
/** @type {T[]} */
|
||||
const values = [];
|
||||
let pending = 0;
|
||||
let cleanup = noop;
|
||||
const sync = () => {
|
||||
if (pending) {
|
||||
return;
|
||||
}
|
||||
cleanup();
|
||||
const result = fn(single ? values[0] : values, set, update);
|
||||
if (auto) {
|
||||
set(result);
|
||||
} else {
|
||||
cleanup = typeof result === 'function' ? result : noop;
|
||||
}
|
||||
};
|
||||
const unsubscribers = stores_array.map((store, i) =>
|
||||
subscribe_to_store(
|
||||
store,
|
||||
(value) => {
|
||||
values[i] = value;
|
||||
pending &= ~(1 << i);
|
||||
if (started) {
|
||||
sync();
|
||||
}
|
||||
},
|
||||
() => {
|
||||
pending |= 1 << i;
|
||||
}
|
||||
)
|
||||
);
|
||||
started = true;
|
||||
sync();
|
||||
return function stop() {
|
||||
run_all(unsubscribers);
|
||||
cleanup();
|
||||
// We need to set this to false because callbacks can still happen despite having unsubscribed:
|
||||
// Callbacks might already be placed in the queue which doesn't know it should no longer
|
||||
// invoke this derived store.
|
||||
started = false;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a store and returns a new one derived from the old one that is readable.
|
||||
*
|
||||
* @template T
|
||||
* @param {Readable<T>} store - store to make readonly
|
||||
* @returns {Readable<T>}
|
||||
*/
|
||||
export function readonly(store) {
|
||||
return {
|
||||
// @ts-expect-error TODO i suspect the bind is unnecessary
|
||||
subscribe: store.subscribe.bind(store)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current value from a store by subscribing and immediately unsubscribing.
|
||||
*
|
||||
* @template T
|
||||
* @param {Readable<T>} store
|
||||
* @returns {T}
|
||||
*/
|
||||
export function get(store) {
|
||||
let value;
|
||||
subscribe_to_store(store, (_) => (value = _))();
|
||||
// @ts-expect-error
|
||||
return value;
|
||||
}
|
||||
36
frontend/node_modules/svelte/src/store/utils.js
generated
vendored
Normal file
36
frontend/node_modules/svelte/src/store/utils.js
generated
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/** @import { Readable } from './public' */
|
||||
import { untrack } from '../internal/client/runtime.js';
|
||||
import { noop } from '../internal/shared/utils.js';
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param {Readable<T> | null | undefined} store
|
||||
* @param {(value: T) => void} run
|
||||
* @param {(value: T) => void} [invalidate]
|
||||
* @returns {() => void}
|
||||
*/
|
||||
export function subscribe_to_store(store, run, invalidate) {
|
||||
if (store == null) {
|
||||
// @ts-expect-error
|
||||
run(undefined);
|
||||
|
||||
// @ts-expect-error
|
||||
if (invalidate) invalidate(undefined);
|
||||
|
||||
return noop;
|
||||
}
|
||||
|
||||
// Svelte store takes a private second argument
|
||||
// StartStopNotifier could mutate state, and we want to silence the corresponding validation error
|
||||
const unsub = untrack(() =>
|
||||
store.subscribe(
|
||||
run,
|
||||
// @ts-expect-error
|
||||
invalidate
|
||||
)
|
||||
);
|
||||
|
||||
// Also support RxJS
|
||||
// @ts-expect-error TODO fix this in the types?
|
||||
return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue