npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

text-template-editor

v0.0.11

Published

用途:在低代码平台中需要有编辑字符串模版,例如一个字符串部分是静态字符串,一部分是由数据库中字段的值替换,下图的例子中,我们编辑了一个字符串模版,并把这个字符串模版翻译成了最后的实际值

Downloads

2

Readme

模版编辑组件

用途:在低代码平台中需要有编辑字符串模版,例如一个字符串部分是静态字符串,一部分是由数据库中字段的值替换,下图的例子中,我们编辑了一个字符串模版,并把这个字符串模版翻译成了最后的实际值

这是一个示例图片

#安装



npm i text-template-editor

//or
yarn add text-template-editor

例子


<script setup lang="ts">

//引入组件
import TextTemplateEditor from "text-template-editor";
//引入组件样式,也可以根据class自己写
import "text-template-editor/dist/style.css";
import Mustache from "mustache";
import { ref } from "vue";
const textDict = {
  field122212312: "测试字段1",
};

const textInstanceObj = {
  field122212312: "字段实际值1",
}

const textEditorRef = ref<any>(null);
const textRef = ref("静态字符串测试+{{field122212312}}");

const translatedText = ref("");

const insertTextAtCursor = () => {
  if (!textEditorRef.value) {
    return;
  }

  textEditorRef.value.insertTextAtCursor("{{field122212312}}");
};

const doTranslate = () => {
  console.log(Mustache);

  translatedText.value = Mustache.render(textRef.value, textInstanceObj);
};
</script>

<template>
  <div class="toolbar">
    <button @click="insertTextAtCursor()">测试添加一个字段</button>
    <button @click="doTranslate">翻译</button>
  </div>

  <div class="flex-col">
    <div class="flex-item">
      <TextTemplateEditor
        ref="textEditorRef"
        :dict="textDict"
        v-model="textRef"
      />
    </div>
    <div class="flex-item">
      <div class="title">模版字符串</div>
      <div>{{ textRef }}</div>
    </div>

    <div class="flex-item">
      <div class="title">将模版翻译成实例:</div>
      <div>
        {{ translatedText }}
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.toolbar {
  button {
    margin: 10px;
    background-color: rgb(193, 218, 199);
  }
}
.flex-col {
  display: flex;
  flex-direction: column;
  min-height: 60vh;
  width: 800px;
  background-color: antiquewhite;
  .flex-item {
    flex: 1;
    // align-items: center;
    display: flex;
    // justify-content: center;
    flex-direction: column;
    .title{
      background-color: aqua;
      width: 100%;
      margin-bottom: 20px;
    }
  }
}
</style>



组件默认样式,可自行覆盖

.text-editor-chm {
  .cm-line {
    line-height: 1.7; /* 或者使用其他值,根据你的需求调整 */
  }
  .field-placeholder {
    padding: 2px 5px;
    margin: 0 2px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
  }
}