diff --git a/.cargo/config.toml b/.cargo/config.toml
index b891103..eac64d8 100644
--- a/.cargo/config.toml
+++ b/.cargo/config.toml
@@ -1,3 +1,3 @@
-[unstable]
+[build]
rustflags = ["--cfg=web_sys_unstable_apis"]
-rustdocflags = ["--cfg=web_sys_unstable_apis"]
\ No newline at end of file
+rustdocflags = ["--cfg=web_sys_unstable_apis"]
diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml
new file mode 100644
index 0000000..b1e6e05
--- /dev/null
+++ b/.github/workflows/cd.yml
@@ -0,0 +1,82 @@
+on:
+ push:
+ # Pattern matched against refs/tags
+ tags:
+ - '*' # Push events to every tag not containing /
+ workflow_dispatch:
+
+name: CD
+
+permissions: write-all
+
+jobs:
+ publish:
+ name: Publish
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - uses: actions-rs/toolchain@v1
+ with:
+ toolchain: nightly
+ profile: minimal
+ override: true
+ components: rustfmt, clippy, rust-src
+ - name: Cache
+ uses: Swatinem/rust-cache@v2
+ - name: Check function count badge
+ run: python3 docs/generate_count_badge.py --check
+ - name: Check version in docs
+ run: python3 docs/add_version_to_docs.py --check
+ - name: Check formatting
+ run: cargo fmt --check
+ - name: Clippy
+ run: cargo clippy --features docs,math --tests -- -D warnings
+ - name: Run tests (general)
+ run: cargo test --features math,docs,ssr
+ - name: Run tests (axum)
+ run: cargo test --features math,docs,ssr,axum --doc use_cookie::use_cookie
+ - name: Run tests (actix)
+ run: cargo test --features math,docs,ssr,actix --doc use_cookie::use_cookie
+
+ #### mdbook
+ - name: Install mdbook I
+ uses: taiki-e/install-action@v2
+ with:
+ tool: cargo-binstall,mdbook
+ - name: Install mdbook II
+ run: |
+ cargo binstall -y mdbook-cmdrun
+ cargo binstall -y trunk@0.17.5
+ rustup target add wasm32-unknown-unknown
+ - name: Setup Pages
+ id: pages
+ uses: actions/configure-pages@v3
+ - name: Build mdbook # TODO : run mdbook tests
+ run: |
+ cd docs/book
+ mdbook build
+ python3 post_build.py
+ - name: Upload artifact
+ uses: actions/upload-pages-artifact@v1
+ with:
+ path: ./docs/book/book
+ - name: Deploy book to github pages
+ id: deployment
+ uses: actions/deploy-pages@v2
+ ##### mdbook end
+
+ - name: Publish crate leptos-use
+ uses: katyo/publish-crates@v2
+ with:
+ registry-token: ${{ secrets.CRATES_TOKEN }}
+
+ - uses: CSchoel/release-notes-from-changelog@v1
+ - name: Create Release using GitHub CLI
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: >
+ gh release create
+ -d
+ -F RELEASE.md
+ -t "Version $RELEASE_VERSION"
+ ${GITHUB_REF#refs/*/}
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 95f75d3..b44b27e 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1,82 +1,48 @@
+name: Continuous Integration
+
on:
- push:
- # Pattern matched against refs/tags
- tags:
- - '*' # Push events to every tag not containing /
- workflow_dispatch:
+ pull_request:
+ branches:
+ - main
+ paths:
+ - "**"
+ - "!/*.md"
+ - "!/**.md"
-name: CI
-
-permissions: write-all
+concurrency:
+ group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
+ cancel-in-progress: true
jobs:
- publish:
- name: Publish
+ integrity:
+ name: Integrity Checks on Rust ${{ matrix.toolchain }}
runs-on: ubuntu-latest
+ timeout-minutes: 15
+ strategy:
+ matrix:
+ toolchain:
+ - stable
+ - nightly
+
steps:
- - uses: actions/checkout@v3
- - uses: actions-rs/toolchain@v1
+ - name: Checkout
+ uses: actions/checkout@v4
+
+ - name: Setup Rust
+ uses: dtolnay/rust-toolchain@master
with:
- toolchain: nightly
- profile: minimal
- override: true
- components: rustfmt, clippy, rust-src
- - name: Cache
+ toolchain: ${{ matrix.toolchain }}
+ targets: wasm32-unknown-unknown
+ components: clippy, rustfmt
+
+ - name: Setup Rust Cache
uses: Swatinem/rust-cache@v2
- - name: Check function count badge
- run: python3 docs/generate_count_badge.py --check
- - name: Check version in docs
- run: python3 docs/add_version_to_docs.py --check
- - name: Check formatting
+
+ - name: Build
+ run: cargo build
+
+ - name: Format
run: cargo fmt --check
+
- name: Clippy
- run: cargo clippy --features docs,math --tests -- -D warnings
- - name: Run tests (general)
- run: cargo test --features math,docs,ssr
- - name: Run tests (axum)
- run: cargo test --features math,docs,ssr,axum --doc use_cookie::use_cookie
- - name: Run tests (actix)
- run: cargo test --features math,docs,ssr,actix --doc use_cookie::use_cookie
-
- #### mdbook
- - name: Install mdbook I
- uses: taiki-e/install-action@v2
- with:
- tool: cargo-binstall,mdbook
- - name: Install mdbook II
- run: |
- cargo binstall -y mdbook-cmdrun
- cargo binstall -y trunk@0.17.5
- rustup target add wasm32-unknown-unknown
- - name: Setup Pages
- id: pages
- uses: actions/configure-pages@v3
- - name: Build mdbook # TODO : run mdbook tests
- run: |
- cd docs/book
- mdbook build
- python3 post_build.py
- - name: Upload artifact
- uses: actions/upload-pages-artifact@v1
- with:
- path: ./docs/book/book
- - name: Deploy book to github pages
- id: deployment
- uses: actions/deploy-pages@v2
- ##### mdbook end
-
- - name: Publish crate leptos-use
- uses: katyo/publish-crates@v2
- with:
- registry-token: ${{ secrets.CRATES_TOKEN }}
-
- - uses: CSchoel/release-notes-from-changelog@v1
- - name: Create Release using GitHub CLI
- env:
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: >
- gh release create
- -d
- -F RELEASE.md
- -t "Version $RELEASE_VERSION"
- ${GITHUB_REF#refs/*/}
+ run: cargo clippy -- -D warnings
diff --git a/.idea/leptos-use.iml b/.idea/leptos-use.iml
index 7d56fcb..b65a8a2 100644
--- a/.idea/leptos-use.iml
+++ b/.idea/leptos-use.iml
@@ -77,6 +77,7 @@
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f0ab304..cba1230 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,7 +3,7 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
-## [Unreleased]
+## [0.11.0] - 2024-07-27
### Breaking Changes 🛠
@@ -50,8 +50,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `JsonCodec` has been renamed to `JsonSerdeCodec`.
- The feature to enable this codec is now called `json_serde` instead of just `serde`.
- `ProstCodec` now encodes as binary data. If you want to keep using it with string data you can wrap it like
- this: `Base64`. You have to enable both features `prost` and `base64` for this.
+ this: `Base64`.
- All of these structs, traits and features now live in their own crate called `codee`
+ - A bunch of new codecs are available. Have a look at the docs for crate `codee`.
- `use_websocket`:
- `UseWebsocketOptions` has been renamed to `UseWebSocketOptions` (uppercase S) to be consistent with the return
type.
@@ -70,12 +71,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
to `on_message_raw` and `on_message_raw_bytes`.
- The new `UseWebSocketOptions::on_message` takes a `&T`.
- `UseWebSocketOptions::on_error` now takes a `UseWebSocketError` instead of a `web_sys::Event`.
-- `use_storage` now always saves the default value to storage if the key doesn't exist yet.
+- `use_storage` now always saves the default value to storage if the key doesn't exist yet.
+- Renamed `BreakpointsSematic` to `BreakpointsSemantic` and `breakpoints_sematic` to `breakpoints_semantic`
+ (note the `n`) (thanks to @mondeja).
### Fixes 🍕
- Fixed auto-reconnect in `use_websocket`
- Fixed typo in compiler error messages in `use_cookie` (thanks to @SleeplessOne1917).
+- Fixed potential signal out of scope issue with `use_raf_fn`
+
+### Other Changes 🔥
+
+- Better links in docs that work both in the book and in rustdoc (thanks to @mondeja).
+- Better CI/CD (thanks to @EstebanBorai).
## [0.10.10] - 2024-05-10
diff --git a/Cargo.toml b/Cargo.toml
index 810b7a0..016d645 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "leptos-use"
-version = "0.10.10"
+version = "0.11.0"
edition = "2021"
authors = ["Marc-Stefan Cassola"]
categories = ["gui", "web-programming"]
diff --git a/README.md b/README.md
index 13ff7c3..b432e0f 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@
-
+
@@ -24,7 +24,7 @@
[![Docs](https://docs.rs/leptos-use/badge.svg)](https://docs.rs/leptos-use/)
[![MIT/Apache 2.0](https://img.shields.io/badge/license-MIT%2FApache-blue.svg)](https://github.com/synphonyte/leptos-use#license)
-[![Build Status](https://github.com/synphonyte/leptos-use/actions/workflows/ci.yml/badge.svg)](https://github.com/synphonyte/leptos-use/actions/workflows/ci.yml)
+[![Build Status](https://github.com/synphonyte/leptos-use/actions/workflows/cd.yml/badge.svg)](https://github.com/synphonyte/leptos-use/actions/workflows/cd.yml)
[![Discord](https://img.shields.io/discord/1031524867910148188?color=%237289DA&label=discord)](https://discord.com/channels/1031524867910148188/1121154537709895783)
```rust
@@ -92,4 +92,4 @@ This will create the function file in the src directory, scaffold an example dir
| <= 0.3 | 0.3 |
| 0.4, 0.5, 0.6 | 0.4 |
| 0.7, 0.8, 0.9 | 0.5 |
-| 0.10 | 0.6 |
\ No newline at end of file
+| 0.10, 0.11 | 0.6 |
diff --git a/docs/book/post_build.py b/docs/book/post_build.py
index 1abc3a2..20691a8 100644
--- a/docs/book/post_build.py
+++ b/docs/book/post_build.py
@@ -13,7 +13,8 @@ def main():
if os.path.isdir(category_dir):
for file in os.listdir(category_dir):
if file.endswith(".md") and (len(sys.argv) == 1 or (sys.argv[1] in file)):
- build_and_copy_demo(category, file)
+ if build_and_copy_demo(category, file):
+ rewrite_links(category, file)
def build_and_copy_demo(category, md_name):
@@ -24,7 +25,8 @@ def build_and_copy_demo(category, md_name):
code = p.wait()
if code != 0:
- sys.exit(code, f"failed to build example '{name}'")
+ sys.stderr.write(f"failed to build example '{name}'\n")
+ sys.exit(code)
example_output_path = os.path.join(example_dir, "dist")
target_path = os.path.join("book", category, name, "demo")
@@ -49,7 +51,7 @@ def build_and_copy_demo(category, md_name):
with open(book_html_path, "w") as f:
f.write(
- f"""{head_split[0]}
+ f"""{head_split[0]}
{demo_head}
{target_head}
@@ -60,6 +62,32 @@ def build_and_copy_demo(category, md_name):
{body_split[1]}""")
+ return True
+
+ return False
+
+
+def rewrite_links(category, md_name):
+ """Rewrite links in generated documentation to make them
+ compatible between rustdoc and the book.
+ """
+ html_name = f"{md_name[:-3]}.html"
+ target_path = os.path.join("book", category, html_name)
+
+ with open(target_path, "r") as f:
+ html = f.read()
+
+ html = html.replace(
+ "fn@crate::", "",
+ ).replace(
+ "crate::", "",
+ ).replace(
+ "fn@", "",
+ )
+
+ with open(target_path, "w") as f:
+ f.write(html)
+
if __name__ == '__main__':
main()
diff --git a/docs/book/src/introduction.md b/docs/book/src/introduction.md
index f12ec1b..cf0098a 100644
--- a/docs/book/src/introduction.md
+++ b/docs/book/src/introduction.md
@@ -12,6 +12,6 @@
-
+
\ No newline at end of file
diff --git a/examples/ssr/Cargo.toml b/examples/ssr/Cargo.toml
index d0b6e6a..5d71626 100644
--- a/examples/ssr/Cargo.toml
+++ b/examples/ssr/Cargo.toml
@@ -8,6 +8,7 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
axum = { version = "0.7", optional = true }
+codee = "0.1"
console_error_panic_hook = "0.1"
console_log = "1"
cfg-if = "1"
diff --git a/examples/ssr/src/app.rs b/examples/ssr/src/app.rs
index 3f25751..fed3766 100644
--- a/examples/ssr/src/app.rs
+++ b/examples/ssr/src/app.rs
@@ -4,7 +4,7 @@ use leptos::prelude::*;
use leptos_meta::*;
use leptos_router::*;
use leptos_use::storage::{use_local_storage, use_local_storage_with_options, UseStorageOptions};
-use leptos_use::utils::FromToStringCodec;
+use codee::string::FromToStringCodec;
use leptos_use::{
use_color_mode_with_options, use_cookie_with_options, use_debounce_fn, use_event_listener,
use_interval, use_intl_number_format, use_preferred_dark, use_timestamp, use_window, ColorMode,
@@ -78,7 +78,7 @@ fn HomePage() -> impl IntoView {
let (test_cookie, _) = use_cookie_with_options::(
"test-cookie",
- UseCookieOptions::::default()
+ UseCookieOptions::::default()
.max_age(3000)
.default_value(Some("Bogus string".to_owned())),
);
diff --git a/examples/use_broadcast_channel/Cargo.toml b/examples/use_broadcast_channel/Cargo.toml
index 6a95089..a7bf756 100644
--- a/examples/use_broadcast_channel/Cargo.toml
+++ b/examples/use_broadcast_channel/Cargo.toml
@@ -5,6 +5,7 @@ edition = "2021"
[dependencies]
leptos = { version = "0.6", features = ["nightly", "csr"] }
+codee = "0.1"
console_error_panic_hook = "0.1"
console_log = "1"
log = "0.4"
diff --git a/examples/use_broadcast_channel/src/main.rs b/examples/use_broadcast_channel/src/main.rs
index cbec90e..124f8bf 100644
--- a/examples/use_broadcast_channel/src/main.rs
+++ b/examples/use_broadcast_channel/src/main.rs
@@ -1,6 +1,6 @@
+use codee::string::FromToStringCodec;
use leptos::prelude::*;
use leptos_use::docs::demo_or_body;
-use leptos_use::utils::FromToStringCodec;
use leptos_use::{use_broadcast_channel, UseBroadcastChannelReturn};
#[component]
@@ -46,8 +46,8 @@ fn Demo() -> impl IntoView {
"Received message: " {move || message().as_ref().unwrap().to_string()}
-
- "Error: " {move || format!("{:?}", error().as_ref().unwrap())}
+
+ "Error: " {move || error.with(|e| format!("{:?}", e.as_ref().unwrap()))}
}
diff --git a/examples/use_clipboard/src/main.rs b/examples/use_clipboard/src/main.rs
index d54195a..04d0108 100644
--- a/examples/use_clipboard/src/main.rs
+++ b/examples/use_clipboard/src/main.rs
@@ -1,6 +1,8 @@
use leptos::prelude::*;
use leptos_use::docs::{demo_or_body, Note};
-use leptos_use::{use_clipboard, use_permission, UseClipboardReturn};
+use leptos_use::{
+ use_clipboard_with_options, use_permission, UseClipboardOptions, UseClipboardReturn,
+};
#[component]
fn Demo() -> impl IntoView {
@@ -11,7 +13,7 @@ fn Demo() -> impl IntoView {
text,
copied,
copy,
- } = use_clipboard();
+ } = use_clipboard_with_options(UseClipboardOptions::default().read(true));
let permission_read = use_permission("clipboard-read");
let permission_write = use_permission("clipboard-write");
diff --git a/examples/use_cookie/Cargo.toml b/examples/use_cookie/Cargo.toml
index 280824f..c645550 100644
--- a/examples/use_cookie/Cargo.toml
+++ b/examples/use_cookie/Cargo.toml
@@ -5,6 +5,7 @@ edition = "2021"
[dependencies]
leptos = { version = "0.6", features = ["nightly", "csr"] }
+codee = "0.1"
console_error_panic_hook = "0.1"
console_log = "1"
log = "0.4"
diff --git a/examples/use_cookie/src/main.rs b/examples/use_cookie/src/main.rs
index ffff3ff..75fb31c 100644
--- a/examples/use_cookie/src/main.rs
+++ b/examples/use_cookie/src/main.rs
@@ -1,7 +1,7 @@
use leptos::prelude::*;
use leptos_use::docs::demo_or_body;
use leptos_use::use_cookie;
-use leptos_use::utils::FromToStringCodec;
+use codee::string::FromToStringCodec;
use rand::prelude::*;
#[component]
diff --git a/examples/use_storage/Cargo.toml b/examples/use_storage/Cargo.toml
index 4a53065..5174789 100644
--- a/examples/use_storage/Cargo.toml
+++ b/examples/use_storage/Cargo.toml
@@ -4,14 +4,14 @@ version = "0.1.0"
edition = "2021"
[dependencies]
-codee = { path = "../../../codee", features = ["json_serde"] }
-leptos = { version = "0.6", features = ["nightly", "csr"] }
+codee = { version = "0.1", features = ["json_serde"] }
console_error_panic_hook = "0.1"
console_log = "1"
-log = "0.4"
+leptos = { version = "0.6", features = ["nightly", "csr"] }
leptos-use = { path = "../..", features = ["docs"] }
-web-sys = "0.3"
+log = "0.4"
serde = "1.0.163"
+web-sys = "0.3"
[dev-dependencies]
wasm-bindgen = "0.2"
diff --git a/examples/use_storage/src/main.rs b/examples/use_storage/src/main.rs
index 4ae5423..5cdb26e 100644
--- a/examples/use_storage/src/main.rs
+++ b/examples/use_storage/src/main.rs
@@ -1,7 +1,7 @@
use leptos::prelude::*;
use leptos_use::docs::{demo_or_body, Note};
use leptos_use::storage::use_local_storage;
-use leptos_use::utils::JsonCodec;
+use codee::string::JsonSerdeCodec;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
@@ -25,8 +25,8 @@ impl Default for BananaState {
#[component]
fn Demo() -> impl IntoView {
- let (state, set_state, reset) = use_local_storage::("banana-state");
- let (state2, _, _) = use_local_storage::("banana-state");
+ let (state, set_state, reset) = use_local_storage::("banana-state");
+ let (state2, _, _) = use_local_storage::("banana-state");
view! {
` where `T` is the web_sys element,
/// * a `Signal` where `T` is the web_sys element,
/// * a `Signal