histoire 0.7.3 → 0.7.4
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/client.d.ts +1 -1
- package/dist/bundled/StoryView.js +22 -19
- package/dist/bundled/dark.js +4 -0
- package/dist/bundled/index.js +0 -1
- package/dist/bundled/index2.js +6 -6
- package/dist/bundled/mapping.js +78 -0
- package/dist/bundled/sandbox.js +7 -6
- package/dist/bundled/state.js +4 -39
- package/dist/bundled/style.css +3 -3
- package/dist/client/app/App.vue +2 -2
- package/dist/client/app/components/panel/ControlsComponentPropItem.vue +13 -6
- package/dist/client/app/components/panel/ControlsComponentProps.vue +2 -1
- package/dist/client/app/components/panel/StatePresets.vue +2 -1
- package/dist/client/app/components/panel/StoryControls.vue +1 -1
- package/dist/client/app/components/panel/StorySourceCode.vue +2 -2
- package/dist/client/app/components/story/StoryVariantGridItem.vue +1 -1
- package/dist/client/app/components/story/StoryVariantSinglePreviewNative.vue +1 -1
- package/dist/client/app/components/story/StoryVariantSinglePreviewRemote.vue +3 -2
- package/dist/client/app/components/story/StoryVariantSingleView.vue +1 -1
- package/dist/client/app/components/toolbar/StoryVariantNewTab.vue +1 -1
- package/dist/client/app/components/tree/StoryGroup.vue +1 -1
- package/dist/client/app/index.js +0 -2
- package/dist/client/app/sandbox.js +4 -5
- package/dist/client/app/types.d.ts +1 -52
- package/dist/client/app/util/mapping.d.ts +1 -1
- package/dist/client/app/util/mapping.js +50 -36
- package/dist/client/app/{components/sandbox/lib.d.ts → util/sandbox.d.ts} +1 -1
- package/dist/client/app/{components/sandbox/lib.js → util/sandbox.js} +1 -1
- package/dist/client/app/util/state.d.ts +0 -4
- package/dist/client/app/util/state.js +3 -39
- package/dist/node/collect/index.d.ts +2 -2
- package/dist/node/collect/index.js +3 -0
- package/dist/node/collect/run.d.ts +2 -0
- package/dist/{client/server/index.js → node/collect/run.js} +1 -1
- package/dist/node/collect/worker.d.ts +3 -3
- package/dist/node/collect/worker.js +4 -1
- package/dist/node/config.d.ts +3 -3
- package/dist/node/context.d.ts +2 -2
- package/dist/node/plugin.d.ts +3 -3
- package/dist/node/stories.d.ts +4 -4
- package/dist/node/tree.d.ts +3 -22
- package/package.json +4 -2
- package/src/client/app/App.vue +2 -2
- package/src/client/app/components/panel/ControlsComponentPropItem.vue +13 -6
- package/src/client/app/components/panel/ControlsComponentProps.vue +2 -1
- package/src/client/app/components/panel/StatePresets.vue +2 -1
- package/src/client/app/components/panel/StoryControls.vue +1 -1
- package/src/client/app/components/panel/StorySourceCode.vue +2 -2
- package/src/client/app/components/story/StoryVariantGridItem.vue +1 -1
- package/src/client/app/components/story/StoryVariantSinglePreviewNative.vue +1 -1
- package/src/client/app/components/story/StoryVariantSinglePreviewRemote.vue +3 -2
- package/src/client/app/components/story/StoryVariantSingleView.vue +1 -1
- package/src/client/app/components/toolbar/StoryVariantNewTab.vue +1 -1
- package/src/client/app/components/tree/StoryGroup.vue +1 -1
- package/src/client/app/index.ts +0 -2
- package/src/client/app/sandbox.ts +4 -5
- package/src/client/app/types.ts +6 -57
- package/src/client/app/util/mapping.ts +47 -34
- package/src/client/app/{components/sandbox/lib.ts → util/sandbox.ts} +2 -2
- package/src/client/app/util/state.ts +4 -39
- package/src/node/collect/index.ts +5 -2
- package/src/node/collect/run.ts +13 -0
- package/src/node/collect/worker.ts +8 -6
- package/src/node/config.ts +3 -3
- package/src/node/context.ts +2 -2
- package/src/node/plugin.ts +2 -2
- package/src/node/server.ts +2 -2
- package/src/node/stories.ts +4 -4
- package/src/node/tree.ts +7 -31
- package/vite.config.ts +12 -7
- package/dist/bundled/SandboxVue3.js +0 -717
- package/dist/bundled/global-components.js +0 -213
- package/dist/client/app/codegen/const.d.ts +0 -1
- package/dist/client/app/codegen/const.js +0 -3
- package/dist/client/app/codegen/serialize-js.d.ts +0 -1
- package/dist/client/app/codegen/serialize-js.js +0 -126
- package/dist/client/app/codegen/util.d.ts +0 -10
- package/dist/client/app/codegen/util.js +0 -70
- package/dist/client/app/codegen/vue3.d.ts +0 -4
- package/dist/client/app/codegen/vue3.js +0 -357
- package/dist/client/app/components/exposed/Story.vue +0 -106
- package/dist/client/app/components/exposed/Variant.vue +0 -78
- package/dist/client/app/components/sandbox/RouterLinkStub.d.ts +0 -21
- package/dist/client/app/components/sandbox/RouterLinkStub.js +0 -43
- package/dist/client/app/components/sandbox/SandboxVue3.vue +0 -185
- package/dist/client/app/global-components.d.ts +0 -2
- package/dist/client/app/global-components.js +0 -10
- package/dist/client/server/index.d.ts +0 -7
- package/dist/client/server/vue3/Story.vue +0 -120
- package/dist/client/server/vue3/Variant.vue +0 -52
- package/dist/client/server/vue3/run.d.ts +0 -2
- package/dist/client/server/vue3/run.js +0 -45
- package/dist/node/types.d.ts +0 -50
- package/dist/node/types.js +0 -1
- package/src/client/app/codegen/const.ts +0 -3
- package/src/client/app/codegen/serialize-js.ts +0 -133
- package/src/client/app/codegen/util.ts +0 -79
- package/src/client/app/codegen/vue3.ts +0 -361
- package/src/client/app/components/exposed/Story.vue +0 -106
- package/src/client/app/components/exposed/Variant.vue +0 -78
- package/src/client/app/components/sandbox/RouterLinkStub.ts +0 -49
- package/src/client/app/components/sandbox/SandboxVue3.vue +0 -185
- package/src/client/app/global-components.ts +0 -13
- package/src/client/server/index.ts +0 -19
- package/src/client/server/vue3/Story.vue +0 -120
- package/src/client/server/vue3/Variant.vue +0 -52
- package/src/client/server/vue3/run.ts +0 -55
- package/src/components.d.ts +0 -143
- package/src/node/types.ts +0 -53
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
import { markRaw, defineComponent, useAttrs, getCurrentInstance, inject, watch, computed, provide, h } from "vue";
|
|
21
|
-
import { registerVueComponents } from "@histoire/controls";
|
|
22
|
-
import { a as applyStateToVariant } from "./state.js";
|
|
23
|
-
const copiedFromExistingVariant = [
|
|
24
|
-
"state",
|
|
25
|
-
"slots",
|
|
26
|
-
"initState",
|
|
27
|
-
"source",
|
|
28
|
-
"responsiveDisabled",
|
|
29
|
-
"setupApp",
|
|
30
|
-
"configReady",
|
|
31
|
-
"previewReady"
|
|
32
|
-
];
|
|
33
|
-
function mapFile(file, existingFile) {
|
|
34
|
-
const result = __spreadProps(__spreadValues({}, file), {
|
|
35
|
-
component: markRaw(file.component),
|
|
36
|
-
story: __spreadProps(__spreadValues({}, file.story), {
|
|
37
|
-
title: file.story.title,
|
|
38
|
-
file: markRaw(file),
|
|
39
|
-
variants: file.story.variants.map((v) => mapVariant(v)),
|
|
40
|
-
slots: () => ({})
|
|
41
|
-
})
|
|
42
|
-
});
|
|
43
|
-
if (existingFile) {
|
|
44
|
-
for (const index in result.story.variants) {
|
|
45
|
-
const variant = result.story.variants[index];
|
|
46
|
-
const existingVariant = existingFile.story.variants[index];
|
|
47
|
-
if (existingVariant) {
|
|
48
|
-
for (const key of copiedFromExistingVariant) {
|
|
49
|
-
if (typeof existingVariant[key] !== "undefined") {
|
|
50
|
-
if (key === "state") {
|
|
51
|
-
variant.state = existingVariant.state;
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
variant[key] = existingVariant[key];
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
if (existingFile.story.lastSelectedVariant) {
|
|
60
|
-
result.story.lastSelectedVariant = result.story.variants.find((v) => v.id === existingFile.story.lastSelectedVariant.id);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return result;
|
|
64
|
-
}
|
|
65
|
-
function mapVariant(variant) {
|
|
66
|
-
return __spreadProps(__spreadValues({}, variant), {
|
|
67
|
-
state: null,
|
|
68
|
-
initState: null,
|
|
69
|
-
setupApp: null,
|
|
70
|
-
slots: () => ({}),
|
|
71
|
-
previewReady: false
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
const _sfc_main$1 = defineComponent({
|
|
75
|
-
name: "Variant",
|
|
76
|
-
__histoireType: "variant",
|
|
77
|
-
props: {
|
|
78
|
-
initState: {
|
|
79
|
-
type: Function,
|
|
80
|
-
default: null
|
|
81
|
-
},
|
|
82
|
-
source: {
|
|
83
|
-
type: String,
|
|
84
|
-
default: null
|
|
85
|
-
},
|
|
86
|
-
responsiveDisabled: {
|
|
87
|
-
type: Boolean,
|
|
88
|
-
default: false
|
|
89
|
-
},
|
|
90
|
-
setupApp: {
|
|
91
|
-
type: Function,
|
|
92
|
-
default: null
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
setup(props) {
|
|
96
|
-
const attrs = useAttrs();
|
|
97
|
-
const vm = getCurrentInstance();
|
|
98
|
-
const implicitState = inject("implicitState");
|
|
99
|
-
watch(() => implicitState, (value) => {
|
|
100
|
-
applyStateToVariant(attrs.variant, value());
|
|
101
|
-
}, {
|
|
102
|
-
immediate: true
|
|
103
|
-
});
|
|
104
|
-
function updateVariant() {
|
|
105
|
-
Object.assign(attrs.variant, {
|
|
106
|
-
initState: async () => {
|
|
107
|
-
if (typeof props.initState === "function") {
|
|
108
|
-
const state = await props.initState();
|
|
109
|
-
applyStateToVariant(attrs.variant, state);
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
slots: () => vm.proxy.$slots,
|
|
113
|
-
source: props.source,
|
|
114
|
-
responsiveDisabled: props.responsiveDisabled,
|
|
115
|
-
setupApp: props.setupApp,
|
|
116
|
-
configReady: true
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
updateVariant();
|
|
120
|
-
return {
|
|
121
|
-
updateVariant
|
|
122
|
-
};
|
|
123
|
-
},
|
|
124
|
-
render() {
|
|
125
|
-
this.updateVariant();
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
const _sfc_main = defineComponent({
|
|
130
|
-
name: "Story",
|
|
131
|
-
__histoireType: "story",
|
|
132
|
-
inheritAttrs: false,
|
|
133
|
-
props: {
|
|
134
|
-
initState: {
|
|
135
|
-
type: Function,
|
|
136
|
-
default: null
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
setup() {
|
|
140
|
-
const vm = getCurrentInstance();
|
|
141
|
-
const attrs = useAttrs();
|
|
142
|
-
const story = computed(() => attrs.story);
|
|
143
|
-
provide("story", story);
|
|
144
|
-
const storyComponent = vm.parent;
|
|
145
|
-
const implicitState = {
|
|
146
|
-
$data: storyComponent.data
|
|
147
|
-
};
|
|
148
|
-
function addImplicitState(key, value) {
|
|
149
|
-
if (typeof value === "function" || value && value.__file) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
implicitState[key] = value;
|
|
153
|
-
}
|
|
154
|
-
for (const key in storyComponent.exposed) {
|
|
155
|
-
addImplicitState(key, storyComponent.exposed[key]);
|
|
156
|
-
}
|
|
157
|
-
for (const key in storyComponent.devtoolsRawSetupState) {
|
|
158
|
-
addImplicitState(key, storyComponent.devtoolsRawSetupState[key]);
|
|
159
|
-
}
|
|
160
|
-
provide("implicitState", () => __spreadValues({}, implicitState));
|
|
161
|
-
function updateStory() {
|
|
162
|
-
Object.assign(attrs.story, {
|
|
163
|
-
slots: () => vm.proxy.$slots
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
return {
|
|
167
|
-
story,
|
|
168
|
-
updateStory
|
|
169
|
-
};
|
|
170
|
-
},
|
|
171
|
-
render() {
|
|
172
|
-
this.updateStory();
|
|
173
|
-
const [firstVariant] = this.story.variants;
|
|
174
|
-
if (firstVariant.id === "_default") {
|
|
175
|
-
return h(_sfc_main$1, __spreadValues({
|
|
176
|
-
variant: firstVariant,
|
|
177
|
-
initState: this.initState
|
|
178
|
-
}, this.$attrs), this.$slots);
|
|
179
|
-
}
|
|
180
|
-
let index = 0;
|
|
181
|
-
const applyAttrs = (vnodes2) => {
|
|
182
|
-
var _a, _b;
|
|
183
|
-
for (const vnode of vnodes2) {
|
|
184
|
-
if (((_a = vnode.type) == null ? void 0 : _a.__histoireType) === "variant") {
|
|
185
|
-
if (!vnode.props) {
|
|
186
|
-
vnode.props = {};
|
|
187
|
-
}
|
|
188
|
-
vnode.props.variant = this.story.variants[index];
|
|
189
|
-
if (!vnode.props.initState && !vnode.props["init-state"]) {
|
|
190
|
-
vnode.props.initState = this.initState;
|
|
191
|
-
}
|
|
192
|
-
for (const attr in this.$attrs) {
|
|
193
|
-
if (typeof vnode.props[attr] === "undefined") {
|
|
194
|
-
vnode.props[attr] = this.$attrs[attr];
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
index++;
|
|
198
|
-
} else if ((_b = vnode.children) == null ? void 0 : _b.length) {
|
|
199
|
-
applyAttrs(vnode.children);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
const vnodes = this.$slots.default();
|
|
204
|
-
applyAttrs(vnodes);
|
|
205
|
-
return vnodes;
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
function registerGlobalComponents(app) {
|
|
209
|
-
app.component("Story", _sfc_main);
|
|
210
|
-
app.component("Variant", _sfc_main$1);
|
|
211
|
-
registerVueComponents(app);
|
|
212
|
-
}
|
|
213
|
-
export { mapFile as m, registerGlobalComponents as r };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const voidElements: string[];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function serializeJs(value: any): string;
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
const KEY_ESCAPE_REG = /[\s-.:|#@$£*%]/;
|
|
2
|
-
const MAX_SINGLE_LINE_ARRAY_LENGTH = 3;
|
|
3
|
-
export function serializeJs(value) {
|
|
4
|
-
const seen = new Set();
|
|
5
|
-
if (value === undefined) {
|
|
6
|
-
return 'undefined';
|
|
7
|
-
}
|
|
8
|
-
if (value === null) {
|
|
9
|
-
return 'null';
|
|
10
|
-
}
|
|
11
|
-
if (typeof value === 'string') {
|
|
12
|
-
return `'${value}'`;
|
|
13
|
-
}
|
|
14
|
-
if (typeof value === 'boolean') {
|
|
15
|
-
return value ? 'true' : 'false';
|
|
16
|
-
}
|
|
17
|
-
if (Array.isArray(value)) {
|
|
18
|
-
return printLines(arrayToSourceLines(value, seen));
|
|
19
|
-
}
|
|
20
|
-
if (typeof value === 'object') {
|
|
21
|
-
return printLines(objectToSourceLines(value, seen));
|
|
22
|
-
}
|
|
23
|
-
if (value?.__autoBuildingObject) {
|
|
24
|
-
return value;
|
|
25
|
-
}
|
|
26
|
-
if (typeof value === 'function' && value.name) {
|
|
27
|
-
return value.name;
|
|
28
|
-
}
|
|
29
|
-
return value.toString();
|
|
30
|
-
}
|
|
31
|
-
function printLines(lines) {
|
|
32
|
-
return lines.map(line => ' '.repeat(line.spaces) + line.line).join('\n');
|
|
33
|
-
}
|
|
34
|
-
function objectToSourceLines(object, seen, indentCount = 0) {
|
|
35
|
-
if (seen.has(object)) {
|
|
36
|
-
object = {};
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
seen.add(object);
|
|
40
|
-
}
|
|
41
|
-
return createLines(indentCount, lines => {
|
|
42
|
-
lines.push('{');
|
|
43
|
-
lines.push(...createLines(1, lines => {
|
|
44
|
-
for (const key in object) {
|
|
45
|
-
const value = object[key];
|
|
46
|
-
let printedKey = key;
|
|
47
|
-
if (KEY_ESCAPE_REG.test(key)) {
|
|
48
|
-
printedKey = `'${printedKey}'`;
|
|
49
|
-
}
|
|
50
|
-
addLinesFromValue(lines, value, `${printedKey}: `, ',', seen);
|
|
51
|
-
}
|
|
52
|
-
}));
|
|
53
|
-
lines.push('}');
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
function arrayToSourceLines(array, seen, indentCount = 0) {
|
|
57
|
-
if (seen.has(array)) {
|
|
58
|
-
array = [];
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
seen.add(array);
|
|
62
|
-
}
|
|
63
|
-
return createLines(indentCount, lines => {
|
|
64
|
-
const contentLines = createLines(1, lines => {
|
|
65
|
-
for (const value of array) {
|
|
66
|
-
addLinesFromValue(lines, value, '', ',', seen);
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
if (contentLines.length === 0) {
|
|
70
|
-
lines.push('[]');
|
|
71
|
-
}
|
|
72
|
-
else if (contentLines.length <= MAX_SINGLE_LINE_ARRAY_LENGTH && !contentLines.some(line => line.spaces > 1)) {
|
|
73
|
-
const [first] = contentLines;
|
|
74
|
-
first.line = contentLines.map(({ line }) => line.substring(0, line.length - 1)).join(', ');
|
|
75
|
-
first.line = `[${first.line}]`;
|
|
76
|
-
first.spaces--;
|
|
77
|
-
lines.push(first);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
lines.push('[', ...contentLines, ']');
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
function createLines(indentCount, handler) {
|
|
85
|
-
const lines = [];
|
|
86
|
-
handler(lines);
|
|
87
|
-
return lines.map(line => {
|
|
88
|
-
if (line.spaces != null) {
|
|
89
|
-
line.spaces += indentCount;
|
|
90
|
-
return line;
|
|
91
|
-
}
|
|
92
|
-
return { spaces: indentCount, line };
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
function addLinesFromValue(lines, value, before, after, seen) {
|
|
96
|
-
let result;
|
|
97
|
-
if (Array.isArray(value)) {
|
|
98
|
-
lines.push(...wrap(arrayToSourceLines(value, seen), before, after));
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
else if (value && typeof value === 'object') {
|
|
102
|
-
lines.push(...wrap(objectToSourceLines(value, seen), before, after));
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
else if (typeof value === 'string') {
|
|
106
|
-
result = value.includes('\'') ? `\`${value}\`` : `'${value}'`;
|
|
107
|
-
}
|
|
108
|
-
else if (typeof value === 'undefined') {
|
|
109
|
-
result = 'undefined';
|
|
110
|
-
}
|
|
111
|
-
else if (value === null) {
|
|
112
|
-
result = 'null';
|
|
113
|
-
}
|
|
114
|
-
else if (typeof value === 'boolean') {
|
|
115
|
-
result = value ? 'true' : 'false';
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
result = value;
|
|
119
|
-
}
|
|
120
|
-
lines.push(before + result + after);
|
|
121
|
-
}
|
|
122
|
-
function wrap(lines, before, after) {
|
|
123
|
-
lines[0].line = before + lines[0].line;
|
|
124
|
-
lines[lines.length - 1].line += after;
|
|
125
|
-
return lines;
|
|
126
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare function indent(lines: string[], count?: number): string[];
|
|
2
|
-
export declare function unindent(code: string): string;
|
|
3
|
-
interface AutoBuildingOject {
|
|
4
|
-
key: string;
|
|
5
|
-
cache: Record<string | symbol, AutoBuildingOject>;
|
|
6
|
-
target: any;
|
|
7
|
-
proxy: any;
|
|
8
|
-
}
|
|
9
|
-
export declare function createAutoBuildingObject(format?: (key: string) => string, specialKeysHandler?: (target: any, p: string | symbol) => (() => unknown) | null, key?: string, depth?: number): AutoBuildingOject;
|
|
10
|
-
export {};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
|
-
export function indent(lines, count = 1) {
|
|
3
|
-
return lines.map(line => `${' '.repeat(count)}${line}`);
|
|
4
|
-
}
|
|
5
|
-
export function unindent(code) {
|
|
6
|
-
const lines = code.split('\n');
|
|
7
|
-
let indentLevel = -1;
|
|
8
|
-
let indentText;
|
|
9
|
-
const linesToAnalyze = lines.filter(line => line.trim().length > 0);
|
|
10
|
-
for (const line of linesToAnalyze) {
|
|
11
|
-
const match = /^\s*/.exec(line);
|
|
12
|
-
if (match && (indentLevel === -1 || indentLevel > match[0].length)) {
|
|
13
|
-
indentLevel = match[0].length;
|
|
14
|
-
indentText = match[0];
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
const result = [];
|
|
18
|
-
for (const line of lines) {
|
|
19
|
-
result.push(line.replace(indentText, ''));
|
|
20
|
-
}
|
|
21
|
-
return result.join('\n').trim();
|
|
22
|
-
}
|
|
23
|
-
export function createAutoBuildingObject(format, specialKeysHandler, key = '', depth = 0) {
|
|
24
|
-
const cache = {};
|
|
25
|
-
if (depth > 32)
|
|
26
|
-
return { key, cache, target: {}, proxy: () => key };
|
|
27
|
-
const target = () => {
|
|
28
|
-
const k = key + '()';
|
|
29
|
-
return format ? format(k) : k;
|
|
30
|
-
};
|
|
31
|
-
const proxy = new Proxy(target, {
|
|
32
|
-
get(_, p) {
|
|
33
|
-
if (p === '__autoBuildingObject') {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
if (p === '__autoBuildingObjectGetKey') {
|
|
37
|
-
return key;
|
|
38
|
-
}
|
|
39
|
-
if (specialKeysHandler) {
|
|
40
|
-
const fn = specialKeysHandler(target, p);
|
|
41
|
-
if (fn) {
|
|
42
|
-
return fn();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (p === 'toString') {
|
|
46
|
-
const k = key + '.toString()';
|
|
47
|
-
return () => format ? format(k) : k;
|
|
48
|
-
}
|
|
49
|
-
if (p === Symbol.toPrimitive) {
|
|
50
|
-
return () => format ? format(key) : key;
|
|
51
|
-
}
|
|
52
|
-
if (!cache[p]) {
|
|
53
|
-
const childKey = key ? `${key}.${p.toString()}` : p.toString();
|
|
54
|
-
const child = createAutoBuildingObject(format, specialKeysHandler, childKey, depth + 1);
|
|
55
|
-
cache[p] = { key: childKey, ...child };
|
|
56
|
-
}
|
|
57
|
-
return cache[p].proxy;
|
|
58
|
-
},
|
|
59
|
-
apply(_, thisArg, args) {
|
|
60
|
-
const k = `${key}(${args.join(', ')})`;
|
|
61
|
-
return format ? format(k) : k;
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
return {
|
|
65
|
-
key,
|
|
66
|
-
cache,
|
|
67
|
-
target,
|
|
68
|
-
proxy,
|
|
69
|
-
};
|
|
70
|
-
}
|