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

Message Bundle component with rich text #110

Closed
NilsJacobsen opened this issue Jul 8, 2024 — with Linear · 2 comments
Closed

Message Bundle component with rich text #110

NilsJacobsen opened this issue Jul 8, 2024 — with Linear · 2 comments
Assignees

Comments

Copy link
Member

NilsJacobsen commented Jul 8, 2024

The last research showed that the message bundle editor which wants to render multiple pattern editors in the shadow root doesn't work.

The rich text editors rely on the Selection API which needs to be supported by the browsers. This API is not standard -> bugs and different behaviour in different browsers.

Proposal: Build the component in a way, that the editor can be on the light dom.

  • We can achieve that with slots
  • We need to create a wrapper component that doesn't put it's children in a shadow dom, to handle wiring and give a easy api to the outside

External Wrapper API (simple)

<inlang-message-bundle
  .messageBundle=${bundle}
  .settings=${settings}
  @change-message-bundle=${() => {}}
>
</inlang-message-bundle>

The wrapper component doesn't use the shadow root, that way we can use slots inside the wrapper that can also be on the top level dom.

Internal API (inside wrapper)

<inlang-message-bundle-root
  .messageBundle=${bundle}
  .settings=${settings}
  @change-message-bundle=${() => {}}
> //shadowRoot
  //shadowRoot
  ${bundle.messages.map(
    (message: any) => html`
      //shadowRoot
  ${message.variants.map(
    (variant: any) => html`
      //shadowRoot
     
    .pattern=${variant.pattern}
     > //slot top-level dom
              
   
  `)}
   
  `)}
</inlang-message-bundle-root>

We can do manual wiring in this component. But the app devs are going to use the simple api as long as they don't want to hack some fancy stuff in it.

Naming convention

  • External
    • inlang-message-bunlde | no-shadow (same api as before)
  • Internal
    • inlang-message-bundle-root
    • inlang-message-bundle-header
    • inlang-message
    • inlang-variant
    • inlang-pattern-editor | no-shadow -> slot
    • (inlang-message-bunlde-action) -> slot
    • (inlang-variant-action) -> slot

Loom

Solving Rich Text Editor Issues in Web Components

@NilsJacobsen NilsJacobsen added the Improvement label Jul 8, 2024 — with Linear
@NilsJacobsen NilsJacobsen self-assigned this Jul 8, 2024
@NilsJacobsen NilsJacobsen changed the title Current message bundle component doesn't allow rich text Message Bundle component with rich text Jul 8, 2024
Copy link
Member

How will apps define custom actions?

If the external inlang-message-bundle component has no shadow root, I think it can't use slots. If slots can't be used, how can apps define custom actions?

<inlang-message-bundle
 .messageBundle=${bundle}
 .settings=${settings}
 @change-message-bundle=${() => {}}
>
  <inlang-message-bundle-action slot="bundle" />
</inlang-message-bundle>

Copy link
Member Author

We could access the children and check if they are a instance of a action template. Based on that we can put it into the right location of the wrapper component and then slot it. Seems doable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants