Skip to content
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

feat(theme): add themes #1954

Draft
wants to merge 31 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8b79b72
feat(theme): add initial theming functionality
JPSchellenberg Dec 2, 2021
1f15f68
feat(theme): add theming options
JPSchellenberg Dec 3, 2021
23a9af9
Merge branch 'master' into feat/theme
JPSchellenberg Dec 18, 2021
00abcd5
refactor(theme): remove redundant styles
JPSchellenberg Dec 18, 2021
565b68b
feat(theme): add further customisation options
JPSchellenberg Dec 19, 2021
84b74f4
refactor(secondaryBackground): rename paperBackgroundColor
JPSchellenberg Dec 19, 2021
64754a5
feat(theme): add further style options
JPSchellenberg Dec 19, 2021
026228a
Merge branch 'master' into feat/theme
JPSchellenberg Dec 19, 2021
ac34e71
fix(h5pconfig): load optional settings
JPSchellenberg Dec 20, 2021
de1777e
refactor: minor issues
sr258 Feb 26, 2022
0644e3c
refactor: more elegant theme injection in player
sr258 Feb 26, 2022
f0276a7
refactor: better theme injection in editor
sr258 Feb 26, 2022
62e08bc
feat: added styles for h5p content hub
sr258 Feb 26, 2022
963e48f
test: fix test
sr258 Feb 26, 2022
137d9c8
refactor: removed hardcoded theme url
sr258 Feb 26, 2022
16ece0d
refactor: cleaned up theme file
sr258 Feb 26, 2022
ed34640
feat: added sass theme builder
sr258 Feb 26, 2022
3c11274
refactor: multi-file scss
sr258 Feb 27, 2022
1cd482d
refactor: improved scss
sr258 Feb 27, 2022
3ccbb6e
refactor: scss restructuring editor + fixes
sr258 Feb 27, 2022
d285fa0
refactor: improve theme
sr258 Feb 27, 2022
9296a8b
fix: metadata theme
sr258 Feb 27, 2022
5bd29cd
fix: better theme
sr258 Feb 27, 2022
daad3c3
feat: branching scenario editor
sr258 Feb 27, 2022
a5f5c22
fix: improved theme
sr258 Feb 27, 2022
4b60f53
refactor: more improvements to editor theme
sr258 Feb 28, 2022
fb45e42
refactor: theme improvements
sr258 Feb 28, 2022
6761f78
Merge remote-tracking branch 'origin/master' into feat/theme
sr258 Jun 17, 2022
b58cc74
test: updated snapshot
sr258 Jun 17, 2022
ff5e0e2
refactor: fixed upload test
sr258 Jun 17, 2022
66502a3
chore: update package lock
sr258 Jun 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/h5p-examples/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,16 @@
"H5P.CoursePresentation": ["H5P.MathDisplay"],
"H5P.InteractiveVideo": ["H5P.MathDisplay"],
"H5P.DragQuestion": ["H5P.MathDisplay"]
},
"theme": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Further customization options could be:

  • corner rounding other button decorations
  • font sizes and font faces
  • margins and paddings

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already planed to add those.

"backgroundColor": "#222b37",
"paperBackgroundColor": "#333d49",
"fontColor": "#ffffff",
"disabledFontColor": "#a0a0a1",
"primaryColor": "#7636dc",
"primaryContrastColor": "#ffffff",
"secondaryColor": "#3d66ff",
"secondaryContrastColor": "#ffffff",
"dividerColor": "#45505d"
}
}
3 changes: 3 additions & 0 deletions packages/h5p-examples/src/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
h5pAjaxExpressRouter,
libraryAdministrationExpressRouter,
contentTypeCacheExpressRouter,
themeRouter,
IRequestWithUser
} from '@lumieducation/h5p-express';
import H5PHtmlExporter from '@lumieducation/h5p-html-exporter';
Expand Down Expand Up @@ -148,6 +149,8 @@ const start = async (): Promise<void> => {
// (H5P.adapters.express) to function properly.
server.use(i18nextHttpMiddleware.handle(i18next));

server.use(h5pEditor.config.baseUrl, themeRouter(h5pEditor));

// The Express adapter handles GET and POST requests to various H5P
// endpoints. You can add an options object as a last parameter to configure
// which endpoints you want to use. In this case we don't pass an options
Expand Down
34 changes: 34 additions & 0 deletions packages/h5p-express/src/ThemeRouter/ThemeExpressRouter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Router, static as ExpressStatic } from 'express';

import { H5PEditor } from '@lumieducation/h5p-server';
import {
errorHandler,
undefinedOrTrue,
catchAndPassOnErrors
} from '../expressErrorHandler';

/**
* This router implements all Ajax calls necessary for the H5P (editor) client to work.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description is not correct

* Use it like this: server.use('/h5p', H5P.adapters.express(h5pEditor, path.resolve('h5p/core'), path.resolve('h5p/editor')));
* If you only want certain routes, you can specify this in the options parameter.
* @param h5pEditor the editor object
* @param h5pCorePath the path on the local disk at which the core files (of the player) can be found
* @param h5pEditorLibraryPath the path on the local disk at which the core files of the editor can be found
* @param routeOptions sets which routes you want and how to handle errors
* @param languageOverride the language to use when returning errors.
* Only has an effect if you use the i18next http middleware, as it relies on
* req.i18n.changeLanguage to be present. Defaults to auto, which means the
* a language detector must have detected language and req.t translated to the
* detected language.
*/
export default function (h5pEditor: H5PEditor): Router {
const router = Router();

// get library file
router.get(`/theme.css`, (req, res) => {
res.setHeader('content-type', 'text/css');
res.status(200).send(h5pEditor.renderTheme());
});

return router;
}
4 changes: 3 additions & 1 deletion packages/h5p-express/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import {
import h5pAjaxExpressRouter from './H5PAjaxRouter/H5PAjaxExpressRouter';
import libraryAdministrationExpressRouter from './LibraryAdministrationRouter/LibraryAdministrationExpressRouter';
import contentTypeCacheExpressRouter from './ContentTypeCacheRouter/ContentTypeCacheExpressRouter';
import themeRouter from './ThemeRouter/ThemeExpressRouter';

export {
IRequestWithLanguage,
IRequestWithUser,
IActionRequest,
h5pAjaxExpressRouter,
libraryAdministrationExpressRouter,
contentTypeCacheExpressRouter
contentTypeCacheExpressRouter,
themeRouter
};
12 changes: 10 additions & 2 deletions packages/h5p-server/src/H5PEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import defaultCopyrightSemanticsLanguageFile from '../assets/translations/copyri
import defaultMetadataSemanticsLanguageFile from '../assets/translations/metadata-semantics/en.json';
import editorAssetList from './editorAssetList.json';
import defaultRenderer from './renderers/default';
import renderTheme from './renderers/theme';
import supportedLanguageList from '../assets/editorLanguages.json';

import ContentManager from './ContentManager';
Expand Down Expand Up @@ -51,6 +52,7 @@ import {
ILumiEditorIntegration,
ISemanticsEntry,
ITemporaryFileStorage,
ITheme,
ITranslationFunction,
IUrlGenerator,
IUser
Expand Down Expand Up @@ -155,8 +157,10 @@ export default class H5PEditor {
);
}

this.globalCustomStyles =
this.options?.customization?.global?.styles || [];
this.globalCustomStyles = this.options?.customization?.global
?.styles || [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The theme should not replace the global styles; they should be concatenated I guess

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not replaced but entered as the first entry in the array .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really? From what I see it takes the global styles and if it is undefined it now takes the theme. They are not combined. The && doesn‘t work here, as this only works in React.

this.config.theme && `${this.config.baseUrl}/theme.css`
];
if (this.config.customization?.global?.editor?.styles) {
this.globalCustomStyles = this.globalCustomStyles.concat(
this.config.customization.global?.editor.styles
Expand Down Expand Up @@ -564,6 +568,10 @@ export default class H5PEditor {
return Promise.resolve(this.renderer(model));
}

public renderTheme(theme?: ITheme): string {
return renderTheme(theme || this.config.theme);
}

/**
* Stores an uploaded file in temporary storage.
* @param contentId the id of the piece of content the file is attached to;
Expand Down
1 change: 1 addition & 0 deletions packages/h5p-server/src/H5PPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export default class H5PPlayer {
),
scripts: this.listCoreScripts().concat(assets.scripts),
styles: this.listCoreStyles().concat(assets.styles),
theme: this.config.theme,
translations: {},
embedTypes: metadata.embedTypes, // TODO: check if the library supports the embed type!
user
Expand Down
2 changes: 1 addition & 1 deletion packages/h5p-server/src/editorAssetList.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"scripts/h5peditor-editor.js",
"scripts/h5peditor.js",
"language/en.js",
"scripts/h5p-hub-client.js",
"scripts/h5p-hub-client.js",
"scripts/h5peditor-semantic-structure.js",
"scripts/h5peditor-library-selector.js",
"scripts/h5peditor-fullscreen-bar.js",
Expand Down
6 changes: 5 additions & 1 deletion packages/h5p-server/src/implementation/H5PConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IH5PConfig, IKeyValueStorage } from '../types';
import { IH5PConfig, IKeyValueStorage, ITheme } from '../types';

/**
* Stores configuration options and literals that are used throughout the system.
Expand Down Expand Up @@ -104,6 +104,8 @@ export default class H5PConfig implements IH5PConfig {
public temporaryFilesUrl: string = '/temp-files';
public uuid: string = '';

public theme?: ITheme;

private storage: IKeyValueStorage;

/**
Expand Down Expand Up @@ -132,6 +134,7 @@ export default class H5PConfig implements IH5PConfig {
await this.loadSettingFromStorage('sendUsageStatistics');
await this.loadSettingFromStorage('siteType');
await this.loadSettingFromStorage('uuid');
await this.loadSettingFromStorage('theme');
return this;
}

Expand Down Expand Up @@ -160,6 +163,7 @@ export default class H5PConfig implements IH5PConfig {
await this.saveSettingToStorage('sendUsageStatistics');
await this.saveSettingToStorage('siteType');
await this.saveSettingToStorage('uuid');
await this.saveSettingToStorage('theme');
}

/**
Expand Down
1 change: 0 additions & 1 deletion packages/h5p-server/src/renderers/default.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { IEditorModel } from '../types';

export default (model: IEditorModel): string => `<html>
<head>
<meta charset="UTF-8">
Expand Down
3 changes: 2 additions & 1 deletion packages/h5p-server/src/renderers/player.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IPlayerModel } from '../types';
import generateThemeCSS from './theme';

export default (model: IPlayerModel): string => `<!doctype html>
<html class="h5p-iframe">
Expand All @@ -11,7 +12,7 @@ export default (model: IPlayerModel): string => `<!doctype html>
${model.scripts
.map((script) => `<script src="${script}"></script>`)
.join('\n ')}

<style>${generateThemeCSS(model.theme)}</style>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The theme should be optional

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is optional. When the theme is not defined it returns an empty string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought I think the way to inject the theme with the global custom style is better, as it doesn‘t require changes in the client and it will also work with the iframe embed type.

<script>
window.H5PIntegration = ${JSON.stringify(model.integration, null, 2)};
</script>
Expand Down
Loading