sqlite-wasm-viewer 1.0.10 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DbViewerWorker.js +1 -2
- package/dist/DbWorker.js +11 -1
- package/dist/ListVirtualizer.js +7 -0
- package/dist/QueryRunner.js +21 -24
- package/dist/bus.js +47 -0
- package/dist/dbWorkerConnector.js +63 -0
- package/dist/index.js +7 -102
- package/dist/state.js +37 -0
- package/dist/styles.css +27 -3
- package/dist/utils/resizeHandler.js +48 -0
- package/dist/viewer.js +76 -0
- package/dist/views/EditCellView/EditCellView.js +23 -17
- package/dist/views/ExecuteSQLView/ExecuteSQLView.js +6 -9
- package/dist/views/ExplorerView/ExplorerView.js +96 -24
- package/dist/views/ExplorerView/styles.css +30 -11
- package/dist/views/SqlLogView/SqlLogView.js +14 -5
- package/dist/views/TableView/TableView.js +102 -43
- package/dist/views/TableView/styles.css +6 -4
- package/package.json +2 -2
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.createSQLExecutorView = createSQLExecutorView;
|
|
7
|
+
var _QueryRunner = require("../../QueryRunner");
|
|
7
8
|
require("./styles.css");
|
|
8
9
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
9
10
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
@@ -39,19 +40,15 @@ var ExecuteSQLView = /*#__PURE__*/function () {
|
|
|
39
40
|
key: "handleExecuteSql",
|
|
40
41
|
value: function handleExecuteSql() {
|
|
41
42
|
if (this.textArea.value) {
|
|
42
|
-
|
|
43
|
-
(_this$queryRunner = this.queryRunner) === null || _this$queryRunner === void 0 ? void 0 : _this$queryRunner.runQuery({
|
|
43
|
+
_QueryRunner.queryRunner.runQuery({
|
|
44
44
|
sql: this.textArea.value,
|
|
45
45
|
parameters: []
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
}, {
|
|
50
|
-
key: "setDb",
|
|
51
|
-
value: function setDb(queryRunner) {
|
|
52
|
-
this.queryRunner = queryRunner;
|
|
53
|
-
}
|
|
54
49
|
}]);
|
|
55
50
|
return ExecuteSQLView;
|
|
56
51
|
}();
|
|
57
|
-
|
|
52
|
+
function createSQLExecutorView(rootEl) {
|
|
53
|
+
return new ExecuteSQLView(rootEl);
|
|
54
|
+
}
|
|
@@ -4,8 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.ExplorerView = void 0;
|
|
7
|
-
|
|
7
|
+
exports.createExplorerView = createExplorerView;
|
|
8
|
+
var Bus = _interopRequireWildcard(require("../../bus"));
|
|
9
|
+
var _state = require("../../state");
|
|
8
10
|
require("./styles.css");
|
|
11
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
9
13
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
10
14
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
15
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
@@ -15,12 +19,19 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _ty
|
|
|
15
19
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
16
20
|
var EXPANDED_EXPLORER_ITEMS_KEY = 'expanded_explorer_items';
|
|
17
21
|
var ExplorerView = /*#__PURE__*/function () {
|
|
18
|
-
function ExplorerView(rootEl) {
|
|
19
|
-
var
|
|
22
|
+
function ExplorerView(rootEl, viewEl) {
|
|
23
|
+
var _this = this,
|
|
24
|
+
_localStorage$getItem;
|
|
20
25
|
_classCallCheck(this, ExplorerView);
|
|
21
26
|
_defineProperty(this, "expandedItems", {});
|
|
22
27
|
_defineProperty(this, "selectedItem", null);
|
|
28
|
+
_defineProperty(this, "showFullItemLabelTimeout", 0);
|
|
29
|
+
Bus.listen('db-found', function (table) {
|
|
30
|
+
_this.addDatabaseItem(table);
|
|
31
|
+
});
|
|
23
32
|
this.dbs = [];
|
|
33
|
+
this.scheduleShowFullItemLabel = this.scheduleShowFullItemLabel.bind(this);
|
|
34
|
+
this.hideFullItemLabel = this.hideFullItemLabel.bind(this);
|
|
24
35
|
var dbListHeader = document.createElement('div');
|
|
25
36
|
dbListHeader.className = 'viewHeader';
|
|
26
37
|
dbListHeader.innerText = 'Database List';
|
|
@@ -29,6 +40,10 @@ var ExplorerView = /*#__PURE__*/function () {
|
|
|
29
40
|
this.containerEl.id = 'explorer_tree';
|
|
30
41
|
rootEl.appendChild(this.containerEl);
|
|
31
42
|
this.expandedItems = JSON.parse((_localStorage$getItem = localStorage.getItem(EXPANDED_EXPLORER_ITEMS_KEY)) !== null && _localStorage$getItem !== void 0 ? _localStorage$getItem : '{}');
|
|
43
|
+
this.fullItemLabelEl = document.createElement('div');
|
|
44
|
+
this.fullItemLabelEl.id = 'full_label';
|
|
45
|
+
this.fullItemLabelEl.style.display = 'none';
|
|
46
|
+
viewEl.appendChild(this.fullItemLabelEl);
|
|
32
47
|
}
|
|
33
48
|
_createClass(ExplorerView, [{
|
|
34
49
|
key: "addDatabaseItem",
|
|
@@ -45,26 +60,29 @@ var ExplorerView = /*#__PURE__*/function () {
|
|
|
45
60
|
}, {
|
|
46
61
|
key: "buildDom",
|
|
47
62
|
value: function buildDom() {
|
|
48
|
-
var
|
|
63
|
+
var _this2 = this;
|
|
49
64
|
this.containerEl.innerHTML = '';
|
|
50
65
|
this.dbs.forEach(function (db) {
|
|
51
|
-
|
|
66
|
+
_this2.buildDbGroupDom(db);
|
|
52
67
|
});
|
|
53
68
|
}
|
|
54
69
|
}, {
|
|
55
70
|
key: "buildDbGroupDom",
|
|
56
71
|
value: function buildDbGroupDom(db) {
|
|
57
|
-
var
|
|
72
|
+
var _this3 = this;
|
|
58
73
|
var dbRoot = document.createDocumentFragment();
|
|
59
74
|
var dbItem = document.createElement('div');
|
|
60
|
-
dbItem
|
|
61
|
-
dbItem
|
|
75
|
+
this.setupCommonItemDom(dbItem);
|
|
76
|
+
this.setupLabelDom(dbItem, db.filename);
|
|
77
|
+
dbItem.classList.add('db');
|
|
78
|
+
dbItem.addEventListener('mouseenter', this.scheduleShowFullItemLabel);
|
|
79
|
+
dbItem.addEventListener('mouseleave', this.hideFullItemLabel);
|
|
62
80
|
var tablesContainer = document.createElement('div');
|
|
63
81
|
var isExpanded = !(this.expandedItems[db.filename] === false);
|
|
64
82
|
this.buildExpandArrowDom(dbItem, tablesContainer, db, isExpanded);
|
|
65
83
|
dbRoot.appendChild(dbItem);
|
|
66
84
|
db.tables.forEach(function (table) {
|
|
67
|
-
|
|
85
|
+
_this3.buildTableDom(tablesContainer, table, db);
|
|
68
86
|
});
|
|
69
87
|
tablesContainer.style.display = isExpanded ? 'block' : 'none';
|
|
70
88
|
dbRoot.appendChild(tablesContainer);
|
|
@@ -73,42 +91,39 @@ var ExplorerView = /*#__PURE__*/function () {
|
|
|
73
91
|
}, {
|
|
74
92
|
key: "buildExpandArrowDom",
|
|
75
93
|
value: function buildExpandArrowDom(itemElem, tablesContainer, db, isExpanded) {
|
|
76
|
-
var
|
|
94
|
+
var _this4 = this;
|
|
77
95
|
var expandArrow = document.createElement('div');
|
|
78
96
|
expandArrow.className = 'expand';
|
|
79
|
-
expandArrow.
|
|
97
|
+
expandArrow.innerHTML = '▸';
|
|
80
98
|
expandArrow.style.cursor = 'pointer';
|
|
81
99
|
if (isExpanded) {
|
|
82
100
|
expandArrow.classList.add('expanded');
|
|
83
101
|
}
|
|
84
102
|
expandArrow.onclick = function () {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
// eslint-disable-next-line no-param-reassign
|
|
88
|
-
tablesContainer.style.display = _this3.expandedItems[db.filename] ? 'block' : 'none';
|
|
103
|
+
_this4.expandedItems[db.filename] = !_this4.expandedItems[db.filename];
|
|
104
|
+
tablesContainer.style.display = _this4.expandedItems[db.filename] ? 'block' : 'none';
|
|
89
105
|
expandArrow.classList.toggle('expanded');
|
|
90
|
-
localStorage.setItem(EXPANDED_EXPLORER_ITEMS_KEY, JSON.stringify(
|
|
106
|
+
localStorage.setItem(EXPANDED_EXPLORER_ITEMS_KEY, JSON.stringify(_this4.expandedItems));
|
|
91
107
|
};
|
|
92
108
|
itemElem.appendChild(expandArrow);
|
|
93
109
|
}
|
|
94
110
|
}, {
|
|
95
111
|
key: "buildTableDom",
|
|
96
112
|
value: function buildTableDom(tablesContainer, tableName, db) {
|
|
97
|
-
var
|
|
113
|
+
var _this5 = this,
|
|
98
114
|
_this$selectedItem,
|
|
99
115
|
_this$selectedItem2;
|
|
100
116
|
var tableItem = document.createElement('div');
|
|
101
|
-
tableItem
|
|
117
|
+
this.setupCommonItemDom(tableItem);
|
|
118
|
+
tableItem.classList.add('table');
|
|
102
119
|
tableItem.onclick = function () {
|
|
103
|
-
|
|
120
|
+
_this5.selectTable(tableItem, db);
|
|
104
121
|
};
|
|
105
122
|
if (((_this$selectedItem = this.selectedItem) === null || _this$selectedItem === void 0 ? void 0 : _this$selectedItem.tableName) === tableName && ((_this$selectedItem2 = this.selectedItem) === null || _this$selectedItem2 === void 0 ? void 0 : _this$selectedItem2.dbName) === db.filename) {
|
|
106
123
|
this.selectedItem.tableElem = tableItem;
|
|
107
124
|
tableItem.classList.add('selected');
|
|
108
125
|
}
|
|
109
|
-
|
|
110
|
-
tableItemInner.innerText = tableName;
|
|
111
|
-
tableItem.appendChild(tableItemInner);
|
|
126
|
+
this.setupLabelDom(tableItem, tableName);
|
|
112
127
|
tablesContainer.appendChild(tableItem);
|
|
113
128
|
}
|
|
114
129
|
}, {
|
|
@@ -125,13 +140,70 @@ var ExplorerView = /*#__PURE__*/function () {
|
|
|
125
140
|
tableElem: tableEl
|
|
126
141
|
};
|
|
127
142
|
var databasePath = databaseItem.filename;
|
|
128
|
-
|
|
143
|
+
(0, _state.selectTable)({
|
|
129
144
|
tableName: tableName,
|
|
130
145
|
databasePath: databasePath
|
|
131
146
|
});
|
|
132
147
|
}
|
|
133
148
|
}
|
|
149
|
+
}, {
|
|
150
|
+
key: "setupCommonItemDom",
|
|
151
|
+
value: function setupCommonItemDom(item) {
|
|
152
|
+
item.classList.add('item');
|
|
153
|
+
item.addEventListener('mouseenter', this.scheduleShowFullItemLabel);
|
|
154
|
+
item.addEventListener('mouseleave', this.hideFullItemLabel);
|
|
155
|
+
}
|
|
156
|
+
}, {
|
|
157
|
+
key: "setupLabelDom",
|
|
158
|
+
value: function setupLabelDom(item, text) {
|
|
159
|
+
var label = document.createElement('div');
|
|
160
|
+
label.className = 'label';
|
|
161
|
+
label.innerText = text;
|
|
162
|
+
item.appendChild(label);
|
|
163
|
+
}
|
|
164
|
+
}, {
|
|
165
|
+
key: "scheduleShowFullItemLabel",
|
|
166
|
+
value: function scheduleShowFullItemLabel(event) {
|
|
167
|
+
var _this6 = this;
|
|
168
|
+
var item = event.target;
|
|
169
|
+
var label = item.querySelector('.label');
|
|
170
|
+
if (label && label.offsetWidth < label.scrollWidth) {
|
|
171
|
+
clearTimeout(this.showFullItemLabelTimeout);
|
|
172
|
+
this.showFullItemLabelTimeout = window.setTimeout(function () {
|
|
173
|
+
_this6.showFullItemLabel(item);
|
|
174
|
+
}, 300);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}, {
|
|
178
|
+
key: "hideFullItemLabel",
|
|
179
|
+
value: function hideFullItemLabel() {
|
|
180
|
+
clearTimeout(this.showFullItemLabelTimeout);
|
|
181
|
+
this.fullItemLabelEl.style.display = 'none';
|
|
182
|
+
}
|
|
183
|
+
}, {
|
|
184
|
+
key: "showFullItemLabel",
|
|
185
|
+
value: function showFullItemLabel(item) {
|
|
186
|
+
var _item$getBoundingClie = item.getBoundingClientRect(),
|
|
187
|
+
left = _item$getBoundingClie.left,
|
|
188
|
+
top = _item$getBoundingClie.top;
|
|
189
|
+
this.fullItemLabelEl.style.display = 'block';
|
|
190
|
+
this.fullItemLabelEl.style.left = "".concat(left - 1, "px");
|
|
191
|
+
this.fullItemLabelEl.style.top = "".concat(top - 1, "px");
|
|
192
|
+
this.fullItemLabelEl.style.backgroundColor = window.getComputedStyle(item).backgroundColor;
|
|
193
|
+
var labelNode = item.querySelector('.label').childNodes[0];
|
|
194
|
+
if (labelNode.nodeType === Node.TEXT_NODE) {
|
|
195
|
+
this.fullItemLabelEl.innerText = labelNode.textContent || '';
|
|
196
|
+
}
|
|
197
|
+
}
|
|
134
198
|
}]);
|
|
135
199
|
return ExplorerView;
|
|
136
200
|
}();
|
|
137
|
-
exports.ExplorerView = ExplorerView;
|
|
201
|
+
exports.ExplorerView = ExplorerView;
|
|
202
|
+
var _explorerView;
|
|
203
|
+
function createExplorerView(rootEl, viewEl) {
|
|
204
|
+
if (!_explorerView) {
|
|
205
|
+
_explorerView = new ExplorerView(rootEl, viewEl);
|
|
206
|
+
} else {
|
|
207
|
+
console.warn('ExplorerView is already created');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -1,21 +1,36 @@
|
|
|
1
1
|
#explorer_tree {
|
|
2
2
|
padding: 8px;
|
|
3
3
|
padding-left: 20px;
|
|
4
|
-
overflow-x: clip;
|
|
5
4
|
overflow-y: auto;
|
|
6
5
|
scrollbar-gutter: stable;
|
|
7
6
|
}
|
|
8
7
|
|
|
8
|
+
#explorer_tree .item {
|
|
9
|
+
height: 20px;
|
|
10
|
+
white-space: nowrap;
|
|
11
|
+
text-overflow: ellipsis;
|
|
12
|
+
background-color: darkgray;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
#explorer_tree .item > .label {
|
|
16
|
+
padding: 2px 4px;
|
|
17
|
+
overflow: hidden;
|
|
18
|
+
text-overflow: ellipsis;
|
|
19
|
+
}
|
|
20
|
+
|
|
9
21
|
#explorer_tree > .db {
|
|
10
22
|
position: relative;
|
|
11
|
-
text-overflow: ellipsis;
|
|
12
|
-
overflow-y: clip;
|
|
13
23
|
}
|
|
14
24
|
|
|
15
25
|
#explorer_tree .expand {
|
|
16
26
|
position: absolute;
|
|
17
|
-
top:
|
|
18
|
-
left: -
|
|
27
|
+
top: 1px;
|
|
28
|
+
left: -20px;
|
|
29
|
+
width: 20px;
|
|
30
|
+
height: 20px;
|
|
31
|
+
display: flex;
|
|
32
|
+
align-items: center;
|
|
33
|
+
justify-content: center;
|
|
19
34
|
transition: all .1s ease-in;
|
|
20
35
|
}
|
|
21
36
|
|
|
@@ -25,15 +40,19 @@
|
|
|
25
40
|
|
|
26
41
|
#explorer_tree .table {
|
|
27
42
|
margin-left: 20px;
|
|
28
|
-
height: 20px;
|
|
29
43
|
cursor: pointer;
|
|
30
44
|
}
|
|
31
45
|
|
|
32
|
-
#explorer_tree .table > div {
|
|
33
|
-
text-overflow: ellipsis;
|
|
34
|
-
overflow-x: hidden;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
46
|
#explorer_tree .table.selected {
|
|
38
47
|
background-color: rgb(128, 128, 128);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
#viewer #full_label {
|
|
51
|
+
position: absolute;
|
|
52
|
+
pointer-events: none;
|
|
53
|
+
z-index: 99999;
|
|
54
|
+
border: 1px solid gray;
|
|
55
|
+
background-color: darkgray;
|
|
56
|
+
padding: 2px 4px;
|
|
57
|
+
border-radius: 2px;
|
|
39
58
|
}
|
|
@@ -3,8 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.createSqlLogView = createSqlLogView;
|
|
7
|
+
var Bus = _interopRequireWildcard(require("../../bus"));
|
|
7
8
|
require("./styles.css");
|
|
9
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
10
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
8
11
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
9
12
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
13
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
@@ -12,10 +15,16 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
12
15
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
13
16
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
14
17
|
var SqlLogView = /*#__PURE__*/function () {
|
|
15
|
-
function SqlLogView(rootEl
|
|
18
|
+
function SqlLogView(rootEl) {
|
|
16
19
|
var _this = this;
|
|
17
20
|
_classCallCheck(this, SqlLogView);
|
|
18
|
-
|
|
21
|
+
Bus.listen('query-run', function (query) {
|
|
22
|
+
if (query.errorMsg) {
|
|
23
|
+
_this.textArea.value += "Error while running previous query: ".concat(query.errorMsg, "\n");
|
|
24
|
+
} else {
|
|
25
|
+
_this.textArea.value += "".concat(query.sql, "\n");
|
|
26
|
+
}
|
|
27
|
+
});
|
|
19
28
|
var container = document.createElement('div');
|
|
20
29
|
container.id = 'sql_log_container';
|
|
21
30
|
var header = document.createElement('div');
|
|
@@ -43,6 +52,6 @@ var SqlLogView = /*#__PURE__*/function () {
|
|
|
43
52
|
}]);
|
|
44
53
|
return SqlLogView;
|
|
45
54
|
}();
|
|
46
|
-
function
|
|
47
|
-
return new SqlLogView(rootEl
|
|
55
|
+
function createSqlLogView(rootEl) {
|
|
56
|
+
return new SqlLogView(rootEl);
|
|
48
57
|
}
|
|
@@ -4,10 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.TableView = void 0;
|
|
7
|
-
|
|
7
|
+
exports.createTableView = createTableView;
|
|
8
|
+
var _state = require("../../state");
|
|
9
|
+
var Bus = _interopRequireWildcard(require("../../bus"));
|
|
8
10
|
var _ListVirtualizer = require("../../ListVirtualizer");
|
|
9
|
-
require("
|
|
11
|
+
var _QueryRunner = require("../../QueryRunner");
|
|
10
12
|
var _TableViewModel = require("./TableViewModel");
|
|
13
|
+
require("./styles.css");
|
|
14
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
11
16
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
12
17
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
18
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
@@ -16,18 +21,33 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
16
21
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
17
22
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
18
23
|
var TableView = /*#__PURE__*/function () {
|
|
19
|
-
function TableView(
|
|
24
|
+
function TableView(rootElement) {
|
|
20
25
|
var _this = this;
|
|
21
26
|
_classCallCheck(this, TableView);
|
|
22
27
|
_defineProperty(this, "updateTimer", null);
|
|
23
|
-
this.viewerElem = viewerElem;
|
|
24
28
|
this.rootElement = rootElement;
|
|
25
|
-
this.queryRunner = queryRunner;
|
|
26
29
|
this.buildDomTemplate();
|
|
27
30
|
this.model = new _TableViewModel.TableViewModel();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
Bus.listen('table-selected', function (table) {
|
|
32
|
+
_this.setTable(table.tableName);
|
|
33
|
+
});
|
|
34
|
+
Bus.listen('query-results', function (data) {
|
|
35
|
+
if ((data === null || data === void 0 ? void 0 : data.label) === 'tableViewColumns') {
|
|
36
|
+
_this.setTableColumns(data.result.resultRows || []);
|
|
37
|
+
} else if ((data === null || data === void 0 ? void 0 : data.label) === 'tableView') {
|
|
38
|
+
_this.setTableResults(data.result.resultRows || []);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
Bus.listen('cell-edited', function (_ref) {
|
|
42
|
+
var cell = _ref.cell,
|
|
43
|
+
value = _ref.value;
|
|
44
|
+
var row = _this.model.rows.find(function (r) {
|
|
45
|
+
return r.rowid === cell.cellRowId;
|
|
46
|
+
});
|
|
47
|
+
if (row) {
|
|
48
|
+
row[cell.columnName] = value;
|
|
49
|
+
_this.virtualizer.update();
|
|
50
|
+
}
|
|
31
51
|
});
|
|
32
52
|
this.virtualizer = new _ListVirtualizer.ListVirtualizer({
|
|
33
53
|
width: 500,
|
|
@@ -37,19 +57,38 @@ var TableView = /*#__PURE__*/function () {
|
|
|
37
57
|
contentRoot: this.bodyRoot,
|
|
38
58
|
container: this.container,
|
|
39
59
|
generatorFn: function generatorFn(i) {
|
|
40
|
-
var _row$rowid;
|
|
41
60
|
var row = _this.model.rows[i];
|
|
42
61
|
if (!row) {
|
|
43
62
|
return null;
|
|
44
63
|
}
|
|
45
64
|
var tr = document.createElement('tr');
|
|
46
|
-
var rowId =
|
|
65
|
+
var rowId = row.rowid;
|
|
66
|
+
tr.onclick = function (event) {
|
|
67
|
+
var _event$target;
|
|
68
|
+
var element = (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.parentElement;
|
|
69
|
+
if (element !== null && element !== void 0 && element.id) {
|
|
70
|
+
var _selectedTable;
|
|
71
|
+
var value = row[element.id];
|
|
72
|
+
(0, _state.selectCell)({
|
|
73
|
+
value: value,
|
|
74
|
+
cellRowId: rowId,
|
|
75
|
+
columnName: element.id,
|
|
76
|
+
tableName: ((_selectedTable = (0, _state.selectedTable)()) === null || _selectedTable === void 0 ? void 0 : _selectedTable.tableName) || ''
|
|
77
|
+
});
|
|
78
|
+
if (_this.model.selectedCell) {
|
|
79
|
+
_this.model.selectedCell.classList.remove('selected');
|
|
80
|
+
}
|
|
81
|
+
element.classList.add('selected');
|
|
82
|
+
_this.model.selectedCell = element;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
47
85
|
Object.keys(row).forEach(function (columnKey) {
|
|
48
86
|
if (columnKey === 'rowid') {
|
|
49
87
|
return;
|
|
50
88
|
}
|
|
51
89
|
var value = row[columnKey];
|
|
52
90
|
var td = document.createElement('td');
|
|
91
|
+
td.id = columnKey;
|
|
53
92
|
var contentEl = document.createElement('div');
|
|
54
93
|
if (value !== null) {
|
|
55
94
|
contentEl.innerHTML = value;
|
|
@@ -57,20 +96,6 @@ var TableView = /*#__PURE__*/function () {
|
|
|
57
96
|
contentEl.innerHTML = 'NULL';
|
|
58
97
|
contentEl.className = 'nullValue';
|
|
59
98
|
}
|
|
60
|
-
td.onclick = function () {
|
|
61
|
-
var _ViewerState$instance;
|
|
62
|
-
_viewerState.ViewerState.instance.setSelectedCell({
|
|
63
|
-
value: value,
|
|
64
|
-
cellRowId: rowId,
|
|
65
|
-
columnName: columnKey,
|
|
66
|
-
tableName: ((_ViewerState$instance = _viewerState.ViewerState.instance.selectedTable) === null || _ViewerState$instance === void 0 ? void 0 : _ViewerState$instance.tableName) || ''
|
|
67
|
-
});
|
|
68
|
-
if (_this.model.selectedCell) {
|
|
69
|
-
_this.model.selectedCell.classList.remove('selected');
|
|
70
|
-
}
|
|
71
|
-
td.classList.add('selected');
|
|
72
|
-
_this.model.selectedCell = td;
|
|
73
|
-
};
|
|
74
99
|
td.appendChild(contentEl);
|
|
75
100
|
tr.appendChild(td);
|
|
76
101
|
});
|
|
@@ -123,6 +148,12 @@ var TableView = /*#__PURE__*/function () {
|
|
|
123
148
|
};
|
|
124
149
|
revertBtn.setAttribute('disabled', '');
|
|
125
150
|
this.viewHeader.appendChild(revertBtn);
|
|
151
|
+
var dropTableBtn = document.createElement('button');
|
|
152
|
+
dropTableBtn.innerText = 'Delete table';
|
|
153
|
+
dropTableBtn.onclick = function () {
|
|
154
|
+
_this2.deleteTable();
|
|
155
|
+
};
|
|
156
|
+
this.viewHeader.appendChild(dropTableBtn);
|
|
126
157
|
this.rootElement.appendChild(this.viewHeader);
|
|
127
158
|
this.container = document.createElement('div');
|
|
128
159
|
this.container.id = 'table_container';
|
|
@@ -133,9 +164,8 @@ var TableView = /*#__PURE__*/function () {
|
|
|
133
164
|
this.bodyRoot = table.createTBody();
|
|
134
165
|
this.container.appendChild(table);
|
|
135
166
|
this.rootElement.appendChild(this.container);
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (hasChanges) {
|
|
167
|
+
Bus.listen('db-dirtied', function (dirty) {
|
|
168
|
+
if (dirty) {
|
|
139
169
|
saveBtn.removeAttribute('disabled');
|
|
140
170
|
revertBtn.removeAttribute('disabled');
|
|
141
171
|
} else {
|
|
@@ -158,23 +188,24 @@ var TableView = /*#__PURE__*/function () {
|
|
|
158
188
|
columnHeader.innerHTML = column;
|
|
159
189
|
var filterFieldCell = document.createElement('th');
|
|
160
190
|
filterFieldCell.className = 'columnFilterCell';
|
|
161
|
-
var
|
|
191
|
+
var filterInput = document.createElement('input');
|
|
162
192
|
if (_this3.model.fitlers[column]) {
|
|
163
|
-
|
|
193
|
+
filterInput.value = _this3.model.fitlers[column];
|
|
164
194
|
}
|
|
165
|
-
|
|
195
|
+
filterInput.onkeydown = function (event) {
|
|
166
196
|
if (event.key === 'Escape') {
|
|
167
|
-
|
|
197
|
+
filterInput.value = '';
|
|
168
198
|
_this3.model.fitlers[column] = '';
|
|
169
199
|
_this3.scheduleUpdate();
|
|
170
200
|
}
|
|
171
201
|
};
|
|
172
|
-
|
|
173
|
-
_this3.model.fitlers[column] =
|
|
202
|
+
filterInput.oninput = function () {
|
|
203
|
+
_this3.model.fitlers[column] = filterInput.value;
|
|
174
204
|
_this3.scheduleUpdate();
|
|
175
205
|
};
|
|
176
|
-
|
|
177
|
-
|
|
206
|
+
filterInput.onmouseover = function () {};
|
|
207
|
+
filterInput.placeholder = 'Filter';
|
|
208
|
+
filterFieldCell.appendChild(filterInput);
|
|
178
209
|
_this3.headerRow.appendChild(columnHeader);
|
|
179
210
|
columnHeader.appendChild(filterFieldCell);
|
|
180
211
|
});
|
|
@@ -195,12 +226,12 @@ var TableView = /*#__PURE__*/function () {
|
|
|
195
226
|
value: function requestRows(refetchColumns) {
|
|
196
227
|
if (refetchColumns) {
|
|
197
228
|
var _sql = "PRAGMA table_info(".concat(this.model.tableName, ");");
|
|
198
|
-
|
|
229
|
+
_QueryRunner.queryRunner.runQuery({
|
|
199
230
|
sql: _sql,
|
|
200
231
|
parameters: []
|
|
201
232
|
}, 'tableViewColumns');
|
|
202
233
|
}
|
|
203
|
-
var sql = "SELECT \"_rowid_\",* FROM ".concat(this.model.tableName);
|
|
234
|
+
var sql = "SELECT \"_rowid_\" as rowid,* FROM ".concat(this.model.tableName);
|
|
204
235
|
var filterSql = [];
|
|
205
236
|
Object.entries(this.model.fitlers).forEach(function (filterEntry) {
|
|
206
237
|
var column = filterEntry[0];
|
|
@@ -212,7 +243,7 @@ var TableView = /*#__PURE__*/function () {
|
|
|
212
243
|
if (filterSql.length > 0) {
|
|
213
244
|
sql += " WHERE ".concat(filterSql.join(' AND '), " ESCAPE '\\'");
|
|
214
245
|
}
|
|
215
|
-
|
|
246
|
+
_QueryRunner.queryRunner.runQuery({
|
|
216
247
|
sql: sql,
|
|
217
248
|
parameters: []
|
|
218
249
|
}, 'tableView');
|
|
@@ -221,22 +252,42 @@ var TableView = /*#__PURE__*/function () {
|
|
|
221
252
|
key: "saveChanges",
|
|
222
253
|
value: function saveChanges() {
|
|
223
254
|
var sql = 'RELEASE "RESTOREPOINT";';
|
|
224
|
-
|
|
255
|
+
_QueryRunner.queryRunner.runQuery({
|
|
225
256
|
sql: sql,
|
|
226
257
|
parameters: []
|
|
227
258
|
});
|
|
228
|
-
|
|
259
|
+
(0, _state.setDirty)(false);
|
|
229
260
|
}
|
|
230
261
|
}, {
|
|
231
262
|
key: "revertChanges",
|
|
232
263
|
value: function revertChanges() {
|
|
233
264
|
var sql = 'ROLLBACK TO SAVEPOINT "RESTOREPOINT";';
|
|
234
|
-
|
|
265
|
+
_QueryRunner.queryRunner.runQuery({
|
|
235
266
|
sql: sql,
|
|
236
267
|
parameters: []
|
|
237
268
|
});
|
|
238
269
|
this.requestRows(true);
|
|
239
|
-
|
|
270
|
+
(0, _state.setDirty)(false);
|
|
271
|
+
}
|
|
272
|
+
}, {
|
|
273
|
+
key: "deleteTable",
|
|
274
|
+
value: function deleteTable() {
|
|
275
|
+
var table = (0, _state.selectedTable)();
|
|
276
|
+
if (!table) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (!(0, _state.isDirty)()) {
|
|
280
|
+
_QueryRunner.queryRunner === null || _QueryRunner.queryRunner === void 0 ? void 0 : _QueryRunner.queryRunner.runQuery({
|
|
281
|
+
sql: 'SAVEPOINT "RESTOREPOINT"',
|
|
282
|
+
parameters: []
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
var sql = "DROP TABLE \"".concat(table.tableName, "\";");
|
|
286
|
+
_QueryRunner.queryRunner.runQuery({
|
|
287
|
+
sql: sql,
|
|
288
|
+
parameters: []
|
|
289
|
+
});
|
|
290
|
+
(0, _state.setDirty)(true);
|
|
240
291
|
}
|
|
241
292
|
}, {
|
|
242
293
|
key: "scheduleUpdate",
|
|
@@ -253,4 +304,12 @@ var TableView = /*#__PURE__*/function () {
|
|
|
253
304
|
}]);
|
|
254
305
|
return TableView;
|
|
255
306
|
}();
|
|
256
|
-
exports.TableView = TableView;
|
|
307
|
+
exports.TableView = TableView;
|
|
308
|
+
var _tableView;
|
|
309
|
+
function createTableView(rootEl) {
|
|
310
|
+
if (!_tableView) {
|
|
311
|
+
_tableView = new TableView(rootEl);
|
|
312
|
+
} else {
|
|
313
|
+
console.warn('TableView is already created');
|
|
314
|
+
}
|
|
315
|
+
}
|
|
@@ -54,6 +54,10 @@
|
|
|
54
54
|
padding-top: 5px;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
#table_container .columnFilterCell input {
|
|
58
|
+
width: calc(100% - 8px);
|
|
59
|
+
}
|
|
60
|
+
|
|
57
61
|
#table_container td, #table_container .columnHeaderCell {
|
|
58
62
|
border: 1px solid lightgray;
|
|
59
63
|
}
|
|
@@ -66,14 +70,12 @@
|
|
|
66
70
|
#table_container td div {
|
|
67
71
|
height: 40px;
|
|
68
72
|
box-sizing: border-box;
|
|
69
|
-
display: -webkit-box;
|
|
70
73
|
padding: 4px;
|
|
71
74
|
text-overflow: ellipsis;
|
|
72
75
|
overflow: hidden;
|
|
73
76
|
white-space: pre;
|
|
74
|
-
-
|
|
75
|
-
-
|
|
76
|
-
line-height: 1.2em;
|
|
77
|
+
font-size: 15px;
|
|
78
|
+
line-height: 1.1em;
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
#table_container .nullValue {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sqlite-wasm-viewer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "An SQLite OPFS database viewer that enables database inspection and SQL command execution.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -52,4 +52,4 @@
|
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"@sqlite.org/sqlite-wasm": "^3.x.x"
|
|
54
54
|
}
|
|
55
|
-
}
|
|
55
|
+
}
|