🚨 Active Supply Chain Attack:node-ipc Package Compromised.Learn More
Socket
Book a DemoSign in
Socket

@solid-devtools/shared

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solid-devtools/shared - npm Package Compare versions

Comparing version
0.9.2
to
0.10.0
+156
dist/chunk-BGRVHE3T.js
import {
__export
} from "./chunk-UICA3PK6.js";
// src/primitives.ts
var primitives_exports = {};
__export(primitives_exports, {
atom: () => atom,
createConsumers: () => createConsumers,
createDerivedSignal: () => createDerivedSignal,
createHover: () => createHover,
createPingedSignal: () => createPingedSignal,
defer: () => defer,
makeHoverElementListener: () => makeHoverElementListener,
trackFromListen: () => trackFromListen,
untrackedCallback: () => untrackedCallback,
useIsMobile: () => useIsMobile,
useIsTouch: () => useIsTouch
});
import {
createMemo,
createSignal,
getOwner,
onCleanup,
untrack,
createComputed
} from "solid-js";
import { onRootCleanup } from "@solid-primitives/utils";
import { makeEventListener } from "@solid-primitives/event-listener";
import { createSharedRoot } from "@solid-primitives/rootless";
import { createMediaQuery } from "@solid-primitives/media";
var untrackedCallback = (fn) => (...a) => untrack(fn.bind(void 0, ...a));
var useIsTouch = createSharedRoot(() => createMediaQuery("(hover: none)"));
var useIsMobile = createSharedRoot(() => createMediaQuery("(max-width: 640px)"));
function createHover(handle) {
let state = false;
let mounted = true;
const mql = window.matchMedia("(hover: none)");
let isTouch = mql.matches;
makeEventListener(mql, "change", ({ matches }) => {
if (isTouch = matches)
handle(state = false);
});
onCleanup(() => {
mounted = false;
if (state)
handle(state = false);
});
const onChange = (newState) => {
if (isTouch || !mounted)
return;
state !== newState && handle(state = newState);
};
return {
onMouseEnter: () => onChange(true),
onMouseLeave: () => setTimeout(() => onChange(false))
};
}
function createConsumers(initial = []) {
const [consumers, setConsumers] = createSignal([...initial], { name: "consumers" });
const enabled = createMemo(() => consumers().some((consumer) => consumer()));
return [
enabled,
(consumer) => {
setConsumers((p) => [...p, consumer]);
onRootCleanup(() => setConsumers((p) => p.filter((p2) => p2 !== consumer)));
}
];
}
function createDerivedSignal(fallback, options) {
const [source, setSource] = createSignal();
return [
createMemo(
() => {
const sourceRef = source();
return sourceRef ? sourceRef() : fallback;
},
void 0,
options
),
(newSource) => {
if (newSource && getOwner())
onCleanup(() => setSource((p) => p === newSource ? void 0 : p));
return setSource(() => newSource);
}
];
}
function makeHoverElementListener(onHover) {
let last = null;
const handleHover = (e) => {
const { target } = e;
if (target === last || !(target instanceof HTMLElement) && target !== null)
return;
onHover(last = target);
};
makeEventListener(window, "mouseover", handleHover);
makeEventListener(document, "mouseleave", handleHover.bind(void 0, { target: null }));
}
function defer(deps, fn, initialValue) {
const isArray = Array.isArray(deps);
let prevInput;
let defer2 = true;
return (prevValue) => {
let input;
if (isArray) {
input = Array(deps.length);
for (let i = 0; i < deps.length; i++)
input[i] = deps[i]();
} else
input = deps();
if (defer2) {
defer2 = false;
return initialValue;
}
const result = untrack(() => fn(input, prevInput, prevValue));
prevInput = input;
return result;
};
}
function atom(value, options) {
const [state, setState] = createSignal(value, { internal: true, ...options });
return (...args) => args.length === 1 ? setState(args[0]) : state();
}
function trackFromListen(listen) {
const [track, trigger] = createSignal(void 0, { equals: false });
listen(trigger);
return track;
}
function createPingedSignal(track, timeout = 400) {
const [isUpdated, setIsUpdated] = createSignal(false);
let timeoutId;
createComputed(
defer(track, () => {
setIsUpdated(true);
clearTimeout(timeoutId);
timeoutId = setTimeout(() => setIsUpdated(false), timeout);
})
);
onCleanup(() => clearTimeout(timeoutId));
return isUpdated;
}
export {
untrackedCallback,
useIsTouch,
useIsMobile,
createHover,
createConsumers,
createDerivedSignal,
makeHoverElementListener,
defer,
atom,
trackFromListen,
createPingedSignal,
primitives_exports
};
import {
__export
} from "./chunk-UICA3PK6.js";
// src/variables.ts
var variables_exports = {};
__export(variables_exports, {
LOCATION_ATTRIBUTE_NAME: () => LOCATION_ATTRIBUTE_NAME,
WINDOW_PROJECTPATH_PROPERTY: () => WINDOW_PROJECTPATH_PROPERTY
});
var WINDOW_PROJECTPATH_PROPERTY = "$sdt_projectPath";
var LOCATION_ATTRIBUTE_NAME = "data-source-loc";
export {
WINDOW_PROJECTPATH_PROPERTY,
LOCATION_ATTRIBUTE_NAME,
variables_exports
};
import {
__export
} from "./chunk-UICA3PK6.js";
// src/utils.ts
var utils_exports = {};
__export(utils_exports, {
arrayRefEquals: () => arrayRefEquals,
callArrayProp: () => callArrayProp,
createCallbackStack: () => createCallbackStack,
dedupeArray: () => dedupeArray,
error: () => error,
findIndexById: () => findIndexById,
findItemById: () => findItemById,
formatTime: () => formatTime,
info: () => info,
log: () => log,
mutateFilter: () => mutateFilter,
mutateRemove: () => mutateRemove,
pushToArrayProp: () => pushToArrayProp,
trimString: () => trimString,
warn: () => warn
});
var getLogLabel = () => [
`%csolid-devtools`,
"color: #fff; background: #2c4f7c; padding: 1px 4px;"
];
function info(data) {
console.info(...getLogLabel(), data);
return data;
}
function log(...args) {
console.log(...getLogLabel(), ...args);
}
function warn(...args) {
console.warn(...getLogLabel(), ...args);
}
function error(...args) {
console.error(...getLogLabel(), ...args);
}
function formatTime(d = new Date()) {
return ("0" + d.getHours()).slice(-2) + ":" + ("0" + d.getMinutes()).slice(-2) + ":" + ("0" + d.getSeconds()).slice(-2);
}
var createCallbackStack = () => {
let stack = [];
const clear = () => stack = [];
return {
push: (...callbacks) => stack.push(...callbacks),
execute(arg0, arg1, arg2, arg3) {
stack.forEach((cb) => cb(arg0, arg1, arg2, arg3));
clear();
},
clear
};
};
function callArrayProp(object, key, ...args) {
const arr = object[key];
if (arr)
for (const cb of arr)
cb(...args);
}
function pushToArrayProp(object, key, value) {
let arr = object[key];
if (arr)
arr.push(value);
else
arr = object[key] = [value];
return arr;
}
function mutateFilter(array, predicate) {
const temp = array.filter(predicate);
array.length = 0;
array.push.apply(array, temp);
}
function mutateRemove(array, item) {
array.splice(array.indexOf(item), 1);
}
var dedupeArray = (array) => Array.from(new Set(array));
var arrayRefEquals = (a, b) => a === b || a.length === b.length && a.every((e) => b.includes(e));
function trimString(str, maxLength) {
if (str.length <= maxLength)
return str;
return str.slice(0, maxLength) + "\u2026";
}
function findIndexById(array, id) {
for (let i = 0; i < array.length; i++)
if (array[i].id === id)
return i;
return -1;
}
function findItemById(array, id) {
for (let i = 0; i < array.length; i++) {
const item = array[i];
if (item.id === id)
return item;
}
}
export {
info,
log,
warn,
error,
formatTime,
createCallbackStack,
callArrayProp,
pushToArrayProp,
mutateFilter,
mutateRemove,
dedupeArray,
arrayRefEquals,
trimString,
findIndexById,
findItemById,
utils_exports
};
import { Accessor } from 'solid-js';
import { MemoOptions, AccessorArray, OnEffectFunction, NoInfer, EffectFunction, SignalOptions } from 'solid-js/types/reactive/signal';
import { AnyFunction } from '@solid-primitives/utils';
import { Primitive } from 'type-fest';
import { Listen } from '@solid-primitives/event-bus';
declare type WritableDeep<T> = 0 extends 1 & T ? T : T extends Primitive ? T : {
-readonly [K in keyof T]: WritableDeep<T[K]>;
};
declare const untrackedCallback: <Fn extends AnyFunction>(fn: Fn) => Fn;
declare const useIsTouch: () => Accessor<boolean>;
declare const useIsMobile: () => Accessor<boolean>;
declare function createHover(handle: (hovering: boolean) => void): {
onMouseEnter: VoidFunction;
onMouseLeave: VoidFunction;
};
/**
* Reactive array reducer — if at least one consumer (boolean signal) is enabled — the returned result will the `true`.
*
* For **IOC**
*/
declare function createConsumers(initial?: readonly Accessor<boolean>[]): [needed: Accessor<boolean>, addConsumer: (consumer: Accessor<boolean>) => void];
declare type DerivedSignal<T> = [
value: Accessor<T>,
setSource: (source?: Accessor<T>) => Accessor<T> | undefined
];
/**
* For **IOC**
*/
declare function createDerivedSignal<T>(): DerivedSignal<T>;
declare function createDerivedSignal<T>(fallback: T, options?: MemoOptions<T>): DerivedSignal<T>;
declare function makeHoverElementListener(onHover: (el: HTMLElement | null) => void): void;
/**
* Solid's `on` helper, but always defers and returns a provided initial value when if does instead of `undefined`.
*
* @param deps
* @param fn
* @param initialValue
*/
declare function defer<S, Next extends Prev, Prev = Next>(deps: AccessorArray<S> | Accessor<S>, fn: OnEffectFunction<S, undefined | NoInfer<Prev>, Next>, initialValue: Next): EffectFunction<undefined | NoInfer<Next>, NoInfer<Next>>;
declare function defer<S, Next extends Prev, Prev = Next>(deps: AccessorArray<S> | Accessor<S>, fn: OnEffectFunction<S, undefined | NoInfer<Prev>, Next>, initialValue?: undefined): EffectFunction<undefined | NoInfer<Next>>;
declare type Atom<T> = (<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) & Accessor<T>;
declare function atom<T>(value: T, options?: SignalOptions<T>): Atom<T>;
declare function atom<T>(value?: undefined, options?: SignalOptions<T | undefined>): Atom<T | undefined>;
declare function trackFromListen(listen: Listen): VoidFunction;
/**
* Creates a signal that will be activated for a given amount of time on every "ping" — a call to the listener function.
*/
declare function createPingedSignal(track: VoidFunction, timeout?: number): Accessor<boolean>;
type primitives_WritableDeep<T> = WritableDeep<T>;
declare const primitives_untrackedCallback: typeof untrackedCallback;
declare const primitives_useIsTouch: typeof useIsTouch;
declare const primitives_useIsMobile: typeof useIsMobile;
declare const primitives_createHover: typeof createHover;
declare const primitives_createConsumers: typeof createConsumers;
type primitives_DerivedSignal<T> = DerivedSignal<T>;
declare const primitives_createDerivedSignal: typeof createDerivedSignal;
declare const primitives_makeHoverElementListener: typeof makeHoverElementListener;
declare const primitives_defer: typeof defer;
type primitives_Atom<T> = Atom<T>;
declare const primitives_atom: typeof atom;
declare const primitives_trackFromListen: typeof trackFromListen;
declare const primitives_createPingedSignal: typeof createPingedSignal;
declare namespace primitives {
export {
primitives_WritableDeep as WritableDeep,
primitives_untrackedCallback as untrackedCallback,
primitives_useIsTouch as useIsTouch,
primitives_useIsMobile as useIsMobile,
primitives_createHover as createHover,
primitives_createConsumers as createConsumers,
primitives_DerivedSignal as DerivedSignal,
primitives_createDerivedSignal as createDerivedSignal,
primitives_makeHoverElementListener as makeHoverElementListener,
primitives_defer as defer,
primitives_Atom as Atom,
primitives_atom as atom,
primitives_trackFromListen as trackFromListen,
primitives_createPingedSignal as createPingedSignal,
};
}
export { Atom as A, DerivedSignal as D, WritableDeep as W, useIsTouch as a, useIsMobile as b, createHover as c, createConsumers as d, createDerivedSignal as e, defer as f, atom as g, createPingedSignal as h, makeHoverElementListener as m, primitives as p, trackFromListen as t, untrackedCallback as u };
declare function info<T>(data: T): T;
declare function log(...args: any[]): void;
declare function warn(...args: any[]): void;
declare function error(...args: any[]): void;
declare function formatTime(d?: Date): string;
declare const createCallbackStack: <A0 = void, A1 = void, A2 = void, A3 = void>() => {
push: (...callbacks: ((arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void)[]) => void;
execute: (arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void;
clear: VoidFunction;
};
declare function callArrayProp<K extends PropertyKey, T extends (...args: Args) => void, Args extends unknown[]>(object: {
[_ in K]?: T[];
}, key: K, ...args: Args): void;
declare function pushToArrayProp<K extends PropertyKey, T>(object: {
[_ in K]?: T[];
}, key: K, value: T): T[];
declare function mutateFilter<T, S extends T>(array: T[], predicate: (value: T, index: number, array: T[]) => value is S): void;
declare function mutateFilter<T>(array: T[], predicate: (value: T, index: number, array: T[]) => unknown): void;
declare function mutateRemove<T>(array: T[], item: T): void;
declare const dedupeArray: <T>(array: readonly T[]) => T[];
/** Checks if both arrays contain the same values. Order doesn't matter. */
declare const arrayRefEquals: <T>(a: readonly T[], b: readonly T[]) => boolean;
/** function that trims too long string */
declare function trimString(str: string, maxLength: number): string;
declare function findIndexById<T extends {
id: string;
}>(array: T[], id: string): number;
declare function findItemById<T extends {
id: string;
}>(array: T[], id: string): T | undefined;
declare const utils_info: typeof info;
declare const utils_log: typeof log;
declare const utils_warn: typeof warn;
declare const utils_error: typeof error;
declare const utils_formatTime: typeof formatTime;
declare const utils_createCallbackStack: typeof createCallbackStack;
declare const utils_callArrayProp: typeof callArrayProp;
declare const utils_pushToArrayProp: typeof pushToArrayProp;
declare const utils_mutateFilter: typeof mutateFilter;
declare const utils_mutateRemove: typeof mutateRemove;
declare const utils_dedupeArray: typeof dedupeArray;
declare const utils_arrayRefEquals: typeof arrayRefEquals;
declare const utils_trimString: typeof trimString;
declare const utils_findIndexById: typeof findIndexById;
declare const utils_findItemById: typeof findItemById;
declare namespace utils {
export {
utils_info as info,
utils_log as log,
utils_warn as warn,
utils_error as error,
utils_formatTime as formatTime,
utils_createCallbackStack as createCallbackStack,
utils_callArrayProp as callArrayProp,
utils_pushToArrayProp as pushToArrayProp,
utils_mutateFilter as mutateFilter,
utils_mutateRemove as mutateRemove,
utils_dedupeArray as dedupeArray,
utils_arrayRefEquals as arrayRefEquals,
utils_trimString as trimString,
utils_findIndexById as findIndexById,
utils_findItemById as findItemById,
};
}
export { callArrayProp as a, mutateRemove as b, createCallbackStack as c, dedupeArray as d, error as e, formatTime as f, arrayRefEquals as g, findIndexById as h, info as i, findItemById as j, log as l, mutateFilter as m, pushToArrayProp as p, trimString as t, utils as u, warn as w };
declare const WINDOW_PROJECTPATH_PROPERTY = "$sdt_projectPath";
declare const LOCATION_ATTRIBUTE_NAME = "data-source-loc";
declare const variables_WINDOW_PROJECTPATH_PROPERTY: typeof WINDOW_PROJECTPATH_PROPERTY;
declare const variables_LOCATION_ATTRIBUTE_NAME: typeof LOCATION_ATTRIBUTE_NAME;
declare namespace variables {
export {
variables_WINDOW_PROJECTPATH_PROPERTY as WINDOW_PROJECTPATH_PROPERTY,
variables_LOCATION_ATTRIBUTE_NAME as LOCATION_ATTRIBUTE_NAME,
};
}
export { LOCATION_ATTRIBUTE_NAME as L, WINDOW_PROJECTPATH_PROPERTY as W, variables as v };
+24
-39
> @solid-devtools/shared@0.9.2 build /home/runner/work/solid-devtools/solid-devtools/packages/shared
> @solid-devtools/shared@0.10.0 build /home/runner/work/solid-devtools/solid-devtools/packages/shared
> tsup
CLI Building entry: src/index.ts, src/bridge.ts, src/graph.ts, src/utils.ts, src/variables.ts, src/serialize.ts, src/primitives.ts
CLI Building entry: src/index.ts, src/utils.ts, src/variables.ts, src/primitives.ts
CLI Using tsconfig: tsconfig.json
CLI tsup v6.3.0
CLI tsup v6.4.0
CLI Using tsup config: /home/runner/work/solid-devtools/solid-devtools/packages/shared/tsup.config.ts
CLI Target: node14
CLI Target: esnext
CLI Cleaning output folder
CJS Build start
ESM Build start
CJS dist/index.cjs 12.71 KB
CJS dist/bridge.cjs 2.35 KB
CJS dist/graph.cjs 1.67 KB
CJS dist/utils.cjs 3.11 KB
CJS dist/variables.cjs 1.55 KB
CJS dist/serialize.cjs 4.23 KB
CJS dist/primitives.cjs 4.85 KB
CJS ⚡️ Build success in 51ms
ESM dist/index.js 569.00 B
ESM dist/bridge.js 301.00 B
ESM dist/chunk-PR5VEWAU.js 1.35 KB
ESM dist/graph.js 127.00 B
ESM dist/chunk-MMTBIUS3.js 847.00 B
ESM dist/utils.js 449.00 B
ESM dist/chunk-TOZEPNWL.js 2.27 KB
ESM dist/variables.js 301.00 B
ESM dist/chunk-SMZVIT3T.js 734.00 B
ESM dist/serialize.js 243.00 B
ESM dist/chunk-PRL2GOEE.js 3.40 KB
ESM dist/primitives.js 383.00 B
ESM dist/chunk-SKMVYPML.js 3.68 KB
CJS dist/index.cjs 8.30 KB
CJS dist/utils.cjs 3.56 KB
CJS dist/variables.cjs 1.28 KB
CJS dist/primitives.cjs 5.56 KB
CJS ⚡️ Build success in 48ms
ESM dist/index.js 311.00 B
ESM dist/utils.js 513.00 B
ESM dist/chunk-OKMKW7SY.js 2.72 KB
ESM dist/variables.js 195.00 B
ESM dist/chunk-FCDQ4DIH.js 450.00 B
ESM dist/primitives.js 465.00 B
ESM dist/chunk-BGRVHE3T.js 4.33 KB
ESM dist/chunk-UICA3PK6.js 191.00 B
ESM ⚡️ Build success in 48ms
DTS Build start
DTS ⚡️ Build success in 3511ms
DTS dist/index.d.ts 422.00 B
DTS dist/bridge.d.ts 376.00 B
DTS dist/graph.d.ts 351.00 B
DTS dist/primitives.d.ts 347.00 B
DTS dist/serialize.d.ts 213.00 B
DTS dist/utils.d.ts 262.00 B
DTS dist/variables.d.ts 168.00 B
DTS dist/bridge-a7e7c461.d.ts 4.00 KB
DTS dist/graph-25a6fe11.d.ts 5.26 KB
DTS dist/primitives-62ee95a0.d.ts 3.60 KB
DTS dist/serialize-dbe0408c.d.ts 2.93 KB
DTS dist/utils-2ecebe79.d.ts 2.67 KB
DTS dist/variables-8a89bbc5.d.ts 1.08 KB
DTS ⚡️ Build success in 3720ms
DTS dist/index.d.ts 320.00 B
DTS dist/primitives.d.ts 471.00 B
DTS dist/utils.d.ts 300.00 B
DTS dist/variables.d.ts 106.00 B
DTS dist/primitives-d935132e.d.ts 4.50 KB
DTS dist/utils-725a6bed.d.ts 3.19 KB
DTS dist/variables-a4699ecf.d.ts 574.00 B
> @solid-devtools/shared@0.9.2 test /home/runner/work/solid-devtools/solid-devtools/packages/shared
> @solid-devtools/shared@0.10.0 test /home/runner/work/solid-devtools/solid-devtools/packages/shared
> vitest

@@ -8,8 +8,6 @@

✓ test/serialise.test.ts  (36 tests) 11ms
No test files found, exiting with code 0
Test Files  1 passed (1)
 Tests  36 passed (36)
 Start at  17:45:25
 Duration  2.55s (transform 1.16s, setup 0ms, collect 173ms, tests 11ms)
include: **/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}
exclude: **/node_modules/**, **/dist/**, **/cypress/**, **/.{idea,git,cache,output,temp}/**
watch exclude: **/node_modules/**, **/dist/**
> @solid-devtools/shared@0.9.2 typecheck /home/runner/work/solid-devtools/solid-devtools/packages/shared
> tsc --noEmit
> @solid-devtools/shared@0.10.0 typecheck /home/runner/work/solid-devtools/solid-devtools/packages/shared
> tsc --noEmit --paths null
# solid-devtools-shared
## 0.10.0
### Minor Changes
- a6b55b0: Move value serialization logic to debugger
- 1990be5: Move graph types from `@solid-devtools/shared` to `@solid-devtools/debugger`
### Patch Changes
- d7e98da: Move some debugger related types from @solid-devtools/shared to @solid-devtools/debugger
## 0.9.2

@@ -4,0 +15,0 @@

@@ -23,6 +23,3 @@ "use strict";

__export(src_exports, {
bridge: () => bridge_exports,
graph: () => graph_exports,
primitives: () => primitives_exports,
serialize: () => serialize_exports,
utils: () => utils_exports,

@@ -33,143 +30,2 @@ variables: () => variables_exports

// src/bridge.ts
var bridge_exports = {};
__export(bridge_exports, {
LOG_MESSAGES: () => LOG_MESSAGES,
onWindowMessage: () => onWindowMessage,
once: () => once,
postWindowMessage: () => postWindowMessage,
startListeningWindowMessages: () => startListeningWindowMessages
});
// src/utils.ts
var utils_exports = {};
__export(utils_exports, {
arrayRefEquals: () => arrayRefEquals,
callArrayProp: () => callArrayProp,
dedupeArray: () => dedupeArray,
findIndexById: () => findIndexById,
findItemById: () => findItemById,
formatTime: () => formatTime,
info: () => info,
log: () => log,
mutateFilter: () => mutateFilter,
mutateRemove: () => mutateRemove,
pushToArrayProp: () => pushToArrayProp,
trimString: () => trimString,
warn: () => warn
});
var getLogLabel = () => [
`%csolid-devtools`,
"color: #fff; background: #2c4f7c; padding: 1px 4px;"
];
function info(data) {
console.info(...getLogLabel(), data);
return data;
}
function log(...args) {
console.log(...getLogLabel(), ...args);
}
function warn(...args) {
console.warn(...getLogLabel(), ...args);
}
function formatTime(d = new Date()) {
return ("0" + d.getHours()).slice(-2) + ":" + ("0" + d.getMinutes()).slice(-2) + ":" + ("0" + d.getSeconds()).slice(-2);
}
function callArrayProp(object, key, ...args) {
const arr = object[key];
if (arr)
for (const cb of arr)
cb(...args);
}
function pushToArrayProp(object, key, value) {
let arr = object[key];
if (arr)
arr.push(value);
else
arr = object[key] = [value];
return arr;
}
function mutateFilter(array, predicate) {
const temp = array.filter(predicate);
array.length = 0;
array.push.apply(array, temp);
}
function mutateRemove(array, item) {
array.splice(array.indexOf(item), 1);
}
var dedupeArray = (array) => Array.from(new Set(array));
var arrayRefEquals = (a, b) => a === b || a.length === b.length && a.every((e) => b.includes(e));
function trimString(str, maxLength) {
if (str.length <= maxLength)
return str;
return str.slice(0, maxLength) + "\u2026";
}
function findIndexById(array, id) {
for (let i = 0; i < array.length; i++)
if (array[i].id === id)
return i;
return -1;
}
function findItemById(array, id) {
for (let i = 0; i < array.length; i++) {
const item = array[i];
if (item.id === id)
return item;
}
}
// src/bridge.ts
var LOG_MESSAGES = false;
var postWindowMessage = (id, payload) => {
LOG_MESSAGES && log("message posted:", id, payload);
postMessage({ id, payload }, "*");
};
var listeners = {};
function startListeningWindowMessages() {
if (typeof window === "undefined")
return;
addEventListener("message", (event) => {
var _a, _b;
const id = (_a = event.data) == null ? void 0 : _a.id;
if (typeof id !== "string")
return;
(_b = listeners[id]) == null ? void 0 : _b.forEach((f) => f(event.data.payload));
});
}
var onWindowMessage = (id, handler) => {
let arr = listeners[id];
if (!arr)
arr = listeners[id] = [];
arr.push(handler);
return () => listeners[id] = arr.filter((l) => l !== handler);
};
function once(method, id, handler) {
const unsub = method(id, (...cbArgs) => {
unsub();
return handler(...cbArgs);
});
return unsub;
}
// src/graph.ts
var graph_exports = {};
__export(graph_exports, {
NodeType: () => NodeType,
getOwner: () => getOwner
});
var import_solid_js = require("solid-js");
var NodeType = /* @__PURE__ */ ((NodeType2) => {
NodeType2[NodeType2["Root"] = 0] = "Root";
NodeType2[NodeType2["Component"] = 1] = "Component";
NodeType2[NodeType2["Effect"] = 2] = "Effect";
NodeType2[NodeType2["Render"] = 3] = "Render";
NodeType2[NodeType2["Memo"] = 4] = "Memo";
NodeType2[NodeType2["Computation"] = 5] = "Computation";
NodeType2[NodeType2["Refresh"] = 6] = "Refresh";
NodeType2[NodeType2["Context"] = 7] = "Context";
NodeType2[NodeType2["Signal"] = 8] = "Signal";
return NodeType2;
})(NodeType || {});
var getOwner = import_solid_js.getOwner;
// src/primitives.ts

@@ -182,4 +38,6 @@ var primitives_exports = {};

createHover: () => createHover,
createPingedSignal: () => createPingedSignal,
defer: () => defer,
makeHoverElementListener: () => makeHoverElementListener,
trackFromListen: () => trackFromListen,
untrackedCallback: () => untrackedCallback,

@@ -189,8 +47,8 @@ useIsMobile: () => useIsMobile,

});
var import_solid_js2 = require("solid-js");
var import_utils2 = require("@solid-primitives/utils");
var import_solid_js = require("solid-js");
var import_utils = require("@solid-primitives/utils");
var import_event_listener = require("@solid-primitives/event-listener");
var import_rootless = require("@solid-primitives/rootless");
var import_media = require("@solid-primitives/media");
var untrackedCallback = (fn) => (...a) => (0, import_solid_js2.untrack)(fn.bind(void 0, ...a));
var untrackedCallback = (fn) => (...a) => (0, import_solid_js.untrack)(fn.bind(void 0, ...a));
var useIsTouch = (0, import_rootless.createSharedRoot)(() => (0, import_media.createMediaQuery)("(hover: none)"));

@@ -207,3 +65,3 @@ var useIsMobile = (0, import_rootless.createSharedRoot)(() => (0, import_media.createMediaQuery)("(max-width: 640px)"));

});
(0, import_solid_js2.onCleanup)(() => {
(0, import_solid_js.onCleanup)(() => {
mounted = false;

@@ -224,4 +82,4 @@ if (state)

function createConsumers(initial = []) {
const [consumers, setConsumers] = (0, import_solid_js2.createSignal)([...initial], { name: "consumers" });
const enabled = (0, import_solid_js2.createMemo)(() => consumers().some((consumer) => consumer()));
const [consumers, setConsumers] = (0, import_solid_js.createSignal)([...initial], { name: "consumers" });
const enabled = (0, import_solid_js.createMemo)(() => consumers().some((consumer) => consumer()));
return [

@@ -231,3 +89,3 @@ enabled,

setConsumers((p) => [...p, consumer]);
(0, import_utils2.onRootCleanup)(() => setConsumers((p) => p.filter((p2) => p2 !== consumer)));
(0, import_utils.onRootCleanup)(() => setConsumers((p) => p.filter((p2) => p2 !== consumer)));
}

@@ -237,5 +95,5 @@ ];

function createDerivedSignal(fallback, options) {
const [source, setSource] = (0, import_solid_js2.createSignal)();
const [source, setSource] = (0, import_solid_js.createSignal)();
return [
(0, import_solid_js2.createMemo)(
(0, import_solid_js.createMemo)(
() => {

@@ -249,4 +107,4 @@ const sourceRef = source();

(newSource) => {
if (newSource && (0, import_solid_js2.getOwner)())
(0, import_solid_js2.onCleanup)(() => setSource((p) => p === newSource ? void 0 : p));
if (newSource && (0, import_solid_js.getOwner)())
(0, import_solid_js.onCleanup)(() => setSource((p) => p === newSource ? void 0 : p));
return setSource(() => newSource);

@@ -283,3 +141,3 @@ }

}
const result = (0, import_solid_js2.untrack)(() => fn(input, prevInput, prevValue));
const result = (0, import_solid_js.untrack)(() => fn(input, prevInput, prevValue));
prevInput = input;

@@ -290,102 +148,117 @@ return result;

function atom(value, options) {
const [state, setState] = (0, import_solid_js2.createSignal)(value, { internal: true, ...options });
const [state, setState] = (0, import_solid_js.createSignal)(value, { internal: true, ...options });
return (...args) => args.length === 1 ? setState(args[0]) : state();
}
function trackFromListen(listen) {
const [track, trigger] = (0, import_solid_js.createSignal)(void 0, { equals: false });
listen(trigger);
return track;
}
function createPingedSignal(track, timeout = 400) {
const [isUpdated, setIsUpdated] = (0, import_solid_js.createSignal)(false);
let timeoutId;
(0, import_solid_js.createComputed)(
defer(track, () => {
setIsUpdated(true);
clearTimeout(timeoutId);
timeoutId = setTimeout(() => setIsUpdated(false), timeout);
})
);
(0, import_solid_js.onCleanup)(() => clearTimeout(timeoutId));
return isUpdated;
}
// src/serialize.ts
var serialize_exports = {};
__export(serialize_exports, {
ElementMap: () => ElementMap,
INFINITY: () => INFINITY,
NAN: () => NAN,
NEGATIVE_INFINITY: () => NEGATIVE_INFINITY,
ValueType: () => ValueType,
encodeValue: () => encodeValue
// src/utils.ts
var utils_exports = {};
__export(utils_exports, {
arrayRefEquals: () => arrayRefEquals,
callArrayProp: () => callArrayProp,
createCallbackStack: () => createCallbackStack,
dedupeArray: () => dedupeArray,
error: () => error,
findIndexById: () => findIndexById,
findItemById: () => findItemById,
formatTime: () => formatTime,
info: () => info,
log: () => log,
mutateFilter: () => mutateFilter,
mutateRemove: () => mutateRemove,
pushToArrayProp: () => pushToArrayProp,
trimString: () => trimString,
warn: () => warn
});
var INFINITY = "__$sdt-Infinity__";
var NEGATIVE_INFINITY = "__$sdt-NegativeInfinity__";
var NAN = "__$sdt-NaN__";
var ValueType = /* @__PURE__ */ ((ValueType2) => {
ValueType2[ValueType2["Number"] = 0] = "Number";
ValueType2[ValueType2["Boolean"] = 1] = "Boolean";
ValueType2[ValueType2["String"] = 2] = "String";
ValueType2[ValueType2["Null"] = 3] = "Null";
ValueType2[ValueType2["Undefined"] = 4] = "Undefined";
ValueType2[ValueType2["Symbol"] = 5] = "Symbol";
ValueType2[ValueType2["Array"] = 6] = "Array";
ValueType2[ValueType2["Object"] = 7] = "Object";
ValueType2[ValueType2["Function"] = 8] = "Function";
ValueType2[ValueType2["Getter"] = 9] = "Getter";
ValueType2[ValueType2["Element"] = 10] = "Element";
ValueType2[ValueType2["Instance"] = 11] = "Instance";
return ValueType2;
})(ValueType || {});
function encodeValue(value, deep, elementMap) {
if (typeof value === "number") {
if (value === Infinity)
return { type: 0 /* Number */, value: INFINITY };
if (value === -Infinity)
return { type: 0 /* Number */, value: NEGATIVE_INFINITY };
if (Number.isNaN(value))
return { type: 0 /* Number */, value: NAN };
return { type: 0 /* Number */, value };
var getLogLabel = () => [
`%csolid-devtools`,
"color: #fff; background: #2c4f7c; padding: 1px 4px;"
];
function info(data) {
console.info(...getLogLabel(), data);
return data;
}
function log(...args) {
console.log(...getLogLabel(), ...args);
}
function warn(...args) {
console.warn(...getLogLabel(), ...args);
}
function error(...args) {
console.error(...getLogLabel(), ...args);
}
function formatTime(d = new Date()) {
return ("0" + d.getHours()).slice(-2) + ":" + ("0" + d.getMinutes()).slice(-2) + ":" + ("0" + d.getSeconds()).slice(-2);
}
var createCallbackStack = () => {
let stack = [];
const clear = () => stack = [];
return {
push: (...callbacks) => stack.push(...callbacks),
execute(arg0, arg1, arg2, arg3) {
stack.forEach((cb) => cb(arg0, arg1, arg2, arg3));
clear();
},
clear
};
};
function callArrayProp(object, key, ...args) {
const arr = object[key];
if (arr)
for (const cb of arr)
cb(...args);
}
function pushToArrayProp(object, key, value) {
let arr = object[key];
if (arr)
arr.push(value);
else
arr = object[key] = [value];
return arr;
}
function mutateFilter(array, predicate) {
const temp = array.filter(predicate);
array.length = 0;
array.push.apply(array, temp);
}
function mutateRemove(array, item) {
array.splice(array.indexOf(item), 1);
}
var dedupeArray = (array) => Array.from(new Set(array));
var arrayRefEquals = (a, b) => a === b || a.length === b.length && a.every((e) => b.includes(e));
function trimString(str, maxLength) {
if (str.length <= maxLength)
return str;
return str.slice(0, maxLength) + "\u2026";
}
function findIndexById(array, id) {
for (let i = 0; i < array.length; i++)
if (array[i].id === id)
return i;
return -1;
}
function findItemById(array, id) {
for (let i = 0; i < array.length; i++) {
const item = array[i];
if (item.id === id)
return item;
}
if (typeof value === "boolean")
return { type: 1 /* Boolean */, value };
if (typeof value === "string")
return { type: 2 /* String */, value };
if (value === null)
return { type: 3 /* Null */ };
if (value === void 0)
return { type: 4 /* Undefined */ };
if (typeof value === "symbol")
return { type: 5 /* Symbol */, value: value.description ?? "" };
if (typeof value === "function")
return { type: 8 /* Function */, value: value.name };
if (value instanceof HTMLElement)
return {
type: 10 /* Element */,
value: elementMap ? { name: value.tagName, id: elementMap.set(value) } : { name: value.tagName }
};
if (Array.isArray(value)) {
const payload = { type: 6 /* Array */, value: value.length };
if (deep)
payload.children = value.map((item) => encodeValue(item, true, elementMap));
return payload;
}
const s = Object.prototype.toString.call(value);
const name = s.slice(8, -1);
if (name === "Object") {
const obj = value;
const payload = {
type: 7 /* Object */,
value: Object.keys(obj).length
};
if (deep) {
const children = payload.children = {};
for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
children[key] = descriptor.get ? { type: 9 /* Getter */, value: key } : encodeValue(descriptor.value, true, elementMap);
}
}
return payload;
}
return { type: 11 /* Instance */, value: name };
}
var lastId = 0;
var ElementMap = class {
obj = {};
map = /* @__PURE__ */ new WeakMap();
get(id) {
return this.obj[id];
}
set(element) {
let id = this.map.get(element);
if (id !== void 0)
return id;
id = (lastId++).toString();
this.obj[id] = element;
this.map.set(element, id);
return id;
}
};

@@ -395,21 +268,12 @@ // src/variables.ts

__export(variables_exports, {
INTERNAL: () => INTERNAL,
LOCATION_ATTRIBUTE_NAME: () => LOCATION_ATTRIBUTE_NAME,
UNNAMED: () => UNNAMED,
WINDOW_PROJECTPATH_PROPERTY: () => WINDOW_PROJECTPATH_PROPERTY,
WINDOW_WRAP_STORE_PROPERTY: () => WINDOW_WRAP_STORE_PROPERTY
WINDOW_PROJECTPATH_PROPERTY: () => WINDOW_PROJECTPATH_PROPERTY
});
var WINDOW_PROJECTPATH_PROPERTY = "$sdt_projectPath";
var WINDOW_WRAP_STORE_PROPERTY = "$sdt_wrapStore";
var LOCATION_ATTRIBUTE_NAME = "data-source-loc";
var UNNAMED = "(unnamed)";
var INTERNAL = Symbol("internal");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
bridge,
graph,
primitives,
serialize,
utils,
variables
});

@@ -1,9 +0,8 @@

export { b as bridge } from './bridge-a7e7c461.js';
export { g as graph } from './graph-25a6fe11.js';
export { p as primitives } from './primitives-62ee95a0.js';
export { s as serialize } from './serialize-dbe0408c.js';
export { u as utils } from './utils-2ecebe79.js';
export { v as variables } from './variables-8a89bbc5.js';
export { p as primitives } from './primitives-d935132e.js';
export { u as utils } from './utils-725a6bed.js';
export { v as variables } from './variables-a4699ecf.js';
import 'solid-js';
import 'solid-js/types/reactive/signal';
import '@solid-primitives/utils';
import 'solid-js';
import 'type-fest';
import '@solid-primitives/event-bus';
import {
bridge_exports
} from "./chunk-PR5VEWAU.js";
import {
graph_exports
} from "./chunk-MMTBIUS3.js";
import {
utils_exports
} from "./chunk-TOZEPNWL.js";
} from "./chunk-OKMKW7SY.js";
import {
variables_exports
} from "./chunk-SMZVIT3T.js";
} from "./chunk-FCDQ4DIH.js";
import {
serialize_exports
} from "./chunk-PRL2GOEE.js";
import {
primitives_exports
} from "./chunk-SKMVYPML.js";
} from "./chunk-BGRVHE3T.js";
import "./chunk-UICA3PK6.js";
export {
bridge_exports as bridge,
graph_exports as graph,
primitives_exports as primitives,
serialize_exports as serialize,
utils_exports as utils,
variables_exports as variables
};

@@ -27,4 +27,6 @@ "use strict";

createHover: () => createHover,
createPingedSignal: () => createPingedSignal,
defer: () => defer,
makeHoverElementListener: () => makeHoverElementListener,
trackFromListen: () => trackFromListen,
untrackedCallback: () => untrackedCallback,

@@ -132,2 +134,20 @@ useIsMobile: () => useIsMobile,

}
function trackFromListen(listen) {
const [track, trigger] = (0, import_solid_js.createSignal)(void 0, { equals: false });
listen(trigger);
return track;
}
function createPingedSignal(track, timeout = 400) {
const [isUpdated, setIsUpdated] = (0, import_solid_js.createSignal)(false);
let timeoutId;
(0, import_solid_js.createComputed)(
defer(track, () => {
setIsUpdated(true);
clearTimeout(timeoutId);
timeoutId = setTimeout(() => setIsUpdated(false), timeout);
})
);
(0, import_solid_js.onCleanup)(() => clearTimeout(timeoutId));
return isUpdated;
}
// Annotate the CommonJS export names for ESM import in node:

@@ -139,4 +159,6 @@ 0 && (module.exports = {

createHover,
createPingedSignal,
defer,
makeHoverElementListener,
trackFromListen,
untrackedCallback,

@@ -143,0 +165,0 @@ useIsMobile,

@@ -0,4 +1,6 @@

import 'solid-js';
import 'solid-js/types/reactive/signal';
import 'solid-js';
import '@solid-primitives/utils';
export { A as Atom, D as DerivedSignal, g as atom, d as createConsumers, e as createDerivedSignal, c as createHover, f as defer, m as makeHoverElementListener, u as untrackedCallback, b as useIsMobile, a as useIsTouch } from './primitives-62ee95a0.js';
import 'type-fest';
import '@solid-primitives/event-bus';
export { A as Atom, D as DerivedSignal, W as WritableDeep, g as atom, d as createConsumers, e as createDerivedSignal, c as createHover, h as createPingedSignal, f as defer, m as makeHoverElementListener, t as trackFromListen, u as untrackedCallback, b as useIsMobile, a as useIsTouch } from './primitives-d935132e.js';

@@ -6,8 +6,10 @@ import {

createHover,
createPingedSignal,
defer,
makeHoverElementListener,
trackFromListen,
untrackedCallback,
useIsMobile,
useIsTouch
} from "./chunk-SKMVYPML.js";
} from "./chunk-BGRVHE3T.js";
import "./chunk-UICA3PK6.js";

@@ -19,4 +21,6 @@ export {

createHover,
createPingedSignal,
defer,
makeHoverElementListener,
trackFromListen,
untrackedCallback,

@@ -23,0 +27,0 @@ useIsMobile,

@@ -25,3 +25,5 @@ "use strict";

callArrayProp: () => callArrayProp,
createCallbackStack: () => createCallbackStack,
dedupeArray: () => dedupeArray,
error: () => error,
findIndexById: () => findIndexById,

@@ -53,5 +55,20 @@ findItemById: () => findItemById,

}
function error(...args) {
console.error(...getLogLabel(), ...args);
}
function formatTime(d = new Date()) {
return ("0" + d.getHours()).slice(-2) + ":" + ("0" + d.getMinutes()).slice(-2) + ":" + ("0" + d.getSeconds()).slice(-2);
}
var createCallbackStack = () => {
let stack = [];
const clear = () => stack = [];
return {
push: (...callbacks) => stack.push(...callbacks),
execute(arg0, arg1, arg2, arg3) {
stack.forEach((cb) => cb(arg0, arg1, arg2, arg3));
clear();
},
clear
};
};
function callArrayProp(object, key, ...args) {

@@ -103,3 +120,5 @@ const arr = object[key];

callArrayProp,
createCallbackStack,
dedupeArray,
error,
findIndexById,

@@ -106,0 +125,0 @@ findItemById,

@@ -1,1 +0,1 @@

export { b as arrayRefEquals, c as callArrayProp, d as dedupeArray, e as findIndexById, g as findItemById, f as formatTime, i as info, l as log, m as mutateFilter, a as mutateRemove, p as pushToArrayProp, t as trimString, w as warn } from './utils-2ecebe79.js';
export { g as arrayRefEquals, a as callArrayProp, c as createCallbackStack, d as dedupeArray, e as error, h as findIndexById, j as findItemById, f as formatTime, i as info, l as log, m as mutateFilter, b as mutateRemove, p as pushToArrayProp, t as trimString, w as warn } from './utils-725a6bed.js';
import {
arrayRefEquals,
callArrayProp,
createCallbackStack,
dedupeArray,
error,
findIndexById,

@@ -15,3 +17,3 @@ findItemById,

warn
} from "./chunk-TOZEPNWL.js";
} from "./chunk-OKMKW7SY.js";
import "./chunk-UICA3PK6.js";

@@ -21,3 +23,5 @@ export {

callArrayProp,
createCallbackStack,
dedupeArray,
error,
findIndexById,

@@ -24,0 +28,0 @@ findItemById,

@@ -23,21 +23,12 @@ "use strict";

__export(variables_exports, {
INTERNAL: () => INTERNAL,
LOCATION_ATTRIBUTE_NAME: () => LOCATION_ATTRIBUTE_NAME,
UNNAMED: () => UNNAMED,
WINDOW_PROJECTPATH_PROPERTY: () => WINDOW_PROJECTPATH_PROPERTY,
WINDOW_WRAP_STORE_PROPERTY: () => WINDOW_WRAP_STORE_PROPERTY
WINDOW_PROJECTPATH_PROPERTY: () => WINDOW_PROJECTPATH_PROPERTY
});
module.exports = __toCommonJS(variables_exports);
var WINDOW_PROJECTPATH_PROPERTY = "$sdt_projectPath";
var WINDOW_WRAP_STORE_PROPERTY = "$sdt_wrapStore";
var LOCATION_ATTRIBUTE_NAME = "data-source-loc";
var UNNAMED = "(unnamed)";
var INTERNAL = Symbol("internal");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
INTERNAL,
LOCATION_ATTRIBUTE_NAME,
UNNAMED,
WINDOW_PROJECTPATH_PROPERTY,
WINDOW_WRAP_STORE_PROPERTY
WINDOW_PROJECTPATH_PROPERTY
});

@@ -1,1 +0,1 @@

export { I as INTERNAL, L as LOCATION_ATTRIBUTE_NAME, U as UNNAMED, W as WINDOW_PROJECTPATH_PROPERTY, a as WINDOW_WRAP_STORE_PROPERTY } from './variables-8a89bbc5.js';
export { L as LOCATION_ATTRIBUTE_NAME, W as WINDOW_PROJECTPATH_PROPERTY } from './variables-a4699ecf.js';
import {
INTERNAL,
LOCATION_ATTRIBUTE_NAME,
UNNAMED,
WINDOW_PROJECTPATH_PROPERTY,
WINDOW_WRAP_STORE_PROPERTY
} from "./chunk-SMZVIT3T.js";
WINDOW_PROJECTPATH_PROPERTY
} from "./chunk-FCDQ4DIH.js";
import "./chunk-UICA3PK6.js";
export {
INTERNAL,
LOCATION_ATTRIBUTE_NAME,
UNNAMED,
WINDOW_PROJECTPATH_PROPERTY,
WINDOW_WRAP_STORE_PROPERTY
WINDOW_PROJECTPATH_PROPERTY
};
{
"name": "@solid-devtools/shared",
"version": "0.9.2",
"version": "0.10.0",
"license": "MIT",

@@ -31,12 +31,2 @@ "author": "Damian Tarnawski <gthetarnav@gmail.com>",

},
"./bridge": {
"import": "./dist/bridge.js",
"require": "./dist/bridge.cjs",
"types": "./dist/bridge.d.ts"
},
"./graph": {
"import": "./dist/graph.js",
"require": "./dist/graph.cjs",
"types": "./dist/graph.d.ts"
},
"./utils": {

@@ -52,7 +42,2 @@ "import": "./dist/utils.js",

},
"./serialize": {
"import": "./dist/serialize.js",
"require": "./dist/serialize.cjs",
"types": "./dist/serialize.d.ts"
},
"./primitives": {

@@ -66,8 +51,2 @@ "import": "./dist/primitives.js",

"*": {
"bridge": [
"./dist/bridge.d.ts"
],
"graph": [
"./dist/graph.d.ts"
],
"utils": [

@@ -79,5 +58,2 @@ "./dist/utils.d.ts"

],
"serialize": [
"./dist/serialize.d.ts"
],
"primitives": [

@@ -88,10 +64,4 @@ "./dist/primitives.d.ts"

},
"devDependencies": {
"solid-js": "^1.6.0",
"tsup": "^6.3.0",
"typescript": "^4.8.4",
"vitest": "^0.23.4"
},
"peerDependencies": {
"solid-js": "^1.5.0"
"solid-js": "^1.6.2"
},

@@ -106,3 +76,3 @@ "dependencies": {

"@solid-primitives/utils": "^3.1.0",
"type-fest": "^3.1.0"
"type-fest": "^3.2.0"
},

@@ -113,4 +83,4 @@ "scripts": {

"test": "vitest",
"typecheck": "tsc --noEmit"
"typecheck": "tsc --noEmit --paths null"
}
}

@@ -1,6 +0,3 @@

export * as bridge from './bridge'
export * as graph from './graph'
export * as primitives from './primitives'
export * as serialize from './serialize'
export * as utils from './utils'
export * as variables from './variables'

@@ -0,1 +1,10 @@

import {
Accessor,
createMemo,
createSignal,
getOwner,
onCleanup,
untrack,
createComputed,
} from 'solid-js'
import type {

@@ -9,3 +18,2 @@ AccessorArray,

} from 'solid-js/types/reactive/signal'
import { Accessor, createMemo, createSignal, getOwner, onCleanup, untrack } from 'solid-js'
import { AnyFunction, onRootCleanup } from '@solid-primitives/utils'

@@ -15,3 +23,11 @@ import { makeEventListener } from '@solid-primitives/event-listener'

import { createMediaQuery } from '@solid-primitives/media'
import { Primitive } from 'type-fest'
import { Listen } from '@solid-primitives/event-bus'
export type WritableDeep<T> = 0 extends 1 & T
? T
: T extends Primitive
? T
: { -readonly [K in keyof T]: WritableDeep<T[K]> }
export const untrackedCallback = <Fn extends AnyFunction>(fn: Fn): Fn =>

@@ -169,1 +185,26 @@ ((...a: Parameters<Fn>) => untrack<ReturnType<Fn>>(fn.bind(void 0, ...a))) as any

}
export function trackFromListen(listen: Listen): VoidFunction {
const [track, trigger] = createSignal(undefined, { equals: false })
listen(trigger)
return track
}
/**
* Creates a signal that will be activated for a given amount of time on every "ping" — a call to the listener function.
*/
export function createPingedSignal(track: VoidFunction, timeout = 400): Accessor<boolean> {
const [isUpdated, setIsUpdated] = createSignal(false)
let timeoutId: ReturnType<typeof setTimeout> | undefined
createComputed(
defer(track, () => {
setIsUpdated(true)
clearTimeout(timeoutId)
timeoutId = setTimeout(() => setIsUpdated(false), timeout)
}),
)
onCleanup(() => clearTimeout(timeoutId))
return isUpdated
}

@@ -7,2 +7,3 @@ const getLogLabel = () => [

export function info<T>(data: T): T {
// eslint-disable-next-line no-console
console.info(...getLogLabel(), data)

@@ -13,8 +14,15 @@ return data

export function log(...args: any[]): void {
// eslint-disable-next-line no-console
console.log(...getLogLabel(), ...args)
}
export function warn(...args: any[]): void {
// eslint-disable-next-line no-console
console.warn(...getLogLabel(), ...args)
}
export function error(...args: any[]): void {
// eslint-disable-next-line no-console
console.error(...getLogLabel(), ...args)
}
export function formatTime(d: Date = new Date()): string {

@@ -30,2 +38,19 @@ return (

export const createCallbackStack = <A0 = void, A1 = void, A2 = void, A3 = void>(): {
push: (...callbacks: ((arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void)[]) => void
execute: (arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void
clear: VoidFunction
} => {
let stack: Array<(arg0: A0, arg1: A1, arg2: A2, arg3: A3) => void> = []
const clear: VoidFunction = () => (stack = [])
return {
push: (...callbacks) => stack.push(...callbacks),
execute(arg0, arg1, arg2, arg3) {
stack.forEach(cb => cb(arg0, arg1, arg2, arg3))
clear()
},
clear,
}
}
export function callArrayProp<

@@ -32,0 +57,0 @@ K extends PropertyKey,

export const WINDOW_PROJECTPATH_PROPERTY = '$sdt_projectPath'
export const WINDOW_WRAP_STORE_PROPERTY = '$sdt_wrapStore'
export const LOCATION_ATTRIBUTE_NAME = 'data-source-loc'
export const UNNAMED = '(unnamed)'
export const INTERNAL = Symbol('internal')
import { R as RootsUpdates, C as ComputationUpdate, N as NodeID, M as Mapped } from './graph-25a6fe11.js';
import { E as EncodedValue } from './serialize-dbe0408c.js';
declare const LOG_MESSAGES = false;
interface Messages {
SolidOnPage: string;
DevtoolsScriptConnected: number;
DevtoolsPanelConnected: {};
Versions: {
client: string;
expectedClient: string;
extension: string;
};
/** devtools -> client: user switching between Solid devtools and other panel */
PanelVisibility: boolean;
/** devtools -> client: the chrome devtools got entirely closed */
PanelClosed: true;
ResetPanel: {};
StructureUpdate: RootsUpdates;
ComputationUpdates: ComputationUpdate[];
/** client -> devtools: signal deep value */
SignalUpdates: {
signals: {
id: NodeID;
value: EncodedValue<boolean>;
}[];
update: boolean;
};
/** client -> devtools: encoded props object */
PropsUpdate: Mapped.Props;
/** client -> devtools: inspected node value update */
ValueUpdate: {
value: EncodedValue<boolean>;
update: boolean;
};
/** devtools -> client: force the debugger to walk the whole tree and send it */
ForceUpdate: {};
/** client -> devtools: send component clicked with the locator to the extension */
ClientInspectedNode: NodeID;
/** client -> devtools: send updates to the owner details */
SetInspectedDetails: Mapped.OwnerDetails;
/** devtools -> client: request for node/signal/prop details — subscribe or unsubscribe */
ToggleInspected: {
type: 'node';
data: null | {
rootId: NodeID;
nodeId: NodeID;
};
} | {
type: 'signal' | 'prop';
data: {
id: NodeID;
selected: boolean;
};
} | {
type: 'value';
data: boolean;
};
/** devtools -> client: user hovered over component/element signal in devtools panel */
HighlightElement: {
rootId: NodeID;
nodeId: NodeID;
} | {
elementId: string;
} | null;
/** client -> devtools: send hovered (by the locator) owner to the extension */
ClientHoveredComponent: {
nodeId: NodeID;
state: boolean;
};
/** devtools -> client: user is selecting component from the page */
ExtLocatorMode: boolean;
/** client -> devtools */
ClientLocatorMode: boolean;
}
declare type PostMessageFn = <K extends keyof Messages>(type: K, ..._: {} extends Messages[K] ? [] : [payload: Messages[K]]) => void;
declare type OnMessageFn = <K extends keyof Messages>(id: K, handler: (payload: Messages[K]) => void) => VoidFunction;
declare const postWindowMessage: PostMessageFn;
/**
* Important ot call this if you want to use {@link onWindowMessage}
*/
declare function startListeningWindowMessages(): void;
declare const onWindowMessage: OnMessageFn;
declare function once<K extends keyof Messages>(method: OnMessageFn, id: K, handler: (payload: Messages[K]) => void): VoidFunction;
declare const bridge_LOG_MESSAGES: typeof LOG_MESSAGES;
type bridge_Messages = Messages;
type bridge_PostMessageFn = PostMessageFn;
type bridge_OnMessageFn = OnMessageFn;
declare const bridge_postWindowMessage: typeof postWindowMessage;
declare const bridge_startListeningWindowMessages: typeof startListeningWindowMessages;
declare const bridge_onWindowMessage: typeof onWindowMessage;
declare const bridge_once: typeof once;
declare namespace bridge {
export {
bridge_LOG_MESSAGES as LOG_MESSAGES,
bridge_Messages as Messages,
bridge_PostMessageFn as PostMessageFn,
bridge_OnMessageFn as OnMessageFn,
bridge_postWindowMessage as postWindowMessage,
bridge_startListeningWindowMessages as startListeningWindowMessages,
bridge_onWindowMessage as onWindowMessage,
bridge_once as once,
};
}
export { LOG_MESSAGES as L, Messages as M, OnMessageFn as O, PostMessageFn as P, once as a, bridge as b, onWindowMessage as o, postWindowMessage as p, startListeningWindowMessages as s };
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/bridge.ts
var bridge_exports = {};
__export(bridge_exports, {
LOG_MESSAGES: () => LOG_MESSAGES,
onWindowMessage: () => onWindowMessage,
once: () => once,
postWindowMessage: () => postWindowMessage,
startListeningWindowMessages: () => startListeningWindowMessages
});
module.exports = __toCommonJS(bridge_exports);
// src/utils.ts
var getLogLabel = () => [
`%csolid-devtools`,
"color: #fff; background: #2c4f7c; padding: 1px 4px;"
];
function log(...args) {
console.log(...getLogLabel(), ...args);
}
// src/bridge.ts
var LOG_MESSAGES = false;
var postWindowMessage = (id, payload) => {
LOG_MESSAGES && log("message posted:", id, payload);
postMessage({ id, payload }, "*");
};
var listeners = {};
function startListeningWindowMessages() {
if (typeof window === "undefined")
return;
addEventListener("message", (event) => {
var _a, _b;
const id = (_a = event.data) == null ? void 0 : _a.id;
if (typeof id !== "string")
return;
(_b = listeners[id]) == null ? void 0 : _b.forEach((f) => f(event.data.payload));
});
}
var onWindowMessage = (id, handler) => {
let arr = listeners[id];
if (!arr)
arr = listeners[id] = [];
arr.push(handler);
return () => listeners[id] = arr.filter((l) => l !== handler);
};
function once(method, id, handler) {
const unsub = method(id, (...cbArgs) => {
unsub();
return handler(...cbArgs);
});
return unsub;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
LOG_MESSAGES,
onWindowMessage,
once,
postWindowMessage,
startListeningWindowMessages
});
import './graph-25a6fe11.js';
import './serialize-dbe0408c.js';
export { L as LOG_MESSAGES, M as Messages, O as OnMessageFn, P as PostMessageFn, o as onWindowMessage, a as once, p as postWindowMessage, s as startListeningWindowMessages } from './bridge-a7e7c461.js';
import 'solid-js/types/reactive/signal';
import '@solid-primitives/utils';
import './variables-8a89bbc5.js';
import {
LOG_MESSAGES,
onWindowMessage,
once,
postWindowMessage,
startListeningWindowMessages
} from "./chunk-PR5VEWAU.js";
import "./chunk-TOZEPNWL.js";
import "./chunk-UICA3PK6.js";
export {
LOG_MESSAGES,
onWindowMessage,
once,
postWindowMessage,
startListeningWindowMessages
};
import {
__export
} from "./chunk-UICA3PK6.js";
// src/graph.ts
var graph_exports = {};
__export(graph_exports, {
NodeType: () => NodeType,
getOwner: () => getOwner
});
import { getOwner as _getOwner } from "solid-js";
var NodeType = /* @__PURE__ */ ((NodeType2) => {
NodeType2[NodeType2["Root"] = 0] = "Root";
NodeType2[NodeType2["Component"] = 1] = "Component";
NodeType2[NodeType2["Effect"] = 2] = "Effect";
NodeType2[NodeType2["Render"] = 3] = "Render";
NodeType2[NodeType2["Memo"] = 4] = "Memo";
NodeType2[NodeType2["Computation"] = 5] = "Computation";
NodeType2[NodeType2["Refresh"] = 6] = "Refresh";
NodeType2[NodeType2["Context"] = 7] = "Context";
NodeType2[NodeType2["Signal"] = 8] = "Signal";
return NodeType2;
})(NodeType || {});
var getOwner = _getOwner;
export {
NodeType,
getOwner,
graph_exports
};
import {
log
} from "./chunk-TOZEPNWL.js";
import {
__export
} from "./chunk-UICA3PK6.js";
// src/bridge.ts
var bridge_exports = {};
__export(bridge_exports, {
LOG_MESSAGES: () => LOG_MESSAGES,
onWindowMessage: () => onWindowMessage,
once: () => once,
postWindowMessage: () => postWindowMessage,
startListeningWindowMessages: () => startListeningWindowMessages
});
var LOG_MESSAGES = false;
var postWindowMessage = (id, payload) => {
LOG_MESSAGES && log("message posted:", id, payload);
postMessage({ id, payload }, "*");
};
var listeners = {};
function startListeningWindowMessages() {
if (typeof window === "undefined")
return;
addEventListener("message", (event) => {
var _a, _b;
const id = (_a = event.data) == null ? void 0 : _a.id;
if (typeof id !== "string")
return;
(_b = listeners[id]) == null ? void 0 : _b.forEach((f) => f(event.data.payload));
});
}
var onWindowMessage = (id, handler) => {
let arr = listeners[id];
if (!arr)
arr = listeners[id] = [];
arr.push(handler);
return () => listeners[id] = arr.filter((l) => l !== handler);
};
function once(method, id, handler) {
const unsub = method(id, (...cbArgs) => {
unsub();
return handler(...cbArgs);
});
return unsub;
}
export {
LOG_MESSAGES,
postWindowMessage,
startListeningWindowMessages,
onWindowMessage,
once,
bridge_exports
};
import {
__export
} from "./chunk-UICA3PK6.js";
// src/serialize.ts
var serialize_exports = {};
__export(serialize_exports, {
ElementMap: () => ElementMap,
INFINITY: () => INFINITY,
NAN: () => NAN,
NEGATIVE_INFINITY: () => NEGATIVE_INFINITY,
ValueType: () => ValueType,
encodeValue: () => encodeValue
});
var INFINITY = "__$sdt-Infinity__";
var NEGATIVE_INFINITY = "__$sdt-NegativeInfinity__";
var NAN = "__$sdt-NaN__";
var ValueType = /* @__PURE__ */ ((ValueType2) => {
ValueType2[ValueType2["Number"] = 0] = "Number";
ValueType2[ValueType2["Boolean"] = 1] = "Boolean";
ValueType2[ValueType2["String"] = 2] = "String";
ValueType2[ValueType2["Null"] = 3] = "Null";
ValueType2[ValueType2["Undefined"] = 4] = "Undefined";
ValueType2[ValueType2["Symbol"] = 5] = "Symbol";
ValueType2[ValueType2["Array"] = 6] = "Array";
ValueType2[ValueType2["Object"] = 7] = "Object";
ValueType2[ValueType2["Function"] = 8] = "Function";
ValueType2[ValueType2["Getter"] = 9] = "Getter";
ValueType2[ValueType2["Element"] = 10] = "Element";
ValueType2[ValueType2["Instance"] = 11] = "Instance";
return ValueType2;
})(ValueType || {});
function encodeValue(value, deep, elementMap) {
if (typeof value === "number") {
if (value === Infinity)
return { type: 0 /* Number */, value: INFINITY };
if (value === -Infinity)
return { type: 0 /* Number */, value: NEGATIVE_INFINITY };
if (Number.isNaN(value))
return { type: 0 /* Number */, value: NAN };
return { type: 0 /* Number */, value };
}
if (typeof value === "boolean")
return { type: 1 /* Boolean */, value };
if (typeof value === "string")
return { type: 2 /* String */, value };
if (value === null)
return { type: 3 /* Null */ };
if (value === void 0)
return { type: 4 /* Undefined */ };
if (typeof value === "symbol")
return { type: 5 /* Symbol */, value: value.description ?? "" };
if (typeof value === "function")
return { type: 8 /* Function */, value: value.name };
if (value instanceof HTMLElement)
return {
type: 10 /* Element */,
value: elementMap ? { name: value.tagName, id: elementMap.set(value) } : { name: value.tagName }
};
if (Array.isArray(value)) {
const payload = { type: 6 /* Array */, value: value.length };
if (deep)
payload.children = value.map((item) => encodeValue(item, true, elementMap));
return payload;
}
const s = Object.prototype.toString.call(value);
const name = s.slice(8, -1);
if (name === "Object") {
const obj = value;
const payload = {
type: 7 /* Object */,
value: Object.keys(obj).length
};
if (deep) {
const children = payload.children = {};
for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
children[key] = descriptor.get ? { type: 9 /* Getter */, value: key } : encodeValue(descriptor.value, true, elementMap);
}
}
return payload;
}
return { type: 11 /* Instance */, value: name };
}
var lastId = 0;
var ElementMap = class {
obj = {};
map = /* @__PURE__ */ new WeakMap();
get(id) {
return this.obj[id];
}
set(element) {
let id = this.map.get(element);
if (id !== void 0)
return id;
id = (lastId++).toString();
this.obj[id] = element;
this.map.set(element, id);
return id;
}
};
export {
INFINITY,
NEGATIVE_INFINITY,
NAN,
ValueType,
encodeValue,
ElementMap,
serialize_exports
};
import {
__export
} from "./chunk-UICA3PK6.js";
// src/primitives.ts
var primitives_exports = {};
__export(primitives_exports, {
atom: () => atom,
createConsumers: () => createConsumers,
createDerivedSignal: () => createDerivedSignal,
createHover: () => createHover,
defer: () => defer,
makeHoverElementListener: () => makeHoverElementListener,
untrackedCallback: () => untrackedCallback,
useIsMobile: () => useIsMobile,
useIsTouch: () => useIsTouch
});
import { createMemo, createSignal, getOwner, onCleanup, untrack } from "solid-js";
import { onRootCleanup } from "@solid-primitives/utils";
import { makeEventListener } from "@solid-primitives/event-listener";
import { createSharedRoot } from "@solid-primitives/rootless";
import { createMediaQuery } from "@solid-primitives/media";
var untrackedCallback = (fn) => (...a) => untrack(fn.bind(void 0, ...a));
var useIsTouch = createSharedRoot(() => createMediaQuery("(hover: none)"));
var useIsMobile = createSharedRoot(() => createMediaQuery("(max-width: 640px)"));
function createHover(handle) {
let state = false;
let mounted = true;
const mql = window.matchMedia("(hover: none)");
let isTouch = mql.matches;
makeEventListener(mql, "change", ({ matches }) => {
if (isTouch = matches)
handle(state = false);
});
onCleanup(() => {
mounted = false;
if (state)
handle(state = false);
});
const onChange = (newState) => {
if (isTouch || !mounted)
return;
state !== newState && handle(state = newState);
};
return {
onMouseEnter: () => onChange(true),
onMouseLeave: () => setTimeout(() => onChange(false))
};
}
function createConsumers(initial = []) {
const [consumers, setConsumers] = createSignal([...initial], { name: "consumers" });
const enabled = createMemo(() => consumers().some((consumer) => consumer()));
return [
enabled,
(consumer) => {
setConsumers((p) => [...p, consumer]);
onRootCleanup(() => setConsumers((p) => p.filter((p2) => p2 !== consumer)));
}
];
}
function createDerivedSignal(fallback, options) {
const [source, setSource] = createSignal();
return [
createMemo(
() => {
const sourceRef = source();
return sourceRef ? sourceRef() : fallback;
},
void 0,
options
),
(newSource) => {
if (newSource && getOwner())
onCleanup(() => setSource((p) => p === newSource ? void 0 : p));
return setSource(() => newSource);
}
];
}
function makeHoverElementListener(onHover) {
let last = null;
const handleHover = (e) => {
const { target } = e;
if (target === last || !(target instanceof HTMLElement) && target !== null)
return;
onHover(last = target);
};
makeEventListener(window, "mouseover", handleHover);
makeEventListener(document, "mouseleave", handleHover.bind(void 0, { target: null }));
}
function defer(deps, fn, initialValue) {
const isArray = Array.isArray(deps);
let prevInput;
let defer2 = true;
return (prevValue) => {
let input;
if (isArray) {
input = Array(deps.length);
for (let i = 0; i < deps.length; i++)
input[i] = deps[i]();
} else
input = deps();
if (defer2) {
defer2 = false;
return initialValue;
}
const result = untrack(() => fn(input, prevInput, prevValue));
prevInput = input;
return result;
};
}
function atom(value, options) {
const [state, setState] = createSignal(value, { internal: true, ...options });
return (...args) => args.length === 1 ? setState(args[0]) : state();
}
export {
untrackedCallback,
useIsTouch,
useIsMobile,
createHover,
createConsumers,
createDerivedSignal,
makeHoverElementListener,
defer,
atom,
primitives_exports
};
import {
__export
} from "./chunk-UICA3PK6.js";
// src/variables.ts
var variables_exports = {};
__export(variables_exports, {
INTERNAL: () => INTERNAL,
LOCATION_ATTRIBUTE_NAME: () => LOCATION_ATTRIBUTE_NAME,
UNNAMED: () => UNNAMED,
WINDOW_PROJECTPATH_PROPERTY: () => WINDOW_PROJECTPATH_PROPERTY,
WINDOW_WRAP_STORE_PROPERTY: () => WINDOW_WRAP_STORE_PROPERTY
});
var WINDOW_PROJECTPATH_PROPERTY = "$sdt_projectPath";
var WINDOW_WRAP_STORE_PROPERTY = "$sdt_wrapStore";
var LOCATION_ATTRIBUTE_NAME = "data-source-loc";
var UNNAMED = "(unnamed)";
var INTERNAL = Symbol("internal");
export {
WINDOW_PROJECTPATH_PROPERTY,
WINDOW_WRAP_STORE_PROPERTY,
LOCATION_ATTRIBUTE_NAME,
UNNAMED,
INTERNAL,
variables_exports
};
import {
__export
} from "./chunk-UICA3PK6.js";
// src/utils.ts
var utils_exports = {};
__export(utils_exports, {
arrayRefEquals: () => arrayRefEquals,
callArrayProp: () => callArrayProp,
dedupeArray: () => dedupeArray,
findIndexById: () => findIndexById,
findItemById: () => findItemById,
formatTime: () => formatTime,
info: () => info,
log: () => log,
mutateFilter: () => mutateFilter,
mutateRemove: () => mutateRemove,
pushToArrayProp: () => pushToArrayProp,
trimString: () => trimString,
warn: () => warn
});
var getLogLabel = () => [
`%csolid-devtools`,
"color: #fff; background: #2c4f7c; padding: 1px 4px;"
];
function info(data) {
console.info(...getLogLabel(), data);
return data;
}
function log(...args) {
console.log(...getLogLabel(), ...args);
}
function warn(...args) {
console.warn(...getLogLabel(), ...args);
}
function formatTime(d = new Date()) {
return ("0" + d.getHours()).slice(-2) + ":" + ("0" + d.getMinutes()).slice(-2) + ":" + ("0" + d.getSeconds()).slice(-2);
}
function callArrayProp(object, key, ...args) {
const arr = object[key];
if (arr)
for (const cb of arr)
cb(...args);
}
function pushToArrayProp(object, key, value) {
let arr = object[key];
if (arr)
arr.push(value);
else
arr = object[key] = [value];
return arr;
}
function mutateFilter(array, predicate) {
const temp = array.filter(predicate);
array.length = 0;
array.push.apply(array, temp);
}
function mutateRemove(array, item) {
array.splice(array.indexOf(item), 1);
}
var dedupeArray = (array) => Array.from(new Set(array));
var arrayRefEquals = (a, b) => a === b || a.length === b.length && a.every((e) => b.includes(e));
function trimString(str, maxLength) {
if (str.length <= maxLength)
return str;
return str.slice(0, maxLength) + "\u2026";
}
function findIndexById(array, id) {
for (let i = 0; i < array.length; i++)
if (array[i].id === id)
return i;
return -1;
}
function findItemById(array, id) {
for (let i = 0; i < array.length; i++) {
const item = array[i];
if (item.id === id)
return item;
}
}
export {
info,
log,
warn,
formatTime,
callArrayProp,
pushToArrayProp,
mutateFilter,
mutateRemove,
dedupeArray,
arrayRefEquals,
trimString,
findIndexById,
findItemById,
utils_exports
};
import * as solid_js_types_reactive_signal from 'solid-js/types/reactive/signal';
import { Many } from '@solid-primitives/utils';
import { I as INTERNAL } from './variables-8a89bbc5.js';
import { E as EncodedValue } from './serialize-dbe0408c.js';
declare enum NodeType {
Root = 0,
Component = 1,
Effect = 2,
Render = 3,
Memo = 4,
Computation = 5,
Refresh = 6,
Context = 7,
Signal = 8
}
declare type NodeID = string & {};
declare namespace Core {
type Owner = solid_js_types_reactive_signal.Owner;
type SignalState = solid_js_types_reactive_signal.SignalState<unknown>;
type Computation = solid_js_types_reactive_signal.Computation<unknown>;
type RootFunction<T> = solid_js_types_reactive_signal.RootFunction<T>;
type EffectFunction = solid_js_types_reactive_signal.EffectFunction<unknown>;
}
declare module 'solid-js/types/reactive/signal' {
interface SignalState<T> {
sdtId?: NodeID;
sdtName?: string;
}
interface Owner {
sdtId?: NodeID;
sdtName?: string;
sdtType?: NodeType;
}
interface Computation<Init, Next> {
sdtId?: NodeID;
sdtType?: NodeType;
onValueUpdate?: Record<symbol, ValueUpdateListener>;
onComputationUpdate?: VoidFunction;
}
}
declare namespace Solid {
interface SignalState {
value: unknown;
observers?: Computation[] | null;
onValueUpdate?: Record<symbol, ValueUpdateListener>;
}
interface Signal extends Core.SignalState, SignalState {
value: unknown;
observers: Computation[] | null;
}
interface Root extends Core.Owner {
owned: Computation[] | null;
owner: Owner | null;
sourceMap?: Record<string, Signal>;
isDisposed?: boolean;
sdtAttached?: Owner | null;
sdtContext?: DebuggerContext;
value?: undefined;
sources?: undefined;
fn?: undefined;
state?: undefined;
sourceSlots?: undefined;
updatedAt?: undefined;
pure?: undefined;
}
interface Computation extends Core.Computation {
name: string;
value: unknown;
observers?: Computation[] | null;
owned: Computation[] | null;
owner: Owner | null;
sourceMap?: Record<string, Signal>;
sources: Signal[] | null;
sdtContext?: undefined;
}
interface Memo extends Signal, Computation {
name: string;
value: unknown;
observers: Computation[] | null;
}
interface Component extends Memo {
props: Record<string, unknown>;
}
type Owner = Computation | Root;
}
declare const getOwner: () => Solid.Owner | null;
declare type DebuggerContext = {
rootId: NodeID;
triggerRootUpdate: VoidFunction;
forceRootUpdate: VoidFunction;
} | typeof INTERNAL;
declare type ComputationUpdate = {
rootId: NodeID;
id: NodeID;
};
declare type RootsUpdates = {
removed: NodeID[];
updated: Record<NodeID, Mapped.Root>;
};
declare type ValueUpdateListener = (newValue: unknown, oldValue: unknown) => void;
declare namespace Mapped {
interface Root {
id: NodeID;
name?: undefined;
type: NodeType.Root;
children?: Owner[];
attached?: NodeID;
}
interface Owner {
id: NodeID;
type: Exclude<NodeType, NodeType.Root | NodeType.Refresh>;
children?: Owner[];
name?: string;
hmr?: boolean;
frozen?: true;
}
interface Signal {
type: NodeType.Signal | NodeType.Memo;
name: string;
id: NodeID;
observers: NodeID[];
value: EncodedValue<false>;
}
type ResolvedComponent = {
id: NodeID;
name: string;
/**
* ! HTMLElements aren't JSON serialisable
*/
element: Many<HTMLElement>;
};
type Props = {
proxy: boolean;
record: Record<string, EncodedValue<boolean>>;
};
interface OwnerDetails {
id: NodeID;
name: string;
type: NodeType;
props?: Props;
signals: Signal[];
/** for computations */
value?: EncodedValue;
/** for computations */
sources?: NodeID[];
/** for memos */
observers?: NodeID[];
}
}
type graph_NodeType = NodeType;
declare const graph_NodeType: typeof NodeType;
type graph_NodeID = NodeID;
declare const graph_Core: typeof Core;
declare const graph_Solid: typeof Solid;
declare const graph_getOwner: typeof getOwner;
type graph_DebuggerContext = DebuggerContext;
type graph_ComputationUpdate = ComputationUpdate;
type graph_RootsUpdates = RootsUpdates;
type graph_ValueUpdateListener = ValueUpdateListener;
declare const graph_Mapped: typeof Mapped;
declare namespace graph {
export {
graph_NodeType as NodeType,
graph_NodeID as NodeID,
graph_Core as Core,
graph_Solid as Solid,
graph_getOwner as getOwner,
graph_DebuggerContext as DebuggerContext,
graph_ComputationUpdate as ComputationUpdate,
graph_RootsUpdates as RootsUpdates,
graph_ValueUpdateListener as ValueUpdateListener,
graph_Mapped as Mapped,
};
}
export { ComputationUpdate as C, DebuggerContext as D, Mapped as M, NodeID as N, RootsUpdates as R, Solid as S, ValueUpdateListener as V, NodeType as a, Core as b, getOwner as c, graph as g };
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/graph.ts
var graph_exports = {};
__export(graph_exports, {
NodeType: () => NodeType,
getOwner: () => getOwner
});
module.exports = __toCommonJS(graph_exports);
var import_solid_js = require("solid-js");
var NodeType = /* @__PURE__ */ ((NodeType2) => {
NodeType2[NodeType2["Root"] = 0] = "Root";
NodeType2[NodeType2["Component"] = 1] = "Component";
NodeType2[NodeType2["Effect"] = 2] = "Effect";
NodeType2[NodeType2["Render"] = 3] = "Render";
NodeType2[NodeType2["Memo"] = 4] = "Memo";
NodeType2[NodeType2["Computation"] = 5] = "Computation";
NodeType2[NodeType2["Refresh"] = 6] = "Refresh";
NodeType2[NodeType2["Context"] = 7] = "Context";
NodeType2[NodeType2["Signal"] = 8] = "Signal";
return NodeType2;
})(NodeType || {});
var getOwner = import_solid_js.getOwner;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
NodeType,
getOwner
});
import 'solid-js/types/reactive/signal';
import '@solid-primitives/utils';
import './variables-8a89bbc5.js';
import './serialize-dbe0408c.js';
export { C as ComputationUpdate, b as Core, D as DebuggerContext, M as Mapped, N as NodeID, a as NodeType, R as RootsUpdates, S as Solid, V as ValueUpdateListener, c as getOwner } from './graph-25a6fe11.js';
import {
NodeType,
getOwner
} from "./chunk-MMTBIUS3.js";
import "./chunk-UICA3PK6.js";
export {
NodeType,
getOwner
};
import { MemoOptions, AccessorArray, OnEffectFunction, NoInfer, EffectFunction, SignalOptions } from 'solid-js/types/reactive/signal';
import { Accessor } from 'solid-js';
import { AnyFunction } from '@solid-primitives/utils';
declare const untrackedCallback: <Fn extends AnyFunction>(fn: Fn) => Fn;
declare const useIsTouch: () => Accessor<boolean>;
declare const useIsMobile: () => Accessor<boolean>;
declare function createHover(handle: (hovering: boolean) => void): {
onMouseEnter: VoidFunction;
onMouseLeave: VoidFunction;
};
/**
* Reactive array reducer — if at least one consumer (boolean signal) is enabled — the returned result will the `true`.
*
* For **IOC**
*/
declare function createConsumers(initial?: readonly Accessor<boolean>[]): [needed: Accessor<boolean>, addConsumer: (consumer: Accessor<boolean>) => void];
declare type DerivedSignal<T> = [
value: Accessor<T>,
setSource: (source?: Accessor<T>) => Accessor<T> | undefined
];
/**
* For **IOC**
*/
declare function createDerivedSignal<T>(): DerivedSignal<T>;
declare function createDerivedSignal<T>(fallback: T, options?: MemoOptions<T>): DerivedSignal<T>;
declare function makeHoverElementListener(onHover: (el: HTMLElement | null) => void): void;
/**
* Solid's `on` helper, but always defers and returns a provided initial value when if does instead of `undefined`.
*
* @param deps
* @param fn
* @param initialValue
*/
declare function defer<S, Next extends Prev, Prev = Next>(deps: AccessorArray<S> | Accessor<S>, fn: OnEffectFunction<S, undefined | NoInfer<Prev>, Next>, initialValue: Next): EffectFunction<undefined | NoInfer<Next>, NoInfer<Next>>;
declare function defer<S, Next extends Prev, Prev = Next>(deps: AccessorArray<S> | Accessor<S>, fn: OnEffectFunction<S, undefined | NoInfer<Prev>, Next>, initialValue?: undefined): EffectFunction<undefined | NoInfer<Next>>;
declare type Atom<T> = (<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) & Accessor<T>;
declare function atom<T>(value: T, options?: SignalOptions<T>): Atom<T>;
declare function atom<T>(value?: undefined, options?: SignalOptions<T | undefined>): Atom<T | undefined>;
declare const primitives_untrackedCallback: typeof untrackedCallback;
declare const primitives_useIsTouch: typeof useIsTouch;
declare const primitives_useIsMobile: typeof useIsMobile;
declare const primitives_createHover: typeof createHover;
declare const primitives_createConsumers: typeof createConsumers;
type primitives_DerivedSignal<T> = DerivedSignal<T>;
declare const primitives_createDerivedSignal: typeof createDerivedSignal;
declare const primitives_makeHoverElementListener: typeof makeHoverElementListener;
declare const primitives_defer: typeof defer;
type primitives_Atom<T> = Atom<T>;
declare const primitives_atom: typeof atom;
declare namespace primitives {
export {
primitives_untrackedCallback as untrackedCallback,
primitives_useIsTouch as useIsTouch,
primitives_useIsMobile as useIsMobile,
primitives_createHover as createHover,
primitives_createConsumers as createConsumers,
primitives_DerivedSignal as DerivedSignal,
primitives_createDerivedSignal as createDerivedSignal,
primitives_makeHoverElementListener as makeHoverElementListener,
primitives_defer as defer,
primitives_Atom as Atom,
primitives_atom as atom,
};
}
export { Atom as A, DerivedSignal as D, useIsTouch as a, useIsMobile as b, createHover as c, createConsumers as d, createDerivedSignal as e, defer as f, atom as g, makeHoverElementListener as m, primitives as p, untrackedCallback as u };
declare const INFINITY = "__$sdt-Infinity__";
declare const NEGATIVE_INFINITY = "__$sdt-NegativeInfinity__";
declare const NAN = "__$sdt-NaN__";
declare enum ValueType {
Number = 0,
Boolean = 1,
String = 2,
Null = 3,
Undefined = 4,
Symbol = 5,
Array = 6,
Object = 7,
Function = 8,
Getter = 9,
Element = 10,
Instance = 11
}
declare type EncodedPreviewPayloadMap = {
[ValueType.Array]: number;
[ValueType.Object]: number;
[ValueType.Number]: number | typeof INFINITY | typeof NEGATIVE_INFINITY | typeof NAN;
[ValueType.Boolean]: boolean;
[ValueType.String]: string;
[ValueType.Symbol]: string;
[ValueType.Function]: string;
[ValueType.Getter]: string;
[ValueType.Element]: {
name: string;
id?: string;
};
[ValueType.Instance]: string;
};
declare type EncodedValueOf<K extends ValueType, Deep extends boolean = false> = {
type: K;
} & (K extends keyof EncodedPreviewPayloadMap ? {
value: EncodedPreviewPayloadMap[K];
} : {
value?: undefined;
}) & (Deep extends true ? K extends ValueType.Object ? {
children: Record<string, EncodedValue<true>>;
} : K extends ValueType.Array ? {
children: EncodedValue<true>[];
} : {
children?: undefined;
} : {
children?: undefined;
});
declare type EncodedValue<Deep extends boolean = false> = {
[K in ValueType]: EncodedValueOf<K, Deep>;
}[ValueType];
declare function encodeValue<Deep extends boolean>(value: unknown, deep: Deep, elementMap?: ElementMap): EncodedValue<Deep>;
declare class ElementMap {
private obj;
private map;
get(id: string): HTMLElement | undefined;
set(element: HTMLElement): string;
}
declare const serialize_INFINITY: typeof INFINITY;
declare const serialize_NEGATIVE_INFINITY: typeof NEGATIVE_INFINITY;
declare const serialize_NAN: typeof NAN;
type serialize_ValueType = ValueType;
declare const serialize_ValueType: typeof ValueType;
type serialize_EncodedPreviewPayloadMap = EncodedPreviewPayloadMap;
type serialize_EncodedValueOf<K extends ValueType, Deep extends boolean = false> = EncodedValueOf<K, Deep>;
type serialize_EncodedValue<Deep extends boolean = false> = EncodedValue<Deep>;
declare const serialize_encodeValue: typeof encodeValue;
type serialize_ElementMap = ElementMap;
declare const serialize_ElementMap: typeof ElementMap;
declare namespace serialize {
export {
serialize_INFINITY as INFINITY,
serialize_NEGATIVE_INFINITY as NEGATIVE_INFINITY,
serialize_NAN as NAN,
serialize_ValueType as ValueType,
serialize_EncodedPreviewPayloadMap as EncodedPreviewPayloadMap,
serialize_EncodedValueOf as EncodedValueOf,
serialize_EncodedValue as EncodedValue,
serialize_encodeValue as encodeValue,
serialize_ElementMap as ElementMap,
};
}
export { EncodedValue as E, INFINITY as I, NEGATIVE_INFINITY as N, ValueType as V, NAN as a, EncodedPreviewPayloadMap as b, EncodedValueOf as c, ElementMap as d, encodeValue as e, serialize as s };
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/serialize.ts
var serialize_exports = {};
__export(serialize_exports, {
ElementMap: () => ElementMap,
INFINITY: () => INFINITY,
NAN: () => NAN,
NEGATIVE_INFINITY: () => NEGATIVE_INFINITY,
ValueType: () => ValueType,
encodeValue: () => encodeValue
});
module.exports = __toCommonJS(serialize_exports);
var INFINITY = "__$sdt-Infinity__";
var NEGATIVE_INFINITY = "__$sdt-NegativeInfinity__";
var NAN = "__$sdt-NaN__";
var ValueType = /* @__PURE__ */ ((ValueType2) => {
ValueType2[ValueType2["Number"] = 0] = "Number";
ValueType2[ValueType2["Boolean"] = 1] = "Boolean";
ValueType2[ValueType2["String"] = 2] = "String";
ValueType2[ValueType2["Null"] = 3] = "Null";
ValueType2[ValueType2["Undefined"] = 4] = "Undefined";
ValueType2[ValueType2["Symbol"] = 5] = "Symbol";
ValueType2[ValueType2["Array"] = 6] = "Array";
ValueType2[ValueType2["Object"] = 7] = "Object";
ValueType2[ValueType2["Function"] = 8] = "Function";
ValueType2[ValueType2["Getter"] = 9] = "Getter";
ValueType2[ValueType2["Element"] = 10] = "Element";
ValueType2[ValueType2["Instance"] = 11] = "Instance";
return ValueType2;
})(ValueType || {});
function encodeValue(value, deep, elementMap) {
if (typeof value === "number") {
if (value === Infinity)
return { type: 0 /* Number */, value: INFINITY };
if (value === -Infinity)
return { type: 0 /* Number */, value: NEGATIVE_INFINITY };
if (Number.isNaN(value))
return { type: 0 /* Number */, value: NAN };
return { type: 0 /* Number */, value };
}
if (typeof value === "boolean")
return { type: 1 /* Boolean */, value };
if (typeof value === "string")
return { type: 2 /* String */, value };
if (value === null)
return { type: 3 /* Null */ };
if (value === void 0)
return { type: 4 /* Undefined */ };
if (typeof value === "symbol")
return { type: 5 /* Symbol */, value: value.description ?? "" };
if (typeof value === "function")
return { type: 8 /* Function */, value: value.name };
if (value instanceof HTMLElement)
return {
type: 10 /* Element */,
value: elementMap ? { name: value.tagName, id: elementMap.set(value) } : { name: value.tagName }
};
if (Array.isArray(value)) {
const payload = { type: 6 /* Array */, value: value.length };
if (deep)
payload.children = value.map((item) => encodeValue(item, true, elementMap));
return payload;
}
const s = Object.prototype.toString.call(value);
const name = s.slice(8, -1);
if (name === "Object") {
const obj = value;
const payload = {
type: 7 /* Object */,
value: Object.keys(obj).length
};
if (deep) {
const children = payload.children = {};
for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
children[key] = descriptor.get ? { type: 9 /* Getter */, value: key } : encodeValue(descriptor.value, true, elementMap);
}
}
return payload;
}
return { type: 11 /* Instance */, value: name };
}
var lastId = 0;
var ElementMap = class {
obj = {};
map = /* @__PURE__ */ new WeakMap();
get(id) {
return this.obj[id];
}
set(element) {
let id = this.map.get(element);
if (id !== void 0)
return id;
id = (lastId++).toString();
this.obj[id] = element;
this.map.set(element, id);
return id;
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ElementMap,
INFINITY,
NAN,
NEGATIVE_INFINITY,
ValueType,
encodeValue
});
export { d as ElementMap, b as EncodedPreviewPayloadMap, E as EncodedValue, c as EncodedValueOf, I as INFINITY, a as NAN, N as NEGATIVE_INFINITY, V as ValueType, e as encodeValue } from './serialize-dbe0408c.js';
import {
ElementMap,
INFINITY,
NAN,
NEGATIVE_INFINITY,
ValueType,
encodeValue
} from "./chunk-PRL2GOEE.js";
import "./chunk-UICA3PK6.js";
export {
ElementMap,
INFINITY,
NAN,
NEGATIVE_INFINITY,
ValueType,
encodeValue
};
declare function info<T>(data: T): T;
declare function log(...args: any[]): void;
declare function warn(...args: any[]): void;
declare function formatTime(d?: Date): string;
declare function callArrayProp<K extends PropertyKey, T extends (...args: Args) => void, Args extends unknown[]>(object: {
[_ in K]?: T[];
}, key: K, ...args: Args): void;
declare function pushToArrayProp<K extends PropertyKey, T>(object: {
[_ in K]?: T[];
}, key: K, value: T): T[];
declare function mutateFilter<T, S extends T>(array: T[], predicate: (value: T, index: number, array: T[]) => value is S): void;
declare function mutateFilter<T>(array: T[], predicate: (value: T, index: number, array: T[]) => unknown): void;
declare function mutateRemove<T>(array: T[], item: T): void;
declare const dedupeArray: <T>(array: readonly T[]) => T[];
/** Checks if both arrays contain the same values. Order doesn't matter. */
declare const arrayRefEquals: <T>(a: readonly T[], b: readonly T[]) => boolean;
/** function that trims too long string */
declare function trimString(str: string, maxLength: number): string;
declare function findIndexById<T extends {
id: string;
}>(array: T[], id: string): number;
declare function findItemById<T extends {
id: string;
}>(array: T[], id: string): T | undefined;
declare const utils_info: typeof info;
declare const utils_log: typeof log;
declare const utils_warn: typeof warn;
declare const utils_formatTime: typeof formatTime;
declare const utils_callArrayProp: typeof callArrayProp;
declare const utils_pushToArrayProp: typeof pushToArrayProp;
declare const utils_mutateFilter: typeof mutateFilter;
declare const utils_mutateRemove: typeof mutateRemove;
declare const utils_dedupeArray: typeof dedupeArray;
declare const utils_arrayRefEquals: typeof arrayRefEquals;
declare const utils_trimString: typeof trimString;
declare const utils_findIndexById: typeof findIndexById;
declare const utils_findItemById: typeof findItemById;
declare namespace utils {
export {
utils_info as info,
utils_log as log,
utils_warn as warn,
utils_formatTime as formatTime,
utils_callArrayProp as callArrayProp,
utils_pushToArrayProp as pushToArrayProp,
utils_mutateFilter as mutateFilter,
utils_mutateRemove as mutateRemove,
utils_dedupeArray as dedupeArray,
utils_arrayRefEquals as arrayRefEquals,
utils_trimString as trimString,
utils_findIndexById as findIndexById,
utils_findItemById as findItemById,
};
}
export { mutateRemove as a, arrayRefEquals as b, callArrayProp as c, dedupeArray as d, findIndexById as e, formatTime as f, findItemById as g, info as i, log as l, mutateFilter as m, pushToArrayProp as p, trimString as t, utils as u, warn as w };
declare const WINDOW_PROJECTPATH_PROPERTY = "$sdt_projectPath";
declare const WINDOW_WRAP_STORE_PROPERTY = "$sdt_wrapStore";
declare const LOCATION_ATTRIBUTE_NAME = "data-source-loc";
declare const UNNAMED = "(unnamed)";
declare const INTERNAL: unique symbol;
declare const variables_WINDOW_PROJECTPATH_PROPERTY: typeof WINDOW_PROJECTPATH_PROPERTY;
declare const variables_WINDOW_WRAP_STORE_PROPERTY: typeof WINDOW_WRAP_STORE_PROPERTY;
declare const variables_LOCATION_ATTRIBUTE_NAME: typeof LOCATION_ATTRIBUTE_NAME;
declare const variables_UNNAMED: typeof UNNAMED;
declare const variables_INTERNAL: typeof INTERNAL;
declare namespace variables {
export {
variables_WINDOW_PROJECTPATH_PROPERTY as WINDOW_PROJECTPATH_PROPERTY,
variables_WINDOW_WRAP_STORE_PROPERTY as WINDOW_WRAP_STORE_PROPERTY,
variables_LOCATION_ATTRIBUTE_NAME as LOCATION_ATTRIBUTE_NAME,
variables_UNNAMED as UNNAMED,
variables_INTERNAL as INTERNAL,
};
}
export { INTERNAL as I, LOCATION_ATTRIBUTE_NAME as L, UNNAMED as U, WINDOW_PROJECTPATH_PROPERTY as W, WINDOW_WRAP_STORE_PROPERTY as a, variables as v };
import { ComputationUpdate, Mapped, NodeID, RootsUpdates } from './graph'
import { EncodedValue } from './serialize'
import { log } from './utils'
export const LOG_MESSAGES = false
export interface Messages {
// client -> content -> devtools.html
// the `string` payload is the ext-client version
SolidOnPage: string
// devtools -> background: number is a tab id
DevtoolsScriptConnected: number
DevtoolsPanelConnected: {}
Versions: { client: string; expectedClient: string; extension: string }
/** devtools -> client: user switching between Solid devtools and other panel */
PanelVisibility: boolean
/** devtools -> client: the chrome devtools got entirely closed */
PanelClosed: true
ResetPanel: {}
StructureUpdate: RootsUpdates
ComputationUpdates: ComputationUpdate[]
/** client -> devtools: signal deep value */
SignalUpdates: { signals: { id: NodeID; value: EncodedValue<boolean> }[]; update: boolean }
/** client -> devtools: encoded props object */
PropsUpdate: Mapped.Props
/** client -> devtools: inspected node value update */
ValueUpdate: { value: EncodedValue<boolean>; update: boolean }
/** devtools -> client: force the debugger to walk the whole tree and send it */
ForceUpdate: {}
/** client -> devtools: send component clicked with the locator to the extension */
ClientInspectedNode: NodeID
/** client -> devtools: send updates to the owner details */
SetInspectedDetails: Mapped.OwnerDetails
/** devtools -> client: request for node/signal/prop details — subscribe or unsubscribe */
ToggleInspected:
| { type: 'node'; data: null | { rootId: NodeID; nodeId: NodeID } }
| { type: 'signal' | 'prop'; data: { id: NodeID; selected: boolean } }
| { type: 'value'; data: boolean }
/** devtools -> client: user hovered over component/element signal in devtools panel */
HighlightElement: { rootId: NodeID; nodeId: NodeID } | { elementId: string } | null
/** client -> devtools: send hovered (by the locator) owner to the extension */
ClientHoveredComponent: { nodeId: NodeID; state: boolean }
/** devtools -> client: user is selecting component from the page */
ExtLocatorMode: boolean
/** client -> devtools */
ClientLocatorMode: boolean
}
export type PostMessageFn = <K extends keyof Messages>(
type: K,
..._: {} extends Messages[K] ? [] : [payload: Messages[K]]
) => void
export type OnMessageFn = <K extends keyof Messages>(
id: K,
handler: (payload: Messages[K]) => void,
) => VoidFunction
export const postWindowMessage: PostMessageFn = (id, payload?: any) => {
LOG_MESSAGES && log('message posted:', id, payload)
postMessage({ id, payload }, '*')
}
const listeners: {
[K in keyof Messages]?: ((payload: Messages[K]) => void)[]
} = {}
/**
* Important ot call this if you want to use {@link onWindowMessage}
*/
export function startListeningWindowMessages() {
if (typeof window === 'undefined') return
addEventListener('message', event => {
const id = event.data?.id as keyof Messages
if (typeof id !== 'string') return
listeners[id]?.forEach(f => f(event.data.payload as never))
})
}
export const onWindowMessage: OnMessageFn = (id, handler) => {
let arr = listeners[id]
if (!arr) arr = listeners[id] = []
arr.push(handler)
return () => (listeners[id] = arr!.filter(l => l !== handler) as any)
}
export function once<K extends keyof Messages>(
method: OnMessageFn,
id: K,
handler: (payload: Messages[K]) => void,
): VoidFunction {
const unsub = method(id, (...cbArgs) => {
unsub()
return handler(...cbArgs)
})
return unsub
}
import { getOwner as _getOwner } from 'solid-js'
import { Many } from '@solid-primitives/utils'
import { INTERNAL } from './variables'
import { EncodedValue } from './serialize'
export enum NodeType {
Root,
Component,
Effect,
Render,
Memo,
Computation,
Refresh,
Context,
Signal,
}
export type NodeID = string & {}
export namespace Core {
export type Owner = import('solid-js/types/reactive/signal').Owner
export type SignalState = import('solid-js/types/reactive/signal').SignalState<unknown>
export type Computation = import('solid-js/types/reactive/signal').Computation<unknown>
export type RootFunction<T> = import('solid-js/types/reactive/signal').RootFunction<T>
export type EffectFunction = import('solid-js/types/reactive/signal').EffectFunction<unknown>
}
declare module 'solid-js/types/reactive/signal' {
interface SignalState<T> {
sdtId?: NodeID
sdtName?: string
}
interface Owner {
sdtId?: NodeID
sdtName?: string
sdtType?: NodeType
}
interface Computation<Init, Next> {
sdtId?: NodeID
sdtType?: NodeType
onValueUpdate?: Record<symbol, ValueUpdateListener>
onComputationUpdate?: VoidFunction
}
}
//
// "Signal___" — owner/signals/etc. objects in the Solid's internal owner graph
//
export namespace Solid {
export interface SignalState {
value: unknown
observers?: Computation[] | null
onValueUpdate?: Record<symbol, ValueUpdateListener>
}
export interface Signal extends Core.SignalState, SignalState {
value: unknown
observers: Computation[] | null
}
export interface Root extends Core.Owner {
owned: Computation[] | null
owner: Owner | null
sourceMap?: Record<string, Signal>
// Used by the debugger
isDisposed?: boolean
sdtAttached?: Owner | null
sdtContext?: DebuggerContext
// Computation compatibility
value?: undefined
sources?: undefined
fn?: undefined
state?: undefined
sourceSlots?: undefined
updatedAt?: undefined
pure?: undefined
}
export interface Computation extends Core.Computation {
name: string
value: unknown
observers?: Computation[] | null
owned: Computation[] | null
owner: Owner | null
sourceMap?: Record<string, Signal>
sources: Signal[] | null
// devtools:
sdtContext?: undefined
}
export interface Memo extends Signal, Computation {
name: string
value: unknown
observers: Computation[] | null
}
export interface Component extends Memo {
props: Record<string, unknown>
}
export type Owner = Computation | Root
}
export const getOwner = _getOwner as () => Solid.Owner | null
export type DebuggerContext =
| {
rootId: NodeID
triggerRootUpdate: VoidFunction
forceRootUpdate: VoidFunction
}
| typeof INTERNAL
export type ComputationUpdate = { rootId: NodeID; id: NodeID }
export type RootsUpdates = {
removed: NodeID[]
updated: Record<NodeID, Mapped.Root>
}
export type ValueUpdateListener = (newValue: unknown, oldValue: unknown) => void
//
// "Mapped___" — owner/signal/etc. objects created by the solid-devtools-debugger runtime library
// They should be JSON serialisable — to be able to send them with chrome.runtime.sendMessage
//
export namespace Mapped {
export interface Root {
id: NodeID
name?: undefined
type: NodeType.Root
children?: Owner[]
// sub-roots will have an owner
attached?: NodeID
}
export interface Owner {
id: NodeID
type: Exclude<NodeType, NodeType.Root | NodeType.Refresh>
children?: Owner[]
name?: string
hmr?: boolean
frozen?: true
}
export interface Signal {
type: NodeType.Signal | NodeType.Memo
name: string
id: NodeID
observers: NodeID[]
value: EncodedValue<false>
}
export type ResolvedComponent = {
id: NodeID
name: string
/**
* ! HTMLElements aren't JSON serialisable
*/
element: Many<HTMLElement>
}
export type Props = {
proxy: boolean
record: Record<string, EncodedValue<boolean>>
}
export interface OwnerDetails {
id: NodeID
name: string
type: NodeType
props?: Props
signals: Signal[]
/** for computations */
value?: EncodedValue
/** for computations */
sources?: NodeID[]
/** for memos */
observers?: NodeID[]
}
}
export const INFINITY = '__$sdt-Infinity__'
export const NEGATIVE_INFINITY = '__$sdt-NegativeInfinity__'
export const NAN = '__$sdt-NaN__'
export enum ValueType {
Number,
Boolean,
String,
Null,
Undefined,
Symbol,
Array,
Object,
Function,
Getter,
Element,
Instance,
}
export type EncodedPreviewPayloadMap = {
[ValueType.Array]: number
[ValueType.Object]: number
[ValueType.Number]: number | typeof INFINITY | typeof NEGATIVE_INFINITY | typeof NAN
[ValueType.Boolean]: boolean
[ValueType.String]: string
[ValueType.Symbol]: string
[ValueType.Function]: string
[ValueType.Getter]: string
[ValueType.Element]: { name: string; id?: string }
[ValueType.Instance]: string
}
export type EncodedValueOf<K extends ValueType, Deep extends boolean = false> = {
type: K
} & (K extends keyof EncodedPreviewPayloadMap
? { value: EncodedPreviewPayloadMap[K] }
: { value?: undefined }) &
(Deep extends true
? K extends ValueType.Object
? { children: Record<string, EncodedValue<true>> }
: K extends ValueType.Array
? { children: EncodedValue<true>[] }
: { children?: undefined }
: { children?: undefined })
export type EncodedValue<Deep extends boolean = false> = {
[K in ValueType]: EncodedValueOf<K, Deep>
}[ValueType]
export function encodeValue<Deep extends boolean>(
value: unknown,
deep: Deep,
elementMap?: ElementMap,
): EncodedValue<Deep> {
if (typeof value === 'number') {
if (value === Infinity) return { type: ValueType.Number, value: INFINITY }
if (value === -Infinity) return { type: ValueType.Number, value: NEGATIVE_INFINITY }
if (Number.isNaN(value)) return { type: ValueType.Number, value: NAN }
return { type: ValueType.Number, value }
}
if (typeof value === 'boolean') return { type: ValueType.Boolean, value }
if (typeof value === 'string') return { type: ValueType.String, value }
if (value === null) return { type: ValueType.Null }
if (value === undefined) return { type: ValueType.Undefined }
if (typeof value === 'symbol') return { type: ValueType.Symbol, value: value.description ?? '' }
if (typeof value === 'function') return { type: ValueType.Function, value: value.name }
if (value instanceof HTMLElement)
return {
type: ValueType.Element,
value: elementMap
? { name: value.tagName, id: elementMap.set(value) }
: { name: value.tagName },
}
if (Array.isArray(value)) {
const payload = { type: ValueType.Array, value: value.length } as EncodedValueOf<
ValueType.Array,
boolean
>
if (deep) payload.children = value.map(item => encodeValue(item, true, elementMap))
return payload
}
const s = Object.prototype.toString.call(value)
const name = s.slice(8, -1)
if (name === 'Object') {
const obj = value as Record<PropertyKey, unknown>
const payload: EncodedValueOf<ValueType.Object, boolean> = {
type: ValueType.Object,
value: Object.keys(obj).length,
}
if (deep) {
const children: Record<string, EncodedValue<true>> = (payload.children = {} as any)
for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
children[key] = descriptor.get
? { type: ValueType.Getter, value: key }
: encodeValue(descriptor.value, true, elementMap)
}
}
return payload
}
return { type: ValueType.Instance, value: name }
}
let lastId = 0
export class ElementMap {
private obj: Record<string, HTMLElement> = {}
private map: WeakMap<HTMLElement, string> = new WeakMap()
get(id: string): HTMLElement | undefined {
return this.obj[id]
}
set(element: HTMLElement): string {
let id = this.map.get(element)
if (id !== undefined) return id
id = (lastId++).toString()
this.obj[id] = element
this.map.set(element, id)
return id
}
}
import { describe, test, expect } from 'vitest'
import {
ValueType,
INFINITY,
NEGATIVE_INFINITY,
NAN,
encodeValue,
EncodedValue,
ElementMap,
} from '../src/serialize'
const _testFunction = () => {}
const encodePreviewExpectations: [string, unknown, EncodedValue<false>][] = [
['Infinity', Infinity, { type: ValueType.Number, value: INFINITY }],
['Negative Infinity', -Infinity, { type: ValueType.Number, value: NEGATIVE_INFINITY }],
['NaN', NaN, { type: ValueType.Number, value: NAN }],
['Number', 1, { type: ValueType.Number, value: 1 }],
['Boolean true', true, { type: ValueType.Boolean, value: true }],
['Boolean false', false, { type: ValueType.Boolean, value: false }],
['String', '', { type: ValueType.String, value: '' }],
['String', 'foo', { type: ValueType.String, value: 'foo' }],
['Null', null, { type: ValueType.Null }],
['Undefined', undefined, { type: ValueType.Undefined }],
['Named Symbol', Symbol('foo'), { type: ValueType.Symbol, value: 'foo' }],
['Symbol', Symbol(), { type: ValueType.Symbol, value: '' }],
['Function', () => {}, { type: ValueType.Function, value: '' }],
['Named Function', _testFunction, { type: ValueType.Function, value: '_testFunction' }],
[
'Element div',
document.createElement('div'),
{ type: ValueType.Element, value: { name: 'DIV' } },
],
['Element a', document.createElement('a'), { type: ValueType.Element, value: { name: 'A' } }],
['Array empty', [], { type: ValueType.Array, value: 0 }],
['Array', [1, 2, 3], { type: ValueType.Array, value: 3 }],
['Object empty', {}, { type: ValueType.Object, value: 0 }],
['Object', { a: 1, b: 2, c: 3 }, { type: ValueType.Object, value: 3 }],
['Date', new Date(), { type: ValueType.Instance, value: 'Date' }],
['Error', new Error(), { type: ValueType.Instance, value: 'Error' }],
['Map', new Map(), { type: ValueType.Instance, value: 'Map' }],
['WeakMap', new WeakMap(), { type: ValueType.Instance, value: 'WeakMap' }],
['Set', new Set(), { type: ValueType.Instance, value: 'Set' }],
]
describe('encodeValue Preview', () => {
for (const [testName, value, expectation] of encodePreviewExpectations) {
test(testName, () => {
const s = encodeValue(value, false)
expect(s).toEqual(expectation)
expect(JSON.parse(JSON.stringify(s))).toEqual(s)
})
}
})
const encodeDeepExpectations: [string, unknown, EncodedValue<true>][] = [
['Array empty', [], { type: ValueType.Array, value: 0, children: [] }],
[
'Array shallow',
[1, 2, 3],
{
type: ValueType.Array,
value: 3,
children: [
{ type: ValueType.Number, value: 1 },
{ type: ValueType.Number, value: 2 },
{ type: ValueType.Number, value: 3 },
],
},
],
[
'Array nested',
[[1, { foo: 'bar' }], 2, { map: new Map() }],
{
type: ValueType.Array,
value: 3,
children: [
{
type: ValueType.Array,
value: 2,
children: [
{ type: ValueType.Number, value: 1 },
{
type: ValueType.Object,
value: 1,
children: { foo: { type: ValueType.String, value: 'bar' } },
},
],
},
{ type: ValueType.Number, value: 2 },
{
type: ValueType.Object,
value: 1,
children: { map: { type: ValueType.Instance, value: 'Map' } },
},
],
},
],
['Object empty', {}, { type: ValueType.Object, value: 0, children: {} }],
[
'Object shallow',
{ a: 1, b: 2, c: 3 },
{
type: ValueType.Object,
value: 3,
children: {
a: { type: ValueType.Number, value: 1 },
b: { type: ValueType.Number, value: 2 },
c: { type: ValueType.Number, value: 3 },
},
},
],
[
'Object nested',
{ a: [1, { foo: 'bar' }], b: 2, c: { map: new Map() } },
{
type: ValueType.Object,
value: 3,
children: {
a: {
type: ValueType.Array,
value: 2,
children: [
{ type: ValueType.Number, value: 1 },
{
type: ValueType.Object,
value: 1,
children: { foo: { type: ValueType.String, value: 'bar' } },
},
],
},
b: { type: ValueType.Number, value: 2 },
c: {
type: ValueType.Object,
value: 1,
children: { map: { type: ValueType.Instance, value: 'Map' } },
},
},
},
],
[
'Object with getter properties',
{
a: 123,
get b() {
return 456
},
},
{
type: ValueType.Object,
value: 2,
children: {
a: { type: ValueType.Number, value: 123 },
b: { type: ValueType.Getter, value: 'b' },
},
},
],
]
describe('encodeValue Deep', () => {
for (const [testName, value, expectation] of encodeDeepExpectations) {
test(testName, () => {
const s = encodeValue(value, true)
expect(s).toEqual(expectation)
expect(JSON.parse(JSON.stringify(s))).toEqual(s)
})
}
})
describe('save elements to a map', () => {
const div1 = document.createElement('div')
const a1 = document.createElement('a')
const div2 = document.createElement('div')
const elMapExpectations: [string, unknown, EncodedValue<true>][] = [
['Element div', div1, { type: ValueType.Element, value: { name: 'DIV', id: '0' } }],
['Element a', a1, { type: ValueType.Element, value: { name: 'A', id: '1' } }],
[
'Element in object',
{ el: div2 },
{
type: ValueType.Object,
value: 1,
children: { el: { type: ValueType.Element, value: { name: 'DIV', id: '2' } } },
},
],
]
const map = new ElementMap()
for (const [testName, value, expectation] of elMapExpectations) {
test(testName, () => {
const s = encodeValue(value, true, map)
expect(s).toEqual(expectation)
expect(JSON.parse(JSON.stringify(s))).toEqual(s)
})
}
test('map containing correct values', () => {
expect(map.get('0')).toBe(div1)
expect(map.get('1')).toBe(a1)
expect(map.get('2')).toBe(div2)
})
})