@jvs-milkdown/ctx 1.2.4 → 1.2.7

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/lib/index.js CHANGED
@@ -22,12 +22,14 @@ var Container = class {
22
22
  //#endregion
23
23
  //#region src/context/slice.ts
24
24
  var Slice = class {
25
- #watchers = [];
25
+ #watchers;
26
26
  #value;
27
- #emit = () => {
28
- this.#watchers.forEach((watcher) => watcher(this.#value));
29
- };
27
+ #emit;
30
28
  constructor(container, value, type) {
29
+ this.#watchers = [];
30
+ this.#emit = () => {
31
+ this.#watchers.forEach((watcher) => watcher(this.#value));
32
+ };
31
33
  this.set = (value) => {
32
34
  this.#value = value;
33
35
  this.#emit();
@@ -81,11 +83,15 @@ var Inspector = class {
81
83
  #meta;
82
84
  #container;
83
85
  #clock;
84
- #injectedSlices = /* @__PURE__ */ new Set();
85
- #consumedSlices = /* @__PURE__ */ new Set();
86
- #recordedTimers = /* @__PURE__ */ new Map();
87
- #waitTimers = /* @__PURE__ */ new Map();
86
+ #injectedSlices;
87
+ #consumedSlices;
88
+ #recordedTimers;
89
+ #waitTimers;
88
90
  constructor(container, clock, meta) {
91
+ this.#injectedSlices = /* @__PURE__ */ new Set();
92
+ this.#consumedSlices = /* @__PURE__ */ new Set();
93
+ this.#recordedTimers = /* @__PURE__ */ new Map();
94
+ this.#waitTimers = /* @__PURE__ */ new Map();
89
95
  this.read = () => {
90
96
  return {
91
97
  metadata: this.#meta,
@@ -138,16 +144,18 @@ var Inspector = class {
138
144
  this.onUse = (sliceType) => {
139
145
  this.#consumedSlices.add(sliceType);
140
146
  };
147
+ this.#getSlice = (sliceType) => {
148
+ return this.#container.get(sliceType).get();
149
+ };
150
+ this.#getTimer = (timerType) => {
151
+ return this.#clock.get(timerType).status;
152
+ };
141
153
  this.#container = container;
142
154
  this.#clock = clock;
143
155
  this.#meta = meta;
144
156
  }
145
- #getSlice = (sliceType) => {
146
- return this.#container.get(sliceType).get();
147
- };
148
- #getTimer = (timerType) => {
149
- return this.#clock.get(timerType).status;
150
- };
157
+ #getSlice;
158
+ #getTimer;
151
159
  };
152
160
  //#endregion
153
161
  //#region src/plugin/ctx.ts
@@ -237,11 +245,14 @@ var Clock = class {
237
245
  //#endregion
238
246
  //#region src/timer/timer.ts
239
247
  var Timer = class {
240
- #promise = null;
241
- #listener = null;
248
+ #promise;
249
+ #listener;
242
250
  #eventUniqId;
243
- #status = "pending";
251
+ #status;
244
252
  constructor(clock, type) {
253
+ this.#promise = null;
254
+ this.#listener = null;
255
+ this.#status = "pending";
245
256
  this.start = () => {
246
257
  this.#promise ??= new Promise((resolve, reject) => {
247
258
  this.#listener = (e) => {
@@ -267,6 +278,14 @@ var Timer = class {
267
278
  const event = new CustomEvent(this.type.name, { detail: { id: this.#eventUniqId } });
268
279
  dispatchEvent(event);
269
280
  };
281
+ this.#removeListener = () => {
282
+ if (this.#listener) removeEventListener(this.type.name, this.#listener);
283
+ };
284
+ this.#waitTimeout = (ifTimeout) => {
285
+ setTimeout(() => {
286
+ ifTimeout();
287
+ }, this.type.timeout);
288
+ };
270
289
  this.#eventUniqId = Symbol(type.name);
271
290
  this.type = type;
272
291
  clock.set(type.id, this);
@@ -274,14 +293,8 @@ var Timer = class {
274
293
  get status() {
275
294
  return this.#status;
276
295
  }
277
- #removeListener = () => {
278
- if (this.#listener) removeEventListener(this.type.name, this.#listener);
279
- };
280
- #waitTimeout = (ifTimeout) => {
281
- setTimeout(() => {
282
- ifTimeout();
283
- }, this.type.timeout);
284
- };
296
+ #removeListener;
297
+ #waitTimeout;
285
298
  };
286
299
  var TimerType = class {
287
300
  constructor(name, timeout = 3e3) {
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["#watchers","#value","#emit","#meta","#container","#clock","#injectedSlices","#consumedSlices","#recordedTimers","#waitTimers","#getSlice","#getTimer","#container","#clock","#meta","#inspector","#eventUniqId","#promise","#listener","#status","#removeListener","#waitTimeout"],"sources":["../src/context/container.ts","../src/context/slice.ts","../src/inspector/inspector.ts","../src/plugin/ctx.ts","../src/timer/clock.ts","../src/timer/timer.ts"],"sourcesContent":["import { contextNotFound } from '@jvs-milkdown/exception'\n\nimport type { Slice, SliceType } from './slice'\n\n/// @internal\nexport type SliceMap = Map<symbol, Slice>\n\n/// Container is a map of slices.\nexport class Container {\n /// @internal\n sliceMap: SliceMap = new Map()\n\n /// Get a slice from the container by slice type or slice name.\n get = <T, N extends string = string>(\n slice: SliceType<T, N> | N\n ): Slice<T, N> => {\n const context =\n typeof slice === 'string'\n ? [...this.sliceMap.values()].find((x) => x.type.name === slice)\n : this.sliceMap.get(slice.id)\n\n if (!context) {\n const name = typeof slice === 'string' ? slice : slice.name\n throw contextNotFound(name)\n }\n return context as Slice<T, N>\n }\n\n /// Remove a slice from the container by slice type or slice name.\n remove = <T, N extends string = string>(slice: SliceType<T, N> | N): void => {\n const context =\n typeof slice === 'string'\n ? [...this.sliceMap.values()].find((x) => x.type.name === slice)\n : this.sliceMap.get(slice.id)\n\n if (!context) return\n\n this.sliceMap.delete(context.type.id)\n }\n\n /// Check if the container has a slice by slice type or slice name.\n has = <T, N extends string = string>(slice: SliceType<T, N> | N): boolean => {\n if (typeof slice === 'string')\n return [...this.sliceMap.values()].some((x) => x.type.name === slice)\n\n return this.sliceMap.has(slice.id)\n }\n}\n","import { ctxCallOutOfScope } from '@jvs-milkdown/exception'\n\nimport type { SliceMap } from './container'\n\n/// Slice is a value of slice type.\nexport class Slice<T = any, N extends string = string> {\n /// The type of the slice.\n readonly type: SliceType<T, N>\n\n /// @internal\n #watchers: Array<(value: T) => unknown> = []\n\n /// @internal\n #value: T\n\n /// @internal\n #emit = () => {\n this.#watchers.forEach((watcher) => watcher(this.#value))\n }\n\n /// @internal\n constructor(container: SliceMap, value: T, type: SliceType<T, N>) {\n this.type = type\n this.#value = value\n container.set(type.id, this)\n }\n\n /// Add a watcher for changes in the slice.\n /// Returns a function to remove the watcher.\n on(watcher: (value: T) => unknown) {\n this.#watchers.push(watcher)\n return () => {\n this.#watchers = this.#watchers.filter((w) => w !== watcher)\n }\n }\n\n /// Add a one-time watcher for changes in the slice.\n /// The watcher will be removed after it is called.\n /// Returns a function to remove the watcher.\n once(watcher: (value: T) => unknown) {\n const off = this.on((value) => {\n watcher(value)\n off()\n })\n return off\n }\n\n /// Remove a watcher.\n off(watcher: (value: T) => unknown) {\n this.#watchers = this.#watchers.filter((w) => w !== watcher)\n }\n\n /// Remove all watchers.\n offAll() {\n this.#watchers = []\n }\n\n /// Set the value of the slice.\n set = (value: T) => {\n this.#value = value\n this.#emit()\n }\n\n /// Get the value of the slice.\n get = () => this.#value\n\n /// Update the value of the slice with a callback.\n update = (updater: (prev: T) => T) => {\n this.#value = updater(this.#value)\n this.#emit()\n }\n}\n\n/// Slice type can be used to create slices in different containers.\nexport class SliceType<T = any, N extends string = string> {\n /// The unique id of the slice type.\n readonly id: symbol\n /// The name of the slice type.\n readonly name: N\n /// @internal\n readonly _typeInfo: () => T\n /// @internal\n readonly _defaultValue: T\n\n /// Create a slice type with a default value and a name.\n /// The name should be unique in the container.\n constructor(value: T, name: N) {\n this.id = Symbol(`Context-${name}`)\n this.name = name\n this._defaultValue = value\n this._typeInfo = (): T => {\n throw ctxCallOutOfScope()\n }\n }\n\n /// Create a slice with a container.\n /// You can also pass a value to override the default value.\n create(container: SliceMap, value: T = this._defaultValue): Slice<T, N> {\n return new Slice(container, value, this)\n }\n}\n\n/// Create a slice type with a default value and a name.\n/// This is equivalent to `new SliceType(value, name)`.\nexport const createSlice = <T = any, N extends string = string>(\n value: T,\n name: N\n) => new SliceType(value, name)\n","import type { Container, SliceType } from '../context'\nimport type { Clock, TimerStatus, TimerType } from '../timer'\nimport type { Meta } from './meta'\n\nexport interface Telemetry {\n metadata: Meta\n injectedSlices: { name: string; value: unknown }[]\n consumedSlices: { name: string; value: unknown }[]\n recordedTimers: { name: string; duration: number; status: TimerStatus }[]\n waitTimers: { name: string; duration: number; status: TimerStatus }[]\n}\n\n/// The inspector object that is used to inspect the runtime environment of a ctx.\nexport class Inspector {\n /// @internal\n readonly #meta: Meta\n\n /// @internal\n readonly #container: Container\n\n /// @internal\n readonly #clock: Clock\n\n /// @internal\n readonly #injectedSlices: Set<SliceType | string> = new Set()\n\n /// @internal\n readonly #consumedSlices: Set<SliceType | string> = new Set()\n\n /// @internal\n readonly #recordedTimers: Map<\n TimerType,\n { duration: number; start: number }\n > = new Map()\n\n /// @internal\n readonly #waitTimers: Map<TimerType, { duration: number }> = new Map()\n\n /// Create an inspector with container, clock and metadata.\n constructor(container: Container, clock: Clock, meta: Meta) {\n this.#container = container\n this.#clock = clock\n this.#meta = meta\n }\n\n /// Read the runtime telemetry as an object of the ctx.\n read = (): Telemetry => {\n return {\n metadata: this.#meta,\n injectedSlices: [...this.#injectedSlices].map((slice) => ({\n name: typeof slice === 'string' ? slice : slice.name,\n value: this.#getSlice(slice),\n })),\n consumedSlices: [...this.#consumedSlices].map((slice) => ({\n name: typeof slice === 'string' ? slice : slice.name,\n value: this.#getSlice(slice),\n })),\n recordedTimers: [...this.#recordedTimers].map(\n ([timer, { duration }]) => ({\n name: timer.name,\n duration,\n status: this.#getTimer(timer),\n })\n ),\n waitTimers: [...this.#waitTimers].map(([timer, { duration }]) => ({\n name: timer.name,\n duration,\n status: this.#getTimer(timer),\n })),\n }\n }\n\n /// @internal\n readonly onRecord = (timerType: TimerType) => {\n this.#recordedTimers.set(timerType, { start: Date.now(), duration: 0 })\n }\n\n /// @internal\n readonly onClear = (timerType: TimerType) => {\n this.#recordedTimers.delete(timerType)\n }\n\n /// @internal\n readonly onDone = (timerType: TimerType) => {\n const timer = this.#recordedTimers.get(timerType)\n if (!timer) return\n timer.duration = Date.now() - timer.start\n }\n\n /// @internal\n readonly onWait = (timerType: TimerType, promise: Promise<void>) => {\n const start = Date.now()\n promise\n .finally(() => {\n this.#waitTimers.set(timerType, { duration: Date.now() - start })\n })\n .catch(console.error)\n }\n\n /// @internal\n readonly onInject = (sliceType: SliceType | string) => {\n this.#injectedSlices.add(sliceType)\n }\n\n /// @internal\n readonly onRemove = (sliceType: SliceType | string) => {\n this.#injectedSlices.delete(sliceType)\n }\n\n /// @internal\n readonly onUse = (sliceType: SliceType | string) => {\n this.#consumedSlices.add(sliceType)\n }\n\n /// @internal\n #getSlice = (sliceType: SliceType | string) => {\n return this.#container.get(sliceType).get()\n }\n\n /// @internal\n #getTimer = (timerType: TimerType) => {\n return this.#clock.get(timerType).status\n }\n}\n","import type { Container, Slice, SliceType } from '../context'\nimport type { Meta } from '../inspector'\nimport type { Clock, TimerType } from '../timer'\n\nimport { Inspector } from '../inspector'\n\n/// The ctx object that can be accessed in plugin and action.\nexport class Ctx {\n /// @internal\n readonly #container: Container\n /// @internal\n readonly #clock: Clock\n /// @internal\n readonly #meta?: Meta\n /// @internal\n readonly #inspector?: Inspector\n\n /// Create a ctx object with container and clock.\n constructor(container: Container, clock: Clock, meta?: Meta) {\n this.#container = container\n this.#clock = clock\n this.#meta = meta\n if (meta) this.#inspector = new Inspector(container, clock, meta)\n }\n\n /// Get metadata of the ctx.\n get meta() {\n return this.#meta\n }\n\n /// Get the inspector of the ctx.\n get inspector() {\n return this.#inspector\n }\n\n /// Produce a new ctx with metadata.\n /// The new ctx will link to the same container and clock with the current ctx.\n /// If the metadata is empty, it will return the current ctx.\n readonly produce = (meta?: Meta) => {\n if (meta && Object.keys(meta).length)\n return new Ctx(this.#container, this.#clock, { ...meta })\n\n return this\n }\n\n /// Add a slice into the ctx.\n readonly inject = <T>(sliceType: SliceType<T>, value?: T) => {\n const slice = sliceType.create(this.#container.sliceMap)\n if (value != null) slice.set(value)\n\n this.#inspector?.onInject(sliceType)\n\n return this\n }\n\n /// Remove a slice from the ctx.\n readonly remove = <T, N extends string = string>(\n sliceType: SliceType<T, N> | N\n ) => {\n this.#container.remove(sliceType)\n this.#inspector?.onRemove(sliceType)\n return this\n }\n\n /// Add a timer into the ctx.\n readonly record = (timerType: TimerType) => {\n timerType.create(this.#clock.store)\n this.#inspector?.onRecord(timerType)\n return this\n }\n\n /// Remove a timer from the ctx.\n readonly clearTimer = (timerType: TimerType) => {\n this.#clock.remove(timerType)\n this.#inspector?.onClear(timerType)\n return this\n }\n\n /// Check if the ctx has a slice.\n readonly isInjected = <T, N extends string = string>(\n sliceType: SliceType<T, N> | N\n ) => this.#container.has(sliceType)\n\n /// Check if the ctx has a timer.\n readonly isRecorded = (timerType: TimerType) => this.#clock.has(timerType)\n\n /// Get a slice from the ctx.\n readonly use = <T, N extends string = string>(\n sliceType: SliceType<T, N> | N\n ): Slice<T, N> => {\n this.#inspector?.onUse(sliceType)\n return this.#container.get(sliceType)\n }\n\n /// Get a slice value from the ctx.\n readonly get = <T, N extends string>(sliceType: SliceType<T, N> | N) =>\n this.use(sliceType).get()\n\n /// Get a slice value from the ctx.\n readonly set = <T, N extends string>(\n sliceType: SliceType<T, N> | N,\n value: T\n ) => this.use(sliceType).set(value)\n\n /// Update a slice value from the ctx by a callback.\n readonly update = <T, N extends string>(\n sliceType: SliceType<T, N> | N,\n updater: (prev: T) => T\n ) => this.use(sliceType).update(updater)\n\n /// Get a timer from the ctx.\n readonly timer = (timer: TimerType) => this.#clock.get(timer)\n\n /// Resolve a timer from the ctx.\n readonly done = (timer: TimerType) => {\n this.timer(timer).done()\n this.#inspector?.onDone(timer)\n }\n\n /// Start a timer from the ctx.\n readonly wait = (timer: TimerType) => {\n const promise = this.timer(timer).start()\n this.#inspector?.onWait(timer, promise)\n return promise\n }\n\n /// Start a list of timers from the ctx, the list is stored in a slice in the ctx.\n /// This is equivalent to\n ///\n /// ```typescript\n /// Promise.all(ctx.get(slice).map(x => ctx.wait(x))).\n /// ```\n readonly waitTimers = async (slice: SliceType<TimerType[]>) => {\n await Promise.all(this.get(slice).map((x) => this.wait(x)))\n }\n}\n","import { timerNotFound } from '@jvs-milkdown/exception'\n\nimport type { Timer, TimerType } from './timer'\n\n/// @internal\nexport type TimerMap = Map<symbol, Timer>\n\n/// Container is a map of timers.\nexport class Clock {\n /// @internal\n readonly store: TimerMap = new Map()\n\n /// Get a timer from the clock by timer type.\n get = (timer: TimerType) => {\n const meta = this.store.get(timer.id)\n if (!meta) throw timerNotFound(timer.name)\n return meta\n }\n\n /// Remove a timer from the clock by timer type.\n remove = (timer: TimerType) => {\n this.store.delete(timer.id)\n }\n\n // Check if the clock has a timer by timer type.\n has = (timer: TimerType) => {\n return this.store.has(timer.id)\n }\n}\n","import type { TimerMap } from './clock'\n\nexport type TimerStatus = 'pending' | 'resolved' | 'rejected'\n\n/// Timer is a promise that can be resolved by calling done.\nexport class Timer {\n /// The type of the timer.\n readonly type: TimerType\n\n /// @internal\n #promise: Promise<void> | null = null\n /// @internal\n #listener: EventListener | null = null\n /// @internal\n readonly #eventUniqId: symbol\n /// @internal\n #status: TimerStatus = 'pending'\n\n /// @internal\n constructor(clock: TimerMap, type: TimerType) {\n this.#eventUniqId = Symbol(type.name)\n this.type = type\n clock.set(type.id, this)\n }\n\n /// The status of the timer.\n /// Can be `pending`, `resolved` or `rejected`.\n get status() {\n return this.#status\n }\n\n /// Start the timer, which will return a promise.\n /// If the timer is already started, it will return the same promise.\n /// If the timer is not resolved in the timeout, it will reject the promise.\n start = () => {\n this.#promise ??= new Promise((resolve, reject) => {\n this.#listener = (e: Event) => {\n if (!(e instanceof CustomEvent)) return\n\n if (e.detail.id === this.#eventUniqId) {\n this.#status = 'resolved'\n this.#removeListener()\n e.stopImmediatePropagation()\n resolve()\n }\n }\n\n this.#waitTimeout(() => {\n if (this.#status === 'pending') this.#status = 'rejected'\n\n this.#removeListener()\n reject(new Error(`Timing ${this.type.name} timeout.`))\n })\n\n this.#status = 'pending'\n addEventListener(this.type.name, this.#listener)\n })\n\n return this.#promise\n }\n\n /// Resolve the timer.\n done = () => {\n const event = new CustomEvent(this.type.name, {\n detail: { id: this.#eventUniqId },\n })\n dispatchEvent(event)\n }\n\n /// @internal\n #removeListener = () => {\n if (this.#listener) removeEventListener(this.type.name, this.#listener)\n }\n\n /// @internal\n #waitTimeout = (ifTimeout: () => void) => {\n setTimeout(() => {\n ifTimeout()\n }, this.type.timeout)\n }\n}\n\n/// Timer type can be used to create timers in different clocks.\nexport class TimerType {\n /// The unique id of the timer type.\n readonly id: symbol\n /// The name of the timer type.\n readonly name: string\n /// The timeout of the timer type.\n readonly timeout: number\n\n /// Create a timer type with a name and a timeout.\n /// The name should be unique in the clock.\n constructor(name: string, timeout = 3000) {\n this.id = Symbol(`Timer-${name}`)\n this.name = name\n this.timeout = timeout\n }\n\n /// Create a timer with a clock.\n create = (clock: TimerMap): Timer => {\n return new Timer(clock, this)\n }\n}\n\n/// Create a timer type with a name and a timeout.\n/// This is equivalent to `new TimerType(name, timeout)`.\nexport const createTimer = (name: string, timeout = 3000) =>\n new TimerType(name, timeout)\n"],"mappings":";;AAQA,IAAa,YAAb,MAAuB;;kCAEA,IAAI,KAAK;cAI5B,UACgB;GAChB,MAAM,UACJ,OAAO,UAAU,WACb,CAAC,GAAG,KAAK,SAAS,QAAQ,CAAC,CAAC,MAAM,MAAM,EAAE,KAAK,SAAS,MAAM,GAC9D,KAAK,SAAS,IAAI,MAAM,GAAG;AAEjC,OAAI,CAAC,QAEH,OAAM,gBADO,OAAO,UAAU,WAAW,QAAQ,MAAM,KAC5B;AAE7B,UAAO;;iBAI+B,UAAqC;GAC3E,MAAM,UACJ,OAAO,UAAU,WACb,CAAC,GAAG,KAAK,SAAS,QAAQ,CAAC,CAAC,MAAM,MAAM,EAAE,KAAK,SAAS,MAAM,GAC9D,KAAK,SAAS,IAAI,MAAM,GAAG;AAEjC,OAAI,CAAC,QAAS;AAEd,QAAK,SAAS,OAAO,QAAQ,KAAK,GAAG;;cAIF,UAAwC;AAC3E,OAAI,OAAO,UAAU,SACnB,QAAO,CAAC,GAAG,KAAK,SAAS,QAAQ,CAAC,CAAC,MAAM,MAAM,EAAE,KAAK,SAAS,MAAM;AAEvE,UAAO,KAAK,SAAS,IAAI,MAAM,GAAG;;;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AAe;AACf,qBAAiB,KAAK,KAAK,MAAM,MAAA,SAAe;KAChD;AAEF,UAAO,MAAA;;oBAII;GACX,MAAM,QAAQ,IAAI,YAAY,KAAK,KAAK,MAAM,EAC5C,QAAQ,EAAE,IAAI,MAAA,aAAmB,EAClC,CAAC;AACF,iBAAc,MAAM;;AA9CpB,QAAA,cAAoB,OAAO,KAAK,KAAK;AACrC,OAAK,OAAO;AACZ,QAAM,IAAI,KAAK,IAAI,KAAK;;CAK1B,IAAI,SAAS;AACX,SAAO,MAAA;;CA0CT,wBAAwB;AACtB,MAAI,MAAA,SAAgB,qBAAoB,KAAK,KAAK,MAAM,MAAA,SAAe;;CAIzE,gBAAgB,cAA0B;AACxC,mBAAiB;AACf,cAAW;KACV,KAAK,KAAK,QAAQ;;;AAKzB,IAAa,YAAb,MAAuB;CAUrB,YAAY,MAAc,UAAU,KAAM;iBAOhC,UAA2B;AACnC,UAAO,IAAI,MAAM,OAAO,KAAK;;AAP7B,OAAK,KAAK,OAAO,SAAS,OAAO;AACjC,OAAK,OAAO;AACZ,OAAK,UAAU;;;AAWnB,IAAa,eAAe,MAAc,UAAU,QAClD,IAAI,UAAU,MAAM,QAAQ"}
1
+ {"version":3,"file":"index.js","names":["#watchers","#value","#emit","#meta","#container","#clock","#injectedSlices","#consumedSlices","#recordedTimers","#waitTimers","#getSlice","#getTimer","#container","#clock","#meta","#inspector","#eventUniqId","#promise","#listener","#status","#removeListener","#waitTimeout"],"sources":["../src/context/container.ts","../src/context/slice.ts","../src/inspector/inspector.ts","../src/plugin/ctx.ts","../src/timer/clock.ts","../src/timer/timer.ts"],"sourcesContent":["import { contextNotFound } from '@jvs-milkdown/exception'\n\nimport type { Slice, SliceType } from './slice'\n\n/// @internal\nexport type SliceMap = Map<symbol, Slice>\n\n/// Container is a map of slices.\nexport class Container {\n /// @internal\n sliceMap: SliceMap = new Map()\n\n /// Get a slice from the container by slice type or slice name.\n get = <T, N extends string = string>(\n slice: SliceType<T, N> | N\n ): Slice<T, N> => {\n const context =\n typeof slice === 'string'\n ? [...this.sliceMap.values()].find((x) => x.type.name === slice)\n : this.sliceMap.get(slice.id)\n\n if (!context) {\n const name = typeof slice === 'string' ? slice : slice.name\n throw contextNotFound(name)\n }\n return context as Slice<T, N>\n }\n\n /// Remove a slice from the container by slice type or slice name.\n remove = <T, N extends string = string>(slice: SliceType<T, N> | N): void => {\n const context =\n typeof slice === 'string'\n ? [...this.sliceMap.values()].find((x) => x.type.name === slice)\n : this.sliceMap.get(slice.id)\n\n if (!context) return\n\n this.sliceMap.delete(context.type.id)\n }\n\n /// Check if the container has a slice by slice type or slice name.\n has = <T, N extends string = string>(slice: SliceType<T, N> | N): boolean => {\n if (typeof slice === 'string')\n return [...this.sliceMap.values()].some((x) => x.type.name === slice)\n\n return this.sliceMap.has(slice.id)\n }\n}\n","import { ctxCallOutOfScope } from '@jvs-milkdown/exception'\n\nimport type { SliceMap } from './container'\n\n/// Slice is a value of slice type.\nexport class Slice<T = any, N extends string = string> {\n /// The type of the slice.\n readonly type: SliceType<T, N>\n\n /// @internal\n #watchers: Array<(value: T) => unknown> = []\n\n /// @internal\n #value: T\n\n /// @internal\n #emit = () => {\n this.#watchers.forEach((watcher) => watcher(this.#value))\n }\n\n /// @internal\n constructor(container: SliceMap, value: T, type: SliceType<T, N>) {\n this.type = type\n this.#value = value\n container.set(type.id, this)\n }\n\n /// Add a watcher for changes in the slice.\n /// Returns a function to remove the watcher.\n on(watcher: (value: T) => unknown) {\n this.#watchers.push(watcher)\n return () => {\n this.#watchers = this.#watchers.filter((w) => w !== watcher)\n }\n }\n\n /// Add a one-time watcher for changes in the slice.\n /// The watcher will be removed after it is called.\n /// Returns a function to remove the watcher.\n once(watcher: (value: T) => unknown) {\n const off = this.on((value) => {\n watcher(value)\n off()\n })\n return off\n }\n\n /// Remove a watcher.\n off(watcher: (value: T) => unknown) {\n this.#watchers = this.#watchers.filter((w) => w !== watcher)\n }\n\n /// Remove all watchers.\n offAll() {\n this.#watchers = []\n }\n\n /// Set the value of the slice.\n set = (value: T) => {\n this.#value = value\n this.#emit()\n }\n\n /// Get the value of the slice.\n get = () => this.#value\n\n /// Update the value of the slice with a callback.\n update = (updater: (prev: T) => T) => {\n this.#value = updater(this.#value)\n this.#emit()\n }\n}\n\n/// Slice type can be used to create slices in different containers.\nexport class SliceType<T = any, N extends string = string> {\n /// The unique id of the slice type.\n readonly id: symbol\n /// The name of the slice type.\n readonly name: N\n /// @internal\n readonly _typeInfo: () => T\n /// @internal\n readonly _defaultValue: T\n\n /// Create a slice type with a default value and a name.\n /// The name should be unique in the container.\n constructor(value: T, name: N) {\n this.id = Symbol(`Context-${name}`)\n this.name = name\n this._defaultValue = value\n this._typeInfo = (): T => {\n throw ctxCallOutOfScope()\n }\n }\n\n /// Create a slice with a container.\n /// You can also pass a value to override the default value.\n create(container: SliceMap, value: T = this._defaultValue): Slice<T, N> {\n return new Slice(container, value, this)\n }\n}\n\n/// Create a slice type with a default value and a name.\n/// This is equivalent to `new SliceType(value, name)`.\nexport const createSlice = <T = any, N extends string = string>(\n value: T,\n name: N\n) => new SliceType(value, name)\n","import type { Container, SliceType } from '../context'\nimport type { Clock, TimerStatus, TimerType } from '../timer'\nimport type { Meta } from './meta'\n\nexport interface Telemetry {\n metadata: Meta\n injectedSlices: { name: string; value: unknown }[]\n consumedSlices: { name: string; value: unknown }[]\n recordedTimers: { name: string; duration: number; status: TimerStatus }[]\n waitTimers: { name: string; duration: number; status: TimerStatus }[]\n}\n\n/// The inspector object that is used to inspect the runtime environment of a ctx.\nexport class Inspector {\n /// @internal\n readonly #meta: Meta\n\n /// @internal\n readonly #container: Container\n\n /// @internal\n readonly #clock: Clock\n\n /// @internal\n readonly #injectedSlices: Set<SliceType | string> = new Set()\n\n /// @internal\n readonly #consumedSlices: Set<SliceType | string> = new Set()\n\n /// @internal\n readonly #recordedTimers: Map<\n TimerType,\n { duration: number; start: number }\n > = new Map()\n\n /// @internal\n readonly #waitTimers: Map<TimerType, { duration: number }> = new Map()\n\n /// Create an inspector with container, clock and metadata.\n constructor(container: Container, clock: Clock, meta: Meta) {\n this.#container = container\n this.#clock = clock\n this.#meta = meta\n }\n\n /// Read the runtime telemetry as an object of the ctx.\n read = (): Telemetry => {\n return {\n metadata: this.#meta,\n injectedSlices: [...this.#injectedSlices].map((slice) => ({\n name: typeof slice === 'string' ? slice : slice.name,\n value: this.#getSlice(slice),\n })),\n consumedSlices: [...this.#consumedSlices].map((slice) => ({\n name: typeof slice === 'string' ? slice : slice.name,\n value: this.#getSlice(slice),\n })),\n recordedTimers: [...this.#recordedTimers].map(\n ([timer, { duration }]) => ({\n name: timer.name,\n duration,\n status: this.#getTimer(timer),\n })\n ),\n waitTimers: [...this.#waitTimers].map(([timer, { duration }]) => ({\n name: timer.name,\n duration,\n status: this.#getTimer(timer),\n })),\n }\n }\n\n /// @internal\n readonly onRecord = (timerType: TimerType) => {\n this.#recordedTimers.set(timerType, { start: Date.now(), duration: 0 })\n }\n\n /// @internal\n readonly onClear = (timerType: TimerType) => {\n this.#recordedTimers.delete(timerType)\n }\n\n /// @internal\n readonly onDone = (timerType: TimerType) => {\n const timer = this.#recordedTimers.get(timerType)\n if (!timer) return\n timer.duration = Date.now() - timer.start\n }\n\n /// @internal\n readonly onWait = (timerType: TimerType, promise: Promise<void>) => {\n const start = Date.now()\n promise\n .finally(() => {\n this.#waitTimers.set(timerType, { duration: Date.now() - start })\n })\n .catch(console.error)\n }\n\n /// @internal\n readonly onInject = (sliceType: SliceType | string) => {\n this.#injectedSlices.add(sliceType)\n }\n\n /// @internal\n readonly onRemove = (sliceType: SliceType | string) => {\n this.#injectedSlices.delete(sliceType)\n }\n\n /// @internal\n readonly onUse = (sliceType: SliceType | string) => {\n this.#consumedSlices.add(sliceType)\n }\n\n /// @internal\n #getSlice = (sliceType: SliceType | string) => {\n return this.#container.get(sliceType).get()\n }\n\n /// @internal\n #getTimer = (timerType: TimerType) => {\n return this.#clock.get(timerType).status\n }\n}\n","import type { Container, Slice, SliceType } from '../context'\nimport type { Meta } from '../inspector'\nimport type { Clock, TimerType } from '../timer'\n\nimport { Inspector } from '../inspector'\n\n/// The ctx object that can be accessed in plugin and action.\nexport class Ctx {\n /// @internal\n readonly #container: Container\n /// @internal\n readonly #clock: Clock\n /// @internal\n readonly #meta?: Meta\n /// @internal\n readonly #inspector?: Inspector\n\n /// Create a ctx object with container and clock.\n constructor(container: Container, clock: Clock, meta?: Meta) {\n this.#container = container\n this.#clock = clock\n this.#meta = meta\n if (meta) this.#inspector = new Inspector(container, clock, meta)\n }\n\n /// Get metadata of the ctx.\n get meta() {\n return this.#meta\n }\n\n /// Get the inspector of the ctx.\n get inspector() {\n return this.#inspector\n }\n\n /// Produce a new ctx with metadata.\n /// The new ctx will link to the same container and clock with the current ctx.\n /// If the metadata is empty, it will return the current ctx.\n readonly produce = (meta?: Meta) => {\n if (meta && Object.keys(meta).length)\n return new Ctx(this.#container, this.#clock, { ...meta })\n\n return this\n }\n\n /// Add a slice into the ctx.\n readonly inject = <T>(sliceType: SliceType<T>, value?: T) => {\n const slice = sliceType.create(this.#container.sliceMap)\n if (value != null) slice.set(value)\n\n this.#inspector?.onInject(sliceType)\n\n return this\n }\n\n /// Remove a slice from the ctx.\n readonly remove = <T, N extends string = string>(\n sliceType: SliceType<T, N> | N\n ) => {\n this.#container.remove(sliceType)\n this.#inspector?.onRemove(sliceType)\n return this\n }\n\n /// Add a timer into the ctx.\n readonly record = (timerType: TimerType) => {\n timerType.create(this.#clock.store)\n this.#inspector?.onRecord(timerType)\n return this\n }\n\n /// Remove a timer from the ctx.\n readonly clearTimer = (timerType: TimerType) => {\n this.#clock.remove(timerType)\n this.#inspector?.onClear(timerType)\n return this\n }\n\n /// Check if the ctx has a slice.\n readonly isInjected = <T, N extends string = string>(\n sliceType: SliceType<T, N> | N\n ) => this.#container.has(sliceType)\n\n /// Check if the ctx has a timer.\n readonly isRecorded = (timerType: TimerType) => this.#clock.has(timerType)\n\n /// Get a slice from the ctx.\n readonly use = <T, N extends string = string>(\n sliceType: SliceType<T, N> | N\n ): Slice<T, N> => {\n this.#inspector?.onUse(sliceType)\n return this.#container.get(sliceType)\n }\n\n /// Get a slice value from the ctx.\n readonly get = <T, N extends string>(sliceType: SliceType<T, N> | N) =>\n this.use(sliceType).get()\n\n /// Get a slice value from the ctx.\n readonly set = <T, N extends string>(\n sliceType: SliceType<T, N> | N,\n value: T\n ) => this.use(sliceType).set(value)\n\n /// Update a slice value from the ctx by a callback.\n readonly update = <T, N extends string>(\n sliceType: SliceType<T, N> | N,\n updater: (prev: T) => T\n ) => this.use(sliceType).update(updater)\n\n /// Get a timer from the ctx.\n readonly timer = (timer: TimerType) => this.#clock.get(timer)\n\n /// Resolve a timer from the ctx.\n readonly done = (timer: TimerType) => {\n this.timer(timer).done()\n this.#inspector?.onDone(timer)\n }\n\n /// Start a timer from the ctx.\n readonly wait = (timer: TimerType) => {\n const promise = this.timer(timer).start()\n this.#inspector?.onWait(timer, promise)\n return promise\n }\n\n /// Start a list of timers from the ctx, the list is stored in a slice in the ctx.\n /// This is equivalent to\n ///\n /// ```typescript\n /// Promise.all(ctx.get(slice).map(x => ctx.wait(x))).\n /// ```\n readonly waitTimers = async (slice: SliceType<TimerType[]>) => {\n await Promise.all(this.get(slice).map((x) => this.wait(x)))\n }\n}\n","import { timerNotFound } from '@jvs-milkdown/exception'\n\nimport type { Timer, TimerType } from './timer'\n\n/// @internal\nexport type TimerMap = Map<symbol, Timer>\n\n/// Container is a map of timers.\nexport class Clock {\n /// @internal\n readonly store: TimerMap = new Map()\n\n /// Get a timer from the clock by timer type.\n get = (timer: TimerType) => {\n const meta = this.store.get(timer.id)\n if (!meta) throw timerNotFound(timer.name)\n return meta\n }\n\n /// Remove a timer from the clock by timer type.\n remove = (timer: TimerType) => {\n this.store.delete(timer.id)\n }\n\n // Check if the clock has a timer by timer type.\n has = (timer: TimerType) => {\n return this.store.has(timer.id)\n }\n}\n","import type { TimerMap } from './clock'\n\nexport type TimerStatus = 'pending' | 'resolved' | 'rejected'\n\n/// Timer is a promise that can be resolved by calling done.\nexport class Timer {\n /// The type of the timer.\n readonly type: TimerType\n\n /// @internal\n #promise: Promise<void> | null = null\n /// @internal\n #listener: EventListener | null = null\n /// @internal\n readonly #eventUniqId: symbol\n /// @internal\n #status: TimerStatus = 'pending'\n\n /// @internal\n constructor(clock: TimerMap, type: TimerType) {\n this.#eventUniqId = Symbol(type.name)\n this.type = type\n clock.set(type.id, this)\n }\n\n /// The status of the timer.\n /// Can be `pending`, `resolved` or `rejected`.\n get status() {\n return this.#status\n }\n\n /// Start the timer, which will return a promise.\n /// If the timer is already started, it will return the same promise.\n /// If the timer is not resolved in the timeout, it will reject the promise.\n start = () => {\n this.#promise ??= new Promise((resolve, reject) => {\n this.#listener = (e: Event) => {\n if (!(e instanceof CustomEvent)) return\n\n if (e.detail.id === this.#eventUniqId) {\n this.#status = 'resolved'\n this.#removeListener()\n e.stopImmediatePropagation()\n resolve()\n }\n }\n\n this.#waitTimeout(() => {\n if (this.#status === 'pending') this.#status = 'rejected'\n\n this.#removeListener()\n reject(new Error(`Timing ${this.type.name} timeout.`))\n })\n\n this.#status = 'pending'\n addEventListener(this.type.name, this.#listener)\n })\n\n return this.#promise\n }\n\n /// Resolve the timer.\n done = () => {\n const event = new CustomEvent(this.type.name, {\n detail: { id: this.#eventUniqId },\n })\n dispatchEvent(event)\n }\n\n /// @internal\n #removeListener = () => {\n if (this.#listener) removeEventListener(this.type.name, this.#listener)\n }\n\n /// @internal\n #waitTimeout = (ifTimeout: () => void) => {\n setTimeout(() => {\n ifTimeout()\n }, this.type.timeout)\n }\n}\n\n/// Timer type can be used to create timers in different clocks.\nexport class TimerType {\n /// The unique id of the timer type.\n readonly id: symbol\n /// The name of the timer type.\n readonly name: string\n /// The timeout of the timer type.\n readonly timeout: number\n\n /// Create a timer type with a name and a timeout.\n /// The name should be unique in the clock.\n constructor(name: string, timeout = 3000) {\n this.id = Symbol(`Timer-${name}`)\n this.name = name\n this.timeout = timeout\n }\n\n /// Create a timer with a clock.\n create = (clock: TimerMap): Timer => {\n return new Timer(clock, this)\n }\n}\n\n/// Create a timer type with a name and a timeout.\n/// This is equivalent to `new TimerType(name, timeout)`.\nexport const createTimer = (name: string, timeout = 3000) =>\n new TimerType(name, timeout)\n"],"mappings":";;AAQA,IAAa,YAAb,MAAuB;;kCAEA,IAAI,KAAK;cAI5B,UACgB;GAChB,MAAM,UACJ,OAAO,UAAU,WACb,CAAC,GAAG,KAAK,SAAS,QAAQ,CAAC,CAAC,MAAM,MAAM,EAAE,KAAK,SAAS,MAAM,GAC9D,KAAK,SAAS,IAAI,MAAM,GAAG;GAEjC,IAAI,CAAC,SAEH,MAAM,gBADO,OAAO,UAAU,WAAW,QAAQ,MAAM,KAC5B;GAE7B,OAAO;;iBAI+B,UAAqC;GAC3E,MAAM,UACJ,OAAO,UAAU,WACb,CAAC,GAAG,KAAK,SAAS,QAAQ,CAAC,CAAC,MAAM,MAAM,EAAE,KAAK,SAAS,MAAM,GAC9D,KAAK,SAAS,IAAI,MAAM,GAAG;GAEjC,IAAI,CAAC,SAAS;GAEd,KAAK,SAAS,OAAO,QAAQ,KAAK,GAAG;;cAIF,UAAwC;GAC3E,IAAI,OAAO,UAAU,UACnB,OAAO,CAAC,GAAG,KAAK,SAAS,QAAQ,CAAC,CAAC,MAAM,MAAM,EAAE,KAAK,SAAS,MAAM;GAEvE,OAAO,KAAK,SAAS,IAAI,MAAM,GAAG;;;;;;ACxCtC,IAAa,QAAb,MAAuD;CAKrD;CAGA;CAGA;CAKA,YAAY,WAAqB,OAAU,MAAuB;mBAXxB,EAAE;qBAM9B;GACZ,KAAKA,UAAU,SAAS,YAAY,QAAQ,KAAKC,OAAO,CAAC;;cAyCpD,UAAa;GAClB,KAAKA,SAAS;GACd,KAAKC,OAAO;;mBAIF,KAAKD;iBAGP,YAA4B;GACpC,KAAKA,SAAS,QAAQ,KAAKA,OAAO;GAClC,KAAKC,OAAO;;EA/CZ,KAAK,OAAO;EAC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,UAAU;;uBAIzD,cAA0B;GACxC,iBAAiB;IACf,WAAW;MACV,KAAK,KAAK,QAAQ;;EA1DrB,KAAKF,eAAe,OAAO,KAAK,KAAK;EACrC,KAAK,OAAO;EACZ,MAAM,IAAI,KAAK,IAAI,KAAK;;CAK1B,IAAI,SAAS;EACX,OAAO,KAAKG;;CA0Cd;CAKA;;AAQF,IAAa,YAAb,MAAuB;CAUrB,YAAY,MAAc,UAAU,KAAM;iBAOhC,UAA2B;GACnC,OAAO,IAAI,MAAM,OAAO,KAAK;;EAP7B,KAAK,KAAK,OAAO,SAAS,OAAO;EACjC,KAAK,OAAO;EACZ,KAAK,UAAU;;;AAWnB,IAAa,eAAe,MAAc,UAAU,QAClD,IAAI,UAAU,MAAM,QAAQ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jvs-milkdown/ctx",
3
- "version": "1.2.4",
3
+ "version": "1.2.7",
4
4
  "keywords": [
5
5
  "markdown",
6
6
  "markdown editor",
@@ -30,7 +30,7 @@
30
30
  }
31
31
  },
32
32
  "dependencies": {
33
- "@jvs-milkdown/exception": "^1.2.4"
33
+ "@jvs-milkdown/exception": "^1.2.7"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "vite build"