Skip to content

Commit ff99d86

Browse files
committed
feat: add require prop
1 parent 1244ad5 commit ff99d86

File tree

11 files changed

+333
-33
lines changed

11 files changed

+333
-33
lines changed

demo/App.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
<VueLive :code="codeSfc" :layout="CustomLayout"/>
1111
<h2>Pure JavaScript code</h2>
1212
<VueLive :code="codeJs" :layout="CustomLayout"/>
13+
<h2>Use the requires prop to make libraries and packages available in the browser</h2>
14+
<VueLive :code="codeChicago" :layout="CustomLayout" :requires="chicagoRequires"/>
1315
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet">
1416
</main>
1517
</template>
@@ -21,6 +23,8 @@ import DatePicker from "vuejs-datepicker";
2123
import codeSfc from "!!raw-loader!./assets/Button.vue";
2224
import codeJs from "!!raw-loader!./assets/input.js";
2325
import codeTemplate from "!!raw-loader!./assets/PureTemplate.html";
26+
import codeChicago from "!!raw-loader!./assets/Chicago.jsx";
27+
import all from "./assets/chicagoNeighbourhoods";
2428
2529
export default {
2630
name: "VueLiveDemo",
@@ -31,7 +35,9 @@ export default {
3135
codeSfc,
3236
codeTemplate,
3337
codeJs,
34-
CustomLayout
38+
codeChicago,
39+
CustomLayout,
40+
chicagoRequires: { chicagoNeighbourhoods: all }
3541
};
3642
}
3743
};

demo/assets/Chicago.jsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import all from "chicagoNeighbourhoods";
2+
let i = 4;
3+
const four = [];
4+
while (i--) {
5+
let indexInList = Math.floor(Math.random() * all.length);
6+
four.push(all[indexInList]);
7+
}
8+
9+
<h3>What Chicago do you wish to visit tonight?</h3>
10+
<ul><li v-for="a in four">{{ a }}</li></ul>
Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
export default [
2+
"Albany Park",
3+
"Altgeld Gardens",
4+
"Andersonville",
5+
"Archer Heights",
6+
"Armour Square",
7+
"Ashburn",
8+
"Ashburn Estates",
9+
"Auburn Gresham",
10+
"Avalon Park",
11+
"Avondale",
12+
"Avondale Gardens",
13+
"Back of the Yards",
14+
"Belmont Central",
15+
"Belmont Gardens",
16+
"Belmont Heights",
17+
"Belmont Terrace",
18+
"Beverly",
19+
"Beverly View",
20+
"Beverly Woods",
21+
"Big Oaks",
22+
"Boystown",
23+
"Bowmanville",
24+
"Brainerd",
25+
"Brickyard",
26+
"Bridgeport",
27+
"Brighton Park",
28+
"Bronzeville",
29+
"Bucktown",
30+
"Budlong Woods",
31+
"Buena Park",
32+
"Burnside",
33+
"Cabrini–Green",
34+
"Calumet Heights",
35+
"Canaryville",
36+
"Central Station",
37+
"Chatham",
38+
"Chicago Lawn",
39+
"Chinatown",
40+
"Chrysler Village",
41+
"Clarendon Park",
42+
"Clearing East",
43+
"Clearing West",
44+
"Cottage Grove Heights",
45+
"Cragin",
46+
"Crestline",
47+
"Dearborn Homes",
48+
"Dearborn Park",
49+
"Douglas Park",
50+
"Dunning",
51+
"East Beverly",
52+
"East Chatham",
53+
"East Garfield Park",
54+
"East Hyde Park",
55+
"East Pilsen",
56+
"East Side",
57+
"East Village",
58+
"Eden Green",
59+
"Edgebrook",
60+
"Edgewater",
61+
"Edgewater Beach",
62+
"Edgewater Glen",
63+
"Edison Park",
64+
"Englewood",
65+
"Fernwood",
66+
"Fifth City",
67+
"Ford City",
68+
"Forest Glen",
69+
"Fuller Park",
70+
"Fulton River District",
71+
"Gage Park",
72+
"Galewood",
73+
"The Gap",
74+
"Garfield Ridge",
75+
"Gladstone Park",
76+
"Gold Coast",
77+
"Golden Gate",
78+
"Goose Island",
79+
"Graceland West",
80+
"Grand Boulevard",
81+
"Grand Crossing",
82+
"Greater Grand Crossing",
83+
"Greektown",
84+
"Gresham",
85+
"Groveland Park",
86+
"Hamilton Park",
87+
"Hanson Park",
88+
"Heart of Chicago",
89+
"Hegewisch",
90+
"Hermosa",
91+
"Hollywood Park",
92+
"Homan Square",
93+
"Humboldt Park",
94+
"Hyde Park",
95+
"Illinois Medical District",
96+
"Irving Park",
97+
"Irving Woods",
98+
"The Island",
99+
"Jackowo",
100+
"Jackson Park Highlands",
101+
"Jefferson Park",
102+
"K-Town",
103+
"Kelvyn Park",
104+
"Kennedy Park",
105+
"Kensington",
106+
"Kenwood",
107+
"Kilbourn Park",
108+
"Kosciuszko Park",
109+
"Lake Meadows",
110+
"Lake View",
111+
"Lake View East",
112+
"Lakewood / Balmoral",
113+
"LeClaire Courts",
114+
"Legends South (Robert Taylor Homes)",
115+
"Lilydale",
116+
"Lincoln Park",
117+
"Lincoln Square",
118+
"Lithuanian Plaza",
119+
"Little Italy",
120+
"Little Village",
121+
"Logan Square",
122+
"Longwood Manor",
123+
"The Loop",
124+
"Lower West Side",
125+
"Loyola",
126+
"Magnificent Mile",
127+
"Margate Park",
128+
"Marquette Park",
129+
"Marshall Square",
130+
"Marynook",
131+
"Mayfair",
132+
"McKinley Park",
133+
"Merchant Park",
134+
"Montclare",
135+
"Morgan Park",
136+
"Mount Greenwood",
137+
"Museum Campus",
138+
"New Eastside",
139+
"Near North Side",
140+
"Near West Side",
141+
"New Chinatown",
142+
"New City",
143+
"Noble Square",
144+
"North Austin",
145+
"North Center",
146+
"North Halsted",
147+
"North Kenwood",
148+
"North Lawndale",
149+
"North Mayfair",
150+
"North Park",
151+
"Nortown",
152+
"Norwood Park East",
153+
"Norwood Park West",
154+
"Oakland",
155+
"O'Hare",
156+
"Old Edgebrook",
157+
"Old Irving Park",
158+
"Old Norwood",
159+
"Old Town",
160+
"Old Town Triangle",
161+
"Oriole Park",
162+
"Palmer Square",
163+
"Park Manor",
164+
"Park West",
165+
"Parkview",
166+
"Peterson Park",
167+
"Pill Hill",
168+
"Pilsen",
169+
"Polish Downtown",
170+
"Polish Village",
171+
"Portage Park",
172+
"Prairie Avenue Historic District",
173+
"Prairie Shores",
174+
"Princeton Park",
175+
"Printer's Row",
176+
"Pulaski Park",
177+
"Pullman",
178+
"Ranch Triangle",
179+
"Ravenswood",
180+
"Ravenswood Gardens",
181+
"Ravenswood Manor",
182+
"River North",
183+
"River West",
184+
"River's Edge",
185+
"Riverdale",
186+
"Rogers Park",
187+
"Roscoe Village",
188+
"Rosehill",
189+
"Roseland",
190+
"Rosemoor",
191+
"Saint Ben's",
192+
"Sauganash",
193+
"Schorsch Forest View",
194+
"Schorsch Village",
195+
"Scottsdale",
196+
"Sheffield Neighbors",
197+
"Sheridan Park",
198+
"Sheridan Station Corridor",
199+
"Sleepy Hollow",
200+
"Smith Park",
201+
"South Austin",
202+
"South Chicago",
203+
"South Commons",
204+
"South Deering",
205+
"South East Ravenswood",
206+
"South Edgebrook",
207+
"South Lawndale",
208+
"South Loop",
209+
"South Shore",
210+
"Stateway Gardens",
211+
"Stony Island Park",
212+
"Streeterville",
213+
"Talley's Corner",
214+
"Tri-Taylor",
215+
"Ukrainian Village",
216+
"Union Ridge",
217+
"University Village",
218+
"Uptown",
219+
"The Villa",
220+
"Vittum Park",
221+
"Wacławowo",
222+
"Washington Heights",
223+
"Washington Park",
224+
"Wentworth Gardens",
225+
"West Beverly",
226+
"West Chatham",
227+
"West Chesterfield",
228+
"West DePaul",
229+
"West Elsdon",
230+
"West Englewood",
231+
"West Garfield Park",
232+
"West Humboldt Park",
233+
"West Lakeview",
234+
"West Lawn",
235+
"West Loop",
236+
"West Morgan Park",
237+
"West Pullman",
238+
"West Ridge",
239+
"West Rogers Park",
240+
"West Town",
241+
"West Woodlawn",
242+
"Wicker Park",
243+
"Wildwood",
244+
"Woodlawn",
245+
"Wrightwood",
246+
"Wrightwood Neighbors",
247+
"Wrigleyville"
248+
];

jest.config.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
11
module.exports = {
2-
moduleFileExtensions: [
3-
'js',
4-
'jsx',
5-
'json',
6-
'vue'
7-
],
2+
moduleFileExtensions: ["js", "jsx", "json", "vue"],
83
transform: {
9-
'^.+\\.vue$': 'vue-jest',
10-
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
11-
'^.+\\.jsx?$': 'babel-jest'
4+
"^.+\\.vue$": "vue-jest",
5+
".+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$":
6+
"jest-transform-stub",
7+
"^.+\\.jsx?$": "babel-jest"
128
},
13-
transformIgnorePatterns: [
14-
'/node_modules/'
15-
],
9+
transformIgnorePatterns: ["/node_modules/"],
1610
moduleNameMapper: {
17-
'^@/(.*)$': '<rootDir>/src/$1'
11+
"^@/(.*)$": "<rootDir>/src/$1"
1812
},
19-
snapshotSerializers: [
20-
'jest-serializer-vue'
21-
],
13+
snapshotSerializers: ["jest-serializer-vue"],
2214
testMatch: [
23-
'**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)'
15+
"**/tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)"
2416
],
25-
testURL: 'http://localhost/',
17+
testURL: "http://localhost/",
2618
watchPlugins: [
27-
'jest-watch-typeahead/filename',
28-
'jest-watch-typeahead/testname'
19+
"jest-watch-typeahead/filename",
20+
"jest-watch-typeahead/testname"
2921
]
30-
}
22+
};

src/Preview.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export default {
2222
components: {
2323
type: Object,
2424
default: () => {}
25+
},
26+
requires: {
27+
type: Object,
28+
default: () => {}
2529
}
2630
},
2731
data() {
@@ -71,7 +75,7 @@ export default {
7175
// - a script setting up variables => we set up the data property of renderedComponent
7276
// - a `new Vue()` script that will return a full config object
7377
script = renderedComponent.script;
74-
data = getVueConfigObject(script, listVars) || {};
78+
data = getVueConfigObject(script, listVars, this.requires) || {};
7579
}
7680
if (renderedComponent.html) {
7781
// if this is a pure template or if we are in hybrid vsg mode,

src/VueLive.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
:code="model"
1010
@detect-language="switchLanguage"
1111
:components="components"
12+
:requires="requires"
1213
/>
1314
</template>
1415
</VueLiveLayout>
@@ -47,6 +48,10 @@ export default {
4748
components: {
4849
type: Object,
4950
default: () => {}
51+
},
52+
requires: {
53+
type: Object,
54+
default: () => {}
5055
}
5156
},
5257
data() {

src/utils/__tests__/getVueConfigObject.unit.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ import getVueConfigObject from "../getVueConfigObject";
22

33
describe("getVueConfigObject", () => {
44
it("should extract parameters", () => {
5-
const data = getVueConfigObject("new Vue({param:'baz'})", []);
5+
const data = getVueConfigObject("new Vue({param:'baz'})", [], {});
66
expect(data.param).toBe("baz");
77
});
88

99
it("should assign variables to data", () => {
10-
const data = getVueConfigObject("var foo = 'baz'; new Vue({})", ["foo"]);
10+
const data = getVueConfigObject(
11+
"var foo = 'baz'; new Vue({})",
12+
["foo"],
13+
{}
14+
);
1115
expect(data.data().foo).toBe("baz");
1216
});
1317
});

0 commit comments

Comments
 (0)