@operato/app 1.0.0-beta.3 → 1.0.0-beta.6
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 +269 -0
- package/dist/src/filter-renderer/filter-resource-select.d.ts +4 -0
- package/dist/src/filter-renderer/filter-resource-select.js +79 -0
- package/dist/src/filter-renderer/filter-resource-select.js.map +1 -0
- package/dist/src/filter-renderer/index.d.ts +1 -0
- package/dist/src/filter-renderer/index.js +5 -0
- package/dist/src/filter-renderer/index.js.map +1 -0
- package/dist/src/grist/id-input.d.ts +19 -0
- package/dist/src/grist/id-input.js +119 -0
- package/dist/src/grist/id-input.js.map +1 -0
- package/dist/src/grist/id-renderer.d.ts +2 -0
- package/dist/src/grist/id-renderer.js +9 -0
- package/dist/src/grist/id-renderer.js.map +1 -0
- package/dist/src/grist/id-selector.d.ts +23 -0
- package/dist/src/grist/id-selector.js +197 -0
- package/dist/src/grist/id-selector.js.map +1 -0
- package/dist/src/grist/index.d.ts +1 -0
- package/dist/src/grist/index.js +7 -0
- package/dist/src/grist/index.js.map +1 -0
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/input/ox-input-resource.d.ts +36 -0
- package/dist/src/input/ox-input-resource.js +161 -0
- package/dist/src/input/ox-input-resource.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -15
- package/src/filter-renderer/filter-resource-select.ts +95 -0
- package/src/filter-renderer/index.ts +6 -0
- package/src/index.ts +2 -1
- package/src/input/ox-input-resource.ts +169 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
|
+
import '@operato/data-grist';
|
|
3
|
+
import { ZERO_DATA } from '@operato/data-grist';
|
|
4
|
+
import { LitElement, css, html } from 'lit';
|
|
5
|
+
import { customElement, property, query } from 'lit/decorators.js';
|
|
6
|
+
import { client } from '@operato/graphql';
|
|
7
|
+
import gql from 'graphql-tag';
|
|
8
|
+
import { i18next } from '@operato/i18n';
|
|
9
|
+
import { isMobileDevice } from '@operato/utils';
|
|
10
|
+
let IdSelector = class IdSelector extends LitElement {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.data = ZERO_DATA;
|
|
14
|
+
this.selectedRecords = [];
|
|
15
|
+
}
|
|
16
|
+
render() {
|
|
17
|
+
return html `
|
|
18
|
+
<ox-grist
|
|
19
|
+
.mode=${isMobileDevice() ? 'LIST' : 'GRID'}
|
|
20
|
+
.config=${this.config}
|
|
21
|
+
.fetchHandler=${this.fetchHandler.bind(this)}
|
|
22
|
+
.selectedRecords=${this.selectedRecords}
|
|
23
|
+
>
|
|
24
|
+
<div id="filters" slot="headless">
|
|
25
|
+
<ox-filters-form></ox-filters-form>
|
|
26
|
+
</div>
|
|
27
|
+
</ox-grist>
|
|
28
|
+
|
|
29
|
+
<div class="button-container">
|
|
30
|
+
<mwc-button @click=${this.oncancel.bind(this)}>${i18next.t('button.cancel')}</mwc-button>
|
|
31
|
+
<mwc-button @click=${this.onconfirm.bind(this)}>${i18next.t('button.confirm')}</mwc-button>
|
|
32
|
+
</div>
|
|
33
|
+
`;
|
|
34
|
+
}
|
|
35
|
+
oncancel() {
|
|
36
|
+
history.back();
|
|
37
|
+
}
|
|
38
|
+
onconfirm() {
|
|
39
|
+
this.confirmCallback && this.confirmCallback(this.selected);
|
|
40
|
+
history.back();
|
|
41
|
+
}
|
|
42
|
+
async firstUpdated() {
|
|
43
|
+
this.config = {
|
|
44
|
+
columns: [
|
|
45
|
+
{
|
|
46
|
+
type: 'gutter',
|
|
47
|
+
gutterName: 'sequence'
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: 'gutter',
|
|
51
|
+
gutterName: 'row-selector',
|
|
52
|
+
multiple: false
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
type: 'string',
|
|
56
|
+
name: 'id',
|
|
57
|
+
header: i18next.t('field.id'),
|
|
58
|
+
hidden: true
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
type: 'string',
|
|
62
|
+
name: 'name',
|
|
63
|
+
header: i18next.t('field.name'),
|
|
64
|
+
record: {
|
|
65
|
+
align: 'left'
|
|
66
|
+
},
|
|
67
|
+
filter: 'search',
|
|
68
|
+
sortable: true,
|
|
69
|
+
width: 160
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
type: 'string',
|
|
73
|
+
name: 'description',
|
|
74
|
+
header: i18next.t('field.description'),
|
|
75
|
+
record: {
|
|
76
|
+
align: 'left'
|
|
77
|
+
},
|
|
78
|
+
filter: 'search',
|
|
79
|
+
sortable: true,
|
|
80
|
+
width: 300
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
rows: {
|
|
84
|
+
selectable: {
|
|
85
|
+
multiple: false
|
|
86
|
+
},
|
|
87
|
+
handlers: {
|
|
88
|
+
click: 'select-row'
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
pagination: {
|
|
92
|
+
infinite: true
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
await this.updateComplete;
|
|
96
|
+
/* TODO config가 설정될 때, fetch() 가 동작하므로, fetch 완료 이벤트를 받아서, selected를 설정해주는 것이 좋겠다.
|
|
97
|
+
현재는 fetch() 가 두번 일어난다.
|
|
98
|
+
*/
|
|
99
|
+
await this.grist.fetch();
|
|
100
|
+
var selected = this.grist.data.records.find(item => this.value == item.id);
|
|
101
|
+
if (selected) {
|
|
102
|
+
this.selectedRecords = [selected];
|
|
103
|
+
}
|
|
104
|
+
/* TODO config가 설정될 때, fetch() 가 동작하므로, fetch 완료 이벤트를 받아서, selected를 설정해주는 것이 좋겠다. */
|
|
105
|
+
await this.updateComplete;
|
|
106
|
+
this.grist.focus();
|
|
107
|
+
}
|
|
108
|
+
async fetchHandler({ page = 1, limit = 100, sorters = [], filters = [] }) {
|
|
109
|
+
const response = await client.query({
|
|
110
|
+
query: gql `
|
|
111
|
+
query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
|
|
112
|
+
q: ${this.queryName}(filters: $filters, pagination: $pagination, sortings: $sortings) {
|
|
113
|
+
items {
|
|
114
|
+
id
|
|
115
|
+
name
|
|
116
|
+
description
|
|
117
|
+
}
|
|
118
|
+
total
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
`,
|
|
122
|
+
variables: {
|
|
123
|
+
filters,
|
|
124
|
+
pagination: { page, limit },
|
|
125
|
+
sortings: sorters
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return {
|
|
129
|
+
total: response.data.q.total || 0,
|
|
130
|
+
records: response.data.q.items || []
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
get selected() {
|
|
134
|
+
var grist = this.renderRoot.querySelector('ox-grist');
|
|
135
|
+
var selected = grist.selected;
|
|
136
|
+
return selected && selected.length > 0 ? selected[0] : undefined;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
IdSelector.styles = css `
|
|
140
|
+
:host {
|
|
141
|
+
display: flex;
|
|
142
|
+
flex-direction: column;
|
|
143
|
+
|
|
144
|
+
background-color: #fff;
|
|
145
|
+
|
|
146
|
+
width: var(--overlay-center-normal-width, 50%);
|
|
147
|
+
height: var(--overlay-center-normal-height, 50%);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
ox-grist {
|
|
151
|
+
flex: 1;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
#filters {
|
|
155
|
+
display: flex;
|
|
156
|
+
flex-direction: row;
|
|
157
|
+
justify-content: space-between;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
#filters > * {
|
|
161
|
+
padding: var(--padding-default) var(--padding-wide);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.button-container {
|
|
165
|
+
display: flex;
|
|
166
|
+
margin-left: auto;
|
|
167
|
+
}
|
|
168
|
+
`;
|
|
169
|
+
__decorate([
|
|
170
|
+
property({ type: String })
|
|
171
|
+
], IdSelector.prototype, "value", void 0);
|
|
172
|
+
__decorate([
|
|
173
|
+
property({ type: Object })
|
|
174
|
+
], IdSelector.prototype, "config", void 0);
|
|
175
|
+
__decorate([
|
|
176
|
+
property({ type: Object })
|
|
177
|
+
], IdSelector.prototype, "data", void 0);
|
|
178
|
+
__decorate([
|
|
179
|
+
property({ type: String })
|
|
180
|
+
], IdSelector.prototype, "queryName", void 0);
|
|
181
|
+
__decorate([
|
|
182
|
+
property({ type: Object })
|
|
183
|
+
], IdSelector.prototype, "basicArgs", void 0);
|
|
184
|
+
__decorate([
|
|
185
|
+
property({ type: Object })
|
|
186
|
+
], IdSelector.prototype, "confirmCallback", void 0);
|
|
187
|
+
__decorate([
|
|
188
|
+
property({ type: Array })
|
|
189
|
+
], IdSelector.prototype, "selectedRecords", void 0);
|
|
190
|
+
__decorate([
|
|
191
|
+
query('ox-grist')
|
|
192
|
+
], IdSelector.prototype, "grist", void 0);
|
|
193
|
+
IdSelector = __decorate([
|
|
194
|
+
customElement('ox-id-selector')
|
|
195
|
+
], IdSelector);
|
|
196
|
+
export { IdSelector };
|
|
197
|
+
//# sourceMappingURL=id-selector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id-selector.js","sourceRoot":"","sources":["../../../src/grist/id-selector.ts"],"names":[],"mappings":";AAAA,OAAO,qBAAqB,CAAA;AAE5B,OAAO,EAOL,SAAS,EACV,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAElE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAA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5D;IAA1B,QAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;mDAAoC;AAE3C;IAAlB,KAAK,CAAC,UAAU,CAAC;yCAAkB;AAxCzB,UAAU;IADtB,aAAa,CAAC,gBAAgB,CAAC;GACnB,UAAU,CAgLtB;SAhLY,UAAU","sourcesContent":["import '@operato/data-grist'\n\nimport {\n DataGrist,\n FetchOption,\n GristConfig,\n GristData,\n GristRecord,\n ZERO_CONFIG,\n ZERO_DATA\n} from '@operato/data-grist'\nimport { LitElement, css, html } from 'lit'\nimport { customElement, property, query } from 'lit/decorators.js'\n\nimport { client } from '@operato/graphql'\nimport gql from 'graphql-tag'\nimport { i18next } from '@operato/i18n'\nimport { isMobileDevice } from '@operato/utils'\n\n@customElement('ox-id-selector')\nexport class IdSelector extends LitElement {\n static styles = css`\n :host {\n display: flex;\n flex-direction: column;\n\n background-color: #fff;\n\n width: var(--overlay-center-normal-width, 50%);\n height: var(--overlay-center-normal-height, 50%);\n }\n\n ox-grist {\n flex: 1;\n }\n\n #filters {\n display: flex;\n flex-direction: row;\n justify-content: space-between;\n }\n\n #filters > * {\n padding: var(--padding-default) var(--padding-wide);\n }\n\n .button-container {\n display: flex;\n margin-left: auto;\n }\n `\n\n @property({ type: String }) value?: string\n @property({ type: Object }) config: any\n @property({ type: Object }) data: GristData = ZERO_DATA\n @property({ type: String }) queryName!: string\n @property({ type: Object }) basicArgs: any\n @property({ type: Object }) confirmCallback?: (record: GristRecord | undefined) => void\n @property({ type: Array }) selectedRecords: GristRecord[] = []\n\n @query('ox-grist') grist!: DataGrist\n\n render() {\n return html`\n <ox-grist\n .mode=${isMobileDevice() ? 'LIST' : 'GRID'}\n .config=${this.config}\n .fetchHandler=${this.fetchHandler.bind(this)}\n .selectedRecords=${this.selectedRecords}\n >\n <div id=\"filters\" slot=\"headless\">\n <ox-filters-form></ox-filters-form>\n </div>\n </ox-grist>\n\n <div class=\"button-container\">\n <mwc-button @click=${this.oncancel.bind(this)}>${i18next.t('button.cancel')}</mwc-button>\n <mwc-button @click=${this.onconfirm.bind(this)}>${i18next.t('button.confirm')}</mwc-button>\n </div>\n `\n }\n\n oncancel() {\n history.back()\n }\n\n onconfirm() {\n this.confirmCallback && this.confirmCallback(this.selected)\n history.back()\n }\n\n async firstUpdated() {\n this.config = {\n columns: [\n {\n type: 'gutter',\n gutterName: 'sequence'\n },\n {\n type: 'gutter',\n gutterName: 'row-selector',\n multiple: false\n },\n {\n type: 'string',\n name: 'id',\n header: i18next.t('field.id'),\n hidden: true\n },\n {\n type: 'string',\n name: 'name',\n header: i18next.t('field.name'),\n record: {\n align: 'left'\n },\n filter: 'search',\n sortable: true,\n width: 160\n },\n {\n type: 'string',\n name: 'description',\n header: i18next.t('field.description'),\n record: {\n align: 'left'\n },\n filter: 'search',\n sortable: true,\n width: 300\n }\n ],\n rows: {\n selectable: {\n multiple: false\n },\n handlers: {\n click: 'select-row'\n }\n },\n pagination: {\n infinite: true\n }\n }\n\n await this.updateComplete\n\n /* TODO config가 설정될 때, fetch() 가 동작하므로, fetch 완료 이벤트를 받아서, selected를 설정해주는 것이 좋겠다. \n 현재는 fetch() 가 두번 일어난다.\n */\n await this.grist.fetch()\n\n var selected = this.grist.data.records.find(item => this.value == item.id)\n if (selected) {\n this.selectedRecords = [selected]\n }\n /* TODO config가 설정될 때, fetch() 가 동작하므로, fetch 완료 이벤트를 받아서, selected를 설정해주는 것이 좋겠다. */\n\n await this.updateComplete\n this.grist.focus()\n }\n\n async fetchHandler({ page = 1, limit = 100, sorters = [], filters = [] }: FetchOption) {\n const response = await client.query({\n query: gql`\n query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {\n q: ${this.queryName}(filters: $filters, pagination: $pagination, sortings: $sortings) {\n items {\n id\n name\n description\n }\n total\n }\n }\n `,\n variables: {\n filters,\n pagination: { page, limit },\n sortings: sorters\n }\n })\n\n return {\n total: response.data.q.total || 0,\n records: response.data.q.items || []\n }\n }\n\n get selected() {\n var grist = this.renderRoot.querySelector('ox-grist') as DataGrist\n\n var selected = grist.selected\n\n return selected && selected.length > 0 ? selected[0] : undefined\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { registerEditor, registerRenderer } from '@operato/data-grist';
|
|
2
|
+
import { IdInput } from './id-input.js';
|
|
3
|
+
import { IdRenderer } from './id-renderer.js';
|
|
4
|
+
/* register grist renderer/editor for id */
|
|
5
|
+
registerEditor('id', IdInput);
|
|
6
|
+
registerRenderer('id', IdRenderer);
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/grist/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAEtE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C,2CAA2C;AAC3C,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;AAE7B,gBAAgB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA","sourcesContent":["import { registerEditor, registerRenderer } from '@operato/data-grist'\n\nimport { IdInput } from './id-input.js'\nimport { IdRenderer } from './id-renderer.js'\n\n/* register grist renderer/editor for id */\nregisterEditor('id', IdInput)\n\nregisterRenderer('id', IdRenderer)\n"]}
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,yBAAyB,CAAA;AACvC,cAAc,4BAA4B,CAAA","sourcesContent":["export * from './input/index.js'\nexport * from './property-editor/index.js'\nexport * from './grist-editor/index.js'\nexport * from './filter-renderer/index.js'\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright © HatioLab Inc. All rights reserved.
|
|
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 { LitElement, PropertyValues } from 'lit';
|
|
12
|
+
import CodeMirror from 'codemirror';
|
|
13
|
+
/**
|
|
14
|
+
WEB Component for code-mirror graphql editor.
|
|
15
|
+
|
|
16
|
+
Example:
|
|
17
|
+
|
|
18
|
+
<ox-input-graphql value=${text} link=${link}>
|
|
19
|
+
</ox-input-graphql>
|
|
20
|
+
*/
|
|
21
|
+
export default class OxInputGraphql extends LitElement {
|
|
22
|
+
static styles: import("lit").CSSResult[];
|
|
23
|
+
/**
|
|
24
|
+
* `value`는 에디터에서 작성중인 contents이다.
|
|
25
|
+
*/
|
|
26
|
+
value?: string;
|
|
27
|
+
link?: string;
|
|
28
|
+
textarea: HTMLTextAreaElement;
|
|
29
|
+
private _self_changing;
|
|
30
|
+
private _changed;
|
|
31
|
+
private _editor?;
|
|
32
|
+
updated(changes: PropertyValues<this>): Promise<void>;
|
|
33
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
34
|
+
getSchema(): Promise<import("graphql").GraphQLSchema>;
|
|
35
|
+
getEditor(): Promise<CodeMirror.EditorFromTextArea | undefined>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright © HatioLab Inc. All rights reserved.
|
|
3
|
+
*/
|
|
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 { GRAPHQL_URI } from '@operato/graphql';
|
|
13
|
+
import { LitElement, css, html, unsafeCSS } from 'lit';
|
|
14
|
+
import { customElement, property, query } from 'lit/decorators.js';
|
|
15
|
+
import { introspectSchema, wrapSchema } from '@graphql-tools/wrap';
|
|
16
|
+
import CodeMirror from 'codemirror';
|
|
17
|
+
import CodeMirrorStyle from '!!text-loader!codemirror/lib/codemirror.css';
|
|
18
|
+
import FullScreenStyle from '!!text-loader!codemirror/addon/display/fullscreen.css';
|
|
19
|
+
import LintStyle from '!!text-loader!codemirror/addon/lint/lint.css';
|
|
20
|
+
import NightThemeStyle from '!!text-loader!codemirror/theme/night.css';
|
|
21
|
+
import ShowHintStyle from '!!text-loader!codemirror/addon/hint/show-hint.css';
|
|
22
|
+
import { fetch } from 'cross-fetch';
|
|
23
|
+
import { print } from 'graphql';
|
|
24
|
+
/**
|
|
25
|
+
WEB Component for code-mirror graphql editor.
|
|
26
|
+
|
|
27
|
+
Example:
|
|
28
|
+
|
|
29
|
+
<ox-input-graphql value=${text} link=${link}>
|
|
30
|
+
</ox-input-graphql>
|
|
31
|
+
*/
|
|
32
|
+
let OxInputGraphql = class OxInputGraphql extends LitElement {
|
|
33
|
+
constructor() {
|
|
34
|
+
super(...arguments);
|
|
35
|
+
this._self_changing = false;
|
|
36
|
+
this._changed = false;
|
|
37
|
+
}
|
|
38
|
+
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()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
render() {
|
|
49
|
+
return html ` <textarea></textarea> `;
|
|
50
|
+
}
|
|
51
|
+
async getSchema() {
|
|
52
|
+
const executor = async ({ document, variables }) => {
|
|
53
|
+
const query = print(document);
|
|
54
|
+
const uri = this.link || GRAPHQL_URI;
|
|
55
|
+
const fetchResult = await fetch(uri, {
|
|
56
|
+
method: 'POST',
|
|
57
|
+
headers: {
|
|
58
|
+
'Content-Type': 'application/json'
|
|
59
|
+
},
|
|
60
|
+
body: JSON.stringify({ query, variables })
|
|
61
|
+
});
|
|
62
|
+
return fetchResult.json();
|
|
63
|
+
};
|
|
64
|
+
return await wrapSchema({
|
|
65
|
+
schema: await introspectSchema(executor),
|
|
66
|
+
executor
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async getEditor() {
|
|
70
|
+
if (!this._editor) {
|
|
71
|
+
try {
|
|
72
|
+
var schema = await this.getSchema();
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
console.error(err);
|
|
76
|
+
}
|
|
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'));
|
|
96
|
+
},
|
|
97
|
+
Esc: function (cm) {
|
|
98
|
+
cm.setOption('fullScreen', !cm.getOption('fullScreen'));
|
|
99
|
+
}
|
|
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
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return this._editor;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
OxInputGraphql.styles = [
|
|
123
|
+
css `
|
|
124
|
+
${unsafeCSS(CodeMirrorStyle)}
|
|
125
|
+
${unsafeCSS(FullScreenStyle)}
|
|
126
|
+
${unsafeCSS(NightThemeStyle)}
|
|
127
|
+
${unsafeCSS(LintStyle)}
|
|
128
|
+
${unsafeCSS(ShowHintStyle)}
|
|
129
|
+
`,
|
|
130
|
+
css `
|
|
131
|
+
:host {
|
|
132
|
+
display: block;
|
|
133
|
+
position: relative;
|
|
134
|
+
}
|
|
135
|
+
|
|
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;
|
|
145
|
+
}
|
|
146
|
+
`
|
|
147
|
+
];
|
|
148
|
+
__decorate([
|
|
149
|
+
property({ type: String })
|
|
150
|
+
], OxInputGraphql.prototype, "value", void 0);
|
|
151
|
+
__decorate([
|
|
152
|
+
property({ type: String })
|
|
153
|
+
], OxInputGraphql.prototype, "link", void 0);
|
|
154
|
+
__decorate([
|
|
155
|
+
query('textarea')
|
|
156
|
+
], OxInputGraphql.prototype, "textarea", void 0);
|
|
157
|
+
OxInputGraphql = __decorate([
|
|
158
|
+
customElement('ox-input-graphql')
|
|
159
|
+
], OxInputGraphql);
|
|
160
|
+
export default OxInputGraphql;
|
|
161
|
+
//# sourceMappingURL=ox-input-resource.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ox-input-resource.js","sourceRoot":"","sources":["../../../src/input/ox-input-resource.ts"],"names":[],"mappings":"AAAA;;GAEG;;AAEH,OAAO,qCAAqC,CAAA;AAC5C,OAAO,sCAAsC,CAAA;AAC7C,OAAO,iCAAiC,CAAA;AACxC,OAAO,4BAA4B,CAAA;AACnC,OAAO,yBAAyB,CAAA;AAChC,OAAO,yBAAyB,CAAA;AAChC,OAAO,yBAAyB,CAAA;AAEhC,OAAO,EAAE,WAAW,EAAU,MAAM,kBAAkB,CAAA;AACtD,OAAO,EAAE,UAAU,EAAkB,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,KAAK,CAAA;AACtE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAClE,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAElE,OAAO,UAAU,MAAM,YAAY,CAAA;AACnC,OAAO,eAAe,MAAM,6CAA6C,CAAA;AACzE,OAAO,eAAe,MAAM,uDAAuD,CAAA;AACnF,OAAO,SAAS,MAAM,8CAA8C,CAAA;AACpE,OAAO,eAAe,MAAM,0CAA0C,CAAA;AACtE,OAAO,aAAa,MAAM,mDAAmD,CAAA;AAC7E,OAAO,EAAE,KAAK,EAAE,MAAM,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/**\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 { GRAPHQL_URI, client } from '@operato/graphql'\nimport { LitElement, PropertyValues, css, html, unsafeCSS } from 'lit'\nimport { customElement, property, query } from 'lit/decorators.js'\nimport { introspectSchema, wrapSchema } from '@graphql-tools/wrap'\n\nimport CodeMirror from 'codemirror'\nimport CodeMirrorStyle from '!!text-loader!codemirror/lib/codemirror.css'\nimport FullScreenStyle from '!!text-loader!codemirror/addon/display/fullscreen.css'\nimport LintStyle from '!!text-loader!codemirror/addon/lint/lint.css'\nimport NightThemeStyle from '!!text-loader!codemirror/theme/night.css'\nimport ShowHintStyle from '!!text-loader!codemirror/addon/hint/show-hint.css'\nimport { fetch } from 'cross-fetch'\nimport { print } from '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"]}
|