@esportsplus/ui 0.61.0 → 0.63.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.audit/audit.json +4 -132
- package/.audit/check-scss.mjs +2 -2
- package/.audit/rules-audit.md +3 -28
- package/README.md +18 -17
- package/RULES.md +30 -0
- package/build/components/accordion/index.d.ts +5 -1
- package/build/components/accordion/index.js +29 -27
- package/build/components/accordion/scss/index.scss +1 -1
- package/build/components/announcement/index.d.ts +720 -2164
- package/build/components/announcement/index.js +12 -9
- package/build/components/announcement/scss/index.scss +1 -1
- package/build/components/breadcrumb/index.d.ts +4 -1
- package/build/components/breadcrumb/index.js +54 -49
- package/build/components/breadcrumb/scss/index.scss +1 -1
- package/build/components/button/copy.d.ts +1 -10
- package/build/components/button/copy.js +14 -11
- package/build/components/button/faces.d.ts +2 -1
- package/build/components/button/faces.js +9 -10
- package/build/components/button/kbd.d.ts +2 -10
- package/build/components/button/kbd.js +17 -15
- package/build/components/button/morph/index.d.ts +1443 -2165
- package/build/components/button/morph/save.d.ts +1 -10
- package/build/components/button/morph/save.js +5 -5
- package/build/components/button/morph/template.d.ts +2 -1
- package/build/components/button/morph/template.js +49 -29
- package/build/components/button/scss/index.scss +1 -1
- package/build/components/button/sidebar.d.ts +1 -10
- package/build/components/button/sidebar.js +14 -12
- package/build/components/button/split.d.ts +6 -1
- package/build/components/button/split.js +16 -11
- package/build/components/capslock/index.d.ts +1 -10
- package/build/components/capslock/index.js +16 -13
- package/build/components/capslock/scss/index.scss +1 -1
- package/build/components/card/scss/index.scss +1 -1
- package/build/components/chat/minimap/index.d.ts +12 -1
- package/build/components/chat/minimap/index.js +98 -74
- package/build/components/checkbox/group.d.ts +2 -10
- package/build/components/checkbox/group.js +39 -29
- package/build/components/checkbox/options.d.ts +5005 -6440
- package/build/components/checkbox/options.js +72 -44
- package/build/components/checkbox/scss/index.scss +1 -1
- package/build/components/color-picker/index.d.ts +10 -1
- package/build/components/color-picker/index.js +99 -82
- package/build/components/color-picker/scss/index.scss +1 -1
- package/build/components/command/palette.d.ts +13 -5
- package/build/components/command/palette.js +141 -130
- package/build/components/command/scss/index.scss +1 -1
- package/build/components/command/search.d.ts +2 -20
- package/build/components/command/search.js +17 -16
- package/build/components/container/scss/index.scss +1 -1
- package/build/components/counter/index.d.ts +1 -10
- package/build/components/counter/index.js +34 -31
- package/build/components/counter/scss/index.scss +1 -1
- package/build/components/dock/index.d.ts +4 -1
- package/build/components/dock/index.js +154 -114
- package/build/components/dock/scss/index.scss +1 -1
- package/build/components/editor/code/editor.d.ts +1 -10
- package/build/components/editor/code/features.d.ts +3 -3
- package/build/components/editor/code/features.js +65 -52
- package/build/components/editor/code/field.d.ts +1 -1
- package/build/components/editor/code/find.d.ts +4 -4
- package/build/components/editor/code/find.js +39 -37
- package/build/components/editor/code/folding.d.ts +1 -1
- package/build/components/editor/code/goto.d.ts +2 -1
- package/build/components/editor/code/goto.js +7 -7
- package/build/components/editor/code/gutter.js +12 -12
- package/build/components/editor/code/html.d.ts +4 -0
- package/build/components/editor/code/html.js +8 -0
- package/build/components/editor/code/minimap.d.ts +4 -10
- package/build/components/editor/code/minimap.js +18 -13
- package/build/components/editor/code/rows.js +6 -12
- package/build/components/editor/code/search.d.ts +1 -2
- package/build/components/editor/code/search.js +1 -1
- package/build/components/editor/code/services/index.d.ts +1 -1
- package/build/components/editor/code/services/index.js +27 -23
- package/build/components/editor/code/services/model.d.ts +1 -5
- package/build/components/editor/code/services/model.js +1 -1
- package/build/components/editor/code/services/session.d.ts +3 -2
- package/build/components/editor/code/services/session.js +1 -4
- package/build/components/editor/code/syntax.d.ts +1 -1
- package/build/components/editor/code/view.d.ts +2 -1
- package/build/components/editor/code/view.js +50 -39
- package/build/components/editor/diffs/merge.d.ts +1 -10
- package/build/components/editor/diffs/merge.js +126 -102
- package/build/components/editor/diffs/render.d.ts +1 -2
- package/build/components/editor/diffs/render.js +2 -8
- package/build/components/editor/diffs/view.d.ts +1 -10
- package/build/components/editor/diffs/view.js +112 -105
- package/build/components/editor/markdown/editing.d.ts +1 -1
- package/build/components/editor/markdown/erase.js +1 -1
- package/build/components/editor/markdown/format.d.ts +23 -0
- package/build/components/editor/markdown/format.js +319 -0
- package/build/components/editor/markdown/html.d.ts +1 -1
- package/build/components/editor/markdown/inline.d.ts +1 -1
- package/build/components/editor/markdown/inline.js +6 -5
- package/build/components/editor/markdown/layout.d.ts +1 -3
- package/build/components/editor/markdown/layout.js +1 -1
- package/build/components/editor/markdown/model.d.ts +3 -9
- package/build/components/editor/markdown/model.js +1 -8
- package/build/components/editor/markdown/render.d.ts +2 -1
- package/build/components/editor/markdown/render.js +278 -247
- package/build/components/editor/markdown/template.d.ts +1 -10
- package/build/components/editor/markdown/toolbar.d.ts +32 -0
- package/build/components/editor/markdown/toolbar.js +556 -0
- package/build/components/editor/markdown/view.d.ts +12 -1
- package/build/components/editor/markdown/view.js +154 -60
- package/build/components/editor/tree/compact.d.ts +2 -1
- package/build/components/editor/tree/compact.js +12 -11
- package/build/components/editor/tree/drag.d.ts +3 -2
- package/build/components/editor/tree/drag.js +29 -26
- package/build/components/editor/tree/edit.d.ts +1 -1
- package/build/components/editor/tree/edit.js +10 -9
- package/build/components/editor/tree/find.d.ts +1 -1
- package/build/components/editor/tree/find.js +10 -6
- package/build/components/editor/tree/icons.d.ts +1 -1
- package/build/components/editor/tree/icons.js +1 -1
- package/build/components/editor/tree/lazy.d.ts +2 -1
- package/build/components/editor/tree/lazy.js +17 -16
- package/build/components/editor/tree/sticky.d.ts +3 -2
- package/build/components/editor/tree/sticky.js +7 -6
- package/build/components/editor/tree/template.d.ts +2 -1
- package/build/components/editor/tree/template.js +144 -157
- package/build/components/editor/viewer/model.js +1 -7
- package/build/components/editor/viewer/template.d.ts +1 -10
- package/build/components/editor/viewer/template.js +74 -65
- package/build/components/editor/workspace/navigate.d.ts +2 -1
- package/build/components/editor/workspace/navigate.js +2 -4
- package/build/components/editor/workspace/session.d.ts +2 -1
- package/build/components/editor/workspace/session.js +14 -9
- package/build/components/editor/workspace/shortcuts.js +39 -33
- package/build/components/editor/workspace/status.js +2 -2
- package/build/components/editor/workspace/statusbar.d.ts +2 -1
- package/build/components/editor/workspace/statusbar.js +49 -48
- package/build/components/editor/workspace/strip.js +6 -5
- package/build/components/editor/workspace/template.d.ts +2 -10
- package/build/components/editor/workspace/template.js +149 -144
- package/build/components/error/index.d.ts +1 -10
- package/build/components/error/index.js +64 -32
- package/build/components/error/scss/index.scss +1 -1
- package/build/components/filter/index.js +138 -74
- package/build/components/filter/scss/index.scss +1 -1
- package/build/components/form/action.d.ts +2 -2
- package/build/components/form/action.js +12 -9
- package/build/components/frame/scss/index.scss +1 -1
- package/build/components/group/index.d.ts +3 -1
- package/build/components/group/index.js +10 -7
- package/build/components/group/scss/index.scss +1 -1
- package/build/components/heatmap/index.d.ts +5 -2
- package/build/components/heatmap/index.js +72 -59
- package/build/components/heatmap/scss/index.scss +1 -1
- package/build/components/highlight/index.d.ts +1 -10
- package/build/components/highlight/index.js +21 -19
- package/build/components/highlight/scss/index.scss +1 -1
- package/build/components/icon/index.d.ts +1 -10
- package/build/components/icon/index.js +11 -10
- package/build/components/image/lazyload.d.ts +2 -1
- package/build/components/image/lazyload.js +29 -26
- package/build/components/image/scss/index.scss +1 -1
- package/build/components/index.d.ts +0 -4
- package/build/components/index.js +0 -4
- package/build/components/inline-edit/index.d.ts +5 -1
- package/build/components/inline-edit/index.js +34 -27
- package/build/components/inline-edit/rich.d.ts +10 -15
- package/build/components/inline-edit/rich.js +81 -1193
- package/build/components/inline-edit/scss/index.scss +1 -1
- package/build/components/inline-edit/status.d.ts +3 -2
- package/build/components/inline-edit/status.js +22 -18
- package/build/components/input/field.d.ts +2 -1
- package/build/components/input/field.js +12 -9
- package/build/components/input/scrub.d.ts +4 -1
- package/build/components/input/scrub.js +25 -20
- package/build/components/input/scss/index.scss +1 -1
- package/build/components/input/tag.d.ts +4 -2
- package/build/components/input/tag.js +58 -53
- package/build/components/link/scss/index.scss +1 -1
- package/build/components/loading/index.d.ts +2 -1
- package/build/components/loading/index.js +6 -3
- package/build/components/loading/scss/index.scss +1 -1
- package/build/components/marquee/index.d.ts +2 -1
- package/build/components/marquee/index.js +77 -72
- package/build/components/marquee/scss/index.scss +1 -1
- package/build/components/marquee/velocity.js +4 -3
- package/build/components/metric/flash.d.ts +2 -1
- package/build/components/metric/flash.js +25 -25
- package/build/components/metric/index.d.ts +13 -2
- package/build/components/metric/index.js +60 -56
- package/build/components/metric/scss/index.scss +1 -1
- package/build/components/nav/scss/index.scss +1 -1
- package/build/components/nav/spy.js +9 -6
- package/build/components/nav/toc.d.ts +1 -10
- package/build/components/nav/tree.d.ts +3 -1
- package/build/components/nav/tree.js +60 -58
- package/build/components/notification/index.d.ts +1 -10
- package/build/components/notification/index.js +26 -36
- package/build/components/notification/scss/index.scss +1 -1
- package/build/components/overlay/index.d.ts +4 -5
- package/build/components/overlay/index.js +399 -196
- package/build/components/overlay/popup.d.ts +5 -6
- package/build/components/overlay/popup.js +80 -39
- package/build/components/overlay/scss/index.scss +1 -1
- package/build/components/pagination/arrows.d.ts +2 -1
- package/build/components/pagination/arrows.js +48 -45
- package/build/components/pagination/cards.d.ts +5 -2
- package/build/components/pagination/cards.js +70 -45
- package/build/components/pagination/dots.d.ts +3 -1
- package/build/components/pagination/dots.js +29 -24
- package/build/components/pagination/index.d.ts +2 -1
- package/build/components/pagination/index.js +27 -28
- package/build/components/pagination/scss/index.scss +1 -1
- package/build/components/panels/dnd.js +30 -22
- package/build/components/panels/group.d.ts +3 -2
- package/build/components/panels/group.js +134 -131
- package/build/components/panels/index.d.ts +2 -10
- package/build/components/panels/index.js +84 -80
- package/build/components/panels/resize.js +39 -3
- package/build/components/panels/scss/index.scss +1 -1
- package/build/components/panels/subtree.d.ts +2 -1
- package/build/components/panels/subtree.js +8 -7
- package/build/components/preview/buttons.d.ts +2 -10
- package/build/components/preview/buttons.js +6 -6
- package/build/components/preview/code.d.ts +1 -10
- package/build/components/preview/code.js +6 -6
- package/build/components/preview/header.d.ts +2 -10
- package/build/components/preview/header.js +15 -12
- package/build/components/preview/index.d.ts +13 -8680
- package/build/components/preview/index.js +22 -22
- package/build/components/preview/scss/index.scss +1 -1
- package/build/components/preview/source.d.ts +1 -10
- package/build/components/preview/source.js +18 -15
- package/build/components/preview/stage.d.ts +2 -10
- package/build/components/preview/stage.js +19 -15
- package/build/components/progress/index.d.ts +2 -1
- package/build/components/progress/index.js +30 -26
- package/build/components/progress/scss/index.scss +1 -1
- package/build/components/progress/text.d.ts +2 -1
- package/build/components/progress/text.js +27 -25
- package/build/components/range/filter.d.ts +2 -1
- package/build/components/range/filter.js +126 -127
- package/build/components/range/index.d.ts +2 -1
- package/build/components/range/index.js +17 -22
- package/build/components/range/scss/index.scss +1 -1
- package/build/components/relative-time/index.d.ts +3 -1
- package/build/components/relative-time/index.js +56 -41
- package/build/components/relative-time/scss/index.scss +1 -1
- package/build/components/root/scss/index.scss +1 -1
- package/build/components/select/expand.d.ts +44 -0
- package/build/components/select/expand.js +215 -0
- package/build/components/select/index.d.ts +18 -9
- package/build/components/select/index.js +108 -81
- package/build/components/select/scss/index.scss +1 -1
- package/build/components/shell/index.d.ts +2 -1
- package/build/components/shell/index.js +127 -109
- package/build/components/shell/scss/index.scss +1 -1
- package/build/components/shortcut-recorder/index.js +46 -43
- package/build/components/shortcut-recorder/scss/index.scss +1 -1
- package/build/components/sortable/index.d.ts +2 -714
- package/build/components/sortable/index.js +75 -64
- package/build/components/sortable/scss/index.scss +1 -1
- package/build/components/story/index.d.ts +4 -10
- package/build/components/story/index.js +121 -63
- package/build/components/story/scss/index.scss +1 -1
- package/build/components/surface-field/engine.js +51 -53
- package/build/components/surface-field/index.d.ts +2180 -2921
- package/build/components/surface-field/index.js +42 -38
- package/build/components/surface-field/scss/index.scss +1 -1
- package/build/components/surface-field/surface.d.ts +1 -10
- package/build/components/surface-field/surface.js +42 -36
- package/build/components/tasklist/index.d.ts +8 -1
- package/build/components/tasklist/index.js +63 -46
- package/build/components/tasklist/scss/index.scss +1 -1
- package/build/components/textarea/index.d.ts +722 -2170
- package/build/components/textarea/index.js +67 -91
- package/build/components/textarea/scss/index.scss +1 -1
- package/build/components/theme/cards.d.ts +4 -0
- package/build/components/theme/cards.js +21 -0
- package/build/components/theme/index.d.ts +12 -3
- package/build/components/theme/index.js +38 -14
- package/build/components/theme/reveal.d.ts +6 -0
- package/build/components/theme/reveal.js +100 -0
- package/build/components/theme/scss/index.scss +1 -1
- package/build/components/{theme-picker → theme}/shared.d.ts +4 -4
- package/build/components/{theme-picker → theme}/shared.js +5 -3
- package/build/components/theme/swatches.d.ts +4 -0
- package/build/components/theme/swatches.js +21 -0
- package/build/components/theme/toggle.d.ts +15 -0
- package/build/components/theme/toggle.js +33 -0
- package/build/components/toast/index.d.ts +6 -2
- package/build/components/toast/index.js +62 -50
- package/build/components/toast/scss/index.scss +1 -1
- package/build/components/tooltip/menu.d.ts +10 -2
- package/build/components/tooltip/menu.js +194 -179
- package/build/components/tooltip/onclick.d.ts +1 -10
- package/build/components/tooltip/onclick.js +25 -27
- package/build/components/tooltip/onhover.d.ts +8 -709
- package/build/components/tooltip/onhover.js +60 -60
- package/build/components/tooltip/scss/index.scss +1 -1
- package/build/components/tooltip/shared.d.ts +5 -3
- package/build/components/tooltip/shared.js +201 -91
- package/build/components/tooltip/utilities.d.ts +10 -4
- package/build/components/tooltip/utilities.js +95 -18
- package/build/components/typewriter/index.d.ts +2855 -1413
- package/build/components/typewriter/index.js +17 -18
- package/build/components/typewriter/retype.d.ts +2 -1
- package/build/components/typewriter/retype.js +21 -18
- package/build/components/typewriter/rotate.d.ts +2 -1
- package/build/components/typewriter/rotate.js +34 -29
- package/build/components/typewriter/scss/index.scss +1 -1
- package/build/components/uptime/index.d.ts +2 -1
- package/build/components/uptime/index.js +51 -47
- package/build/components/uptime/scss/index.scss +1 -1
- package/build/components/usage-meter/index.d.ts +719 -2161
- package/build/components/usage-meter/index.js +23 -20
- package/build/components/usage-meter/scss/index.scss +1 -1
- package/build/modifiers/border/scss/index.scss +1 -1
- package/build/modifiers/box-shadow/scss/index.scss +1 -1
- package/build/modifiers/color/scss/index.scss +1 -1
- package/build/modifiers/disabled/scss/index.scss +2 -0
- package/build/modifiers/glass/index.d.ts +3 -2
- package/build/modifiers/glass/index.js +7 -7
- package/build/modifiers/glass/scss/index.scss +1 -1
- package/build/modifiers/scrollbar/index.d.ts +13 -13
- package/build/modifiers/scrollbar/index.js +74 -90
- package/build/modifiers/scrollbar/scss/index.scss +1 -1
- package/build/shared/animation.d.ts +1 -1
- package/build/shared/animation.js +5 -3
- package/build/shared/dispatch.d.ts +7 -0
- package/build/shared/dispatch.js +25 -0
- package/build/shared/drag.d.ts +2 -4
- package/build/shared/press.d.ts +1 -1
- package/build/shared/press.js +5 -3
- package/build/shared/resize.js +2 -25
- package/build/shared/transition.d.ts +1 -1
- package/build/shared/transition.js +2 -2
- package/build/shared/visible.js +1 -24
- package/package.json +13 -14
- package/src/components/accordion/index.ts +2 -4
- package/src/components/accordion/scss/index.scss +17 -14
- package/src/components/accordion/scss/variables.scss +6 -7
- package/src/components/announcement/scss/index.scss +8 -13
- package/src/components/announcement/scss/variables.scss +12 -8
- package/src/components/breadcrumb/index.ts +4 -4
- package/src/components/breadcrumb/scss/index.scss +12 -12
- package/src/components/breadcrumb/scss/variables.scss +5 -12
- package/src/components/button/copy.ts +1 -1
- package/src/components/button/kbd.ts +8 -7
- package/src/components/button/morph/save.ts +2 -2
- package/src/components/button/morph/template.ts +18 -20
- package/src/components/button/scss/index.scss +84 -59
- package/src/components/button/scss/variables.scss +44 -29
- package/src/components/button/sidebar.ts +2 -2
- package/src/components/button/split.ts +7 -8
- package/src/components/capslock/index.ts +4 -4
- package/src/components/capslock/scss/index.scss +4 -2
- package/src/components/capslock/scss/variables.scss +14 -15
- package/src/components/card/scss/index.scss +10 -19
- package/src/components/card/scss/variables.scss +6 -2
- package/src/components/chat/minimap/index.ts +14 -13
- package/src/components/chat/minimap/scss/index.scss +19 -28
- package/src/components/chat/minimap/scss/variables.scss +33 -29
- package/src/components/checkbox/group.ts +5 -5
- package/src/components/checkbox/options.ts +2 -2
- package/src/components/checkbox/scss/index.scss +10 -6
- package/src/components/checkbox/scss/variables.scss +59 -44
- package/src/components/clipboard/write.ts +2 -1
- package/src/components/color-picker/index.ts +9 -11
- package/src/components/color-picker/scss/index.scss +2 -2
- package/src/components/color-picker/scss/variables.scss +26 -41
- package/src/components/command/palette.ts +15 -29
- package/src/components/command/scss/index.scss +8 -13
- package/src/components/command/scss/variables.scss +8 -8
- package/src/components/command/search.ts +3 -8
- package/src/components/container/scss/index.scss +2 -4
- package/src/components/container/scss/variables.scss +0 -2
- package/src/components/counter/index.ts +2 -1
- package/src/components/counter/scss/index.scss +2 -1
- package/src/components/counter/scss/variables.scss +3 -9
- package/src/components/dock/index.ts +17 -8
- package/src/components/dock/scss/index.scss +26 -56
- package/src/components/dock/scss/variables.scss +11 -20
- package/src/components/editor/code/features.ts +4 -5
- package/src/components/editor/code/field.ts +1 -1
- package/src/components/editor/code/find.ts +1 -1
- package/src/components/editor/code/folding.ts +1 -1
- package/src/components/editor/code/html.ts +17 -0
- package/src/components/editor/code/minimap.ts +7 -5
- package/src/components/editor/code/rows.ts +1 -14
- package/src/components/editor/code/scss/_editor.scss +10 -23
- package/src/components/editor/code/scss/_features.scss +17 -26
- package/src/components/editor/code/scss/_minimap.scss +29 -0
- package/src/components/editor/code/scss/_services.scss +4 -7
- package/src/components/editor/code/scss/index.scss +0 -1
- package/src/components/editor/code/scss/variables.scss +22 -14
- package/src/components/editor/code/search.ts +1 -1
- package/src/components/editor/code/services/completion.ts +1 -0
- package/src/components/editor/code/services/hover.ts +1 -0
- package/src/components/editor/code/services/index.ts +1 -1
- package/src/components/editor/code/services/model.ts +1 -1
- package/src/components/editor/code/services/session.ts +1 -4
- package/src/components/editor/code/syntax.ts +1 -1
- package/src/components/editor/diffs/merge.ts +3 -3
- package/src/components/editor/diffs/render.ts +2 -17
- package/src/components/editor/diffs/scss/_diffs.scss +22 -57
- package/src/components/editor/diffs/scss/_merge.scss +8 -29
- package/src/components/editor/diffs/scss/variables.scss +1 -10
- package/src/components/editor/diffs/view.ts +4 -5
- package/src/components/editor/markdown/editing.ts +1 -1
- package/src/components/editor/markdown/erase.ts +3 -3
- package/src/components/editor/markdown/format.ts +517 -0
- package/src/components/editor/markdown/html.ts +1 -1
- package/src/components/editor/markdown/inline.ts +9 -6
- package/src/components/editor/markdown/layout.ts +1 -1
- package/src/components/editor/markdown/model.ts +2 -17
- package/src/components/editor/markdown/render.ts +3 -2
- package/src/components/editor/markdown/scss/index.scss +132 -57
- package/src/components/editor/markdown/scss/variables.scss +124 -4
- package/src/components/editor/markdown/toolbar.ts +628 -0
- package/src/components/editor/markdown/view.ts +121 -10
- package/src/components/editor/tree/drag.ts +16 -15
- package/src/components/editor/tree/icons.ts +1 -1
- package/src/components/editor/tree/scss/index.scss +69 -44
- package/src/components/editor/tree/scss/variables.scss +75 -44
- package/src/components/editor/tree/sticky.ts +1 -1
- package/src/components/editor/tree/template.ts +2 -2
- package/src/components/editor/viewer/model.ts +1 -14
- package/src/components/editor/viewer/scss/_viewer.scss +22 -72
- package/src/components/editor/viewer/scss/index.scss +1 -1
- package/src/components/editor/viewer/scss/variables.scss +1 -3
- package/src/components/editor/viewer/template.ts +4 -2
- package/src/components/editor/workspace/navigate.ts +3 -6
- package/src/components/editor/workspace/scss/_keybindings.scss +9 -7
- package/src/components/editor/workspace/scss/_status.scss +14 -38
- package/src/components/editor/workspace/scss/_tabs.scss +6 -3
- package/src/components/editor/workspace/scss/index.scss +38 -33
- package/src/components/editor/workspace/scss/variables.scss +57 -53
- package/src/components/editor/workspace/session.ts +20 -13
- package/src/components/editor/workspace/status.ts +2 -2
- package/src/components/editor/workspace/template.ts +12 -21
- package/src/components/error/index.ts +36 -18
- package/src/components/error/scss/index.scss +3 -1
- package/src/components/error/scss/variables.scss +1 -0
- package/src/components/filter/index.ts +146 -99
- package/src/components/filter/scss/variables.scss +1 -1
- package/src/components/form/action.ts +1 -1
- package/src/components/frame/scss/index.scss +10 -6
- package/src/components/frame/scss/variables.scss +11 -6
- package/src/components/grid/scss/index.scss +1 -1
- package/src/components/grid/scss/variables.scss +1 -1
- package/src/components/heatmap/index.ts +2 -2
- package/src/components/heatmap/scss/index.scss +22 -17
- package/src/components/heatmap/scss/variables.scss +16 -34
- package/src/components/highlight/index.ts +0 -1
- package/src/components/highlight/scss/index.scss +13 -21
- package/src/components/highlight/scss/variables.scss +12 -14
- package/src/components/icon/index.ts +0 -4
- package/src/components/icon/scss/index.scss +2 -0
- package/src/components/image/lazyload.ts +1 -1
- package/src/components/image/scss/index.scss +14 -13
- package/src/components/image/scss/variables.scss +16 -12
- package/src/components/index.ts +0 -4
- package/src/components/inline-edit/index.ts +6 -5
- package/src/components/inline-edit/rich.ts +85 -1400
- package/src/components/inline-edit/scss/index.scss +24 -191
- package/src/components/inline-edit/scss/variables.scss +24 -191
- package/src/components/inline-edit/status.ts +6 -3
- package/src/components/input/field.ts +2 -2
- package/src/components/input/scrub.ts +1 -5
- package/src/components/input/scss/_scrub.scss +7 -0
- package/src/components/input/scss/_tag.scss +4 -2
- package/src/components/input/scss/index.scss +1 -2
- package/src/components/input/scss/variables.scss +14 -21
- package/src/components/input/tag.ts +6 -7
- package/src/components/json/download.ts +2 -1
- package/src/components/link/scss/index.scss +0 -1
- package/src/components/loading/index.ts +1 -1
- package/src/components/loading/scss/index.scss +4 -4
- package/src/components/loading/scss/variables.scss +4 -4
- package/src/components/marquee/index.ts +5 -5
- package/src/components/marquee/scss/index.scss +6 -4
- package/src/components/marquee/scss/variables.scss +3 -4
- package/src/components/marquee/velocity.ts +7 -3
- package/src/components/metric/flash.ts +1 -1
- package/src/components/metric/index.ts +5 -13
- package/src/components/metric/scss/_flash.scss +9 -4
- package/src/components/metric/scss/index.scss +11 -9
- package/src/components/metric/scss/variables.scss +73 -73
- package/src/components/nav/scss/index.scss +2 -1
- package/src/components/nav/scss/variables.scss +9 -11
- package/src/components/nav/spy.ts +15 -8
- package/src/components/nav/tree.ts +28 -30
- package/src/components/notification/index.ts +37 -16
- package/src/components/notification/scss/index.scss +32 -17
- package/src/components/notification/scss/variables.scss +12 -12
- package/src/components/overlay/index.ts +212 -142
- package/src/components/overlay/popup.ts +89 -52
- package/src/components/overlay/scss/index.scss +68 -85
- package/src/components/overlay/scss/variables.scss +15 -12
- package/src/components/pagination/cards.ts +1 -2
- package/src/components/pagination/index.ts +3 -9
- package/src/components/pagination/scss/index.scss +12 -12
- package/src/components/pagination/scss/variables.scss +39 -21
- package/src/components/panels/dnd.ts +35 -29
- package/src/components/panels/group.ts +5 -13
- package/src/components/panels/index.ts +4 -6
- package/src/components/panels/resize.ts +30 -4
- package/src/components/panels/scss/index.scss +13 -28
- package/src/components/panels/scss/variables.scss +3 -3
- package/src/components/preview/code.ts +1 -1
- package/src/components/preview/index.ts +12 -7
- package/src/components/preview/scss/index.scss +30 -15
- package/src/components/preview/scss/variables.scss +56 -34
- package/src/components/progress/scss/index.scss +14 -11
- package/src/components/progress/scss/variables.scss +34 -31
- package/src/components/progress/text.ts +9 -8
- package/src/components/range/filter.ts +9 -11
- package/src/components/range/index.ts +2 -9
- package/src/components/range/scss/_filter.scss +4 -3
- package/src/components/range/scss/_slider.scss +2 -1
- package/src/components/range/scss/variables.scss +2 -16
- package/src/components/relative-time/index.ts +15 -16
- package/src/components/relative-time/scss/index.scss +8 -4
- package/src/components/relative-time/scss/variables.scss +7 -3
- package/src/components/root/scss/index.scss +3 -0
- package/src/components/root/scss/variables.scss +11 -11
- package/src/components/select/expand.ts +272 -0
- package/src/components/select/index.ts +142 -119
- package/src/components/select/scss/index.scss +79 -7
- package/src/components/select/scss/variables.scss +67 -3
- package/src/components/shell/index.ts +73 -50
- package/src/components/shell/scss/index.scss +34 -47
- package/src/components/shell/scss/variables.scss +16 -16
- package/src/components/shortcut-recorder/index.ts +14 -17
- package/src/components/shortcut-recorder/scss/index.scss +15 -10
- package/src/components/shortcut-recorder/scss/variables.scss +4 -7
- package/src/components/sortable/index.ts +25 -28
- package/src/components/sortable/scss/index.scss +28 -27
- package/src/components/sortable/scss/variables.scss +12 -7
- package/src/components/story/index.ts +110 -47
- package/src/components/story/scss/index.scss +13 -18
- package/src/components/story/scss/variables.scss +4 -16
- package/src/components/surface-field/engine.ts +71 -72
- package/src/components/surface-field/index.ts +17 -20
- package/src/components/surface-field/scss/index.scss +9 -11
- package/src/components/surface-field/scss/variables.scss +20 -23
- package/src/components/surface-field/surface.ts +4 -3
- package/src/components/tasklist/index.ts +1 -6
- package/src/components/tasklist/scss/index.scss +22 -26
- package/src/components/tasklist/scss/variables.scss +14 -20
- package/src/components/textarea/index.ts +49 -91
- package/src/components/textarea/scss/index.scss +20 -15
- package/src/components/textarea/scss/variables.scss +15 -0
- package/src/components/theme/cards.ts +19 -0
- package/src/components/theme/index.ts +58 -17
- package/src/components/theme/reveal.ts +190 -0
- package/src/components/theme/scss/index.scss +109 -0
- package/src/components/theme/scss/variables.scss +153 -3
- package/src/components/{theme-picker → theme}/shared.ts +9 -6
- package/src/components/theme/swatches.ts +15 -0
- package/src/components/theme/toggle.ts +47 -0
- package/src/components/toast/index.ts +2 -3
- package/src/components/toast/scss/index.scss +63 -0
- package/src/components/toast/scss/variables.scss +121 -16
- package/src/components/tooltip/menu.ts +141 -131
- package/src/components/tooltip/onclick.ts +16 -21
- package/src/components/tooltip/onhover.ts +5 -8
- package/src/components/tooltip/scss/index.scss +534 -56
- package/src/components/tooltip/scss/variables.scss +64 -13
- package/src/components/tooltip/shared.ts +129 -87
- package/src/components/tooltip/utilities.ts +75 -24
- package/src/components/typewriter/index.ts +7 -10
- package/src/components/typewriter/rotate.ts +11 -7
- package/src/components/typewriter/scss/index.scss +2 -0
- package/src/components/typewriter/scss/variables.scss +1 -1
- package/src/components/uptime/index.ts +12 -6
- package/src/components/uptime/scss/index.scss +86 -75
- package/src/components/uptime/scss/variables.scss +82 -51
- package/src/components/usage-meter/index.ts +1 -1
- package/src/components/usage-meter/scss/index.scss +0 -3
- package/src/components/usage-meter/scss/variables.scss +13 -14
- package/src/css-utilities/background.scss +9 -1
- package/src/css-utilities/border.scss +3 -0
- package/src/css-utilities/box-shadow.scss +3 -2
- package/src/css-utilities/color.scss +13 -3
- package/src/css-utilities/disabled.scss +12 -0
- package/src/css-utilities/font/geist/index.scss +2 -1
- package/src/css-utilities/font/montserrat/index.scss +1 -1
- package/src/css-utilities/group.scss +1 -2
- package/src/css-utilities/icon.scss +1 -0
- package/src/css-utilities/layer.scss +2 -1
- package/src/css-utilities/skeleton.scss +4 -1
- package/src/css-utilities/surface.scss +97 -108
- package/src/css-utilities/text.scss +13 -13
- package/src/modifiers/background/scss/variables.scss +2 -4
- package/src/modifiers/border/scss/variables.scss +6 -8
- package/src/modifiers/disabled/scss/index.scss +5 -0
- package/src/modifiers/glass/index.ts +2 -1
- package/src/modifiers/glass/scss/index.scss +8 -11
- package/src/modifiers/glass/scss/variables.scss +1 -0
- package/src/modifiers/scrollbar/index.ts +94 -113
- package/src/modifiers/scrollbar/scss/index.scss +20 -2
- package/src/modifiers/scrollbar/scss/variables.scss +2 -2
- package/src/normalize/scss/index.scss +1 -0
- package/src/shared/anchor.ts +1 -1
- package/src/shared/animation.ts +6 -4
- package/src/shared/dispatch.ts +42 -0
- package/src/shared/drag.ts +2 -1
- package/src/shared/press.ts +7 -5
- package/src/shared/resize.ts +4 -35
- package/src/shared/scss/list.scss +1 -2
- package/src/shared/transition.ts +2 -2
- package/src/shared/visible.ts +3 -35
- package/src/tokens/scss/color.scss +16 -20
- package/src/tokens/scss/focus.scss +5 -0
- package/src/tokens/scss/font-size.scss +1 -2
- package/src/tokens/scss/index.scss +1 -0
- package/src/tokens/scss/scale.scss +4 -8
- package/src/tokens/scss/size.scss +3 -3
- package/src/tokens/scss/spacer.scss +1 -1
- package/src/tokens/scss/state.scss +11 -30
- package/vite-env.d.ts +1 -1
- package/vite.config.ts +10 -8
- package/build/components/cc/index.d.ts +0 -30
- package/build/components/cc/index.js +0 -561
- package/build/components/cc/scss/index.scss +0 -2
- package/build/components/datalist/index.d.ts +0 -42
- package/build/components/datalist/index.js +0 -186
- package/build/components/datalist/scss/index.scss +0 -2
- package/build/components/inline-edit/format.d.ts +0 -29
- package/build/components/inline-edit/format.js +0 -112
- package/build/components/inline-edit/history.d.ts +0 -14
- package/build/components/inline-edit/history.js +0 -40
- package/build/components/inline-edit/markdown.d.ts +0 -7
- package/build/components/inline-edit/markdown.js +0 -314
- package/build/components/inline-edit/model.d.ts +0 -61
- package/build/components/inline-edit/model.js +0 -192
- package/build/components/inline-edit/selection.d.ts +0 -7
- package/build/components/inline-edit/selection.js +0 -114
- package/build/components/inline-edit/utilities.d.ts +0 -4
- package/build/components/inline-edit/utilities.js +0 -12
- package/build/components/sticky-header/index.d.ts +0 -2166
- package/build/components/sticky-header/index.js +0 -58
- package/build/components/sticky-header/scss/index.scss +0 -2
- package/build/components/theme-picker/cards.d.ts +0 -13
- package/build/components/theme-picker/cards.js +0 -17
- package/build/components/theme-picker/index.d.ts +0 -12
- package/build/components/theme-picker/index.js +0 -7
- package/build/components/theme-picker/scss/index.scss +0 -2
- package/build/components/theme-picker/swatches.d.ts +0 -13
- package/build/components/theme-picker/swatches.js +0 -17
- package/build/components/theme-picker/toggle.d.ts +0 -19
- package/build/components/theme-picker/toggle.js +0 -109
- package/src/components/cc/index.ts +0 -563
- package/src/components/cc/scss/index.scss +0 -386
- package/src/components/cc/scss/variables.scss +0 -254
- package/src/components/datalist/index.ts +0 -256
- package/src/components/datalist/scss/index.scss +0 -104
- package/src/components/datalist/scss/variables.scss +0 -43
- package/src/components/inline-edit/format.ts +0 -183
- package/src/components/inline-edit/history.ts +0 -71
- package/src/components/inline-edit/markdown.ts +0 -485
- package/src/components/inline-edit/model.ts +0 -366
- package/src/components/inline-edit/selection.ts +0 -188
- package/src/components/inline-edit/utilities.ts +0 -18
- package/src/components/sticky-header/index.ts +0 -78
- package/src/components/sticky-header/scss/index.scss +0 -141
- package/src/components/sticky-header/scss/variables.scss +0 -78
- package/src/components/theme-picker/cards.ts +0 -19
- package/src/components/theme-picker/index.ts +0 -12
- package/src/components/theme-picker/scss/index.scss +0 -174
- package/src/components/theme-picker/scss/variables.scss +0 -220
- package/src/components/theme-picker/swatches.ts +0 -15
- package/src/components/theme-picker/toggle.ts +0 -150
- package/src/components/tooltip/scss/_center.scss +0 -9
- package/src/components/tooltip/scss/_east.scss +0 -33
- package/src/components/tooltip/scss/_menu.scss +0 -325
- package/src/components/tooltip/scss/_north.scss +0 -33
- package/src/components/tooltip/scss/_shared.scss +0 -112
- package/src/components/tooltip/scss/_south.scss +0 -33
- package/src/components/tooltip/scss/_west.scss +0 -33
|
@@ -1,55 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import checkbox from '~/components/checkbox';
|
|
5
|
-
import clipboard from '~/components/clipboard/write';
|
|
1
|
+
import { effect, reactive, read, signal, write } from '@esportsplus/reactivity';
|
|
2
|
+
import { component, html, type Attributes } from '@esportsplus/template';
|
|
3
|
+
import markdown, { type MarkdownController, type MarkdownOptions } from '~/components/editor/markdown';
|
|
6
4
|
import icon from '~/components/icon';
|
|
7
|
-
import input from '~/components/input';
|
|
8
|
-
import selectInput from '~/components/select';
|
|
9
|
-
import tooltip from '~/components/tooltip';
|
|
10
5
|
import { mac } from '~/shared/platform';
|
|
11
|
-
import { observe } from '~/shared/resize';
|
|
12
|
-
import { viewport } from '~/shared/viewport';
|
|
13
|
-
import { active, check, clear, extent, kindAt, link, setKind, toggle, unformat } from './format';
|
|
14
|
-
import history, { type Entry, type Kind as Step } from './history';
|
|
15
|
-
import { parse, serialize, type Feature, type Group } from './markdown';
|
|
16
|
-
import { caret, empty, insert, length, list, nest, order, paste, remove, slice, sort, split, styleAt, text, type Block, type Doc, type Edit, type Kind, type Mark, type Pos, type Selection, type Span, type Tree } from './model';
|
|
17
|
-
import { capture, elements, restore, target, written } from './selection';
|
|
18
6
|
import status, { INLINE_EDIT_STATUS, type Status } from './status';
|
|
19
|
-
import {
|
|
20
|
-
import boldSvg from '@esportsplus/ui/svg/bold.svg';
|
|
7
|
+
import type { Tool } from '~/components/editor/markdown/toolbar';
|
|
21
8
|
import checkSvg from '@esportsplus/ui/svg/check.svg';
|
|
22
|
-
import clearSvg from '@esportsplus/ui/svg/clear-format.svg';
|
|
23
|
-
import closeSvg from '@esportsplus/ui/svg/close.svg';
|
|
24
|
-
import codeSvg from '@esportsplus/ui/svg/code.svg';
|
|
25
|
-
import copySvg from '@esportsplus/ui/svg/copy.svg';
|
|
26
|
-
import highlightSvg from '@esportsplus/ui/svg/highlight.svg';
|
|
27
|
-
import italicSvg from '@esportsplus/ui/svg/italic.svg';
|
|
28
|
-
import linkSvg from '@esportsplus/ui/svg/link.svg';
|
|
29
|
-
import openSvg from '@esportsplus/ui/svg/external-link.svg';
|
|
30
9
|
import pencilSvg from '@esportsplus/ui/svg/pencil.svg';
|
|
31
|
-
import strikeSvg from '@esportsplus/ui/svg/strikethrough.svg';
|
|
32
|
-
import unlinkSvg from '@esportsplus/ui/svg/unlink.svg';
|
|
33
|
-
import '~/components/button/scss/index.scss';
|
|
34
|
-
import '~/components/select/scss/index.scss';
|
|
35
10
|
import './scss/index.scss';
|
|
36
11
|
|
|
37
12
|
|
|
38
13
|
type A = Attributes & {
|
|
39
14
|
[INLINE_EDIT_RICH_EDITOR]?: Attributes;
|
|
40
|
-
[INLINE_EDIT_RICH_TOOLBAR]?: Attributes;
|
|
41
15
|
[INLINE_EDIT_STATUS]?: Attributes;
|
|
42
|
-
// The
|
|
43
|
-
features?:
|
|
16
|
+
// The toolbar's tools; markdown typed or pasted outside them still formats.
|
|
17
|
+
features?: Tool[];
|
|
44
18
|
label: string;
|
|
45
19
|
multiline?: boolean;
|
|
20
|
+
onconnect?: never;
|
|
46
21
|
ondisconnect?: never;
|
|
47
|
-
ondocumentselectionchange?: never;
|
|
48
|
-
onfocusout?: never;
|
|
49
22
|
// A returned promise holds the status at saving until it settles.
|
|
50
23
|
onsave?: (value: string) => unknown;
|
|
51
|
-
onwindowpointercancel?: never;
|
|
52
|
-
onwindowpointerup?: never;
|
|
53
24
|
placeholder?: string;
|
|
54
25
|
state?: State;
|
|
55
26
|
// Shows the save status under the field; pass a Status to read or drive it from outside.
|
|
@@ -57,287 +28,30 @@ type A = Attributes & {
|
|
|
57
28
|
value?: string;
|
|
58
29
|
};
|
|
59
30
|
|
|
60
|
-
type Action = Exclude<Mark, 'link'> | 'clear' | 'copy' | 'link';
|
|
61
|
-
|
|
62
|
-
// Consecutive blocks rendered together: the items of one list, or a run of other blocks.
|
|
63
|
-
type Section = {
|
|
64
|
-
items: ReactiveArray<View>;
|
|
65
|
-
kind: 'block' | 'bullet' | 'ordered' | 'task';
|
|
66
|
-
slot?: { flush(): void };
|
|
67
|
-
};
|
|
68
|
-
|
|
69
31
|
type State = {
|
|
70
32
|
editing: boolean;
|
|
71
33
|
saved: boolean;
|
|
72
34
|
value: string;
|
|
73
35
|
};
|
|
74
36
|
|
|
75
|
-
type Tool = HTMLElement & { [HINT]: Renderable<unknown> };
|
|
76
|
-
|
|
77
|
-
// A rendered block. A checklist box only toggles 'checked', so its own animation plays instead of a new box.
|
|
78
|
-
type View = {
|
|
79
|
-
block: Block;
|
|
80
|
-
checked: Signal<boolean>;
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const URL_SCHEME = /^[a-z][a-z\d+.-]*:/i;
|
|
85
37
|
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
const EMAIL = /^[^\s/@]+@[^\s/@]+\.[^\s/@]+$/;
|
|
89
|
-
|
|
90
|
-
const MAC_SHORTCUT = /(⇧?)(\w)$/;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const ACTIONS: { action: Action, label: string, shortcut?: string }[] = [
|
|
94
|
-
{ action: 'bold', label: 'Bold', shortcut: 'B' },
|
|
95
|
-
{ action: 'italic', label: 'Italic', shortcut: 'I' },
|
|
96
|
-
{ action: 'strike', label: 'Strikethrough', shortcut: 'Shift+X' },
|
|
97
|
-
{ action: 'code', label: 'Code', shortcut: 'E' },
|
|
98
|
-
{ action: 'highlight', label: 'Highlight', shortcut: 'Shift+H' },
|
|
99
|
-
{ action: 'link', label: 'Link', shortcut: 'K' },
|
|
100
|
-
{ action: 'clear', label: 'Clear formatting' },
|
|
101
|
-
{ action: 'copy', label: 'Copy as markdown' }
|
|
102
|
-
];
|
|
103
|
-
|
|
104
|
-
const BASE: Feature[] = ['bold', 'italic', 'link', 'copy'];
|
|
105
|
-
|
|
106
|
-
// Long enough to read the check, short enough to copy again right away.
|
|
107
|
-
const COPIED_FOR = 1400;
|
|
108
|
-
|
|
109
|
-
// The browser's own formatting commands (a menu, a touch bar), as marks.
|
|
110
|
-
const FORMATS: Partial<Record<string, Exclude<Mark, 'link'>>> = {
|
|
111
|
-
formatBold: 'bold',
|
|
112
|
-
formatItalic: 'italic',
|
|
113
|
-
formatStrikeThrough: 'strike'
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
// Space between the selection and the toolbar, and between the toolbar and the viewport edge.
|
|
117
|
-
const GAP = 8;
|
|
118
|
-
|
|
119
|
-
const HINT = Symbol();
|
|
120
|
-
|
|
121
|
-
const ICONS: Record<Exclude<Action, 'copy'> | 'apply' | 'open' | 'unlink', string> = {
|
|
122
|
-
apply: checkSvg,
|
|
123
|
-
bold: boldSvg,
|
|
124
|
-
clear: clearSvg,
|
|
125
|
-
code: codeSvg,
|
|
126
|
-
highlight: highlightSvg,
|
|
127
|
-
italic: italicSvg,
|
|
128
|
-
link: linkSvg,
|
|
129
|
-
open: openSvg,
|
|
130
|
-
strike: strikeSvg,
|
|
131
|
-
unlink: unlinkSvg
|
|
132
|
-
};
|
|
38
|
+
const BASE: Tool[] = ['bold', 'italic', 'link', 'copy'];
|
|
133
39
|
|
|
134
40
|
const INLINE_EDIT_RICH_EDITOR = Symbol.for('@esportsplus/ui/inline-edit.rich.editor');
|
|
135
41
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const KINDS: { feature?: Group, label: string, value: Kind }[] = [
|
|
139
|
-
{ label: 'Text', value: 'paragraph' },
|
|
140
|
-
{ feature: 'heading', label: 'Heading 1', value: 'h1' },
|
|
141
|
-
{ feature: 'heading', label: 'Heading 2', value: 'h2' },
|
|
142
|
-
{ feature: 'heading', label: 'Heading 3', value: 'h3' },
|
|
143
|
-
{ feature: 'quote', label: 'Quote', value: 'quote' },
|
|
144
|
-
{ feature: 'codeblock', label: 'Code block', value: 'codeblock' },
|
|
145
|
-
{ feature: 'bullet', label: 'Bulleted list', value: 'bullet' },
|
|
146
|
-
{ feature: 'ordered', label: 'Numbered list', value: 'ordered' },
|
|
147
|
-
{ feature: 'task', label: 'Checklist', value: 'task' }
|
|
148
|
-
];
|
|
149
|
-
|
|
150
|
-
// Long enough that labels only show once the pointer rests, so passing across the toolbar stays quiet.
|
|
151
|
-
const TOOLTIP_DELAY = 700;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
// What was typed into the link field, as an address: a bare domain gets https, a bare email mailto.
|
|
155
|
-
function address(value: string) {
|
|
156
|
-
let href = value.trim();
|
|
157
|
-
|
|
158
|
-
if (href && !URL_SCHEME.test(href) && !RELATIVE_URL.test(href)) {
|
|
159
|
-
href = (EMAIL.test(href) ? 'mailto:' : 'https://') + href;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return href && safe(href) ? href : '';
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// Where the browser didn't say what a delete covers: a character, a word or a line from the caret, or the break to
|
|
166
|
-
// the next block at the edge of one.
|
|
167
|
-
function around(doc: Doc, pos: Pos, type: string): Span | null {
|
|
168
|
-
let backward = type.includes('Backward'),
|
|
169
|
-
value = text(doc[pos.block].runs),
|
|
170
|
-
to: number;
|
|
171
|
-
|
|
172
|
-
if (backward && pos.offset === 0) {
|
|
173
|
-
return pos.block > 0 ? { end: pos, start: { block: pos.block - 1, offset: length(doc[pos.block - 1].runs) } } : null;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (!backward && pos.offset === value.length) {
|
|
177
|
-
return pos.block < doc.length - 1 ? { end: { block: pos.block + 1, offset: 0 }, start: pos } : null;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (type.includes('Line')) {
|
|
181
|
-
let edge = backward ? value.lastIndexOf('\n', pos.offset - 1) + 1 : value.indexOf('\n', pos.offset);
|
|
182
|
-
|
|
183
|
-
if (edge < 0) {
|
|
184
|
-
edge = value.length;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
to = edge === pos.offset ? pos.offset + (backward ? -1 : 1) : edge;
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
to = boundary(value, pos.offset, backward, type.includes('Word') ? 'word' : 'grapheme');
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
let other = { block: pos.block, offset: to };
|
|
194
|
-
|
|
195
|
-
return backward ? { end: pos, start: other } : { end: other, start: pos };
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function boundary(value: string, offset: number, backward: boolean, granularity: 'grapheme' | 'word') {
|
|
199
|
-
let edge = backward ? 0 : value.length;
|
|
200
|
-
|
|
201
|
-
for (let { index, isWordLike, segment } of new Intl.Segmenter(undefined, { granularity }).segment(value)) {
|
|
202
|
-
let counts = granularity === 'grapheme' || isWordLike;
|
|
203
|
-
|
|
204
|
-
if (backward && index < offset && counts) {
|
|
205
|
-
edge = index;
|
|
206
|
-
}
|
|
207
|
-
else if (!backward && index + segment.length > offset && counts) {
|
|
208
|
-
return Math.max(index + segment.length, offset + 1);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return edge;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function collapsed(span: Span) {
|
|
216
|
-
return span.start.block === span.end.block && span.start.offset === span.end.offset;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Whether 'view' still renders 'next': the same block with the same content. A changed checkbox it takes on itself.
|
|
220
|
-
function follows(view: View, next: Block) {
|
|
221
|
-
if (view.block === next) {
|
|
222
|
-
return true;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (view.block.key !== next.key || view.block.kind !== next.kind || view.block.runs !== next.runs) {
|
|
226
|
-
return false;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
view.block = next;
|
|
230
|
-
write(view.checked, next.checked);
|
|
231
|
-
|
|
232
|
-
return true;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function glyph(action: Exclude<Action, 'copy'> | 'apply' | 'open' | 'unlink') {
|
|
236
|
-
return icon({ 'aria-hidden': 'true', class: 'inline-edit-toolbar-icon' }, ICONS[action]);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function hint(label: string, shortcut?: string) {
|
|
240
|
-
if (!shortcut) {
|
|
241
|
-
return label;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return mac()
|
|
245
|
-
? `${label} ${shortcut.replace('Shift+', '⇧')}`.replace(MAC_SHORTCUT, '$1⌘$2')
|
|
246
|
-
: `${label} Ctrl+${shortcut}`;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// Runs as elements; a line break is a <br>.
|
|
250
|
-
function inline(trees: Tree[]): Renderable<unknown>[] {
|
|
251
|
-
return trees.map((tree) => {
|
|
252
|
-
if ('text' in tree) {
|
|
253
|
-
return lines(tree.text);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
let children = inline(tree.children);
|
|
257
|
-
|
|
258
|
-
switch (tree.mark) {
|
|
259
|
-
case 'bold':
|
|
260
|
-
return html`<strong>${children}</strong>`;
|
|
261
|
-
case 'code':
|
|
262
|
-
return html`<code>${children}</code>`;
|
|
263
|
-
case 'highlight':
|
|
264
|
-
return html`<mark>${children}</mark>`;
|
|
265
|
-
case 'italic':
|
|
266
|
-
return html`<em>${children}</em>`;
|
|
267
|
-
case 'link':
|
|
268
|
-
return html`<a href='${tree.href}'>${children}</a>`;
|
|
269
|
-
default:
|
|
270
|
-
return html`<s>${children}</s>`;
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
function lines(value: string) {
|
|
276
|
-
let out: Renderable<unknown>[] = [],
|
|
277
|
-
parts = value.split('\n');
|
|
278
|
-
|
|
279
|
-
for (let i = 0, n = parts.length; i < n; i++) {
|
|
280
|
-
if (i > 0) {
|
|
281
|
-
out.push(html`<br>`);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
if (parts[i]) {
|
|
285
|
-
out.push(parts[i]);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
return out;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
function partition(doc: Doc) {
|
|
293
|
-
let out: { blocks: Block[], kind: Section['kind'] }[] = [];
|
|
294
|
-
|
|
295
|
-
for (let i = 0, n = doc.length; i < n; i++) {
|
|
296
|
-
let kind = (list(doc[i].kind) ? doc[i].kind : 'block') as Section['kind'],
|
|
297
|
-
last = out[out.length - 1];
|
|
298
|
-
|
|
299
|
-
if (last && last.kind === kind) {
|
|
300
|
-
last.blocks.push(doc[i]);
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
out.push({ blocks: [doc[i]], kind });
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
return out;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
// Where 'pos' lands once 'span' is deleted; 'pos' is outside it.
|
|
311
|
-
function shift(pos: Pos, { end, start }: Span): Pos {
|
|
312
|
-
if (pos.block < end.block || (pos.block === end.block && pos.offset <= end.offset)) {
|
|
313
|
-
return pos;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
if (pos.block === end.block) {
|
|
317
|
-
return { block: start.block, offset: start.offset + pos.offset - end.offset };
|
|
318
|
-
}
|
|
42
|
+
// Mod+Enter saves here, so the editor's own binding for it (a blank line) is off.
|
|
43
|
+
const KEYBINDINGS = { 'Mod+Enter': null };
|
|
319
44
|
|
|
320
|
-
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
function spans(a: Span | null, b: Span) {
|
|
324
|
-
return !!a
|
|
325
|
-
&& a.start.block === b.start.block
|
|
326
|
-
&& a.start.offset === b.start.offset
|
|
327
|
-
&& a.end.block === b.end.block
|
|
328
|
-
&& a.end.offset === b.end.offset;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
function view(block: Block): View {
|
|
332
|
-
return { block, checked: signal(block.checked) };
|
|
333
|
-
}
|
|
45
|
+
const SPACES = /\s+/g;
|
|
334
46
|
|
|
335
47
|
|
|
48
|
+
// The markdown editor in its inline mode: it rests as text, edits in place with the formatting toolbar over a
|
|
49
|
+
// selection, and saves when focus leaves, on Enter for one line or Mod+Enter for several; Escape puts the text back.
|
|
336
50
|
export default component(
|
|
337
51
|
function(
|
|
338
|
-
this: { attributes?: Pick<A, typeof INLINE_EDIT_RICH_EDITOR | typeof
|
|
52
|
+
this: { attributes?: Pick<A, typeof INLINE_EDIT_RICH_EDITOR | typeof INLINE_EDIT_STATUS> } | void,
|
|
339
53
|
{
|
|
340
|
-
features
|
|
54
|
+
features = BASE,
|
|
341
55
|
label,
|
|
342
56
|
multiline = false,
|
|
343
57
|
onsave,
|
|
@@ -348,1173 +62,144 @@ export default component(
|
|
|
348
62
|
...attributes
|
|
349
63
|
}: A
|
|
350
64
|
) {
|
|
351
|
-
let
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
// Declared so page-wide shortcuts (a command palette on Mod+K) leave these to the text.
|
|
357
|
-
keyshortcuts = actions
|
|
358
|
-
.flatMap(({ shortcut }) => shortcut ? ['Control', 'Meta'].map((mod) => `${mod}+${shortcut}`) : [])
|
|
359
|
-
.concat(multiline ? ['Control+Enter', 'Meta+Enter'] : [])
|
|
360
|
-
.join(' '),
|
|
361
|
-
kinds = KINDS.filter((k) => !k.feature || features.has(k.feature)),
|
|
362
|
-
// 'focus' is the format control the arrow keys rove to, the toolbar's one tab stop.
|
|
363
|
-
local = reactive({ copied: 'idle' as 'error' | 'idle' | 'success', focus: 0, live: '' }),
|
|
364
|
-
marks = actions.filter(({ action }) => action !== 'clear' && action !== 'copy'),
|
|
365
|
-
// The toolbar: 'link' swaps its buttons for the link field, 'instant' holds its moves still, 'origin' and
|
|
366
|
-
// 'x'/'y' place it over the selection.
|
|
367
|
-
panel = reactive({ instant: false, link: false, open: false, origin: '', x: 0, y: 0 }),
|
|
368
|
-
// Mark buttons by their mark, pressed while the selection carries it.
|
|
369
|
-
pressed = reactive(Object.fromEntries(marks.map(({ action }) => [action, false])) as Record<string, boolean>),
|
|
370
|
-
// The saved value as this field writes it, which a value from outside may not be: what an edit differs from.
|
|
371
|
-
pristine = signal(serialize(read(doc), features, multiline)),
|
|
372
|
-
saving = status.saver(state, indicator, () => serialize(read(doc), features, multiline) !== read(pristine), onsave),
|
|
373
|
-
sections = new ReactiveArray<Section>(partition(read(doc)).map(section)),
|
|
374
|
-
slot = html.reactive(sections, group),
|
|
375
|
-
steps = history(),
|
|
376
|
-
tip = tooltip.shared({ delay: { open: TOOLTIP_DELAY } });
|
|
377
|
-
|
|
378
|
-
let composing: { block: number, element: HTMLElement } | null = null,
|
|
379
|
-
copyTimer: ReturnType<typeof setTimeout> | undefined,
|
|
380
|
-
dismissed = false,
|
|
381
|
-
// A drag from inside the text: what it moves, until the drop lands it.
|
|
382
|
-
dragged: Span | null = null,
|
|
383
|
-
editor: HTMLElement | undefined,
|
|
384
|
-
frame = 0,
|
|
385
|
-
items: HTMLElement[] = [],
|
|
386
|
-
keys: AbortController | undefined,
|
|
387
|
-
pressing = false,
|
|
65
|
+
let apple = mac(),
|
|
66
|
+
controller: MarkdownController | undefined,
|
|
67
|
+
current = signal(state.value),
|
|
68
|
+
// The saved value as this field holds it: what an edit differs from.
|
|
69
|
+
pristine = signal(state.value),
|
|
388
70
|
root: HTMLElement | undefined,
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
if (next !== shown) {
|
|
402
|
-
untrack(() => turn(next));
|
|
403
|
-
}
|
|
404
|
-
});
|
|
71
|
+
saving = status.saver(state, indicator, () => clean(read(current)) !== read(pristine), onsave),
|
|
72
|
+
defaults = this?.attributes?.[INLINE_EDIT_RICH_EDITOR],
|
|
73
|
+
own = attributes[INLINE_EDIT_RICH_EDITOR],
|
|
74
|
+
options: MarkdownOptions = {
|
|
75
|
+
inline: true,
|
|
76
|
+
keybindings: KEYBINDINGS,
|
|
77
|
+
label,
|
|
78
|
+
placeholder,
|
|
79
|
+
singleLine: !multiline,
|
|
80
|
+
toolbar: features
|
|
81
|
+
};
|
|
405
82
|
|
|
406
83
|
// A value set from outside while the field rests shows at once.
|
|
407
84
|
effect(() => state.value, (next, previous) => {
|
|
408
85
|
if (previous !== undefined && !state.editing && next !== read(pristine)) {
|
|
409
|
-
|
|
86
|
+
write(pristine, next);
|
|
87
|
+
controller?.setValue(next);
|
|
410
88
|
}
|
|
411
89
|
});
|
|
412
90
|
|
|
413
|
-
function
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
if (!editor || !span) {
|
|
417
|
-
return;
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
if (href !== null) {
|
|
421
|
-
href = address(href);
|
|
422
|
-
|
|
423
|
-
if (!href) {
|
|
424
|
-
hyperlink.invalid = true;
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
back();
|
|
430
|
-
change(link(read(doc), span, href), 'other');
|
|
431
|
-
local.live = href ? 'Link set' : 'Link removed';
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
// Leaves the link field for the buttons, handing focus and the selection back to the text.
|
|
435
|
-
function back() {
|
|
436
|
-
panel.link = false;
|
|
437
|
-
editor?.focus({ preventScroll: true });
|
|
438
|
-
|
|
439
|
-
let span = current();
|
|
440
|
-
|
|
441
|
-
if (span) {
|
|
442
|
-
select({ anchor: span.start, focus: span.end });
|
|
443
|
-
|
|
444
|
-
let range = live();
|
|
445
|
-
|
|
446
|
-
if (range) {
|
|
447
|
-
place(range);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
// Records the change for undo, renders it and puts the selection where it leaves off.
|
|
453
|
-
function change(edit: Edit, kind: Step) {
|
|
454
|
-
steps.push({ doc: read(doc), selection }, edit.selection, kind);
|
|
455
|
-
commit(edit.doc);
|
|
456
|
-
select(edit.selection);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
// Copies carry markdown, so a paste back in keeps the formatting.
|
|
460
|
-
function clip(e: ClipboardEvent, cut: boolean) {
|
|
461
|
-
let range = live(),
|
|
462
|
-
now = editor ? capture(editor) : null;
|
|
463
|
-
|
|
464
|
-
if (!range || range.collapsed || !now || !e.clipboardData) {
|
|
465
|
-
return;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
let holder = document.createElement('div'),
|
|
469
|
-
span = order(now);
|
|
470
|
-
|
|
471
|
-
holder.append(range.cloneContents());
|
|
472
|
-
e.preventDefault();
|
|
473
|
-
e.clipboardData.setData('text/html', holder.innerHTML);
|
|
474
|
-
e.clipboardData.setData('text/plain', serialize(excerpt(span), features, multiline));
|
|
475
|
-
|
|
476
|
-
if (cut) {
|
|
477
|
-
change(remove(read(doc), span), 'other');
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
// The DOM follows the model: each section's items are patched by block identity, so only blocks that changed
|
|
482
|
-
// render again, and the slots land it before the selection is placed.
|
|
483
|
-
function commit(next: Doc) {
|
|
484
|
-
write(doc, next);
|
|
485
|
-
|
|
486
|
-
let parts = partition(next),
|
|
487
|
-
end = 0,
|
|
488
|
-
m = parts.length,
|
|
489
|
-
n = sections.length,
|
|
490
|
-
start = 0;
|
|
491
|
-
|
|
492
|
-
while (start < n && start < m && sections[start].kind === parts[start].kind) {
|
|
493
|
-
patch(sections[start].items, parts[start].blocks);
|
|
494
|
-
start++;
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
while (end < n - start && end < m - start && sections[n - 1 - end].kind === parts[m - 1 - end].kind) {
|
|
498
|
-
patch(sections[n - 1 - end].items, parts[m - 1 - end].blocks);
|
|
499
|
-
end++;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
if (start + end < n || start + end < m) {
|
|
503
|
-
sections.splice(start, n - start - end, ...parts.slice(start, m - end).map(section));
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
slot.flush();
|
|
507
|
-
|
|
508
|
-
for (let i = 0, o = sections.length; i < o; i++) {
|
|
509
|
-
sections[i].slot?.flush();
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
flush();
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
async function copy() {
|
|
516
|
-
let span = current();
|
|
517
|
-
|
|
518
|
-
if (!span) {
|
|
519
|
-
return;
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
// Confirms on press; waiting for the write makes the click feel ignored.
|
|
523
|
-
clearTimeout(copyTimer);
|
|
524
|
-
local.copied = 'success';
|
|
525
|
-
local.live = 'Copied';
|
|
526
|
-
copyTimer = setTimeout(() => {
|
|
527
|
-
local.copied = 'idle';
|
|
528
|
-
}, COPIED_FOR);
|
|
529
|
-
|
|
530
|
-
if (!(await clipboard(serialize(excerpt(span), features, multiline)))) {
|
|
531
|
-
local.copied = 'error';
|
|
532
|
-
local.live = 'Couldn\'t copy';
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
function current() {
|
|
537
|
-
let blocks = read(doc);
|
|
538
|
-
|
|
539
|
-
if (!saved || collapsed(saved) || !blocks[saved.end.block]) {
|
|
540
|
-
return null;
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
return saved;
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
function dismiss() {
|
|
547
|
-
dismissed = true;
|
|
548
|
-
show(false);
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
// A drop from inside the text moves what was dragged; one from elsewhere pastes.
|
|
552
|
-
function drop(e: InputEvent, at: Span) {
|
|
553
|
-
let from = dragged;
|
|
554
|
-
|
|
555
|
-
dragged = null;
|
|
556
|
-
|
|
557
|
-
if (!from) {
|
|
558
|
-
land(at, e.dataTransfer?.getData('text/plain') ?? '');
|
|
559
|
-
return;
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
let pos = at.start,
|
|
563
|
-
inside = (pos.block > from.start.block || (pos.block === from.start.block && pos.offset >= from.start.offset))
|
|
564
|
-
&& (pos.block < from.end.block || (pos.block === from.end.block && pos.offset <= from.end.offset));
|
|
565
|
-
|
|
566
|
-
if (inside) {
|
|
567
|
-
return;
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
let moved = excerpt(from),
|
|
571
|
-
rest = remove(read(doc), from).doc,
|
|
572
|
-
to = shift(pos, from);
|
|
573
|
-
|
|
574
|
-
change(paste(rest, { end: to, start: to }, moved), 'other');
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
// Turns each kind of input into a change to the model. The browser never edits the DOM itself; an input
|
|
578
|
-
// method does, and composition ends by reading back what it wrote.
|
|
579
|
-
function edit(e: InputEvent) {
|
|
580
|
-
let type = e.inputType;
|
|
581
|
-
|
|
582
|
-
if (e.isComposing || type === 'insertCompositionText' || type === 'deleteCompositionText' || type === 'insertFromComposition') {
|
|
583
|
-
return;
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
e.preventDefault();
|
|
587
|
-
resolve();
|
|
588
|
-
|
|
589
|
-
if (!editor) {
|
|
590
|
-
return;
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
let now = capture(editor),
|
|
594
|
-
range = e.getTargetRanges()[0],
|
|
595
|
-
span = (range && target(editor, range)) || (now && order(now));
|
|
596
|
-
|
|
597
|
-
if (!span) {
|
|
598
|
-
return;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
let format = FORMATS[type];
|
|
602
|
-
|
|
603
|
-
if (format) {
|
|
604
|
-
if (features.has(format) && !collapsed(span)) {
|
|
605
|
-
change(toggle(read(doc), span, format), 'other');
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
return;
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
switch (type) {
|
|
612
|
-
case 'deleteByDrag':
|
|
613
|
-
dragged = span;
|
|
614
|
-
return;
|
|
615
|
-
case 'formatRemove':
|
|
616
|
-
if (features.has('clear') && !collapsed(span)) {
|
|
617
|
-
change(clear(read(doc), span), 'other');
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
return;
|
|
621
|
-
case 'historyRedo':
|
|
622
|
-
redo();
|
|
623
|
-
return;
|
|
624
|
-
case 'historyUndo':
|
|
625
|
-
undo();
|
|
626
|
-
return;
|
|
627
|
-
case 'insertFromDrop':
|
|
628
|
-
drop(e, span);
|
|
629
|
-
return;
|
|
630
|
-
case 'insertFromPaste':
|
|
631
|
-
land(span, e.dataTransfer?.getData('text/plain') ?? '');
|
|
632
|
-
return;
|
|
633
|
-
case 'insertLineBreak':
|
|
634
|
-
case 'insertParagraph':
|
|
635
|
-
if (!multiline) {
|
|
636
|
-
finish(true, true);
|
|
637
|
-
}
|
|
638
|
-
else if (type === 'insertParagraph') {
|
|
639
|
-
change(split(read(doc), span), 'other');
|
|
640
|
-
}
|
|
641
|
-
else {
|
|
642
|
-
typed(span, '\n');
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
return;
|
|
646
|
-
case 'insertOrderedList':
|
|
647
|
-
case 'insertUnorderedList': {
|
|
648
|
-
let kind: Kind = type === 'insertOrderedList' ? 'ordered' : 'bullet';
|
|
649
|
-
|
|
650
|
-
if (features.has(kind as Group)) {
|
|
651
|
-
change(setKind(read(doc), span, kind), 'other');
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
return;
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
if (type.startsWith('insert')) {
|
|
659
|
-
typed(span, e.data ?? e.dataTransfer?.getData('text/plain') ?? '');
|
|
660
|
-
}
|
|
661
|
-
else if (type.startsWith('delete')) {
|
|
662
|
-
erase(type, span, now);
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
function erase(type: string, span: Span, now: Selection | null) {
|
|
667
|
-
let blocks = read(doc),
|
|
668
|
-
at = now && now.anchor.block === now.focus.block && now.anchor.offset === now.focus.offset ? now.focus : null;
|
|
669
|
-
|
|
670
|
-
if (type === 'deleteContentBackward' && at?.offset === 0) {
|
|
671
|
-
let next = unformat(blocks, at.block);
|
|
672
|
-
|
|
673
|
-
if (next) {
|
|
674
|
-
change(next, 'other');
|
|
675
|
-
return;
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
let reach = collapsed(span) && at ? around(blocks, at, type) : span;
|
|
680
|
-
|
|
681
|
-
if (reach && !collapsed(reach)) {
|
|
682
|
-
change(remove(blocks, reach), type === 'deleteByCut' ? 'other' : 'delete');
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
// What a copy takes: within one block just its text, across several the blocks as they are.
|
|
687
|
-
function excerpt(span: Span) {
|
|
688
|
-
let part = slice(read(doc), span);
|
|
689
|
-
|
|
690
|
-
if (part.length === 1) {
|
|
691
|
-
part[0] = { ...part[0], checked: false, kind: 'paragraph' };
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
return part;
|
|
91
|
+
function clean(text: string) {
|
|
92
|
+
return multiline ? text.trim() : text.replace(SPACES, ' ').trim();
|
|
695
93
|
}
|
|
696
94
|
|
|
697
95
|
function finish(commit: boolean, keyboard: boolean) {
|
|
698
|
-
if (!
|
|
96
|
+
if (!state.editing || !controller) {
|
|
699
97
|
return;
|
|
700
98
|
}
|
|
701
99
|
|
|
702
|
-
resolve();
|
|
703
100
|
state.editing = false;
|
|
704
|
-
panel.link = false;
|
|
705
|
-
show(false);
|
|
706
101
|
|
|
707
102
|
if (commit) {
|
|
708
103
|
save();
|
|
709
104
|
}
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
load(state.value);
|
|
713
|
-
|
|
714
|
-
if (keyboard) {
|
|
715
|
-
editor.blur();
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
function focus(index: number) {
|
|
720
|
-
local.focus = (index + items.length) % items.length;
|
|
721
|
-
items[local.focus]?.focus();
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
function group(section: Section) {
|
|
725
|
-
let slot = html.reactive(section.items, item);
|
|
726
|
-
|
|
727
|
-
section.slot = slot;
|
|
728
|
-
|
|
729
|
-
switch (section.kind) {
|
|
730
|
-
case 'bullet':
|
|
731
|
-
return html`<ul>${slot}</ul>`;
|
|
732
|
-
case 'ordered':
|
|
733
|
-
return html`<ol>${slot}</ol>`;
|
|
734
|
-
case 'task':
|
|
735
|
-
return html`<ul data-task>${slot}</ul>`;
|
|
736
|
-
default:
|
|
737
|
-
return html`${slot}`;
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
// Inspects the selection for the toolbar: which marks it carries, and the kind of block it starts in.
|
|
742
|
-
function inspect(span: Span) {
|
|
743
|
-
let blocks = read(doc);
|
|
744
|
-
|
|
745
|
-
for (let i = 0, n = marks.length; i < n; i++) {
|
|
746
|
-
let mark = marks[i].action as Mark;
|
|
747
|
-
|
|
748
|
-
pressed[mark] = active(blocks, span, mark);
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
shown = kindAt(blocks, span);
|
|
752
|
-
block.selected = shown;
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
function item(view: View) {
|
|
756
|
-
let { kind, runs } = view.block,
|
|
757
|
-
characters = text(runs),
|
|
758
|
-
body = [inline(nest(runs)), (!characters || characters.endsWith('\n')) && html`<br data-filler>`];
|
|
759
|
-
|
|
760
|
-
switch (kind) {
|
|
761
|
-
case 'bullet':
|
|
762
|
-
case 'ordered':
|
|
763
|
-
return html`<li data-block>${body}</li>`;
|
|
764
|
-
case 'codeblock':
|
|
765
|
-
return html`<pre data-block>${body}</pre>`;
|
|
766
|
-
case 'h1':
|
|
767
|
-
return html`<h1 data-block>${body}</h1>`;
|
|
768
|
-
case 'h2':
|
|
769
|
-
return html`<h2 data-block>${body}</h2>`;
|
|
770
|
-
case 'h3':
|
|
771
|
-
return html`<h3 data-block>${body}</h3>`;
|
|
772
|
-
case 'quote':
|
|
773
|
-
return html`<blockquote data-block>${body}</blockquote>`;
|
|
774
|
-
case 'task':
|
|
775
|
-
return html`
|
|
776
|
-
<li data-block ${{ 'data-checked': () => read(view.checked) ? 'true' : 'false' }}>
|
|
777
|
-
<span class='inline-edit-task' contenteditable='false'>
|
|
778
|
-
${checkbox({
|
|
779
|
-
[checkbox.input]: {
|
|
780
|
-
'aria-label': 'Done',
|
|
781
|
-
checked: () => read(view.checked),
|
|
782
|
-
onchange: (e: Event) => tick(view, (e.currentTarget as HTMLInputElement).checked)
|
|
783
|
-
}
|
|
784
|
-
})}
|
|
785
|
-
</span>
|
|
786
|
-
${body}
|
|
787
|
-
</li>
|
|
788
|
-
`;
|
|
789
|
-
default:
|
|
790
|
-
return html`<p data-block>${body}</p>`;
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
// Markdown lands as formatting, taking on the style at the caret; inside code it stays as typed.
|
|
795
|
-
function land(span: Span, value: string) {
|
|
796
|
-
if (!value) {
|
|
797
|
-
return;
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
let blocks = read(doc),
|
|
801
|
-
host = blocks[span.start.block],
|
|
802
|
-
style = styleAt(host.runs, span.start.offset);
|
|
803
|
-
|
|
804
|
-
if (host.kind === 'codeblock' || style.marks.includes('code')) {
|
|
805
|
-
change(insert(blocks, span, [{ ...style, text: host.kind === 'codeblock' ? value : value.replace(INLINE_LINE_BREAKS, ' ') }]), 'other');
|
|
806
|
-
return;
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
let pasted = parse(value, features, multiline && value.includes('\n'));
|
|
810
|
-
|
|
811
|
-
if (pasted.length === 1 && pasted[0].kind === 'paragraph') {
|
|
812
|
-
if (!pasted[0].runs.length) {
|
|
813
|
-
return;
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
pasted[0] = {
|
|
817
|
-
...pasted[0],
|
|
818
|
-
runs: pasted[0].runs.map((run) => ({ href: run.href || style.href, marks: sort([...style.marks, ...run.marks]), text: run.text }))
|
|
819
|
-
};
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
change(paste(blocks, span, pasted), 'other');
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
function leave(e: FocusEvent) {
|
|
826
|
-
// Focus moving between the text and the toolbar stays in the edit.
|
|
827
|
-
if (!root?.contains(e.relatedTarget as Node | null)) {
|
|
828
|
-
finish(true, false);
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
// Swaps the buttons for the link field, prefilled when the selection sits in a link.
|
|
833
|
-
function linker() {
|
|
834
|
-
let span = current();
|
|
835
|
-
|
|
836
|
-
if (!editor || !span || !toolbar || !url) {
|
|
837
|
-
return;
|
|
105
|
+
else {
|
|
106
|
+
controller.setValue(read(pristine));
|
|
838
107
|
}
|
|
839
108
|
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
if (found) {
|
|
843
|
-
saved = found.span;
|
|
844
|
-
select({ anchor: found.span.start, focus: found.span.end });
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
panel.link = true;
|
|
848
|
-
hyperlink.existing = !!found;
|
|
849
|
-
hyperlink.invalid = false;
|
|
850
|
-
hyperlink.url = found?.href ?? '';
|
|
851
|
-
|
|
852
|
-
let range = live();
|
|
853
|
-
|
|
854
|
-
if (range) {
|
|
855
|
-
place(range);
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
// The field shows, and takes its value, once the link mode lands.
|
|
859
|
-
flush();
|
|
860
|
-
url.focus({ preventScroll: true });
|
|
861
|
-
url.select();
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
function live() {
|
|
865
|
-
let native = window.getSelection();
|
|
866
|
-
|
|
867
|
-
return native && native.rangeCount > 0 ? native.getRangeAt(0) : null;
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
// A fresh document from markdown, with nothing to undo.
|
|
871
|
-
function load(markdown: string) {
|
|
872
|
-
let next = parse(markdown, features, multiline);
|
|
873
|
-
|
|
874
|
-
steps.clear();
|
|
875
|
-
write(pristine, serialize(next, features, multiline));
|
|
876
|
-
commit(next);
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
function navigate(e: KeyboardEvent) {
|
|
880
|
-
if (e.target === url) {
|
|
881
|
-
if (e.key === 'Enter') {
|
|
882
|
-
e.preventDefault();
|
|
883
|
-
apply(url.value);
|
|
884
|
-
}
|
|
885
|
-
else if (e.key === 'Escape') {
|
|
886
|
-
e.preventDefault();
|
|
887
|
-
back();
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
return;
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
|
|
894
|
-
e.preventDefault();
|
|
895
|
-
focus(local.focus + (e.key === 'ArrowRight' ? 1 : -1));
|
|
896
|
-
}
|
|
897
|
-
else if (e.key === 'Home' || e.key === 'End') {
|
|
898
|
-
e.preventDefault();
|
|
899
|
-
focus(e.key === 'Home' ? 0 : -1);
|
|
900
|
-
}
|
|
901
|
-
else if (e.key === 'Escape' && !block.active) {
|
|
902
|
-
e.preventDefault();
|
|
903
|
-
dismiss();
|
|
904
|
-
editor?.focus({ preventScroll: true });
|
|
905
|
-
|
|
906
|
-
let span = current();
|
|
109
|
+
if (keyboard) {
|
|
110
|
+
let active = root?.ownerDocument.activeElement;
|
|
907
111
|
|
|
908
|
-
if (
|
|
909
|
-
|
|
112
|
+
if (active instanceof HTMLElement && root?.contains(active)) {
|
|
113
|
+
active.blur();
|
|
910
114
|
}
|
|
911
115
|
}
|
|
912
116
|
}
|
|
913
117
|
|
|
914
|
-
// Only the blocks that differ from what is rendered render again; a box ticked or unticked just follows.
|
|
915
|
-
function patch(items: ReactiveArray<View>, next: Block[]) {
|
|
916
|
-
let end = 0,
|
|
917
|
-
m = next.length,
|
|
918
|
-
n = items.length,
|
|
919
|
-
start = 0;
|
|
920
|
-
|
|
921
|
-
while (start < n && start < m && follows(items[start], next[start])) {
|
|
922
|
-
start++;
|
|
923
|
-
}
|
|
924
|
-
|
|
925
|
-
while (end < n - start && end < m - start && follows(items[n - 1 - end], next[m - 1 - end])) {
|
|
926
|
-
end++;
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
if (start + end < n || start + end < m) {
|
|
930
|
-
items.splice(start, n - start - end, ...next.slice(start, m - end).map(view));
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
function place(range: Range) {
|
|
935
|
-
if (!root || !toolbar) {
|
|
936
|
-
return;
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
let bounds = range.getBoundingClientRect(),
|
|
940
|
-
box = root.getBoundingClientRect(),
|
|
941
|
-
h = toolbar.offsetHeight,
|
|
942
|
-
lines = [...range.getClientRects()].filter((rect) => rect.width > 0),
|
|
943
|
-
w = toolbar.offsetWidth;
|
|
944
|
-
|
|
945
|
-
let first = lines[0] ?? bounds,
|
|
946
|
-
last = lines[lines.length - 1] ?? bounds;
|
|
947
|
-
|
|
948
|
-
// Floats outside the field, so only the viewport limits it: flips below when there's no room above.
|
|
949
|
-
let below = first.top < h + GAP,
|
|
950
|
-
center = bounds.left + bounds.width / 2,
|
|
951
|
-
x = Math.min(Math.max(center - w / 2, GAP), viewport().width - w - GAP);
|
|
952
|
-
|
|
953
|
-
// Scales out of the selection itself, even when clamped to the edge.
|
|
954
|
-
panel.origin = `${center - x}px ${below ? 0 : h}px`;
|
|
955
|
-
panel.x = x - box.left;
|
|
956
|
-
panel.y = below ? last.bottom - box.top + GAP : first.top - box.top - h - GAP;
|
|
957
|
-
|
|
958
|
-
// Shown afresh it jumps there, committed before its moves glide again; once open it glides along.
|
|
959
|
-
if (!panel.open) {
|
|
960
|
-
panel.instant = true;
|
|
961
|
-
flush();
|
|
962
|
-
void toolbar.offsetWidth;
|
|
963
|
-
panel.instant = false;
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
function redo() {
|
|
968
|
-
let entry = steps.redo({ doc: read(doc), selection });
|
|
969
|
-
|
|
970
|
-
if (entry) {
|
|
971
|
-
revert(entry);
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
// Ends a composition: the text the input method wrote replaces the model's, and the block renders again so
|
|
976
|
-
// none of the nodes it made stay behind.
|
|
977
|
-
function resolve() {
|
|
978
|
-
clearTimeout(settling);
|
|
979
|
-
|
|
980
|
-
if (!composing || !editor) {
|
|
981
|
-
return;
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
let { block: i, element } = composing,
|
|
985
|
-
blocks = read(doc);
|
|
986
|
-
|
|
987
|
-
composing = null;
|
|
988
|
-
|
|
989
|
-
if (!blocks[i] || !element.isConnected) {
|
|
990
|
-
sections.splice(0, sections.length, ...partition(blocks).map(section));
|
|
991
|
-
commit(blocks);
|
|
992
|
-
return;
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
let after = written(element),
|
|
996
|
-
before = text(blocks[i].runs),
|
|
997
|
-
end = 0,
|
|
998
|
-
now = capture(editor),
|
|
999
|
-
start = 0;
|
|
1000
|
-
|
|
1001
|
-
while (start < before.length && start < after.length && before[start] === after[start]) {
|
|
1002
|
-
start++;
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
while (end < before.length - start && end < after.length - start && before[before.length - 1 - end] === after[after.length - 1 - end]) {
|
|
1006
|
-
end++;
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
let next = insert(
|
|
1010
|
-
blocks,
|
|
1011
|
-
{ end: { block: i, offset: before.length - end }, start: { block: i, offset: start } },
|
|
1012
|
-
[{ ...styleAt(blocks[i].runs, start), text: after.slice(start, after.length - end) }]
|
|
1013
|
-
),
|
|
1014
|
-
at = now && now.focus.block === i ? now.focus : next.selection.focus;
|
|
1015
|
-
|
|
1016
|
-
next.doc[i] = { ...next.doc[i], runs: next.doc[i].runs.slice() };
|
|
1017
|
-
|
|
1018
|
-
if (before === after) {
|
|
1019
|
-
commit(next.doc);
|
|
1020
|
-
select(caret(at));
|
|
1021
|
-
return;
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
change({ doc: next.doc, selection: caret(at) }, 'type');
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
function revert(entry: Entry) {
|
|
1028
|
-
commit(entry.doc);
|
|
1029
|
-
|
|
1030
|
-
if (entry.selection) {
|
|
1031
|
-
select(entry.selection);
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
118
|
function save() {
|
|
1036
|
-
let next =
|
|
119
|
+
let next = clean(read(current));
|
|
1037
120
|
|
|
1038
121
|
if (next === read(pristine)) {
|
|
1039
122
|
return;
|
|
1040
123
|
}
|
|
1041
124
|
|
|
1042
125
|
write(pristine, next);
|
|
1043
|
-
saving.save(next);
|
|
1044
|
-
}
|
|
1045
|
-
|
|
1046
|
-
function section({ blocks, kind }: { blocks: Block[], kind: Section['kind'] }): Section {
|
|
1047
|
-
return { items: new ReactiveArray<View>(blocks.map(view)), kind };
|
|
1048
|
-
}
|
|
1049
|
-
|
|
1050
|
-
function select(next: Selection) {
|
|
1051
|
-
selection = next;
|
|
1052
|
-
|
|
1053
|
-
if (editor && document.activeElement === editor) {
|
|
1054
|
-
restore(editor, next);
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
// The selection finalises after pointerup, so it is read a frame later.
|
|
1059
|
-
function settle() {
|
|
1060
|
-
if (!pressing) {
|
|
1061
|
-
return;
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
pressing = false;
|
|
1065
|
-
cancelAnimationFrame(frame);
|
|
1066
|
-
frame = requestAnimationFrame(sync);
|
|
1067
|
-
}
|
|
1068
|
-
|
|
1069
|
-
function show(next: boolean, instant = false) {
|
|
1070
|
-
panel.open = next;
|
|
1071
|
-
|
|
1072
|
-
if (instant) {
|
|
1073
|
-
panel.instant = true;
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
function sync() {
|
|
1078
|
-
if (!editor || !toolbar) {
|
|
1079
|
-
return;
|
|
1080
|
-
}
|
|
1081
126
|
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
if (now) {
|
|
1085
|
-
selection = now;
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
if (composing || (!actions.length && kinds.length < 2)) {
|
|
1089
|
-
return;
|
|
1090
|
-
}
|
|
1091
|
-
|
|
1092
|
-
let range = live();
|
|
1093
|
-
|
|
1094
|
-
// Focus in the toolbar (its buttons, the select, the link field) keeps it where it is.
|
|
1095
|
-
if (toolbar.contains(document.activeElement) || panel.link) {
|
|
1096
|
-
return;
|
|
1097
|
-
}
|
|
1098
|
-
|
|
1099
|
-
if (!now || !range || range.collapsed || !editor.contains(range.commonAncestorContainer)) {
|
|
1100
|
-
if (panel.open) {
|
|
1101
|
-
show(false);
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
return;
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1107
|
-
// A drag in progress settles on release, so the toolbar doesn't chase every pixel.
|
|
1108
|
-
if (pressing) {
|
|
1109
|
-
return;
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
let span = order(now);
|
|
1113
|
-
|
|
1114
|
-
if (dismissed) {
|
|
1115
|
-
if (spans(saved, span)) {
|
|
1116
|
-
return;
|
|
1117
|
-
}
|
|
1118
|
-
|
|
1119
|
-
dismissed = false;
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
|
-
saved = span;
|
|
1123
|
-
place(range);
|
|
1124
|
-
inspect(span);
|
|
1125
|
-
|
|
1126
|
-
if (!panel.open) {
|
|
1127
|
-
local.focus = 0;
|
|
1128
|
-
show(true);
|
|
1129
|
-
}
|
|
1130
|
-
}
|
|
1131
|
-
|
|
1132
|
-
// Ticked without editing, it saves at once; mid-edit it goes with the rest.
|
|
1133
|
-
function tick(view: View, value: boolean) {
|
|
1134
|
-
let blocks = read(doc),
|
|
1135
|
-
index = blocks.findIndex((b) => b.key === view.block.key);
|
|
1136
|
-
|
|
1137
|
-
if (index < 0) {
|
|
1138
|
-
return;
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
change({ doc: check(blocks, index, value), selection: selection ?? caret({ block: index, offset: 0 }) }, 'other');
|
|
1142
|
-
|
|
1143
|
-
if (!state.editing) {
|
|
1144
|
-
save();
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
|
-
function trigger(action: Action) {
|
|
1149
|
-
let span = current();
|
|
1150
|
-
|
|
1151
|
-
if (!span) {
|
|
1152
|
-
return;
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1155
|
-
switch (action) {
|
|
1156
|
-
case 'clear':
|
|
1157
|
-
change(clear(read(doc), span), 'other');
|
|
1158
|
-
local.live = 'Formatting cleared';
|
|
1159
|
-
break;
|
|
1160
|
-
case 'copy':
|
|
1161
|
-
void copy();
|
|
1162
|
-
return;
|
|
1163
|
-
case 'link':
|
|
1164
|
-
linker();
|
|
1165
|
-
return;
|
|
1166
|
-
default:
|
|
1167
|
-
change(toggle(read(doc), span, action), 'other');
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1170
|
-
inspect(span);
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1173
|
-
function turn(kind: Kind) {
|
|
1174
|
-
let span = current();
|
|
1175
|
-
|
|
1176
|
-
if (!editor || !span) {
|
|
1177
|
-
return;
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
shown = kind;
|
|
1181
|
-
editor.focus({ preventScroll: true });
|
|
1182
|
-
change(setKind(read(doc), span, kind), 'other');
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
// Typing takes on the style of the text it follows; a one line field has no line breaks to take.
|
|
1186
|
-
function typed(span: Span, value: string) {
|
|
1187
|
-
if (!multiline) {
|
|
1188
|
-
value = value.replace(INLINE_LINE_BREAKS, ' ');
|
|
1189
|
-
}
|
|
1190
|
-
|
|
1191
|
-
if (!value) {
|
|
1192
|
-
return;
|
|
127
|
+
if (controller && controller.document.value !== next) {
|
|
128
|
+
controller.setValue(next);
|
|
1193
129
|
}
|
|
1194
130
|
|
|
1195
|
-
|
|
1196
|
-
style = styleAt(blocks[span.start.block].runs, span.start.offset + (collapsed(span) ? 0 : 1));
|
|
1197
|
-
|
|
1198
|
-
change(insert(blocks, span, [{ ...style, text: value }]), 'type');
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
|
-
function undo() {
|
|
1202
|
-
let entry = steps.undo({ doc: read(doc), selection });
|
|
1203
|
-
|
|
1204
|
-
if (entry) {
|
|
1205
|
-
revert(entry);
|
|
1206
|
-
}
|
|
131
|
+
saving.save(next);
|
|
1207
132
|
}
|
|
1208
133
|
|
|
1209
|
-
// 'index' is the button's place among the format controls the arrow keys rove.
|
|
1210
|
-
let button = ({ action, label, shortcut }: (typeof ACTIONS)[number], content: Renderable<unknown>, index: number) => html`
|
|
1211
|
-
<button
|
|
1212
|
-
aria-label='${label}'
|
|
1213
|
-
class='button button--feedback inline-edit-toolbar-button'
|
|
1214
|
-
tabindex='${() => local.focus === index ? '0' : '-1'}'
|
|
1215
|
-
type='button'
|
|
1216
|
-
${action === 'clear' || action === 'copy' ? {} : { 'aria-pressed': () => pressed[action] ? 'true' : 'false' }}
|
|
1217
|
-
${{
|
|
1218
|
-
onclick: () => trigger(action),
|
|
1219
|
-
onconnect: (element: Tool) => {
|
|
1220
|
-
element[HINT] = action === 'copy' ? () => local.copied === 'success' ? 'Copied' : label : hint(label, shortcut);
|
|
1221
|
-
items[index] = element;
|
|
1222
|
-
}
|
|
1223
|
-
}}
|
|
1224
|
-
>
|
|
1225
|
-
${content}
|
|
1226
|
-
</button>
|
|
1227
|
-
`;
|
|
1228
|
-
|
|
1229
|
-
// The text style select leads the format controls when there is one.
|
|
1230
|
-
let lead = kinds.length > 1 ? 1 : 0,
|
|
1231
|
-
tools = actions.filter(({ action }) => action === 'clear' || action === 'copy');
|
|
1232
|
-
|
|
1233
134
|
return html`
|
|
1234
135
|
<div
|
|
1235
|
-
class='inline-edit'
|
|
136
|
+
class='inline-edit inline-edit--rich'
|
|
1236
137
|
${this?.attributes}
|
|
1237
138
|
${attributes}
|
|
1238
139
|
${{
|
|
1239
140
|
class: [
|
|
1240
141
|
multiline && 'inline-edit--multiline',
|
|
1241
142
|
() => state.editing && '--active',
|
|
1242
|
-
() => state.saved && 'inline-edit--saved'
|
|
1243
|
-
() => empty(read(doc)) && 'inline-edit--empty'
|
|
143
|
+
() => state.saved && 'inline-edit--saved'
|
|
1244
144
|
],
|
|
1245
|
-
|
|
145
|
+
// Direct: delegation only runs the nearest bound handler, and the editor binds these itself.
|
|
146
|
+
onconnect: (element: HTMLElement, on) => {
|
|
1246
147
|
root = element;
|
|
1247
|
-
|
|
1248
|
-
unobserve = observe(element, sync);
|
|
1249
|
-
},
|
|
1250
|
-
ondisconnect: () => {
|
|
1251
|
-
cancelAnimationFrame(frame);
|
|
1252
|
-
clearTimeout(copyTimer);
|
|
1253
|
-
clearTimeout(settling);
|
|
1254
|
-
keys?.abort();
|
|
1255
|
-
unobserve?.();
|
|
1256
|
-
unobserve = undefined;
|
|
1257
|
-
saving.dispose();
|
|
1258
|
-
},
|
|
1259
|
-
ondocumentselectionchange: sync,
|
|
1260
|
-
onfocusout: leave,
|
|
1261
|
-
onwindowpointercancel: settle,
|
|
1262
|
-
onwindowpointerup: settle
|
|
1263
|
-
}}
|
|
1264
|
-
>
|
|
1265
|
-
<div
|
|
1266
|
-
aria-label='${label}'
|
|
1267
|
-
aria-multiline='${multiline ? 'true' : 'false'}'
|
|
1268
|
-
aria-keyshortcuts='${keyshortcuts}'
|
|
1269
|
-
aria-placeholder='${placeholder}'
|
|
1270
|
-
class='inline-edit-editor'
|
|
1271
|
-
contenteditable='true'
|
|
1272
|
-
data-placeholder='${placeholder}'
|
|
1273
|
-
role='textbox'
|
|
1274
|
-
${this?.attributes?.[INLINE_EDIT_RICH_EDITOR]}
|
|
1275
|
-
${attributes[INLINE_EDIT_RICH_EDITOR]}
|
|
1276
|
-
${{
|
|
1277
|
-
onbeforeinput: edit,
|
|
1278
|
-
oncompositionend: () => {
|
|
1279
|
-
clearTimeout(settling);
|
|
1280
|
-
// Some engines write the composed text after this event, so it is read once they have.
|
|
1281
|
-
settling = setTimeout(resolve, 0);
|
|
1282
|
-
},
|
|
1283
|
-
oncompositionstart: () => {
|
|
1284
|
-
resolve();
|
|
1285
|
-
|
|
1286
|
-
let now = editor ? capture(editor) : null;
|
|
1287
|
-
|
|
1288
|
-
if (!editor || !now) {
|
|
1289
|
-
return;
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
let span = order(now);
|
|
1293
|
-
|
|
1294
|
-
// The input method replaces a selection within one block itself; across blocks it would
|
|
1295
|
-
// merge elements, so that part is deleted first.
|
|
1296
|
-
if (span.start.block !== span.end.block) {
|
|
1297
|
-
change(remove(read(doc), span), 'delete');
|
|
1298
|
-
}
|
|
1299
|
-
|
|
1300
|
-
composing = { block: span.start.block, element: elements(editor)[span.start.block] };
|
|
1301
|
-
show(false, true);
|
|
1302
|
-
},
|
|
1303
|
-
onconnect: (element: HTMLElement) => {
|
|
1304
|
-
editor = element;
|
|
1305
|
-
},
|
|
1306
|
-
oncopy: (e: ClipboardEvent) => clip(e, false),
|
|
1307
|
-
oncut: (e: ClipboardEvent) => clip(e, true),
|
|
1308
|
-
onfocus: () => {
|
|
148
|
+
on(element, 'focusin', () => {
|
|
1309
149
|
state.editing = true;
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
if (e.isComposing) {
|
|
1316
|
-
return;
|
|
150
|
+
}, { direct: true });
|
|
151
|
+
// Focus moving between the text and its toolbar stays in the edit.
|
|
152
|
+
on(element, 'focusout', (e: FocusEvent) => {
|
|
153
|
+
if (!root?.contains(e.relatedTarget as Node | null)) {
|
|
154
|
+
finish(true, false);
|
|
1317
155
|
}
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
mod = e.metaKey || e.ctrlKey;
|
|
1323
|
-
|
|
1324
|
-
if (mod && !e.altKey && (key === 'y' || key === 'z')) {
|
|
1325
|
-
e.preventDefault();
|
|
1326
|
-
|
|
1327
|
-
if (key === 'y' || e.shiftKey) {
|
|
1328
|
-
redo();
|
|
1329
|
-
}
|
|
1330
|
-
else {
|
|
1331
|
-
undo();
|
|
1332
|
-
}
|
|
1333
|
-
|
|
1334
|
-
return;
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
|
-
if (mod && !e.altKey && key !== 'enter') {
|
|
1338
|
-
let action = ACTIONS.find(({ shortcut }) => shortcut?.toLowerCase() === (e.shiftKey ? 'shift+' : '') + key)?.action;
|
|
1339
|
-
|
|
1340
|
-
// Same path as the buttons, so the shortcut updates the toolbar like a click.
|
|
1341
|
-
if (action && features.has(action)) {
|
|
1342
|
-
e.preventDefault();
|
|
1343
|
-
trigger(action);
|
|
1344
|
-
}
|
|
1345
|
-
|
|
156
|
+
}, { direct: true });
|
|
157
|
+
// Bubbled from the text: the editor and its toolbar keep the keys they handle.
|
|
158
|
+
on(element, 'keydown', (e: KeyboardEvent) => {
|
|
159
|
+
if (e.defaultPrevented || e.isComposing) {
|
|
1346
160
|
return;
|
|
1347
161
|
}
|
|
1348
162
|
|
|
1349
163
|
if (e.key === 'Escape') {
|
|
1350
164
|
e.preventDefault();
|
|
1351
|
-
|
|
1352
|
-
if (panel.open) {
|
|
1353
|
-
dismiss();
|
|
1354
|
-
}
|
|
1355
|
-
else {
|
|
1356
|
-
finish(false, true);
|
|
1357
|
-
}
|
|
1358
|
-
|
|
1359
|
-
return;
|
|
165
|
+
finish(false, true);
|
|
1360
166
|
}
|
|
1361
|
-
|
|
1362
|
-
// One line saves on Enter; a multiline field keeps Enter for new blocks and saves on Mod+Enter.
|
|
1363
|
-
if (e.key === 'Enter' && (mod || !multiline)) {
|
|
167
|
+
else if (e.key === 'Enter' && (!multiline || (apple ? e.metaKey : e.ctrlKey))) {
|
|
1364
168
|
e.preventDefault();
|
|
1365
169
|
finish(true, true);
|
|
1366
|
-
return;
|
|
1367
|
-
}
|
|
1368
|
-
|
|
1369
|
-
if (panel.open && !mod && (e.key.length === 1 || e.key === 'Backspace' || e.key === 'Delete' || e.key === 'Enter')) {
|
|
1370
|
-
show(false, true);
|
|
1371
170
|
}
|
|
1372
|
-
},
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
171
|
+
}, { direct: true });
|
|
172
|
+
},
|
|
173
|
+
ondisconnect: saving.dispose
|
|
174
|
+
}}
|
|
175
|
+
>
|
|
176
|
+
${markdown({
|
|
177
|
+
...defaults,
|
|
178
|
+
...own,
|
|
179
|
+
class: ['inline-edit-editor', defaults?.class ?? [], own?.class ?? []].flat(),
|
|
180
|
+
controller: (next: MarkdownController) => {
|
|
181
|
+
controller = next;
|
|
182
|
+
},
|
|
183
|
+
// A box ticked while the field rests saves at once; mid-edit it goes with the rest.
|
|
184
|
+
onChange: (next: string) => {
|
|
185
|
+
write(current, next);
|
|
1378
186
|
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
}
|
|
1382
|
-
},
|
|
1383
|
-
onpointerdown: (e: PointerEvent) => {
|
|
1384
|
-
if (e.button === 0) {
|
|
1385
|
-
pressing = true;
|
|
1386
|
-
}
|
|
187
|
+
if (!state.editing) {
|
|
188
|
+
save();
|
|
1387
189
|
}
|
|
1388
|
-
}
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
<div class='tooltip tooltip--context inline-edit-anchor' ${{ class: () => panel.open && '--active' }}>
|
|
1393
|
-
<div
|
|
1394
|
-
aria-label='Formatting'
|
|
1395
|
-
class='tooltip-content tooltip-content--context inline-edit-toolbar'
|
|
1396
|
-
role='toolbar'
|
|
1397
|
-
${this?.attributes?.[INLINE_EDIT_RICH_TOOLBAR]}
|
|
1398
|
-
${attributes[INLINE_EDIT_RICH_TOOLBAR]}
|
|
1399
|
-
${{
|
|
1400
|
-
'aria-hidden': () => panel.open ? 'false' : 'true',
|
|
1401
|
-
class: [
|
|
1402
|
-
() => panel.instant && 'inline-edit-toolbar--instant',
|
|
1403
|
-
() => panel.link && 'inline-edit-toolbar--link'
|
|
1404
|
-
],
|
|
1405
|
-
inert: () => !panel.open,
|
|
1406
|
-
onconnect: (element: HTMLElement) => {
|
|
1407
|
-
toolbar = element;
|
|
1408
|
-
// Bound directly: delegation only runs the nearest bound handler, which for the text
|
|
1409
|
-
// style select is its own.
|
|
1410
|
-
keys = new AbortController();
|
|
1411
|
-
element.addEventListener('keydown', navigate, { signal: keys.signal });
|
|
1412
|
-
},
|
|
1413
|
-
// Keeps the text selected and focused when a control is pressed; the link field takes focus.
|
|
1414
|
-
onmousedown: (e: MouseEvent) => {
|
|
1415
|
-
if ((e.target as Element).tagName !== 'INPUT') {
|
|
1416
|
-
e.preventDefault();
|
|
1417
|
-
}
|
|
1418
|
-
},
|
|
1419
|
-
style: () => `--toolbar-origin: ${panel.origin}; --toolbar-x: ${panel.x}px; --toolbar-y: ${panel.y}px;`
|
|
1420
|
-
}}
|
|
1421
|
-
>
|
|
1422
|
-
<div class='inline-edit-toolbar-format' ${tip.delegate({ content: (trigger) => (trigger as Tool)[HINT], edge: true, selector: '.inline-edit-toolbar-button' })}>
|
|
1423
|
-
${kinds.length > 1 && html`
|
|
1424
|
-
${selectInput({
|
|
1425
|
-
[selectInput.trigger]: {
|
|
1426
|
-
onconnect: (element: HTMLElement) => {
|
|
1427
|
-
items[0] = element;
|
|
1428
|
-
},
|
|
1429
|
-
tabindex: () => local.focus === 0 ? '0' : '-1'
|
|
1430
|
-
},
|
|
1431
|
-
class: 'inline-edit-toolbar-block',
|
|
1432
|
-
label: 'Text style',
|
|
1433
|
-
options: kinds,
|
|
1434
|
-
state: block
|
|
1435
|
-
})}
|
|
1436
|
-
${(marks.length > 0 || tools.length > 0) && html`<span aria-hidden='true' class='inline-edit-toolbar-divider'></span>`}
|
|
1437
|
-
`}
|
|
1438
|
-
${marks.map((item, i) => button(item, glyph(item.action as Exclude<Action, 'copy'>), lead + i))}
|
|
1439
|
-
${marks.length > 0 && tools.length > 0 && html`<span aria-hidden='true' class='inline-edit-toolbar-divider'></span>`}
|
|
1440
|
-
${tools.map((item, i) => button(
|
|
1441
|
-
item,
|
|
1442
|
-
item.action === 'copy'
|
|
1443
|
-
? faces(() => local.copied, [
|
|
1444
|
-
{ content: icon({ 'aria-hidden': 'true', class: 'button-icon' }, copySvg), key: 'idle' },
|
|
1445
|
-
{ content: icon({ 'aria-hidden': 'true', class: 'button-icon button-icon--draw' }, checkSvg), key: 'success', tone: 'success' },
|
|
1446
|
-
{ content: icon({ 'aria-hidden': 'true', class: 'button-icon button-icon--draw' }, closeSvg), key: 'error', tone: 'error' }
|
|
1447
|
-
])
|
|
1448
|
-
: glyph(item.action as Exclude<Action, 'copy'>),
|
|
1449
|
-
lead + marks.length + i
|
|
1450
|
-
))}
|
|
1451
|
-
${tip.render()}
|
|
1452
|
-
</div>
|
|
1453
|
-
${features.has('link') && html`
|
|
1454
|
-
<div class='inline-edit-toolbar-link'>
|
|
1455
|
-
${input({
|
|
1456
|
-
'aria-invalid': () => hyperlink.invalid && 'true',
|
|
1457
|
-
'aria-label': 'Link address',
|
|
1458
|
-
class: 'inline-edit-toolbar-url',
|
|
1459
|
-
onconnect: (element: HTMLInputElement) => {
|
|
1460
|
-
url = element;
|
|
1461
|
-
},
|
|
1462
|
-
oninput: (e: Event) => {
|
|
1463
|
-
hyperlink.url = (e.currentTarget as HTMLInputElement).value;
|
|
1464
|
-
},
|
|
1465
|
-
placeholder: 'Paste or type a link',
|
|
1466
|
-
type: 'url',
|
|
1467
|
-
value: () => hyperlink.url
|
|
1468
|
-
})}
|
|
1469
|
-
<button
|
|
1470
|
-
aria-label='Apply link'
|
|
1471
|
-
class='button button--feedback inline-edit-toolbar-button'
|
|
1472
|
-
type='button'
|
|
1473
|
-
${{ onclick: () => apply(hyperlink.url) }}
|
|
1474
|
-
>
|
|
1475
|
-
${glyph('apply')}
|
|
1476
|
-
</button>
|
|
1477
|
-
<button
|
|
1478
|
-
aria-label='Open link in a new tab'
|
|
1479
|
-
class='button button--feedback inline-edit-toolbar-button'
|
|
1480
|
-
type='button'
|
|
1481
|
-
${{
|
|
1482
|
-
onclick: () => {
|
|
1483
|
-
let href = address(hyperlink.url);
|
|
1484
|
-
|
|
1485
|
-
if (href) {
|
|
1486
|
-
window.open(href, '_blank', 'noopener');
|
|
1487
|
-
}
|
|
1488
|
-
}
|
|
1489
|
-
}}
|
|
1490
|
-
>
|
|
1491
|
-
${glyph('open')}
|
|
1492
|
-
</button>
|
|
1493
|
-
<button
|
|
1494
|
-
aria-label='Remove link'
|
|
1495
|
-
class='button button--feedback inline-edit-toolbar-button inline-edit-toolbar-unlink'
|
|
1496
|
-
type='button'
|
|
1497
|
-
${{
|
|
1498
|
-
hidden: () => !hyperlink.existing,
|
|
1499
|
-
onclick: () => apply(null)
|
|
1500
|
-
}}
|
|
1501
|
-
>
|
|
1502
|
-
${glyph('unlink')}
|
|
1503
|
-
</button>
|
|
1504
|
-
</div>
|
|
1505
|
-
`}
|
|
1506
|
-
</div>
|
|
1507
|
-
</div>
|
|
190
|
+
},
|
|
191
|
+
options,
|
|
192
|
+
value: state.value
|
|
193
|
+
})}
|
|
1508
194
|
<span aria-hidden='true' class='inline-edit-icon'>
|
|
1509
195
|
${icon({ class: 'inline-edit-icon-pencil' }, pencilSvg)}
|
|
1510
196
|
${icon({ class: 'inline-edit-icon-check' }, checkSvg)}
|
|
1511
197
|
</span>
|
|
1512
|
-
<span aria-live='polite' class='inline-edit-label'>${() => local.live}</span>
|
|
1513
198
|
${saving.status && status.render(saving.status, this?.attributes?.[INLINE_EDIT_STATUS], attributes[INLINE_EDIT_STATUS])}
|
|
1514
199
|
</div>
|
|
1515
200
|
`;
|
|
1516
201
|
},
|
|
1517
|
-
{ editor: INLINE_EDIT_RICH_EDITOR, status: INLINE_EDIT_STATUS
|
|
202
|
+
{ editor: INLINE_EDIT_RICH_EDITOR, status: INLINE_EDIT_STATUS }
|
|
1518
203
|
);
|
|
1519
204
|
|
|
1520
|
-
export type {
|
|
205
|
+
export type { Status, Tool as Feature };
|