From 6e696ea52ffbec6475cc0f759e4ff3916dace49c Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 7 Mar 2024 12:47:04 +0100 Subject: [PATCH] doc(Preview): jsdoc fixes and better function names Signed-off-by: Max --- src/nodes/Preview.js | 49 +++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/src/nodes/Preview.js b/src/nodes/Preview.js index b993ffc6079..412705f34cc 100644 --- a/src/nodes/Preview.js +++ b/src/nodes/Preview.js @@ -93,13 +93,12 @@ export default Node.create({ }, /** - * Turn a preview back into a paragraph - * that contains a single link. + * Turn a preview back into a paragraph with a link. * */ unsetPreview: () => ({ state, chain }) => { console.info(this.attributes) - return isPreview(this.name, this.attributes, state) + return isActive(this.name, this.attributes, state) && chain() .setNode('paragraph') .run() @@ -110,9 +109,11 @@ export default Node.create({ }) /** + * Attributes for a preview from link in the current selection * - * @param root0 - * @param root0.selection + * @param {object} state the edior state + * @param {object} state.selection current selection + * @return {object} */ function previewAttributesFromSelection({ selection }) { const { $from } = selection @@ -121,20 +122,22 @@ function previewAttributesFromSelection({ selection }) { } /** - * - * @param typeOrName - * @param attributes - * @param state + * Is the active node one of typeOrName with the given attributes + * @param {object|string} typeOrName type or name of the preview node type + * @param {object} attributes attributes of the node + * @param {object} state current editor state + * @return {boolean} */ -function isPreview(typeOrName, attributes, state) { +function isActive(typeOrName, attributes, state) { const type = getNodeType(typeOrName, state.schema) return isNodeActive(state, type, attributes) } /** - * - * @param root0 - * @param root0.selection + * Is it possible to convert the currently selected node into a preview? + * @param {object} state current editor state + * @param {object} state.selection current selection + * @return {boolean} */ function previewPossible({ selection }) { const { $from } = selection @@ -150,26 +153,20 @@ function previewPossible({ selection }) { /** * Does the node contain more content than the first child - * @param node - node to inspect + * @param {object} node node to inspect + * @return {boolean} */ function hasOtherContent(node) { - return childCount(node) > 2 - || (childCount(node) === 2 && node.lastChild.textContent.trim()) + return node.childCount > 2 + || (node.childCount === 2 && node.lastChild.textContent.trim()) } /** - * - * @param node + * Get the link href of the given node + * @param {object} node to inspect + * @return {string} The href of the link mark of the node */ function extractHref(node) { const link = node.marks.find(mark => mark.type.name === 'link') return link?.attrs.href } - -/** - * - * @param node - */ -function childCount(node) { - return node.content.content.length -}