@aerogel/core 0.0.0-next.f9394854509d71d644498ac087706a2f8f8eea1c → 0.0.0-next.fb0f08b1df2e4aff5b34e23b9927b06b58484c98

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 (207) hide show
  1. package/dist/aerogel-core.css +1 -0
  2. package/dist/aerogel-core.d.ts +2054 -1811
  3. package/dist/aerogel-core.js +3541 -0
  4. package/dist/aerogel-core.js.map +1 -0
  5. package/package.json +32 -37
  6. package/src/bootstrap/bootstrap.test.ts +4 -7
  7. package/src/bootstrap/index.ts +21 -19
  8. package/src/bootstrap/options.ts +1 -1
  9. package/src/components/AppLayout.vue +14 -0
  10. package/src/components/{AGAppModals.vue → AppModals.vue} +3 -4
  11. package/src/components/AppOverlays.vue +9 -0
  12. package/src/components/AppToasts.vue +16 -0
  13. package/src/components/contracts/AlertModal.ts +19 -0
  14. package/src/components/contracts/Button.ts +16 -0
  15. package/src/components/contracts/ConfirmModal.ts +48 -0
  16. package/src/components/contracts/DropdownMenu.ts +25 -0
  17. package/src/components/contracts/ErrorReportModal.ts +33 -0
  18. package/src/components/contracts/Input.ts +26 -0
  19. package/src/components/contracts/LoadingModal.ts +26 -0
  20. package/src/components/contracts/Modal.ts +21 -0
  21. package/src/components/contracts/PromptModal.ts +34 -0
  22. package/src/components/contracts/Select.ts +45 -0
  23. package/src/components/contracts/Toast.ts +15 -0
  24. package/src/components/contracts/index.ts +11 -0
  25. package/src/components/headless/HeadlessButton.vue +51 -0
  26. package/src/components/headless/HeadlessInput.vue +59 -0
  27. package/src/components/headless/{forms/AGHeadlessInputDescription.vue → HeadlessInputDescription.vue} +7 -8
  28. package/src/components/headless/{forms/AGHeadlessInputError.vue → HeadlessInputError.vue} +4 -8
  29. package/src/components/headless/{forms/AGHeadlessInputInput.vue → HeadlessInputInput.vue} +17 -26
  30. package/src/components/headless/{forms/AGHeadlessInputLabel.vue → HeadlessInputLabel.vue} +3 -7
  31. package/src/components/headless/{forms/AGHeadlessInputTextArea.vue → HeadlessInputTextArea.vue} +10 -13
  32. package/src/components/headless/HeadlessModal.vue +57 -0
  33. package/src/components/headless/HeadlessModalContent.vue +30 -0
  34. package/src/components/headless/HeadlessModalDescription.vue +12 -0
  35. package/src/components/headless/HeadlessModalOverlay.vue +12 -0
  36. package/src/components/headless/HeadlessModalTitle.vue +12 -0
  37. package/src/components/headless/HeadlessSelect.vue +120 -0
  38. package/src/components/headless/{forms/AGHeadlessSelectError.vue → HeadlessSelectError.vue} +5 -6
  39. package/src/components/headless/HeadlessSelectLabel.vue +25 -0
  40. package/src/components/headless/HeadlessSelectOption.vue +34 -0
  41. package/src/components/headless/HeadlessSelectOptions.vue +42 -0
  42. package/src/components/headless/HeadlessSelectTrigger.vue +22 -0
  43. package/src/components/headless/HeadlessSelectValue.vue +18 -0
  44. package/src/components/headless/HeadlessSwitch.vue +96 -0
  45. package/src/components/headless/HeadlessToast.vue +18 -0
  46. package/src/components/headless/HeadlessToastAction.vue +13 -0
  47. package/src/components/headless/index.ts +20 -3
  48. package/src/components/index.ts +6 -11
  49. package/src/components/ui/AdvancedOptions.vue +18 -0
  50. package/src/components/ui/AlertModal.vue +17 -0
  51. package/src/components/ui/Button.vue +100 -0
  52. package/src/components/ui/Checkbox.vue +56 -0
  53. package/src/components/ui/ConfirmModal.vue +50 -0
  54. package/src/components/ui/DropdownMenu.vue +32 -0
  55. package/src/components/ui/DropdownMenuOption.vue +22 -0
  56. package/src/components/ui/DropdownMenuOptions.vue +44 -0
  57. package/src/components/ui/EditableContent.vue +82 -0
  58. package/src/components/ui/ErrorLogs.vue +19 -0
  59. package/src/components/ui/ErrorLogsModal.vue +48 -0
  60. package/src/components/ui/ErrorMessage.vue +15 -0
  61. package/src/components/ui/ErrorReportModal.vue +73 -0
  62. package/src/components/{modals/AGErrorReportModalButtons.vue → ui/ErrorReportModalButtons.vue} +34 -27
  63. package/src/components/ui/ErrorReportModalTitle.vue +24 -0
  64. package/src/components/{forms/AGForm.vue → ui/Form.vue} +4 -5
  65. package/src/components/ui/Input.vue +56 -0
  66. package/src/components/ui/Link.vue +12 -0
  67. package/src/components/ui/LoadingModal.vue +34 -0
  68. package/src/components/ui/Markdown.vue +97 -0
  69. package/src/components/ui/Modal.vue +123 -0
  70. package/src/components/ui/ModalContext.vue +31 -0
  71. package/src/components/ui/ProgressBar.vue +51 -0
  72. package/src/components/ui/PromptModal.vue +38 -0
  73. package/src/components/ui/Select.vue +27 -0
  74. package/src/components/ui/SelectLabel.vue +21 -0
  75. package/src/components/ui/SelectOption.vue +29 -0
  76. package/src/components/ui/SelectOptions.vue +35 -0
  77. package/src/components/ui/SelectTrigger.vue +29 -0
  78. package/src/components/ui/SettingsModal.vue +15 -0
  79. package/src/components/{lib/AGStartupCrash.vue → ui/StartupCrash.vue} +8 -8
  80. package/src/components/ui/Switch.vue +11 -0
  81. package/src/components/ui/Toast.vue +46 -0
  82. package/src/components/ui/index.ts +33 -0
  83. package/src/directives/index.ts +9 -5
  84. package/src/directives/measure.ts +12 -6
  85. package/src/errors/Errors.state.ts +1 -1
  86. package/src/errors/Errors.ts +29 -27
  87. package/src/errors/JobCancelledError.ts +3 -0
  88. package/src/errors/index.ts +9 -6
  89. package/src/errors/utils.ts +1 -1
  90. package/src/forms/{Form.test.ts → FormController.test.ts} +32 -8
  91. package/src/forms/{Form.ts → FormController.ts} +42 -38
  92. package/src/forms/index.ts +2 -3
  93. package/src/forms/utils.ts +35 -35
  94. package/src/index.css +73 -0
  95. package/src/jobs/Job.ts +144 -2
  96. package/src/jobs/index.ts +4 -1
  97. package/src/jobs/listeners.ts +3 -0
  98. package/src/jobs/status.ts +4 -0
  99. package/src/lang/DefaultLangProvider.ts +7 -4
  100. package/src/lang/Lang.state.ts +1 -1
  101. package/src/lang/Lang.ts +1 -1
  102. package/src/lang/index.ts +12 -6
  103. package/src/lang/settings/Debug.vue +39 -0
  104. package/src/lang/settings/Language.vue +48 -0
  105. package/src/lang/settings/index.ts +15 -0
  106. package/src/plugins/Plugin.ts +1 -1
  107. package/src/plugins/index.ts +10 -7
  108. package/src/services/App.state.ts +23 -4
  109. package/src/services/App.ts +16 -3
  110. package/src/services/Cache.ts +1 -1
  111. package/src/services/Events.test.ts +8 -8
  112. package/src/services/Events.ts +16 -12
  113. package/src/services/Service.ts +116 -53
  114. package/src/services/Storage.ts +20 -0
  115. package/src/services/index.ts +14 -5
  116. package/src/services/utils.ts +18 -0
  117. package/src/testing/index.ts +4 -3
  118. package/src/testing/setup.ts +5 -13
  119. package/src/ui/UI.state.ts +8 -13
  120. package/src/ui/UI.ts +209 -123
  121. package/src/ui/index.ts +27 -28
  122. package/src/utils/classes.ts +41 -0
  123. package/src/utils/composition/events.ts +4 -6
  124. package/src/utils/composition/forms.ts +20 -4
  125. package/src/utils/composition/persistent.test.ts +33 -0
  126. package/src/utils/composition/persistent.ts +11 -0
  127. package/src/utils/composition/state.test.ts +47 -0
  128. package/src/utils/composition/state.ts +33 -0
  129. package/src/utils/index.ts +5 -1
  130. package/src/utils/markdown.test.ts +50 -0
  131. package/src/utils/markdown.ts +53 -6
  132. package/src/utils/types.ts +3 -0
  133. package/src/utils/vue.ts +38 -141
  134. package/dist/aerogel-core.cjs.js +0 -2
  135. package/dist/aerogel-core.cjs.js.map +0 -1
  136. package/dist/aerogel-core.esm.js +0 -2
  137. package/dist/aerogel-core.esm.js.map +0 -1
  138. package/histoire.config.ts +0 -7
  139. package/noeldemartin.config.js +0 -5
  140. package/postcss.config.js +0 -6
  141. package/src/assets/histoire.css +0 -3
  142. package/src/components/AGAppLayout.vue +0 -16
  143. package/src/components/AGAppOverlays.vue +0 -41
  144. package/src/components/AGAppSnackbars.vue +0 -13
  145. package/src/components/composition.ts +0 -23
  146. package/src/components/constants.ts +0 -8
  147. package/src/components/forms/AGButton.vue +0 -44
  148. package/src/components/forms/AGCheckbox.vue +0 -41
  149. package/src/components/forms/AGInput.vue +0 -40
  150. package/src/components/forms/AGSelect.story.vue +0 -46
  151. package/src/components/forms/AGSelect.vue +0 -60
  152. package/src/components/forms/index.ts +0 -5
  153. package/src/components/headless/forms/AGHeadlessButton.ts +0 -3
  154. package/src/components/headless/forms/AGHeadlessButton.vue +0 -62
  155. package/src/components/headless/forms/AGHeadlessInput.ts +0 -34
  156. package/src/components/headless/forms/AGHeadlessInput.vue +0 -70
  157. package/src/components/headless/forms/AGHeadlessSelect.ts +0 -42
  158. package/src/components/headless/forms/AGHeadlessSelect.vue +0 -77
  159. package/src/components/headless/forms/AGHeadlessSelectButton.vue +0 -24
  160. package/src/components/headless/forms/AGHeadlessSelectLabel.vue +0 -24
  161. package/src/components/headless/forms/AGHeadlessSelectOption.ts +0 -4
  162. package/src/components/headless/forms/AGHeadlessSelectOption.vue +0 -39
  163. package/src/components/headless/forms/AGHeadlessSelectOptions.ts +0 -3
  164. package/src/components/headless/forms/composition.ts +0 -10
  165. package/src/components/headless/forms/index.ts +0 -18
  166. package/src/components/headless/modals/AGHeadlessModal.ts +0 -34
  167. package/src/components/headless/modals/AGHeadlessModal.vue +0 -86
  168. package/src/components/headless/modals/AGHeadlessModalPanel.vue +0 -28
  169. package/src/components/headless/modals/AGHeadlessModalTitle.vue +0 -13
  170. package/src/components/headless/modals/index.ts +0 -4
  171. package/src/components/headless/snackbars/AGHeadlessSnackbar.vue +0 -10
  172. package/src/components/headless/snackbars/index.ts +0 -40
  173. package/src/components/interfaces.ts +0 -24
  174. package/src/components/lib/AGErrorMessage.vue +0 -16
  175. package/src/components/lib/AGLink.vue +0 -9
  176. package/src/components/lib/AGMarkdown.vue +0 -41
  177. package/src/components/lib/AGMeasured.vue +0 -16
  178. package/src/components/lib/index.ts +0 -5
  179. package/src/components/modals/AGAlertModal.ts +0 -15
  180. package/src/components/modals/AGAlertModal.vue +0 -14
  181. package/src/components/modals/AGConfirmModal.ts +0 -33
  182. package/src/components/modals/AGConfirmModal.vue +0 -26
  183. package/src/components/modals/AGErrorReportModal.ts +0 -46
  184. package/src/components/modals/AGErrorReportModal.vue +0 -54
  185. package/src/components/modals/AGErrorReportModalTitle.vue +0 -25
  186. package/src/components/modals/AGLoadingModal.ts +0 -23
  187. package/src/components/modals/AGLoadingModal.vue +0 -15
  188. package/src/components/modals/AGModal.ts +0 -10
  189. package/src/components/modals/AGModal.vue +0 -39
  190. package/src/components/modals/AGModalContext.ts +0 -8
  191. package/src/components/modals/AGModalContext.vue +0 -22
  192. package/src/components/modals/AGModalTitle.vue +0 -9
  193. package/src/components/modals/AGPromptModal.ts +0 -36
  194. package/src/components/modals/AGPromptModal.vue +0 -34
  195. package/src/components/modals/index.ts +0 -17
  196. package/src/components/snackbars/AGSnackbar.vue +0 -36
  197. package/src/components/snackbars/index.ts +0 -3
  198. package/src/components/utils.ts +0 -10
  199. package/src/directives/initial-focus.ts +0 -11
  200. package/src/forms/composition.ts +0 -6
  201. package/src/main.histoire.ts +0 -1
  202. package/src/utils/tailwindcss.test.ts +0 -26
  203. package/src/utils/tailwindcss.ts +0 -7
  204. package/tailwind.config.js +0 -4
  205. package/tsconfig.json +0 -11
  206. package/vite.config.ts +0 -17
  207. /package/src/{main.ts → index.ts} +0 -0
@@ -1,10 +1,18 @@
1
1
  import { describe, expect, expectTypeOf, it } from 'vitest';
2
+ import { tt } from '@noeldemartin/testing';
3
+ import type { Equals } from '@noeldemartin/utils';
4
+ import type { Expect } from '@noeldemartin/testing';
2
5
 
3
- import { useForm } from './composition';
4
- import { FormFieldTypes } from '@/main';
5
- import { numberInput, requiredStringInput } from '@/forms/utils';
6
+ import {
7
+ numberInput,
8
+ objectInput,
9
+ requiredObjectInput,
10
+ requiredStringInput,
11
+ stringInput,
12
+ } from '@aerogel/core/forms/utils';
13
+ import { useForm } from '@aerogel/core/utils/composition/forms';
6
14
 
7
- describe('Form', () => {
15
+ describe('FormController', () => {
8
16
 
9
17
  it('defines magic fields', () => {
10
18
  const form = useForm({
@@ -20,7 +28,7 @@ describe('Form', () => {
20
28
  // Arrange
21
29
  const form = useForm({
22
30
  name: {
23
- type: FormFieldTypes.String,
31
+ type: 'string',
24
32
  rules: 'required',
25
33
  },
26
34
  });
@@ -38,7 +46,7 @@ describe('Form', () => {
38
46
  // Arrange
39
47
  const form = useForm({
40
48
  name: {
41
- type: FormFieldTypes.String,
49
+ type: 'string',
42
50
  rules: 'required',
43
51
  },
44
52
  });
@@ -59,11 +67,11 @@ describe('Form', () => {
59
67
  // Arrange
60
68
  const form = useForm({
61
69
  trimmed: {
62
- type: FormFieldTypes.String,
70
+ type: 'string',
63
71
  rules: 'required',
64
72
  },
65
73
  untrimmed: {
66
- type: FormFieldTypes.String,
74
+ type: 'string',
67
75
  rules: 'required',
68
76
  trim: false,
69
77
  },
@@ -83,4 +91,20 @@ describe('Form', () => {
83
91
  expect(form.errors).toEqual({ trimmed: ['required'], untrimmed: null });
84
92
  });
85
93
 
94
+ it('infers field types', () => {
95
+ const form = useForm({
96
+ one: stringInput(),
97
+ two: requiredStringInput(),
98
+ three: objectInput(),
99
+ four: requiredObjectInput<{ foo: string; bar?: number }>(),
100
+ });
101
+
102
+ tt<
103
+ | Expect<Equals<typeof form.one, string | null>>
104
+ | Expect<Equals<typeof form.two, string>>
105
+ | Expect<Equals<typeof form.three, object | null>>
106
+ | Expect<Equals<typeof form.four, { foo: string; bar?: number }>>
107
+ >();
108
+ });
109
+
86
110
  });
@@ -1,33 +1,32 @@
1
1
  import { computed, nextTick, reactive, readonly, ref } from 'vue';
2
2
  import { MagicObject, arrayRemove, fail, toString } from '@noeldemartin/utils';
3
- import { validate } from './validation';
4
- import type { ObjectValues } from '@noeldemartin/utils';
5
3
  import type { ComputedRef, DeepReadonly, Ref, UnwrapNestedRefs } from 'vue';
6
4
 
7
- export const FormFieldTypes = {
8
- String: 'string',
9
- Number: 'number',
10
- Boolean: 'boolean',
11
- Object: 'object',
12
- Date: 'date',
13
- } as const;
5
+ import { validate } from './validation';
6
+
7
+ export const __objectType: unique symbol = Symbol();
14
8
 
15
- export interface FormFieldDefinition<TType extends FormFieldType = FormFieldType, TRules extends string = string> {
9
+ export interface FormFieldDefinition<
10
+ TType extends FormFieldType = FormFieldType,
11
+ TRules extends string = string,
12
+ TObjectType = object,
13
+ > {
16
14
  type: TType;
17
15
  trim?: boolean;
18
16
  default?: GetFormFieldValue<TType>;
19
17
  rules?: TRules;
18
+ [__objectType]?: TObjectType;
20
19
  }
21
20
 
22
- export type FormFieldDefinitions = Record<string, FormFieldDefinition>;
23
- export type FormFieldType = ObjectValues<typeof FormFieldTypes>;
21
+ export type FormFieldType = 'string' | 'number' | 'boolean' | 'object' | 'date';
24
22
  export type FormFieldValue = GetFormFieldValue<FormFieldType>;
23
+ export type FormFieldDefinitions = Record<string, FormFieldDefinition>;
25
24
 
26
25
  export type FormData<T> = {
27
- -readonly [k in keyof T]: T[k] extends FormFieldDefinition<infer TType, infer TRules>
26
+ -readonly [k in keyof T]: T[k] extends FormFieldDefinition<infer TType, infer TRules, infer TObjectType>
28
27
  ? TRules extends 'required'
29
- ? GetFormFieldValue<TType>
30
- : GetFormFieldValue<TType> | null
28
+ ? GetFormFieldValue<TType, TObjectType>
29
+ : GetFormFieldValue<TType, TObjectType> | null
31
30
  : never;
32
31
  };
33
32
 
@@ -35,24 +34,26 @@ export type FormErrors<T> = {
35
34
  [k in keyof T]: string[] | null;
36
35
  };
37
36
 
38
- export type GetFormFieldValue<TType> = TType extends typeof FormFieldTypes.String
37
+ export type GetFormFieldValue<TType, TObjectType = object> = TType extends 'string'
39
38
  ? string
40
- : TType extends typeof FormFieldTypes.Number
41
- ? number
42
- : TType extends typeof FormFieldTypes.Boolean
43
- ? boolean
44
- : TType extends typeof FormFieldTypes.Object
45
- ? object
46
- : TType extends typeof FormFieldTypes.Date
47
- ? Date
48
- : never;
49
-
50
- const validForms: WeakMap<Form, ComputedRef<boolean>> = new WeakMap();
39
+ : TType extends 'number'
40
+ ? number
41
+ : TType extends 'boolean'
42
+ ? boolean
43
+ : TType extends 'object'
44
+ ? TObjectType extends object
45
+ ? TObjectType
46
+ : object
47
+ : TType extends 'date'
48
+ ? Date
49
+ : never;
50
+
51
+ const validForms: WeakMap<FormController, ComputedRef<boolean>> = new WeakMap();
51
52
 
52
53
  export type SubmitFormListener = () => unknown;
53
54
  export type FocusFormListener = (input: string) => unknown;
54
55
 
55
- export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinitions> extends MagicObject {
56
+ export default class FormController<Fields extends FormFieldDefinitions = FormFieldDefinitions> extends MagicObject {
56
57
 
57
58
  public errors: DeepReadonly<UnwrapNestedRefs<FormErrors<Fields>>>;
58
59
 
@@ -91,7 +92,7 @@ export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinit
91
92
  this._fields[field] ?? fail<FormFieldDefinition>(`Trying to set undefined '${toString(field)}' field`);
92
93
 
93
94
  this._data[field] =
94
- definition.type === FormFieldTypes.String && (definition.trim ?? true)
95
+ definition.type === 'string' && (definition.trim ?? true)
95
96
  ? (toString(value).trim() as FormData<Fields>[T])
96
97
  : value;
97
98
 
@@ -113,11 +114,14 @@ export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinit
113
114
  }
114
115
 
115
116
  public validate(): boolean {
116
- const errors = Object.entries(this._fields).reduce((formErrors, [name, definition]) => {
117
- formErrors[name] = this.getFieldErrors(name, definition);
117
+ const errors = Object.entries(this._fields).reduce(
118
+ (formErrors, [name, definition]) => {
119
+ formErrors[name] = this.getFieldErrors(name, definition);
118
120
 
119
- return formErrors;
120
- }, {} as Record<string, string[] | null>);
121
+ return formErrors;
122
+ },
123
+ {} as Record<string, string[] | null>,
124
+ );
121
125
 
122
126
  this.resetErrors(errors);
123
127
 
@@ -165,7 +169,7 @@ export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinit
165
169
  this._listeners['focus']?.forEach((listener) => listener(input));
166
170
  }
167
171
 
168
- protected __get(property: string): unknown {
172
+ protected override __get(property: string): unknown {
169
173
  if (!(property in this._fields)) {
170
174
  return super.__get(property);
171
175
  }
@@ -173,7 +177,7 @@ export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinit
173
177
  return this.getFieldValue(property);
174
178
  }
175
179
 
176
- protected __set(property: string, value: unknown): void {
180
+ protected override __set(property: string, value: unknown): void {
177
181
  if (!(property in this._fields)) {
178
182
  super.__set(property, value);
179
183
 
@@ -204,10 +208,10 @@ export default class Form<Fields extends FormFieldDefinitions = FormFieldDefinit
204
208
  return {} as FormData<Fields>;
205
209
  }
206
210
 
207
- const data = Object.entries(fields).reduce((formData, [name, definition]) => {
208
- formData[name as keyof Fields] = (definition.default ?? null) as FormData<Fields>[keyof Fields];
211
+ const data = Object.entries(fields).reduce((initialData, [name, definition]) => {
212
+ initialData[name as keyof Fields] = (definition.default ?? null) as FormData<Fields>[keyof Fields];
209
213
 
210
- return formData;
214
+ return initialData;
211
215
  }, {} as FormData<Fields>);
212
216
 
213
217
  return reactive(data) as FormData<Fields>;
@@ -1,5 +1,4 @@
1
- export * from './composition';
2
- export * from './Form';
1
+ export * from './FormController';
3
2
  export * from './utils';
4
3
  export * from './validation';
5
- export { default as Form } from './Form';
4
+ export { default as FormController } from './FormController';
@@ -1,84 +1,84 @@
1
- import { FormFieldTypes } from './Form';
2
- import type { FormFieldDefinition } from './Form';
1
+ import type { FormFieldDefinition } from './FormController';
3
2
 
4
- export function booleanInput(
5
- defaultValue?: boolean,
6
- options: { rules?: string } = {},
7
- ): FormFieldDefinition<typeof FormFieldTypes.Boolean> {
3
+ export function booleanInput(defaultValue?: boolean, options: { rules?: string } = {}): FormFieldDefinition<'boolean'> {
8
4
  return {
9
5
  default: defaultValue,
10
- type: FormFieldTypes.Boolean,
6
+ type: 'boolean',
11
7
  rules: options.rules,
12
8
  };
13
9
  }
14
10
 
15
- export function dateInput(
16
- defaultValue?: Date,
17
- options: { rules?: string } = {},
18
- ): FormFieldDefinition<typeof FormFieldTypes.Date> {
11
+ export function dateInput(defaultValue?: Date, options: { rules?: string } = {}): FormFieldDefinition<'date'> {
19
12
  return {
20
13
  default: defaultValue,
21
- type: FormFieldTypes.Date,
14
+ type: 'date',
22
15
  rules: options.rules,
23
16
  };
24
17
  }
25
18
 
26
- export function requiredBooleanInput(
27
- defaultValue?: boolean,
28
- ): FormFieldDefinition<typeof FormFieldTypes.Boolean, 'required'> {
19
+ export function requiredBooleanInput(defaultValue?: boolean): FormFieldDefinition<'boolean', 'required'> {
29
20
  return {
30
21
  default: defaultValue,
31
- type: FormFieldTypes.Boolean,
22
+ type: 'boolean',
32
23
  rules: 'required',
33
24
  };
34
25
  }
35
26
 
36
- export function requiredDateInput(defaultValue?: Date): FormFieldDefinition<typeof FormFieldTypes.Date> {
27
+ export function requiredDateInput(defaultValue?: Date): FormFieldDefinition<'date', 'required'> {
37
28
  return {
38
29
  default: defaultValue,
39
- type: FormFieldTypes.Date,
30
+ type: 'date',
40
31
  rules: 'required',
41
32
  };
42
33
  }
43
34
 
44
- export function requiredNumberInput(
45
- defaultValue?: number,
46
- ): FormFieldDefinition<typeof FormFieldTypes.Number, 'required'> {
35
+ export function requiredNumberInput(defaultValue?: number): FormFieldDefinition<'number', 'required'> {
47
36
  return {
48
37
  default: defaultValue,
49
- type: FormFieldTypes.Number,
38
+ type: 'number',
50
39
  rules: 'required',
51
40
  };
52
41
  }
53
42
 
54
- export function requiredStringInput(
55
- defaultValue?: string,
56
- ): FormFieldDefinition<typeof FormFieldTypes.String, 'required'> {
43
+ export function requiredObjectInput<T extends object>(defaultValue?: T): FormFieldDefinition<'object', 'required', T> {
57
44
  return {
58
45
  default: defaultValue,
59
- type: FormFieldTypes.String,
46
+ type: 'object',
60
47
  rules: 'required',
61
48
  };
62
49
  }
63
50
 
64
- export function numberInput(
65
- defaultValue?: number,
66
- options: { rules?: string } = {},
67
- ): FormFieldDefinition<typeof FormFieldTypes.Number> {
51
+ export function requiredStringInput(defaultValue?: string): FormFieldDefinition<'string', 'required'> {
68
52
  return {
69
53
  default: defaultValue,
70
- type: FormFieldTypes.Number,
54
+ type: 'string',
55
+ rules: 'required',
56
+ };
57
+ }
58
+
59
+ export function numberInput(defaultValue?: number, options: { rules?: string } = {}): FormFieldDefinition<'number'> {
60
+ return {
61
+ default: defaultValue,
62
+ type: 'number',
71
63
  rules: options.rules,
72
64
  };
73
65
  }
74
66
 
75
- export function stringInput(
76
- defaultValue?: string,
67
+ export function objectInput<T extends object>(
68
+ defaultValue?: T,
77
69
  options: { rules?: string } = {},
78
- ): FormFieldDefinition<typeof FormFieldTypes.String> {
70
+ ): FormFieldDefinition<'object', string, T> {
71
+ return {
72
+ default: defaultValue,
73
+ type: 'object',
74
+ rules: options.rules,
75
+ };
76
+ }
77
+
78
+ export function stringInput(defaultValue?: string, options: { rules?: string } = {}): FormFieldDefinition<'string'> {
79
79
  return {
80
80
  default: defaultValue,
81
- type: FormFieldTypes.String,
81
+ type: 'string',
82
82
  rules: options.rules,
83
83
  };
84
84
  }
package/src/index.css ADDED
@@ -0,0 +1,73 @@
1
+ @import 'tailwindcss';
2
+
3
+ @plugin '@tailwindcss/forms';
4
+ @plugin '@tailwindcss/typography';
5
+
6
+ @source './';
7
+
8
+ @theme {
9
+ --color-primary: oklch(0.205 0 0);
10
+ --color-primary-50: color-mix(in oklab, var(--color-primary-600) 5%, transparent);
11
+ --color-primary-100: color-mix(in oklab, var(--color-primary-600) 15%, transparent);
12
+ --color-primary-200: color-mix(in oklab, var(--color-primary-600) 30%, transparent);
13
+ --color-primary-300: color-mix(in oklab, var(--color-primary-600) 50%, transparent);
14
+ --color-primary-400: color-mix(in oklab, var(--color-primary-600) 65%, transparent);
15
+ --color-primary-500: color-mix(in oklab, var(--color-primary-600) 80%, transparent);
16
+ --color-primary-600: var(--color-primary);
17
+ --color-primary-700: color-mix(in oklab, var(--color-primary-600) 90%, black);
18
+ --color-primary-800: color-mix(in oklab, var(--color-primary-600) 80%, black);
19
+ --color-primary-900: color-mix(in oklab, var(--color-primary-600) 70%, black);
20
+ --color-primary-950: color-mix(in oklab, var(--color-primary-600) 50%, black);
21
+
22
+ --color-background: oklch(1 0 0);
23
+ --color-links: var(--color-primary);
24
+ }
25
+
26
+ .clickable {
27
+ position: relative;
28
+ }
29
+
30
+ .clickable::after {
31
+ --clickable-size: 44px;
32
+ --clickable-inset-by: min(0px, calc((100% - var(--clickable-size)) / 2));
33
+
34
+ content: '';
35
+ position: absolute;
36
+ top: var(--clickable-inset-by);
37
+ left: var(--clickable-inset-by);
38
+ right: var(--clickable-inset-by);
39
+ bottom: var(--clickable-inset-by);
40
+ }
41
+
42
+ input[type='number'].appearance-textfield {
43
+ appearance: textfield;
44
+ }
45
+
46
+ input[type='number'].appearance-textfield::-webkit-outer-spin-button,
47
+ input[type='number'].appearance-textfield::-webkit-inner-spin-button {
48
+ appearance: none;
49
+ }
50
+
51
+ button[data-markdown-action] {
52
+ color: var(--tw-prose-links);
53
+ text-decoration: underline;
54
+ font-weight: 500;
55
+ }
56
+
57
+ @keyframes fade-in {
58
+ 0% {
59
+ opacity: 0;
60
+ }
61
+ 100% {
62
+ opacity: 1;
63
+ }
64
+ }
65
+
66
+ @keyframes grow {
67
+ 0% {
68
+ scale: 0;
69
+ }
70
+ 100% {
71
+ opacity: 1;
72
+ }
73
+ }
package/src/jobs/Job.ts CHANGED
@@ -1,5 +1,147 @@
1
- export default abstract class Job {
1
+ import { ListenersManager, PromisedValue, round, tap, toError } from '@noeldemartin/utils';
2
+ import type { Listeners } from '@noeldemartin/utils';
2
3
 
3
- public abstract run(): Promise<void>;
4
+ import JobCancelledError from '@aerogel/core/errors/JobCancelledError';
5
+
6
+ import type { JobListener } from './listeners';
7
+ import type { JobStatus } from './status';
8
+
9
+ export default abstract class Job<
10
+ Listener extends JobListener = JobListener,
11
+ Status extends JobStatus = JobStatus,
12
+ SerializedStatus extends JobStatus = JobStatus,
13
+ > {
14
+
15
+ protected status: Status;
16
+ protected _listeners: ListenersManager<JobListener>;
17
+ protected _progress?: number;
18
+ protected _cancelled?: PromisedValue<void>;
19
+ protected _started: PromisedValue<void>;
20
+ protected _completed: PromisedValue<void>;
21
+
22
+ constructor() {
23
+ this.status = this.getInitialStatus();
24
+ this._listeners = new ListenersManager();
25
+ this._started = new PromisedValue();
26
+ this._completed = new PromisedValue();
27
+ }
28
+
29
+ public async start(): Promise<void> {
30
+ this.beforeStart();
31
+ this._started.resolve();
32
+
33
+ try {
34
+ await this.updateProgress();
35
+ await this.run();
36
+ await this.updateProgress();
37
+
38
+ this._completed.resolve();
39
+ } catch (error) {
40
+ if (error instanceof JobCancelledError) {
41
+ return;
42
+ }
43
+
44
+ throw tap(toError(error), (realError) => {
45
+ this._completed.reject(realError);
46
+ });
47
+ }
48
+ }
49
+
50
+ public async cancel(): Promise<void> {
51
+ this._cancelled = new PromisedValue();
52
+
53
+ await this._cancelled;
54
+ }
55
+
56
+ public serialize(): SerializedStatus {
57
+ return this.serializeStatus(this.status);
58
+ }
59
+
60
+ public get listeners(): Listeners<Listener> {
61
+ return this._listeners;
62
+ }
63
+
64
+ public get progress(): number {
65
+ return this._progress ?? 0;
66
+ }
67
+
68
+ public get cancelled(): boolean {
69
+ return !!this._cancelled?.isResolved();
70
+ }
71
+
72
+ public get started(): Promise<void> {
73
+ return this._started;
74
+ }
75
+
76
+ public get completed(): Promise<void> {
77
+ return this._completed;
78
+ }
79
+
80
+ protected abstract run(): Promise<void>;
81
+
82
+ protected getInitialStatus(): Status {
83
+ return { completed: false } as Status;
84
+ }
85
+
86
+ protected beforeStart(): void {
87
+ if (!this._started.isResolved()) {
88
+ return;
89
+ }
90
+
91
+ if (this._cancelled) {
92
+ delete this._progress;
93
+ delete this._cancelled;
94
+
95
+ return;
96
+ }
97
+
98
+ throw new Error('Job already started!');
99
+ }
100
+
101
+ protected assertNotCancelled(): void {
102
+ if (!this._cancelled) {
103
+ return;
104
+ }
105
+
106
+ this._cancelled.resolve();
107
+
108
+ throw new JobCancelledError();
109
+ }
110
+
111
+ protected calculateCurrentProgress(status?: JobStatus): number {
112
+ status ??= this.status;
113
+
114
+ if (status.completed) {
115
+ return 1;
116
+ }
117
+
118
+ if (!status.children) {
119
+ return 0;
120
+ }
121
+
122
+ return round(
123
+ status.children.reduce((total, child) => total + this.calculateCurrentProgress(child), 0) /
124
+ status.children.length,
125
+ 2,
126
+ );
127
+ }
128
+
129
+ protected async updateProgress(update?: (status: Status) => unknown): Promise<void> {
130
+ await update?.(this.status);
131
+
132
+ const progress = this.calculateCurrentProgress();
133
+
134
+ if (progress === this._progress) {
135
+ return;
136
+ }
137
+
138
+ this._progress = progress;
139
+
140
+ await this._listeners.emit('onUpdated', progress);
141
+ }
142
+
143
+ protected serializeStatus(status: Status): SerializedStatus {
144
+ return { ...status } as unknown as SerializedStatus;
145
+ }
4
146
 
5
147
  }
package/src/jobs/index.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  import Job from './Job';
2
2
 
3
3
  export { Job };
4
+ export * from './Job';
5
+ export * from './listeners';
6
+ export * from './status';
4
7
 
5
8
  export async function dispatch(job: Job): Promise<void> {
6
- await job.run();
9
+ await job.start();
7
10
  }
@@ -0,0 +1,3 @@
1
+ export interface JobListener {
2
+ onUpdated?(progress: number): unknown;
3
+ }
@@ -0,0 +1,4 @@
1
+ export interface JobStatus {
2
+ completed: boolean;
3
+ children?: JobStatus[];
4
+ }
@@ -1,10 +1,13 @@
1
- import App from '@/services/App';
1
+ import { isDevelopment } from '@noeldemartin/utils';
2
2
 
3
3
  import type { LangProvider } from './Lang';
4
4
 
5
5
  export default class DefaultLangProvider implements LangProvider {
6
6
 
7
- constructor(private locale: string, private fallbackLocale: string) {}
7
+ constructor(
8
+ private locale: string,
9
+ private fallbackLocale: string,
10
+ ) {}
8
11
 
9
12
  public getLocale(): string {
10
13
  return this.locale;
@@ -28,14 +31,14 @@ export default class DefaultLangProvider implements LangProvider {
28
31
 
29
32
  public translate(key: string): string {
30
33
  // eslint-disable-next-line no-console
31
- App.development && console.warn('Lang provider is missing');
34
+ isDevelopment() && console.warn('Lang provider is missing');
32
35
 
33
36
  return key;
34
37
  }
35
38
 
36
39
  public translateWithDefault(_: string, defaultMessage: string): string {
37
40
  // eslint-disable-next-line no-console
38
- App.development && console.warn('Lang provider is missing');
41
+ isDevelopment() && console.warn('Lang provider is missing');
39
42
 
40
43
  return defaultMessage;
41
44
  }
@@ -1,4 +1,4 @@
1
- import { defineServiceState } from '@/services/Service';
1
+ import { defineServiceState } from '@aerogel/core/services/Service';
2
2
 
3
3
  export default defineServiceState({
4
4
  name: 'lang',
package/src/lang/Lang.ts CHANGED
@@ -52,7 +52,7 @@ export class LangService extends Service {
52
52
  return navigator.languages.find((locale) => locales.includes(locale)) ?? 'en';
53
53
  }
54
54
 
55
- protected async boot(): Promise<void> {
55
+ protected override async boot(): Promise<void> {
56
56
  if (!globalThis.document) {
57
57
  return;
58
58
  }