@haklex/rich-plugin-litexml-paste 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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LiteXmlPastePlugin.d.ts","sourceRoot":"","sources":["../src/LiteXmlPastePlugin.tsx"],"names":[],"mappings":"AAMA,wBAAgB,kBAAkB,SAmCjC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,2BAA2B,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { createDefaultRegistry, deserializeNodesFromXml } from "@haklex/rich-litexml";
|
|
2
|
+
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
3
|
+
import { $insertNodes, $parseSerializedNode, COMMAND_PRIORITY_HIGH, PASTE_COMMAND } from "lexical";
|
|
4
|
+
import { useEffect } from "react";
|
|
5
|
+
//#region src/litexml-import.ts
|
|
6
|
+
var LITEXML_TAG_PATTERN = new RegExp(`<\\/?(?:${[
|
|
7
|
+
"doc",
|
|
8
|
+
"fragment",
|
|
9
|
+
"img",
|
|
10
|
+
"video",
|
|
11
|
+
"link-card",
|
|
12
|
+
"embed",
|
|
13
|
+
"codeblock",
|
|
14
|
+
"mermaid",
|
|
15
|
+
"math",
|
|
16
|
+
"alert",
|
|
17
|
+
"banner",
|
|
18
|
+
"nested-doc",
|
|
19
|
+
"details",
|
|
20
|
+
"spoiler",
|
|
21
|
+
"ruby",
|
|
22
|
+
"mention",
|
|
23
|
+
"tag",
|
|
24
|
+
"comment",
|
|
25
|
+
"footnote",
|
|
26
|
+
"footnote-section",
|
|
27
|
+
"gallery",
|
|
28
|
+
"excalidraw",
|
|
29
|
+
"grid",
|
|
30
|
+
"cell",
|
|
31
|
+
"agent-diff",
|
|
32
|
+
"code-snippet",
|
|
33
|
+
"chat",
|
|
34
|
+
"poll"
|
|
35
|
+
].join("|")})(?:\\s|>|\\/>)`, "i");
|
|
36
|
+
function detectLiteXml(text) {
|
|
37
|
+
return LITEXML_TAG_PATTERN.test(text.trim());
|
|
38
|
+
}
|
|
39
|
+
function parseLiteXmlSerializedNodes(xml) {
|
|
40
|
+
if (!detectLiteXml(xml)) return null;
|
|
41
|
+
const nodes = deserializeNodesFromXml(xml, createDefaultRegistry());
|
|
42
|
+
return nodes.length > 0 ? nodes : null;
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/LiteXmlPastePlugin.tsx
|
|
46
|
+
function LiteXmlPastePlugin() {
|
|
47
|
+
const [editor] = useLexicalComposerContext();
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
return editor.registerCommand(PASTE_COMMAND, (event) => {
|
|
50
|
+
const clipboardData = "clipboardData" in event ? event.clipboardData : null;
|
|
51
|
+
if (!clipboardData) return false;
|
|
52
|
+
if (clipboardData.getData("application/x-lexical-editor")) return false;
|
|
53
|
+
if (Array.from(clipboardData.files).some((f) => f.type.startsWith("image/"))) return false;
|
|
54
|
+
const text = clipboardData.getData("text/plain");
|
|
55
|
+
if (!text || !detectLiteXml(text)) return false;
|
|
56
|
+
try {
|
|
57
|
+
const serializedNodes = parseLiteXmlSerializedNodes(text);
|
|
58
|
+
if (!serializedNodes?.length) return false;
|
|
59
|
+
$insertNodes(serializedNodes.map((s) => $parseSerializedNode(s)));
|
|
60
|
+
event.preventDefault();
|
|
61
|
+
return true;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error("LiteXmlPastePlugin: paste error", error);
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}, COMMAND_PRIORITY_HIGH);
|
|
67
|
+
}, [editor]);
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { LiteXmlPastePlugin, detectLiteXml, parseLiteXmlSerializedNodes };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"litexml-import.d.ts","sourceRoot":"","sources":["../src/litexml-import.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAmCrD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,GAAG,qBAAqB,EAAE,GAAG,IAAI,CAMvF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@haklex/rich-plugin-litexml-paste",
|
|
3
|
+
"version": "0.15.0",
|
|
4
|
+
"description": "LiteXML paste plugin for rich-editor — detects pasted Haklex node XML and converts to Lexical nodes",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/Innei/haklex.git",
|
|
8
|
+
"directory": "packages/rich-plugin-litexml-paste"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"main": "./dist/index.mjs",
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@haklex/rich-litexml": "0.15.0"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@lexical/react": "^0.44.0",
|
|
27
|
+
"@types/react": "^19.2.15",
|
|
28
|
+
"@types/react-dom": "^19.2.3",
|
|
29
|
+
"lexical": "^0.44.0",
|
|
30
|
+
"react": "19.2.5",
|
|
31
|
+
"react-dom": "19.2.5",
|
|
32
|
+
"typescript": "^5.9.3",
|
|
33
|
+
"unplugin-dts": "^1.0.1",
|
|
34
|
+
"vite": "^8.0.13"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@lexical/react": "^0.44.0",
|
|
38
|
+
"lexical": "^0.44.0",
|
|
39
|
+
"react": ">=19",
|
|
40
|
+
"react-dom": ">=19"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "vite build",
|
|
47
|
+
"dev:build": "vite build --watch"
|
|
48
|
+
},
|
|
49
|
+
"types": "./dist/index.d.ts"
|
|
50
|
+
}
|