Skip to content

Commit 93cafa5

Browse files
jackieliiclaude
andauthored
docs: add module import instructions for idiomorph extension (#3350)
* docs: add module import instructions for idiomorph extension Fixes #3349 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * use the right import path * Restore example to make it consistent in the examples * fix manual bundle instructions too * remove unnecessary script tag * remove unminified version as well since it's not needed for htmx integration * clear instruction on using min version with htmx --------- Co-authored-by: Claude <[email protected]>
1 parent 28fae54 commit 93cafa5

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

www/content/extensions/idiomorph.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,69 @@
22
title = "htmx Idiomorph Extension"
33
+++
44

5-
[Idiomorph](https://github.com/bigskysoftware/idiomorph) is a DOM morphing algorithm created by the htmx creator. DOM
5+
[Idiomorph](https://github.com/bigskysoftware/idiomorph) is a DOM morphing algorithm created by the htmx creator. DOM
66
morphing is a process where an existing DOM tree is "morphed" into the shape of another in a way that resuses as much of
7-
the existing DOM's nodes as possible. By preserving nodes when changing from one tree to another you can present a
7+
the existing DOM's nodes as possible. By preserving nodes when changing from one tree to another you can present a
88
much smoother transition between the two states.
99

10-
You can use the idiomorph morphing algorithm as a [swapping](@attributes/hx-swap) strategy by including the idiomorph
10+
You can use the idiomorph morphing algorithm as a [swapping](@attributes/hx-swap) strategy by including the idiomorph
1111
extension.
1212

1313
## Installing
1414

1515
The fastest way to install `idiomorph` is to load it via a CDN. Remember to always include the core htmx library before the extension and [enable the extension](#usage).
16+
1617
```HTML
1718
<head>
1819
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/[email protected]" integrity="sha384-HGfztofotfshcF7+8n44JQL2oJmowVChPTg48S+jvZoztPfvwD79OC/LTtG6dMp+" crossorigin="anonymous"></script>
19-
<script src="https://unpkg.com/[email protected]" integrity="sha384-JcorokHTL/m+D6ZHe2+yFVQopVwZ+91GxAPDyEZ6/A/OEPGEx1+MeNSe2OGvoRS9" crossorigin="anonymous"></script>
2020
<script src="https://unpkg.com/[email protected]/dist/idiomorph-ext.min.js" integrity="sha384-szktAZju9fwY15dZ6D2FKFN4eZoltuXiHStNDJWK9+FARrxJtquql828JzikODob" crossorigin="anonymous"></script>
2121
</head>
2222
<body hx-ext="morph">
2323
```
24-
Unminified versions are also available at:
25-
https://unpkg.com/idiomorph/dist/idiomorph.js
26-
https://unpkg.com/idiomorph/dist/idiomorph-ext.js
2724

28-
While the CDN approach is simple, you may want to consider [not using CDNs in production](https://blog.wesleyac.com/posts/why-not-javascript-cdn). The next easiest way to install `idiomorph` is to simply copy it into your project. Download idiomorph and its htmx extension from `https://unpkg.com/idiomorph` and `https://unpkg.com/idiomorph/dist/idiomorph-ext.min.js`, add them to the appropriate directory in your project and include them where necessary with `<script>` tags.
25+
Unminified versions are also available at:
26+
<https://unpkg.com/idiomorph/dist/idiomorph-ext.js>
27+
28+
While the CDN approach is simple, you may want to consider [not using CDNs in production](https://blog.wesleyac.com/posts/why-not-javascript-cdn). The next easiest way to install `idiomorph` is to simply copy it into your project. Download idiomorph with htmx extension from `https://unpkg.com/idiomorph/dist/idiomorph-ext.min.js`, add them to the appropriate directory in your project and include them where necessary with `<script>` tags.
2929

3030
For npm-style build systems, you can install `idiomorph` via [npm](https://www.npmjs.com/):
31+
3132
```shell
3233
npm install idiomorph
3334
```
34-
After installing, you'll need to use appropriate tooling to bundle `node_modules/idiomorph/dist/idiomorph.js` (or `.min.js`) and `node_modules/idiomorph/dist/idiomorph-ext.js`. For example, you might bundle the extension with htmx core from `node_modules/htmx.org/dist/htmx.js` and project-specific code.
35+
36+
After installing, you'll need to use appropriate tooling to bundle `node_modules/idiomorph/dist/idiomorph-ext.js` (or `node_modules/idiomorph/dist/idiomorph-ext.min.js`). For example, you might bundle the extension with htmx core from `node_modules/htmx.org/dist/htmx.js` and project-specific code.
3537

3638
If you are using a bundler to manage your javascript (e.g. Webpack, Rollup):
39+
3740
- Install `htmx.org` and `idiomorph` via npm
3841
- Import both packages to your `index.js`
42+
3943
```JS
4044
import `htmx.org`;
41-
import `idiomorph`;
45+
import `idiomorph/htmx`;
4246
```
4347

4448
## Usage
4549

4650
Once you have referenced the idiomorph extension, you can register it with the name `morph` on the body and then being
4751
using `morph`, `morph:outerHTML` or `morph:innerHTML` as swap strategies.
4852

49-
* `morph` & `morph:outerHTML` will morph the target element as well as it's children
50-
* `morph:innerHTML` will morph only the inner children of an element, leaving the target untouched
53+
- `morph` & `morph:outerHTML` will morph the target element as well as it's children
54+
- `morph:innerHTML` will morph only the inner children of an element, leaving the target untouched
5155

5256
```html
5357
<body hx-ext="morph">
58+
<button hx-get="/example" hx-swap="morph">
59+
Morph My Outer HTML
60+
</button>
5461

55-
<button hx-get="/example" hx-swap="morph">
56-
Morph My Outer HTML
57-
</button>
58-
59-
<button hx-get="/example" hx-swap="morph:outerHTML">
60-
Morph My Outer HTML
61-
</button>
62-
63-
<button hx-get="/example" hx-swap="morph:innerHTML">
64-
Morph My Inner HTML
65-
</button>
62+
<button hx-get="/example" hx-swap="morph:outerHTML">
63+
Morph My Outer HTML
64+
</button>
6665

66+
<button hx-get="/example" hx-swap="morph:innerHTML">
67+
Morph My Inner HTML
68+
</button>
6769
</body>
6870
```
69-

0 commit comments

Comments
 (0)