@moldable-ai/editor 0.1.1
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 +101 -0
- package/dist/components/floating-toolbar.d.ts +2 -0
- package/dist/components/floating-toolbar.d.ts.map +1 -0
- package/dist/components/floating-toolbar.js +109 -0
- package/dist/components/markdown-editor.d.ts +15 -0
- package/dist/components/markdown-editor.d.ts.map +1 -0
- package/dist/components/markdown-editor.js +80 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/lib/lexical/auto-link-config.d.ts +21 -0
- package/dist/lib/lexical/auto-link-config.d.ts.map +1 -0
- package/dist/lib/lexical/auto-link-config.js +23 -0
- package/dist/lib/lexical/clickable-link-plugin.d.ts +11 -0
- package/dist/lib/lexical/clickable-link-plugin.d.ts.map +1 -0
- package/dist/lib/lexical/clickable-link-plugin.js +97 -0
- package/dist/lib/lexical/editor-theme.d.ts +38 -0
- package/dist/lib/lexical/editor-theme.d.ts.map +1 -0
- package/dist/lib/lexical/editor-theme.js +37 -0
- package/dist/lib/lexical/floating-toolbar-plugin.d.ts +30 -0
- package/dist/lib/lexical/floating-toolbar-plugin.d.ts.map +1 -0
- package/dist/lib/lexical/floating-toolbar-plugin.js +237 -0
- package/dist/lib/lexical/headless-editor.d.ts +6 -0
- package/dist/lib/lexical/headless-editor.d.ts.map +1 -0
- package/dist/lib/lexical/headless-editor.js +30 -0
- package/dist/lib/lexical/markdown-transformers.d.ts +40 -0
- package/dist/lib/lexical/markdown-transformers.d.ts.map +1 -0
- package/dist/lib/lexical/markdown-transformers.js +52 -0
- package/dist/lib/lexical/split-node-at-selection.d.ts +9 -0
- package/dist/lib/lexical/split-node-at-selection.d.ts.map +1 -0
- package/dist/lib/lexical/split-node-at-selection.js +224 -0
- package/dist/lib/lexical/sync-plugin.d.ts +11 -0
- package/dist/lib/lexical/sync-plugin.d.ts.map +1 -0
- package/dist/lib/lexical/sync-plugin.js +45 -0
- package/package.json +81 -0
- package/src/styles/index.css +71 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
import { $convertFromMarkdownString, $convertToMarkdownString, markdownTransformers, } from './markdown-transformers';
|
|
5
|
+
import { $createParagraphNode, $getRoot } from 'lexical';
|
|
6
|
+
/**
|
|
7
|
+
* Plugin that syncs external value changes with the editor.
|
|
8
|
+
* Handles cases where the value prop changes from outside the editor.
|
|
9
|
+
*/
|
|
10
|
+
export function SyncPlugin({ value, initialValueRef }) {
|
|
11
|
+
const [editor] = useLexicalComposerContext();
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
// Skip if this is the initial render or if value matches what we have
|
|
14
|
+
if (value === initialValueRef.current) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
// Check if the current editor content matches the incoming value
|
|
18
|
+
let currentMarkdown = '';
|
|
19
|
+
editor.read(() => {
|
|
20
|
+
currentMarkdown = $convertToMarkdownString({
|
|
21
|
+
transformers: markdownTransformers,
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
// Only update if the value is actually different
|
|
25
|
+
if (currentMarkdown !== value) {
|
|
26
|
+
editor.update(() => {
|
|
27
|
+
const root = $getRoot();
|
|
28
|
+
root.clear();
|
|
29
|
+
if (value) {
|
|
30
|
+
$convertFromMarkdownString({
|
|
31
|
+
markdown: value,
|
|
32
|
+
transformers: markdownTransformers,
|
|
33
|
+
node: root,
|
|
34
|
+
shouldPreserveNewLines: true,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
root.append($createParagraphNode());
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
initialValueRef.current = value;
|
|
42
|
+
}
|
|
43
|
+
}, [editor, value, initialValueRef]);
|
|
44
|
+
return null;
|
|
45
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@moldable-ai/editor",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Rich text markdown editor for Moldable applications",
|
|
5
|
+
"author": "Desiderata LLC",
|
|
6
|
+
"license": "Elastic-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/moldable-ai/moldable.git",
|
|
10
|
+
"directory": "packages/editor"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://moldable.sh",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/moldable-ai/moldable/issues"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "dist/index.js",
|
|
21
|
+
"types": "dist/index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"require": "./dist/index.js",
|
|
26
|
+
"import": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./styles": "./src/styles/index.css"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"src/styles",
|
|
33
|
+
"LICENSE"
|
|
34
|
+
],
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@lexical/clipboard": "^0.39.0",
|
|
37
|
+
"@lexical/code": "^0.39.0",
|
|
38
|
+
"@lexical/extension": "^0.39.0",
|
|
39
|
+
"@lexical/html": "^0.39.0",
|
|
40
|
+
"@lexical/link": "^0.39.0",
|
|
41
|
+
"@lexical/list": "^0.39.0",
|
|
42
|
+
"@lexical/markdown": "^0.39.0",
|
|
43
|
+
"@lexical/react": "^0.39.0",
|
|
44
|
+
"@lexical/rich-text": "^0.39.0",
|
|
45
|
+
"@lexical/selection": "^0.39.0",
|
|
46
|
+
"@lexical/utils": "^0.39.0",
|
|
47
|
+
"lexical": "^0.39.0",
|
|
48
|
+
"lucide-react": "^0.473.0",
|
|
49
|
+
"react-markdown": "^10.1.0",
|
|
50
|
+
"rehype-raw": "^7.0.0",
|
|
51
|
+
"remark-gfm": "^4.0.1"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@lexical/headless": "^0.39.0",
|
|
55
|
+
"@types/jsdom": "^27.0.0",
|
|
56
|
+
"@types/node": "^24.0.3",
|
|
57
|
+
"@types/react": "^19.1.6",
|
|
58
|
+
"@types/react-dom": "^19.1.6",
|
|
59
|
+
"jsdom": "^27.4.0",
|
|
60
|
+
"typescript": "^5.8.3",
|
|
61
|
+
"vitest": "^4.0.16",
|
|
62
|
+
"@moldable-ai/eslint-config": "0.0.1",
|
|
63
|
+
"@moldable-ai/prettier-config": "0.0.1",
|
|
64
|
+
"@moldable-ai/typescript-config": "0.0.1",
|
|
65
|
+
"@moldable-ai/ui": "^0.1.1"
|
|
66
|
+
},
|
|
67
|
+
"peerDependencies": {
|
|
68
|
+
"react": "^19.0.0",
|
|
69
|
+
"react-dom": "^19.0.0",
|
|
70
|
+
"@moldable-ai/ui": "^0.1.1"
|
|
71
|
+
},
|
|
72
|
+
"scripts": {
|
|
73
|
+
"build": "tsc",
|
|
74
|
+
"dev": "tsc --watch",
|
|
75
|
+
"test": "vitest run",
|
|
76
|
+
"test:watch": "vitest",
|
|
77
|
+
"lint": "eslint . --ext .ts,.tsx --max-warnings 0",
|
|
78
|
+
"format": "prettier --write . --ignore-path ../../.prettierignore",
|
|
79
|
+
"check-types": "tsc --noEmit"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lexical Editor Styles
|
|
3
|
+
* Include this in your app's global CSS: @import '@moldable-ai/editor/styles';
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/* Checklist styles */
|
|
7
|
+
.lexical-listitem-checked,
|
|
8
|
+
.lexical-listitem-unchecked {
|
|
9
|
+
position: relative;
|
|
10
|
+
margin-left: 8px;
|
|
11
|
+
margin-right: 8px;
|
|
12
|
+
padding-left: 24px;
|
|
13
|
+
padding-right: 24px;
|
|
14
|
+
list-style-type: none;
|
|
15
|
+
outline: none;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.lexical-listitem-checked {
|
|
19
|
+
text-decoration: line-through;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.lexical-listitem-unchecked::before,
|
|
23
|
+
.lexical-listitem-checked::before {
|
|
24
|
+
content: '';
|
|
25
|
+
width: 16px;
|
|
26
|
+
height: 16px;
|
|
27
|
+
top: 2px;
|
|
28
|
+
left: 0;
|
|
29
|
+
cursor: pointer;
|
|
30
|
+
display: block;
|
|
31
|
+
background-size: cover;
|
|
32
|
+
position: absolute;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.lexical-listitem-unchecked::before {
|
|
36
|
+
border: 1px solid hsl(var(--border));
|
|
37
|
+
border-radius: 4px;
|
|
38
|
+
background-color: transparent;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.lexical-listitem-checked::before {
|
|
42
|
+
border: 1px solid hsl(var(--primary));
|
|
43
|
+
border-radius: 4px;
|
|
44
|
+
background-color: hsl(var(--primary));
|
|
45
|
+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");
|
|
46
|
+
background-repeat: no-repeat;
|
|
47
|
+
background-position: center;
|
|
48
|
+
background-size: 12px;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* Nested list item styles */
|
|
52
|
+
.lexical-nested-listitem {
|
|
53
|
+
list-style-type: none;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.lexical-nested-listitem::before {
|
|
57
|
+
display: none;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.lexical-nested-listitem::after {
|
|
61
|
+
display: none;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* Mention styles */
|
|
65
|
+
.mention {
|
|
66
|
+
color: hsl(var(--primary));
|
|
67
|
+
font-weight: 600;
|
|
68
|
+
background-color: hsl(var(--primary) / 0.1);
|
|
69
|
+
padding: 0 4px;
|
|
70
|
+
border-radius: 4px;
|
|
71
|
+
}
|