High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.
JavaScript campaigncampaign-managementemail-marketingemail-subscriptionlistmonkmailing-listnewsletternewsletter-managementnewsletter-softwareself-hostedsms-gatewaysmtptransactional-emails
SSR: Port forms (`/list/forms`) page.
Kailash Nadh4c8c9d0ad5f8
diff --git a/cmd/admin.go b/cmd/admin.goindex 1728ff0d..5ac83ae1 100644--- a/cmd/admin.go+++ b/cmd/admin.go@@ -68,6 +68,10 @@ var adminJSI18nKeys = []string{"lists.confirmSub","lists.optinTo","lists.newList",++ "public.sub",+ "public.subName",+ "subscribers.email",}func (a *App) makeServerConfig() (serverConfig, error) {diff --git a/cmd/handlers.go b/cmd/handlers.goindex c0c1b12e..21ed56e0 100644--- a/cmd/handlers.go+++ b/cmd/handlers.go@@ -74,6 +74,7 @@ func initHTTPHandlers(e *echo.Echo, a *App) {g.GET(path.Join(uriAdmin, "/custom.js"), serveCustomAppearance("admin.custom_js"))g.GET(path.Join(uriAdmin, "/lists"), a.ViewLists)g.GET(path.Join(uriAdmin, "/lists/:id"), hasID(a.ViewList))+ g.GET(path.Join(uriAdmin, "/lists/forms"), a.ViewForms)}// =================================================================diff --git a/cmd/lists.go b/cmd/lists.goindex 7eaea86e..6ec814c5 100644--- a/cmd/lists.go+++ b/cmd/lists.go@@ -24,6 +24,13 @@ type listView struct {List models.List}+// publicListForm is the minimal list representation used by the forms view.+type publicListForm struct {+ UUID string `json:"uuid"`+ Name string `json:"name"`+ Description string `json:"description"`+}+// GetLists retrieves lists with additional metadata like subscriber counts.func (a *App) GetLists(c echo.Context) error {lists, props, err := a.getLists(c)@@ -81,6 +88,33 @@ func (a *App) ViewList(c echo.Context) error {return c.Render(http.StatusOK, "admin-list", data)}+// ViewForms renders the HTML view for the public subscription form generator.+func (a *App) ViewForms(c echo.Context) error {+ lists, err := a.core.GetLists(models.ListTypePublic, models.ListStatusActive, true, nil)+ if err != nil {+ return err+ }++ out := make([]publicListForm, 0, len(lists))+ for _, l := range lists {+ out = append(out, publicListForm{+ UUID: l.UUID,+ Name: l.Name,+ Description: l.Description,+ })+ }++ data := struct {+ adminView+ PublicLists []publicListForm+ }{+ adminView: newAdminView(c, a.i18n.T("forms.title"), ""),+ PublicLists: out,+ }++ return c.Render(http.StatusOK, "admin-forms", data)+}+// GetList retrieves a single list by id.func (a *App) GetList(c echo.Context) error {// Get the authenticated user.diff --git a/frontend-vue/src/components/Navigation.vue b/frontend-vue/src/components/Navigation.vueindex 11365154..4bc982ee 100644--- a/frontend-vue/src/components/Navigation.vue+++ b/frontend-vue/src/components/Navigation.vue@@ -21,9 +21,9 @@</a></li><li>- <router-link :to="{ name: 'forms' }" data-cy="forms">+ <a href="/admin/lists/forms" data-cy="forms">{{ $t('menu.forms') }}- </router-link>+ </a></li></ul></details>diff --git a/frontend-vue/src/router/index.js b/frontend-vue/src/router/index.jsindex 313f68c4..f5d59560 100644--- a/frontend-vue/src/router/index.js+++ b/frontend-vue/src/router/index.js@@ -17,12 +17,6 @@ const routes = [meta: { title: '' },component: () => import('../views/Dashboard.vue'),},- {- path: '/lists/forms',- name: 'forms',- meta: { title: 'forms.title', group: 'lists' },- component: () => import('../views/Forms.vue'),- },{path: '/subscribers',name: 'subscribers',diff --git a/frontend-vue/src/views/Forms.vue b/frontend-vue/src/views/Forms.vuedeleted file mode 100644index 13233448..00000000--- a/frontend-vue/src/views/Forms.vue+++ /dev/null@@ -1,179 +0,0 @@-<template>- <section class="forms relative">- <header class="row page-header">- <div class="col-8">- <h1>- {{ $t('forms.title') }}- </h1>- </div>- </header>-- <div class="card page-content" :aria-busy="loading.lists ? 'true' : null" data-spinner="large overlay">- <p v-if="!loading.lists && publicLists.length === 0">- {{ $t('forms.noPublicLists') }}- </p>- <div class="row" v-else-if="publicLists.length > 0">- <div class="col-4">- <h4>{{ $t('forms.publicLists') }}</h4>- <p>{{ $t('forms.selectHelp') }}</p>-- <ul class="no" data-cy="lists">- <li v-for="(l, i) in publicLists" :key="l.id">- <b-checkbox v-model="checked" :native-value="i">- {{ l.name }}- </b-checkbox>- </li>- </ul>-- <template v-if="serverConfig.public_subscription.enabled">- <hr />- <h4>{{ $t('forms.publicSubPage') }}</h4>- <p>- <a :href="`${serverConfig.root_url}/subscription/form`" target="_blank" rel="noopener noreferer"- data-cy="url">- {{ serverConfig.root_url }}/subscription/form- </a>- </p>- </template>-- <hr />- <h4>{{ $t('forms.redirectURL') }}</h4>- <p class="text-light text-7">- {{ $t('forms.redirectURLHelp') }}- </p>- <ul v-if="redirectURLs.length > 0" class="no" data-cy="redirect-urls">- <li>- <b-radio v-model="selectedRedirectURL" native-value="">- {{ $t('globals.terms.none') }}- </b-radio>- </li>- <li v-for="url in redirectURLs" :key="url">- <b-radio v-model="selectedRedirectURL" :native-value="url">- {{ url }}- </b-radio>- </li>- </ul>- </div>- <div class="col-8 cold-end" data-cy="form">- <h4>{{ $t('forms.formHTML') }}</h4>- <p>- {{ $t('forms.formHTMLHelp') }}- </p>-- <code-editor lang="html" v-if="checked.length > 0" v-model="html" disabled />- </div>- </div><!-- row -->- </div>- </section>-</template>--<script>-import Vue from 'vue';-import { mapState } from 'vuex';-import CodeEditor from '../components/CodeEditor.vue';--export default Vue.extend({- name: 'ListForm',-- components: {- 'code-editor': CodeEditor,- },-- data() {- return {- checked: [],- html: '',- selectedRedirectURL: '',- };- },-- methods: {- escapeAttr(value) {- return String(value)- .replace(/&/g, '&')- .replace(/</g, '<')- .replace(/>/g, '>')- .replace(/"/g, '"')- .replace(/'/g, ''');- },-- renderHTML() {- let h = `<form method="post" action="${this.serverConfig.root_url}/subscription/form" class="listmonk-form">\n`- + ' <div>\n'- + ` <h3>${this.$t('public.sub')}</h3>\n`- + ' <input type="hidden" name="nonce" />\n';-- if (this.selectedRedirectURL) {- h += ` <input type="hidden" name="next" value="${this.escapeAttr(this.selectedRedirectURL)}" />\n`;- }-- h += '\n'- + ` <p><input type="email" name="email" required placeholder="${this.$t('subscribers.email')}" /></p>\n`- + ` <p><input type="text" name="name" placeholder="${this.$t('public.subName')}" /></p>\n\n`;-- this.checked.forEach((i) => {- const l = this.publicLists[parseInt(i, 10)];-- h += ' <p>\n'- + ` <input id="${l.uuid.substr(0, 5)}" type="checkbox" name="l" checked value="${l.uuid}" />\n`- + ` <label for="${l.uuid.substr(0, 5)}">${l.name}</label>\n`;-- if (l.description) {- h += ' <br />\n'- + ` <span>${l.description}</span>\n`;- }-- h += ' </p>\n';- });-- // Captcha?- if (this.serverConfig.public_subscription.captcha_enabled) {- if (this.serverConfig.public_subscription.captcha_provider === 'altcha') {- h += '\n'- + ` <altcha-widget challengeurl="${this.serverConfig.root_url}/api/public/captcha/altcha"></altcha-widget>\n`- + ` <${'script'} type="module" src="${this.serverConfig.root_url}/public/static/altcha.umd.js" async defer></${'script'}>\n`;- } else if (this.serverConfig.public_subscription.captcha_provider === 'hcaptcha') {- h += '\n'- + ` <div class="h-captcha" data-sitekey="${this.serverConfig.public_subscription.captcha_key}"></div>\n`- + ` <${'script'} src="https://js.hcaptcha.com/1/api.js" async defer></${'script'}>\n`;- }- }-- h += '\n'- + ` <input type="submit" value="${this.$t('public.sub')} " />\n`- + ' </div>\n'- + '</form>';-- this.html = h;- },- },-- computed: {- ...mapState(['loading', 'lists', 'serverConfig']),-- publicLists() {- if (!this.lists.results) {- return [];- }- return this.lists.results.filter((l) => l.type === 'public');- },-- redirectURLs() {- const urls = this.serverConfig.public_subscription- ? this.serverConfig.public_subscription.redirect_urls- : [];- return Array.isArray(urls) ? urls : [];- },- },-- watch: {- checked() {- this.renderHTML();- },-- selectedRedirectURL() {- this.renderHTML();- },- },-});-</script>diff --git a/static/admin/build.mjs b/static/admin/build.mjsindex 1aa90541..10356e19 100644--- a/static/admin/build.mjs+++ b/static/admin/build.mjs@@ -39,7 +39,7 @@ async function build() {.map((f) => path.join(srcJS, 'views', f));const result = await Bun.build({- entrypoints: [path.join(srcJS, 'main.js'), ...views],+ entrypoints: [path.join(srcJS, 'main.js'), path.join(srcJS, 'code-editor.js'), ...views],outdir: path.join(dist, 'js'),root: srcJS,splitting: true,diff --git a/static/admin/bun.lock b/static/admin/bun.locknew file mode 100644index 00000000..e970f2e9--- /dev/null+++ b/static/admin/bun.lock@@ -0,0 +1,76 @@+{+ "lockfileVersion": 1,+ "configVersion": 1,+ "workspaces": {+ "": {+ "name": "listmonk-admin",+ "dependencies": {+ "@codemirror/commands": "^6.10.4",+ "@codemirror/lang-css": "^6.3.1",+ "@codemirror/lang-html": "^6.4.11",+ "@codemirror/lang-javascript": "^6.2.5",+ "@codemirror/lang-markdown": "^6.5.0",+ "@codemirror/language": "^6.12.4",+ "@codemirror/search": "^6.7.1",+ "@codemirror/state": "^6.7.0",+ "@codemirror/view": "^6.43.4",+ "@knadh/oat": "^0.6.2",+ "@lezer/highlight": "^1.2.3",+ "alpinejs": "^3.15.12",+ },+ },+ },+ "packages": {+ "@codemirror/autocomplete": ["@codemirror/[email protected]", "", { "dependencies": { "@codemirror/language": "^6.0.0", "@codemirror/state": "^6.0.0", "@codemirror/view": "^6.17.0", "@lezer/common": "^1.0.0" } }, "sha512-tlosUqb+3BbxCxZdu4tKeRghPFC+QM7q4X5YhKV2eCmPG+1r2F3f4AaSz5sCrFqUtX4Jh20VFTKecl16MgiV9g=="],++ "@codemirror/commands": ["@codemirror/[email protected]", "", { "dependencies": { "@codemirror/language": "^6.0.0", "@codemirror/state": "^6.7.0", "@codemirror/view": "^6.27.0", "@lezer/common": "^1.1.0" } }, "sha512-Ryk9y9T0FFVF0cUGhAknveAyUOl/A1qReTFi+qPKtOh2Z9F4AUBz3XOrYD4ZEgZirdugVzHvd/2/Wcwy5OliTg=="],++ "@codemirror/lang-css": ["@codemirror/[email protected]", "", { "dependencies": { "@codemirror/autocomplete": "^6.0.0", "@codemirror/language": "^6.0.0", "@codemirror/state": "^6.0.0", "@lezer/common": "^1.0.2", "@lezer/css": "^1.1.7" } }, "sha512-kr5fwBGiGtmz6l0LSJIbno9QrifNMUusivHbnA1H6Dmqy4HZFte3UAICix1VuKo0lMPKQr2rqB+0BkKi/S3Ejg=="],++ "@codemirror/lang-html": ["@codemirror/[email protected]", "", { "dependencies": { "@codemirror/autocomplete": "^6.0.0", "@codemirror/lang-css": "^6.0.0", "@codemirror/lang-javascript": "^6.0.0", "@codemirror/language": "^6.4.0", "@codemirror/state": "^6.0.0", "@codemirror/view": "^6.17.0", "@lezer/common": "^1.0.0", "@lezer/css": "^1.1.0", "@lezer/html": "^1.3.12" } }, "sha512-9NsXp7Nwp891pQchI7gPdTwBuSuT3K65NGTHWHNJ55HjYcHLllr0rbIZNdOzas9ztc1EUVBlHou85FFZS4BNnw=="],++ "@codemirror/lang-javascript": ["@codemirror/[email protected]", "", { "dependencies": { "@codemirror/autocomplete": "^6.0.0", "@codemirror/language": "^6.6.0", "@codemirror/lint": "^6.0.0", "@codemirror/state": "^6.0.0", "@codemirror/view": "^6.17.0", "@lezer/common": "^1.0.0", "@lezer/javascript": "^1.0.0" } }, "sha512-zD4e5mS+50htS7F+TYjBPsiIFGanfVqg4HyUz6WNFikgOPf2BgKlx+TQedI1w6n/IqRBVBbBWmGFdLB/7uxO4A=="],++ "@codemirror/lang-markdown": ["@codemirror/[email protected]", "", { "dependencies": { "@codemirror/autocomplete": "^6.7.1", "@codemirror/lang-html": "^6.0.0", "@codemirror/language": "^6.3.0", "@codemirror/state": "^6.0.0", "@codemirror/view": "^6.0.0", "@lezer/common": "^1.2.1", "@lezer/markdown": "^1.0.0" } }, "sha512-0K40bZ35jpHya6FriukbgaleaqzBLZfOh7HuzqbMxBXkbYMJDxfF39c23xOgxFezR+3G+tR2/Mup+Xk865OMvw=="],++ "@codemirror/language": ["@codemirror/[email protected]", "", { "dependencies": { "@codemirror/state": "^6.0.0", "@codemirror/view": "^6.23.0", "@lezer/common": "^1.5.0", "@lezer/highlight": "^1.0.0", "@lezer/lr": "^1.0.0", "style-mod": "^4.0.0" } }, "sha512-1q4PaT+o6PbgpkJt4Q8Fv5XJxTy4FUZ4MWETtyiDw3J0Pyr9E2vqcKL+k9wcvjNTIsauxvE7OfmWj3FRPHQ76A=="],++ "@codemirror/lint": ["@codemirror/[email protected]", "", { "dependencies": { "@codemirror/state": "^6.0.0", "@codemirror/view": "^6.42.0", "crelt": "^1.0.5" } }, "sha512-28/+iWLYxKxsvGYhSYL7zaCZqLz5+FFFDq9tVsvGv9kv8RY4fFAchJ5WX9M3YrrRlTIsECjsXPqeNgnSmNP2dg=="],++ "@codemirror/search": ["@codemirror/[email protected]", "", { "dependencies": { "@codemirror/state": "^6.0.0", "@codemirror/view": "^6.37.0", "crelt": "^1.0.5" } }, "sha512-uMe5UO6PamJtSHrXhhHOzSX3ReWtiJrva6GnPMwSOrZtiExb5X5eExhr2OUZQVvdxPsKpY3Ro2mFbQadpPWmHA=="],++ "@codemirror/state": ["@codemirror/[email protected]", "", { "dependencies": { "@marijn/find-cluster-break": "^1.0.0" } }, "sha512-Zbl9NyscLMZkfXPQnNAIIAFftidrA1UbcJEIMp24C0Bukc2I5T8wJS0wsXYsnDOqCFJUeJ1BITGNs5CqPDSmSg=="],++ "@codemirror/view": ["@codemirror/[email protected]", "", { "dependencies": { "@codemirror/state": "^6.7.0", "crelt": "^1.0.6", "style-mod": "^4.1.0", "w3c-keyname": "^2.2.4" } }, "sha512-YImu23iyKfncJzT7sRy+rEqEhSc8RhOHqDxwy4WzXRKJwYm6iwf/9OJk5ctCAdZ6yi2ZqaGEvmf55fSVqMDrgg=="],++ "@knadh/oat": ["@knadh/[email protected]", "", {}, "sha512-8jpbhUj8tZ84MqBQ4IJQNMwBthxgFW+mYsALQO+tTWh/ZQHJT7nm1vreyV4hRyQlc/FUZhPKm/r1cVDKJkuwuw=="],++ "@lezer/common": ["@lezer/[email protected]", "", {}, "sha512-sxQE460fPZyU3sdc8lafxiPwJHBzZRy/udNFynGQky1SePYBdhkBl1kOagA9uT3pxR8K09bOrmTUqA9wb/PjSQ=="],++ "@lezer/css": ["@lezer/[email protected]", "", { "dependencies": { "@lezer/common": "^1.2.0", "@lezer/highlight": "^1.0.0", "@lezer/lr": "^1.3.0" } }, "sha512-N+tn9tej2hPvyKgHEApMOQfHczDJCwxrRFS3SPn9QjYN+uwHvEDnCgKRrb3mxDYxRS8sKMM8fhC3+lc04Abz5Q=="],++ "@lezer/highlight": ["@lezer/[email protected]", "", { "dependencies": { "@lezer/common": "^1.3.0" } }, "sha512-qXdH7UqTvGfdVBINrgKhDsVTJTxactNNxLk7+UMwZhU13lMHaOBlJe9Vqp907ya56Y3+ed2tlqzys7jDkTmW0g=="],++ "@lezer/html": ["@lezer/[email protected]", "", { "dependencies": { "@lezer/common": "^1.2.0", "@lezer/highlight": "^1.0.0", "@lezer/lr": "^1.0.0" } }, "sha512-oI7n6NJml729m7pjm9lvLvmXbdoMoi2f+1pwSDJkl9d68zGr7a9Btz8NdHTGQZtW2DA25ybeuv/SyDb9D5tseg=="],++ "@lezer/javascript": ["@lezer/[email protected]", "", { "dependencies": { "@lezer/common": "^1.2.0", "@lezer/highlight": "^1.1.3", "@lezer/lr": "^1.3.0" } }, "sha512-vvYx3MhWqeZtGPwDStM2dwgljd5smolYD2lR2UyFcHfxbBQebqx8yjmFmxtJ/E6nN6u1D9srOiVWm3Rb4tmcUA=="],++ "@lezer/lr": ["@lezer/[email protected]", "", { "dependencies": { "@lezer/common": "^1.0.0" } }, "sha512-rnCpTIBafOx4mRp43xOxDJbFipJm/c0cia/V5TiGlhmMa+wsSdoGmUN3w5Bqrks/09Q/D4tNAmWaT8p6NRi77A=="],++ "@lezer/markdown": ["@lezer/[email protected]", "", { "dependencies": { "@lezer/common": "^1.5.0", "@lezer/highlight": "^1.0.0" } }, "sha512-N0SxazMj4k65DBfaf1azqtMZd6u7MqluP84/NZnB/io8Td9aleFmAhz9hcbvSfsxT5tdYlJ5qgv5aMJGY4zEtA=="],++ "@marijn/find-cluster-break": ["@marijn/[email protected]", "", {}, "sha512-FY+MKLBoTsLNJF/eLWaOsXGdz6uh3Iu1axjPf6TUq92IYumcTcXWHoS747JARLkcdlJ/Waiaxc5wQfFO8jC6NA=="],++ "@vue/reactivity": ["@vue/[email protected]", "", { "dependencies": { "@vue/shared": "3.1.5" } }, "sha512-1tdfLmNjWG6t/CsPldh+foumYFo3cpyCHgBYQ34ylaMsJ+SNHQ1kApMIa8jN+i593zQuaw3AdWH0nJTARzCFhg=="],++ "@vue/shared": ["@vue/[email protected]", "", {}, "sha512-oJ4F3TnvpXaQwZJNF3ZK+kLPHKarDmJjJ6jyzVNDKH9md1dptjC7lWR//jrGuLdek/U6iltWxqAnYOu8gCiOvA=="],++ "alpinejs": ["[email protected]", "", { "dependencies": { "@vue/reactivity": "~3.1.1" } }, "sha512-nJvPAQVNPdZZ0NrExJ/kzQco3ijR8LwvCOadQecllESiqT4NyZ/57sN9V2XyvhlBGAbmlKYgeWZvYdKq99ij/Q=="],++ "crelt": ["[email protected]", "", {}, "sha512-aK6BbWfhf4U/wCcLHKPJl/xa6VkVstRaPywWtMKGwuOLc/wZTyQYuoxgvZnNsBvv7Kg3YTBQYYBCggcviQczuA=="],++ "style-mod": ["[email protected]", "", {}, "sha512-i/n8VsZydrugj3Iuzll8+x/00GH2vnYsk1eomD8QiRrSAeW6ItbCQDtfXCeJHd0iwiNagqjQkvpvREEPtW3IoQ=="],++ "w3c-keyname": ["[email protected]", "", {}, "sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ=="],+ }+}diff --git a/static/admin/package.json b/static/admin/package.jsonindex 4b4feee6..3cbbdd48 100644--- a/static/admin/package.json+++ b/static/admin/package.json@@ -9,7 +9,17 @@"watch": "bun ./build.mjs --watch"},"dependencies": {+ "@codemirror/commands": "^6.10.4",+ "@codemirror/lang-css": "^6.3.1",+ "@codemirror/lang-html": "^6.4.11",+ "@codemirror/lang-javascript": "^6.2.5",+ "@codemirror/lang-markdown": "^6.5.0",+ "@codemirror/language": "^6.12.4",+ "@codemirror/search": "^6.7.1",+ "@codemirror/state": "^6.7.0",+ "@codemirror/view": "^6.43.4","@knadh/oat": "^0.6.2",+ "@lezer/highlight": "^1.2.3","alpinejs": "^3.15.12"}}diff --git a/static/admin/src/css/style.css b/static/admin/src/css/style.cssindex 99e367bd..344eb233 100644--- a/static/admin/src/css/style.css+++ b/static/admin/src/css/style.css@@ -555,6 +555,17 @@ svg.icon {padding-block-end: 0;}+ .col-bleed {+ margin: calc(-1 * var(--space-6));+ margin-right: inherit;+ padding: var(--space-6) 0;+ border-right: 1px solid var(--border);++ > * {+ padding: 0 var(--space-6);+ }+ }+/* Stick the table to the edges */.table-wrapper {margin: 0 calc(-1*var(--space-6));@@ -904,6 +915,19 @@ section.analytics {}}+.forms {+ code-editor {+ font-size: var(--text-8);+ height: auto;+ max-height: 40vh;+ min-height: 0;+ }+ .lists {+ max-height: 30vh;+ overflow-y: auto;+ }+}+.alt-body textarea {height: 30vh;}diff --git a/static/admin/src/js/code-editor.js b/static/admin/src/js/code-editor.jsnew file mode 100644index 00000000..88836397--- /dev/null+++ b/static/admin/src/js/code-editor.js@@ -0,0 +1,139 @@+// <code-editor> is a reusable CodeMirror 6 WebComponent.+import { EditorState } from '@codemirror/state';+import {+ EditorView, keymap, highlightActiveLine, lineNumbers, highlightActiveLineGutter,+} from '@codemirror/view';+import { html } from '@codemirror/lang-html';+import { css } from '@codemirror/lang-css';+import { javascript } from '@codemirror/lang-javascript';+import { markdown } from '@codemirror/lang-markdown';+import {+ defaultKeymap, history, historyKeymap, indentWithTab,+} from '@codemirror/commands';+import { defaultHighlightStyle, syntaxHighlighting, bracketMatching } from '@codemirror/language';+import { search, searchKeymap, highlightSelectionMatches } from '@codemirror/search';+import { vsCodeLight } from './editor-theme.js';++const LANGS = {+ html, css, javascript, markdown,+};++class CodeEditor extends HTMLElement {+ constructor() {+ super();+ this.editor = null;+ this.textarea = null;+ this.internalUpdate = false;+ }++ connectedCallback() {+ // Handle if `.value` was assigned before the element was upgraded.+ this._upgradeProperty('value');++ // The (optional) nested textarea with the initial value, which also doubles as the+ // form-submission field. CodeMirror renders into a separate mount div.+ this.textarea = this.querySelector('textarea');+ const initial = this.textarea+ ? this.textarea.value+ : (this.pendingValue ?? this.getAttribute('value') ?? '');+ if (this.textarea) {+ this.textarea.hidden = true;+ }++ const mount = document.createElement('div');+ this.appendChild(mount);++ // Apply .code-editor styles to the <code-editor> tag.+ this.classList.add('code-editor');++ const langFn = LANGS[this.getAttribute('lang')] || html;+ const disabled = this.hasAttribute('disabled');++ const onUpdate = EditorView.updateListener.of((update) => {+ if (!update.docChanged) {+ return;+ }+ this.internalUpdate = true;+ const val = update.state.doc.toString();+ if (this.textarea) {+ this.textarea.value = val;+ }+ this.dispatchEvent(new Event('input', { bubbles: true }));+ this.internalUpdate = false;+ });++ this.editor = new EditorView({+ parent: mount,+ state: EditorState.create({+ doc: initial,+ extensions: [+ langFn(),+ history(),+ highlightActiveLine(),+ bracketMatching(),+ highlightSelectionMatches(),+ lineNumbers(),+ highlightActiveLineGutter(),+ keymap.of([...defaultKeymap, ...historyKeymap, ...searchKeymap, indentWithTab]),++ // Readonly?+ EditorState.readOnly.of(disabled),+ EditorView.editable.of(!disabled),++ // Syntax highlighting and theme.+ syntaxHighlighting(defaultHighlightStyle, { fallback: true }),+ EditorView.lineWrapping,+ vsCodeLight,++ search({ top: true }),++ onUpdate,+ ],+ }),+ });+ }++ disconnectedCallback() {+ if (this.editor) {+ this.editor.destroy();+ this.editor = null;+ }+ }++ get value() {+ return this.editor+ ? this.editor.state.doc.toString()+ : (this.pendingValue ?? this.getAttribute('value') ?? '');+ }++ set value(val) {+ const v = val == null ? '' : String(val);++ if (!this.editor) {+ this.pendingValue = v;+ return;+ }++ // Ignore self-edit / no change.+ if (this.internalUpdate || v === this.editor.state.doc.toString()) {+ return;+ }++ this.editor.dispatch({+ changes: { from: 0, to: this.editor.state.doc.length, insert: v },+ });+ }++ // Reinstall a property that was set on the instance before the element was upgraded.+ _upgradeProperty(prop) {+ if (Object.prototype.hasOwnProperty.call(this, prop)) {+ const v = this[prop];+ delete this[prop];+ this[prop] = v;+ }+ }+}++if (!customElements.get('code-editor')) {+ customElements.define('code-editor', CodeEditor);+}diff --git a/static/admin/src/js/editor-theme.js b/static/admin/src/js/editor-theme.jsnew file mode 100644index 00000000..42b61e6c--- /dev/null+++ b/static/admin/src/js/editor-theme.js@@ -0,0 +1,135 @@+// Forked from https://github.com/fsegurai/codemirror-themes+// MIT License - Copyright (c) 2025 fsegurai++import { EditorView } from '@codemirror/view';+import { HighlightStyle, syntaxHighlighting } from '@codemirror/language';+import { tags } from '@lezer/highlight';++// VSCode Light theme color definitions+const background = '#ffffff';+const foreground = '#383a42';+const caret = '#000000';+const selection = '#add6ff';+const selectionMatch = '#a8ac94';+const lineHighlight = '#99999926';+const gutterBackground = '#ffffff';+const gutterForeground = '#0055d4';+const gutterActiveForeground = '#0b216f';+const keywordColor = '#0055d4';+const controlKeywordColor = '#af00db';+const variableColor = '#e45649';+const classTypeColor = '#0055d4';+const functionColor = '#795e26';+const numberColor = '#098658';+const operatorColor = '#383a42';+const regexpColor = '#af00db';+const stringColor = '#50a14f';+const commentColor = '#999';+const linkColor = '#0055d4';+const invalidColor = '#e45649';++// Define the editor theme styles for VSCode Light+const vsCodeLightTheme = /* @__PURE__ */EditorView.theme({+ '&': {+ color: foreground,+ backgroundColor: background,+ fontFamily: 'Menlo, Monaco, Consolas, "Andale Mono", "Ubuntu Mono", "Courier New", monospace',+ },+ '.cm-content': {+ caretColor: caret,+ },+ '.cm-cursor, .cm-dropCursor': {+ borderLeftColor: caret,+ },+ '&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection': {+ backgroundColor: selection,+ },+ '.cm-searchMatch': {+ backgroundColor: selectionMatch,+ outline: `1px solid ${lineHighlight}`,+ },+ '.cm-activeLine': {+ backgroundColor: lineHighlight,+ },+ '.cm-gutters': {+ backgroundColor: gutterBackground,+ color: gutterForeground,+ },+ '.cm-activeLineGutter': {+ color: gutterActiveForeground,+ },+}, { dark: false });+// Define the highlighting style for code in the VSCode Light theme+const vsCodeLightHighlightStyle = /* @__PURE__ */HighlightStyle.define([+ {+ tag: [+ tags.keyword,+ tags.operatorKeyword,+ tags.modifier,+ tags.color,+ /* @__PURE__ */tags.constant(tags.name),+ /* @__PURE__ */tags.standard(tags.name),+ /* @__PURE__ */tags.standard(tags.tagName),+ /* @__PURE__ */tags.special(tags.brace),+ tags.atom,+ tags.bool,+ /* @__PURE__ */tags.special(tags.variableName),+ ],+ color: keywordColor,+ },+ { tag: [tags.moduleKeyword, tags.controlKeyword], color: controlKeywordColor },+ {+ tag: [+ tags.name,+ tags.deleted,+ tags.character,+ tags.macroName,+ tags.propertyName,+ tags.variableName,+ tags.labelName,+ /* @__PURE__ */tags.definition(tags.name),+ ],+ color: variableColor,+ },+ { tag: tags.heading, fontWeight: 'bold', color: variableColor },+ {+ tag: [+ tags.typeName,+ tags.className,+ tags.tagName,+ tags.number,+ tags.changed,+ tags.annotation,+ tags.self,+ tags.namespace,+ ],+ color: classTypeColor,+ },+ {+ tag: [/* @__PURE__ */tags.function(tags.variableName), /* @__PURE__ */tags.function(tags.propertyName)],+ color: functionColor,+ },+ { tag: [tags.number], color: numberColor },+ {+ tag: [tags.operator, tags.punctuation, tags.separator, tags.url, tags.escape, tags.regexp],+ color: operatorColor,+ },+ { tag: [tags.regexp], color: regexpColor },+ {+ tag: [/* @__PURE__ */tags.special(tags.string), tags.processingInstruction, tags.string, tags.inserted],+ color: stringColor,+ },+ { tag: [tags.meta, tags.comment], color: commentColor },+ { tag: tags.link, color: linkColor, textDecoration: 'underline' },+ { tag: tags.invalid, color: invalidColor },+ { tag: tags.strong, fontWeight: 'bold' },+ { tag: tags.emphasis, fontStyle: 'italic' },+ { tag: tags.strikethrough, textDecoration: 'line-through' },+]);+// Extension to enable the VSCode Light theme (both the editor theme and the highlight style)+const vsCodeLight = [+ vsCodeLightTheme,+ /* @__PURE__ */syntaxHighlighting(vsCodeLightHighlightStyle),+];++export { vsCodeLight, vsCodeLightHighlightStyle, vsCodeLightTheme };diff --git a/static/admin/views/forms.html b/static/admin/views/forms.htmlindex 5ffc0a5d..db156288 100644--- a/static/admin/views/forms.html+++ b/static/admin/views/forms.html@@ -5,38 +5,34 @@<script>const _lists = {{ ToJSON $d.PublicLists }};</script><section class="forms" x-data="formsView(_lists)"><header class="row page-header">- <div class="col-8">+ <div class="col-6"><h1 class="page-title">{{ .L.T "forms.title" }}</h1></div>+ <div class="col-6 col-end align-right hstack justify-end">+ {{- if $.ConfigJS.PublicSubscription.Enabled }}+ <a href="{{ $.ConfigJS.RootURL }}/subscription/form" target="_blank" rel="noopener noreferrer" class="button outline small" data-cy="url" title="{{ $.ConfigJS.RootURL }}/subscription/form">+ {{ Icon "arrow-up-right" }} {{ .L.T "forms.publicSubPage" }}+ </a>+ {{- end }}+ </div></header>- <div class="card page-content p-6">+ <div class="card page-content">{{- if not $d.PublicLists }}<p class="text-light">{{ .L.T "forms.noPublicLists" }}</p>{{- else }}<div class="row">- <div class="col-4">- <h4>{{ .L.T "forms.publicLists" }}</h4>+ <div class="col-4 col-bleed"><p class="text-light text-7">{{ .L.T "forms.selectHelp" }}</p>- <ul class="no" data-cy="lists">- {{- range $d.PublicLists }}+ <ul class="no lists" data-cy="lists">+ {{- range $i, $list := $d.PublicLists }}<li>- <label><input type="checkbox" class="checkbox" value="{{ .UUID }}" x-model="checked" /> {{ .Name }}</label>+ <label><input type="checkbox" value="{{ $list.UUID }}" x-model="checked" {{- if eq $i 0 }} autofocus{{- end }} /> {{ $list.Name }}</label></li>{{- end }}</ul>- {{- if $.ConfigJS.PublicSubscription.Enabled }}- <hr />- <h4>{{ .L.T "forms.publicSubPage" }}</h4>- <p>- <a href="{{ $.ConfigJS.RootURL }}/subscription/form" target="_blank" rel="noopener noreferrer" data-cy="url">- {{ $.ConfigJS.RootURL }}/subscription/form- </a>- </p>- {{- end }}-<hr /><h4>{{ .L.T "forms.redirectURL" }}</h4><p class="text-light text-7">{{ .L.T "forms.redirectURLHelp" }}</p>@@ -54,17 +50,16 @@{{- end }}</div>- <div class="col-8 col-end" data-cy="form">- <h4>{{ .L.T "forms.formHTML" }}</h4>+ <div class="col-8 col-end" data-cy="form" aria-label="{{ .L.T "forms.formHTML" }}"><p class="text-light text-7">{{ .L.T "forms.formHTMLHelp" }}</p><div x-show="checked.length > 0" x-cloak>- <div class="hstack justify-end">+ <div class="align-right"><button type="button" class="small outline" @click="copyHTML" title="{{ .L.T "globals.messages.clickToCopy" }}">{{ Icon "copy" }} {{ .L.T "globals.buttons.copy" }}</button></div>- <pre class="form-html" role="textbox"><code x-text="html"></code></pre>+ <code-editor lang="html" disabled x-effect="$el.value = html"></code-editor></div></div></div><!-- row -->@@ -72,6 +67,7 @@</div></section>+<script type="module" src="{{ URI "/admin/static/js/code-editor.js" }}?v={{ .AssetVersion }}" defer></script><script type="module" src="{{ URI "/admin/static/js/views/forms.js" }}?v={{ .AssetVersion }}" defer></script>{{ template "admin-footer" . -}}