-
-
Notifications
You must be signed in to change notification settings - Fork 703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Put cloneData function for slate block, in order to change the uuids of fragments #5518
base: main
Are you sure you want to change the base?
Changes from 11 commits
6cdacde
ff4d5b7
a687633
2018042
707fb03
ed7f975
c616845
aff3697
511e99d
6d2af88
122322b
b756359
a5ffdba
4892569
8803484
8ba748d
6e4c175
d29d9d9
6d67579
fdec971
5df64d1
c74033c
f3cef86
2b66e67
f193a9f
c55caae
ee15648
05aabd6
20680f6
d3ae95e
c6e7ef4
f98b7a6
d62d505
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
When copying a text block—implemented in Slate—that contains UUIDs attached to elements in the data, the UUIDs get copied into the new block, making them not unique. Now instead of duplicating the UUIDs, a new UUID will be generated and assigned to the copy, preserving uniqueness. @dobr1408 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ import TextBlockView from './TextBlockView'; | |
import TextBlockEdit from './TextBlockEdit'; | ||
import TextBlockSchema from './TextBlockSchema'; | ||
|
||
import { nanoid } from '@plone/volto-slate/utils'; | ||
import { v4 as uuid } from 'uuid'; | ||
|
||
import { | ||
goDown, | ||
goUp, | ||
|
@@ -118,6 +121,27 @@ export default function applyConfig(config) { | |
addPermission: [], | ||
view: [], | ||
}, | ||
cloneData: (data) => { | ||
return [ | ||
uuid(), | ||
{ | ||
...data, | ||
value: [ | ||
...(data?.value || []).map((c) => { | ||
return { | ||
...c, | ||
children: (c?.children || []).map((childrenData) => { | ||
return { | ||
...childrenData, | ||
data: { ...childrenData.data, uid: nanoid(5) }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will add a uid even if there wasn't one there before; is that what we want? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that all children have uid by default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I don't think so. I have not seen it before. |
||
}; | ||
}), | ||
}; | ||
}), | ||
], | ||
}, | ||
]; | ||
}, | ||
blockHasValue: (data) => { | ||
// TODO: this should be handled better | ||
return data && !!data.plaintext?.trim(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this add
children
to nodes that should not have it, like text nodes?I would really like to see a test for this feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this is true, I will modify, and add tests