|
| 1 | +import type { Set } from 'immutable'; |
| 2 | +import React from 'react'; |
| 3 | + |
| 4 | +import { BaseEntityRecords, Context } from '@wordpress/core-data'; |
| 5 | + |
| 6 | +type ComponentStateAware<V> = { |
| 7 | + value: Set<V>; |
| 8 | + setValue(value: ComponentStateAware<V>['value']): void; |
| 9 | +}; |
| 10 | + |
| 11 | +export default EntitiesSearch; |
| 12 | + |
| 13 | +declare namespace EntitiesSearch { |
| 14 | + type PostType<C extends Context = 'view'> = BaseEntityRecords.Type<C>; |
| 15 | + |
| 16 | + type ViewablePostType = Readonly<{ |
| 17 | + [K in keyof PostType<'edit'>]: K extends 'viewable' |
| 18 | + ? true |
| 19 | + : PostType<'edit'>[K]; |
| 20 | + }>; |
| 21 | + |
| 22 | + type ControlOption<V extends any> = Readonly<{ |
| 23 | + value: V; |
| 24 | + label: string; |
| 25 | + }>; |
| 26 | + |
| 27 | + type ComponentStateAware<V> = { |
| 28 | + value: V; |
| 29 | + setValue(value: ComponentStateAware['value']): void; |
| 30 | + }; |
| 31 | + |
| 32 | + type EntitiesRecords<Entity> = Readonly<{ |
| 33 | + records(): Set<Entity>; |
| 34 | + isResolving(): boolean; |
| 35 | + errored(): boolean; |
| 36 | + succeed(): boolean; |
| 37 | + }>; |
| 38 | + |
| 39 | + /** |
| 40 | + * Components |
| 41 | + */ |
| 42 | + interface PostTypeSelect<V> { |
| 43 | + readonly value: V | null; |
| 44 | + readonly options: Set<ControlOption<V>>; |
| 45 | + readonly onChange: (value: PostTypeSelect<V>['value']) => void; |
| 46 | + } |
| 47 | + |
| 48 | + interface PostsSelect<V> { |
| 49 | + readonly value: Set<V> | null; |
| 50 | + readonly options: Set<ControlOption<V>>; |
| 51 | + readonly onChange: (values: PostsSelect<V>['value']) => void; |
| 52 | + } |
| 53 | + |
| 54 | + interface PostsController<P, T> { |
| 55 | + readonly postsComponent: React.ComponentType< |
| 56 | + ComponentStateAware<Set<P>> |
| 57 | + >; |
| 58 | + readonly typesComponent: React.ComponentType<ComponentStateAware<T>>; |
| 59 | + } |
| 60 | +} |
0 commit comments