diff --git a/.idea/leptos-use.iml b/.idea/leptos-use.iml
index a753bb6..ba7f802 100644
--- a/.idea/leptos-use.iml
+++ b/.idea/leptos-use.iml
@@ -18,6 +18,7 @@
+
diff --git a/Cargo.toml b/Cargo.toml
index 6eef86a..6c58386 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -14,6 +14,6 @@ repository = "https://github.com/Synphonyte/leptos-use"
[dependencies]
leptos = "0.3"
-web-sys = { version = "0.3", features = ["ScrollToOptions", "ScrollBehavior"] }
+web-sys = { version = "0.3", features = ["ScrollToOptions", "ScrollBehavior", "CssStyleDeclaration"] }
wasm-bindgen = "0.2"
js-sys = "0.3"
\ No newline at end of file
diff --git a/docs/book/post_build.py b/docs/book/post_build.py
index 81bb266..ce8afab 100644
--- a/docs/book/post_build.py
+++ b/docs/book/post_build.py
@@ -24,7 +24,7 @@ def build_and_copy_demo(category, md_name):
example_output_path = os.path.join(example_dir, "dist")
target_path = os.path.join("book", category, name, "demo")
- print(f"Copying demo from {example_output_path} to {target_path}")
+ print(f"Copying demo from {example_output_path} -> {target_path}")
shutil.copytree(example_output_path, target_path,
dirs_exist_ok=True)
diff --git a/docs/book/src/SUMMARY.md b/docs/book/src/SUMMARY.md
index 57c0c9b..2b5eb9f 100644
--- a/docs/book/src/SUMMARY.md
+++ b/docs/book/src/SUMMARY.md
@@ -12,6 +12,10 @@
- [use_event_listener](browser/use_event_listener.md)
+# Sensors
+
+- [use_scroll](sensors/use_scroll.md)
+
# Utilities
- [use_debounce_fn](utilities/use_debounce_fn.md)
diff --git a/docs/book/src/extract_doc_comment.py b/docs/book/src/extract_doc_comment.py
index f796bb7..436fb18 100644
--- a/docs/book/src/extract_doc_comment.py
+++ b/docs/book/src/extract_doc_comment.py
@@ -5,11 +5,19 @@ import re
def main():
name = sys.argv[1]
file_name = f"../../../../src/{name}.rs"
+
+ types = [];
+
with open(file_name) as f:
in_code_block = False
doc_comment_started = False
+ initial_doc_finished = False
+
for line in f.readlines():
- if line.startswith("///"):
+ if initial_doc_finished:
+ process_further_line(line, name, types)
+
+ elif line.startswith("///"):
doc_comment_started = True
line = line.strip().replace("/// ", "").replace("///", "")
if "```" in line:
@@ -20,11 +28,33 @@ def main():
line = process_line(line, name)
print(line)
+
elif doc_comment_started:
- return
+ initial_doc_finished = True
+
+ add_types_paragraph(types)
+ add_source_paragraph(name)
+
+
+def add_types_paragraph(types):
+ if types:
+ print("\n## Types\n")
+ print("\n".join(types))
+
+
+def add_source_paragraph(name):
+ print("\n## Source\n")
+
+ source_url = f"https://github.com/Synphonyte/leptos-use/blob/main/src/{name}.rs"
+ demo_url = f"https://github.com/Synphonyte/leptos-use/tree/main/examples/{name}"
+ docs_url = f"https://docs.rs/leptos-use/latest/leptos_use/fn.{name}.html"
+
+ print(
+ f"Source • Demo • Docs")
interal_doc_link_pattern = re.compile(r"\[`([^]]+)\`](?!\()")
+ident_pattern = re.compile(r"^[a-zA-Z_][a-zA-Z0-9_]*\b")
def process_line(line, name):
@@ -37,7 +67,6 @@ def process_line(line, name):
source
'''
-
else:
result = re.sub(interal_doc_link_pattern,
r"[`\1`](https://docs.rs/leptos-use/latest/leptos_use/fn.\1.html)",
@@ -46,5 +75,20 @@ def process_line(line, name):
return result
+def process_further_line(line, name, types):
+ if line.startswith("pub enum"):
+ append_type(line, "enum", types)
+ elif line.startswith("pub struct"):
+ append_type(line, "struct", types)
+
+
+def append_type(line, ty, types):
+ start_index = len(f"pub {ty} ")
+ m = re.search(ident_pattern, line[start_index:])
+ if m is not None:
+ ident = m.group(0)
+ types.append(f"- [`{ty} {ident}`](https://docs.rs/leptos-use/latest/leptos_use/{ty}.{ident}.html)")
+
+
if __name__ == '__main__':
main()
diff --git a/docs/book/src/getting_started/get_started.md b/docs/book/src/getting_started/get_started.md
index 3ed6d76..85fcfdf 100644
--- a/docs/book/src/getting_started/get_started.md
+++ b/docs/book/src/getting_started/get_started.md
@@ -8,7 +8,7 @@ cargo add leptos-use
## Examples
-- [Examples Directory](https://github.com/Synphonyte/leptos-use/tree/master/examples)
+- [Examples Directory](https://github.com/Synphonyte/leptos-use/tree/main/examples)
## Usage Example
diff --git a/docs/book/src/sensors/use_scroll.md b/docs/book/src/sensors/use_scroll.md
index 88d257b..1e27f2a 100644
--- a/docs/book/src/sensors/use_scroll.md
+++ b/docs/book/src/sensors/use_scroll.md
@@ -1,3 +1,3 @@
-# use_event_listener
+# use_scroll
diff --git a/src/lib.rs b/src/lib.rs
index adc221c..9fcce26 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,11 +1,15 @@
+//! Collection of essential Leptos utilities inspired by SolidJS USE / VueUse
+
pub mod core;
-pub mod use_debounce_fn;
-pub mod use_event_listener;
-pub mod use_scroll;
-pub mod use_throttle_fn;
+mod use_debounce_fn;
+mod use_event_listener;
+mod use_scroll;
+mod use_throttle_fn;
pub mod utils;
pub use use_debounce_fn::*;
pub use use_event_listener::use_event_listener;
pub use use_scroll::*;
pub use use_throttle_fn::*;
+
+extern crate self as leptos_use;
diff --git a/src/use_debounce_fn.rs b/src/use_debounce_fn.rs
index 7e92bf1..e71ffee 100644
--- a/src/use_debounce_fn.rs
+++ b/src/use_debounce_fn.rs
@@ -1,6 +1,5 @@
-use crate::utils::{
- create_filter_wrapper, create_filter_wrapper_with_arg, debounce_filter, DebounceOptions,
-};
+pub use crate::utils::DebounceOptions;
+use crate::utils::{create_filter_wrapper, create_filter_wrapper_with_arg, debounce_filter};
use leptos::MaybeSignal;
/// Debounce execution of a function.
@@ -9,7 +8,7 @@ use leptos::MaybeSignal;
///
/// ## Demo
///
-/// [Link to Demo](https://github.com/Synphonyte/leptos-use/tree/master/examples/use_debounce_fn)
+/// [Link to Demo](https://github.com/Synphonyte/leptos-use/tree/main/examples/use_debounce_fn)
///
/// ## Usage
///
@@ -87,7 +86,10 @@ where
}
/// Version of [`use_debounce_fn`] with an argument for the debounced function. See the docs for [`use_debounce_fn`] for how to use.
-pub fn use_debounce_fn_with_arg(func: F, ms: impl Into>) -> impl Fn(Arg)
+pub fn use_debounce_fn_with_arg(
+ func: F,
+ ms: impl Into>,
+) -> impl Fn(Arg) + Clone
where
F: FnOnce(Arg) + Clone + 'static,
Arg: Clone + 'static,
@@ -95,12 +97,12 @@ where
use_debounce_fn_with_arg_and_options(func, ms, DebounceOptions::