mitway-tagger 1.3.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 +256 -0
- package/dist/index.cjs +909 -0
- package/dist/index.d.cts +204 -0
- package/dist/index.d.ts +204 -0
- package/dist/index.js +865 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# mITway Tagger
|
|
2
|
+
|
|
3
|
+
Vite plugin suite for Mesh IT Midway integration. Provides everything needed for the mITway-Starter template to communicate with mITway-App.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
| Feature | Description |
|
|
8
|
+
|---------|-------------|
|
|
9
|
+
| **JSX Source Tracking** | Injects source location metadata into React components for visual editing |
|
|
10
|
+
| **Virtual Overrides** | Temporary file modifications with HMR support (no disk writes) |
|
|
11
|
+
| **Visual Editor** | Element selection and live style preview via postMessage |
|
|
12
|
+
| **Iframe Navigation** | Notifies parent window of navigation changes |
|
|
13
|
+
| **Theme Bridge** | Real-time theme preview from mITway-App |
|
|
14
|
+
| **Server Config** | Pre-configured CORS and CSP settings for iframe integration |
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pnpm add -D mitway-tagger
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Basic (all features enabled)
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
// vite.config.ts
|
|
28
|
+
import { defineConfig } from 'vite';
|
|
29
|
+
import react from '@vitejs/plugin-react-swc';
|
|
30
|
+
import { mitwayTagger } from 'mitway-tagger';
|
|
31
|
+
|
|
32
|
+
export default defineConfig({
|
|
33
|
+
plugins: [
|
|
34
|
+
react(),
|
|
35
|
+
...mitwayTagger()
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### With options
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { mitwayTagger } from 'mitway-tagger';
|
|
44
|
+
|
|
45
|
+
export default defineConfig({
|
|
46
|
+
plugins: [
|
|
47
|
+
react(),
|
|
48
|
+
...mitwayTagger({
|
|
49
|
+
jsxSource: true, // JSX source tracking (default: true)
|
|
50
|
+
virtualOverrides: true, // Virtual file overrides (default: true)
|
|
51
|
+
visualEditor: true, // Visual editor support (default: true)
|
|
52
|
+
iframeNavigation: true, // Iframe navigation events (default: true)
|
|
53
|
+
themeBridge: true, // Theme preview bridge (default: true)
|
|
54
|
+
})
|
|
55
|
+
]
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Individual plugins
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import {
|
|
63
|
+
createJsxSourcePlugin,
|
|
64
|
+
createVirtualOverridesPlugin,
|
|
65
|
+
createVisualEditorPlugin,
|
|
66
|
+
createIframeNavigationPlugin,
|
|
67
|
+
createThemeBridgePlugin
|
|
68
|
+
} from 'mitway-tagger';
|
|
69
|
+
|
|
70
|
+
export default defineConfig({
|
|
71
|
+
plugins: [
|
|
72
|
+
react(),
|
|
73
|
+
createJsxSourcePlugin({ extensions: ['.tsx'], exclude: ['node_modules'] }),
|
|
74
|
+
createVisualEditorPlugin(),
|
|
75
|
+
createThemeBridgePlugin(),
|
|
76
|
+
// ... only the plugins you need
|
|
77
|
+
]
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Features Detail
|
|
82
|
+
|
|
83
|
+
### 1. JSX Source Tracking
|
|
84
|
+
|
|
85
|
+
Intercepts `react/jsx-dev-runtime` to attach source location metadata to DOM nodes via a Symbol. This enables the Visual Editor to map selected elements back to their source code.
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
// How it works:
|
|
89
|
+
// Every React element gets a Symbol attached with source info
|
|
90
|
+
element[Symbol.for('__mitwaySource__')] = {
|
|
91
|
+
fileName: '/src/components/Button.tsx',
|
|
92
|
+
lineNumber: 42,
|
|
93
|
+
columnNumber: 8
|
|
94
|
+
};
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 2. Virtual Overrides
|
|
98
|
+
|
|
99
|
+
Allows mITway-App to send temporary file modifications via WebSocket. Changes are applied in-memory and trigger HMR without writing to disk.
|
|
100
|
+
|
|
101
|
+
**WebSocket events:**
|
|
102
|
+
- `mitway:override` - Apply temporary file override
|
|
103
|
+
- `mitway:clear-override` - Clear override for a file
|
|
104
|
+
- `mitway:clear-all-overrides` - Clear all overrides
|
|
105
|
+
|
|
106
|
+
### 3. Visual Editor
|
|
107
|
+
|
|
108
|
+
Injects a script that enables:
|
|
109
|
+
- Element highlighting on hover
|
|
110
|
+
- Element selection with visual overlay
|
|
111
|
+
- Live style preview via inline styles
|
|
112
|
+
- Communication with parent window via postMessage
|
|
113
|
+
|
|
114
|
+
**Message types (to parent):**
|
|
115
|
+
- `VISUAL_EDITOR_ELEMENT_SELECTED` - Element was selected
|
|
116
|
+
- `VISUAL_EDITOR_ELEMENT_DESELECTED` - Selection cleared
|
|
117
|
+
- `VISUAL_EDITOR_HOVER` - Element being hovered
|
|
118
|
+
|
|
119
|
+
**Message types (from parent):**
|
|
120
|
+
- `VISUAL_EDITOR_ACTIVATE` - Enable selection mode
|
|
121
|
+
- `VISUAL_EDITOR_DEACTIVATE` - Disable selection mode
|
|
122
|
+
- `VISUAL_EDITOR_PREVIEW_STYLE` - Preview styles on element
|
|
123
|
+
- `VISUAL_EDITOR_RESTORE_STYLE` - Restore original styles
|
|
124
|
+
|
|
125
|
+
### 4. Iframe Navigation
|
|
126
|
+
|
|
127
|
+
Notifies mITway-App when navigation occurs within the iframe:
|
|
128
|
+
- Intercepts `history.pushState` and `history.replaceState`
|
|
129
|
+
- Listens for `popstate` events
|
|
130
|
+
- Sends `IFRAME_NAVIGATION` messages to parent
|
|
131
|
+
- Receives `NAVIGATE_TO` commands from parent
|
|
132
|
+
|
|
133
|
+
### 5. Theme Bridge
|
|
134
|
+
|
|
135
|
+
Enables real-time theme preview:
|
|
136
|
+
- Captures original CSS variable values
|
|
137
|
+
- Applies theme colors with proper HSL wrapping
|
|
138
|
+
- Supports both base (`--background`) and color-prefixed (`--color-background`) variables
|
|
139
|
+
- Handles radius variables separately
|
|
140
|
+
|
|
141
|
+
**Message types (from parent):**
|
|
142
|
+
- `PREVIEW_THEME` - Preview theme without persisting
|
|
143
|
+
- `RESTORE_THEME` - Restore original CSS variables
|
|
144
|
+
- `APPLY_THEME` - Apply and persist theme
|
|
145
|
+
|
|
146
|
+
**Message types (to parent):**
|
|
147
|
+
- `THEME_BRIDGE_READY` - Bridge initialized
|
|
148
|
+
- `THEME_APPLIED` - Theme was applied
|
|
149
|
+
|
|
150
|
+
## Server Configuration
|
|
151
|
+
|
|
152
|
+
Mesh IT Midway requires specific CORS and CSP settings to work properly inside iframes. The package exports pre-configured server settings:
|
|
153
|
+
|
|
154
|
+
### Using `mitwayServerConfig`
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { defineConfig } from 'vite';
|
|
158
|
+
import react from '@vitejs/plugin-react-swc';
|
|
159
|
+
import path from 'path';
|
|
160
|
+
import { mitwayTagger, mitwayServerConfig } from 'mitway-tagger';
|
|
161
|
+
|
|
162
|
+
export default defineConfig({
|
|
163
|
+
plugins: [
|
|
164
|
+
react(),
|
|
165
|
+
...mitwayTagger()
|
|
166
|
+
],
|
|
167
|
+
resolve: {
|
|
168
|
+
alias: {
|
|
169
|
+
'@': path.resolve(__dirname, './src'),
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
server: mitwayServerConfig,
|
|
173
|
+
preview: mitwayServerConfig,
|
|
174
|
+
});
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### With custom domains
|
|
178
|
+
|
|
179
|
+
If you need to add custom domains to the allowed origins:
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
import { mitwayTagger, createmITwayServerConfig } from 'mitway-tagger';
|
|
183
|
+
|
|
184
|
+
const serverConfig = createmITwayServerConfig({
|
|
185
|
+
additionalOrigins: ['https://my-custom-domain.com'],
|
|
186
|
+
additionalHosts: ['.my-custom-domain.com'],
|
|
187
|
+
port: 3000, // optional, defaults to 80
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
export default defineConfig({
|
|
191
|
+
plugins: [react(), ...mitwayTagger()],
|
|
192
|
+
server: serverConfig,
|
|
193
|
+
preview: serverConfig,
|
|
194
|
+
});
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### What's included in `mitwayServerConfig`
|
|
198
|
+
|
|
199
|
+
| Setting | Value |
|
|
200
|
+
|---------|-------|
|
|
201
|
+
| **Host** | `0.0.0.0` |
|
|
202
|
+
| **Port** | `80` |
|
|
203
|
+
| **CORS Origins** | `app.nttmitway.com`, `app.dev.nttmitway.com`, `app.mitway.local`, `localhost:*` |
|
|
204
|
+
| **CORS Methods** | GET, POST, PUT, DELETE, OPTIONS |
|
|
205
|
+
| **CORS Headers** | Content-Type, Authorization |
|
|
206
|
+
| **CSP frame-ancestors** | Same as CORS origins |
|
|
207
|
+
| **Allowed Hosts** | `.azurecontainerapps.io`, `.nttmitway.com` |
|
|
208
|
+
|
|
209
|
+
## mITway-Starter Integration
|
|
210
|
+
|
|
211
|
+
With `mitway-tagger`, your `vite.config.ts` becomes minimal:
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
import { defineConfig } from 'vite';
|
|
215
|
+
import react from '@vitejs/plugin-react-swc';
|
|
216
|
+
import path from 'path';
|
|
217
|
+
import { mitwayTagger, mitwayServerConfig } from 'mitway-tagger';
|
|
218
|
+
|
|
219
|
+
export default defineConfig({
|
|
220
|
+
plugins: [react(), ...mitwayTagger()],
|
|
221
|
+
resolve: {
|
|
222
|
+
alias: {
|
|
223
|
+
'@': path.resolve(__dirname, './src'),
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
server: mitwayServerConfig,
|
|
227
|
+
preview: mitwayServerConfig,
|
|
228
|
+
});
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
No need for separate plugin files or manual CORS/CSP configuration - everything is included in `mitway-tagger`.
|
|
232
|
+
|
|
233
|
+
## Development
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
# Install dependencies
|
|
237
|
+
pnpm install
|
|
238
|
+
|
|
239
|
+
# Build
|
|
240
|
+
pnpm build
|
|
241
|
+
|
|
242
|
+
# Watch mode
|
|
243
|
+
pnpm dev
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Publishing
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
# Build and publish
|
|
250
|
+
pnpm build
|
|
251
|
+
npm publish
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## License
|
|
255
|
+
|
|
256
|
+
MIT
|