Commit graph

49 commits

Author SHA1 Message Date
Matthias Metelka
a0bbb75a28 Use custom scrollbar in stats screen, use grid layout and tweak CSS (#2154)
* Include base styles in graphs-base.scss

This includes the custom scrollbar styles, which were missing on the stats page.

* Set responsive grid layout on GraphsPage, use TitledContainer component

+ use global button style, tweak input appearance and other small changes

* Improve margins on GraphsPage
2022-11-02 18:23:08 +10:00
Henrik Giesel
fff0bd6e55 Use eslint for sorting our imports (#1637)
* Make eslint sort our imports

* fix missing deps in eslint rule (dae)

Caught on Linux due to the stricter sandboxing

* Remove exports-last eslint rule (for now?)

* Adjust browserslist settings

- We use ResizeObserver which is not supported in browsers like KaiOS,
  Baidu or Android UC

* Raise minimum iOS version 13.4

- It's the first version that supports ResizeObserver

* Apply new eslint rules to sort imports
2022-02-04 18:36:34 +10:00
Henrik Giesel
9ed42d2bac Remove individual .html files + other refactorings (#1588)
* Move some AddCards specific code to NoteCreator.svelte

* Add new strings for Toggling the Visual / HTML editor

* Set LabelContainer vertical-align to text-top

- Makes them look more centered

* Remove appendInParentheses helper

* Make all ts/*.html files include only module.js and module.css

* Move any JS from .html to index files

* Remove .html files from ts modules

* Remove Python with Starlark implemenation

* Remove reference to non-existing file

* Remove deck-option.html as well

* fix change-notetype screen (dae)
2022-01-16 15:05:35 +10:00
RumovZ
54d39d1b3b Live theme changes (#1497)
* Allow theme change at runtime and add hook

* Save or restore default palette on theme change

* Update aqt widget styles on theme change

* styling fixes

- drop _light_palette, as default_palette serves the same purpose
- save default platform theme, and restore it when switching away
from nightmode
- update macOS light/dark mode on theme switch
- fix unreadable menus on Windows

* update night-mode classes on theme change

This is the easy part - CSS styling that uses standard_css or our
css variables should update automatically. The main remaining issue
is JS code that sets colors based on the theme at the time it's run -
eg the graph code, and the editor.

* switch night mode value on toggle

* expose current theme via a store; switch graphs to use it

https://github.com/ankitects/anki/issues/1471#issuecomment-972402492

* start using currentTheme in editor/components

This fixes basic editing - there are still components that need updating.

* add simple xcodeproj for code completion

* add helper to get currently-active system theme on macOS

* fix setCurrentTheme not being immediately available

* live update tag color

* style().name() doesn't work on Qt5

* automatic theme switching on Windows/Mac

* currentTheme -> pageTheme

* Replace `nightModeKey` with `pageTheme`

Co-authored-by: Damien Elmes <gpg@ankiweb.net>
2021-11-25 07:17:41 +10:00
Damien Elmes
eee17476e3 fix deprecation warning in latest svelte-preprocess 2021-10-26 08:43:02 +10:00
Damien Elmes
5d7eb8c425 update to latest rules_nodejs & switch to ts_project
ts_library() is deprecated and will presumably be dropped from a
future rules_nodejs, and it wasn't working with the jest tests
after updating, so we switch over to ts_project().

There are some downsides:

- It's a bit slower, as the worker mode doesn't appear to function
at the moment.
- Getting it working with a mix of source files and generated files
was quite tricky, especially as things behave differently on Windows,
and differently when editing with VS Code. Solved with a small patch
to the rules, and a wrapper script that copies everything into the
bin folder first. To keep VS Code working correctly as well, the built
files are symlinked into the source folder.
- TS libraries are not implicitly linked to node_modules, so they
can't be imported with an absolute name like "lib/proto" - we need
to use relative paths like "../lib/proto" instead. Adjusting "paths"
in tsconfig.json makes it work for TS compilation, but then it fails
at the esbuild stage. We could resolve it by wrapping the TS
libraries in a subsequent js_library() call, but that has the downside
of losing the transient dependencies, meaning they need to be listed
again.  Alternatively we might be able to solve it in the future by
adjusting esbuild, but for now the paths have been made relative to
keep things simple.

Upsides:

- Along with updates to the Svelte tooling, Svelte typing has improved.
All exports made in a Svelte file are now visible to other files that
import them, and we no longer rebuild the Svelte files when TS files
are updated, as the Svelte files do no type checking themselves, and
are just a simple transpilation. Svelte-check now works on Windows again,
and there should be no errors when editing in VS Code after you've
built the project. The only downside seems to be that cmd+clicking
on a Svelte imports jumps to the .d.ts file instead of the original now;
presumably they'll fix that in a future plugin update.
- Each subfolder now has its own tsconfig.json, and tsc can be called
directly for testing purposes (but beware it will place build products
in the source tree): ts/node_modules/.bin/tsc -b ts
- We can drop the custom esbuild_toolchain, as it's included in the
latest rules_nodejs.

Other changes:

- "image_module_support" is moved into lib/, and imported with
<reference types=...>
- Images are now imported directly from their npm package; the
extra copy step has been removed.

Windows users may need to use "bazel clean" before building this,
due to old files lying around in the build folder.
2021-10-01 12:52:53 +10:00
Damien Elmes
3489257f41 update ts deps
- prettier's formatting has changed, so files needed to be reformatted
- dart is spitting out deprecation warnings like:

254 │   2: $spacer / 2,
    │      ^^^^^^^^^^^
    ╵
    bazel-out/darwin-fastbuild/bin/ts/sass/bootstrap/_variables.scss 254:6  @import
    ts/sass/button_mixins.scss 2:9                                          @use
    ts/components/ColorPicker.svelte 2:5                                    root stylesheet

DEPRECATION WARNING: Using / for division is deprecated and will be removed in Dart Sass 2.0.0.

Recommendation: math.div($grid-gutter-width, 2)
2021-05-26 09:37:40 +10:00
Henrik Giesel
31eaeef09b Rename anki/ to lib/ for export
import _ from "anki/x";

will become

import _ from "lib/x";

to fit the directory name.
2021-04-23 10:02:28 +10:00
Henrik Giesel
630ee9c6bb Use graphs-base and congrats-base 2021-04-13 19:47:03 +02:00
Damien Elmes
eb6502bd6e add missing copyright headers to *.svelte 2021-04-13 19:02:41 +10:00
Damien Elmes
43a8b8fec3 stop Svelte warnings from failing the build
+ check for them at test time
2021-04-12 14:28:09 +10:00
Damien Elmes
00eb89c2ec use singleton + free functions for i18n in ts
This allows for tree shaking, and reduces the congrats page from 150k
with the old enum solution to about 80k.
2021-03-26 20:38:44 +10:00
Henrik Giesel
8cb7d4a8ad Create search and days writable in GraphsPage to allow browserSearch to work 2021-03-22 02:44:08 +01:00
Henrik Giesel
1e5bb2f226 Create BrowserSearch component, because we cannot read from stores within slotted content 2021-03-22 01:42:23 +01:00
Henrik Giesel
abdf8a464f Remove pending, and resort to checking for value
- once value is set, it won't be unset
2021-03-22 01:42:23 +01:00
Henrik Giesel
fbf2c6f6fc Rename search and days to initialSearch and intitialDays in GraphsPage 2021-03-22 01:42:23 +01:00
Henrik Giesel
4ef0b3c977 Get it to work, if you change the input
- there's still an issue on initial load
2021-03-22 01:42:23 +01:00
Henrik Giesel
26d4854502 Compiles with WithGraphData 2021-03-22 01:42:23 +01:00
Henrik Giesel
c6ba8f779e Move Graph-specific html from GraphsPage to Graph.svelte 2021-03-22 01:42:21 +01:00
Damien Elmes
7c76693618 merge in Henrik's TS/Svelte refactor with some changes
- The previous commits moved the majority of the remaining global css
into components; move the remaining @emotion/css references into
ticks.scss and the styling of the Graph.svelte. This is not as elegant
as the emotion solution, but builds a whole lot faster, and most of
our styling can be scoped to a component anyway.
- Leave the .html files in ts/ for now. AnkiMobile uses them, and
AnkiDroid likely will in the future too. In the long run we'll likely
move to loading the JS into an existing page instead of loading a
separate page, but at that point we can just exclude the .html file from
copy_files_into_group() without affecting other clients.

Closes #1074
2021-03-21 23:01:18 +10:00
Damien Elmes
c02823b488 bundle all Svelte css into separate file
- svelte compilation outputs a separate .css file for each component
- compilation also adds an "import foo.css" to the top of each generated
.mjs file
- when the .mjs files are bundled into app.js, esbuild creates an app.css
as well
- graphs.scss was renamed to graphs_shared.scss and imported in the
top level GraphsPage. Henrik's style refactoring would be a better path
forward, but I needed to make this change for now, as the filenames were
conflicting.
2021-03-21 16:06:36 +10:00
Damien Elmes
45ec14184a show actual error when graphData fails
The original reason for the catch-all message was users with bad
data such as decimal intervals, but those get automatically coerced
these days. The common case should now be invalid search strings, which
we can show verbatim.
2021-01-29 14:39:05 +10:00
Henrik Giesel
45ff094392 Add bridgeCommand helper function 2021-01-26 01:25:54 +01:00
Henrik Giesel
76691176f6 Add a working example of searching from the stats screen in the Card Counts 2021-01-25 13:46:42 +01:00
Henrik Giesel
cee2f396da Add search event listeners on graphs 2021-01-25 13:45:42 +01:00
Henrik Giesel
f8c590c914 Fix RangeBox RevlogRange defaulting to All instead of Year 2021-01-23 13:57:43 +01:00
Henrik Giesel
15bd2e74f8 Hook up cardCountsSeparateInactive to PreferenceStore 2021-01-22 13:14:35 +01:00
Henrik Giesel
5ee3e0d0d7 Add PreferenceStore with gettable/settable preferences
* setting is not yet hooked up to rslib
2021-01-22 13:14:33 +01:00
Henrik Giesel
1516f5c37e Add GraphsPreferences endpoint to backend 2021-01-22 13:13:48 +01:00
Damien Elmes
f42e62aca6 controller should be marked nullable
While 'SvelteComponent | null' seems to make it into the .tsx file
created by svelte2tsx, the subsequent tsc call seems to discard the
'| null' part when creating the .d.ts file. Hack around it with a cast
for now; this may be fixed if we move to ts_project in the future.
2020-12-29 15:21:46 +10:00
Damien Elmes
8388b1d838 use local strategy for Svelte on CI
Allows some type errors to surface that were only being picked up
on Windows.

The root cause seems to be TypeScript picking up other .d.ts/.tsx
files in the same folder, which it can only do on Windows due to the
lack of sandboxing. On other platforms the other files can't be found,
and tsc changes the types into 'any'.

I experimented with modifying rules_svelte to build all .tsx files up
front and convert them to .d.ts in bulk, but ran into further issues
with conflicting types, as the typings in svelte2tsx seem to conflict
with Svelte's built-in types, and passing the dependencies in explicitly
causes them to be checked even though --skipLibCheck is passed in to
TypeScript.

Forcing sandboxing off is an ugly hack, and our best approach moving
forward may be to switch to ts_project for the Svelte generation -
it does appear that rules_nodejs favours it over ts_library anyway.
2020-12-29 14:50:33 +10:00
Henrik Giesel
71149656fc Fix typo 2020-12-27 02:04:45 +01:00
Henrik Giesel
20c2d55059 Fix formatting 2020-12-26 18:24:24 +01:00
Henrik Giesel
f9229be1ff Pass in RangeBox as an argument, decoupling it from GraphsPage 2020-12-26 14:40:55 +01:00
Henrik Giesel
4309b6f7a5 Fix displaying issue with active spinner 2020-12-26 00:16:54 +01:00
Henrik Giesel
1b4fd39d70 Make Year/All display correctly 2020-12-26 00:08:24 +01:00
Henrik Giesel
4f28750dff Move spinner back to RangeBox 2020-12-25 22:59:11 +01:00
Henrik Giesel
13acbe131c Put RangeBox into its own component 2020-12-25 22:29:42 +01:00
Henrik Giesel
3373cf7ad0 Make spinner's position sticky in relation to graphsContainer 2020-12-25 21:49:56 +01:00
Henrik Giesel
2362ba36d8 Put a transition:fade on the spinner 2020-12-25 20:11:46 +01:00
Henrik Giesel
73c17f9abd Remove .active class from .spin 2020-12-25 20:07:52 +01:00
Henrik Giesel
ee0bbd8fda Turn async function into svelte statement 2020-12-23 16:45:00 +01:00
Henrik Giesel
fa5e2407f3 Making days settable does not make sense, as it will be overwritten 2020-12-23 16:20:12 +01:00
Henrik Giesel
ef7f2ba2a6 Move infile to css to scss file 2020-12-22 22:39:22 +01:00
Henrik Giesel
0967308e53 Make showing of rangeBox based on parameter 2020-12-22 22:36:39 +01:00
Henrik Giesel
d5e9ce4b1d Bubble up days and search to caller 2020-12-22 22:25:47 +01:00
Henrik Giesel
9f8a9ad540 Pass in graphs as arguments into graphs() 2020-12-22 22:09:23 +01:00
Damien Elmes
4f8b19dcfb fix external consumption of ts rules, and simplify import path 2020-11-05 11:01:52 +10:00
Damien Elmes
ce3b08ac58 initial Bazel conversion
Running and testing should be working on the three platforms, but
there's still a fair bit that needs to be done:

- Wheel building + testing in a venv still needs to be implemented.
- Python requirements still need to be compiled with piptool and pinned;
need to compile on all platforms then merge
- Cargo deps in cargo/ and rslib/ need to be cleaned up, and ideally
unified into one place
- Currently using rustls to work around openssl compilation issues
on Linux, but this will break corporate proxies with custom SSL
authorities; need to conditionally use openssl or use
https://github.com/seanmonstar/reqwest/pull/1058
- Makefiles and docs still need cleaning up
- It may make sense to reparent ts/* to the top level, as we don't
nest the other modules under a specific language.
- rspy and pylib must always be updated in lock-step, so merging
rspy into pylib as a private module would simplify things.
- Merging desktop-ftl and mobile-ftl into the core ftl would make
managing and updating translations easier.
- Obsolete scripts need removing.
- And probably more.
2020-11-01 14:26:58 +10:00
Renamed from ts/src/stats/GraphsPage.svelte (Browse further)