-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement macros support in nextjs-enonic-demo #262
- Loading branch information
Showing
12 changed files
with
1,878 additions
and
1,443 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from "react" | ||
import {MetaData} from "../guillotine/getMetaData"; | ||
import {ComponentRegistry} from '../ComponentRegistry'; | ||
import {MacroConfig, MacroData} from '../RichTextProcessor'; | ||
|
||
const unescape = require('unescape'); | ||
|
||
interface BaseMacroProps { | ||
data: MacroData; | ||
meta: MetaData; | ||
} | ||
|
||
export interface MacroProps { | ||
name: string; | ||
config: MacroConfig; | ||
meta: MetaData; | ||
} | ||
|
||
const BaseMacro = (props: BaseMacroProps) => { | ||
const {data, meta} = props; | ||
|
||
console.info(`Looking for macro definition for: ${data.descriptor}`) | ||
const macro = ComponentRegistry.getMacro(data.descriptor); | ||
const MacroView = macro?.view; | ||
if (MacroView) { | ||
const config = data.config[data.name]; | ||
if (config?.body) { | ||
config.body = unescape(config.body); | ||
} | ||
return <MacroView name={data.name} config={config} meta={meta}/>; | ||
} else if (data.descriptor) { | ||
console.warn(`BaseMacro: can not render macro '${data.descriptor}': no next view or catch-all defined`); | ||
} | ||
return null; | ||
} | ||
|
||
export default BaseMacro; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
import React from "react" | ||
import {RENDER_MODE} from '../utils'; | ||
import {RichTextProcessor, TextData} from '../RichTextProcessor'; | ||
import {MetaData} from '../guillotine/getMetaData'; | ||
|
||
type Props = { | ||
data: TextData, | ||
mode?: RENDER_MODE, | ||
meta: MetaData, | ||
tag?: string, | ||
} | ||
|
||
const RichTextView = ({tag, mode, data}: Props) => { | ||
const RichTextView = ({tag, data, meta}: Props) => { | ||
const CustomTag = tag as keyof JSX.IntrinsicElements || 'section'; | ||
const customMode = mode || RENDER_MODE.NEXT; | ||
return <CustomTag dangerouslySetInnerHTML={{__html: RichTextProcessor.process(data, customMode)}}/> | ||
return <CustomTag dangerouslySetInnerHTML={{__html: RichTextProcessor.process(data, meta)}}/> | ||
} | ||
|
||
export default RichTextView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from "react" | ||
import {RENDER_MODE} from '../../_enonicAdapter/utils'; | ||
import {MacroProps} from '../../_enonicAdapter/views/BaseMacro'; | ||
import HTMLReactParser from 'html-react-parser'; | ||
|
||
const DefaultMacro = ({name, config, meta}: MacroProps) => { | ||
if (meta?.renderMode === RENDER_MODE.EDIT) { | ||
return <>{`[${name}]${config.body}[/${name}]`}</> | ||
} else { | ||
return HTMLReactParser(config.body) as JSX.Element; | ||
} | ||
}; | ||
|
||
export default DefaultMacro; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from "react" | ||
import {RENDER_MODE} from '../../_enonicAdapter/utils'; | ||
import {MacroProps} from '../../_enonicAdapter/views/BaseMacro'; | ||
|
||
const YoutubeMacro = ({name, config, meta}: MacroProps) => { | ||
if (meta?.renderMode === RENDER_MODE.EDIT) { | ||
return <>{`[${name} title="${config.title}" url="${config.url}"/]`}</> | ||
} else { | ||
return <>Youtube here</> | ||
} | ||
}; | ||
|
||
export default YoutubeMacro; |
Oops, something went wrong.