@jsonui/core 0.0.11 → 0.1.0

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 (86) hide show
  1. package/README.md +20 -0
  2. package/dist/cjs/index.js +14600 -0
  3. package/dist/cjs/index.js.map +1 -0
  4. package/dist/cjs/types/index.d.ts +13 -0
  5. package/dist/{stock → cjs/types/stock}/Stock.d.ts +27 -27
  6. package/dist/cjs/types/stock/Stock.test.d.ts +1 -0
  7. package/dist/{stock → cjs/types/stock}/appRootFunctions.d.ts +7 -7
  8. package/dist/{stock → cjs/types/stock}/functions.d.ts +7 -7
  9. package/dist/{stock → cjs/types/stock}/validation.d.ts +7 -7
  10. package/dist/{store → cjs/types/store}/persistConfig.d.ts +8 -8
  11. package/dist/{store → cjs/types/store}/reducers.d.ts +4 -4
  12. package/dist/{store → cjs/types/store}/root/actions.d.ts +10 -10
  13. package/dist/{store → cjs/types/store}/root/reducer.d.ts +4 -4
  14. package/dist/cjs/types/store/root/reducer.test.d.ts +1 -0
  15. package/dist/cjs/types/store/root/selector.test.d.ts +1 -0
  16. package/dist/{store → cjs/types/store}/root/selectors.d.ts +11 -11
  17. package/dist/{util → cjs/types/utils}/I18n.d.ts +27 -27
  18. package/dist/cjs/types/utils/I18n.test.d.ts +1 -0
  19. package/dist/{utils → cjs/types/utils}/constants.d.ts +23 -19
  20. package/dist/{utils → cjs/types/utils}/contextHandler.d.ts +4 -4
  21. package/dist/{util → cjs/types/utils}/jsonRefResolver.d.ts +2 -2
  22. package/dist/{utils → cjs/types/utils}/types.d.ts +27 -27
  23. package/dist/cjs/types/utils/util.d.ts +18 -0
  24. package/dist/cjs/types/utils/util.test.d.ts +1 -0
  25. package/dist/{wrapper → cjs/types/wrapper}/wrapperUtil.d.ts +15 -15
  26. package/dist/esm/index.js +14600 -0
  27. package/dist/esm/index.js.map +1 -0
  28. package/dist/esm/types/index.d.ts +13 -0
  29. package/dist/esm/types/stock/Stock.d.ts +27 -0
  30. package/dist/esm/types/stock/Stock.test.d.ts +1 -0
  31. package/dist/esm/types/stock/appRootFunctions.d.ts +7 -0
  32. package/dist/esm/types/stock/functions.d.ts +7 -0
  33. package/dist/esm/types/stock/validation.d.ts +7 -0
  34. package/dist/esm/types/store/persistConfig.d.ts +8 -0
  35. package/dist/esm/types/store/reducers.d.ts +4 -0
  36. package/dist/esm/types/store/root/actions.d.ts +10 -0
  37. package/dist/esm/types/store/root/reducer.d.ts +4 -0
  38. package/dist/esm/types/store/root/reducer.test.d.ts +1 -0
  39. package/dist/esm/types/store/root/selector.test.d.ts +1 -0
  40. package/dist/esm/types/store/root/selectors.d.ts +11 -0
  41. package/dist/{utils → esm/types/utils}/I18n.d.ts +27 -27
  42. package/dist/esm/types/utils/I18n.test.d.ts +1 -0
  43. package/dist/{util → esm/types/utils}/constants.d.ts +23 -19
  44. package/dist/esm/types/utils/contextHandler.d.ts +4 -0
  45. package/dist/{utils → esm/types/utils}/jsonRefResolver.d.ts +2 -2
  46. package/dist/{util → esm/types/utils}/types.d.ts +27 -27
  47. package/dist/esm/types/utils/util.d.ts +18 -0
  48. package/dist/esm/types/utils/util.test.d.ts +1 -0
  49. package/dist/esm/types/wrapper/wrapperUtil.d.ts +15 -0
  50. package/dist/index.d.ts +273 -14
  51. package/package.json +22 -9
  52. package/.eslintrc.json +0 -51
  53. package/.prettierrc +0 -6
  54. package/dist/index.cjs +0 -2
  55. package/dist/index.cjs.map +0 -1
  56. package/dist/index.modern.js +0 -2
  57. package/dist/index.modern.js.map +0 -1
  58. package/dist/index.module.mjs +0 -2
  59. package/dist/index.module.mjs.map +0 -1
  60. package/dist/index.umd.js +0 -2
  61. package/dist/index.umd.js.map +0 -1
  62. package/dist/store/renderers/actions.d.ts +0 -10
  63. package/dist/store/renderers/reducer.d.ts +0 -2
  64. package/dist/store/renderers/selectors.d.ts +0 -5
  65. package/dist/util/contextHandler.d.ts +0 -3
  66. package/dist/util/util.d.ts +0 -22
  67. package/dist/utils/util.d.ts +0 -22
  68. package/src/index.ts +0 -30
  69. package/src/stock/Stock.ts +0 -75
  70. package/src/stock/appRootFunctions.ts +0 -15
  71. package/src/stock/functions.ts +0 -25
  72. package/src/stock/validation.ts +0 -30
  73. package/src/store/persistConfig.ts +0 -20
  74. package/src/store/reducers.ts +0 -6
  75. package/src/store/root/actions.ts +0 -12
  76. package/src/store/root/reducer.ts +0 -71
  77. package/src/store/root/selectors.ts +0 -61
  78. package/src/typings/key-value-replace.d.ts +0 -8
  79. package/src/utils/I18n.ts +0 -99
  80. package/src/utils/constants.ts +0 -21
  81. package/src/utils/contextHandler.ts +0 -5
  82. package/src/utils/jsonRefResolver.ts +0 -88
  83. package/src/utils/types.ts +0 -35
  84. package/src/utils/util.ts +0 -142
  85. package/src/wrapper/wrapperUtil.tsx +0 -139
  86. package/tsconfig.json +0 -5
package/src/utils/I18n.ts DELETED
@@ -1,99 +0,0 @@
1
- import Ajv from 'ajv'
2
- import keyValueReplace from 'key-value-replace'
3
-
4
- interface I18nResources {
5
- [key: string]: {
6
- translation: {
7
- [key: string]: string
8
- }
9
- }
10
- }
11
-
12
- interface I18nProps {
13
- language?: string
14
- resources?: I18nResources
15
- keyPrefix?: string
16
- keyPostfix?: string
17
- nonExistsHandler?: (key: string) => void
18
- }
19
- const I18nSchema = {
20
- $id: 'http://example.com/schemas/schema.json',
21
- type: 'object',
22
- additionalProperties: {
23
- type: 'object',
24
- properties: {
25
- translation: {
26
- type: 'object',
27
- additionalProperties: {
28
- type: 'string',
29
- },
30
- propertyNames: {
31
- type: 'string',
32
- },
33
- minProperties: 1,
34
- },
35
- additionalProperties: false,
36
- },
37
- },
38
- propertyNames: {
39
- pattern: '^[A-Za-z0-9_-]*$',
40
- type: 'string',
41
- },
42
- minProperties: 1,
43
- }
44
-
45
- export default class I18n {
46
- language: string
47
-
48
- languages: string[]
49
-
50
- resources?: I18nResources
51
-
52
- keyPrefix?: string
53
-
54
- keyPostfix?: string
55
-
56
- nonExistsHandler?: (key: string) => void
57
-
58
- availableLanguageKey?: string
59
-
60
- // eslint-disable-next-line consistent-this
61
- constructor({ language = 'en', resources, nonExistsHandler, keyPrefix = '{{', keyPostfix = '}}' }: I18nProps) {
62
- this.language = language
63
- this.nonExistsHandler = nonExistsHandler
64
- this.keyPrefix = keyPrefix
65
- this.keyPostfix = keyPostfix
66
-
67
- const ajv = new Ajv()
68
- const validate = ajv.compile(I18nSchema)
69
- const isValid = validate(resources)
70
- if (isValid) {
71
- this.resources = resources
72
- }
73
- this.languages = Object.keys(resources as any)
74
- if (this.languages && this.languages.includes(this.language)) {
75
- this.availableLanguageKey = this.language
76
- } else if (this.languages && this.languages.includes(this.getLocales())) {
77
- this.availableLanguageKey = this.getLocales()
78
- }
79
- }
80
-
81
- getLocales = () => (this.language.includes('-') ? this.language.split('-') : this.language.split('_') || [])[0]
82
-
83
- t = (key: string, options?: any, language?: string | null) => {
84
- if (!this.resources || (!this.resources && !this.language && !language) || !this.resources[`${this.availableLanguageKey || language}`]) {
85
- return key
86
- }
87
- const value = this.resources[`${this.availableLanguageKey || language}`].translation[key]
88
- if (!value) {
89
- if (this.nonExistsHandler && typeof this.nonExistsHandler === 'function') {
90
- this.nonExistsHandler(key)
91
- }
92
- return key
93
- }
94
- if (options) {
95
- return keyValueReplace(value, options, [this.keyPrefix, this.keyPostfix])
96
- }
97
- return value
98
- }
99
- }
@@ -1,21 +0,0 @@
1
- export const SEPARATOR = '/'
2
- export const STORE_ERROR_POSTFIX = '.error'
3
-
4
- export const PATH_MODIFIERS_KEY = '$pathModifiers'
5
- export const MODIFIER_KEY = '$modifier'
6
- export const ACTION_KEY = '$action'
7
- export const PERSIST_STORAGE_KEY = '$persistStores'
8
- export const PERSIST_STORAGE_NAMES = ['data']
9
- export const REF_ASSETS = '$assetsRef'
10
- export const REF_LOCALES = '$locales'
11
- export const REF_VALIDATES = '$validations'
12
- export const STYLE_WEB_NAME = 'styleWeb'
13
- export const STYLE_RN_NAME = 'styleRN'
14
- export const REDUX_FUNCTIONS = ['set', 'get']
15
-
16
- export const PATHNAME = 'path'
17
- export const SIMPLE_DATA_TYPES = ['string', 'number', 'boolean', 'null']
18
- export const V_CHILDREN_NAME = '$children'
19
- export const V_COMP_NAME = '$comp'
20
- export const ITEM_OF_ARRAY = 'item'
21
- export const PAGINATION_ITEM_PER_PAGE = 1
@@ -1,5 +0,0 @@
1
- import { createContext } from 'react'
2
- import Stock from 'stock/Stock'
3
-
4
- export const StockContext = createContext<typeof Stock | null>(null)
5
- export const PathModifierContext = createContext({})
@@ -1,88 +0,0 @@
1
- import traverse from 'traverse'
2
- import uniq from 'lodash/uniq'
3
- import compact from 'lodash/compact'
4
- import unset from 'lodash/unset'
5
- import findIndex from 'lodash/findIndex'
6
- import pull from 'lodash/pull'
7
- import defaultsDeep from 'lodash/defaultsDeep'
8
- import * as c from './constants'
9
-
10
- export const collectJsonKeys = (refConst: string, json: any) => {
11
- const refs: any[] = []
12
- // eslint-disable-next-line func-names
13
- traverse(json).forEach(function (x) {
14
- if (x && x[refConst] && !!this && !this.circular) {
15
- refs.push(x[refConst])
16
- }
17
- })
18
- const res = {}
19
- uniq(compact(refs)).forEach((i) => defaultsDeep(res, i))
20
- return res
21
- }
22
-
23
- const isFullPath = (path?: string) => {
24
- if (!!path && typeof path === 'string') {
25
- const regex = /^[A-Za-z]*:\/\//
26
- return regex.test(path)
27
- }
28
- return false
29
- }
30
-
31
- const isRelativePath = (path?: string) => !!path && typeof path === 'string' && !isFullPath(path) && !path.startsWith(c.SEPARATOR) // if not full and not start with /
32
-
33
- const isRootPath = (path?: string) => !!path && typeof path === 'string' && !isFullPath(path) && path.startsWith(c.SEPARATOR) // if not full and start with /
34
-
35
- const changeRelativePath = (path: string) => {
36
- let pathArray = path.split(c.SEPARATOR)
37
- pathArray = pull(pathArray, '.') // remove all ./
38
- let count = 0
39
- let relativepathIndex = -1
40
- do {
41
- count += 1
42
- relativepathIndex = findIndex(pathArray, (i) => i === '..')
43
- if (relativepathIndex !== -1) {
44
- unset(pathArray, `[${relativepathIndex}]`)
45
- unset(pathArray, `[${relativepathIndex - 1}]`)
46
- pathArray = compact(pathArray)
47
- }
48
- } while (relativepathIndex !== -1 && count < 100)
49
- return pathArray.join(c.SEPARATOR)
50
- }
51
-
52
- // TODO: just workaround, not works with http://localhost for example
53
- const getRoot = (url3?: string) => {
54
- if (!!url3 && typeof url3 === 'string') {
55
- const regex = /^([A-Za-z]*:\/\/[^/]*)(\/|)/
56
- const found = url3.match(regex)
57
- if (found) {
58
- return `${found[1]}/`
59
- }
60
- }
61
- return null
62
- }
63
-
64
- // console.error('test',isFullPath('asdasd://'))
65
- export const getRefs = (refConst: string, json: any, projectPath = '') => {
66
- const refs: any[] = []
67
- // eslint-disable-next-line func-names
68
- traverse(json).forEach(function (x) {
69
- if (x && x[refConst] && !!this && !this.circular) {
70
- const ref = x[refConst]
71
- let absolutePath
72
- // TODO: If the projectPath is absolute, will be wrong
73
- if (isRootPath(ref)) {
74
- const root = getRoot(projectPath)
75
- absolutePath = changeRelativePath(`${root}${ref}`)
76
- } else if (isRelativePath(ref)) {
77
- absolutePath = changeRelativePath(`${projectPath}${ref}`)
78
- } else {
79
- absolutePath = ref
80
- }
81
- // eslint-disable-next-line no-param-reassign
82
- x[refConst] = absolutePath
83
- refs.push(absolutePath)
84
- }
85
- })
86
- // console.warn(refs);
87
- return uniq(compact(refs))
88
- }
@@ -1,35 +0,0 @@
1
- import React from 'react'
2
- import * as c from 'utils/constants'
3
-
4
- export type UIDefinition = any
5
- export type Path = string
6
- export type ArraysType = any[]
7
- export type WrapperType = React.ElementType
8
-
9
- // eslint-disable-next-line no-use-before-define
10
- export type PropValue = PropsType | ArraysType | string | null | boolean | number | undefined | PathModifiersType
11
-
12
- export interface PathModifierType {
13
- path: string
14
- }
15
- export interface PathModifiersType {
16
- [key: string]: PathModifierType
17
- }
18
-
19
- export interface PropsType {
20
- [key: string]: PropValue
21
- [c.PATH_MODIFIERS_KEY]?: PathModifiersType
22
- }
23
-
24
- export interface PathType {
25
- path: string[]
26
- level: number
27
- }
28
-
29
- export type PathsType = PathType[]
30
-
31
- export interface ValidationType {
32
- store: string
33
- path: string
34
- schema: any
35
- }
package/src/utils/util.ts DELETED
@@ -1,142 +0,0 @@
1
- import jsonpointer from 'jsonpointer'
2
- import cloneDeep from 'lodash/cloneDeep'
3
- import drop from 'lodash/drop'
4
- import findIndex from 'lodash/findIndex'
5
- import pull from 'lodash/pull'
6
- import compact from 'lodash/compact'
7
- import findLastIndex from 'lodash/findLastIndex'
8
- import unset from 'lodash/unset'
9
- import * as c from './constants'
10
- import { PropsType } from './types'
11
-
12
- export const jsonPointerGet = (json: any, path?: string) => {
13
- if (json === null || json === undefined || path === null || path === undefined || typeof path !== 'string') return null
14
- if (path === c.SEPARATOR /* || path === '' same effect */) return json
15
- try {
16
- return jsonpointer.get(json, path.startsWith(c.SEPARATOR) ? path : `${c.SEPARATOR}${path}`)
17
- } catch (e) {
18
- return null
19
- }
20
- }
21
-
22
- export const jsonPointerSet = (json: any, path?: string, value?: any) => {
23
- if (json === null || json === undefined || path === null || path === undefined || typeof path !== 'string') return
24
- if (path === c.SEPARATOR || path === '') {
25
- // eslint-disable-next-line no-param-reassign
26
- json = value
27
- return
28
- }
29
- try {
30
- jsonpointer.set(json, path.startsWith(c.SEPARATOR) ? path : `${c.SEPARATOR}${path}`, value)
31
- // eslint-disable-next-line no-empty
32
- } catch (e) {}
33
- }
34
-
35
- export const getCleanedTopic = (text: string | any) => {
36
- if (!text || typeof text !== 'string' || text.length === 0 || text.length > 1024) {
37
- return null
38
- }
39
- return text.replace(/[^0-9a-zA-Z]/g, '-')
40
- }
41
-
42
- export const pathArrayToPathString = (array: string[]) => array.map((i, index) => (Number.isInteger(i) ? `[${i}]` : `${index > 0 ? '.' : ''}${i}`)).join('')
43
-
44
- export const pathArrayToJsonPointer = (array: string[]) => `/${array.join('/')}`
45
-
46
- /**
47
- * Simple object check.
48
- * @param item
49
- * @returns {boolean}
50
- */
51
- export function isObject(item: any) {
52
- return item && typeof item === 'object' && !Array.isArray(item)
53
- }
54
-
55
- /**
56
- * Deep merge two objects.
57
- * @param target
58
- * @param ...sources
59
- */
60
- export function mergeDeep(target: any, ...sources: any): any {
61
- if (!sources.length) return target
62
- const source = sources.shift()
63
-
64
- if (isObject(target) && isObject(source)) {
65
- // eslint-disable-next-line no-restricted-syntax
66
- for (const key in source) {
67
- if (isObject(source[key])) {
68
- if (!target[key]) Object.assign(target, { [key]: {} })
69
- mergeDeep(target[key], source[key])
70
- } else {
71
- Object.assign(target, { [key]: source[key] })
72
- }
73
- }
74
- }
75
-
76
- return mergeDeep(target, ...sources)
77
- }
78
-
79
- export const mergePath = (target: any, newState: any) => {
80
- if (!newState || typeof newState !== 'object') return target
81
- const newTarget = cloneDeep(target)
82
- Object.entries(newState).forEach(([key, value]) => {
83
- jsonpointer.set(newTarget, key, value)
84
- })
85
- return newTarget
86
- }
87
-
88
- // eslint-disable-next-line import/prefer-default-export
89
- export const changeRelativePath = (path: string) => {
90
- let pathArray = path.split(c.SEPARATOR)
91
- if (pathArray && pathArray.length > 1 && pathArray[pathArray.length - 1] === '') {
92
- pathArray.pop()
93
- }
94
- const absolutepathIndex = findLastIndex(pathArray, (i) => i === '')
95
- if (absolutepathIndex > 0) {
96
- pathArray = drop(pathArray, absolutepathIndex)
97
- }
98
- pathArray = pull(pathArray, '.')
99
- let count = 0
100
- let relativepathIndex = -1
101
- do {
102
- count += 1
103
- relativepathIndex = findIndex(pathArray, (i) => i === '..')
104
- if (relativepathIndex !== -1) {
105
- unset(pathArray, `[${relativepathIndex}]`)
106
- unset(pathArray, `[${relativepathIndex - 1}]`)
107
- pathArray = compact(pathArray)
108
- }
109
- } while (relativepathIndex !== -1 && count < 100)
110
- return pathArray.join(c.SEPARATOR)
111
- }
112
-
113
- // changeRelativePath('111/22222/3333/./anything/../../start')
114
-
115
- const genStyle = (props: PropsType) => {
116
- const { parentComp } = props
117
- const style = { display: 'flex', flexDirection: 'column', ...(props.style as any), ...(props[c.STYLE_WEB_NAME] as any) }
118
-
119
- if (style && style.borderWidth && !style.borderStyle) {
120
- style.borderStyle = 'solid'
121
- }
122
- if (style && style.flex) {
123
- if (
124
- parentComp &&
125
- (parentComp as any).style &&
126
- (parentComp as any).style.flex &&
127
- (parentComp as any).style.flex < 1
128
- // if smaller or larger, noesn't matter
129
- ) {
130
- style.height = `100%`
131
- style.width = `100%`
132
- } else if (!style.height) {
133
- style.height = `${style.flex * 100}%`
134
- }
135
- }
136
- return style
137
- }
138
- export const getStyleForWeb = (props: PropsType = {}, component: string) =>
139
- component === 'View' ? genStyle(props) : { ...(props.style as any), ...(props[c.STYLE_WEB_NAME] as any) }
140
-
141
- // TODO it have to be configurable
142
- export const noChildren = (component: string) => ['Image'].includes(component)
@@ -1,139 +0,0 @@
1
- import React from 'react'
2
- import isEmpty from 'lodash/isEmpty'
3
- import orderBy from 'lodash/orderBy'
4
- import omit from 'lodash/omit'
5
- import isNumber from 'lodash/isNumber'
6
- import traverse from 'traverse'
7
- import * as c from 'utils/constants'
8
- import * as util from 'utils/util'
9
- import Stock from 'stock/Stock'
10
- import { PathModifiersType, PathModifierType, PathsType, PropsType, WrapperType } from '../utils/types'
11
-
12
- export const actionBuilder = (props: PropsType, stock: InstanceType<typeof Stock>) => {
13
- const paths: PathsType = []
14
- // eslint-disable-next-line func-names
15
- traverse(omit(props, ['parentComp'])).forEach(function (x) {
16
- if (
17
- !!x &&
18
- !!x[c.ACTION_KEY] &&
19
- // && !c.REDUX_FUNCTIONS.includes(x[c.ACTION_KEY])
20
- !(this.path.length > 1 && this.path.includes(c.V_CHILDREN_NAME))
21
- ) {
22
- paths.push({ path: this.path, level: this.level })
23
- }
24
- })
25
- orderBy(paths, ['level'], ['desc']).forEach(async (i) => {
26
- const { [c.ACTION_KEY]: functionName, ...functionParams } = traverse(props).get(i.path)
27
- traverse(props).set(i.path, async (...callerArgs: any[]) => {
28
- await stock.callFunction(functionName, functionParams, props, callerArgs)
29
- })
30
- })
31
- }
32
-
33
- export const modifierBuilder = (props: PropsType, stock: InstanceType<typeof Stock>) => {
34
- const paths: PathsType = []
35
- // eslint-disable-next-line func-names
36
- traverse(omit(props, ['parentComp'])).forEach(function (x) {
37
- if (!!x && !!x[c.MODIFIER_KEY] && !c.REDUX_FUNCTIONS.includes(x[c.MODIFIER_KEY]) && !(this.path.length > 1 && this.path.includes(c.V_CHILDREN_NAME))) {
38
- paths.push({ path: this.path, level: this.level })
39
- }
40
- })
41
- orderBy(paths, ['level'], ['desc']).forEach(async (i) => {
42
- const { [c.MODIFIER_KEY]: functionName, ...functionParams } = traverse(props).get(i.path)
43
- traverse(props).set(i.path, stock.callFunction(functionName, functionParams, props))
44
- })
45
- }
46
-
47
- export const pathModifierBuilder = (props: PropsType, pathModifier: PathModifiersType) => {
48
- const currentPaths: PathModifiersType = { ...(props.currentPaths as PathModifiersType) }
49
- let modified = false
50
- if (pathModifier && !isEmpty(pathModifier)) {
51
- Object.keys(pathModifier).forEach((key: string) => {
52
- if (!!key && !!pathModifier[key] && pathModifier[key][c.PATHNAME] !== undefined && pathModifier[key][c.PATHNAME] !== null) {
53
- const path = pathModifier[key][c.PATHNAME]
54
- const parent = currentPaths[key]
55
- modified = true
56
- if (`${path}`.startsWith(c.SEPARATOR) || !(parent && parent[c.PATHNAME])) {
57
- currentPaths[key] = { [c.PATHNAME]: path }
58
- } else {
59
- currentPaths[key] = { [c.PATHNAME]: util.changeRelativePath(`${parent[c.PATHNAME]}${c.SEPARATOR}${path}`) }
60
- }
61
- if (!!currentPaths[key] && !`${currentPaths[key][c.PATHNAME]}`.startsWith(c.SEPARATOR)) {
62
- currentPaths[key][c.PATHNAME] = `${c.SEPARATOR}${currentPaths[key][c.PATHNAME]}`
63
- }
64
- }
65
- })
66
- }
67
- return modified ? { currentPaths } : undefined
68
- }
69
-
70
- export const getWrapperProps = (props: PropsType, parentComp?: any) => {
71
- const res: PropsType = {
72
- ...(c.SIMPLE_DATA_TYPES.includes(typeof props) ? {} : props),
73
- parentComp,
74
- [c.V_COMP_NAME]: c.SIMPLE_DATA_TYPES.includes(typeof props) || props === undefined || props === null ? '_PrimitiveProp' : props[c.V_COMP_NAME],
75
- [c.V_CHILDREN_NAME]: c.SIMPLE_DATA_TYPES.includes(typeof props) || props === undefined || props === null ? props : props[c.V_CHILDREN_NAME],
76
- }
77
- // eslint-disable-next-line no-restricted-syntax
78
- for (const i in res) if (typeof res[i] === 'undefined') delete res[i]
79
- return res
80
- }
81
-
82
- const genChildenFromListItem = (props: PropsType) => {
83
- let { page = 0, listLength = 0, itemPerPage = c.PAGINATION_ITEM_PER_PAGE } = props
84
- const { listItem } = props
85
- const pathModifiers: PathModifiersType = props[c.PATH_MODIFIERS_KEY] as PathModifiersType
86
- const children: PropsType[] = []
87
- if (isNumber(page) && isNumber(listLength) && isNumber(itemPerPage) && pathModifiers) {
88
- page = page >= 0 ? page : 0
89
- itemPerPage = itemPerPage >= 0 ? itemPerPage : 0
90
- listLength = listLength >= 0 ? listLength : 0
91
- const offset = page * itemPerPage <= listLength ? page * itemPerPage : 0
92
- const itemkey: string = Object.keys(pathModifiers)[0]
93
- const firstItem: PathModifierType = pathModifiers[itemkey]
94
- // eslint-disable-next-line no-plusplus
95
- for (let i = offset; i < listLength && i < offset + itemPerPage; i++) {
96
- children.push({
97
- ...(listItem as PropsType),
98
- [c.PATH_MODIFIERS_KEY]: {
99
- ...(pathModifiers as PathModifiersType),
100
- [Object.keys(pathModifiers)[0]]: {
101
- ...(firstItem as PathModifierType),
102
- path: i,
103
- },
104
- } as PathModifiersType,
105
- })
106
- }
107
- }
108
- return children
109
- }
110
-
111
- export const getRootWrapperProps = (props: PropsType, stock: InstanceType<typeof Stock>) => {
112
- const newProps = {
113
- ...props,
114
- // if the children generation move to wrapper, the redux genAllStateProps doesn't wortk properly. why?
115
- }
116
- modifierBuilder(newProps, stock)
117
- actionBuilder(newProps, stock)
118
- if (newProps.isList) {
119
- newProps[c.V_CHILDREN_NAME] = genChildenFromListItem(newProps)
120
- }
121
-
122
- return newProps
123
- }
124
-
125
- export const getChildrensForRoot = (props: PropsType, children: any, Wrapper: WrapperType) => {
126
- // eslint-disable-next-line no-nested-ternary
127
- const parentComp = omit(props, [c.V_CHILDREN_NAME, 'parentComp'])
128
- return !!props && Array.isArray(children) ? (
129
- children.map((childrenItem, index) => {
130
- // eslint-disable-next-line react/no-array-index-key
131
- return <Wrapper key={index} {...getWrapperProps(childrenItem, parentComp)} />
132
- })
133
- ) : (
134
- <Wrapper {...getWrapperProps(children, parentComp)} />
135
- )
136
- }
137
-
138
- export const generateChildren = (props: PropsType, { Wrapper }: InstanceType<typeof Stock>) =>
139
- props[c.V_COMP_NAME] !== '_PrimitiveProp' ? getChildrensForRoot(props, props[c.V_CHILDREN_NAME], Wrapper as WrapperType) : props[c.V_CHILDREN_NAME]
package/tsconfig.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "../../tsconfig",
3
- "compilerOptions": { "baseUrl": "./src/" },
4
- "include": ["src"]
5
- }