react-native-richify 1.0.5 → 1.0.6

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.
@@ -176,13 +176,12 @@ export const DEFAULT_TOOLBAR_ITEMS: ToolbarItem[] = [
176
176
  { id: 'h1', label: 'H1', heading: 'h1' },
177
177
  { id: 'h2', label: 'H2', heading: 'h2' },
178
178
  { id: 'h3', label: 'H3', heading: 'h3' },
179
- { id: 'bullet', label: '\u2022', listType: 'bullet' },
180
- { id: 'ordered', label: '1.', listType: 'ordered' },
181
- { id: 'link', label: 'Link', actionType: 'link' },
182
- { id: 'image', label: 'Img', actionType: 'image' },
183
- { id: 'align-left', label: 'L', textAlign: 'left' },
184
- { id: 'align-center', label: 'C', textAlign: 'center' },
185
- { id: 'align-right', label: 'R', textAlign: 'right' },
179
+ { id: 'bullet', label: '\u2022\u2261', listType: 'bullet' },
180
+ { id: 'ordered', label: '1\u2261', listType: 'ordered' },
181
+ { id: 'link', label: '\ud83d\udd17', actionType: 'link' },
182
+ { id: 'align-left', label: '\u21e4', textAlign: 'left' },
183
+ { id: 'align-center', label: '\u2194', textAlign: 'center' },
184
+ { id: 'align-right', label: '\u21e5', textAlign: 'right' },
186
185
  { id: 'format-markdown', label: 'MD', outputFormat: 'markdown' },
187
186
  { id: 'format-html', label: 'HTML', outputFormat: 'html' },
188
187
  { id: 'preview-literal', label: 'Raw', outputPreviewMode: 'literal' },
@@ -112,15 +112,28 @@ export function useFormatting({
112
112
 
113
113
  const setListType = useCallback(
114
114
  (listType: ListType) => {
115
+ const currentListType =
116
+ selection.start === selection.end
117
+ ? getSelectionStyle(segments, selection).listType ??
118
+ activeStyles.listType
119
+ : getSelectionStyle(segments, selection).listType;
120
+ const nextListType: ListType =
121
+ currentListType === listType ? 'none' : listType;
122
+
115
123
  if (selection.start === selection.end) {
116
124
  onActiveStylesChange({
117
125
  ...activeStyles,
118
- listType: listType === 'none' ? undefined : listType,
119
- heading: listType === 'none' ? activeStyles.heading : undefined,
126
+ listType: nextListType === 'none' ? undefined : nextListType,
127
+ heading:
128
+ nextListType === 'none' ? activeStyles.heading : undefined,
120
129
  });
121
130
  }
122
131
 
123
- const newSegments = setListTypeOnLine(segments, selection, listType);
132
+ const newSegments = setListTypeOnLine(
133
+ segments,
134
+ selection,
135
+ nextListType,
136
+ );
124
137
  onSegmentsChange(newSegments);
125
138
  },
126
139
  [
@@ -134,14 +147,26 @@ export function useFormatting({
134
147
 
135
148
  const setTextAlign = useCallback(
136
149
  (textAlign: TextAlign) => {
150
+ const currentTextAlign =
151
+ selection.start === selection.end
152
+ ? getSelectionStyle(segments, selection).textAlign ??
153
+ activeStyles.textAlign
154
+ : getSelectionStyle(segments, selection).textAlign;
155
+ const nextTextAlign =
156
+ currentTextAlign === textAlign ? undefined : textAlign;
157
+
137
158
  if (selection.start === selection.end) {
138
159
  onActiveStylesChange({
139
160
  ...activeStyles,
140
- textAlign,
161
+ textAlign: nextTextAlign,
141
162
  });
142
163
  }
143
164
 
144
- const newSegments = setTextAlignOnLine(segments, selection, textAlign);
165
+ const newSegments = setTextAlignOnLine(
166
+ segments,
167
+ selection,
168
+ nextTextAlign,
169
+ );
145
170
  onSegmentsChange(newSegments);
146
171
  },
147
172
  [
@@ -95,7 +95,7 @@ export function setListTypeOnLine(
95
95
  export function setTextAlignOnLine(
96
96
  segments: StyledSegment[],
97
97
  selection: SelectionRange,
98
- textAlign: TextAlign,
98
+ textAlign?: TextAlign,
99
99
  ): StyledSegment[] {
100
100
  return setLineStyleOnSelection(segments, selection, {
101
101
  textAlign,