@hero-design/rn 8.86.0 → 8.87.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.
@@ -50,7 +50,7 @@ exports[`StyledCard should render correctly 1`] = `
50
50
  </View>
51
51
  `;
52
52
 
53
- exports[`StyledItemWrapper should render correctly 1`] = `
53
+ exports[`StyledItemWrapper should render correctly with gap=medium 1`] = `
54
54
  <View
55
55
  style={
56
56
  {
@@ -67,6 +67,91 @@ exports[`StyledItemWrapper should render correctly 1`] = `
67
67
  undefined,
68
68
  ]
69
69
  }
70
+ themeGap="medium"
71
+ />
72
+ <View
73
+ pointerEvents="box-none"
74
+ position="bottom"
75
+ style={
76
+ [
77
+ {
78
+ "bottom": 0,
79
+ "elevation": 9999,
80
+ "flexDirection": "column-reverse",
81
+ "left": 0,
82
+ "paddingHorizontal": 24,
83
+ "paddingVertical": 16,
84
+ "position": "absolute",
85
+ "right": 0,
86
+ "top": 0,
87
+ },
88
+ undefined,
89
+ ]
90
+ }
91
+ />
92
+ </View>
93
+ `;
94
+
95
+ exports[`StyledItemWrapper should render correctly with gap=small 1`] = `
96
+ <View
97
+ style={
98
+ {
99
+ "flex": 1,
100
+ }
101
+ }
102
+ >
103
+ <View
104
+ style={
105
+ [
106
+ {
107
+ "padding": 4,
108
+ },
109
+ undefined,
110
+ ]
111
+ }
112
+ themeGap="small"
113
+ />
114
+ <View
115
+ pointerEvents="box-none"
116
+ position="bottom"
117
+ style={
118
+ [
119
+ {
120
+ "bottom": 0,
121
+ "elevation": 9999,
122
+ "flexDirection": "column-reverse",
123
+ "left": 0,
124
+ "paddingHorizontal": 24,
125
+ "paddingVertical": 16,
126
+ "position": "absolute",
127
+ "right": 0,
128
+ "top": 0,
129
+ },
130
+ undefined,
131
+ ]
132
+ }
133
+ />
134
+ </View>
135
+ `;
136
+
137
+ exports[`StyledItemWrapper should render correctly with gap=xsmall 1`] = `
138
+ <View
139
+ style={
140
+ {
141
+ "flex": 1,
142
+ }
143
+ }
144
+ >
145
+ <View
146
+ style={
147
+ [
148
+ {
149
+ "padding": 2,
150
+ },
151
+ undefined,
152
+ ]
153
+ }
154
+ themeGap="xsmall"
70
155
  />
71
156
  <View
72
157
  pointerEvents="box-none"
@@ -38,9 +38,13 @@ import * as Events from './utils/events';
38
38
  import { postMessage, requestBlurEditor } from './utils/rnWebView';
39
39
  import type { WebViewEventMessage } from './utils/rnWebView';
40
40
  import { LABEL_ANIMATION_DURATION } from '../TextInput';
41
+ import { TextUnit } from './types';
41
42
 
42
43
  export interface RichTextEditorRef {
43
44
  requestBlur: VoidFunction;
45
+ insertNodes: (nodes: Record<string, unknown>[]) => void;
46
+ deleteBackward: (unit?: TextUnit) => void;
47
+ setReadOnly: (readOnly: boolean) => void;
44
48
  }
45
49
 
46
50
  export type EditorValue = {
@@ -236,7 +240,32 @@ const RichTextEditor: ComponentType<RichTextEditorProps> = ({
236
240
  }
237
241
  }, [isFocused]);
238
242
 
239
- useImperativeHandle(forwardedRef, () => ({ requestBlur }), [requestBlur]);
243
+ const insertNodes = useCallback((nodes: Record<string, unknown>[]) => {
244
+ postMessageToWebview({
245
+ type: '@hero-editor/webview/editor-insert-nodes',
246
+ data: { nodes },
247
+ });
248
+ }, []);
249
+
250
+ const deleteBackward = useCallback((unit?: TextUnit) => {
251
+ postMessageToWebview({
252
+ type: '@hero-editor/webview/editor-delete-backward',
253
+ data: { unit },
254
+ });
255
+ }, []);
256
+
257
+ const setReadOnly = useCallback((readOnly: boolean) => {
258
+ postMessageToWebview({
259
+ type: '@hero-editor/webview/editor-read-only',
260
+ data: { readOnly },
261
+ });
262
+ }, []);
263
+
264
+ useImperativeHandle(
265
+ forwardedRef,
266
+ () => ({ requestBlur, insertNodes, deleteBackward, setReadOnly }),
267
+ [requestBlur, deleteBackward, insertNodes, setReadOnly]
268
+ );
240
269
 
241
270
  /* Forward events from Toolbar and MentionList to webview */
242
271
  useEffect(() => {
@@ -58,6 +58,7 @@ jest.mock('../utils/rnWebView', () => {
58
58
  /* eslint-disable */
59
59
  /// @ts-ignore
60
60
  import { postMessageMock } from '../utils/rnWebView';
61
+ import { RichTextEditorRef } from "../../../../types";
61
62
  /* eslint-enable */
62
63
 
63
64
  describe('RichTextEditor', () => {
@@ -205,6 +206,64 @@ describe('RichTextEditor', () => {
205
206
  });
206
207
  });
207
208
 
209
+ describe('RichTextEditorRef methods', () => {
210
+ let ref: React.RefObject<RichTextEditorRef>;
211
+
212
+ beforeEach(() => {
213
+ ref = React.createRef<RichTextEditorRef>();
214
+ renderWithTheme(
215
+ <RichTextEditor
216
+ name="rich-text-editor"
217
+ label="Rich Text Editor"
218
+ onChange={jest.fn()}
219
+ onCursorChange={jest.fn()}
220
+ error="this is error"
221
+ style={{ backgroundColor: 'yellow' }}
222
+ ref={ref}
223
+ />
224
+ );
225
+ });
226
+
227
+ it('should call insertNodes', () => {
228
+ const nodes = [{ text: 'test' }];
229
+
230
+ act(() => {
231
+ ref.current?.insertNodes(nodes);
232
+ });
233
+
234
+ expect(postMessageMock).toHaveBeenCalledWith({
235
+ data: { nodes },
236
+ type: '@hero-editor/webview/editor-insert-nodes',
237
+ });
238
+ });
239
+
240
+ it('should call deleteBackward', () => {
241
+ const unit = 'word';
242
+
243
+ act(() => {
244
+ ref.current?.deleteBackward(unit);
245
+ });
246
+
247
+ expect(postMessageMock).toHaveBeenCalledWith({
248
+ data: { unit },
249
+ type: '@hero-editor/webview/editor-delete-backward',
250
+ });
251
+ });
252
+
253
+ it('should call setReadOnly', () => {
254
+ const readOnly = true;
255
+
256
+ act(() => {
257
+ ref.current?.setReadOnly(readOnly);
258
+ });
259
+
260
+ expect(postMessageMock).toHaveBeenCalledWith({
261
+ data: { readOnly },
262
+ type: '@hero-editor/webview/editor-read-only',
263
+ });
264
+ });
265
+ });
266
+
208
267
  describe('postMessageToWebview', () => {
209
268
  const onChangeMock = jest.fn();
210
269
  const onCursorChangeMock = jest.fn();
@@ -7,3 +7,5 @@ export type ToolbarButtonName =
7
7
  | 'headingOne'
8
8
  | 'headingTwo'
9
9
  | '|';
10
+
11
+ export type TextUnit = 'character' | 'word' | 'line' | 'block';
@@ -366,7 +366,11 @@ exports[`theme returns correct theme object 1`] = `
366
366
  "card": 8,
367
367
  },
368
368
  "space": {
369
- "carouselItemSpacing": 8,
369
+ "carouselItemSpacing": {
370
+ "medium": 8,
371
+ "small": 4,
372
+ "xsmall": 2,
373
+ },
370
374
  "contentContainerPaddingHorizontal": 24,
371
375
  "pageControlMarginTop": 16,
372
376
  },
@@ -3,8 +3,12 @@ import type { GlobalTheme } from '../global';
3
3
  const getCardCarouselTheme = (theme: GlobalTheme) => {
4
4
  const space = {
5
5
  pageControlMarginTop: theme.space.medium,
6
- carouselItemSpacing: theme.space.small,
7
6
  contentContainerPaddingHorizontal: theme.space.large,
7
+ carouselItemSpacing: {
8
+ xsmall: theme.space.xxsmall,
9
+ small: theme.space.xsmall,
10
+ medium: theme.space.small,
11
+ },
8
12
  };
9
13
 
10
14
  const colors = {