reflex-components-dataeditor 0.9.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,24 @@
1
+ **/.DS_Store
2
+ **/*.pyc
3
+ assets/external/*
4
+ dist/*
5
+ examples/
6
+ .web
7
+ .states
8
+ .idea
9
+ .vscode
10
+ .coverage
11
+ .coverage.*
12
+ .venv
13
+ venv
14
+ requirements.txt
15
+ .pyi_generator_last_run
16
+ .pyi_generator_diff
17
+ reflex.db
18
+ .codspeed
19
+ .env
20
+ .env.*
21
+ node_modules
22
+ package-lock.json
23
+ *.pyi
24
+ .pre-commit-config.yaml
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 2.4
2
+ Name: reflex-components-dataeditor
3
+ Version: 0.9.0
4
+ Summary: Reflex dataeditor components.
5
+ Author-email: Khaleel Al-Adhami <khaleel@reflex.dev>
6
+ Maintainer-email: Khaleel Al-Adhami <khaleel@reflex.dev>
7
+ Requires-Python: >=3.10
8
+ Requires-Dist: reflex-components-core
9
+ Description-Content-Type: text/markdown
10
+
11
+ # reflex-components-dataeditor
12
+
13
+ Reflex dataeditor components.
@@ -0,0 +1,3 @@
1
+ # reflex-components-dataeditor
2
+
3
+ Reflex dataeditor components.
@@ -0,0 +1,33 @@
1
+ [project]
2
+ name = "reflex-components-dataeditor"
3
+ dynamic = ["version"]
4
+ description = "Reflex dataeditor components."
5
+ readme = "README.md"
6
+ authors = [{ name = "Khaleel Al-Adhami", email = "khaleel@reflex.dev" }]
7
+ maintainers = [{ name = "Khaleel Al-Adhami", email = "khaleel@reflex.dev" }]
8
+ requires-python = ">=3.10"
9
+ dependencies = ["reflex-components-core"]
10
+
11
+ [tool.hatch.version]
12
+ source = "uv-dynamic-versioning"
13
+
14
+ [tool.uv-dynamic-versioning]
15
+ pattern-prefix = "reflex-components-dataeditor-"
16
+ fallback-version = "0.0.0dev0"
17
+
18
+ [tool.hatch.build]
19
+ targets.sdist.artifacts = ["*.pyi"]
20
+ targets.wheel.artifacts = ["*.pyi"]
21
+
22
+ [tool.hatch.build.hooks.reflex-pyi]
23
+ dependencies = [
24
+ "ruff",
25
+ "reflex-base",
26
+ "reflex-components-core",
27
+ "reflex-components-lucide",
28
+ "reflex-components-sonner",
29
+ ]
30
+
31
+ [build-system]
32
+ requires = ["hatchling", "uv-dynamic-versioning", "hatch-reflex-pyi"]
33
+ build-backend = "hatchling.build"
@@ -0,0 +1 @@
1
+ """Reflex DataEditor component."""
@@ -0,0 +1,614 @@
1
+ """Data Editor component from glide-data-grid."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import dataclasses
6
+ from collections.abc import Mapping, Sequence
7
+ from enum import Enum
8
+ from typing import Any, Literal, TypedDict
9
+
10
+ from reflex_base.components.component import Component, NoSSRComponent, field
11
+ from reflex_base.components.literals import LiteralRowMarker
12
+ from reflex_base.event import EventHandler, no_args_event_spec, passthrough_event_spec
13
+ from reflex_base.utils import console, format, types
14
+ from reflex_base.utils.imports import ImportDict, ImportVar
15
+ from reflex_base.utils.serializers import serializer
16
+ from reflex_base.vars import get_unique_variable_name
17
+ from reflex_base.vars.base import Var, VarData
18
+ from reflex_base.vars.function import FunctionStringVar
19
+ from reflex_base.vars.sequence import ArrayVar
20
+
21
+
22
+ # TODO: Fix the serialization issue for custom types.
23
+ class GridColumnIcons(Enum):
24
+ """An Enum for the available icons in DataEditor."""
25
+
26
+ Array = "array"
27
+ AudioUri = "audio_uri"
28
+ Boolean = "boolean"
29
+ HeaderCode = "code"
30
+ Date = "date"
31
+ Email = "email"
32
+ Emoji = "emoji"
33
+ GeoDistance = "geo_distance"
34
+ IfThenElse = "if_then_else"
35
+ Image = "image"
36
+ JoinStrings = "join_strings"
37
+ Lookup = "lookup"
38
+ Markdown = "markdown"
39
+ Math = "math"
40
+ Number = "number"
41
+ Phone = "phone"
42
+ Reference = "reference"
43
+ Rollup = "rollup"
44
+ RowID = "row_id"
45
+ SingleValue = "single_value"
46
+ SplitString = "split_string"
47
+ String = "string"
48
+ TextTemplate = "text_template"
49
+ Time = "time"
50
+ Uri = "uri"
51
+ VideoUri = "video_uri"
52
+
53
+
54
+ @dataclasses.dataclass
55
+ class DataEditorThemeBase:
56
+ """The theme for the DataEditor component."""
57
+
58
+ accent_color: str | None = None
59
+ accent_fg: str | None = None
60
+ accent_light: str | None = None
61
+ base_font_style: str | None = None
62
+ bg_bubble: str | None = None
63
+ bg_bubble_selected: str | None = None
64
+ bg_cell: str | None = None
65
+ bg_cell_medium: str | None = None
66
+ bg_header: str | None = None
67
+ bg_header_has_focus: str | None = None
68
+ bg_header_hovered: str | None = None
69
+ bg_icon_header: str | None = None
70
+ bg_search_result: str | None = None
71
+ border_color: str | None = None
72
+ cell_horizontal_padding: int | None = None
73
+ cell_vertical_padding: int | None = None
74
+ drilldown_border: str | None = None
75
+ editor_font_size: str | None = None
76
+ fg_icon_header: str | None = None
77
+ font_family: str | None = None
78
+ header_bottom_border_color: str | None = None
79
+ header_font_style: str | None = None
80
+ horizontal_border_color: str | None = None
81
+ line_height: int | None = None
82
+ link_color: str | None = None
83
+ text_bubble: str | None = None
84
+ text_dark: str | None = None
85
+ text_group_header: str | None = None
86
+ text_header: str | None = None
87
+ text_header_selected: str | None = None
88
+ text_light: str | None = None
89
+ text_medium: str | None = None
90
+
91
+
92
+ @dataclasses.dataclass(init=False)
93
+ class DataEditorTheme(DataEditorThemeBase):
94
+ """The theme for the DataEditor component."""
95
+
96
+ def __init__(self, **kwargs: Any):
97
+ """Initialize the DataEditorTheme.
98
+
99
+ Args:
100
+ **kwargs: The keyword arguments to initialize the theme.
101
+ """
102
+ kwargs = {format.to_snake_case(k): v for k, v in kwargs.items()}
103
+ super().__init__(**kwargs)
104
+
105
+
106
+ class Bounds(TypedDict):
107
+ """The bounds of the group header."""
108
+
109
+ x: int
110
+ y: int
111
+ width: int
112
+ height: int
113
+
114
+
115
+ class CompatSelection(TypedDict):
116
+ """The selection."""
117
+
118
+ items: list
119
+
120
+
121
+ class Rectangle(TypedDict):
122
+ """The bounds of the group header."""
123
+
124
+ x: int
125
+ y: int
126
+ width: int
127
+ height: int
128
+
129
+
130
+ class GridSelectionCurrent(TypedDict):
131
+ """The current selection."""
132
+
133
+ cell: tuple[int, int]
134
+ range: Rectangle
135
+ rangeStack: list[Rectangle]
136
+
137
+
138
+ class GridSelection(TypedDict):
139
+ """The grid selection."""
140
+
141
+ current: GridSelectionCurrent | None
142
+ columns: CompatSelection
143
+ rows: CompatSelection
144
+
145
+
146
+ class GroupHeaderClickedEventArgs(TypedDict):
147
+ """The arguments for the group header clicked event."""
148
+
149
+ kind: str
150
+ group: str
151
+ location: tuple[int, int]
152
+ bounds: Bounds
153
+ isEdge: bool
154
+ shiftKey: bool
155
+ ctrlKey: bool
156
+ metaKey: bool
157
+ isTouch: bool
158
+ localEventX: int
159
+ localEventY: int
160
+ button: int
161
+ buttons: int
162
+ scrollEdge: tuple[int, int]
163
+
164
+
165
+ class GridCell(TypedDict):
166
+ """The grid cell."""
167
+
168
+ span: list[int] | None
169
+
170
+
171
+ class GridColumn(TypedDict):
172
+ """The grid column."""
173
+
174
+ title: str
175
+ group: str | None
176
+
177
+
178
+ class DataEditor(NoSSRComponent):
179
+ """The DataEditor Component."""
180
+
181
+ tag = "DataEditor"
182
+ is_default = True
183
+ library: str | None = "@glideapps/glide-data-grid@6.0.3"
184
+ lib_dependencies: list[str] = [
185
+ "lodash@4.17.23",
186
+ "react-responsive-carousel@3.2.23",
187
+ ]
188
+
189
+ rows: Var[int] = field(doc="Number of rows.")
190
+
191
+ columns: Var[Sequence[dict[str, Any]]] = field(
192
+ doc="Headers of the columns for the data grid."
193
+ )
194
+
195
+ data: Var[Sequence[Sequence[Any]]] = field(doc="The data.")
196
+
197
+ get_cell_content: Var[str] = field(
198
+ doc="The name of the callback used to find the data to display."
199
+ )
200
+
201
+ get_cells_for_selection: Var[bool] = field(doc="Allow selection for copying.")
202
+
203
+ on_paste: Var[bool] = field(doc="Allow paste.")
204
+
205
+ draw_focus_ring: Var[bool] = field(doc="Controls the drawing of the focus ring.")
206
+
207
+ fixed_shadow_x: Var[bool] = field(
208
+ doc="Enables or disables the overlay shadow when scrolling horizontally."
209
+ )
210
+
211
+ fixed_shadow_y: Var[bool] = field(
212
+ doc="Enables or disables the overlay shadow when scrolling vertically."
213
+ )
214
+
215
+ fill_handle: Var[bool] = field(doc="Controls the presence of the fill indicator")
216
+
217
+ freeze_columns: Var[int] = field(
218
+ doc="The number of columns which should remain in place when scrolling horizontally. Doesn't include rowMarkers."
219
+ )
220
+
221
+ group_header_height: Var[int] = field(
222
+ doc="Controls the header of the group header row."
223
+ )
224
+
225
+ header_height: Var[int] = field(doc="Controls the height of the header row.")
226
+
227
+ # Additional header icons:
228
+ # header_icons: Var[Any] # (TODO: must be a map of name: svg) #noqa: ERA001
229
+
230
+ max_column_auto_width: Var[int] = field(
231
+ doc="The maximum width a column can be automatically sized to."
232
+ )
233
+
234
+ max_column_width: Var[int] = field(
235
+ doc="The maximum width a column can be resized to."
236
+ )
237
+
238
+ min_column_width: Var[int] = field(
239
+ doc="The minimum width a column can be resized to."
240
+ )
241
+
242
+ row_height: Var[int] = field(doc="Determines the height of each row.")
243
+
244
+ row_markers: Var[LiteralRowMarker] = field(
245
+ doc='Kind of row markers. Options are: "none", "number", "checkbox", "both", "checkbox-visible", "clickable-number".'
246
+ )
247
+
248
+ row_marker_start_index: Var[int] = field(
249
+ doc="Changes the starting index for row markers."
250
+ )
251
+
252
+ row_marker_width: Var[int] = field(
253
+ doc="Sets the width of row markers in pixels, if unset row markers will automatically size."
254
+ )
255
+
256
+ smooth_scroll_x: Var[bool] = field(doc="Enable horizontal smooth scrolling.")
257
+
258
+ smooth_scroll_y: Var[bool] = field(doc="Enable vertical smooth scrolling.")
259
+
260
+ vertical_border: Var[ # TODO: support a mapping (dict[int, bool])
261
+ bool
262
+ ] = field(
263
+ doc="Controls the drawing of the left hand vertical border of a column. If set to a boolean value it controls all borders."
264
+ )
265
+
266
+ column_select: Var[Literal["none", "single", "multi"]] = field(
267
+ doc='Allow columns selections. ("none", "single", "multi")'
268
+ )
269
+
270
+ range_select: Var[Literal["none", "cell", "rect", "multi-cell", "multi-rect"]] = (
271
+ field(
272
+ doc='Allow range selections. ("none", "cell", "rect", "multi-cell", "multi-rect").'
273
+ )
274
+ )
275
+
276
+ row_select: Var[Literal["none", "single", "multi"]] = field(
277
+ doc='Allow row selections. ("none", "single", "multi").'
278
+ )
279
+
280
+ prevent_diagonal_scrolling: Var[bool] = field(doc="Prevent diagonal scrolling.")
281
+
282
+ overscroll_x: Var[int] = field(
283
+ doc="Allow to scroll past the limit of the actual content on the horizontal axis."
284
+ )
285
+
286
+ overscroll_y: Var[int] = field(
287
+ doc="Allow to scroll past the limit of the actual content on the vertical axis."
288
+ )
289
+
290
+ scroll_offset_x: Var[int] = field(
291
+ doc="Initial scroll offset on the horizontal axis."
292
+ )
293
+
294
+ scroll_offset_y: Var[int] = field(doc="Initial scroll offset on the vertical axis.")
295
+
296
+ range_selection_blending: Var[Literal["exclusive", "mixed"]] = field(
297
+ doc='Controls which types of range selections can exist at the same time. ("exclusive", "mixed").'
298
+ )
299
+
300
+ column_selection_blending: Var[Literal["exclusive", "mixed"]] = field(
301
+ doc='Controls which types of column selections can exist at the same time. ("exclusive", "mixed").'
302
+ )
303
+
304
+ row_selection_blending: Var[Literal["exclusive", "mixed"]] = field(
305
+ doc='Controls which types of row selections can exist at the same time. ("exclusive", "mixed").'
306
+ )
307
+
308
+ row_selection_mode: Var[Literal["auto", "multi"]] = field(
309
+ doc='Controls row marker selection behavior. "auto" adapts to touch/mouse, "multi" acts as if Ctrl is pressed. ("auto", "multi").'
310
+ )
311
+
312
+ span_range_behavior: Var[Literal["default", "allowPartial"]] = field(
313
+ doc='Controls how spans are handled in selections. ("default", "allowPartial").'
314
+ )
315
+
316
+ theme: Var[DataEditorTheme | dict] = field(doc="global theme")
317
+
318
+ on_cell_activated: EventHandler[passthrough_event_spec(tuple[int, int])] = field(
319
+ doc="Fired when a cell is activated."
320
+ )
321
+
322
+ on_cell_clicked: EventHandler[passthrough_event_spec(tuple[int, int])] = field(
323
+ doc="Fired when a cell is clicked."
324
+ )
325
+
326
+ on_cell_context_menu: EventHandler[passthrough_event_spec(tuple[int, int])] = field(
327
+ doc="Fired when a cell is right-clicked."
328
+ )
329
+
330
+ on_cell_edited: EventHandler[passthrough_event_spec(tuple[int, int], GridCell)] = (
331
+ field(doc="Fired when a cell is edited.")
332
+ )
333
+
334
+ on_group_header_clicked: EventHandler[
335
+ passthrough_event_spec(tuple[int, int], GridCell)
336
+ ] = field(doc="Fired when a group header is clicked.")
337
+
338
+ on_group_header_context_menu: EventHandler[
339
+ passthrough_event_spec(int, GroupHeaderClickedEventArgs)
340
+ ] = field(doc="Fired when a group header is right-clicked.")
341
+
342
+ on_group_header_renamed: EventHandler[passthrough_event_spec(str, str)] = field(
343
+ doc="Fired when a group header is renamed."
344
+ )
345
+
346
+ on_header_clicked: EventHandler[passthrough_event_spec(tuple[int, int])] = field(
347
+ doc="Fired when a header is clicked."
348
+ )
349
+
350
+ on_header_context_menu: EventHandler[passthrough_event_spec(tuple[int, int])] = (
351
+ field(doc="Fired when a header is right-clicked.")
352
+ )
353
+
354
+ on_header_menu_click: EventHandler[passthrough_event_spec(int, Rectangle)] = field(
355
+ doc="Fired when a header menu item is clicked."
356
+ )
357
+
358
+ on_item_hovered: EventHandler[passthrough_event_spec(tuple[int, int])] = field(
359
+ doc="Fired when an item is hovered."
360
+ )
361
+
362
+ on_delete: EventHandler[passthrough_event_spec(GridSelection)] = field(
363
+ doc="Fired when a selection is deleted."
364
+ )
365
+
366
+ on_finished_editing: EventHandler[
367
+ passthrough_event_spec(GridCell | None, tuple[int, int])
368
+ ] = field(doc="Fired when editing is finished.")
369
+
370
+ on_row_appended: EventHandler[no_args_event_spec] = field(
371
+ doc="Fired when a row is appended."
372
+ )
373
+
374
+ grid_selection: Var[GridSelection] = field(
375
+ doc="The current grid selection state (columns, rows, and current cell/range). Must be used when on_grid_selection_change is used otherwise updates will not be reflected in the grid."
376
+ )
377
+
378
+ on_grid_selection_change: EventHandler[passthrough_event_spec(GridSelection)] = (
379
+ field(
380
+ doc="Fired when the grid selection changes. Will pass the current selection, the selected columns and the selected rows."
381
+ )
382
+ )
383
+
384
+ on_selection_cleared: EventHandler[no_args_event_spec] = field(
385
+ doc="Fired when the selection is cleared."
386
+ )
387
+
388
+ on_column_resize: EventHandler[passthrough_event_spec(GridColumn, int)] = field(
389
+ doc="Fired when a column is resized."
390
+ )
391
+
392
+ show_search: Var[bool] = field(doc="Shows search bar.")
393
+
394
+ on_search_close: EventHandler[no_args_event_spec] = field(
395
+ doc="Fired when the search close button is clicked."
396
+ )
397
+
398
+ # Custom cell renderers
399
+ custom_renderers: Var[Any]
400
+
401
+ def add_imports(self) -> ImportDict:
402
+ """Add imports for the component.
403
+
404
+ Returns:
405
+ The import dict.
406
+ """
407
+ if self.library is None:
408
+ return {}
409
+ return {
410
+ "": f"{format.format_library_name(self.library)}/dist/index.css",
411
+ self.library: ["GridCellKind", "CompactSelection"],
412
+ "$/utils/helpers/dataeditor.js": ImportVar(
413
+ tag="formatDataEditorCells", is_default=False, install=False
414
+ ),
415
+ }
416
+
417
+ def add_custom_code(self) -> list[str]:
418
+ """Add custom code for reconstructing GridSelection with CompactSelection objects.
419
+
420
+ Note: When using on_grid_selection_change, Glide Data Grid will not update its internal selection state automatically. Instead,
421
+ the grid_selection prop must be updated with a GridSelection object that has CompactSelection objects for the columns and rows properties.
422
+ This function provides the necessary JavaScript code to reconstruct the GridSelection object from a dict representation.
423
+
424
+ Returns:
425
+ JavaScript code to reconstruct GridSelection.
426
+ """
427
+ return [
428
+ """
429
+ function reconstructGridSelection(selection) {
430
+ if (!selection || typeof selection !== 'object') {
431
+ return undefined;
432
+ }
433
+
434
+ const reconstructCompactSelection = (data) => {
435
+ if (!data || !data.items || !Array.isArray(data.items)) {
436
+ return CompactSelection.empty();
437
+ }
438
+
439
+ const items = data.items;
440
+ if (items.length === 0) {
441
+ return CompactSelection.empty();
442
+ }
443
+
444
+ let result = CompactSelection.empty();
445
+
446
+ // Items are stored as [start, end) ranges in CompactSelection internal format
447
+ for (const item of items) {
448
+ if (Array.isArray(item) && item.length === 2) {
449
+ const [start, end] = item;
450
+ result = result.add([start, end]);
451
+ }
452
+ }
453
+
454
+ return result;
455
+ };
456
+
457
+ return {
458
+ current: selection.current || undefined,
459
+ columns: reconstructCompactSelection(selection.columns),
460
+ rows: reconstructCompactSelection(selection.rows)
461
+ };
462
+ }
463
+ """
464
+ ]
465
+
466
+ def add_hooks(self) -> list[str]:
467
+ """Get the hooks to render.
468
+
469
+ Returns:
470
+ The hooks to render.
471
+ """
472
+ # Define the id of the component in case multiple are used in the same page.
473
+ editor_id = get_unique_variable_name()
474
+
475
+ # Define the name of the getData callback associated with this component and assign to get_cell_content.
476
+ if self.get_cell_content is not None:
477
+ data_callback = self.get_cell_content._js_expr
478
+ else:
479
+ data_callback = f"getData_{editor_id}"
480
+ self.get_cell_content = Var(_js_expr=data_callback)
481
+
482
+ code = [f"function {data_callback}([col, row]){{"]
483
+
484
+ columns_path = str(self.columns)
485
+ data_path = str(self.data)
486
+
487
+ code.extend([
488
+ f" return formatDataEditorCells(col, row, {columns_path}, {data_path});",
489
+ " }",
490
+ ])
491
+
492
+ return ["\n".join(code)]
493
+
494
+ @classmethod
495
+ def create(cls, *children, extended_cell_types: bool = False, **props) -> Component:
496
+ """Create the DataEditor component.
497
+
498
+ Args:
499
+ *children: The children of the data editor.
500
+ extended_cell_types: Whether to enable extended cell types.
501
+ **props: The props of the data editor.
502
+
503
+ Returns:
504
+ The DataEditor component.&
505
+
506
+ Raises:
507
+ ValueError: invalid input.
508
+ """
509
+ from reflex_components_core.el import Div
510
+
511
+ columns = props.get("columns", [])
512
+ data = props.get("data", [])
513
+ rows = props.get("rows")
514
+
515
+ # If rows is not provided, determine from data.
516
+ if rows is None:
517
+ if isinstance(data, Var) and not isinstance(data, ArrayVar):
518
+ msg = "DataEditor data must be an ArrayVar if rows is not provided."
519
+ raise ValueError(msg)
520
+
521
+ props["rows"] = data.length() if isinstance(data, ArrayVar) else len(data)
522
+
523
+ if not isinstance(columns, Var) and len(columns):
524
+ if types.is_dataframe(type(data)) or (
525
+ isinstance(data, Var) and types.is_dataframe(data._var_type)
526
+ ):
527
+ msg = "Cannot pass in both a pandas dataframe and columns to the data_editor component."
528
+ raise ValueError(msg)
529
+ props["columns"] = [
530
+ format.format_data_editor_column(col) for col in columns
531
+ ]
532
+
533
+ if "theme" in props:
534
+ theme = props.get("theme")
535
+ if isinstance(theme, Mapping):
536
+ props["theme"] = DataEditorTheme(**theme)
537
+
538
+ # Allow by default to select a region of cells in the grid.
539
+ props.setdefault("get_cells_for_selection", True)
540
+
541
+ # Disable on_paste by default if not provided.
542
+ props.setdefault("on_paste", False)
543
+
544
+ if props.pop("get_cell_content", None) is not None:
545
+ console.warn(
546
+ "get_cell_content is not user configurable, the provided value will be discarded"
547
+ )
548
+
549
+ # Apply the reconstruction function to grid_selection if it's a Var
550
+ if (grid_selection := props.get("grid_selection")) is not None and isinstance(
551
+ grid_selection, Var
552
+ ):
553
+ props["grid_selection"] = FunctionStringVar.create(
554
+ "reconstructGridSelection"
555
+ ).call(grid_selection)
556
+
557
+ if extended_cell_types:
558
+ props["custom_renderers"] = Var(
559
+ "allCells",
560
+ _var_data=VarData(
561
+ imports={
562
+ "@glideapps/glide-data-grid-cells@6.0.3": ImportVar(
563
+ tag="allCells", is_default=False
564
+ )
565
+ }
566
+ ),
567
+ )
568
+
569
+ grid = super().create(*children, **props)
570
+ return Div.create(
571
+ grid,
572
+ width=props.pop("width", "100%"),
573
+ height=props.pop("height", "100%"),
574
+ )
575
+
576
+ @staticmethod
577
+ def _get_app_wrap_components() -> dict[tuple[int, str], Component]:
578
+ """Get the app wrap components for the component.
579
+
580
+ Returns:
581
+ The app wrap components.
582
+ """
583
+ from reflex_components_core.el import Div
584
+
585
+ class Portal(Div):
586
+ def get_ref(self):
587
+ return None
588
+
589
+ return {
590
+ (-1, "DataEditorPortal"): Portal.create(
591
+ id="portal",
592
+ position="fixed",
593
+ top=0,
594
+ )
595
+ }
596
+
597
+
598
+ @serializer
599
+ def serialize_dataeditortheme(theme: DataEditorTheme):
600
+ """The serializer for the data editor theme.
601
+
602
+ Args:
603
+ theme: The theme to serialize.
604
+
605
+ Returns:
606
+ The serialized theme.
607
+ """
608
+ return {
609
+ format.to_camel_case(k): v for k, v in theme.__dict__.items() if v is not None
610
+ }
611
+
612
+
613
+ data_editor = DataEditor.create
614
+ data_editor_theme = DataEditorTheme
@@ -0,0 +1,354 @@
1
+ """Stub file for reflex_components_dataeditor/dataeditor.py"""
2
+
3
+ # ------------------- DO NOT EDIT ----------------------
4
+ # This file was generated by `reflex/utils/pyi_generator.py`!
5
+ # ------------------------------------------------------
6
+ import dataclasses
7
+ from collections.abc import Mapping, Sequence
8
+ from enum import Enum
9
+ from typing import Any, Literal, TypedDict
10
+
11
+ from reflex_base.components.component import NoSSRComponent
12
+ from reflex_base.event import EventType, PointerEventInfo
13
+ from reflex_base.utils.imports import ImportDict
14
+ from reflex_base.utils.serializers import serializer
15
+ from reflex_base.vars.base import Var
16
+ from reflex_components_core.core.breakpoints import Breakpoints
17
+
18
+ class GridColumnIcons(Enum):
19
+ Array = "array"
20
+ AudioUri = "audio_uri"
21
+ Boolean = "boolean"
22
+ HeaderCode = "code"
23
+ Date = "date"
24
+ Email = "email"
25
+ Emoji = "emoji"
26
+ GeoDistance = "geo_distance"
27
+ IfThenElse = "if_then_else"
28
+ Image = "image"
29
+ JoinStrings = "join_strings"
30
+ Lookup = "lookup"
31
+ Markdown = "markdown"
32
+ Math = "math"
33
+ Number = "number"
34
+ Phone = "phone"
35
+ Reference = "reference"
36
+ Rollup = "rollup"
37
+ RowID = "row_id"
38
+ SingleValue = "single_value"
39
+ SplitString = "split_string"
40
+ String = "string"
41
+ TextTemplate = "text_template"
42
+ Time = "time"
43
+ Uri = "uri"
44
+ VideoUri = "video_uri"
45
+
46
+ @dataclasses.dataclass
47
+ class DataEditorThemeBase:
48
+ accent_color: str | None
49
+ accent_fg: str | None
50
+ accent_light: str | None
51
+ base_font_style: str | None
52
+ bg_bubble: str | None
53
+ bg_bubble_selected: str | None
54
+ bg_cell: str | None
55
+ bg_cell_medium: str | None
56
+ bg_header: str | None
57
+ bg_header_has_focus: str | None
58
+ bg_header_hovered: str | None
59
+ bg_icon_header: str | None
60
+ bg_search_result: str | None
61
+ border_color: str | None
62
+ cell_horizontal_padding: int | None
63
+ cell_vertical_padding: int | None
64
+ drilldown_border: str | None
65
+ editor_font_size: str | None
66
+ fg_icon_header: str | None
67
+ font_family: str | None
68
+ header_bottom_border_color: str | None
69
+ header_font_style: str | None
70
+ horizontal_border_color: str | None
71
+ line_height: int | None
72
+ link_color: str | None
73
+ text_bubble: str | None
74
+ text_dark: str | None
75
+ text_group_header: str | None
76
+ text_header: str | None
77
+ text_header_selected: str | None
78
+ text_light: str | None
79
+ text_medium: str | None
80
+
81
+ @dataclasses.dataclass(init=False)
82
+ class DataEditorTheme(DataEditorThemeBase): ...
83
+
84
+ class Bounds(TypedDict):
85
+ x: int
86
+ y: int
87
+ width: int
88
+ height: int
89
+
90
+ class CompatSelection(TypedDict):
91
+ items: list
92
+
93
+ class Rectangle(TypedDict):
94
+ x: int
95
+ y: int
96
+ width: int
97
+ height: int
98
+
99
+ class GridSelectionCurrent(TypedDict):
100
+ cell: tuple[int, int]
101
+ range: Rectangle
102
+ rangeStack: list[Rectangle]
103
+
104
+ class GridSelection(TypedDict):
105
+ current: GridSelectionCurrent | None
106
+ columns: CompatSelection
107
+ rows: CompatSelection
108
+
109
+ class GroupHeaderClickedEventArgs(TypedDict):
110
+ kind: str
111
+ group: str
112
+ location: tuple[int, int]
113
+ bounds: Bounds
114
+ isEdge: bool
115
+ shiftKey: bool
116
+ ctrlKey: bool
117
+ metaKey: bool
118
+ isTouch: bool
119
+ localEventX: int
120
+ localEventY: int
121
+ button: int
122
+ buttons: int
123
+ scrollEdge: tuple[int, int]
124
+
125
+ class GridCell(TypedDict):
126
+ span: list[int] | None
127
+
128
+ class GridColumn(TypedDict):
129
+ title: str
130
+ group: str | None
131
+
132
+ class DataEditor(NoSSRComponent):
133
+ def add_imports(self) -> ImportDict: ...
134
+ def add_custom_code(self) -> list[str]: ...
135
+ def add_hooks(self) -> list[str]: ...
136
+ @classmethod
137
+ def create(
138
+ cls,
139
+ *children,
140
+ extended_cell_types: bool | None = False,
141
+ rows: Var[int] | int | None = None,
142
+ columns: Sequence[dict[str, Any]] | Var[Sequence[dict[str, Any]]] | None = None,
143
+ data: Sequence[Sequence[Any]] | Var[Sequence[Sequence[Any]]] | None = None,
144
+ get_cell_content: Var[str] | str | None = None,
145
+ get_cells_for_selection: Var[bool] | bool | None = None,
146
+ on_paste: Var[bool] | bool | None = None,
147
+ draw_focus_ring: Var[bool] | bool | None = None,
148
+ fixed_shadow_x: Var[bool] | bool | None = None,
149
+ fixed_shadow_y: Var[bool] | bool | None = None,
150
+ fill_handle: Var[bool] | bool | None = None,
151
+ freeze_columns: Var[int] | int | None = None,
152
+ group_header_height: Var[int] | int | None = None,
153
+ header_height: Var[int] | int | None = None,
154
+ max_column_auto_width: Var[int] | int | None = None,
155
+ max_column_width: Var[int] | int | None = None,
156
+ min_column_width: Var[int] | int | None = None,
157
+ row_height: Var[int] | int | None = None,
158
+ row_markers: Literal[
159
+ "both", "checkbox", "checkbox-visible", "clickable-number", "none", "number"
160
+ ]
161
+ | Var[
162
+ Literal[
163
+ "both",
164
+ "checkbox",
165
+ "checkbox-visible",
166
+ "clickable-number",
167
+ "none",
168
+ "number",
169
+ ]
170
+ ]
171
+ | None = None,
172
+ row_marker_start_index: Var[int] | int | None = None,
173
+ row_marker_width: Var[int] | int | None = None,
174
+ smooth_scroll_x: Var[bool] | bool | None = None,
175
+ smooth_scroll_y: Var[bool] | bool | None = None,
176
+ vertical_border: Var[bool] | bool | None = None,
177
+ column_select: Literal["multi", "none", "single"]
178
+ | Var[Literal["multi", "none", "single"]]
179
+ | None = None,
180
+ range_select: Literal["cell", "multi-cell", "multi-rect", "none", "rect"]
181
+ | Var[Literal["cell", "multi-cell", "multi-rect", "none", "rect"]]
182
+ | None = None,
183
+ row_select: Literal["multi", "none", "single"]
184
+ | Var[Literal["multi", "none", "single"]]
185
+ | None = None,
186
+ prevent_diagonal_scrolling: Var[bool] | bool | None = None,
187
+ overscroll_x: Var[int] | int | None = None,
188
+ overscroll_y: Var[int] | int | None = None,
189
+ scroll_offset_x: Var[int] | int | None = None,
190
+ scroll_offset_y: Var[int] | int | None = None,
191
+ range_selection_blending: Literal["exclusive", "mixed"]
192
+ | Var[Literal["exclusive", "mixed"]]
193
+ | None = None,
194
+ column_selection_blending: Literal["exclusive", "mixed"]
195
+ | Var[Literal["exclusive", "mixed"]]
196
+ | None = None,
197
+ row_selection_blending: Literal["exclusive", "mixed"]
198
+ | Var[Literal["exclusive", "mixed"]]
199
+ | None = None,
200
+ row_selection_mode: Literal["auto", "multi"]
201
+ | Var[Literal["auto", "multi"]]
202
+ | None = None,
203
+ span_range_behavior: Literal["allowPartial", "default"]
204
+ | Var[Literal["allowPartial", "default"]]
205
+ | None = None,
206
+ theme: DataEditorTheme | Var[DataEditorTheme | dict] | dict | None = None,
207
+ grid_selection: GridSelection | Var[GridSelection] | None = None,
208
+ show_search: Var[bool] | bool | None = None,
209
+ custom_renderers: Any | Var[Any] | None = None,
210
+ style: Sequence[Mapping[str, Any]]
211
+ | Mapping[str, Any]
212
+ | Var[Mapping[str, Any]]
213
+ | Breakpoints
214
+ | None = None,
215
+ key: Any | None = None,
216
+ id: Any | None = None,
217
+ ref: Var | None = None,
218
+ class_name: Any | None = None,
219
+ custom_attrs: dict[str, Any | Var] | None = None,
220
+ on_blur: EventType[()] | None = None,
221
+ on_cell_activated: EventType[()] | EventType[tuple[int, int]] | None = None,
222
+ on_cell_clicked: EventType[()] | EventType[tuple[int, int]] | None = None,
223
+ on_cell_context_menu: EventType[()] | EventType[tuple[int, int]] | None = None,
224
+ on_cell_edited: EventType[()] | EventType[tuple[int, int]] | EventType[tuple[int, int], GridCell] | None = None,
225
+ on_click: EventType[()] | EventType[PointerEventInfo] | None = None,
226
+ on_column_resize: EventType[()] | EventType[GridColumn] | EventType[GridColumn, int] | None = None,
227
+ on_context_menu: EventType[()] | EventType[PointerEventInfo] | None = None,
228
+ on_delete: EventType[()] | EventType[GridSelection] | None = None,
229
+ on_double_click: EventType[()] | EventType[PointerEventInfo] | None = None,
230
+ on_finished_editing: EventType[()] | EventType[GridCell | None] | EventType[GridCell | None, tuple[int, int]] | None = None,
231
+ on_focus: EventType[()] | None = None,
232
+ on_grid_selection_change: EventType[()] | EventType[GridSelection] | None = None,
233
+ on_group_header_clicked: EventType[()] | EventType[tuple[int, int]] | EventType[tuple[int, int], GridCell] | None = None,
234
+ on_group_header_context_menu: EventType[()] | EventType[int] | EventType[int, GroupHeaderClickedEventArgs] | None = None,
235
+ on_group_header_renamed: EventType[()] | EventType[str] | EventType[str, str] | None = None,
236
+ on_header_clicked: EventType[()] | EventType[tuple[int, int]] | None = None,
237
+ on_header_context_menu: EventType[()] | EventType[tuple[int, int]] | None = None,
238
+ on_header_menu_click: EventType[()] | EventType[int] | EventType[int, Rectangle] | None = None,
239
+ on_item_hovered: EventType[()] | EventType[tuple[int, int]] | None = None,
240
+ on_mount: EventType[()] | None = None,
241
+ on_mouse_down: EventType[()] | None = None,
242
+ on_mouse_enter: EventType[()] | None = None,
243
+ on_mouse_leave: EventType[()] | None = None,
244
+ on_mouse_move: EventType[()] | None = None,
245
+ on_mouse_out: EventType[()] | None = None,
246
+ on_mouse_over: EventType[()] | None = None,
247
+ on_mouse_up: EventType[()] | None = None,
248
+ on_row_appended: EventType[()] | None = None,
249
+ on_scroll: EventType[()] | None = None,
250
+ on_scroll_end: EventType[()] | None = None,
251
+ on_search_close: EventType[()] | None = None,
252
+ on_selection_cleared: EventType[()] | None = None,
253
+ on_unmount: EventType[()] | None = None,
254
+ **props,
255
+ ) -> DataEditor:
256
+ """Create the DataEditor component.
257
+
258
+ Args:
259
+ *children: The children of the data editor.
260
+ extended_cell_types: Whether to enable extended cell types.
261
+ rows: Number of rows.
262
+ columns: Headers of the columns for the data grid.
263
+ data: The data.
264
+ get_cell_content: The name of the callback used to find the data to display.
265
+ get_cells_for_selection: Allow selection for copying.
266
+ on_paste: Allow paste.
267
+ draw_focus_ring: Controls the drawing of the focus ring.
268
+ fixed_shadow_x: Enables or disables the overlay shadow when scrolling horizontally.
269
+ fixed_shadow_y: Enables or disables the overlay shadow when scrolling vertically.
270
+ fill_handle: Controls the presence of the fill indicator
271
+ freeze_columns: The number of columns which should remain in place when scrolling horizontally. Doesn't include rowMarkers.
272
+ group_header_height: Controls the header of the group header row.
273
+ header_height: Controls the height of the header row.
274
+ max_column_auto_width: The maximum width a column can be automatically sized to.
275
+ max_column_width: The maximum width a column can be resized to.
276
+ min_column_width: The minimum width a column can be resized to.
277
+ row_height: Determines the height of each row.
278
+ row_markers: Kind of row markers. Options are: "none", "number", "checkbox", "both", "checkbox-visible", "clickable-number".
279
+ row_marker_start_index: Changes the starting index for row markers.
280
+ row_marker_width: Sets the width of row markers in pixels, if unset row markers will automatically size.
281
+ smooth_scroll_x: Enable horizontal smooth scrolling.
282
+ smooth_scroll_y: Enable vertical smooth scrolling.
283
+ vertical_border: Controls the drawing of the left hand vertical border of a column. If set to a boolean value it controls all borders.
284
+ column_select: Allow columns selections. ("none", "single", "multi")
285
+ range_select: Allow range selections. ("none", "cell", "rect", "multi-cell", "multi-rect").
286
+ row_select: Allow row selections. ("none", "single", "multi").
287
+ prevent_diagonal_scrolling: Prevent diagonal scrolling.
288
+ overscroll_x: Allow to scroll past the limit of the actual content on the horizontal axis.
289
+ overscroll_y: Allow to scroll past the limit of the actual content on the vertical axis.
290
+ scroll_offset_x: Initial scroll offset on the horizontal axis.
291
+ scroll_offset_y: Initial scroll offset on the vertical axis.
292
+ range_selection_blending: Controls which types of range selections can exist at the same time. ("exclusive", "mixed").
293
+ column_selection_blending: Controls which types of column selections can exist at the same time. ("exclusive", "mixed").
294
+ row_selection_blending: Controls which types of row selections can exist at the same time. ("exclusive", "mixed").
295
+ row_selection_mode: Controls row marker selection behavior. "auto" adapts to touch/mouse, "multi" acts as if Ctrl is pressed. ("auto", "multi").
296
+ span_range_behavior: Controls how spans are handled in selections. ("default", "allowPartial").
297
+ theme: global theme
298
+ grid_selection: The current grid selection state (columns, rows, and current cell/range). Must be used when on_grid_selection_change is used otherwise updates will not be reflected in the grid.
299
+ show_search: Shows search bar.
300
+ custom_renderers: Custom cell renderers
301
+ style: The style of the component.
302
+ key: A unique key for the component.
303
+ id: The id for the component.
304
+ ref: The Var to pass as the ref to the component.
305
+ class_name: The class name for the component.
306
+ custom_attrs: Attributes passed directly to the component.
307
+ on_focus: Fired when the element (or some element inside of it) receives focus. For example, it is called when the user clicks on a text input.
308
+ on_blur: Fired when focus has left the element (or left some element inside of it). For example, it is called when the user clicks outside of a focused text input.
309
+ on_click: Fired when the user clicks on an element. For example, it's called when the user clicks on a button.
310
+ on_context_menu: Fired when the user right-clicks on an element.
311
+ on_double_click: Fired when the user double-clicks on an element.
312
+ on_mouse_down: Fired when the user presses a mouse button on an element.
313
+ on_mouse_enter: Fired when the mouse pointer enters the element.
314
+ on_mouse_leave: Fired when the mouse pointer leaves the element.
315
+ on_mouse_move: Fired when the mouse pointer moves over the element.
316
+ on_mouse_out: Fired when the mouse pointer moves out of the element.
317
+ on_mouse_over: Fired when the mouse pointer moves onto the element.
318
+ on_mouse_up: Fired when the user releases a mouse button on an element.
319
+ on_scroll: Fired when the user scrolls the element.
320
+ on_scroll_end: Fired when scrolling ends on the element.
321
+ on_mount: Fired when the component is mounted to the page.
322
+ on_unmount: Fired when the component is removed from the page. Only called during navigation, not on page refresh.
323
+ on_cell_activated: Fired when a cell is activated.
324
+ on_cell_clicked: Fired when a cell is clicked.
325
+ on_cell_context_menu: Fired when a cell is right-clicked.
326
+ on_cell_edited: Fired when a cell is edited.
327
+ on_group_header_clicked: Fired when a group header is clicked.
328
+ on_group_header_context_menu: Fired when a group header is right-clicked.
329
+ on_group_header_renamed: Fired when a group header is renamed.
330
+ on_header_clicked: Fired when a header is clicked.
331
+ on_header_context_menu: Fired when a header is right-clicked.
332
+ on_header_menu_click: Fired when a header menu item is clicked.
333
+ on_item_hovered: Fired when an item is hovered.
334
+ on_delete: Fired when a selection is deleted.
335
+ on_finished_editing: Fired when editing is finished.
336
+ on_row_appended: Fired when a row is appended.
337
+ on_grid_selection_change: Fired when the grid selection changes. Will pass the current selection, the selected columns and the selected rows.
338
+ on_selection_cleared: Fired when the selection is cleared.
339
+ on_column_resize: Fired when a column is resized.
340
+ on_search_close: Fired when the search close button is clicked.
341
+ **props: The props of the data editor.
342
+
343
+ Returns:
344
+ The DataEditor component.&
345
+
346
+ Raises:
347
+ ValueError: invalid input.
348
+ """
349
+
350
+ @serializer
351
+ def serialize_dataeditortheme(theme: DataEditorTheme): ...
352
+
353
+ data_editor = DataEditor.create
354
+ data_editor_theme = DataEditorTheme