@plasmicapp/react-web 0.2.396 → 0.2.398
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 +344 -184
- package/dist/index-common.d.ts +4 -3
- package/dist/index.cjs.js +1061 -898
- package/dist/index.cjs.js.map +1 -1
- package/dist/react-web.esm.js +1059 -899
- package/dist/react-web.esm.js.map +1 -1
- package/dist/render/elements.d.ts +1 -1
- package/dist/render/global-variants.d.ts +49 -1
- package/dist/render/style-tokens.d.ts +114 -0
- package/package.json +9 -9
- package/skinny/dist/index-common.d.ts +4 -3
- package/skinny/dist/index.js +256 -96
- package/skinny/dist/index.js.map +1 -1
- package/skinny/dist/render/elements.d.ts +1 -1
- package/skinny/dist/render/global-variants.d.ts +49 -1
- package/skinny/dist/render/style-tokens.d.ts +114 -0
|
@@ -41,7 +41,7 @@ export type Flex<DefaultElementType extends React.ElementType> = (Omit<DefaultOv
|
|
|
41
41
|
as?: never;
|
|
42
42
|
render?: never;
|
|
43
43
|
}) | ((props: React.ComponentProps<DefaultElementType>) => React.ReactNode);
|
|
44
|
-
export declare function hasVariant<V extends Variants>(variants: V | undefined, groupName: keyof V, variant: string):
|
|
44
|
+
export declare function hasVariant<V extends Variants>(variants: V | undefined, groupName: keyof V, variant: string): boolean;
|
|
45
45
|
export declare function wrapFlexContainerChildren(children: React.ReactNode, hasGap: boolean): React.DetailedReactHTMLElement<{
|
|
46
46
|
className: string;
|
|
47
47
|
}, HTMLElement> | null;
|
|
@@ -1 +1,49 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type GlobalVariants = {
|
|
2
|
+
[gv: string]: string | undefined;
|
|
3
|
+
};
|
|
4
|
+
export type UseGlobalVariants = () => GlobalVariants;
|
|
5
|
+
/**
|
|
6
|
+
* Usage:
|
|
7
|
+
* ```
|
|
8
|
+
* // plasmic.ts
|
|
9
|
+
* import { usePlatform } from "./PlasmicGlobalVariant__Platform";
|
|
10
|
+
* import { useTheme } from "./PlasmicGlobalVariant__Theme";
|
|
11
|
+
*
|
|
12
|
+
* export const useGlobalVariants = createUseGlobalVariants({
|
|
13
|
+
* platform: usePlatform,
|
|
14
|
+
* theme: useTheme,
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // PlasmicComponent.tsx
|
|
18
|
+
* import { useGlobalVariants } from "./plasmic_project";
|
|
19
|
+
*
|
|
20
|
+
* export function PlasmicComponent() {
|
|
21
|
+
* // ...
|
|
22
|
+
* const globalVariants = useGlobalVariants();
|
|
23
|
+
* // ...
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare function createUseGlobalVariants<T extends {
|
|
28
|
+
[gv: string]: () => string | undefined;
|
|
29
|
+
}>(globalVariantHooks: T): UseGlobalVariants;
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated - new generated code should use `useGlobalVariants` instead
|
|
32
|
+
*
|
|
33
|
+
* Usage:
|
|
34
|
+
* ```
|
|
35
|
+
* // PlasmicComponent.tsx
|
|
36
|
+
* import { useTheme } from "./PlasmicGlobalVariant__Theme";
|
|
37
|
+
* import { usePlatform } from "./PlasmicGlobalVariant__Platform";
|
|
38
|
+
*
|
|
39
|
+
* export function PlasmicComponent() {
|
|
40
|
+
* // ...
|
|
41
|
+
* const globalVariants = ensureGlobalVariants({
|
|
42
|
+
* platform: usePlatform(),
|
|
43
|
+
* theme: useTheme(),
|
|
44
|
+
* });
|
|
45
|
+
* // ...
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function ensureGlobalVariants<T extends GlobalVariants>(globalVariants: T): GlobalVariants;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { UseGlobalVariants } from "./global-variants";
|
|
3
|
+
type ClassName = string;
|
|
4
|
+
/**
|
|
5
|
+
* All style token data for this project.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
*
|
|
9
|
+
* ```
|
|
10
|
+
* // PlasmicStyleTokensProvider.ts
|
|
11
|
+
* import { usePlatform } from "./PlasmicGlobalVariant__Platform";
|
|
12
|
+
* import { useTheme } from "./PlasmicGlobalVariant__Theme";
|
|
13
|
+
* import projectcss from "./plasmic.module.css";
|
|
14
|
+
*
|
|
15
|
+
* const projectStyleTokenData: ProjectStyleTokenData = {
|
|
16
|
+
* base: projectcss.plasmic_tokens,
|
|
17
|
+
* varianted: [
|
|
18
|
+
* {
|
|
19
|
+
* className: projectcss.global_platform_windows,
|
|
20
|
+
* groupName: "platform",
|
|
21
|
+
* variant: "windows"
|
|
22
|
+
* },
|
|
23
|
+
* {
|
|
24
|
+
* className: projectcss.global_platform_osx,
|
|
25
|
+
* groupName: "platform",
|
|
26
|
+
* variant: "osx"
|
|
27
|
+
* },
|
|
28
|
+
* {
|
|
29
|
+
* className: projectcss.global_theme_light,
|
|
30
|
+
* groupName: "theme",
|
|
31
|
+
* variant: "light"
|
|
32
|
+
* },
|
|
33
|
+
* {
|
|
34
|
+
* className: projectcss.global_theme_dark,
|
|
35
|
+
* groupName: "theme",
|
|
36
|
+
* variant: "dark"
|
|
37
|
+
* },
|
|
38
|
+
* ],
|
|
39
|
+
* };
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
interface ProjectStyleTokenData {
|
|
43
|
+
base: ClassName;
|
|
44
|
+
varianted: {
|
|
45
|
+
className: ClassName;
|
|
46
|
+
groupName: string;
|
|
47
|
+
variant: string;
|
|
48
|
+
}[];
|
|
49
|
+
}
|
|
50
|
+
type UseStyleTokens = () => ClassName[];
|
|
51
|
+
/**
|
|
52
|
+
* Returns style tokens. If the context is not available, falls back to the
|
|
53
|
+
* current project's styles.
|
|
54
|
+
*
|
|
55
|
+
* Usage:
|
|
56
|
+
* ```
|
|
57
|
+
* // PlasmicStyleTokensProvider.ts
|
|
58
|
+
* export const useStyleTokens = createUseStyleTokens(
|
|
59
|
+
* projectStyleTokenData,
|
|
60
|
+
* useGlobalVariants,
|
|
61
|
+
* );
|
|
62
|
+
*
|
|
63
|
+
* // PlasmicPage.tsx
|
|
64
|
+
* import { useStyleTokens } from "./plasmic_project";
|
|
65
|
+
*
|
|
66
|
+
* export function PlasmicPage() {
|
|
67
|
+
* const styleTokensClassNames = useStyleTokens();
|
|
68
|
+
* return (
|
|
69
|
+
* <div className={classNames(
|
|
70
|
+
* projectcss.all,
|
|
71
|
+
* projectcss.root_reset,
|
|
72
|
+
* projectcss.plasmic_default_styles,
|
|
73
|
+
* projectcss.plasmic_mixins,
|
|
74
|
+
* styleTokensClassNames,
|
|
75
|
+
* )}>
|
|
76
|
+
* <h1 className={projectcss.all}>
|
|
77
|
+
* Hello, world!
|
|
78
|
+
* </h1>
|
|
79
|
+
* </div>
|
|
80
|
+
* );
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare function createUseStyleTokens(tokenData: ProjectStyleTokenData, useGlobalVariants: UseGlobalVariants): UseStyleTokens;
|
|
85
|
+
/**
|
|
86
|
+
* Creates a StyleTokens context provider for a given project, which includes
|
|
87
|
+
* its tokens, overrides, and all tokens from its dependencies.
|
|
88
|
+
*
|
|
89
|
+
* Usage:
|
|
90
|
+
* ```
|
|
91
|
+
* // PlasmicStyleTokensProvider.ts
|
|
92
|
+
* export const StyleTokensProvider = createStyleTokensProvider(
|
|
93
|
+
* projectStyleTokenData,
|
|
94
|
+
* useGlobalVariants,
|
|
95
|
+
* );
|
|
96
|
+
*
|
|
97
|
+
* // Page.tsx
|
|
98
|
+
* import { StyleTokensProvider } from "./plasmic_project";
|
|
99
|
+
*
|
|
100
|
+
* export default function Page() {
|
|
101
|
+
* return (
|
|
102
|
+
* <PlatformContext.Provider value="osx">
|
|
103
|
+
* <ThemeContext.Provider value="dark">
|
|
104
|
+
* <StyleTokensProvider>
|
|
105
|
+
* <PlasmicPage />
|
|
106
|
+
* </StyleTokensProvider>
|
|
107
|
+
* </ThemeContext.Provider>
|
|
108
|
+
* </PlatformContext.Provider>
|
|
109
|
+
* );
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export declare function createStyleTokensProvider(tokenData: ProjectStyleTokenData, useGlobalVariants: UseGlobalVariants): React.ComponentType<React.PropsWithChildren>;
|
|
114
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicapp/react-web",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.398",
|
|
4
4
|
"description": "plasmic library for rendering in the presentational style",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -95,14 +95,14 @@
|
|
|
95
95
|
"test-storybook": "test-storybook"
|
|
96
96
|
},
|
|
97
97
|
"dependencies": {
|
|
98
|
-
"@plasmicapp/auth-react": "0.0.
|
|
99
|
-
"@plasmicapp/data-sources": "0.1.
|
|
100
|
-
"@plasmicapp/data-sources-context": "0.1.
|
|
101
|
-
"@plasmicapp/host": "1.0.
|
|
98
|
+
"@plasmicapp/auth-react": "0.0.23",
|
|
99
|
+
"@plasmicapp/data-sources": "0.1.188",
|
|
100
|
+
"@plasmicapp/data-sources-context": "0.1.22",
|
|
101
|
+
"@plasmicapp/host": "1.0.224",
|
|
102
102
|
"@plasmicapp/loader-splits": "1.0.64",
|
|
103
|
-
"@plasmicapp/nextjs-app-router": "1.0.
|
|
104
|
-
"@plasmicapp/prepass": "1.0.
|
|
105
|
-
"@plasmicapp/query": "0.1.
|
|
103
|
+
"@plasmicapp/nextjs-app-router": "1.0.17",
|
|
104
|
+
"@plasmicapp/prepass": "1.0.20",
|
|
105
|
+
"@plasmicapp/query": "0.1.80",
|
|
106
106
|
"@react-aria/checkbox": "^3.15.5",
|
|
107
107
|
"@react-aria/focus": "^3.20.3",
|
|
108
108
|
"@react-aria/interactions": "^3.25.1",
|
|
@@ -155,5 +155,5 @@
|
|
|
155
155
|
"react": ">=16.8.0",
|
|
156
156
|
"react-dom": ">=16.8.0"
|
|
157
157
|
},
|
|
158
|
-
"gitHead": "
|
|
158
|
+
"gitHead": "d34346a7551acb26224eade5e29365667acc7ee3"
|
|
159
159
|
}
|
|
@@ -2,16 +2,17 @@ export { PlasmicTranslator } from "@plasmicapp/host";
|
|
|
2
2
|
export { PlasmicPageGuard, withPlasmicPageGuard, } from "./auth/PlasmicPageGuard";
|
|
3
3
|
export { omit, pick } from "./common";
|
|
4
4
|
export { HTMLElementRefOf, StrictProps } from "./react-utils";
|
|
5
|
-
export { Flex, MultiChoiceArg, SingleBooleanChoiceArg, SingleChoiceArg, createPlasmicElementProxy, deriveRenderOpts, hasVariant, makeFragment, mergeVariantsWithStates, wrapWithClassName, } from "./render/elements";
|
|
6
|
-
export { ensureGlobalVariants } from "./render/global-variants";
|
|
7
5
|
export { PlasmicHead, plasmicHeadMeta } from "./render/PlasmicHead";
|
|
8
6
|
export { PlasmicIcon } from "./render/PlasmicIcon";
|
|
9
7
|
export { PlasmicImg } from "./render/PlasmicImg";
|
|
10
8
|
export { PlasmicLink } from "./render/PlasmicLink";
|
|
11
9
|
export { PlasmicSlot, renderPlasmicSlot } from "./render/PlasmicSlot";
|
|
10
|
+
export { Stack } from "./render/Stack";
|
|
11
|
+
export { Flex, MultiChoiceArg, SingleBooleanChoiceArg, SingleChoiceArg, createPlasmicElementProxy, deriveRenderOpts, hasVariant, makeFragment, mergeVariantsWithStates, wrapWithClassName, } from "./render/elements";
|
|
12
|
+
export { createUseGlobalVariants, ensureGlobalVariants, } from "./render/global-variants";
|
|
12
13
|
export { createUseScreenVariants } from "./render/screen-variants";
|
|
13
14
|
export { PlasmicDataSourceContextProvider, PlasmicRootProvider, useCurrentUser, useIsSSR, } from "./render/ssr";
|
|
14
|
-
export {
|
|
15
|
+
export { createStyleTokensProvider, createUseStyleTokens, } from "./render/style-tokens";
|
|
15
16
|
export { Trans, genTranslatableString, usePlasmicTranslator, } from "./render/translation";
|
|
16
17
|
export { useTrigger } from "./render/triggers";
|
|
17
18
|
export * from "./states";
|
package/skinny/dist/index.js
CHANGED
|
@@ -5,13 +5,13 @@ export { PlasmicDataSourceContextProvider, useCurrentUser } from '@plasmicapp/da
|
|
|
5
5
|
import * as plasmicQuery from '@plasmicapp/query';
|
|
6
6
|
import * as React from 'react';
|
|
7
7
|
import React__default, { useLayoutEffect, useEffect } from 'react';
|
|
8
|
-
import get from 'dlv';
|
|
9
|
-
export { default as get } from 'dlv';
|
|
10
|
-
import { c as createElementWithChildren, m as mergeProps, e as ensureNotArray, N as NONE, a as mergePropVals, i as isReactNode, b as isBrowser, u as useIsomorphicLayoutEffect$1 } from './react-utils-2892a561.js';
|
|
11
8
|
export { PlasmicHead, plasmicHeadMeta } from './render/PlasmicHead/index.js';
|
|
12
9
|
export { PlasmicImg } from './render/PlasmicImg/index.js';
|
|
13
10
|
import { T as Trans } from './ssr-649d12f8.js';
|
|
14
11
|
export { P as PlasmicLink, a as PlasmicRootProvider, g as genTranslatableString, u as useIsSSR, b as usePlasmicTranslator } from './ssr-649d12f8.js';
|
|
12
|
+
import { m as mergeProps, c as createElementWithChildren, e as ensureNotArray, N as NONE, a as mergePropVals, i as isReactNode, b as isBrowser, u as useIsomorphicLayoutEffect$1 } from './react-utils-2892a561.js';
|
|
13
|
+
import get from 'dlv';
|
|
14
|
+
export { default as get } from 'dlv';
|
|
15
15
|
import ReactDOM__default from 'react-dom';
|
|
16
16
|
import { useFocusRing } from '@react-aria/focus';
|
|
17
17
|
import { useHover as useHover$1, usePress } from '@react-aria/interactions';
|
|
@@ -146,39 +146,61 @@ function withPlasmicPageGuard(WrappedComponent, options) {
|
|
|
146
146
|
return PageGuard;
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
function
|
|
150
|
-
var
|
|
151
|
-
|
|
152
|
-
return createElementWithChildren(as, __assign({ ref: ref }, rest), wrappedChildren);
|
|
149
|
+
function PlasmicIcon(props) {
|
|
150
|
+
var PlasmicIconType = props.PlasmicIconType, rest = __rest(props, ["PlasmicIconType"]);
|
|
151
|
+
return React.createElement(PlasmicIconType, __assign({}, rest));
|
|
153
152
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return
|
|
153
|
+
|
|
154
|
+
function PlasmicSlot(props) {
|
|
155
|
+
return renderPlasmicSlot(props);
|
|
156
|
+
}
|
|
157
|
+
function renderPlasmicSlot(opts) {
|
|
158
|
+
var as = opts.as, defaultContents = opts.defaultContents, value = opts.value, rest = __rest(opts, ["as", "defaultContents", "value"]);
|
|
159
|
+
var content = value === undefined ? defaultContents : value;
|
|
160
|
+
if (typeof content !== "number" &&
|
|
161
|
+
(!content || (Array.isArray(content) && content.length === 0))) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
// If the content is a raw string, then we need to wrap the raw string
|
|
165
|
+
// into an element, in case the slot is inside a flex-gap
|
|
166
|
+
// container (you cannot apply margin to just a text node).
|
|
167
|
+
var maybeString = maybeAsString(content);
|
|
168
|
+
if (maybeString) {
|
|
169
|
+
content = (React.createElement("span", { className: "__wab_slot-string-wrapper \u03C1sw" }, maybeString));
|
|
170
|
+
}
|
|
171
|
+
var nonEmptyProps = Object.keys(rest).filter(function (p) { return !!rest[p]; });
|
|
172
|
+
if (nonEmptyProps.length === 0) {
|
|
173
|
+
// No attrs to apply to the slot (which means the slot is unstyled), then
|
|
174
|
+
// just render the content directly; no need for style wrapper.
|
|
175
|
+
return content;
|
|
176
|
+
}
|
|
177
|
+
return React.createElement(as || "span", mergeProps({ className: "__wab_slot ρs" }, rest), content);
|
|
178
|
+
}
|
|
179
|
+
function maybeAsString(node) {
|
|
180
|
+
// Unwrap fragments
|
|
181
|
+
if (React.isValidElement(node)) {
|
|
182
|
+
// Fragment doesn't render DOM elements
|
|
183
|
+
if (node.type === React.Fragment) {
|
|
184
|
+
return maybeAsString(node.props.children);
|
|
185
|
+
}
|
|
186
|
+
else if (node.type === Trans) {
|
|
187
|
+
// Trans also doesn't render DOM elements. But we don't want to just render
|
|
188
|
+
// its content string, because we want to keep the <Trans/> for the localization.
|
|
189
|
+
// So we render the same node, to be wrapped into __wab_slot-string-wrapper.
|
|
190
|
+
return node;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (typeof node === "string") {
|
|
194
|
+
return node;
|
|
195
|
+
}
|
|
196
|
+
if (typeof node === "number") {
|
|
197
|
+
return "".concat(node);
|
|
198
|
+
}
|
|
199
|
+
if (Array.isArray(node) && node.length === 1 && typeof node[0] === "string") {
|
|
200
|
+
return node[0];
|
|
201
|
+
}
|
|
202
|
+
return undefined;
|
|
157
203
|
}
|
|
158
|
-
var FlexStack = React.forwardRef(FlexStack_);
|
|
159
|
-
var makeStackImpl = function (as) {
|
|
160
|
-
return React.forwardRef(function (props, ref) {
|
|
161
|
-
var hasGap = props.hasGap, rest = __rest(props, ["hasGap"]);
|
|
162
|
-
return renderStack(as, rest, hasGap, ref);
|
|
163
|
-
});
|
|
164
|
-
};
|
|
165
|
-
var Stack = Object.assign(FlexStack, {
|
|
166
|
-
div: makeStackImpl("div"),
|
|
167
|
-
a: makeStackImpl("a"),
|
|
168
|
-
button: makeStackImpl("button"),
|
|
169
|
-
h1: makeStackImpl("h1"),
|
|
170
|
-
h2: makeStackImpl("h2"),
|
|
171
|
-
h3: makeStackImpl("h3"),
|
|
172
|
-
h4: makeStackImpl("h4"),
|
|
173
|
-
h5: makeStackImpl("h5"),
|
|
174
|
-
h6: makeStackImpl("h6"),
|
|
175
|
-
label: makeStackImpl("label"),
|
|
176
|
-
form: makeStackImpl("form"),
|
|
177
|
-
section: makeStackImpl("section"),
|
|
178
|
-
head: makeStackImpl("head"),
|
|
179
|
-
main: makeStackImpl("main"),
|
|
180
|
-
nav: makeStackImpl("nav"),
|
|
181
|
-
});
|
|
182
204
|
|
|
183
205
|
function hasVariant(variants, groupName, variant) {
|
|
184
206
|
if (variants == null) {
|
|
@@ -525,80 +547,109 @@ function deriveRenderOpts(props, config) {
|
|
|
525
547
|
return { variants: variants, args: args, overrides: overrides };
|
|
526
548
|
}
|
|
527
549
|
|
|
528
|
-
|
|
550
|
+
function renderStack(as, props, hasGap, ref) {
|
|
551
|
+
var children = props.children, rest = __rest(props, ["children"]);
|
|
552
|
+
var wrappedChildren = wrapFlexContainerChildren(children, hasGap !== null && hasGap !== void 0 ? hasGap : false);
|
|
553
|
+
return createElementWithChildren(as, __assign({ ref: ref }, rest), wrappedChildren);
|
|
554
|
+
}
|
|
555
|
+
function FlexStack_(props, outerRef) {
|
|
556
|
+
var as = props.as, hasGap = props.hasGap, rest = __rest(props, ["as", "hasGap"]);
|
|
557
|
+
return renderStack(as !== null && as !== void 0 ? as : "div", rest, hasGap, outerRef);
|
|
558
|
+
}
|
|
559
|
+
var FlexStack = React.forwardRef(FlexStack_);
|
|
560
|
+
var makeStackImpl = function (as) {
|
|
561
|
+
return React.forwardRef(function (props, ref) {
|
|
562
|
+
var hasGap = props.hasGap, rest = __rest(props, ["hasGap"]);
|
|
563
|
+
return renderStack(as, rest, hasGap, ref);
|
|
564
|
+
});
|
|
565
|
+
};
|
|
566
|
+
var Stack = Object.assign(FlexStack, {
|
|
567
|
+
div: makeStackImpl("div"),
|
|
568
|
+
a: makeStackImpl("a"),
|
|
569
|
+
button: makeStackImpl("button"),
|
|
570
|
+
h1: makeStackImpl("h1"),
|
|
571
|
+
h2: makeStackImpl("h2"),
|
|
572
|
+
h3: makeStackImpl("h3"),
|
|
573
|
+
h4: makeStackImpl("h4"),
|
|
574
|
+
h5: makeStackImpl("h5"),
|
|
575
|
+
h6: makeStackImpl("h6"),
|
|
576
|
+
label: makeStackImpl("label"),
|
|
577
|
+
form: makeStackImpl("form"),
|
|
578
|
+
section: makeStackImpl("section"),
|
|
579
|
+
head: makeStackImpl("head"),
|
|
580
|
+
main: makeStackImpl("main"),
|
|
581
|
+
nav: makeStackImpl("nav"),
|
|
582
|
+
});
|
|
583
|
+
|
|
584
|
+
var isDefaultValue = function (val) {
|
|
585
|
+
return val === "PLEASE_RENDER_INSIDE_PROVIDER";
|
|
586
|
+
};
|
|
529
587
|
var seenDefaultVariants = {};
|
|
530
|
-
|
|
531
|
-
|
|
588
|
+
/**
|
|
589
|
+
* Usage:
|
|
590
|
+
* ```
|
|
591
|
+
* // plasmic.ts
|
|
592
|
+
* import { usePlatform } from "./PlasmicGlobalVariant__Platform";
|
|
593
|
+
* import { useTheme } from "./PlasmicGlobalVariant__Theme";
|
|
594
|
+
*
|
|
595
|
+
* export const useGlobalVariants = createUseGlobalVariants({
|
|
596
|
+
* platform: usePlatform,
|
|
597
|
+
* theme: useTheme,
|
|
598
|
+
* });
|
|
599
|
+
*
|
|
600
|
+
* // PlasmicComponent.tsx
|
|
601
|
+
* import { useGlobalVariants } from "./plasmic_project";
|
|
602
|
+
*
|
|
603
|
+
* export function PlasmicComponent() {
|
|
604
|
+
* // ...
|
|
605
|
+
* const globalVariants = useGlobalVariants();
|
|
606
|
+
* // ...
|
|
607
|
+
* }
|
|
608
|
+
* ```
|
|
609
|
+
*/
|
|
610
|
+
function createUseGlobalVariants(globalVariantHooks) {
|
|
611
|
+
return function () {
|
|
612
|
+
return ensureGlobalVariants(Object.fromEntries(Object.entries(globalVariantHooks).map(function (_a) {
|
|
613
|
+
var _b = __read(_a, 2), globalVariant = _b[0], useHook = _b[1];
|
|
614
|
+
return [globalVariant, useHook()];
|
|
615
|
+
})));
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* @deprecated - new generated code should use `useGlobalVariants` instead
|
|
620
|
+
*
|
|
621
|
+
* Usage:
|
|
622
|
+
* ```
|
|
623
|
+
* // PlasmicComponent.tsx
|
|
624
|
+
* import { useTheme } from "./PlasmicGlobalVariant__Theme";
|
|
625
|
+
* import { usePlatform } from "./PlasmicGlobalVariant__Platform";
|
|
626
|
+
*
|
|
627
|
+
* export function PlasmicComponent() {
|
|
628
|
+
* // ...
|
|
629
|
+
* const globalVariants = ensureGlobalVariants({
|
|
630
|
+
* platform: usePlatform(),
|
|
631
|
+
* theme: useTheme(),
|
|
632
|
+
* });
|
|
633
|
+
* // ...
|
|
634
|
+
* }
|
|
635
|
+
* ```
|
|
636
|
+
*/
|
|
637
|
+
function ensureGlobalVariants(globalVariants) {
|
|
638
|
+
Object.entries(globalVariants)
|
|
532
639
|
.filter(function (_a) {
|
|
533
640
|
var _b = __read(_a, 2); _b[0]; var value = _b[1];
|
|
534
641
|
return isDefaultValue(value);
|
|
535
642
|
})
|
|
536
643
|
.forEach(function (_a) {
|
|
537
644
|
var _b = __read(_a, 2), key = _b[0]; _b[1];
|
|
538
|
-
|
|
645
|
+
globalVariants[key] = undefined;
|
|
539
646
|
if (!seenDefaultVariants[key] && process.env.NODE_ENV === "development") {
|
|
540
647
|
seenDefaultVariants[key] = true;
|
|
541
648
|
var providerName = "".concat(key[0].toUpperCase()).concat(key.substring(1), "Context.Provider");
|
|
542
649
|
console.warn("Plasmic context value for global variant \"".concat(key, "\" was not provided; please use ").concat(providerName, " at the root of your React app. Learn More: https://www.plasmic.app/learn/other-assets/#global-variants"));
|
|
543
650
|
}
|
|
544
651
|
});
|
|
545
|
-
return
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
function PlasmicIcon(props) {
|
|
549
|
-
var PlasmicIconType = props.PlasmicIconType, rest = __rest(props, ["PlasmicIconType"]);
|
|
550
|
-
return React.createElement(PlasmicIconType, __assign({}, rest));
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
function PlasmicSlot(props) {
|
|
554
|
-
return renderPlasmicSlot(props);
|
|
555
|
-
}
|
|
556
|
-
function renderPlasmicSlot(opts) {
|
|
557
|
-
var as = opts.as, defaultContents = opts.defaultContents, value = opts.value, rest = __rest(opts, ["as", "defaultContents", "value"]);
|
|
558
|
-
var content = value === undefined ? defaultContents : value;
|
|
559
|
-
if (typeof content !== "number" &&
|
|
560
|
-
(!content || (Array.isArray(content) && content.length === 0))) {
|
|
561
|
-
return null;
|
|
562
|
-
}
|
|
563
|
-
// If the content is a raw string, then we need to wrap the raw string
|
|
564
|
-
// into an element, in case the slot is inside a flex-gap
|
|
565
|
-
// container (you cannot apply margin to just a text node).
|
|
566
|
-
var maybeString = maybeAsString(content);
|
|
567
|
-
if (maybeString) {
|
|
568
|
-
content = (React.createElement("span", { className: "__wab_slot-string-wrapper \u03C1sw" }, maybeString));
|
|
569
|
-
}
|
|
570
|
-
var nonEmptyProps = Object.keys(rest).filter(function (p) { return !!rest[p]; });
|
|
571
|
-
if (nonEmptyProps.length === 0) {
|
|
572
|
-
// No attrs to apply to the slot (which means the slot is unstyled), then
|
|
573
|
-
// just render the content directly; no need for style wrapper.
|
|
574
|
-
return content;
|
|
575
|
-
}
|
|
576
|
-
return React.createElement(as || "span", mergeProps({ className: "__wab_slot ρs" }, rest), content);
|
|
577
|
-
}
|
|
578
|
-
function maybeAsString(node) {
|
|
579
|
-
// Unwrap fragments
|
|
580
|
-
if (React.isValidElement(node)) {
|
|
581
|
-
// Fragment doesn't render DOM elements
|
|
582
|
-
if (node.type === React.Fragment) {
|
|
583
|
-
return maybeAsString(node.props.children);
|
|
584
|
-
}
|
|
585
|
-
else if (node.type === Trans) {
|
|
586
|
-
// Trans also doesn't render DOM elements. But we don't want to just render
|
|
587
|
-
// its content string, because we want to keep the <Trans/> for the localization.
|
|
588
|
-
// So we render the same node, to be wrapped into __wab_slot-string-wrapper.
|
|
589
|
-
return node;
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
if (typeof node === "string") {
|
|
593
|
-
return node;
|
|
594
|
-
}
|
|
595
|
-
if (typeof node === "number") {
|
|
596
|
-
return "".concat(node);
|
|
597
|
-
}
|
|
598
|
-
if (Array.isArray(node) && node.length === 1 && typeof node[0] === "string") {
|
|
599
|
-
return node[0];
|
|
600
|
-
}
|
|
601
|
-
return undefined;
|
|
652
|
+
return globalVariants;
|
|
602
653
|
}
|
|
603
654
|
|
|
604
655
|
var listeners = [];
|
|
@@ -689,6 +740,115 @@ function createUseScreenVariants(isMulti, screenQueries) {
|
|
|
689
740
|
};
|
|
690
741
|
}
|
|
691
742
|
|
|
743
|
+
/**
|
|
744
|
+
* Context that enables a project's style tokens to be propagated across projects.
|
|
745
|
+
*
|
|
746
|
+
* The value is an array of class names, including the class name for the base
|
|
747
|
+
* variant and active global variants. The class names should be applied to all
|
|
748
|
+
* Plasmic content.
|
|
749
|
+
*/
|
|
750
|
+
var StyleTokensContext = React__default.createContext(undefined);
|
|
751
|
+
/**
|
|
752
|
+
* Returns style tokens. If the context is not available, falls back to the
|
|
753
|
+
* current project's styles.
|
|
754
|
+
*
|
|
755
|
+
* Usage:
|
|
756
|
+
* ```
|
|
757
|
+
* // PlasmicStyleTokensProvider.ts
|
|
758
|
+
* export const useStyleTokens = createUseStyleTokens(
|
|
759
|
+
* projectStyleTokenData,
|
|
760
|
+
* useGlobalVariants,
|
|
761
|
+
* );
|
|
762
|
+
*
|
|
763
|
+
* // PlasmicPage.tsx
|
|
764
|
+
* import { useStyleTokens } from "./plasmic_project";
|
|
765
|
+
*
|
|
766
|
+
* export function PlasmicPage() {
|
|
767
|
+
* const styleTokensClassNames = useStyleTokens();
|
|
768
|
+
* return (
|
|
769
|
+
* <div className={classNames(
|
|
770
|
+
* projectcss.all,
|
|
771
|
+
* projectcss.root_reset,
|
|
772
|
+
* projectcss.plasmic_default_styles,
|
|
773
|
+
* projectcss.plasmic_mixins,
|
|
774
|
+
* styleTokensClassNames,
|
|
775
|
+
* )}>
|
|
776
|
+
* <h1 className={projectcss.all}>
|
|
777
|
+
* Hello, world!
|
|
778
|
+
* </h1>
|
|
779
|
+
* </div>
|
|
780
|
+
* );
|
|
781
|
+
* }
|
|
782
|
+
* ```
|
|
783
|
+
*/
|
|
784
|
+
function createUseStyleTokens(tokenData, useGlobalVariants) {
|
|
785
|
+
return function () {
|
|
786
|
+
var overrides = React__default.useContext(StyleTokensContext);
|
|
787
|
+
var globalVariants = useGlobalVariants();
|
|
788
|
+
return React__default.useMemo(function () {
|
|
789
|
+
if (overrides && overrides.length > 0) {
|
|
790
|
+
return overrides;
|
|
791
|
+
}
|
|
792
|
+
else {
|
|
793
|
+
return activeTokensClassNames(tokenData, globalVariants);
|
|
794
|
+
}
|
|
795
|
+
}, [overrides, globalVariants, tokenData]);
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Creates a StyleTokens context provider for a given project, which includes
|
|
800
|
+
* its tokens, overrides, and all tokens from its dependencies.
|
|
801
|
+
*
|
|
802
|
+
* Usage:
|
|
803
|
+
* ```
|
|
804
|
+
* // PlasmicStyleTokensProvider.ts
|
|
805
|
+
* export const StyleTokensProvider = createStyleTokensProvider(
|
|
806
|
+
* projectStyleTokenData,
|
|
807
|
+
* useGlobalVariants,
|
|
808
|
+
* );
|
|
809
|
+
*
|
|
810
|
+
* // Page.tsx
|
|
811
|
+
* import { StyleTokensProvider } from "./plasmic_project";
|
|
812
|
+
*
|
|
813
|
+
* export default function Page() {
|
|
814
|
+
* return (
|
|
815
|
+
* <PlatformContext.Provider value="osx">
|
|
816
|
+
* <ThemeContext.Provider value="dark">
|
|
817
|
+
* <StyleTokensProvider>
|
|
818
|
+
* <PlasmicPage />
|
|
819
|
+
* </StyleTokensProvider>
|
|
820
|
+
* </ThemeContext.Provider>
|
|
821
|
+
* </PlatformContext.Provider>
|
|
822
|
+
* );
|
|
823
|
+
* }
|
|
824
|
+
* ```
|
|
825
|
+
*/
|
|
826
|
+
function createStyleTokensProvider(tokenData, useGlobalVariants) {
|
|
827
|
+
return function (props) {
|
|
828
|
+
var globalVariants = useGlobalVariants();
|
|
829
|
+
var tokens = React__default.useMemo(function () {
|
|
830
|
+
return activeTokensClassNames(tokenData, globalVariants);
|
|
831
|
+
}, [globalVariants, tokenData]);
|
|
832
|
+
return (React__default.createElement(StyleTokensContext.Provider, { value: tokens }, props.children));
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* Gets the class names for the base tokens and the varianted tokens for active
|
|
837
|
+
* global variants.
|
|
838
|
+
*/
|
|
839
|
+
function activeTokensClassNames(tokenData, globalVariants) {
|
|
840
|
+
var varianted = tokenData.varianted
|
|
841
|
+
.filter(function (_a) {
|
|
842
|
+
var groupName = _a.groupName, variant = _a.variant;
|
|
843
|
+
return hasVariant(globalVariants, groupName, variant);
|
|
844
|
+
})
|
|
845
|
+
.map(function (_a) {
|
|
846
|
+
var className = _a.className;
|
|
847
|
+
return className;
|
|
848
|
+
});
|
|
849
|
+
return __spreadArray([tokenData.base], __read(varianted), false);
|
|
850
|
+
}
|
|
851
|
+
|
|
692
852
|
function useFocused(opts) {
|
|
693
853
|
var _a = useFocusRing({
|
|
694
854
|
within: false,
|
|
@@ -1791,5 +1951,5 @@ function deepEqual(a, b) {
|
|
|
1791
1951
|
// Using any while classnames package is not updated to have the correct types exported
|
|
1792
1952
|
var classNames = classNames$1;
|
|
1793
1953
|
|
|
1794
|
-
export { PlasmicIcon, PlasmicPageGuard, PlasmicSlot, Stack, Trans, classNames, createPlasmicElementProxy, createUseScreenVariants, deriveRenderOpts, ensureGlobalVariants, generateOnMutateForSpec, generateStateOnChangeProp, generateStateOnChangePropForCodeComponents, generateStateValueProp, getCurrentInitialValue, getStateCellsInPlasmicProxy, getStateSpecInPlasmicProxy, hasVariant, initializeCodeComponentStates, initializePlasmicStates, is$StateProxy, isPlasmicStateProxy, makeFragment, mergeVariantsWithStates, omit, pick, renderPlasmicSlot, resetToInitialValue, set, useDollarState, useTrigger, withPlasmicPageGuard, wrapWithClassName };
|
|
1954
|
+
export { PlasmicIcon, PlasmicPageGuard, PlasmicSlot, Stack, Trans, classNames, createPlasmicElementProxy, createStyleTokensProvider, createUseGlobalVariants, createUseScreenVariants, createUseStyleTokens, deriveRenderOpts, ensureGlobalVariants, generateOnMutateForSpec, generateStateOnChangeProp, generateStateOnChangePropForCodeComponents, generateStateValueProp, getCurrentInitialValue, getStateCellsInPlasmicProxy, getStateSpecInPlasmicProxy, hasVariant, initializeCodeComponentStates, initializePlasmicStates, is$StateProxy, isPlasmicStateProxy, makeFragment, mergeVariantsWithStates, omit, pick, renderPlasmicSlot, resetToInitialValue, set, useDollarState, useTrigger, withPlasmicPageGuard, wrapWithClassName };
|
|
1795
1955
|
//# sourceMappingURL=index.js.map
|