Class: Inkpen::Extensions::DocumentSection
- Defined in:
- lib/inkpen/extensions/document_section.rb
Overview
DocumentSection extension for TipTap.
Provides true content grouping with a semantic H2 title and collapsible content. Unlike the layout Section extension (which controls width/spacing), DocumentSection groups related blocks under a heading for document structure.
Features:
-
Semantic H2 title (integrates with Table of Contents)
-
Collapsible content with left-gutter toggle
-
Nesting support (sections within sections, up to 3 levels)
-
Draggable as a group
-
Auto-generated IDs for deep linking
Constant Summary collapse
- DEFAULT_MAX_DEPTH =
Default maximum nesting depth for sections.
3
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#allow_nesting? ⇒ Boolean
Whether sections can be nested within each other.
-
#default_collapsed ⇒ Boolean
Default collapsed state for new sections.
-
#max_depth ⇒ Integer
Maximum nesting depth for sections.
-
#name ⇒ Symbol
The unique name of this extension.
-
#show_controls? ⇒ Boolean
Whether to show the collapse toggle control.
-
#to_config ⇒ Hash
Convert to configuration hash for JavaScript.
Methods inherited from Base
#enabled?, #initialize, #to_h, #to_json
Constructor Details
This class inherits a constructor from Inkpen::Extensions::Base
Instance Method Details
#allow_nesting? ⇒ Boolean
Whether sections can be nested within each other.
62 63 64 |
# File 'lib/inkpen/extensions/document_section.rb', line 62 def allow_nesting? .fetch(:allow_nesting, true) end |
#default_collapsed ⇒ Boolean
Default collapsed state for new sections.
53 54 55 |
# File 'lib/inkpen/extensions/document_section.rb', line 53 def default_collapsed .fetch(:default_collapsed, false) end |
#max_depth ⇒ Integer
Maximum nesting depth for sections.
71 72 73 74 |
# File 'lib/inkpen/extensions/document_section.rb', line 71 def max_depth depth = .fetch(:max_depth, DEFAULT_MAX_DEPTH) [[depth, 1].max, 3].min # Clamp between 1 and 3 end |
#name ⇒ Symbol
The unique name of this extension.
44 45 46 |
# File 'lib/inkpen/extensions/document_section.rb', line 44 def name :document_section end |
#show_controls? ⇒ Boolean
Whether to show the collapse toggle control.
81 82 83 |
# File 'lib/inkpen/extensions/document_section.rb', line 81 def show_controls? .fetch(:show_controls, true) end |
#to_config ⇒ Hash
Convert to configuration hash for JavaScript.
90 91 92 93 94 95 96 97 |
# File 'lib/inkpen/extensions/document_section.rb', line 90 def to_config { defaultCollapsed: default_collapsed, allowNesting: allow_nesting?, maxDepth: max_depth, showControls: show_controls? } end |