-
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
177 additions
and
186 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
140 changes: 140 additions & 0 deletions
140
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,140 @@ | ||
import { RulesListItemData } from "devtools/client/inspector/markup/components/rules/RulesListItem"; | ||
import { GenericListData } from "replay-next/components/windowing/GenericListData"; | ||
import { RuleState } from "ui/suspense/styleCaches"; | ||
|
||
import { Item } from "./types"; | ||
|
||
export class RulesListData extends GenericListData<Item, RulesListItemData> { | ||
private _rules: RuleState[] = []; | ||
private _showPseudoElements: boolean = false; | ||
|
||
getItemAtIndexImplementation(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"); | ||
} | ||
|
||
getItemCountImplementation(): 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; | ||
} | ||
|
||
updateItemDataImplementation(itemData: RulesListItemData): boolean { | ||
const { rules, showPseudoElements } = itemData; | ||
|
||
if (this._rules != rules || this._showPseudoElements != showPseudoElements) { | ||
this._rules = rules; | ||
this._showPseudoElements = showPseudoElements; | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
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.