@abp/codemirror 10.4.1 → 10.5.0-rc.1

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.
@@ -1,8 +1,6 @@
1
1
  module.exports = {
2
2
  mappings: {
3
- "@node_modules/codemirror/lib/*.*": "@libs/codemirror/",
4
- "@node_modules/codemirror/mode/**/*.*": "@libs/codemirror/mode/",
5
- "@node_modules/codemirror/theme/**/*.*": "@libs/codemirror/theme/",
6
- "@node_modules/codemirror/addon/**/*.*": "@libs/codemirror/addon/"
3
+ "@node_modules/@abp/codemirror/src/*.*": "@libs/codemirror/",
4
+ "@node_modules/@abp/codemirror/src/mode/**/*.*": "@libs/codemirror/mode/"
7
5
  }
8
6
  }
package/package.json CHANGED
@@ -1,12 +1,22 @@
1
1
  {
2
- "version": "10.4.1",
2
+ "version": "10.5.0-rc.1",
3
3
  "name": "@abp/codemirror",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
+ "scripts": {
8
+ "build": "node ./scripts/build.js"
9
+ },
7
10
  "dependencies": {
8
- "@abp/core": "~10.4.1",
9
- "codemirror": "^5.65.1"
11
+ "@abp/core": "~10.5.0-rc.1",
12
+ "@codemirror/lang-css": "^6.0.0",
13
+ "@codemirror/lang-javascript": "^6.0.0",
14
+ "@codemirror/state": "^6.0.0",
15
+ "@codemirror/view": "^6.0.0",
16
+ "codemirror": "^6.0.2"
17
+ },
18
+ "devDependencies": {
19
+ "esbuild": "^0.25.0"
10
20
  },
11
21
  "gitHead": "bb4ea17d5996f01889134c138d00b6c8f858a431",
12
22
  "homepage": "https://abp.io",
@@ -0,0 +1,21 @@
1
+ const { build } = require('esbuild');
2
+ const path = require('path');
3
+
4
+ async function run() {
5
+ await build({
6
+ entryPoints: [path.join(__dirname, 'entry.js')],
7
+ outfile: path.join(__dirname, '..', 'src', 'codemirror.js'),
8
+ bundle: true,
9
+ format: 'iife',
10
+ platform: 'browser',
11
+ target: ['es2019'],
12
+ sourcemap: false,
13
+ minify: false,
14
+ legalComments: 'eof'
15
+ });
16
+ }
17
+
18
+ run().catch(error => {
19
+ console.error(error);
20
+ process.exit(1);
21
+ });
@@ -0,0 +1,146 @@
1
+ import { EditorState } from '@codemirror/state';
2
+ import { EditorView } from '@codemirror/view';
3
+ import { basicSetup, minimalSetup } from 'codemirror';
4
+ import { css } from '@codemirror/lang-css';
5
+ import { javascript } from '@codemirror/lang-javascript';
6
+
7
+ const modeFactories = {
8
+ css: css,
9
+ javascript: javascript,
10
+ js: javascript
11
+ };
12
+
13
+ function getModeExtension(mode) {
14
+ if (!mode) {
15
+ return null;
16
+ }
17
+
18
+ const modeName = typeof mode === 'string'
19
+ ? mode
20
+ : (mode.name || mode.mode || mode.helperType || '');
21
+ const factory = modeFactories[modeName.toLowerCase()];
22
+
23
+ return factory ? factory() : null;
24
+ }
25
+
26
+ function normalizeWrapperClasses(textarea) {
27
+ return (textarea.className || '')
28
+ .split(/\s+/)
29
+ .filter(Boolean)
30
+ .filter(name => name !== 'form-control' && name !== 'valid' && name !== 'input-validation-error')
31
+ .join(' ');
32
+ }
33
+
34
+ function syncTextarea(textarea, view) {
35
+ textarea.value = view.state.doc.toString();
36
+ }
37
+
38
+ function createWrapper(textarea) {
39
+ const wrapper = document.createElement('div');
40
+ const extraClasses = normalizeWrapperClasses(textarea);
41
+ const style = window.getComputedStyle(textarea);
42
+
43
+ wrapper.className = extraClasses
44
+ ? 'abp-codemirror ' + extraClasses
45
+ : 'abp-codemirror';
46
+ if (textarea.id) {
47
+ wrapper.id = textarea.id + '__codemirror';
48
+ }
49
+
50
+ wrapper.style.width = '100%';
51
+
52
+ if (style.height && style.height !== 'auto' && style.height !== '0px') {
53
+ wrapper.style.height = style.height;
54
+ } else {
55
+ wrapper.style.minHeight = '12rem';
56
+ }
57
+
58
+ return wrapper;
59
+ }
60
+
61
+ function getEditorSetup(options) {
62
+ // CodeMirror 5 default: line numbers off unless lineNumbers === true
63
+ return options.lineNumbers === true ? basicSetup : minimalSetup;
64
+ }
65
+
66
+ function createState(textarea, options) {
67
+ const extensions = [
68
+ getEditorSetup(options),
69
+ EditorView.updateListener.of(update => {
70
+ if (update.docChanged) {
71
+ syncTextarea(textarea, update.view);
72
+ }
73
+ })
74
+ ];
75
+
76
+ const modeExtension = getModeExtension(options.mode);
77
+
78
+ if (modeExtension) {
79
+ extensions.push(modeExtension);
80
+ }
81
+
82
+ if (options.readOnly) {
83
+ extensions.push(EditorState.readOnly.of(true));
84
+ }
85
+
86
+ return EditorState.create({
87
+ doc: textarea.value || '',
88
+ extensions
89
+ });
90
+ }
91
+
92
+ function createCompatibilityEditor(textarea, options) {
93
+ const wrapper = createWrapper(textarea);
94
+
95
+ textarea.parentNode.insertBefore(wrapper, textarea.nextSibling);
96
+ textarea.style.display = 'none';
97
+ textarea.setAttribute('aria-hidden', 'true');
98
+
99
+ const view = new EditorView({
100
+ state: createState(textarea, options || {}),
101
+ parent: wrapper
102
+ });
103
+
104
+ const save = function () {
105
+ syncTextarea(textarea, view);
106
+ };
107
+
108
+ if (textarea.form) {
109
+ textarea.form.addEventListener('submit', save);
110
+ }
111
+
112
+ return {
113
+ getValue: function () {
114
+ return view.state.doc.toString();
115
+ },
116
+ setValue: function (value) {
117
+ view.dispatch({
118
+ changes: {
119
+ from: 0,
120
+ to: view.state.doc.length,
121
+ insert: value || ''
122
+ }
123
+ });
124
+
125
+ save();
126
+ },
127
+ refresh: function () {
128
+ if (typeof view.requestMeasure === 'function') {
129
+ view.requestMeasure();
130
+ }
131
+ },
132
+ focus: function () {
133
+ view.focus();
134
+ },
135
+ save: save,
136
+ getWrapperElement: function () {
137
+ return wrapper;
138
+ }
139
+ };
140
+ }
141
+
142
+ window.CodeMirror = window.CodeMirror || {};
143
+ window.CodeMirror.loadedModes = window.CodeMirror.loadedModes || {};
144
+ window.CodeMirror.fromTextArea = function (textarea, options) {
145
+ return createCompatibilityEditor(textarea, options || {});
146
+ };
@@ -0,0 +1,31 @@
1
+ .abp-codemirror {
2
+ border: 1px solid var(--bs-border-color, #dee2e6);
3
+ border-radius: var(--bs-border-radius, 0.375rem);
4
+ background: var(--bs-body-bg, #ffffff);
5
+ overflow: hidden;
6
+ }
7
+
8
+ .abp-codemirror .cm-editor {
9
+ height: 100%;
10
+ }
11
+
12
+ .abp-codemirror .cm-scroller {
13
+ min-height: 100%;
14
+ height: 100%;
15
+ overflow: auto;
16
+ font-family: var(--bs-font-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace);
17
+ }
18
+
19
+ .abp-codemirror .cm-content,
20
+ .abp-codemirror .cm-gutter {
21
+ min-height: 100%;
22
+ }
23
+
24
+ .abp-codemirror .cm-focused {
25
+ outline: none;
26
+ }
27
+
28
+ .abp-codemirror:focus-within {
29
+ border-color: var(--bs-focus-ring-color, #86b7fe);
30
+ box-shadow: var(--bs-focus-ring-x, 0) var(--bs-focus-ring-y, 0) var(--bs-focus-ring-blur, 0) var(--bs-focus-ring-width, 0.25rem) var(--bs-focus-ring-color, rgba(13, 110, 253, 0.25));
31
+ }