fuma 0.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 (242) hide show
  1. package/README.md +58 -0
  2. package/dist/Meta.svelte +55 -0
  3. package/dist/Meta.svelte.d.ts +20 -0
  4. package/dist/action/index.d.ts +4 -0
  5. package/dist/action/index.js +4 -0
  6. package/dist/action/list/handlers.d.ts +16 -0
  7. package/dist/action/list/handlers.js +92 -0
  8. package/dist/action/list/index.css +40 -0
  9. package/dist/action/list/index.d.ts +23 -0
  10. package/dist/action/list/index.js +44 -0
  11. package/dist/action/list/store.d.ts +3 -0
  12. package/dist/action/list/store.js +1 -0
  13. package/dist/action/list/style.d.ts +2 -0
  14. package/dist/action/list/style.js +14 -0
  15. package/dist/action/list/trigger.d.ts +12 -0
  16. package/dist/action/list/trigger.js +124 -0
  17. package/dist/action/list/utils.d.ts +18 -0
  18. package/dist/action/list/utils.js +68 -0
  19. package/dist/action/portal.d.ts +3 -0
  20. package/dist/action/portal.js +9 -0
  21. package/dist/action/selector.d.ts +15 -0
  22. package/dist/action/selector.js +71 -0
  23. package/dist/action/tip.d.ts +6 -0
  24. package/dist/action/tip.js +12 -0
  25. package/dist/index.d.ts +3 -0
  26. package/dist/index.js +3 -0
  27. package/dist/server/index.d.ts +5 -0
  28. package/dist/server/index.js +5 -0
  29. package/dist/server/json.d.ts +1 -0
  30. package/dist/server/json.js +16 -0
  31. package/dist/server/parseFormData.d.ts +20 -0
  32. package/dist/server/parseFormData.js +63 -0
  33. package/dist/server/parseQuery.d.ts +11 -0
  34. package/dist/server/parseQuery.js +15 -0
  35. package/dist/server/sse.d.ts +6 -0
  36. package/dist/server/sse.js +35 -0
  37. package/dist/server/try.d.ts +6 -0
  38. package/dist/server/try.js +31 -0
  39. package/dist/store/index.d.ts +2 -0
  40. package/dist/store/index.js +2 -0
  41. package/dist/store/isSmallScreen.d.ts +2 -0
  42. package/dist/store/isSmallScreen.js +14 -0
  43. package/dist/store/param.d.ts +24 -0
  44. package/dist/store/param.js +61 -0
  45. package/dist/store/session.d.ts +2 -0
  46. package/dist/store/session.js +13 -0
  47. package/dist/ui/ButtonCopy.svelte +18 -0
  48. package/dist/ui/ButtonCopy.svelte.d.ts +18 -0
  49. package/dist/ui/ButtonDelete.svelte +43 -0
  50. package/dist/ui/ButtonDelete.svelte.d.ts +22 -0
  51. package/dist/ui/Dialog.svelte +58 -0
  52. package/dist/ui/Dialog.svelte.d.ts +25 -0
  53. package/dist/ui/DialogConfirm.svelte +22 -0
  54. package/dist/ui/DialogConfirm.svelte.d.ts +21 -0
  55. package/dist/ui/Icon.svelte +46 -0
  56. package/dist/ui/Icon.svelte.d.ts +24 -0
  57. package/dist/ui/Pagination.svelte +28 -0
  58. package/dist/ui/Pagination.svelte.d.ts +16 -0
  59. package/dist/ui/Placeholder.svelte +11 -0
  60. package/dist/ui/Placeholder.svelte.d.ts +19 -0
  61. package/dist/ui/PlaceholderImage.svelte +14 -0
  62. package/dist/ui/PlaceholderImage.svelte.d.ts +19 -0
  63. package/dist/ui/card/Card.svelte +38 -0
  64. package/dist/ui/card/Card.svelte.d.ts +26 -0
  65. package/dist/ui/card/CardBasic.svelte +14 -0
  66. package/dist/ui/card/CardBasic.svelte.d.ts +20 -0
  67. package/dist/ui/card/CardCollapse.svelte +61 -0
  68. package/dist/ui/card/CardCollapse.svelte.d.ts +22 -0
  69. package/dist/ui/card/CardFullScreen.svelte +28 -0
  70. package/dist/ui/card/CardFullScreen.svelte.d.ts +23 -0
  71. package/dist/ui/card/CardLink.svelte +21 -0
  72. package/dist/ui/card/CardLink.svelte.d.ts +20 -0
  73. package/dist/ui/card/index.d.ts +5 -0
  74. package/dist/ui/card/index.js +5 -0
  75. package/dist/ui/index.d.ts +14 -0
  76. package/dist/ui/index.js +14 -0
  77. package/dist/ui/input/FormControl.svelte +53 -0
  78. package/dist/ui/input/FormControl.svelte.d.ts +30 -0
  79. package/dist/ui/input/InputBoolean.svelte +29 -0
  80. package/dist/ui/input/InputBoolean.svelte.d.ts +21 -0
  81. package/dist/ui/input/InputCheckboxs.svelte +68 -0
  82. package/dist/ui/input/InputCheckboxs.svelte.d.ts +41 -0
  83. package/dist/ui/input/InputCheckboxsMenu.svelte +93 -0
  84. package/dist/ui/input/InputCheckboxsMenu.svelte.d.ts +43 -0
  85. package/dist/ui/input/InputCheckboxsTree.svelte +15 -0
  86. package/dist/ui/input/InputCheckboxsTree.svelte.d.ts +21 -0
  87. package/dist/ui/input/InputCheckboxsTreeNodes.svelte +60 -0
  88. package/dist/ui/input/InputCheckboxsTreeNodes.svelte.d.ts +23 -0
  89. package/dist/ui/input/InputDate.svelte +26 -0
  90. package/dist/ui/input/InputDate.svelte.d.ts +19 -0
  91. package/dist/ui/input/InputDatetime.svelte +21 -0
  92. package/dist/ui/input/InputDatetime.svelte.d.ts +19 -0
  93. package/dist/ui/input/InputImage.svelte +107 -0
  94. package/dist/ui/input/InputImage.svelte.d.ts +35 -0
  95. package/dist/ui/input/InputImagePreview.svelte +56 -0
  96. package/dist/ui/input/InputImagePreview.svelte.d.ts +23 -0
  97. package/dist/ui/input/InputNumber.svelte +22 -0
  98. package/dist/ui/input/InputNumber.svelte.d.ts +23 -0
  99. package/dist/ui/input/InputOptionInParam.svelte +34 -0
  100. package/dist/ui/input/InputOptionInParam.svelte.d.ts +20 -0
  101. package/dist/ui/input/InputOptions.svelte +79 -0
  102. package/dist/ui/input/InputOptions.svelte.d.ts +17 -0
  103. package/dist/ui/input/InputPassword.svelte +21 -0
  104. package/dist/ui/input/InputPassword.svelte.d.ts +36 -0
  105. package/dist/ui/input/InputRadio.svelte +79 -0
  106. package/dist/ui/input/InputRadio.svelte.d.ts +40 -0
  107. package/dist/ui/input/InputRelation.svelte +114 -0
  108. package/dist/ui/input/InputRelation.svelte.d.ts +52 -0
  109. package/dist/ui/input/InputRelations.svelte +138 -0
  110. package/dist/ui/input/InputRelations.svelte.d.ts +49 -0
  111. package/dist/ui/input/InputSearch.svelte +43 -0
  112. package/dist/ui/input/InputSearch.svelte.d.ts +23 -0
  113. package/dist/ui/input/InputSelect.svelte +59 -0
  114. package/dist/ui/input/InputSelect.svelte.d.ts +26 -0
  115. package/dist/ui/input/InputText.svelte +32 -0
  116. package/dist/ui/input/InputText.svelte.d.ts +31 -0
  117. package/dist/ui/input/InputTextarea.svelte +20 -0
  118. package/dist/ui/input/InputTextarea.svelte.d.ts +23 -0
  119. package/dist/ui/input/InputTime.svelte +19 -0
  120. package/dist/ui/input/InputTime.svelte.d.ts +19 -0
  121. package/dist/ui/input/RelationAfter.svelte +42 -0
  122. package/dist/ui/input/RelationAfter.svelte.d.ts +22 -0
  123. package/dist/ui/input/SelectorList.svelte +46 -0
  124. package/dist/ui/input/SelectorList.svelte.d.ts +40 -0
  125. package/dist/ui/input/action.d.ts +13 -0
  126. package/dist/ui/input/action.js +56 -0
  127. package/dist/ui/input/index.d.ts +25 -0
  128. package/dist/ui/input/index.js +25 -0
  129. package/dist/ui/input/textRich/InputTextRich.svelte +58 -0
  130. package/dist/ui/input/textRich/InputTextRich.svelte.d.ts +20 -0
  131. package/dist/ui/input/textRich/SuggesionList.svelte +21 -0
  132. package/dist/ui/input/textRich/SuggesionList.svelte.d.ts +19 -0
  133. package/dist/ui/input/textRich/ToolMark.svelte +19 -0
  134. package/dist/ui/input/textRich/ToolMark.svelte.d.ts +21 -0
  135. package/dist/ui/input/textRich/ToolMarkColor.svelte +32 -0
  136. package/dist/ui/input/textRich/ToolMarkColor.svelte.d.ts +19 -0
  137. package/dist/ui/input/textRich/ToolMarkLink.svelte +63 -0
  138. package/dist/ui/input/textRich/ToolMarkLink.svelte.d.ts +17 -0
  139. package/dist/ui/input/textRich/ToolMenu.svelte +50 -0
  140. package/dist/ui/input/textRich/ToolMenu.svelte.d.ts +29 -0
  141. package/dist/ui/input/textRich/ToolMenuAlign.svelte +46 -0
  142. package/dist/ui/input/textRich/ToolMenuAlign.svelte.d.ts +17 -0
  143. package/dist/ui/input/textRich/ToolMenuInsert.svelte +49 -0
  144. package/dist/ui/input/textRich/ToolMenuInsert.svelte.d.ts +19 -0
  145. package/dist/ui/input/textRich/ToolMenuNode.svelte +56 -0
  146. package/dist/ui/input/textRich/ToolMenuNode.svelte.d.ts +17 -0
  147. package/dist/ui/input/textRich/ToolsBar.svelte +60 -0
  148. package/dist/ui/input/textRich/ToolsBar.svelte.d.ts +18 -0
  149. package/dist/ui/input/textRich/extensions.d.ts +2 -0
  150. package/dist/ui/input/textRich/extensions.js +62 -0
  151. package/dist/ui/input/textRich/indent.d.ts +13 -0
  152. package/dist/ui/input/textRich/indent.js +112 -0
  153. package/dist/ui/input/textRich/suggestion.d.ts +9 -0
  154. package/dist/ui/input/textRich/suggestion.js +56 -0
  155. package/dist/ui/input/types.d.ts +15 -0
  156. package/dist/ui/input/types.js +1 -0
  157. package/dist/ui/menu/ContextMenu.svelte +47 -0
  158. package/dist/ui/menu/ContextMenu.svelte.d.ts +28 -0
  159. package/dist/ui/menu/DropDown.svelte +110 -0
  160. package/dist/ui/menu/DropDown.svelte.d.ts +38 -0
  161. package/dist/ui/menu/dropdown.css +33 -0
  162. package/dist/ui/menu/index.d.ts +2 -0
  163. package/dist/ui/menu/index.js +2 -0
  164. package/dist/ui/period/PeriodPicker.svelte +53 -0
  165. package/dist/ui/period/PeriodPicker.svelte.d.ts +22 -0
  166. package/dist/ui/period/PeriodPickerButton.svelte +73 -0
  167. package/dist/ui/period/PeriodPickerButton.svelte.d.ts +14 -0
  168. package/dist/ui/period/index.d.ts +6 -0
  169. package/dist/ui/period/index.js +2 -0
  170. package/dist/ui/table/Table.svelte +42 -0
  171. package/dist/ui/table/Table.svelte.d.ts +39 -0
  172. package/dist/ui/table/TableBody.svelte +29 -0
  173. package/dist/ui/table/TableBody.svelte.d.ts +33 -0
  174. package/dist/ui/table/TableCell.svelte +27 -0
  175. package/dist/ui/table/TableCell.svelte.d.ts +28 -0
  176. package/dist/ui/table/TableFieldsEdition.svelte +122 -0
  177. package/dist/ui/table/TableFieldsEdition.svelte.d.ts +31 -0
  178. package/dist/ui/table/TableHead.svelte +31 -0
  179. package/dist/ui/table/TableHead.svelte.d.ts +29 -0
  180. package/dist/ui/table/TableViewSelect.svelte +127 -0
  181. package/dist/ui/table/TableViewSelect.svelte.d.ts +24 -0
  182. package/dist/ui/table/cell/TableCellArray.svelte +10 -0
  183. package/dist/ui/table/cell/TableCellArray.svelte.d.ts +16 -0
  184. package/dist/ui/table/cell/TableCellBoolean.svelte +12 -0
  185. package/dist/ui/table/cell/TableCellBoolean.svelte.d.ts +16 -0
  186. package/dist/ui/table/cell/TableCellNumber.svelte +6 -0
  187. package/dist/ui/table/cell/TableCellNumber.svelte.d.ts +16 -0
  188. package/dist/ui/table/cell/TableCellString.svelte +7 -0
  189. package/dist/ui/table/cell/TableCellString.svelte.d.ts +18 -0
  190. package/dist/ui/table/cell/index.d.ts +4 -0
  191. package/dist/ui/table/cell/index.js +4 -0
  192. package/dist/ui/table/context.d.ts +14 -0
  193. package/dist/ui/table/context.js +10 -0
  194. package/dist/ui/table/field.d.ts +79 -0
  195. package/dist/ui/table/field.js +29 -0
  196. package/dist/ui/table/head/TableHeadBoolean.svelte +12 -0
  197. package/dist/ui/table/head/TableHeadBoolean.svelte.d.ts +17 -0
  198. package/dist/ui/table/head/TableHeadDate.svelte +100 -0
  199. package/dist/ui/table/head/TableHeadDate.svelte.d.ts +17 -0
  200. package/dist/ui/table/head/TableHeadDefault.svelte +7 -0
  201. package/dist/ui/table/head/TableHeadDefault.svelte.d.ts +17 -0
  202. package/dist/ui/table/head/TableHeadNumber.svelte +80 -0
  203. package/dist/ui/table/head/TableHeadNumber.svelte.d.ts +17 -0
  204. package/dist/ui/table/head/TableHeadSelect.svelte +75 -0
  205. package/dist/ui/table/head/TableHeadSelect.svelte.d.ts +20 -0
  206. package/dist/ui/table/head/TableHeadString.svelte +35 -0
  207. package/dist/ui/table/head/TableHeadString.svelte.d.ts +17 -0
  208. package/dist/ui/table/head/index.d.ts +19 -0
  209. package/dist/ui/table/head/index.js +22 -0
  210. package/dist/ui/table/index.d.ts +10 -0
  211. package/dist/ui/table/index.js +10 -0
  212. package/dist/ui/table/server.d.ts +1 -0
  213. package/dist/ui/table/server.js +32 -0
  214. package/dist/ui/tabs/Tabs.svelte +28 -0
  215. package/dist/ui/tabs/Tabs.svelte.d.ts +18 -0
  216. package/dist/ui/tabs/TabsIcon.svelte +56 -0
  217. package/dist/ui/tabs/TabsIcon.svelte.d.ts +20 -0
  218. package/dist/ui/tabs/index.d.ts +8 -0
  219. package/dist/ui/tabs/index.js +2 -0
  220. package/dist/utils/avatar.d.ts +1 -0
  221. package/dist/utils/avatar.js +5 -0
  222. package/dist/utils/component.d.ts +7 -0
  223. package/dist/utils/component.js +3 -0
  224. package/dist/utils/formatRange.d.ts +8 -0
  225. package/dist/utils/formatRange.js +25 -0
  226. package/dist/utils/index.d.ts +7 -0
  227. package/dist/utils/index.js +7 -0
  228. package/dist/utils/jsonParse.d.ts +1 -0
  229. package/dist/utils/jsonParse.js +10 -0
  230. package/dist/utils/normalizePath.d.ts +1 -0
  231. package/dist/utils/normalizePath.js +11 -0
  232. package/dist/utils/options.d.ts +7 -0
  233. package/dist/utils/options.js +20 -0
  234. package/dist/utils/tippy.d.ts +5 -0
  235. package/dist/utils/tippy.js +4 -0
  236. package/dist/validation/form.d.ts +31 -0
  237. package/dist/validation/form.js +94 -0
  238. package/dist/validation/index.d.ts +2 -0
  239. package/dist/validation/index.js +2 -0
  240. package/dist/validation/zod.d.ts +338 -0
  241. package/dist/validation/zod.js +100 -0
  242. package/package.json +86 -0
package/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # create-svelte
2
+
3
+ Everything you need to build a Svelte library, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).
4
+
5
+ Read more about creating a library [in the docs](https://kit.svelte.dev/docs/packaging).
6
+
7
+ ## Creating a project
8
+
9
+ If you're seeing this, you've probably already done this step. Congrats!
10
+
11
+ ```bash
12
+ # create a new project in the current directory
13
+ npm create svelte@latest
14
+
15
+ # create a new project in my-app
16
+ npm create svelte@latest my-app
17
+ ```
18
+
19
+ ## Developing
20
+
21
+ Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
22
+
23
+ ```bash
24
+ npm run dev
25
+
26
+ # or start the server and open the app in a new browser tab
27
+ npm run dev -- --open
28
+ ```
29
+
30
+ Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.
31
+
32
+ ## Building
33
+
34
+ To build your library:
35
+
36
+ ```bash
37
+ npm run package
38
+ ```
39
+
40
+ To create a production version of your showcase app:
41
+
42
+ ```bash
43
+ npm run build
44
+ ```
45
+
46
+ You can preview the production build with `npm run preview`.
47
+
48
+ > To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
49
+
50
+ ## Publishing
51
+
52
+ Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)).
53
+
54
+ To publish your library to [npm](https://www.npmjs.com):
55
+
56
+ ```bash
57
+ npm publish
58
+ ```
@@ -0,0 +1,55 @@
1
+ <script>import {} from "svelte";
2
+ import { Card, Table } from "./index.js";
3
+ export let name = "";
4
+ export let description = "";
5
+ export let component;
6
+ let props = [];
7
+ $:
8
+ initMeta(component);
9
+ function initMeta(c) {
10
+ if (!c)
11
+ return;
12
+ updateComponentMeta(c);
13
+ component.$$.after_update.push(() => updateComponentMeta(c));
14
+ }
15
+ function updateComponentMeta(c) {
16
+ const ctx = c.$$.ctx;
17
+ const propsIndex = Object.entries(c.$$.props);
18
+ props = propsIndex.map(([id, index]) => ({
19
+ id,
20
+ value: ctx[index]
21
+ }));
22
+ }
23
+ </script>
24
+
25
+ <Card class="mx-auto mt-6 max-w-4xl">
26
+ <svelte:fragment slot="title">{name}</svelte:fragment>
27
+ <svelte:fragment slot="subtitle">{description}</svelte:fragment>
28
+
29
+ <slot />
30
+
31
+ <div class="my-10" />
32
+
33
+ <Table
34
+ items={props}
35
+ fields={[
36
+ {
37
+ key: 'name',
38
+ label: 'Prop',
39
+ getCell: (p) => p.id,
40
+ locked: true
41
+ },
42
+ {
43
+ key: 'type',
44
+ label: 'Type',
45
+ getCell: (p) => typeof p.value
46
+ },
47
+ {
48
+ key: 'value',
49
+ label: 'Value',
50
+ getCell: (p) => p.value,
51
+ visible: true
52
+ }
53
+ ]}
54
+ ></Table>
55
+ </Card>
@@ -0,0 +1,20 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ name?: string | undefined;
5
+ description?: string | undefined;
6
+ component: SvelteComponent;
7
+ };
8
+ events: {
9
+ [evt: string]: CustomEvent<any>;
10
+ };
11
+ slots: {
12
+ default: {};
13
+ };
14
+ };
15
+ export type MetaProps = typeof __propDef.props;
16
+ export type MetaEvents = typeof __propDef.events;
17
+ export type MetaSlots = typeof __propDef.slots;
18
+ export default class Meta extends SvelteComponent<MetaProps, MetaEvents, MetaSlots> {
19
+ }
20
+ export {};
@@ -0,0 +1,4 @@
1
+ export * from './selector.js';
2
+ export * from './tip.js';
3
+ export * from './portal.js';
4
+ export * from './list/index.js';
@@ -0,0 +1,4 @@
1
+ export * from './selector.js';
2
+ export * from './tip.js';
3
+ export * from './portal.js';
4
+ export * from './list/index.js';
@@ -0,0 +1,16 @@
1
+ import './index.css';
2
+ import { type ListEditableOptions } from './index.js';
3
+ export type Position = {
4
+ clientX: number;
5
+ clientY: number;
6
+ };
7
+ export type DragHandler = ReturnType<typeof createDragHandler>;
8
+ export declare function createDragHandler<Type = unknown>(listElement: HTMLDivElement, itemElement: HTMLElement, options: ListEditableOptions<Type>): {
9
+ on: (event: "dragStart" | "dragMove" | "dragEnd", callback: Callback) => void;
10
+ off: (event: "dragStart" | "dragMove" | "dragEnd", callback: Callback) => void;
11
+ start(position: Position): void;
12
+ move(position?: Position): void;
13
+ end(): void;
14
+ };
15
+ type Callback = () => void;
16
+ export {};
@@ -0,0 +1,92 @@
1
+ import './index.css';
2
+ import { CLASSNAME_DRAG_ACTIVE } from './index.js';
3
+ import { initDragStyle, resetDragStyle } from './style.js';
4
+ import { createPlaceholder, computeLimits, getNewOrderIndex, getListItemIndex, } from './utils.js';
5
+ import { scroll } from './store.js';
6
+ export function createDragHandler(listElement, itemElement, options) {
7
+ let originMouseY = 0;
8
+ let limits = null;
9
+ let placeholder = null;
10
+ let indexFrom = 0;
11
+ let indexTo = 0;
12
+ let currentPosition = { clientX: 0, clientY: 0 };
13
+ const events = createEventEmitter({
14
+ dragStart: options.onDragStart ? [options.onDragStart] : [],
15
+ dragMove: options.onDragMove ? [options.onDragMove] : [],
16
+ dragEnd: options.onDragEnd ? [options.onDragEnd] : [],
17
+ });
18
+ return {
19
+ on: events.on,
20
+ off: events.off,
21
+ start(position) {
22
+ events.emit('dragStart');
23
+ currentPosition = position;
24
+ limits = computeLimits(listElement, itemElement);
25
+ if (!limits)
26
+ return;
27
+ originMouseY = position.clientY + scroll.top;
28
+ listElement.classList.add(CLASSNAME_DRAG_ACTIVE);
29
+ itemElement.classList.add(CLASSNAME_DRAG_ACTIVE);
30
+ initDragStyle(itemElement);
31
+ indexFrom = getListItemIndex(listElement, itemElement);
32
+ indexTo = indexFrom;
33
+ placeholder = createPlaceholder({ listElement, itemElement, indexFrom });
34
+ },
35
+ move(position = currentPosition) {
36
+ events.emit('dragMove');
37
+ currentPosition = position;
38
+ if (!itemElement || !limits || !originMouseY)
39
+ return;
40
+ let deltaMouseY = position.clientY - originMouseY + scroll.top;
41
+ if (deltaMouseY < limits.top)
42
+ deltaMouseY = limits.top;
43
+ if (deltaMouseY > limits.bottom)
44
+ deltaMouseY = limits.bottom;
45
+ itemElement.style.transform = `translateY(${deltaMouseY}px)`;
46
+ const newIndex = limits.items.findIndex((center) => deltaMouseY <= center);
47
+ if (newIndex !== indexTo) {
48
+ indexTo = newIndex;
49
+ placeholder?.moveTo(indexTo);
50
+ }
51
+ },
52
+ end() {
53
+ events.emit('dragEnd');
54
+ resetDragStyle(itemElement);
55
+ placeholder?.remove();
56
+ listElement.classList.remove(CLASSNAME_DRAG_ACTIVE);
57
+ itemElement.classList.remove(CLASSNAME_DRAG_ACTIVE);
58
+ if (indexFrom === indexTo)
59
+ return;
60
+ if (!limits?.items)
61
+ return;
62
+ const len = limits.items.length;
63
+ const newOrderIndex = getNewOrderIndex(len, indexFrom, indexTo);
64
+ if (options.onReindex)
65
+ options.onReindex(newOrderIndex);
66
+ if (options.onChange) {
67
+ if (!options.items) {
68
+ console.error('WARNING', 'The option "onChange" require "items"');
69
+ return;
70
+ }
71
+ const newOrderItems = newOrderIndex.map((index) => options.items[index]);
72
+ options.onChange(newOrderItems);
73
+ options.items = newOrderItems;
74
+ }
75
+ },
76
+ };
77
+ }
78
+ function createEventEmitter(initialEvents) {
79
+ const events = { ...initialEvents };
80
+ return {
81
+ on(event, callback) {
82
+ events[event].push(callback);
83
+ },
84
+ off(event, callback) {
85
+ const index = events[event].indexOf(callback);
86
+ events[event].splice(index, 1);
87
+ },
88
+ emit(event) {
89
+ events[event].forEach((callback) => callback());
90
+ },
91
+ };
92
+ }
@@ -0,0 +1,40 @@
1
+ .editable-list {
2
+ position: relative;
3
+ --border-radius: 5px;
4
+ --background-hover: rgb(246, 246, 246);
5
+ --background-active: rgb(235, 235, 235);
6
+ border-radius: var(--border-radius);
7
+ }
8
+
9
+ .editable-list .item-delete {
10
+ transition: opacity 200ms ease;
11
+ opacity: 1;
12
+ }
13
+
14
+ .editable-list.drag-active .item-delete {
15
+ opacity: 0;
16
+ }
17
+
18
+ .editable-list > div {
19
+ cursor: pointer;
20
+ border-radius: var(--border-radius);
21
+ -ms-user-select: none;
22
+ user-select: none;
23
+ }
24
+
25
+ .editable-list > div:hover {
26
+ background: var(--background-hover);
27
+ }
28
+
29
+ .editable-list > div.drag-active {
30
+ background: var(--background-active);
31
+ }
32
+
33
+ .item-content {
34
+ flex-grow: 1;
35
+ }
36
+
37
+ .item-placholder {
38
+ background: var(--background-hover);
39
+ border-radius: var(--border-radius);
40
+ }
@@ -0,0 +1,23 @@
1
+ export declare const CLASSNAME_LIST = "editable-list";
2
+ export declare const CLASSNAME_DRAG_ACTIVE = "drag-active";
3
+ export declare const CLASSNAME_PLACEHOLDER = "item-placholder";
4
+ export interface ListEditableOptions<Type = unknown> {
5
+ onDragStart?: () => void;
6
+ onDragMove?: () => void;
7
+ onDragEnd?: () => void;
8
+ onHover?: (newOrder: number[]) => void;
9
+ onMove?: (indexFrom: number, indexTo: number) => void;
10
+ /** Déclencher quand l'ordre change. newOrder est un tableau d'index */
11
+ onReindex?: (newOrder: number[]) => void;
12
+ /** Déclencher quand l'ordre change. newOrder est les items fournit réordonné */
13
+ onChange?: (newOrder: Type[]) => void;
14
+ /** Fournir les items pour directement récupérer la liste à jour dans onChange */
15
+ items?: Type[];
16
+ onDelete?: (index: number, items?: Type[]) => void;
17
+ /** Only handle reorder from this elements */
18
+ dragElementsSelector?: string;
19
+ }
20
+ export declare function listEditable<Type = unknown>(node: HTMLDivElement, options?: ListEditableOptions<Type>): {
21
+ destroy(): void;
22
+ update({ items }: ListEditableOptions<Type>): void;
23
+ };
@@ -0,0 +1,44 @@
1
+ import { createDragHandler } from './handlers.js';
2
+ import { mouseDragTrigger, touchDragTrigger, scrollTrigger } from './trigger.js';
3
+ export const CLASSNAME_LIST = 'editable-list';
4
+ export const CLASSNAME_DRAG_ACTIVE = 'drag-active';
5
+ export const CLASSNAME_PLACEHOLDER = 'item-placholder';
6
+ export function listEditable(node, options = {}) {
7
+ const { dragElementsSelector } = options;
8
+ node.classList.add(CLASSNAME_LIST);
9
+ let mouseListeners = [];
10
+ let touchListeners = [];
11
+ let scrollListeners = [];
12
+ createListeners();
13
+ function createListeners() {
14
+ const itemElements = [...node.children];
15
+ const dragElements = [
16
+ ...(dragElementsSelector ? node.querySelectorAll(dragElementsSelector) : itemElements)
17
+ ];
18
+ const dragHandlers = dragElements.map((d, index) => createDragHandler(node, itemElements[index], options));
19
+ mouseListeners = dragElements.map((dragElement, index) => mouseDragTrigger(dragElement, dragHandlers[index]));
20
+ touchListeners = dragElements.map((dragElement, index) => touchDragTrigger(dragElement, dragHandlers[index]));
21
+ const scrollContainer = node.parentElement;
22
+ if (scrollContainer) {
23
+ scrollListeners = dragHandlers.map((handler) => scrollTrigger(handler, scrollContainer));
24
+ }
25
+ }
26
+ function removeListeners() {
27
+ mouseListeners.forEach((listener) => listener.destroy());
28
+ touchListeners.forEach((listener) => listener.destroy());
29
+ scrollListeners.forEach((listener) => listener.destroy());
30
+ }
31
+ return {
32
+ destroy() {
33
+ node?.classList.remove(CLASSNAME_LIST);
34
+ removeListeners();
35
+ },
36
+ update({ items }) {
37
+ if (items?.length !== options.items?.length) {
38
+ removeListeners();
39
+ createListeners();
40
+ }
41
+ options.items = items;
42
+ }
43
+ };
44
+ }
@@ -0,0 +1,3 @@
1
+ export declare const scroll: {
2
+ top: number;
3
+ };
@@ -0,0 +1 @@
1
+ export const scroll = { top: 0 };
@@ -0,0 +1,2 @@
1
+ export declare function initDragStyle(listItemEl: HTMLElement): void;
2
+ export declare function resetDragStyle(listItemEl: HTMLElement): void;
@@ -0,0 +1,14 @@
1
+ export function initDragStyle(listItemEl) {
2
+ listItemEl.style.zIndex = `${+listItemEl.style.zIndex + 1}`;
3
+ listItemEl.style.top = `${listItemEl.offsetTop}px`;
4
+ listItemEl.style.width = `${listItemEl.offsetWidth}px`;
5
+ listItemEl.style.height = `${listItemEl.offsetHeight}px`;
6
+ listItemEl.style.position = 'absolute';
7
+ }
8
+ export function resetDragStyle(listItemEl) {
9
+ listItemEl.style.position = 'initial';
10
+ listItemEl.style.zIndex = `${+listItemEl.style.zIndex - 1}`;
11
+ listItemEl.style.transform = '';
12
+ listItemEl.style.width = `auto`;
13
+ listItemEl.style.height = `auto`;
14
+ }
@@ -0,0 +1,12 @@
1
+ import type { DragHandler } from './handlers.js';
2
+ /** Gestion du cycle de vie des évènements de la souris */
3
+ export declare function mouseDragTrigger(element: HTMLElement, handler: DragHandler): {
4
+ destroy(): void;
5
+ };
6
+ /** Gestion du cycle de vie des évènements de la souris */
7
+ export declare function touchDragTrigger(element: HTMLElement, handler: DragHandler): {
8
+ destroy(): void;
9
+ };
10
+ export declare function scrollTrigger(handler: DragHandler, scrollContainer: Element): {
11
+ destroy(): void;
12
+ };
@@ -0,0 +1,124 @@
1
+ import { scroll } from './store.js';
2
+ /** Gestion du cycle de vie des évènements de la souris */
3
+ export function mouseDragTrigger(element, handler) {
4
+ function startHandler(event) {
5
+ handler.start(event);
6
+ document.addEventListener('mousemove', handler.move);
7
+ document.addEventListener('mouseup', endHandler, { once: true });
8
+ }
9
+ function endHandler() {
10
+ document.removeEventListener('mousemove', handler.move);
11
+ handler.end();
12
+ }
13
+ function stopPropagation(event) {
14
+ event.stopPropagation();
15
+ }
16
+ element.addEventListener('mousedown', startHandler);
17
+ element.addEventListener('click', stopPropagation);
18
+ return {
19
+ destroy() {
20
+ element?.removeEventListener('mousedown', startHandler);
21
+ element?.removeEventListener('click', stopPropagation);
22
+ document.removeEventListener('mousemove', handler.move);
23
+ document.removeEventListener('mouseup', endHandler);
24
+ }
25
+ };
26
+ }
27
+ /** Gestion du cycle de vie des évènements de la souris */
28
+ export function touchDragTrigger(element, handler) {
29
+ let onDrag = false;
30
+ function startHandler(event) {
31
+ onDrag = true;
32
+ handler.start(event.touches[0]);
33
+ }
34
+ function moveHandler(event) {
35
+ if (!onDrag)
36
+ return;
37
+ event.preventDefault();
38
+ handler.move(event.touches[0]);
39
+ }
40
+ function endHandler() {
41
+ onDrag = false;
42
+ handler.end();
43
+ }
44
+ function stopPropagation(event) {
45
+ event.stopPropagation();
46
+ }
47
+ element.addEventListener('touchstart', startHandler);
48
+ element.addEventListener('touchmove', moveHandler);
49
+ element.addEventListener('touchend', endHandler);
50
+ element.addEventListener('click', stopPropagation);
51
+ return {
52
+ destroy() {
53
+ if (!element)
54
+ return;
55
+ element.removeEventListener('touchstart', startHandler);
56
+ element.removeEventListener('touchmove', moveHandler);
57
+ element.removeEventListener('touchend', endHandler);
58
+ element.removeEventListener('click', stopPropagation);
59
+ }
60
+ };
61
+ }
62
+ export function scrollTrigger(handler, scrollContainer) {
63
+ let listeners = [];
64
+ let mousePosition = { clientX: 0, clientY: 0 };
65
+ let containerRect = { top: 0, bottom: 0 };
66
+ function createScrollListener() {
67
+ const scrollHandler = () => {
68
+ scroll.top = scrollContainer.scrollTop;
69
+ handler.move();
70
+ scrollOnTheEdge();
71
+ };
72
+ scrollContainer.addEventListener('scroll', scrollHandler);
73
+ return {
74
+ destroy() {
75
+ scrollContainer.removeEventListener('scroll', scrollHandler);
76
+ }
77
+ };
78
+ }
79
+ function createMouseListener() {
80
+ const mouseMoveHandler = ({ clientX, clientY }) => {
81
+ mousePosition = { clientX, clientY };
82
+ scrollOnTheEdge();
83
+ };
84
+ document.addEventListener('mousemove', mouseMoveHandler);
85
+ return {
86
+ destroy() {
87
+ document.removeEventListener('mousemove', mouseMoveHandler);
88
+ }
89
+ };
90
+ }
91
+ const EDGE_SCROLL_ZONE = 0;
92
+ const SCROLL_INCREMENT = 3;
93
+ function scrollOnTheEdge() {
94
+ const { top, bottom } = containerRect;
95
+ const { clientY } = mousePosition;
96
+ const isOnTop = top + EDGE_SCROLL_ZONE > clientY;
97
+ const isOnBottom = bottom - EDGE_SCROLL_ZONE < clientY;
98
+ const { scrollTop, scrollHeight } = scrollContainer;
99
+ if (isOnTop && scrollTop - SCROLL_INCREMENT > 0) {
100
+ scrollContainer.scrollTo({ top: scrollTop - SCROLL_INCREMENT });
101
+ }
102
+ else if (isOnBottom &&
103
+ scrollContainer.scrollTop + SCROLL_INCREMENT < scrollTop + scrollHeight) {
104
+ scrollContainer.scrollTo({ top: scrollTop + SCROLL_INCREMENT });
105
+ }
106
+ }
107
+ function dragStart() {
108
+ containerRect = scrollContainer.getBoundingClientRect();
109
+ listeners = [createScrollListener(), createMouseListener()];
110
+ }
111
+ function dragEnd() {
112
+ listeners.forEach(({ destroy }) => destroy());
113
+ listeners = [];
114
+ }
115
+ handler.on('dragStart', dragStart);
116
+ handler.on('dragEnd', dragEnd);
117
+ return {
118
+ destroy() {
119
+ handler.off('dragStart', dragStart);
120
+ handler.off('dragEnd', dragEnd);
121
+ listeners.forEach(({ destroy }) => destroy());
122
+ }
123
+ };
124
+ }
@@ -0,0 +1,18 @@
1
+ export declare function getListItemIndex(listElement: HTMLElement, itemEl: HTMLElement): number;
2
+ export interface CreatePlaceholderArgs {
3
+ listElement: HTMLElement;
4
+ itemElement: HTMLElement;
5
+ indexFrom: number;
6
+ }
7
+ export declare function createPlaceholder({ listElement, itemElement, indexFrom }: CreatePlaceholderArgs): {
8
+ moveTo: (index: number) => void;
9
+ remove(): void;
10
+ };
11
+ export interface Limits {
12
+ top: number;
13
+ bottom: number;
14
+ items: number[];
15
+ }
16
+ /** Calcule les limites de déplacement supérieur, inférieur et les frontières entre deux items */
17
+ export declare function computeLimits(listElement: HTMLElement, listItemEl: HTMLElement): Limits | null;
18
+ export declare function getNewOrderIndex(len: number, indexFrom: number, indexTo: number): number[];
@@ -0,0 +1,68 @@
1
+ import { CLASSNAME_PLACEHOLDER } from './index.js';
2
+ export function getListItemIndex(listElement, itemEl) {
3
+ return [...listElement.children].findIndex((item) => item === itemEl);
4
+ }
5
+ export function createPlaceholder({ listElement, itemElement, indexFrom }) {
6
+ const itemsEl = [...listElement.children];
7
+ const placeholderEl = document.createElement('div');
8
+ placeholderEl.classList.add(CLASSNAME_PLACEHOLDER);
9
+ placeholderEl.style.height = itemElement.style.height;
10
+ placeholderEl.style.width = itemElement.style.width;
11
+ listElement.insertBefore(placeholderEl, itemElement);
12
+ const moveTo = (index) => {
13
+ const selectorIndex = index < indexFrom ? index : index + 1;
14
+ const itemEl = itemsEl[selectorIndex];
15
+ listElement.insertBefore(placeholderEl, itemEl);
16
+ };
17
+ return {
18
+ moveTo,
19
+ remove() {
20
+ const parent = placeholderEl.parentNode;
21
+ parent?.removeChild(placeholderEl);
22
+ placeholderEl.remove();
23
+ }
24
+ };
25
+ }
26
+ /** Calcule les limites de déplacement supérieur, inférieur et les frontières entre deux items */
27
+ export function computeLimits(listElement, listItemEl) {
28
+ const rect = listItemEl.getBoundingClientRect();
29
+ const itemsRect = [...listElement.children]
30
+ .filter((el) => !el.classList.contains(CLASSNAME_PLACEHOLDER))
31
+ .map((el) => el.getBoundingClientRect());
32
+ const tops = itemsRect.map((item) => item.top - rect.top);
33
+ const bottoms = itemsRect.map((item) => item.bottom - rect.bottom);
34
+ const items = itemsRect
35
+ .map((item, index, self) => {
36
+ if (index === self.length - 1)
37
+ return false;
38
+ if (tops[index] < 0)
39
+ return tops[index] + item.height / 2;
40
+ return bottoms[index] + self[index + 1].height / 2;
41
+ })
42
+ .filter((v) => v !== false);
43
+ items.push(Infinity);
44
+ return {
45
+ top: tops[0],
46
+ bottom: bottoms[bottoms.length - 1],
47
+ items
48
+ };
49
+ }
50
+ export function getNewOrderIndex(len, indexFrom, indexTo) {
51
+ const [start, end] = [indexFrom, indexTo].sort((a, b) => a - b);
52
+ const arr = Array(len)
53
+ .fill(null)
54
+ .map((_, i) => i);
55
+ const arrStart = arr.slice(0, start);
56
+ const arrEnd = arr.slice(end + 1);
57
+ const arrMove = arr.slice(start, end + 1);
58
+ if (indexFrom < indexTo) {
59
+ arrMove.shift();
60
+ arrMove.push(indexFrom);
61
+ }
62
+ else {
63
+ arrMove.pop();
64
+ arrMove.unshift(indexFrom);
65
+ }
66
+ const newOrder = [...arrStart, ...arrMove, ...arrEnd];
67
+ return newOrder;
68
+ }
@@ -0,0 +1,3 @@
1
+ export declare function portal(node: HTMLElement, selector: string): {
2
+ destroy: () => void;
3
+ };
@@ -0,0 +1,9 @@
1
+ export function portal(node, selector) {
2
+ const target = document.querySelector(selector);
3
+ if (!target)
4
+ throw `tagret not found for selector "${selector}"`;
5
+ target.appendChild(node);
6
+ return {
7
+ destroy: () => node.remove(),
8
+ };
9
+ }
@@ -0,0 +1,15 @@
1
+ type Params = {
2
+ trigger: HTMLElement | undefined;
3
+ focusIndex?: number;
4
+ listQuerySelector?: string;
5
+ itemsQuerySelector?: string;
6
+ onSelect?: (index: number) => unknown;
7
+ onFocus?: (index: number) => unknown;
8
+ keyDownEvent?: KeyboardEvent | undefined;
9
+ keyDownPreventDefault?: boolean;
10
+ };
11
+ export declare function selector(node: HTMLElement, { trigger, focusIndex, listQuerySelector, itemsQuerySelector, onSelect, onFocus, keyDownEvent, keyDownPreventDefault, }: Params): {
12
+ update(props: Partial<Params>): void;
13
+ destroy(): void;
14
+ };
15
+ export {};