create-basicjs 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/README.md +12 -0
  2. package/bin/create-basicjs.js +49 -4
  3. package/package.json +1 -1
  4. package/payload/projects/tauri/.github/workflows/build.yml +86 -0
  5. package/payload/projects/tauri/.github/workflows/tests.yml +87 -0
  6. package/payload/projects/tauri/AGENTS.md +128 -0
  7. package/payload/projects/tauri/CLAUDE.md +1 -0
  8. package/payload/projects/tauri/LICENSE +201 -0
  9. package/payload/projects/tauri/NOTICE +8 -0
  10. package/payload/projects/tauri/README.md +269 -0
  11. package/payload/projects/tauri/checks/window-check.js +189 -0
  12. package/payload/projects/tauri/gitignore +8 -0
  13. package/payload/projects/tauri/handbook/01-getting-started.md +188 -0
  14. package/payload/projects/tauri/handbook/02-the-project.md +264 -0
  15. package/payload/projects/tauri/handbook/03-the-page.md +260 -0
  16. package/payload/projects/tauri/handbook/04-commands.md +265 -0
  17. package/payload/projects/tauri/handbook/05-events-and-state.md +275 -0
  18. package/payload/projects/tauri/handbook/06-plugins.md +282 -0
  19. package/payload/projects/tauri/handbook/07-the-window-and-the-app.md +431 -0
  20. package/payload/projects/tauri/handbook/08-security.md +374 -0
  21. package/payload/projects/tauri/handbook/09-tests-and-checks.md +266 -0
  22. package/payload/projects/tauri/handbook/10-building-and-releasing.md +238 -0
  23. package/payload/projects/tauri/handbook/11-troubleshooting.md +259 -0
  24. package/payload/projects/tauri/handbook/README.md +125 -0
  25. package/payload/projects/tauri/handbook/turkce/01-getting-started.md +193 -0
  26. package/payload/projects/tauri/handbook/turkce/02-the-project.md +272 -0
  27. package/payload/projects/tauri/handbook/turkce/03-the-page.md +272 -0
  28. package/payload/projects/tauri/handbook/turkce/04-commands.md +271 -0
  29. package/payload/projects/tauri/handbook/turkce/05-events-and-state.md +284 -0
  30. package/payload/projects/tauri/handbook/turkce/06-plugins.md +286 -0
  31. package/payload/projects/tauri/handbook/turkce/07-the-window-and-the-app.md +433 -0
  32. package/payload/projects/tauri/handbook/turkce/08-security.md +384 -0
  33. package/payload/projects/tauri/handbook/turkce/09-tests-and-checks.md +275 -0
  34. package/payload/projects/tauri/handbook/turkce/10-building-and-releasing.md +241 -0
  35. package/payload/projects/tauri/handbook/turkce/11-troubleshooting.md +264 -0
  36. package/payload/projects/tauri/handbook/turkce/README.md +128 -0
  37. package/payload/projects/tauri/images/app.png +0 -0
  38. package/payload/projects/tauri/src-tauri/Cargo.lock +4389 -0
  39. package/payload/projects/tauri/src-tauri/Cargo.toml +31 -0
  40. package/payload/projects/tauri/src-tauri/app-icon.svg +16 -0
  41. package/payload/projects/tauri/src-tauri/build.rs +15 -0
  42. package/payload/projects/tauri/src-tauri/capabilities/default.json +7 -0
  43. package/payload/projects/tauri/src-tauri/gitignore +5 -0
  44. package/payload/projects/tauri/src-tauri/icons/128x128.png +0 -0
  45. package/payload/projects/tauri/src-tauri/icons/128x128@2x.png +0 -0
  46. package/payload/projects/tauri/src-tauri/icons/32x32.png +0 -0
  47. package/payload/projects/tauri/src-tauri/icons/icon.icns +0 -0
  48. package/payload/projects/tauri/src-tauri/icons/icon.ico +0 -0
  49. package/payload/projects/tauri/src-tauri/src/check.rs +144 -0
  50. package/payload/projects/tauri/src-tauri/src/files.rs +255 -0
  51. package/payload/projects/tauri/src-tauri/src/main.rs +45 -0
  52. package/payload/projects/tauri/src-tauri/src/sizes.rs +214 -0
  53. package/payload/projects/tauri/src-tauri/tauri.conf.json +44 -0
  54. package/payload/projects/tauri/src-tauri/tests/project.rs +243 -0
  55. package/payload/projects/tauri/ui/app.js +459 -0
  56. package/payload/projects/tauri/ui/backend.js +196 -0
  57. package/payload/projects/tauri/ui/basic/LICENSE +14 -0
  58. package/payload/projects/tauri/ui/basic/basic.min.css +1 -0
  59. package/payload/projects/tauri/ui/basic/basic.min.js +78 -0
  60. package/payload/projects/tauri/ui/basic/font/open-sans/LICENSE.txt +206 -0
  61. package/payload/projects/tauri/ui/basic/font/open-sans/OpenSans-Bold.ttf +0 -0
  62. package/payload/projects/tauri/ui/basic/font/open-sans/OpenSans-Regular.ttf +0 -0
  63. package/payload/projects/tauri/ui/basic/scroll-bar.min.js +3 -0
  64. package/payload/projects/tauri/ui/comp/_sources.txt +9 -0
  65. package/payload/projects/tauri/ui/comp/components.min.js +21 -0
  66. package/payload/projects/tauri/ui/index.html +28 -0
  67. package/payload/projects/tauri/ui/sizes.js +104 -0
  68. package/payload/starter/_basic/VERSION +1 -1
  69. package/payload/starter/_basic/comp/bottom-bar.js +31 -3
  70. package/payload/starter/_basic/comp/code-editor.js +219 -1
  71. package/payload/starter/_basic/comp/context-menu.js +6 -1
  72. package/payload/starter/_basic/comp/markdown-view.js +4 -2
  73. package/payload/starter/_basic/comp/phone-field.js +13 -5
  74. package/payload/starter/_basic/comp/property-panel.js +1 -1
  75. package/payload/starter/_basic/comp/slider.js +27 -12
  76. package/payload/starter/_basic/comp/smart-button.js +5 -1
  77. package/payload/starter/_basic/comp/smart-table.js +8 -1
  78. package/payload/starter/_basic/comp/stepper.js +29 -3
  79. package/payload/starter/_basic/comp/toggle.js +2 -1
  80. package/payload/starter/_basic/docs/component-index.md +53 -53
  81. package/payload/starter/_basic/examples/code-editor.htm +48 -1
  82. package/payload/starter/_basic/examples/gallery-styled.htm +896 -0
  83. package/payload/starter/_basic/examples/search-input.htm +1 -1
  84. package/payload/starter/_basic/examples/select-box-2-item-view.htm +304 -0
  85. package/payload/starter/_basic/examples/{slider-2-classic.htm → slider-2-split.htm} +36 -2
  86. package/payload/starter/_basic/examples/stepper-2.htm +22 -6
  87. package/payload/starter/_basic/min/bottom-bar.min.js +1 -1
  88. package/payload/starter/_basic/min/code-editor.min.js +1 -1
  89. package/payload/starter/_basic/min/context-menu.min.js +1 -1
  90. package/payload/starter/_basic/min/markdown-view.min.js +1 -1
  91. package/payload/starter/_basic/min/phone-field.min.js +1 -1
  92. package/payload/starter/_basic/min/slider.min.js +1 -1
  93. package/payload/starter/_basic/min/smart-button.min.js +1 -1
  94. package/payload/starter/_basic/min/smart-table.min.js +1 -1
  95. package/payload/starter/_basic/min/stepper.min.js +1 -1
  96. package/payload/starter/_basic/min/toggle.min.js +1 -1
  97. package/payload/starter/_basic/tools/check.js +13 -2
@@ -0,0 +1,264 @@
1
+ # 2. The project
2
+
3
+ *Türkçe: [2. Proje](turkce/02-the-project.md)*
4
+
5
+ What every file of the template is for, what happens when the app starts, and the two files of settings:
6
+ `tauri.conf.json` and `Cargo.toml`. Then you make the project your own and take out an example you do not need.
7
+
8
+ ## The files
9
+
10
+ ```text
11
+ README.md the first page of the template (write your own)
12
+ AGENTS.md the rules for an AI assistant; CLAUDE.md is one line: @AGENTS.md
13
+ LICENSE, NOTICE Apache 2.0; NOTICE names basic.js and the Open Sans font
14
+ .gitignore the files git does not take (src-tauri/.gitignore: the compiled app)
15
+ .github/workflows/ tests.yml (every push: the checks), build.yml (a tag: the installers, a draft release)
16
+ images/app.png the picture of the README
17
+ handbook/ this handbook (English; turkce/: Turkish)
18
+ checks/window-check.js the steps of the window check, run inside the real window
19
+ ui/ THE PAGE: the files the window shows
20
+ index.html loads the files below, in this order
21
+ basic/ basic.js v26.11.10 (basic.min.js, basic.min.css, scroll-bar.min.js, the font): a copy
22
+ comp/components.min.js the components of the page in one file: a copy (comp/_sources.txt lists them)
23
+ backend.js every call to Rust and every event of Rust (Backend.); the sample answers of a browser
24
+ app.js the view; example 1 (Folders) and 3 (Open...)
25
+ sizes.js example 2 (Sizes)
26
+ src-tauri/ THE RUST SIDE
27
+ Cargo.toml, Cargo.lock the package tauri-starter 0.1.0 (the version of the app is here), its crates
28
+ build.rs runs before the app is compiled: tauri_build::build()
29
+ tauri.conf.json the name, the identifier, the window, the security policy (CSP), the installers
30
+ capabilities/default.json what the page may use: core:default, dialog:allow-open
31
+ app-icon.svg, icons/ the icon: one drawing, and the files the systems need
32
+ src/main.rs starts the app: the plugin, the state, the list of the commands
33
+ src/files.rs example 1: the command list_folder, and its tests
34
+ src/sizes.rs example 2: the commands measure_folder and stop_measure, the events, and their tests
35
+ src/check.rs the window check (compiled only with --features window-check)
36
+ tests/project.rs 4 tests that read the page and Rust together
37
+ target/, gen/ made by the build; not in git
38
+ ```
39
+
40
+ The repository on GitHub also has `docs/`: the site of the template, which GitHub Pages serves.
41
+
42
+ **Two sides and one bridge.** `ui/` is a page, as in a browser: it can not read a file of the computer by itself.
43
+ `src-tauri/` is a Rust program: it opens the window, and its commands do what the page can not. Only one file of the
44
+ page talks to Rust: `ui/backend.js`. Every call and every event goes through a function of `Backend`, and each
45
+ function has a sample answer for a browser, so the page also opens without Rust (chapter 1).
46
+
47
+ ## When the app starts
48
+
49
+ ```text
50
+ src-tauri/src/main.rs main(): tauri::Builder with the plugin, the state and the commands, then .run()
51
+ -> the window "main" 960 x 640, from tauri.conf.json; it loads ui/index.html
52
+ -> ui/index.html the scripts in order: basic.js, the components, backend.js, app.js, sizes.js
53
+ -> basic.js makes the global page (the whole window), then calls start() of app.js
54
+ -> start() the top bar, the table, the status bar; Sizes.listen(); openFolder("")
55
+ -> ui/backend.js invoke("list_folder", { path: "", showHidden: false })
56
+ -> src-tauri/src/files.rs list_folder: an empty path is the home folder; Ok(a Folder), sent as JSON
57
+ -> showFolder(folder) the rows of the table, the path, the counts
58
+ ```
59
+
60
+ - `main()` makes the app with `tauri::Builder::default()`: `.plugin(...)`, `.manage(...)` and `.invoke_handler(...)`
61
+ add to it, and `.run(tauri::generate_context!())` starts it.
62
+ - `generate_context!()` reads `tauri.conf.json` when the program is compiled; the permissions and the files of `ui/`
63
+ go into the program with it. So the app you build is one program with its page inside: a change in `ui/` needs a
64
+ new build (chapter 10). Under `cargo tauri dev` a change reloads the window.
65
+ - The window of `tauri.conf.json` has no `label`, so its label is `main`: the name `capabilities/default.json` gives
66
+ its permissions to. In the app you build the page comes from inside the program, not from the web (its address is
67
+ `tauri://localhost` on macOS).
68
+ - The scripts of `ui/index.html` run one after the other, and they share their names: there is no `import`. A
69
+ `const` at the top of `app.js` (Ex: `lineIcon`) can be used by `sizes.js`, which loads after it.
70
+
71
+ ## tauri.conf.json
72
+
73
+ The settings of the app, in `src-tauri/`. Here it is with some lines joined, and the long text of the security policy
74
+ cut (chapter 8 reads it part by part):
75
+
76
+ ```json
77
+ {
78
+ "$schema": "https://schema.tauri.app/config/2",
79
+ "productName": "Tauri Starter",
80
+ "identifier": "io.github.bug7a.tauri-starter",
81
+ "build": { "frontendDist": "../ui" },
82
+ "app": {
83
+ "withGlobalTauri": true,
84
+ "windows": [{ "title": "Tauri Starter", "width": 960, "height": 640, "minWidth": 760, "minHeight": 420,
85
+ "theme": "Light" }],
86
+ "security": { "csp": "default-src 'self'; style-src 'self' 'unsafe-inline'; ..." }
87
+ },
88
+ "bundle": {
89
+ "active": true,
90
+ "targets": "all",
91
+ "publisher": "Bugra Ozden",
92
+ "copyright": "Copyright 2020-2026 Bugra Ozden",
93
+ "license": "Apache-2.0",
94
+ "homepage": "https://bug7a.github.io/ozdenui-tauri-template/",
95
+ "category": "Utility",
96
+ "shortDescription": "A desktop app with a Rust side and a basic.js interface",
97
+ "macOS": { "signingIdentity": "-" },
98
+ "icon": ["icons/32x32.png", "icons/128x128.png", "icons/128x128@2x.png", "icons/icon.icns", "icons/icon.ico"]
99
+ }
100
+ }
101
+ ```
102
+
103
+ - `$schema`: the description of every field, so an editor (Ex: VS Code) completes the names and marks a mistake.
104
+ - `productName`: the name of the app as people see it: the name of `Tauri Starter.app` and of the `.dmg` on macOS, of
105
+ the installers, the folder of the app and the Start menu on Windows.
106
+ - `identifier`: the one name of the app among all apps, a domain written backwards (`io.github.bug7a` is
107
+ `bug7a.github.io`). Only letters, digits, `-` and `.`. The systems know the app by it, and the folders where the app
108
+ keeps its data are named after it ([7. The window and the app](07-the-window-and-the-app.md)).
109
+ - `build.frontendDist`: the folder of the page, from `src-tauri/`: `../ui`.
110
+ - `app.withGlobalTauri`: the page gets `window.__TAURI__`, so it reaches Tauri with no npm package and no `import`.
111
+ - `app.windows`: the window the app opens at the start: its title, its size, its smallest size, and its theme
112
+ (`"Light"`: the page has only light colors, so the window stays light on a dark system). Chapter 7 has the other
113
+ fields.
114
+ - `app.security.csp`: the security policy of the page: where scripts, styles, pictures, fonts and calls may come from
115
+ ([8. Security](08-security.md)).
116
+ - `bundle`: what `cargo tauri build` makes. `"targets": "all"` makes every installer of the system it runs on (the
117
+ `.app` and a `.dmg` on macOS; a `-setup.exe` and an `.msi` on Windows; a `.deb`, an `.rpm` and an `.AppImage` on
118
+ Linux). The texts (`publisher`, `copyright`, `license`, `homepage`, `category`, `shortDescription`) are written
119
+ into the installers. `"signingIdentity": "-"` signs the macOS app without a certificate, and `icon` names the
120
+ icon files the installers use ([10. Building and releasing](10-building-and-releasing.md)).
121
+ - There is no `version`: Tauri takes the version of `Cargo.toml`, so it is written in one place.
122
+
123
+ ## Cargo.toml
124
+
125
+ The Rust package of the app, in `src-tauri/`:
126
+
127
+ ```toml
128
+ [package]
129
+ name = "tauri-starter"
130
+ version = "0.1.0"
131
+ description = "A desktop app: a Rust side and a basic.js interface"
132
+ authors = ["Bugra Ozden"]
133
+ license = "Apache-2.0"
134
+ edition = "2021"
135
+ # The oldest Rust that builds Tauri 2 of Cargo.lock: an older one says so, and "rustup update" brings a new one
136
+ rust-version = "1.90"
137
+
138
+ [build-dependencies]
139
+ tauri-build = { version = "2", features = [] }
140
+
141
+ [dependencies]
142
+ tauri = { version = "2", features = [] }
143
+ serde = { version = "1", features = ["derive"] }
144
+ # The folder dialog of the system (the "Open..." button): added with "cargo tauri add dialog"
145
+ tauri-plugin-dialog = "2"
146
+ serde_json = { version = "1", optional = true }
147
+
148
+ [features]
149
+ # cargo run --features window-check: the page is played in its real window (src/check.rs, checks/window-check.js)
150
+ window-check = ["dep:serde_json"]
151
+
152
+ # A small app (the "App Size" guide of Tauri): the release build takes longer, the app is a few MB.
153
+ [profile.release]
154
+ codegen-units = 1
155
+ lto = true
156
+ opt-level = "s"
157
+ panic = "abort"
158
+ strip = true
159
+ ```
160
+
161
+ - `[package]`: `name` is the name of the program file (`tauri-starter`; `tauri-starter.exe` on Windows). `version` is
162
+ the version of the app: the only place it is written. `edition` is the edition of the rules of the Rust language
163
+ the code follows; `rust-version` is the oldest Rust that builds it.
164
+ - `[build-dependencies]`: the crate that `build.rs` uses.
165
+ - `[dependencies]`: the crates of the app. `tauri`; `serde`, which turns a `struct` of Rust into the JSON the page
166
+ gets; `tauri-plugin-dialog`, which `cargo tauri add dialog` wrote; `serde_json`, which only the window check uses.
167
+ `"2"` means any version 2.x of the crate, never a 3; `Cargo.lock` keeps the exact one.
168
+ - `[features]`: `window-check` is off unless a command asks for it (`--features window-check`). With it, the program
169
+ also has `src/check.rs` and `serde_json`; the app you build has neither
170
+ ([9. Tests and checks](09-tests-and-checks.md)).
171
+ - `[profile.release]`: the settings of `cargo tauri build`, for a small program. `opt-level = "s"` makes the code
172
+ small rather than fast; `lto` and `codegen-units = 1` let the compiler look at all the code at once; a `panic` (a
173
+ stop of the program on an error it can not go on from) ends the app at once; `strip` leaves out the names used by
174
+ debuggers. The price is time: a clean `cargo tauri build` took 2 min 7 s on an Apple Silicon Mac (2026-11-20), and
175
+ the app is 3.6 MB.
176
+
177
+ ## The other files of src-tauri/
178
+
179
+ - `build.rs` runs before the app is compiled. `tauri_build::build()` reads `tauri.conf.json` and `capabilities/`,
180
+ stops the build when they have a mistake, and writes `gen/schemas/` (the `$schema` of
181
+ `capabilities/default.json` points there, so the editor knows the names of the permissions).
182
+ - `capabilities/default.json`: what the page of the window `main` may use. `core:default` is the core of Tauri,
183
+ `dialog:allow-open` the folder dialog of the plugin (`cargo tauri add dialog` wrote `dialog:default`, which also
184
+ allows the save dialog and the messages; the page opens only folders). The commands of `src/` need no line here; a
185
+ plugin needs its own ([6. Plugins](06-plugins.md), [8. Security](08-security.md)).
186
+ - `Cargo.lock`: the exact version of every crate, written by `cargo`. It is in git, so every computer and every
187
+ workflow builds the app with the same crates. `cargo update` takes newer ones.
188
+ - `target/` (the compiled crates and the app, some GB) and `gen/` (written by `build.rs`) are not in git.
189
+ `cargo clean` in `src-tauri/` deletes `target/`; the next build compiles everything again.
190
+ - `app-icon.svg` is the drawing of the icon, and `icons/` holds the files made from it.
191
+
192
+ ## Make it your own
193
+
194
+ 1. **The name.** In `src-tauri/tauri.conf.json`: `productName` and the `title` of the window. In
195
+ `src-tauri/Cargo.toml`: `name` (small letters and `-`, Ex: `my-notes`; `cargo` writes the new name into
196
+ `Cargo.lock` by itself). In `ui/index.html`: the `<title>` of the page.
197
+ 2. **The identifier.** A domain of yours written backwards, and the name of the app (Ex: `com.yourname.notes`, or
198
+ `io.github.yourname.notes` for a GitHub name). Choose it, and the name, before the first release: the systems
199
+ remember an app by them.
200
+ 3. **The version** in `src-tauri/Cargo.toml` (`version = "0.1.0"`). The release workflow wants a tag of the same
201
+ version ([10. Building and releasing](10-building-and-releasing.md)).
202
+ 4. **The icon.** Draw a square SVG, or a PNG of 1024 px, and run `cargo tauri icon my-icon.svg` in `src-tauri/`. It
203
+ writes every size into `src-tauri/icons/`, also the icons of phones and of the Microsoft Store (52 files). Keep the
204
+ five files that `tauri.conf.json` names and delete the others.
205
+ 5. **The texts of the installers:** `publisher`, `copyright`, `license`, `homepage`, `category` and
206
+ `shortDescription` in `bundle`; `description` and `authors` in `Cargo.toml`.
207
+ 6. **The files of the template itself:** its `README.md` (write your own), `images/`, `handbook/` (keep it if it
208
+ helps you) and `docs/`. Keep `AGENTS.md` and change it with your app: your AI assistant reads it (chapter 9).
209
+
210
+ ## The license
211
+
212
+ The template is under the Apache License 2.0: you may use it for any app, open or closed, free or sold. When you give
213
+ your app or its code to other people, the license asks for these (its text in `LICENSE` is the rule; this is a short
214
+ reading of it):
215
+
216
+ - A copy of `LICENSE`, and the text of `NOTICE`, go with it (Ex: in the files of the download, or in an About window).
217
+ You may add your own lines to `NOTICE`; keep its lines.
218
+ - A file that came from the template keeps its copyright and license lines. A file you changed says that you changed
219
+ it (Ex: a line of yours under them).
220
+ - Your own new files take your own header, and your own license if you want another one.
221
+ - `ui/basic/` is a copy of basic.js with its own `LICENSE`, and the font in it has its own license: they stay with the
222
+ files.
223
+
224
+ ## Taking an example out
225
+
226
+ **Sizes** (the events of Rust):
227
+
228
+ 1. Delete `ui/sizes.js`, and its `<script>` line in `ui/index.html`.
229
+ 2. Delete `src-tauri/src/sizes.rs`. In `src-tauri/src/main.rs`, delete `mod sizes;`, the `.manage(...)` line with its
230
+ comment, and the two `sizes::` commands of `generate_handler!`. Run `cargo fmt` in `src-tauri/`: the list of one
231
+ command is written on one line.
232
+ 3. In `ui/app.js`: delete `Sizes.createButton();` (`createTopBar()`), `Sizes.listen();` (`start()`), `Sizes.stop();`
233
+ (`showFolder()`) and the function `setRowSize()`. In `toRow()`, a folder has no size any more:
234
+
235
+ ```js
236
+ size: entry.isFolder ? NO_SIZE : entry.size,
237
+ ```
238
+
239
+ 4. In `ui/backend.js`: delete `Backend.measureFolder`, `Backend.stopMeasure` and the sample measure
240
+ (`SAMPLE_MEASURE_STEP`, `SAMPLE_FILE_SIZE`, `sampleMeasure`, `measureSampleFolders`, `stopSampleMeasure`,
241
+ `endSampleMeasure`). Keep `Backend.listen`, `Backend.sampleListeners` and `Backend.emitSample`: your own events
242
+ use them ([5. Events and state](05-events-and-state.md)).
243
+ 5. In `checks/window-check.js`: delete the block `// THE SECOND EXAMPLE: Rust sends events`.
244
+
245
+ **Open...** (the dialog plugin):
246
+
247
+ 1. In the root of the project, `cargo tauri remove dialog` takes out two of the three places that
248
+ `cargo tauri add dialog` wrote: the lines of `Cargo.toml` and the permission of the plugin in
249
+ `capabilities/default.json` (tried: it took out `"dialog:allow-open"`).
250
+ The third one is yours: delete `.plugin(tauri_plugin_dialog::init())` and its comments in `src-tauri/src/main.rs`.
251
+ 2. In `ui/app.js`: the `Open...` button of `createTopBar()`, the function `chooseFolder()`, and `o: chooseFolder` in
252
+ `KEY_ACTIONS`.
253
+ 3. In `ui/backend.js`: `Backend.chooseFolder` and `Backend.SAMPLE_CHOSEN_FOLDER`.
254
+ 4. In `checks/window-check.js`: the block `// THE THIRD EXAMPLE: a plugin of Tauri`.
255
+
256
+ Then, in `src-tauri/`, `cargo test` and the window check tell what is left
257
+ ([9. Tests and checks](09-tests-and-checks.md)). With both examples out, `cargo test` runs 7 tests (the 2 of
258
+ `sizes.rs` are gone) and the window check prints 14 `PASS` lines on macOS: two less without Sizes, one less without
259
+ the dialog.
260
+
261
+ ## Next
262
+
263
+ [3. The page](03-the-page.md): the page is an ordinary basic.js page; what it is made of, and a button, a text and a
264
+ message of your own.
@@ -0,0 +1,260 @@
1
+ # 3. The page
2
+
3
+ *Türkçe: [3. Sayfa](turkce/03-the-page.md)*
4
+
5
+ The page of the window is an ordinary basic.js page. This chapter shows what it is made of and where things are in
6
+ `ui/app.js`, then adds a button, a text and a message of your own, and a component of the kit.
7
+
8
+ ## An ordinary basic.js page
9
+
10
+ `ui/index.html` only loads files, with `<script src>` and `<link>` lines, in this order:
11
+
12
+ ```text
13
+ basic/basic.min.css, basic/basic.min.js, basic/scroll-bar.min.js the library (the font is in basic/ too)
14
+ comp/components.min.js the components
15
+ backend.js, app.js, sizes.js the app
16
+ ```
17
+
18
+ basic.js makes the whole page in JavaScript: there is no HTML to write in `<body>` and no CSS file of the page. When it
19
+ is loaded it makes the global `page` (the whole window); when the page is ready it calls the global `start()`, which
20
+ is in `ui/app.js`. The files share their names in the order they load: `sizes.js` uses `lineIcon()` and
21
+ `currentFolder` of `app.js`, with no `import`. The template has basic.js v26.11.10 (`basic.version`); it is taught by
22
+ its handbook (https://bug7a.github.io/basic.js-handbook/) and its site (https://bug7a.github.io/basic.js/).
23
+
24
+ ## Objects and groups
25
+
26
+ A small page to try them. Make `hello.html` in `ui/`: a copy of `index.html` whose three lines under `THE APP` are
27
+ one line, `<script src="hello.js" type="text/javascript" charset="utf-8"></script>`. Then `hello.js` next to it:
28
+
29
+ ```js
30
+ "use strict";
31
+
32
+ const BAR_STEP = 20; // px: the bar grows by this much for every count
33
+
34
+ let count = 0;
35
+ let lblCount, barCount;
36
+
37
+ const start = function () {
38
+ page.color = "#F4F5F2";
39
+
40
+ // GROUP: one under the other, in the middle of the window
41
+ VGroup({ align: "center center", gap: 16 });
42
+
43
+ lblCount = Label({ text: "0", fontSize: 48, bold: 1 });
44
+
45
+ // BOX: a bar as long as the count
46
+ barCount = Box({ width: BAR_STEP, height: 8, color: "#2F6FED", round: 4 });
47
+
48
+ // GROUP: side by side, only as large as its buttons
49
+ HGroup({ hug: 1, gap: 8 });
50
+ SmartButton({ labelText: "Less", onClick: function () { changeCount(-1); } });
51
+ SmartButton({ labelText: "More", tone: "cyan", onClick: function () { changeCount(1); } });
52
+ endGroup();
53
+
54
+ endGroup();
55
+ };
56
+
57
+ const changeCount = function (step) {
58
+ count = Math.max(0, count + step);
59
+ lblCount.text = String(count);
60
+ barCount.width = BAR_STEP * (count + 1);
61
+ };
62
+ ```
63
+
64
+ Open `hello.html` through the web server of chapter 1, click More and Less. Delete the two files when you are done:
65
+ every file of `ui/` goes into the app.
66
+
67
+ - An object is made where it is written, with its values in one object: `Label({ text: "0", fontSize: 48 })`.
68
+ - `VGroup` puts its objects one under the other, `HGroup` side by side, until `endGroup()`. A group is as large as
69
+ its box (100% x 100%); `hug: 1` makes it as large as what it holds.
70
+ - After it is made, an object changes with its values (`lblCount.text = ...`, `barCount.width = ...`), a component
71
+ with its `set...()` functions (`btnUp.setEnabled(0)` in `app.js`).
72
+ - **`text` is HTML.** A text that comes from Rust or from a person (a file name, a typed text) goes in with
73
+ `plainText`, so it is shown as it is written.
74
+
75
+ ## The components of the template
76
+
77
+ `ui/comp/components.min.js` holds seven components of the kit (https://bug7a.github.io/js-components/):
78
+
79
+ | Component | In the template |
80
+ |---|---|
81
+ | `SmartButton` | the buttons of the top bar (Up, Home, Open..., Sizes / Stop) |
82
+ | `Breadcrumbs` | the path of the folder at the top |
83
+ | `CheckBox` | Hidden files |
84
+ | `SmartTable` | the table: it makes only the rows that are seen, so 100,000 rows are shown at once |
85
+ | `SearchInput` | the Filter box under the table (`SmartTable` makes it) |
86
+ | `ContextMenu` | the list of the columns of the filter (a click on "Name" in it) |
87
+ | `Toast` | the messages, Ex: a folder that could not be opened |
88
+
89
+ The file is minified: read the params of a component in the header of its source, in the folder `comp/` of
90
+ https://github.com/bug7a/js-components (Ex: `smart-button.js`). Never guess a param.
91
+
92
+ ## Where things are in ui/app.js
93
+
94
+ | To change | Look at |
95
+ |---|---|
96
+ | a color, a size, a column | the constants at the top (`PAGE_COLOR`, `ROW_HEIGHT`, `COLUMNS`) |
97
+ | an icon | `ICONS`: SVG texts, `lineIcon()` for a button, `twoToneIcon()` for a row |
98
+ | the top bar | `createTopBar()` |
99
+ | the table and its cells | `createTable()`, `createCellView()`, `updateCellView()`, `fitColumns()` |
100
+ | the status bar | `createStatusBar()`, `showCounts()`, `showSpeed()` |
101
+ | what is done with a folder | `openFolder()`, `showFolder()`, `toRow()` |
102
+ | a click, a key | `onRowClick()`, `onCrumbClick()`, `onHiddenChange()`, `KEY_ACTIONS`, `onKeyDown()` |
103
+ | how a number, a size, a date is written | `formatSize()`, `formatDate()`, `countText()` |
104
+ | Sizes; a call to Rust | `ui/sizes.js`; `ui/backend.js` |
105
+
106
+ ## A button of your own
107
+
108
+ A Reload button reads the folder that is shown again (Ex: after a file was added outside the app). In `ui/app.js`,
109
+ add an icon to `ICONS`:
110
+
111
+ ```js
112
+ reload: lineIcon('<path d="M19.5 12a7.5 7.5 0 1 1-2.2-5.3"/><path d="M19.5 4.5v4h-4"/>'),
113
+ ```
114
+
115
+ add `btnReload` to the line of `let` under it, and the button to `createTopBar()`, after `Sizes.createButton();`:
116
+
117
+ ```js
118
+ btnReload = SmartButton({
119
+ labelText: "", iconFile: ICONS.reload, ariaLabel: "Reload", onClick: reloadFolder,
120
+ });
121
+ ```
122
+
123
+ and its function under `// *** FOLDERS:`:
124
+
125
+ ```js
126
+ // The folder that is shown, read again (Ex: a file was added outside the app)
127
+ const reloadFolder = function () {
128
+ if (!currentFolder) return;
129
+ openFolder(currentFolder.path);
130
+ };
131
+ ```
132
+
133
+ - `labelText: ""` makes an icon button (a square of 44 x 44 px); `ariaLabel` is the name a screen reader says.
134
+ - The icon is an SVG text, as every icon of the page: no picture file is needed.
135
+ - Each button takes room from the path. In the smallest window (760 px) the path now has room for `/` only; a
136
+ `minWidth` of 820 in `tauri.conf.json` gives it back.
137
+
138
+ ## A text in the status bar
139
+
140
+ The biggest file of the folder, between the counts and the speed. In `createStatusBar()`, after `lblCount`:
141
+
142
+ ```js
143
+ lblBiggest = Label({
144
+ fontSize: STATUS_FONT_SIZE, textColor: STATUS_TEXT_COLOR, ellipsis: 1, css: { minWidth: "0px" },
145
+ });
146
+ ```
147
+
148
+ add `lblBiggest` to the line of `let`, call `showBiggestFile(folder);` in `showFolder()` after
149
+ `showCounts(folder);`, and write the function under `showCounts()`:
150
+
151
+ ```js
152
+ // "The biggest: report.pdf (1.2 MB)"
153
+ const showBiggestFile = function (folder) {
154
+ const files = folder.entries.filter(function (entry) { return !entry.isFolder; });
155
+ if (files.length == 0) {
156
+ lblBiggest.plainText = "";
157
+ return;
158
+ }
159
+ const biggest = files.reduce(function (big, entry) { return (entry.size > big.size) ? entry : big; });
160
+ lblBiggest.plainText = "The biggest: " + biggest.name + " (" + formatSize(biggest.size) + ")";
161
+ };
162
+ ```
163
+
164
+ - The name comes from the disk, through Rust: `plainText`, never `text`. A file can be named like an HTML tag; the
165
+ window check opens such a folder to prove that the page shows it as a name.
166
+ - `ellipsis: 1` cuts a long text with "…"; `minWidth: "0px"` lets the label get narrower than its text.
167
+
168
+ ## A message
169
+
170
+ `Toast` shows a message that closes itself. Rust cuts a folder of more than 100,000 entries (`MAX_ENTRIES` of
171
+ `src-tauri/src/files.rs`); tell it. In `showFolder()`, after `showBiggestFile(folder);`, call `warnIfCut(folder);`:
172
+
173
+ ```js
174
+ // A folder of more than 100,000 entries (MAX_ENTRIES of files.rs): the table has the first ones only
175
+ const warnIfCut = function (folder) {
176
+ if (folder.entries.length == folder.total) return;
177
+ const total = countText(folder.total, "item");
178
+ Toast.warning("Rust sent the first " + formatNumber(folder.entries.length) + " of " + total + ".", {
179
+ key: "cut-folder",
180
+ titleText: "A big folder",
181
+ });
182
+ };
183
+ ```
184
+
185
+ - With `MAX_ENTRIES` at 3 (chapter 1) every folder of more than 3 entries shows it.
186
+ - `Toast.success`, `Toast.info`, `Toast.warning` and `Toast.error` take the message and its options: `titleText`,
187
+ `duration` (ms; 0: until it is closed), `key` (a toast with the same key is changed, not added again). A toast
188
+ shows its texts as text, so a name from Rust is safe in it.
189
+
190
+ ## Another component of the kit
191
+
192
+ The page can load any component of the kit. Ex: `Tooltip`, a hint over an object:
193
+
194
+ 1. Copy `comp/tooltip.js` of https://github.com/bug7a/js-components into `ui/comp/`.
195
+ 2. Load it in `ui/index.html`, after `components.min.js`:
196
+
197
+ ```html
198
+ <script src="comp/tooltip.js" type="text/javascript" charset="utf-8"></script>
199
+ ```
200
+
201
+ 3. Use it. In `createTopBar()`, after the Reload button:
202
+
203
+ ```js
204
+ Tooltip({ target: btnReload, hintText: "Read the folder again", hintPosition: "bottom" });
205
+ ```
206
+
207
+ - `SmartTable` uses it when it is there: a name cut with "…" is shown whole in a bubble.
208
+ - A component that extends another one (Ex: `email-field.js` extends `text-field.js`) loads after it. One whose
209
+ header names files of a folder of its own name (`comp/<name>/`) needs that folder in `ui/comp/` too.
210
+ - A component file needs a basic.js at least as new as the one it was written for.
211
+
212
+ ## The rules of the window
213
+
214
+ In the window, the page lives under the security policy of `tauri.conf.json` ([8. Security](08-security.md)):
215
+
216
+ - **Scripts only from the files of `ui/`.** A script from the web, `eval()` or `new Function()`, an `onclick="..."`
217
+ text in HTML and a `<script>` made by code do not run. (A `<script>` written in `ui/index.html` itself runs: Tauri
218
+ adds its hash to the policy when it builds the app.) Keep the code in the `.js` files: the project tests read them.
219
+ - **Pictures** from the files of `ui/` or from `data:` and `blob:` addresses (the icons of the page are `data:`
220
+ texts); not from the web. **Fonts** from the files of `ui/` or `data:`.
221
+ - **Calls** go to Rust only: a `fetch()` to the web is stopped. Call the web from Rust, or open the policy for that
222
+ one address, if that service accepts calls from other sites (chapter 8).
223
+ - A browser has no such policy: a thing that works through Live Server can be stopped in the window. The window
224
+ check is the proof ([9. Tests and checks](09-tests-and-checks.md)).
225
+
226
+ **In a browser** `Backend.isInApp()` is `false`, and every function of `Backend` gives a sample answer
227
+ (`Promise.resolve(...)`) instead of calling Rust. Keep it so for a function you add (chapter 4 does it for a
228
+ command), and call `window.__TAURI__` only in `ui/backend.js`: the page then also opens with no Rust at all.
229
+
230
+ ## The size of the window
231
+
232
+ The window is 960 x 640 and never smaller than 760 x 420 (`tauri.conf.json`). The page is always the whole window,
233
+ and the template places its parts with `"100%"` and `calc()`, so the table grows and shrinks with it. What can not
234
+ follow by itself is fitted at every change of the size, in the function that `start()` gives to `page.onResize()`:
235
+ `fitCrumbs()` collapses the path, `fitColumns()` gives the name column the width that is left.
236
+
237
+ A third one hides the biggest file in a narrow window. Add `fitStatusBar();` to that function, and once more after
238
+ `createStatusBar();` in `start()` (for the first size):
239
+
240
+ ```js
241
+ // At the top, with the other constants:
242
+ const WIDE_STATUS_WIDTH = 900; // px: a narrower window does not show the biggest file
243
+
244
+ // Before createStatusBar(): a narrow window keeps the counts and the speed
245
+ const fitStatusBar = function () {
246
+ lblBiggest.visible = (page.width >= WIDE_STATUS_WIDTH) ? 1 : 0;
247
+ };
248
+ ```
249
+
250
+ ## No npm, no bundler
251
+
252
+ The files of `ui/` are used as they are. A library you want is one more file: its build that is one `.js` file and
253
+ makes a global name (often `.min.js`, a "UMD" or "browser" build), in a folder of `ui/` (Ex: `lib`; the project tests
254
+ read only the `.js` files directly in `ui/`), loaded with a `<script src>` line before the files that use it. A
255
+ `<script>` with an address of the web (a CDN) is stopped by `cargo test` (chapter 9), and a library that comes only as
256
+ `import` modules needs a bundler. Often a crate in Rust does the same work (chapter 4).
257
+
258
+ ## Next
259
+
260
+ [4. Commands](04-commands.md): the page asks, Rust answers. A command read line by line, and a new one of your own.