Skip to content

Commit

Permalink
fix: bug with edit panel not showing
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinchappell committed Oct 21, 2024
1 parent beb475b commit a226bfa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/lib/js/components/columns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Column from './column.js'

const DEFAULT_CONFIG = {
actionButtons: {
buttons: ['clone|copy|handle', 'handle', 'remove'],
buttons: ['clone', 'handle', 'remove'],
disabled: [],
},
}
Expand Down
15 changes: 7 additions & 8 deletions src/lib/js/components/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export default class Component extends Data {
},
}
},
clone: (icons = ['copy']) => {
clone: (icons = ['copy', 'handle']) => {
return {
...dom.btnTemplate({ content: parseIcons(icons) }),
className: ['item-clone'],
Expand All @@ -214,11 +214,10 @@ export default class Component extends Data {
},
}

return this.config.actionButtons.buttons.map(btn => {
const [key, ...rest] = btn.split('|')
const icons = rest.length ? rest : undefined
return (buttonConfig[key] && buttonConfig[key](icons)) || btn
})
const { buttons, disabled } = this.config.actionButtons
const activeButtons = buttons.filter(btn => !disabled.includes(btn))

return activeButtons.map(btn => buttonConfig[btn]?.() || btn)
}

/**
Expand Down Expand Up @@ -295,7 +294,7 @@ export default class Component extends Data {

// @todo add event for onAddChild
const grandChildren = child.get('children')
if (grandChildren && grandChildren.length) {
if (grandChildren?.length) {
child.loadChildren(grandChildren)
}

Expand Down Expand Up @@ -503,7 +502,7 @@ export default class Component extends Data {
getComponent(path) {
const [type, id] = path.split('.')
const group = Components[type]
return id === this.id ? this : group && group.get(id)
return id === this.id ? this : group?.get(id)
}

value = (path, val) => {
Expand Down
18 changes: 11 additions & 7 deletions src/lib/js/components/fields/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export default class Field extends Component {
this.preview = dom.create(this.fieldPreview())
this.editPanels = []

const actionButtons = this.getActionButtons()
const hasEditButton = actionButtons.children.children.some(child => child.meta?.id === 'edit')

let field = {
tag: 'li',
attrs: {
Expand All @@ -36,10 +39,10 @@ export default class Field extends Component {
id: this.id,
children: [
this.label,
this.getActionButtons(), // fieldEdit window
this.fieldEdit, // fieldEdit window,
this.preview, // preview
],
actionButtons,
hasEditButton && this.fieldEdit, // fieldEdit window,
this.preview,
].filter(Boolean),
panelNav: this.panelNav,
dataset: {
hoverTag: i18n.get('field'),
Expand Down Expand Up @@ -224,14 +227,15 @@ export default class Field extends Component {
fieldEdit.action = {
onRender: () => {
this.resizePanelWrap()
// if (!editPanelLength) {
if (!editPanelLength) {
// If this element has no edit panels, remove the edit toggle
const field = this.dom
const editToggle = field.querySelector('.item-edit-toggle')
const fieldActions = field.querySelector('.field-actions')
const actionButtons = fieldActions.getElementsByTagName('button')
fieldActions.style.maxWidth = `${actionButtons.length * actionButtons[0].clientWidth}px`
dom.remove(editToggle)
// }
}
},
}
}
Expand All @@ -248,7 +252,7 @@ export default class Field extends Component {
prevData.id = `prev-${this.id}`

if (this.data?.config.editableContent) {
prevData.attrs = Object.assign({}, prevData.attrs, { contenteditable: true })
prevData.attrs = { ...prevData.attrs, contenteditable: true }
}

const fieldPreview = {
Expand Down

0 comments on commit a226bfa

Please sign in to comment.