drunomics / nuxtjs-drupal-ce

A Nuxt module to easily connect Drupal via custom elements.
https://lupus-decoupled.org/
MIT License
22 stars 4 forks source link

Add support for JSON based rendering of slots #103

Closed fago closed 5 months ago

fago commented 1 year ago

With the nuxt-3 compatible version of nuxtjs-drupal-ce (2.x branch) we want to move to JSON based rendering by default, since it has:

The JSON output will work the same for props, but rendering slots requires some little code.

Here is a render function that works with nuxt3/vue3:

/**
 * Render elements from page data returned from useDrupalCeFetchPage
 * @param customElement
 */
export const useDrupalCeRenderCustomElements = (customElement) => {
  return h(resolveComponent(customElement.element), customElement)
}

see usage at https://github.com/drunomics/nuxtjs-drupal-ce/pull/99/files#diff-5cfc0be424c6459b85448814081e0b5b51be314f128a9fcbab458e06d1b56e33R75

Then components having a slot, e.g. "body" would have to use it like that:

<parent-node-element>
  <component :is="useDrupalCeRenderCustomElements(body)" />
</parent-node-element

for scaffolded componets I could see use doing vue-components that work with both markup and json, by using the json output as the slot fallback:

<parent-node-element>
    <slot name="body"><component :is="useDrupalCeRenderCustomElements(body)" /></slot>
</parent-node-element

We should be able to do the same with Vue2 / nuxt-2.x, so we could allow rendering from JSON there as well.

fago commented 5 months ago

1.x won't receive any further new features, closing.