Skip to content

Commit 29a3af2

Browse files
author
Jiří Fencl
committed
Fix readme, jsdoc, integration doc
1 parent b4a2952 commit 29a3af2

5 files changed

Lines changed: 628 additions & 265 deletions

File tree

packages/preact/README.md

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,75 @@
1-
<p align="center">
2-
<a href="https://merkur.js.org/docs/getting-started" title="Getting started">
3-
<img src="https://raw.githubusercontent.com/mjancarik/merkur/master/images/merkur-logo.png" width="100px" height="100px" alt="Merkur illustration"/>
4-
</a>
5-
</p>
6-
7-
# Merkur
1+
# @merkur/preact
82

93
[![Build Status](https://github.com/mjancarik/merkur/workflows/CI/badge.svg)](https://github.com/mjancarik/merkur/actions/workflows/ci.yml)
10-
[![NPM package version](https://img.shields.io/npm/v/@merkur/core/latest.svg)](https://www.npmjs.com/package/@merkur/core)
11-
![npm bundle size (scoped version)](https://img.shields.io/bundlephobia/minzip/@merkur/core/latest)
4+
[![NPM package version](https://img.shields.io/npm/v/@merkur/preact/latest.svg)](https://www.npmjs.com/package/@merkur/preact)
5+
![npm bundle size (scoped version)](https://img.shields.io/bundlephobia/minzip/@merkur/preact/latest)
126
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
137

14-
The [Merkur](https://merkur.js.org/) is tiny extensible javascript library for front-end microservices(micro frontends). It allows by default server side rendering for loading performance boost. You can connect it with other frameworks or languages because merkur defines easy API. You can use one of six predefined template's library [Preact](https://preactjs.com/), [µhtml](https://github.com/WebReflection/uhtml#readme), [Svelte](https://svelte.dev/) and [vanilla](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) but you can easily extend for others.
15-
16-
## Features
17-
- Flexible templating engine
18-
- Usable with all tech stacks
19-
- SSR-ready by default
20-
- Easy extensible with plugins
21-
- Tiny - 1 KB minified + gzipped
8+
Preact integration helpers for [Merkur](https://merkur.js.org/) widgets. Provides client and server entry points, rendering helpers, and CLI scaffolding support for Preact-based Merkur widgets.
229

23-
## Getting started
10+
## Installation
2411

2512
```bash
26-
npx @merkur/create-widget <name>
13+
npm install @merkur/preact
14+
```
2715

28-
cd name
16+
Peer dependencies required:
2917

30-
npm run dev // Point your browser at http://localhost:4444/
18+
```bash
19+
npm install @merkur/core @merkur/plugin-component
3120
```
32-
![alt text](https://raw.githubusercontent.com/mjancarik/merkur/master/images/hello-widget.png "Merkur example, hello widget")
33-
## Documentation
3421

35-
To check out [live demo](https://merkur.js.org/demo) and [docs](https://merkur.js.org/docs), visit [https://merkur.js.org](https://merkur.js.org).
22+
## Exports
3623

37-
## Contribution
24+
| Export | Description |
25+
|--------|-------------|
26+
| `@merkur/preact/client` | Client-side Preact rendering helpers |
27+
| `@merkur/preact/server` | Server-side rendering helpers (uses `preact-render-to-string`) |
28+
| `@merkur/preact/entries/client.js` | Preact client widget entry point |
29+
| `@merkur/preact/entries/server.js` | Preact server widget entry point |
30+
| `@merkur/preact/cli` | CLI helpers for widget scaffolding |
3831

39-
Contribute to this project via [Pull-Requests](https://github.com/mjancarik/merkur/pulls).
32+
## Documentation
4033

41-
We are using [Changesets](https://github.com/changesets/changesets) for versioning and releasing. To add a changeset describing your changes, run `npm run changeset` from the root of the monorepo.
34+
Full documentation and setup guide at [merkur.js.org](https://merkur.js.org/docs/getting-started).
35+
36+
## Breaking Changes
37+
38+
### v0.47.0
39+
40+
The `@merkur/preact/webpack` export (`applyBabelLoader`, `applyPreactConfig`) has been **removed**, along with the `@babel/preset-react`, `@merkur/tool-webpack`, and `babel-loader` peer dependencies.
41+
42+
If your webpack config used these helpers, configure the Preact Babel preset manually:
43+
44+
```javascript
45+
// webpack.config.js
46+
module.exports = {
47+
module: {
48+
rules: [
49+
{
50+
test: /\.(js|ts|tsx|jsx|mjs)$/,
51+
exclude: /node_modules/,
52+
use: {
53+
loader: 'babel-loader',
54+
options: {
55+
presets: [
56+
[
57+
'@babel/preset-react',
58+
{ runtime: 'automatic', importSource: 'preact' },
59+
],
60+
],
61+
},
62+
},
63+
},
64+
],
65+
},
66+
};
67+
```
4268

43-
> **Note:** The release process is documented in the [root README](https://github.com/mjancarik/merkur#release), which is the source of truth for all contribution and release guidelines.
69+
Alternatively, migrate to the Vite-based Storybook setup described in the [Storybook integration guide](https://merkur.js.org/docs/storybook-integration-into-merkur), which no longer requires webpack or Babel configuration.
4470

45-
---
71+
## Contribution
4672

47-
Thank you to all the people who already contributed to Merkur!
73+
Contribute via [Pull-Requests](https://github.com/mjancarik/merkur/pulls).
4874

49-
<a href="https://github.com/mjancarik/merkur/graphs/contributors">
50-
<img src="https://contrib.rocks/image?repo=mjancarik/merkur" />
51-
</a>
75+
We use [Changesets](https://github.com/changesets/changesets) for versioning. Run `npm run changeset` from the monorepo root to add a changeset for your changes.

packages/tool-storybook/README.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,63 @@
77

88
The module enables integration of [Storybook](https://storybook.js.org/) into [Merkur](https://merkur.js.org/).
99

10-
**[Documentation for @merkur/tool-storybook](https://merkur.js.org/docs/storybook-integration-into-merkur).**
10+
**[Full documentation](https://merkur.js.org/docs/storybook-integration-into-merkur).**
11+
12+
## API
13+
14+
### `createPreviewConfig(options)`
15+
16+
Registers a Merkur widget with Merkur's factory and returns a partial Storybook `preview.mjs` configuration (`{ loaders }`). Spread the result into your preview export.
17+
18+
| Option | Type | Required | Description |
19+
|--------|------|----------|-------------|
20+
| `widgetProperties` | `Object` || Widget definition object — must include `name` and `version`. |
21+
| `render` | `Function` || Called each time the widget's update lifecycle fires, receives the widget instance. Defaults to a no-op. |
22+
| `createWidget` | `Function` || Widget factory function. Defaults to `createMerkurWidget` from `@merkur/core`. |
23+
24+
```javascript
25+
import { createPreviewConfig } from '@merkur/tool-storybook';
26+
import widgetProperties from '../src/widget.js';
27+
28+
export default {
29+
...createPreviewConfig({ widgetProperties, render: myRenderCallback }),
30+
};
31+
```
32+
33+
### `createVanillaRenderer(options)`
34+
35+
Creates a `render` / `update` pair for vanilla JavaScript widgets that produce HTML strings. Pass `render` as the Storybook story render function and `render: renderer.update` to `createPreviewConfig` so state changes trigger re-renders.
36+
37+
| Option | Type | Required | Description |
38+
|--------|------|----------|-------------|
39+
| `ViewComponent` | `Function \| Object<string, Function>` || A single view function `(widget) => htmlString`, or a named map with a `"default"` key. |
40+
| `bindEvents` | `Function` || Called after every render: `(container, widget) => void`. Falls back to `widget.View.bindEvents` if present. |
41+
42+
```javascript
43+
import { createPreviewConfig, createVanillaRenderer } from '@merkur/tool-storybook';
44+
import widgetProperties from '../src/widget.js';
45+
46+
const renderer = createVanillaRenderer({
47+
ViewComponent: { default: (widget) => `<div>${widget.state.counter}</div>` },
48+
bindEvents(container, widget) {
49+
container.querySelector('button')?.addEventListener('click', widget.onClick);
50+
},
51+
});
52+
53+
export default {
54+
...createPreviewConfig({ widgetProperties, render: renderer.update }),
55+
render: renderer.render,
56+
};
57+
```
58+
59+
### `createWidgetLoader(options)`
60+
61+
Low-level factory that returns a single Storybook loader function. `createPreviewConfig` uses this internally. Use it directly when you need more control over widget registration.
62+
63+
| Option | Type | Required | Description |
64+
|--------|------|----------|-------------|
65+
| `widgetProperties` | `Object` | ✅ | Widget definition object — must include `name` and `version`. |
66+
| `render` | `Function` | — | Render callback invoked on widget updates. Defaults to a no-op. |
1167
1268
## About Merkur
1369

0 commit comments

Comments
 (0)