mirror of
https://github.com/penpot/penpot.git
synced 2026-11-27 21:57:52 +00:00
✨ Show writing mode in the Language view and name readings
- The Layout group of the Language view shows the writing mode, orientation and Distribute row, as the Text section does. - The reading item of the text selection menu reads Furigana for Japanese, Pinyin or Zhuyin for Chinese, with a glyph that matches (あ, 拼, ㄅ) instead of the hiragana for every language. AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
c6dd9ec13c
commit
a9a5bc6081
@ -80,6 +80,25 @@
|
||||
(let [value (get styles attr)]
|
||||
(when-not (= :multiple value) value)))
|
||||
|
||||
(defn- reading-label
|
||||
"Name of the reading of a `family` text: furigana for Japanese, pinyin
|
||||
or `zhuyin` for Chinese."
|
||||
[family zhuyin]
|
||||
(cond
|
||||
(= family :japanese) (tr "workspace.text-selection-menu.furigana")
|
||||
(true? zhuyin) (tr "workspace.text-selection-menu.zhuyin")
|
||||
:else (tr "workspace.text-selection-menu.pinyin")))
|
||||
|
||||
(defn- reading-glyph
|
||||
"Glyph standing for the reading of a `family` text: a hiragana for
|
||||
furigana, the first character of 拼音 for pinyin and the first zhuyin
|
||||
symbol for `zhuyin`."
|
||||
[family zhuyin]
|
||||
(cond
|
||||
(= family :japanese) "あ"
|
||||
(true? zhuyin) "ㄅ"
|
||||
:else "拼"))
|
||||
|
||||
(defn annotated?
|
||||
"True when the selection has a reading, emphasis marks, warichu or
|
||||
combine (see `annotations` in `selection-menu*`)."
|
||||
@ -163,9 +182,10 @@
|
||||
"The annotations of the `family` language for the selected text of
|
||||
`shape-id`. `annotations` holds what the text has (nil when its spans
|
||||
differ). A reading takes text without annotations or a whole base
|
||||
(`readable`); a warichu note, the text of one span (`warichu-enabled`)."
|
||||
(`readable`); a warichu note, the text of one span (`warichu-enabled`).
|
||||
The reading is furigana, pinyin or, with `zhuyin`, zhuyin."
|
||||
{::mf/private true}
|
||||
[{:keys [shape-id family annotations on-ruby emphasis-open on-emphasis-open
|
||||
[{:keys [shape-id family zhuyin annotations on-ruby emphasis-open on-emphasis-open
|
||||
^boolean readable ^boolean ruby-enabled ^boolean warichu-enabled]}]
|
||||
(let [{:keys [ruby emphasis warichu combine]} annotations
|
||||
|
||||
@ -209,14 +229,14 @@
|
||||
(apply-text-attrs shape-id {:text-combine-upright (if combine? "none" "all")})))]
|
||||
|
||||
[:*
|
||||
[:> menu-item* {:label (tr "workspace.text-selection-menu.ruby")
|
||||
[:> menu-item* {:label (reading-label family zhuyin)
|
||||
:active ruby?
|
||||
:disabled (not ruby-enabled)
|
||||
:hint (if readable
|
||||
(tr "workspace.options.text-options.zhuyin-selection-hint")
|
||||
(tr "workspace.text-selection-menu.reading-hint"))
|
||||
:on-click open-ruby}
|
||||
[:> glyph* {:glyph "あ"}]]
|
||||
[:> glyph* {:glyph (reading-glyph family zhuyin)}]]
|
||||
[:div {:class (stl/css :emphasis-anchor)}
|
||||
[:> menu-item* {:label (tr "workspace.text-selection-menu.emphasis")
|
||||
:dropdown true
|
||||
@ -245,12 +265,12 @@
|
||||
[:> icon* {:icon-id i/text-combine-upright-all :aria-hidden true}]]])]))
|
||||
|
||||
(mf/defc ruby-input*
|
||||
"Input for the ruby reading of the selected text, starting from its
|
||||
current `reading`. Enter applies it, Remove drops the current one, and
|
||||
Escape and the back button return to the toolbar. A `validate` fn rejects
|
||||
the readings it returns false for."
|
||||
"Input for the ruby reading of the selected text, named `label`, starting
|
||||
from its current `reading`. Enter applies it, Remove drops the current
|
||||
one, and Escape and the back button return to the toolbar. A `validate`
|
||||
fn rejects the readings it returns false for."
|
||||
{::mf/private true}
|
||||
[{:keys [reading validate invalid-hint on-apply on-back more-open on-more]}]
|
||||
[{:keys [label reading validate invalid-hint on-apply on-back more-open on-more]}]
|
||||
(let [reading* (mf/use-state (or reading ""))
|
||||
value (deref reading*)
|
||||
valid? (or (str/blank? value) (nil? validate) (validate (str/trim value)))
|
||||
@ -301,7 +321,7 @@
|
||||
:aria-label (tr "workspace.text-selection-menu.back")
|
||||
:on-click on-back}
|
||||
[:> icon* {:icon-id i/arrow-left :aria-hidden true}]
|
||||
[:span {:class (stl/css :label)} (tr "workspace.text-selection-menu.ruby")]]
|
||||
[:span {:class (stl/css :label)} label]]
|
||||
[:input {:type "text"
|
||||
:class (stl/css :reading-input)
|
||||
:aria-label (tr "workspace.text-selection-menu.reading")
|
||||
@ -440,7 +460,8 @@
|
||||
:aria-label (tr "workspace.text-selection-menu.title")}
|
||||
(case view
|
||||
:ruby [:*
|
||||
[:> ruby-input* {:reading (:ruby annotations)
|
||||
[:> ruby-input* {:label (reading-label family zhuyin)
|
||||
:reading (:ruby annotations)
|
||||
:validate (when zhuyin cjk/zhuyin-reading?)
|
||||
:invalid-hint (tr "workspace.options.text-options.zhuyin-invalid")
|
||||
:more-open more-open
|
||||
@ -453,6 +474,7 @@
|
||||
:vertical vertical}])]
|
||||
[:> toolbar* {:shape-id shape-id
|
||||
:family family
|
||||
:zhuyin zhuyin
|
||||
:annotations annotations
|
||||
:readable readable
|
||||
:ruby-enabled ruby-enabled
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
[app.main.ui.workspace.sidebar.options.menus.text-cjk-controls :as tcc]
|
||||
[app.util.i18n :refer [tr]]
|
||||
[app.util.text.layout :as tl]
|
||||
[app.util.text.writing-mode :as wm]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
@ -469,6 +470,8 @@
|
||||
"Options of the CJK language of the texts in `ids`, in a view of their
|
||||
own that `on-close` leaves. Selected text (with a text selection) comes
|
||||
first, then Layout, then Ruby when the text has readings (`has-ruby`).
|
||||
Layout starts with the writing mode row of the Text section, so the
|
||||
view holds every option of the language.
|
||||
The view closes when the texts no longer share a CJK language."
|
||||
[{:keys [ids options-props on-change on-close has-ruby]}]
|
||||
(let [language-ref (mf/with-memo [ids] (refs/texts-language ids))
|
||||
@ -515,6 +518,8 @@
|
||||
|
||||
(when (some? family)
|
||||
[:> language-group* {:title (tr "workspace.options.text-options.language-group-layout")}
|
||||
(when ^boolean (wm/vertical-layout-active?)
|
||||
[:> tcc/writing-mode-row* {:values values :on-change on-change :on-blur on-blur}])
|
||||
(case family
|
||||
:japanese [:> japanese-layout-options* options-props]
|
||||
:chinese [:> chinese-layout-options*
|
||||
|
||||
@ -55,3 +55,29 @@
|
||||
(let [markup (render 10 {})]
|
||||
(t/is (str/includes? markup "top:30px") "anchored at the bottom right corner")
|
||||
(t/is (str/includes? markup "selection-anchor-below"))))
|
||||
|
||||
(defn- render-toolbar
|
||||
"Static markup of the toolbar for a `family` text, its readings zhuyin
|
||||
when `zhuyin` is true."
|
||||
[family zhuyin]
|
||||
(rds/renderToStaticMarkup
|
||||
(mf/element @#'selection-menu/toolbar*
|
||||
(mf/props {:shape-id (random-uuid)
|
||||
:family family
|
||||
:zhuyin zhuyin
|
||||
:annotations {}
|
||||
:readable true
|
||||
:ruby-enabled true
|
||||
:warichu-enabled true
|
||||
:emphasis-open false
|
||||
:on-emphasis-open identity
|
||||
:on-ruby identity}))))
|
||||
|
||||
(t/deftest reading-item-shows-the-glyph-of-the-language
|
||||
(t/is (str/includes? (render-toolbar :japanese false) "あ"))
|
||||
(let [pinyin (render-toolbar :chinese false)
|
||||
zhuyin (render-toolbar :chinese true)]
|
||||
(t/is (str/includes? pinyin "拼"))
|
||||
(t/is (not (str/includes? pinyin "あ")))
|
||||
(t/is (str/includes? zhuyin "ㄅ"))
|
||||
(t/is (not (str/includes? zhuyin "あ")))))
|
||||
|
||||
@ -9315,6 +9315,14 @@ msgstr "Combine"
|
||||
msgid "workspace.text-selection-menu.emphasis"
|
||||
msgstr "Emphasis"
|
||||
|
||||
#: src/app/main/ui/workspace/shapes/text/selection_menu.cljs
|
||||
msgid "workspace.text-selection-menu.furigana"
|
||||
msgstr "Furigana"
|
||||
|
||||
#: src/app/main/ui/workspace/shapes/text/selection_menu.cljs
|
||||
msgid "workspace.text-selection-menu.pinyin"
|
||||
msgstr "Pinyin"
|
||||
|
||||
#: src/app/main/ui/workspace/shapes/text/selection_menu.cljs
|
||||
msgid "workspace.text-selection-menu.reading"
|
||||
msgstr "Reading"
|
||||
@ -9327,10 +9335,6 @@ msgstr "Select text without a reading or warichu, or a whole reading"
|
||||
msgid "workspace.text-selection-menu.remove"
|
||||
msgstr "Remove"
|
||||
|
||||
#: src/app/main/ui/workspace/shapes/text/selection_menu.cljs
|
||||
msgid "workspace.text-selection-menu.ruby"
|
||||
msgstr "Ruby"
|
||||
|
||||
#: src/app/main/ui/workspace/shapes/text/selection_menu.cljs
|
||||
msgid "workspace.text-selection-menu.ruby-options"
|
||||
msgstr "Ruby options"
|
||||
@ -9347,6 +9351,10 @@ msgstr "Text annotations"
|
||||
msgid "workspace.text-selection-menu.warichu"
|
||||
msgstr "Warichu"
|
||||
|
||||
#: src/app/main/ui/workspace/shapes/text/selection_menu.cljs
|
||||
msgid "workspace.text-selection-menu.zhuyin"
|
||||
msgstr "Zhuyin"
|
||||
|
||||
#: src/app/main/data/workspace/comments.cljs:49
|
||||
msgid "workspace.toast.comments-hidden"
|
||||
msgstr "Comments hidden"
|
||||
|
||||
@ -9218,6 +9218,14 @@ msgstr "Combinar"
|
||||
msgid "workspace.text-selection-menu.emphasis"
|
||||
msgstr "Énfasis"
|
||||
|
||||
#: src/app/main/ui/workspace/shapes/text/selection_menu.cljs
|
||||
msgid "workspace.text-selection-menu.furigana"
|
||||
msgstr "Furigana"
|
||||
|
||||
#: src/app/main/ui/workspace/shapes/text/selection_menu.cljs
|
||||
msgid "workspace.text-selection-menu.pinyin"
|
||||
msgstr "Pinyin"
|
||||
|
||||
#: src/app/main/ui/workspace/shapes/text/selection_menu.cljs
|
||||
msgid "workspace.text-selection-menu.reading"
|
||||
msgstr "Lectura"
|
||||
@ -9230,10 +9238,6 @@ msgstr "Selecciona texto sin lectura ni warichu, o una lectura completa"
|
||||
msgid "workspace.text-selection-menu.remove"
|
||||
msgstr "Quitar"
|
||||
|
||||
#: src/app/main/ui/workspace/shapes/text/selection_menu.cljs
|
||||
msgid "workspace.text-selection-menu.ruby"
|
||||
msgstr "Ruby"
|
||||
|
||||
#: src/app/main/ui/workspace/shapes/text/selection_menu.cljs
|
||||
msgid "workspace.text-selection-menu.ruby-options"
|
||||
msgstr "Opciones de ruby"
|
||||
@ -9250,6 +9254,10 @@ msgstr "Anotaciones de texto"
|
||||
msgid "workspace.text-selection-menu.warichu"
|
||||
msgstr "Warichu"
|
||||
|
||||
#: src/app/main/ui/workspace/shapes/text/selection_menu.cljs
|
||||
msgid "workspace.text-selection-menu.zhuyin"
|
||||
msgstr "Zhuyin"
|
||||
|
||||
#: src/app/main/data/workspace/comments.cljs:49
|
||||
msgid "workspace.toast.comments-hidden"
|
||||
msgstr "Comentarios ocultos"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user