@kaspernj/api-maker 1.0.401 → 1.0.402

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,6 +1,7 @@
1
1
  import BaseComponent from "../base-component"
2
2
  import classNames from "classnames"
3
3
  import {digs} from "diggerize"
4
+ import Header from "./components/header"
4
5
  import {memo} from "react"
5
6
  import {Pressable, Text, View} from "react-native"
6
7
  import PropTypes from "prop-types"
@@ -8,51 +9,41 @@ import propTypesExact from "prop-types-exact"
8
9
  import {shapeComponent} from "set-state-compare/src/shape-component"
9
10
  import SortLink from "../bootstrap/sort-link"
10
11
  import useEventListener from "../use-event-listener.mjs"
11
- import {useRef} from "react"
12
+ import Widths from "./widths"
12
13
 
13
14
  export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseComponent {
14
15
  static propTypes = propTypesExact({
15
16
  column: PropTypes.object.isRequired,
16
- fixedTableLayout: PropTypes.bool.isRequired,
17
17
  table: PropTypes.object.isRequired,
18
- tableSettingColumn: PropTypes.object.isRequired
18
+ tableSettingColumn: PropTypes.object.isRequired,
19
+ width: PropTypes.number.isRequired,
20
+ widths: PropTypes.instanceOf(Widths).isRequired
19
21
  })
20
22
 
21
23
  setup() {
22
- this.columnRef = useRef()
23
-
24
24
  useEventListener(window, "mousemove", this.tt.onWindowMouseMove)
25
25
  useEventListener(window, "mouseup", this.tt.onWindowMouseUp)
26
26
 
27
27
  this.useStates({
28
28
  cursorX: undefined,
29
29
  originalWidth: undefined,
30
- resizing: false,
31
- width: this.p.tableSettingColumn.width()
30
+ resizing: false
32
31
  })
33
32
  }
34
33
 
35
34
  render() {
36
- const {column, fixedTableLayout, table, tableSettingColumn} = this.p
37
- const {width} = this.s
35
+ const {column, table, tableSettingColumn, width} = this.p
38
36
  const {defaultParams} = table.props
39
37
  const {query} = digs(table.collection, "query")
40
- const ColumnInHeadComponent = table.columnInHeadComponent()
41
- let sortLinkStyle
42
- let textProps = {}
43
-
44
- if (fixedTableLayout) {
45
- sortLinkStyle = {whiteSpace: "nowrap", overflow: "hidden"}
46
- textProps.ellipsizeMode="clip"
47
- textProps.numberOfLines = 1
48
- }
49
38
 
50
39
  return (
51
- <ColumnInHeadComponent
52
- className={classNames(...table.headerClassNameForColumn(column))}
53
- data-identifier={tableSettingColumn.identifier()}
54
- ref={this.tt.columnRef}
55
- style={{width}}
40
+ <Header
41
+ dataSet={{
42
+ className: classNames(...table.headerClassNameForColumn(column)),
43
+ identifier: tableSettingColumn.identifier()
44
+ }}
45
+ onLayout={this.tt.onLayout}
46
+ style={{width: `${width}%`}}
56
47
  {...table.columnProps(column)}
57
48
  >
58
49
  <View style={{display: "flex", flexDirection: "row", alignItems: "center"}}>
@@ -61,40 +52,44 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
61
52
  attribute={tableSettingColumn.sortKey()}
62
53
  defaultParams={defaultParams}
63
54
  query={query}
64
- style={sortLinkStyle}
55
+ style={{whiteSpace: "nowrap", overflow: "hidden"}}
65
56
  title={table.headerLabelForColumn(column)}
66
57
  />
67
58
  }
68
59
  {(!tableSettingColumn.hasSortKey() || !query) &&
69
- <Text {...textProps}>
60
+ <Text ellipsizeMode="clip" numberOfLines={1}>
70
61
  {table.headerLabelForColumn(column)}
71
62
  </Text>
72
63
  }
73
- {fixedTableLayout &&
74
- <Pressable onPressIn={this.tt.onResizePressIn} style={{marginLeft: "auto", cursor: "col-resize"}}>
75
- <Text>
76
- |
77
- </Text>
78
- </Pressable>
79
- }
64
+ <Pressable onPressIn={this.tt.onResizePressIn} style={{marginLeft: "auto", cursor: "col-resize"}}>
65
+ <Text>
66
+ |
67
+ </Text>
68
+ </Pressable>
80
69
  </View>
81
- </ColumnInHeadComponent>
70
+ </Header>
82
71
  )
83
72
  }
84
73
 
74
+ onLayout = (e) => {
75
+ const {width} = e.nativeEvent.layout
76
+
77
+ this.currentWidth = width
78
+ }
79
+
85
80
  onResizeEnd = async () => {
86
81
  this.setState({cursorX: undefined, resizing: false})
87
82
 
88
- await this.p.tableSettingColumn.update({
89
- width: this.s.width
90
- })
83
+ const width = this.p.widths.getWidthOfColumn(this.p.tableSettingColumn.identifier())
84
+
85
+ await this.p.tableSettingColumn.update({width})
91
86
  }
92
87
 
93
88
  onResizePressIn = (e) => {
94
89
  e.preventDefault()
95
90
  e.stopPropagation()
96
91
 
97
- const originalWidth = this.s.width || this.tt.columnRef.current.offsetWidth
92
+ const originalWidth = this.currentWidth
98
93
  const cursorX = e.nativeEvent.pageX
99
94
 
100
95
  this.setState({
@@ -112,7 +107,10 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
112
107
  const diffX = newCursorX - cursorX
113
108
  const newWidth = originalWidth + diffX
114
109
 
115
- this.setState({width: newWidth})
110
+ this.p.widths.setWidthOfColumn({
111
+ identifier: this.p.tableSettingColumn.identifier(),
112
+ width: newWidth
113
+ })
116
114
  }
117
115
  }
118
116
 
@@ -1,5 +1,7 @@
1
+ import {Pressable, Text, View} from "react-native"
1
2
  import BaseComponent from "../base-component"
2
3
  import classNames from "classnames"
4
+ import Column from "./components/column"
3
5
  import columnIdentifier from "./column-identifier.mjs"
4
6
  import columnVisible from "./column-visible.mjs"
5
7
  import {digs} from "diggerize"
@@ -8,6 +10,7 @@ import Link from "../link"
8
10
  import MoneyFormatter from "../money-formatter"
9
11
  import PropTypes from "prop-types"
10
12
  import propTypesExact from "prop-types-exact"
13
+ import Row from "./components/row"
11
14
  import {memo} from "react"
12
15
  import {shapeComponent} from "set-state-compare/src/shape-component"
13
16
 
@@ -16,22 +19,16 @@ const WorkerPluginsCheckbox = React.lazy(() => import("./worker-plugins-checkbox
16
19
  export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow extends BaseComponent {
17
20
  static propTypes = propTypesExact({
18
21
  cacheKey: PropTypes.string.isRequired,
19
- columnComponent: PropTypes.oneOfType([
20
- PropTypes.func,
21
- PropTypes.string
22
- ]).isRequired,
22
+ columnWidths: PropTypes.object.isRequired,
23
+ isSmallScreen: PropTypes.bool.isRequired,
23
24
  model: PropTypes.object.isRequired,
24
25
  liveTable: PropTypes.object.isRequired,
25
26
  preparedColumns: PropTypes.array,
26
- rowComponent: PropTypes.oneOfType([
27
- PropTypes.func,
28
- PropTypes.string
29
- ]).isRequired,
30
27
  tableSettingFullCacheKey: PropTypes.string.isRequired
31
28
  })
32
29
 
33
30
  render() {
34
- const {columnComponent: ColumnComponent, model, rowComponent: RowComponent} = this.p
31
+ const {model} = this.p
35
32
  const {modelClass, workplace} = this.p.liveTable.p
36
33
  const {actionsContent, columnsContent, destroyEnabled, editModelPath, viewModelPath} = this.p.liveTable.props
37
34
  const {columns, currentWorkplace} = this.p.liveTable.state
@@ -40,42 +37,57 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
40
37
 
41
38
  let editPath, viewPath
42
39
 
43
- if (editModelPath && model.can("edit")) editPath = editModelPath(this.modelCallbackArgs)
44
- if (viewModelPath && model.can("show")) viewPath = viewModelPath(this.modelCallbackArgs)
40
+ if (editModelPath && model.can("edit")) {
41
+ editPath = editModelPath(this.modelCallbackArgs)
42
+ }
43
+
44
+ if (viewModelPath && model.can("show")) {
45
+ viewPath = viewModelPath(this.modelCallbackArgs)
46
+ }
45
47
 
46
48
  return (
47
- <RowComponent className={`live-table-row ${inflection.dasherize(modelClass.modelClassData().paramKey)}-row`} data-model-id={model.id()}>
49
+ <Row dataSet={{class: `${inflection.dasherize(modelClass.modelClassData().paramKey)}-row`, modelId: model.id()}}>
48
50
  {workplace &&
49
- <ColumnComponent className="workplace-column" style={{width: 25, textAlign: "center"}}>
50
- <WorkerPluginsCheckbox currentWorkplace={currentWorkplace} model={model} />
51
- </ColumnComponent>
51
+ <Column dataSet={{class: "workplace-column"}} style={{width: 25}}>
52
+ <WorkerPluginsCheckbox
53
+ currentWorkplace={currentWorkplace}
54
+ model={model}
55
+ style={{marginHorizontal: "auto"}}
56
+ />
57
+ </Column>
52
58
  }
53
59
  {columns && this.columnsContentFromColumns(model)}
54
60
  {!columns && columnsContent && columnsContent(this.modelCallbackArgs)}
55
- <ColumnComponent className="actions-column">
61
+ <Column dataSet={{class: "actions-column"}} style={{flexDirection: "row"}}>
56
62
  {actionsContent && actionsContent(this.modelCallbackArgs)}
57
63
  {viewPath &&
58
- <Link className="view-button" to={viewPath}>
59
- <i className="fa fa-search la la-search" />
64
+ <Link dataSet={{class: "view-button"}} to={viewPath}>
65
+ <Text>
66
+ &#x1F50D;
67
+ </Text>
60
68
  </Link>
61
69
  }
62
70
  {editPath &&
63
- <Link className="edit-button" to={editPath}>
64
- <i className="fa fa-edit la la-edit" />
71
+ <Link dataSet={{class: "edit-button"}} to={editPath}>
72
+ <Text>
73
+ &#x270E;
74
+ </Text>
65
75
  </Link>
66
76
  }
67
77
  {destroyEnabled && model.can("destroy") &&
68
- <a className="destroy-button" href="#" onClick={this.onDestroyClicked}>
69
- <i className="fa fa-trash la la-trash" />
70
- </a>
78
+ <Pressable dataSet={{class: "destroy-button"}} onPress={this.tt.onDestroyClicked}>
79
+ <Text>
80
+ &#x2715;
81
+ </Text>
82
+ </Pressable>
71
83
  }
72
- </ColumnComponent>
73
- </RowComponent>
84
+ </Column>
85
+ </Row>
74
86
  )
75
87
  }
76
88
 
77
89
  columnClassNamesForColumn (column) {
78
- const classNames = ["live-table-column"]
90
+ const classNames = ["table--column"]
79
91
 
80
92
  if (column.commonProps && column.commonProps.className) classNames.push(column.commonProps.className)
81
93
  if (column.columnProps && column.columnProps.className) classNames.push(column.columnProps.className)
@@ -84,24 +96,30 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
84
96
  }
85
97
 
86
98
  columnsContentFromColumns (model) {
87
- const {preparedColumns} = this.p
88
- const ColumnComponent = this.props.columnComponent
89
-
90
- return preparedColumns?.map(({column, tableSettingColumn}) => columnVisible(column, tableSettingColumn) &&
91
- <ColumnComponent
92
- className={classNames(this.columnClassNamesForColumn(column))}
93
- data-identifier={columnIdentifier(column)}
99
+ const {isSmallScreen, preparedColumns} = this.p
100
+
101
+ return preparedColumns?.map(({column, tableSettingColumn, width}) => columnVisible(column, tableSettingColumn) &&
102
+ <Column
103
+ dataSet={{
104
+ class: classNames(this.columnClassNamesForColumn(column)),
105
+ identifier: columnIdentifier(column)
106
+ }}
94
107
  key={columnIdentifier(column)}
108
+ style={{width: `${width}%`}}
95
109
  {...this.props.liveTable.columnProps(column)}
96
110
  >
97
- <div className="live-table-column-label">
98
- {this.props.liveTable.headerLabelForColumn(column)}
99
- </div>
100
- <div className="live-table-column-value">
111
+ {isSmallScreen &&
112
+ <View dataSet={{class: "table--column-label"}}>
113
+ <Text>
114
+ {this.props.liveTable.headerLabelForColumn(column)}
115
+ </Text>
116
+ </View>
117
+ }
118
+ <View dataSet={{class: "table--column-value"}}>
101
119
  {column.content && this.columnContentFromContentArg(column, model)}
102
120
  {!column.content && column.attribute && this.columnsContentFromAttributeAndPath(column, model)}
103
- </div>
104
- </ColumnComponent>
121
+ </View>
122
+ </Column>
105
123
  )
106
124
  }
107
125
 
@@ -135,7 +153,9 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
135
153
  const modelColumn = attribute?.getColumn()
136
154
 
137
155
  if (modelColumn?.getType() == "date") {
138
- return this.presentDateTime({apiMakerType: "date", value})
156
+ return (
157
+ <Text>{this.presentDateTime({apiMakerType: "date", value})}</Text>
158
+ )
139
159
  }
140
160
 
141
161
  return this.presentColumnValue(value)
@@ -151,9 +171,7 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
151
171
  return modelCallbackArgs
152
172
  }
153
173
 
154
- onDestroyClicked = async (e) => {
155
- e.preventDefault()
156
-
174
+ onDestroyClicked = async () => {
157
175
  const {destroyMessage} = this.p.liveTable.props
158
176
  const {model} = this.p
159
177
 
@@ -174,21 +192,28 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
174
192
 
175
193
  presentColumnValue(value) {
176
194
  if (value instanceof Date) {
177
- return this.presentDateTime({value})
195
+ return <Text>{this.presentDateTime({value})}</Text>
178
196
  } else if (MoneyFormatter.isMoney(value)) {
179
- return MoneyFormatter.format(value)
197
+ return <Text>{MoneyFormatter.format(value)}</Text>
180
198
  } else if (typeof value == "boolean") {
181
199
  if (value) return I18n.t("js.shared.yes", {defaultValue: "Yes"})
182
200
 
183
- return I18n.t("js.shared.no", {defaultValue: "No"})
201
+ return <Text>{I18n.t("js.shared.no", {defaultValue: "No"})}</Text>
184
202
  } else if (Array.isArray(value)) {
185
- return value
186
- .map((valuePart) => this.presentColumnValue(valuePart))
187
- .filter((valuePart) => Boolean(valuePart))
188
- .join(", ")
203
+ return (
204
+ <Text>
205
+ {value
206
+ .map((valuePart) => this.presentColumnValue(valuePart))
207
+ .filter((valuePart) => Boolean(valuePart))
208
+ .join(", ")
209
+ }
210
+ </Text>
211
+ )
212
+ } else if (typeof value == "string") {
213
+ return <Text>{value}</Text>
189
214
  }
190
215
 
191
- return value
216
+ return <Text>{value}</Text>
192
217
  }
193
218
 
194
219
  presentDateTime({apiMakerType, value}) {
@@ -33,7 +33,7 @@ export default memo(shapeComponent(class ColumnRow extends BaseComponent {
33
33
  }
34
34
 
35
35
  return (
36
- <View dataSet={{component: "api-maker--table--settings--column-row"}} style={{justifyContent: "center"}}>
36
+ <View dataSet={{component: "api-maker--table--settings--column-row"}} style={{zIndex: 1, justifyContent: "center"}}>
37
37
  <label style={{whiteSpace: "nowrap"}}>
38
38
  <input
39
39
  className="api-maker--table--setings--column-checkbox"
@@ -1,6 +1,5 @@
1
1
  import "./style"
2
2
  import BaseComponent from "../../base-component"
3
- import Checkbox from "../../utils/checkbox"
4
3
  import columnIdentifier from "../column-identifier.mjs"
5
4
  import ColumnRow from "./column-row"
6
5
  import {memo, useRef} from "react"
@@ -12,7 +11,6 @@ import {Text, View} from "react-native"
12
11
 
13
12
  export default memo(shapeComponent(class ApiMakerTableSettings extends BaseComponent {
14
13
  static propTypes = propTypesExact({
15
- onFixedTableLayoutChanged: PropTypes.func.isRequired,
16
14
  onRequestClose: PropTypes.func.isRequired,
17
15
  table: PropTypes.object.isRequired
18
16
  })
@@ -30,7 +28,6 @@ export default memo(shapeComponent(class ApiMakerTableSettings extends BaseCompo
30
28
 
31
29
  render() {
32
30
  const {table} = this.p
33
- const {fixedTableLayout} = this.s
34
31
  const {preparedColumns} = table.s
35
32
 
36
33
  return (
@@ -40,9 +37,6 @@ export default memo(shapeComponent(class ApiMakerTableSettings extends BaseCompo
40
37
  Settings
41
38
  </Text>
42
39
  </View>
43
- <View>
44
- <Checkbox checked={fixedTableLayout} label="Fixed table" onValueChange={this.tt.onFixedTableChecked} />
45
- </View>
46
40
  <View style={{marginBottom: 5}}>
47
41
  <Text style={{fontSize: 16, fontWeight: "bold"}}>
48
42
  Columns
@@ -55,12 +49,6 @@ export default memo(shapeComponent(class ApiMakerTableSettings extends BaseCompo
55
49
  )
56
50
  }
57
51
 
58
- onFixedTableChecked = async (checked) => {
59
- await this.tableSetting().update({fixed_table_layout: checked})
60
- this.setState({fixedTableLayout: checked})
61
- this.p.onFixedTableLayoutChanged(checked)
62
- }
63
-
64
52
  onWindowMouseUp = (e) => {
65
53
  if (this.tt.rootRef.current && !this.tt.rootRef.current.contains(e.target)) {
66
54
  this.p.onRequestClose()
@@ -50,10 +50,6 @@
50
50
  }
51
51
 
52
52
  .live-table-column {
53
- .live-table-column-label {
54
- display: none;
55
- }
56
-
57
53
  &[data-text-align="center"] {
58
54
  .live-table-column-value {
59
55
  text-align: center;