@operato/app 1.5.49 → 1.5.50

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,3 +1,3 @@
1
1
  module.exports = {
2
- stories: ['../dist/stories/**/*.stories.{js,md,mdx}'],
3
- };
2
+ stories: ['../dist/stories/**/*.stories.{js,md,mdx}']
3
+ }
package/CHANGELOG.md CHANGED
@@ -3,6 +3,15 @@
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.50](https://github.com/hatiolab/operato/compare/v1.5.49...v1.5.50) (2023-12-07)
7
+
8
+
9
+ ### :bug: Bug Fix
10
+
11
+ * codemirror v6 ([4332ac2](https://github.com/hatiolab/operato/commit/4332ac2fc74ae08bcb3d583a13f5c2469f9a9fcd))
12
+
13
+
14
+
6
15
  ### [1.5.49](https://github.com/hatiolab/operato/compare/v1.5.48...v1.5.49) (2023-12-04)
7
16
 
8
17
  **Note:** Version bump only for package @operato/app
@@ -1,15 +1,9 @@
1
1
  /**
2
2
  * @license Copyright © HatioLab Inc. All rights reserved.
3
3
  */
4
- import 'codemirror/addon/display/fullscreen';
5
- import 'codemirror/addon/display/autorefresh';
6
- import 'codemirror/addon/hint/show-hint';
7
- import 'codemirror/addon/lint/lint';
8
- import 'codemirror-graphql/hint';
9
- import 'codemirror-graphql/lint';
10
- import 'codemirror-graphql/mode';
11
- import CodeMirror from 'codemirror';
12
- import { LitElement, PropertyValues } from 'lit';
4
+ import { PropertyValues } from 'lit';
5
+ import { EditorView } from '@codemirror/view';
6
+ import { OxFormField } from '@operato/input';
13
7
  /**
14
8
  WEB Component for code-mirror graphql editor.
15
9
 
@@ -18,7 +12,7 @@ import { LitElement, PropertyValues } from 'lit';
18
12
  <ox-input-graphql value=${text} link=${link}>
19
13
  </ox-input-graphql>
20
14
  */
21
- export default class OxInputGraphql extends LitElement {
15
+ export default class OxInputGraphql extends OxFormField {
22
16
  static styles: import("lit").CSSResult[];
23
17
  /**
24
18
  * `value`는 에디터에서 작성중인 contents이다.
@@ -32,5 +26,5 @@ export default class OxInputGraphql extends LitElement {
32
26
  updated(changes: PropertyValues<this>): Promise<void>;
33
27
  render(): import("lit").TemplateResult<1>;
34
28
  getSchema(): Promise<import("graphql").GraphQLSchema>;
35
- getEditor(): Promise<CodeMirror.EditorFromTextArea | undefined>;
29
+ getEditor(): Promise<EditorView>;
36
30
  }
@@ -2,25 +2,20 @@
2
2
  * @license Copyright © HatioLab Inc. All rights reserved.
3
3
  */
4
4
  import { __decorate } from "tslib";
5
- import 'codemirror/addon/display/fullscreen';
6
- import 'codemirror/addon/display/autorefresh';
7
- import 'codemirror/addon/hint/show-hint';
8
- import 'codemirror/addon/lint/lint';
9
- import 'codemirror-graphql/hint';
10
- import 'codemirror-graphql/lint';
11
- import 'codemirror-graphql/mode';
12
- import FullScreenStyle from '!!text-loader!codemirror/addon/display/fullscreen.css';
13
- import ShowHintStyle from '!!text-loader!codemirror/addon/hint/show-hint.css';
14
- import LintStyle from '!!text-loader!codemirror/addon/lint/lint.css';
15
- import CodeMirrorStyle from '!!text-loader!codemirror/lib/codemirror.css';
16
- import NightThemeStyle from '!!text-loader!codemirror/theme/night.css';
17
- import CodeMirror from 'codemirror';
18
5
  import { fetch } from 'cross-fetch';
19
6
  import { print } from 'graphql';
20
- import { css, html, LitElement, unsafeCSS } from 'lit';
7
+ import { css, html } from 'lit';
21
8
  import { customElement, property, query } from 'lit/decorators.js';
9
+ import { graphql } from 'cm6-graphql';
10
+ import { history, historyKeymap, indentWithTab } from '@codemirror/commands';
11
+ import { autocompletion, closeBrackets } from '@codemirror/autocomplete';
12
+ import { bracketMatching, syntaxHighlighting } from '@codemirror/language';
13
+ import { oneDarkHighlightStyle, oneDark } from '@codemirror/theme-one-dark';
14
+ import { EditorView, highlightActiveLine, keymap } from '@codemirror/view';
22
15
  import { introspectSchema, wrapSchema } from '@graphql-tools/wrap';
23
16
  import { GRAPHQL_URI } from '@operato/graphql';
17
+ import { OxFormField } from '@operato/input';
18
+ import { togglefullscreen } from '@operato/utils';
24
19
  /**
25
20
  WEB Component for code-mirror graphql editor.
26
21
 
@@ -29,20 +24,69 @@ import { GRAPHQL_URI } from '@operato/graphql';
29
24
  <ox-input-graphql value=${text} link=${link}>
30
25
  </ox-input-graphql>
31
26
  */
32
- let OxInputGraphql = class OxInputGraphql extends LitElement {
27
+ let OxInputGraphql = class OxInputGraphql extends OxFormField {
33
28
  constructor() {
34
29
  super(...arguments);
35
30
  this._self_changing = false;
36
31
  this._changed = false;
32
+ // async getEditor() {
33
+ // if (!this._editor) {
34
+ // try {
35
+ // var schema = await this.getSchema()
36
+ // } catch (err) {
37
+ // console.error(err)
38
+ // }
39
+ // if (this.textarea) {
40
+ // this._editor = CodeMirror.fromTextArea(this.textarea, {
41
+ // value: this.value,
42
+ // mode: 'graphql',
43
+ // lint: {
44
+ // //@ts-ignore
45
+ // schema
46
+ // },
47
+ // hintOptions: {
48
+ // //@ts-ignore
49
+ // schema
50
+ // },
51
+ // tabSize: 2,
52
+ // lineNumbers: false,
53
+ // showCursorWhenSelecting: true,
54
+ // theme: 'night',
55
+ // extraKeys: {
56
+ // F11: function (cm) {
57
+ // cm.setOption('fullScreen', !cm.getOption('fullScreen'))
58
+ // },
59
+ // Esc: function (cm) {
60
+ // cm.setOption('fullScreen', !cm.getOption('fullScreen'))
61
+ // }
62
+ // },
63
+ // autoRefresh: {
64
+ // delay: 500
65
+ // }
66
+ // })
67
+ // this._editor.on('blur', (editor: CodeMirror.Editor, e: FocusEvent) => {
68
+ // if (!this._changed) return
69
+ // this.value = editor.getValue()
70
+ // this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
71
+ // })
72
+ // this._editor.on('change', async (editor: CodeMirror.Editor, changeObj: CodeMirror.EditorChange) => {
73
+ // this._self_changing = true
74
+ // this._changed = true
75
+ // await this.requestUpdate()
76
+ // this._self_changing = false
77
+ // })
78
+ // }
79
+ // }
80
+ // return this._editor
81
+ // }
37
82
  }
38
83
  async updated(changes) {
39
- if ((!this._editor || changes.has('value') || changes.has('link')) && !this._self_changing) {
40
- if (changes.has('link')) {
41
- this._editor = undefined;
42
- }
43
- ;
44
- (await this.getEditor()).setValue(this.value === undefined ? '' : String(this.value));
45
- // ;(await this.getEditor()).refresh()
84
+ const editor = await this.getEditor();
85
+ if (changes.has('value') && editor && !this._self_changing) {
86
+ const to = editor.state.doc.toString().length;
87
+ editor.dispatch({
88
+ changes: { from: 0, to, insert: this.value === undefined ? '' : String(this.value) }
89
+ });
46
90
  }
47
91
  }
48
92
  render() {
@@ -68,80 +112,71 @@ let OxInputGraphql = class OxInputGraphql extends LitElement {
68
112
  }
69
113
  async getEditor() {
70
114
  if (!this._editor) {
115
+ var schema;
71
116
  try {
72
- var schema = await this.getSchema();
117
+ schema = await this.getSchema();
73
118
  }
74
119
  catch (err) {
75
120
  console.error(err);
76
121
  }
77
- if (this.textarea) {
78
- this._editor = CodeMirror.fromTextArea(this.textarea, {
79
- value: this.value,
80
- mode: 'graphql',
81
- lint: {
82
- //@ts-ignore
83
- schema
84
- },
85
- hintOptions: {
86
- //@ts-ignore
87
- schema
88
- },
89
- tabSize: 2,
90
- lineNumbers: false,
91
- showCursorWhenSelecting: true,
92
- theme: 'night',
93
- extraKeys: {
94
- F11: function (cm) {
95
- cm.setOption('fullScreen', !cm.getOption('fullScreen'));
122
+ this._editor = new EditorView({
123
+ doc: this.value,
124
+ extensions: [
125
+ bracketMatching(),
126
+ closeBrackets(),
127
+ history(),
128
+ autocompletion(),
129
+ oneDark,
130
+ syntaxHighlighting(oneDarkHighlightStyle),
131
+ graphql(schema, {
132
+ onShowInDocs(field, type, parentType) {
133
+ alert(`Showing in docs.: Field: ${field}, Type: ${type}, ParentType: ${parentType}`);
96
134
  },
97
- Esc: function (cm) {
98
- cm.setOption('fullScreen', !cm.getOption('fullScreen'));
135
+ onFillAllFields(view, schema, _query, cursor, token) {
136
+ alert(`Filling all fields. Token: ${token}`);
99
137
  }
100
- },
101
- autoRefresh: {
102
- delay: 500
103
- }
104
- });
105
- this._editor.on('blur', (editor, e) => {
106
- if (!this._changed)
107
- return;
108
- this.value = editor.getValue();
109
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }));
110
- });
111
- this._editor.on('change', async (editor, changeObj) => {
112
- this._self_changing = true;
113
- this._changed = true;
114
- await this.requestUpdate();
115
- this._self_changing = false;
116
- });
117
- }
138
+ }),
139
+ highlightActiveLine(),
140
+ history(),
141
+ keymap.of([
142
+ ...historyKeymap,
143
+ indentWithTab,
144
+ {
145
+ key: 'Escape',
146
+ run: (view) => {
147
+ togglefullscreen(this);
148
+ return true;
149
+ }
150
+ }
151
+ ]),
152
+ EditorView.updateListener.of(v => {
153
+ if (v.docChanged) {
154
+ this._self_changing = true;
155
+ this.value = v.state.doc.toString();
156
+ this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }));
157
+ requestAnimationFrame(() => {
158
+ this._self_changing = false;
159
+ });
160
+ }
161
+ })
162
+ ],
163
+ parent: this.renderRoot
164
+ });
118
165
  }
119
166
  return this._editor;
120
167
  }
121
168
  };
122
169
  OxInputGraphql.styles = [
123
- css `
124
- ${unsafeCSS(CodeMirrorStyle)}
125
- ${unsafeCSS(FullScreenStyle)}
126
- ${unsafeCSS(NightThemeStyle)}
127
- ${unsafeCSS(LintStyle)}
128
- ${unsafeCSS(ShowHintStyle)}
129
- `,
130
170
  css `
131
171
  :host {
132
- display: block;
172
+ display: flex;
173
+ flex-direction: column;
133
174
  position: relative;
175
+ background: white;
134
176
  }
135
177
 
136
- textarea {
137
- display: block;
138
- height: 100%;
139
- width: 100%;
140
- resize: none;
141
- font-size: 16px;
142
- line-height: 20px;
143
- border: 0px;
144
- padding: 0px;
178
+ .cm-editor {
179
+ flex: 1;
145
180
  }
146
181
  `
147
182
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"ox-input-graphql.js","sourceRoot":"","s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AE,KAAK,EAAE,MAAyB,EAAE,SAAkC,EAAE,EAAE;oBAChG,IAAI,CAAC,cAAc,GAAG,IAAI,CAAA;oBAE1B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;oBAEpB,MAAM,IAAI,CAAC,aAAa,EAAE,CAAA;oBAE1B,IAAI,CAAC,cAAc,GAAG,KAAK,CAAA;gBAC7B,CAAC,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAA;IACrB,CAAC;;AAnIM,qBAAM,GAAG;IACd,GAAG,CAAA;QACC,SAAS,CAAC,eAAe,CAAC;QAC1B,SAAS,CAAC,eAAe,CAAC;WACvB,SAAS,CAAC,eAAe,CAAC;WAC1B,SAAS,CAAC,SAAS,CAAC;WACpB,SAAS,CAAC,aAAa,CAAC;KAC9B;IACD,GAAG,CAAA;;;;;;;;;;;;;;;;KAgBF;CACF,AAzBY,CAyBZ;AAK2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;6CAAe;AACd;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;4CAAc;AAEtB;IAAlB,KAAK,CAAC,UAAU,CAAC;gDAA+B;AAlC9B,cAAc;IADlC,aAAa,CAAC,kBAAkB,CAAC;GACb,cAAc,CAqIlC;eArIoB,cAAc","sourcesContent":["/**\n * @license Copyright © HatioLab Inc. All rights reserved.\n */\n\nimport 'codemirror/addon/display/fullscreen'\nimport 'codemirror/addon/display/autorefresh'\nimport 'codemirror/addon/hint/show-hint'\nimport 'codemirror/addon/lint/lint'\nimport 'codemirror-graphql/hint'\nimport 'codemirror-graphql/lint'\nimport 'codemirror-graphql/mode'\n\nimport FullScreenStyle from '!!text-loader!codemirror/addon/display/fullscreen.css'\nimport ShowHintStyle from '!!text-loader!codemirror/addon/hint/show-hint.css'\nimport LintStyle from '!!text-loader!codemirror/addon/lint/lint.css'\nimport CodeMirrorStyle from '!!text-loader!codemirror/lib/codemirror.css'\nimport NightThemeStyle from '!!text-loader!codemirror/theme/night.css'\nimport CodeMirror from 'codemirror'\nimport { fetch } from 'cross-fetch'\nimport { print } from 'graphql'\nimport { css, html, LitElement, PropertyValues, unsafeCSS } from 'lit'\nimport { customElement, property, query } from 'lit/decorators.js'\n\nimport { introspectSchema, wrapSchema } from '@graphql-tools/wrap'\nimport { GRAPHQL_URI } from '@operato/graphql'\n\n/**\n WEB Component for code-mirror graphql editor.\n \n Example:\n \n <ox-input-graphql value=${text} link=${link}>\n </ox-input-graphql>\n */\n@customElement('ox-input-graphql')\nexport default class OxInputGraphql extends LitElement {\n static styles = [\n css`\n ${unsafeCSS(CodeMirrorStyle)}\n ${unsafeCSS(FullScreenStyle)}\n ${unsafeCSS(NightThemeStyle)}\n ${unsafeCSS(LintStyle)}\n ${unsafeCSS(ShowHintStyle)}\n `,\n css`\n :host {\n display: block;\n position: relative;\n }\n\n textarea {\n display: block;\n height: 100%;\n width: 100%;\n resize: none;\n font-size: 16px;\n line-height: 20px;\n border: 0px;\n padding: 0px;\n }\n `\n ]\n\n /**\n * `value`는 에디터에서 작성중인 contents이다.\n */\n @property({ type: String }) value?: string\n @property({ type: String }) link?: string\n\n @query('textarea') textarea!: HTMLTextAreaElement\n\n private _self_changing: boolean = false\n private _changed: boolean = false\n private _editor?: CodeMirror.EditorFromTextArea\n\n async updated(changes: PropertyValues<this>) {\n if ((!this._editor || changes.has('value') || changes.has('link')) && !this._self_changing) {\n if (changes.has('link')) {\n this._editor = undefined\n }\n ;(await this.getEditor())!.setValue(this.value === undefined ? '' : String(this.value))\n // ;(await this.getEditor()).refresh()\n }\n }\n\n render() {\n return html` <textarea></textarea> `\n }\n\n async getSchema() {\n const executor = async ({ document, variables }: any) => {\n const query = print(document)\n const uri = this.link || GRAPHQL_URI\n\n const fetchResult = await fetch(uri, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify({ query, variables })\n })\n return fetchResult.json()\n }\n\n return await wrapSchema({\n schema: await introspectSchema(executor),\n executor\n })\n }\n\n async getEditor() {\n if (!this._editor) {\n try {\n var schema = await this.getSchema()\n } catch (err) {\n console.error(err)\n }\n\n if (this.textarea) {\n this._editor = CodeMirror.fromTextArea(this.textarea, {\n value: this.value,\n mode: 'graphql',\n lint: {\n //@ts-ignore\n schema\n },\n hintOptions: {\n //@ts-ignore\n schema\n },\n tabSize: 2,\n lineNumbers: false,\n showCursorWhenSelecting: true,\n theme: 'night',\n extraKeys: {\n F11: function (cm) {\n cm.setOption('fullScreen', !cm.getOption('fullScreen'))\n },\n Esc: function (cm) {\n cm.setOption('fullScreen', !cm.getOption('fullScreen'))\n }\n },\n autoRefresh: {\n delay: 500\n }\n })\n\n this._editor.on('blur', (editor: CodeMirror.Editor, e: FocusEvent) => {\n if (!this._changed) return\n\n this.value = editor.getValue()\n this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))\n })\n\n this._editor.on('change', async (editor: CodeMirror.Editor, changeObj: CodeMirror.EditorChange) => {\n this._self_changing = true\n\n this._changed = true\n\n await this.requestUpdate()\n\n this._self_changing = false\n })\n }\n }\n\n return this._editor\n }\n}\n"]}
1
+ {"version":3,"file":"ox-input-graphql.js","sourceRoot":"","sources":["../../../src/input/ox-input-graphql.ts"],"names":[],"mappings":"AAAA;;GAEG;;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAkB,MAAM,KAAK,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAErC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAG5E,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MA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B,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC;4BACjB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAA;4BAC1B,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAA;4BACnC,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,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;;AArHM,qBAAM,GAAG;IACd,GAAG,CAAA;;;;;;;;;;;KAWF;CACF,AAbY,CAaZ;AAK2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;6CAAe;AACd;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;4CAAc;AAEtB;IAAlB,KAAK,CAAC,UAAU,CAAC;gDAA+B;AAtB9B,cAAc;IADlC,aAAa,CAAC,kBAAkB,CAAC;GACb,cAAc,CAkLlC;eAlLoB,cAAc","sourcesContent":["/**\n * @license Copyright © HatioLab Inc. All rights reserved.\n */\n\nimport { fetch } from 'cross-fetch'\nimport { print } from 'graphql'\nimport { css, html, PropertyValues } from 'lit'\nimport { customElement, property, query } from 'lit/decorators.js'\nimport { graphql } from 'cm6-graphql'\n\nimport { history, historyKeymap, indentWithTab } from '@codemirror/commands'\nimport { javascript } from '@codemirror/lang-javascript'\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'\nimport { EditorView, highlightActiveLine, keymap } from '@codemirror/view'\n\nimport { introspectSchema, wrapSchema } from '@graphql-tools/wrap'\nimport { GRAPHQL_URI } from '@operato/graphql'\nimport { OxFormField } from '@operato/input'\nimport { togglefullscreen } from '@operato/utils'\n\n/**\n WEB Component for code-mirror graphql editor.\n \n Example:\n \n <ox-input-graphql value=${text} link=${link}>\n </ox-input-graphql>\n */\n@customElement('ox-input-graphql')\nexport default class OxInputGraphql extends OxFormField {\n static styles = [\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 }) link?: string\n\n @query('textarea') textarea!: HTMLTextAreaElement\n\n private _self_changing: boolean = false\n private _changed: boolean = false\n private _editor?: EditorView\n\n async updated(changes: PropertyValues<this>) {\n const editor = await this.getEditor()\n if (changes.has('value') && editor && !this._self_changing) {\n const to = editor.state.doc.toString().length\n editor.dispatch({\n changes: { from: 0, to, insert: this.value === undefined ? '' : String(this.value) }\n })\n }\n }\n\n render() {\n return html` <textarea></textarea> `\n }\n\n async getSchema() {\n const executor = async ({ document, variables }: any) => {\n const query = print(document)\n const uri = this.link || GRAPHQL_URI\n\n const fetchResult = await fetch(uri, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify({ query, variables })\n })\n return fetchResult.json()\n }\n\n return await wrapSchema({\n schema: await introspectSchema(executor),\n executor\n })\n }\n\n async getEditor() {\n if (!this._editor) {\n var schema\n try {\n schema = await this.getSchema()\n } catch (err) {\n console.error(err)\n }\n\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 graphql(schema, {\n onShowInDocs(field, type, parentType) {\n alert(`Showing in docs.: Field: ${field}, Type: ${type}, ParentType: ${parentType}`)\n },\n onFillAllFields(view, schema, _query, cursor, token) {\n alert(`Filling all fields. Token: ${token}`)\n }\n }),\n highlightActiveLine(),\n history(),\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 // async getEditor() {\n // if (!this._editor) {\n // try {\n // var schema = await this.getSchema()\n // } catch (err) {\n // console.error(err)\n // }\n\n // if (this.textarea) {\n // this._editor = CodeMirror.fromTextArea(this.textarea, {\n // value: this.value,\n // mode: 'graphql',\n // lint: {\n // //@ts-ignore\n // schema\n // },\n // hintOptions: {\n // //@ts-ignore\n // schema\n // },\n // tabSize: 2,\n // lineNumbers: false,\n // showCursorWhenSelecting: true,\n // theme: 'night',\n // extraKeys: {\n // F11: function (cm) {\n // cm.setOption('fullScreen', !cm.getOption('fullScreen'))\n // },\n // Esc: function (cm) {\n // cm.setOption('fullScreen', !cm.getOption('fullScreen'))\n // }\n // },\n // autoRefresh: {\n // delay: 500\n // }\n // })\n\n // this._editor.on('blur', (editor: CodeMirror.Editor, e: FocusEvent) => {\n // if (!this._changed) return\n\n // this.value = editor.getValue()\n // this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))\n // })\n\n // this._editor.on('change', async (editor: CodeMirror.Editor, changeObj: CodeMirror.EditorChange) => {\n // this._self_changing = true\n\n // this._changed = true\n\n // await this.requestUpdate()\n\n // this._self_changing = false\n // })\n // }\n // }\n\n // return this._editor\n // }\n}\n"]}
@@ -0,0 +1,25 @@
1
+ import '../src/input/ox-input-graphql.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,44 @@
1
+ import '../src/input/ox-input-graphql.js';
2
+ import { html } from 'lit';
3
+ export default {
4
+ title: 'ox-input-graphql',
5
+ component: 'ox-input-graphql',
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
+ </style>
18
+
19
+ <ox-input-graphql
20
+ @change=${(e) => {
21
+ console.log(e.target.value);
22
+ }}
23
+ name=${name}
24
+ .value=${value}
25
+ >
26
+ </ox-input-graphql>
27
+ `;
28
+ export const Regular = Template.bind({});
29
+ Regular.args = {
30
+ name: 'code',
31
+ value: `
32
+ query privileges {
33
+ privileges {
34
+ items {
35
+ privilege
36
+ category
37
+ description
38
+ }
39
+ total
40
+ }
41
+ }
42
+ `
43
+ };
44
+ //# sourceMappingURL=ox-input-graphql.stories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ox-input-graphql.stories.js","sourceRoot":"","sources":["../../stories/ox-input-graphql.stories.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAA;AAEzC,OAAO,EAAE,IAAI,EAAkB,MAAM,KAAK,CAAA;AAE1C,eAAe;IACb,KAAK,EAAE,kBAAkB;IACzB,SAAS,EAAE,kBAAkB;IAC7B,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;;;;;;;;;cASrE,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;;;;;;;;;;;CAWR;CACA,CAAA","sourcesContent":["import '../src/input/ox-input-graphql.js'\n\nimport { html, TemplateResult } from 'lit'\n\nexport default {\n title: 'ox-input-graphql',\n component: 'ox-input-graphql',\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 </style>\n\n <ox-input-graphql\n @change=${(e: Event) => {\n console.log((e.target as HTMLInputElement).value)\n }}\n name=${name}\n .value=${value}\n >\n </ox-input-graphql>\n`\n\nexport const Regular = Template.bind({})\nRegular.args = {\n name: 'code',\n value: `\nquery privileges {\n privileges {\n items {\n privilege\n category\n description\n }\n total\n }\n}\n`\n}\n"]}