taipy-gui.d.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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 declare const Router: () => JSX.Element;
  114. /**
  115. * An Icon representation.
  116. */
  117. export interface Icon {
  118. /** The URL to the image. */
  119. path: string;
  120. /** The text. */
  121. text: string;
  122. /** light theme path */
  123. lightPath?: string;
  124. /** dark theme path */
  125. darkPath?: string;
  126. }
  127. /**
  128. * A string or an icon.
  129. */
  130. export declare type stringIcon = string | Icon;
  131. /**
  132. * An item in a List of Values (LoV).
  133. */
  134. export interface LovItem {
  135. /** The unique identifier of this item. */
  136. id: string;
  137. /** The items label (string and/or icon). */
  138. item: stringIcon;
  139. /** The array of child items. */
  140. children?: LovItem[];
  141. }
  142. /**
  143. * A LoV (list of value) element.
  144. *
  145. * Each `LoVElt` holds:
  146. *
  147. * - Its identifier as a string;
  148. * - Its label (or icon) as a `stringIcon`;
  149. * - Potential child elements as an array of `LoVElt`s.
  150. */
  151. export declare type LoVElt = [
  152. /** The identifier. */
  153. string,
  154. /** The label or icon. */
  155. stringIcon,
  156. /** The list of children. */
  157. LoVElt[]?
  158. ];
  159. /**
  160. * A series of LoV elements.
  161. */
  162. export declare type LoV = LoVElt[];
  163. /**
  164. * A React hook that returns a LoV list from the LoV default value and the LoV bound value.
  165. * @param lov - The bound lov value.
  166. * @param defaultLov - The JSON-stringified default LoV value.
  167. * @param tree - This flag indicates if the LoV list is a tree or a flat list (default is false).
  168. * @returns A list of LoV items.
  169. */
  170. export declare const useLovListMemo: (lov: LoV | undefined, defaultLov: string, tree?: boolean) => LovItem[];
  171. /**
  172. * The state of the underlying Taipy application.
  173. */
  174. export interface State {}
  175. /**
  176. * Application actions as used by the application reducer.
  177. */
  178. export interface Action {}
  179. /**
  180. * Create a *send update* `Action` that will be used to update `Context`.
  181. *
  182. * This action will update the variable *name* (if *propagate* is true) and trigger the
  183. * invocation of the `on_change` Python function on the backend.
  184. * @param name - The name of the variable holding the requested data
  185. * as received as a property.
  186. * @param value - The new value for the variable named *name*.
  187. * @param context - The execution context (property `context`).
  188. * @param onChange - The name of the `on_change` Python function to
  189. * invoke on the backend (default is "on_change").
  190. * @param propagate - A flag indicating that the variable should be
  191. * automatically updated on the backend.
  192. * @param relName - The name of the related variable (for
  193. * example the lov when a lov value is updated).
  194. * @returns The action fed to the reducer.
  195. */
  196. export declare const createSendUpdateAction: (
  197. name: string | undefined,
  198. value: unknown,
  199. context: string | undefined,
  200. onChange?: string,
  201. propagate?: boolean,
  202. relName?: string
  203. ) => Action;
  204. /**
  205. * Create an *action* `Action` that will be used to update `Context`.
  206. *
  207. * This action will trigger the invocation of the `on_action` Python function on the backend,
  208. * providing all the parameters as a payload.
  209. * @param name - The name of the action function on the backend.
  210. * @param context - The execution context (property `context`).
  211. * @param value - The value associated with the action. This can be an object or
  212. * any type of value.
  213. * @param args - Additional information associated to the action.
  214. * @returns The action fed to the reducer.
  215. */
  216. export declare const createSendActionNameAction: (
  217. name: string | undefined,
  218. context: string | undefined,
  219. value: unknown,
  220. ...args: unknown[]
  221. ) => Action;
  222. /**
  223. * Create a *request data update* `Action` that will be used to update the `Context`.
  224. *
  225. * This action will provoke the invocation of the `get_data()` method of the backend
  226. * library. That invocation generates an update of the elements holding the data named
  227. * *name* on the frontend.
  228. * @param name - The name of the variable holding the requested data as received as
  229. * a property.
  230. * @param id - The identifier of the visual element.
  231. * @param context - The execution context (property `context`).
  232. * @param columns - The list of the columns needed by the element that emitted this
  233. * action.
  234. * @param pageKey - The unique identifier of the data that will be received from
  235. * this action.
  236. * @param payload - The payload (specific to the type of component
  237. * ie table, chart...).
  238. * @param allData - The flag indicating if all the data is requested.
  239. * @param library - The name of the {@link extension} library.
  240. * @returns The action fed to the reducer.
  241. */
  242. export declare const createRequestDataUpdateAction: (
  243. name: string | undefined,
  244. id: string | undefined,
  245. context: string | undefined,
  246. columns: string[],
  247. pageKey: string,
  248. payload: Record<string, unknown>,
  249. allData?: boolean,
  250. library?: string
  251. ) => Action;
  252. /**
  253. * Create a *request update* `Action` that will be used to update the `Context`.
  254. *
  255. * This action will generate an update of the elements holding the variables named
  256. * *names* on the front-end.
  257. * @param id - The identifier of the visual element.
  258. * @param context - The execution context (property `context`).
  259. * @param names - The names of the requested variables as received in updateVarName and/or updateVars properties.
  260. * @param forceRefresh - Should Taipy re-evaluate the variables or use the current values.
  261. * @returns The action fed to the reducer.
  262. */
  263. export declare const createRequestUpdateAction: (
  264. id: string | undefined,
  265. context: string | undefined,
  266. names: string[],
  267. forceRefresh?: boolean
  268. ) => Action;
  269. /**
  270. * A column description as received by the backend.
  271. */
  272. export interface ColumnDesc {
  273. /** The unique column identifier. */
  274. dfid: string;
  275. /** The column type. */
  276. type: string;
  277. /** The value format. */
  278. format?: string;
  279. /** The column title. */
  280. title?: string;
  281. /** The order of the column. */
  282. index: number;
  283. /** The width. */
  284. width?: number | string;
  285. /** If set to true, the column should not be editable. */
  286. notEditable?: boolean;
  287. /** The column name that would hold the css classname to apply to the cell. */
  288. style?: string;
  289. /** The value that would replace a NaN value. */
  290. nanValue?: string;
  291. /** The TimeZone identifier used if the type is Date. */
  292. tz?: string;
  293. /** The flag that allows filtering. */
  294. filter?: boolean;
  295. /** The identifier for the aggregation function. */
  296. apply?: string;
  297. /** The flag that would allow the user to aggregate the column. */
  298. groupBy?: boolean;
  299. widthHint?: number;
  300. }
  301. /**
  302. * A cell value type.
  303. */
  304. export declare type RowValue = string | number | boolean | null;
  305. /**
  306. * The definition of a table row.
  307. *
  308. * A row definition associates a name (a string) to a type (a {@link RowValue}).
  309. */
  310. export declare type RowType = Record<string, RowValue>;
  311. /**
  312. * The Taipy Store.
  313. */
  314. export interface Store {
  315. /** The State of the Taipy application. */
  316. state: State;
  317. /** The React *dispatch* function. */
  318. dispatch: React.Dispatch<Action>;
  319. }
  320. /**
  321. * The Taipy-specific React context.
  322. *
  323. * The type of this variable is `React.Context<Store>`.
  324. */
  325. export declare const Context: React.Context<Store>;
  326. /**
  327. * A React hook to manage a dynamic scalar property.
  328. *
  329. * A dynamic scalar property is defined by a default property and a bound property.
  330. * @typeParam T - The dynamic property type.
  331. * @param value - The bound value.
  332. * @param defaultValue - The default value.
  333. * @param defaultStatic - The default static value.
  334. * @returns The latest updated value.
  335. */
  336. export declare const useDynamicProperty: <T>(value: T, defaultValue: T, defaultStatic: T) => T;
  337. /**
  338. * A React hook to manage a dynamic json property.
  339. *
  340. * A dynamic scalar property is defined by a default property and a bound property.
  341. * @typeParam T - The dynamic property type.
  342. * @param value - The bound value.
  343. * @param defaultValue - The default value.
  344. * @param defaultStatic - The default static value.
  345. * @returns The latest updated value.
  346. */
  347. export const useDynamicJsonProperty: <T>(value: string | T, defaultValue: string, defaultStatic: T) => T;
  348. /**
  349. * A React hook that requests an update for every dynamic property of the element.
  350. * @param dispatch - The React dispatcher associated to `TaipyContext`.
  351. * @param id - The identifier of the element.
  352. * @param context - The execution context (property `context`).
  353. * @param updateVars - The content of the property `updateVars`.
  354. * @param varName - The default property backend provided variable (through property `updateVarName`).
  355. * @param forceRefresh - Should Taipy re-evaluate the variables or use the current values.
  356. */
  357. export declare const useDispatchRequestUpdateOnFirstRender: (
  358. dispatch: React.Dispatch<Action>,
  359. id?: string,
  360. context?: string,
  361. updateVars?: string,
  362. varName?: string,
  363. forceRefresh?: boolean
  364. ) => void;
  365. /**
  366. * A React hook that returns the *dispatch* function.
  367. *
  368. * The *dispatch* function allows to send Actions to the Store and initiate backend\
  369. * communications.
  370. * @returns The *dispatch* function.
  371. */
  372. export declare const useDispatch: () => React.Dispatch<Action>;
  373. /**
  374. * A React hook that returns the page module.
  375. *
  376. * The *module* Needs to be added to all Actions to allow for the correct execution of backend functions.
  377. * @returns The page module.
  378. */
  379. export declare const useModule: () => string | undefined;