f673f3ac80
Introduce a FastHTML-style component model alongside the existing function-based one, purely additive: - Node: base renderable; __html__/__str__ render lazily so str()/f-string composition keeps working during migration. - Element: the single class for any HTML element (tag + attrs + children), rendering via the existing memoized _render_element. - Safe: wraps pre-rendered HTML (migration bridge for f-string components). - Fragment: ordered children with no wrapper tag (replaces str(a)+str(b)). - BaseComponent: base for higher-level components; render() returns a subtree, media declared via a Media attribute. - Media: declarative JS deps with order-preserving dedup merge. - collect_media()/render() helpers walk the tree. The legacy Component() function now builds an Element and is Node-aware in its child handling, so a tree mixing string- and node-returning components renders correctly with byte-identical output. No call sites changed yet. https://claude.ai/code/session_01BKurBhE3Qj25p7Bfsg7EeK
160 lines
2.8 KiB
Python
160 lines
2.8 KiB
Python
"""Server-side HTML component library.
|
|
|
|
Split into core / primitives / domain / filters submodules; this package
|
|
re-exports the public API so ``from common.components import X`` keeps working.
|
|
"""
|
|
|
|
from common.components.core import (
|
|
BaseComponent,
|
|
Component,
|
|
Element,
|
|
Fragment,
|
|
HTMLAttribute,
|
|
HTMLTag,
|
|
Media,
|
|
Node,
|
|
Safe,
|
|
_render_element,
|
|
collect_media,
|
|
randomid,
|
|
render,
|
|
)
|
|
from common.components.date_range_picker import (
|
|
DateRangeCalendar,
|
|
DateRangeField,
|
|
DateRangePicker,
|
|
)
|
|
from common.components.domain import (
|
|
GameLink,
|
|
GameStatus,
|
|
GameStatusSelector,
|
|
LinkedPurchase,
|
|
NameWithIcon,
|
|
PriceConverted,
|
|
PurchasePrice,
|
|
SessionDeviceSelector,
|
|
_resolve_name_with_icon,
|
|
)
|
|
from common.components.filters import (
|
|
DeviceFilterBar,
|
|
FilterBar,
|
|
PlatformFilterBar,
|
|
PlayEventFilterBar,
|
|
PurchaseFilterBar,
|
|
SessionFilterBar,
|
|
StringFilter,
|
|
)
|
|
from common.components.primitives import (
|
|
H1,
|
|
A,
|
|
AddForm,
|
|
Button,
|
|
ButtonGroup,
|
|
Checkbox,
|
|
CsrfInput,
|
|
Div,
|
|
ExternalScript,
|
|
Icon,
|
|
Input,
|
|
Label,
|
|
Li,
|
|
Modal,
|
|
ModuleScript,
|
|
Pill,
|
|
Popover,
|
|
PopoverTruncated,
|
|
Radio,
|
|
SearchField,
|
|
SimpleTable,
|
|
Span,
|
|
StaticScript,
|
|
TableHeader,
|
|
TableRow,
|
|
TableTd,
|
|
Td,
|
|
Template,
|
|
Tr,
|
|
Ul,
|
|
YearPicker,
|
|
paginated_table_content,
|
|
)
|
|
from common.components.search_select import (
|
|
DEFAULT_PREFETCH,
|
|
FilterSelect,
|
|
LabeledOption,
|
|
SearchSelect,
|
|
SearchSelectOption,
|
|
searchselect_selected,
|
|
)
|
|
from common.utils import truncate
|
|
|
|
__all__ = [
|
|
"truncate",
|
|
"BaseComponent",
|
|
"Component",
|
|
"Element",
|
|
"Fragment",
|
|
"Media",
|
|
"Node",
|
|
"Safe",
|
|
"collect_media",
|
|
"render",
|
|
"HTMLAttribute",
|
|
"HTMLTag",
|
|
"_render_element",
|
|
"randomid",
|
|
"A",
|
|
"AddForm",
|
|
"Button",
|
|
"ButtonGroup",
|
|
"Checkbox",
|
|
"CsrfInput",
|
|
"Div",
|
|
"ExternalScript",
|
|
"H1",
|
|
"Icon",
|
|
"Input",
|
|
"Modal",
|
|
"ModuleScript",
|
|
"Pill",
|
|
"Popover",
|
|
"PopoverTruncated",
|
|
"Radio",
|
|
"SearchField",
|
|
"DEFAULT_PREFETCH",
|
|
"FilterSelect",
|
|
"LabeledOption",
|
|
"SearchSelect",
|
|
"SearchSelectOption",
|
|
"searchselect_selected",
|
|
"SimpleTable",
|
|
"Span",
|
|
"StaticScript",
|
|
"Label",
|
|
"TableHeader",
|
|
"TableRow",
|
|
"TableTd",
|
|
"Template",
|
|
"YearPicker",
|
|
"paginated_table_content",
|
|
"GameLink",
|
|
"GameStatus",
|
|
"GameStatusSelector",
|
|
"LinkedPurchase",
|
|
"NameWithIcon",
|
|
"PriceConverted",
|
|
"PurchasePrice",
|
|
"SessionDeviceSelector",
|
|
"_resolve_name_with_icon",
|
|
"DateRangeCalendar",
|
|
"DateRangeField",
|
|
"DateRangePicker",
|
|
"FilterBar",
|
|
"PurchaseFilterBar",
|
|
"SessionFilterBar",
|
|
"DeviceFilterBar",
|
|
"PlatformFilterBar",
|
|
"PlayEventFilterBar",
|
|
"StringFilter",
|
|
]
|