From 3b76d80c14127ed703c5a7067615b6dd76a8d536 Mon Sep 17 00:00:00 2001 From: SamTv12345 Date: Tue, 23 Jul 2024 09:58:52 +0200 Subject: [PATCH] Fixed bootstrap. --- pnpm-lock.yaml | 8 ++++++++ src/node/hooks/express/specialpages.ts | 10 +++++++++- src/node/utils/Minify.ts | 6 +++--- src/package.json | 1 + src/static/js/pad.ts | 9 +++++---- src/static/js/pad_connectionstatus.ts | 1 - src/static/js/vendors/nice-select.js | 11 +++++++---- src/templates/pad.html | 7 +------ src/templates/padBootstrap.ts | 11 ++++++----- src/templates/timeslider.html | 4 ---- 10 files changed, 40 insertions(+), 28 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4f4d031ef..111b5e813 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -188,6 +188,9 @@ importers: jose: specifier: ^5.6.3 version: 5.6.3 + jquery: + specifier: ^3.7.1 + version: 3.7.1 js-cookie: specifier: ^3.0.5 version: 3.0.5 @@ -3168,6 +3171,9 @@ packages: jose@5.6.3: resolution: {integrity: sha512-1Jh//hEEwMhNYPDDLwXHa2ePWgWiFNNUadVmguAAw2IJ6sj9mNxV5tGXJNqlMkJAybF6Lgw1mISDxTePP/187g==} + jquery@3.7.1: + resolution: {integrity: sha512-m4avr8yL8kmFN8psrbFFFmB/If14iN5o9nw/NgnnM+kybDJpRsAynV2BsfpTYrTRysYUdADVD7CkUUizgkpLfg==} + js-cookie@3.0.5: resolution: {integrity: sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==} engines: {node: '>=14'} @@ -7672,6 +7678,8 @@ snapshots: jose@5.6.3: {} + jquery@3.7.1: {} + js-cookie@3.0.5: {} js-tokens@4.0.0: {} diff --git a/src/node/hooks/express/specialpages.ts b/src/node/hooks/express/specialpages.ts index 304c5fd0e..73b9e33e1 100644 --- a/src/node/hooks/express/specialpages.ts +++ b/src/node/hooks/express/specialpages.ts @@ -12,6 +12,8 @@ import {userCanModify} from './webaccess'; import {pluginDefs} from '../../../static/js/pluginfw/plugin_defs'; import {build, buildSync} from 'esbuild' +import {availableLangs} from "../i18n"; +import {clientPluginNames} from "../../../static/js/pluginfw/shared"; let ioI: { sockets: { sockets: any[]; }; } | null = null export const socketio = (hookName: string, {io}: any) => { @@ -157,6 +159,9 @@ const handleLiveReload = async (args: any, padString: string, timeSliderString: const content = requireP('ep_etherpad-lite/templates/pad.html', { req, toolbar, + settings: settings, + clientPluginNames: clientPluginNames, + langs: availableLangs, isReadOnly, entrypoint: '/watch/pad?hash=' + hash }) @@ -186,6 +191,8 @@ const handleLiveReload = async (args: any, padString: string, timeSliderString: const content = requireP('ep_etherpad-lite/templates/timeslider.html', { req, toolbar, + langs: availableLangs, + settings: settings, isReadOnly, entrypoint: '/watch/timeslider?hash=' + hash }) @@ -210,7 +217,8 @@ const convertTypescriptWatched = (content: string, cb: (output:string, hash: str }, alias:{ "ep_etherpad-lite/static/js/browser": 'ep_etherpad-lite/static/js/vendors/browser', - "ep_etherpad-lite/static/js/nice-select": 'ep_etherpad-lite/static/js/vendors/nice-select' + "ep_etherpad-lite/static/js/nice-select": 'ep_etherpad-lite/static/js/vendors/nice-select', + "jquery": "ep_etherpad-lite/node_modules/jquery" }, bundle: true, // Bundle the files together minify: process.env.NODE_ENV === "production", // Minify the output diff --git a/src/node/utils/Minify.ts b/src/node/utils/Minify.ts index b88ac05ad..21c923c5a 100644 --- a/src/node/utils/Minify.ts +++ b/src/node/utils/Minify.ts @@ -249,7 +249,7 @@ const getFileCompressed = async (filename: string, contentType: string|false) => const compressResult = await compressJS(content.toString()); - if (compressResult.warnings) { + if (compressResult.warnings.length != 0) { console.error(`Error compressing JS (${filename}) using terser`, compressResult.warnings); } else { jsSources = compressResult.code.toString(); // Convert content obj code to string @@ -268,13 +268,13 @@ const getFileCompressed = async (filename: string, contentType: string|false) => const compressResult = await compressCSS(path.resolve(ROOT_DIR, filename)); - if (compressResult) { + if (compressResult == null) { console.error(`Error compressing CSS (${filename}) using terser`, compressResult); } else { contentString = compressResult } } catch (error) { - console.error(`CleanCSS.minify() returned an error on ${filename}: ${error}`); + console.error(`CleanCSS.minify() returned an error on : ${error}`); } resolve(content.toString()); }); diff --git a/src/package.json b/src/package.json index c536f5064..d89726c4e 100644 --- a/src/package.json +++ b/src/package.json @@ -46,6 +46,7 @@ "formidable": "^3.5.1", "http-errors": "^2.0.0", "jose": "^5.6.3", + "jquery": "^3.7.1", "js-cookie": "^3.0.5", "jsdom": "^24.1.0", "jsonminify": "0.4.2", diff --git a/src/static/js/pad.ts b/src/static/js/pad.ts index 80beda56a..eb7cdc131 100644 --- a/src/static/js/pad.ts +++ b/src/static/js/pad.ts @@ -867,7 +867,8 @@ export type PadSettings = { export const pad = new Pad() -exports.baseURL = ''; -exports.randomString = randomString; -exports.getParams = getParams; -exports.pad = pad; +export let baseURL = ''; + +export const setPadBaseURL = (url: string)=> { + baseURL = url +} diff --git a/src/static/js/pad_connectionstatus.ts b/src/static/js/pad_connectionstatus.ts index 2aeec5241..8cd9ea0fc 100644 --- a/src/static/js/pad_connectionstatus.ts +++ b/src/static/js/pad_connectionstatus.ts @@ -101,4 +101,3 @@ class PadConnectionStatus { export const padconnectionstatus = new PadConnectionStatus() -exports.padconnectionstatus = padconnectionstatus; diff --git a/src/static/js/vendors/nice-select.js b/src/static/js/vendors/nice-select.js index 447ff6413..f3c39be51 100644 --- a/src/static/js/vendors/nice-select.js +++ b/src/static/js/vendors/nice-select.js @@ -1,3 +1,7 @@ +import jquery from 'jquery'; +window.jQuery = jquery; +window.$ = jquery; + // WARNING: This file has been modified from the Original // TODO: Nice Select seems relatively abandoned, we should consider other options. @@ -5,9 +9,8 @@ https://github.com/hernansartorio/jquery-nice-select Made by HernĂ¡n Sartorio */ -(function($) { - - $.fn.niceSelect = function(method) { +(function() { + window.$.fn.niceSelect = function(method) { // Methods if (typeof method == 'string') { @@ -209,4 +212,4 @@ }; -}(jQuery)); +}(window.jQuery)); diff --git a/src/templates/pad.html b/src/templates/pad.html index 17a523e83..535756d36 100644 --- a/src/templates/pad.html +++ b/src/templates/pad.html @@ -1,10 +1,5 @@ -<% - import settings from 'ep_etherpad-lite/node/utils/Settings' - import langs from 'ep_etherpad-lite/node/hooks/i18n' - import {pluginUtils} from 'ep_etherpad-lite/static/js/pluginfw/shared' -%> - + <% e.begin_block("htmlHead"); %> <% e.end_block(); %> diff --git a/src/templates/padBootstrap.ts b/src/templates/padBootstrap.ts index 28927f537..f305d0b36 100644 --- a/src/templates/padBootstrap.ts +++ b/src/templates/padBootstrap.ts @@ -1,7 +1,10 @@ import browser from 'ep_etherpad-lite/static/js/vendors/browser' import {padeditbar} from 'ep_etherpad-lite/static/js/pad_editbar' import {padImpExp} from 'ep_etherpad-lite/static/js/pad_impexp' - +import jquery from 'jquery'; +window.jQuery = jquery; +window.$ = jquery; +import {pad, setPadBaseURL} from 'ep_etherpad-lite/static/js/pad' (async () => { require('../../src/static/js/l10n') @@ -17,10 +20,8 @@ import {padImpExp} from 'ep_etherpad-lite/static/js/pad_impexp' //window.require.resolveTmp = require.resolve('ep_etherpad-lite/static/js/pad_cookie'); const basePath = new URL('..', window.location.href).pathname; - window.$ = window.jQuery = require('ep_etherpad-lite/static/js/vendors/jquery'); window.browser = browser; - const pad = require('ep_etherpad-lite/static/js/pad'); - pad.baseURL = basePath; + setPadBaseURL(basePath); window.plugins = require('ep_etherpad-lite/static/js/pluginfw/client_plugins'); const hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks'); @@ -44,6 +45,6 @@ import {padImpExp} from 'ep_etherpad-lite/static/js/pad_impexp' window._postPluginUpdateForTestingDone = true; window.pluginDefs = require('../../src/static/js/pluginfw/plugin_defs'); pad.init(); - await new Promise((resolve) => $(resolve)); + await new Promise((resolve) => window.$(resolve)); await hooks.aCallAll('documentReady'); })(); diff --git a/src/templates/timeslider.html b/src/templates/timeslider.html index e2178e54e..1cbcfa6ea 100644 --- a/src/templates/timeslider.html +++ b/src/templates/timeslider.html @@ -1,7 +1,3 @@ -<% - var settings = require("ep_etherpad-lite/node/utils/Settings") - , langs = require("ep_etherpad-lite/node/hooks/i18n").availableLangs -%>