@antscorp/antsomi-ui 2.0.103 → 2.0.105

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 (168) hide show
  1. package/es/__mocks__/sql-query.json +56 -0
  2. package/es/assets/css/main.scss +2 -2
  3. package/es/components/atoms/App/App.d.ts +7 -0
  4. package/es/components/atoms/App/App.js +5 -0
  5. package/es/components/atoms/App/index.d.ts +1 -0
  6. package/es/components/atoms/App/index.js +1 -0
  7. package/es/components/atoms/Input/Input.d.ts +11 -17
  8. package/es/components/atoms/Input/Input.js +11 -12
  9. package/es/components/atoms/List/List.d.ts +1 -0
  10. package/es/components/atoms/List/List.js +1 -0
  11. package/es/components/atoms/List/index.d.ts +1 -0
  12. package/es/components/atoms/List/index.js +1 -0
  13. package/es/components/atoms/Scrollbars/Scrollbars.d.ts +3 -4
  14. package/es/components/atoms/Scrollbars/Scrollbars.js +2 -1
  15. package/es/components/atoms/SlideBar/SlideBar.js +1 -1
  16. package/es/components/atoms/Tag/Tag.js +1 -1
  17. package/es/components/atoms/index.d.ts +3 -0
  18. package/es/components/atoms/index.js +2 -0
  19. package/es/components/icons/FeedbackOutlinedIcon.d.ts +3 -0
  20. package/es/components/icons/FeedbackOutlinedIcon.js +7 -0
  21. package/es/components/icons/LazyIcon/LazyIcon.d.ts +5 -0
  22. package/es/components/icons/LazyIcon/LazyIcon.js +5 -0
  23. package/es/components/icons/NavigateBeforeIcon.d.ts +3 -0
  24. package/es/components/icons/NavigateBeforeIcon.js +7 -0
  25. package/es/components/icons/NavigateNextIcon.d.ts +3 -0
  26. package/es/components/icons/NavigateNextIcon.js +7 -0
  27. package/es/components/icons/PenSparkIcon.d.ts +3 -0
  28. package/es/components/icons/PenSparkIcon.js +7 -0
  29. package/es/components/icons/StatusSuccessIcon.d.ts +3 -0
  30. package/es/components/icons/StatusSuccessIcon.js +7 -0
  31. package/es/components/icons/SummarizeIconIcon.d.ts +3 -0
  32. package/es/components/icons/SummarizeIconIcon.js +7 -0
  33. package/es/components/icons/index.d.ts +5 -0
  34. package/es/components/icons/index.js +5 -0
  35. package/es/components/index.scss +1 -0
  36. package/es/components/molecules/AddDynamicContent/AddDynamicContent.d.ts +1 -2
  37. package/es/components/molecules/CalendarSelection/constants.d.ts +1 -1
  38. package/es/components/molecules/CalendarSelection/constants.js +1 -1
  39. package/es/components/molecules/CaptureScreen/CaptureScreen.d.ts +8 -2
  40. package/es/components/molecules/CaptureScreen/CaptureScreen.js +2 -2
  41. package/es/components/molecules/DrawerDetail/DrawerDetail.js +19 -7
  42. package/es/components/molecules/DrawerDetail/types.d.ts +5 -0
  43. package/es/components/molecules/EditingListV2/components/Loadable.d.ts +1 -1
  44. package/es/components/molecules/EditorScript/EditorScript.d.ts +1 -2
  45. package/es/components/molecules/EditorScript/EditorScript.js +5 -1
  46. package/es/components/molecules/FontSizeInput/index.scss +15 -0
  47. package/es/components/molecules/Select/styled.js +1 -1
  48. package/es/components/molecules/SelectAccount/type.d.ts +1 -1
  49. package/es/components/molecules/TagifyInput/utils.style.js +1 -0
  50. package/es/components/molecules/TemplateSaveAs/hooks/useTemplateSave.d.ts +1 -1
  51. package/es/components/organism/AccountProfile/components/AccountSetting/AccountSetting.js +2 -1
  52. package/es/components/organism/AccountProfile/components/AccountSetting/components/LanguageSelector/styles.d.ts +1 -1
  53. package/es/components/organism/AccountProfile/components/AccountSetting/components/LanguageSelector/styles.js +1 -1
  54. package/es/components/organism/ActivityTimeline/__mocks__/event_tracking.json +1290 -0
  55. package/es/components/organism/ActivityTimeline/__mocks__/timeline.json +3059 -0
  56. package/es/components/organism/DataTable/hooks/useDataTableListing/useDataTableListing.js +5 -4
  57. package/es/components/organism/Login/components/LoginWithEmail/styled.js +1 -1
  58. package/es/components/organism/Login/components/SetupGGAuthenticator/styled.js +1 -1
  59. package/es/components/organism/Login/components/SignIn/styled.js +1 -1
  60. package/es/components/organism/Login/components/WidgetLayout/styled.js +1 -1
  61. package/es/components/organism/Login/styled.d.ts +3 -3
  62. package/es/components/organism/Login/styled.js +11 -11
  63. package/es/components/organism/ModifyColumnModal/styled.d.ts +2 -2
  64. package/es/components/organism/PreviewTemplateModal/components/ThumbnailSlider/styled.d.ts +1 -2
  65. package/es/components/organism/PreviewTemplateModal/components/ThumbnailSlider/styled.js +3 -1
  66. package/es/components/organism/SQLGeneration/SQLGeneration.d.ts +3 -0
  67. package/es/components/organism/SQLGeneration/SQLGeneration.js +26 -0
  68. package/es/components/organism/SQLGeneration/components/CheckboxShowDiff.d.ts +2 -0
  69. package/es/components/organism/SQLGeneration/components/CheckboxShowDiff.js +16 -0
  70. package/es/components/organism/SQLGeneration/components/EditTableSourcesDrawer.d.ts +2 -0
  71. package/es/components/organism/SQLGeneration/components/EditTableSourcesDrawer.js +56 -0
  72. package/es/components/organism/SQLGeneration/components/ErrorDisplay.d.ts +21 -0
  73. package/es/components/organism/SQLGeneration/components/ErrorDisplay.js +69 -0
  74. package/es/components/organism/SQLGeneration/components/SQLGenerationActions.d.ts +4 -0
  75. package/es/components/organism/SQLGeneration/components/SQLGenerationActions.js +23 -0
  76. package/es/components/organism/SQLGeneration/components/SQLGenerationCodeBlock.d.ts +2 -0
  77. package/es/components/organism/SQLGeneration/components/SQLGenerationCodeBlock.js +22 -0
  78. package/es/components/organism/SQLGeneration/components/SQLGenerationEditPrompt.d.ts +2 -0
  79. package/es/components/organism/SQLGeneration/components/SQLGenerationEditPrompt.js +66 -0
  80. package/es/components/organism/SQLGeneration/components/SQLGenerationHeader.d.ts +2 -0
  81. package/es/components/organism/SQLGeneration/components/SQLGenerationHeader.js +10 -0
  82. package/es/components/organism/SQLGeneration/components/SQLGenerationModal.d.ts +2 -0
  83. package/es/components/organism/SQLGeneration/components/SQLGenerationModal.js +35 -0
  84. package/es/components/organism/SQLGeneration/components/SQLGenerationPagination.d.ts +4 -0
  85. package/es/components/organism/SQLGeneration/components/SQLGenerationPagination.js +13 -0
  86. package/es/components/organism/SQLGeneration/components/SQLGenerationPrompt.d.ts +2 -0
  87. package/es/components/organism/SQLGeneration/components/SQLGenerationPrompt.js +31 -0
  88. package/es/components/organism/SQLGeneration/components/SQLGenerationPromptDisplay.d.ts +2 -0
  89. package/es/components/organism/SQLGeneration/components/SQLGenerationPromptDisplay.js +15 -0
  90. package/es/components/organism/SQLGeneration/components/SQLGenerationQuerySummary.d.ts +2 -0
  91. package/es/components/organism/SQLGeneration/components/SQLGenerationQuerySummary.js +17 -0
  92. package/es/components/organism/SQLGeneration/components/SQLGenerationRefine.d.ts +1 -0
  93. package/es/components/organism/SQLGeneration/components/SQLGenerationRefine.js +55 -0
  94. package/es/components/organism/SQLGeneration/components/SQLGenerationResult.d.ts +5 -0
  95. package/es/components/organism/SQLGeneration/components/SQLGenerationResult.js +29 -0
  96. package/es/components/organism/SQLGeneration/components/index.d.ts +9 -0
  97. package/es/components/organism/SQLGeneration/components/index.js +9 -0
  98. package/es/components/organism/SQLGeneration/components/styled.d.ts +52 -0
  99. package/es/components/organism/SQLGeneration/components/styled.js +382 -0
  100. package/es/components/organism/SQLGeneration/constants.d.ts +48 -0
  101. package/es/components/organism/SQLGeneration/constants.js +48 -0
  102. package/es/components/organism/SQLGeneration/hooks/index.d.ts +1 -0
  103. package/es/components/organism/SQLGeneration/hooks/index.js +1 -0
  104. package/es/components/organism/SQLGeneration/hooks/useKeyboardNavigation.d.ts +14 -0
  105. package/es/components/organism/SQLGeneration/hooks/useKeyboardNavigation.js +123 -0
  106. package/es/components/organism/SQLGeneration/index.d.ts +10 -0
  107. package/es/components/organism/SQLGeneration/index.js +6 -0
  108. package/es/components/organism/SQLGeneration/index.scss +1 -0
  109. package/es/components/organism/SQLGeneration/integrations/AceEditor/index.d.ts +1 -0
  110. package/es/components/organism/SQLGeneration/integrations/AceEditor/index.js +1 -0
  111. package/es/components/organism/SQLGeneration/integrations/AceEditor/index.scss +4 -0
  112. package/es/components/organism/SQLGeneration/integrations/AceEditor/useAceEditor.d.ts +9 -0
  113. package/es/components/organism/SQLGeneration/integrations/AceEditor/useAceEditor.js +24 -0
  114. package/es/components/organism/SQLGeneration/integrations/AceEditor/useEnhancePlaceholder.d.ts +10 -0
  115. package/es/components/organism/SQLGeneration/integrations/AceEditor/useEnhancePlaceholder.js +172 -0
  116. package/es/components/organism/SQLGeneration/integrations/AceEditor/useInsertQuery.d.ts +8 -0
  117. package/es/components/organism/SQLGeneration/integrations/AceEditor/useInsertQuery.js +21 -0
  118. package/es/components/organism/SQLGeneration/integrations/AntsomiAI/index.d.ts +1 -0
  119. package/es/components/organism/SQLGeneration/integrations/AntsomiAI/index.js +1 -0
  120. package/es/components/organism/SQLGeneration/integrations/AntsomiAI/useAntsomiAI.d.ts +1 -0
  121. package/es/components/organism/SQLGeneration/integrations/AntsomiAI/useAntsomiAI.js +35 -0
  122. package/es/components/organism/SQLGeneration/integrations/AntsomiSqlWS/index.d.ts +1 -0
  123. package/es/components/organism/SQLGeneration/integrations/AntsomiSqlWS/index.js +1 -0
  124. package/es/components/organism/SQLGeneration/integrations/AntsomiSqlWS/useAntsomiSqlWS.d.ts +7 -0
  125. package/es/components/organism/SQLGeneration/integrations/AntsomiSqlWS/useAntsomiSqlWS.js +10 -0
  126. package/es/components/organism/SQLGeneration/selectors.d.ts +857 -0
  127. package/es/components/organism/SQLGeneration/selectors.js +61 -0
  128. package/es/components/organism/SQLGeneration/store/index.d.ts +2 -0
  129. package/es/components/organism/SQLGeneration/store/index.js +1 -0
  130. package/es/components/organism/SQLGeneration/store/provider.d.ts +7 -0
  131. package/es/components/organism/SQLGeneration/store/provider.js +40 -0
  132. package/es/components/organism/SQLGeneration/store/store.d.ts +383 -0
  133. package/es/components/organism/SQLGeneration/store/store.js +309 -0
  134. package/es/components/organism/SQLGeneration/store/types.d.ts +97 -0
  135. package/es/components/organism/SQLGeneration/store/types.js +1 -0
  136. package/es/components/organism/SQLGeneration/types.d.ts +29 -0
  137. package/es/components/organism/SQLGeneration/types.js +1 -0
  138. package/es/components/organism/index.d.ts +1 -0
  139. package/es/components/organism/index.js +1 -0
  140. package/es/components/organism/index.scss +1 -0
  141. package/es/components/template/TemplateListing/hooks/useTemplateListing.d.ts +3 -4
  142. package/es/hooks/index.d.ts +1 -0
  143. package/es/hooks/index.js +1 -0
  144. package/es/hooks/useFocusManagement.d.ts +14 -0
  145. package/es/hooks/useFocusManagement.js +124 -0
  146. package/es/locales/ja/google-sheet.json +2 -2
  147. package/es/providers/ConfigProvider/ConfigProvider.js +4 -1
  148. package/es/providers/ConfigProvider/GlobalStyle.js +153 -46
  149. package/es/queries/AI/index.d.ts +23 -0
  150. package/es/queries/AI/index.js +4 -0
  151. package/es/queries/AI/useSqlGeneration.d.ts +25 -0
  152. package/es/queries/AI/useSqlGeneration.js +13 -0
  153. package/es/queries/TemplateListing/index.d.ts +2 -2
  154. package/es/queries/index.d.ts +1 -0
  155. package/es/queries/index.js +1 -0
  156. package/es/services/AI/index.d.ts +15 -0
  157. package/es/services/AI/index.js +15 -0
  158. package/es/types/auth.d.ts +25 -0
  159. package/es/types/auth.js +1 -0
  160. package/es/types/index.d.ts +1 -0
  161. package/es/types/index.js +1 -0
  162. package/es/utils/common.d.ts +1 -0
  163. package/es/utils/common.js +16 -1
  164. package/es/utils/web.d.ts +16 -3
  165. package/es/utils/web.js +36 -3
  166. package/es/utils/zustand.d.ts +10 -0
  167. package/es/utils/zustand.js +8 -0
  168. package/package.json +16 -11
@@ -0,0 +1,48 @@
1
+ export declare const SQL_GENERATION_CONSTANTS: {
2
+ readonly POPOVER_WIDTH: 600;
3
+ readonly POPOVER_MAX_WIDTH: 800;
4
+ readonly TEXTAREA_MIN_ROWS: 3;
5
+ readonly TEXTAREA_MAX_ROWS: 6;
6
+ readonly MODAL_WIDTH: 800;
7
+ readonly PLACEHOLDER_TEXTS: {
8
+ readonly PROMPT: "Enter a prompt to generate a query";
9
+ readonly SEARCH_TABLES: "Search for tables...";
10
+ readonly REFINE_PROMPT: "Refine";
11
+ readonly NO_RESULT: "No SQL generated yet";
12
+ };
13
+ readonly LOADING_TEXTS: {
14
+ readonly GENERATING: "Generating SQL...";
15
+ };
16
+ readonly RESULT_TEXTS: {
17
+ readonly PROCESSED_DATA: "This query will process {size} when run.";
18
+ };
19
+ readonly BUTTON_TEXTS: {
20
+ readonly GENERATE: "Generate";
21
+ readonly EDIT: "Edit";
22
+ readonly INSERT: "Insert";
23
+ readonly EDIT_TABLE_SOURCES: "Edit Table Sources";
24
+ readonly QUERY_SUMMARY: "Query Summary";
25
+ readonly APPLY: "Apply";
26
+ readonly CLOSE: "Close";
27
+ readonly CANCEL: "Cancel";
28
+ };
29
+ readonly TITLES: {
30
+ readonly MAIN: "Generate SQL with AI";
31
+ readonly EDIT_TABLE_SOURCES: "Edit table sources";
32
+ readonly TABLE_ASSET: "Table asset";
33
+ readonly RATING: {
34
+ readonly THUMBS_UP: "This is helpful";
35
+ readonly THUMBS_DOWN: "This is not helpful";
36
+ readonly MORE_FEEDBACK: "More feedback";
37
+ };
38
+ };
39
+ readonly MESSAGES: {
40
+ readonly LOADING: "Generating SQL...";
41
+ readonly NO_RESULT: "No SQL generated yet";
42
+ readonly PROCESSING_INFO: "This query will process {size} when run.";
43
+ readonly TABLE_SOURCES_INFO: "Metadata associated with the selected tables will be used to refine your suggestion.";
44
+ };
45
+ };
46
+ export declare const DEFAULT_RESULT_SETTINGS: {
47
+ showDiff: boolean;
48
+ };
@@ -0,0 +1,48 @@
1
+ export const SQL_GENERATION_CONSTANTS = {
2
+ POPOVER_WIDTH: 600,
3
+ POPOVER_MAX_WIDTH: 800,
4
+ TEXTAREA_MIN_ROWS: 3,
5
+ TEXTAREA_MAX_ROWS: 6,
6
+ MODAL_WIDTH: 800,
7
+ PLACEHOLDER_TEXTS: {
8
+ PROMPT: 'Enter a prompt to generate a query',
9
+ SEARCH_TABLES: 'Search for tables...',
10
+ REFINE_PROMPT: 'Refine',
11
+ NO_RESULT: 'No SQL generated yet',
12
+ },
13
+ LOADING_TEXTS: {
14
+ GENERATING: 'Generating SQL...',
15
+ },
16
+ RESULT_TEXTS: {
17
+ PROCESSED_DATA: 'This query will process {size} when run.',
18
+ },
19
+ BUTTON_TEXTS: {
20
+ GENERATE: 'Generate',
21
+ EDIT: 'Edit',
22
+ INSERT: 'Insert',
23
+ EDIT_TABLE_SOURCES: 'Edit Table Sources',
24
+ QUERY_SUMMARY: 'Query Summary',
25
+ APPLY: 'Apply',
26
+ CLOSE: 'Close',
27
+ CANCEL: 'Cancel',
28
+ },
29
+ TITLES: {
30
+ MAIN: 'Generate SQL with AI',
31
+ EDIT_TABLE_SOURCES: 'Edit table sources',
32
+ TABLE_ASSET: 'Table asset',
33
+ RATING: {
34
+ THUMBS_UP: 'This is helpful',
35
+ THUMBS_DOWN: 'This is not helpful',
36
+ MORE_FEEDBACK: 'More feedback',
37
+ },
38
+ },
39
+ MESSAGES: {
40
+ LOADING: 'Generating SQL...',
41
+ NO_RESULT: 'No SQL generated yet',
42
+ PROCESSING_INFO: 'This query will process {size} when run.',
43
+ TABLE_SOURCES_INFO: 'Metadata associated with the selected tables will be used to refine your suggestion.',
44
+ },
45
+ };
46
+ export const DEFAULT_RESULT_SETTINGS = {
47
+ showDiff: false,
48
+ };
@@ -0,0 +1 @@
1
+ export { useKeyboardNavigation, useSQLGenerationKeyboard } from './useKeyboardNavigation';
@@ -0,0 +1 @@
1
+ export { useKeyboardNavigation, useSQLGenerationKeyboard } from './useKeyboardNavigation';
@@ -0,0 +1,14 @@
1
+ export interface KeyboardNavigationOptions {
2
+ onEscape?: () => void;
3
+ onEnter?: () => void;
4
+ onCtrlEnter?: () => void;
5
+ onArrowUp?: () => void;
6
+ onArrowDown?: () => void;
7
+ onArrowLeft?: () => void;
8
+ onArrowRight?: () => void;
9
+ disabled?: boolean;
10
+ }
11
+ export declare const useKeyboardNavigation: (options?: KeyboardNavigationOptions) => {
12
+ handleKeyDown: (event: KeyboardEvent) => void;
13
+ };
14
+ export declare const useSQLGenerationKeyboard: () => void;
@@ -0,0 +1,123 @@
1
+ import { useEffect, useCallback } from 'react';
2
+ import { useSQLGenerationStore } from '../store/provider';
3
+ import { selectHasResult, selectIsEditingPrompt, selectIsRefining, selectIsLoading, } from '../selectors';
4
+ export const useKeyboardNavigation = (options = {}) => {
5
+ const { onEscape, onEnter, onCtrlEnter, onArrowUp, onArrowDown, onArrowLeft, onArrowRight, disabled = false, } = options;
6
+ const handleKeyDown = useCallback((event) => {
7
+ if (disabled)
8
+ return;
9
+ const { key, ctrlKey, metaKey, altKey, shiftKey } = event;
10
+ const isModifierPressed = ctrlKey || metaKey || altKey || shiftKey;
11
+ // Prevent handling if user is typing in an input/textarea
12
+ const target = event.target;
13
+ const isInputElement = ['INPUT', 'TEXTAREA'].includes(target.tagName) || target.contentEditable === 'true';
14
+ switch (key) {
15
+ case 'Escape':
16
+ if (onEscape) {
17
+ event.preventDefault();
18
+ onEscape();
19
+ }
20
+ break;
21
+ case 'Enter':
22
+ if ((ctrlKey || metaKey) && onCtrlEnter) {
23
+ event.preventDefault();
24
+ onCtrlEnter();
25
+ }
26
+ else if (!isModifierPressed && !isInputElement && onEnter) {
27
+ event.preventDefault();
28
+ onEnter();
29
+ }
30
+ break;
31
+ case 'ArrowUp':
32
+ if (!isInputElement && onArrowUp) {
33
+ event.preventDefault();
34
+ onArrowUp();
35
+ }
36
+ break;
37
+ case 'ArrowDown':
38
+ if (!isInputElement && onArrowDown) {
39
+ event.preventDefault();
40
+ onArrowDown();
41
+ }
42
+ break;
43
+ case 'ArrowLeft':
44
+ if (!isInputElement && onArrowLeft) {
45
+ event.preventDefault();
46
+ onArrowLeft();
47
+ }
48
+ break;
49
+ case 'ArrowRight':
50
+ if (!isInputElement && onArrowRight) {
51
+ event.preventDefault();
52
+ onArrowRight();
53
+ }
54
+ break;
55
+ default:
56
+ break;
57
+ }
58
+ }, [disabled, onEscape, onEnter, onCtrlEnter, onArrowUp, onArrowDown, onArrowLeft, onArrowRight]);
59
+ useEffect(() => {
60
+ if (disabled)
61
+ return;
62
+ document.addEventListener('keydown', handleKeyDown);
63
+ return () => {
64
+ document.removeEventListener('keydown', handleKeyDown);
65
+ };
66
+ }, [handleKeyDown, disabled]);
67
+ return { handleKeyDown };
68
+ };
69
+ // Hook for SQL Generation specific keyboard shortcuts
70
+ export const useSQLGenerationKeyboard = () => {
71
+ const hasResults = useSQLGenerationStore(selectHasResult);
72
+ const isEditingPrompt = useSQLGenerationStore(selectIsEditingPrompt);
73
+ const isRefining = useSQLGenerationStore(selectIsRefining);
74
+ const isLoading = useSQLGenerationStore(selectIsLoading);
75
+ const setIsOpen = useSQLGenerationStore(s => s.setIsOpen);
76
+ const setIsEditingPrompt = useSQLGenerationStore(s => s.setIsEditingPrompt);
77
+ const generateSQL = useSQLGenerationStore(s => s.generateSQL);
78
+ const refineSQL = useSQLGenerationStore(s => s.refineSQL);
79
+ const setCurrentResultKey = useSQLGenerationStore(s => s.setCurrentResultKey);
80
+ const resultAllKeys = useSQLGenerationStore(s => s.results.allKeys);
81
+ const currentResultKey = useSQLGenerationStore(s => s.currentResultKey);
82
+ const handleEscape = useCallback(() => {
83
+ if (isEditingPrompt) {
84
+ setIsEditingPrompt(false);
85
+ }
86
+ else {
87
+ setIsOpen(false);
88
+ }
89
+ }, [isEditingPrompt, setIsEditingPrompt, setIsOpen]);
90
+ const handleCtrlEnter = useCallback(() => {
91
+ if (isLoading)
92
+ return;
93
+ if (isRefining) {
94
+ refineSQL();
95
+ }
96
+ else if (!hasResults) {
97
+ generateSQL();
98
+ }
99
+ }, [isLoading, isRefining, hasResults, refineSQL, generateSQL]);
100
+ const handleArrowLeft = useCallback(() => {
101
+ if (hasResults && resultAllKeys.length > 1) {
102
+ const currentIndex = resultAllKeys.indexOf(currentResultKey || '');
103
+ if (currentIndex > 0) {
104
+ setCurrentResultKey(resultAllKeys[currentIndex - 1]);
105
+ }
106
+ }
107
+ }, [hasResults, resultAllKeys, currentResultKey, setCurrentResultKey]);
108
+ const handleArrowRight = useCallback(() => {
109
+ if (hasResults && resultAllKeys.length > 1) {
110
+ const currentIndex = resultAllKeys.indexOf(currentResultKey || '');
111
+ if (currentIndex < resultAllKeys.length - 1) {
112
+ setCurrentResultKey(resultAllKeys[currentIndex + 1]);
113
+ }
114
+ }
115
+ }, [hasResults, resultAllKeys, currentResultKey, setCurrentResultKey]);
116
+ useKeyboardNavigation({
117
+ onEscape: handleEscape,
118
+ onCtrlEnter: handleCtrlEnter,
119
+ onArrowLeft: handleArrowLeft,
120
+ onArrowRight: handleArrowRight,
121
+ disabled: false,
122
+ });
123
+ };
@@ -0,0 +1,10 @@
1
+ export { SQLGeneration } from './SQLGeneration';
2
+ export type { SQLGenerationProps, SQLGenerationResult, TableSource } from './types';
3
+ export { SQLGenerationProvider, useSQLGenerationStore, type SQLGenerationProviderProps, } from './store';
4
+ export declare const SQLGenerationIntegrations: {
5
+ readonly useAntsomiSqlWS: (params?: {
6
+ triggerTitle: string;
7
+ } | undefined) => {
8
+ setAceEditor: (editor: import("react-ace/lib/types").IAceEditor) => void;
9
+ };
10
+ };
@@ -0,0 +1,6 @@
1
+ import { useAntsomiSqlWS } from './integrations/AntsomiSqlWS';
2
+ export { SQLGeneration } from './SQLGeneration';
3
+ export { SQLGenerationProvider, useSQLGenerationStore, } from './store';
4
+ export const SQLGenerationIntegrations = {
5
+ useAntsomiSqlWS,
6
+ };
@@ -0,0 +1 @@
1
+ @use './integrations/AceEditor';
@@ -0,0 +1 @@
1
+ export { useEnhancePlaceholder } from './useEnhancePlaceholder';
@@ -0,0 +1 @@
1
+ export { useEnhancePlaceholder } from './useEnhancePlaceholder';
@@ -0,0 +1,4 @@
1
+ .ace-sqlgen-placeholder {
2
+ display: inline-block;
3
+ cursor: pointer;
4
+ }
@@ -0,0 +1,9 @@
1
+ import type { IAceEditor } from 'react-ace/lib/types';
2
+ export type Params = {
3
+ triggerTitle?: string;
4
+ maxRetries?: number;
5
+ baseDelay?: number;
6
+ };
7
+ export declare const useAceEditor: (params?: Params) => {
8
+ setAceEditor: (editor: IAceEditor) => void;
9
+ };
@@ -0,0 +1,24 @@
1
+ import { useCallback } from 'react';
2
+ import { useEnhancePlaceholder } from './useEnhancePlaceholder';
3
+ import { useInsertQuery } from './useInsertQuery';
4
+ import { useSQLGenerationStore } from '../../store';
5
+ export const useAceEditor = (params) => {
6
+ const setIsOpen = useSQLGenerationStore(s => s.setIsOpen);
7
+ const resetStore = useSQLGenerationStore(s => s.reset);
8
+ const { setAceEditor: setAceEditorForPlaceholder } = useEnhancePlaceholder({
9
+ triggerTitle: params?.triggerTitle,
10
+ maxRetries: params?.maxRetries,
11
+ baseDelay: params?.baseDelay,
12
+ });
13
+ const { setAceEditor: setAceEditorForInsertQuery } = useInsertQuery({
14
+ onInsertQueryDone: () => {
15
+ setIsOpen(false);
16
+ resetStore();
17
+ },
18
+ });
19
+ const setAceEditor = useCallback((editor) => {
20
+ setAceEditorForPlaceholder(editor);
21
+ setAceEditorForInsertQuery(editor);
22
+ }, [setAceEditorForPlaceholder, setAceEditorForInsertQuery]);
23
+ return { setAceEditor };
24
+ };
@@ -0,0 +1,10 @@
1
+ import type { IAceEditor } from 'react-ace/lib/types';
2
+ type Params = {
3
+ triggerTitle?: string;
4
+ maxRetries?: number;
5
+ baseDelay?: number;
6
+ };
7
+ export declare const useEnhancePlaceholder: (params?: Params) => {
8
+ setAceEditor: (editor: IAceEditor) => void;
9
+ };
10
+ export {};
@@ -0,0 +1,172 @@
1
+ import { useCallback, useRef, useEffect } from 'react';
2
+ import { useUnmount } from '@antscorp/antsomi-ui/es/hooks';
3
+ import { useSQLGenerationStore } from '../../store';
4
+ export const useEnhancePlaceholder = (params) => {
5
+ const { triggerTitle = 'generate SQL with AI', maxRetries = 5, baseDelay = 100 } = params || {};
6
+ const timeoutRef = useRef();
7
+ const mutationObserverRef = useRef(null);
8
+ const editorRef = useRef(null);
9
+ const placeholderRef = useRef(null);
10
+ const triggerRef = useRef(null);
11
+ const retryCountRef = useRef(0);
12
+ const isDestroyedRef = useRef(false);
13
+ const setModalSqlGenerationOpen = useSQLGenerationStore(state => state.setIsOpen);
14
+ const syncPlaceholderEl = useCallback((editor) => {
15
+ if (isDestroyedRef.current)
16
+ return false;
17
+ const selectedEl = editor.renderer.container.querySelector('.ace_placeholder');
18
+ if (selectedEl && selectedEl instanceof HTMLDivElement) {
19
+ placeholderRef.current = selectedEl;
20
+ return true;
21
+ }
22
+ return false;
23
+ }, []);
24
+ const waitForPlaceholder = useCallback((editor, retryCount = 0) => new Promise(resolve => {
25
+ if (isDestroyedRef.current) {
26
+ resolve(null);
27
+ return;
28
+ }
29
+ // Try to find placeholder immediately
30
+ if (syncPlaceholderEl(editor)) {
31
+ resolve(placeholderRef.current);
32
+ return;
33
+ }
34
+ // If max retries reached, resolve with null
35
+ if (retryCount >= maxRetries) {
36
+ // eslint-disable-next-line no-console
37
+ console.warn(`AceEditor placeholder not found after ${maxRetries} retries`);
38
+ resolve(null);
39
+ return;
40
+ }
41
+ // Use exponential backoff: baseDelay * 2^retryCount
42
+ const delay = baseDelay * 2 ** retryCount;
43
+ timeoutRef.current = setTimeout(() => {
44
+ if (isDestroyedRef.current) {
45
+ resolve(null);
46
+ return;
47
+ }
48
+ waitForPlaceholder(editor, retryCount + 1).then(resolve);
49
+ }, delay);
50
+ }), [syncPlaceholderEl, maxRetries, baseDelay]);
51
+ const updatePlaceholderVisibility = useCallback(async (forceWait = false) => {
52
+ const editor = editorRef.current;
53
+ if (!editor || isDestroyedRef.current)
54
+ return;
55
+ // If placeholder not found and we need to wait for it
56
+ if (!placeholderRef.current || forceWait) {
57
+ clearTimeout(timeoutRef.current);
58
+ const placeholder = await waitForPlaceholder(editor, 0);
59
+ if (!placeholder || isDestroyedRef.current)
60
+ return;
61
+ }
62
+ if (!placeholderRef.current)
63
+ return;
64
+ const content = editor.session.getValue();
65
+ const isEmpty = content.length === 0;
66
+ const appendTriggerEl = (placeholderEl) => {
67
+ // Avoid duplicate triggers
68
+ if (triggerRef.current && placeholderEl.contains(triggerRef.current)) {
69
+ return;
70
+ }
71
+ let triggerEl;
72
+ if (triggerRef.current) {
73
+ triggerEl = triggerRef.current;
74
+ }
75
+ else {
76
+ triggerEl = document.createElement('span');
77
+ triggerRef.current = triggerEl;
78
+ }
79
+ triggerEl.classList.add('ace-sqlgen-placeholder');
80
+ triggerEl.innerHTML = ` or <u class='trigger-title'>${triggerTitle}</u>`;
81
+ triggerEl.addEventListener('click', () => {
82
+ setModalSqlGenerationOpen(true);
83
+ });
84
+ placeholderEl.appendChild(triggerEl);
85
+ };
86
+ if (isEmpty && placeholderRef.current) {
87
+ appendTriggerEl(placeholderRef.current);
88
+ }
89
+ if (!isEmpty && triggerRef.current) {
90
+ triggerRef.current.remove();
91
+ triggerRef.current = null;
92
+ }
93
+ }, [setModalSqlGenerationOpen, triggerTitle, waitForPlaceholder]);
94
+ // Setup MutationObserver to watch for DOM changes
95
+ const setupMutationObserver = useCallback((editor) => {
96
+ if (mutationObserverRef.current) {
97
+ mutationObserverRef.current.disconnect();
98
+ }
99
+ mutationObserverRef.current = new MutationObserver(mutations => {
100
+ if (isDestroyedRef.current)
101
+ return;
102
+ let shouldUpdate = false;
103
+ mutations.forEach(mutation => {
104
+ // Check if placeholder-related nodes were added/removed
105
+ if (mutation.type === 'childList') {
106
+ const addedNodes = Array.from(mutation.addedNodes);
107
+ const removedNodes = Array.from(mutation.removedNodes);
108
+ const hasPlaceholderChanges = [...addedNodes, ...removedNodes].some(node => node instanceof Element &&
109
+ (node.classList?.contains('ace_placeholder') ||
110
+ node.querySelector?.('.ace_placeholder')));
111
+ if (hasPlaceholderChanges) {
112
+ shouldUpdate = true;
113
+ }
114
+ }
115
+ });
116
+ if (shouldUpdate) {
117
+ // Small delay to ensure DOM is stable
118
+ setTimeout(() => {
119
+ if (!isDestroyedRef.current) {
120
+ updatePlaceholderVisibility(true);
121
+ }
122
+ }, 50);
123
+ }
124
+ });
125
+ // Observe the editor container for changes
126
+ mutationObserverRef.current.observe(editor.renderer.container, {
127
+ childList: true,
128
+ subtree: true,
129
+ });
130
+ }, [updatePlaceholderVisibility]);
131
+ const setAceEditorRef = useCallback((editor) => {
132
+ if (isDestroyedRef.current)
133
+ return;
134
+ editorRef.current = editor;
135
+ retryCountRef.current = 0;
136
+ // Setup mutation observer to watch for DOM changes
137
+ setupMutationObserver(editor);
138
+ // Initial placeholder setup
139
+ updatePlaceholderVisibility(true);
140
+ const eventCb = () => {
141
+ if (!isDestroyedRef.current) {
142
+ updatePlaceholderVisibility();
143
+ }
144
+ };
145
+ editor.on('change', eventCb);
146
+ editor.on('blur', eventCb);
147
+ editor.on('focus', eventCb);
148
+ }, [updatePlaceholderVisibility, setupMutationObserver]);
149
+ // Cleanup function
150
+ const cleanup = useCallback(() => {
151
+ isDestroyedRef.current = true;
152
+ clearTimeout(timeoutRef.current);
153
+ if (mutationObserverRef.current) {
154
+ mutationObserverRef.current.disconnect();
155
+ mutationObserverRef.current = null;
156
+ }
157
+ if (triggerRef.current) {
158
+ triggerRef.current.remove();
159
+ triggerRef.current = null;
160
+ }
161
+ placeholderRef.current = null;
162
+ editorRef.current = null;
163
+ }, []);
164
+ useUnmount(cleanup);
165
+ // Also cleanup on component re-render if needed
166
+ useEffect(() => () => {
167
+ if (isDestroyedRef.current) {
168
+ cleanup();
169
+ }
170
+ }, [cleanup]);
171
+ return { setAceEditor: setAceEditorRef };
172
+ };
@@ -0,0 +1,8 @@
1
+ import type { IAceEditor } from 'react-ace/lib/types';
2
+ type Params = {
3
+ onInsertQueryDone?: () => void;
4
+ };
5
+ export declare const useInsertQuery: (params?: Params) => {
6
+ setAceEditor: (editor: IAceEditor) => void;
7
+ };
8
+ export {};
@@ -0,0 +1,21 @@
1
+ import { useCallback, useRef } from 'react';
2
+ import { useSQLGenerationStore } from '../../store';
3
+ export const useInsertQuery = (params) => {
4
+ const { onInsertQueryDone } = params || {};
5
+ const editorRef = useRef(null);
6
+ const setState = useSQLGenerationStore(s => s.setState);
7
+ const setAceEditorRef = useCallback((editor) => {
8
+ editorRef.current = editor;
9
+ setState({
10
+ onInsertSQL: sql => {
11
+ const content = editor.session.getValue();
12
+ const isEmpty = content.length === 0;
13
+ if (isEmpty) {
14
+ editor.insert(sql);
15
+ onInsertQueryDone?.();
16
+ }
17
+ },
18
+ });
19
+ }, [setState, onInsertQueryDone]);
20
+ return { setAceEditor: setAceEditorRef };
21
+ };
@@ -0,0 +1 @@
1
+ export { useAntsomiAI } from './useAntsomiAI';
@@ -0,0 +1 @@
1
+ export { useAntsomiAI } from './useAntsomiAI';
@@ -0,0 +1 @@
1
+ export declare const useAntsomiAI: () => void;
@@ -0,0 +1,35 @@
1
+ import { useAppConfigContext } from '@antscorp/antsomi-ui/es/providers';
2
+ import { useSQLGenerationStore } from '../../store';
3
+ import { AntsomiAIQueries } from '@antscorp/antsomi-ui/es/queries/AI';
4
+ import { useEffect } from 'react';
5
+ export const useAntsomiAI = () => {
6
+ const setState = useSQLGenerationStore(s => s.setState);
7
+ const { appConfig } = useAppConfigContext();
8
+ const { generateSQLAsync } = AntsomiAIQueries.useSqlGeneration({
9
+ env: appConfig.env || 'production',
10
+ auth: {
11
+ token: appConfig.auth?.token || '',
12
+ userId: +(appConfig.auth?.userId || 0),
13
+ accountId: +(appConfig.auth?.accountId || 0),
14
+ portalId: +(appConfig.auth?.portalId || 0),
15
+ },
16
+ });
17
+ useEffect(() => {
18
+ setState({
19
+ onGenerateSQL: async (prompt, context) => {
20
+ const data = await generateSQLAsync({
21
+ prompt,
22
+ selected_tables: context.selectedTables,
23
+ history: {
24
+ pass_turns: context.history.pastTurns,
25
+ },
26
+ });
27
+ const generationResult = {
28
+ ...data,
29
+ sqlSuggestion: data.sql_suggestion,
30
+ };
31
+ return generationResult;
32
+ },
33
+ });
34
+ }, [generateSQLAsync, setState]);
35
+ };
@@ -0,0 +1 @@
1
+ export { useAntsomiSqlWS } from './useAntsomiSqlWS';
@@ -0,0 +1 @@
1
+ export { useAntsomiSqlWS } from './useAntsomiSqlWS';
@@ -0,0 +1,7 @@
1
+ type Params = {
2
+ triggerTitle: string;
3
+ };
4
+ export declare const useAntsomiSqlWS: (params?: Params) => {
5
+ setAceEditor: (editor: import("react-ace/lib/types").IAceEditor) => void;
6
+ };
7
+ export {};
@@ -0,0 +1,10 @@
1
+ import { useAceEditor } from '../AceEditor/useAceEditor';
2
+ import { useAntsomiAI } from '../AntsomiAI';
3
+ export const useAntsomiSqlWS = (params) => {
4
+ const { triggerTitle } = params || {};
5
+ const { setAceEditor } = useAceEditor({
6
+ triggerTitle,
7
+ });
8
+ useAntsomiAI();
9
+ return { setAceEditor };
10
+ };