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

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,149 @@ 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 type Constructor<T = any> = {
146
+ new (...args: any[]): T;
147
+ };
148
+ declare const hasDefault: unique symbol;
149
+ export type WithDefault<T> = T & {
150
+ [hasDefault]: T;
151
+ };
152
+ declare const isOptional: unique symbol;
153
+ export type Optional<T> = T & {
154
+ [isOptional]: T;
155
+ };
156
+ declare const typeBrand: unique symbol;
157
+ export type Type<T> = T & {
158
+ [typeBrand]: T;
159
+ /**
160
+ * Attaches a default value to the type. A defaulted value is implicitly
161
+ * optional: `undefined` passes validation (the default is meant to fill
162
+ * it). The default can be given as a factory (`() => value`), which is
163
+ * called once per consumer, so mutable defaults ([], {}) are not shared. A
164
+ * default for a function type must use the factory form.
165
+ */
166
+ default(value: T extends Function ? () => T : T | (() => T)): WithDefault<T>;
167
+ /**
168
+ * Marks the type as optional: `undefined` passes validation, and an object
169
+ * key with an optional type may be omitted. A type with a default is
170
+ * already implicitly optional, so `.optional()` and `.default()` do not
171
+ * need to be combined (and cannot be chained).
172
+ */
173
+ optional(): Optional<T>;
174
+ };
175
+ export type IsAny<T> = 0 extends 1 & T ? true : false;
176
+ export type HasDefault<T> = IsAny<T> extends true ? false : T extends {
177
+ [hasDefault]: any;
178
+ } ? true : false;
179
+ export type IsOptional<T> = IsAny<T> extends true ? false : T extends {
180
+ [isOptional]: any;
181
+ } ? true : false;
182
+ export type StripDefault<T> = T extends {
183
+ [hasDefault]: infer U;
184
+ } ? U : T;
185
+ export type StripOptional<T> = T extends {
186
+ [isOptional]: infer U;
187
+ } ? U | undefined : T;
188
+ export type StripType<T> = T extends {
189
+ [typeBrand]: infer U;
190
+ } ? U : T;
191
+ export type StripBrands<T> = StripType<StripDefault<StripOptional<T>>>;
192
+ export type StripBrandsAll<T extends any[]> = {
193
+ [K in keyof T]: StripBrands<T[K]>;
194
+ };
195
+ export type GetDefaultedEntries<T> = {
196
+ [K in keyof T as HasDefault<T[K]> extends true ? K : never]: StripBrands<T[K]>;
197
+ };
198
+ export type GetOptionalEntries<T> = {
199
+ [K in keyof T as IsOptional<T[K]> extends true ? K : HasDefault<T[K]> extends true ? K : never]?: StripBrands<T[K]>;
200
+ };
201
+ export type GetRequiredEntries<T> = {
202
+ [K in keyof T as IsOptional<T[K]> extends true ? never : HasDefault<T[K]> extends true ? never : K]: StripBrands<T[K]>;
203
+ };
204
+ export type PrettifyShape<T> = T extends Function ? T : {
205
+ [K in keyof T]: T[K];
206
+ };
207
+ export type ResolveOptionalEntries<T> = PrettifyShape<GetRequiredEntries<T> & GetOptionalEntries<T>>;
208
+ export type KeyedObject<K extends string[]> = {
209
+ [P in K[number]]: any;
210
+ };
211
+ export type ResolveShapedObject<T extends {}> = PrettifyShape<ResolveOptionalEntries<T>>;
212
+ export type ResolveObjectType<T extends {}> = ResolveShapedObject<T extends string[] ? KeyedObject<T> : T>;
213
+ export type UnionToIntersection<U> = (U extends any ? (_: U) => any : never) extends (_: infer I) => void ? I : never;
214
+ /**
215
+ * Returns the default value factory attached to a type by `.default()`, if
216
+ * any. This is how consumers (props, config, ...) resolve defaults at
217
+ * runtime: validation only runs in dev mode, so defaults are metadata on the
218
+ * schema, not a validation side-effect.
219
+ */
220
+ export declare function getDefault(type: any): (() => any) | undefined;
221
+ /**
222
+ * Returns `value` with defaults from the schema filled in, at any depth: a
223
+ * default fires when the value at its schema position is `undefined`. The
224
+ * input is never mutated; objects are copied along the changed paths only, so
225
+ * if nothing is filled in, `value` is returned as is.
226
+ *
227
+ * Note that this only recurses through object shapes, tuples and arrays
228
+ * (unions are ambiguous, records have no fixed keys).
229
+ */
230
+ export declare function applyDefaults<T>(value: unknown, type: T): StripBrands<T>;
231
+ declare function anyType(): Type<any>;
232
+ declare function booleanType(): Type<boolean>;
233
+ declare function numberType<T extends number = number>(): Type<T>;
234
+ declare function stringType<T extends string = string>(): Type<T>;
235
+ declare function arrayType(): Type<any[]>;
236
+ declare function arrayType<T>(): Type<T[]>;
237
+ declare function arrayType<T>(elementType: T): Type<StripBrands<T>[]>;
238
+ declare function constructorType<T extends Constructor>(constructor: T): Type<T>;
239
+ declare function customValidator<T>(type: T, validator: (value: StripBrands<T>) => boolean, errorMessage?: string): Type<StripBrands<T>>;
240
+ declare function functionType(): Type<(...parameters: any[]) => any>;
241
+ declare function functionType<const P extends any[]>(parameters: P): Type<(...parameters: StripBrandsAll<P>) => void>;
242
+ declare function functionType<const P extends any[], R>(): Type<(...parameters: P) => R>;
243
+ declare function functionType<const P extends any[], R>(parameters: P, result: R): Type<(...parameters: StripBrandsAll<P>) => StripBrands<R>>;
244
+ declare function instanceType<T extends Constructor>(constructor: T): Type<InstanceType<T>>;
245
+ declare function intersection<T extends any[]>(types: T): Type<UnionToIntersection<StripBrands<T[number]>>>;
246
+ export type LiteralTypes = number | string | boolean | null | undefined;
247
+ declare function literalType<const T extends LiteralTypes>(literal: T): Type<T>;
248
+ declare function literalSelection<const T extends LiteralTypes>(literals: T[]): Type<T>;
249
+ declare function objectType(): Type<Record<string, any>>;
250
+ declare function objectType<const Keys extends string[]>(keys: Keys): Type<ResolveOptionalEntries<KeyedObject<Keys>>>;
251
+ declare function objectType<Shape extends {}>(): Type<ResolveOptionalEntries<Shape>>;
252
+ declare function objectType<Shape extends {}>(shape: Shape): Type<ResolveOptionalEntries<Shape>>;
253
+ declare function strictObjectType<const Keys extends string[]>(keys: Keys): Type<ResolveOptionalEntries<KeyedObject<Keys>>>;
254
+ declare function strictObjectType<Shape extends {}>(shape: Shape): Type<ResolveOptionalEntries<Shape>>;
255
+ declare function promiseType(): Type<Promise<void>>;
256
+ declare function promiseType<T>(type: T): Type<Promise<StripBrands<T>>>;
257
+ declare function recordType(): Type<Record<PropertyKey, any>>;
258
+ declare function recordType<V>(valueType: V): Type<Record<PropertyKey, StripBrands<V>>>;
259
+ declare function tuple<const T extends any[]>(types: T): Type<StripBrandsAll<T>>;
260
+ declare function union<T extends any[]>(types: T): Type<StripBrands<T[number]>>;
261
+ declare function reactiveValueType(): Type<ReactiveValue<any>>;
262
+ declare function reactiveValueType<T>(): Type<ReactiveValue<T>>;
263
+ declare function reactiveValueType<T>(type: T): Type<ReactiveValue<StripBrands<T>>>;
264
+ declare function ref(): Type<HTMLElement | null>;
265
+ declare function ref<T extends Constructor<HTMLElement>>(type: T): Type<InstanceType<T> | null>;
266
+ declare const types: {
267
+ and: typeof intersection;
268
+ any: typeof anyType;
269
+ array: typeof arrayType;
270
+ boolean: typeof booleanType;
271
+ constructor: typeof constructorType;
272
+ customValidator: typeof customValidator;
273
+ function: typeof functionType;
274
+ instanceOf: typeof instanceType;
275
+ literal: typeof literalType;
276
+ number: typeof numberType;
277
+ object: typeof objectType;
278
+ or: typeof union;
279
+ promise: typeof promiseType;
280
+ record: typeof recordType;
281
+ ref: typeof ref;
282
+ selection: typeof literalSelection;
283
+ signal: typeof reactiveValueType;
284
+ strictObject: typeof strictObjectType;
285
+ string: typeof stringType;
286
+ tuple: typeof tuple;
287
+ };
145
288
  export interface ResourceOptions<T> {
146
289
  name?: string;
147
290
  validation?: T;
@@ -149,16 +292,17 @@ export interface ResourceOptions<T> {
149
292
  export interface ResourceAddOptions {
150
293
  sequence?: number;
151
294
  }
295
+ export type Item<T> = StripBrands<T>;
152
296
  export declare class Resource<T> {
153
297
  private _items;
154
298
  private _name?;
155
299
  private _validation?;
156
300
  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>;
301
+ items: ReactiveValue<Item<T>[]>;
302
+ add(item: Item<T>, options?: ResourceAddOptions): Resource<T>;
303
+ delete(item: Item<T>): Resource<T>;
304
+ has(item: Item<T>): boolean;
305
+ use(item: Item<T>, options?: ResourceAddOptions): Resource<T>;
162
306
  }
163
307
  export interface PluginConstructor {
164
308
  new (...args: any[]): Plugin$1;
@@ -307,6 +451,8 @@ export interface SignalOptions<T> {
307
451
  type?: T;
308
452
  }
309
453
  declare function triggerSignal(signal: Signal<any>): void;
454
+ declare function signalRef(): Signal<HTMLElement | null>;
455
+ declare function signalRef<T extends Constructor<HTMLElement>>(type: T): Signal<InstanceType<T> | null>;
310
456
  declare function signalArray<T>(initialValue: T[]): Signal<T[]>;
311
457
  declare function signalArray<T>(initialValue: NoInfer<T>[], options: SignalOptions<T>): Signal<T[]>;
312
458
  declare function signalObject<T extends Record<PropertyKey, any>>(initialValue: T): Signal<T>;
@@ -324,6 +470,7 @@ export declare function signal<T>(value: T): Signal<T>;
324
470
  export declare function signal<T>(value: NoInfer<T>, options: SignalOptions<T>): Signal<T>;
325
471
  export declare namespace signal {
326
472
  var trigger: typeof triggerSignal;
473
+ var ref: typeof signalRef;
327
474
  var Array: typeof signalArray;
328
475
  var Map: typeof signalMap;
329
476
  var Object: typeof signalObject;
@@ -359,27 +506,6 @@ export interface ValidationIssue {
359
506
  }
360
507
  export declare function assertType(value: any, validation: any, errorMessage?: string): void;
361
508
  export declare function validateType(value: any, validation: any): ValidationIssue[];
362
- export type Constructor<T = any> = {
363
- new (...args: any[]): T;
364
- };
365
- export type GetOptionalEntries<T> = {
366
- [K in keyof T as K extends `${infer P}?` ? P : never]?: T[K];
367
- };
368
- export type GetRequiredEntries<T> = {
369
- [K in keyof T as K extends `${string}?` ? never : K]: T[K];
370
- };
371
- export type PrettifyShape<T> = T extends Function ? T : {
372
- [K in keyof T]: T[K];
373
- };
374
- export type ResolveOptionalEntries<T> = PrettifyShape<GetRequiredEntries<T> & GetOptionalEntries<T>>;
375
- export type KeyedObject<K extends string[]> = {
376
- [P in K[number]]: any;
377
- };
378
- export type ResolveShapedObject<T extends {}> = PrettifyShape<ResolveOptionalEntries<T>>;
379
- export type ResolveObjectType<T extends {}> = ResolveShapedObject<T extends string[] ? KeyedObject<T> : T>;
380
- export type UnionToIntersection<U> = (U extends any ? (_: U) => any : never) extends (_: infer I) => void ? I : never;
381
- declare function constructorType<T extends Constructor>(constructor: T): T;
382
- export type LiteralTypes = number | string | boolean | null | undefined;
383
509
  export interface RegistryOptions<T> {
384
510
  name?: string;
385
511
  validation?: T;
@@ -387,6 +513,7 @@ export interface RegistryOptions<T> {
387
513
  export interface RegistryAddOptions extends ResourceAddOptions {
388
514
  force?: boolean;
389
515
  }
516
+ type Item$1<T> = StripBrands<T>;
390
517
  export declare class Registry<T> {
391
518
  private _map;
392
519
  private _name;
@@ -394,23 +521,20 @@ export declare class Registry<T> {
394
521
  constructor(options?: RegistryOptions<T>);
395
522
  entries: ReactiveValue<[
396
523
  string,
397
- T
398
- ][], [
399
- string,
400
- T
524
+ Item$1<T>
401
525
  ][]>;
402
- items: ReactiveValue<T[], T[]>;
526
+ items: ReactiveValue<Item$1<T>[]>;
403
527
  addById<U extends {
404
528
  id: string;
405
- } & T>(item: U, options?: RegistryAddOptions): Registry<T>;
406
- add(key: string, value: T, options?: RegistryAddOptions): Registry<T>;
407
- get(key: string, defaultValue?: T): T;
529
+ } & Item$1<T>>(item: U, options?: RegistryAddOptions): Registry<T>;
530
+ add(key: string, value: Item$1<T>, options?: RegistryAddOptions): Registry<T>;
531
+ get(key: string, defaultValue?: Item$1<T>): Item$1<T>;
408
532
  delete(key: string): void;
409
533
  has(key: string): boolean;
410
- use(key: string, value: T, options?: RegistryAddOptions): Registry<T>;
534
+ use(key: string, value: Item$1<T>, options?: RegistryAddOptions): Registry<T>;
411
535
  useById<U extends {
412
536
  id: string;
413
- } & T>(item: U, options?: RegistryAddOptions): Registry<T>;
537
+ } & Item$1<T>>(item: U, options?: RegistryAddOptions): Registry<T>;
414
538
  }
415
539
  /**
416
540
  * Creates a reactive effect bound to the surrounding component or plugin.
@@ -430,6 +554,10 @@ export declare function useEffect(fn: Parameters<typeof effect>[0]): void;
430
554
  * listener is attached through a `useEffect` and re-attaches when the signal's
431
555
  * value changes; nothing is attached while the signal is null).
432
556
  *
557
+ * The handler is not bound: it is passed as-is to `addEventListener`, so inside
558
+ * it `this` is the event target, not the calling component. Wrap a method in an
559
+ * arrow function (or bind it) if it relies on `this`.
560
+ *
433
561
  * Example — close a menu when the user clicks anywhere on `window`:
434
562
  * useListener(window, "click", () => this.close());
435
563
  */
@@ -439,8 +567,9 @@ export declare function onWillDestroy(fn: (scope: Scope) => void | any): void;
439
567
  export type PluginInstance<T extends PluginConstructor> = Omit<InstanceType<T>, "setup">;
440
568
  export declare function plugin<T extends PluginConstructor>(pluginType: T): PluginInstance<T>;
441
569
  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;
570
+ export declare function config<T>(key: string, type: WithDefault<T>): T;
571
+ export declare function config<T>(key: string, type: Optional<T>): T | undefined;
572
+ export declare function config<T>(key: string, type: T): StripBrands<T>;
444
573
  export declare class EventBus extends EventTarget {
445
574
  trigger(name: string, payload?: any): void;
446
575
  }
@@ -547,14 +676,14 @@ export declare class Component {
547
676
  setup(): void;
548
677
  }
549
678
  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;
679
+ declare function staticProp<T>(key: string, type: WithDefault<T>): T;
680
+ declare function staticProp<T>(key: string, type: Optional<T>): T | undefined;
681
+ declare function staticProp<T>(key: string, type: T): StripBrands<T>;
552
682
  declare const isProps: unique symbol;
553
683
  export type WithDefaults<T, D> = T & Required<D>;
554
684
  export type Props<T extends {}> = T & {
555
685
  [isProps]: true;
556
686
  };
557
- export type GetPropsDefaults<T extends object> = PrettifyShape<GetOptionalEntries<T>>;
558
687
  export type GetPropsWithOptionals<T> = T extends Props<infer P> ? (P extends WithDefaults<infer R, any> ? R : P) : never;
559
688
  export type GetProps<T> = {
560
689
  [K in keyof T]: T[K] extends {
@@ -566,9 +695,7 @@ export type GetProps<T> = {
566
695
  export interface PropsFunction {
567
696
  (): Props<Record<string, any>>;
568
697
  <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>>;
698
+ <Shape extends {}>(shape: Shape): Props<WithDefaults<ResolveObjectType<Shape>, GetDefaultedEntries<Shape>>>;
572
699
  static: typeof staticProp;
573
700
  }
574
701
  export declare const props: PropsFunction;
@@ -664,29 +791,39 @@ export declare class ErrorBoundary extends Component {
664
791
  static template: string;
665
792
  props: Props<WithDefaults<{
666
793
  error?: ReactiveValue<any, any> | undefined;
667
- }, {
668
- error: Signal<any>;
669
- }>>;
794
+ }, GetDefaultedEntries<{
795
+ error: WithDefault<ReactiveValue<any, any>>;
796
+ }>>>;
670
797
  setup(): void;
671
798
  }
672
799
  export declare class Portal extends Component {
673
800
  static template: string;
674
- props: Props<{
801
+ props: Props<WithDefaults<{
675
802
  slots: {
676
803
  default: any;
677
804
  };
678
805
  target: any;
679
- }>;
806
+ }, GetDefaultedEntries<{
807
+ slots: Type<{
808
+ default: any;
809
+ }>;
810
+ target: any;
811
+ }>>>;
680
812
  setup(): void;
681
813
  }
682
814
  export declare class Suspense extends Component {
683
815
  static template: string;
684
- props: Props<{
816
+ props: Props<WithDefaults<{
685
817
  slots: {
686
818
  default: any;
687
- fallback?: any;
819
+ fallback: any;
688
820
  };
689
- }>;
821
+ }, GetDefaultedEntries<{
822
+ slots: Type<{
823
+ default: any;
824
+ fallback: any;
825
+ }>;
826
+ }>>>;
690
827
  private prepared;
691
828
  private mounted;
692
829
  private subRootMounted;
@@ -702,59 +839,8 @@ export declare function onPatched(fn: (scope: ComponentNode) => void | any): voi
702
839
  export declare function onWillUnmount(fn: (scope: ComponentNode) => void | any): void;
703
840
  export type OnErrorCallback = (error: any) => void | any;
704
841
  export declare function onError(callback: OnErrorCallback): void;
705
- declare function componentType(): typeof Component;
706
- export declare const types: {
707
- component: typeof componentType;
708
- and: <T extends any[]>(types: T) => UnionToIntersection<T[number]>;
709
- any: () => any;
710
- array: {
711
- (): any[];
712
- <T>(): T[];
713
- <T>(elementType: T): T[];
714
- };
715
- boolean: () => boolean;
716
- constructor: typeof constructorType;
717
- customValidator: <T>(type: T, validator: (value: T) => boolean, errorMessage?: string) => T;
718
- function: {
719
- (): (...parameters: any[]) => any;
720
- <const P extends any[]>(parameters: P): (...parameters: P) => void;
721
- <const P extends any[], R>(): (...parameters: P) => R;
722
- <const P extends any[], R>(parameters: P, result: R): (...parameters: P) => R;
723
- };
724
- instanceOf: <T extends Constructor>(constructor: T) => InstanceType<T>;
725
- literal: <const T extends LiteralTypes>(literal: T) => T;
726
- number: <T extends number = number>() => T;
727
- object: {
728
- (): Record<string, any>;
729
- <const Keys extends string[]>(keys: Keys): ResolveOptionalEntries<KeyedObject<Keys>>;
730
- <Shape extends {}>(): ResolveOptionalEntries<Shape>;
731
- <Shape extends {}>(shape: Shape): ResolveOptionalEntries<Shape>;
732
- };
733
- or: <T extends any[]>(types: T) => T[number];
734
- promise: {
735
- (): Promise<void>;
736
- <T>(type: T): Promise<T>;
737
- };
738
- record: {
739
- (): Record<PropertyKey, any>;
740
- <V>(valueType: V): Record<PropertyKey, V>;
741
- };
742
- ref: {
743
- (): HTMLElement | null;
744
- <T extends Constructor<HTMLElement>>(type: T): InstanceType<T> | null;
745
- };
746
- selection: <const T extends LiteralTypes>(literals: T[]) => T;
747
- signal: {
748
- (): ReactiveValue<any>;
749
- <T>(): ReactiveValue<T>;
750
- <T>(type: T): ReactiveValue<T>;
751
- };
752
- strictObject: {
753
- <const Keys extends string[]>(keys: Keys): ResolveOptionalEntries<KeyedObject<Keys>>;
754
- <Shape extends {}>(shape: Shape): ResolveOptionalEntries<Shape>;
755
- };
756
- string: <T extends string = string>() => T;
757
- tuple: <const T extends any[]>(types: T) => T;
842
+ declare const types$1: typeof types & {
843
+ component: () => Type<typeof Component>;
758
844
  };
759
845
  export declare function providePlugins(pluginConstructors: PluginConstructor[] | Resource<PluginConstructor>, config?: Record<string, any>): void;
760
846
  export declare const blockDom: {
@@ -778,6 +864,8 @@ export {
778
864
  Plugin$1 as Plugin,
779
865
  mount$1 as mount,
780
866
  status$1 as status,
867
+ types$1 as t,
868
+ types$1 as types,
781
869
  };
782
870
 
783
871
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odoo/owl",
3
- "version": "3.0.0-alpha.34",
3
+ "version": "3.0.0-alpha.35",
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.34",
47
- "@odoo/owl-core": "3.0.0-alpha.34",
48
- "@odoo/owl-runtime": "3.0.0-alpha.34",
46
+ "@odoo/owl-compiler": "3.0.0-alpha.35",
47
+ "@odoo/owl-core": "3.0.0-alpha.35",
48
+ "@odoo/owl-runtime": "3.0.0-alpha.35",
49
49
  "jsdom": "^25.0.1"
50
50
  }
51
51
  }