@flexiui/svelte-rich-text 0.0.50 → 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.
- package/dist/RichText.svelte +801 -41
- package/dist/extensions/Audio.d.ts +2 -0
- package/dist/extensions/Audio.js +5 -0
- package/dist/extensions/AudioPlayer.svelte +30 -13
- package/dist/extensions/AudioPlayer.svelte.d.ts +1 -0
- package/dist/extensions/AudioPlayerWrapper.svelte +1 -0
- package/dist/extensions/NodeLineHeight.d.ts +1 -1
- package/dist/extensions/NodeLineHeight.js +14 -11
- package/dist/extensions/audioStore.d.ts +1 -0
- package/dist/extensions/audioStore.js +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/renderRichText.js +2 -1
- package/dist/styles.css +300 -207
- package/package.json +1 -1
|
@@ -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> {
|
package/dist/extensions/Audio.js
CHANGED
|
@@ -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
|
|
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={
|
|
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
|
|
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) {
|
|
@@ -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:
|
|
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
|
|
31
|
-
return commands.updateAttributes(
|
|
31
|
+
if (allowedTypes.includes(node.type.name)) {
|
|
32
|
+
return commands.updateAttributes(node.type.name, {
|
|
32
33
|
lineHeight,
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
});
|
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
|
-
|
|
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
|
-
|
|
5
|
+
import { audioAttributes } from './extensions/audioStore';
|
|
6
|
+
export { RichText, PlaceholderExt, AudioExt, renderHTMLFromJSON, audioAttributes, };
|
package/dist/renderRichText.js
CHANGED
|
@@ -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
|
`;
|