@kaspernj/api-maker 1.0.460 → 1.0.462

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.
Files changed (48) hide show
  1. package/build/bootstrap/attribute-row.js +135 -0
  2. package/build/bootstrap/attribute-rows.js +1 -2
  3. package/build/bootstrap/sort-link.js +4 -4
  4. package/build/config.js +2 -2
  5. package/build/history.js +3 -0
  6. package/build/historyExpo.js +10 -0
  7. package/build/inputs/checkbox.js +1 -8
  8. package/build/link.js +6 -2
  9. package/build/super-admin/layout/header/index.js +23 -14
  10. package/build/super-admin/layout/index.js +64 -10
  11. package/build/super-admin/layout/menu/index.js +131 -20
  12. package/build/table/filters/filter.js +3 -3
  13. package/build/table/header-column.js +3 -3
  14. package/build/table/model-row.js +5 -5
  15. package/build/table/settings/download-action.js +3 -3
  16. package/build/table/table.js +4 -4
  17. package/build/translated-collections.js +2 -2
  18. package/build/use-breakpoint.js +20 -2
  19. package/build/utils/icon.js +23 -0
  20. package/build/utils/modal.js +3 -3
  21. package/build/with-api-maker.js +29 -0
  22. package/package.json +3 -2
  23. package/src/bootstrap/{attribute-row/index.jsx → attribute-row.jsx} +45 -17
  24. package/src/bootstrap/attribute-rows.jsx +0 -2
  25. package/src/bootstrap/sort-link.jsx +3 -3
  26. package/src/config.js +1 -1
  27. package/src/history.js +3 -0
  28. package/src/historyExpo.js +9 -0
  29. package/src/inputs/checkbox.jsx +0 -4
  30. package/src/link.jsx +6 -1
  31. package/src/super-admin/layout/header/index.jsx +27 -16
  32. package/src/super-admin/layout/header/style.scss +0 -11
  33. package/src/super-admin/layout/index.jsx +56 -11
  34. package/src/super-admin/layout/menu/index.jsx +124 -40
  35. package/src/super-admin/layout/menu/style.scss +0 -94
  36. package/src/table/filters/filter.jsx +2 -2
  37. package/src/table/header-column.jsx +2 -2
  38. package/src/table/model-row.jsx +4 -4
  39. package/src/table/settings/download-action.jsx +2 -2
  40. package/src/table/table.jsx +3 -3
  41. package/src/translated-collections.js +1 -1
  42. package/src/use-breakpoint.js +25 -1
  43. package/src/utils/icon.jsx +21 -0
  44. package/src/utils/modal.jsx +2 -2
  45. package/src/with-api-maker.jsx +31 -0
  46. package/build/bootstrap/attribute-row/index.js +0 -111
  47. package/src/bootstrap/attribute-row/basic-style.scss +0 -9
  48. package/src/super-admin/layout/style.scss +0 -25
@@ -1,5 +1,6 @@
1
- // import "../../../../src/super-admin/layout/menu/style"
1
+ import {StyleSheet, View} from "react-native"
2
2
  import BaseComponent from "../../../base-component"
3
+ import Icon from "../../../utils/icon"
3
4
  import memo from "set-state-compare/src/memo"
4
5
  import Link from "../../../link"
5
6
  import MenuContent from "./menu-content"
@@ -10,9 +11,46 @@ import PropTypesExact from "prop-types-exact"
10
11
  import React from "react"
11
12
  import {shapeComponent} from "set-state-compare/src/shape-component"
12
13
  import Text from "../../../utils/text"
14
+ import useBreakpoint from "../../../use-breakpoint"
13
15
  import useCurrentUser from "../../../use-current-user"
14
16
  import useI18n from "i18n-on-steroids/src/use-i18n"
15
- import {View} from "react-native"
17
+ import {WithDefaultStyle} from "../../../utils/default-style"
18
+
19
+ const styles = StyleSheet.create({
20
+ root: {
21
+ base: {
22
+ position: "fixed",
23
+ zIndex: 9,
24
+ overflowY: "auto",
25
+ overflowX: "hidden",
26
+ top: 0,
27
+ left: 0,
28
+ height: "100%",
29
+ flexDirection: "column",
30
+ backgroundColor: "#1b1c1e"
31
+ },
32
+ mdDown: {
33
+ width: "100%",
34
+ maxWidth: 250,
35
+ maxHeight: "100vh",
36
+ overflowY: "auto"
37
+ },
38
+ mdUp: {
39
+ width: 250
40
+ },
41
+ lgUp: {
42
+ width: 290
43
+ }
44
+ },
45
+ userName: {
46
+ flexShrink: 1,
47
+ marginLeft: 8
48
+ },
49
+ userNameContainer: {
50
+ overflow: "hidden",
51
+ maxWidth: 140
52
+ }
53
+ })
16
54
 
17
55
  export default memo(shapeComponent(class ComponentsAdminLayoutMenu extends BaseComponent {
18
56
  static propTypes = PropTypesExact({
@@ -23,53 +61,99 @@ export default memo(shapeComponent(class ComponentsAdminLayoutMenu extends BaseC
23
61
  })
24
62
 
25
63
  setup() {
64
+ const {lgUp, mdDown, mdUp} = useBreakpoint()
26
65
  const {t} = useI18n({namespace: "js.api_maker.super_admin.layout.menu"})
27
66
  const currentUser = useCurrentUser()
28
67
 
29
- this.setInstance({currentUser, t})
68
+ this.setInstance({currentUser, lgUp, mdDown, mdUp, t})
30
69
  }
31
70
 
32
71
  render() {
33
- const {currentUser, t} = this.tt
72
+ const {currentUser, lgUp, mdDown, mdUp, t} = this.tt
34
73
  const {active, noAccess, triggered} = this.props
35
74
 
75
+ const style = [styles.root.base]
76
+
77
+ if (mdDown) style.push(styles.root.mdDown)
78
+ if (mdUp) style.push(styles.root.mdUp)
79
+ if (lgUp) style.push(styles.root.lgUp)
80
+
81
+ if (mdDown && !triggered) {
82
+ return null
83
+ }
84
+
36
85
  return (
37
- <View dataSet={{component: "super-admin--layout--menu", triggered}}>
38
- <div className="menu-logo">
39
- <Link dataSet={{class: "menu-logo-link"}} to={Params.withParams({})}>
40
- <Text>
41
- Admin
42
- </Text>
43
- </Link>
44
- </div>
45
- <div className="menu-items-center">
46
- {!noAccess &&
47
- <MenuContent active={active} />
48
- }
49
- </div>
50
- <div className="menu-items-bottom">
51
- {currentUser &&
52
- <div className="menu-user-section">
53
- <div className="menu-user-icon">
54
- <i className="fa fa-user" />
55
- </div>
56
- <div className="menu-user-name">
57
- <div className="menu-user-name-container">
58
- {currentUser.name()}
59
- </div>
60
- </div>
61
- </div>
62
- }
63
- {currentUser &&
64
- <MenuItem
65
- active
66
- className="sign-out-menu-item"
67
- icon="sign-out-alt"
68
- label={t(".sign_out", {defaultValue: "Sign out"})}
69
- onClick={this.tt.onSignOutClicked}
70
- />
71
- }
72
- </div>
86
+ <View dataSet={{component: "super-admin--layout--menu", triggered}} style={style}>
87
+ <WithDefaultStyle style={{Text: {color: "#fff"}}}>
88
+ <View
89
+ dataSet={{class: "menu-logo"}}
90
+ style={{
91
+ overflow: "hidden",
92
+ marginTop: 25,
93
+ marginRight: "auto",
94
+ marginLeft: "auto"
95
+ }}
96
+ >
97
+ <Link dataSet={{class: "menu-logo-link"}} to={Params.withParams({})}>
98
+ <Text
99
+ style={{
100
+ fontSize: 42,
101
+ textOverflow: "ellipsis",
102
+ whiteSpace: "nowrap"
103
+ }}
104
+ >
105
+ Admin
106
+ </Text>
107
+ </Link>
108
+ </View>
109
+ <View dataSet={{class: "menu-items-center"}} style={{marginTop: 25}}>
110
+ {!noAccess &&
111
+ <MenuContent active={active} />
112
+ }
113
+ </View>
114
+ <View dataSet={{class: "menu-items-bottom"}} style={{marginTop: "auto", marginBottom: 25}}>
115
+ {currentUser &&
116
+ <View
117
+ dataSet={{class: "menu-user-section"}}
118
+ style={{
119
+ flexDirection: "row",
120
+ alignItems: "center",
121
+ marginRight: 25,
122
+ marginBottom: 25,
123
+ marginLeft: 25
124
+ }}
125
+ >
126
+ <View
127
+ dataSet={{class: "menu-user-icon"}}
128
+ style={{
129
+ width: 44,
130
+ height: 44,
131
+ alignItems: "center",
132
+ justifyContent: "center",
133
+ backgroundColor: "#abbcd0",
134
+ borderRadius: "50%"
135
+ }}
136
+ >
137
+ <Icon name="user" size={12} />
138
+ </View>
139
+ <View className="menu-user-name" style={styles.userName}>
140
+ <Text dataSet={{class: "menu-user-name-container"}} style={styles.userNameContainer}>
141
+ {currentUser.name()}
142
+ </Text>
143
+ </View>
144
+ </View>
145
+ }
146
+ {currentUser &&
147
+ <MenuItem
148
+ active
149
+ className="sign-out-menu-item"
150
+ icon="sign-out-alt"
151
+ label={t(".sign_out", {defaultValue: "Sign out"})}
152
+ onClick={this.tt.onSignOutClicked}
153
+ />
154
+ }
155
+ </View>
156
+ </WithDefaultStyle>
73
157
  </View>
74
158
  )
75
159
  }
@@ -1,49 +1,6 @@
1
1
  @use "@kaspernj/api-maker/src/super-admin/stylesheets/variables" as *;
2
2
 
3
3
  [data-component="super-admin--layout--menu"] {
4
- position: fixed;
5
- z-index: 9;
6
- overflow-y: auto;
7
- overflow-x: hidden;
8
- top: 0;
9
- left: 0;
10
- display: flex;
11
- height: 100%;
12
- flex-direction: column;
13
- background: #1b1c1e;
14
- color: #fff;
15
-
16
- @media (max-width: $sm-to) {
17
- width: 100%;
18
- max-width: 250px;
19
- max-height: 100vh;
20
- overflow-y: auto;
21
-
22
- &[data-triggered="false"] {
23
- display: none;
24
- }
25
- }
26
-
27
- @media (min-width: $md-from) {
28
- width: 250px;
29
- }
30
-
31
- @media (min-width: $lg-from) {
32
- width: 290px;
33
- }
34
-
35
- .menu-logo {
36
- overflow: hidden;
37
- width: 80%;
38
- margin-top: 25px;
39
- margin-right: auto;
40
- margin-left: auto;
41
- font-size: 42px;
42
- text-align: center;
43
- text-overflow: ellipsis;
44
- white-space: nowrap;
45
- }
46
-
47
4
  .menu-logo-link {
48
5
  &:link,
49
6
  &:visited {
@@ -51,55 +8,4 @@
51
8
  text-decoration: none;
52
9
  }
53
10
  }
54
-
55
- .menu-items-center {
56
- margin-top: 25px;
57
- }
58
-
59
- .menu-items-bottom {
60
- margin-top: auto;
61
- margin-bottom: 25px;
62
- }
63
-
64
- .menu-user-section {
65
- display: flex;
66
- align-items: center;
67
- margin-right: 25px;
68
- margin-bottom: 25px;
69
- margin-left: 25px;
70
- }
71
-
72
- .menu-user-icon {
73
- display: flex;
74
- width: 44px;
75
- min-width: 44px;
76
- max-width: 44px;
77
- height: 44px;
78
- align-items: center;
79
- justify-content: center;
80
- background: #abbcd0;
81
- border-radius: 50%;
82
- }
83
-
84
- .menu-user-name {
85
- flex-shrink: 1;
86
- margin-left: 8px;
87
- }
88
-
89
- .menu-user-name-container {
90
- overflow: hidden;
91
- max-width: 140px;
92
- }
93
-
94
- .menu-user-items {
95
- position: relative;
96
- margin-left: auto;
97
- }
98
-
99
- .menu-user-items-link {
100
- &:link,
101
- &:visited {
102
- color: #dededf;
103
- }
104
- }
105
11
  }
@@ -1,6 +1,6 @@
1
1
  import {Pressable, View} from "react-native"
2
2
  import BaseComponent from "../../base-component"
3
- import FontAwesomeIcon from "react-native-vector-icons/FontAwesome"
3
+ import Icon from "../../utils/icon"
4
4
  import PropTypes from "prop-types"
5
5
  import PropTypesExact from "prop-types-exact"
6
6
  import memo from "set-state-compare/src/memo"
@@ -47,7 +47,7 @@ export default memo(shapeComponent(class ApiMakerTableFilter extends BaseCompone
47
47
  </Text>
48
48
  </Pressable>
49
49
  <Pressable dataSet={{class: "remove-filter-button"}} onPress={this.tt.onRemoveFilterPressed} style={{marginLeft: 6}}>
50
- <FontAwesomeIcon name="remove" />
50
+ <Icon name="remove" />
51
51
  </Pressable>
52
52
  </View>
53
53
  )
@@ -1,9 +1,9 @@
1
1
  import React, {useMemo} from "react"
2
2
  import BaseComponent from "../base-component"
3
3
  import classNames from "classnames"
4
- import FontAwesomeIcon from "react-native-vector-icons/FontAwesome"
5
4
  import Header from "./components/header"
6
5
  import HeaderColumnContent from "./header-column-content"
6
+ import Icon from "../utils/icon"
7
7
  import memo from "set-state-compare/src/memo"
8
8
  import {Animated, PanResponder} from "react-native"
9
9
  import PropTypes from "prop-types"
@@ -100,7 +100,7 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
100
100
  {...restColumnProps}
101
101
  >
102
102
  {mdUp &&
103
- <FontAwesomeIcon name="bars" style={{marginRight: 3, fontSize: 12}} {...touchProps} />
103
+ <Icon name="bars" style={{marginRight: 3, fontSize: 12}} {...touchProps} />
104
104
  }
105
105
  <HeaderColumnContent column={column} table={table} tableSettingColumn={tableSettingColumn} />
106
106
  {mdUp &&
@@ -4,7 +4,7 @@ import Column from "./components/column"
4
4
  import columnIdentifier from "./column-identifier"
5
5
  import EventEmitter from "events"
6
6
  import FlashMessage from "../flash-message"
7
- import FontAwesomeIcon from "react-native-vector-icons/FontAwesome"
7
+ import Icon from "../utils/icon"
8
8
  import * as inflection from "inflection"
9
9
  import modelCallbackArgs from "./model-callback-args"
10
10
  import Link from "../link"
@@ -76,17 +76,17 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
76
76
  {actionsContent && actionsContent(this.tt.modelCallbackArgs)}
77
77
  {viewPath &&
78
78
  <Link dataSet={{class: "view-button"}} style={{marginLeft: 2, marginRight: 2}} to={viewPath}>
79
- <FontAwesomeIcon name="search" size={18} />
79
+ <Icon name="search" size={18} />
80
80
  </Link>
81
81
  }
82
82
  {editPath &&
83
83
  <Link dataSet={{class: "edit-button"}} style={{marginLeft: 2, marginRight: 2}} to={editPath}>
84
- <FontAwesomeIcon name="pencil" size={20} />
84
+ <Icon name="pencil" size={20} />
85
85
  </Link>
86
86
  }
87
87
  {destroyEnabled && model.can("destroy") &&
88
88
  <Pressable dataSet={{class: "destroy-button"}} style={{marginLeft: 2, marginRight: 2}} onPress={this.tt.onDestroyClicked}>
89
- <FontAwesomeIcon name="remove" size={22} />
89
+ <Icon name="remove" size={22} />
90
90
  </Pressable>
91
91
  }
92
92
  </Column>
@@ -3,7 +3,7 @@ import ColumnContent from "../column-content"
3
3
  import columnIdentifier from "../column-identifier"
4
4
  import columnVisible from "../column-visible"
5
5
  import {saveAs} from "file-saver"
6
- import FontAwesomeIcon from "react-native-vector-icons/FontAwesome"
6
+ import Icon from "../../utils/icon"
7
7
  import memo from "set-state-compare/src/memo"
8
8
  import PropTypes from "prop-types"
9
9
  import propTypesExact from "prop-types-exact"
@@ -21,7 +21,7 @@ export default memo(shapeComponent(class ApiMakerTableSettingsDownloadAction ext
21
21
  render() {
22
22
  return (
23
23
  <Pressable onPress={this.tt.onDownloadPress} style={{flexDirection: "row", alignItems: "center"}}>
24
- <FontAwesomeIcon name="download" size={20} />
24
+ <Icon name="download" size={20} />
25
25
  <Text style={{marginLeft: 5}}>
26
26
  Download
27
27
  </Text>
@@ -11,11 +11,11 @@ import DraggableSort from "../draggable-sort/index"
11
11
  import EventEmitter from "events"
12
12
  import Filters from "./filters"
13
13
  import FlatList from "./components/flat-list"
14
- import FontAwesomeIcon from "react-native-vector-icons/FontAwesome"
15
14
  import {Form} from "../form"
16
15
  import Header from "./components/header"
17
16
  import HeaderColumn from "./header-column"
18
17
  import HeaderSelect from "./header-select"
18
+ import Icon from "../utils/icon"
19
19
  import * as inflection from "inflection"
20
20
  import memo from "set-state-compare/src/memo"
21
21
  import modelClassRequire from "../model-class-require"
@@ -732,14 +732,14 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
732
732
  <View style={{flexDirection: "row"}}>
733
733
  {controls && controls({models, qParams, query, result})}
734
734
  <Pressable dataSet={{class: "filter-button"}} onPress={this.tt.onFilterClicked}>
735
- <FontAwesomeIcon name="search" size={20} />
735
+ <Icon name="search" size={20} />
736
736
  </Pressable>
737
737
  <View style={{position: "relative"}}>
738
738
  {showSettings &&
739
739
  <Settings onRequestClose={this.tt.onRequestCloseSettings} table={this} />
740
740
  }
741
741
  <Pressable dataSet={{class: "settings-button"}} onPress={this.tt.onSettingsClicked}>
742
- <FontAwesomeIcon name="gear" size={20} />
742
+ <Icon name="gear" size={20} />
743
743
  </Pressable>
744
744
  </View>
745
745
  </View>
@@ -1,6 +1,6 @@
1
1
  import {digg} from "diggerize"
2
2
  import I18nOnSteroids from "i18n-on-steroids"
3
- import translatedCollectionsData from "../src/translated-collections-data.js.erb"
3
+ import translatedCollectionsData from "translated-collections-data.json"
4
4
 
5
5
  export default class ApiMakerTranslatedCollections {
6
6
  static get (modelClass, collectionName) {
@@ -1,6 +1,7 @@
1
1
  import {useCallback, useLayoutEffect} from "react"
2
2
  import apiMakerConfig from "@kaspernj/api-maker/build/config"
3
3
  import {Dimensions} from "react-native"
4
+ import * as inflection from "inflection"
4
5
  import useShape from "set-state-compare/src/use-shape"
5
6
 
6
7
  const calculateBreakPoint = (window) => {
@@ -26,6 +27,8 @@ const calculateBreakPoint = (window) => {
26
27
  throw new Error(`Couldn't not find breakpoint from window width: ${windowWidth}`)
27
28
  }
28
29
 
30
+ const sizeTypes = ["down", "up"]
31
+
29
32
  const useBreakpoint = () => {
30
33
  const s = useShape()
31
34
  const onCalled = useCallback(({window}) => {
@@ -40,13 +43,34 @@ const useBreakpoint = () => {
40
43
  breakpoint: () => calculateBreakPoint(Dimensions.get("window"))
41
44
  })
42
45
 
46
+ const styling = useCallback((args) => {
47
+ const style = Object.assign({}, args.base)
48
+
49
+ for (const breakpointData of apiMakerConfig.getBreakPoints()) {
50
+ const breakpoint = breakpointData[0]
51
+
52
+ for (const sizeType of sizeTypes) {
53
+ const breakpointWithSizeType = `${breakpoint}${inflection.camelize(sizeType)}`
54
+
55
+ if (args[breakpointWithSizeType] && s.s.breakpoint[breakpointWithSizeType]) {
56
+ Object.assign(style, args[breakpointWithSizeType])
57
+ }
58
+ }
59
+ }
60
+
61
+ return style
62
+ }, [])
63
+
43
64
  useLayoutEffect(() => {
44
65
  const subscription = Dimensions.addEventListener("change", onCalled)
45
66
 
46
67
  return () => subscription?.remove()
47
68
  })
48
69
 
49
- return s.s.breakpoint
70
+ return {
71
+ styling,
72
+ ...s.s.breakpoint
73
+ }
50
74
  }
51
75
 
52
76
  export default useBreakpoint
@@ -0,0 +1,21 @@
1
+ import BaseComponent from "../base-component"
2
+ import FontAwesomeIcon from "react-native-vector-icons/FontAwesome"
3
+ import memo from "set-state-compare/src/memo"
4
+ import React from "react"
5
+ import {shapeComponent} from "set-state-compare/src/shape-component"
6
+ import {useDefaultStyle} from "./default-style"
7
+
8
+ export default memo(shapeComponent(class ApiMakerUtilsIcon extends BaseComponent {
9
+ render() {
10
+ const defaultStyle = useDefaultStyle()
11
+ const {style, ...restProps} = this.props
12
+ const actualStyle = Object.assign(
13
+ {color: defaultStyle.Text.color},
14
+ style
15
+ )
16
+
17
+ return (
18
+ <FontAwesomeIcon style={actualStyle} {...restProps} />
19
+ )
20
+ }
21
+ }))
@@ -1,7 +1,7 @@
1
1
  import {Modal, Pressable, View} from "react-native"
2
2
  import BaseComponent from "../base-component"
3
3
  import Card from "./card"
4
- import FontAwesomeIcon from "react-native-vector-icons/FontAwesome"
4
+ import Icon from "../utils/icon"
5
5
  import memo from "set-state-compare/src/memo"
6
6
  import {shapeComponent} from "set-state-compare/src/shape-component"
7
7
  import useBreakpoint from "../use-breakpoint"
@@ -50,7 +50,7 @@ export default memo(shapeComponent(class ApiMakerUtilsComponent extends BaseComp
50
50
  cardHeaderControls() {
51
51
  return (
52
52
  <Pressable onPress={this.tt.onModalClosePress} style={{marginLeft: "auto", padding: 5}}>
53
- <FontAwesomeIcon name="remove" />
53
+ <Icon name="remove" />
54
54
  </Pressable>
55
55
  )
56
56
  }
@@ -0,0 +1,31 @@
1
+ import React, {createContext, useContext, useMemo} from "react"
2
+ import ApiMakerConfig from "./config"
3
+ import memo from "set-state-compare/src/memo"
4
+
5
+ const ApiMakerContext = createContext()
6
+ const useApiMaker = () => {
7
+ const apiMakerContext = useContext(ApiMakerContext)
8
+
9
+ if (apiMakerContext) {
10
+ return apiMakerContext
11
+ }
12
+
13
+ return {
14
+ config: ApiMakerConfig
15
+ }
16
+ }
17
+
18
+ const WithApiMaker = memo(({children, config, ...restProps}) => {
19
+ const restPropsKeys = Object.keys(restProps)
20
+ const value = useMemo(() => ({config}), [config])
21
+
22
+ if (restPropsKeys.length > 0) throw new Error(`Unhandled props: ${restPropsKeys.join(", ")}`)
23
+
24
+ return (
25
+ <ApiMakerContext.Provider value={value}>
26
+ {children}
27
+ </ApiMakerContext.Provider>
28
+ )
29
+ })
30
+
31
+ export {useApiMaker, WithApiMaker}