From b726aecf82e588d87efbddbd82216f5949fc834a Mon Sep 17 00:00:00 2001 From: Sebastian Rettig Date: Sun, 8 Dec 2024 18:59:33 +0100 Subject: [PATCH 1/3] chore: updated to core 1.27.0 and editor moodle-1.27.0 --- packages/h5p-rest-example-server/package.json | 2 +- .../assets/defaultClientStrings.json | 11 +++- .../assets/translations/client/en.json | 9 +++- packages/h5p-server/src/SemanticsEnforcer.ts | 51 +++++++++++-------- packages/h5p-server/src/editorAssetList.json | 6 +-- .../src/implementation/H5PConfig.ts | 4 +- packages/h5p-server/src/playerAssetList.json | 9 ++-- scripts/install.sh | 2 +- 8 files changed, 61 insertions(+), 33 deletions(-) diff --git a/packages/h5p-rest-example-server/package.json b/packages/h5p-rest-example-server/package.json index e8a4a66d3..6f2935725 100644 --- a/packages/h5p-rest-example-server/package.json +++ b/packages/h5p-rest-example-server/package.json @@ -7,7 +7,7 @@ "scripts": { "build": "npx tsc -P ./tsconfig.build.json", "clean": "rm -rf h5p && rm -rf build && rm -rf coverage && rm -rf node_modules", - "prepare": "sh download-core.sh c79f97a16fd8c6fc0232c10d5bed5b94502ee9e9 c886fa6ded498bbe0148e9484f9b1534facc264e", + "prepare": "sh download-core.sh 829524eaf81fe3f3a295d0e843812be4735f51fc 80b3b281ee9d064b563f242e8ee7a0026b5bf205", "start:watch": "npx ts-node-dev --deps --respawn src/index.ts", "start": "npx ts-node -P ./tsconfig.build.json src/index.ts", "start:shared-state:watch": "npx ts-node-dev --deps --respawn src/indexSharedState.ts", diff --git a/packages/h5p-server/assets/defaultClientStrings.json b/packages/h5p-server/assets/defaultClientStrings.json index 80928fa04..1b3321292 100644 --- a/packages/h5p-server/assets/defaultClientStrings.json +++ b/packages/h5p-server/assets/defaultClientStrings.json @@ -162,5 +162,12 @@ "emailAddressDescription": "client:emailAddressDescription", "copyrightWarning": "client:copyrightWarning", "keywordsExits": "client:keywordsExits", - "someKeywordsExits": "client:someKeywordsExits" -} + "someKeywordsExits": "client:someKeywordsExits", + "width": "client:width", + "height": "client:height", + "rotateLeft": "client:rotateLeft", + "rotateRight": "client:rotateRight", + "cropImage": "client:cropImage", + "confirmCrop": "client:confirmCrop", + "cancelCrop": "client:cancelCrop" +} \ No newline at end of file diff --git a/packages/h5p-server/assets/translations/client/en.json b/packages/h5p-server/assets/translations/client/en.json index b30ed4afa..5dd01d3d1 100644 --- a/packages/h5p-server/assets/translations/client/en.json +++ b/packages/h5p-server/assets/translations/client/en.json @@ -162,5 +162,12 @@ "emailAddressDescription": "The email address will be used by H5P to reach out to the publisher in case of any issues with the content or in case the publisher needs to recover their account. It will not be published or shared with any third parties", "copyrightWarning": "Copyrighted material cannot be shared in the H5P Content Hub. If the content is licensed with a OER friendly license like Creative Commons, please choose the appropriate license. If not this content cannot be shared.", "keywordsExits": "Keywords already exists!", - "someKeywordsExits": "Some of these keywords already exist" + "someKeywordsExits": "Some of these keywords already exist", + "width": "width", + "height": "height", + "rotateLeft": "Rotate Left", + "rotateRight": "Rotate Right", + "cropImage": "Crop Image", + "confirmCrop": "Confirm Crop", + "cancelCrop": "Cancel Crop" } diff --git a/packages/h5p-server/src/SemanticsEnforcer.ts b/packages/h5p-server/src/SemanticsEnforcer.ts index ad11235d4..8c810f930 100644 --- a/packages/h5p-server/src/SemanticsEnforcer.ts +++ b/packages/h5p-server/src/SemanticsEnforcer.ts @@ -160,10 +160,13 @@ export default class SemanticsEnforcer { 'td', 'th', 'colgroup', + 'col', 'thead', 'tbody', 'tfoot', - 'caption' + 'caption', + 'figure', + 'figcaption' ]; } if (allowedTags.includes('strong')) { @@ -201,17 +204,17 @@ export default class SemanticsEnforcer { allowedStyles['font-size'] = [/^[0-9.]+(em|px|%)$/i]; } if (semantics.font.family) { - allowedStyles['font-family'] = [/^[-a-z0-9," ]+$/i]; + allowedStyles['font-family'] = [/^[-a-z0-9,\'&; ]+$/i]; } if (semantics.font.color) { // eslint-disable-next-line @typescript-eslint/dot-notation allowedStyles['color'] = [ - /^(#[a-f0-9]{3}[a-f0-9]{3}?|rgba?\([0-9, ]+\))$/i + /^(#[a-f0-9]{3}[a-f0-9]{3}?|rgba?\([0-9, ]+\)|hsla?\([0-9,.% ]+\)) *;?$/i ]; } if (semantics.font.background) { allowedStyles['background-color'] = [ - /^(#[a-f0-9]{3}[a-f0-9]{3}?|rgba?\([0-9, ]+\))$/i + /^(#[a-f0-9]{3}[a-f0-9]{3}?|rgba?\([0-9, ]+\)|hsla?\([0-9,.% ]+\)) *;?$/i ]; } if (semantics.font.spacing) { @@ -225,19 +228,27 @@ export default class SemanticsEnforcer { const tableCellStyle = allowedTags.includes('table') ? { - 'white-space': [/^(nowrap)|(normal)|(pre)$/i], - 'text-align': [/^(center|left|right|justify)$/i], - 'vertical-align': [ - /^(baseline)|(text-top)|(text-bottom)|(sub)|(super)$/i + border: [ + /^[0-9.]+(em|px|%|) *(none|solid|dotted|dashed|double|groove|ridge|inset|outset) *(#[a-f0-9]{3}[a-f0-9]{3}?|rgba?\([0-9, ]+\)|hsla?\([0-9,.% ]+\))$/i ], - height: [/^[0-9.]+(em|px|%)$/i], + 'border-style': [ + /^(none|solid|dotted|dashed|double|groove|ridge|inset|outset)$/i + ], + 'border-width': [/^[0-9.]+(em|px|%)$/i], + 'border-color': [ + /^(#[a-f0-9]{3}[a-f0-9]{3}?|rgba?\([0-9, ]+\)|hsla?\([0-9,.% ]+\))$/i + ], + 'vertical-align': [/^(middle|top|bottom)$/i], + padding: [/^[0-9.]+(em|px|%|)$/i], width: [/^[0-9.]+(em|px|%)$/i], + height: [/^[0-9.]+(em|px|%)$/i], + float: [/(right|left|none)/i], + 'border-collapse': [/^collapse$/i], 'background-color': [ - /^(#[a-f0-9]{3}[a-f0-9]{3}?|rgba?\([0-9, ]+\))$/i + /^(#[a-f0-9]{3}[a-f0-9]{3}?|rgba?\([0-9, ]+\)|hsla?\([0-9,.% ]+\))$/i ], - 'border-color': [ - /^(#[a-f0-9]{3}[a-f0-9]{3}?|rgba?\([0-9, ]+\))$/i - ] + 'white-space': [/^(nowrap)|(normal)|(pre)$/i], + 'text-align': [/^(center|left|right|justify)$/i] } : undefined; @@ -261,14 +272,14 @@ export default class SemanticsEnforcer { }, allowedStyles: { '*': allowedStyles, - table: allowedTags.includes('table') - ? { - height: [/^[0-9.]+(em|px|%)$/i], - width: [/^[0-9.]+(em|px|%)$/i] - } - : undefined, + table: tableCellStyle, td: tableCellStyle, - th: tableCellStyle + th: tableCellStyle, + colgroup: tableCellStyle, + col: tableCellStyle, + caption: tableCellStyle, + figure: tableCellStyle, + figcaption: tableCellStyle } }); } diff --git a/packages/h5p-server/src/editorAssetList.json b/packages/h5p-server/src/editorAssetList.json index 62556665c..a9b8e84fe 100644 --- a/packages/h5p-server/src/editorAssetList.json +++ b/packages/h5p-server/src/editorAssetList.json @@ -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", @@ -64,11 +64,11 @@ "styles/h5p-core-button.css" ], "editor": [ - "libs/darkroom.css", + "libs/cropper.css", "styles/css/h5p-hub-client.css", "styles/css/fonts.css", "styles/css/application.css", "styles/css/libs/zebra_datepicker.min.css" ] } -} +} \ No newline at end of file diff --git a/packages/h5p-server/src/implementation/H5PConfig.ts b/packages/h5p-server/src/implementation/H5PConfig.ts index ee07b4bc2..24635f3fa 100644 --- a/packages/h5p-server/src/implementation/H5PConfig.ts +++ b/packages/h5p-server/src/implementation/H5PConfig.ts @@ -34,7 +34,7 @@ export default class H5PConfig implements IH5PConfig { 'json png jpg jpeg gif bmp tif tiff svg eot ttf woff woff2 otf webm mp4 ogg mp3 m4a wav txt pdf rtf doc docx xls xlsx ppt pptx odt ods odp xml csv diff patch swf md textile vtt webvtt gltf glb'; public coreApiVersion: { major: number; minor: number } = { major: 1, - minor: 26 + minor: 27 }; public coreUrl: string = '/core'; public customization: { @@ -69,7 +69,7 @@ export default class H5PConfig implements IH5PConfig { public enableLrsContentTypes: boolean = true; public exportMaxContentPathLength: number = 255; public fetchingDisabled: 0 | 1 = 0; - public h5pVersion: string = '1.24-master'; + public h5pVersion: string = '1.27.0'; public hubContentTypesEndpoint: string = 'https://api.h5p.org/v1/content-types/'; public hubRegistrationEndpoint: string = 'https://api.h5p.org/v1/sites'; diff --git a/packages/h5p-server/src/playerAssetList.json b/packages/h5p-server/src/playerAssetList.json index 4d0b24918..7efac3f46 100644 --- a/packages/h5p-server/src/playerAssetList.json +++ b/packages/h5p-server/src/playerAssetList.json @@ -9,14 +9,17 @@ "js/h5p-content-type.js", "js/h5p-confirmation-dialog.js", "js/h5p-action-bar.js", - "js/request-queue.js" + "js/request-queue.js", + "js/h5p-tooltip.js" ] }, "styles": { "core": [ "styles/h5p.css", "styles/h5p-confirmation-dialog.css", - "styles/h5p-core-button.css" + "styles/h5p-core-button.css", + "styles/h5p-tooltip.css", + "styles/h5p-table.css" ] } -} +} \ No newline at end of file diff --git a/scripts/install.sh b/scripts/install.sh index 35a9a1ea4..0ee934d99 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,7 +1,7 @@ # If the editor and core files are missing, we download them from GitHub. if [ ! -d "packages/h5p-examples/h5p/editor" ] || [ ! -d "packages/h5p-examples/h5p/core" ] then - sh packages/h5p-examples/download-core.sh f3579c0d28205bf34490ee151c07d43a2ffc3507 0365b081efa8b55ab9fd58594aa599f9630268f6 + sh packages/h5p-examples/download-core.sh 829524eaf81fe3f3a295d0e843812be4735f51fc 80b3b281ee9d064b563f242e8ee7a0026b5bf205 else echo "Not downloading H5P Core and Editor files as they are already present!" fi From d2bc924c2ea4f55b0d41a9a7c5171935ca676b18 Mon Sep 17 00:00:00 2001 From: Sebastian Rettig Date: Sun, 8 Dec 2024 19:40:22 +0100 Subject: [PATCH 2/3] test: fixed tests --- .../test/H5PPlayer.loadDependencies.test.ts | 23 ++-- .../H5PPlayer.renderHtmlPage.test.ts.snap | 126 +++++++++++------- 2 files changed, 89 insertions(+), 60 deletions(-) diff --git a/packages/h5p-server/test/H5PPlayer.loadDependencies.test.ts b/packages/h5p-server/test/H5PPlayer.loadDependencies.test.ts index 4175b7168..01e8196df 100644 --- a/packages/h5p-server/test/H5PPlayer.loadDependencies.test.ts +++ b/packages/h5p-server/test/H5PPlayer.loadDependencies.test.ts @@ -64,12 +64,12 @@ describe('Loading dependencies', () => { metadataOverride: h5pObject as any }) .then((model) => { - expect((model as any).styles.slice(3)).toEqual([ + expect((model as any).styles.slice(5)).toEqual([ '/h5p/libraries/Foo-4.2/foo1.css?version=4.2.0', '/h5p/libraries/Foo-4.2/foo2.css?version=4.2.0', '/h5p/libraries/Bar-2.1/bar.css?version=2.1.0' ]); - expect((model as any).scripts.slice(9)).toEqual([ + expect((model as any).scripts.slice(10)).toEqual([ '/h5p/libraries/Foo-4.2/foo1.js?version=4.2.0', '/h5p/libraries/Foo-4.2/foo2.js?version=4.2.0', '/h5p/libraries/Bar-2.1/bar.js?version=2.1.0' @@ -148,12 +148,12 @@ describe('Loading dependencies', () => { metadataOverride: h5pObject as any }) .then((model) => { - expect((model as any).styles.slice(3)).toEqual([ + expect((model as any).styles.slice(5)).toEqual([ '/h5p/libraries/Foo-4.2/foo1.css?version=4.2.0', '/h5p/libraries/Foo-4.2/foo2.css?version=4.2.0', '/h5p/libraries/Bar-2.1/bar.css?version=2.1.0' ]); - expect((model as any).scripts.slice(9)).toEqual([ + expect((model as any).scripts.slice(10)).toEqual([ '/h5p/libraries/Foo-4.2/foo1.js?version=4.2.0', '/h5p/libraries/Foo-4.2/foo2.js?version=4.2.0', '/h5p/libraries/Bar-2.1/bar.js?version=2.1.0' @@ -243,12 +243,12 @@ describe('Loading dependencies', () => { metadataOverride: h5pObject as any }) .then((model) => { - expect((model as any).styles.slice(3)).toEqual([ + expect((model as any).styles.slice(5)).toEqual([ '/h5p/libraries/Baz-3.3/baz.css?version=3.3.0', '/h5p/libraries/Bar-2.1/bar.css?version=2.1.0', '/h5p/libraries/Foo-4.2/foo.css?version=4.2.0' ]); - expect((model as any).scripts.slice(9)).toEqual([ + expect((model as any).scripts.slice(10)).toEqual([ '/h5p/libraries/Baz-3.3/baz.js?version=3.3.0', '/h5p/libraries/Bar-2.1/bar.js?version=2.1.0', '/h5p/libraries/Foo-4.2/foo.js?version=4.2.0' @@ -331,12 +331,12 @@ describe('Loading dependencies', () => { metadataOverride: h5pObject as any }) .then((model) => { - expect((model as any).styles.slice(3)).toEqual([ + expect((model as any).styles.slice(5)).toEqual([ '/h5p/libraries/Baz-3.3/baz.css?version=3.3.0', '/h5p/libraries/Bar-2.1/bar.css?version=2.1.0', '/h5p/libraries/Foo-4.2/foo.css?version=4.2.0' ]); - expect((model as any).scripts.slice(9)).toEqual([ + expect((model as any).scripts.slice(10)).toEqual([ '/h5p/libraries/Baz-3.3/baz.js?version=3.3.0', '/h5p/libraries/Bar-2.1/bar.js?version=2.1.0', '/h5p/libraries/Foo-4.2/foo.js?version=4.2.0' @@ -423,12 +423,12 @@ describe('Loading dependencies', () => { metadataOverride: h5pObject as any }) .then((model) => { - expect((model as any).styles.slice(3)).toEqual([ + expect((model as any).styles.slice(5)).toEqual([ '/h5p/libraries/Baz-3.3/baz.css?version=3.3.0', '/h5p/libraries/Bar-2.1/bar.css?version=2.1.0', '/h5p/libraries/Foo-4.2/foo.css?version=4.2.0' ]); - expect((model as any).scripts.slice(9)).toEqual([ + expect((model as any).scripts.slice(10)).toEqual([ '/h5p/libraries/Baz-3.3/baz.js?version=3.3.0', '/h5p/libraries/Bar-2.1/bar.js?version=2.1.0', '/h5p/libraries/Foo-4.2/foo.js?version=4.2.0' @@ -523,6 +523,7 @@ describe('Loading dependencies', () => { `/baseUrl/coreUrl/js/h5p-confirmation-dialog.js?version=${config.h5pVersion}`, `/baseUrl/coreUrl/js/h5p-action-bar.js?version=${config.h5pVersion}`, `/baseUrl/coreUrl/js/request-queue.js?version=${config.h5pVersion}`, + `/baseUrl/coreUrl/js/h5p-tooltip.js?version=${config.h5pVersion}`, `/baseUrl/libraryUrl/Baz-3.3/baz.js?version=3.3.0`, `/baseUrl/libraryUrl/Bar-2.1/bar.js?version=2.1.0`, `/baseUrl/libraryUrl/Foo-4.2/foo.js?version=4.2.0` @@ -532,6 +533,8 @@ describe('Loading dependencies', () => { `/baseUrl/coreUrl/styles/h5p.css?version=${config.h5pVersion}`, `/baseUrl/coreUrl/styles/h5p-confirmation-dialog.css?version=${config.h5pVersion}`, `/baseUrl/coreUrl/styles/h5p-core-button.css?version=${config.h5pVersion}`, + `/baseUrl/coreUrl/styles/h5p-tooltip.css?version=${config.h5pVersion}`, + `/baseUrl/coreUrl/styles/h5p-table.css?version=${config.h5pVersion}`, `/baseUrl/libraryUrl/Baz-3.3/baz.css?version=3.3.0`, `/baseUrl/libraryUrl/Bar-2.1/bar.css?version=2.1.0`, `/baseUrl/libraryUrl/Foo-4.2/foo.css?version=4.2.0` diff --git a/packages/h5p-server/test/__snapshots__/H5PPlayer.renderHtmlPage.test.ts.snap b/packages/h5p-server/test/__snapshots__/H5PPlayer.renderHtmlPage.test.ts.snap index ddddfbfe0..ad0c74d7c 100644 --- a/packages/h5p-server/test/__snapshots__/H5PPlayer.renderHtmlPage.test.ts.snap +++ b/packages/h5p-server/test/__snapshots__/H5PPlayer.renderHtmlPage.test.ts.snap @@ -6,19 +6,22 @@ exports[`Rendering the HTML page includes custom scripts and styles in the gener - - - + + + + + - - - - - - - - - + + + + + + + + + + - - - - - - - - + + + + + + + + + + + + + + +