KVision Framework Documentation

repository·master·Indexed 23 days ago

https://github.com/rjaros/kvision

An 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.

Tokens
4.5K
Snippets
4
Records
36
Agent score
80%

What's inside KVision

  1. What is KVision?

    master
    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.
  2. Overview of KVision Modules

    master
    KVision 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.
  3. Core KVision Components and Layouts

    master

    The core of KVision is built around the Widget class and various container modules:

    • io.kvision.core: Contains the base Widget class, 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, and io.kvision.dropdown: Provide Bootstrap-based navigation and menu components.
  4. KVision Form Implementation

    master

    KVision 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.
  5. How KVision works: Reactive and Imperative programming

    master

    KVision 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 Flow and StateFlow for observables.
    • Imperative Programming: Provides direct control over component manipulation.
    • Virtual DOM: Utilizes the Snabbdom fast virtual DOM implementation for efficient rendering.
    • Fullstack Capabilities: Integrates with Kilua RPC to allow shared data models and business logic between Kotlin/JS frontends and server-side frameworks like Ktor, Spring Boot, Micronaut, and more.
  6. Data Handling and State Management

    master

    KVision 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 Coroutines Flows 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.
  7. Third-party Library Integrations

    master

    KVision includes high-level wrappers for several popular JavaScript libraries:

    • Charts: io.kvision.chart (based on chart.js).
    • Data Grids: io.kvision.tabulator (based on Tabulator).
    • Maps: io.kvision.maps (based on Leaflet).
    • UI Frameworks: io.kvision.react (for embedding React components) and io.kvision.snabbdom (virtual DOM bindings).
  8. Material Web Components in KVision

    master

    For developers following Material Design, KVision provides a dedicated set of Material Web components under the io.kvision.material package. This includes:

    • Buttons & Actions: button, iconbutton, fab (floating action button), and ripple.
    • Selection & Input: checkbox, radio, select, slider, switch, and textfield (filled/outlined).
    • Navigation & Layout: tabs, list, menu, and divider.
    • Feedback & Containers: chips, dialog, progress (circular/linear), and icon.
  9. Quickstart: Build a production application

    master

    To create an optimized production build of your KVision application, use the zip Gradle task. This will generate a compressed package containing the optimized application.

    Run the following command:

    ./gradlew zip

    The resulting application package will be located in build/libs/ (e.g., showcase-1.0.0-SNAPSHOT.zip).

    ./gradlew zip
  10. Quickstart: Set up a KVision development environment

    master

    To 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).

    1. Clone the examples repository:
      git clone https://github.com/rjaros/kvision-examples.git
    2. Navigate to a showcase directory:
      cd kvision-examples/showcase
    3. Run the Gradle incremental build task:
      ./gradlew -t run
    4. 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
  11. Initialize the application with a Root container

    master

    The Root container 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 a Root by targeting an element's id or by passing an HTMLElement directly.

    Use the Application.root() extension function to initialize it.

  12. Example: Building a reactive UI with ObservableValue

    master

    This example demonstrates how to use ObservableValue to create a reactive UI. When the value of the state changes, the h1 component 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 += "!"
                    }
                }
            }
        }
    }