react-native-jet-markdown 0.2.1 → 0.2.2
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 +4 -56
- package/android/src/main/cpp/JniBindings.cpp +0 -106
- package/android/src/main/java/com/jetmarkdown/JetMarkdownNative.kt +0 -79
- package/android/src/main/java/com/jetmarkdown/JetMarkdownPackage.kt +1 -2
- package/android/src/main/java/com/jetmarkdown/render/spans/MarkdownLineHeightSpan.kt +2 -13
- package/cpp/react/override/react/renderer/components/JetMarkdownViewSpec/ComponentDescriptors.h +0 -4
- package/cpp/tests/parser_tests.cpp +0 -402
- package/cpp/tests/run_tests.sh +0 -3
- package/lib/module/index.js +0 -2
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -3
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +0 -127
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/package.json +2 -5
- package/src/index.tsx +0 -9
- package/src/types.ts +0 -134
- package/android/src/main/java/com/jetmarkdown/editor/EditorSpans.kt +0 -217
- package/android/src/main/java/com/jetmarkdown/editor/JetMarkdownEditorManager.kt +0 -224
- package/android/src/main/java/com/jetmarkdown/editor/JetMarkdownEditorView.kt +0 -1736
- package/cpp/core/AstToMarkdown.cpp +0 -549
- package/cpp/core/AstToMarkdown.h +0 -16
- package/cpp/core/EditorRuns.cpp +0 -640
- package/cpp/core/EditorRuns.h +0 -94
- package/cpp/core/EditorText.cpp +0 -15
- package/cpp/core/EditorText.h +0 -18
- package/cpp/react/JetMarkdownEditorShadowNode.cpp +0 -54
- package/cpp/react/JetMarkdownEditorShadowNode.h +0 -55
- package/cpp/react/JetMarkdownEditorState.h +0 -35
- package/ios/editor/JetMarkdownEditor.h +0 -12
- package/ios/editor/JetMarkdownEditor.mm +0 -2002
- package/lib/module/JetMarkdownEditor.js +0 -85
- package/lib/module/JetMarkdownEditor.js.map +0 -1
- package/lib/module/JetMarkdownEditor.native.js +0 -244
- package/lib/module/JetMarkdownEditor.native.js.map +0 -1
- package/lib/module/JetMarkdownEditorNativeComponent.ts +0 -173
- package/lib/module/useJetMarkdownEditor.js +0 -41
- package/lib/module/useJetMarkdownEditor.js.map +0 -1
- package/lib/typescript/src/JetMarkdownEditor.d.ts +0 -6
- package/lib/typescript/src/JetMarkdownEditor.d.ts.map +0 -1
- package/lib/typescript/src/JetMarkdownEditor.native.d.ts +0 -6
- package/lib/typescript/src/JetMarkdownEditor.native.d.ts.map +0 -1
- package/lib/typescript/src/JetMarkdownEditorNativeComponent.d.ts +0 -105
- package/lib/typescript/src/JetMarkdownEditorNativeComponent.d.ts.map +0 -1
- package/lib/typescript/src/useJetMarkdownEditor.d.ts +0 -36
- package/lib/typescript/src/useJetMarkdownEditor.d.ts.map +0 -1
- package/src/JetMarkdownEditor.native.tsx +0 -301
- package/src/JetMarkdownEditor.tsx +0 -90
- package/src/JetMarkdownEditorNativeComponent.ts +0 -173
- package/src/useJetMarkdownEditor.ts +0 -50
package/src/index.tsx
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
/** biome-ignore-all lint/performance/noBarrelFile: go away */
|
|
2
2
|
|
|
3
3
|
export { defaultStyles, mergeStyles } from "./defaultStyles";
|
|
4
|
-
export { JetMarkdownEditor } from "./JetMarkdownEditor";
|
|
5
4
|
export { JetMarkdownView } from "./JetMarkdownView";
|
|
6
5
|
export type {
|
|
7
6
|
FontVariant,
|
|
8
7
|
FontWeight,
|
|
9
|
-
JetMarkdownEditorProps,
|
|
10
|
-
JetMarkdownEditorRef,
|
|
11
8
|
JetMarkdownViewProps,
|
|
12
9
|
MarkdownContainerStyle,
|
|
13
10
|
MarkdownDividerStyle,
|
|
14
|
-
MarkdownEditorState,
|
|
15
11
|
MarkdownHeadingLevel,
|
|
16
12
|
MarkdownImageData,
|
|
17
13
|
MarkdownImageEvent,
|
|
@@ -20,15 +16,10 @@ export type {
|
|
|
20
16
|
MarkdownLayoutStyle,
|
|
21
17
|
MarkdownListMarkerStyle,
|
|
22
18
|
MarkdownListStyle,
|
|
23
|
-
MarkdownMentionEvent,
|
|
24
|
-
MarkdownMentionQueryEvent,
|
|
25
19
|
MarkdownMentionStyle,
|
|
26
|
-
MarkdownPasteEvent,
|
|
27
|
-
MarkdownSelection,
|
|
28
20
|
MarkdownSpoilerStyle,
|
|
29
21
|
MarkdownStyles,
|
|
30
22
|
MarkdownTableStyle,
|
|
31
23
|
MarkdownTextStyle,
|
|
32
24
|
MarkdownUrlEvent,
|
|
33
25
|
} from "./types";
|
|
34
|
-
export { useJetMarkdownEditor } from "./useJetMarkdownEditor";
|
package/src/types.ts
CHANGED
|
@@ -274,10 +274,6 @@ export interface MarkdownContainerStyle extends MarkdownTextStyle {
|
|
|
274
274
|
backgroundColor?: ColorValue;
|
|
275
275
|
/** Vertical spacing between blocks; overrides `styles.gap`. */
|
|
276
276
|
gap?: number;
|
|
277
|
-
/**
|
|
278
|
-
* Editor: caps autogrow — past this height the editor scrolls
|
|
279
|
-
* internally like a textarea. Viewer: plain layout clamp.
|
|
280
|
-
*/
|
|
281
277
|
maxHeight?: number;
|
|
282
278
|
padding?: number;
|
|
283
279
|
paddingBottom?: number;
|
|
@@ -288,136 +284,6 @@ export interface MarkdownContainerStyle extends MarkdownTextStyle {
|
|
|
288
284
|
paddingVertical?: number;
|
|
289
285
|
}
|
|
290
286
|
|
|
291
|
-
/** Formatting active at the cursor / selection. */
|
|
292
|
-
export interface MarkdownEditorState {
|
|
293
|
-
/** 0 = no heading. */
|
|
294
|
-
headingLevel: number;
|
|
295
|
-
isBlockQuote: boolean;
|
|
296
|
-
isBold: boolean;
|
|
297
|
-
isCodeBlock: boolean;
|
|
298
|
-
isInlineCode: boolean;
|
|
299
|
-
isItalic: boolean;
|
|
300
|
-
isOrderedList: boolean;
|
|
301
|
-
isSpoiler: boolean;
|
|
302
|
-
isStrikethrough: boolean;
|
|
303
|
-
isSubscript: boolean;
|
|
304
|
-
isSuperscript: boolean;
|
|
305
|
-
isUnorderedList: boolean;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
export interface MarkdownSelection {
|
|
309
|
-
end: number;
|
|
310
|
-
start: number;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
export interface MarkdownMentionEvent {
|
|
314
|
-
trigger: string;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
export interface MarkdownMentionQueryEvent {
|
|
318
|
-
query: string;
|
|
319
|
-
trigger: string;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Paste payload. `text` is present when the clipboard has text (parsed as
|
|
324
|
-
* markdown and inserted by default); `images` when it has images (reported
|
|
325
|
-
* only, never auto-inserted). `preventDefault()` suppresses the default
|
|
326
|
-
* text insertion.
|
|
327
|
-
*/
|
|
328
|
-
export interface MarkdownPasteEvent {
|
|
329
|
-
images?: MarkdownImageData[];
|
|
330
|
-
preventDefault(): void;
|
|
331
|
-
text?: string;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
export interface JetMarkdownEditorRef {
|
|
335
|
-
blur(): void;
|
|
336
|
-
focus(): void;
|
|
337
|
-
/** Resolves the markdown as of the latest edit. */
|
|
338
|
-
getMarkdown(): Promise<string>;
|
|
339
|
-
/**
|
|
340
|
-
* Links the selection to `url`; with a collapsed cursor, inserts `label`
|
|
341
|
-
* (or the URL itself) as linked text.
|
|
342
|
-
*/
|
|
343
|
-
insertLink(url: string, label?: string): void;
|
|
344
|
-
/** Parses `markdown` and inserts it at the cursor (or over the selection). */
|
|
345
|
-
insertMarkdown(markdown: string): void;
|
|
346
|
-
/**
|
|
347
|
-
* Inserts an atomic mention token (`trigger + label`, e.g. `@ali`)
|
|
348
|
-
* linked to `url` (an app scheme like `users://ali`), replacing any
|
|
349
|
-
* active mention query.
|
|
350
|
-
*/
|
|
351
|
-
insertMention(trigger: string, label: string, url: string): void;
|
|
352
|
-
/** Removes the link covering the selection or cursor. */
|
|
353
|
-
removeLink(): void;
|
|
354
|
-
setSelection(start: number, end: number): void;
|
|
355
|
-
/** Replaces the content; the value is parsed as markdown. */
|
|
356
|
-
setValue(markdown: string): void;
|
|
357
|
-
/** Block toggles apply to every line the selection touches. */
|
|
358
|
-
toggleBlockQuote(): void;
|
|
359
|
-
/**
|
|
360
|
-
* Each inline toggle applies to the selection, or arms/disarms the mark
|
|
361
|
-
* for text typed at the collapsed cursor.
|
|
362
|
-
*/
|
|
363
|
-
toggleBold(): void;
|
|
364
|
-
toggleCode(): void;
|
|
365
|
-
toggleCodeBlock(): void;
|
|
366
|
-
/** Toggles the heading level (1-6) on the selected lines. */
|
|
367
|
-
toggleHeading(level: number): void;
|
|
368
|
-
toggleItalic(): void;
|
|
369
|
-
toggleOrderedList(): void;
|
|
370
|
-
toggleSpoiler(): void;
|
|
371
|
-
toggleStrikethrough(): void;
|
|
372
|
-
toggleSubscript(): void;
|
|
373
|
-
toggleSuperscript(): void;
|
|
374
|
-
toggleUnorderedList(): void;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
export interface JetMarkdownEditorProps {
|
|
378
|
-
/** Scale text with the system font size setting. Defaults to true. */
|
|
379
|
-
allowFontScaling?: boolean;
|
|
380
|
-
autoCapitalize?: "none" | "sentences" | "words" | "characters";
|
|
381
|
-
autoCorrect?: boolean;
|
|
382
|
-
autoFocus?: boolean;
|
|
383
|
-
/**
|
|
384
|
-
* Caret color. On iOS the caret and selection share one tint, so
|
|
385
|
-
* `selectionColor` wins when both are set. Android 10+ only. Platform
|
|
386
|
-
* colors (`PlatformColor`, `DynamicColorIOS`) are supported.
|
|
387
|
-
*/
|
|
388
|
-
cursorColor?: ColorValue;
|
|
389
|
-
/** Initial markdown content, applied once. */
|
|
390
|
-
defaultValue?: string;
|
|
391
|
-
editable?: boolean;
|
|
392
|
-
/** Trigger characters (e.g. '@', '#') that begin a mention. */
|
|
393
|
-
mentionTriggers?: string[];
|
|
394
|
-
multiline?: boolean;
|
|
395
|
-
onBlur?: () => void;
|
|
396
|
-
onChangeMarkdown?: (markdown: string) => void;
|
|
397
|
-
onChangeSelection?: (selection: MarkdownSelection) => void;
|
|
398
|
-
onChangeState?: (state: MarkdownEditorState) => void;
|
|
399
|
-
onChangeText?: (text: string) => void;
|
|
400
|
-
onFocus?: () => void;
|
|
401
|
-
onLinkDetected?: (event: MarkdownUrlEvent) => void;
|
|
402
|
-
onMentionChange?: (event: MarkdownMentionQueryEvent) => void;
|
|
403
|
-
onMentionEnd?: (event: MarkdownMentionEvent) => void;
|
|
404
|
-
onMentionStart?: (event: MarkdownMentionEvent) => void;
|
|
405
|
-
onPaste?: (event: MarkdownPasteEvent) => void;
|
|
406
|
-
placeholder?: string;
|
|
407
|
-
placeholderTextColor?: ColorValue;
|
|
408
|
-
scrollEnabled?: boolean;
|
|
409
|
-
/**
|
|
410
|
-
* Selection highlight color. On iOS this also tints the caret (UIKit
|
|
411
|
-
* shares one tint). Platform colors (`PlatformColor`, `DynamicColorIOS`)
|
|
412
|
-
* are supported.
|
|
413
|
-
*/
|
|
414
|
-
selectionColor?: ColorValue;
|
|
415
|
-
/** Same container style contract as the viewer. */
|
|
416
|
-
style?: StyleProp<MarkdownContainerStyle>;
|
|
417
|
-
/** Per-element markdown styles; shared shape with the viewer. */
|
|
418
|
-
styles?: MarkdownStyles;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
287
|
export interface JetMarkdownViewProps {
|
|
422
288
|
/** Scale text with the system font size setting. Defaults to true. */
|
|
423
289
|
allowFontScaling?: boolean;
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
package com.jetmarkdown.editor
|
|
2
|
-
|
|
3
|
-
import android.graphics.Canvas
|
|
4
|
-
import android.graphics.Paint
|
|
5
|
-
import android.graphics.Typeface
|
|
6
|
-
import android.text.Layout
|
|
7
|
-
import android.text.TextPaint
|
|
8
|
-
import android.text.style.LeadingMarginSpan
|
|
9
|
-
import android.text.style.MetricAffectingSpan
|
|
10
|
-
|
|
11
|
-
/** Inline mark bits; mirrors jetmarkdown::EditorMark in cpp/core/EditorRuns.h. */
|
|
12
|
-
object EditorMarks {
|
|
13
|
-
const val BOLD = 1
|
|
14
|
-
const val ITALIC = 1 shl 1
|
|
15
|
-
const val STRIKETHROUGH = 1 shl 2
|
|
16
|
-
const val INLINE_CODE = 1 shl 3
|
|
17
|
-
const val SPOILER = 1 shl 4
|
|
18
|
-
const val SUPERSCRIPT = 1 shl 5
|
|
19
|
-
const val SUBSCRIPT = 1 shl 6
|
|
20
|
-
|
|
21
|
-
val ALL = intArrayOf(
|
|
22
|
-
BOLD, ITALIC, STRIKETHROUGH, INLINE_CODE, SPOILER, SUPERSCRIPT, SUBSCRIPT,
|
|
23
|
-
)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Per-line block types; mirrors jetmarkdown::EditorBlockType. */
|
|
27
|
-
object EditorBlocks {
|
|
28
|
-
const val HEADING = 1
|
|
29
|
-
const val QUOTE = 2
|
|
30
|
-
const val CODE = 3
|
|
31
|
-
const val BULLET = 4
|
|
32
|
-
const val ORDERED = 5
|
|
33
|
-
|
|
34
|
-
fun pack(type: Int, level: Int): Int = (type shl 8) or level
|
|
35
|
-
|
|
36
|
-
fun type(packed: Int): Int = packed shr 8
|
|
37
|
-
|
|
38
|
-
fun level(packed: Int): Int = packed and 0xFF
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** Marker for every derived visual span; removed wholesale on rebuild. */
|
|
43
|
-
interface EditorDerivedSpan
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Data-only source of truth for one inline mark over a range. Visual styling
|
|
47
|
-
* is carried by derived spans rebuilt from these after every change.
|
|
48
|
-
*/
|
|
49
|
-
class EditorMarkSpan(val mark: Int)
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Data-only linked range. Mentions carry an app-scheme URL and `atomic`
|
|
53
|
-
* (the token edits as one unit).
|
|
54
|
-
*/
|
|
55
|
-
class LinkDataSpan(val url: String, val atomic: Boolean)
|
|
56
|
-
|
|
57
|
-
/** Derived link appearance. */
|
|
58
|
-
class LinkDisplaySpan(private val color: Int) :
|
|
59
|
-
android.text.style.CharacterStyle(),
|
|
60
|
-
EditorDerivedSpan {
|
|
61
|
-
override fun updateDrawState(paint: TextPaint) {
|
|
62
|
-
paint.color = color
|
|
63
|
-
paint.isUnderlineText = true
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** Derived visual styling for the combined mark flags of a range. */
|
|
68
|
-
class EditorDisplaySpan(private val flags: Int) : MetricAffectingSpan(), EditorDerivedSpan {
|
|
69
|
-
override fun updateMeasureState(paint: TextPaint) {
|
|
70
|
-
apply(paint)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
override fun updateDrawState(paint: TextPaint) {
|
|
74
|
-
apply(paint)
|
|
75
|
-
if (flags and EditorMarks.STRIKETHROUGH != 0) {
|
|
76
|
-
paint.isStrikeThruText = true
|
|
77
|
-
}
|
|
78
|
-
if (flags and EditorMarks.INLINE_CODE != 0) {
|
|
79
|
-
paint.bgColor = 0x26808080
|
|
80
|
-
}
|
|
81
|
-
if (flags and EditorMarks.SPOILER != 0) {
|
|
82
|
-
paint.bgColor = 0x40595959
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
private fun apply(paint: TextPaint) {
|
|
87
|
-
var style = paint.typeface?.style ?: Typeface.NORMAL
|
|
88
|
-
if (flags and EditorMarks.BOLD != 0) {
|
|
89
|
-
style = style or Typeface.BOLD
|
|
90
|
-
}
|
|
91
|
-
if (flags and EditorMarks.ITALIC != 0) {
|
|
92
|
-
style = style or Typeface.ITALIC
|
|
93
|
-
}
|
|
94
|
-
val base =
|
|
95
|
-
if (flags and EditorMarks.INLINE_CODE != 0) Typeface.MONOSPACE else paint.typeface
|
|
96
|
-
paint.typeface = Typeface.create(base, style)
|
|
97
|
-
|
|
98
|
-
// Sup/sub match the viewer's 0.7 scaling.
|
|
99
|
-
if (flags and (EditorMarks.SUPERSCRIPT or EditorMarks.SUBSCRIPT) != 0) {
|
|
100
|
-
val size = paint.textSize
|
|
101
|
-
paint.textSize = size * 0.7f
|
|
102
|
-
if (flags and EditorMarks.SUPERSCRIPT != 0) {
|
|
103
|
-
paint.baselineShift -= (size * 0.33f).toInt()
|
|
104
|
-
} else {
|
|
105
|
-
paint.baselineShift += (size * 0.15f).toInt()
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** Heading lines scale up and embolden. */
|
|
112
|
-
class HeadingDisplaySpan(level: Int) : MetricAffectingSpan(), EditorDerivedSpan {
|
|
113
|
-
private val scale = when (level) {
|
|
114
|
-
1 -> 2f
|
|
115
|
-
2 -> 1.5f
|
|
116
|
-
3 -> 1.25f
|
|
117
|
-
4 -> 1.125f
|
|
118
|
-
5 -> 1f
|
|
119
|
-
else -> 0.875f
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
override fun updateMeasureState(paint: TextPaint) = apply(paint)
|
|
123
|
-
|
|
124
|
-
override fun updateDrawState(paint: TextPaint) = apply(paint)
|
|
125
|
-
|
|
126
|
-
private fun apply(paint: TextPaint) {
|
|
127
|
-
paint.textSize = paint.textSize * scale
|
|
128
|
-
paint.isFakeBoldText = true
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Code lines: monospace glyphs. The full-width background stripe is drawn
|
|
134
|
-
* by the view (spans cannot cover empty lines).
|
|
135
|
-
*/
|
|
136
|
-
class CodeLineDisplaySpan : MetricAffectingSpan(), EditorDerivedSpan {
|
|
137
|
-
override fun updateMeasureState(paint: TextPaint) {
|
|
138
|
-
paint.typeface = Typeface.MONOSPACE
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
override fun updateDrawState(paint: TextPaint) {
|
|
142
|
-
paint.typeface = Typeface.MONOSPACE
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/** Quote lines: leading margin with a vertical bar. */
|
|
147
|
-
class QuoteDisplaySpan(private val density: Float) : LeadingMarginSpan, EditorDerivedSpan {
|
|
148
|
-
override fun getLeadingMargin(first: Boolean): Int = (16 * density).toInt()
|
|
149
|
-
|
|
150
|
-
override fun drawLeadingMargin(
|
|
151
|
-
canvas: Canvas,
|
|
152
|
-
paint: Paint,
|
|
153
|
-
x: Int,
|
|
154
|
-
dir: Int,
|
|
155
|
-
top: Int,
|
|
156
|
-
baseline: Int,
|
|
157
|
-
bottom: Int,
|
|
158
|
-
text: CharSequence,
|
|
159
|
-
start: Int,
|
|
160
|
-
end: Int,
|
|
161
|
-
first: Boolean,
|
|
162
|
-
layout: Layout,
|
|
163
|
-
) {
|
|
164
|
-
val previous = paint.color
|
|
165
|
-
val width = 3 * density
|
|
166
|
-
paint.color = (paint.color and 0x00FFFFFF) or -0x67000000
|
|
167
|
-
val barLeft = x + dir * 4 * density
|
|
168
|
-
canvas.drawRect(barLeft, top.toFloat(), barLeft + dir * width, bottom.toFloat(), paint)
|
|
169
|
-
paint.color = previous
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/** Line-height span the display refresh can remove wholesale. */
|
|
174
|
-
class EditorLineHeightSpan(heightPx: Int) :
|
|
175
|
-
com.jetmarkdown.render.spans.MarkdownLineHeightSpan(heightPx),
|
|
176
|
-
EditorDerivedSpan
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* No-op run splitter for a heading's newline: keeps it out of the
|
|
180
|
-
* heading's font run so the trailing empty line's caret doesn't inherit
|
|
181
|
-
* heading metrics.
|
|
182
|
-
*/
|
|
183
|
-
class NewlineResetSpan : MetricAffectingSpan(), EditorDerivedSpan {
|
|
184
|
-
override fun updateMeasureState(paint: TextPaint) = Unit
|
|
185
|
-
|
|
186
|
-
override fun updateDrawState(paint: TextPaint) = Unit
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/** List lines: leading margin drawing the bullet or the item number. */
|
|
190
|
-
class ListMarkerDisplaySpan(
|
|
191
|
-
private val marker: String,
|
|
192
|
-
private val density: Float,
|
|
193
|
-
) : LeadingMarginSpan, EditorDerivedSpan {
|
|
194
|
-
override fun getLeadingMargin(first: Boolean): Int = (28 * density).toInt()
|
|
195
|
-
|
|
196
|
-
override fun drawLeadingMargin(
|
|
197
|
-
canvas: Canvas,
|
|
198
|
-
paint: Paint,
|
|
199
|
-
x: Int,
|
|
200
|
-
dir: Int,
|
|
201
|
-
top: Int,
|
|
202
|
-
baseline: Int,
|
|
203
|
-
bottom: Int,
|
|
204
|
-
text: CharSequence,
|
|
205
|
-
start: Int,
|
|
206
|
-
end: Int,
|
|
207
|
-
first: Boolean,
|
|
208
|
-
layout: Layout,
|
|
209
|
-
) {
|
|
210
|
-
if (!first) {
|
|
211
|
-
return
|
|
212
|
-
}
|
|
213
|
-
val width = paint.measureText(marker)
|
|
214
|
-
val position = x + dir * ((24 * density) - width - (6 * density))
|
|
215
|
-
canvas.drawText(marker, position, baseline.toFloat(), paint)
|
|
216
|
-
}
|
|
217
|
-
}
|
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
package com.jetmarkdown.editor
|
|
2
|
-
|
|
3
|
-
import com.facebook.react.bridge.ReadableArray
|
|
4
|
-
import com.facebook.react.module.annotations.ReactModule
|
|
5
|
-
import com.facebook.react.uimanager.SimpleViewManager
|
|
6
|
-
import com.facebook.react.uimanager.StateWrapper
|
|
7
|
-
import com.facebook.react.uimanager.ThemedReactContext
|
|
8
|
-
import com.facebook.react.uimanager.ViewManagerDelegate
|
|
9
|
-
import com.facebook.react.uimanager.annotations.ReactProp
|
|
10
|
-
import com.facebook.react.viewmanagers.JetMarkdownEditorManagerDelegate
|
|
11
|
-
import com.facebook.react.viewmanagers.JetMarkdownEditorManagerInterface
|
|
12
|
-
import com.jetmarkdown.JetMarkdownNative
|
|
13
|
-
import com.jetmarkdown.style.PlatformColorResolver
|
|
14
|
-
|
|
15
|
-
@ReactModule(name = JetMarkdownEditorManager.NAME)
|
|
16
|
-
class JetMarkdownEditorManager : SimpleViewManager<JetMarkdownEditorView>(),
|
|
17
|
-
JetMarkdownEditorManagerInterface<JetMarkdownEditorView> {
|
|
18
|
-
private val delegate: ViewManagerDelegate<JetMarkdownEditorView> =
|
|
19
|
-
JetMarkdownEditorManagerDelegate(this)
|
|
20
|
-
|
|
21
|
-
init {
|
|
22
|
-
JetMarkdownNative.ensureInstalled()
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
override fun getDelegate(): ViewManagerDelegate<JetMarkdownEditorView> = delegate
|
|
26
|
-
|
|
27
|
-
override fun getName(): String = NAME
|
|
28
|
-
|
|
29
|
-
public override fun createViewInstance(context: ThemedReactContext): JetMarkdownEditorView {
|
|
30
|
-
JetMarkdownNative.ensureInstalled()
|
|
31
|
-
PlatformColorResolver.install(context)
|
|
32
|
-
return JetMarkdownEditorView(context)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
@ReactProp(name = "allowFontScaling")
|
|
36
|
-
override fun setAllowFontScaling(view: JetMarkdownEditorView?, value: Boolean) {
|
|
37
|
-
view?.allowFontScaling = value
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
@ReactProp(name = "autoCapitalize")
|
|
41
|
-
override fun setAutoCapitalize(view: JetMarkdownEditorView?, value: String?) {
|
|
42
|
-
view?.setCapitalizeMode(value)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
@ReactProp(name = "autoCorrect")
|
|
46
|
-
override fun setAutoCorrect(view: JetMarkdownEditorView?, value: Boolean) {
|
|
47
|
-
view?.setAutoCorrectEnabled(value)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
@ReactProp(name = "autoFocus")
|
|
51
|
-
override fun setAutoFocus(view: JetMarkdownEditorView?, value: Boolean) {
|
|
52
|
-
view?.setAutoFocus(value)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
@ReactProp(name = "cursorColor", customType = "Color")
|
|
56
|
-
override fun setCursorColor(view: JetMarkdownEditorView?, value: Int?) {
|
|
57
|
-
view?.setCursorColorInt(value ?: 0)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
@ReactProp(name = "defaultValue")
|
|
61
|
-
override fun setDefaultValue(view: JetMarkdownEditorView?, value: String?) {
|
|
62
|
-
view?.setDefaultValue(value)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
@ReactProp(name = "editable")
|
|
66
|
-
override fun setEditable(view: JetMarkdownEditorView?, value: Boolean) {
|
|
67
|
-
view?.isEnabled = value
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
@ReactProp(name = "maxHeight")
|
|
71
|
-
override fun setMaxHeight(view: JetMarkdownEditorView?, value: Double) {
|
|
72
|
-
view?.setMaxContentHeight(value)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
@ReactProp(name = "mentionTriggers")
|
|
76
|
-
override fun setMentionTriggers(view: JetMarkdownEditorView?, value: ReadableArray?) {
|
|
77
|
-
val triggers = ArrayList<String>()
|
|
78
|
-
if (value != null) {
|
|
79
|
-
for (index in 0 until value.size()) {
|
|
80
|
-
val trigger = value.getString(index)
|
|
81
|
-
if (!trigger.isNullOrEmpty()) {
|
|
82
|
-
triggers.add(trigger.substring(0, 1))
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
view?.mentionTriggers = triggers
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
@ReactProp(name = "multiline")
|
|
90
|
-
override fun setMultiline(view: JetMarkdownEditorView?, value: Boolean) {
|
|
91
|
-
view?.setMultiline(value)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
@ReactProp(name = "placeholder")
|
|
95
|
-
override fun setPlaceholder(view: JetMarkdownEditorView?, value: String?) {
|
|
96
|
-
view?.setPlaceholderText(value)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
@ReactProp(name = "placeholderTextColor", customType = "Color")
|
|
100
|
-
override fun setPlaceholderTextColor(view: JetMarkdownEditorView?, value: Int?) {
|
|
101
|
-
view?.setPlaceholderColor(value ?: 0)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
@ReactProp(name = "scrollEnabled")
|
|
105
|
-
override fun setScrollEnabled(view: JetMarkdownEditorView?, value: Boolean) {
|
|
106
|
-
view?.setScrollAllowed(value)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
@ReactProp(name = "selectionColor", customType = "Color")
|
|
110
|
-
override fun setSelectionColor(view: JetMarkdownEditorView?, value: Int?) {
|
|
111
|
-
view?.setSelectionColorInt(value ?: 0)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
@ReactProp(name = "stylesJson")
|
|
115
|
-
override fun setStylesJson(view: JetMarkdownEditorView?, value: String?) {
|
|
116
|
-
view?.setStylesJson(value)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
override fun blur(view: JetMarkdownEditorView?) {
|
|
120
|
-
view?.blurAndHideKeyboard()
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
override fun focus(view: JetMarkdownEditorView?) {
|
|
124
|
-
view?.focusAndShowKeyboard()
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
override fun setSelection(view: JetMarkdownEditorView?, start: Int, end: Int) {
|
|
128
|
-
view?.setEditorSelection(start, end)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
override fun setValue(view: JetMarkdownEditorView?, value: String?) {
|
|
132
|
-
view?.setMarkdownValue(value ?: "")
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
override fun insertLink(view: JetMarkdownEditorView?, url: String?, label: String?) {
|
|
136
|
-
view?.insertLink(url ?: "", label ?: "")
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
override fun insertMarkdown(view: JetMarkdownEditorView?, value: String?) {
|
|
140
|
-
view?.insertMarkdownAt(value ?: "")
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
override fun insertMention(
|
|
144
|
-
view: JetMarkdownEditorView?,
|
|
145
|
-
trigger: String?,
|
|
146
|
-
label: String?,
|
|
147
|
-
url: String?,
|
|
148
|
-
) {
|
|
149
|
-
view?.insertMention(trigger ?: "", label ?: "", url ?: "")
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
override fun removeLink(view: JetMarkdownEditorView?) {
|
|
153
|
-
view?.removeLink()
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
override fun toggleBlockQuote(view: JetMarkdownEditorView?) {
|
|
157
|
-
view?.toggleBlock(EditorBlocks.QUOTE, 0)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
override fun toggleBold(view: JetMarkdownEditorView?) {
|
|
161
|
-
view?.toggleMark(EditorMarks.BOLD)
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
override fun toggleCodeBlock(view: JetMarkdownEditorView?) {
|
|
165
|
-
view?.toggleBlock(EditorBlocks.CODE, 0)
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
override fun toggleHeading(view: JetMarkdownEditorView?, level: Int) {
|
|
169
|
-
view?.toggleBlock(EditorBlocks.HEADING, level.coerceIn(1, 6))
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
override fun toggleOrderedList(view: JetMarkdownEditorView?) {
|
|
173
|
-
view?.toggleBlock(EditorBlocks.ORDERED, 0)
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
override fun toggleUnorderedList(view: JetMarkdownEditorView?) {
|
|
177
|
-
view?.toggleBlock(EditorBlocks.BULLET, 0)
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
override fun toggleCode(view: JetMarkdownEditorView?) {
|
|
181
|
-
view?.toggleMark(EditorMarks.INLINE_CODE)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
override fun toggleItalic(view: JetMarkdownEditorView?) {
|
|
185
|
-
view?.toggleMark(EditorMarks.ITALIC)
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
override fun toggleSpoiler(view: JetMarkdownEditorView?) {
|
|
189
|
-
view?.toggleMark(EditorMarks.SPOILER)
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
override fun toggleStrikethrough(view: JetMarkdownEditorView?) {
|
|
193
|
-
view?.toggleMark(EditorMarks.STRIKETHROUGH)
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
override fun toggleSubscript(view: JetMarkdownEditorView?) {
|
|
197
|
-
view?.toggleMark(EditorMarks.SUBSCRIPT)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
override fun toggleSuperscript(view: JetMarkdownEditorView?) {
|
|
201
|
-
view?.toggleMark(EditorMarks.SUPERSCRIPT)
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
override fun prepareToRecycleView(
|
|
205
|
-
reactContext: ThemedReactContext,
|
|
206
|
-
view: JetMarkdownEditorView,
|
|
207
|
-
): JetMarkdownEditorView {
|
|
208
|
-
view.resetForRecycle()
|
|
209
|
-
return view
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
override fun updateState(
|
|
213
|
-
view: JetMarkdownEditorView,
|
|
214
|
-
props: com.facebook.react.uimanager.ReactStylesDiffMap,
|
|
215
|
-
stateWrapper: StateWrapper?,
|
|
216
|
-
): Any? {
|
|
217
|
-
view.stateWrapper = stateWrapper
|
|
218
|
-
return null
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
companion object {
|
|
222
|
-
const val NAME = "JetMarkdownEditor"
|
|
223
|
-
}
|
|
224
|
-
}
|