@datawheel/bespoke 0.5.4 → 0.5.5

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.
Files changed (2) hide show
  1. package/dist/index.js +71 -52
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -4984,9 +4984,9 @@ function Stat({
4984
4984
  }
4985
4985
  ),
4986
4986
  /* @__PURE__ */ jsxs(Stack, { spacing: 0, children: [
4987
- /* @__PURE__ */ jsx(RichText, { component: "div", size: "md", html: title, style: settings }),
4988
- /* @__PURE__ */ jsx(RichText, { component: "div", size: "xl", html: value, style: settings }),
4989
- /* @__PURE__ */ jsx(RichText, { component: "div", size: "sm", html: subtitle, style: settings })
4987
+ title && /* @__PURE__ */ jsx(RichText, { component: "div", size: "md", html: title, style: settings }),
4988
+ value && /* @__PURE__ */ jsx(RichText, { component: "div", size: "xl", html: value, style: settings }),
4989
+ subtitle && /* @__PURE__ */ jsx(RichText, { component: "div", size: "sm", html: subtitle, style: settings })
4990
4990
  ] }, "stat"),
4991
4991
  tooltip && /* @__PURE__ */ jsx(InnerTooltip, { content: tooltip })
4992
4992
  ] });
@@ -12666,6 +12666,63 @@ var init_UnlocalizedFieldLabel = __esm({
12666
12666
  UnlocalizedFieldLabel_default = UnlocalizedFieldLabel;
12667
12667
  }
12668
12668
  });
12669
+
12670
+ // components/blocks/types/selector.ts
12671
+ var SELECTOR_TYPE, SELECTOR_COMPONENT, OPTION_TYPE, isValidSelectorOptionsArray, isPrimitiveTypeVariable, isValidSelectorState, deriveLogicOptions;
12672
+ var init_selector = __esm({
12673
+ "components/blocks/types/selector.ts"() {
12674
+ init_esm_shims();
12675
+ SELECTOR_TYPE = {
12676
+ SINGLE: "single",
12677
+ MULTI: "multi"
12678
+ };
12679
+ SELECTOR_COMPONENT = {
12680
+ SEGMENTED_CONTROL: "segmented control",
12681
+ SELECTOR: "selector"
12682
+ };
12683
+ OPTION_TYPE = {
12684
+ STATIC: "static",
12685
+ DYNAMIC: "dynamic"
12686
+ };
12687
+ isValidSelectorOptionsArray = (variable) => variable && Array.isArray(variable) && variable.length > 0;
12688
+ isPrimitiveTypeVariable = (variable) => isValidSelectorOptionsArray(variable) && ["string"].includes(typeof variable[0]);
12689
+ isValidSelectorState = (simpleState) => {
12690
+ const {
12691
+ name,
12692
+ type,
12693
+ optionsType,
12694
+ options
12695
+ } = simpleState;
12696
+ if (![name, type, optionsType, options].every(Boolean))
12697
+ return false;
12698
+ if (optionsType === OPTION_TYPE.STATIC)
12699
+ return options.static?.length > 0 && options.static?.every((o2) => o2.id);
12700
+ if (!options.dynamic?.isPrimitiveType)
12701
+ return !!options.dynamic?.idKey;
12702
+ return true;
12703
+ };
12704
+ deriveLogicOptions = (selectorType, options, optionsType) => {
12705
+ let defaultValue;
12706
+ let logicOptions;
12707
+ if (optionsType === OPTION_TYPE.STATIC) {
12708
+ defaultValue = selectorType === SELECTOR_TYPE.SINGLE ? options.static.find((o2) => o2.isDefault)?.id : options.static.filter((o2) => o2.isDefault).map((o2) => o2.id);
12709
+ logicOptions = options.static.map(({ id, label }) => ({ id, label: label || id }));
12710
+ } else {
12711
+ const {
12712
+ optionsVar,
12713
+ idKey,
12714
+ labelKey,
12715
+ defaultVar,
12716
+ isPrimitiveType
12717
+ } = options.dynamic;
12718
+ if (defaultVar)
12719
+ defaultValue = `variables["${defaultVar}"]`;
12720
+ logicOptions = isPrimitiveType ? `variables["${optionsVar}"]` : `(variables["${optionsVar}"] || []).map(d => ({id: String(d["${idKey}"]), label: String(d["${labelKey || idKey}"])}))`;
12721
+ }
12722
+ return { logicOptions, defaultValue };
12723
+ };
12724
+ }
12725
+ });
12669
12726
  function StaticSelectorOptionRow({ option, editOption, deleteOption }) {
12670
12727
  return /* @__PURE__ */ jsxs("tr", { className: "reports-selector-static-option", children: [
12671
12728
  /* @__PURE__ */ jsx("td", { children: /* @__PURE__ */ jsx(
@@ -12904,23 +12961,7 @@ function SelectorUI(props) {
12904
12961
  component: selectorComponent,
12905
12962
  type: selectorType
12906
12963
  };
12907
- let defaultValue;
12908
- let logicOptions;
12909
- if (optionsType === OPTION_TYPE.STATIC) {
12910
- defaultValue = selectorType === SELECTOR_TYPE.SINGLE ? options.static.find((o2) => o2.isDefault)?.id : options.static.filter((o2) => o2.isDefault).map((o2) => o2.id);
12911
- logicOptions = options.static.map(({ id: id2, label }) => ({ id: id2, label: label || id2 }));
12912
- } else {
12913
- const {
12914
- optionsVar,
12915
- idKey,
12916
- labelKey,
12917
- defaultVar,
12918
- isPrimitiveType
12919
- } = options.dynamic;
12920
- if (defaultVar)
12921
- defaultValue = `variables["${defaultVar}"]`;
12922
- logicOptions = isPrimitiveType ? `variables["${optionsVar}"]` : `(variables["${optionsVar}"] || []).map(d => ({id: String(d["${idKey}"]), label: String(d["${labelKey || idKey}"])}))`;
12923
- }
12964
+ const { logicOptions, defaultValue } = deriveLogicOptions(selectorType, options, optionsType);
12924
12965
  if (defaultValue)
12925
12966
  logicObj.defaultValue = defaultValue;
12926
12967
  logicObj.options = logicOptions;
@@ -13009,7 +13050,7 @@ function SelectorUI(props) {
13009
13050
  executeButton
13010
13051
  ] });
13011
13052
  }
13012
- var SELECTOR_TYPE, SELECTOR_COMPONENT, OPTION_TYPE, isValidSelectorOptionsArray, isPrimitiveTypeVariable, isValidSelectorState, SelectorUI_default;
13053
+ var SelectorUI_default;
13013
13054
  var init_SelectorUI = __esm({
13014
13055
  "components/blocks/types/simpleEditors/SelectorUI.tsx"() {
13015
13056
  init_esm_shims();
@@ -13019,35 +13060,7 @@ var init_SelectorUI = __esm({
13019
13060
  init_RichTextEditor();
13020
13061
  init_UnlocalizedFieldLabel();
13021
13062
  init_cms();
13022
- SELECTOR_TYPE = {
13023
- SINGLE: "single",
13024
- MULTI: "multi"
13025
- };
13026
- SELECTOR_COMPONENT = {
13027
- SEGMENTED_CONTROL: "segmented control",
13028
- SELECTOR: "selector"
13029
- };
13030
- OPTION_TYPE = {
13031
- STATIC: "static",
13032
- DYNAMIC: "dynamic"
13033
- };
13034
- isValidSelectorOptionsArray = (variable) => variable && Array.isArray(variable) && variable.length > 0;
13035
- isPrimitiveTypeVariable = (variable) => isValidSelectorOptionsArray(variable) && ["string"].includes(typeof variable[0]);
13036
- isValidSelectorState = (simpleState) => {
13037
- const {
13038
- name,
13039
- type,
13040
- optionsType,
13041
- options
13042
- } = simpleState;
13043
- if (![name, type, optionsType, options].every(Boolean))
13044
- return false;
13045
- if (optionsType === OPTION_TYPE.STATIC)
13046
- return options.static?.length > 0 && options.static?.every((o2) => o2.id);
13047
- if (!options.dynamic?.isPrimitiveType)
13048
- return !!options.dynamic?.idKey;
13049
- return true;
13050
- };
13063
+ init_selector();
13051
13064
  SelectorUI_default = SelectorUI;
13052
13065
  }
13053
13066
  });
@@ -21019,6 +21032,7 @@ var scaffoldEmptyBlock = (block) => {
21019
21032
  // components/blocks/Block.tsx
21020
21033
  init_stringifyObject();
21021
21034
  init_BlockEditorProvider();
21035
+ init_selector();
21022
21036
  var UNLOCALIZED_ICON_KEYS = [
21023
21037
  "_iconVariant",
21024
21038
  "_iconSize",
@@ -21144,7 +21158,11 @@ function Block2({ id, modified, callbacks, inline }) {
21144
21158
  });
21145
21159
  const logicObj = { ...newSimple };
21146
21160
  if (block.type === BLOCK_TYPES.SELECTOR) {
21147
- logicObj.options = logicObj.options[logicObj.optionsType];
21161
+ const { selectorType, options, optionsType } = contentByLocale[currentLocale2].content.simple;
21162
+ const { logicOptions, defaultValue } = deriveLogicOptions(selectorType, options, optionsType);
21163
+ if (defaultValue)
21164
+ logicObj.defaultValue = defaultValue;
21165
+ logicObj.options = logicOptions;
21148
21166
  }
21149
21167
  newContentByLocale[locale].content = {
21150
21168
  ...newContentByLocale[locale].content,
@@ -21160,10 +21178,11 @@ function Block2({ id, modified, callbacks, inline }) {
21160
21178
  const { settings } = blockState;
21161
21179
  const contentByLocale = Object.values(blockState.contentByLocale).reduce(reduceContent, {});
21162
21180
  const properties = ["id", "api", "shared", "type"].reduce((acc, d2) => ({ ...acc, [d2]: blockState[d2] }), {});
21181
+ const newContent = spreadUnlocalizedContent(contentByLocale, currentLocale);
21163
21182
  return {
21164
21183
  ...properties,
21165
21184
  id: blockState.id,
21166
- contentByLocale: spreadUnlocalizedContent(contentByLocale, currentLocale),
21185
+ contentByLocale: newContent,
21167
21186
  settings
21168
21187
  };
21169
21188
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datawheel/bespoke",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
4
4
  "description": "Content management system for creating automated data reports",
5
5
  "exports": {
6
6
  ".": {
@@ -141,4 +141,4 @@
141
141
  "peerDependencies": {
142
142
  "next": "^14.2.3"
143
143
  }
144
- }
144
+ }