@operato/scene-table 8.0.0-beta.1 → 9.0.0-beta.0

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.
@@ -1,189 +0,0 @@
1
- import { ApplicationContext, Component, Model, POINT, Style } from '@hatiolab/things-scene'
2
- import merge from 'lodash-es/merge'
3
- import Table from './table'
4
- import TableCell from './table-cell'
5
- import DataList from './data-list/data-list'
6
-
7
- export type WHERE = 'all' | 'in' | 'out' | 'left' | 'right' | 'center' | 'middle' | 'top' | 'bottom' | 'clear'
8
-
9
- export const SIDES: { [key: string]: string[] } = {
10
- all: ['top', 'left', 'bottom', 'right'],
11
- out: ['top', 'left', 'bottom', 'right'],
12
- left: ['left'],
13
- right: ['right'],
14
- top: ['top'],
15
- bottom: ['bottom'],
16
- leftright: ['left', 'right'],
17
- topbottom: ['top', 'bottom']
18
- }
19
-
20
- export const CLEAR_STYLE = {
21
- strokeStyle: '',
22
- lineDash: 'solid',
23
- lineWidth: 0
24
- }
25
-
26
- export const DEFAULT_STYLE = {
27
- strokeStyle: '#999',
28
- lineDash: 'solid',
29
- lineWidth: 1
30
- }
31
-
32
- export function buildNewCell(type: string, app: ApplicationContext): TableCell {
33
- return Model.compile(
34
- {
35
- type,
36
- left: 0,
37
- top: 0,
38
- width: 1,
39
- height: 1,
40
- textWrap: true,
41
- border: buildBorderStyle(DEFAULT_STYLE, 'all')
42
- },
43
- app
44
- ) as TableCell
45
- }
46
-
47
- export function buildCopiedCell(copy: Model, app: ApplicationContext): TableCell {
48
- var obj = JSON.parse(JSON.stringify(copy))
49
- delete obj.text
50
- delete obj.refid
51
-
52
- return Model.compile(obj, app) as TableCell
53
- }
54
-
55
- export function buildBorderStyle(style: Style, where: string) {
56
- return (SIDES[where] || []).reduce((border: { [key: string]: any }, side: string) => {
57
- border[side] = style
58
- return border
59
- }, {} as { [key: string]: any })
60
- }
61
-
62
- export function setCellBorder(cell: any, style: Style, where: string) {
63
- if (!cell) return
64
- cell.set('border', merge({}, cell.getState('border') || {}, buildBorderStyle(style, where)))
65
- }
66
-
67
- export function isLeftMost(total: number, columns: number, indices: number[], i: number) {
68
- return i == 0 || !(i % columns) || indices.indexOf(i - 1) == -1
69
- }
70
-
71
- export function isRightMost(total: number, columns: number, indices: number[], i: number) {
72
- return i == total - 1 || i % columns == columns - 1 || indices.indexOf(i + 1) == -1
73
- }
74
-
75
- export function isTopMost(total: number, columns: number, indices: number[], i: number) {
76
- return i < columns || indices.indexOf(i - columns) == -1
77
- }
78
-
79
- export function isBottomMost(total: number, columns: number, indices: number[], i: number) {
80
- return i > total - columns - 1 || indices.indexOf(i + columns) == -1
81
- }
82
-
83
- export function above(columns: number, i: number) {
84
- return i - columns
85
- }
86
-
87
- export function below(columns: number, i: number) {
88
- return i + columns
89
- }
90
-
91
- export function before(columns: number, i: number) {
92
- return !(i % columns) ? -1 : i - 1
93
- }
94
-
95
- export function after(columns: number, i: number) {
96
- return !((i + 1) % columns) ? -1 : i + 1
97
- }
98
-
99
- export function array(value: any, size: number) {
100
- var arr = []
101
- for (let i = 0; i < size; i++) arr.push(1)
102
- return arr
103
- }
104
-
105
- export function adjustCellWidth(component: Table | DataList, index: number, diff: number) {
106
- var { width } = component.textBounds
107
- var widths_sum = component.widths_sum
108
-
109
- var widths = component.widths.slice()
110
-
111
- var diff_unit = (diff / width) * widths_sum
112
-
113
- var min_width_unit = (widths_sum / width) * 10 // 10픽셀정도를 최소로
114
-
115
- if (diff_unit < 0) diff_unit = -Math.min(widths[index] - min_width_unit, -diff_unit)
116
- else diff_unit = Math.min(widths[index + 1] - min_width_unit, diff_unit)
117
-
118
- widths[index] = Math.round((widths[index] + diff_unit) * 100) / 100
119
- widths[index + 1] = Math.round((widths[index + 1] - diff_unit) * 100) / 100
120
-
121
- component.set('widths', widths)
122
- }
123
-
124
- export function adjustCellHeight(component: Table | DataList, index: number, diff: number) {
125
- var { height } = component.textBounds
126
- var heights_sum = component.heights_sum
127
-
128
- var heights = component.heights.slice()
129
-
130
- var diff_unit = (diff / height) * heights_sum
131
-
132
- var min_height_unit = (heights_sum / height) * 10 // 10픽셀정도를 최소로
133
-
134
- if (diff_unit < 0) diff_unit = -Math.min(heights[index] - min_height_unit, -diff_unit)
135
- else diff_unit = Math.min(heights[index + 1] - min_height_unit, diff_unit)
136
-
137
- heights[index] = Math.round((heights[index] + diff_unit) * 100) / 100
138
- heights[index + 1] = Math.round((heights[index + 1] - diff_unit) * 100) / 100
139
-
140
- component.set('heights', heights)
141
- }
142
-
143
- export var columnControlHandler = {
144
- ondragmove: function (point: POINT, index: number, component: Table) {
145
- var { left, width } = component.textBounds
146
- var widths_sum = component.widths_sum
147
-
148
- var widths = component.widths.slice()
149
-
150
- /* 컨트롤의 원래 위치를 구한다. */
151
- var origin_pos_unit = widths.slice(0, index + 1).reduce((sum: number, width: number) => sum + width, 0)
152
- var origin_offset = left + (origin_pos_unit / widths_sum) * width
153
-
154
- /*
155
- * point의 좌표는 부모 레이어 기준의 x, y 값이다.
156
- * 따라서, 도형의 회전을 감안한 좌표로의 변환이 필요하다.
157
- * Transcoord시에는 point좌표가 부모까지 transcoord되어있는 상태이므로,
158
- * 컴포넌트자신에 대한 transcoord만 필요하다.(마지막 파라미터를 false로).
159
- */
160
- var transcoorded = component.transcoordP2S(point.x, point.y)
161
-
162
- adjustCellWidth(component, index, transcoorded.x - origin_offset)
163
- }
164
- }
165
-
166
- export var rowControlHandler = {
167
- ondragmove: function (point: POINT, index: number, component: Table) {
168
- var { top, height } = component.textBounds
169
- var heights_sum = component.heights_sum
170
-
171
- var heights = component.heights.slice()
172
-
173
- /* 컨트롤의 원래 위치를 구한다. */
174
- index -= component.columns - 1
175
- var origin_pos_unit = heights.slice(0, index + 1).reduce((sum: number, height: number) => sum + height, 0)
176
- var origin_offset = top + (origin_pos_unit / heights_sum) * height
177
-
178
- /*
179
- * point의 좌표는 부모 레이어 기준의 x, y 값이다.
180
- * 따라서, 도형의 회전을 감안한 좌표로의 변환이 필요하다.
181
- * Transcoord시에는 point좌표가 부모까지 transcoord되어있는 상태이므로,
182
- * 컴포넌트자신에 대한 transcoord만 필요하다.(마지막 파라미터를 false로).
183
- */
184
- var transcoorded = component.transcoordP2S(point.x, point.y)
185
- var diff = transcoorded.y - origin_offset
186
-
187
- adjustCellHeight(component, index, diff)
188
- }
189
- }
package/src/index.ts DELETED
@@ -1,6 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
- export { default as Table } from './table'
5
- export { default as TableCell } from './table-cell'
6
- export { default as DataList } from './data-list/data-list'
package/src/table-cell.ts DELETED
@@ -1,138 +0,0 @@
1
- /*
2
- * Copyright © HatioLab Inc. All rights reserved.
3
- */
4
- import { Component, ComponentNature, RectPath } from '@hatiolab/things-scene'
5
-
6
- import Table from './table'
7
-
8
- type Style = { [style: string]: any }
9
-
10
- const NATURE: ComponentNature = {
11
- mutable: false,
12
- resizable: true,
13
- rotatable: true,
14
- properties: [
15
- {
16
- type: 'editor-table',
17
- label: '',
18
- name: '',
19
- property: {
20
- merge: true,
21
- split: true
22
- }
23
- },
24
- {
25
- type: 'string',
26
- label: 'data-key',
27
- name: 'dataKey',
28
- property: 'dataKey'
29
- },
30
- {
31
- type: 'number',
32
- label: 'data-index',
33
- name: 'dataIndex',
34
- property: 'dataIndex'
35
- }
36
- ],
37
- help: 'scene/component/table-cell'
38
- }
39
-
40
- const EMPTY_BORDER = {}
41
-
42
- function isBottomMost(idx: number, rows: number, columns: number, components: Component[]) {
43
- return idx >= (rows - 1) * columns || (components[idx + columns] && components[idx + columns].hidden)
44
- }
45
-
46
- function isRightMost(idx: number, rows: number, columns: number, components: Component[]) {
47
- return (idx + 1) % columns == 0 || (components[idx + 1] && components[idx + 1].hidden)
48
- }
49
-
50
- /**
51
- * 1. 스타일을 상속 받아야 함. (cascade-style)
52
- * 2. 스타일을 동적처리할 수 있음. (로직처리)
53
- * 3. 데이타를 받을 수 있음.
54
- */
55
- export default class TableCell extends RectPath(Component) {
56
- // export default class TableCell extends Container {
57
-
58
- // get layout() {
59
- // return Layout.getState(this.getState('layout') || 'card')
60
- // }
61
-
62
- get nature() {
63
- return NATURE
64
- }
65
-
66
- set merged(merged) {
67
- this.set('merged', !!merged)
68
- if (merged) this.set('text', '')
69
- }
70
-
71
- get merged() {
72
- return this.getState('merged')
73
- }
74
-
75
- set rowspan(rowspan) {
76
- this.set('rowspan', rowspan)
77
- }
78
-
79
- get rowspan() {
80
- return this.getState('rowspan')
81
- }
82
-
83
- set colspan(colspan) {
84
- this.set('colspan', colspan)
85
- }
86
-
87
- get colspan() {
88
- return this.getState('colspan')
89
- }
90
-
91
- set strokeStyle(strokeStyle: string) {
92
- const { lineWidth, lineDash } = this.state
93
- var style = { strokeStyle } as any
94
-
95
- lineWidth && (style.lineWidth = lineWidth)
96
- lineDash && (style.lineDash = lineDash)
97
-
98
- const table = this.parent as Table
99
- table?.setCellsStyle([this], style, 'out', false /* not clear before */)
100
- }
101
-
102
- _drawBorder(context: CanvasRenderingContext2D, x: number, y: number, to_x: number, to_y: number, style: Style) {
103
- if (style && style.strokeStyle && style.lineWidth && style.lineDash) {
104
- context.beginPath()
105
- context.moveTo(x, y)
106
- context.lineTo(to_x, to_y)
107
- Component.drawStroke(context, style)
108
- }
109
- }
110
-
111
- render(context: CanvasRenderingContext2D) {
112
- var { left, top, width, height } = this.state
113
-
114
- var { border } = this.state
115
- border ||= {}
116
-
117
- // Cell 채우기.
118
- context.beginPath()
119
- context.lineWidth = 0
120
- context.rect(left, top, width, height)
121
- this.drawFill(context)
122
-
123
- // Border 그리기
124
- var parent = this.parent as Table
125
- var idx = parent.components.indexOf(this)
126
- var columns = parent.columns || 1
127
- var rows = parent.rows || 1
128
-
129
- this._drawBorder(context, left, top, left + width, top, border.top)
130
- this._drawBorder(context, left, top + height, left, top, border.left)
131
- if (isRightMost(idx, rows, columns, parent.components))
132
- this._drawBorder(context, left + width, top, left + width, top + height, border.right)
133
- if (isBottomMost(idx, rows, columns, parent.components))
134
- this._drawBorder(context, left + width, top + height, left, top + height, border.bottom)
135
- }
136
- }
137
-
138
- Component.register('table-cell', TableCell)