@novely/core 0.44.2 → 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
@@ -292,16 +292,16 @@ var noop = () => {
292
292
  var isAction = (element) => {
293
293
  return Array.isArray(element) && isString(element[0]);
294
294
  };
295
+ var flatActions = (item) => {
296
+ return item.flatMap((data) => {
297
+ const type = data[0];
298
+ if (Array.isArray(type)) return flatActions(data);
299
+ return [data];
300
+ });
301
+ };
295
302
  var flattenStory = (story) => {
296
303
  const entries = Object.entries(story).map(([name, items]) => {
297
- const flat = (item) => {
298
- return item.flatMap((data) => {
299
- const type = data[0];
300
- if (Array.isArray(type)) return flat(data);
301
- return [data];
302
- });
303
- };
304
- return [name, flat(items)];
304
+ return [name, flatActions(items)];
305
305
  });
306
306
  return Object.fromEntries(entries);
307
307
  };
@@ -1198,9 +1198,10 @@ var novely = ({
1198
1198
  const choice = props[i];
1199
1199
  props[i] = [
1200
1200
  choice.title,
1201
- choice.children,
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]`);