@plasmicapp/react-web 0.2.228 → 0.2.230

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/all.d.ts CHANGED
@@ -24,6 +24,7 @@ interface PlasmicPageGuardProps {
24
24
  minRole?: string;
25
25
  canTriggerLogin: boolean;
26
26
  children: React__default.ReactNode;
27
+ unauthorizedComp?: React__default.ReactNode;
27
28
  }
28
29
  declare function PlasmicPageGuard(props: PlasmicPageGuardProps): JSX.Element | null;
29
30
  declare function withPlasmicPageGuard<P extends object>(WrappedComponent: React__default.ComponentType<P>, options: Omit<PlasmicPageGuardProps, "children">): React__default.FC<P>;
@@ -5,6 +5,7 @@ interface PlasmicPageGuardProps {
5
5
  minRole?: string;
6
6
  canTriggerLogin: boolean;
7
7
  children: React.ReactNode;
8
+ unauthorizedComp?: React.ReactNode;
8
9
  }
9
10
  export declare function PlasmicPageGuard(props: PlasmicPageGuardProps): JSX.Element | null;
10
11
  export declare function withPlasmicPageGuard<P extends object>(WrappedComponent: React.ComponentType<P>, options: Omit<PlasmicPageGuardProps, "children">): React.FC<P>;
package/dist/index.cjs.js CHANGED
@@ -249,7 +249,7 @@ function triggerLogin(appId, authorizeEndpoint, redirectUri) {
249
249
  });
250
250
  }
251
251
  function PlasmicPageGuard(props) {
252
- var appId = props.appId, authorizeEndpoint = props.authorizeEndpoint, minRole = props.minRole, canTriggerLogin = props.canTriggerLogin, children = props.children;
252
+ var appId = props.appId, authorizeEndpoint = props.authorizeEndpoint, minRole = props.minRole, canTriggerLogin = props.canTriggerLogin, children = props.children, unauthorizedComp = props.unauthorizedComp;
253
253
  var dataSourceCtxValue = dataSourcesContext.usePlasmicDataSourceContext();
254
254
  React__default['default'].useEffect(function () {
255
255
  if (canTriggerLogin) {
@@ -280,12 +280,24 @@ function PlasmicPageGuard(props) {
280
280
  }
281
281
  return dataSourceCtxValue.user.roleIds.includes(minRole);
282
282
  }
283
+ /*
284
+ PlasmicPageGuard has three cases:
285
+ 1. No value of dataSourceCtxValue, user is loading or a trigger login should be performed.
286
+ In this case, we don't want to render the children or the access denied message.
287
+ While the user is loading we look to see if don't have a user value as we can be in a
288
+ revalidate state.
289
+ 2. The user doesn't have access to the page in which we show an access denied message.
290
+ 3. The user has access to the page in which we render the children.
291
+ */
283
292
  if (!dataSourceCtxValue ||
284
- dataSourceCtxValue.isUserLoading ||
293
+ (dataSourceCtxValue.isUserLoading && !dataSourceCtxValue.user) ||
285
294
  (!dataSourceCtxValue.user && minRole && canTriggerLogin)) {
286
295
  return null;
287
296
  }
288
297
  if (!canUserViewPage()) {
298
+ if (unauthorizedComp) {
299
+ return React__default['default'].createElement(React__default['default'].Fragment, null, unauthorizedComp);
300
+ }
289
301
  return React__default['default'].createElement("div", null, "You don't have access to this page");
290
302
  }
291
303
  return React__default['default'].createElement(React__default['default'].Fragment, null, children);
@@ -1675,7 +1687,19 @@ function PlasmicRootProvider(props) {
1675
1687
  React__namespace.createElement(dataSourcesContext.PlasmicDataSourceContextProvider, { value: dataSourceContextValue },
1676
1688
  React__namespace.createElement(PlasmicTranslatorContext.Provider, { value: (_a = props.i18n) !== null && _a !== void 0 ? _a : props.translator },
1677
1689
  React__namespace.createElement(PlasmicHeadContext.Provider, { value: props.Head },
1678
- React__namespace.createElement(host.PlasmicLinkProvider, { Link: (_b = props.Link) !== null && _b !== void 0 ? _b : PlasmicLinkInternal }, children))))))));
1690
+ React__namespace.createElement(SafePlasmicLinkProvider, { Link: (_b = props.Link) !== null && _b !== void 0 ? _b : PlasmicLinkInternal }, children))))))));
1691
+ }
1692
+ /**
1693
+ * A PlasmicLinkProvider that anticipates PlasmicLinkProvider may not exist yet from
1694
+ * @plasmicapp/host if the user is using an older version
1695
+ */
1696
+ function SafePlasmicLinkProvider(props) {
1697
+ if (host.PlasmicLinkProvider) {
1698
+ return React__namespace.createElement(host.PlasmicLinkProvider, __assign({}, props));
1699
+ }
1700
+ else {
1701
+ return React__namespace.createElement(React__namespace.Fragment, null, props.children);
1702
+ }
1679
1703
  }
1680
1704
  var useIsSSR = ssr.useIsSSR;
1681
1705
  function useHasPlasmicRoot() {