Commit Graph

1811 Commits

Author SHA1 Message Date
RumovZ
4ea370959b
Fix flicker when remapping imported notetype field (#2005) 2022-08-08 01:01:25 +10:00
Henrik Giesel
3e28605638
Use wavy flags (flag-alternative) (#1995) 2022-08-01 20:15:22 +10:00
Damien Elmes
2e2fc799e2 Only show basename of CSV file 2022-07-23 17:53:50 +10:00
Damien Elmes
340da23104 Wrap type answer output in code tag; remove extra div
This would make more sense as a class on the outer div, but existing
templates reference code#typeans, so avoid breaking things for now.
2022-07-22 20:37:56 +10:00
Damien Elmes
f582181ea4 Upgrade Svelte for CVE 2022-07-22 20:06:45 +10:00
RumovZ
cc929687ae
Deck-specific Limits (#1955)
* Add deck-specific limits to DeckNormal

* Add deck-specific limits to schema11

* Add DeckLimitsDialog

* deck_limits_qt6.py needs to be a symlink

* Clear duplicate deck setting keys on downgrade

* Export deck limits when exporting with scheduling

* Revert "deck_limits_qt6.py needs to be a symlink"

This reverts commit 4ee7be1e10c4e8c49bb20de3bf45ac18b5e2d4f6.

* Revert "Add DeckLimitsDialog"

This reverts commit eb0e2a62d33df0b518d9204a27b09e97966ce82a.

* Add day limits to DeckNormal

* Add deck and day limits mock to deck options

* Revert "Add deck and day limits mock to deck options"

This reverts commit 0775814989e8cb486483d06727b1af266bb4513a.

* Add Tabs component for daily limits

* Add borders to tabs component

* Revert "Add borders to tabs component"

This reverts commit aaaf5538932540f944d92725c63bb04cfe97ea14.

* Implement tabbed limits properly

* Add comment to translations

* Update rslib/src/decks/limits.rs

Co-authored-by: Damien Elmes <dae@users.noreply.github.com>

* Fix camel case in clear_other_duplicates()

* day_limit → current_limit

* Also import day limits

* Remember last used day limits

* Add day limits to schema 11

* Tweak comment (dae)

* Exclude day limit in export (dae)

* Tweak tab wording (dae)

* Update preset limits on preset change

* Explain tabs in tooltip (dae)

* Omit deck and today limits if v2 is enabled

* Preserve deck limit when switching to today limit
2022-07-19 18:27:25 +10:00
RumovZ
cff04a288a
Fix card info not updating (#1957)
Update was not triggered if card id didn't change.
2022-07-12 10:34:48 +10:00
Damien Elmes
5ea78e1c8e Since DupeResolution is in CsvMetadata, we don't need to pass it separately
Follow-up to #1930
2022-06-27 17:15:54 +10:00
RumovZ
b6a7760cb4
Restore and save last dupe resolution setting (#1930)
* Restore dupe resolution setting

* Save dupe resolution setting

* Push config logic into backend (dae)
2022-06-24 15:10:06 +10:00
Matthias Metelka
e6f158e445
Fix descriptions overflowing field (#1925) 2022-06-23 13:32:07 +10:00
Henrik Giesel
c1e54e6842
Fix field description (#1923)
* Remove most of the original description placeholder implementation

* Move description showing logic to RichTextInput

- there is no need to propagate it to ContentEditable

* Remove the @html from field-description

This actually worked - however I removed it in case we'd rather offer
markdown support or something else in the future.

* Do not remove placeholder already on focus

- Other editors do not do it either

* Hide via hidden attribute instead of unmounting

* Do not pass content to ContentEditable

* Sort imports

* Change placeholder text color (dae)

In day mode, slightly-grey is almost indistinguishable from black
(at least on the monitor I'm using here)
2022-06-22 09:53:10 +10:00
RumovZ
1b8bab73d1
Csv import tweaks (#1920)
* Don't use special label for tags column

This was setting the label of whichever column the user chose for tags
to "Tags". Showing field content is more helpful.

* Map tags column automatically like fields
2022-06-22 09:44:12 +10:00
Damien Elmes
3eb8a6ce9d Pass content directly instead of its writable container 2022-06-21 12:24:00 +10:00
Damien Elmes
30c6bd58c9 Recalculate field map after delimeter changes
https://forums.ankiweb.net/t/anki-2-1-54-release-candidate/20861/8
2022-06-21 10:35:08 +10:00
Hikaru Y
bc5633e070
Fix field description not toggled properly (#1919)
It appears that a variable bound to the `innerHTML` property of
a contenteditable element is only updated when `input` event fires on
the element, and not when changes are made to the DOM programmatically.
2022-06-21 10:12:00 +10:00
Henrik Giesel
3969487e77
Join RichTextAPI and RichTextContextAPI + Expose anki/RichTextInput (#1918)
* Format scss correctly so it passes ts:format

* Use on and singleCallback in ImageHandle and MathjaxHandle

* Add a few comments

* Fix relict of partial commit

* Fix 'element not found' in ImageHandle

* Remove setting css on image handle twice

* Remove use of container in ImageHandle

* Remove use of container in MathjaxHandle

* Use unprefixed properties of RichTextInputAPI

* Inline api to get to RichTextInputAPI

* Join customStyles into RichTextInputAPI

* Export RichTextInput; Remove SetContext

* Address eslint and svelte_check
2022-06-20 16:11:27 +10:00
Henrik Giesel
336ad05693
Add EditorField export (#1915)
- This is useful when you want to set up hooks, etc. on the EditorField
  component
- Because when you can only use the NoteEditor export, you cannot notice
  when fields are mounted or destroyed
2022-06-20 12:07:07 +10:00
Henrik Giesel
ae69bb0834
Check event.key instead of event.code to detect Space in TagEditor (#1913)
* Closes #1901
2022-06-17 11:08:17 +10:00
Matthias Metelka
6d8fb35fab
Make field description a placeholder inside EditingArea (#1912)
* Move field description into EditingArea as placeholder

* Prevent insertion of breaks into empty fields

to allow :empty CSS selector to also work on fields other than the first one.

* Remove redundant setContext from EditingArea

* Fix import order

* Revert "Prevent insertion of breaks into empty fields"

This reverts commit 1615fd5cf441b1047dae6a34265acb9c5cae50b2.

* Use class:empty instead of :empty CSS pseudo-class

* Restrict description to single line, ellipse overflow

* Make description in field dialog a bit clearer
2022-06-17 11:02:30 +10:00
Abdo
1bab947c9c
Fix JS drop event not firing in the reviewer (#1906)
* Allow webviews to opt in to default D&D handling

* Remove redundant webview.js include

* Block default drag & drop behavior in reviewing screens

* Fix mypy error
2022-06-10 23:33:53 +10:00
RumovZ
6da5e5b042
CSV import/export fixes and features (#1898)
* Fix footer moving upwards

* Fix column detection

Was broken because escaped line breaks were not considered.
Also removes delimiter detection on `#columns:` line. User must use tabs
or set delimiter beforehand.

* Add CSV preview

* Parse `#tags column:`

* Optionally export deck and notetype with CSV

* Avoid clones in CSV export

* Prevent bottom of page appearing under footer (dae)

* Increase padding to 1em (dae)

With 0.5em, when a vertical scrollbar is shown, it sits right next to
the right edge of the content, making it look like there's no right
margin.

* Experimental changes to make table fit+scroll (dae)

- limit individual cells to 15em, and show ellipses when truncated
- limit total table width to body width, so that inner table is shown
with scrollbar
- use class rather than id - ids are bad practice in Svelte components,
as more than one may be displayed on a single page

* Skip importing foreign notes with filtered decks

Were implicitly imported into the default deck before.
Also some refactoring to fetch deck ids and names beforehand.

* Hide spacer below hidden field mapping

* Fix guid being replaced when updating note

* Fix dupe identity check

Canonify tags before checking if dupe is identical, but only add update
tags later if appropriate.

* Fix deck export for notes with missing card 1

* Fix note lines starting with `#`

csv crate doesn't support escaping a leading comment char. :(

* Support import/export of guids

* Strip HTML from preview rows

* Fix initially set deck if current is filtered

* Make isHtml toggle reactive

* Fix `html_to_text_line()` stripping sound names

* Tweak export option labels

* Switch to patched rust-csv fork

Fixes writing lines starting with `#`, so revert 5ece10ad05f331.

* List column options with first column field

* Fix flag for exports with HTML stripped
2022-06-09 10:28:01 +10:00
Damien Elmes
496bce229b Override older protobufjs pulled in via @bazel/typescript 2022-06-03 13:15:48 +10:00
Damien Elmes
5ae7a4e3c4 Update protobufjs due to CVE 2022-06-03 12:54:41 +10:00
Damien Elmes
f042c0b9ec Prevent protobufjs attempting to install packages at runtime 2022-06-03 12:51:34 +10:00
Damien Elmes
92e13ae0d3 Fix some layout issues in the CSV import screen
- Align headers with the settings below them
- More equally space rows
- Ensure Import button is anchored to the bottom (
caused by 9b0729970e)
2022-06-02 18:48:28 +10:00
RumovZ
42cbe42f06
Plaintext import/export (#1850)
* Add crate csv

* Add start of csv importing on backend

* Add Menomosyne serializer

* Add csv and json importing on backend

* Add plaintext importing on frontend

* Add csv metadata extraction on backend

* Add csv importing with GUI

* Fix missing dfa file in build

Added compile_data_attr, then re-ran cargo/update.py.

* Don't use doubly buffered reader in csv

* Escape HTML entities if CSV is not HTML

Also use name 'is_html' consistently.

* Use decimal number as foreign ease (like '2.5')

* ForeignCard.ivl → ForeignCard.interval

* Only allow fixed set of CSV delimiters

* Map timestamp of ForeignCard to native due time

* Don't trim CSV records

* Document use of empty strings for defaults

* Avoid creating CardGenContexts for every note

This requires CardGenContext to be generic, so it works both with an
owned and borrowed notetype.

* Show all accepted file types  in import file picker

* Add import_json_file()

* factor → ease_factor

* delimter_from_value → delimiter_from_value

* Map columns to fields, not the other way around

* Fallback to current config for csv metadata

* Add start of new import csv screen

* Temporary fix for compilation issue on Linux/Mac

* Disable jest bazel action for import-csv

Jest fails with an error code if no tests are available, but this would
not be noticable on Windows as Jest is not run there.

* Fix field mapping issue

* Revert "Temporary fix for compilation issue on Linux/Mac"

This reverts commit 21f8a261408cdae49ec031aa21a1b659c4f66d82.

* Add HtmlSwitch and move Switch to components

* Fix spacing and make selectors consistent

* Fix shortcut tooltip

* Place import button at the top with path

* Fix meta column indices

* Remove NotetypeForString

* Fix queue and type of foreign cards

* Support different dupe resolution strategies

* Allow dupe resolution selection when importing CSV

* Test import of unnormalized text

Close  #1863.

* Fix logging of foreign notes

* Implement CSV exports

* Use db_scalar() in notes_table_len()

* Rework CSV metadata

- Notetypes and decks are either defined by a global id or by a column.
- If a notetype id is provided, its field map must also be specified.
- If a notetype column is provided, fields are now mapped by index
instead of name at import time. So the first non-meta column is used for
the first field of every note, regardless of notetype. This makes
importing easier and should improve compatiblity with files without a
notetype column.
- Ensure first field can be mapped to a column.
- Meta columns must be defined as `#[meta name]:[column index]` instead
of in the `#columns` tag.
- Column labels contain the raw names defined by the file and must be
prettified by the frontend.

* Adjust frontend to new backend column mapping

* Add force flags for is_html and delimiter

* Detect if CSV is HTML by field content

* Update dupe resolution labels

* Simplify selectors

* Fix coalescence of oneofs in TS

* Disable meta columns from selection

Plus a lot of refactoring.

* Make import button stick to the bottom

* Write delimiter and html flag into csv

* Refetch field map after notetype change

* Fix log labels for csv import

* Log notes whose deck/notetype was missing

* Fix hiding of empty log queues

* Implement adding tags to all notes of a csv

* Fix dupe resolution not being set in log

* Implement adding tags to updated notes of a csv

* Check first note field is not empty

* Temporary fix for build on Linux/Mac

* Fix inverted html check (dae)

* Remove unused ftl string

* Delimiter → Separator

* Remove commented-out line

* Don't accept .json files

* Tweak tag ftl strings

* Remove redundant blur call

* Strip sound and add spaces in csv export

* Export HTML by default

* Fix unset deck in Mnemosyne import

Also accept both numbers and strings for notetypes and decks in JSON.

* Make DupeResolution::Update the default

* Fix missing dot in extension

* Make column indices 1-based

* Remove StickContainer from TagEditor

Fixes line breaking, border and z index on ImportCsvPage.

* Assign different key combos to tag editors

* Log all updated duplicates

Add a log field for the true number of found notes.

* Show identical notes as skipped

* Split tag-editor into separate ts module (dae)

* Add progress for CSV export

* Add progress for text import

* Tidy-ups after tag-editor split (dae)

- import-csv no longer depends on editor
- remove some commented lines
2022-06-01 20:26:16 +10:00
Damien Elmes
96bacf792c Increase limit on easy multiplier
https://forums.ankiweb.net/t/limited-easy-bonus/20044
2022-05-26 12:51:51 +10:00
wisherhxl
5e1b67bcbc
Fix ibus first keystroke goes two (#1886)
Calling `moveCaretToEnd()` when `richText` is empty will cause the first keystroke of
ibus-based input methods with candidates to goes double. For example, if you
type "a" it becomes "aa". This problem exists in many linux distributions.
When `richText` is empty, there is no need to place the caret, just return
as a workaround.
2022-05-26 10:47:55 +10:00
Damien Elmes
9b0729970e Fix deck options sticky bar at top disappearing on scroll
Issue was introduced in 7922f18296
when the styling was moved into base.scss. From what I can tell, there
are two locations where the current styling is required:

- the editor, to ensure the tags are shown at the bottom
- the change notetype screen, which requires this styling for a sticky
bar at top

I'm no CSS guru, so if someone thinks this could be solved in a better
way, please submit a follow-up PR.

Closes #1782
2022-05-23 16:10:45 +10:00
Henrik Giesel
7a77a8f2f9
Add getNoteId to exports (#1884) 2022-05-23 09:14:36 +10:00
Damien Elmes
ae18ba2a05 Switch editor to full MathJax package to fix broken autoloads
Re: https://forums.ankiweb.net/t/anki-2-1-53-release-candidate/20122/2

Autoloads in MathJax are asynchronous, and the caller is expected to
use asynchronous APIs when they are in use [1]. The editor uses the synchronous
tex2svg(), which throws a "MathJax retry" error when an autoload package
has not yet loaded. Attempting to use the package before it has loaded
appears to break future invocations as well, so the package fails to work
at all until a new webview is created.

The following HTML will reproduce the issue when added to a single card
in a new profile:

```
<strong>6&nbsp; &nbsp;&nbsp;</strong>Every combination of <anki-mathjax>\boldsymbol{v}=(1,-2,1)</anki-mathjax> and <anki-mathjax>\boldsymbol{w}=(0,1,-1)</anki-mathjax> has components that add to&nbsp; _____.<br>
```

Ideally we'd switch the MathJax rendering to be asynchronous, but that
didn't work well when I tried it in #1862. For now I've just switched
to the full package, which adds about 130KB to the final minified JS
(2.76MB), and likely slows down editor loading somewhat.

[1] https://github.com/mathjax/MathJax/issues/2557#issuecomment-727655089
2022-05-21 14:01:38 +10:00
Damien Elmes
8b1afc7e3a Reveal cloze answers in MathJax preview
Closes #1862
2022-05-19 12:48:12 +10:00
BlueGreenMagick
6ddbf7bc10
Fix graphs tooltip incorrect position (#1872) 2022-05-19 11:08:57 +10:00
Henrik Giesel
dba12e8cb3
Allow style tags in HTML editor (#1870) 2022-05-17 16:37:20 +10:00
Damien Elmes
a451fec5a1 Fix new card positions being included in future due graph
Introduced in f60de39015

https://forums.ankiweb.net/t/anki-2-1-52-qt6-stats-bug-future-due-backlog/20016
2022-05-16 15:14:15 +10:00
Henrik Giesel
826e135510
Update Svelte to 3.48.0 (#1867) 2022-05-16 14:47:38 +10:00
Henrik Giesel
1b18005d6e
Transform <br> in Mathjax to newlines (#1866)
* Transform <br> in Mathjax to newlines

* Add missing quantifier
2022-05-16 14:42:10 +10:00
Damien Elmes
a070bec03c Allow alt tags when pasting images
https://forums.ankiweb.net/t/do-not-strip-alt-attribute-when-pasting-images-from-the-web/20007
2022-05-16 14:32:24 +10:00
Henrik Giesel
3b8aa97396
Use same config for editor and reviewer Mathjax (#1865)
* Remove custom config and use tex-chtml-full for editor Mathjax

* Add mathjax package in /ts

* Share mathjax config between tex-svg and tex-chtml

* Use "[+]" in Mathjax config again

* Remove mention of MathJaxReady

* Satisfy eslint
2022-05-13 13:23:35 +10:00
Henrik Giesel
b6fb64fde1
Implement cloze buttons in Mathjax editor (#1860)
* Introduce RichTextClozeButtons

* Implement cloze buttons in Mathjax editor
2022-05-13 13:04:20 +10:00
Henrik Giesel
52438fe4c9
Move focus into HTML editor when shown (#1861)
* Move focus into input field, when input is shown

* Change trapFocusOut to move focus into available inputs

- This means that e.g. closing the HTML editor with focus in it will
  focus the visual editor in turn

* Prevent Control+A unselecting tag editor when no tags exist
2022-05-13 13:02:03 +10:00
Henrik Giesel
de2cc20c59
Change how resizable images work (#1859)
* Add ResizableImage.svelte in ts/editable

* Set image constrained via attributes instead of managed style sheet

* Implement new constrained size method

* Turn WithImageConstrained.svelte into normal ts file

* Introduce removeStyleProperties

Removes "style" attribute if all style properties were cleared

* Avoid --editor-width and use one variable set on container

* Disable shrinking if already smaller than shrunken size

* Add button to restore image to original size

* Don't allow restoring original size if no custom width set

* Bottom-center HandleLabel

* Satisfy svelte-check
2022-05-13 12:57:07 +10:00
BlueGreenMagick
fb5521eeed
remove image.style.height on resize (#1856) 2022-05-11 10:06:34 +10:00
Henrik Giesel
89530c5f24
Change sequence of Mathjax escaping (#1854) 2022-05-10 11:54:06 +10:00
Henrik Giesel
6043d2f5a2
Set editor size to 1.6 on Windows as well (#1853) 2022-05-10 11:48:11 +10:00
Henrik Giesel
96d9539b9d
Fix activeName updating wrongly when selecting previous tag from invalid tag (#1851) 2022-05-10 11:45:41 +10:00
BlueGreenMagick
68482d37a1
select all tags with Ctrl+A (#1847) 2022-05-10 11:39:54 +10:00
BlueGreenMagick
9d98c62d50
Fix when tooltip changes before tooltipObject is created (#1845)
It can happen in TagWithTooltip.svelte
when a tag is normalized beause of leading/trailing delimiter
2022-05-10 11:36:54 +10:00
BlueGreenMagick
fc8b976ca8
fix typo. Shortcut uses on:action not on:click (#1846) 2022-05-09 19:55:35 +10:00
BlueGreenMagick
faa21266db
Fix caret jumping to start when unselecting autocomplete suggestion (#1844) 2022-05-09 11:15:56 +10:00
BlueGreenMagick
cc374996cc
align tag icon and text (#1843) 2022-05-09 11:15:44 +10:00
Henrik Giesel
1ec227d926
Make TagAddButton focusable and simulate click on focus (#1838) 2022-05-07 09:15:58 +10:00
Damien Elmes
bc6ede7c11 Fix &amp; showing up in MathJax
https://forums.ankiweb.net/t/anki-2-1-52-release-candidate/19412/22

Accidentally introduced in #1818
2022-05-03 14:21:31 +10:00
Damien Elmes
6f0d86b9a9 Cap tag matches to 10 on macOS/Qt5 to work around Chromium perf issue
Closes #1825
2022-04-27 19:23:07 +10:00
Damien Elmes
f60de39015 Fix due graph showing wrong date for review cards with resched off
Since we are using the original due date instead of the current one,
the learning check needs to be based on the card type, not its current
queue.

https://forums.ankiweb.net/t/anki-2-1-51-release-candidate/18942/22
2022-04-25 14:14:08 +10:00
Henrik Giesel
b8eabfd622
Remove onInput call in input handler (#1819)
This was implemented by me to prevent seemingly empty fields,
which however still contain some HTML (e.g. <div></div>) and
thus will trigger in the templates.
However it only worked in very limited cases, maybe we could
solve this better by indicating whether a field has content somehow.
2022-04-25 13:56:05 +10:00
Henrik Giesel
2be1f4c56d
Instead of transforming to {\lt}, transform to &lt; (#1818)
* Instead of transforming to {\lt}, transform to &lt;

- In Mathjax editor
- This way you can also use Mathjax convenience shortcuts like <=> in
  chemistry mode: \ce{<=>}

* Remove unused translateEntitiesToMathjax() (dae)

https://github.com/ankitects/anki/pull/1818#discussion_r857238310
2022-04-25 13:42:54 +10:00
Matthias Metelka
2b739d76b2
Align list items to start (#1816) 2022-04-22 14:18:11 +10:00
Matthias Metelka
770fabd51b
Remove unnecessary night mode rule for typeans (#1815)
which caused https://forums.ankiweb.net/t/shaddow-below-cloze-type-area-in-night-mode/19287/2
2022-04-22 14:17:43 +10:00
Henrik Giesel
cf78a555c6
Add some component comment (#1779)
* Add a component comment for NoteEditor

* Move comments above component template

* EditorField -> EditingArea
2022-04-19 17:20:26 +10:00
Damien Elmes
adbe96ca00
Load page script after body created (#1802)
document.body must exist by the time the top level Svelte component
initializes.

https://forums.ankiweb.net/t/2-1-50-editor-wont-show-when-addons-load-many-js-files/19036
2022-04-19 17:16:56 +10:00
Damien Elmes
856d4763a9 Switch strong/em back to b/i
In the absence of strong arguments either way, and given the fact that
strong/em has broken a few (perhaps rare) use-cases, reverting seems
prudent. But happy to revisit this again in the future if someone has
a convincing argument for why we should be doing it differently.

Closes #1807
2022-04-19 16:28:44 +10:00
Henrik Giesel
6017214042
Fix resetting of formatting modes when pressing modifer or dead keys (#1811)
* Fix shift removing bold formatting

* Remove input handler on selection change

We listened to "non-input events" mostly to catch events that
change the selection (like Ctrl-a, or arrow keys) anyway
2022-04-19 16:08:32 +10:00
Damien Elmes
a9769813ba Add back support for custom mountpoint in card stats
The move to separate .html files broke our legacy card stats routine.

Related: d1d71ffdbb
2022-04-15 15:30:05 +10:00
Henrik Giesel
f3f5a42218
Speed up editor by lazily loading CodeMirror - Second try (#1776)
* Revert "Revert "Speed up editor by lazily loading CodeMirror (#1766)""

This reverts commit b0a2884f19.

* Pass in options via action update + Make access to editor optional
2022-04-09 13:25:54 +10:00
Abdo
964f0a5763
Add relative overdueness to review order (#1757)
* Add relative overdueness to review order

* Add test for relative overdue
2022-04-09 13:20:09 +10:00
Damien Elmes
b0a2884f19 Revert "Speed up editor by lazily loading CodeMirror (#1766)"
This reverts commit 0db921dd39.

This caused a regression that needs looking into:
https://github.com/ankitects/anki/issues/1775
2022-04-06 11:08:32 +10:00
Damien Elmes
1a55942ffa Fix invisible tag input in Qt5 (thanks to Hikaru)
Closes #1768
2022-04-05 09:53:36 +10:00
Henrik Giesel
0db921dd39
Speed up editor by lazily loading CodeMirror (#1766) 2022-04-03 19:00:20 +10:00
Henrik Giesel
7bfd7245e0
Fix HighlightColorButton setting last text color (#1765) 2022-04-02 14:58:32 +10:00
Henrik Giesel
67c1f7368e
Set caret inside chemical expression in Mathjax (#1763) 2022-03-31 23:39:49 +10:00
Damien Elmes
6df63f8643 Tweak cloze deletion labels 2022-03-31 14:47:51 +10:00
Henrik Giesel
5b1fcccf33
Add extra button group for cloze commands (#1756)
* First attempt at adding a directory for icons under //ts

* Fix image import

* Fix import order

* Add cloze button group

* Fix issue with toolbar.toolbar dynamically slottable

* Change tooltip for repeating cloze deletion

* Fix repeat cloze button not working on macOS (dae)
2022-03-31 13:30:00 +10:00
Henrik Giesel
7f737b60c6
Fix infinite update loop in editor with invalid input HTML (#1761)
* Use async function in PlainTextInput

* Clean up PlainTextInput

* Refactor logic from {Rich,Plain}TextInput into own files

* Remove prohibited tags on content.subscribe which also parses the html
2022-03-31 11:17:13 +10:00
Damien Elmes
f0dc6e103f Fix "repeat cloze" shortcut regression
Closes #1748 again.
2022-03-30 14:52:16 +10:00
Damien Elmes
91ca5090aa Don't attempt to localize numbers in SpinBoxFloat
Issue report: 
https://forums.ankiweb.net/t/anki-2-1-50-beta-6-release-candidate/18181/71

Localization was added in #1566. It works fine in the Qt5 build, but
the Qt6 build appears broken. This appears to be a change in Chromium,
and the latest Chrome has the same issue. Whether it's a legitimate bug
on their end, a deliberate change in behaviour, or we're doing something
wrong, I do not know.
2022-03-29 14:45:18 +10:00
Henrik Giesel
7977a0dc1f
Allow using keyup with registerShortcut (#1755) 2022-03-29 09:28:44 +10:00
Damien Elmes
5dab7ed47e Use original due date for learning cards as well in the future due graph
Closes #1735
2022-03-25 08:39:52 +10:00
Henrik Giesel
bf20353b53
Add tooltip that you can double-click image for restoring its size (#1738)
* Add tooltip that you can double-click image for restoring its size

* Update ftl/core/editing.ftl

Lower case label
2022-03-24 19:53:57 +10:00
Henrik Giesel
9029c5f497
Fix cursor sometimes not being moved into mathjax editor (#1737) 2022-03-24 18:29:30 +10:00
Damien Elmes
7ab79aad8b
Update ts deps for minimist issue (#1739)
Presumably not an issue for our use case, but this removes the warning
from GitHub.

ef88b9325f
2022-03-24 10:24:56 +10:00
Henrik Giesel
2d00b6659f
Fix add-on usages of addMedia (#1721)
* Expose old .addMedia again, and use a new resolve_media for built-in uses

* Add an explaining comment for addMedia

* Add some docstrings (dae)
2022-03-16 10:29:06 +10:00
Bruce Harris
d7a101827a
Extend maximum answer time... (#1698)
* Extend maximum answer time...

Previously the time allowed to answer a question was capped at 10 minutes.
While this makes sense for fact recall, it limits the utility of Anki when
used for solving problems that can take more time to work through. This
extends the maximum answer time to 2 hours, which seems to be a reasonable
upper limit for solving a math or algorithm question.

* Add warning when max answer time exceeds 10 minutes

* Move warning below input field
2022-03-15 10:06:45 +10:00
Henrik Giesel
1ec3741934
Fix outstanding tag editor issues (#1717)
* Start using WithFloating for SelectedTagBadge

* Adjust arrow on WithFloating for all directions

* Move TagOptionsBadge to its own sub directory

* Show autocomplete menu via WithFloating

* Have WithFloating return asReference instead of initializing its own reference element

* Add html: overflow: hidden for editor

* Replace ButtonToolbar with generic div

* Move scroll logic into autocomplete item + restrict Popover width to 95vw

* Fix autocomplete menu after pressing enter after selecting

- should not trigger an autocomplete choose

* Overlap TagInput perfectly with Tag

* Satisfy formatter

* Fix autocompletion item scrolling too much

* Remove unused Tag.svelte focusable prop

* Remove console.log

* Fix floating arrow is a diamond in dark mode

* Set autocompletion menu to 80vw
2022-03-11 15:48:49 +10:00
Henrik Giesel
76bdfb3899
Add a flag to allow loading the fields dialog in a web view (#1706)
* Load fields_web from fields.py if appropriate flag is set

* Add FieldsPage as entry for new fields view

* Pass mypy

* Fix pylint

* Fix fields_web in Qt5 (dae)

May not be related to the CI error, but required for compatibility
with Qt5.
2022-03-03 22:45:26 +10:00
Henrik Giesel
29d17a84fc
Fix newline shortcut in MathjaxMenu (#1705) 2022-03-03 18:55:07 +10:00
Henrik Giesel
88217c5e7d
Replace (some) Bootstrap dropdowns with Floating UI (#1695)
* Implement a first version of WithFloating and Portal

* Add outside slot for Portal

* Execute computePosition from WithFloating

* Set up a first example of new WithFloating with the Latex menu

* Use autoUpdate in WithFloating

* Create sveltelib/position

* Add event-store

* Use event-store in close-on-click

* Implement subscribeToUpdates

* Introduce sass/elevation

* Split close-on-click to closing-click and subscribe-trigger

* Have closing-* stores return a symbol

- This way they act more of an EventEmitter than a store

* Allow passing show store

* Remove styling on float on updatePosition removal

* Implement a nice border for dropdowns

* Apply different border and box-shadow to Popover in dark/light theme

* Fix Ctrl+Shift+T not working

* Satisfy formatters and tests

* Add copyright header

* move copyright header to top (dae)
2022-03-02 14:21:19 +10:00
Henrik Giesel
92bf23df99
Use async functions in .svelte files (#1693)
* Use async functions in CodeMirror.svelte

* Fix using async functions by modifying svelte-preprocess output

* Revert "Fix using async functions by modifying svelte-preprocess output"

This reverts commit 94c9cadaaa3ca2084780833e9efc7807f2f1d1a9.

Trying a different fix.

* Change TypeScript target to ES2019
2022-02-27 22:35:47 +10:00
Damien Elmes
6941bccde4 Add support for proto3 optional scalars
Protobuf 3.15 introduced support for marking scalar fields like
uint32 as optional, and all of our tooling appears to support it
now. This allows us to use simple optional/null checks in our Rust/
TypeScript code, without having to resort to an inner message.

I had to apply a minor patch to protobufjs to get this working with
the json-module output; this has also been submitted upstream:
https://github.com/protobufjs/protobuf.js/pull/1693

I've modified CardStatsResponse as an example of the new syntax.

One thing to note: while the Rust and TypeScript bindings use optional/
null fields, as that is the norm in those languages, Google's Python
bindings are not very Pythonic. Referencing an optional field that is
missing will yield the default value, and a separate HasField() call
is required, eg:

```
>>> from anki.stats_pb2 import CardStatsResponse as R
... msg = R.FromString(b"")
... print(msg.first_review)
... print(msg.HasField("first_review"))
0
False
```
2022-02-27 19:42:06 +10:00
Henrik Giesel
55c64e5b54
Fix Mathjax sometimes being deleted even though it's not selected (#1696)
* Fix frame element being deleted, when a frame handle is deleted from while selected

* Fix mixing up preceding/following
2022-02-27 17:58:01 +10:00
Henrik Giesel
5963791d85
Consider using --force-message for ts/protobuf.bzl (#1694)
* Use --force-message in ts/protobuf

* Remove some now unnecessary type assertions in deck-options/lib

* Satisfy formatter
2022-02-27 17:35:07 +10:00
Damien Elmes
625d8596a4 Update to Jest 28 alpha
https://github.com/ankitects/anki/pull/1682
2022-02-25 16:20:50 +10:00
Damien Elmes
902f125954 Update rules_nodejs 2022-02-25 16:19:26 +10:00
Damien Elmes
f3b0c31354 Update JS deps 2022-02-25 15:29:49 +10:00
Henrik Giesel
50e36bc312
Fix plain text (#1689)
* Move remove-prohibited-tags logic from PlainTextInput

* Make CodeMirror export a promise

* Offer lifecycle hooks for PlainTextInput for easily accessing code mirror instance

* Fix </> breaking Mathjax

* remove debug statement (dae)
2022-02-25 11:14:26 +10:00
Henrik Giesel
7c27159149
Fix setting of caret when creating clozes (#1688) 2022-02-25 11:07:44 +10:00
Henrik Giesel
0d83581ab0
Fix insert media always insert at the start (on Windows) (#1684)
* Move Trigger into its own file

* Try implement HandlerList

* Implement new input handler and handler-list

* Use new refocus HandlerList in TextColorButton

* Fix TextColorButton on windows

* Move ColorPicker to editor-toolbar

* Change trigger behavior of overwriteSurround

* Fix mathjax-overlay flushCaret

* Insert image via bridgeCommand return value

* Fix invoking color picker with F8

* Have remove format work even when collapsed

* Satisfy formatter

* Insert media via callback resolved from python

* Replace print with web.eval

* Fix python formatting

* remove unused function (dae)
2022-02-25 10:59:06 +10:00
Damien Elmes
1a3eef505f interday sibling burying is only valid in v3 2022-02-23 14:33:52 +10:00
Henrik Giesel
8b84368e3a
Move all buttons to our custom inline surrounding (#1682)
* Clarify some comments

* Don't destructure insertion trigger

* Make superscript and subscript use domlib/surround

* Create new {Text,Highlight}ColorButton

* Use domlib/surround for textcolor

- However there's still a crucial bug, when you're breaking existing
  colored span when unsurrounding, their color is not restored

* Add underline format to removeFormats

* Simplify type of ElementMatcher and ElementClearer for end users

* Add some comments for normalize-insertion-ranges

* Split normalize-insertion-ranges into remove-adjacent and remove-within

* Factor out find-remove from unsurround.ts

* Rename merge-mach, simplify remove-within

* Clarify some comments

* Refactor first reduce

* Refactor reduceRight

* Flatten functions in merge-ranges

* Move some functionality to merge-ranges and do not export

* Refactor merge-ranges

* Remove createInitialMergeMatch

* Finish refactoring of merge-ranges

* Refactor merge-ranges to minimal-ranges and add some unit testing

* Move more logic into text-node

* Remove most most of the logic from remove-adjacent

- remove-adjacent is still part of the "merging" logic, as it increases
  the scope of the child node ranges

* Add some tests for edge cases

* Merge remove-adjacent logic into minimal-ranges

* Refactor unnecessary list destructuring

* Add some TODOs

* Put removing nodes and adding new nodes into sequence

* Refactor MatchResult to MatchType and return clear from matcher

* Inline surround/helpers

* Shorten name of param

* Add another edge case test

* Add an example where commonAncestorContainer != normalization level

* Fix bug in find-adjacent when find more than one nested nodes

* Allow comments for Along type

* Simplify find-adjacent by removing intermediate and/or curried functions

* Remove extend-adjacent

* Add more tests when find-adjacent finds by descension

* Fix find-adjacent descending into block-level elements

* Add clarifying comment to refusing to descend into block-level elements

* Move shifting logic into find-adjacent

* Rename file matcher to match-type

* Give a first implemention of TreeVertex

* Remove MatchType.ALONG

- findAdjacent now directly modifies the range

* Rename MatchType.MATCH into MatchType.REMOVE

* Implement a version of find-within that utilizies match-tree

* Turn child node range into a class

* Fix bug in new find-adjacent function

* Make all find-adjacent tests test for ranges

* Surrounding within farthestMatchingAncestor when available

* Fix an issue with negligable elements

- also rename "along" elements to "negligable"

* Add two TODOs to SurroundFormat interface

* Have a messy first implementation of the new tree-node algorithm

* Maintain whether formatting nodes are covered or within user selection

* Move covered and insideRange into TreeNode superclass

* Reimplement findAdjacent logic

* Add extension logic

* Add an evaluate method to nodes

* Introduce BlockNode

* Add a first evaluate implementation

* Add left shift and inner shift logic

* Implement SurroundFormatUser

* Allow pass in formatter, ascender and merger from outside

* Fix insideRange and covered switch-up

* Fix MatchNode.prototype.isAscendable

* Fix another switch-up of covered and insideRange...

* Remove a lot of old code

* Have surround functions only return the range

- I still cannot think of a good reason why we should return addedNodes
  and removedNodes, except for testing.

* Create formatting-tree directory

* Create build-tree directory + Move find-above up to /domlib

* Remove range-anchors

* Move unsurround logic into no-splitting

* Fix extend-merge

* Fix inner shift being eroneusly returned as left shift

* Fix oversight in SplitRange

* Redefine how ranges are recreated

* Rename covered to insideMatch and put as fourth parameter instead of third

* Keep track of match holes and match leaves

* Rename ChildNodeRange to FlatRange

* Change signature of matcher

* Fix bug in extend-merge

* Improve Match class

* Utilize cache in TextColorButton

* Implement getBaseSurrounder for TextColorButton

* Add matchAncestors field to FormattingNode

* Introduce matchAncestors and getCache

* Do clearing during parsing already

- This way, you know whether elements will be removed before getting to
  Formatting nodes

* Make HighlightColorButton use our surround mechanism

* Fix a bug with calling .removeAttribute and .hasAttribute

* Add side button to RemoveFormat button

* Add disabled to remove format side button

* Expose remove formats on RemoveFormat button

* Reinvent editor/surround as Surrounder class

* Fix split-text when working with insert trigger

* Try counteracting the contenteditable's auto surrounding

* Remove matching elements before normalizing

* Rewrite match-type

* Move setting match leaves into build

* Change editing strings

- So that color strings match bold/italic strings better

* Fix border radius of List options menu

* Implement extensions functionality

* Remove some unnecessary code

* Fix split range endOffset

* Type MatchType

* Reformat MatchType + add docs

* Fix domlib/surround/apply

* Satisfy last tests

* Register Surrounder as package

* Clarify some comments

* Correctly implement reformat

* Reformat with inactive eraser formats

* Clear empty spans with RemoveFormatButton

* Fix Super/Subscript button

* Use ftl string for hardcoded tooltip

* Adjust wording
2022-02-22 22:17:22 +10:00
RumovZ
131a94dd85
Config for burying interday learning cards (#1680)
* Add config for burying interday learning cards

* Expose bury interday learning config in GUI
2022-02-22 21:37:59 +10:00
Damien Elmes
d1d71ffdbb add back support for custom mount point in congrats screen
This was inadvertently dropped in 478b3a53f1,
but AnkiWeb requires it.

In the future we will need to give these index pages a bit more thought,
as it's not very helpful to be exporting a creation function if we're
automatically mounting as the module is imported. Dropping the automatic
mounting would give us more flexibility, but currently that leads to
a FOUC in night mode, as the webview is revealed prior to a subsequent
web.eval() call being able to fire.
2022-02-17 16:28:48 +10:00
Damien Elmes
4b941d9461 older Safari does not support Blob.arrayBuffer() 2022-02-15 15:02:45 +10:00
Damien Elmes
b652e3b895 add class to 'show timer' switch 2022-02-14 20:04:19 +10:00
Damien Elmes
c41e455554 fix reviewer_extras 2022-02-14 18:46:50 +10:00
RumovZ
d55f080733
V3 parent limits (#1638)
* avoid repinning Rust deps by default

* add id_tree dependency

* Respect intermediate child limits in v3

* Test new behaviour of v3 counts

* Rework v3 queue building to respect parent limits

* Add missing did field to SQL query

* Fix `LimitTreeMap::is_exhausted()`

* Rework tree building logic

https://github.com/ankitects/anki/pull/1638#discussion_r798328734

* Add timer for build_queues()

* `is_exhausted()` -> `limit_reached()`

* Move context and limits into `QueueBuilder`

This allows for moving more logic into QueueBuilder, so less passing
around of arguments. Unfortunately, some tests will require additional
work to set up.

* Fix stop condition in new_cards_by_position

* Fix order gather order of new cards by deck

* Add scheduler/queue/builder/burying.rs

* Fix bad tree due to unsorted child decks

* Fix comment

* Fix `cap_new_to_review_rec()`

* Add test for new card gathering

* Always sort `child_decks()`

* Fix deck removal in `cap_new_to_review_rec()`

* Fix sibling ordering in new card gathering

* Remove limits for deck total count with children

* Add random gather order

* Remove bad sibling order handling

All routines ensure ascending order now.
Also do some other minor refactoring.

* Remove queue truncating

All routines stop now as soon as the root limit is reached.

* Move deck fetching into `QueueBuilder::new()`

* Rework new card gather and sort options

https://github.com/ankitects/anki/pull/1638#issuecomment-1032173013

* Disable new sort order choices ...

depending on set gather order.

* Use enum instead of numbers

* Ensure valid sort order setting

* Update new gather and sort order tooltips

* Warn about random insertion order with v3

* Revert "Add timer for build_queues()"

This reverts commit c9f5fc6ebe87953c17a0c842990b009b5596c69c.

* Update rslib/src/storage/card/mod.rs (dae)

* minor wording tweaks to the tooltips (dae)

+ move legacy strings to bottom
+ consistent capitalization (our leech action still needs fixing,
but that will require introducing a new 'suspend card' string as the
existing one is used elsewhere as well)
2022-02-10 09:55:43 +10:00
Henrik Giesel
30427fb540
Fix editor dropdowns (#1649) 2022-02-08 14:13:55 +10:00
Henrik Giesel
c0d47e18b7
Fix CommandIconButton (#1648)
- It did not respect shortcuts
2022-02-08 14:13:18 +10:00
Henrik Giesel
16e9e56ad8
Make sure initial comments are preserved in HTML editor (#1647) 2022-02-08 14:07:09 +10:00
Henrik Giesel
0c81bbce04
Fix field not restored if active (#1639)
* Fix field not being restored after Undo, if field also has focus

* Execute moveCaretToEnd after undoing a change

- Otherwise the caret might be placed in seemingly random positions

* Fix wording of comments

* Remove autofocus functionality of EditingArea

- instead await a tick in focusField
- We used the autofocus prop for the initial focus setting when opening the
  editor. However it seems that awaiting tick in focusField also does the trick.
2022-02-05 15:58:31 +10:00
Henrik Giesel
c5280cd056
Fix CodeMirror retaining history of unrelated notes (#1640) 2022-02-04 18:40:50 +10:00
Henrik Giesel
30bbbaf00b
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
Damien Elmes
83baa946dd fix mojibake on congrats screen
a8d4774cdb (commitcomment-65963462)
2022-02-04 18:25:40 +10:00
Henrik Giesel
a981e56008
Improved add-on extension API (#1626)
* Add componentHook functionality

* Register package NoteEditor

* Rename OldEditorAdapter to NoteEditor

* Expose instances in component-hook as well

* Rename NoteTypeButtons to NotetypeButtons

* Move PreviewButton initialization to BrowserEditor.svelte

* Remove focusInRichText

- Same thing can be done by inspecting activeInput

* Satisfy formatter

* Fix remaining rebase issues

* Add .bazel to .prettierignore

* Rename currentField and activeInput to focused{Field,Input}

* Move identifier to lib and registration to sveltelib

* Fix Dynamic component insertion

* Simplify editingInputIsRichText

* Give extra warning in svelte/svelte.ts

- This was caused by doing a rename of a files, that only differed in
  case: NoteTypeButtons.svelte to NotetypeButtons.svelte
- It was quite tough to figure out, and this console.log might make it
  easier if it ever happens again

* Change signature of contextProperty

* Add ts/typings for add-on definition files

* Add Anki types in typings/common/index.d.ts

* Export without .svelte suffix

It conflicts with how Svelte types its packages

* Fix left over .svelte import from editor.py

* Rename NoteTypeButtons to unrelated to ensure case-only rename

* Rename back to NotetypeButtons.svelte

* Remove unused component-hook.ts, Fix typing in lifecycle-hooks

* Merge runtime-require and register-package into one file

+ Give some preliminary types to require

* Rename uiDidLoad to loaded

* Fix eslint / svelte-check

* Rename context imports to noteEditorContext

* Fix import name mismatch

- I wonder why these issues are not caught by svelte-check?

* Rename two missed usages of uiDidLoad

* Fix ButtonDropdown from having wrong border-radius

* Uniformly rename libraries to packages

- I don't have a strong opinion on whether to name them libraries or
  packages, I just think we should have a uniform name.
- JS/TS only uses the terms "module" and "namespace", however `package`
  is a reserved keyword for future use, whereas `library` is not.

* Refactor registration.ts into dynamic-slotting

- This is part of an effort to refactor the dynamic slotting (extending
  buttons) functionality out of components like ButtonGroup.

* Remove dynamically-slottable logic from ButtonToolbar

* Use DynamicallySlottable in editor-toolbar

* Fix no border radius on indentation button dropdown

* Fix AddonButtons

* Remove Item/ButtonGroupItem in deck-options, where it's not necessary

* Remove unnecessary uses of Item and ButtonGroupItem

* Fix remaining tests

* Fix relative imports

* Revert change return value of remapBinToSrcDir to ./bazel/out...

* Remove typings directory

* Adjust comments for dynamic-slottings
2022-02-03 14:52:11 +10:00
Hikaru Y
7501ff7ab5
Fix field content overflowing its container (#1618) 2022-01-25 10:35:13 +10:00
Henrik Giesel
f534dbb8e5
Separate input components into their own directories / Remove WithShortcut (#1613)
* Put PlainTextInput into its own directory

* Create a directory for RichTextInput

* Create editor-toolbar directory

* Move PreviewButton into editor-toolbar

* The time to refactor this is not quite yet here

* Create tag-editor directory

* Remove some of the uses of WithShortcut

* Remove all uses of WithShortcut from editor package

* Remove last uses of WithShortcut

* Fix typo
2022-01-24 11:43:09 +10:00
Damien Elmes
f842ab7c9d switch convenience symlinks to .bazel/
Unfortunately 5efaf5a4be broke the Svelte
language tools - presumably having paths outside of the repo is confusing
them.

As a plan B, the symlinks have been shifted to a single subdir. Along
with some exclusions in the VS Code config, this should allow VS Code
to continue to work out of the box, but the docs will need updating
to reflect the extra work required for PyCharm/IntelliJ.

+ fix svelte-check execution on a system without node installed. It
still throws up some errors that are presumably caused by our multiple
rootDirs - not sure if there's an easy way to work around that.
2022-01-24 11:06:02 +10:00
Damien Elmes
e986304592 replace some bazel-bin references in our scripts
+ fix scripts/mypy-watch, and make it only listen to change events
2022-01-23 20:17:08 +10:00
Henrik Giesel
a8d4774cdb
Add _raw methods for all methods in the backend (#1594)
* Add _bytes methods for all methods in the backend

Expose get_note in qt/aqt/mediasrv.py

* Satisfy formatter

* Rename _bytes function to _raw and have them bytes as input

* Fix backend generation

* Use lib/proto/deckOptions in deck-options

* Add exposed_backend to qt/aqt/mediasrv.py

* Move some more backend methods to exposed_backend_list

* Use protobufjs for congrats and i18n

* Use protobufjs for completeTag

* Use protobufjs services in change-notetype

* Reorder post handlers in alphabetical manner

* Satisfy tests

* Remove unused collection methods

* Rename access_backend to raw_backend_request

* Use _vendor.stringcase instead of creating a new function

* Remove SKIP_UNROLL_OUTPUT

* Directly call _run_command in non _raw methods

* Remove TranslateString, ChangeNotetype and CompleteTag from SKIP_UNROLL_INPUT

* Remove UpdateDeckConfigs from SKIP_UNROLL_INPUT

* Remove ChangeNotetype from SKIP_UNROLL_INPUT

* Remove SKIP_UNROLL_INPUT

* Fix typing issue with translate_string

- Adds typing support for Protobuf maps in genbackend.py

* Do not emit convenience method for protobuf TranslateString
2022-01-21 21:32:39 +10:00
Henrik Giesel
f90895995f
Fix the caret flushing behavior when moving out of a Mathjax element (#1605)
* Fix the caret flushing behavior when moving out of a Mathjax element

* Fix typing issue and add docs for ContentEditableAPI
2022-01-19 10:17:53 +10:00
Henrik Giesel
0bb04e2951
Fix bug when selecting text next to frame by clicking three times (#1604) 2022-01-19 10:15:53 +10:00
RumovZ
0e06a1c679
Webview margins (#1583)
* Improve side margins in card info screen

* Improve top margin in deck options screen

* Hide revlog time of day on narrow screens

* Remove monospace for now (dae)
2022-01-17 15:04:25 +10:00
Henrik Giesel
478b3a53f1
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
Damien Elmes
e3bfc86f50 update JS deps
- fixes warnings about security issues in marked/markdown-it
- jsdoc is mostly unmaintained at this point, and we need to override
its dependencies manually
- typescript is still pinned
2022-01-16 13:29:48 +10:00
Damien Elmes
ce049ec360 sass/codemirror does not appear to be used 2022-01-15 21:19:58 +10:00
Damien Elmes
15358ac4e8 copy_bootstrap_css/icons were unused 2022-01-15 20:35:11 +10:00
Henrik Giesel
3beea5e1e4
Split/Merge editor.py for its three use cases (#1581)
* Forbid inserting object and iframe tags via PlainTextInput

* Add optional browserMode parameter to Editor

* Create new ts modules for three editor instances

- note-creator for AddCards
- browser-editor for the editor in the Browser
- reviewer-editor for the EditCurrent

* Revert "Forbid inserting object and iframe tags via PlainTextInput"

This reverts commit ab90ae8194494d883a1863126496e2d8f332509e.

* Refactor browserMode to editorMode

* Move new editor variants inside /ts/editor directory

* Fix typo
2022-01-12 14:51:43 +10:00
Henrik Giesel
489eadb352
Fix IME input after tab (#1584)
* Avoid initial call of mirror-dom

* Disable updateFocus from OldEditorAdapter

* fixes IME input duplication bug

* Fix saving of latestLocation for ContentEditable

* Fix IME after calling placeCaretAfterContent

* Export other libraries from domlib/index.ts

* Remove dead code

+ Uncomment code which was mistakenly left commmented
2022-01-12 08:39:41 +10:00
Ryan
ead75f2898
Calendar graph uses consistent colors across years (#1585) 2022-01-11 16:26:26 +10:00
Henrik Giesel
4360fd16fb
Use default colors for CodeMirror in light theme Anki (#1578)
Refactor PlainTextInput

Put CodeMirror themes into variables
2022-01-10 12:51:50 +10:00
RumovZ
1cee864875
Fix padding and alignment inside revlog table (#1576)
* Use nested tables in revlog

This allows for centered rows, while still preserving internal
alignment.

* Fix hidden columns

* Replace inner tables with flexbox divs

* Replace revlog table with flexbox divs

* Replace flex-gap in revlog

Unsupported on iOS and Qt5.
2022-01-10 12:50:48 +10:00
Henrik Giesel
81cc5a0914
Small Tag editor fixes (#1580)
* Adjust height of TagInputs to not switch when changing mode

* Hide scrollbar on tag suggestions when not necessary
2022-01-08 11:48:17 +10:00
Henrik Giesel
7e5b6aba4a
Reset .style.width when resizing images (#1579) 2022-01-08 11:47:12 +10:00
Henrik Giesel
739e286b0b
Fix some Mathjax issues (#1547)
* Move move-nodes logic into domlib

Refactor input-manager

Refactor out FocusTrap from EditingArea

Remove unnecessary selecting of node from surround

Add onInput interface to input-manager

Create MathjaxElement.svelte

- This should contain all the setup necessary for displaying
  <anki-mathjax> elements in the rich text input
- Does not contain setup necessary for Mathjax Overlay

Deal with backwards deletion, when caret inside anki-mathjax

Set mathjax elements contenteditable=false

Do not undecorate mathjaxx element on disconnect

- Fixes issues, where Mathjax might undecorate when it is moved into a
  different div

Add framed element custom element

Introduce iterateActions to allow global hooks for RichTextInput

Remove some old code

Deal with deletion of frame handles

Make Anki frame and frame handles restore each other

Make FrameElement restore its structure upon modification

Frame and strip off framing from MathjaxElement automatically

Move FrameHandle to separate FrameStart/FrameEnd

Refactor FrameHandle

Set data-frames on FrameElement

Fix logic error connected to FrameElement

Communicate frameHandle move{in,out} to anki-mathjax

Clear selection when blurring ContentEditable

Make sure frame is destroyed when undecorating Mathjax

Use Hairline space instead of zeroWidth

- it has better behavior in the contenteditable when placing the caret
  via clicking

Allow detection of block elements with `block` attribute

- This way, anki-mathjax block="true" will make field a
field be recognized to have block content

Make block frame element operater without handles

- Clicking on the left/right side of a block mathjax will insert a br
  element to that side

When deleting, remove mathajax-element not just image

Update MathjaxButtons to correctly show block state

SelectAll when moving into inline anki mathjax

Remove CodeMirror autofocus functionality

Move it to Mathjaxeditor directly

Fix getRangeAt throwing error

Update older code to use cross-browser

Fix issue with FrameHandles not being properyly removed

Satisfy formatting

Use === instead of node.isSameNode()

Fix issue of focusTrap not initialized

* Fix after rebasing

* Fix focus not being moved to first field

* Add documentation for input-manager and iterate-actions

* Export logic of ContentEditable to content-editable

* Fix issue with inserting newline right next to inline Mathjax

* Fix reframing issue of Mathjax Svelte component

* Allow for deletion of Inline Mathjax again

* Rename iterate-actions to action-list

* Add copyright header

* Split off frame-handle from frame-element

* Add some comments for framing process

* Add mising return types
2022-01-08 11:46:01 +10:00
Damien Elmes
a6c65efd36 another attempt at enforcing script load order
See discussion on 36e20fd110 (commitcomment-62861929)
2022-01-07 14:23:55 +10:00
Damien Elmes
349d5d0862 Revert "Guarantee execution order of <script> elements (#1574)"
This reverts commit 36e20fd110.

Reverting until this can be investigated:

36e20fd110 (commitcomment-62861929)
2022-01-04 10:43:56 +10:00
Hikaru Y
36e20fd110
Guarantee execution order of <script> elements (#1574) 2022-01-04 08:58:09 +10:00
Vova Selin
2df3698e8c
Minor changes to graphs (#1566)
* Add thousands comma separator for card counts graph

* Fix Answer Buttons graph's tooltip

Changes to the "times pressed" heading

* Shows the percent of that button out of all the presses

* Comma separates total on thousands

* Update CONTRIBUTERS

* Wider spacing for graph tables

* Switch to locale-based stats numbers

* Update CONTRIBUTORS 

Wrong email?

* Fix counts graph on narrow devices

Graph and table now align in a column when the device's screen is narrow. Columns widths are  bounded to not get too wide

* Rename toLocaleXXX functions

* toLocaleNumber -> localizedNumber
 *  toLocaleString -> localizedDate

Also cleans up sketchy "card counts" table formatting

* Localize more numbers

Uses locale-based rounding for more numbers now

* Localize graph axis ticks

* Fix future-due graph tooltip

* avoid div by zero (dae)

Ignoring NaN in localizedNumber() could potentially mask a mistake
in the future - better to explicitly handle the invalid case at the
source instead.
2021-12-29 15:04:15 +10:00
Hikaru Y
df0ad4be4b
Prevent unwanted <div> from being left behind when clearing field (#1565)
* Prevent unwanted <div> from being left behind when clearing field

* Use event.currentTarget instead of 'this'

* Check if event.data is empty for better performance

* Change order of conditions for better performance
2021-12-24 09:12:04 +10:00
Hikaru Y
12ccdee25b
Fix some issues with closing previewer (#1563)
* Fix media playback not terminating when previewer is closed

https://forums.ankiweb.net/t/anki-2-1-50-beta/15608/78

* Fix _on_preview_closed being called twice unnecessarily

The function was being called twice when the preview button is clicked
while the previewer is open.

* Fix console error caused by leftover code

The following error was shown in the console when closing previewer:
`Uncaught TypeError: Cannot read property 'classList' of null`

* Toggle state of preview button via 'active' prop
2021-12-20 20:23:50 +10:00
Damien Elmes
e175c068af fix inverted SchedBuried and UserBuried in cards.ts
This wasn't causing any problems, as we only ever checked for both at
once.
2021-12-20 12:57:35 +10:00
Hikaru Y
e92d7f13e3
Preload external css files to prevent flash of unstyled content (#1558)
* Preload external css files to prevent flash of unstyled content

This is an implementation of the approach mentioned in the commit
message of 46b85d5.

* Tweak max_age value for css files

Ensure that css preloading works even on a slow PC.
2021-12-16 21:47:10 +10:00
RumovZ
80ed94ed08
Cap steps (#1548)
* Fix steps being mistaken for seconds

* Cap steps at `u32::max` seconds

* Fix overflow of steps in Rust

* Prevent overflow of `IntervalKind`

* Prevent overflow in `revlod/mod.rs`

Also replace some `as` with `from` and `try_from` as is recommended to
highlight potential issues.

* Ensure v2 doesn't store overflowing revlog ivls

* Lower steps cap in deck options

Whereas large card intervals are converted to days, revlog intervals use
i32s to store large numbers of seconds.

* Format
2021-12-15 18:46:26 +10:00
Damien Elmes
8d90b6b061 run buildifier/buildozer to tidy up BUILD files 2021-12-14 09:18:24 +10:00
Matthias Metelka
cc5ba4ed84
Reimplement "Show Duplicates" button in editor (#1550)
* Add "Show duplicates" to LabelContainer

* Avoid bubbling down the duplicate logic into EditorField

* Move duplicate link into its own slot

to center it between name/description and field-state.

* Revert "Move duplicate link into its own slot"

This reverts commit 3a4511042da7083a52d67b58550b13d873dcbea5.

* Justify dupes within FieldState

to achieve the same result as before while avoiding additional logic within EditorField.

Co-Authored-By: Henrik Giesel <hengiesel@gmail.com>
2021-12-13 14:06:12 +10:00
Henrik Giesel
4966f3cc44
Add back wrap function (#1551)
* Remove surround from RichText and PlainText

* Export wrap
2021-12-13 14:00:35 +10:00
RumovZ
e336f5a239
Add shortcuts for list and indentation (#1546) 2021-12-10 17:54:31 +10:00
Matthias Metelka
1fc060620c
Decrease button and tag size for Linux and Windows (#1532)
* Decrease button size for platforms other than Mac

* Refactor legacy button styles

* Restrict size of add-on icons
2021-12-06 19:01:15 +10:00
Henrik Giesel
fa6a531bd5
Block {,max-}{width,height} from being copied (#1529) 2021-12-06 18:41:08 +10:00
Abdo
b3ea7288ab
Flip arrows of Bootstrap-styled <select>s for RTL langs (#1526)
* Flip arrows of Bootstrap-styled <select>s for RTL langs

* Use the dir attribute to set document direction

* Remove unused variable and fix use of CSS var
2021-12-06 18:40:26 +10:00
Hikaru Y
e8b795ba69
Fix custom CSS not being applied to scrollbars in night mode (#1525) 2021-12-05 08:20:42 +10:00
Matthias Metelka
eefa46dc8e
Rename StickyNav to StickyHeader (#1524)
so as to not create false assumptions about its functionality.
2021-12-05 08:18:58 +10:00
Matthias Metelka
933ee647bc
Align design of Change Notetype screen with rest of UI (#1522)
* Remove background and border from scrollArea

* Fix 1px of background text showing above template header on scroll

I couldn't figure out the reason for this "clipping" issue. What I tried:
- check HTML structure for any elements that might add extra padding/margin
- remove the 1px border of the header

* Adjust spacing to be more in line with rest of UI
2021-12-04 14:53:16 +10:00
Matthias Metelka
936323e430
Show downwards arrow on SelectButton (#1521)
* Show downwards arrow on SelectButton

The arrow wasn't showing because the button linear-gradient background overrides the background-image for the arrow.

Select can't have pseudo-elements, so I had to add an extra div.

* Remove height definition

to fix text cutting off on Windows.

* Hide default arrow in light theme

to keep consistency with dark theme, where the arrow has to be custom due to the button gradient.

* Use alternative approach to prevent text getting cropped

and add height definition back again.

Co-Authored-By: Hikaru Y. <47855854+hikaru-y@users.noreply.github.com>

* Adjust arrow position for rtl

Co-authored-by: Hikaru Y. <47855854+hikaru-y@users.noreply.github.com>
2021-12-04 08:08:20 +10:00
Henrik Giesel
d0c6f0d7ba
Fix focus lost after adding note if non-sticky (#1523) 2021-12-03 21:41:12 +10:00
Damien Elmes
661f769700 update Node deps
TypeScript is currently pinned. Before updating to 4.5, we will likely
need to use --preserveValueImports in svelte.ts:
https://devblogs.microsoft.com/typescript/announcing-typescript-4-5/#preserve-value-imports

There's also an issue with missing types when importing from bootstrap
.js files that will need investigating.
2021-12-03 20:35:53 +10:00
Damien Elmes
47b701688f fix update-licenses.sh 2021-12-03 20:35:53 +10:00
Damien Elmes
7fcb8cbb62 fix position showing as date in card stats
Fixes #1519
2021-12-02 16:10:29 +10:00
Matthias Metelka
8edca4e6c1
Add missing editorToolbar export (#1511) 2021-11-29 12:40:31 +10:00
RumovZ
f2173fddb0
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
63404de5df prettier: don't depend on system node being available 2021-11-25 07:14:15 +10:00
Matthias Metelka
68092082f2
Change Notetype UI Rework (#1499)
* Enable access to old notetype name

* Set minimum height for ChangeNotetypeDialog

* Add bootstrap icons to change-notetype

* Move alert up and make it collapsible

* Tweak some CSS

- Add variables --sticky-bg and --sticky-border to StickyContainer
- Tweak base.css

* Add translatable string "(Nothing)"

* Rework ChangeNotetype screen

* Initially load option at newIndex and remaining options on focus

Optimization for big notetypes:
Should increase efficiency from O(n²) to O(n). Test on notetype with 500 templates shows significant improvement in load time (~10s down to ~1s).

* Try to satisfy rust test

* Change arrow direction depending on reading direction

+ add 0.5em top padding to main

* Create Alert.svelte

* Introduce CSS variable --pane-bg

* Revert "Initially load option at newIndex and remaining options on focus"

This reverts commit f42beee45c27dba9433d76217fb583b117fb5231.

* Final cleanup

* Refine padding/gutter
2021-11-24 12:09:55 +10:00
Henrik Giesel
97b28398ea
Fix some issues with new surround buttons (#1505)
* Add a store to indicate whether input trigger is active

Button state is then indicated by: caretIsInBold XOR boldTriggerActive

* Fix surrounding where normalization is tripped up by empty text nodes

* Add failing test for unsurrounding

* Fix failing test

* prohibitOverlapse does not need to be active, if aboveEnd is null

* Reinsert Italic and Underline button

* Refactor find-adjacent to use sum types

* Simplify return value of normalizeAdjacent
2021-11-24 10:33:14 +10:00
Henrik Giesel
4886f5772d
Fix Cloze button (#1504) 2021-11-24 10:25:24 +10:00
Henrik Giesel
2778b9220c
Mathjax editor improvements (#1502)
* Remove unnecessary stopPropagation of mathjax-overlay events

* Use CodeMirror component for MathjaxHandle

* Refactor ResizeObserver code in MathjaxHandle

* Wrap setRange in CodeMirror in try/catch

* Add Mathjax Editor bottom margin

* Add custom Enter and Shift+Enter shortcuts for the MathjaxHandle

* Format

* Move placeCaretAfter to domlib

* Move focus back to field after editing Mathjax

* Put Cursor after Mathjax after accepting

* Add delete button for Mathjax

* Change border color of mathjax menu

* Refactor into MathjaxMenu

* Put caretKeyword in variable

* Use one ResizeObserver for all Mathjax images

* Add minmimum width for Mathjax editor

* is still smaller than minimal window width

* Add bazel directories to .prettierignore and format from root

* exclude ftl/usage (dae)

the json files that live there are output from our tooling, and
formatting them means an extra step each time we want to update them

also exclude .mypy_cache, which is output by scripts/mypy*

* minor ftl tweak: newline -> new line  (dae)
2021-11-23 10:27:32 +10:00
Henrik Giesel
1a874b184d
Fix missing left margin in CongratsPage (#1498) 2021-11-19 11:02:54 +10:00
Henrik Giesel
64d46ca638
Reverse-engineer surrounding with execCommand (#1377)
* Add utility functions for saving and restoring the caret location

Implement surroundNoSplitting

Clarify surroundNoSplitting comments

Start implementing surroundSplitting and triggerIfSimpleInput

Fix after rebase

Implement findBefore / findAfter in lib/surround

* to merge adjacent nodes into the surrounding nodes

Use new prettier settings with lib/{location,surround}

Fix imports that I missed to rename

Add some tests for find-adjacent

Split find-within from find-adjacent

Normalize nodes after insertion in surroundNoSplitting

Do not deep clone surroundNode

-> no intention of supporting deep nodes, as normalization would be impossible

Add some tests concerning nested surrounding nested nodes

Select surroundedRange after surrounding

Fix ascendWhileSingleInline

A flawed first surround/trigger implementation

Move trigger out of lib/surround

Implement Input Manager as a way to handle bold on empty selection

Switch bold button away from execCommand

Pass in Matcher instead of selector to find-adjacent and surroundNoSplitting

* Also adds a failing test for no-splitting

Refactor find-adjacent

* add failing test when findBefore's nodes have different amounts of
  child nodes

Change type signature of find-adjacent methods to more single-concern

Add test for surrounding where adjacent block becomes three Text elements

Make nodes found within surrounded range extend the ranges endOffset

Add base parameter to surroundNoSplitting to stop ascending beyond container

Stop surrounding from bubbling beyond base in merge-match

Make all tests pass

Add some failing tests to point to future development

Add empty elements as constant

Implement a broken version of unsurround

Even split text if it creates zero-length texts

-> they are still valid, despite what Chromium says

Rename {start,end} to {start,end}Container

Add more unit tests with surround after a nested element

Set endOffset after split-off possibly zero length text nodes

Deal with empty elements when surrounding

Only include split off end text if zero length

Use range anchors instead off calcluating surroundedRange from offsets

* this approach allows for removal of base elements when unsurrounding

Comment out test which fail because of jsdom bugs

We'll be able to enable them again after Jest 28

Make the first unsurround tests pass

Add new failing test for unsurround text within tag

Fix unsurround

Test is deactivated until Jest 28

Rewrite input-manager and trigger callback after insertion

Avoid creating zero length text nodes by using insertBefore when appropriate

Implement matches vs keepMatches

Make shadow root and editable element available on component tree

Make WithState work with asynchronous updater functions

Add new Bold/Italic/UnderlineButton using our logic

Add failing test for unsurrounding

* Move surround/ to domlib

* Add jest dependency

* Make find-within return a sum type array rather than two arrays

* Use FoundMatch sum-type for find-above (and find-within)

* Fix issue where elements could be cleared twice

* if they are IN the range.endContainer

* Pass remaining test

* Add another failing test

* Fix empty text nodes being considered for surrounding

* Satisfy svelte check

* Make on more type correct

* Satisfy remaining tests

* Add missing copyright header
2021-11-18 19:18:39 +10:00
Henrik Giesel
ab6a68ec49
Introduce our own Container, Row, and Col components (#1495)
* Refactor out Placeholder from CardInfo.svelte

* Add breakpoint parameter for Container

- Use `Container` component inside `TitledContainer`

* Build Item into Row

- Use Row in DeckOptionsPage instead of just Item

* Reengineer Container/Row/Col CSS

* Inline Badges next to Labels when Lable spans multiple rows

* Adjust margins for mobile

* Implement Col component breakpoints

* Move card-info to use new Container and Row components

* Join StickyHeader and StickyFooter to StickyContainer

* Remove default middle vertical-alignment for Badges again

* Satisfy tests

* Restore inline gutters in change-notetype Mapper

* Add some comment to Col and Container

* Fix breaking behavior in DeckOptionsPage when multi-column

* Add back toolbar left padding to counter-act buttongroup right margins

* Make Label in SwitchRow take more of available space
2021-11-17 13:49:52 +10:00
Abdo
98b527eb99
Load missing i18n modules (#1494) 2021-11-17 07:28:48 +10:00
RumovZ
0efa3f944f
Garbage collect unused Fluent strings (#1482)
* Canonify import of i18n module

Should always be imported as `tr`, or `tr2` if there is a name collision
(Svelte).

* Add helper for garbage collecting ftl strings

Also add a serializer for ftl asts.

* Add helper for filter-mapping `DirEntry`s

* Fix `i18n_helpers/BUILD.bazel`

* run cargo-raze

* Refactor `garbage_collection.rs`

- Improve helper for file iterating
- Remove unused terms as well
- Fix issue with checking for nested messages by switching to a regex-
based approach (which runs before deleting)
- Some more refactorings and lint fixes

* Fix lints in `serialize.rs`

* Write json pretty and sorted

* Update `serialize.rs` and fix header

* Fix doc and remove `dbg!`

* Add binaries for ftl garbage collection

Also relax type constraints and strip debug tests.

* add rust_binary targets for i18n helpers (dae)

* add scripts to update desktop usage/garbage collect (dae)

Since we've already diverged from 2.1.49, we won't gain anything
from generating a stable json just yet. But once 2.1.50 is released,
we should run 'ftl/update-desktop-usage.sh stable'.

* add keys from AnkiMobile (dae)

* Mention caveats in `remove-unused.sh`
2021-11-12 18:19:01 +10:00
Damien Elmes
d668ac8f7f fix card info layout & test code
Closes #1479

Related: #1470
2021-11-12 16:24:08 +10:00
Damien Elmes
3fc81e5f15 another external workspace fix for sass 2021-11-12 15:02:17 +10:00
Henrik Giesel
610ef8f043
Save and restore location on ContentEditable (#1481)
* Add utility functions for saving and restoring the caret location

* Implement cross-browser.getSelection

* Save and restore location on ContentEditable

* Fix refocus by clicking on a field that had a non-collapsed selection
2021-11-09 12:53:39 +10:00
Matthias Metelka
371f731e30
Editor Field Descriptions (#1476)
* Add description input to fields dialog

QLineEdit seems like the best option, as it saves space and motivates users to keep their descriptions concise.

* Add setDescriptions to note initialization script

Went for the extra function instead of including it in setFields to prevent potential add-on breakages.

* Add tooltip next to field name if description is set

* Refactor code according to suggestions

Set default tooltip placement to right instead of bottom

Use .get() for fld["description"]

Fix tab order in fields dialog

Swap out abbreviation "desc" for full length name to keep consistency

* Update Protobuf and Rust for description

Add description to notetypes.proto and schema11

Co-authored-by: RumovZ <RumovZ@users.noreply.github.com>

* Fix tooltips not updating with description

Remove redundant variable tooltipOptions

Update previousTooltip within reactive function

* Move LabelDescription out of LabelName

Co-authored-by: Henrik Giesel <hgiesel@users.noreply.github.com>

* Decrease icon size and fix alignment

Co-Authored-By: Henrik Giesel <hengiesel@gmail.com>

* the new key needs to be cleared from fields, not the notetype itself

Co-authored-by: RumovZ <RumovZ@users.noreply.github.com>
Co-authored-by: Henrik Giesel <hengiesel@gmail.com>
Co-authored-by: Damien Elmes <gpg@ankiweb.net>
2021-11-06 09:42:48 +10:00
Henrik Giesel
c9bd39c6a2
Several editor fixes (#1478)
* Declare toolbar api via modifiable property

* Fix addon buttons

* Assign editing areas in a synchronous way

* Restore the Tab shortcut that moves the caret to end

- moveCaretToEnd is called twice now: The moveCaretToEnd calls in
  *TextInput causes the caret to be moved to the end when switching back
  from the window and back.
- To fix this, I will need the code for saving and restoring locations
  from #1377

* Restore selections in the PlainTextInput

* Improve type safety of destroyable

- clearable-array was renamed to destroyable
2021-11-05 11:29:02 +10:00
Damien Elmes
84021976d5 speed up Svelte compile
Approx 27s -> 16s when rebuilding editor after making a change to
lib. Still slower than I'd like.
2021-11-04 15:18:28 +10:00
Damien Elmes
8d5cddb05c add a missing references line in ts/graphs 2021-11-04 14:56:50 +10:00
Henrik Giesel
c87ba7d426
Set "no-non-null-assertion: off" by default (#1475) 2021-11-04 11:42:51 +10:00
Damien Elmes
fd013f68d2 ensure revlog headers match alignment of columns
+ right-align interval; it looks bad centered
2021-11-02 16:32:09 +10:00
Damien Elmes
5e15ab0ebb use absolute package paths in eslint.bzl 2021-11-02 13:49:19 +10:00
Damien Elmes
c988116da5 add lint checks for unsupported browser API calls 2021-11-02 13:44:41 +10:00
Damien Elmes
52ea7c2a05 avoid Object.fromEntries() and some instances of globalThis
Not supported on early iOS 12. This can be reverted after iOS 12
support is dropped, which should be soon.
2021-11-02 12:54:06 +10:00
Damien Elmes
0cd4c9431a include subfolders in eslint/prettier checks 2021-11-02 12:50:27 +10:00
Damien Elmes
2c248e6a3d revert congrats h3 style change from #1470
Presumably bootstrap is overriding the styling of headers; this is a
quick fix to make the header be bold again, like the graphs screen.
2021-11-01 12:55:31 +10:00
Damien Elmes
9151fd93d4 allow passing npm repo name in compile_svelte() 2021-10-31 18:10:11 +10:00
Damien Elmes
69c04baf5a use absolute path for sql_format 2021-10-31 11:13:38 +10:00
Henrik Giesel
09c29219b4
Several CSS fixes - Editor Cleanup (#1470)
* Refactor editor css, fix editor button highlight

- Avoid using webview.css
- Move more buttons css into button_mixins

* Fix DropdownItem appearance

* Fix the visuals of tags

* Make dropdown font slightly smaller

* Give SelectOption a background color

* Move some css from deck-options-base to CardStateCustomizer

* Avoid using core.scss for CardStats

* Avoid using sass/core in congrats package

* Inline core.scss into webview.scss

* Include fusion-vars for base.scss

* need to keep core.scss around for now (dae)
2021-10-31 08:29:22 +10:00
Matthias Metelka
9f8be1af93
Highlight field badges when toggled to non-default state (#1466) 2021-10-31 07:48:37 +10:00
Henrik Giesel
afc56a8398
Fix DeckOptions toolbar having wrong margins and no flex-grow (#1464)
ButtonToolbar.svelte now has to assume that the button elements
are two levels below it. This can be simplified once we can use
flex-gap.
2021-10-28 19:37:52 +10:00
Abdo
20d9a26a8c
Strip isolation chars from deck options warnings to fix RTL display (#1457)
Co-authored-by: Damien Elmes <dae@users.noreply.github.com>
2021-10-26 20:11:25 +10:00
Damien Elmes
6af8a47d57 fix deprecation warning in latest svelte-preprocess 2021-10-26 08:43:02 +10:00
Damien Elmes
3f24f9820d update js deps 2021-10-26 08:30:13 +10:00
Damien Elmes
a80a267cff //ts:format now runs on current working directory, instead of entire repo 2021-10-23 15:48:33 +10:00
Damien Elmes
3b8b71b815 minor tweak to new-platforms.md, and run prettier on docs 2021-10-23 15:40:45 +10:00
Henrik Giesel
02409d083b
Fix RTL text display being off + Update PlainTextInput RTL on save (#1448) 2021-10-23 11:06:15 +10:00
RumovZ
1c9b5a2e83
Card info cleanup (#1446)
* Cast proto interface to type ...

... instead of using non-null assertions in Revlog.svelte.

* Remove OptionalInt32 and OptionalUInt32
2021-10-23 11:00:43 +10:00
Damien Elmes
048a9a2b60 vendor stringcase
It's a tiny library that has not been updated in years, and it was
leading to a warning on startup:

 DeprecationWarning: invalid escape sequence \W
  return re.sub("\W+", "", string)
2021-10-22 08:56:44 +10:00
Henrik Giesel
4678b12570
Fix Preview button not showing and cloze button not hiding (#1437) 2021-10-20 07:09:12 +10:00
Henrik Giesel
0dff5ea3a3
Use trailingComma: all setting in .prettierrc (#1435) 2021-10-19 09:06:00 +10:00
Henrik Giesel
bf3adbc812
Svelte Editor hotfixes (#1436)
* Fix white on white text in light mode

* Reflect rename to FieldsEditor in class name

* Fix adjusting fields ending in an endless loop
2021-10-19 08:38:06 +10:00
Henrik Giesel
c2768e2188
Translate Editor entirely to Svelte (#1403)
* Translate editor to Svelte

Make editor fields grid rather than flexbox

Refactor ButtonToolbar margins

Remove remaining svelte.d.ts symlinks

Implement saveNow

Fix text surrounding

Remove HTML editor button

Clean up some empty files

Add visual for new field state badges

* Adds new IconConstrain.svelte to generalize the icon handling for
IconButton and Badge

Implement sticky functionality again

Enable Editable and Codable field state badges

Add shortcuts to FieldState badges

Add Shift+F9 shortcut back

Add inline padding back to editor fields, tag editor and toolbar

Make Editable and Codable only "visually hidden"

This way they are still updated in the background
Otherwise reshowing them will always start them up empty

Make empty editing area focusable

Start with moving fieldsKey and currentFieldKey to context.ts

Fix Codable being wrong size when opening for first time

Add back drag'n'drop

Make ButtonItem display: contents again

* This will break the gap between ButtonGroup items, however once we
  have a newer Chromium version we should use CSS gap property anyway

Fix most of typing issues

Use --label-color background color LabelContainer

Add back red color for dupes

Generalize the editor toolbar in the multiroot editor to widgets

Implement Notification.svelte for showing cloze hints

Add colorful icon to notification

Hook up Editable to EditingArea

Move EditingArea into EditorField

Include editorField in editor/context

Fix rebasing issues

Uniformly use SvelteComponentTyped

Take LabelContainer out of EditingArea

Use mirror-dom and node-store to export editable content

Fix editable update mechanism

Prepare passing the editing inputs as slots

Pass in editing inputs as slots

Use codable options again in codemirror

Delete editor/lib.ts

Remove CodableAdapter, Use more generic CodeMirror component

Fix clicking LabelContainer to focus

Use prettier

Rename Editable to ContentEditable

Fix writing Mathjax from Codable to Editable

Correctly adjust output HTML from editable

Refactor EditableStyles out of EditableContainer

Pass Image and Mathjax Handle via slots to Editable

Make Editable add its editingInputApi

Make Editable hideable

Fix font size not being set correctly

Refactor both fieldFocused and focusInCodable to focusInEditable

Fix focusIfField

Bring back $activeInput

Fix ClozeButton

Remove signifyCustomInput

Refactor MathjaxHandle

Refactor out some logic into store-subscribe

Fix Mathjax editor

Use focusTrap instead of focusing div

Delegate focus back to editingInput when refocusing focusTrap

Elegantly move focus between editing inputs when closing/opening

Make Codable tabbable

Automatically move caret to end on editable and codable

+ remove from editingInput api

Fix ButtonDropdown having two rows and missing button margins

Make svelte_check and eslint pass

Satisfy editor svelte_check

Save field updates to db again

Await editable styles before mounting content editable

Remove unused import from OldEditorAdapter

Add copyright header to OldEditorAdapter

Update button active state from contenteditable

* Use activateStickyShortcuts after waiting for noteEditorPromise

* Set fields via stores, make tags correctly set

* Add explaining comment to setFields

* Fix ClozeButton

* Send focus and blur events again

* Fix Codable not correctly updating on blur with invalid HTML

* Remove old code for special Enter behavior in tags

* Do not use logical properties for ButtonToolbar margins

* Remove getCurrentField

Instead use noteEditor->currentField or noteEditor->activeInput

* Remove Extensible type

* Use context-property for NoteEditor, EditorField and EditingArea

* Rename parameter in mirror-dom.allowResubscription

* Fix cutOrCopy

* Refactor context.ts into the individual components

* Move focusing of editingArea up to editorField

* Rename promiseResolve -> promiseWithResolver

* Rename Editable->RichTextInput and Codable->PlainTextInput

* Remove now unnecessary type assertion for `getNoteEditor` and `getEditingArea`

* Refocus field after adding, so subscription to editing area is refreshed
2021-10-18 22:01:15 +10:00
Damien Elmes
cbc358ff0b add aliases to run vendored python and node from command line
You can then do './scripts/python -m venv /path/to/venv' to create
a virtual env based on the bundled Python, which can be handy if
you don't happen to have the appropriate version of Python installed
separately.
2021-10-18 19:50:41 +10:00
Damien Elmes
3d416b4a68 convert sql_format to ts_project; move into separate folder 2021-10-18 19:39:45 +10:00
RumovZ
9b1d53e359 Use null for missing stats 2021-10-18 09:36:31 +02:00
RumovZ
0b3b3a5f33 sentCardId -> requestedCardId 2021-10-18 09:12:10 +02:00
RumovZ
8eed005db6 Use null for unset cardId 2021-10-18 09:11:00 +02:00
RumovZ
dc4f5adc44 Default to includeRevlog = true 2021-10-18 09:04:49 +02:00
RumovZ
2a93868922 Center placeholder 2021-10-18 09:01:25 +02:00
RumovZ
bbba21126f Improve clarity in card info code a tiny little bit 2021-10-18 09:01:25 +02:00
RumovZ
3c5e149176 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
5062024974 Move update logic into CardInfo.svelte 2021-10-18 09:01:24 +02:00
RumovZ
4b5ea6c110 Make CardStats a separate component 2021-10-18 09:01:23 +02:00
RumovZ
a47453d5f3 Implement reactively updating Card Info 2021-10-18 09:01:22 +02:00
Damien Elmes
fed5c3da0e drop ts_library() requirement in ts/svelte 2021-10-18 13:00:55 +10:00
Damien Elmes
bb5053990b 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
1f876cfe39 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
e8c5802a96 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
abad6c3844 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
53ce7d2759 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
3672b0fe73
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
7128de895f 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
c64bac57a6
Put sass into repo directory (#1409)
Fix Sass build
2021-10-09 10:25:03 +10:00
Henrik Giesel
c63e0abd68
Fix prettier after moving node_modules to repo dir (#1413) 2021-10-09 10:13:14 +10:00
Henrik Giesel
dec0fbe845
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 e1d4292ce3979e7b7ee21bf3951b8a462d45c29c.

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 0a96776a475e9901c1f9f3407c726d1d002fb9ef.

* move withCollapsedWhitespace back to i18n/utils

* Add back /ts as in rootDirs
2021-10-07 23:31:49 +10:00
Damien Elmes
79ceb89637 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
1aaf8fce1e fix invalid arg to ButtonGroup revealed by typing fix 2021-10-07 21:33:15 +10:00
Damien Elmes
46b80ca773 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
046c6c55d3 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
e9d71bfbe4 yarn upgrade --latest
bootstrap still held back
2021-10-01 12:52:53 +10:00
Damien Elmes
a3d9f90af5 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
e46ca4ee54 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
604247482d handle changed aria-expanded typing 2021-09-29 12:20:27 +10:00
Damien Elmes
d44b49294b 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
04ba24cb54 silence execCommand deprecation warnings for now 2021-09-29 11:36:37 +10:00
Damien Elmes
e660e0a3e5 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
dc20300794 update to TypeScript 4.4.x 2021-09-23 09:53:37 +10:00
Damien Elmes
82f1cda09a fixes for TypeScript 4.4.x
closes #1386
2021-09-23 09:52:21 +10:00
Damien Elmes
94c4f99343 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
3f1da03615 Allow for explicit any 2021-09-17 21:30:32 +02:00
Henrik Giesel
51c0cedaf5 Make HandleSelection perfectly size when first activating 2021-09-17 21:23:04 +02:00
Henrik Giesel
06d1ec6af4 Fix missizing of HandleSelection when first moving from empty to Mathjax 2021-09-17 20:54:37 +02:00
Henrik Giesel
88fd31a099 Ugly fix: do not execute moveCursorPastPostfix when front includes "anki-mathjax" 2021-09-17 20:12:11 +02:00
Henrik Giesel
c30ba6a3f6 Add ChangeTimer.prototype.fireImmediately
so Mathjax is saved when exiting editor prematurely
2021-09-16 14:47:05 +02:00
Henrik Giesel
a1dde7c966 Wrap Mathjax compilation into try/catch 2021-09-16 14:31:20 +02:00
Henrik Giesel
60690e0557 Rename StickyBar and StickyBottom to StickyHeader and StickyFooter 2021-09-15 23:15:55 +02:00
Henrik Giesel
896b40c873 Remove now unused import in TagEditor 2021-09-15 22:59:47 +02:00
Henrik Giesel
9f56d51811 Fix suggestions not showing when typing space in a TagInput 2021-09-15 22:54:53 +02:00
Henrik Giesel
b502ceedca Make the ImageHandle and MathjaxHandle dropdowns perfectly touch the HandleSelection 2021-09-15 22:26:32 +02:00
Henrik Giesel
1f09402066 Stop propagation for paste in MathjaxHandle editor 2021-09-15 22:14:38 +02:00
Henrik Giesel
97647e7b24 Prevent hiding handles by clicking on handles 2021-09-15 17:56:56 +02:00
Henrik Giesel
9001b597da Remove style attribute after remove float property if not styling left 2021-09-15 17:36:48 +02:00