@calcit/procs 0.8.35 → 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 +51 -30
- 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/package.json +1 -1
- package/package.json +1 -1
- package/ts-src/calcit.procs.mts +5 -1
- package/ts-src/custom-formatter.mts +57 -34
- 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/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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isLiteral } from "./js-primes.mjs";
|
|
2
2
|
import { CalcitRef, CalcitSymbol, CalcitTag } from "./calcit-data.mjs";
|
|
3
3
|
import { CalcitRecord } from "./js-record.mjs";
|
|
4
4
|
import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
|
|
@@ -27,7 +27,10 @@ let styles = (o) => {
|
|
|
27
27
|
let keys = Object.keys(o);
|
|
28
28
|
for (let idx = 0; idx < keys.length; idx++) {
|
|
29
29
|
let key = keys[idx];
|
|
30
|
-
|
|
30
|
+
let value = o[key];
|
|
31
|
+
if (value) {
|
|
32
|
+
styleCode += `${kabab(key)}:${value};`;
|
|
33
|
+
}
|
|
31
34
|
}
|
|
32
35
|
return {
|
|
33
36
|
style: styleCode,
|
|
@@ -55,6 +58,23 @@ let tr = (style, ...children) => {
|
|
|
55
58
|
let td = (style, ...children) => {
|
|
56
59
|
return ["td", styles(style), ...children];
|
|
57
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";
|
|
76
|
+
}
|
|
77
|
+
};
|
|
58
78
|
export let load_console_formatter_$x_ = () => {
|
|
59
79
|
if (typeof window === "object") {
|
|
60
80
|
window["devtoolsFormatters"] = [
|
|
@@ -68,18 +88,20 @@ export let load_console_formatter_$x_ = () => {
|
|
|
68
88
|
}
|
|
69
89
|
if (obj instanceof CalcitList || obj instanceof CalcitSliceList) {
|
|
70
90
|
let preview = "";
|
|
91
|
+
let hasCollection = false;
|
|
71
92
|
for (let idx = 0; idx < obj.len(); idx++) {
|
|
72
93
|
preview += " ";
|
|
73
|
-
if (
|
|
74
|
-
preview += obj.get(idx)
|
|
94
|
+
if (isLiteral(obj.get(idx))) {
|
|
95
|
+
preview += saveString(obj.get(idx));
|
|
75
96
|
}
|
|
76
97
|
else {
|
|
77
98
|
preview += "..";
|
|
99
|
+
hasCollection = true;
|
|
78
100
|
break;
|
|
79
101
|
}
|
|
80
102
|
}
|
|
81
103
|
return div({
|
|
82
|
-
color: hsl(280, 80, 60, 0.4),
|
|
104
|
+
color: hasCollection ? hsl(280, 80, 60, 0.4) : null,
|
|
83
105
|
}, `[]`, span({
|
|
84
106
|
fontSize: "8px",
|
|
85
107
|
verticalAlign: "middle",
|
|
@@ -88,17 +110,19 @@ export let load_console_formatter_$x_ = () => {
|
|
|
88
110
|
}
|
|
89
111
|
if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
|
|
90
112
|
let preview = "";
|
|
113
|
+
let hasCollection = false;
|
|
91
114
|
for (let [k, v] of obj.pairs()) {
|
|
92
115
|
preview += " ";
|
|
93
|
-
if (
|
|
94
|
-
preview += `(${k
|
|
116
|
+
if (isLiteral(k) && isLiteral(v)) {
|
|
117
|
+
preview += `(${saveString(k)} ${saveString(v)})`;
|
|
95
118
|
}
|
|
96
119
|
else {
|
|
97
120
|
preview += "..";
|
|
121
|
+
hasCollection = true;
|
|
98
122
|
break;
|
|
99
123
|
}
|
|
100
124
|
}
|
|
101
|
-
return div({ color: hsl(280, 80, 60, 0.4) }, "{}", preview);
|
|
125
|
+
return div({ color: hasCollection ? hsl(280, 80, 60, 0.4) : undefined }, "{}", preview);
|
|
102
126
|
}
|
|
103
127
|
if (obj instanceof CalcitSet) {
|
|
104
128
|
return div({ color: hsl(280, 80, 60, 0.4) }, obj.toString(true));
|
|
@@ -108,11 +132,20 @@ export let load_console_formatter_$x_ = () => {
|
|
|
108
132
|
return ret;
|
|
109
133
|
}
|
|
110
134
|
if (obj instanceof CalcitTuple) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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;
|
|
114
148
|
}
|
|
115
|
-
return ret;
|
|
116
149
|
}
|
|
117
150
|
if (obj instanceof CalcitRef) {
|
|
118
151
|
return div({
|
|
@@ -126,24 +159,12 @@ export let load_console_formatter_$x_ = () => {
|
|
|
126
159
|
},
|
|
127
160
|
hasBody: (obj) => {
|
|
128
161
|
if (obj instanceof CalcitList || obj instanceof CalcitSliceList) {
|
|
129
|
-
let
|
|
130
|
-
|
|
131
|
-
if (!is_literal(obj.get(idx))) {
|
|
132
|
-
has_collection = true;
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return obj.len() > 0 && has_collection;
|
|
162
|
+
let hasCollection = obj.nestedDataInChildren();
|
|
163
|
+
return obj.len() > 0 && hasCollection;
|
|
137
164
|
}
|
|
138
165
|
if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
|
|
139
|
-
let
|
|
140
|
-
|
|
141
|
-
if (!is_literal(k) || !is_literal(v)) {
|
|
142
|
-
has_collection = true;
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return obj.len() > 0 && has_collection;
|
|
166
|
+
let hasCollection = obj.nestedDataInChildren();
|
|
167
|
+
return obj.len() > 0 && hasCollection;
|
|
147
168
|
}
|
|
148
169
|
if (obj instanceof CalcitSet) {
|
|
149
170
|
return obj.len() > 0;
|
|
@@ -179,8 +200,8 @@ export let load_console_formatter_$x_ = () => {
|
|
|
179
200
|
let ret = table({ color: hsl(280, 80, 60), borderLeft: "1px solid #eee" });
|
|
180
201
|
let pairs = obj.pairs();
|
|
181
202
|
pairs.sort((pa, pb) => {
|
|
182
|
-
let ka = pa[0]
|
|
183
|
-
let kb = pb[0]
|
|
203
|
+
let ka = saveString(pa[0]);
|
|
204
|
+
let kb = saveString(pb[0]);
|
|
184
205
|
if (ka < kb) {
|
|
185
206
|
return -1;
|
|
186
207
|
}
|
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/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,
|
|
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";
|
|
@@ -41,7 +41,10 @@ let styles = (o: any) => {
|
|
|
41
41
|
let keys = Object.keys(o);
|
|
42
42
|
for (let idx = 0; idx < keys.length; idx++) {
|
|
43
43
|
let key = keys[idx];
|
|
44
|
-
|
|
44
|
+
let value = (o as any)[key];
|
|
45
|
+
if (value) {
|
|
46
|
+
styleCode += `${kabab(key)}:${value};`;
|
|
47
|
+
}
|
|
45
48
|
}
|
|
46
49
|
return {
|
|
47
50
|
style: styleCode,
|
|
@@ -72,6 +75,21 @@ let td = (style: any, ...children: any[]) => {
|
|
|
72
75
|
return ["td", styles(style), ...children];
|
|
73
76
|
};
|
|
74
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";
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
75
93
|
export let load_console_formatter_$x_ = () => {
|
|
76
94
|
if (typeof window === "object") {
|
|
77
95
|
window["devtoolsFormatters"] = [
|
|
@@ -85,18 +103,20 @@ export let load_console_formatter_$x_ = () => {
|
|
|
85
103
|
}
|
|
86
104
|
if (obj instanceof CalcitList || obj instanceof CalcitSliceList) {
|
|
87
105
|
let preview = "";
|
|
106
|
+
let hasCollection = false;
|
|
88
107
|
for (let idx = 0; idx < obj.len(); idx++) {
|
|
89
108
|
preview += " ";
|
|
90
|
-
if (
|
|
91
|
-
preview += obj.get(idx)
|
|
109
|
+
if (isLiteral(obj.get(idx))) {
|
|
110
|
+
preview += saveString(obj.get(idx));
|
|
92
111
|
} else {
|
|
93
112
|
preview += "..";
|
|
113
|
+
hasCollection = true;
|
|
94
114
|
break;
|
|
95
115
|
}
|
|
96
116
|
}
|
|
97
117
|
return div(
|
|
98
118
|
{
|
|
99
|
-
color: hsl(280, 80, 60, 0.4),
|
|
119
|
+
color: hasCollection ? hsl(280, 80, 60, 0.4) : null,
|
|
100
120
|
},
|
|
101
121
|
`[]`,
|
|
102
122
|
span(
|
|
@@ -113,16 +133,18 @@ export let load_console_formatter_$x_ = () => {
|
|
|
113
133
|
}
|
|
114
134
|
if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
|
|
115
135
|
let preview = "";
|
|
136
|
+
let hasCollection = false;
|
|
116
137
|
for (let [k, v] of obj.pairs()) {
|
|
117
138
|
preview += " ";
|
|
118
|
-
if (
|
|
119
|
-
preview += `(${k
|
|
139
|
+
if (isLiteral(k) && isLiteral(v)) {
|
|
140
|
+
preview += `(${saveString(k)} ${saveString(v)})`;
|
|
120
141
|
} else {
|
|
121
142
|
preview += "..";
|
|
143
|
+
hasCollection = true;
|
|
122
144
|
break;
|
|
123
145
|
}
|
|
124
146
|
}
|
|
125
|
-
return div({ color: hsl(280, 80, 60, 0.4) }, "{}", preview);
|
|
147
|
+
return div({ color: hasCollection ? hsl(280, 80, 60, 0.4) : undefined }, "{}", preview);
|
|
126
148
|
}
|
|
127
149
|
if (obj instanceof CalcitSet) {
|
|
128
150
|
return div({ color: hsl(280, 80, 60, 0.4) }, obj.toString(true));
|
|
@@ -132,15 +154,28 @@ export let load_console_formatter_$x_ = () => {
|
|
|
132
154
|
return ret;
|
|
133
155
|
}
|
|
134
156
|
if (obj instanceof CalcitTuple) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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;
|
|
142
178
|
}
|
|
143
|
-
return ret;
|
|
144
179
|
}
|
|
145
180
|
if (obj instanceof CalcitRef) {
|
|
146
181
|
return div(
|
|
@@ -165,24 +200,12 @@ export let load_console_formatter_$x_ = () => {
|
|
|
165
200
|
},
|
|
166
201
|
hasBody: (obj) => {
|
|
167
202
|
if (obj instanceof CalcitList || obj instanceof CalcitSliceList) {
|
|
168
|
-
let
|
|
169
|
-
|
|
170
|
-
if (!is_literal(obj.get(idx))) {
|
|
171
|
-
has_collection = true;
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return obj.len() > 0 && has_collection;
|
|
203
|
+
let hasCollection = obj.nestedDataInChildren();
|
|
204
|
+
return obj.len() > 0 && hasCollection;
|
|
176
205
|
}
|
|
177
206
|
if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
|
|
178
|
-
let
|
|
179
|
-
|
|
180
|
-
if (!is_literal(k) || !is_literal(v)) {
|
|
181
|
-
has_collection = true;
|
|
182
|
-
break;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return obj.len() > 0 && has_collection;
|
|
207
|
+
let hasCollection = obj.nestedDataInChildren();
|
|
208
|
+
return obj.len() > 0 && hasCollection;
|
|
186
209
|
}
|
|
187
210
|
if (obj instanceof CalcitSet) {
|
|
188
211
|
return obj.len() > 0;
|
|
@@ -228,8 +251,8 @@ export let load_console_formatter_$x_ = () => {
|
|
|
228
251
|
let ret: any[] = table({ color: hsl(280, 80, 60), borderLeft: "1px solid #eee" });
|
|
229
252
|
let pairs = obj.pairs();
|
|
230
253
|
pairs.sort((pa, pb) => {
|
|
231
|
-
let ka = pa[0]
|
|
232
|
-
let kb = pb[0]
|
|
254
|
+
let ka = saveString(pa[0]);
|
|
255
|
+
let kb = saveString(pb[0]);
|
|
233
256
|
if (ka < kb) {
|
|
234
257
|
return -1;
|
|
235
258
|
} else if (ka > kb) {
|
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;
|