@mythrantic/svelte-rich-text 0.2.8

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.
Files changed (92) hide show
  1. package/README.md +289 -0
  2. package/dist/components/core/blockWrapper.svelte +88 -0
  3. package/dist/components/core/blockWrapper.svelte.d.ts +19 -0
  4. package/dist/components/core/editMode.svelte +95 -0
  5. package/dist/components/core/editMode.svelte.d.ts +16 -0
  6. package/dist/components/core/main.svelte +196 -0
  7. package/dist/components/core/main.svelte.d.ts +65 -0
  8. package/dist/components/core/toolBar.svelte +141 -0
  9. package/dist/components/core/toolBar.svelte.d.ts +16 -0
  10. package/dist/components/core/viewMode.svelte +28 -0
  11. package/dist/components/core/viewMode.svelte.d.ts +25 -0
  12. package/dist/components/editBlocks/code.svelte +68 -0
  13. package/dist/components/editBlocks/code.svelte.d.ts +24 -0
  14. package/dist/components/editBlocks/header.svelte +66 -0
  15. package/dist/components/editBlocks/header.svelte.d.ts +23 -0
  16. package/dist/components/editBlocks/img.svelte +47 -0
  17. package/dist/components/editBlocks/img.svelte.d.ts +24 -0
  18. package/dist/components/editBlocks/list.svelte +102 -0
  19. package/dist/components/editBlocks/list.svelte.d.ts +23 -0
  20. package/dist/components/editBlocks/paragraph.svelte +22 -0
  21. package/dist/components/editBlocks/paragraph.svelte.d.ts +26 -0
  22. package/dist/components/editBlocks/quote.svelte +57 -0
  23. package/dist/components/editBlocks/quote.svelte.d.ts +23 -0
  24. package/dist/components/editBlocks/space.svelte +24 -0
  25. package/dist/components/editBlocks/space.svelte.d.ts +22 -0
  26. package/dist/components/extra/dropDown.svelte +117 -0
  27. package/dist/components/extra/dropDown.svelte.d.ts +23 -0
  28. package/dist/components/extra/input.svelte +63 -0
  29. package/dist/components/extra/input.svelte.d.ts +21 -0
  30. package/dist/components/extra/select.svelte +50 -0
  31. package/dist/components/extra/select.svelte.d.ts +30 -0
  32. package/dist/components/extra/textarea.svelte +40 -0
  33. package/dist/components/extra/textarea.svelte.d.ts +21 -0
  34. package/dist/components/extra/upload.svelte +79 -0
  35. package/dist/components/extra/upload.svelte.d.ts +21 -0
  36. package/dist/components/icons/closeIcon.svelte +6 -0
  37. package/dist/components/icons/closeIcon.svelte.d.ts +25 -0
  38. package/dist/components/icons/closeQuoteIcon.svelte +9 -0
  39. package/dist/components/icons/closeQuoteIcon.svelte.d.ts +25 -0
  40. package/dist/components/icons/codeIcon.svelte +12 -0
  41. package/dist/components/icons/codeIcon.svelte.d.ts +25 -0
  42. package/dist/components/icons/copyIcon.svelte +12 -0
  43. package/dist/components/icons/copyIcon.svelte.d.ts +25 -0
  44. package/dist/components/icons/deleteIcon.svelte +12 -0
  45. package/dist/components/icons/deleteIcon.svelte.d.ts +25 -0
  46. package/dist/components/icons/doneIcon.svelte +17 -0
  47. package/dist/components/icons/doneIcon.svelte.d.ts +25 -0
  48. package/dist/components/icons/downIcon.svelte +12 -0
  49. package/dist/components/icons/downIcon.svelte.d.ts +25 -0
  50. package/dist/components/icons/headerIcon.svelte +12 -0
  51. package/dist/components/icons/headerIcon.svelte.d.ts +25 -0
  52. package/dist/components/icons/imageIcon.svelte +12 -0
  53. package/dist/components/icons/imageIcon.svelte.d.ts +25 -0
  54. package/dist/components/icons/listIcon.svelte +12 -0
  55. package/dist/components/icons/listIcon.svelte.d.ts +25 -0
  56. package/dist/components/icons/menuIcon.svelte +12 -0
  57. package/dist/components/icons/menuIcon.svelte.d.ts +25 -0
  58. package/dist/components/icons/openQuoteIcon.svelte +9 -0
  59. package/dist/components/icons/openQuoteIcon.svelte.d.ts +25 -0
  60. package/dist/components/icons/paragraphIcon.svelte +12 -0
  61. package/dist/components/icons/paragraphIcon.svelte.d.ts +25 -0
  62. package/dist/components/icons/plusIcon.svelte +3 -0
  63. package/dist/components/icons/plusIcon.svelte.d.ts +25 -0
  64. package/dist/components/icons/spaceIcon.svelte +9 -0
  65. package/dist/components/icons/spaceIcon.svelte.d.ts +25 -0
  66. package/dist/components/icons/upIcon.svelte +12 -0
  67. package/dist/components/icons/upIcon.svelte.d.ts +25 -0
  68. package/dist/components/icons/uploadIcon.svelte +9 -0
  69. package/dist/components/icons/uploadIcon.svelte.d.ts +25 -0
  70. package/dist/components/viewBlocks/viewCode.svelte +150 -0
  71. package/dist/components/viewBlocks/viewCode.svelte.d.ts +20 -0
  72. package/dist/components/viewBlocks/viewHeader.svelte +13 -0
  73. package/dist/components/viewBlocks/viewHeader.svelte.d.ts +19 -0
  74. package/dist/components/viewBlocks/viewImage.svelte +35 -0
  75. package/dist/components/viewBlocks/viewImage.svelte.d.ts +20 -0
  76. package/dist/components/viewBlocks/viewList.svelte +69 -0
  77. package/dist/components/viewBlocks/viewList.svelte.d.ts +19 -0
  78. package/dist/components/viewBlocks/viewParagraph.svelte +12 -0
  79. package/dist/components/viewBlocks/viewParagraph.svelte.d.ts +18 -0
  80. package/dist/components/viewBlocks/viewQuote.svelte +29 -0
  81. package/dist/components/viewBlocks/viewQuote.svelte.d.ts +19 -0
  82. package/dist/components/viewBlocks/viewSpace.svelte +4 -0
  83. package/dist/components/viewBlocks/viewSpace.svelte.d.ts +18 -0
  84. package/dist/index.d.ts +3 -0
  85. package/dist/index.js +13 -0
  86. package/dist/utils/consts.d.ts +96 -0
  87. package/dist/utils/consts.js +1 -0
  88. package/dist/utils/functions.d.ts +2 -0
  89. package/dist/utils/functions.js +12 -0
  90. package/dist/utils/stores.d.ts +6 -0
  91. package/dist/utils/stores.js +3 -0
  92. package/package.json +107 -0
package/README.md ADDED
@@ -0,0 +1,289 @@
1
+ # Valiant Rich Text Svelte Component
2
+
3
+ ![valiantlynx logo](./static/valiantlynx.jpg)
4
+
5
+ ## Introduction
6
+
7
+ The **Valiant Rich Text Svelte Component** is a powerful and versatile rich text editor for Svelte applications. It allows users to create, edit, and manage structured text content by adding various blocks with associated data. This component is designed to be highly customizable, responsive on mobile devices, and supportive of both editing and viewing modes.
8
+
9
+ ## Installation
10
+
11
+ To get started with the Valiant Rich Text Svelte Component, you can install it via your package manager of choice:
12
+
13
+ ```bash
14
+ npm install @valiantlynx/svelte-rich-text
15
+ # or
16
+ yarn add @valiantlynx/svelte-rich-text
17
+ # or
18
+ pnpm i @valiantlynx/svelte-rich-text
19
+ ```
20
+
21
+ ## Basic Usage
22
+
23
+ To use the valiantlynx Rich Text editor, import the `ValiantRichText` component and include it in your Svelte application.
24
+
25
+ ```svelte
26
+ <script>
27
+ import { ValiantRichText } from '@valiantlynx/svelte-rich-text';
28
+ </script>
29
+
30
+ <ValiantRichText />
31
+ ```
32
+
33
+ ## Data Structure
34
+
35
+ The rich text editor works with a specific data structure known as `dataBlock`. This type includes:
36
+
37
+ - `image`: Represents image blocks with data such as base64 representation, name, and caption.
38
+ - `paragraph`: Basic text blocks.
39
+ - `code`: Code blocks with text content and a specified programming language.
40
+ - `quote`: Text quotes with owner attribution.
41
+ - `header`: Header blocks with different levels (1 to 4) and associated text.
42
+ - `space`: Empty space blocks with a specified size.
43
+ - `list`: List blocks with items and an ordered or unordered list type.
44
+
45
+ ```ts
46
+ type dataBlock =
47
+ | { name: 'image'; id: string; data: { base64: string; name: string; caption: string } }
48
+ | { name: 'paragraph'; id: string; data: { text: string } }
49
+ | { name: 'code'; id: string; data: { text: string; lang: languages } }
50
+ | { name: 'quote'; id: string; data: { text: string; owner: string } }
51
+ | { name: 'header'; id: string; data: { text: string; level: 1 | 2 | 3 | 4 } }
52
+ | { name: 'space'; id: string; data: { size: number } }
53
+ | { name: 'list'; id: string; data: { items: string[]; type: 'ordered' | 'unordered' } };
54
+ ```
55
+
56
+ ### Block States
57
+
58
+ Each block in the Valiant Rich Text editor can exist in one of three states:
59
+
60
+ 1. **View State:** In this state, the block displays its information based on its type and associated data.
61
+ 2. **Focus State:** When a user clicks on a block, it switches to the focus state. In this state, the block is wrapped with a wrapper that provides options for deleting the block and reordering it (moving it up or down).
62
+ 3. **Edit State:** Upon another click, the block enters the edit state, allowing the user to modify the block's information. ## Customization
63
+
64
+ ## Customization
65
+
66
+ You can customize various aspects of the rich text editor:
67
+
68
+ - **Colors:**
69
+
70
+ - `primaryColor`: Used in both focus and view states.
71
+ - `secondaryColor`: Specifically used in the edit state.
72
+ - `textColor`: Defines the text color within the editor.
73
+ - `bgColor`: Specifies the background color of the editor.
74
+
75
+ - **Fonts:**
76
+
77
+ - `headerFont`: Set the font for header elements (e.g., h1, h2, h3, h4).
78
+ - `bodyFont`: Define the font for general text elements (e.g., p, span, label, li, a).
79
+
80
+ - **Font Sizes and Line Heights:**
81
+
82
+ - Customize font sizes using `h1`, `h2`, `h3`, `h4`, `body`, `small`.
83
+ - Set line heights for various text elements using `lh1`, `lh2`, `lh3`, `lh4`, and `lbody`.
84
+
85
+ - **Custom Code Themes:** Uses themes from `prism.js` for code blocks and highlights.
86
+
87
+ - **Initial Data:** You can prepopulate the editor with initial data by passing an array of `dataBlock` to the `initialData` prop.
88
+
89
+ - **Custom Code Block Languages:** Define the list of languages users can use for code blocks with the `codeBlockLanguages` prop. By default, it includes JavaScript, Java, C, CSS, TypeScript, Python, and C#.
90
+
91
+ - **Custom spacing:** By default **valiant** separate blocks with 10px gap and have **margin-block** set to 30px you can change that using **blocksGap** and **marginBlock** props .
92
+
93
+ - **Custom Components:** You can replace the default view components for various block types with your custom components. For example:
94
+ - `customImage` for image blocks
95
+ - `customCode` for code blocks
96
+ - `customList` for list blocks
97
+ - `customHeader` for header blocks
98
+ - `customParagraph` for paragraph blocks
99
+ - `customQuote` for quote blocks
100
+
101
+ ```ts
102
+ export let customImage: ComponentType<
103
+ SvelteComponent<{ base64: string; name: string; caption: string }>
104
+ > = ViewImage;
105
+
106
+ export let customCode: ComponentType<SvelteComponent<{ text: string; lang: languages }>> = ViewCode;
107
+
108
+ export let customList: ComponentType<
109
+ SvelteComponent<{ items: string[]; type: 'ordered' | 'unordered' }>
110
+ > = ViewList;
111
+
112
+ export let customHeader: ComponentType<SvelteComponent<{ text: string; level: 1 | 2 | 3 | 4 }>> =
113
+ ViewHeader;
114
+
115
+ export let customParagraph: ComponentType<SvelteComponent<{ text: string }>> = ViewParagraph;
116
+
117
+ export let customQuote: ComponentType<SvelteComponent<{ text: string; owner: string }>> = ViewQuote;
118
+ ```
119
+
120
+ ## View Mode
121
+
122
+ The Valiant Rich Text editor includes a `viewMode` prop, which, when set to `true`, allows you to use the editor in a read-only mode. In this mode, you can display existing content without enabling editing.
123
+
124
+ ```svelte
125
+ <script>
126
+ import { ValiantRichText } from '@valiantlynx/svelte-rich-text';
127
+ </script>
128
+
129
+ <ValiantRichText viewMode={true} />
130
+ ```
131
+
132
+ ## The getData Function
133
+
134
+ The package provides a function to retrieve the `dataBlock` at any given moment. Here is an example:
135
+
136
+ ```ts
137
+ <script>
138
+ import { ValiantRichText, getData } from '@valiantlynx/svelte-rich-text';
139
+ </script>
140
+
141
+ <ValiantRichText viewMode={true} />
142
+ <Button on:click={()=>{
143
+ const data = getData(); // returns dataBlock[] type
144
+ saveData(data);
145
+ }}>Save</Button>
146
+ ```
147
+
148
+ ## Svelte Highlight
149
+
150
+ The package uses `prism.js` for code highlighting. To use it, you need to import the `prism.css` file in your application. You can do this by adding the following line to your `index.html` file:
151
+
152
+ ```html
153
+ <svelte:head>
154
+ <!-- Include Prism.js and its CSS theme for syntax highlighting -->
155
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.25.0/prism.min.js"></script>
156
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.25.0/themes/prism-okaidia.min.css" />
157
+ </svelte:head>
158
+ ```
159
+
160
+ ## Props
161
+
162
+ Here are all ValiantRichText props and their default values:
163
+
164
+ ```ts
165
+ export let initialData: dataBlock[] = [];
166
+
167
+ export let viewMode = false;
168
+
169
+ export let blocksGap = 10;
170
+
171
+ export let marginBlock = 30;
172
+
173
+ export let headerFont = `Verdana, sans-serif`;
174
+
175
+ export let bodyFont = `Helvetica, sans-serif`;
176
+
177
+ export let primaryColor = '#3366FF';
178
+
179
+ export let secondaryColor = '#1eeb36';
180
+
181
+ export let textColor = '#121212';
182
+
183
+ export let bgColor = '#ffffff';
184
+
185
+ export let h1 = 'clamp(1.8rem, calc(1.8rem + ((1vw - 0.48rem) * 0.9722)), 2.1rem)';
186
+
187
+ export let h2 = 'clamp(1.5rem, calc(1.5rem + ((1vw - 0.48rem) * 0.9722)), 1.8rem)';
188
+
189
+ export let h3 = 'clamp(1.2rem, calc(1.2rem + ((1vw - 0.48rem) * 0.9722)), 1.5rem)';
190
+
191
+ export let h4 = 'clamp(1.125rem, calc(1.15rem + ((1vw - 0.48rem) * 0.3472)), 1.2rem)';
192
+
193
+ export let body = 'clamp(1rem, calc(1rem + ((1vw - 0.48rem) * 0.1736)), 1.125rem)';
194
+
195
+ export let small = 'clamp(0.875rem, calc(0.875rem + ((1vw - 0.48rem) * 0.1736)), 1rem)';
196
+
197
+ export let lh1 = '1.3';
198
+
199
+ export let lh2 = '1.35';
200
+
201
+ export let lh3 = '1.4';
202
+
203
+ export let lh4 = '1.5';
204
+
205
+ export let lbody = '1.6';
206
+
207
+ export let codeTheme: string = nightOwl;
208
+
209
+ export let customImage: ComponentType<
210
+ SvelteComponent<{ base64: string; name: string; caption: string }>
211
+ > = ViewImage;
212
+
213
+ export let customCode: ComponentType<SvelteComponent<{ text: string; lang: languages }>> = ViewCode;
214
+
215
+ export let customList: ComponentType<
216
+ SvelteComponent<{ items: string[]; type: 'ordered' | 'unordered' }>
217
+ > = ViewList;
218
+
219
+ export let customHeader: ComponentType<SvelteComponent<{ text: string; level: 1 | 2 | 3 | 4 }>> =
220
+ ViewHeader;
221
+
222
+ export let customParagraph: ComponentType<SvelteComponent<{ text: string }>> = ViewParagraph;
223
+
224
+ export let customQuote: ComponentType<SvelteComponent<{ text: string; owner: string }>> = ViewQuote;
225
+
226
+ export let codeBlockLanguages: languages[] = [
227
+ 'actionscript',
228
+ 'angular', // For Angular templates
229
+ 'assembly',
230
+ 'bash',
231
+ 'c',
232
+ 'clojure',
233
+ 'cobol',
234
+ 'cpp', // C++
235
+ 'csharp', // C#
236
+ 'css',
237
+ 'dart',
238
+ 'dockerfile',
239
+ 'elixir',
240
+ 'elm',
241
+ 'erlang',
242
+ 'fortran',
243
+ 'fsharp', // F#
244
+ 'graphql',
245
+ 'groovy',
246
+ 'haskell',
247
+ 'html',
248
+ 'java',
249
+ 'javascript',
250
+ 'json',
251
+ 'julia',
252
+ 'kotlin',
253
+ 'less',
254
+ 'lua',
255
+ 'markdown',
256
+ 'matlab',
257
+ 'nim',
258
+ 'nodejs',
259
+ 'objective-c',
260
+ 'ocaml',
261
+ 'pascal',
262
+ 'perl',
263
+ 'php',
264
+ 'plaintext',
265
+ 'powershell',
266
+ 'python',
267
+ 'r',
268
+ 'react', // JSX
269
+ 'reason', // ReasonML
270
+ 'ruby',
271
+ 'rust',
272
+ 'sass',
273
+ 'scala',
274
+ 'scheme',
275
+ 'shell', // General shell scripting
276
+ 'sql',
277
+ 'stylus',
278
+ 'svelte',
279
+ 'swift',
280
+ 'toml',
281
+ 'typescript',
282
+ 'vbnet', // Visual Basic .NET
283
+ 'vue',
284
+ 'wasm', // WebAssembly
285
+ 'xml',
286
+ 'yaml'
287
+ ];
288
+
289
+ ```
@@ -0,0 +1,88 @@
1
+ <script>import Code from "../editBlocks/code.svelte";
2
+ import Header from "../editBlocks/header.svelte";
3
+ import Img from "../editBlocks/img.svelte";
4
+ import List from "../editBlocks/list.svelte";
5
+ import Paragraph from "../editBlocks/paragraph.svelte";
6
+ import Quote from "../editBlocks/quote.svelte";
7
+ import { workingBlock } from "../../utils/stores.js";
8
+ import Space from "../editBlocks/space.svelte";
9
+ export let dataBlock;
10
+ $: active = $workingBlock && $workingBlock.state == "editing" && $workingBlock.id == dataBlock.id;
11
+ $: focused = $workingBlock && $workingBlock.state == "focused" && $workingBlock.id == dataBlock.id;
12
+ </script>
13
+
14
+ <div
15
+ class="blockWrapper"
16
+ class:focused
17
+ class:editing={active}
18
+ data-blockid={dataBlock.id}
19
+ data-blocktype={dataBlock.name}
20
+ >
21
+ {#if dataBlock.name == 'header'}
22
+ <Header id={dataBlock.id} content={dataBlock.data} {active} />
23
+ {:else if dataBlock.name == 'code'}
24
+ <Code content={dataBlock.data} id={dataBlock.id} {active} />
25
+ {:else if dataBlock.name == 'image'}
26
+ <Img id={dataBlock.id} content={dataBlock.data} {active} />
27
+ {:else if dataBlock.name == 'list'}
28
+ <List id={dataBlock.id} content={dataBlock.data} {active} />
29
+ {:else if dataBlock.name == 'paragraph'}
30
+ <Paragraph id={dataBlock.id} content={dataBlock.data} {active} />
31
+ {:else if dataBlock.name == 'quote'}
32
+ <Quote id={dataBlock.id} content={dataBlock.data} {active} />
33
+ {:else}
34
+ <Space id={dataBlock.id} content={dataBlock.data} {active} />
35
+ {/if}
36
+ <span class="blockType">{dataBlock.name}</span>
37
+ </div>
38
+
39
+ <style>
40
+ .blockWrapper {
41
+ width: 100%;
42
+ padding-top: 30px;
43
+ position: relative;
44
+ }
45
+
46
+ .focused {
47
+ border: 2px solid var(--primaryColor);
48
+ border-radius: 8px;
49
+ }
50
+
51
+ .focused,
52
+ .editing {
53
+ padding-bottom: 10px;
54
+ padding-inline: 15px;
55
+ }
56
+ .editing {
57
+ border: 2px solid var(--secondaryColor);
58
+ border-radius: 8px;
59
+ }
60
+
61
+ .focused .blockType,
62
+ .editing .blockType {
63
+ display: inline-block;
64
+ }
65
+ .focused .blockType {
66
+ background-color: var(--primaryColor);
67
+ }
68
+
69
+ .editing .blockType {
70
+ background-color: var(--secondaryColor);
71
+ }
72
+
73
+ .blockType {
74
+ position: absolute;
75
+ width: fit-content;
76
+ height: fit-content;
77
+ top: 0%;
78
+ right: 0%;
79
+ font-size: var(--small);
80
+ color: var(--textColor);
81
+ font-weight: bold;
82
+ display: none;
83
+ padding-inline: 12px;
84
+ padding-block: 2px;
85
+ border-bottom-left-radius: 12px;
86
+ text-transform: capitalize;
87
+ }
88
+ </style>
@@ -0,0 +1,19 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { dataBlock } from '../../utils/consts.js';
3
+ declare const __propDef: {
4
+ props: {
5
+ dataBlock: dataBlock;
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {};
11
+ exports?: {};
12
+ bindings?: string;
13
+ };
14
+ export type BlockWrapperProps = typeof __propDef.props;
15
+ export type BlockWrapperEvents = typeof __propDef.events;
16
+ export type BlockWrapperSlots = typeof __propDef.slots;
17
+ export default class BlockWrapper extends SvelteComponent<BlockWrapperProps, BlockWrapperEvents, BlockWrapperSlots> {
18
+ }
19
+ export {};
@@ -0,0 +1,95 @@
1
+ <script>import { data, workingBlock } from "../../utils/stores";
2
+ import { onMount } from "svelte";
3
+ import BlockWrapper from "./blockWrapper.svelte";
4
+ import ToolBar from "./toolBar.svelte";
5
+ import DropDown from "../extra/dropDown.svelte";
6
+ import UpIcon from "../icons/upIcon.svelte";
7
+ import DeleteIcon from "../icons/deleteIcon.svelte";
8
+ import DownIcon from "../icons/downIcon.svelte";
9
+ function traverseParent(element) {
10
+ while (element) {
11
+ let currentId = element?.dataset.blockid;
12
+ if (typeof currentId == "string") return currentId;
13
+ element = element.parentElement;
14
+ }
15
+ return null;
16
+ }
17
+ function switchBlockState(event) {
18
+ const id = traverseParent(event.target);
19
+ if (!id) workingBlock.set(null);
20
+ else if ($workingBlock == null || $workingBlock.id !== id)
21
+ workingBlock.set({ id, state: "focused" });
22
+ else workingBlock.set({ id, state: "editing" });
23
+ }
24
+ function move(up) {
25
+ data.update((prev) => {
26
+ const index = prev.findIndex((val2) => val2.id == $workingBlock.id);
27
+ const val = prev.splice(index, 1)[0];
28
+ prev.splice(up ? index - 1 : index + 1, 0, val);
29
+ return prev;
30
+ });
31
+ }
32
+ function Delete() {
33
+ data.update((prev) => {
34
+ const newDataBlocks = prev.filter((element) => {
35
+ return element.id != $workingBlock.id;
36
+ });
37
+ return newDataBlocks;
38
+ });
39
+ }
40
+ onMount(() => {
41
+ window.addEventListener("click", switchBlockState);
42
+ return () => {
43
+ window.removeEventListener("click", switchBlockState);
44
+ };
45
+ });
46
+ </script>
47
+
48
+ {#each $data as block}
49
+ <div class="block">
50
+ <BlockWrapper dataBlock={block} />
51
+ {#if $workingBlock?.id == block.id && $workingBlock.state == 'focused'}
52
+ <div class="menu">
53
+ <DropDown
54
+ options={[
55
+ {
56
+ label: 'move the block up',
57
+ icon: UpIcon,
58
+ cb: () => {
59
+ move(true);
60
+ }
61
+ },
62
+ {
63
+ icon: DownIcon,
64
+ label: 'move the block down',
65
+ cb: () => {
66
+ move(false);
67
+ }
68
+ },
69
+ {
70
+ icon: DeleteIcon,
71
+ label: 'Delete the block',
72
+ cb: () => {
73
+ Delete();
74
+ }
75
+ }
76
+ ]}
77
+ />
78
+ </div>
79
+ {/if}
80
+ </div>
81
+ {/each}
82
+
83
+ <ToolBar />
84
+
85
+ <style>
86
+ .block {
87
+ display: flex;
88
+ width: 100%;
89
+ gap: 10px;
90
+ align-items: center;
91
+ }
92
+ .block .menu {
93
+ display: block;
94
+ }
95
+ </style>
@@ -0,0 +1,16 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: Record<string, never>;
4
+ events: {
5
+ [evt: string]: CustomEvent<any>;
6
+ };
7
+ slots: {};
8
+ exports?: {};
9
+ bindings?: string;
10
+ };
11
+ export type EditModeProps = typeof __propDef.props;
12
+ export type EditModeEvents = typeof __propDef.events;
13
+ export type EditModeSlots = typeof __propDef.slots;
14
+ export default class EditMode extends SvelteComponent<EditModeProps, EditModeEvents, EditModeSlots> {
15
+ }
16
+ export {};
@@ -0,0 +1,196 @@
1
+ <script>import { data } from "../../utils/stores.js";
2
+ import { setContext } from "svelte";
3
+ import ViewImage from "../viewBlocks/viewImage.svelte";
4
+ import ViewCode from "../viewBlocks/viewCode.svelte";
5
+ import ViewHeader from "../viewBlocks/viewHeader.svelte";
6
+ import ViewList from "../viewBlocks/viewList.svelte";
7
+ import ViewParagraph from "../viewBlocks/viewParagraph.svelte";
8
+ import ViewQuote from "../viewBlocks/viewQuote.svelte";
9
+ import ViewMode from "./viewMode.svelte";
10
+ import EditMode from "./editMode.svelte";
11
+ export let initialData = [];
12
+ export let viewMode = false;
13
+ export let headerFont = `Verdana, sans-serif`;
14
+ export let bodyFont = `Helvetica, sans-serif`;
15
+ export let primaryColor = "#3366FF";
16
+ export let secondaryColor = "#1eeb36";
17
+ export let textColor = "#121212";
18
+ export let bgColor = "#ffffff";
19
+ export let blocksGap = 10;
20
+ export let marginBlock = 30;
21
+ export let h1 = "clamp(1.8rem, calc(1.8rem + ((1vw - 0.48rem) * 0.9722)), 2.1rem)";
22
+ export let h2 = "clamp(1.5rem, calc(1.5rem + ((1vw - 0.48rem) * 0.9722)), 1.8rem)";
23
+ export let h3 = "clamp(1.2rem, calc(1.2rem + ((1vw - 0.48rem) * 0.9722)), 1.5rem)";
24
+ export let h4 = "clamp(1.125rem, calc(1.15rem + ((1vw - 0.48rem) * 0.3472)), 1.2rem)";
25
+ export let body = "clamp(1rem, calc(1rem + ((1vw - 0.48rem) * 0.1736)), 1.125rem)";
26
+ export let small = "clamp(0.875rem, calc(0.875rem + ((1vw - 0.48rem) * 0.1736)), 1rem)";
27
+ export let lh1 = "1.3";
28
+ export let lh2 = "1.35";
29
+ export let lh3 = "1.4";
30
+ export let lh4 = "1.5";
31
+ export let lbody = "1.6";
32
+ export let customImage = ViewImage;
33
+ export let customCode = ViewCode;
34
+ export let customList = ViewList;
35
+ export let customHeader = ViewHeader;
36
+ export let customParagraph = ViewParagraph;
37
+ export let customQuote = ViewQuote;
38
+ export let codeBlockLanguages = [
39
+ "actionscript",
40
+ "angular",
41
+ // For Angular templates
42
+ "assembly",
43
+ "bash",
44
+ "c",
45
+ "clojure",
46
+ "cobol",
47
+ "cpp",
48
+ // C++
49
+ "csharp",
50
+ // C#
51
+ "css",
52
+ "dart",
53
+ "dockerfile",
54
+ "elixir",
55
+ "elm",
56
+ "erlang",
57
+ "fortran",
58
+ "fsharp",
59
+ // F#
60
+ "graphql",
61
+ "groovy",
62
+ "haskell",
63
+ "html",
64
+ "java",
65
+ "javascript",
66
+ "json",
67
+ "julia",
68
+ "kotlin",
69
+ "less",
70
+ "lua",
71
+ "markdown",
72
+ "matlab",
73
+ "nim",
74
+ "nodejs",
75
+ "objective-c",
76
+ "ocaml",
77
+ "pascal",
78
+ "perl",
79
+ "php",
80
+ "plaintext",
81
+ "powershell",
82
+ "python",
83
+ "r",
84
+ "react",
85
+ // JSX
86
+ "reason",
87
+ // ReasonML
88
+ "ruby",
89
+ "rust",
90
+ "sass",
91
+ "scala",
92
+ "scheme",
93
+ "shell",
94
+ // General shell scripting
95
+ "sql",
96
+ "stylus",
97
+ "svelte",
98
+ "swift",
99
+ "toml",
100
+ "typescript",
101
+ "vbnet",
102
+ // Visual Basic .NET
103
+ "vue",
104
+ "wasm",
105
+ // WebAssembly
106
+ "xml",
107
+ "yaml"
108
+ ];
109
+ setContext("Image", customImage);
110
+ setContext("Code", customCode);
111
+ setContext("Header", customHeader);
112
+ setContext("Paragraph", customParagraph);
113
+ setContext("List", customList);
114
+ setContext("Quote", customQuote);
115
+ setContext("languages", codeBlockLanguages);
116
+ data.set(initialData);
117
+ </script>
118
+
119
+ <div
120
+ class="main"
121
+ style:--primaryColor={primaryColor}
122
+ style:--secondaryColor={secondaryColor}
123
+ style:--textColor={textColor}
124
+ style:--headingFont={headerFont}
125
+ style:--bodyFont={bodyFont}
126
+ style:--bgColor={bgColor}
127
+ style:--h1={h1}
128
+ style:--h2={h2}
129
+ style:--h3={h3}
130
+ style:--h4={h4}
131
+ style:--body={body}
132
+ style:--small={small}
133
+ style:--lh1={lh1}
134
+ style:gap="{blocksGap}px"
135
+ style:--lh2={lh2}
136
+ style:--lh3={lh3}
137
+ style:--lh4={lh4}
138
+ style:--lbody={lbody}
139
+ style:margin-block="{marginBlock}px"
140
+ >
141
+ {#if viewMode}
142
+ <ViewMode />
143
+ {:else}
144
+ <EditMode />
145
+ {/if}
146
+ </div>
147
+
148
+ <style>
149
+ .main {
150
+ width: 100%;
151
+ display: flex;
152
+ flex-direction: column;
153
+ }
154
+ .main :global(*) {
155
+ box-sizing: border-box;
156
+ margin: 0;
157
+ padding: 0;
158
+ }
159
+ .main :global(h1),
160
+ .main :global(h2),
161
+ .main :global(h3),
162
+ .main :global(h4) {
163
+ font-family: var(--headingFont);
164
+ font-weight: bold;
165
+ color: var(--textColor);
166
+ word-break: break-word;
167
+ }
168
+ .main :global(h1) {
169
+ font-size: var(--h1);
170
+ line-height: var(--lh1);
171
+ }
172
+ .main :global(h2) {
173
+ font-size: var(--h2);
174
+ line-height: var(--lh2);
175
+ }
176
+ .main :global(h3) {
177
+ font-size: var(--h3);
178
+ line-height: var(--lh3);
179
+ }
180
+ .main :global(h4) {
181
+ font-size: var(--h4);
182
+ line-height: var(--lh4);
183
+ }
184
+
185
+ .main :global(span),
186
+ .main :global(li),
187
+ .main :global(p),
188
+ .main :global(i),
189
+ .main :global(label) {
190
+ word-break: break-word;
191
+ font-family: var(--bodyFont);
192
+ font-size: var(--body);
193
+ font-weight: 400;
194
+ line-height: var(--lbody);
195
+ }
196
+ </style>