@licklist/design 0.44.485-dev.81 → 0.44.485-dev.82

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/index.d.ts CHANGED
@@ -18,6 +18,7 @@ export * from "./sales";
18
18
  export * from "./setting";
19
19
  export * from "./sidebar";
20
20
  export * from "./snippet";
21
+ export * from "./sortable-fields";
21
22
  export * from "./sortable-list";
22
23
  export * from "./sortable-tree";
23
24
  export * from "./static";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,e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@ -0,0 +1,10 @@
1
+ import type { PropsWithChildren } from "react";
2
+ import type { UniqueIdentifier } from "@dnd-kit/core";
3
+ import "./style.scss";
4
+ interface Props {
5
+ id: UniqueIdentifier;
6
+ }
7
+ export declare function SortableFieldItem({ children, id }: PropsWithChildren<Props>): JSX.Element;
8
+ export declare function DragHandle(): JSX.Element;
9
+ export {};
10
+ //# sourceMappingURL=SortableFieldItem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SortableFieldItem.d.ts","sourceRoot":"","sources":["../../src/sortable-fields/SortableFieldItem.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAiB,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC9D,OAAO,KAAK,EAEV,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAGvB,OAAO,cAAc,CAAC;AAEtB,UAAU,KAAK;IACb,EAAE,EAAE,gBAAgB,CAAC;CACtB;AAYD,wBAAgB,iBAAiB,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,iBAAiB,CAAC,KAAK,CAAC,eAsB3E;AAED,wBAAgB,UAAU,gBAYzB"}
@@ -0,0 +1,18 @@
1
+ import type { ReactNode } from "react";
2
+ import type { UniqueIdentifier } from "@dnd-kit/core";
3
+ import { SortableFieldItem } from "./SortableFieldItem";
4
+ interface BaseItem {
5
+ id: UniqueIdentifier;
6
+ }
7
+ interface Props<T extends BaseItem> {
8
+ items: T[];
9
+ onChange(activeIndex: number, overIndex: number): void;
10
+ renderItem(item: T, index: number): ReactNode;
11
+ }
12
+ export declare function SortableFieldList<T extends BaseItem>({ items, onChange, renderItem, }: Props<T>): JSX.Element;
13
+ export declare namespace SortableFieldList {
14
+ var Item: typeof SortableFieldItem;
15
+ var DragHandle: typeof import("./SortableFieldItem").DragHandle;
16
+ }
17
+ export {};
18
+ //# sourceMappingURL=SortableFieldList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SortableFieldList.d.ts","sourceRoot":"","sources":["../../src/sortable-fields/SortableFieldList.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAQvC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAMtD,OAAO,EAAc,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEpE,UAAU,QAAQ;IAChB,EAAE,EAAE,gBAAgB,CAAC;CACtB;AAED,UAAU,KAAK,CAAC,CAAC,SAAS,QAAQ;IAChC,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACvD,UAAU,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/C;AAED,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,QAAQ,EAAE,EACpD,KAAK,EACL,QAAQ,EACR,UAAU,GACX,EAAE,KAAK,CAAC,CAAC,CAAC,eA2BV;yBA/Be,iBAAiB"}
@@ -0,0 +1,2 @@
1
+ export type { SortableFieldList } from "./SortableFieldList";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sortable-fields/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC"}
@@ -8,6 +8,7 @@
8
8
  @import "./sales";
9
9
  @import "./setting";
10
10
  @import "./sidebar";
11
+ @import "./sortable-field";
11
12
  @import "./sortable-tree";
12
13
  @import "./static";
13
14
  @import "./table";
@@ -0,0 +1,21 @@
1
+ .sortable-field-list {
2
+ display: flex;
3
+
4
+ .icon-container {
5
+ margin-right: .8rem;
6
+ margin-left: .2rem;
7
+ margin-top: 1rem;
8
+
9
+ div {
10
+ width: 0.75rem;
11
+ height: 2px;
12
+ margin-bottom: 2px;
13
+ background-color: #B5CCDE;
14
+ border-radius: 1px;
15
+ }
16
+ }
17
+
18
+ .form-group {
19
+ width: 100%;
20
+ }
21
+ }
@@ -0,0 +1 @@
1
+ @import "./SortableField";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@licklist/design",
3
- "version": "0.44.485-dev.81",
3
+ "version": "0.44.485-dev.82",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+ssh://git@bitbucket.org/artelogicsoft/licklist_design.git"
package/src/index.ts CHANGED
@@ -18,6 +18,7 @@ export * from "./sales";
18
18
  export * from "./setting";
19
19
  export * from "./sidebar";
20
20
  export * from "./snippet";
21
+ export * from "./sortable-fields";
21
22
  export * from "./sortable-list";
22
23
  export * from "./sortable-tree";
23
24
  export * from "./static";
@@ -0,0 +1,61 @@
1
+ import React, { createContext, useContext, useMemo } from "react";
2
+ import type { CSSProperties, PropsWithChildren } from "react";
3
+ import type {
4
+ DraggableSyntheticListeners,
5
+ UniqueIdentifier,
6
+ } from "@dnd-kit/core";
7
+ import { useSortable } from "@dnd-kit/sortable";
8
+ import { CSS } from "@dnd-kit/utilities";
9
+ import "./style.scss";
10
+
11
+ interface Props {
12
+ id: UniqueIdentifier;
13
+ }
14
+
15
+ interface Context {
16
+ listeners: DraggableSyntheticListeners;
17
+ ref(node: HTMLElement | null): void;
18
+ }
19
+
20
+ const SortableItemContext = createContext<Context>({
21
+ listeners: undefined,
22
+ ref: () => {},
23
+ });
24
+
25
+ export function SortableFieldItem({ children, id }: PropsWithChildren<Props>) {
26
+ const { isDragging, listeners, setNodeRef, setDraggableNodeRef, transform } =
27
+ useSortable({ id });
28
+ const context = useMemo(
29
+ () => ({
30
+ listeners,
31
+ ref: setDraggableNodeRef,
32
+ }),
33
+ [listeners, setDraggableNodeRef]
34
+ );
35
+ const style: CSSProperties = {
36
+ opacity: isDragging ? 0.4 : undefined,
37
+ transform: CSS.Translate.toString(transform),
38
+ };
39
+
40
+ return (
41
+ <SortableItemContext.Provider value={context}>
42
+ <div ref={setNodeRef} className="sortable-field-list" style={style}>
43
+ {children}
44
+ </div>
45
+ </SortableItemContext.Provider>
46
+ );
47
+ }
48
+
49
+ export function DragHandle() {
50
+ const { listeners, ref } = useContext(SortableItemContext);
51
+
52
+ return (
53
+ <div {...listeners} ref={ref}>
54
+ <div className="icon-container">
55
+ <div />
56
+ <div />
57
+ <div />
58
+ </div>
59
+ </div>
60
+ );
61
+ }
@@ -0,0 +1,62 @@
1
+ import React from "react";
2
+ import type { ReactNode } from "react";
3
+ import {
4
+ DndContext,
5
+ KeyboardSensor,
6
+ PointerSensor,
7
+ useSensor,
8
+ useSensors,
9
+ } from "@dnd-kit/core";
10
+ import type { UniqueIdentifier } from "@dnd-kit/core";
11
+ import {
12
+ SortableContext,
13
+ sortableKeyboardCoordinates,
14
+ } from "@dnd-kit/sortable";
15
+
16
+ import { DragHandle, SortableFieldItem } from "./SortableFieldItem";
17
+
18
+ interface BaseItem {
19
+ id: UniqueIdentifier;
20
+ }
21
+
22
+ interface Props<T extends BaseItem> {
23
+ items: T[];
24
+ onChange(activeIndex: number, overIndex: number): void;
25
+ renderItem(item: T, index: number): ReactNode;
26
+ }
27
+
28
+ export function SortableFieldList<T extends BaseItem>({
29
+ items,
30
+ onChange,
31
+ renderItem,
32
+ }: Props<T>) {
33
+ const sensors = useSensors(
34
+ useSensor(PointerSensor),
35
+ useSensor(KeyboardSensor, {
36
+ coordinateGetter: sortableKeyboardCoordinates,
37
+ })
38
+ );
39
+
40
+ return (
41
+ <DndContext
42
+ sensors={sensors}
43
+ onDragEnd={({ active, over }) => {
44
+ if (over && active.id !== over?.id) {
45
+ const activeIndex = items.findIndex(({ id }) => id === active.id);
46
+ const overIndex = items.findIndex(({ id }) => id === over.id);
47
+
48
+ onChange(activeIndex, overIndex);
49
+ }
50
+ }}
51
+ >
52
+ <SortableContext items={items}>
53
+ {items.map((item, index) => (
54
+ <div key={item.id}>{renderItem(item, index)}</div>
55
+ ))}
56
+ </SortableContext>
57
+ </DndContext>
58
+ );
59
+ }
60
+
61
+ SortableFieldList.Item = SortableFieldItem;
62
+ SortableFieldList.DragHandle = DragHandle;
@@ -0,0 +1 @@
1
+ export type { SortableFieldList } from "./SortableFieldList";
@@ -8,6 +8,7 @@
8
8
  @import "./sales";
9
9
  @import "./setting";
10
10
  @import "./sidebar";
11
+ @import "./sortable-field";
11
12
  @import "./sortable-tree";
12
13
  @import "./static";
13
14
  @import "./table";
@@ -0,0 +1,21 @@
1
+ .sortable-field-list {
2
+ display: flex;
3
+
4
+ .icon-container {
5
+ margin-right: .8rem;
6
+ margin-left: .2rem;
7
+ margin-top: 1rem;
8
+
9
+ div {
10
+ width: 0.75rem;
11
+ height: 2px;
12
+ margin-bottom: 2px;
13
+ background-color: #B5CCDE;
14
+ border-radius: 1px;
15
+ }
16
+ }
17
+
18
+ .form-group {
19
+ width: 100%;
20
+ }
21
+ }
@@ -0,0 +1 @@
1
+ @import "./SortableField";