@sme.up/ketchup 9.4.0 → 9.5.1

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.
Files changed (124) hide show
  1. package/dist/cjs/{f-button-4bef0f8e.js → f-button-b76723c7.js} +1 -1
  2. package/dist/cjs/{f-cell-5e0a400e.js → f-cell-0238450e.js} +5 -5
  3. package/dist/cjs/{f-chip-9159b2a5.js → f-chip-aad323a5.js} +2 -2
  4. package/dist/cjs/{f-image-b9074ea8.js → f-image-a049cb94.js} +1 -1
  5. package/dist/cjs/{f-paginator-utils-bfa0fa70.js → f-paginator-utils-3c1c8cf4.js} +2 -2
  6. package/dist/cjs/{f-text-field-bd197af7.js → f-text-field-d045c000.js} +1 -1
  7. package/dist/cjs/index.cjs.js +1 -1
  8. package/dist/cjs/ketchup.cjs.js +1 -1
  9. package/dist/cjs/kup-accordion.cjs.entry.js +2 -2
  10. package/dist/cjs/kup-autocomplete_27.cjs.entry.js +133 -19
  11. package/dist/cjs/kup-box.cjs.entry.js +7 -7
  12. package/dist/cjs/kup-calendar.cjs.entry.js +4 -4
  13. package/dist/cjs/kup-card-list.cjs.entry.js +1 -1
  14. package/dist/cjs/kup-cell.cjs.entry.js +6 -6
  15. package/dist/cjs/kup-dashboard.cjs.entry.js +4 -4
  16. package/dist/cjs/kup-drawer.cjs.entry.js +1 -1
  17. package/dist/cjs/kup-echart.cjs.entry.js +1 -1
  18. package/dist/cjs/kup-family-tree.cjs.entry.js +3 -3
  19. package/dist/cjs/kup-grid.cjs.entry.js +1 -1
  20. package/dist/cjs/kup-iframe.cjs.entry.js +1 -1
  21. package/dist/cjs/kup-image-list.cjs.entry.js +6 -6
  22. package/dist/cjs/kup-lazy.cjs.entry.js +1 -1
  23. package/dist/cjs/kup-magic-box.cjs.entry.js +2 -2
  24. package/dist/cjs/{kup-manager-5106d5c6.js → kup-manager-ef4342bb.js} +494 -242
  25. package/dist/cjs/kup-nav-bar.cjs.entry.js +1 -1
  26. package/dist/cjs/kup-numeric-picker.cjs.entry.js +2 -2
  27. package/dist/cjs/kup-photo-frame.cjs.entry.js +1 -1
  28. package/dist/cjs/kup-planner.cjs.entry.js +2 -2
  29. package/dist/cjs/kup-probe.cjs.entry.js +1 -1
  30. package/dist/cjs/kup-qlik.cjs.entry.js +1 -1
  31. package/dist/cjs/kup-snackbar.cjs.entry.js +3 -3
  32. package/dist/cjs/loader.cjs.js +1 -1
  33. package/dist/collection/assets/card.js +46 -0
  34. package/dist/collection/components/kup-card/built-in/kup-card-built-in.js +9 -0
  35. package/dist/collection/components/kup-card/built-in/kup-card-openai.js +74 -0
  36. package/dist/collection/components/kup-card/kup-card-declarations.js +1 -0
  37. package/dist/collection/components/kup-card/kup-card.css +86 -0
  38. package/dist/collection/components/kup-card/kup-card.js +6 -0
  39. package/dist/collection/components/kup-data-table/kup-data-table.js +10 -2
  40. package/dist/collection/components/kup-dialog/kup-dialog.css +3 -3
  41. package/dist/collection/components/kup-dialog/kup-dialog.js +19 -5
  42. package/dist/collection/components/kup-image/assets/svg/open-ai.svg +1 -0
  43. package/dist/collection/managers/kup-manager/kup-manager.js +7 -0
  44. package/dist/collection/managers/kup-openai/kup-openai-declarations.js +1 -0
  45. package/dist/collection/managers/kup-openai/kup-openai.js +248 -0
  46. package/dist/components/kup-autocomplete2.js +784 -545
  47. package/dist/components/kup-manager.js +494 -242
  48. package/dist/esm/{f-button-4d7a0b09.js → f-button-e5a13d96.js} +1 -1
  49. package/dist/esm/{f-cell-0bf956b8.js → f-cell-44737d32.js} +5 -5
  50. package/dist/esm/{f-chip-91249dc2.js → f-chip-4ba1fb6c.js} +2 -2
  51. package/dist/esm/{f-image-d666df65.js → f-image-17dd7557.js} +1 -1
  52. package/dist/esm/{f-paginator-utils-b5be40ee.js → f-paginator-utils-c0925f43.js} +2 -2
  53. package/dist/esm/{f-text-field-00a4d490.js → f-text-field-97929753.js} +1 -1
  54. package/dist/esm/index.js +1 -1
  55. package/dist/esm/ketchup.js +1 -1
  56. package/dist/esm/kup-accordion.entry.js +2 -2
  57. package/dist/esm/kup-autocomplete_27.entry.js +133 -19
  58. package/dist/esm/kup-box.entry.js +7 -7
  59. package/dist/esm/kup-calendar.entry.js +4 -4
  60. package/dist/esm/kup-card-list.entry.js +1 -1
  61. package/dist/esm/kup-cell.entry.js +6 -6
  62. package/dist/esm/kup-dashboard.entry.js +4 -4
  63. package/dist/esm/kup-drawer.entry.js +1 -1
  64. package/dist/esm/kup-echart.entry.js +1 -1
  65. package/dist/esm/kup-family-tree.entry.js +3 -3
  66. package/dist/esm/kup-grid.entry.js +1 -1
  67. package/dist/esm/kup-iframe.entry.js +1 -1
  68. package/dist/esm/kup-image-list.entry.js +6 -6
  69. package/dist/esm/kup-lazy.entry.js +1 -1
  70. package/dist/esm/kup-magic-box.entry.js +2 -2
  71. package/dist/esm/{kup-manager-7f0372fb.js → kup-manager-21e2ce65.js} +494 -242
  72. package/dist/esm/kup-nav-bar.entry.js +1 -1
  73. package/dist/esm/kup-numeric-picker.entry.js +2 -2
  74. package/dist/esm/kup-photo-frame.entry.js +1 -1
  75. package/dist/esm/kup-planner.entry.js +2 -2
  76. package/dist/esm/kup-probe.entry.js +1 -1
  77. package/dist/esm/kup-qlik.entry.js +1 -1
  78. package/dist/esm/kup-snackbar.entry.js +3 -3
  79. package/dist/esm/loader.js +1 -1
  80. package/dist/ketchup/assets/svg/open-ai.svg +1 -0
  81. package/dist/ketchup/index.esm.js +1 -1
  82. package/dist/ketchup/ketchup.esm.js +1 -1
  83. package/dist/ketchup/p-00cc3d95.entry.js +1 -0
  84. package/dist/ketchup/{p-f5b5b35d.entry.js → p-04861e0f.entry.js} +1 -1
  85. package/dist/ketchup/{p-491c3cd0.entry.js → p-0bdd3eb4.entry.js} +1 -1
  86. package/dist/ketchup/{p-9fdd98be.entry.js → p-15c3d2c4.entry.js} +1 -1
  87. package/dist/ketchup/{p-1ecff2b9.entry.js → p-265c1bac.entry.js} +1 -1
  88. package/dist/ketchup/{p-b51b1000.entry.js → p-3172b2d6.entry.js} +1 -1
  89. package/dist/ketchup/{p-19be646f.entry.js → p-4528e07a.entry.js} +1 -1
  90. package/dist/ketchup/{p-e8f5b996.entry.js → p-4b141cad.entry.js} +1 -1
  91. package/dist/ketchup/{p-16c23ab7.entry.js → p-4dbcd9cf.entry.js} +1 -1
  92. package/dist/ketchup/{p-01401fba.entry.js → p-62fe8b61.entry.js} +1 -1
  93. package/dist/ketchup/{p-466d3604.entry.js → p-65984a13.entry.js} +1 -1
  94. package/dist/ketchup/{p-1180f9e0.entry.js → p-6e2a9054.entry.js} +1 -1
  95. package/dist/ketchup/p-7e1d9192.js +29 -0
  96. package/dist/ketchup/{p-28dcc98b.js → p-859aa987.js} +1 -1
  97. package/dist/ketchup/{p-96678597.entry.js → p-88efeed0.entry.js} +1 -1
  98. package/dist/ketchup/p-89f09a1c.entry.js +9 -0
  99. package/dist/ketchup/p-91180bd4.entry.js +1 -0
  100. package/dist/ketchup/{p-d5a9924b.entry.js → p-9868af74.entry.js} +1 -1
  101. package/dist/ketchup/p-9bdc7491.js +1 -0
  102. package/dist/ketchup/{p-1e77ddec.js → p-9bf00c9c.js} +1 -1
  103. package/dist/ketchup/{p-378bbbcf.js → p-9e68a4c0.js} +1 -1
  104. package/dist/ketchup/{p-3ba32190.entry.js → p-aecf6437.entry.js} +1 -1
  105. package/dist/ketchup/{p-31a3eb96.entry.js → p-bc0a2875.entry.js} +1 -1
  106. package/dist/ketchup/{p-bbc121a2.entry.js → p-da3b5277.entry.js} +1 -1
  107. package/dist/ketchup/{p-8e04781a.js → p-de755f71.js} +1 -1
  108. package/dist/ketchup/{p-6d51125a.js → p-e50650d0.js} +1 -1
  109. package/dist/ketchup/{p-abdbd35e.entry.js → p-ec469a38.entry.js} +1 -1
  110. package/dist/ketchup/{p-f0b3d110.entry.js → p-ee382e52.entry.js} +1 -1
  111. package/dist/ketchup/{p-613ef7fa.entry.js → p-f8069901.entry.js} +1 -1
  112. package/dist/types/components/kup-card/built-in/kup-card-built-in.d.ts +6 -0
  113. package/dist/types/components/kup-card/built-in/kup-card-openai.d.ts +3 -0
  114. package/dist/types/components/kup-card/kup-card-declarations.d.ts +20 -1
  115. package/dist/types/managers/kup-manager/kup-manager-declarations.d.ts +3 -0
  116. package/dist/types/managers/kup-manager/kup-manager.d.ts +2 -0
  117. package/dist/types/managers/kup-openai/kup-openai-declarations.d.ts +4 -0
  118. package/dist/types/managers/kup-openai/kup-openai.d.ts +29 -0
  119. package/package.json +1 -1
  120. package/dist/ketchup/p-8c835b19.entry.js +0 -1
  121. package/dist/ketchup/p-91ee68b1.js +0 -29
  122. package/dist/ketchup/p-bfa85d01.js +0 -1
  123. package/dist/ketchup/p-d6aa3b78.entry.js +0 -1
  124. package/dist/ketchup/p-e4657f9b.entry.js +0 -9
@@ -1091,11 +1091,19 @@ export class KupDataTable {
1091
1091
  }
1092
1092
  return (h("kup-card", { customStyle: "::slotted(kup-switch) { width: max-content !important; } ::slotted(*) { margin: auto !important; } ::slotted(.customize-element) { margin: auto !important; padding: 0 1em 1em 1em !important; width: max-content !important; } ::slotted(.customize-element):nth-child(1) { padding-top: 1em !important; }", isMenu: true, layoutFamily: KupCardFamily.FREE, ref: (el) => {
1093
1093
  __classPrivateFieldSet(this, _KupDataTable_customizeTopPanelRef, el, "f");
1094
- }, sizeX: "360px", sizeY: "300px" }, density, grid, fontsize, transpose, h("kup-switch", { class: "customize-element", checked: this.dragEnabled, label: __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").language.translate(KupLanguageGeneric.DRAG_AND_DROP), leadingLabel: true, "onkup-switch-change": () => (this.dragEnabled = !this.dragEnabled) }), h("kup-switch", { class: "customize-element", checked: this.editableData, label: __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").language.translate(KupLanguageGeneric.EDITABLE), leadingLabel: true, "onkup-switch-change": () => (this.editableData = !this.editableData) }), h("kup-button", { title: __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").language.translate(KupLanguageGeneric.TOGGLE) +
1094
+ }, sizeX: "360px", sizeY: "300px" }, density, grid, fontsize, transpose, h("kup-switch", { class: "customize-element", checked: this.dragEnabled, label: __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").language.translate(KupLanguageGeneric.DRAG_AND_DROP), leadingLabel: true, "onkup-switch-change": () => (this.dragEnabled = !this.dragEnabled) }), h("kup-switch", { class: "customize-element", checked: this.editableData, label: __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").language.translate(KupLanguageGeneric.EDITABLE), leadingLabel: true, "onkup-switch-change": () => (this.editableData = !this.editableData) }), h("div", { style: {
1095
+ display: 'grid',
1096
+ 'grid-template-columns': 'repeat(2, auto)',
1097
+ width: 'max-content',
1098
+ } }, h("kup-button", { title: __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").language.translate(KupLanguageGeneric.TOGGLE) +
1095
1099
  ' Magic Box ' +
1096
1100
  '(' +
1097
1101
  __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").language.translate(KupLanguageGeneric.EXPERIMENTAL_FEAT) +
1098
- ')', icon: "auto-fix", "onkup-button-click": () => __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").toggleMagicBox() }), totalsMatrix));
1102
+ ')', icon: "auto-fix", "onkup-button-click": () => __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").toggleMagicBox() }), __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").openAI && __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").openAI.url ? (h("kup-button", { title: __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").language.translate(KupLanguageGeneric.TOGGLE) +
1103
+ ' Open AI ' +
1104
+ '(' +
1105
+ __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").language.translate(KupLanguageGeneric.EXPERIMENTAL_FEAT) +
1106
+ ')', icon: "open-ai", "onkup-button-click": () => __classPrivateFieldGet(this, _KupDataTable_kupManager, "f").openAI.show(this.data) })) : null), totalsMatrix));
1099
1107
  }
1100
1108
  render() {
1101
1109
  __classPrivateFieldSet(this, _KupDataTable_thRefs, [], "f");
@@ -20,11 +20,11 @@
20
20
  width: 100%;
21
21
  }
22
22
 
23
- [fade-in] {
23
+ :host([fade-in]) {
24
24
  opacity: 0;
25
25
  }
26
- [fade-in] ::slotted {
27
- display: none;
26
+ :host([fade-in]) ::slotted {
27
+ opacity: 0;
28
28
  }
29
29
 
30
30
  .header {
@@ -14,13 +14,14 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
14
14
  throw new TypeError("Cannot write private member to an object whose class did not declare it");
15
15
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
16
  };
17
- var _KupDialog_header, _KupDialog_kupManager;
17
+ var _KupDialog_header, _KupDialog_kupManager, _KupDialog_recalcSafeguard;
18
18
  import { forceUpdate, h, Host, } from "@stencil/core";
19
19
  import { FImage } from "../../f-components/f-image/f-image";
20
20
  import { kupManagerInstance } from "../../managers/kup-manager/kup-manager";
21
21
  import { getProps, setProps } from "../../utils/utils";
22
22
  import { componentWrapperId } from "../../variables/GenericVariables";
23
23
  import { KupDialogProps, } from "./kup-dialog-declarations";
24
+ import { KupDebugCategory } from "../../managers/kup-debug/kup-debug-declarations";
24
25
  export class KupDialog {
25
26
  constructor() {
26
27
  /*-------------------------------------------------*/
@@ -28,6 +29,7 @@ export class KupDialog {
28
29
  /*-------------------------------------------------*/
29
30
  _KupDialog_header.set(this, null);
30
31
  _KupDialog_kupManager.set(this, kupManagerInstance());
32
+ _KupDialog_recalcSafeguard.set(this, 0);
31
33
  this.autoCenter = { onReady: true };
32
34
  this.customStyle = '';
33
35
  this.header = { icons: { close: true } };
@@ -61,11 +63,25 @@ export class KupDialog {
61
63
  * Places the dialog at the center of the screen.
62
64
  */
63
65
  async recalcPosition() {
66
+ var _a;
64
67
  const rect = this.rootElement.getBoundingClientRect();
68
+ if (!rect.x && !rect.y) {
69
+ __classPrivateFieldGet(this, _KupDialog_kupManager, "f").debug.logMessage(this, `recalcPosition() ran before the component finished being drawn. Running again (attempt #${__classPrivateFieldGet(this, _KupDialog_recalcSafeguard, "f")}).`, KupDebugCategory.INFO);
70
+ if (__classPrivateFieldGet(this, _KupDialog_recalcSafeguard, "f") < 50) {
71
+ __classPrivateFieldSet(this, _KupDialog_recalcSafeguard, (_a = __classPrivateFieldGet(this, _KupDialog_recalcSafeguard, "f"), _a++, _a), "f");
72
+ setTimeout(async () => this.recalcPosition(), 50);
73
+ return;
74
+ }
75
+ else {
76
+ __classPrivateFieldGet(this, _KupDialog_kupManager, "f").debug.logMessage(this, `Too many attempts centering the dialog.`, KupDebugCategory.WARNING);
77
+ }
78
+ }
79
+ __classPrivateFieldSet(this, _KupDialog_recalcSafeguard, 0, "f");
65
80
  const left = window.innerWidth / 2 - rect.width / 2;
66
81
  const top = window.innerHeight / 2 - rect.height / 2;
67
82
  this.rootElement.style.setProperty('--kup_dialog_left', left + 'px');
68
83
  this.rootElement.style.setProperty('--kup_dialog_top', top + 'px');
84
+ this.rootElement.removeAttribute('fade-in');
69
85
  }
70
86
  /**
71
87
  * This method is used to trigger a new render of the component.
@@ -91,9 +107,7 @@ export class KupDialog {
91
107
  var _a;
92
108
  __classPrivateFieldGet(this, _KupDialog_kupManager, "f").interact.dialogify(this.rootElement, __classPrivateFieldGet(this, _KupDialog_header, "f") ? __classPrivateFieldGet(this, _KupDialog_header, "f") : null, !this.resizable);
93
109
  if ((_a = this.autoCenter) === null || _a === void 0 ? void 0 : _a.onReady) {
94
- this.recalcPosition().then(() => {
95
- this.rootElement.removeAttribute('fade-in');
96
- });
110
+ this.recalcPosition();
97
111
  }
98
112
  else {
99
113
  this.rootElement.removeAttribute('fade-in');
@@ -476,4 +490,4 @@ export class KupDialog {
476
490
  }
477
491
  static get elementRef() { return "rootElement"; }
478
492
  }
479
- _KupDialog_header = new WeakMap(), _KupDialog_kupManager = new WeakMap();
493
+ _KupDialog_header = new WeakMap(), _KupDialog_kupManager = new WeakMap(), _KupDialog_recalcSafeguard = new WeakMap();
@@ -0,0 +1 @@
1
+ <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z"/></svg>
@@ -18,6 +18,7 @@ import { KupMath } from "../kup-math/kup-math";
18
18
  import { KupTooltip } from "../kup-tooltip/kup-tooltip";
19
19
  import { setAssetPath } from "@stencil/core";
20
20
  import html2canvas from "html2canvas";
21
+ import { KupOpenAI } from "../kup-openai/kup-openai";
21
22
  const dom = document.documentElement;
22
23
  /**
23
24
  * This class controls every other Ketchup utility suite.
@@ -29,6 +30,8 @@ export class KupManager {
29
30
  */
30
31
  constructor(overrides) {
31
32
  let datesLocale = null, debugActive = null, debugAutoprint = null, debugLogLimit = null, dialogRestrictContainer = null, dialogZIndex = null, languageList = null, languageName = null, objectsList = null, scrollOnHoverDelay = null, scrollOnHoverStep = null, themeList = null, themeName = null, tooltipDelay = null, tooltipFCellCallbacks = null;
33
+ /** POI VIA */
34
+ let openAIUrl = 'https://kokosstaging.smeup.com';
32
35
  if (overrides) {
33
36
  const assetsPath = overrides.assetsPath;
34
37
  const dates = overrides.dates;
@@ -39,6 +42,9 @@ export class KupManager {
39
42
  const scrollOnHover = overrides.scrollOnHover;
40
43
  const theme = overrides.theme;
41
44
  const tooltip = overrides.tooltip;
45
+ if (overrides.openAIUrl) {
46
+ openAIUrl = overrides.openAIUrl;
47
+ }
42
48
  if (assetsPath) {
43
49
  setAssetPath(assetsPath);
44
50
  }
@@ -89,6 +95,7 @@ export class KupManager {
89
95
  this.interact = new KupInteract(dialogZIndex, dialogRestrictContainer);
90
96
  this.language = new KupLanguage(languageList, languageName);
91
97
  this.magicBox = null;
98
+ this.openAI = new KupOpenAI(openAIUrl);
92
99
  this.math = new KupMath();
93
100
  this.overrides = overrides ? overrides : null;
94
101
  this.objects = new KupObjects(objectsList);
@@ -0,0 +1,248 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f)
3
+ throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
5
+ throw new TypeError("Cannot read private member from an object whose class did not declare it");
6
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
7
+ };
8
+ var _KupOpenAI_instances, _KupOpenAI_setError, _KupOpenAI_invalidPassword, _KupOpenAI_create, _KupOpenAI_connect, _KupOpenAI_disconnect;
9
+ import { KupCardFamily } from "../../components/kup-card/kup-card-declarations";
10
+ import { KupDebugCategory } from "../kup-debug/kup-debug-declarations";
11
+ const dom = document.documentElement;
12
+ export class KupOpenAI {
13
+ /**
14
+ * Initializes KupOpenAI.
15
+ */
16
+ constructor(url) {
17
+ _KupOpenAI_instances.add(this);
18
+ this.card = null;
19
+ this.data = null;
20
+ this.dialog = null;
21
+ this.sessionInfo = null;
22
+ this.url = null;
23
+ this.container = document.createElement('div');
24
+ this.container.setAttribute('kup-openai', '');
25
+ document.body.appendChild(this.container);
26
+ this.url = url;
27
+ }
28
+ getCardOptions() {
29
+ if (!this.card.data) {
30
+ this.card.data = {};
31
+ }
32
+ if (!this.card.data.options) {
33
+ this.card.data.options = {
34
+ submitCb: this.chat,
35
+ authCb: this.auth,
36
+ };
37
+ }
38
+ return this.card.data.options;
39
+ }
40
+ /**
41
+ * Shows the component
42
+ * @param data
43
+ * @param options
44
+ */
45
+ show(data) {
46
+ this.data = data;
47
+ // Creates the card or updates it with new options
48
+ __classPrivateFieldGet(this, _KupOpenAI_instances, "m", _KupOpenAI_create).call(this);
49
+ }
50
+ /**
51
+ * Hides the component.
52
+ */
53
+ hide() {
54
+ this.card.remove();
55
+ this.card = null;
56
+ this.dialog.remove();
57
+ this.dialog = null;
58
+ __classPrivateFieldGet(this, _KupOpenAI_instances, "m", _KupOpenAI_disconnect).call(this);
59
+ }
60
+ async auth(event) {
61
+ console.log('cacca');
62
+ const openAI = dom.ketchup.openAI;
63
+ if (!openAI.url) {
64
+ return;
65
+ }
66
+ const pwd = await event.detail.comp.getValue();
67
+ let response = null;
68
+ try {
69
+ response = await fetch(openAI.url + '/api/auth', {
70
+ method: 'POST',
71
+ headers: {
72
+ 'Content-Type': 'application/json',
73
+ },
74
+ body: JSON.stringify({ data: pwd }),
75
+ });
76
+ }
77
+ catch (e) {
78
+ __classPrivateFieldGet(openAI, _KupOpenAI_instances, "m", _KupOpenAI_setError).call(openAI, e.message, openAI);
79
+ return;
80
+ }
81
+ if (response) {
82
+ if (response.status != 200) {
83
+ __classPrivateFieldGet(openAI, _KupOpenAI_instances, "m", _KupOpenAI_invalidPassword).call(openAI, event);
84
+ //this.#setError(await response.text());
85
+ return;
86
+ }
87
+ const responseJson = await response.json();
88
+ if (responseJson.status == 'ok') {
89
+ openAI.getCardOptions().state = 'connecting';
90
+ openAI.card.refresh();
91
+ __classPrivateFieldGet(openAI, _KupOpenAI_instances, "m", _KupOpenAI_connect).call(openAI);
92
+ return;
93
+ }
94
+ }
95
+ openAI.getCardOptions().state = 'error';
96
+ openAI.card.refresh();
97
+ }
98
+ async chat(disableInteractivity, inputArea) {
99
+ const communicate = async (question) => {
100
+ if (!openAI.url) {
101
+ return;
102
+ }
103
+ if (!openAI.sessionInfo) {
104
+ return;
105
+ }
106
+ const responseMessages = [];
107
+ let response = null;
108
+ try {
109
+ response = await fetch(openAI.url + '/api/chat', {
110
+ method: 'POST',
111
+ headers: {
112
+ 'Content-Type': 'application/json',
113
+ },
114
+ body: JSON.stringify({
115
+ fileId: openAI.sessionInfo.fileId,
116
+ threadId: openAI.sessionInfo.threadId,
117
+ question: question,
118
+ }),
119
+ });
120
+ }
121
+ catch (e) {
122
+ __classPrivateFieldGet(this, _KupOpenAI_instances, "m", _KupOpenAI_setError).call(this, e.message, openAI);
123
+ }
124
+ if (response) {
125
+ if (response.status != 200) {
126
+ __classPrivateFieldGet(this, _KupOpenAI_instances, "m", _KupOpenAI_setError).call(this, await response.text(), openAI);
127
+ return;
128
+ }
129
+ const responseJson = await response.json();
130
+ if (responseJson && responseJson.messages) {
131
+ responseMessages.push(...responseJson.messages);
132
+ }
133
+ }
134
+ return responseMessages;
135
+ };
136
+ const openAI = dom.ketchup.openAI;
137
+ if (!openAI.card) {
138
+ return;
139
+ }
140
+ disableInteractivity(true);
141
+ openAI.getCardOptions().messages = await communicate(await inputArea.getValue());
142
+ openAI.card.refresh();
143
+ disableInteractivity(false);
144
+ }
145
+ }
146
+ _KupOpenAI_instances = new WeakSet(), _KupOpenAI_setError = function _KupOpenAI_setError(message, _this, dontRefreshCard) {
147
+ if (!_this) {
148
+ _this = this;
149
+ }
150
+ dom.ketchup.debug.logMessage(_this, message, KupDebugCategory.ERROR);
151
+ if (dontRefreshCard) {
152
+ return;
153
+ }
154
+ _this.getCardOptions().state = 'error';
155
+ _this.card.refresh();
156
+ }, _KupOpenAI_invalidPassword = function _KupOpenAI_invalidPassword(event) {
157
+ const field = event.detail.comp;
158
+ field.helper = 'Invalid password.';
159
+ field.rootElement.classList.add('kup-danger');
160
+ field.refresh();
161
+ }, _KupOpenAI_create = function _KupOpenAI_create() {
162
+ this.card = document.createElement('kup-card');
163
+ this.card.layoutFamily = KupCardFamily.BUILT_IN;
164
+ this.card.layoutNumber = 7;
165
+ this.card.sizeX = '100%';
166
+ this.card.sizeY = '100%';
167
+ this.dialog = document.createElement('kup-dialog');
168
+ this.dialog.header = {
169
+ title: 'Chat with Data',
170
+ icons: { close: true },
171
+ };
172
+ this.dialog.id = 'openai';
173
+ this.dialog.modal = { closeOnBackdropClick: false };
174
+ this.dialog.sizeX = '50vw';
175
+ this.dialog.sizeY = '50vh';
176
+ this.dialog.addEventListener('kup-dialog-close', () => this.hide());
177
+ this.dialog.appendChild(this.card);
178
+ this.container.appendChild(this.dialog);
179
+ if (!this.url) {
180
+ this.getCardOptions().state = 'error';
181
+ }
182
+ else {
183
+ this.getCardOptions().state = 'authentication';
184
+ }
185
+ }, _KupOpenAI_connect = async function _KupOpenAI_connect() {
186
+ if (!this.url) {
187
+ return;
188
+ }
189
+ let response = null;
190
+ try {
191
+ response = await fetch(this.url + '/api/init', {
192
+ method: 'POST',
193
+ headers: {
194
+ 'Content-Type': 'application/json',
195
+ },
196
+ body: JSON.stringify({ data: this.data }),
197
+ });
198
+ }
199
+ catch (e) {
200
+ __classPrivateFieldGet(this, _KupOpenAI_instances, "m", _KupOpenAI_setError).call(this, e.message);
201
+ return;
202
+ }
203
+ if (response) {
204
+ if (response.status != 200) {
205
+ __classPrivateFieldGet(this, _KupOpenAI_instances, "m", _KupOpenAI_setError).call(this, await response.text());
206
+ return;
207
+ }
208
+ const responseJson = await response.json();
209
+ this.sessionInfo = {
210
+ fileId: responseJson.fileId,
211
+ threadId: responseJson.threadId,
212
+ };
213
+ this.getCardOptions().state = 'ready';
214
+ this.card.refresh();
215
+ return;
216
+ }
217
+ this.getCardOptions().state = 'error';
218
+ this.card.refresh();
219
+ }, _KupOpenAI_disconnect = async function _KupOpenAI_disconnect() {
220
+ if (!this.url) {
221
+ return;
222
+ }
223
+ if (!this.sessionInfo) {
224
+ return;
225
+ }
226
+ let response = null;
227
+ try {
228
+ response = await fetch(this.url + '/api/finalize', {
229
+ method: 'POST',
230
+ headers: {
231
+ 'Content-Type': 'application/json',
232
+ },
233
+ body: JSON.stringify({
234
+ fileId: this.sessionInfo.fileId,
235
+ threadId: this.sessionInfo.threadId,
236
+ }),
237
+ });
238
+ }
239
+ catch (e) {
240
+ __classPrivateFieldGet(this, _KupOpenAI_instances, "m", _KupOpenAI_setError).call(this, e.message, undefined, true);
241
+ }
242
+ this.sessionInfo = null;
243
+ if (response) {
244
+ if (response.status != 200) {
245
+ __classPrivateFieldGet(this, _KupOpenAI_instances, "m", _KupOpenAI_setError).call(this, await response.text(), undefined, true);
246
+ }
247
+ }
248
+ };