Skip to content

Commit

Permalink
feat(table-plugin): automatically handle relative URLs
Browse files Browse the repository at this point in the history
This commit adds `baseUrl` from document metadata to `sourceBaseUrl` as
a HTMLTable prop.

BREAKING CHANGE: `sourceBaseUrl` has been moved from `TableConfig` to
`HTMLTableBaseProps`. It means you cannot override this value with
`renderersProps.table.sourceBaseUrl` anymore. Use a custom renderer with
`useHtmlTableProps` hook and HTMLTable component to override this value
manually, but you probably shouldn't since the new foundry engines
allows it automatically. If your html source is inline, use
`source.baseUrl` instead, so that every relative URL will be normalized
against this base. Read https://git.io/JtwG0 for a detailed description.
  • Loading branch information
jsamr committed Feb 8, 2021
1 parent 03dfe69 commit 000b9b4
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ export interface HTMLTableBaseProps extends HTMLTableStats
| [html](./table-plugin.htmltablebaseprops.html.md) | string | The outerHtml of <table> tag. |
| [htmlAttribs?](./table-plugin.htmltablebaseprops.htmlattribs.md) | HtmlAttributesDictionary | <i>(Optional)</i> Html attributes for this table node. |
| [onLinkPress?](./table-plugin.htmltablebaseprops.onlinkpress.md) | RenderHTMLPassedProps\['onLinkPress'\] | <i>(Optional)</i> Intercept links press. |
| [sourceBaseUrl?](./table-plugin.htmltablebaseprops.sourcebaseurl.md) | string | <i>(Optional)</i> The base to resolve relative URLs. |
| [WebView](./table-plugin.htmltablebaseprops.webview.md) | ComponentType&lt;any&gt; | The <code>WebView</code> Component you wish to use. |
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@native-html/table-plugin](./table-plugin.md) &gt; [HTMLTableBaseProps](./table-plugin.htmltablebaseprops.md) &gt; [sourceBaseUrl](./table-plugin.htmltablebaseprops.sourcebaseurl.md)

## HTMLTableBaseProps.sourceBaseUrl property

The base to resolve relative URLs.

<b>Signature:</b>

```typescript
sourceBaseUrl?: string;
```
1 change: 0 additions & 1 deletion packages/table-plugin/docs/table-plugin.tableconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export interface TableConfig
| [cssRules?](./table-plugin.tableconfig.cssrules.md) | string | <i>(Optional)</i> Override default CSS rules with this prop. |
| [displayMode?](./table-plugin.tableconfig.displaymode.md) | 'normal' \| 'embedded' \| 'expand' | <i>(Optional)</i> Determine how the width of the table is constrained (or not).<ul> <li> <b>normal</b>: the table will have no peculiar constrain on <code>width</code> or <code>maxWidth</code>. </li> <li> <b>embedded</b>: the table acts like a width-constrained embedded (React Native Render HTML RFC001), with <code>maxWidth</code> determined by <code>contentWidth</code> and <code>computeEmbeddedMaxWidth</code>. </li> <li> <b>expand</b>: like <b>embedded</b>, but with <code>width</code> set to <code>maxWidth</code>. This can be useful to have a center-aligned table on wide screens. </li> </ul> |
| [maxScale?](./table-plugin.tableconfig.maxscale.md) | boolean | <i>(Optional)</i> Max zoom scale (must be greater than 1). |
| [sourceBaseUrl?](./table-plugin.tableconfig.sourcebaseurl.md) | string | <i>(Optional)</i> See https://git.io/JeCAG |
| [style?](./table-plugin.tableconfig.style.md) | StyleProp&lt;ViewStyle&gt; | <i>(Optional)</i> Container style. |
| [tableStyleSpecs?](./table-plugin.tableconfig.tablestylespecs.md) | [TableStyleSpecs](./table-plugin.tablestylespecs.md) | <i>(Optional)</i> Specs to generate css rules.<img src="https://raw.githubusercontent.com/native-html/table-plugin/master/images/TableStyleSpecs.png" /> |
| [webViewProps?](./table-plugin.tableconfig.webviewprops.md) | any | <i>(Optional)</i> Any props you'd like to pass to the <code>WebView</code> component. |
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion packages/table-plugin/etc/table-plugin.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface HTMLTableBaseProps extends HTMLTableStats {
html: string;
htmlAttribs?: HtmlAttributesDictionary;
onLinkPress?: RenderHTMLPassedProps['onLinkPress'];
sourceBaseUrl?: string;
WebView: ComponentType<any>;
}

Expand Down Expand Up @@ -60,7 +61,6 @@ export interface TableConfig {
cssRules?: string;
displayMode?: 'normal' | 'embedded' | 'expand';
maxScale?: boolean;
sourceBaseUrl?: string;
style?: StyleProp<ViewStyle>;
tableStyleSpecs?: TableStyleSpecs;
webViewProps?: any;
Expand Down
2 changes: 1 addition & 1 deletion packages/table-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"react": "16.13.1",
"react-native": "^0.63.2",
"react-native-builder-bob": "^0.17.1",
"react-native-render-html": "6.0.0-alpha.12",
"react-native-render-html": "6.0.0-alpha.13",
"react-native-webview": "11.0.0",
"react-test-renderer": "16.13.1",
"release-it": "^14.3.0",
Expand Down
10 changes: 5 additions & 5 deletions packages/table-plugin/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,6 @@ export interface TableConfig {
*/
maxScale?: boolean;

/**
* See https://git.io/JeCAG
*/
sourceBaseUrl?: string;

/**
* Container style.
*/
Expand Down Expand Up @@ -321,6 +316,11 @@ export interface HTMLTableBaseProps extends HTMLTableStats {
*/
html: string;

/**
* The base to resolve relative URLs.
*/
sourceBaseUrl?: string;

/**
* Intercept links press.
*/
Expand Down
5 changes: 4 additions & 1 deletion packages/table-plugin/src/useHtmlTableProps.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Dimensions } from 'react-native';
import {
CustomTagRendererProps,
useSharedProps
useSharedProps,
useDocumentMetadata
} from 'react-native-render-html';
import extractHtmlAndStatsFromTableDomNode from './extractHtmlAndStatsFromTableDomNode';
import { HTMLTableProps, TableConfig } from './types';
Expand Down Expand Up @@ -41,6 +42,7 @@ export default function useHtmlTableProps(
typeof contentWidth === 'number'
? contentWidth
: Dimensions.get('window').width;
const documentBaseUrl = useDocumentMetadata().baseUrl;
const availableWidth =
computeEmbeddedMaxWidth?.call(null, resolvedContentWidth, 'table') ||
resolvedContentWidth;
Expand All @@ -66,6 +68,7 @@ export default function useHtmlTableProps(
...stats,
key,
html,
sourceBaseUrl: documentBaseUrl,
style: composedStyles,
onLinkPress,
WebView
Expand Down

0 comments on commit 000b9b4

Please sign in to comment.