1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 05:47:05 +09:00

DROID-384 Editor | Enhancement | Simple table, add row and column actions, part 1 (#2712)

* DROID-384 row and column models added to table view

* DROID-384 fix tests

* DROID-384 fix tests after refactoring

* DROID-384 editor table delegate added

* DROID-384 cell diff util

* DROID-384 table diff util

* DROID-384 column, row models refactoring

* DROID-384 cells extension refactoring

* DROID-384 table widget items

* DROID-384 get column and row tabs items

* DROID-384 tests

* DROID-384 create table column use case

* DROID-384 code style + ci

* DROID-384 ci off

* DROID-384 kdoc

Co-authored-by: konstantiniiv <ki@anytype.io>
This commit is contained in:
Konstantin Ivanov 2022-11-23 12:03:04 +01:00 committed by GitHub
parent 779ecb47d5
commit 3d1bbb73da
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 1691 additions and 569 deletions

View file

@ -92,6 +92,7 @@ import com.anytypeio.anytype.presentation.editor.editor.InternalDetailModificati
import com.anytypeio.anytype.presentation.editor.editor.Orchestrator
import com.anytypeio.anytype.presentation.editor.editor.Proxy
import com.anytypeio.anytype.presentation.editor.editor.pattern.DefaultPatternMatcher
import com.anytypeio.anytype.presentation.editor.editor.table.EditorTableDelegate
import com.anytypeio.anytype.presentation.editor.render.DefaultBlockViewRenderer
import com.anytypeio.anytype.presentation.editor.selection.SelectionStateHolder
import com.anytypeio.anytype.presentation.editor.template.DefaultEditorTemplateDelegate
@ -250,6 +251,9 @@ open class EditorTestSetup {
@Mock
lateinit var fillTableRow: FillTableRow
@Mock
lateinit var tableDelegate: EditorTableDelegate
val root: String = "rootId123"
private val urlBuilder by lazy {
@ -339,6 +343,7 @@ open class EditorTestSetup {
featureToggles = DefaultFeatureToggles()
TestEditorFragment.testViewModelFactory = EditorViewModelFactory(
openPage = openPage,
closeObject = closePage,
@ -420,7 +425,8 @@ open class EditorTestSetup {
editorTemplateDelegate = editorTemplateDelegate,
createNewObject = createNewObject,
objectToSet = objectToSet,
featureToggles = featureToggles
featureToggles = featureToggles,
tableDelegate = tableDelegate
)
}

View file

@ -80,6 +80,7 @@ import com.anytypeio.anytype.domain.sets.FindObjectSetForType
import com.anytypeio.anytype.domain.status.InterceptThreadStatus
import com.anytypeio.anytype.domain.status.ThreadStatusChannel
import com.anytypeio.anytype.domain.table.CreateTable
import com.anytypeio.anytype.domain.table.CreateTableColumn
import com.anytypeio.anytype.domain.table.FillTableRow
import com.anytypeio.anytype.domain.templates.ApplyTemplate
import com.anytypeio.anytype.domain.templates.GetTemplates
@ -96,6 +97,8 @@ import com.anytypeio.anytype.presentation.editor.editor.Interactor
import com.anytypeio.anytype.presentation.editor.editor.InternalDetailModificationManager
import com.anytypeio.anytype.presentation.editor.editor.Orchestrator
import com.anytypeio.anytype.presentation.editor.editor.pattern.DefaultPatternMatcher
import com.anytypeio.anytype.presentation.editor.editor.table.DefaultEditorTableDelegate
import com.anytypeio.anytype.presentation.editor.editor.table.EditorTableDelegate
import com.anytypeio.anytype.presentation.editor.render.DefaultBlockViewRenderer
import com.anytypeio.anytype.presentation.editor.selection.SelectionStateHolder
import com.anytypeio.anytype.presentation.editor.template.DefaultEditorTemplateDelegate
@ -226,7 +229,8 @@ object EditorSessionModule {
editorTemplateDelegate: EditorTemplateDelegate,
createNewObject: CreateNewObject,
objectToSet: ConvertObjectToSet,
featureToggles: FeatureToggles
featureToggles: FeatureToggles,
tableDelegate: EditorTableDelegate
): EditorViewModelFactory = EditorViewModelFactory(
openPage = openPage,
closeObject = closePage,
@ -259,7 +263,8 @@ object EditorSessionModule {
editorTemplateDelegate = editorTemplateDelegate,
createNewObject = createNewObject,
objectToSet = objectToSet,
featureToggles = featureToggles
featureToggles = featureToggles,
tableDelegate = tableDelegate
)
@JvmStatic
@ -286,6 +291,17 @@ object EditorSessionModule {
applyTemplate = applyTemplate
)
@JvmStatic
@Provides
@PerScreen
fun provideTableDelegate(
dispatcher: Dispatcher<Payload>,
createTableColumn: CreateTableColumn
): EditorTableDelegate = DefaultEditorTableDelegate(
dispatcher = dispatcher,
createTableColumn = createTableColumn
)
@JvmStatic
@Provides
fun provideDefaultBlockViewRenderer(
@ -1013,6 +1029,13 @@ object EditorUseCaseModule {
repo: BlockRepository
): ClearBlockStyle = ClearBlockStyle(repo)
@JvmStatic
@Provides
@PerScreen
fun provideBlockTableCreateColumn(
repo: BlockRepository
): CreateTableColumn = CreateTableColumn(repo)
@Module
interface Bindings {

View file

@ -245,8 +245,8 @@ class BlockViewDiffUtil(
}
if (newBlock is BlockView.Table && oldBlock is BlockView.Table) {
if (newBlock.rows.size != oldBlock.rows.size) {
changes.add(TABLE_ROW_COUNT_CHANGED)
if (newBlock.columns != oldBlock.columns || newBlock.rows != oldBlock.rows) {
return super.getChangePayload(oldItemPosition, newItemPosition)
}
if (newBlock.cells != oldBlock.cells) {
changes.add(TABLE_CELLS_CHANGED)
@ -319,7 +319,6 @@ class BlockViewDiffUtil(
fun tableCellsSelectionChanged() = changes.contains(TABLE_CELLS_SELECTION_CHANGED)
fun tableCellsChanged() = changes.contains(TABLE_CELLS_CHANGED)
fun tableRowCountChanged() = changes.contains(TABLE_ROW_COUNT_CHANGED)
}
companion object {
@ -357,6 +356,5 @@ class BlockViewDiffUtil(
const val TABLE_CELLS_SELECTION_CHANGED = 340
const val TABLE_CELLS_CHANGED = 341
const val TABLE_ROW_COUNT_CHANGED = 342
}
}

View file

@ -17,7 +17,7 @@ class TableCellsDiffUtil(
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
val newItem = new[newItemPosition]
val oldItem = old[oldItemPosition]
return newItem.rowId == oldItem.rowId && newItem.columnId == oldItem.columnId
return newItem.getId() == oldItem.getId()
}
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {

View file

@ -47,7 +47,7 @@ class EditableCellHolder(
fun bindEmptyCell() {
if (root.background != null) root.background = null
if (content.text != null) content.text = null
content.enableReadMode()
if (content.isTextSelectable) content.enableReadMode()
}
fun cellSelection(isSelected: Boolean) {

View file

@ -75,9 +75,9 @@ class TableBlockHolder(
}
fun bind(item: BlockView.Table) {
applyRowCount(item)
applySelection(item)
applyBackground(item)
applyRowCount(item)
applyCells(item)
updateCellsSelection(item)
}
@ -89,7 +89,6 @@ class TableBlockHolder(
payloads.forEach { payload ->
if (payload.selectionChanged()) applySelection(item)
if (payload.backgroundColorChanged()) applyBackground(item)
if (payload.tableRowCountChanged()) applyRowCount(item)
if (payload.tableCellsChanged()) applyCells(item)
if (payload.tableCellsSelectionChanged()) updateCellsSelection(item)
}

View file

@ -10,8 +10,7 @@ import com.anytypeio.anytype.presentation.editor.editor.table.SimpleTableWidgetI
class SimpleTableWidgetAdapter(
private var items: List<SimpleTableWidgetItem>,
private val onClick: (SimpleTableWidgetItem) -> Unit
) :
RecyclerView.Adapter<SimpleTableWidgetAdapter.VH>() {
) : RecyclerView.Adapter<SimpleTableWidgetAdapter.VH>() {
fun update(items: List<SimpleTableWidgetItem>) {
this.items = items
@ -25,8 +24,7 @@ class SimpleTableWidgetAdapter(
).apply {
itemView.setOnClickListener {
val pos = bindingAdapterPosition
if (pos != RecyclerView.NO_POSITION)
onClick(items[pos])
if (pos != RecyclerView.NO_POSITION) onClick(items[pos])
}
}
return holder
@ -38,8 +36,7 @@ class SimpleTableWidgetAdapter(
override fun getItemCount(): Int = items.size
class VH(binding: ItemSimpleTableActionBinding) :
RecyclerView.ViewHolder(binding.root) {
class VH(binding: ItemSimpleTableActionBinding) : RecyclerView.ViewHolder(binding.root) {
val icon = binding.icon
val title = binding.title
@ -47,75 +44,83 @@ class SimpleTableWidgetAdapter(
fun bind(item: SimpleTableWidgetItem) {
when (item) {
SimpleTableWidgetItem.Cell.ClearContents,
SimpleTableWidgetItem.Row.ClearContents,
SimpleTableWidgetItem.Column.ClearContents -> {
is SimpleTableWidgetItem.Row.ClearContents,
is SimpleTableWidgetItem.Column.ClearContents -> {
title.setText(R.string.simple_tables_widget_item_clear_contents)
icon.setImageResource(R.drawable.ic_clear_32)
}
SimpleTableWidgetItem.Cell.ClearStyle -> {
SimpleTableWidgetItem.Cell.ResetStyle,
is SimpleTableWidgetItem.Column.ResetStyle,
is SimpleTableWidgetItem.Row.ResetStyle -> {
title.setText(R.string.simple_tables_widget_item_clear_style)
icon.setImageResource(R.drawable.ic_reset_32)
}
SimpleTableWidgetItem.Cell.Color,
SimpleTableWidgetItem.Column.Color,
SimpleTableWidgetItem.Row.Color -> {
is SimpleTableWidgetItem.Column.Color,
is SimpleTableWidgetItem.Row.Color -> {
title.setText(R.string.simple_tables_widget_item_color)
icon.setImageResource(R.drawable.ic_color_32)
}
SimpleTableWidgetItem.Cell.Style,
SimpleTableWidgetItem.Row.Style,
SimpleTableWidgetItem.Column.Style -> {
is SimpleTableWidgetItem.Row.Style,
is SimpleTableWidgetItem.Column.Style -> {
title.setText(R.string.simple_tables_widget_item_style)
icon.setImageResource(R.drawable.ic_style_32)
}
SimpleTableWidgetItem.Column.Delete,
SimpleTableWidgetItem.Row.Delete -> {
is SimpleTableWidgetItem.Column.Delete,
is SimpleTableWidgetItem.Row.Delete -> {
title.setText(R.string.toolbar_action_delete)
icon.setImageResource(R.drawable.ic_block_action_delete)
}
SimpleTableWidgetItem.Column.Duplicate,
SimpleTableWidgetItem.Row.Duplicate -> {
is SimpleTableWidgetItem.Column.Duplicate,
is SimpleTableWidgetItem.Row.Duplicate -> {
title.setText(R.string.toolbar_action_duplicate)
icon.setImageResource(R.drawable.ic_block_action_duplicate)
}
SimpleTableWidgetItem.Column.InsertLeft -> {
is SimpleTableWidgetItem.Column.InsertLeft -> {
title.setText(R.string.simple_tables_widget_item_insert_left)
icon.setImageResource(R.drawable.ic_column_insert_left)
}
SimpleTableWidgetItem.Column.InsertRight -> {
is SimpleTableWidgetItem.Column.InsertRight -> {
title.setText(R.string.simple_tables_widget_item_insert_right)
icon.setImageResource(R.drawable.ic_column_insert_right)
}
SimpleTableWidgetItem.Column.MoveLeft -> {
is SimpleTableWidgetItem.Column.MoveLeft -> {
title.setText(R.string.simple_tables_widget_item_move_left)
icon.setImageResource(R.drawable.ic_move_column_left)
}
SimpleTableWidgetItem.Column.MoveRight -> {
is SimpleTableWidgetItem.Column.MoveRight -> {
title.setText(R.string.simple_tables_widget_item_move_right)
icon.setImageResource(R.drawable.ic_move_column_right)
}
SimpleTableWidgetItem.Column.Sort,
SimpleTableWidgetItem.Row.Sort -> {
title.setText(R.string.sort)
icon.setImageResource(R.drawable.ic_action_sort)
}
SimpleTableWidgetItem.Row.InsertAbove -> {
is SimpleTableWidgetItem.Row.InsertAbove -> {
title.setText(R.string.simple_tables_widget_item_insert_above)
icon.setImageResource(R.drawable.ic_add_row_above)
}
SimpleTableWidgetItem.Row.InsertBelow -> {
is SimpleTableWidgetItem.Row.InsertBelow -> {
title.setText(R.string.simple_tables_widget_item_insert_below)
icon.setImageResource(R.drawable.ic_add_row_below)
}
SimpleTableWidgetItem.Row.MoveDown -> {
is SimpleTableWidgetItem.Row.MoveDown -> {
title.setText(R.string.simple_tables_widget_item_move_down)
icon.setImageResource(R.drawable.ic_move_row_down)
}
SimpleTableWidgetItem.Row.MoveUp -> {
is SimpleTableWidgetItem.Row.MoveUp -> {
title.setText(R.string.simple_tables_widget_item_move_up)
icon.setImageResource(R.drawable.ic_move_row_up)
}
else -> Unit
is SimpleTableWidgetItem.Column.Copy,
is SimpleTableWidgetItem.Row.Copy -> {
title.setText(R.string.simple_tables_widget_item_copy)
icon.setImageResource(R.drawable.ic_copy_32)
}
is SimpleTableWidgetItem.Column.Sort -> {
title.setText(R.string.simple_tables_widget_item_sort)
icon.setImageResource(R.drawable.ic_action_32)
}
SimpleTableWidgetItem.Tab.Cell -> Unit
SimpleTableWidgetItem.Tab.Column -> Unit
SimpleTableWidgetItem.Tab.Row -> Unit
}
}
}

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="32"
android:viewportHeight="32">
<path
android:pathData="M17.5,5.5H8.5C6.843,5.5 5.5,6.843 5.5,8.5V17.5C5.5,19.157 6.843,20.5 8.5,20.5H10V14.5C10,12.015 12.015,10 14.5,10H20.5V8.5C20.5,6.843 19.157,5.5 17.5,5.5ZM22,10H23.5C25.985,10 28,12.015 28,14.5V23.5C28,25.985 25.985,28 23.5,28H14.5C12.015,28 10,25.985 10,23.5V22H8.5C6.015,22 4,19.985 4,17.5V8.5C4,6.015 6.015,4 8.5,4H17.5C19.985,4 22,6.015 22,8.5V10ZM14.5,11.5H23.5C25.157,11.5 26.5,12.843 26.5,14.5V23.5C26.5,25.157 25.157,26.5 23.5,26.5H14.5C12.843,26.5 11.5,25.157 11.5,23.5V14.5C11.5,12.843 12.843,11.5 14.5,11.5Z"
android:fillColor="@color/glyph_active"
android:fillType="evenOdd"/>
</vector>

View file

@ -550,6 +550,8 @@
<string name="simple_tables_widget_item_move_right">Move right</string>
<string name="simple_tables_widget_item_insert_above">Insert above</string>
<string name="simple_tables_widget_item_insert_below">Insert below</string>
<string name="simple_tables_widget_item_copy">Copy</string>
<string name="simple_tables_widget_item_sort">Sort</string>
<string name="simple_tables_widget_item_move_up">Move up</string>
<string name="simple_tables_widget_item_move_down">Move down</string>
<string name="simple_tables_widget_tab_cell">Cell</string>

View file

@ -1,6 +1,5 @@
package com.anytypeio.anytype.core_ui
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.RelationFormat
import com.anytypeio.anytype.core_models.ThemeColor
import com.anytypeio.anytype.core_ui.features.editor.BlockViewDiffUtil
@ -9,7 +8,6 @@ import com.anytypeio.anytype.core_ui.features.editor.BlockViewDiffUtil.Companion
import com.anytypeio.anytype.core_ui.features.editor.BlockViewDiffUtil.Companion.MARKUP_CHANGED
import com.anytypeio.anytype.core_ui.features.editor.BlockViewDiffUtil.Companion.TABLE_CELLS_CHANGED
import com.anytypeio.anytype.core_ui.features.editor.BlockViewDiffUtil.Companion.TABLE_CELLS_SELECTION_CHANGED
import com.anytypeio.anytype.core_ui.features.editor.BlockViewDiffUtil.Companion.TABLE_ROW_COUNT_CHANGED
import com.anytypeio.anytype.core_ui.features.editor.BlockViewDiffUtil.Companion.TEXT_CHANGED
import com.anytypeio.anytype.core_ui.features.editor.BlockViewDiffUtil.Payload
import com.anytypeio.anytype.presentation.editor.editor.Markup
@ -1747,7 +1745,7 @@ class BlockViewDiffUtilTest {
}
@Test
fun `when table block have different rows size - should be rows size and cells changed payloads`() {
fun `when table block have different row lists - should be nullable payload`() {
//SETUP
val tableId = MockDataFactory.randomUuid()
@ -1769,7 +1767,39 @@ class BlockViewDiffUtilTest {
val payload = diff.getChangePayload(0, 0)
//EXPECTED
val expectedPayloads = Payload(listOf(TABLE_ROW_COUNT_CHANGED, TABLE_CELLS_CHANGED))
val expectedPayloads = null
//ASSERT
assertEquals(
actual = payload,
expected = expectedPayloads
)
}
@Test
fun `when table block have different column lists - should be nullable payload`() {
//SETUP
val tableId = MockDataFactory.randomUuid()
val oldBlock = StubTableView(
tableId = tableId,
tab = BlockView.Table.Tab.CELL,
rowSize = 10,
columnSize = 10
)
val newBlock = StubTableView(
tableId = tableId,
tab = BlockView.Table.Tab.CELL,
rowSize = 10,
columnSize = 11
)
//TESTING
val diff = BlockViewDiffUtil(old = listOf(oldBlock), new = listOf(newBlock))
val payload = diff.getChangePayload(0, 0)
//EXPECTED
val expectedPayloads = null
//ASSERT
assertEquals(

View file

@ -1,7 +1,6 @@
package com.anytypeio.anytype.core_ui
import com.anytypeio.anytype.core_models.StubParagraph
import com.anytypeio.anytype.core_models.ThemeColor
import com.anytypeio.anytype.presentation.editor.editor.ext.clearSearchHighlights
import com.anytypeio.anytype.presentation.editor.editor.ext.highlight
import com.anytypeio.anytype.presentation.editor.editor.ext.nextSearchTarget
@ -1109,21 +1108,31 @@ class BlockViewSearchTextTest {
id = row1Block1.id,
text = row1Block1.content.asText().text
),
rowId = rowId1,
columnId = columnId1,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(0),
tableId = tableId
tableId = tableId,
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(0)
)
),
BlockView.Table.Cell(
block = BlockView.Text.Paragraph(
id = row1Block2.id,
text = row1Block2.content.asText().text
),
rowId = rowId1,
columnId = columnId2,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(1)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -1131,10 +1140,15 @@ class BlockViewSearchTextTest {
id = row1Block3.id,
text = row1Block3.content.asText().text
),
rowId = rowId1,
columnId = columnId3,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId3),
index = BlockView.Table.ColumnIndex(2)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -1142,10 +1156,15 @@ class BlockViewSearchTextTest {
id = row2Block1.id,
text = row2Block1.content.asText().text
),
rowId = rowId2,
columnId = columnId1,
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(0),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(0)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -1153,10 +1172,15 @@ class BlockViewSearchTextTest {
id = row2Block2.id,
text = row2Block2.content.asText().text
),
rowId = rowId2,
columnId = columnId2,
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(1)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -1164,23 +1188,45 @@ class BlockViewSearchTextTest {
id = row2Block3.id,
text = row2Block3.content.asText().text
),
rowId = rowId2,
columnId = columnId3,
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId3),
index = BlockView.Table.ColumnIndex(2)
),
tableId = tableId
)
)
val columns = listOf(
BlockView.Table.ColumnId(value = columnId1),
BlockView.Table.ColumnId(value = columnId2),
BlockView.Table.ColumnId(value = columnId3),
BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(0)
),
BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(1)
),
BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId3),
index = BlockView.Table.ColumnIndex(2)
)
)
val rows = listOf(
BlockView.Table.RowId(value = rowId1),
BlockView.Table.RowId(value = rowId2)
BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
)
)
val views = listOf<BlockView>(
@ -1207,10 +1253,15 @@ class BlockViewSearchTextTest {
)
)
),
rowId = rowId1,
columnId = columnId1,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(0),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(0)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -1225,10 +1276,15 @@ class BlockViewSearchTextTest {
)
)
),
rowId = rowId1,
columnId = columnId2,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(1)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -1243,10 +1299,15 @@ class BlockViewSearchTextTest {
)
)
),
rowId = rowId1,
columnId = columnId3,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId3),
index = BlockView.Table.ColumnIndex(2)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -1261,10 +1322,15 @@ class BlockViewSearchTextTest {
)
)
),
rowId = rowId2,
columnId = columnId1,
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(0),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(0)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -1279,10 +1345,15 @@ class BlockViewSearchTextTest {
)
)
),
rowId = rowId2,
columnId = columnId2,
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(1)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -1297,10 +1368,15 @@ class BlockViewSearchTextTest {
)
)
),
rowId = rowId2,
columnId = columnId3,
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId3),
index = BlockView.Table.ColumnIndex(2)
),
tableId = tableId
)
)
@ -1358,10 +1434,15 @@ class BlockViewSearchTextTest {
id = row1Block1.id,
text = row1Block1.content.asText().text
),
rowId = rowId1,
columnId = columnId1,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(0),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(0)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -1369,10 +1450,15 @@ class BlockViewSearchTextTest {
id = row1Block2.id,
text = row1Block2.content.asText().text
),
rowId = rowId1,
columnId = columnId2,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(1)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -1380,10 +1466,15 @@ class BlockViewSearchTextTest {
id = row1Block3.id,
text = row1Block3.content.asText().text
),
rowId = rowId1,
columnId = columnId3,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId3),
index = BlockView.Table.ColumnIndex(2)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -1391,10 +1482,15 @@ class BlockViewSearchTextTest {
id = row2Block1.id,
text = row2Block1.content.asText().text
),
rowId = rowId2,
columnId = columnId1,
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(0),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(0)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -1402,10 +1498,15 @@ class BlockViewSearchTextTest {
id = row2Block2.id,
text = row2Block2.content.asText().text
),
rowId = rowId2,
columnId = columnId2,
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(1)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -1413,22 +1514,45 @@ class BlockViewSearchTextTest {
id = row2Block3.id,
text = row2Block3.content.asText().text
),
rowId = rowId2,
columnId = columnId3,
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId3),
index = BlockView.Table.ColumnIndex(2)
),
tableId = tableId
)
)
val columns = listOf(
BlockView.Table.ColumnId(value = columnId1),
BlockView.Table.ColumnId(value = columnId2),
BlockView.Table.ColumnId(value = columnId3)
BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(0)
),
BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(1)
),
BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId3),
index = BlockView.Table.ColumnIndex(2)
)
)
val rows = listOf(
BlockView.Table.RowId(value = rowId1),
BlockView.Table.RowId(value = rowId2)
BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
)
)
val views = listOf<BlockView>(
@ -1448,10 +1572,15 @@ class BlockViewSearchTextTest {
id = row1Block1.id,
text = row1Block1.content.asText().text
),
rowId = rowId1,
columnId = columnId1,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(0),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(0)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -1459,10 +1588,15 @@ class BlockViewSearchTextTest {
id = row1Block2.id,
text = row1Block2.content.asText().text
),
rowId = rowId1,
columnId = columnId2,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(1)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -1470,10 +1604,15 @@ class BlockViewSearchTextTest {
id = row1Block3.id,
text = row1Block3.content.asText().text
),
rowId = rowId1,
columnId = columnId3,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId3),
index = BlockView.Table.ColumnIndex(2)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -1481,10 +1620,15 @@ class BlockViewSearchTextTest {
id = row2Block1.id,
text = row2Block1.content.asText().text
),
rowId = rowId2,
columnId = columnId1,
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(0),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(0)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -1492,10 +1636,15 @@ class BlockViewSearchTextTest {
id = row2Block2.id,
text = row2Block2.content.asText().text
),
rowId = rowId2,
columnId = columnId2,
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(1)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -1503,10 +1652,15 @@ class BlockViewSearchTextTest {
id = row2Block3.id,
text = row2Block3.content.asText().text
),
rowId = rowId2,
columnId = columnId3,
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId3),
index = BlockView.Table.ColumnIndex(2)
),
tableId = tableId
)
)

View file

@ -347,10 +347,15 @@ fun StubTwoRowsThreeColumnsSimpleTable(
id = row1Block1.id,
text = row1Block1.content.asText().text
),
rowId = rowId1,
columnId = columnId1,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(0),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(0)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -358,10 +363,15 @@ fun StubTwoRowsThreeColumnsSimpleTable(
id = row1Block2.id,
text = row1Block2.content.asText().text
),
rowId = rowId1,
columnId = columnId2,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(1)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -369,10 +379,15 @@ fun StubTwoRowsThreeColumnsSimpleTable(
id = row1Block3.id,
text = row1Block3.content.asText().text
),
rowId = rowId1,
columnId = columnId3,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId3),
index = BlockView.Table.ColumnIndex(2)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -380,10 +395,15 @@ fun StubTwoRowsThreeColumnsSimpleTable(
id = row2Block1.id,
text = row2Block1.content.asText().text
),
rowId = rowId2,
columnId = columnId1,
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(0),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(0)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -391,10 +411,15 @@ fun StubTwoRowsThreeColumnsSimpleTable(
id = row2Block2.id,
text = row2Block2.content.asText().text
),
rowId = rowId2,
columnId = columnId2,
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(1)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -402,23 +427,45 @@ fun StubTwoRowsThreeColumnsSimpleTable(
id = row2Block3.id,
text = row2Block3.content.asText().text
),
rowId = rowId2,
columnId = columnId3,
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId3),
index = BlockView.Table.ColumnIndex(2)
),
tableId = tableId
)
)
val columns = listOf(
BlockView.Table.ColumnId(value = columnId1),
BlockView.Table.ColumnId(value = columnId2),
BlockView.Table.ColumnId(value = columnId3),
BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(0)
),
BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(1)
),
BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId3),
index = BlockView.Table.ColumnIndex(2)
)
)
val rows = listOf(
BlockView.Table.RowId(value = rowId1),
BlockView.Table.RowId(value = rowId2)
BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
)
)
return BlockView.Table(
@ -440,13 +487,20 @@ fun StubTableView(
selectedCellsIds: List<Id> = emptyList()
): BlockView.Table {
val columns = mutableListOf<BlockView.Table.ColumnId>()
val rows = mutableListOf<BlockView.Table.RowId>()
val columns = mutableListOf<BlockView.Table.Column>()
val rows = mutableListOf<BlockView.Table.Row>()
val cells = mutableListOf<BlockView.Table.Cell>()
for (i in 0 until rowSize) {
for (j in 0 until columnSize) {
val columnId = BlockView.Table.ColumnId(value = "columnId$j")
val rowId = BlockView.Table.RowId(value = "rowId$i")
val column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(value = "columnId$j"),
index = BlockView.Table.ColumnIndex(j)
)
val row = BlockView.Table.Row(
id = BlockView.Table.RowId(value = "rowId$i"),
index = BlockView.Table.RowIndex(i),
isHeader = false
)
val cell = StubCellView(
rowId = "rowId$i",
rowIndex = BlockView.Table.RowIndex(i),
@ -458,8 +512,8 @@ fun StubTableView(
),
tableId = tableId
)
rows.add(rowId)
columns.add(columnId)
rows.add(row)
columns.add(column)
cells.add(cell)
}
}
@ -484,13 +538,17 @@ fun StubCellView(
block: BlockView.Text.Paragraph?,
tableId: Id
) = BlockView.Table.Cell(
rowId = rowId,
rowIndex = rowIndex,
columnId = columnId,
columnIndex = columnIndex,
isHeader = isHeader,
block = block,
tableId = tableId
tableId = tableId,
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId),
index = rowIndex,
isHeader = isHeader
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId),
index = columnIndex
)
)
fun StubPattern(

View file

@ -64,10 +64,15 @@ class TableBlockTest {
val cells = listOf(
BlockView.Table.Cell(
rowId = rowId1,
columnId = columnId1,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(0),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(0)
),
block = null,
tableId = tableId
),
@ -76,10 +81,15 @@ class TableBlockTest {
id = row1Block1.id,
text = row1Block1.content.asText().text
),
rowId = rowId1,
columnId = columnId2,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(1)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -87,17 +97,27 @@ class TableBlockTest {
id = row1Block2.id,
text = row1Block2.content.asText().text
),
rowId = rowId1,
columnId = columnId3,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId3),
index = BlockView.Table.ColumnIndex(2)
),
tableId = tableId
),
BlockView.Table.Cell(
rowId = rowId1,
columnId = columnId4,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(3),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId4),
index = BlockView.Table.ColumnIndex(3)
),
block = null,
tableId = tableId
)
@ -105,10 +125,15 @@ class TableBlockTest {
val cellsNew = listOf(
BlockView.Table.Cell(
rowId = rowId1,
columnId = columnId1,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(0),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(0)
),
block = null,
tableId = tableId
),
@ -117,10 +142,15 @@ class TableBlockTest {
id = row1Block1.id,
text = row1Block1.content.asText().text
),
rowId = rowId1,
columnId = columnId2,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(1)
),
tableId = tableId
),
BlockView.Table.Cell(
@ -128,30 +158,58 @@ class TableBlockTest {
id = row1Block2.id,
text = newText
),
rowId = rowId1,
columnId = columnId3,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId3),
index = BlockView.Table.ColumnIndex(2)
),
tableId = tableId
),
BlockView.Table.Cell(
rowId = rowId1,
columnId = columnId4,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(3),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId4),
index = BlockView.Table.ColumnIndex(3)
),
block = null,
tableId = tableId
)
)
val columns = listOf(
BlockView.Table.ColumnId(value = columnId1),
BlockView.Table.ColumnId(value = columnId2),
BlockView.Table.ColumnId(value = columnId3),
BlockView.Table.ColumnId(value = columnId4)
BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(0)
),
BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(1)
),
BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId3),
index = BlockView.Table.ColumnIndex(2)
),
BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId4),
index = BlockView.Table.ColumnIndex(3)
)
)
val rows = listOf(BlockView.Table.RowId(value = rowId1))
val rows = listOf(
BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
)
)
scenario.onFragment {
it.view?.updateLayoutParams {

View file

@ -0,0 +1,32 @@
package com.anytypeio.anytype.domain.table
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.Payload
import com.anytypeio.anytype.core_models.Position
import com.anytypeio.anytype.domain.base.BaseUseCase
import com.anytypeio.anytype.domain.base.Either
import com.anytypeio.anytype.domain.block.repo.BlockRepository
class CreateTableColumn(
private val repo: BlockRepository
) : BaseUseCase<Payload, CreateTableColumn.Params>() {
override suspend fun run(params: Params): Either<Throwable, Payload> = safe {
repo.createTableColumn(
ctx = params.ctx,
targetId = params.target,
position = params.position
)
}
/**
* @param ctx - id of the context object
* @param target - id of the closest column
* @param position - position of the new column, relative to target column
*/
data class Params(
val ctx: Id,
val target: Id,
val position: Position
)
}

View file

@ -143,6 +143,8 @@ import com.anytypeio.anytype.presentation.editor.editor.styling.getStyleBackgrou
import com.anytypeio.anytype.presentation.editor.editor.styling.getStyleColorBackgroundToolbarState
import com.anytypeio.anytype.presentation.editor.editor.styling.getStyleOtherToolbarState
import com.anytypeio.anytype.presentation.editor.editor.styling.getStyleTextToolbarState
import com.anytypeio.anytype.presentation.editor.editor.table.EditorTableDelegate
import com.anytypeio.anytype.presentation.editor.editor.table.EditorTableEvent
import com.anytypeio.anytype.presentation.editor.editor.table.SimpleTableWidgetItem
import com.anytypeio.anytype.presentation.editor.editor.toCoreModel
import com.anytypeio.anytype.presentation.editor.editor.updateText
@ -157,9 +159,9 @@ import com.anytypeio.anytype.presentation.editor.selection.getAllSelectedColumns
import com.anytypeio.anytype.presentation.editor.selection.getAllSelectedRows
import com.anytypeio.anytype.presentation.editor.selection.getIdsInColumn
import com.anytypeio.anytype.presentation.editor.selection.getIdsInRow
import com.anytypeio.anytype.presentation.editor.selection.getSimpleTableWidgetColumn
import com.anytypeio.anytype.presentation.editor.selection.getSimpleTableWidgetItems
import com.anytypeio.anytype.presentation.editor.selection.getSimpleTableWidgetRow
import com.anytypeio.anytype.presentation.editor.selection.getSimpleTableWidgetColumnItems
import com.anytypeio.anytype.presentation.editor.selection.getSimpleTableWidgetCellItems
import com.anytypeio.anytype.presentation.editor.selection.getSimpleTableWidgetRowItems
import com.anytypeio.anytype.presentation.editor.selection.toggleTableMode
import com.anytypeio.anytype.presentation.editor.selection.updateTableBlockSelection
import com.anytypeio.anytype.presentation.editor.selection.updateTableBlockTab
@ -260,7 +262,8 @@ class EditorViewModel(
private val templateDelegate: EditorTemplateDelegate,
private val createNewObject: CreateNewObject,
private val objectToSet: ConvertObjectToSet,
private val featureToggles: FeatureToggles
private val featureToggles: FeatureToggles,
private val tableDelegate: EditorTableDelegate
) : ViewStateViewModel<ViewState>(),
PickerListener,
SupportNavigation<EventWrapper<AppNavigation.Command>>,
@ -269,6 +272,7 @@ class EditorViewModel(
ToggleStateHolder by renderer,
SelectionStateHolder by orchestrator.memory.selections,
EditorTemplateDelegate by templateDelegate,
EditorTableDelegate by tableDelegate,
StateReducer<List<Block>, Event> by reducer {
val actions = MutableStateFlow(ActionItemType.defaultSorting)
@ -3832,7 +3836,7 @@ class EditorViewModel(
EditorMode.Edit -> {
onTableRowEmptyCellClicked(
cellId = clicked.cell.getId(),
rowId = clicked.cell.rowId
rowId = clicked.cell.row.id.value
)
}
EditorMode.Select -> {
@ -3846,7 +3850,7 @@ class EditorViewModel(
if (cellTableId == modeTableId) {
onTableRowEmptyCellClicked(
cellId = clicked.cell.getId(),
rowId = clicked.cell.rowId
rowId = clicked.cell.row.id.value
)
proceedWithClickingOnCellInTableMode(
cell = clicked.cell,
@ -6085,7 +6089,7 @@ class EditorViewModel(
)
}
}
SimpleTableWidgetItem.Cell.ClearStyle -> {
SimpleTableWidgetItem.Cell.ResetStyle -> {
viewModelScope.launch {
orchestrator.proxies.intents.send(
Intent.Text.ClearStyle(
@ -6143,6 +6147,17 @@ class EditorViewModel(
)
}
}
is SimpleTableWidgetItem.Column.InsertLeft -> {
viewModelScope.launch {
tableDelegate.onEditorTableEvent(
EditorTableEvent.CreateColumn(
ctx = context,
target = item.column.value,
position = Position.LEFT
)
)
}
}
else -> Unit
}
}
@ -6171,7 +6186,7 @@ class EditorViewModel(
renderCommand.send(Unit)
controlPanelInteractor.onEvent(
ControlPanelMachine.Event.SimpleTableWidget.ShowCellTab(
cellItems = getSimpleTableWidgetItems(),
cellItems = getSimpleTableWidgetCellItems(),
tableId = cell.tableId,
cellSize = currentSelection().size
)
@ -6222,23 +6237,23 @@ class EditorViewModel(
)
ControlPanelMachine.Event.SimpleTableWidget.ShowCellTab(
cellItems = getSimpleTableWidgetItems(),
cellItems = getSimpleTableWidgetCellItems(),
tableId = cell.tableId,
cellSize = currentSelection().size
)
}
BlockView.Table.Tab.COLUMN -> {
val columnCellIds = tableBlock.getIdsInColumn(index = cell.columnIndex)
val columnCellIds = tableBlock.getIdsInColumn(index = cell.column.index)
if (isSelected(cell.getId())) {
unselect(columnCellIds)
} else {
select(columnCellIds)
}
val selectedColumns = mutableSetOf<Id>()
val selectedColumns = mutableSetOf<BlockView.Table.Column>()
tableBlock.cells.forEach {
if (currentSelection().contains(it.getId())) {
selectedColumns.add(it.columnId)
selectedColumns.add(it.column)
}
}
@ -6247,22 +6262,25 @@ class EditorViewModel(
)
ControlPanelMachine.Event.SimpleTableWidget.ShowColumnTab(
columnItems = getSimpleTableWidgetColumn(),
columnItems = getSimpleTableWidgetColumnItems(
selectedColumns = selectedColumns,
columnsSize = tableBlock.columns.size
),
tableId = cell.tableId,
columnsSize = selectedColumns.size
)
}
BlockView.Table.Tab.ROW -> {
val rowCellIds = tableBlock.getIdsInRow(index = cell.rowIndex)
val rowCellIds = tableBlock.getIdsInRow(index = cell.row.index)
if (isSelected(cell.getId())) {
unselect(rowCellIds)
} else {
select(rowCellIds)
}
val selectedRows = mutableSetOf<Id>()
val selectedRows = mutableSetOf<BlockView.Table.Row>()
tableBlock.cells.forEach {
if (currentSelection().contains(it.getId())) {
selectedRows.add(it.rowId)
selectedRows.add(it.row)
}
}
mode = modeTable.copy(
@ -6270,7 +6288,10 @@ class EditorViewModel(
)
ControlPanelMachine.Event.SimpleTableWidget.ShowRowTab(
rowItems = getSimpleTableWidgetRow(),
rowItems = getSimpleTableWidgetRowItems(
selectedRows = selectedRows,
rowsSize = tableBlock.rows.size
),
tableId = cell.tableId,
rowsSize = selectedRows.size
)
@ -6312,7 +6333,7 @@ class EditorViewModel(
tab = BlockView.Table.Tab.CELL
)
ControlPanelMachine.Event.SimpleTableWidget.ShowCellTab(
cellItems = getSimpleTableWidgetItems(),
cellItems = getSimpleTableWidgetCellItems(),
tableId = tableId,
cellSize = currentSelection().size
)
@ -6323,15 +6344,18 @@ class EditorViewModel(
val selectedColumns = tableBlock.getAllSelectedColumns(
selectedCellsIds = currentSelection()
)
select(selectedColumns.columns)
select(selectedColumns.cellsInColumns)
mode = modeTable.copy(
targets = currentSelection(),
tab = BlockView.Table.Tab.COLUMN
)
ControlPanelMachine.Event.SimpleTableWidget.ShowColumnTab(
columnItems = getSimpleTableWidgetColumn(),
columnItems = getSimpleTableWidgetColumnItems(
selectedColumns = selectedColumns.selectedColumns,
columnsSize = tableBlock.columns.size
),
tableId = tableId,
columnsSize = selectedColumns.count
columnsSize = selectedColumns.selectedColumns.size
)
}
BlockView.Table.Tab.ROW -> {
@ -6340,15 +6364,18 @@ class EditorViewModel(
val selectedRows = tableBlock.getAllSelectedRows(
selectedCellsIds = currentSelection()
)
select(selectedRows.rows)
select(selectedRows.cellsInRows)
mode = modeTable.copy(
targets = currentSelection(),
tab = BlockView.Table.Tab.ROW
)
ControlPanelMachine.Event.SimpleTableWidget.ShowRowTab(
rowItems = getSimpleTableWidgetRow(),
rowItems = getSimpleTableWidgetRowItems(
selectedRows = selectedRows.selectedRows,
rowsSize = tableBlock.rows.size
),
tableId = tableId,
rowsSize = selectedRows.count
rowsSize = selectedRows.selectedRows.size
)
}
}

View file

@ -34,6 +34,7 @@ import com.anytypeio.anytype.presentation.common.Delegator
import com.anytypeio.anytype.presentation.common.StateReducer
import com.anytypeio.anytype.presentation.editor.editor.DetailModificationManager
import com.anytypeio.anytype.presentation.editor.editor.Orchestrator
import com.anytypeio.anytype.presentation.editor.editor.table.EditorTableDelegate
import com.anytypeio.anytype.presentation.editor.render.DefaultBlockViewRenderer
import com.anytypeio.anytype.presentation.editor.template.EditorTemplateDelegate
import com.anytypeio.anytype.presentation.util.CopyFileToCacheDirectory
@ -71,7 +72,8 @@ open class EditorViewModelFactory(
private val editorTemplateDelegate: EditorTemplateDelegate,
private val createNewObject: CreateNewObject,
private val objectToSet: ConvertObjectToSet,
private val featureToggles: FeatureToggles
private val featureToggles: FeatureToggles,
private val tableDelegate: EditorTableDelegate
) : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
@ -108,7 +110,8 @@ open class EditorViewModelFactory(
templateDelegate = editorTemplateDelegate,
createNewObject = createNewObject,
objectToSet = objectToSet,
featureToggles = featureToggles
featureToggles = featureToggles,
tableDelegate = tableDelegate
) as T
}
}

View file

@ -1320,8 +1320,8 @@ sealed class BlockView : ViewType {
override val id: String,
override val isSelected: Boolean,
val background: ThemeColor = ThemeColor.DEFAULT,
val columns: List<ColumnId>,
val rows: List<RowId>,
val columns: List<Column>,
val rows: List<Row>,
val cells: List<Cell>,
val selectedCellsIds: List<Id>,
val tab: Tab = Tab.CELL
@ -1329,15 +1329,12 @@ sealed class BlockView : ViewType {
override fun getViewType(): Int = HOLDER_TABLE
data class Cell(
val rowId: Id,
val rowIndex: RowIndex,
val columnId: Id,
val columnIndex: ColumnIndex,
val isHeader: Boolean = false,
val block: Text.Paragraph?,
val tableId: Id
val tableId: Id,
val row: Row,
val column: Column,
val block: Text.Paragraph?
) {
fun getId() = "$rowId-$columnId"
fun getId() = "${row.id.value}-${column.id.value}"
}
data class CellSelection(
@ -1355,11 +1352,15 @@ sealed class BlockView : ViewType {
@JvmInline
value class RowIndex(val value: Int)
data class Row(val id: RowId, val index: RowIndex, val isHeader: Boolean)
@JvmInline
value class ColumnId(val value: String)
@JvmInline
value class ColumnIndex(val value: Int)
data class Column(val id: ColumnId, val index: ColumnIndex)
enum class Tab { CELL, COLUMN, ROW }
}
}

View file

@ -0,0 +1,41 @@
package com.anytypeio.anytype.presentation.editor.editor.table
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.Payload
import com.anytypeio.anytype.core_models.Position
import com.anytypeio.anytype.domain.table.CreateTableColumn
import com.anytypeio.anytype.presentation.editor.Editor
import com.anytypeio.anytype.presentation.util.Dispatcher
import timber.log.Timber
sealed class EditorTableEvent {
data class CreateColumn(val ctx: Id, val target: Id, val position: Position) :
EditorTableEvent()
}
interface EditorTableDelegate {
suspend fun onEditorTableEvent(event: EditorTableEvent)
}
class DefaultEditorTableDelegate(
private val dispatcher: Dispatcher<Payload>,
private val createTableColumn: CreateTableColumn
) : EditorTableDelegate {
override suspend fun onEditorTableEvent(event: EditorTableEvent) {
when (event) {
is EditorTableEvent.CreateColumn -> {
val params = CreateTableColumn.Params(
ctx = event.ctx,
target = event.target,
position = event.position
)
createTableColumn.run(params).proceed(
failure = { Timber.e("Error while creating table column:${it.message} ") },
success = { payload -> dispatcher.send(payload) }
)
}
}
}
}

View file

@ -1,38 +1,43 @@
package com.anytypeio.anytype.presentation.editor.editor.table
import com.anytypeio.anytype.presentation.editor.editor.model.BlockView
sealed class SimpleTableWidgetItem {
sealed class Cell : SimpleTableWidgetItem() {
object ClearContents : Cell()
object Color : Cell()
object Style : Cell()
object ClearStyle : Cell()
object ResetStyle : Cell()
}
sealed class Column : SimpleTableWidgetItem() {
object InsertLeft : Column()
object InsertRight : Column()
object MoveLeft : Column()
object MoveRight : Column()
object Duplicate : Column()
object Delete : Column()
object ClearContents : Column()
object Sort : Column()
object Color : Column()
object Style : Column()
data class InsertLeft(val column: BlockView.Table.ColumnId) : Column()
data class InsertRight(val column: BlockView.Table.ColumnId) : Column()
data class MoveLeft(val column: BlockView.Table.ColumnId) : Column()
data class MoveRight(val column: BlockView.Table.ColumnId) : Column()
data class Duplicate(val columns: List<BlockView.Table.ColumnId>) : Column()
data class Delete(val columns: List<BlockView.Table.ColumnId>) : Column()
data class Copy(val columns: List<BlockView.Table.ColumnId>) : Column()
data class ClearContents(val columns: List<BlockView.Table.ColumnId>) : Column()
data class Sort(val column: BlockView.Table.ColumnId) : Column()
data class Color(val columns: List<BlockView.Table.ColumnId>) : Column()
data class Style(val columns: List<BlockView.Table.ColumnId>) : Column()
data class ResetStyle(val columns: List<BlockView.Table.ColumnId>) : Column()
}
sealed class Row : SimpleTableWidgetItem() {
object InsertAbove : Row()
object InsertBelow : Row()
object MoveUp : Row()
object MoveDown : Row()
object Duplicate : Row()
object Delete : Row()
object ClearContents : Row()
object Sort : Row()
object Color : Row()
object Style : Row()
data class InsertAbove(val row: BlockView.Table.RowId) : Row()
data class InsertBelow(val row: BlockView.Table.RowId) : Row()
data class MoveUp(val row: BlockView.Table.RowId) : Row()
data class MoveDown(val row: BlockView.Table.RowId) : Row()
data class Duplicate(val rows: List<BlockView.Table.RowId>) : Row()
data class Delete(val rows: List<BlockView.Table.RowId>) : Row()
data class Copy(val rows: List<BlockView.Table.RowId>) : Row()
data class ClearContents(val rows: List<BlockView.Table.RowId>) : Row()
data class Color(val rows: List<BlockView.Table.RowId>) : Row()
data class Style(val rows: List<BlockView.Table.RowId>) : Row()
data class ResetStyle(val rows: List<BlockView.Table.RowId>) : Row()
}
sealed class Tab : SimpleTableWidgetItem() {

View file

@ -2,7 +2,6 @@ package com.anytypeio.anytype.presentation.editor.render
import com.anytypeio.anytype.core_models.Block
import com.anytypeio.anytype.core_models.Block.Content
import com.anytypeio.anytype.core_models.CoverType
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.core_models.ObjectType
import com.anytypeio.anytype.core_models.ObjectType.Companion.BOOKMARK_TYPE
@ -11,7 +10,6 @@ import com.anytypeio.anytype.core_models.Relation
import com.anytypeio.anytype.core_models.Relations
import com.anytypeio.anytype.core_models.SmartBlockType
import com.anytypeio.anytype.core_models.ThemeColor
import com.anytypeio.anytype.core_models.Url
import com.anytypeio.anytype.core_models.ext.parseThemeTextColor
import com.anytypeio.anytype.core_models.ext.textColor
import com.anytypeio.anytype.core_models.restrictions.ObjectRestriction
@ -20,7 +18,6 @@ import com.anytypeio.anytype.domain.editor.Editor.Focus
import com.anytypeio.anytype.domain.misc.UrlBuilder
import com.anytypeio.anytype.presentation.BuildConfig.NESTED_DECORATION_ENABLED
import com.anytypeio.anytype.presentation.editor.Editor
import com.anytypeio.anytype.presentation.editor.cover.CoverColor
import com.anytypeio.anytype.presentation.editor.cover.CoverImageHashProvider
import com.anytypeio.anytype.presentation.editor.editor.ext.getTextAndMarks
import com.anytypeio.anytype.presentation.editor.editor.model.BlockView
@ -36,7 +33,6 @@ import com.anytypeio.anytype.presentation.objects.ObjectIcon
import com.anytypeio.anytype.presentation.objects.appearance.LinkAppearanceFactory
import com.anytypeio.anytype.presentation.relations.BasicObjectCoverWrapper
import com.anytypeio.anytype.presentation.relations.BlockFieldsCoverWrapper
import com.anytypeio.anytype.presentation.relations.CoverWrapper
import com.anytypeio.anytype.presentation.relations.DocumentRelationView
import com.anytypeio.anytype.presentation.relations.getCover
import com.anytypeio.anytype.presentation.relations.view
@ -1926,20 +1922,28 @@ class DefaultBlockViewRenderer @Inject constructor(
): BlockView.Table {
var cells: List<BlockView.Table.Cell> = emptyList()
var columnsIds: List<BlockView.Table.ColumnId> = emptyList()
var rowsIds: List<BlockView.Table.RowId> = emptyList()
var rowCount = 0
var rows: List<BlockView.Table.Row> = emptyList()
var columns: List<BlockView.Table.Column> = emptyList()
blocks.getValue(block.id).forEach { container ->
val containerContent = container.content
if (containerContent !is Content.Layout) return@forEach
if (containerContent.type == Content.Layout.Type.TABLE_COLUMN) {
columnsIds = blocks.getValue(container.id).map { BlockView.Table.ColumnId(it.id) }
columns = blocks.getValue(container.id).mapIndexed { index, column ->
BlockView.Table.Column(
id = BlockView.Table.ColumnId(column.id),
index = BlockView.Table.ColumnIndex(index)
)
}
}
if (containerContent.type == Content.Layout.Type.TABLE_ROW) {
val rows = blocks.getValue(container.id)
rowsIds = rows.map { BlockView.Table.RowId(it.id) }
rowCount = rows.size
rows = blocks.getValue(container.id).mapIndexed { index, row ->
BlockView.Table.Row(
id = BlockView.Table.RowId(row.id),
index = BlockView.Table.RowIndex(index),
isHeader = (row.content as? Content.TableRow)?.isHeader ?: false
)
}
cells = tableCells(
mode = mode,
focus = focus,
@ -1947,7 +1951,7 @@ class DefaultBlockViewRenderer @Inject constructor(
details = details,
selection = selection,
rows = rows,
columnIds = columnsIds,
columns = columns,
blocks = blocks,
tableId = block.id
)
@ -1955,8 +1959,8 @@ class DefaultBlockViewRenderer @Inject constructor(
}
return BlockView.Table(
id = block.id,
columns = columnsIds,
rows = rowsIds,
columns = columns,
rows = rows,
cells = cells,
isSelected = checkIfSelected(
mode = mode,
@ -1971,8 +1975,8 @@ class DefaultBlockViewRenderer @Inject constructor(
private fun tableCells(
tableId: Id,
blocks: Map<String, List<Block>>,
rows: List<Block>,
columnIds: List<BlockView.Table.ColumnId>,
rows: List<BlockView.Table.Row>,
columns: List<BlockView.Table.Column>,
mode: EditorMode,
focus: Focus,
indent: Int,
@ -1980,16 +1984,18 @@ class DefaultBlockViewRenderer @Inject constructor(
selection: Set<Id>
): List<BlockView.Table.Cell> {
val cells = mutableListOf<BlockView.Table.Cell>()
columnIds.mapIndexed { columnIndex, columnId ->
rows.forEachIndexed { rowIndex, row ->
val isHeader = (row.content as? Content.TableRow)?.isHeader ?: false
val cellId = "${row.id}-${columnId.value}"
val rowsChildren = blocks.getValue(row.id)
val block = rowsChildren.firstOrNull { it.id == cellId }
val paragraph = if (block != null) {
val content = block.content
check(content is Content.Text)
{ Timber.e("Table row block content should be Text") }
columns.forEach { column ->
rows.forEach { row ->
val cell = BlockView.Table.Cell(
tableId = tableId,
row = row,
column = column,
block = null
)
val rowCellBlocks = blocks.getValue(row.id.value)
val block = rowCellBlocks.firstOrNull { it.id == cell.getId() }
val content = block?.content
val paragraph = if (block != null && content is Content.Text) {
if (content.style == Content.Text.Style.P) {
paragraph(
mode = mode,
@ -2008,17 +2014,11 @@ class DefaultBlockViewRenderer @Inject constructor(
} else {
null
}
cells.add(
BlockView.Table.Cell(
rowId = row.id,
rowIndex = BlockView.Table.RowIndex(rowIndex),
columnId = columnId.value,
columnIndex = BlockView.Table.ColumnIndex(columnIndex),
isHeader = isHeader,
tableId = tableId,
block = paragraph
)
)
if (paragraph != null) {
cells.add(cell.copy(block = paragraph))
} else {
cells.add(cell)
}
}
}
return cells

View file

@ -3,6 +3,14 @@ package com.anytypeio.anytype.presentation.editor.selection
import com.anytypeio.anytype.core_models.Id
import com.anytypeio.anytype.presentation.editor.editor.model.BlockView
import com.anytypeio.anytype.presentation.editor.editor.table.SimpleTableWidgetItem
import com.anytypeio.anytype.presentation.editor.editor.table.SimpleTableWidgetItem.Column.InsertRight
import com.anytypeio.anytype.presentation.editor.editor.table.SimpleTableWidgetItem.Column.InsertLeft
import com.anytypeio.anytype.presentation.editor.editor.table.SimpleTableWidgetItem.Column.MoveLeft
import com.anytypeio.anytype.presentation.editor.editor.table.SimpleTableWidgetItem.Column.MoveRight
import com.anytypeio.anytype.presentation.editor.editor.table.SimpleTableWidgetItem.Row.InsertAbove
import com.anytypeio.anytype.presentation.editor.editor.table.SimpleTableWidgetItem.Row.InsertBelow
import com.anytypeio.anytype.presentation.editor.editor.table.SimpleTableWidgetItem.Row.MoveDown
import com.anytypeio.anytype.presentation.editor.editor.table.SimpleTableWidgetItem.Row.MoveUp
typealias CellSelection = BlockView.Table.CellSelection
@ -387,74 +395,130 @@ fun List<BlockView>.updateTableBlockTab(
}
}
fun getSimpleTableWidgetItems(): List<SimpleTableWidgetItem> {
fun getSimpleTableWidgetCellItems(): List<SimpleTableWidgetItem> {
return listOf(
SimpleTableWidgetItem.Cell.ClearContents,
SimpleTableWidgetItem.Cell.Color,
SimpleTableWidgetItem.Cell.Style,
SimpleTableWidgetItem.Cell.ClearStyle
SimpleTableWidgetItem.Cell.ResetStyle
)
}
fun getSimpleTableWidgetColumn(): List<SimpleTableWidgetItem> {
return listOf(
SimpleTableWidgetItem.Column.InsertLeft,
SimpleTableWidgetItem.Column.InsertRight,
SimpleTableWidgetItem.Column.MoveLeft,
SimpleTableWidgetItem.Column.MoveRight,
SimpleTableWidgetItem.Column.ClearContents,
SimpleTableWidgetItem.Column.Color,
SimpleTableWidgetItem.Column.Style,
)
fun getSimpleTableWidgetColumnItems(
selectedColumns: Set<BlockView.Table.Column>,
columnsSize: Int
): List<SimpleTableWidgetItem> {
return mutableListOf<SimpleTableWidgetItem>().apply {
if (selectedColumns.size == 1) {
addAll(selectedColumns.first().getTableWidgetItemsByColumn(columnsSize))
}
if (selectedColumns.isNotEmpty()) {
val ids = selectedColumns.map { it.id }
addAll(
listOf(
SimpleTableWidgetItem.Column.Delete(ids),
SimpleTableWidgetItem.Column.Copy(ids),
SimpleTableWidgetItem.Column.Duplicate(ids),
SimpleTableWidgetItem.Column.ClearContents(ids),
SimpleTableWidgetItem.Column.Color(ids),
SimpleTableWidgetItem.Column.Style(ids),
SimpleTableWidgetItem.Column.ResetStyle(ids)
)
)
}
}
}
fun getSimpleTableWidgetRow(): List<SimpleTableWidgetItem> {
return listOf(
SimpleTableWidgetItem.Row.InsertAbove,
SimpleTableWidgetItem.Row.InsertBelow,
SimpleTableWidgetItem.Row.MoveDown,
SimpleTableWidgetItem.Row.MoveUp,
SimpleTableWidgetItem.Row.ClearContents,
SimpleTableWidgetItem.Row.Color,
SimpleTableWidgetItem.Row.Style,
)
fun getSimpleTableWidgetRowItems(
selectedRows: Set<BlockView.Table.Row>,
rowsSize: Int
): List<SimpleTableWidgetItem> {
return mutableListOf<SimpleTableWidgetItem>().apply {
if (selectedRows.size == 1) {
addAll(selectedRows.first().getTableWidgetItemsByRow(rowsSize))
}
if (selectedRows.isNotEmpty()) {
val ids = selectedRows.map { it.id }
addAll(
listOf(
SimpleTableWidgetItem.Row.Delete(ids),
SimpleTableWidgetItem.Row.Copy(ids),
SimpleTableWidgetItem.Row.Duplicate(ids),
SimpleTableWidgetItem.Row.ClearContents(ids),
SimpleTableWidgetItem.Row.Color(ids),
SimpleTableWidgetItem.Row.Style(ids),
SimpleTableWidgetItem.Row.ResetStyle(ids)
)
)
}
}
}
fun BlockView.Table.Column.getTableWidgetItemsByColumn(
columnsSize: Int
): List<SimpleTableWidgetItem> = mutableListOf<SimpleTableWidgetItem>().apply {
add(InsertLeft(id))
add(InsertRight(id))
if (index.value > 0) add(MoveLeft(id))
if (index.value < columnsSize - 1) add(MoveRight(id))
}
fun BlockView.Table.Row.getTableWidgetItemsByRow(
rowSize: Int
): List<SimpleTableWidgetItem> = mutableListOf<SimpleTableWidgetItem>().apply {
add(InsertAbove(id))
add(InsertBelow(id))
if (index.value > 0) add(MoveUp(id))
if (index.value < rowSize - 1) add(MoveDown(id))
}
fun BlockView.Table.getIdsInRow(index: BlockView.Table.RowIndex): List<Id> =
this.cells.filter { it.rowIndex == index }.map { it.getId() }
this.cells.mapNotNull {
if (it.row.index == index) {
it.getId()
} else {
null
}
}
fun BlockView.Table.getIdsInColumn(index: BlockView.Table.ColumnIndex): List<Id> =
this.cells.filter { it.columnIndex == index }.map { it.getId() }
this.cells.mapNotNull {
if (it.column.index == index) {
it.getId()
} else {
null
}
}
fun BlockView.Table.getAllSelectedColumns(selectedCellsIds: Set<Id>): SelectedColumns {
val selectedCells = cells.filter { selectedCellsIds.contains(it.getId()) }
val selectedColumns = mutableSetOf<Id>()
val selectedColumnsIndexes = mutableSetOf<Int>()
val selectedColumnCells = mutableSetOf<Id>()
val selectedColumns = mutableSetOf<BlockView.Table.Column>()
selectedCells.forEach { cell ->
selectedColumnsIndexes.add(cell.columnIndex.value)
val column = getIdsInColumn(cell.columnIndex)
selectedColumns.addAll(column)
selectedColumns.add(cell.column)
selectedColumnCells.addAll(getIdsInColumn(cell.column.index))
}
return SelectedColumns(
columns = selectedColumns.toList(),
count = selectedColumnsIndexes.size
cellsInColumns = selectedColumnCells.toList(),
selectedColumns = selectedColumns
)
}
fun BlockView.Table.getAllSelectedRows(selectedCellsIds: Set<Id>): SelectedRows {
val selectedCells = cells.filter { selectedCellsIds.contains(it.getId()) }
val selectedRows = mutableSetOf<Id>()
val selectedRowsIndexes = mutableSetOf<Int>()
val selectedRowCells = mutableSetOf<Id>()
val selectedRows = mutableSetOf<BlockView.Table.Row>()
selectedCells.forEach { cell ->
selectedRowsIndexes.add(cell.rowIndex.value)
val row = getIdsInRow(cell.rowIndex)
selectedRows.addAll(row)
selectedRows.add(cell.row)
selectedRowCells.addAll(getIdsInRow(cell.row.index))
}
return SelectedRows(
rows = selectedRows.toList(),
count = selectedRowsIndexes.size
cellsInRows = selectedRowCells.toList(), selectedRows = selectedRows
)
}
data class SelectedRows(val rows: List<Id>, val count: Int)
data class SelectedColumns(val columns: List<Id>, val count: Int)
data class SelectedRows(val cellsInRows: List<Id>, val selectedRows: Set<BlockView.Table.Row>)
data class SelectedColumns(
val cellsInColumns: List<Id>,
val selectedColumns: Set<BlockView.Table.Column>
)

View file

@ -10,8 +10,8 @@ class TableCellsSelectionState {
cells.forEach { cell ->
memory = updateTableCellsSelectionState(
cellId = cell.getId(),
rowIndex = cell.rowIndex,
columnIndex = cell.columnIndex,
rowIndex = cell.row.index,
columnIndex = cell.column.index,
selectionState = current(),
rowsSize = rowsSize
)

View file

@ -103,6 +103,7 @@ import com.anytypeio.anytype.presentation.editor.editor.pattern.DefaultPatternMa
import com.anytypeio.anytype.presentation.editor.editor.slash.SlashItem
import com.anytypeio.anytype.presentation.editor.editor.styling.StyleToolbarState
import com.anytypeio.anytype.presentation.editor.editor.styling.StylingEvent
import com.anytypeio.anytype.presentation.editor.editor.table.EditorTableDelegate
import com.anytypeio.anytype.presentation.editor.render.DefaultBlockViewRenderer
import com.anytypeio.anytype.presentation.editor.render.parseThemeBackgroundColor
import com.anytypeio.anytype.presentation.editor.selection.SelectionStateHolder
@ -334,6 +335,9 @@ open class EditorViewModelTest {
@Mock
lateinit var createTable: CreateTable
@Mock
lateinit var tableDelegate: EditorTableDelegate
private lateinit var updateDetail: UpdateDetail
lateinit var vm: EditorViewModel
@ -4024,7 +4028,8 @@ open class EditorViewModelTest {
templateDelegate = editorTemplateDelegate,
createNewObject = createNewObject,
objectToSet = objectToSet,
featureToggles = mock()
featureToggles = mock(),
tableDelegate = tableDelegate
)
}

View file

@ -77,6 +77,7 @@ import com.anytypeio.anytype.presentation.editor.Editor
import com.anytypeio.anytype.presentation.editor.EditorViewModel
import com.anytypeio.anytype.presentation.editor.cover.CoverImageHashProvider
import com.anytypeio.anytype.presentation.editor.editor.pattern.DefaultPatternMatcher
import com.anytypeio.anytype.presentation.editor.editor.table.EditorTableDelegate
import com.anytypeio.anytype.presentation.editor.render.DefaultBlockViewRenderer
import com.anytypeio.anytype.presentation.editor.selection.SelectionStateHolder
import com.anytypeio.anytype.presentation.editor.template.DefaultEditorTemplateDelegate
@ -266,6 +267,9 @@ open class EditorPresentationTestSetup {
@Mock
lateinit var fillTableRow: FillTableRow
@Mock
lateinit var tableDelegate: EditorTableDelegate
lateinit var editorTemplateDelegate: EditorTemplateDelegate
protected val builder: UrlBuilder get() = UrlBuilder(gateway)
@ -382,7 +386,8 @@ open class EditorPresentationTestSetup {
templateDelegate = editorTemplateDelegate,
createNewObject = createNewObject,
objectToSet = objectToSet,
featureToggles = mock()
featureToggles = mock(),
tableDelegate = tableDelegate
)
}

View file

@ -9,7 +9,14 @@ import kotlin.test.assertEquals
class TableCellsSelectionStateTest {
val tableId = MockDataFactory.randomUuid()
private val tableId = MockDataFactory.randomUuid()
private val rowId0 = MockDataFactory.randomUuid()
private val rowId1 = MockDataFactory.randomUuid()
private val rowId2 = MockDataFactory.randomUuid()
private val columnId0 = MockDataFactory.randomUuid()
private val columnId1 = MockDataFactory.randomUuid()
private val columnId2 = MockDataFactory.randomUuid()
@Test
fun `when click on cell expecting selected state with this cell`() {
@ -22,10 +29,15 @@ class TableCellsSelectionStateTest {
cellsSelectionState.set(
cells = listOf(
BlockView.Table.Cell(
rowId = "row1",
columnId = "column1",
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(1)
),
block = null,
tableId = tableId
)
@ -38,7 +50,7 @@ class TableCellsSelectionStateTest {
//EXPECTED
val expected = mapOf(
4 to CellSelection(
cellId = "row1-column1",
cellId = "$rowId1-$columnId1",
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(1),
left = true,
@ -63,10 +75,15 @@ class TableCellsSelectionStateTest {
cellsSelectionState.set(
cells = listOf(
BlockView.Table.Cell(
rowId = "row1",
columnId = "column1",
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(1)
),
block = null,
tableId = tableId,
)
@ -78,10 +95,15 @@ class TableCellsSelectionStateTest {
cellsSelectionState.set(
cells = listOf(
BlockView.Table.Cell(
rowId = "row1",
columnId = "column1",
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(1)
),
block = null,
tableId = tableId
)
@ -109,10 +131,15 @@ class TableCellsSelectionStateTest {
cellsSelectionState.set(
cells = listOf(
BlockView.Table.Cell(
rowId = "row1",
columnId = "column0",
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(0),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId0),
index = BlockView.Table.ColumnIndex(0)
),
block = null,
tableId = tableId
)
@ -123,10 +150,15 @@ class TableCellsSelectionStateTest {
cellsSelectionState.set(
cells = listOf(
BlockView.Table.Cell(
rowId = "row1",
columnId = "column2",
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(2)
),
block = null,
tableId = tableId
)
@ -138,10 +170,15 @@ class TableCellsSelectionStateTest {
cellsSelectionState.set(
cells = listOf(
BlockView.Table.Cell(
rowId = "row2",
columnId = "column0",
rowIndex = BlockView.Table.RowIndex(2),
columnIndex = BlockView.Table.ColumnIndex(0),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(2),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId0),
index = BlockView.Table.ColumnIndex(0)
),
block = null,
tableId = tableId
)
@ -153,10 +190,15 @@ class TableCellsSelectionStateTest {
cellsSelectionState.set(
cells = listOf(
BlockView.Table.Cell(
rowId = "row0",
columnId = "column2",
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId0),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(2)
),
block = null,
tableId = tableId
)
@ -168,10 +210,15 @@ class TableCellsSelectionStateTest {
cellsSelectionState.set(
cells = listOf(
BlockView.Table.Cell(
rowId = "row1",
columnId = "column1",
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(1)
),
block = null,
tableId = tableId
)
@ -184,7 +231,7 @@ class TableCellsSelectionStateTest {
//EXPECTED
val expected = mapOf(
1 to CellSelection(
cellId = "row1-column0",
cellId = "$rowId1-$columnId0",
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(0),
left = true,
@ -193,7 +240,7 @@ class TableCellsSelectionStateTest {
bottom = false
),
7 to CellSelection(
cellId = "row1-column2",
cellId = "$rowId1-$columnId2",
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(2),
left = false,
@ -202,7 +249,7 @@ class TableCellsSelectionStateTest {
bottom = true,
),
2 to CellSelection(
cellId = "row2-column0",
cellId = "$rowId2-$columnId0",
rowIndex = BlockView.Table.RowIndex(2),
columnIndex = BlockView.Table.ColumnIndex(0),
left = true,
@ -211,7 +258,7 @@ class TableCellsSelectionStateTest {
bottom = true,
),
6 to CellSelection(
cellId = "row0-column2",
cellId = "$rowId0-$columnId2",
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(2),
left = true,
@ -220,7 +267,7 @@ class TableCellsSelectionStateTest {
bottom = false,
),
4 to CellSelection(
cellId = "row1-column1",
cellId = "$rowId1-$columnId1",
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(1),
left = false,
@ -239,10 +286,15 @@ class TableCellsSelectionStateTest {
cellsSelectionState.set(
cells = listOf(
BlockView.Table.Cell(
rowId = "row1",
columnId = "column1",
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(1)
),
block = null,
tableId = tableId
)
@ -255,7 +307,7 @@ class TableCellsSelectionStateTest {
//EXPECTED
val expected2 = mapOf(
1 to CellSelection(
cellId = "row1-column0",
cellId = "$rowId1-$columnId0",
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(0),
left = true,
@ -264,7 +316,7 @@ class TableCellsSelectionStateTest {
bottom = false
),
7 to CellSelection(
cellId = "row1-column2",
cellId = "$rowId1-$columnId2",
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(2),
left = true,
@ -273,7 +325,7 @@ class TableCellsSelectionStateTest {
bottom = true
),
2 to CellSelection(
cellId = "row2-column0",
cellId = "$rowId2-$columnId0",
rowIndex = BlockView.Table.RowIndex(2),
columnIndex = BlockView.Table.ColumnIndex(0),
left = true,
@ -282,7 +334,7 @@ class TableCellsSelectionStateTest {
bottom = true
),
6 to CellSelection(
cellId = "row0-column2",
cellId = "$rowId0-$columnId2",
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(2),
left = true,
@ -301,10 +353,15 @@ class TableCellsSelectionStateTest {
cellsSelectionState.set(
cells = listOf(
BlockView.Table.Cell(
rowId = "row0",
columnId = "column2",
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId0),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(2)
),
block = null,
tableId = tableId
)
@ -315,10 +372,15 @@ class TableCellsSelectionStateTest {
cellsSelectionState.set(
cells = listOf(
BlockView.Table.Cell(
rowId = "row2",
columnId = "column0",
rowIndex = BlockView.Table.RowIndex(2),
columnIndex = BlockView.Table.ColumnIndex(0),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(2),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId0),
index = BlockView.Table.ColumnIndex(0)
),
block = null,
tableId = tableId
)
@ -331,7 +393,7 @@ class TableCellsSelectionStateTest {
//EXPECTED
val expected3 = mapOf(
1 to CellSelection(
cellId = "row1-column0",
cellId = "$rowId1-$columnId0",
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(0),
left = true,
@ -340,7 +402,7 @@ class TableCellsSelectionStateTest {
bottom = true
),
7 to CellSelection(
cellId = "row1-column2",
cellId = "$rowId1-$columnId2",
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(2),
left = true,

View file

@ -17,9 +17,8 @@ import com.anytypeio.anytype.presentation.editor.editor.EditorPresentationTestSe
import com.anytypeio.anytype.presentation.editor.editor.control.ControlPanelState
import com.anytypeio.anytype.presentation.editor.editor.listener.ListenerType
import com.anytypeio.anytype.presentation.editor.editor.model.BlockView
import com.anytypeio.anytype.presentation.editor.selection.getSimpleTableWidgetColumn
import com.anytypeio.anytype.presentation.editor.selection.getSimpleTableWidgetItems
import com.anytypeio.anytype.presentation.editor.selection.getSimpleTableWidgetRow
import com.anytypeio.anytype.presentation.editor.selection.getSimpleTableWidgetCellItems
import com.anytypeio.anytype.presentation.editor.selection.getSimpleTableWidgetRowItems
import com.anytypeio.anytype.presentation.util.CoroutinesTestRule
import com.anytypeio.anytype.test_utils.MockDataFactory
import kotlinx.coroutines.runBlocking
@ -81,10 +80,15 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
onClickListener(
ListenerType.TableEmptyCell(
cell = BlockView.Table.Cell(
rowId = rows[0].id,
columnId = columns[1].id,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rows[0].id),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columns[1].id),
index = BlockView.Table.ColumnIndex(1)
),
block = null,
tableId = table.id
)
@ -93,10 +97,15 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
onClickListener(
ListenerType.TableEmptyCell(
cell = BlockView.Table.Cell(
rowId = rows[1].id,
columnId = columns[0].id,
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(0),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rows[1].id),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columns[0].id),
index = BlockView.Table.ColumnIndex(0)
),
block = null,
tableId = table.id
)
@ -147,10 +156,15 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
onClickListener(
ListenerType.TableTextCell(
cell = BlockView.Table.Cell(
rowId = rows[0].id,
columnId = columns[1].id,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rows[0].id),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columns[1].id),
index = BlockView.Table.ColumnIndex(1)
),
block = BlockView.Text.Paragraph(
id = cells[0].id,
text = cells[0].content.asText().text
@ -162,10 +176,15 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
onClickListener(
ListenerType.TableTextCell(
cell = BlockView.Table.Cell(
rowId = rows[1].id,
columnId = columns[0].id,
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(0),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rows[1].id),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columns[0].id),
index = BlockView.Table.ColumnIndex(0)
),
block = BlockView.Text.Paragraph(
id = cells[1].id,
text = cells[1].content.asText().text
@ -279,10 +298,15 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
onClickListener(
clicked = ListenerType.TableTextCell(
cell = BlockView.Table.Cell(
rowId = rows[1].id,
columnId = columns[1].id,
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rows[1].id),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columns[1].id),
index = BlockView.Table.ColumnIndex(1)
),
block = BlockView.Text.Paragraph(
id = cells[4].id,
text = cells[4].content.asText().text
@ -295,10 +319,15 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
onClickListener(
clicked = ListenerType.TableTextCell(
cell = BlockView.Table.Cell(
rowId = rows[2].id,
columnId = columns[2].id,
rowIndex = BlockView.Table.RowIndex(2),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rows[2].id),
index = BlockView.Table.RowIndex(2),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columns[2].id),
index = BlockView.Table.ColumnIndex(2)
),
block = BlockView.Text.Paragraph(
id = cells[8].id,
text = cells[8].content.asText().text
@ -311,10 +340,15 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
onClickListener(
clicked = ListenerType.TableTextCell(
cell = BlockView.Table.Cell(
rowId = rows[1].id,
columnId = columns[1].id,
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rows[1].id),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columns[1].id),
index = BlockView.Table.ColumnIndex(1)
),
block = BlockView.Text.Paragraph(
id = cells[4].id,
text = cells[4].content.asText().text
@ -388,10 +422,15 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
onClickListener(
clicked = ListenerType.TableTextCell(
cell = BlockView.Table.Cell(
rowId = rows[2].id,
columnId = columns[2].id,
rowIndex = BlockView.Table.RowIndex(2),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rows[2].id),
index = BlockView.Table.RowIndex(2),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columns[2].id),
index = BlockView.Table.ColumnIndex(2)
),
block = BlockView.Text.Paragraph(
id = cells[8].id,
text = cells[8].content.asText().text
@ -472,10 +511,15 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
onClickListener(
clicked = ListenerType.TableTextCell(
cell = BlockView.Table.Cell(
rowId = rows[2].id,
columnId = columns[2].id,
rowIndex = BlockView.Table.RowIndex(2),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rows[2].id),
index = BlockView.Table.RowIndex(2),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columns[2].id),
index = BlockView.Table.ColumnIndex(2)
),
block = BlockView.Text.Paragraph(
id = cells[8].id,
text = cells[8].content.asText().text
@ -488,10 +532,15 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
onClickListener(
clicked = ListenerType.TableTextCell(
cell = BlockView.Table.Cell(
rowId = rows[2].id,
columnId = columns[2].id,
rowIndex = BlockView.Table.RowIndex(2),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rows[2].id),
index = BlockView.Table.RowIndex(2),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columns[2].id),
index = BlockView.Table.ColumnIndex(2)
),
block = BlockView.Text.Paragraph(
id = cells[8].id,
text = cells[8].content.asText().text
@ -561,9 +610,9 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
clicked = ListenerType.TableTextCell(
cell = mapToViewCell(
cell = cells[13],
rows = rows,
row = rows[3],
rowIndex = 3,
columns = columns,
column = columns[1],
columnIndex = 1
)
)
@ -573,9 +622,9 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
clicked = ListenerType.TableTextCell(
cell = mapToViewCell(
cell = cells[11],
rows = rows,
row = rows[2],
rowIndex = 2,
columns = columns,
column = columns[3],
columnIndex = 3
)
)
@ -621,10 +670,23 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
cells[15].id
)
var ids = listOf(
BlockView.Table.ColumnId(columns[0].id),
BlockView.Table.ColumnId(columns[1].id),
BlockView.Table.ColumnId(columns[3].id)
)
val expectedSimpleTableWidget = ControlPanelState.Toolbar.SimpleTableWidget(
isVisible = true,
tableId = tableId,
columnItems = getSimpleTableWidgetColumn(),
columnItems = listOf(
SimpleTableWidgetItem.Column.Delete(ids),
SimpleTableWidgetItem.Column.Copy(ids),
SimpleTableWidgetItem.Column.Duplicate(ids),
SimpleTableWidgetItem.Column.ClearContents(ids),
SimpleTableWidgetItem.Column.Color(ids),
SimpleTableWidgetItem.Column.Style(ids),
SimpleTableWidgetItem.Column.ResetStyle(ids)
),
selectedCount = 3,
tab = BlockView.Table.Tab.COLUMN
)
@ -651,9 +713,9 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
clicked = ListenerType.TableTextCell(
cell = mapToViewCell(
cell = cells[15],
rows = rows,
row = rows[3],
rowIndex = 3,
columns = columns,
column = columns[3],
columnIndex = 3
)
)
@ -663,9 +725,9 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
clicked = ListenerType.TableTextCell(
cell = mapToViewCell(
cell = cells[0],
rows = rows,
row = rows[0],
rowIndex = 0,
columns = columns,
column = columns[0],
columnIndex = 0
)
)
@ -675,9 +737,9 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
clicked = ListenerType.TableTextCell(
cell = mapToViewCell(
cell = cells[2],
rows = rows,
row = rows[0],
rowIndex = 0,
columns = columns,
column = columns[2],
columnIndex = 2
)
)
@ -711,10 +773,23 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
cells[14].id
)
ids = listOf(
BlockView.Table.ColumnId(columns[1].id),
BlockView.Table.ColumnId(columns[2].id)
)
val expectedSimpleTableWidget1 = ControlPanelState.Toolbar.SimpleTableWidget(
isVisible = true,
tableId = tableId,
columnItems = getSimpleTableWidgetColumn(),
columnItems = listOf(
SimpleTableWidgetItem.Column.Delete(ids),
SimpleTableWidgetItem.Column.Copy(ids),
SimpleTableWidgetItem.Column.Duplicate(ids),
SimpleTableWidgetItem.Column.ClearContents(ids),
SimpleTableWidgetItem.Column.Color(ids),
SimpleTableWidgetItem.Column.Style(ids),
SimpleTableWidgetItem.Column.ResetStyle(ids)
),
selectedCount = 2,
tab = BlockView.Table.Tab.COLUMN
)
@ -775,10 +850,24 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
cells[10].id
)
var idsRow = listOf(
BlockView.Table.RowId(rows[0].id),
BlockView.Table.RowId(rows[3].id),
BlockView.Table.RowId(rows[2].id)
)
val expectedSimpleTableWidget2 = ControlPanelState.Toolbar.SimpleTableWidget(
isVisible = true,
tableId = tableId,
rowItems = getSimpleTableWidgetRow(),
rowItems = listOf(
SimpleTableWidgetItem.Row.Delete(idsRow),
SimpleTableWidgetItem.Row.Copy(idsRow),
SimpleTableWidgetItem.Row.Duplicate(idsRow),
SimpleTableWidgetItem.Row.ClearContents(idsRow),
SimpleTableWidgetItem.Row.Color(idsRow),
SimpleTableWidgetItem.Row.Style(idsRow),
SimpleTableWidgetItem.Row.ResetStyle(idsRow)
),
selectedCount = 3,
tab = BlockView.Table.Tab.ROW
)
@ -805,9 +894,9 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
clicked = ListenerType.TableTextCell(
cell = mapToViewCell(
cell = cells[12],
rows = rows,
row = rows[3],
rowIndex = 3,
columns = columns,
column = columns[0],
columnIndex = 0
)
)
@ -817,9 +906,9 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
clicked = ListenerType.TableTextCell(
cell = mapToViewCell(
cell = cells[10],
rows = rows,
row = rows[2],
rowIndex = 2,
columns = columns,
column = columns[2],
columnIndex = 2
)
)
@ -844,10 +933,24 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
cells[2].id,
cells[3].id
)
idsRow = listOf(BlockView.Table.RowId(rows[0].id))
val expectedSimpleTableWidget3 = ControlPanelState.Toolbar.SimpleTableWidget(
isVisible = true,
tableId = tableId,
rowItems = getSimpleTableWidgetRow(),
rowItems = listOf(
SimpleTableWidgetItem.Row.InsertAbove(BlockView.Table.RowId(rows[0].id)),
SimpleTableWidgetItem.Row.InsertBelow(BlockView.Table.RowId(rows[0].id)),
SimpleTableWidgetItem.Row.MoveDown(BlockView.Table.RowId(rows[0].id)),
SimpleTableWidgetItem.Row.Delete(idsRow),
SimpleTableWidgetItem.Row.Copy(idsRow),
SimpleTableWidgetItem.Row.Duplicate(idsRow),
SimpleTableWidgetItem.Row.ClearContents(idsRow),
SimpleTableWidgetItem.Row.Color(idsRow),
SimpleTableWidgetItem.Row.Style(idsRow),
SimpleTableWidgetItem.Row.ResetStyle(idsRow)
),
selectedCount = 1,
tab = BlockView.Table.Tab.ROW
)
@ -892,7 +995,12 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
val expectedSimpleTableWidget4 = ControlPanelState.Toolbar.SimpleTableWidget(
isVisible = true,
tableId = tableId,
cellItems = getSimpleTableWidgetItems(),
cellItems = listOf(
SimpleTableWidgetItem.Cell.ClearContents,
SimpleTableWidgetItem.Cell.Color,
SimpleTableWidgetItem.Cell.Style,
SimpleTableWidgetItem.Cell.ResetStyle
),
selectedCount = 3,
tab = BlockView.Table.Tab.CELL
)
@ -912,18 +1020,341 @@ class EditorTableBlockTest : EditorPresentationTestSetup() {
)
}
/**
* Выделена 1 колонка, стоит на позиции 0
*/
@Test
fun `when selected one column and column index is zero - should have proper menu items`() {
//SETUP
val columns = StubTableColumns(size = 3)
val rows = StubTableRows(size = 2)
val cells = StubTableCells(columns = columns, rows = rows)
val columnLayout = StubLayoutColumns(children = columns.map { it.id })
val rowLayout = StubLayoutRows(children = rows.map { it.id })
val table = StubTable(id = tableId, children = listOf(columnLayout.id, rowLayout.id))
val title = StubTitle()
val header = StubHeader(children = listOf(title.id))
val page = StubSmartBlock(id = root, children = listOf(header.id, table.id))
val document =
listOf(page, header, title, table, columnLayout, rowLayout) + columns + rows + cells
stubInterceptEvents()
stubOpenDocument(document)
//TESTING Focus Cell[0] - Enter Table Mode - Click Tab COLUMN
val vm = buildViewModel()
vm.apply {
onStart(root)
onBlockFocusChanged(
id = cells[0].id,
hasFocus = true
)
onBlockToolbarBlockActionsClicked()
onBlockFocusChanged(
id = cells[0].id,
hasFocus = false
)
onSimpleTableWidgetItemClicked(
item = SimpleTableWidgetItem.Tab.Column
)
}
//EXPECTED
var expectedMode = Editor.Mode.Table(
tableId = table.id,
initialTargets = setOf(cells[0].id),
targets = setOf(
cells[0].id,
cells[3].id
),
tab = BlockView.Table.Tab.COLUMN
)
var expectedSelectedState = listOf(
cells[0].id,
cells[3].id
)
var id = BlockView.Table.ColumnId(columns[0].id)
var ids = listOf(id)
var expectedItems = listOf(
SimpleTableWidgetItem.Column.InsertLeft(id),
SimpleTableWidgetItem.Column.InsertRight(id),
SimpleTableWidgetItem.Column.MoveRight(id),
SimpleTableWidgetItem.Column.Delete(ids),
SimpleTableWidgetItem.Column.Copy(ids),
SimpleTableWidgetItem.Column.Duplicate(ids),
SimpleTableWidgetItem.Column.ClearContents(ids),
SimpleTableWidgetItem.Column.Color(ids),
SimpleTableWidgetItem.Column.Style(ids),
SimpleTableWidgetItem.Column.ResetStyle(ids)
)
var expectedSimpleTableWidget = ControlPanelState.Toolbar.SimpleTableWidget(
isVisible = true,
tableId = tableId,
columnItems = expectedItems,
selectedCount = 1,
tab = BlockView.Table.Tab.COLUMN
)
//ASSERT
assertEquals(
expected = expectedSelectedState,
actual = vm.currentSelection().toList()
)
assertEquals(
expected = expectedMode,
actual = vm.mode as Editor.Mode.Table
)
assertEquals(
expected = expectedSimpleTableWidget,
actual = vm.controlPanelViewState.value?.simpleTableWidget
)
//TESTING Click Cell[1](select Column 1) - Click Cell[0](unselect Column 0)
vm.apply {
onClickListener(
clicked = ListenerType.TableTextCell(
cell = mapToViewCell(
cell = cells[1],
row = rows[0],
rowIndex = 0,
column = columns[1],
columnIndex = 1
)
)
)
onClickListener(
clicked = ListenerType.TableTextCell(
cell = mapToViewCell(
cell = cells[0],
row = rows[0],
rowIndex = 0,
column = columns[0],
columnIndex = 0
)
)
)
}
//EXPECTED
expectedMode = Editor.Mode.Table(
tableId = table.id,
initialTargets = setOf(cells[0].id),
targets = setOf(
cells[1].id,
cells[4].id
),
tab = BlockView.Table.Tab.COLUMN
)
expectedSelectedState = listOf(
cells[1].id,
cells[4].id
)
id = BlockView.Table.ColumnId(columns[1].id)
ids = listOf(id)
expectedItems = listOf(
SimpleTableWidgetItem.Column.InsertLeft(id),
SimpleTableWidgetItem.Column.InsertRight(id),
SimpleTableWidgetItem.Column.MoveLeft(id),
SimpleTableWidgetItem.Column.MoveRight(id),
SimpleTableWidgetItem.Column.Delete(ids),
SimpleTableWidgetItem.Column.Copy(ids),
SimpleTableWidgetItem.Column.Duplicate(ids),
SimpleTableWidgetItem.Column.ClearContents(ids),
SimpleTableWidgetItem.Column.Color(ids),
SimpleTableWidgetItem.Column.Style(ids),
SimpleTableWidgetItem.Column.ResetStyle(ids)
)
expectedSimpleTableWidget = ControlPanelState.Toolbar.SimpleTableWidget(
isVisible = true,
tableId = tableId,
columnItems = expectedItems,
selectedCount = 1,
tab = BlockView.Table.Tab.COLUMN
)
//ASSERT
assertEquals(
expected = expectedSelectedState,
actual = vm.currentSelection().toList()
)
assertEquals(
expected = expectedMode,
actual = vm.mode as Editor.Mode.Table
)
assertEquals(
expected = expectedSimpleTableWidget,
actual = vm.controlPanelViewState.value?.simpleTableWidget
)
//TESTING Click Cell[2](select Column 2) - Click Cell[1](unselect Column 1)
vm.apply {
onClickListener(
clicked = ListenerType.TableTextCell(
cell = mapToViewCell(
cell = cells[2],
row = rows[0],
rowIndex = 0,
column = columns[2],
columnIndex = 2
)
)
)
onClickListener(
clicked = ListenerType.TableTextCell(
cell = mapToViewCell(
cell = cells[1],
row = rows[0],
rowIndex = 0,
column = columns[1],
columnIndex = 1
)
)
)
}
//EXPECTED
expectedMode = Editor.Mode.Table(
tableId = table.id,
initialTargets = setOf(cells[0].id),
targets = setOf(
cells[2].id,
cells[5].id
),
tab = BlockView.Table.Tab.COLUMN
)
expectedSelectedState = listOf(
cells[2].id,
cells[5].id
)
id = BlockView.Table.ColumnId(columns[2].id)
ids = listOf(id)
expectedItems = listOf(
SimpleTableWidgetItem.Column.InsertLeft(id),
SimpleTableWidgetItem.Column.InsertRight(id),
SimpleTableWidgetItem.Column.MoveLeft(id),
SimpleTableWidgetItem.Column.Delete(ids),
SimpleTableWidgetItem.Column.Copy(ids),
SimpleTableWidgetItem.Column.Duplicate(ids),
SimpleTableWidgetItem.Column.ClearContents(ids),
SimpleTableWidgetItem.Column.Color(ids),
SimpleTableWidgetItem.Column.Style(ids),
SimpleTableWidgetItem.Column.ResetStyle(ids)
)
expectedSimpleTableWidget = ControlPanelState.Toolbar.SimpleTableWidget(
isVisible = true,
tableId = tableId,
columnItems = expectedItems,
selectedCount = 1,
tab = BlockView.Table.Tab.COLUMN
)
//ASSERT
assertEquals(
expected = expectedSelectedState,
actual = vm.currentSelection().toList()
)
assertEquals(
expected = expectedMode,
actual = vm.mode as Editor.Mode.Table
)
assertEquals(
expected = expectedSimpleTableWidget,
actual = vm.controlPanelViewState.value?.simpleTableWidget
)
//TESTING Click Cell[0](select Column 0)
vm.apply {
onClickListener(
clicked = ListenerType.TableTextCell(
cell = mapToViewCell(
cell = cells[0],
row = rows[0],
rowIndex = 0,
column = columns[0],
columnIndex = 0
)
)
)
}
//EXPECTED
expectedMode = Editor.Mode.Table(
tableId = table.id,
initialTargets = setOf(cells[0].id),
targets = setOf(
cells[2].id,
cells[5].id,
cells[0].id,
cells[3].id
),
tab = BlockView.Table.Tab.COLUMN
)
expectedSelectedState = listOf(
cells[0].id,
cells[3].id,
cells[2].id,
cells[5].id
)
ids =
listOf(BlockView.Table.ColumnId(columns[0].id), BlockView.Table.ColumnId(columns[2].id))
expectedItems = listOf(
SimpleTableWidgetItem.Column.Delete(ids),
SimpleTableWidgetItem.Column.Copy(ids),
SimpleTableWidgetItem.Column.Duplicate(ids),
SimpleTableWidgetItem.Column.ClearContents(ids),
SimpleTableWidgetItem.Column.Color(ids),
SimpleTableWidgetItem.Column.Style(ids),
SimpleTableWidgetItem.Column.ResetStyle(ids)
)
expectedSimpleTableWidget = ControlPanelState.Toolbar.SimpleTableWidget(
isVisible = true,
tableId = tableId,
columnItems = expectedItems,
selectedCount = 2,
tab = BlockView.Table.Tab.COLUMN
)
//ASSERT
assertEquals(
expected = expectedSelectedState,
actual = vm.currentSelection().toList()
)
assertEquals(
expected = expectedMode,
actual = vm.mode as Editor.Mode.Table
)
assertEquals(
expected = expectedSimpleTableWidget,
actual = vm.controlPanelViewState.value?.simpleTableWidget
)
}
private fun mapToViewCell(
cell: Block,
rows: List<Block>,
row: Block,
rowIndex: Int,
columns: List<Block>,
column: Block,
columnIndex: Int
): BlockView.Table.Cell {
return BlockView.Table.Cell(
rowId = rows[rowIndex].id,
columnId = columns[columnIndex].id,
rowIndex = BlockView.Table.RowIndex(rowIndex),
columnIndex = BlockView.Table.ColumnIndex(columnIndex),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(row.id),
index = BlockView.Table.RowIndex(rowIndex),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(column.id),
index = BlockView.Table.ColumnIndex(columnIndex)
),
block = BlockView.Text.Paragraph(
id = cell.id,
text = cell.content.asText().text

View file

@ -196,24 +196,40 @@ class TableBlockRendererTest {
cells.add(
BlockView.Table.Cell(
block = p,
rowId = row.id,
columnId = column.id,
rowIndex = BlockView.Table.RowIndex(rowIndex),
columnIndex = BlockView.Table.ColumnIndex(columnIndex),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(row.id),
index = BlockView.Table.RowIndex(rowIndex),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(column.id),
index = BlockView.Table.ColumnIndex(columnIndex)
),
tableId = table.id
)
)
}
}
val columnViews = mutableListOf<BlockView.Table.ColumnId>()
columns.forEach { column ->
columnViews.add(BlockView.Table.ColumnId(value = column.id))
val columnViews = mutableListOf<BlockView.Table.Column>()
columns.forEachIndexed { index, column ->
columnViews.add(
BlockView.Table.Column(
id = BlockView.Table.ColumnId(column.id),
index = BlockView.Table.ColumnIndex(index)
)
)
}
val rowViews = mutableListOf<BlockView.Table.RowId>()
rows.forEach { row ->
rowViews.add(BlockView.Table.RowId(value = row.id))
val rowViews = mutableListOf<BlockView.Table.Row>()
rows.forEachIndexed { index, row ->
rowViews.add(
BlockView.Table.Row(
id = BlockView.Table.RowId(value = row.id),
index = BlockView.Table.RowIndex(value = index),
isHeader = false
)
)
}
val expected = listOf(
@ -348,10 +364,15 @@ class TableBlockRendererTest {
rows.forEachIndexed { rowIndex, row ->
cells.add(
BlockView.Table.Cell(
rowId = row.id,
columnId = column.id,
rowIndex = BlockView.Table.RowIndex(rowIndex),
columnIndex = BlockView.Table.ColumnIndex(columnIndex),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(row.id),
index = BlockView.Table.RowIndex(rowIndex),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(column.id),
index = BlockView.Table.ColumnIndex(columnIndex)
),
block = null,
tableId = table.id
)
@ -359,14 +380,25 @@ class TableBlockRendererTest {
}
}
val columnViews = mutableListOf<BlockView.Table.ColumnId>()
columns.forEach { column ->
columnViews.add(BlockView.Table.ColumnId(value = column.id))
val columnViews = mutableListOf<BlockView.Table.Column>()
columns.forEachIndexed { index, column ->
columnViews.add(
BlockView.Table.Column(
id = BlockView.Table.ColumnId(column.id),
index = BlockView.Table.ColumnIndex(index)
)
)
}
val rowViews = mutableListOf<BlockView.Table.RowId>()
rows.forEach { row ->
rowViews.add(BlockView.Table.RowId(value = row.id))
val rowViews = mutableListOf<BlockView.Table.Row>()
rows.forEachIndexed { index, row ->
rowViews.add(
BlockView.Table.Row(
id = BlockView.Table.RowId(value = row.id),
index = BlockView.Table.RowIndex(value = index),
isHeader = false
)
)
}
val expected = listOf(
@ -518,126 +550,197 @@ class TableBlockRendererTest {
val cells =
listOf(
BlockView.Table.Cell(
rowId = rowId1,
columnId = columnId1,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(0),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(0)
),
block = null,
tableId = table.id
),
BlockView.Table.Cell(
rowId = rowId2,
columnId = columnId1,
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(0)
),
block = BlockView.Text.Paragraph(
id = row2Block1.id,
text = row2Block1.content.asText().text
),
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(0),
tableId = table.id
),
BlockView.Table.Cell(
rowId = rowId3,
columnId = columnId1,
rowIndex = BlockView.Table.RowIndex(2),
columnIndex = BlockView.Table.ColumnIndex(0),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId3),
index = BlockView.Table.RowIndex(2),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId1),
index = BlockView.Table.ColumnIndex(0)
),
block = null,
tableId = table.id
), //column1
BlockView.Table.Cell(
rowId = rowId1,
columnId = columnId2,
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(1)
),
block = BlockView.Text.Paragraph(
id = row1Block1.id,
text = row1Block1.content.asText().text
),
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(1),
tableId = table.id
),
BlockView.Table.Cell(
rowId = rowId2,
columnId = columnId2,
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(1)
),
block = BlockView.Text.Paragraph(
id = row2Block2.id,
text = row2Block2.content.asText().text
),
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(1),
tableId = table.id
),
BlockView.Table.Cell(
rowId = rowId3,
columnId = columnId2,
rowIndex = BlockView.Table.RowIndex(2),
columnIndex = BlockView.Table.ColumnIndex(1),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId3),
index = BlockView.Table.RowIndex(2),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId2),
index = BlockView.Table.ColumnIndex(1)
),
block = null,
tableId = table.id
),//column2
BlockView.Table.Cell(
rowId = rowId1,
columnId = columnId3,
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId3),
index = BlockView.Table.ColumnIndex(2)
),
block = null,
tableId = table.id
),
BlockView.Table.Cell(
rowId = rowId2,
columnId = columnId3,
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId3),
index = BlockView.Table.ColumnIndex(2)
),
block = null,
tableId = table.id
),
BlockView.Table.Cell(
rowId = rowId3,
columnId = columnId3,
rowIndex = BlockView.Table.RowIndex(2),
columnIndex = BlockView.Table.ColumnIndex(2),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId3),
index = BlockView.Table.RowIndex(2),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId3),
index = BlockView.Table.ColumnIndex(2)
),
block = null,
tableId = table.id
),//column3
BlockView.Table.Cell(
rowId = rowId1,
columnId = columnId4,
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId1),
index = BlockView.Table.RowIndex(0),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId4),
index = BlockView.Table.ColumnIndex(3)
),
block = BlockView.Text.Paragraph(
id = row1Block2.id,
text = row1Block2.content.asText().text
),
rowIndex = BlockView.Table.RowIndex(0),
columnIndex = BlockView.Table.ColumnIndex(3),
tableId = table.id
),
BlockView.Table.Cell(
rowId = rowId2,
columnId = columnId4,
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId2),
index = BlockView.Table.RowIndex(1),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId4),
index = BlockView.Table.ColumnIndex(3)
),
block = BlockView.Text.Paragraph(
id = row2Block3.id,
text = row2Block3.content.asText().text
),
rowIndex = BlockView.Table.RowIndex(1),
columnIndex = BlockView.Table.ColumnIndex(3),
tableId = table.id
),
BlockView.Table.Cell(
rowId = rowId3,
columnId = columnId4,
rowIndex = BlockView.Table.RowIndex(2),
columnIndex = BlockView.Table.ColumnIndex(3),
row = BlockView.Table.Row(
id = BlockView.Table.RowId(rowId3),
index = BlockView.Table.RowIndex(2),
isHeader = false
),
column = BlockView.Table.Column(
id = BlockView.Table.ColumnId(columnId4),
index = BlockView.Table.ColumnIndex(3)
),
block = null,
tableId = table.id
)
)
val columnViews = mutableListOf<BlockView.Table.ColumnId>()
columns.forEach { column ->
columnViews.add(BlockView.Table.ColumnId(value = column.id))
val columnViews = mutableListOf<BlockView.Table.Column>()
columns.forEachIndexed { index, column ->
columnViews.add(
BlockView.Table.Column(
id = BlockView.Table.ColumnId(column.id),
index = BlockView.Table.ColumnIndex(index)
)
)
}
val rowViews = mutableListOf<BlockView.Table.RowId>()
rows.forEach { row ->
rowViews.add(BlockView.Table.RowId(value = row.id))
val rowViews = mutableListOf<BlockView.Table.Row>()
rows.forEachIndexed { index, row ->
rowViews.add(
BlockView.Table.Row(
id = BlockView.Table.RowId(value = row.id),
index = BlockView.Table.RowIndex(value = index),
isHeader = false
)
)
}
val expected = listOf(