@jinntec/fore 3.3.2 → 4.0.0

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.
Files changed (73) hide show
  1. package/README.md +98 -70
  2. package/dist/fore-dev.js +5593 -6832
  3. package/dist/fore.js +5602 -4887
  4. package/index.js +5 -10
  5. package/package.json +7 -7
  6. package/resources/fore.css +33 -0
  7. package/src/DependencyNotifyingDomFacade.js +90 -21
  8. package/src/DependentXPathQueries.js +15 -2
  9. package/src/ForeElementMixin.js +110 -16
  10. package/src/UndoManager.js +267 -0
  11. package/src/actions/abstract-action.js +71 -30
  12. package/src/actions/fx-action.js +5 -0
  13. package/src/actions/fx-append.js +3 -3
  14. package/src/actions/fx-commit-history.js +26 -0
  15. package/src/actions/fx-hide.js +1 -1
  16. package/src/actions/fx-insert.js +25 -22
  17. package/src/actions/fx-load.js +5 -5
  18. package/src/actions/fx-redo.js +58 -0
  19. package/src/actions/fx-refresh.js +2 -2
  20. package/src/actions/fx-reload.js +1 -1
  21. package/src/actions/fx-replace.js +1 -1
  22. package/src/actions/fx-send.js +27 -5
  23. package/src/actions/fx-setattribute.js +11 -7
  24. package/src/actions/fx-undo.js +58 -0
  25. package/src/createNodes.js +314 -0
  26. package/src/fore.js +53 -18
  27. package/src/functions/fx-functionlib.js +10 -10
  28. package/src/fx-bind.js +30 -18
  29. package/src/fx-fore.js +222 -200
  30. package/src/fx-instance.js +18 -1
  31. package/src/fx-model.js +236 -69
  32. package/src/fx-submission.js +37 -29
  33. package/src/fx-var.js +49 -13
  34. package/src/getInScopeContext.js +1 -1
  35. package/src/json/JSONDomFacade.js +1 -1
  36. package/src/json/JSONLens.js +2 -2
  37. package/src/ui/UIElement.js +18 -8
  38. package/src/ui/abstract-control.js +45 -3
  39. package/src/ui/fx-alert.js +4 -0
  40. package/src/ui/fx-case.js +1 -1
  41. package/src/ui/fx-container.js +3 -0
  42. package/src/ui/fx-control-menu.js +79 -11
  43. package/src/ui/fx-control.js +130 -41
  44. package/src/ui/fx-dialog.js +5 -0
  45. package/src/ui/fx-items.js +6 -6
  46. package/src/ui/fx-output.js +37 -1
  47. package/src/ui/fx-repeat.js +1065 -103
  48. package/src/ui/fx-repeatitem.js +4 -1
  49. package/src/ui/fx-switch.js +116 -3
  50. package/src/ui/fx-trigger.js +9 -4
  51. package/src/ui/fx-upload.js +10 -4
  52. package/src/ui/repeat-base.js +20 -12
  53. package/src/withDraggability.js +10 -1
  54. package/src/xpath-evaluation.js +30 -18
  55. package/src/xpath-path.js +122 -0
  56. package/src/xpath-util.js +11 -126
  57. package/src/actions/StringTpl.js +0 -17
  58. package/src/extract-predicate-deps.js +0 -57
  59. package/src/extractPredicateDependencies.js +0 -36
  60. package/src/json/lensFromNode.js +0 -5
  61. package/src/json-util.js +0 -27
  62. package/src/tools/adi.js +0 -1111
  63. package/src/tools/deprecation.md +0 -1
  64. package/src/tools/fx-action-log.js +0 -745
  65. package/src/tools/fx-devtools.js +0 -444
  66. package/src/tools/fx-dom-inspector.js +0 -610
  67. package/src/tools/fx-json-instance.js +0 -444
  68. package/src/tools/fx-log-item.js +0 -128
  69. package/src/tools/fx-log-settings.js +0 -533
  70. package/src/tools/fx-minimap.js +0 -203
  71. package/src/tools/helpers.js +0 -132
  72. package/src/ui/TemplateExpression.js +0 -12
  73. package/src/ui/fx-dom-inspector.js +0 -1255
@@ -1,203 +0,0 @@
1
- class FxMinimap extends HTMLElement {
2
- constructor() {
3
- super();
4
- this.canvas = document.createElement('canvas');
5
- this.options = this.getAttribute('options') ? JSON.parse(this.getAttribute('options')) : {};
6
- this.attachShadow({ mode: 'open' });
7
- this.shadowRoot.appendChild(this.canvas);
8
- this.WIN = window;
9
- this.DOC = this.WIN.document;
10
- this.DOC_EL = this.DOC.documentElement;
11
- this.BODY = this.DOC.querySelector('body');
12
- }
13
-
14
- connectedCallback() {
15
- this.ctx = this.canvas.getContext('2d');
16
- this.black = pc => `rgba(0,0,0,${pc / 100})`;
17
- this.viewport = this.querySelector(this.getAttribute('selector'));
18
- this.settings = {
19
- viewport: this.viewport,
20
- styles: {
21
- 'header,footer,section,article': this.black(8),
22
- 'h1,a': this.black(10),
23
- 'h2,h3,h4': this.black(8),
24
- },
25
- back: this.black(2),
26
- view: this.black(5),
27
- drag: this.black(10),
28
- interval: null,
29
- ...this.options,
30
- };
31
-
32
- const _listener = (el, method, types, fn) =>
33
- types.split(/\s+/).forEach(type => el[method](type, fn));
34
- this.on = (el, types, fn) => _listener(el, 'addEventListener', types, fn);
35
- this.off = (el, types, fn) => _listener(el, 'removeEventListener', types, fn);
36
-
37
- this.Rect = (x, y, w, h) => ({
38
- x,
39
- y,
40
- w,
41
- h,
42
- });
43
-
44
- this.rect_rel_to = (rect, pos = { x: 0, y: 0 }) =>
45
- this.Rect(rect.x - pos.x, rect.y - pos.y, rect.w, rect.h);
46
-
47
- this.rect_of_doc = () =>
48
- this.Rect(0, 0, document.documentElement.scrollWidth, document.documentElement.scrollHeight);
49
-
50
- this.rect_of_win = () =>
51
- this.Rect(
52
- window.pageXOffset,
53
- window.pageYOffset,
54
- document.documentElement.clientWidth,
55
- document.documentElement.clientHeight,
56
- );
57
-
58
- this.el_get_offset = el => {
59
- const br = el.getBoundingClientRect();
60
- return { x: br.left + window.pageXOffset, y: br.top + window.pageYOffset };
61
- };
62
-
63
- this.rect_of_el = el => {
64
- const { x, y } = this.el_get_offset(el);
65
- return this.Rect(x, y, el.offsetWidth, el.offsetHeight);
66
- };
67
-
68
- this.rect_of_viewport = el => {
69
- const { x, y } = this.el_get_offset(el);
70
- return this.Rect(x + el.clientLeft, y + el.clientTop, el.clientWidth, el.clientHeight);
71
- };
72
-
73
- this.rect_of_content = el => {
74
- const { x, y } = this.el_get_offset(el);
75
- return this.Rect(
76
- x + el.clientLeft - el.scrollLeft,
77
- y + el.clientTop - el.scrollTop,
78
- el.scrollWidth,
79
- el.scrollHeight,
80
- );
81
- };
82
-
83
- this.calc_scale = (() => {
84
- const width = this.canvas.clientWidth;
85
- const height = this.canvas.clientHeight;
86
- return (w, h) => Math.min(width / w, height / h);
87
- })();
88
-
89
- this.resize_canvas = (w, h) => {
90
- this.canvas.width = w;
91
- this.canvas.height = h;
92
- this.canvas.style.width = `${w}px`;
93
- this.canvas.style.height = `${h}px`;
94
- };
95
-
96
- this.viewport = this.settings.viewport;
97
- this.find = sel => Array.from((this.viewport || document).querySelectorAll(sel));
98
-
99
- this.drag = false;
100
- this.root_rect = null;
101
- this.view_rect = null;
102
- this.scale = null;
103
- this.drag_rx = null;
104
- this.drag_ry = null;
105
- }
106
-
107
- draw_rect(rect, col) {
108
- if (col) {
109
- this.ctx.beginPath();
110
- this.ctx.rect(rect.x, rect.y, rect.w, rect.h);
111
- this.ctx.fillStyle = col;
112
- this.ctx.fill();
113
- }
114
- }
115
-
116
- find(sel) {
117
- return Array.from((this.viewport || this.DOC).querySelectorAll(sel));
118
- }
119
-
120
- apply_styles(styles) {
121
- Object.keys(styles).forEach(sel => {
122
- const col = styles[sel];
123
- this.find(sel).forEach(el => {
124
- this.draw_rect(this.rect_rel_to(this.rect_of_el(el), this.root_rect), col);
125
- });
126
- });
127
- }
128
-
129
- draw() {
130
- this.root_rect = this.viewport ? this.rect_of_content(this.viewport) : this.rect_of_doc();
131
- this.view_rect = this.viewport ? this.rect_of_viewport(this.viewport) : this.rect_of_win();
132
- this.scale = this.calc_scale(this.root_rect.w, this.root_rect.h);
133
-
134
- this.resize_canvas(this.root_rect.w * this.scale, this.root_rect.h * this.scale);
135
-
136
- this.ctx.setTransform(1, 0, 0, 1, 0, 0);
137
- this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
138
- this.ctx.scale(this.scale, this.scale);
139
-
140
- this.draw_rect(this.rect_rel_to(this.root_rect, this.root_rect), this.settings.back);
141
- this.apply_styles(this.settings.styles);
142
- this.draw_rect(
143
- this.rect_rel_to(this.view_rect, this.root_rect),
144
- this.drag ? this.settings.drag : this.settings.view,
145
- );
146
- }
147
-
148
- on_drag(ev) {
149
- ev.preventDefault();
150
- const cr = this.rect_of_viewport(this.canvas);
151
- const x = (ev.pageX - cr.x) / this.scale - this.view_rect.w * this.drag_rx;
152
- const y = (ev.pageY - cr.y) / this.scale - this.view_rect.h * this.drag_ry;
153
-
154
- if (this.viewport) {
155
- this.viewport.scrollLeft = x;
156
- this.viewport.scrollTop = y;
157
- } else {
158
- this.WIN.scrollTo(x, y);
159
- }
160
- this.draw();
161
- }
162
-
163
- on_drag_end(ev) {
164
- this.drag = false;
165
- this.canvas.style.cursor = 'pointer';
166
- this.BODY.style.cursor = 'auto';
167
- this.off(this.WIN, 'mousemove', this.on_drag);
168
- this.off(this.WIN, 'mouseup', this.on_drag_end);
169
- this.on_drag(ev);
170
- }
171
-
172
- on_drag_start(ev) {
173
- this.drag = true;
174
-
175
- const cr = this.rect_of_viewport(this.canvas);
176
- const vr = this.rect_rel_to(this.view_rect, this.root_rect);
177
- this.drag_rx = ((ev.pageX - cr.x) / this.scale - vr.x) / vr.w;
178
- this.drag_ry = ((ev.pageY - cr.y) / this.scale - vr.y) / vr.h;
179
- if (this.drag_rx < 0 || this.drag_rx > 1 || this.drag_ry < 0 || this.drag_ry > 1) {
180
- this.drag_rx = 0.5;
181
- this.drag_ry = 0.5;
182
- }
183
-
184
- this.canvas.style.cursor = 'crosshair';
185
- this.BODY.style.cursor = 'crosshair';
186
- this.on(this.WIN, 'mousemove', this.on_drag);
187
- this.on(this.WIN, 'mouseup', this.on_drag_end);
188
- this.on_drag(ev);
189
- }
190
-
191
- init() {
192
- this.canvas.style.cursor = 'pointer';
193
- this.on(this.canvas, 'mousedown', this.on_drag_start);
194
- this.on(this.viewport || this.WIN, 'load resize scroll', this.draw());
195
- if (this.settings.interval > 0) {
196
- setInterval(() => this.draw(), this.settings.interval);
197
- }
198
- this.draw();
199
- }
200
- }
201
- if (!customElements.get('fx-minimap')) {
202
- customElements.define('fx-minimap', FxMinimap);
203
- }
@@ -1,132 +0,0 @@
1
- export function addClass(element, strClass) {
2
- element.classList.add(strClass);
3
- }
4
-
5
- export function removeClass(element, strClass) {
6
- element.classList.remove(strClass);
7
- }
8
-
9
- // Checks whether the text node is not empty or contains only the EOL
10
- export function isEmptyTextNode(node) {
11
- if (typeof node !== 'object') {
12
- throw new Error(
13
- `isEmptyTextNode: Expected argument node of type object, ${typeof node} given.`,
14
- );
15
- }
16
-
17
- return /^\s*$/.test(node.textContent);
18
- }
19
-
20
- // Checks whether the node or its children contains only text information
21
- export function containsOnlyText(node, checkChildren) {
22
- if (typeof node !== 'object') {
23
- throw new Error(
24
- `containsOnlyText: Expected argument node of type object, ${typeof node} given.`,
25
- );
26
- }
27
-
28
- checkChildren = checkChildren || false;
29
-
30
- let result = false;
31
- let nodeTmp = null;
32
-
33
- // does the node contain only text nodes?
34
- if (checkChildren) {
35
- for (let i = 0, len = node.childNodes.length; i < len; i += 1) {
36
- nodeTmp = node.childNodes[i];
37
- result =
38
- nodeTmp.nodeType === Node.TEXT_NODE ||
39
- nodeTmp.nodeType === Node.COMMENT_NODE ||
40
- nodeTmp.nodeType === Node.CDATA_SECTION_NODE;
41
-
42
- if (!result) {
43
- break;
44
- }
45
- }
46
- } else {
47
- // check the node type if it doesn't have any children
48
- result =
49
- node.nodeType === Node.TEXT_NODE ||
50
- node.nodeType === Node.COMMENT_NODE ||
51
- node.nodeType === Node.CDATA_SECTION_NODE;
52
- }
53
-
54
- return result;
55
- }
56
-
57
- // Create element wrapper -- allows to set attributes using the config object.
58
- export function newElement(elem, attrs) {
59
- const el = document.createElement(elem);
60
-
61
- attrs = attrs || {};
62
- for (const attr of Object.keys(attrs)) {
63
- el.setAttribute(attr, attrs[attr]);
64
- }
65
-
66
- return el;
67
- }
68
-
69
- // Helper function for options view
70
- export function drawOptionRow(optionCode, optionText) {
71
- const row = newElement('span', { class: 'adi-opt' });
72
- row.innerHTML = `<label><input type="checkbox" data-opt="${optionCode}">${optionText}</label>`;
73
-
74
- return row;
75
- }
76
-
77
- // Renders the options panel
78
- export function drawOptions() {
79
- const ui = newElement('div', { id: 'adi-opts-view', class: 'adi-hidden' });
80
- const head1 = newElement('span', { class: 'adi-opt-heading' });
81
- const head2 = newElement('span', { class: 'adi-opt-heading' });
82
- const close = newElement('span', { class: 'adi-opt-close' });
83
-
84
- head1.textContent = 'General options';
85
- head2.textContent = 'Observed nodes';
86
-
87
- ui.appendChild(head1);
88
- ui.appendChild(drawOptionRow('saving', 'Enable saving of settings'));
89
- ui.appendChild(drawOptionRow('makeVisible', 'Scroll to the active element in DOM View'));
90
- ui.appendChild(drawOptionRow('omitEmptyText', 'Hide empty text nodes'));
91
- ui.appendChild(drawOptionRow('foldText', 'Fold the text nodes'));
92
- ui.appendChild(drawOptionRow('transparent', 'Enable transparent background'));
93
- ui.appendChild(head2);
94
- ui.appendChild(drawOptionRow('nodeTypes-3', 'Text node'));
95
- ui.appendChild(drawOptionRow('nodeTypes-8', 'Comment node'));
96
- // ui.appendChild(drawOptionRow('nodeTypes-1', 'Element node'));
97
- // ui.appendChild(drawOptionRow('nodeTypes-9', 'Document node'));
98
- ui.appendChild(close);
99
-
100
- return ui;
101
- }
102
-
103
- // Stops event propagation and also prevents the default behavior.
104
- export function pauseEvent(e) {
105
- if (e.stopPropagation) {
106
- e.stopPropagation();
107
- }
108
-
109
- if (e.preventDefault) {
110
- e.preventDefault();
111
- }
112
-
113
- e.cancelBubble = true;
114
- e.returnValue = false;
115
-
116
- return false;
117
- }
118
- // Helper function for attributes view
119
- export function drawAttrRow(attrName, attrValue) {
120
- const row = newElement('span', { class: 'adi-attr' });
121
- switch (attrName.toLowerCase()) {
122
- case 'defaultaction':
123
- row.innerHTML = `<label>${attrName}: <select data-attr="${attrName}" value="${attrValue}"><option>perform</option><option>cancel</option></label>`;
124
- break;
125
- case 'delay':
126
- row.innerHTML = `<label>${attrName}: <input type="number" data-attr="${attrName}" value="${attrValue}" readonly="readonly"></label>`;
127
- break;
128
- default:
129
- row.innerHTML = `<label>${attrName}: <input type="text" data-attr="${attrName}" value="${attrValue}" readonly="readonly"></label>`;
130
- }
131
- return row;
132
- }
@@ -1,12 +0,0 @@
1
- export class TemplateExpression {
2
- static get properties() {
3
- return {
4
- dataNode: {
5
- type: Object,
6
- },
7
- expression: {
8
- type: Object,
9
- },
10
- };
11
- }
12
- }