mirror of
https://github.com/penpot/penpot.git
synced 2025-05-29 23:16:11 +02:00
🐛 Fix exception on paste invalid html
This commit is contained in:
parent
ecb85778bc
commit
79a164be6d
5 changed files with 75 additions and 69 deletions
|
@ -49,6 +49,7 @@
|
||||||
- Fix issue that makes workspace shortcuts stop working [Taiga #11062](https://tree.taiga.io/project/penpot/issue/11062)
|
- Fix issue that makes workspace shortcuts stop working [Taiga #11062](https://tree.taiga.io/project/penpot/issue/11062)
|
||||||
- Fix problem while syncing library colors and typographies [Taiga #11068](https://tree.taiga.io/project/penpot/issue/11068)
|
- Fix problem while syncing library colors and typographies [Taiga #11068](https://tree.taiga.io/project/penpot/issue/11068)
|
||||||
- Fix problem with path edition of shapes [Taiga #9496](https://tree.taiga.io/project/penpot/issue/9496)
|
- Fix problem with path edition of shapes [Taiga #9496](https://tree.taiga.io/project/penpot/issue/9496)
|
||||||
|
- Fix exception on paste invalid html [Taiga #11047](https://tree.taiga.io/project/penpot/issue/11047)
|
||||||
|
|
||||||
## 2.6.2
|
## 2.6.2
|
||||||
|
|
||||||
|
|
|
@ -214,8 +214,7 @@
|
||||||
|
|
||||||
(defn lazy-validator
|
(defn lazy-validator
|
||||||
[s]
|
[s]
|
||||||
(let [s (schema s)
|
(let [vfn (delay (validator s))]
|
||||||
vfn (delay (validator s))]
|
|
||||||
(fn [v] (@vfn v))))
|
(fn [v] (@vfn v))))
|
||||||
|
|
||||||
(defn lazy-explainer
|
(defn lazy-explainer
|
||||||
|
|
|
@ -16,54 +16,56 @@
|
||||||
|
|
||||||
(def node-types #{"root" "paragraph-set" "paragraph"})
|
(def node-types #{"root" "paragraph-set" "paragraph"})
|
||||||
|
|
||||||
(sm/register!
|
(def schema:content
|
||||||
^{::sm/type ::content}
|
[:map
|
||||||
[:map
|
[:type [:= "root"]]
|
||||||
[:type [:= "root"]]
|
[:key {:optional true} :string]
|
||||||
[:key {:optional true} :string]
|
[:children
|
||||||
[:children
|
{:optional true}
|
||||||
{:optional true}
|
[:maybe
|
||||||
[:maybe
|
[:vector {:min 1 :gen/max 2 :gen/min 1}
|
||||||
[:vector {:min 1 :gen/max 2 :gen/min 1}
|
[:map
|
||||||
[:map
|
[:type [:= "paragraph-set"]]
|
||||||
[:type [:= "paragraph-set"]]
|
[:key {:optional true} :string]
|
||||||
[:key {:optional true} :string]
|
[:children
|
||||||
[:children
|
[:vector {:min 1 :gen/max 2 :gen/min 1}
|
||||||
[:vector {:min 1 :gen/max 2 :gen/min 1}
|
[:map
|
||||||
[:map
|
[:type [:= "paragraph"]]
|
||||||
[:type [:= "paragraph"]]
|
[:key {:optional true} :string]
|
||||||
[:key {:optional true} :string]
|
[:fills {:optional true}
|
||||||
[:fills {:optional true}
|
[:maybe
|
||||||
[:maybe
|
[:vector {:gen/max 2} ::shape/fill]]]
|
||||||
[:vector {:gen/max 2} ::shape/fill]]]
|
[:font-family {:optional true} :string]
|
||||||
[:font-family {:optional true} :string]
|
[:font-size {:optional true} :string]
|
||||||
[:font-size {:optional true} :string]
|
[:font-style {:optional true} :string]
|
||||||
[:font-style {:optional true} :string]
|
[:font-weight {:optional true} :string]
|
||||||
[:font-weight {:optional true} :string]
|
[:direction {:optional true} :string]
|
||||||
[:direction {:optional true} :string]
|
[:text-decoration {:optional true} :string]
|
||||||
[:text-decoration {:optional true} :string]
|
[:text-transform {:optional true} :string]
|
||||||
[:text-transform {:optional true} :string]
|
[:typography-ref-id {:optional true} [:maybe ::sm/uuid]]
|
||||||
[:typography-ref-id {:optional true} [:maybe ::sm/uuid]]
|
[:typography-ref-file {:optional true} [:maybe ::sm/uuid]]
|
||||||
[:typography-ref-file {:optional true} [:maybe ::sm/uuid]]
|
[:children
|
||||||
[:children
|
[:vector {:min 1 :gen/max 2 :gen/min 1}
|
||||||
[:vector {:min 1 :gen/max 2 :gen/min 1}
|
[:map
|
||||||
[:map
|
[:text :string]
|
||||||
[:text :string]
|
[:key {:optional true} :string]
|
||||||
[:key {:optional true} :string]
|
[:fills {:optional true}
|
||||||
[:fills {:optional true}
|
[:maybe
|
||||||
[:maybe
|
[:vector {:gen/max 2} ::shape/fill]]]
|
||||||
[:vector {:gen/max 2} ::shape/fill]]]
|
[:font-family {:optional true} :string]
|
||||||
[:font-family {:optional true} :string]
|
[:font-size {:optional true} :string]
|
||||||
[:font-size {:optional true} :string]
|
[:font-style {:optional true} :string]
|
||||||
[:font-style {:optional true} :string]
|
[:font-weight {:optional true} :string]
|
||||||
[:font-weight {:optional true} :string]
|
[:direction {:optional true} :string]
|
||||||
[:direction {:optional true} :string]
|
[:text-decoration {:optional true} :string]
|
||||||
[:text-decoration {:optional true} :string]
|
[:text-transform {:optional true} :string]
|
||||||
[:text-transform {:optional true} :string]
|
[:typography-ref-id {:optional true} [:maybe ::sm/uuid]]
|
||||||
[:typography-ref-id {:optional true} [:maybe ::sm/uuid]]
|
[:typography-ref-file {:optional true} [:maybe ::sm/uuid]]]]]]]]]]]]])
|
||||||
[:typography-ref-file {:optional true} [:maybe ::sm/uuid]]]]]]]]]]]]])
|
|
||||||
|
|
||||||
|
(sm/register! ::content schema:content)
|
||||||
|
|
||||||
|
(def valid-content?
|
||||||
|
(sm/lazy-validator schema:content))
|
||||||
|
|
||||||
(sm/register!
|
(sm/register!
|
||||||
^{::sm/type ::position-data}
|
^{::sm/type ::position-data}
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
[app.common.types.shape :as cts]
|
[app.common.types.shape :as cts]
|
||||||
[app.common.types.shape-tree :as ctst]
|
[app.common.types.shape-tree :as ctst]
|
||||||
[app.common.types.shape.layout :as ctl]
|
[app.common.types.shape.layout :as ctl]
|
||||||
|
[app.common.types.shape.text :as types.text]
|
||||||
[app.common.types.typography :as ctt]
|
[app.common.types.typography :as ctt]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
|
@ -2192,27 +2193,27 @@
|
||||||
(ptk/reify ::paste-html-text
|
(ptk/reify ::paste-html-text
|
||||||
ptk/WatchEvent
|
ptk/WatchEvent
|
||||||
(watch [_ state _]
|
(watch [_ state _]
|
||||||
(let [root (dwtxt/create-root-from-html html)
|
(let [root (dwtxt/create-root-from-html html)
|
||||||
content (tc/dom->cljs root)
|
content (tc/dom->cljs root)]
|
||||||
|
(when (types.text/valid-content? content)
|
||||||
|
(let [id (uuid/next)
|
||||||
|
width (max 8 (min (* 7 (count text)) 700))
|
||||||
|
height 16
|
||||||
|
{:keys [x y]} (calculate-paste-position state)
|
||||||
|
|
||||||
id (uuid/next)
|
shape {:id id
|
||||||
width (max 8 (min (* 7 (count text)) 700))
|
:type :text
|
||||||
height 16
|
:name (txt/generate-shape-name text)
|
||||||
{:keys [x y]} (calculate-paste-position state)
|
:x x
|
||||||
|
:y y
|
||||||
shape {:id id
|
:width width
|
||||||
:type :text
|
:height height
|
||||||
:name (txt/generate-shape-name text)
|
:grow-type (if (> (count text) 100) :auto-height :auto-width)
|
||||||
:x x
|
:content content}
|
||||||
:y y
|
undo-id (js/Symbol)]
|
||||||
:width width
|
(rx/of (dwu/start-undo-transaction undo-id)
|
||||||
:height height
|
(dwsh/create-and-add-shape :text x y shape)
|
||||||
:grow-type (if (> (count text) 100) :auto-height :auto-width)
|
(dwu/commit-undo-transaction undo-id))))))))
|
||||||
:content content}
|
|
||||||
undo-id (js/Symbol)]
|
|
||||||
(rx/of (dwu/start-undo-transaction undo-id)
|
|
||||||
(dwsh/create-and-add-shape :text x y shape)
|
|
||||||
(dwu/commit-undo-transaction undo-id))))))
|
|
||||||
|
|
||||||
(defn- paste-text
|
(defn- paste-text
|
||||||
[text]
|
[text]
|
||||||
|
|
|
@ -83,7 +83,10 @@ export function mapContentFragmentFromDocument(document, root, styleDefaults) {
|
||||||
currentNode = nodeIterator.nextNode();
|
currentNode = nodeIterator.nextNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
fragment.appendChild(currentParagraph);
|
if (currentParagraph) {
|
||||||
|
fragment.appendChild(currentParagraph);
|
||||||
|
}
|
||||||
|
|
||||||
if (fragment.children.length === 1) {
|
if (fragment.children.length === 1) {
|
||||||
const isContentInline = isContentFragmentFromDocumentInline(document);
|
const isContentInline = isContentFragmentFromDocumentInline(document);
|
||||||
if (isContentInline) {
|
if (isContentInline) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue