<template>
<div class="app container-fluid">
<!-- undo toolbar -->
<div class="toolbar d-flex flex-wrap align-items-center gap-1">
<button id="undo" class="btn btn-primary" :disabled="!canUndo" @click="undoStack.undo()">
<span class="arrow">↶</span> Undo (ctrl+Z)
</button>
<button id="redo" class="btn btn-primary" :disabled="!canRedo" @click="undoStack.redo()">
<span class="arrow">↷</span> Redo (ctrl+Y)
</button>
<button class="btn btn-outline-secondary" disabled>
Action Count: {{ actionCount }}
</button>
<button id="clear" class="btn btn-outline-secondary" :disabled="!actionCount" @click="undoStack.clear()">
Clear Undo/Redo Stack
</button>
</div>
<!-- undoable form -->
<form id="undoable-form">
<div class="row">
<!-- HTML input elements -->
<div class="col-md-5">
<h3>HTML Input Elements</h3>
<div class="mb-3">
<label for="firstName">First Name</label>
<input id="firstName" class="form-control" placeholder="First Name" />
</div>
<div class="mb-3">
<label for="lastName">Last Name</label>
<input id="lastName" class="form-control" placeholder="Last Name" />
</div>
<div class="mb-3">
<label for="select">Select</label>
<select id="select" class="form-select">
<option value="value1">Apples</option>
<option value="value2" selected>Oranges</option>
<option value="value3">Grapes</option>
</select>
</div>
<div class="mb-3">
<label for="area">TextArea</label>
<textarea id="area" class="form-control" placeholder="textarea"></textarea>
</div>
<div class="mb-3 label-indent">
<label class="me-3">
<input type="checkbox" id="inlineCheckbox1" value="option1" checked /> Red
</label>
<label class="me-3">
<input type="checkbox" id="inlineCheckbox2" value="option2" /> Green
</label>
<label class="me-3">
<input type="checkbox" id="inlineCheckbox3" value="option3" /> Blue
</label>
</div>
<div class="mb-3 label-indent">
<label class="me-3">
<input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1" checked />
Hot
</label>
<label class="me-3">
<input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2" /> Cold
</label>
<label class="me-3">
<input type="radio" name="inlineRadioOptions" id="inlineRadio3" value="option3" /> Medium
</label>
</div>
</div>
<!-- Wijmo controls -->
<div class="col-md-7">
<h3>Wijmo Controls</h3>
<div class="mb-3">
<label for="country">Country</label>
<wj-combo-box id="country" placeholder="Country" :itemsSource="countries" :isRequired="false"
:selectedIndex="-1" />
</div>
<div class="mb-3">
<label for="amount">Amount</label>
<wj-input-number id="amount" placeholder="Amount" :format="'c2'" :min="0" :step="10"
:isRequired="false" :value="null" />
</div>
<div class="mb-3">
<label for="date">Date</label>
<wj-input-date id="date" placeholder="Date" :isRequired="false" :value="null" />
</div>
<div class="mb-3">
<label for="color" title="ComboBox">Color</label>
<wj-combo-box id="color" :itemsSource="colors" :isRequired="false" :selectedIndex="-1" />
</div>
<div class="mb-3">
<label for="ac" title="AutoComplete">Color</label>
<wj-auto-complete id="ac" :itemsSource="colors" :selectedIndex="-1" />
</div>
<div class="mb-3">
<label for="colors" title="MultiSelect">Colors</label>
<wj-multi-select id="colors" :itemsSource="colors" />
</div>
<div class="mb-3">
<label for="mac" title="MultiAutoComplete">Colors</label>
<wj-multi-auto-complete id="mac" :itemsSource="colors" :selectedIndex="-1" />
</div>
<div class="mb-3">
<label for="gauge">Gauge</label>
<wj-radial-gauge id="gauge" :thickness=".2" :min="0" :max="100" :value="50" :isReadOnly="false"
:tickSpacing="10" :showTicks="true" :showText="'Value'" :needleShape="'Outer'"
:needleLength="'Inner'" />
</div>
<div class="mb-3">
<label for="grid">Grid</label>
<wj-flex-grid div id="grid" :anchorCursor="true" :frozenColumns="2" :allowAddNew="true"
:allowDelete="true" :itemsSource="data" :initialized="initGrid" />
<div class="d-flex flex-wrap align-items-center gap-1">
<button type="button" id="add-row" class="btn btn-primary" @click="addRow($event)">
Add Row in Code
</button>
<button type="button" id="del-row" class="btn btn-primary" @click="deleteRow($event)">
Delete Row in Code
</button>
<label class="mb-0">
New Row At Top
<input id="nr-top" class="wj-no-undo" type="checkbox"
@change="grid.newRowAtTop = $event.target.checked" />
</label>
</div>
</div>
</div>
</div>
</form>
</div>
</template>
<script setup>
import "src/app.css";
import { UndoStack } from "@mescius/wijmo.undo";
import { CellRangeEventArgs } from "@mescius/wijmo.grid";
import { ref, onMounted } from "vue";
const undoStack = ref(null);
const grid = ref(null);
const data = ref(getData());
const colors = ref(getColors());
const countries = ref(getCountries());
const names = ref(getNames());
const canUndo = ref(false);
const canRedo = ref(false);
const actionCount = ref(0);
onMounted(function () // enable undo/redo for the form
{
undoStack.value = new UndoStack("#undoable-form", {
maxActions: 50,
stateChanged: (s) => {
canUndo.value = s.canUndo;
canRedo.value = s.canRedo;
actionCount.value = s.actionCount;
},
});
});
// initialize grid
function initGrid(s) {
// save reference to the grid
grid.value = s;
// add data maps to some columns
let col = s.getColumn("name");
col.dataMap = names.value;
col.dataMap.isEditable = true;
col = s.getColumn("country");
col.dataMap = countries.value;
}
// add a row in code, calling "onRowAdded" to enable undo for this action
function addRow(e) {
let g = grid.value;
g.focus();
let view = g.collectionView;
let newItem = view.addNew();
newItem.id = -1;
newItem.name = "new item";
newItem.active = true;
g.onRowAdded(new CellRangeEventArgs(g.cells, g.selection)); // create undoable action, it also commit the changes
e.preventDefault(); // don't submit the form
}
// delete a row in code, calling "onDeletingRow" to enable undo for this action
function deleteRow(e) {
let g = grid.value,
view = g.editableCollectionView;
g.focus();
if (view.items.length) {
let sel = g.selection;
if (sel.row > -1) {
let item = g.rows[sel.row].dataItem;
g.onDeletingRow(new CellRangeEventArgs(g.cells, g.selection)); // create undoable action
view.remove(item);
}
}
e.preventDefault(); // don't submit the form
}
// generate some data for the sample
function getColors() {
return "Black,Blue,Brown,Green,Magenta,Orange,Pink,Purple,Red,Teal,Violet,White,Yellow".split(",");
}
function getCountries() {
return "US,Germany,UK,Japan,Italy,Greece".split(",");
}
function getNames() {
return "Abe,Bob,Chuck,Dan,Ed,Fred".split(",");
}
function getData() {
let countries = getCountries(),
names = getNames(),
data = [];
for (let i = 0; i < 50; i++) {
data.push({
id: i,
name: names[i % names.length],
country: countries[i % countries.length],
active: i % 5 != 0,
downloads: Math.round(Math.random() * 200000),
sales: Math.round(Math.random() * 20000),
});
}
return data;
}
</script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>MESCIUS Wijmo UndoStack</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- SystemJS -->
<script src="compiler.js" type="module"></script>
<script src="https://cdn.jsdelivr.net/npm/systemjs@0.21.5/dist/system.src.js" integrity="sha512-skZbMyvYdNoZfLmiGn5ii6KmklM82rYX2uWctBhzaXPxJgiv4XBwJnFGr5k8s+6tE1pcR1nuTKghozJHyzMcoA==" crossorigin="anonymous"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('./src/app.js');
</script>
</head>
<body>
<div id="app">
</div>
</body>
</html>
(function (global) {
System.config({
transpiler: 'plugin-babel',
babelOptions: {
es2015: true,
},
meta: {
'*.css': { loader: 'css' },
'*.vue': { loader: '../plugin-vue/index.js' },
//'*.vue': { loader: 'systemjs-plugin-vue' }
},
paths: {
// paths serve as alias
'npm:': 'node_modules/',
'cdn:': 'https://cdn.mescius.io/demoapps/packages/wijmojs/5.20262.60-rc/',
'pcdn:': 'https://cdn.jsdelivr.net/npm/'
},
// map tells the System loader where to look for things
map: {
'@mescius/wijmo': 'cdn:@mescius/wijmo/index.js',
'@mescius/wijmo.input': 'cdn:@mescius/wijmo.input/index.js',
'@mescius/wijmo.styles': 'cdn:@mescius/wijmo.styles',
'@mescius/wijmo.cultures': 'cdn:@mescius/wijmo.cultures',
'@mescius/wijmo.chart': 'cdn:@mescius/wijmo.chart/index.js',
'@mescius/wijmo.chart.analytics': 'cdn:@mescius/wijmo.chart.analytics/index.js',
'@mescius/wijmo.chart.animation': 'cdn:@mescius/wijmo.chart.animation/index.js',
'@mescius/wijmo.chart.annotation': 'cdn:@mescius/wijmo.chart.annotation/index.js',
'@mescius/wijmo.chart.finance': 'cdn:@mescius/wijmo.chart.finance/index.js',
'@mescius/wijmo.chart.finance.analytics': 'cdn:@mescius/wijmo.chart.finance.analytics/index.js',
'@mescius/wijmo.chart.hierarchical': 'cdn:@mescius/wijmo.chart.hierarchical/index.js',
'@mescius/wijmo.chart.interaction': 'cdn:@mescius/wijmo.chart.interaction/index.js',
'@mescius/wijmo.chart.radar': 'cdn:@mescius/wijmo.chart.radar/index.js',
'@mescius/wijmo.chart.render': 'cdn:@mescius/wijmo.chart.render/index.js',
'@mescius/wijmo.chart.webgl': 'cdn:@mescius/wijmo.chart.webgl/index.js',
'@mescius/wijmo.chart.map': 'cdn:@mescius/wijmo.chart.map/index.js',
'@mescius/wijmo.gauge': 'cdn:@mescius/wijmo.gauge/index.js',
'@mescius/wijmo.grid': 'cdn:@mescius/wijmo.grid/index.js',
'@mescius/wijmo.grid.detail': 'cdn:@mescius/wijmo.grid.detail/index.js',
'@mescius/wijmo.grid.filter': 'cdn:@mescius/wijmo.grid.filter/index.js',
'@mescius/wijmo.grid.search': 'cdn:@mescius/wijmo.grid.search/index.js',
'@mescius/wijmo.grid.style': 'cdn:@mescius/wijmo.grid.style/index.js',
'@mescius/wijmo.grid.grouppanel': 'cdn:@mescius/wijmo.grid.grouppanel/index.js',
'@mescius/wijmo.grid.multirow': 'cdn:@mescius/wijmo.grid.multirow/index.js',
'@mescius/wijmo.grid.transposed': 'cdn:@mescius/wijmo.grid.transposed/index.js',
'@mescius/wijmo.grid.transposedmultirow': 'cdn:@mescius/wijmo.grid.transposedmultirow/index.js',
'@mescius/wijmo.grid.pdf': 'cdn:@mescius/wijmo.grid.pdf/index.js',
'@mescius/wijmo.grid.sheet': 'cdn:@mescius/wijmo.grid.sheet/index.js',
'@mescius/wijmo.grid.xlsx': 'cdn:@mescius/wijmo.grid.xlsx/index.js',
'@mescius/wijmo.grid.selector': 'cdn:@mescius/wijmo.grid.selector/index.js',
'@mescius/wijmo.grid.cellmaker': 'cdn:@mescius/wijmo.grid.cellmaker/index.js',
'@mescius/wijmo.nav': 'cdn:@mescius/wijmo.nav/index.js',
'@mescius/wijmo.odata': 'cdn:@mescius/wijmo.odata/index.js',
'@mescius/wijmo.olap': 'cdn:@mescius/wijmo.olap/index.js',
'@mescius/wijmo.rest': 'cdn:@mescius/wijmo.rest/index.js',
'@mescius/wijmo.pdf': 'cdn:@mescius/wijmo.pdf/index.js',
'@mescius/wijmo.pdf.security': 'cdn:@mescius/wijmo.pdf.security/index.js',
'@mescius/wijmo.viewer': 'cdn:@mescius/wijmo.viewer/index.js',
'@mescius/wijmo.xlsx': 'cdn:@mescius/wijmo.xlsx/index.js',
'@mescius/wijmo.undo': 'cdn:@mescius/wijmo.undo/index.js',
'@mescius/wijmo.interop.grid': 'cdn:@mescius/wijmo.interop.grid/index.js',
'@mescius/wijmo.touch': 'cdn:@mescius/wijmo.touch/index.js',
'@mescius/wijmo.cloud': 'cdn:@mescius/wijmo.cloud/index.js',
'@mescius/wijmo.barcode': 'cdn:@mescius/wijmo.barcode/index.js',
'@mescius/wijmo.barcode.common': 'cdn:@mescius/wijmo.barcode.common/index.js',
'@mescius/wijmo.barcode.composite': 'cdn:@mescius/wijmo.barcode.composite/index.js',
'@mescius/wijmo.barcode.specialized': 'cdn:@mescius/wijmo.barcode.specialized/index.js',
'@mescius/wijmo.vue2.chart.analytics': 'cdn:@mescius/wijmo.vue2.chart.analytics/index.js',
'@mescius/wijmo.vue2.chart.animation': 'cdn:@mescius/wijmo.vue2.chart.animation/index.js',
'@mescius/wijmo.vue2.chart.annotation': 'cdn:@mescius/wijmo.vue2.chart.annotation/index.js',
'@mescius/wijmo.vue2.chart.finance.analytics': 'cdn:@mescius/wijmo.vue2.chart.finance.analytics/index.js',
'@mescius/wijmo.vue2.chart.finance': 'cdn:@mescius/wijmo.vue2.chart.finance/index.js',
'@mescius/wijmo.vue2.chart.hierarchical': 'cdn:@mescius/wijmo.vue2.chart.hierarchical/index.js',
'@mescius/wijmo.vue2.chart.interaction': 'cdn:@mescius/wijmo.vue2.chart.interaction/index.js',
'@mescius/wijmo.vue2.chart.radar': 'cdn:@mescius/wijmo.vue2.chart.radar/index.js',
'@mescius/wijmo.vue2.chart.map': 'cdn:@mescius/wijmo.vue2.chart.map/index.js',
'@mescius/wijmo.vue2.chart': 'cdn:@mescius/wijmo.vue2.chart/index.js',
'@mescius/wijmo.vue2.core': 'cdn:@mescius/wijmo.vue2.core/index.js',
'@mescius/wijmo.vue2.gauge': 'cdn:@mescius/wijmo.vue2.gauge/index.js',
'@mescius/wijmo.vue2.grid.detail': 'cdn:@mescius/wijmo.vue2.grid.detail/index.js',
'@mescius/wijmo.vue2.grid.filter': 'cdn:@mescius/wijmo.vue2.grid.filter/index.js',
'@mescius/wijmo.vue2.grid.grouppanel': 'cdn:@mescius/wijmo.vue2.grid.grouppanel/index.js',
'@mescius/wijmo.vue2.grid.search': 'cdn:@mescius/wijmo.vue2.grid.search/index.js',
'@mescius/wijmo.vue2.grid.multirow': 'cdn:@mescius/wijmo.vue2.grid.multirow/index.js',
'@mescius/wijmo.vue2.grid.sheet': 'cdn:@mescius/wijmo.vue2.grid.sheet/index.js',
'@mescius/wijmo.vue2.grid.transposed': 'cdn:@mescius/wijmo.vue2.grid.transposed/index.js',
'@mescius/wijmo.vue2.grid.transposedmultirow': 'cdn:@mescius/wijmo.vue2.grid.transposedmultirow/index.js',
'@mescius/wijmo.vue2.grid': 'cdn:@mescius/wijmo.vue2.grid/index.js',
'@mescius/wijmo.vue2.input': 'cdn:@mescius/wijmo.vue2.input/index.js',
'@mescius/wijmo.vue2.olap': 'cdn:@mescius/wijmo.vue2.olap/index.js',
'@mescius/wijmo.vue2.viewer': 'cdn:@mescius/wijmo.vue2.viewer/index.js',
'@mescius/wijmo.vue2.nav': 'cdn:@mescius/wijmo.vue2.nav/index.js',
'@mescius/wijmo.vue2.base': 'cdn:@mescius/wijmo.vue2.base/index.js',
'@mescius/wijmo.vue2.barcode.common': 'cdn:@mescius/wijmo.vue2.barcode.common/index.js',
'@mescius/wijmo.vue2.barcode.composite': 'cdn:@mescius/wijmo.vue2.barcode.composite/index.js',
'@mescius/wijmo.vue2.barcode.specialized': 'cdn:@mescius/wijmo.vue2.barcode.specialized/index.js',
'bootstrap.css': 'pcdn:bootstrap@5.3.8/dist/css/bootstrap.min.css',
jszip: 'pcdn:jszip@3.8.0/dist/jszip.js',
css: 'pcdn:systemjs-plugin-css@0.1.37/css.js',
vue: 'pcdn:vue@3.4.21/dist/vue.cjs.js',
'@vue/compiler-dom': 'pcdn:@vue/compiler-dom@3.4.21/dist/compiler-dom.global.prod.js',
'@vue/runtime-dom': 'pcdn:@vue/runtime-dom@3.4.21/dist/runtime-dom.global.prod.js',
'@vue/shared': 'pcdn:@vue/shared@3.4.21/dist/shared.cjs.js',
'@vue/compiler-dom': 'pcdn:@vue/compiler-dom@3.4.21/dist/compiler-dom.global.prod.js',
'@vue/runtime-dom': 'pcdn:@vue/runtime-dom@3.4.21/dist/runtime-dom.global.prod.js',
'@vue/shared': 'pcdn:@vue/shared@3.4.21/dist/shared.cjs.js',
'@vue/compiler-dom': 'pcdn:@vue/compiler-dom@3.4.21/dist/compiler-dom.global.prod.js',
'@vue/runtime-dom': 'pcdn:@vue/runtime-dom@3.4.21/dist/runtime-dom.global.prod.js',
'@vue/shared': 'pcdn:@vue/shared@3.4.21/dist/shared.cjs.js',
'@vue/compiler-dom': 'pcdn:@vue/compiler-dom@3.4.21/dist/compiler-dom.global.prod.js',
'@vue/runtime-dom': 'pcdn:@vue/runtime-dom@3.4.21/dist/runtime-dom.global.prod.js',
'@vue/shared': 'pcdn:@vue/shared@3.4.21/dist/shared.cjs.js',
'@vue/compiler-dom': 'pcdn:@vue/compiler-dom@3.4.21/dist/compiler-dom.global.prod.js',
'@vue/runtime-dom': 'pcdn:@vue/runtime-dom@3.4.21/dist/runtime-dom.global.prod.js',
'@vue/shared': 'pcdn:@vue/shared@3.4.21/dist/shared.cjs.js',
'@vue/compiler-dom': 'pcdn:@vue/compiler-dom@3.4.21/dist/compiler-dom.global.prod.js',
'@vue/runtime-dom': 'pcdn:@vue/runtime-dom@3.4.21/dist/runtime-dom.global.prod.js',
'@vue/shared': 'pcdn:@vue/shared@3.4.21/dist/shared.cjs.js',
'@vue/compiler-dom': 'pcdn:@vue/compiler-dom@3.4.21/dist/compiler-dom.global.prod.js',
'@vue/runtime-dom': 'pcdn:@vue/runtime-dom@3.4.21/dist/runtime-dom.global.prod.js',
'@vue/shared': 'pcdn:@vue/shared@3.4.21/dist/shared.cjs.js',
'@vue/compiler-dom': 'pcdn:@vue/compiler-dom@3.4.21/dist/compiler-dom.global.prod.js',
'@vue/runtime-dom': 'pcdn:@vue/runtime-dom@3.4.21/dist/runtime-dom.global.prod.js',
'@vue/shared': 'pcdn:@vue/shared@3.4.21/dist/shared.cjs.js',
'vue-loader': 'pcdn:systemjs-vue-browser@1.0.11/index.js',
//'systemjs-plugin-vue': 'pcdn:systemjs-plugin-vue@1.2.0/index.js',
'plugin-babel': 'pcdn:systemjs-plugin-babel@0.0.25/plugin-babel.js',
'systemjs-babel-build': 'pcdn:systemjs-plugin-babel@0.0.25/systemjs-babel-browser.js',
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
src: {
defaultExtension: 'js',
},
rxjs: {
defaultExtension: 'js',
},
node_modules: {
defaultExtension: 'js',
},
wijmo: {
defaultExtension: 'js',
},
},
});
})(this);