Skip to content
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

My best interpretation of what the typings should look like after merge of #464 #628

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/record/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
isIgnored,
isIframeINode,
hasShadowRoot,
styleAttributeValue,
} from '../utils';
import { IframeManager } from './iframe-manager';
import { ShadowDomManager } from './shadow-dom-manager';
Expand Down Expand Up @@ -475,20 +476,24 @@ export default class MutationBuffer {
}
if (m.attributeName === 'style') {
const old = this.doc.createElement('span');
old.setAttribute('style', m.oldValue);
if (item.attributes['style'] === undefined) {
if (m.oldValue) {
old.setAttribute('style', m.oldValue);
}
if (item.attributes['style'] === undefined ||
item.attributes['style'] === null) {
item.attributes['style'] = {};
}
const style_obj = (item.attributes['style'] as styleAttributeValue);
eoghanmurray marked this conversation as resolved.
Show resolved Hide resolved
for (let i=0; i<target.style.length; i++) {
let pname = target.style[i];
const newValue = target.style.getPropertyValue(pname);
const newPriority = target.style.getPropertyPriority(pname);
if (newValue != old.style.getPropertyValue(pname) ||
newPriority != old.style.getPropertyPriority(pname)) {
if (newPriority == '') {
item.attributes['style'][pname] = newValue;
style_obj[pname] = newValue;
eoghanmurray marked this conversation as resolved.
Show resolved Hide resolved
} else {
item.attributes['style'][pname] = [newValue, newPriority];
style_obj[pname] = [newValue, newPriority];
eoghanmurray marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand All @@ -497,7 +502,7 @@ export default class MutationBuffer {
if (target.style.getPropertyValue(pname) === '' ||
!target.style.getPropertyValue(pname) // covering potential non-standard browsers
) {
item.attributes['style'][pname] = false; // delete
style_obj[pname] = false; // delete
eoghanmurray marked this conversation as resolved.
Show resolved Hide resolved
}
}
} else {
Expand Down
18 changes: 12 additions & 6 deletions src/replay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
canvasMutationData,
Mirror,
ElementState,
styleAttributeValue,
styleValueWithPriority,
} from '../types';
import {
createMirror,
Expand Down Expand Up @@ -1324,13 +1326,17 @@ export class Replayer {
}
}
} else if (attributeName === 'style') {
for (var s in value) {
if (value[s] === false) {
((target as Node) as Element).style.removeProperty(s);
} else if (Array.isArray(value[s])) {
((target as Node) as Element).style.setProperty(s, value[s][0], value[s][1]);
let sv = (value as styleAttributeValue);
const htarget = ((target as Node) as HTMLElement);
for (var s in sv) {
if (sv[s] === false) {
htarget.style.removeProperty(s);
} else if (sv[s] instanceof Array) {
const svp = (sv[s] as styleValueWithPriority);
htarget.style.setProperty(s, svp[0], svp[1]);
eoghanmurray marked this conversation as resolved.
Show resolved Hide resolved
} else {
((target as Node) as Element).style.setProperty(s, value[s]);
const svs = (sv[s] as string)
htarget.style.setProperty(s, svs);
eoghanmurray marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,11 @@ export type textMutation = {
};

export type styleAttributeValue = {
[key:string]: [string, string] | string | false;
[key:string]: styleValueWithPriority | string | false;
};

export type styleValueWithPriority = [string, string];

export type attributeCursor = {
node: Node;
attributes: {
Expand Down
8 changes: 6 additions & 2 deletions typings/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,20 @@ export declare type textMutation = {
id: number;
value: string | null;
};
export declare type styleAttributeValue = {
[key: string]: styleValueWithPriority | string | false;
};
export declare type styleValueWithPriority = [string, string];
export declare type attributeCursor = {
node: Node;
attributes: {
[key: string]: string | null;
[key: string]: string | styleAttributeValue | null;
};
};
export declare type attributeMutation = {
id: number;
attributes: {
[key: string]: string | null;
[key: string]: string | styleAttributeValue | null;
};
};
export declare type removedNodeMutation = {
Expand Down