This repository has been archived by the owner on Sep 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MOC 96 use dsl for editing rebased (#148)
* Use Reactor to modify dom in chat * Fix biome * Prototype interfaces for Reactor * Add highlighting to applied modification * WIP: Use DSL for edits * Support unapply in all DSL commands except replaceAll * All tests passing for apply/unapply modifications * Implement reactor interface * First modifications working end-to-end * Refactor reactor; Begin highlighter integration * Integrate chat and edit * Integrate highlighting * fix typo in mocksi-lite/package.json * remove buggy timestamp updater * Update Reactor's README to match the current API * disable timestamps and keep everything else the same for now --------- Co-authored-by: Jonathan Kaplan <[email protected]> Co-authored-by: Jonathan Kaplan <[email protected]>
- Loading branch information
1 parent
e0e2795
commit fb1b0d5
Showing
24 changed files
with
1,746 additions
and
537 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { Reactor } from "@repo/reactor"; | ||
|
||
export default new Reactor(); |
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
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
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,2 +1,8 @@ | ||
export { modifyHtml } from "./main"; | ||
export type { Modification, ModificationRequest } from "./interfaces"; | ||
export type { | ||
Modification, | ||
ModificationRequest, | ||
AppliedModifications, | ||
DomJsonExportNode, | ||
Highlighter, | ||
} from "./interfaces"; | ||
export { Reactor } from "./reactor"; |
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,33 +1,69 @@ | ||
interface TimeStampReference { | ||
// NOTE: this is a iso8601 date string | ||
recordedAt: string; | ||
// NOTE: this is a iso8601 date string | ||
currentTime: string; | ||
} | ||
|
||
export interface Modification { | ||
selector?: string; | ||
xpath?: string; | ||
action: | ||
| "replace" | ||
| "replaceAll" | ||
| "append" | ||
| "prepend" | ||
| "remove" | ||
| "swapImage" | ||
| "highlight" | ||
| "toast" | ||
| "addComponent" | ||
| "updateTimestampReferences" | ||
| "unknown"; | ||
content?: string; | ||
imageUrl?: string; | ||
toastMessage?: string; | ||
componentHtml?: string; | ||
highlightStyle?: string; | ||
duration?: number; | ||
timestampRef?: TimeStampReference; | ||
} | ||
|
||
export interface ModificationRequest { | ||
description: string; | ||
modifications: Modification[]; | ||
} | ||
|
||
export interface AppliedModifications { | ||
modificationRequest: ModificationRequest; | ||
|
||
/** | ||
* Turn highlighting on or off for the changes made | ||
* by this request | ||
*/ | ||
setHighlight(highlight: boolean): void; | ||
} | ||
|
||
export interface DomJsonExportNode { | ||
tag: string; | ||
visible: boolean; | ||
text?: string; | ||
attributes?: Record<string, string>; | ||
children?: DomJsonExportNode[]; | ||
} | ||
|
||
export interface Highlighter { | ||
highlightNode(elementToHighlight: Node): void; | ||
removeHighlightNode(elementToUnhighlight: Node): void; | ||
} | ||
|
||
export abstract class AppliableModification { | ||
doc: Document; | ||
highlightNodes: Node[] = []; | ||
|
||
constructor(doc: Document) { | ||
this.doc = doc; | ||
} | ||
|
||
abstract apply(): void; | ||
abstract unapply(): void; | ||
|
||
getHighlightNodes(): Node[] { | ||
return this.highlightNodes; | ||
} | ||
|
||
addHighlightNode(node: Node): void { | ||
this.highlightNodes.push(node); | ||
} | ||
} |
Oops, something went wrong.