@matrajs/solid 0.15.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/LICENSE +21 -0
- package/README.md +59 -0
- package/dist/index.cjs +30 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +42 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nahim Hossain Shohan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# @matrajs/solid
|
|
2
|
+
|
|
3
|
+
Solid bindings for [Matra](https://matrajs.com): `createMatra`, and a signal
|
|
4
|
+
that follows the editor.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npm i @matrajs/core @matrajs/solid
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```tsx
|
|
11
|
+
import { starterKit } from '@matrajs/core'
|
|
12
|
+
import { createMatra } from '@matrajs/solid'
|
|
13
|
+
|
|
14
|
+
export function Editor() {
|
|
15
|
+
const { editor, mount, state } = createMatra({
|
|
16
|
+
extensions: starterKit,
|
|
17
|
+
content: '<p>Hello</p>',
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<>
|
|
22
|
+
<button
|
|
23
|
+
onClick={() => editor.commands.toggleBold()}
|
|
24
|
+
aria-pressed={state().isActive('bold')}
|
|
25
|
+
>
|
|
26
|
+
Bold
|
|
27
|
+
</button>
|
|
28
|
+
<div ref={mount} />
|
|
29
|
+
</>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## What it adds
|
|
35
|
+
|
|
36
|
+
Solid's reactivity is not a render loop, so there is no external-store shape to
|
|
37
|
+
reach for. A signal that bumps on every change is enough: everything reading
|
|
38
|
+
`state()` re-runs and nothing else does.
|
|
39
|
+
|
|
40
|
+
- **`state()` returns the editor itself**, not a copy. A toolbar asks
|
|
41
|
+
`isActive` at render time, and cloning a document to answer that would be the
|
|
42
|
+
expensive way to do nothing. What changes behind it is a version counter,
|
|
43
|
+
because the editor is one object that never changes identity — a signal
|
|
44
|
+
holding it directly would never notify.
|
|
45
|
+
- **`onCleanup` destroys it**, so the element is safe to reuse.
|
|
46
|
+
- **`mount` is guarded**, because a ref can run twice under a hot reload.
|
|
47
|
+
|
|
48
|
+
The editor is created immediately rather than on mount, so `commands`,
|
|
49
|
+
`getJSON()` and `getText()` all work before anything is on screen — which is
|
|
50
|
+
what SSR and a test both need.
|
|
51
|
+
|
|
52
|
+
## Styling
|
|
53
|
+
|
|
54
|
+
Matra ships no appearance. See
|
|
55
|
+
[the styling guide](https://matrajs.com/docs/styling).
|
|
56
|
+
|
|
57
|
+
## Licence
|
|
58
|
+
|
|
59
|
+
MIT.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@matrajs/core');
|
|
4
|
+
var solidJs = require('solid-js');
|
|
5
|
+
|
|
6
|
+
// src/index.ts
|
|
7
|
+
function createMatra(options) {
|
|
8
|
+
const editor = core.createEditor(options);
|
|
9
|
+
const [version, bump] = solidJs.createSignal(0);
|
|
10
|
+
const republish = () => bump((count) => count + 1);
|
|
11
|
+
const offChange = editor.on("change", republish);
|
|
12
|
+
const offSelection = editor.on("selectionChange", republish);
|
|
13
|
+
solidJs.onCleanup(() => {
|
|
14
|
+
offChange();
|
|
15
|
+
offSelection();
|
|
16
|
+
editor.destroy();
|
|
17
|
+
});
|
|
18
|
+
const mount = (element) => {
|
|
19
|
+
if (!editor.unsafe.view) editor.mount(element);
|
|
20
|
+
};
|
|
21
|
+
const state = () => {
|
|
22
|
+
version();
|
|
23
|
+
return editor;
|
|
24
|
+
};
|
|
25
|
+
return { editor, mount, state };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
exports.createMatra = createMatra;
|
|
29
|
+
//# sourceMappingURL=index.cjs.map
|
|
30
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["createEditor","createSignal","onCleanup"],"mappings":";;;;;;AAyCO,SAAS,YACd,OAAA,EACgB;AAChB,EAAA,MAAM,MAAA,GAASA,kBAAa,OAAO,CAAA;AAInC,EAAA,MAAM,CAAC,OAAA,EAAS,IAAI,CAAA,GAAIC,qBAAa,CAAC,CAAA;AACtC,EAAA,MAAM,YAAY,MAAM,IAAA,CAAK,CAAC,KAAA,KAAU,QAAQ,CAAC,CAAA;AAEjD,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,EAAA,CAAG,QAAA,EAAU,SAAS,CAAA;AAC/C,EAAA,MAAM,YAAA,GAAe,MAAA,CAAO,EAAA,CAAG,iBAAA,EAAmB,SAAS,CAAA;AAE3D,EAAAC,iBAAA,CAAU,MAAM;AACd,IAAA,SAAA,EAAU;AACV,IAAA,YAAA,EAAa;AACb,IAAA,MAAA,CAAO,OAAA,EAAQ;AAAA,EACjB,CAAC,CAAA;AAED,EAAA,MAAM,KAAA,GAAQ,CAAC,OAAA,KAAyB;AAGtC,IAAA,IAAI,CAAC,MAAA,CAAO,MAAA,CAAO,IAAA,EAAM,MAAA,CAAO,MAAM,OAAO,CAAA;AAAA,EAC/C,CAAA;AAEA,EAAA,MAAM,QAA6B,MAAM;AACvC,IAAA,OAAA,EAAQ;AACR,IAAA,OAAO,MAAA;AAAA,EACT,CAAA;AAEA,EAAA,OAAO,EAAE,MAAA,EAAQ,KAAA,EAAO,KAAA,EAAM;AAChC","file":"index.cjs","sourcesContent":["import { type AnyDef, type Editor, type EditorOptions, createEditor } from '@matrajs/core'\nimport { type Accessor, createSignal, onCleanup } from 'solid-js'\n\n/**\n * Solid bindings.\n *\n * Solid's reactivity is not a render loop, so there is no `useSyncExternalStore`\n * shape to reach for: a signal that bumps on every change is enough, and\n * everything reading it re-runs and nothing else does.\n */\n\nexport interface MatraEditor<T extends readonly AnyDef[]> {\n /** The editor. It exists before anything is on screen. */\n editor: Editor<T>\n /** `ref={mount}` on the element the editor should live in. */\n mount: (element: HTMLElement) => void\n /**\n * Read this inside JSX to re-run when the editor changes.\n *\n * It returns the editor itself rather than a copy, because a toolbar asks\n * `isActive` at render time and cloning a document to answer that would be\n * the expensive way to do nothing.\n */\n state: Accessor<Editor<T>>\n}\n\n/**\n * Create an editor bound to this component's lifetime.\n *\n * ```tsx\n * const { editor, mount, state } = createMatra({ extensions: starterKit })\n *\n * return (\n * <>\n * <button onClick={() => editor.commands.toggleBold()}\n * aria-pressed={state().isActive('bold')}>Bold</button>\n * <div ref={mount} />\n * </>\n * )\n * ```\n */\nexport function createMatra<const T extends readonly AnyDef[]>(\n options: EditorOptions<T>,\n): MatraEditor<T> {\n const editor = createEditor(options)\n\n // A counter rather than the editor itself: the editor is one object that\n // never changes identity, so a signal holding it would never notify.\n const [version, bump] = createSignal(0)\n const republish = () => bump((count) => count + 1)\n\n const offChange = editor.on('change', republish)\n const offSelection = editor.on('selectionChange', republish)\n\n onCleanup(() => {\n offChange()\n offSelection()\n editor.destroy()\n })\n\n const mount = (element: HTMLElement) => {\n // Guarded, because a ref can run twice under a hot reload and two views on\n // one element is two carets fighting over it.\n if (!editor.unsafe.view) editor.mount(element)\n }\n\n const state: Accessor<Editor<T>> = () => {\n version()\n return editor\n }\n\n return { editor, mount, state }\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AnyDef, Editor, EditorOptions } from '@matrajs/core';
|
|
2
|
+
import { Accessor } from 'solid-js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Solid bindings.
|
|
6
|
+
*
|
|
7
|
+
* Solid's reactivity is not a render loop, so there is no `useSyncExternalStore`
|
|
8
|
+
* shape to reach for: a signal that bumps on every change is enough, and
|
|
9
|
+
* everything reading it re-runs and nothing else does.
|
|
10
|
+
*/
|
|
11
|
+
interface MatraEditor<T extends readonly AnyDef[]> {
|
|
12
|
+
/** The editor. It exists before anything is on screen. */
|
|
13
|
+
editor: Editor<T>;
|
|
14
|
+
/** `ref={mount}` on the element the editor should live in. */
|
|
15
|
+
mount: (element: HTMLElement) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Read this inside JSX to re-run when the editor changes.
|
|
18
|
+
*
|
|
19
|
+
* It returns the editor itself rather than a copy, because a toolbar asks
|
|
20
|
+
* `isActive` at render time and cloning a document to answer that would be
|
|
21
|
+
* the expensive way to do nothing.
|
|
22
|
+
*/
|
|
23
|
+
state: Accessor<Editor<T>>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create an editor bound to this component's lifetime.
|
|
27
|
+
*
|
|
28
|
+
* ```tsx
|
|
29
|
+
* const { editor, mount, state } = createMatra({ extensions: starterKit })
|
|
30
|
+
*
|
|
31
|
+
* return (
|
|
32
|
+
* <>
|
|
33
|
+
* <button onClick={() => editor.commands.toggleBold()}
|
|
34
|
+
* aria-pressed={state().isActive('bold')}>Bold</button>
|
|
35
|
+
* <div ref={mount} />
|
|
36
|
+
* </>
|
|
37
|
+
* )
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare function createMatra<const T extends readonly AnyDef[]>(options: EditorOptions<T>): MatraEditor<T>;
|
|
41
|
+
|
|
42
|
+
export { type MatraEditor, createMatra };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AnyDef, Editor, EditorOptions } from '@matrajs/core';
|
|
2
|
+
import { Accessor } from 'solid-js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Solid bindings.
|
|
6
|
+
*
|
|
7
|
+
* Solid's reactivity is not a render loop, so there is no `useSyncExternalStore`
|
|
8
|
+
* shape to reach for: a signal that bumps on every change is enough, and
|
|
9
|
+
* everything reading it re-runs and nothing else does.
|
|
10
|
+
*/
|
|
11
|
+
interface MatraEditor<T extends readonly AnyDef[]> {
|
|
12
|
+
/** The editor. It exists before anything is on screen. */
|
|
13
|
+
editor: Editor<T>;
|
|
14
|
+
/** `ref={mount}` on the element the editor should live in. */
|
|
15
|
+
mount: (element: HTMLElement) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Read this inside JSX to re-run when the editor changes.
|
|
18
|
+
*
|
|
19
|
+
* It returns the editor itself rather than a copy, because a toolbar asks
|
|
20
|
+
* `isActive` at render time and cloning a document to answer that would be
|
|
21
|
+
* the expensive way to do nothing.
|
|
22
|
+
*/
|
|
23
|
+
state: Accessor<Editor<T>>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create an editor bound to this component's lifetime.
|
|
27
|
+
*
|
|
28
|
+
* ```tsx
|
|
29
|
+
* const { editor, mount, state } = createMatra({ extensions: starterKit })
|
|
30
|
+
*
|
|
31
|
+
* return (
|
|
32
|
+
* <>
|
|
33
|
+
* <button onClick={() => editor.commands.toggleBold()}
|
|
34
|
+
* aria-pressed={state().isActive('bold')}>Bold</button>
|
|
35
|
+
* <div ref={mount} />
|
|
36
|
+
* </>
|
|
37
|
+
* )
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare function createMatra<const T extends readonly AnyDef[]>(options: EditorOptions<T>): MatraEditor<T>;
|
|
41
|
+
|
|
42
|
+
export { type MatraEditor, createMatra };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createEditor } from '@matrajs/core';
|
|
2
|
+
import { createSignal, onCleanup } from 'solid-js';
|
|
3
|
+
|
|
4
|
+
// src/index.ts
|
|
5
|
+
function createMatra(options) {
|
|
6
|
+
const editor = createEditor(options);
|
|
7
|
+
const [version, bump] = createSignal(0);
|
|
8
|
+
const republish = () => bump((count) => count + 1);
|
|
9
|
+
const offChange = editor.on("change", republish);
|
|
10
|
+
const offSelection = editor.on("selectionChange", republish);
|
|
11
|
+
onCleanup(() => {
|
|
12
|
+
offChange();
|
|
13
|
+
offSelection();
|
|
14
|
+
editor.destroy();
|
|
15
|
+
});
|
|
16
|
+
const mount = (element) => {
|
|
17
|
+
if (!editor.unsafe.view) editor.mount(element);
|
|
18
|
+
};
|
|
19
|
+
const state = () => {
|
|
20
|
+
version();
|
|
21
|
+
return editor;
|
|
22
|
+
};
|
|
23
|
+
return { editor, mount, state };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { createMatra };
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;AAyCO,SAAS,YACd,OAAA,EACgB;AAChB,EAAA,MAAM,MAAA,GAAS,aAAa,OAAO,CAAA;AAInC,EAAA,MAAM,CAAC,OAAA,EAAS,IAAI,CAAA,GAAI,aAAa,CAAC,CAAA;AACtC,EAAA,MAAM,YAAY,MAAM,IAAA,CAAK,CAAC,KAAA,KAAU,QAAQ,CAAC,CAAA;AAEjD,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,EAAA,CAAG,QAAA,EAAU,SAAS,CAAA;AAC/C,EAAA,MAAM,YAAA,GAAe,MAAA,CAAO,EAAA,CAAG,iBAAA,EAAmB,SAAS,CAAA;AAE3D,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,SAAA,EAAU;AACV,IAAA,YAAA,EAAa;AACb,IAAA,MAAA,CAAO,OAAA,EAAQ;AAAA,EACjB,CAAC,CAAA;AAED,EAAA,MAAM,KAAA,GAAQ,CAAC,OAAA,KAAyB;AAGtC,IAAA,IAAI,CAAC,MAAA,CAAO,MAAA,CAAO,IAAA,EAAM,MAAA,CAAO,MAAM,OAAO,CAAA;AAAA,EAC/C,CAAA;AAEA,EAAA,MAAM,QAA6B,MAAM;AACvC,IAAA,OAAA,EAAQ;AACR,IAAA,OAAO,MAAA;AAAA,EACT,CAAA;AAEA,EAAA,OAAO,EAAE,MAAA,EAAQ,KAAA,EAAO,KAAA,EAAM;AAChC","file":"index.js","sourcesContent":["import { type AnyDef, type Editor, type EditorOptions, createEditor } from '@matrajs/core'\nimport { type Accessor, createSignal, onCleanup } from 'solid-js'\n\n/**\n * Solid bindings.\n *\n * Solid's reactivity is not a render loop, so there is no `useSyncExternalStore`\n * shape to reach for: a signal that bumps on every change is enough, and\n * everything reading it re-runs and nothing else does.\n */\n\nexport interface MatraEditor<T extends readonly AnyDef[]> {\n /** The editor. It exists before anything is on screen. */\n editor: Editor<T>\n /** `ref={mount}` on the element the editor should live in. */\n mount: (element: HTMLElement) => void\n /**\n * Read this inside JSX to re-run when the editor changes.\n *\n * It returns the editor itself rather than a copy, because a toolbar asks\n * `isActive` at render time and cloning a document to answer that would be\n * the expensive way to do nothing.\n */\n state: Accessor<Editor<T>>\n}\n\n/**\n * Create an editor bound to this component's lifetime.\n *\n * ```tsx\n * const { editor, mount, state } = createMatra({ extensions: starterKit })\n *\n * return (\n * <>\n * <button onClick={() => editor.commands.toggleBold()}\n * aria-pressed={state().isActive('bold')}>Bold</button>\n * <div ref={mount} />\n * </>\n * )\n * ```\n */\nexport function createMatra<const T extends readonly AnyDef[]>(\n options: EditorOptions<T>,\n): MatraEditor<T> {\n const editor = createEditor(options)\n\n // A counter rather than the editor itself: the editor is one object that\n // never changes identity, so a signal holding it would never notify.\n const [version, bump] = createSignal(0)\n const republish = () => bump((count) => count + 1)\n\n const offChange = editor.on('change', republish)\n const offSelection = editor.on('selectionChange', republish)\n\n onCleanup(() => {\n offChange()\n offSelection()\n editor.destroy()\n })\n\n const mount = (element: HTMLElement) => {\n // Guarded, because a ref can run twice under a hot reload and two views on\n // one element is two carets fighting over it.\n if (!editor.unsafe.view) editor.mount(element)\n }\n\n const state: Accessor<Editor<T>> = () => {\n version()\n return editor\n }\n\n return { editor, mount, state }\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@matrajs/solid",
|
|
3
|
+
"version": "0.15.0",
|
|
4
|
+
"description": "Solid bindings for Matra — createMatra, and a signal that follows it.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Nahim Hossain Shohan",
|
|
7
|
+
"homepage": "https://matrajs.com",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/amrelaco/matra.git",
|
|
11
|
+
"directory": "packages/solid"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/amrelaco/matra/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"editor",
|
|
18
|
+
"rich-text",
|
|
19
|
+
"solid",
|
|
20
|
+
"solid-js",
|
|
21
|
+
"matra"
|
|
22
|
+
],
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"main": "./dist/index.cjs",
|
|
29
|
+
"module": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.js",
|
|
35
|
+
"require": "./dist/index.cjs"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"README.md"
|
|
41
|
+
],
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@matrajs/core": "^0.15.0"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"solid-js": ">=1.8"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/react": "^18.3.12",
|
|
50
|
+
"react": "^18.3.1",
|
|
51
|
+
"react-dom": "^18.3.1"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsup",
|
|
55
|
+
"clean": "rm -rf dist"
|
|
56
|
+
}
|
|
57
|
+
}
|