fuma 0.5.0 → 1.0.0

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 (125) hide show
  1. package/dist/private/Meta.svelte +32 -27
  2. package/dist/private/Meta.svelte.d.ts +1 -0
  3. package/dist/private/api.d.ts +1 -1
  4. package/dist/ui/badge/Badge.svelte +4 -3
  5. package/dist/ui/button/ButtonCopy.svelte +32 -26
  6. package/dist/ui/button/ButtonDelete.svelte +23 -21
  7. package/dist/ui/button/ButtonDelete.svelte.d.ts +1 -0
  8. package/dist/ui/card/Card.svelte +13 -10
  9. package/dist/ui/card/Card.svelte.d.ts +1 -0
  10. package/dist/ui/card/CardBasic.svelte +5 -4
  11. package/dist/ui/card/CardBasic.svelte.d.ts +1 -0
  12. package/dist/ui/card/CardCollapse.svelte +35 -31
  13. package/dist/ui/card/CardCollapse.svelte.d.ts +1 -0
  14. package/dist/ui/card/CardFullScreen.svelte +8 -6
  15. package/dist/ui/card/CardFullScreen.svelte.d.ts +3 -0
  16. package/dist/ui/card/CardLink.svelte +5 -4
  17. package/dist/ui/card/CardLink.svelte.d.ts +1 -0
  18. package/dist/ui/dialog/Dialog.svelte +41 -34
  19. package/dist/ui/dialog/Dialog.svelte.d.ts +1 -0
  20. package/dist/ui/dialog/DialogConfirm.svelte +6 -4
  21. package/dist/ui/dialog/DialogConfirm.svelte.d.ts +1 -0
  22. package/dist/ui/drawer/Drawer.svelte +47 -38
  23. package/dist/ui/drawer/Drawer.svelte.d.ts +16 -0
  24. package/dist/ui/form/Form.svelte +101 -83
  25. package/dist/ui/form/Form.svelte.d.ts +1 -0
  26. package/dist/ui/form/FormInput.svelte +12 -6
  27. package/dist/ui/form/FormInput.svelte.d.ts +30 -8
  28. package/dist/ui/form/FormSection.svelte +24 -17
  29. package/dist/ui/form/formInput.d.ts +7 -4
  30. package/dist/ui/icon/Icon.svelte +35 -32
  31. package/dist/ui/index.d.ts +0 -1
  32. package/dist/ui/index.js +0 -1
  33. package/dist/ui/input/FormControl.svelte +48 -36
  34. package/dist/ui/input/FormControl.svelte.d.ts +7 -9
  35. package/dist/ui/input/InputBoolean.svelte +29 -22
  36. package/dist/ui/input/InputBoolean.svelte.d.ts +5 -1
  37. package/dist/ui/input/InputCheckboxs.svelte +37 -34
  38. package/dist/ui/input/InputCheckboxs.svelte.d.ts +5 -1
  39. package/dist/ui/input/InputCheckboxsMenu.svelte +64 -47
  40. package/dist/ui/input/InputCheckboxsMenu.svelte.d.ts +5 -1
  41. package/dist/ui/input/InputCheckboxsTree.svelte +9 -6
  42. package/dist/ui/input/InputCheckboxsTreeNodes.svelte +36 -28
  43. package/dist/ui/input/InputCombo.svelte +76 -65
  44. package/dist/ui/input/InputCombo.svelte.d.ts +5 -1
  45. package/dist/ui/input/InputDate.svelte +36 -29
  46. package/dist/ui/input/InputDateTime.svelte +37 -30
  47. package/dist/ui/input/InputImage.svelte +52 -45
  48. package/dist/ui/input/InputImage.svelte.d.ts +1 -0
  49. package/dist/ui/input/InputImagePreview.svelte +24 -20
  50. package/dist/ui/input/InputNumber.svelte +28 -22
  51. package/dist/ui/input/InputNumber.svelte.d.ts +1 -5
  52. package/dist/ui/input/InputOptionInParam.svelte +12 -10
  53. package/dist/ui/input/InputOptions.svelte +40 -34
  54. package/dist/ui/input/InputPassword.svelte +22 -18
  55. package/dist/ui/input/InputPassword.svelte.d.ts +5 -1
  56. package/dist/ui/input/InputRadio.svelte +51 -46
  57. package/dist/ui/input/InputRadio.svelte.d.ts +5 -1
  58. package/dist/ui/input/InputRelation.svelte +119 -111
  59. package/dist/ui/input/InputRelation.svelte.d.ts +6 -12
  60. package/dist/ui/input/InputRelations.svelte +94 -90
  61. package/dist/ui/input/InputRelations.svelte.d.ts +5 -12
  62. package/dist/ui/input/InputSearch.svelte +13 -10
  63. package/dist/ui/input/InputSelect.svelte +59 -46
  64. package/dist/ui/input/InputText.svelte +29 -28
  65. package/dist/ui/input/InputText.svelte.d.ts +0 -3
  66. package/dist/ui/input/InputTextarea.svelte +20 -19
  67. package/dist/ui/input/InputTextarea.svelte.d.ts +1 -5
  68. package/dist/ui/input/InputTime.svelte +43 -35
  69. package/dist/ui/input/RelationAfter.svelte +13 -9
  70. package/dist/ui/input/SelectorList.svelte +16 -12
  71. package/dist/ui/input/SelectorList.svelte.d.ts +4 -0
  72. package/dist/ui/input/textRich/InputTextRich.svelte +63 -54
  73. package/dist/ui/input/textRich/InputTextRich.svelte.d.ts +5 -1
  74. package/dist/ui/input/textRich/SuggesionList.svelte +13 -9
  75. package/dist/ui/input/textRich/ToolMark.svelte +12 -9
  76. package/dist/ui/input/textRich/ToolMarkColor.svelte +16 -12
  77. package/dist/ui/input/textRich/ToolMarkLink.svelte +46 -38
  78. package/dist/ui/input/textRich/ToolMenu.svelte +34 -19
  79. package/dist/ui/input/textRich/ToolMenuAlign.svelte +13 -9
  80. package/dist/ui/input/textRich/ToolMenuInsert.svelte +12 -7
  81. package/dist/ui/input/textRich/ToolMenuNode.svelte +14 -10
  82. package/dist/ui/input/textRich/ToolsBar.svelte +17 -13
  83. package/dist/ui/login/Login.svelte +37 -31
  84. package/dist/ui/menu/ContextMenu.svelte +37 -31
  85. package/dist/ui/menu/ContextMenu.svelte.d.ts +1 -0
  86. package/dist/ui/menu/DropDown.svelte +92 -83
  87. package/dist/ui/menu/DropDown.svelte.d.ts +1 -0
  88. package/dist/ui/menu/DropDownMenu.svelte +25 -18
  89. package/dist/ui/menu/DropDownMenu.svelte.d.ts +1 -0
  90. package/dist/ui/mode/ToggleMode.svelte +15 -14
  91. package/dist/ui/mode/ToggleMode.svelte.d.ts +6 -1
  92. package/dist/ui/pagination/Pagination.svelte +9 -8
  93. package/dist/ui/placeholder/Placeholder.svelte +4 -3
  94. package/dist/ui/placeholder/Placeholder.svelte.d.ts +1 -0
  95. package/dist/ui/placeholder/PlaceholderImage.svelte +6 -4
  96. package/dist/ui/placeholder/PlaceholderImage.svelte.d.ts +1 -0
  97. package/dist/ui/range/RangePicker.svelte +76 -63
  98. package/dist/ui/range/RangePickerButton.svelte +43 -35
  99. package/dist/ui/table/Table.svelte +35 -28
  100. package/dist/ui/table/TableBody.svelte +18 -12
  101. package/dist/ui/table/TableCell.svelte +13 -10
  102. package/dist/ui/table/TableFieldsEdition.svelte +57 -51
  103. package/dist/ui/table/TableHead.svelte +19 -20
  104. package/dist/ui/table/TableViewSelect.svelte +50 -37
  105. package/dist/ui/table/cell/TableCellArray.svelte +5 -3
  106. package/dist/ui/table/cell/TableCellBoolean.svelte +4 -3
  107. package/dist/ui/table/cell/TableCellNumber.svelte +2 -1
  108. package/dist/ui/table/cell/TableCellString.svelte +5 -2
  109. package/dist/ui/table/head/TableHeadBoolean.svelte +6 -3
  110. package/dist/ui/table/head/TableHeadDate.svelte +54 -47
  111. package/dist/ui/table/head/TableHeadDefault.svelte +5 -2
  112. package/dist/ui/table/head/TableHeadNumber.svelte +65 -53
  113. package/dist/ui/table/head/TableHeadSelect.svelte +47 -41
  114. package/dist/ui/table/head/TableHeadString.svelte +14 -8
  115. package/dist/ui/tabs/Tabs.svelte +8 -5
  116. package/dist/ui/tabs/TabsIcon.svelte +31 -28
  117. package/dist/validation/zod.d.ts +1 -1
  118. package/dist/validation/zod.js +1 -1
  119. package/package.json +32 -33
  120. package/dist/ui/slot/Slot.svelte +0 -35
  121. package/dist/ui/slot/Slot.svelte.d.ts +0 -22
  122. package/dist/ui/slot/Span.svelte +0 -4
  123. package/dist/ui/slot/Span.svelte.d.ts +0 -16
  124. package/dist/ui/slot/index.d.ts +0 -1
  125. package/dist/ui/slot/index.js +0 -1
@@ -1,55 +1,68 @@
1
- <script>import { createEventDispatcher, onMount } from "svelte";
2
- import { mdiUnfoldMoreHorizontal } from "@mdi/js";
3
- import { Icon } from "../icon/index.js";
4
- import { DropDown } from "../menu/index.js";
5
- import { SelectorList, FormControl } from "./index.js";
6
- import { parseOptions } from "../../utils/options.js";
7
- $:
8
- ({ value: _value, options, tippyProps, placeholder, ...props } = $$props);
9
- export let value = _value;
10
- $:
11
- _options = parseOptions(options);
12
- $:
13
- selectedOption = _options.find((opt) => opt.value === value);
14
- let dropDown;
15
- let button;
16
- const dispatch = createEventDispatcher();
17
- let focusIndex = 0;
18
- onMount(() => {
19
- const index = _options.findIndex((opt) => opt.value === value);
20
- focusIndex = index === -1 ? 0 : index;
21
- });
22
- function onSelect(index) {
23
- focusIndex = index;
24
- value = _options[index].value;
25
- dispatch("input", value);
26
- dispatch("select", value);
27
- dropDown.hide();
28
- }
1
+ <script lang="ts">
2
+ import { createEventDispatcher, onMount } from 'svelte'
3
+ import { mdiUnfoldMoreHorizontal } from '@mdi/js'
4
+
5
+ import { Icon } from '../icon/index.js'
6
+ import { DropDown } from '../menu/index.js'
7
+ import { SelectorList, FormControl, type InputProps } from './index.js'
8
+
9
+ import { type Options, parseOptions } from '../../utils/options.js'
10
+ import type { TippyProps } from '../../utils/tippy.js'
11
+
12
+ type $$Props = Omit<InputProps, 'input' | 'inputElement'> & {
13
+ options: Options
14
+ tippyProps?: TippyProps
15
+ placeholder?: string
16
+ }
17
+ $: ({ value: _value, options, tippyProps, placeholder, ...props } = $$props as $$Props)
18
+ export let value = _value
19
+
20
+ $: _options = parseOptions(options)
21
+ $: selectedOption = _options.find((opt) => opt.value === value)
22
+
23
+ let dropDown: DropDown
24
+ let button: HTMLButtonElement
25
+ const dispatch = createEventDispatcher<{ input: string; select: string }>()
26
+
27
+ let focusIndex = 0
28
+ onMount(() => {
29
+ const index = _options.findIndex((opt) => opt.value === value)
30
+ focusIndex = index === -1 ? 0 : index
31
+ })
32
+
33
+ function onSelect(index: number) {
34
+ focusIndex = index
35
+ value = _options[index].value
36
+ dispatch('input', value)
37
+ dispatch('select', value)
38
+ dropDown.hide()
39
+ }
29
40
  </script>
30
41
 
31
42
  <DropDown bind:this={dropDown}>
32
43
  <svelte:fragment slot="activator">
33
- <FormControl {...props} let:key>
34
- <button
35
- bind:this={button}
36
- id={key}
37
- type="button"
38
- class="input-bordered flex h-12 items-center gap-2 rounded-lg border pl-4 pr-2 hover:bg-base-200/50"
39
- >
40
- {#if selectedOption}
41
- {#if selectedOption.icon}
42
- <Icon path={selectedOption.icon} size={21} class="opacity-70" />
44
+ <FormControl {...props}>
45
+ {#snippet children({ key })}
46
+ <button
47
+ bind:this={button}
48
+ id={key}
49
+ type="button"
50
+ class="input-bordered flex h-12 items-center gap-2 rounded-lg border pl-4 pr-2 hover:bg-base-200/50"
51
+ >
52
+ {#if selectedOption}
53
+ {#if selectedOption.icon}
54
+ <Icon path={selectedOption.icon} size={21} class="opacity-70" />
55
+ {/if}
56
+ <span>{selectedOption.label}</span>
57
+ {:else if placeholder}
58
+ <span class="opacity-60">{placeholder}</span>
43
59
  {/if}
44
- <span>{selectedOption.label}</span>
45
- {:else if placeholder}
46
- <span class="opacity-60">{placeholder}</span>
60
+ <Icon class="ml-auto" path={mdiUnfoldMoreHorizontal} size={18} />
61
+ </button>
62
+ {#if value !== undefined}
63
+ <input type="hidden" name={key} {value} />
47
64
  {/if}
48
- <Icon class="ml-auto" path={mdiUnfoldMoreHorizontal} size={18} />
49
- </button>
50
- {#if value !== undefined}
51
- <input type="hidden" name={key} {value} />
52
- {/if}
65
+ {/snippet}
53
66
  </FormControl>
54
67
  </svelte:fragment>
55
68
 
@@ -1,32 +1,33 @@
1
- <script>import { FormControl, bindValueWithParams } from "./index.js";
2
- $:
3
- ({ input, value: _value, classWrapper, bindWithParams, ...props } = $$props);
4
- $:
5
- ({ class: inputClass, ...inputProps } = input || {});
6
- export let value = _value;
7
- export let inputElement = void 0;
1
+ <script lang="ts">
2
+ import { FormControl, bindValueWithParams, type InputProps } from './index.js'
3
+
4
+ type $$Props = InputProps
5
+ $: ({ input, value: _value, classWrapper, bindWithParams, ...props } = $$props as $$Props)
6
+ $: ({ class: inputClass, ...inputProps } = input || {})
7
+ export let value = _value
8
+ export let inputElement: HTMLInputElement | undefined = undefined
8
9
  </script>
9
10
 
10
11
  <FormControl {...props} enhanceDisabled={props.enhanceDisabled || bindWithParams} let:key>
11
- <slot name="label_append" slot="label_append" />
12
-
13
- <div class={classWrapper}>
14
- <slot name="prepend" {value} />
15
- <input
16
- bind:value
17
- on:input
18
- on:focus
19
- on:blur
20
- on:keydown
21
- on:keyup
22
- bind:this={inputElement}
23
- use:bindValueWithParams={{ bindEnable: bindWithParams, initValue: (v) => (value = v) }}
24
- type="text"
25
- name={key}
26
- id={key}
27
- class="input input-bordered w-full {inputClass || ''}"
28
- {...inputProps}
29
- />
30
- <slot name="append" {value} />
31
- </div>
12
+ {#snippet children({ key })}
13
+ <div class={classWrapper}>
14
+ <slot name="prepend" {value} />
15
+ <input
16
+ bind:value
17
+ on:input
18
+ on:focus
19
+ on:blur
20
+ on:keydown
21
+ on:keyup
22
+ bind:this={inputElement}
23
+ use:bindValueWithParams={{ bindEnable: bindWithParams, initValue: (v) => (value = v) }}
24
+ type="text"
25
+ name={key}
26
+ id={key}
27
+ class="input input-bordered w-full {inputClass || ''}"
28
+ {...inputProps}
29
+ />
30
+ <slot name="append" {value} />
31
+ </div>
32
+ {/snippet}
32
33
  </FormControl>
@@ -12,9 +12,6 @@ declare const __propDef: {
12
12
  [evt: string]: CustomEvent<any>;
13
13
  };
14
14
  slots: {
15
- label_append: {
16
- slot: string;
17
- };
18
15
  prepend: {
19
16
  value: string | null | undefined;
20
17
  };
@@ -1,22 +1,23 @@
1
- <script>import { FormControl } from "./index.js";
2
- $:
3
- ({ textarea, value: _value, ...props } = $$props);
4
- $:
5
- ({ class: inputClass, ...inputProps } = textarea || {});
6
- export let value = _value;
1
+ <script lang="ts">
2
+ import { FormControl, type TextareaProps } from './index.js'
3
+ type $$Props = TextareaProps
4
+ $: ({ textarea, value: _value, ...props } = $$props as $$Props)
5
+ $: ({ class: inputClass, ...inputProps } = textarea || {})
6
+ export let value = _value
7
7
  </script>
8
8
 
9
- <FormControl {...props} let:key>
10
- <slot name="label_append" slot="label_append" />
11
- <textarea
12
- bind:value
13
- on:input
14
- on:focus
15
- on:blur
16
- name={key}
17
- id={key}
18
- class="textarea textarea-bordered {inputClass || ''}"
19
- rows="4"
20
- {...inputProps}
21
- />
9
+ <FormControl {...props}>
10
+ {#snippet children({ key })}
11
+ <textarea
12
+ bind:value
13
+ on:input
14
+ on:focus
15
+ on:blur
16
+ name={key}
17
+ id={key}
18
+ class="textarea textarea-bordered {inputClass || ''}"
19
+ rows="4"
20
+ {...inputProps}
21
+ ></textarea>
22
+ {/snippet}
22
23
  </FormControl>
@@ -9,11 +9,7 @@ declare const __propDef: {
9
9
  } & {
10
10
  [evt: string]: CustomEvent<any>;
11
11
  };
12
- slots: {
13
- label_append: {
14
- slot: string;
15
- };
16
- };
12
+ slots: {};
17
13
  };
18
14
  export type InputTextareaProps = typeof __propDef.props;
19
15
  export type InputTextareaEvents = typeof __propDef.events;
@@ -1,38 +1,46 @@
1
- <script>import { createEventDispatcher } from "svelte";
2
- import { FormControl } from "./index.js";
3
- import dayjs from "dayjs";
4
- export let value = void 0;
5
- export let input = {};
6
- $:
7
- ({ class: inputClass = "", ...inputProps } = input);
8
- const dispatch = createEventDispatcher();
9
- const onInput = ({ currentTarget }) => {
10
- value = getDateTime(currentTarget.value);
11
- dispatch("input", value);
12
- };
13
- function getDateTime(v) {
14
- if (!v)
15
- return value;
16
- const date = new Date(value || 0);
17
- const dateString = [
18
- date.getFullYear().toString(),
19
- (date.getMonth() + 1).toString().padStart(2, "0"),
20
- date.getDate().toString().padStart(2, "0")
21
- ].join("-");
22
- return /* @__PURE__ */ new Date(`${dateString}T${v}`);
23
- }
1
+ <script lang="ts">
2
+ import { createEventDispatcher } from 'svelte'
3
+ import type { HTMLInputAttributes, FormEventHandler } from 'svelte/elements'
4
+ import { FormControl, type InputProps } from './index.js'
5
+ import dayjs from 'dayjs'
6
+ type $$Props = InputProps<Date>
7
+
8
+ export let value: Date | null | undefined = undefined
9
+ export let input: HTMLInputAttributes = {}
10
+
11
+ $: ({ class: inputClass = '', ...inputProps } = input)
12
+
13
+ const dispatch = createEventDispatcher<{ input: Date | null }>()
14
+
15
+ const onInput: FormEventHandler<HTMLInputElement> = ({ currentTarget }) => {
16
+ value = getDateTime(currentTarget.value)
17
+ dispatch('input', value)
18
+ }
19
+
20
+ function getDateTime(v: string | null | undefined): Date | null | undefined {
21
+ if (!v) return value
22
+ const date = new Date(value || 0)
23
+ const dateString = [
24
+ date.getFullYear().toString(),
25
+ (date.getMonth() + 1).toString().padStart(2, '0'),
26
+ date.getDate().toString().padStart(2, '0')
27
+ ].join('-')
28
+ return new Date(`${dateString}T${v}`)
29
+ }
24
30
  </script>
25
31
 
26
- <FormControl {...$$restProps} let:key>
27
- <input
28
- value={value && dayjs(value).format('HH:mm')}
29
- on:input={onInput}
30
- on:focus
31
- on:blur
32
- type="time"
33
- name={key}
34
- id={key}
35
- class="input input-bordered {inputClass}"
36
- {...inputProps}
37
- />
32
+ <FormControl {...$$restProps}>
33
+ {#snippet children({ key })}
34
+ <input
35
+ value={value && dayjs(value).format('HH:mm')}
36
+ on:input={onInput}
37
+ on:focus
38
+ on:blur
39
+ type="time"
40
+ name={key}
41
+ id={key}
42
+ class="input input-bordered {inputClass}"
43
+ {...inputProps}
44
+ />
45
+ {/snippet}
38
46
  </FormControl>
@@ -1,12 +1,16 @@
1
- <script>import { fade } from "svelte/transition";
2
- import { createEventDispatcher } from "svelte";
3
- import { mdiLoading, mdiPlus } from "@mdi/js";
4
- import Icon from "../icon/Icon.svelte";
5
- export let isLoading;
6
- export let createUrl = "";
7
- export let createTitle = "";
8
- export let createIcon = mdiPlus;
9
- const dispatch = createEventDispatcher();
1
+ <script lang="ts">
2
+ import { fade } from 'svelte/transition'
3
+ import { createEventDispatcher } from 'svelte'
4
+ import { mdiLoading, mdiPlus } from '@mdi/js'
5
+
6
+ import Icon from '../icon/Icon.svelte'
7
+
8
+ export let isLoading: boolean
9
+ export let createUrl = ''
10
+ export let createTitle = ''
11
+ export let createIcon = mdiPlus
12
+
13
+ const dispatch = createEventDispatcher<{ unselect: void; create: void }>()
10
14
  </script>
11
15
 
12
16
  {#if isLoading}
@@ -1,15 +1,19 @@
1
- <script generics="Item extends {id: string}">import { createEventDispatcher } from "svelte";
2
- import { selector } from "../../action/selector.js";
3
- let klass = "";
4
- export { klass as class };
5
- export let items;
6
- export let isError = false;
7
- export let isLoading = false;
8
- export let focusIndex = 0;
9
- export let trigger = void 0;
10
- export let keyDownEvent = void 0;
11
- export let keyDownPreventDefault = true;
12
- const dispatch = createEventDispatcher();
1
+ <script lang="ts" generics="Item extends {id: string}">
2
+ import { createEventDispatcher } from 'svelte'
3
+ import { selector } from '../../action/selector.js'
4
+
5
+ let klass = ''
6
+ export { klass as class }
7
+
8
+ export let items: Item[]
9
+ export let isError = false
10
+ export let isLoading = false
11
+ export let focusIndex = 0
12
+ export let trigger: HTMLElement | undefined = undefined
13
+ export let keyDownEvent: KeyboardEvent | undefined = undefined
14
+ export let keyDownPreventDefault = true
15
+
16
+ const dispatch = createEventDispatcher<{ select: number }>()
13
17
  </script>
14
18
 
15
19
  <ul
@@ -11,6 +11,10 @@ declare class __sveltets_Render<Item extends {
11
11
  trigger?: HTMLElement | undefined;
12
12
  keyDownEvent?: KeyboardEvent | undefined;
13
13
  keyDownPreventDefault?: boolean | undefined;
14
+ children?: import("svelte").Snippet<[{
15
+ item: Item;
16
+ index: any;
17
+ }]> | undefined;
14
18
  };
15
19
  events(): {
16
20
  select: CustomEvent<number>;
@@ -1,58 +1,67 @@
1
- <script>import { createEventDispatcher, onMount } from "svelte";
2
- import { Editor } from "@tiptap/core";
3
- import debounce from "debounce";
4
- import { jsonParse } from "../../../utils/jsonParse.js";
5
- import { FormControl } from "../index.js";
6
- import ToolsBar from "./ToolsBar.svelte";
7
- import { extensions } from "./extensions.js";
8
- export let value = "";
9
- export let classToolbar = "";
10
- let element;
11
- let editor = null;
12
- const dispatch = createEventDispatcher();
13
- onMount(() => {
14
- initEditor();
15
- return () => {
16
- if (editor)
17
- editor.destroy();
18
- };
19
- });
20
- function initEditor() {
21
- const valueAsHtml = !value.startsWith("{") && value !== "null";
22
- editor = new Editor({
23
- element,
24
- content: valueAsHtml ? value : jsonParse(value, void 0),
25
- editorProps: {
26
- attributes: {
27
- class: "prose max-w-[210mm] mx-auto focus:outline-none"
28
- }
29
- },
30
- extensions,
31
- onTransaction() {
32
- editor = editor;
33
- updateValue();
34
- }
35
- });
36
- }
37
- const updateValue = debounce(() => {
38
- if (!editor)
39
- return;
40
- const newValue = JSON.stringify(editor.getJSON());
41
- if (newValue === value)
42
- return;
43
- value = newValue;
44
- dispatch("change");
45
- }, 120);
1
+ <script lang="ts">
2
+ import { createEventDispatcher, onMount, type ComponentProps } from 'svelte'
3
+ import { Editor } from '@tiptap/core'
4
+ import debounce from 'debounce'
5
+
6
+ import { jsonParse } from '../../../utils/jsonParse.js'
7
+ import { FormControl } from '../index.js'
8
+ import ToolsBar from './ToolsBar.svelte'
9
+ import { extensions } from './extensions.js'
10
+
11
+ type $$Props = ComponentProps<FormControl> & { value?: string; classToolbar?: string }
12
+
13
+ export let value = ''
14
+ export let classToolbar = ''
15
+
16
+ let element: HTMLDivElement
17
+ let editor: Editor | null = null
18
+
19
+ const dispatch = createEventDispatcher<{ change: void }>()
20
+
21
+ onMount(() => {
22
+ initEditor()
23
+ return () => {
24
+ if (editor) editor.destroy()
25
+ }
26
+ })
27
+
28
+ function initEditor() {
29
+ const valueAsHtml = !value.startsWith('{') && value !== 'null'
30
+ editor = new Editor({
31
+ element,
32
+ content: valueAsHtml ? value : jsonParse(value, undefined),
33
+ editorProps: {
34
+ attributes: {
35
+ class: 'prose max-w-[210mm] mx-auto focus:outline-none'
36
+ }
37
+ },
38
+ extensions,
39
+ onTransaction() {
40
+ editor = editor
41
+ updateValue()
42
+ }
43
+ })
44
+ }
45
+
46
+ const updateValue = debounce(() => {
47
+ if (!editor) return
48
+ const newValue = JSON.stringify(editor.getJSON())
49
+ if (newValue === value) return
50
+ value = newValue
51
+ dispatch('change')
52
+ }, 120)
46
53
  </script>
47
54
 
48
- <FormControl {...$$restProps} let:key>
49
- <div class="bordered relative rounded-lg border">
50
- {#if editor}
51
- <ToolsBar {editor} class={classToolbar} />
55
+ <FormControl {...$$restProps}>
56
+ {#snippet children({ key })}
57
+ <div class="bordered relative rounded-lg border">
58
+ {#if editor}
59
+ <ToolsBar {editor} class={classToolbar} />
60
+ {/if}
61
+ <div bind:this={element} class="min-h-[20rem] p-4 pb-10"></div>
62
+ </div>
63
+ {#if key}
64
+ <input type="hidden" name={key} {value} />
52
65
  {/if}
53
- <div bind:this={element} class="min-h-[20rem] p-4 pb-10" />
54
- </div>
55
- {#if key}
56
- <input type="hidden" name={key} {value} />
57
- {/if}
66
+ {/snippet}
58
67
  </FormControl>
@@ -4,13 +4,17 @@ declare const __propDef: {
4
4
  class?: string | undefined;
5
5
  classLabel?: string | undefined;
6
6
  key?: string | undefined;
7
- label?: string | import("svelte").ComponentType | import("../../..").ComponentAndProps | undefined;
7
+ label?: string | import("svelte").Snippet<[]> | undefined;
8
+ labelAppend?: import("svelte").Snippet<[]> | null | undefined;
8
9
  error?: string | undefined;
9
10
  hint?: string | undefined;
10
11
  prefix?: string | number | undefined;
11
12
  prefixFor?: string | number | undefined;
12
13
  enhanceDisabled?: boolean | undefined;
13
14
  labelPosition?: ("top" | "left" | "right") | undefined;
15
+ children?: import("svelte").Snippet<[{
16
+ key: string;
17
+ }]> | undefined;
14
18
  } & {
15
19
  value?: string | undefined;
16
20
  classToolbar?: string | undefined;
@@ -1,12 +1,16 @@
1
- <script>import { SelectorList } from "../index.js";
2
- export let props;
3
- export let keyDownEvent = void 0;
4
- function handleSelect(index) {
5
- const item = props.items[index];
6
- if (!item)
7
- return;
8
- props.command(item);
9
- }
1
+ <script lang="ts">
2
+ import type { SuggestionProps } from '@tiptap/suggestion'
3
+ import { SelectorList } from '../index.js'
4
+ import type { SuggestionItem } from './suggestion.js'
5
+
6
+ export let props: SuggestionProps<SuggestionItem>
7
+ export let keyDownEvent: KeyboardEvent | undefined = undefined
8
+
9
+ function handleSelect(index: number) {
10
+ const item = props.items[index]
11
+ if (!item) return
12
+ props.command(item)
13
+ }
10
14
  </script>
11
15
 
12
16
  <SelectorList
@@ -1,12 +1,15 @@
1
- <script>import { Icon } from "../../icon/index.js";
2
- import { tip } from "../../../action/tip.js";
3
- export let editor;
4
- export let key;
5
- export let label;
6
- export let icon;
7
- export let action;
8
- $:
9
- isActive = editor.isActive(key);
1
+ <script lang="ts">
2
+ import type { Editor } from '@tiptap/core'
3
+ import { Icon } from '../../icon/index.js'
4
+ import { tip } from '../../../action/tip.js'
5
+
6
+ export let editor: Editor
7
+ export let key: string
8
+ export let label: string
9
+ export let icon: string
10
+ export let action: () => void
11
+
12
+ $: isActive = editor.isActive(key)
10
13
  </script>
11
14
 
12
15
  <button
@@ -1,14 +1,18 @@
1
- <script>import { Icon } from "../../icon/index.js";
2
- import { tip } from "../../../action/tip.js";
3
- export let icon;
4
- export let label;
5
- export let color;
6
- export let setColor;
7
- let inputColor;
8
- function handleClick() {
9
- inputColor.click();
10
- setColor(color);
11
- }
1
+ <script lang="ts">
2
+ import { Icon } from '../../icon/index.js'
3
+ import { tip } from '../../../action/tip.js'
4
+
5
+ export let icon: string
6
+ export let label: string
7
+ export let color: string
8
+ export let setColor: (color: string) => void
9
+
10
+ let inputColor: HTMLInputElement
11
+
12
+ function handleClick() {
13
+ inputColor.click()
14
+ setColor(color)
15
+ }
12
16
  </script>
13
17
 
14
18
  <div class="flex align-bottom">
@@ -25,7 +29,7 @@ function handleClick() {
25
29
  <span
26
30
  class="badge indicator-item badge-xs scale-75 border transition-none"
27
31
  style:background={color}
28
- />
32
+ ></span>
29
33
  <Icon path={icon} size={19} class="opacity-70" />
30
34
  </div>
31
35
  </button>