From b72b23d6aeff1aca47348ca8efc04f1e69e7a2f0 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Thu, 23 May 2024 16:56:11 +0200 Subject: [PATCH] Cleaning some stuff. --- client/common-client-plugin.ts | 1 + client/common/configuration/contexts/channel.ts | 12 +++++------- .../configuration/elements/channel-configuration.ts | 12 +++++------- client/common/configuration/elements/channel-home.ts | 6 +++--- .../configuration/elements/configuration-row.ts | 1 - client/common/configuration/elements/index.js | 4 ++++ client/common/configuration/register.ts | 3 +-- .../common/configuration/services/channel-details.ts | 4 ++-- client/common/lib/contexts/peertube.ts | 4 ++++ .../{configuration => lib}/directives/translation.ts | 0 .../elements/dynamic-table-form.ts | 8 ++++---- .../{configuration => lib}/elements/help-button.ts | 2 +- client/common/lib/elements/index.js | 3 +++ client/tsconfig.json | 4 ++-- package.json | 2 -- 15 files changed, 35 insertions(+), 31 deletions(-) create mode 100644 client/common/configuration/elements/index.js create mode 100644 client/common/lib/contexts/peertube.ts rename client/common/{configuration => lib}/directives/translation.ts (100%) rename client/common/{configuration => lib}/elements/dynamic-table-form.ts (97%) rename client/common/{configuration => lib}/elements/help-button.ts (96%) create mode 100644 client/common/lib/elements/index.js diff --git a/client/common-client-plugin.ts b/client/common-client-plugin.ts index 354e51c0..5ad14b05 100644 --- a/client/common-client-plugin.ts +++ b/client/common-client-plugin.ts @@ -6,6 +6,7 @@ import type { RegisterClientOptions } from '@peertube/peertube-types/client' import type { RegisterClientFormFieldOptions } from '@peertube/peertube-types' import { registerConfiguration } from './common/configuration/register' import { registerRoom } from './common/room/register' +import './common/lib/elements' // Import shared elements. async function register (clientOptions: RegisterClientOptions): Promise { const { peertubeHelpers, registerHook, registerVideoField } = clientOptions diff --git a/client/common/configuration/contexts/channel.ts b/client/common/configuration/contexts/channel.ts index befa159e..99aaece9 100644 --- a/client/common/configuration/contexts/channel.ts +++ b/client/common/configuration/contexts/channel.ts @@ -1,8 +1,6 @@ -import { createContext } from "@lit/context"; -import type { RegisterClientOptions } from "@peertube/peertube-types/client/types"; -import type { ChannelConfiguration } from "shared/lib/types"; -import { ChannelDetailsService } from "../services/channel-details"; +import type { ChannelConfiguration } from 'shared/lib/types' +import { createContext } from '@lit/context' +import { ChannelDetailsService } from '../services/channel-details' -export const registerClientOptionsContext = createContext(Symbol('register-client-options')); -export const channelConfigurationContext = createContext(Symbol('channel-configuration')); -export const channelDetailsServiceContext = createContext(Symbol('channel-configuration-service')); \ No newline at end of file +export const channelConfigurationContext = createContext(Symbol('channel-configuration')) +export const channelDetailsServiceContext = createContext(Symbol('channel-configuration-service')) diff --git a/client/common/configuration/elements/channel-configuration.ts b/client/common/configuration/elements/channel-configuration.ts index 7261a656..e030c103 100644 --- a/client/common/configuration/elements/channel-configuration.ts +++ b/client/common/configuration/elements/channel-configuration.ts @@ -1,15 +1,13 @@ import type { RegisterClientOptions } from '@peertube/peertube-types/client' +import type { ChannelConfiguration } from 'shared/lib/types' import { html, LitElement } from 'lit' import { customElement, property, state } from 'lit/decorators.js' -import { ptTr } from '../directives/translation' -import './dynamic-table-form' -import './configuration-row' -import './help-button' -import { Task } from '@lit/task'; -import type { ChannelConfiguration } from 'shared/lib/types' +import { ptTr } from '../../lib/directives/translation' +import { Task } from '@lit/task' import { ChannelDetailsService } from '../services/channel-details' import { provide } from '@lit/context' -import { channelConfigurationContext, channelDetailsServiceContext, registerClientOptionsContext } from '../contexts/channel' +import { channelConfigurationContext, channelDetailsServiceContext } from '../contexts/channel' +import { registerClientOptionsContext } from '../../lib/contexts/peertube' @customElement('livechat-channel-configuration') export class ChannelConfigurationElement extends LitElement { diff --git a/client/common/configuration/elements/channel-home.ts b/client/common/configuration/elements/channel-home.ts index 2b773c89..e2014092 100644 --- a/client/common/configuration/elements/channel-home.ts +++ b/client/common/configuration/elements/channel-home.ts @@ -1,13 +1,13 @@ import type { RegisterClientOptions } from '@peertube/peertube-types/client' import { html, LitElement } from 'lit' import { customElement, property, state } from 'lit/decorators.js' -import { ptTr } from '../directives/translation' -import './help-button' +import { ptTr } from '../../lib/directives/translation' import { Task } from '@lit/task'; import type { ChannelLiveChatInfos } from 'shared/lib/types' import { ChannelDetailsService } from '../services/channel-details' import { provide } from '@lit/context' -import { channelDetailsServiceContext, registerClientOptionsContext } from '../contexts/channel' +import { channelDetailsServiceContext } from '../contexts/channel' +import { registerClientOptionsContext } from '../../lib/contexts/peertube' @customElement('livechat-channel-home') export class ChannelHomeElement extends LitElement { diff --git a/client/common/configuration/elements/configuration-row.ts b/client/common/configuration/elements/configuration-row.ts index a2edca34..14907f88 100644 --- a/client/common/configuration/elements/configuration-row.ts +++ b/client/common/configuration/elements/configuration-row.ts @@ -1,6 +1,5 @@ import { html, LitElement } from 'lit' import { customElement, property } from 'lit/decorators.js' -import './help-button' @customElement('livechat-configuration-row') export class ConfigurationRowElement extends LitElement { diff --git a/client/common/configuration/elements/index.js b/client/common/configuration/elements/index.js new file mode 100644 index 00000000..81761f51 --- /dev/null +++ b/client/common/configuration/elements/index.js @@ -0,0 +1,4 @@ +// Add here all your elements, the main JS file will import them all. +import './channel-configuration' +import './channel-home' +import './configuration-row' diff --git a/client/common/configuration/register.ts b/client/common/configuration/register.ts index ae5bd36a..5e69e3ed 100644 --- a/client/common/configuration/register.ts +++ b/client/common/configuration/register.ts @@ -3,9 +3,8 @@ // SPDX-License-Identifier: AGPL-3.0-only import type { RegisterClientOptions } from '@peertube/peertube-types/client' -import './elements/channel-home' -import './elements/channel-configuration' import { html, render } from 'lit' +import './elements' // Import all needed elements. /** * Registers stuff related to the user's configuration pages. diff --git a/client/common/configuration/services/channel-details.ts b/client/common/configuration/services/channel-details.ts index 84c6cb61..04d0819e 100644 --- a/client/common/configuration/services/channel-details.ts +++ b/client/common/configuration/services/channel-details.ts @@ -1,5 +1,5 @@ -import type { RegisterClientOptions } from "@peertube/peertube-types/client" -import { ChannelLiveChatInfos, ChannelConfiguration, ChannelConfigurationOptions } from "shared/lib/types" +import type { RegisterClientOptions } from '@peertube/peertube-types/client' +import { ChannelLiveChatInfos, ChannelConfiguration, ChannelConfigurationOptions } from 'shared/lib/types' import { getBaseRoute } from "../../../utils/uri" diff --git a/client/common/lib/contexts/peertube.ts b/client/common/lib/contexts/peertube.ts new file mode 100644 index 00000000..c132d45a --- /dev/null +++ b/client/common/lib/contexts/peertube.ts @@ -0,0 +1,4 @@ +import type { RegisterClientOptions } from '@peertube/peertube-types/client/types' +import { createContext } from '@lit/context' + +export const registerClientOptionsContext = createContext(Symbol('register-client-options')) diff --git a/client/common/configuration/directives/translation.ts b/client/common/lib/directives/translation.ts similarity index 100% rename from client/common/configuration/directives/translation.ts rename to client/common/lib/directives/translation.ts diff --git a/client/common/configuration/elements/dynamic-table-form.ts b/client/common/lib/elements/dynamic-table-form.ts similarity index 97% rename from client/common/configuration/elements/dynamic-table-form.ts rename to client/common/lib/elements/dynamic-table-form.ts index 571f73f7..d042acb3 100644 --- a/client/common/configuration/elements/dynamic-table-form.ts +++ b/client/common/lib/elements/dynamic-table-form.ts @@ -155,7 +155,7 @@ export class DynamicTableFormElement extends LitElement { } render = () => { - const inputId = `peertube-livechat-${this.formName.replaceAll('_', '-')}-table` + const inputId = `peertube-livechat-${this.formName.replace(/_/g, '-')}-table` this._updateLastRowId() @@ -200,7 +200,7 @@ export class DynamicTableFormElement extends LitElement { } private _renderDataRow = (rowData: { _id: number; row: {[key: string]: DynamicTableAcceptedTypes} }) => { - const inputId = `peertube-livechat-${this.formName.replaceAll('_', '-')}-row-${rowData._id}` + const inputId = `peertube-livechat-${this.formName.replace(/_/g, '-')}-row-${rowData._id}` return html` ${Object.entries(rowData.row).filter(([k, v]) => k != '_id') @@ -226,8 +226,8 @@ export class DynamicTableFormElement extends LitElement { let formElement - const inputName = `${this.formName.replaceAll('-', '_')}_${propertyName.toString().replaceAll('-', '_')}_${rowId}` - const inputId = `peertube-livechat-${this.formName.replaceAll('_', '-')}-${propertyName.toString().replaceAll('_', '-')}-${rowId}` + const inputName = `${this.formName.replace(/-/g, '_')}_${propertyName.toString().replace(/-/g, '_')}_${rowId}` + const inputId = `peertube-livechat-${this.formName.replace(/_/g, '-')}-${propertyName.toString().replace(/_/g, '-')}-${rowId}` switch (propertyValue.constructor) { case String: diff --git a/client/common/configuration/elements/help-button.ts b/client/common/lib/elements/help-button.ts similarity index 96% rename from client/common/configuration/elements/help-button.ts rename to client/common/lib/elements/help-button.ts index cff00c6a..f33c96dd 100644 --- a/client/common/configuration/elements/help-button.ts +++ b/client/common/lib/elements/help-button.ts @@ -3,7 +3,7 @@ import { customElement, property, state } from 'lit/decorators.js' import { unsafeHTML } from 'lit/directives/unsafe-html.js' import { helpButtonSVG } from '../../../videowatch/buttons' import { consume } from '@lit/context' -import { registerClientOptionsContext } from '../contexts/channel' +import { registerClientOptionsContext } from '../contexts/peertube' import type { RegisterClientOptions } from '@peertube/peertube-types/client' import { Task } from '@lit/task' import { localizedHelpUrl } from '../../../utils/help' diff --git a/client/common/lib/elements/index.js b/client/common/lib/elements/index.js new file mode 100644 index 00000000..ac4c84b6 --- /dev/null +++ b/client/common/lib/elements/index.js @@ -0,0 +1,3 @@ +// Add here all your elements, the main JS file will import them all. +import './help-button' +import './dynamic-table-form' diff --git a/client/tsconfig.json b/client/tsconfig.json index 259d61de..a48ab054 100644 --- a/client/tsconfig.json +++ b/client/tsconfig.json @@ -1,9 +1,9 @@ { "compilerOptions": { "experimentalDecorators": true, - "module": "es2022", + "module": "es6", "moduleResolution": "node", - "target": "es2022", + "target": "es5", "allowJs": true, "sourceMap": true, "forceConsistentCasingInFileNames": true, diff --git a/package.json b/package.json index bd7d658c..7959ba09 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,6 @@ "@types/express": "^4.17.13", "@types/got": "^9.6.12", "@types/http-proxy": "^1.17.9", - "@types/mustache": "^4.2.2", "@types/node": "^16.11.6", "@types/winston": "^2.4.4", "@types/xmpp__jid": "^1.3.5", @@ -71,7 +70,6 @@ "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^5.1.1", "eslint-plugin-standard": "^5.0.0", - "mustache": "^4.2.0", "npm-run-all": "^4.1.5", "sass": "^1.43.4", "sharp": "^0.33.2",