@rathkit/rte-jquery 0.0.0 → 0.1.0-alpha.3
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 +28 -4
- package/dist/index.d.ts +24 -0
- package/dist/index.js +47 -0
- package/package.json +61 -3
package/README.md
CHANGED
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
# @rathkit/rte-jquery
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **Alpha** (0.1.0-alpha.0). Not for production: the APIs will change between releases. Published to the `next` tag only.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The editor for jQuery: `$(el).rkEditor(options)` over the custom element, with `rk:change` events. Works with jQuery 3 and 4.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
6
8
|
|
|
7
9
|
```sh
|
|
8
|
-
npm install @rathkit/rte-jquery@next
|
|
10
|
+
npm install @rathkit/rte-jquery@next @rathkit/rte-core@next @rathkit/rte-element@next
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
This package has no dependencies of its own. It works with `@rathkit/rte-core`, `@rathkit/rte-element` (peer dependencies, all optional so that npm installs nothing you did not ask for), so install the ones you use alongside it.
|
|
14
|
+
|
|
15
|
+
## Example
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import $ from "jquery";
|
|
19
|
+
import "@rathkit/rte-element/define";
|
|
20
|
+
import { install } from "@rathkit/rte-jquery";
|
|
21
|
+
|
|
22
|
+
install($);
|
|
23
|
+
// in a page with <div id="editor"></div>
|
|
24
|
+
$("#editor").rkEditor({ label: "Body", html: "<p>Hello</p>" });
|
|
25
|
+
$("#editor").on("rk:change", (event, html) => console.log(html));
|
|
26
|
+
$("#editor").rkEditor("html"); // read it; rkEditor("html", "<p>x</p>") replaces it
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## More
|
|
30
|
+
|
|
31
|
+
Documentation: <https://rathkit.com>. Source and issues: <https://github.com/rathkit/rte>. What is checked: [SUPPORT.md](https://github.com/rathkit/rte/blob/main/docs/SUPPORT.md). Changes: [CHANGELOG.md](https://github.com/rathkit/rte/blob/main/CHANGELOG.md). How a release is verified: [VERIFY.md](https://github.com/rathkit/rte/blob/main/docs/VERIFY.md).
|
|
32
|
+
|
|
33
|
+
## License
|
|
34
|
+
|
|
35
|
+
[Apache-2.0](LICENSE)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { RkEditorOptions } from "@rathkit/rte-element";
|
|
2
|
+
export interface RkJqueryOptions extends RkEditorOptions {
|
|
3
|
+
/** The starting HTML. */
|
|
4
|
+
html?: string;
|
|
5
|
+
readOnly?: boolean;
|
|
6
|
+
/** The name screen readers announce for the editing surface. */
|
|
7
|
+
label: string;
|
|
8
|
+
}
|
|
9
|
+
interface JQueryLike {
|
|
10
|
+
fn: Record<string, unknown>;
|
|
11
|
+
(element: Element): {
|
|
12
|
+
trigger(name: string, data: unknown[]): void;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Adds `.rkEditor()` to jQuery:
|
|
17
|
+
* - `$(el).rkEditor({ label, html, ... })` turns the element into an editor, once;
|
|
18
|
+
* - `$(el).rkEditor("html")` reads the HTML of the first element, `$(el).rkEditor("html", "<p>x</p>")` replaces it;
|
|
19
|
+
* - `$(el).rkEditor("editor")` gives the editor of the first element (a promise, because it is built when the element connects);
|
|
20
|
+
* - `$(el).rkEditor("destroy")` removes it.
|
|
21
|
+
* Changes arrive as `rk:change` events with the HTML as the second argument to the handler.
|
|
22
|
+
*/
|
|
23
|
+
export declare function install($?: JQueryLike): void;
|
|
24
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const KEY = "rkEditor";
|
|
2
|
+
const editorOf = (host) => host?.__rk ?? host;
|
|
3
|
+
export function install($ = globalThis.jQuery) {
|
|
4
|
+
$.fn[KEY] = function (arg, value) {
|
|
5
|
+
if (typeof arg === "string") {
|
|
6
|
+
const first = editorOf(this[0]);
|
|
7
|
+
switch (arg) {
|
|
8
|
+
case "html":
|
|
9
|
+
if (value === undefined)
|
|
10
|
+
return first?.value;
|
|
11
|
+
this.each(function () { const el = editorOf(this); if (el)
|
|
12
|
+
el.value = value; });
|
|
13
|
+
return this;
|
|
14
|
+
case "editor":
|
|
15
|
+
return first?.whenReady();
|
|
16
|
+
case "destroy":
|
|
17
|
+
this.each(function () { this.__rk?.remove(); delete this.__rk; });
|
|
18
|
+
return this;
|
|
19
|
+
default:
|
|
20
|
+
throw new Error(`rkEditor: unknown method "${arg}"`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const options = arg;
|
|
24
|
+
return this.each(function () {
|
|
25
|
+
const host = this;
|
|
26
|
+
if (host.__rk)
|
|
27
|
+
return;
|
|
28
|
+
const { html, readOnly, label, ...rest } = options;
|
|
29
|
+
const el = document.createElement("rk-editor");
|
|
30
|
+
el.setAttribute("label", label);
|
|
31
|
+
if (html !== undefined)
|
|
32
|
+
el.setAttribute("value", html);
|
|
33
|
+
if (readOnly)
|
|
34
|
+
el.setAttribute("readonly", "");
|
|
35
|
+
el.options = rest;
|
|
36
|
+
el.addEventListener("rk-change", (event) => {
|
|
37
|
+
const detail = event.detail;
|
|
38
|
+
if (typeof $ === "function")
|
|
39
|
+
$(host).trigger("rk:change", [detail.html]);
|
|
40
|
+
else
|
|
41
|
+
host.dispatchEvent(new CustomEvent("rk:change", { bubbles: true, detail }));
|
|
42
|
+
});
|
|
43
|
+
host.__rk = el;
|
|
44
|
+
host.appendChild(el);
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rathkit/rte-jquery",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0-alpha.3",
|
|
4
|
+
"description": "The editor for jQuery: $(el).rkEditor(options) over the custom element, with rk:change events.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"rich-text",
|
|
7
|
+
"editor",
|
|
8
|
+
"wysiwyg",
|
|
9
|
+
"contenteditable",
|
|
10
|
+
"zero-dependencies",
|
|
11
|
+
"typescript",
|
|
12
|
+
"jquery",
|
|
13
|
+
"plugin"
|
|
14
|
+
],
|
|
5
15
|
"license": "Apache-2.0",
|
|
6
16
|
"homepage": "https://rathkit.com",
|
|
7
17
|
"repository": {
|
|
@@ -12,7 +22,55 @@
|
|
|
12
22
|
"bugs": {
|
|
13
23
|
"url": "https://github.com/rathkit/rte/issues"
|
|
14
24
|
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=22.14.0"
|
|
29
|
+
},
|
|
15
30
|
"publishConfig": {
|
|
16
|
-
"access": "public"
|
|
31
|
+
"access": "public",
|
|
32
|
+
"provenance": true,
|
|
33
|
+
"tag": "next"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"NOTICE",
|
|
38
|
+
"!dist/**/*.map"
|
|
39
|
+
],
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"types": "./dist/index.d.ts",
|
|
43
|
+
"default": "./dist/index.js"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@rathkit/rte-core": ">=0.1.0-alpha.3 <0.2.0",
|
|
48
|
+
"@rathkit/rte-element": ">=0.1.0-alpha.3 <0.2.0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"@rathkit/rte-core": {
|
|
52
|
+
"optional": true
|
|
53
|
+
},
|
|
54
|
+
"@rathkit/rte-element": {
|
|
55
|
+
"optional": true
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@rathkit/rte-core": "workspace:*",
|
|
60
|
+
"@rathkit/rte-element": "workspace:*"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json && tsc -p tsconfig.build.js.json",
|
|
64
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
65
|
+
"test": "node --test \"src/**/*.test.ts\""
|
|
66
|
+
},
|
|
67
|
+
"rathkit": {
|
|
68
|
+
"budgets": [
|
|
69
|
+
{
|
|
70
|
+
"name": "jquery",
|
|
71
|
+
"entry": "dist/index.js",
|
|
72
|
+
"gzipKB": 2
|
|
73
|
+
}
|
|
74
|
+
]
|
|
17
75
|
}
|
|
18
76
|
}
|