Skip to content

Commit

Permalink
fix: autotagging attributes (#753)
Browse files Browse the repository at this point in the history
  • Loading branch information
YvesRijckaert authored Jun 4, 2024
1 parent 4633be5 commit c1a527e
Show file tree
Hide file tree
Showing 8 changed files with 352 additions and 83 deletions.
10 changes: 8 additions & 2 deletions packages/live-preview-sdk/src/__tests__/saveEvent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ describe('SaveEvent', () => {
const callback = vi.fn();
const entry = { sys: { id: '1' } } as Entry;

const saveEvent = new SaveEvent({ locale });
const saveEvent = new SaveEvent({
locale,
options: { locale: 'en-US', targetOrigin: ['http://localhost:1234'] },
});
saveEvent.subscribe(callback);
saveEvent.receiveMessage({
data: {},
Expand All @@ -40,7 +43,10 @@ describe('SaveEvent', () => {
const callback = vi.fn();
const entry = { sys: { id: '2' } } as Entry;

const saveEvent = new SaveEvent({ locale });
const saveEvent = new SaveEvent({
locale,
options: { locale: 'en-US', targetOrigin: ['http://localhost:1234'] },
});
saveEvent.subscribe(callback);
saveEvent.receiveMessage({
method: LivePreviewPostMessageMethods.ENTRY_SAVED,
Expand Down
26 changes: 23 additions & 3 deletions packages/live-preview-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,15 @@ export class ContentfulLivePreview {

if (this.liveUpdatesEnabled) {
this.liveUpdates = new LiveUpdates({ locale, targetOrigin: this.targetOrigin });
this.saveEvent = new SaveEvent({ locale });
this.saveEvent = new SaveEvent({
locale,
options: {
locale: this.locale,
space: this.space,
environment: this.environment,
targetOrigin: this.targetOrigin,
},
});
}

// bind event listeners for interactivity
Expand Down Expand Up @@ -196,7 +204,13 @@ export class ContentfulLivePreview {
// tell the editor that there's a SDK
const { taggedElements, manuallyTaggedCount, automaticallyTaggedCount } = this
.inspectorModeEnabled
? getAllTaggedElements()
? getAllTaggedElements({
options: {
locale: this.locale,
space: this.space,
environment: this.environment,
},
})
: {
taggedElements: [],
manuallyTaggedCount: 0,
Expand Down Expand Up @@ -367,7 +381,13 @@ export class ContentfulLivePreview {
* Returns a list of tagged entries on the page
*/
static getEntryList(): string[] {
return getAllTaggedEntries();
return getAllTaggedEntries({
options: {
locale: this.locale,
space: this.space,
environment: this.environment,
},
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ describe('getAllTaggedElements', () => {
</div>
`);

const elements = getAllTaggedElements(dom, true);
const elements = getAllTaggedElements({
root: dom,
ignoreManual: true,
options: { locale: 'en-US' },
});

expect(elements).toHaveLength(1 + 10 + 30 + 3);
});
Expand Down
Loading

0 comments on commit c1a527e

Please sign in to comment.