mirror of https://github.com/sveltejs/svelte
parent
82d17c5a6f
commit
87a05ec47b
@ -1,109 +0,0 @@
|
|||||||
import { custom_event, append, insert, detach, listen, attr } from './dom';
|
|
||||||
import { now } from 'svelte/environment';
|
|
||||||
let inited;
|
|
||||||
export function add_location_dev$legacy(element, file, line, column, char) {
|
|
||||||
element.__svelte_meta = {
|
|
||||||
loc: { file, line, column, char },
|
|
||||||
};
|
|
||||||
}
|
|
||||||
export function dispatch_dev$legacy<T = any>(type: string, detail?: T) {
|
|
||||||
if (!inited && `__SVELTE_DEVTOOLS_GLOBAL_HOOK__` in window) {
|
|
||||||
inited = true;
|
|
||||||
throw new Error(`You must specify the version`);
|
|
||||||
}
|
|
||||||
document.dispatchEvent(custom_event(type, { version: __VERSION__, ...detail }));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function append_dev$legacy(target: Node, node: Node) {
|
|
||||||
dispatch_dev$legacy('SvelteDOMInsert', { target, node });
|
|
||||||
append(target, node);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function insert_dev$legacy(target: Node, node: Node, anchor?: Node) {
|
|
||||||
dispatch_dev$legacy('SvelteDOMInsert', { target, node, anchor });
|
|
||||||
insert(target, node, anchor);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function detach_dev$legacy(node: Node) {
|
|
||||||
dispatch_dev$legacy('SvelteDOMRemove', { node });
|
|
||||||
detach(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function detach_between_dev$legacy(before: Node, after: Node) {
|
|
||||||
while (before.nextSibling && before.nextSibling !== after) {
|
|
||||||
detach_dev$legacy(before.nextSibling);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function detach_before_dev$legacy(after: Node) {
|
|
||||||
while (after.previousSibling) {
|
|
||||||
detach_dev$legacy(after.previousSibling);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function detach_after_dev$legacy(before: Node) {
|
|
||||||
while (before.nextSibling) {
|
|
||||||
detach_dev$legacy(before.nextSibling);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function listen_dev$legacy(
|
|
||||||
node: Node,
|
|
||||||
event: string,
|
|
||||||
handler: EventListenerOrEventListenerObject,
|
|
||||||
options?: boolean | AddEventListenerOptions | EventListenerOptions,
|
|
||||||
has_prevent_default?: boolean,
|
|
||||||
has_stop_propagation?: boolean
|
|
||||||
) {
|
|
||||||
const modifiers = options === true ? ['capture'] : options ? Array.from(Object.keys(options)) : [];
|
|
||||||
if (has_prevent_default) modifiers.push('preventDefault');
|
|
||||||
if (has_stop_propagation) modifiers.push('stopPropagation');
|
|
||||||
|
|
||||||
dispatch_dev$legacy('SvelteDOMAddEventListener', { node, event, handler, modifiers });
|
|
||||||
|
|
||||||
const dispose = listen(node, event, handler, options);
|
|
||||||
return () => {
|
|
||||||
dispatch_dev$legacy('SvelteDOMRemoveEventListener', { node, event, handler, modifiers });
|
|
||||||
dispose();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function attr_dev$legacy(node: Element, attribute: string, value?: string) {
|
|
||||||
attr(node, attribute, value);
|
|
||||||
|
|
||||||
if (value == null) dispatch_dev$legacy('SvelteDOMRemoveAttribute', { node, attribute });
|
|
||||||
else dispatch_dev$legacy('SvelteDOMSetAttribute', { node, attribute, value });
|
|
||||||
}
|
|
||||||
|
|
||||||
export function prop_dev$legacy(node: Element, property: string, value?: any) {
|
|
||||||
node[property] = value;
|
|
||||||
|
|
||||||
dispatch_dev$legacy('SvelteDOMSetProperty', { node, property, value });
|
|
||||||
}
|
|
||||||
|
|
||||||
export function dataset_dev$legacy(node: HTMLElement, property: string, value?: any) {
|
|
||||||
node.dataset[property] = value;
|
|
||||||
|
|
||||||
dispatch_dev$legacy('SvelteDOMSetDataset', { node, property, value });
|
|
||||||
}
|
|
||||||
|
|
||||||
export function set_data_dev$legacy(text, data) {
|
|
||||||
data = '' + data;
|
|
||||||
if (text.data === data) return;
|
|
||||||
|
|
||||||
dispatch_dev$legacy('SvelteDOMSetData', { node: text, data });
|
|
||||||
text.data = data;
|
|
||||||
}
|
|
||||||
export function loop_guard_dev$legacy(timeout) {
|
|
||||||
const start = now();
|
|
||||||
return () => {
|
|
||||||
if (now() - start > timeout) {
|
|
||||||
throw new Error(`Infinite loop detected`);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
export function validate_store_dev$legacy(store, name) {
|
|
||||||
if (store != null && typeof store.subscribe !== 'function') {
|
|
||||||
throw new Error(`'${name}' is not a store with a 'subscribe' method`);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,147 +0,0 @@
|
|||||||
import { SvelteComponent } from './Component';
|
|
||||||
|
|
||||||
const dev$context = {
|
|
||||||
block: null,
|
|
||||||
component: null,
|
|
||||||
};
|
|
||||||
abstract class Dev$ {
|
|
||||||
self;
|
|
||||||
parent_block = dev$context.block;
|
|
||||||
parent_component = dev$context.component;
|
|
||||||
constructor(self) {
|
|
||||||
this.self = self;
|
|
||||||
}
|
|
||||||
abstract add(type, payload): void;
|
|
||||||
abstract subscribers: {}[];
|
|
||||||
dispatch(type, payload: any) {
|
|
||||||
this.add(type, payload);
|
|
||||||
this.subscribers.forEach((subscriber) => {
|
|
||||||
if (type in subscriber) subscriber[type](payload);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
subscribe(subscriber) {
|
|
||||||
this.subscribers.push(subscriber);
|
|
||||||
return () => {
|
|
||||||
const index = this.subscribers.indexOf(subscriber);
|
|
||||||
if (~index) this.subscribers.splice(index, 1);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
class Dev$Component extends Dev$ {
|
|
||||||
self: SvelteComponent;
|
|
||||||
block;
|
|
||||||
add(type, payload) {}
|
|
||||||
}
|
|
||||||
class Dev$Block extends Dev$ {
|
|
||||||
self;
|
|
||||||
parent_block;
|
|
||||||
parent_component;
|
|
||||||
elements: Dev$Element[] = [];
|
|
||||||
}
|
|
||||||
class Dev$Element extends Dev$ {
|
|
||||||
component;
|
|
||||||
node;
|
|
||||||
parent;
|
|
||||||
children = [];
|
|
||||||
attributes: {};
|
|
||||||
eventListeners: {};
|
|
||||||
style: {};
|
|
||||||
class: {};
|
|
||||||
add(type, payload) {}
|
|
||||||
subscribers: Dev$ElementSubscriber[] = [];
|
|
||||||
dispatch(type, payload: any) {
|
|
||||||
this.add(type, payload);
|
|
||||||
this.subscribers.forEach((subscriber) => {
|
|
||||||
if (type in subscriber) subscriber[type](payload);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
subscribe(subscriber) {
|
|
||||||
this.subscribers.push(subscriber);
|
|
||||||
return () => {
|
|
||||||
const index = this.subscribers.indexOf(subscriber);
|
|
||||||
if (~index) this.subscribers.splice(index, 1);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
interface Dev$ElementSubscriber {
|
|
||||||
onMount(payload): void;
|
|
||||||
onUnmount(payload): void;
|
|
||||||
setAttribute(payload): void;
|
|
||||||
removeAttribute(payload): void;
|
|
||||||
addEventListener(payload): void;
|
|
||||||
removeEventListener(payload): void;
|
|
||||||
addClass(payload): void;
|
|
||||||
removeClass(payload): void;
|
|
||||||
addStyle(payload): void;
|
|
||||||
removeStyle(payload): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const dev$dispatch =
|
|
||||||
__DEV__ &&
|
|
||||||
!__TEST__ &&
|
|
||||||
typeof window !== 'undefined' &&
|
|
||||||
(function dev$create_hook() {
|
|
||||||
const subscribers = [];
|
|
||||||
const rootComponents = [];
|
|
||||||
const hook = {
|
|
||||||
version: __VERSION__,
|
|
||||||
has_subscribers: false,
|
|
||||||
subscribe(listener) {
|
|
||||||
this.has_subscribers = true;
|
|
||||||
subscribers.push(listener);
|
|
||||||
if (rootComponents.length) rootComponents.forEach((component) => listener.addRootComponent(component));
|
|
||||||
else listener.ping(`init-no-components`);
|
|
||||||
return () => {
|
|
||||||
const index = subscribers.indexOf(listener);
|
|
||||||
if (~index) {
|
|
||||||
subscribers.splice(index, 1);
|
|
||||||
this.has_subscribers = !!subscribers.length;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
Object.defineProperty(window, `__SVELTE_DEVTOOLS_GLOBAL_HOOK__`, {
|
|
||||||
enumerable: false,
|
|
||||||
get() {
|
|
||||||
return hook;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return function update(target_type, event_type, ...values) {
|
|
||||||
if (!hook.has_subscribers) return;
|
|
||||||
subscribers.forEach((listener) => {
|
|
||||||
if (target_type in listener && event_type in listener[target_type]) {
|
|
||||||
listener[target_type][event_type](...values);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
|
|
||||||
export function dev$element(element: Element | Node | EventTarget, event: keyof ElementEventsMap, payload?: any) {
|
|
||||||
if (__DEV__) {
|
|
||||||
dev$dispatch(`element`, event, element, payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export function dev$block(event: keyof BlockEventsMap, payload) {}
|
|
||||||
export function dev$assert(truthy: any, else_throw: string) {
|
|
||||||
if (__DEV__ && !truthy) {
|
|
||||||
throw new Error(else_throw);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ElementEventsMap {
|
|
||||||
onMount;
|
|
||||||
onDestroy;
|
|
||||||
setAttribute;
|
|
||||||
removeAttribute;
|
|
||||||
addEventListener;
|
|
||||||
removeEventListener;
|
|
||||||
addClass;
|
|
||||||
removeClass;
|
|
||||||
}
|
|
||||||
interface BlockEventsMap {
|
|
||||||
'create';
|
|
||||||
'claim';
|
|
||||||
'claim.failed';
|
|
||||||
}
|
|
@ -0,0 +1,158 @@
|
|||||||
|
import { custom_event, append, insert, detach, listen, attr } from './dom';
|
||||||
|
import { now, has_Symbol } from 'svelte/environment';
|
||||||
|
import { SvelteComponent } from './Component';
|
||||||
|
|
||||||
|
export function add_location_dev(element, file, line, column, char) {
|
||||||
|
element.__svelte_meta = {
|
||||||
|
loc: { file, line, column, char },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
export function dispatch_dev<T = any>(type: string, detail?: T) {
|
||||||
|
document.dispatchEvent(custom_event(type, { version: __VERSION__, ...detail }));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function append_dev(target: Node, node: Node) {
|
||||||
|
dispatch_dev('SvelteDOMInsert', { target, node });
|
||||||
|
append(target, node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function insert_dev(target: Node, node: Node, anchor?: Node) {
|
||||||
|
dispatch_dev('SvelteDOMInsert', { target, node, anchor });
|
||||||
|
insert(target, node, anchor);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function detach_dev(node: Node) {
|
||||||
|
dispatch_dev('SvelteDOMRemove', { node });
|
||||||
|
detach(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function detach_between_dev(before: Node, after: Node) {
|
||||||
|
while (before.nextSibling && before.nextSibling !== after) {
|
||||||
|
detach_dev(before.nextSibling);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function detach_before_dev(after: Node) {
|
||||||
|
while (after.previousSibling) {
|
||||||
|
detach_dev(after.previousSibling);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function detach_after_dev(before: Node) {
|
||||||
|
while (before.nextSibling) {
|
||||||
|
detach_dev(before.nextSibling);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function listen_dev(
|
||||||
|
node: Node,
|
||||||
|
event: string,
|
||||||
|
handler: EventListenerOrEventListenerObject,
|
||||||
|
options?: boolean | AddEventListenerOptions | EventListenerOptions,
|
||||||
|
has_prevent_default?: boolean,
|
||||||
|
has_stop_propagation?: boolean
|
||||||
|
) {
|
||||||
|
const modifiers = options === true ? ['capture'] : options ? Array.from(Object.keys(options)) : [];
|
||||||
|
if (has_prevent_default) modifiers.push('preventDefault');
|
||||||
|
if (has_stop_propagation) modifiers.push('stopPropagation');
|
||||||
|
|
||||||
|
dispatch_dev('SvelteDOMAddEventListener', { node, event, handler, modifiers });
|
||||||
|
|
||||||
|
const dispose = listen(node, event, handler, options);
|
||||||
|
return () => {
|
||||||
|
dispatch_dev('SvelteDOMRemoveEventListener', { node, event, handler, modifiers });
|
||||||
|
dispose();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function attr_dev(node: Element, attribute: string, value?: string) {
|
||||||
|
attr(node, attribute, value);
|
||||||
|
|
||||||
|
if (value == null) dispatch_dev('SvelteDOMRemoveAttribute', { node, attribute });
|
||||||
|
else dispatch_dev('SvelteDOMSetAttribute', { node, attribute, value });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function prop_dev(node: Element, property: string, value?: any) {
|
||||||
|
node[property] = value;
|
||||||
|
|
||||||
|
dispatch_dev('SvelteDOMSetProperty', { node, property, value });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function dataset_dev(node: HTMLElement, property: string, value?: any) {
|
||||||
|
node.dataset[property] = value;
|
||||||
|
|
||||||
|
dispatch_dev('SvelteDOMSetDataset', { node, property, value });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function set_data_dev(text, data) {
|
||||||
|
data = '' + data;
|
||||||
|
if (text.data === data) return;
|
||||||
|
|
||||||
|
dispatch_dev('SvelteDOMSetData', { node: text, data });
|
||||||
|
text.data = data;
|
||||||
|
}
|
||||||
|
export function loop_guard_dev(timeout) {
|
||||||
|
const start = now();
|
||||||
|
return () => {
|
||||||
|
if (now() - start > timeout) {
|
||||||
|
throw new Error(`Infinite loop detected`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
export function validate_store_dev(store, name) {
|
||||||
|
if (store != null && typeof store.subscribe !== 'function') {
|
||||||
|
throw new Error(
|
||||||
|
`Could not subscribe to $${name}. A valid store is an object with a .subscribe method, consider setting ${name} to null if this is expected.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export const is_array_like_dev = (arg) => {
|
||||||
|
if (typeof arg !== 'string' && typeof arg === 'object' && !('length' in arg))
|
||||||
|
throw new Error(
|
||||||
|
`{#each} only iterates over Array-like Objects.${
|
||||||
|
has_Symbol && Symbol.iterator in arg
|
||||||
|
? ' Consider using a [...spread] to convert this iterable into an Array instead.'
|
||||||
|
: ''
|
||||||
|
}`
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export const check_duplicate_keys_dev = (ctx, list, get_context, get_key) => {
|
||||||
|
const keys = new Set();
|
||||||
|
for (let i = 0; i < list.length; i++) {
|
||||||
|
const key = get_key(get_context(ctx, list, i));
|
||||||
|
if (keys.has(key)) {
|
||||||
|
throw new Error(`Cannot have duplicate keys in a keyed each`);
|
||||||
|
}
|
||||||
|
keys.add(key);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
type Props = Record<string, any>;
|
||||||
|
export interface SvelteComponentDev {
|
||||||
|
$set(props?: Props): void;
|
||||||
|
$on<T = any>(event: string, callback: (event: CustomEvent<T>) => void): () => void;
|
||||||
|
$destroy(): void;
|
||||||
|
[accessor: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SvelteComponentDev extends SvelteComponent {
|
||||||
|
constructor(options: {
|
||||||
|
target: Element;
|
||||||
|
anchor?: Element;
|
||||||
|
props?: Props;
|
||||||
|
hydrate?: boolean;
|
||||||
|
intro?: boolean;
|
||||||
|
$$inline?: boolean;
|
||||||
|
}) {
|
||||||
|
if (!options || (!options.target && !options.$$inline)) throw new Error(`'target' is a required option`);
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
$destroy() {
|
||||||
|
super.$destroy();
|
||||||
|
this.$destroy = () => {
|
||||||
|
console.warn(`Component was already destroyed`); // eslint-disable-line no-console
|
||||||
|
};
|
||||||
|
}
|
||||||
|
$capture_state() {}
|
||||||
|
$inject_state() {}
|
||||||
|
}
|
@ -1,56 +0,0 @@
|
|||||||
import { SvelteComponent } from './Component';
|
|
||||||
import { now, has_Symbol } from 'svelte/environment';
|
|
||||||
import { dev$assert } from './dev.tools';
|
|
||||||
|
|
||||||
export const dev$is_array_like = (arg) =>
|
|
||||||
dev$assert(
|
|
||||||
typeof arg === 'string' || (typeof arg === 'object' && 'length' in arg),
|
|
||||||
`{#each} only iterates over Array-like Objects.${
|
|
||||||
has_Symbol && Symbol.iterator in arg
|
|
||||||
? ' Consider using a [...spread] to convert this iterable into an Array instead.'
|
|
||||||
: ''
|
|
||||||
}`
|
|
||||||
);
|
|
||||||
|
|
||||||
export const dev$known_slots = (name, slot, keys) =>
|
|
||||||
Object.keys(slot).forEach((key) => dev$assert(keys.includes(key), `<${name}> received an unexpected slot "${key}".`));
|
|
||||||
|
|
||||||
export const dev$is_valid_store = (store, name) =>
|
|
||||||
dev$assert(
|
|
||||||
typeof store === 'object' && (store === null || typeof store.subscribe === 'function'),
|
|
||||||
`Could not subscribe to $${name}. A valid store is an object with a .subscribe method, consider setting ${name} to null if this is expected.`
|
|
||||||
);
|
|
||||||
|
|
||||||
export function dev$loop_guard(loopGuardTimeout) {
|
|
||||||
const start = now();
|
|
||||||
return () => dev$assert(now() - start < loopGuardTimeout, `Infinite loop detected`);
|
|
||||||
}
|
|
||||||
type Props = Record<string, any>;
|
|
||||||
export interface SvelteComponentDev {
|
|
||||||
$set(props?: Props): void;
|
|
||||||
$on<T = any>(event: string, callback: (event: CustomEvent<T>) => void): () => void;
|
|
||||||
$destroy(): void;
|
|
||||||
[accessor: string]: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class SvelteComponentDev extends SvelteComponent {
|
|
||||||
constructor(options: {
|
|
||||||
target: Element;
|
|
||||||
anchor?: Element;
|
|
||||||
props?: Props;
|
|
||||||
hydrate?: boolean;
|
|
||||||
intro?: boolean;
|
|
||||||
$$inline?: boolean;
|
|
||||||
}) {
|
|
||||||
if (!options || (!options.target && !options.$$inline)) throw new Error(`'target' is a required option`);
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
$destroy() {
|
|
||||||
super.$destroy();
|
|
||||||
this.$destroy = () => {
|
|
||||||
console.warn(`Component was already destroyed`); // eslint-disable-line no-console
|
|
||||||
};
|
|
||||||
}
|
|
||||||
$capture_state() {}
|
|
||||||
$inject_state() {}
|
|
||||||
}
|
|
Loading…
Reference in new issue