jest-bdd-generator
Version:
Jest code generator empowered with Gherkin and BDD
1,140 lines (1,137 loc) • 35 kB
JavaScript
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _async_to_generator(fn) {
return function() {
var self = this, args = arguments;
return new Promise(function(resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(void 0);
});
};
}
function _define_property(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _object_spread(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === "function") {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_define_property(target, key, source[key]);
});
}
return target;
}
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useCallback, useEffect, useReducer, useRef, useState } from "react";
import styled from "styled-components";
import * as pako from "pako";
const THEME = [
"#000",
"#dfe",
"#fe2c55",
"#FFF",
"#faffde",
"#048"
];
const LEFT_MOUSEKEY = 1;
const BACKGROUND_EDITOR = THEME[1];
const EditorWrap = styled("section")`
background: ${BACKGROUND_EDITOR};
width: 50em;
`;
const Toolbox = styled("div")`
display: flex;
color: ${THEME[5]};
button {
background: ${THEME[1]};
border: solid 1px ${THEME[5]};
border-radius: 0.2em;
margin-left: 0.5em;
font-size: 18px;
padding: 0.2em 0.7em;
}
div {
display: inline-flex;
flex-direction: column;
justify-content: center;
font-size: 12px;
input {
margin: 0;
}
}
`;
const ExpressionEditorWrap = styled("div")`
> div {
border-bottom: solid 1px ${THEME[3]};
font-size: 12px;
display: flex;
width: 100%;
flex-direction: row;
line-height: 1.6em;
> label {
flex: 1 1 0;
text-align: right;
overflow: hidden;
}
> input[type='button'] {
background: transparent;
}
> input,
> textarea {
text-indent: 0.2em;
}
> input,
> select,
> textarea {
font-size: 12px;
flex: 2 1 0;
height: 2em;
margin: 1px;
padding: 0 0.8em;
border: solid 1px ${THEME[5]};
border-radius: 0.4em;
}
> textarea {
min-height: 4em;
padding: 0.4em 0.8em;
}
> input.empty,
> select.empty,
> textarea.empty {
background: #ccc;
color: ${THEME[5]};
}
> input::placeholder,
> textarea::placeholder {
color: ${THEME[5]};
}
}
`;
const PasteReceiver = styled("div")`
padding: 5em 0;
margin: 1em;
text-align: center;
align-items: stretch;
border: dashed;
background: rgba(255, 255, 255, 0.5);
&:focus {
background: #aa6;
}
em,
i,
b {
float: left;
padding: 0 1em;
}
i {
text-decoration: line-through;
color: #a88;
}
em {
color: #888;
}
`;
const Cell = styled("span")`
text-align: right;
background: ${THEME[3]};
height: 1.5em;
`;
const RowHead = styled("label")`
transition: all 0.3s;
display: inline-flex;
min-height: 0.6em;
cursor: pointer;
justify-content: end;
> * {
flex: 1 1 10em;
border: solid 1px transparent;
transition: all 0.3s;
height: 1.5em;
}
`;
const Table = styled("article")`
font-size: 10px;
width: 100%;
position: relative;
background: ${THEME[4]};
display: flex;
align-items: end;
overflow: auto;
> aside {
overflow: visible;
color: ${THEME[5]};
display: table;
> label {
display: table-row;
> a {
display: table-cell;
white-space: nowrap;
}
}
}
> section::-webkit-scrollbar {
display: none;
}
> section {
overflow: auto;
-ms-overflow-style: none;
scrollbar-width: none;
> div {
display: table;
> div {
color: ${THEME[5]};
display: table-row;
> span {
transition: all 0.3s;
border: solid 1px transparent;
display: table-cell;
height: 1.5em;
min-width: 10em;
white-space: nowrap;
> label {
display: flex;
flex-direction: column;
> * {
flex: 0 1 1.5em;
}
}
}
}
}
}
.highlight {
background: ${THEME[1]};
color: ${THEME[0]};
span {
background: ${THEME[1]};
}
.highlight {
background: #ffa;
}
}
`;
function restoreHash(selections) {
var _window_location, _window;
if (!((_window = window) === null || _window === void 0 ? void 0 : (_window_location = _window.location) === null || _window_location === void 0 ? void 0 : _window_location.hash)) {
return [
[],
[],
""
];
}
const restoredRaw = window.location.hash.substring(1);
if (!restoredRaw) {
return [
[],
[],
""
];
}
const restoredString = pako.inflate(new Uint8Array([
...atob(restoredRaw)
].map((c) => c.charCodeAt(0))), {
to: "string"
});
const [colsRestored, rowsRestored] = restoredString ? JSON.parse(restoredString, (k, v) => {
if ((selections === null || selections === void 0 ? void 0 : selections[k]) !== void 0) {
return convertStringyValue(selections[k], v);
}
return v;
}) : [
[],
[]
];
return [
colsRestored,
rowsRestored,
restoredRaw
];
}
function _digit2(num) {
return (num + 100).toFixed().substring(1);
}
function showDate(date) {
const datetime = date instanceof Date ? date : convertStringyValue(/* @__PURE__ */ new Date(), date);
return `${datetime.getFullYear()}-${_digit2(datetime.getMonth() + 1)}-${_digit2(datetime.getDate())}T${_digit2(datetime.getHours())}:${_digit2(datetime.getMinutes())}:${_digit2(datetime.getSeconds())}`;
}
function testStringyValue(reference, rawValue) {
return convertStringyValue(reference, rawValue) === reference;
}
function convertStringyValue(reference, rawValue) {
if (Array.isArray(reference)) {
if (typeof reference[0] === "object" && !(reference[0] instanceof Date)) {
var _reference_find;
return (_reference_find = reference.find((s) => testStringyValue(s.value, rawValue))) === null || _reference_find === void 0 ? void 0 : _reference_find.value;
} else {
return reference.find((s) => testStringyValue(s, rawValue));
}
}
if (typeof reference === "number") {
if (typeof rawValue === "string") {
let val;
if (rawValue.match(/((\.)|(\de)|(^0[xb]))$/)) {
val = Number(`${rawValue}0`);
} else {
val = Number(rawValue);
}
return isNaN(val) ? void 0 : val;
} else {
return rawValue;
}
}
if (typeof reference === "boolean") {
return Boolean(rawValue);
}
if (reference instanceof Date) {
return rawValue ? new Date(rawValue) : void 0;
}
return rawValue;
}
function ExpressionInput({ name, data, selections, focused, onPaste, onChange }) {
const [expression, setExpression] = useState();
const reference = useRef(null);
const changeHandler = useCallback((evt) => {
onChange === null || onChange === void 0 ? void 0 : onChange(evt);
}, [
name,
data
]);
useEffect(() => {
const val = data[name];
if (val === "" || val === void 0) {
setExpression("");
} else {
setExpression((prev) => {
if (convertStringyValue(selections, prev) === val) {
return prev;
}
return convertStringyValue(selections, val);
});
}
}, [
data,
name,
data[name]
]);
useEffect(() => {
var _reference_current;
(_reference_current = reference.current) === null || _reference_current === void 0 ? void 0 : _reference_current.focus();
}, [
focused
]);
const loser = (e) => {
if (!data) {
return;
}
const target = e.target;
if (target.value === "") {
delete data[name];
setExpression(void 0);
} else {
const value = Array.isArray(selections) ? selections[Number(target.value)] : convertStringyValue(selections, target.value);
data[name] = value;
setExpression(value !== void 0 ? target.value : "");
}
changeHandler(e);
};
if (Array.isArray(selections)) {
return /* @__PURE__ */ _jsxs("select", {
ref: reference,
name: name.toString(),
value: selections.findIndex((s) => s === expression),
onInput: loser,
onPaste,
className: data[name] === void 0 ? "empty" : "",
children: [
/* @__PURE__ */ _jsx("option", {
value: "",
children: "-none"
}),
selections.map((str, i) => /* @__PURE__ */ _jsx("option", {
value: i,
children: str === null || str === void 0 ? void 0 : str.toString()
}, i))
]
});
} else if (name === "note") {
var _expression_toString;
return /* @__PURE__ */ _jsx("textarea", {
ref: reference,
name: name.toString(),
onInput: loser,
value: (_expression_toString = expression === null || expression === void 0 ? void 0 : expression.toString()) !== null && _expression_toString !== void 0 ? _expression_toString : "",
onPaste,
placeholder: "-none",
className: data[name] === void 0 ? "empty" : ""
});
} else if (selections instanceof Date) {
return /* @__PURE__ */ _jsx("input", {
type: "datetime-local",
ref: reference,
name: name.toString(),
autoFocus: focused,
onChange: loser,
value: expression ? showDate(expression) : void 0,
onPaste,
placeholder: "-none",
className: data[name] === void 0 ? "empty" : ""
});
} else {
var _expression_toString1;
return /* @__PURE__ */ _jsx("input", {
ref: reference,
name: name.toString(),
autoFocus: focused,
onInput: loser,
value: (_expression_toString1 = expression === null || expression === void 0 ? void 0 : expression.toString()) !== null && _expression_toString1 !== void 0 ? _expression_toString1 : "",
onPaste,
placeholder: "-none",
className: data[name] === void 0 ? "empty" : ""
});
}
}
function ExpressionEditor({ colSetting, colHead, insertBefore, deleting, insertAfter, focused, onPaste, onChange }) {
const [, refresh] = useReducer((val) => val + 1, 0);
const keys = colSetting ? Object.keys(colSetting).sort((a, b) => {
return b === "note" ? -1 : 1;
}) : [];
const testConnection = (e) => {
return onChange === null || onChange === void 0 ? void 0 : onChange(e);
};
return /* @__PURE__ */ _jsx(ExpressionEditorWrap, {
onPaste,
children: colHead ? /* @__PURE__ */ _jsxs(_Fragment, {
children: [
/* @__PURE__ */ _jsxs("div", {
children: [
/* @__PURE__ */ _jsx("input", {
type: "button",
value: "InsertBefore",
onClick: insertBefore
}),
/* @__PURE__ */ _jsx("input", {
type: "button",
value: "Delete",
onClick: deleting
}),
/* @__PURE__ */ _jsx("input", {
type: "button",
value: "InsertAfter",
onClick: insertAfter
})
]
}),
...keys.map((key, i) => {
const selections = colSetting[key];
let selectionValues = selections;
let testConnectionOnChange = testConnection;
if (Array.isArray(selections) && typeof selections[0] === "object" && !(selections[0] instanceof Date)) {
const relations = selections;
selectionValues = relations.map((relation) => {
return relation.value;
});
testConnectionOnChange = (e) => {
const val = e.target.value;
const relation = relations[parseInt(val)];
if (relation) {
Object.keys(relation).forEach((key2) => {
if (key2 !== "value") {
colHead.expression[key2] = relation[key2];
}
});
refresh();
}
return onChange === null || onChange === void 0 ? void 0 : onChange(e);
};
}
return /* @__PURE__ */ _jsxs("div", {
children: [
/* @__PURE__ */ _jsxs("label", {
children: [
key,
" : "
]
}),
/* @__PURE__ */ _jsx(ExpressionInput, {
selections: selectionValues,
onChange: testConnectionOnChange,
name: key,
data: colHead.expression,
focused: focused === key
})
]
}, i);
})
]
}) : /* @__PURE__ */ _jsx(_Fragment, {})
});
}
function Head({ colHead, onClick, isEditing, style, className, titles, getTrigger, targeted, children, onMouseMove }) {
const displayTitle = titles !== null && titles !== void 0 ? titles : Object.keys(colHead.expression);
const backgroundDefault = isEditing ? BACKGROUND_EDITOR : "";
const [background, setBackground] = useState([]);
const [, forceUpdate] = useReducer((x) => {
const currentTitles = titles !== null && titles !== void 0 ? titles : Object.keys(colHead.expression);
const bg = currentTitles.map((exp, idx) => {
if (x[idx] === colHead.expression[exp]) {
return exp === targeted ? BACKGROUND_EDITOR : backgroundDefault;
}
return "#faa";
});
setBackground(bg);
return currentTitles.map((exp) => colHead.expression[exp]);
}, displayTitle.map((exp) => colHead.expression[exp]));
const transitionEndHandler = (e) => {
const bg = displayTitle.map((exp) => exp === targeted ? BACKGROUND_EDITOR : backgroundDefault);
setBackground(bg);
};
getTrigger === null || getTrigger === void 0 ? void 0 : getTrigger(forceUpdate);
return /* @__PURE__ */ _jsxs(RowHead, {
style: _object_spread({
background: backgroundDefault
}, style),
className,
title: JSON.stringify(colHead.expression),
onMouseMove,
children: [
children,
(displayTitle.length === 0 ? [
void 0
] : displayTitle).map((exp, i) => {
const value = exp ? colHead.expression[exp] : void 0;
let display;
if (value === void 0) {
display = "-empty-";
} else if (value === Infinity) {
display = "Infinity";
} else if (typeof value === "number" && isNaN(value)) {
display = "NaN";
} else {
display = JSON.stringify(value);
}
return /* @__PURE__ */ _jsx("a", {
onClick: () => onClick(colHead, exp),
onTransitionEnd: transitionEndHandler,
style: {
background: background[i],
color: exp === "note" ? "#996" : "inherit"
},
children: display
}, i);
})
]
});
}
function TestOracle({ defaultCols, defaultRows, colSelections, execute, sort }) {
const [cols, setCols] = useState([]);
const [rows, setRows] = useState([]);
const [sortCol, setSortCol] = useState();
const [sortDirection, setSortDirection] = useState(1);
const [editingHead, setEditingHead] = useState();
let headToRefresh = editingHead;
const [editingKey, setEditingKey] = useState();
const [result, setResult] = useState();
const defaultSels = _object_spread({
note: ""
}, colSelections);
const [colSel, setColSel] = useState(defaultSels);
const [commonColProperty, setCommonColProperty] = useState();
const [pasteNote, setPasteNote] = useState();
const [highlightRow, setHighlightRow] = useState();
const [highlightCol, setHighlightCol] = useState();
const [selection, setSelection] = useState([]);
const [selecting, setSelecting] = useState(false);
const [format, setFormat] = useState("gherkin");
const triggersRows = new Array(rows.length);
const triggersCols = new Array(cols.length);
const compressed = btoa(String.fromCharCode.apply(null, pako.deflate(JSON.stringify([
cols,
rows
], (k, v) => {
if (typeof colSelections[k] === "number") {
if (v === Infinity) {
return "Infinity";
}
if (isNaN(v)) {
return "NaN";
}
return Number(v);
}
return v;
}))));
useEffect(() => {
const [colsRestored, rowsRestored] = restoreHash(colSelections);
if (rowsRestored.length) {
setRows(rowsRestored);
} else {
setRows(defaultRows.map((item) => ({
expression: item
})));
}
if (colsRestored.length) {
setCols(colsRestored);
} else {
setCols(defaultCols.map((item) => ({
expression: item
})));
}
}, [
defaultCols,
defaultRows
]);
useEffect(() => {
var _window_location, _window;
if (((_window = window) === null || _window === void 0 ? void 0 : (_window_location = _window.location) === null || _window_location === void 0 ? void 0 : _window_location.hash) !== void 0) {
window.location.hash = compressed;
}
}, [
compressed
]);
const pasteHandler = (clip) => {
const text = clip.clipboardData.getData("text/plain");
if (!text) {
return;
}
if (!editingKey) {
return;
}
const values = text.split(/\r?\n/);
const selection2 = colSel[editingKey];
if (!selection2) {
return;
}
const nodes = [];
values.forEach((val, idx) => {
var _selection_, _triggersRows_idx;
nodes[idx] = /* @__PURE__ */ _jsx("em", {
children: val
});
if (idx >= rows.length) {
rows.push({
expression: {}
});
}
nodes[idx] = /* @__PURE__ */ _jsx("i", {
children: val
});
if (!val) {
return;
}
let parsed;
if ((_selection_ = selection2[0]) === null || _selection_ === void 0 ? void 0 : _selection_.value) {
const found = selection2.find((s) => s.value === convertStringyValue(s.value, val));
parsed = found === null || found === void 0 ? void 0 : found.value;
if (found) {
Object.keys(found).forEach((k) => {
if (k !== "value") {
rows[idx].expression[k] = found[k];
}
});
}
} else {
parsed = convertStringyValue(selection2, val);
}
rows[idx].expression[editingKey] = parsed;
(_triggersRows_idx = triggersRows[idx]) === null || _triggersRows_idx === void 0 ? void 0 : _triggersRows_idx.call(triggersRows);
if (parsed !== void 0) {
nodes[idx] = /* @__PURE__ */ _jsx("b", {
children: JSON.stringify(parsed)
});
}
});
setRows(rows.slice(0, values.length));
setPasteNote(/* @__PURE__ */ _jsxs(_Fragment, {
children: [
...nodes
]
}));
};
const getEditingArray = () => {
const idxRows = rows.findIndex((h) => h === editingHead);
if (idxRows !== -1) {
return [
idxRows,
rows,
setRows
];
} else {
const idxCols = cols.findIndex((h) => h === editingHead);
if (idxCols !== -1) {
return [
idxCols,
cols,
setCols
];
}
}
throw new Error("not found");
};
const insertBefore = () => {
const [idxRows, editingArray, update] = getEditingArray();
editingArray.splice(idxRows, 0, {
expression: {}
});
update([
...editingArray
]);
};
const deleting = () => {
const [idxRows, editingArray, update] = getEditingArray();
editingArray.splice(idxRows, 1);
setEditingHead(void 0);
update([
...editingArray
]);
};
const insertAfter = () => {
const [idxRows, editingArray, update] = getEditingArray();
editingArray.splice(idxRows + 1, 0, {
expression: {}
});
update([
...editingArray
]);
};
const width = {};
const executeAll = function() {
var _ref = _async_to_generator(function* (r = rows, c = cols) {
return Promise.all(r.map(function() {
var _ref2 = _async_to_generator(function* (rowExp) {
return yield Promise.all(c.map(function() {
var _ref3 = _async_to_generator(function* (colExp) {
try {
const options = Object.assign({}, rowExp.expression, colExp.expression);
return execute(options).catch((err) => /* @__PURE__ */ _jsx("s", {
title: err.toString(),
children: "Error"
}));
} catch (err) {
var _err_message, _ref4;
return (_ref4 = (_err_message = err.message) !== null && _err_message !== void 0 ? _err_message : err === null || err === void 0 ? void 0 : err.toString()) !== null && _ref4 !== void 0 ? _ref4 : err;
}
});
return function(colExp) {
return _ref3.apply(this, arguments);
};
}()));
});
return function(rowExp) {
return _ref2.apply(this, arguments);
};
}()));
});
return function executeAll2() {
return _ref.apply(this, arguments);
};
}();
const run = function() {
var _ref = _async_to_generator(function* () {
const ret = yield executeAll(rows, cols);
setResult(ret);
});
return function run2() {
return _ref.apply(this, arguments);
};
}();
const refreshHead = () => {
if (headToRefresh) {
var _triggersRows_idxRows, _triggersCols_idxCols;
const idxCols = cols.indexOf(headToRefresh);
const idxRows = rows.indexOf(headToRefresh);
(_triggersRows_idxRows = triggersRows[idxRows]) === null || _triggersRows_idxRows === void 0 ? void 0 : _triggersRows_idxRows.call(triggersRows);
(_triggersCols_idxCols = triggersCols[idxCols]) === null || _triggersCols_idxCols === void 0 ? void 0 : _triggersCols_idxCols.call(triggersCols);
if (idxRows === -1 && idxCols === -1) {
triggersRows.forEach((r) => r === null || r === void 0 ? void 0 : r());
}
}
};
const editHandler = () => {
if ((commonColProperty === null || commonColProperty === void 0 ? void 0 : commonColProperty.expression) && editingHead === commonColProperty) {
const keys = Object.keys(commonColProperty.expression);
keys.forEach((k) => {
const key = k;
const val = commonColProperty.expression[key];
rows.forEach((rowColumn, i) => {
var _triggersRows_i;
if (rowColumn.expression[key] !== val) {
delete commonColProperty.expression[key];
rowColumn.expression[key] = val;
}
(_triggersRows_i = triggersRows[i]) === null || _triggersRows_i === void 0 ? void 0 : _triggersRows_i.call(triggersRows);
});
});
} else {
refreshHead();
}
};
const selected = (row, col) => {
return selection.findIndex((s) => s[0] === row && s[1] === col);
};
const addToSelection = (row, col) => {
selection.push([
row,
col
]);
};
const addSelectionRange = (row, col) => {
var _selection_;
let [startRow, startCol] = (_selection_ = selection[0]) !== null && _selection_ !== void 0 ? _selection_ : [
row !== null && row !== void 0 ? row : 0,
col !== null && col !== void 0 ? col : 0
];
selection.splice(1, selection.length - 2);
let endRow = row !== null && row !== void 0 ? row : rows.length - 1;
let endCol = col !== null && col !== void 0 ? col : cols.length - 1;
if (endRow < startRow) {
endRow = startRow;
startRow = row;
}
if (endCol < startCol) {
endCol = startCol;
startCol = col;
}
for (let r = startRow; r <= endRow; r++) {
for (let c = startCol; c <= endCol; c++) {
addToSelection(r, c);
}
}
};
const removeSelection = (row, col) => {
const idxOccurrence = selected(row, col);
if (idxOccurrence !== -1) {
selection.splice(idxOccurrence, 1);
}
};
const mouseMoveHandler = (e) => {
if (highlightCol === void 0 || highlightRow === void 0) {
return;
}
if (selecting && e.buttons === LEFT_MOUSEKEY) {
e.preventDefault();
addSelectionRange(highlightRow, highlightCol);
setSelection([
...selection
]);
}
};
const mouseDownHandler = (e) => {
setSelection([
[
highlightRow,
highlightCol
]
]);
e.preventDefault();
setSelecting(true);
};
const mouseUpHandler = (e) => {
setSelecting(false);
setSelection([
...selection
]);
};
const headClickHandler = (data, keyName) => {
setColSel(defaultSels);
setEditingKey(keyName !== null && keyName !== void 0 ? keyName : Object.keys(colSelections)[0]);
refreshHead();
setEditingHead(data);
headToRefresh = data;
refreshHead();
};
const headHeadClickHandler = (title) => {
const selections = colSelections[title];
const colSelection = {
[title]: selections
};
setColSel(colSelection);
setEditingKey(title);
setPasteNote(void 0);
refreshHead();
headToRefresh = {
expression: {}
};
setEditingHead(headToRefresh);
setCommonColProperty(headToRefresh);
refreshHead();
};
const headSortClickHandler = function() {
var _ref = _async_to_generator(function* (data) {
if (!sort) {
return headClickHandler(data);
}
let dir;
if (sortCol === data) {
dir = -sortDirection;
} else {
dir = 1;
}
setSortDirection(dir);
setSortCol(data);
const sorter = yield sort(data === null || data === void 0 ? void 0 : data.expression);
if (!sorter) {
return headClickHandler(data);
}
const sorted = rows.sort((a, b) => {
return dir * (sorter(a) - sorter(b));
});
setRows(sorted.map((item) => _object_spread({}, item)));
setResult([]);
});
return function headSortClickHandler2(data) {
return _ref.apply(this, arguments);
};
}();
const arrRowExpression = (r) => r.reduce((prev, { expression }) => {
const keys = Object.keys(expression);
return prev.concat(keys).filter((dup, id, arr) => arr.indexOf(dup) === id);
}, []);
const clipboard = function() {
var _ref = _async_to_generator(function* () {
const _rows = [];
const _cols = [];
if (selection.length) {
selection.forEach(([r, c]) => {
if (!_rows.includes(rows[r])) {
_rows.push(rows[r]);
}
if (!_cols.includes(cols[c])) {
_cols.push(cols[c]);
}
});
} else {
_rows.push(...rows);
_cols.push(...cols);
}
const _results = yield executeAll(_rows, _cols);
const expressions = arrRowExpression(_rows);
const headArray = [
...expressions,
..._cols.map((c, i) => Object.values(c.expression).join(";"))
];
const resultArray = _results.map((row, i) => [
...expressions.map((k) => {
var _rows_i_expression_k;
return (_rows_i_expression_k = _rows[i].expression[k]) !== null && _rows_i_expression_k !== void 0 ? _rows_i_expression_k : "";
}),
...row
]);
const resultTableFormat = [
headArray,
...resultArray
].map((row) => row.join(format === "gherkin" ? " | " : " ")).join("\n");
yield navigator.clipboard.writeText(resultTableFormat);
});
return function clipboard2() {
return _ref.apply(this, arguments);
};
}();
const highlight = (row, col) => {
setHighlightRow(row);
setHighlightCol(col);
};
return /* @__PURE__ */ _jsxs(_Fragment, {
children: [
/* @__PURE__ */ _jsxs(Toolbox, {
children: [
/* @__PURE__ */ _jsx("button", {
type: "button",
onClick: run,
children: "run"
}),
/* @__PURE__ */ _jsx("button", {
type: "button",
onClick: clipboard,
children: "copy"
}),
/* @__PURE__ */ _jsxs("div", {
children: [
/* @__PURE__ */ _jsxs("label", {
htmlFor: "rbtGherkin",
title: 'separator: "|"',
children: [
/* @__PURE__ */ _jsx("input", {
id: "rbtGherkin",
type: "radio",
value: "Gherkin",
name: "format",
checked: format === "gherkin",
onChange: () => setFormat("gherkin")
}),
"Gherkin"
]
}),
/* @__PURE__ */ _jsxs("label", {
htmlFor: "rbtXls",
title: 'separator: "\\t"',
children: [
/* @__PURE__ */ _jsx("input", {
id: "rbtXls",
type: "radio",
value: "xls",
name: "format",
checked: format === "xls",
onChange: () => setFormat("xls")
}),
"XLS"
]
})
]
})
]
}),
/* @__PURE__ */ _jsxs(Table, {
onMouseUp: mouseUpHandler,
children: [
/* @__PURE__ */ _jsxs("aside", {
children: [
/* @__PURE__ */ _jsx(RowHead, {
style: {
width: "100%",
textAlign: "center"
},
children: arrRowExpression(rows).map((title, i) => /* @__PURE__ */ _jsx("a", {
onClick: () => headHeadClickHandler(title),
style: Object.keys(colSel).length === 1 && editingKey === title ? {
background: BACKGROUND_EDITOR
} : {},
children: title.replace("formatOption", "opt")
}, i))
}),
rows.map((r, i) => /* @__PURE__ */ _jsx(Head, {
className: highlightRow === i ? "highlight" : "",
onMouseMove: () => highlight(i, -1),
titles: arrRowExpression(rows),
getTrigger: (refresh) => {
triggersRows[i] = refresh;
},
onClick: headClickHandler,
colHead: r,
isEditing: editingHead === r,
targeted: editingHead === r || Object.keys(colSel).length === 1 ? editingKey : void 0
}, i))
]
}),
/* @__PURE__ */ _jsx("section", {
children: /* @__PURE__ */ _jsxs("div", {
onMouseLeave: mouseUpHandler,
children: [
/* @__PURE__ */ _jsx("div", {
style: width,
onMouseDown: (e) => {
setSelection([]);
e.preventDefault();
},
children: cols.map((col, j) => /* @__PURE__ */ _jsx("span", {
children: /* @__PURE__ */ _jsx(Head, {
colHead: col,
className: highlightCol === j ? "highlight" : "",
getTrigger: (refresh) => {
triggersCols[j] = refresh;
},
onClick: headSortClickHandler,
onMouseMove: (e) => {
if (e.buttons === LEFT_MOUSEKEY) {
addSelectionRange(void 0, j);
setSelection([
...selection
]);
e.preventDefault();
}
},
isEditing: editingHead === col,
style: {
textAlign: "center"
},
children: /* @__PURE__ */ _jsx("i", {
children: sortCol === col ? sortDirection === 1 ? "↓" : "↑" : void 0
})
})
}, j))
}),
rows.map((r, i) => /* @__PURE__ */ _jsx("div", {
onMouseDown: mouseDownHandler,
style: width,
className: highlightRow === i ? "highlight" : "",
children: cols.map((col, j) => {
var _result_i;
var _result_i_j;
return _jsx(Cell, {
style: selected(i, j) !== -1 ? {
borderColor: `${THEME[5]} ${THEME[2]} ${THEME[2]} ${THEME[5]}`
} : {},
onMouseMove: (e) => {
highlight(i, j);
return mouseMoveHandler(e);
},
className: highlightCol === j ? "highlight" : "",
children: (_result_i_j = result === null || result === void 0 ? void 0 : (_result_i = result[i]) === null || _result_i === void 0 ? void 0 : _result_i[j]) !== null && _result_i_j !== void 0 ? _result_i_j : "--"
}, j);
})
}, i))
]
})
})
]
}),
/* @__PURE__ */ _jsxs(EditorWrap, {
children: [
/* @__PURE__ */ _jsx(ExpressionEditor, {
onPaste: pasteHandler,
colSetting: colSel,
colHead: editingHead,
focused: editingKey,
insertAfter,
deleting,
insertBefore,
onChange: editHandler
}),
commonColProperty && commonColProperty === editingHead ? /* @__PURE__ */ _jsx(PasteReceiver, {
onPaste: pasteHandler,
children: /* @__PURE__ */ _jsx("span", {
children: pasteNote || "paste multiple lines here"
})
}) : /* @__PURE__ */ _jsx(_Fragment, {})
]
})
]
});
}
export {
TestOracle,
restoreHash
};
//# sourceMappingURL=TestOracle.js.map