@novely/core 0.44.3 → 0.45.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/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,32 @@ 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 lang = getLanguageFromStore(storageData);
1744
+ const state = getStateAtCtx(ctx);
1745
+ const activeValue = !active || active({
1746
+ lang,
1747
+ state
1748
+ });
1749
+ const visibleValue = !visible || visible({
1750
+ lang,
1751
+ state
1752
+ });
1753
+ active$.set(activeValue);
1754
+ visible$.set(visibleValue);
1755
+ };
1756
+ update();
1757
+ const onSelectGuarded = onSelect || noop;
1758
+ const onSelectWrapped = () => {
1759
+ onSelectGuarded({
1760
+ recompute: update
1761
+ });
1762
+ };
1747
1763
  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];
1764
+ return [templateReplace(content, data2), active$, visible$, onSelectWrapped, imageValue];
1752
1765
  });
1753
1766
  if (DEV3 && transformedChoices.length === 0) {
1754
1767
  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]`);