Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transpile files #849

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion blocks/account.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// deno-lint-ignore-file no-explicit-any
import JsonViewer from "../components/JsonViewer.tsx";
import JsonViewer from "../components/JsonViewer.ts";
import type { Block, BlockModule, InstanceOf } from "../engine/block.ts";

// deno-lint-ignore no-empty-interface
Expand Down
4 changes: 2 additions & 2 deletions blocks/action.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// deno-lint-ignore-file no-explicit-any
import { applyProps, type FnProps } from "../blocks/utils.tsx";
import JsonViewer from "../components/JsonViewer.tsx";
import JsonViewer from "../components/JsonViewer.ts";
import type { Block, BlockModule, InstanceOf } from "../engine/block.ts";
import { applyProps, type FnProps } from "./utils.ts";

export type Action = InstanceOf<typeof actionBlock, "#/root/actions">;

Expand Down
12 changes: 6 additions & 6 deletions blocks/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
import blocks from "../blocks/index.ts";
import { propsLoader } from "../blocks/propsLoader.ts";
import type { SectionModule } from "../blocks/section.ts";
import {
type AppHttpContext,
buildImportMap,
type FnProps,
} from "../blocks/utils.tsx";
import type { Block, BlockModule, InstanceOf } from "../engine/block.ts";
import type {
BaseContext,
Expand All @@ -23,7 +18,12 @@ import type {
import type { DecoManifest, FnContext } from "../types.ts";
import { resolversFrom } from "./appsUtil.ts";
import { isInvokeCtx } from "./loader.ts";
import { fnContextFromHttpContext } from "./utils.tsx";
import {
type AppHttpContext,
buildImportMap,
fnContextFromHttpContext,
type FnProps,
} from "./utils.ts";

export type Apps = InstanceOf<AppRuntime, "#/root/apps">;
export type AppManifest = Omit<DecoManifest, "islands" | "routes">;
Expand Down
2 changes: 1 addition & 1 deletion blocks/appsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import type { DanglingRecover } from "../engine/manifest/manifest.ts";
import { compose, type ResolverMiddleware } from "../engine/middleware.ts";
import type { AppManifest } from "../types.ts";
import { usePreviewFunc } from "./utils.tsx";
import { usePreviewFunc } from "./utils.ts";

const resolverIsBlock = (blk: Block) => (resolver: string) => {
const splitted = resolver.split("/");
Expand Down
2 changes: 1 addition & 1 deletion blocks/flag.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { HttpContext } from "../blocks/handler.ts";
import type { Matcher } from "../blocks/matcher.ts";
import JsonViewer from "../components/JsonViewer.tsx";
import JsonViewer from "../components/JsonViewer.ts";
import type { TsType, TsTypeReference } from "../deps.ts";
import type { Block, BlockModule, InstanceOf } from "../engine/block.ts";
import { isDeferred } from "../engine/core/resolver.ts";
Expand Down
4 changes: 2 additions & 2 deletions blocks/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { wrapCaughtErrors } from "../blocks/loader.ts";
import {
newSingleFlightGroup,
type SingleFlightKeyFunc,
} from "../blocks/utils.tsx";
import JsonViewer from "../components/JsonViewer.tsx";
} from "../blocks/utils.ts";
import JsonViewer from "../components/JsonViewer.ts";
import type { Block, BlockModule } from "../engine/block.ts";
import type { HandlerContext } from "../engine/manifest/manifest.ts";
import type { DecoState, LoaderFunction } from "../types.ts";
Expand Down
2 changes: 1 addition & 1 deletion blocks/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
type FnContext,
fnContextFromHttpContext,
type RequestState,
} from "./utils.tsx";
} from "./utils.ts";

export interface HttpContext<
// deno-lint-ignore ban-types
Expand Down
2 changes: 1 addition & 1 deletion blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import matcherBlock from "../blocks/matcher.ts";
import sectionBlock from "../blocks/section.ts";
import workflowBlock from "../blocks/workflow.ts";
import type { Block } from "../engine/block.ts";
import pageBlock from "./page.tsx";
import pageBlock from "./page.ts";

const userDefinedBlocks: Block[] = [];

Expand Down
4 changes: 2 additions & 2 deletions blocks/loader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// deno-lint-ignore-file no-explicit-any
import JsonViewer from "../components/JsonViewer.tsx";
import JsonViewer from "../components/JsonViewer.ts";
import { RequestContext } from "../deco.ts";
import { ValueType, weakcache } from "../deps.ts";
import type { Block, BlockModule, InstanceOf } from "../engine/block.ts";
Expand All @@ -18,7 +18,7 @@ import {
type FnProps,
type RequestState,
type SingleFlightKeyFunc,
} from "./utils.tsx";
} from "./utils.ts";

export type Loader = InstanceOf<typeof loaderBlock, "#/root/loaders">;

Expand Down
2 changes: 1 addition & 1 deletion blocks/matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { HttpContext } from "../blocks/handler.ts";
import { getCookies, Murmurhash3, setCookie } from "../deps.ts";
import type { Block, BlockModule, InstanceOf } from "../engine/block.ts";
import type { Device } from "../utils/userAgent.ts";
import type { RequestState } from "./utils.tsx";
import type { RequestState } from "./utils.ts";

export type Matcher = InstanceOf<typeof matcherBlock, "#/root/matchers">;

Expand Down
16 changes: 8 additions & 8 deletions blocks/mod.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
export type { WorkflowGen } from "@deco/durable";
export {
type SectionContext,
SectionContext as SectionCtx,
} from "../components/section.tsx";
SectionContext as SectionCtx, type SectionContext
} from "../components/section.ts";
export type { ComponentFunc, ComponentMetadata } from "../engine/block.ts";
export type { Resolvable } from "../engine/core/resolver.ts";
export type { Accounts } from "./account.ts";
Expand All @@ -12,21 +11,22 @@ export type {
AppMiddlewareContext,
Apps,
ImportMap,
ManifestOf,
ManifestOf
} from "./app.ts";
export type { Flag, FlagObj, MultivariateFlag, Variant } from "./flag.ts";
export type { Handler } from "./handler.ts";
export { default as blocks, defineBlock } from "./index.ts";
export type { Loader } from "./loader.ts";
export type { MatchContext, Matcher } from "./matcher.ts";
export type { Page } from "./page.tsx";
export type { Page } from "./page.ts";
export { isSection, type Section } from "./section.ts";
export {
applyProps,
buildImportMap,
buildImportMapWith,
createBagKey,
} from "./utils.tsx";
export type { FnProps } from "./utils.tsx";
createBagKey
} from "./utils.ts";
export type { FnProps } from "./utils.ts";
export { WorkflowContext } from "./workflow.ts";
export type { Workflow, WorkflowFn } from "./workflow.ts";

9 changes: 5 additions & 4 deletions blocks/page.tsx → blocks/page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// deno-lint-ignore-file no-explicit-any
/** @jsxRuntime automatic */
/** @jsxImportSource preact */

import { jsx as _jsx } from "preact/jsx-runtime";
import type { Block, InstanceOf, ResolverLike } from "../engine/block.ts";
import { createSectionBlock, type SectionModule } from "./section.ts";

Expand All @@ -27,7 +25,10 @@ const page: Block<
any
> = createSectionBlock(
(component, ComponentFunc) => (props, { resolveChain }) => ({
Component: (p) => <ComponentFunc {...p} />,
Component: (p) =>
/*#__PURE__*/ _jsx(ComponentFunc, {
...p,
}),
props,
metadata: { resolveChain, component },
}),
Expand Down
2 changes: 1 addition & 1 deletion blocks/propsLoader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// deno-lint-ignore-file no-explicit-any
import type { FnProps } from "../blocks/utils.tsx";
import type { FnProps } from "../blocks/utils.ts";
import type {
Diff,
Intersection,
Expand Down
9 changes: 3 additions & 6 deletions blocks/section.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ import type { ComponentType, JSX } from "preact";
import type { AppManifest } from "../blocks/app.ts";
import type { HttpContext } from "../blocks/handler.ts";
import { type PropsLoader, propsLoader } from "../blocks/propsLoader.ts";
import {
fnContextFromHttpContext,
type RequestState,
} from "../blocks/utils.tsx";
import StubSection, { Empty } from "../components/StubSection.tsx";
import { alwaysThrow, withSection } from "../components/section.tsx";
import StubSection, { Empty } from "../components/StubSection.ts";
import { alwaysThrow, withSection } from "../components/section.ts";
import { Context } from "../deco.ts";
import type { DeepPartial } from "../deps.ts";
import type {
Expand All @@ -20,6 +16,7 @@ import type {
} from "../engine/block.ts";
import type { Resolver } from "../engine/core/resolver.ts";
import { HttpError } from "../engine/errors.ts";
import { fnContextFromHttpContext, type RequestState } from "./utils.ts";

/**
* @widget none
Expand Down
11 changes: 4 additions & 7 deletions blocks/utils.tsx → blocks/utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
/** @jsxRuntime automatic */
/** @jsxImportSource preact */

// deno-lint-ignore-file no-explicit-any
import type { StatusCode as Status } from "@std/http/status";
import type { JSX } from "preact";
import type { AppManifest, ImportMap } from "../blocks/app.ts";
import { isInvokeCtx } from "../blocks/loader.ts";
import type { InvocationFunc } from "../clients/withManifest.ts";
import { withSection } from "../components/section.tsx";
import { withSection } from "../components/section.ts";
import type {
Block,
BlockModule,
Expand All @@ -25,8 +20,10 @@ import type { Flag } from "../types.ts";
import { buildInvokeFunc } from "../utils/invoke.server.ts";
import type { InvocationProxy } from "../utils/invoke.types.ts";
import { type Device, deviceOf, isBot as isUABot } from "../utils/userAgent.ts";
import type { HttpContext } from "./handler.ts";
import type { Vary } from "../utils/vary.ts";
import type { AppManifest, ImportMap } from "./app.ts";
import type { HttpContext } from "./handler.ts";
import { isInvokeCtx } from "./loader.ts";

export type SingleFlightKeyFunc<TConfig = any, TCtx = any> = (
args: TConfig,
Expand Down
8 changes: 4 additions & 4 deletions blocks/workflow.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// deno-lint-ignore-file no-explicit-any
import {
type Arg,
type LocalActivityCommand,
type Metadata,
type Workflow as DurableWorkflow,
WorkflowContext as DurableWorkflowContext,
type LocalActivityCommand,
type Metadata,
type WorkflowExecution,
} from "../deps.ts";
import type { Block, BlockModule, InstanceOf } from "../engine/block.ts";
import type { AppManifest, DecoSiteState, DecoState } from "../types.ts";
import type {
AvailableActions,
AvailableFunctions,
Expand All @@ -18,14 +19,13 @@ import type {
ManifestFunction,
ManifestLoader,
} from "../utils/invoke.types.ts";
import type { AppManifest, DecoSiteState, DecoState } from "../types.ts";
import type { DotNestedKeys } from "../utils/object.ts";
import type { HttpContext } from "./handler.ts";
import {
type FnContext,
fnContextFromHttpContext,
type RequestState,
} from "./utils.tsx";
} from "./utils.ts";

export interface WorkflowMetadata extends Metadata {
defaultInvokeHeaders?: Record<string, string>;
Expand Down
39 changes: 23 additions & 16 deletions components/JsonViewer.tsx → components/JsonViewer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/** @jsxRuntime automatic */
/** @jsxImportSource preact */

import { useFramework } from "../runtime/handler.tsx";
import type { JSX } from "preact";
import {
Fragment as _Fragment,
jsx as _jsx,
jsxs as _jsxs,
} from "preact/jsx-runtime";
import { useFramework } from "../runtime/handler.ts";

export interface Props {
body: string;
Expand Down Expand Up @@ -52,16 +54,21 @@ const snippet = (json: string) => {
*/
export default function JsonViewer(p: Props): JSX.Element {
const { Head } = useFramework();
return (
<>
{/** @ts-ignore: could not type it well */}
<Head>
<script
type="module"
dangerouslySetInnerHTML={{ __html: `(${snippet})(${p.body});` }}
/>
</Head>
<pre id="json-renderer">{p.body}</pre>
</>
);
return /*#__PURE__*/ _jsxs(_Fragment, {
children: [
// @ts-expect-error: JSX does not have a script element
/*#__PURE__*/ _jsx(Head, {
children: /*#__PURE__*/ _jsx("script", {
type: "module",
dangerouslySetInnerHTML: {
__html: `(${snippet})(${p.body});`,
},
}),
}),
/*#__PURE__*/ _jsx("pre", {
id: "json-renderer",
children: p.body,
}),
],
});
}
44 changes: 25 additions & 19 deletions components/LiveControls.tsx → components/LiveControls.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/** @jsxRuntime automatic */
/** @jsxImportSource preact */

import {
Fragment as _Fragment,
jsx as _jsx,
jsxs as _jsxs,
} from "preact/jsx-runtime";
import { context } from "../deco.ts";
import { DomInspector, DomInspectorActivators } from "../deps.ts";
import type { Flag, Site } from "../types.ts";
Expand Down Expand Up @@ -174,23 +176,27 @@ const main = () => {
};

function LiveControls({ site, page, flags }: Props) {
return (
<>
<script
type="application/json"
id="__DECO_STATE"
dangerouslySetInnerHTML={{
__html: JSON.stringify({ page, site, flags }),
}}
/>
<script
type="module"
dangerouslySetInnerHTML={{
return /*#__PURE__*/ _jsxs(_Fragment, {
children: [
/*#__PURE__*/ _jsx("script", {
type: "application/json",
id: "__DECO_STATE",
dangerouslySetInnerHTML: {
__html: JSON.stringify({
page,
site,
flags,
}),
},
}),
/*#__PURE__*/ _jsx("script", {
type: "module",
dangerouslySetInnerHTML: {
__html: `${domInspectorModule}\n(${main})()`,
}}
/>
</>
);
},
}),
],
});
}

export default LiveControls;
11 changes: 11 additions & 0 deletions components/PreviewNotAvailable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { jsxs as _jsxs } from "preact/jsx-runtime";

export default function PreviewNotAvailable({ block }: { block: string }) {
return /*#__PURE__*/ _jsxs("div", {
children: [
"The preview of ",
block,
" is not available.",
],
});
}
6 changes: 0 additions & 6 deletions components/PreviewNotAvailable.tsx

This file was deleted.

Loading
Loading