@native-html/table-plugin
Version:
🔠A WebView-based plugin to render tables in react-native-render-html
68 lines (62 loc) • 2.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = useHtmlTableProps;
var _reactNative = require("react-native");
var _reactNativeRenderHtml = require("react-native-render-html");
var _extractHtmlAndStatsFromTableDomNode = _interopRequireDefault(require("./extractHtmlAndStatsFromTableDomNode"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Extract props for the HTMLTable component from renderer function arguments.
* This function is especially usefull for custom table renderers.
*
* @param props - The props of a custom block renderer.
* @param tableConfig - Override config options.
*
* @public
*/
function useHtmlTableProps({
style,
tnode
}, tableConfig) {
const {
WebView,
defaultWebViewProps,
computeEmbeddedMaxWidth
} = (0, _reactNativeRenderHtml.useSharedProps)();
const contentWidth = (0, _reactNativeRenderHtml.useContentWidth)();
const globalTableConfig = (0, _reactNativeRenderHtml.useRendererProps)('table');
const {
onPress: onLinkPress
} = (0, _reactNativeRenderHtml.useRendererProps)('a');
const resolvedConfig = { ...globalTableConfig,
...tableConfig,
webViewProps: { ...defaultWebViewProps,
...(globalTableConfig === null || globalTableConfig === void 0 ? void 0 : globalTableConfig.webViewProps),
...(tableConfig === null || tableConfig === void 0 ? void 0 : tableConfig.webViewProps)
}
};
const resolvedContentWidth = typeof contentWidth === 'number' ? contentWidth : _reactNative.Dimensions.get('window').width;
const documentBaseUrl = (0, _reactNativeRenderHtml.useDocumentMetadata)().baseUrl;
const availableWidth = (computeEmbeddedMaxWidth === null || computeEmbeddedMaxWidth === void 0 ? void 0 : computeEmbeddedMaxWidth.call(null, resolvedContentWidth, 'table')) || resolvedContentWidth;
const {
html,
stats
} = (0, _extractHtmlAndStatsFromTableDomNode.default)(tnode.domNode);
const displayMode = resolvedConfig.displayMode || 'normal';
const composedStyles = [style, displayMode === 'expand' ? {
width: availableWidth
} : displayMode === 'embedded' ? {
maxWidth: availableWidth
} : null];
return { ...resolvedConfig,
...stats,
html,
sourceBaseUrl: documentBaseUrl,
style: composedStyles,
onLinkPress,
WebView
};
}
//# sourceMappingURL=useHtmlTableProps.js.map