@things-factory/id-rule-base 7.0.1-alpha.64 → 7.0.1-alpha.71

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.
@@ -0,0 +1,8 @@
1
+ import { registerEditor } from '@operato/data-grist'
2
+
3
+ import { GristCodeInput } from './editors/grist-code-input'
4
+
5
+ export default function bootstrap() {
6
+ /* id-rule 의 GristRenderer는 텍스트와 같으므로, 별도로 정의하지 않음. */
7
+ registerEditor('id-rule', GristCodeInput)
8
+ }
@@ -1,11 +1,15 @@
1
- import '@material/mwc-button'
1
+ import '@material/web/button/elevated-button.js'
2
2
  import '@operato/i18n/ox-i18n.js'
3
3
  import '@operato/input/ox-input-code.js'
4
4
 
5
- import { i18next } from '@things-factory/i18n-base'
6
- import { client, gqlContext } from '@things-factory/shell'
7
5
  import gql from 'graphql-tag'
8
6
  import { css, html, LitElement } from 'lit'
7
+ import { customElement, property, query, state } from 'lit/decorators.js'
8
+
9
+ import { i18next } from '@operato/i18n'
10
+ import { client } from '@operato/graphql'
11
+ import { ColumnConfig, GristRecord } from '@operato/data-grist'
12
+ import { OxInputCode } from '@operato/input'
9
13
 
10
14
  const FETCH_ID_RULE_GQL = type => {
11
15
  return gql`
@@ -19,9 +23,10 @@ const FETCH_ID_RULE_GQL = type => {
19
23
  `
20
24
  }
21
25
 
26
+ @customElement('grist-code-input-popup')
22
27
  export class GristCodeInputPopup extends LitElement {
23
- static get styles() {
24
- return css`
28
+ static styles = [
29
+ css`
25
30
  :host {
26
31
  display: flex;
27
32
  flex-direction: column;
@@ -80,19 +85,18 @@ export class GristCodeInputPopup extends LitElement {
80
85
  justify-content: flex-end;
81
86
  }
82
87
  `
83
- }
88
+ ]
89
+
90
+ @property({ type: String }) value?: string
91
+ @property({ type: Object }) column?: ColumnConfig
92
+ @property({ type: Object }) record?: GristRecord
93
+ @property({ type: Number }) row?: number
94
+ @property({ type: Object }) field?: any
95
+ @property({ type: Object }) _idRule?: any
96
+ @property({ type: Object }) headers?: { [header: string]: string }
97
+
98
+ @query('ox-input-code') ruleEditor!: OxInputCode
84
99
 
85
- static get properties() {
86
- return {
87
- value: String,
88
- column: Object,
89
- record: Object,
90
- row: Number,
91
- field: Object,
92
- _idRule: Object,
93
- headers: Object
94
- }
95
- }
96
100
  render() {
97
101
  return html`
98
102
  <div id="wrapper">
@@ -102,13 +106,14 @@ export class GristCodeInputPopup extends LitElement {
102
106
  <li><span>seed</span><ox-i18n msgid="label.argument seed description"></ox-i18n></li>
103
107
  </ul>
104
108
  <ox-input-code id="rule-editor" type="text" .value=${(this._idRule || {}).rule}></ox-input-code>
109
+
105
110
  <div id="footer">
106
- <mwc-button
107
- label=${i18next.t('button.save')}
108
- @click=${e => {
111
+ <md-elevated-button
112
+ label=${String(i18next.t('button.save'))}
113
+ @click=${(e: Event) => {
109
114
  this.updateIdRule()
110
115
  }}
111
- ></mwc-button>
116
+ ></md-elevated-button>
112
117
  </div>
113
118
  </div>
114
119
  `
@@ -117,15 +122,14 @@ export class GristCodeInputPopup extends LitElement {
117
122
  updated(changed) {
118
123
  if (changed.has('value')) {
119
124
  if (this.value && typeof this.value === 'string') {
120
- this.getRule(this.value)
125
+ this.getRule()
121
126
  }
122
127
  }
123
128
  }
124
129
 
125
130
  async getRule() {
126
131
  var response = await client.query({
127
- query: FETCH_ID_RULE_GQL(this.value),
128
- context: gqlContext()
132
+ query: FETCH_ID_RULE_GQL(this.value)
129
133
  })
130
134
 
131
135
  let idRule = response.data.idRule
@@ -153,8 +157,7 @@ export class GristCodeInputPopup extends LitElement {
153
157
  }
154
158
  }
155
159
  `,
156
- variables: { idRule },
157
- context: gqlContext()
160
+ variables: { idRule }
158
161
  })
159
162
  ).data?.createIdRule
160
163
  }
@@ -162,13 +165,12 @@ export class GristCodeInputPopup extends LitElement {
162
165
  async updateIdRule() {
163
166
  if (!this._idRule) console.error('ID Rule not found')
164
167
 
165
- const editor = this.renderRoot.querySelector('#rule-editor')
166
- const rule = editor.value
168
+ const rule = this.ruleEditor.value
167
169
 
168
170
  const type = this._idRule.type
169
171
 
170
172
  const patch = {
171
- ...this.idRule,
173
+ ...this._idRule,
172
174
  rule
173
175
  }
174
176
 
@@ -181,8 +183,7 @@ export class GristCodeInputPopup extends LitElement {
181
183
  }
182
184
  }
183
185
  `,
184
- variables: { type, patch },
185
- context: gqlContext()
186
+ variables: { type, patch }
186
187
  })
187
188
 
188
189
  this.dispatchEvent(
@@ -193,4 +194,3 @@ export class GristCodeInputPopup extends LitElement {
193
194
  )
194
195
  }
195
196
  }
196
- customElements.define('grist-code-input-popup', GristCodeInputPopup)
@@ -1,13 +1,17 @@
1
- import '@material/mwc-button'
2
- import { OxGristEditor } from '@operato/data-grist'
3
- import { i18next } from '@things-factory/i18n-base'
1
+ import '@material/web/icon/icon.js'
2
+
4
3
  import { css, html } from 'lit'
4
+ import { customElement, property } from 'lit/decorators.js'
5
+ import { OxGristEditor } from '@operato/data-grist'
6
+ import { i18next } from '@operato/i18n'
7
+ import { OxPopup } from '@operato/popup'
8
+
5
9
  import './grist-code-input-popup'
6
- import './id-rule-renderer'
7
10
 
11
+ @customElement('grist-code-input')
8
12
  export class GristCodeInput extends OxGristEditor {
9
- static get styles() {
10
- return css`
13
+ static styles = [
14
+ css`
11
15
  :host {
12
16
  display: flex;
13
17
  flex-flow: row nowrap;
@@ -28,14 +32,7 @@ export class GristCodeInput extends OxGristEditor {
28
32
  justify-content: inherit;
29
33
  }
30
34
 
31
- id-rule-renderer {
32
- display: flex;
33
- flex: auto;
34
-
35
- justify-content: inherit;
36
- }
37
-
38
- mwc-icon {
35
+ md-icon {
39
36
  width: 20px;
40
37
  font-size: 1.5em;
41
38
  }
@@ -55,15 +52,10 @@ export class GristCodeInput extends OxGristEditor {
55
52
  border: none;
56
53
  }
57
54
  `
58
- }
55
+ ]
59
56
 
60
- static get properties() {
61
- return {
62
- ...OxGristEditor.properties,
63
- headers: Object,
64
- popup: Object
65
- }
66
- }
57
+ @property({ type: Object }) headers?: Object
58
+ @property({ type: Object }) popup?: OxPopup | null
67
59
 
68
60
  render() {
69
61
  return html`
@@ -75,7 +67,8 @@ export class GristCodeInput extends OxGristEditor {
75
67
  .field=${this.column}
76
68
  .row=${this.row}
77
69
  ></input>
78
- <mwc-icon id="more" @click=${e => this.openPopup()}>more_vert</mwc-icon>
70
+
71
+ <md-icon id="more" @click=${e => this.openPopup()}>more_vert</md-icon>
79
72
  `
80
73
  }
81
74
 
@@ -110,7 +103,7 @@ export class GristCodeInput extends OxGristEditor {
110
103
  .field=${this.field}
111
104
  .headers=${this.headers}
112
105
  @close-popup=${e => {
113
- this.popup.close()
106
+ this.popup?.close()
114
107
  this.popup = null
115
108
  }}
116
109
  ></grist-code-input-popup>
@@ -126,4 +119,3 @@ export class GristCodeInput extends OxGristEditor {
126
119
  )
127
120
  }
128
121
  }
129
- customElements.define('grist-code-input', GristCodeInput)
@@ -0,0 +1 @@
1
+ export default function bootstrap(): void;
@@ -0,0 +1,7 @@
1
+ import { registerEditor } from '@operato/data-grist';
2
+ import { GristCodeInput } from './editors/grist-code-input';
3
+ export default function bootstrap() {
4
+ /* id-rule 의 GristRenderer는 텍스트와 같으므로, 별도로 정의하지 않음. */
5
+ registerEditor('id-rule', GristCodeInput);
6
+ }
7
+ //# sourceMappingURL=bootstrap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../client/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEpD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAE3D,MAAM,CAAC,OAAO,UAAU,SAAS;IAC/B,sDAAsD;IACtD,cAAc,CAAC,SAAS,EAAE,cAAc,CAAC,CAAA;AAC3C,CAAC","sourcesContent":["import { registerEditor } from '@operato/data-grist'\n\nimport { GristCodeInput } from './editors/grist-code-input'\n\nexport default function bootstrap() {\n /* id-rule 의 GristRenderer는 텍스트와 같으므로, 별도로 정의하지 않음. */\n registerEditor('id-rule', GristCodeInput)\n}\n"]}
@@ -0,0 +1,24 @@
1
+ import '@material/web/button/elevated-button.js';
2
+ import '@operato/i18n/ox-i18n.js';
3
+ import '@operato/input/ox-input-code.js';
4
+ import { LitElement } from 'lit';
5
+ import { ColumnConfig, GristRecord } from '@operato/data-grist';
6
+ import { OxInputCode } from '@operato/input';
7
+ export declare class GristCodeInputPopup extends LitElement {
8
+ static styles: import("lit").CSSResult[];
9
+ value?: string;
10
+ column?: ColumnConfig;
11
+ record?: GristRecord;
12
+ row?: number;
13
+ field?: any;
14
+ _idRule?: any;
15
+ headers?: {
16
+ [header: string]: string;
17
+ };
18
+ ruleEditor: OxInputCode;
19
+ render(): import("lit").TemplateResult<1>;
20
+ updated(changed: any): void;
21
+ getRule(): Promise<void>;
22
+ createIdRule(): Promise<any>;
23
+ updateIdRule(): Promise<void>;
24
+ }
@@ -0,0 +1,200 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import '@material/web/button/elevated-button.js';
3
+ import '@operato/i18n/ox-i18n.js';
4
+ import '@operato/input/ox-input-code.js';
5
+ import gql from 'graphql-tag';
6
+ import { css, html, LitElement } from 'lit';
7
+ import { customElement, property, query } from 'lit/decorators.js';
8
+ import { i18next } from '@operato/i18n';
9
+ import { client } from '@operato/graphql';
10
+ import { OxInputCode } from '@operato/input';
11
+ const FETCH_ID_RULE_GQL = type => {
12
+ return gql `
13
+ {
14
+ idRule(type:"${type}") {
15
+ id,
16
+ type,
17
+ rule
18
+ }
19
+ }
20
+ `;
21
+ };
22
+ let GristCodeInputPopup = class GristCodeInputPopup extends LitElement {
23
+ render() {
24
+ return html `
25
+ <div id="wrapper">
26
+ <h4><ox-i18n msgid="label.arguments"></ox-i18n></h4>
27
+ <ul>
28
+ <li><span>domain</span><ox-i18n msgid="label.argument domain description"></ox-i18n></li>
29
+ <li><span>seed</span><ox-i18n msgid="label.argument seed description"></ox-i18n></li>
30
+ </ul>
31
+ <ox-input-code id="rule-editor" type="text" .value=${(this._idRule || {}).rule}></ox-input-code>
32
+
33
+ <div id="footer">
34
+ <md-elevated-button
35
+ label=${String(i18next.t('button.save'))}
36
+ @click=${(e) => {
37
+ this.updateIdRule();
38
+ }}
39
+ ></md-elevated-button>
40
+ </div>
41
+ </div>
42
+ `;
43
+ }
44
+ updated(changed) {
45
+ if (changed.has('value')) {
46
+ if (this.value && typeof this.value === 'string') {
47
+ this.getRule();
48
+ }
49
+ }
50
+ }
51
+ async getRule() {
52
+ var response = await client.query({
53
+ query: FETCH_ID_RULE_GQL(this.value)
54
+ });
55
+ let idRule = response.data.idRule;
56
+ if (!idRule) {
57
+ idRule = await this.createIdRule();
58
+ }
59
+ this._idRule = idRule;
60
+ this.requestUpdate();
61
+ }
62
+ async createIdRule() {
63
+ var _a;
64
+ var idRule = {
65
+ type: this.value,
66
+ rule: `return ''`
67
+ };
68
+ return (_a = (await client.mutate({
69
+ mutation: gql `
70
+ mutation createIdRule($idRule: NewIdRule!) {
71
+ createIdRule(idRule: $idRule) {
72
+ type
73
+ rule
74
+ }
75
+ }
76
+ `,
77
+ variables: { idRule }
78
+ })).data) === null || _a === void 0 ? void 0 : _a.createIdRule;
79
+ }
80
+ async updateIdRule() {
81
+ if (!this._idRule)
82
+ console.error('ID Rule not found');
83
+ const rule = this.ruleEditor.value;
84
+ const type = this._idRule.type;
85
+ const patch = Object.assign(Object.assign({}, this._idRule), { rule });
86
+ await client.mutate({
87
+ mutation: gql `
88
+ mutation updateIdRule($type: String!, $patch: IdRulePatch!) {
89
+ updateIdRule(type: $type, patch: $patch) {
90
+ type
91
+ rule
92
+ }
93
+ }
94
+ `,
95
+ variables: { type, patch }
96
+ });
97
+ this.dispatchEvent(new CustomEvent('close-popup', {
98
+ bubbles: true,
99
+ composed: true
100
+ }));
101
+ }
102
+ };
103
+ GristCodeInputPopup.styles = [
104
+ css `
105
+ :host {
106
+ display: flex;
107
+ flex-direction: column;
108
+ padding: 0;
109
+ align-items: center;
110
+ box-sizing: border-box;
111
+ width: 100%;
112
+ border: 0;
113
+ background-color: var(--popup-content-background-color);
114
+
115
+ font: var(--grist-object-editor-font);
116
+ color: var(--grist-object-editor-color);
117
+
118
+ justify-content: inherit;
119
+ }
120
+
121
+ :host * {
122
+ box-sizing: border-box;
123
+ }
124
+
125
+ #wrapper {
126
+ flex: 1;
127
+ width: 100%;
128
+ display: flex;
129
+ flex-direction: column;
130
+ padding: 5px;
131
+ }
132
+
133
+ #wrapper > h4 {
134
+ margin: 0;
135
+ }
136
+
137
+ #wrapper > ul {
138
+ width: 100%;
139
+ }
140
+
141
+ #wrapper > ul > li {
142
+ display: flex;
143
+ }
144
+ #wrapper > ul > li > span {
145
+ font-weight: bold;
146
+ flex-basis: 200px;
147
+ }
148
+
149
+ #wrapper > ul > li > ox-i18n {
150
+ flex: 1;
151
+ }
152
+
153
+ ox-input-code {
154
+ width: 100%;
155
+ flex: 1;
156
+ }
157
+
158
+ #footer {
159
+ display: flex;
160
+ justify-content: flex-end;
161
+ }
162
+ `
163
+ ];
164
+ __decorate([
165
+ property({ type: String }),
166
+ __metadata("design:type", String)
167
+ ], GristCodeInputPopup.prototype, "value", void 0);
168
+ __decorate([
169
+ property({ type: Object }),
170
+ __metadata("design:type", Object)
171
+ ], GristCodeInputPopup.prototype, "column", void 0);
172
+ __decorate([
173
+ property({ type: Object }),
174
+ __metadata("design:type", Object)
175
+ ], GristCodeInputPopup.prototype, "record", void 0);
176
+ __decorate([
177
+ property({ type: Number }),
178
+ __metadata("design:type", Number)
179
+ ], GristCodeInputPopup.prototype, "row", void 0);
180
+ __decorate([
181
+ property({ type: Object }),
182
+ __metadata("design:type", Object)
183
+ ], GristCodeInputPopup.prototype, "field", void 0);
184
+ __decorate([
185
+ property({ type: Object }),
186
+ __metadata("design:type", Object)
187
+ ], GristCodeInputPopup.prototype, "_idRule", void 0);
188
+ __decorate([
189
+ property({ type: Object }),
190
+ __metadata("design:type", Object)
191
+ ], GristCodeInputPopup.prototype, "headers", void 0);
192
+ __decorate([
193
+ query('ox-input-code'),
194
+ __metadata("design:type", OxInputCode)
195
+ ], GristCodeInputPopup.prototype, "ruleEditor", void 0);
196
+ GristCodeInputPopup = __decorate([
197
+ customElement('grist-code-input-popup')
198
+ ], GristCodeInputPopup);
199
+ export { GristCodeInputPopup };
200
+ //# sourceMappingURL=grist-code-input-popup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grist-code-input-popup.js","sourceRoot":"","sources":["../../client/editors/grist-code-input-popup.ts"],"names":[],"mappings":"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","sourcesContent":["import '@material/web/button/elevated-button.js'\nimport '@operato/i18n/ox-i18n.js'\nimport '@operato/input/ox-input-code.js'\n\nimport gql from 'graphql-tag'\nimport { css, html, LitElement } from 'lit'\nimport { customElement, property, query, state } from 'lit/decorators.js'\n\nimport { i18next } from '@operato/i18n'\nimport { client } from '@operato/graphql'\nimport { ColumnConfig, GristRecord } from '@operato/data-grist'\nimport { OxInputCode } from '@operato/input'\n\nconst FETCH_ID_RULE_GQL = type => {\n return gql`\n {\n idRule(type:\"${type}\") {\n id,\n type,\n rule\n }\n }\n`\n}\n\n@customElement('grist-code-input-popup')\nexport class GristCodeInputPopup extends LitElement {\n static styles = [\n css`\n :host {\n display: flex;\n flex-direction: column;\n padding: 0;\n align-items: center;\n box-sizing: border-box;\n width: 100%;\n border: 0;\n background-color: var(--popup-content-background-color);\n\n font: var(--grist-object-editor-font);\n color: var(--grist-object-editor-color);\n\n justify-content: inherit;\n }\n\n :host * {\n box-sizing: border-box;\n }\n\n #wrapper {\n flex: 1;\n width: 100%;\n display: flex;\n flex-direction: column;\n padding: 5px;\n }\n\n #wrapper > h4 {\n margin: 0;\n }\n\n #wrapper > ul {\n width: 100%;\n }\n\n #wrapper > ul > li {\n display: flex;\n }\n #wrapper > ul > li > span {\n font-weight: bold;\n flex-basis: 200px;\n }\n\n #wrapper > ul > li > ox-i18n {\n flex: 1;\n }\n\n ox-input-code {\n width: 100%;\n flex: 1;\n }\n\n #footer {\n display: flex;\n justify-content: flex-end;\n }\n `\n ]\n\n @property({ type: String }) value?: string\n @property({ type: Object }) column?: ColumnConfig\n @property({ type: Object }) record?: GristRecord\n @property({ type: Number }) row?: number\n @property({ type: Object }) field?: any\n @property({ type: Object }) _idRule?: any\n @property({ type: Object }) headers?: { [header: string]: string }\n\n @query('ox-input-code') ruleEditor!: OxInputCode\n\n render() {\n return html`\n <div id=\"wrapper\">\n <h4><ox-i18n msgid=\"label.arguments\"></ox-i18n></h4>\n <ul>\n <li><span>domain</span><ox-i18n msgid=\"label.argument domain description\"></ox-i18n></li>\n <li><span>seed</span><ox-i18n msgid=\"label.argument seed description\"></ox-i18n></li>\n </ul>\n <ox-input-code id=\"rule-editor\" type=\"text\" .value=${(this._idRule || {}).rule}></ox-input-code>\n\n <div id=\"footer\">\n <md-elevated-button\n label=${String(i18next.t('button.save'))}\n @click=${(e: Event) => {\n this.updateIdRule()\n }}\n ></md-elevated-button>\n </div>\n </div>\n `\n }\n\n updated(changed) {\n if (changed.has('value')) {\n if (this.value && typeof this.value === 'string') {\n this.getRule()\n }\n }\n }\n\n async getRule() {\n var response = await client.query({\n query: FETCH_ID_RULE_GQL(this.value)\n })\n\n let idRule = response.data.idRule\n if (!idRule) {\n idRule = await this.createIdRule()\n }\n\n this._idRule = idRule\n this.requestUpdate()\n }\n\n async createIdRule() {\n var idRule = {\n type: this.value,\n rule: `return ''`\n }\n\n return (\n await client.mutate({\n mutation: gql`\n mutation createIdRule($idRule: NewIdRule!) {\n createIdRule(idRule: $idRule) {\n type\n rule\n }\n }\n `,\n variables: { idRule }\n })\n ).data?.createIdRule\n }\n\n async updateIdRule() {\n if (!this._idRule) console.error('ID Rule not found')\n\n const rule = this.ruleEditor.value\n\n const type = this._idRule.type\n\n const patch = {\n ...this._idRule,\n rule\n }\n\n await client.mutate({\n mutation: gql`\n mutation updateIdRule($type: String!, $patch: IdRulePatch!) {\n updateIdRule(type: $type, patch: $patch) {\n type\n rule\n }\n }\n `,\n variables: { type, patch }\n })\n\n this.dispatchEvent(\n new CustomEvent('close-popup', {\n bubbles: true,\n composed: true\n })\n )\n }\n}\n"]}
@@ -0,0 +1,12 @@
1
+ import '@material/web/icon/icon.js';
2
+ import { OxGristEditor } from '@operato/data-grist';
3
+ import { OxPopup } from '@operato/popup';
4
+ import './grist-code-input-popup';
5
+ export declare class GristCodeInput extends OxGristEditor {
6
+ static styles: import("lit").CSSResult[];
7
+ headers?: Object;
8
+ popup?: OxPopup | null;
9
+ render(): import("lit").TemplateResult<1>;
10
+ firstUpdated(): Promise<void>;
11
+ openPopup(): void;
12
+ }
@@ -0,0 +1,119 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import '@material/web/icon/icon.js';
3
+ import { css, html } from 'lit';
4
+ import { customElement, property } from 'lit/decorators.js';
5
+ import { OxGristEditor } from '@operato/data-grist';
6
+ import { i18next } from '@operato/i18n';
7
+ import './grist-code-input-popup';
8
+ let GristCodeInput = class GristCodeInput extends OxGristEditor {
9
+ render() {
10
+ return html `
11
+ <input
12
+ type="text"
13
+ .value=${this.value}
14
+ .record=${this.record}
15
+ .column=${this.column}
16
+ .field=${this.column}
17
+ .row=${this.row}
18
+ ></input>
19
+
20
+ <md-icon id="more" @click=${e => this.openPopup()}>more_vert</md-icon>
21
+ `;
22
+ }
23
+ async firstUpdated() {
24
+ await this.updateComplete;
25
+ await super.firstUpdated();
26
+ }
27
+ openPopup() {
28
+ if (this.record.__dirty__) {
29
+ document.dispatchEvent(new CustomEvent('notify', {
30
+ detail: {
31
+ level: 'error',
32
+ message: i18next.t('text.please_save_your_modifications_first')
33
+ }
34
+ }));
35
+ return;
36
+ }
37
+ document.dispatchEvent(new CustomEvent('open-popup', {
38
+ detail: {
39
+ template: html `
40
+ <grist-code-input-popup
41
+ .value=${this.value}
42
+ .column=${this.column}
43
+ .record=${this.record}
44
+ .row=${this.row}
45
+ .field=${this.field}
46
+ .headers=${this.headers}
47
+ @close-popup=${e => {
48
+ var _a;
49
+ (_a = this.popup) === null || _a === void 0 ? void 0 : _a.close();
50
+ this.popup = null;
51
+ }}
52
+ ></grist-code-input-popup>
53
+ `,
54
+ options: {
55
+ title: i18next.t('title.ID Rule Editor')
56
+ },
57
+ callback: popup => {
58
+ this.popup = popup;
59
+ }
60
+ }
61
+ }));
62
+ }
63
+ };
64
+ GristCodeInput.styles = [
65
+ css `
66
+ :host {
67
+ display: flex;
68
+ flex-flow: row nowrap;
69
+ align-items: center;
70
+
71
+ padding: 7px 0px;
72
+ box-sizing: border-box;
73
+
74
+ width: 100%;
75
+ height: 100%;
76
+
77
+ border: 0;
78
+ background-color: transparent;
79
+
80
+ font: var(--grist-object-editor-font);
81
+ color: var(--grist-object-editor-color);
82
+
83
+ justify-content: inherit;
84
+ }
85
+
86
+ md-icon {
87
+ width: 20px;
88
+ font-size: 1.5em;
89
+ }
90
+
91
+ #popup {
92
+ display: flex;
93
+ overflow: hidden;
94
+ }
95
+
96
+ input {
97
+ border: none;
98
+ background-color: transparent;
99
+ }
100
+
101
+ input:focus {
102
+ outline: none;
103
+ border: none;
104
+ }
105
+ `
106
+ ];
107
+ __decorate([
108
+ property({ type: Object }),
109
+ __metadata("design:type", Object)
110
+ ], GristCodeInput.prototype, "headers", void 0);
111
+ __decorate([
112
+ property({ type: Object }),
113
+ __metadata("design:type", Object)
114
+ ], GristCodeInput.prototype, "popup", void 0);
115
+ GristCodeInput = __decorate([
116
+ customElement('grist-code-input')
117
+ ], GristCodeInput);
118
+ export { GristCodeInput };
119
+ //# sourceMappingURL=grist-code-input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grist-code-input.js","sourceRoot":"","sources":["../../client/editors/grist-code-input.ts"],"names":[],"mappings":";AAAA,OAAO,4BAA4B,CAAA;AAEnC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAC/B,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAGvC,OAAO,0BAA0B,CAAA;AAG1B,IAAM,cAAc,GAApB,MAAM,cAAe,SAAQ,aAAa;IAgD/C,MAAM;QACJ,OAAO,IAAI,CAAA;;;iBAGE,IAAI,CAAC,KAAK;kBACT,IAAI,CAAC,MAAM;kBACX,IAAI,CAAC,MAAM;iBACZ,IAAI,CAAC,MAAM;eACb,IAAI,CAAC,GAAG;;;kCAGW,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE;KAClD,CAAA;IACH,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,cAAc,CAAA;QACzB,MAAM,KAAK,CAAC,YAAY,EAAE,CAAA;IAC5B,CAAC;IAED,SAAS;QACP,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;YACzB,QAAQ,CAAC,aAAa,CACpB,IAAI,WAAW,CAAC,QAAQ,EAAE;gBACxB,MAAM,EAAE;oBACN,KAAK,EAAE,OAAO;oBACd,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,2CAA2C,CAAC;iBAChE;aACF,CAAC,CACH,CAAA;YAED,OAAM;SACP;QAED,QAAQ,CAAC,aAAa,CACpB,IAAI,WAAW,CAAC,YAAY,EAAE;YAC5B,MAAM,EAAE;gBACN,QAAQ,EAAE,IAAI,CAAA;;uBAED,IAAI,CAAC,KAAK;wBACT,IAAI,CAAC,MAAM;wBACX,IAAI,CAAC,MAAM;qBACd,IAAI,CAAC,GAAG;uBACN,IAAI,CAAC,KAAK;yBACR,IAAI,CAAC,OAAO;6BACR,CAAC,CAAC,EAAE;;oBACjB,MAAA,IAAI,CAAC,KAAK,0CAAE,KAAK,EAAE,CAAA;oBACnB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAA;gBACnB,CAAC;;WAEJ;gBACD,OAAO,EAAE;oBACP,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,sBAAsB,CAAC;iBACzC;gBACD,QAAQ,EAAE,KAAK,CAAC,EAAE;oBAChB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;gBACpB,CAAC;aACF;SACF,CAAC,CACH,CAAA;IACH,CAAC;;AA3GM,qBAAM,GAAG;IACd,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAwCF;CACF,CAAA;AAED;IAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;8BAAW,MAAM;+CAAA;AAC5C;IAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;6CAAuB;AA9CvC,cAAc;IAD1B,aAAa,CAAC,kBAAkB,CAAC;GACrB,cAAc,CA6G1B;SA7GY,cAAc","sourcesContent":["import '@material/web/icon/icon.js'\n\nimport { css, html } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\nimport { OxGristEditor } from '@operato/data-grist'\nimport { i18next } from '@operato/i18n'\nimport { OxPopup } from '@operato/popup'\n\nimport './grist-code-input-popup'\n\n@customElement('grist-code-input')\nexport class GristCodeInput extends OxGristEditor {\n static styles = [\n 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 md-icon {\n width: 20px;\n font-size: 1.5em;\n }\n\n #popup {\n display: flex;\n overflow: hidden;\n }\n\n input {\n border: none;\n background-color: transparent;\n }\n\n input:focus {\n outline: none;\n border: none;\n }\n `\n ]\n\n @property({ type: Object }) headers?: Object\n @property({ type: Object }) popup?: OxPopup | null\n\n render() {\n return html`\n <input\n type=\"text\"\n .value=${this.value}\n .record=${this.record}\n .column=${this.column}\n .field=${this.column}\n .row=${this.row}\n ></input>\n\n <md-icon id=\"more\" @click=${e => this.openPopup()}>more_vert</md-icon>\n `\n }\n\n async firstUpdated() {\n await this.updateComplete\n await super.firstUpdated()\n }\n\n openPopup() {\n if (this.record.__dirty__) {\n document.dispatchEvent(\n new CustomEvent('notify', {\n detail: {\n level: 'error',\n message: i18next.t('text.please_save_your_modifications_first')\n }\n })\n )\n\n return\n }\n\n document.dispatchEvent(\n new CustomEvent('open-popup', {\n detail: {\n template: html`\n <grist-code-input-popup\n .value=${this.value}\n .column=${this.column}\n .record=${this.record}\n .row=${this.row}\n .field=${this.field}\n .headers=${this.headers}\n @close-popup=${e => {\n this.popup?.close()\n this.popup = null\n }}\n ></grist-code-input-popup>\n `,\n options: {\n title: i18next.t('title.ID Rule Editor')\n },\n callback: popup => {\n this.popup = popup\n }\n }\n })\n )\n }\n}\n"]}
File without changes
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../client/index.ts"],"names":[],"mappings":"","sourcesContent":[""]}