type
stringclasses 7
values | content
stringlengths 4
9.55k
| repo
stringlengths 7
96
| path
stringlengths 4
178
| language
stringclasses 1
value |
|---|---|---|---|---|
ArrowFunction
|
(host, value) => value
|
auzmartist/mandala
|
src/components/mandala-companion.ts
|
TypeScript
|
ArrowFunction
|
(host, value) => {
host.mandala.forEach((m) => m.template = [...host.template])
dispatch(host, 'change', {detail: {
template: [...host.template]
}, bubbles: true})
}
|
auzmartist/mandala
|
src/components/mandala-companion.ts
|
TypeScript
|
ArrowFunction
|
(m) => m.template = [...host.template]
|
auzmartist/mandala
|
src/components/mandala-companion.ts
|
TypeScript
|
ArrowFunction
|
(host) => (fn) => host.state = fn(host.state)
|
auzmartist/mandala
|
src/components/mandala-companion.ts
|
TypeScript
|
ArrowFunction
|
(fn) => host.state = fn(host.state)
|
auzmartist/mandala
|
src/components/mandala-companion.ts
|
TypeScript
|
ArrowFunction
|
({state}) => state.layers[state.active]
|
auzmartist/mandala
|
src/components/mandala-companion.ts
|
TypeScript
|
ArrowFunction
|
({state: {layers}}) => arrChain([...layers])
|
auzmartist/mandala
|
src/components/mandala-companion.ts
|
TypeScript
|
ArrowFunction
|
({state, activeLayer, styleToggle, mandalaStyles}) => html`
<div>
<section class="editor">
<div class="preview">
<nav>
<small class="c-active">Layer: ${state.active}</small>
</nav>
<mandala-polygon n="${activeLayer[0]}" r="${activeLayer[1]}" vr="${activeLayer[2]}" d="${state.active}" />
</div>
<div class="config">
${state.layers.map((l, i) => html`
<div class="layer ${state.active === i ? 'active' : ''}" tabindex="${i}" data-layer="${i}" onclick="${setActiveLayer}">
${l.map((v, idx) => html`
<input type="number" size="5" min="1" step="1" value="${v}" data-layer="${i}"
onfocus="${setActiveLayer}"
onchange="${(host, e) => setLayerValue(host, e, idx)}"/>
`)}
<button class="delete" title="Delete"
onclick="${(host) => deleteLayer(host, i)}">🗙</button>
</div>
`)}
<button class="add" onclick="${addLayer}">Add Layer</button>
</div>
<hr/>
<mandala-style-companion layer="${state.active}" active="${styleToggle}"
onstyle="${setMandalaStyles}"/>
</section>
<slot></slot>
</div>
<style>
${mandalaStyles}
</style>
`.define({MandalaPolygon, MandalaStyleCompanion}).style(styles.toString())
|
auzmartist/mandala
|
src/components/mandala-companion.ts
|
TypeScript
|
ArrowFunction
|
(l, i) => html`
<div class="layer ${state.active === i ? 'active' : ''}" tabindex="${i}" data-layer="${i}" onclick="${setActiveLayer}">
${l.map((v, idx) => html`
<input type="number" size="5" min="1" step="1" value="${v}" data-layer="${i}"
onfocus="${setActiveLayer}"
onchange="${(host, e) => setLayerValue(host, e, idx)}"/>
`)}
<button class="delete" title="Delete"
onclick="${(host) => deleteLayer(host, i)}">🗙</button>
</div>
`
|
auzmartist/mandala
|
src/components/mandala-companion.ts
|
TypeScript
|
ArrowFunction
|
(v, idx) => html`
<input type="number" size="5" min="1" step="1" value="${v}" data-layer="${i}"
onfocus="${setActiveLayer}"
onchange="${(host, e) => setLayerValue(host, e, idx)}"/>
`
|
auzmartist/mandala
|
src/components/mandala-companion.ts
|
TypeScript
|
ArrowFunction
|
(host, e) => setLayerValue(host, e, idx)
|
auzmartist/mandala
|
src/components/mandala-companion.ts
|
TypeScript
|
ArrowFunction
|
(host) => deleteLayer(host, i)
|
auzmartist/mandala
|
src/components/mandala-companion.ts
|
TypeScript
|
InterfaceDeclaration
|
interface MandalaCompanion extends HTMLElement {
type: string
[key: string]: any
}
|
auzmartist/mandala
|
src/components/mandala-companion.ts
|
TypeScript
|
ArrowFunction
|
value => {
this.setState({ inputValue: value });
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
value => {
this.setState({ inputPlaceHolder: value });
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => {
if (this.inputRef && this.inputRef.current) {
// TODO: check the reason
(this.inputRef.current as any).focus();
}
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
cb => {
const clickOutsideHandler = (e: Event) => {
const optionInstance = this.optionsRef && this.optionsRef.current;
const triggerDom = this.triggerRef && this.triggerRef.current;
const optionsDom = ReactDOM.findDOMNode(optionInstance);
const target = e.target as Element;
if (
optionsDom &&
(!optionsDom.contains(target) || !optionsDom.contains(target.parentNode)) &&
triggerDom &&
!triggerDom.contains(target)
) {
cb(e);
}
};
this.clickOutsideHandler = clickOutsideHandler;
document.addEventListener('mousedown', clickOutsideHandler, false);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
(e: Event) => {
const optionInstance = this.optionsRef && this.optionsRef.current;
const triggerDom = this.triggerRef && this.triggerRef.current;
const optionsDom = ReactDOM.findDOMNode(optionInstance);
const target = e.target as Element;
if (
optionsDom &&
(!optionsDom.contains(target) || !optionsDom.contains(target.parentNode)) &&
triggerDom &&
!triggerDom.contains(target)
) {
cb(e);
}
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => {
document.removeEventListener('mousedown', this.clickOutsideHandler, false);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => {
let { rePosKey } = this.state;
rePosKey = rePosKey + 1;
this.setState({ rePosKey });
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
states => {
this.setState({ ...states } as CascaderState);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => {
this.setState({ isOpen: true });
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
cb => {
this.setState({ isOpen: false }, () => {
cb && cb();
});
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => {
cb && cb();
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
selectedKeys => this.setState({ selectedKeys })
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
value => {
this.props.onChange && this.props.onChange(value);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
selected => {
this.props.onSelect && this.props.onSelect(selected);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
input => {
this.props.onSearch && this.props.onSearch(input);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
(...v) => {
this.props.onFocus && this.props.onFocus(...v);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
(...v) => {
this.props.onBlur && this.props.onBlur(...v);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
visible => {
this.props.onDropdownVisibleChange(visible);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
bool => {
this.setState({ isHovering: bool });
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
(selectedOpt, callback) => {
const { loadData } = this.props;
if (loadData) {
new Promise<void>(resolve => {
loadData(selectedOpt).then(() => {
callback();
this.setState({ loading: false });
resolve();
});
});
}
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
resolve => {
loadData(selectedOpt).then(() => {
callback();
this.setState({ loading: false });
resolve();
});
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => {
callback();
this.setState({ loading: false });
resolve();
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
(newLoadedKeys, data) => {
const { onLoad } = this.props;
onLoad && onLoad(newLoadedKeys, data);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
(e, { panelIndex, activeNode }) => {
this.props.onListScroll(e, { panelIndex, activeNode });
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
data => this.props.onExceed(data)
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => this.props.onClear()
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
(name: string) => {
const firstInProps = isEmpty(prevProps) && name in props;
const nameHasChange = prevProps && !isEqual(prevProps[name], props[name]);
return firstInProps || nameHasChange;
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => {
const firstInProps = !prevProps && 'treeData' in props;
const treeDataHasChange = prevProps && prevProps.treeData !== props.treeData;
return firstInProps || treeDataHasChange;
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
(valueItem: SimpleValueType[]) => {
const formatItem: (string | number)[] = onChangeWithObject ?
(valueItem as CascaderData[]).map(i => i.value) :
valueItem as (string | number)[];
formatValuePath.push(formatItem);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
i => i.value
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
v => {
const formatKeyItem = findKeysForValues(v, keyEntities);
!isEmpty(formatKeyItem) && formatKeys.push(formatKeyItem);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
(value: string) => {
this.foundation.handleInputChange(value);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
(e: any, tagValuePath: Array<string | number>) => {
this.foundation.handleTagRemove(e, tagValuePath);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
(value: string | Array<string>, idx: number, type: string) => {
const { keyEntities, disabledKeys } = this.state;
const { size, disabled, displayProp, displayRender, disableStrictly } = this.props;
const nodeKey = type === strings.IS_VALUE ?
findKeysForValues(value, keyEntities)[0] :
value;
const isDsiabled = disabled ||
keyEntities[nodeKey].data.disabled ||
(disableStrictly && disabledKeys.has(nodeKey));
if (!isEmpty(keyEntities) && !isEmpty(keyEntities[nodeKey])) {
const tagCls = cls(`${prefixcls}-selection-tag`, {
[`${prefixcls}-selection-tag-disabled`]: isDsiabled,
});
// custom render tags
if (isFunction(displayRender)) {
return displayRender(keyEntities[nodeKey], idx);
// default render tags
} else {
return (
<Tag
size={size === 'default' ? 'large' : size}
key={`tag-${nodeKey}-${idx}`}
color="white"
className={tagCls}
closable
onClose={(tagChildren, e) => {
// When value has not changed, prevent clicking tag closeBtn to close tag
e.preventDefault();
this.handleTagRemove(e, keyEntities[nodeKey].valuePath);
}}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
checkedKey => {
if (!isEmpty(keyEntities[checkedKey])) {
tagValue.push(keyEntities[checkedKey].valuePath);
}
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
(e: MouseEvent, item: Entity | Data) => {
this.foundation.handleItemClick(e, item);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
(e: MouseEvent, item: Entity) => {
this.foundation.handleItemHover(e, item);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
(item: Entity | Data) => {
this.foundation.onItemCheckboxClick(item);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
(e: React.UIEvent<HTMLUListElement, UIEvent>, ind: number) => {
this.foundation.handleListScroll(e, ind);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => {
const {
inputValue,
isSearching,
activeKeys,
selectedKeys,
checkedKeys,
halfCheckedKeys,
loadedKeys,
loadingKeys
} = this.state;
const {
filterTreeNode,
dropdownClassName,
dropdownStyle,
loadData,
emptyContent,
separator,
topSlot,
bottomSlot,
showNext,
multiple
} = this.props;
const searchable = Boolean(filterTreeNode) && isSearching;
const popoverCls = cls(dropdownClassName, `${prefixcls}-popover`);
const renderData = this.foundation.getRenderData();
const content = (
<div className={popoverCls} role="list-box" style={dropdownStyle}>
{topSlot}
<Item
activeKeys={activeKeys}
selectedKeys={selectedKeys}
separator={separator}
loadedKeys={loadedKeys}
loadingKeys={loadingKeys}
onItemClick={this.handleItemClick}
onItemHover={this.handleItemHover}
showNext={showNext}
onItemCheckboxClick={this.onItemCheckboxClick}
onListScroll={this.handleListScroll}
searchable={searchable}
keyword={inputValue}
emptyContent={emptyContent}
loadData={loadData}
data={renderData}
multiple={multiple}
checkedKeys={checkedKeys}
halfCheckedKeys={halfCheckedKeys}
/>
{bottomSlot}
</div>
);
return content;
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
(hiddenTag: Array<ReactNode>) => {
const { disabled, showRestTagsPopover, restTagsPopoverProps } = this.props;
const plusNCls = cls(`${prefixcls}-selection-n`, {
[`${prefixcls}-selection-n-disabled`]: disabled
});
const renderPlusNChildren = (
<span className={plusNCls}>
+{hiddenTag.length}
</span>
);
return (
showRestTagsPopover && !disabled ?
(
<Popover
content={hiddenTag}
showArrow
trigger="hover"
position="top"
autoAdjustOverflow
{...restTagsPopoverProps}
>
{renderPlusNChildren}
</Popover>
) :
renderPlusNChildren
);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => {
const { autoMergeValue, maxTagCount } = this.props;
const { checkedKeys, resolvedCheckedKeys } = this.state;
const realKeys = this.mergeType === strings.NONE_MERGE_TYPE
? checkedKeys
: resolvedCheckedKeys;
const displayTag: Array<ReactNode> = [];
const hiddenTag: Array<ReactNode> = [];
[...realKeys].forEach((checkedKey, idx) => {
const notExceedMaxTagCount = !isNumber(maxTagCount) || maxTagCount >= idx + 1;
const item = this.renderTagItem(checkedKey, idx, strings.IS_KEY);
if (notExceedMaxTagCount) {
displayTag.push(item);
} else {
hiddenTag.push(item);
}
});
return (
<>
{displayTag}
{!isEmpty(hiddenTag) && this.renderPlusN(hiddenTag)}
</>
);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
(checkedKey, idx) => {
const notExceedMaxTagCount = !isNumber(maxTagCount) || maxTagCount >= idx + 1;
const item = this.renderTagItem(checkedKey, idx, strings.IS_KEY);
if (notExceedMaxTagCount) {
displayTag.push(item);
} else {
hiddenTag.push(item);
}
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => {
const { placeholder, filterTreeNode, multiple } = this.props;
const { selectedKeys, checkedKeys } = this.state;
const searchable = Boolean(filterTreeNode);
if (!searchable) {
if (multiple) {
if (isEmpty(checkedKeys)) {
return <span className={`${prefixcls}-selection-placeholder`}>{placeholder}</span>;
}
return this.renderMultipleTags();
} else {
const displayText = selectedKeys.size ?
this.foundation.renderDisplayText([...selectedKeys][0]) :
'';
const spanCls = cls({
[`${prefixcls}-selection-placeholder`]: !displayText || !displayText.length,
});
return <span className={spanCls}>{displayText ? displayText : placeholder}</span>;
}
}
const input = multiple ? this.renderTagInput() : this.renderInput();
return input;
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => {
const { suffix }: any = this.props;
const suffixWrapperCls = cls({
[`${prefixcls}-suffix`]: true,
[`${prefixcls}-suffix-text`]: suffix && isString(suffix),
[`${prefixcls}-suffix-icon`]: isSemiIcon(suffix),
});
return <div className={suffixWrapperCls}>{suffix}</div>;
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => {
const { prefix, insetLabel } = this.props;
const labelNode: any = prefix || insetLabel;
const prefixWrapperCls = cls({
[`${prefixcls}-prefix`]: true,
// to be doublechecked
[`${prefixcls}-inset-label`]: insetLabel,
[`${prefixcls}-prefix-text`]: labelNode && isString(labelNode),
[`${prefixcls}-prefix-icon`]: isSemiIcon(labelNode),
});
return <div className={prefixWrapperCls}>{labelNode}</div>;
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => {
const { disabled, triggerRender, multiple } = this.props;
const { selectedKeys, inputValue, inputPlaceHolder, resolvedCheckedKeys, checkedKeys } = this.state;
let realValue;
if (multiple) {
if (this.mergeType === strings.NONE_MERGE_TYPE) {
realValue = checkedKeys;
} else {
realValue = resolvedCheckedKeys;
}
} else {
realValue = [...selectedKeys][0];
}
return (
<Trigger
value={realValue}
inputValue={inputValue}
onChange={this.handleInputChange}
onClear={this.handleClear}
placeholder={inputPlaceHolder}
disabled={disabled}
triggerRender={triggerRender}
componentName={'Cascader'}
componentProps={{ ...this.props }}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => {
this.foundation.toggleHoverState(true);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => {
this.foundation.toggleHoverState(false);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
(e: MouseEvent) => {
e && e.stopPropagation();
this.foundation.handleClear();
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => {
const { showClear, disabled, multiple } = this.props;
const { selectedKeys, isOpen, isHovering, checkedKeys } = this.state;
const hasValue = selectedKeys.size;
const multipleWithHaveValue = multiple && checkedKeys.size;
return showClear && (hasValue || multipleWithHaveValue) && !disabled && (isOpen || isHovering);
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => {
const clearCls = cls(`${prefixcls}-clearbtn`);
const allowClear = this.showClearBtn();
if (allowClear) {
return (
<div className={clearCls} onClick={this.handleClear}>
<IconClear />
</div>
);
}
return null;
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => {
const { arrowIcon } = this.props;
const showClearBtn = this.showClearBtn();
if (showClearBtn) {
return null;
}
return arrowIcon ? <div className={cls(`${prefixcls}-arrow`)}>{arrowIcon}</div> : null;
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => {
const {
disabled,
multiple,
filterTreeNode,
style,
size,
className,
validateStatus,
prefix,
suffix,
insetLabel,
triggerRender,
showClear,
} = this.props;
const { isOpen, isFocus, isInput, checkedKeys } = this.state;
const filterable = Boolean(filterTreeNode);
const useCustomTrigger = typeof triggerRender === 'function';
const classNames = useCustomTrigger ?
cls(className) :
cls(prefixcls, className, {
[`${prefixcls}-focus`]: isFocus || (isOpen && !isInput),
[`${prefixcls}-disabled`]: disabled,
[`${prefixcls}-single`]: true,
[`${prefixcls}-filterable`]: filterable,
[`${prefixcls}-error`]: validateStatus === 'error',
[`${prefixcls}-warning`]: validateStatus === 'warning',
[`${prefixcls}-small`]: size === 'small',
[`${prefixcls}-large`]: size === 'large',
[`${prefixcls}-with-prefix`]: prefix || insetLabel,
[`${prefixcls}-with-suffix`]: suffix,
});
const mouseEvent = showClear ?
{
onMouseEnter: () => this.handleMouseOver(),
onMouseLeave: () => this.handleMouseLeave(),
} :
{};
const sectionCls = cls(`${prefixcls}-selection`, {
[`${prefixcls}-selection-multiple`]: multiple && !isEmpty(checkedKeys),
});
const inner = useCustomTrigger ?
this.renderCustomTrigger() :
[
<Fragment key={'prefix'}>{prefix || insetLabel ? this.renderPrefix() : null}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => this.handleMouseOver()
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
ArrowFunction
|
() => this.handleMouseLeave()
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
InterfaceDeclaration
|
export interface ScrollPanelProps extends BasicScrollPanelProps {
activeNode: CascaderData;
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
InterfaceDeclaration
|
export interface TriggerRenderProps extends BasicTriggerRenderProps {
componentProps: CascaderProps;
onClear: (e: React.MouseEvent) => void;
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
InterfaceDeclaration
|
export interface CascaderProps extends BasicCascaderProps {
arrowIcon?: ReactNode;
defaultValue?: Value;
dropdownStyle?: CSSProperties;
emptyContent?: ReactNode;
motion?: Motion;
treeData?: Array<CascaderData>;
restTagsPopoverProps?: PopoverProps;
children?: ReactNode;
value?: Value;
prefix?: ReactNode;
suffix?: ReactNode;
insetLabel?: ReactNode;
style?: CSSProperties;
bottomSlot?: ReactNode;
topSlot?: ReactNode;
triggerRender?: (props: TriggerRenderProps) => ReactNode;
onListScroll?: (e: React.UIEvent<HTMLUListElement, UIEvent>, panel: ScrollPanelProps) => void;
loadData?: (selectOptions: CascaderData[]) => Promise<void>;
onLoad?: (newLoadedKeys: Set<string>, data: CascaderData) => void;
onChange?: (value: Value) => void;
onExceed?: (checkedItem: Entity[]) => void;
displayRender?: (selected: Array<string> | Entity, idx?: number) => ReactNode;
onBlur?: (e: MouseEvent) => void;
onFocus?: (e: MouseEvent) => void;
validateStatus?: ValidateStatus;
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
InterfaceDeclaration
|
export interface CascaderState extends BasicCascaderInnerData {
keyEntities: Entities;
prevProps: CascaderProps;
treeData?: Array<CascaderData>;
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
TypeAliasDeclaration
|
/* The basic type of the value of Cascader */
export type SimpleValueType = string | number | CascaderData;
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
TypeAliasDeclaration
|
/* The value of Cascader */
export type Value = SimpleValueType | Array<SimpleValueType> | Array<Array<SimpleValueType>>;
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
MethodDeclaration
|
static getDerivedStateFromProps(props: CascaderProps, prevState: CascaderState) {
const {
multiple,
value,
defaultValue,
onChangeWithObject,
leafOnly,
autoMergeValue,
} = props;
const { prevProps } = prevState;
let keyEntities = prevState.keyEntities || {};
const newState: Partial<CascaderState> = { };
const needUpdate = (name: string) => {
const firstInProps = isEmpty(prevProps) && name in props;
const nameHasChange = prevProps && !isEqual(prevProps[name], props[name]);
return firstInProps || nameHasChange;
};
const needUpdateData = () => {
const firstInProps = !prevProps && 'treeData' in props;
const treeDataHasChange = prevProps && prevProps.treeData !== props.treeData;
return firstInProps || treeDataHasChange;
};
const needUpdateTreeData = needUpdate('treeData') || needUpdateData();
const needUpdateValue = needUpdate('value') || (isEmpty(prevProps) && defaultValue);
if (multiple) {
// when value and treedata need updated
if (needUpdateTreeData || needUpdateValue) {
// update state.keyEntities
if (needUpdateTreeData) {
newState.treeData = props.treeData;
keyEntities = convertDataToEntities(props.treeData);
newState.keyEntities = keyEntities;
}
let realKeys: Array<string> | Set<string> = prevState.checkedKeys;
// when data was updated
if (needUpdateValue) {
// normallizedValue is used to save the value in two-dimensional array format
let normallizedValue: SimpleValueType[][] = [];
const realValue = needUpdate('value') ? value : defaultValue;
// eslint-disable-next-line max-depth
if (Array.isArray(realValue)) {
normallizedValue = Array.isArray(realValue[0]) ?
realValue as SimpleValueType[][] :
[realValue] as SimpleValueType[][];
} else {
normallizedValue = [[realValue]];
}
// formatValuePath is used to save value of valuePath
const formatValuePath: (string | number)[][] = [];
normallizedValue.forEach((valueItem: SimpleValueType[]) => {
const formatItem: (string | number)[] = onChangeWithObject ?
(valueItem as CascaderData[]).map(i => i.value) :
valueItem as (string | number)[];
formatValuePath.push(formatItem);
});
// formatKeys is used to save key of value
const formatKeys: any[] = [];
formatValuePath.forEach(v => {
const formatKeyItem = findKeysForValues(v, keyEntities);
!isEmpty(formatKeyItem) && formatKeys.push(formatKeyItem);
});
realKeys = formatKeys;
}
const calRes = calcCheckedKeys(flatten(realKeys as string[]), keyEntities);
const checkedKeys = new Set(calRes.checkedKeys);
const halfCheckedKeys = new Set(calRes.halfCheckedKeys);
// disableStrictly
if (props.disableStrictly) {
newState.disabledKeys = calcDisabledKeys(keyEntities);
}
const isLeafOnlyMerge = calcMergeType(autoMergeValue, leafOnly) === strings.LEAF_ONLY_MERGE_TYPE;
newState.prevProps = props;
newState.checkedKeys = checkedKeys;
newState.halfCheckedKeys = halfCheckedKeys;
newState.resolvedCheckedKeys = new Set(normalizeKeyList(checkedKeys, keyEntities, isLeafOnlyMerge));
}
}
return newState;
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
MethodDeclaration
|
componentDidMount() {
this.foundation.init();
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
MethodDeclaration
|
componentWillUnmount() {
this.foundation.destroy();
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
MethodDeclaration
|
componentDidUpdate(prevProps: CascaderProps) {
let isOptionsChanged = false;
if (!isEqual(prevProps.treeData, this.props.treeData)) {
isOptionsChanged = true;
this.foundation.collectOptions();
}
if (prevProps.value !== this.props.value && !isOptionsChanged) {
this.foundation.handleValueChange(this.props.value);
}
}
|
huxiangdev/semi-design
|
packages/semi-ui/cascader/index.tsx
|
TypeScript
|
FunctionDeclaration
|
function serialize(data: string): Buffer {
const header: Buffer = Buffer.alloc(5);
header.writeUInt8(0, 0); // TODO: Uncompressed only
header.writeInt32BE(data.length, 1);
return Buffer.concat([header, Buffer.from(data, 'utf8')]);
}
|
SProst/grpc-node
|
packages/grpc-js/test/test-call-stream.ts
|
TypeScript
|
ArrowFunction
|
() => {
assert2.clearMustCalls();
}
|
SProst/grpc-node
|
packages/grpc-js/test/test-call-stream.ts
|
TypeScript
|
ArrowFunction
|
done => {
const responseMetadata = new Metadata();
responseMetadata.add('key', 'value');
const callStream = new Http2CallStream(
'foo',
{} as Http2Channel,
callStreamArgs,
filterStackFactory
);
const http2Stream = new ClientHttp2StreamMock({
payload: Buffer.alloc(0),
frameLengths: [],
});
callStream.once(
'metadata',
assert2.mustCall(metadata => {
assert.deepStrictEqual(metadata.get('key'), ['value']);
})
);
callStream.attachHttp2Stream(http2Stream);
http2Stream.emitResponse(200, responseMetadata);
assert2.afterMustCallsSatisfied(done);
}
|
SProst/grpc-node
|
packages/grpc-js/test/test-call-stream.ts
|
TypeScript
|
ArrowFunction
|
metadata => {
assert.deepStrictEqual(metadata.get('key'), ['value']);
}
|
SProst/grpc-node
|
packages/grpc-js/test/test-call-stream.ts
|
TypeScript
|
ArrowFunction
|
() => {
const c = http2.constants;
const s = Status;
const errorCodeMapping = {
[c.NGHTTP2_NO_ERROR]: s.INTERNAL,
[c.NGHTTP2_PROTOCOL_ERROR]: s.INTERNAL,
[c.NGHTTP2_INTERNAL_ERROR]: s.INTERNAL,
[c.NGHTTP2_FLOW_CONTROL_ERROR]: s.INTERNAL,
[c.NGHTTP2_SETTINGS_TIMEOUT]: s.INTERNAL,
[c.NGHTTP2_STREAM_CLOSED]: null,
[c.NGHTTP2_FRAME_SIZE_ERROR]: s.INTERNAL,
[c.NGHTTP2_REFUSED_STREAM]: s.UNAVAILABLE,
[c.NGHTTP2_CANCEL]: s.CANCELLED,
[c.NGHTTP2_COMPRESSION_ERROR]: s.INTERNAL,
[c.NGHTTP2_CONNECT_ERROR]: s.INTERNAL,
[c.NGHTTP2_ENHANCE_YOUR_CALM]: s.RESOURCE_EXHAUSTED,
[c.NGHTTP2_INADEQUATE_SECURITY]: s.PERMISSION_DENIED,
};
const keys = Object.keys(errorCodeMapping).map(key => Number(key));
keys.forEach(key => {
const value = errorCodeMapping[key];
// A null value indicates: behavior isn't specified, so skip this test.
const maybeSkip = (fn: typeof it) => (value ? fn : fn.skip);
maybeSkip(it)(`for error code ${key}`, () => {
return new Promise((resolve, reject) => {
const callStream = new Http2CallStream(
'foo',
{} as Http2Channel,
callStreamArgs,
filterStackFactory
);
const http2Stream = new ClientHttp2StreamMock({
payload: Buffer.alloc(0),
frameLengths: [],
});
callStream.attachHttp2Stream(http2Stream);
callStream.once('status', status => {
try {
assert.strictEqual(status.code, value);
resolve();
} catch (e) {
reject(e);
}
});
http2Stream.rstCode = Number(key);
http2Stream.emit('close');
});
});
});
}
|
SProst/grpc-node
|
packages/grpc-js/test/test-call-stream.ts
|
TypeScript
|
ArrowFunction
|
key => Number(key)
|
SProst/grpc-node
|
packages/grpc-js/test/test-call-stream.ts
|
TypeScript
|
ArrowFunction
|
key => {
const value = errorCodeMapping[key];
// A null value indicates: behavior isn't specified, so skip this test.
const maybeSkip = (fn: typeof it) => (value ? fn : fn.skip);
maybeSkip(it)(`for error code ${key}`, () => {
return new Promise((resolve, reject) => {
const callStream = new Http2CallStream(
'foo',
{} as Http2Channel,
callStreamArgs,
filterStackFactory
);
const http2Stream = new ClientHttp2StreamMock({
payload: Buffer.alloc(0),
frameLengths: [],
});
callStream.attachHttp2Stream(http2Stream);
callStream.once('status', status => {
try {
assert.strictEqual(status.code, value);
resolve();
} catch (e) {
reject(e);
}
});
http2Stream.rstCode = Number(key);
http2Stream.emit('close');
});
});
}
|
SProst/grpc-node
|
packages/grpc-js/test/test-call-stream.ts
|
TypeScript
|
ArrowFunction
|
(fn: typeof it) => (value ? fn : fn.skip)
|
SProst/grpc-node
|
packages/grpc-js/test/test-call-stream.ts
|
TypeScript
|
ArrowFunction
|
() => {
return new Promise((resolve, reject) => {
const callStream = new Http2CallStream(
'foo',
{} as Http2Channel,
callStreamArgs,
filterStackFactory
);
const http2Stream = new ClientHttp2StreamMock({
payload: Buffer.alloc(0),
frameLengths: [],
});
callStream.attachHttp2Stream(http2Stream);
callStream.once('status', status => {
try {
assert.strictEqual(status.code, value);
resolve();
} catch (e) {
reject(e);
}
});
http2Stream.rstCode = Number(key);
http2Stream.emit('close');
});
}
|
SProst/grpc-node
|
packages/grpc-js/test/test-call-stream.ts
|
TypeScript
|
ArrowFunction
|
(resolve, reject) => {
const callStream = new Http2CallStream(
'foo',
{} as Http2Channel,
callStreamArgs,
filterStackFactory
);
const http2Stream = new ClientHttp2StreamMock({
payload: Buffer.alloc(0),
frameLengths: [],
});
callStream.attachHttp2Stream(http2Stream);
callStream.once('status', status => {
try {
assert.strictEqual(status.code, value);
resolve();
} catch (e) {
reject(e);
}
});
http2Stream.rstCode = Number(key);
http2Stream.emit('close');
}
|
SProst/grpc-node
|
packages/grpc-js/test/test-call-stream.ts
|
TypeScript
|
ArrowFunction
|
status => {
try {
assert.strictEqual(status.code, value);
resolve();
} catch (e) {
reject(e);
}
}
|
SProst/grpc-node
|
packages/grpc-js/test/test-call-stream.ts
|
TypeScript
|
ArrowFunction
|
done => {
const callStream = new Http2CallStream(
'foo',
{} as Http2Channel,
callStreamArgs,
filterStackFactory
);
assert.strictEqual(callStream.getDeadline(), callStreamArgs.deadline);
assert.strictEqual(callStream.getStatus(), null);
const credentials = CallCredentials.createEmpty();
callStream.setCredentials(credentials);
assert.strictEqual(callStream.getCredentials(), credentials);
callStream.on(
'status',
assert2.mustCall(status => {
assert.strictEqual(status.code, Status.CANCELLED);
assert.strictEqual(status.details, ';)');
assert.strictEqual(callStream.getStatus(), status);
})
);
callStream.cancelWithStatus(Status.CANCELLED, ';)');
// TODO: getPeer
assert2.afterMustCallsSatisfied(done);
}
|
SProst/grpc-node
|
packages/grpc-js/test/test-call-stream.ts
|
TypeScript
|
ArrowFunction
|
status => {
assert.strictEqual(status.code, Status.CANCELLED);
assert.strictEqual(status.details, ';)');
assert.strictEqual(callStream.getStatus(), status);
}
|
SProst/grpc-node
|
packages/grpc-js/test/test-call-stream.ts
|
TypeScript
|
ArrowFunction
|
() => {
it('should handle an empty message', done => {
const callStream = new Http2CallStream(
'foo',
{} as Http2Channel,
callStreamArgs,
filterStackFactory
);
const http2Stream = new ClientHttp2StreamMock({
payload: serialize(''),
frameLengths: [],
});
callStream.once(
'data',
assert2.mustCall(buffer => {
assert.strictEqual(buffer.toString('utf8'), '');
})
);
callStream.attachHttp2Stream(http2Stream);
assert2.afterMustCallsSatisfied(done);
});
[
{
description: 'all data is supplied in a single frame',
frameLengths: [],
},
{
description: 'frames are split along header field delimiters',
frameLengths: [1, 4],
},
{
description:
'portions of header fields are split between different frames',
frameLengths: [2, 1, 1, 4],
},
{
description: 'frames are split into bytes',
frameLengths: range(0, 20).map(() => 1),
},
].forEach((testCase: { description: string; frameLengths: number[] }) => {
it(`should handle a short message where ${
testCase.description
}`, done => {
const callStream = new Http2CallStream(
'foo',
{} as Http2Channel,
callStreamArgs,
filterStackFactory
);
const http2Stream = new ClientHttp2StreamMock({
payload: serialize(message), // 21 bytes
frameLengths: testCase.frameLengths,
});
callStream.once(
'data',
assert2.mustCall(buffer => {
assert.strictEqual(buffer.toString('utf8'), message);
})
);
callStream.once('end', assert2.mustCall(() => {}));
callStream.attachHttp2Stream(http2Stream);
assert2.afterMustCallsSatisfied(done);
});
});
[
{
description: 'all data is supplied in a single frame',
frameLengths: [],
},
{
description: 'frames are split between delimited messages',
frameLengths: [21],
},
{
description: 'frames are split within messages',
frameLengths: [10, 22],
},
{
description: "part of 2nd message's header is in first frame",
frameLengths: [24],
},
{
description: 'frames are split into bytes',
frameLengths: range(0, 41).map(() => 1),
},
].forEach((testCase: { description: string; frameLengths: number[] }) => {
it(`should handle two messages where ${testCase.description}`, done => {
const callStream = new Http2CallStream(
'foo',
{} as Http2Channel,
callStreamArgs,
filterStackFactory
);
const http2Stream = new ClientHttp2StreamMock({
payload: Buffer.concat([serialize(message), serialize(message)]), // 42 bytes
frameLengths: testCase.frameLengths,
});
callStream.once(
'data',
assert2.mustCall(buffer => {
assert.strictEqual(buffer.toString('utf8'), message);
})
);
callStream.once(
'data',
assert2.mustCall(buffer => {
assert.strictEqual(buffer.toString('utf8'), message);
})
);
callStream.once('end', assert2.mustCall(() => {}));
callStream.attachHttp2Stream(http2Stream);
assert2.afterMustCallsSatisfied(done);
});
});
it('should send buffered writes', done => {
const callStream = new Http2CallStream(
'foo',
{} as Http2Channel,
callStreamArgs,
filterStackFactory
);
const http2Stream = new ClientHttp2StreamMock({
payload: Buffer.alloc(0),
frameLengths: [],
});
let streamFlushed = false;
http2Stream.once(
'write',
assert2.mustCall((chunk: Buffer) => {
const dataLength = chunk.readInt32BE(1);
const encodedMessage = chunk.slice(5).toString('utf8');
assert.strictEqual(dataLength, message.length);
assert.strictEqual(encodedMessage, message);
streamFlushed = true;
})
);
callStream.write(
{ message: Buffer.from(message) },
assert2.mustCall(() => {
// Ensure this is called only after contents are written to http2Stream
assert.ok(streamFlushed);
})
);
callStream.end(assert2.mustCall(() => {}));
callStream.attachHttp2Stream(http2Stream);
assert2.afterMustCallsSatisfied(done);
});
it('should cause data chunks in write calls afterward to be written to the given stream', done => {
const callStream = new Http2CallStream(
'foo',
{} as Http2Channel,
callStreamArgs,
filterStackFactory
);
const http2Stream = new ClientHttp2StreamMock({
payload: Buffer.alloc(0),
frameLengths: [],
});
http2Stream.once(
'write',
assert2.mustCall((chunk: Buffer) => {
const dataLength = chunk.readInt32BE(1);
const encodedMessage = chunk.slice(5).toString('utf8');
assert.strictEqual(dataLength, message.length);
assert.strictEqual(encodedMessage, message);
})
);
callStream.attachHttp2Stream(http2Stream);
callStream.write(
{ message: Buffer.from(message) },
assert2.mustCall(() => {})
);
callStream.end(assert2.mustCall(() => {}));
assert2.afterMustCallsSatisfied(done);
});
it('should handle underlying stream errors', () => {
const callStream = new Http2CallStream(
'foo',
{} as Http2Channel,
callStreamArgs,
filterStackFactory
);
const http2Stream = new ClientHttp2StreamMock({
payload: Buffer.alloc(0),
frameLengths: [],
});
callStream.once(
'status',
assert2.mustCall(status => {
assert.strictEqual(status.code, Status.INTERNAL);
})
);
callStream.attachHttp2Stream(http2Stream);
http2Stream.emit('error');
});
}
|
SProst/grpc-node
|
packages/grpc-js/test/test-call-stream.ts
|
TypeScript
|
ArrowFunction
|
done => {
const callStream = new Http2CallStream(
'foo',
{} as Http2Channel,
callStreamArgs,
filterStackFactory
);
const http2Stream = new ClientHttp2StreamMock({
payload: serialize(''),
frameLengths: [],
});
callStream.once(
'data',
assert2.mustCall(buffer => {
assert.strictEqual(buffer.toString('utf8'), '');
})
);
callStream.attachHttp2Stream(http2Stream);
assert2.afterMustCallsSatisfied(done);
}
|
SProst/grpc-node
|
packages/grpc-js/test/test-call-stream.ts
|
TypeScript
|
ArrowFunction
|
buffer => {
assert.strictEqual(buffer.toString('utf8'), '');
}
|
SProst/grpc-node
|
packages/grpc-js/test/test-call-stream.ts
|
TypeScript
|
ArrowFunction
|
() => 1
|
SProst/grpc-node
|
packages/grpc-js/test/test-call-stream.ts
|
TypeScript
|
ArrowFunction
|
(testCase: { description: string; frameLengths: number[] }) => {
it(`should handle a short message where ${
testCase.description
}`, done => {
const callStream = new Http2CallStream(
'foo',
{} as Http2Channel,
callStreamArgs,
filterStackFactory
);
const http2Stream = new ClientHttp2StreamMock({
payload: serialize(message), // 21 bytes
frameLengths: testCase.frameLengths,
});
callStream.once(
'data',
assert2.mustCall(buffer => {
assert.strictEqual(buffer.toString('utf8'), message);
})
);
callStream.once('end', assert2.mustCall(() => {}));
callStream.attachHttp2Stream(http2Stream);
assert2.afterMustCallsSatisfied(done);
});
}
|
SProst/grpc-node
|
packages/grpc-js/test/test-call-stream.ts
|
TypeScript
|
ArrowFunction
|
done => {
const callStream = new Http2CallStream(
'foo',
{} as Http2Channel,
callStreamArgs,
filterStackFactory
);
const http2Stream = new ClientHttp2StreamMock({
payload: serialize(message), // 21 bytes
frameLengths: testCase.frameLengths,
});
callStream.once(
'data',
assert2.mustCall(buffer => {
assert.strictEqual(buffer.toString('utf8'), message);
})
);
callStream.once('end', assert2.mustCall(() => {}));
callStream.attachHttp2Stream(http2Stream);
assert2.afterMustCallsSatisfied(done);
}
|
SProst/grpc-node
|
packages/grpc-js/test/test-call-stream.ts
|
TypeScript
|
ArrowFunction
|
buffer => {
assert.strictEqual(buffer.toString('utf8'), message);
}
|
SProst/grpc-node
|
packages/grpc-js/test/test-call-stream.ts
|
TypeScript
|
ArrowFunction
|
(testCase: { description: string; frameLengths: number[] }) => {
it(`should handle two messages where ${testCase.description}`, done => {
const callStream = new Http2CallStream(
'foo',
{} as Http2Channel,
callStreamArgs,
filterStackFactory
);
const http2Stream = new ClientHttp2StreamMock({
payload: Buffer.concat([serialize(message), serialize(message)]), // 42 bytes
frameLengths: testCase.frameLengths,
});
callStream.once(
'data',
assert2.mustCall(buffer => {
assert.strictEqual(buffer.toString('utf8'), message);
})
);
callStream.once(
'data',
assert2.mustCall(buffer => {
assert.strictEqual(buffer.toString('utf8'), message);
})
);
callStream.once('end', assert2.mustCall(() => {}));
callStream.attachHttp2Stream(http2Stream);
assert2.afterMustCallsSatisfied(done);
});
}
|
SProst/grpc-node
|
packages/grpc-js/test/test-call-stream.ts
|
TypeScript
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.