@operato/app 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/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.49",
5
+ "version": "1.5.51",
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": "tsc && npm run analyze -- --exclude dist && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds -c .storybook/server.mjs\"",
124
- "storybook:build": "tsc && npm run analyze -- --exclude dist && build-storybook"
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.49",
133
- "@operato/data-grist": "^1.5.49",
134
- "@operato/font": "^1.5.49",
139
+ "@operato/attachment": "^1.5.51",
140
+ "@operato/data-grist": "^1.5.51",
141
+ "@operato/font": "^1.5.51",
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.49",
145
+ "@operato/input": "^1.5.51",
139
146
  "@operato/layout": "^1.5.48",
140
- "@operato/property-editor": "^1.5.49",
147
+ "@operato/property-editor": "^1.5.51",
141
148
  "@operato/shell": "^1.5.48",
142
149
  "@operato/styles": "^1.5.48",
143
150
  "@operato/utils": "^1.5.44",
144
- "codemirror": "^5.64.0",
145
- "codemirror-graphql": "^2.0.9",
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": "f31c2176c17ea549d3626e063e6518879d0996a1"
192
+ "gitHead": "35850ad26ab8c395d6f6791daf76549ffda3d404"
186
193
  }
@@ -2,27 +2,22 @@
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, LitElement, PropertyValues, unsafeCSS } from 'lit'
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 { autocompletion, closeBrackets } from '@codemirror/autocomplete'
13
+ import { bracketMatching, syntaxHighlighting } from '@codemirror/language'
14
+ import { oneDarkHighlightStyle, oneDark } from '@codemirror/theme-one-dark'
15
+ import { EditorView, highlightActiveLine, keymap } from '@codemirror/view'
23
16
 
24
17
  import { introspectSchema, wrapSchema } from '@graphql-tools/wrap'
25
18
  import { GRAPHQL_URI } from '@operato/graphql'
19
+ import { OxFormField } from '@operato/input'
20
+ import { togglefullscreen } from '@operato/utils'
26
21
 
27
22
  /**
28
23
  WEB Component for code-mirror graphql editor.
@@ -33,30 +28,18 @@ import { GRAPHQL_URI } from '@operato/graphql'
33
28
  </ox-input-graphql>
34
29
  */
35
30
  @customElement('ox-input-graphql')
36
- export default class OxInputGraphql extends LitElement {
31
+ export default class OxInputGraphql extends OxFormField {
37
32
  static styles = [
38
- css`
39
- ${unsafeCSS(CodeMirrorStyle)}
40
- ${unsafeCSS(FullScreenStyle)}
41
- ${unsafeCSS(NightThemeStyle)}
42
- ${unsafeCSS(LintStyle)}
43
- ${unsafeCSS(ShowHintStyle)}
44
- `,
45
33
  css`
46
34
  :host {
47
- display: block;
35
+ display: flex;
36
+ flex-direction: column;
48
37
  position: relative;
38
+ background: white;
49
39
  }
50
40
 
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;
41
+ .cm-editor {
42
+ flex: 1;
60
43
  }
61
44
  `
62
45
  ]
@@ -67,26 +50,19 @@ export default class OxInputGraphql extends LitElement {
67
50
  @property({ type: String }) value?: string
68
51
  @property({ type: String }) link?: string
69
52
 
70
- @query('textarea') textarea!: HTMLTextAreaElement
71
-
72
53
  private _self_changing: boolean = false
73
- private _changed: boolean = false
74
- private _editor?: CodeMirror.EditorFromTextArea
54
+ private _editor?: EditorView
75
55
 
76
56
  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()
57
+ const editor = await this.getEditor()
58
+ if (changes.has('value') && editor && !this._self_changing) {
59
+ const to = editor.state.doc.toString().length
60
+ editor.dispatch({
61
+ changes: { from: 0, to, insert: this.value === undefined ? '' : String(this.value) }
62
+ })
83
63
  }
84
64
  }
85
65
 
86
- render() {
87
- return html` <textarea></textarea> `
88
- }
89
-
90
66
  async getSchema() {
91
67
  const executor = async ({ document, variables }: any) => {
92
68
  const query = print(document)
@@ -110,59 +86,53 @@ export default class OxInputGraphql extends LitElement {
110
86
 
111
87
  async getEditor() {
112
88
  if (!this._editor) {
89
+ var schema
113
90
  try {
114
- var schema = await this.getSchema()
91
+ schema = await this.getSchema()
115
92
  } catch (err) {
116
93
  console.error(err)
117
94
  }
118
95
 
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'))
96
+ this._editor = new EditorView({
97
+ doc: this.value,
98
+ extensions: [
99
+ bracketMatching(),
100
+ closeBrackets(),
101
+ history(),
102
+ autocompletion(),
103
+ oneDark,
104
+ syntaxHighlighting(oneDarkHighlightStyle),
105
+ graphql(schema, {
106
+ onShowInDocs(field, type, parentType) {
107
+ alert(`Showing in docs.: Field: ${field}, Type: ${type}, ParentType: ${parentType}`)
138
108
  },
139
- Esc: function (cm) {
140
- cm.setOption('fullScreen', !cm.getOption('fullScreen'))
109
+ onFillAllFields(view, schema, _query, cursor, token) {
110
+ alert(`Filling all fields. Token: ${token}`)
141
111
  }
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()
112
+ }),
113
+ highlightActiveLine(),
114
+ history(),
115
+ keymap.of([...historyKeymap, indentWithTab]),
116
+ EditorView.updateListener.of(v => {
117
+ if (v.docChanged) {
118
+ this._self_changing = true
119
+ this.value = v.state.doc.toString()
120
+ this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
121
+ requestAnimationFrame(() => {
122
+ this._self_changing = false
123
+ })
124
+ }
125
+ })
126
+ ],
127
+ parent: this.renderRoot
128
+ })
129
+ }
161
130
 
162
- this._self_changing = false
163
- })
131
+ this._editor.contentDOM.addEventListener('keydown', event => {
132
+ if (event.key === 'Escape') {
133
+ togglefullscreen(this._editor!.contentDOM)
164
134
  }
165
- }
135
+ })
166
136
 
167
137
  return this._editor
168
138
  }
@@ -8,6 +8,6 @@ import { OxPropertyEditor, PropertySpec } from '@operato/property-editor'
8
8
  @customElement('ox-property-editor-graphql')
9
9
  export class OxPropertyEditorGraphQL extends OxPropertyEditor {
10
10
  editorTemplate(value: any, spec: PropertySpec): TemplateResult {
11
- return html` <ox-input-graphql id="editor" .value=${value} fullwidth> </ox-input-graphql> `
11
+ return html` <ox-input-graphql class="multiline-input" id="editor" .value=${value} fullwidth> </ox-input-graphql> `
12
12
  }
13
13
  }
@@ -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
+ }