本文整理汇总了TypeScript中@ephox/katamari.Arr.head方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Arr.head方法的具体用法?TypeScript Arr.head怎么用?TypeScript Arr.head使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@ephox/katamari.Arr
的用法示例。
在下文中一共展示了Arr.head方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
(lastPos) => {
return Options.liftN([Arr.head(lastPos.getClientRects()), Arr.head(newPos.getClientRects())], (lastRect, newRect) => {
const lastDist = Math.abs(x - lastRect.left);
const newDist = Math.abs(x - newRect.left);
return newDist <= lastDist ? newPos : lastPos;
}).or(acc);
}
示例2: Uploader
const changeFileInput = (helpers: Helpers, info: ImageDialogInfo, state: ImageDialogState, api: API) => {
const data = api.getData();
api.block('Uploading image'); // What msg do we pass to the lock?
Arr.head(data.fileinput)
.fold(() => {
api.unblock();
}, (file) => {
const blobUri: string = URL.createObjectURL(file);
const uploader = Uploader({
url: info.url,
basePath: info.basePath,
credentials: info.credentials,
handler: info.handler
});
const finalize = () => {
api.unblock();
URL.revokeObjectURL(blobUri);
};
Utils.blobToDataUri(file).then((dataUrl) => {
const blobInfo = helpers.createBlobCache(file, blobUri, dataUrl);
uploader.upload(blobInfo).then((url: string) => {
api.setData({ src: { value: url, meta: { } } });
api.showTab('General');
changeSrc(helpers, info, state, api);
finalize();
}).catch((err) => {
finalize();
helpers.alertErr(api, err);
});
});
});
};
示例3: writeDeep
const composeList = (scope: Document, entries: Entry[]): Option<Element> => {
const cast: Segment[] = Arr.foldl(entries, (cast, entry) => {
return entry.depth > cast.length ? writeDeep(scope, cast, entry) : writeShallow(scope, cast, entry);
}, []);
return Arr.head(cast).map((segment) => segment.list);
};
示例4: createJoinedSections
const writeDeep = (scope: Document, outline: Section[], entry: Entry): Section[] => {
const newSections = createJoinedSections(scope, entry.depth - outline.length, entry.listType);
populateSections(newSections, entry);
Options.liftN([
Arr.last(outline),
Arr.head(newSections)
], joinSections);
return outline.concat(newSections);
};
示例5: getViewPortRect
const scrollRangeIntoView = (editor: Editor, rng: Range) => {
Arr.head(CaretPosition.fromRangeStart(rng).getClientRects()).each((rngRect) => {
const bodyRect = getViewPortRect(editor);
const overflow = getOverflow(bodyRect, rngRect);
const margin = 4;
const dx = overflow.x > 0 ? overflow.x + margin : overflow.x - margin;
const dy = overflow.y > 0 ? overflow.y + margin : overflow.y - margin;
scrollBy(editor, overflow.x !== 0 ? dx : 0, overflow.y !== 0 ? dy : 0);
});
};
示例6: if
const getMaxHeight = (heights: number[]) => {
return Arr.head(Arr.sort(heights, (a, b) => {
if (a > b) {
return -1;
} else if (a < b) {
return +1;
} else {
return 0;
}
}));
};
示例7: return
return () => {
const from = forward ? CaretPosition.fromRangeEnd(editor.selection.getRng()) : CaretPosition.fromRangeStart(editor.selection.getRng());
const result = forward ? getPositionsUntilNextLine(editor.getBody(), from) : getPositionsUntilPreviousLine(editor.getBody(), from);
const to = forward ? Arr.last(result.positions) : Arr.head(result.positions);
return to.filter(isCefPosition(forward)).fold(
Fun.constant(false),
(pos) => {
editor.selection.setRng(pos.toRange());
return true;
}
);
};
示例8: navigateIgnoreEmptyTextNodes
const isAtBlockBoundary = (forward: boolean, root: Element, pos: CaretPosition) => {
const parentBlocks = Arr.filter(Parents.parentsAndSelf(Element.fromDom(pos.container()), root), ElementType.isBlock);
return Arr.head(parentBlocks).fold(
() => {
return navigateIgnoreEmptyTextNodes(forward, root.dom(), pos).forall((newPos) => {
return isInSameBlock(newPos, pos, root.dom()) === false;
});
},
(parent) => {
return navigateIgnoreEmptyTextNodes(forward, parent.dom(), pos).isNone();
}
);
};
示例9:
const open = (editor: Editor) => {
const languages: LanguageSpec[] = Languages.getLanguages(editor);
const defaultLanguage: string = Arr.head(languages).fold(() => '', (l) => l.value);
const currentLanguage: string = Languages.getCurrentLanguage(editor, defaultLanguage);
const currentCode: string = CodeSample.getCurrentCode(editor);
editor.windowManager.open({
title: 'Insert/Edit Code Sample',
size: 'large',
body: {
type: 'panel',
items: [
{
type: 'selectbox',
name: 'language',
label: 'Language',
items: languages
},
{
type: 'textarea',
name: 'code',
label: 'Code view',
}
]
},
buttons: [
{
type: 'cancel',
name: 'cancel',
text: 'Cancel',
},
{
type: 'submit',
name: 'save',
text: 'Save',
primary: true
}
],
initialData: {
language: currentLanguage,
code: currentCode
},
onSubmit: (api) => {
const data = api.getData();
CodeSample.insertCodeSample(editor, data.language, data.code);
api.close();
}
});
};
示例10:
find: (comp: AlloyComponent) => {
const children = Replacing.contents(comp);
return Arr.head(children);
}