-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Plugins should not depend on a particular theme – aka support for multiple themes #5304
Comments
This is an RFC ofc :P @oleq @oskarwrobel @postJScriptum |
BTW, there's one more, very important, aspect. Helpers MUST NOT introduce any rules. They may introduce mixins and variables, but not final styles. Otherwise, those styles will be included in output CSS multiple times. Example of a bad helper – |
My limited brain tells me
If there comes another theme, the author must import 1. and on top of that style the form according to their needs. |
That's another thing. How a certain package might bring CSS for a certain theme... This part is super scary, but... I think that we should do whatever is possible to make it unnecessary. This means that we must first try to refactor the theme in such a way that a link will use only the generic parts of a chosen theme, not a specific theme's files. |
Related topic: ckeditor/ckeditor5-engine#872 (comment) |
TL;DR: After some research, I came up with the conclusion that the tool that handles themes in our ecosystem and solves the style duplication issue too is PostCSS. However, the migration from SASS isn't painless. Solution to the theme duplication problemThe postcss-import plugin, which is maintained by postcss comes with the I simulated multiple editor types scenario and I found out that this importer library prevents duplication that SASS cannot handle: in SASS the output is:
while postcss-importer optimizes it to
How to implement, load and optimize themes?The idea is that the ckeditor5-ui package and other packages that also provide UI components (e.g. ckeditor5-link) will define base styles only. At this moment, only ckeditor5-ui follows this rule. The base styles must be limited and as simple as possible, so any theme can build on top this foundation and achieve the expected result. The structure of ckeditor5-ui will remain almost the same
but ckeditor5-link will no longer provide an "all–in–one"
Editor packages will also follow the stylesheet–per-view rule:
Then finally, the theme package will provide stylesheets corresponding with each view, supplementing base styles with colors, fonts, borders, spacings, etc.:
How to glue the base themes in packages with the actual theme?Since PostCSS is a JavaScript tool, it's easy to write custom plugins. They can be defined as npm imports and used in I created a simple theme loader which obtains the path to the theme and for each base theme file found:
It basically does the job of the postcss-theme plugin but
The 'use strict';
const path = require( 'path' );
const postcssImport = require( 'postcss-import' );
const postcssCssnext = require( 'postcss-cssnext' );
const CKThemeImporter = require( './ck-theme-importer' );
module.exports = {
plugins: [
postcssImport(),
CKThemeImporter( {
themePath: path.resolve( __dirname, 'packages/ckedior5-theme-foo' )
} ),
postcssCssnext()
]
}; Cons of PostCSS and general migration issuesPostCSS solves our issues, allow easy extension with JavaScript plugins and feels comfortable but there's still major a pitfall of the migration. By itself, PostCSS offers nothing to make the creation and management of CSS easier. No mixins, variables, function, extends, etc.. Without plugins, PostCSS is a pass-through utility. And unfortunately, the existing plugins fall short compared our experience with SASS. The most promising plugin I think we should use is CSSNext. It offers the CSS functionality unavailable in most web browsers but slowly becoming standards. It's like Babel but for CSS. The plugin would give us variables :root {
--mainColor: red;
}
a {
color: var(--mainColor);
}
nesting, and many other useful utils to deals with colors, units, etc. It does not offer mixins, though, which is a sad news for us because ATM we rely on this feature (e.g. see the There are other plugins that offer SASS–like mixins, e.g. postcss-mixins but the functionality is limited (no if statements, no loops), and the popularity of the plugin is low. If one day the plugin becomes obsolete and it is already widespread in our ecosystem, it will be a pain to maintain it on our own or remove it without a major uproar in the community. TBH, I'd rather see fewer plugins even if that would mean our code is longer because the lower maintenance cost will pay off in the long run. CSSNext is a good start IMO because in the future, the features it provides will be supported natively by web browsers and that means a smooth transition at some point. Can we live without mixins? What other plugins could we use make our life easier? RollupI checked the integration with Rollup and the simple import postcss from 'rollup-plugin-postcss';
import resolve from 'rollup-plugin-node-resolve';
export default {
input: './src/ckeditor.js',
plugins: [
resolve(),
postcss( {
plugins: require( './postcss.config.js' ).plugins
} )
],
output: {
file: './build/rollup/ckeditor.js',
format: 'umd'
},
}; Theming vs. fast customizationA quick customization using the variables without creating a new theme should still be possible. The postcss-cssnext (CSSNext) plugin offers variable customization directly in the module.exports = {
plugins: [
...
postcssCssnext( {
features: {
customProperties: {
variables: {
ck-color-fg: "red",
ck-color-bg: "green"
}
}
}
} )
]
}; It's a similar feature to |
Docs: Migrated the snippet adapter to PostCSS (see ckeditor/ckeditor5-ui#144).
Other: Migrated the theme from SASS to PostCSS (see ckeditor/ckeditor5-ui#144). BREAKING CHANGE: The styles are no longer developed in SASS which means various `.scss` files (including variables, mixins, etc.) became unavailable. Please refer to the [Theme Customization](https://docs.ckeditor.com/ckeditor5/latest/framework/guides/ui/theme-customization.html) guide to learn more about migration to PostCSS.
Other: Migrated package styles to PostCSS. Moved the visual styles to ckeditor5-theme-lark (see ckeditor/ckeditor5-ui#144).
Other: Migrated package styles to PostCSS. Moved the visual styles to ckeditor5-theme-lark (see ckeditor/ckeditor5-ui#144).
Other: Changed the webpack configuration so the styles are processed using PostCSS instead of SASS (see ckeditor/ckeditor5-ui#144).
Other: Changed the webpack configuration so the styles are processed using PostCSS instead of SASS (see ckeditor/ckeditor5-ui#144).
Other: Changed the webpack configuration so the styles are processed using PostCSS instead of SASS (see ckeditor/ckeditor5-ui#144).
Other: Migrated the editor styles to PostCSS (see ckeditor/ckeditor5-ui#144).
Other: Migrated the editor styles to PostCSS (see ckeditor/ckeditor5-ui#144).
Other: Migrated the editor styles to PostCSS. Moved visual styles to ckeditor5-theme-lark (see ckeditor/ckeditor5-ui#144).
Other: Migrated package styles to PostCSS. Moved visual styles to ckeditor5-theme-lark (see ckeditor/ckeditor5-ui#144).
Other: Migrated package styles to PostCSS. Moved visual styles to ckeditor5-theme-lark (see ckeditor/ckeditor5-ui#144).
Other: Migrated package styles to PostCSS. Moved visual styles to ckeditor5-theme-lark (see ckeditor/ckeditor5-ui#144).
Other: Migrated package styles to PostCSS. Moved visual styles to ckeditor5-theme-lark (see ckeditor/ckeditor5-ui#144).
Other: Migrated package styles to PostCSS. Moved visual styles to ckeditor5-theme-lark (see ckeditor/ckeditor5-ui#144).
Other: Migrated package styles to PostCSS. Moved visual styles to ckeditor5-theme-lark (see ckeditor/ckeditor5-ui#144).
Other: Migrated the package styles from SASS to PostCSS to bring theme support and avoid duplicates in some editor builds. Closes #144. Closes ckeditor/ckeditor5#420. BREAKING CHANGE: The styles are no longer developed in SASS which means the `.scss` files became unavailable. Please refer to the [Theme Customization](https://docs.ckeditor.com/ckeditor5/latest/framework/guides/ui/theme-customization.html) guide to learn more about migration to PostCSS.
@oskarwrobel pointed out that the link package requires the lark package now because of this: https://github.com/ckeditor/ckeditor5-link/blob/69cc9fe393698b9689307c209f8d496e6c1f0769/theme/components/linkform.scss#L4
My first thought was – move this spacing helper to
ckeditor5-ui
because plugins should not depend on a specific theme.However, the spacing helpers shouldn't be defined by the
ckeditor5-ui
wireframe theme. So this is more complicated. A plugin's theme can depend on:@ckeditor/ckeditor5-ui/theme/*
@ckeditor/ckeditor5-theme/theme/_helpers/*
What is the second package –
ckeditor5-theme
? It's the theme which the developer chose upon running a bundler. This is the theme which all packages will import (e.g. the classic editor). It won't really exist, so the bundler will resolve its path to an existing theme.E.g. if you'd configure
CKEditorWebpackPlugin
withtheme: 'xyz'
, it would resolve all requests to@ckeditor/ckeditor5-theme
to@ckeditor/ckeditor5-theme-xyx
.This, as understood by my limited brain, will implement support for multiple themes.
The remaining bit is that every theme must import the same set of
_helpers
, so we need to standardise them. And I don't think that they should be kept in_helpers
but ratherhelpers
.PS. The tricky thing here will be to how to run this on CI ;> The default theme will need to be lark and we'll need to add it as a dev dep of packages which require any theme files.
The text was updated successfully, but these errors were encountered: