vinaysikarwar/kria-lite 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vinaysikarwar/kria-lite

Composer 安装命令:

composer require vinaysikarwar/kria-lite

包简介

Kria Lite — tiny vanilla JS WYSIWYG editor with PHP upload example.

README 文档

README

Kria Lite logo

License Size Vanilla JS

A tiny, dependency-free WYSIWYG editor in vanilla JavaScript. Fast to load, simple to use, and easy to integrate.

  • Zero dependencies
  • Image upload with progress (via XHR or custom handler)
  • Basic sanitization built in

Feature overview

  • Core

    • Lightweight vanilla JS; no dependencies
    • Toolbar: Bold, Italic, Underline, Strike, Remove format, H1/H2/H3, Paragraph, Align Left/Center/Right, Bulleted/Numbered lists, Indent/Outdent, Link, Image, Table, Horizontal rule, Code block, Quote, Toggle Source (HTML), Fullscreen
    • Keyboard shortcuts: Cmd/Ctrl+B/I/U, Cmd/Ctrl+K (link)
    • Basic HTML sanitization
    • Image upload via uploadUrl or custom uploadHandler with progress
    • API: getHTML, setHTML, getText, insertHtml, destroy
    • Optional autosave to localStorage
  • Advanced build extras (kria.editor.widget.*)

    • Undo/Redo with custom snapshot history + toolbar buttons; shortcuts Cmd/Ctrl+Z and Shift+Cmd/Ctrl+Z
    • Mobile-friendly UI: sticky/scrollable toolbar on small screens, larger tap targets, safe-area insets
    • Font family dropdown, font size, font and background color pickers
    • Link dialog (restores selection) and Image dialog
    • Paste images from clipboard: instant blob preview, optional upload with URL replacement
    • Table dialog: choose rows and columns before insert
    • Code block insertion, Toggle source (WYSIWYG/HTML), Fullscreen mode
    • Active-state indication for toolbar buttons
    • Overridable icons via options.icons
    • Plugin hook: options.plugins: (instance) => void
    • Enhanced paste handling (prefer HTML; fallback to plain text → paragraphs)

Quick start

Include the script and enhance your <textarea>

<script src="editor.widget.js"></script>
<textarea class="wysiwyg" style="width:100%;height:300px"></textarea>
<script>
  // Use either alias:
  // KriaLite.init('.wysiwyg');
  WYSIWYG.init('.wysiwyg', {
    // Optional image upload
    uploadUrl: '/wysiwyg/upload.php',
    uploadFieldName: 'image',
    // Optional: map your API response to an URL
    parseUploadResponse: (json) => json && json.url
  });
</script>

Upload endpoint

A sample PHP upload handler is provided at upload.php. It stores images under uploads/images and returns { "url": "/wysiwyg/uploads/images/<filename>" }.

  • Adjust $publicPathPrefix if your public path differs
  • Set $maxFileSize and $allowedMime as needed
  • For auth, flip $requireAuthToken to true and implement validation

API

  • WYSIWYG.init(selectorOrNodeList, options)
  • KriaLite.init(selectorOrNodeList, options) (alias)
  • WYSIWYG.sanitizeHtml(html)

Key options (see editor.widget.js for full list):

  • height (number)
  • toolbar (array of controls)
  • sanitize (boolean)
  • uploadUrl, uploadFieldName, uploadHeaders
  • uploadHandler(file, { onProgress }) custom uploader returning { url } or string
  • onUploadProgress(percent, loaded, total, imgEl, instance)
  • parseUploadResponse(json) -> string URL

Build and minify

Requires Node.js. This repo ships with a minimal build using UglifyJS.

npm install
npm run build

Outputs:

  • Core: editor.widget.min.js, editor.widget.min.js.map
  • Advanced: kria.editor.widget.min.js, kria.editor.widget.min.js.map

Advanced build usage

<script src="kria.editor.widget.min.js"></script>
<textarea class="wysiwyg" style="width:100%;height:300px"></textarea>
<script>
  WYSIWYG.init('.wysiwyg', {
    // Optional: customize icons per control
    // icons: { undo: '<svg>...</svg>' },
    // Optional image upload
    uploadUrl: '/wysiwyg/upload.php',
    uploadFieldName: 'image',
    autosaveKey: 'post-42-draft'
  });
</script>

Publish options

  • GitHub Releases: tag versions (e.g., v0.1.0) and attach the minified build
  • npm: publish the package for easy install (npm publish)
  • Packagist: submit this repo to Packagist to expose the PHP example via Composer
  • CDN: once on npm, unpkg/jsDelivr can serve the minified file directly

Demo and social links

Try online:

GitHub topics (set): wysiwyg, editor, vanilla-js, rich-text, lightweight, javascript

Tip: Add a repo social preview image (Settings → Social preview). A screenshot of the editor or the assets/logo.svg on a gradient background works well.

Demo

The demo is a simple static page using KriaLite.init() and no upload backend. To enable uploads in your own app, configure uploadUrl as shown above.

Notes

  • Uses document.execCommand for editing for broad compatibility.
  • Blob image previews are inserted instantly; final URL replaces on upload success.
  • Minimal CSS is injected automatically; customize via overrides if needed.

License

MIT

vinaysikarwar/kria-lite 适用场景与选型建议

vinaysikarwar/kria-lite 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 vinaysikarwar/kria-lite 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 vinaysikarwar/kria-lite 我们能提供哪些服务?
定制开发 / 二次开发

基于 vinaysikarwar/kria-lite 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 23
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: JavaScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-20