jack 1 неделя назад
Родитель
Сommit
b01f123ef6
2 измененных файлов с 78 добавлено и 40 удалено
  1. 2 2
      src/hooks/useImport.ts
  2. 76 38
      src/utils/prosemirror/schema/nodes.ts

+ 2 - 2
src/hooks/useImport.ts

@@ -1946,8 +1946,8 @@ export default () => {
                   : undefined
 
                 const pattern: string | undefined = el.fill?.type === 'image' ? el.fill.value.picBase64 : undefined
-                const fill = el.fill?.type === 'color' ? el.fill.value : ''
-                const style = getStyle(convertFontSizePtToPx(el.content, ratio, el.autoFit)) + (el.pathBBox.pWidth ? ';width:' + (el.pathBBox.pWidth * ratio) + 'px;height:' + (el.pathBBox.pHeight * ratio) + 'px;' : '') // 设置字体的样式等,这里由于不支持的样式在里面会过滤
+                const fill = el.fill?.type === 'color' ? el.fill.value : 'none'
+                const style = getStyle(convertFontSizePtToPx(el.content, ratio, el.autoFit)) + (el.pathBBox?.pWidth ? ';width:' + (el.pathBBox?.pWidth * ratio) + 'px;height:' + (el.pathBBox?.pHeight * ratio) + 'px;' : '') // 设置字体的样式等,这里由于不支持的样式在里面会过滤
                 const element: PPTShapeElement = {
                   type: 'shape',
                   id: nanoid(10),

+ 76 - 38
src/utils/prosemirror/schema/nodes.ts

@@ -101,7 +101,6 @@ const listItem: NodeSpec = {
   group: 'block',
 }
 */
-
 const listItem: NodeSpec = {
   attrs: {
     align: { default: '' },
@@ -110,7 +109,12 @@ const listItem: NodeSpec = {
     marginBottom: { default: '' },
     marginLeft: { default: '' },
     marginRight: { default: '' },
-    lineHeight: { default: '' },   // ✅ 新增
+    lineHeight: { default: '' },
+    // ✅ 新增 padding 属性
+    paddingTop: { default: '' },
+    paddingRight: { default: '' },
+    paddingBottom: { default: '' },
+    paddingLeft: { default: '' },
   },
   content: 'paragraph block*',
   group: 'block',
@@ -128,7 +132,12 @@ const listItem: NodeSpec = {
         const marginBottom = style.marginBottom || '';
         const marginLeft = style.marginLeft || '';
         const marginRight = style.marginRight || '';
-        const lineHeight = style.lineHeight || '';   // ✅ 新增
+        const lineHeight = style.lineHeight || '';
+        // ✅ 读取 padding 值
+        const paddingTop = style.paddingTop || '';
+        const paddingRight = style.paddingRight || '';
+        const paddingBottom = style.paddingBottom || '';
+        const paddingLeft = style.paddingLeft || '';
 
         let align = textAlign || textAlignLast || '';
         align = /^(left|right|center|justify)$/.test(align) ? align : '';
@@ -140,7 +149,11 @@ const listItem: NodeSpec = {
           marginBottom,
           marginLeft,
           marginRight,
-          lineHeight,   // ✅ 新增
+          lineHeight,
+          paddingTop,
+          paddingRight,
+          paddingBottom,
+          paddingLeft,
         };
       },
     },
@@ -153,7 +166,11 @@ const listItem: NodeSpec = {
       marginBottom,
       marginLeft,
       marginRight,
-      lineHeight,   // ✅ 新增
+      lineHeight,
+      paddingTop,
+      paddingRight,
+      paddingBottom,
+      paddingLeft,
     } = node.attrs;
 
     let style = '';
@@ -161,26 +178,19 @@ const listItem: NodeSpec = {
     if (align) {
       style += `text-align: ${align}; text-align-last: ${align};`;
     }
-    // 🔧 原写法 text-indent: (100% - ${textIndent}); 为非法 CSS,建议改为:
     if (textIndent) {
-      style += `text-indent: ${textIndent};`;   // 假设 textIndent 已是合法 CSS 值(如 "2em")
-    }
-    if (marginTop) {
-      style += `margin-top: ${marginTop};`;
-    }
-    if (marginBottom) {
-      style += `margin-bottom: ${marginBottom};`;
-    }
-    if (marginLeft) {
-      style += `margin-left: ${marginLeft};`;
-    }
-    if (marginRight) {
-      style += `margin-right: ${marginRight};`;
-    }
-    // ✅ 新增 line-height 输出
-    if (lineHeight) {
-      style += `line-height: ${lineHeight};`;
+      style += `text-indent: ${textIndent};`;
     }
+    if (marginTop) style += `margin-top: ${marginTop};`;
+    if (marginBottom) style += `margin-bottom: ${marginBottom};`;
+    if (marginLeft) style += `margin-left: ${marginLeft};`;
+    if (marginRight) style += `margin-right: ${marginRight};`;
+    if (lineHeight) style += `line-height: ${lineHeight};`;
+    // ✅ 输出 padding
+    if (paddingTop) style += `padding-top: ${paddingTop};`;
+    if (paddingRight) style += `padding-right: ${paddingRight};`;
+    if (paddingBottom) style += `padding-bottom: ${paddingBottom};`;
+    if (paddingLeft) style += `padding-left: ${paddingLeft};`;
 
     const attrs: { style?: string } = {};
     if (style) attrs.style = style;
@@ -188,16 +198,22 @@ const listItem: NodeSpec = {
     return ['li', attrs, 0];
   },
 };
+
 const paragraph: NodeSpec = {
   attrs: {
     align: { default: '' },
     indent: { default: 0 },
-    textIndent: { default: 0 },     // 注意:这里原定义为数字,但 parse 中存的是字符串,需统一
+    textIndent: { default: 0 },
     marginTop: { default: '' },
     marginBottom: { default: '' },
     marginLeft: { default: '' },
     marginRight: { default: '' },
-    lineHeight: { default: '' },     // ✅ 新增
+    lineHeight: { default: '' },
+    // ✅ 新增 padding 属性
+    paddingTop: { default: '' },
+    paddingRight: { default: '' },
+    paddingBottom: { default: '' },
+    paddingLeft: { default: '' },
   },
   content: 'inline*',
   group: 'block',
@@ -216,8 +232,13 @@ const paragraph: NodeSpec = {
         const marginBottom = style.marginBottom || '';
         const marginLeft = style.marginLeft || '';
         const marginRight = style.marginRight || '';
-        const textIndent = style.textIndent || '';   // 此处存为字符串,但与 attrs 定义的默认类型不一致,建议统一改为字符串默认 ''
-        const lineHeight = style.lineHeight || '';    // ✅ 新增
+        const textIndent = style.textIndent || '';
+        const lineHeight = style.lineHeight || '';
+        // ✅ 读取 padding
+        const paddingTop = style.paddingTop || '';
+        const paddingRight = style.paddingRight || '';
+        const paddingBottom = style.paddingBottom || '';
+        const paddingLeft = style.paddingLeft || '';
 
         return {
           align,
@@ -226,7 +247,11 @@ const paragraph: NodeSpec = {
           marginBottom,
           marginLeft,
           marginRight,
-          lineHeight,   // ✅ 新增
+          lineHeight,
+          paddingTop,
+          paddingRight,
+          paddingBottom,
+          paddingLeft,
         };
       },
     },
@@ -247,7 +272,11 @@ const paragraph: NodeSpec = {
       marginBottom,
       marginLeft,
       marginRight,
-      lineHeight,   // ✅ 新增
+      lineHeight,
+      paddingTop,
+      paddingRight,
+      paddingBottom,
+      paddingLeft,
     } = node.attrs;
 
     let style = '';
@@ -255,28 +284,36 @@ const paragraph: NodeSpec = {
     if (align && align !== 'left') {
       style += `text-align: ${align};text-align-last: ${align};`;
     }
-
     if (textIndent) {
-      // 🔧 修复非法 CSS 语法
       style += `text-indent: ${textIndent};`;
     }
-
     if (marginTop) style += `margin-top: ${marginTop};`;
     if (marginBottom) style += `margin-bottom: ${marginBottom};`;
     if (marginLeft) style += `margin-left: ${marginLeft};`;
     if (marginRight) style += `margin-right: ${marginRight};`;
-
-    // ✅ 新增 line-height 输出
-    if (lineHeight) {
-      style += `line-height: ${lineHeight};`;
-    }
+    if (lineHeight) style += `line-height: ${lineHeight};`;
+    // ✅ 输出 padding
+    if (paddingTop) style += `padding-top: ${paddingTop};`;
+    if (paddingRight) style += `padding-right: ${paddingRight};`;
+    if (paddingBottom) style += `padding-bottom: ${paddingBottom};`;
+    if (paddingLeft) style += `padding-left: ${paddingLeft};`;
 
     const attr: Attr = { style };
-
     return ['p', attr, 0];
   },
 };
 
+const hardBreak: NodeSpec = {
+  inline: true,       // 内联节点
+  group: 'inline',    // 属于 inline 组
+  selectable: false,  // 不可被光标单独选中
+  parseDOM: [{ tag: 'br' }],
+  toDOM() {
+    return ['br'];
+  },
+};
+
+
 const {
   doc,
   blockquote,
@@ -291,4 +328,5 @@ export default {
   'ordered_list': orderedList,
   'bullet_list': bulletList,
   'list_item': listItem,
+  hard_break: hardBreak,  // 新增
 }