KVision Framework Documentation
repository·master·Indexed 23 days ago
https://github.com/rjaros/kvisionAn object-oriented web framework for Kotlin/JS that enables the creation of modern web applications using a type-safe DSL without writing HTML, CSS, or JavaScript. KVision supports both reactive and imperative programming models, utilizes the Snabbdom virtual DOM for efficient rendering, and provides a rich set of GUI components, including Bootstrap-styled elements and form controls with validation and masking capabilities.
What's inside KVision
- KVision is an object-oriented web framework for Kotlin/JS. It allows developers to build modern web applications using the Kotlin language without needing to write manual HTML, CSS, or JavaScript. The framework provides a rich hierarchy of ready-to-use GUI components that serve as the building blocks for application user interfaces.
Overview of KVision Modules
masterKVision is an object-oriented web framework for Kotlin/JS. It provides a wide range of modules for building complex web applications, including core UI components, form handling, layout management, and integrations with popular JavaScript libraries like Chart.js, Leaflet, Tabulator, and React. The framework supports various design systems, including Bootstrap and Material Web components.Core KVision Components and Layouts
masterThe core of KVision is built around the
Widgetclass and various container modules:io.kvision.core: Contains the baseWidgetclass, core interfaces, and CSS enums for colors, borders, backgrounds, fonts, and positioning.io.kvision.panel: Provides container classes for layouts, including CSS Flexbox, CSS Grid, and Bootstrap's 12-column responsive grid.io.kvision.html: Provides components for standard HTML tags, including dedicated classes for buttons, images, links, lists, and iframes, with Handlebars.js template support.io.kvision.navbar,io.kvision.offcanvas, andio.kvision.dropdown: Provide Bootstrap-based navigation and menu components.
KVision Form Implementation
masterKVision provides a comprehensive form system with built-in validation support. Modules include:
io.kvision.form: The main entry point for form implementations.io.kvision.form.text: Text inputs, including password, text area, rich text area, and typeahead.io.kvision.form.number: Numeric inputs with range selection and spinners.io.kvision.form.select: Select components, including those with remote data source support.io.kvision.form.check: Checkboxes, radio buttons, and radio button groups.io.kvision.form.time: Date and time input components.io.kvision.form.upload: File upload components with drag & drop, preview, and AJAX upload modes.
How KVision works: Reactive and Imperative programming
masterKVision is an object-oriented web framework for Kotlin/JS that allows building modern web applications without writing HTML, CSS, or JavaScript directly. It uses a rich hierarchy of GUI components and type-safe DSL builders.
Key architectural features include:
- Reactive Programming: Supports the observer pattern, data binding, and integration with Kotlin
FlowandStateFlowfor observables. - Imperative Programming: Provides direct control over component manipulation.
- Virtual DOM: Utilizes the
Snabbdomfast virtual DOM implementation for efficient rendering. - Fullstack Capabilities: Integrates with
Kilua RPCto allow shared data models and business logic between Kotlin/JS frontends and server-side frameworks like Ktor, Spring Boot, Micronaut, and more.
- Reactive Programming: Supports the observer pattern, data binding, and integration with Kotlin
Data Handling and State Management
masterKVision offers several ways to manage application state and data flow:
io.kvision.state: Implements the observer pattern, including observable lists.io.kvision.redux: Provides a predictable state container based on the Redux library.io.kvision.event: Provides extension functions to produce Kotlin CoroutinesFlows from KVision events and data sources.io.kvision.rest: A RESTful API client supporting type-safe connectivity.io.kvision.routing: A simple wrapper for JavaScript routing.
Third-party Library Integrations
masterKVision includes high-level wrappers for several popular JavaScript libraries:
- Charts:
io.kvision.chart(based onchart.js). - Data Grids:
io.kvision.tabulator(based onTabulator). - Maps:
io.kvision.maps(based onLeaflet). - UI Frameworks:
io.kvision.react(for embedding React components) andio.kvision.snabbdom(virtual DOM bindings).
- Charts:
Material Web Components in KVision
masterFor developers following Material Design, KVision provides a dedicated set of Material Web components under the
io.kvision.materialpackage. This includes:- Buttons & Actions:
button,iconbutton,fab(floating action button), andripple. - Selection & Input:
checkbox,radio,select,slider,switch, andtextfield(filled/outlined). - Navigation & Layout:
tabs,list,menu, anddivider. - Feedback & Containers:
chips,dialog,progress(circular/linear), andicon.
- Buttons & Actions:
Quickstart: Build a production application
masterTo create an optimized production build of your KVision application, use the
zipGradle task. This will generate a compressed package containing the optimized application.Run the following command:
./gradlew zipThe resulting application package will be located in
build/libs/(e.g.,showcase-1.0.0-SNAPSHOT.zip)../gradlew zipQuickstart: Set up a KVision development environment
masterTo start developing with KVision, you can use the official examples repository to see the framework in action and test changes immediately using Hot Module Replacement (HMR).
- Clone the examples repository:
git clone https://github.com/rjaros/kvision-examples.git - Navigate to a showcase directory:
cd kvision-examples/showcase - Run the Gradle incremental build task:
./gradlew -t run - Open
http://localhost:3000/in your browser to view the application.
git clone https://github.com/rjaros/kvision-examples.git cd kvision-examples/showcase ./gradlew -t run- Clone the examples repository:
Initialize the application with a Root container
masterThe
Rootcontainer is the entry point for your KVision application. It is bound to a specific element in your HTML file and is responsible for rendering the component tree and managing the Snabbdom virtual DOM. You can create aRootby targeting an element'sidor by passing anHTMLElementdirectly.Use the
Application.root()extension function to initialize it.Example: Building a reactive UI with ObservableValue
masterThis example demonstrates how to use
ObservableValueto create a reactive UI. When the value of the state changes, theh1component automatically updates to reflect the new content.class App : Application() { val state = ObservableValue("Hello world") override fun start() { root("root") { vPanel { h1(state) { +it } button("Add an exclamation mark").onClick { state.value += "!" } } } } }class App : Application() { val state = ObservableValue("Hello world") override fun start() { root("root") { vPanel { h1(state) { +it } button("Add an exclamation mark").onClick { state.value += "!" } } } } }