@phuong-tran-redoc/document-engine-core 0.0.27 → 0.0.29
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/package.json
CHANGED
|
@@ -48,8 +48,35 @@ import { Node, mergeAttributes } from '@tiptap/core';
|
|
|
48
48
|
* Parse HTML to recognize dynamic field spans when loading/pasting content
|
|
49
49
|
*/ parseHTML () {
|
|
50
50
|
return [
|
|
51
|
+
// ----------------------------------------------------------
|
|
52
|
+
// RULE 1: Standard Tiptap Format (Ưu tiên cao nhất)
|
|
53
|
+
// ----------------------------------------------------------
|
|
51
54
|
{
|
|
52
55
|
tag: 'span[data-field-id]'
|
|
56
|
+
},
|
|
57
|
+
// ----------------------------------------------------------
|
|
58
|
+
// RULE 2: Legacy CKEditor Format (Migration Layer)
|
|
59
|
+
// ----------------------------------------------------------
|
|
60
|
+
{
|
|
61
|
+
// Selector CSS để nhận diện node của CKEditor
|
|
62
|
+
tag: 'span.red-dynamic-field',
|
|
63
|
+
// Hàm này chạy khi Tiptap tìm thấy tag trên
|
|
64
|
+
getAttrs: (node)=>{
|
|
65
|
+
if (typeof node === 'string') return false;
|
|
66
|
+
const element = node;
|
|
67
|
+
// 1. Trích xuất ID từ nội dung text: "{{ref}}" -> "ref"
|
|
68
|
+
const rawText = element.innerText || element.textContent || '';
|
|
69
|
+
// Regex để xóa dấu {{ và }} và khoảng trắng thừa
|
|
70
|
+
const id = rawText.replace(/{{|}}/g, '').trim();
|
|
71
|
+
// 2. Trích xuất Label từ attribute cũ
|
|
72
|
+
// CKEditor dùng 'value', 'dynamicfieldname' hoặc 'name'
|
|
73
|
+
const label = element.getAttribute('value') || element.getAttribute('dynamicfieldname') || element.getAttribute('name') || id; // Fallback nếu không tìm thấy label
|
|
74
|
+
// Trả về object khớp với cấu trúc 'addAttributes' ở trên
|
|
75
|
+
return {
|
|
76
|
+
fieldId: id,
|
|
77
|
+
label: label
|
|
78
|
+
};
|
|
79
|
+
}
|
|
53
80
|
}
|
|
54
81
|
];
|
|
55
82
|
},
|