svedit 0.7.0 → 0.7.1

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.
@@ -573,15 +573,15 @@ ${fallback_html}`;
573
573
 
574
574
  let plain_text,
575
575
  pasted_json,
576
- pasted_images = [];
576
+ pasted_media = [];
577
577
 
578
578
  // NOTE: For some reason, await navigator.clipboard.read()
579
579
  const clipboard_items = event.clipboardData?.items || [];
580
580
  for (const item of clipboard_items || []) {
581
- if (item.type.startsWith('image/')) {
581
+ if (item.type.startsWith('image/') || item.type.startsWith('video/') || item.type.startsWith('audio/')) {
582
582
  const blob = item.getAsFile();
583
583
  const data_url = URL.createObjectURL(blob);
584
- pasted_images.push({
584
+ pasted_media.push({
585
585
  blob,
586
586
  data_url,
587
587
  type: item.type,
@@ -590,11 +590,12 @@ ${fallback_html}`;
590
590
  }
591
591
  }
592
592
 
593
- if (pasted_images.length > 0) {
594
- pasted_json = await session.config.handle_image_paste(session, pasted_images);
595
- console.log('pasted_json_after_image_paste', pasted_json);
593
+ if (pasted_media.length > 0) {
594
+ const handle_media_paste = session.config.handle_media_paste || session.config.handle_image_paste
595
+ pasted_json = await handle_media_paste(session, pasted_media);
596
+ console.log('pasted_json_after_media_paste', pasted_json);
596
597
  // NOTE: If no pasted_json is returned from the custom handler, we assume that content creation has been
597
- // handled inside handle_image_paste already.
598
+ // handled inside handle_media_paste already.
598
599
  if (!pasted_json) return;
599
600
  } else {
600
601
  // First try to extract svedit data from HTML format
@@ -1 +1 @@
1
- {"version":3,"file":"Svedit.svelte.d.ts","sourceRoot":"","sources":["../src/lib/Svedit.svelte.js"],"names":[],"mappings":";;;;;;;AAm3CA;;eAAqD;iCAt1C1C,cAAc"}
1
+ {"version":3,"file":"Svedit.svelte.d.ts","sourceRoot":"","sources":["../src/lib/Svedit.svelte.js"],"names":[],"mappings":";;;;;;;AAo3CA;;eAAqD;iCAv1C1C,cAAc"}
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Set multiple properties on a node via a transaction.
3
+ *
4
+ * @param {object} tr - The transaction
5
+ * @param {Array} path - Path to the node
6
+ * @param {Record<string, any>} properties - Key/value pairs to set
7
+ */
8
+ export function set_properties(tr: object, path: any[], properties: Record<string, any>): void;
1
9
  export function break_text_node(tr: any): boolean;
2
10
  export function join_text_node(tr: any): boolean;
3
11
  export function insert_default_node(tr: any): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"transforms.svelte.d.ts","sourceRoot":"","sources":["../src/lib/transforms.svelte.js"],"names":[],"mappings":"AAGA,kDAqDC;AAED,iDAoEC;AAED,sDAuBC"}
1
+ {"version":3,"file":"transforms.svelte.d.ts","sourceRoot":"","sources":["../src/lib/transforms.svelte.js"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,mCAJW,MAAM,2BAEN,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAM7B;AAED,kDAqDC;AAED,iDAoEC;AAED,sDAuBC"}
@@ -1,6 +1,19 @@
1
1
  import { split_annotated_text, join_annotated_text, get_char_length } from './utils.js';
2
2
  import { get_default_node_type } from './doc_utils.js';
3
3
 
4
+ /**
5
+ * Set multiple properties on a node via a transaction.
6
+ *
7
+ * @param {object} tr - The transaction
8
+ * @param {Array} path - Path to the node
9
+ * @param {Record<string, any>} properties - Key/value pairs to set
10
+ */
11
+ export function set_properties(tr, path, properties) {
12
+ for (const [key, value] of Object.entries(properties)) {
13
+ tr.set([...path, key], value);
14
+ }
15
+ }
16
+
4
17
  export function break_text_node(tr) {
5
18
  // Keep a reference of the original selection (before any transforms are applied)
6
19
  const selection = tr.selection;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svedit",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -573,15 +573,15 @@ ${fallback_html}`;
573
573
 
574
574
  let plain_text,
575
575
  pasted_json,
576
- pasted_images = [];
576
+ pasted_media = [];
577
577
 
578
578
  // NOTE: For some reason, await navigator.clipboard.read()
579
579
  const clipboard_items = event.clipboardData?.items || [];
580
580
  for (const item of clipboard_items || []) {
581
- if (item.type.startsWith('image/')) {
581
+ if (item.type.startsWith('image/') || item.type.startsWith('video/') || item.type.startsWith('audio/')) {
582
582
  const blob = item.getAsFile();
583
583
  const data_url = URL.createObjectURL(blob);
584
- pasted_images.push({
584
+ pasted_media.push({
585
585
  blob,
586
586
  data_url,
587
587
  type: item.type,
@@ -590,11 +590,12 @@ ${fallback_html}`;
590
590
  }
591
591
  }
592
592
 
593
- if (pasted_images.length > 0) {
594
- pasted_json = await session.config.handle_image_paste(session, pasted_images);
595
- console.log('pasted_json_after_image_paste', pasted_json);
593
+ if (pasted_media.length > 0) {
594
+ const handle_media_paste = session.config.handle_media_paste || session.config.handle_image_paste
595
+ pasted_json = await handle_media_paste(session, pasted_media);
596
+ console.log('pasted_json_after_media_paste', pasted_json);
596
597
  // NOTE: If no pasted_json is returned from the custom handler, we assume that content creation has been
597
- // handled inside handle_image_paste already.
598
+ // handled inside handle_media_paste already.
598
599
  if (!pasted_json) return;
599
600
  } else {
600
601
  // First try to extract svedit data from HTML format
@@ -1,6 +1,19 @@
1
1
  import { split_annotated_text, join_annotated_text, get_char_length } from './utils.js';
2
2
  import { get_default_node_type } from './doc_utils.js';
3
3
 
4
+ /**
5
+ * Set multiple properties on a node via a transaction.
6
+ *
7
+ * @param {object} tr - The transaction
8
+ * @param {Array} path - Path to the node
9
+ * @param {Record<string, any>} properties - Key/value pairs to set
10
+ */
11
+ export function set_properties(tr, path, properties) {
12
+ for (const [key, value] of Object.entries(properties)) {
13
+ tr.set([...path, key], value);
14
+ }
15
+ }
16
+
4
17
  export function break_text_node(tr) {
5
18
  // Keep a reference of the original selection (before any transforms are applied)
6
19
  const selection = tr.selection;