-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate Elements panel RulesList to new GenericList component
- Loading branch information
Showing
6 changed files
with
176 additions
and
185 deletions.
There are no files selected for viewing
This file contains 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
135 changes: 135 additions & 0 deletions
135
src/devtools/client/inspector/markup/components/rules/RulesListData.ts
This file contains 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,135 @@ | ||
import { GenericListData } from "replay-next/components/windowing/GenericListData"; | ||
import { RuleState } from "ui/suspense/styleCaches"; | ||
|
||
import { Item } from "./types"; | ||
|
||
export class RulesListData extends GenericListData<Item> { | ||
private _rules: RuleState[] = []; | ||
private _showPseudoElements: boolean = false; | ||
|
||
calculateItemCount(): number { | ||
let count = 0; | ||
let currentInheritedNodeId = null; | ||
let currentPseudoElement = null; | ||
|
||
for (let index = 0; index < this._rules.length; index++) { | ||
const rule = this._rules[index]; | ||
|
||
if (rule.declarations.filter(declaration => !declaration.isInvisible).length === 0) { | ||
continue; // Collapse empty sets | ||
} | ||
|
||
if (!!rule.pseudoElement !== !!currentPseudoElement) { | ||
count++; | ||
currentPseudoElement = rule.pseudoElement; | ||
} | ||
|
||
if (rule.pseudoElement && !this._showPseudoElements) { | ||
continue; | ||
} | ||
|
||
if (rule?.inheritance?.inheritedSource != null) { | ||
// Render a header the first time a new inheritance section is encountered | ||
if ((rule.inheritance?.inheritedNodeId ?? null) !== currentInheritedNodeId) { | ||
currentInheritedNodeId = rule.inheritance?.inheritedNodeId ?? null; | ||
|
||
count++; | ||
} | ||
} | ||
|
||
count += 2; // Header and footer | ||
count += rule.declarations.length; | ||
} | ||
|
||
return count; | ||
} | ||
|
||
getItemAtIndex(index: number): Item { | ||
let currentInheritedNodeId = null; | ||
let currentPseudoElement = null; | ||
|
||
for (let rulesIndex = 0; rulesIndex < this._rules.length; rulesIndex++) { | ||
const rule = this._rules[rulesIndex]; | ||
|
||
if (rule.declarations.filter(declaration => !declaration.isInvisible).length === 0) { | ||
continue; // Collapse empty sets | ||
} | ||
|
||
if (!!rule.pseudoElement !== !!currentPseudoElement) { | ||
currentPseudoElement = rule.pseudoElement; | ||
|
||
if (index === 0) { | ||
return { | ||
isPseudoElement: !!rule.pseudoElement, | ||
type: "pseudo", | ||
}; | ||
} else { | ||
index--; | ||
} | ||
} | ||
|
||
if (rule.pseudoElement && !this._showPseudoElements) { | ||
continue; | ||
} | ||
|
||
if (rule.inheritance?.inheritedSource != null) { | ||
if ((rule.inheritance?.inheritedNodeId ?? null) !== currentInheritedNodeId) { | ||
currentInheritedNodeId = rule.inheritance?.inheritedNodeId ?? null; | ||
|
||
if (index === 0) { | ||
return { | ||
inheritedSource: rule.inheritance.inheritedSource, | ||
type: "inheritance", | ||
}; | ||
} else { | ||
index--; | ||
} | ||
} | ||
} | ||
|
||
if (index === 0) { | ||
return { | ||
rule, | ||
type: "header", | ||
}; | ||
} else { | ||
index--; | ||
} | ||
|
||
for ( | ||
let declarationIndex = 0; | ||
declarationIndex < rule.declarations.length; | ||
declarationIndex++ | ||
) { | ||
if (index === 0) { | ||
return { | ||
declaration: rule.declarations[declarationIndex], | ||
type: "declaration", | ||
}; | ||
} else { | ||
index--; | ||
} | ||
} | ||
|
||
if (index === 0) { | ||
return { | ||
rule, | ||
type: "footer", | ||
}; | ||
} else { | ||
index--; | ||
} | ||
} | ||
|
||
throw Error("Could not find data for row"); | ||
} | ||
|
||
updateRules(rules: RuleState[], showPseudoElements: boolean): void { | ||
if (this._rules != rules || this._showPseudoElements != showPseudoElements) { | ||
this._rules = rules; | ||
this._showPseudoElements = showPseudoElements; | ||
|
||
this.handleDataChange(); | ||
} | ||
} | ||
} |
This file contains 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
24 changes: 9 additions & 15 deletions
24
src/devtools/client/inspector/markup/components/rules/types.ts
This file contains 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,45 +1,39 @@ | ||
import { DeclarationState, RuleState } from "ui/suspense/styleCaches"; | ||
|
||
export type DeclarationStateItemData = { | ||
export type DeclarationStateItem = { | ||
declaration: DeclarationState; | ||
type: "declaration"; | ||
}; | ||
|
||
export type InheritanceItemData = { | ||
export type InheritanceItem = { | ||
inheritedSource: string; | ||
type: "inheritance"; | ||
}; | ||
|
||
export type PseudoElementItemData = { | ||
export type PseudoElementItem = { | ||
isPseudoElement: boolean; | ||
type: "pseudo"; | ||
}; | ||
|
||
export type RuleStateItemData = { | ||
export type RuleStateItem = { | ||
rule: RuleState; | ||
type: "header" | "footer"; | ||
}; | ||
|
||
export type ItemData = | ||
| DeclarationStateItemData | ||
| InheritanceItemData | ||
| PseudoElementItemData | ||
| RuleStateItemData; | ||
export type Item = DeclarationStateItem | InheritanceItem | PseudoElementItem | RuleStateItem; | ||
|
||
export function isDeclarationStateItemData( | ||
itemData: ItemData | ||
): itemData is DeclarationStateItemData { | ||
export function isDeclarationStateItem(itemData: Item): itemData is DeclarationStateItem { | ||
return itemData.type === "declaration"; | ||
} | ||
|
||
export function isInheritanceItemData(itemData: ItemData): itemData is InheritanceItemData { | ||
export function isInheritanceItem(itemData: Item): itemData is InheritanceItem { | ||
return itemData.type === "inheritance"; | ||
} | ||
|
||
export function isPseudoElementItemData(itemData: ItemData): itemData is PseudoElementItemData { | ||
export function isPseudoElementItem(itemData: Item): itemData is PseudoElementItem { | ||
return itemData.type === "pseudo"; | ||
} | ||
|
||
export function isRuleStateItemData(itemData: ItemData): itemData is RuleStateItemData { | ||
export function isRuleStateItem(itemData: Item): itemData is RuleStateItem { | ||
return itemData.type === "header" || itemData.type === "footer"; | ||
} |
39 changes: 0 additions & 39 deletions
39
src/devtools/client/inspector/markup/components/rules/utils/getItemCount.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.