-
Notifications
You must be signed in to change notification settings - Fork 590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pro 6518 mobile preview #4720
Pro 6518 mobile preview #4720
Changes from all commits
38e5020
be578e8
60de087
4c20516
62fd03a
c9579c8
895fb42
7db9493
8991290
6806ded
174c897
4573f98
e52a478
bf528e8
ca2bb37
c296953
e6e4cd1
52c8cb3
129cc3a
0ac0e49
f7eaa02
070fc88
1329f7e
64e6c27
5b8b7a3
b2c051a
ec60630
bffb915
c93db00
180a12d
3b887ff
05f0f75
0d072dd
d08b8fd
f86f60a
7da9500
c8ccaac
e023214
881919b
6116ee9
adc5e6b
a363ade
ad3412a
54b2574
6d0ec03
3b30474
89524be
b04e3af
89739a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a good reason not to use Vue 3 here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to do like the existing vue components in the project |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
<template> | ||
<div | ||
data-apos-test="devicePreviewMode" | ||
class="apos-admin-bar__device-preview-mode" | ||
> | ||
<component | ||
:is="'AposButton'" | ||
v-for="(screen, name) in screens" | ||
:key="name" | ||
:data-apos-test="`devicePreviewMode:${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-is-active': mode === name }" | ||
@click="toggleDevicePreviewMode({ mode: name, label: screen.label, width: screen.width, height: screen.height })" | ||
/> | ||
</div> | ||
</template> | ||
<script> | ||
|
||
export default { | ||
name: 'TheAposContextDevicePreview', | ||
props: { | ||
// { screenName: { label: string, width: string, height: string, icon: string } } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wanted comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, to explain the expected props |
||
screens: { | ||
type: Object, | ||
validator(value, props) { | ||
return Object.values(value).every(screen => | ||
typeof screen.label === 'string' && | ||
typeof screen.width === 'string' && | ||
typeof screen.height === 'string' && | ||
typeof screen.icon === 'string' | ||
); | ||
}, | ||
default: () => { | ||
return {}; | ||
} | ||
}, | ||
resizable: { | ||
type: Boolean, | ||
default: false | ||
} | ||
}, | ||
emits: [ 'switch-device-preview-mode', 'reset-device-preview-mode' ], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't find where these are being listened to? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's not, but if you want to listen to it and do something you can |
||
data() { | ||
return { | ||
mode: null, | ||
originalBodyBackground: null | ||
}; | ||
}, | ||
mounted() { | ||
apos.bus.$on('command-menu-admin-bar-toggle-device-preview-mode', this.toggleDevicePreviewMode); | ||
|
||
this.originalBodyBackground = window.getComputedStyle(document.querySelector('body'))?.background || | ||
'#fff'; | ||
|
||
const state = this.loadState(); | ||
if (state.mode) { | ||
this.toggleDevicePreviewMode(state); | ||
} | ||
}, | ||
unmounted() { | ||
apos.bus.$off('command-menu-admin-bar-toggle-device-preview-mode', this.toggleDevicePreviewMode); | ||
}, | ||
methods: { | ||
switchDevicePreviewMode({ | ||
mode, | ||
label, | ||
width, | ||
height | ||
}) { | ||
document.querySelector('body').setAttribute('data-device-preview-mode', mode); | ||
document.querySelector('[data-apos-refreshable]').setAttribute('data-resizable', this.resizable); | ||
document.querySelector('[data-apos-refreshable]').setAttribute('data-label', this.$t(label)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we're not displaying it anymore then we can remove this line, as well as in |
||
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', { | ||
mode, | ||
label, | ||
width, | ||
height | ||
}); | ||
this.saveState({ | ||
mode, | ||
label, | ||
width, | ||
height | ||
}); | ||
}, | ||
toggleDevicePreviewMode({ | ||
mode, | ||
label, | ||
width, | ||
height | ||
}) { | ||
if (this.mode === mode || mode === null) { | ||
document.querySelector('body').removeAttribute('data-device-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.saveState({ mode: this.mode }); | ||
|
||
return; | ||
} | ||
|
||
this.switchDevicePreviewMode({ | ||
mode, | ||
label, | ||
width, | ||
height | ||
}); | ||
}, | ||
loadState() { | ||
return JSON.parse(sessionStorage.getItem('aposDevicePreviewMode') || '{}'); | ||
}, | ||
saveState({ | ||
mode = null, | ||
label = null, | ||
width = null, | ||
height = null | ||
} = {}) { | ||
const state = this.loadState(); | ||
if (state.mode !== mode) { | ||
sessionStorage.setItem( | ||
'aposDevicePreviewMode', | ||
JSON.stringify({ | ||
mode, | ||
label, | ||
width, | ||
height | ||
}) | ||
); | ||
} | ||
} | ||
} | ||
}; | ||
</script> | ||
<style lang="scss" scoped> | ||
.apos-admin-bar__device-preview-mode { | ||
display: flex; | ||
gap: $spacing-half; | ||
margin-left: $spacing-double; | ||
} | ||
|
||
.apos-admin-bar__device-preview-mode-button { | ||
&.apos-is-active { | ||
color: var(--a-text-primary); | ||
text-decoration: none; | ||
background-color: var(--a-base-10); | ||
border-radius: var(--a-border-radius); | ||
outline: 1px solid var(--a-base-7); | ||
} | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,47 @@ module.exports = { | |
rebundleModules: undefined, | ||
// In case of external front end like Astro, this option allows to | ||
// disable the build of the public UI assets. | ||
publicBundle: true | ||
publicBundle: true, | ||
// Device preview in the admin UI. | ||
// NOTE: the whole devicePreviewMode option must be carried over | ||
// to the project for override to work properly. | ||
// Nested object options are not deep merged in Apostrophe. | ||
Comment on lines
+49
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth mentioning that Option transformation feature will arrive soon? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And maybe a reference to the NOTE set in https://github.com/apostrophecms/apostrophe/pull/4720/files#diff-b6b6b266c1d47df2888216d22ec38c634e3d7266da34575319bf0ccf9d2e5131R24 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it will be in the doc, I think we will update it when this feature lands in apostrophe |
||
devicePreviewMode: { | ||
// Enable device preview mode | ||
enable: false, | ||
// Warn during build about unsupported media queries. | ||
debug: false, | ||
// If we can resize the preview container? | ||
resizable: false, | ||
// Screens with icons | ||
// For adding icons, please refer to the icons documentation | ||
// https://docs.apostrophecms.org/reference/module-api/module-overview.html#icons | ||
screens: { | ||
desktop: { | ||
label: 'apostrophe:devicePreviewDesktop', | ||
width: '1500px', | ||
height: '900px', | ||
icon: 'monitor-icon' | ||
}, | ||
tablet: { | ||
label: 'apostrophe:devicePreviewTablet', | ||
width: '1024px', | ||
height: '768px', | ||
icon: 'tablet-icon' | ||
}, | ||
mobile: { | ||
label: 'apostrophe:devicePreviewMobile', | ||
width: '480px', | ||
height: '1000px', | ||
icon: 'cellphone-icon' | ||
} | ||
}, | ||
// Transform method used on media feature | ||
// Can be either: | ||
// - (mediaFeature) => { return mediaFeature.replaceAll('xx', 'yy'); } | ||
// - null | ||
transform: null | ||
} | ||
}, | ||
|
||
async init(self) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems more UX-friendly to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will not work with current keyboard shortcut listener implementation
P+0
is supposed to beP
and
0
, but it comes with additional challenges (the order you're pressing the keys is importantP+0
and0+P
should be different shortcuts)P,0
is translated toP
then
0
(you still can holdP
while pressing0
), I think this is what you're looking for.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P,[n]
is a bit slow if we want to quickly switch between modes.But it's not that bad.