Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
"module": "build/esm/index.js",
"types": "types/src/index.d.ts",
"exports": {
".": {
"types": "./types/src/index.d.ts",
"require": "./build/cjs/index.js",
"import": "./build/esm/index.js"
"./window-scroll": {
"types": "./types/src/window-scroll.d.ts",
"require": "./build/cjs/window-scroll.js",
"import": "./build/esm/window-scroll.js"
},
"./container-scroll": {
"types": "./types/src/container-scroll.d.ts",
"require": "./build/cjs/container-scroll.js",
"import": "./build/esm/container-scroll.js"
}
},
"files": [
Expand Down
143 changes: 0 additions & 143 deletions src/ReactUnipika/ReactUnipika.tsx

This file was deleted.

117 changes: 117 additions & 0 deletions src/ReactUnipika/ReactUnipikaBase.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import React from 'react';

// @ts-expect-error
import unipika from '@gravity-ui/unipika/lib/unipika';

import {cn} from '../utils/classname';
import {ReactUnipikaCommonProps} from './types';
import {UnipikaSettings} from '../StructuredYson/types';
import {defaultUnipikaSettings} from './constants';

const block = cn('g-ru-react-unipika');

interface ConvertedValue {
convertedValue?: any;

Check warning on line 14 in src/ReactUnipika/ReactUnipikaBase.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
error?: any;

Check warning on line 15 in src/ReactUnipika/ReactUnipikaBase.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
}

function convertValue(value: any, settings: UnipikaSettings): ConvertedValue {

Check warning on line 18 in src/ReactUnipika/ReactUnipikaBase.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
try {
// TODO: fix me later
// The call is required because unipika.format() applies default values to a passed settings inplace.
// We have to leave this call without it the behaviour will be broken.
if (settings.format === 'raw-json') {
unipika.formatRaw(value, settings);
} else {
unipika.formatFromYSON(value, settings);
}

if (value === undefined) {
return {convertedValue: ''};
}

if (settings.format === 'raw-json') {
return {convertedValue: unipika.converters.raw(value, settings)};
}

return {convertedValue: unipika.converters.yson(value, settings)};
} catch (error) {
return {error};
}
}

interface WithReactUnipikaBaseProps<P extends ReactUnipikaCommonProps> {
renderVirtualized: (props: P, convertedValue: any) => React.ReactNode;

Check warning on line 44 in src/ReactUnipika/ReactUnipikaBase.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
}

export function withReactUnipikaBase<P extends ReactUnipikaCommonProps>(
config: WithReactUnipikaBaseProps<P>,
) {
return function ReactUnipikaBaseComponent(props: P) {
const {
value,
settings = defaultUnipikaSettings,
inline = false,
children,
virtualized = true,
className,
renderError,
} = props;

const {convertedValue, error} = React.useMemo(
() => convertValue(value, settings),
[value, settings],
);

const getFormattedTitle = React.useCallback(() => {
if (!inline) {
return undefined;
}

const titleSettings = Object.assign({}, settings, {asHTML: false});
return unipika.format(convertedValue, titleSettings);
}, [inline, settings, convertedValue]);

const getFormattedValue = React.useCallback(() => {
return unipika.format(convertedValue, settings);
}, [convertedValue, settings]);

const classes = block(
{
inline: inline && 'yes',
},
className,
);

if (error) {
return renderError?.(error);
}

return settings.asHTML ? (
<div className={classes} title={getFormattedTitle()} dir="auto">
{virtualized ? (
config.renderVirtualized(props, convertedValue)
) : (
<pre
className="unipika"
dangerouslySetInnerHTML={{
__html: getFormattedValue(),
}}
/>
)}
{children}
</div>
) : (
<div
className={classes}
title={getFormattedTitle()}
dangerouslySetInnerHTML={{
__html: getFormattedValue(),
}}
dir="auto"
>
{children}
</div>
);
};
}
39 changes: 39 additions & 0 deletions src/ReactUnipika/ReactUnipikaContainerScroll.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';

import {StructuredYsonContainerScroll} from '../StructuredYson/StructuredYsonContainerScroll';
import {withReactUnipikaBase} from './ReactUnipikaBase';
import {ReactUnipikaWithScrollContainer} from './types';
import {defaultUnipikaSettings} from './constants';

export const ReactUnipikaContainerScroll = withReactUnipikaBase<ReactUnipikaWithScrollContainer>({
renderVirtualized: (props, convertedValue) => {
const {
settings = defaultUnipikaSettings,
extraTools,
customLayout,
toolbarStickyTop,
renderToolbar,
collapseIconType,
showContainerSize,
initiallyCollapsed,
caseInsensitiveSearch,
scrollContainerRef,
} = props;

return (
<StructuredYsonContainerScroll
value={convertedValue}
settings={settings}
extraTools={extraTools}
customLayout={customLayout}
toolbarStickyTop={toolbarStickyTop}
renderToolbar={renderToolbar}
collapseIconType={collapseIconType}
showContainerSize={showContainerSize}
initiallyCollapsed={initiallyCollapsed}
caseInsensitiveSearch={caseInsensitiveSearch}
scrollContainerRef={scrollContainerRef}
/>
);
},
});
37 changes: 37 additions & 0 deletions src/ReactUnipika/ReactUnipikaWindowScroll.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';

import {StructuredYsonWindowScroll} from '../StructuredYson/StructuredYsonWindowScroll';
import {withReactUnipikaBase} from './ReactUnipikaBase';
import {ReactUnipikaCommonProps} from './types';
import {defaultUnipikaSettings} from './constants';

export const ReactUnipikaWindowScroll = withReactUnipikaBase<ReactUnipikaCommonProps>({
renderVirtualized: (props, convertedValue) => {
const {
settings = defaultUnipikaSettings,
extraTools,
customLayout,
toolbarStickyTop,
renderToolbar,
collapseIconType,
showContainerSize,
initiallyCollapsed,
caseInsensitiveSearch,
} = props;

return (
<StructuredYsonWindowScroll
value={convertedValue}
settings={settings}
extraTools={extraTools}
customLayout={customLayout}
toolbarStickyTop={toolbarStickyTop}
renderToolbar={renderToolbar}
collapseIconType={collapseIconType}
showContainerSize={showContainerSize}
initiallyCollapsed={initiallyCollapsed}
caseInsensitiveSearch={caseInsensitiveSearch}
/>
);
},
});
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading