@jinntec/fore 1.0.0-3 → 1.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.
- package/README.md +25 -34
- package/dist/fore-dev.js +43 -0
- package/dist/fore-dev.js.map +1 -0
- package/dist/fore.js +36 -1
- package/dist/fore.js.map +1 -0
- package/index.js +3 -0
- package/package.json +34 -38
- package/resources/fore.css +35 -50
- package/src/DependencyNotifyingDomFacade.js +10 -16
- package/src/ForeElementMixin.js +25 -18
- package/src/actions/abstract-action.js +17 -9
- package/src/actions/fx-action.js +6 -4
- package/src/actions/fx-append.js +8 -17
- package/src/actions/fx-confirm.js +3 -1
- package/src/actions/fx-delete.js +6 -3
- package/src/actions/fx-dispatch.js +9 -8
- package/src/actions/fx-hide.js +10 -6
- package/src/actions/fx-insert.js +49 -39
- package/src/actions/fx-message.js +3 -1
- package/src/actions/fx-refresh.js +11 -1
- package/src/actions/fx-replace.js +68 -0
- package/src/actions/fx-return.js +42 -0
- package/src/actions/fx-send.js +3 -1
- package/src/actions/fx-setvalue.js +58 -51
- package/src/actions/fx-show.js +8 -4
- package/src/actions/fx-toggle.js +15 -10
- package/src/actions/fx-update.js +3 -1
- package/src/dep_graph.js +4 -2
- package/src/drawdown.js +67 -82
- package/src/fore.js +158 -11
- package/src/functions/fx-function.js +11 -3
- package/src/fx-bind.js +42 -202
- package/src/fx-fore.js +105 -70
- package/src/fx-header.js +3 -1
- package/src/fx-instance.js +9 -1
- package/src/fx-model.js +31 -23
- package/src/fx-submission.js +73 -47
- package/src/fx-var.js +7 -4
- package/src/getInScopeContext.js +37 -11
- package/src/modelitem.js +4 -4
- package/src/relevance.js +65 -0
- package/src/ui/abstract-control.js +55 -35
- package/src/ui/fx-alert.js +7 -1
- package/src/ui/fx-case.js +3 -1
- package/src/ui/fx-container.js +7 -1
- package/src/ui/fx-control.js +283 -33
- package/src/ui/fx-dialog.js +54 -40
- package/src/ui/fx-group.js +3 -1
- package/src/ui/fx-hint.js +4 -1
- package/src/ui/fx-inspector.js +117 -17
- package/src/ui/fx-items.js +8 -8
- package/src/ui/fx-output.js +14 -5
- package/src/ui/fx-repeat.js +33 -41
- package/src/ui/fx-repeatitem.js +10 -4
- package/src/ui/fx-switch.js +3 -1
- package/src/ui/fx-trigger.js +3 -1
- package/src/xpath-evaluation.js +121 -131
- package/src/xpath-util.js +14 -7
- package/dist/fore-all.js +0 -140
- package/src/.DS_Store +0 -0
- package/src/actions/.DS_Store +0 -0
- package/src/ui/.DS_Store +0 -0
package/src/drawdown.js
CHANGED
|
@@ -4,72 +4,67 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
function markdown(src) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
7
|
+
const rx_lt = /</g;
|
|
8
|
+
const rx_gt = />/g;
|
|
9
|
+
const rx_space = /\t|\r|\uf8ff/g;
|
|
10
|
+
const rx_escape = /\\([\\\|`*_{}\[\]()#+\-~])/g;
|
|
11
|
+
const rx_hr = /^([*\-=_] *){3,}$/gm;
|
|
12
|
+
const rx_blockquote = /\n *> *([^]*?)(?=(\n|$){2})/g;
|
|
13
|
+
const rx_list = /\n( *)(?:[*\-+]|((\d+)|([a-z])|[A-Z])[.)]) +([^]*?)(?=(\n|$){2})/g;
|
|
14
|
+
const rx_listjoin = /<\/(ol|ul)>\n\n<\1>/g;
|
|
15
|
+
const rx_highlight = /(^|[^A-Za-z\d\\])(([*_])|(~)|(\^)|(--)|(\+\+)|`)(\2?)([^<]*?)\2\8(?!\2)(?=\W|_|$)/g;
|
|
16
|
+
const rx_code = /\n((```|~~~).*\n?([^]*?)\n?\2|(( {4}.*?\n)+))/g;
|
|
17
|
+
const rx_link = /((!?)\[(.*?)\]\((.*?)( ".*")?\)|\\([\\`*_{}\[\]()#+\-.!~]))/g;
|
|
18
|
+
const rx_table = /\n(( *\|.*?\| *\n)+)/g;
|
|
19
|
+
const rx_thead = /^.*\n( *\|( *\:?-+\:?-+\:? *\|)* *\n|)/;
|
|
20
|
+
const rx_row = /.*\n/g;
|
|
21
|
+
const rx_cell = /\||(.*?[^\\])\|/g;
|
|
22
|
+
const rx_heading = /(?=^|>|\n)([>\s]*?)(#{1,6}) (.*?)( #*)? *(?=\n|$)/g;
|
|
23
|
+
const rx_para = /(?=^|>|\n)\s*\n+([^<]+?)\n+\s*(?=\n|<|$)/g;
|
|
24
|
+
const rx_stash = /-\d+\uf8ff/g;
|
|
25
25
|
|
|
26
26
|
function replace(rex, fn) {
|
|
27
27
|
src = src.replace(rex, fn);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
function element(tag, content) {
|
|
31
|
-
return
|
|
31
|
+
return `<${tag}>${content}</${tag}>`;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
function blockquote(src) {
|
|
35
|
-
return src.replace(rx_blockquote,
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
return src.replace(rx_blockquote, (all, content) =>
|
|
36
|
+
element('blockquote', blockquote(highlight(content.replace(/^ *> */gm, '')))),
|
|
37
|
+
);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
function list(src) {
|
|
41
|
-
return src.replace(rx_list,
|
|
42
|
-
|
|
41
|
+
return src.replace(rx_list, (all, ind, ol, num, low, content) => {
|
|
42
|
+
const entry = element(
|
|
43
43
|
'li',
|
|
44
44
|
highlight(
|
|
45
45
|
content
|
|
46
|
-
.split(RegExp(
|
|
46
|
+
.split(RegExp(`\n ?${ind}(?:(?:\\d+|[a-zA-Z])[.)]|[*\\-+]) +`, 'g'))
|
|
47
47
|
.map(list)
|
|
48
48
|
.join('</li><li>'),
|
|
49
49
|
),
|
|
50
50
|
);
|
|
51
51
|
|
|
52
|
-
return
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
(low ? 'low' : 'upp') +
|
|
62
|
-
'er-alpha">') +
|
|
63
|
-
entry +
|
|
64
|
-
'</ol>'
|
|
65
|
-
: element('ul', entry))
|
|
66
|
-
);
|
|
52
|
+
return `\n${
|
|
53
|
+
ol
|
|
54
|
+
? `<ol start="${
|
|
55
|
+
num
|
|
56
|
+
? `${ol}">`
|
|
57
|
+
: `${parseInt(ol, 36) - 9}" style="list-style-type:${low ? 'low' : 'upp'}er-alpha">`
|
|
58
|
+
}${entry}</ol>`
|
|
59
|
+
: element('ul', entry)
|
|
60
|
+
}`;
|
|
67
61
|
});
|
|
68
62
|
}
|
|
69
63
|
|
|
70
64
|
function highlight(src) {
|
|
71
|
-
return src.replace(
|
|
72
|
-
|
|
65
|
+
return src.replace(
|
|
66
|
+
rx_highlight,
|
|
67
|
+
(all, _, p1, emp, sub, sup, small, big, p2, content) =>
|
|
73
68
|
_ +
|
|
74
69
|
element(
|
|
75
70
|
emp
|
|
@@ -88,19 +83,18 @@ function markdown(src) {
|
|
|
88
83
|
? 'big'
|
|
89
84
|
: 'code',
|
|
90
85
|
highlight(content),
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
});
|
|
86
|
+
),
|
|
87
|
+
);
|
|
94
88
|
}
|
|
95
89
|
|
|
96
90
|
function unesc(str) {
|
|
97
91
|
return str.replace(rx_escape, '$1');
|
|
98
92
|
}
|
|
99
93
|
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
const stash = [];
|
|
95
|
+
let si = 0;
|
|
102
96
|
|
|
103
|
-
src =
|
|
97
|
+
src = `\n${src}\n`;
|
|
104
98
|
|
|
105
99
|
replace(rx_lt, '<');
|
|
106
100
|
replace(rx_gt, '>');
|
|
@@ -117,56 +111,47 @@ function markdown(src) {
|
|
|
117
111
|
replace(rx_listjoin, '');
|
|
118
112
|
|
|
119
113
|
// code
|
|
120
|
-
replace(rx_code,
|
|
121
|
-
stash[--si] = element('pre', element('code', p3 || p4.replace(/^
|
|
122
|
-
return si
|
|
114
|
+
replace(rx_code, (all, p1, p2, p3, p4) => {
|
|
115
|
+
stash[--si] = element('pre', element('code', p3 || p4.replace(/^ {4}/gm, '')));
|
|
116
|
+
return `${si}\uf8ff`;
|
|
123
117
|
});
|
|
124
118
|
|
|
125
119
|
// link or image
|
|
126
|
-
replace(rx_link,
|
|
120
|
+
replace(rx_link, (all, p1, p2, p3, p4, p5, p6) => {
|
|
127
121
|
stash[--si] = p4
|
|
128
122
|
? p2
|
|
129
|
-
?
|
|
130
|
-
:
|
|
123
|
+
? `<img src="${p4}" alt="${p3}"/>`
|
|
124
|
+
: `<a href="${p4}">${unesc(highlight(p3))}</a>`
|
|
131
125
|
: p6;
|
|
132
|
-
return si
|
|
126
|
+
return `${si}\uf8ff`;
|
|
133
127
|
});
|
|
134
128
|
|
|
135
129
|
// table
|
|
136
|
-
replace(rx_table,
|
|
137
|
-
|
|
138
|
-
return (
|
|
139
|
-
'
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
'
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}),
|
|
152
|
-
)
|
|
153
|
-
);
|
|
130
|
+
replace(rx_table, (all, table) => {
|
|
131
|
+
const sep = table.match(rx_thead)[1];
|
|
132
|
+
return `\n${element(
|
|
133
|
+
'table',
|
|
134
|
+
table.replace(rx_row, (row, ri) =>
|
|
135
|
+
row == sep
|
|
136
|
+
? ''
|
|
137
|
+
: element(
|
|
138
|
+
'tr',
|
|
139
|
+
row.replace(rx_cell, (all, cell, ci) =>
|
|
140
|
+
ci ? element(sep && !ri ? 'th' : 'td', unesc(highlight(cell || ''))) : '',
|
|
141
|
+
),
|
|
142
|
+
),
|
|
143
|
+
),
|
|
144
|
+
)}`;
|
|
154
145
|
});
|
|
155
146
|
|
|
156
147
|
// heading
|
|
157
|
-
replace(rx_heading,
|
|
158
|
-
return _ + element('h' + p1.length, unesc(highlight(p2)));
|
|
159
|
-
});
|
|
148
|
+
replace(rx_heading, (all, _, p1, p2) => _ + element(`h${p1.length}`, unesc(highlight(p2))));
|
|
160
149
|
|
|
161
150
|
// paragraph
|
|
162
|
-
replace(rx_para,
|
|
163
|
-
return element('p', unesc(highlight(content)));
|
|
164
|
-
});
|
|
151
|
+
replace(rx_para, (all, content) => element('p', unesc(highlight(content))));
|
|
165
152
|
|
|
166
153
|
// stash
|
|
167
|
-
replace(rx_stash,
|
|
168
|
-
return stash[parseInt(all)];
|
|
169
|
-
});
|
|
154
|
+
replace(rx_stash, all => stash[parseInt(all)]);
|
|
170
155
|
|
|
171
156
|
return src.trim();
|
|
172
157
|
}
|
package/src/fore.js
CHANGED
|
@@ -13,6 +13,7 @@ export class Fore {
|
|
|
13
13
|
return [
|
|
14
14
|
'FX-DELETE',
|
|
15
15
|
'FX-DISPATCH',
|
|
16
|
+
'FX-HIDE',
|
|
16
17
|
'FX-INSERT',
|
|
17
18
|
'FX-LOAD',
|
|
18
19
|
'FX-MESSAGE',
|
|
@@ -29,6 +30,7 @@ export class Fore {
|
|
|
29
30
|
'FX-SETFOCUS',
|
|
30
31
|
'FX-SETINDEX',
|
|
31
32
|
'FX-SETVALUE',
|
|
33
|
+
'FX-SHOW',
|
|
32
34
|
'FX-TOGGLE',
|
|
33
35
|
'FX-UPDATE',
|
|
34
36
|
];
|
|
@@ -125,7 +127,11 @@ export class Fore {
|
|
|
125
127
|
const { children } = startElement;
|
|
126
128
|
if (children) {
|
|
127
129
|
Array.from(children).forEach(element => {
|
|
130
|
+
if (element.nodeName.toUpperCase() === 'FX-FORE') {
|
|
131
|
+
resolve('done');
|
|
132
|
+
}
|
|
128
133
|
if (Fore.isUiElement(element.nodeName) && typeof element.refresh === 'function') {
|
|
134
|
+
// console.log('refreshing ',element);
|
|
129
135
|
element.refresh();
|
|
130
136
|
} else if (element.nodeName.toUpperCase() !== 'FX-MODEL') {
|
|
131
137
|
Fore.refreshChildren(element, force);
|
|
@@ -138,14 +144,21 @@ export class Fore {
|
|
|
138
144
|
return refreshed;
|
|
139
145
|
}
|
|
140
146
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
/**
|
|
148
|
+
* Alternative to `closest` that respects subcontrol boundaries
|
|
149
|
+
*/
|
|
150
|
+
static getClosest(querySelector, start) {
|
|
151
|
+
while (!start.matches(querySelector)) {
|
|
152
|
+
if (start.matches('fx-fore')) {
|
|
153
|
+
// Subform reached. Bail out
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
start = start.parentNode;
|
|
157
|
+
if (!start) {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return start;
|
|
149
162
|
}
|
|
150
163
|
|
|
151
164
|
/**
|
|
@@ -188,8 +201,8 @@ export class Fore {
|
|
|
188
201
|
return fadeIn();
|
|
189
202
|
}
|
|
190
203
|
|
|
191
|
-
static fadeOutElement(element) {
|
|
192
|
-
const duration =
|
|
204
|
+
static fadeOutElement(element, duration) {
|
|
205
|
+
// const duration = duration;
|
|
193
206
|
let fadeOut = () => {
|
|
194
207
|
// Stop all current animations
|
|
195
208
|
if (element.getAnimations) {
|
|
@@ -210,7 +223,7 @@ export class Fore {
|
|
|
210
223
|
|
|
211
224
|
static dispatch(target, eventName, detail) {
|
|
212
225
|
const event = new CustomEvent(eventName, {
|
|
213
|
-
composed:
|
|
226
|
+
composed: false,
|
|
214
227
|
bubbles: true,
|
|
215
228
|
detail,
|
|
216
229
|
});
|
|
@@ -218,6 +231,140 @@ export class Fore {
|
|
|
218
231
|
target.dispatchEvent(event);
|
|
219
232
|
}
|
|
220
233
|
|
|
234
|
+
static prettifyXml(source) {
|
|
235
|
+
const xmlDoc = new DOMParser().parseFromString(source, 'application/xml');
|
|
236
|
+
const xsltDoc = new DOMParser().parseFromString(
|
|
237
|
+
[
|
|
238
|
+
// describes how we want to modify the XML - indent everything
|
|
239
|
+
'<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">',
|
|
240
|
+
' <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>',
|
|
241
|
+
' <xsl:strip-space elements="*"/>',
|
|
242
|
+
' <xsl:template match="text()">', // change to just text() to strip space in text nodes
|
|
243
|
+
' <xsl:value-of select="normalize-space(.)"/>',
|
|
244
|
+
' </xsl:template>',
|
|
245
|
+
' <xsl:template match="node()|@*">',
|
|
246
|
+
' <xsl:copy>',
|
|
247
|
+
' <xsl:apply-templates select="node()|@*"/>',
|
|
248
|
+
' </xsl:copy>',
|
|
249
|
+
' </xsl:template>',
|
|
250
|
+
'</xsl:stylesheet>',
|
|
251
|
+
].join('\n'),
|
|
252
|
+
'application/xml',
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
const xsltProcessor = new XSLTProcessor();
|
|
257
|
+
xsltProcessor.importStylesheet(xsltDoc);
|
|
258
|
+
const resultDoc = xsltProcessor.transformToDocument(xmlDoc);
|
|
259
|
+
const resultXml = new XMLSerializer().serializeToString(resultDoc);
|
|
260
|
+
return resultXml;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
static formatXml (xml) {
|
|
264
|
+
var reg = /(>)(<)(\/*)/g;
|
|
265
|
+
var wsexp = / *(.*) +\n/g;
|
|
266
|
+
var contexp = /(<.+>)(.+\n)/g;
|
|
267
|
+
xml = xml.replace(reg, '$1\n$2$3').replace(wsexp, '$1\n').replace(contexp, '$1\n$2');
|
|
268
|
+
var pad = 0;
|
|
269
|
+
var formatted = '';
|
|
270
|
+
var lines = xml.split('\n');
|
|
271
|
+
var indent = 0;
|
|
272
|
+
var lastType = 'other';
|
|
273
|
+
// 4 types of tags - single, closing, opening, other (text, doctype, comment) - 4*4 = 16 transitions
|
|
274
|
+
var transitions = {
|
|
275
|
+
'single->single': 0,
|
|
276
|
+
'single->closing': -1,
|
|
277
|
+
'single->opening': 0,
|
|
278
|
+
'single->other': 0,
|
|
279
|
+
'closing->single': 0,
|
|
280
|
+
'closing->closing': -1,
|
|
281
|
+
'closing->opening': 0,
|
|
282
|
+
'closing->other': 0,
|
|
283
|
+
'opening->single': 1,
|
|
284
|
+
'opening->closing': 0,
|
|
285
|
+
'opening->opening': 1,
|
|
286
|
+
'opening->other': 1,
|
|
287
|
+
'other->single': 0,
|
|
288
|
+
'other->closing': -1,
|
|
289
|
+
'other->opening': 0,
|
|
290
|
+
'other->other': 0
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
for (var i = 0; i < lines.length; i++) {
|
|
294
|
+
var ln = lines[i];
|
|
295
|
+
var single = Boolean(ln.match(/<.+\/>/)); // is this line a single tag? ex. <br />
|
|
296
|
+
var closing = Boolean(ln.match(/<\/.+>/)); // is this a closing tag? ex. </a>
|
|
297
|
+
var opening = Boolean(ln.match(/<[^!].*>/)); // is this even a tag (that's not <!something>)
|
|
298
|
+
var type = single ? 'single' : closing ? 'closing' : opening ? 'opening' : 'other';
|
|
299
|
+
var fromTo = lastType + '->' + type;
|
|
300
|
+
lastType = type;
|
|
301
|
+
var padding = '';
|
|
302
|
+
|
|
303
|
+
indent += transitions[fromTo];
|
|
304
|
+
for (var j = 0; j < indent; j++) {
|
|
305
|
+
padding += ' ';
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
formatted += padding + ln + '\n';
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
static async loadForeFromUrl(hostElement, url) {
|
|
313
|
+
console.log('########## loading Fore from ', this.src, '##########');
|
|
314
|
+
await fetch(url, {
|
|
315
|
+
method: 'GET',
|
|
316
|
+
mode: 'cors',
|
|
317
|
+
credentials: 'include',
|
|
318
|
+
headers: {
|
|
319
|
+
'Content-Type': 'text/html',
|
|
320
|
+
},
|
|
321
|
+
})
|
|
322
|
+
.then(response => {
|
|
323
|
+
const responseContentType = response.headers.get('content-type').toLowerCase();
|
|
324
|
+
console.log('********** responseContentType *********', responseContentType);
|
|
325
|
+
if (responseContentType.startsWith('text/html')) {
|
|
326
|
+
return response.text().then(result =>
|
|
327
|
+
// console.log('xml ********', result);
|
|
328
|
+
new DOMParser().parseFromString(result, 'text/html'),
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
return 'done';
|
|
332
|
+
})
|
|
333
|
+
.then(data => {
|
|
334
|
+
// const theFore = fxEvaluateXPathToFirstNode('//fx-fore', data.firstElementChild);
|
|
335
|
+
const theFore = data.querySelector('fx-fore');
|
|
336
|
+
// console.log('thefore', theFore)
|
|
337
|
+
if (!theFore) {
|
|
338
|
+
hostElement.dispatchEvent(
|
|
339
|
+
new CustomEvent('error', {
|
|
340
|
+
composed: false,
|
|
341
|
+
bubbles: true,
|
|
342
|
+
detail: {
|
|
343
|
+
message: 'cyclic graph',
|
|
344
|
+
},
|
|
345
|
+
}),
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
hostElement.appendChild(theFore);
|
|
349
|
+
theFore.classList.add('widget');
|
|
350
|
+
// return theFore;
|
|
351
|
+
// theFore.setAttribute('from-src', this.src);
|
|
352
|
+
// this.replaceWith(theFore);
|
|
353
|
+
})
|
|
354
|
+
.catch(error => {
|
|
355
|
+
hostElement.dispatchEvent(
|
|
356
|
+
new CustomEvent('error', {
|
|
357
|
+
composed: false,
|
|
358
|
+
bubbles: true,
|
|
359
|
+
detail: {
|
|
360
|
+
error: error,
|
|
361
|
+
message: `'${url}' not found or does not contain Fore element.`,
|
|
362
|
+
},
|
|
363
|
+
}),
|
|
364
|
+
);
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
|
|
221
368
|
/**
|
|
222
369
|
* clear all text nodes and attribute values to get a 'clean' template.
|
|
223
370
|
* @param n
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { registerCustomXPathFunction } from 'fontoxpath';
|
|
2
2
|
import { foreElementMixin } from '../ForeElementMixin.js';
|
|
3
|
-
import { evaluateXPath } from '../xpath-evaluation.js';
|
|
3
|
+
import { evaluateXPath, globallyDeclaredFunctionLocalNames } from '../xpath-evaluation.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Allows to extend a form with local custom functions.
|
|
@@ -41,10 +41,16 @@ export class FxFunction extends foreElementMixin(HTMLElement) {
|
|
|
41
41
|
|
|
42
42
|
// TODO: lookup prefix
|
|
43
43
|
const functionIdentifier =
|
|
44
|
-
prefix === 'local'
|
|
44
|
+
prefix === 'local' || !prefix
|
|
45
45
|
? { namespaceURI: 'http://www.w3.org/2005/xquery-local-functions', localName }
|
|
46
46
|
: `${prefix}:${localName}`;
|
|
47
47
|
|
|
48
|
+
// Make the function available globally w/o a prefix. See the functionNameResolver for for how
|
|
49
|
+
// this is picked up
|
|
50
|
+
if (!prefix) {
|
|
51
|
+
globallyDeclaredFunctionLocalNames.push(localName);
|
|
52
|
+
}
|
|
53
|
+
|
|
48
54
|
const paramParts = params
|
|
49
55
|
? params.split(',').map(param => {
|
|
50
56
|
const match = param.match(/(?<variableName>\$[^\s]+)(?:\sas\s(?<varType>.+))/);
|
|
@@ -102,4 +108,6 @@ export class FxFunction extends foreElementMixin(HTMLElement) {
|
|
|
102
108
|
}
|
|
103
109
|
}
|
|
104
110
|
}
|
|
105
|
-
customElements.
|
|
111
|
+
if (!customElements.get('fx-function')) {
|
|
112
|
+
customElements.define('fx-function', FxFunction);
|
|
113
|
+
}
|