ncore-ui-kit 1.1.0-alpha.6 → 1.1.0-alpha.7
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.
- package/lib/module/components/codeViewer/index.js +174 -56
- package/lib/module/components/codeViewer/index.js.map +1 -1
- package/lib/module/components/codeViewer/parser.js +47 -0
- package/lib/module/components/codeViewer/parser.js.map +1 -1
- package/lib/module/components/codeViewer/stylesheet.js +66 -1
- package/lib/module/components/codeViewer/stylesheet.js.map +1 -1
- package/lib/module/components/dateSelector/index.js.map +1 -1
- package/lib/module/components/dateTimeSheet/index.js.map +1 -1
- package/lib/module/components/embeddedMenu/index.js.map +1 -1
- package/lib/module/components/mainHeader/index.js.map +1 -1
- package/lib/module/components/menu/index.js.map +1 -1
- package/lib/module/components/monthSelector/index.js.map +1 -1
- package/lib/module/components/numericInput/index.js.map +1 -1
- package/lib/module/components/selectSheet/index.js.map +1 -1
- package/lib/module/components/textInput/index.js.map +1 -1
- package/lib/module/components/timeSelector/index.js.map +1 -1
- package/lib/module/components/yearSelector/index.js.map +1 -1
- package/lib/module/context/theme.js +4 -4
- package/lib/module/context/theme.js.map +1 -1
- package/lib/module/helpers/theme/palette.js +20 -13
- package/lib/module/helpers/theme/palette.js.map +1 -1
- package/lib/module/package.json +1 -1
- package/lib/package.json +1 -1
- package/lib/src/components/codeViewer/index.js +194 -58
- package/lib/src/components/codeViewer/parser.js +50 -0
- package/lib/src/components/codeViewer/stylesheet.js +67 -2
- package/lib/src/components/dateSelector/index.js +11 -8
- package/lib/src/components/dateTimeSheet/index.js +20 -8
- package/lib/src/components/embeddedMenu/index.js +22 -13
- package/lib/src/components/mainHeader/index.js +10 -7
- package/lib/src/components/menu/index.js +11 -5
- package/lib/src/components/monthSelector/index.js +11 -8
- package/lib/src/components/numericInput/index.js +3 -2
- package/lib/src/components/selectSheet/index.js +27 -13
- package/lib/src/components/textInput/index.js +3 -2
- package/lib/src/components/timeSelector/index.js +21 -12
- package/lib/src/components/yearSelector/index.js +11 -8
- package/lib/src/context/theme.js +4 -4
- package/lib/src/helpers/theme/palette.js +20 -13
- package/lib/tsconfig.build.tsbuildinfo +1 -1
- package/lib/typescript/package.json +1 -1
- package/lib/typescript/src/components/codeViewer/index.d.ts +1 -1
- package/lib/typescript/src/components/codeViewer/index.d.ts.map +1 -1
- package/lib/typescript/src/components/codeViewer/parser.d.ts +2 -0
- package/lib/typescript/src/components/codeViewer/parser.d.ts.map +1 -1
- package/lib/typescript/src/components/codeViewer/stylesheet.d.ts +293 -2
- package/lib/typescript/src/components/codeViewer/stylesheet.d.ts.map +1 -1
- package/lib/typescript/src/components/codeViewer/type.d.ts +6 -0
- package/lib/typescript/src/components/codeViewer/type.d.ts.map +1 -1
- package/lib/typescript/src/components/dateSelector/index.d.ts.map +1 -1
- package/lib/typescript/src/components/dateTimeSheet/index.d.ts.map +1 -1
- package/lib/typescript/src/components/embeddedMenu/index.d.ts.map +1 -1
- package/lib/typescript/src/components/mainHeader/index.d.ts.map +1 -1
- package/lib/typescript/src/components/menu/index.d.ts.map +1 -1
- package/lib/typescript/src/components/monthSelector/index.d.ts.map +1 -1
- package/lib/typescript/src/components/numericInput/index.d.ts.map +1 -1
- package/lib/typescript/src/components/selectSheet/index.d.ts.map +1 -1
- package/lib/typescript/src/components/textInput/index.d.ts.map +1 -1
- package/lib/typescript/src/components/timeSelector/index.d.ts.map +1 -1
- package/lib/typescript/src/components/yearSelector/index.d.ts.map +1 -1
- package/lib/typescript/src/helpers/theme/palette.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/codeViewer/index.tsx +284 -76
- package/src/components/codeViewer/parser.ts +55 -0
- package/src/components/codeViewer/stylesheet.ts +74 -2
- package/src/components/codeViewer/type.ts +6 -0
- package/src/components/dateSelector/index.tsx +12 -7
- package/src/components/dateTimeSheet/index.tsx +53 -35
- package/src/components/embeddedMenu/components/menuButton/index.tsx +2 -2
- package/src/components/embeddedMenu/index.tsx +42 -27
- package/src/components/mainHeader/index.tsx +14 -9
- package/src/components/menu/components/menuButton/index.tsx +2 -2
- package/src/components/menu/index.tsx +24 -14
- package/src/components/monthSelector/index.tsx +12 -7
- package/src/components/numericInput/index.tsx +11 -9
- package/src/components/selectSheet/index.tsx +59 -35
- package/src/components/siteLogo/index.tsx +2 -2
- package/src/components/snackBar/index.tsx +2 -2
- package/src/components/textInput/index.tsx +11 -9
- package/src/components/timeSelector/index.tsx +82 -73
- package/src/components/toast/index.tsx +2 -2
- package/src/components/yearSelector/index.tsx +12 -7
- package/src/context/theme.tsx +5 -5
- package/src/helpers/theme/palette.ts +25 -17
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from "react";
|
|
7
7
|
import {
|
|
8
8
|
Text as NativeText,
|
|
9
|
+
TouchableOpacity,
|
|
9
10
|
ScrollView,
|
|
10
11
|
Platform,
|
|
11
12
|
View
|
|
@@ -18,6 +19,8 @@ import stylesheet, {
|
|
|
18
19
|
useStyles
|
|
19
20
|
} from "./stylesheet";
|
|
20
21
|
import {
|
|
22
|
+
splitTokensIntoLines,
|
|
23
|
+
getLineIndentation,
|
|
21
24
|
parseCode
|
|
22
25
|
} from "./parser";
|
|
23
26
|
import {
|
|
@@ -27,14 +30,21 @@ import {
|
|
|
27
30
|
} from "../../core/hooks";
|
|
28
31
|
import Clipboard from "@react-native-clipboard/clipboard";
|
|
29
32
|
import {
|
|
33
|
+
ChevronRightIcon,
|
|
34
|
+
ChevronDownIcon,
|
|
30
35
|
CheckIcon,
|
|
31
36
|
CopyIcon
|
|
32
37
|
} from "lucide-react-native";
|
|
33
|
-
|
|
38
|
+
import {
|
|
39
|
+
webStyle
|
|
40
|
+
} from "../../utils";
|
|
34
41
|
import Button from "../button";
|
|
35
|
-
import Text from "../text";
|
|
36
42
|
|
|
37
43
|
const CodeViewer = ({
|
|
44
|
+
isLineNumberVisible = true,
|
|
45
|
+
autoFoldMaxLines = 60,
|
|
46
|
+
isCollapsible = true,
|
|
47
|
+
autoFold = false,
|
|
38
48
|
language,
|
|
39
49
|
code
|
|
40
50
|
}: ICodeViewerProps) => {
|
|
@@ -55,77 +65,177 @@ const CodeViewer = ({
|
|
|
55
65
|
|
|
56
66
|
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
|
57
67
|
|
|
58
|
-
const containerRef = useRef<import("react").ComponentRef<typeof View>>(null);
|
|
59
68
|
|
|
60
|
-
const [
|
|
61
|
-
stickyTop,
|
|
62
|
-
setStickyTop
|
|
63
|
-
] = useState<number>(0);
|
|
64
69
|
|
|
65
70
|
useEffect(() => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const handleScroll = (e: Event) => {
|
|
71
|
-
const el = containerRef.current as unknown as HTMLElement;
|
|
72
|
-
|
|
73
|
-
if (!el || !el.getBoundingClientRect) {
|
|
74
|
-
return;
|
|
71
|
+
return () => {
|
|
72
|
+
if (timeoutRef.current) {
|
|
73
|
+
clearTimeout(timeoutRef.current);
|
|
75
74
|
}
|
|
75
|
+
};
|
|
76
|
+
}, []);
|
|
76
77
|
|
|
77
|
-
|
|
78
|
+
const tokens = useMemo(() => parseCode(code, language), [
|
|
79
|
+
language,
|
|
80
|
+
code
|
|
81
|
+
]);
|
|
78
82
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
const lines = useMemo(() => {
|
|
84
|
+
return splitTokensIntoLines(tokens);
|
|
85
|
+
}, [tokens]);
|
|
82
86
|
|
|
83
|
-
|
|
84
|
-
|
|
87
|
+
const lineIndentations = useMemo(() => {
|
|
88
|
+
return lines.map((line) => getLineIndentation(line));
|
|
89
|
+
}, [lines]);
|
|
85
90
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
const isLineFoldable = useMemo(() => {
|
|
92
|
+
return lines.map((_, i) => {
|
|
93
|
+
const currentIndent = lineIndentations[i] as number;
|
|
94
|
+
for (let j = i + 1; j < lines.length; j++) {
|
|
95
|
+
const nextIndent = lineIndentations[j] as number;
|
|
96
|
+
const nextLineStr = (lines[j] as import("./type").Token[]).map((t) => t.value).join("").trim();
|
|
89
97
|
|
|
90
|
-
|
|
91
|
-
const maxOffset = rect.height - (50 + (spaces.spacingMd * 2));
|
|
98
|
+
if (nextLineStr.length === 0) continue;
|
|
92
99
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
if (nextIndent > currentIndent) {
|
|
101
|
+
return true;
|
|
102
|
+
} else {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
97
105
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
106
|
+
return false;
|
|
107
|
+
});
|
|
108
|
+
}, [
|
|
109
|
+
lines,
|
|
110
|
+
lineIndentations
|
|
111
|
+
]);
|
|
101
112
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}, []);
|
|
113
|
+
const hasAnyFoldableLine = useMemo(() => {
|
|
114
|
+
return isLineFoldable.some((foldable) => foldable);
|
|
115
|
+
}, [isLineFoldable]);
|
|
106
116
|
|
|
107
|
-
|
|
108
|
-
return () => {
|
|
109
|
-
if (timeoutRef.current) {
|
|
110
|
-
clearTimeout(timeoutRef.current);
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
}, []);
|
|
117
|
+
const actualIsCollapsible = isCollapsible && hasAnyFoldableLine;
|
|
114
118
|
|
|
115
119
|
const {
|
|
120
|
+
languageText: languageTextDynamicStyle,
|
|
116
121
|
container: containerDynamicStyle,
|
|
122
|
+
lineRow: lineRowDynamicStyle,
|
|
123
|
+
gutter: gutterDynamicStyle,
|
|
117
124
|
text: textDynamicStyle
|
|
118
125
|
} = useStyles({
|
|
126
|
+
isLineNumberVisible,
|
|
127
|
+
isCollapsible: actualIsCollapsible,
|
|
119
128
|
typography,
|
|
120
129
|
colors,
|
|
121
130
|
spaces
|
|
122
131
|
});
|
|
123
132
|
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
133
|
+
const initialCollapsedLines = useMemo(() => {
|
|
134
|
+
const collapsed = new Set<number>();
|
|
135
|
+
if (!autoFold || !actualIsCollapsible) return collapsed;
|
|
136
|
+
|
|
137
|
+
let minIndent = Infinity;
|
|
138
|
+
for (let i = 0; i < lines.length; i++) {
|
|
139
|
+
if (isLineFoldable[i]) {
|
|
140
|
+
const indent = lineIndentations[i] as number;
|
|
141
|
+
if (indent < minIndent) {
|
|
142
|
+
minIndent = indent;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
for (let i = 0; i < lines.length; i++) {
|
|
148
|
+
if (isLineFoldable[i]) {
|
|
149
|
+
const startIndent = lineIndentations[i] as number;
|
|
150
|
+
|
|
151
|
+
if (startIndent <= minIndent) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
let blockLength = 0;
|
|
156
|
+
|
|
157
|
+
for (let j = i + 1; j < lines.length; j++) {
|
|
158
|
+
const currentIndent = lineIndentations[j] as number;
|
|
159
|
+
const lineStr = (lines[j] as import("./type").Token[]).map((t) => t.value).join("").trim();
|
|
160
|
+
|
|
161
|
+
if (lineStr.length !== 0 && currentIndent <= startIndent) {
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
blockLength++;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (blockLength > autoFoldMaxLines) {
|
|
169
|
+
collapsed.add(i);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return collapsed;
|
|
174
|
+
}, [
|
|
175
|
+
autoFoldMaxLines,
|
|
176
|
+
lineIndentations,
|
|
177
|
+
isLineFoldable,
|
|
178
|
+
autoFold,
|
|
179
|
+
lines
|
|
180
|
+
]);
|
|
181
|
+
|
|
182
|
+
const [
|
|
183
|
+
collapsedLines,
|
|
184
|
+
setCollapsedLines
|
|
185
|
+
] = useState<Set<number>>(initialCollapsedLines);
|
|
186
|
+
|
|
187
|
+
useEffect(() => {
|
|
188
|
+
setCollapsedLines(initialCollapsedLines);
|
|
189
|
+
}, [
|
|
190
|
+
initialCollapsedLines
|
|
127
191
|
]);
|
|
128
192
|
|
|
193
|
+
const visibleLines = useMemo(() => {
|
|
194
|
+
const visible = new Set<number>();
|
|
195
|
+
const activeFolds: number[] = [];
|
|
196
|
+
|
|
197
|
+
for (let i = 0; i < lines.length; i++) {
|
|
198
|
+
const indent = lineIndentations[i] as number;
|
|
199
|
+
const lineStr = (lines[i] as import("./type").Token[]).map((t) => t.value).join("").trim();
|
|
200
|
+
const isEmpty = lineStr.length === 0;
|
|
201
|
+
|
|
202
|
+
if (!isEmpty) {
|
|
203
|
+
while (activeFolds.length > 0 && indent <= (activeFolds[activeFolds.length - 1] as number)) {
|
|
204
|
+
activeFolds.pop();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (activeFolds.length > 0) {
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
visible.add(i);
|
|
213
|
+
|
|
214
|
+
if (actualIsCollapsible && collapsedLines.has(i) && isLineFoldable[i]) {
|
|
215
|
+
activeFolds.push(indent);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return visible;
|
|
219
|
+
}, [
|
|
220
|
+
lineIndentations,
|
|
221
|
+
isLineFoldable,
|
|
222
|
+
collapsedLines,
|
|
223
|
+
actualIsCollapsible,
|
|
224
|
+
lines
|
|
225
|
+
]);
|
|
226
|
+
|
|
227
|
+
const toggleFold = (lineIndex: number) => {
|
|
228
|
+
setCollapsedLines((prev) => {
|
|
229
|
+
const next = new Set(prev);
|
|
230
|
+
if (next.has(lineIndex)) {
|
|
231
|
+
next.delete(lineIndex);
|
|
232
|
+
} else {
|
|
233
|
+
next.add(lineIndex);
|
|
234
|
+
}
|
|
235
|
+
return next;
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
|
|
129
239
|
const getTokenColor = (type: TokenType) => {
|
|
130
240
|
return colors.code[type as keyof typeof colors.code] || colors.code.default;
|
|
131
241
|
};
|
|
@@ -176,7 +286,6 @@ const CodeViewer = ({
|
|
|
176
286
|
};
|
|
177
287
|
|
|
178
288
|
return <View
|
|
179
|
-
ref={containerRef}
|
|
180
289
|
style={[
|
|
181
290
|
stylesheet.container,
|
|
182
291
|
containerDynamicStyle
|
|
@@ -193,40 +302,139 @@ const CodeViewer = ({
|
|
|
193
302
|
}
|
|
194
303
|
]}
|
|
195
304
|
>
|
|
196
|
-
<
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
305
|
+
<View>
|
|
306
|
+
{
|
|
307
|
+
language ?
|
|
308
|
+
<NativeText
|
|
309
|
+
selectable={false}
|
|
310
|
+
style={[
|
|
311
|
+
stylesheet.content,
|
|
312
|
+
textDynamicStyle,
|
|
313
|
+
languageTextDynamicStyle
|
|
314
|
+
]}
|
|
315
|
+
>
|
|
316
|
+
// {language}
|
|
317
|
+
</NativeText>
|
|
318
|
+
:
|
|
319
|
+
null
|
|
320
|
+
}
|
|
321
|
+
{lines.map((lineTokens, index) => {
|
|
322
|
+
if (!visibleLines.has(index)) return null;
|
|
323
|
+
|
|
324
|
+
const isFoldable = isLineFoldable[index];
|
|
325
|
+
const isCollapsed = collapsedLines.has(index);
|
|
326
|
+
const isGutterVisible = isLineNumberVisible || actualIsCollapsible;
|
|
327
|
+
|
|
328
|
+
return <View
|
|
329
|
+
key={`line-${index}`}
|
|
330
|
+
style={[
|
|
331
|
+
stylesheet.lineRow,
|
|
332
|
+
lineRowDynamicStyle
|
|
333
|
+
]}
|
|
214
334
|
>
|
|
215
|
-
{
|
|
216
|
-
|
|
335
|
+
{
|
|
336
|
+
isGutterVisible ?
|
|
337
|
+
<View
|
|
338
|
+
style={[
|
|
339
|
+
stylesheet.gutter,
|
|
340
|
+
gutterDynamicStyle,
|
|
341
|
+
{
|
|
342
|
+
borderRightColor: colors.content.border.subtle
|
|
343
|
+
}
|
|
344
|
+
]}
|
|
345
|
+
>
|
|
346
|
+
{
|
|
347
|
+
isLineNumberVisible ?
|
|
348
|
+
<NativeText
|
|
349
|
+
selectable={false}
|
|
350
|
+
style={[
|
|
351
|
+
stylesheet.lineNumber,
|
|
352
|
+
{
|
|
353
|
+
fontFamily: Platform.OS === "web" ? "monospace" : "System",
|
|
354
|
+
color: colors.content.text.low
|
|
355
|
+
}
|
|
356
|
+
]}
|
|
357
|
+
>
|
|
358
|
+
{index + 1}
|
|
359
|
+
</NativeText>
|
|
360
|
+
:
|
|
361
|
+
null
|
|
362
|
+
}
|
|
363
|
+
{
|
|
364
|
+
actualIsCollapsible ?
|
|
365
|
+
isFoldable ?
|
|
366
|
+
<TouchableOpacity
|
|
367
|
+
style={stylesheet.foldIcon}
|
|
368
|
+
onPress={() => {
|
|
369
|
+
toggleFold(index);
|
|
370
|
+
}}
|
|
371
|
+
>
|
|
372
|
+
{
|
|
373
|
+
isCollapsed ?
|
|
374
|
+
<ChevronRightIcon
|
|
375
|
+
color={colors.content.text.low}
|
|
376
|
+
size={14}
|
|
377
|
+
/>
|
|
378
|
+
:
|
|
379
|
+
<ChevronDownIcon
|
|
380
|
+
color={colors.content.text.low}
|
|
381
|
+
size={14}
|
|
382
|
+
/>
|
|
383
|
+
}
|
|
384
|
+
</TouchableOpacity>
|
|
385
|
+
:
|
|
386
|
+
<View
|
|
387
|
+
style={stylesheet.foldIconPlaceholder}
|
|
388
|
+
/>
|
|
389
|
+
:
|
|
390
|
+
null
|
|
391
|
+
}
|
|
392
|
+
</View>
|
|
393
|
+
:
|
|
394
|
+
null
|
|
395
|
+
}
|
|
396
|
+
<NativeText
|
|
397
|
+
style={[
|
|
398
|
+
stylesheet.content,
|
|
399
|
+
textDynamicStyle,
|
|
400
|
+
{
|
|
401
|
+
color: colors.content.text.high
|
|
402
|
+
}
|
|
403
|
+
]}
|
|
404
|
+
>
|
|
405
|
+
{lineTokens.map((token, tIndex) => {
|
|
406
|
+
return <NativeText
|
|
407
|
+
key={`token-${index}-${tIndex}`}
|
|
408
|
+
style={{
|
|
409
|
+
color: getTokenColor(token.type)
|
|
410
|
+
}}
|
|
411
|
+
>
|
|
412
|
+
{token.value}
|
|
413
|
+
</NativeText>;
|
|
414
|
+
})}
|
|
415
|
+
{isCollapsed && (
|
|
416
|
+
<NativeText
|
|
417
|
+
style={{
|
|
418
|
+
backgroundColor: colors.content.container.subtle,
|
|
419
|
+
color: colors.content.text.mid
|
|
420
|
+
}}
|
|
421
|
+
>
|
|
422
|
+
{" ... "}
|
|
423
|
+
</NativeText>)}
|
|
424
|
+
</NativeText>
|
|
425
|
+
</View>;
|
|
217
426
|
})}
|
|
218
|
-
</
|
|
427
|
+
</View>
|
|
219
428
|
</ScrollView>
|
|
220
429
|
<View
|
|
221
430
|
style={[
|
|
222
431
|
stylesheet.stickyActionContainer,
|
|
223
432
|
{
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
marginLeft: spaces.spacingMd
|
|
433
|
+
marginLeft: spaces.spacingMd,
|
|
434
|
+
...webStyle({
|
|
435
|
+
position: "sticky",
|
|
436
|
+
top: spaces.spacingMd
|
|
437
|
+
})
|
|
230
438
|
}
|
|
231
439
|
]}
|
|
232
440
|
>
|
|
@@ -649,3 +649,58 @@ export const parseCode = (code: string, language?: string): Token[] => {
|
|
|
649
649
|
|
|
650
650
|
return tokens;
|
|
651
651
|
};
|
|
652
|
+
|
|
653
|
+
export const splitTokensIntoLines = (tokens: Token[]): Token[][] => {
|
|
654
|
+
const lines: Token[][] = [];
|
|
655
|
+
let currentLine: Token[] = [];
|
|
656
|
+
|
|
657
|
+
tokens.forEach((token) => {
|
|
658
|
+
if (token.value.includes("\n")) {
|
|
659
|
+
const parts = token.value.split("\n");
|
|
660
|
+
parts.forEach((part, index) => {
|
|
661
|
+
if (part.length > 0) {
|
|
662
|
+
currentLine.push({
|
|
663
|
+
...token,
|
|
664
|
+
value: part
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
if (index < parts.length - 1) {
|
|
669
|
+
lines.push(currentLine);
|
|
670
|
+
|
|
671
|
+
currentLine = [];
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
} else {
|
|
675
|
+
currentLine.push(token);
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
if (currentLine.length > 0) {
|
|
679
|
+
lines.push(currentLine);
|
|
680
|
+
}
|
|
681
|
+
return lines;
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
export const getLineIndentation = (lineTokens: Token[]): number => {
|
|
685
|
+
let indentation = 0;
|
|
686
|
+
for (const token of lineTokens) {
|
|
687
|
+
if (token.type === "text") {
|
|
688
|
+
const match = token.value.match(/^(\s+)/);
|
|
689
|
+
|
|
690
|
+
if (match) {
|
|
691
|
+
const matchLen = (match[1] as string).length;
|
|
692
|
+
|
|
693
|
+
indentation += matchLen;
|
|
694
|
+
|
|
695
|
+
if (matchLen !== token.value.length) {
|
|
696
|
+
break;
|
|
697
|
+
}
|
|
698
|
+
} else if (token.value.length > 0) {
|
|
699
|
+
break;
|
|
700
|
+
}
|
|
701
|
+
} else {
|
|
702
|
+
break;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
return indentation;
|
|
706
|
+
};
|
|
@@ -15,7 +15,6 @@ const stylesheet = StyleSheet.create({
|
|
|
15
15
|
container: {
|
|
16
16
|
alignItems: "flex-start",
|
|
17
17
|
flexDirection: "row",
|
|
18
|
-
overflow: "hidden",
|
|
19
18
|
borderRadius: 10,
|
|
20
19
|
borderWidth: 1
|
|
21
20
|
},
|
|
@@ -34,14 +33,71 @@ const stylesheet = StyleSheet.create({
|
|
|
34
33
|
...webStyle({
|
|
35
34
|
whiteSpace: Platform.OS === "web" ? "pre" : "pre-wrap"
|
|
36
35
|
})
|
|
36
|
+
},
|
|
37
|
+
lineRow: {
|
|
38
|
+
alignItems: "flex-start",
|
|
39
|
+
flexDirection: "row",
|
|
40
|
+
minHeight: 24
|
|
41
|
+
},
|
|
42
|
+
gutter: {
|
|
43
|
+
justifyContent: "flex-end",
|
|
44
|
+
flexDirection: "row",
|
|
45
|
+
alignItems: "center",
|
|
46
|
+
borderRightWidth: 1,
|
|
47
|
+
...webStyle({
|
|
48
|
+
userSelect: "none"
|
|
49
|
+
})
|
|
50
|
+
},
|
|
51
|
+
lineNumber: {
|
|
52
|
+
textAlign: "right",
|
|
53
|
+
marginRight: 4,
|
|
54
|
+
fontSize: 12,
|
|
55
|
+
...webStyle({
|
|
56
|
+
userSelect: "none"
|
|
57
|
+
})
|
|
58
|
+
},
|
|
59
|
+
foldIcon: {
|
|
60
|
+
justifyContent: "center",
|
|
61
|
+
alignItems: "center",
|
|
62
|
+
height: 14,
|
|
63
|
+
width: 14
|
|
64
|
+
},
|
|
65
|
+
foldIconPlaceholder: {
|
|
66
|
+
height: 14,
|
|
67
|
+
width: 14
|
|
37
68
|
}
|
|
38
69
|
});
|
|
39
70
|
|
|
40
71
|
export const useStyles = ({
|
|
72
|
+
isLineNumberVisible = true,
|
|
73
|
+
isCollapsible = true,
|
|
41
74
|
typography,
|
|
42
75
|
colors,
|
|
43
76
|
spaces
|
|
44
77
|
}: ICodeViewerDynamicStyleProps) => {
|
|
78
|
+
const isGutterVisible = isLineNumberVisible || isCollapsible;
|
|
79
|
+
|
|
80
|
+
let gutterPaddingRight = 10;
|
|
81
|
+
let gutterMarginRight = 10;
|
|
82
|
+
|
|
83
|
+
let gutterWidth = 50;
|
|
84
|
+
|
|
85
|
+
if (isLineNumberVisible && !isCollapsible) {
|
|
86
|
+
gutterPaddingRight = 6;
|
|
87
|
+
gutterMarginRight = 8;
|
|
88
|
+
|
|
89
|
+
gutterWidth = 32;
|
|
90
|
+
} else if (!isLineNumberVisible && isCollapsible) {
|
|
91
|
+
gutterWidth = 30;
|
|
92
|
+
} else if (!isGutterVisible) {
|
|
93
|
+
gutterPaddingRight = 0;
|
|
94
|
+
gutterMarginRight = 0;
|
|
95
|
+
|
|
96
|
+
gutterWidth = 0;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const languageMarginLeft = spaces.spacingSm;
|
|
100
|
+
|
|
45
101
|
const styles = {
|
|
46
102
|
container: {
|
|
47
103
|
backgroundColor: colors.content.container.subtle,
|
|
@@ -52,7 +108,23 @@ export const useStyles = ({
|
|
|
52
108
|
text: {
|
|
53
109
|
...typography.bodyMediumSize,
|
|
54
110
|
lineHeight: 24
|
|
55
|
-
} as TextStyle
|
|
111
|
+
} as TextStyle,
|
|
112
|
+
languageText: {
|
|
113
|
+
color: colors.content.text.low,
|
|
114
|
+
marginBottom: spaces.spacingSm,
|
|
115
|
+
marginLeft: languageMarginLeft,
|
|
116
|
+
...webStyle({
|
|
117
|
+
userSelect: "none"
|
|
118
|
+
})
|
|
119
|
+
} as TextStyle,
|
|
120
|
+
gutter: {
|
|
121
|
+
paddingRight: gutterPaddingRight,
|
|
122
|
+
marginRight: gutterMarginRight,
|
|
123
|
+
width: gutterWidth
|
|
124
|
+
} as ViewStyle,
|
|
125
|
+
lineRow: {
|
|
126
|
+
marginLeft: !isGutterVisible ? spaces.spacingSm : 0
|
|
127
|
+
} as ViewStyle
|
|
56
128
|
};
|
|
57
129
|
|
|
58
130
|
return styles;
|
|
@@ -9,9 +9,15 @@ export interface ICodeViewerDynamicStyleProps {
|
|
|
9
9
|
typography: NCoreUIKit.ActivePalette["typography"];
|
|
10
10
|
spaces: NCoreUIKit.ActivePalette["spaces"];
|
|
11
11
|
colors: NCoreUIKit.ActivePalette["colors"];
|
|
12
|
+
isLineNumberVisible?: boolean;
|
|
13
|
+
isCollapsible?: boolean;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
interface ICodeViewerProps {
|
|
17
|
+
isLineNumberVisible?: boolean;
|
|
18
|
+
autoFoldMaxLines?: number;
|
|
19
|
+
isCollapsible?: boolean;
|
|
20
|
+
autoFold?: boolean;
|
|
15
21
|
language?: string;
|
|
16
22
|
code: string;
|
|
17
23
|
}
|
|
@@ -329,16 +329,21 @@ const DateSelector = ({
|
|
|
329
329
|
>
|
|
330
330
|
{dayItem.dayNumber}
|
|
331
331
|
</Text>
|
|
332
|
-
{
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
332
|
+
{
|
|
333
|
+
isShowTodayIndicator && dayItem.isToday ?
|
|
334
|
+
<View
|
|
335
|
+
style={[
|
|
336
|
+
stylesheet.todayIndicator,
|
|
337
|
+
selectionStyle,
|
|
338
|
+
todayIndicatorDynamicStyle,
|
|
337
339
|
dayItem.isSelected ? {
|
|
338
340
|
borderColor: colors.content.border.subtle
|
|
339
341
|
} : null
|
|
340
|
-
|
|
341
|
-
|
|
342
|
+
]}
|
|
343
|
+
/>
|
|
344
|
+
:
|
|
345
|
+
null
|
|
346
|
+
}
|
|
342
347
|
</TouchableOpacity>;
|
|
343
348
|
};
|
|
344
349
|
|