@bhsd/codemirror-mediawiki 3.0.3 → 3.2.0

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/dist/static.d.ts CHANGED
@@ -19,9 +19,5 @@ export declare const tagModes: {
19
19
  combobox: string;
20
20
  combooption: string;
21
21
  inputbox: string;
22
- templatedata: string;
23
- mapframe: string;
24
- maplink: string;
25
- graph: string;
26
22
  };
27
23
  export declare const getStaticMwConfig: ({ variable, parserFunction: [p0, p1, ...p2], protocol, nsid, functionHook, variants, redirection, ext, doubleUnderscore: [d0, d1, d2, d3], img, }: ConfigData, modes: Record<string, string>) => MwConfig;
package/dist/static.js CHANGED
@@ -17,10 +17,6 @@ export const tagModes = {
17
17
  combobox: 'text/combobox',
18
18
  combooption: 'mediawiki',
19
19
  inputbox: 'text/inputbox',
20
- templatedata: 'json',
21
- mapframe: 'json',
22
- maplink: 'json',
23
- graph: 'json',
24
20
  };
25
21
  export const getStaticMwConfig = ({ variable, parserFunction: [p0, p1, ...p2], protocol, nsid, functionHook, variants, redirection, ext, doubleUnderscore: [d0, d1, d2, d3], img, }, modes) => ({
26
22
  tags: Object.fromEntries(ext.map(s => [s, true])),
@@ -1,4 +1,5 @@
1
1
  import type { Extension } from '@codemirror/state';
2
+ import type { CodeMirror6 } from './codemirror';
2
3
  import type { LintSource } from './lintsource';
3
- declare const _default: (fixer: LintSource["fixer"]) => Extension;
4
+ declare const _default: (cm: CodeMirror6, fixer: LintSource["fixer"]) => Extension;
4
5
  export default _default;
package/dist/statusBar.js CHANGED
@@ -1,5 +1,11 @@
1
1
  import { showPanel } from '@codemirror/view';
2
2
  import { nextDiagnostic, setDiagnosticsEffect } from '@codemirror/lint';
3
+ import { menuRegistry } from './codemirror';
4
+ const optionAll = /* @__PURE__ */ (() => {
5
+ const ele = document.createElement('div');
6
+ ele.textContent = 'Fix all auto-fixable problems';
7
+ return ele;
8
+ })();
3
9
  function getLintMarker(view, severity, menu) {
4
10
  const marker = document.createElement('div'), icon = document.createElement('div');
5
11
  marker.className = `cm-status-${severity}`;
@@ -36,10 +42,20 @@ function getLintMarker(view, severity, menu) {
36
42
  const updateDiagnosticsCount = (diagnostics, s, marker) => {
37
43
  marker.lastChild.textContent = String(diagnostics.filter(({ severity }) => severity === s).length);
38
44
  };
39
- const hasFix = (diagnostic) => diagnostic.actions?.some(({ name }) => name === 'fix');
40
- const updateDiagnosticMessage = (view, allDiagnostics, main, msg, menu) => {
41
- const diagnostics = allDiagnostics.filter(({ from, to }) => from <= main.to && to >= main.from), diagnostic = diagnostics.find(({ from, to }) => from <= main.head && to >= main.head) ?? diagnostics[0];
42
- if (diagnostic) {
45
+ const hasFix = (diagnostic) => diagnostic.actions?.some(({ name }) => name === 'fix' || name.startsWith('Fix:'));
46
+ const isItemActionable = (cm, { name, isActionable }) => cm.hasPreference(name) && isActionable(cm);
47
+ const toggleClass = (classList, enabled) => {
48
+ classList.toggle('cm-status-fix-enabled', enabled);
49
+ classList.toggle('cm-status-fix-disabled', !enabled);
50
+ };
51
+ const getDiagnostics = (all, main) => all.filter(({ from, to }) => from <= main.to && to >= main.from);
52
+ const updateDiagnosticMessage = (cm, allDiagnostics, main, msg) => {
53
+ const diagnostics = getDiagnostics(allDiagnostics, main);
54
+ if (diagnostics.length === 0) {
55
+ msg.textContent = '';
56
+ }
57
+ else {
58
+ const diagnostic = diagnostics.find(({ from, to }) => from <= main.head && to >= main.head) ?? diagnostics[0], view = cm.view;
43
59
  msg.textContent = diagnostic.message;
44
60
  if (diagnostic.actions) {
45
61
  msg.append(...diagnostic.actions.map(({ name, apply }) => {
@@ -55,52 +71,58 @@ const updateDiagnosticMessage = (view, allDiagnostics, main, msg, menu) => {
55
71
  }));
56
72
  }
57
73
  }
58
- else {
59
- msg.textContent = '';
60
- }
74
+ };
75
+ const updateMenu = (cm, allDiagnostics, main, classList, menu, fixer) => {
61
76
  if (menu) {
62
- menu.replaceChildren(...[
63
- ...new Set(diagnostics.filter(hasFix)
64
- .map(({ message }) => / \(([^()]+)\)$/u.exec(message)?.[1])
65
- .filter(Boolean)),
66
- ].map(rule => {
77
+ const actionable = menuRegistry.filter(item => isItemActionable(cm, item)), fixable = new Set(fixer && getDiagnostics(allDiagnostics, main).filter(hasFix)
78
+ .map(({ message }) => / \(([^()]+)\)$/u.exec(message)?.[1])
79
+ .filter(Boolean));
80
+ if (actionable.length === 0 && fixable.size === 0) {
81
+ toggleClass(classList, false);
82
+ return;
83
+ }
84
+ toggleClass(classList, true);
85
+ const actions = actionable.flatMap(({ getItems }) => getItems(cm)), quickfix = [...fixable].map(rule => {
67
86
  const option = document.createElement('div');
68
87
  option.textContent = `Fix all ${rule} problems`;
69
88
  option.dataset['rule'] = rule;
70
89
  return option;
71
- }), menu.lastChild);
90
+ });
91
+ if (fixable.size > 0) {
92
+ quickfix.push(optionAll);
93
+ }
94
+ menu.replaceChildren(...actions, ...quickfix);
72
95
  }
73
96
  };
74
97
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
75
- export default (fixer) => showPanel.of(view => {
98
+ export default (cm, fixer) => showPanel.of(view => {
76
99
  let diagnostics = [], menu;
77
- if (fixer) {
78
- const optionAll = document.createElement('div');
79
- optionAll.textContent = 'Fix all auto-fixable problems';
100
+ if (!view.state.readOnly && (fixer || menuRegistry.length > 0)) {
80
101
  menu = document.createElement('div');
81
102
  menu.className = 'cm-status-fix-menu';
82
103
  menu.tabIndex = -1;
83
- menu.append(optionAll);
84
- menu.addEventListener('click', ({ target }) => {
85
- if (target === menu) {
86
- return;
87
- }
88
- (async () => {
89
- const { doc } = view.state, output = await fixer(doc, target.dataset['rule']);
90
- if (output !== doc.toString()) {
91
- view.dispatch({
92
- changes: { from: 0, to: doc.length, insert: output },
93
- });
104
+ if (fixer) {
105
+ menu.addEventListener('click', ({ target }) => {
106
+ if (target === menu) {
107
+ return;
94
108
  }
95
- view.focus();
96
- })();
97
- });
109
+ (async () => {
110
+ const { doc } = view.state, output = await fixer(doc, target.dataset['rule']);
111
+ if (output !== doc.toString()) {
112
+ view.dispatch({
113
+ changes: { from: 0, to: doc.length, insert: output },
114
+ });
115
+ }
116
+ view.focus();
117
+ })();
118
+ });
119
+ }
98
120
  menu.addEventListener('focusout', () => {
99
121
  menu.style.display = 'none';
100
122
  });
101
123
  view.dom.append(menu);
102
124
  }
103
- const dom = document.createElement('div'), worker = document.createElement('div'), message = document.createElement('div'), position = document.createElement('div'), error = getLintMarker(view, 'error'), warning = getLintMarker(view, 'warning'), fix = getLintMarker(view, 'fix', menu);
125
+ const dom = document.createElement('div'), worker = document.createElement('div'), message = document.createElement('div'), position = document.createElement('div'), error = getLintMarker(view, 'error'), warning = getLintMarker(view, 'warning'), fix = getLintMarker(view, 'fix', menu), { classList } = fix.firstChild;
104
126
  worker.className = 'cm-status-worker';
105
127
  worker.append(error, warning, fix);
106
128
  message.className = 'cm-status-message';
@@ -110,23 +132,22 @@ export default (fixer) => showPanel.of(view => {
110
132
  dom.append(worker, message, position);
111
133
  return {
112
134
  dom,
113
- update({ state: { selection: { main }, doc, readOnly }, transactions, docChanged, selectionSet }) {
135
+ update({ state: { selection: { main }, doc }, transactions, docChanged, selectionSet }) {
114
136
  for (const tr of transactions) {
115
137
  for (const effect of tr.effects) {
116
138
  if (effect.is(setDiagnosticsEffect)) {
117
139
  diagnostics = effect.value;
118
- const fixable = !readOnly && Boolean(fixer) && diagnostics.some(hasFix), { classList } = fix.firstChild;
119
- classList.toggle('cm-status-fix-enabled', fixable);
120
- classList.toggle('cm-status-fix-disabled', !fixable);
121
140
  worker.classList.toggle('cm-status-worker-enabled', diagnostics.length > 0);
122
141
  updateDiagnosticsCount(diagnostics, 'error', error);
123
142
  updateDiagnosticsCount(diagnostics, 'warning', warning);
124
- updateDiagnosticMessage(view, diagnostics, main, message, menu);
143
+ updateDiagnosticMessage(cm, diagnostics, main, message);
144
+ updateMenu(cm, diagnostics, main, classList, menu, fixer);
125
145
  }
126
146
  }
127
147
  }
128
148
  if (docChanged || selectionSet) {
129
- updateDiagnosticMessage(view, diagnostics, main, message, menu);
149
+ updateDiagnosticMessage(cm, diagnostics, main, message);
150
+ updateMenu(cm, diagnostics, main, classList, menu, fixer);
130
151
  const { number, from } = doc.lineAt(main.head);
131
152
  position.textContent = `${number}:${main.head - from}`;
132
153
  if (!main.empty) {
package/dist/token.d.ts CHANGED
@@ -181,8 +181,5 @@ export declare class MediaWiki {
181
181
  'text/inputbox'(): StreamParser<State>;
182
182
  inGallery(section?: boolean): Tokenizer;
183
183
  'text/gallery'(tags: string[]): StreamParser<State>;
184
- javascript(): StreamParser<unknown>;
185
- json(): StreamParser<unknown>;
186
- lua(): StreamParser<unknown>;
187
184
  }
188
185
  export {};
package/dist/token.js CHANGED
@@ -41,8 +41,6 @@ import { Tag } from '@lezer/highlight';
41
41
  import { getRegex } from '@bhsd/common';
42
42
  import { decodeHTML } from '@bhsd/browser';
43
43
  import { otherParserFunctions } from '@bhsd/cm-util';
44
- import { javascript, json } from '@codemirror/legacy-modes/mode/javascript';
45
- import { lua } from '@codemirror/legacy-modes/mode/lua';
46
44
  import { htmlTags, voidHtmlTags, selfClosingTags, tokenTable, tokens } from './config';
47
45
  class MediaWikiData {
48
46
  constructor(tags) {
@@ -1268,7 +1266,7 @@ let MediaWiki = (() => {
1268
1266
  else if (stream.eat('>')) {
1269
1267
  const { config: { tagModes } } = this;
1270
1268
  state.extName = name;
1271
- state.extMode ||= name in tagModes
1269
+ state.extMode ||= name in tagModes && (tagModes[name]) in this
1272
1270
  && this[tagModes[name]](state.data.tags.filter(tag => tag !== name));
1273
1271
  if (state.extMode) {
1274
1272
  state.extState = state.extMode.startState(0);
@@ -1992,15 +1990,6 @@ let MediaWiki = (() => {
1992
1990
  },
1993
1991
  };
1994
1992
  }
1995
- javascript() {
1996
- return javascript;
1997
- }
1998
- json() {
1999
- return json;
2000
- }
2001
- lua() {
2002
- return lua;
2003
- }
2004
1993
  };
2005
1994
  })();
2006
1995
  export { MediaWiki };
package/dist/vue.js CHANGED
@@ -3,12 +3,12 @@ import { htmlLanguage, htmlCompletionSource } from '@codemirror/lang-html';
3
3
  import { javascript } from '@codemirror/lang-javascript';
4
4
  import { LanguageSupport } from '@codemirror/language';
5
5
  import { jsCompletion } from './javascript';
6
- import css from './css';
6
+ import { cssCompletion } from './css';
7
7
  export default () => vue({
8
8
  base: new LanguageSupport(htmlLanguage, [
9
9
  htmlLanguage.data.of({ autocomplete: htmlCompletionSource }),
10
10
  javascript().support,
11
11
  jsCompletion,
12
- css(undefined).support,
12
+ cssCompletion(),
13
13
  ]),
14
14
  });