Skip to content

Commit c591032

Browse files
authored
chore: add constants in node view, lint and format (#772)
1 parent d1c9d26 commit c591032

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

packages/super-editor/src/core/super-converter/v2/importer/runNodeImporter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const handleRunNode = (params) => {
1717
const defaultNodeStyles = getMarksFromStyles(docx, parentStyleId);
1818

1919
if (hasRunProperties) {
20-
const { marks = [], attributes = {} } = parseProperties(node);
20+
const { marks = [] } = parseProperties(node);
2121

2222
/* Store run style attributes in an array, then store the defaultNodeStyles (parent styles) in a second array
2323
Then combine the two arrays and create a new array of marks, where the

packages/super-editor/src/extensions/list-item/ListItemNodeView.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { docxNumberigHelpers } from '@/core/super-converter/v2/importer/listImpo
99
const MARKER_PADDING = 6;
1010
const MARKER_OFFSET_RIGHT = 4;
1111
const MIN_MARKER_WIDTH = 20;
12+
const POINT_TO_PIXEL_CONVERSION_FACTOR = 1.33;
13+
const DEFAULT_FONT_FAMILY = 'Arial, sans-serif';
14+
const DEFAULT_FONT_SIZE = '10pt';
1215

1316
const IS_DEBUGGING = false;
1417

@@ -338,26 +341,36 @@ export const getVisibleIndent = (stylePpr, numDefPpr, inlineIndent) => {
338341
return result;
339342
};
340343

344+
/**
345+
* Calculate the width of the list item marker.
346+
* @param {HTMLElement} dom - The DOM element of the list item.
347+
* @param {HTMLElement} numberingDOM - The DOM element of the numbering.
348+
* @param {Object} param2 - Additional parameters.
349+
* @param {boolean} param2.withPadding - Whether to include padding in the calculation.
350+
* @returns {number} The width of the marker.
351+
*/
341352
function calculateMarkerWidth(dom, numberingDOM, { withPadding = true } = {}) {
342353
const markerText = numberingDOM.textContent || '';
343-
const fontSize = dom.style.fontSize || '10pt';
354+
const fontSize = dom.style.fontSize || DEFAULT_FONT_SIZE;
344355
const fontValue = dom.style.fontFamily;
345-
const fontFamily = fontValue && fontValue !== 'inherit' ? fontValue : 'Arial';
356+
const fontFamily = fontValue && fontValue !== 'inherit' ? fontValue : DEFAULT_FONT_FAMILY;
346357

347358
if (!markerText.trim()) return 0;
348359

349360
try {
350361
const canvas = document.createElement('canvas');
351362
const context = canvas.getContext('2d');
352363

353-
const fontSizePx = fontSize.includes('pt') ? Number.parseFloat(fontSize) * 1.33 : Number.parseFloat(fontSize);
364+
const fontSizePx = fontSize.includes('pt')
365+
? Number.parseFloat(fontSize) * POINT_TO_PIXEL_CONVERSION_FACTOR
366+
: Number.parseFloat(fontSize);
354367

355368
context.font = `${fontSizePx}px ${fontFamily}`;
356369

357370
const textWidth = context.measureText(markerText).width;
358371
const resultWidth = withPadding ? Math.ceil(textWidth + MARKER_PADDING) : Math.ceil(textWidth);
359372
return resultWidth;
360-
} catch (err) {
373+
} catch {
361374
return 0;
362375
}
363376
}

0 commit comments

Comments
 (0)