react-native-marked 8.1.1 → 8.2.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 (70) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +354 -354
  3. package/dist/commonjs/components/MDImage.js +3 -3
  4. package/dist/commonjs/components/MDImage.js.map +1 -1
  5. package/dist/commonjs/components/MDList.js.map +1 -1
  6. package/dist/commonjs/components/MDSvg.js.map +1 -1
  7. package/dist/commonjs/components/MDTable.js.map +1 -1
  8. package/dist/commonjs/hooks/useMarkdown.js.map +1 -1
  9. package/dist/commonjs/hooks/useMarkdownWithComponents.js.map +1 -1
  10. package/dist/commonjs/index.js.map +1 -1
  11. package/dist/commonjs/lib/Markdown.js.map +1 -1
  12. package/dist/commonjs/lib/Parser.js +4 -4
  13. package/dist/commonjs/lib/Parser.js.map +1 -1
  14. package/dist/commonjs/lib/ReactComponentRegistry.js.map +1 -1
  15. package/dist/commonjs/lib/ReactComponentTokenizer.js.map +1 -1
  16. package/dist/commonjs/lib/Renderer.js.map +1 -1
  17. package/dist/commonjs/lib/types.js.map +1 -1
  18. package/dist/commonjs/theme/colors.js.map +1 -1
  19. package/dist/commonjs/theme/spacing.js.map +1 -1
  20. package/dist/commonjs/theme/styles.js.map +1 -1
  21. package/dist/commonjs/theme/types.js.map +1 -1
  22. package/dist/commonjs/utils/handlers.js.map +1 -1
  23. package/dist/commonjs/utils/svg.js.map +1 -1
  24. package/dist/commonjs/utils/table.js.map +1 -1
  25. package/dist/commonjs/utils/url.js.map +1 -1
  26. package/dist/module/components/MDImage.js +3 -3
  27. package/dist/module/components/MDImage.js.map +1 -1
  28. package/dist/module/components/MDList.js.map +1 -1
  29. package/dist/module/components/MDSvg.js.map +1 -1
  30. package/dist/module/components/MDTable.js.map +1 -1
  31. package/dist/module/hooks/useMarkdown.js.map +1 -1
  32. package/dist/module/hooks/useMarkdownWithComponents.js.map +1 -1
  33. package/dist/module/index.js.map +1 -1
  34. package/dist/module/lib/Markdown.js.map +1 -1
  35. package/dist/module/lib/Parser.js +4 -4
  36. package/dist/module/lib/Parser.js.map +1 -1
  37. package/dist/module/lib/ReactComponentRegistry.js.map +1 -1
  38. package/dist/module/lib/ReactComponentTokenizer.js.map +1 -1
  39. package/dist/module/lib/Renderer.js.map +1 -1
  40. package/dist/module/lib/types.js.map +1 -1
  41. package/dist/module/theme/colors.js.map +1 -1
  42. package/dist/module/theme/spacing.js.map +1 -1
  43. package/dist/module/theme/styles.js.map +1 -1
  44. package/dist/module/theme/types.js.map +1 -1
  45. package/dist/module/utils/handlers.js.map +1 -1
  46. package/dist/module/utils/svg.js.map +1 -1
  47. package/dist/module/utils/table.js.map +1 -1
  48. package/dist/module/utils/url.js.map +1 -1
  49. package/package.json +175 -175
  50. package/src/components/MDImage.tsx +90 -90
  51. package/src/components/MDList.tsx +46 -46
  52. package/src/components/MDSvg.tsx +108 -108
  53. package/src/components/MDTable.tsx +60 -60
  54. package/src/hooks/useMarkdown.ts +51 -51
  55. package/src/hooks/useMarkdownWithComponents.tsx +89 -89
  56. package/src/index.ts +43 -43
  57. package/src/lib/Markdown.tsx +53 -53
  58. package/src/lib/Parser.tsx +316 -316
  59. package/src/lib/ReactComponentRegistry.tsx +52 -52
  60. package/src/lib/ReactComponentTokenizer.ts +149 -149
  61. package/src/lib/Renderer.tsx +238 -238
  62. package/src/lib/types.ts +87 -87
  63. package/src/theme/colors.ts +31 -31
  64. package/src/theme/spacing.ts +10 -10
  65. package/src/theme/styles.ts +198 -198
  66. package/src/theme/types.ts +33 -33
  67. package/src/utils/handlers.ts +9 -9
  68. package/src/utils/svg.ts +14 -14
  69. package/src/utils/table.ts +29 -29
  70. package/src/utils/url.ts +22 -22
@@ -1,90 +1,90 @@
1
- import React, {
2
- type FunctionComponent,
3
- memo,
4
- useEffect,
5
- useState,
6
- } from "react";
7
- import {
8
- ActivityIndicator,
9
- Image,
10
- ImageBackground,
11
- type ImageStyle,
12
- } from "react-native";
13
-
14
- type MDImageProps = {
15
- uri: string;
16
- label?: string;
17
- alt?: string;
18
- style?: ImageStyle;
19
- };
20
-
21
- type MDImageState = {
22
- isLoading: boolean;
23
- aspectRatio: number | undefined;
24
- };
25
-
26
- const MDImage: FunctionComponent<MDImageProps> = ({
27
- uri,
28
- label,
29
- alt = "Image",
30
- style,
31
- }) => {
32
- const [imageState, setImageState] = useState<MDImageState>({
33
- isLoading: true,
34
- aspectRatio: undefined,
35
- });
36
-
37
- /**
38
- * Fetches image dimension
39
- * Sets aspect ratio if resolved
40
- */
41
- const fetchOriginalSizeFromRemoteImage = () => {
42
- Image.getSize(
43
- uri,
44
- (width: number, height: number) => {
45
- if (width > 0 && height > 0) {
46
- setImageState({ isLoading: false, aspectRatio: width / height });
47
- } else {
48
- setImageState({ isLoading: false, aspectRatio: undefined });
49
- }
50
- },
51
- () => {
52
- setImageState((current) => {
53
- return {
54
- ...current,
55
- isLoading: false,
56
- };
57
- });
58
- },
59
- );
60
- };
61
-
62
- useEffect(() => {
63
- fetchOriginalSizeFromRemoteImage();
64
- });
65
-
66
- return (
67
- <ImageBackground
68
- source={{ uri: uri }}
69
- style={{
70
- width: "100%",
71
- aspectRatio: imageState.aspectRatio,
72
- }}
73
- aria-label={label}
74
- accessibilityRole="image"
75
- accessibilityLabel={alt}
76
- accessibilityHint={undefined}
77
- imageStyle={style}
78
- testID="react-native-marked-md-image"
79
- >
80
- {imageState.isLoading ? (
81
- <ActivityIndicator
82
- testID="react-native-marked-md-image-activity-indicator"
83
- size={"small"}
84
- />
85
- ) : null}
86
- </ImageBackground>
87
- );
88
- };
89
-
90
- export default memo(MDImage);
1
+ import React, {
2
+ type FunctionComponent,
3
+ memo,
4
+ useEffect,
5
+ useState,
6
+ } from "react";
7
+ import {
8
+ ActivityIndicator,
9
+ Image,
10
+ ImageBackground,
11
+ type ImageStyle,
12
+ } from "react-native";
13
+
14
+ type MDImageProps = {
15
+ uri: string;
16
+ label?: string;
17
+ alt?: string;
18
+ style?: ImageStyle;
19
+ };
20
+
21
+ type MDImageState = {
22
+ isLoading: boolean;
23
+ aspectRatio: number | undefined;
24
+ };
25
+
26
+ const MDImage: FunctionComponent<MDImageProps> = ({
27
+ uri,
28
+ label,
29
+ alt = "Image",
30
+ style,
31
+ }) => {
32
+ const [imageState, setImageState] = useState<MDImageState>({
33
+ isLoading: true,
34
+ aspectRatio: undefined,
35
+ });
36
+
37
+ /**
38
+ * Fetches image dimension
39
+ * Sets aspect ratio if resolved
40
+ */
41
+ const fetchOriginalSizeFromRemoteImage = () => {
42
+ Image.getSize(
43
+ uri,
44
+ (width: number, height: number) => {
45
+ if (width > 0 && height > 0) {
46
+ setImageState({ isLoading: false, aspectRatio: width / height });
47
+ } else {
48
+ setImageState({ isLoading: false, aspectRatio: undefined });
49
+ }
50
+ },
51
+ () => {
52
+ setImageState((current) => {
53
+ return {
54
+ ...current,
55
+ isLoading: false,
56
+ };
57
+ });
58
+ },
59
+ );
60
+ };
61
+
62
+ useEffect(() => {
63
+ fetchOriginalSizeFromRemoteImage();
64
+ });
65
+
66
+ return (
67
+ <ImageBackground
68
+ source={{ uri: uri }}
69
+ style={{
70
+ width: "100%",
71
+ aspectRatio: imageState.aspectRatio,
72
+ }}
73
+ aria-label={label}
74
+ accessibilityRole="image"
75
+ accessibilityLabel={alt}
76
+ accessibilityHint={undefined}
77
+ imageStyle={style}
78
+ testID="react-native-marked-md-image"
79
+ >
80
+ {imageState.isLoading ? (
81
+ <ActivityIndicator
82
+ testID="react-native-marked-md-image-activity-indicator"
83
+ size={"small"}
84
+ />
85
+ ) : null}
86
+ </ImageBackground>
87
+ );
88
+ };
89
+
90
+ export default memo(MDImage);
@@ -1,46 +1,46 @@
1
- import Decimal from "@jsamr/counter-style/presets/decimal";
2
- import Disc from "@jsamr/counter-style/presets/disc";
3
- import { MarkedListItem, useMarkedList } from "@jsamr/react-native-li";
4
- import React, {
5
- Fragment,
6
- type FunctionComponent,
7
- memo,
8
- type ReactNode,
9
- } from "react";
10
- import type { TextStyle, ViewStyle } from "react-native";
11
-
12
- type MDListProps = {
13
- ordered: boolean;
14
- li: ReactNode[];
15
- listStyle?: ViewStyle;
16
- textStyle?: TextStyle;
17
- startIndex?: number;
18
- };
19
-
20
- const MDList: FunctionComponent<MDListProps> = ({
21
- ordered,
22
- li,
23
- listStyle,
24
- textStyle,
25
- startIndex,
26
- }) => {
27
- const listProps = useMarkedList({
28
- counterRenderer: ordered ? Decimal : Disc,
29
- startIndex: startIndex,
30
- markerTextStyle: textStyle,
31
- markerBoxStyle: listStyle,
32
- length: li.length,
33
- });
34
-
35
- return (
36
- <Fragment>
37
- {li.map((node, index) => (
38
- <MarkedListItem key={index} index={index} {...listProps}>
39
- {node}
40
- </MarkedListItem>
41
- ))}
42
- </Fragment>
43
- );
44
- };
45
-
46
- export default memo(MDList);
1
+ import Decimal from "@jsamr/counter-style/presets/decimal";
2
+ import Disc from "@jsamr/counter-style/presets/disc";
3
+ import { MarkedListItem, useMarkedList } from "@jsamr/react-native-li";
4
+ import React, {
5
+ Fragment,
6
+ type FunctionComponent,
7
+ memo,
8
+ type ReactNode,
9
+ } from "react";
10
+ import type { TextStyle, ViewStyle } from "react-native";
11
+
12
+ type MDListProps = {
13
+ ordered: boolean;
14
+ li: ReactNode[];
15
+ listStyle?: ViewStyle;
16
+ textStyle?: TextStyle;
17
+ startIndex?: number;
18
+ };
19
+
20
+ const MDList: FunctionComponent<MDListProps> = ({
21
+ ordered,
22
+ li,
23
+ listStyle,
24
+ textStyle,
25
+ startIndex,
26
+ }) => {
27
+ const listProps = useMarkedList({
28
+ counterRenderer: ordered ? Decimal : Disc,
29
+ startIndex: startIndex,
30
+ markerTextStyle: textStyle,
31
+ markerBoxStyle: listStyle,
32
+ length: li.length,
33
+ });
34
+
35
+ return (
36
+ <Fragment>
37
+ {li.map((node, index) => (
38
+ <MarkedListItem key={index} index={index} {...listProps}>
39
+ {node}
40
+ </MarkedListItem>
41
+ ))}
42
+ </Fragment>
43
+ );
44
+ };
45
+
46
+ export default memo(MDList);
@@ -1,108 +1,108 @@
1
- import React, {
2
- type FunctionComponent,
3
- memo,
4
- useEffect,
5
- useRef,
6
- useState,
7
- } from "react";
8
- import { ActivityIndicator, type LayoutChangeEvent, View } from "react-native";
9
- import { SvgFromXml } from "react-native-svg";
10
- import { getSvgDimensions } from "./../utils/svg";
11
-
12
- type MDSvgProps = {
13
- uri: string;
14
- alt?: string;
15
- };
16
-
17
- type MdSvgState = {
18
- viewBox: string;
19
- width: number;
20
- height: number;
21
- svg: string;
22
- isLoading: boolean;
23
- error: boolean;
24
- aspectRatio?: number;
25
- };
26
-
27
- const MDSvg: FunctionComponent<MDSvgProps> = ({ uri, alt = "image" }) => {
28
- const isFirstLoad = useRef<boolean>(false);
29
- const [layoutWidth, setLayoutWidth] = useState<number>(0);
30
- const [svgState, setSvgState] = useState<MdSvgState>({
31
- viewBox: "",
32
- width: 0,
33
- height: 0,
34
- svg: "",
35
- isLoading: true,
36
- error: false,
37
- aspectRatio: undefined,
38
- });
39
- useEffect(() => {
40
- const fetchSvg = async () => {
41
- try {
42
- const res = await fetch(uri);
43
- const text = await res.text();
44
- if (res.status !== 200) {
45
- throw new Error("Status is not 200");
46
- }
47
- const { viewBox, width, height } = getSvgDimensions(text);
48
-
49
- setSvgState({
50
- width,
51
- height,
52
- viewBox,
53
- svg: text,
54
- isLoading: false,
55
- error: false,
56
- aspectRatio: width / height,
57
- });
58
- } catch (_e) {
59
- setSvgState((state) => ({
60
- ...state,
61
- error: true,
62
- isLoading: false,
63
- }));
64
- }
65
- };
66
-
67
- fetchSvg();
68
- }, [uri]);
69
-
70
- const onLayout = (event: LayoutChangeEvent) => {
71
- if (!isFirstLoad.current) {
72
- setLayoutWidth(event.nativeEvent.layout.width ?? 0);
73
- isFirstLoad.current = true;
74
- }
75
- };
76
-
77
- const getWidth = () => {
78
- if (layoutWidth && svgState.width) {
79
- return Math.min(layoutWidth, svgState.width);
80
- }
81
- return "100%";
82
- };
83
-
84
- return (
85
- <View
86
- style={{ width: getWidth(), aspectRatio: svgState.aspectRatio }}
87
- onLayout={onLayout}
88
- >
89
- {svgState.isLoading ? (
90
- <ActivityIndicator size={"small"} />
91
- ) : (
92
- <SvgFromXml
93
- xml={svgState.svg}
94
- width={"100%"}
95
- height={"100%"}
96
- viewBox={svgState.viewBox}
97
- aria-label={alt}
98
- accessibilityRole="image"
99
- accessibilityLabel={alt}
100
- accessibilityHint={undefined}
101
- testID="react-native-marked-md-svg"
102
- />
103
- )}
104
- </View>
105
- );
106
- };
107
-
108
- export default memo(MDSvg);
1
+ import React, {
2
+ type FunctionComponent,
3
+ memo,
4
+ useEffect,
5
+ useRef,
6
+ useState,
7
+ } from "react";
8
+ import { ActivityIndicator, type LayoutChangeEvent, View } from "react-native";
9
+ import { SvgFromXml } from "react-native-svg";
10
+ import { getSvgDimensions } from "./../utils/svg";
11
+
12
+ type MDSvgProps = {
13
+ uri: string;
14
+ alt?: string;
15
+ };
16
+
17
+ type MdSvgState = {
18
+ viewBox: string;
19
+ width: number;
20
+ height: number;
21
+ svg: string;
22
+ isLoading: boolean;
23
+ error: boolean;
24
+ aspectRatio?: number;
25
+ };
26
+
27
+ const MDSvg: FunctionComponent<MDSvgProps> = ({ uri, alt = "image" }) => {
28
+ const isFirstLoad = useRef<boolean>(false);
29
+ const [layoutWidth, setLayoutWidth] = useState<number>(0);
30
+ const [svgState, setSvgState] = useState<MdSvgState>({
31
+ viewBox: "",
32
+ width: 0,
33
+ height: 0,
34
+ svg: "",
35
+ isLoading: true,
36
+ error: false,
37
+ aspectRatio: undefined,
38
+ });
39
+ useEffect(() => {
40
+ const fetchSvg = async () => {
41
+ try {
42
+ const res = await fetch(uri);
43
+ const text = await res.text();
44
+ if (res.status !== 200) {
45
+ throw new Error("Status is not 200");
46
+ }
47
+ const { viewBox, width, height } = getSvgDimensions(text);
48
+
49
+ setSvgState({
50
+ width,
51
+ height,
52
+ viewBox,
53
+ svg: text,
54
+ isLoading: false,
55
+ error: false,
56
+ aspectRatio: width / height,
57
+ });
58
+ } catch (_e) {
59
+ setSvgState((state) => ({
60
+ ...state,
61
+ error: true,
62
+ isLoading: false,
63
+ }));
64
+ }
65
+ };
66
+
67
+ fetchSvg();
68
+ }, [uri]);
69
+
70
+ const onLayout = (event: LayoutChangeEvent) => {
71
+ if (!isFirstLoad.current) {
72
+ setLayoutWidth(event.nativeEvent.layout.width ?? 0);
73
+ isFirstLoad.current = true;
74
+ }
75
+ };
76
+
77
+ const getWidth = () => {
78
+ if (layoutWidth && svgState.width) {
79
+ return Math.min(layoutWidth, svgState.width);
80
+ }
81
+ return "100%";
82
+ };
83
+
84
+ return (
85
+ <View
86
+ style={{ width: getWidth(), aspectRatio: svgState.aspectRatio }}
87
+ onLayout={onLayout}
88
+ >
89
+ {svgState.isLoading ? (
90
+ <ActivityIndicator size={"small"} />
91
+ ) : (
92
+ <SvgFromXml
93
+ xml={svgState.svg}
94
+ width={"100%"}
95
+ height={"100%"}
96
+ viewBox={svgState.viewBox}
97
+ aria-label={alt}
98
+ accessibilityRole="image"
99
+ accessibilityLabel={alt}
100
+ accessibilityHint={undefined}
101
+ testID="react-native-marked-md-svg"
102
+ />
103
+ )}
104
+ </View>
105
+ );
106
+ };
107
+
108
+ export default memo(MDSvg);
@@ -1,60 +1,60 @@
1
- import React, { type FunctionComponent, memo, type ReactNode } from "react";
2
- import { ScrollView, View, type ViewStyle } from "react-native";
3
- import { Cell, Table, TableWrapper } from "react-native-reanimated-table";
4
-
5
- type MDTableProps = {
6
- header: ReactNode[][];
7
- rows: ReactNode[][][];
8
- widthArr: number[];
9
- rowStyle?: ViewStyle;
10
- cellStyle?: ViewStyle;
11
- borderColor?: string;
12
- borderWidth?: number;
13
- tableStyle?: ViewStyle;
14
- };
15
-
16
- const MDTable: FunctionComponent<MDTableProps> = ({
17
- header,
18
- rows,
19
- widthArr,
20
- cellStyle,
21
- rowStyle,
22
- tableStyle,
23
- borderColor,
24
- borderWidth,
25
- }) => {
26
- return (
27
- <ScrollView horizontal={true}>
28
- <Table borderStyle={{ borderColor, borderWidth }} style={tableStyle}>
29
- <TableWrapper style={rowStyle}>
30
- {header.map((headerCol, index) => {
31
- return (
32
- <Cell
33
- width={widthArr[index]}
34
- key={`${index}`}
35
- data={<View style={cellStyle}>{headerCol}</View>}
36
- />
37
- );
38
- })}
39
- </TableWrapper>
40
- {rows.map((rowData, index) => {
41
- return (
42
- <TableWrapper key={`${index}`} style={rowStyle}>
43
- {rowData.map((cellData, cellIndex) => {
44
- return (
45
- <Cell
46
- width={widthArr[cellIndex]}
47
- key={`${cellIndex}`}
48
- data={<View style={cellStyle}>{cellData}</View>}
49
- />
50
- );
51
- })}
52
- </TableWrapper>
53
- );
54
- })}
55
- </Table>
56
- </ScrollView>
57
- );
58
- };
59
-
60
- export default memo(MDTable);
1
+ import React, { type FunctionComponent, memo, type ReactNode } from "react";
2
+ import { ScrollView, View, type ViewStyle } from "react-native";
3
+ import { Cell, Table, TableWrapper } from "react-native-reanimated-table";
4
+
5
+ type MDTableProps = {
6
+ header: ReactNode[][];
7
+ rows: ReactNode[][][];
8
+ widthArr: number[];
9
+ rowStyle?: ViewStyle;
10
+ cellStyle?: ViewStyle;
11
+ borderColor?: string;
12
+ borderWidth?: number;
13
+ tableStyle?: ViewStyle;
14
+ };
15
+
16
+ const MDTable: FunctionComponent<MDTableProps> = ({
17
+ header,
18
+ rows,
19
+ widthArr,
20
+ cellStyle,
21
+ rowStyle,
22
+ tableStyle,
23
+ borderColor,
24
+ borderWidth,
25
+ }) => {
26
+ return (
27
+ <ScrollView horizontal={true}>
28
+ <Table borderStyle={{ borderColor, borderWidth }} style={tableStyle}>
29
+ <TableWrapper style={rowStyle}>
30
+ {header.map((headerCol, index) => {
31
+ return (
32
+ <Cell
33
+ width={widthArr[index]}
34
+ key={`${index}`}
35
+ data={<View style={cellStyle}>{headerCol}</View>}
36
+ />
37
+ );
38
+ })}
39
+ </TableWrapper>
40
+ {rows.map((rowData, index) => {
41
+ return (
42
+ <TableWrapper key={`${index}`} style={rowStyle}>
43
+ {rowData.map((cellData, cellIndex) => {
44
+ return (
45
+ <Cell
46
+ width={widthArr[cellIndex]}
47
+ key={`${cellIndex}`}
48
+ data={<View style={cellStyle}>{cellData}</View>}
49
+ />
50
+ );
51
+ })}
52
+ </TableWrapper>
53
+ );
54
+ })}
55
+ </Table>
56
+ </ScrollView>
57
+ );
58
+ };
59
+
60
+ export default memo(MDTable);