anki/ts/editor/HandleLabel.svelte

40 lines
923 B
Svelte
Raw Normal View History

2021-08-05 03:24:04 +02:00
<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="ts">
Move away from Bazel (#2202) (for upgrading users, please see the notes at the bottom) Bazel brought a lot of nice things to the table, such as rebuilds based on content changes instead of modification times, caching of build products, detection of incorrect build rules via a sandbox, and so on. Rewriting the build in Bazel was also an opportunity to improve on the Makefile-based build we had prior, which was pretty poor: most dependencies were external or not pinned, and the build graph was poorly defined and mostly serialized. It was not uncommon for fresh checkouts to fail due to floating dependencies, or for things to break when trying to switch to an older commit. For day-to-day development, I think Bazel served us reasonably well - we could generally switch between branches while being confident that builds would be correct and reasonably fast, and not require full rebuilds (except on Windows, where the lack of a sandbox and the TS rules would cause build breakages when TS files were renamed/removed). Bazel achieves that reliability by defining rules for each programming language that define how source files should be turned into outputs. For the rules to work with Bazel's sandboxing approach, they often have to reimplement or partially bypass the standard tools that each programming language provides. The Rust rules call Rust's compiler directly for example, instead of using Cargo, and the Python rules extract each PyPi package into a separate folder that gets added to sys.path. These separate language rules allow proper declaration of inputs and outputs, and offer some advantages such as caching of build products and fine-grained dependency installation. But they also bring some downsides: - The rules don't always support use-cases/platforms that the standard language tools do, meaning they need to be patched to be used. I've had to contribute a number of patches to the Rust, Python and JS rules to unblock various issues. - The dependencies we use with each language sometimes make assumptions that do not hold in Bazel, meaning they either need to be pinned or patched, or the language rules need to be adjusted to accommodate them. I was hopeful that after the initial setup work, things would be relatively smooth-sailing. Unfortunately, that has not proved to be the case. Things frequently broke when dependencies or the language rules were updated, and I began to get frustrated at the amount of Anki development time I was instead spending on build system upkeep. It's now about 2 years since switching to Bazel, and I think it's time to cut losses, and switch to something else that's a better fit. The new build system is based on a small build tool called Ninja, and some custom Rust code in build/. This means that to build Anki, Bazel is no longer required, but Ninja and Rust need to be installed on your system. Python and Node toolchains are automatically downloaded like in Bazel. This new build system should result in faster builds in some cases: - Because we're using cargo to build now, Rust builds are able to take advantage of pipelining and incremental debug builds, which we didn't have with Bazel. It's also easier to override the default linker on Linux/macOS, which can further improve speeds. - External Rust crates are now built with opt=1, which improves performance of debug builds. - Esbuild is now used to transpile TypeScript, instead of invoking the TypeScript compiler. This results in faster builds, by deferring typechecking to test/check time, and by allowing more work to happen in parallel. As an example of the differences, when testing with the mold linker on Linux, adding a new message to tags.proto (which triggers a recompile of the bulk of the Rust and TypeScript code) results in a compile that goes from about 22s on Bazel to about 7s in the new system. With the standard linker, it's about 9s. Some other changes of note: - Our Rust workspace now uses cargo-hakari to ensure all packages agree on available features, preventing unnecessary rebuilds. - pylib/anki is now a PEP420 implicit namespace, avoiding the need to merge source files and generated files into a single folder for running. By telling VSCode about the extra search path, code completion now works with generated files without needing to symlink them into the source folder. - qt/aqt can't use PEP420 as it's difficult to get rid of aqt/__init__.py. Instead, the generated files are now placed in a separate _aqt package that's added to the path. - ts/lib is now exposed as @tslib, so the source code and generated code can be provided under the same namespace without a merging step. - MyPy and PyLint are now invoked once for the entire codebase. - dprint will be used to format TypeScript/json files in the future instead of the slower prettier (currently turned off to avoid causing conflicts). It can automatically defer to prettier when formatting Svelte files. - svelte-check is now used for typechecking our Svelte code, which revealed a few typing issues that went undetected with the old system. - The Jest unit tests now work on Windows as well. If you're upgrading from Bazel, updated usage instructions are in docs/development.md and docs/build.md. A summary of the changes: - please remove node_modules and .bazel - install rustup (https://rustup.rs/) - install rsync if not already installed (on windows, use pacman - see docs/windows.md) - install Ninja (unzip from https://github.com/ninja-build/ninja/releases/tag/v1.11.1 and place on your path, or from your distro/homebrew if it's 1.10+) - update .vscode/settings.json from .vscode.dist
2022-11-27 06:24:20 +01:00
import { directionKey } from "@tslib/context-keys";
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 14:01:15 +02:00
import { getContext } from "svelte";
import type { Readable } from "svelte/store";
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 14:01:15 +02:00
const direction = getContext<Readable<"ltr" | "rtl">>(directionKey);
2021-08-05 03:24:04 +02:00
</script>
Use WithFloating for MathjaxOverlay (#2011) * Allow passing in reference into WithFloating as prop * Fix WithAutocomplete * Fix WithFloating for MathjaxOverlay * Add resize-store * Allow passing debug=True to jest_test for debugger support (#2013) * Disable auto-closing of HTML tags https://forums.ankiweb.net/t/set-html-editor-as-a-default-editor-instead-of-visual-editor/20988/3 Closes #1963 * Add slight margin to MathjaxEditor * Enable passing offset and shift to WithFloating * Hide overflow of mathjax editor * Add automatic hide functionality to sveltelib/position * Last polishes for Surrounder class (#2017) * Make private properties in Surrounder truly private * Fix remove logic of Surrounder * No reason for toggleTriggerRemove to be async * Allow using alt-shift to set all remove formats but this one * modifyFormat => updateFormat * Fix formatting * Fix field descriptions blocking cursor from being set (#2018) - happens when focus is in HTML editor * Remove hiding functionality again until it's really useful * Add support for autoPlacement * Implement new WithFloating that supports manually calling position() * Implement hide mechanisms * Add option in math dropdown to toggle MathJax rendering (#2014) * Add option in math dropdown to toggle MathJax rendering Closes #1942 * Hackily redraw the page when toggling MathJax * Add Fluent string * Default input setting in fields dialog (#1987) (kleinerpirat) * Introduce field setting to use plain text editor by default (kleinerpirat) * Remove leftover function from #1476 * Use boolean instead of string * Simplify clear_other_field_duplicates * Convert plain text key to camelCase * Move HTML item below the existing checkbox, instead of to the right (dae) Showing it on the right is more space efficient, but feels a bit cluttered IMHO. * Fix not being able to scroll when mouse hovers PlainTextInput (#2019) * Remove overscroll-behavior: none for * (all elements) * Revert "Remove overscroll-behavior: none for * (all elements)" This reverts commit 189358908cecd03027e19d8fe47822735319ec17. * Use body instead of *, but keep CSS rule * Unify two CSS rules * Remove console.logs * Reposition mathjax menu on switching between inline/block * Implement WithOverlay * Implement FloatingArrow * Display overlay with padding and brighter background * Rename to MathjaxOverlay * Simplify MathjaxOverlay component overall * Rename ImageHandle to image overlay * Generally fix ImageOverlay again * Increase z-index of StickyContainer * Fix setting block or inline on mathjax * Add reasons in closing-{click,keyup} * Have both WithFloating and WithOverlay use a simple show flag instead of a store * Remove subscribe-trigger * Fix clicking from one mathjax element to another * Check before executing cleanup * Do not wait for elements to mount before slotting in With{Floating,Overlay} * Allow using reference slot for WithFloating and WithOveray * Add inline argument to options * Add support for inline slot in WithOvelay * Use WithFloating for RemoveFormatButton * Remove last uses of DropdownMenu and WithDropdown * Remove all of the bootstrap dropdown components * Fix closing behavior of several buttons and ImageOverlay * Increase popover padding to 6px * Find a different way to create some padding at the bottom of the fields ...before the tag editor @kleinerpirat I think is what this css what trying to achieve? * Satisfy tests * Use removeStyleProperties in ImageOverlay * Use notify function in WithOverlay and WithFloating * Do not use portal for WithFloating and WithOverlay Allows for scrolling * Set hidden to default false in Rich/Plain TextInput * Reset handle when changing mathjax elements via click * Restrict size of empty mathjax image * Prevent sticky labels from obscuring menus * Remove several overflow-hidden * Fix empty string being falsy bug when editing mathjax * Do not import portal anymore * Use { reason, originalEvent } instead of symbol as update to modified event store * Fix closing behavior of image overlay (do not close after resize) * Simplify Collapsible * Use removeStyleProperties in Collapsible * Satisfy eslint * Fix latex shortcuts being mounted * Fix mathjax overlay not focusable in first field * Neither hide image overlay on escaped * Fix Block ButtonDropdown wrapping * Bring back portal to fix tag editor
2022-09-05 09:20:00 +02:00
<div class="handle-label" class:is-rtl={$direction === "rtl"}>
2021-08-05 03:24:04 +02:00
<slot />
</div>
<style lang="scss">
Use WithFloating for MathjaxOverlay (#2011) * Allow passing in reference into WithFloating as prop * Fix WithAutocomplete * Fix WithFloating for MathjaxOverlay * Add resize-store * Allow passing debug=True to jest_test for debugger support (#2013) * Disable auto-closing of HTML tags https://forums.ankiweb.net/t/set-html-editor-as-a-default-editor-instead-of-visual-editor/20988/3 Closes #1963 * Add slight margin to MathjaxEditor * Enable passing offset and shift to WithFloating * Hide overflow of mathjax editor * Add automatic hide functionality to sveltelib/position * Last polishes for Surrounder class (#2017) * Make private properties in Surrounder truly private * Fix remove logic of Surrounder * No reason for toggleTriggerRemove to be async * Allow using alt-shift to set all remove formats but this one * modifyFormat => updateFormat * Fix formatting * Fix field descriptions blocking cursor from being set (#2018) - happens when focus is in HTML editor * Remove hiding functionality again until it's really useful * Add support for autoPlacement * Implement new WithFloating that supports manually calling position() * Implement hide mechanisms * Add option in math dropdown to toggle MathJax rendering (#2014) * Add option in math dropdown to toggle MathJax rendering Closes #1942 * Hackily redraw the page when toggling MathJax * Add Fluent string * Default input setting in fields dialog (#1987) (kleinerpirat) * Introduce field setting to use plain text editor by default (kleinerpirat) * Remove leftover function from #1476 * Use boolean instead of string * Simplify clear_other_field_duplicates * Convert plain text key to camelCase * Move HTML item below the existing checkbox, instead of to the right (dae) Showing it on the right is more space efficient, but feels a bit cluttered IMHO. * Fix not being able to scroll when mouse hovers PlainTextInput (#2019) * Remove overscroll-behavior: none for * (all elements) * Revert "Remove overscroll-behavior: none for * (all elements)" This reverts commit 189358908cecd03027e19d8fe47822735319ec17. * Use body instead of *, but keep CSS rule * Unify two CSS rules * Remove console.logs * Reposition mathjax menu on switching between inline/block * Implement WithOverlay * Implement FloatingArrow * Display overlay with padding and brighter background * Rename to MathjaxOverlay * Simplify MathjaxOverlay component overall * Rename ImageHandle to image overlay * Generally fix ImageOverlay again * Increase z-index of StickyContainer * Fix setting block or inline on mathjax * Add reasons in closing-{click,keyup} * Have both WithFloating and WithOverlay use a simple show flag instead of a store * Remove subscribe-trigger * Fix clicking from one mathjax element to another * Check before executing cleanup * Do not wait for elements to mount before slotting in With{Floating,Overlay} * Allow using reference slot for WithFloating and WithOveray * Add inline argument to options * Add support for inline slot in WithOvelay * Use WithFloating for RemoveFormatButton * Remove last uses of DropdownMenu and WithDropdown * Remove all of the bootstrap dropdown components * Fix closing behavior of several buttons and ImageOverlay * Increase popover padding to 6px * Find a different way to create some padding at the bottom of the fields ...before the tag editor @kleinerpirat I think is what this css what trying to achieve? * Satisfy tests * Use removeStyleProperties in ImageOverlay * Use notify function in WithOverlay and WithFloating * Do not use portal for WithFloating and WithOverlay Allows for scrolling * Set hidden to default false in Rich/Plain TextInput * Reset handle when changing mathjax elements via click * Restrict size of empty mathjax image * Prevent sticky labels from obscuring menus * Remove several overflow-hidden * Fix empty string being falsy bug when editing mathjax * Do not import portal anymore * Use { reason, originalEvent } instead of symbol as update to modified event store * Fix closing behavior of image overlay (do not close after resize) * Simplify Collapsible * Use removeStyleProperties in Collapsible * Satisfy eslint * Fix latex shortcuts being mounted * Fix mathjax overlay not focusable in first field * Neither hide image overlay on escaped * Fix Block ButtonDropdown wrapping * Bring back portal to fix tag editor
2022-09-05 09:20:00 +02:00
.handle-label {
2021-08-05 03:24:04 +02:00
position: absolute;
width: fit-content;
2021-08-05 03:24:04 +02:00
left: 0;
right: 0;
bottom: 3px;
margin-left: auto;
margin-right: auto;
2021-08-05 03:24:04 +02:00
font-size: 13px;
color: white;
Use WithFloating for MathjaxOverlay (#2011) * Allow passing in reference into WithFloating as prop * Fix WithAutocomplete * Fix WithFloating for MathjaxOverlay * Add resize-store * Allow passing debug=True to jest_test for debugger support (#2013) * Disable auto-closing of HTML tags https://forums.ankiweb.net/t/set-html-editor-as-a-default-editor-instead-of-visual-editor/20988/3 Closes #1963 * Add slight margin to MathjaxEditor * Enable passing offset and shift to WithFloating * Hide overflow of mathjax editor * Add automatic hide functionality to sveltelib/position * Last polishes for Surrounder class (#2017) * Make private properties in Surrounder truly private * Fix remove logic of Surrounder * No reason for toggleTriggerRemove to be async * Allow using alt-shift to set all remove formats but this one * modifyFormat => updateFormat * Fix formatting * Fix field descriptions blocking cursor from being set (#2018) - happens when focus is in HTML editor * Remove hiding functionality again until it's really useful * Add support for autoPlacement * Implement new WithFloating that supports manually calling position() * Implement hide mechanisms * Add option in math dropdown to toggle MathJax rendering (#2014) * Add option in math dropdown to toggle MathJax rendering Closes #1942 * Hackily redraw the page when toggling MathJax * Add Fluent string * Default input setting in fields dialog (#1987) (kleinerpirat) * Introduce field setting to use plain text editor by default (kleinerpirat) * Remove leftover function from #1476 * Use boolean instead of string * Simplify clear_other_field_duplicates * Convert plain text key to camelCase * Move HTML item below the existing checkbox, instead of to the right (dae) Showing it on the right is more space efficient, but feels a bit cluttered IMHO. * Fix not being able to scroll when mouse hovers PlainTextInput (#2019) * Remove overscroll-behavior: none for * (all elements) * Revert "Remove overscroll-behavior: none for * (all elements)" This reverts commit 189358908cecd03027e19d8fe47822735319ec17. * Use body instead of *, but keep CSS rule * Unify two CSS rules * Remove console.logs * Reposition mathjax menu on switching between inline/block * Implement WithOverlay * Implement FloatingArrow * Display overlay with padding and brighter background * Rename to MathjaxOverlay * Simplify MathjaxOverlay component overall * Rename ImageHandle to image overlay * Generally fix ImageOverlay again * Increase z-index of StickyContainer * Fix setting block or inline on mathjax * Add reasons in closing-{click,keyup} * Have both WithFloating and WithOverlay use a simple show flag instead of a store * Remove subscribe-trigger * Fix clicking from one mathjax element to another * Check before executing cleanup * Do not wait for elements to mount before slotting in With{Floating,Overlay} * Allow using reference slot for WithFloating and WithOveray * Add inline argument to options * Add support for inline slot in WithOvelay * Use WithFloating for RemoveFormatButton * Remove last uses of DropdownMenu and WithDropdown * Remove all of the bootstrap dropdown components * Fix closing behavior of several buttons and ImageOverlay * Increase popover padding to 6px * Find a different way to create some padding at the bottom of the fields ...before the tag editor @kleinerpirat I think is what this css what trying to achieve? * Satisfy tests * Use removeStyleProperties in ImageOverlay * Use notify function in WithOverlay and WithFloating * Do not use portal for WithFloating and WithOverlay Allows for scrolling * Set hidden to default false in Rich/Plain TextInput * Reset handle when changing mathjax elements via click * Restrict size of empty mathjax image * Prevent sticky labels from obscuring menus * Remove several overflow-hidden * Fix empty string being falsy bug when editing mathjax * Do not import portal anymore * Use { reason, originalEvent } instead of symbol as update to modified event store * Fix closing behavior of image overlay (do not close after resize) * Simplify Collapsible * Use removeStyleProperties in Collapsible * Satisfy eslint * Fix latex shortcuts being mounted * Fix mathjax overlay not focusable in first field * Neither hide image overlay on escaped * Fix Block ButtonDropdown wrapping * Bring back portal to fix tag editor
2022-09-05 09:20:00 +02:00
background-color: rgba(0 0 0 / 0.4);
2021-08-05 03:24:04 +02:00
border-color: black;
border-radius: 5px;
2021-08-05 03:24:04 +02:00
padding: 0 5px;
pointer-events: none;
user-select: none;
2021-08-05 03:24:04 +02:00
}
</style>