| 593 | }) |
| 594 | |
| 595 | export function buildEditor ({ dynamicAreaProps, attachmentsIndex, renderHtmlForSaveRef, onFieldDrop, onFieldDestroy, editorOptions }) { |
| 596 | const FieldNode = Node.create({ |
| 597 | name: 'fieldNode', |
| 598 | inline: true, |
| 599 | group: 'inline', |
| 600 | atom: true, |
| 601 | draggable: true, |
| 602 | addAttributes () { |
| 603 | return { |
| 604 | uuid: { default: null }, |
| 605 | areaUuid: { default: null }, |
| 606 | width: { default: '124px' }, |
| 607 | height: { default: null }, |
| 608 | verticalAlign: { default: 'text-bottom' }, |
| 609 | display: { default: 'inline-flex' } |
| 610 | } |
| 611 | }, |
| 612 | parseHTML () { |
| 613 | return [{ |
| 614 | tag: 'dynamic-field', |
| 615 | getAttrs (dom) { |
| 616 | return { |
| 617 | uuid: dom.getAttribute('uuid'), |
| 618 | areaUuid: dom.getAttribute('area-uuid'), |
| 619 | width: dom.style.width, |
| 620 | height: dom.style.height, |
| 621 | display: dom.style.display, |
| 622 | verticalAlign: dom.style.verticalAlign |
| 623 | } |
| 624 | } |
| 625 | }] |
| 626 | }, |
| 627 | renderHTML ({ node }) { |
| 628 | const attrs = { |
| 629 | uuid: node.attrs.uuid, |
| 630 | 'area-uuid': node.attrs.areaUuid, |
| 631 | style: `width: ${node.attrs.width}; height: ${node.attrs.height}; display: ${node.attrs.display}; vertical-align: ${node.attrs.verticalAlign};` |
| 632 | } |
| 633 | |
| 634 | if (!renderHtmlForSaveRef.value) { |
| 635 | const fieldArea = dynamicAreaProps.findFieldArea(node.attrs.areaUuid) |
| 636 | |
| 637 | if (fieldArea?.field && fieldArea?.area) { |
| 638 | const field = JSON.parse(JSON.stringify(fieldArea.field)) |
| 639 | const area = JSON.parse(JSON.stringify(fieldArea.area)) |
| 640 | |
| 641 | delete field.areas |
| 642 | delete field.uuid |
| 643 | delete field.submitter_uuid |
| 644 | delete area.uuid |
| 645 | delete area.attachment_uuid |
| 646 | |
| 647 | attrs['data-field'] = JSON.stringify(field) |
| 648 | attrs['data-area'] = JSON.stringify(area) |
| 649 | attrs['data-template-id'] = dynamicAreaProps.template.id |
| 650 | } |
| 651 | } |
| 652 | |