1+ // @ts -check
12import { Node , Attribute } from '@core/index.js' ;
23
4+ /**
5+ * Heading attributes
6+ * @typedef {Object } HeadingAttributes
7+ * @property {number } level - Heading level (1-6)
8+ */
9+
10+ /**
11+ * @module Heading
12+ * @sidebarTitle Heading
13+ * @snippetPath /snippets/extensions/heading.mdx
14+ * @shortcut Mod-Alt-1 | toggleHeading | Toggle heading level 1
15+ * @shortcut Mod-Alt-2 | toggleHeading | Toggle heading level 2
16+ * @shortcut Mod-Alt-3 | toggleHeading | Toggle heading level 3
17+ * @shortcut Mod-Alt-4 | toggleHeading | Toggle heading level 4
18+ * @shortcut Mod-Alt-5 | toggleHeading | Toggle heading level 5
19+ * @shortcut Mod-Alt-6 | toggleHeading | Toggle heading level 6
20+ */
321export const Heading = Node . create ( {
422 name : 'heading' ,
523
@@ -11,6 +29,12 @@ export const Heading = Node.create({
1129
1230 addOptions ( ) {
1331 return {
32+ /**
33+ * @typedef {Object } HeadingOptions
34+ * @category Options
35+ * @property {number[] } [levels=[1,2,3,4,5,6]] - Supported heading levels
36+ * @property {Object } [htmlAttributes] - HTML attributes for heading elements
37+ */
1438 levels : [ 1 , 2 , 3 , 4 , 5 , 6 ] ,
1539 htmlAttributes : {
1640 'aria-label' : 'Heading node' ,
@@ -20,11 +44,27 @@ export const Heading = Node.create({
2044
2145 addAttributes ( ) {
2246 return {
47+ /**
48+ * @category Attribute
49+ * @param {number } [level=1] - Heading level from 1 (largest) to 6 (smallest)
50+ */
2351 level : {
2452 default : 1 ,
2553 rendered : false ,
2654 } ,
55+
56+ /**
57+ * @private
58+ * @category Attribute
59+ * @param {Object } [tabStops] - Internal tab stop configuration
60+ */
2761 tabStops : { rendered : false } ,
62+
63+ /**
64+ * @private
65+ * @category Attribute
66+ * @param {string } [sdBlockId] - Internal block tracking ID
67+ */
2868 sdBlockId : {
2969 default : null ,
3070 keepOnSplit : false ,
@@ -51,13 +91,37 @@ export const Heading = Node.create({
5191
5292 addCommands ( ) {
5393 return {
94+ /**
95+ * Set a heading with specified level
96+ * @category Command
97+ * @param {HeadingAttributes } attributes - Heading attributes including level
98+ * @returns {Function } Command function
99+ * @example
100+ * // Set heading level 2
101+ * setHeading({ level: 2 })
102+ * @note Converts current block to heading
103+ */
54104 setHeading :
55105 ( attributes ) =>
56106 ( { commands } ) => {
57107 const containsLevel = this . options . levels . includes ( attributes . level ) ;
58108 if ( ! containsLevel ) return false ;
59109 return commands . setNode ( this . name , attributes ) ;
60110 } ,
111+
112+ /**
113+ * Toggle between heading and paragraph
114+ * @category Command
115+ * @param {HeadingAttributes } attributes - Heading attributes including level
116+ * @returns {Function } Command function
117+ * @example
118+ * // Toggle heading level 1
119+ * toggleHeading({ level: 1 })
120+ *
121+ * // Toggle heading level 3
122+ * toggleHeading({ level: 3 })
123+ * @note Switches between heading and paragraph for the same level
124+ */
61125 toggleHeading :
62126 ( attributes ) =>
63127 ( { commands } ) => {
0 commit comments