2d8750b4 by Adam Heath

Update react side for adjustments and multiple xpath matches.

1 parent 1367a306
import React from 'react'
import { COMMENT_NODE, DOCUMENT_NODE, DOCTYPE_NODE, ELEMENT_NODE, TEXT_NODE } from 'ultrahtml'
import { parseHtml, createMatcher, findNode } from 'astro-wt/html'
import { parseHtml, createAdjuster, createMatcher, findNode } from 'astro-wt/html'
import { decode } from 'html-entities'
export const ReparseStaticChildren = (replaceOptions, Component) => (props) => {
......@@ -43,13 +43,14 @@ export const CreateReplacement = (Element, propsOrCreator) => (matchOptions) =>
export const DeleteHandler = () => null
export const Replace = (props) => {
const { debug = 0, html, xpath, replacements } = props
const doc = props.node ? props.node : parseHtml(html, { react: false })
const node = xpath ? findNode(doc, xpath) : doc
const { debug = 0, html, xpath, adjustments, replacements } = props
const adjuster = createAdjuster(adjustments)
const doc = props.node ? props.node : parseHtml(html, { adjuster })
const nodes = xpath ? findNode(doc, xpath, { single: false }) : [ doc ]
const replacers = Object.entries(replacements).map(([ selector, Handler ]) => [ createMatcher(selector), Handler ])
const nextDebug = debug ? debug - 1 : 0
if (debug) console.log('Replace', { html, replacers, node })
const result = Match({ debug: nextDebug, node, replacers })
const result = nodes.map(node => Match({ debug: nextDebug, node, replacers }))
if (debug) console.log('Replace result', result)
return result
}
......