@tscircuit/core 0.0.203 → 0.0.204

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.
package/dist/index.d.ts CHANGED
@@ -41,6 +41,8 @@ declare abstract class Renderable implements IRenderable {
41
41
  constructor(props: any);
42
42
  protected _markDirty(phase: RenderPhase): void;
43
43
  protected _queueAsyncEffect(effect: () => Promise<void>): void;
44
+ protected _emitRenderLifecycleEvent(phase: RenderPhase, eventType: "start" | "end"): void;
45
+ getString(): string;
44
46
  _hasIncompleteAsyncEffects(): boolean;
45
47
  getCurrentRenderPhase(): RenderPhase | null;
46
48
  getRenderGraph(): Record<string, any>;
@@ -79,7 +81,7 @@ interface SchematicBoxDimensions {
79
81
  };
80
82
  }
81
83
 
82
- type RootCircuitEventName = "asyncEffectComplete";
84
+ type RootCircuitEventName = "asyncEffectComplete" | "renderable:renderLifecycle:anyEvent" | `renderable:renderLifecycle:${RenderPhase}:start` | `renderable:renderLifecycle:${RenderPhase}:end`;
83
85
  declare class Circuit {
84
86
  firstChild: PrimitiveComponent | null;
85
87
  children: PrimitiveComponent[];
package/dist/index.js CHANGED
@@ -143,6 +143,27 @@ var Renderable = class {
143
143
  }
144
144
  });
145
145
  }
146
+ _emitRenderLifecycleEvent(phase, eventType) {
147
+ const eventPayload = {
148
+ renderId: this._renderId,
149
+ componentDisplayName: this.getString()
150
+ };
151
+ const eventName = `renderable:renderLifecycle:${phase}:${eventType}`;
152
+ if ("root" in this && this.root) {
153
+ ;
154
+ this.root.emit(eventName, {
155
+ ...eventPayload,
156
+ type: eventName
157
+ });
158
+ this.root.emit("renderable:renderLifecycle:anyEvent", {
159
+ ...eventPayload,
160
+ type: eventName
161
+ });
162
+ }
163
+ }
164
+ getString() {
165
+ return this.constructor.name;
166
+ }
146
167
  _hasIncompleteAsyncEffects() {
147
168
  return this._asyncEffects.some((effect) => !effect.complete);
148
169
  }
@@ -150,7 +171,7 @@ var Renderable = class {
150
171
  return this._currentRenderPhase;
151
172
  }
152
173
  getRenderGraph() {
153
- const graph = {
174
+ return {
154
175
  id: this._renderId,
155
176
  currentPhase: this._currentRenderPhase,
156
177
  renderPhaseStates: this.renderPhaseStates,
@@ -159,7 +180,6 @@ var Renderable = class {
159
180
  (child) => child.getRenderGraph()
160
181
  )
161
182
  };
162
- return graph;
163
183
  }
164
184
  runRenderCycle() {
165
185
  for (const renderPhase of orderedRenderPhases) {
@@ -181,10 +201,11 @@ var Renderable = class {
181
201
  const isDirty = phaseState.dirty;
182
202
  if (!isInitialized && this.shouldBeRemoved) return;
183
203
  if (this.shouldBeRemoved && isInitialized) {
184
- ;
204
+ this._emitRenderLifecycleEvent(phase, "start");
185
205
  this?.[`remove${phase}`]?.();
186
206
  phaseState.initialized = false;
187
207
  phaseState.dirty = false;
208
+ this._emitRenderLifecycleEvent(phase, "end");
188
209
  return;
189
210
  }
190
211
  const prevPhaseIndex = orderedRenderPhases.indexOf(phase) - 1;
@@ -193,17 +214,20 @@ var Renderable = class {
193
214
  const hasIncompleteEffects = this._asyncEffects.filter((e) => e.phase === prevPhase).some((e) => !e.complete);
194
215
  if (hasIncompleteEffects) return;
195
216
  }
217
+ this._emitRenderLifecycleEvent(phase, "start");
196
218
  if (isInitialized) {
197
219
  if (isDirty) {
198
220
  ;
199
221
  this?.[`update${phase}`]?.();
200
222
  phaseState.dirty = false;
201
223
  }
224
+ this._emitRenderLifecycleEvent(phase, "end");
202
225
  return;
203
226
  }
204
227
  phaseState.dirty = false;
205
228
  this?.[`doInitial${phase}`]?.();
206
229
  phaseState.initialized = true;
230
+ this._emitRenderLifecycleEvent(phase, "end");
207
231
  }
208
232
  runRenderPhaseForChildren(phase) {
209
233
  for (const child of this.children) {
@@ -5580,7 +5604,7 @@ var Circuit = class {
5580
5604
  this._guessRootComponent();
5581
5605
  return this.firstChild?.selectOne(selector, opts) ?? null;
5582
5606
  }
5583
- _eventListeners = { asyncEffectComplete: [] };
5607
+ _eventListeners = {};
5584
5608
  emit(event, ...args) {
5585
5609
  if (!this._eventListeners[event]) return;
5586
5610
  for (const listener of this._eventListeners[event]) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.203",
4
+ "version": "0.0.204",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",