react-native-nitro-markdown 0.6.2 → 0.7.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 (75) hide show
  1. package/README.md +128 -503
  2. package/android/gradle.properties +2 -2
  3. package/lib/commonjs/MarkdownSession.js +6 -2
  4. package/lib/commonjs/MarkdownSession.js.map +1 -1
  5. package/lib/commonjs/headless.js +0 -4
  6. package/lib/commonjs/headless.js.map +1 -1
  7. package/lib/commonjs/index.js.map +1 -1
  8. package/lib/commonjs/markdown-stream.js +8 -6
  9. package/lib/commonjs/markdown-stream.js.map +1 -1
  10. package/lib/commonjs/markdown.js +0 -1
  11. package/lib/commonjs/markdown.js.map +1 -1
  12. package/lib/commonjs/renderers/image.js +0 -1
  13. package/lib/commonjs/renderers/image.js.map +1 -1
  14. package/lib/commonjs/renderers/link.js +0 -1
  15. package/lib/commonjs/renderers/link.js.map +1 -1
  16. package/lib/commonjs/renderers/math.js +0 -1
  17. package/lib/commonjs/renderers/math.js.map +1 -1
  18. package/lib/commonjs/use-markdown-stream.js +23 -4
  19. package/lib/commonjs/use-markdown-stream.js.map +1 -1
  20. package/lib/module/MarkdownSession.js +6 -2
  21. package/lib/module/MarkdownSession.js.map +1 -1
  22. package/lib/module/headless.js +0 -4
  23. package/lib/module/headless.js.map +1 -1
  24. package/lib/module/index.js.map +1 -1
  25. package/lib/module/markdown-stream.js +8 -6
  26. package/lib/module/markdown-stream.js.map +1 -1
  27. package/lib/module/markdown.js +0 -1
  28. package/lib/module/markdown.js.map +1 -1
  29. package/lib/module/renderers/image.js +0 -1
  30. package/lib/module/renderers/image.js.map +1 -1
  31. package/lib/module/renderers/link.js +0 -1
  32. package/lib/module/renderers/link.js.map +1 -1
  33. package/lib/module/renderers/math.js +0 -1
  34. package/lib/module/renderers/math.js.map +1 -1
  35. package/lib/module/use-markdown-stream.js +22 -5
  36. package/lib/module/use-markdown-stream.js.map +1 -1
  37. package/lib/typescript/commonjs/MarkdownSession.d.ts +1 -1
  38. package/lib/typescript/commonjs/MarkdownSession.d.ts.map +1 -1
  39. package/lib/typescript/commonjs/headless.d.ts +6 -3
  40. package/lib/typescript/commonjs/headless.d.ts.map +1 -1
  41. package/lib/typescript/commonjs/index.d.ts +2 -1
  42. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  43. package/lib/typescript/commonjs/markdown-stream.d.ts +2 -1
  44. package/lib/typescript/commonjs/markdown-stream.d.ts.map +1 -1
  45. package/lib/typescript/commonjs/markdown.d.ts.map +1 -1
  46. package/lib/typescript/commonjs/renderers/image.d.ts.map +1 -1
  47. package/lib/typescript/commonjs/renderers/link.d.ts.map +1 -1
  48. package/lib/typescript/commonjs/renderers/math.d.ts.map +1 -1
  49. package/lib/typescript/commonjs/use-markdown-stream.d.ts +4 -1
  50. package/lib/typescript/commonjs/use-markdown-stream.d.ts.map +1 -1
  51. package/lib/typescript/module/MarkdownSession.d.ts +1 -1
  52. package/lib/typescript/module/MarkdownSession.d.ts.map +1 -1
  53. package/lib/typescript/module/headless.d.ts +6 -3
  54. package/lib/typescript/module/headless.d.ts.map +1 -1
  55. package/lib/typescript/module/index.d.ts +2 -1
  56. package/lib/typescript/module/index.d.ts.map +1 -1
  57. package/lib/typescript/module/markdown-stream.d.ts +2 -1
  58. package/lib/typescript/module/markdown-stream.d.ts.map +1 -1
  59. package/lib/typescript/module/markdown.d.ts.map +1 -1
  60. package/lib/typescript/module/renderers/image.d.ts.map +1 -1
  61. package/lib/typescript/module/renderers/link.d.ts.map +1 -1
  62. package/lib/typescript/module/renderers/math.d.ts.map +1 -1
  63. package/lib/typescript/module/use-markdown-stream.d.ts +4 -1
  64. package/lib/typescript/module/use-markdown-stream.d.ts.map +1 -1
  65. package/package.json +6 -5
  66. package/react-native-nitro-markdown.podspec +1 -1
  67. package/src/MarkdownSession.ts +9 -2
  68. package/src/headless.ts +35 -34
  69. package/src/index.ts +9 -1
  70. package/src/markdown-stream.tsx +12 -7
  71. package/src/markdown.tsx +0 -1
  72. package/src/renderers/image.tsx +0 -1
  73. package/src/renderers/link.tsx +0 -1
  74. package/src/renderers/math.tsx +0 -1
  75. package/src/use-markdown-stream.ts +53 -13
@@ -1,4 +1,4 @@
1
- import { useRef, useCallback, useState, useEffect } from "react";
1
+ import { useRef, useCallback, useState, useEffect, useMemo } from "react";
2
2
  import { createMarkdownSession } from "./MarkdownSession";
3
3
  import {
4
4
  createTimestampTimeline,
@@ -8,10 +8,11 @@ import {
8
8
 
9
9
  export type MarkdownSession = ReturnType<typeof createMarkdownSession>;
10
10
 
11
- export function useMarkdownSession() {
11
+ export function useMarkdownSession(initialText?: string) {
12
12
  const sessionRef = useRef<MarkdownSession | null>(null);
13
+ const initialTextRef = useRef(initialText);
13
14
  if (sessionRef.current === null) {
14
- sessionRef.current = createMarkdownSession();
15
+ sessionRef.current = createMarkdownSession(initialText);
15
16
  }
16
17
 
17
18
  const [isStreaming, setIsStreaming] = useState(false);
@@ -31,6 +32,15 @@ export function useMarkdownSession() {
31
32
  };
32
33
  }, []);
33
34
 
35
+ useEffect(() => {
36
+ if (initialText === undefined || initialTextRef.current === initialText) {
37
+ return;
38
+ }
39
+
40
+ initialTextRef.current = initialText;
41
+ sessionRef.current!.reset(initialText);
42
+ }, [initialText]);
43
+
34
44
  const stop = useCallback(() => {
35
45
  setIsStreaming(false);
36
46
  }, []);
@@ -55,16 +65,46 @@ export function useMarkdownSession() {
55
65
  return sessionRef.current!.replace(from, to, text);
56
66
  }, []);
57
67
 
58
- return {
59
- getSession,
60
- isStreaming,
61
- setIsStreaming,
62
- stop,
63
- clear,
64
- setHighlight,
65
- reset,
66
- replace,
67
- };
68
+ return useMemo(
69
+ () => ({
70
+ getSession,
71
+ isStreaming,
72
+ setIsStreaming,
73
+ stop,
74
+ clear,
75
+ setHighlight,
76
+ reset,
77
+ replace,
78
+ }),
79
+ [
80
+ clear,
81
+ getSession,
82
+ isStreaming,
83
+ replace,
84
+ reset,
85
+ setHighlight,
86
+ setIsStreaming,
87
+ stop,
88
+ ],
89
+ );
90
+ }
91
+
92
+ export type MarkdownSessionController = ReturnType<typeof useMarkdownSession>;
93
+
94
+ export function isMarkdownSessionController(
95
+ value: MarkdownSession | MarkdownSessionController,
96
+ ): value is MarkdownSessionController {
97
+ return typeof Reflect.get(value, "getSession") === "function";
98
+ }
99
+
100
+ export function resolveMarkdownSession(
101
+ session: MarkdownSession | MarkdownSessionController,
102
+ ): MarkdownSession {
103
+ if (isMarkdownSessionController(session)) {
104
+ return session.getSession();
105
+ }
106
+
107
+ return session;
68
108
  }
69
109
 
70
110
  export function useStream(timestamps?: Record<number, number>) {