@aerogel/core 0.0.0-next.e4c0d5bd2801fbe93545477ea515af53df69b522 → 0.0.0-next.ea2e864c719d0a4d01b04729a9b681c0e9c85ea7

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aerogel/core",
3
- "version": "0.0.0-next.e4c0d5bd2801fbe93545477ea515af53df69b522",
3
+ "version": "0.0.0-next.ea2e864c719d0a4d01b04729a9b681c0e9c85ea7",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "exports": {
@@ -33,6 +33,7 @@
33
33
  "class-variance-authority": "^0.7.1",
34
34
  "clsx": "^2.1.1",
35
35
  "dompurify": "^3.2.4",
36
+ "eruda": "^3.4.1",
36
37
  "marked": "^15.0.7",
37
38
  "pinia": "^2.1.6",
38
39
  "reka-ui": "^2.2.0",
@@ -64,8 +64,8 @@ watchEffect(() => {
64
64
  return;
65
65
  }
66
66
 
67
- if (type === 'date') {
68
- $input.value.valueAsDate = value.value as Date;
67
+ if (type === 'date' && value.value instanceof Date) {
68
+ $input.value.valueAsDate = value.value;
69
69
 
70
70
  return;
71
71
  }
@@ -0,0 +1,96 @@
1
+ <template>
2
+ <div :class="rootClass">
3
+ <label v-if="label" :for="expose.id" :class="labelClass">
4
+ {{ label }}
5
+ </label>
6
+ <SwitchRoot
7
+ :id="expose.id"
8
+ :name
9
+ :model-value="expose.value.value"
10
+ v-bind="$attrs"
11
+ :class="inputClass"
12
+ @update:model-value="$emit('update:modelValue', $event)"
13
+ >
14
+ <SwitchThumb :class="thumbClass" />
15
+ </SwitchRoot>
16
+ </div>
17
+ </template>
18
+
19
+ <script setup lang="ts" generic="T extends boolean = boolean">
20
+ import { SwitchRoot, SwitchThumb } from 'reka-ui';
21
+ import { computed, inject, readonly, watchEffect } from 'vue';
22
+ import { uuid } from '@noeldemartin/utils';
23
+ import type { HTMLAttributes } from 'vue';
24
+
25
+ import type FormController from '@aerogel/core/forms/FormController';
26
+ import type { FormFieldValue } from '@aerogel/core/forms/FormController';
27
+ import type { InputEmits, InputExpose, InputProps } from '@aerogel/core/components/contracts/Input';
28
+
29
+ defineOptions({ inheritAttrs: false });
30
+
31
+ const {
32
+ name,
33
+ label,
34
+ description,
35
+ modelValue,
36
+ class: rootClass,
37
+ } = defineProps<
38
+ InputProps<T> & {
39
+ class?: HTMLAttributes['class'];
40
+ labelClass?: HTMLAttributes['class'];
41
+ inputClass?: HTMLAttributes['class'];
42
+ thumbClass?: HTMLAttributes['class'];
43
+ }
44
+ >();
45
+ const emit = defineEmits<InputEmits>();
46
+ const form = inject<FormController | null>('form', null);
47
+ const errors = computed(() => {
48
+ if (!form || !name) {
49
+ return null;
50
+ }
51
+
52
+ return form.errors[name] ?? null;
53
+ });
54
+
55
+ const expose = {
56
+ id: `switch-${uuid()}`,
57
+ name: computed(() => name),
58
+ label: computed(() => label),
59
+ description: computed(() => description),
60
+ value: computed(() => {
61
+ if (form && name) {
62
+ return form.getFieldValue(name) as boolean;
63
+ }
64
+
65
+ return modelValue;
66
+ }),
67
+ errors: readonly(errors),
68
+ required: computed(() => {
69
+ if (!name || !form) {
70
+ return;
71
+ }
72
+
73
+ return form.getFieldRules(name).includes('required');
74
+ }),
75
+ update(value) {
76
+ if (form && name) {
77
+ form.setFieldValue(name, value as FormFieldValue);
78
+
79
+ return;
80
+ }
81
+
82
+ emit('update:modelValue', value);
83
+ },
84
+ } satisfies InputExpose;
85
+
86
+ defineExpose(expose);
87
+
88
+ watchEffect(() => {
89
+ if (!description && !errors.value) {
90
+ return;
91
+ }
92
+
93
+ // eslint-disable-next-line no-console
94
+ console.warn('Errors and description not implemented in <HeadlessSwitch>');
95
+ });
96
+ </script>
@@ -16,4 +16,5 @@ export { default as HeadlessSelectOption } from './HeadlessSelectOption.vue';
16
16
  export { default as HeadlessSelectOptions } from './HeadlessSelectOptions.vue';
17
17
  export { default as HeadlessSelectTrigger } from './HeadlessSelectTrigger.vue';
18
18
  export { default as HeadlessSelectValue } from './HeadlessSelectValue.vue';
19
+ export { default as HeadlessSwitch } from './HeadlessSwitch.vue';
19
20
  export { default as HeadlessToast } from './HeadlessToast.vue';
@@ -88,6 +88,21 @@ const renderedClasses = computed(() => variantClasses<Variants<Pick<ButtonProps,
88
88
  disabled: false,
89
89
  class: 'hover:underline',
90
90
  },
91
+ {
92
+ variant: 'link',
93
+ size: 'small',
94
+ class: 'leading-6',
95
+ },
96
+ {
97
+ variant: 'link',
98
+ size: 'default',
99
+ class: 'leading-8',
100
+ },
101
+ {
102
+ variant: 'link',
103
+ size: 'large',
104
+ class: 'leading-10',
105
+ },
91
106
  ],
92
107
  defaultVariants: {
93
108
  variant: 'default',
@@ -27,14 +27,22 @@
27
27
 
28
28
  <HeadlessModalTitle
29
29
  v-if="title"
30
- class="px-4 pt-5 pb-2 text-base font-semibold text-gray-900"
31
- :class="{ 'sr-only': titleHidden }"
30
+ class="px-4 pt-5 text-base font-semibold text-gray-900"
31
+ :class="{
32
+ 'sr-only': titleHidden,
33
+ 'pb-0': description && !descriptionHidden,
34
+ 'pb-2': !description || descriptionHidden,
35
+ }"
32
36
  >
33
37
  <Markdown :text="title" inline />
34
38
  </HeadlessModalTitle>
35
39
 
36
- <HeadlessModalDescription v-if="description" :class="{ 'sr-only': descriptionHidden }">
37
- <Markdown :text="description" class="mt-1 text-sm leading-6 text-gray-500" />
40
+ <HeadlessModalDescription
41
+ v-if="description"
42
+ class="px-4 pt-1 pb-2"
43
+ :class="{ 'sr-only': descriptionHidden }"
44
+ >
45
+ <Markdown :text="description" class="text-sm leading-6 text-gray-500" />
38
46
  </HeadlessModalDescription>
39
47
 
40
48
  <div :class="renderedContentClass">
@@ -7,11 +7,15 @@
7
7
 
8
8
  <script setup lang="ts">
9
9
  import { computed } from 'vue';
10
+ import type { HTMLAttributes } from 'vue';
10
11
 
11
12
  import HeadlessSelectLabel from '@aerogel/core/components/headless/HeadlessSelectLabel.vue';
12
13
  import { classes, injectReactiveOrFail } from '@aerogel/core/utils';
13
14
  import type { SelectExpose } from '@aerogel/core/components/contracts/Select';
14
15
 
16
+ const { class: rootClasses } = defineProps<{ class?: HTMLAttributes['class'] }>();
17
+
15
18
  const select = injectReactiveOrFail<SelectExpose>('select', '<SelectLabel> must be a child of a <Select>');
16
- const renderedClasses = computed(() => classes('block text-sm leading-6 font-medium text-gray-900', select.labelClass));
19
+ const renderedClasses = computed(() =>
20
+ classes('block text-sm leading-6 font-medium text-gray-900', select.labelClass, rootClasses));
17
21
  </script>
@@ -0,0 +1,11 @@
1
+ <template>
2
+ <HeadlessSwitch
3
+ class="flex flex-row items-center gap-1"
4
+ input-class="disabled:opacity-50 disabled:cursor-not-allowed data-[state=checked]:bg-primary-600 data-[state=unchecked]:bg-gray-200 relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focusdisabled:opacity-50 disabled:cursor-not-allowed :ring-2 focus:ring-primary-600 focus:ring-offset-2 focus:outline-hidden"
5
+ thumb-class="data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0 pointer-events-none inline-block size-5 transform rounded-full bg-white shadow-sm ring-0 transition duration-200 ease-in-out"
6
+ />
7
+ </template>
8
+
9
+ <script setup lang="ts">
10
+ import HeadlessSwitch from '@aerogel/core/components/headless/HeadlessSwitch.vue';
11
+ </script>
@@ -29,4 +29,5 @@ export { default as SelectOptions } from './SelectOptions.vue';
29
29
  export { default as SelectTrigger } from './SelectTrigger.vue';
30
30
  export { default as SettingsModal } from './SettingsModal.vue';
31
31
  export { default as StartupCrash } from './StartupCrash.vue';
32
+ export { default as Switch } from './Switch.vue';
32
33
  export { default as Toast } from './Toast.vue';
@@ -1,9 +1,11 @@
1
- import type { App } from 'vue';
1
+ import type { App as AppInstance } from 'vue';
2
2
 
3
+ import App from '@aerogel/core/services/App';
3
4
  import { bootServices } from '@aerogel/core/services';
4
5
  import { definePlugin } from '@aerogel/core/plugins';
5
6
 
6
7
  import Errors from './Errors';
8
+ import settings from './settings';
7
9
  import type { ErrorReport, ErrorReportLog, ErrorSource } from './Errors.state';
8
10
 
9
11
  export * from './utils';
@@ -19,7 +21,7 @@ const frameworkHandler: ErrorHandler = (error) => {
19
21
  return true;
20
22
  };
21
23
 
22
- function setUpErrorHandler(app: App, baseHandler: ErrorHandler = () => false): void {
24
+ function setUpErrorHandler(app: AppInstance, baseHandler: ErrorHandler = () => false): void {
23
25
  const errorHandler: ErrorHandler = (error) => baseHandler(error) || frameworkHandler(error);
24
26
 
25
27
  app.config.errorHandler = errorHandler;
@@ -34,6 +36,8 @@ export default definePlugin({
34
36
  async install(app, options) {
35
37
  setUpErrorHandler(app, options.handleError);
36
38
 
39
+ settings.forEach((setting) => App.addSetting(setting));
40
+
37
41
  await bootServices(app, services);
38
42
  },
39
43
  });
@@ -0,0 +1,39 @@
1
+ <template>
2
+ <div class="mt-4 flex flex-row">
3
+ <div class="flex-grow">
4
+ <h3 id="debug-setting" class="text-base font-semibold">
5
+ {{ $td('settings.debug', 'Debugging') }}
6
+ </h3>
7
+ <Markdown
8
+ lang-key="settings.debugDescription"
9
+ lang-default="Enable debugging with [Eruda](https://eruda.liriliri.io/)."
10
+ class="mt-1 text-sm text-gray-500"
11
+ />
12
+ </div>
13
+
14
+ <Switch v-model="enabled" aria-labelledby="debug-setting" />
15
+ </div>
16
+ </template>
17
+
18
+ <script setup lang="ts">
19
+ import { ref, watchEffect } from 'vue';
20
+ import type Eruda from 'eruda';
21
+
22
+ import Switch from '@aerogel/core/components/ui/Switch.vue';
23
+ import Markdown from '@aerogel/core/components/ui/Markdown.vue';
24
+
25
+ let eruda: typeof Eruda | null = null;
26
+ const enabled = ref(false);
27
+
28
+ watchEffect(async () => {
29
+ if (!enabled.value) {
30
+ eruda?.destroy();
31
+
32
+ return;
33
+ }
34
+
35
+ eruda ??= (await import('eruda')).default;
36
+
37
+ eruda.init();
38
+ });
39
+ </script>
@@ -0,0 +1,10 @@
1
+ import { defineSettings } from '@aerogel/core/services';
2
+
3
+ import Debug from './Debug.vue';
4
+
5
+ export default defineSettings([
6
+ {
7
+ priority: 10,
8
+ component: Debug,
9
+ },
10
+ ]);
package/src/lang/index.ts CHANGED
@@ -4,8 +4,8 @@ import { definePlugin } from '@aerogel/core/plugins';
4
4
 
5
5
  import Lang from './Lang';
6
6
  import settings from './settings';
7
- import type { LangProvider } from './Lang';
8
7
  import { translate, translateWithDefault } from './utils';
8
+ import type { LangProvider } from './Lang';
9
9
 
10
10
  export { Lang, translate, translateWithDefault };
11
11
  export type { LangProvider };
@@ -7,7 +7,7 @@
7
7
  :render-option="renderLocale"
8
8
  >
9
9
  <div class="grow">
10
- <SelectLabel>
10
+ <SelectLabel class="text-base font-semibold">
11
11
  {{ $td('settings.locale', 'Language') }}
12
12
  </SelectLabel>
13
13
  <Markdown
@@ -1,4 +1,4 @@
1
- import type { App as VueApp } from 'vue';
1
+ import type { App as AppInstance } from 'vue';
2
2
 
3
3
  import { definePlugin } from '@aerogel/core/plugins';
4
4
  import { isDevelopment, isTesting } from '@noeldemartin/utils';
@@ -30,7 +30,7 @@ export type DefaultServices = typeof defaultServices;
30
30
 
31
31
  export interface Services extends DefaultServices {}
32
32
 
33
- export async function bootServices(app: VueApp, services: Record<string, Service>): Promise<void> {
33
+ export async function bootServices(app: AppInstance, services: Record<string, Service>): Promise<void> {
34
34
  await Promise.all(
35
35
  Object.entries(services).map(async ([name, service]) => {
36
36
  await service