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.
- package/README.md +383 -120
- package/lib/commonjs/components/RichTextInput.js +0 -4
- package/lib/commonjs/components/RichTextInput.js.map +1 -1
- package/lib/commonjs/constants/defaultStyles.js +6 -10
- package/lib/commonjs/constants/defaultStyles.js.map +1 -1
- package/lib/commonjs/hooks/useFormatting.js +9 -5
- package/lib/commonjs/hooks/useFormatting.js.map +1 -1
- package/lib/commonjs/utils/formatter.js.map +1 -1
- package/lib/module/components/RichTextInput.js +0 -4
- package/lib/module/components/RichTextInput.js.map +1 -1
- package/lib/module/constants/defaultStyles.js +6 -10
- package/lib/module/constants/defaultStyles.js.map +1 -1
- package/lib/module/hooks/useFormatting.js +9 -5
- package/lib/module/hooks/useFormatting.js.map +1 -1
- package/lib/module/utils/formatter.js.map +1 -1
- package/lib/typescript/src/components/RichTextInput.d.ts.map +1 -1
- package/lib/typescript/src/constants/defaultStyles.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useFormatting.d.ts.map +1 -1
- package/lib/typescript/src/utils/formatter.d.ts +1 -1
- package/lib/typescript/src/utils/formatter.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/RichTextInput.tsx +0 -4
- package/src/constants/defaultStyles.ts +6 -7
- package/src/hooks/useFormatting.ts +30 -5
- package/src/utils/formatter.ts +1 -1
|
@@ -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
|
|
181
|
-
{ id: 'link', label: '
|
|
182
|
-
{ id: '
|
|
183
|
-
{ id: 'align-
|
|
184
|
-
{ id: 'align-
|
|
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:
|
|
119
|
-
heading:
|
|
126
|
+
listType: nextListType === 'none' ? undefined : nextListType,
|
|
127
|
+
heading:
|
|
128
|
+
nextListType === 'none' ? activeStyles.heading : undefined,
|
|
120
129
|
});
|
|
121
130
|
}
|
|
122
131
|
|
|
123
|
-
const newSegments = setListTypeOnLine(
|
|
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(
|
|
165
|
+
const newSegments = setTextAlignOnLine(
|
|
166
|
+
segments,
|
|
167
|
+
selection,
|
|
168
|
+
nextTextAlign,
|
|
169
|
+
);
|
|
145
170
|
onSegmentsChange(newSegments);
|
|
146
171
|
},
|
|
147
172
|
[
|
package/src/utils/formatter.ts
CHANGED
|
@@ -95,7 +95,7 @@ export function setListTypeOnLine(
|
|
|
95
95
|
export function setTextAlignOnLine(
|
|
96
96
|
segments: StyledSegment[],
|
|
97
97
|
selection: SelectionRange,
|
|
98
|
-
textAlign
|
|
98
|
+
textAlign?: TextAlign,
|
|
99
99
|
): StyledSegment[] {
|
|
100
100
|
return setLineStyleOnSelection(segments, selection, {
|
|
101
101
|
textAlign,
|