-
Notifications
You must be signed in to change notification settings - Fork 17
(WIP) Migrate render html #9
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c622b8d
chore: setup render-html project
jsamr a3d5fac
chore: setup render-html CI
jsamr 50a0545
chore: wip
jsamr c4eb354
chore: bump minor deps upgrades
jsamr 782bad0
chore: bump a few major devdeps
jsamr 193e8fe
chore: upgrade to typescript 5.6.3
jsamr 7a11deb
chore: add build and test scripts for render-html
DorianMazur 6d43c40
chore: add vscode settings.json
DorianMazur 22fbd7b
chore: update sdks
DorianMazur 8b67610
fix: typescript paths
DorianMazur 895c794
ci: simplify workflows
DorianMazur a726a23
fix: typescript errors in css-processor
DorianMazur b2dd2b0
fix: typescript errors in render-html
DorianMazur 9e29d21
fix: revert changing and to internal
5ZYSZ3K 985f9f1
fix: remove unsupported props from SCCNativeParseRun and type adjuste…
5ZYSZ3K bd94c72
fix: bring back workspace settings, and adjust types in CSSNativePars…
5ZYSZ3K 45d1537
feat: implement support for missing style properties
5ZYSZ3K File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,87 @@ | ||
| import { TNode } from '@native-html/transient-render-engine'; | ||
| import { ComponentType } from 'react'; | ||
| import { CustomRendererProps } from '..'; | ||
| import lookupRecord from '../helpers/lookupRecord'; | ||
| import BRRenderer from '../renderers/BRRenderer'; | ||
| import WBRRenderer from '../renderers/WBRRenderer'; | ||
| import { | ||
| CustomRenderer, | ||
| HTMLElementModelRecord, | ||
| InternalRenderer | ||
| } from '../shared-types'; | ||
| import internalRenderers from './internalRenderers'; | ||
| import { | ||
| CustomTagRendererRecord, | ||
| InternalTextContentRenderer | ||
| } from './render-types'; | ||
|
|
||
| const internalTextRenderers: Record<string, InternalTextContentRenderer> = { | ||
| br: BRRenderer, | ||
| wbr: WBRRenderer | ||
| }; | ||
|
|
||
| export interface RendererConfig<T extends TNode> { | ||
| Custom: CustomRenderer<T> | null; | ||
| Default: InternalRenderer<T> | null; | ||
| } | ||
|
|
||
| export default class RenderRegistry { | ||
| constructor( | ||
| customRenderers: CustomTagRendererRecord = {}, | ||
| elementModels: HTMLElementModelRecord | ||
| ) { | ||
| this.customRenderers = customRenderers; | ||
| this.elementModels = elementModels; | ||
| } | ||
|
|
||
| private readonly customRenderers: CustomTagRendererRecord = {}; | ||
| private readonly elementModels: HTMLElementModelRecord; | ||
|
|
||
| private getCustomRendererForTNode<T extends TNode>( | ||
| tnode: T | ||
| ): ComponentType<CustomRendererProps<T>> | null { | ||
| if (tnode.tagName! in this.customRenderers) { | ||
| const renderer = this.customRenderers[tnode.tagName!]; | ||
| /* istanbul ignore next */ | ||
| if (typeof __DEV__ === 'boolean' && __DEV__) { | ||
| // In DEV, check for discrepancies. | ||
| const elementModel = this.elementModels[tnode.tagName!]; | ||
| if (!elementModel) { | ||
| console.warn( | ||
| `You are attempting to render a ${tnode.tagName!} tag but you didn't provide an HTMLElementModel. Make sure you register a model for this tag in "customHTMLElementModels" prop. ` | ||
| ); | ||
| } else if (!tnode.matchContentModel(elementModel.contentModel)) { | ||
| console.warn( | ||
| `You are attempting to render "${tnode.tagName}" of type "${tnode.displayName}", but the registered renderer is of content model type ${elementModel?.contentModel} which is incompatible with "${tnode.displayName}".` | ||
| ); | ||
| } | ||
| } | ||
| return renderer as any; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| private getDefaultRendererForTNode<T extends TNode>( | ||
| tnode: T | ||
| ): InternalRenderer<T> | null { | ||
| if (tnode.tagName! in internalRenderers) { | ||
| //@ts-expect-error we know that the tagName is in the map | ||
| return internalRenderers[tnode.tagName!]; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| getInternalTextRenderer(tagName: string | null) { | ||
| if (lookupRecord(internalTextRenderers, tagName)) { | ||
| return internalTextRenderers[tagName]; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| getRendererConfigForTNode<T extends TNode>(tnode: T): RendererConfig<T> { | ||
| return { | ||
| Custom: this.getCustomRendererForTNode(tnode), | ||
| Default: this.getDefaultRendererForTNode(tnode) | ||
| }; | ||
| } | ||
| } |
This file contains hidden or 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 ARenderer from '../renderers/ARenderer'; | ||
| import IMGRenderer from '../renderers/IMGRenderer'; | ||
| import OLRenderer from '../renderers/OLRenderer'; | ||
| import ULRenderer from '../renderers/ULRenderer'; | ||
|
|
||
| const internalRenderers = { | ||
| img: IMGRenderer, | ||
| ul: ULRenderer, | ||
| ol: OLRenderer, | ||
| a: ARenderer | ||
| }; | ||
|
|
||
| export default internalRenderers; |
This file contains hidden or 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,53 @@ | ||
| import { TBlock, TPhrasing, TText } from '@native-html/transient-render-engine'; | ||
| import { ComponentType } from 'react'; | ||
| import { TNodeSubRendererProps } from '../internal-types'; | ||
| import { CustomRenderer, InternalRenderer } from '../shared-types'; | ||
|
|
||
| /** | ||
| * Special internal renderers for non-printable text (wbr, br). | ||
| */ | ||
| export type InternalTextContentRenderer = ComponentType< | ||
| TNodeSubRendererProps<TText> | ||
| > & { | ||
| isNativeInternalTextRenderer: true; | ||
| }; | ||
|
|
||
| /** | ||
| * Internal renderer for tags with a **block** content model. | ||
| */ | ||
| export type InternalBlockRenderer = InternalRenderer<TBlock>; | ||
|
|
||
| /** | ||
| * Internal renderer for tags with a **mixed** content model. | ||
| */ | ||
| export type InternalMixedRenderer = InternalRenderer< | ||
| TBlock | TPhrasing | TText | ||
| >; | ||
|
|
||
| /** | ||
| * Internal renderer for tags with a **textual** content model. | ||
| */ | ||
| export type InternalTextualRenderer = InternalRenderer<TPhrasing | TText>; | ||
|
|
||
| /** | ||
| * Block renderers can only render tnodes of type TBlock. | ||
| */ | ||
| export type CustomBlockRenderer = CustomRenderer<TBlock>; | ||
|
|
||
| /** | ||
| * Textual renderers can render tnodes of type TText or TPhrasing. | ||
| */ | ||
| export type CustomTextualRenderer = CustomRenderer<TText | TPhrasing>; | ||
|
|
||
| /** | ||
| * Mixed renderers can can render tnodes of type TText, TPhrasing or TBlock. | ||
| */ | ||
| export type CustomMixedRenderer = CustomRenderer<TBlock | TPhrasing | TText>; | ||
|
|
||
| /** | ||
| * A record of custom renderers. | ||
| */ | ||
| export type CustomTagRendererRecord = Record< | ||
| string, | ||
| CustomBlockRenderer | CustomTextualRenderer | CustomMixedRenderer | ||
| >; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DorianMazur We prefer
as nevertoas any(well we prefer none). This is immediate technical debt, please open a ticket and add a reference to this ticket in a comment to this line.