occam-query 3.1.133
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/.swcrc +11 -0
- package/README.md +118 -0
- package/bin/main.js +15 -0
- package/example.js +35580 -0
- package/index.html +47 -0
- package/lib/constants.js +13 -0
- package/lib/example/utilities/token.js +28 -0
- package/lib/example/view/div/sizeable.js +39 -0
- package/lib/example/view/input/expression.js +156 -0
- package/lib/example/view/input/maximumDepth.js +156 -0
- package/lib/example/view/input.js +39 -0
- package/lib/example/view/subHeading.js +39 -0
- package/lib/example/view/textarea/content.js +155 -0
- package/lib/example/view/textarea/nodes.js +176 -0
- package/lib/example/view/textarea/parseTree.js +183 -0
- package/lib/example/view/textarea.js +39 -0
- package/lib/example/view.js +250 -0
- package/lib/example.js +19 -0
- package/lib/index.js +27 -0
- package/lib/query.js +168 -0
- package/lib/spread.js +86 -0
- package/lib/utilities/array.js +61 -0
- package/lib/utilities/query.js +79 -0
- package/license.txt +48 -0
- package/package.json +41 -0
- package/src/constants.js +3 -0
- package/src/example/utilities/token.js +21 -0
- package/src/example/view/div/sizeable.js +12 -0
- package/src/example/view/input/expression.js +35 -0
- package/src/example/view/input/maximumDepth.js +35 -0
- package/src/example/view/input.js +14 -0
- package/src/example/view/subHeading.js +16 -0
- package/src/example/view/textarea/content.js +33 -0
- package/src/example/view/textarea/nodes.js +64 -0
- package/src/example/view/textarea/parseTree.js +50 -0
- package/src/example/view/textarea.js +18 -0
- package/src/example/view.js +120 -0
- package/src/example.js +21 -0
- package/src/index.js +4 -0
- package/src/query.js +170 -0
- package/src/spread.js +65 -0
- package/src/utilities/array.js +30 -0
- package/src/utilities/query.js +52 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
default: function() {
|
|
13
|
+
return _default;
|
|
14
|
+
},
|
|
15
|
+
queryByClass: function() {
|
|
16
|
+
return queryByClass;
|
|
17
|
+
},
|
|
18
|
+
queryByClasses: function() {
|
|
19
|
+
return queryByClasses;
|
|
20
|
+
},
|
|
21
|
+
queryByExpression: function() {
|
|
22
|
+
return queryByExpression;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
var _query = /*#__PURE__*/ _interop_require_default(require("../query"));
|
|
26
|
+
function _instanceof(left, right) {
|
|
27
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
28
|
+
return !!right[Symbol.hasInstance](left);
|
|
29
|
+
} else {
|
|
30
|
+
return left instanceof right;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function _interop_require_default(obj) {
|
|
34
|
+
return obj && obj.__esModule ? obj : {
|
|
35
|
+
default: obj
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function queryByClass(node, Class) {
|
|
39
|
+
var nodes = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [];
|
|
40
|
+
if (_instanceof(node, Class)) {
|
|
41
|
+
nodes.push(node);
|
|
42
|
+
}
|
|
43
|
+
var nodeNonTerminalNode = node.isNonTerminalNode();
|
|
44
|
+
if (nodeNonTerminalNode) {
|
|
45
|
+
var childNodes = node.getChildNodes();
|
|
46
|
+
childNodes.forEach(function(childNode) {
|
|
47
|
+
return queryByClass(childNode, Class, nodes);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return nodes;
|
|
51
|
+
}
|
|
52
|
+
function queryByClasses(node, Classes) {
|
|
53
|
+
var nodes = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [];
|
|
54
|
+
Classes.some(function(Class) {
|
|
55
|
+
if (_instanceof(node, Class)) {
|
|
56
|
+
nodes.push(node);
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
var nodeNonTerminalNode = node.isNonTerminalNode();
|
|
61
|
+
if (nodeNonTerminalNode) {
|
|
62
|
+
var childNodes = node.getChildNodes();
|
|
63
|
+
childNodes.forEach(function(childNode) {
|
|
64
|
+
return queryByClasses(childNode, Classes, nodes);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return nodes;
|
|
68
|
+
}
|
|
69
|
+
function queryByExpression(node, expression, maximumDepth) {
|
|
70
|
+
var query = _query.default.fromExpression(expression, maximumDepth), nodes = query.execute(node);
|
|
71
|
+
return nodes;
|
|
72
|
+
}
|
|
73
|
+
var _default = {
|
|
74
|
+
queryByClass: queryByClass,
|
|
75
|
+
queryByClasses: queryByClasses,
|
|
76
|
+
queryByExpression: queryByExpression
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlsaXRpZXMvcXVlcnkuanMiXSwic291cmNlc0NvbnRlbnQiOlsiXCJ1c2Ugc3RyaWN0XCI7XG5cbmltcG9ydCBRdWVyeSBmcm9tIFwiLi4vcXVlcnlcIjtcblxuZXhwb3J0IGZ1bmN0aW9uIHF1ZXJ5QnlDbGFzcyhub2RlLCBDbGFzcywgbm9kZXMgPSBbXSkge1xuICBpZiAobm9kZSBpbnN0YW5jZW9mIENsYXNzKSB7XG4gICAgbm9kZXMucHVzaChub2RlKTtcbiAgfVxuXG4gIGNvbnN0IG5vZGVOb25UZXJtaW5hbE5vZGUgPSBub2RlLmlzTm9uVGVybWluYWxOb2RlKCk7XG5cbiAgaWYgKG5vZGVOb25UZXJtaW5hbE5vZGUpIHtcbiAgICBjb25zdCBjaGlsZE5vZGVzID0gbm9kZS5nZXRDaGlsZE5vZGVzKCk7XG5cbiAgICBjaGlsZE5vZGVzLmZvckVhY2goKGNoaWx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0JDLFFBQU87WUFDekJDLE1BQU1DLElBQUksQ0FBQ0g7WUFFWCxPQUFPO1FBQ1Q7SUFDRjtJQUVBLElBQU1JLHNCQUFzQkosS0FBS0ssaUJBQWlCO0lBRWxELElBQUlELHFCQUFxQjtRQUN2QixJQUFNRSxhQUFhTixLQUFLTyxhQUFhO1FBRXJDRCxXQUFXRSxPQUFPLENBQUMsU0FBQ0M7bUJBQWNYLGVBQWVXLFdBQVdDLFNBQVNSOztJQUN2RTtJQUVBLE9BQU9BO0FBQ1Q7QUFFTyxTQUFTSCxrQkFBa0JDLElBQUksRUFBRVksVUFBVSxFQUFFQyxZQUFZO0lBQzlELElBQU1DLFFBQVFDLGNBQUssQ0FBQ0MsY0FBYyxDQUFDSixZQUFZQyxlQUN6Q1gsUUFBUVksTUFBTUcsT0FBTyxDQUFDakI7SUFFNUIsT0FBT0U7QUFDVDtJQUVBLFdBQWU7SUFDYkwsY0FBQUE7SUFDQUMsZ0JBQUFBO0lBQ0FDLG1CQUFBQTtBQUNGIn0=
|
package/license.txt
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
MIT And Anti-996 Licenses
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 James Smith
|
|
4
|
+
|
|
5
|
+
These licenses shall be included in all copies or substantial portions of
|
|
6
|
+
this software and associated documentation files (the "Software").
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this Software, to deal in the Software without restriction, including
|
|
10
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
11
|
+
distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
12
|
+
persons to whom the Software is furnished to do so, subject to the following
|
|
13
|
+
conditions:
|
|
14
|
+
|
|
15
|
+
1. The individual or the legal entity must conspicuously display,
|
|
16
|
+
without modification, this License and the notice on each redistributed
|
|
17
|
+
or derivative copy of the Licensed Work.
|
|
18
|
+
|
|
19
|
+
2. The individual or the legal entity must strictly comply with all
|
|
20
|
+
applicable laws, regulations, rules and standards of the jurisdiction
|
|
21
|
+
relating to labor and employment where the individual is physically
|
|
22
|
+
located or where the individual was born or naturalized; or where the
|
|
23
|
+
legal entity is registered or is operating (whichever is stricter). In
|
|
24
|
+
case that the jurisdiction has no such laws, regulations, rules and
|
|
25
|
+
standards or its laws, regulations, rules and standards are
|
|
26
|
+
unenforceable, the individual or the legal entity are required to
|
|
27
|
+
comply with Core International Labor Standards.
|
|
28
|
+
|
|
29
|
+
3. The individual or the legal entity shall not induce, suggest or force
|
|
30
|
+
its employee(s), whether full-time or part-time, or its independent
|
|
31
|
+
contractor(s), in any methods, to agree in oral or written form, to
|
|
32
|
+
directly or indirectly restrict, weaken or relinquish his or her
|
|
33
|
+
rights or remedies under such laws, regulations, rules and standards
|
|
34
|
+
relating to labor and employment as mentioned above, no matter whether
|
|
35
|
+
such written or oral agreements are enforceable under the laws of the
|
|
36
|
+
said jurisdiction, nor shall such individual or the legal entity
|
|
37
|
+
limit, in any methods, the rights of its employee(s) or independent
|
|
38
|
+
contractor(s) from reporting or complaining to the copyright holder or
|
|
39
|
+
relevant authorities monitoring the compliance of the license about
|
|
40
|
+
its violation(s) of the said license.
|
|
41
|
+
|
|
42
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
43
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
44
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
45
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
46
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
47
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
48
|
+
SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "occam-query",
|
|
3
|
+
"author": "James Smith",
|
|
4
|
+
"version": "3.1.133",
|
|
5
|
+
"license": "MIT, Anti-996",
|
|
6
|
+
"homepage": "https://github.com/djalbat/occam-query",
|
|
7
|
+
"description": "Occam's query functionality.",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/djalbat/occam-query"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"necessary": "^13.3.1"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@swc/core": "^1.2.50",
|
|
17
|
+
"easy": "^16.0.19",
|
|
18
|
+
"easy-layout": "^6.0.121",
|
|
19
|
+
"easy-with-style": "^3.0.312",
|
|
20
|
+
"esbuild": "^0.9.2",
|
|
21
|
+
"express": "^4.17.1",
|
|
22
|
+
"juxtapose": "^4.0.80",
|
|
23
|
+
"lively-cli": "^2.0.52",
|
|
24
|
+
"watchful-cli": "^1.7.44",
|
|
25
|
+
"with-style": "^5.0.129"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"start": "node ./bin/main.js",
|
|
29
|
+
"clean": "rm -rf ./lib",
|
|
30
|
+
"watchful": "watchful -m --transpiler=swc --bundler=esbuild --source-directory=./src --lib-directory=./lib --entry-file=example.js --bundle-file=./example.js --wait=100",
|
|
31
|
+
"batch": "npm run watchful batch --",
|
|
32
|
+
"batch-debug": "npm run watchful batch -- --debug",
|
|
33
|
+
"incremental": "npm run watchful incremental --",
|
|
34
|
+
"incremental-debug": "npm run watchful incremental -- --debug",
|
|
35
|
+
"build": "npm run clean && npm run batch",
|
|
36
|
+
"build-debug": "npm run clean && npm run batch-debug",
|
|
37
|
+
"watch": "npm run clean && npm run batch && npm run incremental",
|
|
38
|
+
"watch-debug": "npm run clean && npm run batch-debug && npm run incremental-debug"
|
|
39
|
+
},
|
|
40
|
+
"main": "./lib/index.js"
|
|
41
|
+
}
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export function tokenIndexFromTerminalNodeAndTokens(terminalNode, tokens) {
|
|
4
|
+
const significantToken = terminalNode.getSignificantToken(),
|
|
5
|
+
significantTokenIndex = tokens.indexOf(significantToken),
|
|
6
|
+
tokenIndex = `(${significantTokenIndex})`;
|
|
7
|
+
|
|
8
|
+
return tokenIndex;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function tokenIndexesFromNonTerminalNodeAndTokens(nonTerminalNode, tokens) {
|
|
12
|
+
const firstSignificantToken = nonTerminalNode.getFirstSignificantToken(),
|
|
13
|
+
lastSignificantToken = nonTerminalNode.getLastSignificantToken(),
|
|
14
|
+
firstSignificantTokenIndex = tokens.indexOf(firstSignificantToken),
|
|
15
|
+
lastSignificantTokenIndex = tokens.indexOf(lastSignificantToken),
|
|
16
|
+
tokenIndexes = (firstSignificantTokenIndex !== lastSignificantTokenIndex) ?
|
|
17
|
+
`(${firstSignificantTokenIndex}-${lastSignificantTokenIndex})` :
|
|
18
|
+
`(${firstSignificantTokenIndex})`;
|
|
19
|
+
|
|
20
|
+
return tokenIndexes;
|
|
21
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Input from "../input";
|
|
4
|
+
|
|
5
|
+
export default class ExpressionInput extends Input {
|
|
6
|
+
getExpression() {
|
|
7
|
+
const value = this.getValue(),
|
|
8
|
+
expression = value; ///
|
|
9
|
+
|
|
10
|
+
return expression;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
setExpression(expression) {
|
|
14
|
+
const value = expression; ///
|
|
15
|
+
|
|
16
|
+
this.setValue(value);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
parentContext() {
|
|
20
|
+
const getExpression = this.getExpression.bind(this),
|
|
21
|
+
setExpression = this.setExpression.bind(this),
|
|
22
|
+
setExpressionReadOnly = this.setReadOnly.bind(this); ///;
|
|
23
|
+
|
|
24
|
+
return ({
|
|
25
|
+
getExpression,
|
|
26
|
+
setExpression,
|
|
27
|
+
setExpressionReadOnly
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static defaultProperties = {
|
|
32
|
+
className: "expression",
|
|
33
|
+
spellCheck: "false"
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Input from "../input";
|
|
4
|
+
|
|
5
|
+
export default class MaximumDepthInput extends Input {
|
|
6
|
+
getMaximumDepth() {
|
|
7
|
+
const value = this.getValue(),
|
|
8
|
+
maximumDepth = Number(value);
|
|
9
|
+
|
|
10
|
+
return maximumDepth;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
setMaximumDepth(maximumDepth) {
|
|
14
|
+
const value = maximumDepth; ///
|
|
15
|
+
|
|
16
|
+
this.setValue(value);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
parentContext() {
|
|
20
|
+
const getMaximumDepth = this.getMaximumDepth.bind(this),
|
|
21
|
+
setMaximumDepth = this.setMaximumDepth.bind(this),
|
|
22
|
+
setMaximumDepthReadOnly = this.setReadOnly.bind(this); ///;
|
|
23
|
+
|
|
24
|
+
return ({
|
|
25
|
+
getMaximumDepth,
|
|
26
|
+
setMaximumDepth,
|
|
27
|
+
setMaximumDepthReadOnly
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static defaultProperties = {
|
|
32
|
+
className: "maximum-depth",
|
|
33
|
+
spellCheck: "false"
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Textarea from "../textarea";
|
|
4
|
+
|
|
5
|
+
export default class ContentTextarea extends Textarea {
|
|
6
|
+
getContent() {
|
|
7
|
+
const value = this.getValue(),
|
|
8
|
+
content = value; ///
|
|
9
|
+
|
|
10
|
+
return content;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
setContent(content) {
|
|
14
|
+
const value = content;
|
|
15
|
+
|
|
16
|
+
this.setValue(value);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
parentContext() {
|
|
20
|
+
const getContent = this.getContent.bind(this),
|
|
21
|
+
setContent = this.setContent.bind(this);
|
|
22
|
+
|
|
23
|
+
return ({
|
|
24
|
+
getContent,
|
|
25
|
+
setContent
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static defaultProperties = {
|
|
30
|
+
className: "content",
|
|
31
|
+
spellCheck: "false"
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import Textarea from "../textarea";
|
|
4
|
+
|
|
5
|
+
import { EMPTY_STRING } from "../../../constants";
|
|
6
|
+
import { tokenIndexFromTerminalNodeAndTokens, tokenIndexesFromNonTerminalNodeAndTokens } from "../../utilities/token"
|
|
7
|
+
|
|
8
|
+
export default class NodesTextarea extends Textarea {
|
|
9
|
+
getNodes() {
|
|
10
|
+
const value = this.getValue(),
|
|
11
|
+
nodes = value; ///
|
|
12
|
+
|
|
13
|
+
return nodes;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
setNodes(nodes, tokens) { ///
|
|
17
|
+
const value = nodes.reduce((value, node) => {
|
|
18
|
+
const nodeTerminalNode = node.isTerminalNode();
|
|
19
|
+
|
|
20
|
+
if (nodeTerminalNode) {
|
|
21
|
+
const terminalNode = node, ///
|
|
22
|
+
significantToken = terminalNode.getSignificantToken(),
|
|
23
|
+
significantTokenType = significantToken.getType(),
|
|
24
|
+
tokenIndex = tokenIndexFromTerminalNodeAndTokens(terminalNode, tokens);
|
|
25
|
+
|
|
26
|
+
value = `${value}[${significantTokenType}]${tokenIndex}\n`;
|
|
27
|
+
} else {
|
|
28
|
+
const nonTerminalNode = node, ///
|
|
29
|
+
ruleName = nonTerminalNode.getRuleName(),
|
|
30
|
+
tokenIndexes = tokenIndexesFromNonTerminalNodeAndTokens(nonTerminalNode, tokens);
|
|
31
|
+
|
|
32
|
+
value = `${value}${ruleName}${tokenIndexes}\n`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return value;
|
|
36
|
+
}, EMPTY_STRING);
|
|
37
|
+
|
|
38
|
+
this.setValue(value);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
clearNodes() {
|
|
42
|
+
const value = EMPTY_STRING;
|
|
43
|
+
|
|
44
|
+
this.setValue(value);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
parentContext() {
|
|
48
|
+
const getNodes = this.getNodes.bind(this),
|
|
49
|
+
setNodes = this.setNodes.bind(this),
|
|
50
|
+
clearNodes = this.clearNodes.bind(this);
|
|
51
|
+
|
|
52
|
+
return ({
|
|
53
|
+
getNodes,
|
|
54
|
+
setNodes,
|
|
55
|
+
clearNodes
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static defaultProperties = {
|
|
60
|
+
className: "nodes",
|
|
61
|
+
spellCheck: "false",
|
|
62
|
+
readOnly: true
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import withStyle from "easy-with-style"; ///
|
|
4
|
+
|
|
5
|
+
import Textarea from "../textarea";
|
|
6
|
+
|
|
7
|
+
import { EMPTY_STRING } from "../../../constants";
|
|
8
|
+
|
|
9
|
+
class ParseTreeTextarea extends Textarea {
|
|
10
|
+
setParseTree(parseTree) {
|
|
11
|
+
if (parseTree !== null) {
|
|
12
|
+
parseTree.shiftLine(); //
|
|
13
|
+
|
|
14
|
+
const parseTreeString = parseTree.asString(),
|
|
15
|
+
value = parseTreeString; ///
|
|
16
|
+
|
|
17
|
+
this.setValue(value);
|
|
18
|
+
} else {
|
|
19
|
+
this.clearParseTree();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
clearParseTree() {
|
|
24
|
+
const value = EMPTY_STRING;
|
|
25
|
+
|
|
26
|
+
this.setValue(value);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
parentContext() {
|
|
30
|
+
const setParseTree = this.setParseTree.bind(this),
|
|
31
|
+
clearParseTree = this.clearParseTree.bind(this);
|
|
32
|
+
|
|
33
|
+
return ({
|
|
34
|
+
setParseTree,
|
|
35
|
+
clearParseTree
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static defaultProperties = {
|
|
40
|
+
className: "tokens",
|
|
41
|
+
spellCheck: "false",
|
|
42
|
+
readOnly: true
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default withStyle(ParseTreeTextarea)`
|
|
47
|
+
|
|
48
|
+
height: 32rem;
|
|
49
|
+
|
|
50
|
+
`;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import withStyle from "easy-with-style"; ///
|
|
4
|
+
|
|
5
|
+
import { Textarea } from "easy";
|
|
6
|
+
|
|
7
|
+
export default withStyle(Textarea)`
|
|
8
|
+
|
|
9
|
+
border: 1px solid darkgrey;
|
|
10
|
+
height: 12rem;
|
|
11
|
+
resize: vertical;
|
|
12
|
+
padding: 0.25rem;
|
|
13
|
+
font-size: 1.2rem;
|
|
14
|
+
line-height: 1.5rem;
|
|
15
|
+
white-space: pre;
|
|
16
|
+
font-family: monospace;
|
|
17
|
+
|
|
18
|
+
`;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import withStyle from "easy-with-style"; ///
|
|
4
|
+
|
|
5
|
+
import { Element } from "easy";
|
|
6
|
+
import { queryUtilities } from "../index"; ///
|
|
7
|
+
import { CSSLexer, CSSParser } from "with-style";
|
|
8
|
+
import { RowsDiv, ColumnDiv, ColumnsDiv, VerticalSplitterDiv } from "easy-layout";
|
|
9
|
+
|
|
10
|
+
import SubHeading from "./view/subHeading";
|
|
11
|
+
import SizeableDiv from "./view/div/sizeable";
|
|
12
|
+
import NodesTextarea from "./view/textarea/nodes";
|
|
13
|
+
import ExpressionInput from "./view/input/expression";
|
|
14
|
+
import ContentTextarea from "./view/textarea/content";
|
|
15
|
+
import MaximumDepthInput from "./view/input/maximumDepth";
|
|
16
|
+
import ParseTreeTextarea from "./view/textarea/parseTree";
|
|
17
|
+
|
|
18
|
+
const cssLexer = CSSLexer.fromNothing(),
|
|
19
|
+
cssParser = CSSParser.fromNothing();
|
|
20
|
+
|
|
21
|
+
const { queryByExpression } = queryUtilities;
|
|
22
|
+
|
|
23
|
+
class View extends Element {
|
|
24
|
+
keyUpHandler = (event, element) => {
|
|
25
|
+
try {
|
|
26
|
+
const content = this.getContent(),
|
|
27
|
+
tokens = cssLexer.tokenise(content),
|
|
28
|
+
node = cssParser.parse(tokens),
|
|
29
|
+
abridged = true,
|
|
30
|
+
parseTree = node.asParseTree(tokens, abridged),
|
|
31
|
+
expression = this.getExpression(),
|
|
32
|
+
maximumDepth = this.getMaximumDepth(),
|
|
33
|
+
nodes = queryByExpression(node, expression, maximumDepth);
|
|
34
|
+
|
|
35
|
+
this.setNodes(nodes, tokens); ///
|
|
36
|
+
|
|
37
|
+
this.setParseTree(parseTree);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.log(error);
|
|
40
|
+
|
|
41
|
+
this.clearNodes();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
childElements() {
|
|
46
|
+
return ([
|
|
47
|
+
|
|
48
|
+
<ColumnsDiv>
|
|
49
|
+
<SizeableDiv>
|
|
50
|
+
<RowsDiv>
|
|
51
|
+
<SubHeading>
|
|
52
|
+
Expression
|
|
53
|
+
</SubHeading>
|
|
54
|
+
<ExpressionInput onKeyUp={this.keyUpHandler} />
|
|
55
|
+
<SubHeading>
|
|
56
|
+
Maximum depth
|
|
57
|
+
</SubHeading>
|
|
58
|
+
<MaximumDepthInput onKeyUp={this.keyUpHandler} />
|
|
59
|
+
<SubHeading>
|
|
60
|
+
Nodes
|
|
61
|
+
</SubHeading>
|
|
62
|
+
<NodesTextarea />
|
|
63
|
+
</RowsDiv>
|
|
64
|
+
</SizeableDiv>
|
|
65
|
+
<VerticalSplitterDiv />
|
|
66
|
+
<ColumnDiv>
|
|
67
|
+
<RowsDiv>
|
|
68
|
+
<SubHeading>
|
|
69
|
+
Content
|
|
70
|
+
</SubHeading>
|
|
71
|
+
<ContentTextarea onKeyUp={this.keyUpHandler} />
|
|
72
|
+
<SubHeading>
|
|
73
|
+
Parse tree
|
|
74
|
+
</SubHeading>
|
|
75
|
+
<ParseTreeTextarea />
|
|
76
|
+
</RowsDiv>
|
|
77
|
+
</ColumnDiv>
|
|
78
|
+
</ColumnsDiv>
|
|
79
|
+
|
|
80
|
+
]);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
initialise() {
|
|
84
|
+
this.assignContext();
|
|
85
|
+
|
|
86
|
+
const { initialContent, initialExpression, initialMaximumDepth } = this.constructor,
|
|
87
|
+
content = initialContent, ///
|
|
88
|
+
expression = initialExpression, ///
|
|
89
|
+
maximumDepth = initialMaximumDepth; ///
|
|
90
|
+
|
|
91
|
+
this.setContent(content);
|
|
92
|
+
|
|
93
|
+
this.setExpression(expression);
|
|
94
|
+
|
|
95
|
+
this.setMaximumDepth(maximumDepth);
|
|
96
|
+
|
|
97
|
+
this.keyUpHandler(); ///
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
static initialContent = `.view {
|
|
101
|
+
background: red;
|
|
102
|
+
}
|
|
103
|
+
`;
|
|
104
|
+
|
|
105
|
+
static initialExpression = "//@special[2...4]";
|
|
106
|
+
|
|
107
|
+
static initialMaximumDepth = 5;
|
|
108
|
+
|
|
109
|
+
static tagName = "div";
|
|
110
|
+
|
|
111
|
+
static defaultProperties = {
|
|
112
|
+
className: "view"
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export default withStyle(View)`
|
|
117
|
+
|
|
118
|
+
padding: 1rem;
|
|
119
|
+
|
|
120
|
+
`;
|
package/src/example.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import "juxtapose";
|
|
4
|
+
|
|
5
|
+
import withStyle from "easy-with-style"; ///
|
|
6
|
+
|
|
7
|
+
import { Body } from "easy";
|
|
8
|
+
|
|
9
|
+
import View from "./example/view";
|
|
10
|
+
|
|
11
|
+
const { renderStyles } = withStyle;
|
|
12
|
+
|
|
13
|
+
const body = new Body();
|
|
14
|
+
|
|
15
|
+
renderStyles();
|
|
16
|
+
|
|
17
|
+
body.mount(
|
|
18
|
+
|
|
19
|
+
<View/>
|
|
20
|
+
|
|
21
|
+
);
|
package/src/index.js
ADDED