本文整理匯總了TypeScript中@ephox/katamari.Thunk類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Thunk類的具體用法?TypeScript Thunk怎麽用?TypeScript Thunk使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Thunk類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: handler
const resetTargets = () => {
// Reset the targets
targets.set(Thunk.cached(findTargets)());
// Trigger change handlers
Arr.each(changeHandlers.get(), (handler) => handler());
};
示例2: getInitialValue
const getGroups = Thunk.cached(function (realm, editor) {
return [
{
label: 'the link group',
items: [
SerialisedDialog.sketch({
fields: [
Inputs.field('url', 'Type or paste URL'),
Inputs.field('text', 'Link text'),
Inputs.field('title', 'Link title'),
Inputs.field('target', 'Link target'),
Inputs.hidden('link')
],
// Do not include link
maxFieldIndex: [ 'url', 'text', 'title', 'target' ].length - 1,
getInitialValue (/* dialog */) {
return Option.some(
LinkBridge.getInfo(editor)
);
},
onExecute (dialog/*, simulatedEvent */) {
const info = Representing.getValue(dialog);
LinkBridge.applyInfo(editor, info);
realm.restoreToolbar();
editor.focus();
}
})
]
}
];
});
示例3: createAutocompleteItems
const register = (editor: Editor, sharedBackstage: UiFactoryBackstageShared) => {
const autocompleter = GuiFactory.build(
InlineView.sketch({
dom: {
tag: 'div',
classes: [ 'tox-autocompleter' ]
},
components: [
],
lazySink: sharedBackstage.getSink
})
);
const isActive = () => InlineView.isOpen(autocompleter);
const closeIfNecessary = () => {
if (isActive()) {
InlineView.hide(autocompleter);
}
};
// This needs to be calcluated once things are ready, but the key events must be bound
// before `init` or other keydown / keypress listeners will fire first. Therefore,
// this is a thunk so that its value is calculated just once when it is used for the
// first time, and after that it's value is stored.
const getAutocompleters: () => Autocompleters.AutocompleterDatabase = Thunk.cached(() => {
return Autocompleters.register(editor);
});
const getCombinedItems = (triggerChar: string, matches: AutocompleteLookupData[]): ItemTypes.ItemSpec[] => {
const columns = Options.findMap(matches, (m) => Option.from(m.columns)).getOr(1);
return Arr.bind(matches, (match) => {
const choices = match.items;
return createAutocompleteItems(
choices,
(itemValue, itemMeta) => {
const nr = editor.selection.getRng();
const textNode = nr.startContainer as Text; // TODO: Investigate if this is safe
getContext(nr, triggerChar, textNode.data, nr.startOffset).fold(
() => console.error('Lost context. Cursor probably moved'),
({ rng }) => {
const autocompleterApi: InlineContent.AutocompleterInstanceApi = {
hide: closeIfNecessary
};
match.onAction(autocompleterApi, rng, itemValue, itemMeta);
}
);
},
columns,
ItemResponse.BUBBLE_TO_SANDBOX,
sharedBackstage
);
});
};
const onKeypress = Throttler.last((e) => {
const optMatches = e.key === ' ' ? Option.none<{ range: Range, triggerChar: string, lookupData: Promise<AutocompleteLookupData[]> }>() : lookup(editor, getAutocompleters);
optMatches.fold(
closeIfNecessary,
(lookupInfo) => {
lookupInfo.lookupData.then((lookupData) => {
const combinedItems = getCombinedItems(lookupInfo.triggerChar, lookupData);
// Only open the autocompleter if there are items to show
if (combinedItems.length > 0) {
const columns: Types.ColumnTypes = Options.findMap(lookupData, (ld) => Option.from(ld.columns)).getOr(1);
InlineView.showAt(
autocompleter,
{
anchor: 'selection',
root: Element.fromDom(editor.getBody()),
getSelection: () => {
return Option.some({
start: () => Element.fromDom(lookupInfo.range.startContainer),
soffset: () => lookupInfo.range.startOffset,
finish: () => Element.fromDom(lookupInfo.range.endContainer),
foffset: () => lookupInfo.range.endOffset
});
}
},
Menu.sketch(
createMenuFrom(
createPartialMenuWithAlloyItems('autocompleter-value', true, combinedItems, columns, 'normal'),
columns,
FocusMode.ContentFocus,
// Use the constant.
'normal'
)
)
);
InlineView.getContent(autocompleter).each(Highlighting.highlightFirst);
} else {
closeIfNecessary();
}
});
}
);
//.........這裏部分代碼省略.........
示例4: renderContextToolbar
const register = (editor: Editor, registryContextToolbars, sink, extras) => {
const contextbar = GuiFactory.build(
renderContextToolbar({
sink,
onEscape: () => {
editor.focus();
return Option.some(true);
}
})
);
const getBoxElement = () => Option.some(Element.fromDom(editor.contentAreaContainer));
editor.on('init', () => {
const scroller = editor.getBody().ownerDocument.defaultView;
// FIX: make a lot nicer.
const onScroll = DomEvent.bind(Element.fromDom(scroller), 'scroll', () => {
lastAnchor.get().each((anchor) => {
const elem = lastElement.get().getOr(editor.selection.getNode());
const nodeBounds = elem.getBoundingClientRect();
const contentAreaBounds = editor.contentAreaContainer.getBoundingClientRect();
const aboveEditor = nodeBounds.bottom < 0;
const belowEditor = nodeBounds.top > contentAreaBounds.height;
if (aboveEditor || belowEditor) {
Css.set(contextbar.element(), 'display', 'none');
} else {
Css.remove(contextbar.element(), 'display');
Positioning.positionWithin(sink, anchor, contextbar, getBoxElement());
}
});
});
editor.on('remove', () => {
onScroll.unbind();
});
});
const lastAnchor = Cell(Option.none());
const lastElement = Cell<Option<DomElement>>(Option.none<DomElement>());
const timer = Cell(null);
const wrapInPopDialog = (toolbarSpec: AlloySpec) => {
return {
dom: {
tag: 'div',
classes: ['tox-pop__dialog'],
},
components: [toolbarSpec],
behaviours: Behaviour.derive([
Keying.config({
mode: 'acyclic'
}),
AddEventsBehaviour.config('pop-dialog-wrap-events', [
AlloyEvents.runOnAttached((comp) => {
editor.shortcuts.add('ctrl+F9', 'focus statusbar', () => Keying.focusIn(comp));
}),
AlloyEvents.runOnDetached((comp) => {
editor.shortcuts.remove('ctrl+F9');
})
])
])
};
};
const getScopes: () => ScopedToolbars = Thunk.cached(() => {
return ToolbarScopes.categorise(registryContextToolbars, (toolbarApi) => {
const alloySpec = buildToolbar(toolbarApi);
AlloyTriggers.emitWith(contextbar, forwardSlideEvent, {
forwardContents: wrapInPopDialog(alloySpec)
});
});
});
const buildToolbar = (ctx): AlloySpec => {
const { buttons } = editor.ui.registry.getAll();
const scopes = getScopes();
return ctx.type === 'contexttoolbar' ? (() => {
const allButtons = Merger.merge(buttons, scopes.formNavigators);
const initGroups = identifyButtons(editor, { buttons: allButtons, toolbar: ctx.items }, extras, Option.some([ 'form:' ]));
return renderToolbar({
uid: Id.generate('context-toolbar'),
initGroups,
onEscape: Option.none,
cyclicKeying: true,
backstage: extras.backstage,
getSink: () => Result.error('')
});
})() : (() => {
return ContextForm.renderContextForm(ctx, extras.backstage);
})();
};
editor.on(showContextToolbarEvent, (e) => {
const scopes = getScopes();
// TODO: Have this stored in a better structure
Objects.readOptFrom<Toolbar.ContextToolbar | Toolbar.ContextForm>(scopes.lookupTable, e.toolbarKey).each((ctx) => {
launchContext(ctx, e.target === editor ? Option.none() : Option.some(e as DomElement));
//.........這裏部分代碼省略.........