hamzus-ui 0.0.245 → 0.0.247

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hamzus-ui",
3
- "version": "0.0.245",
3
+ "version": "0.0.247",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "svelte": "index.js",
@@ -3,45 +3,28 @@
3
3
  import IconButton from '..//IconButton/IconButton.svelte';
4
4
 
5
5
  // ---------- État ----------
6
- export let initialValue = `# Mon Projet
7
-
8
- > Une courte description qui donne envie de scroller.
9
-
10
- ## Installation
11
-
12
- \`\`\`bash
13
- npm install mon-projet
14
- \`\`\`
15
-
16
- ## Utilisation
17
-
18
- \`\`\`js
19
- import { run } from 'mon-projet'
20
- run()
21
- \`\`\`
22
-
23
- - [x] Setup du repo
24
- - [ ] Écrire les tests
25
- - [ ] Publier sur npm
26
-
27
- Voir la [documentation](https://example.com) pour plus de détails.
28
- `;
29
-
30
- let source = initialValue;
6
+ export let value = ``;
7
+ export let onChange = ()=>{};
8
+ let previousValue = value;
31
9
  let mode = 'split'; // 'edit' | 'split' | 'preview'
32
10
  let filename = 'README.md';
33
11
  let dirty = false;
34
12
  let textareaEl;
35
13
  let copied = false;
36
14
 
37
- $: wordCount = (source.match(/\S+/g) || []).length;
38
- $: charCount = source.length;
15
+ $: wordCount = (value.match(/\S+/g) || []).length;
16
+ $: charCount = value.length;
39
17
  $: readMinutes = Math.max(1, Math.round(wordCount / 200));
40
- $: html = renderMarkdown(source);
18
+ $: html = renderMarkdown(value);
41
19
 
42
20
  function onInput(e) {
43
- source = e.target.value;
21
+ value = e.target.value;
44
22
  dirty = true;
23
+ if (previousValue !== value) {
24
+ onChange(value)
25
+ }
26
+
27
+ previousValue = value
45
28
  }
46
29
 
47
30
  // ---------- Petit moteur markdown (sans dépendance) ----------
@@ -186,9 +169,9 @@ Voir la [documentation](https://example.com) pour plus de détails.
186
169
  if (!textareaEl) return;
187
170
  const start = textareaEl.selectionStart;
188
171
  const end = textareaEl.selectionEnd;
189
- const selected = source.slice(start, end) || placeholder;
190
- const next = source.slice(0, start) + before + selected + after + source.slice(end);
191
- source = next;
172
+ const selected = value.slice(start, end) || placeholder;
173
+ const next = value.slice(0, start) + before + selected + after + value.slice(end);
174
+ value = next;
192
175
  dirty = true;
193
176
  requestAnimationFrame(() => {
194
177
  textareaEl.focus();
@@ -200,8 +183,8 @@ Voir la [documentation](https://example.com) pour plus de détails.
200
183
  function insertLinePrefix(prefix) {
201
184
  if (!textareaEl) return;
202
185
  const start = textareaEl.selectionStart;
203
- const lineStart = source.lastIndexOf('\n', start - 1) + 1;
204
- source = source.slice(0, lineStart) + prefix + source.slice(lineStart);
186
+ const lineStart = value.lastIndexOf('\n', start - 1) + 1;
187
+ value = value.slice(0, lineStart) + prefix + value.slice(lineStart);
205
188
  dirty = true;
206
189
  requestAnimationFrame(() => textareaEl.focus());
207
190
  }
@@ -220,7 +203,7 @@ Voir la [documentation](https://example.com) pour plus de détails.
220
203
 
221
204
  async function copyMarkdown() {
222
205
  try {
223
- await navigator.clipboard.writeText(source);
206
+ await navigator.clipboard.writeText(value);
224
207
  copied = true;
225
208
  setTimeout(() => (copied = false), 1600);
226
209
  } catch (e) {
@@ -229,7 +212,7 @@ Voir la [documentation](https://example.com) pour plus de détails.
229
212
  }
230
213
 
231
214
  function downloadFile() {
232
- const blob = new Blob([source], { type: 'text/markdown;charset=utf-8' });
215
+ const blob = new Blob([value], { type: 'text/markdown;charset=utf-8' });
233
216
  const url = URL.createObjectURL(blob);
234
217
  const a = document.createElement('a');
235
218
  a.href = url;
@@ -262,7 +245,7 @@ Voir la [documentation](https://example.com) pour plus de détails.
262
245
  bind:this={textareaEl}
263
246
  class="editor-pane"
264
247
  spellcheck="false"
265
- value={source}
248
+ value={value}
266
249
  on:input={onInput}
267
250
  placeholder="Écris ton README en Markdown..."
268
251
  ></textarea>
@@ -64,6 +64,8 @@ export function sendRequest(request) {
64
64
  }
65
65
  }
66
66
  resolve(false);
67
+ } else {
68
+ resolve(JSON.parse(xhr.responseText))
67
69
  }
68
70
  };
69
71