bun-plugin-stx 0.0.9 → 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 +32 -32
- package/dist/client.d.ts +29 -38
- package/dist/client.js +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.js +8803 -12259
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -112,9 +112,9 @@ export default {
|
|
|
112
112
|
}
|
|
113
113
|
```
|
|
114
114
|
|
|
115
|
-
##
|
|
115
|
+
## stx Template Syntax
|
|
116
116
|
|
|
117
|
-
|
|
117
|
+
stx templates use a syntax inspired by Laravel Blade. Templates can contain HTML with special directives for rendering dynamic content.
|
|
118
118
|
|
|
119
119
|
### Basic Example
|
|
120
120
|
|
|
@@ -122,7 +122,7 @@ STX templates use a syntax inspired by Laravel Blade. Templates can contain HTML
|
|
|
122
122
|
<!DOCTYPE html>
|
|
123
123
|
<html>
|
|
124
124
|
<head>
|
|
125
|
-
<title>
|
|
125
|
+
<title>stx Example</title>
|
|
126
126
|
<script>
|
|
127
127
|
// Define your data as an ESM export
|
|
128
128
|
export const title = "Hello World";
|
|
@@ -148,7 +148,7 @@ STX templates use a syntax inspired by Laravel Blade. Templates can contain HTML
|
|
|
148
148
|
|
|
149
149
|
### Data Export Options
|
|
150
150
|
|
|
151
|
-
There are two ways to expose data in your
|
|
151
|
+
There are two ways to expose data in your stx templates:
|
|
152
152
|
|
|
153
153
|
#### 1. ESM exports (recommended)
|
|
154
154
|
|
|
@@ -188,7 +188,7 @@ There are two ways to expose data in your STX templates:
|
|
|
188
188
|
|
|
189
189
|
#### Custom Directives
|
|
190
190
|
|
|
191
|
-
|
|
191
|
+
stx supports defining your own custom directives for template processing:
|
|
192
192
|
|
|
193
193
|
```ts
|
|
194
194
|
import type { CustomDirective } from 'bun-plugin-stx'
|
|
@@ -298,7 +298,7 @@ Output unescaped HTML content:
|
|
|
298
298
|
|
|
299
299
|
#### Markdown Support
|
|
300
300
|
|
|
301
|
-
|
|
301
|
+
stx supports rendering Markdown content directly in your templates using the `@markdown` directive:
|
|
302
302
|
|
|
303
303
|
```html
|
|
304
304
|
<div class="content">
|
|
@@ -339,7 +339,7 @@ Content here
|
|
|
339
339
|
|
|
340
340
|
### Internationalization (i18n)
|
|
341
341
|
|
|
342
|
-
|
|
342
|
+
stx supports internationalization to help you build multilingual applications. Translation files are stored in YAML format (JSON also supported) and support nested keys and parameter replacements.
|
|
343
343
|
|
|
344
344
|
#### Configuration
|
|
345
345
|
|
|
@@ -371,7 +371,7 @@ Create translation files in your translationsDir:
|
|
|
371
371
|
|
|
372
372
|
```yaml
|
|
373
373
|
# translations/en.yaml
|
|
374
|
-
welcome: Welcome to
|
|
374
|
+
welcome: Welcome to stx
|
|
375
375
|
greeting: Hello, :name!
|
|
376
376
|
nav:
|
|
377
377
|
home: Home
|
|
@@ -381,7 +381,7 @@ nav:
|
|
|
381
381
|
|
|
382
382
|
```yaml
|
|
383
383
|
# translations/de.yaml
|
|
384
|
-
welcome: Willkommen bei
|
|
384
|
+
welcome: Willkommen bei stx
|
|
385
385
|
greeting: Hallo, :name!
|
|
386
386
|
nav:
|
|
387
387
|
home: Startseite
|
|
@@ -391,7 +391,7 @@ nav:
|
|
|
391
391
|
|
|
392
392
|
#### Using Translations
|
|
393
393
|
|
|
394
|
-
|
|
394
|
+
stx provides multiple ways to use translations in your templates:
|
|
395
395
|
|
|
396
396
|
1. **@translate Directive**
|
|
397
397
|
|
|
@@ -438,7 +438,7 @@ Then in your template:
|
|
|
438
438
|
|
|
439
439
|
### Web Components Integration
|
|
440
440
|
|
|
441
|
-
|
|
441
|
+
stx now provides seamless integration with Web Components, allowing you to automatically build and use custom elements from your stx components.
|
|
442
442
|
|
|
443
443
|
#### Configuration
|
|
444
444
|
|
|
@@ -461,7 +461,7 @@ await build({
|
|
|
461
461
|
{
|
|
462
462
|
name: 'MyButton', // Class name for the component
|
|
463
463
|
tag: 'my-button', // HTML tag name (must contain a hyphen)
|
|
464
|
-
file: 'components/button.stx', // Path to the
|
|
464
|
+
file: 'components/button.stx', // Path to the stx component
|
|
465
465
|
attributes: ['type', 'text', 'disabled'] // Observed attributes
|
|
466
466
|
},
|
|
467
467
|
{
|
|
@@ -507,9 +507,9 @@ Include web components in your templates with the `@webcomponent` directive:
|
|
|
507
507
|
</html>
|
|
508
508
|
```
|
|
509
509
|
|
|
510
|
-
#### Source
|
|
510
|
+
#### Source stx Components
|
|
511
511
|
|
|
512
|
-
The original
|
|
512
|
+
The original stx components can be simple:
|
|
513
513
|
|
|
514
514
|
```html
|
|
515
515
|
<!-- components/button.stx -->
|
|
@@ -539,9 +539,9 @@ Web components support several configuration options:
|
|
|
539
539
|
|
|
540
540
|
## TypeScript Support
|
|
541
541
|
|
|
542
|
-
|
|
542
|
+
stx includes TypeScript declarations for importing .stx files. Make sure your `tsconfig.json` includes the necessary configuration:
|
|
543
543
|
|
|
544
|
-
```
|
|
544
|
+
```jsonc
|
|
545
545
|
{
|
|
546
546
|
"compilerOptions": {
|
|
547
547
|
// ... your other options
|
|
@@ -561,7 +561,7 @@ declare module '*.stx';
|
|
|
561
561
|
|
|
562
562
|
## Server-Side Rendering Optimizations
|
|
563
563
|
|
|
564
|
-
|
|
564
|
+
stx supports advanced server-side rendering features including streaming and partial hydration.
|
|
565
565
|
|
|
566
566
|
### Streaming Rendering
|
|
567
567
|
|
|
@@ -569,7 +569,7 @@ Streaming allows you to send parts of your HTML to the client as they become ava
|
|
|
569
569
|
|
|
570
570
|
#### Basic Usage
|
|
571
571
|
|
|
572
|
-
|
|
572
|
+
stx templates can be rendered as streams using the `stream()` method:
|
|
573
573
|
|
|
574
574
|
```ts
|
|
575
575
|
import { streamTemplate } from 'bun-plugin-stx'
|
|
@@ -577,8 +577,8 @@ import template from './templates/home.stx'
|
|
|
577
577
|
|
|
578
578
|
// Create a streaming response
|
|
579
579
|
const stream = await streamTemplate(template, {
|
|
580
|
-
title:
|
|
581
|
-
items: [
|
|
580
|
+
title: 'Streaming Example',
|
|
581
|
+
items: ['Apple', 'Banana', 'Cherry']
|
|
582
582
|
})
|
|
583
583
|
|
|
584
584
|
// Use with Bun's server
|
|
@@ -608,12 +608,12 @@ Bun.serve({
|
|
|
608
608
|
async fetch(req) {
|
|
609
609
|
// Create a new ReadableStream
|
|
610
610
|
const stream = new ReadableStream({
|
|
611
|
-
type:
|
|
611
|
+
type: 'direct',
|
|
612
612
|
async start(controller) {
|
|
613
613
|
// Render the page shell immediately
|
|
614
614
|
controller.write(await renderer.renderShell({
|
|
615
|
-
title:
|
|
616
|
-
user: { name:
|
|
615
|
+
title: 'Dashboard',
|
|
616
|
+
user: { name: 'John' }
|
|
617
617
|
}))
|
|
618
618
|
|
|
619
619
|
// Simulate fetching data and stream sections as they're ready
|
|
@@ -722,11 +722,11 @@ Organize your templates for streaming by using section comments:
|
|
|
722
722
|
|
|
723
723
|
### Partial Hydration
|
|
724
724
|
|
|
725
|
-
|
|
725
|
+
stx supports partial hydration to minimize the amount of JavaScript sent to the client and improve performance. This technique allows you to selectively hydrate only the interactive parts of your page.
|
|
726
726
|
|
|
727
727
|
#### Configuration
|
|
728
728
|
|
|
729
|
-
Enable partial hydration in your
|
|
729
|
+
Enable partial hydration in your stx configuration:
|
|
730
730
|
|
|
731
731
|
```ts
|
|
732
732
|
// stx.config.ts
|
|
@@ -794,7 +794,7 @@ export default function hydrate(el: HTMLElement, props: any) {
|
|
|
794
794
|
const addButton = el.querySelector('.add-to-cart-btn') as HTMLButtonElement
|
|
795
795
|
|
|
796
796
|
addButton.addEventListener('click', () => {
|
|
797
|
-
const quantity = parseInt(quantityInput.value)
|
|
797
|
+
const quantity = Number.parseInt(quantityInput.value)
|
|
798
798
|
|
|
799
799
|
// Add to cart logic
|
|
800
800
|
console.log(`Adding ${quantity} items to cart`)
|
|
@@ -811,7 +811,7 @@ This approach ensures that only the necessary JavaScript is loaded for interacti
|
|
|
811
811
|
|
|
812
812
|
### Async Data Fetching
|
|
813
813
|
|
|
814
|
-
|
|
814
|
+
stx supports async data fetching within templates for efficient server-side rendering:
|
|
815
815
|
|
|
816
816
|
```html
|
|
817
817
|
<script>
|
|
@@ -837,7 +837,7 @@ STX supports async data fetching within templates for efficient server-side rend
|
|
|
837
837
|
|
|
838
838
|
## Example Server
|
|
839
839
|
|
|
840
|
-
Run a development server with your
|
|
840
|
+
Run a development server with your stx templates:
|
|
841
841
|
|
|
842
842
|
```ts
|
|
843
843
|
// serve.ts
|
|
@@ -950,7 +950,7 @@ Made with 💙
|
|
|
950
950
|
|
|
951
951
|
## Documentation Generation
|
|
952
952
|
|
|
953
|
-
|
|
953
|
+
stx can automatically generate documentation for your components, templates, and directives. This helps developers understand your UI components and how to use them.
|
|
954
954
|
|
|
955
955
|
### Command Line
|
|
956
956
|
|
|
@@ -994,12 +994,12 @@ export default {
|
|
|
994
994
|
directives: true,
|
|
995
995
|
extraContent: '## Getting Started\n\nThis is additional content to include in the documentation.',
|
|
996
996
|
},
|
|
997
|
-
}
|
|
997
|
+
}
|
|
998
998
|
```
|
|
999
999
|
|
|
1000
1000
|
### Component Documentation
|
|
1001
1001
|
|
|
1002
|
-
|
|
1002
|
+
stx can extract component metadata from JSDoc comments in your component files:
|
|
1003
1003
|
|
|
1004
1004
|
```html
|
|
1005
1005
|
<!--
|
|
@@ -1045,7 +1045,7 @@ This component will be documented with all its properties, types, default values
|
|
|
1045
1045
|
|
|
1046
1046
|
### Web Component Documentation
|
|
1047
1047
|
|
|
1048
|
-
|
|
1048
|
+
stx will automatically document web components defined in your configuration:
|
|
1049
1049
|
|
|
1050
1050
|
```ts
|
|
1051
1051
|
export default {
|
package/dist/client.d.ts
CHANGED
|
@@ -1,42 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Hydrate all islands with the given handlers
|
|
3
|
+
*/
|
|
4
|
+
export declare function hydrateIslands(handlers: IslandHandlers): void;
|
|
5
|
+
/**
|
|
6
|
+
* Add preload links for island scripts
|
|
7
|
+
*/
|
|
8
|
+
export declare function preloadIslandHandlers(handlers: IslandHandlers): void;
|
|
9
|
+
/**
|
|
10
|
+
* Initialize island hydration with the given handlers
|
|
11
|
+
*/
|
|
12
|
+
export declare function initIslands(handlers: IslandHandlers, config?: HydrationConfig): void;
|
|
13
|
+
/**
|
|
14
|
+
* Client-side functionality for bun-plugin-stx
|
|
15
|
+
* This file is meant to be used in the browser
|
|
16
|
+
*/
|
|
17
|
+
// Version info
|
|
18
|
+
export declare const version: '1.0.0';
|
|
19
|
+
/**
|
|
20
|
+
* Configuration for island hydration
|
|
21
|
+
*/
|
|
2
22
|
export declare interface HydrationConfig {
|
|
3
23
|
autoStart?: boolean
|
|
4
24
|
preload?: 'none' | 'eager' | 'lazy'
|
|
5
25
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
name: string,
|
|
15
|
-
handler: () => Promise<any>,
|
|
16
|
-
): Promise<void> {
|
|
17
|
-
if (!isBrowser) return
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
const id = element.getAttribute('data-island-id')
|
|
21
|
-
const propsScript = document.querySelector(`script[data-island-props="${id}"]`) as HTMLScriptElement
|
|
22
|
-
const props = propsScript ? JSON.parse(propsScript.textContent || '{}') : {}
|
|
23
|
-
|
|
24
|
-
const module = await handler()
|
|
25
|
-
const hydrateFn: HydrationFunction = module.default || module.hydrate
|
|
26
|
-
|
|
27
|
-
if (typeof hydrateFn !== 'function') {
|
|
28
|
-
console.error(`Island handler for "${name}" does not export a valid hydration function`)
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
await hydrateFn(element, props)
|
|
33
|
-
|
|
34
|
-
element.setAttribute('data-hydrated', 'true')
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
console.error(`Failed to hydrate island "${name}":`, error)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
export declare function hydrateIslands(handlers: IslandHandlers): void;
|
|
41
|
-
export declare function preloadIslandHandlers(handlers: IslandHandlers): void;
|
|
42
|
-
export declare function initIslands(handlers: IslandHandlers, config: HydrationConfig = {}): void;
|
|
26
|
+
/**
|
|
27
|
+
* Island handler registry
|
|
28
|
+
*/
|
|
29
|
+
export type IslandHandlers = Record<string, () => Promise<any>>
|
|
30
|
+
/**
|
|
31
|
+
* Island hydration function type
|
|
32
|
+
*/
|
|
33
|
+
export type HydrationFunction = (element: HTMLElement, props: any) => void | Promise<void>
|
package/dist/client.js
CHANGED
|
@@ -15,7 +15,6 @@ var __toESM = (mod, isNodeMode, target) => {
|
|
|
15
15
|
});
|
|
16
16
|
return to;
|
|
17
17
|
};
|
|
18
|
-
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
19
18
|
var __export = (target, all) => {
|
|
20
19
|
for (var name in all)
|
|
21
20
|
__defProp(target, name, {
|
|
@@ -26,6 +25,7 @@ var __export = (target, all) => {
|
|
|
26
25
|
});
|
|
27
26
|
};
|
|
28
27
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
28
|
+
var __promiseAll = (args) => Promise.all(args);
|
|
29
29
|
var __require = import.meta.require;
|
|
30
30
|
|
|
31
31
|
// src/client.ts
|
package/dist/index.d.ts
CHANGED