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

hxc3-command

v0.0.6

Published

command support ie7+

Downloads

13

Readme

hxc3-command

redo undo

Install

hxc3-command

Screenshot

pic

Demo

Development:

npm install
npm run dev

open browser:

http://127.0.0.1:8080/demo1/    

原理 每次操作只记录操作的具体位置的变动, 而不是把整份数据做操作前后的备份。

例如 如果要删除表格第一行,第一列的数据, 只需要缓存住 内容变动的位置, 内容变动前后的数据。 这样撤销时,仍能根据这三个参数返回。

Usage

step1: create a new "commonCommand.js" File in your project, e.g: demo1/commonCommand.js

step2: write a pair of functions, tips: the value of editCellContent returned, will be the parameters of editCellContentRollup;

commonCommand.js:

var commonCommand = {
    /**
     * editOneCell
     * @param  {[type]} d [description]
     * @return {[type]}   [description]
     */
    editCellContent: function (d){
        var xpos = d[0];
        var ypos = d[1];
        var afterEditCon = d[2];
        var beforeEditCon = d[3];
        var data = d[4];
        var cbk = d[5];
        data[ypos][xpos] = afterEditCon;
        cbk('edit cell');
        return d;
    },
    editCellContentRollup: function (d){
        var xpos = d[0];
        var ypos = d[1];
        var afterEditCon = d[2];
        var beforeEditCon = d[3];
        var data = d[4];
        var cbk = d[5];
        data[ypos][xpos] = beforeEditCon;
        cbk('rollup edit cell');
        return d;
    }
}

step3: register a command before use, 注意 每个命令执行过以后, 传入的参数都是在缓存中的, 会一直存在直到程序退出,所以每条命令传入的参数务必控制大小。 如例子中虽然传入了data表格的全部数据,但因为数组是引用方式调用,所以该命令无论添加几次执行,缓存中还是那一个数组地址。

当然也可以在cbk回调函数再执行对data的修改

// global
const hxc3 = {};

function registerCommand() {
    var command = new MacroCommand();
    hxc3.excelCommand = command;

    ////////////////////
    // redo undo 注册一下 //
    ////////////////////
    // edit cell
    command.action("editCellContent", commonCommand.editCellContent, commonCommand.editCellContentRollup);

    // delte cell
    command.action("editCol", commonCommand.editCol, commonCommand.editColRollup);

    // bind undo btn
    document.getElementById('menubtn_undo').onclick = function () {
        command.undo();
    };
    // bind redo btn
    document.getElementById('menubtn_redo').onclick = function () {
        command.redo();
    };
}

registerCommand();

step4: 调用


// excute a command
document.getElementById('btn1').onclick = function () {
    // 数组对应的位置
    hxc3.excelCommand.do("editCellContent", [
        0,
        0,
        'data1first',
        '73.98', 
        data,
        function(msg){
            console.log(msg);
            // do something
        }
    ]);
}