GithubHelp home page GithubHelp logo

kbwo / http-tsx-source-jump Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mizchi/tsx-source-jump

1.0 0.0 0.0 99 KB

Jump from the HTML element to the source code of the generator

TypeScript 97.21% HTML 2.79%

http-tsx-source-jump's Introduction

http-tsx-source-jump

Jump from the HTML element to the source code of the generator.

How it works

this plugin is customized to use in vim.

How to use

Install

yarn add http-tsx-source-jump -D

Vite

// vite.config.ts
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
import { tsxSourceJump } from "tsx-source-jump/vite";

export default defineConfig({
  plugins: [
    // DO NOT INCLUDE IN PRODUCTION
    ...(process.env.NODE_ENV !== "production"
      ? [
          tsxSourceJump({
            // your projectRoot
            projectRoot: __dirname + "/",
            // rewriting element target
            target: [/^[a-z]+$/],
            port: 3333,
          }),
        ]
      : []),
    react(),
  ],
});

(Current tsx-source-jump rewrites .tsx to .tsx to work with any ts compiler (tsc, esbuild, swc). It may causes performance problem)

Mount Overlay

// entrypoint
import React from "react";
import ReactDOM from "react-dom";
import { App } from "./App";
import { SourceJumpOverlayPortal } from "tsx-source-jump/runtime";

ReactDOM.render(
  <React.StrictMode>
    <SourceJumpOverlayPortal />
    <App />
  </React.StrictMode>,
  document.getElementById("root")
);

Jump!

  • Enter your vite app (http://localhost:3000)
  • Press Shift and move cursor to element you want to open
  • Click element path

with primitive dom wrapper like charkra-ui / react-native-elements ...

tsx-source-jump adds data-sj-path="..." for target options.

// vite.config.ts
tsxSourceJump({
  projectRoot: __dirname + "/",
  target: [
    // default target: div, main, span...
    /^[a-z]+$/,
    // Additional targets for chakra-ui
    /^(Box|Flex|Center|Container|Grid|SimpleGrid|Stack|Wrap|Button|Link|Icon|Image)$/,
  ],
});

Targeted elements should pass data-sj-* to raw elements.

How it works internal

tsx-source-jump/vite's typescript transformer adds data-sj-* as props.

// from
<div>
  xxx
</div>

// to
<div data-sj-path="..." data-sj-display-name="...">
  xxx
</div>

In browser, SourceJumpOverlayPortal component catches mouseover events and overlay ui.

TODO

  • Support other framework
  • Support swc, babel
  • Lightweight runtime (preact)
  • Inline Code Editor

LICENSE

MIT

Special Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.