v1.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace zin;
  3. require_once dirname(__DIR__) . DS . 'textarea' . DS . 'v1.php';
  4. class pageEditor extends wg
  5. {
  6. /**
  7. * @var mixed[]
  8. */
  9. protected static $defineProps = array(
  10. 'uploadUrl?: string', // 图片上传链接
  11. 'name?: string', // 表单名称
  12. 'htmlName?: string', // HTML 内容表单名称
  13. 'placeholder?: string=""', // 占位文本
  14. 'fullscreenable?: bool=true', // 是否可全屏
  15. 'size?: string="sm"', // 尺寸,可选值 'sm', 'lg', 'full', 'auto'
  16. 'readonly?: bool=false', // 是否只读
  17. 'locale?: string', // 语言,可选值 'zh', 'en',默认跟随浏览器,也可以是自定义的语言项 JSON,详见 ZenEditor 文档
  18. 'value?: string', // 初始内容
  19. 'downloadUrl?: string', // 文件下载链接
  20. 'uid?: string' // 图片上传 uid
  21. );
  22. protected function created()
  23. {
  24. if(empty($this->prop('uid'))) $this->setProp('uid', uniqid());
  25. $this->setDefaultProps(array('uploadUrl' => createLink('file', 'ajaxUpload', 'uid=' . $this->prop('uid'))));
  26. }
  27. /**
  28. * @param string $editor
  29. * @param string $type
  30. */
  31. protected function buildTemplate($editor, $type)
  32. {
  33. global $app, $lang;
  34. $app->loadLang('user');
  35. jsVar('templateEmpty', $lang->user->tplContentNotEmpty);
  36. jsVar('confirmDeleteTemplate', $lang->user->confirmDeleteTemplate);
  37. return btnGroup
  38. (
  39. setClass('absolute right-0'),
  40. btn
  41. (
  42. setClass('ghost border-l border-r border-light'),
  43. on::click("window.showSaveModal('$editor', '$type')"),
  44. $lang->user->saveTemplate
  45. ),
  46. dropdown
  47. (
  48. btn($lang->user->applyTemplate, setClass('ghost')),
  49. set::items(array('url' => createLink('user', 'ajaxGetTemplates', "editor=$editor&type=$type")))
  50. )
  51. );
  52. }
  53. protected function build()
  54. {
  55. global $config;
  56. $value = $this->prop('value');
  57. $readonly = $this->prop('readonly');
  58. $name = $this->prop('name');
  59. $size = $this->prop('size');
  60. $zuiPath = isset($config->zuiEditorPath) ? $config->zuiEditorPath : null;
  61. $zuiPathSetting = null;
  62. if($zuiPath)
  63. {
  64. $zuiPathSetting = js
  65. (
  66. <<<JS
  67. \$.registerLib('blocksuite', {
  68. src: [
  69. '{$zuiPath}/editor.umd.cjs',
  70. '{$zuiPath}/editor.css',
  71. ],
  72. root: false,
  73. check: 'BlockSuite',
  74. });
  75. JS
  76. );
  77. }
  78. $downloadUrl = $this->prop('downloadUrl');
  79. if(is_null($downloadUrl)) $downloadUrl = createLink('file', 'ajaxQuery', 'fileID={gid}');
  80. return div
  81. (
  82. setClass('editor-container rounded relative w-full no-morph', $readonly ? 'is-readonly' : ''),
  83. $size === 'full' ? setStyle('height', '100%') : setClass('h-auto'),
  84. setCssVar('--affine-editor-side-padding', '0'),
  85. zui::pageEditor
  86. (
  87. set::_class('w-full h-full'),
  88. set::name($name),
  89. set::htmlName($this->prop('htmlName')),
  90. set::uid($this->prop('uid')),
  91. set::content($value),
  92. set::readonly($readonly),
  93. set::downloadUrl($downloadUrl),
  94. set($this->getRestProps())
  95. ),
  96. $zuiPathSetting
  97. );
  98. }
  99. }