fuma 0.5.1 → 1.0.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.
Files changed (124) hide show
  1. package/README.md +1 -1
  2. package/dist/private/Meta.svelte +32 -27
  3. package/dist/private/Meta.svelte.d.ts +1 -0
  4. package/dist/private/api.d.ts +1 -1
  5. package/dist/ui/badge/Badge.svelte +4 -3
  6. package/dist/ui/button/ButtonCopy.svelte +32 -26
  7. package/dist/ui/button/ButtonDelete.svelte +23 -21
  8. package/dist/ui/button/ButtonDelete.svelte.d.ts +1 -0
  9. package/dist/ui/card/Card.svelte +13 -10
  10. package/dist/ui/card/Card.svelte.d.ts +1 -0
  11. package/dist/ui/card/CardBasic.svelte +5 -4
  12. package/dist/ui/card/CardBasic.svelte.d.ts +1 -0
  13. package/dist/ui/card/CardCollapse.svelte +35 -31
  14. package/dist/ui/card/CardCollapse.svelte.d.ts +1 -0
  15. package/dist/ui/card/CardFullScreen.svelte +8 -6
  16. package/dist/ui/card/CardFullScreen.svelte.d.ts +3 -0
  17. package/dist/ui/card/CardLink.svelte +5 -4
  18. package/dist/ui/card/CardLink.svelte.d.ts +1 -0
  19. package/dist/ui/dialog/Dialog.svelte +41 -34
  20. package/dist/ui/dialog/Dialog.svelte.d.ts +1 -0
  21. package/dist/ui/dialog/DialogConfirm.svelte +6 -4
  22. package/dist/ui/dialog/DialogConfirm.svelte.d.ts +1 -0
  23. package/dist/ui/drawer/Drawer.svelte +47 -38
  24. package/dist/ui/drawer/Drawer.svelte.d.ts +16 -0
  25. package/dist/ui/form/Form.svelte +101 -83
  26. package/dist/ui/form/Form.svelte.d.ts +1 -0
  27. package/dist/ui/form/FormInput.svelte +12 -6
  28. package/dist/ui/form/FormInput.svelte.d.ts +30 -8
  29. package/dist/ui/form/FormSection.svelte +24 -17
  30. package/dist/ui/form/formInput.d.ts +7 -4
  31. package/dist/ui/icon/Icon.svelte +35 -32
  32. package/dist/ui/index.d.ts +0 -1
  33. package/dist/ui/index.js +0 -1
  34. package/dist/ui/input/FormControl.svelte +48 -36
  35. package/dist/ui/input/FormControl.svelte.d.ts +7 -9
  36. package/dist/ui/input/InputBoolean.svelte +29 -22
  37. package/dist/ui/input/InputBoolean.svelte.d.ts +5 -1
  38. package/dist/ui/input/InputCheckboxs.svelte +37 -34
  39. package/dist/ui/input/InputCheckboxs.svelte.d.ts +5 -1
  40. package/dist/ui/input/InputCheckboxsMenu.svelte +64 -47
  41. package/dist/ui/input/InputCheckboxsMenu.svelte.d.ts +5 -1
  42. package/dist/ui/input/InputCheckboxsTree.svelte +9 -6
  43. package/dist/ui/input/InputCheckboxsTreeNodes.svelte +36 -28
  44. package/dist/ui/input/InputCombo.svelte +76 -65
  45. package/dist/ui/input/InputCombo.svelte.d.ts +5 -1
  46. package/dist/ui/input/InputDate.svelte +36 -29
  47. package/dist/ui/input/InputDateTime.svelte +37 -30
  48. package/dist/ui/input/InputImage.svelte +52 -45
  49. package/dist/ui/input/InputImage.svelte.d.ts +1 -0
  50. package/dist/ui/input/InputImagePreview.svelte +24 -20
  51. package/dist/ui/input/InputNumber.svelte +28 -22
  52. package/dist/ui/input/InputNumber.svelte.d.ts +1 -5
  53. package/dist/ui/input/InputOptionInParam.svelte +12 -10
  54. package/dist/ui/input/InputOptions.svelte +40 -34
  55. package/dist/ui/input/InputPassword.svelte +22 -18
  56. package/dist/ui/input/InputPassword.svelte.d.ts +5 -1
  57. package/dist/ui/input/InputRadio.svelte +51 -46
  58. package/dist/ui/input/InputRadio.svelte.d.ts +5 -1
  59. package/dist/ui/input/InputRelation.svelte +119 -111
  60. package/dist/ui/input/InputRelation.svelte.d.ts +6 -12
  61. package/dist/ui/input/InputRelations.svelte +94 -90
  62. package/dist/ui/input/InputRelations.svelte.d.ts +5 -12
  63. package/dist/ui/input/InputSearch.svelte +13 -10
  64. package/dist/ui/input/InputSelect.svelte +59 -46
  65. package/dist/ui/input/InputText.svelte +29 -28
  66. package/dist/ui/input/InputText.svelte.d.ts +0 -3
  67. package/dist/ui/input/InputTextarea.svelte +20 -19
  68. package/dist/ui/input/InputTextarea.svelte.d.ts +1 -5
  69. package/dist/ui/input/InputTime.svelte +43 -35
  70. package/dist/ui/input/RelationAfter.svelte +13 -9
  71. package/dist/ui/input/SelectorList.svelte +16 -12
  72. package/dist/ui/input/SelectorList.svelte.d.ts +4 -0
  73. package/dist/ui/input/textRich/InputTextRich.svelte +63 -54
  74. package/dist/ui/input/textRich/InputTextRich.svelte.d.ts +5 -1
  75. package/dist/ui/input/textRich/SuggesionList.svelte +13 -9
  76. package/dist/ui/input/textRich/ToolMark.svelte +12 -9
  77. package/dist/ui/input/textRich/ToolMarkColor.svelte +16 -12
  78. package/dist/ui/input/textRich/ToolMarkLink.svelte +46 -38
  79. package/dist/ui/input/textRich/ToolMenu.svelte +34 -19
  80. package/dist/ui/input/textRich/ToolMenuAlign.svelte +13 -9
  81. package/dist/ui/input/textRich/ToolMenuInsert.svelte +12 -7
  82. package/dist/ui/input/textRich/ToolMenuNode.svelte +14 -10
  83. package/dist/ui/input/textRich/ToolsBar.svelte +17 -13
  84. package/dist/ui/login/Login.svelte +37 -31
  85. package/dist/ui/menu/ContextMenu.svelte +37 -31
  86. package/dist/ui/menu/ContextMenu.svelte.d.ts +1 -0
  87. package/dist/ui/menu/DropDown.svelte +92 -83
  88. package/dist/ui/menu/DropDown.svelte.d.ts +1 -0
  89. package/dist/ui/menu/DropDownMenu.svelte +25 -18
  90. package/dist/ui/menu/DropDownMenu.svelte.d.ts +1 -0
  91. package/dist/ui/mode/ToggleMode.svelte +19 -15
  92. package/dist/ui/mode/ToggleMode.svelte.d.ts +7 -1
  93. package/dist/ui/pagination/Pagination.svelte +9 -8
  94. package/dist/ui/placeholder/Placeholder.svelte +4 -3
  95. package/dist/ui/placeholder/Placeholder.svelte.d.ts +1 -0
  96. package/dist/ui/placeholder/PlaceholderImage.svelte +6 -4
  97. package/dist/ui/placeholder/PlaceholderImage.svelte.d.ts +1 -0
  98. package/dist/ui/range/RangePicker.svelte +76 -63
  99. package/dist/ui/range/RangePickerButton.svelte +43 -35
  100. package/dist/ui/table/Table.svelte +35 -28
  101. package/dist/ui/table/TableBody.svelte +18 -12
  102. package/dist/ui/table/TableCell.svelte +13 -10
  103. package/dist/ui/table/TableFieldsEdition.svelte +57 -51
  104. package/dist/ui/table/TableHead.svelte +19 -20
  105. package/dist/ui/table/TableViewSelect.svelte +50 -37
  106. package/dist/ui/table/cell/TableCellArray.svelte +5 -3
  107. package/dist/ui/table/cell/TableCellBoolean.svelte +4 -3
  108. package/dist/ui/table/cell/TableCellNumber.svelte +2 -1
  109. package/dist/ui/table/cell/TableCellString.svelte +5 -2
  110. package/dist/ui/table/head/TableHeadBoolean.svelte +6 -3
  111. package/dist/ui/table/head/TableHeadDate.svelte +54 -47
  112. package/dist/ui/table/head/TableHeadDefault.svelte +5 -2
  113. package/dist/ui/table/head/TableHeadNumber.svelte +65 -53
  114. package/dist/ui/table/head/TableHeadSelect.svelte +47 -41
  115. package/dist/ui/table/head/TableHeadString.svelte +14 -8
  116. package/dist/ui/tabs/Tabs.svelte +8 -5
  117. package/dist/ui/tabs/TabsIcon.svelte +31 -28
  118. package/package.json +32 -33
  119. package/dist/ui/slot/Slot.svelte +0 -35
  120. package/dist/ui/slot/Slot.svelte.d.ts +0 -22
  121. package/dist/ui/slot/Span.svelte +0 -4
  122. package/dist/ui/slot/Span.svelte.d.ts +0 -16
  123. package/dist/ui/slot/index.d.ts +0 -1
  124. package/dist/ui/slot/index.js +0 -1
@@ -1,33 +1,40 @@
1
- <script>import { createEventDispatcher } from "svelte";
2
- import dayjs from "dayjs";
3
- import { FormControl } from "./index.js";
4
- import { USE_COERCE_DATE } from "../../utils/constant.js";
5
- export let value = void 0;
6
- export let input = {};
7
- $:
8
- ({ class: inputClass = "", ...inputProps } = input);
9
- const dispatch = createEventDispatcher();
10
- const handleInput = ({ currentTarget }) => {
11
- const newValue = currentTarget.valueAsDate;
12
- if (newValue === null)
13
- value = null;
14
- newValue?.setHours(value?.getHours() || 0, value?.getMinutes() || 0, value?.getSeconds() || 0);
15
- value = newValue;
16
- dispatch("input", value);
17
- };
1
+ <script lang="ts">
2
+ import { createEventDispatcher } from 'svelte'
3
+ import type { FormEventHandler, HTMLInputAttributes } from 'svelte/elements'
4
+ import dayjs from 'dayjs'
5
+
6
+ import { FormControl, type InputProps } from './index.js'
7
+ import { USE_COERCE_DATE } from '../../utils/constant.js'
8
+
9
+ type $$Props = InputProps<Date | null | undefined>
10
+ export let value: Date | null | undefined = undefined
11
+ export let input: HTMLInputAttributes = {}
12
+ $: ({ class: inputClass = '', ...inputProps } = input)
13
+
14
+ const dispatch = createEventDispatcher<{ input: Date | null }>()
15
+
16
+ const handleInput: FormEventHandler<HTMLInputElement> = ({ currentTarget }) => {
17
+ const newValue = currentTarget.valueAsDate
18
+ if (newValue === null) value = null
19
+ newValue?.setHours(value?.getHours() || 0, value?.getMinutes() || 0, value?.getSeconds() || 0)
20
+ value = newValue
21
+ dispatch('input', value)
22
+ }
18
23
  </script>
19
24
 
20
- <FormControl {...$$restProps} let:key>
21
- <input
22
- value={value && dayjs(value).format('YYYY-MM-DD')}
23
- on:input={handleInput}
24
- on:focus
25
- on:blur
26
- type="date"
27
- id={key}
28
- class="input input-bordered {inputClass}"
29
- {...inputProps}
30
- />
25
+ <FormControl {...$$restProps}>
26
+ {#snippet children({ key })}
27
+ <input
28
+ value={value && dayjs(value).format('YYYY-MM-DD')}
29
+ on:input={handleInput}
30
+ on:focus
31
+ on:blur
32
+ type="date"
33
+ id={key}
34
+ class="input input-bordered {inputClass}"
35
+ {...inputProps}
36
+ />
31
37
 
32
- <input type="hidden" name={key} value="{USE_COERCE_DATE}{value?.toJSON()}" />
38
+ <input type="hidden" name={key} value="{USE_COERCE_DATE}{value?.toJSON()}" />
39
+ {/snippet}
33
40
  </FormControl>
@@ -1,34 +1,41 @@
1
- <script>import { USE_COERCE_DATE } from "../../utils/constant.js";
2
- import { FormControl } from "./index.js";
3
- import { createEventDispatcher } from "svelte";
4
- import dayjs from "dayjs";
5
- export let value = void 0;
6
- export let input = {};
7
- $:
8
- ({ class: inputClass = "", ...inputProps } = input);
9
- const dispatch = createEventDispatcher();
10
- const handleInput = ({ currentTarget }) => {
11
- value = getDateTime(currentTarget.value);
12
- dispatch("input", value);
13
- };
14
- function getDateTime(v) {
15
- if (typeof v !== "string")
16
- return null;
17
- return new Date(v);
18
- }
1
+ <script lang="ts">
2
+ import type { FormEventHandler, HTMLInputAttributes } from 'svelte/elements'
3
+ import { USE_COERCE_DATE } from '../../utils/constant.js'
4
+ import { FormControl, type InputProps } from './index.js'
5
+ import { createEventDispatcher } from 'svelte'
6
+ import dayjs from 'dayjs'
7
+
8
+ type $$Props = InputProps<Date | null | undefined>
9
+ export let value: Date | null | undefined = undefined
10
+ export let input: HTMLInputAttributes = {}
11
+ $: ({ class: inputClass = '', ...inputProps } = input)
12
+
13
+ const dispatch = createEventDispatcher<{ input: Date | null }>()
14
+
15
+ const handleInput: FormEventHandler<HTMLInputElement> = ({ currentTarget }) => {
16
+ value = getDateTime(currentTarget.value)
17
+ dispatch('input', value)
18
+ }
19
+
20
+ function getDateTime(v: string | null | undefined): Date | null {
21
+ if (typeof v !== 'string') return null
22
+ return new Date(v)
23
+ }
19
24
  </script>
20
25
 
21
- <FormControl {...$$restProps} let:key>
22
- <input
23
- value={value && dayjs(value).format('YYYY-MM-DDTHH:mm')}
24
- on:input={handleInput}
25
- on:focus
26
- on:blur
27
- type="datetime-local"
28
- id={key}
29
- class="input input-bordered {inputClass}"
30
- {...inputProps}
31
- />
26
+ <FormControl {...$$restProps}>
27
+ {#snippet children({ key })}
28
+ <input
29
+ value={value && dayjs(value).format('YYYY-MM-DDTHH:mm')}
30
+ on:input={handleInput}
31
+ on:focus
32
+ on:blur
33
+ type="datetime-local"
34
+ id={key}
35
+ class="input input-bordered {inputClass}"
36
+ {...inputProps}
37
+ />
32
38
 
33
- <input type="hidden" name={key} value="{USE_COERCE_DATE}{value?.toJSON()}" />
39
+ <input type="hidden" name={key} value="{USE_COERCE_DATE}{value?.toJSON()}" />
40
+ {/snippet}
34
41
  </FormControl>
@@ -1,49 +1,56 @@
1
- <script context="module"></script>
1
+ <script lang="ts" context="module">
2
+ export type Crop = { width: number; height: number; x: number; y: number }
3
+ </script>
4
+
5
+ <script lang="ts">
6
+ import { onMount, createEventDispatcher } from 'svelte'
7
+ import Cropper from 'svelte-easy-crop'
8
+ import { mdiTrayArrowUp } from '@mdi/js'
9
+
10
+ import type { TippyInstance } from '../../utils/tippy.js'
11
+ import { Icon } from '../icon/index.js'
12
+ import { DropDown } from '../menu/index.js'
13
+ import { Dialog } from '../dialog/index.js'
14
+
15
+ export let aspect = 1
16
+ export let title = 'Image'
17
+ export let formaction: string | undefined = undefined
18
+ export let key = ''
19
+ let dialog: HTMLDialogElement
20
+ let tip: TippyInstance
21
+ let image = ''
22
+ let crop: Crop | undefined = undefined
23
+ let inputFile: HTMLInputElement
24
+
25
+ const dispatch = createEventDispatcher<{ submit: { crop: Crop; image: string } }>()
26
+
27
+ function onFileSelected() {
28
+ if (!inputFile.files) return
29
+ const file = inputFile.files[0]
30
+ const reader = new FileReader()
31
+ reader.onload = ({ target }) => {
32
+ image = (target?.result || '') as string
33
+ dialog?.showModal()
34
+ }
35
+ reader.readAsDataURL(file)
36
+ }
37
+
38
+ export function close() {
39
+ tip?.hide()
40
+ dialog?.close()
41
+ }
42
+
43
+ onMount(() => {
44
+ if (!$$slots.actions) tip.disable()
45
+ })
46
+ function handleClickActivator() {
47
+ if (!$$slots.actions) inputFile.click()
48
+ }
2
49
 
3
- <script>import { onMount, createEventDispatcher } from "svelte";
4
- import Cropper from "svelte-easy-crop";
5
- import { mdiTrayArrowUp } from "@mdi/js";
6
- import { Icon } from "../icon/index.js";
7
- import { DropDown } from "../menu/index.js";
8
- import { Dialog } from "../dialog/index.js";
9
- export let aspect = 1;
10
- export let title = "Image";
11
- export let formaction = void 0;
12
- export let key = "";
13
- let dialog;
14
- let tip;
15
- let image = "";
16
- let crop = void 0;
17
- let inputFile;
18
- const dispatch = createEventDispatcher();
19
- function onFileSelected() {
20
- if (!inputFile.files)
21
- return;
22
- const file = inputFile.files[0];
23
- const reader = new FileReader();
24
- reader.onload = ({ target }) => {
25
- image = target?.result || "";
26
- dialog?.showModal();
27
- };
28
- reader.readAsDataURL(file);
29
- }
30
- export function close() {
31
- tip?.hide();
32
- dialog?.close();
33
- }
34
- onMount(() => {
35
- if (!$$slots.actions)
36
- tip.disable();
37
- });
38
- function handleClickActivator() {
39
- if (!$$slots.actions)
40
- inputFile.click();
41
- }
42
- function handleValidation() {
43
- close();
44
- if (crop && image)
45
- dispatch("submit", { crop, image });
46
- }
50
+ function handleValidation() {
51
+ close()
52
+ if (crop && image) dispatch('submit', { crop, image })
53
+ }
47
54
  </script>
48
55
 
49
56
  <DropDown tippyProps={{ arrow: true }} hideOnBlur bind:tip>
@@ -12,6 +12,7 @@ declare const __propDef: {
12
12
  formaction?: string | undefined;
13
13
  key?: string | undefined;
14
14
  close?: (() => void) | undefined;
15
+ children?: import("svelte").Snippet<[]> | undefined;
15
16
  };
16
17
  events: {
17
18
  submit: CustomEvent<{
@@ -1,23 +1,27 @@
1
- <script>import { InputImage } from "./index.js";
2
- import { PlaceholderImage } from "../placeholder/index.js";
3
- export let key = "";
4
- export let src = "";
5
- export let alt = "";
6
- let klass = "";
7
- export { klass as class };
8
- export let title = "Image";
9
- export let x;
10
- export let y;
11
- export let aspect = x / y;
12
- let crop = null;
13
- let image = "";
14
- let scale = 0;
15
- let preview;
16
- async function handleSubmit(detail) {
17
- crop = detail.crop;
18
- image = detail.image;
19
- scale = x / crop.width;
20
- }
1
+ <script lang="ts">
2
+ import { InputImage, type Crop } from './index.js'
3
+ import { PlaceholderImage } from '../placeholder/index.js'
4
+
5
+ export let key = ''
6
+ export let src = ''
7
+ export let alt = ''
8
+ let klass = ''
9
+ export { klass as class }
10
+ export let title = 'Image'
11
+ export let x: number
12
+ export let y: number
13
+ export let aspect = x / y
14
+
15
+ let crop: Crop | null = null
16
+ let image = ''
17
+ let scale = 0
18
+ let preview: HTMLImageElement
19
+
20
+ async function handleSubmit(detail: { crop: Crop; image: string }) {
21
+ crop = detail.crop
22
+ image = detail.image
23
+ scale = x / crop.width
24
+ }
21
25
  </script>
22
26
 
23
27
  <InputImage {key} {title} {aspect} on:submit={({ detail }) => handleSubmit(detail)}>
@@ -1,25 +1,31 @@
1
- <script>import { USE_COERCE_NUMBER } from "../../utils/constant.js";
2
- import { FormControl } from "./index.js";
3
- export let value = void 0;
4
- export let input = void 0;
5
- export let inputElement = void 0;
1
+ <script lang="ts">
2
+ import { USE_COERCE_NUMBER } from '../../utils/constant.js'
3
+ import { FormControl, type InputProps } from './index.js'
4
+ import type { HTMLInputAttributes } from 'svelte/elements'
5
+
6
+ type $$Props = InputProps<number>
7
+
8
+ export let value: number | null | undefined = undefined
9
+ export let input: HTMLInputAttributes | undefined = undefined
10
+ export let inputElement: HTMLInputElement | undefined = undefined
6
11
  </script>
7
12
 
8
- <FormControl {...$$restProps} let:key>
9
- <slot name="label_append" slot="label_append" />
10
- <input
11
- bind:value
12
- bind:this={inputElement}
13
- on:input
14
- on:focus
15
- on:blur
16
- type="number"
17
- id={key}
18
- inputmode="numeric"
19
- class="input input-bordered"
20
- {...input}
21
- />
22
- {#if value !== undefined}
23
- <input type="hidden" name={key} value="{USE_COERCE_NUMBER}{value}" />
24
- {/if}
13
+ <FormControl {...$$restProps}>
14
+ {#snippet children({ key })}
15
+ <input
16
+ bind:value
17
+ bind:this={inputElement}
18
+ on:input
19
+ on:focus
20
+ on:blur
21
+ type="number"
22
+ id={key}
23
+ inputmode="numeric"
24
+ class="input input-bordered"
25
+ {...input}
26
+ />
27
+ {#if value !== undefined}
28
+ <input type="hidden" name={key} value="{USE_COERCE_NUMBER}{value}" />
29
+ {/if}
30
+ {/snippet}
25
31
  </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 InputNumberProps = typeof __propDef.props;
19
15
  export type InputNumberEvents = typeof __propDef.events;
@@ -1,13 +1,15 @@
1
- <script>import { Icon } from "../icon/index.js";
2
- import { parseOptions } from "../../utils/options.js";
3
- import { urlParam } from "../../store/param.js";
4
- let klass = "";
5
- export { klass as class };
6
- export let key;
7
- export let options;
8
- export let removeKeys = [];
9
- $:
10
- _options = parseOptions(options);
1
+ <script lang="ts">
2
+ import { Icon } from '../icon/index.js'
3
+ import { parseOptions, type Options } from '../../utils/options.js'
4
+ import { urlParam } from '../../store/param.js'
5
+
6
+ let klass = ''
7
+ export { klass as class }
8
+ export let key: string
9
+ export let options: Options
10
+ export let removeKeys: string[] = []
11
+
12
+ $: _options = parseOptions(options)
11
13
  </script>
12
14
 
13
15
  <div class="join {klass}">
@@ -1,37 +1,43 @@
1
- <script>import { slide } from "svelte/transition";
2
- import { mdiPlus, mdiTrashCanOutline } from "@mdi/js";
3
- import { toast } from "svelte-sonner";
4
- import { Icon } from "../icon/index.js";
5
- import { listEditable } from "../../action/list/index.js";
6
- export let key;
7
- export let value = "[]";
8
- let options = JSON.parse(value || "[]");
9
- let newOption = "";
10
- let optionInput;
11
- function handleKeyDown(e) {
12
- if (e.key === "Enter") {
13
- e.preventDefault();
14
- createOption();
15
- }
16
- }
17
- function createOption() {
18
- if (!newOption)
19
- return;
20
- if (options.includes(newOption))
21
- return toast.warning("Cette option \xE9xiste d\xE9j\xE0 !");
22
- options = [...options, newOption];
23
- newOption = "";
24
- value = JSON.stringify(options);
25
- optionInput.focus();
26
- }
27
- function removeOption(index) {
28
- options = [...options.slice(0, index), ...options.slice(index + 1)];
29
- value = JSON.stringify(options);
30
- }
31
- function onChange(newOrder) {
32
- options = newOrder;
33
- value = JSON.stringify(options);
34
- }
1
+ <script lang="ts">
2
+ import { slide } from 'svelte/transition'
3
+ import { mdiPlus, mdiTrashCanOutline } from '@mdi/js'
4
+ import { toast } from 'svelte-sonner'
5
+
6
+ import { Icon } from '../icon/index.js'
7
+ import { listEditable } from '../../action/list/index.js'
8
+
9
+ export let key: string
10
+ export let value: string | undefined | null = '[]'
11
+
12
+ let options: string[] = JSON.parse(value || '[]')
13
+ let newOption = ''
14
+ let optionInput: HTMLInputElement
15
+
16
+ function handleKeyDown(e: KeyboardEvent) {
17
+ if (e.key === 'Enter') {
18
+ e.preventDefault()
19
+ createOption()
20
+ }
21
+ }
22
+
23
+ function createOption() {
24
+ if (!newOption) return
25
+ if (options.includes(newOption)) return toast.warning('Cette option éxiste déjà !')
26
+ options = [...options, newOption]
27
+ newOption = ''
28
+ value = JSON.stringify(options)
29
+ optionInput.focus()
30
+ }
31
+
32
+ function removeOption(index: number) {
33
+ options = [...options.slice(0, index), ...options.slice(index + 1)]
34
+ value = JSON.stringify(options)
35
+ }
36
+
37
+ function onChange(newOrder: string[]) {
38
+ options = newOrder
39
+ value = JSON.stringify(options)
40
+ }
35
41
  </script>
36
42
 
37
43
  <input type="hidden" name={key} {value} />
@@ -1,21 +1,25 @@
1
- <script>import { FormControl } from "./index.js";
2
- $:
3
- ({ input, value: _value, ...props } = $$props);
4
- export let value = _value;
5
- export let autocomplete = "current-password";
1
+ <script lang="ts">
2
+ import { FormControl, type InputProps } from './index.js'
3
+
4
+ type $$Props = InputProps & { autocomplete?: string }
5
+ $: ({ input, value: _value, ...props } = $$props as $$Props)
6
+ export let value = _value
7
+ export let autocomplete = 'current-password'
6
8
  </script>
7
9
 
8
- <FormControl {...props} let:key>
9
- <input
10
- bind:value
11
- on:input
12
- on:focus
13
- on:blur
14
- type="password"
15
- name={key}
16
- id={key}
17
- class="input input-bordered"
18
- {autocomplete}
19
- {...input}
20
- />
10
+ <FormControl {...props}>
11
+ {#snippet children({ key })}
12
+ <input
13
+ bind:value
14
+ on:input
15
+ on:focus
16
+ on:blur
17
+ type="password"
18
+ name={key}
19
+ id={key}
20
+ class="input input-bordered"
21
+ {autocomplete}
22
+ {...input}
23
+ />
24
+ {/snippet}
21
25
  </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("../../index.js").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
  input?: import("svelte/elements.js").HTMLInputAttributes | undefined;
16
20
  inputElement?: HTMLInputElement | undefined;
@@ -1,35 +1,39 @@
1
- <script>import { onMount } from "svelte";
2
- import { slide } from "svelte/transition";
3
- import { parseOptions } from "../../utils/options.js";
4
- import { formContext } from "../../validation/form.js";
5
- import { FormControl, bindValueWithParams } from "./index.js";
6
- $:
7
- ({
8
- input,
9
- value: _value,
10
- error: _error,
11
- options,
12
- optionsClass = "",
13
- hint,
14
- class: klass,
15
- ...props
16
- } = $$props);
17
- export let value = _value;
18
- export let error = _error;
19
- $:
20
- _options = parseOptions(options);
21
- let formControl;
22
- const { setError } = formContext.get();
23
- onMount(() => {
24
- if (props.key)
25
- setError[props.key] = (err) => error = err;
26
- const inputs = formControl.querySelectorAll("input");
27
- const handleInput = () => error = "";
28
- inputs.forEach((input2) => input2.addEventListener("input", handleInput));
29
- return () => {
30
- inputs.forEach((input2) => input2.removeEventListener("input", handleInput));
31
- };
32
- });
1
+ <script lang="ts">
2
+ import { onMount } from 'svelte'
3
+ import { slide } from 'svelte/transition'
4
+
5
+ import { type Options, parseOptions } from '../../utils/options.js'
6
+ import { formContext } from '../../validation/form.js'
7
+ import { FormControl, bindValueWithParams, type InputProps } from './index.js'
8
+
9
+ type $$Props = InputProps & { options: Options; optionsClass?: string }
10
+ $: ({
11
+ input,
12
+ value: _value,
13
+ error: _error,
14
+ options,
15
+ optionsClass = '',
16
+ hint,
17
+ class: klass,
18
+ ...props
19
+ } = $$props as $$Props)
20
+ export let value = _value
21
+ export let error = _error
22
+
23
+ $: _options = parseOptions(options)
24
+
25
+ let formControl: HTMLDivElement
26
+ const { setError } = formContext.get()
27
+ onMount(() => {
28
+ if (props.key) setError[props.key] = (err) => (error = err)
29
+
30
+ const inputs = formControl.querySelectorAll('input')
31
+ const handleInput = () => (error = '')
32
+ inputs.forEach((input) => input.addEventListener('input', handleInput))
33
+ return () => {
34
+ inputs.forEach((input) => input.removeEventListener('input', handleInput))
35
+ }
36
+ })
33
37
  </script>
34
38
 
35
39
  <div class={klass} bind:this={formControl}>
@@ -44,25 +48,26 @@ onMount(() => {
44
48
  {#each _options as option}
45
49
  <FormControl
46
50
  {...props}
47
- let:key
48
51
  enhanceDisabled
49
52
  label={option.label}
50
53
  prefixFor={option.value}
51
54
  class="flex-row-reverse items-center justify-end gap-2"
52
55
  >
53
- <input
54
- use:bindValueWithParams={{ bindEnable: props.bindWithParams }}
55
- bind:group={value}
56
- on:input
57
- on:focus
58
- on:blur
59
- value={option.value}
60
- type="radio"
61
- name={key}
62
- id="{option.value}{key}"
63
- class="radio"
64
- {...input}
65
- />
56
+ {#snippet children({ key })}
57
+ <input
58
+ use:bindValueWithParams={{ bindEnable: props.bindWithParams }}
59
+ bind:group={value}
60
+ on:input
61
+ on:focus
62
+ on:blur
63
+ value={option.value}
64
+ type="radio"
65
+ name={key}
66
+ id="{option.value}{key}"
67
+ class="radio"
68
+ {...input}
69
+ />
70
+ {/snippet}
66
71
  </FormControl>
67
72
  {/each}
68
73
  </div>