@odoo/owl 3.0.0-alpha.32 → 3.0.0-alpha.34

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.
@@ -142,6 +142,54 @@ export interface ComputationAtom<T = any> extends Atom<T> {
142
142
  state: ComputationState;
143
143
  }
144
144
  export declare function untrack<T>(fn: (...args: any[]) => T): T;
145
+ export interface ResourceOptions<T> {
146
+ name?: string;
147
+ validation?: T;
148
+ }
149
+ export interface ResourceAddOptions {
150
+ sequence?: number;
151
+ }
152
+ export declare class Resource<T> {
153
+ private _items;
154
+ private _name?;
155
+ private _validation?;
156
+ constructor(options?: ResourceOptions<T>);
157
+ items: ReactiveValue<T[], T[]>;
158
+ add(item: T, options?: ResourceAddOptions): Resource<T>;
159
+ delete(item: T): Resource<T>;
160
+ has(item: T): boolean;
161
+ use(item: T, options?: ResourceAddOptions): Resource<T>;
162
+ }
163
+ export interface PluginConstructor {
164
+ new (...args: any[]): Plugin$1;
165
+ id: string;
166
+ sequence: number;
167
+ }
168
+ declare class Plugin$1 {
169
+ private static _shadowId;
170
+ static get id(): string;
171
+ static set id(shadowId: string);
172
+ static sequence: number;
173
+ __owl__: PluginManager;
174
+ constructor(manager: PluginManager);
175
+ setup(): void;
176
+ }
177
+ export interface PluginManagerOptions {
178
+ parent?: PluginManager | null;
179
+ config?: Record<string, any>;
180
+ }
181
+ declare class PluginManager extends Scope {
182
+ config: Record<string, any>;
183
+ plugins: Record<string, Plugin$1>;
184
+ ready: Promise<void>;
185
+ private hasPendingReady;
186
+ constructor(app: any, options?: PluginManagerOptions);
187
+ destroy(): void;
188
+ getPluginById<T extends Plugin$1>(id: string): T | null;
189
+ getPlugin<T extends PluginConstructor>(pluginConstructor: T): InstanceType<T> | null;
190
+ startPlugin<T extends PluginConstructor>(pluginConstructor: T): InstanceType<T> | null;
191
+ startPlugins(pluginConstructors: PluginConstructor[]): void;
192
+ }
145
193
  /**
146
194
  * Returns the active scope. Throws if no scope is active — use this inside
147
195
  * hooks and setup functions where the caller is expected to be in a scope.
@@ -149,6 +197,7 @@ export declare function untrack<T>(fn: (...args: any[]) => T): T;
149
197
  export declare function useScope(): Scope;
150
198
  export declare abstract class Scope {
151
199
  app: any;
200
+ pluginManager: PluginManager;
152
201
  status: StatusValue;
153
202
  computations: ComputationAtom[];
154
203
  willStart: Array<() => any>;
@@ -226,31 +275,24 @@ export declare function markRaw<T extends Target>(value: T): T;
226
275
  */
227
276
  export declare function toRaw<T extends Target, U extends Reactive<T>>(value: U | T): T;
228
277
  /**
229
- * Creates a reactive proxy for an object. Reading data on the proxy object
230
- * subscribes to changes to the data. Writing data on the object will cause the
231
- * notify callback to be called if there are suscriptions to that data. Nested
232
- * objects and arrays are automatically made reactive as well.
278
+ * Wraps an object so it behaves like a signal, but with the familiar
279
+ * property-access API: instead of `count()` / `count.set(n)`, you write
280
+ * `state.count` and `state.count = n`. Reading and writing the proxy
281
+ * transparently looks and feels like reading and writing the original object.
233
282
  *
234
- * Whenever you are notified of a change, all subscriptions are cleared, and if
235
- * you would like to be notified of any further changes, you should go read
236
- * the underlying data again. We assume that if you don't go read it again after
237
- * being notified, it means that you are no longer interested in that data.
283
+ * Reactivity is nested: reading a property that holds another object/array
284
+ * returns a proxy for that value too, recursively. Arrays, Maps, Sets, and
285
+ * WeakMaps are also wrapped, so `state.items.push(x)` or `state.map.set(k, v)`
286
+ * notify subscribers the same way property writes do.
238
287
  *
239
- * Subscriptions:
240
- * + Reading a property on an object will subscribe you to changes in the value
241
- * of that property.
242
- * + Accessing an object's keys (eg with Object.keys or with `for..in`) will
243
- * subscribe you to the creation/deletion of keys. Checking the presence of a
244
- * key on the object with 'in' has the same effect.
245
- * - getOwnPropertyDescriptor does not currently subscribe you to the property.
246
- * This is a choice that was made because changing a key's value will trigger
247
- * this trap and we do not want to subscribe by writes. This also means that
248
- * Object.hasOwnProperty doesn't subscribe as it goes through this trap.
288
+ * Subscriptions are only created when a read happens *while a computation is
289
+ * active* i.e. inside a component's render, or inside an `effect`,
290
+ * `computed`, or `asyncComputed`. Reading the proxy from a plain function
291
+ * with no surrounding computation just returns the value without subscribing
292
+ * anything.
249
293
  *
250
- * @param target the object for which to create a proxy proxy
251
- * @param callback the function to call when an observed property of the
252
- * proxy has changed
253
- * @returns a proxy that tracks changes to it
294
+ * @param target the object to make reactive
295
+ * @returns a proxy that tracks reads/writes against `target`
254
296
  */
255
297
  export declare function proxy<T extends Target>(target: T): T;
256
298
  export interface Signal<T> extends ReactiveValue<T> {
@@ -311,7 +353,7 @@ export interface AsyncComputed<T> {
311
353
  export declare function asyncComputed<T>(fetcher: (ctx: AsyncComputedContext) => Promise<T>, options?: AsyncComputedOptions<T>): AsyncComputed<T>;
312
354
  export interface ValidationIssue {
313
355
  message: string;
314
- path?: PropertyKey[];
356
+ path?: string;
315
357
  received?: any;
316
358
  [K: string]: any;
317
359
  }
@@ -338,24 +380,6 @@ export type ResolveObjectType<T extends {}> = ResolveShapedObject<T extends stri
338
380
  export type UnionToIntersection<U> = (U extends any ? (_: U) => any : never) extends (_: infer I) => void ? I : never;
339
381
  declare function constructorType<T extends Constructor>(constructor: T): T;
340
382
  export type LiteralTypes = number | string | boolean | null | undefined;
341
- export interface ResourceOptions<T> {
342
- name?: string;
343
- validation?: T;
344
- }
345
- export interface ResourceAddOptions {
346
- sequence?: number;
347
- }
348
- export declare class Resource<T> {
349
- private _items;
350
- private _name?;
351
- private _validation?;
352
- constructor(options?: ResourceOptions<T>);
353
- items: ReactiveValue<T[], T[]>;
354
- add(item: T, options?: ResourceAddOptions): Resource<T>;
355
- delete(item: T): Resource<T>;
356
- has(item: T): boolean;
357
- use(item: T, options?: ResourceAddOptions): Resource<T>;
358
- }
359
383
  export interface RegistryOptions<T> {
360
384
  name?: string;
361
385
  validation?: T;
@@ -388,33 +412,43 @@ export declare class Registry<T> {
388
412
  id: string;
389
413
  } & T>(item: U, options?: RegistryAddOptions): Registry<T>;
390
414
  }
391
- export interface PluginConstructor {
392
- new (...args: any[]): Plugin$1;
393
- id: string;
394
- }
395
- declare class Plugin$1 {
396
- private static _shadowId;
397
- static get id(): string;
398
- static set id(shadowId: string);
399
- __owl__: PluginManager;
400
- constructor(manager: PluginManager);
401
- setup(): void;
402
- }
403
- export interface PluginManagerOptions {
404
- parent?: PluginManager | null;
405
- config?: Record<string, any>;
415
+ /**
416
+ * Creates a reactive effect bound to the surrounding component or plugin.
417
+ * Equivalent to `onWillDestroy(effect(fn))`: the effect runs once immediately,
418
+ * re-runs whenever any reactive value (signal, computed, proxy property) read
419
+ * during its execution changes, and is disposed when the owning scope is
420
+ * destroyed. If the callback returns a function, that function is called as
421
+ * cleanup before each re-run and on disposal.
422
+ */
423
+ export declare function useEffect(fn: Parameters<typeof effect>[0]): void;
424
+ /**
425
+ * Adds an event listener to a target and automatically removes it when the
426
+ * surrounding component or plugin is destroyed.
427
+ *
428
+ * `target` can be either an `EventTarget` (the listener is attached
429
+ * immediately) or a `Signal<EventTarget | null>` such as a `t-ref` (the
430
+ * listener is attached through a `useEffect` and re-attaches when the signal's
431
+ * value changes; nothing is attached while the signal is null).
432
+ *
433
+ * Example — close a menu when the user clicks anywhere on `window`:
434
+ * useListener(window, "click", () => this.close());
435
+ */
436
+ export declare function useListener(target: EventTarget | Signal<EventTarget | null>, eventName: string, handler: EventListener, eventParams?: AddEventListenerOptions): void;
437
+ export declare function onWillStart(fn: (scope: Scope) => Promise<void> | void | any): void;
438
+ export declare function onWillDestroy(fn: (scope: Scope) => void | any): void;
439
+ export type PluginInstance<T extends PluginConstructor> = Omit<InstanceType<T>, "setup">;
440
+ export declare function plugin<T extends PluginConstructor>(pluginType: T): PluginInstance<T>;
441
+ export declare function config<T = any>(key: string): T;
442
+ export declare function config<T>(key: string, type: T): T;
443
+ export declare function config<T>(key: string, type: T, defaultValue: T): T;
444
+ export declare class EventBus extends EventTarget {
445
+ trigger(name: string, payload?: any): void;
406
446
  }
407
- declare class PluginManager extends Scope {
408
- config: Record<string, any>;
409
- plugins: Record<string, Plugin$1>;
410
- ready: Promise<void>;
411
- constructor(app: any, options?: PluginManagerOptions);
412
- destroy(): void;
413
- getPluginById<T extends Plugin$1>(id: string): T | null;
414
- getPlugin<T extends PluginConstructor>(pluginConstructor: T): InstanceType<T> | null;
415
- startPlugin<T extends PluginConstructor>(pluginConstructor: T): InstanceType<T> | null;
416
- startPlugins(pluginConstructors: PluginConstructor[]): void;
447
+ declare class Markup extends String {
417
448
  }
449
+ export declare function htmlEscape(str: any): Markup;
450
+ export declare function markup(strings: TemplateStringsArray, ...placeholders: unknown[]): Markup;
451
+ export declare function markup(value: string): Markup;
418
452
  declare class Fiber {
419
453
  node: ComponentNode;
420
454
  bdom: BDom | null;
@@ -468,12 +502,12 @@ declare class ComponentNode extends Scope implements VNode<ComponentNode> {
468
502
  [key: string]: ComponentNode;
469
503
  };
470
504
  willUpdateProps: LifecycleHook[];
505
+ propsUpdated: LifecycleHook[];
471
506
  willUnmount: LifecycleHook[];
472
507
  mounted: LifecycleHook[];
473
508
  willPatch: LifecycleHook[];
474
509
  patched: LifecycleHook[];
475
510
  signalComputation: ComputationAtom;
476
- pluginManager: PluginManager;
477
511
  constructor(C: ComponentConstructor, props: Record<string, any>, app: App, parent: ComponentNode | null, parentKey: string | null);
478
512
  decorate(f: Function, hookName: string): Function;
479
513
  initiateRender(fiber: Fiber | MountFiber): Promise<void>;
@@ -512,6 +546,9 @@ export declare class Component {
512
546
  constructor(node: ComponentNode);
513
547
  setup(): void;
514
548
  }
549
+ declare function staticProp<T = any>(key: string): T;
550
+ declare function staticProp<T>(key: string, type: T): T;
551
+ declare function staticProp<T>(key: string, type: T, defaultValue: T): T;
515
552
  declare const isProps: unique symbol;
516
553
  export type WithDefaults<T, D> = T & Required<D>;
517
554
  export type Props<T extends {}> = T & {
@@ -526,11 +563,15 @@ export type GetProps<T> = {
526
563
  }[keyof T] extends (x: infer I) => void ? {
527
564
  [K in keyof I]: I[K];
528
565
  } : never;
529
- export declare function props(): Props<Record<string, any>>;
530
- export declare function props<const Keys extends string[]>(keys: Keys): Props<ResolveObjectType<Keys>>;
531
- export declare function props<const Keys extends string[], Defaults>(keys: Keys, defaults: Defaults & GetPropsDefaults<KeyedObject<Keys>>): Props<WithDefaults<ResolveObjectType<Keys>, Defaults>>;
532
- export declare function props<Shape extends {}>(shape: Shape): Props<ResolveObjectType<Shape>>;
533
- export declare function props<Shape extends {}, Defaults>(shape: Shape, defaults: Defaults & GetPropsDefaults<Shape>): Props<WithDefaults<ResolveObjectType<Shape>, Defaults>>;
566
+ export interface PropsFunction {
567
+ (): Props<Record<string, any>>;
568
+ <const Keys extends string[]>(keys: Keys): Props<ResolveObjectType<Keys>>;
569
+ <const Keys extends string[], Defaults>(keys: Keys, defaults: Defaults & GetPropsDefaults<KeyedObject<Keys>>): Props<WithDefaults<ResolveObjectType<Keys>, Defaults>>;
570
+ <Shape extends {}>(shape: Shape): Props<ResolveObjectType<Shape>>;
571
+ <Shape extends {}, Defaults>(shape: Shape, defaults: Defaults & GetPropsDefaults<Shape>): Props<WithDefaults<ResolveObjectType<Shape>, Defaults>>;
572
+ static: typeof staticProp;
573
+ }
574
+ export declare const props: PropsFunction;
534
575
  declare class Scheduler {
535
576
  static requestAnimationFrame: (callback: FrameRequestCallback) => number;
536
577
  tasks: Set<RootFiber>;
@@ -586,15 +627,7 @@ export declare namespace xml {
586
627
  var nextId: number;
587
628
  }
588
629
  declare function validateTarget(target: HTMLElement | ShadowRoot): void;
589
- export declare class EventBus extends EventTarget {
590
- trigger(name: string, payload?: any): void;
591
- }
592
630
  export declare function whenReady(fn?: any): Promise<void>;
593
- declare class Markup extends String {
594
- }
595
- export declare function htmlEscape(str: any): Markup;
596
- export declare function markup(strings: TemplateStringsArray, ...placeholders: unknown[]): Markup;
597
- export declare function markup(value: string): Markup;
598
631
  export type ComponentInstance<C extends ComponentConstructor> = C extends new (...args: any) => infer T ? T : never;
599
632
  export interface RootConfig<P> {
600
633
  props?: P;
@@ -642,7 +675,7 @@ export declare class Portal extends Component {
642
675
  slots: {
643
676
  default: any;
644
677
  };
645
- target: string | HTMLElement | ReactiveValue<HTMLElement, HTMLElement>;
678
+ target: any;
646
679
  }>;
647
680
  setup(): void;
648
681
  }
@@ -659,47 +692,14 @@ export declare class Suspense extends Component {
659
692
  private subRootMounted;
660
693
  setup(): void;
661
694
  }
662
- export declare function prop(key: string): any;
663
- export declare function prop<T>(key: string, type: T): T;
664
- export declare function prop<T>(key: string, type: T, defaultValue: T): T;
665
695
  export type STATUS_DESCR = "new" | "started" | "mounted" | "cancelled" | "destroyed";
666
696
  declare function status$1(entity: Component | Plugin$1): STATUS_DESCR;
667
- /**
668
- * This hook will run a callback when a component is mounted and patched, and
669
- * will run a cleanup function before patching and before unmounting the
670
- * the component.
671
- *
672
- * @template T
673
- * @param {Effect<T>} effect the effect to run on component mount and/or patch
674
- * @param {()=>[...T]} [computeDependencies=()=>[NaN]] a callback to compute
675
- * dependencies that will decide if the effect needs to be cleaned up and
676
- * run again. If the dependencies did not change, the effect will not run
677
- * again. The default value returns an array containing only NaN because
678
- * NaN !== NaN, which will cause the effect to rerun on every patch.
679
- */
680
- export declare function useEffect(fn: Parameters<typeof effect>[0]): void;
681
- /**
682
- * When a component needs to listen to DOM Events on element(s) that are not
683
- * part of his hierarchy, we can use the `useListener` hook.
684
- * It will immediately add the listener, and remove it whenever the plugin or
685
- * component is destroyed.
686
- *
687
- * Example:
688
- * a menu needs to listen to the click on window to be closed automatically
689
- *
690
- * Usage:
691
- * in the constructor of the OWL component that needs to be notified,
692
- * `useListener(window, 'click', () => this._doSomething());`
693
- * */
694
- export declare function useListener(target: EventTarget | Signal<EventTarget | null>, eventName: string, handler: EventListener, eventParams?: AddEventListenerOptions): void;
695
- export declare function useApp(): App;
696
- export declare function onWillStart(fn: (scope: Scope) => Promise<void> | void | any): void;
697
+ export declare const useApp: () => App;
697
698
  export declare function onWillUpdateProps(fn: (nextProps: any, scope: ComponentNode) => Promise<void> | void | any): void;
698
699
  export declare function onMounted(fn: (scope: ComponentNode) => void | any): void;
699
700
  export declare function onWillPatch(fn: (scope: ComponentNode) => any | void): void;
700
701
  export declare function onPatched(fn: (scope: ComponentNode) => void | any): void;
701
702
  export declare function onWillUnmount(fn: (scope: ComponentNode) => void | any): void;
702
- export declare function onWillDestroy(fn: (scope: Scope) => void | any): void;
703
703
  export type OnErrorCallback = (error: any) => void | any;
704
704
  export declare function onError(callback: OnErrorCallback): void;
705
705
  declare function componentType(): typeof Component;
@@ -709,6 +709,7 @@ export declare const types: {
709
709
  any: () => any;
710
710
  array: {
711
711
  (): any[];
712
+ <T>(): T[];
712
713
  <T>(elementType: T): T[];
713
714
  };
714
715
  boolean: () => boolean;
@@ -717,14 +718,16 @@ export declare const types: {
717
718
  function: {
718
719
  (): (...parameters: any[]) => any;
719
720
  <const P extends any[]>(parameters: P): (...parameters: P) => void;
721
+ <const P extends any[], R>(): (...parameters: P) => R;
720
722
  <const P extends any[], R>(parameters: P, result: R): (...parameters: P) => R;
721
723
  };
722
724
  instanceOf: <T extends Constructor>(constructor: T) => InstanceType<T>;
723
725
  literal: <const T extends LiteralTypes>(literal: T) => T;
724
- number: () => number;
726
+ number: <T extends number = number>() => T;
725
727
  object: {
726
728
  (): Record<string, any>;
727
729
  <const Keys extends string[]>(keys: Keys): ResolveOptionalEntries<KeyedObject<Keys>>;
730
+ <Shape extends {}>(): ResolveOptionalEntries<Shape>;
728
731
  <Shape extends {}>(shape: Shape): ResolveOptionalEntries<Shape>;
729
732
  };
730
733
  or: <T extends any[]>(types: T) => T[number];
@@ -743,18 +746,16 @@ export declare const types: {
743
746
  selection: <const T extends LiteralTypes>(literals: T[]) => T;
744
747
  signal: {
745
748
  (): ReactiveValue<any>;
749
+ <T>(): ReactiveValue<T>;
746
750
  <T>(type: T): ReactiveValue<T>;
747
751
  };
748
752
  strictObject: {
749
753
  <const Keys extends string[]>(keys: Keys): ResolveOptionalEntries<KeyedObject<Keys>>;
750
754
  <Shape extends {}>(shape: Shape): ResolveOptionalEntries<Shape>;
751
755
  };
752
- string: () => string;
756
+ string: <T extends string = string>() => T;
753
757
  tuple: <const T extends any[]>(types: T) => T;
754
758
  };
755
- export type PluginInstance<T extends PluginConstructor> = Omit<InstanceType<T>, "setup">;
756
- export declare function plugin<T extends PluginConstructor>(pluginType: T): PluginInstance<T>;
757
- export declare function config<T = any>(name: string, type?: T): T;
758
759
  export declare function providePlugins(pluginConstructors: PluginConstructor[] | Resource<PluginConstructor>, config?: Record<string, any>): void;
759
760
  export declare const blockDom: {
760
761
  config: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odoo/owl",
3
- "version": "3.0.0-alpha.32",
3
+ "version": "3.0.0-alpha.34",
4
4
  "description": "Odoo Web Library (OWL)",
5
5
  "main": "dist/owl.cjs.js",
6
6
  "module": "dist/owl.es.js",
@@ -43,9 +43,9 @@
43
43
  },
44
44
  "homepage": "https://github.com/odoo/owl#readme",
45
45
  "devDependencies": {
46
- "@odoo/owl-compiler": "3.0.0-alpha.32",
47
- "@odoo/owl-core": "3.0.0-alpha.32",
48
- "@odoo/owl-runtime": "3.0.0-alpha.32",
46
+ "@odoo/owl-compiler": "3.0.0-alpha.34",
47
+ "@odoo/owl-core": "3.0.0-alpha.34",
48
+ "@odoo/owl-runtime": "3.0.0-alpha.34",
49
49
  "jsdom": "^25.0.1"
50
50
  }
51
51
  }