@writeon/core 0.1.0 → 0.3.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/dist/commands.d.ts +5 -4
- package/dist/extension.d.ts +1 -1
- package/dist/extensions.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +13 -2
- package/dist/presets.d.ts +1 -1
- package/dist/{types-Dy7Bm7XX.d.ts → types-XoUXB0kY.d.ts} +17 -6
- package/llms-full.txt +1315 -257
- package/llms.txt +6 -1
- package/package.json +1 -6
package/dist/commands.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as Command } from "./types-
|
|
1
|
+
import { d as HeadingLevel, t as Command } from "./types-XoUXB0kY.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. */
|
|
@@ -14,9 +14,9 @@ export declare function clearFormatting(): Command;
|
|
|
14
14
|
/** Turn the selected blocks into paragraphs. */
|
|
15
15
|
export declare function setParagraph(): Command;
|
|
16
16
|
/** Turn the selected blocks into headings of `level`. Requires the `heading` extension. */
|
|
17
|
-
export declare function setHeading(level:
|
|
17
|
+
export declare function setHeading(level: HeadingLevel): Command;
|
|
18
18
|
/** Heading of `level` if the block is not one already, otherwise back to a paragraph. */
|
|
19
|
-
export declare function toggleHeading(level:
|
|
19
|
+
export declare function toggleHeading(level: HeadingLevel): Command;
|
|
20
20
|
/** Wrap the selection in a blockquote, or lift it out of one. Requires `blockquote`. */
|
|
21
21
|
export declare function toggleBlockquote(): Command;
|
|
22
22
|
/** Insert a line break inside the current block. Requires `hardBreak`. */
|
|
@@ -48,4 +48,5 @@ export declare function unsetLink(): Command;
|
|
|
48
48
|
/** Undo the last change. Requires the `history` extension. */
|
|
49
49
|
export declare function undo(): Command;
|
|
50
50
|
/** Redo the last undone change. Requires the `history` extension. */
|
|
51
|
-
export declare function redo(): Command;
|
|
51
|
+
export declare function redo(): Command;
|
|
52
|
+
export type { HeadingLevel };
|
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,
|
|
9
|
+
import { c as Extension, l as ExtensionContext, n as DocJSON, p as NodeAttribute, t as Command, u as ExtensionSpec } from "./types-XoUXB0kY.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 } from "./types-
|
|
1
|
+
import { c as Extension, d as HeadingLevel } from "./types-XoUXB0kY.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_`. */
|
|
@@ -23,7 +23,7 @@ export declare const link: (options?: LinkOptions) => Extension;
|
|
|
23
23
|
/** Options for the `heading` extension. */
|
|
24
24
|
export interface HeadingOptions {
|
|
25
25
|
/** Heading levels the user can create. Default `[1, 2, 3]`. */
|
|
26
|
-
levels?: readonly
|
|
26
|
+
levels?: readonly HeadingLevel[];
|
|
27
27
|
}
|
|
28
28
|
/** Headings. `Mod-Alt-1…6`, `# ` … `###### `; `Mod-Alt-0` back to paragraph. */
|
|
29
29
|
export declare const heading: (options?: HeadingOptions) => Extension;
|
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 MarkJSON, i as
|
|
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-XoUXB0kY.js";
|
|
9
9
|
/**
|
|
10
10
|
* A debounced function with explicit control over pending calls.
|
|
11
11
|
*/
|
|
@@ -70,4 +70,4 @@ export declare const DEFAULT_PROTOCOLS: readonly string[];
|
|
|
70
70
|
* (`java\tscript:` runs as `javascript:`).
|
|
71
71
|
*/
|
|
72
72
|
export declare function isAllowedUrl(href: string, protocols?: readonly string[]): boolean;
|
|
73
|
-
export type { Command, Debounced, DocJSON, Editor,
|
|
73
|
+
export type { Command, Debounced, DocJSON, Editor, EditorExtendSource, EditorLabel, EditorOptions, EditorSnapshot, Extension, HeadingLevel, MarkJSON, NodeJSON, TransactionScope };
|
package/dist/index.js
CHANGED
|
@@ -259,6 +259,9 @@ function createEditor(options) {
|
|
|
259
259
|
get isEmpty() {
|
|
260
260
|
return isDocEmpty(state.doc);
|
|
261
261
|
},
|
|
262
|
+
get isDestroyed() {
|
|
263
|
+
return destroyed;
|
|
264
|
+
},
|
|
262
265
|
focus(position) {
|
|
263
266
|
assertAlive();
|
|
264
267
|
if (!view) return;
|
|
@@ -279,7 +282,14 @@ function createEditor(options) {
|
|
|
279
282
|
view === null || view === void 0 || view.setProps({});
|
|
280
283
|
changed();
|
|
281
284
|
},
|
|
282
|
-
|
|
285
|
+
enable(source) {
|
|
286
|
+
if (!warnedEnable) {
|
|
287
|
+
warnedEnable = true;
|
|
288
|
+
console.warn("[writeon] editor.enable() is renamed to editor.extend(). enable() is removed in 1.0.");
|
|
289
|
+
}
|
|
290
|
+
return editor.extend(source);
|
|
291
|
+
},
|
|
292
|
+
async extend(source) {
|
|
283
293
|
assertAlive();
|
|
284
294
|
const added = await loadExtensions(source);
|
|
285
295
|
if (destroyed) return;
|
|
@@ -289,7 +299,7 @@ function createEditor(options) {
|
|
|
289
299
|
for (const ext of fresh) {
|
|
290
300
|
var _spec$requires;
|
|
291
301
|
const spec = ext.spec;
|
|
292
|
-
if (spec.nodes || spec.marks) throw new Error(`[writeon] Extension "${ext.name}" defines nodes or marks, which cannot be added to a running editor. Pass its schema extension to createEditor() and
|
|
302
|
+
if (spec.nodes || spec.marks) throw new Error(`[writeon] Extension "${ext.name}" defines nodes or marks, which cannot be added to a running editor. Pass its schema extension to createEditor() and add only the behaviour with editor.extend().`);
|
|
293
303
|
const missing = ((_spec$requires = spec.requires) !== null && _spec$requires !== void 0 ? _spec$requires : []).filter((name) => !names.has(name) && !fresh.some((other) => other.name === name));
|
|
294
304
|
if (missing.length > 0) throw new Error(`[writeon] Extension "${ext.name}" requires ${missing.map((n) => `"${n}"`).join(", ")}, which is not added. Add it to createEditor({ extensions }) (an editor cannot gain nodes or marks later), e.g. advancedSchema() from @writeon/advanced/schema for advanced().`);
|
|
295
305
|
}
|
|
@@ -317,6 +327,7 @@ function createEditor(options) {
|
|
|
317
327
|
if (options.element) mount(options.element);
|
|
318
328
|
return editor;
|
|
319
329
|
}
|
|
330
|
+
let warnedEnable = false;
|
|
320
331
|
async function loadExtensions(source) {
|
|
321
332
|
const loaded = typeof source === "function" ? await source() : source;
|
|
322
333
|
return "default" in loaded ? loaded.default : loaded;
|
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-XoUXB0kY.js";
|
|
10
10
|
/** Per-extension settings for `basic()`. `false` leaves an extension out. */
|
|
11
11
|
export interface BasicOptions {
|
|
12
12
|
/** Headings, or their options. */
|
|
@@ -46,7 +46,7 @@ interface EditorOptions {
|
|
|
46
46
|
/** Element to mount into. Omit to create the editor first and call `mount()` later. */
|
|
47
47
|
element?: HTMLElement;
|
|
48
48
|
/** Extensions that make up the editor, usually a preset such as `basic()`. */
|
|
49
|
-
extensions: Extension[];
|
|
49
|
+
extensions: readonly Extension[];
|
|
50
50
|
/** Initial document. Omit for an empty document. */
|
|
51
51
|
content?: DocJSON | null;
|
|
52
52
|
/** Accessible name: an `aria-label` string or the id of a labelling element. */
|
|
@@ -125,6 +125,11 @@ interface Editor {
|
|
|
125
125
|
}): void;
|
|
126
126
|
/** Whether the document is a single empty text block. */
|
|
127
127
|
readonly isEmpty: boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Whether `destroy()` was called. UI that defers work (a timer, a
|
|
130
|
+
* microtask) checks it before reading the editor again.
|
|
131
|
+
*/
|
|
132
|
+
readonly isDestroyed: boolean;
|
|
128
133
|
/** Focus the editable area, optionally moving the cursor to the start or end. Does nothing when not mounted. */
|
|
129
134
|
focus(position?: "start" | "end"): void;
|
|
130
135
|
/** Remove focus from the editable area. */
|
|
@@ -140,10 +145,14 @@ interface Editor {
|
|
|
140
145
|
*
|
|
141
146
|
* @example
|
|
142
147
|
* ```ts
|
|
143
|
-
* await editor.
|
|
148
|
+
* await editor.extend(() => import('@writeon/advanced'))
|
|
144
149
|
* ```
|
|
145
150
|
*/
|
|
146
|
-
|
|
151
|
+
extend(source: EditorExtendSource): Promise<void>;
|
|
152
|
+
/**
|
|
153
|
+
* @deprecated Renamed to `extend()`, which this calls. Removed in 1.0.
|
|
154
|
+
*/
|
|
155
|
+
enable(source: EditorExtendSource): Promise<void>;
|
|
147
156
|
/**
|
|
148
157
|
* Attach to a DOM element. Document and history are kept across mount/unmount.
|
|
149
158
|
* Throws if already mounted.
|
|
@@ -170,8 +179,8 @@ interface ExtensionContext {
|
|
|
170
179
|
/** The editor's schema. */
|
|
171
180
|
readonly schema: Schema;
|
|
172
181
|
}
|
|
173
|
-
/** Extensions to
|
|
174
|
-
type
|
|
182
|
+
/** Extensions to add, or a loader for them (a module whose default export is the list works too). */
|
|
183
|
+
type EditorExtendSource = readonly Extension[] | (() => Promise<readonly Extension[] | {
|
|
175
184
|
/** The extensions, as the default export of a loaded module. */
|
|
176
185
|
default: readonly Extension[];
|
|
177
186
|
}>);
|
|
@@ -222,4 +231,6 @@ interface Extension {
|
|
|
222
231
|
/** @internal Use `defineExtension()` instead of building this by hand. */
|
|
223
232
|
readonly spec: ExtensionSpec;
|
|
224
233
|
}
|
|
225
|
-
|
|
234
|
+
/** A heading level, `1` (`<h1>`) to `6` (`<h6>`). */
|
|
235
|
+
type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
236
|
+
export { EditorLabel as a, Extension as c, HeadingLevel as d, MarkJSON as f, TransactionScope as h, EditorExtendSource as i, ExtensionContext as l, NodeJSON as m, DocJSON as n, EditorOptions as o, NodeAttribute as p, Editor as r, EditorSnapshot as s, Command as t, ExtensionSpec as u };
|