@rathkit/rte-svelte 0.1.0-alpha.4 → 0.1.0-alpha.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @rathkit/rte-svelte
2
2
 
3
- > **Alpha** (0.1.0-alpha.0). Not for production: the APIs will change between releases. Published to the `next` tag only.
3
+ > **Alpha.** Not for production: the APIs will change between releases. Published to the `next` tag only.
4
4
 
5
5
  The editor for Svelte: stores and an action over the headless layer. Svelte's store contract is a plain shape, so this package needs nothing from Svelte itself.
6
6
 
package/dist/action.d.ts CHANGED
@@ -1,13 +1,22 @@
1
1
  import type { Editor } from "@rathkit/rte-core/dom";
2
+ import type { Selection } from "@rathkit/rte-core";
2
3
  import { type StandardOptions } from "@rathkit/rte-core/standard";
3
- export interface RteActionOptions extends Omit<StandardOptions, "element" | "html" | "readOnly"> {
4
+ export interface RteActionOptions extends Omit<StandardOptions, "element" | "html" | "readOnly" | "disabled"> {
4
5
  /** The starting HTML. */
5
6
  html?: string;
6
7
  readOnly?: boolean;
8
+ /** Read-only, and not focusable or in the tab order. Live: changes in `update` apply. */
9
+ disabled?: boolean;
7
10
  /** Called with the HTML after each change that alters it. */
8
11
  onChange?: (html: string) => void;
9
12
  /** Called once the editor exists. */
10
13
  onReady?: (editor: Editor) => void;
14
+ /** Called when the editor gains the focus. */
15
+ onFocus?: (editor: Editor) => void;
16
+ /** Called when the editor loses the focus. */
17
+ onBlur?: (editor: Editor) => void;
18
+ /** Called when the selection moves or changes. */
19
+ onSelection?: (selection: Selection) => void;
11
20
  }
12
21
  export declare function rteEditor(element: HTMLElement, options?: RteActionOptions): {
13
22
  update(next: RteActionOptions): void;
package/dist/action.js CHANGED
@@ -1,21 +1,22 @@
1
1
  import { createEditor } from "@rathkit/rte-core/standard";
2
2
  export function rteEditor(element, options = {}) {
3
- const { html, readOnly, onChange: _c, onReady: _r, ...rest } = options;
4
- const editor = createEditor({ ...rest, element, html: html ?? "", readOnly: readOnly ?? false });
3
+ const { html, readOnly, disabled, onChange: _c, onReady: _r, onFocus: _f, onBlur: _b, onSelection: _s, ...rest } = options;
4
+ const editor = createEditor({ ...rest, element, html: html ?? "", readOnly: readOnly ?? false, disabled: disabled ?? false });
5
5
  let latest = options;
6
- let last = editor.getHtml();
7
- const stop = editor.subscribe(() => {
8
- const now = editor.getHtml();
9
- if (now === last)
10
- return;
11
- last = now;
12
- latest.onChange?.(now);
13
- });
6
+ const offs = [
7
+ editor.on("change", (now) => latest.onChange?.(now)),
8
+ editor.on("focus", (e) => latest.onFocus?.(e)),
9
+ editor.on("blur", (e) => latest.onBlur?.(e)),
10
+ editor.on("selection", (selection) => latest.onSelection?.(selection)),
11
+ ];
12
+ const stop = () => { for (const off of offs)
13
+ off(); };
14
14
  options.onReady?.(editor);
15
15
  return {
16
16
  update(next) {
17
17
  latest = next;
18
18
  editor.setReadOnly(next.readOnly ?? false);
19
+ editor.setDisabled(next.disabled ?? false);
19
20
  },
20
21
  destroy() {
21
22
  stop();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rathkit/rte-svelte",
3
- "version": "0.1.0-alpha.4",
3
+ "version": "0.1.0-alpha.5",
4
4
  "description": "The editor for Svelte: stores and an action over the headless layer, with no editor or accessibility logic of its own.",
5
5
  "keywords": [
6
6
  "rich-text",
@@ -44,8 +44,8 @@
44
44
  }
45
45
  },
46
46
  "peerDependencies": {
47
- "@rathkit/rte-core": ">=0.1.0-alpha.4 <0.2.0",
48
- "@rathkit/rte-headless": ">=0.1.0-alpha.4 <0.2.0"
47
+ "@rathkit/rte-core": ">=0.1.0-alpha.5 <0.2.0",
48
+ "@rathkit/rte-headless": ">=0.1.0-alpha.5 <0.2.0"
49
49
  },
50
50
  "peerDependenciesMeta": {
51
51
  "@rathkit/rte-core": {