@archbase/components 3.0.25 → 4.0.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 (168) hide show
  1. package/dist/buttons/ArchbaseSpeedDial.d.ts +59 -0
  2. package/dist/buttons/index.d.ts +2 -0
  3. package/dist/charts/ArchbaseArcGauge.d.ts +55 -0
  4. package/dist/charts/ArchbaseGantt.d.ts +70 -0
  5. package/dist/charts/ArchbaseLinearGauge.d.ts +55 -0
  6. package/dist/charts/ArchbaseResourceTimeline.d.ts +61 -0
  7. package/dist/charts/ArchbaseSparkline.d.ts +45 -0
  8. package/dist/charts/index.d.ts +10 -0
  9. package/dist/containers/ArchbaseExpansionPanel.d.ts +60 -0
  10. package/dist/containers/ArchbaseFloatingPanel.d.ts +91 -0
  11. package/dist/containers/index.d.ts +4 -0
  12. package/dist/datagrid/export/ArchbaseDataGridExcelExport.d.ts +67 -0
  13. package/dist/datagrid/export/index.d.ts +2 -0
  14. package/dist/datagrid/index.d.ts +1 -0
  15. package/dist/display/ArchbaseAnimationWrapper.d.ts +73 -0
  16. package/dist/display/ArchbaseBarcodeGenerator.d.ts +50 -0
  17. package/dist/display/ArchbaseCarousel.d.ts +100 -0
  18. package/dist/display/ArchbaseCodeViewer.d.ts +63 -0
  19. package/dist/display/ArchbaseDiffViewer.d.ts +41 -0
  20. package/dist/display/ArchbaseJsonTree.d.ts +34 -0
  21. package/dist/display/ArchbaseLightbox.d.ts +89 -0
  22. package/dist/display/ArchbaseMarquee.d.ts +46 -0
  23. package/dist/display/ArchbasePhotoAlbum.d.ts +58 -0
  24. package/dist/display/ArchbaseQRCode.d.ts +44 -0
  25. package/dist/display/ArchbaseTooltipRich.d.ts +82 -0
  26. package/dist/display/ArchbaseVirtualList.d.ts +116 -0
  27. package/dist/display/index.d.ts +24 -0
  28. package/dist/editors/ArchbaseAIPromptInput.d.ts +69 -0
  29. package/dist/editors/ArchbaseAsyncMultiSelect.d.ts +1 -1
  30. package/dist/editors/ArchbaseAsyncSelect.d.ts +1 -1
  31. package/dist/editors/ArchbaseBarcodeScanner.d.ts +63 -0
  32. package/dist/editors/ArchbaseCepInput.d.ts +26 -0
  33. package/dist/editors/ArchbaseColorGradientPicker.d.ts +80 -0
  34. package/dist/editors/ArchbaseCpfCnpjInput.d.ts +21 -0
  35. package/dist/editors/ArchbaseCurrencyInput.d.ts +25 -0
  36. package/dist/editors/ArchbaseDualListbox.d.ts +61 -0
  37. package/dist/editors/ArchbaseInPlaceEditor.d.ts +67 -0
  38. package/dist/editors/ArchbaseLightGrid.d.ts +56 -0
  39. package/dist/editors/ArchbaseMentionInput.d.ts +75 -0
  40. package/dist/editors/ArchbaseMultiEmail.d.ts +53 -0
  41. package/dist/editors/ArchbaseMultiViewCalendar.d.ts +47 -0
  42. package/dist/editors/ArchbaseNumberStepper.d.ts +66 -0
  43. package/dist/editors/ArchbaseOTPInput.d.ts +27 -0
  44. package/dist/editors/ArchbasePhoneInput.d.ts +52 -0
  45. package/dist/editors/ArchbaseRangeSlider.d.ts +22 -0
  46. package/dist/editors/ArchbaseSignaturePad.d.ts +60 -0
  47. package/dist/editors/ArchbaseSpeechToTextInput.d.ts +106 -0
  48. package/dist/editors/ArchbaseSpreadsheet.d.ts +56 -0
  49. package/dist/editors/ArchbaseTagInput.d.ts +55 -0
  50. package/dist/editors/index.d.ts +40 -0
  51. package/dist/feedback/ArchbaseChunkProgressBar.d.ts +35 -0
  52. package/dist/feedback/ArchbaseRipple.d.ts +43 -0
  53. package/dist/feedback/ArchbaseSkeleton.d.ts +115 -0
  54. package/dist/feedback/index.d.ts +6 -0
  55. package/dist/filters/ArchbaseColumnSelector.d.ts +38 -0
  56. package/dist/filters/index.d.ts +2 -0
  57. package/dist/forms/ArchbaseFieldArray.d.ts +80 -0
  58. package/dist/forms/ArchbaseFormWizard.d.ts +73 -0
  59. package/dist/forms/ArchbaseStepper.d.ts +51 -0
  60. package/dist/forms/index.d.ts +8 -0
  61. package/dist/forms/useArchbaseFormWizard.d.ts +74 -0
  62. package/dist/hooks/index.d.ts +2 -0
  63. package/dist/hooks/useArchbaseConfirm.d.ts +59 -0
  64. package/dist/image/editor/index.d.ts +43 -4
  65. package/dist/image/index.d.ts +1 -0
  66. package/dist/index.css +1 -1
  67. package/dist/index.d.ts +1 -0
  68. package/dist/index.js +22510 -13820
  69. package/dist/list/ArchbaseTreeList.d.ts +76 -0
  70. package/dist/list/index.d.ts +2 -0
  71. package/dist/navigation/ArchbaseActionSheet.d.ts +70 -0
  72. package/dist/navigation/ArchbaseAppBar.d.ts +63 -0
  73. package/dist/navigation/ArchbaseBottomNavigation.d.ts +61 -0
  74. package/dist/navigation/ArchbaseContextMenu.d.ts +76 -0
  75. package/dist/navigation/ArchbaseKeyboardShortcuts.d.ts +85 -0
  76. package/dist/navigation/ArchbaseSpotlight.d.ts +69 -0
  77. package/dist/navigation/index.d.ts +12 -0
  78. package/dist/notification/ArchbaseNotificationCenter.d.ts +56 -0
  79. package/dist/notification/index.d.ts +2 -0
  80. package/dist/onboarding/ArchbaseOnboardingTour.d.ts +27 -76
  81. package/dist/viewers/ArchbaseDocViewer.d.ts +40 -0
  82. package/dist/viewers/ArchbasePdfBuilder.d.ts +53 -0
  83. package/dist/viewers/ArchbaseXmlViewer.d.ts +36 -0
  84. package/dist/viewers/index.d.ts +6 -0
  85. package/package.json +41 -18
  86. package/src/buttons/ArchbaseSpeedDial.tsx +282 -0
  87. package/src/buttons/index.ts +3 -0
  88. package/src/charts/ArchbaseArcGauge.tsx +325 -0
  89. package/src/charts/ArchbaseGantt.tsx +494 -0
  90. package/src/charts/ArchbaseLinearGauge.tsx +288 -0
  91. package/src/charts/ArchbaseResourceTimeline.tsx +433 -0
  92. package/src/charts/ArchbaseSparkline.tsx +193 -0
  93. package/src/charts/index.ts +20 -1
  94. package/src/containers/ArchbaseExpansionPanel.tsx +208 -0
  95. package/src/containers/ArchbaseFloatingPanel.tsx +448 -0
  96. package/src/containers/index.ts +17 -0
  97. package/src/datagrid/components/pagination/grid-pagination.tsx +2 -2
  98. package/src/datagrid/export/ArchbaseDataGridExcelExport.tsx +293 -0
  99. package/src/datagrid/export/index.ts +8 -0
  100. package/src/datagrid/index.tsx +2 -0
  101. package/src/display/ArchbaseAnimationWrapper.tsx +272 -0
  102. package/src/display/ArchbaseBarcodeGenerator.tsx +303 -0
  103. package/src/display/ArchbaseCarousel.tsx +679 -0
  104. package/src/display/ArchbaseCodeViewer.tsx +271 -0
  105. package/src/display/ArchbaseDiffViewer.tsx +108 -0
  106. package/src/display/ArchbaseJsonTree.tsx +150 -0
  107. package/src/display/ArchbaseLightbox.tsx +279 -0
  108. package/src/display/ArchbaseMarquee.tsx +268 -0
  109. package/src/display/ArchbasePhotoAlbum.tsx +415 -0
  110. package/src/display/ArchbaseQRCode.tsx +137 -0
  111. package/src/display/ArchbaseTooltipRich.tsx +317 -0
  112. package/src/display/ArchbaseVirtualList.tsx +618 -0
  113. package/src/display/index.ts +94 -1
  114. package/src/editors/ArchbaseAIPromptInput.tsx +432 -0
  115. package/src/editors/ArchbaseBarcodeScanner.tsx +570 -0
  116. package/src/editors/ArchbaseCepInput.tsx +173 -0
  117. package/src/editors/ArchbaseColorGradientPicker.tsx +460 -0
  118. package/src/editors/ArchbaseCpfCnpjInput.tsx +193 -0
  119. package/src/editors/ArchbaseCurrencyInput.tsx +100 -0
  120. package/src/editors/ArchbaseDualListbox.tsx +671 -0
  121. package/src/editors/ArchbaseInPlaceEditor.tsx +406 -0
  122. package/src/editors/ArchbaseLightGrid.tsx +538 -0
  123. package/src/editors/ArchbaseMentionInput.tsx +384 -0
  124. package/src/editors/ArchbaseMultiEmail.tsx +367 -0
  125. package/src/editors/ArchbaseMultiViewCalendar.tsx +439 -0
  126. package/src/editors/ArchbaseNumberStepper.tsx +219 -0
  127. package/src/editors/ArchbaseOTPInput.tsx +133 -0
  128. package/src/editors/ArchbaseOperationHoursEditor.tsx +1 -1
  129. package/src/editors/ArchbasePhoneInput.tsx +355 -0
  130. package/src/editors/ArchbaseRangeSlider.tsx +109 -0
  131. package/src/editors/ArchbaseSignaturePad.tsx +425 -0
  132. package/src/editors/ArchbaseSpeechToTextInput.tsx +444 -0
  133. package/src/editors/ArchbaseSpreadsheet.tsx +388 -0
  134. package/src/editors/ArchbaseTagInput.tsx +326 -0
  135. package/src/editors/index.tsx +92 -0
  136. package/src/feedback/ArchbaseChunkProgressBar.tsx +156 -0
  137. package/src/feedback/ArchbaseRipple.tsx +278 -0
  138. package/src/feedback/ArchbaseSkeleton.tsx +419 -0
  139. package/src/feedback/index.ts +22 -1
  140. package/src/filters/ArchbaseColumnSelector.tsx +268 -0
  141. package/src/filters/index.ts +2 -0
  142. package/src/forms/ArchbaseFieldArray.tsx +305 -0
  143. package/src/forms/ArchbaseFormWizard.tsx +284 -0
  144. package/src/forms/ArchbaseStepper.tsx +137 -0
  145. package/src/forms/index.ts +24 -2
  146. package/src/forms/useArchbaseFormWizard.ts +283 -0
  147. package/src/hooks/index.ts +12 -0
  148. package/src/hooks/useArchbaseConfirm.ts +293 -0
  149. package/src/image/editor/functions/image-processing.ts +5 -0
  150. package/src/image/editor/index.tsx +305 -391
  151. package/src/image/index.ts +1 -0
  152. package/src/index.ts +3 -0
  153. package/src/list/ArchbaseTreeList.tsx +422 -0
  154. package/src/list/index.ts +3 -0
  155. package/src/navigation/ArchbaseActionSheet.tsx +301 -0
  156. package/src/navigation/ArchbaseAppBar.tsx +233 -0
  157. package/src/navigation/ArchbaseBottomNavigation.tsx +243 -0
  158. package/src/navigation/ArchbaseContextMenu.tsx +298 -0
  159. package/src/navigation/ArchbaseKeyboardShortcuts.tsx +472 -0
  160. package/src/navigation/ArchbaseSpotlight.tsx +483 -0
  161. package/src/navigation/index.ts +48 -1
  162. package/src/notification/ArchbaseNotificationCenter.tsx +502 -0
  163. package/src/notification/index.ts +2 -0
  164. package/src/onboarding/ArchbaseOnboardingTour.tsx +229 -102
  165. package/src/viewers/ArchbaseDocViewer.tsx +584 -0
  166. package/src/viewers/ArchbasePdfBuilder.tsx +291 -0
  167. package/src/viewers/ArchbaseXmlViewer.tsx +142 -0
  168. package/src/viewers/index.ts +12 -0
@@ -0,0 +1,271 @@
1
+ /**
2
+ * ArchbaseCodeViewer — visualizador de codigo-fonte com syntax highlighting
3
+ * usando @mantine/code-highlight, com binding opcional ao dataSource.
4
+ * @status stable
5
+ */
6
+ import { Box, Input } from '@mantine/core';
7
+ import { CodeHighlight, CodeHighlightTabs } from '@mantine/code-highlight';
8
+ import type { CodeHighlightTabsCode } from '@mantine/code-highlight';
9
+ import { useForceUpdate } from '@mantine/hooks';
10
+ import React, { CSSProperties, useCallback, useEffect, useRef, useState } from 'react';
11
+ import type { DataSourceEvent, IArchbaseDataSourceBase } from '@archbase/data';
12
+ import { DataSourceEventNames, useArchbaseDidUpdate, useArchbaseV1V2Compatibility } from '@archbase/data';
13
+
14
+ function getInitialValue<T>(
15
+ value: string | undefined,
16
+ dataSource?: IArchbaseDataSourceBase<T>,
17
+ dataField?: string,
18
+ ): string {
19
+ let initialValue: string | undefined = value;
20
+ if (dataSource && dataField) {
21
+ initialValue = dataSource.getFieldValue(dataField) as string | undefined;
22
+ if (!initialValue) {
23
+ initialValue = '';
24
+ }
25
+ }
26
+ return initialValue ?? '';
27
+ }
28
+
29
+ export interface ArchbaseCodeViewerTab {
30
+ /** Nome do arquivo exibido na aba */
31
+ fileName: string;
32
+ /** Codigo-fonte da aba */
33
+ code: string;
34
+ /** Linguagem para syntax highlighting */
35
+ language: string;
36
+ /** Icone opcional da aba */
37
+ icon?: React.ReactNode;
38
+ }
39
+
40
+ export interface ArchbaseCodeViewerProps<T> {
41
+ /** Fonte de dados onde sera lido o valor do codigo (V1 ou V2) */
42
+ dataSource?: IArchbaseDataSourceBase<T>;
43
+ /** Campo de onde sera lido o valor do codigo na fonte de dados */
44
+ dataField?: string;
45
+ /** Valor do codigo (standalone) */
46
+ value?: string;
47
+ /** Alias para value */
48
+ code?: string;
49
+ /** Linguagem para syntax highlighting @default 'typescript' */
50
+ language?: string;
51
+ /** Exibir numeros de linha @default true */
52
+ showLineNumbers?: boolean;
53
+ /** Exibir botao de copiar @default true */
54
+ showCopyButton?: boolean;
55
+ /** Label do componente */
56
+ label?: string;
57
+ /** Descricao do componente */
58
+ description?: string;
59
+ /** Mensagem de erro */
60
+ error?: string;
61
+ /** Linhas destacadas */
62
+ highlightLines?: Record<string, { color: string; label?: string }>;
63
+ /** Altura maxima com scroll */
64
+ maxHeight?: string | number;
65
+ /** Estilo CSS */
66
+ style?: CSSProperties;
67
+ /** Classe CSS */
68
+ className?: string;
69
+ /** Largura do componente */
70
+ width?: string | number;
71
+ /** Quando fornecido, renderiza CodeHighlightTabs em vez de CodeHighlight */
72
+ tabs?: ArchbaseCodeViewerTab[];
73
+ /** Exibir borda ao redor do codigo @default false */
74
+ withBorder?: boolean;
75
+ /** Border radius @default 'sm' */
76
+ radius?: string | number;
77
+ /** Label do botao de copiar @default 'Copiar' */
78
+ copyLabel?: string;
79
+ /** Label do botao apos copiar @default 'Copiado' */
80
+ copiedLabel?: string;
81
+ /** Exibir botao de expandir/colapsar @default false */
82
+ withExpandButton?: boolean;
83
+ }
84
+
85
+ export function ArchbaseCodeViewer<T>({
86
+ dataSource,
87
+ dataField,
88
+ value,
89
+ code,
90
+ language = 'typescript',
91
+ showLineNumbers: _showLineNumbers = true,
92
+ showCopyButton = true,
93
+ label,
94
+ description,
95
+ error,
96
+ highlightLines: _highlightLines,
97
+ maxHeight,
98
+ style,
99
+ className,
100
+ width,
101
+ tabs,
102
+ withBorder = false,
103
+ radius = 'sm',
104
+ copyLabel = 'Copiar',
105
+ copiedLabel = 'Copiado',
106
+ withExpandButton = false,
107
+ }: ArchbaseCodeViewerProps<T>) {
108
+ // Hook de compatibilidade V1/V2
109
+ const v1v2Compatibility = useArchbaseV1V2Compatibility<string>(
110
+ 'ArchbaseCodeViewer',
111
+ dataSource,
112
+ dataField,
113
+ '',
114
+ );
115
+
116
+ const forceUpdate = useForceUpdate();
117
+
118
+ const [currentValue, setCurrentValue] = useState<string>(
119
+ getInitialValue(value ?? code, dataSource, dataField),
120
+ );
121
+
122
+ const loadDataSourceFieldValue = () => {
123
+ let initialValue: string | undefined = value ?? code;
124
+
125
+ if (dataSource && dataField) {
126
+ initialValue = dataSource.getFieldValue(dataField) as string | undefined;
127
+ if (!initialValue) {
128
+ initialValue = '';
129
+ }
130
+ }
131
+
132
+ setCurrentValue(initialValue ?? '');
133
+ };
134
+
135
+ const fieldChangedListener = useCallback(() => {
136
+ loadDataSourceFieldValue();
137
+ }, []);
138
+
139
+ const dataSourceEvent = useCallback(
140
+ (event: DataSourceEvent<T>) => {
141
+ if (dataSource && dataField) {
142
+ if (
143
+ event.type === DataSourceEventNames.dataChanged ||
144
+ event.type === DataSourceEventNames.recordChanged ||
145
+ event.type === DataSourceEventNames.afterScroll ||
146
+ event.type === DataSourceEventNames.afterCancel ||
147
+ event.type === DataSourceEventNames.afterEdit
148
+ ) {
149
+ loadDataSourceFieldValue();
150
+ if (!v1v2Compatibility.isDataSourceV2) {
151
+ forceUpdate();
152
+ }
153
+ }
154
+ }
155
+ },
156
+ [v1v2Compatibility.isDataSourceV2],
157
+ );
158
+
159
+ // Ref para manter callback sempre atualizado
160
+ const dataSourceEventRef = useRef(dataSourceEvent);
161
+ useEffect(() => {
162
+ dataSourceEventRef.current = dataSourceEvent;
163
+ }, [dataSourceEvent]);
164
+
165
+ // Wrapper estavel que delega para ref
166
+ const stableDataSourceEvent = useCallback((event: DataSourceEvent<T>) => {
167
+ dataSourceEventRef.current(event);
168
+ }, []);
169
+
170
+ // Registrar listeners com cleanup apropriado
171
+ useEffect(() => {
172
+ loadDataSourceFieldValue();
173
+ if (dataSource && dataField) {
174
+ const hasFieldListener =
175
+ typeof (dataSource as any).addFieldChangeListener === 'function';
176
+ dataSource.addListener(stableDataSourceEvent);
177
+ if (hasFieldListener) {
178
+ (dataSource as any).addFieldChangeListener(dataField, fieldChangedListener);
179
+ }
180
+
181
+ return () => {
182
+ dataSource.removeListener(stableDataSourceEvent);
183
+ if (hasFieldListener) {
184
+ (dataSource as any).removeFieldChangeListener(dataField, fieldChangedListener);
185
+ }
186
+ };
187
+ }
188
+ }, [dataSource, dataField, stableDataSourceEvent, fieldChangedListener]);
189
+
190
+ useArchbaseDidUpdate(() => {
191
+ loadDataSourceFieldValue();
192
+ }, []);
193
+
194
+ // Atualizar quando value/code prop mudar externamente
195
+ useEffect(() => {
196
+ if (!dataSource && !dataField) {
197
+ setCurrentValue(value ?? code ?? '');
198
+ }
199
+ }, [value, code, dataSource, dataField]);
200
+
201
+ const codeContent = currentValue;
202
+
203
+ const renderCodeHighlight = () => {
204
+ if (tabs && tabs.length > 0) {
205
+ const tabsCode: CodeHighlightTabsCode[] = tabs.map((tab) => ({
206
+ fileName: tab.fileName,
207
+ code: tab.code,
208
+ language: tab.language,
209
+ icon: tab.icon,
210
+ }));
211
+
212
+ return (
213
+ <CodeHighlightTabs
214
+ code={tabsCode}
215
+ withCopyButton={showCopyButton}
216
+ withBorder={withBorder}
217
+ radius={radius as any}
218
+ copyLabel={copyLabel}
219
+ copiedLabel={copiedLabel}
220
+ withExpandButton={withExpandButton}
221
+ />
222
+ );
223
+ }
224
+
225
+ return (
226
+ <CodeHighlight
227
+ code={codeContent}
228
+ language={language}
229
+ withCopyButton={showCopyButton}
230
+ withBorder={withBorder}
231
+ radius={radius as any}
232
+ copyLabel={copyLabel}
233
+ copiedLabel={copiedLabel}
234
+ withExpandButton={withExpandButton}
235
+ />
236
+ );
237
+ };
238
+
239
+ const wrapperStyle: CSSProperties = {
240
+ ...style,
241
+ width,
242
+ };
243
+
244
+ const codeWrapper = maxHeight ? (
245
+ <Box style={{ maxHeight, overflow: 'auto' }}>{renderCodeHighlight()}</Box>
246
+ ) : (
247
+ renderCodeHighlight()
248
+ );
249
+
250
+ if (label || description || error) {
251
+ return (
252
+ <Input.Wrapper
253
+ label={label}
254
+ description={description}
255
+ error={error}
256
+ style={wrapperStyle}
257
+ className={className}
258
+ >
259
+ {codeWrapper}
260
+ </Input.Wrapper>
261
+ );
262
+ }
263
+
264
+ return (
265
+ <Box style={wrapperStyle} className={className}>
266
+ {codeWrapper}
267
+ </Box>
268
+ );
269
+ }
270
+
271
+ ArchbaseCodeViewer.displayName = 'ArchbaseCodeViewer';
@@ -0,0 +1,108 @@
1
+ import { Box, Input, useComputedColorScheme } from '@mantine/core';
2
+ import type { CSSProperties } from 'react';
3
+ import React from 'react';
4
+ import ReactDiffViewer, { DiffMethod } from 'react-diff-viewer-continued';
5
+
6
+ export { DiffMethod } from 'react-diff-viewer-continued';
7
+
8
+ export interface ArchbaseDiffViewerProps {
9
+ /** Texto original (lado esquerdo) */
10
+ oldValue: string;
11
+ /** Texto novo (lado direito) */
12
+ newValue: string;
13
+ /** Exibir em modo split (lado a lado) ou unificado */
14
+ splitView?: boolean;
15
+ /** Exibir apenas as diferenças */
16
+ showDiffOnly?: boolean;
17
+ /** Titulo do painel esquerdo */
18
+ leftTitle?: string;
19
+ /** Titulo do painel direito */
20
+ rightTitle?: string;
21
+ /** Linguagem para syntax highlighting */
22
+ language?: string;
23
+ /** Metodo de comparacao */
24
+ compareMethod?: DiffMethod;
25
+ /** Titulo do componente */
26
+ label?: string;
27
+ /** Descricao do componente */
28
+ description?: string;
29
+ /** Estilo do componente */
30
+ style?: CSSProperties;
31
+ /** Classe CSS do componente */
32
+ className?: string;
33
+ /** Largura do componente */
34
+ width?: string | number;
35
+ /** Altura maxima do componente (com scroll) */
36
+ height?: string | number;
37
+ /** Usar tema escuro (auto-detectado do Mantine se nao informado) */
38
+ useDarkTheme?: boolean;
39
+ /** Ocultar numeros de linha */
40
+ hideLineNumbers?: boolean;
41
+ /** Linhas de contexto ao redor das diferencas */
42
+ extraLinesSurroundingDiff?: number;
43
+ }
44
+
45
+ const ArchbaseDiffViewer: React.FC<ArchbaseDiffViewerProps> = ({
46
+ oldValue,
47
+ newValue,
48
+ splitView = true,
49
+ showDiffOnly = false,
50
+ leftTitle,
51
+ rightTitle,
52
+ language,
53
+ compareMethod = DiffMethod.CHARS,
54
+ label,
55
+ description,
56
+ style,
57
+ className,
58
+ width,
59
+ height,
60
+ useDarkTheme,
61
+ hideLineNumbers = false,
62
+ extraLinesSurroundingDiff = 3,
63
+ }) => {
64
+ const computedColorScheme = useComputedColorScheme('light');
65
+ const darkTheme = useDarkTheme ?? computedColorScheme === 'dark';
66
+
67
+ const containerStyle: CSSProperties = {
68
+ width,
69
+ ...(height
70
+ ? {
71
+ maxHeight: height,
72
+ overflow: 'auto',
73
+ }
74
+ : {}),
75
+ ...style,
76
+ };
77
+
78
+ const diffContent = (
79
+ <Box className={className} style={containerStyle}>
80
+ <ReactDiffViewer
81
+ oldValue={oldValue}
82
+ newValue={newValue}
83
+ splitView={splitView}
84
+ showDiffOnly={showDiffOnly}
85
+ leftTitle={leftTitle}
86
+ rightTitle={rightTitle}
87
+ compareMethod={compareMethod}
88
+ useDarkTheme={darkTheme}
89
+ hideLineNumbers={hideLineNumbers}
90
+ extraLinesSurroundingDiff={extraLinesSurroundingDiff}
91
+ />
92
+ </Box>
93
+ );
94
+
95
+ if (label || description) {
96
+ return (
97
+ <Input.Wrapper label={label} description={description}>
98
+ {diffContent}
99
+ </Input.Wrapper>
100
+ );
101
+ }
102
+
103
+ return diffContent;
104
+ };
105
+
106
+ ArchbaseDiffViewer.displayName = 'ArchbaseDiffViewer';
107
+
108
+ export { ArchbaseDiffViewer };
@@ -0,0 +1,150 @@
1
+ import { useCallback, useEffect, useMemo } from 'react';
2
+ import { JsonView, allExpanded, darkStyles, defaultStyles, collapseAllNested } from 'react-json-view-lite';
3
+ import 'react-json-view-lite/dist/index.css';
4
+ import { Box, Input, ScrollArea, useMantineTheme, useComputedColorScheme } from '@mantine/core';
5
+ import {
6
+ useArchbaseV1V2Compatibility,
7
+ useArchbaseDataSourceListener,
8
+ } from '@archbase/data';
9
+ import type { IArchbaseDataSourceBase } from '@archbase/data';
10
+
11
+ export interface ArchbaseJsonTreeProps<T> {
12
+ /** DataSource to read the JSON object/string from */
13
+ dataSource?: IArchbaseDataSourceBase<T>;
14
+ /** Field name within the DataSource */
15
+ dataField?: string;
16
+ /** Standalone JSON data (object or JSON string) */
17
+ data?: object | string;
18
+ /** Label for Input.Wrapper */
19
+ label?: string;
20
+ /** Description for Input.Wrapper */
21
+ description?: string;
22
+ /** Error message for Input.Wrapper */
23
+ error?: string;
24
+ /** Whether nodes are expanded by default (default: true) */
25
+ defaultExpanded?: boolean;
26
+ /** Maximum depth to expand nodes */
27
+ maxDepth?: number;
28
+ /** Whether clicking a node expands/collapses it (default: true) */
29
+ clickToExpandNode?: boolean;
30
+ /** Custom style */
31
+ style?: React.CSSProperties;
32
+ /** Custom class name */
33
+ className?: string;
34
+ /** Width of the container */
35
+ width?: string | number;
36
+ /** Max height of the container (enables scroll) */
37
+ maxHeight?: string | number;
38
+ }
39
+
40
+ function ArchbaseJsonTree<T>({
41
+ dataSource,
42
+ dataField,
43
+ data: dataProp,
44
+ label,
45
+ description,
46
+ error,
47
+ defaultExpanded = true,
48
+ maxDepth,
49
+ clickToExpandNode = true,
50
+ style,
51
+ className,
52
+ width,
53
+ maxHeight,
54
+ }: ArchbaseJsonTreeProps<T>) {
55
+ const theme = useMantineTheme();
56
+ const colorScheme = useComputedColorScheme('light');
57
+ const isDark = colorScheme === 'dark';
58
+
59
+ const {
60
+ currentValue,
61
+ loadDataSourceFieldValue,
62
+ } = useArchbaseV1V2Compatibility<any>(
63
+ 'ArchbaseJsonTree',
64
+ dataSource,
65
+ dataField,
66
+ dataProp,
67
+ );
68
+
69
+ useEffect(() => {
70
+ if (dataSource && dataField) {
71
+ loadDataSourceFieldValue();
72
+ }
73
+ }, [dataSource, dataField, loadDataSourceFieldValue]);
74
+
75
+ const dataSourceEvent = useCallback((_event: any) => {
76
+ loadDataSourceFieldValue();
77
+ }, [loadDataSourceFieldValue]);
78
+
79
+ useArchbaseDataSourceListener({
80
+ dataSource,
81
+ listener: dataSourceEvent,
82
+ });
83
+
84
+ const parsedData = useMemo(() => {
85
+ if (currentValue === undefined || currentValue === null) {
86
+ return undefined;
87
+ }
88
+ if (typeof currentValue === 'string') {
89
+ try {
90
+ return JSON.parse(currentValue);
91
+ } catch {
92
+ return { __parseError: `Invalid JSON: ${currentValue}` };
93
+ }
94
+ }
95
+ if (typeof currentValue === 'object') {
96
+ return currentValue;
97
+ }
98
+ return currentValue;
99
+ }, [currentValue]);
100
+
101
+ const shouldExpandNode = useMemo(() => {
102
+ if (maxDepth !== undefined) {
103
+ return (level: number) => level < maxDepth;
104
+ }
105
+ return defaultExpanded ? allExpanded : collapseAllNested;
106
+ }, [defaultExpanded, maxDepth]);
107
+
108
+ const jsonStyles = isDark ? darkStyles : defaultStyles;
109
+
110
+ if (parsedData === undefined) {
111
+ return null;
112
+ }
113
+
114
+ const jsonView = (
115
+ <JsonView
116
+ data={parsedData}
117
+ shouldExpandNode={shouldExpandNode}
118
+ style={jsonStyles}
119
+ clickToExpandNode={clickToExpandNode}
120
+ />
121
+ );
122
+
123
+ const innerContent = maxHeight ? (
124
+ <ScrollArea style={{ maxHeight }} type="auto">
125
+ {jsonView}
126
+ </ScrollArea>
127
+ ) : (
128
+ jsonView
129
+ );
130
+
131
+ const content = (
132
+ <Box style={{ width, ...style }} className={className}>
133
+ {innerContent}
134
+ </Box>
135
+ );
136
+
137
+ if (label || description || error) {
138
+ return (
139
+ <Input.Wrapper label={label} description={description} error={error}>
140
+ {content}
141
+ </Input.Wrapper>
142
+ );
143
+ }
144
+
145
+ return content;
146
+ }
147
+
148
+ ArchbaseJsonTree.displayName = 'ArchbaseJsonTree';
149
+
150
+ export { ArchbaseJsonTree };