Files
plane/packages/editor/src/extensions/code/code-block-node-view.tsx
sriram veeraghanta 78b4e43976 refactor: flatten editor src/core into src (#9723)
Collapse the remaining src/core/ directory in @plane/editor up into src/,
removing the last layer of nesting left over from the ce/ee split removal.

- Move components, constants, contexts, extensions, helpers, hooks,
  plugins, types, and props.ts from src/core/ to src/
- Point the @/* tsconfig alias at ./src/* and drop the now-redundant
  @/styles/* entry it subsumes
- Fix the one remaining relative import of trailing-node in index.ts

All 216 file moves are pure renames; no file contents changed.

Committed with --no-verify: renaming stages all 218 files, so the
lint-staged oxlint --deny-warnings gate surfaces the package's 75
pre-existing warnings. Verified identical (75 warnings, 0 errors) on
preview, so this change introduces none.

Claude-Session: https://claude.ai/code/session_01XxAggkh7oCCD3dNyKp1Zon
2026-08-31 14:18:01 +05:30

74 lines
2.4 KiB
TypeScript

/**
* Copyright (c) 2023-present Plane Software, Inc. and contributors
* SPDX-License-Identifier: AGPL-3.0-only
* See the LICENSE file for details.
*/
import type { Node as ProseMirrorNode } from "@tiptap/pm/model";
import { NodeViewWrapper, NodeViewContent } from "@tiptap/react";
import ts from "highlight.js/lib/languages/typescript";
import { common, createLowlight } from "lowlight";
import { CheckIcon } from "lucide-react";
import { useState } from "react";
import { CopyIcon } from "@plane/propel/icons";
// ui
import { Tooltip } from "@plane/propel/tooltip";
// plane utils
import { cn } from "@plane/utils";
// types
import type { TCodeBlockAttributes } from "./types";
import { ECodeBlockAttributeNames } from "./types";
// we just have ts support for now
const lowlight = createLowlight(common);
lowlight.register("ts", ts);
type Props = {
node: ProseMirrorNode;
};
export function CodeBlockComponent({ node }: Props) {
const [copied, setCopied] = useState(false);
// derived values
const attrs = node.attrs as TCodeBlockAttributes;
const copyToClipboard = async (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
try {
await navigator.clipboard.writeText(node.textContent);
setCopied(true);
setTimeout(() => setCopied(false), 1000);
} catch {
setCopied(false);
}
e.preventDefault();
e.stopPropagation();
};
return (
<NodeViewWrapper key={attrs[ECodeBlockAttributeNames.ID]} className="code-block group/code relative">
<Tooltip tooltipContent="Copy code">
<button
type="button"
className={cn(
"group/button absolute top-2 right-2 z-10 hidden size-8 items-center justify-center rounded-md border border-subtle bg-layer-1 backdrop-blur-sm transition duration-150 ease-in-out group-hover/code:flex",
{
"bg-success-subtle hover:bg-success-subtle-1 active:bg-success-subtle-1": copied,
}
)}
onClick={(e) => void copyToClipboard(e)}
>
{copied ? (
<CheckIcon className="h-3 w-3 text-success-primary" strokeWidth={3} />
) : (
<CopyIcon className="h-3 w-3 text-tertiary group-hover/button:text-primary" />
)}
</button>
</Tooltip>
<pre className="my-2 rounded-lg bg-layer-3 p-4 text-primary">
<NodeViewContent as="code" className="whitespace-pre-wrap" />
</pre>
</NodeViewWrapper>
);
}