@duongthiu/onex-core 0.1.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 +428 -0
- package/THEME_API.md +681 -0
- package/dist/api-vuL1Eg5L.d.mts +2961 -0
- package/dist/api-vuL1Eg5L.d.ts +2961 -0
- package/dist/chunk-3SZX6LHT.js +244 -0
- package/dist/chunk-3SZX6LHT.js.map +1 -0
- package/dist/chunk-7EON6Q4L.mjs +8149 -0
- package/dist/chunk-7EON6Q4L.mjs.map +1 -0
- package/dist/chunk-WDY773GJ.js +8308 -0
- package/dist/chunk-WDY773GJ.js.map +1 -0
- package/dist/chunk-XE4EOKS4.mjs +239 -0
- package/dist/chunk-XE4EOKS4.mjs.map +1 -0
- package/dist/client.d.mts +1461 -0
- package/dist/client.d.ts +1461 -0
- package/dist/client.js +542 -0
- package/dist/client.js.map +1 -0
- package/dist/client.mjs +5 -0
- package/dist/client.mjs.map +1 -0
- package/dist/index.d.mts +125 -0
- package/dist/index.d.ts +125 -0
- package/dist/index.js +601 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +61 -0
- package/dist/index.mjs.map +1 -0
- package/dist/server.d.mts +70 -0
- package/dist/server.d.ts +70 -0
- package/dist/server.js +196 -0
- package/dist/server.js.map +1 -0
- package/dist/server.mjs +188 -0
- package/dist/server.mjs.map +1 -0
- package/package.json +113 -0
package/README.md
ADDED
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
# @onex/core
|
|
2
|
+
|
|
3
|
+
Core package for the OneX theme marketplace - provides types, components, and utilities for building third-party themes.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @onex/core react react-dom
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @onex/core react react-dom
|
|
11
|
+
# or
|
|
12
|
+
yarn add @onex/core react react-dom
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
### For Theme Developers
|
|
18
|
+
|
|
19
|
+
Create a new theme using `@onex/core`:
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
// src/index.ts
|
|
23
|
+
import type { ThemeModule, SectionComponentProps } from "@onex/core"
|
|
24
|
+
import { ButtonComponent, Heading } from "@onex/core/client"
|
|
25
|
+
|
|
26
|
+
// 1. Define your section components
|
|
27
|
+
export function HeroMinimal({ section }: SectionComponentProps) {
|
|
28
|
+
return (
|
|
29
|
+
<section className="hero">
|
|
30
|
+
<Heading level={1}>{section.settings.title}</Heading>
|
|
31
|
+
<ButtonComponent href={section.settings.ctaUrl}>
|
|
32
|
+
{section.settings.ctaText}
|
|
33
|
+
</ButtonComponent>
|
|
34
|
+
</section>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 2. Create theme manifest
|
|
39
|
+
export const manifest = {
|
|
40
|
+
id: "my-theme",
|
|
41
|
+
name: "My Theme",
|
|
42
|
+
version: "1.0.0",
|
|
43
|
+
author: {
|
|
44
|
+
name: "Your Name",
|
|
45
|
+
email: "you@example.com"
|
|
46
|
+
},
|
|
47
|
+
engine: "^1.0.0",
|
|
48
|
+
peerDependencies: {
|
|
49
|
+
react: "^19.0.0",
|
|
50
|
+
"react-dom": "^19.0.0"
|
|
51
|
+
},
|
|
52
|
+
sections: ["hero-minimal"],
|
|
53
|
+
config: themeConfig,
|
|
54
|
+
exports: {
|
|
55
|
+
main: "./dist/index.mjs"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 3. Export theme module
|
|
60
|
+
export const theme: ThemeModule = {
|
|
61
|
+
manifest,
|
|
62
|
+
config: themeConfig,
|
|
63
|
+
sections: {
|
|
64
|
+
"hero-minimal": HeroMinimal
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default theme
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Build Configuration
|
|
72
|
+
|
|
73
|
+
Use esbuild with externalized dependencies:
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
// esbuild.config.js
|
|
77
|
+
const esbuild = require("esbuild")
|
|
78
|
+
|
|
79
|
+
esbuild.build({
|
|
80
|
+
entryPoints: ["src/index.ts"],
|
|
81
|
+
bundle: true,
|
|
82
|
+
format: "esm",
|
|
83
|
+
outfile: "dist/index.mjs",
|
|
84
|
+
external: [
|
|
85
|
+
"@onex/core",
|
|
86
|
+
"@onex/core/client",
|
|
87
|
+
"react",
|
|
88
|
+
"react-dom"
|
|
89
|
+
],
|
|
90
|
+
minify: true,
|
|
91
|
+
sourcemap: true
|
|
92
|
+
})
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Package Exports
|
|
96
|
+
|
|
97
|
+
### Default Export (`@onex/core`)
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
import { ... } from "@onex/core"
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Re-exports everything from `@onex/core/client` for convenience.
|
|
104
|
+
|
|
105
|
+
### Client Export (`@onex/core/client`)
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { ... } from "@onex/core/client"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Browser-safe exports with `"use client"` directive:
|
|
112
|
+
- ✅ All type definitions
|
|
113
|
+
- ✅ UI components (Button, Heading, Card, etc.)
|
|
114
|
+
- ✅ Rendering engine (SectionRenderer, BlockRenderer, ComponentRenderer)
|
|
115
|
+
- ✅ React contexts (ThemeContext, CartContext, ViewportContext, PageDataContext)
|
|
116
|
+
- ✅ Utilities (cn, generateId, block-finder, etc.)
|
|
117
|
+
- ✅ Registries (SectionRegistry, BlockRegistry, ComponentRegistry)
|
|
118
|
+
|
|
119
|
+
### Server Export (`@onex/core/server`)
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { ... } from "@onex/core/server"
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Server-only exports:
|
|
126
|
+
- ✅ ThemeRegistryManager (uses Node.js fs APIs)
|
|
127
|
+
- ✅ All types (re-exported for convenience)
|
|
128
|
+
|
|
129
|
+
## Available Types
|
|
130
|
+
|
|
131
|
+
### Theme Contract Types
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
import type {
|
|
135
|
+
ThemeManifest, // Theme metadata
|
|
136
|
+
ThemeModule, // What themes export
|
|
137
|
+
ThemeConfig, // Design tokens
|
|
138
|
+
ThemeUpload, // Upload metadata
|
|
139
|
+
} from "@onex/core"
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Section Types
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
import type {
|
|
146
|
+
SectionComponentProps, // Props for section components
|
|
147
|
+
SectionInstance, // Section data
|
|
148
|
+
SectionSchema, // Section blueprint
|
|
149
|
+
TemplateDefinition, // Template variant
|
|
150
|
+
} from "@onex/core"
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Component Types
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import type {
|
|
157
|
+
ComponentInstance, // Component data
|
|
158
|
+
ComponentDefinition, // Component blueprint
|
|
159
|
+
StyleSettings, // Component styles
|
|
160
|
+
} from "@onex/core"
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Block Types
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
import type {
|
|
167
|
+
BlockInstance, // Block data (supports nesting)
|
|
168
|
+
BlockDefinition, // Block blueprint
|
|
169
|
+
} from "@onex/core"
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Validation Types
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
import type {
|
|
176
|
+
ValidationResult, // Validation result
|
|
177
|
+
ValidationError, // Validation error
|
|
178
|
+
ValidationWarning, // Validation warning
|
|
179
|
+
} from "@onex/core"
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Available Components
|
|
183
|
+
|
|
184
|
+
35+ pre-built UI components ready to use:
|
|
185
|
+
|
|
186
|
+
### Layout Components
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
import {
|
|
190
|
+
GridContainer,
|
|
191
|
+
FullWidthSection,
|
|
192
|
+
Container,
|
|
193
|
+
Grid,
|
|
194
|
+
Columns
|
|
195
|
+
} from "@onex/core/client"
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Text Components
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
import {
|
|
202
|
+
Heading,
|
|
203
|
+
Paragraph,
|
|
204
|
+
Quote,
|
|
205
|
+
Badge
|
|
206
|
+
} from "@onex/core/client"
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Interactive Components
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
import {
|
|
213
|
+
ButtonComponent,
|
|
214
|
+
Link,
|
|
215
|
+
Divider,
|
|
216
|
+
Spacer
|
|
217
|
+
} from "@onex/core/client"
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Media Components
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
import {
|
|
224
|
+
Image,
|
|
225
|
+
Icon,
|
|
226
|
+
Video,
|
|
227
|
+
Gallery,
|
|
228
|
+
Map
|
|
229
|
+
} from "@onex/core/client"
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Form Components
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
import {
|
|
236
|
+
Input,
|
|
237
|
+
Textarea,
|
|
238
|
+
Checkbox,
|
|
239
|
+
Select
|
|
240
|
+
} from "@onex/core/client"
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Advanced Components
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
import {
|
|
247
|
+
Card,
|
|
248
|
+
Alert,
|
|
249
|
+
Accordion,
|
|
250
|
+
Tabs,
|
|
251
|
+
Rating,
|
|
252
|
+
Progress,
|
|
253
|
+
Timer,
|
|
254
|
+
Table,
|
|
255
|
+
Code
|
|
256
|
+
} from "@onex/core/client"
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Utilities
|
|
260
|
+
|
|
261
|
+
### cn() - Class Name Merger
|
|
262
|
+
|
|
263
|
+
Combines Tailwind CSS classes with proper precedence:
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
import { cn } from "@onex/core/client"
|
|
267
|
+
|
|
268
|
+
const className = cn(
|
|
269
|
+
"text-base",
|
|
270
|
+
"text-lg", // This wins (last one)
|
|
271
|
+
condition && "font-bold",
|
|
272
|
+
section.settings.customClass
|
|
273
|
+
)
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### generateId() - UUID Generator
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
import { generateId } from "@onex/core/client"
|
|
280
|
+
|
|
281
|
+
const id = generateId() // "abc123-def456-..."
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### Block Finder
|
|
285
|
+
|
|
286
|
+
Find and update nested blocks:
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
import { findBlockInSection, updateBlockInSection } from "@onex/core/client"
|
|
290
|
+
|
|
291
|
+
const block = findBlockInSection(section, blockId)
|
|
292
|
+
const updated = updateBlockInSection(section, blockId, { settings: {...} })
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
## Contexts
|
|
296
|
+
|
|
297
|
+
### ThemeContext
|
|
298
|
+
|
|
299
|
+
Access theme configuration:
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
import { useTheme } from "@onex/core/client"
|
|
303
|
+
|
|
304
|
+
function MyComponent() {
|
|
305
|
+
const { config } = useTheme()
|
|
306
|
+
return <div style={{ color: config.colors.light.primary }}>...</div>
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### CartContext
|
|
311
|
+
|
|
312
|
+
Shopping cart state management:
|
|
313
|
+
|
|
314
|
+
```typescript
|
|
315
|
+
import { useCart } from "@onex/core/client"
|
|
316
|
+
|
|
317
|
+
function AddToCartButton() {
|
|
318
|
+
const { addItem } = useCart()
|
|
319
|
+
return <button onClick={() => addItem(product)}>Add to Cart</button>
|
|
320
|
+
}
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### ViewportContext
|
|
324
|
+
|
|
325
|
+
Responsive breakpoint detection:
|
|
326
|
+
|
|
327
|
+
```typescript
|
|
328
|
+
import { useViewport } from "@onex/core/client"
|
|
329
|
+
|
|
330
|
+
function ResponsiveComponent() {
|
|
331
|
+
const { isMobile, isTablet, isDesktop } = useViewport()
|
|
332
|
+
return isMobile ? <MobileView /> : <DesktopView />
|
|
333
|
+
}
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
## Theme Development Workflow
|
|
337
|
+
|
|
338
|
+
1. **Setup**: Install `@onex/core` and create theme structure
|
|
339
|
+
2. **Develop**: Create section components using types and UI components
|
|
340
|
+
3. **Build**: Bundle with esbuild, externalize `@onex/core`
|
|
341
|
+
4. **Validate**: Run `onex theme validate` (CLI coming in Phase 4)
|
|
342
|
+
5. **Test**: Test with local storefront instance
|
|
343
|
+
6. **Publish**: Upload ZIP to OneX marketplace
|
|
344
|
+
|
|
345
|
+
## Security Constraints
|
|
346
|
+
|
|
347
|
+
### v1.0.0 - Static + Runtime Constraints
|
|
348
|
+
|
|
349
|
+
**Allowed**:
|
|
350
|
+
- ✅ Import from `@onex/core`, `react`, `react-dom`
|
|
351
|
+
- ✅ Standard JavaScript/TypeScript
|
|
352
|
+
- ✅ Tailwind CSS classes
|
|
353
|
+
- ✅ Fetch API for CDN resources
|
|
354
|
+
|
|
355
|
+
**Blocked** (detected via AST validation):
|
|
356
|
+
- ❌ `eval()` or `new Function()`
|
|
357
|
+
- ❌ Node.js APIs (`fs`, `path`, `child_process`, etc.)
|
|
358
|
+
- ❌ Dynamic imports except from CDN
|
|
359
|
+
- ❌ Bundle size > 1MB
|
|
360
|
+
|
|
361
|
+
**Runtime Protection**:
|
|
362
|
+
- Error boundaries catch render crashes
|
|
363
|
+
- Engine version enforcement
|
|
364
|
+
- Limited API surface
|
|
365
|
+
|
|
366
|
+
⚠️ **Note**: v1 does NOT provide true sandboxing against memory leaks, infinite loops, or network abuse. v2 will add iframe sandbox for stronger isolation.
|
|
367
|
+
|
|
368
|
+
## Engine Version Compatibility
|
|
369
|
+
|
|
370
|
+
Specify compatible `@onex/core` versions using semver:
|
|
371
|
+
|
|
372
|
+
```typescript
|
|
373
|
+
{
|
|
374
|
+
"engine": "^1.0.0" // Compatible with 1.x
|
|
375
|
+
}
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
The platform enforces compatibility at runtime:
|
|
379
|
+
|
|
380
|
+
```typescript
|
|
381
|
+
if (!semver.satisfies(platformVersion, theme.engine)) {
|
|
382
|
+
throw new Error("Incompatible theme version")
|
|
383
|
+
}
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
## Documentation
|
|
387
|
+
|
|
388
|
+
- **API Reference**: See [`THEME_API.md`](./THEME_API.md)
|
|
389
|
+
- **Type Definitions**: See [`src/types/`](./src/types/)
|
|
390
|
+
- **Component Docs**: Coming soon
|
|
391
|
+
- **Examples**: See `onex-theme-template` repository
|
|
392
|
+
|
|
393
|
+
## Development
|
|
394
|
+
|
|
395
|
+
```bash
|
|
396
|
+
# Install dependencies
|
|
397
|
+
pnpm install
|
|
398
|
+
|
|
399
|
+
# Build package
|
|
400
|
+
pnpm build
|
|
401
|
+
|
|
402
|
+
# Watch mode
|
|
403
|
+
pnpm dev
|
|
404
|
+
|
|
405
|
+
# Type check
|
|
406
|
+
pnpm type-check
|
|
407
|
+
|
|
408
|
+
# Run tests
|
|
409
|
+
pnpm test
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
## Versioning
|
|
413
|
+
|
|
414
|
+
This package follows [Semantic Versioning](https://semver.org/):
|
|
415
|
+
|
|
416
|
+
- **Major** (2.0.0): Breaking changes to public API (`@public` types)
|
|
417
|
+
- **Minor** (1.1.0): New features, backward compatible
|
|
418
|
+
- **Patch** (1.0.1): Bug fixes, backward compatible
|
|
419
|
+
|
|
420
|
+
## License
|
|
421
|
+
|
|
422
|
+
MIT
|
|
423
|
+
|
|
424
|
+
---
|
|
425
|
+
|
|
426
|
+
**For theme developers**: Start with the [Theme API Reference](./THEME_API.md) for complete documentation.
|
|
427
|
+
|
|
428
|
+
**For platform developers**: See internal documentation in `/docs`.
|