Skip to content

Commit

Permalink
fix: rename element to node
Browse files Browse the repository at this point in the history
  • Loading branch information
michelegera committed Nov 6, 2023
1 parent 7c8ea75 commit db26603
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 60 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ _my-list.hbs_
_my-hyperlink.hbs_

```hbs
<a href={{@node.element.data.url}}>{{yield}}</a>
<a href={{@node.node.data.url}}>{{yield}}</a>
```

### Use existing addons
Expand All @@ -91,7 +91,7 @@ For example you want to use [`ember-async-image`](https://github.com/html-next/e
_image.hbs_

```hbs
<AsyncImage src={{@node.element.url}} />
<AsyncImage src={{@node.node.url}} />
```

### Migrating from prismic-dom
Expand Down
2 changes: 1 addition & 1 deletion ember-prismic-dom/src/components/prismic/children.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
@onUnknownTag={{@onUnknownTag}}
/>
{{~else~}}
{{~@node.element.text~}}
{{~@node.node.text~}}
{{~/each~}}
2 changes: 1 addition & 1 deletion ember-prismic-dom/src/components/prismic/element.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/>
{{~else if (eq @node.type 'hyperlink')~}}
<a
href={{@node.element.data.url}}
href={{@node.node.data.url}}
rel='noreferrer noopener'
target={{this.target}}
><Prismic::Children
Expand Down
2 changes: 1 addition & 1 deletion ember-prismic-dom/src/components/prismic/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class PrismicElementComponent extends Component {
}

get target() {
return this.args.node.element.data.value?.target || '_blank';
return this.args.node.node.data.value?.target || '_blank';
}

get isCustom() {
Expand Down
26 changes: 13 additions & 13 deletions ember-prismic-dom/src/components/prismic/image.hbs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{{! @glint-nocheck: not typesafe yet }}
{{~#if @node.element.linkUrl~}}
{{~#if @node.node.linkUrl~}}
<a
href={{@node.element.linkUrl}}
target={{if @node.element.linkTarget @node.element.linkTarget '_blank'}}
href={{@node.node.linkUrl}}
target={{if @node.node.linkTarget @node.node.linkTarget '_blank'}}
rel='noreferrer noopener'
><img
alt={{@node.element.alt}}
copyright={{@node.element.copyright}}
src={{@node.element.url}}
width={{@node.element.width}}
height={{@node.element.height}}
alt={{@node.node.alt}}
copyright={{@node.node.copyright}}
src={{@node.node.url}}
width={{@node.node.width}}
height={{@node.node.height}}
/></a>
{{~else~}}
<img
alt={{@node.element.alt}}
copyright={{@node.element.copyright}}
src={{@node.element.url}}
width={{@node.element.width}}
height={{@node.element.height}}
alt={{@node.node.alt}}
copyright={{@node.node.copyright}}
src={{@node.node.url}}
width={{@node.node.width}}
height={{@node.node.height}}
/>
{{~/if~}}
6 changes: 3 additions & 3 deletions test-app/tests/integration/components/prismic/dom-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module('Integration | Component | prismic/dom', function (hooks) {
test('hyperlink', async function (assert) {
class Hyperlink extends Component {}
setComponentTemplate(
hbs`<a href={{@node.element.data.url}}>{{yield}}</a>`,
hbs`<a href={{@node.node.data.url}}>{{yield}}</a>`,
Hyperlink,
);

Expand Down Expand Up @@ -145,7 +145,7 @@ module('Integration | Component | prismic/dom', function (hooks) {

assert.strictEqual(
cleanHtml(this),
'<div><p>This is some text with <strong>overla</strong><em><strong>pp</strong>ings</em> spans and here</p></div>',
'<div><p>This is some text with <strong>overla<em>pp</em></strong><em>ings</em> spans and here</p></div>',
);
});

Expand All @@ -171,7 +171,7 @@ module('Integration | Component | prismic/dom', function (hooks) {

assert.strictEqual(
cleanHtml(this),
'<div><p><em>A </em><a href="https://example.org" rel="noreferrer noopener" target="_blank"><em>li<strong></strong></em><strong>nk</strong></a><strong> wi</strong>th overlap</p></div>',
'<div><p><em>A <a href="https://example.org" rel="noreferrer noopener" target="_blank">li</a></em><a href="https://example.org" rel="noreferrer noopener" target="_blank"><strong>nk</strong></a><strong> wi</strong>th overlap</p></div>',
);
});
});
Expand Down
72 changes: 36 additions & 36 deletions test-app/tests/integration/components/prismic/element-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module('Integration | Component | prismic/element', function (hooks) {
assert.expect(2);
this.node = {
type: 'figure',
element: {
node: {
type: 'figure',
text: 'Qonto The all-in-one business account',
spans: [],
Expand All @@ -32,7 +32,7 @@ module('Integration | Component | prismic/element', function (hooks) {
test('em', async function (assert) {
this.node = {
type: 'em',
element: {
node: {
type: 'em',
text: 'Qonto The all-in-one business account',
spans: [],
Expand All @@ -48,7 +48,7 @@ module('Integration | Component | prismic/element', function (hooks) {
test('heading', async function (assert) {
this.node = {
type: 'heading1',
element: {
node: {
type: 'heading1',
text: 'Qonto The all-in-one business account',
spans: [],
Expand All @@ -64,7 +64,7 @@ module('Integration | Component | prismic/element', function (hooks) {
test('hyperlink', async function (assert) {
this.node = {
type: 'hyperlink',
element: {
node: {
start: 0,
end: 7,
type: 'hyperlink',
Expand All @@ -73,7 +73,7 @@ module('Integration | Component | prismic/element', function (hooks) {
children: [
{
type: 'span',
element: { type: 'span', start: 0, end: 7, text: 'example' },
node: { type: 'span', start: 0, end: 7, text: 'example' },
children: [],
start: 0,
end: 7,
Expand All @@ -94,7 +94,7 @@ module('Integration | Component | prismic/element', function (hooks) {
test('image', async function (assert) {
this.node = {
type: 'image',
element: {
node: {
alt: 'Qonto The all-in-one business account',
copyright: 'qonto',
width: '500',
Expand All @@ -114,7 +114,7 @@ module('Integration | Component | prismic/element', function (hooks) {
test('paragraph', async function (assert) {
this.node = {
type: 'paragraph',
element: {
node: {
type: 'paragraph',
text: 'Qonto The all-in-one business account',
spans: [],
Expand All @@ -130,7 +130,7 @@ module('Integration | Component | prismic/element', function (hooks) {
test('span', async function (assert) {
this.node = {
type: 'span',
element: {
node: {
type: 'span',
text: 'Qonto The all-in-one business account',
spans: [],
Expand All @@ -146,7 +146,7 @@ module('Integration | Component | prismic/element', function (hooks) {
test('preformatted', async function (assert) {
this.node = {
type: 'preformatted',
element: {
node: {
type: 'performatted',
text: 'Qonto The all-in-one business account',
spans: [],
Expand All @@ -162,7 +162,7 @@ module('Integration | Component | prismic/element', function (hooks) {
test('strong', async function (assert) {
this.node = {
type: 'strong',
element: {
node: {
type: 'strong',
text: 'Qonto The all-in-one business account',
spans: [],
Expand All @@ -178,7 +178,7 @@ module('Integration | Component | prismic/element', function (hooks) {
test('label', async function (assert) {
this.node = {
type: 'label',
element: {
node: {
type: 'label',
text: 'Qonto The all-in-one business account',
spans: [],
Expand All @@ -196,19 +196,19 @@ module('Integration | Component | prismic/element', function (hooks) {
test('list', async function (assert) {
this.node = {
type: 'group-list-item',
element: { type: 'group-list-item', spans: [], text: '' },
node: { type: 'group-list-item', spans: [], text: '' },
children: [
{
type: 'list-item',
element: {
node: {
type: 'list-item',
text: 'one',
spans: [],
},
},
{
type: 'list-item',
element: {
node: {
type: 'list-item',
text: 'two',
spans: [],
Expand All @@ -223,7 +223,7 @@ module('Integration | Component | prismic/element', function (hooks) {
test('it renders', async function (assert) {
this.node = {
type: 'paragraph',
element: {
node: {
type: 'paragraph',
text: 'This is some text with overlappings spans and here',
spans: [
Expand All @@ -234,7 +234,7 @@ module('Integration | Component | prismic/element', function (hooks) {
children: [
{
type: 'span',
element: {
node: {
type: 'span',
start: 0,
end: 23,
Expand All @@ -247,11 +247,11 @@ module('Integration | Component | prismic/element', function (hooks) {
},
{
type: 'strong',
element: { start: 23, end: 31, type: 'strong' },
node: { start: 23, end: 31, type: 'strong' },
children: [
{
type: 'span',
element: { type: 'span', start: 23, end: 29, text: 'overla' },
node: { type: 'span', start: 23, end: 29, text: 'overla' },
children: [],
start: 23,
end: 29,
Expand All @@ -264,15 +264,15 @@ module('Integration | Component | prismic/element', function (hooks) {
},
{
type: 'em',
element: { start: 29, end: 35, type: 'em' },
node: { start: 29, end: 35, type: 'em' },
children: [
{
type: 'strong',
element: { start: 23, end: 31, type: 'strong' },
node: { start: 23, end: 31, type: 'strong' },
children: [
{
type: 'span',
element: { type: 'span', start: 29, end: 31, text: 'pp' },
node: { type: 'span', start: 29, end: 31, text: 'pp' },
children: [],
start: 29,
end: 31,
Expand All @@ -285,7 +285,7 @@ module('Integration | Component | prismic/element', function (hooks) {
},
{
type: 'span',
element: { type: 'span', start: 31, end: 35, text: 'ings' },
node: { type: 'span', start: 31, end: 35, text: 'ings' },
children: [],
start: 31,
end: 35,
Expand All @@ -298,7 +298,7 @@ module('Integration | Component | prismic/element', function (hooks) {
},
{
type: 'span',
element: {
node: {
type: 'span',
start: 35,
end: 50,
Expand All @@ -323,7 +323,7 @@ module('Integration | Component | prismic/element', function (hooks) {
test('it renders links with overlapping styles', async function (assert) {
this.node = {
type: 'paragraph',
element: {
node: {
type: 'paragraph',
text: 'A link with overlap',
spans: [
Expand All @@ -340,11 +340,11 @@ module('Integration | Component | prismic/element', function (hooks) {
children: [
{
type: 'em',
element: { start: 0, end: 4, type: 'em' },
node: { start: 0, end: 4, type: 'em' },
children: [
{
type: 'span',
element: { type: 'span', start: 0, end: 2, text: 'A ' },
node: { type: 'span', start: 0, end: 2, text: 'A ' },
children: [],
start: 0,
end: 2,
Expand All @@ -357,7 +357,7 @@ module('Integration | Component | prismic/element', function (hooks) {
},
{
type: 'hyperlink',
element: {
node: {
start: 2,
end: 6,
type: 'hyperlink',
Expand All @@ -366,23 +366,23 @@ module('Integration | Component | prismic/element', function (hooks) {
children: [
{
type: 'em',
element: { start: 0, end: 4, type: 'em' },
node: { start: 0, end: 4, type: 'em' },
children: [
{
type: 'span',
element: { type: 'span', start: 2, end: 4, text: 'li' },
node: { type: 'span', start: 2, end: 4, text: 'li' },
children: [],
start: 2,
end: 4,
text: 'li',
},
{
type: 'strong',
element: { start: 4, end: 9, type: 'strong' },
node: { start: 4, end: 9, type: 'strong' },
children: [
{
type: 'span',
element: { type: 'span', start: 4, end: 4, text: '' },
node: { type: 'span', start: 4, end: 4, text: '' },
children: [],
start: 4,
end: 4,
Expand All @@ -400,11 +400,11 @@ module('Integration | Component | prismic/element', function (hooks) {
},
{
type: 'strong',
element: { start: 4, end: 9, type: 'strong' },
node: { start: 4, end: 9, type: 'strong' },
children: [
{
type: 'span',
element: { type: 'span', start: 4, end: 6, text: 'nk' },
node: { type: 'span', start: 4, end: 6, text: 'nk' },
children: [],
start: 4,
end: 6,
Expand All @@ -422,11 +422,11 @@ module('Integration | Component | prismic/element', function (hooks) {
},
{
type: 'strong',
element: { start: 4, end: 9, type: 'strong' },
node: { start: 4, end: 9, type: 'strong' },
children: [
{
type: 'span',
element: { type: 'span', start: 6, end: 9, text: ' wi' },
node: { type: 'span', start: 6, end: 9, text: ' wi' },
children: [],
start: 6,
end: 9,
Expand All @@ -439,7 +439,7 @@ module('Integration | Component | prismic/element', function (hooks) {
},
{
type: 'span',
element: { type: 'span', start: 9, end: 19, text: 'th overlap' },
node: { type: 'span', start: 9, end: 19, text: 'th overlap' },
children: [],
start: 9,
end: 19,
Expand Down
Loading

0 comments on commit db26603

Please sign in to comment.