Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
a952f00
wip
ltfschoen Mar 27, 2023
bfae234
wip
ltfschoen Mar 27, 2023
916cf92
finish invoice example
ltfschoen Mar 27, 2023
d6b170d
try debug
ltfschoen Mar 31, 2023
dfc527f
wasm-logger
ltfschoen Mar 31, 2023
21160ee
wip
ltfschoen Apr 1, 2023
351a9a1
wip
ltfschoen Apr 1, 2023
7abedf5
wip
ltfschoen Apr 2, 2023
66cfead
remove rubbish stuff
ltfschoen Apr 2, 2023
2efc7da
remove more
ltfschoen Apr 2, 2023
604174d
wip
ltfschoen Apr 3, 2023
d9da6dd
qr code per task
ltfschoen Apr 3, 2023
100f533
enter billing address required to exit edit
ltfschoen Apr 3, 2023
d8d8e2f
wip
ltfschoen Apr 3, 2023
c71f49f
use Branch3. see issue #51
ltfschoen Apr 3, 2023
eec4d43
wip
ltfschoen Apr 3, 2023
dc0166e
use only Table instead of also TableFileDetails
ltfschoen Apr 3, 2023
833b66c
refactor to use Content per issue #53
ltfschoen Apr 3, 2023
83dd40c
fix EntryView value shown to load from details.csv file then still be…
ltfschoen Apr 3, 2023
ab0aa29
use bevy_reflect
ltfschoen Apr 4, 2023
d0b10e4
remove draft proc macro as not necessary
ltfschoen Apr 4, 2023
2078370
fix
ltfschoen Apr 4, 2023
69674e6
wip - not working
ltfschoen Apr 4, 2023
0b46f8c
wip
ltfschoen Apr 4, 2023
8123bf0
Merge branch 'master' into luke/invoice-debug
ltfschoen Apr 4, 2023
b4cc0db
update versions
ltfschoen Apr 4, 2023
f8a9f6d
simplify to use less Vectors
ltfschoen Apr 4, 2023
3e2f55b
refactor into separate function for testing
ltfschoen Apr 4, 2023
f9393bc
unit tests in separate file
ltfschoen Apr 4, 2023
084db0e
incorporate feedback from issue #58
ltfschoen Apr 4, 2023
43c821c
incorporate feedback declare event handlers inside map
ltfschoen Apr 4, 2023
c228fab
add placeholders to input fields of details from file
ltfschoen Apr 4, 2023
602109c
wip
ltfschoen Apr 4, 2023
e4d838c
wip
ltfschoen Apr 4, 2023
f8eca34
wip
ltfschoen Apr 4, 2023
ad44c2a
wip
ltfschoen Apr 4, 2023
f1fe014
wip
ltfschoen Apr 4, 2023
d4365c0
refactor into DetailEditing and DetailView
ltfschoen Apr 4, 2023
91448fa
remove OptionalClass
ltfschoen Apr 4, 2023
9659245
wip
ltfschoen Apr 5, 2023
2b10552
display details with head as column on left
ltfschoen Apr 5, 2023
96cc445
qr code with format
ltfschoen Apr 5, 2023
9305329
wip
ltfschoen Apr 5, 2023
c781b0f
temporarily comment out custom code
ltfschoen Apr 5, 2023
89287dd
incomplete
ltfschoen Apr 6, 2023
334ae49
wip
ltfschoen Apr 7, 2023
61da556
fix
ltfschoen Apr 7, 2023
c3fd1f2
simplify
ltfschoen Apr 25, 2023
8b2bb08
remove old get_data_for_col
ltfschoen Apr 25, 2023
56fd15d
update details table. causes memory access out of bounds. edits dont …
ltfschoen Apr 25, 2023
4ff1bdf
fix so it updates edited cells in LocalStorage rows as Owned values
ltfschoen Apr 25, 2023
ea2df1f
refreshing page loads from local storage instead of mock data
ltfschoen Apr 26, 2023
e19514d
update local storage with data when loaded from csv file
ltfschoen Apr 26, 2023
e27b860
remove my code that uses serde to get parts of table
ltfschoen Apr 26, 2023
3e494c1
wip
ltfschoen Apr 26, 2023
6862305
try to write to details Table to details.csv file but panics
ltfschoen Apr 26, 2023
0a023e8
wip csv file download
ltfschoen Apr 26, 2023
d19d417
wip csv file download cleanup old stuff
ltfschoen Apr 26, 2023
3b482f3
fix so clicking generates csv download url works and clicking downloa…
ltfschoen Apr 28, 2023
c8efcf7
simpler approach to replacing element in vector using core::mem::replace
ltfschoen Apr 28, 2023
362da38
use iterators
ltfschoen Apr 28, 2023
965e178
move css into separate file
ltfschoen Apr 28, 2023
50f3403
feat: single click of button in UI downloads CSV with latest changes …
ltfschoen Apr 29, 2023
d842a92
fix indentation
ltfschoen Apr 29, 2023
41d435c
feat: style the choose file button
ltfschoen Apr 29, 2023
03b3abd
remove old code that used bevy reflect
ltfschoen Apr 29, 2023
24f68e1
merge master and fix conflicts
ltfschoen Apr 29, 2023
240aed2
update fixing merge conflict that was not yet fixed
ltfschoen Apr 29, 2023
7cfcfcb
updating to kobold 0.8.0 broke save and upload
ltfschoen Apr 29, 2023
b1f549e
replace update with update_silent to access state without triggering …
ltfschoen Apr 29, 2023
3b997b4
rename editing to editing_main. conditionally render hint only if not…
ltfschoen Apr 29, 2023
49a8112
add fn to auto click details save file button on init load so when us…
ltfschoen Apr 30, 2023
c5a4a32
save file button disabled shown in grey until user edits a cell then …
ltfschoen Apr 30, 2023
5e69cf8
closure without condition for on_mount
ltfschoen Apr 30, 2023
d414093
wip - try to get it to re-render updated state.details.table in UI af…
ltfschoen Apr 30, 2023
4b9de75
Merge branch 'master' into luke/invoice-debug
ltfschoen Apr 30, 2023
5e0e1b8
switch back to using update instead of update_silent since upstream f…
ltfschoen Apr 30, 2023
0383323
refactor using Maciej click approach. clean up
ltfschoen Apr 30, 2023
d86415f
remove update_main and update_details since already done by onchange
ltfschoen Apr 30, 2023
d141f49
cargo fmt to pass ci tests
ltfschoen Apr 30, 2023
ee328a7
refactor moving components into separate files and folder
ltfschoen Apr 30, 2023
d390250
restore Editor
ltfschoen Apr 30, 2023
0badc18
move Editor into components folder. move csv data into data folder
ltfschoen Apr 30, 2023
136d2fc
refactor onload_main and onload_details into onload_common
ltfschoen Apr 30, 2023
3f7277e
use enum for TableVariants Main and Details
ltfschoen Apr 30, 2023
1626aa0
pretty main table upload button
ltfschoen May 1, 2023
ca7db6e
add save csv for main. refactor into common save csv function. add di…
ltfschoen May 1, 2023
3b7e3b5
cargo fmt to pass ci tests
ltfschoen May 1, 2023
c664329
Merge branch 'master' into luke/invoice-debug
ltfschoen May 1, 2023
275a363
upload multiple times from same details.csv file
ltfschoen May 1, 2023
daa517a
fix so can upload multiple times simple solution. hide traditional fi…
ltfschoen May 1, 2023
1a24dd6
add test for function update_csv_row_for_modified_table_cells
ltfschoen May 1, 2023
79433ce
validate qty of rows and columns being downloaded. pad extra labels w…
ltfschoen May 1, 2023
1abbb65
cargo fmt
ltfschoen May 1, 2023
6f08bb3
cleaner solution to setting file input field value to null after gett…
ltfschoen May 1, 2023
07f4f59
refactor padding columns into common function
ltfschoen May 1, 2023
8f2abfd
add test for pad_csv_data
ltfschoen May 1, 2023
df94e93
refactor into csv helpers. refactor common validation function for co…
ltfschoen May 1, 2023
e399e31
cargo fmt
ltfschoen May 1, 2023
60bc7b8
refactor to use get(state) to minimise need to use TableVariant condi…
ltfschoen May 1, 2023
e8dc39e
bind_async closure needs to return the future onload_common returns f…
ltfschoen May 2, 2023
391fc51
rename TableVariants to TableVariant singular
ltfschoen May 2, 2023
9240041
provide table variant at start of CSV file prefixed with a hash and e…
ltfschoen May 2, 2023
7995e72
use the table variant type corresponding to the button they pressed i…
ltfschoen May 2, 2023
6b0e519
when saving file to prefix csv file data with table variant stored in…
ltfschoen May 3, 2023
71c9b67
update readme
ltfschoen May 3, 2023
6c2b281
remove useless old stuff
ltfschoen May 3, 2023
8e1fd25
fix by renaming the variables row from the details table. move labels…
ltfschoen May 3, 2023
e8dea20
add logo component
ltfschoen May 4, 2023
abc541a
fix example csv files to include table variant prefix and remove vari…
ltfschoen May 4, 2023
cd8ac98
remove disused css
ltfschoen May 4, 2023
4188eeb
wip remove row
ltfschoen May 5, 2023
2e5a5f6
wip remove row - error out of bounds on get_text
ltfschoen May 5, 2023
fcd5c13
wip remove row - try fix using js but same error
ltfschoen May 6, 2023
643cd07
fix Header to use .columns not .rows. remove div for delete row butto…
ltfschoen May 6, 2023
b7e60f9
remove row - fix byte out of bound error so it works. was not updatin…
ltfschoen May 7, 2023
29e9389
remove useless remove row using extern c since not necessary
ltfschoen May 7, 2023
45e3f1c
refactor last_insitu_range_end into common fn. fix so users can delet…
ltfschoen May 7, 2023
75aa4e9
remove row wip
ltfschoen May 7, 2023
e17e7c4
finish remove row - unnecessary complexity taken out
ltfschoen May 8, 2023
d10948e
update readme and cargo fmt
ltfschoen May 8, 2023
4c6f678
refactor generation of remove row element id to a closure and pass to…
ltfschoen May 8, 2023
b0ec99a
pretty the destroy row button with transparent border and background
ltfschoen May 8, 2023
ac0ae20
finish add row button feature to main table
ltfschoen May 8, 2023
bfa91c4
update readme with add row feature
ltfschoen May 8, 2023
de6beb8
bulk upload both table files at once. saving tables must be done indi…
ltfschoen May 8, 2023
854c27b
remove fn passed to child generate_remove_row_id_for_row since not re…
ltfschoen May 8, 2023
444a8b6
rename onremove to ondestroy
ltfschoen May 8, 2023
c29ba76
wip ButtonAddRow broken
ltfschoen May 8, 2023
096f15b
stick table head row for main table when scrolling
ltfschoen May 9, 2023
1c7a36a
ButtonAddRow pass row and Hook with onclick handler internally in child
ltfschoen May 9, 2023
8036673
restore uploading individual csv files since users if any might not w…
ltfschoen May 9, 2023
1f190ad
refactor ButtonAddRow and ButtonDestroyRow into separate components
ltfschoen May 9, 2023
f671a1d
update licensing
ltfschoen May 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 97 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Because the `view!` macro produces unique transient types, `if` and `match` expr
the macro will naturally fail to compile.

Using the `auto_branch` flag on the `#[component]` attribute
**Kobold** will scan the body of of your component render function, and make all `view!` macro invocations
**Kobold** will scan the body of your component render function, and make all `view!` macro invocations
inside an `if` or `match` expression, and wrap them in an enum making them the same type:

```rust
Expand Down
2 changes: 1 addition & 1 deletion crates/kobold/src/stateful/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::View;
/// A hook into some state `S`. A reference to `Hook` is obtained by using the [`stateful`](crate::stateful::stateful)
/// function.
///
/// Hook can be read from though its `Deref` implementation, and it allows for mutations either by [`bind`ing](Hook::bind)
/// Hook can be read from through its `Deref` implementation, and it allows for mutations by [`bind`ing](Hook::bind)
/// closures to it.
#[repr(transparent)]
pub struct Hook<S> {
Expand Down
2 changes: 1 addition & 1 deletion crates/kobold_qr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn KoboldQR(data: &str, size: usize) -> impl View + '_ {

Some(
view! {
<canvas width={pixels} height={pixels} {style} />
<canvas width={pixels} height={pixels} style="width: 50px; height: 50px;" />
}
.on_render(move |canvas| {
let ctx = match canvas.get_context("2d") {
Expand Down
40 changes: 40 additions & 0 deletions examples/invoice/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[package]
name = "kobold_invoice"
version = "0.1.0"
edition = "2021"

[[bin]]
name = "main"
path = "src/main.rs"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
kobold = { version = "0.8.0", path = "../../crates/kobold" }
kobold_macros = { version = "0.8.0", path = "../../crates/kobold_macros" }
kobold_qr = { version = "0.8.0", path = "../../crates/kobold_qr" }
compact_str = "0.7.0"
gloo-console = "0.2.3"
gloo-file = "0.2.3"
gloo-storage = "0.2.1"
gloo-utils = { version = "0.1.2", features = ["serde"] }
heck = "0.4.1"
js-sys = "0.3.61"
log = "0.4.17"
logos = "0.12.1"
serde = "1.0.159"
serde_json = "1.0.95"
take_mut = "0.2.2"
wasm-bindgen = "0.2.84"
wasm-bindgen-futures = "0.4.34"
wasm-logger = "0.2.0"

[dependencies.web-sys]
version = "0.3.61"
features = [
"console",
"Document",
"HtmlInputElement",
"File",
"FileList",
]
58 changes: 58 additions & 0 deletions examples/invoice/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
* Usage
* Run the following from the project root directory:
```
cd examples/invoice/
cargo install --locked trunk
RUST_LOG=info trunk serve --address=127.0.0.1 --open
```
* Open in web browser http://localhost:8080
* Upload, edit (saves in local storage), and download a backup to a CSV file for the "Main" table
* Create a text file similar to the example in folder ./data/main.csv and `mock_file_main` in state.rs, prefixed with `#main,`.
* Note: It looks like there is an additional column on the first row but that cell will be removed during the upload process and used to populate a `TableVariant` value in the state that is reflected in Local Storage
* Upload a file by clicking "Upload CSV file (Main) to upload it in the "Main" table
* View the file in the UI and serialised in browser Local Storage under key `kobald.invoice.main`
* Modify the table by double clicking cells and pressing escape or enter to save
* Add rows to the "Main" table if required by clicking the "+" icon above where you want to insert a new row
* Remove rows from the "Main" table if required by clicking the "X" icon on that row
* Save a backup of the file by clicking the associated "Save to CSV file" button
* Note: The downloaded file should be prefixed with `#main,` to indicate it uses the `TableVariant::Main` table
* Upload, edit (saves in local storage), and download a backup to a CSV file for the "Details" table
* Repeat steps used for the "Main" table, but similar to example in folder ./data/details.csv and `mock_file_details` in state.rs, and prefixed with `#details,` instead, and stored under `kobald.invoice.details` in Local Storage instead.

* Contributing Guidelines
* Format `cargo fmt --all` before pushing commits
* Test with `cargo test` before pushing commits

* Browser Compatibility:
* Brave Version 1.50.121 Chromium: 112.0.5615.138 (Official Build) (x86_64)
* Chrome Version 112.0.5615.137 (Official Build) (x86_64)
* Firefox Version 112.0.2 (64-bit)

* Notes:
* Best Practice
* Use `&str` and avoid `String`
* Troubleshooting
* If you try to pass a function to a child component through props with `impl Listener<MouseEvent<HtmlElement>>` or `&dyn Fn(&mut State, MouseEvent<HtmlElement>)` or `pub fn MyChildComponent<F: Fn(&mut State, MouseEvent<HtmlElement>)>(onfoobar_fn: F) -> impl View {` or by passing a bound closure `pub fn MyChildComponent<F: Listener<MouseEvent<HtmlElement>>>(onfoobar_fn: F) -> impl View {` using kobold::event::Listener (https://docs.rs/kobold/latest/kobold/event/trait.Listener.html) that calls a function that is defined in a parent component and manipulates the state then you may encounter errors, which is not yet supported in Kobold. In the meantime just pass a `state: &Hook<State>` prop to the child component and interact with the state in an `onclick` handler or similar directly by containing the function in the handler. This approach is used in the commit that updated this README comment.
* Closure (e.g. `state.update(|state| state.store())` has access to Signal of state
* `update` doesn't implement Deref so you can't access fields on it like you can with a Hook
* `update_silent` gives access to the actual state without triggering a render
* State
* Tables
* all `Table` cells should be populated with `Insitu` by default, the only exception is when you have escapes in the loaded CSV. e.g. if your CSV contains quotes in quotes, the parser needs to change escapes quotes into unescaped ones, so it will allocate a String to do it in. for a value in quotes it slices with +1/-1 to skip quotes, and then for escapes it also skips quotes and then replaces escaped quotes inside. if you put something like: `"hello ""world"""` in your CSV file, that will be `Text::Owned`
* the `Table` `source` property values should be read only
* if you edit a `Table` cell, just swap it from `Insitu` to `Owned` text
* you get an owned string from `.value()` so there is no point in trying to avoid it
* loading a file prefers `Insitu` since it can just borrow all unescaped values from the `source` without allocations
* it uses `fn parse_row` in csv.rs to magically know whether to store in `Insitu` instead of `Owned`, otherwise we explicitly tell it to use `Insitu` when setting the default value `Text::Insitu(0..0)` in this file and when we edit a field in the UI so it becomes `Owned("text")` (where text is what we enter)
* `Text` is used instead of just String to avoid unnecessary allocations that are expensive, since subslicing the `source` with an `Insitu` `range` is a const operation, so it's just fiddling with a pointer and the length - so it's not exactly free, but it's as close to free as you can get. even better would be for `Insitu` to contain `&str`, but internal borrowing is a bit of a pain

* References:
* [kobold docs](https://docs.rs/kobold/latest/kobold/)
* [wasm-bindgen docs](https://rustwasm.github.io/docs/wasm-bindgen/introduction.html)
* [web-sys File](https://rustwasm.github.io/wasm-bindgen/api/web_sys/struct.File.html#)
* [js-sys](https://docs.rs/js-sys/latest/js_sys)
* Example: https://yew.rs/docs/0.18.0/concepts/wasm-bindgen/web-sys
* [std::fs::File::create](https://doc.rust-lang.org/std/fs/struct.File.html#method.create)

* Credits:
* Maciej Hirsz
6 changes: 6 additions & 0 deletions examples/invoice/Trunk.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[tools]
wasm_bindgen = "0.2.84"

[build]
filehash = false
pattern_script = "<script type=\"module\">import init, { koboldCallback } from '{base}{js}';init('{base}{wasm}');window.koboldCallback = koboldCallback;</script>"
2 changes: 2 additions & 0 deletions examples/invoice/data/details.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#details,the invoice date,invoice number,name person from,organisation name from,organisation address from,email from,name person attention to,title to,organisation name to,email to
01.04.2023,0001,luke,clawbird,2 metaverse ave,[email protected],recipient_name,director,nftverse,[email protected]
3 changes: 3 additions & 0 deletions examples/invoice/data/main.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#main,description,total,qr
task1,10,0x0000000000000000000000000000000000000000|h160
task2,20,0x1000000000000000000000000000000000000000|h160
Loading