@peter.naydenov/morph 3.3.2 → 3.3.3
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/.claude/scheduled_tasks.lock +1 -0
- package/.claude/settings.local.json +14 -0
- package/.graphify_cached.json +1 -0
- package/.graphify_semantic_new.json +1 -0
- package/.graphify_uncached.txt +14 -0
- package/.opencode/package-lock.json +115 -0
- package/.opencode/plugins/graphify.js +22 -0
- package/AGENTS.md +8 -0
- package/Changelog.md +10 -0
- package/graphify-out/.graphify_python +1 -0
- package/graphify-out/GRAPH_REPORT.md +147 -0
- package/graphify-out/cache/12d38a6879ec5b7a18b61b92920684a5e915c2255c41e2c56168c678dba94023.json +1 -0
- package/graphify-out/cache/1ba574be094f9bd868bbce1091b9988d6188ae071762a73d483516498b742434.json +1 -0
- package/graphify-out/cache/2dfd19c49f88b8af0c95f7692ae9453b54cf898dba6c24cad9cbd555b365f5e7.json +1 -0
- package/graphify-out/cache/343264caa0702ae2210efeb2d673fb69b59bd01403803c84f9da0ce21d93c6fe.json +1 -0
- package/graphify-out/cache/38f82a17b2933bf14206263846c7396b46ac0db01af525300ac20f2f3f2b0534.json +1 -0
- package/graphify-out/cache/3a8b3ccf38f1d380228dda52c3c595ec76b5827b6905ef7e2bef6e265ee4ac16.json +1 -0
- package/graphify-out/cache/3b3e764a57e1d2ce17e5a74bea1c7ee493260e27266c114a72688d441f712e52.json +1 -0
- package/graphify-out/cache/42bc18f8ec31b043b4c4ecc11c79c288afe0801207d60a7cc322d11ab4579864.json +1 -0
- package/graphify-out/cache/4e3d45485b073109c7d91f18dac64ffbf0cbc21ae0edac016cb7b5f061954af6.json +1 -0
- package/graphify-out/cache/4ed08a09c3f090fe62cd56647a5251d60cf2f095156e502244a4f732929e342c.json +1 -0
- package/graphify-out/cache/51c174d3534ae05ed6dcbdb7f0d16da0b22f05677ef2863920e0a541b06090dd.json +1 -0
- package/graphify-out/cache/51d65b15aad6e35883d6ccaa0688273d7e14d8b7b85b194c50c365e5ea6710c6.json +1 -0
- package/graphify-out/cache/5d96cf59b7e5e3ea65c2ddcc6267178ea8916e104ff3f82a5a4d90179f762d11.json +1 -0
- package/graphify-out/cache/63fa82962f6899c2c099e95b595c5106f5dd53b2dc65037b89d6c6578033c03c.json +1 -0
- package/graphify-out/cache/6878c29d96e13e9fee1e01e4ca4e77d28b1e8e6c4f1d05dbffdca58625ef5694.json +1 -0
- package/graphify-out/cache/6c7082448b871f8cce9c6e26f788252a3b0c7e88ce40b4d3652ca9b78a2df049.json +1 -0
- package/graphify-out/cache/7cb42a4ad6e7c2f8b66560c9c40053e479cc1cffdf074d6b00bc23e607535376.json +1 -0
- package/graphify-out/cache/8712e549b4b42d5dc14c3e4b56f384c9d8e37116dc61ad906a05e10a1445ff40.json +1 -0
- package/graphify-out/cache/8b1ea63dfe0d47683be14dd72078eb83cf5b182d497237adbcd50ebdc1fee1bc.json +1 -0
- package/graphify-out/cache/8cd02cb84a50696666d33fee84a4a7e75fce651780ba7a4474bfe9b4a2b79c46.json +1 -0
- package/graphify-out/cache/8d0520a089ffaa71927ddddad5cb4d8f796a9febf0b8c4d54f78453b955520c5.json +1 -0
- package/graphify-out/cache/9406e0a23a011eaa9d74fe717280e5be52142ba4db8b7baee948dcdea6fe2617.json +1 -0
- package/graphify-out/cache/98abf9b9fbeb7f5fdaef6b853c949d297586b99e2965330906234f2ae331c0af.json +1 -0
- package/graphify-out/cache/9decf23c89efbaa42811f95c737234abee72478582ce4a46d99ba12d7446bb7b.json +1 -0
- package/graphify-out/cache/a37bc5340c5f31d2ef717845d339f468853e6554f753466ba2d995147d25fedf.json +1 -0
- package/graphify-out/cache/a77d81d5705a824ba81dc3556452ecc99978bc335e65e961aee29ce01e7cf81c.json +1 -0
- package/graphify-out/cache/ast/v0.8.39/21cd1a6bc5dbd687522c86e9f7db1842400b31ee3ba62127533aba56a478da5d.json +1 -0
- package/graphify-out/cache/ast/v0.8.39/29c3826c5e1938406f9eaf50a1354609aeb16e8f0d27e5a454c069c982f21180.json +1 -0
- package/graphify-out/cache/ast/v0.8.39/c31ea4d76660d1000df3bd29929d120e900297c7a1c26e5266312c21a9432e55.json +1 -0
- package/graphify-out/cache/ast/v0.8.39/de54c2617a64a2a1c1db34e6494216dd949fe730b51270bebba55c63d54a31e9.json +1 -0
- package/graphify-out/cache/b83cba0b46f18ae8fc4d50b540eaa276c28745ea4639863c082cb41681220b9d.json +1 -0
- package/graphify-out/cache/bd607a8d62efb3cceb791e36c2495c5ceee38e913c2386d293cca88566f4c0aa.json +1 -0
- package/graphify-out/cache/beb2827f4b8ad2aaacd809c8d783eb1f5f3c3c997ce6941d1cc9b2f0df7a0d6e.json +1 -0
- package/graphify-out/cache/ca721e7772d7906c5fecc00d69aa50bdc5e73ba087807089f3ca26509e014889.json +1 -0
- package/graphify-out/cache/cb49f9ceae6e04f66081b0c73c0574bddaf01240ea0c7efc1880616b94b4c0d8.json +1 -0
- package/graphify-out/cache/ce9874dce6f3f855a53dd706b4b83a503dc4ba72f7f36b6d73ec2cc8354f3cdf.json +1 -0
- package/graphify-out/cache/d3e24fc669e3f2a2c5e9e864a97ca447f0dcc1c5aad33c88a2280ac97188e888.json +1 -0
- package/graphify-out/cache/d6c072004e2ea18f9a5380aa75980cd08b15e7d6d893d396a5baac37dfc24310.json +1 -0
- package/graphify-out/cache/d99f1759a41541d9ef41aefdf89a2dbcab7272ccc91a9794062224124222e333.json +1 -0
- package/graphify-out/cache/dbb69ddd98951e0d5e51b2e1a2cf97a8febb147e55b81b43b05b680844bf4a1f.json +1 -0
- package/graphify-out/cache/df270b9b613de7bbefce4cabc6b3dd6e66ebecdbf6f0cefde05bb676569ee1c3.json +1 -0
- package/graphify-out/cache/e56607f0791079dbd05e56cdac41f88124785d367f9da0eb436952406cb317da.json +1 -0
- package/graphify-out/cache/ecdfee4e64acdd666f25596341a8ff4a41d7ee1e637de40685ff33c1efa814c7.json +1 -0
- package/graphify-out/cache/f0f3005c7ec68d16fcde259d6bc996520841d021ce2531cbb7f3de343996c4ea.json +1 -0
- package/graphify-out/cache/f2bfcd400f076a7e8a9e54b821d555c90b93ef4dd8d3652f78ec35acad5e0615.json +1 -0
- package/graphify-out/cache/semantic/043be2e32281a59e2bacb95418b95816b558a290aa581434b22666fb9a6a3a6c.json +1 -0
- package/graphify-out/cache/semantic/13439df0f4f40e2c190340576c1a46c2cc82b9fc789f262c78d7129cc56ef13c.json +1 -0
- package/graphify-out/cache/semantic/136052be0f52f9258076b87da6bde0ea62763a63684cc6729f759910448ae675.json +1 -0
- package/graphify-out/cache/semantic/15cbc6ab30bfa8cf7bb9b5646a2598aa78531047ef5096d5d8ab08edbcf8ee7d.json +1 -0
- package/graphify-out/cache/semantic/21cd1a6bc5dbd687522c86e9f7db1842400b31ee3ba62127533aba56a478da5d.json +1 -0
- package/graphify-out/cache/semantic/22bd0d40f23b81ba30a703fc290cc518f18d3148f5553ffc79f4bf8a0a71722c.json +1 -0
- package/graphify-out/cache/semantic/29c3826c5e1938406f9eaf50a1354609aeb16e8f0d27e5a454c069c982f21180.json +1 -0
- package/graphify-out/cache/semantic/2e913a06516b6bff22019b157680d17617db82a9ed2277ce1e20eac945939a7e.json +1 -0
- package/graphify-out/cache/semantic/30db4df562575c6116ad9e8843f19c557ab6fc25288c7aed8926641748b21fd6.json +1 -0
- package/graphify-out/cache/semantic/325abe6948add2e47c2271195503ab21f897e27f2cc9af292f39408b94a2f51c.json +1 -0
- package/graphify-out/cache/semantic/3579f6cf2c93aa83eb9396e389c195f17e4cff527d43718e61503e5c0f223f84.json +1 -0
- package/graphify-out/cache/semantic/36cda2fb14ba2ee3b8bc721a278f4963bf001c72258dd707b4b141334be01c15.json +1 -0
- package/graphify-out/cache/semantic/403b6596e3414f78206fc02adf9b62f07af237be191e0f4b26706041bf1e0ee1.json +1 -0
- package/graphify-out/cache/semantic/40f4144bc24d137a1afdcac95143c2bc3e26c0086d150c73df85fdf236bebe01.json +1 -0
- package/graphify-out/cache/semantic/45d85f3ac35b83d9a076c6e25c220324a0c92d0e955ba85e04b20ef09ddad9fd.json +1 -0
- package/graphify-out/cache/semantic/468d9e0c3d92cce2723852d2f29033326433cdc368203092b8470f2f356e3cec.json +1 -0
- package/graphify-out/cache/semantic/5983c77253844a325cb78f45828115ede5a688908bd38fa1b32ca78ab319deb9.json +1 -0
- package/graphify-out/cache/semantic/59ef3e18c32f0f877d8854ecb5e9f8714c608d5d90ca7adc71f2859fe496f66f.json +1 -0
- package/graphify-out/cache/semantic/71dd26effab66822e1d20111accfa0cc434826661da83b1b86a6fc3119980a66.json +1 -0
- package/graphify-out/cache/semantic/78bc10fe7d8d145c2c12af97dd75ea16f6787f1f15f0af0b145ac315ce63dcb6.json +1 -0
- package/graphify-out/cache/semantic/7c92d89867073cc9e54a821be558de7322fa42f342cf4c52da9bf02c29f43b1d.json +1 -0
- package/graphify-out/cache/semantic/82c3b90b2523c47b43a3212e2d30ed8d06c0027697f89fe177d062baf4d4202f.json +1 -0
- package/graphify-out/cache/semantic/8917cb163ec1afce8e5d659680749a553be3aa6aef54ebc757dd1b7c81d707c6.json +1 -0
- package/graphify-out/cache/semantic/8da5742abeaeadae80c4f57a4e98432a4bfc789eadb5082d3919780d646546f6.json +1 -0
- package/graphify-out/cache/semantic/97f4eb2208c6b1e81c84600ab52507478f5e682e63e5546a92c97b4c3d9371eb.json +1 -0
- package/graphify-out/cache/semantic/9c01c0ac53d626004b3d72953063c71f251710e7f23a8765c149159b0f422ecc.json +1 -0
- package/graphify-out/cache/semantic/9d0bbf5bdbb2aa4e3507d2e118464ce70d165916e29cae54b5ead974bfc1bd04.json +1 -0
- package/graphify-out/cache/semantic/9e59357a8097ad32258c2cb47c066508049e7f8c21fa55a1a5f5a4b0eee41275.json +1 -0
- package/graphify-out/cache/semantic/aaaff53eae109640d8e48c4585390fa7a2c2ca04088d314e578c316ca95f53e0.json +1 -0
- package/graphify-out/cache/semantic/b18464395b8719578b14148fd37880916c62b10f78942c862da386815c05b628.json +1 -0
- package/graphify-out/cache/semantic/c31ea4d76660d1000df3bd29929d120e900297c7a1c26e5266312c21a9432e55.json +1 -0
- package/graphify-out/cache/semantic/c74b855b4778be378db8fa05e33582c33cb563d8698ba6dae566e1cd37d0fb09.json +1 -0
- package/graphify-out/cache/semantic/cc8bf09a84e6fcc420e2438b3d6403560128b0edbd907761350fa58536d844ff.json +1 -0
- package/graphify-out/cache/semantic/d39f7cd9481b6f19c88e62ff5f7a3bddbf3a3593b2b1257a5092b44374c70874.json +1 -0
- package/graphify-out/cache/semantic/d5472c5e2c6560c9de5c17a444e2060eb9ccaa5dc7f4f3fe0dc3a5f68625bb91.json +1 -0
- package/graphify-out/cache/semantic/de54c2617a64a2a1c1db34e6494216dd949fe730b51270bebba55c63d54a31e9.json +1 -0
- package/graphify-out/cache/semantic/e29c1a9e35ffd56ab3b1e2f4800b48e9a6880bddecfc028dfdaf14498f52d8b4.json +1 -0
- package/graphify-out/cache/semantic/e39668e1347ee1000e7fba8b922c76488e34c35f2088b8334806e0256cfd71a7.json +1 -0
- package/graphify-out/cache/semantic/e9eea1131268a154e037e558c1856fbb2941e129b405659416b4e69746759440.json +1 -0
- package/graphify-out/cache/semantic/f3863c3e1c42f444b735cf4042b01a07b4e2f0bff82580bfab9bad1a784b8f4d.json +1 -0
- package/graphify-out/cache/semantic/f6dde571c1b88858dbf6da9b447dba7e66d9cb211c0130abcbb0768efed52e7b.json +1 -0
- package/graphify-out/cache/semantic/fa84dbd8fb64d52d0d43ea31da6cff178668e3eba7efb6e96ff605f3838a2bea.json +1 -0
- package/graphify-out/cache/stat-index.json +1 -0
- package/graphify-out/cost.json +18 -0
- package/graphify-out/graph.html +307 -0
- package/graphify-out/graph.json +6531 -0
- package/graphify-out/manifest.json +467 -0
- package/opencode.json +6 -0
- package/package.json +14 -6
- package/src/main.js +3 -7
- package/src/methods/_chopTemplates.js +56 -63
- package/src/methods/_setupActions.js +7 -14
- package/src/methods/actionData.js +35 -21
- package/src/methods/actionExtendedRender.js +21 -22
- package/src/methods/actionMix.js +47 -49
- package/src/methods/actionRender.js +43 -75
- package/src/methods/build.js +75 -97
- package/src/methods/executeActions.js +63 -49
- package/src/methods/processCommands.js +6 -10
- package/src/methods/processPlaceholders.js +105 -123
- package/src/methods/render.js +11 -13
|
@@ -1,81 +1,74 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Creates a template chopping function that splits text into parts and placeholders.
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* @param {object} settings - Configuration object containing template delimiters
|
|
5
5
|
* @param {string} settings.TG_PRX - Opening delimiter (e.g., '{{')
|
|
6
6
|
* @param {string} settings.TG_SFX - Closing delimiter (e.g., '}}')
|
|
7
7
|
* @param {number} settings.TG_SIZE_P - Length of opening delimiter
|
|
8
8
|
* @param {number} settings.TG_SIZE_S - Length of closing delimiter
|
|
9
|
-
*
|
|
9
|
+
*
|
|
10
10
|
* @returns {Function} Function that chops template text into array parts
|
|
11
|
-
*
|
|
11
|
+
*
|
|
12
12
|
* @example
|
|
13
13
|
* const chop = _chopTemplate(settings);
|
|
14
14
|
* const result = chop('Hello {{name}}!');
|
|
15
|
+
* // Returns: ['Hello ', '{{name}}', '!']
|
|
15
16
|
*/
|
|
16
17
|
function _chopTemplate ( settings ) {
|
|
17
|
-
return function
|
|
18
|
+
return function chop ( text ) {
|
|
18
19
|
const { TG_PRX, TG_SFX, TG_SIZE_P, TG_SIZE_S } = settings;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if ( text.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
let additional = _chopTemplate ( nextText )
|
|
50
|
-
return res.concat ( additional )
|
|
51
|
-
}
|
|
52
|
-
}} // chopTemplate func.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
/**
|
|
20
|
+
|
|
21
|
+
if ( typeof text != 'string' ) return showError ( 'notAString' )
|
|
22
|
+
if ( text.length == 0 ) return []
|
|
23
|
+
|
|
24
|
+
const start = text.indexOf ( TG_PRX )
|
|
25
|
+
if ( start == -1 ) return [ text ] // No placeholders left
|
|
26
|
+
|
|
27
|
+
const res = []
|
|
28
|
+
if ( start > 0 ) res.push ( text.slice ( 0, start ))
|
|
29
|
+
|
|
30
|
+
let end = text.indexOf ( TG_SFX )
|
|
31
|
+
const nextStart = text.indexOf ( TG_PRX, start + TG_SIZE_P )
|
|
32
|
+
|
|
33
|
+
if ( end == -1 ) return showError ( 'missingClosing' )
|
|
34
|
+
if ( end < start ) return showError ( 'closedBeforeOpened' )
|
|
35
|
+
end += TG_SIZE_S
|
|
36
|
+
|
|
37
|
+
if ( nextStart != -1 && nextStart < end ) return showError ( 'newBeforeClosed' )
|
|
38
|
+
|
|
39
|
+
res.push ( text.slice ( start, end ))
|
|
40
|
+
|
|
41
|
+
const rest = chop ( text.slice ( end )) // Continue with the rest of the text
|
|
42
|
+
if ( typeof rest === 'string' ) return rest // Parse error found deeper in the template. Propagate it.
|
|
43
|
+
return res.concat ( rest )
|
|
44
|
+
}
|
|
45
|
+
} // _chopTemplate func.
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
/**
|
|
57
50
|
* Returns error messages for template parsing failures.
|
|
58
|
-
*
|
|
51
|
+
*
|
|
59
52
|
* @param {string} type - Error type identifier
|
|
60
53
|
* @returns {string} Human-readable error message
|
|
61
54
|
*/
|
|
62
|
-
function showError (type) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
55
|
+
function showError ( type ) {
|
|
56
|
+
switch ( type ) {
|
|
57
|
+
case 'notAString':
|
|
58
|
+
return `Error: Template is not a string.`
|
|
59
|
+
case 'missingClosing':
|
|
60
|
+
return `Error: Placeholder with missing closing tag.`
|
|
61
|
+
case 'closedBeforeOpened':
|
|
62
|
+
return `Error: Placeholder closing tag without starting one.`
|
|
63
|
+
case 'newBeforeClosed':
|
|
64
|
+
return `Error: Nested placeholders. Close placeholder before open new one.`
|
|
65
|
+
default:
|
|
66
|
+
return `Error: Unknown template error.`
|
|
67
|
+
}
|
|
68
|
+
} // showError func.
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
export default _chopTemplate
|
|
73
|
+
|
|
74
|
+
|
|
@@ -16,25 +16,18 @@
|
|
|
16
16
|
* // 2: [] }
|
|
17
17
|
*/
|
|
18
18
|
function _setupActions ( actions, dataDeepLevel=10 ) {
|
|
19
|
-
let
|
|
19
|
+
let
|
|
20
20
|
actSetup = {}
|
|
21
|
-
, actionList = [...actions]
|
|
22
21
|
, actLevel = 0
|
|
23
|
-
, i = 0
|
|
24
|
-
, countHashes = 0
|
|
25
22
|
;
|
|
26
|
-
|
|
27
|
-
actionList.forEach ( action => { if ( action === '#' ) countHashes++ })
|
|
28
|
-
if ( countHashes < dataDeepLevel ) console.error ( `Error: Not enough level markers (#) for data with depth level ${dataDeepLevel}. Found ${countHashes} level markers in actions: ${actions.join(', ')}` )
|
|
29
|
-
|
|
30
|
-
do {
|
|
31
|
-
actSetup[i] = []
|
|
32
|
-
i++
|
|
33
|
-
} while ( i <= dataDeepLevel )
|
|
34
23
|
|
|
24
|
+
const countHashes = actions.filter ( action => action === '#' ).length
|
|
25
|
+
if ( countHashes < dataDeepLevel ) console.error ( `Error: Not enough level markers (#) for data with depth level ${dataDeepLevel}. Found ${countHashes} level markers in actions: ${actions.join(', ')}` )
|
|
35
26
|
|
|
27
|
+
for ( let i = 0; i <= dataDeepLevel; i++ ) actSetup[i] = []
|
|
36
28
|
|
|
37
|
-
|
|
29
|
+
// 'every' works as forEach with a break: returning false stops on too many '#'
|
|
30
|
+
actions.every ( act => {
|
|
38
31
|
if ( act === '#' ) { // it's a change level action
|
|
39
32
|
actLevel++
|
|
40
33
|
if ( actLevel > dataDeepLevel ) return false
|
|
@@ -91,7 +84,7 @@ function _setupActions ( actions, dataDeepLevel=10 ) {
|
|
|
91
84
|
, level: actLevel
|
|
92
85
|
})
|
|
93
86
|
return true
|
|
94
|
-
}) //
|
|
87
|
+
}) // actions every
|
|
95
88
|
return actSetup
|
|
96
89
|
} // _setupActions func.
|
|
97
90
|
|
|
@@ -1,30 +1,44 @@
|
|
|
1
1
|
import _defineDataType from "./_defineType.js"
|
|
2
2
|
|
|
3
|
-
function actionData({ name }, levelData, { helpers, extendArguments, nestedData, level, useHelper }) {
|
|
4
|
-
const theData = levelData
|
|
5
|
-
let dataType = _defineDataType(theData)
|
|
6
3
|
|
|
7
|
-
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Action 'data' ('>'). Calls the named helper to transform the data before
|
|
7
|
+
* rendering. The result replaces the level data.
|
|
8
|
+
*
|
|
9
|
+
* Function data provides its value by being called. The uncalled item stays
|
|
10
|
+
* available to the helper as the 'full' argument.
|
|
11
|
+
*
|
|
12
|
+
* @param {object} step - Action step: { name } is the helper name
|
|
13
|
+
* @param {any} theData - Current data item from the level slice
|
|
14
|
+
* @param {object} context - Execution context (see executeActions.js)
|
|
15
|
+
*/
|
|
16
|
+
function actionData ({ name }, theData, { helpers, extendArguments, nestedData, level, useHelper }) {
|
|
17
|
+
const callHelper = ( data, full, uhContext ) => helpers[name] ({ data, ...extendArguments, full, useHelper: useHelper ( uhContext ) })
|
|
18
|
+
|
|
19
|
+
switch ( _defineDataType ( theData )) {
|
|
8
20
|
case 'array':
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
21
|
+
theData.forEach ( ( d, i ) => {
|
|
22
|
+
const value = ( d instanceof Function ) ? d () : d
|
|
23
|
+
theData[i] = callHelper ( value, d, d )
|
|
24
|
+
})
|
|
25
|
+
break
|
|
14
26
|
case 'object':
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
break
|
|
27
|
+
nestedData[level] = [ callHelper ( theData, theData, theData ) ]
|
|
28
|
+
break
|
|
29
|
+
case 'function': {
|
|
30
|
+
const value = theData ()
|
|
31
|
+
nestedData[level] = [ callHelper ( value, theData, value ) ]
|
|
32
|
+
break
|
|
33
|
+
}
|
|
23
34
|
case 'primitive':
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
break
|
|
35
|
+
nestedData[level] = callHelper ( theData, theData, theData )
|
|
36
|
+
break
|
|
27
37
|
} // switch dataType
|
|
28
|
-
}
|
|
38
|
+
} // actionData func.
|
|
39
|
+
|
|
40
|
+
|
|
29
41
|
|
|
30
42
|
export default actionData
|
|
43
|
+
|
|
44
|
+
|
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Action 'extendedRender' ('+'). Runs the named helper over every item of the
|
|
3
|
+
* root level data (nestedData[0]) and replaces the items with the results.
|
|
4
|
+
*
|
|
5
|
+
* Useful when a placeholder needs to post-process the whole data list after
|
|
6
|
+
* the deeper levels are already rendered. Missing helpers are silently ignored.
|
|
7
|
+
*
|
|
8
|
+
* @param {object} step - Action step: { name } is the helper name
|
|
9
|
+
* @param {any} theData - Current data item (unused - this action works on the root level)
|
|
10
|
+
* @param {object} context - Execution context (see executeActions.js)
|
|
11
|
+
*/
|
|
12
|
+
function actionExtendedRender ({ name }, theData, { helpers, extendArguments, useHelper, nestedData }) {
|
|
13
|
+
const helper = helpers[name]
|
|
2
14
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
// build.js used `nestedData[0]`.
|
|
6
|
-
// "nestedData[0].forEach((d, i) => {"
|
|
7
|
-
// "const uh = createUseHelper(d);"
|
|
8
|
-
// "nestedData[0][i] = helpers[name]({ data: d, ...extendArguments, full: d, useHelper: uh })"
|
|
15
|
+
if ( typeof helper !== 'function' ) return
|
|
16
|
+
if ( !Array.isArray ( nestedData[0] )) return
|
|
9
17
|
|
|
10
|
-
|
|
11
|
-
|
|
18
|
+
nestedData[0].forEach ( ( d, i ) => {
|
|
19
|
+
nestedData[0][i] = helper ({ data: d, ...extendArguments, full: d, useHelper: useHelper ( d ) })
|
|
20
|
+
})
|
|
21
|
+
} // actionExtendedRender func.
|
|
12
22
|
|
|
13
|
-
const isValid = typeof helpers[name] === 'function';
|
|
14
23
|
|
|
15
|
-
if (isValid) {
|
|
16
|
-
if (nestedData[0] && Array.isArray(nestedData[0])) {
|
|
17
|
-
nestedData[0].forEach((d, i) => {
|
|
18
|
-
const uh = useHelper(d);
|
|
19
|
-
nestedData[0][i] = helpers[name]({ data: d, ...extendArguments, full: d, useHelper: uh })
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
// TODO: Error...
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
24
|
|
|
28
25
|
export default actionExtendedRender
|
|
26
|
+
|
|
27
|
+
|
package/src/methods/actionMix.js
CHANGED
|
@@ -1,61 +1,59 @@
|
|
|
1
1
|
import _defineDataType from "./_defineType.js"
|
|
2
2
|
import walk from '@peter.naydenov/walk'
|
|
3
3
|
|
|
4
|
-
function actionMix({ name }, levelData, { helpers, extendArguments, nestedData, level, useHelper }) {
|
|
5
|
-
const theData = levelData
|
|
6
|
-
let dataType = _defineDataType(theData)
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Action 'mix' ('[]'). Merges the level data into a single value.
|
|
8
|
+
*
|
|
9
|
+
* Anonymous mix ('[]', no helper name):
|
|
10
|
+
* - array : joins all items (or their 'text' property) into one string;
|
|
11
|
+
* - object : publishes the 'text' results to the upper data levels,
|
|
12
|
+
* matching values by their breadcrumb keys.
|
|
13
|
+
*
|
|
14
|
+
* Named mix ('[]helperName'): the helper receives the data and produces
|
|
15
|
+
* the merged value itself.
|
|
16
|
+
*
|
|
17
|
+
* @param {object} step - Action step: { name } is the helper name ('' for anonymous mix)
|
|
18
|
+
* @param {any} theData - Current data item from the level slice
|
|
19
|
+
* @param {object} context - Execution context (see executeActions.js)
|
|
20
|
+
*/
|
|
21
|
+
function actionMix ({ name }, theData, { helpers, extendArguments, nestedData, level, useHelper }) {
|
|
22
|
+
|
|
23
|
+
if ( name === '' ) { // Anonymous mixing action
|
|
24
|
+
switch ( _defineDataType ( theData )) {
|
|
25
|
+
case 'object': {
|
|
26
|
+
const hasBreadcrumbKeys = Object.keys ( theData ).some ( k => k.includes ( '/' ))
|
|
27
|
+
if ( hasBreadcrumbKeys ) Object.entries ( theData ).forEach ( ([ k, v ]) => nestedData[level][k] = v['text'] )
|
|
28
|
+
else nestedData[level] = theData['text']
|
|
29
|
+
|
|
30
|
+
// Publish up: replace matching breadcrumb values on every level above
|
|
31
|
+
const check = ({ value, breadcrumbs }) => nestedData[level][breadcrumbs] ? nestedData[level][breadcrumbs] : value
|
|
32
|
+
for ( let i = level - 1; i >= 0; i-- ) {
|
|
33
|
+
nestedData[i] = walk ({ data: nestedData[i], objectCallback: check })
|
|
16
34
|
}
|
|
17
|
-
function check({ value, breadcrumbs }) {
|
|
18
|
-
if (nestedData[level][breadcrumbs]) return nestedData[level][breadcrumbs]
|
|
19
|
-
return value
|
|
20
|
-
} // check func.
|
|
21
35
|
break
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (x == null) return
|
|
27
|
-
if (xType === 'object') theData[0] += `${x.text}`
|
|
28
|
-
else theData[0] += `${x}`
|
|
29
|
-
theData.toSpliced(i, 1)
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
let xxType = _defineDataType(x);
|
|
33
|
-
theData[0] = ''
|
|
34
|
-
if (xxType === null) return
|
|
35
|
-
else if (xxType === 'object') theData[0] = `${x.text}`
|
|
36
|
-
else theData[0] = `${x}`
|
|
37
|
-
}
|
|
38
|
-
}) // forEach theData
|
|
36
|
+
}
|
|
37
|
+
case 'array': {
|
|
38
|
+
const asText = ( x ) => ( _defineDataType ( x ) === 'object' ) ? `${x.text}` : `${x}`
|
|
39
|
+
theData[0] = theData.map ( x => ( x == null ) ? '' : asText ( x )).join ( '' )
|
|
39
40
|
theData.length = 1
|
|
40
41
|
break
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
let val = helpers[name]({ data: theData, ...extendArguments, full: theData, useHelper: localUseHelper }); // 'full: d' in build.js, here 'theData'
|
|
47
|
-
let valType = _defineDataType(val);
|
|
42
|
+
}
|
|
43
|
+
} // switch dataType
|
|
44
|
+
}
|
|
45
|
+
else { // Named mixing action - the helper produces the merged value
|
|
46
|
+
const val = helpers[name] ({ data: theData, ...extendArguments, full: theData, useHelper: useHelper ( theData ) })
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
} // switch valType
|
|
48
|
+
theData.length = 0
|
|
49
|
+
switch ( _defineDataType ( val )) {
|
|
50
|
+
case 'primitive':
|
|
51
|
+
theData[0] = val
|
|
52
|
+
break
|
|
53
|
+
case 'array':
|
|
54
|
+
theData.push ( ...val )
|
|
55
|
+
break
|
|
56
|
+
} // switch valType
|
|
59
57
|
}
|
|
60
58
|
} // actionMix func.
|
|
61
59
|
|
|
@@ -1,86 +1,54 @@
|
|
|
1
1
|
import _defineDataType from "./_defineType.js"
|
|
2
2
|
import render from "./render.js"
|
|
3
3
|
|
|
4
|
-
function actionRender({ name }, levelData, { helpers, original, dependencies, useHelper, extendArguments, nestedData, level, iData }) {
|
|
5
|
-
/**
|
|
6
|
-
* logic from build.js 'render' case
|
|
7
|
-
* levelData is the array we are iterating (nestedData[level] or similar)
|
|
8
|
-
* But wait, build.js iterates levelData.
|
|
9
|
-
* "levelData.forEach((theData, iData) => {"
|
|
10
|
-
* So actionRender receives a SINGLE item?
|
|
11
|
-
* No, existing logic handles 'array' dataType inside the switch.
|
|
12
|
-
* But the loop inside build.js ALREADY iterates levelData.
|
|
13
|
-
* Line 276: `levelData.forEach((theData, iData) => { ... switch(type) ... })`
|
|
14
|
-
* So 'theData' is a single item from the level.
|
|
15
|
-
* BUT 'dataType' switch inside handles 'array'?
|
|
16
|
-
* _defineDataType(theData).
|
|
17
|
-
* If 'theData' is array, it iterates it.
|
|
18
|
-
* Yes.
|
|
19
|
-
*/
|
|
20
4
|
|
|
21
|
-
const theData = levelData
|
|
22
|
-
let dataType = _defineDataType(theData)
|
|
23
|
-
const isRenderFunction = typeof helpers[name] === 'function';
|
|
24
5
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Action 'render'. Renders the current data item with the named helper and
|
|
8
|
+
* writes the result back into the data slice.
|
|
9
|
+
*
|
|
10
|
+
* Write-back rules:
|
|
11
|
+
* - primitive results replace the data item;
|
|
12
|
+
* - object data receives the result as its 'text' property;
|
|
13
|
+
* - a null result marks the item as null, so later steps can skip it.
|
|
14
|
+
*
|
|
15
|
+
* @param {object} step - Action step: { name } is the helper name
|
|
16
|
+
* @param {any} theData - Current data item from the level slice
|
|
17
|
+
* @param {object} context - Execution context (see executeActions.js)
|
|
18
|
+
*/
|
|
19
|
+
function actionRender ({ name }, theData, { helpers, original, dependencies, useHelper, extendArguments, nestedData, level }) {
|
|
20
|
+
const
|
|
21
|
+
dataType = _defineDataType ( theData )
|
|
22
|
+
, isRenderFunction = typeof helpers[name] === 'function'
|
|
23
|
+
, callHelper = ( data, full ) => helpers[name] ({ data, ...extendArguments, full, useHelper: useHelper ( data ) })
|
|
24
|
+
;
|
|
43
25
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
, text = render(d, name, helpers, original, dependencies)
|
|
55
|
-
;
|
|
56
|
-
if (text == null) theData[i] = null
|
|
57
|
-
else if (dType === 'object') d['text'] = text
|
|
58
|
-
else theData[i] = text
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
break
|
|
26
|
+
switch ( dataType ) {
|
|
27
|
+
case 'array':
|
|
28
|
+
theData.forEach ( ( d, i ) => {
|
|
29
|
+
if ( d == null ) return
|
|
30
|
+
const text = isRenderFunction ? callHelper ( d, original ) : render ( d, name, helpers, original, dependencies )
|
|
31
|
+
if ( text == null ) theData[i] = null
|
|
32
|
+
else if ( _defineDataType ( d ) === 'object' ) d['text'] = text
|
|
33
|
+
else theData[i] = text
|
|
34
|
+
})
|
|
35
|
+
break
|
|
62
36
|
case 'function':
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
nestedData[level] = helpers[name]({ data: fD, ...extendArguments, full: theData, useHelper: useHelperFn })
|
|
66
|
-
break
|
|
37
|
+
nestedData[level] = callHelper ( theData (), theData )
|
|
38
|
+
break
|
|
67
39
|
case 'primitive':
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
else nestedData[level] = render(theData, name, helpers, original, dependencies)
|
|
73
|
-
break
|
|
40
|
+
if ( isRenderFunction ) nestedData[level] = callHelper ( theData, theData )
|
|
41
|
+
else nestedData[level] = render ( theData, name, helpers, original, dependencies )
|
|
42
|
+
break
|
|
74
43
|
case 'object':
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
break
|
|
83
|
-
} // switch renderDataType
|
|
84
|
-
}
|
|
44
|
+
if ( isRenderFunction ) theData['text'] = callHelper ( theData, theData )
|
|
45
|
+
else theData['text'] = render ( theData, name, helpers, original, dependencies )
|
|
46
|
+
break
|
|
47
|
+
} // switch dataType
|
|
48
|
+
} // actionRender func.
|
|
49
|
+
|
|
50
|
+
|
|
85
51
|
|
|
86
52
|
export default actionRender
|
|
53
|
+
|
|
54
|
+
|