Skip to content

Add edited content rendered on vue-intlayer #280

@aymericzip

Description

@aymericzip

See vue app example in the monorepo: https://github.com/aymericzip/intlayer/tree/main/examples/vite-vue-app

# start app
pnpm run dev
# start editor 
pnpm start:editor

On the react version of the plugin, when the content got updated via the visual editor, it got stored into the EditedContentRenderer

Related code:

/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
export const intlayerNodePlugins: Plugins = {
  id: 'intlayer-node-plugin',
  canHandle: (node) =>
    typeof node === 'bigint' ||
    typeof node === 'string' ||
    typeof node === 'number',
  transform: (
    _node,
    {
      plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components
      ...rest
    }
  ) =>
    renderIntlayerNode({
      ...rest,
      value: rest.children,
      children: (
        <ContentSelectorRenderer {...rest} key={rest.children}>
          <EditedContentRenderer {...rest}>
            {rest.children}
          </EditedContentRenderer>
        </ContentSelectorRenderer>
      ),
    }),
};

So when a change is made using the CMS, or the VIsual editor, the user can see the changes directly rendered visually.


On vue, the same logic should be applied to replace the base content by the updated content

Related code

/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
export const intlayerNodePlugins: Plugins = {
  id: 'intlayer-node-plugin',
  canHandle: (node) =>
    typeof node === 'bigint' ||
    typeof node === 'string' ||
    typeof node === 'number',
  transform: (_node, { children, ...rest }) =>
    renderIntlayerNode({
      ...rest,
      value: children,
      children: () =>
        h(
          // EditorSelectorRenderer, // Maximum stack size exceeded
          ContentSelectorWrapper,
          {
            dictionaryKey: rest.dictionaryKey,
            keyPath: rest.keyPath,
          },
          {
            default: () => children,
          }
        ),
    }),
};

Expected Behavior:

Vue’s intlayerNodePlugins should mirror the React logic: after a node is edited and saved in the editedContent ref, the rendered node should reflect the update without requiring a full refresh or manual intervention.


Suggested Fix:

Ensure vue-intlayer/src/plugins.ts reads from editedContent and replaces the node tree similarly to useEditedContentRenderer.tsx in React. It may require introducing a computed mapping or watcher on editedContent to conditionally render edited nodes in intlayerNodePlugins.

Metadata

Metadata

Assignees

No one assigned

    Labels

    CMSRelated to CMS / externalization of contentvueRelated to vue js

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions