@operato/scene-table 7.3.9 → 7.3.19

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,171 +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
-
6
- export type WHERE = 'all' | 'in' | 'out' | 'left' | 'right' | 'center' | 'middle' | 'top' | 'bottom' | 'clear'
7
-
8
- export const SIDES: { [key: string]: string[] } = {
9
- all: ['top', 'left', 'bottom', 'right'],
10
- out: ['top', 'left', 'bottom', 'right'],
11
- left: ['left'],
12
- right: ['right'],
13
- top: ['top'],
14
- bottom: ['bottom'],
15
- leftright: ['left', 'right'],
16
- topbottom: ['top', 'bottom']
17
- }
18
-
19
- export const CLEAR_STYLE = {
20
- strokeStyle: '',
21
- lineDash: 'solid',
22
- lineWidth: 0
23
- }
24
-
25
- export const DEFAULT_STYLE = {
26
- strokeStyle: '#999',
27
- lineDash: 'solid',
28
- lineWidth: 1
29
- }
30
-
31
- export function buildNewCell(type: string, app: ApplicationContext): TableCell {
32
- return Model.compile(
33
- {
34
- type,
35
- left: 0,
36
- top: 0,
37
- width: 1,
38
- height: 1,
39
- textWrap: true,
40
- border: buildBorderStyle(DEFAULT_STYLE, 'all')
41
- },
42
- app
43
- ) as TableCell
44
- }
45
-
46
- export function buildCopiedCell(copy: Model, app: ApplicationContext): TableCell {
47
- var obj = JSON.parse(JSON.stringify(copy))
48
- delete obj.text
49
- delete obj.refid
50
-
51
- return Model.compile(obj, app) as TableCell
52
- }
53
-
54
- export function buildBorderStyle(style: Style, where: string) {
55
- return (SIDES[where] || []).reduce((border: { [key: string]: any }, side: string) => {
56
- border[side] = style
57
- return border
58
- }, {} as { [key: string]: any })
59
- }
60
-
61
- export function setCellBorder(cell: any, style: Style, where: string) {
62
- if (!cell) return
63
- cell.set('border', merge({}, cell.getState('border') || {}, buildBorderStyle(style, where)))
64
- }
65
-
66
- export function isLeftMost(total: number, columns: number, indices: number[], i: number) {
67
- return i == 0 || !(i % columns) || indices.indexOf(i - 1) == -1
68
- }
69
-
70
- export function isRightMost(total: number, columns: number, indices: number[], i: number) {
71
- return i == total - 1 || i % columns == columns - 1 || indices.indexOf(i + 1) == -1
72
- }
73
-
74
- export function isTopMost(total: number, columns: number, indices: number[], i: number) {
75
- return i < columns || indices.indexOf(i - columns) == -1
76
- }
77
-
78
- export function isBottomMost(total: number, columns: number, indices: number[], i: number) {
79
- return i > total - columns - 1 || indices.indexOf(i + columns) == -1
80
- }
81
-
82
- export function above(columns: number, i: number) {
83
- return i - columns
84
- }
85
-
86
- export function below(columns: number, i: number) {
87
- return i + columns
88
- }
89
-
90
- export function before(columns: number, i: number) {
91
- return !(i % columns) ? -1 : i - 1
92
- }
93
-
94
- export function after(columns: number, i: number) {
95
- return !((i + 1) % columns) ? -1 : i + 1
96
- }
97
-
98
- export function array(value: any, size: number) {
99
- var arr = []
100
- for (let i = 0; i < size; i++) arr.push(1)
101
- return arr
102
- }
103
-
104
- export var columnControlHandler = {
105
- ondragmove: function (point: POINT, index: number, component: Table) {
106
- var { left, width } = component.textBounds
107
- var widths_sum = component.widths_sum
108
-
109
- var widths = component.widths.slice()
110
-
111
- /* 컨트롤의 원래 위치를 구한다. */
112
- var origin_pos_unit = widths.slice(0, index + 1).reduce((sum: number, width: number) => sum + width, 0)
113
- var origin_offset = left + (origin_pos_unit / widths_sum) * width
114
-
115
- /*
116
- * point의 좌표는 부모 레이어 기준의 x, y 값이다.
117
- * 따라서, 도형의 회전을 감안한 좌표로의 변환이 필요하다.
118
- * Transcoord시에는 point좌표가 부모까지 transcoord되어있는 상태이므로,
119
- * 컴포넌트자신에 대한 transcoord만 필요하다.(마지막 파라미터를 false로).
120
- */
121
- var transcoorded = component.transcoordP2S(point.x, point.y)
122
- var diff = transcoorded.x - origin_offset
123
-
124
- var diff_unit = (diff / width) * widths_sum
125
-
126
- var min_width_unit = (widths_sum / width) * 10 // 10픽셀정도를 최소로
127
-
128
- if (diff_unit < 0) diff_unit = -Math.min(widths[index] - min_width_unit, -diff_unit)
129
- else diff_unit = Math.min(widths[index + 1] - min_width_unit, diff_unit)
130
-
131
- widths[index] = Math.round((widths[index] + diff_unit) * 100) / 100
132
- widths[index + 1] = Math.round((widths[index + 1] - diff_unit) * 100) / 100
133
-
134
- component.set('widths', widths)
135
- }
136
- }
137
-
138
- export var rowControlHandler = {
139
- ondragmove: function (point: POINT, index: number, component: Table) {
140
- var { top, height } = component.textBounds
141
- var heights_sum = component.heights_sum
142
-
143
- var heights = component.heights.slice()
144
-
145
- /* 컨트롤의 원래 위치를 구한다. */
146
- index -= component.columns - 1
147
- var origin_pos_unit = heights.slice(0, index + 1).reduce((sum: number, height: number) => sum + height, 0)
148
- var origin_offset = top + (origin_pos_unit / heights_sum) * height
149
-
150
- /*
151
- * point의 좌표는 부모 레이어 기준의 x, y 값이다.
152
- * 따라서, 도형의 회전을 감안한 좌표로의 변환이 필요하다.
153
- * Transcoord시에는 point좌표가 부모까지 transcoord되어있는 상태이므로,
154
- * 컴포넌트자신에 대한 transcoord만 필요하다.(마지막 파라미터를 false로).
155
- */
156
- var transcoorded = component.transcoordP2S(point.x, point.y)
157
- var diff = transcoorded.y - origin_offset
158
-
159
- var diff_unit = (diff / height) * heights_sum
160
-
161
- var min_height_unit = (heights_sum / height) * 10 // 10픽셀정도를 최소로
162
-
163
- if (diff_unit < 0) diff_unit = -Math.min(heights[index] - min_height_unit, -diff_unit)
164
- else diff_unit = Math.min(heights[index + 1] - min_height_unit, diff_unit)
165
-
166
- heights[index] = Math.round((heights[index] + diff_unit) * 100) / 100
167
- heights[index + 1] = Math.round((heights[index + 1] - diff_unit) * 100) / 100
168
-
169
- component.set('heights', heights)
170
- }
171
- }
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)