@shwfed/nuxt 0.11.16 → 0.11.18
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/dist/module.json +1 -1
- package/dist/module.mjs +4 -0
- package/dist/runtime/components/button-action.d.vue.ts +18 -0
- package/dist/runtime/components/button-action.vue +57 -0
- package/dist/runtime/components/button-action.vue.d.ts +18 -0
- package/dist/runtime/components/button.d.vue.ts +1 -2
- package/dist/runtime/components/button.vue +1 -10
- package/dist/runtime/components/button.vue.d.ts +1 -2
- package/dist/runtime/components/ui/buttons/Buttons.d.vue.ts +1 -2
- package/dist/runtime/components/ui/buttons/Buttons.vue +68 -12
- package/dist/runtime/components/ui/buttons/Buttons.vue.d.ts +1 -2
- package/dist/runtime/components/ui/buttons/action-registry.d.ts +15 -0
- package/dist/runtime/components/ui/buttons/action-registry.js +1 -0
- package/dist/runtime/components/ui/buttons/button-action.types.d.ts +6 -0
- package/dist/runtime/components/ui/buttons/button-action.types.js +26 -0
- package/dist/runtime/components/ui/buttons/schema.js +2 -2
- package/dist/runtime/composables/useButtonAction.d.ts +2 -1
- package/dist/runtime/plugins/toast/index.d.ts +2 -2
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -73,6 +73,10 @@ const module$1 = defineNuxtModule({
|
|
|
73
73
|
name: "ShwfedButton",
|
|
74
74
|
filePath: resolver.resolve("runtime/components/button.vue")
|
|
75
75
|
});
|
|
76
|
+
addComponent({
|
|
77
|
+
name: "ShwfedButtonAction",
|
|
78
|
+
filePath: resolver.resolve("runtime/components/button-action.vue")
|
|
79
|
+
});
|
|
76
80
|
addComponent({
|
|
77
81
|
name: "ShwfedFields",
|
|
78
82
|
filePath: resolver.resolve("runtime/components/fields.vue")
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ButtonActionEffect, ButtonActionEffectFactory } from '../composables/useButtonAction.js';
|
|
2
|
+
import type { OverlayBodyRender } from '../composables/useOverlay.js';
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
actionId: string;
|
|
5
|
+
effect?: ButtonActionEffect | ButtonActionEffectFactory;
|
|
6
|
+
};
|
|
7
|
+
type __VLS_Slots = {
|
|
8
|
+
default?: OverlayBodyRender;
|
|
9
|
+
};
|
|
10
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
11
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
12
|
+
declare const _default: typeof __VLS_export;
|
|
13
|
+
export default _default;
|
|
14
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
15
|
+
new (): {
|
|
16
|
+
$slots: S;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { inject, onBeforeUnmount, onMounted, onUpdated } from "vue";
|
|
3
|
+
import { buttonActionRegistryKey } from "./ui/buttons/action-registry";
|
|
4
|
+
defineOptions({
|
|
5
|
+
inheritAttrs: false
|
|
6
|
+
});
|
|
7
|
+
const props = defineProps({
|
|
8
|
+
actionId: { type: String, required: true },
|
|
9
|
+
effect: { type: Function, required: false, skipCheck: true }
|
|
10
|
+
});
|
|
11
|
+
const slots = defineSlots();
|
|
12
|
+
const registry = inject(buttonActionRegistryKey, void 0);
|
|
13
|
+
const ownerId = crypto.randomUUID();
|
|
14
|
+
const isDevelopment = process.env.NODE_ENV !== "production";
|
|
15
|
+
let registeredActionId;
|
|
16
|
+
let hasWarnedMissingRegistry = false;
|
|
17
|
+
function warnMissingRegistry() {
|
|
18
|
+
if (!isDevelopment || hasWarnedMissingRegistry) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
hasWarnedMissingRegistry = true;
|
|
22
|
+
console.warn("[shwfed-button-action] must be used inside <shwfed-button>.");
|
|
23
|
+
}
|
|
24
|
+
function syncAction() {
|
|
25
|
+
if (!registry) {
|
|
26
|
+
warnMissingRegistry();
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (registeredActionId && registeredActionId !== props.actionId) {
|
|
30
|
+
registry.unregisterAction(registeredActionId, ownerId);
|
|
31
|
+
}
|
|
32
|
+
registry.registerAction({
|
|
33
|
+
ownerId,
|
|
34
|
+
actionId: props.actionId,
|
|
35
|
+
effect: props.effect,
|
|
36
|
+
render: slots.default
|
|
37
|
+
});
|
|
38
|
+
registeredActionId = props.actionId;
|
|
39
|
+
}
|
|
40
|
+
syncAction();
|
|
41
|
+
onMounted(() => {
|
|
42
|
+
syncAction();
|
|
43
|
+
});
|
|
44
|
+
onUpdated(() => {
|
|
45
|
+
syncAction();
|
|
46
|
+
});
|
|
47
|
+
onBeforeUnmount(() => {
|
|
48
|
+
if (!registry || !registeredActionId) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
registry.unregisterAction(registeredActionId, ownerId);
|
|
52
|
+
});
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<template>
|
|
56
|
+
<span v-if="false" />
|
|
57
|
+
</template>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ButtonActionEffect, ButtonActionEffectFactory } from '../composables/useButtonAction.js';
|
|
2
|
+
import type { OverlayBodyRender } from '../composables/useOverlay.js';
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
actionId: string;
|
|
5
|
+
effect?: ButtonActionEffect | ButtonActionEffectFactory;
|
|
6
|
+
};
|
|
7
|
+
type __VLS_Slots = {
|
|
8
|
+
default?: OverlayBodyRender;
|
|
9
|
+
};
|
|
10
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
11
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
12
|
+
declare const _default: typeof __VLS_export;
|
|
13
|
+
export default _default;
|
|
14
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
15
|
+
new (): {
|
|
16
|
+
$slots: S;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Effect } from 'effect';
|
|
2
|
-
import type { OverlayBodyRender } from '../composables/useOverlay.js';
|
|
3
2
|
import type { ButtonConfigInput } from './ui/buttons/schema.js';
|
|
4
3
|
export { ButtonActionC, ButtonBodyC, ButtonBodyInputC, ButtonConfigC, ButtonConfigInputC, ButtonDropdownC, ButtonGroupC, ButtonModalC, ButtonsStyleC, CURRENT_COMPATIBILITY_DATE, KIND, SUPPORTED_COMPATIBILITY_DATES, createButtonConfig, } from './ui/buttons/schema.js';
|
|
5
4
|
export type { ButtonAction, ButtonBody, ButtonBodyInput, ButtonConfig, ButtonConfigInput, ButtonDropdown, ButtonDropdownAction, ButtonGroup, ButtonGroupItem, ButtonModal, ButtonSize, ButtonVariant, } from './ui/buttons/schema.js';
|
|
@@ -158,7 +157,7 @@ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
|
|
|
158
157
|
style?: string | undefined;
|
|
159
158
|
}>) => any) | undefined;
|
|
160
159
|
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
|
|
161
|
-
|
|
160
|
+
default?: (props: {}) => any;
|
|
162
161
|
}>;
|
|
163
162
|
type __VLS_WithSlots<T, S> = T & {
|
|
164
163
|
new (): {
|
|
@@ -9,7 +9,6 @@ const props = defineProps({
|
|
|
9
9
|
config: { type: null, required: false }
|
|
10
10
|
});
|
|
11
11
|
const emit = defineEmits(["update:config"]);
|
|
12
|
-
const slots = defineSlots();
|
|
13
12
|
const defaultConfig = createButtonConfig({
|
|
14
13
|
gap: 12,
|
|
15
14
|
groups: []
|
|
@@ -53,14 +52,6 @@ export { ButtonActionService, currentButtonAction } from "../composables/useButt
|
|
|
53
52
|
:config="resolveConfig()"
|
|
54
53
|
@update:config="handleConfigUpdate"
|
|
55
54
|
>
|
|
56
|
-
<
|
|
57
|
-
v-for="(_, slotName) in slots"
|
|
58
|
-
#[slotName]="slotProps"
|
|
59
|
-
>
|
|
60
|
-
<slot
|
|
61
|
-
:name="slotName"
|
|
62
|
-
v-bind="slotProps ?? {}"
|
|
63
|
-
/>
|
|
64
|
-
</template>
|
|
55
|
+
<slot />
|
|
65
56
|
</UiButtons>
|
|
66
57
|
</template>
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Effect } from 'effect';
|
|
2
|
-
import type { OverlayBodyRender } from '../composables/useOverlay.js';
|
|
3
2
|
import type { ButtonConfigInput } from './ui/buttons/schema.js';
|
|
4
3
|
export { ButtonActionC, ButtonBodyC, ButtonBodyInputC, ButtonConfigC, ButtonConfigInputC, ButtonDropdownC, ButtonGroupC, ButtonModalC, ButtonsStyleC, CURRENT_COMPATIBILITY_DATE, KIND, SUPPORTED_COMPATIBILITY_DATES, createButtonConfig, } from './ui/buttons/schema.js';
|
|
5
4
|
export type { ButtonAction, ButtonBody, ButtonBodyInput, ButtonConfig, ButtonConfigInput, ButtonDropdown, ButtonDropdownAction, ButtonGroup, ButtonGroupItem, ButtonModal, ButtonSize, ButtonVariant, } from './ui/buttons/schema.js';
|
|
@@ -158,7 +157,7 @@ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
|
|
|
158
157
|
style?: string | undefined;
|
|
159
158
|
}>) => any) | undefined;
|
|
160
159
|
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
|
|
161
|
-
|
|
160
|
+
default?: (props: {}) => any;
|
|
162
161
|
}>;
|
|
163
162
|
type __VLS_WithSlots<T, S> = T & {
|
|
164
163
|
new (): {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Effect } from 'effect';
|
|
2
|
-
import { type OverlayBodyRender } from '../../../composables/useOverlay.js';
|
|
3
2
|
import { type ButtonConfigInput } from './schema.js';
|
|
4
3
|
export { ButtonActionC, ButtonConfigC, ButtonConfigInputC, ButtonDropdownC, ButtonGroupC, ButtonModalC, ButtonsStyleC } from './schema.js';
|
|
5
4
|
export { ButtonBodyC, ButtonBodyInputC, CURRENT_COMPATIBILITY_DATE, KIND, SUPPORTED_COMPATIBILITY_DATES, createButtonConfig, } from './schema.js';
|
|
@@ -159,7 +158,7 @@ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
|
|
|
159
158
|
style?: string | undefined;
|
|
160
159
|
}>) => any) | undefined;
|
|
161
160
|
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
|
|
162
|
-
|
|
161
|
+
default?: (props: {}) => any;
|
|
163
162
|
}>;
|
|
164
163
|
type __VLS_WithSlots<T, S> = T & {
|
|
165
164
|
new (): {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { useNuxtApp } from "#app";
|
|
3
|
-
import { useAttrs, computed, onBeforeUnmount, ref, watch } from "vue";
|
|
3
|
+
import { useAttrs, computed, onBeforeUnmount, provide, reactive, ref, watch } from "vue";
|
|
4
4
|
import { computedAsync } from "@vueuse/core";
|
|
5
5
|
import { Icon } from "@iconify/vue";
|
|
6
6
|
import { Effect } from "effect";
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
ButtonConfigC,
|
|
26
26
|
createButtonConfig
|
|
27
27
|
} from "./schema";
|
|
28
|
+
import { buttonActionRegistryKey } from "./action-registry";
|
|
28
29
|
defineOptions({
|
|
29
30
|
inheritAttrs: false
|
|
30
31
|
});
|
|
@@ -37,8 +38,10 @@ const defaultConfig = createButtonConfig({
|
|
|
37
38
|
groups: []
|
|
38
39
|
});
|
|
39
40
|
const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu;
|
|
41
|
+
const isDevelopment = process.env.NODE_ENV !== "production";
|
|
42
|
+
const duplicateActionWarnings = /* @__PURE__ */ new Set();
|
|
43
|
+
const unknownActionWarnings = /* @__PURE__ */ new Set();
|
|
40
44
|
const attrs = useAttrs();
|
|
41
|
-
const slots = defineSlots();
|
|
42
45
|
const { locale, t } = useI18n();
|
|
43
46
|
const { $dsl } = useNuxtApp();
|
|
44
47
|
const overlay = useOverlay();
|
|
@@ -46,6 +49,7 @@ const isCheating = useCheating();
|
|
|
46
49
|
const isConfiguratorOpen = ref(false);
|
|
47
50
|
const pendingIds = ref([]);
|
|
48
51
|
const overlayOwnerId = crypto.randomUUID();
|
|
52
|
+
const declaredActions = reactive({});
|
|
49
53
|
const currentConfig = computedAsync(
|
|
50
54
|
async () => ButtonConfigC.parse(await props.config.pipe(Effect.runPromise) ?? defaultConfig)
|
|
51
55
|
);
|
|
@@ -55,13 +59,69 @@ watch(currentConfig, (value) => {
|
|
|
55
59
|
displayConfig.value = value;
|
|
56
60
|
}
|
|
57
61
|
}, { immediate: true });
|
|
62
|
+
const actionIds = computed(() => displayConfig.value.groups.flatMap((group) => group.items.flatMap((item) => {
|
|
63
|
+
if (isDropdownItem(item)) {
|
|
64
|
+
return item.items.map((child) => child.id);
|
|
65
|
+
}
|
|
66
|
+
return [item.id];
|
|
67
|
+
})));
|
|
68
|
+
const actionIdSet = computed(() => new Set(actionIds.value));
|
|
69
|
+
function warnDuplicateAction(actionId) {
|
|
70
|
+
if (!isDevelopment || duplicateActionWarnings.has(actionId)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
duplicateActionWarnings.add(actionId);
|
|
74
|
+
console.warn(`[shwfed-button] duplicate action declaration for "${actionId}". The latest declaration wins.`);
|
|
75
|
+
}
|
|
76
|
+
function warnUnknownAction(actionId) {
|
|
77
|
+
if (!isDevelopment || unknownActionWarnings.has(actionId)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
unknownActionWarnings.add(actionId);
|
|
81
|
+
console.warn(`[shwfed-button] action "${actionId}" is not present in the current button config.`);
|
|
82
|
+
}
|
|
83
|
+
function registerAction(definition) {
|
|
84
|
+
const existing = declaredActions[definition.actionId];
|
|
85
|
+
if (existing && existing.ownerId !== definition.ownerId) {
|
|
86
|
+
warnDuplicateAction(definition.actionId);
|
|
87
|
+
}
|
|
88
|
+
declaredActions[definition.actionId] = definition;
|
|
89
|
+
}
|
|
90
|
+
function unregisterAction(actionId, ownerId) {
|
|
91
|
+
const existing = declaredActions[actionId];
|
|
92
|
+
if (!existing) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (ownerId !== void 0 && existing.ownerId !== ownerId) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
Reflect.deleteProperty(declaredActions, actionId);
|
|
99
|
+
}
|
|
100
|
+
provide(buttonActionRegistryKey, {
|
|
101
|
+
registerAction,
|
|
102
|
+
unregisterAction,
|
|
103
|
+
hasAction: (actionId) => actionIdSet.value.has(actionId)
|
|
104
|
+
});
|
|
105
|
+
function validateDeclaredActions() {
|
|
106
|
+
if (currentConfig.value === void 0) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
for (const actionId of Object.keys(declaredActions)) {
|
|
110
|
+
if (!actionIdSet.value.has(actionId)) {
|
|
111
|
+
warnUnknownAction(actionId);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
watch(actionIdSet, () => {
|
|
116
|
+
validateDeclaredActions();
|
|
117
|
+
}, { immediate: true });
|
|
58
118
|
const modalDefinitions = computed(() => {
|
|
59
119
|
const nextDefinitions = [];
|
|
60
120
|
for (const group of displayConfig.value.groups) {
|
|
61
121
|
for (const item of group.items) {
|
|
62
122
|
if (isDropdownItem(item)) {
|
|
63
123
|
for (const child of item.items) {
|
|
64
|
-
const render2 =
|
|
124
|
+
const render2 = declaredActions[child.id]?.render;
|
|
65
125
|
if (render2) {
|
|
66
126
|
nextDefinitions.push({
|
|
67
127
|
definitionId: child.id,
|
|
@@ -73,7 +133,7 @@ const modalDefinitions = computed(() => {
|
|
|
73
133
|
}
|
|
74
134
|
continue;
|
|
75
135
|
}
|
|
76
|
-
const render =
|
|
136
|
+
const render = declaredActions[item.id]?.render;
|
|
77
137
|
if (render) {
|
|
78
138
|
nextDefinitions.push({
|
|
79
139
|
definitionId: item.id,
|
|
@@ -92,14 +152,8 @@ watch(modalDefinitions, (definitions) => {
|
|
|
92
152
|
onBeforeUnmount(() => {
|
|
93
153
|
overlay.syncDefinitions(overlayOwnerId, []);
|
|
94
154
|
});
|
|
95
|
-
const actionIds = computed(() => displayConfig.value.groups.flatMap((group) => group.items.flatMap((item) => {
|
|
96
|
-
if ("items" in item) {
|
|
97
|
-
return item.items.map((child) => child.id);
|
|
98
|
-
}
|
|
99
|
-
return [item.id];
|
|
100
|
-
})));
|
|
101
155
|
const rootAttrs = computed(() => {
|
|
102
|
-
const ignoredKeys =
|
|
156
|
+
const ignoredKeys = actionIdSet.value;
|
|
103
157
|
const nextAttrs = {};
|
|
104
158
|
for (const [key, value] of Object.entries(attrs)) {
|
|
105
159
|
if (ignoredKeys.has(key) || key === "class" || uuidPattern.test(key)) {
|
|
@@ -155,7 +209,7 @@ function getModalShell(modal) {
|
|
|
155
209
|
};
|
|
156
210
|
}
|
|
157
211
|
function getButtonEffect(buttonId) {
|
|
158
|
-
return
|
|
212
|
+
return declaredActions[buttonId]?.effect;
|
|
159
213
|
}
|
|
160
214
|
function isEffectValue(value) {
|
|
161
215
|
return typeof value === "object" && value !== null && "_op" in value;
|
|
@@ -456,6 +510,8 @@ export { ButtonActionService, currentButtonAction } from "../../../composables/u
|
|
|
456
510
|
</DropdownMenu>
|
|
457
511
|
</template>
|
|
458
512
|
</ButtonGroup>
|
|
513
|
+
|
|
514
|
+
<slot />
|
|
459
515
|
</div>
|
|
460
516
|
</template>
|
|
461
517
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Effect } from 'effect';
|
|
2
|
-
import { type OverlayBodyRender } from '../../../composables/useOverlay.js';
|
|
3
2
|
import { type ButtonConfigInput } from './schema.js';
|
|
4
3
|
export { ButtonActionC, ButtonConfigC, ButtonConfigInputC, ButtonDropdownC, ButtonGroupC, ButtonModalC, ButtonsStyleC } from './schema.js';
|
|
5
4
|
export { ButtonBodyC, ButtonBodyInputC, CURRENT_COMPATIBILITY_DATE, KIND, SUPPORTED_COMPATIBILITY_DATES, createButtonConfig, } from './schema.js';
|
|
@@ -159,7 +158,7 @@ declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
|
|
|
159
158
|
style?: string | undefined;
|
|
160
159
|
}>) => any) | undefined;
|
|
161
160
|
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>, {
|
|
162
|
-
|
|
161
|
+
default?: (props: {}) => any;
|
|
163
162
|
}>;
|
|
164
163
|
type __VLS_WithSlots<T, S> = T & {
|
|
165
164
|
new (): {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { InjectionKey } from 'vue';
|
|
2
|
+
import type { ButtonActionEffect, ButtonActionEffectFactory } from '../../../composables/useButtonAction.js';
|
|
3
|
+
import type { OverlayBodyRender } from '../../../composables/useOverlay.js';
|
|
4
|
+
export type DeclaredButtonAction = Readonly<{
|
|
5
|
+
ownerId: string;
|
|
6
|
+
actionId: string;
|
|
7
|
+
effect?: ButtonActionEffect | ButtonActionEffectFactory;
|
|
8
|
+
render?: OverlayBodyRender;
|
|
9
|
+
}>;
|
|
10
|
+
export interface ButtonActionRegistry {
|
|
11
|
+
registerAction: (definition: DeclaredButtonAction) => void;
|
|
12
|
+
unregisterAction: (actionId: string, ownerId?: string) => void;
|
|
13
|
+
hasAction: (actionId: string) => boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare const buttonActionRegistryKey: InjectionKey<ButtonActionRegistry>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const buttonActionRegistryKey = Symbol("shwfed/button-action-registry");
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type ButtonActionEffect, type ButtonActionEffectFactory } from '../../../composables/useButtonAction.js';
|
|
2
|
+
export declare const overlayFactoryEffect: ButtonActionEffectFactory;
|
|
3
|
+
export declare const submitFactoryEffect: ButtonActionEffectFactory;
|
|
4
|
+
export declare const promiseEffect: ButtonActionEffect;
|
|
5
|
+
export declare const syncEffect: ButtonActionEffect;
|
|
6
|
+
export declare const overlayContextEffect: ButtonActionEffectFactory;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Effect, Option } from "effect";
|
|
2
|
+
import { openOverlay } from "../../../composables/useOverlay.js";
|
|
3
|
+
import { currentButtonAction } from "../../../composables/useButtonAction.js";
|
|
4
|
+
export const overlayFactoryEffect = ({ id }) => Effect.gen(function* () {
|
|
5
|
+
const handle = yield* openOverlay(id);
|
|
6
|
+
return handle;
|
|
7
|
+
});
|
|
8
|
+
export const submitFactoryEffect = ({ title }) => Effect.gen(function* () {
|
|
9
|
+
if (title.length === 0) {
|
|
10
|
+
return yield* Effect.fail(new Error("missing title"));
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
submitted: true,
|
|
14
|
+
title
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
export const promiseEffect = Effect.promise(async () => ({
|
|
18
|
+
status: "ok"
|
|
19
|
+
}));
|
|
20
|
+
export const syncEffect = Effect.sync(() => 1);
|
|
21
|
+
export const overlayContextEffect = () => Effect.gen(function* () {
|
|
22
|
+
const action = yield* currentButtonAction();
|
|
23
|
+
const handle = yield* openOverlay(action.id);
|
|
24
|
+
const result = yield* handle.result;
|
|
25
|
+
return Option.isSome(result);
|
|
26
|
+
});
|
|
@@ -24,7 +24,7 @@ export const ButtonActionC = z.strictObject({
|
|
|
24
24
|
variant: buttonVariantC,
|
|
25
25
|
size: buttonSizeC,
|
|
26
26
|
hideTitle: z.boolean().optional().describe("\u4EC5\u5BF9\u975E\u4E0B\u62C9\u6309\u94AE\u751F\u6548\uFF1B\u4E3A true \u65F6\u9690\u85CF\u6309\u94AE\u6587\u5B57\uFF0C\u4EC5\u663E\u793A\u56FE\u6807"),
|
|
27
|
-
modal: ButtonModalC.optional().describe("\
|
|
27
|
+
modal: ButtonModalC.optional().describe("\u4F9B\u5F53\u524D action \u7684 overlay \u58F0\u660E\u4F7F\u7528\u7684\u9ED8\u8BA4 Modal \u58F3\u914D\u7F6E")
|
|
28
28
|
}).readonly();
|
|
29
29
|
const DropdownButtonActionC = z.strictObject({
|
|
30
30
|
id: buttonIdC,
|
|
@@ -32,7 +32,7 @@ const DropdownButtonActionC = z.strictObject({
|
|
|
32
32
|
tooltip: localeC.optional().describe("\u4E0B\u62C9\u9879\u6309\u94AE\u63D0\u793A\u7684\u672C\u5730\u5316\u663E\u793A\u6587\u672C"),
|
|
33
33
|
icon: z.string().optional().describe("Iconify \u56FE\u6807\u6807\u8BC6\u7B26"),
|
|
34
34
|
variant: buttonVariantC,
|
|
35
|
-
modal: ButtonModalC.optional().describe("\
|
|
35
|
+
modal: ButtonModalC.optional().describe("\u4F9B\u5F53\u524D action \u7684 overlay \u58F0\u660E\u4F7F\u7528\u7684\u9ED8\u8BA4 Modal \u58F3\u914D\u7F6E")
|
|
36
36
|
}).readonly();
|
|
37
37
|
export const ButtonDropdownC = z.strictObject({
|
|
38
38
|
id: buttonIdC,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Context, Effect, type Scope } from 'effect';
|
|
2
|
+
import type { OverlayService } from './useOverlay.js';
|
|
2
3
|
export type ButtonActionRuntime = Readonly<{
|
|
3
4
|
id: string;
|
|
4
5
|
locale: string;
|
|
@@ -15,7 +16,7 @@ declare const ButtonActionService_base: Context.TagClass<ButtonActionService, "s
|
|
|
15
16
|
}>>;
|
|
16
17
|
export declare class ButtonActionService extends ButtonActionService_base {
|
|
17
18
|
}
|
|
18
|
-
export type ButtonActionEffect = Effect.Effect<
|
|
19
|
+
export type ButtonActionEffect = Effect.Effect<unknown, unknown, ButtonActionService | OverlayService | Scope.Scope> | Effect.Effect<unknown, unknown, ButtonActionService | OverlayService> | Effect.Effect<unknown, unknown, ButtonActionService | Scope.Scope> | Effect.Effect<unknown, unknown, OverlayService | Scope.Scope> | Effect.Effect<unknown, unknown, ButtonActionService> | Effect.Effect<unknown, unknown, OverlayService> | Effect.Effect<unknown, unknown, Scope.Scope> | Effect.Effect<unknown, unknown, never>;
|
|
19
20
|
export type ButtonActionEffectFactory = (context: ButtonActionRuntime) => ButtonActionEffect;
|
|
20
21
|
export declare function currentButtonAction(): Effect.Effect<ButtonActionRuntime, never, ButtonActionService>;
|
|
21
22
|
export {};
|
|
@@ -7,9 +7,9 @@ declare const _default: import("#app").Plugin<{
|
|
|
7
7
|
custom: (component: import("vue").Component, data?: import("vue-sonner").ExternalToast) => string | number;
|
|
8
8
|
message: (message: string | (() => string | import("vue").Component) | import("vue").Component, data?: import("vue-sonner").ExternalToast) => string | number;
|
|
9
9
|
promise: <ToastData>(promise: Promise<ToastData> | (() => Promise<ToastData>), data?: ({
|
|
10
|
+
dismissible?: boolean | undefined;
|
|
10
11
|
id?: number | string | undefined;
|
|
11
12
|
icon?: import("vue").Component | undefined;
|
|
12
|
-
dismissible?: boolean | undefined;
|
|
13
13
|
duration?: number | undefined;
|
|
14
14
|
class?: string | undefined;
|
|
15
15
|
style?: import("vue").CSSProperties | undefined;
|
|
@@ -60,9 +60,9 @@ declare const _default: import("#app").Plugin<{
|
|
|
60
60
|
custom: (component: import("vue").Component, data?: import("vue-sonner").ExternalToast) => string | number;
|
|
61
61
|
message: (message: string | (() => string | import("vue").Component) | import("vue").Component, data?: import("vue-sonner").ExternalToast) => string | number;
|
|
62
62
|
promise: <ToastData>(promise: Promise<ToastData> | (() => Promise<ToastData>), data?: ({
|
|
63
|
+
dismissible?: boolean | undefined;
|
|
63
64
|
id?: number | string | undefined;
|
|
64
65
|
icon?: import("vue").Component | undefined;
|
|
65
|
-
dismissible?: boolean | undefined;
|
|
66
66
|
duration?: number | undefined;
|
|
67
67
|
class?: string | undefined;
|
|
68
68
|
style?: import("vue").CSSProperties | undefined;
|