Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Jan 21, 2025
2 parents e65d6bc + 07b0132 commit 2ac5577
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 20 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
### Added

- Added the `data-on-interval` attribute.
- Added the `__delay` modifier for `data-on-*` attributes.
- Added the `__delay` modifier to `data-on-*` attributes.
- Added the `__self` modifier to the `data-star-ignore` attribute.
- Added the entire context to error messages output in the browser console.
- Added the ability to use an empty value when using the `data-signals-*` syntax, which sets the value to an empty string.

### Changed

- Changed the order in which plugins are applied to elements to be depth-first per element, then per `data` attribute ([#495](https://github.com/starfederation/datastar/issues/495)).
- Improved the handling of invalid expressions and signals, and made error handling generally more granular ([#452](https://github.com/starfederation/datastar/issues/452)).
- The `data-star-ignore` attribute now ignores descendant elements by default.

### Fixed

Expand Down
4 changes: 2 additions & 2 deletions bundles/datastar-core.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions bundles/datastar-core.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bundles/datastar.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions bundles/datastar.js.map

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions library/src/engine/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ export class Engine {
// Cleanup any previous plugins
this.#cleanup(el)

// Skip elements with empty dataset or marked to be ignored
if (!el.dataset || 'starIgnore' in el.dataset) return

// Apply the plugins to the element in order of application
// since DOMStringMap is ordered, we can be deterministic
for (const rawKey of Object.keys(el.dataset)) {
Expand Down Expand Up @@ -287,9 +284,16 @@ export class Engine {
if (
!element ||
!(element instanceof HTMLElement || element instanceof SVGElement)
)
) {
return null
}
const dataset = element.dataset
if ('starIgnore' in dataset) {
return null
callback(element)
}
if (!('starIgnore__self' in dataset)) {
callback(element)
}
let el = element.firstElementChild
while (el) {
this.#walkDownDOM(el, callback)
Expand Down
4 changes: 2 additions & 2 deletions sdk/go/consts.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions site/routes_examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func setupExamples(ctx context.Context, router chi.Router, signals sessions.Stor
Links: []*SidebarLink{
{ID: "plugin_order"},
{ID: "polling"},
{ID: "ignore_attributes"},
{ID: "bind_keys"},
{ID: "classes"},
{ID: "scroll_into_view"},
Expand Down
29 changes: 29 additions & 0 deletions site/static/md/examples/ignore_attributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Ignore Attributes

## Demo

<div data-signals-foo="'A valid signal'" class="text-primary">
<div data-star-ignore__self data-text="$notASignal">
<div data-text="$foo"></div>
</div>
</div>

## Explanation

```html
<div data-signals-foo="'A valid signal'">
<div data-star-ignore__self data-text="$notASignal">
<div data-text="$foo"></div>
</div>
</div>
```

This demonstrates how adding the `data-star-ignore__self` attribute to an element prevents the element from being processed by Datastar.

The `__self` modifier limits the behavior to the element itself. Removing the `__self` modifier would cause Datastar also ignore the descendant elements.

```html
<div data-star-ignore data-text="$notASignal">
<div data-text="$alsoNotASignal"></div>
</div>
```
10 changes: 8 additions & 2 deletions site/static/md/reference/attribute_plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,16 @@ The signal name can be specified in the key (as above), or in the value (as belo

### `data-star-ignore`

Datastar walks the entire DOM and applies plugins to each element it encounters. It's possible to tell Datastar to ignore an element by placing a `data-star-ignore` attribute on it. This can be useful for preventing naming conflicts with third-party libraries.
Datastar walks the entire DOM and applies plugins to each element it encounters. It's possible to tell Datastar to ignore an element and its descendants by placing a `data-star-ignore` attribute on it. This can be useful for preventing naming conflicts with third-party libraries.

```html
<div data-star-ignore data-show-thirdpartylib>
This element’s attributes will not be processed by Datastar.
<div data-show-thirdpartylib>
These element will not be processed by Datastar.
</div>
</div>
```

#### Modifiers

- `__self` - Only ignore the element itself, not its descendants.

0 comments on commit 2ac5577

Please sign in to comment.