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

Conversion from simple model to complex view (slot conversion) #1589

Closed
jodator opened this issue Mar 1, 2019 · 6 comments
Closed

Conversion from simple model to complex view (slot conversion) #1589

jodator opened this issue Mar 1, 2019 · 6 comments
Labels
domain:dx This issue reports a developer experience problem or possible improvement. package:engine resolution:duplicate This issue is a duplicate of another issue and was merged into it. squad:core Issue to be handled by the Core team. status:discussion type:docs This issue reports a task related to documentation (e.g. an idea for a guide). type:feature This issue reports a feature request (an idea for a new functionality or a missing option). type:refactor This issue requires or describes a code refactoring.

Comments

@jodator
Copy link
Contributor

jodator commented Mar 1, 2019

Some nested widgets might have a structure that does not map 1:1 all elements inside.

(View)                                 (Model)
div.widget                           -> widget
    div.wrapper
        div.inner-wrapper
            div.widget-title
                div.sub-editable     ->    widgetTitle
            div.widget-body
                div.sub-editable     ->    widgetBody

Similar case is with current widgets that maps <figure> from the view to <image> or <table> element in the model. So the mapping is not element to element but rather view widget wrapper to model element.

This complicates stuff as to override some parts of such widget conversion requires deeper understanding of the feature. For image it is hard IMO but for tables might be hard as hell for outsiders.

The second part is to showcase how to map view element editable to element in the model so the selection and automatic conversion of children will work out-of-the-box. In such example one would rather convert div.widget-title but map the div.sub-editable to widgetTitle in the model.

@jodator jodator added this to the iteration 23 milestone Mar 1, 2019
@Reinmar
Copy link
Member

Reinmar commented Mar 6, 2019

I've made a PoC of what I call a "slot conversion", when we can control where children of a specific model element are being inserted in the view: https://github.com/ckeditor/ckeditor5-core/tree/poc-slot-conversion (updated version in monorepo: https://github.com/ckeditor/ckeditor5/tree/poc/slot-conversion)

(View)                                   (Model)
div.container                        <-> container
    div.slot
        foo                          <->     foo
        bar                          <->     bar

This is a bit different scenario than what you described, because in what you showed @jodator widgetTitle gets converted to a specific place and so does widgetBody. However, I'd try to think how to generalise both approaches and document both. I've been often asked about both of them and perhaps they share more common aspects than it initially seems.

@Reinmar Reinmar changed the title How to handle nested widgets (a guide maybe?) [Docs] Conversion from simple model to complex view Mar 6, 2019
@Reinmar Reinmar added the type:docs This issue reports a task related to documentation (e.g. an idea for a guide). label Mar 7, 2019
@mlewand mlewand modified the milestones: iteration 23, iteration 24 Apr 8, 2019
@mlewand mlewand modified the milestones: iteration 24, iteration 25 May 27, 2019
@Reinmar Reinmar modified the milestones: iteration 25, iteration 26 Jun 27, 2019
@mlewand mlewand modified the milestones: iteration 26, nice-to-have Jul 29, 2019
@Reinmar
Copy link
Member

Reinmar commented Sep 19, 2019

BTW, this is labeled with type:docs, but I think we could also propose an API for that. That'd be much better.

@Reinmar Reinmar added type:feature This issue reports a feature request (an idea for a new functionality or a missing option). status:confirmed and removed status:discussion labels Sep 19, 2019
@Reinmar Reinmar added the type:refactor This issue requires or describes a code refactoring. label Mar 27, 2020
@Reinmar Reinmar changed the title [Docs] Conversion from simple model to complex view Conversion from simple model to complex view Mar 27, 2020
@Reinmar Reinmar added domain:dx This issue reports a developer experience problem or possible improvement. package:engine labels Mar 27, 2020
@Reinmar Reinmar changed the title Conversion from simple model to complex view Conversion from simple model to complex view (slot conversion) Mar 27, 2020
@Reinmar
Copy link
Member

Reinmar commented Jun 18, 2020

Interestingly, the slot conversion that I made a PoC of in #1589 (comment) break widget type around feature. Since the model element is mapped to the slot, the WTA feature does not recognise the widget element as here it gets the slot element instead.

That could probably be fixed in WTA itself because I don't know why it gets the view element from the model element and not the other way around, but in general, playing with mappings may lead to such issues.

After implementing a couple such widgets I see two things that we should make easier:

  • Defining a converter that inserts all children of the element being converted into a given container element of the created view structure.
    • Example: You need two nested containers, one within the other to represent a single model element. And children of that model element should be converted into the nested container.
  • Defining a converter that inserts the view element into a different than default location in the already existing view.

@tomalec
Copy link
Contributor

tomalec commented Jul 9, 2020

As for a freshman, without any knowledge of CKE5 converters, the problem looks like Shadow DOM content distribution.

There was even a proposal from Google for an imperative distribution API:

Maybe we can get some inspiration and naming the native world, to make CKE-specific things easier to understand.

BTW, why don't we use the actual shadow DOM?

@jodator
Copy link
Contributor Author

jodator commented Sep 29, 2020

Cross-linking table case: #8138 (comment).

@Reinmar Reinmar modified the milestones: nice-to-have, iteration 37 Oct 8, 2020
@jodator jodator modified the milestones: iteration 37, nice-to-have Oct 19, 2020
@jodator jodator removed their assignment Oct 26, 2020
@Reinmar Reinmar added squad:core Issue to be handled by the Core team. and removed squad:dx labels Sep 9, 2021
@niegowski
Copy link
Contributor

Outdated DUP #10294

@Reinmar Reinmar added the resolution:duplicate This issue is a duplicate of another issue and was merged into it. label Nov 17, 2021
@Reinmar Reinmar removed this from the nice-to-have milestone Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:dx This issue reports a developer experience problem or possible improvement. package:engine resolution:duplicate This issue is a duplicate of another issue and was merged into it. squad:core Issue to be handled by the Core team. status:discussion type:docs This issue reports a task related to documentation (e.g. an idea for a guide). type:feature This issue reports a feature request (an idea for a new functionality or a missing option). type:refactor This issue requires or describes a code refactoring.
Projects
None yet
Development

No branches or pull requests

5 participants