@globalbrain/sefirot 0.72.0 → 2.0.0-draft.4

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 (175) hide show
  1. package/CHANGELOG.md +8 -808
  2. package/README.md +1 -1
  3. package/lib/assets/styles/bootstrap.css +1 -2
  4. package/lib/assets/styles/variables.css +14 -47
  5. package/lib/components/SAvatar.vue +9 -18
  6. package/lib/components/SButton.vue +35 -48
  7. package/lib/components/SDialog.vue +16 -34
  8. package/lib/components/SDropdown.vue +36 -55
  9. package/lib/components/SDropdownItem.vue +27 -39
  10. package/lib/components/SDropdownItemText.vue +4 -9
  11. package/lib/components/SDropdownItemUser.vue +4 -12
  12. package/lib/components/SInputBase.vue +33 -45
  13. package/lib/components/SInputCheckbox.vue +17 -37
  14. package/lib/components/SInputDropdown.vue +109 -171
  15. package/lib/components/SInputDropdownItem.vue +26 -32
  16. package/lib/components/SInputDropdownItemText.vue +6 -11
  17. package/lib/components/SInputDropdownItemTextTag.vue +10 -17
  18. package/lib/components/SInputDropdownItemUser.vue +5 -13
  19. package/lib/components/SInputDropdownItemUserTag.vue +9 -16
  20. package/lib/components/SInputFile.vue +38 -53
  21. package/lib/components/SInputHMS.vue +91 -114
  22. package/lib/components/SInputNumber.vue +27 -106
  23. package/lib/components/SInputRadio.vue +21 -34
  24. package/lib/components/SInputRadios.vue +36 -46
  25. package/lib/components/SInputText.vue +72 -628
  26. package/lib/components/SInputTextarea.vue +54 -113
  27. package/lib/components/SInputYMD.vue +94 -105
  28. package/lib/components/SLink.vue +16 -52
  29. package/lib/components/SModal.vue +39 -98
  30. package/lib/components/SPortalModals.vue +37 -54
  31. package/lib/components/SPortalSnackbars.vue +9 -24
  32. package/lib/components/SSheet.vue +73 -28
  33. package/lib/components/SSheetFooter.vue +5 -3
  34. package/lib/components/SSheetFooterAction.vue +10 -15
  35. package/lib/components/SSheetFooterActions.vue +2 -4
  36. package/lib/components/SSheetMedium.vue +14 -22
  37. package/lib/components/SSheetTitle.vue +20 -0
  38. package/lib/components/SSnackbar.vue +18 -28
  39. package/lib/composables/Dialog.ts +9 -17
  40. package/lib/composables/Dropdown.ts +2 -2
  41. package/lib/composables/{Menu.ts → Flyout.ts} +11 -4
  42. package/lib/composables/Form.ts +42 -44
  43. package/lib/composables/Modal.ts +11 -19
  44. package/lib/composables/Snackbar.ts +18 -0
  45. package/lib/composables/Validation.ts +28 -0
  46. package/lib/mixins/Sheet.ts +5 -7
  47. package/lib/store/Sefirot.ts +8 -13
  48. package/lib/store/dialog/index.ts +20 -10
  49. package/lib/store/modal/index.ts +11 -18
  50. package/lib/store/snackbars/index.ts +3 -4
  51. package/lib/support/{Util.ts → Utils.ts} +0 -2
  52. package/lib/types/Utils.ts +0 -7
  53. package/lib/types/vue-shims.d.ts +7 -0
  54. package/lib/validation/rules/checked.ts +6 -10
  55. package/lib/validation/rules/fileExtension.ts +9 -9
  56. package/lib/validation/rules/hms.ts +9 -9
  57. package/lib/validation/rules/index.ts +10 -74
  58. package/lib/validation/rules/maxLength.ts +10 -9
  59. package/lib/validation/rules/minLength.ts +12 -0
  60. package/lib/validation/rules/required.ts +2 -10
  61. package/lib/validation/rules/requiredHms.ts +11 -0
  62. package/lib/validation/rules/requiredIf.ts +3 -11
  63. package/lib/validation/rules/requiredYmd.ts +11 -0
  64. package/lib/validation/rules/ymd.ts +11 -0
  65. package/lib/validation/validators/checked.ts +1 -1
  66. package/lib/validation/validators/fileExtension.ts +1 -1
  67. package/lib/validation/validators/hms.ts +5 -5
  68. package/lib/validation/validators/requiredHms.ts +17 -0
  69. package/lib/validation/validators/requiredYmd.ts +7 -0
  70. package/lib/validation/validators/ymd.ts +41 -0
  71. package/package.json +45 -50
  72. package/lib/components/SAction.vue +0 -37
  73. package/lib/components/SActionAvatar.vue +0 -25
  74. package/lib/components/SActionButton.vue +0 -40
  75. package/lib/components/SActionPill.vue +0 -35
  76. package/lib/components/SActionSwitch.vue +0 -37
  77. package/lib/components/SAlert.vue +0 -145
  78. package/lib/components/SButtonGroup.vue +0 -160
  79. package/lib/components/SCard.vue +0 -111
  80. package/lib/components/SCardFooter.vue +0 -74
  81. package/lib/components/SCardHeader.vue +0 -213
  82. package/lib/components/SGrid.vue +0 -237
  83. package/lib/components/SGridActionLink.vue +0 -53
  84. package/lib/components/SGridActionMulti.vue +0 -139
  85. package/lib/components/SGridActionSingle.vue +0 -64
  86. package/lib/components/SHeader.vue +0 -180
  87. package/lib/components/SInputCheckboxes.vue +0 -87
  88. package/lib/components/SInputDate.vue +0 -192
  89. package/lib/components/SInputDay.vue +0 -87
  90. package/lib/components/SInputMonth.vue +0 -86
  91. package/lib/components/SInputSelect.vue +0 -298
  92. package/lib/components/SInputSwitch.vue +0 -212
  93. package/lib/components/SInputSwitches.vue +0 -108
  94. package/lib/components/SInputTime.vue +0 -255
  95. package/lib/components/SInputYear.vue +0 -60
  96. package/lib/components/SMarkdown.vue +0 -56
  97. package/lib/components/SPlaceholderBlank.vue +0 -113
  98. package/lib/components/SPlaceholderImage.vue +0 -83
  99. package/lib/components/SPortalScreens.vue +0 -62
  100. package/lib/components/SProgressBar.vue +0 -89
  101. package/lib/components/SResponsive.vue +0 -46
  102. package/lib/components/SScreen.vue +0 -81
  103. package/lib/components/SSheetHeader.vue +0 -75
  104. package/lib/components/SSheetHeaderTitle.vue +0 -17
  105. package/lib/components/SStep.vue +0 -107
  106. package/lib/components/SSteps.vue +0 -75
  107. package/lib/components/STag.vue +0 -67
  108. package/lib/components/STooltip.vue +0 -134
  109. package/lib/components/SWindow.vue +0 -158
  110. package/lib/components/icons/SIconCopy.vue +0 -6
  111. package/lib/composables/Action.ts +0 -141
  112. package/lib/composables/Alert.ts +0 -50
  113. package/lib/composables/Card.ts +0 -46
  114. package/lib/composables/FormValidation.ts +0 -150
  115. package/lib/composables/Header.ts +0 -72
  116. package/lib/composables/InputDropdown.ts +0 -6
  117. package/lib/composables/Markdown.ts +0 -138
  118. package/lib/composables/Router.ts +0 -20
  119. package/lib/composables/Step.ts +0 -7
  120. package/lib/composables/Store.ts +0 -9
  121. package/lib/composables/Tag.ts +0 -32
  122. package/lib/composables/Tooltip.ts +0 -91
  123. package/lib/composables/Utils.ts +0 -115
  124. package/lib/composables/markdown/LinkPlugin.ts +0 -45
  125. package/lib/compositions/useForm.ts +0 -17
  126. package/lib/compositions/useResizeObserver.ts +0 -25
  127. package/lib/compositions/useTime.ts +0 -26
  128. package/lib/store/alert/index.ts +0 -32
  129. package/lib/store/screen/index.ts +0 -46
  130. package/lib/types/v-calendar.d.ts +0 -5
  131. package/lib/validation/Validation.ts +0 -151
  132. package/lib/validation/rules/day.ts +0 -11
  133. package/lib/validation/rules/email.ts +0 -11
  134. package/lib/validation/rules/every.ts +0 -38
  135. package/lib/validation/rules/include.ts +0 -11
  136. package/lib/validation/rules/includeSome.ts +0 -11
  137. package/lib/validation/rules/integer.ts +0 -11
  138. package/lib/validation/rules/maxValue.ts +0 -11
  139. package/lib/validation/rules/minValue.ts +0 -11
  140. package/lib/validation/rules/month.ts +0 -11
  141. package/lib/validation/rules/not.ts +0 -10
  142. package/lib/validation/rules/regex.ts +0 -11
  143. package/lib/validation/rules/requiredHMS.ts +0 -11
  144. package/lib/validation/rules/requiredMonthDate.ts +0 -11
  145. package/lib/validation/rules/requiredYearMonth.ts +0 -11
  146. package/lib/validation/rules/requiredYearMonthDate.ts +0 -11
  147. package/lib/validation/rules/rule.ts +0 -5
  148. package/lib/validation/rules/sameAs.ts +0 -11
  149. package/lib/validation/rules/url.ts +0 -11
  150. package/lib/validation/rules/validateIf.ts +0 -27
  151. package/lib/validation/rules/year.ts +0 -11
  152. package/lib/validation/rules/yearMonth.ts +0 -11
  153. package/lib/validation/rules/yearMonthDate.ts +0 -11
  154. package/lib/validation/validators/day.ts +0 -29
  155. package/lib/validation/validators/email.ts +0 -5
  156. package/lib/validation/validators/include.ts +0 -5
  157. package/lib/validation/validators/includeSome.ts +0 -5
  158. package/lib/validation/validators/index.ts +0 -51
  159. package/lib/validation/validators/integer.ts +0 -6
  160. package/lib/validation/validators/maxLength.ts +0 -3
  161. package/lib/validation/validators/maxValue.ts +0 -3
  162. package/lib/validation/validators/minValue.ts +0 -3
  163. package/lib/validation/validators/month.ts +0 -3
  164. package/lib/validation/validators/monthDate.ts +0 -20
  165. package/lib/validation/validators/regex.ts +0 -3
  166. package/lib/validation/validators/required.ts +0 -27
  167. package/lib/validation/validators/requiredHMS.ts +0 -17
  168. package/lib/validation/validators/requiredMonthDate.ts +0 -8
  169. package/lib/validation/validators/requiredYearMonth.ts +0 -8
  170. package/lib/validation/validators/requiredYearMonthDate.ts +0 -9
  171. package/lib/validation/validators/sameAs.ts +0 -5
  172. package/lib/validation/validators/url.ts +0 -5
  173. package/lib/validation/validators/year.ts +0 -3
  174. package/lib/validation/validators/yearMonth.ts +0 -20
  175. package/lib/validation/validators/yearMonthDate.ts +0 -21
@@ -1,158 +0,0 @@
1
- <template>
2
- <SModalBase :name="name" :closable="closable" @click.stop>
3
- <div class="SWindow" @click.stop>
4
- <button v-if="closable" class="close" @click="close">
5
- <SIconX class="close-icon" />
6
- </button>
7
-
8
- <div v-if="showHeader" class="header">
9
- <p class="title">{{ title }}</p>
10
- <p v-if="lead" class="lead">{{ lead }}</p>
11
- </div>
12
-
13
- <div class="content">
14
- <slot />
15
- </div>
16
-
17
- <div v-if="actions" class="actions">
18
- <div v-for="(action, index) in actions" :key="index" class="action">
19
- <SButton
20
- :label="action.label"
21
- :type="action.type"
22
- :mode="action.mode"
23
- size="large"
24
- @click="action.callback"
25
- />
26
- </div>
27
- </div>
28
- </div>
29
- </SModalBase>
30
- </template>
31
-
32
- <script lang="ts">
33
- import { PropType, computed, defineComponent } from '@vue/composition-api'
34
- import { ButtonAction } from '../composables/Action'
35
- import { useStore } from '../composables/Store'
36
- import SIconX from './icons/SIconX.vue'
37
- import SButton from './SButton.vue'
38
- import SModalBase from './SModalBase.vue'
39
-
40
- export default defineComponent({
41
- components: {
42
- SIconX,
43
- SButton,
44
- SModalBase
45
- },
46
-
47
- props: {
48
- name: { type: String, required: true },
49
- title: { type: String, default: null },
50
- lead: { type: String, default: null },
51
- actions: { type: Array as PropType<ButtonAction[]>, default: null },
52
- closable: { type: Boolean, default: false }
53
- },
54
-
55
- setup(props) {
56
- const store = useStore()
57
-
58
- const showHeader = computed(() => !!props.title)
59
-
60
- function close(): void {
61
- store.dispatch('window/close')
62
- }
63
-
64
- return {
65
- showHeader,
66
- close
67
- }
68
- }
69
- })
70
- </script>
71
-
72
- <style lang="postcss" scoped>
73
- @import "@/assets/styles/variables";
74
-
75
- .SWindow {
76
- position: relative;
77
- margin: 48px 24px;
78
- border-radius: 2px;
79
- max-width: 768px;
80
- background-color: var(--c-white);
81
- box-shadow: var(--shadow-depth-5);
82
- transition: opacity .25s, transform .25s;
83
- transition-delay: .05s;
84
-
85
- @media (min-width: 768px) {
86
- margin: 96px auto;
87
- }
88
- }
89
-
90
- .close {
91
- position: absolute;
92
- top: 0;
93
- right: 0;
94
- z-index: 10;
95
- display: flex;
96
- justify-content: center;
97
- align-items: center;
98
- width: 64px;
99
- height: 64px;
100
-
101
- &:hover .close-icon {
102
- fill: var(--c-black);
103
- }
104
- }
105
-
106
- .close-icon {
107
- width: 16px;
108
- height: 16px;
109
- fill: var(--c-gray);
110
- transition: fill .25s;
111
- }
112
-
113
- .header {
114
- border-radius: 2px 2px 0 0;
115
- padding: 32px;
116
- background-color: var(--c-white-soft);
117
-
118
- @media (min-width: 768px) {
119
- padding: 48px 64px 40px;
120
- }
121
- }
122
-
123
- .title {
124
- line-height: 32px;
125
- text-align: center;
126
- font-size: 24px;
127
- }
128
-
129
- .lead {
130
- padding-top: 8px;
131
- text-align: center;
132
- color: var(--c-gray);
133
- }
134
-
135
- .content {
136
- padding: 32px;
137
-
138
- @media (min-width: 768px) {
139
- padding: 48px 64px;
140
- }
141
- }
142
-
143
- .actions {
144
- display: flex;
145
- justify-content: center;
146
- padding: 32px;
147
-
148
- @media (min-width: 768px) {
149
- padding: 32px 64px 48px;
150
- }
151
- }
152
-
153
- .action {
154
- & + & {
155
- padding-left: 16px;
156
- }
157
- }
158
- </style>
@@ -1,6 +0,0 @@
1
- <template>
2
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
3
- <path d="M20,23H11a2.9,2.9,0,0,1-3-3V11a2.9,2.9,0,0,1,3-3h9a2.9,2.9,0,0,1,3,3v9A2.9,2.9,0,0,1,20,23ZM11,10a.9.9,0,0,0-1,1v9a.9.9,0,0,0,1,1h9a.9.9,0,0,0,1-1V11a.9.9,0,0,0-1-1Z" />
4
- <path d="M5,16H4a2.9,2.9,0,0,1-3-3V4A2.9,2.9,0,0,1,4,1h9a2.9,2.9,0,0,1,3,3V5a1,1,0,0,1-2,0V4a.9.9,0,0,0-1-1H4A.9.9,0,0,0,3,4v9a.9.9,0,0,0,1,1H5a1,1,0,0,1,0,2Z" />
5
- </svg>
6
- </template>
@@ -1,141 +0,0 @@
1
- import { Values, OmitType } from '../types/Utils'
2
- import { Refish } from './Utils'
3
-
4
- export type Action = Values<Actions>
5
-
6
- export interface Actions {
7
- ButtonAction: ButtonAction
8
- PillAction: PillAction
9
- AvatarAction: AvatarAction
10
- SwitchAction: SwitchAction
11
- }
12
-
13
- export interface ActionBase {
14
- type: Type
15
- size?: Size
16
- gap?: number
17
- callback?(): void
18
- }
19
-
20
- export type Type = Values<typeof Types>
21
-
22
- export const Types = {
23
- Button: 'button',
24
- Avatar: 'avatar',
25
- Pill: 'pill',
26
- Switch: 'switch'
27
- } as const
28
-
29
- export type Size = Values<typeof Sizes>
30
-
31
- export const Sizes = {
32
- Small: 'small',
33
- Medium: 'medium'
34
- } as const
35
-
36
- export interface ButtonAction extends ActionBase {
37
- type: typeof Types.Button
38
- kind?: ButtonActionKind
39
- mode?: ButtonActionMode
40
- icon?: any
41
- label?: string
42
- link?: string
43
- rounded?: boolean
44
- inverse?: boolean
45
- loading?: boolean
46
- }
47
-
48
- export type ButtonActionKind = Values<typeof ButtonActionKinds>
49
-
50
- export const ButtonActionKinds = {
51
- Primary: 'primary',
52
- Secondary: 'secondary',
53
- Tertiary: 'tertiary',
54
- Text: 'text',
55
- Mute: 'mute'
56
- } as const
57
-
58
- export type ButtonActionMode = Values<typeof ButtonActionModes>
59
-
60
- export const ButtonActionModes = {
61
- Neutral: 'neutral',
62
- Info: 'info',
63
- Success: 'success',
64
- Warning: 'warning',
65
- Danger: 'danger'
66
- } as const
67
-
68
- export interface PillAction extends ActionBase {
69
- type: typeof Types.Pill
70
- mode?: PillActionMode
71
- label: string
72
- }
73
-
74
- export type PillActionMode = Values<typeof PillActionModes>
75
-
76
- export const PillActionModes = {
77
- Neutral: 'neutral',
78
- Info: 'info',
79
- Success: 'success',
80
- Warning: 'warning',
81
- Danger: 'danger'
82
- } as const
83
-
84
- export interface AvatarAction extends ActionBase {
85
- type: typeof Types.Avatar
86
- avatars: AvatarActionAvatar[]
87
- }
88
-
89
- export interface AvatarActionAvatar {
90
- avatar: string
91
- name?: string
92
- }
93
-
94
- export interface SwitchAction extends ActionBase {
95
- type: typeof Types.Switch
96
- value: Refish<boolean>
97
- mode?: SwitchActionMode
98
- text?: string
99
- textMode?: SwitchActionTextMode
100
- }
101
-
102
- export type SwitchActionMode = Values<typeof SwitchActionModes>
103
-
104
- export const SwitchActionModes = {
105
- Neutral: 'neutral',
106
- Info: 'info',
107
- Success: 'success',
108
- Warning: 'warning',
109
- Danger: 'danger'
110
- } as const
111
-
112
- export type SwitchActionTextMode = Values<typeof SwitchActionTextModes>
113
-
114
- export const SwitchActionTextModes = {
115
- Neutral: 'neutral',
116
- Mute: 'mute',
117
- Info: 'info',
118
- Success: 'success',
119
- Warning: 'warning',
120
- Danger: 'danger'
121
- } as const
122
-
123
- export function useAction<T extends Action>(action: T): T {
124
- return action
125
- }
126
-
127
- export function useButtonAction(action: OmitType<ButtonAction>): ButtonAction {
128
- return { type: Types.Button, ...action }
129
- }
130
-
131
- export function usePillAction(action: OmitType<PillAction>): PillAction {
132
- return { type: Types.Pill, ...action }
133
- }
134
-
135
- export function useAvatarAction(action: OmitType<AvatarAction>): AvatarAction {
136
- return { type: Types.Avatar, ...action }
137
- }
138
-
139
- export function useSwitchAction(action: OmitType<SwitchAction>): SwitchAction {
140
- return { type: Types.Switch, ...action }
141
- }
@@ -1,50 +0,0 @@
1
- import { Values } from '../types/Utils'
2
- import { useStore } from './Store'
3
- import { useModalUid } from './Modal'
4
-
5
- export interface Alert {
6
- open(alert: AlertOptions): Promise<any>
7
- close(): Promise<any>
8
- }
9
-
10
- export interface AlertOptions {
11
- type?: AlertMode
12
- title: string
13
- text: string
14
- actions: Action[]
15
- }
16
-
17
- export type AlertMode = Values<typeof AlertModes>
18
-
19
- export const AlertModes = {
20
- Info: 'info',
21
- Success: 'success',
22
- Warning: 'warning',
23
- Danger: 'danger'
24
- } as const
25
-
26
- export interface Action {
27
- type: 'primary' | 'secondary' | 'tertiary' | 'text' | 'mute'
28
- mode: 'neutral' | 'info' | 'success' | 'warning' | 'danger'
29
- icon?: any
30
- label: string
31
- callback(): void
32
- }
33
-
34
- export function useAlert(): Alert {
35
- const store = useStore()
36
- const uid = useModalUid()
37
-
38
- function open(alert: AlertOptions) {
39
- return store.dispatch('alert/open', { ...alert, uid })
40
- }
41
-
42
- function close() {
43
- return store.dispatch('alert/close', uid)
44
- }
45
-
46
- return {
47
- open,
48
- close
49
- }
50
- }
@@ -1,46 +0,0 @@
1
- import { Values } from '../types/Utils'
2
- import { Refish } from './Utils'
3
-
4
- export interface Card {
5
- header?: Header
6
- footer?: Footer
7
- mode?: Mode
8
- round?: number
9
- depth?: number
10
- collapsable?: boolean
11
- }
12
-
13
- export interface Header {
14
- title?: string
15
- actions?: Refish<Action[]>
16
- }
17
-
18
- export interface Footer {
19
- actions: Refish<Action[]>
20
- }
21
-
22
- export interface Action {
23
- type: 'primary' | 'secondary' | 'tertiary' | 'text' | 'mute'
24
- mode?: Mode
25
- icon?: ActionIconType | object
26
- label?: string
27
- link?: string
28
- disabled?: string | null
29
- callback?(): void
30
- }
31
-
32
- export type ActionIconType = 'edit-3' | 'plus' | 'trash-2'
33
-
34
- export type Mode = Values<typeof Modes>
35
-
36
- export const Modes = {
37
- Neutral: 'neutral',
38
- Info: 'info',
39
- Success: 'success',
40
- Warning: 'warning',
41
- Danger: 'danger'
42
- } as const
43
-
44
- export function useCard(card: Card): Card {
45
- return card
46
- }
@@ -1,150 +0,0 @@
1
- import { Ref, ComputedRef, ref, computed } from '@vue/composition-api'
2
- import { required } from '../validation/validators'
3
- import { Rule } from '../validation/rules'
4
-
5
- export interface Validation {
6
- $isValidation: boolean
7
- $isDirty: Ref<boolean> | ComputedRef<boolean>
8
- $isValid: ComputedRef<boolean>
9
- $errors: ComputedRef<Error[]>
10
- $touch (): void
11
- $reset (): void
12
- $validate (): boolean
13
- [key: string]: any
14
- }
15
-
16
- export type Rules = NestedRules | Validators
17
-
18
- export interface NestedRules {
19
- [key: string]: Rules | any
20
- }
21
-
22
- export interface Validators {
23
- [key: string]: Rule[]
24
- }
25
-
26
- export type Error = [string, string]
27
-
28
- export function useFormValidation<T extends Record<string, any>>(data: T, rules: Rules, rootData?: T): Validation {
29
- const validation = {} as Validation
30
-
31
- setValidations(validation, data, rules, rootData ?? data)
32
-
33
- setupValidation(validation)
34
-
35
- return validation
36
- }
37
-
38
- function setValidations<T extends Record<string, any>>(validation: Validation, data: T, rules: Rules, rootData: T): void {
39
- for (const name in rules) {
40
- const rule = rules[name]
41
-
42
- if (isValidation(rule)) {
43
- validation[name] = rule
44
- continue
45
- }
46
-
47
- if (Array.isArray(rule)) {
48
- validation[name] = createValidation(name, data, rule, rootData)
49
- continue
50
- }
51
-
52
- validation[name] = useFormValidation(data[name], rule, rootData)
53
- }
54
- }
55
-
56
- function createValidation<T extends Record<string, any>>(name: string, data: T, rules: Rule[], rootData: T): Validation {
57
- const isDirty = ref(false)
58
- const isValid = computed(() => errors.value.length === 0)
59
- const errors = computed(() => getErrors(name, data, rules, rootData))
60
-
61
- function touch(): void {
62
- isDirty.value = true
63
- }
64
-
65
- function reset(): void {
66
- isDirty.value = false
67
- }
68
-
69
- function validate(): boolean {
70
- touch()
71
- return isValid.value
72
- }
73
-
74
- return {
75
- $isValidation: true,
76
- $isDirty: isDirty,
77
- $isValid: isValid,
78
- $errors: errors,
79
- $touch: touch,
80
- $reset: reset,
81
- $validate: validate
82
- }
83
- }
84
-
85
- function setupValidation(validation: Validation): void {
86
- const isDirty = computed(() => {
87
- return Object.keys(validation).every((field) => {
88
- const v = validation[field]
89
-
90
- return isValidation(v) ? v.$isDirty.value : true
91
- })
92
- })
93
-
94
- const isValid = computed(() => errors.value.length === 0)
95
-
96
- const errors = computed(() => {
97
- return Object.keys(validation).reduce<Error[]>((errors, field) => {
98
- const v = validation[field]
99
- return isValidation(v) ? errors.concat(v.$errors.value) : errors
100
- }, [])
101
- })
102
-
103
- function touch(): void {
104
- callAll(validation, 'touch')
105
- }
106
-
107
- function reset(): void {
108
- callAll(validation, 'reset')
109
- }
110
-
111
- const validate = () => {
112
- touch()
113
- return isValid.value
114
- }
115
-
116
- validation.$isValidation = true
117
- validation.$isDirty = isDirty
118
- validation.$errors = errors
119
- validation.$isValid = isValid
120
- validation.$touch = touch
121
- validation.$reset = reset
122
- validation.$validate = validate
123
- }
124
-
125
- function getErrors<T extends Record<string, any>>(name: string, data: T, rules: Rule[], rootData: T): Error[] {
126
- return rules.reduce<Error[]>((errors, rule) => {
127
- const value = data[name]
128
-
129
- if (rule.optional && !required(value)) {
130
- return errors
131
- }
132
-
133
- if (!rule.validate(value, rootData)) {
134
- errors.push([rule.name, rule.message])
135
- }
136
-
137
- return errors
138
- }, [])
139
- }
140
-
141
- function callAll(validation: Validation, method: 'touch' | 'reset'): void {
142
- for (const field in validation) {
143
- const v = validation[field]
144
- isValidation(v) && v[`$${method}`]()
145
- }
146
- }
147
-
148
- function isValidation(obj: any): obj is Validation {
149
- return obj !== null && typeof obj === 'object' && !Array.isArray(obj) && !!obj.$isValidation
150
- }
@@ -1,72 +0,0 @@
1
- import { ComputedRef } from '@vue/composition-api'
2
- import { Values } from '../types/Utils'
3
- import { Refish } from './Utils'
4
- import { Action } from './Action'
5
- import { Tag } from './Tag'
6
- import { Dropdown, UseDropdownOptions, useDropdown } from './Dropdown'
7
-
8
- export * from './Action'
9
- export * from './Tag'
10
-
11
- export interface Header {
12
- size?: Size
13
- mode?: Mode
14
- icon?: any
15
- title?: Refish<string>
16
- search?: Search
17
- actions?: Refish<Action[]>
18
- tags?: Refish<Tag[]>
19
- }
20
-
21
- export type Size = Values<typeof Sizes>
22
-
23
- export const Sizes = {
24
- Small: 'small',
25
- Medium: 'medium',
26
- Large: 'large'
27
- } as const
28
-
29
- export type Mode = Values<typeof Modes>
30
-
31
- export const Modes = {
32
- Neutral: 'neutral',
33
- Info: 'info',
34
- Success: 'success',
35
- Warning: 'warning',
36
- Danger: 'danger'
37
- } as const
38
-
39
- export interface Search {
40
- placeholder: string
41
- presets?: SearchPresets
42
- value: ComputedRef<string>
43
- onEnter(text: string): void
44
- }
45
-
46
- export interface SearchPresets {
47
- title: string
48
- dropdown: Dropdown
49
- }
50
-
51
- export interface UseSearchPresetsOptions {
52
- title: string
53
- dropdown: UseDropdownOptions
54
- }
55
-
56
- export function useHeader(header: Header): Header {
57
- return header
58
- }
59
-
60
- export function useSearch(search: Search): Search {
61
- return search
62
- }
63
-
64
- export function useSearchPresets(presets: UseSearchPresetsOptions): SearchPresets {
65
- return {
66
- title: presets.title,
67
- dropdown: useDropdown({
68
- closeOnClick: true,
69
- ...presets.dropdown
70
- })
71
- }
72
- }
@@ -1,6 +0,0 @@
1
- export type { Search, Item, TextItem, UserItem } from './Dropdown'
2
- export {
3
- useSearch,
4
- useTextItem as useTextOption,
5
- useUserItem as useUserOption
6
- } from './Dropdown'