@bhsd/codemirror-mediawiki 2.19.6 → 2.19.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/i18n/en.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.19.6",
2
+ "version": "2.19.7",
3
3
  "lang": "en",
4
4
  "i18n-failed": "Failed to fetch the translation file in $1.",
5
5
  "title": "CodeMirror Addons",
package/i18n/zh-hans.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.19.6",
2
+ "version": "2.19.7",
3
3
  "lang": "zh-hans",
4
4
  "i18n-failed": "获取 $1 的语言文件失败。",
5
5
  "title": "CodeMirror插件",
package/i18n/zh-hant.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.19.6",
2
+ "version": "2.19.7",
3
3
  "lang": "zh-hant",
4
4
  "i18n-failed": "取得 $1 的語言檔案失敗。",
5
5
  "title": "CodeMirror外掛程式",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bhsd/codemirror-mediawiki",
3
- "version": "2.19.6",
3
+ "version": "2.19.7",
4
4
  "description": "Modified CodeMirror mode based on wikimedia/mediawiki-extensions-CodeMirror",
5
5
  "keywords": [
6
6
  "mediawiki",
@@ -34,10 +34,10 @@
34
34
  "scripts": {
35
35
  "prepublishOnly": "npm run build",
36
36
  "build:core": "esbuild ./src/codemirror.ts --charset=utf8 --bundle --minify --target=es2019 --format=esm --sourcemap --outfile=dist/main.min.js && esbuild ./src/linter.ts --charset=utf8 --target=es2019 --format=esm --outfile=dist/linter.mjs && tsc --emitDeclarationOnly",
37
- "build:mw": "esbuild ./mw/base.ts --charset=utf8 --bundle --minify --target=es2019 --format=esm --sourcemap --outfile=dist/mw.min.js && esbuild ./mw/config.ts --charset=utf8 --bundle --target=es2019 --format=esm --outfile=dist/mwConfig.mjs",
37
+ "build:mw": "esbuild ./mw/base.ts --charset=utf8 --bundle --minify --target=es2019 --format=esm --outfile=dist/mw.min.js && esbuild ./mw/config.ts --charset=utf8 --bundle --target=es2019 --format=esm --outfile=dist/mwConfig.mjs",
38
38
  "build:wiki": "esbuild ./mw/base.ts --charset=utf8 --bundle --minify --target=es2019 --format=iife --sourcemap --outfile=dist/wiki.min.js",
39
39
  "build:gh-page": "bash build.sh",
40
- "build:test": "tsc --project test/tsconfig.json && node test/dist/test/test.js",
40
+ "build:test": "tsc --project test/tsconfig.json && mocha",
41
41
  "build": "npm run build:core && npm run build:mw && npm run build:wiki && eslint --no-eslintrc -c .eslintrc.dist.cjs dist/*.js",
42
42
  "lint:ts": "tsc --noEmit && tsc --project mw/tsconfig.json --noEmit && tsc --project test/tsconfig.json --noEmit && eslint --cache .",
43
43
  "lint:css": "stylelint *.css",
@@ -72,6 +72,7 @@
72
72
  "@stylistic/stylelint-plugin": "^3.1.1",
73
73
  "@types/eslint": "^8.56.10",
74
74
  "@types/jquery": "^3.5.32",
75
+ "@types/mocha": "^10.0.10",
75
76
  "@types/node": "^22.10.1",
76
77
  "@types/oojs-ui": "^0.49.0",
77
78
  "@typescript-eslint/eslint-plugin": "^8.16.0",
@@ -89,6 +90,7 @@
89
90
  "eslint-plugin-unicorn": "^56.0.1",
90
91
  "http-server": "^14.1.0",
91
92
  "luacheck-browserify": "^0.2.0",
93
+ "mocha": "^10.8.2",
92
94
  "monaco-editor": "^0.52.0",
93
95
  "monaco-wiki": "^1.5.0",
94
96
  "stylelint": "^16.11.0",
package/src/static.ts CHANGED
@@ -26,41 +26,35 @@ export const tagModes = {
26
26
  graph: 'json',
27
27
  };
28
28
 
29
- /**
30
- * Object.fromEntries polyfill
31
- * @param entries
32
- * @param obj
33
- * @param string 是否为字符串
34
- */
35
- const fromEntries = (entries: readonly string[], obj: Record<string, unknown>, string?: boolean): void => {
36
- for (const entry of entries) {
37
- obj[entry] = string ? entry : true;
38
- }
39
- };
40
-
41
29
  export const getStaticMwConfig = (
42
- {parserFunction, protocol, nsid, variants, redirection, ext, doubleUnderscore, img}: Config,
30
+ {
31
+ parserFunction: [p0, p1, ...p2],
32
+ protocol,
33
+ nsid,
34
+ variants,
35
+ redirection,
36
+ ext,
37
+ doubleUnderscore: [d0, d1, d2],
38
+ img,
39
+ }: Config,
43
40
  modes: Record<string, string>,
44
- ): MwConfig => {
45
- const mwConfig: MwConfig = {
46
- tags: {},
47
- tagModes: modes,
48
- doubleUnderscore: [{}, {}],
49
- functionSynonyms: [parserFunction[0], {}],
50
- urlProtocols: `${protocol}|//`,
51
- nsid,
52
- img: Object.fromEntries(Object.entries(img).map(([key, val]) => [key, `img_${val}`])),
53
- variants,
54
- redirection,
41
+ ): MwConfig => ({
42
+ tags: Object.fromEntries(ext.map(s => [s, true])),
43
+ tagModes: modes,
44
+ doubleUnderscore: [
45
+ Object.fromEntries((d2 && d0.length === 0 ? Object.keys(d2) : d0).map(s => [`__${s}__`, true])),
46
+ Object.fromEntries(d1.map(s => [`__${s}__`, true])),
47
+ ],
48
+ functionSynonyms: [
49
+ {
50
+ ...p0,
51
+ ...Object.fromEntries(p2.flat().map(s => [s, s])),
55
52
  },
56
- [insensitive,, obj] = doubleUnderscore;
57
- fromEntries(ext, mwConfig.tags);
58
- fromEntries(
59
- (obj && insensitive.length === 0 ? Object.keys(obj) : insensitive).map(s => `__${s}__`),
60
- mwConfig.doubleUnderscore[0],
61
- );
62
- fromEntries(doubleUnderscore[1].map(s => `__${s}__`), mwConfig.doubleUnderscore[1]);
63
- fromEntries((parserFunction.slice(2) as string[][]).flat(), mwConfig.functionSynonyms[0], true);
64
- fromEntries(parserFunction[1], mwConfig.functionSynonyms[1]);
65
- return mwConfig;
66
- };
53
+ Object.fromEntries(p1.map(s => [s, true])),
54
+ ],
55
+ urlProtocols: `${protocol}|//`,
56
+ nsid,
57
+ img: Object.fromEntries(Object.entries(img).map(([k, v]) => [k, `img_${v}`])),
58
+ variants,
59
+ redirection,
60
+ });