@plasmicpkgs/plasmic-rich-components 1.0.79 → 1.0.80

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/common.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export declare function useIsClient(): boolean;
2
2
  export declare function capitalize(text: string): string;
3
+ export declare function isLight(color: string): boolean;
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ require('@plasmicapp/host/registerGlobalContext');
5
5
  var proComponents = require('@ant-design/pro-components');
6
6
  var React = require('react');
7
7
  var antd = require('antd');
8
+ var tinycolor = require('@ctrl/tinycolor');
8
9
  var icons = require('@ant-design/icons');
9
10
  var csvWriterBrowser = require('csv-writer-browser');
10
11
  var fastStringify = require('fast-stringify');
@@ -952,10 +953,20 @@ function useIsClient() {
952
953
  function capitalize(text) {
953
954
  return text.slice(0, 1).toUpperCase() + text.slice(1);
954
955
  }
956
+ function isLight(color) {
957
+ var _a = tinycolor.tinycolor(color).toRgb(), r = _a.r, g = _a.g, b = _a.b;
958
+ return r * 0.299 + g * 0.587 + b * 0.114 > 186;
959
+ }
955
960
 
961
+ function omitUndefined(x) {
962
+ return Object.fromEntries(Object.entries(x).filter(function (_a) {
963
+ _a[0]; var v = _a[1];
964
+ return v !== undefined;
965
+ }));
966
+ }
956
967
  function RichLayout(_a) {
957
968
  var _b, _c, _d;
958
- 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"]);
969
+ 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"]);
959
970
  var isClient = useIsClient();
960
971
  var _f = React.useState(undefined), pathname = _f[0], setPathname = _f[1];
961
972
  React.useEffect(function () {
@@ -963,12 +974,88 @@ function RichLayout(_a) {
963
974
  setPathname(location.pathname);
964
975
  }
965
976
  }, []);
977
+ var token = antd.theme.useToken().token;
978
+ var origTextColor = token.colorTextBase;
979
+ function getNavBgColor() {
980
+ var _a, _b;
981
+ var scheme = (_a = simpleNavTheme === null || simpleNavTheme === void 0 ? void 0 : simpleNavTheme.scheme) !== null && _a !== void 0 ? _a : "default";
982
+ switch (scheme) {
983
+ case "primary":
984
+ return token.colorPrimary;
985
+ case "dark":
986
+ // Ant default dark blue Menu color.
987
+ return "#011528";
988
+ case "custom":
989
+ return (_b = simpleNavTheme === null || simpleNavTheme === void 0 ? void 0 : simpleNavTheme.customBgColor) !== null && _b !== void 0 ? _b : token.colorBgBase;
990
+ case "light":
991
+ // Just use this sorta ugly gray if using 'light' scheme in 'dark' mode.
992
+ // Otherwise using light scheme in light mode.
993
+ return "#fff";
994
+ case "default":
995
+ return token.colorBgBase || "#fff";
996
+ }
997
+ }
998
+ var navBgColor = getNavBgColor();
999
+ // Dynamically determine whether we need to change the text to black/white or not, based on background color.
1000
+ // We don't want light-on-light or dark-on-dark, so if both isNavBgLight and isOrigTextLight are the same, then need to change.
1001
+ // If no need to change, we leave text color as is.
1002
+ var isNavBgLight = isLight(navBgColor);
1003
+ var isOrigTextLight = isLight(origTextColor);
1004
+ // Ant will interpret "" as defaulting to "#fff" for dark mode and "#000" in light mode.
1005
+ var navTextColor = isNavBgLight !== isOrigTextLight ? undefined : "";
966
1006
  if (!isClient) {
967
1007
  return null;
968
1008
  }
969
1009
  return (React__default.default.createElement("div", { className: className },
970
1010
  React__default.default.createElement("style", null, ".ant-pro-layout-bg-list {\n display: none;\n }"),
971
1011
  React__default.default.createElement(proComponents.ProLayout, __assign({}, layoutProps, {
1012
+ // Theme just the header. If you simply pass in navTheme=realDark, it affects all main content as well.
1013
+ //
1014
+ // What we're doing is telling Ant to use the dark mode algorithm. However, dark mode algorithm doesn't change
1015
+ // the seed tokens for colorTextBase and colorBgBase - it only fills in #fff and #000 for these if they are
1016
+ // unset (""). So that's why further up we may be setting the text color to "".
1017
+ //
1018
+ // I think it doesn't matter too much what is the colorBgBase, since we are setting (Pro-specific) `tokens`
1019
+ // further down for actually setting the fill of the nav sections. What matters is the text color - if we're
1020
+ // showing a dark background, then we want the text to be white.
1021
+ //
1022
+ // We could specify darkAlgorithm to ConfigProvider, but IIRC Pro might be setting some of its own tokens
1023
+ // based on whether dark is being specified to the ProConfigProvider. So that's why we need that.
1024
+ //
1025
+ // ProConfigProvider does first read/inherit the theme/tokens from the surrounding ConfigProvider.
1026
+ headerRender: function (_props, defaultDom) { return (React__default.default.createElement(antd.ConfigProvider, { theme: { token: omitUndefined({ colorTextBase: navTextColor }) } },
1027
+ React__default.default.createElement(proComponents.ProConfigProvider, { dark: !isNavBgLight }, defaultDom))); }, token: {
1028
+ header: omitUndefined({
1029
+ colorBgHeader: navBgColor,
1030
+ }),
1031
+ // Ideally, we'd do something similar to headerRender above, and just specify general dark mode to specify
1032
+ // whether all components/text should be light.
1033
+ // But for some reason it doesn't work, causing the bg color to be ignored (just the default dark Menu color),
1034
+ // *and* the text is just dark as well.
1035
+ // Haven't yet been able to unravel the pro components code to figure out the proper way to do this, so just
1036
+ // bluntly specifying tokens here, as recommended in some GitHub issue.
1037
+ sider: isNavBgLight
1038
+ ? undefined
1039
+ : {
1040
+ colorBgCollapsedButton: navBgColor,
1041
+ colorTextCollapsedButtonHover: "rgba(255,255,255,0.85)",
1042
+ colorTextCollapsedButton: "rgba(255,255,255,0.65)",
1043
+ colorMenuBackground: navBgColor,
1044
+ colorBgMenuItemCollapsedHover: "rgba(0,0,0,0.06)",
1045
+ colorBgMenuItemCollapsedSelected: "rgba(0,0,0,0.15)",
1046
+ colorBgMenuItemCollapsedElevated: "rgba(0,0,0,0.85)",
1047
+ colorMenuItemDivider: "rgba(255,255,255,0.15)",
1048
+ colorBgMenuItemHover: "rgba(0,0,0,0.06)",
1049
+ colorBgMenuItemSelected: "rgba(0,0,0,0.15)",
1050
+ colorTextMenuSelected: "#fff",
1051
+ colorTextMenuItemHover: "rgba(255,255,255,0.75)",
1052
+ colorTextMenu: "rgba(255,255,255,0.75)",
1053
+ colorTextMenuSecondary: "rgba(255,255,255,0.65)",
1054
+ colorTextMenuTitle: "rgba(255,255,255,0.95)",
1055
+ colorTextMenuActive: "rgba(255,255,255,0.95)",
1056
+ colorTextSubMenuSelected: "#fff",
1057
+ },
1058
+ },
972
1059
  // Tweak defaults. ProLayout is janky and has terrible docs!
973
1060
  layout: (_b = layoutProps.layout) !== null && _b !== void 0 ? _b : "top", fixedHeader: (_c = layoutProps.fixedHeader) !== null && _c !== void 0 ? _c : false, fixSiderbar:
974
1061
  // Doesn't stretch full height if you set this to false and you're in mix mode.
@@ -985,7 +1072,7 @@ function RichLayout(_a) {
985
1072
  // collapsedShowGroupTitle: true,
986
1073
  defaultOpenAll: true,
987
1074
  // hideMenuWhenCollapsed: true,
988
- }, avatarProps: showAvatarMenu && false
1075
+ }, avatarProps: showAvatarMenu
989
1076
  ? {
990
1077
  src: avatarImage,
991
1078
  size: "small",
@@ -1035,7 +1122,7 @@ function generateNavMenuType(remainingDepth, displayName, defaultValue) {
1035
1122
  }
1036
1123
  var richLayoutMeta = {
1037
1124
  name: "hostless-rich-layout",
1038
- displayName: "Rich Page Layout",
1125
+ displayName: "Rich App Layout",
1039
1126
  props: {
1040
1127
  children: {
1041
1128
  type: "slot",
@@ -1074,6 +1161,26 @@ var richLayoutMeta = {
1074
1161
  }); }),
1075
1162
  defaultValueHint: "top",
1076
1163
  },
1164
+ simpleNavTheme: {
1165
+ displayName: "Theme",
1166
+ type: "object",
1167
+ fields: {
1168
+ scheme: {
1169
+ type: "choice",
1170
+ options: ["default", "primary", "light", "dark", "custom"].map(function (v) { return ({
1171
+ label: capitalize(v),
1172
+ value: v,
1173
+ }); }),
1174
+ defaultValueHint: "default",
1175
+ },
1176
+ customBgColor: {
1177
+ type: "color",
1178
+ displayName: "Custom color",
1179
+ hidden: function (props) { var _a; return !(((_a = props.simpleNavTheme) === null || _a === void 0 ? void 0 : _a.scheme) === "custom"); },
1180
+ defaultValue: "#D73B58",
1181
+ },
1182
+ },
1183
+ },
1077
1184
  // Advanced, show later
1078
1185
  /*
1079
1186
  siderMenuType: {
@@ -1091,18 +1198,6 @@ var richLayoutMeta = {
1091
1198
  options: ["Fluid", "Fixed"],
1092
1199
  defaultValueHint: "Fluid",
1093
1200
  },
1094
- navTheme: {
1095
- displayName: "Theme",
1096
- type: "choice",
1097
- options: [
1098
- { value: "realDark", label: "Dark" },
1099
- { value: "light", label: "Light" },
1100
- ],
1101
- },
1102
- colorPrimary: {
1103
- displayName: "Primary color",
1104
- type: "color",
1105
- },
1106
1201
  */
1107
1202
  fixedHeader: {
1108
1203
  displayName: "Sticky header",
@@ -1152,6 +1247,7 @@ var richLayoutMeta = {
1152
1247
  defaultStyles: {
1153
1248
  width: "full-bleed",
1154
1249
  height: "stretch",
1250
+ minHeight: "100vh",
1155
1251
  },
1156
1252
  importName: "RichLayout",
1157
1253
  importPath: "@plasmicpkgs/plasmic-rich-components",