@writeon/core 0.2.0 → 1.0.0-rc.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.
@@ -1,4 +1,4 @@
1
- import { t as Command } from "./types-BwODQ2T0.js";
1
+ import { d as HeadingLevel, t as Command } from "./types-Bd25IgDH.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: number): Command;
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: number): Command;
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 };
@@ -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, f as NodeAttribute, l as ExtensionContext, n as DocJSON, t as Command, u as ExtensionSpec } from "./types-BwODQ2T0.js";
9
+ import { c as Extension, l as ExtensionContext, n as DocJSON, p as NodeAttribute, t as Command, u as ExtensionSpec } from "./types-Bd25IgDH.js";
10
10
  import "prosemirror-state";
11
11
  import { InputRule } from "prosemirror-inputrules";
12
12
  /**
@@ -1,4 +1,4 @@
1
- import { c as Extension } from "./types-BwODQ2T0.js";
1
+ import { c as Extension, d as HeadingLevel } from "./types-Bd25IgDH.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 number[];
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 EditorEnableSource, m as TransactionScope, n as DocJSON, o as EditorOptions, p as NodeJSON, r as Editor, s as EditorSnapshot, t as Command } from "./types-BwODQ2T0.js";
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-Bd25IgDH.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, EditorEnableSource, EditorLabel, EditorOptions, EditorSnapshot, Extension, MarkJSON, NodeJSON, TransactionScope };
73
+ export type { Command, Debounced, DocJSON, Editor, EditorExtendSource, EditorLabel, EditorOptions, EditorSnapshot, Extension, HeadingLevel, MarkJSON, NodeJSON, TransactionScope };
package/dist/index.js CHANGED
@@ -282,7 +282,7 @@ function createEditor(options) {
282
282
  view === null || view === void 0 || view.setProps({});
283
283
  changed();
284
284
  },
285
- async enable(source) {
285
+ async extend(source) {
286
286
  assertAlive();
287
287
  const added = await loadExtensions(source);
288
288
  if (destroyed) return;
@@ -292,7 +292,7 @@ function createEditor(options) {
292
292
  for (const ext of fresh) {
293
293
  var _spec$requires;
294
294
  const spec = ext.spec;
295
- 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 enable only the behaviour.`);
295
+ 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().`);
296
296
  const missing = ((_spec$requires = spec.requires) !== null && _spec$requires !== void 0 ? _spec$requires : []).filter((name) => !names.has(name) && !fresh.some((other) => other.name === name));
297
297
  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().`);
298
298
  }
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-BwODQ2T0.js";
9
+ import { c as Extension } from "./types-Bd25IgDH.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. */
@@ -145,10 +145,10 @@ interface Editor {
145
145
  *
146
146
  * @example
147
147
  * ```ts
148
- * await editor.enable(() => import('@writeon/advanced'))
148
+ * await editor.extend(() => import('@writeon/advanced'))
149
149
  * ```
150
150
  */
151
- enable(source: EditorEnableSource): Promise<void>;
151
+ extend(source: EditorExtendSource): Promise<void>;
152
152
  /**
153
153
  * Attach to a DOM element. Document and history are kept across mount/unmount.
154
154
  * Throws if already mounted.
@@ -175,8 +175,8 @@ interface ExtensionContext {
175
175
  /** The editor's schema. */
176
176
  readonly schema: Schema;
177
177
  }
178
- /** Extensions to enable, or a loader for them (a module whose default export is the list works too). */
179
- type EditorEnableSource = readonly Extension[] | (() => Promise<readonly Extension[] | {
178
+ /** Extensions to add, or a loader for them (a module whose default export is the list works too). */
179
+ type EditorExtendSource = readonly Extension[] | (() => Promise<readonly Extension[] | {
180
180
  /** The extensions, as the default export of a loaded module. */
181
181
  default: readonly Extension[];
182
182
  }>);
@@ -227,4 +227,6 @@ interface Extension {
227
227
  /** @internal Use `defineExtension()` instead of building this by hand. */
228
228
  readonly spec: ExtensionSpec;
229
229
  }
230
- export { EditorLabel as a, Extension as c, MarkJSON as d, NodeAttribute as f, EditorEnableSource as i, ExtensionContext as l, TransactionScope as m, DocJSON as n, EditorOptions as o, NodeJSON as p, Editor as r, EditorSnapshot as s, Command as t, ExtensionSpec as u };
230
+ /** A heading level, `1` (`<h1>`) to `6` (`<h6>`). */
231
+ type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
232
+ 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 };