@plasmicpkgs/plasmic-rich-components 1.0.78 → 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,9 +5,8 @@ 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
- var lib = require('@ant-design/pro-utils/lib');
10
- var configProvider = require('antd/es/config-provider');
11
10
  var csvWriterBrowser = require('csv-writer-browser');
12
11
  var fastStringify = require('fast-stringify');
13
12
 
@@ -209,10 +208,11 @@ function buildFieldsPropType(opts) {
209
208
  displayName: displayName,
210
209
  control: control,
211
210
  argNames: ["currentItem", "currentValue"],
212
- argValues: function (_props, ctx) {
213
- var _a;
214
- var row = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.data) === null || _a === void 0 ? void 0 : _a[0];
215
- var cell = _props.fieldId ? row === null || row === void 0 ? void 0 : row[_props.fieldId] : undefined;
211
+ argValues: function (_props, ctx, _a) {
212
+ var _b;
213
+ var item = _a.item;
214
+ var row = (_b = ctx === null || ctx === void 0 ? void 0 : ctx.data) === null || _b === void 0 ? void 0 : _b[0];
215
+ var cell = item.fieldId ? row === null || row === void 0 ? void 0 : row[item.fieldId] : undefined;
216
216
  return [row, cell];
217
217
  },
218
218
  });
@@ -259,7 +259,7 @@ function buildFieldsPropType(opts) {
259
259
  type: "string",
260
260
  displayName: "Title",
261
261
  defaultValueHint: getDefaultValueHint("title"),
262
- }, expr: rowDataType("Customize data"), isHidden: {
262
+ }, expr: rowDataType("Customize cell data"), isHidden: {
263
263
  type: "boolean",
264
264
  displayName: "Is hidden",
265
265
  defaultValueHint: getDefaultValueHint("isHidden"),
@@ -873,7 +873,10 @@ function useColumnDefinitions$1(data, props) {
873
873
  return defaultRender(_);
874
874
  },
875
875
  render: function (value, record, rowIndex) {
876
- return renderValue(value, record, cconfig);
876
+ var cellValue = cconfig.fieldId
877
+ ? record[cconfig.fieldId]
878
+ : undefined;
879
+ return renderValue(cellValue, record, cconfig);
877
880
  },
878
881
  };
879
882
  return columnDefinition;
@@ -950,9 +953,16 @@ function useIsClient() {
950
953
  function capitalize(text) {
951
954
  return text.slice(0, 1).toUpperCase() + text.slice(1);
952
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
+ }
953
960
 
954
- function ensureArray(xs) {
955
- return Array.isArray(xs) ? xs : [xs];
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
+ }));
956
966
  }
957
967
  function RichLayout(_a) {
958
968
  var _b, _c, _d;
@@ -964,19 +974,35 @@ function RichLayout(_a) {
964
974
  setPathname(location.pathname);
965
975
  }
966
976
  }, []);
967
- var _g = React.useContext(configProvider.ConfigContext); _g.locale; var th = _g.theme; __rest(_g, ["locale", "theme"]);
968
977
  var token = antd.theme.useToken().token;
969
- var inDarkMode = ensureArray(th === null || th === void 0 ? void 0 : th.algorithm).includes(antd.theme.darkAlgorithm);
970
- var bgColor = (simpleNavTheme === null || simpleNavTheme === void 0 ? void 0 : simpleNavTheme.scheme) === "accent"
971
- ? token.colorPrimary
972
- : (simpleNavTheme === null || simpleNavTheme === void 0 ? void 0 : simpleNavTheme.scheme) === "dark"
973
- ? // This is the default dark Menu color in Ant.
974
- "#011528"
975
- : inDarkMode
976
- ? // Just use this sorta ugly gray if using 'light' scheme in 'dark' mode....
977
- "rgba(0,0,0,0.6)"
978
- : // Using 'light' scheme in 'light' mode
979
- undefined;
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 : "";
980
1006
  if (!isClient) {
981
1007
  return null;
982
1008
  }
@@ -984,23 +1010,37 @@ function RichLayout(_a) {
984
1010
  React__default.default.createElement("style", null, ".ant-pro-layout-bg-list {\n display: none;\n }"),
985
1011
  React__default.default.createElement(proComponents.ProLayout, __assign({}, layoutProps, {
986
1012
  // Theme just the header. If you simply pass in navTheme=realDark, it affects all main content as well.
987
- headerRender: function (props, defaultDom) { return (React__default.default.createElement(proComponents.ProConfigProvider, { dark: (simpleNavTheme === null || simpleNavTheme === void 0 ? void 0 : simpleNavTheme.scheme) !== "light" }, defaultDom)); }, token: {
988
- header: lib.omitUndefined({
989
- colorBgHeader: bgColor,
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,
990
1030
  }),
991
1031
  // Ideally, we'd do something similar to headerRender above, and just specify general dark mode to specify
992
1032
  // whether all components/text should be light.
993
1033
  // But for some reason it doesn't work, causing the bg color to be ignored (just the default dark Menu color),
994
1034
  // *and* the text is just dark as well.
995
- // Haven't bothered debugging the pro components code to figure out the proper way to do this, so just
996
- // bluntly specifying tokens here.
997
- sider: !inDarkMode && (simpleNavTheme === null || simpleNavTheme === void 0 ? void 0 : simpleNavTheme.scheme) === "light"
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
998
1038
  ? undefined
999
1039
  : {
1000
- colorBgCollapsedButton: "#fff",
1001
- colorTextCollapsedButtonHover: "rgba(0,0,0,0.65)",
1002
- colorTextCollapsedButton: "rgba(0,0,0,0.45)",
1003
- colorMenuBackground: bgColor,
1040
+ colorBgCollapsedButton: navBgColor,
1041
+ colorTextCollapsedButtonHover: "rgba(255,255,255,0.85)",
1042
+ colorTextCollapsedButton: "rgba(255,255,255,0.65)",
1043
+ colorMenuBackground: navBgColor,
1004
1044
  colorBgMenuItemCollapsedHover: "rgba(0,0,0,0.06)",
1005
1045
  colorBgMenuItemCollapsedSelected: "rgba(0,0,0,0.15)",
1006
1046
  colorBgMenuItemCollapsedElevated: "rgba(0,0,0,0.85)",
@@ -1032,7 +1072,7 @@ function RichLayout(_a) {
1032
1072
  // collapsedShowGroupTitle: true,
1033
1073
  defaultOpenAll: true,
1034
1074
  // hideMenuWhenCollapsed: true,
1035
- }, avatarProps: showAvatarMenu && 0 / 1
1075
+ }, avatarProps: showAvatarMenu
1036
1076
  ? {
1037
1077
  src: avatarImage,
1038
1078
  size: "small",
@@ -1072,7 +1112,7 @@ function generateNavMenuType(remainingDepth, displayName, defaultValue) {
1072
1112
  nameFunc: function (item) {
1073
1113
  return item.name || (!displayName ? "Unnamed nested item" : "Unnamed item");
1074
1114
  },
1075
- fields: __assign({ path: "string", name: "string" }, (remainingDepth === 0
1115
+ fields: __assign({ path: "href", name: "string" }, (remainingDepth === 0
1076
1116
  ? {}
1077
1117
  : {
1078
1118
  routes: generateNavMenuType(remainingDepth - 1),
@@ -1082,7 +1122,7 @@ function generateNavMenuType(remainingDepth, displayName, defaultValue) {
1082
1122
  }
1083
1123
  var richLayoutMeta = {
1084
1124
  name: "hostless-rich-layout",
1085
- displayName: "Rich Page Layout",
1125
+ displayName: "Rich App Layout",
1086
1126
  props: {
1087
1127
  children: {
1088
1128
  type: "slot",
@@ -1123,16 +1163,21 @@ var richLayoutMeta = {
1123
1163
  },
1124
1164
  simpleNavTheme: {
1125
1165
  displayName: "Theme",
1126
- advanced: true,
1127
1166
  type: "object",
1128
1167
  fields: {
1129
1168
  scheme: {
1130
1169
  type: "choice",
1131
- options: ["light", "accent", "dark"].map(function (v) { return ({
1170
+ options: ["default", "primary", "light", "dark", "custom"].map(function (v) { return ({
1132
1171
  label: capitalize(v),
1133
1172
  value: v,
1134
1173
  }); }),
1135
- defaultValue: "accent",
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",
1136
1181
  },
1137
1182
  },
1138
1183
  },
@@ -1202,6 +1247,7 @@ var richLayoutMeta = {
1202
1247
  defaultStyles: {
1203
1248
  width: "full-bleed",
1204
1249
  height: "stretch",
1250
+ minHeight: "100vh",
1205
1251
  },
1206
1252
  importName: "RichLayout",
1207
1253
  importPath: "@plasmicpkgs/plasmic-rich-components",
@@ -1360,7 +1406,10 @@ function useColumnDefinitions(data, props) {
1360
1406
  return defaultRender(_);
1361
1407
  },
1362
1408
  render: function (value, record, rowIndex) {
1363
- return renderValue(value, record, cconfig);
1409
+ var cellValue = cconfig.fieldId
1410
+ ? record[cconfig.fieldId]
1411
+ : undefined;
1412
+ return renderValue(cellValue, record, cconfig);
1364
1413
  },
1365
1414
  };
1366
1415
  return columnDefinition;