Commit graph

65 commits

Author SHA1 Message Date
Henrik Giesel
dc9a65bd8b Disallow setting, deleting or defining properties on packages 2021-09-03 00:52:39 +02:00
Henrik Giesel
76ca1356ac Implement register-package and export some packages
Exported packages are:
* anki/packages
* anki/shortcuts
* anki/bridgecommand
2021-08-30 14:41:40 +02:00
Damien Elmes
481a87367c fix incorrect calendar day labels
https://forums.ankiweb.net/t/day-of-the-week-legend-on-heatmap/9450/7
2021-08-24 12:17:35 +10:00
Damien Elmes
875fd62264 expose require() instead of the svelte global
- Means add-on authors should not need to inject any code in their build
- Should be more flexible - we can export multiple libraries if we wish,
and don't have to worry about require() being clobbered by old add-ons.
2021-08-24 10:22:07 +10:00
Damien Elmes
e3b53fc078 split out remaining tags, stats, media and rendering 2021-07-10 23:16:18 +10:00
Damien Elmes
673955de5b split out sync, search, scheduler & config 2021-07-10 21:33:12 +10:00
Damien Elmes
1fb86d499d split out decks, deckconfig, notes, notetypes 2021-07-10 20:44:22 +10:00
Damien Elmes
c43674762e split out cards and collection 2021-07-10 19:52:31 +10:00
Damien Elmes
5255409093 refactor protobuf handling for split/import
In order to split backend.proto into a more manageable size, the protobuf
handling needed to be updated. This took more time than I would have
liked, as each language handles protobuf differently:

- The Python Protobuf code ignores "package" directives, and relies
solely on how the files are laid out on disk. While it would have been
nice to keep the generated files in a private subpackage, Protobuf gets
confused if the files are located in a location that does not match
their original .proto layout, so the old approach of storing them in
_backend/ will not work. They now clutter up pylib/anki instead. I'm
rather annoyed by that, but alternatives seem to be having to add an extra
level to the Protobuf path, making the other languages suffer, or trying
to hack around the issue by munging sys.modules.
- Protobufjs fails to expose packages if they don't start with a capital
letter, despite the fact that lowercase packages are the norm in most
languages :-( This required a patch to fix.
- Rust was the easiest, as Prost is relatively straightforward compared
to Google's tools.

The Protobuf files are now stored in /proto/anki, with a separate package
for each file. I've split backend.proto into a few files as a test, but
the majority of that work is still to come.

The Python Protobuf building is a bit of a hack at the moment, hard-coding
"proto" as the top level folder, but it seems to get the job done for now.

Also changed the workspace name, as there seems to be a number of Bazel
repos moving away from the more awkward reverse DNS naming style.
2021-07-10 19:17:05 +10:00
Damien Elmes
14263c7a79 move protobuf into separate folder in preparation for multiple files 2021-07-09 21:02:40 +10:00
Damien Elmes
cd303de619 specific encoding of strings.json
https://forums.ankiweb.net/t/win10-build-error-unicodedecodeerror-gbk-codec-cant-decode-byte-0x91/10714
2021-06-11 20:12:38 +10:00
Damien Elmes
33cecaa618 use different toolbar size on Mac
see discussion on 8c8bf26488
2021-06-05 11:28:36 +10:00
Damien Elmes
4a575dbe0a hook up some missing translations in deck options screen 2021-05-26 14:41:18 +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
6f31ab5990 Prefer event.which over event.{key,code}
It works better with alternative Latin-based keyboard layouts
2021-05-22 17:50:23 +02:00
Henrik Giesel
5cbda88605 Base shortcuts with letters no event.key, with symbols/numbers on event.code 2021-05-21 22:45:55 +02:00
Henrik Giesel
cc15145a0b Make numpad keys also cancel current shortcut sequence 2021-05-21 19:03:06 +02:00
Henrik Giesel
21cf99d612 Capitalize keyboard shortcut letters 2021-05-20 18:46:22 +02:00
Henrik Giesel
3145e4884f Instead of timeouts, make non-related keypresses cancel shortcut sequences 2021-05-20 18:32:53 +02:00
Henrik Giesel
abf1418695 Switch to keyboard shortcuts based on event.key 2021-05-20 18:28:59 +02:00
Damien Elmes
5bd3884a71 support card state mutator in test scheduler
Documentation to come
2021-05-17 16:59:02 +10:00
Damien Elmes
eefdd564e2 remove nested terneries and enable lint
@hgiesel would you mind quickly checking I've correctly captured
the logic here?
2021-04-23 13:00:18 +10:00
Damien Elmes
5e37cb7561 move isApplePlatform() into lib/shortcuts, and remove sveltelib file 2021-04-23 11:22:30 +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
d4e6fe6a34 Prefer optionalModifiers over register multiple shortcuts 2021-04-22 18:15:25 +02:00
Henrik Giesel
4ebad6f173 Add optionalModifiers parameter to registerShortcut 2021-04-22 17:28:38 +02:00
Henrik Giesel
33fc648695 Add license headers 2021-04-22 16:49:30 +02:00
Henrik Giesel
363469dc36 Satisfy formatter 2021-04-22 15:24:27 +02:00
Henrik Giesel
469c138ec1 Add shortcut labels for ColorPicker and Latex items 2021-04-22 14:35:44 +02:00
Henrik Giesel
7c2ac1fd37 Add getPlatformString for making shortcuts to platform string 2021-04-22 13:04:24 +02:00
Henrik Giesel
e2e1b4d37b Use registerShortcut within WithShortcut 2021-04-22 01:15:38 +02:00
Henrik Giesel
3b52bf6cb8 Add lib/shortcuts 2021-04-22 01:15:38 +02:00
Damien Elmes
de5f892807 allow postrequest to send a binary body; fix WithGraphData
As far as I can tell, the existing code was transforming the encoded
protobuf data into UTF8, and we're just lucky it wasn't causing problems
with the small message we were sending.
2021-04-20 17:47:52 +10:00
Damien Elmes
c0e615ddde support es6 imports in Jest tests
Switching to lodash-es caused Jest to fail. The standard Jest workflow
would be to transpile things with Bazel, but we can do it faster by
bundling with esbuild.

the log in lib.test.ts has revealed numbers are being set as Long instead
of JS numbers, and the published workaround for it is not working :-(
2021-04-17 16:38:45 +10:00
Damien Elmes
168af33aa8 add macro for invoking Jest 2021-04-16 23:46:31 +10:00
Damien Elmes
72193c45ec more experimental updates to deck config screen
- try out bootstrap modals - they're not perfect, but let's see how
they go for now. Won't be hard to switch to bridge commands if required.
- handle adding/renaming/removing
- add a class to manage the state
2021-04-16 23:29:21 +10:00
Damien Elmes
2a43d42323 run black/isort on Python scripts 2021-04-14 18:22:02 +10:00
Damien Elmes
1f475a1709 add missing copyright headers to *.ts 2021-04-13 18:57:08 +10:00
Damien Elmes
c6da01c4aa disable Jest tests on Windows again
It looks like the templated_args change only masked the error last time;
Jest seems broken on Windows with both the patched .24 version, latest
stable, and the new beta version too, presumably because symlinks are
being handled differently on Windows somehow. It might be possible to
hack around the issue by patching the following file, but I'm not sure:

https://github.com/facebook/jest/blob/master/packages/jest-haste-map/src/crawlers/node.ts
2021-04-12 15:39:46 +10:00
Damien Elmes
9d03e266e3 add naturalWholeUnit() and basic tests to lib/time.ts
naturalWholeUnit() is not currently used
2021-04-12 14:42:06 +10:00
Damien Elmes
125dcee811 remove obsolete comment 2021-03-26 21:47:23 +10:00
Damien Elmes
0006a385e1 allow js to request specific i18n modules
Brings the payload on the congrats page with a non-English language
down from about 150k to 15k
2021-03-26 21:43:36 +10:00
Damien Elmes
5ef9282f9b fix handling of variables that don't match ts naming style 2021-03-26 21:34:24 +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
Damien Elmes
b145b04ddf drop legacy enum from ts/ 2021-03-26 19:26:35 +10:00
Damien Elmes
6cde7ff536 update remaining TR references in ts/ 2021-03-26 19:24:48 +10:00
Damien Elmes
0e50259e6b update TR references with args in *.ts; fix average answer time 2021-03-26 19:10:39 +10:00
Damien Elmes
efb92d5ee9 generate ts methods for translations 2021-03-26 18:11:58 +10:00
Damien Elmes
0c63a7c8c4 rework translation handling
Instead of generating a fluent.proto file with a giant enum, create
a .json file representing the translations that downstream consumers
can use for code generation.

This enables the generation of a separate method for each translation,
with a docstring that shows the actual text, and any required arguments
listed in the function signature.

The codebase is still using the old enum for now; updating it will need
to come in future commits, and the old enum will need to be kept
around, as add-ons are referencing it.

Other changes:

- move translation code into a separate crate
- store the translations on a per-file/module basis, which will allow
us to avoid sending 1000+ strings on each JS page load in the future
- drop the undocumented support for external .ftl files, that we weren't
using
- duplicate strings in translation files are now checked for at build
time
- fix i18n test failing when run outside Bazel
- drop slog dependency in i18n module
2021-03-26 09:41:32 +10:00
Damien Elmes
72885bc710 move to new rules_nodejs protobuf example to unblock upgrade
@hgiesel the tag editor will need to add the following to the rollup
deps:

        "//ts/lib:backend_proto",
        "//ts/lib:fluent_proto",
2021-03-20 10:24:32 +10:00