@antscorp/antsomi-ui 2.0.103 → 2.0.104

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 +15 -10
@@ -0,0 +1,309 @@
1
+ import { createStore } from 'zustand';
2
+ import { immer } from 'zustand/middleware/immer';
3
+ import { devtools } from 'zustand/middleware';
4
+ import { selectAllPreviousResults, selectCurrentResult, selectCurrentResultIndex, selectCurrentResultSettings, selectSelctedTableSources, } from '../selectors';
5
+ import { pick } from 'lodash';
6
+ import { DEFAULT_RESULT_SETTINGS } from '../constants';
7
+ import produce from 'immer';
8
+ import { createContext } from 'react';
9
+ export const createSQLGenerationStore = (initProps) => {
10
+ const DEFAULT_PROPS = {
11
+ abortControllers: {},
12
+ isOpen: false,
13
+ isLoading: false,
14
+ isEditTableSourcesOpen: false,
15
+ isSummaryLoading: false,
16
+ isEditingPrompt: false,
17
+ isRefining: false,
18
+ currentResultKey: null,
19
+ prompt: '',
20
+ refinePrompt: '',
21
+ results: {
22
+ byKey: {},
23
+ byKeySettings: {},
24
+ allKeys: [],
25
+ },
26
+ tableSources: [],
27
+ searchQuery: '',
28
+ error: null,
29
+ generateSQLError: null,
30
+ refineSQLError: null,
31
+ querySummaryError: null,
32
+ ...initProps,
33
+ };
34
+ return createStore()(devtools(immer((set, get, store) => ({
35
+ ...DEFAULT_PROPS,
36
+ setIsOpen: isOpen => {
37
+ set({ isOpen });
38
+ get().onOpenChange?.(isOpen);
39
+ },
40
+ setIsLoading: isLoading => set({ isLoading }),
41
+ setIsSummaryLoading: isSummaryLoading => set({ isSummaryLoading }),
42
+ setIsEditTableSourcesOpen: isEditTableSourcesOpen => set({ isEditTableSourcesOpen }),
43
+ setIsEditingPrompt: isEditingPrompt => set({ isEditingPrompt }),
44
+ setCurrentResultKey: newKey => {
45
+ if (newKey !== get().currentResultKey) {
46
+ get().abortQuerySummary();
47
+ get().abortGenerateSQL();
48
+ set({ isEditingPrompt: false });
49
+ }
50
+ set(state => {
51
+ state.currentResultKey = newKey;
52
+ });
53
+ },
54
+ setPrompt: prompt => set({ prompt }),
55
+ setResults: results => set({ results }),
56
+ setTableSources: tableSources => set({ tableSources }),
57
+ setSearchQuery: searchQuery => set({ searchQuery }),
58
+ generateSQL: async () => {
59
+ const { onGenerateSQL, prompt, setIsLoading, setGenerateSQLError } = get();
60
+ if (!onGenerateSQL)
61
+ return;
62
+ const selectedTables = selectSelctedTableSources(get());
63
+ const pastTurns = selectAllPreviousResults(get());
64
+ const controller = new AbortController();
65
+ // Clear previous errors
66
+ setGenerateSQLError(null);
67
+ setIsLoading(true);
68
+ set(state => {
69
+ state.abortControllers.generateSQL = controller;
70
+ });
71
+ try {
72
+ const sqlResult = await onGenerateSQL(prompt, {
73
+ selectedTables,
74
+ history: { pastTurns },
75
+ }, {
76
+ signal: controller.signal,
77
+ });
78
+ const currentResultIndex = selectCurrentResultIndex(get());
79
+ const prevCurrentResultSettings = selectCurrentResultSettings(get());
80
+ if (currentResultIndex !== -1) {
81
+ // remove from current results and insert new result
82
+ set(state => {
83
+ state.results.allKeys.splice(currentResultIndex);
84
+ state.results.byKey = pick(state.results.byKey, state.results.allKeys);
85
+ state.results.byKeySettings = pick(state.results.byKeySettings, state.results.allKeys);
86
+ });
87
+ }
88
+ set(state => {
89
+ state.prompt = '';
90
+ state.results.allKeys.push(sqlResult.key);
91
+ state.results.byKey[sqlResult.key] = sqlResult;
92
+ state.results.byKeySettings[sqlResult.key] =
93
+ prevCurrentResultSettings || DEFAULT_RESULT_SETTINGS;
94
+ state.currentResultKey = sqlResult.key;
95
+ });
96
+ }
97
+ catch (error) {
98
+ if (controller.signal.aborted)
99
+ return;
100
+ // eslint-disable-next-line no-console
101
+ console.error('Failed to generate SQL:', error);
102
+ // Set error state
103
+ const errorMessage = error instanceof Error ? error.message : 'Failed to generate SQL';
104
+ setGenerateSQLError({
105
+ message: errorMessage,
106
+ code: 'GENERATE_SQL_ERROR',
107
+ timestamp: Date.now(),
108
+ operation: 'generateSQL',
109
+ });
110
+ }
111
+ finally {
112
+ setIsLoading(false);
113
+ set(state => {
114
+ state.abortControllers.generateSQL = undefined;
115
+ });
116
+ }
117
+ },
118
+ insertSQL: () => {
119
+ const { onInsertSQL, results, currentResultKey } = get();
120
+ if (!currentResultKey)
121
+ return;
122
+ const currentSql = results.byKey[currentResultKey].sqlSuggestion;
123
+ if (onInsertSQL && currentSql) {
124
+ onInsertSQL(currentSql);
125
+ }
126
+ },
127
+ querySummary: async () => {
128
+ const { onQuerySummary, results, currentResultKey, setIsSummaryLoading, setQuerySummaryError, } = get();
129
+ const controller = new AbortController();
130
+ try {
131
+ if (!currentResultKey)
132
+ return;
133
+ const currentSql = results.byKey[currentResultKey].sqlSuggestion;
134
+ if (!onQuerySummary || !currentSql)
135
+ return;
136
+ // Clear previous errors
137
+ setQuerySummaryError(null);
138
+ setIsSummaryLoading(true);
139
+ set(state => {
140
+ state.abortControllers.querySummary = controller;
141
+ });
142
+ const summarySqlResult = await onQuerySummary(currentSql, {
143
+ signal: controller.signal,
144
+ });
145
+ set(state => {
146
+ const currentResult = state.results.byKey[currentResultKey];
147
+ if (currentResult) {
148
+ currentResult.summary = summarySqlResult;
149
+ }
150
+ });
151
+ }
152
+ catch (error) {
153
+ if (controller.signal.aborted)
154
+ return;
155
+ // eslint-disable-next-line no-console
156
+ console.error('Failed to generate query summary:', error);
157
+ // Set error state
158
+ const errorMessage = error instanceof Error ? error.message : 'Failed to generate query summary';
159
+ setQuerySummaryError({
160
+ message: errorMessage,
161
+ code: 'QUERY_SUMMARY_ERROR',
162
+ timestamp: Date.now(),
163
+ operation: 'querySummary',
164
+ });
165
+ }
166
+ finally {
167
+ setIsSummaryLoading(false);
168
+ set(state => {
169
+ state.abortControllers.querySummary = undefined;
170
+ });
171
+ }
172
+ },
173
+ abortGenerateSQL: () => {
174
+ const { abortControllers, setIsLoading } = get();
175
+ abortControllers.generateSQL?.abort();
176
+ setIsLoading(false);
177
+ },
178
+ abortQuerySummary: () => {
179
+ const { abortControllers, setIsSummaryLoading } = get();
180
+ abortControllers.querySummary?.abort();
181
+ setIsSummaryLoading(false);
182
+ },
183
+ abortRefineSQL: () => {
184
+ const { abortControllers, setIsRefining } = get();
185
+ abortControllers.refineSQL?.abort();
186
+ setIsRefining(false);
187
+ },
188
+ refineSQL: async () => {
189
+ const { setIsRefining, setRefineSQLError } = get();
190
+ const onRefineSQL = get().onRefineSQL || get().onGenerateSQL;
191
+ const currentResult = selectCurrentResult(get());
192
+ const previousResults = selectAllPreviousResults(get());
193
+ if (!onRefineSQL || !currentResult)
194
+ return;
195
+ const pastTurns = [...previousResults, currentResult];
196
+ const controller = new AbortController();
197
+ try {
198
+ // Clear previous errors
199
+ setRefineSQLError(null);
200
+ setIsRefining(true);
201
+ set(state => {
202
+ state.abortControllers.refineSQL = controller;
203
+ // update current result refine prompt
204
+ state.results.byKey[currentResult.key].refinePrompt = get().refinePrompt;
205
+ });
206
+ const refineResult = await onRefineSQL(get().refinePrompt, {
207
+ selectedTables: selectSelctedTableSources(get()),
208
+ history: { pastTurns },
209
+ }, {
210
+ signal: controller.signal,
211
+ });
212
+ const currentResultIndex = selectCurrentResultIndex(get());
213
+ set(state => {
214
+ // remove all results after current result
215
+ state.results.allKeys.splice(currentResultIndex + 1);
216
+ state.results.allKeys.push(refineResult.key);
217
+ state.results.byKey = pick(state.results.byKey, state.results.allKeys);
218
+ state.results.byKeySettings = pick(state.results.byKeySettings, state.results.allKeys);
219
+ // update refine result
220
+ state.results.byKey[refineResult.key] = refineResult;
221
+ state.results.byKeySettings[refineResult.key] = DEFAULT_RESULT_SETTINGS;
222
+ state.refinePrompt = '';
223
+ state.currentResultKey = refineResult.key;
224
+ });
225
+ }
226
+ catch (error) {
227
+ if (controller.signal.aborted)
228
+ return;
229
+ // eslint-disable-next-line no-console
230
+ console.error('Failed to refine SQL:', error);
231
+ // Set error state
232
+ const errorMessage = error instanceof Error ? error.message : 'Failed to refine SQL';
233
+ setRefineSQLError({
234
+ message: errorMessage,
235
+ code: 'REFINE_SQL_ERROR',
236
+ timestamp: Date.now(),
237
+ operation: 'refineSQL',
238
+ });
239
+ }
240
+ finally {
241
+ setIsRefining(false);
242
+ set(state => {
243
+ state.abortControllers.refineSQL = undefined;
244
+ });
245
+ }
246
+ },
247
+ setRefinePrompt: refinePrompt => set({ refinePrompt }),
248
+ setIsRefining: isRefining => set({ isRefining }),
249
+ setCurrentResultSettings: updateFn => {
250
+ const { currentResultKey } = get();
251
+ if (!currentResultKey)
252
+ return;
253
+ set(state => {
254
+ const updated = produce(state.results.byKeySettings[currentResultKey], updateFn);
255
+ state.results.byKeySettings[currentResultKey] = updated;
256
+ });
257
+ },
258
+ // Error actions
259
+ setError: error => set({ error }),
260
+ setGenerateSQLError: generateSQLError => set({ generateSQLError }),
261
+ setRefineSQLError: refineSQLError => set({ refineSQLError }),
262
+ setQuerySummaryError: querySummaryError => set({ querySummaryError }),
263
+ clearErrors: () => set({
264
+ error: null,
265
+ generateSQLError: null,
266
+ refineSQLError: null,
267
+ querySummaryError: null,
268
+ }),
269
+ clearError: operation => {
270
+ switch (operation) {
271
+ case 'generateSQL':
272
+ set({ generateSQLError: null });
273
+ break;
274
+ case 'refineSQL':
275
+ set({ refineSQLError: null });
276
+ break;
277
+ case 'querySummary':
278
+ set({ querySummaryError: null });
279
+ break;
280
+ default:
281
+ break;
282
+ }
283
+ },
284
+ // Retry actions
285
+ retryGenerateSQL: async () => {
286
+ const { generateSQL, clearError } = get();
287
+ clearError('generateSQL');
288
+ return generateSQL();
289
+ },
290
+ retryRefineSQL: async () => {
291
+ const { refineSQL, clearError } = get();
292
+ clearError('refineSQL');
293
+ return refineSQL();
294
+ },
295
+ retryQuerySummary: async () => {
296
+ const { querySummary, clearError } = get();
297
+ clearError('querySummary');
298
+ return querySummary();
299
+ },
300
+ setState: nextStateOrUpdater => set(nextStateOrUpdater),
301
+ reset: () => {
302
+ set(store.getInitialState());
303
+ },
304
+ })), {
305
+ name: 'SQLGenerationStore',
306
+ enabled: initProps?.env !== 'production',
307
+ }));
308
+ };
309
+ export const SQLGenerationContext = createContext(undefined);
@@ -0,0 +1,97 @@
1
+ import { SQLGenerationContext, SQLGenerationResult, TableSource } from '../types';
2
+ import { Draft } from 'immer';
3
+ export interface SQLResultSettings {
4
+ showDiff: boolean;
5
+ }
6
+ export interface SQLResults {
7
+ byKey: Record<string, SQLGenerationResult>;
8
+ byKeySettings: Record<string, SQLResultSettings>;
9
+ allKeys: string[];
10
+ }
11
+ export interface SQLGenerationError {
12
+ message: string;
13
+ code?: string;
14
+ timestamp: number;
15
+ operation: 'generateSQL' | 'refineSQL' | 'querySummary';
16
+ }
17
+ export interface SQLGenerationState {
18
+ abortControllers: {
19
+ generateSQL?: AbortController;
20
+ querySummary?: AbortController;
21
+ refineSQL?: AbortController;
22
+ };
23
+ isOpen: boolean;
24
+ isLoading: boolean;
25
+ isRefining: boolean;
26
+ isSummaryLoading: boolean;
27
+ isEditTableSourcesOpen: boolean;
28
+ isEditingPrompt: boolean;
29
+ currentResultKey: string | null;
30
+ error: SQLGenerationError | null;
31
+ generateSQLError: SQLGenerationError | null;
32
+ refineSQLError: SQLGenerationError | null;
33
+ querySummaryError: SQLGenerationError | null;
34
+ prompt: string;
35
+ refinePrompt: string;
36
+ tableSources: TableSource[];
37
+ searchQuery: string;
38
+ results: SQLResults;
39
+ onGenerateSQL?: (prompt: string, context: SQLGenerationContext, options: {
40
+ signal: AbortSignal;
41
+ }) => Promise<SQLGenerationResult>;
42
+ onRefineSQL?: (refinePrompt: string, context: SQLGenerationContext, options: {
43
+ signal: AbortSignal;
44
+ }) => Promise<SQLGenerationResult>;
45
+ onInsertSQL?: (sql: string) => void;
46
+ onQuerySummary?: (sql: string, options: {
47
+ signal: AbortSignal;
48
+ }) => Promise<string>;
49
+ onOpenChange?: (open: boolean) => void;
50
+ }
51
+ export interface SQLGenerationActions {
52
+ setState: (update: Partial<SQLGenerationState>) => void;
53
+ reset: () => void;
54
+ setIsOpen: (isOpen: boolean) => void;
55
+ setIsLoading: (isLoading: boolean) => void;
56
+ setIsSummaryLoading: (isLoading: boolean) => void;
57
+ setIsEditTableSourcesOpen: (isOpen: boolean) => void;
58
+ setIsEditingPrompt: (isEditing: boolean) => void;
59
+ setCurrentResultKey: (key: string) => void;
60
+ setPrompt: (prompt: string) => void;
61
+ setResults: (results: SQLResults) => void;
62
+ setTableSources: (sources: TableSource[]) => void;
63
+ setSearchQuery: (query: string) => void;
64
+ setRefinePrompt: (prompt: string) => void;
65
+ setIsRefining: (isRefining: boolean) => void;
66
+ setCurrentResultSettings: (updateFn: (draft: Draft<SQLResultSettings>) => void) => void;
67
+ setError: (error: SQLGenerationError | null) => void;
68
+ setGenerateSQLError: (error: SQLGenerationError | null) => void;
69
+ setRefineSQLError: (error: SQLGenerationError | null) => void;
70
+ setQuerySummaryError: (error: SQLGenerationError | null) => void;
71
+ clearErrors: () => void;
72
+ clearError: (operation: SQLGenerationError['operation']) => void;
73
+ generateSQL: () => Promise<void>;
74
+ insertSQL: () => void;
75
+ querySummary: () => Promise<void>;
76
+ refineSQL: () => Promise<void>;
77
+ abortGenerateSQL: () => void;
78
+ abortQuerySummary: () => void;
79
+ abortRefineSQL: () => void;
80
+ retryGenerateSQL: () => Promise<void>;
81
+ retryRefineSQL: () => Promise<void>;
82
+ retryQuerySummary: () => Promise<void>;
83
+ }
84
+ export type SQLGenerationStore = SQLGenerationState & SQLGenerationActions;
85
+ export type SQLGenerationStoreInitialProps = {
86
+ env?: 'production' | 'staging' | 'development';
87
+ onGenerateSQL?: (prompt: string, context: SQLGenerationContext, options: {
88
+ signal: AbortSignal;
89
+ }) => Promise<SQLGenerationResult>;
90
+ onRefineSQL?: (refinePrompt: string, context: SQLGenerationContext, options: {
91
+ signal: AbortSignal;
92
+ }) => Promise<SQLGenerationResult>;
93
+ onInsertSQL?: (sql: string) => void;
94
+ onQuerySummary?: (sql: string, options: {
95
+ signal: AbortSignal;
96
+ }) => Promise<string>;
97
+ };
@@ -0,0 +1,29 @@
1
+ export interface TableSource {
2
+ id: string;
3
+ name: string;
4
+ dataset: string;
5
+ project: string;
6
+ selected: boolean;
7
+ }
8
+ export interface SQLGenerationResult {
9
+ key: string;
10
+ prompt: string;
11
+ sqlSuggestion: string;
12
+ summary?: string;
13
+ refinePrompt?: string;
14
+ explanation?: string;
15
+ processedDataSize?: string;
16
+ estimatedCost?: string;
17
+ queryComplexity?: 'simple' | 'medium' | 'complex';
18
+ }
19
+ export interface SQLGenerationContext {
20
+ selectedTables: TableSource[];
21
+ history: {
22
+ pastTurns: SQLGenerationResult[];
23
+ };
24
+ }
25
+ export interface SQLGenerationProps {
26
+ tableSources?: TableSource[];
27
+ isOpen?: boolean;
28
+ onOpenChange?: (open: boolean) => void;
29
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -16,4 +16,5 @@ export * from './Login';
16
16
  export * from './BasicLogin';
17
17
  export * from './Filter';
18
18
  export { ActivityTimeline, type ActivityTimeLineProps } from './ActivityTimeline';
19
+ export { SQLGeneration, SQLGenerationIntegrations, SQLGenerationProvider, useSQLGenerationStore, type SQLGenerationProps, type SQLGenerationProviderProps, } from './SQLGeneration';
19
20
  export { WhatsappMobile, SAMPLE_PREVIEW } from './PreviewCollections';
@@ -16,4 +16,5 @@ export * from './Login';
16
16
  export * from './BasicLogin';
17
17
  export * from './Filter';
18
18
  export { ActivityTimeline } from './ActivityTimeline';
19
+ export { SQLGeneration, SQLGenerationIntegrations, SQLGenerationProvider, useSQLGenerationStore, } from './SQLGeneration';
19
20
  export { WhatsappMobile, SAMPLE_PREVIEW } from './PreviewCollections';
@@ -0,0 +1 @@
1
+ @use './SQLGeneration';
@@ -1,10 +1,9 @@
1
1
  /// <reference types="react" />
2
- import { ResponseListing, TServiceAuth } from '@antscorp/antsomi-ui/es/types';
2
+ import { TServiceAuth } from '@antscorp/antsomi-ui/es/types';
3
3
  import { TCategoryItem, TCheckedCategories, TSelectTemplateAction, TTemplateItem } from '../types';
4
4
  import { TTemplateListingConfig } from '@antscorp/antsomi-ui/es/types/templateListing';
5
5
  import { TThumbnailCardId } from '../../../molecules/ThumbnailCard';
6
6
  import { InfiniteData } from '@tanstack/react-query';
7
- import { ObjectTemplate } from '@antscorp/antsomi-ui/es/models/ObjectTemplate';
8
7
  import { TemplateCategory } from '@antscorp/antsomi-ui/es/models/TemplateCategory';
9
8
  interface TemplateListingOptions {
10
9
  serviceAuth: TServiceAuth;
@@ -62,7 +61,7 @@ export declare const useTemplateListing: <T = undefined>(options: TemplateListin
62
61
  templateItems: (TTemplateItem | undefined)[];
63
62
  openCategoryKeys: string[];
64
63
  similarTemplates: (TTemplateItem | undefined)[];
65
- templateDetail: ObjectTemplate | undefined;
64
+ templateDetail: any;
66
65
  checkedCategories: TCheckedCategories;
67
66
  selectTemplateAction: string | T | undefined;
68
67
  previewTemplateCategories: TCategoryItem[];
@@ -71,7 +70,7 @@ export declare const useTemplateListing: <T = undefined>(options: TemplateListin
71
70
  isLoadingTemplateList: boolean;
72
71
  isLoadingTemplateDetail: boolean;
73
72
  refetchCategoryList: <TPageData>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<TemplateCategory[], any>>;
74
- refetchTemplateList: <TPageData_1>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData_1>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<InfiniteData<ResponseListing<ObjectTemplate>>, any>>;
73
+ refetchTemplateList: <TPageData_1>(options?: (import("@tanstack/react-query").RefetchOptions & import("@tanstack/react-query").RefetchQueryFilters<TPageData_1>) | undefined) => Promise<import("@tanstack/react-query").QueryObserverResult<InfiniteData<any>, any>>;
75
74
  onChangeCheckedCategories: (checkedCategories: TCheckedCategories) => void;
76
75
  onChangeOpenCategoryKeys: (openKeys: string[]) => void;
77
76
  onRemoveObjectTemplate: (id: TThumbnailCardId) => void;
@@ -26,4 +26,5 @@ export * from './useCustomRouter';
26
26
  export * from './useUpdateEffect';
27
27
  export * from './useOutsideClick';
28
28
  export * from './useDebouncedCallbackV2';
29
+ export * from './useFocusManagement';
29
30
  export * from './useCountdown';
package/es/hooks/index.js CHANGED
@@ -45,4 +45,5 @@ export * from './useCustomRouter';
45
45
  export * from './useUpdateEffect';
46
46
  export * from './useOutsideClick';
47
47
  export * from './useDebouncedCallbackV2';
48
+ export * from './useFocusManagement';
48
49
  export * from './useCountdown';
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ export interface FocusManagementOptions {
3
+ autoFocus?: boolean;
4
+ restoreFocus?: boolean;
5
+ trapFocus?: boolean;
6
+ }
7
+ export declare const useFocusManagement: (isOpen: boolean, options?: FocusManagementOptions) => {
8
+ containerRef: import("react").RefObject<HTMLDivElement>;
9
+ };
10
+ export declare const useComponentFocus: () => {
11
+ focusElement: (selector: string, delay?: number) => void;
12
+ focusFirstInput: (container?: HTMLElement, delay?: number) => void;
13
+ focusButton: (text: string, delay?: number) => void;
14
+ };
@@ -0,0 +1,124 @@
1
+ import { useEffect, useRef, useCallback } from 'react';
2
+ // Helper function to get all focusable elements
3
+ const getFocusableElements = (container) => {
4
+ const focusableSelectors = [
5
+ 'button:not([disabled])',
6
+ 'input:not([disabled])',
7
+ 'textarea:not([disabled])',
8
+ 'select:not([disabled])',
9
+ 'a[href]',
10
+ '[tabindex]:not([tabindex="-1"])',
11
+ '[contenteditable="true"]',
12
+ ].join(', ');
13
+ const focusableEls = [];
14
+ Array.from(container.querySelectorAll(focusableSelectors)).forEach(element => {
15
+ if (!(element instanceof HTMLElement))
16
+ return false;
17
+ if (element.offsetWidth > 0 &&
18
+ element.offsetHeight > 0 &&
19
+ !element.hidden &&
20
+ window.getComputedStyle(element).visibility !== 'hidden') {
21
+ focusableEls.push(element);
22
+ }
23
+ });
24
+ return focusableEls;
25
+ };
26
+ export const useFocusManagement = (isOpen, options = {}) => {
27
+ const { autoFocus = true, restoreFocus = true, trapFocus = true } = options;
28
+ const containerRef = useRef(null);
29
+ const previousActiveElementRef = useRef(null);
30
+ // Store the previously focused element when modal opens
31
+ useEffect(() => {
32
+ if (isOpen && restoreFocus) {
33
+ const { activeElement } = document;
34
+ if (activeElement instanceof HTMLElement) {
35
+ previousActiveElementRef.current = activeElement;
36
+ }
37
+ }
38
+ }, [isOpen, restoreFocus]);
39
+ // Auto focus first focusable element when modal opens
40
+ useEffect(() => {
41
+ if (isOpen && autoFocus && containerRef.current) {
42
+ const firstFocusable = getFocusableElements(containerRef.current)[0];
43
+ if (firstFocusable) {
44
+ // Small delay to ensure modal is fully rendered
45
+ setTimeout(() => {
46
+ firstFocusable.focus();
47
+ }, 100);
48
+ }
49
+ }
50
+ }, [isOpen, autoFocus]);
51
+ // Restore focus when modal closes
52
+ useEffect(() => {
53
+ if (!isOpen && restoreFocus && previousActiveElementRef.current) {
54
+ previousActiveElementRef.current.focus();
55
+ previousActiveElementRef.current = null;
56
+ }
57
+ }, [isOpen, restoreFocus]);
58
+ // Focus trap
59
+ const handleKeyDown = useCallback((event) => {
60
+ if (!isOpen || !trapFocus || !containerRef.current)
61
+ return;
62
+ if (event.key === 'Tab') {
63
+ const focusableElements = getFocusableElements(containerRef.current);
64
+ const firstElement = focusableElements[0];
65
+ const lastElement = focusableElements[focusableElements.length - 1];
66
+ if (event.shiftKey) {
67
+ // Shift + Tab
68
+ if (document.activeElement === firstElement) {
69
+ event.preventDefault();
70
+ lastElement?.focus();
71
+ }
72
+ }
73
+ else {
74
+ // Tab
75
+ if (document.activeElement === lastElement) {
76
+ event.preventDefault();
77
+ firstElement?.focus();
78
+ }
79
+ }
80
+ }
81
+ }, [isOpen, trapFocus]);
82
+ useEffect(() => {
83
+ if (isOpen && trapFocus) {
84
+ document.addEventListener('keydown', handleKeyDown);
85
+ return () => {
86
+ document.removeEventListener('keydown', handleKeyDown);
87
+ };
88
+ }
89
+ }, [handleKeyDown, isOpen, trapFocus]);
90
+ return { containerRef };
91
+ };
92
+ export const useComponentFocus = () => {
93
+ const focusElement = useCallback((selector, delay = 0) => {
94
+ setTimeout(() => {
95
+ const element = document.querySelector(selector);
96
+ if (element instanceof HTMLElement) {
97
+ element.focus();
98
+ }
99
+ }, delay);
100
+ }, []);
101
+ const focusFirstInput = useCallback((container, delay = 0) => {
102
+ setTimeout(() => {
103
+ const targetContainer = container || document;
104
+ const firstInput = targetContainer.querySelector('input:not([disabled]), textarea:not([disabled])');
105
+ if (firstInput) {
106
+ firstInput.focus();
107
+ }
108
+ }, delay);
109
+ }, []);
110
+ const focusButton = useCallback((text, delay = 0) => {
111
+ setTimeout(() => {
112
+ const buttons = Array.from(document.querySelectorAll('button'));
113
+ const targetButton = buttons.find(button => button.textContent?.trim().toLowerCase() === text.toLowerCase());
114
+ if (targetButton) {
115
+ targetButton.focus();
116
+ }
117
+ }, delay);
118
+ }, []);
119
+ return {
120
+ focusElement,
121
+ focusFirstInput,
122
+ focusButton,
123
+ };
124
+ };
@@ -971,7 +971,7 @@
971
971
  "_TAB_INFORMATION_FIELD": "情報フィールド",
972
972
  "_TAB_JOURNEY": "旅",
973
973
  "_TAB_METRIC": "メトリック",
974
- "_TAB_MODEL_DIAGRAM": "",
974
+ "_TAB_MODEL_DIAGRAM": "ダイアグラム",
975
975
  "_TAB_MODEL_FIELD": "フィールド",
976
976
  "_TAB_OBECT_REFERENCE": "オブジェクト参照",
977
977
  "_TAB_OBJECT_ATTRIBUTE": "属性",
@@ -2538,7 +2538,7 @@
2538
2538
  "_WEBPER_TEMP_OBJ_INLINE_5": "社会的証明の表示",
2539
2539
  "_WEBPER_TEMP_OBJ_INLINE_6": "教育コンテンツ",
2540
2540
  "_WEBPER_TEMP_OBJ_SLIDEIN_1": "リードマグネット",
2541
- "_WEBPER_TEMP_OBJ_SLIDEIN_2": "終了意図",
2541
+ "_WEBPER_TEMP_OBJ_SLIDEIN_2": "終了の意図",
2542
2542
  "_WEBPER_TEMP_OBJ_SLIDEIN_3": "コンテンツティーザー",
2543
2543
  "_WEBPER_TEMP_OBJ_SLIDEIN_4": "アンケートと世論調査",
2544
2544
  "_WEBPER_TEMP_OBJ_SLIDEIN_5": "社会的証明の表示",