Framework facilitates backend-initiated user interface modifications. These changes are made possible through Code-Managed Components (CMCs), distinct from the Builder-Managed Components (BMCs). CMCs, unlike BMCs, are dynamically created and modified via back-end code, and cannot be edited (but still can be viewed) within the application builder. It’s important to also note that CMCs do not persist in your application’s files and exist only during the application runtime, supporting dynamic UI adjustments.Documentation Index
Fetch the complete documentation index at: https://dev.writer.com/llms.txt
Use this file to discover all available pages before exploring further.
To summarise:CMC – Code-Managed Component
- created via application back-end;
- cannot be edited in builder;
- is not saved to
.wf/components-*.jsonl.
- created via builder;
- can be edited in builder;
- is saved to
.wf/components-*.jsonl.
UI manager
Framework provides two independent approaches for managing your application’s UI: initializing a base UI and making session-specific updates.Initializing base UI
Theinit_ui() method sets up a UI manager to configure UI components at the application’s startup. This creates a component set that is accessible across all sessions:
Making session-specific updates
For dynamic, session-specific UI updates, theui parameter is used within handler functions. This approach allows for real-time modifications tailored to individual user sessions:
UI manager methods
find method
You can use the ui.find(component_id: str) method to access existing components by ID:
RuntimeError.
refresh_with method
You can use the ui.refresh_with(component_id: str) method to replace children CMCs of an existing component (referenced by its ID):
find method, it also raises a RuntimeError if it fails to find a referenced component.
parent method
ui.parent(component_id: str, level: int = 1) gives access to the id to parents at higher levels.
Component methods
UI manager contains methods linked to each front-end component. For example, in previous code snippets we provide aui.Text method, which is used for creating Text components.
This method expects content: dict as first argument, which enables you to set the field properties of the component, through corresponding keys:
content as its first argument:
content, a set of fields which is specific to the component type, you can also modify the base properties of the component itself, which are:
id: str: A unique identifier used for accessing the component after it was created.
Providing an identifier that is already taken would result inRuntimeWarningand the existing component being overwritten with a newly created one.If no ID is provided with a component, a UUID is automatically generated for it.Make sure to provide anidif you intend tofindthe component later
As thefindmethod relies onidof the component, retrieval might get tricky if itsidwas generated randomly.position: int: Determines the display order of the component in relation to its siblings.
Position0means that the component is the first child of its parent.
Position-2is used for components – such as sidebars – that have a specific reserved position not related to their siblings.Position is calculated automatically for each component, and you should be careful when you override it with predefined value, as this might lead to unexpected results.parentId: str: Determines the parent container for the component. By default, components recognise the container in the context of which they were defined as their parent. This allows for linking components to their parents outside of context, or for overriding a parent within a context.visible: bool | str: Determines the visibility of the component,Trueby default.handlers: dict[str, callable]: Attaches event handlers to the component. Each dictionary key represents an event, and its value is the corresponding handler.:A component can be linked to multiple event handlers.binding: dict[str, str]: Links the component to a state variable via binding. The dictionary key is the bindable event, and the value is the state variable’s name:Unlike handlers, a component can be linked to just one variable via a bindable event. If thebindingdictionary includes multiple event-variable pairs, aRuntimeErrorwill be triggered.
Container components
Framework provides multiple layout components that can serve as containers for other components. You can usewith keyword to define such layouts:
with are being appended to it:
refresh_with method: