@datawheel/bespoke 0.5.0 → 0.5.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
@@ -1,5 +1,5 @@
1
- import { Group, Stack, Text, useMantineTheme, List, Modal, Button, Input, MantineProvider, Box, Navbar, ScrollArea, Avatar, AppShell, UnstyledButton, ThemeIcon, LoadingOverlay, Skeleton, Flex, packSx, Menu, Card, Center, Space, Badge, Title, Tabs, TextInput, Code, Loader, Divider, SegmentedControl, Select, ActionIcon, Textarea, Paper, Alert, Container, Grid, Tooltip, createStyles, MultiSelect, Anchor, Checkbox, MediaQuery, Affix, rem, Popover, Radio, Switch, Drawer, Overlay, NumberInput, Autocomplete, Notification, Image, Header, px, Accordion, FileInput, SimpleGrid, Burger, Collapse, HoverCard, CopyButton, Breadcrumbs, Col } from '@mantine/core';
2
- import React, { forwardRef, useState, useCallback, useRef, useEffect, createContext, useContext, useMemo, Fragment as Fragment$1, memo, useImperativeHandle } from 'react';
1
+ import { Group, Stack, Text, useMantineTheme, List, Modal, Button, Input, MantineProvider, Box, Navbar, ScrollArea, Avatar, AppShell, UnstyledButton, ThemeIcon, LoadingOverlay, Skeleton, Flex, packSx, Menu, Card, Center, Space, Badge, Title, Tabs, TextInput, Code, Loader, Divider, SegmentedControl, Select, ActionIcon, Textarea, Paper, Alert, Container, Grid, Tooltip, createStyles, MultiSelect, Anchor, Checkbox, MediaQuery, Affix, rem, Popover, Radio, Switch, Drawer, Overlay, NumberInput, Autocomplete, Notification, Image, Accordion, Header, px, FileInput, SimpleGrid, Burger, Collapse, HoverCard, CopyButton, Breadcrumbs, Col } from '@mantine/core';
2
+ import React, { forwardRef, useState, useCallback, useRef, useEffect, createContext, useContext, useMemo, Fragment as Fragment$1, createElement, memo, useImperativeHandle } from 'react';
3
3
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
4
4
  import axios from 'axios';
5
5
  import * as d3Array from 'd3-array';
@@ -21,11 +21,12 @@ import { HYDRATE, createWrapper } from 'next-redux-wrapper';
21
21
  import { Notifications, notifications } from '@mantine/notifications';
22
22
  import { useDispatch, useSelector } from 'react-redux';
23
23
  import Router, { useRouter } from 'next/router';
24
- import { useClickOutside, useDisclosure, useDebouncedValue, useSetState, useUncontrolled, useHotkeys, getHotkeyHandler, useMediaQuery, useMergedRef, useFullscreen } from '@mantine/hooks';
25
- import { IconDice, IconBoxMultiple, IconEyeOff, IconChevronDown, IconBallpen, IconDatabase, IconMathFunction, IconUsers, IconLogout, IconHeading, IconApi, IconPercentage, IconChartBar, IconAlignLeft, IconSelector, IconPhoto, IconUserCircle, IconEdit, IconServer, IconPencil, IconAlertCircle, IconCircleCheck, IconPlayerPlay, IconTrash, IconCircleX, IconPlus, IconFileAnalytics, IconHome, IconSearch, IconX, IconRefresh, IconDownload, IconCircleDashed, IconLanguage, IconSettingsFilled, IconEye, IconWorldUpload, IconBraces, IconClockHour2, IconAugmentedReality, IconGitMerge, IconGripHorizontal, IconChevronLeft, IconChevronRight, IconListCheck, IconPolaroid, IconCircleMinus, IconInfoCircle, IconTable, IconCamera, IconShare, IconQuestionMark, IconCirclePlus, IconLogin, IconWorld, IconLock, IconCopy, IconBinaryTree, IconVariable, IconArrowRightCircle, IconPhotoFilled, IconFileUpload, IconIndentIncrease, IconCodeDots, IconUpload, IconCodePlus, IconLink, IconSparkles, IconClipboardCheck, IconClipboardCopy, IconExternalLink, IconFileTypeCsv, IconFileTypeJs, IconFileTypeXls, IconTemplate, IconCode, IconPalette, IconBold, IconItalic, IconUnderline, IconAlignCenter, IconAlignRight, IconAlignJustified, IconArrowBackUp, IconArrowForwardUp, IconCheck, IconLanguageOff, IconTriangleInvertedFilled, IconDeviceFloppy, IconSettings, IconMinimize, IconMaximize, IconGlobe, IconLinkOff } from '@tabler/icons-react';
24
+ import { useClickOutside, useDisclosure, useDebouncedValue, useSetState, useUncontrolled, useHotkeys, useListState, randomId, getHotkeyHandler, useMediaQuery, useMergedRef, useFullscreen } from '@mantine/hooks';
25
+ import { IconDice, IconBoxMultiple, IconEyeOff, IconChevronDown, IconBallpen, IconDatabase, IconMathFunction, IconUsers, IconLogout, IconHeading, IconApi, IconPercentage, IconChartBar, IconAlignLeft, IconSelector, IconPhoto, IconTable, IconUserCircle, IconEdit, IconServer, IconPencil, IconAlertCircle, IconCircleCheck, IconPlayerPlay, IconTrash, IconCircleX, IconPlus, IconFileAnalytics, IconHome, IconSearch, IconX, IconRefresh, IconDownload, IconCircleDashed, IconLanguage, IconSettingsFilled, IconEye, IconWorldUpload, IconBraces, IconClockHour2, IconAugmentedReality, IconGitMerge, IconGripHorizontal, IconChevronLeft, IconChevronRight, IconListCheck, IconPolaroid, IconCircleMinus, IconInfoCircle, IconGripVertical, IconCamera, IconShare, IconQuestionMark, IconCirclePlus, IconLogin, IconWorld, IconLock, IconCopy, IconBinaryTree, IconVariable, IconArrowRightCircle, IconPhotoFilled, IconFileUpload, IconIndentIncrease, IconCodeDots, IconUpload, IconCodePlus, IconLink, IconSparkles, IconClipboardCheck, IconClipboardCopy, IconExternalLink, IconFileTypeCsv, IconFileTypeJs, IconFileTypeXls, IconTemplate, IconCode, IconPalette, IconBold, IconItalic, IconUnderline, IconAlignCenter, IconAlignRight, IconAlignJustified, IconArrowBackUp, IconArrowForwardUp, IconCheck, IconLanguageOff, IconTriangleInvertedFilled, IconDeviceFloppy, IconSettings, IconMinimize, IconMaximize, IconGlobe, IconLinkOff } from '@tabler/icons-react';
26
26
  import Link from 'next/link';
27
27
  import parse2, { Element as Element$1, domToReact, Text as Text$1 } from 'html-react-parser';
28
28
  import { UserProvider, withPageAuthRequired, useUser } from '@auth0/nextjs-auth0/client';
29
+ import { MantineReactTable } from 'mantine-react-table';
29
30
  import { dataConcat, dataLoad } from 'd3plus-viz';
30
31
  import * as d3plus from 'd3plus-react';
31
32
  import dynamic from 'next/dynamic';
@@ -44,8 +45,8 @@ import HardBreak from '@tiptap/extension-hard-break';
44
45
  import TextAlign from '@tiptap/extension-text-align';
45
46
  import Placeholder from '@tiptap/extension-placeholder';
46
47
  import Typography from '@tiptap/extension-typography';
48
+ import { DragDropContext, Droppable, Draggable } from '@hello-pangea/dnd';
47
49
  import { Prism } from '@mantine/prism';
48
- import { MantineReactTable } from 'mantine-react-table';
49
50
  import slugifyFn from 'slugify';
50
51
  import JSZip from 'jszip';
51
52
  import { saveAs } from 'file-saver';
@@ -53,7 +54,6 @@ import { select } from 'd3-selection';
53
54
  import { saveElement } from 'd3plus-export';
54
55
  import { FacebookShareButton, FacebookIcon, TwitterShareButton, TwitterIcon, TelegramShareButton, TelegramIcon, WhatsappShareButton, WhatsappIcon, LinkedinShareButton, LinkedinIcon, RedditShareButton, RedditIcon, EmailShareButton, EmailIcon } from 'react-share';
55
56
  import Head from 'next/head';
56
- import { DragDropContext, Droppable, Draggable } from '@hello-pangea/dnd';
57
57
  import Editor, { useMonaco } from '@monaco-editor/react';
58
58
  import { format } from 'pretty-format';
59
59
  import * as d3 from 'd3';
@@ -602,7 +602,8 @@ var init_cms = __esm({
602
602
  NAV: "nav",
603
603
  // todo1.0, how to put custom blocks in here?
604
604
  RESET_BUTTON: "reset_button",
605
- COMPARISON_BUTTON: "comparison_button"
605
+ COMPARISON_BUTTON: "comparison_button",
606
+ TABLE: "table"
606
607
  };
607
608
  BLOCK_LOGIC_TYPES = {
608
609
  GENERATOR: "generator",
@@ -615,7 +616,8 @@ var init_cms = __esm({
615
616
  BLOCK_TYPES.GENERATOR,
616
617
  BLOCK_TYPES.SELECTOR,
617
618
  BLOCK_TYPES.VIZ,
618
- BLOCK_TYPES.IMAGE
619
+ BLOCK_TYPES.IMAGE,
620
+ BLOCK_TYPES.TABLE
619
621
  ];
620
622
  BLOCK_FIELDS = {
621
623
  ALT: "alt",
@@ -635,6 +637,7 @@ var init_cms = __esm({
635
637
  SRC: "src",
636
638
  SLUG: "slug",
637
639
  SUBTITLE: "subtitle",
640
+ TABLE: "table",
638
641
  TITLE: "title",
639
642
  TOOLTIP: "tooltip",
640
643
  TWITTER: "twitter",
@@ -772,7 +775,8 @@ var init_cms = __esm({
772
775
  }
773
776
  ],
774
777
  [BLOCK_TYPES.GENERATOR]: [],
775
- [BLOCK_TYPES.VIZ]: []
778
+ [BLOCK_TYPES.VIZ]: [],
779
+ [BLOCK_TYPES.TABLE]: []
776
780
  };
777
781
  BLOCK_SETTINGS = {
778
782
  NAME: "name",
@@ -6046,6 +6050,68 @@ var init_ComparisonButton = __esm({
6046
6050
  init_ComparisonProvider();
6047
6051
  }
6048
6052
  });
6053
+ function Table({ columns = [], data = [], tableProps = {}, sectionId = null }) {
6054
+ const [isFullScreen, setIsFullScreen] = useState(false);
6055
+ const [translations, setTranslations] = useState({});
6056
+ const columnsKeys = useMemo(() => columns.map((column) => column.accessorKey), [columns]);
6057
+ const filteredData = useMemo(() => data.filter(
6058
+ (item) => typeof item === "object" && item !== null && !Array.isArray(item) && Object.keys(item).some((val) => columnsKeys.includes(val))
6059
+ ), [columnsKeys, data]);
6060
+ const richColumns = useMemo(() => columns.map((column) => ({
6061
+ ...column,
6062
+ Cell: ({ renderedCellValue }) => /* @__PURE__ */ jsx(RichText, { html: `${renderedCellValue}` }),
6063
+ filterFn: "contains"
6064
+ })), [columns]);
6065
+ const { locale } = useRouter();
6066
+ useEffect(() => {
6067
+ const loadLocalizedComponent = async () => {
6068
+ try {
6069
+ const lang = locale || "en";
6070
+ const componentName = `${lang.toUpperCase()}`;
6071
+ const componentModule = await import(`mantine-react-table/locales/${lang}.js`);
6072
+ setTranslations(componentModule[`MRT_Localization_${componentName}`]);
6073
+ } catch (error) {
6074
+ console.error("Error loading translations:", error);
6075
+ }
6076
+ };
6077
+ loadLocalizedComponent();
6078
+ }, [locale]);
6079
+ return /* @__PURE__ */ jsx(
6080
+ MantineReactTable,
6081
+ {
6082
+ ...tableProps,
6083
+ autoResetPageIndex: false,
6084
+ columns: richColumns,
6085
+ data: filteredData,
6086
+ enableColumnFilterModes: true,
6087
+ enableFilterMatchHighlighting: false,
6088
+ globalFilterFn: "contains",
6089
+ layoutMode: "grid",
6090
+ localization: translations,
6091
+ onIsFullScreenChange: (val) => {
6092
+ const element = document.getElementById(`section-${sectionId}`);
6093
+ if (element) {
6094
+ if (val) {
6095
+ element.style.zIndex = "10";
6096
+ } else {
6097
+ element.style.zIndex = "1";
6098
+ }
6099
+ }
6100
+ setIsFullScreen(val);
6101
+ },
6102
+ state: {
6103
+ ...tableProps.state,
6104
+ isFullScreen
6105
+ }
6106
+ }
6107
+ );
6108
+ }
6109
+ var init_Table = __esm({
6110
+ "frontend/components/report/blocks/Table.tsx"() {
6111
+ init_esm_shims();
6112
+ init_RichText();
6113
+ }
6114
+ });
6049
6115
  var localeDefault8, frontEndMessage, errorStub, propify, d3plusPropify_default;
6050
6116
  var init_d3plusPropify = __esm({
6051
6117
  "libs/d3plusPropify.ts"() {
@@ -6264,6 +6330,7 @@ var init_blocks = __esm({
6264
6330
  init_Related();
6265
6331
  init_ResetButton();
6266
6332
  init_ComparisonButton();
6333
+ init_Table();
6267
6334
  VizView = dynamic(
6268
6335
  () => Promise.resolve().then(() => (init_Viz(), Viz_exports)),
6269
6336
  { ssr: false }
@@ -6280,7 +6347,8 @@ var init_blocks = __esm({
6280
6347
  [BLOCK_TYPES.NAV]: NavView,
6281
6348
  [BLOCK_TYPES.RELATED]: RelatedView,
6282
6349
  [BLOCK_TYPES.RESET_BUTTON]: ResetButtonView,
6283
- [BLOCK_TYPES.COMPARISON_BUTTON]: ComparisonButtonPreview
6350
+ [BLOCK_TYPES.COMPARISON_BUTTON]: ComparisonButtonPreview,
6351
+ [BLOCK_TYPES.TABLE]: Table
6284
6352
  };
6285
6353
  blocks_default = TypeRenderers;
6286
6354
  }
@@ -6361,10 +6429,12 @@ var init_stringifyObject = __esm({
6361
6429
  str += "false";
6362
6430
  else if (val === void 0)
6363
6431
  str = null;
6432
+ else if (["boolean", "number"].includes(typeof val))
6433
+ str += val;
6364
6434
  else
6365
6435
  str += `"${val}"`;
6366
6436
  return str;
6367
- }).filter(Boolean).join(`,${newLine(depth + 1)}`)}${newLine(depth)}${isArray ? "]" : "}"}`;
6437
+ }).filter((val) => val !== null).join(`,${newLine(depth + 1)}`)}${newLine(depth)}${isArray ? "]" : "}"}`;
6368
6438
  };
6369
6439
  stringifyObject_default = stringifyObject;
6370
6440
  }
@@ -12837,6 +12907,7 @@ function SelectorUI(props) {
12837
12907
  type: selectorType,
12838
12908
  component: selectorComponent,
12839
12909
  hideLabel,
12910
+ defaultValue,
12840
12911
  optionsType,
12841
12912
  options
12842
12913
  };
@@ -13431,6 +13502,516 @@ var init_StatUI = __esm({
13431
13502
  init_cms();
13432
13503
  }
13433
13504
  });
13505
+ function TableUI(props) {
13506
+ const { executeButton, id, onChange, referenceContent = {}, referenceLocale, simpleState } = props;
13507
+ const { columns: referenceColumns } = referenceContent;
13508
+ const locale = useCurrentLocale();
13509
+ const isActiveRefenceContent = useMemo(
13510
+ () => locale !== referenceLocale && referenceContent && Object.keys(referenceContent).length > 0,
13511
+ [locale, referenceContent, referenceLocale]
13512
+ );
13513
+ const variables = useInputVariablesFlat(id);
13514
+ const [columnOrder, setColumnOrder] = useState([]);
13515
+ const [customLabels, customLabelsHandler] = useListState([]);
13516
+ const [defaultVariableList, setDefaultVariableList] = useState([]);
13517
+ const [isInvalidStructure, setIsInvalidStructure] = useState(false);
13518
+ const [optionVariableMap, setOptionVariableMap] = useState({});
13519
+ const [paginationState, setPaginationState] = useState(defaultPaginationState);
13520
+ const [paginationProps, setPaginationProps] = useState({ rowsPerPageOptions: defaultPageSizes });
13521
+ const [selectedColumns, selectedColumnsHandler] = useListState([]);
13522
+ const [selectedVariable, setSelectedVariable] = useState(null);
13523
+ const [tableProps, setTableProps] = useSetState(defaultTableGlobalProps);
13524
+ const [initialTableState, setInitialTableState] = useState(defaultInitialStateProps);
13525
+ const [tableState, setTableState] = useState({});
13526
+ const allChecked = useMemo(() => selectedColumns.every((column) => column.checked), [selectedColumns]);
13527
+ const indeterminate = useMemo(() => {
13528
+ return selectedColumns.some((column) => column.checked) && !allChecked;
13529
+ }, [allChecked, selectedColumns]);
13530
+ useEffect(() => {
13531
+ if (!simpleState || !Object.keys(simpleState).length)
13532
+ return;
13533
+ const variableContent = variables[simpleState.variable] || [];
13534
+ const columns = /* @__PURE__ */ new Set();
13535
+ variableContent.filter((item) => typeof item === "object" && item !== null).forEach((item) => {
13536
+ Object.keys(item).forEach((key) => columns.add(key));
13537
+ });
13538
+ const stateColumns = {};
13539
+ if (simpleState.columns && Object.keys(simpleState.columns)) {
13540
+ simpleState.columns.forEach((column) => {
13541
+ stateColumns[column.accessorKey] = column.header;
13542
+ });
13543
+ }
13544
+ const keyList = [];
13545
+ const keyLabels = [];
13546
+ Array.from(columns).forEach((key) => {
13547
+ keyLabels.push({
13548
+ key,
13549
+ label: stateColumns[key] || key
13550
+ });
13551
+ keyList.push({
13552
+ checked: stateColumns[key] ? true : false,
13553
+ key: randomId(),
13554
+ label: key
13555
+ });
13556
+ });
13557
+ customLabelsHandler.setState(keyLabels);
13558
+ selectedColumnsHandler.setState(keyList);
13559
+ const { initialState: initialState4 = {}, state = {}, mantinePaginationProps = {}, ...props2 } = simpleState.tableProps || {};
13560
+ setColumnOrder(state.columnOrder || []);
13561
+ setPaginationProps(mantinePaginationProps);
13562
+ setPaginationState(initialState4.pagination);
13563
+ setTableProps({ ...props2 });
13564
+ setTableState(state);
13565
+ setInitialTableState(initialState4);
13566
+ setSelectedVariable(simpleState.variable || "");
13567
+ }, []);
13568
+ useEffect(() => {
13569
+ if (!variables) {
13570
+ setOptionVariableMap({});
13571
+ return;
13572
+ }
13573
+ const validVariableMap = Object.entries(variables).filter(([_2, variableContent]) => isValidSelectorOptionsArray2(variableContent)).reduce((acc, [variableName, variableContent]) => {
13574
+ acc[variableName] = variableContent;
13575
+ return acc;
13576
+ }, {});
13577
+ setOptionVariableMap(validVariableMap);
13578
+ const validDefaultIdList = Object.keys(validVariableMap);
13579
+ setDefaultVariableList(validDefaultIdList);
13580
+ }, [variables]);
13581
+ const handleVariableSelect = (value) => {
13582
+ setSelectedVariable(value);
13583
+ if (!value || !isValidSelectorOptionsArray2(optionVariableMap[value])) {
13584
+ setIsInvalidStructure(false);
13585
+ selectedColumnsHandler.setState([]);
13586
+ return;
13587
+ }
13588
+ const items = optionVariableMap[value];
13589
+ if (items.every((item) => typeof item === "object" && item === null)) {
13590
+ setIsInvalidStructure(false);
13591
+ selectedColumnsHandler.setState([]);
13592
+ return;
13593
+ }
13594
+ if (items.every((item) => typeof item === "object" && item !== null)) {
13595
+ setIsInvalidStructure(false);
13596
+ } else {
13597
+ setIsInvalidStructure(true);
13598
+ }
13599
+ const uniqueKeys = /* @__PURE__ */ new Set();
13600
+ items.filter((item) => typeof item === "object" && item !== null).forEach((item) => {
13601
+ Object.keys(item).forEach((key) => uniqueKeys.add(key));
13602
+ });
13603
+ const keyList = [];
13604
+ const keyLabels = [];
13605
+ const columns = [];
13606
+ Array.from(uniqueKeys).forEach((key) => {
13607
+ keyList.push({
13608
+ checked: true,
13609
+ key: randomId(),
13610
+ label: key
13611
+ });
13612
+ keyLabels.push({
13613
+ key,
13614
+ label: key
13615
+ });
13616
+ columns.push(key);
13617
+ });
13618
+ selectedColumnsHandler.setState(keyList);
13619
+ customLabelsHandler.setState(keyLabels);
13620
+ setColumnOrder(columns);
13621
+ };
13622
+ useEffect(() => {
13623
+ const columnLabelsMap = {};
13624
+ customLabels.forEach((column) => {
13625
+ columnLabelsMap[column.key] = column.label;
13626
+ });
13627
+ const columns = selectedColumns.filter((column) => column.checked).map((column) => ({
13628
+ accessorKey: column.label,
13629
+ header: columnLabelsMap[column.label]
13630
+ }));
13631
+ const extendedInitialTableState = {
13632
+ ...initialTableState,
13633
+ pagination: paginationState
13634
+ };
13635
+ const extendedTableState = {
13636
+ ...tableState,
13637
+ columnOrder
13638
+ };
13639
+ const logicObj = {
13640
+ columns,
13641
+ data: selectedVariable ? `variables["${selectedVariable}"]` : [],
13642
+ tableProps: {
13643
+ ...tableProps,
13644
+ initialState: extendedInitialTableState,
13645
+ state: extendedTableState,
13646
+ mantinePaginationProps: paginationProps
13647
+ },
13648
+ variable: selectedVariable || ""
13649
+ };
13650
+ const logic = `return ${stringifyObject_default(logicObj)};`;
13651
+ const simpleState2 = {
13652
+ columns,
13653
+ data: selectedVariable ? `variables["${selectedVariable}"]` : [],
13654
+ tableProps: {
13655
+ ...tableProps,
13656
+ initialState: extendedInitialTableState,
13657
+ state: extendedTableState,
13658
+ mantinePaginationProps: paginationProps
13659
+ },
13660
+ variable: selectedVariable || ""
13661
+ };
13662
+ onChange(simpleState2, logic);
13663
+ }, [
13664
+ columnOrder,
13665
+ customLabels,
13666
+ paginationProps,
13667
+ paginationState,
13668
+ selectedColumns,
13669
+ selectedVariable,
13670
+ tableProps,
13671
+ tableState,
13672
+ initialTableState
13673
+ ]);
13674
+ const onDragEnd = useCallback((result) => {
13675
+ if (!result.destination || result.source.index === result.destination.index)
13676
+ return;
13677
+ const newOrder = [...columnOrder];
13678
+ const [draggedItem] = newOrder.splice(result.source.index, 1);
13679
+ newOrder.splice(result.destination.index, 0, draggedItem);
13680
+ setColumnOrder(newOrder);
13681
+ setTableState((current) => {
13682
+ const newState = current;
13683
+ newState["columnOrder"] = newOrder;
13684
+ return newState;
13685
+ });
13686
+ }, [columnOrder]);
13687
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
13688
+ /* @__PURE__ */ jsxs(Stack, { mb: "sm", children: [
13689
+ /* @__PURE__ */ jsx(
13690
+ Select,
13691
+ {
13692
+ clearable: true,
13693
+ data: defaultVariableList,
13694
+ description: "Select an array of data available in the block inputs to use as data input for the table.",
13695
+ label: "Data input",
13696
+ onChange: (value) => handleVariableSelect(value),
13697
+ searchable: true,
13698
+ value: selectedVariable
13699
+ }
13700
+ ),
13701
+ selectedVariable && optionVariableMap[selectedVariable] && selectedColumns.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
13702
+ /* @__PURE__ */ jsx(
13703
+ Input.Wrapper,
13704
+ {
13705
+ description: "Select the columns to display in the table.",
13706
+ error: isInvalidStructure && "There is a mix of types in the input data. Only object types rows will be kept.",
13707
+ label: "Selected columns",
13708
+ children: /* @__PURE__ */ jsxs(Stack, { mt: "xs", children: [
13709
+ /* @__PURE__ */ jsxs(Group, { grow: true, children: [
13710
+ /* @__PURE__ */ jsx(Text, { fz: "xs", children: "Selected" }),
13711
+ /* @__PURE__ */ jsx(Text, { fz: "xs", children: "Label" }),
13712
+ isActiveRefenceContent && /* @__PURE__ */ jsxs(Group, { spacing: "xs", children: [
13713
+ /* @__PURE__ */ jsx(Text, { fz: "xs", children: "Reference Label" }),
13714
+ /* @__PURE__ */ jsx(
13715
+ Badge,
13716
+ {
13717
+ variant: "light",
13718
+ size: "xs",
13719
+ rightSection: /* @__PURE__ */ jsx(Center, { children: /* @__PURE__ */ jsx(IconLanguage, { size: rem(12) }) }),
13720
+ children: referenceLocale.toUpperCase()
13721
+ }
13722
+ )
13723
+ ] })
13724
+ ] }),
13725
+ /* @__PURE__ */ jsx(
13726
+ Checkbox,
13727
+ {
13728
+ checked: allChecked,
13729
+ indeterminate,
13730
+ label: "All",
13731
+ onChange: () => selectedColumnsHandler.setState((current) => current.map((value) => ({ ...value, checked: !allChecked })))
13732
+ }
13733
+ ),
13734
+ /* @__PURE__ */ jsx(ScrollArea.Autosize, { mah: 300, children: /* @__PURE__ */ jsx(DragDropContext, { onDragEnd, children: /* @__PURE__ */ jsx(Droppable, { droppableId: "columns", children: (droppableProvided) => /* @__PURE__ */ jsx("div", { ref: droppableProvided.innerRef, ...droppableProvided.droppableProps, children: columnOrder.map((option, index) => {
13735
+ const columnIndex = selectedColumns.findIndex((col) => col.label === option);
13736
+ const column = selectedColumns[columnIndex];
13737
+ return /* @__PURE__ */ jsx(
13738
+ Draggable,
13739
+ {
13740
+ draggableId: `${column.label}`,
13741
+ index,
13742
+ isDragDisabled: !column.checked,
13743
+ children: (draggableProvided) => /* @__PURE__ */ jsx(
13744
+ ColumnRenderer,
13745
+ {
13746
+ customLabels,
13747
+ customLabelsHandler,
13748
+ index: columnIndex,
13749
+ isActiveRefenceContent,
13750
+ option: column,
13751
+ ref: draggableProvided.innerRef,
13752
+ referenceColumns,
13753
+ selectedColumnsHandler,
13754
+ ...draggableProvided.draggableProps,
13755
+ ...draggableProvided.dragHandleProps
13756
+ }
13757
+ )
13758
+ },
13759
+ column.label
13760
+ );
13761
+ }) }) }) }) })
13762
+ ] })
13763
+ }
13764
+ ),
13765
+ /* @__PURE__ */ jsx(Accordion, { variant: "separated", children: /* @__PURE__ */ jsxs(Accordion.Item, { value: "custom-props", children: [
13766
+ /* @__PURE__ */ jsx(Accordion.Control, { children: "Custom properties" }),
13767
+ /* @__PURE__ */ jsx(Accordion.Panel, { children: /* @__PURE__ */ jsx(Stack, { children: /* @__PURE__ */ jsxs(
13768
+ Input.Wrapper,
13769
+ {
13770
+ description: "Select the needed table options.",
13771
+ label: "Table options",
13772
+ children: [
13773
+ /* @__PURE__ */ jsx(Group, { mt: "xs", children: Object.keys(tableProps).map((prop) => /* @__PURE__ */ jsx(
13774
+ Checkbox,
13775
+ {
13776
+ checked: tableProps[prop],
13777
+ label: /* @__PURE__ */ jsx(
13778
+ Tooltip,
13779
+ {
13780
+ label: tableGlobalPropsDesc[prop]?.desc || prop,
13781
+ multiline: true,
13782
+ children: /* @__PURE__ */ jsx(Text, { children: tableGlobalPropsDesc[prop]?.label || prop })
13783
+ }
13784
+ ),
13785
+ onChange: () => setTableProps({ [prop]: !tableProps[prop] })
13786
+ },
13787
+ `table-prop-${prop}`
13788
+ )) }),
13789
+ tableProps?.enablePagination && /* @__PURE__ */ jsxs(Fragment, { children: [
13790
+ /* @__PURE__ */ jsx(Divider, { mt: "xs" }),
13791
+ /* @__PURE__ */ jsxs(
13792
+ Input.Wrapper,
13793
+ {
13794
+ description: "Customize initial pagination properties.",
13795
+ label: "Pagination props",
13796
+ mt: "xs",
13797
+ children: [
13798
+ /* @__PURE__ */ jsxs(Group, { grow: true, children: [
13799
+ /* @__PURE__ */ jsx(
13800
+ NumberInput,
13801
+ {
13802
+ label: "Initial page",
13803
+ min: 0,
13804
+ onChange: (value) => {
13805
+ setPaginationState((current) => ({
13806
+ ...current,
13807
+ pageIndex: value
13808
+ }));
13809
+ },
13810
+ value: paginationState.pageIndex
13811
+ }
13812
+ ),
13813
+ /* @__PURE__ */ jsx(
13814
+ Select,
13815
+ {
13816
+ data: paginationProps.rowsPerPageOptions || [],
13817
+ getCreateLabel: (value) => `+ Create ${value}`,
13818
+ label: "Initial page size",
13819
+ onChange: (value) => {
13820
+ setPaginationState((current) => ({
13821
+ ...current,
13822
+ pageSize: parseInt(value, 10)
13823
+ }));
13824
+ },
13825
+ searchable: true,
13826
+ value: paginationState.pageSize.toString()
13827
+ }
13828
+ )
13829
+ ] }),
13830
+ /* @__PURE__ */ jsxs(Group, { align: "flex-end", grow: true, children: [
13831
+ /* @__PURE__ */ jsx(
13832
+ MultiSelect,
13833
+ {
13834
+ clearable: true,
13835
+ creatable: true,
13836
+ data: paginationProps.rowsPerPageOptions || [],
13837
+ getCreateLabel: (value) => `+ Create ${value}`,
13838
+ label: "Page size options",
13839
+ onChange: (value) => {
13840
+ setPaginationProps((current) => ({
13841
+ ...current,
13842
+ rowsPerPageOptions: value.sort((a2, b2) => parseInt(a2, 10) - parseInt(b2, 10))
13843
+ }));
13844
+ if (value && value.length > 0 && !value.includes(paginationState.pageSize.toString())) {
13845
+ setPaginationState((current) => ({
13846
+ ...current,
13847
+ pageSize: parseInt(value[0], 10)
13848
+ }));
13849
+ }
13850
+ },
13851
+ onCreate: (value) => {
13852
+ setPaginationProps((current) => ({
13853
+ ...current,
13854
+ rowsPerPageOptions: [...current.rowsPerPageOptions || [], value].sort((a2, b2) => parseInt(a2, 10) - parseInt(b2, 10))
13855
+ }));
13856
+ return value;
13857
+ },
13858
+ searchable: true,
13859
+ value: paginationProps.rowsPerPageOptions || []
13860
+ }
13861
+ ),
13862
+ /* @__PURE__ */ jsx(
13863
+ Button,
13864
+ {
13865
+ color: "yellow",
13866
+ onClick: () => {
13867
+ setPaginationProps((current) => ({
13868
+ ...current,
13869
+ rowsPerPageOptions: defaultPageSizes
13870
+ }));
13871
+ setPaginationState(defaultPaginationState);
13872
+ },
13873
+ children: "Reset page sizes values"
13874
+ }
13875
+ )
13876
+ ] })
13877
+ ]
13878
+ }
13879
+ )
13880
+ ] })
13881
+ ]
13882
+ }
13883
+ ) }) })
13884
+ ] }) })
13885
+ ] })
13886
+ ] }),
13887
+ executeButton
13888
+ ] });
13889
+ }
13890
+ var defaultTableGlobalProps, tableGlobalPropsDesc, defaultInitialStateProps, defaultPageSizes, defaultPaginationState, isValidSelectorOptionsArray2, ColumnRenderer;
13891
+ var init_TableUI = __esm({
13892
+ "components/blocks/types/simpleEditors/TableUI.tsx"() {
13893
+ init_esm_shims();
13894
+ init_stringifyObject();
13895
+ init_hooks();
13896
+ defaultTableGlobalProps = {
13897
+ enableBottomToolbar: true,
13898
+ enableColumnActions: true,
13899
+ enableColumnFilters: true,
13900
+ enableColumnResizing: true,
13901
+ enableDensityToggle: true,
13902
+ enableFullScreenToggle: false,
13903
+ enableGlobalFilter: true,
13904
+ enableHiding: true,
13905
+ enablePagination: true,
13906
+ enableSorting: true,
13907
+ enableStickyHeader: true,
13908
+ enableTopToolbar: true
13909
+ };
13910
+ tableGlobalPropsDesc = {
13911
+ enableBottomToolbar: {
13912
+ label: "Enable bottom toolbar",
13913
+ desc: "Show or hide the bottom toolbar. By disabling it, pagination will also be hidden."
13914
+ },
13915
+ enableColumnActions: {
13916
+ label: "Enable column actions",
13917
+ desc: "Enables or disables column actions for all columns. Column actions include sort, filter, show/hide column and reset column size."
13918
+ },
13919
+ enableColumnFilters: {
13920
+ label: "Enable column filters",
13921
+ desc: "Enables or disables the filter options available on columns."
13922
+ },
13923
+ enableColumnResizing: {
13924
+ label: "Enable column resizing",
13925
+ desc: "Enables the column resizing feature for all columns."
13926
+ },
13927
+ enableDensityToggle: {
13928
+ label: "Enable density toggle",
13929
+ desc: "Enable the density toggle that allows users to modify the height of each row. Disabling it will hide the density toggle button in the top toolbar."
13930
+ },
13931
+ enableFullScreenToggle: {
13932
+ label: "Enable full screen toggle",
13933
+ desc: "Enable or disable the full screen toggle feature. Disabling it will hide the full screen toggle button in the top toolbar."
13934
+ },
13935
+ enableGlobalFilter: {
13936
+ label: "Enable global filter",
13937
+ desc: "Enable global filter feature to filter data on all columns and rows. Disabling it will hide the global filter button in the top toolbar."
13938
+ },
13939
+ enableHiding: {
13940
+ label: "Enable hiding",
13941
+ desc: "Enable hiding columns feature. Disabling it will hide the hiding button in the top toolbar."
13942
+ },
13943
+ enablePagination: {
13944
+ label: "Enable pagination",
13945
+ desc: "Enable pagination feature. Disabling it will hide the pagination options in the bottom toolbar."
13946
+ },
13947
+ enableSorting: {
13948
+ label: "Enable sorting",
13949
+ desc: "Enable sorting feature for all columns."
13950
+ },
13951
+ enableStickyHeader: {
13952
+ label: "Enable sticky header",
13953
+ desc: "Allows you to maintain the column headers when scrolling through the rows of the table."
13954
+ },
13955
+ enableTopToolbar: {
13956
+ label: "Enable top toolbar",
13957
+ desc: "Show or hide the top toolbar. By disabling it, globar filter, hiding, density and full screen toggles will also be hidden."
13958
+ }
13959
+ };
13960
+ defaultInitialStateProps = {
13961
+ density: "xs"
13962
+ };
13963
+ defaultPageSizes = ["5", "10", "15", "20", "25", "30", "50", "100"];
13964
+ defaultPaginationState = {
13965
+ pageIndex: 0,
13966
+ pageSize: 10
13967
+ };
13968
+ isValidSelectorOptionsArray2 = (variable) => variable && Array.isArray(variable) && variable.some((elemento) => typeof elemento === "object" && elemento !== null);
13969
+ ColumnRenderer = forwardRef(
13970
+ function ColumnRendererComponent({
13971
+ customLabels,
13972
+ customLabelsHandler,
13973
+ index,
13974
+ isActiveRefenceContent = false,
13975
+ option,
13976
+ referenceColumns = [],
13977
+ selectedColumnsHandler,
13978
+ ...rest
13979
+ }, ref) {
13980
+ const customLabel = customLabels.find((label) => label.key === option.label)?.label || "";
13981
+ const referenceColumn = referenceColumns.find((column) => column.accessorKey === option.label);
13982
+ const referenceColumnLabel = referenceColumn?.header || option.label;
13983
+ return /* @__PURE__ */ jsxs(Group, { grow: true, ref, ...rest, children: [
13984
+ /* @__PURE__ */ jsxs(Group, { children: [
13985
+ /* @__PURE__ */ jsx(IconGripVertical, {}),
13986
+ /* @__PURE__ */ jsx(
13987
+ Checkbox,
13988
+ {
13989
+ checked: option.checked,
13990
+ label: option.label,
13991
+ onChange: (event) => selectedColumnsHandler.setItemProp(index, "checked", event.currentTarget.checked)
13992
+ }
13993
+ )
13994
+ ] }),
13995
+ /* @__PURE__ */ jsx(
13996
+ Input,
13997
+ {
13998
+ disabled: !option.checked,
13999
+ onChange: (event) => customLabelsHandler.setItemProp(index, "label", event.currentTarget.value),
14000
+ value: customLabel
14001
+ }
14002
+ ),
14003
+ isActiveRefenceContent && /* @__PURE__ */ jsx(
14004
+ Input,
14005
+ {
14006
+ disabled: true,
14007
+ value: referenceColumnLabel
14008
+ }
14009
+ )
14010
+ ] }, `table-group-${option.label}-${index}`);
14011
+ }
14012
+ );
14013
+ }
14014
+ });
13434
14015
 
13435
14016
  // components/blocks/types/simpleEditors/index.js
13436
14017
  var simpleEditors, simpleEditors_default;
@@ -13445,6 +14026,7 @@ var init_simpleEditors = __esm({
13445
14026
  init_TitleUI();
13446
14027
  init_ComparisonButtonUI();
13447
14028
  init_StatUI();
14029
+ init_TableUI();
13448
14030
  simpleEditors = {
13449
14031
  [BLOCK_TYPES.SELECTOR]: SelectorUI_default,
13450
14032
  [BLOCK_TYPES.NAV]: NavUI,
@@ -13452,7 +14034,8 @@ var init_simpleEditors = __esm({
13452
14034
  [BLOCK_TYPES.RESET_BUTTON]: ResetButtonUI,
13453
14035
  [BLOCK_TYPES.COMPARISON_BUTTON]: ComparisonButtonUI,
13454
14036
  [BLOCK_TYPES.TITLE]: TitleUI,
13455
- [BLOCK_TYPES.STAT]: StatUI
14037
+ [BLOCK_TYPES.STAT]: StatUI,
14038
+ [BLOCK_TYPES.TABLE]: TableUI
13456
14039
  };
13457
14040
  simpleEditors_default = simpleEditors;
13458
14041
  }
@@ -14017,7 +14600,7 @@ function useCurrentLocale2() {
14017
14600
  if (paramLocale && paramLocale !== "" && locales4.includes(paramLocale) && paramLocale !== currentLocale) {
14018
14601
  dispatch(actions_exports.setCurrentLocale(paramLocale));
14019
14602
  }
14020
- }, [paramLocale]);
14603
+ }, []);
14021
14604
  return currentLocale;
14022
14605
  }
14023
14606
  var init_useCurrentLocale = __esm({
@@ -14158,6 +14741,63 @@ var init_ComparisonButton2 = __esm({
14158
14741
  init_esm_shims();
14159
14742
  }
14160
14743
  });
14744
+ function TablePreview({ columns = [], id, data = [], tableProps = {} }) {
14745
+ const [translations, setTranslations] = useState({});
14746
+ const { initialState: initialState4 } = tableProps;
14747
+ const pageIndex = initialState4?.pagination?.pageIndex;
14748
+ const pageSize = initialState4?.pagination?.pageSize;
14749
+ const tableId = `table-${[id, pageIndex, pageSize].filter((d2) => d2).join("-")}`;
14750
+ const columnsKeys = useMemo(() => columns.map((column) => column.accessorKey), [columns]);
14751
+ const filteredData = useMemo(() => data.filter(
14752
+ (item) => typeof item === "object" && item !== null && !Array.isArray(item) && Object.keys(item).some((val) => columnsKeys.includes(val))
14753
+ ), [columnsKeys, data]);
14754
+ const richColumns = useMemo(() => columns.map((column) => ({
14755
+ ...column,
14756
+ Cell: ({ renderedCellValue }) => /* @__PURE__ */ jsx(RichText, { html: `${renderedCellValue}` }),
14757
+ filterFn: "contains"
14758
+ })), [columns]);
14759
+ const locale = useCurrentLocale();
14760
+ useEffect(() => {
14761
+ const loadLocalizedComponent = async () => {
14762
+ try {
14763
+ const lang = locale || "en";
14764
+ const componentName = `${lang.toUpperCase()}`;
14765
+ const componentModule = await import(`mantine-react-table/locales/${lang}.js`);
14766
+ setTranslations(componentModule[`MRT_Localization_${componentName}`]);
14767
+ } catch (error) {
14768
+ console.error("Error loading translations:", error);
14769
+ }
14770
+ };
14771
+ loadLocalizedComponent();
14772
+ }, [locale]);
14773
+ return /* @__PURE__ */ createElement(
14774
+ MantineReactTable,
14775
+ {
14776
+ ...tableProps,
14777
+ autoResetPageIndex: false,
14778
+ columns: richColumns,
14779
+ data: filteredData,
14780
+ enableColumnFilterModes: true,
14781
+ enableFilterMatchHighlighting: false,
14782
+ globalFilterFn: "contains",
14783
+ key: tableId,
14784
+ layoutMode: "grid",
14785
+ localization: translations,
14786
+ state: {
14787
+ ...tableProps.state,
14788
+ // prevents the user from getting the full screen table overlay error on cms
14789
+ isFullScreen: false
14790
+ }
14791
+ }
14792
+ );
14793
+ }
14794
+ var init_Table2 = __esm({
14795
+ "components/blocks/types/renderers/Table.tsx"() {
14796
+ init_esm_shims();
14797
+ init_RichText();
14798
+ init_hooks();
14799
+ }
14800
+ });
14161
14801
 
14162
14802
  // components/blocks/types/renderers/Viz.tsx
14163
14803
  var Viz_exports2 = {};
@@ -14288,6 +14928,7 @@ var init_renderers = __esm({
14288
14928
  init_Related2();
14289
14929
  init_ResetButton2();
14290
14930
  init_ComparisonButton2();
14931
+ init_Table2();
14291
14932
  VizPreview = dynamic(
14292
14933
  () => Promise.resolve().then(() => (init_Viz2(), Viz_exports2)),
14293
14934
  { ssr: false }
@@ -14304,7 +14945,8 @@ var init_renderers = __esm({
14304
14945
  [BLOCK_TYPES.NAV]: NavPreview,
14305
14946
  [BLOCK_TYPES.RELATED]: RelatedPreview,
14306
14947
  [BLOCK_TYPES.RESET_BUTTON]: ResetButtonPreview,
14307
- [BLOCK_TYPES.COMPARISON_BUTTON]: ComparisonButtonPreview2
14948
+ [BLOCK_TYPES.COMPARISON_BUTTON]: ComparisonButtonPreview2,
14949
+ [BLOCK_TYPES.TABLE]: TablePreview
14308
14950
  };
14309
14951
  renderers_default = renderersMap;
14310
14952
  }
@@ -14323,7 +14965,8 @@ var init_icons = __esm({
14323
14965
  "visualization": IconChartBar,
14324
14966
  "paragraph": IconAlignLeft,
14325
14967
  "selector": IconSelector,
14326
- "image": IconPhoto
14968
+ "image": IconPhoto,
14969
+ "table": IconTable
14327
14970
  };
14328
14971
  }
14329
14972
  });
@@ -14350,7 +14993,8 @@ var init_labels = __esm({
14350
14993
  "related": "Related Reports",
14351
14994
  // (?)
14352
14995
  "nav": "Navigation",
14353
- "image": "Image"
14996
+ "image": "Image",
14997
+ "table": "Table"
14354
14998
  };
14355
14999
  }
14356
15000
  });
@@ -14446,6 +15090,12 @@ var init_types = __esm({
14446
15090
  renderer: renderers_default[BLOCK_TYPES.COMPARISON_BUTTON],
14447
15091
  renderPreviewOnEdit: true,
14448
15092
  evalWhenNonActive: true
15093
+ },
15094
+ [BLOCK_TYPES.TABLE]: {
15095
+ type: BLOCK_TYPES.TABLE,
15096
+ renderer: renderers_default[BLOCK_TYPES.TABLE],
15097
+ renderPreviewOnEdit: false,
15098
+ evalWhenNonActive: false
14449
15099
  }
14450
15100
  };
14451
15101
  types_default = allBlocks;
@@ -14553,6 +15203,13 @@ function Block({ blockId, active = true, asComparison = false }) {
14553
15203
  void 0,
14554
15204
  blockContext
14555
15205
  );
15206
+ if (block.type === BLOCK_TYPES.TABLE) {
15207
+ setContent3({
15208
+ sectionId: block.section_id,
15209
+ ...vars
15210
+ });
15211
+ return;
15212
+ }
14556
15213
  setContent3(vars);
14557
15214
  return;
14558
15215
  };
@@ -17541,7 +18198,7 @@ function DimensionAutocomplete(props) {
17541
18198
  value: _variant,
17542
18199
  onChange: setVariant
17543
18200
  },
17544
- dimensionId
18201
+ `dimension-${dimensionId}`
17545
18202
  ),
17546
18203
  /* @__PURE__ */ jsx(
17547
18204
  Text,
@@ -17562,7 +18219,7 @@ function DimensionAutocomplete(props) {
17562
18219
  onChange: setMember,
17563
18220
  locale
17564
18221
  },
17565
- _variant
18222
+ `variant-${_variant}`
17566
18223
  )
17567
18224
  ] });
17568
18225
  }
@@ -18988,6 +19645,7 @@ function CMSHeader(props) {
18988
19645
  locale: previewLocale,
18989
19646
  output: "full"
18990
19647
  })).then(({ results }) => {
19648
+ dispatch(actions_exports.setCurrentLocale(previewLocale));
18991
19649
  if (results && results.length === dimensions.length && dimensions.length) {
18992
19650
  dispatch(actions_exports.recalculateVariables(resource, { previews: results }));
18993
19651
  } else {
@@ -20333,6 +20991,11 @@ var unlocalizedKeys = {
20333
20991
  ],
20334
20992
  [BLOCK_TYPES.STAT]: [
20335
20993
  ...UNLOCALIZED_ICON_KEYS
20994
+ ],
20995
+ [BLOCK_TYPES.TABLE]: [
20996
+ "data",
20997
+ "tableProps",
20998
+ "variable"
20336
20999
  ]
20337
21000
  };
20338
21001
  var reduceContent = (acc, d2) => ({ ...acc, [d2.locale]: { ...d2, content: d2.content } });
@@ -20433,10 +21096,14 @@ function Block2({ id, modified, callbacks, inline }) {
20433
21096
  newSimple[key] = unlocalizedContent.simple[key];
20434
21097
  }
20435
21098
  });
21099
+ const logicObj = { ...newSimple };
21100
+ if (block.type === BLOCK_TYPES.SELECTOR) {
21101
+ logicObj.options = logicObj.options[logicObj.optionsType];
21102
+ }
20436
21103
  newContentByLocale[locale].content = {
20437
21104
  ...newContentByLocale[locale].content,
20438
21105
  simple: newSimple,
20439
- logic: `return ${stringifyObject_default(newSimple)}`
21106
+ logic: `return ${stringifyObject_default(logicObj)}`
20440
21107
  };
20441
21108
  });
20442
21109
  return newContentByLocale;
@@ -20860,7 +21527,7 @@ var CreateBlockButton = ({ columns, columnIndex, section }) => {
20860
21527
  },
20861
21528
  sx: { ":hover": { backgroundColor: "#EBEBEB" } },
20862
21529
  children: /* @__PURE__ */ jsxs(Group, { spacing: "xs", children: [
20863
- /* @__PURE__ */ jsx(ActionIcon, { color: "blue", variant: "filled", size: "sm", radius: "xl", children: /* @__PURE__ */ jsx(BlockIcon2, { size: "0.8rem" }) }),
21530
+ /* @__PURE__ */ jsx(ThemeIcon, { color: "blue", variant: "filled", size: "sm", radius: "xl", children: /* @__PURE__ */ jsx(BlockIcon2, { size: "0.8rem" }) }),
20864
21531
  /* @__PURE__ */ jsx(Text, { size: "xs", children: getBlockLabel(d2) || d2 })
20865
21532
  ] })
20866
21533
  }
package/dist/server.js CHANGED
@@ -785,7 +785,8 @@ var BLOCK_CONTENT_TYPES = {
785
785
  NAV: "nav",
786
786
  // todo1.0, how to put custom blocks in here?
787
787
  RESET_BUTTON: "reset_button",
788
- COMPARISON_BUTTON: "comparison_button"
788
+ COMPARISON_BUTTON: "comparison_button",
789
+ TABLE: "table"
789
790
  };
790
791
  var BLOCK_LOGIC_TYPES = {
791
792
  GENERATOR: "generator",
@@ -2538,7 +2539,9 @@ function dbReportFactory(db) {
2538
2539
  );
2539
2540
  const entities = await Report.findAll({
2540
2541
  where: idList.length > 0 ? { id: idList } : void 0,
2541
- include: include ? reportQuery.include : void 0
2542
+ include: include ? reportQuery.include?.filter(
2543
+ (i2) => typeof include === "string" ? i2["association"] === include : include
2544
+ ) : void 0
2542
2545
  });
2543
2546
  if (idList.length === 0 || entities.length === idList.length) {
2544
2547
  return entities.map((entity) => {
@@ -2567,7 +2570,6 @@ function dbReportFactory(db) {
2567
2570
  }
2568
2571
  async function updateReport(data) {
2569
2572
  const { id, dimensions, sections, ...reportData } = data;
2570
- console.log(data, "CON DATA");
2571
2573
  const entity = await Report.findByPk(id, {
2572
2574
  include: reportQuery.include,
2573
2575
  rejectOnEmpty: true
@@ -7030,8 +7032,13 @@ function getInstalledPackageVersion(packageName) {
7030
7032
  mainPath.endsWith("/example") ? mainPath.replace("/example", "") : mainPath,
7031
7033
  "package-lock.json"
7032
7034
  );
7033
- const packageLock = JSON.parse(fs.readFileSync(packageLockPath, "utf-8"));
7034
- const version = packageLock.dependencies && packageLock.dependencies[packageName] && packageLock.dependencies[packageName].version !== "file:packages/reports" ? packageLock.dependencies[packageName].version : "0.dev";
7035
+ let version;
7036
+ try {
7037
+ const packageLock = JSON.parse(fs.readFileSync(packageLockPath, "utf-8"));
7038
+ version = packageLock.dependencies && packageLock.dependencies[packageName] && packageLock.dependencies[packageName].version !== "file:packages/reports" ? packageLock.dependencies[packageName].version : "0.dev";
7039
+ } catch {
7040
+ version = "0.vercel";
7041
+ }
7035
7042
  return version || "Version not found";
7036
7043
  }
7037
7044
  function BespokeManagerServerSideProps(options) {
@@ -7045,20 +7052,35 @@ function BespokeManagerServerSideProps(options) {
7045
7052
  getServerSideProps: storeWrapper.getServerSideProps((store) => {
7046
7053
  const { dispatch } = store;
7047
7054
  return async (ctx) => {
7055
+ const firstSegment = ctx.query[pathSegmentsKey];
7056
+ const [page] = Array.isArray(firstSegment) ? firstSegment : [firstSegment];
7048
7057
  await dispatch(useDatabaseApi);
7049
7058
  const bespokeVersion = await getInstalledPackageVersion("@datawheel/bespoke");
7050
7059
  const preResult = await preResolve(store, ctx);
7051
7060
  if ("redirect" in preResult)
7052
7061
  return { props: preResult };
7053
- await Promise.all([
7054
- dispatch(readEntity("formatter", {})),
7055
- dispatch(readEntity("report", {
7056
- id: parseReportId(ctx.query[pathSegmentsKey]),
7057
- include: true
7058
- })),
7059
- // Mark the status as CMS environment
7060
- dispatch(statusActions.setStatus({ isCMS: true }))
7061
- ]);
7062
+ if (page === "reports") {
7063
+ if (parseReportId(ctx.query[pathSegmentsKey])) {
7064
+ await Promise.all([
7065
+ dispatch(readEntity("formatter", {})),
7066
+ dispatch(readEntity("report", {
7067
+ id: parseReportId(ctx.query[pathSegmentsKey]),
7068
+ include: true
7069
+ })),
7070
+ statusActions.setStatus({ isCMS: true })
7071
+ ]);
7072
+ } else {
7073
+ await Promise.all([
7074
+ dispatch(readEntity("report", {
7075
+ include: "dimensions"
7076
+ })),
7077
+ statusActions.setStatus({ isCMS: true })
7078
+ ]);
7079
+ }
7080
+ }
7081
+ if (page === "formatters") {
7082
+ await dispatch(readEntity("formatter", {}));
7083
+ }
7062
7084
  const postResult = await postResolve(store, ctx);
7063
7085
  return {
7064
7086
  props: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datawheel/bespoke",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Content management system for creating automated data reports",
5
5
  "exports": {
6
6
  ".": {