data-primals-engine 1.0.11 → 1.1.0

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 (166) hide show
  1. package/client/README.md +8 -0
  2. package/client/index.html +31 -0
  3. package/client/index.js +25 -0
  4. package/client/package-lock.json +11664 -0
  5. package/client/package.json +70 -0
  6. package/client/public/demo/26899917-d1ba-4df4-bb33-48d09a8778da.jpg +0 -0
  7. package/client/public/demo/4b9894c7-12cd-466d-8fd3-a2757b09ec96.jpg +0 -0
  8. package/client/public/demo/7ed369ac-a1a2-4b45-b0cd-4fd5bcf5a75a.jpg +0 -0
  9. package/client/public/doc/API.postman_collection.json +214 -0
  10. package/client/public/github.svg +1 -0
  11. package/client/public/profilCompany.jpg +0 -0
  12. package/client/public/profilDeveloper.jpg +0 -0
  13. package/client/public/profilEngineer.jpg +0 -0
  14. package/client/public/profilPersonal.jpg +0 -0
  15. package/client/public/profils .psd +0 -0
  16. package/client/public/react.svg +9 -0
  17. package/client/src/APIInfo.jsx +328 -0
  18. package/client/src/AddWidgetTypeModal.jsx +44 -0
  19. package/client/src/AddWidgetTypeModal.scss +87 -0
  20. package/client/src/App.css +42 -0
  21. package/client/src/App.jsx +586 -0
  22. package/client/src/App.scss +1466 -0
  23. package/client/src/AssistantChat.jsx +280 -0
  24. package/client/src/AssistantChat.scss +229 -0
  25. package/client/src/Button.jsx +12 -0
  26. package/client/src/Button.scss +197 -0
  27. package/client/src/CalculationBuilder.jsx +338 -0
  28. package/client/src/CalculationStepRow.jsx +199 -0
  29. package/client/src/CalendarConfigModal.jsx +49 -0
  30. package/client/src/ChartConfigModal.jsx +402 -0
  31. package/client/src/ConditionBuilder.jsx +622 -0
  32. package/client/src/ConditionBuilder.scss +672 -0
  33. package/client/src/ConditionBuilder2.jsx +757 -0
  34. package/client/src/ContentView.jsx +274 -0
  35. package/client/src/CronBuilder.jsx +126 -0
  36. package/client/src/CronBuilder.scss +128 -0
  37. package/client/src/CronPartBuilder.jsx +150 -0
  38. package/client/src/Dashboard.jsx +210 -0
  39. package/client/src/Dashboard.scss +445 -0
  40. package/client/src/DashboardChart.jsx +362 -0
  41. package/client/src/DashboardFlexViewItem.jsx +129 -0
  42. package/client/src/DashboardView.jsx +554 -0
  43. package/client/src/DataChart.jsx +349 -0
  44. package/client/src/DataEditor.jsx +556 -0
  45. package/client/src/DataLayout.jsx +709 -0
  46. package/client/src/DataTable.jsx +996 -0
  47. package/client/src/DataTable.scss +73 -0
  48. package/client/src/Dialog.jsx +90 -0
  49. package/client/src/Dialog.scss +117 -0
  50. package/client/src/DisplayFlexNodeRenderer.jsx +115 -0
  51. package/client/src/DocumentationPageLayout.jsx +93 -0
  52. package/client/src/DocumentationPageLayout.scss +262 -0
  53. package/client/src/Draggable.jsx +222 -0
  54. package/client/src/Draggable.scss +49 -0
  55. package/client/src/ExportDialog.jsx +172 -0
  56. package/client/src/Field.jsx +1558 -0
  57. package/client/src/FlexBuilder.jsx +269 -0
  58. package/client/src/FlexBuilder.scss +226 -0
  59. package/client/src/FlexBuilderControls.jsx +170 -0
  60. package/client/src/FlexBuilderModal.jsx +75 -0
  61. package/client/src/FlexBuilderModal.scss +109 -0
  62. package/client/src/FlexBuilderPreview.jsx +48 -0
  63. package/client/src/FlexBuilderUtils.js +84 -0
  64. package/client/src/FlexDataRenderer.jsx +170 -0
  65. package/client/src/FlexDataRenderer.scss +80 -0
  66. package/client/src/FlexNode.jsx +290 -0
  67. package/client/src/FlexTreeUtils.js +129 -0
  68. package/client/src/HiddenableCell.jsx +46 -0
  69. package/client/src/HiddenableCell.scss +36 -0
  70. package/client/src/KPIDialog.jsx +39 -0
  71. package/client/src/KPIWidget.jsx +139 -0
  72. package/client/src/KanbanCard.jsx +92 -0
  73. package/client/src/KanbanColumn.jsx +29 -0
  74. package/client/src/KanbanConfigModal.jsx +115 -0
  75. package/client/src/KanbanView.jsx +113 -0
  76. package/client/src/KanbanView.scss +107 -0
  77. package/client/src/MessageRotator.jsx +77 -0
  78. package/client/src/MessageRotator.scss +14 -0
  79. package/client/src/ModelCreator.jsx +640 -0
  80. package/client/src/ModelCreator.scss +154 -0
  81. package/client/src/ModelCreatorField.jsx +810 -0
  82. package/client/src/ModelImporter.jsx +120 -0
  83. package/client/src/ModelList.jsx +205 -0
  84. package/client/src/Notification.jsx +137 -0
  85. package/client/src/Notification.scss +126 -0
  86. package/client/src/NotificationProvider.jsx +73 -0
  87. package/client/src/PackGallery.jsx +211 -0
  88. package/client/src/PackGallery.scss +156 -0
  89. package/client/src/Pagination.jsx +141 -0
  90. package/client/src/RTE.jsx +415 -0
  91. package/client/src/RTETrans.jsx +103 -0
  92. package/client/src/RelationField.jsx +247 -0
  93. package/client/src/RelationValue.jsx +230 -0
  94. package/client/src/RestoreConfirmationModal.jsx +183 -0
  95. package/client/src/RestoreDialog.jsx +134 -0
  96. package/client/src/RestoreDialog.scss +67 -0
  97. package/client/src/RichTextEditorModal.jsx +34 -0
  98. package/client/src/RichTextEditorModal.scss +54 -0
  99. package/client/src/TourSpotlight.jsx +234 -0
  100. package/client/src/TourSpotlight.scss +100 -0
  101. package/client/src/TutorialsMenu.jsx +83 -0
  102. package/client/src/TutorialsMenu.scss +217 -0
  103. package/client/src/TutorialsRewardModal.jsx +65 -0
  104. package/client/src/Utils.jsx +78 -0
  105. package/client/src/ViewSwitcher.jsx +54 -0
  106. package/client/src/ViewSwitcher.scss +74 -0
  107. package/client/src/Webpage.jsx +69 -0
  108. package/client/src/_variables.scss +21 -0
  109. package/client/src/assets/react.svg +1 -0
  110. package/client/src/constants.js +68 -0
  111. package/client/src/contexts/AuthContext.jsx +28 -0
  112. package/client/src/contexts/ModelContext.jsx +328 -0
  113. package/client/src/contexts/UIContext.jsx +52 -0
  114. package/client/src/core/data.js +35 -0
  115. package/client/src/entry-client.jsx +15 -0
  116. package/client/src/entry-server.jsx +13 -0
  117. package/client/src/filter.js +222 -0
  118. package/client/src/hooks/data.js +101 -0
  119. package/client/src/hooks/useDebounce.js +20 -0
  120. package/client/src/hooks/useDragAndDrop.js +59 -0
  121. package/client/src/hooks/useLocalStorage.js +100 -0
  122. package/client/src/hooks/useMount.js +42 -0
  123. package/client/src/hooks/useTutorials.jsx +227 -0
  124. package/client/src/hooks/useWindowSize.js +24 -0
  125. package/client/src/i18n.js +47 -0
  126. package/client/src/index.css +90 -0
  127. package/client/src/index.js +10 -0
  128. package/client/src/main.jsx +11 -0
  129. package/client/src/translations.js +15940 -0
  130. package/client/src/tutorials.js +112 -0
  131. package/client/vite.config.js +30 -0
  132. package/eslint.config.js +50 -0
  133. package/package.json +48 -27
  134. package/server.js +9 -0
  135. package/src/constants.js +12 -23
  136. package/src/core.js +9 -8
  137. package/src/data.js +81 -80
  138. package/src/defaultModels.js +114 -115
  139. package/src/email.js +8 -9
  140. package/src/engine.js +5 -5
  141. package/src/events.js +1 -2
  142. package/src/i18n.js +212 -211
  143. package/src/middlewares/middleware-mongodb.js +94 -93
  144. package/src/migrate.js +24 -24
  145. package/src/modules/assistant.js +55 -55
  146. package/src/modules/bucket.js +10 -9
  147. package/src/modules/data.js +387 -357
  148. package/src/modules/file.js +3 -6
  149. package/src/modules/mongodb.js +6 -7
  150. package/src/modules/user.js +24 -47
  151. package/src/modules/workflow.js +68 -67
  152. package/src/openai.jobs.js +2 -2
  153. package/src/packs.js +30 -31
  154. package/src/providers.js +101 -3
  155. package/src/setenv.js +1 -1
  156. package/src/user.js +0 -17
  157. package/src/workers/crypto-worker.js +21 -20
  158. package/src/workers/import-export-worker.js +18 -18
  159. package/test/data.backup.integration.test.js +7 -12
  160. package/test/data.integration.test.js +27 -25
  161. package/test/globalSetup.js +2 -2
  162. package/test/import_export.integration.test.js +6 -6
  163. package/test/model.integration.test.js +21 -22
  164. package/test/workflow.integration.test.js +2 -5
  165. package/test/workflow.robustness.test.js +6 -13
  166. package/vitest.config.js +2 -2
@@ -0,0 +1,349 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { Bar, Doughnut, Pie, Line } from 'react-chartjs-2';
4
+ import {
5
+ Chart as ChartJS,
6
+ ArcElement,
7
+ Tooltip,
8
+ Legend,
9
+ CategoryScale,
10
+ LinearScale,
11
+ BarElement,
12
+ PointElement,
13
+ LineElement,
14
+ Title,
15
+ Filler // Import Filler for line chart area fill
16
+ } from 'chart.js';
17
+ import { useTranslation } from 'react-i18next'; // Optional: for default title
18
+
19
+ // Register all necessary components for the chart types we want to support
20
+ ChartJS.register(
21
+ ArcElement, // For Pie/Doughnut
22
+ Tooltip,
23
+ Legend,
24
+ CategoryScale, // For Bar/Line (X-axis)
25
+ LinearScale, // For Bar/Line (Y-axis)
26
+ BarElement, // For Bar
27
+ PointElement, // For Line
28
+ LineElement, // For Line
29
+ Title, // For Chart Title
30
+ Filler // For Line chart area fill
31
+ );
32
+
33
+ // --- Default Options ---
34
+
35
+ const defaultOptions = {
36
+ responsive: true,
37
+ maintainAspectRatio: false, // Allows controlling height/width ratio via container
38
+ plugins: {
39
+ legend: {
40
+ position: 'top', // Sensible default legend position
41
+ },
42
+ title: {
43
+ display: true, // Display title by default
44
+ text: 'Chart Title', // Default title text
45
+ },
46
+ tooltip: {
47
+ mode: 'index',
48
+ intersect: false,
49
+ },
50
+ },
51
+ scales: { // Default scales (primarily for Bar/Line)
52
+ x: {
53
+ display: true,
54
+ title: {
55
+ display: false, // No default X-axis title
56
+ text: 'X Axis',
57
+ },
58
+ ticks: {
59
+ // Auto-skip ticks if they overlap
60
+ autoSkip: true,
61
+ maxRotation: 45, // Rotate labels slightly if needed
62
+ minRotation: 0,
63
+ }
64
+ },
65
+ y: {
66
+ display: true,
67
+ title: {
68
+ display: false, // No default Y-axis title
69
+ text: 'Y Axis',
70
+ },
71
+ beginAtZero: true, // Start Y-axis at 0 by default
72
+ },
73
+ },
74
+ };
75
+
76
+ // Specific defaults for Pie/Doughnut (no scales)
77
+ const pieDoughnutDefaults = {
78
+ scales: undefined, // Remove scales for Pie/Doughnut
79
+ };
80
+
81
+ // Specific defaults for Line (tension)
82
+ const lineDefaults = {
83
+ tension: 0.1, // Slight curve for line charts
84
+ };
85
+
86
+ // --- Helper Functions ---
87
+
88
+ /**
89
+ * Generates a palette of distinct colors.
90
+ * @param {number} count - Number of colors needed.
91
+ * @returns {string[]} An array of hex color strings.
92
+ */
93
+ const generateDefaultColors = (count) => {
94
+ const colors = [
95
+ '#FF6384', '#36A2EB', '#FFCE56', '#4BC0C0', '#9966FF', '#FF9F40',
96
+ '#FFCD56', '#C9CBCF', '#3FC77D', '#E7E9ED', '#77DD77', '#FDFD96',
97
+ '#84B4E8', '#F49AC2', '#FAA460', '#B19CD9', '#FFB347', '#FFD1DC'
98
+ ];
99
+ // Repeat colors if more are needed than the base palette
100
+ const result = [];
101
+ for (let i = 0; i < count; i++) {
102
+ result.push(colors[i % colors.length]);
103
+ }
104
+ return result;
105
+ };
106
+
107
+ /**
108
+ * Merges user-provided options with default options.
109
+ * @param {object} userOptions - Options provided via props.
110
+ * @param {string} chartType - The type of chart ('bar', 'line', 'pie', 'doughnut').
111
+ * @returns {object} The merged options object.
112
+ */
113
+ const mergeOptions = (userOptions, chartType, defaultTitle) => {
114
+ let baseDefaults = { ...defaultOptions };
115
+
116
+ // Apply type-specific defaults
117
+ if (chartType === 'pie' || chartType === 'doughnut') {
118
+ baseDefaults = { ...baseDefaults, ...pieDoughnutDefaults };
119
+ }
120
+ if (chartType === 'line') {
121
+ baseDefaults = { ...baseDefaults, ...lineDefaults };
122
+ }
123
+
124
+ // Deep merge (simple version, consider lodash.merge for complex cases)
125
+ const merged = {
126
+ ...baseDefaults,
127
+ ...userOptions,
128
+ plugins: {
129
+ ...baseDefaults.plugins,
130
+ ...(userOptions?.plugins),
131
+ title: {
132
+ ...baseDefaults.plugins?.title,
133
+ text: userOptions?.plugins?.title?.text ?? defaultTitle ?? baseDefaults.plugins?.title?.text, // Prioritize user title, then default prop, then base default
134
+ display: userOptions?.plugins?.title?.display ?? (!!(userOptions?.plugins?.title?.text ?? defaultTitle)), // Display title if text is provided
135
+ ...(userOptions?.plugins?.title),
136
+ },
137
+ legend: {
138
+ ...baseDefaults.plugins?.legend,
139
+ ...(userOptions?.plugins?.legend),
140
+ },
141
+ tooltip: {
142
+ ...baseDefaults.plugins?.tooltip,
143
+ ...(userOptions?.plugins?.tooltip),
144
+ },
145
+ },
146
+ scales: { // Merge scales carefully
147
+ x: {
148
+ ...baseDefaults.scales?.x,
149
+ ...(userOptions?.scales?.x),
150
+ title: {
151
+ ...baseDefaults.scales?.x?.title,
152
+ ...(userOptions?.scales?.x?.title),
153
+ },
154
+ ticks: {
155
+ ...baseDefaults.scales?.x?.ticks,
156
+ ...(userOptions?.scales?.x?.ticks),
157
+ }
158
+ },
159
+ y: {
160
+ ...baseDefaults.scales?.y,
161
+ ...(userOptions?.scales?.y),
162
+ title: {
163
+ ...baseDefaults.scales?.y?.title,
164
+ ...(userOptions?.scales?.y?.title),
165
+ },
166
+ ticks: {
167
+ ...baseDefaults.scales?.y?.ticks,
168
+ ...(userOptions?.scales?.y?.ticks),
169
+ }
170
+ },
171
+ // Allow adding other scales (e.g., y1 for dual-axis)
172
+ ...(userOptions?.scales),
173
+ }
174
+ };
175
+
176
+ // Remove scales entirely if chart type doesn't use them
177
+ if (chartType === 'pie' || chartType === 'doughnut') {
178
+ delete merged.scales;
179
+ }
180
+
181
+
182
+ return merged;
183
+ };
184
+
185
+ /**
186
+ * Prepares the data object for Chart.js, ensuring default colors if needed.
187
+ * @param {object} chartData - The data object provided via props ({ labels: [], datasets: [] }).
188
+ * @returns {object} The prepared data object.
189
+ */
190
+ const prepareData = (chartData) => {
191
+ if (!chartData || !chartData.datasets) {
192
+ return { labels: [], datasets: [] }; // Return empty structure if data is invalid
193
+ }
194
+
195
+ const preparedDatasets = chartData.datasets.map((dataset, index) => {
196
+ const dataLength = dataset.data?.length || 0;
197
+ const needsColor = !dataset.backgroundColor;
198
+ const needsBorderColor = !dataset.borderColor; // Often useful for Line charts
199
+
200
+ // Generate default colors only if backgroundColor is missing
201
+ const defaultBgColors = needsColor ? generateDefaultColors(dataLength) : undefined;
202
+ // Use a single border color by default for line charts if not provided
203
+ const defaultBorderColor = needsBorderColor && defaultBgColors ? defaultBgColors[index % defaultBgColors.length] : undefined;
204
+
205
+ return {
206
+ ...dataset,
207
+ backgroundColor: dataset.backgroundColor ?? defaultBgColors,
208
+ borderColor: dataset.borderColor ?? defaultBorderColor,
209
+ // Add hover colors slightly darker/lighter than base colors if not provided
210
+ hoverBackgroundColor: dataset.hoverBackgroundColor ?? dataset.backgroundColor ?? defaultBgColors,
211
+ hoverBorderColor: dataset.hoverBorderColor ?? dataset.borderColor ?? defaultBorderColor,
212
+ };
213
+ });
214
+
215
+ return {
216
+ ...chartData,
217
+ datasets: preparedDatasets,
218
+ };
219
+ };
220
+
221
+
222
+ // --- DataChart Component ---
223
+
224
+ export const DataChart = ({ type = 'bar', data, options = {}, title, className = '', height = '300px', width = '100%' }) => {
225
+ const { t } = useTranslation(); // Optional i18n
226
+
227
+ // Basic validation
228
+ if (!data || !data.labels || !data.datasets || data.datasets.length === 0) {
229
+ console.warn("DataChart: Invalid or empty 'data' prop provided.", data);
230
+ return <div className={`data-chart-container ${className}`} style={{ height, width, display: 'flex', alignItems: 'center', justifyContent: 'center', border: '1px dashed #ccc' }}>{t('dashboards.no_data_chart') || 'No data available for chart'}</div>;
231
+ }
232
+
233
+ const chartType = type.toLowerCase();
234
+ const defaultTitleText = title ?? t(`dashboards.chart_title_${chartType}`) ?? `Chart (${chartType})`; // Example i18n key
235
+ const finalOptions = mergeOptions(options, chartType, defaultTitleText);
236
+ const finalData = prepareData(data);
237
+
238
+ let ChartComponent;
239
+ switch (chartType) {
240
+ case 'doughnut':
241
+ ChartComponent = Doughnut;
242
+ break;
243
+ case 'pie':
244
+ ChartComponent = Pie;
245
+ break;
246
+ case 'line':
247
+ ChartComponent = Line;
248
+ break;
249
+ case 'bar':
250
+ default: // Default to Bar chart
251
+ ChartComponent = Bar;
252
+ break;
253
+ }
254
+
255
+ return (
256
+ <div className={`data-chart-container ${className}`} style={{ position: 'relative', height, width }}>
257
+ <ChartComponent options={finalOptions} data={finalData} />
258
+ </div>
259
+ );
260
+ };
261
+
262
+ // --- PropTypes ---
263
+
264
+ DataChart.propTypes = {
265
+ /** The type of chart to render */
266
+ type: PropTypes.oneOf(['bar', 'line', 'pie', 'doughnut']),
267
+ /** Chart data in Chart.js format ({ labels: [], datasets: [{ label, data, backgroundColor?, borderColor?, ... }] }) */
268
+ data: PropTypes.shape({
269
+ labels: PropTypes.arrayOf(PropTypes.string).isRequired,
270
+ datasets: PropTypes.arrayOf(PropTypes.shape({
271
+ label: PropTypes.string,
272
+ data: PropTypes.arrayOf(PropTypes.number).isRequired,
273
+ backgroundColor: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
274
+ borderColor: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
275
+ // ... other dataset options allowed by Chart.js
276
+ })).isRequired,
277
+ }).isRequired,
278
+ /** Chart.js options object. Will be merged with sensible defaults. */
279
+ options: PropTypes.object,
280
+ /** Optional default title for the chart if not specified in options.plugins.title.text */
281
+ title: PropTypes.string,
282
+ /** Optional CSS class name for the container div */
283
+ className: PropTypes.string,
284
+ /** Height of the chart container (CSS value) */
285
+ height: PropTypes.string,
286
+ /** Width of the chart container (CSS value) */
287
+ width: PropTypes.string,
288
+ };
289
+
290
+ // Example Usage (assuming you have data in the correct format):
291
+ /*
292
+ const MyComponent = () => {
293
+ const barData = {
294
+ labels: ['January', 'February', 'March', 'April', 'May', 'June'],
295
+ datasets: [
296
+ {
297
+ label: 'Dataset 1',
298
+ data: [65, 59, 80, 81, 56, 55],
299
+ // backgroundColor: 'rgba(255, 99, 132, 0.5)', // Optional: Provide colors
300
+ },
301
+ {
302
+ label: 'Dataset 2',
303
+ data: [35, 49, 60, 71, 46, 35],
304
+ // backgroundColor: 'rgba(54, 162, 235, 0.5)', // Optional
305
+ },
306
+ ],
307
+ };
308
+
309
+ const pieData = {
310
+ labels: ['Red', 'Blue', 'Yellow'],
311
+ datasets: [{
312
+ label: 'My First Dataset',
313
+ data: [300, 50, 100],
314
+ // backgroundColor: ['rgb(255, 99, 132)', 'rgb(54, 162, 235)', 'rgb(255, 205, 86)'], // Optional
315
+ hoverOffset: 4
316
+ }]
317
+ };
318
+
319
+ const lineOptions = {
320
+ plugins: {
321
+ title: { text: 'Monthly Sales Trend' },
322
+ legend: { display: true }
323
+ },
324
+ scales: {
325
+ y: { title: { display: true, text: 'Sales ($)' } }
326
+ }
327
+ }
328
+
329
+ return (
330
+ <div>
331
+ <h2>Bar Chart Example</h2>
332
+ <DataChart type="bar" data={barData} title="Monthly Revenue" height="400px" />
333
+
334
+ <h2>Pie Chart Example</h2>
335
+ <DataChart type="pie" data={pieData} title="Color Distribution" width="50%" height="350px" />
336
+
337
+ <h2>Line Chart Example with Custom Options</h2>
338
+ <DataChart type="line" data={barData} options={lineOptions} height="350px" />
339
+ </div>
340
+ );
341
+ }
342
+
343
+ options: {
344
+ scales: {
345
+ xAxes: [{
346
+ type: 'time',
347
+ }]
348
+ },
349
+ */