Skip to content

Commit

Permalink
doc(Preview): jsdoc fixes and better function names
Browse files Browse the repository at this point in the history
Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Mar 7, 2024
1 parent 81ec438 commit 6e696ea
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions src/nodes/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
}

0 comments on commit 6e696ea

Please sign in to comment.