Commit graph

1409 commits

Author SHA1 Message Date
RumovZ
45836b2ff8 Use null for missing stats 2021-10-18 09:36:31 +02:00
RumovZ
bde763dcad sentCardId -> requestedCardId 2021-10-18 09:12:10 +02:00
RumovZ
ff9dd841ca Use null for unset cardId 2021-10-18 09:11:00 +02:00
RumovZ
8fb055d72e Default to includeRevlog = true 2021-10-18 09:04:49 +02:00
RumovZ
b5368a0e23 Center placeholder 2021-10-18 09:01:25 +02:00
RumovZ
424a50dcdc Improve clarity in card info code a tiny little bit 2021-10-18 09:01:25 +02:00
RumovZ
ae4677c1c2 Move update logic into CardInfo.svelte
Also use a simpler and faster way to avoid race conditions.
2021-10-18 09:01:24 +02:00
RumovZ
847bf3fe12 Move update logic into CardInfo.svelte 2021-10-18 09:01:24 +02:00
RumovZ
083d2db98b Make CardStats a separate component 2021-10-18 09:01:23 +02:00
RumovZ
80ae938fc8 Implement reactively updating Card Info 2021-10-18 09:01:22 +02:00
Damien Elmes
659a175a13 drop ts_library() requirement in ts/svelte 2021-10-18 13:00:55 +10:00
Damien Elmes
5be9ae5229 pass ts deps into most Svelte packages; remove redundant deps
Henrik, I've left editable/editor alone to avoid causing a conflict;
please add them in your PR instead when you get a chance.
2021-10-18 12:44:31 +10:00
Damien Elmes
a78852d636 Svelte build improvements
1. All Svelte files in a package are compiled in one step now, which
ensures that properties that use types from a different Svelte file in the
same package are typed correctly. The single-file svelte() has been removed,
and compile_svelte() may be renamed to svelte() in the future.

2. The .ts files in the same package are included as part of the Svelte
compilation, so that types imported imported from .ts files in the
same package work.

3. Dependencies passed into the rule are now loaded into the TypeScript
compiler, so that properties referencing types from different packages
work. We'll need to update our compile_svelte() lines to list the
dependencies. For example, before this change:

% cat bazel-bin/ts/congrats/CongratsPage.svelte.d.ts
import { SvelteComponentTyped } from "svelte";
declare const __propDef: {
    props: {
        info: any;
    };
...

After adding //ts/lib to the deps of compile_svelte() in ts/congrats:

% cat bazel-bin/ts/congrats/CongratsPage.svelte.d.ts
import { SvelteComponentTyped } from "svelte";
import type { Scheduler } from "../lib/proto";
declare const __propDef: {
    props: {
        info: Scheduler.CongratsInfoResponse;
    };
...
2021-10-18 12:44:29 +10:00
Damien Elmes
276d8cc5a5 pass sole arg to cardStats as a dictionary
Easier to extend in the future, or (de)serialize in a strongly-typed
language.
2021-10-14 19:28:51 +10:00
Damien Elmes
dde0ef372f layout tweaks to card info
- negative margins result in truncated text when the window size
is reduced, so avoid them
- having a 100% table inside a flexbox is not responsive - the table
does not adjust its size as the width is increased or decreased
- in order to look decent on narrow screens (eg phones), we allow
margin collapsing
- in order to look decent on wide screens, we limit the maximum
width to something that is readable
- hide some columns in portrait mode on narrow screens

I tried preserving the centering with margin-left/right: auto, but
could not get it looking right, so have had to move things back to
left alignment.
2021-10-14 19:28:33 +10:00
Damien Elmes
084384c2b0 support #test in card-info.html
allows us to use scripts/ts-run and ts-watch to test the page
in Chrome by surfing to http://127.0.0.1:40000/_anki/pages/card-info.html#testXXX
2021-10-14 19:23:33 +10:00
RumovZ
ea9fc3730e Switch CardInfoDialog to ts page (#1414)
* Only collect card stats on the backend ...

... instead of rendering an HTML string using askama.

* Add ts page Card Info

* Update test for new `col.card_stats()`

* Remove obsolete CardStats code

* Use new ts page in `CardInfoDialog`

* Align start and end instead of left and right

Curiously, `text-align: start` does not work for `th` tags if assigned
via classes.

* Adopt ts refactorings after rebase

#1405 and #1409

* Clean up `ts/card-info/BUILD.bazel`

* Port card info logic from Rust to TS

* Move repeated field to the top

https://github.com/ankitects/anki/pull/1414#discussion_r725402730

* Convert pseudo classes to interfaces

* CardInfoPage -> CardInfo

* Make revlog in card info optional

* Add legacy support for old card stats

* Check for undefined instead of falsy

* Make Revlog separate component

* drop askama dependency (dae)

* Fix nightmode for legacy card stats
2021-10-14 19:22:47 +10:00
Damien Elmes
3a795aae22 declare bootstrap prereq in Svelte compile
Mistakenly stripped this out when removing the typescript dependencies
2021-10-13 11:48:22 +10:00
Henrik Giesel
ac92155a8e Put sass into repo directory (#1409)
Fix Sass build
2021-10-09 10:25:03 +10:00
Henrik Giesel
2680d1bad8 Fix prettier after moving node_modules to repo dir (#1413) 2021-10-09 10:13:14 +10:00
Henrik Giesel
f0b61782be Refactor i18n (#1405)
Merging note: the typing changes were fixed in a separate PR.

* Put rootDirs into subprojects

- typings do not work for any ts or svelte files
- if we set the 'rootDirs' in ts/tsconfig.json to '../bazel-bin/ts' and then inherit
  them from e.g. editor, the root will be changed to '../../bazel-bin/ts',
  however editor needs look in '../../bazel-bin/ts/editor' instead.

* Rename i18n and i18n_helpers to i18n-generated and i18n

- This way, we can restrict the awkwardness of importing files outside
  the ts directory within lib

* Fix missing typing of i18n and backend_proto by adding back symlinks

* Split up i18n-generated into i18n-{translate,modules}

* Change i18n from singleton to functions

* Revert "Put rootDirs into subprojects"

This partially reverts commit e1d4292ce3.

It seems like this might not be necessary after all.
However some other change made on this branch seems to have fixed
the .svelte.d.ts imports

* Introduce i18n-bundles to remove circular import

There was a circular import i18n.ts <-> i18n-translate.ts

* Create own directory for i18n

* Move lib/i18n/translate to lib/translate

* This restores tree shaking

* Update tsconfig libs and module

* es2018-2020 have wide support on all modern browsers including

* Switch bundles and langs inside i18n to variables again

* Add missing copyright header

* Rename translate.ts to ftl.ts

* Remove the symlinks again

I added them to fix to have completion for tr, however this would have
also have meant to abandon the tree shaking.
As we want to have tree shaking, it's also not necessary to have the
symlinks anymore

* Revert "Update tsconfig libs and module"

This reverts commit 0a96776a47.

* move withCollapsedWhitespace back to i18n/utils

* Add back /ts as in rootDirs
2021-10-07 23:31:49 +10:00
Damien Elmes
13ffa43d7e svelte needs its shims to generate prop typing
I erroneously removed them near the end of the ts_project work, and
didn't realise the properties had broken.
2021-10-07 21:33:21 +10:00
Damien Elmes
7cc3b1816c fix invalid arg to ButtonGroup revealed by typing fix 2021-10-07 21:33:15 +10:00
Damien Elmes
f209a72b7c move node_modules into root folder [action required]
Recommend removing ts/node_modules folder before attempting to
build after this update.

This moves ts/node_modules into the root of the project to work around
https://github.com/ankitects/anki/pull/1405#issuecomment-936213861

Also fixes the sass errors shown when running scripts/svelte-check
2021-10-07 11:42:27 +10:00
Damien Elmes
af88b480f9 use extra rootDir in tsconfig instead of symlinks
The nice thing about the symlink approach is that it allowed tsc -b
to function without any changes to the tsconfig.json file, but it meant
there were extra links we had to maintain. So instead, we just add an
extra rootDirs entry, and add two commented-out lines that can be
uncommented when wanting to build with tsc directly.
2021-10-01 18:36:52 +10:00
Damien Elmes
a5c7134d43 yarn upgrade --latest
bootstrap still held back
2021-10-01 12:52:53 +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
7ce0b944bd update svelte-check
Invoking from scripts/svelte-check is currently broken due to sass
imports - it appears to have been broken some time back.
2021-09-29 12:27:27 +10:00
Damien Elmes
899d0556e8 handle changed aria-expanded typing 2021-09-29 12:20:27 +10:00
Damien Elmes
6db52323dd make 'for' argument optional in TooltipLabel
The latest svelte-check has revealed we were not passing 'for' in
when we should have been. This is a quick hack to get the tests passing
again, but a better approach that actually makes this accessible again
would be good in the future.
2021-09-29 12:20:03 +10:00
Damien Elmes
9b994ac537 silence execCommand deprecation warnings for now 2021-09-29 11:36:37 +10:00
Damien Elmes
5d0736ab96 update svelte2tsx
We can now use the typings from the Svelte library instead of the
svelte2tsx shims
2021-09-25 11:07:31 +10:00
Damien Elmes
8f7e7498da update to TypeScript 4.4.x 2021-09-23 09:53:37 +10:00
Damien Elmes
81104f47f4 fixes for TypeScript 4.4.x
closes #1386
2021-09-23 09:52:21 +10:00
Damien Elmes
df26c61164 update ts deps
typescript and bootstrap have been pinned for now:

https://github.com/ankitects/anki/issues/1386
https://github.com/ankitects/anki/issues/1385

hint failures for svelte-check have also been temporarily turned
off, due to it now complaining about document.execCommand():

Hint: The signature '(commandId: string, showUI?: boolean, value?: string): boolean' of 'document.execCommand' is deprecated. (ts)
    const wrapWithForecolor = (color: string) => () => {
        document.execCommand("forecolor", false, color);
    };

Will follow up in #1377
2021-09-22 23:21:39 +10:00
Henrik Giesel
66608b06b0 Allow for explicit any 2021-09-17 21:30:32 +02:00
Henrik Giesel
16b6d95593 Make HandleSelection perfectly size when first activating 2021-09-17 21:23:04 +02:00
Henrik Giesel
1e2fa82446 Fix missizing of HandleSelection when first moving from empty to Mathjax 2021-09-17 20:54:37 +02:00
Henrik Giesel
82d93f3eae Ugly fix: do not execute moveCursorPastPostfix when front includes "anki-mathjax" 2021-09-17 20:12:11 +02:00
Henrik Giesel
222da3912a Add ChangeTimer.prototype.fireImmediately
so Mathjax is saved when exiting editor prematurely
2021-09-16 14:47:05 +02:00
Henrik Giesel
159e932f79 Wrap Mathjax compilation into try/catch 2021-09-16 14:31:20 +02:00
Henrik Giesel
4b0e35a357 Rename StickyBar and StickyBottom to StickyHeader and StickyFooter 2021-09-15 23:15:55 +02:00
Henrik Giesel
9f500cf78a Remove now unused import in TagEditor 2021-09-15 22:59:47 +02:00
Henrik Giesel
d6702c1c68 Fix suggestions not showing when typing space in a TagInput 2021-09-15 22:54:53 +02:00
Henrik Giesel
84eda7c547 Make the ImageHandle and MathjaxHandle dropdowns perfectly touch the HandleSelection 2021-09-15 22:26:32 +02:00
Henrik Giesel
f4aa6bf90b Stop propagation for paste in MathjaxHandle editor 2021-09-15 22:14:38 +02:00
Henrik Giesel
dbaba6233a Prevent hiding handles by clicking on handles 2021-09-15 17:56:56 +02:00
Henrik Giesel
d4c535183b Remove style attribute after remove float property if not styling left 2021-09-15 17:36:48 +02:00
Henrik Giesel
e10a5f0a38 Always correctly update MathjaxHandle position 2021-09-15 17:05:43 +02:00
Henrik Giesel
b7d8ae8f22 Correctly pass down dropdownObject... 2021-09-15 16:16:42 +02:00