@kaspernj/api-maker 1.0.408 → 1.0.410
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.
- package/package.json +1 -1
- package/src/bootstrap/sort-link.jsx +2 -2
- package/src/table/header-column.jsx +40 -8
- package/src/table/model-row.jsx +18 -13
- package/src/table/table.jsx +65 -7
package/package.json
CHANGED
|
@@ -54,7 +54,7 @@ export default memo(shapeComponent(class ApiMakerBootstrapSortLink extends BaseC
|
|
|
54
54
|
|
|
55
55
|
render () {
|
|
56
56
|
const LinkComponent = this.linkComponent()
|
|
57
|
-
const {attribute, className, defaultParams, linkComponent, onChanged, query, title, ...restProps} = this.props
|
|
57
|
+
const {attribute, className, defaultParams, linkComponent, onChanged, query, textProps, title, ...restProps} = this.props
|
|
58
58
|
|
|
59
59
|
return (
|
|
60
60
|
<LinkComponent
|
|
@@ -67,7 +67,7 @@ export default memo(shapeComponent(class ApiMakerBootstrapSortLink extends BaseC
|
|
|
67
67
|
to={this.href()}
|
|
68
68
|
{...restProps}
|
|
69
69
|
>
|
|
70
|
-
<Text>
|
|
70
|
+
<Text {...textProps}>
|
|
71
71
|
{this.title()}
|
|
72
72
|
</Text>
|
|
73
73
|
</LinkComponent>
|
|
@@ -3,7 +3,7 @@ import classNames from "classnames"
|
|
|
3
3
|
import {digs} from "diggerize"
|
|
4
4
|
import Header from "./components/header"
|
|
5
5
|
import {memo} from "react"
|
|
6
|
-
import {Pressable, Text, View} from "react-native"
|
|
6
|
+
import {Platform, Pressable, Text, View} from "react-native"
|
|
7
7
|
import PropTypes from "prop-types"
|
|
8
8
|
import propTypesExact from "prop-types-exact"
|
|
9
9
|
import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
@@ -14,6 +14,7 @@ import Widths from "./widths"
|
|
|
14
14
|
export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseComponent {
|
|
15
15
|
static propTypes = propTypesExact({
|
|
16
16
|
column: PropTypes.object.isRequired,
|
|
17
|
+
resizing: PropTypes.bool.isRequired,
|
|
17
18
|
table: PropTypes.object.isRequired,
|
|
18
19
|
tableSettingColumn: PropTypes.object.isRequired,
|
|
19
20
|
width: PropTypes.number.isRequired,
|
|
@@ -32,8 +33,9 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
|
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
render() {
|
|
35
|
-
const {column, table, tableSettingColumn, width} = this.p
|
|
36
|
+
const {column, resizing, table, tableSettingColumn, width} = this.p
|
|
36
37
|
const {defaultParams} = table.props
|
|
38
|
+
const {styleForHeader, styleForHeaderText} = table.tt
|
|
37
39
|
const {query} = digs(table.collection, "query")
|
|
38
40
|
|
|
39
41
|
return (
|
|
@@ -43,7 +45,10 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
|
|
|
43
45
|
identifier: tableSettingColumn.identifier()
|
|
44
46
|
}}
|
|
45
47
|
onLayout={this.tt.onLayout}
|
|
46
|
-
style={{
|
|
48
|
+
style={styleForHeader({style: {
|
|
49
|
+
cursor: resizing ? "col-resize" : undefined,
|
|
50
|
+
width: `${width}%`
|
|
51
|
+
}})}
|
|
47
52
|
{...table.columnProps(column)}
|
|
48
53
|
>
|
|
49
54
|
<View style={{display: "flex", flexDirection: "row", alignItems: "center"}}>
|
|
@@ -53,6 +58,7 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
|
|
|
53
58
|
defaultParams={defaultParams}
|
|
54
59
|
query={query}
|
|
55
60
|
style={{whiteSpace: "nowrap", overflow: "hidden"}}
|
|
61
|
+
textProps={{ellipsizeMode: "clip", numberOfLines: 1, style: styleForHeaderText()}}
|
|
56
62
|
title={table.headerLabelForColumn(column)}
|
|
57
63
|
/>
|
|
58
64
|
}
|
|
@@ -61,12 +67,20 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
|
|
|
61
67
|
{table.headerLabelForColumn(column)}
|
|
62
68
|
</Text>
|
|
63
69
|
}
|
|
64
|
-
<Pressable onPressIn={this.tt.onResizePressIn} style={{marginLeft: "auto", cursor: "col-resize"}}>
|
|
65
|
-
<Text>
|
|
66
|
-
|
|
|
67
|
-
</Text>
|
|
68
|
-
</Pressable>
|
|
69
70
|
</View>
|
|
71
|
+
<Pressable
|
|
72
|
+
onMouseDown={Platform.OS == "web" ? this.tt.onResizeMouseDown : undefined}
|
|
73
|
+
onPressIn={this.tt.onResizePressIn}
|
|
74
|
+
style={{
|
|
75
|
+
position: "absolute",
|
|
76
|
+
top: 0,
|
|
77
|
+
right: 0,
|
|
78
|
+
width: 10,
|
|
79
|
+
height: "100%",
|
|
80
|
+
cursor: "col-resize",
|
|
81
|
+
zIndex: 9999
|
|
82
|
+
}}
|
|
83
|
+
/>
|
|
70
84
|
</Header>
|
|
71
85
|
)
|
|
72
86
|
}
|
|
@@ -79,12 +93,29 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
|
|
|
79
93
|
|
|
80
94
|
onResizeEnd = async () => {
|
|
81
95
|
this.setState({cursorX: undefined, resizing: false})
|
|
96
|
+
this.p.table.setState({resizing: false})
|
|
82
97
|
|
|
83
98
|
const width = this.p.widths.getWidthOfColumn(this.p.tableSettingColumn.identifier())
|
|
84
99
|
|
|
85
100
|
await this.p.tableSettingColumn.update({width})
|
|
86
101
|
}
|
|
87
102
|
|
|
103
|
+
// Otherwise text is selectable on web
|
|
104
|
+
onResizeMouseDown = (e) => {
|
|
105
|
+
e.preventDefault()
|
|
106
|
+
e.stopPropagation()
|
|
107
|
+
|
|
108
|
+
const originalWidth = this.currentWidth
|
|
109
|
+
const cursorX = e.nativeEvent.pageX
|
|
110
|
+
|
|
111
|
+
this.setState({
|
|
112
|
+
cursorX,
|
|
113
|
+
originalWidth,
|
|
114
|
+
resizing: true
|
|
115
|
+
})
|
|
116
|
+
this.p.table.setState({resizing: true})
|
|
117
|
+
}
|
|
118
|
+
|
|
88
119
|
onResizePressIn = (e) => {
|
|
89
120
|
e.preventDefault()
|
|
90
121
|
e.stopPropagation()
|
|
@@ -97,6 +128,7 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
|
|
|
97
128
|
originalWidth,
|
|
98
129
|
resizing: true
|
|
99
130
|
})
|
|
131
|
+
this.p.table.setState({resizing: true})
|
|
100
132
|
}
|
|
101
133
|
|
|
102
134
|
onWindowMouseMove = (e) => {
|
package/src/table/model-row.jsx
CHANGED
|
@@ -21,6 +21,7 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
|
|
|
21
21
|
static propTypes = propTypesExact({
|
|
22
22
|
cacheKey: PropTypes.string.isRequired,
|
|
23
23
|
columnWidths: PropTypes.object.isRequired,
|
|
24
|
+
index: PropTypes.number.isRequired,
|
|
24
25
|
isSmallScreen: PropTypes.bool.isRequired,
|
|
25
26
|
model: PropTypes.object.isRequired,
|
|
26
27
|
liveTable: PropTypes.object.isRequired,
|
|
@@ -29,10 +30,12 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
|
|
|
29
30
|
})
|
|
30
31
|
|
|
31
32
|
render() {
|
|
32
|
-
const {model} = this.p
|
|
33
|
-
const {modelClass, workplace} =
|
|
34
|
-
const {actionsContent,
|
|
35
|
-
const {columns, currentWorkplace} =
|
|
33
|
+
const {index, liveTable, model} = this.p
|
|
34
|
+
const {modelClass, workplace} = liveTable.p
|
|
35
|
+
const {actionsContent, destroyEnabled, editModelPath, viewModelPath} = liveTable.props
|
|
36
|
+
const {columns, currentWorkplace} = liveTable.state
|
|
37
|
+
const {styleForColumn, styleForRow} = liveTable.tt
|
|
38
|
+
const even = index % 2 == 0
|
|
36
39
|
|
|
37
40
|
this.modelCallbackArgs = this._modelCallbackArgs() // 'model' can change so this needs to be re-cached for every render
|
|
38
41
|
|
|
@@ -47,9 +50,12 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
|
|
|
47
50
|
}
|
|
48
51
|
|
|
49
52
|
return (
|
|
50
|
-
<Row
|
|
53
|
+
<Row
|
|
54
|
+
dataSet={{class: `${inflection.dasherize(modelClass.modelClassData().paramKey)}-row`, modelId: model.id()}}
|
|
55
|
+
style={styleForRow({even})}
|
|
56
|
+
>
|
|
51
57
|
{workplace &&
|
|
52
|
-
<Column dataSet={{class: "workplace-column"}} style={{width:
|
|
58
|
+
<Column dataSet={{class: "workplace-column"}} style={styleForColumn({even, style: {width: 41}})}>
|
|
53
59
|
<WorkerPluginsCheckbox
|
|
54
60
|
currentWorkplace={currentWorkplace}
|
|
55
61
|
model={model}
|
|
@@ -57,9 +63,8 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
|
|
|
57
63
|
/>
|
|
58
64
|
</Column>
|
|
59
65
|
}
|
|
60
|
-
{columns && this.columnsContentFromColumns(model)}
|
|
61
|
-
{
|
|
62
|
-
<Column dataSet={{class: "actions-column"}} style={{flexDirection: "row"}}>
|
|
66
|
+
{columns && this.columnsContentFromColumns(model, even)}
|
|
67
|
+
<Column dataSet={{class: "actions-column"}} style={styleForColumn({even, style: {flexDirection: "row"}, type: "actions"})}>
|
|
63
68
|
{actionsContent && actionsContent(this.modelCallbackArgs)}
|
|
64
69
|
{viewPath &&
|
|
65
70
|
<Link dataSet={{class: "view-button"}} to={viewPath}>
|
|
@@ -81,7 +86,7 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
|
|
|
81
86
|
)
|
|
82
87
|
}
|
|
83
88
|
|
|
84
|
-
columnClassNamesForColumn
|
|
89
|
+
columnClassNamesForColumn(column) {
|
|
85
90
|
const classNames = ["table--column"]
|
|
86
91
|
|
|
87
92
|
if (column.commonProps && column.commonProps.className) classNames.push(column.commonProps.className)
|
|
@@ -90,17 +95,17 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
|
|
|
90
95
|
return classNames
|
|
91
96
|
}
|
|
92
97
|
|
|
93
|
-
columnsContentFromColumns
|
|
98
|
+
columnsContentFromColumns(model, even) {
|
|
94
99
|
const {isSmallScreen, preparedColumns} = this.p
|
|
95
100
|
|
|
96
|
-
return preparedColumns?.map(({column, tableSettingColumn, width}) => columnVisible(column, tableSettingColumn) &&
|
|
101
|
+
return preparedColumns?.map(({column, tableSettingColumn, width}, columnIndex) => columnVisible(column, tableSettingColumn) &&
|
|
97
102
|
<Column
|
|
98
103
|
dataSet={{
|
|
99
104
|
class: classNames(this.columnClassNamesForColumn(column)),
|
|
100
105
|
identifier: columnIdentifier(column)
|
|
101
106
|
}}
|
|
102
107
|
key={columnIdentifier(column)}
|
|
103
|
-
style={{width: `${width}%`}}
|
|
108
|
+
style={this.p.liveTable.styleForColumn({column, columnIndex, even, style: {width: `${width}%`}})}
|
|
104
109
|
{...this.props.liveTable.columnProps(column)}
|
|
105
110
|
>
|
|
106
111
|
{isSmallScreen &&
|
package/src/table/table.jsx
CHANGED
|
@@ -55,7 +55,6 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
55
55
|
className: PropTypes.string,
|
|
56
56
|
collection: PropTypes.instanceOf(Collection),
|
|
57
57
|
columns: PropTypes.oneOfType([PropTypes.array, PropTypes.func]),
|
|
58
|
-
columnsContent: PropTypes.func,
|
|
59
58
|
controls: PropTypes.func,
|
|
60
59
|
currentUser: PropTypes.object,
|
|
61
60
|
defaultDateFormatName: PropTypes.string,
|
|
@@ -116,6 +115,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
116
115
|
queryQName: () => `${queryName}_q`,
|
|
117
116
|
queryPageName: () => `${queryName}_page`,
|
|
118
117
|
querySName,
|
|
118
|
+
resizing: false,
|
|
119
119
|
showFilters: () => Boolean(queryParams[querySName]),
|
|
120
120
|
showSettings: false,
|
|
121
121
|
tableSetting: undefined,
|
|
@@ -297,7 +297,6 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
297
297
|
className,
|
|
298
298
|
collection,
|
|
299
299
|
columns,
|
|
300
|
-
columnsContent,
|
|
301
300
|
controls,
|
|
302
301
|
currentUser,
|
|
303
302
|
defaultDateFormatName,
|
|
@@ -351,12 +350,14 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
351
350
|
const flatList = (
|
|
352
351
|
<FlatList
|
|
353
352
|
data={models}
|
|
354
|
-
dataSet={{class: className}}
|
|
353
|
+
dataSet={{class: classNames("api-maker--table", className)}}
|
|
355
354
|
extraData={this.s.lastUpdate}
|
|
356
355
|
keyExtractor={this.tt.keyExtrator}
|
|
357
356
|
ListHeaderComponent={this.tt.listHeaderComponent}
|
|
358
357
|
onLayout={this.tt.onFlatListLayout}
|
|
359
358
|
renderItem={this.tt.renderItem}
|
|
359
|
+
showsHorizontalScrollIndicator
|
|
360
|
+
style={{border: "1px solid #dbdbdb", borderRadius: 5, overflowX: "auto"}}
|
|
360
361
|
{...restProps}
|
|
361
362
|
/>
|
|
362
363
|
)
|
|
@@ -453,9 +454,9 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
453
454
|
const {query} = digs(this.collection, "query")
|
|
454
455
|
|
|
455
456
|
return (
|
|
456
|
-
<Row dataSet={{class: "live-table-header-row"}}>
|
|
457
|
+
<Row dataSet={{class: "live-table-header-row"}} style={this.styleForRow()}>
|
|
457
458
|
{workplace && currentWorkplace &&
|
|
458
|
-
<Header style={{width:
|
|
459
|
+
<Header style={this.styleForHeader({style: {width: 41}})}>
|
|
459
460
|
<WorkerPluginsCheckAllCheckbox
|
|
460
461
|
currentWorkplace={currentWorkplace}
|
|
461
462
|
query={query}
|
|
@@ -464,18 +465,19 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
464
465
|
</Header>
|
|
465
466
|
}
|
|
466
467
|
{this.headersContentFromColumns()}
|
|
467
|
-
<Header />
|
|
468
|
+
<Header style={this.styleForHeader({style: {}, type: "actions"})} />
|
|
468
469
|
</Row>
|
|
469
470
|
)
|
|
470
471
|
}
|
|
471
472
|
|
|
472
|
-
renderItem = ({item: model}) => {
|
|
473
|
+
renderItem = ({index, item: model}) => {
|
|
473
474
|
const {preparedColumns, tableSettingFullCacheKey} = this.s
|
|
474
475
|
|
|
475
476
|
return (
|
|
476
477
|
<ModelRow
|
|
477
478
|
cacheKey={model.cacheKey()}
|
|
478
479
|
columnWidths={this.columnWidths()}
|
|
480
|
+
index={index}
|
|
479
481
|
isSmallScreen={this.tt.isSmallScreen}
|
|
480
482
|
key={model.id()}
|
|
481
483
|
liveTable={this}
|
|
@@ -486,6 +488,61 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
486
488
|
)
|
|
487
489
|
}
|
|
488
490
|
|
|
491
|
+
styleForColumn({column, columnIndex, even, style, type}) {
|
|
492
|
+
const defaultStyle = {
|
|
493
|
+
justifyContent: "center",
|
|
494
|
+
padding: 8,
|
|
495
|
+
backgroundColor: even ? "#f5f5f5" : undefined
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
if (type != "actions") {
|
|
499
|
+
defaultStyle.borderRight = "1px solid #dbdbdb"
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
const actualStyle = Object.assign(
|
|
503
|
+
defaultStyle,
|
|
504
|
+
style
|
|
505
|
+
)
|
|
506
|
+
|
|
507
|
+
return actualStyle
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
styleForHeader({column, columnIndex, style, type}) {
|
|
511
|
+
const defaultStyle = {
|
|
512
|
+
padding: 8
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
if (type != "actions") {
|
|
516
|
+
defaultStyle.borderRight = "1px solid #dbdbdb"
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
const actualStyle = Object.assign(
|
|
520
|
+
defaultStyle,
|
|
521
|
+
style
|
|
522
|
+
)
|
|
523
|
+
|
|
524
|
+
return actualStyle
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
styleForHeaderText() {
|
|
528
|
+
const actualStyle = {fontWeight: "bold"}
|
|
529
|
+
|
|
530
|
+
return actualStyle
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
styleForRow({even} = {}) {
|
|
534
|
+
const actualStyle = {
|
|
535
|
+
flex: 1,
|
|
536
|
+
alignItems: "stretch"
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
if (even) {
|
|
540
|
+
actualStyle.backgroundColor = "#f5f5f5"
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
return actualStyle
|
|
544
|
+
}
|
|
545
|
+
|
|
489
546
|
tableControls() {
|
|
490
547
|
const {controls} = this.props
|
|
491
548
|
const {showSettings} = this.s
|
|
@@ -570,6 +627,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
570
627
|
<HeaderColumn
|
|
571
628
|
column={column}
|
|
572
629
|
key={tableSettingColumn.identifier()}
|
|
630
|
+
resizing={this.s.resizing}
|
|
573
631
|
table={this}
|
|
574
632
|
tableSettingColumn={tableSettingColumn}
|
|
575
633
|
width={width}
|