@operato/app 0.4.2

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/.editorconfig ADDED
@@ -0,0 +1,29 @@
1
+ # EditorConfig helps developers define and maintain consistent
2
+ # coding styles between different editors and IDEs
3
+ # editorconfig.org
4
+
5
+ root = true
6
+
7
+
8
+ [*]
9
+
10
+ # Change these settings to your own preference
11
+ indent_style = space
12
+ indent_size = 2
13
+
14
+ # We recommend you to keep these unchanged
15
+ end_of_line = lf
16
+ charset = utf-8
17
+ trim_trailing_whitespace = true
18
+ insert_final_newline = true
19
+
20
+ [*.md]
21
+ trim_trailing_whitespace = false
22
+
23
+ [*.json]
24
+ indent_size = 2
25
+
26
+ [*.{html,js,md}]
27
+ block_comment_start = /**
28
+ block_comment = *
29
+ block_comment_end = */
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ stories: ['../dist/stories/**/*.stories.{js,md,mdx}'],
3
+ };
@@ -0,0 +1,8 @@
1
+ import { storybookPlugin } from '@web/dev-server-storybook';
2
+ import baseConfig from '../web-dev-server.config.mjs';
3
+
4
+ export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
5
+ ...baseConfig,
6
+ open: '/',
7
+ plugins: [storybookPlugin({ type: 'web-components' }), ...baseConfig.plugins],
8
+ });
package/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ### [0.4.2](https://github.com/hatiolab/operato/compare/v0.4.1...v0.4.2) (2022-03-06)
7
+
8
+
9
+ ### :rocket: New Features
10
+
11
+ * add @operato/app module to support productivity for web application ([217d1f2](https://github.com/hatiolab/operato/commit/217d1f2d99ff75dcd8da1293814653f4758c04b8))
12
+
13
+
14
+ ### :mega: Other
15
+
16
+ * delete unused ([0c23746](https://github.com/hatiolab/operato/commit/0c237461b67a8b9cc69304ea963cb230e7c143e4))
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) hatiolab.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # \<mini-app>
2
+
3
+ This webcomponent follows the [open-wc](https://github.com/open-wc/open-wc) recommendation.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm i mini-app
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```html
14
+ <script type="module">
15
+ import 'mini-app/mini-app.js'
16
+ </script>
17
+
18
+ <mini-app></mini-app>
19
+ ```
20
+
21
+ ## Linting and formatting
22
+
23
+ To scan the project for linting and formatting errors, run
24
+
25
+ ```bash
26
+ npm run lint
27
+ ```
28
+
29
+ To automatically fix linting and formatting errors, run
30
+
31
+ ```bash
32
+ npm run format
33
+ ```
34
+
35
+ ## Testing with Web Test Runner
36
+
37
+ To execute a single test run:
38
+
39
+ ```bash
40
+ npm run test
41
+ ```
42
+
43
+ To run the tests in interactive watch mode run:
44
+
45
+ ```bash
46
+ npm run test:watch
47
+ ```
48
+
49
+ ## Demoing with Storybook
50
+
51
+ To run a local instance of Storybook for your component, run
52
+
53
+ ```bash
54
+ npm run storybook
55
+ ```
56
+
57
+ To build a production version of Storybook, run
58
+
59
+ ```bash
60
+ npm run storybook:build
61
+ ```
62
+
63
+ ## Tooling configs
64
+
65
+ For most of the tools, the configuration is in the `package.json` to reduce the amount of files in your project.
66
+
67
+ If you customize the configuration a lot, you can consider moving them to individual files.
68
+
69
+ ## Local Demo with `web-dev-server`
70
+
71
+ ```bash
72
+ npm start
73
+ ```
74
+
75
+ To run a local development server that serves the basic demo located in `demo/index.html`
@@ -0,0 +1,33 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en-GB">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <style>
6
+ body {
7
+ background: #fafafa;
8
+ --ox-checkbox-size: 12px;
9
+ }
10
+
11
+ #demo {
12
+ position: relative;
13
+ height: 300px;
14
+ background-color: lightgray;
15
+ vertical-align: middle;
16
+ }
17
+ </style>
18
+ <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet" />
19
+ <link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet" />
20
+ </head>
21
+ <body>
22
+ <div id="demo"></div>
23
+
24
+ <script type="module">
25
+ import { html, render } from 'lit'
26
+ import '@material/mwc-icon'
27
+
28
+ const parent = document.querySelector('#demo')
29
+
30
+ render(html``, parent)
31
+ </script>
32
+ </body>
33
+ </html>
@@ -0,0 +1,19 @@
1
+ import '@material/mwc-icon';
2
+ import './id-selector.js';
3
+ import { ColumnConfig, GristRecord, InputEditor } from '@operato/data-grist';
4
+ import { TemplateResult } from 'lit';
5
+ export declare class IdInput extends InputEditor {
6
+ static styles: import("lit").CSSResult;
7
+ value?: {
8
+ id?: string;
9
+ [propany: string]: any;
10
+ };
11
+ column: ColumnConfig;
12
+ record: GristRecord;
13
+ row: number;
14
+ private popup?;
15
+ private template?;
16
+ render(): TemplateResult<1>;
17
+ firstUpdated(): Promise<void>;
18
+ openSelector(): void;
19
+ }
@@ -0,0 +1,119 @@
1
+ import { __decorate } from "tslib";
2
+ import '@material/mwc-icon';
3
+ import './id-selector.js';
4
+ import { InputEditor } from '@operato/data-grist';
5
+ import { css, html } from 'lit';
6
+ import { customElement, property } from 'lit/decorators.js';
7
+ import { openPopup } from '@operato/layout';
8
+ let IdInput = class IdInput extends InputEditor {
9
+ render() {
10
+ var { nameField = 'name', descriptionField = 'description' } = this.column.record.options || {};
11
+ var value = this.value;
12
+ return html `
13
+ ${!value ? html `` : html ` <span>${value[nameField]} (${value[descriptionField]})</span> `}
14
+ <mwc-icon>arrow_drop_down</mwc-icon>
15
+ `;
16
+ }
17
+ async firstUpdated() {
18
+ this.value = this.record[this.column.name];
19
+ this.template = ((this.column.record || {}).options || {}).template;
20
+ await this.updateComplete;
21
+ this.renderRoot.addEventListener('click', e => {
22
+ e.stopPropagation();
23
+ this.openSelector();
24
+ });
25
+ this.openSelector();
26
+ }
27
+ openSelector() {
28
+ if (this.popup) {
29
+ delete this.popup;
30
+ }
31
+ const confirmCallback = selected => {
32
+ if (!selected) {
33
+ return;
34
+ }
35
+ var { idField = 'id', nameField = 'name', descriptionField = 'description' } = this.column.record.options || {};
36
+ this.dispatchEvent(new CustomEvent('field-change', {
37
+ bubbles: true,
38
+ composed: true,
39
+ detail: {
40
+ before: this.value,
41
+ after: {
42
+ [idField]: selected[idField],
43
+ [nameField]: selected[nameField],
44
+ [descriptionField]: selected[descriptionField]
45
+ },
46
+ record: this.record,
47
+ column: this.column,
48
+ row: this.row
49
+ }
50
+ }));
51
+ };
52
+ var value = this.value || {};
53
+ var template = this.template ||
54
+ html `
55
+ <ox-id-selector
56
+ .value=${value.id}
57
+ .confirmCallback=${confirmCallback.bind(this)}
58
+ .queryName=${this.column.record.options.queryName}
59
+ .basicArgs=${this.column.record.options.basicArgs}
60
+ ></ox-id-selector>
61
+ `;
62
+ this.popup = openPopup(template, {
63
+ backdrop: true,
64
+ size: 'large',
65
+ title: 'select item'
66
+ });
67
+ }
68
+ };
69
+ IdInput.styles = css `
70
+ :host {
71
+ display: flex;
72
+ flex-flow: row nowrap;
73
+ align-items: center;
74
+
75
+ padding: 7px 0px;
76
+ box-sizing: border-box;
77
+
78
+ width: 100%;
79
+ height: 100%;
80
+
81
+ border: 0;
82
+ background-color: transparent;
83
+
84
+ font: var(--grist-object-editor-font);
85
+ color: var(--grist-object-editor-color);
86
+
87
+ justify-content: inherit;
88
+ }
89
+
90
+ span {
91
+ display: flex;
92
+ flex: auto;
93
+
94
+ justify-content: inherit;
95
+ }
96
+
97
+ mwc-icon {
98
+ width: 20px;
99
+ font-size: 1.5em;
100
+ margin-left: auto;
101
+ }
102
+ `;
103
+ __decorate([
104
+ property({ type: Object })
105
+ ], IdInput.prototype, "value", void 0);
106
+ __decorate([
107
+ property({ type: Object })
108
+ ], IdInput.prototype, "column", void 0);
109
+ __decorate([
110
+ property({ type: Object })
111
+ ], IdInput.prototype, "record", void 0);
112
+ __decorate([
113
+ property({ type: Number })
114
+ ], IdInput.prototype, "row", void 0);
115
+ IdInput = __decorate([
116
+ customElement('ox-id-input')
117
+ ], IdInput);
118
+ export { IdInput };
119
+ //# sourceMappingURL=id-input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id-input.js","sourceRoot":"","sources":["../../../src/grist/id-input.ts"],"names":[],"mappings":";AAAA,OAAO,oBAAoB,CAAA;AAC3B,OAAO,kBAAkB,CAAA;AAEzB,OAAO,EAA6B,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAC5E,OAAO,EAAkB,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAE3D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAG3C,IAAa,OAAO,G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AAC/C;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uCAAsB;AACrB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uCAAqB;AACpB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;oCAAa;AAvC7B,OAAO;IADnB,aAAa,CAAC,aAAa,CAAC;GAChB,OAAO,CA4HnB;SA5HY,OAAO","sourcesContent":["import '@material/mwc-icon'\nimport './id-selector.js'\n\nimport { ColumnConfig, GristRecord, InputEditor } from '@operato/data-grist'\nimport { TemplateResult, css, html } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport { openPopup } from '@operato/layout'\n\n@customElement('ox-id-input')\nexport class IdInput extends InputEditor {\n static styles = css`\n :host {\n display: flex;\n flex-flow: row nowrap;\n align-items: center;\n\n padding: 7px 0px;\n box-sizing: border-box;\n\n width: 100%;\n height: 100%;\n\n border: 0;\n background-color: transparent;\n\n font: var(--grist-object-editor-font);\n color: var(--grist-object-editor-color);\n\n justify-content: inherit;\n }\n\n span {\n display: flex;\n flex: auto;\n\n justify-content: inherit;\n }\n\n mwc-icon {\n width: 20px;\n font-size: 1.5em;\n margin-left: auto;\n }\n `\n\n @property({ type: Object }) value?: { id?: string; [propany: string]: any }\n @property({ type: Object }) column!: ColumnConfig\n @property({ type: Object }) record!: GristRecord\n @property({ type: Number }) row!: number\n\n private popup?: {\n name: string\n close: () => void\n closed: boolean\n onclosed?: (() => void) | undefined\n }\n\n private template?: TemplateResult\n\n render() {\n var { nameField = 'name', descriptionField = 'description' } = this.column.record.options || {}\n var value = this.value\n\n return html`\n ${!value ? html`` : html` <span>${value[nameField]} (${value[descriptionField]})</span> `}\n <mwc-icon>arrow_drop_down</mwc-icon>\n `\n }\n\n async firstUpdated() {\n this.value = this.record[this.column.name]\n this.template = ((this.column.record || {}).options || {}).template\n\n await this.updateComplete\n\n this.renderRoot.addEventListener('click', e => {\n e.stopPropagation()\n\n this.openSelector()\n })\n\n this.openSelector()\n }\n\n openSelector() {\n if (this.popup) {\n delete this.popup\n }\n\n const confirmCallback: (record: GristRecord | undefined) => void = selected => {\n if (!selected) {\n return\n }\n\n var { idField = 'id', nameField = 'name', descriptionField = 'description' } = this.column.record.options || {}\n\n this.dispatchEvent(\n new CustomEvent('field-change', {\n bubbles: true,\n composed: true,\n detail: {\n before: this.value,\n after: {\n [idField]: selected[idField],\n [nameField]: selected[nameField],\n [descriptionField]: selected[descriptionField]\n },\n record: this.record,\n column: this.column,\n row: this.row\n }\n })\n )\n }\n\n var value = this.value || {}\n var template =\n this.template ||\n html`\n <ox-id-selector\n .value=${value.id}\n .confirmCallback=${confirmCallback.bind(this)}\n .queryName=${this.column.record.options.queryName}\n .basicArgs=${this.column.record.options.basicArgs}\n ></ox-id-selector>\n `\n\n this.popup = openPopup(template, {\n backdrop: true,\n size: 'large',\n title: 'select item'\n })\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import { FieldRenderer } from '@operato/data-grist';
2
+ export declare const IdRenderer: FieldRenderer;
@@ -0,0 +1,9 @@
1
+ import { html } from 'lit';
2
+ export const IdRenderer = (value, column, record, rowIndex, field) => {
3
+ if (!value) {
4
+ return '';
5
+ }
6
+ var { nameField = 'name', descriptionField = 'description' } = column.record.options || {};
7
+ return html ` ${value[nameField] || ''}(${value[descriptionField] || ''}) `;
8
+ };
9
+ //# sourceMappingURL=id-renderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id-renderer.js","sourceRoot":"","sources":["../../../src/grist/id-renderer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAE1B,MAAM,CAAC,MAAM,UAAU,GAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE;IAClF,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,EAAE,CAAA;KACV;IAED,IAAI,EAAE,SAAS,GAAG,MAAM,EAAE,gBAAgB,GAAG,aAAa,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAA;IAE1F,OAAO,IAAI,CAAA,IAAI,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,KAAK,CAAC,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAA;AAC5E,CAAC,CAAA","sourcesContent":["import { FieldRenderer } from '@operato/data-grist'\nimport { html } from 'lit'\n\nexport const IdRenderer: FieldRenderer = (value, column, record, rowIndex, field) => {\n if (!value) {\n return ''\n }\n\n var { nameField = 'name', descriptionField = 'description' } = column.record.options || {}\n\n return html` ${value[nameField] || ''}(${value[descriptionField] || ''}) `\n}\n"]}
@@ -0,0 +1,23 @@
1
+ import '@operato/data-grist';
2
+ import { DataGrist, FetchOption, GristData, GristRecord } from '@operato/data-grist';
3
+ import { LitElement } from 'lit';
4
+ export declare class IdSelector extends LitElement {
5
+ static styles: import("lit").CSSResult;
6
+ value?: string;
7
+ config: any;
8
+ data: GristData;
9
+ queryName: string;
10
+ basicArgs: any;
11
+ confirmCallback?: (record: GristRecord | undefined) => void;
12
+ selectedRecords: GristRecord[];
13
+ grist: DataGrist;
14
+ render(): import("lit-html").TemplateResult<1>;
15
+ oncancel(): void;
16
+ onconfirm(): void;
17
+ firstUpdated(): Promise<void>;
18
+ fetchHandler({ page, limit, sorters, filters }: FetchOption): Promise<{
19
+ total: any;
20
+ records: any;
21
+ }>;
22
+ get selected(): GristRecord | undefined;
23
+ }
@@ -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,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAG/C,IAAa,UAAU,GAAvB,MAAa,UAAW,SAAQ,UAAU;IAA1C;;QAkC8B,SAAI,GAAc,SAAS,CAAA;QAI5B,oBAAe,GAAkB,EAAE,CAAA;IA0IhE,CAAC;IAtIC,MAAM;QACJ,OAAO,IAAI,CAAA;;gBAEC,cAAc,EAAE,CAAC,CAAC,CAAC,MA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ig,\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"]}
@@ -0,0 +1 @@
1
+ export * from './grist/index.js';
@@ -0,0 +1,2 @@
1
+ export * from './grist/index.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA","sourcesContent":["export * from './grist/index.js'\n"]}