@calcit/procs 0.8.34 → 0.8.36
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/lib/calcit.procs.mjs +6 -1
- package/lib/custom-formatter.mjs +144 -65
- package/lib/js-cirru.mjs +7 -7
- package/lib/js-list.mjs +15 -0
- package/lib/js-map.mjs +18 -1
- package/lib/js-primes.mjs +1 -1
- package/lib/js-tuple.mjs +0 -1
- package/lib/package.json +1 -1
- package/package.json +1 -1
- package/ts-src/calcit.procs.mts +5 -1
- package/ts-src/custom-formatter.mts +191 -66
- package/ts-src/js-cirru.mts +7 -7
- package/ts-src/js-list.mts +15 -1
- package/ts-src/js-map.mts +20 -2
- package/ts-src/js-primes.mts +1 -1
- package/ts-src/js-tuple.mts +0 -1
package/lib/calcit.procs.mjs
CHANGED
|
@@ -130,7 +130,12 @@ export let peekDefatom = (path) => {
|
|
|
130
130
|
return refsRegistry.get(path);
|
|
131
131
|
};
|
|
132
132
|
export let _$n_atom_$o_deref = (x) => {
|
|
133
|
-
|
|
133
|
+
if (x instanceof CalcitRef) {
|
|
134
|
+
return x.value;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
throw new Error("Expected CalcitRef");
|
|
138
|
+
}
|
|
134
139
|
};
|
|
135
140
|
export let _$n__ADD_ = (x, y) => {
|
|
136
141
|
return x + y;
|
package/lib/custom-formatter.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isLiteral } from "./js-primes.mjs";
|
|
1
2
|
import { CalcitRef, CalcitSymbol, CalcitTag } from "./calcit-data.mjs";
|
|
2
3
|
import { CalcitRecord } from "./js-record.mjs";
|
|
3
4
|
import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
|
|
@@ -16,11 +17,63 @@ let embedObject = (x) => {
|
|
|
16
17
|
},
|
|
17
18
|
];
|
|
18
19
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
/** camel case to kabab case */
|
|
21
|
+
let kabab = (s) => {
|
|
22
|
+
return s.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
|
|
23
|
+
};
|
|
24
|
+
/** returns {style: "..."} */
|
|
25
|
+
let styles = (o) => {
|
|
26
|
+
let styleCode = "";
|
|
27
|
+
let keys = Object.keys(o);
|
|
28
|
+
for (let idx = 0; idx < keys.length; idx++) {
|
|
29
|
+
let key = keys[idx];
|
|
30
|
+
let value = o[key];
|
|
31
|
+
if (value) {
|
|
32
|
+
styleCode += `${kabab(key)}:${value};`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
style: styleCode,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
let hsl = (/** 0~360 */ h, /** 0~100 */ s, /** 0~100 */ l, /** 0~1 */ a) => {
|
|
40
|
+
if (a != null) {
|
|
41
|
+
return `hsla(${h}, ${s}%, ${l}%, ${a})`;
|
|
42
|
+
}
|
|
43
|
+
return `hsl(${h}, ${s}%, ${l}%)`;
|
|
44
|
+
};
|
|
45
|
+
/** create element */
|
|
46
|
+
let div = (style, ...children) => {
|
|
47
|
+
return ["div", styles(style), ...children];
|
|
48
|
+
};
|
|
49
|
+
let span = (style, ...children) => {
|
|
50
|
+
return ["span", styles(style), ...children];
|
|
51
|
+
};
|
|
52
|
+
let table = (style, ...children) => {
|
|
53
|
+
return ["table", styles(style), ...children];
|
|
54
|
+
};
|
|
55
|
+
let tr = (style, ...children) => {
|
|
56
|
+
return ["tr", styles(style), ...children];
|
|
57
|
+
};
|
|
58
|
+
let td = (style, ...children) => {
|
|
59
|
+
return ["td", styles(style), ...children];
|
|
60
|
+
};
|
|
61
|
+
/** handle null value in nested data */
|
|
62
|
+
let saveString = (v) => {
|
|
63
|
+
if (typeof v === "string") {
|
|
64
|
+
if (v.match(/[\s\"\n\t\,]/)) {
|
|
65
|
+
return `"|${v}"`;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
return `|${v}`;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else if (v != null && v.toString) {
|
|
72
|
+
return v.toString();
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
return "nil";
|
|
22
76
|
}
|
|
23
|
-
return x;
|
|
24
77
|
};
|
|
25
78
|
export let load_console_formatter_$x_ = () => {
|
|
26
79
|
if (typeof window === "object") {
|
|
@@ -28,107 +81,127 @@ export let load_console_formatter_$x_ = () => {
|
|
|
28
81
|
{
|
|
29
82
|
header: (obj, config) => {
|
|
30
83
|
if (obj instanceof CalcitTag) {
|
|
31
|
-
return
|
|
84
|
+
return div({ color: hsl(240, 80, 60) }, obj.toString());
|
|
32
85
|
}
|
|
33
86
|
if (obj instanceof CalcitSymbol) {
|
|
34
|
-
return
|
|
87
|
+
return div({ color: hsl(240, 80, 60) }, obj.toString());
|
|
35
88
|
}
|
|
36
89
|
if (obj instanceof CalcitList || obj instanceof CalcitSliceList) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
90
|
+
let preview = "";
|
|
91
|
+
let hasCollection = false;
|
|
92
|
+
for (let idx = 0; idx < obj.len(); idx++) {
|
|
93
|
+
preview += " ";
|
|
94
|
+
if (isLiteral(obj.get(idx))) {
|
|
95
|
+
preview += saveString(obj.get(idx));
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
preview += "..";
|
|
99
|
+
hasCollection = true;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return div({
|
|
104
|
+
color: hasCollection ? hsl(280, 80, 60, 0.4) : null,
|
|
105
|
+
}, `[]`, span({
|
|
106
|
+
fontSize: "8px",
|
|
107
|
+
verticalAlign: "middle",
|
|
108
|
+
color: hsl(280, 80, 80, 0.8),
|
|
109
|
+
}, `${obj.len()}`), " ", preview);
|
|
43
110
|
}
|
|
44
111
|
if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
|
|
45
|
-
|
|
112
|
+
let preview = "";
|
|
113
|
+
let hasCollection = false;
|
|
114
|
+
for (let [k, v] of obj.pairs()) {
|
|
115
|
+
preview += " ";
|
|
116
|
+
if (isLiteral(k) && isLiteral(v)) {
|
|
117
|
+
preview += `(${saveString(k)} ${saveString(v)})`;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
preview += "..";
|
|
121
|
+
hasCollection = true;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return div({ color: hasCollection ? hsl(280, 80, 60, 0.4) : undefined }, "{}", preview);
|
|
46
126
|
}
|
|
47
127
|
if (obj instanceof CalcitSet) {
|
|
48
|
-
return
|
|
128
|
+
return div({ color: hsl(280, 80, 60, 0.4) }, obj.toString(true));
|
|
49
129
|
}
|
|
50
130
|
if (obj instanceof CalcitRecord) {
|
|
51
|
-
let ret =
|
|
52
|
-
for (let idx = 0; idx < obj.fields.length; idx++) {
|
|
53
|
-
ret.push([
|
|
54
|
-
"div",
|
|
55
|
-
{ style: "margin-left: 8px;" },
|
|
56
|
-
["div", { style: "margin-left: 8px; display: inline-block;" }, embedObject(obj.fields[idx])],
|
|
57
|
-
["div", { style: "margin-left: 8px; display: inline-block;" }, embedObject(obj.values[idx])],
|
|
58
|
-
]);
|
|
59
|
-
}
|
|
131
|
+
let ret = div({ color: hsl(280, 80, 60, 0.4) }, `%{} ${obj.name} ...`);
|
|
60
132
|
return ret;
|
|
61
133
|
}
|
|
62
134
|
if (obj instanceof CalcitTuple) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
135
|
+
if (obj.klass) {
|
|
136
|
+
let ret = div({}, div({ display: "inline-block", color: hsl(300, 100, 40) }, "%::"), div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.klass)), div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.tag)));
|
|
137
|
+
for (let idx = 0; idx < obj.extra.length; idx++) {
|
|
138
|
+
ret.push(div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.extra[idx])));
|
|
139
|
+
}
|
|
140
|
+
return ret;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
let ret = div({}, div({ display: "inline-block", color: hsl(300, 100, 40) }, "::"), div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.tag)));
|
|
144
|
+
for (let idx = 0; idx < obj.extra.length; idx++) {
|
|
145
|
+
ret.push(div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.extra[idx])));
|
|
146
|
+
}
|
|
147
|
+
return ret;
|
|
68
148
|
}
|
|
69
|
-
return ret;
|
|
70
149
|
}
|
|
71
150
|
if (obj instanceof CalcitRef) {
|
|
72
|
-
return
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
`Ref ${obj.path}`,
|
|
76
|
-
["div", { style: "color: hsl(280, 80%, 60%)" }, ["div", { style: "margin-left: 8px;" }, embedObject(obj.value)]],
|
|
77
|
-
];
|
|
151
|
+
return div({
|
|
152
|
+
color: hsl(280, 80, 60),
|
|
153
|
+
}, `Ref ${obj.path}`, div({ color: hsl(280, 80, 60) }, div({ marginLeft: "8px" }, embedObject(obj.value))));
|
|
78
154
|
}
|
|
79
155
|
if (obj instanceof CalcitCirruQuote) {
|
|
80
|
-
return
|
|
81
|
-
"div",
|
|
82
|
-
{ style: "color: hsl(240, 80%, 60%); display: flex;" },
|
|
83
|
-
`CirruQuote`,
|
|
84
|
-
[
|
|
85
|
-
"div",
|
|
86
|
-
{ style: "color: hsl(280, 80%, 60%); padding: 4px 4px; margin: 0 4px 2px; border: 1px solid hsl(0,70%,90%); border-radius: 4px;" },
|
|
87
|
-
obj.textForm().trim(),
|
|
88
|
-
],
|
|
89
|
-
];
|
|
156
|
+
return div({ color: hsl(280, 80, 60), display: "flex" }, `CirruQuote`, div({ color: hsl(280, 80, 60), padding: "4px 4px", margin: "0 4px 2px", border: "1px solid hsl(0,70%,90%)", borderRadius: "4px" }, obj.textForm().trim()));
|
|
90
157
|
}
|
|
91
158
|
return null;
|
|
92
159
|
},
|
|
93
160
|
hasBody: (obj) => {
|
|
94
161
|
if (obj instanceof CalcitList || obj instanceof CalcitSliceList) {
|
|
95
|
-
|
|
162
|
+
let hasCollection = obj.nestedDataInChildren();
|
|
163
|
+
return obj.len() > 0 && hasCollection;
|
|
96
164
|
}
|
|
97
165
|
if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
|
|
98
|
-
|
|
166
|
+
let hasCollection = obj.nestedDataInChildren();
|
|
167
|
+
return obj.len() > 0 && hasCollection;
|
|
99
168
|
}
|
|
100
169
|
if (obj instanceof CalcitSet) {
|
|
101
170
|
return obj.len() > 0;
|
|
102
171
|
}
|
|
172
|
+
if (obj instanceof CalcitRecord) {
|
|
173
|
+
return obj.fields.length > 0;
|
|
174
|
+
}
|
|
103
175
|
return false;
|
|
104
176
|
},
|
|
105
177
|
body: (obj, config) => {
|
|
106
178
|
if (obj instanceof CalcitList || obj instanceof CalcitSliceList) {
|
|
107
179
|
let flexMode = obj.len() > 40 ? "inline-flex" : "flex";
|
|
108
|
-
return
|
|
109
|
-
return
|
|
110
|
-
"
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
180
|
+
return div({ color: hsl(280, 80, 60), borderLeft: "1px solid #eee" }, ...obj.toArray().map((x, idx) => {
|
|
181
|
+
return div({ marginLeft: "8px", display: flexMode, paddingRight: "16px" }, span({
|
|
182
|
+
fontFamily: "monospace",
|
|
183
|
+
marginRight: "8px",
|
|
184
|
+
color: hsl(280, 80, 90),
|
|
185
|
+
flexShrink: 0,
|
|
186
|
+
fontSize: "10px",
|
|
187
|
+
}, idx), embedObject(x));
|
|
115
188
|
}));
|
|
116
189
|
}
|
|
117
190
|
if (obj instanceof CalcitSet) {
|
|
118
|
-
let ret =
|
|
191
|
+
let ret = div({ color: hsl(280, 80, 60), borderLeft: "1px solid #eee" });
|
|
119
192
|
let values = obj.values();
|
|
120
193
|
for (let idx = 0; idx < values.length; idx++) {
|
|
121
194
|
let x = values[idx];
|
|
122
|
-
ret.push(
|
|
195
|
+
ret.push(div({ marginLeft: "8px", display: "inline-block" }, embedObject(x)));
|
|
123
196
|
}
|
|
124
197
|
return ret;
|
|
125
198
|
}
|
|
126
199
|
if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
|
|
127
|
-
let ret =
|
|
200
|
+
let ret = table({ color: hsl(280, 80, 60), borderLeft: "1px solid #eee" });
|
|
128
201
|
let pairs = obj.pairs();
|
|
129
202
|
pairs.sort((pa, pb) => {
|
|
130
|
-
let ka = pa[0]
|
|
131
|
-
let kb = pb[0]
|
|
203
|
+
let ka = saveString(pa[0]);
|
|
204
|
+
let kb = saveString(pb[0]);
|
|
132
205
|
if (ka < kb) {
|
|
133
206
|
return -1;
|
|
134
207
|
}
|
|
@@ -141,12 +214,18 @@ export let load_console_formatter_$x_ = () => {
|
|
|
141
214
|
});
|
|
142
215
|
for (let idx = 0; idx < pairs.length; idx++) {
|
|
143
216
|
let [k, v] = pairs[idx];
|
|
144
|
-
ret.push(
|
|
145
|
-
"
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
217
|
+
ret.push(tr({
|
|
218
|
+
marginLeft: "8px",
|
|
219
|
+
}, td({ marginLeft: "8px", verticalAlign: "top" }, embedObject(k)), td({ marginLeft: "8px" }, embedObject(v))));
|
|
220
|
+
}
|
|
221
|
+
return ret;
|
|
222
|
+
}
|
|
223
|
+
if (obj instanceof CalcitRecord) {
|
|
224
|
+
let ret = table({ color: hsl(280, 80, 60), borderLeft: "1px solid #eee" });
|
|
225
|
+
for (let idx = 0; idx < obj.fields.length; idx++) {
|
|
226
|
+
ret.push(tr({
|
|
227
|
+
marginLeft: "8px",
|
|
228
|
+
}, td({ marginLeft: "8px", verticalAlign: "top" }, embedObject(obj.fields[idx])), td({ marginLeft: "8px" }, embedObject(obj.values[idx]))));
|
|
150
229
|
}
|
|
151
230
|
return ret;
|
|
152
231
|
}
|
package/lib/js-cirru.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { writeCirruCode } from "@cirru/writer.ts";
|
|
2
|
-
import {
|
|
2
|
+
import { isLiteral, _$n_compare } from "./js-primes.mjs";
|
|
3
3
|
import { CalcitList, CalcitSliceList } from "./js-list.mjs";
|
|
4
4
|
import { CalcitRecord } from "./js-record.mjs";
|
|
5
5
|
import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
|
|
@@ -94,10 +94,10 @@ export let to_cirru_edn = (x) => {
|
|
|
94
94
|
pairs_buffer.push(pairs[idx]);
|
|
95
95
|
}
|
|
96
96
|
pairs_buffer.sort((a, b) => {
|
|
97
|
-
let a0_literal =
|
|
98
|
-
let a1_literal =
|
|
99
|
-
let b0_literal =
|
|
100
|
-
let b1_literal =
|
|
97
|
+
let a0_literal = isLiteral(a[0]);
|
|
98
|
+
let a1_literal = isLiteral(a[1]);
|
|
99
|
+
let b0_literal = isLiteral(b[0]);
|
|
100
|
+
let b1_literal = isLiteral(b[1]);
|
|
101
101
|
if (a0_literal && b0_literal) {
|
|
102
102
|
if (a1_literal && !b1_literal) {
|
|
103
103
|
return -1;
|
|
@@ -132,8 +132,8 @@ export let to_cirru_edn = (x) => {
|
|
|
132
132
|
}
|
|
133
133
|
// placed literals first
|
|
134
134
|
buffer.sort((a, b) => {
|
|
135
|
-
let a1_literal =
|
|
136
|
-
let b1_literal =
|
|
135
|
+
let a1_literal = isLiteral(a[1]);
|
|
136
|
+
let b1_literal = isLiteral(b[1]);
|
|
137
137
|
if (a1_literal && !b1_literal) {
|
|
138
138
|
return -1;
|
|
139
139
|
}
|
package/lib/js-list.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as ternaryTree from "@calcit/ternary-tree";
|
|
2
|
+
import { isLiteral } from "./js-primes.mjs";
|
|
2
3
|
import { initTernaryTreeList, initTernaryTreeListFromRange, listLen, listGet, assocList, listToItems, dissocList, assocBefore, assocAfter, } from "@calcit/ternary-tree";
|
|
3
4
|
import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
|
|
4
5
|
import { CalcitSet } from "./js-set.mjs";
|
|
@@ -90,6 +91,13 @@ export class CalcitList {
|
|
|
90
91
|
reverse() {
|
|
91
92
|
return new CalcitList(ternaryTree.reverse(this.value));
|
|
92
93
|
}
|
|
94
|
+
nestedDataInChildren() {
|
|
95
|
+
for (let idx = 0; idx < this.len(); idx++) {
|
|
96
|
+
if (!isLiteral(this.get(idx))) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
93
101
|
}
|
|
94
102
|
// represent append-only immutable list in Array slices
|
|
95
103
|
export class CalcitSliceList {
|
|
@@ -238,6 +246,13 @@ export class CalcitSliceList {
|
|
|
238
246
|
reverse() {
|
|
239
247
|
return this.turnListMode().reverse();
|
|
240
248
|
}
|
|
249
|
+
nestedDataInChildren() {
|
|
250
|
+
for (let idx = 0; idx < this.len(); idx++) {
|
|
251
|
+
if (!isLiteral(this.get(idx))) {
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
241
256
|
}
|
|
242
257
|
function* sliceGenerator(xs, start, end) {
|
|
243
258
|
if (xs == null) {
|
package/lib/js-map.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as ternaryTree from "@calcit/ternary-tree";
|
|
2
|
+
import { isLiteral } from "./js-primes.mjs";
|
|
2
3
|
import { CalcitSet } from "./js-set.mjs";
|
|
3
4
|
import { mapLen, assocMap, dissocMap, isMapEmpty, toPairsArray, mapGetDefault, initEmptyTernaryTreeMap, initTernaryTreeMapFromArray, } from "@calcit/ternary-tree";
|
|
4
5
|
import { isNestedCalcitData, tipNestedCalcitData, toString } from "./calcit-data.mjs";
|
|
@@ -152,8 +153,16 @@ export class CalcitMap {
|
|
|
152
153
|
}
|
|
153
154
|
return new CalcitSet(ret);
|
|
154
155
|
}
|
|
156
|
+
/** detecthing in custom formatter */
|
|
157
|
+
nestedDataInChildren() {
|
|
158
|
+
for (let [k, v] of this.pairs()) {
|
|
159
|
+
if (!isLiteral(k) || !isLiteral(v)) {
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
155
164
|
}
|
|
156
|
-
|
|
165
|
+
/* store small map in linear array to reduce cost of building tree */
|
|
157
166
|
export class CalcitSliceMap {
|
|
158
167
|
constructor(value) {
|
|
159
168
|
if (value == null) {
|
|
@@ -345,4 +354,12 @@ export class CalcitSliceMap {
|
|
|
345
354
|
}
|
|
346
355
|
return new CalcitSet(ret);
|
|
347
356
|
}
|
|
357
|
+
/** detecthing in custom formatter */
|
|
358
|
+
nestedDataInChildren() {
|
|
359
|
+
for (let [k, v] of this.pairs()) {
|
|
360
|
+
if (!isLiteral(k) || !isLiteral(v)) {
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
348
365
|
}
|
package/lib/js-primes.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
|
|
|
5
5
|
import { CalcitSet as CalcitSet } from "./js-set.mjs";
|
|
6
6
|
import { CalcitTuple } from "./js-tuple.mjs";
|
|
7
7
|
import { CalcitCirruQuote } from "./js-cirru.mjs";
|
|
8
|
-
export let
|
|
8
|
+
export let isLiteral = (x) => {
|
|
9
9
|
if (x == null)
|
|
10
10
|
return true;
|
|
11
11
|
if (typeof x == "string")
|
package/lib/js-tuple.mjs
CHANGED
package/lib/package.json
CHANGED
package/package.json
CHANGED
package/ts-src/calcit.procs.mts
CHANGED
|
@@ -161,7 +161,11 @@ export let peekDefatom = (path: string): CalcitRef => {
|
|
|
161
161
|
};
|
|
162
162
|
|
|
163
163
|
export let _$n_atom_$o_deref = (x: CalcitRef): CalcitValue => {
|
|
164
|
-
|
|
164
|
+
if (x instanceof CalcitRef) {
|
|
165
|
+
return x.value;
|
|
166
|
+
} else {
|
|
167
|
+
throw new Error("Expected CalcitRef");
|
|
168
|
+
}
|
|
165
169
|
};
|
|
166
170
|
|
|
167
171
|
export let _$n__ADD_ = (x: number, y: number): number => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CalcitValue } from "./js-primes.mjs";
|
|
1
|
+
import { CalcitValue, isLiteral } from "./js-primes.mjs";
|
|
2
2
|
import { CalcitRef, CalcitSymbol, CalcitTag } from "./calcit-data.mjs";
|
|
3
3
|
|
|
4
4
|
import { CalcitRecord } from "./js-record.mjs";
|
|
@@ -30,11 +30,64 @@ let embedObject = (x: CalcitValue) => {
|
|
|
30
30
|
];
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
/** camel case to kabab case */
|
|
34
|
+
let kabab = (s: string) => {
|
|
35
|
+
return s.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** returns {style: "..."} */
|
|
39
|
+
let styles = (o: any) => {
|
|
40
|
+
let styleCode = "";
|
|
41
|
+
let keys = Object.keys(o);
|
|
42
|
+
for (let idx = 0; idx < keys.length; idx++) {
|
|
43
|
+
let key = keys[idx];
|
|
44
|
+
let value = (o as any)[key];
|
|
45
|
+
if (value) {
|
|
46
|
+
styleCode += `${kabab(key)}:${value};`;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
style: styleCode,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
let hsl = (/** 0~360 */ h: number, /** 0~100 */ s: number, /** 0~100 */ l: number, /** 0~1 */ a?: number) => {
|
|
55
|
+
if (a != null) {
|
|
56
|
+
return `hsla(${h}, ${s}%, ${l}%, ${a})`;
|
|
57
|
+
}
|
|
58
|
+
return `hsl(${h}, ${s}%, ${l}%)`;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/** create element */
|
|
62
|
+
let div = (style: any, ...children: any[]) => {
|
|
63
|
+
return ["div", styles(style), ...children];
|
|
64
|
+
};
|
|
65
|
+
let span = (style: any, ...children: any[]) => {
|
|
66
|
+
return ["span", styles(style), ...children];
|
|
67
|
+
};
|
|
68
|
+
let table = (style: any, ...children: any[]) => {
|
|
69
|
+
return ["table", styles(style), ...children];
|
|
70
|
+
};
|
|
71
|
+
let tr = (style: any, ...children: any[]) => {
|
|
72
|
+
return ["tr", styles(style), ...children];
|
|
73
|
+
};
|
|
74
|
+
let td = (style: any, ...children: any[]) => {
|
|
75
|
+
return ["td", styles(style), ...children];
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** handle null value in nested data */
|
|
79
|
+
let saveString = (v: CalcitValue) => {
|
|
80
|
+
if (typeof v === "string") {
|
|
81
|
+
if (v.match(/[\s\"\n\t\,]/)) {
|
|
82
|
+
return `"|${v}"`;
|
|
83
|
+
} else {
|
|
84
|
+
return `|${v}`;
|
|
85
|
+
}
|
|
86
|
+
} else if (v != null && v.toString) {
|
|
87
|
+
return v.toString();
|
|
88
|
+
} else {
|
|
89
|
+
return "nil";
|
|
36
90
|
}
|
|
37
|
-
return x;
|
|
38
91
|
};
|
|
39
92
|
|
|
40
93
|
export let load_console_formatter_$x_ = () => {
|
|
@@ -43,109 +96,163 @@ export let load_console_formatter_$x_ = () => {
|
|
|
43
96
|
{
|
|
44
97
|
header: (obj, config) => {
|
|
45
98
|
if (obj instanceof CalcitTag) {
|
|
46
|
-
return
|
|
99
|
+
return div({ color: hsl(240, 80, 60) }, obj.toString());
|
|
47
100
|
}
|
|
48
101
|
if (obj instanceof CalcitSymbol) {
|
|
49
|
-
return
|
|
102
|
+
return div({ color: hsl(240, 80, 60) }, obj.toString());
|
|
50
103
|
}
|
|
51
104
|
if (obj instanceof CalcitList || obj instanceof CalcitSliceList) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
105
|
+
let preview = "";
|
|
106
|
+
let hasCollection = false;
|
|
107
|
+
for (let idx = 0; idx < obj.len(); idx++) {
|
|
108
|
+
preview += " ";
|
|
109
|
+
if (isLiteral(obj.get(idx))) {
|
|
110
|
+
preview += saveString(obj.get(idx));
|
|
111
|
+
} else {
|
|
112
|
+
preview += "..";
|
|
113
|
+
hasCollection = true;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return div(
|
|
118
|
+
{
|
|
119
|
+
color: hasCollection ? hsl(280, 80, 60, 0.4) : null,
|
|
120
|
+
},
|
|
121
|
+
`[]`,
|
|
122
|
+
span(
|
|
123
|
+
{
|
|
124
|
+
fontSize: "8px",
|
|
125
|
+
verticalAlign: "middle",
|
|
126
|
+
color: hsl(280, 80, 80, 0.8),
|
|
127
|
+
},
|
|
128
|
+
`${obj.len()}`
|
|
129
|
+
),
|
|
130
|
+
" ",
|
|
131
|
+
preview
|
|
132
|
+
);
|
|
58
133
|
}
|
|
59
134
|
if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
|
|
60
|
-
|
|
135
|
+
let preview = "";
|
|
136
|
+
let hasCollection = false;
|
|
137
|
+
for (let [k, v] of obj.pairs()) {
|
|
138
|
+
preview += " ";
|
|
139
|
+
if (isLiteral(k) && isLiteral(v)) {
|
|
140
|
+
preview += `(${saveString(k)} ${saveString(v)})`;
|
|
141
|
+
} else {
|
|
142
|
+
preview += "..";
|
|
143
|
+
hasCollection = true;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return div({ color: hasCollection ? hsl(280, 80, 60, 0.4) : undefined }, "{}", preview);
|
|
61
148
|
}
|
|
62
149
|
if (obj instanceof CalcitSet) {
|
|
63
|
-
return
|
|
150
|
+
return div({ color: hsl(280, 80, 60, 0.4) }, obj.toString(true));
|
|
64
151
|
}
|
|
65
152
|
if (obj instanceof CalcitRecord) {
|
|
66
|
-
let ret: any[] =
|
|
67
|
-
for (let idx = 0; idx < obj.fields.length; idx++) {
|
|
68
|
-
ret.push([
|
|
69
|
-
"div",
|
|
70
|
-
{ style: "margin-left: 8px;" },
|
|
71
|
-
["div", { style: "margin-left: 8px; display: inline-block;" }, embedObject(obj.fields[idx])],
|
|
72
|
-
["div", { style: "margin-left: 8px; display: inline-block;" }, embedObject(obj.values[idx])],
|
|
73
|
-
]);
|
|
74
|
-
}
|
|
153
|
+
let ret: any[] = div({ color: hsl(280, 80, 60, 0.4) }, `%{} ${obj.name} ...`);
|
|
75
154
|
return ret;
|
|
76
155
|
}
|
|
77
156
|
if (obj instanceof CalcitTuple) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
157
|
+
if (obj.klass) {
|
|
158
|
+
let ret: any[] = div(
|
|
159
|
+
{},
|
|
160
|
+
div({ display: "inline-block", color: hsl(300, 100, 40) }, "%::"),
|
|
161
|
+
div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.klass)),
|
|
162
|
+
div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.tag))
|
|
163
|
+
);
|
|
164
|
+
for (let idx = 0; idx < obj.extra.length; idx++) {
|
|
165
|
+
ret.push(div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.extra[idx])));
|
|
166
|
+
}
|
|
167
|
+
return ret;
|
|
168
|
+
} else {
|
|
169
|
+
let ret: any[] = div(
|
|
170
|
+
{},
|
|
171
|
+
div({ display: "inline-block", color: hsl(300, 100, 40) }, "::"),
|
|
172
|
+
div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.tag))
|
|
173
|
+
);
|
|
174
|
+
for (let idx = 0; idx < obj.extra.length; idx++) {
|
|
175
|
+
ret.push(div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.extra[idx])));
|
|
176
|
+
}
|
|
177
|
+
return ret;
|
|
83
178
|
}
|
|
84
|
-
return ret;
|
|
85
179
|
}
|
|
86
180
|
if (obj instanceof CalcitRef) {
|
|
87
|
-
return
|
|
88
|
-
|
|
89
|
-
|
|
181
|
+
return div(
|
|
182
|
+
{
|
|
183
|
+
color: hsl(280, 80, 60),
|
|
184
|
+
},
|
|
90
185
|
`Ref ${obj.path}`,
|
|
91
|
-
|
|
92
|
-
|
|
186
|
+
div({ color: hsl(280, 80, 60) }, div({ marginLeft: "8px" }, embedObject(obj.value)))
|
|
187
|
+
);
|
|
93
188
|
}
|
|
94
189
|
if (obj instanceof CalcitCirruQuote) {
|
|
95
|
-
return
|
|
96
|
-
"
|
|
97
|
-
{ style: "color: hsl(240, 80%, 60%); display: flex;" },
|
|
190
|
+
return div(
|
|
191
|
+
{ color: hsl(280, 80, 60), display: "flex" },
|
|
98
192
|
`CirruQuote`,
|
|
99
|
-
|
|
100
|
-
"
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
];
|
|
193
|
+
div(
|
|
194
|
+
{ color: hsl(280, 80, 60), padding: "4px 4px", margin: "0 4px 2px", border: "1px solid hsl(0,70%,90%)", borderRadius: "4px" },
|
|
195
|
+
obj.textForm().trim()
|
|
196
|
+
)
|
|
197
|
+
);
|
|
105
198
|
}
|
|
106
199
|
return null;
|
|
107
200
|
},
|
|
108
201
|
hasBody: (obj) => {
|
|
109
202
|
if (obj instanceof CalcitList || obj instanceof CalcitSliceList) {
|
|
110
|
-
|
|
203
|
+
let hasCollection = obj.nestedDataInChildren();
|
|
204
|
+
return obj.len() > 0 && hasCollection;
|
|
111
205
|
}
|
|
112
206
|
if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
|
|
113
|
-
|
|
207
|
+
let hasCollection = obj.nestedDataInChildren();
|
|
208
|
+
return obj.len() > 0 && hasCollection;
|
|
114
209
|
}
|
|
115
210
|
if (obj instanceof CalcitSet) {
|
|
116
211
|
return obj.len() > 0;
|
|
117
212
|
}
|
|
213
|
+
if (obj instanceof CalcitRecord) {
|
|
214
|
+
return obj.fields.length > 0;
|
|
215
|
+
}
|
|
118
216
|
return false;
|
|
119
217
|
},
|
|
120
218
|
body: (obj, config) => {
|
|
121
219
|
if (obj instanceof CalcitList || obj instanceof CalcitSliceList) {
|
|
122
220
|
let flexMode = obj.len() > 40 ? "inline-flex" : "flex";
|
|
123
|
-
return
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
{
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
221
|
+
return div(
|
|
222
|
+
{ color: hsl(280, 80, 60), borderLeft: "1px solid #eee" },
|
|
223
|
+
...(obj.toArray().map((x, idx) => {
|
|
224
|
+
return div(
|
|
225
|
+
{ marginLeft: "8px", display: flexMode, paddingRight: "16px" },
|
|
226
|
+
span(
|
|
227
|
+
{
|
|
228
|
+
fontFamily: "monospace",
|
|
229
|
+
marginRight: "8px",
|
|
230
|
+
color: hsl(280, 80, 90),
|
|
231
|
+
flexShrink: 0,
|
|
232
|
+
fontSize: "10px",
|
|
233
|
+
},
|
|
234
|
+
idx
|
|
235
|
+
),
|
|
236
|
+
embedObject(x)
|
|
237
|
+
);
|
|
238
|
+
}) as any[])
|
|
132
239
|
);
|
|
133
240
|
}
|
|
134
241
|
if (obj instanceof CalcitSet) {
|
|
135
|
-
let ret: any[] =
|
|
242
|
+
let ret: any[] = div({ color: hsl(280, 80, 60), borderLeft: "1px solid #eee" });
|
|
136
243
|
let values = obj.values();
|
|
137
244
|
for (let idx = 0; idx < values.length; idx++) {
|
|
138
245
|
let x = values[idx];
|
|
139
|
-
ret.push(
|
|
246
|
+
ret.push(div({ marginLeft: "8px", display: "inline-block" }, embedObject(x)));
|
|
140
247
|
}
|
|
141
248
|
return ret;
|
|
142
249
|
}
|
|
143
250
|
if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
|
|
144
|
-
let ret: any[] =
|
|
251
|
+
let ret: any[] = table({ color: hsl(280, 80, 60), borderLeft: "1px solid #eee" });
|
|
145
252
|
let pairs = obj.pairs();
|
|
146
253
|
pairs.sort((pa, pb) => {
|
|
147
|
-
let ka = pa[0]
|
|
148
|
-
let kb = pb[0]
|
|
254
|
+
let ka = saveString(pa[0]);
|
|
255
|
+
let kb = saveString(pb[0]);
|
|
149
256
|
if (ka < kb) {
|
|
150
257
|
return -1;
|
|
151
258
|
} else if (ka > kb) {
|
|
@@ -156,12 +263,30 @@ export let load_console_formatter_$x_ = () => {
|
|
|
156
263
|
});
|
|
157
264
|
for (let idx = 0; idx < pairs.length; idx++) {
|
|
158
265
|
let [k, v] = pairs[idx];
|
|
159
|
-
ret.push(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
266
|
+
ret.push(
|
|
267
|
+
tr(
|
|
268
|
+
{
|
|
269
|
+
marginLeft: "8px",
|
|
270
|
+
},
|
|
271
|
+
td({ marginLeft: "8px", verticalAlign: "top" }, embedObject(k)),
|
|
272
|
+
td({ marginLeft: "8px" }, embedObject(v))
|
|
273
|
+
)
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
return ret;
|
|
277
|
+
}
|
|
278
|
+
if (obj instanceof CalcitRecord) {
|
|
279
|
+
let ret: any[] = table({ color: hsl(280, 80, 60), borderLeft: "1px solid #eee" });
|
|
280
|
+
for (let idx = 0; idx < obj.fields.length; idx++) {
|
|
281
|
+
ret.push(
|
|
282
|
+
tr(
|
|
283
|
+
{
|
|
284
|
+
marginLeft: "8px",
|
|
285
|
+
},
|
|
286
|
+
td({ marginLeft: "8px", verticalAlign: "top" }, embedObject(obj.fields[idx])),
|
|
287
|
+
td({ marginLeft: "8px" }, embedObject(obj.values[idx]))
|
|
288
|
+
)
|
|
289
|
+
);
|
|
165
290
|
}
|
|
166
291
|
return ret;
|
|
167
292
|
}
|
package/ts-src/js-cirru.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { overwriteComparator, initTernaryTreeMap } from "@calcit/ternary-tree";
|
|
2
2
|
import { CirruWriterNode, writeCirruCode } from "@cirru/writer.ts";
|
|
3
3
|
|
|
4
|
-
import { CalcitValue,
|
|
4
|
+
import { CalcitValue, isLiteral, _$n_compare } from "./js-primes.mjs";
|
|
5
5
|
import { CalcitList, CalcitSliceList } from "./js-list.mjs";
|
|
6
6
|
import { CalcitRecord } from "./js-record.mjs";
|
|
7
7
|
import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
|
|
@@ -99,10 +99,10 @@ export let to_cirru_edn = (x: CalcitValue): CirruEdnFormat => {
|
|
|
99
99
|
pairs_buffer.push(pairs[idx]);
|
|
100
100
|
}
|
|
101
101
|
pairs_buffer.sort((a, b) => {
|
|
102
|
-
let a0_literal =
|
|
103
|
-
let a1_literal =
|
|
104
|
-
let b0_literal =
|
|
105
|
-
let b1_literal =
|
|
102
|
+
let a0_literal = isLiteral(a[0]);
|
|
103
|
+
let a1_literal = isLiteral(a[1]);
|
|
104
|
+
let b0_literal = isLiteral(b[0]);
|
|
105
|
+
let b1_literal = isLiteral(b[1]);
|
|
106
106
|
if (a0_literal && b0_literal) {
|
|
107
107
|
if (a1_literal && !b1_literal) {
|
|
108
108
|
return -1;
|
|
@@ -132,8 +132,8 @@ export let to_cirru_edn = (x: CalcitValue): CirruEdnFormat => {
|
|
|
132
132
|
}
|
|
133
133
|
// placed literals first
|
|
134
134
|
buffer.sort((a, b) => {
|
|
135
|
-
let a1_literal =
|
|
136
|
-
let b1_literal =
|
|
135
|
+
let a1_literal = isLiteral(a[1] as CalcitValue);
|
|
136
|
+
let b1_literal = isLiteral(b[1] as CalcitValue);
|
|
137
137
|
if (a1_literal && !b1_literal) {
|
|
138
138
|
return -1;
|
|
139
139
|
} else if (!a1_literal && b1_literal) {
|
package/ts-src/js-list.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as ternaryTree from "@calcit/ternary-tree";
|
|
2
2
|
|
|
3
|
-
import { CalcitValue } from "./js-primes.mjs";
|
|
3
|
+
import { CalcitValue, isLiteral } from "./js-primes.mjs";
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
TernaryTreeList,
|
|
@@ -106,6 +106,13 @@ export class CalcitList {
|
|
|
106
106
|
reverse() {
|
|
107
107
|
return new CalcitList(ternaryTree.reverse(this.value));
|
|
108
108
|
}
|
|
109
|
+
nestedDataInChildren(): boolean {
|
|
110
|
+
for (let idx = 0; idx < this.len(); idx++) {
|
|
111
|
+
if (!isLiteral(this.get(idx))) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
109
116
|
}
|
|
110
117
|
|
|
111
118
|
// represent append-only immutable list in Array slices
|
|
@@ -254,6 +261,13 @@ export class CalcitSliceList {
|
|
|
254
261
|
reverse() {
|
|
255
262
|
return this.turnListMode().reverse();
|
|
256
263
|
}
|
|
264
|
+
nestedDataInChildren(): boolean {
|
|
265
|
+
for (let idx = 0; idx < this.len(); idx++) {
|
|
266
|
+
if (!isLiteral(this.get(idx))) {
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
257
271
|
}
|
|
258
272
|
|
|
259
273
|
function* sliceGenerator(xs: Array<CalcitValue>, start: number, end: number): Generator<CalcitValue> {
|
package/ts-src/js-map.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as ternaryTree from "@calcit/ternary-tree";
|
|
2
2
|
|
|
3
|
-
import { CalcitValue } from "./js-primes.mjs";
|
|
3
|
+
import { CalcitValue, isLiteral } from "./js-primes.mjs";
|
|
4
4
|
import { CalcitSet } from "./js-set.mjs";
|
|
5
5
|
|
|
6
6
|
import {
|
|
@@ -174,9 +174,18 @@ export class CalcitMap {
|
|
|
174
174
|
}
|
|
175
175
|
return new CalcitSet(ret);
|
|
176
176
|
}
|
|
177
|
+
|
|
178
|
+
/** detecthing in custom formatter */
|
|
179
|
+
nestedDataInChildren() {
|
|
180
|
+
for (let [k, v] of this.pairs()) {
|
|
181
|
+
if (!isLiteral(k) || !isLiteral(v)) {
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
177
186
|
}
|
|
178
187
|
|
|
179
|
-
|
|
188
|
+
/* store small map in linear array to reduce cost of building tree */
|
|
180
189
|
export class CalcitSliceMap {
|
|
181
190
|
cachedHash: Hash;
|
|
182
191
|
/** in arrayMode, only flatten values, instead of tree structure */
|
|
@@ -369,4 +378,13 @@ export class CalcitSliceMap {
|
|
|
369
378
|
}
|
|
370
379
|
return new CalcitSet(ret);
|
|
371
380
|
}
|
|
381
|
+
|
|
382
|
+
/** detecthing in custom formatter */
|
|
383
|
+
nestedDataInChildren() {
|
|
384
|
+
for (let [k, v] of this.pairs()) {
|
|
385
|
+
if (!isLiteral(k) || !isLiteral(v)) {
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
372
390
|
}
|
package/ts-src/js-primes.mts
CHANGED
|
@@ -25,7 +25,7 @@ export type CalcitValue =
|
|
|
25
25
|
| CalcitCirruQuote
|
|
26
26
|
| null;
|
|
27
27
|
|
|
28
|
-
export let
|
|
28
|
+
export let isLiteral = (x: CalcitValue): boolean => {
|
|
29
29
|
if (x == null) return true;
|
|
30
30
|
if (typeof x == "string") return true;
|
|
31
31
|
if (typeof x == "boolean") return true;
|
package/ts-src/js-tuple.mts
CHANGED
|
@@ -62,7 +62,6 @@ export class CalcitTuple {
|
|
|
62
62
|
content += toString(args[i], false, disableJsDataWarning);
|
|
63
63
|
}
|
|
64
64
|
if (this.klass instanceof CalcitRecord) {
|
|
65
|
-
console.log("CLASS", this.klass);
|
|
66
65
|
return `(%:: ${content} (:class ${this.klass.name.value}))`;
|
|
67
66
|
} else {
|
|
68
67
|
return `(:: ${content})`;
|