diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index ee793bbf33..2b8be69109 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -317,6 +317,26 @@ components-v2 (features/active-feature? state :components-v2)] (rx/of (add-component2 selected components-v2)))))) + +(defn add-multiple-components + "Add several new components to current file library, from the currently selected shapes." + [] + (ptk/reify ::add-multiple-components + ptk/WatchEvent + (watch [_ state _] + (let [components-v2 (features/active-feature? state :components-v2) + objects (wsh/lookup-page-objects state) + selected (->> (wsh/lookup-selected state) + (cph/clean-loops objects)) + added-components (map + #(add-component2 [%] components-v2) + selected) + undo-id (js/Symbol)] + (rx/concat + (rx/of (dwu/start-undo-transaction undo-id)) + (rx/from added-components) + (rx/of (dwu/commit-undo-transaction undo-id))))))) + (defn rename-component "Rename the component with the given id, in the current file library." [id new-name] diff --git a/frontend/src/app/main/ui/workspace/context_menu.cljs b/frontend/src/app/main/ui/workspace/context_menu.cljs index 94c79352d7..dfae97b106 100644 --- a/frontend/src/app/main/ui/workspace/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/context_menu.cljs @@ -439,7 +439,8 @@ has-component? (some true? (map #(contains? % :component-id) shapes)) is-component? (and single? (-> shapes first :component-id some?)) - is-non-root? (and single? (ctk/in-component-copy-not-root? (first shapes))) + in-copy-not-root? (some true? (map #(ctk/in-component-copy-not-root? %) shapes)) + objects (deref refs/workspace-page-objects) touched? (and single? (cph/component-touched? objects (:id (first shapes)))) can-update-main? (or (not components-v2) touched?) @@ -462,6 +463,7 @@ (ctf/get-component workspace-libraries component-file component-id))) do-add-component #(st/emit! (dwl/add-component)) + do-add-multiple-components #(st/emit! (dwl/add-multiple-components)) do-detach-component #(st/emit! (dwl/detach-component id)) do-detach-component-in-bulk #(st/emit! dwl/detach-selected-components) do-reset-component #(st/emit! (dwl/reset-component id)) @@ -504,12 +506,15 @@ :on-accept do-update-component-in-bulk}))))] [:* [:* - (when (or (not is-non-root?) (and has-component? (not single?))) + (when (or (not in-copy-not-root?) (and has-component? (not single?))) [:& menu-separator]) - (when-not is-non-root? + (when-not in-copy-not-root? [:& menu-entry {:title (tr "workspace.shape.menu.create-component") :shortcut (sc/get-tooltip :create-component) :on-click do-add-component}]) + (when-not (or single? in-copy-not-root?) + [:& menu-entry {:title (tr "workspace.shape.menu.create-multiple-components") + :on-click do-add-multiple-components}]) (when (and has-component? (not single?)) [:* [:& menu-entry {:title (tr "workspace.shape.menu.detach-instances-in-bulk") diff --git a/frontend/translations/en.po b/frontend/translations/en.po index e498172159..caac63b6dc 100644 --- a/frontend/translations/en.po +++ b/frontend/translations/en.po @@ -4367,6 +4367,9 @@ msgstr "Selection to board" msgid "workspace.shape.menu.create-component" msgstr "Create component" +msgid "workspace.shape.menu.create-multiple-components" +msgstr "Create multiple components" + #: src/app/main/ui/workspace/context_menu.cljs msgid "workspace.shape.menu.cut" msgstr "Cut" diff --git a/frontend/translations/es.po b/frontend/translations/es.po index 4a617c3971..acc2519f4b 100644 --- a/frontend/translations/es.po +++ b/frontend/translations/es.po @@ -4469,6 +4469,9 @@ msgstr "Tablero de selección" msgid "workspace.shape.menu.create-component" msgstr "Crear componente" +msgid "workspace.shape.menu.create-multiple-components" +msgstr "Crear múltiples componentes" + #: src/app/main/ui/workspace/context_menu.cljs msgid "workspace.shape.menu.cut" msgstr "Cortar"