@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.
- package/.storybook/main.js +2 -2
- package/CHANGELOG.md +9 -0
- package/dist/src/input/ox-input-graphql.d.ts +5 -11
- package/dist/src/input/ox-input-graphql.js +114 -79
- package/dist/src/input/ox-input-graphql.js.map +1 -1
- package/dist/stories/ox-input-graphql.stories.d.ts +25 -0
- package/dist/stories/ox-input-graphql.stories.js +44 -0
- package/dist/stories/ox-input-graphql.stories.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -11
- package/src/input/ox-input-graphql.ts +127 -85
- package/stories/ox-input-graphql.stories.ts +58 -0
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@operato/app",
|
|
3
3
|
"description": "WebApplication production supporting components following open-wc recommendations",
|
|
4
4
|
"author": "heartyoh",
|
|
5
|
-
"version": "1.5.
|
|
5
|
+
"version": "1.5.50",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
7
7
|
"module": "dist/src/index.js",
|
|
8
8
|
"exports": {
|
|
@@ -112,6 +112,7 @@
|
|
|
112
112
|
"directory": "webcomponents/app"
|
|
113
113
|
},
|
|
114
114
|
"scripts": {
|
|
115
|
+
"clean": "npx rimraf dist",
|
|
115
116
|
"analyze": "cem analyze --litelement",
|
|
116
117
|
"start": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds\"",
|
|
117
118
|
"build": "tsc && npm run analyze -- --exclude dist",
|
|
@@ -120,29 +121,35 @@
|
|
|
120
121
|
"format": "eslint --ext .ts,.html . --fix --ignore-path .gitignore && prettier \"**/*.ts\" --write --ignore-path .gitignore",
|
|
121
122
|
"test": "tsc && wtr --coverage",
|
|
122
123
|
"test:watch": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wtr --watch\"",
|
|
123
|
-
"storybook": "
|
|
124
|
-
"storybook:build": "
|
|
124
|
+
"storybook": "npm run build && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds -c .storybook/server.mjs\"",
|
|
125
|
+
"storybook:build": "npm run build && build-storybook"
|
|
125
126
|
},
|
|
126
127
|
"dependencies": {
|
|
128
|
+
"@codemirror/autocomplete": "^6.11.1",
|
|
129
|
+
"@codemirror/commands": "^6.3.2",
|
|
130
|
+
"@codemirror/language": "^6.9.3",
|
|
131
|
+
"@codemirror/state": "^6.3.3",
|
|
132
|
+
"@codemirror/theme-one-dark": "^6.1.2",
|
|
133
|
+
"@codemirror/view": "^6.22.1",
|
|
127
134
|
"@graphql-tools/delegate": "^10.0.1",
|
|
128
135
|
"@graphql-tools/wrap": "^8.5.0",
|
|
129
136
|
"@material/mwc-button": "^0.27.0",
|
|
130
137
|
"@material/mwc-icon": "^0.27.0",
|
|
131
138
|
"@material/mwc-icon-button": "^0.27.0",
|
|
132
|
-
"@operato/attachment": "^1.5.
|
|
133
|
-
"@operato/data-grist": "^1.5.
|
|
134
|
-
"@operato/font": "^1.5.
|
|
139
|
+
"@operato/attachment": "^1.5.50",
|
|
140
|
+
"@operato/data-grist": "^1.5.50",
|
|
141
|
+
"@operato/font": "^1.5.50",
|
|
135
142
|
"@operato/form": "^1.5.44",
|
|
136
143
|
"@operato/graphql": "^1.4.76",
|
|
137
144
|
"@operato/i18n": "^1.5.14",
|
|
138
|
-
"@operato/input": "^1.5.
|
|
145
|
+
"@operato/input": "^1.5.50",
|
|
139
146
|
"@operato/layout": "^1.5.48",
|
|
140
|
-
"@operato/property-editor": "^1.5.
|
|
147
|
+
"@operato/property-editor": "^1.5.50",
|
|
141
148
|
"@operato/shell": "^1.5.48",
|
|
142
149
|
"@operato/styles": "^1.5.48",
|
|
143
150
|
"@operato/utils": "^1.5.44",
|
|
144
|
-
"
|
|
145
|
-
"codemirror
|
|
151
|
+
"cm6-graphql": "^0.0.12",
|
|
152
|
+
"codemirror": "^6.0.1",
|
|
146
153
|
"cronstrue": "^2.2.0",
|
|
147
154
|
"cross-fetch": "^3.1.5",
|
|
148
155
|
"graphql": "^16.5.0",
|
|
@@ -182,5 +189,5 @@
|
|
|
182
189
|
"prettier --write"
|
|
183
190
|
]
|
|
184
191
|
},
|
|
185
|
-
"gitHead": "
|
|
192
|
+
"gitHead": "4e8d7b771ecb89da1a9b599d62dc1775b253d3bb"
|
|
186
193
|
}
|
|
@@ -2,27 +2,24 @@
|
|
|
2
2
|
* @license Copyright © HatioLab Inc. All rights reserved.
|
|
3
3
|
*/
|
|
4
4
|
|
|
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
|
-
|
|
13
|
-
import FullScreenStyle from '!!text-loader!codemirror/addon/display/fullscreen.css'
|
|
14
|
-
import ShowHintStyle from '!!text-loader!codemirror/addon/hint/show-hint.css'
|
|
15
|
-
import LintStyle from '!!text-loader!codemirror/addon/lint/lint.css'
|
|
16
|
-
import CodeMirrorStyle from '!!text-loader!codemirror/lib/codemirror.css'
|
|
17
|
-
import NightThemeStyle from '!!text-loader!codemirror/theme/night.css'
|
|
18
|
-
import CodeMirror from 'codemirror'
|
|
19
5
|
import { fetch } from 'cross-fetch'
|
|
20
6
|
import { print } from 'graphql'
|
|
21
|
-
import { css, html,
|
|
7
|
+
import { css, html, PropertyValues } from 'lit'
|
|
22
8
|
import { customElement, property, query } from 'lit/decorators.js'
|
|
9
|
+
import { graphql } from 'cm6-graphql'
|
|
10
|
+
|
|
11
|
+
import { history, historyKeymap, indentWithTab } from '@codemirror/commands'
|
|
12
|
+
import { javascript } from '@codemirror/lang-javascript'
|
|
13
|
+
import { EditorState } from '@codemirror/state'
|
|
14
|
+
import { autocompletion, closeBrackets } from '@codemirror/autocomplete'
|
|
15
|
+
import { bracketMatching, syntaxHighlighting } from '@codemirror/language'
|
|
16
|
+
import { oneDarkHighlightStyle, oneDark } from '@codemirror/theme-one-dark'
|
|
17
|
+
import { EditorView, highlightActiveLine, keymap } from '@codemirror/view'
|
|
23
18
|
|
|
24
19
|
import { introspectSchema, wrapSchema } from '@graphql-tools/wrap'
|
|
25
20
|
import { GRAPHQL_URI } from '@operato/graphql'
|
|
21
|
+
import { OxFormField } from '@operato/input'
|
|
22
|
+
import { togglefullscreen } from '@operato/utils'
|
|
26
23
|
|
|
27
24
|
/**
|
|
28
25
|
WEB Component for code-mirror graphql editor.
|
|
@@ -33,30 +30,18 @@ import { GRAPHQL_URI } from '@operato/graphql'
|
|
|
33
30
|
</ox-input-graphql>
|
|
34
31
|
*/
|
|
35
32
|
@customElement('ox-input-graphql')
|
|
36
|
-
export default class OxInputGraphql extends
|
|
33
|
+
export default class OxInputGraphql extends OxFormField {
|
|
37
34
|
static styles = [
|
|
38
|
-
css`
|
|
39
|
-
${unsafeCSS(CodeMirrorStyle)}
|
|
40
|
-
${unsafeCSS(FullScreenStyle)}
|
|
41
|
-
${unsafeCSS(NightThemeStyle)}
|
|
42
|
-
${unsafeCSS(LintStyle)}
|
|
43
|
-
${unsafeCSS(ShowHintStyle)}
|
|
44
|
-
`,
|
|
45
35
|
css`
|
|
46
36
|
:host {
|
|
47
|
-
display:
|
|
37
|
+
display: flex;
|
|
38
|
+
flex-direction: column;
|
|
48
39
|
position: relative;
|
|
40
|
+
background: white;
|
|
49
41
|
}
|
|
50
42
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
height: 100%;
|
|
54
|
-
width: 100%;
|
|
55
|
-
resize: none;
|
|
56
|
-
font-size: 16px;
|
|
57
|
-
line-height: 20px;
|
|
58
|
-
border: 0px;
|
|
59
|
-
padding: 0px;
|
|
43
|
+
.cm-editor {
|
|
44
|
+
flex: 1;
|
|
60
45
|
}
|
|
61
46
|
`
|
|
62
47
|
]
|
|
@@ -71,15 +56,15 @@ export default class OxInputGraphql extends LitElement {
|
|
|
71
56
|
|
|
72
57
|
private _self_changing: boolean = false
|
|
73
58
|
private _changed: boolean = false
|
|
74
|
-
private _editor?:
|
|
59
|
+
private _editor?: EditorView
|
|
75
60
|
|
|
76
61
|
async updated(changes: PropertyValues<this>) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
62
|
+
const editor = await this.getEditor()
|
|
63
|
+
if (changes.has('value') && editor && !this._self_changing) {
|
|
64
|
+
const to = editor.state.doc.toString().length
|
|
65
|
+
editor.dispatch({
|
|
66
|
+
changes: { from: 0, to, insert: this.value === undefined ? '' : String(this.value) }
|
|
67
|
+
})
|
|
83
68
|
}
|
|
84
69
|
}
|
|
85
70
|
|
|
@@ -110,60 +95,117 @@ export default class OxInputGraphql extends LitElement {
|
|
|
110
95
|
|
|
111
96
|
async getEditor() {
|
|
112
97
|
if (!this._editor) {
|
|
98
|
+
var schema
|
|
113
99
|
try {
|
|
114
|
-
|
|
100
|
+
schema = await this.getSchema()
|
|
115
101
|
} catch (err) {
|
|
116
102
|
console.error(err)
|
|
117
103
|
}
|
|
118
104
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
tabSize: 2,
|
|
132
|
-
lineNumbers: false,
|
|
133
|
-
showCursorWhenSelecting: true,
|
|
134
|
-
theme: 'night',
|
|
135
|
-
extraKeys: {
|
|
136
|
-
F11: function (cm) {
|
|
137
|
-
cm.setOption('fullScreen', !cm.getOption('fullScreen'))
|
|
105
|
+
this._editor = new EditorView({
|
|
106
|
+
doc: this.value,
|
|
107
|
+
extensions: [
|
|
108
|
+
bracketMatching(),
|
|
109
|
+
closeBrackets(),
|
|
110
|
+
history(),
|
|
111
|
+
autocompletion(),
|
|
112
|
+
oneDark,
|
|
113
|
+
syntaxHighlighting(oneDarkHighlightStyle),
|
|
114
|
+
graphql(schema, {
|
|
115
|
+
onShowInDocs(field, type, parentType) {
|
|
116
|
+
alert(`Showing in docs.: Field: ${field}, Type: ${type}, ParentType: ${parentType}`)
|
|
138
117
|
},
|
|
139
|
-
|
|
140
|
-
|
|
118
|
+
onFillAllFields(view, schema, _query, cursor, token) {
|
|
119
|
+
alert(`Filling all fields. Token: ${token}`)
|
|
141
120
|
}
|
|
142
|
-
},
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
121
|
+
}),
|
|
122
|
+
highlightActiveLine(),
|
|
123
|
+
history(),
|
|
124
|
+
keymap.of([
|
|
125
|
+
...historyKeymap,
|
|
126
|
+
indentWithTab,
|
|
127
|
+
{
|
|
128
|
+
key: 'Escape',
|
|
129
|
+
run: (view: EditorView) => {
|
|
130
|
+
togglefullscreen(this)
|
|
131
|
+
return true
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
]),
|
|
135
|
+
EditorView.updateListener.of(v => {
|
|
136
|
+
if (v.docChanged) {
|
|
137
|
+
this._self_changing = true
|
|
138
|
+
this.value = v.state.doc.toString()
|
|
139
|
+
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
|
|
140
|
+
requestAnimationFrame(() => {
|
|
141
|
+
this._self_changing = false
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
],
|
|
146
|
+
parent: this.renderRoot
|
|
147
|
+
})
|
|
165
148
|
}
|
|
166
149
|
|
|
167
150
|
return this._editor
|
|
168
151
|
}
|
|
152
|
+
|
|
153
|
+
// async getEditor() {
|
|
154
|
+
// if (!this._editor) {
|
|
155
|
+
// try {
|
|
156
|
+
// var schema = await this.getSchema()
|
|
157
|
+
// } catch (err) {
|
|
158
|
+
// console.error(err)
|
|
159
|
+
// }
|
|
160
|
+
|
|
161
|
+
// if (this.textarea) {
|
|
162
|
+
// this._editor = CodeMirror.fromTextArea(this.textarea, {
|
|
163
|
+
// value: this.value,
|
|
164
|
+
// mode: 'graphql',
|
|
165
|
+
// lint: {
|
|
166
|
+
// //@ts-ignore
|
|
167
|
+
// schema
|
|
168
|
+
// },
|
|
169
|
+
// hintOptions: {
|
|
170
|
+
// //@ts-ignore
|
|
171
|
+
// schema
|
|
172
|
+
// },
|
|
173
|
+
// tabSize: 2,
|
|
174
|
+
// lineNumbers: false,
|
|
175
|
+
// showCursorWhenSelecting: true,
|
|
176
|
+
// theme: 'night',
|
|
177
|
+
// extraKeys: {
|
|
178
|
+
// F11: function (cm) {
|
|
179
|
+
// cm.setOption('fullScreen', !cm.getOption('fullScreen'))
|
|
180
|
+
// },
|
|
181
|
+
// Esc: function (cm) {
|
|
182
|
+
// cm.setOption('fullScreen', !cm.getOption('fullScreen'))
|
|
183
|
+
// }
|
|
184
|
+
// },
|
|
185
|
+
// autoRefresh: {
|
|
186
|
+
// delay: 500
|
|
187
|
+
// }
|
|
188
|
+
// })
|
|
189
|
+
|
|
190
|
+
// this._editor.on('blur', (editor: CodeMirror.Editor, e: FocusEvent) => {
|
|
191
|
+
// if (!this._changed) return
|
|
192
|
+
|
|
193
|
+
// this.value = editor.getValue()
|
|
194
|
+
// this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
|
|
195
|
+
// })
|
|
196
|
+
|
|
197
|
+
// this._editor.on('change', async (editor: CodeMirror.Editor, changeObj: CodeMirror.EditorChange) => {
|
|
198
|
+
// this._self_changing = true
|
|
199
|
+
|
|
200
|
+
// this._changed = true
|
|
201
|
+
|
|
202
|
+
// await this.requestUpdate()
|
|
203
|
+
|
|
204
|
+
// this._self_changing = false
|
|
205
|
+
// })
|
|
206
|
+
// }
|
|
207
|
+
// }
|
|
208
|
+
|
|
209
|
+
// return this._editor
|
|
210
|
+
// }
|
|
169
211
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import '../src/input/ox-input-graphql.js'
|
|
2
|
+
|
|
3
|
+
import { html, TemplateResult } from 'lit'
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'ox-input-graphql',
|
|
7
|
+
component: 'ox-input-graphql',
|
|
8
|
+
argTypes: {
|
|
9
|
+
value: { control: 'text' },
|
|
10
|
+
name: { control: 'text' }
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface Story<T> {
|
|
15
|
+
(args: T): TemplateResult
|
|
16
|
+
args?: Partial<T>
|
|
17
|
+
argTypes?: Record<string, unknown>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface ArgTypes {
|
|
21
|
+
name?: string
|
|
22
|
+
value?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const Template: Story<ArgTypes> = ({ name = 'code', value = '' }: ArgTypes) => html`
|
|
26
|
+
<link href="/themes/app-theme.css" rel="stylesheet" />
|
|
27
|
+
<link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet" />
|
|
28
|
+
<style>
|
|
29
|
+
body {
|
|
30
|
+
}
|
|
31
|
+
</style>
|
|
32
|
+
|
|
33
|
+
<ox-input-graphql
|
|
34
|
+
@change=${(e: Event) => {
|
|
35
|
+
console.log((e.target as HTMLInputElement).value)
|
|
36
|
+
}}
|
|
37
|
+
name=${name}
|
|
38
|
+
.value=${value}
|
|
39
|
+
>
|
|
40
|
+
</ox-input-graphql>
|
|
41
|
+
`
|
|
42
|
+
|
|
43
|
+
export const Regular = Template.bind({})
|
|
44
|
+
Regular.args = {
|
|
45
|
+
name: 'code',
|
|
46
|
+
value: `
|
|
47
|
+
query privileges {
|
|
48
|
+
privileges {
|
|
49
|
+
items {
|
|
50
|
+
privilege
|
|
51
|
+
category
|
|
52
|
+
description
|
|
53
|
+
}
|
|
54
|
+
total
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
`
|
|
58
|
+
}
|