mirror of
https://github.com/penpot/penpot.git
synced 2026-11-17 07:30:35 +00:00
* 🎉 Add UI for toggling bullet lists (under config flag) * 🎉 Store list-style-type as a paragraph attribute The bullet list toggle now saves list-style-type ("none" or "disc") on the selected paragraphs and reads it back. A paragraph without the attr counts as "none", so a bullet paragraph next to an older one shows as mixed. WASM keeps the value on each paragraph: the paragraph bytes grow from 12 to 16, Enter keeps it on the new paragraph, and the v3 editor reports it in the current styles, so the sidebar shows it while editing too. Refs #12630 AI-assisted-by: claude-opus-5-5 * ✨ Draw bullets for list paragraphs A paragraph with list-style-type "disc" now gets a solid round bullet, sized as Chrome draws a CSS disc marker (measured with Source Sans Pro): a radius of 0.16 font sizes, centered 0.32 font sizes above the first baseline, with a gap of 0.33 font sizes before the text. The bullet hangs outside the text box, before its start edge (after it for RTL), like CSS list-style-position: outside, so the text layout, caret and selection stay as they were. The bullet takes the paint of its line's first style run, so fills, strokes, shadows and masks apply to it as they do to the glyphs. An empty item, which has no run, borrows the previous item's paint. The cached paint, the text extrect and text-to-path share one walker over the paragraphs, so they always agree: the extrect grows to hold the bullets, like shadows and blur, and flattening a text keeps them. Refs #12630 AI-assisted-by: claude-opus-5-5 * ✨ Show the list style in Inspect Text paragraphs with list-style-type "disc" now show a "List Style" row in the Inspect Styles and Computed views, after Text Transform. Its copy action gives "list-style-type: disc;". Text without a list shows no row. The list item check lives in common as list-paragraph?, so every place that needs it shares one rule. Refs #12630 AI-assisted-by: claude-opus-5-5 * ✨ Generate list HTML and CSS for bullet paragraphs In the Inspect code, neighbouring paragraphs with list-style-type "disc" become one <ul> with an <li> each, keeping the paragraph's class and dir. Other paragraphs stay <p>. Only code mode groups them; text rendering still uses <p>. The CSS sets list-style-type on the items and resets the list's margin and padding, so the browser hangs the bullet before the text as the canvas does. Paragraph rules set font-size: 0, so each item also gets a ::marker rule with its first span's font size and text color. A ::marker can't paint a gradient, so a gradient fill gives its first stop. Refs #12630 AI-assisted-by: claude-opus-5-5
174 lines
7.6 KiB
Clojure
174 lines
7.6 KiB
Clojure
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
;;
|
|
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
|
|
|
(ns common-tests.attrs-test
|
|
(:require
|
|
[app.common.attrs :as attrs]
|
|
[clojure.test :as t]))
|
|
|
|
(t/deftest get-attrs-multi-same-value
|
|
(t/testing "returns value when all objects have the same attribute value"
|
|
(let [objs [{:attr "red"}
|
|
{:attr "red"}
|
|
{:attr "red"}]
|
|
result (attrs/get-attrs-multi objs [:attr])]
|
|
(t/is (= {:attr "red"} result))))
|
|
|
|
(t/testing "returns nil when all objects have nil value"
|
|
(let [objs [{:attr nil}
|
|
{:attr nil}]
|
|
result (attrs/get-attrs-multi objs [:attr])]
|
|
(t/is (= {:attr nil} result)))))
|
|
|
|
(t/deftest get-attrs-multi-different-values
|
|
(t/testing "returns :multiple when objects have different concrete values"
|
|
(let [objs [{:attr "red"}
|
|
{:attr "blue"}]
|
|
result (attrs/get-attrs-multi objs [:attr])]
|
|
(t/is (= {:attr :multiple} result)))))
|
|
|
|
(t/deftest get-attrs-multi-missing-key
|
|
(t/testing "returns value when one object has the attribute and another doesn't"
|
|
(let [objs [{:attr "red"}
|
|
{:other "value"}]
|
|
result (attrs/get-attrs-multi objs [:attr])]
|
|
(t/is (= {:attr "red"} result))))
|
|
|
|
(t/testing "returns value when one object has UUID and another is missing"
|
|
(let [uuid #uuid "550e8400-e29b-41d4-a716-446655440000"
|
|
objs [{:attr uuid}
|
|
{:other "value"}]
|
|
result (attrs/get-attrs-multi objs [:attr])]
|
|
(t/is (= {:attr uuid} result))))
|
|
|
|
(t/testing "returns :multiple when some objects have the key and some don't"
|
|
(let [objs [{:attr "red"}
|
|
{:other "value"}
|
|
{:attr "blue"}]
|
|
result (attrs/get-attrs-multi objs [:attr])]
|
|
(t/is (= {:attr :multiple} result))))
|
|
|
|
(t/testing "returns nil when one object has nil and another is missing"
|
|
(let [objs [{:attr nil}
|
|
{:other "value"}]
|
|
result (attrs/get-attrs-multi objs [:attr])]
|
|
(t/is (= {:attr nil} result)))))
|
|
|
|
(t/deftest get-attrs-multi-all-missing
|
|
(t/testing "all missing → attribute NOT included in result"
|
|
(let [objs [{:other "value"}
|
|
{:different "data"}]
|
|
result (attrs/get-attrs-multi objs [:attr])]
|
|
(t/is (= {} result)
|
|
"Attribute should not be in result when all objects are missing")))
|
|
|
|
(t/testing "all missing with empty maps → attribute NOT included"
|
|
(let [objs [{} {}]
|
|
result (attrs/get-attrs-multi objs [:attr])]
|
|
(t/is (= {} result)
|
|
"Attribute should not be in result"))))
|
|
|
|
(t/deftest get-attrs-multi-multiple-attributes
|
|
(t/testing "handles multiple attributes with different merge results"
|
|
(let [objs [{:attr1 "red" :attr2 "blue"}
|
|
{:attr1 "red" :attr2 "green"}
|
|
{:attr1 "red"}] ; :attr2 missing
|
|
result (attrs/get-attrs-multi objs [:attr1 :attr2])]
|
|
(t/is (= {:attr1 "red" :attr2 :multiple} result))))
|
|
|
|
(t/testing "handles mixed scenarios: same, different, and missing"
|
|
(let [uuid #uuid "550e8400-e29b-41d4-a716-446655440000"
|
|
uuid2 #uuid "550e8400-e29b-41d4-a716-446655440001"
|
|
objs [{:id :a :ref uuid}
|
|
{:id :b :ref uuid2}
|
|
{:id :c}] ; :ref missing
|
|
result (attrs/get-attrs-multi objs [:id :ref])]
|
|
(t/is (= {:id :multiple :ref :multiple} result)))))
|
|
|
|
(t/deftest get-attrs-multi-typography-ref-id-scenario
|
|
(t/testing "the specific bug scenario: typography-ref-id with UUID vs missing"
|
|
(let [uuid #uuid "550e8400-e29b-41d4-a716-446655440000"
|
|
;; Shape 1 has typography-ref-id with a UUID
|
|
shape1 {:id :shape1 :typography-ref-id uuid}
|
|
;; Shape 2 does NOT have typography-ref-id at all
|
|
shape2 {:id :shape2}
|
|
result (attrs/get-attrs-multi [shape1 shape2] [:typography-ref-id])]
|
|
(t/is (= {:typography-ref-id uuid} result))))
|
|
|
|
(t/testing "both shapes missing → attribute NOT included in result"
|
|
(let [shape1 {:id :shape1}
|
|
shape2 {:id :shape2}
|
|
result (attrs/get-attrs-multi [shape1 shape2] [:typography-ref-id])]
|
|
(t/is (= {} result)
|
|
"Expected empty map when all shapes are missing the attribute"))))
|
|
|
|
(t/deftest get-attrs-multi-bug-missing-vs-present
|
|
(t/testing "BUG FIXED: one shape has :typography-ref-id, other does NOT → returns uuid"
|
|
(let [uuid #uuid "550e8400-e29b-41d4-a716-446655440000"
|
|
shape1 {:id :shape1 :typography-ref-id uuid}
|
|
shape2 {:id :shape2}
|
|
result (attrs/get-attrs-multi [shape1 shape2] [:typography-ref-id])]
|
|
(t/is (= {:typography-ref-id uuid} result))))
|
|
|
|
(t/testing "both missing → empty map (attribute not in result)"
|
|
(let [shape1 {:id :shape1}
|
|
shape2 {:id :shape2}
|
|
result (attrs/get-attrs-multi [shape1 shape2] [:typography-ref-id])]
|
|
(t/is (= {} result)
|
|
"Expected empty map when all shapes are missing the attribute")))
|
|
|
|
(t/testing "both equal values → return the value"
|
|
(let [uuid #uuid "550e8400-e29b-41d4-a716-446655440000"
|
|
shape1 {:id :shape1 :typography-ref-id uuid}
|
|
shape2 {:id :shape2 :typography-ref-id uuid}
|
|
result (attrs/get-attrs-multi [shape1 shape2] [:typography-ref-id])]
|
|
(t/is (= {:typography-ref-id uuid} result))))
|
|
|
|
(t/testing "different values → return :multiple"
|
|
(let [uuid1 #uuid "550e8400-e29b-41d4-a716-446655440000"
|
|
uuid2 #uuid "550e8400-e29b-41d4-a716-446655440001"
|
|
shape1 {:id :shape1 :typography-ref-id uuid1}
|
|
shape2 {:id :shape2 :typography-ref-id uuid2}
|
|
result (attrs/get-attrs-multi [shape1 shape2] [:typography-ref-id])]
|
|
(t/is (= {:typography-ref-id :multiple} result)))))
|
|
|
|
(t/deftest get-attrs-multi-default-equal
|
|
(t/testing "numbers use close? for equality"
|
|
(let [objs [{:value 1.0}
|
|
{:value 1.0000001}]
|
|
result (attrs/get-attrs-multi objs [:value])]
|
|
(t/is (= {:value 1.0} result)
|
|
"Numbers within tolerance should be considered equal")))
|
|
|
|
(t/testing "different floating point positions beyond tolerance are :multiple"
|
|
(let [objs [{:x -26}
|
|
{:x -153}]
|
|
result (attrs/get-attrs-multi objs [:x])]
|
|
(t/is (= {:x :multiple} result)
|
|
"Different positions should be :multiple"))))
|
|
(defn- text-shape-with-paragraphs
|
|
[& paragraphs]
|
|
{:content {:type "root"
|
|
:children [{:type "paragraph-set"
|
|
:children (mapv #(merge {:type "paragraph"
|
|
:children [{:text "item"}]}
|
|
%)
|
|
paragraphs)}]}})
|
|
|
|
(t/deftest get-text-attrs-multi-list-style-type
|
|
(t/testing "paragraphs with the same list style return it"
|
|
(let [shape (text-shape-with-paragraphs {:list-style-type "disc"}
|
|
{:list-style-type "disc"})]
|
|
(t/is (= "disc" (:list-style-type (attrs/get-text-attrs-multi shape {} [:list-style-type]))))))
|
|
|
|
(t/testing "a paragraph without list style counts as no list"
|
|
(let [shape (text-shape-with-paragraphs {})]
|
|
(t/is (= "none" (:list-style-type (attrs/get-text-attrs-multi shape {} [:list-style-type]))))))
|
|
|
|
(t/testing "a bullet paragraph next to one without list style is mixed"
|
|
(let [shape (text-shape-with-paragraphs {:list-style-type "disc"} {})]
|
|
(t/is (= :multiple (:list-style-type (attrs/get-text-attrs-multi shape {} [:list-style-type])))))))
|