mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-06-11 07:23:32 -07:00
website: up signals + added compare folder to all groups
This commit is contained in:
@@ -36,6 +36,8 @@
|
||||
- Fixed history not being properly registered
|
||||
- Fixed window being moveable on iOS when in standalone mode when it shouldn't be
|
||||
- Split `index.html` and `script.js` into multiple js and css files to load only what's necessary at a given time
|
||||
- Added `Compare` section to all groups, to compare all datasets within a group
|
||||
- Updated `Solid Signals` library, which had an important breaking change on the `createEffect` function which might bring some bugs
|
||||
|
||||
## Parser
|
||||
|
||||
|
||||
+1
-1
@@ -971,7 +971,7 @@
|
||||
}
|
||||
|
||||
details:not([open]) > summary:hover > & {
|
||||
background-color: var(--orange);
|
||||
background-color: var(--orange) !important;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+163
-138
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* @import {Options} from './options';
|
||||
* @import { HoveredLegend, PriceSeriesType, Series } from "./types/self"
|
||||
* @import { Options } from './options';
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -205,22 +206,21 @@ export function init({
|
||||
const debouncedSaveVisibleRange = utils.debounce(saveVisibleRange, 250);
|
||||
|
||||
function createFetchChunksOfVisibleDatasetsEffect() {
|
||||
signals.createEffect(() => {
|
||||
const ids = visibleDatasetIds();
|
||||
const datasets = Array.from(activeDatasets());
|
||||
signals.createEffect(
|
||||
() => ({ ids: visibleDatasetIds(), activeDatasets: activeDatasets() }),
|
||||
({ ids, activeDatasets }) => {
|
||||
const datasets = Array.from(activeDatasets);
|
||||
|
||||
if (ids.length === 0 || datasets.length === 0) return;
|
||||
if (ids.length === 0 || datasets.length === 0) return;
|
||||
|
||||
signals.untrack(() => {
|
||||
console.log(ids, datasets);
|
||||
for (let i = 0; i < ids.length; i++) {
|
||||
const id = ids[i];
|
||||
for (let j = 0; j < datasets.length; j++) {
|
||||
datasets[j].fetch(id);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
createFetchChunksOfVisibleDatasetsEffect();
|
||||
|
||||
@@ -352,9 +352,7 @@ export function init({
|
||||
);
|
||||
|
||||
const hoveredLegend = signals.createSignal(
|
||||
/** @type {{label: HTMLLabelElement, series: Series} | undefined} */ (
|
||||
undefined
|
||||
),
|
||||
/** @type {HoveredLegend | undefined} */ (undefined),
|
||||
);
|
||||
const notHoveredLegendTransparency = "66";
|
||||
/**
|
||||
@@ -365,9 +363,13 @@ export function init({
|
||||
*/
|
||||
function createLegend({ series, disabled, name }) {
|
||||
const div = window.document.createElement("div");
|
||||
signals.createEffect(() => {
|
||||
div.hidden = disabled?.() ? true : false;
|
||||
});
|
||||
|
||||
if (disabled) {
|
||||
signals.createEffect(disabled, (disabled) => {
|
||||
div.hidden = disabled;
|
||||
});
|
||||
}
|
||||
|
||||
elements.legend.prepend(div);
|
||||
|
||||
const { input, label, spanMain } = utils.dom.createComplexLabeledInput({
|
||||
@@ -395,8 +397,8 @@ export function init({
|
||||
hoveredLegend.set(undefined);
|
||||
});
|
||||
|
||||
signals.createEffect(() => {
|
||||
input.checked = series.active();
|
||||
signals.createEffect(series.active, (checked) => {
|
||||
input.checked = checked;
|
||||
});
|
||||
|
||||
function shouldHighlight() {
|
||||
@@ -416,69 +418,74 @@ export function init({
|
||||
const spanColor = window.document.createElement("span");
|
||||
spanColors.append(spanColor);
|
||||
|
||||
signals.createEffect(() => {
|
||||
const c = color();
|
||||
if (shouldHighlight()) {
|
||||
spanColor.style.backgroundColor = c;
|
||||
} else {
|
||||
spanColor.style.backgroundColor = `${c}${notHoveredLegendTransparency}`;
|
||||
}
|
||||
});
|
||||
signals.createEffect(
|
||||
() => ({ color: color(), shouldHighlight: shouldHighlight() }),
|
||||
({ color, shouldHighlight }) => {
|
||||
if (shouldHighlight) {
|
||||
spanColor.style.backgroundColor = color;
|
||||
} else {
|
||||
spanColor.style.backgroundColor = `${color}${notHoveredLegendTransparency}`;
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
function createHoverEffect() {
|
||||
const initialColors = /** @type {Record<string, any>} */ ({});
|
||||
const darkenedColors = /** @type {Record<string, any>} */ ({});
|
||||
|
||||
/** @type {HoveredLegend | undefined} */
|
||||
let previouslyHovered = undefined;
|
||||
|
||||
signals.createEffect(
|
||||
// @ts-ignore
|
||||
(previouslyHovered) => {
|
||||
const hovered = hoveredLegend();
|
||||
|
||||
() => ({ hovered: hoveredLegend(), ids: visibleDatasetIds() }),
|
||||
({ hovered, ids }) => {
|
||||
if (!hovered && !previouslyHovered) return hovered;
|
||||
|
||||
const ids = visibleDatasetIds();
|
||||
|
||||
for (let i = 0; i < ids.length; i++) {
|
||||
const chunkId = ids[i];
|
||||
const chunkIndex = utils.chunkIdToIndex(scale(), chunkId);
|
||||
const chunk = series.chunks[chunkIndex]?.();
|
||||
const chunk = series.chunks[chunkIndex];
|
||||
|
||||
if (!chunk) return;
|
||||
signals.createEffect(chunk, (chunk) => {
|
||||
if (!chunk) return;
|
||||
|
||||
if (hovered) {
|
||||
const seriesOptions = chunk.options();
|
||||
if (!seriesOptions) return;
|
||||
if (hovered) {
|
||||
const seriesOptions = chunk.options();
|
||||
if (!seriesOptions) return;
|
||||
|
||||
initialColors[i] = {};
|
||||
darkenedColors[i] = {};
|
||||
initialColors[i] = {};
|
||||
darkenedColors[i] = {};
|
||||
|
||||
Object.entries(seriesOptions).forEach(([k, v]) => {
|
||||
if (k.toLowerCase().includes("color") && v) {
|
||||
if (typeof v === "string" && !v.startsWith("#")) {
|
||||
return;
|
||||
Object.entries(seriesOptions).forEach(([k, v]) => {
|
||||
if (k.toLowerCase().includes("color") && v) {
|
||||
if (typeof v === "string" && !v.startsWith("#")) {
|
||||
return;
|
||||
}
|
||||
|
||||
v = /** @type {string} */ (v).substring(0, 7);
|
||||
initialColors[i][k] = v;
|
||||
darkenedColors[i][k] =
|
||||
`${v}${notHoveredLegendTransparency}`;
|
||||
} else if (k === "lastValueVisible" && v) {
|
||||
initialColors[i][k] = true;
|
||||
darkenedColors[i][k] = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
v = /** @type {string} */ (v).substring(0, 7);
|
||||
initialColors[i][k] = v;
|
||||
darkenedColors[i][k] = `${v}${notHoveredLegendTransparency}`;
|
||||
} else if (k === "lastValueVisible" && v) {
|
||||
initialColors[i][k] = true;
|
||||
darkenedColors[i][k] = false;
|
||||
signals.createEffect(shouldHighlight, (shouldHighlight) => {
|
||||
if (shouldHighlight) {
|
||||
chunk.applyOptions(initialColors[i]);
|
||||
} else {
|
||||
chunk.applyOptions(darkenedColors[i]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (shouldHighlight()) {
|
||||
chunk.applyOptions(initialColors[i]);
|
||||
} else {
|
||||
chunk.applyOptions(darkenedColors[i]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return hovered;
|
||||
previouslyHovered = hovered;
|
||||
},
|
||||
undefined,
|
||||
);
|
||||
}
|
||||
createHoverEffect();
|
||||
@@ -540,21 +547,22 @@ export function init({
|
||||
|
||||
const visible = signals.createMemo(() => active() && !disabled());
|
||||
|
||||
signals.createEffect(() => {
|
||||
if (disabled()) {
|
||||
return;
|
||||
}
|
||||
signals.createEffect(
|
||||
() => ({ disabled: disabled(), active: active() }),
|
||||
({ disabled, active }) => {
|
||||
if (disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
const a = active();
|
||||
|
||||
if (a !== (defaultActive || true)) {
|
||||
utils.url.writeParam(id, a);
|
||||
utils.storage.write(storageId, a);
|
||||
} else {
|
||||
utils.url.removeParam(id);
|
||||
utils.storage.remove(storageId);
|
||||
}
|
||||
});
|
||||
if (active !== (defaultActive || true)) {
|
||||
utils.url.writeParam(id, active);
|
||||
utils.storage.write(storageId, active);
|
||||
} else {
|
||||
utils.url.removeParam(id);
|
||||
utils.storage.remove(storageId);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
/** @type {Series} */
|
||||
const series = {
|
||||
@@ -579,22 +587,22 @@ export function init({
|
||||
|
||||
chunks[index] = chunk;
|
||||
|
||||
signals.createEffect(() => {
|
||||
const values = json.vec();
|
||||
const isMyTurn = signals.createMemo(() => {
|
||||
if (seriesIndex <= 0) return true;
|
||||
|
||||
if (!values) return;
|
||||
const previousSeriesChunk = chartSeries.at(seriesIndex - 1)?.chunks[
|
||||
index
|
||||
];
|
||||
const isPreviousSeriesOnChart = previousSeriesChunk?.();
|
||||
|
||||
if (seriesIndex > 0) {
|
||||
const previousSeriesChunk = chartSeries.at(seriesIndex - 1)?.chunks[
|
||||
index
|
||||
];
|
||||
const isPreviousSeriesOnChart = previousSeriesChunk?.();
|
||||
if (!isPreviousSeriesOnChart) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
return !!isPreviousSeriesOnChart;
|
||||
});
|
||||
|
||||
signals.createEffect(
|
||||
() => ({ values: json.vec(), isMyTurn: isMyTurn() }),
|
||||
({ values, isMyTurn }) => {
|
||||
if (!values || !isMyTurn) return;
|
||||
|
||||
signals.untrack(() => {
|
||||
let s = chunk();
|
||||
|
||||
if (!s) {
|
||||
@@ -647,28 +655,39 @@ export function init({
|
||||
s.setData(values);
|
||||
|
||||
setMinMaxMarkersWhenIdle();
|
||||
},
|
||||
);
|
||||
|
||||
signals.createEffect(
|
||||
() => ({
|
||||
chunk: chunk(),
|
||||
currentVec: dataset.fetchedJSONs.at(index)?.vec(),
|
||||
nextVec: dataset.fetchedJSONs.at(index + 1)?.vec(),
|
||||
}),
|
||||
({ chunk, currentVec, nextVec }) => {
|
||||
if (chunk && currentVec?.length && nextVec?.length) {
|
||||
chunk.update(nextVec[0]);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
signals.createEffect(chunk, (chunk) => {
|
||||
const isChunkLastVisible = signals.createMemo(() => {
|
||||
const last = lastVisibleDatasetIndex();
|
||||
return last !== undefined && last === index;
|
||||
});
|
||||
});
|
||||
|
||||
signals.createEffect(() => {
|
||||
const _chunk = chunk();
|
||||
const currentVec = dataset.fetchedJSONs.at(index)?.vec();
|
||||
const nextVec = dataset.fetchedJSONs.at(index + 1)?.vec();
|
||||
|
||||
if (_chunk && currentVec?.length && nextVec?.length) {
|
||||
_chunk.update(nextVec[0]);
|
||||
}
|
||||
});
|
||||
|
||||
const isChunkLastVisible = signals.createMemo(() => {
|
||||
const last = lastVisibleDatasetIndex();
|
||||
return last !== undefined && last === index;
|
||||
});
|
||||
|
||||
signals.createEffect(() => {
|
||||
chunk()?.applyOptions({
|
||||
lastValueVisible: series.visible() && isChunkLastVisible(),
|
||||
});
|
||||
signals.createEffect(
|
||||
() => ({
|
||||
visible: series.visible(),
|
||||
isChunkLastVisible: isChunkLastVisible(),
|
||||
}),
|
||||
({ visible, isChunkLastVisible }) => {
|
||||
chunk?.applyOptions({
|
||||
lastValueVisible: visible && isChunkLastVisible,
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
const shouldChunkBeVisible = signals.createMemo(() => {
|
||||
@@ -700,10 +719,17 @@ export function init({
|
||||
return wasChunkVisible;
|
||||
});
|
||||
|
||||
signals.createEffect(() => {
|
||||
const visible = series.visible() && chunkVisible();
|
||||
chunk()?.applyOptions({
|
||||
visible,
|
||||
signals.createEffect(chunk, (chunk) => {
|
||||
if (!chunk) return;
|
||||
|
||||
const visible = signals.createMemo(
|
||||
() => series.visible() && chunkVisible(),
|
||||
);
|
||||
|
||||
signals.createEffect(visible, (visible) => {
|
||||
chunk.applyOptions({
|
||||
visible,
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -774,16 +800,18 @@ export function init({
|
||||
});
|
||||
|
||||
function createLiveCandleUpdateEffect() {
|
||||
signals.createEffect(() => {
|
||||
const latest = webSockets.krakenCandle.latest();
|
||||
|
||||
signals.createEffect(webSockets.krakenCandle.latest, (latest) => {
|
||||
if (!latest) return;
|
||||
|
||||
const index = utils.chunkIdToIndex(s, latest.year);
|
||||
|
||||
const series = priceSeries.chunks.at(index)?.();
|
||||
const series = priceSeries.chunks.at(index);
|
||||
|
||||
series?.update(latest);
|
||||
if (series) {
|
||||
signals.createEffect(series, (series) => {
|
||||
series?.update(latest);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
createLiveCandleUpdateEffect();
|
||||
@@ -870,10 +898,10 @@ export function init({
|
||||
initGoToButtons(elements.timeScaleHeightButtons);
|
||||
|
||||
function createScaleButtonsToggleEffect() {
|
||||
signals.createEffect(() => {
|
||||
const scaleIsDate = scale() === "date";
|
||||
elements.timeScaleDateButtons.hidden = !scaleIsDate;
|
||||
elements.timeScaleHeightButtons.hidden = scaleIsDate;
|
||||
const isDate = signals.createMemo(() => scale() === "date");
|
||||
signals.createEffect(isDate, (isDate) => {
|
||||
elements.timeScaleDateButtons.hidden = !isDate;
|
||||
elements.timeScaleHeightButtons.hidden = isDate;
|
||||
});
|
||||
}
|
||||
createScaleButtonsToggleEffect();
|
||||
@@ -1065,11 +1093,10 @@ export function init({
|
||||
);
|
||||
|
||||
function createSetMinMaxMarkersWhenIdleEffect() {
|
||||
signals.createEffect(() => {
|
||||
visibleTimeRange();
|
||||
dark();
|
||||
signals.untrack(setMinMaxMarkersWhenIdle);
|
||||
});
|
||||
signals.createEffect(
|
||||
() => [visibleTimeRange(), dark()],
|
||||
setMinMaxMarkersWhenIdle,
|
||||
);
|
||||
}
|
||||
createSetMinMaxMarkersWhenIdleEffect();
|
||||
|
||||
@@ -1097,12 +1124,12 @@ export function init({
|
||||
const priceLineSeries = _createPriceSeries("Line");
|
||||
|
||||
function createLinkPriceSeriesEffect() {
|
||||
signals.createEffect(() => {
|
||||
priceCandlestickSeries.active.set(priceLineSeries.active());
|
||||
signals.createEffect(priceLineSeries.active, (active) => {
|
||||
priceCandlestickSeries.active.set(active);
|
||||
});
|
||||
|
||||
signals.createEffect(() => {
|
||||
priceLineSeries.active.set(priceCandlestickSeries.active());
|
||||
signals.createEffect(priceCandlestickSeries.active, (active) => {
|
||||
priceLineSeries.active.set(active);
|
||||
});
|
||||
}
|
||||
createLinkPriceSeriesEffect();
|
||||
@@ -1142,9 +1169,8 @@ export function init({
|
||||
chartSeries.forEach((series) => {
|
||||
allSeries.unshift(series);
|
||||
|
||||
signals.createEffect(() => {
|
||||
series.active();
|
||||
signals.untrack(setMinMaxMarkersWhenIdle);
|
||||
signals.createEffect(series.active, () => {
|
||||
setMinMaxMarkersWhenIdle();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1153,17 +1179,17 @@ export function init({
|
||||
);
|
||||
|
||||
function createChartVisibilityEffect() {
|
||||
signals.createEffect(() => {
|
||||
signals.createEffect(chartVisible, (chartVisible) => {
|
||||
const chartWrapper = chartDiv.parentElement;
|
||||
if (!chartWrapper) throw "Should exist";
|
||||
chartWrapper.hidden = !chartVisible();
|
||||
chartWrapper.hidden = !chartVisible;
|
||||
});
|
||||
}
|
||||
createChartVisibilityEffect();
|
||||
|
||||
function createTimeScaleVisibilityEffect() {
|
||||
signals.createEffect(() => {
|
||||
const visible = chartIndex === chartCount - 1 && chartVisible();
|
||||
signals.createEffect(chartVisible, (chartVisible) => {
|
||||
const visible = chartIndex === chartCount - 1 && chartVisible;
|
||||
|
||||
chart.timeScale().applyOptions({
|
||||
visible,
|
||||
@@ -1178,9 +1204,9 @@ export function init({
|
||||
}
|
||||
createTimeScaleVisibilityEffect();
|
||||
|
||||
signals.createEffect(() =>
|
||||
signals.createEffect(chartMode, (chartMode) =>
|
||||
chart.priceScale("right").applyOptions({
|
||||
mode: chartMode() === "linear" ? 0 : 1,
|
||||
mode: chartMode === "linear" ? 0 : 1,
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -1235,9 +1261,8 @@ export function init({
|
||||
}
|
||||
|
||||
function createApplyChartOptionEffect() {
|
||||
signals.createEffect(() => {
|
||||
const option = selected();
|
||||
signals.createUntrackedRoot(() => {
|
||||
signals.createEffect(selected, (option) => {
|
||||
signals.createRoot(() => {
|
||||
applyChartOption(option);
|
||||
});
|
||||
});
|
||||
|
||||
+160
-177
@@ -1,19 +1,19 @@
|
||||
// @ts-check
|
||||
|
||||
/**
|
||||
* @import { OptionPath, PartialOption, PartialOptionsGroup, PartialOptionsTree, Option, OptionsGroup, Series, PriceSeriesType, ResourceDataset, TimeScale, SerializedHistory, TimeRange, Unit, Marker, Weighted, DatasetPath, OHLC, FetchedJSON, DatasetValue, FetchedResult, AnyDatasetPath, SeriesBlueprint, BaselineSpecificSeriesBlueprint, CandlestickSpecificSeriesBlueprint, LineSpecificSeriesBlueprint, SpecificSeriesBlueprintWithChart, Signal, Color, SettingsTheme, DatasetCandlestickData, FoldersFilter, PartialChartOption, ChartOption, AnyPartialOption, ProcessedOptionAddons, OptionsTree, AnyPath, SimulationOption } from "./types/self"
|
||||
* @import { Option, ResourceDataset, TimeScale, SerializedHistory, TimeRange, Unit, Marker, Weighted, DatasetPath, OHLC, FetchedJSON, DatasetValue, FetchedResult, AnyDatasetPath, SeriesBlueprint, BaselineSpecificSeriesBlueprint, CandlestickSpecificSeriesBlueprint, LineSpecificSeriesBlueprint, SpecificSeriesBlueprintWithChart, Signal, Color, SettingsTheme, DatasetCandlestickData, FoldersFilter, PartialChartOption, ChartOption, AnyPartialOption, ProcessedOptionAddons, OptionsTree, AnyPath, SimulationOption } from "./types/self"
|
||||
* @import {createChart as CreateClassicChart, createChartEx as CreateCustomChart, LineStyleOptions} from "./packages/lightweight-charts/v4.2.0/types";
|
||||
* @import * as _ from "./packages/ufuzzy/v1.0.14/types"
|
||||
* @import { DeepPartial, ChartOptions, IChartApi, IHorzScaleBehavior, WhitespaceData, SingleValueData, ISeriesApi, Time, LogicalRange, SeriesMarker, CandlestickData, SeriesType, BaselineStyleOptions, SeriesOptionsCommon } from "./packages/lightweight-charts/v4.2.0/types"
|
||||
* @import { DatePath, HeightPath, LastPath } from "./types/paths";
|
||||
* @import { SignalOptions, untrack as Untrack } from "./packages/solid-signals/2024-04-17/types/core"
|
||||
* @import { getOwner as GetOwner, onCleanup as OnCleanup, Owner } from "./packages/solid-signals/2024-04-17/types/owner"
|
||||
* @import { createSignal as CreateSignal, createEffect as CreateEffect, Accessor, Setter, createMemo as CreateMemo, createRoot as CreateRoot, runWithOwner as RunWithOwner } from "./packages/solid-signals/2024-04-17/types/signals";
|
||||
* @import { SignalOptions } from "./packages/solid-signals/2024-10-28/types/core"
|
||||
* @import { getOwner as GetOwner, onCleanup as OnCleanup, Owner } from "./packages/solid-signals/2024-10-28/types/owner"
|
||||
* @import { createSignal as CreateSignal, createEffect as CreateEffect, Accessor, Setter, createMemo as CreateMemo, createRoot as CreateRoot, runWithOwner as RunWithOwner } from "./packages/solid-signals/2024-10-28/types/signals";
|
||||
*/
|
||||
|
||||
function initPackages() {
|
||||
async function importSignals() {
|
||||
return import("./packages/solid-signals/2024-04-17/script.js").then(
|
||||
return import("./packages/solid-signals/2024-10-28/script.js").then(
|
||||
(_signals) => {
|
||||
const signals = {
|
||||
createSolidSignal: /** @type {CreateSignal} */ (
|
||||
@@ -22,7 +22,6 @@ function initPackages() {
|
||||
createEffect: /** @type {CreateEffect} */ (_signals.createEffect),
|
||||
createMemo: /** @type {CreateMemo} */ (_signals.createMemo),
|
||||
createRoot: /** @type {CreateRoot} */ (_signals.createRoot),
|
||||
untrack: /** @type {Untrack} */ (_signals.untrack),
|
||||
getOwner: /** @type {GetOwner} */ (_signals.getOwner),
|
||||
runWithOwner: /** @type {RunWithOwner} */ (_signals.runWithOwner),
|
||||
onCleanup: /** @type {OnCleanup} */ (_signals.onCleanup),
|
||||
@@ -34,7 +33,10 @@ function initPackages() {
|
||||
* @returns {Signal<T>}
|
||||
*/
|
||||
createSignal(initialValue, options) {
|
||||
const [get, set] = this.createSolidSignal(initialValue, options);
|
||||
const [get, set] = this.createSolidSignal(
|
||||
/** @type {any} */ (initialValue),
|
||||
options,
|
||||
);
|
||||
|
||||
// @ts-ignore
|
||||
get.set = set;
|
||||
@@ -54,9 +56,7 @@ function initPackages() {
|
||||
}
|
||||
|
||||
let firstEffect = true;
|
||||
this.createEffect(() => {
|
||||
const value = get();
|
||||
|
||||
this.createEffect(get, (value) => {
|
||||
if (!save) return;
|
||||
|
||||
if (!firstEffect && save.id) {
|
||||
@@ -82,13 +82,6 @@ function initPackages() {
|
||||
// @ts-ignore
|
||||
return get;
|
||||
},
|
||||
/**
|
||||
* @param {(dispose: VoidFunction) => void} callback
|
||||
*/
|
||||
createUntrackedRoot: (callback) =>
|
||||
signals.untrack(() => {
|
||||
signals.createRoot(callback);
|
||||
}),
|
||||
};
|
||||
|
||||
return signals;
|
||||
@@ -285,34 +278,35 @@ function initPackages() {
|
||||
minimumWidth: 78,
|
||||
});
|
||||
|
||||
signals.createEffect(() => {
|
||||
const { default: _defaultColor, off: _offColor } = colors;
|
||||
|
||||
const defaultColor = _defaultColor();
|
||||
const offColor = _offColor();
|
||||
|
||||
chart.applyOptions({
|
||||
layout: {
|
||||
textColor: offColor,
|
||||
},
|
||||
rightPriceScale: {
|
||||
borderVisible: false,
|
||||
},
|
||||
timeScale: {
|
||||
borderVisible: false,
|
||||
},
|
||||
crosshair: {
|
||||
horzLine: {
|
||||
color: defaultColor,
|
||||
labelBackgroundColor: defaultColor,
|
||||
signals.createEffect(
|
||||
() => ({
|
||||
defaultColor: colors.default(),
|
||||
offColor: colors.off(),
|
||||
}),
|
||||
({ defaultColor, offColor }) => {
|
||||
chart.applyOptions({
|
||||
layout: {
|
||||
textColor: offColor,
|
||||
},
|
||||
vertLine: {
|
||||
color: defaultColor,
|
||||
labelBackgroundColor: defaultColor,
|
||||
rightPriceScale: {
|
||||
borderVisible: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
timeScale: {
|
||||
borderVisible: false,
|
||||
},
|
||||
crosshair: {
|
||||
horzLine: {
|
||||
color: defaultColor,
|
||||
labelBackgroundColor: defaultColor,
|
||||
},
|
||||
vertLine: {
|
||||
color: defaultColor,
|
||||
labelBackgroundColor: defaultColor,
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
return chart;
|
||||
}
|
||||
@@ -366,8 +360,8 @@ function initPackages() {
|
||||
const series = chart.addBaselineSeries(seriesOptions);
|
||||
|
||||
signals.runWithOwner(owner, () => {
|
||||
signals.createEffect(() => {
|
||||
series.applyOptions(computeColors());
|
||||
signals.createEffect(computeColors, (computeColors) => {
|
||||
series.applyOptions(computeColors);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -409,8 +403,8 @@ function initPackages() {
|
||||
});
|
||||
|
||||
signals.runWithOwner(owner, () => {
|
||||
signals.createEffect(() => {
|
||||
candlestickSeries.applyOptions(computeColors());
|
||||
signals.createEffect(computeColors, (computeColors) => {
|
||||
candlestickSeries.applyOptions(computeColors);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -441,8 +435,8 @@ function initPackages() {
|
||||
});
|
||||
|
||||
signals.runWithOwner(owner, () => {
|
||||
signals.createEffect(() => {
|
||||
series.applyOptions(computeColors());
|
||||
signals.createEffect(computeColors, (computeColors) => {
|
||||
series.applyOptions(computeColors);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -909,8 +903,8 @@ const utils = {
|
||||
if (typeof title === "string") {
|
||||
legend.innerHTML = title;
|
||||
} else {
|
||||
signals.createEffect(() => {
|
||||
legend.innerHTML = title();
|
||||
signals.createEffect(title, (title) => {
|
||||
legend.innerHTML = title;
|
||||
});
|
||||
}
|
||||
field.append(legend);
|
||||
@@ -2182,9 +2176,7 @@ function initWebSockets(signals) {
|
||||
krakenCandle.open();
|
||||
|
||||
function createDocumentTitleEffect() {
|
||||
signals.createEffect(() => {
|
||||
const latest = krakenCandle.latest();
|
||||
|
||||
signals.createEffect(krakenCandle.latest, (latest) => {
|
||||
if (latest) {
|
||||
const close = latest.close;
|
||||
console.log("close:", close);
|
||||
@@ -2231,13 +2223,13 @@ packages.signals().then((signals) =>
|
||||
);
|
||||
function createFetchLastValuesWhenNeededEffect() {
|
||||
let previousHeight = -1;
|
||||
signals.createEffect(() => {
|
||||
if (previousHeight !== lastHeight()) {
|
||||
signals.createEffect(lastHeight, (lastHeight) => {
|
||||
if (previousHeight !== lastHeight) {
|
||||
fetch("/api/last").then((response) => {
|
||||
response.json().then((json) => {
|
||||
if (typeof json === "object") {
|
||||
lastValues.set(json);
|
||||
previousHeight = lastHeight();
|
||||
previousHeight = lastHeight;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -2282,112 +2274,108 @@ packages.signals().then((signals) =>
|
||||
let firstChartOption = true;
|
||||
let firstSimulationOption = true;
|
||||
|
||||
signals.createEffect(() => {
|
||||
const option = options.selected();
|
||||
signals.createEffect(options.selected, (option) => {
|
||||
if (previousElement) {
|
||||
previousElement.hidden = true;
|
||||
utils.url.resetParams(option);
|
||||
utils.url.pushHistory(option.id);
|
||||
} else {
|
||||
utils.url.replaceHistory({ pathname: option.id });
|
||||
}
|
||||
|
||||
signals.untrack(() => {
|
||||
if (previousElement) {
|
||||
previousElement.hidden = true;
|
||||
utils.url.resetParams(option);
|
||||
utils.url.pushHistory(option.id);
|
||||
} else {
|
||||
utils.url.replaceHistory({ pathname: option.id });
|
||||
const hideTop = option.kind === "home" || option.kind === "pdf";
|
||||
elements.selectedHeader.hidden = hideTop;
|
||||
elements.selectedHr.hidden = hideTop;
|
||||
|
||||
elements.selectedTitle.innerHTML = option.title;
|
||||
elements.selectedDescription.innerHTML = option.serializedPath;
|
||||
|
||||
/** @type {HTMLElement} */
|
||||
let element;
|
||||
|
||||
switch (option.kind) {
|
||||
case "home": {
|
||||
element = elements.home;
|
||||
break;
|
||||
}
|
||||
case "chart": {
|
||||
element = elements.charts;
|
||||
|
||||
const hideTop = option.kind === "home" || option.kind === "pdf";
|
||||
elements.selectedHeader.hidden = hideTop;
|
||||
elements.selectedHr.hidden = hideTop;
|
||||
lastChartOption.set(option);
|
||||
|
||||
elements.selectedTitle.innerHTML = option.title;
|
||||
elements.selectedDescription.innerHTML = option.serializedPath;
|
||||
|
||||
/** @type {HTMLElement} */
|
||||
let element;
|
||||
|
||||
switch (option.kind) {
|
||||
case "home": {
|
||||
element = elements.home;
|
||||
break;
|
||||
}
|
||||
case "chart": {
|
||||
element = elements.charts;
|
||||
|
||||
lastChartOption.set(option);
|
||||
|
||||
if (firstChartOption) {
|
||||
const lightweightCharts = packages.lightweightCharts();
|
||||
const chartScript = import("./chart.js");
|
||||
utils.dom.importStyleAndThen("/styles/chart.css", () =>
|
||||
chartScript.then(({ init: initChartsElement }) =>
|
||||
lightweightCharts.then((lightweightCharts) =>
|
||||
signals.runWithOwner(owner, () =>
|
||||
initChartsElement({
|
||||
colors,
|
||||
consts,
|
||||
dark,
|
||||
datasets,
|
||||
elements,
|
||||
ids,
|
||||
lightweightCharts,
|
||||
options,
|
||||
selected: /** @type {any} */ (lastChartOption),
|
||||
signals,
|
||||
utils,
|
||||
webSockets,
|
||||
}),
|
||||
),
|
||||
if (firstChartOption) {
|
||||
const lightweightCharts = packages.lightweightCharts();
|
||||
const chartScript = import("./chart.js");
|
||||
utils.dom.importStyleAndThen("/styles/chart.css", () =>
|
||||
chartScript.then(({ init: initChartsElement }) =>
|
||||
lightweightCharts.then((lightweightCharts) =>
|
||||
signals.runWithOwner(owner, () =>
|
||||
initChartsElement({
|
||||
colors,
|
||||
consts,
|
||||
dark,
|
||||
datasets,
|
||||
elements,
|
||||
ids,
|
||||
lightweightCharts,
|
||||
options,
|
||||
selected: /** @type {any} */ (lastChartOption),
|
||||
signals,
|
||||
utils,
|
||||
webSockets,
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
firstChartOption = false;
|
||||
|
||||
break;
|
||||
),
|
||||
);
|
||||
}
|
||||
case "simulation": {
|
||||
element = elements.simulation;
|
||||
firstChartOption = false;
|
||||
|
||||
lastSimulationOption.set(option);
|
||||
break;
|
||||
}
|
||||
case "simulation": {
|
||||
element = elements.simulation;
|
||||
|
||||
if (firstSimulationOption) {
|
||||
const lightweightCharts = packages.lightweightCharts();
|
||||
const simulationScript = import("./simulation.js");
|
||||
lastSimulationOption.set(option);
|
||||
|
||||
utils.dom.importStyleAndThen("/styles/simulation.css", () =>
|
||||
simulationScript.then(({ init }) =>
|
||||
lightweightCharts.then((lightweightCharts) =>
|
||||
signals.runWithOwner(owner, () =>
|
||||
init({
|
||||
colors,
|
||||
consts,
|
||||
dark,
|
||||
datasets,
|
||||
elements,
|
||||
ids,
|
||||
lightweightCharts,
|
||||
options,
|
||||
selected: /** @type {any} */ (lastChartOption),
|
||||
signals,
|
||||
utils,
|
||||
webSockets,
|
||||
}),
|
||||
),
|
||||
if (firstSimulationOption) {
|
||||
const lightweightCharts = packages.lightweightCharts();
|
||||
const simulationScript = import("./simulation.js");
|
||||
|
||||
utils.dom.importStyleAndThen("/styles/simulation.css", () =>
|
||||
simulationScript.then(({ init }) =>
|
||||
lightweightCharts.then((lightweightCharts) =>
|
||||
signals.runWithOwner(owner, () =>
|
||||
init({
|
||||
colors,
|
||||
consts,
|
||||
dark,
|
||||
datasets,
|
||||
elements,
|
||||
ids,
|
||||
lightweightCharts,
|
||||
options,
|
||||
selected: /** @type {any} */ (lastChartOption),
|
||||
signals,
|
||||
utils,
|
||||
webSockets,
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
firstSimulationOption = false;
|
||||
),
|
||||
);
|
||||
}
|
||||
firstSimulationOption = false;
|
||||
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
element.hidden = false;
|
||||
previousElement = element;
|
||||
});
|
||||
element.hidden = false;
|
||||
previousElement = element;
|
||||
});
|
||||
}
|
||||
createApplyOptionEffect();
|
||||
@@ -2410,13 +2398,16 @@ packages.signals().then((signals) =>
|
||||
});
|
||||
});
|
||||
|
||||
signals.createEffect(() => {
|
||||
if (options.selected().isFavorite()) {
|
||||
elements.buttonFavorite.dataset.highlight = "";
|
||||
} else {
|
||||
delete elements.buttonFavorite.dataset.highlight;
|
||||
}
|
||||
});
|
||||
signals.createEffect(
|
||||
() => options.selected().isFavorite(),
|
||||
(isFavorite) => {
|
||||
if (isFavorite) {
|
||||
elements.buttonFavorite.dataset.highlight = "";
|
||||
} else {
|
||||
delete elements.buttonFavorite.dataset.highlight;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
initFavoriteButton();
|
||||
|
||||
@@ -2467,9 +2458,7 @@ packages.signals().then((signals) =>
|
||||
|
||||
function createMobileSwitchEffect() {
|
||||
let firstRun = true;
|
||||
signals.createEffect(() => {
|
||||
options.selected();
|
||||
|
||||
signals.createEffect(options.selected, () => {
|
||||
if (!firstRun && !utils.dom.isHidden(elements.selectedLabel)) {
|
||||
elements.selectedLabel.click();
|
||||
}
|
||||
@@ -2496,16 +2485,14 @@ packages.signals().then((signals) =>
|
||||
elements.foldersFilterAllCount.innerHTML =
|
||||
options.list.length.toLocaleString();
|
||||
|
||||
signals.createEffect(() => {
|
||||
elements.foldersFilterFavoritesCount.innerHTML = options.counters
|
||||
.favorites()
|
||||
.toLocaleString();
|
||||
signals.createEffect(options.counters.favorites, (counterFavorites) => {
|
||||
elements.foldersFilterFavoritesCount.innerHTML =
|
||||
counterFavorites.toLocaleString();
|
||||
});
|
||||
|
||||
signals.createEffect(() => {
|
||||
elements.foldersFilterNewCount.innerHTML = options.counters
|
||||
.new()
|
||||
.toLocaleString();
|
||||
signals.createEffect(options.counters.new, (counterNew) => {
|
||||
elements.foldersFilterNewCount.innerHTML =
|
||||
counterNew.toLocaleString();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2530,8 +2517,7 @@ packages.signals().then((signals) =>
|
||||
options.filter.set("new");
|
||||
});
|
||||
|
||||
signals.createEffect(() => {
|
||||
const f = options.filter();
|
||||
signals.createEffect(options.filter, (f) => {
|
||||
localStorage.setItem(ids.foldersFilter, f);
|
||||
switch (f) {
|
||||
case "all": {
|
||||
@@ -2866,9 +2852,7 @@ packages.signals().then((signals) =>
|
||||
}
|
||||
|
||||
function createUnshiftHistoryEffect() {
|
||||
signals.createEffect(() => {
|
||||
const option = options.selected();
|
||||
|
||||
signals.createEffect(options.selected, (option) => {
|
||||
const head = history.at(0);
|
||||
if (
|
||||
head &&
|
||||
@@ -2967,8 +2951,7 @@ packages.signals().then((signals) =>
|
||||
initHistoryListInDom();
|
||||
|
||||
function createUpdateHistoryEffect() {
|
||||
signals.createEffect(() => {
|
||||
const option = options.selected();
|
||||
signals.createEffect(options.selected, (option) => {
|
||||
const date = new Date();
|
||||
const testedString = dateToTestedString(date);
|
||||
|
||||
@@ -3088,11 +3071,11 @@ packages.signals().then((signals) =>
|
||||
}
|
||||
|
||||
function createUpdateDataThemeEffect() {
|
||||
signals.createEffect(() => {
|
||||
localStorage.setItem(settingsThemeLocalStorageKey, theme());
|
||||
signals.createEffect(theme, (theme) => {
|
||||
localStorage.setItem(settingsThemeLocalStorageKey, theme);
|
||||
updateTheme(
|
||||
theme() === "dark" ||
|
||||
(theme() === "system" &&
|
||||
theme === "dark" ||
|
||||
(theme === "system" &&
|
||||
preferredColorSchemeMatchMedia.matches),
|
||||
);
|
||||
});
|
||||
|
||||
+1294
-1274
File diff suppressed because it is too large
Load Diff
@@ -1,18 +1,13 @@
|
||||
// src/error.ts
|
||||
var NotReadyError = class extends Error {
|
||||
};
|
||||
var NotReadyError = class extends Error {};
|
||||
var NoOwnerError = class extends Error {
|
||||
constructor() {
|
||||
super(
|
||||
""
|
||||
);
|
||||
super("");
|
||||
}
|
||||
};
|
||||
var ContextNotFoundError = class extends Error {
|
||||
constructor() {
|
||||
super(
|
||||
""
|
||||
);
|
||||
super("");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -50,14 +45,12 @@ var Owner = class {
|
||||
h = defaultContext;
|
||||
f = null;
|
||||
constructor(signal = false) {
|
||||
if (currentOwner && !signal)
|
||||
currentOwner.append(this);
|
||||
if (currentOwner && !signal) currentOwner.append(this);
|
||||
}
|
||||
append(child) {
|
||||
child.k = this;
|
||||
child.j = this;
|
||||
if (this.g)
|
||||
this.g.j = child;
|
||||
if (this.g) this.g.j = child;
|
||||
child.g = this.g;
|
||||
this.g = child;
|
||||
if (child.h !== this.h) {
|
||||
@@ -68,9 +61,10 @@ var Owner = class {
|
||||
}
|
||||
}
|
||||
dispose(self = true) {
|
||||
if (this.a === STATE_DISPOSED)
|
||||
return;
|
||||
let head = self ? this.j || this.k : this, current = this.g, next = null;
|
||||
if (this.a === STATE_DISPOSED) return;
|
||||
let head = self ? this.j || this.k : this,
|
||||
current = this.g,
|
||||
next = null;
|
||||
while (current && current.k === this) {
|
||||
current.dispose(true);
|
||||
current.n();
|
||||
@@ -78,16 +72,12 @@ var Owner = class {
|
||||
current.g = null;
|
||||
current = next;
|
||||
}
|
||||
if (self)
|
||||
this.n();
|
||||
if (current)
|
||||
current.j = !self ? this : this.j;
|
||||
if (head)
|
||||
head.g = current;
|
||||
if (self) this.n();
|
||||
if (current) current.j = !self ? this : this.j;
|
||||
if (head) head.g = current;
|
||||
}
|
||||
n() {
|
||||
if (this.j)
|
||||
this.j.g = null;
|
||||
if (this.j) this.j.g = null;
|
||||
this.k = null;
|
||||
this.j = null;
|
||||
this.h = defaultContext;
|
||||
@@ -96,8 +86,7 @@ var Owner = class {
|
||||
this.emptyDisposal();
|
||||
}
|
||||
emptyDisposal() {
|
||||
if (!this.e)
|
||||
return;
|
||||
if (!this.e) return;
|
||||
if (Array.isArray(this.e)) {
|
||||
for (let i = 0; i < this.e.length; i++) {
|
||||
const callable = this.e[i];
|
||||
@@ -109,9 +98,9 @@ var Owner = class {
|
||||
this.e = null;
|
||||
}
|
||||
handleError(error) {
|
||||
if (!this.f)
|
||||
throw error;
|
||||
let i = 0, len = this.f.length;
|
||||
if (!this.f) throw error;
|
||||
let i = 0,
|
||||
len = this.f.length;
|
||||
for (i = 0; i < len; i++) {
|
||||
try {
|
||||
this.f[i](error);
|
||||
@@ -120,8 +109,7 @@ var Owner = class {
|
||||
error = e;
|
||||
}
|
||||
}
|
||||
if (i === len)
|
||||
throw error;
|
||||
if (i === len) throw error;
|
||||
}
|
||||
};
|
||||
function createContext(defaultValue, description) {
|
||||
@@ -131,7 +119,9 @@ function getContext(context, owner = currentOwner) {
|
||||
if (!owner) {
|
||||
throw new NoOwnerError();
|
||||
}
|
||||
const value = hasContext(context, owner) ? owner.h[context.id] : context.defaultValue;
|
||||
const value = hasContext(context, owner)
|
||||
? owner.h[context.id]
|
||||
: context.defaultValue;
|
||||
if (isUndefined(value)) {
|
||||
throw new ContextNotFoundError();
|
||||
}
|
||||
@@ -143,15 +133,14 @@ function setContext(context, value, owner = currentOwner) {
|
||||
}
|
||||
owner.h = {
|
||||
...owner.h,
|
||||
[context.id]: isUndefined(value) ? context.defaultValue : value
|
||||
[context.id]: isUndefined(value) ? context.defaultValue : value,
|
||||
};
|
||||
}
|
||||
function hasContext(context, owner = currentOwner) {
|
||||
return !isUndefined(owner?.h[context.id]);
|
||||
}
|
||||
function onCleanup(disposable) {
|
||||
if (!currentOwner)
|
||||
return;
|
||||
if (!currentOwner) return;
|
||||
const node = currentOwner;
|
||||
if (!node.e) {
|
||||
node.e = disposable;
|
||||
@@ -176,12 +165,10 @@ var Computations = [];
|
||||
var RenderEffects = [];
|
||||
var Effects = [];
|
||||
function flushSync() {
|
||||
if (!runningScheduled)
|
||||
runScheduled();
|
||||
if (!runningScheduled) runScheduled();
|
||||
}
|
||||
function flushQueue() {
|
||||
if (scheduled)
|
||||
return;
|
||||
if (scheduled) return;
|
||||
scheduled = true;
|
||||
queueMicrotask(runScheduled);
|
||||
}
|
||||
@@ -193,8 +180,7 @@ function runTop(node) {
|
||||
}
|
||||
}
|
||||
for (let i = ancestors.length - 1; i >= 0; i--) {
|
||||
if (ancestors[i].a !== STATE_DISPOSED)
|
||||
ancestors[i].l();
|
||||
if (ancestors[i].a !== STATE_DISPOSED) ancestors[i].l();
|
||||
}
|
||||
}
|
||||
function runScheduled() {
|
||||
@@ -222,8 +208,7 @@ function runScheduled() {
|
||||
}
|
||||
function runPureQueue(queue) {
|
||||
for (let i = 0; i < queue.length; i++) {
|
||||
if (queue[i].a !== STATE_CLEAN)
|
||||
runTop(queue[i]);
|
||||
if (queue[i].a !== STATE_CLEAN) runTop(queue[i]);
|
||||
}
|
||||
}
|
||||
function runEffectQueue(queue) {
|
||||
@@ -274,16 +259,12 @@ var Computation2 = class extends Owner {
|
||||
this.s = compute2;
|
||||
this.a = compute2 ? STATE_DIRTY : STATE_CLEAN;
|
||||
this.d = initialValue;
|
||||
if (options?.equals !== void 0)
|
||||
this.t = options.equals;
|
||||
if (options?.unobserved)
|
||||
this.x = options?.unobserved;
|
||||
if (options?.equals !== void 0) this.t = options.equals;
|
||||
if (options?.unobserved) this.x = options?.unobserved;
|
||||
}
|
||||
y() {
|
||||
if (this.s)
|
||||
this.l();
|
||||
if (!this.b || this.b.length)
|
||||
track(this);
|
||||
if (this.s) this.l();
|
||||
if (!this.b || this.b.length) track(this);
|
||||
newFlags |= this.i & ~currentMask;
|
||||
if (this.i & ERROR_BIT) {
|
||||
throw this.d;
|
||||
@@ -336,11 +317,14 @@ var Computation2 = class extends Owner {
|
||||
}
|
||||
/** Update the computation with a new value. */
|
||||
write(value, flags = 0, raw = false) {
|
||||
const newValue = !raw && typeof value === "function" ? value(this.d) : value;
|
||||
const valueChanged = newValue !== UNCHANGED && (!!(flags & ERROR_BIT) || this.t === false || !this.t(this.d, newValue));
|
||||
if (valueChanged)
|
||||
this.d = newValue;
|
||||
const changedFlagsMask = this.i ^ flags, changedFlags = changedFlagsMask & flags;
|
||||
const newValue =
|
||||
!raw && typeof value === "function" ? value(this.d) : value;
|
||||
const valueChanged =
|
||||
newValue !== UNCHANGED &&
|
||||
(!!(flags & ERROR_BIT) || this.t === false || !this.t(this.d, newValue));
|
||||
if (valueChanged) this.d = newValue;
|
||||
const changedFlagsMask = this.i ^ flags,
|
||||
changedFlags = changedFlagsMask & flags;
|
||||
this.i = flags;
|
||||
this.w = clock + 1;
|
||||
if (this.c) {
|
||||
@@ -358,8 +342,7 @@ var Computation2 = class extends Owner {
|
||||
* Set the current node's state, and recursively mark all of this node's observers as STATE_CHECK
|
||||
*/
|
||||
m(state) {
|
||||
if (this.a >= state)
|
||||
return;
|
||||
if (this.a >= state) return;
|
||||
this.a = state;
|
||||
if (this.c) {
|
||||
for (let i = 0; i < this.c.length; i++) {
|
||||
@@ -374,17 +357,16 @@ var Computation2 = class extends Owner {
|
||||
* @param newFlags The source's new flags, masked to just the changed ones.
|
||||
*/
|
||||
z(mask, newFlags2) {
|
||||
if (this.a >= STATE_DIRTY)
|
||||
return;
|
||||
if (this.a >= STATE_DIRTY) return;
|
||||
if (mask & this.p) {
|
||||
this.m(STATE_DIRTY);
|
||||
return;
|
||||
}
|
||||
if (this.a >= STATE_CHECK)
|
||||
return;
|
||||
if (this.a >= STATE_CHECK) return;
|
||||
const prevFlags = this.i & mask;
|
||||
const deltaFlags = prevFlags ^ newFlags2;
|
||||
if (newFlags2 === prevFlags) ; else if (deltaFlags & prevFlags & mask) {
|
||||
if (newFlags2 === prevFlags);
|
||||
else if (deltaFlags & prevFlags & mask) {
|
||||
this.m(STATE_CHECK);
|
||||
} else {
|
||||
this.i ^= deltaFlags;
|
||||
@@ -433,10 +415,8 @@ var Computation2 = class extends Owner {
|
||||
* Remove ourselves from the owner graph and the computation graph
|
||||
*/
|
||||
n() {
|
||||
if (this.a === STATE_DISPOSED)
|
||||
return;
|
||||
if (this.b)
|
||||
removeSourceObservers(this, 0);
|
||||
if (this.a === STATE_DISPOSED) return;
|
||||
if (this.b) removeSourceObservers(this, 0);
|
||||
super.n();
|
||||
}
|
||||
};
|
||||
@@ -450,7 +430,7 @@ function loadingState(node) {
|
||||
node.l();
|
||||
return !!(node.i & LOADING_BIT);
|
||||
},
|
||||
options
|
||||
options,
|
||||
);
|
||||
computation.p = ERROR_BIT | LOADING_BIT;
|
||||
setOwner(prevOwner);
|
||||
@@ -466,7 +446,7 @@ function errorState(node) {
|
||||
node.l();
|
||||
return !!(node.i & ERROR_BIT);
|
||||
},
|
||||
options
|
||||
options,
|
||||
);
|
||||
computation.p = ERROR_BIT;
|
||||
setOwner(prevOwner);
|
||||
@@ -474,10 +454,13 @@ function errorState(node) {
|
||||
}
|
||||
function track(computation) {
|
||||
if (currentObserver) {
|
||||
if (!newSources && currentObserver.b && currentObserver.b[newSourcesIndex] === computation) {
|
||||
if (
|
||||
!newSources &&
|
||||
currentObserver.b &&
|
||||
currentObserver.b[newSourcesIndex] === computation
|
||||
) {
|
||||
newSourcesIndex++;
|
||||
} else if (!newSources)
|
||||
newSources = [computation];
|
||||
} else if (!newSources) newSources = [computation];
|
||||
else if (computation !== newSources[newSources.length - 1]) {
|
||||
newSources.push(computation);
|
||||
}
|
||||
@@ -487,7 +470,9 @@ function track(computation) {
|
||||
}
|
||||
}
|
||||
function update(node) {
|
||||
const prevSources = newSources, prevSourcesIndex = newSourcesIndex, prevFlags = newFlags;
|
||||
const prevSources = newSources,
|
||||
prevSourcesIndex = newSourcesIndex,
|
||||
prevFlags = newFlags;
|
||||
newSources = null;
|
||||
newSourcesIndex = 0;
|
||||
newFlags = 0;
|
||||
@@ -504,8 +489,7 @@ function update(node) {
|
||||
}
|
||||
} finally {
|
||||
if (newSources) {
|
||||
if (node.b)
|
||||
removeSourceObservers(node, newSourcesIndex);
|
||||
if (node.b) removeSourceObservers(node, newSourcesIndex);
|
||||
if (node.b && newSourcesIndex > 0) {
|
||||
node.b.length = newSourcesIndex + newSources.length;
|
||||
for (let i = 0; i < newSources.length; i++) {
|
||||
@@ -517,10 +501,8 @@ function update(node) {
|
||||
let source;
|
||||
for (let i = newSourcesIndex; i < node.b.length; i++) {
|
||||
source = node.b[i];
|
||||
if (!source.c)
|
||||
source.c = [node];
|
||||
else
|
||||
source.c.push(node);
|
||||
if (!source.c) source.c = [node];
|
||||
else source.c.push(node);
|
||||
}
|
||||
} else if (node.b && newSourcesIndex < node.b.length) {
|
||||
removeSourceObservers(node, newSourcesIndex);
|
||||
@@ -541,8 +523,7 @@ function removeSourceObservers(node, index) {
|
||||
swap = source.c.indexOf(node);
|
||||
source.c[swap] = source.c[source.c.length - 1];
|
||||
source.c.pop();
|
||||
if (!source.c.length)
|
||||
source.x?.();
|
||||
if (!source.c.length) source.x?.();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -550,8 +531,7 @@ function isEqual(a, b) {
|
||||
return a === b;
|
||||
}
|
||||
function untrack(fn) {
|
||||
if (currentObserver === null)
|
||||
return fn();
|
||||
if (currentObserver === null) return fn();
|
||||
return compute(getOwner(), fn, null);
|
||||
}
|
||||
function hasUpdated(fn) {
|
||||
@@ -565,7 +545,9 @@ function hasUpdated(fn) {
|
||||
}
|
||||
}
|
||||
function compute(owner, compute2, observer) {
|
||||
const prevOwner = setOwner(owner), prevObserver = currentObserver, prevMask = currentMask;
|
||||
const prevOwner = setOwner(owner),
|
||||
prevObserver = currentObserver,
|
||||
prevMask = currentMask;
|
||||
currentObserver = observer;
|
||||
currentMask = observer?.p ?? DEFAULT_FLAGS;
|
||||
try {
|
||||
@@ -583,8 +565,7 @@ var EagerComputation = class extends Computation2 {
|
||||
Computations.push(this);
|
||||
}
|
||||
m(state) {
|
||||
if (this.a >= state)
|
||||
return;
|
||||
if (this.a >= state) return;
|
||||
if (this.a === STATE_CLEAN) {
|
||||
Computations.push(this);
|
||||
flushQueue();
|
||||
@@ -604,8 +585,7 @@ var BaseEffect = class extends Computation2 {
|
||||
this.o = initialValue;
|
||||
}
|
||||
write(value) {
|
||||
if (value === UNCHANGED)
|
||||
return this.d;
|
||||
if (value === UNCHANGED) return this.d;
|
||||
this.d = value;
|
||||
this.q = true;
|
||||
return value;
|
||||
@@ -626,8 +606,7 @@ var Effect = class extends BaseEffect {
|
||||
flushQueue();
|
||||
}
|
||||
m(state) {
|
||||
if (this.a >= state)
|
||||
return;
|
||||
if (this.a >= state) return;
|
||||
if (this.a === STATE_CLEAN) {
|
||||
Effects.push(this);
|
||||
flushQueue();
|
||||
@@ -642,8 +621,7 @@ var RenderEffect = class extends BaseEffect {
|
||||
RenderEffects.push(this);
|
||||
}
|
||||
m(state) {
|
||||
if (this.a >= state)
|
||||
return;
|
||||
if (this.a >= state) return;
|
||||
if (this.a === STATE_CLEAN) {
|
||||
RenderEffects.push(this);
|
||||
flushQueue();
|
||||
@@ -659,7 +637,7 @@ function createSignal(first, second, third) {
|
||||
const node2 = new Computation2(
|
||||
first(p ? untrack(p[0]) : second),
|
||||
null,
|
||||
third
|
||||
third,
|
||||
);
|
||||
return [node2.read.bind(node2), node2.write.bind(node2)];
|
||||
});
|
||||
@@ -677,7 +655,7 @@ function createAsync(fn, initial, options) {
|
||||
return {
|
||||
wait() {
|
||||
return source;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
const signal = new Computation2(initial, null, options);
|
||||
@@ -689,16 +667,15 @@ function createAsync(fn, initial, options) {
|
||||
},
|
||||
(error) => {
|
||||
signal.write(error, ERROR_BIT);
|
||||
}
|
||||
},
|
||||
);
|
||||
} else {
|
||||
let abort = false;
|
||||
onCleanup(() => abort = true);
|
||||
onCleanup(() => (abort = true));
|
||||
(async () => {
|
||||
try {
|
||||
for await (let value of source) {
|
||||
if (abort)
|
||||
return;
|
||||
if (abort) return;
|
||||
signal.write(value, 0);
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -711,43 +688,28 @@ function createAsync(fn, initial, options) {
|
||||
return () => lhs.wait().wait();
|
||||
}
|
||||
function createMemo(compute2, initialValue, options) {
|
||||
let node = new Computation2(
|
||||
initialValue,
|
||||
compute2,
|
||||
options
|
||||
);
|
||||
let node = new Computation2(initialValue, compute2, options);
|
||||
let value;
|
||||
return () => {
|
||||
if (node) {
|
||||
value = node.wait();
|
||||
if (!node.b?.length)
|
||||
node = void 0;
|
||||
if (!node.b?.length) node = void 0;
|
||||
}
|
||||
return value;
|
||||
};
|
||||
}
|
||||
function createEffect(compute2, effect, initialValue, options) {
|
||||
void new Effect(
|
||||
initialValue,
|
||||
compute2,
|
||||
effect,
|
||||
void 0
|
||||
);
|
||||
void new Effect(initialValue, compute2, effect, void 0);
|
||||
}
|
||||
function createRenderEffect(compute2, effect, initialValue, options) {
|
||||
void new RenderEffect(
|
||||
initialValue,
|
||||
compute2,
|
||||
effect,
|
||||
void 0
|
||||
);
|
||||
void new RenderEffect(initialValue, compute2, effect, void 0);
|
||||
}
|
||||
function createRoot(init) {
|
||||
const owner = new Owner();
|
||||
return compute(
|
||||
owner,
|
||||
!init.length ? init : () => init(() => owner.dispose()),
|
||||
null
|
||||
null,
|
||||
);
|
||||
}
|
||||
function runWithOwner(owner, run) {
|
||||
@@ -768,4 +730,33 @@ function catchError(fn, handler) {
|
||||
}
|
||||
}
|
||||
|
||||
export { Computation2 as Computation, ContextNotFoundError, Effect, NoOwnerError, NotReadyError, Owner, RenderEffect, catchError, compute, createAsync, createContext, createEffect, createMemo, createRenderEffect, createRoot, createSignal, flushSync, getContext, getObserver, getOwner, hasContext, hasUpdated, isEqual, onCleanup, runWithOwner, setContext, setOwner, untrack };
|
||||
export {
|
||||
Computation2 as Computation,
|
||||
ContextNotFoundError,
|
||||
Effect,
|
||||
NoOwnerError,
|
||||
NotReadyError,
|
||||
Owner,
|
||||
RenderEffect,
|
||||
catchError,
|
||||
compute,
|
||||
createAsync,
|
||||
createContext,
|
||||
createEffect,
|
||||
createMemo,
|
||||
createRenderEffect,
|
||||
createRoot,
|
||||
createSignal,
|
||||
flushSync,
|
||||
getContext,
|
||||
getObserver,
|
||||
getOwner,
|
||||
hasContext,
|
||||
hasUpdated,
|
||||
isEqual,
|
||||
onCleanup,
|
||||
runWithOwner,
|
||||
setContext,
|
||||
setOwner,
|
||||
untrack,
|
||||
};
|
||||
|
||||
@@ -19,7 +19,7 @@ self.addEventListener("install", (_event) => {
|
||||
"/styles/chart.css",
|
||||
"/scripts/packages/lean-qr/v2.3.4/script.js",
|
||||
"/scripts/packages/lightweight-charts/v4.2.0/script.js",
|
||||
"/scripts/packages/solid-signals/2024-04-17/script.js",
|
||||
"/scripts/packages/solid-signals/2024-10-28/script.js",
|
||||
"/scripts/packages/ufuzzy/v1.0.14/script.js",
|
||||
]);
|
||||
}),
|
||||
|
||||
@@ -384,8 +384,8 @@ function appendInputDate({ id, title, value, parent, today, signals }) {
|
||||
|
||||
input.min = "2011-01-01";
|
||||
|
||||
signals.createEffect(() => {
|
||||
input.max = today().toJSON().split("T")[0];
|
||||
signals.createEffect(today, (today) => {
|
||||
input.max = today.toJSON().split("T")[0];
|
||||
});
|
||||
|
||||
parent.append(input);
|
||||
|
||||
Vendored
+41
-3
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
Accessor,
|
||||
Setter,
|
||||
} from "../packages/solid-signals/2024-04-17/types/signals";
|
||||
} from "../packages/solid-signals/2024-10-28/types/signals";
|
||||
import {
|
||||
DeepPartial,
|
||||
BaselineStyleOptions,
|
||||
@@ -17,7 +17,8 @@ import {
|
||||
ISeriesApi,
|
||||
} from "../packages/lightweight-charts/v4.2.0/types";
|
||||
import { DatePath, HeightPath, LastPath } from "./paths";
|
||||
import { Owner } from "../packages/solid-signals/2024-04-17/types/owner";
|
||||
import { Owner } from "../packages/solid-signals/2024-10-28/types/owner";
|
||||
import { AnyPossibleCohortId } from "../options";
|
||||
|
||||
type GrowToSize<T, N extends number, A extends T[]> = A["length"] extends N
|
||||
? A
|
||||
@@ -52,7 +53,7 @@ interface BaselineSpecificSeriesBlueprint {
|
||||
|
||||
interface CandlestickSpecificSeriesBlueprint {
|
||||
type: "Candlestick";
|
||||
color?: undefined;
|
||||
color?: Color;
|
||||
options?: DeepPartial<CandlestickStyleOptions & SeriesOptionsCommon>;
|
||||
}
|
||||
|
||||
@@ -80,6 +81,8 @@ type SeriesBlueprint = {
|
||||
formatNumber?: false;
|
||||
} & AnySpecificSeriesBlueprint;
|
||||
|
||||
type SeriesBluePrintType = NonNullable<SeriesBlueprint["type"]>;
|
||||
|
||||
type Unit =
|
||||
| ""
|
||||
| "Bitcoin"
|
||||
@@ -289,3 +292,38 @@ declare global {
|
||||
MyNamespace: any;
|
||||
}
|
||||
}
|
||||
|
||||
interface HoveredLegend {
|
||||
label: HTMLLabelElement;
|
||||
series: Series;
|
||||
}
|
||||
|
||||
type NotFunction<T> = T extends Function ? never : T;
|
||||
|
||||
type Groups = import("../options").Groups;
|
||||
|
||||
type DefaultCohortOption = CohortOption<AnyPossibleCohortId>;
|
||||
|
||||
interface CohortOption<Id extends AnyPossibleCohortId> {
|
||||
scale: TimeScale;
|
||||
name: string;
|
||||
title: string;
|
||||
datasetId: Id;
|
||||
color: Color;
|
||||
filenameAddon?: string;
|
||||
}
|
||||
|
||||
type DefaultCohortOptions = CohortOptions<AnyPossibleCohortId>;
|
||||
|
||||
interface CohortOptions<Id extends AnyPossibleCohortId> {
|
||||
scale: TimeScale;
|
||||
name: string;
|
||||
title: string;
|
||||
list: CohortOption<Id>[];
|
||||
}
|
||||
|
||||
interface SeriesBlueprintParam<T> {
|
||||
title: string;
|
||||
singleColor?: Color;
|
||||
genPath: (id: T, scale: TimeScale) => AnyDatasetPath;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user