Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ceb78db72 | ||
|
|
86e347a6eb | ||
|
|
e1669e3685 |
No files matched your search
@@ -2,6 +2,9 @@
|
||||
* @file Bundler utilities.
|
||||
*/
|
||||
|
||||
import { createRequire } from "node:module";
|
||||
import { dirname, join } from "node:path";
|
||||
|
||||
import { NodeEnvironment, serializeEnvironmentVars } from "@goauthentik/core/environment/node";
|
||||
import {
|
||||
AuthentikVersion,
|
||||
@@ -34,3 +37,21 @@ export function createBundleDefinitions() {
|
||||
"process.env.NODE_ENV": SerializedNodeEnvironment,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a mapping of import paths to the files a package ships without exporting them.
|
||||
*/
|
||||
export function createBundleAliases(): Record<string, string> {
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
return {
|
||||
// Monaco's `exports` map covers only its modules. The editor renders in a shadow root,
|
||||
// so it needs the stylesheet that its modules would otherwise inject into the document.
|
||||
// `require` resolves the package to `min/vs/index.js`, next to that stylesheet.
|
||||
"monaco-editor/min/vs/editor/editor.main.css": join(
|
||||
dirname(require.resolve("monaco-editor")),
|
||||
"editor",
|
||||
"editor.main.css",
|
||||
),
|
||||
};
|
||||
}
|
||||
+1
-10
@@ -157,13 +157,6 @@
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@codemirror/lang-css": "^6.3.1",
|
||||
"@codemirror/lang-html": "^6.4.11",
|
||||
"@codemirror/lang-javascript": "^6.2.5",
|
||||
"@codemirror/lang-python": "^6.2.1",
|
||||
"@codemirror/lang-xml": "^6.1.0",
|
||||
"@codemirror/legacy-modes": "^6.5.3",
|
||||
"@codemirror/theme-one-dark": "^6.1.3",
|
||||
"@formatjs/intl-listformat": "^8.3.13",
|
||||
"@fortawesome/fontawesome-free": "^7.3.1",
|
||||
"@goauthentik/api": "link:packages/client-ts",
|
||||
@@ -192,7 +185,6 @@
|
||||
"@storybook/addon-links": "^10.6.1",
|
||||
"@storybook/web-components": "^10.6.1",
|
||||
"@storybook/web-components-vite": "^10.6.1",
|
||||
"@types/codemirror": "^5.60.17",
|
||||
"@types/grecaptcha": "^3.0.9",
|
||||
"@types/guacamole-common-js": "^1.5.5",
|
||||
"@types/node": "catalog:",
|
||||
@@ -206,7 +198,6 @@
|
||||
"change-case": "^5.4.4",
|
||||
"chart.js": "^4.5.1",
|
||||
"chartjs-adapter-date-fns": "^3.0.0",
|
||||
"codemirror": "^6.0.2",
|
||||
"cookie": "^2.0.1",
|
||||
"core-js": "^3.49.0",
|
||||
"country-flag-icons": "^1.6.20",
|
||||
@@ -233,6 +224,7 @@
|
||||
"maplibre-gl": "^5.24.0",
|
||||
"md-front-matter": "^1.0.4",
|
||||
"mermaid": "^11.17.2",
|
||||
"monaco-editor": "^0.57.0",
|
||||
"node-domexception": "workspace:*",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"oxfmt": "catalog:",
|
||||
@@ -251,7 +243,6 @@
|
||||
"remark-gfm": "^4.0.1",
|
||||
"remark-rehype": "^11.1.2",
|
||||
"storybook": "^10.6.2",
|
||||
"style-mod": "^4.1.3",
|
||||
"stylelint": "^17.14.1",
|
||||
"trusted-types": "^2.0.0",
|
||||
"ts-pattern": "^5.9.0",
|
||||
|
||||
Generated
+25
-287
@@ -210,27 +210,6 @@ importers:
|
||||
|
||||
.:
|
||||
dependencies:
|
||||
'@codemirror/lang-css':
|
||||
specifier: ^6.3.1
|
||||
version: 6.3.1
|
||||
'@codemirror/lang-html':
|
||||
specifier: ^6.4.11
|
||||
version: 6.4.11
|
||||
'@codemirror/lang-javascript':
|
||||
specifier: ^6.2.5
|
||||
version: 6.2.5
|
||||
'@codemirror/lang-python':
|
||||
specifier: ^6.2.1
|
||||
version: 6.2.1
|
||||
'@codemirror/lang-xml':
|
||||
specifier: ^6.1.0
|
||||
version: 6.1.0
|
||||
'@codemirror/legacy-modes':
|
||||
specifier: ^6.5.3
|
||||
version: 6.5.3
|
||||
'@codemirror/theme-one-dark':
|
||||
specifier: ^6.1.3
|
||||
version: 6.1.3
|
||||
'@formatjs/intl-listformat':
|
||||
specifier: ^8.3.13
|
||||
version: 8.3.13
|
||||
@@ -315,9 +294,6 @@ importers:
|
||||
'@storybook/web-components-vite':
|
||||
specifier: ^10.6.1
|
||||
version: 10.6.1([email protected])([email protected](@types/[email protected])([email protected])([email protected]))([email protected](@types/[email protected])([email protected])([email protected])([email protected]))
|
||||
'@types/codemirror':
|
||||
specifier: ^5.60.17
|
||||
version: 5.60.17
|
||||
'@types/grecaptcha':
|
||||
specifier: ^3.0.9
|
||||
version: 3.0.9
|
||||
@@ -357,9 +333,6 @@ importers:
|
||||
chartjs-adapter-date-fns:
|
||||
specifier: ^3.0.0
|
||||
version: 3.0.0([email protected])([email protected])
|
||||
codemirror:
|
||||
specifier: ^6.0.2
|
||||
version: 6.0.2
|
||||
cookie:
|
||||
specifier: ^2.0.1
|
||||
version: 2.0.1
|
||||
@@ -438,6 +411,9 @@ importers:
|
||||
mermaid:
|
||||
specifier: ^11.17.2
|
||||
version: 11.17.2
|
||||
monaco-editor:
|
||||
specifier: ^0.57.0
|
||||
version: 0.57.0
|
||||
node-domexception:
|
||||
specifier: workspace:*
|
||||
version: link:packages/node-domexception
|
||||
@@ -492,9 +468,6 @@ importers:
|
||||
storybook:
|
||||
specifier: ^10.6.2
|
||||
version: 10.6.2(@types/[email protected])([email protected])([email protected])
|
||||
style-mod:
|
||||
specifier: ^4.1.3
|
||||
version: 4.1.3
|
||||
stylelint:
|
||||
specifier: ^17.14.1
|
||||
version: 17.14.1([email protected])([email protected])
|
||||
@@ -711,48 +684,6 @@ packages:
|
||||
'@chevrotain/[email protected]':
|
||||
resolution: {integrity: sha512-U+HFai5+zmJCkK86QsaJtoITlboZHBqrVketcO2ROv865xfCMSFpELQoz1GkX5GzME8pTa+3kbKrZHQtI0gdbw==}
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
resolution: {integrity: sha512-tlosUqb+3BbxCxZdu4tKeRghPFC+QM7q4X5YhKV2eCmPG+1r2F3f4AaSz5sCrFqUtX4Jh20VFTKecl16MgiV9g==}
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
resolution: {integrity: sha512-Ryk9y9T0FFVF0cUGhAknveAyUOl/A1qReTFi+qPKtOh2Z9F4AUBz3XOrYD4ZEgZirdugVzHvd/2/Wcwy5OliTg==}
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
resolution: {integrity: sha512-kr5fwBGiGtmz6l0LSJIbno9QrifNMUusivHbnA1H6Dmqy4HZFte3UAICix1VuKo0lMPKQr2rqB+0BkKi/S3Ejg==}
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
resolution: {integrity: sha512-9NsXp7Nwp891pQchI7gPdTwBuSuT3K65NGTHWHNJ55HjYcHLllr0rbIZNdOzas9ztc1EUVBlHou85FFZS4BNnw==}
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
resolution: {integrity: sha512-zD4e5mS+50htS7F+TYjBPsiIFGanfVqg4HyUz6WNFikgOPf2BgKlx+TQedI1w6n/IqRBVBbBWmGFdLB/7uxO4A==}
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
resolution: {integrity: sha512-IRjC8RUBhn9mGR9ywecNhB51yePWCGgvHfY1lWN/Mrp3cKuHr0isDKia+9HnvhiWNnMpbGhWrkhuWOc09exRyw==}
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
resolution: {integrity: sha512-3z0blhicHLfwi2UgkZYRPioSgVTo9PV5GP5ducFH6FaHy0IAJRg+ixj5gTR1gnT/glAIC8xv4w2VL1LoZfs+Jg==}
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
resolution: {integrity: sha512-1q4PaT+o6PbgpkJt4Q8Fv5XJxTy4FUZ4MWETtyiDw3J0Pyr9E2vqcKL+k9wcvjNTIsauxvE7OfmWj3FRPHQ76A==}
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
resolution: {integrity: sha512-xCsmIzH78MyWkib9jlPaaun57XNkfbMIhagfaZVd0iLTqlpw3jXaIcbZm72MTmmn64eTZpBVNjbyYh+QXnxRsg==}
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
resolution: {integrity: sha512-28/+iWLYxKxsvGYhSYL7zaCZqLz5+FFFDq9tVsvGv9kv8RY4fFAchJ5WX9M3YrrRlTIsECjsXPqeNgnSmNP2dg==}
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
resolution: {integrity: sha512-uMe5UO6PamJtSHrXhhHOzSX3ReWtiJrva6GnPMwSOrZtiExb5X5eExhr2OUZQVvdxPsKpY3Ro2mFbQadpPWmHA==}
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
resolution: {integrity: sha512-Zbl9NyscLMZkfXPQnNAIIAFftidrA1UbcJEIMp24C0Bukc2I5T8wJS0wsXYsnDOqCFJUeJ1BITGNs5CqPDSmSg==}
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
resolution: {integrity: sha512-NzBdIvEJmx6fjeremiGp3t/okrLPYT0d9orIc7AFun8oZcRk58aejkqhv6spnz4MLAevrKNPMQYXEWMg4s+sKA==}
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
resolution: {integrity: sha512-YImu23iyKfncJzT7sRy+rEqEhSc8RhOHqDxwy4WzXRKJwYm6iwf/9OJk5ctCAdZ6yi2ZqaGEvmf55fSVqMDrgg==}
|
||||
|
||||
'@csstools/[email protected]':
|
||||
resolution: {integrity: sha512-DtdHlgXh5ZkA43cwBcAm+huzgJiwx3ZTWVjBs94kwz2xKqSimDA3lBgCjphYgwgVUMWatSM0pDd8TILB1yrVVg==}
|
||||
engines: {node: '>=20.19.0'}
|
||||
@@ -1099,30 +1030,6 @@ packages:
|
||||
'@kurkle/[email protected]':
|
||||
resolution: {integrity: sha512-M5UknZPHRu3DEDWoipU6sE8PdkZ6Z/S+v4dD+Ke8IaNlpdSQah50lz1KtcFBa2vsdOnwbbnxJwVM4wty6udA5w==}
|
||||
|
||||
'@lezer/[email protected]':
|
||||
resolution: {integrity: sha512-sxQE460fPZyU3sdc8lafxiPwJHBzZRy/udNFynGQky1SePYBdhkBl1kOagA9uT3pxR8K09bOrmTUqA9wb/PjSQ==}
|
||||
|
||||
'@lezer/[email protected]':
|
||||
resolution: {integrity: sha512-N+tn9tej2hPvyKgHEApMOQfHczDJCwxrRFS3SPn9QjYN+uwHvEDnCgKRrb3mxDYxRS8sKMM8fhC3+lc04Abz5Q==}
|
||||
|
||||
'@lezer/[email protected]':
|
||||
resolution: {integrity: sha512-qXdH7UqTvGfdVBINrgKhDsVTJTxactNNxLk7+UMwZhU13lMHaOBlJe9Vqp907ya56Y3+ed2tlqzys7jDkTmW0g==}
|
||||
|
||||
'@lezer/[email protected]':
|
||||
resolution: {integrity: sha512-oI7n6NJml729m7pjm9lvLvmXbdoMoi2f+1pwSDJkl9d68zGr7a9Btz8NdHTGQZtW2DA25ybeuv/SyDb9D5tseg==}
|
||||
|
||||
'@lezer/[email protected]':
|
||||
resolution: {integrity: sha512-vvYx3MhWqeZtGPwDStM2dwgljd5smolYD2lR2UyFcHfxbBQebqx8yjmFmxtJ/E6nN6u1D9srOiVWm3Rb4tmcUA==}
|
||||
|
||||
'@lezer/[email protected]':
|
||||
resolution: {integrity: sha512-rnCpTIBafOx4mRp43xOxDJbFipJm/c0cia/V5TiGlhmMa+wsSdoGmUN3w5Bqrks/09Q/D4tNAmWaT8p6NRi77A==}
|
||||
|
||||
'@lezer/[email protected]':
|
||||
resolution: {integrity: sha512-MhQIURHRytsNzP/YXnqpYKW6la6voAH3kyplTOOiCdjyFY6cWWGFVmYVdHIPrElqSDf4iCDktQCockB9FxuhzQ==}
|
||||
|
||||
'@lezer/[email protected]':
|
||||
resolution: {integrity: sha512-CdDwirL0OEaStFue/66ZmFSeppuL6Dwjlk8qk153mSQwiSH/Dlri4GNymrNWnUmPl2Um7QfV1FO9KFUyX3Twww==}
|
||||
|
||||
'@lit-labs/[email protected]':
|
||||
resolution: {integrity: sha512-VHb0ALPMTlgKjM6yIxxoQNnpKyUKLD04VzeQdsiXkMqkvYlAHxq9glGLmgbb889/1GsohSOAjvQYoiBppXFqrQ==}
|
||||
|
||||
@@ -1178,9 +1085,6 @@ packages:
|
||||
'@maplibre/[email protected]':
|
||||
resolution: {integrity: sha512-j6p0AdjvAR19Z3XaCysle7A4ZSo08tYOzxD0Y9NQylwPAkwJJeYub5b2eVucdeDh7erhv69DahoLOevDRERRUw==}
|
||||
|
||||
'@marijn/[email protected]':
|
||||
resolution: {integrity: sha512-FY+MKLBoTsLNJF/eLWaOsXGdz6uh3Iu1axjPf6TUq92IYumcTcXWHoS747JARLkcdlJ/Waiaxc5wQfFO8jC6NA==}
|
||||
|
||||
'@mdx-js/[email protected]':
|
||||
resolution: {integrity: sha512-f++rKLQgUVYDAtECQ6fn/is15GkEH9+nZPM3MS0RcxVqoTfawHvDlSCH7JbMhAM6uJ32v3eXLvLmLvjGu7PTQw==}
|
||||
peerDependencies:
|
||||
@@ -2738,9 +2642,6 @@ packages:
|
||||
'@types/[email protected]':
|
||||
resolution: {integrity: sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==}
|
||||
|
||||
'@types/[email protected]':
|
||||
resolution: {integrity: sha512-AZq2FIsUHVMlp7VSe2hTfl5w4pcUkoFkM3zVsRKsn1ca8CXRDYvnin04+HP2REkwsxemuHqvDofdlhUWNpbwfw==}
|
||||
|
||||
'@types/[email protected]':
|
||||
resolution: {integrity: sha512-hOLWVbm7uRza0BYXpIIW5pxfrKe0W+D5lrFiAEYR+pb6w3N2SwSMaJbXdUfSEv+dT4MfHBLtn5js0LAWaO6otw==}
|
||||
|
||||
@@ -2893,9 +2794,6 @@ packages:
|
||||
'@types/[email protected]':
|
||||
resolution: {integrity: sha512-FmgJfu+MOcQ370SD0ev7EI8TlCAfKYU+B4m5T3yXc1CiRN94g/SZPtsCkk506aUDtlMnFZvasDwHHUcZUEaYuA==}
|
||||
|
||||
'@types/[email protected]':
|
||||
resolution: {integrity: sha512-ypzHFE/wBzh+BlH6rrBgS5I/Z7RD21pGhZ2rltb/+ZrVM1awdZwjx7hE5XfuYgHWk9uvV5HLZN3SloevCAp3Bw==}
|
||||
|
||||
'@types/[email protected]':
|
||||
resolution: {integrity: sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==}
|
||||
|
||||
@@ -3324,9 +3222,6 @@ packages:
|
||||
resolution: {integrity: sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-VhydHotNW5w1UGK0Qj96BwSk/Zqbp9WbnyK2W/eVMv4QyF41INRGpjUhFJY7/uDNuudSc33a/PKr4iDqRduvHw==}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==}
|
||||
|
||||
@@ -3414,9 +3309,6 @@ packages:
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-py8JiEKzjhYw6HPJ0L7SxLgCYim36UPRTZX43/kqGueUCZLSvnrqAiwW8HtQibur7mdkFQUkjOgdK+o/9FBtaw==}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-aK6BbWfhf4U/wCcLHKPJl/xa6VkVstRaPywWtMKGwuOLc/wZTyQYuoxgvZnNsBvv7Kg3YTBQYYBCggcviQczuA==}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-yyID2G7xhMPgVy+Kd6VPJC9s1czj5z1J8AaVsBmt5K5q9Ck9eEkWezMtm4Oe/D01Jg2K43edfhPIjk0qYEjZqA==}
|
||||
hasBin: true
|
||||
@@ -3712,6 +3604,9 @@ packages:
|
||||
resolution: {integrity: sha512-gYzvtM72ZtxQO0T048kd6HWSbbGCNOUwcnfQ01cqIJ4X2IYKFFHZ5mKvrQETcFXxsRObZulDaKmy//R7TPtsBg==}
|
||||
engines: {node: '>=20.19.0'}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-EUBjM+B+lkDE41iE82DDSCfkoPGfXx8IxFxPMjNzm/Uk4xDet77rTN9wqlxlVg71kK7XGuUMv6wUxJUwwv+Xyw==}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-B/pSlYVHQ58kqISD/yDjuJ1yfzI34m1gF4lAod2bwSRhiN4K5Cl3H8Af7hqB2PmTL911tdEudnnXn5FnhRoz0w==}
|
||||
|
||||
@@ -4713,6 +4608,11 @@ packages:
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-wiYz4+JrLyb/DqW2hkFJxP7Vd7JuTDm77fvbM8VfEQdmSMqcImWeeRbHwZjBjIFki/VaMK2BhFi7oUUZeM5bqw==}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-uIj4+faQ+MgHgwUW1l2PsPglZLOLOT1uErt06dAPtx2kjteLAkbsd/0FiYg/MGS+i7ZKLb7w2WClxHkzOOuryQ==}
|
||||
engines: {node: '>= 18'}
|
||||
hasBin: true
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-TI3V8YYWvkVf3KJe1dRkpnjs68JUPyEa5vjKrp1XEEJUAOaQc+Qj+L1qWbPd0SJuAdQkFU0h73sXXqwDYxsiDA==}
|
||||
engines: {node: '>= 20'}
|
||||
@@ -4932,6 +4832,9 @@ packages:
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-5BkI9KGoqrNvBGUe15/QlZq3OooZ8WLg1AxTpaqHRCP3HNpzPPZKE2EDz8M7c+VRmCeUw1Brp4cx/PWm3kI/5A==}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-Y3wQdFg2Va6etvQ5I82yUhGdsKrcYox6p7FfL1LbK2J4V01F9TGlepTIhnK24t7koZibmg82KGglhA1XK5IsLQ==}
|
||||
engines: {node: '>=10'}
|
||||
@@ -5767,9 +5670,6 @@ packages:
|
||||
resolution: {integrity: sha512-ki4hZQfh5rX0QDLLkOCj+h+CVNkqmp/CMf8v8kZpkNVK6jGQooMytqzLZYUVYIZcFZ6yDB70EfD8POcFXiF5oA==}
|
||||
engines: {node: '>=18'}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-i/n8VsZydrugj3Iuzll8+x/00GH2vnYsk1eomD8QiRrSAeW6ItbCQDtfXCeJHd0iwiNagqjQkvpvREEPtW3IoQ==}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-xVQwyiuxALUBNB2fBe0tmNemg9KqLtdj3T64mioFDar79B2cU8LIyz+3KL6LdiHs9NkeNfwxpKSaIVOY8f112g==}
|
||||
engines: {node: '>=20.19.0'}
|
||||
@@ -6160,9 +6060,6 @@ packages:
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-8TEXQxlldWAuIODdukIb+TR5s+9Ds40eSJrw+1iDDA9IFORPjMELarNQE3myz5XIkWWpdprmJjm1/SxMlWOC8A==}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==}
|
||||
|
||||
[email protected]:
|
||||
resolution: {integrity: sha512-3hu+tD8YzSLGuFYtPRb48vdhKMi0KQV5sn+uWr8+7dMEq/2G/dtLrdDinkLjqq5TIbIBjYJ4Ax/n3YiaW7QM8A==}
|
||||
engines: {node: 20 || >=22}
|
||||
@@ -6344,110 +6241,6 @@ snapshots:
|
||||
|
||||
'@chevrotain/[email protected]': {}
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
dependencies:
|
||||
'@codemirror/language': 6.12.4
|
||||
'@codemirror/state': 6.7.0
|
||||
'@codemirror/view': 6.43.4
|
||||
'@lezer/common': 1.5.2
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
dependencies:
|
||||
'@codemirror/language': 6.12.4
|
||||
'@codemirror/state': 6.7.0
|
||||
'@codemirror/view': 6.43.4
|
||||
'@lezer/common': 1.5.2
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
dependencies:
|
||||
'@codemirror/autocomplete': 6.20.3
|
||||
'@codemirror/language': 6.12.4
|
||||
'@codemirror/state': 6.7.0
|
||||
'@lezer/common': 1.5.2
|
||||
'@lezer/css': 1.3.4
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
dependencies:
|
||||
'@codemirror/autocomplete': 6.20.3
|
||||
'@codemirror/lang-css': 6.3.1
|
||||
'@codemirror/lang-javascript': 6.2.5
|
||||
'@codemirror/language': 6.12.4
|
||||
'@codemirror/state': 6.7.0
|
||||
'@codemirror/view': 6.43.4
|
||||
'@lezer/common': 1.5.2
|
||||
'@lezer/css': 1.3.4
|
||||
'@lezer/html': 1.3.13
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
dependencies:
|
||||
'@codemirror/autocomplete': 6.20.3
|
||||
'@codemirror/language': 6.12.4
|
||||
'@codemirror/lint': 6.9.7
|
||||
'@codemirror/state': 6.7.0
|
||||
'@codemirror/view': 6.43.4
|
||||
'@lezer/common': 1.5.2
|
||||
'@lezer/javascript': 1.5.4
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
dependencies:
|
||||
'@codemirror/autocomplete': 6.20.3
|
||||
'@codemirror/language': 6.12.4
|
||||
'@codemirror/state': 6.7.0
|
||||
'@lezer/common': 1.5.2
|
||||
'@lezer/python': 1.1.19
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
dependencies:
|
||||
'@codemirror/autocomplete': 6.20.3
|
||||
'@codemirror/language': 6.12.4
|
||||
'@codemirror/state': 6.7.0
|
||||
'@codemirror/view': 6.43.4
|
||||
'@lezer/common': 1.5.2
|
||||
'@lezer/xml': 1.0.6
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
dependencies:
|
||||
'@codemirror/state': 6.7.0
|
||||
'@codemirror/view': 6.43.4
|
||||
'@lezer/common': 1.5.2
|
||||
'@lezer/highlight': 1.2.3
|
||||
'@lezer/lr': 1.4.10
|
||||
style-mod: 4.1.3
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
dependencies:
|
||||
'@codemirror/language': 6.12.4
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
dependencies:
|
||||
'@codemirror/state': 6.7.0
|
||||
'@codemirror/view': 6.43.4
|
||||
crelt: 1.0.7
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
dependencies:
|
||||
'@codemirror/state': 6.7.0
|
||||
'@codemirror/view': 6.43.4
|
||||
crelt: 1.0.7
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
dependencies:
|
||||
'@marijn/find-cluster-break': 1.0.3
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
dependencies:
|
||||
'@codemirror/language': 6.12.4
|
||||
'@codemirror/state': 6.7.0
|
||||
'@codemirror/view': 6.43.4
|
||||
'@lezer/highlight': 1.2.3
|
||||
|
||||
'@codemirror/[email protected]':
|
||||
dependencies:
|
||||
'@codemirror/state': 6.7.0
|
||||
crelt: 1.0.7
|
||||
style-mod: 4.1.3
|
||||
w3c-keyname: 2.2.8
|
||||
|
||||
'@csstools/[email protected](@csstools/[email protected](@csstools/[email protected]))(@csstools/[email protected])':
|
||||
dependencies:
|
||||
'@csstools/css-parser-algorithms': 4.0.0(@csstools/[email protected])
|
||||
@@ -6717,46 +6510,6 @@ snapshots:
|
||||
|
||||
'@kurkle/[email protected]': {}
|
||||
|
||||
'@lezer/[email protected]': {}
|
||||
|
||||
'@lezer/[email protected]':
|
||||
dependencies:
|
||||
'@lezer/common': 1.5.2
|
||||
'@lezer/highlight': 1.2.3
|
||||
'@lezer/lr': 1.4.10
|
||||
|
||||
'@lezer/[email protected]':
|
||||
dependencies:
|
||||
'@lezer/common': 1.5.2
|
||||
|
||||
'@lezer/[email protected]':
|
||||
dependencies:
|
||||
'@lezer/common': 1.5.2
|
||||
'@lezer/highlight': 1.2.3
|
||||
'@lezer/lr': 1.4.10
|
||||
|
||||
'@lezer/[email protected]':
|
||||
dependencies:
|
||||
'@lezer/common': 1.5.2
|
||||
'@lezer/highlight': 1.2.3
|
||||
'@lezer/lr': 1.4.10
|
||||
|
||||
'@lezer/[email protected]':
|
||||
dependencies:
|
||||
'@lezer/common': 1.5.2
|
||||
|
||||
'@lezer/[email protected]':
|
||||
dependencies:
|
||||
'@lezer/common': 1.5.2
|
||||
'@lezer/highlight': 1.2.3
|
||||
'@lezer/lr': 1.4.10
|
||||
|
||||
'@lezer/[email protected]':
|
||||
dependencies:
|
||||
'@lezer/common': 1.5.2
|
||||
'@lezer/highlight': 1.2.3
|
||||
'@lezer/lr': 1.4.10
|
||||
|
||||
'@lit-labs/[email protected]': {}
|
||||
|
||||
'@lit/[email protected]':
|
||||
@@ -6830,8 +6583,6 @@ snapshots:
|
||||
'@types/geojson': 7946.0.16
|
||||
pbf: 5.1.2
|
||||
|
||||
'@marijn/[email protected]': {}
|
||||
|
||||
'@mdx-js/[email protected](@types/[email protected])([email protected])':
|
||||
dependencies:
|
||||
'@types/mdx': 2.0.14
|
||||
@@ -8217,10 +7968,6 @@ snapshots:
|
||||
'@types/deep-eql': 4.0.2
|
||||
assertion-error: 2.0.1
|
||||
|
||||
'@types/[email protected]':
|
||||
dependencies:
|
||||
'@types/tern': 0.23.9
|
||||
|
||||
'@types/[email protected]': {}
|
||||
|
||||
'@types/[email protected]':
|
||||
@@ -8390,10 +8137,6 @@ snapshots:
|
||||
|
||||
'@types/[email protected]': {}
|
||||
|
||||
'@types/[email protected]':
|
||||
dependencies:
|
||||
'@types/estree': 1.0.9
|
||||
|
||||
'@types/[email protected]': {}
|
||||
|
||||
'@types/[email protected]': {}
|
||||
@@ -8904,16 +8647,6 @@ snapshots:
|
||||
strip-ansi: 6.0.1
|
||||
wrap-ansi: 7.0.0
|
||||
|
||||
[email protected]:
|
||||
dependencies:
|
||||
'@codemirror/autocomplete': 6.20.3
|
||||
'@codemirror/commands': 6.10.4
|
||||
'@codemirror/language': 6.12.4
|
||||
'@codemirror/lint': 6.9.7
|
||||
'@codemirror/search': 6.7.1
|
||||
'@codemirror/state': 6.7.0
|
||||
'@codemirror/view': 6.43.4
|
||||
|
||||
[email protected]:
|
||||
dependencies:
|
||||
color-name: 1.1.3
|
||||
@@ -8979,8 +8712,6 @@ snapshots:
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]:
|
||||
@@ -9291,6 +9022,10 @@ snapshots:
|
||||
dependencies:
|
||||
domelementtype: 3.0.0
|
||||
|
||||
[email protected]:
|
||||
optionalDependencies:
|
||||
'@types/trusted-types': 2.0.7
|
||||
|
||||
[email protected]:
|
||||
optionalDependencies:
|
||||
'@types/trusted-types': 2.0.7
|
||||
@@ -10408,6 +10143,8 @@ snapshots:
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]: {}
|
||||
@@ -10839,6 +10576,11 @@ snapshots:
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]:
|
||||
dependencies:
|
||||
dompurify: 3.4.15
|
||||
marked: 14.0.0
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]: {}
|
||||
@@ -11888,8 +11630,6 @@ snapshots:
|
||||
dependencies:
|
||||
'@tokenizer/token': 0.3.0
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]([email protected])([email protected]):
|
||||
dependencies:
|
||||
'@csstools/css-calc': 3.2.1(@csstools/[email protected](@csstools/[email protected]))(@csstools/[email protected])
|
||||
@@ -12310,8 +12050,6 @@ snapshots:
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
[email protected]: {}
|
||||
|
||||
@@ -11,7 +11,7 @@ import { copyAssets } from "./build-assets.ts";
|
||||
import { localeManifestPlugin } from "#bundler/locale-manifest-plugin/node";
|
||||
import { mdxPlugin } from "#bundler/mdx-plugin/node";
|
||||
import { styleLoaderPlugin } from "#bundler/style-loader-plugin/node";
|
||||
import { createBundleDefinitions } from "#bundler/utils/node";
|
||||
import { createBundleAliases, createBundleDefinitions } from "#bundler/utils/node";
|
||||
import { ConsoleLogger } from "#logger/node";
|
||||
import { DistDirectory, EntryPoint, PackageRoot } from "#paths/node";
|
||||
|
||||
@@ -126,6 +126,7 @@ const BASE_ESBUILD_OPTIONS: BuildOptions = {
|
||||
...(NodeEnvironment === "production" ? ["production"] : ["development", "production"]),
|
||||
],
|
||||
plugins: BASE_ESBUILD_PLUGINS,
|
||||
alias: createBundleAliases(),
|
||||
define: bundleDefinitions,
|
||||
format: "esm",
|
||||
};
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
import "#elements/CodeEditor/ak-code-editor";
|
||||
import { CodeEditor } from "#elements/CodeEditor/ak-code-editor";
|
||||
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { userEvent } from "vitest/browser";
|
||||
|
||||
import { html, render } from "lit";
|
||||
|
||||
const mounted = new Set<HTMLElement>();
|
||||
|
||||
/**
|
||||
* Render the editor inside a form, the way the admin forms do.
|
||||
*/
|
||||
function mount(template: unknown) {
|
||||
const form = document.body.appendChild(document.createElement("form"));
|
||||
mounted.add(form);
|
||||
|
||||
render(template, form);
|
||||
|
||||
return { form, element: form.querySelector<CodeEditor>("ak-code-editor")! };
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for the lazily imported editor, then place the cursor at the end of the first line.
|
||||
*/
|
||||
async function focusEditor(element: CodeEditor) {
|
||||
// Vite's dev server transforms Monaco's modules on first import, which takes seconds.
|
||||
await vi.waitFor(() => expect(element.shadowRoot?.querySelector(".view-lines")).toBeTruthy(), {
|
||||
timeout: 15_000,
|
||||
});
|
||||
|
||||
await userEvent.click(element.shadowRoot!.querySelector(".view-lines")!);
|
||||
await userEvent.keyboard("{End}");
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
mounted.forEach((container) => container.remove());
|
||||
mounted.clear();
|
||||
});
|
||||
|
||||
describe("ak-code-editor", () => {
|
||||
it("submits the value set on the element before the editor loads", () => {
|
||||
const { form, element } = mount(
|
||||
html`<ak-code-editor name="attributes" mode="yaml" value="a: 1"></ak-code-editor>`,
|
||||
);
|
||||
|
||||
expect(new FormData(form).get("attributes")).toBe("a: 1");
|
||||
expect(element.toJSON()).toStrictEqual({ a: 1 });
|
||||
});
|
||||
|
||||
it("creates the editor once a collapsed group is opened", async () => {
|
||||
// With the module already loaded, an editor created on connect would render right away.
|
||||
await import("#elements/CodeEditor/editor");
|
||||
|
||||
const { form, element } = mount(
|
||||
html`<details>
|
||||
<summary>Advanced settings</summary>
|
||||
<ak-code-editor mode="yaml" raw value="a: 1"></ak-code-editor>
|
||||
</details>`,
|
||||
);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
|
||||
expect(element.shadowRoot?.querySelector(".monaco-editor")).toBeNull();
|
||||
|
||||
form.querySelector("details")!.open = true;
|
||||
|
||||
await focusEditor(element);
|
||||
await userEvent.keyboard("0");
|
||||
|
||||
expect(element.value).toBe("a: 10");
|
||||
});
|
||||
|
||||
it("follows typing", async () => {
|
||||
const { form, element } = mount(
|
||||
html`<ak-code-editor
|
||||
name="expression"
|
||||
mode="python"
|
||||
raw
|
||||
value="x = 1"
|
||||
></ak-code-editor>`,
|
||||
);
|
||||
|
||||
const onChange = vi.fn();
|
||||
element.addEventListener("change", onChange);
|
||||
|
||||
await focusEditor(element);
|
||||
await userEvent.keyboard("0");
|
||||
|
||||
expect(element.value).toBe("x = 10");
|
||||
expect(new FormData(form).get("expression")).toBe("x = 10");
|
||||
expect(onChange).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("ignores typing when read-only", async () => {
|
||||
const { element } = mount(
|
||||
html`<ak-code-editor mode="yaml" raw readonly value="a: 1"></ak-code-editor>`,
|
||||
);
|
||||
|
||||
await focusEditor(element);
|
||||
await userEvent.keyboard("0");
|
||||
|
||||
expect(element.value).toBe("a: 1");
|
||||
});
|
||||
|
||||
it("cuts and pastes with the keyboard", async () => {
|
||||
const { element } = mount(
|
||||
html`<ak-code-editor mode="yaml" raw value="a: 1"></ak-code-editor>`,
|
||||
);
|
||||
|
||||
await focusEditor(element);
|
||||
await userEvent.keyboard("{Shift>}{Home}{/Shift}{ControlOrMeta>}x{/ControlOrMeta}");
|
||||
|
||||
expect(element.value).toBe("");
|
||||
|
||||
await userEvent.keyboard(
|
||||
"{ControlOrMeta>}v{/ControlOrMeta}{ControlOrMeta>}v{/ControlOrMeta}",
|
||||
);
|
||||
|
||||
expect(element.value).toBe("a: 1a: 1");
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
import { pluckErrorDetail } from "#common/errors/network";
|
||||
|
||||
import type { CodeMirrorEditor } from "#elements/CodeEditor/editor";
|
||||
import type { MonacoEditor } from "#elements/CodeEditor/editor";
|
||||
import {
|
||||
CodeEditorMode,
|
||||
parseCodeEditorSource,
|
||||
@@ -8,11 +8,10 @@ import {
|
||||
} from "#elements/CodeEditor/shared";
|
||||
import { FormAssociatedElement } from "#elements/forms/form-associated-element";
|
||||
|
||||
import type { EditorState } from "@codemirror/state";
|
||||
import type { Jsonifiable } from "type-fest";
|
||||
|
||||
import { msg } from "@lit/localize";
|
||||
import { css, CSSResult } from "lit";
|
||||
import { css, CSSResult, PropertyValues } from "lit";
|
||||
import { customElement, property } from "lit/decorators.js";
|
||||
|
||||
@customElement("ak-code-editor")
|
||||
@@ -20,17 +19,22 @@ export class CodeEditor<T extends Jsonifiable = Jsonifiable> extends FormAssocia
|
||||
//#region Styles
|
||||
|
||||
public static styles: CSSResult[] = [
|
||||
// Better alignment with patternfly components
|
||||
css`
|
||||
.cm-editor {
|
||||
padding-top: calc(
|
||||
var(--pf-global--spacer--form-element) - var(--pf-global--BorderWidth--sm)
|
||||
);
|
||||
padding-bottom: calc(
|
||||
var(--pf-global--spacer--form-element) - var(--pf-global--BorderWidth--sm)
|
||||
);
|
||||
padding-right: var(--pf-c-form-control--inset--base);
|
||||
padding-left: var(--pf-c-form-control--inset--base);
|
||||
:host {
|
||||
display: block;
|
||||
/* Holds the field's place until the editor loads. */
|
||||
min-height: 3rem;
|
||||
border-radius: var(--pf-global--BorderRadius--sm);
|
||||
background-color: var(--pf-global--BackgroundColor--light-300);
|
||||
}
|
||||
|
||||
:host([theme="dark"]) {
|
||||
background-color: #282c34;
|
||||
}
|
||||
|
||||
.ak-c-code-editor {
|
||||
min-height: 3rem;
|
||||
max-height: 50vh;
|
||||
}
|
||||
`,
|
||||
];
|
||||
@@ -51,22 +55,20 @@ export class CodeEditor<T extends Jsonifiable = Jsonifiable> extends FormAssocia
|
||||
return;
|
||||
}
|
||||
|
||||
this.#parsedValue = stringifyCodeEditorSource(nextValue, this.mode);
|
||||
this.#source = stringifyCodeEditorSource(nextValue, this.mode);
|
||||
|
||||
this.#syncValidity();
|
||||
|
||||
// This is only relevant when a value has been set after the editor has been created.
|
||||
this.#editor?.view?.dispatch({
|
||||
changes: {
|
||||
from: 0,
|
||||
to: this.#editor.view?.state.doc.length,
|
||||
insert: this.#parsedValue,
|
||||
},
|
||||
});
|
||||
this.#editor?.editor.setValue(this.#source);
|
||||
}
|
||||
|
||||
public get value(): string {
|
||||
return this.#parse(this.#editor?.view?.state);
|
||||
if (typeof this.#source === "undefined") {
|
||||
return "";
|
||||
}
|
||||
|
||||
return this.#parseSource(this.#source);
|
||||
}
|
||||
|
||||
public toJSON(): string {
|
||||
@@ -74,44 +76,35 @@ export class CodeEditor<T extends Jsonifiable = Jsonifiable> extends FormAssocia
|
||||
}
|
||||
|
||||
#syncValidity() {
|
||||
this.internals.setFormValue(this.#parsedValue || "");
|
||||
this.internals.setFormValue(this.#source || "");
|
||||
|
||||
let message: string | undefined;
|
||||
const flags: ValidityStateFlags = {};
|
||||
|
||||
if (this.required && !this.#parsedValue) {
|
||||
if (this.required && !this.#source) {
|
||||
message = msg("This field is required.");
|
||||
flags.valueMissing = true;
|
||||
}
|
||||
|
||||
this.internals.setValidity(flags, message, this.#editor?.view?.dom);
|
||||
this.internals.setValidity(flags, message, this.#editor?.editor.getDomNode() ?? undefined);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region CodeMirror Internals
|
||||
//#region Monaco Internals
|
||||
|
||||
#editor?: CodeMirrorEditor;
|
||||
#editor?: MonacoEditor;
|
||||
|
||||
//#region Value State
|
||||
|
||||
#parsedValue?: string;
|
||||
|
||||
#parse(editorState?: EditorState): string {
|
||||
if (editorState) {
|
||||
return this.#parseSource(editorState.doc.toString());
|
||||
}
|
||||
|
||||
// The editor module is imported lazily.
|
||||
// A form submitted before that import resolves has no editor state to read.
|
||||
// So we fall back to the pending value stored in `#parsedValue`.
|
||||
|
||||
if (typeof this.#parsedValue === "undefined") {
|
||||
return "";
|
||||
}
|
||||
|
||||
return this.#parseSource(this.#parsedValue);
|
||||
}
|
||||
/**
|
||||
* The editor's text.
|
||||
*
|
||||
* @remarks
|
||||
* The editor is created once the element is shown, from a lazily imported module,
|
||||
* so a form submitted before then still reads the value that was set on the element.
|
||||
*/
|
||||
#source?: string;
|
||||
|
||||
#parseSource(innerValue: string): string {
|
||||
if (this.raw) {
|
||||
@@ -133,66 +126,75 @@ export class CodeEditor<T extends Jsonifiable = Jsonifiable> extends FormAssocia
|
||||
|
||||
//#region Lifecycle
|
||||
|
||||
async #initialize(root: ShadowRoot | Document) {
|
||||
async #initialize(root: ShadowRoot) {
|
||||
console.debug("ak-code-editor: initializing editor...");
|
||||
|
||||
const { CodeMirrorEditor } = await import("#elements/CodeEditor/editor");
|
||||
const { MonacoEditor } = await import("#elements/CodeEditor/editor");
|
||||
|
||||
this.#editor = new CodeMirrorEditor({
|
||||
// The element may have been removed while the editor module was loading.
|
||||
if (!this.isConnected || this.#editor) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.#editor = new MonacoEditor({
|
||||
root,
|
||||
mode: this.mode,
|
||||
theme: this.activeTheme,
|
||||
readOnly: this.disabled,
|
||||
value: this.#parsedValue || "",
|
||||
onUpdate: (view) => {
|
||||
if (!view.docChanged) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.#parsedValue = this.#parse(view.state);
|
||||
readOnly: this.readOnly || this.disabled,
|
||||
value: this.#source || "",
|
||||
onChange: (source) => {
|
||||
this.#source = source;
|
||||
this.#syncValidity();
|
||||
|
||||
this.dispatchEvent(
|
||||
new CustomEvent("change", {
|
||||
detail: view,
|
||||
}),
|
||||
);
|
||||
this.dispatchEvent(new Event("change"));
|
||||
},
|
||||
});
|
||||
|
||||
this.#editor.view.contentDOM.tabIndex = 0;
|
||||
root.appendChild(this.#editor.view.dom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defers loading Monaco until the element is shown, since many forms keep their code
|
||||
* field in a collapsed group that is usually never opened.
|
||||
*/
|
||||
#visibilityObserver = new IntersectionObserver((entries) => {
|
||||
if (!entries.some((entry) => entry.isIntersecting)) return;
|
||||
|
||||
this.#visibilityObserver.disconnect();
|
||||
this.#initialize(this.renderRoot as ShadowRoot);
|
||||
});
|
||||
|
||||
public override connectedCallback(): void {
|
||||
super.connectedCallback();
|
||||
|
||||
if (this.getAttribute("tabindex") === null) {
|
||||
this.setAttribute("tabindex", "0");
|
||||
this.#visibilityObserver.observe(this);
|
||||
}
|
||||
|
||||
protected override updated(changedProperties: PropertyValues<this>): void {
|
||||
super.updated(changedProperties);
|
||||
|
||||
if (!this.#editor) return;
|
||||
|
||||
if (changedProperties.has("mode")) {
|
||||
this.#editor.setMode(this.mode);
|
||||
}
|
||||
|
||||
this.addEventListener("focus", this.#focusListener);
|
||||
|
||||
this.role ||= "combobox";
|
||||
this.#initialize(this.shadowRoot || document);
|
||||
if (changedProperties.has("readOnly") || changedProperties.has("disabled")) {
|
||||
this.#editor.setReadOnly(this.readOnly || this.disabled);
|
||||
}
|
||||
}
|
||||
|
||||
public override disconnectedCallback(): void {
|
||||
super.disconnectedCallback();
|
||||
|
||||
this.removeEventListener("focus", this.#focusListener);
|
||||
this.#visibilityObserver.disconnect();
|
||||
|
||||
if (this.#editor) {
|
||||
console.debug("ak-code-editor: destroying editor");
|
||||
|
||||
this.#editor.dispose();
|
||||
this.#editor = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
#focusListener = () => {
|
||||
this.#editor?.view?.contentDOM?.focus();
|
||||
};
|
||||
|
||||
//#endregion
|
||||
}
|
||||
|
||||
|
||||
@@ -1,138 +1,223 @@
|
||||
/**
|
||||
* @remarks
|
||||
* This should be imported dynamically to avoid the bundle size impact of CodeMirror.
|
||||
* This should be imported dynamically to avoid the bundle size impact of Monaco.
|
||||
*
|
||||
* ```ts
|
||||
* const { CodeMirrorEditor } = await import("#elements/CodeEditor/editor");
|
||||
* const { MonacoEditor } = await import("#elements/CodeEditor/editor");
|
||||
* ```
|
||||
* @file CodeMirror editor module.
|
||||
* @file Monaco editor module.
|
||||
*/
|
||||
|
||||
import "monaco-editor/features/bracketMatching/register";
|
||||
import "monaco-editor/features/caretOperations/register";
|
||||
import "monaco-editor/features/clipboard/register";
|
||||
import "monaco-editor/features/comment/register";
|
||||
import "monaco-editor/features/contextmenu/register";
|
||||
import "monaco-editor/features/cursorUndo/register";
|
||||
import "monaco-editor/features/find/register";
|
||||
import "monaco-editor/features/folding/register";
|
||||
import "monaco-editor/features/hover/register";
|
||||
import "monaco-editor/features/gotoLine/register";
|
||||
import "monaco-editor/features/indentation/register";
|
||||
import "monaco-editor/features/linesOperations/register";
|
||||
import "monaco-editor/features/multicursor/register";
|
||||
import "monaco-editor/features/readOnlyMessage/register";
|
||||
import "monaco-editor/features/smartSelect/register";
|
||||
import "monaco-editor/features/snippet/register";
|
||||
import "monaco-editor/features/toggleTabFocusMode/register";
|
||||
import "monaco-editor/features/wordHighlighter/register";
|
||||
import "monaco-editor/features/wordOperations/register";
|
||||
import "monaco-editor/features/wordPartOperations/register";
|
||||
import "monaco-editor/languages/definitions/css/register";
|
||||
import "monaco-editor/languages/definitions/html/register";
|
||||
import "monaco-editor/languages/definitions/javascript/register";
|
||||
import "monaco-editor/languages/definitions/python/register";
|
||||
import "monaco-editor/languages/definitions/xml/register";
|
||||
import "monaco-editor/languages/definitions/yaml/register";
|
||||
// The suggestion widget has no feature entry point of its own.
|
||||
import "monaco-editor/editor/contrib/suggest/browser/suggestController";
|
||||
// Monaco's package exports do not cover its CSS, so the bundlers alias this path to the file.
|
||||
import MonacoStyles from "monaco-editor/min/vs/editor/editor.main.css";
|
||||
|
||||
import { createStyleSheetUnsafe, setAdoptedStyleSheets } from "#common/stylesheets";
|
||||
import { ResolvedUITheme, ThemeChangeEvent } from "#common/theme";
|
||||
|
||||
import { CodeEditorMode } from "#elements/CodeEditor/shared";
|
||||
import { OneDark } from "#elements/CodeEditor/themes/one-dark";
|
||||
|
||||
import { UiThemeEnum } from "@goauthentik/api";
|
||||
|
||||
import { defaultKeymap, history, historyKeymap, indentWithTab } from "@codemirror/commands";
|
||||
import { css as cssLang } from "@codemirror/lang-css";
|
||||
import { html as htmlLang } from "@codemirror/lang-html";
|
||||
import { javascript } from "@codemirror/lang-javascript";
|
||||
import { python } from "@codemirror/lang-python";
|
||||
import { xml } from "@codemirror/lang-xml";
|
||||
import {
|
||||
defaultHighlightStyle,
|
||||
LanguageSupport,
|
||||
StreamLanguage,
|
||||
syntaxHighlighting,
|
||||
} from "@codemirror/language";
|
||||
import * as yamlMode from "@codemirror/legacy-modes/mode/yaml";
|
||||
import type { Extension } from "@codemirror/state";
|
||||
import { Compartment, EditorState } from "@codemirror/state";
|
||||
import { oneDark, oneDarkHighlightStyle } from "@codemirror/theme-one-dark";
|
||||
import { drawSelection, EditorView, keymap, lineNumbers, ViewUpdate } from "@codemirror/view";
|
||||
import { match } from "ts-pattern";
|
||||
import { editor as monaco } from "monaco-editor/editor/editor.api";
|
||||
|
||||
//#region Language support
|
||||
const $MonacoStyles = createStyleSheetUnsafe(MonacoStyles);
|
||||
|
||||
export function createLanguageSupport(mode: CodeEditorMode): LanguageSupport {
|
||||
return match(mode)
|
||||
.with(CodeEditorMode.XML, () => xml())
|
||||
.with(CodeEditorMode.JavaScript, () => javascript())
|
||||
.with(CodeEditorMode.HTML, () => htmlLang())
|
||||
.with(CodeEditorMode.Python, () => python())
|
||||
.with(CodeEditorMode.CSS, () => cssLang())
|
||||
.with(CodeEditorMode.YAML, () => new LanguageSupport(StreamLanguage.define(yamlMode.yaml)))
|
||||
.exhaustive();
|
||||
/**
|
||||
* The rules of Monaco's stylesheet that must apply to the document rather than the editor's
|
||||
* shadow root:
|
||||
*
|
||||
* - Chromium ignores `@font-face` rules in a shadow root's styles, so the icon font only loads when
|
||||
* the document declares it.
|
||||
* - Monaco appends its screen reader live region, which announces e.g. search results, to the
|
||||
* document body. Without the rule that moves it off screen, the announcements are visible below
|
||||
* the page.
|
||||
*/
|
||||
const $MonacoDocumentStyles = new CSSStyleSheet();
|
||||
|
||||
for (const rule of $MonacoStyles.cssRules) {
|
||||
if (
|
||||
rule instanceof CSSFontFaceRule ||
|
||||
(rule instanceof CSSStyleRule && rule.selectorText === ".monaco-aria-container")
|
||||
) {
|
||||
$MonacoDocumentStyles.insertRule(rule.cssText);
|
||||
}
|
||||
}
|
||||
|
||||
export interface CodeMirrorInit {
|
||||
setAdoptedStyleSheets(document, (currentStyleSheets) => [
|
||||
...currentStyleSheets,
|
||||
$MonacoDocumentStyles,
|
||||
]);
|
||||
|
||||
// Keeps the editor apart from the white form behind it, as PatternFly's
|
||||
// `--pf-global--BackgroundColor--light-300` does for other fields.
|
||||
// Monaco themes only take literal colors.
|
||||
monaco.defineTheme("ak-light", {
|
||||
base: "vs",
|
||||
inherit: true,
|
||||
rules: [],
|
||||
colors: { "editor.background": "#f0f0f0" },
|
||||
});
|
||||
|
||||
monaco.defineTheme("ak-dark", OneDark);
|
||||
|
||||
/**
|
||||
* Language services, loaded with the first editor of their language.
|
||||
*/
|
||||
const LanguageServices: Partial<Record<CodeEditorMode, () => Promise<unknown>>> = {
|
||||
[CodeEditorMode.CSS]: () => import("#elements/CodeEditor/languages/css-service"),
|
||||
[CodeEditorMode.Python]: () => import("#elements/CodeEditor/languages/python-service"),
|
||||
};
|
||||
|
||||
function loadLanguageService(mode: CodeEditorMode): void {
|
||||
LanguageServices[mode]?.().catch((error: unknown) => {
|
||||
console.warn("code-editor: failed to load language service", mode, error);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Python is indented by four spaces by convention, and in authentik's documentation.
|
||||
*/
|
||||
function tabSize(mode: CodeEditorMode): number {
|
||||
return mode === CodeEditorMode.Python ? 4 : 2;
|
||||
}
|
||||
|
||||
function themeName(theme: ResolvedUITheme): string {
|
||||
return theme === UiThemeEnum.Dark ? "ak-dark" : "ak-light";
|
||||
}
|
||||
|
||||
export interface MonacoEditorInit {
|
||||
mode?: CodeEditorMode;
|
||||
theme?: ResolvedUITheme;
|
||||
readOnly?: boolean;
|
||||
value?: string;
|
||||
root: Document | ShadowRoot;
|
||||
onUpdate?: (update: ViewUpdate) => void;
|
||||
root: ShadowRoot;
|
||||
onChange?: (value: string) => void;
|
||||
}
|
||||
|
||||
export class CodeMirrorEditor implements Disposable {
|
||||
public view: EditorView;
|
||||
export class MonacoEditor implements Disposable {
|
||||
public editor: monaco.IStandaloneCodeEditor;
|
||||
|
||||
#container = document.createElement("div");
|
||||
#themeAbortController = new AbortController();
|
||||
|
||||
#theme: Compartment = new Compartment();
|
||||
#syntaxHighlighting: Compartment = new Compartment();
|
||||
|
||||
#themeLight = EditorView.theme(
|
||||
{
|
||||
"&": {
|
||||
backgroundColor: "var(--pf-global--BackgroundColor--light-300)",
|
||||
},
|
||||
},
|
||||
{ dark: false },
|
||||
);
|
||||
#themeDark = oneDark;
|
||||
|
||||
#syntaxHighlightingLight = syntaxHighlighting(defaultHighlightStyle);
|
||||
#syntaxHighlightingDark = syntaxHighlighting(oneDarkHighlightStyle);
|
||||
|
||||
constructor({
|
||||
mode = CodeEditorMode.JavaScript,
|
||||
theme = "light",
|
||||
readOnly = false,
|
||||
value = "",
|
||||
onUpdate = () => {},
|
||||
onChange = () => {},
|
||||
root,
|
||||
}: CodeMirrorInit) {
|
||||
const dark = theme === UiThemeEnum.Dark;
|
||||
}: MonacoEditorInit) {
|
||||
setAdoptedStyleSheets(root, (currentStyleSheets) =>
|
||||
currentStyleSheets.includes($MonacoStyles)
|
||||
? currentStyleSheets
|
||||
: [...currentStyleSheets, $MonacoStyles],
|
||||
);
|
||||
|
||||
const extensions: Array<Extension | null> = [
|
||||
history(),
|
||||
keymap.of([...defaultKeymap, ...historyKeymap, indentWithTab]),
|
||||
createLanguageSupport(mode),
|
||||
lineNumbers(),
|
||||
drawSelection(),
|
||||
EditorView.lineWrapping,
|
||||
EditorView.updateListener.of(onUpdate),
|
||||
EditorState.readOnly.of(!!readOnly),
|
||||
EditorState.tabSize.of(2),
|
||||
this.#syntaxHighlighting.of(
|
||||
dark ? this.#syntaxHighlightingDark : this.#syntaxHighlightingLight,
|
||||
),
|
||||
this.#theme.of(dark ? this.#themeDark : this.#themeLight),
|
||||
];
|
||||
this.#container.className = "ak-c-code-editor";
|
||||
root.appendChild(this.#container);
|
||||
|
||||
this.view = new EditorView({
|
||||
extensions: extensions.filter(Boolean) as Extension[],
|
||||
root,
|
||||
doc: value,
|
||||
this.editor = monaco.create(this.#container, {
|
||||
value,
|
||||
language: mode,
|
||||
theme: themeName(theme),
|
||||
readOnly,
|
||||
automaticLayout: true,
|
||||
minimap: { enabled: false },
|
||||
wordWrap: "on",
|
||||
tabSize: tabSize(mode),
|
||||
// The editor grows with its content, see the content size listener below.
|
||||
scrollBeyondLastLine: false,
|
||||
// Let the page scroll once the editor has nothing left to scroll.
|
||||
scrollbar: { alwaysConsumeMouseWheel: false },
|
||||
renderLineHighlightOnlyWhenFocus: true,
|
||||
renderWhitespace: "selection",
|
||||
guides: { bracketPairs: "active" },
|
||||
padding: { top: 6, bottom: 6 },
|
||||
// Word suggestions are computed in a web worker, which is not bundled.
|
||||
wordBasedSuggestions: "off",
|
||||
});
|
||||
|
||||
document.addEventListener(ThemeChangeEvent.eventName, this.#themeChangeListener, {
|
||||
signal: this.#themeAbortController.signal,
|
||||
loadLanguageService(mode);
|
||||
|
||||
// Monaco needs an explicit height. Following the content keeps short values compact,
|
||||
// and the container's CSS `max-height` caps long ones, which then scroll.
|
||||
const followContentHeight = () => {
|
||||
this.#container.style.height = `${this.editor.getContentHeight()}px`;
|
||||
};
|
||||
|
||||
followContentHeight();
|
||||
this.editor.onDidContentSizeChange(followContentHeight);
|
||||
|
||||
// Monaco scrolls its own viewport to reveal a search match or the cursor, which does
|
||||
// not help while part of the editor is scrolled out of the surrounding form or modal.
|
||||
// Clicks are left alone, since scrolling the page under the pointer turns them into
|
||||
// selections.
|
||||
this.editor.onDidChangeCursorSelection(({ source }) => {
|
||||
if (source === "mouse") return;
|
||||
|
||||
this.#container.scrollIntoView({ block: "nearest" });
|
||||
});
|
||||
|
||||
this.editor.onDidChangeModelContent(() => {
|
||||
onChange(this.editor.getValue());
|
||||
});
|
||||
|
||||
document.addEventListener(
|
||||
ThemeChangeEvent.eventName,
|
||||
(event) => monaco.setTheme(themeName(event.theme)),
|
||||
{ signal: this.#themeAbortController.signal },
|
||||
);
|
||||
}
|
||||
|
||||
#themeChangeListener = (event: ThemeChangeEvent) => {
|
||||
if (!this.view) {
|
||||
return;
|
||||
public setMode(mode: CodeEditorMode): void {
|
||||
const model = this.editor.getModel();
|
||||
|
||||
if (model) {
|
||||
monaco.setModelLanguage(model, mode);
|
||||
model.updateOptions({ tabSize: tabSize(mode) });
|
||||
}
|
||||
|
||||
const effects =
|
||||
event.theme === UiThemeEnum.Dark
|
||||
? [
|
||||
this.#theme.reconfigure(this.#themeDark),
|
||||
this.#syntaxHighlighting.reconfigure(this.#syntaxHighlightingDark),
|
||||
]
|
||||
: [
|
||||
this.#theme.reconfigure(this.#themeLight),
|
||||
this.#syntaxHighlighting.reconfigure(this.#syntaxHighlightingLight),
|
||||
];
|
||||
loadLanguageService(mode);
|
||||
}
|
||||
|
||||
this.view.dispatch({ effects });
|
||||
};
|
||||
public setReadOnly(readOnly: boolean): void {
|
||||
this.editor.updateOptions({ readOnly });
|
||||
}
|
||||
|
||||
public [Symbol.dispose](): void {
|
||||
this.view.destroy();
|
||||
this.#themeAbortController.abort();
|
||||
this.editor.dispose();
|
||||
this.#container.remove();
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* @remarks
|
||||
* Runs Monaco's CSS language service on the page instead of in a web worker. Its `register`
|
||||
* entry point would start a worker and, through Monaco's worker setup, load every editor
|
||||
* feature this package leaves out.
|
||||
* @file CSS suggestions, hovers and validation.
|
||||
*/
|
||||
|
||||
import { PageWorkerContext } from "#elements/CodeEditor/languages/page-worker";
|
||||
|
||||
import { languages } from "monaco-editor/editor/editor.api";
|
||||
import {
|
||||
CompletionAdapter,
|
||||
DiagnosticsAdapter,
|
||||
FoldingRangeAdapter,
|
||||
HoverAdapter,
|
||||
} from "monaco-editor/languages/features/common/lspLanguageFeatures";
|
||||
import { CSSWorker } from "monaco-editor/languages/features/css/cssWorker";
|
||||
|
||||
const service = new CSSWorker(PageWorkerContext, {
|
||||
languageId: "css",
|
||||
options: {
|
||||
validate: true,
|
||||
data: { useDefaultDataProvider: true },
|
||||
},
|
||||
});
|
||||
|
||||
const worker = () => Promise.resolve(service);
|
||||
|
||||
languages.registerCompletionItemProvider("css", new CompletionAdapter(worker, ["/", "-", ":"]));
|
||||
languages.registerHoverProvider("css", new HoverAdapter(worker));
|
||||
languages.registerFoldingRangeProvider("css", new FoldingRangeAdapter(worker));
|
||||
|
||||
new DiagnosticsAdapter("css", worker, (listener) => {
|
||||
// The adapter only checks models created after it, so check the existing ones once.
|
||||
queueMicrotask(listener);
|
||||
|
||||
return { dispose() {} };
|
||||
});
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* @file Types for the Monaco modules that ship without declarations.
|
||||
*/
|
||||
|
||||
declare module "monaco-editor/editor/contrib/suggest/browser/suggestController" {}
|
||||
|
||||
declare module "monaco-editor/languages/features/common/lspLanguageFeatures" {
|
||||
import type { IDisposable, languages, Uri } from "monaco-editor/editor/editor.api";
|
||||
|
||||
/**
|
||||
* Resolves the language service that answers for the given models.
|
||||
*/
|
||||
export type WorkerAccessor<T> = (...uris: Uri[]) => Promise<T>;
|
||||
|
||||
export class CompletionAdapter<T> implements languages.CompletionItemProvider {
|
||||
constructor(worker: WorkerAccessor<T>, triggerCharacters: string[]);
|
||||
triggerCharacters: string[];
|
||||
provideCompletionItems: languages.CompletionItemProvider["provideCompletionItems"];
|
||||
}
|
||||
|
||||
export class HoverAdapter<T> implements languages.HoverProvider {
|
||||
constructor(worker: WorkerAccessor<T>);
|
||||
provideHover: languages.HoverProvider["provideHover"];
|
||||
}
|
||||
|
||||
export class FoldingRangeAdapter<T> implements languages.FoldingRangeProvider {
|
||||
constructor(worker: WorkerAccessor<T>);
|
||||
provideFoldingRanges: languages.FoldingRangeProvider["provideFoldingRanges"];
|
||||
}
|
||||
|
||||
export class DiagnosticsAdapter<T> implements IDisposable {
|
||||
constructor(
|
||||
languageId: string,
|
||||
worker: WorkerAccessor<T>,
|
||||
configChangeEvent: (listener: () => void) => IDisposable,
|
||||
);
|
||||
dispose(): void;
|
||||
}
|
||||
}
|
||||
|
||||
declare module "monaco-editor/languages/features/css/cssWorker" {
|
||||
/**
|
||||
* The model data a language service reads, as Monaco's worker mirrors it.
|
||||
*/
|
||||
export interface MirrorModel {
|
||||
readonly uri: { toString(): string };
|
||||
readonly version: number;
|
||||
getValue(): string;
|
||||
}
|
||||
|
||||
export interface CSSWorkerContext {
|
||||
getMirrorModels(): MirrorModel[];
|
||||
}
|
||||
|
||||
export interface CSSWorkerCreateData {
|
||||
languageId: "css" | "less" | "scss";
|
||||
options: {
|
||||
validate?: boolean;
|
||||
lint?: Record<string, "ignore" | "warning" | "error">;
|
||||
data?: { useDefaultDataProvider?: boolean };
|
||||
};
|
||||
}
|
||||
|
||||
export class CSSWorker {
|
||||
constructor(ctx: CSSWorkerContext, createData: CSSWorkerCreateData);
|
||||
}
|
||||
}
|
||||
|
||||
declare module "monaco-editor/languages/definitions/python/python" {
|
||||
import type { languages } from "monaco-editor/editor/editor.api";
|
||||
|
||||
/**
|
||||
* The Monarch definition Monaco highlights Python with.
|
||||
*/
|
||||
export const language: languages.IMonarchLanguage & { keywords: string[] };
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* @file Lets Monaco's language services, written to run in a web worker, run on the page.
|
||||
*/
|
||||
|
||||
import { editor } from "monaco-editor/editor/editor.api";
|
||||
import type { CSSWorkerContext } from "monaco-editor/languages/features/css/cssWorker";
|
||||
|
||||
/**
|
||||
* Gives a language service the editor's models, in place of the copies a worker would hold.
|
||||
*/
|
||||
export const PageWorkerContext: CSSWorkerContext = {
|
||||
getMirrorModels: () =>
|
||||
editor.getModels().map((model) => ({
|
||||
uri: model.uri,
|
||||
version: model.getVersionId(),
|
||||
getValue: () => model.getValue(),
|
||||
})),
|
||||
};
|
||||
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* @remarks
|
||||
* Expressions are the body of a function the server wraps them in, so `return` is valid at the
|
||||
* top level and the context variables are that function's parameters, which are not known here.
|
||||
* @file Python suggestions.
|
||||
*/
|
||||
|
||||
import { editor, languages, Range } from "monaco-editor/editor/editor.api";
|
||||
import { language } from "monaco-editor/languages/definitions/python/python";
|
||||
|
||||
/**
|
||||
* The keywords and builtins Monaco highlights, without dunder names such as `__init__`.
|
||||
*/
|
||||
const Keywords = Array.from(new Set(language.keywords as string[])).filter(
|
||||
(keyword) => !keyword.startsWith("__"),
|
||||
);
|
||||
|
||||
const KeywordSet = new Set(Keywords);
|
||||
|
||||
const Snippets: Record<string, string> = {
|
||||
"if": "if ${1:condition}:\n\t${0:pass}",
|
||||
"if/else": "if ${1:condition}:\n\t${2:pass}\nelse:\n\t${0:pass}",
|
||||
"for": "for ${1:item} in ${2:items}:\n\t${0:pass}",
|
||||
"try/except": "try:\n\t${1:pass}\nexcept ${2:Exception} as ${3:exc}:\n\t${0:pass}",
|
||||
"def": "def ${1:name}(${2}):\n\t${0:pass}",
|
||||
"with": "with ${1:expression} as ${2:target}:\n\t${0:pass}",
|
||||
};
|
||||
|
||||
/**
|
||||
* Names already written in the expression, as Monaco's tokenizer finds them, so names in strings
|
||||
* and comments are left out.
|
||||
*/
|
||||
function collectNames(model: editor.ITextModel, currentWord: string): Set<string> {
|
||||
const names = new Set<string>();
|
||||
const lines = model.getLinesContent();
|
||||
|
||||
editor.tokenize(model.getValue(), "python").forEach((tokens, lineIndex) => {
|
||||
const line = lines[lineIndex];
|
||||
|
||||
tokens.forEach((token, tokenIndex) => {
|
||||
if (token.type !== "identifier.python") return;
|
||||
|
||||
const end = tokens[tokenIndex + 1]?.offset ?? line.length;
|
||||
const name = line.slice(token.offset, end);
|
||||
|
||||
if (name !== currentWord && !KeywordSet.has(name)) names.add(name);
|
||||
});
|
||||
});
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
languages.registerCompletionItemProvider("python", {
|
||||
provideCompletionItems(model, position) {
|
||||
const word = model.getWordUntilPosition(position);
|
||||
|
||||
const range = new Range(
|
||||
position.lineNumber,
|
||||
word.startColumn,
|
||||
position.lineNumber,
|
||||
word.endColumn,
|
||||
);
|
||||
|
||||
// Attribute access needs to know the object's type.
|
||||
const before = model.getLineContent(position.lineNumber).slice(0, word.startColumn - 1);
|
||||
|
||||
if (before.trimEnd().endsWith(".")) return { suggestions: [] };
|
||||
|
||||
const { CompletionItemKind: Kind, CompletionItemInsertTextRule: Rule } = languages;
|
||||
|
||||
const suggestions: languages.CompletionItem[] = [
|
||||
...Keywords.map((label) => ({
|
||||
label,
|
||||
kind: Kind.Keyword,
|
||||
insertText: label,
|
||||
range,
|
||||
})),
|
||||
...Object.entries(Snippets).map(([label, insertText]) => ({
|
||||
label,
|
||||
kind: Kind.Snippet,
|
||||
insertText,
|
||||
insertTextRules: Rule.InsertAsSnippet,
|
||||
range,
|
||||
})),
|
||||
...Array.from(collectNames(model, word.word), (label) => ({
|
||||
label,
|
||||
kind: Kind.Variable,
|
||||
insertText: label,
|
||||
range,
|
||||
})),
|
||||
];
|
||||
|
||||
return { suggestions };
|
||||
},
|
||||
});
|
||||
@@ -1,5 +1,8 @@
|
||||
import { parse as parseYAML, stringify as stringifyYAML } from "yaml";
|
||||
|
||||
/**
|
||||
* The languages the code editor highlights, named by their Monaco language ID.
|
||||
*/
|
||||
export const CodeEditorMode = {
|
||||
XML: "xml",
|
||||
JavaScript: "javascript",
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Joshua Azemoh
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,505 @@
|
||||
/**
|
||||
* @file One Dark theme for Monaco.
|
||||
* @see https://github.com/azemoh/vscode-onedark (MIT, vendored at 37abe2b, see one-dark.LICENSE)
|
||||
*/
|
||||
|
||||
import type { editor } from "monaco-editor/editor/editor.api";
|
||||
|
||||
interface TokenColor {
|
||||
scope?: string | string[];
|
||||
settings: { foreground?: string; background?: string; fontStyle?: string };
|
||||
}
|
||||
|
||||
/**
|
||||
* Monaco's language definitions emit Monarch token names rather than TextMate scopes.
|
||||
* Each maps to the TextMate scope whose color it takes.
|
||||
*/
|
||||
const MonarchScopes: Record<string, string> = {
|
||||
"number": "constant.numeric",
|
||||
"tag": "entity.name.tag",
|
||||
"metatag": "entity.name.tag",
|
||||
"attribute.name": "entity.other.attribute-name",
|
||||
"attribute.value": "string",
|
||||
"type": "entity.name.type",
|
||||
"namespace": "entity.name.module",
|
||||
"operators": "keyword.operator",
|
||||
"regexp": "string.embedded",
|
||||
};
|
||||
|
||||
function toRule(token: string, { foreground, background, fontStyle }: TokenColor["settings"]) {
|
||||
return {
|
||||
token,
|
||||
foreground: foreground?.replace("#", ""),
|
||||
background: background?.replace("#", ""),
|
||||
fontStyle,
|
||||
} satisfies editor.ITokenThemeRule;
|
||||
}
|
||||
|
||||
function createRules(tokenColors: TokenColor[]): editor.ITokenThemeRule[] {
|
||||
const settingsByScope = new Map<string, TokenColor["settings"]>();
|
||||
|
||||
for (const { scope, settings } of tokenColors) {
|
||||
for (const name of [scope ?? []].flat()) {
|
||||
// Scope selectors with exclusions have no Monaco equivalent.
|
||||
if (!name.includes(" ")) settingsByScope.set(name, settings);
|
||||
}
|
||||
}
|
||||
|
||||
const rules = Array.from(settingsByScope, ([token, settings]) => toRule(token, settings));
|
||||
|
||||
for (const [token, scope] of Object.entries(MonarchScopes)) {
|
||||
const settings = settingsByScope.get(scope);
|
||||
|
||||
if (settings) rules.push(toRule(token, settings));
|
||||
}
|
||||
|
||||
return rules;
|
||||
}
|
||||
|
||||
//#region Vendored theme
|
||||
|
||||
const OneDarkTheme = {
|
||||
tokenColors: [
|
||||
{
|
||||
settings: {
|
||||
background: "#282c34",
|
||||
foreground: "#abb2bf",
|
||||
findHighlight: "#FFE792",
|
||||
findHighlightForeground: "#000000",
|
||||
selectionBorder: "#222218",
|
||||
activeGuide: "#9D550FB0",
|
||||
bracketsForeground: "#F8F8F2A5",
|
||||
bracketsOptions: "underline",
|
||||
bracketContentsForeground: "#F8F8F2A5",
|
||||
bracketContentsOptions: "underline",
|
||||
tagsOptions: "stippled_underline",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Comment",
|
||||
scope: "comment",
|
||||
settings: {
|
||||
foreground: "#5c6370",
|
||||
fontStyle: "italic",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Comment",
|
||||
scope: "html.doctype",
|
||||
settings: {
|
||||
foreground: "#5c6370",
|
||||
fontStyle: "italic",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "String",
|
||||
scope: "string",
|
||||
settings: {
|
||||
foreground: "#98c379",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Embedded String Begin and End",
|
||||
scope: ["string.embedded.begin", "string.embedded.end"],
|
||||
settings: {
|
||||
foreground: "#e06c75",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Embedded String",
|
||||
scope: "string.embedded",
|
||||
settings: {
|
||||
foreground: "#56b6c2",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Number",
|
||||
scope: "constant.numeric",
|
||||
settings: {
|
||||
foreground: "#d19a66",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Built-in constant",
|
||||
scope: "constant.language",
|
||||
settings: {
|
||||
foreground: "#d19a66",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "User-defined constant",
|
||||
scope: ["constant.character", "constant.other"],
|
||||
settings: {
|
||||
foreground: "#d19a66",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Language Variable",
|
||||
scope: "variable.language",
|
||||
settings: {
|
||||
foreground: "#c678dd",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Variable",
|
||||
scope: ["variable.readwrite", "variable.block", "variable.support"],
|
||||
settings: {
|
||||
foreground: "#e06c75",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Variable",
|
||||
scope: "variable.readwrite.var-single-variable.js",
|
||||
settings: {
|
||||
foreground: "#d19a66",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Variable",
|
||||
scope: "variable.readwrite.js",
|
||||
settings: {
|
||||
foreground: "#abb2bf",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Keyword",
|
||||
scope: [
|
||||
"keyword",
|
||||
"keyword.operator.logical",
|
||||
"keyword.operator.constructor",
|
||||
"keyword.operator.new",
|
||||
],
|
||||
settings: {
|
||||
foreground: "#c678dd",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Keyword Operator",
|
||||
scope: "keyword.operator",
|
||||
settings: {
|
||||
foreground: "#61afef",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Storage",
|
||||
scope: "storage",
|
||||
settings: {
|
||||
fontStyle: "",
|
||||
foreground: "#c678dd",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Storage type",
|
||||
scope: "storage.type.function",
|
||||
settings: {
|
||||
foreground: "#c678dd",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Class name",
|
||||
scope: ["entity.name.class", "entity.name.module", "entity.name.type"],
|
||||
settings: {
|
||||
foreground: "#e5c07b",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Inherited class",
|
||||
scope: "entity.other.inherited-class",
|
||||
settings: {
|
||||
foreground: "#98c379",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Tag name",
|
||||
scope: "entity.name.tag",
|
||||
settings: {
|
||||
fontStyle: "",
|
||||
foreground: "#e06c75",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Tag attribute",
|
||||
scope: "entity.other.attribute-name",
|
||||
settings: {
|
||||
fontStyle: "",
|
||||
foreground: "#d19a66",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Function name",
|
||||
scope: "entity.name.function",
|
||||
settings: {
|
||||
fontStyle: "",
|
||||
foreground: "#61afef",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Function argument",
|
||||
scope: "variable.parameter",
|
||||
settings: {
|
||||
fontStyle: "italic",
|
||||
foreground: "#e06c75",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Function call",
|
||||
scope: "entity.name.function-call",
|
||||
settings: {
|
||||
fontStyle: "",
|
||||
foreground: "#abb2bf",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Builtin Functions",
|
||||
scope: ["function.support.builtin", "function.support.core"],
|
||||
settings: {
|
||||
fontStyle: "",
|
||||
foreground: "#56b6c2",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Library function",
|
||||
scope: "support.function",
|
||||
settings: {
|
||||
foreground: "#56b6c2",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Library constant",
|
||||
scope: "support.constant",
|
||||
settings: {
|
||||
fontStyle: "",
|
||||
foreground: "#e5c07b",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Library class/type",
|
||||
scope: "support.class",
|
||||
settings: {
|
||||
foreground: "#e5c07b",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Library type",
|
||||
scope: "support.type",
|
||||
settings: {
|
||||
foreground: "#e06c75",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Json Property",
|
||||
scope: "support.dictionary.json",
|
||||
settings: {
|
||||
foreground: "#e06c75",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "StyleSheet Property name",
|
||||
scope: [
|
||||
"support.type.property-name.css",
|
||||
"support.type.property-name.scss",
|
||||
"support.type.property-name.less",
|
||||
"support.type.property-name.sass",
|
||||
],
|
||||
settings: {
|
||||
foreground: "#abb2bf",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "StyleSheet Property value",
|
||||
scope: [
|
||||
"support.constant.css",
|
||||
"support.constant.scss",
|
||||
"support.constant.less",
|
||||
"support.constant.sass",
|
||||
],
|
||||
settings: {
|
||||
foreground: "#56b6c2",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "StyleSheet Variable",
|
||||
scope: ["variable.css", "variable.scss", "variable.less", "variable.sass"],
|
||||
settings: {
|
||||
foreground: "#e06c75",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "StyleSheet Variable String",
|
||||
scope: [
|
||||
"variable.css.string",
|
||||
"variable.scss.string",
|
||||
"variable.less.string",
|
||||
"variable.sass.string",
|
||||
],
|
||||
settings: {
|
||||
foreground: "#98c379",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "StyleSheet Unit",
|
||||
scope: ["unit.css", "unit.scss", "unit.less", "unit.sass"],
|
||||
settings: {
|
||||
foreground: "#d19a66",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "StyleSheet Function",
|
||||
scope: ["function.css", "function.scss", "function.less", "function.sass"],
|
||||
settings: {
|
||||
foreground: "#56b6c2",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Other variable",
|
||||
scope: ["variable.other.property", "variable.other.object", "variable.other.block"],
|
||||
settings: {
|
||||
foreground: "#e06c75",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Pug/Jade Import",
|
||||
scope: ["jade.import.variable", "pug.import.variable"],
|
||||
settings: {
|
||||
foreground: "#e06c75",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Invalid",
|
||||
scope: "invalid",
|
||||
settings: {
|
||||
background: "#c678dd",
|
||||
fontStyle: "",
|
||||
foreground: "#F8F8F0",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Invalid deprecated",
|
||||
scope: "invalid.deprecated",
|
||||
settings: {
|
||||
background: "#56b6c2",
|
||||
foreground: "#F8F8F0",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "JSON String",
|
||||
scope: "structure.dictionary.property-name.json",
|
||||
settings: {
|
||||
foreground: "#e06c75",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Link",
|
||||
scope: "string.detected-link",
|
||||
settings: {
|
||||
foreground: "#c678dd",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "diff.header",
|
||||
scope: ["meta.diff", "meta.diff.header"],
|
||||
settings: {
|
||||
foreground: "#75715E",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "diff.deleted",
|
||||
scope: "markup.deleted",
|
||||
settings: {
|
||||
foreground: "#c678dd",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "diff.inserted",
|
||||
scope: "markup.inserted",
|
||||
settings: {
|
||||
foreground: "#e5c07b",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "diff.changed",
|
||||
scope: "markup.changed",
|
||||
settings: {
|
||||
foreground: "#98c379",
|
||||
},
|
||||
},
|
||||
{
|
||||
scope: "constant.numeric.line-number.find-in-files - match",
|
||||
settings: {
|
||||
foreground: "#56b6c2A0",
|
||||
},
|
||||
},
|
||||
{
|
||||
scope: "entity.name.filename.find-in-files",
|
||||
settings: {
|
||||
foreground: "#98c379",
|
||||
},
|
||||
},
|
||||
],
|
||||
colors: {
|
||||
"activityBar.background": "#2F333D",
|
||||
"activityBar.foreground": "#D7DAE0",
|
||||
"activityBarBadge.background": "#528bff",
|
||||
"activityBarBadge.foreground": "#F8FAFD",
|
||||
"button.background": "#528bff",
|
||||
"dropdown.background": "#1d1f23",
|
||||
"diffEditor.insertedTextBackground": "#00809B33",
|
||||
"dropdown.border": "#181A1F",
|
||||
"editor.background": "#282c34",
|
||||
"editorError.foreground": "#c24038",
|
||||
"editorRuler.foreground": "#484848",
|
||||
"editor.lineHighlightBackground": "#383E4A",
|
||||
"editor.selectionBackground": "#3E4451",
|
||||
"editorCursor.foreground": "#f8f8f0",
|
||||
"editor.editor.findMatchBackground": "#42557B",
|
||||
"editor.findMatchHighlightBackground": "#314365",
|
||||
"editorGroup.background": "#181A1F",
|
||||
"editorGroup.border": "#181A1F",
|
||||
"editorGroupHeader.tabsBackground": "#21252B",
|
||||
"editorIndentGuide.background": "#3B4048",
|
||||
"editorLineNumber.foreground": "#495162",
|
||||
"editorWhitespace.foreground": "#3B4048",
|
||||
"editorHoverWidget.background": "#21252B",
|
||||
"editorHoverWidget.border": "#181A1F",
|
||||
"editorSuggestWidget.background": "#21252B",
|
||||
"editorSuggestWidget.border": "#181A1F",
|
||||
"editorSuggestWidget.selectedBackground": "#2c313a",
|
||||
"editorWidget.background": "#21252B",
|
||||
"input.background": "#1d1f23",
|
||||
"list.activeSelectionBackground": "#2c313a",
|
||||
"list.activeSelectionForeground": "#d7dae0",
|
||||
"list.focusBackground": "#383E4A",
|
||||
"list.hoverBackground": "#292d35",
|
||||
"list.highlightForeground": "#C5C5C5",
|
||||
"list.inactiveSelectionBackground": "#2c313a",
|
||||
"list.inactiveSelectionForeground": "#d7dae0",
|
||||
"notification.background": "#21252b",
|
||||
"scrollbarSlider.background": "#4E566680",
|
||||
"scrollbarSlider.activeBackground": "#747D9180",
|
||||
"scrollbarSlider.hoverBackground": "#5A637580",
|
||||
"sideBar.background": "#21252b",
|
||||
"sideBarSectionHeader.background": "#282c34",
|
||||
"statusBar.background": "#21252B",
|
||||
"statusBar.foreground": "#9da5b4",
|
||||
"statusBarItem.hoverBackground": "#2c313a",
|
||||
"statusBar.noFolderBackground": "#21252B",
|
||||
"statusBar.debuggingBackground": "#21252B",
|
||||
"tab.activeBackground": "#2c313a",
|
||||
"tab.border": "#181A1F",
|
||||
"tab.inactiveBackground": "#21252B",
|
||||
"titleBar.activeBackground": "#282c34",
|
||||
"titleBar.activeForeground": "#9da5b4",
|
||||
"titleBar.inactiveBackground": "#282C34",
|
||||
"titleBar.inactiveForeground": "#6B717D",
|
||||
},
|
||||
name: "One Dark Theme",
|
||||
};
|
||||
|
||||
//#endregion
|
||||
|
||||
export const OneDark: editor.IStandaloneThemeData = {
|
||||
base: "vs-dark",
|
||||
inherit: true,
|
||||
rules: createRules(OneDarkTheme.tokenColors),
|
||||
colors: OneDarkTheme.colors,
|
||||
};
|
||||
@@ -103,7 +103,7 @@ web/src/styles/
|
||||
authentik/ # component CSS
|
||||
components/<Name>/ # Per-component overrides or new, unique components
|
||||
login.css # login-screen layout + token bridges
|
||||
atom/ # CodeMirror CSS stuff (imported into the CodeMirror component)
|
||||
atom/ # One Dark syntax colors (imported into ak-mdx)
|
||||
```
|
||||
|
||||
Note: quite a number of components have embedded CSS of their own (via Lit's `css()` function) or
|
||||
|
||||
@@ -25,7 +25,7 @@ test.describe("Invitation form", () => {
|
||||
//#endregion
|
||||
|
||||
// Regression for goauthentik/authentik#22637: typing custom attributes into the
|
||||
// CodeMirror editor must not block submission.
|
||||
// code editor must not block submission.
|
||||
test("Create invitation with custom attributes", async ({ page, form, pointer }, testInfo) => {
|
||||
const name = invitationNames.get(testInfo.testId)!;
|
||||
const { fill, selectSearchValue } = form;
|
||||
|
||||
+19
-7
@@ -2,7 +2,7 @@
|
||||
|
||||
import { join } from "node:path";
|
||||
|
||||
import { createBundleDefinitions } from "#bundler/utils/node";
|
||||
import { createBundleAliases, createBundleDefinitions } from "#bundler/utils/node";
|
||||
import { inlineCSSPlugin } from "#bundler/vite-plugin-lit-css/node";
|
||||
|
||||
import { resolvePackage } from "@goauthentik/core/paths/node";
|
||||
@@ -12,14 +12,24 @@ import { defineConfig } from "vite";
|
||||
|
||||
const patternflyPath = resolvePackage("@patternfly/patternfly", import.meta);
|
||||
|
||||
/**
|
||||
* @satisfies {import("vite").UserConfig["resolve"]}
|
||||
*/
|
||||
const resolve = {
|
||||
alias: [
|
||||
// `inlineCSSPlugin` appends `?inline` to CSS imports, which a string alias won't match.
|
||||
...Object.entries(createBundleAliases()).map(([find, replacement]) => ({
|
||||
find: new RegExp(`^${RegExp.escape(find)}(?=\\?|$)`),
|
||||
replacement,
|
||||
})),
|
||||
{ find: "./assets/fonts", replacement: join(patternflyPath, "assets", "fonts") },
|
||||
{ find: "./assets/pficon", replacement: join(patternflyPath, "assets", "pficon") },
|
||||
],
|
||||
};
|
||||
|
||||
export default defineConfig({
|
||||
define: createBundleDefinitions(),
|
||||
resolve: {
|
||||
alias: {
|
||||
"./assets/fonts": join(patternflyPath, "assets", "fonts"),
|
||||
"./assets/pficon": join(patternflyPath, "assets", "pficon"),
|
||||
},
|
||||
},
|
||||
resolve,
|
||||
optimizeDeps: {
|
||||
// Fixes dependency resolution issue associated with `npm link`ed packages.
|
||||
include: ["@goauthentik/api"],
|
||||
@@ -66,6 +76,8 @@ export default defineConfig({
|
||||
// this the CSS resolves to a Vite style side-effect with no
|
||||
// default export, and importing any AKElement throws.
|
||||
plugins: [inlineCSSPlugin()],
|
||||
// Nor the root aliases, which the code editor needs for Monaco's stylesheet.
|
||||
resolve,
|
||||
test: {
|
||||
setupFiles: ["./test/lit/setup.js"],
|
||||
|
||||
|
||||
Reference in new issue
Block a user