-
Notifications
You must be signed in to change notification settings - Fork 650
PRO-8493: inject admin UI styles for layout #5116
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,8 +76,10 @@ module.exports = { | |
| self.__meta.name === '@apostrophecms/layout-widget' && | ||
| self.options.injectStyles !== false | ||
| ) { | ||
| self.stylesContent = await self.loadAndProcessStyles(); | ||
| self.publicStylesContent = await self.loadAndProcessPublicStyles(); | ||
| self.aposStylesContent = await self.loadAndProcessAposStyles(); | ||
| self.appendNodes('head', 'publicCssNodes'); | ||
| self.appendNodes('head', 'aposCssNodes'); | ||
| } | ||
| }, | ||
| handlers(self) { | ||
|
|
@@ -123,7 +125,8 @@ module.exports = { | |
| attrs: { type: 'text/css' }, | ||
| body: [ | ||
| { | ||
| raw: self.stylesContent[req.scene] || self.stylesContent.public | ||
| raw: self.publicStylesContent[req.scene] || | ||
| self.publicStylesContent.public | ||
| } | ||
| ] | ||
| }, | ||
|
|
@@ -132,6 +135,28 @@ module.exports = { | |
| } | ||
| ]; | ||
| }, | ||
| aposCssNodes(req) { | ||
| if (req.scene !== 'apos') { | ||
| return []; | ||
| } | ||
| return [ | ||
| { | ||
| comment: ' Admin Layout styles ' | ||
| }, | ||
| { | ||
| name: 'style', | ||
| attrs: { type: 'text/css' }, | ||
| body: [ | ||
| { | ||
| raw: self.aposStylesContent.apos | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| comment: ' End Admin Layout styles ' | ||
| } | ||
| ]; | ||
| }, | ||
| validateAndIdentifyTypes() { | ||
| if (self.options.columns < 2) { | ||
| throw new Error('The layout widget must have at least 2 columns.'); | ||
|
|
@@ -202,8 +227,18 @@ module.exports = { | |
| column: hasTypes[self.columnWidgetName] | ||
| }; | ||
| }, | ||
| async loadAndProcessStyles() { | ||
| const cssFilePath = path.join(__dirname, 'ui', 'src', 'layout.css'); | ||
| async loadAndProcessPublicStyles() { | ||
| return self.loadAndProcessStylesFromScene({ build: 'src' }); | ||
| }, | ||
| async loadAndProcessAposStyles() { | ||
| return self.loadAndProcessStylesFromScene({ | ||
| build: 'apos', | ||
| scene: 'apos' | ||
| }); | ||
| }, | ||
| async loadAndProcessStylesFromScene({ build, scene }) { | ||
| const pathSegments = [ 'ui', build, 'layout.css' ]; | ||
| const cssFilePath = path.join(__dirname, ...pathSegments); | ||
| let cssContent = fs.readFileSync(cssFilePath, 'utf8'); | ||
| const mobileBreakpoint = self.options.mobile?.breakpoint || 600; | ||
| const mobileBreakpointPlus = mobileBreakpoint + 1; | ||
|
|
@@ -215,9 +250,9 @@ module.exports = { | |
| .replace(/\{\$tablet\}/g, tabletBreakpoint) | ||
| .replace(/\{\$tablet-plus\}/g, tabletBreakpointPlus); | ||
|
|
||
| return self.processCss(cssContent); | ||
| return self.processCss(cssContent, scene); | ||
| }, | ||
| async processCss(cssContent) { | ||
| async processCss(cssContent, scene = null) { | ||
|
Contributor
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 no scene we do both?
Contributor
Author
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. yes |
||
| try { | ||
| const postcss = require('postcss'); | ||
| const cssnano = require('cssnano'); | ||
|
|
@@ -234,10 +269,14 @@ module.exports = { | |
| } | ||
|
|
||
| if (options.enable !== true) { | ||
| return { | ||
| apos: resultPublic.css, | ||
| public: resultPublic.css | ||
| }; | ||
| return scene | ||
| ? { | ||
| [scene]: resultPublic.css | ||
| } | ||
| : { | ||
| apos: resultPublic.css, | ||
| public: resultPublic.css | ||
| }; | ||
| } | ||
|
|
||
| const mobilePreview = require('postcss-viewport-to-container-toggle'); | ||
|
|
@@ -260,10 +299,14 @@ module.exports = { | |
| ) | ||
| ]).process(cssContent, { from: undefined }); | ||
|
|
||
| return { | ||
| apos: resultApos.css, | ||
| public: resultPublic.css | ||
| }; | ||
| return scene | ||
| ? { | ||
| [scene]: scene === 'apos' ? resultApos.css : resultPublic.css | ||
| } | ||
| : { | ||
| apos: resultApos.css, | ||
| public: resultPublic.css | ||
| }; | ||
| } catch (error) { | ||
| const errorTrace = error.stack | ||
| ? error.stack | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* Tablet rules for admin interface */ | ||
| /* stylelint-disable-next-line media-feature-name-allowed-list */ | ||
| @media screen and (min-width: {$mobile-plus}px) and (max-width: {$tablet}px) { | ||
| .apos-layout__grid:not(.manage)[data-tablet-auto="true"] { | ||
| grid-template-columns: repeat(2, 1fr); | ||
|
|
||
| --grid-rows: auto; | ||
| } | ||
|
|
||
| .apos-layout__grid:not(.manage)[data-tablet-auto="true"] > .apos-layout__item { | ||
| grid-column: auto / span 1; | ||
| grid-row: auto / span 1; | ||
| order: var(--order, 0); | ||
| } | ||
|
|
||
| .apos-layout__grid:not(.manage)[data-tablet-auto="true"] > .apos-layout__item[data-tablet-full="true"] { | ||
| grid-column: 1 / span 2; | ||
| } | ||
|
|
||
| .apos-layout__grid:not(.manage)[data-tablet-auto="false"] { | ||
| --grid-rows: var(--tablet-rows, var(--grid-rows)); | ||
| } | ||
|
|
||
| .apos-layout__grid:not(.manage)[data-tablet-auto="false"] > .apos-layout__item { | ||
| grid-column: var(--tablet-colstart, auto) / span var(--tablet-colspan, 1); | ||
| grid-row: var(--tablet-rowstart, auto) / span var(--tablet-rowspan, 1); | ||
| justify-self: var(--tablet-justify); | ||
| /* stylelint-disable-next-line declaration-block-no-redundant-longhand-properties */ | ||
| align-self: var(--tablet-align); | ||
| order: var(--tablet-order, var(--order, 0)); | ||
| } | ||
|
|
||
| /* Hide items not visible on tablet */ | ||
| .apos-layout__grid:not(.manage) > .apos-layout__item[data-visible-tablet="false"] { | ||
| display: none; | ||
| } | ||
| } | ||
|
|
||
| /* Mobile rules for admin interface */ | ||
| /* stylelint-disable-next-line media-feature-name-allowed-list */ | ||
| @media screen and (max-width: {$mobile}px) { | ||
| .apos-layout__grid:not(.manage) { | ||
| grid-template-columns: 1fr; | ||
|
|
||
| --grid-rows: auto; | ||
| } | ||
|
|
||
| .apos-layout__grid:not(.manage)[data-mobile-auto="true"] > .apos-layout__item { | ||
| grid-column: auto / span 1; | ||
| grid-row: auto / span 1; | ||
| order: var(--order, 0); | ||
| } | ||
|
|
||
| /* Manual mode: use configured columns and device vars */ | ||
| .apos-layout__grid:not(.manage)[data-mobile-auto="false"] { | ||
| --grid-rows: var(--mobile-rows, var(--grid-rows)); | ||
| } | ||
|
|
||
| .apos-layout__grid:not(.manage)[data-mobile-auto="false"] > .apos-layout__item { | ||
| grid-column: var(--mobile-colstart, auto) / span var(--mobile-colspan, 1); | ||
| grid-row: var(--mobile-rowstart, auto) / span var(--mobile-rowspan, 1); | ||
| justify-self: var(--mobile-justify); | ||
| /* stylelint-disable-next-line declaration-block-no-redundant-longhand-properties */ | ||
| align-self: var(--mobile-align); | ||
| order: var(--mobile-order, var(--order, 0)); | ||
| } | ||
|
|
||
| /* Hide items not visible on mobile */ | ||
| .apos-layout__grid:not(.manage) > .apos-layout__item[data-visible-mobile="false"] { | ||
| display: none; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Detail but don't really see the need of pathSegments const
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.
I'll let it slide for now, because saving review time is a bigger win :D