-
Notifications
You must be signed in to change notification settings - Fork 7
fix: fix html fragment support #1131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5ef5292
fix: create a simple fix
Gozala 5056fc0
chore: use wrapper element instead
Gozala ed4093d
chore: use common-fragment elemnet
Gozala b85b5b9
chore: add counter recepie
Gozala 0988327
fix: counter example
Gozala 2466a63
fix: display for the common-fragment
Gozala 0e154c7
fix: types
Gozala 12a492a
chore: disable lint rule about unnecessary fragments in the test
Gozala 886999e
Merge remote-tracking branch 'origin/main' into feat/dom-fragments-su…
Gozala d6bd8d7
Apply suggestions from code review
Gozala dcd7ba8
Update ui/src/components/common-fragment.ts
Gozala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { render, setEventSanitizer, setNodeSanitizer } from "./render.ts"; | ||
export { debug, setDebug } from "./logger.ts"; | ||
export { Fragment, h, type VNode } from "./jsx.ts"; | ||
export { h, type VNode } from "./jsx.ts"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { beforeEach, describe, it } from "@std/testing/bdd"; | ||
import * as assert from "./assert.ts"; | ||
import { h } from "../src/jsx.ts"; | ||
|
||
describe("jsx dom fragments support", () => { | ||
it("dom fragments should work", () => { | ||
const fragment = ( | ||
<> | ||
<p>Hello world</p> | ||
</> | ||
); | ||
|
||
assert.matchObject( | ||
fragment, | ||
<common-fragment> | ||
<p>Hello world</p> | ||
</common-fragment>, | ||
); | ||
}); | ||
|
||
it("dom fragments with multiple children", () => { | ||
const fragment = ( | ||
<> | ||
<p>Grocery List</p> | ||
<ul> | ||
<li>Buy Milk</li> | ||
</ul> | ||
</> | ||
); | ||
|
||
assert.matchObject( | ||
fragment, | ||
<common-fragment> | ||
<p>Grocery List</p> | ||
<ul> | ||
<li>Buy Milk</li> | ||
</ul> | ||
</common-fragment>, | ||
); | ||
}); | ||
|
||
it("fragments inside the element", () => { | ||
const grocery = ( | ||
<> | ||
<p>Grocery List</p> | ||
<ul> | ||
<li>Buy Milk</li> | ||
</ul> | ||
</> | ||
); | ||
|
||
assert.matchObject( | ||
<div>{grocery}</div>, | ||
<div> | ||
<common-fragment> | ||
<p>Grocery List</p> | ||
<ul> | ||
<li>Buy Milk</li> | ||
</ul> | ||
</common-fragment> | ||
</div>, | ||
); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// deno-lint-ignore-file jsx-no-useless-fragment | ||
import { h } from "@commontools/html"; | ||
import { | ||
derive, | ||
handler, | ||
NAME, | ||
recipe, | ||
schema, | ||
str, | ||
UI, | ||
} from "@commontools/builder"; | ||
|
||
// Different way to define the same schema, using 'schema' helper function, | ||
// let's as leave off `as const satisfies JSONSchema`. | ||
const model = schema({ | ||
type: "object", | ||
properties: { | ||
value: { type: "number", default: 0, asCell: true }, | ||
}, | ||
default: { value: 0 }, | ||
}); | ||
|
||
const increment = handler({}, model, (_, state) => { | ||
state.value.set(state.value.get() + 1); | ||
}); | ||
|
||
const decrement = handler({}, model, (_, state) => { | ||
state.value.set(state.value.get() - 1); | ||
}); | ||
|
||
export default recipe(model, model, (cell) => { | ||
return { | ||
[NAME]: str`Simple counter: ${derive(cell.value, String)}`, | ||
[UI]: ( | ||
<div> | ||
<button type="button" onClick={increment(cell)}>+</button> | ||
{/* use html fragment to test that it works */} | ||
<> | ||
<b>{cell.value}</b> | ||
</> | ||
<button type="button" onClick={decrement(cell)}>-</button> | ||
</div> | ||
), | ||
value: cell.value, | ||
}; | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export class CommonFragmentElement extends HTMLElement { | ||
constructor() { | ||
super(); | ||
this.attachShadow({ mode: "open" }) | ||
// Add a slot to display the children | ||
.appendChild(document.createElement("slot")); | ||
Gozala marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Tell engine to ignore this element for layout purposes | ||
this.style.display = 'contents'; | ||
} | ||
} | ||
|
||
customElements.define("common-fragment", CommonFragmentElement); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.