Class: Inkpen::Extensions::Table

Inherits:
Base
  • Object
show all
Defined in:
lib/inkpen/extensions/table.rb

Overview

Table extension for TipTap.

Enables table functionality including headers, cells, row/column operations, and cell merging. Uses ProseMirror’s table system under the hood.

Examples:

Basic usage

extension = Inkpen::Extensions::Table.new

With custom options

extension = Inkpen::Extensions::Table.new(
  resizable: true,
  header_row: true,
  cell_min_width: 100
)

See Also:

Author:

  • Inkpen Team

Since:

  • 0.2.0

Constant Summary collapse

DEFAULT_CELL_MIN_WIDTH =

Default minimum cell width in pixels.

Since:

  • 0.2.0

25
DEFAULT_CELL_MAX_WIDTH =

Default maximum cell width in pixels.

Since:

  • 0.2.0

500

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

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_merge?Boolean

Whether to allow cell merging.

Returns:

  • (Boolean)

    true to enable cell merging

Since:

  • 0.2.0



112
113
114
# File 'lib/inkpen/extensions/table.rb', line 112

def allow_merge?
  options.fetch(:allow_merge, true)
end

#cell_backgrounds?Boolean

Whether to allow cell background colors.

Returns:

  • (Boolean)

    true to enable cell backgrounds

Since:

  • 0.2.0



103
104
105
# File 'lib/inkpen/extensions/table.rb', line 103

def cell_backgrounds?
  options.fetch(:cell_backgrounds, true)
end

#cell_max_widthInteger?

Maximum cell width in pixels (optional).

Returns:

  • (Integer, nil)

    maximum width or nil for unlimited

Since:

  • 0.2.0



85
86
87
# File 'lib/inkpen/extensions/table.rb', line 85

def cell_max_width
  options[:cell_max_width]
end

#cell_min_widthInteger

Minimum cell width in pixels.

Returns:

  • (Integer)

    minimum width

Since:

  • 0.2.0



76
77
78
# File 'lib/inkpen/extensions/table.rb', line 76

def cell_min_width
  options.fetch(:cell_min_width, DEFAULT_CELL_MIN_WIDTH)
end

#default_colsInteger

Default number of columns when inserting a new table.

Returns:

  • (Integer)

    default column count

Since:

  • 0.2.0



130
131
132
# File 'lib/inkpen/extensions/table.rb', line 130

def default_cols
  options.fetch(:default_cols, 3)
end

#default_rowsInteger

Default number of rows when inserting a new table.

Returns:

  • (Integer)

    default row count

Since:

  • 0.2.0



121
122
123
# File 'lib/inkpen/extensions/table.rb', line 121

def default_rows
  options.fetch(:default_rows, 3)
end

#header_column?Boolean

Whether the first column is treated as a header column.

Returns:

  • (Boolean)

    true if first column is header

Since:

  • 0.2.0



67
68
69
# File 'lib/inkpen/extensions/table.rb', line 67

def header_column?
  options.fetch(:header_column, false)
end

#header_row?Boolean

Whether the first row is treated as a header row.

Returns:

  • (Boolean)

    true if first row is header

Since:

  • 0.2.0



58
59
60
# File 'lib/inkpen/extensions/table.rb', line 58

def header_row?
  options.fetch(:header_row, true)
end

#nameSymbol

The unique name of this extension.

Returns:

  • (Symbol)

    :table

Since:

  • 0.2.0



40
41
42
# File 'lib/inkpen/extensions/table.rb', line 40

def name
  :table
end

#resizable?Boolean

Whether table columns can be resized.

Returns:

  • (Boolean)

    true to enable column resizing

Since:

  • 0.2.0



49
50
51
# File 'lib/inkpen/extensions/table.rb', line 49

def resizable?
  options.fetch(:resizable, true)
end

#to_configHash

Convert to configuration hash for JavaScript.

Returns:

  • (Hash)

    configuration for the TipTap extension

Since:

  • 0.2.0



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/inkpen/extensions/table.rb', line 148

def to_config
  {
    resizable: resizable?,
    headerRow: header_row?,
    headerColumn: header_column?,
    cellMinWidth: cell_min_width,
    cellMaxWidth: cell_max_width,
    toolbar: toolbar?,
    cellBackgrounds: cell_backgrounds?,
    allowMerge: allow_merge?,
    defaultRows: default_rows,
    defaultCols: default_cols,
    withHeaderRow: with_header_row?
  }.compact
end

#toolbar?Boolean

Whether to show the table toolbar.

Returns:

  • (Boolean)

    true to show toolbar

Since:

  • 0.2.0



94
95
96
# File 'lib/inkpen/extensions/table.rb', line 94

def toolbar?
  options.fetch(:toolbar, true)
end

#with_header_row?Boolean

Whether to include headers when inserting a new table.

Returns:

  • (Boolean)

    true to include header row

Since:

  • 0.2.0



139
140
141
# File 'lib/inkpen/extensions/table.rb', line 139

def with_header_row?
  options.fetch(:with_header_row, true)
end