@operato/data-grist 8.0.0-alpha.8 → 8.0.0-beta.1

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 (218) hide show
  1. package/CHANGELOG.md +186 -0
  2. package/dist/src/data-grid/data-grid-body.js +21 -7
  3. package/dist/src/data-grid/data-grid-body.js.map +1 -1
  4. package/dist/src/data-grid/data-grid-footer.js +2 -0
  5. package/dist/src/data-grid/data-grid-footer.js.map +1 -1
  6. package/dist/src/data-grid/data-grid-header.d.ts +1 -1
  7. package/dist/src/data-grid/data-grid-header.js +13 -9
  8. package/dist/src/data-grid/data-grid-header.js.map +1 -1
  9. package/dist/src/editors/ox-grist-editor-varname.d.ts +6 -0
  10. package/dist/src/editors/ox-grist-editor-varname.js +36 -0
  11. package/dist/src/editors/ox-grist-editor-varname.js.map +1 -0
  12. package/dist/src/editors/ox-grist-editor.js +3 -3
  13. package/dist/src/editors/ox-grist-editor.js.map +1 -1
  14. package/dist/src/editors/registry.js +3 -1
  15. package/dist/src/editors/registry.js.map +1 -1
  16. package/dist/src/gutters/gutter-sequence.d.ts +1 -1
  17. package/dist/src/record-view/index.d.ts +1 -1
  18. package/dist/src/record-view/index.js +1 -1
  19. package/dist/src/record-view/index.js.map +1 -1
  20. package/dist/src/record-view/{record-creator.d.ts → ox-record-creator.d.ts} +8 -4
  21. package/dist/src/record-view/{record-creator.js → ox-record-creator.js} +90 -34
  22. package/dist/src/record-view/ox-record-creator.js.map +1 -0
  23. package/dist/src/renderers/ox-grist-renderer-boolean.js +1 -1
  24. package/dist/src/renderers/ox-grist-renderer-boolean.js.map +1 -1
  25. package/dist/stories/accumulator-format.stories.d.ts +1 -1
  26. package/dist/stories/accumulator-format.stories.js +1 -1
  27. package/dist/stories/accumulator-format.stories.js.map +1 -1
  28. package/dist/stories/click-event-custom.stories.d.ts +45 -0
  29. package/dist/stories/click-event-custom.stories.js +247 -0
  30. package/dist/stories/click-event-custom.stories.js.map +1 -0
  31. package/dist/stories/click-event.stories.d.ts +1 -1
  32. package/dist/stories/click-event.stories.js +1 -1
  33. package/dist/stories/click-event.stories.js.map +1 -1
  34. package/dist/stories/fixed-column.stories.d.ts +1 -1
  35. package/dist/stories/fixed-column.stories.js +1 -1
  36. package/dist/stories/fixed-column.stories.js.map +1 -1
  37. package/dist/stories/grid-setting.stories.d.ts +1 -1
  38. package/dist/stories/grid-setting.stories.js +1 -1
  39. package/dist/stories/grid-setting.stories.js.map +1 -1
  40. package/dist/stories/grist-modes.stories.d.ts +1 -1
  41. package/dist/stories/grist-modes.stories.js +1 -1
  42. package/dist/stories/grist-modes.stories.js.map +1 -1
  43. package/dist/stories/group-header.stories.d.ts +1 -1
  44. package/dist/stories/group-header.stories.js +1 -1
  45. package/dist/stories/group-header.stories.js.map +1 -1
  46. package/dist/stories/textarea.stories.d.ts +1 -1
  47. package/dist/stories/textarea.stories.js +1 -1
  48. package/dist/stories/textarea.stories.js.map +1 -1
  49. package/dist/stories/tree-column-with-checkbox.stories.d.ts +1 -1
  50. package/dist/stories/tree-column-with-checkbox.stories.js +1 -1
  51. package/dist/stories/tree-column-with-checkbox.stories.js.map +1 -1
  52. package/dist/stories/tree-column.stories.d.ts +1 -1
  53. package/dist/stories/tree-column.stories.js +1 -1
  54. package/dist/stories/tree-column.stories.js.map +1 -1
  55. package/dist/tsconfig.tsbuildinfo +1 -1
  56. package/package.json +20 -20
  57. package/themes/calendar-theme.css +3 -1
  58. package/.storybook/main.js +0 -3
  59. package/.storybook/preview.js +0 -52
  60. package/.storybook/server.mjs +0 -8
  61. package/dist/src/record-view/record-creator.js.map +0 -1
  62. package/src/accumulator/accumulator.ts +0 -63
  63. package/src/configure/column-builder.ts +0 -114
  64. package/src/configure/config-builder.ts +0 -40
  65. package/src/configure/filters-option-builder.ts +0 -8
  66. package/src/configure/imex-option-builder.ts +0 -5
  67. package/src/configure/list-option-builder.ts +0 -9
  68. package/src/configure/rows-option-builder.ts +0 -38
  69. package/src/configure/tree-option-builder.ts +0 -22
  70. package/src/configure/zero-config.ts +0 -83
  71. package/src/const.ts +0 -1
  72. package/src/data-card/data-card-field.ts +0 -94
  73. package/src/data-card/data-card-gutter-menu.ts +0 -94
  74. package/src/data-card/data-card-gutter.ts +0 -103
  75. package/src/data-card/data-card.ts +0 -154
  76. package/src/data-card/event-handlers/record-card-click-handler.ts +0 -34
  77. package/src/data-card/event-handlers/record-card-dblclick-handler.ts +0 -34
  78. package/src/data-card/record-card.ts +0 -298
  79. package/src/data-consumer.ts +0 -11
  80. package/src/data-grid/data-grid-accum-field.ts +0 -109
  81. package/src/data-grid/data-grid-body-style.ts +0 -85
  82. package/src/data-grid/data-grid-body.ts +0 -749
  83. package/src/data-grid/data-grid-field.ts +0 -227
  84. package/src/data-grid/data-grid-footer.ts +0 -117
  85. package/src/data-grid/data-grid-header.ts +0 -574
  86. package/src/data-grid/data-grid.ts +0 -293
  87. package/src/data-grid/event-handlers/data-grid-body-click-handler.ts +0 -69
  88. package/src/data-grid/event-handlers/data-grid-body-contextmenu-handler.ts +0 -32
  89. package/src/data-grid/event-handlers/data-grid-body-dblclick-handler.ts +0 -42
  90. package/src/data-grid/event-handlers/data-grid-body-focus-change-handler.ts +0 -24
  91. package/src/data-grid/event-handlers/data-grid-body-keydown-handler.ts +0 -234
  92. package/src/data-grist.ts +0 -1233
  93. package/src/data-list/data-list-field.ts +0 -82
  94. package/src/data-list/data-list-gutter.ts +0 -108
  95. package/src/data-list/data-list.ts +0 -145
  96. package/src/data-list/event-handlers/record-partial-click-handler.ts +0 -34
  97. package/src/data-list/event-handlers/record-partial-dblclick-handler.ts +0 -33
  98. package/src/data-list/event-handlers/record-partial-long-press-handler.ts +0 -33
  99. package/src/data-list/record-partial.ts +0 -264
  100. package/src/data-manipulator.ts +0 -426
  101. package/src/data-provider.ts +0 -271
  102. package/src/data-report/data-report-body-style.ts +0 -58
  103. package/src/data-report/data-report-body.ts +0 -189
  104. package/src/data-report/data-report-component.ts +0 -138
  105. package/src/data-report/data-report-field.ts +0 -83
  106. package/src/data-report/data-report-header.ts +0 -242
  107. package/src/data-report/event-handlers/data-report-body-click-handler.ts +0 -38
  108. package/src/data-report/event-handlers/data-report-body-dblclick-handler.ts +0 -25
  109. package/src/data-report/event-handlers/data-report-body-keydown-handler.ts +0 -68
  110. package/src/data-report.ts +0 -424
  111. package/src/editors/index.ts +0 -4
  112. package/src/editors/ox-grist-editor-checkbox.ts +0 -28
  113. package/src/editors/ox-grist-editor-color.ts +0 -10
  114. package/src/editors/ox-grist-editor-date.ts +0 -10
  115. package/src/editors/ox-grist-editor-datetime.ts +0 -27
  116. package/src/editors/ox-grist-editor-email.ts +0 -10
  117. package/src/editors/ox-grist-editor-file.ts +0 -28
  118. package/src/editors/ox-grist-editor-image.ts +0 -31
  119. package/src/editors/ox-grist-editor-month.ts +0 -10
  120. package/src/editors/ox-grist-editor-multiple-select.ts +0 -57
  121. package/src/editors/ox-grist-editor-number.ts +0 -27
  122. package/src/editors/ox-grist-editor-password.ts +0 -10
  123. package/src/editors/ox-grist-editor-select.ts +0 -55
  124. package/src/editors/ox-grist-editor-tel.ts +0 -10
  125. package/src/editors/ox-grist-editor-text.ts +0 -14
  126. package/src/editors/ox-grist-editor-textarea.ts +0 -16
  127. package/src/editors/ox-grist-editor-time.ts +0 -10
  128. package/src/editors/ox-grist-editor-tree.ts +0 -27
  129. package/src/editors/ox-grist-editor-week.ts +0 -10
  130. package/src/editors/ox-grist-editor.ts +0 -207
  131. package/src/editors/ox-input-tree.ts +0 -226
  132. package/src/editors/registry.ts +0 -80
  133. package/src/empty-note.ts +0 -46
  134. package/src/filters/filter-checkbox.ts +0 -49
  135. package/src/filters/filter-input-barcode.ts +0 -34
  136. package/src/filters/filter-input.ts +0 -30
  137. package/src/filters/filter-range-date.ts +0 -81
  138. package/src/filters/filter-range-number.ts +0 -64
  139. package/src/filters/filter-select-buttons.ts +0 -60
  140. package/src/filters/filter-select.ts +0 -68
  141. package/src/filters/filter-styles.ts +0 -119
  142. package/src/filters/filters-form.ts +0 -476
  143. package/src/filters/index.ts +0 -10
  144. package/src/filters/registry.ts +0 -56
  145. package/src/formatters/date-formatter.ts +0 -3
  146. package/src/formatters/index.ts +0 -1
  147. package/src/formatters/number-formatter.ts +0 -3
  148. package/src/formatters/registry.ts +0 -30
  149. package/src/formatters/text-formatter.ts +0 -3
  150. package/src/gutters/gutter-button.ts +0 -51
  151. package/src/gutters/gutter-dirty.ts +0 -96
  152. package/src/gutters/gutter-row-selector.ts +0 -89
  153. package/src/gutters/gutter-sequence.ts +0 -54
  154. package/src/gutters/index.ts +0 -1
  155. package/src/gutters/registry.ts +0 -32
  156. package/src/handlers/contextmenu-tree-mutation.ts +0 -80
  157. package/src/handlers/index.ts +0 -1
  158. package/src/handlers/move-down.ts +0 -44
  159. package/src/handlers/move-up.ts +0 -44
  160. package/src/handlers/record-copy.ts +0 -38
  161. package/src/handlers/record-delete.ts +0 -30
  162. package/src/handlers/record-view-handler.ts +0 -27
  163. package/src/handlers/registry.ts +0 -42
  164. package/src/handlers/select-row-toggle.ts +0 -30
  165. package/src/handlers/select-row.ts +0 -27
  166. package/src/index.ts +0 -17
  167. package/src/personalizer/index.ts +0 -1
  168. package/src/personalizer/ox-grist-filter-personalizer.ts +0 -192
  169. package/src/personalizer/ox-grist-personalizer.ts +0 -226
  170. package/src/record-view/event-handlers/record-view-body-click-handler.ts +0 -33
  171. package/src/record-view/event-handlers/record-view-body-keydown-handler.ts +0 -26
  172. package/src/record-view/index.ts +0 -2
  173. package/src/record-view/record-creator.ts +0 -226
  174. package/src/record-view/record-view-body.ts +0 -257
  175. package/src/record-view/record-view-handler.ts +0 -86
  176. package/src/record-view/record-view.ts +0 -122
  177. package/src/renderers/index.ts +0 -14
  178. package/src/renderers/ox-grist-renderer-boolean.ts +0 -43
  179. package/src/renderers/ox-grist-renderer-color.ts +0 -15
  180. package/src/renderers/ox-grist-renderer-date.ts +0 -62
  181. package/src/renderers/ox-grist-renderer-file.ts +0 -31
  182. package/src/renderers/ox-grist-renderer-image.ts +0 -27
  183. package/src/renderers/ox-grist-renderer-json5.ts +0 -36
  184. package/src/renderers/ox-grist-renderer-link.ts +0 -17
  185. package/src/renderers/ox-grist-renderer-password.ts +0 -7
  186. package/src/renderers/ox-grist-renderer-progress.ts +0 -45
  187. package/src/renderers/ox-grist-renderer-select.ts +0 -58
  188. package/src/renderers/ox-grist-renderer-text.ts +0 -16
  189. package/src/renderers/ox-grist-renderer-textarea.ts +0 -7
  190. package/src/renderers/ox-grist-renderer-tree.ts +0 -189
  191. package/src/renderers/ox-grist-renderer.ts +0 -35
  192. package/src/renderers/registry.ts +0 -111
  193. package/src/sorters/sorters-control.ts +0 -143
  194. package/src/types.ts +0 -813
  195. package/src/utils/index.ts +0 -2
  196. package/src/utils/list-param.ts +0 -72
  197. package/src/utils/supports-passive.ts +0 -13
  198. package/stories/accumulator-format.stories.ts +0 -276
  199. package/stories/barcode-input-filter.stories.ts +0 -216
  200. package/stories/bounded-select-filters.stories.ts +0 -333
  201. package/stories/bounded-select-record.stories.ts +0 -336
  202. package/stories/click-event.stories.ts +0 -283
  203. package/stories/creatable-only-column.stories.ts +0 -253
  204. package/stories/default-filters.stories.ts +0 -241
  205. package/stories/dynamic-editable.stories.ts +0 -313
  206. package/stories/empty-sorters.stories.ts +0 -180
  207. package/stories/explicit-fetch.stories.ts +0 -186
  208. package/stories/fixed-column.stories.ts +0 -416
  209. package/stories/grid-setting.stories.ts +0 -501
  210. package/stories/grist-modes.stories.ts +0 -451
  211. package/stories/group-header.stories.ts +0 -442
  212. package/stories/record-view.stories.ts +0 -143
  213. package/stories/textarea.stories.ts +0 -261
  214. package/stories/tree-column-with-checkbox.stories.ts +0 -297
  215. package/stories/tree-column.stories.ts +0 -296
  216. package/tsconfig.json +0 -26
  217. package/web-dev-server.config.mjs +0 -27
  218. package/web-test-runner.config.mjs +0 -45
@@ -1,31 +0,0 @@
1
- import '@operato/input/ox-input-image.js'
2
-
3
- import { OxGristEditor } from './ox-grist-editor.js'
4
- import { customElement } from 'lit/decorators.js'
5
- import { html } from 'lit'
6
-
7
- @customElement('ox-grist-editor-image')
8
- export class OxGristEditorImage extends OxGristEditor {
9
- get editorTemplate() {
10
- return html` <ox-input-image .value=${this.value}></ox-input-image> `
11
- }
12
-
13
- _onchange(e: Event) {
14
- e.stopPropagation()
15
-
16
- const input = e.target as HTMLInputElement
17
-
18
- // value가 image file object인지, image url인지 확인
19
- if (input.files?.[0]) {
20
- this._dirtyValue = this.formatFromEditor(input.files[0])
21
- } else {
22
- this._dirtyValue = this.formatFromEditor(input.value)
23
- }
24
-
25
- this._onfocusout()
26
- }
27
-
28
- formatFromEditor(value: any) {
29
- return value
30
- }
31
- }
@@ -1,10 +0,0 @@
1
- import { OxGristEditor } from './ox-grist-editor.js'
2
- import { customElement } from 'lit/decorators.js'
3
- import { html } from 'lit'
4
-
5
- @customElement('ox-grist-editor-month')
6
- export class OxGristEditorMonth extends OxGristEditor {
7
- get editorTemplate() {
8
- return html` <input type="month" .value=${this.value} /> `
9
- }
10
- }
@@ -1,57 +0,0 @@
1
- import '@operato/input/ox-select.js'
2
- import '@operato/input/ox-checkbox.js'
3
- import '@operato/popup/ox-popup-list.js'
4
-
5
- import { html, css } from 'lit'
6
- import { customElement } from 'lit/decorators.js'
7
-
8
- import { OxGristEditor } from './ox-grist-editor.js'
9
-
10
- @customElement('ox-grist-editor-multiple-select')
11
- export class OxGristEditorMultipleSelect extends OxGristEditor {
12
- static styles = [
13
- ...OxGristEditor.styles,
14
- css`
15
- :host {
16
- overflow: visible;
17
- }
18
- `
19
- ]
20
-
21
- get editorTemplate() {
22
- var rowOptionField = this.record[this.column.record.rowOptionField || '']
23
- var { options = [] } = rowOptionField ? rowOptionField : this.column.record
24
-
25
- if (typeof options == 'function') {
26
- options = options.call(null, this.value, this.column, this.record, this.rowIndex, this.field) || []
27
- }
28
-
29
- options = options.map((option: any) => {
30
- switch (typeof option) {
31
- case 'string':
32
- return {
33
- display: option,
34
- value: option
35
- }
36
- case 'object':
37
- return {
38
- display: option.display,
39
- value: option.value
40
- }
41
- default:
42
- return option
43
- }
44
- })
45
-
46
- return html`
47
- <ox-select .value=${this.value} style="width: 100%;">
48
- <ox-popup-list multiple attr-selected="checked">
49
- ${options.map(
50
- (option: { display: string; value: string }) =>
51
- html` <ox-checkbox option value=${option.value}>${option.display}</ox-checkbox> `
52
- )}
53
- </ox-popup-list>
54
- </ox-select>
55
- `
56
- }
57
- }
@@ -1,27 +0,0 @@
1
- import { OxGristEditor } from './ox-grist-editor.js'
2
- import { customElement } from 'lit/decorators.js'
3
- import { html } from 'lit'
4
- import { parseToNumberOrNull } from '@operato/utils'
5
-
6
- @customElement('ox-grist-editor-number')
7
- export class OxGristEditorNumber extends OxGristEditor {
8
- get inlineEditable() {
9
- return true
10
- }
11
-
12
- formatFromEditor(value: any) {
13
- const parsed = parseToNumberOrNull(value) ?? null
14
-
15
- if (parsed !== null && this.column.type == 'integer') {
16
- return Math.floor(parsed)
17
- }
18
-
19
- return parsed
20
- }
21
-
22
- get editorTemplate() {
23
- var { min = -Infinity, max = Infinity } = this.column.record.options || {}
24
-
25
- return html` <input type="number" .value=${this.value} .min=${Number(min)} .max=${Number(max)} /> `
26
- }
27
- }
@@ -1,10 +0,0 @@
1
- import { OxGristEditor } from './ox-grist-editor.js'
2
- import { customElement } from 'lit/decorators.js'
3
- import { html } from 'lit'
4
-
5
- @customElement('ox-grist-editor-password')
6
- export class OxGristEditorPassword extends OxGristEditor {
7
- get editorTemplate() {
8
- return html` <input type="password" .value=${this.value} /> `
9
- }
10
- }
@@ -1,55 +0,0 @@
1
- import { html } from 'lit'
2
- import { customElement } from 'lit/decorators.js'
3
- import { until } from 'lit/directives/until.js'
4
-
5
- import { OxGristEditor } from './ox-grist-editor.js'
6
- import { SelectOption, SelectOptionObject } from '../types.js'
7
-
8
- function buildOptions(options: SelectOption[], value: any) {
9
- const selectOptionObjects = options.map(option => {
10
- switch (typeof option) {
11
- case 'string':
12
- return {
13
- display: option,
14
- value: option
15
- }
16
- case 'object':
17
- return {
18
- display: option.display || option.name,
19
- value: option.value
20
- }
21
- default:
22
- return option
23
- }
24
- }) as SelectOptionObject[]
25
-
26
- return html`
27
- <select>
28
- ${selectOptionObjects.map(
29
- (option: any) => html`
30
- <option ?selected=${option.value == value} value=${option.value}>${option.display}</option>
31
- `
32
- )}
33
- </select>
34
- `
35
- }
36
-
37
- @customElement('ox-grist-editor-select')
38
- export class OxGristEditorSelect extends OxGristEditor {
39
- get editorTemplate() {
40
- var rowOptionField = this.record[this.column.record.rowOptionField || '']
41
- var { options = [] } = rowOptionField ? rowOptionField : this.column.record
42
-
43
- if (typeof options == 'function') {
44
- options = options.call(null, this.value, this.column, this.record, this.rowIndex, this.field)
45
-
46
- if (options instanceof Promise) {
47
- return html`${until(options.then(options => buildOptions(options, this.value)))}`
48
- } else {
49
- return buildOptions((options || []) as SelectOption[], this.value)
50
- }
51
- } else {
52
- return buildOptions((options || []) as SelectOption[], this.value)
53
- }
54
- }
55
- }
@@ -1,10 +0,0 @@
1
- import { OxGristEditor } from './ox-grist-editor.js'
2
- import { customElement } from 'lit/decorators.js'
3
- import { html } from 'lit'
4
-
5
- @customElement('ox-grist-editor-tel')
6
- export class OxGristEditorTel extends OxGristEditor {
7
- get editorTemplate() {
8
- return html` <input type="tel" .value=${this.value} /> `
9
- }
10
- }
@@ -1,14 +0,0 @@
1
- import { OxGristEditor } from './ox-grist-editor.js'
2
- import { customElement } from 'lit/decorators.js'
3
- import { html } from 'lit'
4
-
5
- @customElement('ox-grist-editor-text')
6
- export class OxGristEditorText extends OxGristEditor {
7
- get inlineEditable() {
8
- return true
9
- }
10
-
11
- get editorTemplate() {
12
- return html` <input type="text" .value=${this.value} /> `
13
- }
14
- }
@@ -1,16 +0,0 @@
1
- import '@operato/input/ox-input-textarea.js'
2
-
3
- import { OxGristEditor } from './ox-grist-editor.js'
4
- import { customElement } from 'lit/decorators.js'
5
- import { html } from 'lit'
6
-
7
- @customElement('ox-grist-editor-textarea')
8
- export class OxGristEditorTextarea extends OxGristEditor {
9
- get inlineEditable() {
10
- return true
11
- }
12
-
13
- get editorTemplate() {
14
- return html` <ox-input-textarea .value=${this.value}></ox-input-textarea> `
15
- }
16
- }
@@ -1,10 +0,0 @@
1
- import { OxGristEditor } from './ox-grist-editor.js'
2
- import { customElement } from 'lit/decorators.js'
3
- import { html } from 'lit'
4
-
5
- @customElement('ox-grist-editor-time')
6
- export class OxGristEditorTime extends OxGristEditor {
7
- get editorTemplate() {
8
- return html` <input type="time" .value=${this.value} /> `
9
- }
10
- }
@@ -1,27 +0,0 @@
1
- import './ox-input-tree'
2
-
3
- import { html, css } from 'lit'
4
- import { customElement, query } from 'lit/decorators.js'
5
-
6
- import { OxGristEditor } from './ox-grist-editor.js'
7
-
8
- @customElement('ox-grist-editor-tree')
9
- export class OxGristEditorTree extends OxGristEditor {
10
- static styles = [
11
- css`
12
- :host {
13
- flex: 1;
14
- }
15
-
16
- ox-input-tree {
17
- flex: 1;
18
- }
19
- `
20
- ]
21
-
22
- get editorTemplate() {
23
- var { selectable } = this.column.record.options || {}
24
-
25
- return html`<ox-input-tree .value=${this.value} .record=${this.record} ?selectable=${selectable}></ox-input-tree>`
26
- }
27
- }
@@ -1,10 +0,0 @@
1
- import { OxGristEditor } from './ox-grist-editor.js'
2
- import { customElement } from 'lit/decorators.js'
3
- import { html } from 'lit'
4
-
5
- @customElement('ox-grist-editor-week')
6
- export class OxGristEditorWeek extends OxGristEditor {
7
- get editorTemplate() {
8
- return html` <input type="week" .value=${this.value} /> `
9
- }
10
- }
@@ -1,207 +0,0 @@
1
- import { css, html, LitElement, PropertyValues } from 'lit'
2
- import { customElement, property } from 'lit/decorators.js'
3
-
4
- import { ZERO_COLUMN, ZERO_RECORD } from '../configure/zero-config'
5
- import { DataGridField } from '../data-grid/data-grid-field'
6
- import { ColumnConfig, GristRecord } from '../types'
7
- import { getDefaultValue } from '@operato/time-calculator'
8
-
9
- const STYLE = css`
10
- :host {
11
- display: flex;
12
-
13
- align-items: center;
14
-
15
- width: 100%;
16
- height: 100%;
17
-
18
- border: 0;
19
- background-color: transparent;
20
-
21
- overflow: hidden;
22
- justify-content: var(--data-grid-field-justify-content, flex-start);
23
- }
24
-
25
- :host > * {
26
- display: flex;
27
-
28
- width: 100%;
29
- height: 100%;
30
-
31
- border: 0;
32
- background-color: transparent;
33
-
34
- box-sizing: border-box;
35
-
36
- align-items: center;
37
- }
38
-
39
- :host > style {
40
- display: none;
41
- }
42
-
43
- :host > input {
44
- color: var(--md-sys-color-on-background);
45
- }
46
-
47
- :host > input[type='checkbox'] {
48
- width: initial;
49
- margin: 0;
50
- }
51
- *:focus {
52
- outline: none;
53
- }
54
-
55
- input[type='file'] {
56
- opacity: 0%;
57
- }
58
-
59
- @media screen and (max-width: 460px) {
60
- :host > * {
61
- border: initial;
62
- background-color: initial;
63
- }
64
-
65
- *:focus {
66
- outline: none;
67
- }
68
-
69
- input,
70
- select,
71
- textarea {
72
- font-size: 16px;
73
- }
74
- }
75
- `
76
-
77
- @customElement('ox-grist-editor')
78
- export class OxGristEditor extends LitElement {
79
- static styles = [STYLE]
80
-
81
- @property({ type: Object }) value?: any
82
- @property({ type: Object }) column: ColumnConfig = ZERO_COLUMN
83
- @property({ type: Object }) record: GristRecord = ZERO_RECORD
84
- @property({ type: Number }) rowIndex?: number
85
- @property({ type: Object }) field?: DataGridField
86
- @property({ type: Number }) row?: number
87
-
88
- protected _dirtyValue?: any
89
-
90
- render() {
91
- return this.editorTemplate
92
- }
93
-
94
- get editor(): HTMLElement | null {
95
- return this.renderRoot.firstElementChild as HTMLElement
96
- }
97
-
98
- get inlineEditable() {
99
- return false
100
- }
101
-
102
- async firstUpdated() {
103
- this.renderRoot.addEventListener('change', this._onchange.bind(this))
104
- this.renderRoot.addEventListener('focusout', this._onfocusout.bind(this))
105
- this.addEventListener('click', this._onclick.bind(this))
106
- this.addEventListener('dblclick', this._ondblclick.bind(this))
107
- this.addEventListener('keydown', this._onkeydown.bind(this))
108
-
109
- /* editor mode 인 경우의 마우스 움직임이, grist-body의 이벤트 처리에 의해서 에디터를 리셋시킬 수 있으므로, 이벤트 전파를 막는다. */
110
- this.addEventListener('mousedown', (e: Event) => e.stopPropagation())
111
- this.addEventListener('mousemove', (e: Event) => e.stopPropagation())
112
- this.addEventListener('mouseup', (e: Event) => e.stopPropagation())
113
-
114
- const { name = '' } = this.column
115
- const { align, defaultValue } = this.column.record
116
-
117
- if (align) {
118
- this.style.textAlign = align
119
- this.style.textAlignLast = align /* for select */
120
- }
121
-
122
- var currentValue = this.record[name]
123
-
124
- if (typeof currentValue == 'undefined' && defaultValue) {
125
- currentValue = getDefaultValue(defaultValue, this.record)
126
- }
127
-
128
- this.value = this._dirtyValue = this.formatForEditor(currentValue)
129
-
130
- // 입력을 위한 키를 누르면서 편집모드가 될때는 누른 키가 처음에 입력되도록, enter 같은 것을 눌러서 편집모드가 되면 현재 값으로 편집모드 전환
131
- const valueWith = this.inlineEditable && this.field?.valueWith
132
- this.value = this._dirtyValue = valueWith ? this.formatFromEditor(valueWith) : this.formatForEditor(currentValue)
133
-
134
- requestAnimationFrame(() => {
135
- this.focus()
136
- !valueWith && this.select()
137
- })
138
- }
139
-
140
- select() {
141
- const editor = this.editor
142
- if ((editor as HTMLInputElement)?.select) {
143
- return (editor as HTMLInputElement).select()
144
- }
145
- }
146
-
147
- focus() {
148
- const editor = this.editor
149
- if (editor) {
150
- editor.focus()
151
- }
152
- }
153
-
154
- formatForEditor(value: any): any {
155
- return value == null ? '' : value
156
- }
157
-
158
- formatFromEditor(value: any): any {
159
- return value
160
- }
161
-
162
- _onfocusout() {
163
- // paste시 field-change는 Body에서 하므로 X
164
- if (this.field?.isWorking === true) return
165
-
166
- const { name = '' } = this.column
167
- var currentValue = this.record[name] || ''
168
-
169
- if (this._dirtyValue !== currentValue) {
170
- this.dispatchEvent(
171
- new CustomEvent('field-change', {
172
- bubbles: true,
173
- composed: true,
174
- detail: {
175
- before: currentValue,
176
- after: this._dirtyValue,
177
- column: this.column,
178
- record: this.record,
179
- row: this.row
180
- }
181
- })
182
- )
183
- }
184
- }
185
-
186
- _onchange(e: Event): void {
187
- e.stopPropagation()
188
-
189
- const value = (e.target as any)?.value
190
-
191
- this._dirtyValue = this.formatFromEditor(value)
192
- }
193
-
194
- _onkeydown(e: Event): void {}
195
-
196
- _onclick(e: Event): void {
197
- e.stopPropagation()
198
- }
199
-
200
- _ondblclick(e: Event): void {
201
- e.stopPropagation()
202
- }
203
-
204
- get editorTemplate() {
205
- return html``
206
- }
207
- }