@plasmicpkgs/plasmic-rich-components 1.0.79 → 1.0.81

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.
@@ -1,8 +1,9 @@
1
1
  import registerComponent from '@plasmicapp/host/registerComponent';
2
2
  import '@plasmicapp/host/registerGlobalContext';
3
- import { ProDescriptions, ProLayout, ProTable, TableDropdown } from '@ant-design/pro-components';
3
+ import { ProDescriptions, ProLayout, ProConfigProvider, ProTable, TableDropdown } from '@ant-design/pro-components';
4
4
  import React, { useState, useEffect, useRef } from 'react';
5
- import { Checkbox, Switch, Empty, Dropdown, Button } from 'antd';
5
+ import { Checkbox, Switch, Empty, theme, ConfigProvider, Dropdown, Button } from 'antd';
6
+ import { tinycolor } from '@ctrl/tinycolor';
6
7
  import { LogoutOutlined, PlusOutlined, EllipsisOutlined } from '@ant-design/icons';
7
8
  import { createObjectCsvStringifier } from 'csv-writer-browser';
8
9
  import fastStringify from 'fast-stringify';
@@ -185,9 +186,10 @@ function deriveValueType(cconfig) {
185
186
  }
186
187
  function buildFieldsPropType(opts) {
187
188
  function getDefaultValueHint(field) {
188
- return function (_item, contextData) {
189
- if (_item.fieldId) {
190
- var fieldSetting = contextData === null || contextData === void 0 ? void 0 : contextData.mergedFields.find(function (f) { return f.fieldId === _item.fieldId; });
189
+ return function (_props, contextData, _a) {
190
+ var item = _a.item;
191
+ if (item.fieldId) {
192
+ var fieldSetting = contextData === null || contextData === void 0 ? void 0 : contextData.mergedFields.find(function (f) { return f.fieldId === item.fieldId; });
191
193
  return fieldSetting === null || fieldSetting === void 0 ? void 0 : fieldSetting[field];
192
194
  }
193
195
  return undefined;
@@ -944,10 +946,20 @@ function useIsClient() {
944
946
  function capitalize(text) {
945
947
  return text.slice(0, 1).toUpperCase() + text.slice(1);
946
948
  }
949
+ function isLight(color) {
950
+ var _a = tinycolor(color).toRgb(), r = _a.r, g = _a.g, b = _a.b;
951
+ return r * 0.299 + g * 0.587 + b * 0.114 > 186;
952
+ }
947
953
 
954
+ function omitUndefined(x) {
955
+ return Object.fromEntries(Object.entries(x).filter(function (_a) {
956
+ _a[0]; var v = _a[1];
957
+ return v !== undefined;
958
+ }));
959
+ }
948
960
  function RichLayout(_a) {
949
961
  var _b, _c, _d;
950
- var children = _a.children, navMenuItems = _a.navMenuItems, _e = _a.rootUrl, rootUrl = _e === void 0 ? "/" : _e, actionsChildren = _a.actionsChildren, footerChildren = _a.footerChildren, avatarLabel = _a.avatarLabel, avatarImage = _a.avatarImage, showAvatarMenu = _a.showAvatarMenu, className = _a.className, layoutProps = __rest(_a, ["children", "navMenuItems", "rootUrl", "actionsChildren", "footerChildren", "avatarLabel", "avatarImage", "showAvatarMenu", "className"]);
962
+ var children = _a.children, navMenuItems = _a.navMenuItems, _e = _a.rootUrl, rootUrl = _e === void 0 ? "/" : _e, actionsChildren = _a.actionsChildren, footerChildren = _a.footerChildren, avatarLabel = _a.avatarLabel, avatarImage = _a.avatarImage, showAvatarMenu = _a.showAvatarMenu, className = _a.className, simpleNavTheme = _a.simpleNavTheme, layoutProps = __rest(_a, ["children", "navMenuItems", "rootUrl", "actionsChildren", "footerChildren", "avatarLabel", "avatarImage", "showAvatarMenu", "className", "simpleNavTheme"]);
951
963
  var isClient = useIsClient();
952
964
  var _f = useState(undefined), pathname = _f[0], setPathname = _f[1];
953
965
  useEffect(function () {
@@ -955,12 +967,88 @@ function RichLayout(_a) {
955
967
  setPathname(location.pathname);
956
968
  }
957
969
  }, []);
970
+ var token = theme.useToken().token;
971
+ var origTextColor = token.colorTextBase;
972
+ function getNavBgColor() {
973
+ var _a, _b;
974
+ var scheme = (_a = simpleNavTheme === null || simpleNavTheme === void 0 ? void 0 : simpleNavTheme.scheme) !== null && _a !== void 0 ? _a : "default";
975
+ switch (scheme) {
976
+ case "primary":
977
+ return token.colorPrimary;
978
+ case "dark":
979
+ // Ant default dark blue Menu color.
980
+ return "#011528";
981
+ case "custom":
982
+ return (_b = simpleNavTheme === null || simpleNavTheme === void 0 ? void 0 : simpleNavTheme.customBgColor) !== null && _b !== void 0 ? _b : token.colorBgBase;
983
+ case "light":
984
+ // Just use this sorta ugly gray if using 'light' scheme in 'dark' mode.
985
+ // Otherwise using light scheme in light mode.
986
+ return "#fff";
987
+ case "default":
988
+ return token.colorBgBase || "#fff";
989
+ }
990
+ }
991
+ var navBgColor = getNavBgColor();
992
+ // Dynamically determine whether we need to change the text to black/white or not, based on background color.
993
+ // We don't want light-on-light or dark-on-dark, so if both isNavBgLight and isOrigTextLight are the same, then need to change.
994
+ // If no need to change, we leave text color as is.
995
+ var isNavBgLight = isLight(navBgColor);
996
+ var isOrigTextLight = isLight(origTextColor);
997
+ // Ant will interpret "" as defaulting to "#fff" for dark mode and "#000" in light mode.
998
+ var navTextColor = isNavBgLight !== isOrigTextLight ? undefined : "";
958
999
  if (!isClient) {
959
1000
  return null;
960
1001
  }
961
1002
  return (React.createElement("div", { className: className },
962
1003
  React.createElement("style", null, ".ant-pro-layout-bg-list {\n display: none;\n }"),
963
1004
  React.createElement(ProLayout, __assign({}, layoutProps, {
1005
+ // Theme just the header. If you simply pass in navTheme=realDark, it affects all main content as well.
1006
+ //
1007
+ // What we're doing is telling Ant to use the dark mode algorithm. However, dark mode algorithm doesn't change
1008
+ // the seed tokens for colorTextBase and colorBgBase - it only fills in #fff and #000 for these if they are
1009
+ // unset (""). So that's why further up we may be setting the text color to "".
1010
+ //
1011
+ // I think it doesn't matter too much what is the colorBgBase, since we are setting (Pro-specific) `tokens`
1012
+ // further down for actually setting the fill of the nav sections. What matters is the text color - if we're
1013
+ // showing a dark background, then we want the text to be white.
1014
+ //
1015
+ // We could specify darkAlgorithm to ConfigProvider, but IIRC Pro might be setting some of its own tokens
1016
+ // based on whether dark is being specified to the ProConfigProvider. So that's why we need that.
1017
+ //
1018
+ // ProConfigProvider does first read/inherit the theme/tokens from the surrounding ConfigProvider.
1019
+ headerRender: function (_props, defaultDom) { return (React.createElement(ConfigProvider, { theme: { token: omitUndefined({ colorTextBase: navTextColor }) } },
1020
+ React.createElement(ProConfigProvider, { dark: !isNavBgLight }, defaultDom))); }, token: {
1021
+ header: omitUndefined({
1022
+ colorBgHeader: navBgColor,
1023
+ }),
1024
+ // Ideally, we'd do something similar to headerRender above, and just specify general dark mode to specify
1025
+ // whether all components/text should be light.
1026
+ // But for some reason it doesn't work, causing the bg color to be ignored (just the default dark Menu color),
1027
+ // *and* the text is just dark as well.
1028
+ // Haven't yet been able to unravel the pro components code to figure out the proper way to do this, so just
1029
+ // bluntly specifying tokens here, as recommended in some GitHub issue.
1030
+ sider: isNavBgLight
1031
+ ? undefined
1032
+ : {
1033
+ colorBgCollapsedButton: navBgColor,
1034
+ colorTextCollapsedButtonHover: "rgba(255,255,255,0.85)",
1035
+ colorTextCollapsedButton: "rgba(255,255,255,0.65)",
1036
+ colorMenuBackground: navBgColor,
1037
+ colorBgMenuItemCollapsedHover: "rgba(0,0,0,0.06)",
1038
+ colorBgMenuItemCollapsedSelected: "rgba(0,0,0,0.15)",
1039
+ colorBgMenuItemCollapsedElevated: "rgba(0,0,0,0.85)",
1040
+ colorMenuItemDivider: "rgba(255,255,255,0.15)",
1041
+ colorBgMenuItemHover: "rgba(0,0,0,0.06)",
1042
+ colorBgMenuItemSelected: "rgba(0,0,0,0.15)",
1043
+ colorTextMenuSelected: "#fff",
1044
+ colorTextMenuItemHover: "rgba(255,255,255,0.75)",
1045
+ colorTextMenu: "rgba(255,255,255,0.75)",
1046
+ colorTextMenuSecondary: "rgba(255,255,255,0.65)",
1047
+ colorTextMenuTitle: "rgba(255,255,255,0.95)",
1048
+ colorTextMenuActive: "rgba(255,255,255,0.95)",
1049
+ colorTextSubMenuSelected: "#fff",
1050
+ },
1051
+ },
964
1052
  // Tweak defaults. ProLayout is janky and has terrible docs!
965
1053
  layout: (_b = layoutProps.layout) !== null && _b !== void 0 ? _b : "top", fixedHeader: (_c = layoutProps.fixedHeader) !== null && _c !== void 0 ? _c : false, fixSiderbar:
966
1054
  // Doesn't stretch full height if you set this to false and you're in mix mode.
@@ -977,7 +1065,7 @@ function RichLayout(_a) {
977
1065
  // collapsedShowGroupTitle: true,
978
1066
  defaultOpenAll: true,
979
1067
  // hideMenuWhenCollapsed: true,
980
- }, avatarProps: showAvatarMenu && false
1068
+ }, avatarProps: showAvatarMenu
981
1069
  ? {
982
1070
  src: avatarImage,
983
1071
  size: "small",
@@ -1027,7 +1115,7 @@ function generateNavMenuType(remainingDepth, displayName, defaultValue) {
1027
1115
  }
1028
1116
  var richLayoutMeta = {
1029
1117
  name: "hostless-rich-layout",
1030
- displayName: "Rich Page Layout",
1118
+ displayName: "Rich App Layout",
1031
1119
  props: {
1032
1120
  children: {
1033
1121
  type: "slot",
@@ -1066,6 +1154,26 @@ var richLayoutMeta = {
1066
1154
  }); }),
1067
1155
  defaultValueHint: "top",
1068
1156
  },
1157
+ simpleNavTheme: {
1158
+ displayName: "Theme",
1159
+ type: "object",
1160
+ fields: {
1161
+ scheme: {
1162
+ type: "choice",
1163
+ options: ["default", "primary", "light", "dark", "custom"].map(function (v) { return ({
1164
+ label: capitalize(v),
1165
+ value: v,
1166
+ }); }),
1167
+ defaultValueHint: "default",
1168
+ },
1169
+ customBgColor: {
1170
+ type: "color",
1171
+ displayName: "Custom color",
1172
+ hidden: function (props) { var _a; return !(((_a = props.simpleNavTheme) === null || _a === void 0 ? void 0 : _a.scheme) === "custom"); },
1173
+ defaultValue: "#D73B58",
1174
+ },
1175
+ },
1176
+ },
1069
1177
  // Advanced, show later
1070
1178
  /*
1071
1179
  siderMenuType: {
@@ -1083,18 +1191,6 @@ var richLayoutMeta = {
1083
1191
  options: ["Fluid", "Fixed"],
1084
1192
  defaultValueHint: "Fluid",
1085
1193
  },
1086
- navTheme: {
1087
- displayName: "Theme",
1088
- type: "choice",
1089
- options: [
1090
- { value: "realDark", label: "Dark" },
1091
- { value: "light", label: "Light" },
1092
- ],
1093
- },
1094
- colorPrimary: {
1095
- displayName: "Primary color",
1096
- type: "color",
1097
- },
1098
1194
  */
1099
1195
  fixedHeader: {
1100
1196
  displayName: "Sticky header",
@@ -1144,6 +1240,7 @@ var richLayoutMeta = {
1144
1240
  defaultStyles: {
1145
1241
  width: "full-bleed",
1146
1242
  height: "stretch",
1243
+ minHeight: "100vh",
1147
1244
  },
1148
1245
  importName: "RichLayout",
1149
1246
  importPath: "@plasmicpkgs/plasmic-rich-components",
@@ -1559,7 +1656,10 @@ var dataTableMeta = {
1559
1656
  displayName: "Row key",
1560
1657
  helpText: "Column key to use as row key; can also be a function that takes in a row and returns a key value",
1561
1658
  hidden: function (ps) { return !ps.canSelectRows || ps.canSelectRows === "none"; },
1562
- defaultValueHint: function (ps) { return deriveRowKey(ps.data, ps.rowKey); },
1659
+ defaultValueHint: function (ps) {
1660
+ var derivedRowKey = deriveRowKey(ps.data, ps.rowKey);
1661
+ return derivedRowKey !== undefined ? "".concat(derivedRowKey) : undefined;
1662
+ },
1563
1663
  },
1564
1664
  selectedRowKey: {
1565
1665
  type: "string",