Skip to content

Commit

Permalink
Some quick bug fixes and bandaids
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohan committed Nov 9, 2023
1 parent ea0e63a commit 718b408
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 140 deletions.
20 changes: 10 additions & 10 deletions public/js/buildamic.js

Large diffs are not rendered by default.

11 changes: 3 additions & 8 deletions resources/js/components/fieldtypes/Buildamic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,11 @@ export default {
},
},
// watch: {
// value: {
// handler(val) {
// console.log({ val });
// },
// deep: true,
// },
// },
mounted() {
Statamic.$hooks.on('entry.saved', (resolve, reject) => {
window.location.reload();
});
console.log({test: this.meta})
this.$store.dispatch("setFieldDefaults", this.meta);
this.$store.dispatch("setGlobals", this.config.globals);
Expand Down
20 changes: 17 additions & 3 deletions resources/js/components/sections/SectionSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@
@input="boxed_layout = $event"
:key="boxed_layout"
/>
<label>Inner Container?</label>
<toggle-fieldtype
:config="{
handle: 'section_inner_container',
}"
:value="inner_container"
@input="inner_container = $event"
:key="inner_container"
/>
</div>
</template>
</design-tab>
Expand Down Expand Up @@ -41,9 +50,6 @@ export default {
columns: this.field.value,
};
},
mounted() {
console.log({ boxed: this.boxed_layout });
},
computed: {
boxed_layout: {
get() {
Expand All @@ -54,6 +60,14 @@ export default {
this.updateField({ path: `boxed_layout`, val: $event });
},
},
inner_container: {
get() {
return this.getDeep("inner_container");
},
set($event) {
this.updateField({ path: `inner_container`, val: $event });
},
},
},
components: {
OptionsTab,
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/shared/FieldBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default {
: this.field.value[handle];
value.forEach((_, i) => {
return replicator.fields.forEach((field) => {
return replicator.fields?.forEach((field) => {
if (!field.validate) return false;
const field_value = value[i][field.handle];
formData[`${field.handle}-${i}`] = {};
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/shared/ModuleControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,4 @@ export default {
},
},
};
</script>
</script>
2 changes: 1 addition & 1 deletion resources/js/components/shared/SettingStack.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ export default {
};
</script>
<style></style>
<style></style>
28 changes: 14 additions & 14 deletions resources/js/factories/modules/row.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { InlineDefaults, AttributeDefaults } from './moduleDefaults.js'
import { createModule } from "./moduleFactory";
import { createModule } from "./moduleFactory.js";

const Row = function ({ UUID, ADMIN_LABEL }) {

// We are including a column by default
const column = createModule('Column');
// We are including a column by default
const column = createModule('Column');

this.uuid = `${UUID}`
this.type = 'row'
this.config = {
enabled: true,
buildamic_settings: {
admin_label: ADMIN_LABEL || this.type,
column_count_total: 12,
inline: { ...JSON.parse(JSON.stringify(InlineDefaults)) },
attributes: { ...JSON.parse(JSON.stringify(AttributeDefaults)) }
}
this.uuid = `${UUID}`
this.type = 'row'
this.config = {
enabled: true,
buildamic_settings: {
admin_label: ADMIN_LABEL || this.type,
column_count_total: 12,
inline: { ...JSON.parse(JSON.stringify(InlineDefaults)) },
attributes: { ...JSON.parse(JSON.stringify(AttributeDefaults)) }
}
this.value = [column]
}
this.value = [column]
}

export { Row }
28 changes: 14 additions & 14 deletions resources/js/factories/modules/section.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { InlineDefaults, AttributeDefaults } from './moduleDefaults.js'
import { createModule } from "./moduleFactory";
import { createModule } from "./moduleFactory.js";

const Section = function ({ UUID, ADMIN_LABEL }) {

// Wea
const row = createModule('Row');
// Wea
const row = createModule('Row');

this.uuid = `${UUID}`
this.type = 'section'
this.config = {
enabled: true,
buildamic_settings: {
admin_label: ADMIN_LABEL || this.type,
inline: { ...JSON.parse(JSON.stringify(InlineDefaults)) },
boxed_layout: true,
attributes: { ...JSON.parse(JSON.stringify(AttributeDefaults)) }
}
this.uuid = `${UUID}`
this.type = 'section'
this.config = {
enabled: true,
buildamic_settings: {
admin_label: ADMIN_LABEL || this.type,
inline: { ...JSON.parse(JSON.stringify(InlineDefaults)) },
boxed_layout: true,
attributes: { ...JSON.parse(JSON.stringify(AttributeDefaults)) }
}
this.value = [row]
}
this.value = [row]
}

export { Section }
174 changes: 87 additions & 87 deletions resources/js/mixins/OptionsFields.js
Original file line number Diff line number Diff line change
@@ -1,106 +1,106 @@
import resolveConfig from "tailwindcss/resolveConfig";
import resolveConfig from "tailwindcss/resolveConfig.js";
import tailwindConfig from "../../../tailwind.config.js";
import { InlineDefaults, AttributeDefaults } from '../factories/modules/moduleDefaults';
import { InlineDefaults, AttributeDefaults } from '../factories/modules/moduleDefaults.js';
const fullConfig = resolveConfig(tailwindConfig);
import { getDeep, setDeep, mergeDeep } from '../functions/objectHelpers'
import { getDeep, setDeep, mergeDeep } from '../functions/objectHelpers.js'
import { mapGetters, mapActions } from 'vuex'
import { bus } from '../eventBus'
import { bus } from '../eventBus.js'

const removeXSPrefixFromValue = (value) => {
return value.indexOf(':') === -1 ? value : value.split(':')[1];
return value.indexOf(':') === -1 ? value : value.split(':')[1];
}

export default {
data() {
return {
reactiveTick: 0
}
data() {
return {
reactiveTick: 0
}
},
computed: {
...mapGetters(["breakpoint", "dirtyFields"]),
settings() {
return this.field.config.buildamic_settings
}
},
created: function () {
this.setDirtyFields([]);
if (this.field) {
// Backwards Compatibility with older versions of the addon
if (!this.settings?.inline || InlineDefaults.version !== this.settings.inline?.version) {
this.setInlineDefaults();
}
if (!this.settings?.attributes || AttributeDefaults.version !== this.settings.attributes?.version) {
this.setAttributeDefaults();
}
}
},
methods: {
...mapActions(['setDirtyFields']),
setDeep,
getDeep(e, obj = this.settings) {
const val = getDeep(obj, e);
return val ? val : false
},
computed: {
...mapGetters(["breakpoint", "dirtyFields"]),
settings() {
return this.field.config.buildamic_settings
}
saveFields() {
return true
},
created: function () {
this.setDirtyFields([]);
if (this.field) {
// Backwards Compatibility with older versions of the addon
if (!this.settings?.inline || InlineDefaults.version !== this.settings.inline?.version) {
this.setInlineDefaults();
}
if (!this.settings?.attributes || AttributeDefaults.version !== this.settings.attributes?.version) {
this.setAttributeDefaults();
}
}
},
methods: {
...mapActions(['setDirtyFields']),
setDeep,
getDeep(e, obj = this.settings) {
const val = getDeep(obj, e);
return val ? val : false
},
saveFields() {
return true
},
updateField({ obj = this.settings, path, type = null, key = '', val, vm = this }, responsive = false) {
if (type === 'asset' && !val.length) return
const fullPath = responsive ? `${path}.${this.breakpoint}` : path
updateField({ obj = this.settings, path, type = null, key = '', val, vm = this }, responsive = false) {
if (type === 'asset' && !val.length) return
const fullPath = responsive ? `${path}.${this.breakpoint}` : path

// We have an XS option for responsive sizes but tailwind has no prefix for the smallest size so
// we need to remove xs from the value
if (responsive && typeof val === 'string' && val !== 'none' && val && this.breakpoint === 'xs') {
val = removeXSPrefixFromValue(val);
}
// We have an XS option for responsive sizes but tailwind has no prefix for the smallest size so
// we need to remove xs from the value
if (responsive && typeof val === 'string' && val !== 'none' && val && this.breakpoint === 'xs') {
val = removeXSPrefixFromValue(val);
}

// When choosing the "none" option in select fields, remove the value
if (val === 'none') {
val = ''
}
// When choosing the "none" option in select fields, remove the value
if (val === 'none') {
val = ''
}

// Get the fields value when first opening the stack and add that
// to the dirty fields array allowing reverting changes if not saved.
const existingIndex = this.dirtyFields.findIndex(el => el.obj.uuid, obj.uuid);
const oldValue = { obj, fullPath, val: (getDeep(obj, fullPath) ?? '') };
if (existingIndex === -1) {
this.setDirtyFields([...this.dirtyFields, oldValue]);
}
// Get the fields value when first opening the stack and add that
// to the dirty fields array allowing reverting changes if not saved.
const existingIndex = this.dirtyFields.findIndex(el => el.obj.uuid, obj.uuid);
const oldValue = { obj, fullPath, val: (getDeep(obj, fullPath) ?? '') };
if (existingIndex === -1) {
this.setDirtyFields([...this.dirtyFields, oldValue]);
}

// Set the value in pagebuilder JSON and validate the field
setDeep(obj, fullPath, val);
this.$nextTick(() => {
bus.$emit('validate-fields', path.split('.').pop());
})
// Set the value in pagebuilder JSON and validate the field
setDeep(obj, fullPath, val);
this.$nextTick(() => {
bus.$emit('validate-fields', path.split('.').pop());
})

this.reactiveTick++;
},
updateMeta({ obj = this.settings, path, val }, responsive = false) {
const fullPath = responsive ? `${path}.${this.breakpoint}` : path
if (fullPath) {
setDeep(obj, fullPath, val);
}
},
getTWClasses(type, prefix) {
const options = Object.entries(fullConfig.theme[type]).reduce(
(acc, [key, val]) => {
if (key.charAt(0) !== '-') {
acc[`${prefix}-${key}`] = `${prefix}-${key}`;
} else {
acc[`-${prefix}${key}`] = `-${prefix}${key}`;
}
return acc;
},
{}
);
return Object.assign({ 'none': 'N/A' }, options);
},
setInlineDefaults() {
this.setDeep(this.settings, 'inline', mergeDeep(JSON.parse(JSON.stringify(InlineDefaults)), (this.settings?.inline || {})));
this.reactiveTick++;
},
updateMeta({ obj = this.settings, path, val }, responsive = false) {
const fullPath = responsive ? `${path}.${this.breakpoint}` : path
if (fullPath) {
setDeep(obj, fullPath, val);
}
},
getTWClasses(type, prefix) {
const options = Object.entries(fullConfig.theme[type]).reduce(
(acc, [key, val]) => {
if (key.charAt(0) !== '-') {
acc[`${prefix}-${key}`] = `${prefix}-${key}`;
} else {
acc[`-${prefix}${key}`] = `-${prefix}${key}`;
}
return acc;
},
setAttributeDefaults() {
this.setDeep(this.settings, 'attributes', mergeDeep(JSON.parse(JSON.stringify(AttributeDefaults)), (this.settings?.attributes || {})));
}
{}
);
return Object.assign({ 'none': 'N/A' }, options);
},
setInlineDefaults() {
this.setDeep(this.settings, 'inline', mergeDeep(JSON.parse(JSON.stringify(InlineDefaults)), (this.settings?.inline || {})));
},
setAttributeDefaults() {
this.setDeep(this.settings, 'attributes', mergeDeep(JSON.parse(JSON.stringify(AttributeDefaults)), (this.settings?.attributes || {})));
}
},

}
2 changes: 1 addition & 1 deletion resources/views/layouts/section.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@php
$boxed = $section->buildamicSetting('boxed_layout') ? true : false;
$boxed = $section->buildamicSetting('boxed_layout') ? true : ($section->buildamicSetting('inner_container') ? true : false);
$background_image = $section->computedAttribute('background_image') ?? null;
$background_video = $section->computedAttribute('background_video') ?? null;
$mp4 = $background_video['mp4'][0] ?? null;
Expand Down

0 comments on commit 718b408

Please sign in to comment.