taipy-gui.d.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. /*
  2. * Copyright 2021-2024 Avaiga Private Limited
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  5. * the License. You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  10. * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  11. * specific language governing permissions and limitations under the License.
  12. */
  13. import * as React from "react";
  14. /**
  15. * Extracts the backend name of a property.
  16. *
  17. * @param updateVars - The value held by the property *updateVars*.
  18. * @param name - The name of a bound property.
  19. * @returns The backend-generated variable name.
  20. */
  21. export declare const getUpdateVar: (updateVars: string, name: string) => string | undefined;
  22. export interface TaipyActiveProps extends TaipyDynamicProps, TaipyHoverProps {
  23. defaultActive?: boolean;
  24. active?: boolean;
  25. }
  26. export interface TaipyHoverProps {
  27. hoverText?: string;
  28. defaultHoverText?: string;
  29. }
  30. export interface TaipyDynamicProps extends TaipyBaseProps {
  31. updateVarName?: string;
  32. propagate?: boolean;
  33. updateVars?: string;
  34. }
  35. export interface TaipyBaseProps {
  36. id?: string;
  37. libClassName?: string;
  38. className?: string;
  39. dynamicClassName?: string;
  40. }
  41. export interface DialogProps extends TaipyActiveProps {
  42. title: string;
  43. onAction?: string;
  44. closeLabel?: string;
  45. labels?: string;
  46. page?: string;
  47. partial?: boolean;
  48. open?: boolean;
  49. defaultOpen?: string | boolean;
  50. children?: React.ReactNode;
  51. height?: string | number;
  52. width?: string | number;
  53. localAction?: (idx: number) => void;
  54. }
  55. export declare const Dialog: (props: DialogProps) => JSX.Element;
  56. export interface ChartProp extends TaipyActiveProps, TaipyChangeProps {
  57. title?: string;
  58. width?: string | number;
  59. height?: string | number;
  60. defaultConfig: string;
  61. config?: string;
  62. data?: Record<string, TraceValueType>;
  63. defaultLayout?: string;
  64. layout?: string;
  65. plotConfig?: string;
  66. onRangeChange?: string;
  67. testId?: string;
  68. render?: boolean;
  69. defaultRender?: boolean;
  70. template?: string;
  71. template_Dark_?: string;
  72. template_Light_?: string;
  73. }
  74. export type TraceValueType = Record<string, (string | number)[]>;
  75. export declare const Chart: (props: ChartProp) => JSX.Element;
  76. export interface TaipyMultiSelectProps {
  77. selected?: number[];
  78. }
  79. export interface TaipyChangeProps {
  80. onChange?: string;
  81. }
  82. export type TableValueType = Record<string, Record<string, any>>;
  83. export interface TaipyTableProps extends TaipyActiveProps, TaipyMultiSelectProps {
  84. data?: TableValueType;
  85. columns?: string;
  86. defaultColumns: string;
  87. height?: string;
  88. width?: string;
  89. pageSize?: number;
  90. onEdit?: string;
  91. onDelete?: string;
  92. onAdd?: string;
  93. onAction?: string;
  94. editable?: boolean;
  95. defaultEditable?: boolean;
  96. lineStyle?: string;
  97. tooltip?: string;
  98. cellTooltip?: string;
  99. nanValue?: string;
  100. filter?: boolean;
  101. size?: "small" | "medium";
  102. userData?: unknown;
  103. }
  104. export interface TaipyPaginatedTableProps extends TaipyTableProps {
  105. pageSizeOptions?: string;
  106. allowAllRows?: boolean;
  107. showAll?: boolean;
  108. }
  109. export interface TableProps extends TaipyPaginatedTableProps {
  110. autoLoading?: boolean;
  111. }
  112. export declare const Table: (props: TableProps) => JSX.Element;
  113. export interface FilterDesc {
  114. col: string;
  115. action: string;
  116. value: string | number | boolean | Date;
  117. type: string;
  118. }
  119. export interface TableFilterProps {
  120. columns: Record<string, ColumnDesc>;
  121. colsOrder?: Array<string>;
  122. onValidate: (data: Array<FilterDesc>) => void;
  123. appliedFilters?: Array<FilterDesc>;
  124. className?: string;
  125. filteredCount: number;
  126. }
  127. export declare const TableFilter: (props: TableFilterProps) => JSX.Element;
  128. export interface SortDesc {
  129. col: string;
  130. order: boolean;
  131. }
  132. export interface TableSortProps {
  133. columns: Record<string, ColumnDesc>;
  134. colsOrder?: Array<string>;
  135. onValidate: (data: Array<SortDesc>) => void;
  136. appliedSorts?: Array<SortDesc>;
  137. className?: string;
  138. }
  139. export declare const TableSort: (props: TableSortProps) => JSX.Element;
  140. export interface FileSelectorProps extends TaipyActiveProps {
  141. onAction?: string;
  142. defaultLabel?: string;
  143. label?: string;
  144. multiple?: boolean;
  145. extensions?: string;
  146. dropMessage?: string;
  147. notify?: boolean;
  148. width?: string | number;
  149. icon?: React.ReactNode;
  150. withBorder?: boolean;
  151. onUploadAction?: string;
  152. uploadData?: string;
  153. }
  154. export declare const FileSelector: (props: FileSelectorProps) => JSX.Element;
  155. export declare const Router: () => JSX.Element;
  156. /**
  157. * An Icon representation.
  158. */
  159. export interface Icon {
  160. /** The URL to the image. */
  161. path: string;
  162. /** The text. */
  163. text: string;
  164. /** light theme path */
  165. lightPath?: string;
  166. /** dark theme path */
  167. darkPath?: string;
  168. }
  169. /**
  170. * A string or an icon.
  171. */
  172. export declare type stringIcon = string | Icon;
  173. /**
  174. * An item in a List of Values (LoV).
  175. */
  176. export interface LovItem {
  177. /** The unique identifier of this item. */
  178. id: string;
  179. /** The items label (string and/or icon). */
  180. item: stringIcon;
  181. /** The array of child items. */
  182. children?: LovItem[];
  183. }
  184. /**
  185. * A LoV (list of value) element.
  186. *
  187. * Each `LoVElt` holds:
  188. *
  189. * - Its identifier as a string;
  190. * - Its label (or icon) as a `stringIcon`;
  191. * - Potential child elements as an array of `LoVElt`s.
  192. */
  193. export declare type LoVElt = [
  194. /** The identifier. */
  195. string,
  196. /** The label or icon. */
  197. stringIcon,
  198. /** The list of children. */
  199. LoVElt[]?
  200. ];
  201. /**
  202. * A series of LoV elements.
  203. */
  204. export declare type LoV = LoVElt[];
  205. /**
  206. * A React hook that returns a LoV list from the LoV default value and the LoV bound value.
  207. * @param lov - The bound lov value.
  208. * @param defaultLov - The JSON-stringified default LoV value.
  209. * @param tree - This flag indicates if the LoV list is a tree or a flat list (default is false).
  210. * @returns A list of LoV items.
  211. */
  212. export declare const useLovListMemo: (lov: LoV | undefined, defaultLov: string, tree?: boolean) => LovItem[];
  213. /**
  214. * The state of the underlying Taipy application.
  215. */
  216. export interface State {}
  217. /**
  218. * Application actions as used by the application reducer.
  219. */
  220. export interface Action {}
  221. /**
  222. * Create a *send update* `Action` that will be used to update `Context`.
  223. *
  224. * This action will update the variable *name* (if *propagate* is true) and trigger the
  225. * invocation of the `on_change` Python function on the backend.
  226. * @param name - The name of the variable holding the requested data
  227. * as received as a property.
  228. * @param value - The new value for the variable named *name*.
  229. * @param context - The execution context (property `context`).
  230. * @param onChange - The name of the `on_change` Python function to
  231. * invoke on the backend (default is "on_change").
  232. * @param propagate - A flag indicating that the variable should be
  233. * automatically updated on the backend.
  234. * @param relName - The name of the related variable (for
  235. * example the lov when a lov value is updated).
  236. * @returns The action fed to the reducer.
  237. */
  238. export declare const createSendUpdateAction: (
  239. name: string | undefined,
  240. value: unknown,
  241. context: string | undefined,
  242. onChange?: string,
  243. propagate?: boolean,
  244. relName?: string
  245. ) => Action;
  246. /**
  247. * Create an *action* `Action` that will be used to update `Context`.
  248. *
  249. * This action will trigger the invocation of the `on_action` Python function on the backend,
  250. * providing all the parameters as a payload.
  251. * @param name - The name of the action function on the backend.
  252. * @param context - The execution context (property `context`).
  253. * @param value - The value associated with the action. This can be an object or
  254. * any type of value.
  255. * @param args - Additional information associated to the action.
  256. * @returns The action fed to the reducer.
  257. */
  258. export declare const createSendActionNameAction: (
  259. name: string | undefined,
  260. context: string | undefined,
  261. value: unknown,
  262. ...args: unknown[]
  263. ) => Action;
  264. /**
  265. * Create a *request data update* `Action` that will be used to update the `Context`.
  266. *
  267. * This action will provoke the invocation of the `get_data()` method of the backend
  268. * library. That invocation generates an update of the elements holding the data named
  269. * *name* on the frontend.
  270. * @param name - The name of the variable holding the requested data as received as
  271. * a property.
  272. * @param id - The identifier of the visual element.
  273. * @param context - The execution context (property `context`).
  274. * @param columns - The list of the columns needed by the element that emitted this
  275. * action.
  276. * @param pageKey - The unique identifier of the data that will be received from
  277. * this action.
  278. * @param payload - The payload (specific to the type of component
  279. * ie table, chart...).
  280. * @param allData - The flag indicating if all the data is requested.
  281. * @param library - The name of the {@link extension} library.
  282. * @returns The action fed to the reducer.
  283. */
  284. export declare const createRequestDataUpdateAction: (
  285. name: string | undefined,
  286. id: string | undefined,
  287. context: string | undefined,
  288. columns: string[],
  289. pageKey: string,
  290. payload: Record<string, unknown>,
  291. allData?: boolean,
  292. library?: string
  293. ) => Action;
  294. /**
  295. * Create a *request update* `Action` that will be used to update the `Context`.
  296. *
  297. * This action will generate an update of the elements holding the variables named
  298. * *names* on the front-end.
  299. * @param id - The identifier of the visual element.
  300. * @param context - The execution context (property `context`).
  301. * @param names - The names of the requested variables as received in updateVarName and/or updateVars properties.
  302. * @param forceRefresh - Should Taipy re-evaluate the variables or use the current values.
  303. * @returns The action fed to the reducer.
  304. */
  305. export declare const createRequestUpdateAction: (
  306. id: string | undefined,
  307. context: string | undefined,
  308. names: string[],
  309. forceRefresh?: boolean,
  310. stateContext?: Record<string, unknown>
  311. ) => Action;
  312. /**
  313. * Broadcast stack definition.
  314. */
  315. export interface BroadcastDesc {
  316. /** Name of the broadcast. */
  317. name: string;
  318. /** Broadcast stack */
  319. stack: Array<unknown>;
  320. }
  321. /**
  322. * Create an *un broadcast* `Action` that will be used to update local state.
  323. *
  324. * This action will remove a value from a broadcasted stacked variable identified by name.
  325. * @param name - The name of the variable identifying the broadcast.
  326. * @param values - The values to remove.
  327. * @returns The action fed to the reducer.
  328. */
  329. export declare const createUnBroadcastAction: (name: string, ...values: Array<unknown>) => Action;
  330. /**
  331. * A column description as received by the backend.
  332. */
  333. export interface ColumnDesc {
  334. /** The unique column identifier. */
  335. dfid: string;
  336. /** The column type. */
  337. type: string;
  338. /** The value format. */
  339. format?: string;
  340. /** The column title. */
  341. title?: string;
  342. /** The order of the column. */
  343. index: number;
  344. /** The column width. */
  345. width?: number | string;
  346. /** If true, the column cannot be edited. */
  347. notEditable?: boolean;
  348. /** The name of the column that holds the CSS classname to
  349. * apply to the cells. */
  350. className?: string;
  351. /** The name of the column that holds the tooltip to
  352. * show on the cells. */
  353. tooltip?: string;
  354. /** The name of the column that holds the formatted value to
  355. * show on the cells. */
  356. formatFn?: string;
  357. /** The value that would replace a NaN value. */
  358. nanValue?: string;
  359. /** The TimeZone identifier used if the type is `date`. */
  360. tz?: string;
  361. /** The flag that allows filtering. */
  362. filter?: boolean;
  363. /** The name of the aggregation function. */
  364. apply?: string;
  365. /** The flag that allows the user to aggregate the column. */
  366. groupBy?: boolean;
  367. widthHint?: number;
  368. /** The list of values that can be used on edit. */
  369. lov?: string[];
  370. /** If true the user can enter any value besides the lov values. */
  371. freeLov?: boolean;
  372. }
  373. /**
  374. * A cell value type.
  375. */
  376. export declare type RowValue = string | number | boolean | null;
  377. /**
  378. * The definition of a table row.
  379. *
  380. * A row definition associates a name (a string) to a type (a {@link RowValue}).
  381. */
  382. export declare type RowType = Record<string, RowValue>;
  383. /**
  384. * The Taipy Store.
  385. */
  386. export interface Store {
  387. /** The State of the Taipy application. */
  388. state: State;
  389. /** The React *dispatch* function. */
  390. dispatch: React.Dispatch<Action>;
  391. }
  392. /**
  393. * The Taipy-specific React context.
  394. *
  395. * The type of this variable is `React.Context<Store>`.
  396. */
  397. export declare const Context: React.Context<Store>;
  398. /**
  399. * A React hook to manage a dynamic scalar property.
  400. *
  401. * A dynamic scalar property is defined by a default property and a bound property.
  402. * @typeParam T - The dynamic property type.
  403. * @param value - The bound value.
  404. * @param defaultValue - The default value.
  405. * @param defaultStatic - The default static value.
  406. * @returns The latest updated value.
  407. */
  408. export declare const useDynamicProperty: <T>(value: T, defaultValue: T, defaultStatic: T) => T;
  409. /**
  410. * A React hook to manage a dynamic json property.
  411. *
  412. * A dynamic scalar property is defined by a default property and a bound property.
  413. * @typeParam T - The dynamic property type.
  414. * @param value - The bound value.
  415. * @param defaultValue - The default value.
  416. * @param defaultStatic - The default static value.
  417. * @returns The latest updated value.
  418. */
  419. export const useDynamicJsonProperty: <T>(value: string | T, defaultValue: string, defaultStatic: T) => T;
  420. /**
  421. * A React hook that requests an update for every dynamic property of the element.
  422. * @param dispatch - The React dispatcher associated to `TaipyContext`.
  423. * @param id - The identifier of the element.
  424. * @param context - The execution context (property `context`).
  425. * @param updateVars - The content of the property `updateVars`.
  426. * @param varName - The default property backend provided variable (through property `updateVarName`).
  427. * @param forceRefresh - Should Taipy re-evaluate the variables or use the current values.
  428. */
  429. export declare const useDispatchRequestUpdateOnFirstRender: (
  430. dispatch: React.Dispatch<Action>,
  431. id?: string,
  432. context?: string,
  433. updateVars?: string,
  434. varName?: string,
  435. forceRefresh?: boolean
  436. ) => void;
  437. /**
  438. * A React hook that returns the *dispatch* function.
  439. *
  440. * The *dispatch* function allows to send Actions to the Store and initiate backend\
  441. * communications.
  442. * @returns The *dispatch* function.
  443. */
  444. export declare const useDispatch: () => React.Dispatch<Action>;
  445. /**
  446. * A React hook that returns the page module.
  447. *
  448. * The *module* Needs to be added to all Actions to allow for the correct execution of backend functions.
  449. * @returns The page module.
  450. */
  451. export declare const useModule: () => string | undefined;