@flexiui/svelte-rich-text 0.0.49 → 0.0.51

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.
@@ -13,6 +13,7 @@ export interface AudioOptions {
13
13
  playBtnTextColor: string;
14
14
  colorPlay: string;
15
15
  maxWidth: string;
16
+ rewriteStyles: boolean;
16
17
  }
17
18
  export interface SetAudioOptions {
18
19
  src: string;
@@ -29,6 +30,7 @@ export interface SetAudioOptions {
29
30
  playBtnTextColor?: string;
30
31
  colorPlay?: string;
31
32
  maxWidth?: string;
33
+ rewriteStyles?: boolean;
32
34
  }
33
35
  declare module '@tiptap/core' {
34
36
  interface Commands<ReturnType> {
@@ -24,6 +24,7 @@ export const Audio = Node.create({
24
24
  playBtnTextColor: 'currentColor',
25
25
  colorPlay: '#5d5d5dc9',
26
26
  maxWidth: '100%',
27
+ rewriteStyles: false,
27
28
  };
28
29
  },
29
30
  inline() {
@@ -84,6 +85,10 @@ export const Audio = Node.create({
84
85
  default: this.options.maxWidth,
85
86
  renderHTML: a => ({ 'data-max-width': a.maxWidth }),
86
87
  },
88
+ rewriteStyles: {
89
+ default: this.options.rewriteStyles,
90
+ renderHTML: a => ({ 'data-rewrite-styles': a.rewriteStyles }),
91
+ },
87
92
  };
88
93
  },
89
94
  parseHTML() {
@@ -5,7 +5,7 @@
5
5
  <script lang="ts">
6
6
  import { onMount, tick } from "svelte";
7
7
  import WaveSurfer from "wavesurfer.js";
8
- import { activeAudioId } from "./audioStore";
8
+ import { activeAudioId, audioAttributes } from "./audioStore";
9
9
 
10
10
  export let id: string;
11
11
  export let src: string;
@@ -22,6 +22,7 @@
22
22
  export let playBtnTextColor: string;
23
23
  export let colorPlay: string;
24
24
  export let maxWidth: string;
25
+ export let rewriteStyles: boolean | string = false;
25
26
 
26
27
  let wavesurfer: WaveSurfer | null = null;
27
28
  let waveformEl: HTMLDivElement | null = null;
@@ -44,6 +45,18 @@
44
45
 
45
46
  id = id + "-" + Math.random().toString(36).substring(2, 15);
46
47
 
48
+ audioAttributes.set({
49
+ bgColor,
50
+ textColor,
51
+ borderRadius,
52
+ accentColor,
53
+ accentColorPaused,
54
+ playBtnBgColor,
55
+ playBtnTextColor,
56
+ colorPlay,
57
+ maxWidth,
58
+ });
59
+
47
60
  function formatTime(seconds: number) {
48
61
  if (isNaN(seconds) || seconds < 0) return "0:00";
49
62
 
@@ -287,22 +300,22 @@
287
300
  window.removeEventListener("mouseup", onVolumeGrabMouseUp);
288
301
  }
289
302
 
290
- const styleVars = [
291
- bgColor && `--player-bg-color: ${bgColor};`,
292
- playBtnBgColor && `--player-play-btn-bg: ${playBtnBgColor};`,
293
- playBtnTextColor && `--player-play-btn-color: ${playBtnTextColor};`,
294
- accentColor && `--player-primary-color: ${accentColor};`,
295
- accentColorPaused && `--player-progress-default-bg: ${accentColorPaused};`,
296
- textColor && `--player-text-color: ${textColor};`,
297
- borderRadius && `--player-border-radius: ${borderRadius};`,
298
- ].filter(Boolean).join('\n');
303
+ const rewrite = rewriteStyles === true || rewriteStyles === 'true';
299
304
  </script>
300
305
 
301
306
  <div
302
307
  class="audio-player"
303
308
  {id}
304
309
  class:playing
305
- style={styleVars}
310
+ style={`
311
+ ${(bgColor || $audioAttributes.bgColor) && `--player-bg-color: ${rewrite ? bgColor : $audioAttributes.bgColor};`}
312
+ ${playBtnBgColor && `--player-play-btn-bg: ${playBtnBgColor};`}
313
+ ${playBtnTextColor && `--player-play-btn-color: ${playBtnTextColor};`}
314
+ ${`--player-primary-color: ${rewrite ? accentColor : $audioAttributes.accentColor};`}
315
+ ${accentColorPaused && `--player-progress-default-bg: ${accentColorPaused};`}
316
+ ${textColor && `--player-text-color: ${textColor};`}
317
+ ${borderRadius && `--player-border-radius: ${borderRadius};`}
318
+ `}
306
319
  >
307
320
  <button
308
321
  onclick={() => togglePlayPause()}
@@ -539,11 +552,15 @@ style={styleVars}
539
552
  color: var(--player-play-btn-color);
540
553
  border: 2px solid transparent;
541
554
  border-radius: 100%;
542
- outline-offset: 4px;
543
- outline-color: var(--player-play-btn-bg);
555
+ outline: none;
544
556
  cursor: pointer;
545
557
  transition: filter 0.3s ease, transform 0.3s ease, background 0.3s ease;
546
558
 
559
+ &:focus-visible {
560
+ outline-offset: 4px;
561
+ outline-color: var(--player-play-btn-bg);
562
+ }
563
+
547
564
  &:hover {
548
565
  /* background: var(--player-primary-color); */
549
566
  &:not(.playing) {
@@ -16,6 +16,7 @@ declare const __propDef: {
16
16
  playBtnTextColor: string;
17
17
  colorPlay: string;
18
18
  maxWidth: string;
19
+ rewriteStyles?: boolean | string;
19
20
  };
20
21
  events: {
21
22
  [evt: string]: CustomEvent<any>;
@@ -85,6 +85,7 @@
85
85
  playBtnTextColor={attrs.playBtnTextColor}
86
86
  colorPlay={attrs.colorPlay}
87
87
  maxWidth={attrs.maxWidth}
88
+ rewriteStyles={attrs.rewriteStyles}
88
89
  ></AudioPlayer>
89
90
 
90
91
  {#if selected}
@@ -1,7 +1,7 @@
1
1
  import { Extension } from "@tiptap/core";
2
2
  declare module '@tiptap/core' {
3
3
  interface Commands<ReturnType> {
4
- lineHeight: {
4
+ nodeLineHeight: {
5
5
  setNodeLineHeight: (lineHeight: string) => ReturnType;
6
6
  unsetNodeLineHeight: () => ReturnType;
7
7
  };
@@ -1,10 +1,11 @@
1
1
  import { Extension } from "@tiptap/core";
2
+ const allowedTypes = ["paragraph", "heading", "h1"];
2
3
  export const NodeLineHeight = Extension.create({
3
4
  name: "nodeLineHeight",
4
5
  addGlobalAttributes() {
5
6
  return [
6
7
  {
7
- types: ["paragraph", "heading"],
8
+ types: allowedTypes,
8
9
  attributes: {
9
10
  lineHeight: {
10
11
  default: null,
@@ -27,24 +28,26 @@ export const NodeLineHeight = Extension.create({
27
28
  const { $from } = state.selection;
28
29
  for (let d = $from.depth; d > 0; d--) {
29
30
  const node = $from.node(d);
30
- if (node.type.name === "paragraph") {
31
- return commands.updateAttributes("paragraph", {
31
+ if (allowedTypes.includes(node.type.name)) {
32
+ return commands.updateAttributes(node.type.name, {
32
33
  lineHeight,
33
34
  });
34
35
  }
35
- if (node.type.name === "heading") {
36
- return commands.updateAttributes("heading", {
37
- lineHeight,
36
+ }
37
+ return false;
38
+ },
39
+ unsetNodeLineHeight: () => ({ state, commands }) => {
40
+ const { $from } = state.selection;
41
+ for (let d = $from.depth; d > 0; d--) {
42
+ const node = $from.node(d);
43
+ if (allowedTypes.includes(node.type.name)) {
44
+ return commands.updateAttributes(node.type.name, {
45
+ lineHeight: null,
38
46
  });
39
47
  }
40
48
  }
41
49
  return false;
42
50
  },
43
- unsetNodeLineHeight: () => ({ commands }) => {
44
- return commands.updateAttributes("paragraph", {
45
- lineHeight: null,
46
- });
47
- },
48
51
  };
49
52
  }
50
53
  });
@@ -188,7 +188,6 @@
188
188
  aria-label="Row options"
189
189
  type="button"
190
190
  onclick={(e) => {
191
- editor.commands.deleteSelection();
192
191
  editor?.chain().focus().selectRow(getPos()).run();
193
192
  showTooltip(e.target as HTMLElement, "row-dropdown");
194
193
  }}
@@ -202,7 +201,6 @@
202
201
  aria-label="Column options"
203
202
  type="button"
204
203
  onclick={(e) => {
205
- editor.commands.deleteSelection();
206
204
  editor?.chain().focus().selectColumn(getPos()).run();
207
205
  showTooltip(e.target as HTMLElement, "column-dropdown");
208
206
  }}
@@ -1 +1,2 @@
1
1
  export declare const activeAudioId: import("svelte/store").Writable<string>;
2
+ export declare const audioAttributes: import("svelte/store").Writable<any>;
@@ -1,2 +1,3 @@
1
1
  import { writable } from "svelte/store";
2
2
  export const activeAudioId = writable(null);
3
+ export const audioAttributes = writable({});
package/dist/index.d.ts CHANGED
@@ -2,4 +2,5 @@ import RichText from './RichText.svelte';
2
2
  import { renderHTMLFromJSON } from './renderRichText';
3
3
  import { Placeholder as PlaceholderExt } from './extensions/Placeholder';
4
4
  import { Audio as AudioExt } from './extensions/Audio';
5
- export { RichText, PlaceholderExt, AudioExt, renderHTMLFromJSON };
5
+ import { audioAttributes } from './extensions/audioStore';
6
+ export { RichText, PlaceholderExt, AudioExt, renderHTMLFromJSON, audioAttributes, };
package/dist/index.js CHANGED
@@ -2,4 +2,5 @@ import RichText from './RichText.svelte';
2
2
  import { renderHTMLFromJSON } from './renderRichText';
3
3
  import { Placeholder as PlaceholderExt } from './extensions/Placeholder';
4
4
  import { Audio as AudioExt } from './extensions/Audio';
5
- export { RichText, PlaceholderExt, AudioExt, renderHTMLFromJSON };
5
+ import { audioAttributes } from './extensions/audioStore';
6
+ export { RichText, PlaceholderExt, AudioExt, renderHTMLFromJSON, audioAttributes, };
@@ -29,7 +29,7 @@ const nodeMapping = {
29
29
  return `<div class="fl-grid-item">${serializeChildrenToHTMLString(children)}</div>`;
30
30
  },
31
31
  audio({ node, children }) {
32
- const { id, src, controls, bgColor, textColor, borderRadius, accentColor, accentColorPaused, playBtnBgColor, playBtnTextColor, maxWidth, colorPlay } = node.attrs;
32
+ const { id, src, controls, bgColor, textColor, borderRadius, accentColor, accentColorPaused, playBtnBgColor, playBtnTextColor, maxWidth, colorPlay, rewriteStyles, } = node.attrs;
33
33
  return `
34
34
  <fl-audio-player
35
35
  class="fl-audio-player"
@@ -45,6 +45,7 @@ const nodeMapping = {
45
45
  playBtnTextColor="${playBtnTextColor}"
46
46
  maxWidth="${maxWidth}"
47
47
  colorPlay="${colorPlay}"
48
+ rewriteStyles="${rewriteStyles}"
48
49
  >
49
50
  </fl-audio-player>
50
51
  `;