Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions resources/js/components/fieldtypes/bard/BardFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,12 @@ export default {
this.loadingSet = handle;

this.fetchSet(handle)
.then(data => this._addSet(handle, index, data))
.then(data => this._addSet(handle, data))
.catch(() => this.$toast.error(__('Something went wrong')))
.finally(() => this.loadingSet = null);
},

_addSet(handle, index, data) {
_addSet(handle, data) {
const id = uniqid();
const deepCopy = JSON.parse(JSON.stringify(data.defaults));
const values = Object.assign({}, { type: handle }, deepCopy);
Expand Down Expand Up @@ -551,7 +551,9 @@ export default {
return this.fieldPathKeys
.map((key, index) => {
if (Number.isInteger(parseInt(key))) {
return data_get(this.publishContainer.values, this.fieldPathKeys.slice(0, index + 1).join('.'))?.attrs?.values.type;
let setValues = data_get(this.publishContainer.values, this.fieldPathKeys.slice(0, index + 1).join('.'));

return setValues.attrs?.values.type || setValues.type;
}

return key;
Expand Down Expand Up @@ -580,13 +582,18 @@ export default {
});
},

pasteSet(attrs) {
async pasteSet(attrs) {
const old_id = attrs.id;
const id = uniqid();
const enabled = attrs.enabled;
const values = Object.assign({}, attrs.values);

this.updateSetMeta(id, this.meta.existing[old_id] || this.meta.defaults[values.type] || {});
if (this.meta.existing[old_id]) {
this.updateSetMeta(id, this.meta.existing[old_id]);
} else {
const data = await this.fetchSet(values.type);
this.updateSetMeta(id, data.new);
}

return { id, enabled, values };
},
Expand Down
44 changes: 30 additions & 14 deletions resources/js/components/fieldtypes/bard/Set.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,36 @@ export const Set = Node.create({
new Plugin({
key: new PluginKey('setPastedTransformer'),
props: {
transformPasted: (slice) => {
const { content } = slice.content;
return new Slice(
Fragment.fromArray(
content.map((node) => {
if (node.type === type) {
return node.type.create(bard.pasteSet(node.attrs));
}
return node.copy(node.content);
}),
),
slice.openStart,
slice.openEnd,
);
handlePaste: (view, event, slice) => {
let hasSetNodes = false;
slice.content.forEach((node) => {
if (node.type === type) hasSetNodes = true;
});

if (!hasSetNodes) return false;

(async () => {
const content = [];
for (const node of slice.content.content) {
if (node.type === type) {
const newAttrs = await bard.pasteSet(node.attrs);
content.push(node.type.create(newAttrs));
} else {
content.push(node);
}
}

const newSlice = new Slice(
Fragment.fromArray(content),
slice.openStart,
slice.openEnd,
);

const tr = view.state.tr.replaceSelection(newSlice);
view.dispatch(tr);
})();

return true;
},
},
}),
Expand Down
4 changes: 3 additions & 1 deletion resources/js/components/fieldtypes/replicator/Replicator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ export default {
return this.fieldPathKeys
.map((key, index) => {
if (Number.isInteger(parseInt(key))) {
return data_get(this.publishContainer.values, this.fieldPathKeys.slice(0, index + 1).join('.'))?.type;
let setValues = data_get(this.publishContainer.values, this.fieldPathKeys.slice(0, index + 1).join('.'));

return setValues.attrs?.values.type || setValues.type;
}

return key;
Expand Down