Skip to content
Merged
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
3 changes: 3 additions & 0 deletions editor-packages/editor-preview-pip/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This shall not be included on npm.
// Re-exporter for use-as-submodule
export * from "./lib";
44 changes: 44 additions & 0 deletions editor-packages/editor-preview-pip/lib/context-menu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { useState } from "react";
import * as ContextMenu from "@radix-ui/react-context-menu";
import {
ContextMenuContent,
ContextMenuCheckboxItem,
ContextMenuTrigger,
ContextMenuItem,
} from "@modulz/design-system";
import { BlockFrameInteraction } from "./preferences";

export default function VanillaFrameContextManuProvider({
children,
}: {
children: React.ReactNode;
}) {
return (
<ContextMenu.Root>
<ContextMenuTrigger>{children}</ContextMenuTrigger>

<ContextMenuContent>
<AllowInteractionPreferenceMenu />
</ContextMenuContent>
</ContextMenu.Root>
);
}

function AllowInteractionPreferenceMenu() {
const [allowInteraction, setAllowInteraction] = useState(
BlockFrameInteraction.get()
);

return (
<ContextMenuCheckboxItem
checked={allowInteraction}
onSelect={() => {
const inverted = !allowInteraction;
BlockFrameInteraction.set(inverted);
setAllowInteraction(inverted);
}}
>
<ContextMenu.Label>Allow interaction</ContextMenu.Label>
</ContextMenuCheckboxItem>
);
}
6 changes: 6 additions & 0 deletions editor-packages/editor-preview-pip/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ import PIP from "./pip";
import ResizablePIP from "./resizable-pip";

export { PIP, ResizablePIP };

import VanillaFrameContextManuProvider from "./context-menu";

export { VanillaFrameContextManuProvider };

export * as preference from "./preferences";
4 changes: 3 additions & 1 deletion editor-packages/editor-preview-pip/lib/pip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ function PIP({
backgroundColor?: string;
}) {
return (
<Draggable>
<Draggable handle=".handle" bounds="parent">
<PipWindow
className="handle"
id="handle"
borderRadius={borderRadius}
boxShadow={boxShadow}
zIndex={zIndex}
Expand Down
18 changes: 18 additions & 0 deletions editor-packages/editor-preview-pip/lib/preferences.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const BlockFrameInteraction = {
get: () => {
if (typeof window !== "undefined") {
return (
window.localStorage.getItem("vanilla-interaction-block-preference") ===
"true"
);
}
},
set: (interaction: boolean) => {
if (typeof window !== "undefined") {
window.localStorage.setItem(
"vanilla-interaction-block-preference",
String(interaction)
);
}
},
};
12 changes: 7 additions & 5 deletions editor-packages/editor-preview-pip/lib/resizable-pip.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import PIP from "./PIP";
import PIP from "./pip";
import { ResizableBox } from "react-resizable";
import "react-resizable/css/styles.css";
import type { ResizableBoxProps as RawResizableBoxProps } from "react-resizable";
import styled from "@emotion/styled";

Expand Down Expand Up @@ -52,6 +53,11 @@ function ResizablePIP({
return (
<PIP>
<StyledResizableBox
draggableOpts={{
onMouseDown: (e) => {
e.stopPropagation();
},
}}
{...otherResizableProps}
axis={axis}
handle={resizeHandle}
Expand All @@ -68,10 +74,6 @@ function ResizablePIP({

const StyledResizableBox = styled(ResizableBox)`
overflow: auto;

:hover {
cursor: default;
}
`;

export default ResizablePIP;
1 change: 1 addition & 0 deletions editor-packages/editor-preview-pip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
],
"repository": "https://github.com/gridaco/designto-code",
"dependencies": {
"@radix-ui/react-context-menu": "^0.1.1",
"react-draggable": "^4.4.4",
"react-resizable": "^3.0.4"
},
Expand Down
7 changes: 6 additions & 1 deletion editor-packages/editor-preview-pip/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@
"noUnusedLocals": false,
"sourceMap": false
},
"exclude": ["node_modules", "**/*.spec.ts", "dist"]
"exclude": [
"node_modules",
"**/*.spec.ts",
"dist",
"index.ts" // index.ts is for monorepo use
]
}
32 changes: 30 additions & 2 deletions editor-packages/editor-preview-vanilla/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
# Vanilla preview

![](./docs/assets/example-of-vanilla-preview-on-grida-assistant.png)

## Installation

```sh
yarn add @code-editor/vanilla-preview
```

## Usage

```tsx
import { VanillaPreview } from "@code-editor/vanilla-preview";

export default function () {
return <VanillaPreview />;
}
```

## Disable overflow

## Scaling

## Autoscale with margin value (horizontal margin)

## Todo: Cached preview for optimization

while repositioning, rescaling the html iframe with large content, it may be more performant to cache the preview and use them while transition is happening.

## Used by

- code.grida.co
- assistant/@ui/previewer
- [code.grida.co](https://github.com/gridaco/designto-code)
- [assistant/@ui/previewer](https://github.com/gridaco/assistant)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions editor-packages/editor-preview-vanilla/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@code-editor/vanilla-preview",
"version": "0.0.0",
"private": "false"
}
1 change: 1 addition & 0 deletions editor/next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const withTM = require("next-transpile-modules")([
// region @editor-app
"@editor-app/live-session",
"@code-editor/preview-pip", // TODO: remove me. this is for development. for production, use npm ver instead.

// region editor-submodule deps
"@base-sdk-fp/auth",
Expand Down
3 changes: 2 additions & 1 deletion editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@material-ui/core": "^4.12.3",
"@material-ui/icons": "^4.11.2",
"@material-ui/lab": "^4.0.0-alpha.60",
"@modulz/design-system": "^0.6.1",
"@monaco-editor/react": "^4.1.3",
"@reflect-blocks/figma-embed": "^0.0.5",
"@reflect-ui/editor-ui": "0.0.1",
Expand Down Expand Up @@ -55,4 +56,4 @@
"raw-loader": "^4.0.2",
"typescript": "^4.2.3"
}
}
}
Loading