@globalbrain/sefirot 0.72.0 → 2.0.0-draft.1

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 (174) hide show
  1. package/CHANGELOG.md +2 -820
  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 +59 -633
  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 +53 -90
  30. package/lib/components/SPortalModals.vue +37 -53
  31. package/lib/components/SPortalSnackbars.vue +9 -24
  32. package/lib/components/SSheet.vue +10 -23
  33. package/lib/components/SSheetFooter.vue +0 -2
  34. package/lib/components/SSheetFooterAction.vue +9 -14
  35. package/lib/components/SSheetFooterActions.vue +1 -3
  36. package/lib/components/SSheetHeader.vue +9 -24
  37. package/lib/components/SSheetHeaderTitle.vue +0 -2
  38. package/lib/components/SSheetMedium.vue +12 -14
  39. package/lib/components/SSnackbar.vue +18 -28
  40. package/lib/composables/Dialog.ts +9 -17
  41. package/lib/composables/Dropdown.ts +1 -1
  42. package/lib/composables/{Menu.ts → Flyout.ts} +11 -4
  43. package/lib/composables/Form.ts +42 -44
  44. package/lib/composables/Modal.ts +9 -9
  45. package/lib/composables/Snackbar.ts +18 -0
  46. package/lib/composables/Validation.ts +28 -0
  47. package/lib/mixins/Sheet.ts +3 -3
  48. package/lib/store/Sefirot.ts +8 -13
  49. package/lib/store/dialog/index.ts +20 -10
  50. package/lib/store/modal/index.ts +11 -13
  51. package/lib/store/snackbars/index.ts +3 -4
  52. package/lib/support/{Util.ts → Utils.ts} +0 -2
  53. package/lib/types/Utils.ts +0 -7
  54. package/lib/types/vue-shims.d.ts +7 -0
  55. package/lib/validation/rules/checked.ts +6 -10
  56. package/lib/validation/rules/fileExtension.ts +9 -9
  57. package/lib/validation/rules/hms.ts +9 -9
  58. package/lib/validation/rules/index.ts +10 -74
  59. package/lib/validation/rules/maxLength.ts +10 -9
  60. package/lib/validation/rules/minLength.ts +12 -0
  61. package/lib/validation/rules/required.ts +2 -10
  62. package/lib/validation/rules/requiredHms.ts +11 -0
  63. package/lib/validation/rules/requiredIf.ts +3 -11
  64. package/lib/validation/rules/requiredYmd.ts +11 -0
  65. package/lib/validation/rules/ymd.ts +11 -0
  66. package/lib/validation/validators/checked.ts +1 -1
  67. package/lib/validation/validators/fileExtension.ts +1 -1
  68. package/lib/validation/validators/hms.ts +5 -5
  69. package/lib/validation/validators/requiredHms.ts +17 -0
  70. package/lib/validation/validators/requiredYmd.ts +7 -0
  71. package/lib/validation/validators/ymd.ts +41 -0
  72. package/package.json +45 -50
  73. package/lib/components/SAction.vue +0 -37
  74. package/lib/components/SActionAvatar.vue +0 -25
  75. package/lib/components/SActionButton.vue +0 -40
  76. package/lib/components/SActionPill.vue +0 -35
  77. package/lib/components/SActionSwitch.vue +0 -37
  78. package/lib/components/SAlert.vue +0 -145
  79. package/lib/components/SButtonGroup.vue +0 -160
  80. package/lib/components/SCard.vue +0 -111
  81. package/lib/components/SCardFooter.vue +0 -74
  82. package/lib/components/SCardHeader.vue +0 -213
  83. package/lib/components/SGrid.vue +0 -237
  84. package/lib/components/SGridActionLink.vue +0 -53
  85. package/lib/components/SGridActionMulti.vue +0 -139
  86. package/lib/components/SGridActionSingle.vue +0 -64
  87. package/lib/components/SHeader.vue +0 -180
  88. package/lib/components/SInputCheckboxes.vue +0 -87
  89. package/lib/components/SInputDate.vue +0 -192
  90. package/lib/components/SInputDay.vue +0 -87
  91. package/lib/components/SInputMonth.vue +0 -86
  92. package/lib/components/SInputSelect.vue +0 -298
  93. package/lib/components/SInputSwitch.vue +0 -212
  94. package/lib/components/SInputSwitches.vue +0 -108
  95. package/lib/components/SInputTime.vue +0 -255
  96. package/lib/components/SInputYear.vue +0 -60
  97. package/lib/components/SMarkdown.vue +0 -56
  98. package/lib/components/SPlaceholderBlank.vue +0 -113
  99. package/lib/components/SPlaceholderImage.vue +0 -83
  100. package/lib/components/SPortalScreens.vue +0 -62
  101. package/lib/components/SProgressBar.vue +0 -89
  102. package/lib/components/SResponsive.vue +0 -46
  103. package/lib/components/SScreen.vue +0 -81
  104. package/lib/components/SStep.vue +0 -107
  105. package/lib/components/SSteps.vue +0 -75
  106. package/lib/components/STag.vue +0 -67
  107. package/lib/components/STooltip.vue +0 -134
  108. package/lib/components/SWindow.vue +0 -158
  109. package/lib/components/icons/SIconCopy.vue +0 -6
  110. package/lib/composables/Action.ts +0 -141
  111. package/lib/composables/Alert.ts +0 -50
  112. package/lib/composables/Card.ts +0 -46
  113. package/lib/composables/FormValidation.ts +0 -150
  114. package/lib/composables/Header.ts +0 -72
  115. package/lib/composables/InputDropdown.ts +0 -6
  116. package/lib/composables/Markdown.ts +0 -138
  117. package/lib/composables/Router.ts +0 -20
  118. package/lib/composables/Step.ts +0 -7
  119. package/lib/composables/Store.ts +0 -9
  120. package/lib/composables/Tag.ts +0 -32
  121. package/lib/composables/Tooltip.ts +0 -91
  122. package/lib/composables/Utils.ts +0 -115
  123. package/lib/composables/markdown/LinkPlugin.ts +0 -45
  124. package/lib/compositions/useForm.ts +0 -17
  125. package/lib/compositions/useResizeObserver.ts +0 -25
  126. package/lib/compositions/useTime.ts +0 -26
  127. package/lib/store/alert/index.ts +0 -32
  128. package/lib/store/screen/index.ts +0 -46
  129. package/lib/types/v-calendar.d.ts +0 -5
  130. package/lib/validation/Validation.ts +0 -151
  131. package/lib/validation/rules/day.ts +0 -11
  132. package/lib/validation/rules/email.ts +0 -11
  133. package/lib/validation/rules/every.ts +0 -38
  134. package/lib/validation/rules/include.ts +0 -11
  135. package/lib/validation/rules/includeSome.ts +0 -11
  136. package/lib/validation/rules/integer.ts +0 -11
  137. package/lib/validation/rules/maxValue.ts +0 -11
  138. package/lib/validation/rules/minValue.ts +0 -11
  139. package/lib/validation/rules/month.ts +0 -11
  140. package/lib/validation/rules/not.ts +0 -10
  141. package/lib/validation/rules/regex.ts +0 -11
  142. package/lib/validation/rules/requiredHMS.ts +0 -11
  143. package/lib/validation/rules/requiredMonthDate.ts +0 -11
  144. package/lib/validation/rules/requiredYearMonth.ts +0 -11
  145. package/lib/validation/rules/requiredYearMonthDate.ts +0 -11
  146. package/lib/validation/rules/rule.ts +0 -5
  147. package/lib/validation/rules/sameAs.ts +0 -11
  148. package/lib/validation/rules/url.ts +0 -11
  149. package/lib/validation/rules/validateIf.ts +0 -27
  150. package/lib/validation/rules/year.ts +0 -11
  151. package/lib/validation/rules/yearMonth.ts +0 -11
  152. package/lib/validation/rules/yearMonthDate.ts +0 -11
  153. package/lib/validation/validators/day.ts +0 -29
  154. package/lib/validation/validators/email.ts +0 -5
  155. package/lib/validation/validators/include.ts +0 -5
  156. package/lib/validation/validators/includeSome.ts +0 -5
  157. package/lib/validation/validators/index.ts +0 -51
  158. package/lib/validation/validators/integer.ts +0 -6
  159. package/lib/validation/validators/maxLength.ts +0 -3
  160. package/lib/validation/validators/maxValue.ts +0 -3
  161. package/lib/validation/validators/minValue.ts +0 -3
  162. package/lib/validation/validators/month.ts +0 -3
  163. package/lib/validation/validators/monthDate.ts +0 -20
  164. package/lib/validation/validators/regex.ts +0 -3
  165. package/lib/validation/validators/required.ts +0 -27
  166. package/lib/validation/validators/requiredHMS.ts +0 -17
  167. package/lib/validation/validators/requiredMonthDate.ts +0 -8
  168. package/lib/validation/validators/requiredYearMonth.ts +0 -8
  169. package/lib/validation/validators/requiredYearMonthDate.ts +0 -9
  170. package/lib/validation/validators/sameAs.ts +0 -5
  171. package/lib/validation/validators/url.ts +0 -5
  172. package/lib/validation/validators/year.ts +0 -3
  173. package/lib/validation/validators/yearMonth.ts +0 -20
  174. package/lib/validation/validators/yearMonthDate.ts +0 -21
@@ -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'
@@ -1,138 +0,0 @@
1
- import MarkdownIt from 'markdown-it'
2
- import { onUnmounted, Ref } from '@vue/composition-api'
3
- import { isCallbackUrl, isExternalUrl, LinkAttrs, linkPlugin } from './markdown/LinkPlugin'
4
- import { useRouter } from './Router'
5
-
6
- export type UseMarkdown = (source: string, inline: boolean) => string
7
-
8
- export interface UseMarkdownOptions extends MarkdownIt.Options {
9
- linkAttrs?: LinkAttrs
10
- config?: (md: MarkdownIt) => void
11
- }
12
-
13
- export function useMarkdown(options: UseMarkdownOptions = {}): UseMarkdown {
14
- const md = new MarkdownIt({
15
- linkify: true,
16
- ...options
17
- })
18
-
19
- md.use(linkPlugin, {
20
- target: '_blank',
21
- rel: 'noopener noreferrer',
22
- ...options.linkAttrs
23
- })
24
-
25
- if (options.config) {
26
- options.config(md)
27
- }
28
-
29
- return (source, inline) => {
30
- return inline ? md.renderInline(source) : md.render(source)
31
- }
32
- }
33
-
34
- export interface UseLink {
35
- addListeners(): void
36
- removeListeners(): void
37
- subscribe(cb: LinkSubscriber): () => void
38
- }
39
-
40
- export interface UseLinkOptions {
41
- container: Ref<Element | null>
42
- callbacks?: LinkCallback[]
43
- }
44
-
45
- export interface LinkSubscriberPayload {
46
- event: Event
47
- target: HTMLAnchorElement
48
- isExternal: boolean
49
- isCallback: boolean
50
- }
51
-
52
- export type LinkSubscriber = (payload: LinkSubscriberPayload) => void
53
-
54
- export type LinkCallback = () => void
55
-
56
- export function useLink({ container, callbacks }: UseLinkOptions): UseLink {
57
- const router = useRouter()
58
- const subscribers: LinkSubscriber[] = []
59
-
60
- onUnmounted(() => removeListeners())
61
-
62
- function handler(event: Event): void {
63
- const target = event.target as HTMLAnchorElement
64
- const href = target.getAttribute('href')!
65
-
66
- if (!href) {
67
- return
68
- }
69
-
70
- const isExternal = isExternalUrl(href)
71
- const isCallback = isCallbackUrl(href)
72
-
73
- subscribers.forEach(sub => sub({
74
- event,
75
- target,
76
- isExternal,
77
- isCallback
78
- }))
79
-
80
- if (isExternal) {
81
- return
82
- }
83
-
84
- if (!event.defaultPrevented) {
85
- event.preventDefault()
86
- }
87
-
88
- if (isCallback) {
89
- const idx = parseInt(target.dataset.callbackId || '')
90
- const callback = (callbacks ?? [])[idx]
91
-
92
- if (!callback) {
93
- throw new Error(`Callback not found at index: ${idx}`)
94
- }
95
-
96
- return callback()
97
- }
98
-
99
- router.push(href)
100
- }
101
-
102
- function addListeners(): void {
103
- removeListeners()
104
-
105
- if (container.value) {
106
- findLinks(container.value).forEach((element) => {
107
- element.addEventListener('click', handler)
108
- })
109
- }
110
- }
111
-
112
- function removeListeners(): void {
113
- if (container.value) {
114
- findLinks(container.value).forEach((element) => {
115
- element.removeEventListener('click', handler)
116
- })
117
- }
118
- }
119
-
120
- function subscribe(fn: LinkSubscriber): () => void {
121
- subscribers.push(fn)
122
-
123
- return () => {
124
- const idx = subscribers.indexOf(fn)
125
- idx > -1 && subscribers.splice(idx, 1)
126
- }
127
- }
128
-
129
- return {
130
- addListeners,
131
- removeListeners,
132
- subscribe
133
- }
134
- }
135
-
136
- function findLinks(target: Element) {
137
- return target.querySelectorAll('a.SMarkdown-link')
138
- }
@@ -1,20 +0,0 @@
1
- import { computed, ComputedRef, getCurrentInstance } from '@vue/composition-api'
2
- import VueRouter, { Route } from 'vue-router'
3
-
4
- export function useRouter(): VueRouter {
5
- const { proxy } = getCurrentInstance()!
6
-
7
- return proxy.$router
8
- }
9
-
10
- export function useRoute(): ComputedRef<Route> {
11
- const { proxy } = getCurrentInstance()!
12
-
13
- return computed(() => proxy.$route)
14
- }
15
-
16
- export function useParams(): ComputedRef<Record<string, string>> {
17
- const { proxy } = getCurrentInstance()!
18
-
19
- return computed(() => proxy.$route.params)
20
- }
@@ -1,7 +0,0 @@
1
- export interface Step {
2
- status: StepStatus
3
- text?: string
4
- }
5
-
6
- export type StepStatus = 'upcoming' | 'active' | 'done' | 'failed'
7
- export type BarMode = 'mute' | 'active'
@@ -1,9 +0,0 @@
1
- import { getCurrentInstance } from '@vue/composition-api'
2
- import { Store } from 'vuex'
3
- import { State } from '../store/Sefirot'
4
-
5
- export function useStore(): Store<State> {
6
- const { proxy } = getCurrentInstance()!
7
-
8
- return proxy.$store
9
- }
@@ -1,32 +0,0 @@
1
- import { Values } from '../types/Utils'
2
-
3
- export interface Tag {
4
- size?: Size
5
- mode?: Mode
6
- icon?: any
7
- text?: string
8
- link?: string
9
- }
10
-
11
- export type Size = Values<typeof Sizes>
12
-
13
- export const Sizes = {
14
- Small: 'small',
15
- Medium: 'medium',
16
- Large: 'large'
17
- } as const
18
-
19
- export type Mode = Values<typeof Modes>
20
-
21
- export const Modes = {
22
- Neutral: 'neutral',
23
- Info: 'info',
24
- Success: 'success',
25
- Warning: 'warning',
26
- Danger: 'danger',
27
- Mute: 'mute'
28
- } as const
29
-
30
- export function useTag(tag: Tag): Tag {
31
- return tag
32
- }