Skip to content

Commit

Permalink
rename device into breakpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
haroun committed Oct 3, 2024
1 parent ff18a14 commit 5ed6120
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 68 deletions.
32 changes: 16 additions & 16 deletions modules/@apostrophecms/admin-bar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ module.exports = {
pageTree: true
},
commands(self) {
const devicePreviewModeScreens = (
self.apos.asset.options.devicePreviewMode?.enable &&
self.apos.asset.options.devicePreviewMode?.screens
const breakpointPreviewModeScreens = (
self.apos.asset.options.breakpointPreviewMode?.enable &&
self.apos.asset.options.breakpointPreviewMode?.screens
) || {};
const devicePreviewModeCommands = {
[`${self.__meta.name}:toggle-device-preview-mode:exit`]: {
const breakpointPreviewModeCommands = {
[`${self.__meta.name}:toggle-breakpoint-preview-mode:exit`]: {
type: 'item',
label: {
key: 'apostrophe:commandMenuToggleDevicePreviewMode',
device: '$t(apostrophe:breakpointPreviewExit)'
key: 'apostrophe:commandMenuToggleBreakpointPreviewMode',
breakpoint: '$t(apostrophe:breakpointPreviewExit)'
},
action: {
type: 'command-menu-admin-bar-toggle-device-preview-mode',
type: 'command-menu-admin-bar-toggle-breakpoint-preview-mode',
payload: {
mode: null,
width: null,
Expand All @@ -37,20 +37,20 @@ module.exports = {
}
};
let index = 1;
for (const [ name, screen ] of Object.entries(devicePreviewModeScreens)) {
for (const [ name, screen ] of Object.entries(breakpointPreviewModeScreens)) {
// Up to 9 shortcuts available
if (index === 9) {
break;
}

devicePreviewModeCommands[`${self.__meta.name}:toggle-device-preview-mode:${name}`] = {
breakpointPreviewModeCommands[`${self.__meta.name}:toggle-breakpoint-preview-mode:${name}`] = {
type: 'item',
label: {
key: 'apostrophe:commandMenuToggleDevicePreviewMode',
device: `$t(${screen.label})`
key: 'apostrophe:commandMenuToggleBreakpointPreviewMode',
breakpoint: `$t(${screen.label})`
},
action: {
type: 'command-menu-admin-bar-toggle-device-preview-mode',
type: 'command-menu-admin-bar-toggle-breakpoint-preview-mode',
payload: {
mode: name,
label: `$t(${screen.label})`,
Expand Down Expand Up @@ -114,7 +114,7 @@ module.exports = {
},
shortcut: 'Ctrl+Shift+D Meta+Shift+D'
},
...devicePreviewModeCommands
...breakpointPreviewModeCommands
},
modal: {
default: {
Expand All @@ -132,7 +132,7 @@ module.exports = {
commands: [
`${self.__meta.name}:toggle-edit-preview-mode`,
`${self.__meta.name}:toggle-published-draft-document`,
...Object.keys(devicePreviewModeCommands)
...Object.keys(breakpointPreviewModeCommands)
]
}
}
Expand Down Expand Up @@ -407,7 +407,7 @@ module.exports = {
aposLocale: context.aposLocale,
aposDocId: context.aposDocId
},
devicePreviewMode: self.apos.asset.options.devicePreviewMode ||
breakpointPreviewMode: self.apos.asset.options.breakpointPreviewMode ||
{
enable: false,
debug: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<template>
<div
data-apos-test="devicePreviewMode"
class="apos-admin-bar__device-preview-mode"
data-apos-test="breakpointPreviewMode"
class="apos-admin-bar__breakpoint-preview-mode"
>
<component
:is="'AposButton'"
v-for="(screen, name) in screens"
:key="name"
:data-apos-test="`devicePreviewMode:${name}`"
:data-apos-test="`breakpointPreviewMode:${name}`"
:modifiers="['small', 'no-motion']"
:label="screen.label"
:title="$t(screen.label)"
:icon="screen.icon"
:icon-only="true"
type="subtle"
class="apos-admin-bar__device-preview-mode-button"
class="apos-admin-bar__breakpoint-preview-mode-button"
:class="{ 'apos-is-active': mode === name }"
@click="toggleDevicePreviewMode({ mode: name, label: screen.label, width: screen.width, height: screen.height })"
@click="toggleBreakpointPreviewMode({ mode: name, label: screen.label, width: screen.width, height: screen.height })"
/>
</div>
</template>
<script>
export default {
name: 'TheAposContextDevicePreview',
name: 'TheAposContextBreakpointPreviewMode',
props: {
// { screenName: { label: string, width: string, height: string, icon: string } }
screens: {
Expand All @@ -45,43 +45,43 @@ export default {
default: false
}
},
emits: [ 'switch-device-preview-mode', 'reset-device-preview-mode' ],
emits: [ 'switch-breakpoint-preview-mode', 'reset-breakpoint-preview-mode' ],
data() {
return {
mode: null,
originalBodyBackground: null
};
},
mounted() {
apos.bus.$on('command-menu-admin-bar-toggle-device-preview-mode', this.toggleDevicePreviewMode);
apos.bus.$on('command-menu-admin-bar-toggle-breakpoint-preview-mode', this.toggleBreakpointPreviewMode);
this.originalBodyBackground = window.getComputedStyle(document.querySelector('body'))?.background ||
'#fff';
const state = this.loadState();
if (state.mode) {
this.toggleDevicePreviewMode(state);
this.toggleBreakpointPreviewMode(state);
}
},
unmounted() {
apos.bus.$off('command-menu-admin-bar-toggle-device-preview-mode', this.toggleDevicePreviewMode);
apos.bus.$off('command-menu-admin-bar-toggle-breakpoint-preview-mode', this.toggleBreakpointPreviewMode);
},
methods: {
switchDevicePreviewMode({
switchBreakpointPreviewMode({
mode,
label,
width,
height
}) {
document.querySelector('body').setAttribute('data-device-preview-mode', mode);
document.querySelector('body').setAttribute('data-breakpoint-preview-mode', mode);
document.querySelector('[data-apos-refreshable]').setAttribute('data-resizable', this.resizable);
document.querySelector('[data-apos-refreshable]').setAttribute('data-label', this.$t(label));
document.querySelector('[data-apos-refreshable]').style.width = width;
document.querySelector('[data-apos-refreshable]').style.height = height;
document.querySelector('[data-apos-refreshable]').style.background = this.originalBodyBackground;
this.mode = mode;
this.$emit('switch-device-preview-mode', {
this.$emit('switch-breakpoint-preview-mode', {
mode,
label,
width,
Expand All @@ -94,36 +94,36 @@ export default {
height
});
},
toggleDevicePreviewMode({
toggleBreakpointPreviewMode({
mode,
label,
width,
height
}) {
if (this.mode === mode || mode === null) {
document.querySelector('body').removeAttribute('data-device-preview-mode');
document.querySelector('body').removeAttribute('data-breakpoint-preview-mode');
document.querySelector('[data-apos-refreshable]').removeAttribute('data-resizable');
document.querySelector('[data-apos-refreshable]').removeAttribute('data-label');
document.querySelector('[data-apos-refreshable]').style.removeProperty('width');
document.querySelector('[data-apos-refreshable]').style.removeProperty('height');
document.querySelector('[data-apos-refreshable]').style.removeProperty('background');
this.mode = null;
this.$emit('reset-device-preview-mode');
this.$emit('reset-breakpoint-preview-mode');
this.saveState({ mode: this.mode });
return;
}
this.switchDevicePreviewMode({
this.switchBreakpointPreviewMode({
mode,
label,
width,
height
});
},
loadState() {
return JSON.parse(sessionStorage.getItem('aposDevicePreviewMode') || '{}');
return JSON.parse(sessionStorage.getItem('aposBreakpointPreviewMode') || '{}');
},
saveState({
mode = null,
Expand All @@ -134,7 +134,7 @@ export default {
const state = this.loadState();
if (state.mode !== mode) {
sessionStorage.setItem(
'aposDevicePreviewMode',
'aposBreakpointPreviewMode',
JSON.stringify({
mode,
label,
Expand All @@ -148,13 +148,13 @@ export default {
};
</script>
<style lang="scss" scoped>
.apos-admin-bar__device-preview-mode {
.apos-admin-bar__breakpoint-preview-mode {
display: flex;
gap: $spacing-half;
margin-left: $spacing-double;
}
.apos-admin-bar__device-preview-mode-button {
.apos-admin-bar__breakpoint-preview-mode-button {
&.apos-is-active {
color: var(--a-text-primary);
text-decoration: none;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
:tooltip="tooltip"
:modifiers="modifiers"
/>
<TheAposContextDevicePreviewMode
v-if="isDevicePreviewModeEnabled"
:screens="devicePreviewModeScreens"
:resizable="devicePreviewModeResizable"
@switch-device-preview-mode="addContextLabel"
@reset-device-preview-mode="removeContextLabel"
<TheAposContextBreakpointPreviewMode
v-if="isBreakpointPreviewModeEnabled"
:screens="breakpointPreviewModeScreens"
:resizable="breakpointPreviewModeResizable"
@switch-breakpoint-preview-mode="addContextLabel"
@reset-breakpoint-preview-mode="removeContextLabel"
/>
</span>
</transition-group>
Expand Down Expand Up @@ -101,14 +101,14 @@ export default {
isUnpublished() {
return !this.context.lastPublishedAt;
},
isDevicePreviewModeEnabled() {
return this.moduleOptions.devicePreviewMode.enable || false;
isBreakpointPreviewModeEnabled() {
return this.moduleOptions.breakpointPreviewMode.enable || false;
},
devicePreviewModeScreens() {
return this.moduleOptions.devicePreviewMode.screens || {};
breakpointPreviewModeScreens() {
return this.moduleOptions.breakpointPreviewMode.screens || {};
},
devicePreviewModeResizable() {
return this.moduleOptions.devicePreviewMode.resizable || false;
breakpointPreviewModeResizable() {
return this.moduleOptions.breakpointPreviewMode.resizable || false;
},
docTooltip() {
return {
Expand Down
3 changes: 1 addition & 2 deletions modules/@apostrophecms/asset/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {
// In case of external front end like Astro, this option allows to
// disable the build of the public UI assets.
publicBundle: true,
// Device preview in the admin UI.
// Breakpoint preview in the admin UI.
// NOTE: the whole breakpointPreviewMode option must be carried over
// to the project for overrides to work properly.
// Nested object options are not deep merged in Apostrophe.
Expand Down Expand Up @@ -89,7 +89,6 @@ module.exports = {

async init(self) {

self.options.devicePreviewMode = self.options.breakpointPreviewMode || self.options.devicePreviewMode;
self.restartId = self.apos.util.generateId();
self.iconMap = {
...globalIcons
Expand Down
6 changes: 3 additions & 3 deletions modules/@apostrophecms/asset/lib/webpack/apos/webpack.scss.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const path = require('path');

module.exports = (options, apos) => {
const mediaToContainerQueriesLoader = apos.asset.options.devicePreviewMode?.enable === true
const mediaToContainerQueriesLoader = apos.asset.options.breakpointPreviewMode?.enable === true
? {
loader: path.resolve(__dirname, '../media-to-container-queries-loader.js'),
options: {
debug: apos.asset.options.devicePreviewMode?.debug === true,
transform: apos.asset.options.devicePreviewMode?.transform || null
debug: apos.asset.options.breakpointPreviewMode?.debug === true,
transform: apos.asset.options.breakpointPreviewMode?.transform || null
}
}
: '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ module.exports = function (source) {
});

// Media query
// Only apply when data-device-preview-mode is not set
// Only apply when data-breakpoint-preview-mode is not set
atRule.walkRules(rule => {
const newRule = rule.clone({
selectors: rule.selectors.map(selector => {
if (selector.startsWith('body')) {
return selector.replace('body', ':where(body:not([data-device-preview-mode]))');
return selector.replace('body', ':where(body:not([data-breakpoint-preview-mode]))');
}

return `:where(body:not([data-device-preview-mode])) ${selector}`;
return `:where(body:not([data-breakpoint-preview-mode])) ${selector}`;
})
});

Expand Down
6 changes: 3 additions & 3 deletions modules/@apostrophecms/asset/lib/webpack/src/webpack.scss.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = (options, apos, srcBuildNames) => {
const mediaToContainerQueriesLoader = apos.asset.options.devicePreviewMode?.enable === true
const mediaToContainerQueriesLoader = apos.asset.options.breakpointPreviewMode?.enable === true
? {
loader: path.resolve(__dirname, '../media-to-container-queries-loader.js'),
options: {
debug: apos.asset.options.devicePreviewMode?.debug === true,
transform: apos.asset.options.devicePreviewMode?.transform || null
debug: apos.asset.options.breakpointPreviewMode?.debug === true,
transform: apos.asset.options.breakpointPreviewMode?.transform || null
}
}
: '';
Expand Down
12 changes: 6 additions & 6 deletions modules/@apostrophecms/i18n/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
"batchPublishCompleted": "Published {{ count }} {{ type }}.",
"batchRestoreProgress": "Restoring {{ type }}...",
"batchRestoreCompleted": "Restored {{ count }} {{ type }}.",
"breakpointPreviewDesktop": "Desktop",
"breakpointPreviewExit": "Exit",
"breakpointPreviewMobile": "Mobile",
"breakpointPreviewTablet": "Tablet",
"browseDocType": "Browse {{ type }}",
"cancel": "Cancel",
"cannotChangeSlugPrefix": "cannot change the slug prefix",
Expand Down Expand Up @@ -96,10 +100,10 @@
"commandMenuSelectAll": "Select all",
"commandMenuShortcut": "Keyboard Shortcuts",
"commandMenuShowShortcutList": "Show shortcut list",
"commandMenuToggleDevicePreviewMode": "Preview: {{ device }}",
"commandMenuTaskbar": "Taskbar",
"commandMenuToggleBreakpointPreviewMode": "Preview: {{ breakpoint }}",
"commandMenuToggleEditPreviewMode": "Toggle edit / preview",
"commandMenuTogglePublishedDraftDocument": "Toggle published / draft document",
"commandMenuTaskbar": "Taskbar",
"commandMenuUndo": "Undo",
"confirmArchive": "You are going to archive the {{ type }} {{ title }}.",
"confirmSettings": "Confirm Settings",
Expand Down Expand Up @@ -127,10 +131,6 @@
"deleteTable": "Delete Table",
"description": "Description",
"deselectAll": "Deselect All",
"breakpointPreviewDesktop": "Desktop",
"breakpointPreviewExit": "Exit",
"breakpointPreviewMobile": "Mobile",
"breakpointPreviewTablet": "Tablet",
"disabled": "Disabled",
"discardChanges": "Discard Changes",
"discardChangesPrompt": "Do you want to discard changes?",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
}

body[data-device-preview-mode] {
body[data-breakpoint-preview-mode] {
background: var(--a-base-10);

[data-apos-context-label] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
@import './_tables';
@import './_tooltips';
@import './_widgets';
@import './_device_preview';
@import './_breakpoint_preview';

0 comments on commit 5ed6120

Please sign in to comment.