@novely/core 0.44.3 → 0.45.0

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/index.js CHANGED
@@ -1201,6 +1201,7 @@ var novely = ({
1201
1201
  flatActions(choice.children),
1202
1202
  choice.active,
1203
1203
  choice.visible,
1204
+ choice.onSelect,
1204
1205
  choice.image
1205
1206
  ];
1206
1207
  }
@@ -1735,20 +1736,29 @@ var novely = ({
1735
1736
  choices.unshift(question);
1736
1737
  question = "";
1737
1738
  }
1738
- const transformedChoices = choices.map(([content, action2, active, visible, image]) => {
1739
- const activeValue = !active || active({
1740
- lang: getLanguageFromStore(storageData),
1741
- state: getStateAtCtx(ctx)
1742
- });
1743
- const visibleValue = !visible || visible({
1744
- lang: getLanguageFromStore(storageData),
1745
- state: getStateAtCtx(ctx)
1746
- });
1739
+ const transformedChoices = choices.map(([content, _children, active, visible, onSelect, image]) => {
1740
+ const active$ = store(false);
1741
+ const visible$ = store(false);
1742
+ const update = () => {
1743
+ const activeValue = !active || active({
1744
+ lang: getLanguageFromStore(storageData),
1745
+ state: getStateAtCtx(ctx)
1746
+ });
1747
+ const visibleValue = !visible || visible({
1748
+ lang: getLanguageFromStore(storageData),
1749
+ state: getStateAtCtx(ctx)
1750
+ });
1751
+ active$.set(activeValue);
1752
+ visible$.set(visibleValue);
1753
+ };
1754
+ update();
1755
+ const onSelectGuarded = onSelect || noop;
1756
+ const onSelectWrapped = async () => {
1757
+ await onSelectGuarded();
1758
+ update();
1759
+ };
1747
1760
  const imageValue = image ? handleImageAsset(image) : "";
1748
- if (DEV3 && action2.length === 0 && (!activeValue && !visibleValue)) {
1749
- console.warn(`Choice children should not be empty, either add content there or make item not selectable`);
1750
- }
1751
- return [templateReplace(content, data2), activeValue, visibleValue, imageValue];
1761
+ return [templateReplace(content, data2), active$, visible$, onSelectWrapped, imageValue];
1752
1762
  });
1753
1763
  if (DEV3 && transformedChoices.length === 0) {
1754
1764
  throw new Error(`Running choice without variants to choose from, look at how to use Choice action properly [https://novely.pages.dev/guide/actions/choice#usage]`);