@open-wysiwyg-editor/astro 0.0.0-stage → 1.0.0
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/LICENSE +21 -0
- package/README.md +120 -2
- package/RichTextEditor.astro +32 -0
- package/index.d.ts +2 -0
- package/index.js +1 -0
- package/package.json +54 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 alhassan-ahmed and open-wysiwyg-editor contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,121 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center"><a href="https://alhassan73.github.io/open-wysiwyg-editor/"><img src="https://raw.githubusercontent.com/alhassan73/open-wysiwyg-editor/main/.github/assets/banner.png" alt="Open WYSIWYG Editor — accessible, RTL-first rich text editor for every framework" width="100%"></a></p>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# @open-wysiwyg-editor/astro
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@open-wysiwyg-editor/astro)
|
|
6
|
+
[](https://github.com/alhassan73/open-wysiwyg-editor/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
**[Live demo →](https://alhassan73.github.io/open-wysiwyg-editor/)** · [GitHub](https://github.com/alhassan73/open-wysiwyg-editor) · [npm](https://www.npmjs.com/package/@open-wysiwyg-editor/astro)
|
|
9
|
+
|
|
10
|
+
An Astro component for the [Open WYSIWYG Editor](https://github.com/alhassan73/open-wysiwyg-editor#readme): an accessible (WCAG 2.2 AA), RTL-first rich text editor that runs under a strict Content Security Policy. It renders an `<owe-editor>` form field, so it works with plain form posts and needs no UI framework or client island.
|
|
11
|
+
|
|
12
|
+
```astro
|
|
13
|
+
<RichTextEditor name="body" value="<p>Hello</p>" />
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @open-wysiwyg-editor/astro
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Requires Astro 4 or newer.
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
The component imports its own script and styles, so you don't add anything else.
|
|
27
|
+
|
|
28
|
+
```astro
|
|
29
|
+
---
|
|
30
|
+
import { RichTextEditor } from "@open-wysiwyg-editor/astro";
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
<form method="post" action="/api/save">
|
|
34
|
+
<label for="body">Article</label>
|
|
35
|
+
<RichTextEditor id="body" name="body" value="<p>Hello <strong>world</strong></p>" />
|
|
36
|
+
<button>Save</button>
|
|
37
|
+
</form>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The editor is form-associated: the HTML is submitted under `name` with the surrounding `<form>`, and `form.reset()` restores the field.
|
|
41
|
+
|
|
42
|
+
### Props
|
|
43
|
+
|
|
44
|
+
| Prop | Type | Notes |
|
|
45
|
+
| --- | --- | --- |
|
|
46
|
+
| `name` | `string` | Form field name |
|
|
47
|
+
| `value` | `string` | Initial content as HTML |
|
|
48
|
+
| `placeholder` | `string` | |
|
|
49
|
+
| `label` | `string` | Accessible name. Or point a `<label for>` at the component's `id` |
|
|
50
|
+
| `readonly`, `disabled` | `boolean` | |
|
|
51
|
+
| `language` | `string` | UI language, for example `"ar"`. Defaults to `<html lang>` |
|
|
52
|
+
| `dir` | `"ltr"`, `"rtl"` or `"auto"` | Base direction of the content |
|
|
53
|
+
| `toolbar` | `string` | Toolbar items separated by spaces, for example `"bold italic \| link"`, or `"none"` |
|
|
54
|
+
| other | | Any HTML attribute (`id`, `class`, `data-*`…) is passed to the element |
|
|
55
|
+
|
|
56
|
+
`language` and `toolbar` are read when the editor is created. The rest follow later changes.
|
|
57
|
+
|
|
58
|
+
### Arabic and a custom toolbar
|
|
59
|
+
|
|
60
|
+
```astro
|
|
61
|
+
<RichTextEditor
|
|
62
|
+
name="body"
|
|
63
|
+
language="ar"
|
|
64
|
+
dir="rtl"
|
|
65
|
+
label="المحتوى"
|
|
66
|
+
toolbar="bold italic underline | link bulletList orderedList"
|
|
67
|
+
/>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Reading the value in a page script
|
|
71
|
+
|
|
72
|
+
The element fires `input` on every change and `change` when it loses focus after a change. `element.value` is the HTML, and `element.editor` is the editor instance once it has started.
|
|
73
|
+
|
|
74
|
+
```astro
|
|
75
|
+
<RichTextEditor id="body" name="body" />
|
|
76
|
+
|
|
77
|
+
<script>
|
|
78
|
+
const field = document.querySelector<HTMLElement & { value: string }>("#body")!;
|
|
79
|
+
field.addEventListener("input", () => console.log(field.value));
|
|
80
|
+
</script>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
For the full editor API (`getHTML()`, `commands`, `on()`…), use `field.editor`. For extra `createEditor` options, set `field.options = { … }` before the element connects. See the [HTML forms](https://github.com/alhassan73/open-wysiwyg-editor#html-forms) and [options](https://github.com/alhassan73/open-wysiwyg-editor#options) sections of the core docs.
|
|
84
|
+
|
|
85
|
+
### Saving: form post and API route
|
|
86
|
+
|
|
87
|
+
`src/pages/api/save.ts` (needs an adapter, or a prerender-off route):
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import type { APIRoute } from "astro";
|
|
91
|
+
|
|
92
|
+
export const prerender = false;
|
|
93
|
+
|
|
94
|
+
export const POST: APIRoute = async ({ request }) => {
|
|
95
|
+
const form = await request.formData();
|
|
96
|
+
const body = String(form.get("body") ?? "");
|
|
97
|
+
// Sanitize again on the server before you store or render it for other users.
|
|
98
|
+
return Response.json({ length: body.length });
|
|
99
|
+
};
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
In an Astro page (server output), read the same field with `await Astro.request.formData()` when `Astro.request.method === "POST"`.
|
|
103
|
+
|
|
104
|
+
## Styling
|
|
105
|
+
|
|
106
|
+
The component already imports `open-wysiwyg-editor/style.css`, and Astro bundles it with your page. Theme it with CSS variables; see [Styling](https://github.com/alhassan73/open-wysiwyg-editor#styling) in the core docs. To show saved HTML elsewhere, import `open-wysiwyg-editor/content.css`.
|
|
107
|
+
|
|
108
|
+
## SSR and static builds
|
|
109
|
+
|
|
110
|
+
The server (or the static build) renders only the `<owe-editor>` element, with the initial HTML in its `value` attribute. Astro escapes that attribute, so content from users can't run before the editor sanitizes it. The editor starts in the browser, and the field works with a plain form post in both `static` and `server` output.
|
|
111
|
+
|
|
112
|
+
## Links
|
|
113
|
+
|
|
114
|
+
- [Core docs](https://github.com/alhassan73/open-wysiwyg-editor#readme)
|
|
115
|
+
- [Live demo](https://alhassan73.github.io/open-wysiwyg-editor/)
|
|
116
|
+
- [Changelog](https://github.com/alhassan73/open-wysiwyg-editor/blob/main/CHANGELOG.md)
|
|
117
|
+
- [Report an issue](https://github.com/alhassan73/open-wysiwyg-editor/issues)
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
[MIT](https://github.com/alhassan73/open-wysiwyg-editor/blob/main/LICENSE) © alhassan-ahmed
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
// Renders <owe-editor>. The initial HTML travels in the escaped `value` attribute, so content that
|
|
3
|
+
// came from users can't run before the editor sanitizes it. The editor itself starts in the browser.
|
|
4
|
+
import type { HTMLAttributes } from "astro/types";
|
|
5
|
+
|
|
6
|
+
export interface Props extends HTMLAttributes<"div"> {
|
|
7
|
+
/** Initial content as HTML. */
|
|
8
|
+
value?: string;
|
|
9
|
+
/** Form field name: the HTML is submitted with the surrounding <form>. */
|
|
10
|
+
name?: string;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
/** Accessible name (or point a <label for> at the element's id). */
|
|
13
|
+
label?: string;
|
|
14
|
+
readonly?: boolean;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
/** UI language, e.g. "ar". Defaults to <html lang>. */
|
|
17
|
+
language?: string;
|
|
18
|
+
/** Base direction of the content. */
|
|
19
|
+
dir?: "ltr" | "rtl" | "auto";
|
|
20
|
+
/** Toolbar items separated by spaces ("bold italic | link"), or "none". */
|
|
21
|
+
toolbar?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const { value = "", ...attributes } = Astro.props;
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
<owe-editor value={value} {...attributes}></owe-editor>
|
|
28
|
+
|
|
29
|
+
<script>
|
|
30
|
+
import "open-wysiwyg-editor/element";
|
|
31
|
+
import "open-wysiwyg-editor/style.css";
|
|
32
|
+
</script>
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as RichTextEditor } from "./RichTextEditor.astro";
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-wysiwyg-editor/astro",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Astro component for open-wysiwyg-editor: <RichTextEditor name value />, works with plain form posts. Accessible (WCAG 2.2 AA), RTL-first, CSP-safe.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "alhassan-ahmed",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"default": "./index.js"
|
|
12
|
+
},
|
|
13
|
+
"./RichTextEditor.astro": "./RichTextEditor.astro",
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"index.js",
|
|
18
|
+
"index.d.ts",
|
|
19
|
+
"RichTextEditor.astro"
|
|
20
|
+
],
|
|
21
|
+
"keywords": [
|
|
22
|
+
"astro",
|
|
23
|
+
"astro-component",
|
|
24
|
+
"withastro",
|
|
25
|
+
"wysiwyg",
|
|
26
|
+
"rich-text-editor",
|
|
27
|
+
"editor",
|
|
28
|
+
"accessibility",
|
|
29
|
+
"a11y",
|
|
30
|
+
"rtl",
|
|
31
|
+
"arabic"
|
|
32
|
+
],
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"open-wysiwyg-editor": "^1.0.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"astro": ">=4.0.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependenciesMeta": {
|
|
40
|
+
"astro": {
|
|
41
|
+
"optional": true
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://alhassan73.github.io/open-wysiwyg-editor/",
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/alhassan73/open-wysiwyg-editor/issues"
|
|
50
|
+
},
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "git+https://github.com/alhassan73/open-wysiwyg-editor.git",
|
|
54
|
+
"directory": "packages/astro"
|
|
55
|
+
}
|
|
56
|
+
}
|