@onlook/storybook-plugin 0.4.0-beta.18 → 0.4.0-beta.19
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/index.js +135 -3
- package/dist/preset/index.js +135 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -857,9 +857,139 @@ function handleStoryFileChange({ file, modules }) {
|
|
|
857
857
|
}
|
|
858
858
|
}
|
|
859
859
|
|
|
860
|
-
// src/package-mock/
|
|
860
|
+
// src/package-mock/convex-mock.ts
|
|
861
861
|
var VALID_IDENT_RE2 = /^[A-Za-z_$][\w$]*$/;
|
|
862
862
|
var RESERVED_HELPER_NAMES = /* @__PURE__ */ new Set([
|
|
863
|
+
"__pass",
|
|
864
|
+
"__null",
|
|
865
|
+
"__asyncNoop",
|
|
866
|
+
"__noop",
|
|
867
|
+
"__convexClient",
|
|
868
|
+
"createElement",
|
|
869
|
+
"Fragment"
|
|
870
|
+
]);
|
|
871
|
+
var SHARED_PREAMBLE = [
|
|
872
|
+
"import { createElement, Fragment } from 'react';",
|
|
873
|
+
"const __asyncNoop = async () => {};",
|
|
874
|
+
"const __noop = () => {};",
|
|
875
|
+
// No `: any` param annotation — the virtual module is parsed as PLAIN JS.
|
|
876
|
+
"const __pass = (props) => createElement(Fragment, null, props ? props.children : undefined);",
|
|
877
|
+
"const __null = () => null;"
|
|
878
|
+
];
|
|
879
|
+
var CONVEX_CLIENT_PREAMBLE = [
|
|
880
|
+
"const __convexClient = {",
|
|
881
|
+
" setAuth: __noop,",
|
|
882
|
+
" clearAuth: __noop,",
|
|
883
|
+
" close: __asyncNoop,",
|
|
884
|
+
" connectionState: () => ({ hasInflightRequests: false, isWebSocketConnected: false }),",
|
|
885
|
+
" watchQuery: () => ({",
|
|
886
|
+
" onUpdate: () => __noop,",
|
|
887
|
+
" localQueryResult: () => undefined,",
|
|
888
|
+
" journal: () => undefined,",
|
|
889
|
+
" }),",
|
|
890
|
+
" mutation: __asyncNoop,",
|
|
891
|
+
" action: __asyncNoop,",
|
|
892
|
+
" query: __asyncNoop,",
|
|
893
|
+
"};"
|
|
894
|
+
];
|
|
895
|
+
var CONVEX_KNOWN_HOOKS = {
|
|
896
|
+
useQuery: "undefined",
|
|
897
|
+
useQueries: "({})",
|
|
898
|
+
useMutation: "__asyncNoop",
|
|
899
|
+
useAction: "__asyncNoop",
|
|
900
|
+
usePaginatedQuery: "({ results: [], status: 'LoadingFirstPage', isLoading: true, loadMore: __noop })",
|
|
901
|
+
useConvex: "__convexClient",
|
|
902
|
+
useConvexAuth: "({ isLoading: false, isAuthenticated: true })"
|
|
903
|
+
};
|
|
904
|
+
var CONVEX_CHILDREN_COMPONENTS = /* @__PURE__ */ new Set([
|
|
905
|
+
"ConvexProvider",
|
|
906
|
+
"ConvexProviderWithAuth",
|
|
907
|
+
"ConvexProviderWithClerk",
|
|
908
|
+
"Authenticated"
|
|
909
|
+
]);
|
|
910
|
+
var CONVEX_NULL_COMPONENTS = /* @__PURE__ */ new Set(["Unauthenticated", "AuthLoading"]);
|
|
911
|
+
function convexExportLine(name) {
|
|
912
|
+
if (name in CONVEX_KNOWN_HOOKS) {
|
|
913
|
+
return `export const ${name} = () => ${CONVEX_KNOWN_HOOKS[name]};`;
|
|
914
|
+
}
|
|
915
|
+
if (name === "ConvexReactClient") {
|
|
916
|
+
return "export function ConvexReactClient() { return __convexClient; }";
|
|
917
|
+
}
|
|
918
|
+
if (CONVEX_CHILDREN_COMPONENTS.has(name)) return `export const ${name} = __pass;`;
|
|
919
|
+
if (CONVEX_NULL_COMPONENTS.has(name)) return `export const ${name} = __null;`;
|
|
920
|
+
if (/^use[A-Z]/.test(name)) return `export const ${name} = () => undefined;`;
|
|
921
|
+
if (/^[A-Z]/.test(name)) return `export const ${name} = __pass;`;
|
|
922
|
+
return `export const ${name} = undefined;`;
|
|
923
|
+
}
|
|
924
|
+
function buildConvexReactMockSource(usedExports) {
|
|
925
|
+
const names = dedupeNames([
|
|
926
|
+
...usedExports,
|
|
927
|
+
...Object.keys(CONVEX_KNOWN_HOOKS),
|
|
928
|
+
...CONVEX_CHILDREN_COMPONENTS,
|
|
929
|
+
...CONVEX_NULL_COMPONENTS,
|
|
930
|
+
"ConvexReactClient"
|
|
931
|
+
]);
|
|
932
|
+
return [
|
|
933
|
+
"// Auto-generated by @onlook/storybook-plugin (package mock). Zero-backend",
|
|
934
|
+
"// Convex stand-in: queries stay in the loading state (`useQuery` returns",
|
|
935
|
+
"// `undefined`), mutations/actions no-op, auth reads signed-in. Swap back to",
|
|
936
|
+
"// the real convex package (with a deployment URL) for live data.",
|
|
937
|
+
...SHARED_PREAMBLE,
|
|
938
|
+
...CONVEX_CLIENT_PREAMBLE,
|
|
939
|
+
"",
|
|
940
|
+
...names.map(convexExportLine),
|
|
941
|
+
"",
|
|
942
|
+
"export default {};",
|
|
943
|
+
""
|
|
944
|
+
].join("\n");
|
|
945
|
+
}
|
|
946
|
+
var CONVEX_AUTH_KNOWN_HOOKS = {
|
|
947
|
+
useAuthActions: "({ signIn: __asyncNoop, signOut: __asyncNoop })",
|
|
948
|
+
useAuthToken: "null"
|
|
949
|
+
};
|
|
950
|
+
var CONVEX_AUTH_CHILDREN_COMPONENTS = /* @__PURE__ */ new Set(["ConvexAuthProvider"]);
|
|
951
|
+
function convexAuthExportLine(name) {
|
|
952
|
+
if (name in CONVEX_AUTH_KNOWN_HOOKS) {
|
|
953
|
+
return `export const ${name} = () => ${CONVEX_AUTH_KNOWN_HOOKS[name]};`;
|
|
954
|
+
}
|
|
955
|
+
if (CONVEX_AUTH_CHILDREN_COMPONENTS.has(name)) {
|
|
956
|
+
return `export const ${name} = __pass;`;
|
|
957
|
+
}
|
|
958
|
+
if (/^use[A-Z]/.test(name)) return `export const ${name} = () => undefined;`;
|
|
959
|
+
if (/^[A-Z]/.test(name)) return `export const ${name} = __pass;`;
|
|
960
|
+
return `export const ${name} = undefined;`;
|
|
961
|
+
}
|
|
962
|
+
function buildConvexAuthMockSource(usedExports) {
|
|
963
|
+
const names = dedupeNames([
|
|
964
|
+
...usedExports,
|
|
965
|
+
...Object.keys(CONVEX_AUTH_KNOWN_HOOKS),
|
|
966
|
+
...CONVEX_AUTH_CHILDREN_COMPONENTS
|
|
967
|
+
]);
|
|
968
|
+
return [
|
|
969
|
+
"// Auto-generated by @onlook/storybook-plugin (package mock). Zero-backend",
|
|
970
|
+
"// @convex-dev/auth stand-in: auth actions no-op, no token. Swap back to the",
|
|
971
|
+
"// real package for live auth flows.",
|
|
972
|
+
...SHARED_PREAMBLE,
|
|
973
|
+
"",
|
|
974
|
+
...names.map(convexAuthExportLine),
|
|
975
|
+
"",
|
|
976
|
+
"export default {};",
|
|
977
|
+
""
|
|
978
|
+
].join("\n");
|
|
979
|
+
}
|
|
980
|
+
function dedupeNames(usedExports) {
|
|
981
|
+
return Array.from(
|
|
982
|
+
new Set(
|
|
983
|
+
usedExports.filter(
|
|
984
|
+
(n) => VALID_IDENT_RE2.test(n) && n !== "default" && !RESERVED_HELPER_NAMES.has(n)
|
|
985
|
+
)
|
|
986
|
+
)
|
|
987
|
+
).sort();
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
// src/package-mock/clerk-mock.ts
|
|
991
|
+
var VALID_IDENT_RE3 = /^[A-Za-z_$][\w$]*$/;
|
|
992
|
+
var RESERVED_HELPER_NAMES2 = /* @__PURE__ */ new Set([
|
|
863
993
|
"__user",
|
|
864
994
|
"__pass",
|
|
865
995
|
"__null",
|
|
@@ -872,7 +1002,9 @@ var RESERVED_HELPER_NAMES = /* @__PURE__ */ new Set([
|
|
|
872
1002
|
]);
|
|
873
1003
|
var BUILDERS = {
|
|
874
1004
|
"@clerk/nextjs": buildClerkMockSource,
|
|
875
|
-
"@clerk/clerk-react": buildClerkMockSource
|
|
1005
|
+
"@clerk/clerk-react": buildClerkMockSource,
|
|
1006
|
+
"convex/react": buildConvexReactMockSource,
|
|
1007
|
+
"@convex-dev/auth/react": buildConvexAuthMockSource
|
|
876
1008
|
};
|
|
877
1009
|
function isKnownMockPackage(pkg) {
|
|
878
1010
|
return pkg in BUILDERS;
|
|
@@ -996,7 +1128,7 @@ function buildClerkMockSource(usedExports) {
|
|
|
996
1128
|
const names = Array.from(
|
|
997
1129
|
new Set(
|
|
998
1130
|
usedExports.filter(
|
|
999
|
-
(n) =>
|
|
1131
|
+
(n) => VALID_IDENT_RE3.test(n) && n !== "default" && !RESERVED_HELPER_NAMES2.has(n)
|
|
1000
1132
|
)
|
|
1001
1133
|
)
|
|
1002
1134
|
).sort();
|
package/dist/preset/index.js
CHANGED
|
@@ -853,9 +853,139 @@ function moduleLoadCatchAllPlugin() {
|
|
|
853
853
|
};
|
|
854
854
|
}
|
|
855
855
|
|
|
856
|
-
// src/package-mock/
|
|
856
|
+
// src/package-mock/convex-mock.ts
|
|
857
857
|
var VALID_IDENT_RE2 = /^[A-Za-z_$][\w$]*$/;
|
|
858
858
|
var RESERVED_HELPER_NAMES = /* @__PURE__ */ new Set([
|
|
859
|
+
"__pass",
|
|
860
|
+
"__null",
|
|
861
|
+
"__asyncNoop",
|
|
862
|
+
"__noop",
|
|
863
|
+
"__convexClient",
|
|
864
|
+
"createElement",
|
|
865
|
+
"Fragment"
|
|
866
|
+
]);
|
|
867
|
+
var SHARED_PREAMBLE = [
|
|
868
|
+
"import { createElement, Fragment } from 'react';",
|
|
869
|
+
"const __asyncNoop = async () => {};",
|
|
870
|
+
"const __noop = () => {};",
|
|
871
|
+
// No `: any` param annotation — the virtual module is parsed as PLAIN JS.
|
|
872
|
+
"const __pass = (props) => createElement(Fragment, null, props ? props.children : undefined);",
|
|
873
|
+
"const __null = () => null;"
|
|
874
|
+
];
|
|
875
|
+
var CONVEX_CLIENT_PREAMBLE = [
|
|
876
|
+
"const __convexClient = {",
|
|
877
|
+
" setAuth: __noop,",
|
|
878
|
+
" clearAuth: __noop,",
|
|
879
|
+
" close: __asyncNoop,",
|
|
880
|
+
" connectionState: () => ({ hasInflightRequests: false, isWebSocketConnected: false }),",
|
|
881
|
+
" watchQuery: () => ({",
|
|
882
|
+
" onUpdate: () => __noop,",
|
|
883
|
+
" localQueryResult: () => undefined,",
|
|
884
|
+
" journal: () => undefined,",
|
|
885
|
+
" }),",
|
|
886
|
+
" mutation: __asyncNoop,",
|
|
887
|
+
" action: __asyncNoop,",
|
|
888
|
+
" query: __asyncNoop,",
|
|
889
|
+
"};"
|
|
890
|
+
];
|
|
891
|
+
var CONVEX_KNOWN_HOOKS = {
|
|
892
|
+
useQuery: "undefined",
|
|
893
|
+
useQueries: "({})",
|
|
894
|
+
useMutation: "__asyncNoop",
|
|
895
|
+
useAction: "__asyncNoop",
|
|
896
|
+
usePaginatedQuery: "({ results: [], status: 'LoadingFirstPage', isLoading: true, loadMore: __noop })",
|
|
897
|
+
useConvex: "__convexClient",
|
|
898
|
+
useConvexAuth: "({ isLoading: false, isAuthenticated: true })"
|
|
899
|
+
};
|
|
900
|
+
var CONVEX_CHILDREN_COMPONENTS = /* @__PURE__ */ new Set([
|
|
901
|
+
"ConvexProvider",
|
|
902
|
+
"ConvexProviderWithAuth",
|
|
903
|
+
"ConvexProviderWithClerk",
|
|
904
|
+
"Authenticated"
|
|
905
|
+
]);
|
|
906
|
+
var CONVEX_NULL_COMPONENTS = /* @__PURE__ */ new Set(["Unauthenticated", "AuthLoading"]);
|
|
907
|
+
function convexExportLine(name) {
|
|
908
|
+
if (name in CONVEX_KNOWN_HOOKS) {
|
|
909
|
+
return `export const ${name} = () => ${CONVEX_KNOWN_HOOKS[name]};`;
|
|
910
|
+
}
|
|
911
|
+
if (name === "ConvexReactClient") {
|
|
912
|
+
return "export function ConvexReactClient() { return __convexClient; }";
|
|
913
|
+
}
|
|
914
|
+
if (CONVEX_CHILDREN_COMPONENTS.has(name)) return `export const ${name} = __pass;`;
|
|
915
|
+
if (CONVEX_NULL_COMPONENTS.has(name)) return `export const ${name} = __null;`;
|
|
916
|
+
if (/^use[A-Z]/.test(name)) return `export const ${name} = () => undefined;`;
|
|
917
|
+
if (/^[A-Z]/.test(name)) return `export const ${name} = __pass;`;
|
|
918
|
+
return `export const ${name} = undefined;`;
|
|
919
|
+
}
|
|
920
|
+
function buildConvexReactMockSource(usedExports) {
|
|
921
|
+
const names = dedupeNames([
|
|
922
|
+
...usedExports,
|
|
923
|
+
...Object.keys(CONVEX_KNOWN_HOOKS),
|
|
924
|
+
...CONVEX_CHILDREN_COMPONENTS,
|
|
925
|
+
...CONVEX_NULL_COMPONENTS,
|
|
926
|
+
"ConvexReactClient"
|
|
927
|
+
]);
|
|
928
|
+
return [
|
|
929
|
+
"// Auto-generated by @onlook/storybook-plugin (package mock). Zero-backend",
|
|
930
|
+
"// Convex stand-in: queries stay in the loading state (`useQuery` returns",
|
|
931
|
+
"// `undefined`), mutations/actions no-op, auth reads signed-in. Swap back to",
|
|
932
|
+
"// the real convex package (with a deployment URL) for live data.",
|
|
933
|
+
...SHARED_PREAMBLE,
|
|
934
|
+
...CONVEX_CLIENT_PREAMBLE,
|
|
935
|
+
"",
|
|
936
|
+
...names.map(convexExportLine),
|
|
937
|
+
"",
|
|
938
|
+
"export default {};",
|
|
939
|
+
""
|
|
940
|
+
].join("\n");
|
|
941
|
+
}
|
|
942
|
+
var CONVEX_AUTH_KNOWN_HOOKS = {
|
|
943
|
+
useAuthActions: "({ signIn: __asyncNoop, signOut: __asyncNoop })",
|
|
944
|
+
useAuthToken: "null"
|
|
945
|
+
};
|
|
946
|
+
var CONVEX_AUTH_CHILDREN_COMPONENTS = /* @__PURE__ */ new Set(["ConvexAuthProvider"]);
|
|
947
|
+
function convexAuthExportLine(name) {
|
|
948
|
+
if (name in CONVEX_AUTH_KNOWN_HOOKS) {
|
|
949
|
+
return `export const ${name} = () => ${CONVEX_AUTH_KNOWN_HOOKS[name]};`;
|
|
950
|
+
}
|
|
951
|
+
if (CONVEX_AUTH_CHILDREN_COMPONENTS.has(name)) {
|
|
952
|
+
return `export const ${name} = __pass;`;
|
|
953
|
+
}
|
|
954
|
+
if (/^use[A-Z]/.test(name)) return `export const ${name} = () => undefined;`;
|
|
955
|
+
if (/^[A-Z]/.test(name)) return `export const ${name} = __pass;`;
|
|
956
|
+
return `export const ${name} = undefined;`;
|
|
957
|
+
}
|
|
958
|
+
function buildConvexAuthMockSource(usedExports) {
|
|
959
|
+
const names = dedupeNames([
|
|
960
|
+
...usedExports,
|
|
961
|
+
...Object.keys(CONVEX_AUTH_KNOWN_HOOKS),
|
|
962
|
+
...CONVEX_AUTH_CHILDREN_COMPONENTS
|
|
963
|
+
]);
|
|
964
|
+
return [
|
|
965
|
+
"// Auto-generated by @onlook/storybook-plugin (package mock). Zero-backend",
|
|
966
|
+
"// @convex-dev/auth stand-in: auth actions no-op, no token. Swap back to the",
|
|
967
|
+
"// real package for live auth flows.",
|
|
968
|
+
...SHARED_PREAMBLE,
|
|
969
|
+
"",
|
|
970
|
+
...names.map(convexAuthExportLine),
|
|
971
|
+
"",
|
|
972
|
+
"export default {};",
|
|
973
|
+
""
|
|
974
|
+
].join("\n");
|
|
975
|
+
}
|
|
976
|
+
function dedupeNames(usedExports) {
|
|
977
|
+
return Array.from(
|
|
978
|
+
new Set(
|
|
979
|
+
usedExports.filter(
|
|
980
|
+
(n) => VALID_IDENT_RE2.test(n) && n !== "default" && !RESERVED_HELPER_NAMES.has(n)
|
|
981
|
+
)
|
|
982
|
+
)
|
|
983
|
+
).sort();
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
// src/package-mock/clerk-mock.ts
|
|
987
|
+
var VALID_IDENT_RE3 = /^[A-Za-z_$][\w$]*$/;
|
|
988
|
+
var RESERVED_HELPER_NAMES2 = /* @__PURE__ */ new Set([
|
|
859
989
|
"__user",
|
|
860
990
|
"__pass",
|
|
861
991
|
"__null",
|
|
@@ -868,7 +998,9 @@ var RESERVED_HELPER_NAMES = /* @__PURE__ */ new Set([
|
|
|
868
998
|
]);
|
|
869
999
|
var BUILDERS = {
|
|
870
1000
|
"@clerk/nextjs": buildClerkMockSource,
|
|
871
|
-
"@clerk/clerk-react": buildClerkMockSource
|
|
1001
|
+
"@clerk/clerk-react": buildClerkMockSource,
|
|
1002
|
+
"convex/react": buildConvexReactMockSource,
|
|
1003
|
+
"@convex-dev/auth/react": buildConvexAuthMockSource
|
|
872
1004
|
};
|
|
873
1005
|
function isKnownMockPackage(pkg) {
|
|
874
1006
|
return pkg in BUILDERS;
|
|
@@ -992,7 +1124,7 @@ function buildClerkMockSource(usedExports) {
|
|
|
992
1124
|
const names = Array.from(
|
|
993
1125
|
new Set(
|
|
994
1126
|
usedExports.filter(
|
|
995
|
-
(n) =>
|
|
1127
|
+
(n) => VALID_IDENT_RE3.test(n) && n !== "default" && !RESERVED_HELPER_NAMES2.has(n)
|
|
996
1128
|
)
|
|
997
1129
|
)
|
|
998
1130
|
).sort();
|