From bc1e1876d638e090ec784e9a1483730ec4e62ad8 Mon Sep 17 00:00:00 2001 From: Simon Leeb <52261246+sliemeobn@users.noreply.github.com> Date: Wed, 11 Nov 2026 22:36:07 +0100 Subject: [PATCH] fix docs inconsistencies, typos and outdated info --- guide/animation/animatable-modifiers.md | 6 ++- guide/animation/animate-layout-and-css.md | 4 +- guide/animation/custom-animations.md | 2 +- guide/animation/phase-animator.md | 2 +- guide/animation/transitions.md | 2 +- guide/dom-interaction/handling-events.md | 9 ++++ guide/dom-interaction/html-elements.md | 22 ++++---- guide/dom-interaction/input-bindings.md | 4 +- guide/essentials/application.md | 24 ++++----- guide/essentials/environment.md | 32 +++++------ guide/essentials/lifecycle-events.md | 66 +++++++++++------------ guide/essentials/list-rendering.md | 2 +- guide/essentials/state-and-reactivity.md | 8 +-- guide/essentials/views.md | 22 ++++---- guide/get-started.md | 6 +-- guide/introduction.md | 5 +- guide/topics/server-side-rendering.md | 8 +-- guide/topics/web-components.md | 2 +- index.md | 5 +- 19 files changed, 123 insertions(+), 108 deletions(-) diff --git a/guide/animation/animatable-modifiers.md b/guide/animation/animatable-modifiers.md index 213425d..220f14b 100644 --- a/guide/animation/animatable-modifiers.md +++ b/guide/animation/animatable-modifiers.md @@ -4,10 +4,14 @@ This section is incomplete. ::: -### See also +## See also - `ElementaryUI.View.opacity(_:)` - `ElementaryUI.View.offset(x:y:)` - `ElementaryUI.View.rotationEffect(_:anchor:)` +- `ElementaryUI.View.scaleEffect(_:anchor:)` +- `ElementaryUI.View.blur(radius:)` +- `ElementaryUI.View.saturation(_:)` +- `ElementaryUI.View.brightness(_:)` diff --git a/guide/animation/animate-layout-and-css.md b/guide/animation/animate-layout-and-css.md index 1118a34..53a364f 100644 --- a/guide/animation/animate-layout-and-css.md +++ b/guide/animation/animate-layout-and-css.md @@ -1,11 +1,11 @@ # Animate changes to layout and CSS values -ElementaryUI comes with a _**FLIP**_ animation system that enables automatic +ElementaryUI comes with a **FLIP** animation system that enables automatic animation of essentially any visible change to your view's layout or appearance. **FLIP** (First, Last, Invert, Play) is a technique that captures the geometry or appearance of an element before and after a change, then animates the difference. A view can opt-in to FLIP handling with modifiers, and any [transaction with an animation](transactions-and-animations.md#transactions) will be animated accordingly. -### Animate layout containers +## Animate layout containers You can enable layout FLIP-handling on any [HTML element](../dom-interaction/html-elements.md) by applying the `ElementaryUI.View.animateContainerLayout(animateContainerSize:)` modifier. diff --git a/guide/animation/custom-animations.md b/guide/animation/custom-animations.md index 1a5aab2..8eac7ec 100644 --- a/guide/animation/custom-animations.md +++ b/guide/animation/custom-animations.md @@ -4,7 +4,7 @@ This section is incomplete. ::: -### See also +## See also - `ElementaryUI.Animatable` - `ElementaryUI.CustomAnimation` diff --git a/guide/animation/phase-animator.md b/guide/animation/phase-animator.md index 83f13f9..9b63ac6 100644 --- a/guide/animation/phase-animator.md +++ b/guide/animation/phase-animator.md @@ -26,6 +26,6 @@ Here, `.phaseAnimator` animates an existing view. Each click adds a heart and ma ## Choosing animations -Use the `animation` closure to choose an `ElementaryUI.Animation` for each phase, including the return to the first phase. +Use the `animation` closure to choose an `ElementaryUI.Animation` for the transition into each phase, including the return to the first phase. Omit the closure to use the default animation, or return `nil` for a step without animation. diff --git a/guide/animation/transitions.md b/guide/animation/transitions.md index 574197a..9e6d58a 100644 --- a/guide/animation/transitions.md +++ b/guide/animation/transitions.md @@ -4,7 +4,7 @@ This section is incomplete. ::: -### See also +## See also - `ElementaryUI.Transition` - `ElementaryUI.View.transition(_:animation:)` diff --git a/guide/dom-interaction/handling-events.md b/guide/dom-interaction/handling-events.md index 3cdb745..cc01ee9 100644 --- a/guide/dom-interaction/handling-events.md +++ b/guide/dom-interaction/handling-events.md @@ -6,6 +6,15 @@ ElementaryUI provides on*Event* modifiers to handle DOM events like clicks, key This section is incomplete. ::: +## Available events + +- `ElementaryUI.View.onClick(_:)` +- `ElementaryUI.View.onMouseDown(_:)` +- `ElementaryUI.View.onMouseMove(_:)` +- `ElementaryUI.View.onMouseUp(_:)` +- `ElementaryUI.View.onKeyDown(_:)` +- `ElementaryUI.View.onInput(_:)` + ## Example Use `ElementaryUI.View.onMouseMove(_:)` to track mouse movement: diff --git a/guide/dom-interaction/html-elements.md b/guide/dom-interaction/html-elements.md index cc5edd7..d8975be 100644 --- a/guide/dom-interaction/html-elements.md +++ b/guide/dom-interaction/html-elements.md @@ -17,13 +17,13 @@ Build up your HTML using the provided lower-case types like `div`, `p`, `button` ```swift @View struct MyView { - var body: some View { - div { - h1 { "Title" } - p { "Paragraph text" } - button { "Click me" } + var body: some View { + div { + h1 { "Title" } + p { "Paragraph text" } + button { "Click me" } + } } - } } ``` @@ -33,14 +33,14 @@ HTML attributes like `class`, `style`, and `id` are typically set via the elemen ```swift div(.class("container"), .id("main")) { - p(.style(["color": "crimson"])) { - "Styled text" - } - input(.type(.text), .placeholder("Enter something")) + p(.style(["color": "crimson"])) { + "Styled text" + } + input(.type(.text), .placeholder("Enter something")) } ``` -Attributes can also be altered by using the modifier syntax, this allows for easy handling of conditional attributes. +Attributes can also be altered by using the modifier syntax, which allows for easy handling of conditional attributes. ```swift div { diff --git a/guide/dom-interaction/input-bindings.md b/guide/dom-interaction/input-bindings.md index 6023dec..68d3902 100644 --- a/guide/dom-interaction/input-bindings.md +++ b/guide/dom-interaction/input-bindings.md @@ -4,8 +4,8 @@ This section is incomplete. ::: -### See also +## See also - `ElementaryUI.View.bindValue(_:)` - `ElementaryUI.View.bindChecked(_:)` -- [Controlling Focus](/guide/dom-interaction/controlling-focus) +- [Controlling Focus](controlling-focus.md) diff --git a/guide/essentials/application.md b/guide/essentials/application.md index ff38f84..9f54c13 100644 --- a/guide/essentials/application.md +++ b/guide/essentials/application.md @@ -9,18 +9,18 @@ Mounting an application means **attaching its rendered output to the DOM**. Afte ```swift @main struct MyApp { - static func main() { - Application(ContentView()) - .mount(in: .body) - } + static func main() { + Application(ContentView()) + .mount(in: .body) + } } ``` -The `ElementaryUI.Application.mount(in:)` supports arbitrary CSS selectors. You can mount an application into any parent element. +The `ElementaryUI.Application.mount(in:)` method supports arbitrary CSS selectors. You can mount an application into any parent element. ```swift Application(ContentView()) - .mount(in: "#app") + .mount(in: "#app") ``` ## Multiple applications @@ -30,13 +30,13 @@ You can create and mount multiple applications on the same page. This is useful ```swift @main struct IslandsApp { - static func main() { - Application(Navigation()) - .mount(in: "#nav-container") + static func main() { + Application(Navigation()) + .mount(in: "#nav-container") - Application(CommentsSection()) - .mount(in: "#comments-island") - } + Application(CommentsSection()) + .mount(in: "#comments-island") + } } ``` diff --git a/guide/essentials/environment.md b/guide/essentials/environment.md index cc673a8..8259126 100644 --- a/guide/essentials/environment.md +++ b/guide/essentials/environment.md @@ -9,7 +9,7 @@ This sets up a typed environment key with a default value. ```swift extension EnvironmentValues { - @Entry var themeColor: String = "blue" + @Entry var themeColor: String = "blue" } ``` @@ -17,7 +17,7 @@ You can then provide a value using the `ElementaryUI.View.environment(_:_:)` mod ```swift MyView() - .environment(#Key(\.themeColor), "rebeccapurple") + .environment(#Key(\.themeColor), "rebeccapurple") ``` ::: info NOTE @@ -26,47 +26,47 @@ Since key paths cannot be used in Embedded Swift, you must wrap them with the `E ## Using environment values in a view -Access environment values in your `ElementaryUI.View` using the `ElementaryUI.Environment` property wrapper. +Access environment values in your `ElementaryUI.View` using the [`Environment`](https://swiftpackageindex.com/elementary-swift/elementary-ui/documentation/elementaryui/environment-swift.struct) property wrapper. ```swift @View struct Greeting { - @Environment(#Key(\.themeColor)) var color + @Environment(#Key(\.themeColor)) var color - var body: some View { - p(.style(["color": color])) { "Hello" } - } + var body: some View { + p(.style(["color": color])) { "Hello" } + } } ``` ::: info NOTE -`ElementaryUI.Environment` will only work in types annotated with the `ElementaryUI.@View` macro. +[`Environment`](https://swiftpackageindex.com/elementary-swift/elementary-ui/documentation/elementaryui/environment-swift.struct) will only work in types annotated with the `ElementaryUI.@View` macro. ::: ## Reactive objects -You can also pass [reactive objects](./state-and-reactivity.md#reactive) directly in the environment. The object's type acts as the environment key. +You can also pass [reactive objects](state-and-reactivity.md#reactive) directly in the environment. The object's type acts as the environment key. ```swift @Reactive final class UserProfile { - var name: String = "Anonymous" + var name: String = "Anonymous" } // Providing the object let profile = UserProfile() ContentView() - .environment(profile) + .environment(profile) // Reading the object in a sub view @View struct ProfileHeader { - @Environment(UserProfile.self) var profile + @Environment(UserProfile.self) var profile - var body: some View { - p { - "User: \(profile.name)" + var body: some View { + p { + "User: \(profile.name)" + } } - } } ``` diff --git a/guide/essentials/lifecycle-events.md b/guide/essentials/lifecycle-events.md index 441591a..7d0c3ca 100644 --- a/guide/essentials/lifecycle-events.md +++ b/guide/essentials/lifecycle-events.md @@ -9,28 +9,28 @@ Use the `ElementaryUI.View.onAppear(_:)` modifier to run an action when a view i ```swift @View struct MyView { - var body: some View { - div { "Hello" } - .onAppear { - print("View appeared!") - } - } + var body: some View { + div { "Hello" } + .onAppear { + print("View appeared!") + } + } } ``` ## `onDisappear` -Use the `ElementaryUI.View.onDisappear(_:)` modifier to run an action when a view is removed from hierarchy. +Use the `ElementaryUI.View.onDisappear(_:)` modifier to run an action when a view is removed from the hierarchy. ```swift @View struct MyView { - var body: some View { - div { "Goodbye" } - .onDisappear { - print("View disappeared!") - } - } + var body: some View { + div { "Goodbye" } + .onDisappear { + print("View disappeared!") + } + } } ``` @@ -41,15 +41,15 @@ The `ElementaryUI.View.onChange(of:initial:_:)` modifier triggers an action when ```swift @View struct CounterView { - @State var count = 0 + @State var count = 0 - var body: some View { - button { "Increment" } - .onClick { count += 1 } - .onChange(of: count) { - print("Count is now \(count)") - } - } + var body: some View { + button { "Increment" } + .onClick { count += 1 } + .onChange(of: count) { + print("Count is now \(count)") + } + } } ``` @@ -60,19 +60,19 @@ Use the `ElementaryUI.View.task(_:)` modifier to run an asynchronous operation w ```swift @View struct MyView { - @State var data: String? + @State var data: String? - var body: some View { - div { - if let data = data { - data - } else { - "Loading..." - } - } - .task { - data = await fetchData() + var body: some View { + div { + if let data = data { + data + } else { + "Loading..." + } + } + .task { + data = await fetchData() + } } - } } ``` diff --git a/guide/essentials/list-rendering.md b/guide/essentials/list-rendering.md index 97aacd2..42cd3bb 100644 --- a/guide/essentials/list-rendering.md +++ b/guide/essentials/list-rendering.md @@ -2,7 +2,7 @@ ## `ForEach` -Use `ElementaryUI.ForEach` when you need a stable id for your list items (reordering, insertions, animations). You can either use elements that implement `Identifiable`, or the `ElementaryUI.ForEach.init(_:id:content:)` initializer that takes an `id` closure returning any `Hashable` value. +Use `ForEach` when you need a stable id for your list items (reordering, insertions, animations). You can either use elements that implement `Identifiable`, or the `ForEach(_:id:content:)` initializer that takes an `id` closure returning any `Hashable` value. <<< @/swift/Sources/Snippets/ListStrings.swift#snippet diff --git a/guide/essentials/state-and-reactivity.md b/guide/essentials/state-and-reactivity.md index 26412f4..7b2a82c 100644 --- a/guide/essentials/state-and-reactivity.md +++ b/guide/essentials/state-and-reactivity.md @@ -12,15 +12,15 @@ Use the `ElementaryUI.State` property wrapper to declare local, mutable state fo -The lifetime of the state is tied to the **view’s lifetime**. For example, when this `Counter` view first appears in the view hierachy, a new slice of memory is initialized with `0`. As long as the view remains mounted, the current value of `count` is kept. Once the view is removed from the hierarchy, the memory is released again. +The lifetime of the state is tied to the **view’s lifetime**. For example, when this `TinyCounter` view first appears in the view hierarchy, a new slice of memory is initialized with `1`. As long as the view remains mounted, the current value of `count` is kept. Once the view is removed from the hierarchy, the memory is released again. ## `@Reactive` -Use the `Reactivity.@Reactive` macro to define a reference type that can be used view state. +Use the `Reactivity.@Reactive` macro to define a reference type that can be used as view state. -Any view that accesses one or more properties in its `body` will automatically be re-evaluated when the value of these properties change. +Any view that accesses one or more properties in its `body` will automatically be re-evaluated when the values of these properties change. -::: info Note +::: info NOTE This is essentially `@Observable`, but with support for Embedded Swift. diff --git a/guide/essentials/views.md b/guide/essentials/views.md index fd8320b..1fb74b5 100644 --- a/guide/essentials/views.md +++ b/guide/essentials/views.md @@ -4,18 +4,18 @@ Views are the fundamental building blocks in ElementaryUI. You describe the user ## Creating a view -A view is anything that conforms to the `ElementaryUI.View` protocol. You define your own view by applying the `ElementaryUI.@View` to a plain-old `struct`. +A view is anything that conforms to the `ElementaryUI.View` protocol. You define your own view by applying the `ElementaryUI.@View` macro to a plain-old `struct`. The `body` property describes what a `ElementaryUI.View` is composed of. ```swift @View struct Greeting { - var name: String + var name: String - var body: some View { - p { "Hello \(name)" } - } + var body: some View { + p { "Hello \(name)" } + } } ``` @@ -26,18 +26,18 @@ You build up bigger parts of UI by composing smaller views. Placing views inside ```swift @View struct Screen { - var body: some View { - div { - h1 { "Welcome, mighty pirate" } - Greeting(name: "Guybrush Threepwood") + var body: some View { + div { + h1 { "Welcome, mighty pirate" } + Greeting(name: "Guybrush Threepwood") + } } - } } ``` ## HTML elements are views -ElementaryUI's [HTML Elements](/guide/dom-interaction/html-elements) (like `div`, `p`, `button`) are views too — they participate in the same composition model as your own views. +ElementaryUI's [HTML Elements](../dom-interaction/html-elements.md) (like `div`, `p`, `button`) are views too — they participate in the same composition model as your own views. That means you can freely mix “element views” and “custom views” in the same hierarchy. diff --git a/guide/get-started.md b/guide/get-started.md index 945f9fb..7df2604 100644 --- a/guide/get-started.md +++ b/guide/get-started.md @@ -62,7 +62,7 @@ Here is a list of starter and demo projects: | [**Minimal Vite Starter**](https://github.com/elementary-swift/starter-vite) | Basic template for ElementaryUI. | | [**Tailwind Starter**](https://github.com/elementary-swift/starter-vite-tailwind) | Starter template with [Tailwind CSS](https://tailwindcss.com) preconfigured. | | [**Swiftle**](https://elementary-swift.github.io/elementary-ui/) | A tiny word game using [ElementaryFlow](https://github.com/elementary-swift/elementary-flow). | -| [**Full Stack Swift Demo**](https://cloudflare-worker.examples.elementary.codes/) | Swift in the browser. Swift on the edge, running in Cloudflare workers. | +| [**Full Stack Swift Demo**](https://cloudflare-worker.examples.elementary.codes/) | Swift in the browser. Swift on the edge, running in Cloudflare Workers. | ## Manual Setup @@ -101,7 +101,7 @@ struct MyApp { ```swift:line-numbers=6 [Package.swift] let package = Package( name: "MyApp", - platforms: [.macOS(.v15)], // [!code ++] + platforms: [.macOS(.v26)], // [!code ++] dependencies: [ .package(url: "https://github.com/swiftwasm/JavaScriptKit", from: "0.62.0"), .package(url: "https://github.com/elementary-swift/elementary-ui", from: "0.9.0") @@ -192,7 +192,7 @@ Finally, add an `index.html` file with a short script that runs the WebAssembly diff --git a/guide/introduction.md b/guide/introduction.md index a6b1883..424d00f 100644 --- a/guide/introduction.md +++ b/guide/introduction.md @@ -46,18 +46,17 @@ Your application can still choose to use "full Swift", but the framework itself ## The Road to 1.0 While official _Swift for WebAssembly_ SDKs are still new and Embedded Swift continues to evolve rapidly, the foundation is solidifying. -The core architecture — the reactive engine, the DOM mapping, and the animation system — are in place and ready to bear some load. +The core architecture — the reactive engine, the DOM mapping, and the animation system — is in place and ready to bear some load. ::: info Here are a few high-level topics that are still ahead
-- Support for creating web components (custom elements) - Fill in missing gaps for value bindings and event handlers - Client-side router implementation (for route-based SPAs) - Mechanism for fetching JSON data (embedded compatible) - Web Storage APIs (local/session storage, embedded compatible) -- Complete transform and filter effects and built-in transitions +- More built-in animatable modifiers (colors, borders) and transitions - Swift-native layout and style module (idiomatic APIs for CSS) - Support more CSS properties in FLIP animations - Investigate how to further reduce wasm binary size diff --git a/guide/topics/server-side-rendering.md b/guide/topics/server-side-rendering.md index 9fe7ca0..ec67165 100644 --- a/guide/topics/server-side-rendering.md +++ b/guide/topics/server-side-rendering.md @@ -1,7 +1,7 @@ # Server-Side Rendering ElementaryUI is designed to run in the browser and keep the DOM in sync with your view hierarchy. -But the lower-level building blocks it stands on — all HTML types and the `@HTMLBuilder` for composition — come from the [`Elementary`](https://github.com/elementary-swift/elementary) package, which focuses on **server-side rendering (SSR)**. +But the lower-level building blocks it stands on — all HTML types and the `@ContentBuilder` for composition — come from the [`Elementary`](https://github.com/elementary-swift/elementary) package, which focuses on **server-side rendering (SSR)**. This chapter explains how SSR works in Elementary today, how it relates to ElementaryUI, and what patterns are practical while a _hydration_ feature is still evolving. @@ -21,7 +21,7 @@ Elementary renders to text and is framework-agnostic, so it works with any Swift ```swift [Hummingbird] // https://github.com/hummingbird-community/hummingbird-elementary -.package(url: "https://github.com/hummingbird-community/hummingbird-elementary.git", from: "0.5.0"), +.package(url: "https://github.com/hummingbird-community/hummingbird-elementary.git", from: "0.6.0"), .product(name: "HummingbirdElementary", package: "hummingbird-elementary"), ``` @@ -42,7 +42,7 @@ However, you can still combine SSR and interactivity using an **islands** approa - Use **Elementary** to render the full HTML page (or most of it). - Add placeholders like `
` where you want interactivity. -- In the browser, mount one or more **ElementaryUI** applications into those placeholders using `Application(...).mount(in:)`. +- In the browser, mount one or more **ElementaryUI** applications into those placeholders using `ElementaryUI.Application.mount(in:)`. This gives you: @@ -51,7 +51,7 @@ This gives you: You can read more about mounting multiple apps in the [Application](../essentials/application.md#multiple-applications) chapter. -You can also define [Web Components](web-components.md) in ElementaryUI and include their custom HTML tags in the server-rendered page. Your Swift module registers these custom elements with the browser and they mount automatically when appear in the server-generated HTML. This website uses custom elements for its interactive snippets by registering an `` element. +You can also define [Web Components](web-components.md) in ElementaryUI and include their custom HTML tags in the server-rendered page. Your Swift module registers these custom elements with the browser and they mount automatically when they appear in the server-generated HTML. This website uses custom elements for its interactive snippets by registering an `` element. ## Hydration (the direction) diff --git a/guide/topics/web-components.md b/guide/topics/web-components.md index c044876..b58aef8 100644 --- a/guide/topics/web-components.md +++ b/guide/topics/web-components.md @@ -35,7 +35,7 @@ Here, `shadow: .open` mounts the view inside an open [Shadow DOM](https://develo Look, Mom, so wonky! -Once the Swift application loads and registers the element, matching tags mount and unmount automatically, including those already on the page. No explicit `Application.mount(in:)` call is needed. +Once the Swift application loads and registers the element, matching tags mount and unmount automatically, including those already on the page. No explicit `ElementaryUI.Application.mount(in:)` call is needed. ## Typed attributes diff --git a/index.md b/index.md index f605ec7..d5c4b79 100644 --- a/index.md +++ b/index.md @@ -16,7 +16,7 @@ hero: link: /guide/introduction - theme: alt text: ⭐️ GitHub - link: http://github.com/elementary-swift/elementary-ui + link: https://github.com/elementary-swift/elementary-ui features: - icon: 🌐 @@ -37,6 +37,9 @@ features: - icon: 🚀 title: Vite-Powered Development details: Fast dev server with hot reload for rapid iteration + - icon: 🧩 + title: Web Components + details: Publish views as typed custom elements for any web page --- <<< @/swift/Sources/Snippets/LoveCounter.swift#snippet