@operato/grist-editor 1.0.0-alpha.9 → 1.0.0-beta.39

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.
Files changed (87) hide show
  1. package/.storybook/main.js +2 -2
  2. package/.storybook/server.mjs +4 -4
  3. package/LICENSE +2 -2
  4. package/README.md +29 -9
  5. package/dist/src/index.js +15 -1
  6. package/package.json +36 -26
  7. package/src/index.ts +18 -0
  8. package/src/ox-grist-editor-crontab.ts +62 -0
  9. package/src/ox-grist-editor-duration.ts +62 -0
  10. package/src/{parameters/parameters-editor.ts → ox-grist-editor-parameters.ts} +14 -27
  11. package/src/ox-grist-editor-partition-keys.ts +86 -0
  12. package/src/ox-grist-editor-value-map.ts +86 -0
  13. package/src/ox-grist-renderer-crontab.ts +31 -0
  14. package/src/{parameters/parameters-editor-builder.ts → ox-parameters-builder.ts} +6 -10
  15. package/src/ox-popup-crontab-input.ts +75 -0
  16. package/src/ox-popup-duration-input.ts +75 -0
  17. package/src/{parameters/parameters-editor-popup.ts → ox-popup-parameters-builder.ts} +10 -9
  18. package/src/ox-popup-partition-keys-input.ts +97 -0
  19. package/src/ox-popup-value-map-input.ts +102 -0
  20. package/stories/ox-grist-editor-crontab.stories.ts +429 -0
  21. package/themes/app-theme.css +142 -0
  22. package/themes/form-theme.css +75 -0
  23. package/themes/grist-theme.css +194 -0
  24. package/themes/oops-theme.css +26 -0
  25. package/themes/report-theme.css +47 -0
  26. package/translations/en.json +3 -0
  27. package/translations/ko.json +3 -0
  28. package/translations/ms.json +3 -0
  29. package/translations/zh.json +3 -0
  30. package/web-dev-server.config.mjs +9 -8
  31. package/web-test-runner.config.mjs +7 -19
  32. package/.editorconfig +0 -29
  33. package/CHANGELOG.md +0 -11
  34. package/demo/data-grist-test.html +0 -456
  35. package/demo/index.html +0 -33
  36. package/dist/src/code/code-editor.d.ts +0 -6
  37. package/dist/src/code/code-editor.js +0 -50
  38. package/dist/src/code/code-editor.js.map +0 -1
  39. package/dist/src/code/index.d.ts +0 -1
  40. package/dist/src/code/index.js +0 -5
  41. package/dist/src/code/index.js.map +0 -1
  42. package/dist/src/id/id-input.d.ts +0 -19
  43. package/dist/src/id/id-input.js +0 -119
  44. package/dist/src/id/id-input.js.map +0 -1
  45. package/dist/src/id/id-renderer.d.ts +0 -2
  46. package/dist/src/id/id-renderer.js +0 -9
  47. package/dist/src/id/id-renderer.js.map +0 -1
  48. package/dist/src/id/id-selector.d.ts +0 -23
  49. package/dist/src/id/id-selector.js +0 -197
  50. package/dist/src/id/id-selector.js.map +0 -1
  51. package/dist/src/id/index.d.ts +0 -1
  52. package/dist/src/id/index.js +0 -7
  53. package/dist/src/id/index.js.map +0 -1
  54. package/dist/src/index.d.ts +0 -0
  55. package/dist/src/index.js.map +0 -1
  56. package/dist/src/object/index.d.ts +0 -1
  57. package/dist/src/object/index.js +0 -6
  58. package/dist/src/object/index.js.map +0 -1
  59. package/dist/src/object/object-editor.d.ts +0 -18
  60. package/dist/src/object/object-editor.js +0 -152
  61. package/dist/src/object/object-editor.js.map +0 -1
  62. package/dist/src/object/object-selector.d.ts +0 -38
  63. package/dist/src/object/object-selector.js +0 -338
  64. package/dist/src/object/object-selector.js.map +0 -1
  65. package/dist/src/parameters/index.d.ts +0 -1
  66. package/dist/src/parameters/index.js +0 -6
  67. package/dist/src/parameters/index.js.map +0 -1
  68. package/dist/src/parameters/parameters-editor-builder.d.ts +0 -4
  69. package/dist/src/parameters/parameters-editor-builder.js +0 -119
  70. package/dist/src/parameters/parameters-editor-builder.js.map +0 -1
  71. package/dist/src/parameters/parameters-editor-popup.d.ts +0 -13
  72. package/dist/src/parameters/parameters-editor-popup.js +0 -111
  73. package/dist/src/parameters/parameters-editor-popup.js.map +0 -1
  74. package/dist/src/parameters/parameters-editor.d.ts +0 -18
  75. package/dist/src/parameters/parameters-editor.js +0 -106
  76. package/dist/src/parameters/parameters-editor.js.map +0 -1
  77. package/dist/tsconfig.tsbuildinfo +0 -1
  78. package/src/code/code-editor.ts +0 -78
  79. package/src/code/index.ts +0 -6
  80. package/src/id/id-input.ts +0 -135
  81. package/src/id/id-renderer.ts +0 -12
  82. package/src/id/id-selector.ts +0 -189
  83. package/src/id/index.ts +0 -8
  84. package/src/object/index.ts +0 -8
  85. package/src/object/object-editor.ts +0 -162
  86. package/src/object/object-selector.ts +0 -346
  87. package/src/parameters/index.ts +0 -8
@@ -1,3 +1,3 @@
1
1
  module.exports = {
2
- stories: ['../dist/stories/**/*.stories.{js,md,mdx}'],
3
- };
2
+ stories: ['../dist/stories/**/*.stories.{js,md,mdx}']
3
+ }
@@ -1,8 +1,8 @@
1
- import { storybookPlugin } from '@web/dev-server-storybook';
2
- import baseConfig from '../web-dev-server.config.mjs';
1
+ import { storybookPlugin } from '@web/dev-server-storybook'
2
+ import baseConfig from '../web-dev-server.config.mjs'
3
3
 
4
4
  export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
5
5
  ...baseConfig,
6
6
  open: '/',
7
- plugins: [storybookPlugin({ type: 'web-components' }), ...baseConfig.plugins],
8
- });
7
+ plugins: [storybookPlugin({ type: 'web-components' }), ...baseConfig.plugins]
8
+ })
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) hatiolab.com
3
+ Copyright (c) Hatiolab Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,46 +1,66 @@
1
- # \<mini-app>
1
+ # \<grist-editor>
2
2
 
3
3
  This webcomponent follows the [open-wc](https://github.com/open-wc/open-wc) recommendation.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm i mini-app
8
+ npm i grist-editor
9
9
  ```
10
10
 
11
11
  ## Usage
12
12
 
13
13
  ```html
14
14
  <script type="module">
15
- import 'mini-app/mini-app.js'
15
+ import 'grist-editor/grist-editor.js'
16
16
  </script>
17
17
 
18
- <mini-app></mini-app>
18
+ <grist-editor></grist-editor>
19
19
  ```
20
20
 
21
- ## Linting and formatting
21
+ ## Linting with ESLint, Prettier, and Types
22
22
 
23
- To scan the project for linting and formatting errors, run
23
+ To scan the project for linting errors, run
24
24
 
25
25
  ```bash
26
26
  npm run lint
27
27
  ```
28
28
 
29
- To automatically fix linting and formatting errors, run
29
+ You can lint with ESLint and Prettier individually as well
30
+
31
+ ```bash
32
+ npm run lint:eslint
33
+ ```
34
+
35
+ ```bash
36
+ npm run lint:prettier
37
+ ```
38
+
39
+ To automatically fix many linting errors, run
30
40
 
31
41
  ```bash
32
42
  npm run format
33
43
  ```
34
44
 
45
+ You can format using ESLint and Prettier individually as well
46
+
47
+ ```bash
48
+ npm run format:eslint
49
+ ```
50
+
51
+ ```bash
52
+ npm run format:prettier
53
+ ```
54
+
35
55
  ## Testing with Web Test Runner
36
56
 
37
- To execute a single test run:
57
+ To run the suite of Web Test Runner tests, run
38
58
 
39
59
  ```bash
40
60
  npm run test
41
61
  ```
42
62
 
43
- To run the tests in interactive watch mode run:
63
+ To run the tests in watch mode (for &lt;abbr title=&#34;test driven development&#34;&gt;TDD&lt;/abbr&gt;, for example), run
44
64
 
45
65
  ```bash
46
66
  npm run test:watch
package/dist/src/index.js CHANGED
@@ -1,2 +1,16 @@
1
- "use strict";
1
+ import { OxGristRendererJson5, registerEditor, registerRenderer } from '@operato/data-grist';
2
+ import { OxGristEditorCrontab } from './ox-grist-editor-crontab.js';
3
+ import { OxGristEditorDuration } from './ox-grist-editor-duration.js';
4
+ import { OxGristEditorParameters } from './ox-grist-editor-parameters.js';
5
+ import { OxGristEditorPartitionKeys } from './ox-grist-editor-partition-keys.js';
6
+ import { OxGristEditorValueMap } from './ox-grist-editor-value-map.js';
7
+ /* register grist renderer/editor for id */
8
+ registerEditor('parameters', OxGristEditorParameters);
9
+ registerEditor('value-map', OxGristEditorValueMap);
10
+ registerEditor('partition-keys', OxGristEditorPartitionKeys);
11
+ registerEditor('crontab', OxGristEditorCrontab);
12
+ registerEditor('duration', OxGristEditorDuration);
13
+ registerRenderer('parameters', OxGristRendererJson5);
14
+ registerRenderer('value-map', OxGristRendererJson5);
15
+ registerRenderer('partition-keys', OxGristRendererJson5);
2
16
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,20 +1,11 @@
1
1
  {
2
2
  "name": "@operato/grist-editor",
3
+ "version": "1.0.0-beta.39",
3
4
  "description": "Webcomponent for grist-editor following open-wc recommendations",
4
- "license": "MIT",
5
5
  "author": "heartyoh",
6
- "version": "1.0.0-alpha.9",
6
+ "license": "MIT",
7
7
  "main": "dist/src/index.js",
8
8
  "module": "dist/src/index.js",
9
- "exports": {
10
- ".": "./dist/src/index.js",
11
- "./id/id-input.js": "./dist/src/id/id-input.js",
12
- "./id/id-selector.js": "./dist/src/id/id-selector.js",
13
- "./id/id-renderer.js": "./dist/src/id/id-renderer.js",
14
- "./object/object-selector.js": "./dist/src/object/object-selector.js",
15
- "./object/object-renderer.js": "./dist/src/object/object-renderer.js",
16
- "./code/code-editor.js": "./dist/src/code/code-editor.js"
17
- },
18
9
  "publishConfig": {
19
10
  "access": "public",
20
11
  "@operato:registry": "https://registry.npmjs.org"
@@ -24,6 +15,19 @@
24
15
  "url": "git+https://github.com/hatiolab/operato.git",
25
16
  "directory": "webcomponents/grist-editor"
26
17
  },
18
+ "exports": {
19
+ ".": "./dist/src/index.js",
20
+ "./ox-grist-editor-duration.js": "./dist/src/ox-grist-editor-duration.js",
21
+ "./ox-grist-editor-crontab.js": "./dist/src/ox-grist-editor-crontab.js",
22
+ "./ox-grist-renderer-crontab.js": "./dist/src/ox-grist-renderer-crontab.js",
23
+ "./ox-grist-editor-json.js": "./dist/src/ox-grist-editor-json.js",
24
+ "./ox-grist-editor-code.js": "./dist/src/ox-grist-editor-code.js",
25
+ "./ox-grist-editor-resource-object.js": "./dist/src/ox-grist-editor-resource-object.js",
26
+ "./ox-grist-editor-resource-code.js": "./dist/src/ox-grist-editor-resource-code.js",
27
+ "./ox-grist-editor-parameters.js": "./dist/src/ox-grist-editor-parameters.js",
28
+ "./ox-grist-editor-value-map.js": "./dist/src/ox-grist-editor-value-map.js",
29
+ "./ox-grist-editor-partition-keys.js": "./dist/src/ox-grist-editor-partition-keys.js"
30
+ },
27
31
  "scripts": {
28
32
  "analyze": "cem analyze --litelement",
29
33
  "start": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds\"",
@@ -40,31 +44,38 @@
40
44
  "@material/mwc-button": "^0.25.3",
41
45
  "@material/mwc-icon": "^0.25.3",
42
46
  "@material/mwc-icon-button": "^0.25.3",
43
- "@operato/data-grist": "^1.0.0-alpha.9",
44
- "@operato/form": "^1.0.0-alpha.9",
45
- "@operato/graphql": "^1.0.0-alpha.9",
46
- "@operato/i18n": "^1.0.0-alpha.9",
47
- "@operato/layout": "^1.0.0-alpha.9",
48
- "@operato/property-editor": "^1.0.0-alpha.9",
49
- "@operato/shell": "^1.0.0-alpha.9",
50
- "@operato/styles": "^1.0.0-alpha.9",
51
- "@operato/utils": "^1.0.0-alpha.9",
52
- "lit": "^2.2.0"
47
+ "@operato/data-grist": "^1.0.0-beta.39",
48
+ "@operato/help": "^1.0.0-beta.39",
49
+ "@operato/i18n": "^1.0.0-beta.39",
50
+ "@operato/input": "^1.0.0-beta.39",
51
+ "@operato/popup": "^1.0.0-beta.39",
52
+ "@operato/styles": "^1.0.0-beta.39",
53
+ "codemirror": "^5.64.0",
54
+ "codemirror-graphql": "^0.15.2",
55
+ "cronstrue": "^2.2.0",
56
+ "cross-fetch": "^3.1.5",
57
+ "lit": "^2.2.1",
58
+ "lodash-es": "^4.17.21"
53
59
  },
54
60
  "devDependencies": {
55
61
  "@custom-elements-manifest/analyzer": "^0.4.17",
56
62
  "@hatiolab/prettier-config": "^1.0.0",
63
+ "@material/mwc-fab": "^0.25.3",
64
+ "@material/mwc-icon": "^0.25.3",
57
65
  "@open-wc/eslint-config": "^4.3.0",
58
66
  "@open-wc/testing": "^3.0.4",
67
+ "@types/bwip-js": "^2.1.1",
68
+ "@types/lodash-es": "^4.17.5",
69
+ "@types/w3c-web-usb": "^1.0.5",
59
70
  "@typescript-eslint/eslint-plugin": "^4.33.0",
60
71
  "@typescript-eslint/parser": "^4.33.0",
61
72
  "@web/dev-server": "^0.1.29",
62
- "@web/dev-server-storybook": "next",
73
+ "@web/dev-server-storybook": "^0.5.0",
63
74
  "@web/test-runner": "next",
64
75
  "concurrently": "^5.3.0",
65
76
  "eslint": "^7.32.0",
66
77
  "eslint-config-prettier": "^8.3.0",
67
- "husky": "^4.3.8",
78
+ "husky": "^7.0.2",
68
79
  "lint-staged": "^10.5.4",
69
80
  "prettier": "^2.4.1",
70
81
  "tslib": "^2.3.1",
@@ -82,6 +93,5 @@
82
93
  "eslint --fix",
83
94
  "prettier --write"
84
95
  ]
85
- },
86
- "gitHead": "fb82c87ab8b869139076c4e74c46309460b67d35"
87
- }
96
+ }
97
+ }
package/src/index.ts CHANGED
@@ -0,0 +1,18 @@
1
+ import { OxGristRendererJson5, registerEditor, registerRenderer } from '@operato/data-grist'
2
+
3
+ import { OxGristEditorCrontab } from './ox-grist-editor-crontab.js'
4
+ import { OxGristEditorDuration } from './ox-grist-editor-duration.js'
5
+ import { OxGristEditorParameters } from './ox-grist-editor-parameters.js'
6
+ import { OxGristEditorPartitionKeys } from './ox-grist-editor-partition-keys.js'
7
+ import { OxGristEditorValueMap } from './ox-grist-editor-value-map.js'
8
+
9
+ /* register grist renderer/editor for id */
10
+ registerEditor('parameters', OxGristEditorParameters)
11
+ registerEditor('value-map', OxGristEditorValueMap)
12
+ registerEditor('partition-keys', OxGristEditorPartitionKeys)
13
+ registerEditor('crontab', OxGristEditorCrontab)
14
+ registerEditor('duration', OxGristEditorDuration)
15
+
16
+ registerRenderer('parameters', OxGristRendererJson5)
17
+ registerRenderer('value-map', OxGristRendererJson5)
18
+ registerRenderer('partition-keys', OxGristRendererJson5)
@@ -0,0 +1,62 @@
1
+ import './ox-popup-crontab-input.js'
2
+
3
+ import { html } from 'lit'
4
+ import { customElement } from 'lit/decorators.js'
5
+
6
+ import { OxGristEditor } from '@operato/data-grist'
7
+ import { i18next } from '@operato/i18n'
8
+ import { openPopup, PopupHandle } from '@operato/popup'
9
+
10
+ @customElement('ox-grist-editor-crontab')
11
+ export class OxGristEditorCrontab extends OxGristEditor {
12
+ private popup?: PopupHandle
13
+
14
+ get editorTemplate() {
15
+ return html` <input type="text" .value=${this.value || ''} /> `
16
+ }
17
+
18
+ async firstUpdated() {
19
+ await this.updateComplete
20
+
21
+ this.renderRoot.addEventListener('click', e => {
22
+ e.stopPropagation()
23
+
24
+ this.showEditorPopup()
25
+ })
26
+
27
+ this.showEditorPopup()
28
+ }
29
+
30
+ showEditorPopup() {
31
+ if (this.popup) {
32
+ delete this.popup
33
+ }
34
+
35
+ const confirmCallback = (newval: any) => {
36
+ this.dispatchEvent(
37
+ new CustomEvent('field-change', {
38
+ bubbles: true,
39
+ composed: true,
40
+ detail: {
41
+ before: this.value,
42
+ after: newval,
43
+ record: this.record,
44
+ column: this.column,
45
+ row: this.row
46
+ }
47
+ })
48
+ )
49
+ }
50
+
51
+ this.popup = openPopup(
52
+ html`
53
+ <ox-popup-crontab-input .value=${this.value} .confirmCallback=${confirmCallback}></ox-popup-crontab-input>
54
+ `,
55
+ {
56
+ backdrop: true,
57
+ title: i18next.t('title.setting schedule'),
58
+ help: 'data-grist/grist-editor/crontab'
59
+ }
60
+ )
61
+ }
62
+ }
@@ -0,0 +1,62 @@
1
+ import './ox-popup-duration-input.js'
2
+
3
+ import { html } from 'lit'
4
+ import { customElement } from 'lit/decorators.js'
5
+
6
+ import { OxGristEditor } from '@operato/data-grist'
7
+ import { i18next } from '@operato/i18n'
8
+ import { openPopup, PopupHandle } from '@operato/popup'
9
+
10
+ @customElement('ox-grist-editor-duration')
11
+ export class OxGristEditorDuration extends OxGristEditor {
12
+ private popup?: PopupHandle
13
+
14
+ get editorTemplate() {
15
+ return html` <input type="text" .value=${this.value || ''} /> `
16
+ }
17
+
18
+ async firstUpdated() {
19
+ await this.updateComplete
20
+
21
+ this.renderRoot.addEventListener('click', e => {
22
+ e.stopPropagation()
23
+
24
+ this.showEditorPopup()
25
+ })
26
+
27
+ this.showEditorPopup()
28
+ }
29
+
30
+ showEditorPopup() {
31
+ if (this.popup) {
32
+ delete this.popup
33
+ }
34
+
35
+ const confirmCallback = (newval: any) => {
36
+ this.dispatchEvent(
37
+ new CustomEvent('field-change', {
38
+ bubbles: true,
39
+ composed: true,
40
+ detail: {
41
+ before: this.value,
42
+ after: newval,
43
+ record: this.record,
44
+ column: this.column,
45
+ row: this.row
46
+ }
47
+ })
48
+ )
49
+ }
50
+
51
+ this.popup = openPopup(
52
+ html`
53
+ <ox-popup-duration-input .value=${this.value} .confirmCallback=${confirmCallback}></ox-popup-duration-input>
54
+ `,
55
+ {
56
+ backdrop: true,
57
+ title: i18next.t('title.setting schedule'),
58
+ help: 'data-grist/grist-editor/duration'
59
+ }
60
+ )
61
+ }
62
+ }
@@ -2,36 +2,22 @@
2
2
  * @license Copyright © HatioLab Inc. All rights reserved.
3
3
  */
4
4
 
5
- import './parameters-editor-builder.js'
6
- import './parameters-editor-popup.js'
5
+ import './ox-parameters-builder.js'
6
+ import './ox-popup-parameters-builder.js'
7
7
 
8
- import { ColumnConfig, GristRecord, InputEditor } from '@operato/data-grist'
9
- import { LitElement, css, html } from 'lit'
10
- import { PopupHandle, openPopup } from '@operato/layout'
11
- import { customElement, property } from 'lit/decorators.js'
8
+ import { html } from 'lit'
9
+ import { customElement } from 'lit/decorators.js'
10
+ import { cloneDeep } from 'lodash-es'
12
11
 
12
+ import { OxGristEditor } from '@operato/data-grist'
13
13
  import { i18next } from '@operato/i18n'
14
+ import { openPopup, PopupHandle } from '@operato/popup'
14
15
 
15
- @customElement('ox-parameters-editor')
16
- export class ParametersEditor extends InputEditor {
17
- static styles = css`
18
- :host {
19
- color: black;
20
-
21
- overflow: hidden;
22
- text-overflow: ellipsis;
23
- }
24
- `
25
-
26
- @property({ type: Object }) value: any
27
- @property({ type: Object }) column!: ColumnConfig
28
- @property({ type: Object }) record!: GristRecord
29
- @property({ type: Number }) row!: number
30
- @property({ type: Object }) field!: any
31
-
16
+ @customElement('ox-grist-editor-parameters')
17
+ export class OxGristEditorParameters extends OxGristEditor {
32
18
  private popup?: PopupHandle
33
19
 
34
- render() {
20
+ get editorTemplate() {
35
21
  const value = typeof this.value === 'object' ? JSON.stringify(this.value) : this.value
36
22
  return html` ${value || ''} `
37
23
  }
@@ -78,7 +64,8 @@ export class ParametersEditor extends InputEditor {
78
64
  }
79
65
 
80
66
  try {
81
- var value: any = !objectified && typeof this.value === 'string' ? JSON.parse(this.value) : this.value
67
+ var value: any =
68
+ !objectified && typeof this.value === 'string' ? JSON.parse(this.value) : cloneDeep(this.value || {})
82
69
  } catch (e) {
83
70
  var value: any = {}
84
71
  }
@@ -92,14 +79,14 @@ export class ParametersEditor extends InputEditor {
92
79
  따라서, 가급적 이들 속성의 레퍼런스를 변화시키지 않는 것이 좋다.
93
80
  */
94
81
  var template = html`
95
- <ox-parameters-editor-popup
82
+ <ox-popup-parameters-builder
96
83
  .value=${value}
97
84
  .props=${spec}
98
85
  .host=${this.record}
99
86
  .context=${context}
100
87
  .confirmCallback=${confirmCallback}
101
88
  >
102
- </ox-parameters-editor-popup>
89
+ </ox-popup-parameters-builder>
103
90
  `
104
91
 
105
92
  this.popup = openPopup(template, {
@@ -0,0 +1,86 @@
1
+ /**
2
+ * @license Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+
5
+ import './ox-popup-partition-keys-input.js'
6
+
7
+ import { html } from 'lit'
8
+ import { customElement } from 'lit/decorators.js'
9
+ import { cloneDeep } from 'lodash-es'
10
+
11
+ import { OxGristEditor } from '@operato/data-grist'
12
+ import { i18next } from '@operato/i18n'
13
+ import { openPopup, PopupHandle } from '@operato/popup'
14
+
15
+ @customElement('ox-grist-editor-partition-keys')
16
+ export class OxGristEditorPartitionKeys extends OxGristEditor {
17
+ private popup?: PopupHandle
18
+
19
+ get editorTemplate() {
20
+ const value = typeof this.value === 'object' ? JSON.stringify(this.value) : this.value
21
+ return html` ${value || ''} `
22
+ }
23
+
24
+ async firstUpdated() {
25
+ await this.updateComplete
26
+
27
+ this.renderRoot.addEventListener('click', e => {
28
+ e.stopPropagation()
29
+
30
+ this.openSelector()
31
+ })
32
+
33
+ this.openSelector()
34
+ }
35
+
36
+ async openSelector() {
37
+ if (this.popup) {
38
+ delete this.popup
39
+ }
40
+
41
+ const { name, help, objectified = false } = this.column.record?.options || {}
42
+
43
+ const confirmCallback = (newval: any) => {
44
+ this.dispatchEvent(
45
+ new CustomEvent('field-change', {
46
+ bubbles: true,
47
+ composed: true,
48
+ detail: {
49
+ before: this.value,
50
+ after: !objectified ? JSON.stringify(newval) : newval,
51
+ record: this.record,
52
+ column: this.column,
53
+ row: this.row
54
+ }
55
+ })
56
+ )
57
+ }
58
+
59
+ try {
60
+ var value: any =
61
+ !objectified && typeof this.value === 'string' ? JSON.parse(this.value) : cloneDeep(this.value || {})
62
+ } catch (e) {
63
+ var value: any = {}
64
+ }
65
+
66
+ /*
67
+ 주의 : 이 팝업 템플릿은 layout 모듈에 의해서 render 되므로,
68
+ layout의 구성에 변화가 발생하면, 다시 render된다.
69
+ 이 팝업이 떠 있는 상태에서, 또 다른 팝업이 뜨는 경우도 layout 구성의 변화를 야기한다. (overlay의 갯수의 증가)
70
+ 이 경우 value, options, confirmCallback 등 클로져를 사용한 것들이 초기 바인딩된 값으로 다시 바인딩되게 되는데,
71
+ 만약, 템플릿 내부에서 이들 속성의 레퍼런스가 변화했다면, 원래 상태로 되돌아가는 현상이 발생하게 된다.
72
+ 따라서, 가급적 이들 속성의 레퍼런스를 변화시키지 않는 것이 좋다.
73
+ */
74
+ var template = html`
75
+ <ox-popup-partition-keys-input .value=${value} .confirmCallback=${confirmCallback}>
76
+ </ox-popup-partition-keys-input>
77
+ `
78
+
79
+ this.popup = openPopup(template, {
80
+ backdrop: true,
81
+ size: 'large',
82
+ title: `${name?.toUpperCase() || i18next.t('field.partition-keys')} `,
83
+ help
84
+ })
85
+ }
86
+ }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * @license Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+
5
+ import './ox-popup-value-map-input.js'
6
+
7
+ import { html } from 'lit'
8
+ import { customElement } from 'lit/decorators.js'
9
+ import { cloneDeep } from 'lodash-es'
10
+
11
+ import { OxGristEditor } from '@operato/data-grist'
12
+ import { i18next } from '@operato/i18n'
13
+ import { openPopup, PopupHandle } from '@operato/popup'
14
+
15
+ @customElement('ox-grist-editor-value-map')
16
+ export class OxGristEditorValueMap extends OxGristEditor {
17
+ private popup?: PopupHandle
18
+
19
+ get editorTemplate() {
20
+ const value = typeof this.value === 'object' ? JSON.stringify(this.value) : this.value
21
+ return html` ${value || ''} `
22
+ }
23
+
24
+ async firstUpdated() {
25
+ await this.updateComplete
26
+
27
+ this.renderRoot.addEventListener('click', e => {
28
+ e.stopPropagation()
29
+
30
+ this.openSelector()
31
+ })
32
+
33
+ this.openSelector()
34
+ }
35
+
36
+ async openSelector() {
37
+ if (this.popup) {
38
+ delete this.popup
39
+ }
40
+
41
+ const { name, help, valuetype = 'string', objectified = false } = this.column.record?.options || {}
42
+
43
+ const confirmCallback = (newval: any) => {
44
+ this.dispatchEvent(
45
+ new CustomEvent('field-change', {
46
+ bubbles: true,
47
+ composed: true,
48
+ detail: {
49
+ before: this.value,
50
+ after: !objectified ? JSON.stringify(newval) : newval,
51
+ record: this.record,
52
+ column: this.column,
53
+ row: this.row
54
+ }
55
+ })
56
+ )
57
+ }
58
+
59
+ try {
60
+ var value: any =
61
+ !objectified && typeof this.value === 'string' ? JSON.parse(this.value) : cloneDeep(this.value || {})
62
+ } catch (e) {
63
+ var value: any = {}
64
+ }
65
+
66
+ /*
67
+ 주의 : 이 팝업 템플릿은 layout 모듈에 의해서 render 되므로,
68
+ layout의 구성에 변화가 발생하면, 다시 render된다.
69
+ 이 팝업이 떠 있는 상태에서, 또 다른 팝업이 뜨는 경우도 layout 구성의 변화를 야기한다. (overlay의 갯수의 증가)
70
+ 이 경우 value, options, confirmCallback 등 클로져를 사용한 것들이 초기 바인딩된 값으로 다시 바인딩되게 되는데,
71
+ 만약, 템플릿 내부에서 이들 속성의 레퍼런스가 변화했다면, 원래 상태로 되돌아가는 현상이 발생하게 된다.
72
+ 따라서, 가급적 이들 속성의 레퍼런스를 변화시키지 않는 것이 좋다.
73
+ */
74
+ var template = html`
75
+ <ox-popup-value-map-input .value=${value} .valuetype=${valuetype} .confirmCallback=${confirmCallback}>
76
+ </ox-popup-value-map-input>
77
+ `
78
+
79
+ this.popup = openPopup(template, {
80
+ backdrop: true,
81
+ size: 'large',
82
+ title: `${name?.toUpperCase() || i18next.t('field.value-map')} `,
83
+ help
84
+ })
85
+ }
86
+ }
@@ -0,0 +1,31 @@
1
+ import cronstrue from 'cronstrue/i18n'
2
+ import i18next from 'i18next'
3
+ import { html } from 'lit'
4
+
5
+ import { FieldRenderer } from '@operato/data-grist'
6
+ import { detectOverflow } from '@operato/utils'
7
+
8
+ function onmouseover(e: Event) {
9
+ const element = e.target as HTMLSpanElement
10
+ if (detectOverflow(element)) {
11
+ element.setAttribute('data-tooltip', element.textContent!)
12
+ }
13
+ }
14
+
15
+ function onmouseout(e: Event) {
16
+ const element = e.target as HTMLSpanElement
17
+ element.removeAttribute('data-tooltip')
18
+ }
19
+
20
+ export const OxGristRendererCrontab: FieldRenderer = (value, column, record, rowIndex, field) => {
21
+ let text = ''
22
+
23
+ try {
24
+ const language = (i18next.language || 'en').substring(0, 2)
25
+ text = !value ? '' : cronstrue.toString(value, { locale: language || 'en' })
26
+ } catch (e) {
27
+ console.error(e)
28
+ }
29
+
30
+ return html`<span @mouseover=${onmouseover} @mouseout=${onmouseout}>${text}</span>`
31
+ }