2828 SelectionModes ,
2929 as_cell_selection ,
3030 assert_patches_shape ,
31- wrap_shiny_html ,
3231)
32+ from ._data_frame_utils ._html import maybe_as_cell_html
3333from ._data_frame_utils ._styles import as_browser_style_infos
3434from ._data_frame_utils ._tbl_data import (
3535 apply_frame_patches__typed ,
@@ -195,7 +195,7 @@ class data_frame(Renderer[DataFrameResult[DataFrameLikeT]]):
195195 patches with updated values.
196196 """
197197
198- _cell_patch_map : reactive .Value [dict [tuple [int , int ], CellPatchProcessed ]]
198+ _cell_patch_map : reactive .Value [dict [tuple [int , int ], CellPatch ]]
199199 """
200200 Reactive dictionary of patches to be applied to the data frame.
201201
@@ -204,7 +204,7 @@ class data_frame(Renderer[DataFrameResult[DataFrameLikeT]]):
204204
205205 The key is defined as `(row_index, column_index)`.
206206 """
207- cell_patches : reactive .Calc_ [list [CellPatchProcessed ]]
207+ cell_patches : reactive .Calc_ [list [CellPatch ]]
208208 """
209209 Reactive value of the data frame's edits provided by the user.
210210 """
@@ -349,7 +349,7 @@ def _init_reactives(self) -> None:
349349 self ._cell_patch_map = reactive .Value ({})
350350
351351 @reactive .calc
352- def self_cell_patches () -> list [CellPatchProcessed ]:
352+ def self_cell_patches () -> list [CellPatch ]:
353353 return list (self ._cell_patch_map ().values ())
354354
355355 self .cell_patches = self_cell_patches
@@ -537,8 +537,8 @@ async def patch_fn(
537537
538538 async def patches_fn (
539539 * ,
540- patches : list [CellPatch ],
541- ):
540+ patches : tuple [CellPatch , ... ],
541+ ) -> ListOrTuple [ CellPatch ] :
542542 ret_patches : list [CellPatch ] = []
543543 for patch in patches :
544544
@@ -583,7 +583,7 @@ def _set_patches_handler(self) -> str:
583583 return self ._set_patches_handler_impl (self ._patches_handler )
584584
585585 # Do not change this method name unless you update corresponding code in `/js/dataframe/`!!
586- async def _patches_handler (self , patches : list [CellPatch ]) -> Jsonifiable :
586+ async def _patches_handler (self , patches : tuple [CellPatch , ... ]) -> Jsonifiable :
587587 """
588588 Accepts edit patches requests from the client and returns the processed patches.
589589
@@ -602,7 +602,8 @@ async def _patches_handler(self, patches: list[CellPatch]) -> Jsonifiable:
602602
603603 with session_context (self ._get_session ()):
604604 # Call user's cell update method to retrieve formatted values
605- patches = await self ._patches_fn (patches = patches )
605+ val = await self ._patches_fn (patches = patches )
606+ patches = tuple (val )
606607
607608 # Check to make sure `updated_infos` is a list of dicts with the correct keys
608609 bad_patches_format = not isinstance (patches , list )
@@ -625,29 +626,45 @@ async def _patches_handler(self, patches: list[CellPatch]) -> Jsonifiable:
625626 )
626627
627628 # Add (or overwrite) new cell patches by setting each patch into the cell patch map
628- processed_patches : list [Jsonifiable ] = []
629629 for patch in patches :
630- processed_patch = self ._set_cell_patch_map_value (
630+ self ._set_cell_patch_map_value (
631631 value = patch ["value" ],
632632 row_index = patch ["row_index" ],
633633 column_index = patch ["column_index" ],
634634 )
635- processed_patches .append (
636- cell_patch_processed_to_jsonifiable (processed_patch )
637- )
635+
636+ # Upgrade any HTML-like content to `CellHtml` json objects
637+ processed_patches : list [CellPatchProcessed ] = [
638+ {
639+ "row_index" : patch ["row_index" ],
640+ "column_index" : patch ["column_index" ],
641+ # Only upgrade the value if it is necessary
642+ "value" : maybe_as_cell_html (
643+ patch ["value" ],
644+ session = self ._get_session (),
645+ ),
646+ }
647+ for patch in patches
648+ ]
649+
650+ # Prep the processed patches for sending to the client
651+ jsonifiable_patches : list [Jsonifiable ] = [
652+ cell_patch_processed_to_jsonifiable (ret_processed_patch )
653+ for ret_processed_patch in processed_patches
654+ ]
638655
639656 await self ._attempt_update_cell_style ()
640657
641658 # Return the processed patches to the client
642- return processed_patches
659+ return jsonifiable_patches
643660
644661 def _set_cell_patch_map_value (
645662 self ,
646663 value : CellValue ,
647664 * ,
648665 row_index : int ,
649666 column_index : int ,
650- ) -> CellPatchProcessed :
667+ ):
651668 """
652669 Set the value within the cell patch map.
653670
@@ -671,18 +688,16 @@ def _set_cell_patch_map_value(
671688 # TODO-barret-render.data_frame; The `value` should be coerced by pandas to the correct type
672689 # TODO-barret; See https://pandas.pydata.org/pandas-docs/stable/user_guide/basics.html#object-conversion
673690
674- cell_patch_processed : CellPatchProcessed = {
691+ cell_patch : CellPatch = {
675692 "row_index" : row_index ,
676693 "column_index" : column_index ,
677- "value" : wrap_shiny_html ( value , session = self . _get_session ()) ,
694+ "value" : value ,
678695 }
679696 # Use copy to set the new value
680697 cell_patch_map = self ._cell_patch_map ().copy ()
681- cell_patch_map [(row_index , column_index )] = cell_patch_processed
698+ cell_patch_map [(row_index , column_index )] = cell_patch
682699 self ._cell_patch_map .set (cell_patch_map )
683700
684- return cell_patch_processed
685-
686701 async def _attempt_update_cell_style (self ) -> None :
687702 with session_context (self ._get_session ()):
688703
@@ -704,7 +719,7 @@ async def _attempt_update_cell_style(self) -> None:
704719 # TODO-barret-render.data_frame; Add `update_cell_value()` method
705720 # def _update_cell_value(
706721 # self, value: CellValue, *, row_index: int, column_index: int
707- # ) -> CellPatchProcessed :
722+ # ) -> CellPatch :
708723 # """
709724 # Update the value of a cell in the data frame.
710725 #
0 commit comments