index.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 { ComponentType } from "react";
  14. import Button from "./Button";
  15. import Chat from "./Chat";
  16. import Chart from "./Chart";
  17. import DateRange from "./DateRange";
  18. import DateSelector from "./DateSelector";
  19. import Dialog from "./Dialog";
  20. import Expandable from "./Expandable";
  21. import Field from "./Field";
  22. import FileDownload from "./FileDownload";
  23. import FileSelector from "./FileSelector";
  24. import Image from "./Image";
  25. import Indicator from "./Indicator";
  26. import Input from "./Input";
  27. import Login from "./Login";
  28. import Layout from "./Layout";
  29. import Link from "./Link";
  30. import MenuCtl from "./MenuCtl";
  31. import Metric from "./Metric";
  32. import NavBar from "./NavBar";
  33. import PageContent from "../pages/PageContent";
  34. import Pane from "./Pane";
  35. import Part from "./Part";
  36. import Selector from "./Selector";
  37. import Slider from "./Slider";
  38. import StatusList from "./StatusList";
  39. import Table from "./Table";
  40. import Toggle from "./Toggle";
  41. import TreeView from "./TreeView";
  42. const registeredComponents: Record<string, ComponentType> = {};
  43. export const getRegisteredComponents = () => {
  44. if (registeredComponents.TreeView === undefined) {
  45. Object.entries({
  46. a: Link,
  47. Button: Button,
  48. Chat: Chat,
  49. Chart: Chart,
  50. DateRange: DateRange,
  51. DateSelector: DateSelector,
  52. Dialog: Dialog,
  53. Expandable: Expandable,
  54. Field: Field,
  55. FileDownload: FileDownload,
  56. FileSelector: FileSelector,
  57. Image: Image,
  58. Indicator: Indicator,
  59. Input: Input,
  60. Login: Login,
  61. Layout: Layout,
  62. MenuCtl: MenuCtl,
  63. Metric: Metric,
  64. NavBar: NavBar,
  65. PageContent: PageContent,
  66. Pane: Pane,
  67. Part: Part,
  68. Selector: Selector,
  69. Slider: Slider,
  70. Status: StatusList,
  71. Table: Table,
  72. Toggle: Toggle,
  73. TreeView: TreeView,
  74. }).forEach(([name, comp]) => (registeredComponents[name] = comp as ComponentType));
  75. if (window.taipyConfig?.extensions) {
  76. Object.entries(window.taipyConfig.extensions).forEach(([libName, elts]) => {
  77. if (elts && elts.length) {
  78. const libParts = libName.split("/");
  79. const modName = libParts.length > 2 ? libParts[2] : libName;
  80. const mod: Record<string, ComponentType> = window[modName] as Record<string, ComponentType>;
  81. if (mod) {
  82. elts.forEach((elt) => {
  83. const comp = mod[elt];
  84. if (comp) {
  85. registeredComponents[modName + "_" + elt] = comp;
  86. } else {
  87. console.error("module '", modName, "' doesn't export component '", elt, "'");
  88. }
  89. });
  90. } else {
  91. console.error("module '", modName, "' cannot be loaded.");
  92. }
  93. }
  94. });
  95. }
  96. }
  97. return registeredComponents;
  98. };