@operato/app 1.0.0-alpha.10 → 1.0.0-alpha.13
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/@types/global/index.d.ts +2 -0
- package/CHANGELOG.md +27 -0
- package/dist/src/grist/code-editor.js +8 -3
- package/dist/src/grist/code-editor.js.map +1 -1
- package/dist/src/input/ox-input-fill-style.js +1 -1
- package/dist/src/input/ox-input-fill-style.js.map +1 -1
- package/dist/src/input/ox-input-graphql.d.ts +36 -0
- package/dist/src/input/ox-input-graphql.js +161 -0
- package/dist/src/input/ox-input-graphql.js.map +1 -0
- package/dist/src/property-editor/ox-property-editor-graphql.d.ts +5 -0
- package/dist/src/property-editor/ox-property-editor-graphql.js +15 -0
- package/dist/src/property-editor/ox-property-editor-graphql.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -13
- package/src/grist/code-editor.ts +2 -3
- package/src/input/ox-input-fill-style.ts +1 -1
- package/src/input/ox-input-graphql.ts +169 -0
- package/src/property-editor/ox-property-editor-graphql.ts +12 -0
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "WebApplication production supporting components following open-wc recommendations",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "heartyoh",
|
|
6
|
-
"version": "1.0.0-alpha.
|
|
6
|
+
"version": "1.0.0-alpha.13",
|
|
7
7
|
"main": "dist/src/index.js",
|
|
8
8
|
"module": "dist/src/index.js",
|
|
9
9
|
"exports": {
|
|
@@ -15,9 +15,11 @@
|
|
|
15
15
|
"./grist/object-editor.js": "./dist/src/grist/object-editor.js",
|
|
16
16
|
"./grist/code-editor.js": "./dist/src/grist/code-editor.js",
|
|
17
17
|
"./grist/parameters-editor.js": "./dist/src/grist/parameters-editor.js",
|
|
18
|
+
"./input/ox-input-graphql.js": "./dist/src/input/ox-input-graphql.js",
|
|
18
19
|
"./input/ox-input-background-pattern.js": "./dist/src/input/ox-input-background-pattern.js",
|
|
19
20
|
"./input/ox-input-color-gradient.js": "./dist/src/input/ox-input-color-gradient.js",
|
|
20
|
-
"./input/ox-input-fill-style.js": "./dist/src/input/ox-input-fill-style.js"
|
|
21
|
+
"./input/ox-input-fill-style.js": "./dist/src/input/ox-input-fill-style.js",
|
|
22
|
+
"./property-editor/ox-property-editor-graphql.js": "./dist/src/property-editor/ox-property-editor-graphql.js"
|
|
21
23
|
},
|
|
22
24
|
"publishConfig": {
|
|
23
25
|
"access": "public",
|
|
@@ -44,16 +46,16 @@
|
|
|
44
46
|
"@material/mwc-button": "^0.25.3",
|
|
45
47
|
"@material/mwc-icon": "^0.25.3",
|
|
46
48
|
"@material/mwc-icon-button": "^0.25.3",
|
|
47
|
-
"@operato/attachment": "^1.0.0-alpha.
|
|
48
|
-
"@operato/data-grist": "^1.0.0-alpha.
|
|
49
|
-
"@operato/form": "^1.0.0-alpha.
|
|
50
|
-
"@operato/graphql": "^1.0.0-alpha.
|
|
51
|
-
"@operato/i18n": "^1.0.0-alpha.
|
|
52
|
-
"@operato/layout": "^1.0.0-alpha.
|
|
53
|
-
"@operato/property-editor": "^1.0.0-alpha.
|
|
54
|
-
"@operato/shell": "^1.0.0-alpha.
|
|
55
|
-
"@operato/styles": "^1.0.0-alpha.
|
|
56
|
-
"@operato/utils": "^1.0.0-alpha.
|
|
49
|
+
"@operato/attachment": "^1.0.0-alpha.13",
|
|
50
|
+
"@operato/data-grist": "^1.0.0-alpha.13",
|
|
51
|
+
"@operato/form": "^1.0.0-alpha.13",
|
|
52
|
+
"@operato/graphql": "^1.0.0-alpha.13",
|
|
53
|
+
"@operato/i18n": "^1.0.0-alpha.13",
|
|
54
|
+
"@operato/layout": "^1.0.0-alpha.13",
|
|
55
|
+
"@operato/property-editor": "^1.0.0-alpha.13",
|
|
56
|
+
"@operato/shell": "^1.0.0-alpha.13",
|
|
57
|
+
"@operato/styles": "^1.0.0-alpha.13",
|
|
58
|
+
"@operato/utils": "^1.0.0-alpha.13",
|
|
57
59
|
"lit": "^2.2.0"
|
|
58
60
|
},
|
|
59
61
|
"devDependencies": {
|
|
@@ -88,5 +90,5 @@
|
|
|
88
90
|
"prettier --write"
|
|
89
91
|
]
|
|
90
92
|
},
|
|
91
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "b0c60655bb787d7fea4ce06797d91c1fa2ab2b69"
|
|
92
94
|
}
|
package/src/grist/code-editor.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import '@material/mwc-icon'
|
|
2
|
-
import {} from '@operato/shell'
|
|
3
2
|
|
|
4
3
|
import { InputEditor, RecordConfig } from '@operato/data-grist'
|
|
5
4
|
import { client, gqlContext } from '@operato/graphql'
|
|
6
5
|
|
|
6
|
+
import { customElement } from 'lit/decorators.js'
|
|
7
7
|
import gql from 'graphql-tag'
|
|
8
8
|
import { html } from 'lit'
|
|
9
9
|
|
|
@@ -31,6 +31,7 @@ const FETCH_COMMON_CODE_GQL = (codeName: string) => gql`
|
|
|
31
31
|
}
|
|
32
32
|
`
|
|
33
33
|
|
|
34
|
+
@customElement('code-editor')
|
|
34
35
|
export class CodeEditor extends InputEditor {
|
|
35
36
|
async firstUpdated() {
|
|
36
37
|
super.firstUpdated()
|
|
@@ -74,5 +75,3 @@ export class CodeEditor extends InputEditor {
|
|
|
74
75
|
`
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
|
-
|
|
78
|
-
customElements.define('code-editor', CodeEditor)
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright © HatioLab Inc. All rights reserved.
|
|
3
|
+
*/
|
|
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 { GRAPHQL_URI, client } from '@operato/graphql'
|
|
14
|
+
import { LitElement, PropertyValues, css, html, unsafeCSS } from 'lit'
|
|
15
|
+
import { customElement, property, query } from 'lit/decorators.js'
|
|
16
|
+
import { introspectSchema, wrapSchema } from '@graphql-tools/wrap'
|
|
17
|
+
|
|
18
|
+
import CodeMirror from 'codemirror'
|
|
19
|
+
import CodeMirrorStyle from '!!text-loader!codemirror/lib/codemirror.css'
|
|
20
|
+
import FullScreenStyle from '!!text-loader!codemirror/addon/display/fullscreen.css'
|
|
21
|
+
import LintStyle from '!!text-loader!codemirror/addon/lint/lint.css'
|
|
22
|
+
import NightThemeStyle from '!!text-loader!codemirror/theme/night.css'
|
|
23
|
+
import ShowHintStyle from '!!text-loader!codemirror/addon/hint/show-hint.css'
|
|
24
|
+
import { fetch } from 'cross-fetch'
|
|
25
|
+
import { print } from 'graphql'
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
WEB Component for code-mirror graphql editor.
|
|
29
|
+
|
|
30
|
+
Example:
|
|
31
|
+
|
|
32
|
+
<ox-input-graphql value=${text} link=${link}>
|
|
33
|
+
</ox-input-graphql>
|
|
34
|
+
*/
|
|
35
|
+
@customElement('ox-input-graphql')
|
|
36
|
+
export default class OxInputGraphql extends LitElement {
|
|
37
|
+
static styles = [
|
|
38
|
+
css`
|
|
39
|
+
${unsafeCSS(CodeMirrorStyle)}
|
|
40
|
+
${unsafeCSS(FullScreenStyle)}
|
|
41
|
+
${unsafeCSS(NightThemeStyle)}
|
|
42
|
+
${unsafeCSS(LintStyle)}
|
|
43
|
+
${unsafeCSS(ShowHintStyle)}
|
|
44
|
+
`,
|
|
45
|
+
css`
|
|
46
|
+
:host {
|
|
47
|
+
display: block;
|
|
48
|
+
position: relative;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
textarea {
|
|
52
|
+
display: block;
|
|
53
|
+
height: 100%;
|
|
54
|
+
width: 100%;
|
|
55
|
+
resize: none;
|
|
56
|
+
font-size: 16px;
|
|
57
|
+
line-height: 20px;
|
|
58
|
+
border: 0px;
|
|
59
|
+
padding: 0px;
|
|
60
|
+
}
|
|
61
|
+
`
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* `value`는 에디터에서 작성중인 contents이다.
|
|
66
|
+
*/
|
|
67
|
+
@property({ type: String }) value?: string
|
|
68
|
+
@property({ type: String }) link?: string
|
|
69
|
+
|
|
70
|
+
@query('textarea') textarea!: HTMLTextAreaElement
|
|
71
|
+
|
|
72
|
+
private _self_changing: boolean = false
|
|
73
|
+
private _changed: boolean = false
|
|
74
|
+
private _editor?: CodeMirror.EditorFromTextArea
|
|
75
|
+
|
|
76
|
+
async updated(changes: PropertyValues<this>) {
|
|
77
|
+
if ((!this._editor || changes.has('value') || changes.has('link')) && !this._self_changing) {
|
|
78
|
+
if (changes.has('link')) {
|
|
79
|
+
this._editor = undefined
|
|
80
|
+
}
|
|
81
|
+
;(await this.getEditor())!.setValue(this.value === undefined ? '' : String(this.value))
|
|
82
|
+
// ;(await this.getEditor()).refresh()
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
render() {
|
|
87
|
+
return html` <textarea></textarea> `
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async getSchema() {
|
|
91
|
+
const executor = async ({ document, variables }: any) => {
|
|
92
|
+
const query = print(document)
|
|
93
|
+
const uri = this.link || GRAPHQL_URI
|
|
94
|
+
|
|
95
|
+
const fetchResult = await fetch(uri, {
|
|
96
|
+
method: 'POST',
|
|
97
|
+
headers: {
|
|
98
|
+
'Content-Type': 'application/json'
|
|
99
|
+
},
|
|
100
|
+
body: JSON.stringify({ query, variables })
|
|
101
|
+
})
|
|
102
|
+
return fetchResult.json()
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return await wrapSchema({
|
|
106
|
+
schema: await introspectSchema(executor),
|
|
107
|
+
executor
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async getEditor() {
|
|
112
|
+
if (!this._editor) {
|
|
113
|
+
try {
|
|
114
|
+
var schema = await this.getSchema()
|
|
115
|
+
} catch (err) {
|
|
116
|
+
console.error(err)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (this.textarea) {
|
|
120
|
+
this._editor = CodeMirror.fromTextArea(this.textarea, {
|
|
121
|
+
value: this.value,
|
|
122
|
+
mode: 'graphql',
|
|
123
|
+
lint: {
|
|
124
|
+
//@ts-ignore
|
|
125
|
+
schema
|
|
126
|
+
},
|
|
127
|
+
hintOptions: {
|
|
128
|
+
//@ts-ignore
|
|
129
|
+
schema
|
|
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'))
|
|
138
|
+
},
|
|
139
|
+
Esc: function (cm) {
|
|
140
|
+
cm.setOption('fullScreen', !cm.getOption('fullScreen'))
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
autoRefresh: {
|
|
144
|
+
delay: 500
|
|
145
|
+
}
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
this._editor.on('blur', (editor: CodeMirror.Editor, e: FocusEvent) => {
|
|
149
|
+
if (!this._changed) return
|
|
150
|
+
|
|
151
|
+
this.value = editor.getValue()
|
|
152
|
+
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
this._editor.on('change', async (editor: CodeMirror.Editor, changeObj: CodeMirror.EditorChange) => {
|
|
156
|
+
this._self_changing = true
|
|
157
|
+
|
|
158
|
+
this._changed = true
|
|
159
|
+
|
|
160
|
+
await this.requestUpdate()
|
|
161
|
+
|
|
162
|
+
this._self_changing = false
|
|
163
|
+
})
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return this._editor
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import '../input/ox-input-graphql.js'
|
|
2
|
+
|
|
3
|
+
import { OxPropertyEditor } from '@operato/property-editor'
|
|
4
|
+
import { customElement } from 'lit/decorators.js'
|
|
5
|
+
import { html } from 'lit'
|
|
6
|
+
|
|
7
|
+
@customElement('ox-property-editor-graphql')
|
|
8
|
+
export class OxPropertyEditorGraphQL extends OxPropertyEditor {
|
|
9
|
+
editorTemplate() {
|
|
10
|
+
return html` <ox-input-graphql id="editor" .value=${this.value} fullwidth> </ox-input-graphql> `
|
|
11
|
+
}
|
|
12
|
+
}
|