@operato/input 1.5.49 → 1.5.51
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/CHANGELOG.md +18 -0
- package/dist/src/ox-input-code.d.ts +3 -9
- package/dist/src/ox-input-code.js +43 -101
- package/dist/src/ox-input-code.js.map +1 -1
- package/dist/src/ox-input-graphql.d.ts +29 -0
- package/dist/src/ox-input-graphql.js +108 -0
- package/dist/src/ox-input-graphql.js.map +1 -0
- package/dist/stories/ox-input-code.stories.d.ts +25 -0
- package/dist/stories/ox-input-code.stories.js +36 -0
- package/dist/stories/ox-input-code.stories.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -3
- package/src/ox-input-code.ts +47 -109
- package/src/ox-input-graphql.ts +99 -0
- package/stories/{ox-input-code.stories.ts_ → ox-input-code.stories.ts} +7 -8
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,24 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
+
### [1.5.51](https://github.com/hatiolab/operato/compare/v1.5.50...v1.5.51) (2023-12-07)
|
7
|
+
|
8
|
+
|
9
|
+
### :bug: Bug Fix
|
10
|
+
|
11
|
+
* ox-input-code, ox-input-graphql ([5cf8a78](https://github.com/hatiolab/operato/commit/5cf8a782a27d3980aa55c428273e491b17dba73b))
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
### [1.5.50](https://github.com/hatiolab/operato/compare/v1.5.49...v1.5.50) (2023-12-07)
|
16
|
+
|
17
|
+
|
18
|
+
### :bug: Bug Fix
|
19
|
+
|
20
|
+
* codemirror v6 ([4332ac2](https://github.com/hatiolab/operato/commit/4332ac2fc74ae08bcb3d583a13f5c2469f9a9fcd))
|
21
|
+
|
22
|
+
|
23
|
+
|
6
24
|
### [1.5.49](https://github.com/hatiolab/operato/compare/v1.5.48...v1.5.49) (2023-12-04)
|
7
25
|
|
8
26
|
|
@@ -1,12 +1,8 @@
|
|
1
1
|
/**
|
2
2
|
* @license Copyright © HatioLab Inc. All rights reserved.
|
3
3
|
*/
|
4
|
-
import 'codemirror/mode/javascript/javascript';
|
5
|
-
import 'codemirror/mode/python/python';
|
6
|
-
import 'codemirror/addon/display/fullscreen';
|
7
|
-
import 'codemirror/addon/display/autorefresh';
|
8
|
-
import CodeMirror from 'codemirror';
|
9
4
|
import { PropertyValues } from 'lit';
|
5
|
+
import { EditorView } from '@codemirror/view';
|
10
6
|
import { OxFormField } from './ox-form-field';
|
11
7
|
/**
|
12
8
|
WEB Component for code-mirror code editor.
|
@@ -26,9 +22,7 @@ export declare class OxInputCode extends OxFormField {
|
|
26
22
|
tabSize: number;
|
27
23
|
tabAsSpace: boolean;
|
28
24
|
private _self_changing;
|
29
|
-
private _editor
|
30
|
-
private _changed;
|
25
|
+
private _editor?;
|
31
26
|
updated(changes: PropertyValues<this>): void;
|
32
|
-
|
33
|
-
get editor(): CodeMirror.EditorFromTextArea | null | undefined;
|
27
|
+
get editor(): EditorView;
|
34
28
|
}
|
@@ -2,16 +2,14 @@
|
|
2
2
|
* @license Copyright © HatioLab Inc. All rights reserved.
|
3
3
|
*/
|
4
4
|
import { __decorate } from "tslib";
|
5
|
-
import '
|
6
|
-
import 'codemirror/mode/python/python';
|
7
|
-
import 'codemirror/addon/display/fullscreen';
|
8
|
-
import 'codemirror/addon/display/autorefresh';
|
9
|
-
import FullScreenStyle from '!!text-loader!codemirror/addon/display/fullscreen.css';
|
10
|
-
import CodeMirrorStyle from '!!text-loader!codemirror/lib/codemirror.css';
|
11
|
-
import NightThemeStyle from '!!text-loader!codemirror/theme/night.css';
|
12
|
-
import CodeMirror from 'codemirror';
|
13
|
-
import { css, html, unsafeCSS } from 'lit';
|
5
|
+
import { css } from 'lit';
|
14
6
|
import { customElement, property } from 'lit/decorators.js';
|
7
|
+
import { history, historyKeymap, indentWithTab } from '@codemirror/commands';
|
8
|
+
import { EditorView, highlightActiveLine, keymap } from '@codemirror/view';
|
9
|
+
import { autocompletion, closeBrackets } from '@codemirror/autocomplete';
|
10
|
+
import { bracketMatching, syntaxHighlighting } from '@codemirror/language';
|
11
|
+
import { oneDarkHighlightStyle, oneDark } from '@codemirror/theme-one-dark';
|
12
|
+
import { javascript } from '@codemirror/lang-javascript';
|
15
13
|
import { ScrollbarStyles } from '@operato/styles';
|
16
14
|
import { togglefullscreen } from '@operato/utils';
|
17
15
|
import { OxFormField } from './ox-form-field';
|
@@ -33,119 +31,63 @@ let OxInputCode = class OxInputCode extends OxFormField {
|
|
33
31
|
this.tabSize = 2;
|
34
32
|
this.tabAsSpace = true;
|
35
33
|
this._self_changing = false;
|
36
|
-
this._editor = null;
|
37
|
-
this._changed = false;
|
38
34
|
}
|
39
35
|
static { this.styles = [
|
40
36
|
ScrollbarStyles,
|
41
37
|
css `
|
42
|
-
${unsafeCSS(CodeMirrorStyle)}
|
43
|
-
${unsafeCSS(FullScreenStyle)}
|
44
|
-
${unsafeCSS(NightThemeStyle)}
|
45
|
-
`,
|
46
|
-
css `
|
47
38
|
:host {
|
48
39
|
display: flex;
|
49
40
|
flex-direction: column;
|
50
41
|
position: relative;
|
42
|
+
background: white;
|
51
43
|
}
|
52
44
|
|
53
|
-
.
|
45
|
+
.cm-editor {
|
54
46
|
flex: 1;
|
55
47
|
}
|
56
|
-
|
57
|
-
textarea {
|
58
|
-
display: block;
|
59
|
-
height: 100%;
|
60
|
-
width: 100%;
|
61
|
-
resize: none;
|
62
|
-
font-size: 16px;
|
63
|
-
line-height: 20px;
|
64
|
-
border: 0px;
|
65
|
-
padding: 0px;
|
66
|
-
}
|
67
|
-
|
68
|
-
#fs-toggle:not(:fullscreen) {
|
69
|
-
background-color: #afa;
|
70
|
-
}
|
71
|
-
|
72
|
-
.CodeMirror-fullscreen {
|
73
|
-
position: fixed;
|
74
|
-
top: 0;
|
75
|
-
left: 0;
|
76
|
-
width: 100%;
|
77
|
-
height: 100%;
|
78
|
-
z-index: 9999;
|
79
|
-
}
|
80
48
|
`
|
81
49
|
]; }
|
82
|
-
// private lint: any
|
83
|
-
// private hintOptions: any
|
84
50
|
updated(changes) {
|
85
51
|
if (changes.has('value') && this.editor && !this._self_changing) {
|
86
|
-
this.editor
|
87
|
-
this.editor
|
52
|
+
const to = this.editor.state.doc.toString().length;
|
53
|
+
this.editor.dispatch({
|
54
|
+
changes: { from: 0, to, insert: this.value === undefined ? '' : String(this.value) }
|
55
|
+
});
|
88
56
|
}
|
89
57
|
}
|
90
|
-
render() {
|
91
|
-
return html ` <textarea></textarea> `;
|
92
|
-
}
|
93
58
|
get editor() {
|
94
59
|
if (!this._editor) {
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
},
|
121
|
-
// https://github.com/codemirror/CodeMirror/issues/988#issuecomment-37095621
|
122
|
-
Tab: tabAsSpace
|
123
|
-
? function (cm) {
|
124
|
-
cm.replaceSelection(Array(cm.getOption('tabSize')).join(' '));
|
125
|
-
}
|
126
|
-
: false
|
127
|
-
},
|
128
|
-
autoRefresh: {
|
129
|
-
delay: 500
|
130
|
-
}
|
131
|
-
});
|
132
|
-
this._editor.on('blur', e => {
|
133
|
-
if (!this._changed)
|
134
|
-
return;
|
135
|
-
this.value = e.getValue();
|
136
|
-
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }));
|
137
|
-
});
|
138
|
-
this._editor.on('change', async (e) => {
|
139
|
-
this._self_changing = true;
|
140
|
-
this._changed = true;
|
141
|
-
await this.updateComplete;
|
142
|
-
this._self_changing = false;
|
143
|
-
});
|
144
|
-
this._editor.on('keydown', async (_, e) => {
|
145
|
-
e.stopPropagation();
|
146
|
-
});
|
147
|
-
}
|
60
|
+
this._editor = new EditorView({
|
61
|
+
doc: this.value,
|
62
|
+
extensions: [
|
63
|
+
bracketMatching(),
|
64
|
+
closeBrackets(),
|
65
|
+
history(),
|
66
|
+
autocompletion(),
|
67
|
+
oneDark,
|
68
|
+
syntaxHighlighting(oneDarkHighlightStyle),
|
69
|
+
highlightActiveLine(),
|
70
|
+
javascript(),
|
71
|
+
keymap.of([...historyKeymap, indentWithTab]),
|
72
|
+
EditorView.updateListener.of(v => {
|
73
|
+
if (v.docChanged) {
|
74
|
+
this._self_changing = true;
|
75
|
+
this.value = v.state.doc.toString();
|
76
|
+
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }));
|
77
|
+
requestAnimationFrame(() => {
|
78
|
+
this._self_changing = false;
|
79
|
+
});
|
80
|
+
}
|
81
|
+
})
|
82
|
+
],
|
83
|
+
parent: this.renderRoot
|
84
|
+
});
|
148
85
|
}
|
86
|
+
this._editor.contentDOM.addEventListener('keydown', event => {
|
87
|
+
if (event.key === 'Escape') {
|
88
|
+
togglefullscreen(this._editor.contentDOM);
|
89
|
+
}
|
90
|
+
});
|
149
91
|
return this._editor;
|
150
92
|
}
|
151
93
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ox-input-code.js","sourceRoot":"","sources":["../../src/ox-input-code.ts"],"names":[],"mappings":"AAAA;;GAEG;;AAEH,OAAO,
|
1
|
+
{"version":3,"file":"ox-input-code.js","sourceRoot":"","sources":["../../src/ox-input-code.ts"],"names":[],"mappings":"AAAA;;GAEG;;AAEH,OAAO,EAAE,GAAG,EAAkB,MAAM,KAAK,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE3D,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAC5E,OAAO,EAAE,UAAU,EAAE,mBAAmB,E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,OAAQ,CAAC,UAAU,CAAC,CAAA;YAC5C,CAAC;QACH,CAAC,CAAC,CAAA;QAEF,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;;AArD2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;0CAAmB;AAClB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;yCAAc;AACU;IAAlD,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;4CAAoB;AACd;IAAvD,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC;+CAA2B;AAvBvE,WAAW;IADvB,aAAa,CAAC,eAAe,CAAC;GAClB,WAAW,CA0EvB","sourcesContent":["/**\n * @license Copyright © HatioLab Inc. All rights reserved.\n */\n\nimport { css, PropertyValues } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport { history, historyKeymap, indentWithTab } from '@codemirror/commands'\nimport { EditorView, highlightActiveLine, keymap } from '@codemirror/view'\nimport { EditorState } from '@codemirror/state'\nimport { autocompletion, closeBrackets } from '@codemirror/autocomplete'\nimport { bracketMatching, syntaxHighlighting } from '@codemirror/language'\nimport { oneDarkHighlightStyle, oneDark } from '@codemirror/theme-one-dark'\n\nimport { javascript } from '@codemirror/lang-javascript'\n\nimport { ScrollbarStyles } from '@operato/styles'\nimport { togglefullscreen } from '@operato/utils'\n\nimport { OxFormField } from './ox-form-field'\n\n/**\nWEB Component for code-mirror code editor.\n\nExample:\n\n <ox-input-code .value=${text} mode=${mode} tab-size=\"4\" tab-as-space=\"true\">\n </ox-input-code>\n*/\n@customElement('ox-input-code')\nexport class OxInputCode extends OxFormField {\n static styles = [\n ScrollbarStyles,\n css`\n :host {\n display: flex;\n flex-direction: column;\n position: relative;\n background: white;\n }\n\n .cm-editor {\n flex: 1;\n }\n `\n ]\n\n /**\n * `value`는 에디터에서 작성중인 contents이다.\n */\n @property({ type: String }) value: string = ''\n @property({ type: String }) mode?: string\n @property({ type: Number, attribute: 'tab-size' }) tabSize: number = 2\n @property({ type: Boolean, attribute: 'tab-as-space' }) tabAsSpace: boolean = true\n\n private _self_changing: boolean = false\n private _editor?: EditorView\n\n updated(changes: PropertyValues<this>) {\n if (changes.has('value') && this.editor && !this._self_changing) {\n const to = this.editor.state.doc.toString().length\n this.editor.dispatch({\n changes: { from: 0, to, insert: this.value === undefined ? '' : String(this.value) }\n })\n }\n }\n\n get editor() {\n if (!this._editor) {\n this._editor = new EditorView({\n doc: this.value,\n extensions: [\n bracketMatching(),\n closeBrackets(),\n history(),\n autocompletion(),\n oneDark,\n syntaxHighlighting(oneDarkHighlightStyle),\n highlightActiveLine(),\n javascript(),\n keymap.of([...historyKeymap, indentWithTab]),\n EditorView.updateListener.of(v => {\n if (v.docChanged) {\n this._self_changing = true\n this.value = v.state.doc.toString()\n this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))\n requestAnimationFrame(() => {\n this._self_changing = false\n })\n }\n })\n ],\n parent: this.renderRoot\n })\n }\n\n this._editor.contentDOM.addEventListener('keydown', event => {\n if (event.key === 'Escape') {\n togglefullscreen(this._editor!.contentDOM)\n }\n })\n\n return this._editor\n }\n}\n"]}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright © HatioLab Inc. All rights reserved.
|
3
|
+
*/
|
4
|
+
import { PropertyValues } from 'lit';
|
5
|
+
import { EditorView } from '@codemirror/view';
|
6
|
+
import { OxFormField } from './ox-form-field';
|
7
|
+
/**
|
8
|
+
WEB Component for code-mirror code editor.
|
9
|
+
|
10
|
+
Example:
|
11
|
+
|
12
|
+
<ox-input-code .value=${text} mode=${mode} tab-size="4" tab-as-space="true">
|
13
|
+
</ox-input-code>
|
14
|
+
*/
|
15
|
+
export declare class OxInputCode extends OxFormField {
|
16
|
+
static styles: import("lit").CSSResult[];
|
17
|
+
/**
|
18
|
+
* `value`는 에디터에서 작성중인 contents이다.
|
19
|
+
*/
|
20
|
+
value: string;
|
21
|
+
mode?: string;
|
22
|
+
tabSize: number;
|
23
|
+
tabAsSpace: boolean;
|
24
|
+
private _self_changing;
|
25
|
+
private _editor?;
|
26
|
+
private _changed;
|
27
|
+
updated(changes: PropertyValues<this>): void;
|
28
|
+
get editor(): EditorView;
|
29
|
+
}
|
@@ -0,0 +1,108 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright © HatioLab Inc. All rights reserved.
|
3
|
+
*/
|
4
|
+
import { __decorate } from "tslib";
|
5
|
+
import { css } from 'lit';
|
6
|
+
import { customElement, property } from 'lit/decorators.js';
|
7
|
+
import { history, historyKeymap, indentWithTab } from '@codemirror/commands';
|
8
|
+
import { EditorView, highlightActiveLine, keymap } from '@codemirror/view';
|
9
|
+
import { javascript } from '@codemirror/lang-javascript';
|
10
|
+
import { ScrollbarStyles } from '@operato/styles';
|
11
|
+
import { togglefullscreen } from '@operato/utils';
|
12
|
+
import { OxFormField } from './ox-form-field';
|
13
|
+
/**
|
14
|
+
WEB Component for code-mirror code editor.
|
15
|
+
|
16
|
+
Example:
|
17
|
+
|
18
|
+
<ox-input-code .value=${text} mode=${mode} tab-size="4" tab-as-space="true">
|
19
|
+
</ox-input-code>
|
20
|
+
*/
|
21
|
+
let OxInputCode = class OxInputCode extends OxFormField {
|
22
|
+
constructor() {
|
23
|
+
super(...arguments);
|
24
|
+
/**
|
25
|
+
* `value`는 에디터에서 작성중인 contents이다.
|
26
|
+
*/
|
27
|
+
this.value = '';
|
28
|
+
this.tabSize = 2;
|
29
|
+
this.tabAsSpace = true;
|
30
|
+
this._self_changing = false;
|
31
|
+
this._changed = false;
|
32
|
+
}
|
33
|
+
static { this.styles = [
|
34
|
+
ScrollbarStyles,
|
35
|
+
css `
|
36
|
+
:host {
|
37
|
+
display: flex;
|
38
|
+
flex-direction: column;
|
39
|
+
position: relative;
|
40
|
+
background: white;
|
41
|
+
}
|
42
|
+
|
43
|
+
.cm-editor {
|
44
|
+
flex: 1;
|
45
|
+
}
|
46
|
+
`
|
47
|
+
]; }
|
48
|
+
updated(changes) {
|
49
|
+
if (changes.has('value') && this.editor && !this._self_changing) {
|
50
|
+
const to = this.editor.state.doc.toString().length;
|
51
|
+
this.editor.dispatch({
|
52
|
+
changes: { from: 0, to, insert: this.value === undefined ? '' : String(this.value) }
|
53
|
+
});
|
54
|
+
}
|
55
|
+
}
|
56
|
+
get editor() {
|
57
|
+
if (!this._editor) {
|
58
|
+
this._editor = new EditorView({
|
59
|
+
doc: this.value,
|
60
|
+
extensions: [
|
61
|
+
highlightActiveLine(),
|
62
|
+
history(),
|
63
|
+
javascript(),
|
64
|
+
keymap.of([
|
65
|
+
...historyKeymap,
|
66
|
+
indentWithTab,
|
67
|
+
{
|
68
|
+
key: 'Escape',
|
69
|
+
run: (view) => {
|
70
|
+
togglefullscreen(this);
|
71
|
+
return true;
|
72
|
+
}
|
73
|
+
}
|
74
|
+
]),
|
75
|
+
EditorView.updateListener.of(v => {
|
76
|
+
if (v.docChanged) {
|
77
|
+
this._self_changing = true;
|
78
|
+
this.value = v.state.doc.toString();
|
79
|
+
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }));
|
80
|
+
requestAnimationFrame(() => {
|
81
|
+
this._self_changing = false;
|
82
|
+
});
|
83
|
+
}
|
84
|
+
})
|
85
|
+
],
|
86
|
+
parent: this.renderRoot
|
87
|
+
});
|
88
|
+
}
|
89
|
+
return this._editor;
|
90
|
+
}
|
91
|
+
};
|
92
|
+
__decorate([
|
93
|
+
property({ type: String })
|
94
|
+
], OxInputCode.prototype, "value", void 0);
|
95
|
+
__decorate([
|
96
|
+
property({ type: String })
|
97
|
+
], OxInputCode.prototype, "mode", void 0);
|
98
|
+
__decorate([
|
99
|
+
property({ type: Number, attribute: 'tab-size' })
|
100
|
+
], OxInputCode.prototype, "tabSize", void 0);
|
101
|
+
__decorate([
|
102
|
+
property({ type: Boolean, attribute: 'tab-as-space' })
|
103
|
+
], OxInputCode.prototype, "tabAsSpace", void 0);
|
104
|
+
OxInputCode = __decorate([
|
105
|
+
customElement('ox-input-code')
|
106
|
+
], OxInputCode);
|
107
|
+
export { OxInputCode };
|
108
|
+
//# sourceMappingURL=ox-input-graphql.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ox-input-graphql.js","sourceRoot":"","sources":["../../src/ox-input-graphql.ts"],"names":[],"mappings":"AAAA;;GAEG;;AAEH,OAAO,EAAE,GAAG,EAAkB,MAAM,KAAK,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE3D,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAC5E,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEjD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7C;;;;;;;EAOE;AAEK,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,WAAW;IAArC;;QAiBL;;WAEG;QACyB,UAAK,GAAW,EAAE,CAAA;QAEK,YAAO,GAAW,CAAC,CAAA;QACd,eAAU,GAAY,IAAI,CAAA;QAE1E,mBAAc,GAAY,KAAK,CAAA;QAE/B,aAAQ,GAAY,KAAK,CAAA;IA+CnC,CAAC;aAzEQ,WAAM,GAAG;QACd,eAAe;QACf,GAAG,CAAA;;;;;;;;;;;KAWF;KACF,AAdY,CAcZ;IAcD,OAAO,CAAC,OAA6B;QACnC,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,MAA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MAAM,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;4BACpG,qBAAqB,CAAC,GAAG,EAAE;gCACzB,IAAI,CAAC,cAAc,GAAG,KAAK,CAAA;4BAC7B,CAAC,CAAC,CAAA;wBACJ,CAAC;oBACH,CAAC,CAAC;iBACH;gBACD,MAAM,EAAE,IAAI,CAAC,UAAU;aACxB,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;;AArD2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;0CAAmB;AAClB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;yCAAc;AACU;IAAlD,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;4CAAoB;AACd;IAAvD,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,CAAC;+CAA2B;AAvBvE,WAAW;IADvB,aAAa,CAAC,eAAe,CAAC;GAClB,WAAW,CA0EvB","sourcesContent":["/**\n * @license Copyright © HatioLab Inc. All rights reserved.\n */\n\nimport { css, PropertyValues } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport { history, historyKeymap, indentWithTab } from '@codemirror/commands'\nimport { EditorView, highlightActiveLine, keymap } from '@codemirror/view'\nimport { javascript } from '@codemirror/lang-javascript'\nimport { ScrollbarStyles } from '@operato/styles'\nimport { togglefullscreen } from '@operato/utils'\n\nimport { OxFormField } from './ox-form-field'\n\n/**\nWEB Component for code-mirror code editor.\n\nExample:\n\n <ox-input-code .value=${text} mode=${mode} tab-size=\"4\" tab-as-space=\"true\">\n </ox-input-code>\n*/\n@customElement('ox-input-code')\nexport class OxInputCode extends OxFormField {\n static styles = [\n ScrollbarStyles,\n css`\n :host {\n display: flex;\n flex-direction: column;\n position: relative;\n background: white;\n }\n\n .cm-editor {\n flex: 1;\n }\n `\n ]\n\n /**\n * `value`는 에디터에서 작성중인 contents이다.\n */\n @property({ type: String }) value: string = ''\n @property({ type: String }) mode?: string\n @property({ type: Number, attribute: 'tab-size' }) tabSize: number = 2\n @property({ type: Boolean, attribute: 'tab-as-space' }) tabAsSpace: boolean = true\n\n private _self_changing: boolean = false\n private _editor?: EditorView\n private _changed: boolean = false\n\n updated(changes: PropertyValues<this>) {\n if (changes.has('value') && this.editor && !this._self_changing) {\n const to = this.editor.state.doc.toString().length\n this.editor.dispatch({\n changes: { from: 0, to, insert: this.value === undefined ? '' : String(this.value) }\n })\n }\n }\n\n get editor() {\n if (!this._editor) {\n this._editor = new EditorView({\n doc: this.value,\n extensions: [\n highlightActiveLine(),\n history(),\n javascript(),\n keymap.of([\n ...historyKeymap,\n indentWithTab,\n {\n key: 'Escape',\n run: (view: EditorView) => {\n togglefullscreen(this)\n return true\n }\n }\n ]),\n EditorView.updateListener.of(v => {\n if (v.docChanged) {\n this._self_changing = true\n this.value = v.state.doc.toString()\n this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))\n requestAnimationFrame(() => {\n this._self_changing = false\n })\n }\n })\n ],\n parent: this.renderRoot\n })\n }\n\n return this._editor\n }\n}\n"]}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import '../src/ox-input-code.js';
|
2
|
+
import { TemplateResult } from 'lit';
|
3
|
+
declare const _default: {
|
4
|
+
title: string;
|
5
|
+
component: string;
|
6
|
+
argTypes: {
|
7
|
+
value: {
|
8
|
+
control: string;
|
9
|
+
};
|
10
|
+
name: {
|
11
|
+
control: string;
|
12
|
+
};
|
13
|
+
};
|
14
|
+
};
|
15
|
+
export default _default;
|
16
|
+
interface Story<T> {
|
17
|
+
(args: T): TemplateResult;
|
18
|
+
args?: Partial<T>;
|
19
|
+
argTypes?: Record<string, unknown>;
|
20
|
+
}
|
21
|
+
interface ArgTypes {
|
22
|
+
name?: string;
|
23
|
+
value?: string;
|
24
|
+
}
|
25
|
+
export declare const Regular: Story<ArgTypes>;
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import '../src/ox-input-code.js';
|
2
|
+
import { html } from 'lit';
|
3
|
+
export default {
|
4
|
+
title: 'ox-input-code',
|
5
|
+
component: 'ox-input-code',
|
6
|
+
argTypes: {
|
7
|
+
value: { control: 'text' },
|
8
|
+
name: { control: 'text' }
|
9
|
+
}
|
10
|
+
};
|
11
|
+
const Template = ({ name = 'code', value = '' }) => html `
|
12
|
+
<link href="/themes/app-theme.css" rel="stylesheet" />
|
13
|
+
<link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet" />
|
14
|
+
<style>
|
15
|
+
body {
|
16
|
+
}
|
17
|
+
ox-input-code {
|
18
|
+
height: 300px;
|
19
|
+
}
|
20
|
+
</style>
|
21
|
+
|
22
|
+
<ox-input-code
|
23
|
+
@change=${(e) => {
|
24
|
+
console.log(e.target.value);
|
25
|
+
}}
|
26
|
+
name=${name}
|
27
|
+
.value=${value}
|
28
|
+
>
|
29
|
+
</ox-input-code>
|
30
|
+
`;
|
31
|
+
export const Regular = Template.bind({});
|
32
|
+
Regular.args = {
|
33
|
+
name: 'code',
|
34
|
+
value: ''
|
35
|
+
};
|
36
|
+
//# sourceMappingURL=ox-input-code.stories.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ox-input-code.stories.js","sourceRoot":"","sources":["../../stories/ox-input-code.stories.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAA;AAEhC,OAAO,EAAE,IAAI,EAAkB,MAAM,KAAK,CAAA;AAE1C,eAAe;IACb,KAAK,EAAE,eAAe;IACtB,SAAS,EAAE,eAAe;IAC1B,QAAQ,EAAE;QACR,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE;QAC1B,IAAI,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE;KAC1B;CACF,CAAA;AAaD,MAAM,QAAQ,GAAoB,CAAC,EAAE,IAAI,GAAG,MAAM,EAAE,KAAK,GAAG,EAAE,EAAY,EAAE,EAAE,CAAC,IAAI,CAAA;;;;;;;;;;;;cAYrE,CAAC,CAAQ,EAAE,EAAE;IACrB,OAAO,CAAC,GAAG,CAAE,CAAC,CAAC,MAA2B,CAAC,KAAK,CAAC,CAAA;AACnD,CAAC;WACM,IAAI;aACF,KAAK;;;CAGjB,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACxC,OAAO,CAAC,IAAI,GAAG;IACb,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,EAAE;CACV,CAAA","sourcesContent":["import '../src/ox-input-code.js'\n\nimport { html, TemplateResult } from 'lit'\n\nexport default {\n title: 'ox-input-code',\n component: 'ox-input-code',\n argTypes: {\n value: { control: 'text' },\n name: { control: 'text' }\n }\n}\n\ninterface Story<T> {\n (args: T): TemplateResult\n args?: Partial<T>\n argTypes?: Record<string, unknown>\n}\n\ninterface ArgTypes {\n name?: string\n value?: string\n}\n\nconst Template: Story<ArgTypes> = ({ name = 'code', value = '' }: ArgTypes) => html`\n <link href=\"/themes/app-theme.css\" rel=\"stylesheet\" />\n <link href=\"https://fonts.googleapis.com/css?family=Material+Icons&display=block\" rel=\"stylesheet\" />\n <style>\n body {\n }\n ox-input-code {\n height: 300px;\n }\n </style>\n\n <ox-input-code\n @change=${(e: Event) => {\n console.log((e.target as HTMLInputElement).value)\n }}\n name=${name}\n .value=${value}\n >\n </ox-input-code>\n`\n\nexport const Regular = Template.bind({})\nRegular.args = {\n name: 'code',\n value: ''\n}\n"]}
|