Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
common
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
npm
common
Commits
7439d626
Commit
7439d626
authored
Oct 29, 2018
by
Vladislav Lagunov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[fields] Исправления в ~/Form.ts
parent
5870a612
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
36 deletions
+34
-36
fields/Suggestions.tsx
+2
-2
fields/TextField.tsx
+2
-2
fields/context.tsx
+9
-21
fields/create-form.ts
+20
-11
fields/i18n.po.yml
+1
-0
No files found.
fields/Suggestions.tsx
View file @
7439d626
...
@@ -23,7 +23,7 @@ export type Props<A=any> = StandardProps<React.HTMLProps<HTMLDivElement>, string
...
@@ -23,7 +23,7 @@ export type Props<A=any> = StandardProps<React.HTMLProps<HTMLDivElement>, string
pending
?:
boolean
;
pending
?:
boolean
;
dontMove
?:
boolean
;
dontMove
?:
boolean
;
//
c
allbacks
//
C
allbacks
onSelect
?(
a
:
A
):
void
;
onSelect
?(
a
:
A
):
void
;
onVisibilityChange
?(
open
:
boolean
):
void
;
onVisibilityChange
?(
open
:
boolean
):
void
;
}
}
...
@@ -192,7 +192,7 @@ class Suggestions<A> extends React.Component<Props<A>, State> {
...
@@ -192,7 +192,7 @@ class Suggestions<A> extends React.Component<Props<A>, State> {
}
}
}
}
export default withStyles(styles)(withGettext(require('./i18n.yml'))(Suggestions));
export default withStyles(styles)(withGettext(require('./i18n.
po.
yml'))(Suggestions));
// Styles
// Styles
...
...
fields/TextField.tsx
View file @
7439d626
...
@@ -10,7 +10,7 @@ const eyeSlash = require('./eye-slash.svg');
...
@@ -10,7 +10,7 @@ const eyeSlash = require('./eye-slash.svg');
// Props
// Props
export
type
Props
=
StandardProps
<
React
.
HTMLProps
<
HTML
DivElement
>
,
ClassKey
,
'ref'
|
'onKeyDown
'
|
'disabled'
>
&
FieldProps
<
string
>
&
{
export
type
Props
=
StandardProps
<
React
.
HTMLProps
<
HTML
InputElement
>
,
ClassKey
,
'ref
'
|
'disabled'
>
&
FieldProps
<
string
>
&
{
__
:
Gettext
;
__
:
Gettext
;
ctx
?:
LocaleCtx
;
ctx
?:
LocaleCtx
;
type
?:
React
.
HTMLProps
<
HTMLInputElement
>
[
'type'
];
type
?:
React
.
HTMLProps
<
HTMLInputElement
>
[
'type'
];
...
@@ -115,7 +115,7 @@ export class TextField extends React.Component<Props, State> {
...
@@ -115,7 +115,7 @@ export class TextField extends React.Component<Props, State> {
}
}
}
}
export
default
withGettext
(
require
(
'./i18n.yml'
))(
TextField
);
export
default
withGettext
(
require
(
'./i18n.
po.
yml'
))(
TextField
);
// CSS классы
// CSS классы
...
...
fields/context.tsx
View file @
7439d626
import
*
as
React
from
'react'
;
import
{
AuthCtx
as
Ctx
}
from
'~/context'
;
import
{
AuthCtx
as
Ctx
}
from
'~/context'
;
import
{
I18nString
}
from
'~/gettext'
;
import
{
I18nString
}
from
'~/gettext'
;
import
{
ObjectPath
}
from
'~/functions/get-at'
;
import
{
ObjectPath
}
from
'~/functions/get-at'
;
export
const
{
Provider
,
Consumer
}
=
React
.
createContext
<
FieldProps
>
(
void
0
as
any
);
// Контекст поля
// Контекст поля
export
interface
FieldProps
<
Value
=
any
>
{
export
interface
FieldProps
<
T
=
any
>
{
ctx
?:
Ctx
;
ctx
?:
Ctx
;
value
:
Value
;
value
:
T
;
disabled
?:
Disabled
;
disabled
?:
Disabled
;
error
?:
Error
|
Validation
<
any
>
;
// Здесь должен передавться результат `validate` те `Validation<A>`
onValueChange
?(
value
:
Value
):
void
;
error
?:
Error
;
onValueChange
?(
value
:
T
):
void
;
onValueChange
?(
value
:
any
,
at
?:
ObjectPath
):
void
;
onValueChange
?(
value
:
any
,
at
?:
ObjectPath
):
void
;
onFocus
?(
e
?:
React
.
SyntheticEvent
):
void
;
onBlur
?(
e
?:
React
.
SyntheticEvent
):
void
;
onClick
?(
e
?:
React
.
SyntheticEvent
):
void
;
onKeyDown
?(
e
:
React
.
KeyboardEvent
):
void
;
}
}
// Флаги активности
// Флаги активности
export
interface
DisabledRecord
{
export
type
Disabled
=
boolean
|
object
;
[
K
:
string
]:
Disabled
;
}
export
type
Disabled
=
boolean
|
DisabledRecord
;
// Ошибки в форме
// Ошибки в поле
export
interface
ErrorRecord
{
export
type
Error
=
boolean
|
string
|
object
|
I18nString
;
[
K
:
string
]:
Error
;
}
export
type
Error
=
boolean
|
string
|
ErrorRecord
|
I18nString
;
// Валидация формы
export
type
Validation
<
A
>
=
Partial
<
Record
<
keyof
A
,
Error
>>
;
export
type
Validation
<
A
>
=
Partial
<
Record
<
keyof
A
,
Error
>>
;
fields/
F
orm.ts
→
fields/
create-f
orm.ts
View file @
7439d626
...
@@ -4,6 +4,7 @@ import { FieldProps } from './';
...
@@ -4,6 +4,7 @@ import { FieldProps } from './';
// import { StandardProps } from '@material-ui/core';
// import { StandardProps } from '@material-ui/core';
import
memoize
from
'~/functions/memoize'
;
import
memoize
from
'~/functions/memoize'
;
import
{
ObjectKey
,
ObjectPath
}
from
'~/functions/get-at'
;
import
{
ObjectKey
,
ObjectPath
}
from
'~/functions/get-at'
;
import
{
isEqual
}
from
'lodash'
;
// Props
// Props
...
@@ -18,24 +19,18 @@ export type CardProps<T> = {
...
@@ -18,24 +19,18 @@ export type CardProps<T> = {
//
//
export
type
Any
<
T
=
any
>
=
React
.
ReactType
<
FieldProps
<
T
>>
;
export
type
Any
<
T
=
any
>
=
React
.
ReactType
<
FieldProps
<
T
>>
;
export
type
AnyC
<
T
=
any
>
=
React
.
ReactElement
<
FieldProps
<
T
>>
;
export
type
GetProps
<
T
extends
Any
>
=
T
extends
React
.
ReactType
<
infer
Props
>
?
Props
:
never
;
export
type
GetProps
<
T
extends
Any
>
=
T
extends
React
.
ReactType
<
infer
Props
>
?
Props
:
never
;
// Props
export
type
CreateFormOptions
<
T
>
=
{
export
type
ZoomComponentProps
<
C
extends
Any
>
=
{
Component
:
C
;
}
&
GetProps
<
C
>
;
export
type
CreateZoomOptions
<
T
>
=
{
validate
?(
value
:
T
):
any
;
validate
?(
value
:
T
):
any
;
disabled
?(
value
:
T
):
any
;
disabled
?(
value
:
T
):
any
;
};
};
export
default
function
createForm
<
O
extends
CreateZoomOptions
<
any
>>
(
options
:
O
)
{
export
default
function
createForm
<
O
extends
CreateFormOptions
<
any
>>
(
options
:
O
)
{
type
T
=
O
extends
CreateZoomOptions
<
infer
T
>
?
T
:
never
;
type
T
=
O
extends
CreateFormOptions
<
infer
T
>
?
T
:
never
;
function
bindZoom
(
self
:
React
.
Component
<
CardProps
<
T
>>
)
{
function
bindZoom
(
self
:
React
.
Component
<
CardProps
<
T
>>
)
{
function
Zoom
<
K1
extends
keyof
T
,
C
extends
Any
<
T
[
K1
]
>>
(...
keys
:
[
K1
]):
(
Component
:
C
,
props
?:
GetProps
<
C
>
)
=>
JSX
.
Element
;
function
Zoom
<
K1
extends
keyof
T
,
C
extends
Any
<
T
[
K1
]
>>
(...
keys
:
[
K1
]):
(
Component
:
C
,
props
?:
GetProps
<
C
>
)
=>
JSX
.
Element
;
function
Zoom
<
K1
extends
keyof
T
,
K2
extends
keyof
T
[
K1
],
C
extends
Any
<
T
[
K1
][
K2
]
>>
(...
keys
:
[
K1
,
K2
]):
(
Component
:
C
,
props
?:
GetProps
<
C
>
)
=>
JSX
.
Element
;
function
Zoom
<
K1
extends
keyof
T
,
K2
extends
keyof
T
[
K1
],
C
extends
Any
<
T
[
K1
][
K2
]
>>
(...
keys
:
[
K1
,
K2
]):
(
Component
:
C
,
props
?:
GetProps
<
C
>
)
=>
JSX
.
Element
;
...
@@ -62,8 +57,22 @@ export default function createForm<O extends CreateZoomOptions<any>>(options: O)
...
@@ -62,8 +57,22 @@ export default function createForm<O extends CreateZoomOptions<any>>(options: O)
return
Zoom
;
return
Zoom
;
}
}
function
set
<
M
extends
CardProps
<
T
>
[
'model'
]
>
(
model
:
M
,
form
:
T
):
M
{
// @ts-ignore
return
isEqual
(
model
.
initial
,
form
)
?
{
...
model
,
modified
:
null
}
:
{
...
model
,
modified
:
form
};
}
function
get
<
M
extends
CardProps
<
T
>
[
'model'
]
>
(
model
:
M
):
T
{
// @ts-ignore
return
model
.
modified
||
model
.
initial
;
}
function
modify
<
M
extends
CardProps
<
T
>
[
'model'
]
>
(
model
:
M
,
f
:
(
form
:
T
)
=>
T
):
M
{
return
set
(
model
,
f
(
get
(
model
)));
}
// @ts-ignore
// @ts-ignore
return
{
...
options
,
bindZoom
}
as
{
bindZoom
:
typeof
bindZoom
}
&
O
;
return
{
...
options
,
bindZoom
,
set
,
get
,
modify
}
as
{
bindZoom
:
typeof
bindZoom
,
set
:
typeof
set
,
get
:
typeof
get
,
modify
:
typeof
modify
}
&
O
;
}
}
...
...
fields/i18n.yml
→
fields/i18n.
po.
yml
View file @
7439d626
# https://git.bitmaster.ru/npm/common/tree/master/gettext#%D0%A4%D0%BE%D1%80%D0%BC%D0%B0%D1%82-poyml
-
"
"
:
-
"
"
:
locale
:
"
ru-RU"
locale
:
"
ru-RU"
"
Fill
out
this
field"
:
"
Заполните
это
поле"
"
Fill
out
this
field"
:
"
Заполните
это
поле"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment