@writeon/core 1.0.0-rc.0 → 1.0.0-rc.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.
- package/dist/commands.d.ts +1 -1
- package/dist/extension.d.ts +1 -1
- package/dist/extensions.d.ts +1 -1
- package/dist/extensions.js +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -0
- package/dist/presets.d.ts +1 -1
- package/dist/{types-Bd25IgDH.d.ts → types-CKTNafiT.d.ts} +14 -0
- package/llms-full.txt +45 -4
- package/package.json +1 -1
package/dist/commands.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { d as HeadingLevel, t as Command } from "./types-
|
|
1
|
+
import { d as HeadingLevel, t as Command } from "./types-CKTNafiT.js";
|
|
2
2
|
/** Toggle bold on the selection. Requires the `bold` extension. */
|
|
3
3
|
export declare const toggleBold: () => Command;
|
|
4
4
|
/** Toggle italic on the selection. Requires the `italic` extension. */
|
package/dist/extension.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @module @writeon/core/extension
|
|
7
7
|
*/
|
|
8
8
|
import { MarkType, Node, Schema } from "prosemirror-model";
|
|
9
|
-
import { c as Extension, l as ExtensionContext, n as DocJSON, p as NodeAttribute, t as Command, u as ExtensionSpec } from "./types-
|
|
9
|
+
import { c as Extension, l as ExtensionContext, n as DocJSON, p as NodeAttribute, t as Command, u as ExtensionSpec } from "./types-CKTNafiT.js";
|
|
10
10
|
import "prosemirror-state";
|
|
11
11
|
import { InputRule } from "prosemirror-inputrules";
|
|
12
12
|
/**
|
package/dist/extensions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as Extension, d as HeadingLevel } from "./types-
|
|
1
|
+
import { c as Extension, d as HeadingLevel } from "./types-CKTNafiT.js";
|
|
2
2
|
/** Bold text. `Mod-b`, `**text**` or `__text__`. */
|
|
3
3
|
export declare const bold: () => Extension;
|
|
4
4
|
/** Italic text. `Mod-i`, `*text*` or `_text_`. */
|
package/dist/extensions.js
CHANGED
|
@@ -307,7 +307,8 @@ const hardBreak = defineExtension(() => ({
|
|
|
307
307
|
group: "inline",
|
|
308
308
|
selectable: false,
|
|
309
309
|
parseDOM: [{ tag: "br" }],
|
|
310
|
-
toDOM: () => ["br"]
|
|
310
|
+
toDOM: () => ["br"],
|
|
311
|
+
leafText: () => "\n"
|
|
311
312
|
} },
|
|
312
313
|
keymap: () => ({
|
|
313
314
|
"Shift-Enter": insertHardBreak(),
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @packageDocumentation
|
|
6
6
|
* @module @writeon/core
|
|
7
7
|
*/
|
|
8
|
-
import { a as EditorLabel, c as Extension, d as HeadingLevel, f as MarkJSON, h as TransactionScope, i as EditorExtendSource, m as NodeJSON, n as DocJSON, o as EditorOptions, r as Editor, s as EditorSnapshot, t as Command } from "./types-
|
|
8
|
+
import { a as EditorLabel, c as Extension, d as HeadingLevel, f as MarkJSON, h as TransactionScope, i as EditorExtendSource, m as NodeJSON, n as DocJSON, o as EditorOptions, r as Editor, s as EditorSnapshot, t as Command } from "./types-CKTNafiT.js";
|
|
9
9
|
/**
|
|
10
10
|
* A debounced function with explicit control over pending calls.
|
|
11
11
|
*/
|
package/dist/index.js
CHANGED
|
@@ -249,6 +249,11 @@ function createEditor(options) {
|
|
|
249
249
|
content: (_json$content = state.doc.toJSON().content) !== null && _json$content !== void 0 ? _json$content : []
|
|
250
250
|
};
|
|
251
251
|
},
|
|
252
|
+
getText(textOptions) {
|
|
253
|
+
var _textOptions$blockSep;
|
|
254
|
+
assertAlive();
|
|
255
|
+
return state.doc.textBetween(0, state.doc.content.size, (_textOptions$blockSep = textOptions === null || textOptions === void 0 ? void 0 : textOptions.blockSeparator) !== null && _textOptions$blockSep !== void 0 ? _textOptions$blockSep : "\n\n");
|
|
256
|
+
},
|
|
252
257
|
setContent(doc, setOptions) {
|
|
253
258
|
assertAlive();
|
|
254
259
|
const next = parseContent(schema, doc);
|
package/dist/presets.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @module @writeon/core/presets
|
|
7
7
|
*/
|
|
8
8
|
import { HeadingOptions, HistoryOptions, LinkOptions } from "./extensions.js";
|
|
9
|
-
import { c as Extension } from "./types-
|
|
9
|
+
import { c as Extension } from "./types-CKTNafiT.js";
|
|
10
10
|
/** Per-extension settings for `basic()`. `false` leaves an extension out. */
|
|
11
11
|
export interface BasicOptions {
|
|
12
12
|
/** Headings, or their options. */
|
|
@@ -119,6 +119,20 @@ interface Editor {
|
|
|
119
119
|
subscribe(listener: () => void): () => void;
|
|
120
120
|
/** The document in the JSON format, stamped with the current `schemaVersion`. */
|
|
121
121
|
getJSON(): DocJSON;
|
|
122
|
+
/**
|
|
123
|
+
* The document as plain text, e.g. to count words or characters. Blocks are
|
|
124
|
+
* separated by `blockSeparator` (default a blank line, `"\n\n"`), a line
|
|
125
|
+
* break is `"\n"`, and a mention is `"@"` and its label. Images and other
|
|
126
|
+
* nodes without text add nothing.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* const words = editor.getText().split(/\s+/).filter(Boolean).length
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
getText(options?: {
|
|
134
|
+
blockSeparator?: string;
|
|
135
|
+
}): string;
|
|
122
136
|
/** Replace the document. Not added to undo history unless `addToHistory` is `true`. */
|
|
123
137
|
setContent(doc: DocJSON, options?: {
|
|
124
138
|
addToHistory?: boolean;
|
package/llms-full.txt
CHANGED
|
@@ -8,8 +8,8 @@ Source: /guide/getting-started.md
|
|
|
8
8
|
|
|
9
9
|
# Getting started
|
|
10
10
|
|
|
11
|
-
**
|
|
12
|
-
|
|
11
|
+
**Release candidate:**
|
|
12
|
+
These pages describe 1.0, now a release candidate. Install it with the `rc` tag (`npm install @writeon/core@rc`); without it you get 0.x. Coming from 0.x: [Upgrading to 1.0](/guide/upgrade-1.md).
|
|
13
13
|
|
|
14
14
|
## Install
|
|
15
15
|
|
|
@@ -270,6 +270,15 @@ export function examples(editor: Editor) {
|
|
|
270
270
|
|
|
271
271
|
In React, `useEditorState(editor, selector)` re-renders only when the selected value changes; in Vue, it returns a ref.
|
|
272
272
|
|
|
273
|
+
`editor.getText()` returns the document as plain text, with a blank line between blocks, for example to count words:
|
|
274
|
+
|
|
275
|
+
```ts
|
|
276
|
+
const words = useEditorState(
|
|
277
|
+
editor,
|
|
278
|
+
() => editor.getText().split(/\s+/).filter(Boolean).length,
|
|
279
|
+
)
|
|
280
|
+
```
|
|
281
|
+
|
|
273
282
|
## Lifecycle
|
|
274
283
|
|
|
275
284
|
- `createEditor({ element })` mounts at once; without `element`, call `editor.mount(el)` later. Document and history survive `unmount()` and `mount()`.
|
|
@@ -793,8 +802,8 @@ Source: /guide/element.md
|
|
|
793
802
|
From a CDN, with no build step. Pin the version you tested with:
|
|
794
803
|
|
|
795
804
|
```html
|
|
796
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@writeon/element@0.
|
|
797
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/@writeon/element@0.
|
|
805
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@writeon/element@1.0.0-rc.0/dist/style.css" />
|
|
806
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@writeon/element@1.0.0-rc.0/dist/cdn/writeon-editor.js"></script>
|
|
798
807
|
```
|
|
799
808
|
|
|
800
809
|
The CDN file has everything in it (about 115 KB gzipped). With a bundler (Vite, webpack), install the package instead; it shares ProseMirror and Writeon with the rest of your app:
|
|
@@ -842,6 +851,8 @@ Put a `<textarea>` inside, with the name and the current value:
|
|
|
842
851
|
|
|
843
852
|
Print the value **escaped** (`{{ }}`, not `{!! !!}` or `|raw`). A textarea shows text, never runs it, so stored HTML cannot run while the page loads.
|
|
844
853
|
|
|
854
|
+
There is no `value` attribute (the element warns in the console if it finds one): the textarea is what keeps the field working before and without JavaScript. From JavaScript, set the `value` property.
|
|
855
|
+
|
|
845
856
|
What the element does with the textarea:
|
|
846
857
|
|
|
847
858
|
- **Until the element starts, and if JavaScript does not load, the textarea is the field.** The form still sends the text. If the element cannot start (no accessible name, a value it cannot read), the textarea stays and a `writeon-error` event says why.
|
|
@@ -3921,6 +3932,36 @@ Current state for rendering UI. Returns the same frozen object until the state c
|
|
|
3921
3932
|
|
|
3922
3933
|
***
|
|
3923
3934
|
|
|
3935
|
+
### getText()
|
|
3936
|
+
|
|
3937
|
+
```ts
|
|
3938
|
+
getText(options?): string;
|
|
3939
|
+
```
|
|
3940
|
+
|
|
3941
|
+
The document as plain text, e.g. to count words or characters. Blocks are
|
|
3942
|
+
separated by `blockSeparator` (default a blank line, `"\n\n"`), a line
|
|
3943
|
+
break is `"\n"`, and a mention is `"@"` and its label. Images and other
|
|
3944
|
+
nodes without text add nothing.
|
|
3945
|
+
|
|
3946
|
+
#### Parameters
|
|
3947
|
+
|
|
3948
|
+
| Parameter | Type |
|
|
3949
|
+
| ------ | ------ |
|
|
3950
|
+
| `options?` | \{ `blockSeparator?`: `string`; \} |
|
|
3951
|
+
| `options.blockSeparator?` | `string` |
|
|
3952
|
+
|
|
3953
|
+
#### Returns
|
|
3954
|
+
|
|
3955
|
+
`string`
|
|
3956
|
+
|
|
3957
|
+
#### Example
|
|
3958
|
+
|
|
3959
|
+
```ts
|
|
3960
|
+
const words = editor.getText().split(/\s+/).filter(Boolean).length
|
|
3961
|
+
```
|
|
3962
|
+
|
|
3963
|
+
***
|
|
3964
|
+
|
|
3924
3965
|
### isActive()
|
|
3925
3966
|
|
|
3926
3967
|
```ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@writeon/core",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.1",
|
|
4
4
|
"description": "Framework-agnostic, headless, accessible rich text editor core built on ProseMirror",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Ma'ruf Sheraliyev (https://github.com/mfs1011)",
|