13 | {/each}
14 |
--------------------------------------------------------------------------------
/Ch4_Code_Practical_Svelte/sourcing fake products/app.svelte - style.txt:
--------------------------------------------------------------------------------
1 |
27 |
--------------------------------------------------------------------------------
/Ch5_Code_Practical_Svelte/lifecycle methods - part 1/app.svelte.txt:
--------------------------------------------------------------------------------
1 |
11 |
12 |
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Apress Source Code
2 |
3 | This repository accompanies [*Practical Svelte*](https://www.apress.com/9781484273739) by Alex Libby (Apress, 2022).
4 |
5 | [comment]: #cover
6 | 
7 |
8 | Download the files as a zip using the green button, or clone the repository to your machine using Git.
9 |
10 | ## Releases
11 |
12 | Release v1.0 corresponds to the code in the published book, without corrections or updates.
13 |
14 | ## Contributions
15 |
16 | See the file Contributing.md for more information on how you can contribute to this repository.
--------------------------------------------------------------------------------
/Ch7_Code_Practical_Svelte/3A - Header & footer/header markup.txt:
--------------------------------------------------------------------------------
1 |
2 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/Contributing.md:
--------------------------------------------------------------------------------
1 | # Contributing to Apress Source Code
2 |
3 | Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers.
4 |
5 | ## How to Contribute
6 |
7 | 1. Make sure you have a GitHub account.
8 | 2. Fork the repository for the relevant book.
9 | 3. Create a new branch on which to make your change, e.g.
10 | `git checkout -b my_code_contribution`
11 | 4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted.
12 | 5. Submit a pull request.
13 |
14 | Thank you for your contribution!
--------------------------------------------------------------------------------
/Ch6_Code_Practical_Svelte/one at a time/audio player code.txt:
--------------------------------------------------------------------------------
1 |
4 |
5 |
11 |
12 |
17 |
18 |
--------------------------------------------------------------------------------
/Ch7_Code_Practical_Svelte/3A - Header & footer/header styling.txt:
--------------------------------------------------------------------------------
1 |
35 |
--------------------------------------------------------------------------------
/Ch2_Code_Practical_Svelte/src/components/Footer.svelte:
--------------------------------------------------------------------------------
1 |
10 |
11 |
14 |
15 |
--------------------------------------------------------------------------------
/Ch7_Code_Practical_Svelte/3C - Products, Product Pages and Cart/styling - cart.txt:
--------------------------------------------------------------------------------
1 |
38 |
--------------------------------------------------------------------------------
/Ch11_Code_Practical_Svelte/custom easing using css/app.svelte - css.txt:
--------------------------------------------------------------------------------
1 |
28 |
--------------------------------------------------------------------------------
/Ch2_Code_Practical_Svelte/images/instagram.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Ch6_Code_Practical_Svelte/contact form/contact - script block.txt:
--------------------------------------------------------------------------------
1 |
31 |
--------------------------------------------------------------------------------
/Ch2_Code_Practical_Svelte/images/facebook.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Ch2_Code_Practical_Svelte/src/App.svelte:
--------------------------------------------------------------------------------
1 |
13 |
14 |
17 |
18 |
19 |
20 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/Ch2_Code_Practical_Svelte/src/pages/About.svelte:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
About Us
7 |
8 |
9 |
10 |
11 |
12 |
13 |
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sed odio id nulla gravida rhoncus. Suspendisse potenti. In volutpat nibh non tellus laoreet, vitae faucibus ipsum sollicitudin. Duis viverra pulvinar tempus. Phasellus odio nunc, imperdiet vitae diam quis, sollicitudin pretium massa. Donec molestie mauris id semper sagittis.
14 |
Vivamus euismod arcu non velit pulvinar, in egestas mauris tincidunt. Vivamus eget elit non est semper elementum. Quisque turpis elit, tristique eu elit at, rhoncus ullamcorper eros. Integer efficitur efficitur libero, venenatis rhoncus sapien posuere ut. Nulla semper, magna at luctus luctus, orci lacus scelerisque erat, id consequat quam mauris sed neque.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sed odio id nulla gravida rhoncus. Suspendisse potenti. In volutpat nibh non tellus laoreet, vitae faucibus ipsum sollicitudin. Duis viverra pulvinar tempus. Phasellus odio nunc, imperdiet vitae diam quis, sollicitudin pretium massa. Donec molestie mauris id semper sagittis.
18 |
Vivamus euismod arcu non velit pulvinar, in egestas mauris tincidunt. Vivamus eget elit non est semper elementum. Quisque turpis elit, tristique eu elit at, rhoncus ullamcorper eros. Integer efficitur efficitur libero, venenatis rhoncus sapien posuere ut. Nulla semper, magna at luctus luctus, orci lacus scelerisque erat, id consequat quam mauris sed neque.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sed odio id nulla gravida rhoncus. Suspendisse potenti. In volutpat nibh non tellus laoreet, vitae faucibus ipsum sollicitudin. Duis viverra pulvinar tempus. Phasellus odio nunc, imperdiet vitae diam quis, sollicitudin pretium massa. Donec molestie mauris id semper sagittis.
13 |
14 | New Arrivals
15 |
16 |
17 |
18 |
19 |
20 |
21 |
Vivamus euismod arcu non velit pulvinar, in egestas mauris tincidunt. Vivamus eget elit non est semper elementum. Quisque turpis elit, tristique eu elit at, rhoncus ullamcorper eros. Integer efficitur efficitur libero, venenatis rhoncus sapien posuere ut. Nulla semper, magna at luctus luctus, orci lacus scelerisque erat, id consequat quam mauris sed neque.
22 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Freeware License, some rights reserved
2 |
3 | Copyright (c) 2022 Alex Libby
4 |
5 | Permission is hereby granted, free of charge, to anyone obtaining a copy
6 | of this software and associated documentation files (the "Software"),
7 | to work with the Software within the limits of freeware distribution and fair use.
8 | This includes the rights to use, copy, and modify the Software for personal use.
9 | Users are also allowed and encouraged to submit corrections and modifications
10 | to the Software for the benefit of other users.
11 |
12 | It is not allowed to reuse, modify, or redistribute the Software for
13 | commercial use in any way, or for a user’s educational materials such as books
14 | or blog articles without prior permission from the copyright holder.
15 |
16 | The above copyright notice and this permission notice need to be included
17 | in all copies or substantial portions of the software.
18 |
19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 | SOFTWARE.
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Ch2_Code_Practical_Svelte/src/components/Cart.svelte:
--------------------------------------------------------------------------------
1 |
30 |
31 |
34 |
35 |
60 | {#each todos.filter(t => !t.done) as todo (todo.id)}
61 |
68 | {/each}
69 |
70 |
71 |
72 |
119 |
--------------------------------------------------------------------------------
/Ch1_Code_Practical_Svelte/README.md:
--------------------------------------------------------------------------------
1 | *Looking for a shareable component template? Go here --> [sveltejs/component-template](https://github.com/sveltejs/component-template)*
2 |
3 | ---
4 |
5 | # svelte app
6 |
7 | This is a project template for [Svelte](https://svelte.dev) apps. It lives at https://github.com/sveltejs/template.
8 |
9 | To create a new project based on this template using [degit](https://github.com/Rich-Harris/degit):
10 |
11 | ```bash
12 | npx degit sveltejs/template svelte-app
13 | cd svelte-app
14 | ```
15 |
16 | *Note that you will need to have [Node.js](https://nodejs.org) installed.*
17 |
18 |
19 | ## Get started
20 |
21 | Install the dependencies...
22 |
23 | ```bash
24 | cd svelte-app
25 | npm install
26 | ```
27 |
28 | ...then start [Rollup](https://rollupjs.org):
29 |
30 | ```bash
31 | npm run dev
32 | ```
33 |
34 | Navigate to [localhost:5000](http://localhost:5000). You should see your app running. Edit a component file in `src`, save it, and reload the page to see your changes.
35 |
36 | By default, the server will only respond to requests from localhost. To allow connections from other computers, edit the `sirv` commands in package.json to include the option `--host 0.0.0.0`.
37 |
38 | If you're using [Visual Studio Code](https://code.visualstudio.com/) we recommend installing the official extension [Svelte for VS Code](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode). If you are using other editors you may need to install a plugin in order to get syntax highlighting and intellisense.
39 |
40 | ## Building and running in production mode
41 |
42 | To create an optimised version of the app:
43 |
44 | ```bash
45 | npm run build
46 | ```
47 |
48 | You can run the newly built app with `npm run start`. This uses [sirv](https://github.com/lukeed/sirv), which is included in your package.json's `dependencies` so that the app will work when you deploy to platforms like [Heroku](https://heroku.com).
49 |
50 |
51 | ## Single-page app mode
52 |
53 | By default, sirv will only respond to requests that match files in `public`. This is to maximise compatibility with static fileservers, allowing you to deploy your app anywhere.
54 |
55 | If you're building a single-page app (SPA) with multiple routes, sirv needs to be able to respond to requests for *any* path. You can make it so by editing the `"start"` command in package.json:
56 |
57 | ```js
58 | "start": "sirv public --single"
59 | ```
60 |
61 | ## Using TypeScript
62 |
63 | This template comes with a script to set up a TypeScript development environment, you can run it immediately after cloning the template with:
64 |
65 | ```bash
66 | node scripts/setupTypeScript.js
67 | ```
68 |
69 | Or remove the script via:
70 |
71 | ```bash
72 | rm scripts/setupTypeScript.js
73 | ```
74 |
75 | ## Deploying to the web
76 |
77 | ### With [Vercel](https://vercel.com)
78 |
79 | Install `vercel` if you haven't already:
80 |
81 | ```bash
82 | npm install -g vercel
83 | ```
84 |
85 | Then, from within your project folder:
86 |
87 | ```bash
88 | cd public
89 | vercel deploy --name my-project
90 | ```
91 |
92 | ### With [surge](https://surge.sh/)
93 |
94 | Install `surge` if you haven't already:
95 |
96 | ```bash
97 | npm install -g surge
98 | ```
99 |
100 | Then, from within your project folder:
101 |
102 | ```bash
103 | npm run build
104 | surge public my-project.surge.sh
105 | ```
106 |
--------------------------------------------------------------------------------
/Ch1_Code_Practical_Svelte/scripts/setupTypeScript.js:
--------------------------------------------------------------------------------
1 | // @ts-check
2 |
3 | /** This script modifies the project to support TS code in .svelte files like:
4 |
5 |
8 |
9 | As well as validating the code for CI.
10 | */
11 |
12 | /** To work on this script:
13 | rm -rf test-template template && git clone sveltejs/template test-template && node scripts/setupTypeScript.js test-template
14 | */
15 |
16 | const fs = require("fs")
17 | const path = require("path")
18 | const { argv } = require("process")
19 |
20 | const projectRoot = argv[2] || path.join(__dirname, "..")
21 |
22 | // Add deps to pkg.json
23 | const packageJSON = JSON.parse(fs.readFileSync(path.join(projectRoot, "package.json"), "utf8"))
24 | packageJSON.devDependencies = Object.assign(packageJSON.devDependencies, {
25 | "svelte-check": "^1.0.0",
26 | "svelte-preprocess": "^4.0.0",
27 | "@rollup/plugin-typescript": "^6.0.0",
28 | "typescript": "^3.9.3",
29 | "tslib": "^2.0.0",
30 | "@tsconfig/svelte": "^1.0.0"
31 | })
32 |
33 | // Add script for checking
34 | packageJSON.scripts = Object.assign(packageJSON.scripts, {
35 | "validate": "svelte-check"
36 | })
37 |
38 | // Write the package JSON
39 | fs.writeFileSync(path.join(projectRoot, "package.json"), JSON.stringify(packageJSON, null, " "))
40 |
41 | // mv src/main.js to main.ts - note, we need to edit rollup.config.js for this too
42 | const beforeMainJSPath = path.join(projectRoot, "src", "main.js")
43 | const afterMainTSPath = path.join(projectRoot, "src", "main.ts")
44 | fs.renameSync(beforeMainJSPath, afterMainTSPath)
45 |
46 | // Switch the app.svelte file to use TS
47 | const appSveltePath = path.join(projectRoot, "src", "App.svelte")
48 | let appFile = fs.readFileSync(appSveltePath, "utf8")
49 | appFile = appFile.replace("