@bangle.dev/core
Advanced tools
Comparing version 0.2.0 to 0.2.1
11
api.md
@@ -582,6 +582,10 @@ --- | ||
The heading component also allows you to collapse and uncollapse any content, after the current heading, that is not of type heading or has a heading of level greater than the current heading. A collapsed heading will have a class name of `bangle-heading-collapsed` to allow for styling. A collapsed heading will save the collapsed data in a JSON string under the dom attribute `data-bangle-attrs`. | ||
The heading component also allows you to collapse and uncollapse any content, after the current heading, that is not of type heading or has a heading of level greater than the current heading. | ||
:warning: For serializing to Markdown you will have to uncollapse your document, since markdown doesn't support collapsing. You can run the command`uncollapseAllHeadings` before serializing to markdown to avoid this problem. | ||
:bulb: The collapsed data is saved in the node attribute `collapseContent`, it is also accessible inside the DOM data attribute by accessing `data-bangle-attrs`. | ||
:bulb: A collapsed heading will have a class name of `bangle-heading-collapsed` to allow for styling. | ||
:warning: For serializing to Markdown you will have to uncollapse your document, since markdown doesn't support collapsing. You should run the command`uncollapseAllHeadings` before serializing to markdown. | ||
On top of the collapse commands, the component also exports the following helper functions to help with collapse functionality: | ||
@@ -595,2 +599,5 @@ | ||
- **flattenFragmentJSON**(fragmentJSON: Object): Object\ | ||
Deep flattens any nested collapsed heading in the object. Bangle internally uses this to implement `uncollapseAllHeadings` command. Example `flattenFragmentJSON(node.attrs.collapseContent)`. | ||
**Usage** | ||
@@ -597,0 +604,0 @@ |
@@ -316,23 +316,2 @@ import { setBlockType } from 'prosemirror-commands'; | ||
export function uncollapseAllHeadings() { | ||
const flattenFragmentJSON = (fragJSON) => { | ||
let result = []; | ||
fragJSON.forEach((nodeJSON) => { | ||
if (nodeJSON.type === 'heading' && nodeJSON.attrs.collapseContent) { | ||
const collapseContent = nodeJSON.attrs.collapseContent; | ||
result.push({ | ||
...nodeJSON, | ||
attrs: { | ||
...nodeJSON.attrs, | ||
collapseContent: null, | ||
}, | ||
}); | ||
result.push(...flattenFragmentJSON(collapseContent)); | ||
} else { | ||
result.push(nodeJSON); | ||
} | ||
}); | ||
return result; | ||
}; | ||
return (state, dispatch) => { | ||
@@ -397,2 +376,23 @@ const collapsibleNodes = listCollapsedHeading(state); | ||
export const flattenFragmentJSON = (fragJSON) => { | ||
let result = []; | ||
fragJSON.forEach((nodeJSON) => { | ||
if (nodeJSON.type === 'heading' && nodeJSON.attrs.collapseContent) { | ||
const collapseContent = nodeJSON.attrs.collapseContent; | ||
result.push({ | ||
...nodeJSON, | ||
attrs: { | ||
...nodeJSON.attrs, | ||
collapseContent: null, | ||
}, | ||
}); | ||
result.push(...flattenFragmentJSON(collapseContent)); | ||
} else { | ||
result.push(nodeJSON); | ||
} | ||
}); | ||
return result; | ||
}; | ||
// TODO | ||
@@ -399,0 +399,0 @@ /** |
{ | ||
"name": "@bangle.dev/core", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"homepage": "https://bangle.dev", | ||
@@ -5,0 +5,0 @@ "authors": [ |
489870