@bhsd/codemirror-mediawiki 3.2.0 → 3.4.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/ref.js CHANGED
@@ -82,4 +82,13 @@ export default (cm) => [
82
82
  }
83
83
  }
84
84
  }),
85
+ EditorView.theme({
86
+ '.cm-tooltip-ref': {
87
+ padding: '2px 5px',
88
+ width: 'max-content',
89
+ maxWidth: '60vw',
90
+ cursor: 'pointer',
91
+ whiteSpace: 'pre-wrap',
92
+ },
93
+ }),
85
94
  ];
package/dist/statusBar.js CHANGED
@@ -1,4 +1,4 @@
1
- import { showPanel } from '@codemirror/view';
1
+ import { showPanel, EditorView } from '@codemirror/view';
2
2
  import { nextDiagnostic, setDiagnosticsEffect } from '@codemirror/lint';
3
3
  import { menuRegistry } from './codemirror';
4
4
  const optionAll = /* @__PURE__ */ (() => {
@@ -94,66 +94,144 @@ const updateMenu = (cm, allDiagnostics, main, classList, menu, fixer) => {
94
94
  menu.replaceChildren(...actions, ...quickfix);
95
95
  }
96
96
  };
97
+ const panelSelector = '.cm-panel-status', workerSelector = '.cm-status-worker', errorSelector = '.cm-status-error', warningSelector = '.cm-status-warning', enabledSelector = '.cm-status-fix-enabled', disabledSelector = '.cm-status-fix-disabled', menuSelector = '.cm-status-fix-menu', messageSelector = '.cm-status-message';
97
98
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
98
- export default (cm, fixer) => showPanel.of(view => {
99
- let diagnostics = [], menu;
100
- if (!view.state.readOnly && (fixer || menuRegistry.length > 0)) {
101
- menu = document.createElement('div');
102
- menu.className = 'cm-status-fix-menu';
103
- menu.tabIndex = -1;
104
- if (fixer) {
105
- menu.addEventListener('click', ({ target }) => {
106
- if (target === menu) {
107
- return;
108
- }
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
- });
99
+ export default (cm, fixer) => [
100
+ showPanel.of(view => {
101
+ let diagnostics = [], menu;
102
+ if (!view.state.readOnly && (fixer || menuRegistry.length > 0)) {
103
+ menu = document.createElement('div');
104
+ menu.className = 'cm-status-fix-menu';
105
+ menu.tabIndex = -1;
106
+ if (fixer) {
107
+ menu.addEventListener('click', ({ target }) => {
108
+ if (target === menu) {
109
+ return;
115
110
  }
116
- view.focus();
117
- })();
111
+ (async () => {
112
+ const { doc } = view.state, output = await fixer(doc, target.dataset['rule']);
113
+ if (output !== doc.toString()) {
114
+ view.dispatch({
115
+ changes: { from: 0, to: doc.length, insert: output },
116
+ });
117
+ }
118
+ view.focus();
119
+ })();
120
+ });
121
+ }
122
+ menu.addEventListener('focusout', () => {
123
+ menu.style.display = 'none';
118
124
  });
125
+ view.dom.append(menu);
119
126
  }
120
- menu.addEventListener('focusout', () => {
121
- menu.style.display = 'none';
122
- });
123
- view.dom.append(menu);
124
- }
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;
126
- worker.className = 'cm-status-worker';
127
- worker.append(error, warning, fix);
128
- message.className = 'cm-status-message';
129
- position.className = 'cm-status-line';
130
- position.textContent = '0:0';
131
- dom.className = 'cm-panel cm-panel-status';
132
- dom.append(worker, message, position);
133
- return {
134
- dom,
135
- update({ state: { selection: { main }, doc }, transactions, docChanged, selectionSet }) {
136
- for (const tr of transactions) {
137
- for (const effect of tr.effects) {
138
- if (effect.is(setDiagnosticsEffect)) {
139
- diagnostics = effect.value;
140
- worker.classList.toggle('cm-status-worker-enabled', diagnostics.length > 0);
141
- updateDiagnosticsCount(diagnostics, 'error', error);
142
- updateDiagnosticsCount(diagnostics, 'warning', warning);
143
- updateDiagnosticMessage(cm, diagnostics, main, message);
144
- updateMenu(cm, diagnostics, main, classList, menu, fixer);
127
+ 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;
128
+ worker.className = 'cm-status-worker';
129
+ worker.append(error, warning, fix);
130
+ message.className = 'cm-status-message';
131
+ position.className = 'cm-status-line';
132
+ position.textContent = '0:0';
133
+ dom.className = 'cm-panel cm-panel-status';
134
+ dom.append(worker, message, position);
135
+ return {
136
+ dom,
137
+ update({ state: { selection: { main }, doc }, transactions, docChanged, selectionSet }) {
138
+ for (const tr of transactions) {
139
+ for (const effect of tr.effects) {
140
+ if (effect.is(setDiagnosticsEffect)) {
141
+ diagnostics = effect.value;
142
+ worker.classList.toggle('cm-status-worker-enabled', diagnostics.length > 0);
143
+ updateDiagnosticsCount(diagnostics, 'error', error);
144
+ updateDiagnosticsCount(diagnostics, 'warning', warning);
145
+ updateDiagnosticMessage(cm, diagnostics, main, message);
146
+ updateMenu(cm, diagnostics, main, classList, menu, fixer);
147
+ }
145
148
  }
146
149
  }
147
- }
148
- if (docChanged || selectionSet) {
149
- updateDiagnosticMessage(cm, diagnostics, main, message);
150
- updateMenu(cm, diagnostics, main, classList, menu, fixer);
151
- const { number, from } = doc.lineAt(main.head);
152
- position.textContent = `${number}:${main.head - from}`;
153
- if (!main.empty) {
154
- position.textContent += ` (${main.to - main.from})`;
150
+ if (docChanged || selectionSet) {
151
+ updateDiagnosticMessage(cm, diagnostics, main, message);
152
+ updateMenu(cm, diagnostics, main, classList, menu, fixer);
153
+ const { number, from } = doc.lineAt(main.head);
154
+ position.textContent = `${number}:${main.head - from}`;
155
+ if (!main.empty) {
156
+ position.textContent += ` (${main.to - main.from})`;
157
+ }
155
158
  }
156
- }
159
+ },
160
+ };
161
+ }),
162
+ EditorView.theme({
163
+ [panelSelector]: {
164
+ lineHeight: 1.4,
165
+ },
166
+ [`${panelSelector}>div`]: {
167
+ padding: '0 .3em',
168
+ display: 'table-cell',
169
+ },
170
+ [workerSelector]: {
171
+ '-webkitUserSelect': 'none',
172
+ userSelect: 'none',
173
+ },
174
+ [`${workerSelector}>*`]: {
175
+ display: 'table-cell',
176
+ whiteSpace: 'nowrap',
177
+ },
178
+ [`${errorSelector},${warningSelector}`]: {
179
+ paddingRight: '8px',
180
+ },
181
+ [`.cm-status-worker-enabled ${errorSelector},.cm-status-worker-enabled ${warningSelector}`]: {
182
+ cursor: 'pointer',
183
+ },
184
+ [`${workerSelector}>*>div`]: {
185
+ display: 'inline-block',
186
+ verticalAlign: 'middle',
187
+ },
188
+ [`${workerSelector}>*>div:first-child`]: {
189
+ marginRight: '4px',
190
+ width: '1em',
191
+ height: '1em',
192
+ },
193
+ [`${disabledSelector},${enabledSelector}`]: {
194
+ maskImage: "url('data:image/svg+xml,"
195
+ + '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20">'
196
+ // eslint-disable-next-line @stylistic/max-len
197
+ + '<path d="M8 19a1 1 0 001 1h2a1 1 0 001-1v-1H8zm9-12a7 7 0 10-12 4.9S7 14 7 15v1a1 1 0 001 1h4a1 1 0 001-1v-1c0-1 2-3.1 2-3.1A7 7 0 0017 7"/>'
198
+ + '</svg>'
199
+ + "')",
200
+ maskSize: '100%',
201
+ maskRepeat: 'no-repeat',
202
+ maskPosition: 'center',
203
+ },
204
+ [disabledSelector]: {
205
+ backgroundColor: '#dadde3',
206
+ },
207
+ [enabledSelector]: {
208
+ backgroundColor: '#ffce31',
209
+ cursor: 'pointer',
210
+ },
211
+ [menuSelector]: {
212
+ display: 'none',
213
+ position: 'absolute',
214
+ zIndex: 301,
215
+ border: '1px solid #ddd',
216
+ borderRadius: '2px',
217
+ outline: 'none',
218
+ whiteSpace: 'nowrap',
219
+ },
220
+ [`${menuSelector}>div`]: {
221
+ padding: '1px 5px',
222
+ cursor: 'pointer',
223
+ },
224
+ [messageSelector]: {
225
+ borderStyle: 'solid',
226
+ borderWidth: '0 1px',
227
+ width: '100%',
228
+ },
229
+ [`${messageSelector} .cm-diagnosticAction`]: {
230
+ paddingTop: 0,
231
+ paddingBottom: 0,
232
+ },
233
+ '.cm-status-line': {
234
+ whiteSpace: 'nowrap',
157
235
  },
158
- };
159
- });
236
+ }),
237
+ ];
@@ -0,0 +1,8 @@
1
+ import type { Extension } from '@codemirror/state';
2
+ export declare const light: Extension,
3
+ /**
4
+ * @author 鬼影233
5
+ * @author Bhsd
6
+ * @see https://zh.moegirl.org.cn/User:%E9%AC%BC%E5%BD%B1233/nord-moeskin.css
7
+ */
8
+ nord: Extension;
package/dist/theme.js ADDED
@@ -0,0 +1,108 @@
1
+ import { EditorView } from '@codemirror/view';
2
+ import { nord as nordBase } from 'cm6-theme-nord';
3
+ export const light = /* @__PURE__ */ EditorView.theme({
4
+ '&': {
5
+ backgroundColor: '#fff',
6
+ },
7
+ '&.cm-focused .cm-matchingTag': {
8
+ backgroundColor: 'rgb(50,140,130,.32)',
9
+ },
10
+ '&.cm-focused .cm-nonmatchingTag': {
11
+ backgroundColor: 'rgb(187,85,85,.27)',
12
+ },
13
+ '.cm-tooltip-hover code': {
14
+ backgroundColor: '#e0e6eb',
15
+ },
16
+ '.cm-status-fix-menu': {
17
+ backgroundColor: '#f5f5f5',
18
+ boxShadow: '0 2px 2px 0 rgb(0,0,0,.25)',
19
+ },
20
+ '.cm-status-fix-menu>div:hover': {
21
+ backgroundColor: '#e2f2ff',
22
+ },
23
+ '.cm-status-message': {
24
+ borderColor: '#c8ccd1',
25
+ },
26
+ '.cm-content': {
27
+ '--cm-arg': '#b0c',
28
+ '--cm-attr': '#179b1c',
29
+ '--cm-comment': '#7b8c8f',
30
+ '--cm-convert': '#b68',
31
+ '--cm-entity': '#00a1a1',
32
+ '--cm-error': '#d73333',
33
+ '--cm-func': '#a11',
34
+ '--cm-hr': '#0076dd',
35
+ '--cm-hr-bg': 'rgb(0,0,0,.07)',
36
+ '--cm-link': '#000aaa',
37
+ '--cm-sect': '#006fe6',
38
+ '--cm-sp': 'rgb(134,206,255,.3)',
39
+ '--cm-table': '#d08',
40
+ '--cm-table-attr': '#f500d4',
41
+ '--cm-tag': '#14866d',
42
+ '--cm-tpl': '#80c',
43
+ '--cm-var': '#ad9300',
44
+ '--cm-var-name': '#ac6600',
45
+ },
46
+ }),
47
+ /**
48
+ * @author 鬼影233
49
+ * @author Bhsd
50
+ * @see https://zh.moegirl.org.cn/User:%E9%AC%BC%E5%BD%B1233/nord-moeskin.css
51
+ */
52
+ nord = [
53
+ nordBase,
54
+ /* @__PURE__ */ EditorView.theme({
55
+ 'div.cm-activeLine': {
56
+ backgroundColor: 'rgb(76,86,106,.27)',
57
+ },
58
+ '&.cm-focused .cm-matchingTag': {
59
+ backgroundColor: '#eceff4',
60
+ color: '#434c5e',
61
+ },
62
+ '&.cm-focused .cm-nonmatchingTag': {
63
+ backgroundColor: 'rgb(235,203,139,.32)',
64
+ },
65
+ ['&.cm-focused>.cm-scroller>.cm-selectionLayer div.cm-selectionBackground,'
66
+ + '.cm-tooltip-hover code, .cm-status-fix-menu>div:hover, .cm-diagnosticAction, div.cm-tooltip-fold']: {
67
+ backgroundColor: '#4c566a',
68
+ },
69
+ 'div.cm-panels': {
70
+ color: '#d8dee9',
71
+ },
72
+ '.cm-status-fix-menu': {
73
+ backgroundColor: '#252a33',
74
+ },
75
+ '.cm-status-message': {
76
+ borderColor: '#000',
77
+ },
78
+ '&.cm-focused .cm-searchMatch.cm-searchMatch-selected': {
79
+ color: '#b48ead',
80
+ },
81
+ 'div.cm-tooltip-autocomplete ul li[aria-selected]': {
82
+ color: 'inherit',
83
+ },
84
+ 'div.cm-gutters': {
85
+ color: '#5e81ac',
86
+ },
87
+ '.cm-content': {
88
+ '--cm-arg': '#9f78a5',
89
+ '--cm-attr': '#97b757',
90
+ '--cm-comment': '#4c566a',
91
+ '--cm-convert': '#b68',
92
+ '--cm-entity': '#00a1a1',
93
+ '--cm-error': '#bf616a',
94
+ '--cm-func': '#bf616a',
95
+ '--cm-hr': '#5e81ac',
96
+ '--cm-hr-bg': '#3b4252',
97
+ '--cm-link': '#5e81ac',
98
+ '--cm-sect': '#81a1c1',
99
+ '--cm-sp': '#88c0d0',
100
+ '--cm-table': '#b48ead',
101
+ '--cm-table-attr': '#9f78a5',
102
+ '--cm-tag': '#a3be8c',
103
+ '--cm-tpl': '#9f78a5',
104
+ '--cm-var': '#d08770',
105
+ '--cm-var-name': '#d08770',
106
+ },
107
+ }),
108
+ ];