@opositatest/markdown-text-editor 1.0.5
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 +139 -0
- package/dist/editor.css +2 -0
- package/dist/editor.js +86859 -0
- package/dist/favicon.svg +1 -0
- package/dist/icons.svg +24 -0
- package/dist/react/favicon.svg +1 -0
- package/dist/react/icons.svg +24 -0
- package/dist/react/index.js +95826 -0
- package/dist/react/markdown-text-editor.css +2 -0
- package/dist/react/module-BNH92kHQ.js +1901 -0
- package/dist/react/native-PBRRnxaU.js +107 -0
- package/package.json +58 -0
package/README.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# @opositatest/markdown-text-editor
|
|
2
|
+
|
|
3
|
+
Rich-text editor that serializes content as Markdown. Ships as a self-contained Web Component and as a React component.
|
|
4
|
+
|
|
5
|
+
## Web Component
|
|
6
|
+
|
|
7
|
+
Load via CDN (no build step required):
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@opositatest/markdown-text-editor/dist/editor.css" />
|
|
11
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@opositatest/markdown-text-editor/dist/editor.js"></script>
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### Usage
|
|
15
|
+
|
|
16
|
+
```html
|
|
17
|
+
<form>
|
|
18
|
+
<markdown-text-editor
|
|
19
|
+
name="body"
|
|
20
|
+
value="Initial content"
|
|
21
|
+
placeholder="Write here…"
|
|
22
|
+
width="100%"
|
|
23
|
+
height="320px"
|
|
24
|
+
required
|
|
25
|
+
></markdown-text-editor>
|
|
26
|
+
</form>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Attributes
|
|
30
|
+
|
|
31
|
+
| Attribute | Type | Description |
|
|
32
|
+
|---------------|---------|--------------------------------------------------|
|
|
33
|
+
| `name` | string | Field name for form submission |
|
|
34
|
+
| `value` | string | Initial Markdown value |
|
|
35
|
+
| `placeholder` | string | Placeholder text shown when empty |
|
|
36
|
+
| `width` | string | CSS width for the editor container |
|
|
37
|
+
| `height` | string | CSS height for the editor container |
|
|
38
|
+
| `disabled` | boolean | Disables the editor |
|
|
39
|
+
| `readonly` | boolean | Makes the editor read-only |
|
|
40
|
+
| `required` | boolean | Participates in native form validation |
|
|
41
|
+
|
|
42
|
+
`width` and `height` accept any valid CSS size, such as `320px`, `40rem`, or `100%`.
|
|
43
|
+
|
|
44
|
+
### Properties
|
|
45
|
+
|
|
46
|
+
| Property | Type | Description |
|
|
47
|
+
|---------------------|---------|-------------------------------------|
|
|
48
|
+
| `element.value` | string | Get or set Markdown content |
|
|
49
|
+
| `element.width` | string | Get or set CSS width |
|
|
50
|
+
| `element.height` | string | Get or set CSS height |
|
|
51
|
+
| `element.disabled` | boolean | Get or set disabled state |
|
|
52
|
+
| `element.readOnly` | boolean | Get or set read-only state |
|
|
53
|
+
|
|
54
|
+
### Methods
|
|
55
|
+
|
|
56
|
+
| Method | Description |
|
|
57
|
+
|---------------------------|------------------------------------|
|
|
58
|
+
| `focus()` | Focus the editor |
|
|
59
|
+
| `getMarkdown()` | Returns current content as Markdown |
|
|
60
|
+
| `setMarkdown(value)` | Replaces editor content |
|
|
61
|
+
|
|
62
|
+
### Events
|
|
63
|
+
|
|
64
|
+
| Event | Fires when |
|
|
65
|
+
|---------|-------------------------------------------------|
|
|
66
|
+
| `input` | On every content change (keystroke) |
|
|
67
|
+
| `change`| On blur if value changed since focus |
|
|
68
|
+
| `ready` | Once the editor has initialized |
|
|
69
|
+
|
|
70
|
+
### Form integration
|
|
71
|
+
|
|
72
|
+
`required` participates in native browser form validation via `ElementInternals` (with a hidden-input fallback for browsers that don't support it). The field value is submitted with the form using the `name` attribute.
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## React Component
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npm install @opositatest/markdown-text-editor
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
import { MarkdownTextEditor } from '@opositatest/markdown-text-editor'
|
|
84
|
+
import '@opositatest/markdown-text-editor/style'
|
|
85
|
+
|
|
86
|
+
<MarkdownTextEditor defaultValue="Hello" width="100%" height="320px" />
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Props
|
|
90
|
+
|
|
91
|
+
| Prop | Type | Description |
|
|
92
|
+
|----------------|---------------------------------------------|--------------------------------------------------|
|
|
93
|
+
| `value` | `string` | Controlled Markdown value |
|
|
94
|
+
| `defaultValue` | `string` | Uncontrolled initial value |
|
|
95
|
+
| `onChange` | `(value: string) => void` | Called on every content change |
|
|
96
|
+
| `onReady` | `(handle: MarkdownTextEditorHandle) => void`| Called once editor has initialized |
|
|
97
|
+
| `placeholder` | `string` | Placeholder text shown when empty |
|
|
98
|
+
| `width` | `string` | CSS width for the editor container |
|
|
99
|
+
| `height` | `string` | CSS height for the editor container |
|
|
100
|
+
| `disabled` | `boolean` | Disables the editor |
|
|
101
|
+
| `readonly` | `boolean` | Makes the editor read-only |
|
|
102
|
+
| `className` | `string` | Additional CSS class on the editor container |
|
|
103
|
+
|
|
104
|
+
`width` and `height` accept any valid CSS size, such as `320px`, `40rem`, or `100%`.
|
|
105
|
+
|
|
106
|
+
### Imperative handle (via ref)
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
import { useRef } from 'react'
|
|
110
|
+
import { MarkdownTextEditor, type TMarkdownTextEditorHandle } from '@opositatest/markdown-text-editor'
|
|
111
|
+
|
|
112
|
+
const ref = useRef<TMarkdownTextEditorHandle>(null)
|
|
113
|
+
|
|
114
|
+
<MarkdownTextEditor ref={ref} defaultValue="Hello" onChange={setValue} />
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
| Method | Description |
|
|
118
|
+
|-----------------------|-------------------------------------|
|
|
119
|
+
| `ref.focus()` | Focus the editor |
|
|
120
|
+
| `ref.getMarkdown()` | Returns current content as Markdown |
|
|
121
|
+
| `ref.setMarkdown(v)` | Replaces editor content |
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Package exports
|
|
126
|
+
|
|
127
|
+
| Export | Description |
|
|
128
|
+
|------------------------------------------|------------------------------------|
|
|
129
|
+
| `@opositatest/markdown-text-editor` | React component + types |
|
|
130
|
+
| `@opositatest/markdown-text-editor/input`| Self-contained Web Component bundle |
|
|
131
|
+
| `@opositatest/markdown-text-editor/style`| CSS stylesheet |
|
|
132
|
+
|
|
133
|
+
## Browser support
|
|
134
|
+
|
|
135
|
+
Requires browsers with support for [Custom Elements v1](https://caniuse.com/custom-elementsv1) and [ElementInternals](https://caniuse.com/mdn-api_elementinternals). All modern browsers (Chrome 77+, Firefox 98+, Safari 16.4+) are supported.
|
|
136
|
+
|
|
137
|
+
## Peer dependencies (React component only)
|
|
138
|
+
|
|
139
|
+
`react >= 19`, `react-dom >= 19`
|