react-native-enriched 0.3.0 → 0.4.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 (202) hide show
  1. package/README.md +6 -4
  2. package/android/build.gradle +3 -3
  3. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerDelegate.java +3 -0
  4. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerInterface.java +1 -0
  5. package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ComponentDescriptors.cpp +1 -1
  6. package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ComponentDescriptors.h +1 -1
  7. package/{ios/generated/RNEnrichedTextInputViewSpec → android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec}/EventEmitters.cpp +31 -29
  8. package/{ios/generated/RNEnrichedTextInputViewSpec → android/generated/jni/react/renderer/components/ReactNativeEnrichedSpec}/EventEmitters.h +22 -25
  9. package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/Props.h +57 -0
  10. package/android/gradle.properties +5 -5
  11. package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputViewPackage.kt → ReactNativeEnrichedPackage.kt} +3 -2
  12. package/android/src/main/java/com/swmansion/enriched/{utils → common}/AsyncDrawable.kt +40 -8
  13. package/android/src/main/java/com/swmansion/enriched/common/CheckboxDrawable.kt +81 -0
  14. package/android/src/main/java/com/swmansion/enriched/{utils → common}/EnrichedConstants.kt +1 -1
  15. package/android/src/main/java/com/swmansion/enriched/common/EnrichedStyle.kt +57 -0
  16. package/android/src/main/java/com/swmansion/enriched/{spans/utils → common}/ForceRedrawSpan.kt +1 -1
  17. package/android/src/main/java/com/swmansion/enriched/common/MentionStyle.kt +7 -0
  18. package/android/src/main/java/com/swmansion/enriched/{utils → common}/ResourceManager.kt +1 -1
  19. package/android/src/main/java/com/swmansion/enriched/{utils → common/parser}/EnrichedParser.java +126 -99
  20. package/android/src/main/java/com/swmansion/enriched/common/parser/EnrichedSpanFactory.kt +79 -0
  21. package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedBlockQuoteSpan.kt +9 -13
  22. package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedBoldSpan.kt +12 -0
  23. package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedCheckboxListSpan.kt +91 -0
  24. package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedCodeBlockSpan.kt +8 -12
  25. package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH1Span.kt +20 -0
  26. package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH2Span.kt +20 -0
  27. package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH3Span.kt +20 -0
  28. package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH4Span.kt +21 -0
  29. package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH5Span.kt +20 -0
  30. package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedH6Span.kt +20 -0
  31. package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedImageSpan.kt +43 -38
  32. package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedInlineCodeSpan.kt +7 -11
  33. package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedItalicSpan.kt +12 -0
  34. package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedLinkSpan.kt +7 -11
  35. package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedMentionSpan.kt +6 -10
  36. package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedOrderedListSpan.kt +12 -21
  37. package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedStrikeThroughSpan.kt +11 -0
  38. package/android/src/main/java/com/swmansion/enriched/common/spans/EnrichedUnderlineSpan.kt +11 -0
  39. package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/EnrichedUnorderedListSpan.kt +9 -13
  40. package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/interfaces/EnrichedBlockSpan.kt +1 -1
  41. package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/interfaces/EnrichedHeadingSpan.kt +1 -1
  42. package/android/src/main/java/com/swmansion/enriched/common/spans/interfaces/EnrichedInlineSpan.kt +3 -0
  43. package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/interfaces/EnrichedParagraphSpan.kt +1 -1
  44. package/android/src/main/java/com/swmansion/enriched/common/spans/interfaces/EnrichedSpan.kt +3 -0
  45. package/android/src/main/java/com/swmansion/enriched/{spans → common/spans}/interfaces/EnrichedZeroWidthSpaceSpan.kt +1 -1
  46. package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputConnectionWrapper.kt → textinput/EnrichedTextInputConnectionWrapper.kt} +2 -2
  47. package/android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputSpannableFactory.kt +83 -0
  48. package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputView.kt → textinput/EnrichedTextInputView.kt} +87 -51
  49. package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputViewLayoutManager.kt → textinput/EnrichedTextInputViewLayoutManager.kt} +1 -1
  50. package/android/src/main/java/com/swmansion/enriched/{EnrichedTextInputViewManager.kt → textinput/EnrichedTextInputViewManager.kt} +24 -17
  51. package/android/src/main/java/com/swmansion/enriched/{MeasurementStore.kt → textinput/MeasurementStore.kt} +5 -4
  52. package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/MentionHandler.kt +2 -2
  53. package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnChangeHtmlEvent.kt +1 -1
  54. package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnChangeSelectionEvent.kt +1 -1
  55. package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnChangeStateEvent.kt +1 -1
  56. package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnChangeTextEvent.kt +2 -2
  57. package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnInputBlurEvent.kt +1 -1
  58. package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnInputFocusEvent.kt +1 -1
  59. package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnInputKeyPressEvent.kt +1 -1
  60. package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnLinkDetectedEvent.kt +1 -1
  61. package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnMentionDetectedEvent.kt +1 -1
  62. package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnMentionEvent.kt +1 -1
  63. package/android/src/main/java/com/swmansion/enriched/textinput/events/OnPasteImagesEvent.kt +47 -0
  64. package/android/src/main/java/com/swmansion/enriched/{events → textinput/events}/OnRequestHtmlResultEvent.kt +1 -1
  65. package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputBlockQuoteSpan.kt +14 -0
  66. package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputBoldSpan.kt +14 -0
  67. package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputCheckboxListSpan.kt +15 -0
  68. package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputCodeBlockSpan.kt +14 -0
  69. package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH1Span.kt +14 -0
  70. package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH2Span.kt +14 -0
  71. package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH3Span.kt +14 -0
  72. package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH4Span.kt +14 -0
  73. package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH5Span.kt +14 -0
  74. package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputH6Span.kt +14 -0
  75. package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputImageSpan.kt +36 -0
  76. package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputInlineCodeSpan.kt +14 -0
  77. package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputItalicSpan.kt +14 -0
  78. package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputLinkSpan.kt +15 -0
  79. package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputMentionSpan.kt +18 -0
  80. package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputOrderedListSpan.kt +21 -0
  81. package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputStrikeThroughSpan.kt +14 -0
  82. package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputUnderlineSpan.kt +14 -0
  83. package/android/src/main/java/com/swmansion/enriched/textinput/spans/EnrichedInputUnorderedListSpan.kt +14 -0
  84. package/android/src/main/java/com/swmansion/enriched/{spans → textinput/spans}/EnrichedSpans.kt +39 -30
  85. package/android/src/main/java/com/swmansion/enriched/textinput/spans/interfaces/EnrichedInputSpan.kt +10 -0
  86. package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/HtmlStyle.kt +58 -43
  87. package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/InlineStyles.kt +4 -4
  88. package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/ListStyles.kt +77 -26
  89. package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/ParagraphStyles.kt +30 -25
  90. package/android/src/main/java/com/swmansion/enriched/{styles → textinput/styles}/ParametrizedStyles.kt +19 -19
  91. package/android/src/main/java/com/swmansion/enriched/{utils → textinput/utils}/EnrichedEditableFactory.kt +2 -2
  92. package/android/src/main/java/com/swmansion/enriched/{utils → textinput/utils}/EnrichedSelection.kt +15 -14
  93. package/android/src/main/java/com/swmansion/enriched/{utils → textinput/utils}/EnrichedSpanState.kt +15 -50
  94. package/android/src/main/java/com/swmansion/enriched/{utils → textinput/utils}/EnrichedSpannable.kt +3 -3
  95. package/android/src/main/java/com/swmansion/enriched/{utils → textinput/utils}/EnrichedSpannableStringBuilder.kt +2 -1
  96. package/android/src/main/java/com/swmansion/enriched/textinput/utils/RichContentReceiver.kt +127 -0
  97. package/android/src/main/java/com/swmansion/enriched/textinput/utils/Utils.kt +106 -0
  98. package/android/src/main/java/com/swmansion/enriched/{watchers → textinput/watchers}/EnrichedSpanWatcher.kt +10 -10
  99. package/android/src/main/java/com/swmansion/enriched/{watchers → textinput/watchers}/EnrichedTextWatcher.kt +3 -3
  100. package/android/src/main/new_arch/CMakeLists.txt +1 -1
  101. package/android/src/main/new_arch/ReactNativeEnrichedSpec.cpp +11 -0
  102. package/android/src/main/new_arch/ReactNativeEnrichedSpec.h +15 -0
  103. package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputMeasurementManager.h +1 -1
  104. package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputShadowNode.h +2 -2
  105. package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/conversions.h +1 -1
  106. package/ios/EnrichedTextInputView.h +1 -0
  107. package/ios/EnrichedTextInputView.mm +274 -55
  108. package/ios/config/InputConfig.h +10 -0
  109. package/ios/config/InputConfig.mm +119 -0
  110. package/ios/extensions/ImageExtension.h +35 -0
  111. package/ios/extensions/ImageExtension.mm +156 -0
  112. package/ios/extensions/LayoutManagerExtension.mm +115 -95
  113. package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ComponentDescriptors.cpp +1 -1
  114. package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ComponentDescriptors.h +1 -1
  115. package/{android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec → ios/generated/ReactNativeEnrichedSpec}/EventEmitters.cpp +31 -29
  116. package/{android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec → ios/generated/ReactNativeEnrichedSpec}/EventEmitters.h +22 -25
  117. package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/Props.h +57 -0
  118. package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/RCTComponentViewHelpers.h +21 -0
  119. package/ios/inputParser/InputParser.mm +135 -8
  120. package/ios/inputTextView/InputTextView.mm +118 -0
  121. package/ios/interfaces/ImageAttachment.h +1 -0
  122. package/ios/interfaces/ImageAttachment.mm +43 -4
  123. package/ios/interfaces/StyleHeaders.h +13 -2
  124. package/ios/interfaces/StyleTypeEnum.h +1 -0
  125. package/ios/internals/EnrichedTextInputViewState.cpp +6 -6
  126. package/ios/styles/CheckboxListStyle.mm +321 -0
  127. package/ios/styles/H1Style.mm +3 -0
  128. package/ios/styles/H2Style.mm +3 -0
  129. package/ios/styles/H3Style.mm +3 -0
  130. package/ios/styles/H4Style.mm +3 -0
  131. package/ios/styles/H5Style.mm +3 -0
  132. package/ios/styles/H6Style.mm +3 -0
  133. package/ios/styles/HeadingStyleBase.mm +150 -78
  134. package/ios/utils/CheckboxHitTestUtils.h +10 -0
  135. package/ios/utils/CheckboxHitTestUtils.mm +123 -0
  136. package/ios/utils/ParagraphAttributesUtils.mm +83 -53
  137. package/ios/utils/TextBlockTapGestureRecognizer.h +17 -0
  138. package/ios/utils/TextBlockTapGestureRecognizer.mm +56 -0
  139. package/ios/utils/ZeroWidthSpaceUtils.mm +14 -3
  140. package/lib/module/EnrichedTextInput.js +36 -11
  141. package/lib/module/EnrichedTextInput.js.map +1 -1
  142. package/lib/module/{EnrichedTextInputNativeComponent.ts → spec/EnrichedTextInputNativeComponent.ts} +40 -9
  143. package/lib/module/types.js +4 -0
  144. package/lib/module/types.js.map +1 -0
  145. package/lib/module/utils/normalizeHtmlStyle.js +6 -0
  146. package/lib/module/utils/normalizeHtmlStyle.js.map +1 -1
  147. package/lib/module/utils/nullthrows.js +9 -0
  148. package/lib/module/utils/nullthrows.js.map +1 -0
  149. package/lib/typescript/src/EnrichedTextInput.d.ts +9 -49
  150. package/lib/typescript/src/EnrichedTextInput.d.ts.map +1 -1
  151. package/lib/typescript/src/index.d.ts +2 -1
  152. package/lib/typescript/src/index.d.ts.map +1 -1
  153. package/lib/typescript/src/{EnrichedTextInputNativeComponent.d.ts → spec/EnrichedTextInputNativeComponent.d.ts} +33 -8
  154. package/lib/typescript/src/spec/EnrichedTextInputNativeComponent.d.ts.map +1 -0
  155. package/lib/typescript/src/types.d.ts +58 -0
  156. package/lib/typescript/src/types.d.ts.map +1 -0
  157. package/lib/typescript/src/utils/normalizeHtmlStyle.d.ts +2 -2
  158. package/lib/typescript/src/utils/normalizeHtmlStyle.d.ts.map +1 -1
  159. package/lib/typescript/src/utils/nullthrows.d.ts +2 -0
  160. package/lib/typescript/src/utils/nullthrows.d.ts.map +1 -0
  161. package/lib/typescript/src/utils/regexParser.d.ts +1 -1
  162. package/lib/typescript/src/utils/regexParser.d.ts.map +1 -1
  163. package/package.json +4 -4
  164. package/src/EnrichedTextInput.tsx +49 -62
  165. package/src/index.tsx +3 -1
  166. package/src/{EnrichedTextInputNativeComponent.ts → spec/EnrichedTextInputNativeComponent.ts} +40 -9
  167. package/src/types.ts +59 -0
  168. package/src/utils/normalizeHtmlStyle.ts +8 -5
  169. package/src/utils/nullthrows.ts +7 -0
  170. package/src/utils/regexParser.ts +1 -1
  171. package/android/src/main/java/com/swmansion/enriched/events/OnChangeStateDeprecatedEvent.kt +0 -21
  172. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBoldSpan.kt +0 -17
  173. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH1Span.kt +0 -24
  174. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH2Span.kt +0 -24
  175. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH3Span.kt +0 -24
  176. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH4Span.kt +0 -24
  177. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH5Span.kt +0 -24
  178. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH6Span.kt +0 -24
  179. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedItalicSpan.kt +0 -16
  180. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedStrikeThroughSpan.kt +0 -15
  181. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnderlineSpan.kt +0 -15
  182. package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedInlineSpan.kt +0 -3
  183. package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedSpan.kt +0 -9
  184. package/android/src/main/java/com/swmansion/enriched/utils/Utils.kt +0 -21
  185. package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.cpp +0 -22
  186. package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.h +0 -26
  187. package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts.map +0 -1
  188. /package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/Props.cpp +0 -0
  189. /package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ShadowNodes.cpp +0 -0
  190. /package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ShadowNodes.h +0 -0
  191. /package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/States.cpp +0 -0
  192. /package/android/generated/jni/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/States.h +0 -0
  193. /package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputComponentDescriptor.h +0 -0
  194. /package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputMeasurementManager.cpp +0 -0
  195. /package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputShadowNode.cpp +0 -0
  196. /package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputState.cpp +0 -0
  197. /package/android/src/main/new_arch/react/renderer/components/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/EnrichedTextInputState.h +0 -0
  198. /package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/Props.cpp +0 -0
  199. /package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ShadowNodes.cpp +0 -0
  200. /package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/ShadowNodes.h +0 -0
  201. /package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/States.cpp +0 -0
  202. /package/ios/generated/{RNEnrichedTextInputViewSpec → ReactNativeEnrichedSpec}/States.h +0 -0
@@ -0,0 +1,321 @@
1
+ #import "EnrichedTextInputView.h"
2
+ #import "FontExtension.h"
3
+ #import "OccurenceUtils.h"
4
+ #import "ParagraphsUtils.h"
5
+ #import "StyleHeaders.h"
6
+ #import "TextInsertionUtils.h"
7
+
8
+ @implementation CheckboxListStyle {
9
+ EnrichedTextInputView *_input;
10
+ }
11
+
12
+ + (StyleType)getStyleType {
13
+ return CheckboxList;
14
+ }
15
+
16
+ + (BOOL)isParagraphStyle {
17
+ return YES;
18
+ }
19
+
20
+ - (CGFloat)getHeadIndent {
21
+ return [_input->config checkboxListMarginLeft] +
22
+ [_input->config checkboxListGapWidth] +
23
+ [_input->config checkboxListBoxSize];
24
+ }
25
+
26
+ - (instancetype)initWithInput:(id)input {
27
+ self = [super init];
28
+ _input = (EnrichedTextInputView *)input;
29
+ return self;
30
+ }
31
+
32
+ - (void)applyStyle:(NSRange)range {
33
+ // Applying a checkbox list style requires a checked value,
34
+ // which is why this method is not implemented.
35
+ // Use 'applyStyleWithCheckedValue' and provide the checked value instead.
36
+ }
37
+
38
+ - (void)applyStyleWithCheckedValue:(BOOL)checked inRange:(NSRange)range {
39
+ BOOL isStylePresent = [self detectStyle:range];
40
+ if (range.length >= 1) {
41
+ isStylePresent ? [self removeAttributes:range]
42
+ : [self addAttributesWithCheckedValue:checked
43
+ inRange:range
44
+ withTypingAttr:YES];
45
+ } else {
46
+ isStylePresent
47
+ ? [self removeTypingAttributes]
48
+ : [self addAttributesWithCheckedValue:checked
49
+ inRange:_input->textView.selectedRange
50
+ withTypingAttr:YES];
51
+ ;
52
+ }
53
+ }
54
+
55
+ - (void)addAttributes:(NSRange)range withTypingAttr:(BOOL)withTypingAttr {
56
+ [self addAttributesWithCheckedValue:NO
57
+ inRange:range
58
+ withTypingAttr:withTypingAttr];
59
+ }
60
+
61
+ - (void)addTypingAttributes {
62
+ }
63
+
64
+ - (void)removeAttributes:(NSRange)range {
65
+ NSArray *paragraphs =
66
+ [ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView
67
+ range:range];
68
+
69
+ [_input->textView.textStorage beginEditing];
70
+
71
+ for (NSValue *value in paragraphs) {
72
+ NSRange range = [value rangeValue];
73
+ [_input->textView.textStorage
74
+ enumerateAttribute:NSParagraphStyleAttributeName
75
+ inRange:range
76
+ options:0
77
+ usingBlock:^(id _Nullable value, NSRange range,
78
+ BOOL *_Nonnull stop) {
79
+ NSMutableParagraphStyle *pStyle =
80
+ [(NSParagraphStyle *)value mutableCopy];
81
+ pStyle.textLists = @[];
82
+ pStyle.headIndent = 0;
83
+ pStyle.firstLineHeadIndent = 0;
84
+ [_input->textView.textStorage
85
+ addAttribute:NSParagraphStyleAttributeName
86
+ value:pStyle
87
+ range:range];
88
+ }];
89
+ }
90
+
91
+ [_input->textView.textStorage endEditing];
92
+
93
+ // also remove typing attributes
94
+ NSMutableDictionary *typingAttrs =
95
+ [_input->textView.typingAttributes mutableCopy];
96
+ NSMutableParagraphStyle *pStyle =
97
+ [typingAttrs[NSParagraphStyleAttributeName] mutableCopy];
98
+ pStyle.textLists = @[];
99
+ pStyle.headIndent = 0;
100
+ pStyle.firstLineHeadIndent = 0;
101
+ typingAttrs[NSParagraphStyleAttributeName] = pStyle;
102
+ _input->textView.typingAttributes = typingAttrs;
103
+ }
104
+
105
+ - (void)removeTypingAttributes {
106
+ [self removeAttributes:_input->textView.selectedRange];
107
+ }
108
+
109
+ - (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text {
110
+ if ([self detectStyle:_input->textView.selectedRange] && text.length == 0) {
111
+ // backspace while the style is active
112
+
113
+ NSRange paragraphRange = [_input->textView.textStorage.string
114
+ paragraphRangeForRange:_input->textView.selectedRange];
115
+
116
+ if (NSEqualRanges(_input->textView.selectedRange, NSMakeRange(0, 0))) {
117
+ // a backspace on the very first input's line list point
118
+ // it doesn't run textVieDidChange so we need to manually remove
119
+ // attributes
120
+ [self removeAttributes:paragraphRange];
121
+ return YES;
122
+ } else if (range.location == paragraphRange.location - 1) {
123
+ // same case in other lines; here, the removed range location will be
124
+ // exactly 1 less than paragraph range location
125
+ [self removeAttributes:paragraphRange];
126
+ return YES;
127
+ }
128
+ }
129
+ return NO;
130
+ }
131
+
132
+ // used to make sure checkbox marker is correct when a newline is placed
133
+ - (BOOL)handleNewlinesInRange:(NSRange)range replacementText:(NSString *)text {
134
+ // in a checkbox list and a new text ends with a newline
135
+ if ([self detectStyle:_input->textView.selectedRange] && text.length > 0 &&
136
+ [[NSCharacterSet newlineCharacterSet]
137
+ characterIsMember:[text characterAtIndex:text.length - 1]]) {
138
+ // do the replacement manually
139
+ [TextInsertionUtils replaceText:text
140
+ at:range
141
+ additionalAttributes:nullptr
142
+ input:_input
143
+ withSelection:YES];
144
+ // apply checkbox attributes to the new paragraph
145
+ [self addAttributes:_input->textView.selectedRange withTypingAttr:YES];
146
+ return YES;
147
+ }
148
+ return NO;
149
+ }
150
+
151
+ - (void)toggleCheckedAt:(NSUInteger)location {
152
+ if (location >= _input->textView.textStorage.length) {
153
+ return;
154
+ }
155
+
156
+ NSParagraphStyle *pStyle =
157
+ [_input->textView.textStorage attribute:NSParagraphStyleAttributeName
158
+ atIndex:location
159
+ effectiveRange:NULL];
160
+ NSTextList *list = pStyle.textLists.firstObject;
161
+
162
+ BOOL isCurrentlyChecked = [list.markerFormat isEqualToString:@"{checkbox:1}"];
163
+
164
+ NSString *fullText = _input->textView.textStorage.string;
165
+ NSRange paragraphRange =
166
+ [fullText paragraphRangeForRange:NSMakeRange(location, 0)];
167
+
168
+ [self addAttributesWithCheckedValue:!isCurrentlyChecked
169
+ inRange:paragraphRange
170
+ withTypingAttr:NO];
171
+ }
172
+
173
+ - (void)addAttributesWithCheckedValue:(BOOL)checked
174
+ inRange:(NSRange)range
175
+ withTypingAttr:(BOOL)withTypingAttr {
176
+ NSString *markerFormat = checked ? @"{checkbox:1}" : @"{checkbox:0}";
177
+ NSTextList *checkboxMarker =
178
+ [[NSTextList alloc] initWithMarkerFormat:markerFormat options:0];
179
+ NSArray *paragraphs =
180
+ [ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView
181
+ range:range];
182
+ // if we fill empty lines with zero width spaces, we need to offset later
183
+ // ranges
184
+ NSInteger offset = 0;
185
+ // needed for range adjustments
186
+ NSRange preModificationRange = _input->textView.selectedRange;
187
+
188
+ // let's not emit some weird selection changes or text/html changes
189
+ _input->blockEmitting = YES;
190
+
191
+ for (NSValue *value in paragraphs) {
192
+ // take previous offsets into consideration
193
+ NSRange fixedRange = NSMakeRange([value rangeValue].location + offset,
194
+ [value rangeValue].length);
195
+
196
+ // length 0 with first line, length 1 and newline with some empty lines in
197
+ // the middle
198
+ if (fixedRange.length == 0 ||
199
+ (fixedRange.length == 1 &&
200
+ [[NSCharacterSet newlineCharacterSet]
201
+ characterIsMember:[_input->textView.textStorage.string
202
+ characterAtIndex:fixedRange.location]])) {
203
+ [TextInsertionUtils insertText:@"\u200B"
204
+ at:fixedRange.location
205
+ additionalAttributes:nullptr
206
+ input:_input
207
+ withSelection:NO];
208
+ fixedRange = NSMakeRange(fixedRange.location, fixedRange.length + 1);
209
+ offset += 1;
210
+ }
211
+
212
+ [_input->textView.textStorage
213
+ enumerateAttribute:NSParagraphStyleAttributeName
214
+ inRange:fixedRange
215
+ options:0
216
+ usingBlock:^(id _Nullable value, NSRange range,
217
+ BOOL *_Nonnull stop) {
218
+ NSMutableParagraphStyle *pStyle =
219
+ [(NSParagraphStyle *)value mutableCopy];
220
+ pStyle.textLists = @[ checkboxMarker ];
221
+ pStyle.headIndent = [self getHeadIndent];
222
+ pStyle.firstLineHeadIndent = [self getHeadIndent];
223
+ [_input->textView.textStorage
224
+ addAttribute:NSParagraphStyleAttributeName
225
+ value:pStyle
226
+ range:range];
227
+ }];
228
+ }
229
+
230
+ // back to emitting
231
+ _input->blockEmitting = NO;
232
+
233
+ if (preModificationRange.length == 0) {
234
+ // fix selection if only one line was possibly made a list and filled with a
235
+ // space
236
+ _input->textView.selectedRange = preModificationRange;
237
+ } else {
238
+ // in other cases, fix the selection with newly made offsets
239
+ _input->textView.selectedRange = NSMakeRange(
240
+ preModificationRange.location, preModificationRange.length + offset);
241
+ }
242
+
243
+ // also add typing attributes
244
+ if (withTypingAttr) {
245
+ NSMutableDictionary *typingAttrs =
246
+ [_input->textView.typingAttributes mutableCopy];
247
+ NSMutableParagraphStyle *pStyle =
248
+ [typingAttrs[NSParagraphStyleAttributeName] mutableCopy];
249
+ pStyle.textLists = @[ checkboxMarker ];
250
+ pStyle.headIndent = [self getHeadIndent];
251
+ pStyle.firstLineHeadIndent = [self getHeadIndent];
252
+ typingAttrs[NSParagraphStyleAttributeName] = pStyle;
253
+ _input->textView.typingAttributes = typingAttrs;
254
+ }
255
+ }
256
+
257
+ - (BOOL)styleCondition:(id _Nullable)value range:(NSRange)range {
258
+ NSParagraphStyle *paragraph = (NSParagraphStyle *)value;
259
+ return paragraph != nullptr && paragraph.textLists.count == 1 &&
260
+ [paragraph.textLists.firstObject.markerFormat hasPrefix:@"{checkbox"];
261
+ }
262
+
263
+ - (BOOL)detectStyle:(NSRange)range {
264
+ if (range.length >= 1) {
265
+ return [OccurenceUtils detect:NSParagraphStyleAttributeName
266
+ withInput:_input
267
+ inRange:range
268
+ withCondition:^BOOL(id _Nullable value, NSRange range) {
269
+ return [self styleCondition:value range:range];
270
+ }];
271
+ } else {
272
+ return [OccurenceUtils detect:NSParagraphStyleAttributeName
273
+ withInput:_input
274
+ atIndex:range.location
275
+ checkPrevious:YES
276
+ withCondition:^BOOL(id _Nullable value, NSRange range) {
277
+ return [self styleCondition:value range:range];
278
+ }];
279
+ }
280
+ }
281
+
282
+ - (BOOL)anyOccurence:(NSRange)range {
283
+ return [OccurenceUtils any:NSParagraphStyleAttributeName
284
+ withInput:_input
285
+ inRange:range
286
+ withCondition:^BOOL(id _Nullable value, NSRange range) {
287
+ return [self styleCondition:value range:range];
288
+ }];
289
+ }
290
+
291
+ - (NSArray<StylePair *> *_Nullable)findAllOccurences:(NSRange)range {
292
+ return [OccurenceUtils all:NSParagraphStyleAttributeName
293
+ withInput:_input
294
+ inRange:range
295
+ withCondition:^BOOL(id _Nullable value, NSRange range) {
296
+ return [self styleCondition:value range:range];
297
+ }];
298
+ }
299
+
300
+ - (BOOL)getCheckboxStateAt:(NSUInteger)location {
301
+ if (location >= _input->textView.textStorage.length) {
302
+ return NO;
303
+ }
304
+
305
+ NSParagraphStyle *style =
306
+ [_input->textView.textStorage attribute:NSParagraphStyleAttributeName
307
+ atIndex:location
308
+ effectiveRange:NULL];
309
+
310
+ if (style && style.textLists.count > 0) {
311
+ NSTextList *list = style.textLists.firstObject;
312
+
313
+ if ([list.markerFormat isEqualToString:@"{checkbox:1}"]) {
314
+ return YES;
315
+ }
316
+ }
317
+
318
+ return NO;
319
+ }
320
+
321
+ @end
@@ -5,6 +5,9 @@
5
5
  + (StyleType)getStyleType {
6
6
  return H1;
7
7
  }
8
+ - (NSString *)getHeadingLevelString {
9
+ return @"H1";
10
+ }
8
11
  + (BOOL)isParagraphStyle {
9
12
  return YES;
10
13
  }
@@ -5,6 +5,9 @@
5
5
  + (StyleType)getStyleType {
6
6
  return H2;
7
7
  }
8
+ - (NSString *)getHeadingLevelString {
9
+ return @"H2";
10
+ }
8
11
  + (BOOL)isParagraphStyle {
9
12
  return YES;
10
13
  }
@@ -5,6 +5,9 @@
5
5
  + (StyleType)getStyleType {
6
6
  return H3;
7
7
  }
8
+ - (NSString *)getHeadingLevelString {
9
+ return @"H3";
10
+ }
8
11
  + (BOOL)isParagraphStyle {
9
12
  return YES;
10
13
  }
@@ -5,6 +5,9 @@
5
5
  + (StyleType)getStyleType {
6
6
  return H4;
7
7
  }
8
+ - (NSString *)getHeadingLevelString {
9
+ return @"H4";
10
+ }
8
11
  + (BOOL)isParagraphStyle {
9
12
  return YES;
10
13
  }
@@ -5,6 +5,9 @@
5
5
  + (StyleType)getStyleType {
6
6
  return H5;
7
7
  }
8
+ - (NSString *)getHeadingLevelString {
9
+ return @"H5";
10
+ }
8
11
  + (BOOL)isParagraphStyle {
9
12
  return YES;
10
13
  }
@@ -5,6 +5,9 @@
5
5
  + (StyleType)getStyleType {
6
6
  return H6;
7
7
  }
8
+ - (NSString *)getHeadingLevelString {
9
+ return @"H6";
10
+ }
8
11
  + (BOOL)isParagraphStyle {
9
12
  return YES;
10
13
  }