mirror of
https://github.com/penpot/penpot.git
synced 2026-11-26 21:00:32 +00:00
🐛 Keep variant property order and remove the right property past eight
Variants.properties and currentValues() went through a set, which loses order past eight items, so index-based removeProperty/renameProperty from a plugin hit the wrong property. Use distinct to keep the order. In the sidebar, input-with-meta* kept the input node after a real blur and replayed a stale rename with an old position when its row unmounted, undoing a property removal. Clear the node in on-stop-edit. Add a unit test, a plugin-api-test-suite case and a plugins changelog entry. Closes #13247
This commit is contained in:
parent
7f53bf76b6
commit
1438be5b26
@ -51,6 +51,7 @@
|
||||
(fn [event]
|
||||
(dom/stop-propagation event)
|
||||
(reset! editing* false)
|
||||
(mf/set-ref-val! last-node* nil)
|
||||
(when on-blur
|
||||
(on-blur event))))
|
||||
|
||||
@ -77,7 +78,9 @@
|
||||
:on-blur on-stop-edit
|
||||
:on-key-down handle-key-down})]
|
||||
|
||||
;; Cleanup: Simulate a blur event
|
||||
;; Cleanup: simulate a blur only for an edit that never blurred.
|
||||
;; on-stop-edit clears last-node*, so a finished edit is not replayed
|
||||
;; when the row unmounts.
|
||||
(mf/with-effect [on-blur last-node*]
|
||||
(fn []
|
||||
(let [input (mf/ref-val last-node*)
|
||||
|
||||
@ -715,7 +715,7 @@
|
||||
(->> (get-variant-components file-id id)
|
||||
(mapcat :variant-properties)
|
||||
(keep :name)
|
||||
(set)
|
||||
(distinct)
|
||||
(apply array)))}
|
||||
|
||||
:currentValues
|
||||
@ -726,7 +726,7 @@
|
||||
(->> variant-properties
|
||||
(d/seek #(= (:name %) property)))))
|
||||
(keep :value)
|
||||
(set)
|
||||
(distinct)
|
||||
(apply array)))
|
||||
|
||||
:variantComponents
|
||||
|
||||
@ -366,6 +366,17 @@
|
||||
(t/is (= [plugin-id :removeProperty "Plugin doesn't have 'library:write' permission"]
|
||||
(first @errors)))))))
|
||||
|
||||
(t/deftest variant-properties-keep-order-past-eight
|
||||
(let [names (mapv #(str "Property " %) (range 1 12))
|
||||
values (mapv #(str "Value " %) (range 1 12))
|
||||
components (mapv (fn [value]
|
||||
{:variant-properties (mapv #(hash-map :name % :value value) names)})
|
||||
values)]
|
||||
(with-redefs [library/get-variant-components (constantly components)]
|
||||
(let [proxy (library/variant-proxy plugin-id (uuid/next) (uuid/next))]
|
||||
(t/is (= names (vec (.-properties proxy))))
|
||||
(t/is (= values (vec (.currentValues proxy "Property 9"))))))))
|
||||
|
||||
(t/deftest variant-rename-property-checks-permission
|
||||
(let [plugin-id "test-plugin"
|
||||
file-id (uuid/next)
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
- **plugins-runtime**: `TokenFontFamilies.resolvedValue` and the `fontFamilies` member of `TokenTypographyValue` now keep a family whose name has several words (`Hanken Grotesk`) as one entry, instead of splitting it into an array of its words, and keep names with words the resolver would otherwise read as colors or numbers (`Red Hat Display`, `Press Start 2P`) unchanged.
|
||||
- **plugins-runtime:** A SES `repairIntrinsics` failure at startup (for example, when a browser extension wraps the native `Temporal` global) no longer leaves the whole app blank. Plugins are skipped for that session, the error is logged, and a telemetry event reports the unavailable runtime; the editor, login and sign-up pages load as usual. Plugins work as before in every other environment. When startup fails, SES has already replaced `Function.prototype.toString` in the host realm before throwing, but no intrinsics are hardened and no sandbox is created. Closes #12924.
|
||||
- **plugins-runtime:** `Variants.removeProperty()` no longer leaves two variants with the same values. When several variants clash, the top one in the layers panel keeps its values and each lower one gets a numbered value (`Big (1)`, or `(1)` when all its remaining values are empty). Closes #12959.
|
||||
- **plugins-runtime:** `Variants.properties` and `Variants.currentValues()` keep the order of the variant properties and values when there are more than eight. They used to come back shuffled, so `removeProperty()` and `renameProperty()` could hit the wrong property when called with an index read from `properties`. Closes #13247.
|
||||
|
||||
## 1.6.0 (2026-11-10)
|
||||
|
||||
|
||||
@ -295,6 +295,28 @@ describe('Variants', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('variant properties keep their order past eight', async (ctx) => {
|
||||
const vc = await variantComponent(ctx);
|
||||
const v = vc.variants!;
|
||||
while (v.properties.length < 10) {
|
||||
const before = v.properties.length;
|
||||
v.addProperty();
|
||||
await waitFor(() => v.properties.length > before);
|
||||
}
|
||||
expect(v.properties).toHaveLength(10);
|
||||
|
||||
v.renameProperty(4, 'Middle');
|
||||
await waitFor(() => v.properties[4] === 'Middle');
|
||||
const renamed = [...v.properties];
|
||||
expect(renamed[4]).toBe('Middle');
|
||||
expect(new Set(renamed).size).toBe(10);
|
||||
|
||||
const removed = renamed[8];
|
||||
v.removeProperty(8);
|
||||
await waitFor(() => v.properties.length === 9);
|
||||
expect(v.properties).toEqual(renamed.filter((name) => name !== removed));
|
||||
});
|
||||
|
||||
test('addVariant and setVariantProperty mutate the variant', async (ctx) => {
|
||||
const vc = await variantComponent(ctx);
|
||||
const v = vc.variants;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user