v1.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace zin;
  3. class monaco extends wg
  4. {
  5. /**
  6. * @var mixed[]
  7. */
  8. protected static $defineProps = array(
  9. 'id: string',
  10. 'action?: string',
  11. 'options?: array',
  12. 'diffContent?: array',
  13. 'selectedLines?: string', // startLine,endLine 或者 startLine,endLine,startCol,endCol
  14. 'selectedClass?: string', // yellow-decoration: 黄色背景,wave-decoration: 红色波浪线
  15. 'lineMap?: array', // 用于设置行号的显示规则,如 array('编辑器行号' => '实际行号')
  16. 'onMouseDown?: string',
  17. 'onMouseMove?: string'
  18. );
  19. /**
  20. * @var mixed[]
  21. */
  22. protected static $defaultProps = array(
  23. 'action' => 'create',
  24. 'options' => array(),
  25. 'diffContent' => array(),
  26. 'onMouseDown' => '',
  27. 'onMouseMove' => ''
  28. );
  29. public static function getPageJS()
  30. {
  31. return file_get_contents(__DIR__ . DS . 'js' . DS . 'v1.js');
  32. }
  33. public static function getPageCSS()
  34. {
  35. return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css');
  36. }
  37. protected function build()
  38. {
  39. global $app;
  40. $vsPath = $app->getWebRoot() . 'js/monaco-editor/min/vs';
  41. $clientLang = $app->clientLang;
  42. $id = $this->prop('id');
  43. $action = $this->prop('action');
  44. $options = $this->prop('options');
  45. $diffContent = $this->prop('diffContent');
  46. $selectedLines = $this->prop('selectedLines');
  47. $selectedClass = $this->prop('selectedClass');
  48. $lineMap = $this->prop('lineMap');
  49. $onMouseDown = $this->prop('onMouseDown');
  50. $onMouseMove = $this->prop('onMouseMove');
  51. if(!$options) $options = new stdclass();
  52. return div
  53. (
  54. jsVar('id', $id),
  55. jsVar('action', $action),
  56. jsVar('options', $options),
  57. jsVar('diffContent', !$diffContent ? new stdclass() : $diffContent),
  58. jsVar('onMouseDown', $onMouseDown),
  59. jsVar('onMouseMove', $onMouseMove),
  60. jsVar('vsPath', $vsPath),
  61. jsVar('clientLang', $clientLang),
  62. jsVar('selectedLines', $selectedLines),
  63. jsVar('selectedClass', $selectedClass),
  64. jsVar('+lineMap', empty($lineMap) ? null : $lineMap),
  65. setID($id)
  66. );
  67. }
  68. }