@shwfed/nuxt 0.11.0 → 0.11.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.
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shwfed/nuxt",
3
3
  "configKey": "shwfed",
4
- "version": "0.11.0",
4
+ "version": "0.11.1",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -2,6 +2,8 @@ import { Effect } from 'effect';
2
2
  import type { ButtonConfigInput } from './ui/buttons/schema.js';
3
3
  export { ButtonActionC, ButtonBodyC, ButtonBodyInputC, ButtonConfigC, ButtonConfigInputC, ButtonDropdownC, ButtonGroupC, ButtonModalC, ButtonsStyleC, CURRENT_COMPATIBILITY_DATE, KIND, SUPPORTED_COMPATIBILITY_DATES, createButtonConfig, } from './ui/buttons/schema.js';
4
4
  export type { ButtonAction, ButtonBody, ButtonBodyInput, ButtonConfig, ButtonConfigInput, ButtonDropdown, ButtonDropdownAction, ButtonGroup, ButtonGroupItem, ButtonModal, } from './ui/buttons/schema.js';
5
+ export type { ButtonActionEffect, ButtonActionEffectFactory, ButtonActionRuntime } from '../composables/useButtonAction.js';
6
+ export { ButtonActionService, currentButtonAction } from '../composables/useButtonAction.js';
5
7
  declare const _default: typeof __VLS_export;
6
8
  export default _default;
7
9
  declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
@@ -43,6 +43,7 @@ export {
43
43
  SUPPORTED_COMPATIBILITY_DATES,
44
44
  createButtonConfig
45
45
  } from "./ui/buttons/schema";
46
+ export { ButtonActionService, currentButtonAction } from "../composables/useButtonAction";
46
47
  </script>
47
48
 
48
49
  <template>
@@ -2,6 +2,8 @@ import { Effect } from 'effect';
2
2
  import type { ButtonConfigInput } from './ui/buttons/schema.js';
3
3
  export { ButtonActionC, ButtonBodyC, ButtonBodyInputC, ButtonConfigC, ButtonConfigInputC, ButtonDropdownC, ButtonGroupC, ButtonModalC, ButtonsStyleC, CURRENT_COMPATIBILITY_DATE, KIND, SUPPORTED_COMPATIBILITY_DATES, createButtonConfig, } from './ui/buttons/schema.js';
4
4
  export type { ButtonAction, ButtonBody, ButtonBodyInput, ButtonConfig, ButtonConfigInput, ButtonDropdown, ButtonDropdownAction, ButtonGroup, ButtonGroupItem, ButtonModal, } from './ui/buttons/schema.js';
5
+ export type { ButtonActionEffect, ButtonActionEffectFactory, ButtonActionRuntime } from '../composables/useButtonAction.js';
6
+ export { ButtonActionService, currentButtonAction } from '../composables/useButtonAction.js';
5
7
  declare const _default: typeof __VLS_export;
6
8
  export default _default;
7
9
  declare const __VLS_export: __VLS_WithSlots<import("vue").DefineComponent<{
@@ -2,7 +2,9 @@ import { Effect } from 'effect';
2
2
  import { type ButtonConfigInput } from './schema.js';
3
3
  export { ButtonActionC, ButtonConfigC, ButtonConfigInputC, ButtonDropdownC, ButtonGroupC, ButtonModalC, ButtonsStyleC } from './schema.js';
4
4
  export { ButtonBodyC, ButtonBodyInputC, CURRENT_COMPATIBILITY_DATE, KIND, SUPPORTED_COMPATIBILITY_DATES, createButtonConfig, } from './schema.js';
5
+ export { ButtonActionService, currentButtonAction } from '../../../composables/useButtonAction.js';
5
6
  export type { ButtonAction, ButtonBody, ButtonBodyInput, ButtonConfig, ButtonConfigInput, ButtonDropdown, ButtonDropdownAction, ButtonGroup, ButtonGroupItem, ButtonModal, } from './schema.js';
7
+ export type { ButtonActionEffect, ButtonActionEffectFactory, ButtonActionRuntime } from '../../../composables/useButtonAction.js';
6
8
  declare const _default: typeof __VLS_export;
7
9
  export default _default;
8
10
  declare const __VLS_export: import("vue").DefineComponent<{
@@ -6,6 +6,9 @@ import { Icon } from "@iconify/vue";
6
6
  import { Effect } from "effect";
7
7
  import { useI18n } from "vue-i18n";
8
8
  import { useCheating } from "#imports";
9
+ import {
10
+ ButtonActionService
11
+ } from "../../../composables/useButtonAction";
9
12
  import { provideOverlay, useOverlay } from "../../../composables/useOverlay";
10
13
  import { getLocalizedText, hasVisibleLocaleValue } from "../../../utils/coders";
11
14
  import { cn } from "../../../utils/cn";
@@ -154,11 +157,14 @@ function getButtonEffect(buttonId) {
154
157
  function isEffectValue(value) {
155
158
  return typeof value === "object" && value !== null && "_op" in value;
156
159
  }
160
+ function isEffectFactory(value) {
161
+ return typeof value === "function";
162
+ }
157
163
  function isPending(buttonId) {
158
164
  return pendingIds.value.includes(buttonId);
159
165
  }
160
166
  function isButtonDisabled(buttonId) {
161
- return isPending(buttonId) || !isEffectValue(getButtonEffect(buttonId));
167
+ return isPending(buttonId) || !(isEffectValue(getButtonEffect(buttonId)) || isEffectFactory(getButtonEffect(buttonId)));
162
168
  }
163
169
  function isDropdownPending(dropdown) {
164
170
  return dropdown.items.some((item) => isPending(item.id));
@@ -166,17 +172,65 @@ function isDropdownPending(dropdown) {
166
172
  function hasButtonTooltip(button) {
167
173
  return hasVisibleLocaleValue(button.tooltip);
168
174
  }
175
+ function findButtonAction(buttonId) {
176
+ for (const group of displayConfig.value.groups) {
177
+ for (const item of group.items) {
178
+ if (isDropdownItem(item)) {
179
+ const child = item.items.find((candidate) => candidate.id === buttonId);
180
+ if (child) {
181
+ return child;
182
+ }
183
+ continue;
184
+ }
185
+ if (item.id === buttonId) {
186
+ return item;
187
+ }
188
+ }
189
+ }
190
+ return void 0;
191
+ }
192
+ function createButtonActionRuntime(button) {
193
+ const tooltip = getButtonTooltip(button);
194
+ return {
195
+ id: button.id,
196
+ locale: locale.value,
197
+ title: getButtonLabel(button),
198
+ description: tooltip,
199
+ tooltip
200
+ };
201
+ }
202
+ function resolveButtonEffect(button) {
203
+ const value = getButtonEffect(button.id);
204
+ if (isEffectValue(value)) {
205
+ return value;
206
+ }
207
+ if (!isEffectFactory(value)) {
208
+ return void 0;
209
+ }
210
+ const effect = value(createButtonActionRuntime(button));
211
+ return isEffectValue(effect) ? effect : void 0;
212
+ }
169
213
  async function runButton(buttonId) {
170
214
  if (isPending(buttonId)) {
171
215
  return;
172
216
  }
173
- const effect = getButtonEffect(buttonId);
174
- if (!isEffectValue(effect)) {
217
+ const button = findButtonAction(buttonId);
218
+ if (!button) {
219
+ return;
220
+ }
221
+ const effect = resolveButtonEffect(button);
222
+ if (!effect) {
175
223
  return;
176
224
  }
225
+ const action = createButtonActionRuntime(button);
177
226
  pendingIds.value = [...pendingIds.value, buttonId];
178
227
  try {
179
- await Effect.runPromise(provideOverlay(Effect.scoped(effect), overlay));
228
+ await Effect.runPromise(
229
+ provideOverlay(
230
+ Effect.scoped(effect).pipe(Effect.provideService(ButtonActionService, action)),
231
+ overlay
232
+ )
233
+ );
180
234
  } finally {
181
235
  pendingIds.value = pendingIds.value.filter((id) => id !== buttonId);
182
236
  }
@@ -211,6 +265,7 @@ export {
211
265
  SUPPORTED_COMPATIBILITY_DATES,
212
266
  createButtonConfig
213
267
  } from "./schema";
268
+ export { ButtonActionService, currentButtonAction } from "../../../composables/useButtonAction";
214
269
  </script>
215
270
 
216
271
  <template>
@@ -2,7 +2,9 @@ import { Effect } from 'effect';
2
2
  import { type ButtonConfigInput } from './schema.js';
3
3
  export { ButtonActionC, ButtonConfigC, ButtonConfigInputC, ButtonDropdownC, ButtonGroupC, ButtonModalC, ButtonsStyleC } from './schema.js';
4
4
  export { ButtonBodyC, ButtonBodyInputC, CURRENT_COMPATIBILITY_DATE, KIND, SUPPORTED_COMPATIBILITY_DATES, createButtonConfig, } from './schema.js';
5
+ export { ButtonActionService, currentButtonAction } from '../../../composables/useButtonAction.js';
5
6
  export type { ButtonAction, ButtonBody, ButtonBodyInput, ButtonConfig, ButtonConfigInput, ButtonDropdown, ButtonDropdownAction, ButtonGroup, ButtonGroupItem, ButtonModal, } from './schema.js';
7
+ export type { ButtonActionEffect, ButtonActionEffectFactory, ButtonActionRuntime } from '../../../composables/useButtonAction.js';
6
8
  declare const _default: typeof __VLS_export;
7
9
  export default _default;
8
10
  declare const __VLS_export: import("vue").DefineComponent<{
@@ -0,0 +1,21 @@
1
+ import { Context, Effect, type Scope } from 'effect';
2
+ export type ButtonActionRuntime = Readonly<{
3
+ id: string;
4
+ locale: string;
5
+ title: string;
6
+ description?: string;
7
+ tooltip?: string;
8
+ }>;
9
+ declare const ButtonActionService_base: Context.TagClass<ButtonActionService, "shwfed/ButtonActionService", Readonly<{
10
+ id: string;
11
+ locale: string;
12
+ title: string;
13
+ description?: string;
14
+ tooltip?: string;
15
+ }>>;
16
+ export declare class ButtonActionService extends ButtonActionService_base {
17
+ }
18
+ export type ButtonActionEffect = Effect.Effect<void, never, ButtonActionService | Scope.Scope> | Effect.Effect<void, never, ButtonActionService> | Effect.Effect<void, never, Scope.Scope> | Effect.Effect<void, never, never>;
19
+ export type ButtonActionEffectFactory = (context: ButtonActionRuntime) => ButtonActionEffect;
20
+ export declare function currentButtonAction(): Effect.Effect<ButtonActionRuntime, never, ButtonActionService>;
21
+ export {};
@@ -0,0 +1,6 @@
1
+ import { Context, Effect } from "effect";
2
+ export class ButtonActionService extends Context.Tag("shwfed/ButtonActionService")() {
3
+ }
4
+ export function currentButtonAction() {
5
+ return Effect.flatMap(ButtonActionService, (action) => Effect.succeed(action));
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shwfed/nuxt",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "type": "module",