@rathkit/rte-jquery 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 +5 -5
- package/dist/index.d.ts +10 -8
- package/dist/index.js +20 -15
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @rathkit/rte-jquery
|
|
2
2
|
|
|
3
|
-
> **Alpha
|
|
3
|
+
> **Alpha.** Not for production: the APIs will change between releases. Published to the `next` tag only.
|
|
4
4
|
|
|
5
|
-
The editor for jQuery: `$(el).
|
|
5
|
+
The editor for jQuery: `$(el).rteEditor(options)` over the custom element, with `rte:change` events. Works with jQuery 3 and 4.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -21,9 +21,9 @@ import { install } from "@rathkit/rte-jquery";
|
|
|
21
21
|
|
|
22
22
|
install($);
|
|
23
23
|
// in a page with <div id="editor"></div>
|
|
24
|
-
$("#editor").
|
|
25
|
-
$("#editor").on("
|
|
26
|
-
$("#editor").
|
|
24
|
+
$("#editor").rteEditor({ label: "Body", html: "<p>Hello</p>" });
|
|
25
|
+
$("#editor").on("rte:change", (event, html) => console.log(html));
|
|
26
|
+
$("#editor").rteEditor("html"); // read it; rteEditor("html", "<p>x</p>") replaces it
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
## More
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export interface
|
|
1
|
+
import type { RteElementOptions } from "@rathkit/rte-element";
|
|
2
|
+
export interface RteJqueryOptions extends RteElementOptions {
|
|
3
3
|
/** The starting HTML. */
|
|
4
4
|
html?: string;
|
|
5
5
|
readOnly?: boolean;
|
|
6
|
+
/** Read-only, and not focusable or in the tab order. */
|
|
7
|
+
disabled?: boolean;
|
|
6
8
|
/** The name screen readers announce for the editing surface. */
|
|
7
9
|
label: string;
|
|
8
10
|
}
|
|
@@ -13,12 +15,12 @@ interface JQueryLike {
|
|
|
13
15
|
};
|
|
14
16
|
}
|
|
15
17
|
/**
|
|
16
|
-
* Adds `.
|
|
17
|
-
* - `$(el).
|
|
18
|
-
* - `$(el).
|
|
19
|
-
* - `$(el).
|
|
20
|
-
* - `$(el).
|
|
21
|
-
* Changes arrive as `
|
|
18
|
+
* Adds `.rteEditor()` to jQuery:
|
|
19
|
+
* - `$(el).rteEditor({ label, html, ... })` turns the element into an editor, once;
|
|
20
|
+
* - `$(el).rteEditor("html")` reads the HTML of the first element, `$(el).rteEditor("html", "<p>x</p>")` replaces it;
|
|
21
|
+
* - `$(el).rteEditor("editor")` gives the editor of the first element (a promise, because it is built when the element connects);
|
|
22
|
+
* - `$(el).rteEditor("destroy")` removes it.
|
|
23
|
+
* Changes arrive as `rte:change` events with the HTML as the second argument to the handler.
|
|
22
24
|
*/
|
|
23
25
|
export declare function install($?: JQueryLike): void;
|
|
24
26
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const KEY = "
|
|
2
|
-
const editorOf = (host) => host?.
|
|
1
|
+
const KEY = "rteEditor";
|
|
2
|
+
const editorOf = (host) => host?.__rte ?? host;
|
|
3
3
|
export function install($ = globalThis.jQuery) {
|
|
4
4
|
$.fn[KEY] = function (arg, value) {
|
|
5
5
|
if (typeof arg === "string") {
|
|
@@ -14,33 +14,38 @@ export function install($ = globalThis.jQuery) {
|
|
|
14
14
|
case "editor":
|
|
15
15
|
return first?.whenReady();
|
|
16
16
|
case "destroy":
|
|
17
|
-
this.each(function () { this.
|
|
17
|
+
this.each(function () { this.__rte?.remove(); delete this.__rte; });
|
|
18
18
|
return this;
|
|
19
19
|
default:
|
|
20
|
-
throw new Error(`
|
|
20
|
+
throw new Error(`rteEditor: unknown method "${arg}"`);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
const options = arg;
|
|
24
24
|
return this.each(function () {
|
|
25
25
|
const host = this;
|
|
26
|
-
if (host.
|
|
26
|
+
if (host.__rte)
|
|
27
27
|
return;
|
|
28
|
-
const { html, readOnly, label, ...rest } = options;
|
|
29
|
-
const el = document.createElement("
|
|
28
|
+
const { html, readOnly, disabled, label, ...rest } = options;
|
|
29
|
+
const el = document.createElement("rte-editor");
|
|
30
30
|
el.setAttribute("label", label);
|
|
31
31
|
if (html !== undefined)
|
|
32
32
|
el.setAttribute("value", html);
|
|
33
33
|
if (readOnly)
|
|
34
34
|
el.setAttribute("readonly", "");
|
|
35
|
+
if (disabled)
|
|
36
|
+
el.setAttribute("disabled", "");
|
|
35
37
|
el.options = rest;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
for (const name of ["change", "ready", "focus", "blur", "selection"]) {
|
|
39
|
+
el.addEventListener(`rte-${name}`, (event) => {
|
|
40
|
+
const detail = event.detail;
|
|
41
|
+
const payload = name === "change" ? detail.html : name === "selection" ? detail.selection : (host.__rte?.editor ?? detail.editor);
|
|
42
|
+
if (typeof $ === "function")
|
|
43
|
+
$(host).trigger(`rte:${name}`, [payload]);
|
|
44
|
+
else
|
|
45
|
+
host.dispatchEvent(new CustomEvent(`rte:${name}`, { bubbles: true, detail }));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
host.__rte = el;
|
|
44
49
|
host.appendChild(el);
|
|
45
50
|
});
|
|
46
51
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rathkit/rte-jquery",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
4
|
-
"description": "The editor for jQuery: $(el).
|
|
3
|
+
"version": "0.1.0-alpha.5",
|
|
4
|
+
"description": "The editor for jQuery: $(el).rteEditor(options) over the custom element, with rte:change events.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rich-text",
|
|
7
7
|
"editor",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@rathkit/rte-core": ">=0.1.0-alpha.
|
|
48
|
-
"@rathkit/rte-element": ">=0.1.0-alpha.
|
|
47
|
+
"@rathkit/rte-core": ">=0.1.0-alpha.5 <0.2.0",
|
|
48
|
+
"@rathkit/rte-element": ">=0.1.0-alpha.5 <0.2.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependenciesMeta": {
|
|
51
51
|
"@rathkit/rte-core": {
|