@kivacore/dom-selector-client 0.0.0 → 0.7.0
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/README.md +82 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1467 -0
- package/package.json +41 -4
- package/src/babel-plugin-component-annotate.ts +419 -0
- package/src/dom-selector-helper.js +604 -0
package/README.md
CHANGED
|
@@ -1,3 +1,84 @@
|
|
|
1
1
|
# @kivacore/dom-selector-client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A simple CLI that prepares your Vite or Astro project for interactive element selection during development. It injects a lightweight helper script and annotates elements with useful data attributes so external tools can highlight and reference them.
|
|
4
|
+
|
|
5
|
+
- Adds a dev-only Vite plugin that serves and injects `dom-selector-helper.js`
|
|
6
|
+
- For React projects, adds a Babel plugin to annotate JSX elements with `data-component-*`
|
|
7
|
+
- For Astro/vanilla projects, adds an HTML transform to annotate tags with `data-component-*`
|
|
8
|
+
- Touches only config and adds helper files; no runtime dependency in production
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
- pnpm: `pnpm add -D @kivacore/dom-selector-client`
|
|
12
|
+
- npm: `npm i -D @kivacore/dom-selector-client`
|
|
13
|
+
- yarn: `yarn add -D @kivacore/dom-selector-client`
|
|
14
|
+
|
|
15
|
+
Requires Node 18+.
|
|
16
|
+
|
|
17
|
+
## One-Line Setup
|
|
18
|
+
- npx: `npx @kivacore/dom-selector-client@latest setup`
|
|
19
|
+
- pnpm: `pnpm dlx @kivacore/dom-selector-client@latest setup`
|
|
20
|
+
- yarn: `yarn dlx @kivacore/dom-selector-client@latest setup`
|
|
21
|
+
|
|
22
|
+
`setup` will:
|
|
23
|
+
- install `@kivacore/dom-selector-client` as a dev dependency if it is missing
|
|
24
|
+
- install `@babel/core` automatically for React projects if it is missing
|
|
25
|
+
- run the project configuration step described below
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
- npx: `npx dom-selector setup`
|
|
29
|
+
- pnpm: `pnpm dlx dom-selector setup`
|
|
30
|
+
- already installed: `dom-selector install`
|
|
31
|
+
|
|
32
|
+
The installer will:
|
|
33
|
+
- Detect Astro vs. Vite and framework flavor (React or vanilla)
|
|
34
|
+
- Copy `dom-selector-helper.js` to your project root (if not present)
|
|
35
|
+
- Update `astro.config.*` or `vite.config.*` to inject a dev-only plugin that includes the helper
|
|
36
|
+
- For React projects, copy `babel-plugin-component-annotate.ts` to your project root and register a Babel transform in Vite to add `data-component-name` and `data-component-path` attributes to JSX elements during dev
|
|
37
|
+
|
|
38
|
+
No changes are made if your config is already set up.
|
|
39
|
+
|
|
40
|
+
## What It Adds
|
|
41
|
+
- Dev-only Vite plugin: injects `<script type="module" src="/dom-selector-helper.js"></script>` into HTML and serves the file from the project root
|
|
42
|
+
- React: Babel plugin that annotates all JSX opening elements with:
|
|
43
|
+
- `data-component-name`: The element/component name
|
|
44
|
+
- `data-component-path`: Relative file path with line:column (e.g. `src/App.tsx:12:5`)
|
|
45
|
+
- Astro/vanilla: A Vite transform that annotates HTML tags (outside frontmatter/script/style blocks) with the same attributes
|
|
46
|
+
|
|
47
|
+
Annotations are added only in development. The helper and plugins are inert in production builds.
|
|
48
|
+
|
|
49
|
+
## Using The Helper
|
|
50
|
+
The injected `dom-selector-helper.js` listens for postMessage events:
|
|
51
|
+
- Enable: `window.postMessage({ type: 'DOCY_SELECTOR', action: 'enable' }, '*')`
|
|
52
|
+
- Disable: `window.postMessage({ type: 'DOCY_SELECTOR', action: 'disable' }, '*')`
|
|
53
|
+
|
|
54
|
+
When enabled, hovering highlights elements, and clicking sends a message to `window.parent`:
|
|
55
|
+
|
|
56
|
+
- `{ type: 'DOCY_SELECTOR', action: 'elementSelected', payload: { rect, componentName, filePath, componentPath, selector, tagName, className, hasTextContent, textContent, src } }`
|
|
57
|
+
|
|
58
|
+
This is designed to work inside iframes or dev UIs that consume the selection signal.
|
|
59
|
+
|
|
60
|
+
## Files Touched
|
|
61
|
+
- Project root:
|
|
62
|
+
- `dom-selector-helper.js` (copied if missing)
|
|
63
|
+
- `babel-plugin-component-annotate.ts` (React projects, copied if missing)
|
|
64
|
+
- Config:
|
|
65
|
+
- `astro.config.*` or `vite.config.*` updated to register dev-only plugins
|
|
66
|
+
|
|
67
|
+
You can remove these changes by deleting the two files and reverting the plugin additions in your config.
|
|
68
|
+
|
|
69
|
+
## Notes
|
|
70
|
+
- React requires `@babel/core` for the inline transform. If it’s not found, the installer will warn you to install it: `npm i -D @babel/core`.
|
|
71
|
+
- Vue support: the helper is injected, but element annotation is not yet implemented for Vue components.
|
|
72
|
+
|
|
73
|
+
## CLI
|
|
74
|
+
- `dom-selector setup`
|
|
75
|
+
- Installs `@kivacore/dom-selector-client` into the target project and configures it
|
|
76
|
+
- React projects also get `@babel/core` installed automatically when missing
|
|
77
|
+
- Options: `-d, --directory <dir>` target project directory (defaults to CWD)
|
|
78
|
+
- `dom-selector install`
|
|
79
|
+
- Configures the target project when dependencies are already installed
|
|
80
|
+
- Options: `-d, --directory <dir>` target project directory (defaults to CWD)
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|