phosphorjs / phosphor

The PhosphorJS Library
BSD 3-Clause "New" or "Revised" License
1.04k stars 166 forks source link

[WIP] Cell Editing #444

Open mbektas opened 4 years ago

mbektas commented 4 years ago

Hi @sccolbert (cc. @jasongrout, @blink1073, @afshin, @ellisonbg, @SylvainCorlay) I have been working on adding editing capabilities to DataGrid and trying to have a flexible design so that it is possibly something that can be merged to upstream and useful for everyone. It is still a work in progress and I would appreciate any feedback.

In a short summary, it adds a new DataModel (MutableDataModel), ICellEditorController interface with a concrete implementation and ICellEditor interface with several editor implementations and ICellInputValidator interface with concrete implementations for some types. I also added cursor movement using Tab & Enter keys within body or confined to selections when there are any.

Editing is possible if data model is of type MutableDataModel and there is a selection model. It is triggered using double click or typing. Editing can also be triggered programmatically, optionally with a custom editor and validator. Editor type to use is inferred from metadata if the metadata follows the schema defined in https://frictionlessdata.io/specs/table-schema/, otherwise if cell data is a primitive type TextCellEditor is used.

Cell editors to used can be set/overridden based on cell data type or metadata key-value pair match.

DataGrid example is modified to present most of the editing features including a custom cell editor.

CellEditing

Some Documentation to help with PR

Cursor movement

Deleting Cell values (setting to null) using Delete key

MutableDataModel which defines new method setData

Cell Editor

TextCellEditor

NumberCellEditor

IntegerCellEditor

BooleanCellEditor

DateCellEditor

OptionCellEditor

DynamicOptionCellEditor

Editor Controller

Validators

TextInputValidator

NumberInputValidator

IntegerInputValidator

sccolbert commented 4 years ago

Thanks @mbektasbbg! I just wanted to comment and say this looks awesome at first glance. I'll give it a more in-depth review with comments in the the immediate future :)

jasongrout commented 4 years ago

I also sat down with Mehmet and we discussed some code style things as well as tested and found some behavior bugs in Firefox/Safari, which he took notes on.

Mehmet also mentioned he views this as an initial WIP implementation, and he has some design questions and wants to consider the implementation and design as definitely open for discussion.

jasongrout commented 4 years ago

And I'll add, @mbektasbbg, that I'm also really excited about this!