Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Moc 96 use dsl for editing #105

Closed
wants to merge 21 commits into from

Conversation

jonathankap
Copy link
Contributor

@jonathankap jonathankap commented Jul 25, 2024

Here are some thoughts on interfaces for a Reactor class that could be used to by the editor to add DSL support. The plugin would attach a Reactor class to the DOM. This class would maintain a list of ModificationRequests, and apply those modifications to the DOM. It would also listen for mutations and re-apply the modifications as appropriate.

The Reactor defines two core events: onUrlLoaded and onPageLoaded - these are triggers that the plugin could use to query the backend for the right list of modifications. The specification for a "page" load, which is meant to be when the page changes on an SPA, is TBD.

The Reactor does not handle any interactions with the backend or user. Those - for storing modifications, editing, etc - would be handled in the plugin. The Reactor would only be used to apply the modifications to the live DOM.

Below is some pseudo-code of how I imagine Reactor being used:

  1. Initial setup:
const reactor = new Reactor();
reactor.on('onUrlLoaded', (url) => {
  // fetch modifications for the given URL from the backend
  modifications: Array<ModificationRequest> = getModificationsForURL(url);
  // apply to reactor
  modifications.forEach(reactor.addModifications)
});
reactor.on('onPageLoaded', (url, page) => {
  // fetch modifications for the given URL from the backend
  modifications: Array<ModificationRequest> = getModificationsForPage(url, page);
  // apply to reactor
  modifications.forEach(reactor.addModifications)
});
reactor.attach();
  1. Editor or AI adds a modification:
reactor.addModification({ ... })
  1. Editor or AI undoes a modification
reactor.removeLastModification();
  1. Turn on highlighting for a specific modification
const applied = reactor.getAppliedModifications().find(appliedModification => ...)
applied.setHighlight(true)
  1. Remove an arbitrary modification from the list. This will unapply all modifications after
    this one in the list, then remove the modification and reapply all later modifications
const appliedIndex = reactor.getAppliedModifications().findIndex(appliedModification => ...)
reactor.getAppliedModifications().splice(appliedIndex, 1)

My current questions are:

  1. how do we detect/define SPA page changes to listen for?
  2. should things like highlighting live in the reactor?
  3. is there a generic way to handle appliedModifications as an array, or does it need to be a subclass?

Summary by CodeRabbit

  • New Features

    • Enhanced content processing capabilities with a new method for converting HTML elements to JSON.
    • Introduced a centralized approach for DOM modifications, improving maintainability and consistency.
    • Added support for complex modification scenarios through expanded interfaces, including a new action type, replaceAll.
  • Bug Fixes

    • Removed deprecated functions to streamline content handling and improve performance.
  • Documentation

    • Updated dependencies to reflect new capabilities provided by the @repo/reactor package.
  • Tests

    • Expanded test coverage for DOM manipulation functions, ensuring robustness and accuracy in modifications.

@jonathankap jonathankap requested review from elg0nz and bkd705 July 25, 2024 17:00
Copy link

linear bot commented Jul 25, 2024

Copy link

coderabbitai bot commented Jul 25, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Walkthrough

The recent changes enhance the mocksi-lite application by improving DOM manipulation and JSON serialization processes. Key updates include the introduction of a new utility for converting HTML elements to JSON, refined functionality for modifying the DOM, and expanded testing to ensure reliability. These optimizations support more adaptable and maintainable code, fostering better performance and consistency across the application.

Changes

Files Change Summary
.../ContentApp.tsx, .../ChatToast.tsx Replaced innerHTMLToJson with htmlElementToJson for improved JSON serialization. Removed obsolete functions for cleaner code and better maintainability.
.../package.json Added @repo/reactor dependency to enhance application capabilities.
.../utils.ts Modified authOptions for flexibility and removed innerHTMLToJson, indicating a shift away from certain functionalities.
.../index.ts, .../interfaces.ts Expanded exports in index.ts and enhanced interfaces with new properties and methods for better DOM modification and event handling.
.../main.ts Introduced modifyDom for asynchronous DOM modifications and added detailed JSON serialization functionality with htmlElementToJson.
.../tests/index.test.ts, .../main.test.ts Expanded test coverage to include new modification functionalities, ensuring robust verification of the changes.
.../utils.ts Enhanced generateModifications and applyModification functions, allowing for more complex text replacements and DOM manipulations.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ChatToast
    participant ContentApp
    participant Reactor

    User->>ContentApp: Trigger Content
    ContentApp->>Reactor: Modify DOM
    Reactor->>ChatToast: Update Toast
    ChatToast->>Reactor: Serialize HTML to JSON
    Reactor->>ContentApp: Return JSON Data
    ContentApp->>User: Render Updated Content
Loading

🐇 "In burrows deep, where changes leap,
A new dawn glows, our code will flow.
With functions bright and tests in sight,
We hop with glee, from root to tree!
Let JSON sing, and toasts take wing!" 🌼


Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (3)
packages/reactor/interfaces.ts (1)

42-56: The new events onUrlLoaded and onPageLoaded are defined but not used anywhere in the codebase.

  • onUrlLoaded and onPageLoaded are only defined in packages/reactor/interfaces.ts.
  • There are no occurrences of these events being used, registered, or triggered in the codebase.

This indicates that the implementation is incomplete or these events are intended for future use. Please review and ensure that these events are integrated and utilized as intended.

Analysis chain

LGTM! Verify the usage of the new events.

The ReactorEvents interface defines events for onUrlLoaded and onPageLoaded, providing triggers for the plugin to request modifications based on the current URL or page context.

Ensure that the new events are used correctly throughout the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new events `onUrlLoaded` and `onPageLoaded` in the codebase.

# Test: Search for the usage of `onUrlLoaded` event. Expect: Occurrences of `onUrlLoaded`.
rg --type ts 'onUrlLoaded'

# Test: Search for the usage of `onPageLoaded` event. Expect: Occurrences of `onPageLoaded`.
rg --type ts 'onPageLoaded'

Length of output: 205


Script:

#!/bin/bash
# Description: Verify the usage of the new events `onUrlLoaded` and `onPageLoaded` in the codebase.

# Test: Search for event listeners or handlers that might use `onUrlLoaded`.
rg --type ts 'onUrlLoaded'

# Test: Search for event listeners or handlers that might use `onPageLoaded`.
rg --type ts 'onPageLoaded'

# Test: Search for any event registration or trigger related to `onUrlLoaded`.
rg --type ts 'addEventListener' -A 5

# Test: Search for any event registration or trigger related to `onPageLoaded`.
rg --type ts 'addEventListener' -A 5

# Test: Search for any event registration or trigger related to `onUrlLoaded`.
rg --type ts 'dispatchEvent' -A 5

# Test: Search for any event registration or trigger related to `onPageLoaded`.
rg --type ts 'dispatchEvent' -A 5

Length of output: 6483

packages/reactor/utils.ts (2)

49-51: Improve error logging.

The current error logging could be more informative by including the error message.

-  console.warn(`Invalid selector: ${mod.selector ? mod.selector : mod.xpath}`);
+  console.warn(`Invalid selector: ${mod.selector ? mod.selector : mod.xpath}. Error: ${e.message}`);

56-60: Improve element not found logging.

The current logging could be more informative by including the modification details.

-  console.warn(`Element not found for selector: ${mod.selector ? mod.selector : mod.xpath}`);
+  console.warn(`Element not found for selector: ${mod.selector ? mod.selector : mod.xpath}. Modification: ${JSON.stringify(mod)}`);
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1273015 and d46bbd1.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (10)
  • apps/mocksi-lite/content/ContentApp.tsx (2 hunks)
  • apps/mocksi-lite/content/Toast/ChatToast.tsx (5 hunks)
  • apps/mocksi-lite/package.json (1 hunks)
  • apps/mocksi-lite/utils.ts (2 hunks)
  • packages/reactor/index.ts (1 hunks)
  • packages/reactor/interfaces.ts (2 hunks)
  • packages/reactor/main.ts (2 hunks)
  • packages/reactor/tests/index.test.ts (2 hunks)
  • packages/reactor/tests/main.test.ts (1 hunks)
  • packages/reactor/utils.ts (3 hunks)
Additional comments not posted (26)
packages/reactor/index.ts (1)

1-1: Ensure new functions are correctly exported.

The export statement now includes modifyDom and htmlElementToJson. Ensure these functions exist and are correctly implemented in the module.

Verification successful

The new functions are correctly exported.

The functions modifyDom and htmlElementToJson are defined and exported in packages/reactor/main.ts as expected.

  • modifyDom is defined in packages/reactor/main.ts.
  • htmlElementToJson is defined in packages/reactor/main.ts.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of `modifyDom` and `htmlElementToJson` in the module.

# Test: Search for the function definitions. Expect: Functions are defined in the module.
rg --type ts 'export function modifyDom' packages/reactor/main.ts
rg --type ts 'export function htmlElementToJson' packages/reactor/main.ts

Length of output: 143


Script:

#!/bin/bash
# Description: Verify the existence and export of `modifyDom` and `htmlElementToJson` in the module.

# Test: Search for the function definitions and export statements. Expect: Functions are defined and exported in the module.
rg 'modifyDom' --type ts
rg 'htmlElementToJson' --type ts

Length of output: 1304

apps/mocksi-lite/package.json (1)

29-29: Ensure the new dependency is correctly added.

The new dependency @repo/reactor has been added. Ensure the dependency exists and is correctly versioned.

Verification successful

Ensure the new dependency is correctly added.

The new dependency @repo/reactor has been correctly added and is being used in the project.

  • pnpm-lock.yaml
  • packages/reactor/package.json
  • apps/mocksi-lite/package.json
  • apps/mocksi-lite/content/ContentApp.tsx
  • apps/mocksi-lite/content/Toast/ChatToast.tsx
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and version of `@repo/reactor`.

# Test: Check the package version. Expect: Package is correctly versioned.
npm show @repo/reactor version

Length of output: 103


Script:

#!/bin/bash
# Description: Verify the existence of `@repo/reactor` dependency in the repository.

# Test: Search for the `@repo/reactor` dependency declaration in the repository.
rg '@repo/reactor'

Length of output: 374

packages/reactor/tests/index.test.ts (2)

23-49: Ensure the new test case for modifyDom is correct and comprehensive.

The new test case for modifyDom modifies the DOM directly. Ensure the test case is correct, comprehensive, and follows best practices.


3-3: Ensure the new imports are correct.

The new imports include ModificationRequest, modifyDom, and modifyHtml. Ensure these imports are correctly used in the test cases.

Verification successful

The new imports are correctly used.

The imports for ModificationRequest, modifyDom, and modifyHtml are present and correctly used in the test cases.

  • packages/reactor/tests/index.test.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of `ModificationRequest`, `modifyDom`, and `modifyHtml`.

# Test: Check the imports. Expect: Imports are correctly used in the test cases.
rg --type ts 'import { type ModificationRequest, modifyDom, modifyHtml }' packages/reactor/tests/index.test.ts

Length of output: 262


Script:

#!/bin/bash
# Description: Verify the existence and usage of `ModificationRequest`, `modifyDom`, and `modifyHtml`.

# Test: Check the imports. Expect: Imports are correctly used in the test cases.
rg --type ts 'import \{ type ModificationRequest, modifyDom, modifyHtml \}' packages/reactor/tests/index.test.ts

# Test: Verify the usage of `ModificationRequest`, `modifyDom`, and `modifyHtml`. Expect: They are used in the test cases.
rg --type ts 'ModificationRequest|modifyDom|modifyHtml' packages/reactor/tests/index.test.ts

Length of output: 587

packages/reactor/interfaces.ts (4)

34-39: LGTM!

The DomJsonExportNode interface provides a detailed representation of elements, including their attributes and children.


3-8: LGTM! Verify the usage of new properties and action type.

The new properties selector and xpath, and the action type replaceAll enhance the flexibility of the Modification interface.

Ensure that the new properties and action type are used correctly throughout the codebase.

Verification successful

The new properties selector and xpath, and the action type replaceAll are correctly integrated and used throughout the codebase.

  • selector is used in packages/reactor/utils.ts, packages/reactor/tests, and apps/mocksi-lite.
  • xpath is used in packages/reactor/utils.ts and packages/reactor/tests.
  • replaceAll is used in apps/mocksi-lite/utils.ts, packages/reactor/utils.ts, packages/reactor/tests, and packages/dodom/receivers.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of new properties and action type in the codebase.

# Test: Search for the usage of `selector` property. Expect: Occurrences of `selector`.
rg --type ts 'selector'

# Test: Search for the usage of `xpath` property. Expect: Occurrences of `xpath`.
rg --type ts 'xpath'

# Test: Search for the usage of `replaceAll` action type. Expect: Occurrences of `replaceAll`.
rg --type ts 'replaceAll'

Length of output: 3498


30-32: LGTM! Verify the usage of the new property.

The new property modificationRequest in the AppliedModification interface provides a structured way to link applied modifications to their requests.

Ensure that the new property is used correctly throughout the codebase.

Verification successful

Let's gather more context around the usages of modificationRequest to ensure they align with the new interface definition and are used correctly.


Verified!

The new property modificationRequest in the AppliedModification interface is used correctly and consistently throughout the codebase.

  • main.ts: The property is assigned and passed to functions handling modifications.
  • index.test.ts: The property is used in test cases to ensure correct functionality.
  • interfaces.ts: The interface documents the expected structure and usage.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new property `modificationRequest` in the codebase.

# Test: Search for the usage of `modificationRequest` property. Expect: Occurrences of `modificationRequest`.
rg --type ts 'modificationRequest'

Length of output: 800


Script:

#!/bin/bash
# Description: Gather context around the usage of `modificationRequest` property.

# Extract lines around the occurrences of `modificationRequest` in `main.ts`, `interfaces.ts`, and `index.test.ts`.
rg --type ts 'modificationRequest' -A 3 -B 3

Length of output: 2899


64-107: LGTM! Verify the usage of the new methods and events.

The Reactor interface provides a comprehensive set of methods and events for managing the reactor's lifecycle and modifications.

Ensure that the new methods and events are used correctly throughout the codebase.

apps/mocksi-lite/content/ContentApp.tsx (2)

40-40: LGTM!

The function htmlElementToJson is used to serialize the document body into JSON, enhancing the robustness of the JSON conversion process.


1-1: LGTM! Verify the usage of the new function.

The import statement for innerHTMLToJson has been removed and replaced with htmlElementToJson.

Ensure that the new function htmlElementToJson is used correctly in the file.

Verification successful

The function htmlElementToJson is correctly imported and used in ContentApp.tsx.

The import statement for innerHTMLToJson has been replaced with htmlElementToJson, and the new function is correctly utilized in the file.

  • ContentApp.tsx: Correct usage of htmlElementToJson observed.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new function `htmlElementToJson` in the file.

# Test: Search for the usage of `htmlElementToJson` function. Expect: Occurrences of `htmlElementToJson`.
rg --type tsx 'htmlElementToJson'

Length of output: 61


Script:

#!/bin/bash
# Description: Verify the usage of the new function `htmlElementToJson` in the file.

# Test: Search for the usage of `htmlElementToJson` function in .tsx files. Expect: Occurrences of `htmlElementToJson`.
rg 'htmlElementToJson' --glob '*.tsx' -A 3

Length of output: 1785

packages/reactor/main.ts (3)

25-35: LGTM!

The function modifyDom applies modifications to the DOM based on a ModificationRequest object, encapsulating error handling and using the existing generateModifications utility.


37-99: LGTM!

The function htmlElementToJson converts an HTMLElement into a JSON representation, capturing the structure and attributes of the DOM elements, and includes logic to handle different node types and apply filters.


102-115: LGTM!

The function textElementFilter filters out non-visible text nodes, ensuring that only meaningful nodes are processed in the JSON conversion.

packages/reactor/utils.ts (7)

87-89: LGTM!

The code changes are approved.


134-134: LGTM!

The code changes are approved.


135-158: LGTM!

The code changes are approved.


160-175: LGTM!

The code changes are approved.


177-187: LGTM!

The code changes are approved.


189-203: LGTM!

The code changes are approved.


21-25: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to generateModifications match the new logic and handle the updated elements type correctly.

packages/reactor/tests/main.test.ts (1)

29-83: LGTM!

The code changes are approved.

apps/mocksi-lite/content/Toast/ChatToast.tsx (4)

1-9: LGTM!

The code changes are approved.


103-107: LGTM!

The code changes are approved.


128-129: LGTM!

The code changes are approved.


175-175: LGTM!

The code changes are approved.

apps/mocksi-lite/utils.ts (1)

38-38: Verify the definition and import of SignupURL.

Ensure that SignupURL is correctly defined and imported to avoid runtime errors.

Verification successful

The definition and import of SignupURL are correct.

  • SignupURL is defined in apps/mocksi-lite/consts.ts and is correctly used in apps/mocksi-lite/utils.ts and other files.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the definition and import of `SignupURL`.

# Test: Search for the definition and import of `SignupURL`. Expect: Only occurances of the correct definition and import.
rg --type js --type ts --type tsx 'SignupURL'

Length of output: 73


Script:

#!/bin/bash
# Description: Verify the definition and import of `SignupURL`.

# Test: Search for the definition and import of `SignupURL`. Expect: Only occurrences of the correct definition and import.
rg --type js --type ts 'SignupURL'

Length of output: 556

Comment on lines 26 to 44
// construct a new NodeListOf<Element> from items found by the xpath
elements = [];
if (!mod.xpath.startsWith("//html")) {
mod.xpath = `//html/${mod.xpath}`;
}
const xpath = document.evaluate(
mod.xpath,
doc,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null,
);
for (let i = 0; i < xpath.snapshotLength; i++) {
const item = xpath.snapshotItem(i);
if (item !== null && item instanceof Element) {
elements.push(item);
}
}
} else {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve XPath construction logic.

The current logic constructs a new XPath expression if it does not start with //html. This can be improved by ensuring the XPath expression is always valid and scoped correctly.

-  if (!mod.xpath.startsWith("//html")) {
-    mod.xpath = `//html/${mod.xpath}`;
-  }
+  if (!mod.xpath.startsWith("/")) {
+    mod.xpath = `//${mod.xpath}`;
+  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// construct a new NodeListOf<Element> from items found by the xpath
elements = [];
if (!mod.xpath.startsWith("//html")) {
mod.xpath = `//html/${mod.xpath}`;
}
const xpath = document.evaluate(
mod.xpath,
doc,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null,
);
for (let i = 0; i < xpath.snapshotLength; i++) {
const item = xpath.snapshotItem(i);
if (item !== null && item instanceof Element) {
elements.push(item);
}
}
} else {
// construct a new NodeListOf<Element> from items found by the xpath
elements = [];
if (!mod.xpath.startsWith("/")) {
mod.xpath = `//${mod.xpath}`;
}
const xpath = document.evaluate(
mod.xpath,
doc,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null,
);
for (let i = 0; i < xpath.snapshotLength; i++) {
const item = xpath.snapshotItem(i);
if (item !== null && item instanceof Element) {
elements.push(item);
}
}
} else {

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d46bbd1 and 7ad3f87.

Files selected for processing (1)
  • packages/reactor/interfaces.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/reactor/interfaces.ts

@jonathankap jonathankap changed the base branch from main to improve_chat July 25, 2024 17:23
@elg0nz
Copy link
Contributor

elg0nz commented Jul 25, 2024

I like it!

Your approach reminds me of Reactive JS - it was really ahead of its time. It's great to see Reactor living up to its name. I named this package Reactor not only to signal it does more than just DOM changes, but also to hint at its event-based/reactive nature.

Let's address your questions:

  1. Detecting SPA page changes:
    I'll be frank and say I don't know 😅. I'll let @bkd705 tackle this question since he's more experienced with big JS apps.

  2. Should highlighting be in Reactor?
    Yes. Reactor's secondary goal is to create an interface for LLMs to interact with demo apps. I'm aiming to have Reactor handle about 90% of all changes, including UI stuff like highlights and adding "edit me" boxes.

  3. Handling appliedModifications:
    We can decide on this. An array should work fine.

@bkd705
Copy link
Contributor

bkd705 commented Jul 25, 2024

I like it!

Your approach reminds me of Reactive JS - it was really ahead of its time. It's great to see Reactor living up to its name. I named this package Reactor not only to signal it does more than just DOM changes, but also to hint at its event-based/reactive nature.

Let's address your questions:

  1. Detecting SPA page changes:
    I'll be frank and say I don't know 😅. I'll let @bkd705 tackle this question since he's more experienced with big JS apps.
  2. Should highlighting be in Reactor?
    Yes. Reactor's secondary goal is to create an interface for LLMs to interact with demo apps. I'm aiming to have Reactor handle about 90% of all changes, including UI stuff like highlights and adding "edit me" boxes.
  3. Handling appliedModifications:
    We can decide on this. An array should work fine.

I think we can potentially reuse some of this observermutation setup to listen for SPA changes, I might push back on that being a short term goal though since we're disabling most interactions at the moment so for now we can probably get away with assuming you're on a static page and add that functionality in later.

@bkd705
Copy link
Contributor

bkd705 commented Jul 25, 2024

One thing we will need and not sure how it fits into reactor is the ability to say "I want to do this same edit to all matching nodes on the page" vs "I only want to target this specific node even if there are other identical ones on the page"

Potentially we'll need to store a "path" to the node (ie. think like a folder tree, and map that concept to the dom tree).
But also we'd need a "toggle" somewhere (ie. function argument) to say "this change applies to all instances" or "only apply this change to this specific path"

@bkd705
Copy link
Contributor

bkd705 commented Jul 25, 2024

Can we maybe add a "bulk add" interface, I know under the hood it'll still be a loop but maybe would help clean up the usage if rather than the user needing to loop over each modification individually we can just pass an array of modifications to a function

@bkd705
Copy link
Contributor

bkd705 commented Jul 25, 2024

Does reactor itself need to have these on events or can we just use the built in browser ones and relieve reactor of that responsibility, put it on the consumer to decide when they want these things to load and how

@bkd705
Copy link
Contributor

bkd705 commented Jul 25, 2024

For #2 I might argue that it makes sense to have Reactor do the highlighting since it knows where the modifications are and can keep better track of them, but maybe we do it through a function where reactor gives the consumer the x/y coordinates and the consumer is responsible for actually drawing the box, that way its a bit agnostic to changes or maybe different types of highlighting etc

@elg0nz elg0nz marked this pull request as ready for review August 18, 2024 23:29
Copy link
Contributor

@elg0nz elg0nz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great so far, I'm going to attempt to merge this in and find a way to plug it in behind a configuration setting so we can toggle it on/off as needed.

@elg0nz
Copy link
Contributor

elg0nz commented Aug 18, 2024

superseded by #148 but keeping around for reference.

@elg0nz elg0nz closed this Aug 18, 2024
@elg0nz elg0nz reopened this Aug 19, 2024
@elg0nz
Copy link
Contributor

elg0nz commented Aug 19, 2024

Closing this PR due to multiple semantic conflicts throughout the code. Please review the changes and resolve these conflicts before reopening the PR.

@elg0nz elg0nz closed this Aug 19, 2024
@elg0nz elg0nz deleted the MOC-96-use-dsl-for-editing branch September 12, 2024 21:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants