Sha256: 3ff4ae3437b26b2c518969525456e3adf45017979b63e9b7e8850de9152af13f

Contents?: true

Size: 1.95 KB

Versions: 21

Compression:

Stored size: 1.95 KB

Contents

import { isBlank } from '@/misc/utils'

export default (services) => ({
  fetchSection({ commit, state: { sections } }, id) {
    const section = sections[id]
    commit('SET_SECTION', section)
    return section
  },
  hoverSection({ commit }, hoveredSection) {
    commit('SET_HOVERED_SECTION', hoveredSection)
  },
  leaveSection({ commit }) {
    commit('SET_HOVERED_SECTION', null)
  },
  addSection(
    { commit, getters, state: { site } },
    { sectionDefinition, insertAt },
  ) {
    if (sectionDefinition.insertAt) insertAt = sectionDefinition.insertAt
    const section = services.section.build(sectionDefinition, site)
    commit('ADD_SECTION', { section, insertAt })
    commit('TOUCH_SECTION', section.id)
    services.livePreview.addSection(getters.content, section, insertAt)
    return section
  },
  removeSection({ commit }, sectionId) {
    commit('REMOVE_SECTION', sectionId)
    services.livePreview.removeSection(sectionId)
  },
  updateSectionContent({ commit, getters, state: { section } }, change) {
    commit('UPDATE_SECTION_CONTENT', change)
    commit('TOUCH_SECTION', section.id)
    services.livePreview.updateSection(
      getters.content,
      getters.denormalizedSection,
      change,
    )
  },
  moveSection(
    {
      commit,
      getters,
      state: {
        page: { sections },
      },
    },
    { from, to },
  ) {
    if (isBlank(from) || isBlank(to)) return
    commit('MOVE_HOVERED_SECTION', { fromIndex: from, toIndex: to })
    services.livePreview.moveSection(
      getters.content,
      sections[from],
      sections[to],
      from < to ? 'down' : 'up',
    )
  },
  moveHoveredSection(
    {
      dispatch,
      state: {
        hoveredSection: { sectionId },
        page: { sections },
      },
    },
    direction,
  ) {
    const indices = services.section.calculateMovingIndices(
      sections,
      sectionId,
      direction,
    )
    dispatch('moveSection', { from: indices.fromIndex, to: indices.toIndex })
  },
})

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
maglevcms-1.8.0 app/frontend/editor/store/actions/section.js
maglevcms-1.7.3 app/frontend/editor/store/actions/section.js
maglevcms-1.7.2 app/frontend/editor/store/actions/section.js
maglevcms-1.7.1 app/frontend/editor/store/actions/section.js
maglevcms-1.7.0 app/frontend/editor/store/actions/section.js
maglevcms-1.6.1 app/frontend/editor/store/actions/section.js
maglevcms-1.6.0 app/frontend/editor/store/actions/section.js
maglevcms-1.5.1 app/frontend/editor/store/actions/section.js
maglevcms-1.4.0 app/frontend/editor/store/actions/section.js
maglevcms-1.3.0 app/frontend/editor/store/actions/section.js
maglevcms-1.2.2 app/frontend/editor/store/actions/section.js
maglevcms-1.2.1 app/frontend/editor/store/actions/section.js
maglevcms-1.2.0 app/frontend/editor/store/actions/section.js
maglevcms-1.1.7 app/frontend/editor/store/actions/section.js
maglevcms-1.1.6 app/frontend/editor/store/actions/section.js
maglevcms-1.1.5 app/frontend/editor/store/actions/section.js
maglevcms-1.1.4 app/frontend/editor/store/actions/section.js
maglevcms-1.1.3 app/frontend/editor/store/actions/section.js
maglevcms-1.1.2 app/frontend/editor/store/actions/section.js
maglevcms-1.1.1 app/frontend/editor/store/actions/section.js