@vaadin/hilla-react-crud
Version:
Hilla CRUD utils for React
49 lines • 1.84 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import React, { forwardRef } from 'react';
export function convertToTitleCase(inputString) {
const stringWithSpaces = inputString.replace(/_/gu, ' ');
const words = stringWithSpaces.split(' ');
const titleCaseWords = words.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase());
return titleCaseWords.join(' ');
}
export function registerStylesheet(stylesheet) {
const css = Array.from(stylesheet.cssRules)
.map((rule) => rule.cssText)
.join('\n');
const styleTag = document.createElement('style');
styleTag.textContent = css;
document.head.prepend(styleTag);
}
const registeredFeatures = new Set();
function useFeatureRegistration(feature) {
if (registeredFeatures.has(feature)) {
return;
}
registeredFeatures.add(feature);
((feature, vaadinObj = (window.Vaadin ??= {})) => {
vaadinObj.registrations ??= [];
vaadinObj.registrations.push({
is: feature ? `@vaadin/hilla-react-crud/${feature}` : '@vaadin/hilla-react-crud',
version: '24.7.2',
});
})(feature);
}
export function featureRegistration(Component, feature) {
return forwardRef((props, ref) => {
useFeatureRegistration(feature);
return _jsx(Component, { ...props, ref: ref });
});
}
export function isFilterEmpty(filter) {
if (filter['@type'] === 'and' || filter['@type'] === 'or') {
if (filter.children.length === 0) {
return true;
}
return filter.children.every((child) => isFilterEmpty(child));
}
if ('filterValue' in filter) {
return filter.filterValue === '';
}
throw new Error(`Unknown filter type: ${'@type' in filter ? filter['@type'] : JSON.stringify(filter)} `);
}
//# sourceMappingURL=util.js.map