@luxalgo/vela 0.7.0 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/{DataProvider-Bu9E5Zh5.d.ts → DataProvider-BALR0qPq.d.ts} +1 -1
  2. package/dist/{DataProvider-Ck2qyS_9.d.cts → DataProvider-D5uMiJYz.d.cts} +1 -1
  3. package/dist/{chunk-IFJJPXSV.js → chunk-BFA32GOU.js} +44 -16
  4. package/dist/{chunk-CZRNTHD6.js → chunk-BKHSQ4YM.js} +129 -125
  5. package/dist/{chunk-A4G64KVF.js → chunk-PTNO3YK2.js} +311 -111
  6. package/dist/{chunk-A347YL2P.js → chunk-QBWLINWL.js} +67 -9
  7. package/dist/{chunk-UHXG5J7C.js → chunk-ZADTVRUO.js} +1 -1
  8. package/dist/{contributions-BjQ7hyIx.d.ts → contributions-BbhbZd3c.d.ts} +31 -9
  9. package/dist/{contributions-Cv2Mutvn.d.cts → contributions-CcBFe-91.d.cts} +31 -9
  10. package/dist/index.cjs +391 -157
  11. package/dist/index.d.cts +52 -17
  12. package/dist/index.d.ts +52 -17
  13. package/dist/index.js +4 -4
  14. package/dist/{options-ex2_gtKp.d.ts → options-C7b_Qssu.d.cts} +42 -1
  15. package/dist/{options-ex2_gtKp.d.cts → options-C7b_Qssu.d.ts} +42 -1
  16. package/dist/{plugin-CiyhU7pi.d.ts → plugin-Cnix5ZBh.d.ts} +6 -4
  17. package/dist/{plugin-absNH7Yn.d.cts → plugin-D6MlX4--.d.cts} +6 -4
  18. package/dist/plugin.cjs +39 -15
  19. package/dist/plugin.d.cts +4 -4
  20. package/dist/plugin.d.ts +4 -4
  21. package/dist/plugin.js +2 -2
  22. package/dist/providers/binance.d.cts +2 -2
  23. package/dist/providers/binance.d.ts +2 -2
  24. package/dist/providers/coinbase.d.cts +2 -2
  25. package/dist/providers/coinbase.d.ts +2 -2
  26. package/dist/providers/hyperliquid.d.cts +2 -2
  27. package/dist/providers/hyperliquid.d.ts +2 -2
  28. package/dist/{statusline-model-BXoU4Kua.d.ts → statusline-model-D8NL7o4L.d.ts} +3 -3
  29. package/dist/{statusline-model-cRhPBLPO.d.cts → statusline-model-DUKt7_TQ.d.cts} +3 -3
  30. package/dist/ui.cjs +8 -4
  31. package/dist/ui.d.cts +10 -7
  32. package/dist/ui.d.ts +10 -7
  33. package/dist/ui.js +2 -2
  34. package/dist/vela.global.js +391 -157
  35. package/dist/vela.global.min.js +70 -70
  36. package/dist/widget.cjs +418 -128
  37. package/dist/widget.d.cts +6 -6
  38. package/dist/widget.d.ts +6 -6
  39. package/dist/widget.js +6 -6
  40. package/dist/workspace.cjs +418 -128
  41. package/dist/workspace.d.cts +39 -6
  42. package/dist/workspace.d.ts +39 -6
  43. package/dist/workspace.js +5 -5
  44. package/package.json +1 -1
  45. /package/dist/{chunk-FE6V2YAQ.js → chunk-JU4CWEBF.js} +0 -0
@@ -1,7 +1,7 @@
1
- import { parseSymbol, priceStyleIds, BUILTIN_PRICE_STYLES, tzButtonLabel, SecondClock, TIMEZONES, normalizeTimezone, tzMenuLabel, isGroupRow, defaultMemberOf, groupKeyOf, groupMembers, LEGEND_AT_TOP_ATTR, normalizeSession, Vela, TypedEventBus, MultiProviderFeed, registerBuiltinChartTypes, resolveTheme, buildToolbar, createCustomMark, createAttributionMark, DrawingToolbar, applyAttributionMarkTheme, sharedBarStore, timeframeToMs } from './chunk-A4G64KVF.js';
2
- import { chartType, resolveTopbarComposition, topbarActionOverride, TOPBAR_BUILTIN_IDS, widgetActions, SidePanel, sidePanels, DEFAULT_PANEL_ORDER, symbolRanking, resolveEngines, legendActionsProviderFor, legendCalloutsProviderFor, statePersistenceHandlers, topbarHas, rendererDefaults, widgetAttachments, getDrawingType, inputDeltas } from './chunk-IFJJPXSV.js';
3
- import { Tooltip, KeymapManager, isEditableTarget, Drawer } from './chunk-UHXG5J7C.js';
4
- import { Menu, Dialog, CalloutBubble, applyPlotOverlayTokens, ensureUIHost } from './chunk-CZRNTHD6.js';
1
+ import { parseSymbol, priceStyleIds, BUILTIN_PRICE_STYLES, tzButtonLabel, SecondClock, TIMEZONES, normalizeTimezone, tzMenuLabel, isGroupRow, defaultMemberOf, groupKeyOf, groupMembers, LEGEND_AT_TOP_ATTR, normalizeSession, Vela, TypedEventBus, MultiProviderFeed, registerBuiltinChartTypes, resolveTheme, buildToolbar, createCustomMark, createAttributionMark, DrawingToolbar, applyAttributionMarkTheme, sharedBarStore, timeframeToMs } from './chunk-PTNO3YK2.js';
2
+ import { chartType, resolveTopbarComposition, topbarActionOverride, TOPBAR_BUILTIN_IDS, widgetActions, SidePanel, sidePanels, DEFAULT_PANEL_ORDER, symbolRanking, resolveEngines, legendActionsProviderFor, legendCalloutsProviderFor, statePersistenceHandlers, topbarHas, rendererDefaults, widgetAttachments, getDrawingType, inputDeltas } from './chunk-BFA32GOU.js';
3
+ import { Tooltip, KeymapManager, isEditableTarget, Drawer } from './chunk-ZADTVRUO.js';
4
+ import { Menu, Dialog, CalloutBubble, applyPlotOverlayTokens, ensureUIHost } from './chunk-BKHSQ4YM.js';
5
5
  import { registerIcon, svg16, injectStyles, iconEl, iconMarkup, iconAt, SESSION_OFF, SESSION_POST, SESSION_PRE, icon, categoricalColor } from './chunk-CAFCLMPF.js';
6
6
  import { baseOf } from './chunk-W4EJWLEO.js';
7
7
 
@@ -6107,7 +6107,8 @@ var ChartCell = class {
6107
6107
  this.statusline?.setFitMode(on);
6108
6108
  }
6109
6109
  /** The workspace shell keeps the app theme; the cell host's tokens re-derive from
6110
- * the LIVE plot surface (see {@link applyPlotOverlayTokens}). */
6110
+ * the LIVE plot surface for overlay ink (statusline, watermark). Menus portal to
6111
+ * `.vela-ui` and keep the app-theme surface (see {@link applyPlotOverlayTokens}). */
6111
6112
  syncPlotOverlayTokens() {
6112
6113
  applyPlotOverlayTokens(this.host, this.appTheme, this.inner?.renderer.getConfig() ?? null);
6113
6114
  }
@@ -8243,7 +8244,21 @@ var VelaWorkspace = class {
8243
8244
  /** Live sync configuration (mutable copy of the option). */
8244
8245
  this.syncOpts = {};
8245
8246
  this.stateTimer = null;
8246
- this.onUnload = () => this.persistNow();
8247
+ /** Re-entrance guard for {@link flushPendingState}: a `state:changed` subscriber that
8248
+ * calls back into the workspace (`destroy()` on save is the obvious one) must not
8249
+ * re-enter the flush and recurse. */
8250
+ this.emitting = false;
8251
+ /** False until the constructor finishes. Boot is not an edit: seeding the sync
8252
+ * settings marks state dirty, so without this a workspace mounted and torn down
8253
+ * inside the debounce window would flush and tell the host the user had changed
8254
+ * something — a save of the default document over whatever was stored. */
8255
+ this.booted = false;
8256
+ /** A page unload gets the same flush as a teardown — the pending edit reaches the
8257
+ * host, the timer is cleared, and a `destroy()` that follows adds no second write. */
8258
+ this.onUnload = () => {
8259
+ this.flushPendingState();
8260
+ this.persistNow();
8261
+ };
8247
8262
  /** Re-entrance guard around one propagation tick: followers' synchronous echoes
8248
8263
  * (their setVisibleRange re-emits viewport:changed) must not re-propagate. */
8249
8264
  this.syncBusy = false;
@@ -8557,6 +8572,7 @@ var VelaWorkspace = class {
8557
8572
  }
8558
8573
  this.mountAttachments();
8559
8574
  this.restoreGlobalExt();
8575
+ this.booted = true;
8560
8576
  }
8561
8577
  // ── access ──────────────────────────────────────────────────
8562
8578
  /** The cell with identity `id` (its declared name, or `c<N>` when undeclared), or
@@ -8965,13 +8981,17 @@ var VelaWorkspace = class {
8965
8981
  }
8966
8982
  destroy() {
8967
8983
  if (this.destroyed) return;
8968
- this.persistNow();
8984
+ this.flushPendingState();
8969
8985
  this.destroyed = true;
8970
- if (this.stateTimer != null) clearTimeout(this.stateTimer);
8971
8986
  if (this.persistKey !== null && typeof window !== "undefined") window.removeEventListener("beforeunload", this.onUnload);
8972
8987
  this.resizeObserver?.disconnect();
8973
8988
  this.splitters.destroy();
8974
8989
  for (const [id, cell] of [...this.cellsById]) {
8990
+ try {
8991
+ this.poolSet(id, cell.dehydrate());
8992
+ } catch (err) {
8993
+ console.warn(`[vela] could not snapshot cell "${id}" while destroying:`, err);
8994
+ }
8975
8995
  cell.destroy();
8976
8996
  this.cellsById.delete(id);
8977
8997
  }
@@ -9057,7 +9077,7 @@ var VelaWorkspace = class {
9057
9077
  /** Debounced dirty mark: one `state:changed` (+ one storage write in persist mode)
9058
9078
  * per burst of edits, flushed hard on unload/destroy. */
9059
9079
  markStateDirty() {
9060
- if (this.destroyed) return;
9080
+ if (this.destroyed || !this.booted) return;
9061
9081
  if (this.stateTimer != null) clearTimeout(this.stateTimer);
9062
9082
  this.stateTimer = setTimeout(() => {
9063
9083
  this.stateTimer = null;
@@ -9065,6 +9085,44 @@ var VelaWorkspace = class {
9065
9085
  this.persistNow();
9066
9086
  }, 500);
9067
9087
  }
9088
+ /**
9089
+ * Push a pending debounced change out NOW, for a teardown or a page unload — the
9090
+ * two moments the 500ms timer would otherwise never reach.
9091
+ *
9092
+ * Dropping it was a silent data loss: the timer carries BOTH halves of the dirty
9093
+ * signal — the `state:changed` event and the storage write — so a host that saves
9094
+ * from that event (a server-backed host, where `persistNow` is a no-op for want of
9095
+ * a `persistKey`) simply never heard about the user's last edit.
9096
+ *
9097
+ * Idempotent and re-entrancy safe, which the ordering here buys:
9098
+ * - a no-op unless a timer is actually pending, so a teardown with nothing
9099
+ * outstanding stays silent and never invents an edit;
9100
+ * - the timer is cleared FIRST, so nothing survives this call and a second call
9101
+ * does nothing — `destroy()` after an unload flush adds no second write;
9102
+ * - the state is snapshotted BEFORE the handlers run, and that snapshot is what
9103
+ * gets persisted, so storage and the host are told the same thing even if a
9104
+ * handler mutates state while it runs;
9105
+ * - `emitting` is held across the emit, so a handler calling back in (a host that
9106
+ * tears down on save is the obvious one) cannot re-enter this and recurse.
9107
+ */
9108
+ flushPendingState() {
9109
+ if (this.stateTimer == null || this.emitting) return;
9110
+ clearTimeout(this.stateTimer);
9111
+ this.stateTimer = null;
9112
+ const snapshot = this.persistKey !== null ? encodeState(this.getState()) : null;
9113
+ this.emitting = true;
9114
+ try {
9115
+ this.events.emit("state:changed", void 0);
9116
+ } finally {
9117
+ this.emitting = false;
9118
+ }
9119
+ if (snapshot !== null && this.persistKey !== null) {
9120
+ try {
9121
+ void this.storage.set(this.persistKey, snapshot);
9122
+ } catch {
9123
+ }
9124
+ }
9125
+ }
9068
9126
  /** Write the current state through the storage adapter now (fire-and-forget). */
9069
9127
  persistNow() {
9070
9128
  if (this.persistKey === null || this.destroyed) return;
@@ -1,4 +1,4 @@
1
- import { normalizeProps, nextUid, runMachine, spreadProps } from './chunk-CZRNTHD6.js';
1
+ import { normalizeProps, nextUid, runMachine, spreadProps } from './chunk-BKHSQ4YM.js';
2
2
  import { injectStyles } from './chunk-CAFCLMPF.js';
3
3
  import * as tooltip from '@zag-js/tooltip';
4
4
  import * as dialog from '@zag-js/dialog';
@@ -1,5 +1,5 @@
1
- import { x as Millis, an as InputSchema, al as IndicatorMeta, P as PriceStyle, O as OHLCV, I as InputValue, l as IndicatorModel, k as MoveTarget, aH as PaneAxis, aV as SeriesSpec, aj as Fill, G as Background, aM as PriceLine, a6 as DrawingLine, a2 as DrawingBox, a5 as DrawingLabel, aa as DrawingPolyline, a7 as DrawingLinefill, af as DrawingTable, h as IndicatorStatus, a as VisibleRange, c as VelaTheme, S as SerializedDrawing, z as DrawingTypeKey, y as SnapMode, a8 as DrawingMode, u as MarkClickEvent, e as IChartRenderer, R as RendererCapabilities, o as LegendActionView, p as LegendCalloutView, U as Unsubscribe, C as CrosshairEvent, A as AxisLongPressEvent, v as DataWindowReadout, n as SymbolPickerFn, W as WallClock, b8 as PaneInfo, ai as DrawingsOption, ac as DrawingSeriesGateway, D as Drawing, s as TimelineMark, t as MarkGroup, b as VelaOptions, E as AddIndicatorOptions, aG as MarketSwitch, aF as MarketSnapshot, V as VisibleRangePreset, T as ThemeName } from './options-ex2_gtKp.js';
2
- import { S as SymbolInfo, B as BarRange, M as MarketDataFeed, D as DataProvider, P as ProviderInfo, a as SymbolDescriptor, b as ProviderCapabilities } from './DataProvider-Bu9E5Zh5.js';
1
+ import { x as Millis, an as InputSchema, al as IndicatorMeta, P as PriceStyle, O as OHLCV, I as InputValue, l as IndicatorModel, k as MoveTarget, aH as PaneAxis, aW as SeriesSpec, aj as Fill, G as Background, aM as PriceLine, a6 as DrawingLine, a2 as DrawingBox, a5 as DrawingLabel, aa as DrawingPolyline, a7 as DrawingLinefill, af as DrawingTable, h as IndicatorStatus, a as VisibleRange, c as VelaTheme, S as SerializedDrawing, z as DrawingTypeKey, y as SnapMode, a8 as DrawingMode, u as MarkClickEvent, e as IChartRenderer, R as RendererCapabilities, o as LegendActionView, p as LegendCalloutView, U as Unsubscribe, C as CrosshairEvent, A as AxisLongPressEvent, v as DataWindowReadout, n as SymbolPickerFn, W as WallClock, bc as PaneInfo, ai as DrawingsOption, ac as DrawingSeriesGateway, D as Drawing, s as TimelineMark, t as MarkGroup, b as VelaOptions, E as AddIndicatorOptions, aG as MarketSwitch, aF as MarketSnapshot, V as VisibleRangePreset, T as ThemeName } from './options-C7b_Qssu.js';
2
+ import { S as SymbolInfo, B as BarRange, M as MarketDataFeed, D as DataProvider, P as ProviderInfo, a as SymbolDescriptor, b as ProviderCapabilities } from './DataProvider-BALR0qPq.js';
3
3
 
4
4
  /**
5
5
  * A strategy's broker state at ONE bar — the flat summary a host reads while a script
@@ -282,9 +282,10 @@ interface IndicatorEventMap extends Record<string, unknown> {
282
282
  interface IndicatorHandle {
283
283
  readonly id: string;
284
284
  readonly title: string;
285
- /** The script source this indicator was added with. `undefined` for a NATIVE
286
- * (core-computed) indicator there is no script to show. What a host editor
287
- * opens when a legend action asks for "the code behind this row". */
285
+ /** The script source this indicator currently runs (the one it was added with,
286
+ * until {@link updateCode} replaces it). `undefined` for a NATIVE (core-computed)
287
+ * indicator there is no script to show. What a host editor opens when a legend
288
+ * action asks for "the code behind this row". */
288
289
  readonly source?: string;
289
290
  /** The registered type of a NATIVE (core-computed) indicator — `undefined` for a
290
291
  * script indicator. The two are exclusive: a handle has a `source` or a `nativeType`. */
@@ -309,6 +310,17 @@ interface IndicatorHandle {
309
310
  setProp(key: string, value: InputValue): void;
310
311
  /** Override several declaration props at once and re-run. */
311
312
  setProps(values: Record<string, InputValue>): void;
313
+ /**
314
+ * Replace the script and re-run it **in place** — same `id`, same legend row, same
315
+ * pane placement, same handle; the seam for a host editor's "run my edit" and for a
316
+ * library's "update to the new version". The new source is prepared first: only once
317
+ * it compiles is the running script stopped and the new one started, so a broken edit
318
+ * leaves the current indicator computing and painting and reports through `error`.
319
+ * Input and prop values survive where the new script still declares their key;
320
+ * anything else takes the new declaration default. No-op for a native indicator and
321
+ * for an unchanged source.
322
+ */
323
+ updateCode(source: string): void;
312
324
  /**
313
325
  * Hide or show the indicator. Hiding **suspends** it — its visuals are dropped (the legend
314
326
  * row stays, marked hidden) and its computation stops (the engine session is torn down), so a
@@ -439,6 +451,10 @@ interface NativeIndicatorOutput {
439
451
  }
440
452
  /** Services the host gives a running native indicator. */
441
453
  interface NativeIndicatorContext {
454
+ /** This instance's indicator id — the same id its `IndicatorHandle`, `inspect()` and
455
+ * the pane listing report. Lets an instance name itself to host code (a picker, a
456
+ * hit-test) and tell itself apart from siblings of a `multiInstance` type. */
457
+ readonly id: string;
442
458
  readonly symbol: string;
443
459
  readonly timeframe: string;
444
460
  readonly live: boolean;
@@ -475,11 +491,13 @@ interface NativeIndicator {
475
491
  onViewport(range: VisibleRange): void;
476
492
  /** Settings changed — recompute + emit. */
477
493
  setInputs(inputs: Record<string, InputValue>): void;
478
- /** Hidden — stop timers/fetches (free resources); the instance + its state are kept for resume. */
494
+ /** Hidden — stop timers/fetches (free resources); the instance + its state are kept for resume.
495
+ * Only ever called after `start` (an instance added hidden is not suspended — it is
496
+ * started when first shown). */
479
497
  suspend(): void;
480
498
  /** Shown again — resume + re-emit. */
481
499
  resume(): void;
482
- /** Removed — full teardown (clear caches, stop timers). */
500
+ /** Removed — full teardown (clear caches, stop timers). Only ever called after `start`. */
483
501
  stop(): void;
484
502
  }
485
503
  /**
@@ -515,8 +533,10 @@ interface NativeIndicatorDescriptor {
515
533
  /**
516
534
  * Allow several instances of this type on one chart — every add creates a new one (a study
517
535
  * like a moving average is typically stacked at different lengths). Absent ⇒ SINGLE instance
518
- * per type: a second add returns the existing handle. A type that pushes a bespoke layer
519
- * payload through `pushData` must stay single-instance (the layer is keyed by type).
536
+ * per type: a second add returns the existing handle. A type that paints through a renderer
537
+ * layer (`pushData`) gets ONE layer instance per indicator instance, each fed by that
538
+ * instance's own channel and painting on that instance's pane — so instances never
539
+ * overwrite each other (see `IndicatorModel.native.channel`).
520
540
  */
521
541
  readonly multiInstance?: boolean;
522
542
  inputsSchema(): InputSchema[];
@@ -574,6 +594,8 @@ type ScriptRunCause =
574
594
  | 'bar'
575
595
  /** An input was edited. */
576
596
  | 'inputs'
597
+ /** The script's source was replaced in place (`handle.updateCode`). */
598
+ | 'code'
577
599
  /** The visible range moved (viewport-aware scripts only). */
578
600
  | 'viewport'
579
601
  /** The chart's market changed and the script re-executed over the new bars. */
@@ -1,5 +1,5 @@
1
- import { x as Millis, an as InputSchema, al as IndicatorMeta, P as PriceStyle, O as OHLCV, I as InputValue, l as IndicatorModel, k as MoveTarget, aH as PaneAxis, aV as SeriesSpec, aj as Fill, G as Background, aM as PriceLine, a6 as DrawingLine, a2 as DrawingBox, a5 as DrawingLabel, aa as DrawingPolyline, a7 as DrawingLinefill, af as DrawingTable, h as IndicatorStatus, a as VisibleRange, c as VelaTheme, S as SerializedDrawing, z as DrawingTypeKey, y as SnapMode, a8 as DrawingMode, u as MarkClickEvent, e as IChartRenderer, R as RendererCapabilities, o as LegendActionView, p as LegendCalloutView, U as Unsubscribe, C as CrosshairEvent, A as AxisLongPressEvent, v as DataWindowReadout, n as SymbolPickerFn, W as WallClock, b8 as PaneInfo, ai as DrawingsOption, ac as DrawingSeriesGateway, D as Drawing, s as TimelineMark, t as MarkGroup, b as VelaOptions, E as AddIndicatorOptions, aG as MarketSwitch, aF as MarketSnapshot, V as VisibleRangePreset, T as ThemeName } from './options-ex2_gtKp.cjs';
2
- import { S as SymbolInfo, B as BarRange, M as MarketDataFeed, D as DataProvider, P as ProviderInfo, a as SymbolDescriptor, b as ProviderCapabilities } from './DataProvider-Ck2qyS_9.cjs';
1
+ import { x as Millis, an as InputSchema, al as IndicatorMeta, P as PriceStyle, O as OHLCV, I as InputValue, l as IndicatorModel, k as MoveTarget, aH as PaneAxis, aW as SeriesSpec, aj as Fill, G as Background, aM as PriceLine, a6 as DrawingLine, a2 as DrawingBox, a5 as DrawingLabel, aa as DrawingPolyline, a7 as DrawingLinefill, af as DrawingTable, h as IndicatorStatus, a as VisibleRange, c as VelaTheme, S as SerializedDrawing, z as DrawingTypeKey, y as SnapMode, a8 as DrawingMode, u as MarkClickEvent, e as IChartRenderer, R as RendererCapabilities, o as LegendActionView, p as LegendCalloutView, U as Unsubscribe, C as CrosshairEvent, A as AxisLongPressEvent, v as DataWindowReadout, n as SymbolPickerFn, W as WallClock, bc as PaneInfo, ai as DrawingsOption, ac as DrawingSeriesGateway, D as Drawing, s as TimelineMark, t as MarkGroup, b as VelaOptions, E as AddIndicatorOptions, aG as MarketSwitch, aF as MarketSnapshot, V as VisibleRangePreset, T as ThemeName } from './options-C7b_Qssu.cjs';
2
+ import { S as SymbolInfo, B as BarRange, M as MarketDataFeed, D as DataProvider, P as ProviderInfo, a as SymbolDescriptor, b as ProviderCapabilities } from './DataProvider-D5uMiJYz.cjs';
3
3
 
4
4
  /**
5
5
  * A strategy's broker state at ONE bar — the flat summary a host reads while a script
@@ -282,9 +282,10 @@ interface IndicatorEventMap extends Record<string, unknown> {
282
282
  interface IndicatorHandle {
283
283
  readonly id: string;
284
284
  readonly title: string;
285
- /** The script source this indicator was added with. `undefined` for a NATIVE
286
- * (core-computed) indicator there is no script to show. What a host editor
287
- * opens when a legend action asks for "the code behind this row". */
285
+ /** The script source this indicator currently runs (the one it was added with,
286
+ * until {@link updateCode} replaces it). `undefined` for a NATIVE (core-computed)
287
+ * indicator there is no script to show. What a host editor opens when a legend
288
+ * action asks for "the code behind this row". */
288
289
  readonly source?: string;
289
290
  /** The registered type of a NATIVE (core-computed) indicator — `undefined` for a
290
291
  * script indicator. The two are exclusive: a handle has a `source` or a `nativeType`. */
@@ -309,6 +310,17 @@ interface IndicatorHandle {
309
310
  setProp(key: string, value: InputValue): void;
310
311
  /** Override several declaration props at once and re-run. */
311
312
  setProps(values: Record<string, InputValue>): void;
313
+ /**
314
+ * Replace the script and re-run it **in place** — same `id`, same legend row, same
315
+ * pane placement, same handle; the seam for a host editor's "run my edit" and for a
316
+ * library's "update to the new version". The new source is prepared first: only once
317
+ * it compiles is the running script stopped and the new one started, so a broken edit
318
+ * leaves the current indicator computing and painting and reports through `error`.
319
+ * Input and prop values survive where the new script still declares their key;
320
+ * anything else takes the new declaration default. No-op for a native indicator and
321
+ * for an unchanged source.
322
+ */
323
+ updateCode(source: string): void;
312
324
  /**
313
325
  * Hide or show the indicator. Hiding **suspends** it — its visuals are dropped (the legend
314
326
  * row stays, marked hidden) and its computation stops (the engine session is torn down), so a
@@ -439,6 +451,10 @@ interface NativeIndicatorOutput {
439
451
  }
440
452
  /** Services the host gives a running native indicator. */
441
453
  interface NativeIndicatorContext {
454
+ /** This instance's indicator id — the same id its `IndicatorHandle`, `inspect()` and
455
+ * the pane listing report. Lets an instance name itself to host code (a picker, a
456
+ * hit-test) and tell itself apart from siblings of a `multiInstance` type. */
457
+ readonly id: string;
442
458
  readonly symbol: string;
443
459
  readonly timeframe: string;
444
460
  readonly live: boolean;
@@ -475,11 +491,13 @@ interface NativeIndicator {
475
491
  onViewport(range: VisibleRange): void;
476
492
  /** Settings changed — recompute + emit. */
477
493
  setInputs(inputs: Record<string, InputValue>): void;
478
- /** Hidden — stop timers/fetches (free resources); the instance + its state are kept for resume. */
494
+ /** Hidden — stop timers/fetches (free resources); the instance + its state are kept for resume.
495
+ * Only ever called after `start` (an instance added hidden is not suspended — it is
496
+ * started when first shown). */
479
497
  suspend(): void;
480
498
  /** Shown again — resume + re-emit. */
481
499
  resume(): void;
482
- /** Removed — full teardown (clear caches, stop timers). */
500
+ /** Removed — full teardown (clear caches, stop timers). Only ever called after `start`. */
483
501
  stop(): void;
484
502
  }
485
503
  /**
@@ -515,8 +533,10 @@ interface NativeIndicatorDescriptor {
515
533
  /**
516
534
  * Allow several instances of this type on one chart — every add creates a new one (a study
517
535
  * like a moving average is typically stacked at different lengths). Absent ⇒ SINGLE instance
518
- * per type: a second add returns the existing handle. A type that pushes a bespoke layer
519
- * payload through `pushData` must stay single-instance (the layer is keyed by type).
536
+ * per type: a second add returns the existing handle. A type that paints through a renderer
537
+ * layer (`pushData`) gets ONE layer instance per indicator instance, each fed by that
538
+ * instance's own channel and painting on that instance's pane — so instances never
539
+ * overwrite each other (see `IndicatorModel.native.channel`).
520
540
  */
521
541
  readonly multiInstance?: boolean;
522
542
  inputsSchema(): InputSchema[];
@@ -574,6 +594,8 @@ type ScriptRunCause =
574
594
  | 'bar'
575
595
  /** An input was edited. */
576
596
  | 'inputs'
597
+ /** The script's source was replaced in place (`handle.updateCode`). */
598
+ | 'code'
577
599
  /** The visible range moved (viewport-aware scripts only). */
578
600
  | 'viewport'
579
601
  /** The chart's market changed and the script re-executed over the new bars. */