@kaspernj/api-maker 1.0.381 → 1.0.382

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaspernj/api-maker",
3
- "version": "1.0.381",
3
+ "version": "1.0.382",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "index.js",
@@ -13,6 +13,7 @@ import {useRef} from "react"
13
13
  export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseComponent {
14
14
  static propTypes = propTypesExact({
15
15
  column: PropTypes.object.isRequired,
16
+ fixedTableLayout: PropTypes.bool.isRequired,
16
17
  table: PropTypes.object.isRequired,
17
18
  tableSettingColumn: PropTypes.object.isRequired
18
19
  })
@@ -32,7 +33,7 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
32
33
  }
33
34
 
34
35
  render() {
35
- const {column, table, tableSettingColumn} = this.p
36
+ const {column, fixedTableLayout, table, tableSettingColumn} = this.p
36
37
  const {width} = this.s
37
38
  const {defaultParams} = table.props
38
39
  const {query} = digs(table.collection, "query")
@@ -55,11 +56,13 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
55
56
  {table.headerLabelForColumn(column)}
56
57
  </Text>
57
58
  }
58
- <Pressable onPressIn={this.tt.onResizePressIn} style={{marginLeft: "auto", cursor: "col-resize"}}>
59
- <Text>
60
- |
61
- </Text>
62
- </Pressable>
59
+ {fixedTableLayout &&
60
+ <Pressable onPressIn={this.tt.onResizePressIn} style={{marginLeft: "auto", cursor: "col-resize"}}>
61
+ <Text>
62
+ |
63
+ </Text>
64
+ </Pressable>
65
+ }
63
66
  </View>
64
67
  </ColumnInHeadComponent>
65
68
  )
@@ -7,22 +7,31 @@ import * as inflection from "inflection"
7
7
  import Link from "../link"
8
8
  import MoneyFormatter from "../money-formatter"
9
9
  import PropTypes from "prop-types"
10
+ import propTypesExact from "prop-types-exact"
10
11
  import {memo} from "react"
11
12
  import {shapeComponent} from "set-state-compare/src/shape-component"
12
13
 
13
14
  const WorkerPluginsCheckbox = React.lazy(() => import("./worker-plugins-checkbox"))
14
15
 
15
16
  export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow extends BaseComponent {
16
- static propTypes = {
17
+ static propTypes = propTypesExact({
17
18
  cacheKey: PropTypes.string.isRequired,
19
+ columnComponent: PropTypes.oneOfType([
20
+ PropTypes.func,
21
+ PropTypes.string
22
+ ]).isRequired,
18
23
  model: PropTypes.object.isRequired,
19
24
  liveTable: PropTypes.object.isRequired,
20
25
  preparedColumns: PropTypes.array,
26
+ rowComponent: PropTypes.oneOfType([
27
+ PropTypes.func,
28
+ PropTypes.string
29
+ ]).isRequired,
21
30
  tableSettingFullCacheKey: PropTypes.string.isRequired
22
- }
31
+ })
23
32
 
24
33
  render() {
25
- const {model} = this.p
34
+ const {columnComponent: ColumnComponent, model, rowComponent: RowComponent} = this.p
26
35
  const {modelClass, workplace} = this.p.liveTable.p
27
36
  const {actionsContent, columnsContent, destroyEnabled, editModelPath, viewModelPath} = this.p.liveTable.props
28
37
  const {columns, currentWorkplace} = this.p.liveTable.state
@@ -34,9 +43,6 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
34
43
  if (editModelPath && model.can("edit")) editPath = editModelPath(this.modelCallbackArgs)
35
44
  if (viewModelPath && model.can("show")) viewPath = viewModelPath(this.modelCallbackArgs)
36
45
 
37
- const RowComponent = this.props.rowComponent
38
- const ColumnComponent = this.props.columnComponent
39
-
40
46
  return (
41
47
  <RowComponent className={`live-table-row ${inflection.dasherize(modelClass.modelClassData().paramKey)}-row`} data-model-id={model.id()}>
42
48
  {workplace &&
@@ -0,0 +1,88 @@
1
+ import BaseComponent from "../../base-component"
2
+ import columnIdentifier from "../column-identifier.mjs"
3
+ import PropTypes from "prop-types"
4
+ import propTypesExact from "prop-types-exact"
5
+ import {memo, useEffect, useRef} from "react"
6
+ import {shapeComponent} from "set-state-compare/src/shape-component.js"
7
+ import {View} from "react-native"
8
+
9
+ export default memo(shapeComponent(class ColumnRow extends BaseComponent {
10
+ static propTypes = propTypesExact({
11
+ column: PropTypes.object.isRequired,
12
+ table: PropTypes.object.isRequired,
13
+ tableSettingColumn: PropTypes.object.isRequired
14
+ })
15
+
16
+ setup() {
17
+ this.checked = this.p.tableSettingColumn.visible()
18
+ this.checkboxRef = useRef()
19
+
20
+ useEffect(() => {
21
+ this.updateCheckboxChecked()
22
+ }, [this.checked])
23
+ }
24
+
25
+ render() {
26
+ const {column, table, tableSettingColumn} = this.p
27
+ const checkboxProps = {}
28
+
29
+ if (tableSettingColumn.visible() === true) {
30
+ checkboxProps.checked = "checked"
31
+ } else if (tableSettingColumn.visible() === null) {
32
+ checkboxProps.indeterminate = "indeterminate"
33
+ }
34
+
35
+ return (
36
+ <View dataSet={{component: "api-maker--table--settings--column-row"}} style={{justifyContent: "center"}}>
37
+ <label style={{whiteSpace: "nowrap"}}>
38
+ <input
39
+ className="api-maker--table--setings--column-checkbox"
40
+ data-identifier={columnIdentifier(column)}
41
+ onChange={this.onCheckboxChange}
42
+ ref={this.checkboxRef}
43
+ type="checkbox"
44
+ {...checkboxProps}
45
+ />
46
+ {table.headerLabelForColumn(column)}
47
+ </label>
48
+ </View>
49
+ )
50
+ }
51
+
52
+ onCheckboxChange = () => {
53
+ const {checked} = this
54
+
55
+ if (checked === true) {
56
+ this.checked = null
57
+ } else if (checked === null) {
58
+ this.checked = false
59
+ } else {
60
+ this.checked = true
61
+ }
62
+
63
+ this.updateCheckboxChecked()
64
+ this.updateTableSettingColumn()
65
+ }
66
+
67
+ updateCheckboxChecked() {
68
+ const {checked} = this.tt
69
+
70
+ if (checked === true) {
71
+ this.checkboxRef.current.checked = true
72
+ this.checkboxRef.current.indeterminate = undefined
73
+ } else if (checked === null) {
74
+ this.checkboxRef.current.checked = undefined
75
+ this.checkboxRef.current.indeterminate = true
76
+ } else {
77
+ this.checkboxRef.current.checked = undefined
78
+ this.checkboxRef.current.indeterminate = undefined
79
+ }
80
+ }
81
+
82
+ async updateTableSettingColumn() {
83
+ const {table, tableSettingColumn} = this.p
84
+
85
+ await tableSettingColumn.update({visible: this.checked})
86
+ table.updateSettingsFullCacheKey()
87
+ }
88
+ }))
@@ -1,107 +1,53 @@
1
1
  import "./style"
2
+ import BaseComponent from "../../base-component"
3
+ import Checkbox from "../../utils/checkbox"
2
4
  import columnIdentifier from "../column-identifier.mjs"
3
- import EventListener from "../../event-listener.jsx"
5
+ import ColumnRow from "./column-row"
6
+ import {memo, useRef} from "react"
4
7
  import PropTypes from "prop-types"
5
- import React from "react"
6
-
7
- class ColumnRow extends React.PureComponent {
8
- static propTypes = {
9
- column: PropTypes.object.isRequired,
10
- table: PropTypes.object.isRequired,
11
- tableSettingColumn: PropTypes.object.isRequired
12
- }
13
-
14
- checked = this.props.tableSettingColumn.visible()
15
- checkboxRef = React.createRef()
16
-
17
- componentDidMount() {
18
- this.updateCheckboxChecked()
19
- }
20
-
21
- componentDidUpdate() {
22
- this.updateCheckboxChecked()
23
- }
24
-
25
- render() {
26
- const {column, table, tableSettingColumn} = this.props
27
- const checkboxProps = {}
28
-
29
- if (tableSettingColumn.visible() === true) {
30
- checkboxProps.checked = "checked"
31
- } else if (tableSettingColumn.visible() === null) {
32
- checkboxProps.indeterminate = "indeterminate"
33
- }
34
-
35
- return (
36
- <div className="api-maker--table--settings--column-row">
37
- <label style={{whiteSpace: "nowrap"}}>
38
- <input
39
- className="api-maker--table--setings--column-checkbox"
40
- data-identifier={columnIdentifier(column)}
41
- onChange={this.onCheckboxChange}
42
- ref={this.checkboxRef}
43
- type="checkbox"
44
- {...checkboxProps}
45
- />
46
- {table.headerLabelForColumn(column)}
47
- </label>
48
- </div>
49
- )
50
- }
51
-
52
- onCheckboxChange = () => {
53
- const {checked} = this
54
-
55
- if (checked === true) {
56
- this.checked = null
57
- } else if (checked === null) {
58
- this.checked = false
59
- } else {
60
- this.checked = true
61
- }
62
-
63
- this.updateCheckboxChecked()
64
- this.updateTableSettingColumn()
65
- }
66
-
67
- updateCheckboxChecked() {
68
- const {checked} = this
69
-
70
- if (checked === true) {
71
- this.checkboxRef.current.checked = true
72
- this.checkboxRef.current.indeterminate = undefined
73
- } else if (checked === null) {
74
- this.checkboxRef.current.checked = undefined
75
- this.checkboxRef.current.indeterminate = true
76
- } else {
77
- this.checkboxRef.current.checked = undefined
78
- this.checkboxRef.current.indeterminate = undefined
79
- }
80
- }
81
-
82
- async updateTableSettingColumn() {
83
- const {table, tableSettingColumn} = this.props
84
-
85
- await tableSettingColumn.update({visible: this.checked})
86
- table.updateSettingsFullCacheKey()
87
- }
88
- }
89
-
90
- export default class ApiMakerTableSettings extends React.PureComponent {
91
- static propTypes = {
8
+ import propTypesExact from "prop-types-exact"
9
+ import {shapeComponent} from "set-state-compare/src/shape-component.js"
10
+ import useEventListener from "../../use-event-listener"
11
+ import {Text, View} from "react-native"
12
+
13
+ export default memo(shapeComponent(class ApiMakerTableSettings extends BaseComponent {
14
+ static propTypes = propTypesExact({
15
+ onFixedTableLayoutChanged: PropTypes.func.isRequired,
92
16
  onRequestClose: PropTypes.func.isRequired,
93
17
  table: PropTypes.object.isRequired
18
+ })
19
+
20
+ setup() {
21
+ this.rootRef = useRef()
22
+
23
+ useEventListener(window, "mouseup", this.tt.onWindowMouseUp)
24
+ this.useStates({
25
+ fixedTableLayout: this.tableSetting().fixedTableLayout()
26
+ })
94
27
  }
95
28
 
96
- rootRef = React.createRef()
29
+ tableSetting = () => this.p.table.s.tableSetting
97
30
 
98
31
  render() {
99
- const {table} = this.props
100
- const {preparedColumns} = table.state
32
+ const {table} = this.p
33
+ const {fixedTableLayout} = this.s
34
+ const {preparedColumns} = table.s
101
35
 
102
36
  return (
103
- <div className="api-maker--table--settings" ref={this.rootRef}>
104
- <EventListener event="mouseup" onCalled={this.onWindowMouseUp} target={window} />
37
+ <div className="api-maker--table--settings" ref={this.tt.rootRef}>
38
+ <View style={{marginBottom: 5}}>
39
+ <Text style={{fontSize: 16, fontWeight: "bold"}}>
40
+ Settings
41
+ </Text>
42
+ </View>
43
+ <View>
44
+ <Checkbox checked={fixedTableLayout} label="Fixed table" onValueChange={this.tt.onFixedTableChecked} />
45
+ </View>
46
+ <View style={{marginBottom: 5}}>
47
+ <Text style={{fontSize: 16, fontWeight: "bold"}}>
48
+ Columns
49
+ </Text>
50
+ </View>
105
51
  {preparedColumns?.map(({column, tableSettingColumn}) =>
106
52
  <ColumnRow column={column} key={columnIdentifier(column)} table={table} tableSettingColumn={tableSettingColumn} />
107
53
  )}
@@ -109,9 +55,15 @@ export default class ApiMakerTableSettings extends React.PureComponent {
109
55
  )
110
56
  }
111
57
 
58
+ onFixedTableChecked = async (checked) => {
59
+ await this.tableSetting().update({fixedTableLayout: true})
60
+ this.setState({fixedTableLayout: checked})
61
+ this.p.onFixedTableLayoutChanged(checked)
62
+ }
63
+
112
64
  onWindowMouseUp = (e) => {
113
- if (this.rootRef.current && !this.rootRef.current.contains(e.target)) {
114
- this.props.onRequestClose()
65
+ if (this.tt.rootRef.current && !this.tt.rootRef.current.contains(e.target)) {
66
+ this.p.onRequestClose()
115
67
  }
116
68
  }
117
- }
69
+ }))
@@ -1,8 +1,10 @@
1
1
  @import "./variables";
2
2
 
3
3
  .api-maker--table {
4
- table {
5
- table-layout: fixed;
4
+ &[data-fixed-table-layout="true"] {
5
+ table {
6
+ table-layout: fixed;
7
+ }
6
8
  }
7
9
 
8
10
  .live-table-header {
@@ -99,6 +99,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
99
99
  this.useStates({
100
100
  columns: columnsAsArray,
101
101
  currentWorkplace: undefined,
102
+ fixedTableLayout: undefined,
102
103
  identifier: () => this.props.identifier || `${collectionKey}-default`,
103
104
  preload: undefined,
104
105
  preparedColumns: undefined,
@@ -163,6 +164,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
163
164
  const {columns, preload} = this.tableSettings.preparedColumns(tableSetting)
164
165
 
165
166
  this.setState({
167
+ fixedTableLayout: tableSetting.fixedTableLayout(),
166
168
  preparedColumns: columns,
167
169
  preload: this.mergedPreloads(preload),
168
170
  tableSetting,
@@ -219,7 +221,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
219
221
  }
220
222
 
221
223
  return (
222
- <div className={this.className()}>
224
+ <div className={this.className()} data-fixed-table-layout={this.s.fixedTableLayout}>
223
225
  {showNoRecordsAvailableContent &&
224
226
  <div className="live-table--no-records-available-content">
225
227
  {noRecordsAvailableContent({models, qParams, overallCount})}
@@ -395,6 +397,10 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
395
397
  this.setState({showFilters: !this.state.showFilters})
396
398
  }
397
399
 
400
+ onFixedTableLayoutChanged = (fixedTableLayout) => {
401
+ this.setState({fixedTableLayout})
402
+ }
403
+
398
404
  onPerPageChanged = (e) => {
399
405
  const {queryName} = this.s
400
406
  const newPerPageValue = digg(e, "target", "value")
@@ -419,7 +425,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
419
425
  </a>
420
426
  <span style={{position: "relative"}}>
421
427
  {showSettings &&
422
- <Settings onRequestClose={this.tt.onRequestCloseSettings} table={this} />
428
+ <Settings onFixedTableLayoutChanged={this.tt.onFixedTableLayoutChanged} onRequestClose={this.tt.onRequestCloseSettings} table={this} />
423
429
  }
424
430
  <a className="settings-button" href="#" onClick={this.tt.onSettingsClicked}>
425
431
  <i className="fa fa-fw fa-gear la la-fw la-gear" />
@@ -431,7 +437,6 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
431
437
 
432
438
  tableContent () {
433
439
  const {workplace} = this.p
434
- const {breakpoint} = this.tt
435
440
  const {currentWorkplace, preparedColumns, tableSettingFullCacheKey} = this.s
436
441
  const {models, query} = digs(this.collection, "models", "query")
437
442
  const ColumnInHeadComponent = this.columnInHeadComponent()
@@ -463,7 +468,6 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
463
468
  <BodyComponent>
464
469
  {models.map((model) =>
465
470
  <ModelRow
466
- breakPoint={breakpoint}
467
471
  cacheKey={model.cacheKey()}
468
472
  columnComponent={this.columnComponent()}
469
473
  key={model.id()}
@@ -537,7 +541,13 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
537
541
  rowComponent = () => this.responsiveComponent("tr")
538
542
 
539
543
  headersContentFromColumns = () => this.s.preparedColumns?.map(({column, tableSettingColumn}) => columnVisible(column, tableSettingColumn) &&
540
- <HeaderColumn column={column} key={tableSettingColumn.identifier()} table={this} tableSettingColumn={tableSettingColumn} />
544
+ <HeaderColumn
545
+ column={column}
546
+ fixedTableLayout={this.s.fixedTableLayout}
547
+ key={tableSettingColumn.identifier()}
548
+ table={this}
549
+ tableSettingColumn={tableSettingColumn}
550
+ />
541
551
  )
542
552
 
543
553
  headerClassNameForColumn (column) {
@@ -0,0 +1,33 @@
1
+ import BaseComponent from "../base-component"
2
+ import {CheckBox, Text, View} from "react-native"
3
+ import {memo} from "react"
4
+ import PropTypes from "prop-types"
5
+ import propTypesExact from "prop-types-exact"
6
+ import {shapeComponent} from "set-state-compare/src/shape-component.js"
7
+
8
+ export default memo(shapeComponent(class ApiMakerUtilsCheckbox extends BaseComponent {
9
+ static defaultProps = {
10
+ label: undefined
11
+ }
12
+
13
+ static propTypes = propTypesExact({
14
+ checked: PropTypes.bool.isRequired,
15
+ label: PropTypes.string,
16
+ onValueChange: PropTypes.func.isRequired
17
+ })
18
+
19
+ render() {
20
+ const {checked, label, onValueChange} = this.p
21
+
22
+ return (
23
+ <View dataSet={{component: "api-maker--utils--checkbox"}} style={{flexDirection: "row", alignItems: "center"}}>
24
+ <CheckBox onValueChange={onValueChange} value={checked} />
25
+ {label &&
26
+ <Text style={{marginLeft: 3}}>
27
+ {label}
28
+ </Text>
29
+ }
30
+ </View>
31
+ )
32
+ }
33
+ }))