How to use @kui-shell/plugin-editor - 10 common examples

To help you get started, we’ve selected a few @kui-shell/plugin-editor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github IBM / kui / plugins / plugin-openwhisk-editor-extensions / src / lib / cmds / compose.ts View on Github external
console.error(err)
          } else {
            resolve()
          }
        })
      })

    const action = getEntity()
    debug('addWskflow action', action)
    if (action.type !== 'compositions') {
      // no need to generate wskflows if this isn't a composition
      return
    }

    if (!filepath) {
      filepath = await mktemp(extension(action.exec.kind))
    }

    const source = editor.getValue()
    await write(source)

    const ast = await generateAST(source, filepath)
    if (ast.statusCode || ast.code) {
      // some error generating the AST
      editor.clearDecorations()
      handleParseError(ast, filepath, editor)
    } else {
      if (differentASTs(action.ast, ast)) {
        action.ast = ast
        await updateView()
      }
    }
github IBM / kui / plugins / plugin-openwhisk-editor-extensions / src / preload.ts View on Github external
entity['persister'] = persisters.actions
      debug('getEntity', entity)
      return entity
    }

    const { gotoReadonlyView, fetchAction } = await import('./lib/cmds/new')

    registerFetcher(fetchAction())

    const unlock = lockIcon({
      getEntity,
      mode: 'unlock',
      label: 'Edit',
      // icon: 'fas fa-lock',
      tooltip: 'Click to edit', // TODO externalize string
      direct: edit({
        getEntity,
        lock: ({ getEntity }) => lockIcon({ getEntity, direct: gotoReadonlyView({ getEntity }) })
      })
    })

    setTimeout(async () => {
      const { addActionMode } = await import('@kui-shell/plugin-openwhisk')
      addActionMode(unlock, 'unshift')
    })
  }
}
github IBM / kui / plugins / plugin-openwhisk-editor-extensions / src / preload.ts View on Github external
if (!Capabilities.isHeadless()) {
    const { Models } = await import('@kui-shell/core/api/models')
    const { persisters } = await import('./lib/cmds/new')

    const getEntity = (tab: Tabs.Tab) => {
      const entity = Models.Selection.current(tab)
      entity['persister'] = persisters.actions
      debug('getEntity', entity)
      return entity
    }

    const { gotoReadonlyView, fetchAction } = await import('./lib/cmds/new')

    registerFetcher(fetchAction())

    const unlock = lockIcon({
      getEntity,
      mode: 'unlock',
      label: 'Edit',
      // icon: 'fas fa-lock',
      tooltip: 'Click to edit', // TODO externalize string
      direct: edit({
        getEntity,
        lock: ({ getEntity }) => lockIcon({ getEntity, direct: gotoReadonlyView({ getEntity }) })
      })
    })

    setTimeout(async () => {
      const { addActionMode } = await import('@kui-shell/plugin-openwhisk')
      addActionMode(unlock, 'unshift')
    })
  }
github IBM / kui / plugins / plugin-openwhisk-editor-extensions / src / preload.ts View on Github external
debug('initializing')

  if (!Capabilities.isHeadless()) {
    const { Models } = await import('@kui-shell/core/api/models')
    const { persisters } = await import('./lib/cmds/new')

    const getEntity = (tab: Tabs.Tab) => {
      const entity = Models.Selection.current(tab)
      entity['persister'] = persisters.actions
      debug('getEntity', entity)
      return entity
    }

    const { gotoReadonlyView, fetchAction } = await import('./lib/cmds/new')

    registerFetcher(fetchAction())

    const unlock = lockIcon({
      getEntity,
      mode: 'unlock',
      label: 'Edit',
      // icon: 'fas fa-lock',
      tooltip: 'Click to edit', // TODO externalize string
      direct: edit({
        getEntity,
        lock: ({ getEntity }) => lockIcon({ getEntity, direct: gotoReadonlyView({ getEntity }) })
      })
    })

    setTimeout(async () => {
      const { addActionMode } = await import('@kui-shell/plugin-openwhisk')
      addActionMode(unlock, 'unshift')
github IBM / kui / plugins / plugin-openwhisk-editor-extensions / src / lib / model / composition-persister.ts View on Github external
new Promise((resolve, reject) => {
      // eslint-disable-next-line @typescript-eslint/no-var-requires
      const fs = require('fs')
      // eslint-disable-next-line @typescript-eslint/no-var-requires
      const tmp = require('tmp')

      tmp.file({ prefix: 'shell-', postfix: extension(app.exec.kind) }, (err, filepath, fd, cleanup) => {
        if (err) {
          reject(err)
        } else {
          fs.write(fd, app.exec.code, async err => {
            if (err) {
              reject(err)
            } else {
              const { REPL } = await import('@kui-shell/core/api/repl')
              return REPL.pexec(
                `wsk app update ${REPL.encodeComponent(app.name)} ${REPL.encodeComponent(filepath)} --kind ${
                  app.exec.kind
                }`
              )
                .then(app => {
                  cleanup()
                  resolve(app)
github IBM / kui / plugins / plugin-openwhisk-editor-extensions / src / lib / cmds / compose.ts View on Github external
const defaultPlaceholderFn = ({ kind = 'nodejs:default', template }) => {
  if (!template) {
    // if the command didn't specify a template to start with, we
    // will use one of the built-in placeholders, based on the
    // kind of code being created
    return placeholders[language(kind)]
  } else {
    // otherwise, we will open the editor showing a template file
    return new Promise((resolve, reject) => {
      const readViaImport = () => {
        debug(
          'readViaImport',
          Util.findFile(template),
          Util.findFile(template).replace(/^.*plugin-apache-composer\/samples(.*)$/, '$1')
        )
        resolve(
          require('raw-loader!@kui-shell/plugin-apache-composer/samples' +
            Util.findFile(template).replace(/^.*plugin-apache-composer\/samples(.*)$/, '$1')).default
        )
      }

      const readViaFilesystem = () => {
github IBM / kui / plugins / plugin-openwhisk-editor-extensions / src / lib / cmds / compose.ts View on Github external
isNew: true,
        ast,
        persister
      }
    })

  //
  // otherwise, open the in-Shell editor
  // then update the editor to show the placeholder action
  // then send a response back to the repl
  //
  return betterNotExist(name, options)
    .then(() => Promise.all([makeAction(), openEditor(tab, name, options, execOptions)]))
    .then(prepareEditorWithAction)
    .then(addWskflow(tab))
    .then(respondToRepl(undefined, ['is-modified']))
}
github IBM / kui / plugins / plugin-openwhisk-editor-extensions / src / lib / cmds / new.ts View on Github external
exec: { kind, prettyKind, code },
        isNew: true,
        ast,
        persister
      }
    })

  //
  // otherwise, open the in-Shell editor
  // then update the editor to show the placeholder action
  // then send a response back to the repl
  //
  return betterNotExist(name, options)
    .then(() => Promise.all([makeAction(), openEditor(tab, name, options, execOptions)]))
    .then(prepareEditorWithAction)
    .then(respondToRepl(undefined, ['is-modified']))
}
github IBM / kui / plugins / plugin-openwhisk-editor-extensions / src / lib / cmds / new.ts View on Github external
.catch(err => {
      debug('fetchAction error', err.statusCode, err.code, err.message)
      if (tryLocal && err.code !== 406) {
        // 406 means that this is a valid action, but lacking composer source
        return fetchFile(name)
      } else {
        throw err
      }
    })
}
github IBM / kui / plugins / plugin-editor / src / lib / open.ts View on Github external
const getEntityFn = (custom && custom.getEntity) || currentSelection
  let currentEntity = getEntityFn(tab)
  const getEntity = () => currentEntity

  // for certain content types, always show folding controls, rather
  // than on mouse over (which is the default behavior for monaco)
  const entityRightNow = currentEntity
  const kind = entityRightNow && ((entityRightNow.exec && entityRightNow.exec.kind) || entityRightNow.contentType)
  if (kind === 'yaml' || kind === 'json') {
    options.showFoldingControls = 'always'
  }

  if (!pre2) {
    injectCSS({
      css: require('@kui-shell/plugin-editor/web/css/editor.css').toString(),
      key: 'editor.editor'
    })
    pre2 = true
  }

  const content = document.createElement('div')
  const editorWrapper = document.createElement('div')

  editorWrapper.className = 'monaco-editor-wrapper'
  content.appendChild(editorWrapper)

  // we want the editor to have focus, so the user can start coding
  // (but don't bother if we are in readOnly mode)
  if (!options.readOnly) {
    editorWrapper.focus()
  }