histoire 0.7.2 → 0.7.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/dist/bundled/SandboxVue3.js +20 -9
- package/dist/bundled/state.js +9 -5
- package/dist/client/app/codegen/serialize-js.js +22 -9
- package/dist/client/app/util/state.d.ts +1 -1
- package/dist/client/app/util/state.js +9 -5
- package/dist/style.css +76 -0
- package/package.json +2 -2
- package/src/client/app/codegen/serialize-js.ts +24 -10
- package/src/client/app/util/state.ts +11 -5
|
@@ -91,6 +91,7 @@ function createAutoBuildingObject(format, specialKeysHandler, key = "", depth =
|
|
|
91
91
|
const KEY_ESCAPE_REG = /[\s-.:|#@$£*%]/;
|
|
92
92
|
const MAX_SINGLE_LINE_ARRAY_LENGTH = 3;
|
|
93
93
|
function serializeJs(value) {
|
|
94
|
+
const seen = /* @__PURE__ */ new Set();
|
|
94
95
|
if (value === void 0) {
|
|
95
96
|
return "undefined";
|
|
96
97
|
}
|
|
@@ -104,10 +105,10 @@ function serializeJs(value) {
|
|
|
104
105
|
return value ? "true" : "false";
|
|
105
106
|
}
|
|
106
107
|
if (Array.isArray(value)) {
|
|
107
|
-
return printLines(arrayToSourceLines(value));
|
|
108
|
+
return printLines(arrayToSourceLines(value, seen));
|
|
108
109
|
}
|
|
109
110
|
if (typeof value === "object") {
|
|
110
|
-
return printLines(objectToSourceLines(value));
|
|
111
|
+
return printLines(objectToSourceLines(value, seen));
|
|
111
112
|
}
|
|
112
113
|
if (value == null ? void 0 : value.__autoBuildingObject) {
|
|
113
114
|
return value;
|
|
@@ -120,7 +121,12 @@ function serializeJs(value) {
|
|
|
120
121
|
function printLines(lines) {
|
|
121
122
|
return lines.map((line) => " ".repeat(line.spaces) + line.line).join("\n");
|
|
122
123
|
}
|
|
123
|
-
function objectToSourceLines(object, indentCount = 0) {
|
|
124
|
+
function objectToSourceLines(object, seen, indentCount = 0) {
|
|
125
|
+
if (seen.has(object)) {
|
|
126
|
+
object = {};
|
|
127
|
+
} else {
|
|
128
|
+
seen.add(object);
|
|
129
|
+
}
|
|
124
130
|
return createLines(indentCount, (lines) => {
|
|
125
131
|
lines.push("{");
|
|
126
132
|
lines.push(...createLines(1, (lines2) => {
|
|
@@ -130,17 +136,22 @@ function objectToSourceLines(object, indentCount = 0) {
|
|
|
130
136
|
if (KEY_ESCAPE_REG.test(key)) {
|
|
131
137
|
printedKey = `'${printedKey}'`;
|
|
132
138
|
}
|
|
133
|
-
addLinesFromValue(lines2, value, `${printedKey}: `, ",");
|
|
139
|
+
addLinesFromValue(lines2, value, `${printedKey}: `, ",", seen);
|
|
134
140
|
}
|
|
135
141
|
}));
|
|
136
142
|
lines.push("}");
|
|
137
143
|
});
|
|
138
144
|
}
|
|
139
|
-
function arrayToSourceLines(array, indentCount = 0) {
|
|
145
|
+
function arrayToSourceLines(array, seen, indentCount = 0) {
|
|
146
|
+
if (seen.has(array)) {
|
|
147
|
+
array = [];
|
|
148
|
+
} else {
|
|
149
|
+
seen.add(array);
|
|
150
|
+
}
|
|
140
151
|
return createLines(indentCount, (lines) => {
|
|
141
152
|
const contentLines = createLines(1, (lines2) => {
|
|
142
153
|
for (const value of array) {
|
|
143
|
-
addLinesFromValue(lines2, value, "", ",");
|
|
154
|
+
addLinesFromValue(lines2, value, "", ",", seen);
|
|
144
155
|
}
|
|
145
156
|
});
|
|
146
157
|
if (contentLines.length === 0) {
|
|
@@ -167,13 +178,13 @@ function createLines(indentCount, handler) {
|
|
|
167
178
|
return { spaces: indentCount, line };
|
|
168
179
|
});
|
|
169
180
|
}
|
|
170
|
-
function addLinesFromValue(lines, value, before, after) {
|
|
181
|
+
function addLinesFromValue(lines, value, before, after, seen) {
|
|
171
182
|
let result;
|
|
172
183
|
if (Array.isArray(value)) {
|
|
173
|
-
lines.push(...wrap(arrayToSourceLines(value), before, after));
|
|
184
|
+
lines.push(...wrap(arrayToSourceLines(value, seen), before, after));
|
|
174
185
|
return;
|
|
175
186
|
} else if (value && typeof value === "object") {
|
|
176
|
-
lines.push(...wrap(objectToSourceLines(value), before, after));
|
|
187
|
+
lines.push(...wrap(objectToSourceLines(value, seen), before, after));
|
|
177
188
|
return;
|
|
178
189
|
} else if (typeof value === "string") {
|
|
179
190
|
result = value.includes("'") ? `\`${value}\`` : `'${value}'`;
|
package/dist/bundled/state.js
CHANGED
|
@@ -3,18 +3,22 @@ import { isRef, unref } from "vue";
|
|
|
3
3
|
const isDark = useDark({ valueDark: "htw-dark" });
|
|
4
4
|
const toggleDark = useToggle(isDark);
|
|
5
5
|
const isObject = (val) => val !== null && typeof val === "object";
|
|
6
|
-
function toRawDeep(val) {
|
|
6
|
+
function toRawDeep(val, seen = /* @__PURE__ */ new Set()) {
|
|
7
7
|
const unwrappedValue = isRef(val) ? unref(val) : val;
|
|
8
|
+
if (seen.has(unwrappedValue)) {
|
|
9
|
+
return Array.isArray(unwrappedValue) ? [] : {};
|
|
10
|
+
}
|
|
11
|
+
seen.add(unwrappedValue);
|
|
8
12
|
if (!isObject(unwrappedValue)) {
|
|
9
13
|
return unwrappedValue;
|
|
10
14
|
}
|
|
11
15
|
if (Array.isArray(unwrappedValue)) {
|
|
12
|
-
return unwrappedValue.map(toRawDeep);
|
|
16
|
+
return unwrappedValue.map((value) => toRawDeep(value, seen));
|
|
13
17
|
}
|
|
14
|
-
return toRawObject(unwrappedValue);
|
|
18
|
+
return toRawObject(unwrappedValue, seen);
|
|
15
19
|
}
|
|
16
|
-
const toRawObject = (obj) => Object.keys(obj).reduce((raw, key) => {
|
|
17
|
-
raw[key] = toRawDeep(obj[key]);
|
|
20
|
+
const toRawObject = (obj, seen = /* @__PURE__ */ new Set()) => Object.keys(obj).reduce((raw, key) => {
|
|
21
|
+
raw[key] = toRawDeep(obj[key], seen);
|
|
18
22
|
return raw;
|
|
19
23
|
}, {});
|
|
20
24
|
function clone(data) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const KEY_ESCAPE_REG = /[\s-.:|#@$£*%]/;
|
|
2
2
|
const MAX_SINGLE_LINE_ARRAY_LENGTH = 3;
|
|
3
3
|
export function serializeJs(value) {
|
|
4
|
+
const seen = new Set();
|
|
4
5
|
if (value === undefined) {
|
|
5
6
|
return 'undefined';
|
|
6
7
|
}
|
|
@@ -14,10 +15,10 @@ export function serializeJs(value) {
|
|
|
14
15
|
return value ? 'true' : 'false';
|
|
15
16
|
}
|
|
16
17
|
if (Array.isArray(value)) {
|
|
17
|
-
return printLines(arrayToSourceLines(value));
|
|
18
|
+
return printLines(arrayToSourceLines(value, seen));
|
|
18
19
|
}
|
|
19
20
|
if (typeof value === 'object') {
|
|
20
|
-
return printLines(objectToSourceLines(value));
|
|
21
|
+
return printLines(objectToSourceLines(value, seen));
|
|
21
22
|
}
|
|
22
23
|
if (value?.__autoBuildingObject) {
|
|
23
24
|
return value;
|
|
@@ -30,7 +31,13 @@ export function serializeJs(value) {
|
|
|
30
31
|
function printLines(lines) {
|
|
31
32
|
return lines.map(line => ' '.repeat(line.spaces) + line.line).join('\n');
|
|
32
33
|
}
|
|
33
|
-
function objectToSourceLines(object, indentCount = 0) {
|
|
34
|
+
function objectToSourceLines(object, seen, indentCount = 0) {
|
|
35
|
+
if (seen.has(object)) {
|
|
36
|
+
object = {};
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
seen.add(object);
|
|
40
|
+
}
|
|
34
41
|
return createLines(indentCount, lines => {
|
|
35
42
|
lines.push('{');
|
|
36
43
|
lines.push(...createLines(1, lines => {
|
|
@@ -40,17 +47,23 @@ function objectToSourceLines(object, indentCount = 0) {
|
|
|
40
47
|
if (KEY_ESCAPE_REG.test(key)) {
|
|
41
48
|
printedKey = `'${printedKey}'`;
|
|
42
49
|
}
|
|
43
|
-
addLinesFromValue(lines, value, `${printedKey}: `, ',');
|
|
50
|
+
addLinesFromValue(lines, value, `${printedKey}: `, ',', seen);
|
|
44
51
|
}
|
|
45
52
|
}));
|
|
46
53
|
lines.push('}');
|
|
47
54
|
});
|
|
48
55
|
}
|
|
49
|
-
function arrayToSourceLines(array, indentCount = 0) {
|
|
56
|
+
function arrayToSourceLines(array, seen, indentCount = 0) {
|
|
57
|
+
if (seen.has(array)) {
|
|
58
|
+
array = [];
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
seen.add(array);
|
|
62
|
+
}
|
|
50
63
|
return createLines(indentCount, lines => {
|
|
51
64
|
const contentLines = createLines(1, lines => {
|
|
52
65
|
for (const value of array) {
|
|
53
|
-
addLinesFromValue(lines, value, '', ',');
|
|
66
|
+
addLinesFromValue(lines, value, '', ',', seen);
|
|
54
67
|
}
|
|
55
68
|
});
|
|
56
69
|
if (contentLines.length === 0) {
|
|
@@ -79,14 +92,14 @@ function createLines(indentCount, handler) {
|
|
|
79
92
|
return { spaces: indentCount, line };
|
|
80
93
|
});
|
|
81
94
|
}
|
|
82
|
-
function addLinesFromValue(lines, value, before, after) {
|
|
95
|
+
function addLinesFromValue(lines, value, before, after, seen) {
|
|
83
96
|
let result;
|
|
84
97
|
if (Array.isArray(value)) {
|
|
85
|
-
lines.push(...wrap(arrayToSourceLines(value), before, after));
|
|
98
|
+
lines.push(...wrap(arrayToSourceLines(value, seen), before, after));
|
|
86
99
|
return;
|
|
87
100
|
}
|
|
88
101
|
else if (value && typeof value === 'object') {
|
|
89
|
-
lines.push(...wrap(objectToSourceLines(value), before, after));
|
|
102
|
+
lines.push(...wrap(objectToSourceLines(value, seen), before, after));
|
|
90
103
|
return;
|
|
91
104
|
}
|
|
92
105
|
else if (typeof value === 'string') {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Variant } from '../types';
|
|
2
|
-
export declare function toRawDeep(val: any): any;
|
|
2
|
+
export declare function toRawDeep(val: any, seen?: Set<unknown>): any;
|
|
3
3
|
export declare function clone(data: any): any;
|
|
4
4
|
export declare function omit(data: any, keys: string[]): {};
|
|
5
5
|
export declare function applyStateToVariant(variant: Variant, state: any): void;
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { unref, isRef } from 'vue';
|
|
2
2
|
const isObject = (val) => val !== null && typeof val === 'object';
|
|
3
|
-
export function toRawDeep(val) {
|
|
3
|
+
export function toRawDeep(val, seen = new Set()) {
|
|
4
4
|
const unwrappedValue = isRef(val) ? unref(val) : val;
|
|
5
|
+
if (seen.has(unwrappedValue)) {
|
|
6
|
+
return Array.isArray(unwrappedValue) ? [] : {};
|
|
7
|
+
}
|
|
8
|
+
seen.add(unwrappedValue);
|
|
5
9
|
if (!isObject(unwrappedValue)) {
|
|
6
10
|
return unwrappedValue;
|
|
7
11
|
}
|
|
8
12
|
if (Array.isArray(unwrappedValue)) {
|
|
9
|
-
return unwrappedValue.map(toRawDeep);
|
|
13
|
+
return unwrappedValue.map(value => toRawDeep(value, seen));
|
|
10
14
|
}
|
|
11
|
-
return toRawObject(unwrappedValue);
|
|
15
|
+
return toRawObject(unwrappedValue, seen);
|
|
12
16
|
}
|
|
13
|
-
const toRawObject = (obj) => Object.keys(obj).reduce((raw, key) => {
|
|
14
|
-
raw[key] = toRawDeep(obj[key]);
|
|
17
|
+
const toRawObject = (obj, seen = new Set()) => Object.keys(obj).reduce((raw, key) => {
|
|
18
|
+
raw[key] = toRawDeep(obj[key], seen);
|
|
15
19
|
return raw;
|
|
16
20
|
}, {});
|
|
17
21
|
export function clone(data) {
|
package/dist/style.css
CHANGED
|
@@ -205,6 +205,58 @@
|
|
|
205
205
|
border-color:#000c
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
+
.htw-range-input::-webkit-slider-thumb{
|
|
209
|
+
height:.75rem;
|
|
210
|
+
width:.75rem;
|
|
211
|
+
-webkit-appearance:none;
|
|
212
|
+
appearance:none;
|
|
213
|
+
border-radius:9999px;
|
|
214
|
+
border-width:1px;
|
|
215
|
+
border-style:solid;
|
|
216
|
+
border-color:#00000040;
|
|
217
|
+
--tw-bg-opacity: 1;
|
|
218
|
+
background-color:rgb(255 255 255 / var(--tw-bg-opacity))
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.htw-dark .htw-range-input::-webkit-slider-thumb{
|
|
222
|
+
border-color:#ffffff40;
|
|
223
|
+
--tw-bg-opacity: 1;
|
|
224
|
+
background-color:rgb(63 63 70 / var(--tw-bg-opacity))
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
.htw-range-input:hover::-webkit-slider-thumb{
|
|
228
|
+
--tw-border-opacity: 1 !important;
|
|
229
|
+
border-color:rgb(16 185 129 / var(--tw-border-opacity))!important;
|
|
230
|
+
--tw-bg-opacity: 1 !important;
|
|
231
|
+
background-color:rgb(16 185 129 / var(--tw-bg-opacity))!important
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.htw-range-input::-moz-range-thumb{
|
|
235
|
+
height:.75rem;
|
|
236
|
+
width:.75rem;
|
|
237
|
+
-moz-appearance:none;
|
|
238
|
+
appearance:none;
|
|
239
|
+
border-radius:9999px;
|
|
240
|
+
border-width:1px;
|
|
241
|
+
border-style:solid;
|
|
242
|
+
border-color:#00000040;
|
|
243
|
+
--tw-bg-opacity: 1;
|
|
244
|
+
background-color:rgb(255 255 255 / var(--tw-bg-opacity))
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.htw-dark .htw-range-input::-moz-range-thumb{
|
|
248
|
+
border-color:#ffffff40;
|
|
249
|
+
--tw-bg-opacity: 1;
|
|
250
|
+
background-color:rgb(63 63 70 / var(--tw-bg-opacity))
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
.htw-range-input:hover::-moz-range-thumb{
|
|
254
|
+
--tw-border-opacity: 1 !important;
|
|
255
|
+
border-color:rgb(16 185 129 / var(--tw-border-opacity))!important;
|
|
256
|
+
--tw-bg-opacity: 1 !important;
|
|
257
|
+
background-color:rgb(16 185 129 / var(--tw-bg-opacity))!important
|
|
258
|
+
}
|
|
259
|
+
|
|
208
260
|
.v-popper{
|
|
209
261
|
line-height:0
|
|
210
262
|
}
|
|
@@ -1123,6 +1175,10 @@ button {
|
|
|
1123
1175
|
height:5rem
|
|
1124
1176
|
}
|
|
1125
1177
|
|
|
1178
|
+
.htw-h-1{
|
|
1179
|
+
height:0.25rem
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1126
1182
|
.htw-max-h-full{
|
|
1127
1183
|
max-height:100%
|
|
1128
1184
|
}
|
|
@@ -1313,6 +1369,12 @@ button {
|
|
|
1313
1369
|
resize:vertical
|
|
1314
1370
|
}
|
|
1315
1371
|
|
|
1372
|
+
.htw-appearance-none{
|
|
1373
|
+
-webkit-appearance:none;
|
|
1374
|
+
-moz-appearance:none;
|
|
1375
|
+
appearance:none
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1316
1378
|
.htw-grid-cols-\[repeat\(auto-fill\,minmax\(200px\,1fr\)\)\]{
|
|
1317
1379
|
grid-template-columns:repeat(auto-fill,minmax(200px,1fr))
|
|
1318
1380
|
}
|
|
@@ -1467,6 +1529,10 @@ button {
|
|
|
1467
1529
|
border-width:2px
|
|
1468
1530
|
}
|
|
1469
1531
|
|
|
1532
|
+
.htw-border-0{
|
|
1533
|
+
border-width:0px
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1470
1536
|
.htw-border-b-2{
|
|
1471
1537
|
border-bottom-width:2px
|
|
1472
1538
|
}
|
|
@@ -1610,6 +1676,11 @@ button {
|
|
|
1610
1676
|
background-color:rgb(var(--_histoire-color-gray-700) / var(--tw-bg-opacity))
|
|
1611
1677
|
}
|
|
1612
1678
|
|
|
1679
|
+
.\!htw-bg-primary-500{
|
|
1680
|
+
--tw-bg-opacity:1 !important;
|
|
1681
|
+
background-color:rgb(var(--_histoire-color-primary-500) / var(--tw-bg-opacity)) !important
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1613
1684
|
.htw-stroke-white{
|
|
1614
1685
|
stroke:#fff
|
|
1615
1686
|
}
|
|
@@ -1815,6 +1886,11 @@ button {
|
|
|
1815
1886
|
color:rgb(var(--_histoire-color-primary-800) / var(--tw-text-opacity))
|
|
1816
1887
|
}
|
|
1817
1888
|
|
|
1889
|
+
.htw-text-gray-700{
|
|
1890
|
+
--tw-text-opacity:1;
|
|
1891
|
+
color:rgb(var(--_histoire-color-gray-700) / var(--tw-text-opacity))
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1818
1894
|
.htw-opacity-25{
|
|
1819
1895
|
opacity:0.25
|
|
1820
1896
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "histoire",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "A fast story book powered by Vite",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"histoire": "./bin.mjs"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@histoire/controls": "^0.7.
|
|
36
|
+
"@histoire/controls": "^0.7.3",
|
|
37
37
|
"@iconify/vue": "^3.2.1",
|
|
38
38
|
"@types/markdown-it": "^12.2.3",
|
|
39
39
|
"@vueuse/core": "^8.2.5",
|
|
@@ -7,6 +7,8 @@ interface Line {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export function serializeJs (value: any): string {
|
|
10
|
+
const seen = new Set()
|
|
11
|
+
|
|
10
12
|
if (value === undefined) {
|
|
11
13
|
return 'undefined'
|
|
12
14
|
}
|
|
@@ -20,10 +22,10 @@ export function serializeJs (value: any): string {
|
|
|
20
22
|
return value ? 'true' : 'false'
|
|
21
23
|
}
|
|
22
24
|
if (Array.isArray(value)) {
|
|
23
|
-
return printLines(arrayToSourceLines(value))
|
|
25
|
+
return printLines(arrayToSourceLines(value, seen))
|
|
24
26
|
}
|
|
25
27
|
if (typeof value === 'object') {
|
|
26
|
-
return printLines(objectToSourceLines(value))
|
|
28
|
+
return printLines(objectToSourceLines(value, seen))
|
|
27
29
|
}
|
|
28
30
|
if (value?.__autoBuildingObject) {
|
|
29
31
|
return value
|
|
@@ -38,7 +40,13 @@ function printLines (lines: Line[]) {
|
|
|
38
40
|
return lines.map(line => ' '.repeat(line.spaces) + line.line).join('\n')
|
|
39
41
|
}
|
|
40
42
|
|
|
41
|
-
function objectToSourceLines (object, indentCount = 0) {
|
|
43
|
+
function objectToSourceLines (object, seen: Set<unknown>, indentCount = 0) {
|
|
44
|
+
if (seen.has(object)) {
|
|
45
|
+
object = {}
|
|
46
|
+
} else {
|
|
47
|
+
seen.add(object)
|
|
48
|
+
}
|
|
49
|
+
|
|
42
50
|
return createLines(indentCount, lines => {
|
|
43
51
|
lines.push('{')
|
|
44
52
|
lines.push(...createLines(1, lines => {
|
|
@@ -50,18 +58,24 @@ function objectToSourceLines (object, indentCount = 0) {
|
|
|
50
58
|
printedKey = `'${printedKey}'`
|
|
51
59
|
}
|
|
52
60
|
|
|
53
|
-
addLinesFromValue(lines, value, `${printedKey}: `, ',')
|
|
61
|
+
addLinesFromValue(lines, value, `${printedKey}: `, ',', seen)
|
|
54
62
|
}
|
|
55
63
|
}))
|
|
56
64
|
lines.push('}')
|
|
57
65
|
})
|
|
58
66
|
}
|
|
59
67
|
|
|
60
|
-
function arrayToSourceLines (array: any[], indentCount = 0) {
|
|
68
|
+
function arrayToSourceLines (array: any[], seen: Set<unknown>, indentCount = 0): Array<Line> {
|
|
69
|
+
if (seen.has(array)) {
|
|
70
|
+
array = []
|
|
71
|
+
} else {
|
|
72
|
+
seen.add(array)
|
|
73
|
+
}
|
|
74
|
+
|
|
61
75
|
return createLines(indentCount, lines => {
|
|
62
76
|
const contentLines = createLines(1, lines => {
|
|
63
77
|
for (const value of array) {
|
|
64
|
-
addLinesFromValue(lines, value, '', ',')
|
|
78
|
+
addLinesFromValue(lines, value, '', ',', seen)
|
|
65
79
|
}
|
|
66
80
|
})
|
|
67
81
|
if (contentLines.length === 0) {
|
|
@@ -78,7 +92,7 @@ function arrayToSourceLines (array: any[], indentCount = 0) {
|
|
|
78
92
|
})
|
|
79
93
|
}
|
|
80
94
|
|
|
81
|
-
function createLines (indentCount: number, handler: (lines: any[]) => unknown) {
|
|
95
|
+
function createLines (indentCount: number, handler: (lines: any[]) => unknown): Array<Line> {
|
|
82
96
|
const lines: any[] = []
|
|
83
97
|
handler(lines)
|
|
84
98
|
return lines.map(line => {
|
|
@@ -90,13 +104,13 @@ function createLines (indentCount: number, handler: (lines: any[]) => unknown) {
|
|
|
90
104
|
})
|
|
91
105
|
}
|
|
92
106
|
|
|
93
|
-
function addLinesFromValue (lines: Line[], value, before, after) {
|
|
107
|
+
function addLinesFromValue (lines: Line[], value, before, after, seen) {
|
|
94
108
|
let result
|
|
95
109
|
if (Array.isArray(value)) {
|
|
96
|
-
lines.push(...wrap(arrayToSourceLines(value), before, after))
|
|
110
|
+
lines.push(...wrap(arrayToSourceLines(value, seen), before, after))
|
|
97
111
|
return
|
|
98
112
|
} else if (value && typeof value === 'object') {
|
|
99
|
-
lines.push(...wrap(objectToSourceLines(value), before, after))
|
|
113
|
+
lines.push(...wrap(objectToSourceLines(value, seen), before, after))
|
|
100
114
|
return
|
|
101
115
|
} else if (typeof value === 'string') {
|
|
102
116
|
result = value.includes('\'') ? `\`${value}\`` : `'${value}'`
|
|
@@ -3,22 +3,28 @@ import type { Variant } from '../types'
|
|
|
3
3
|
|
|
4
4
|
const isObject = (val) => val !== null && typeof val === 'object'
|
|
5
5
|
|
|
6
|
-
export function toRawDeep (val) {
|
|
6
|
+
export function toRawDeep (val, seen = new Set()) {
|
|
7
7
|
const unwrappedValue = isRef(val) ? unref(val) : val
|
|
8
8
|
|
|
9
|
+
if (seen.has(unwrappedValue)) {
|
|
10
|
+
return Array.isArray(unwrappedValue) ? [] : {}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
seen.add(unwrappedValue)
|
|
14
|
+
|
|
9
15
|
if (!isObject(unwrappedValue)) {
|
|
10
16
|
return unwrappedValue
|
|
11
17
|
}
|
|
12
18
|
|
|
13
19
|
if (Array.isArray(unwrappedValue)) {
|
|
14
|
-
return unwrappedValue.map(toRawDeep)
|
|
20
|
+
return unwrappedValue.map(value => toRawDeep(value, seen))
|
|
15
21
|
}
|
|
16
22
|
|
|
17
|
-
return toRawObject(unwrappedValue)
|
|
23
|
+
return toRawObject(unwrappedValue, seen)
|
|
18
24
|
}
|
|
19
25
|
|
|
20
|
-
const toRawObject = (obj: Record<any, any
|
|
21
|
-
raw[key] = toRawDeep(obj[key])
|
|
26
|
+
const toRawObject = (obj: Record<any, any>, seen = new Set()) => Object.keys(obj).reduce((raw, key) => {
|
|
27
|
+
raw[key] = toRawDeep(obj[key], seen)
|
|
22
28
|
return raw
|
|
23
29
|
}, {})
|
|
24
30
|
|