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