import { createCommands } from '@jolibox/common'; import { invokeNative } from '@jolibox/native-bridge'; import { createSyncAPI, registerCanIUse, t } from './base'; export const showKeyboard = createSyncAPI('showKeyboard', { paramsSchema: t.tuple( t.object({ defaultValue: t.string().optional().default(''), multiple: t.boolean().optional().default(false), maxLength: t.unknown().optional().default(100000) }) ), implement(params) { const maxLength = Math.floor(Number(params.maxLength) ?? 100000); let { defaultValue } = params; if (defaultValue && maxLength) { defaultValue = defaultValue.slice(0, maxLength); } invokeNative('showKeyboardSync', { ...params, defaultValue, maxLength }); } }); registerCanIUse('keyboard.showKeyboard', { version: '1.0.0', properties: { params: { defaultValue: '1.0.0', multiple: '1.0.0', confirmHold: '1.0.0', confirmType: '1.0.0', maxLength: '1.0.0' } }, success: { errMsg: '1.0.0' } }); export const updateKeyboard = createSyncAPI('updateKeyboard', { paramsSchema: t.tuple( t.object({ value: t.string() }) ), implement(params) { invokeNative('updateKeyboardSync', params); } }); registerCanIUse('keyboard.updateKeyboard', { version: '1.0.0', properties: { params: { value: '1.0.0' } } }); export const hideKeyboard = createSyncAPI('hideKeyboard', { implement() { invokeNative('hideKeyboardSync'); } }); registerCanIUse('keyboard.hideKeyboard', { version: '1.0.0' }); const commands = createCommands(); commands.registerCommand('KeyboardSDK.showKeyboard', showKeyboard); commands.registerCommand('KeyboardSDK.updateKeyboard', updateKeyboard); commands.registerCommand('KeyboardSDK.hideKeyboard', hideKeyboard);