@window-splitter/interface 0.7.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 (57) hide show
  1. package/.tshy/build.json +8 -0
  2. package/.tshy/commonjs.json +18 -0
  3. package/.tshy/esm.json +17 -0
  4. package/.turbo/turbo-build.log +5 -0
  5. package/.turbo/turbo-lint.log +5 -0
  6. package/CHANGELOG.md +44 -0
  7. package/README.md +3 -0
  8. package/dist/commonjs/index.d.ts +4 -0
  9. package/dist/commonjs/index.d.ts.map +1 -0
  10. package/dist/commonjs/index.js +20 -0
  11. package/dist/commonjs/index.js.map +1 -0
  12. package/dist/commonjs/interface.d.ts +128 -0
  13. package/dist/commonjs/interface.d.ts.map +1 -0
  14. package/dist/commonjs/interface.js +67 -0
  15. package/dist/commonjs/interface.js.map +1 -0
  16. package/dist/commonjs/mergeAttributes.d.ts +19 -0
  17. package/dist/commonjs/mergeAttributes.d.ts.map +1 -0
  18. package/dist/commonjs/mergeAttributes.js +63 -0
  19. package/dist/commonjs/mergeAttributes.js.map +1 -0
  20. package/dist/commonjs/move.d.ts +52 -0
  21. package/dist/commonjs/move.d.ts.map +1 -0
  22. package/dist/commonjs/move.js +124 -0
  23. package/dist/commonjs/move.js.map +1 -0
  24. package/dist/commonjs/package.json +3 -0
  25. package/dist/commonjs/test.d.ts +18 -0
  26. package/dist/commonjs/test.d.ts.map +1 -0
  27. package/dist/commonjs/test.js +85 -0
  28. package/dist/commonjs/test.js.map +1 -0
  29. package/dist/esm/index.d.ts +4 -0
  30. package/dist/esm/index.d.ts.map +1 -0
  31. package/dist/esm/index.js +4 -0
  32. package/dist/esm/index.js.map +1 -0
  33. package/dist/esm/interface.d.ts +128 -0
  34. package/dist/esm/interface.d.ts.map +1 -0
  35. package/dist/esm/interface.js +62 -0
  36. package/dist/esm/interface.js.map +1 -0
  37. package/dist/esm/mergeAttributes.d.ts +19 -0
  38. package/dist/esm/mergeAttributes.d.ts.map +1 -0
  39. package/dist/esm/mergeAttributes.js +60 -0
  40. package/dist/esm/mergeAttributes.js.map +1 -0
  41. package/dist/esm/move.d.ts +52 -0
  42. package/dist/esm/move.d.ts.map +1 -0
  43. package/dist/esm/move.js +121 -0
  44. package/dist/esm/move.js.map +1 -0
  45. package/dist/esm/package.json +3 -0
  46. package/dist/esm/test.d.ts +18 -0
  47. package/dist/esm/test.d.ts.map +1 -0
  48. package/dist/esm/test.js +81 -0
  49. package/dist/esm/test.js.map +1 -0
  50. package/eslint.config.js +3 -0
  51. package/package.json +83 -0
  52. package/src/index.ts +3 -0
  53. package/src/interface.ts +214 -0
  54. package/src/mergeAttributes.ts +84 -0
  55. package/src/move.ts +210 -0
  56. package/src/test.ts +133 -0
  57. package/tsconfig.json +6 -0
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "../src",
5
+ "module": "nodenext",
6
+ "moduleResolution": "nodenext"
7
+ }
8
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": "./build.json",
3
+ "include": [
4
+ "../src/**/*.ts",
5
+ "../src/**/*.cts",
6
+ "../src/**/*.tsx",
7
+ "../src/**/*.json"
8
+ ],
9
+ "exclude": [
10
+ "../src/**/*.test.ts",
11
+ "../node_modules",
12
+ "../src/**/*.mts",
13
+ "../src/package.json"
14
+ ],
15
+ "compilerOptions": {
16
+ "outDir": "../.tshy-build/commonjs"
17
+ }
18
+ }
package/.tshy/esm.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "extends": "./build.json",
3
+ "include": [
4
+ "../src/**/*.ts",
5
+ "../src/**/*.mts",
6
+ "../src/**/*.tsx",
7
+ "../src/**/*.json"
8
+ ],
9
+ "exclude": [
10
+ "../src/**/*.test.ts",
11
+ "../node_modules",
12
+ "../src/package.json"
13
+ ],
14
+ "compilerOptions": {
15
+ "outDir": "../.tshy-build/esm"
16
+ }
17
+ }
@@ -0,0 +1,5 @@
1
+
2
+ 
3
+ > @window-splitter/interface@0.6.5 build /Users/andrew/Documents/react-window-splitter/packages/interface
4
+ > tshy
5
+
@@ -0,0 +1,5 @@
1
+
2
+ 
3
+ > @window-splitter/interface@0.6.5 lint /Users/andrew/Documents/react-window-splitter/packages/interface
4
+ > eslint .
5
+
package/CHANGELOG.md ADDED
@@ -0,0 +1,44 @@
1
+ # v0.7.0 (Mon Apr 28 2025)
2
+
3
+ ### Release Notes
4
+
5
+ #### `@window-splitter/solid` ([#54](https://github.com/hipstersmoothie/window-splitter/pull/54))
6
+
7
+ The second framework adapter for `window-splitter` is live!
8
+
9
+ Things of note:
10
+
11
+ - `react-window-splitter` is deprecated in favor of `@window-splitter/react`
12
+ - `@window-splitter/solid` is feature complete and passes the test full test suite
13
+ - `@window-splitter/interface` was created to house the shared component types and some help functions
14
+
15
+ In creating the solid adapter we had to make vanilla JS versions of some functions we previously got from a dependency. This resulted in a 7.4% bundle size reduction for the react package 🎉
16
+
17
+ ### Breaking Change
18
+
19
+ The API for registering panel handles changed a little bit. If you're using the `@window-splitter/state` package directly you will have to update your code (if you exist send me a message!)
20
+
21
+ ---
22
+
23
+ #### 🚀 Enhancement
24
+
25
+ - `@window-splitter/solid` [#54](https://github.com/hipstersmoothie/window-splitter/pull/54) ([@hipstersmoothie](https://github.com/hipstersmoothie))
26
+
27
+ #### 🐛 Bug Fix
28
+
29
+ - lint ([@hipstersmoothie](https://github.com/hipstersmoothie))
30
+ - fix attr merging ([@hipstersmoothie](https://github.com/hipstersmoothie))
31
+ - fix unmount ([@hipstersmoothie](https://github.com/hipstersmoothie))
32
+ - ugh ([@hipstersmoothie](https://github.com/hipstersmoothie))
33
+ - update names ([@hipstersmoothie](https://github.com/hipstersmoothie))
34
+ - build ([@hipstersmoothie](https://github.com/hipstersmoothie))
35
+ - use shared move ([@hipstersmoothie](https://github.com/hipstersmoothie))
36
+ - fix lint ([@hipstersmoothie](https://github.com/hipstersmoothie))
37
+ - fix build ([@hipstersmoothie](https://github.com/hipstersmoothie))
38
+ - move move ([@hipstersmoothie](https://github.com/hipstersmoothie))
39
+ - move shared stuff ([@hipstersmoothie](https://github.com/hipstersmoothie))
40
+ - move shared types out ([@hipstersmoothie](https://github.com/hipstersmoothie))
41
+
42
+ #### Authors: 1
43
+
44
+ - Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie))
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # `@window-splitter/interface`
2
+
3
+ Shared component interface for window splitter components.
@@ -0,0 +1,4 @@
1
+ export * from "./interface.js";
2
+ export * from "./move.js";
3
+ export * from "./mergeAttributes.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./interface.js"), exports);
18
+ __exportStar(require("./move.js"), exports);
19
+ __exportStar(require("./mergeAttributes.js"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAC/B,4CAA0B;AAC1B,uDAAqC","sourcesContent":["export * from \"./interface.js\";\nexport * from \"./move.js\";\nexport * from \"./mergeAttributes.js\";\n"]}
@@ -0,0 +1,128 @@
1
+ import { Constraints, GroupMachineContextValue, OnResizeCallback, PanelData, ParsedUnit, PixelUnit, Rect, Unit } from "@window-splitter/state";
2
+ export interface PanelGroupHandle {
3
+ /** The id of the group */
4
+ getId: () => string;
5
+ /** Get the sizes of all the items in the layout as pixels */
6
+ getPixelSizes: () => Array<number>;
7
+ /** Get the sizes of all the items in the layout as percentages of the group size */
8
+ getPercentageSizes: () => Array<number>;
9
+ /**
10
+ * Set the size of all the items in the layout.
11
+ * This just calls `setSize` on each item. It is up to
12
+ * you to make sure the sizes make sense.
13
+ *
14
+ * NOTE: Setting handle sizes will do nothing.
15
+ */
16
+ setSizes: (items: Array<Unit>) => void;
17
+ /** Get the template for the group in pixels. Useful for testing */
18
+ getTemplate: () => string;
19
+ getState: () => "idle" | "dragging";
20
+ }
21
+ export interface SharedPanelGroupProps extends Partial<Pick<GroupMachineContextValue, "orientation" | "autosaveStrategy">> {
22
+ /** Persisted state to initialized the machine with */
23
+ snapshot?: GroupMachineContextValue;
24
+ /** An id to use for autosaving the layout */
25
+ autosaveId?: string;
26
+ }
27
+ export interface PanelHandle {
28
+ /** Collapse the panel */
29
+ collapse: () => void;
30
+ /** Returns true if the panel is collapsed */
31
+ isCollapsed: () => boolean;
32
+ /** Expand the panel */
33
+ expand: () => void;
34
+ /** Returns true if the panel is expanded */
35
+ isExpanded: () => boolean;
36
+ /** The id of the panel */
37
+ getId: () => string;
38
+ /** Get the size of the panel in pixels */
39
+ getPixelSize: () => number;
40
+ /** Get percentage of the panel relative to the group */
41
+ getPercentageSize: () => number;
42
+ /**
43
+ * Set the size of the panel in pixels.
44
+ *
45
+ * This will be clamped to the min/max values of the panel.
46
+ * If you want the panel to collapse/expand you should use the
47
+ * expand/collapse methods.
48
+ */
49
+ setSize: (size: Unit) => void;
50
+ }
51
+ export interface SharedPanelProps<CollapsValue> extends Constraints<Unit>, Pick<PanelData, "collapseAnimation"> {
52
+ /** Callback called when the panel is resized */
53
+ onResize?: OnResizeCallback;
54
+ /**
55
+ * __CONTROLLED COMPONENT__
56
+ *
57
+ * If this prop is used it will be used as the source of truth for the collapsed state.
58
+ * It should be used in conjunction with the `onCollapseChange` prop.
59
+ *
60
+ * Use this if you want full control over the collapsed state. When trying to
61
+ * collapse a panel it will defer to onCollapseChange to determine if it should
62
+ * be collapsed.
63
+ */
64
+ collapsed?: CollapsValue;
65
+ /**
66
+ * __CONTROLLED COMPONENT__
67
+ *
68
+ * A callback called with the new desired collapsed state. If paired w
69
+ * with the `collapsed` prop this will be used to control the collapsed state.
70
+ *
71
+ * Otherwise this will just be called with the new collapsed state so you can
72
+ * use it to update your own state.
73
+ */
74
+ onCollapseChange?: (isCollapsed: boolean) => void;
75
+ }
76
+ export declare function getPanelDomAttributes({ groupId, id, collapsible, collapsed, }: {
77
+ groupId: string | undefined;
78
+ id: string;
79
+ collapsible: boolean | undefined;
80
+ collapsed: boolean | undefined;
81
+ }): {
82
+ id: string;
83
+ "data-splitter-group-id": string | undefined;
84
+ "data-splitter-type": string;
85
+ "data-splitter-id": string;
86
+ "data-collapsed": boolean | undefined;
87
+ };
88
+ export interface SharedPanelResizerProps extends Partial<Pick<PanelHandle, "setSize">> {
89
+ /** If the handle is disabled */
90
+ disabled?: boolean;
91
+ /** The size of the handle */
92
+ size?: PixelUnit;
93
+ /** Called when the user starts dragging the handle */
94
+ onDragStart?: () => void;
95
+ /** Called when the user drags the handle */
96
+ onDrag?: () => void;
97
+ /** Called when the user stops dragging the handle */
98
+ onDragEnd?: () => void;
99
+ }
100
+ export declare function getPanelResizerDomAttributes({ groupId, id, orientation, isDragging, activeDragHandleId, disabled, controlsId, min, max, currentValue, groupSize, }: {
101
+ groupId: string | undefined;
102
+ id: string;
103
+ orientation: "horizontal" | "vertical";
104
+ isDragging: boolean;
105
+ activeDragHandleId: string | undefined;
106
+ disabled: boolean | undefined;
107
+ controlsId: string | undefined;
108
+ min: ParsedUnit | undefined;
109
+ max: ParsedUnit | "1fr" | undefined;
110
+ currentValue: ParsedUnit | undefined;
111
+ groupSize: number;
112
+ }): {
113
+ id: string;
114
+ role: "separator";
115
+ "data-splitter-type": string;
116
+ "data-splitter-id": string;
117
+ "data-splitter-group-id": string | undefined;
118
+ "data-handle-orientation": "horizontal" | "vertical";
119
+ "data-state": string;
120
+ "aria-label": string;
121
+ "aria-disabled": boolean | undefined;
122
+ "aria-controls": string | undefined;
123
+ "aria-valuemin": number | undefined;
124
+ "aria-valuemax": number | undefined;
125
+ "aria-valuenow": number | undefined;
126
+ };
127
+ export declare function measureGroupChildren(groupId: string, cb: (childrenSizes: Record<string, Rect>) => void): () => void;
128
+ //# sourceMappingURL=interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EAEX,wBAAwB,EACxB,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,SAAS,EACT,IAAI,EACJ,IAAI,EACL,MAAM,wBAAwB,CAAC;AAEhC,MAAM,WAAW,gBAAgB;IAC/B,0BAA0B;IAC1B,KAAK,EAAE,MAAM,MAAM,CAAC;IACpB,6DAA6D;IAC7D,aAAa,EAAE,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC;IACnC,oFAAoF;IACpF,kBAAkB,EAAE,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC;IACxC;;;;;;OAMG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IACvC,mEAAmE;IACnE,WAAW,EAAE,MAAM,MAAM,CAAC;IAC1B,QAAQ,EAAE,MAAM,MAAM,GAAG,UAAU,CAAC;CACrC;AAED,MAAM,WAAW,qBACf,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anelDomAttributes = getPanelDomAttributes;
4
+ exports.getPanelResizerDomAttributes = getPanelResizerDomAttributes;
5
+ exports.measureGroupChildren = measureGroupChildren;
6
+ const state_1 = require("@window-splitter/state");
7
+ function getPanelDomAttributes({ groupId, id, collapsible, collapsed, }) {
8
+ return {
9
+ id: id,
10
+ "data-splitter-group-id": groupId,
11
+ "data-splitter-type": "panel",
12
+ "data-splitter-id": id,
13
+ "data-collapsed": collapsible ? collapsed : undefined,
14
+ };
15
+ }
16
+ function getPanelResizerDomAttributes({ groupId, id, orientation, isDragging, activeDragHandleId, disabled, controlsId, min, max, currentValue, groupSize, }) {
17
+ return {
18
+ id: id,
19
+ role: "separator",
20
+ "data-splitter-type": "handle",
21
+ "data-splitter-id": id,
22
+ "data-splitter-group-id": groupId,
23
+ "data-handle-orientation": orientation,
24
+ "data-state": isDragging
25
+ ? "dragging"
26
+ : activeDragHandleId
27
+ ? "inactive"
28
+ : "idle",
29
+ "aria-label": "Resize Handle",
30
+ "aria-disabled": disabled,
31
+ "aria-controls": controlsId,
32
+ "aria-valuemin": min ? (0, state_1.getUnitPercentageValue)(groupSize, min) : undefined,
33
+ "aria-valuemax": max === "1fr"
34
+ ? 100
35
+ : max
36
+ ? (0, state_1.getUnitPercentageValue)(groupSize, max)
37
+ : undefined,
38
+ "aria-valuenow": currentValue
39
+ ? (0, state_1.getUnitPercentageValue)(groupSize, currentValue)
40
+ : undefined,
41
+ };
42
+ }
43
+ function measureGroupChildren(groupId, cb) {
44
+ const childrenObserver = new ResizeObserver((childrenEntries) => {
45
+ const childrenSizes = {};
46
+ for (const childEntry of childrenEntries) {
47
+ const child = childEntry.target;
48
+ const childId = child.getAttribute("data-splitter-id");
49
+ const childSize = childEntry.borderBoxSize[0];
50
+ if (childId && childSize) {
51
+ childrenSizes[childId] = {
52
+ width: childSize.inlineSize,
53
+ height: childSize.blockSize,
54
+ };
55
+ }
56
+ }
57
+ cb(childrenSizes);
58
+ });
59
+ const c = document.querySelectorAll(`[data-splitter-group-id="${groupId}"]`);
60
+ for (const child of c) {
61
+ childrenObserver.observe(child);
62
+ }
63
+ return () => {
64
+ childrenObserver.disconnect();
65
+ };
66
+ }
67
+ //# sourceMappingURL=interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interface.js","sourceRoot":"","sources":["../../src/interface.ts"],"names":[],"mappings":";;AA8FA,sDAkBC;AAgBD,oEAmDC;AAED,oDAgCC;AArND,kDAUgC;AAoFhC,SAAgB,qBAAqB,CAAC,EACpC,OAAO,EACP,EAAE,EACF,WAAW,EACX,SAAS,GAMV;IACC,OAAO;QACL,EAAE,EAAE,EAAE;QACN,wBAAwB,EAAE,OAAO;QACjC,oBAAoB,EAAE,OAAO;QAC7B,kBAAkB,EAAE,EAAE;QACtB,gBAAgB,EAAE,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;KACtD,CAAC;AACJ,CAAC;AAgBD,SAAgB,4BAA4B,CAAC,EAC3C,OAAO,EACP,EAAE,EACF,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,QAAQ,EACR,UAAU,EACV,GAAG,EACH,GAAG,EACH,YAAY,EACZ,SAAS,GAaV;IACC,OAAO;QACL,EAAE,EAAE,EAAE;QACN,IAAI,EAAE,WAAoB;QAC1B,oBAAoB,EAAE,QAAQ;QAC9B,kBAAkB,EAAE,EAAE;QACtB,wBAAwB,EAAE,OAAO;QACjC,yBAAyB,EAAE,WAAW;QACtC,YAAY,EAAE,UAAU;YACtB,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,kBAAkB;gBAClB,CAAC,CAAC,UAAU;gBACZ,CAAC,CAAC,MAAM;QACZ,YAAY,EAAE,eAAe;QAC7B,eAAe,EAAE,QAAQ;QACzB,eAAe,EAAE,UAAU;QAC3B,eAAe,EAAE,GAAG,CAAC,CAAC,CAAC,IAAA,8BAAsB,EAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS;QACzE,eAAe,EACb,GAAG,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nitPercentageValue,\n GroupMachineContextValue,\n OnResizeCallback,\n PanelData,\n ParsedUnit,\n PixelUnit,\n Rect,\n Unit,\n} from \"@window-splitter/state\";\n\nexport interface PanelGroupHandle {\n /** The id of the group */\n getId: () => string;\n /** Get the sizes of all the items in the layout as pixels */\n getPixelSizes: () => Array<number>;\n /** Get the sizes of all the items in the layout as percentages of the group size */\n getPercentageSizes: () => Array<number>;\n /**\n * Set the size of all the items in the layout.\n * This just calls `setSize` on each item. It is up to\n * you to make sure the sizes make sense.\n *\n * NOTE: Setting handle sizes will do nothing.\n */\n setSizes: (items: Array<Unit>) => void;\n /** Get the template for the group in pixels. Useful for testing */\n getTemplate: () => string;\n getState: () => \"idle\" | \"dragging\";\n}\n\nexport interface SharedPanelGroupProps\n extends Partial<\n Pick<GroupMachineContextValue, \"orientation\" | \"autosaveStrategy\">\n > {\n /** Persisted state to initialized the machine with */\n snapshot?: GroupMachineContextValue;\n /** An id to use for autosaving the layout */\n autosaveId?: string;\n}\n\nexport interface PanelHandle {\n /** Collapse the panel */\n collapse: () => void;\n /** Returns true if the panel is collapsed */\n isCollapsed: () => boolean;\n /** Expand the panel */\n expand: () => void;\n /** Returns true if the panel is expanded */\n isExpanded: () => boolean;\n /** The id of the panel */\n getId: () => string;\n /** Get the size of the panel in pixels */\n getPixelSize: () => number;\n /** Get percentage of the panel relative to the group */\n getPercentageSize: () => number;\n /**\n * Set the size of the panel in pixels.\n *\n * This will be clamped to the min/max values of the panel.\n * If you want the panel to collapse/expand you should use the\n * expand/collapse methods.\n */\n setSize: (size: Unit) => void;\n}\nexport interface SharedPanelProps<CollapsValue>\n extends Constraints<Unit>,\n Pick<PanelData, \"collapseAnimation\"> {\n /** Callback called when the panel is resized */\n onResize?: OnResizeCallback;\n /**\n * __CONTROLLED COMPONENT__\n *\n * If this prop is used it will be used as the source of truth for the collapsed state.\n * It should be used in conjunction with the `onCollapseChange` prop.\n *\n * Use this if you want full control over the collapsed state. When trying to\n * collapse a panel it will defer to onCollapseChange to determine if it should\n * be collapsed.\n */\n collapsed?: CollapsValue;\n /**\n * __CONTROLLED COMPONENT__\n *\n * A callback called with the new desired collapsed state. If paired w\n * with the `collapsed` prop this will be used to control the collapsed state.\n *\n * Otherwise this will just be called with the new collapsed state so you can\n * use it to update your own state.\n */\n onCollapseChange?: (isCollapsed: boolean) => void;\n}\n\nexport function getPanelDomAttributes({\n groupId,\n id,\n collapsible,\n collapsed,\n}: {\n groupId: string | undefined;\n id: string;\n collapsible: boolean | undefined;\n collapsed: boolean | undefined;\n}) {\n return {\n id: id,\n \"data-splitter-group-id\": groupId,\n \"data-splitter-type\": \"panel\",\n \"data-splitter-id\": id,\n \"data-collapsed\": collapsible ? collapsed : undefined,\n };\n}\n\nexport interface SharedPanelResizerProps\n extends Partial<Pick<PanelHandle, \"setSize\">> {\n /** If the handle is disabled */\n disabled?: boolean;\n /** The size of the handle */\n size?: PixelUnit;\n /** Called when the user starts dragging the handle */\n onDragStart?: () => void;\n /** Called when the user drags the handle */\n onDrag?: () => void;\n /** Called when the user stops dragging the handle */\n onDragEnd?: () => void;\n}\n\nexport function getPanelResizerDomAttributes({\n groupId,\n id,\n orientation,\n isDragging,\n activeDragHandleId,\n disabled,\n controlsId,\n min,\n max,\n currentValue,\n groupSize,\n}: {\n groupId: string | undefined;\n id: string;\n orientation: \"horizontal\" | \"vertical\";\n isDragging: boolean;\n activeDragHandleId: string | undefined;\n disabled: boolean | undefined;\n controlsId: string | undefined;\n min: ParsedUnit | undefined;\n max: ParsedUnit | \"1fr\" | undefined;\n currentValue: ParsedUnit | undefined;\n groupSize: number;\n}) {\n return {\n id: id,\n role: \"separator\" as const,\n \"data-splitter-type\": \"handle\",\n \"data-splitter-id\": id,\n \"data-splitter-group-id\": groupId,\n \"data-handle-orientation\": orientation,\n \"data-state\": isDragging\n ? \"dragging\"\n : activeDragHandleId\n ? \"inactive\"\n : \"idle\",\n \"aria-label\": \"Resize Handle\",\n \"aria-disabled\": disabled,\n \"aria-controls\": controlsId,\n \"aria-valuemin\": min ? getUnitPercentageValue(groupSize, min) : undefined,\n \"aria-valuemax\":\n max === \"1fr\"\n ? 100\n : max\n ? getUnitPercentageValue(groupSize, max)\n : undefined,\n \"aria-valuenow\": currentValue\n ? getUnitPercentageValue(groupSize, currentValue)\n : undefined,\n };\n}\n\nexport function measureGroupChildren(\n groupId: string,\n cb: (childrenSizes: Record<string, Rect>) => void\n) {\n const childrenObserver = new ResizeObserver((childrenEntries) => {\n const childrenSizes: Record<string, { width: number; height: number }> = {};\n\n for (const childEntry of childrenEntries) {\n const child = childEntry.target as HTMLElement;\n const childId = child.getAttribute(\"data-splitter-id\");\n const childSize = childEntry.borderBoxSize[0];\n\n if (childId && childSize) {\n childrenSizes[childId] = {\n width: childSize.inlineSize,\n height: childSize.blockSize,\n };\n }\n }\n\n cb(childrenSizes);\n });\n\n const c = document.querySelectorAll(`[data-splitter-group-id=\"${groupId}\"]`);\n\n for (const child of c) {\n childrenObserver.observe(child);\n }\n\n return () => {\n childrenObserver.disconnect();\n };\n}\n"]}
@@ -0,0 +1,19 @@
1
+ type Props = Record<string, any>;
2
+ type PropsArg = Props | null | undefined;
3
+ type TupleTypes<T> = {
4
+ [P in keyof T]: T[P];
5
+ } extends {
6
+ [key: number]: infer V;
7
+ } ? NullToObject<V> : never;
8
+ type NullToObject<T> = T extends null | undefined ? object : T;
9
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
10
+ /**
11
+ * Merges multiple props objects together. Event handlers are chained,
12
+ * classNames are combined, and ids are deduplicated - different ids
13
+ * will trigger a side-effect and re-render components hooked up with `useId`.
14
+ * For all other props, the last prop object overrides all previous ones.
15
+ * @param args - Multiple sets of props to merge together.
16
+ */
17
+ export declare function mergeAttributes<T extends PropsArg[]>(...args: T): UnionToIntersection<TupleTypes<T>>;
18
+ export {};
19
+ //# sourceMappingURL=mergeAttributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeAttributes.d.ts","sourceRoot":"","sources":["../../src/mergeAttributes.ts"],"names":[],"mappings":"AAwBA,KAAK,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEjC,KAAK,QAAQ,GAAG,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC;AAGzC,KAAK,UAAU,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAE,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;CAAE,GAC5E,YAAY,CAAC,CAAC,CAAC,GACf,KAAK,CAAC;AACV,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,CAAC,CAAC;AAE/D,KAAK,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,GAAG,KAAK,CAAC,SAAS,CAC7E,CAAC,EAAE,MAAM,CAAC,KACP,IAAI,GACL,CAAC,GACD,KAAK,CAAC;AAEV;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,QAAQ,EAAE,EAClD,GAAG,IAAI,EAAE,CAAC,GACT,mBAAmB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAkCpC"}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.mergeAttributes = mergeAttributes;
5
+ /*
6
+ * Copyright 2020 Adobe. All rights reserved.
7
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License. You may obtain a copy
9
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software distributed under
12
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
13
+ * OF ANY KIND, either express or implied. See the License for the specific language
14
+ * governing permissions and limitations under the License.
15
+ */
16
+ function chain(...callbacks) {
17
+ return (...args) => {
18
+ for (const callback of callbacks) {
19
+ if (typeof callback === "function") {
20
+ callback(...args);
21
+ }
22
+ }
23
+ };
24
+ }
25
+ /**
26
+ * Merges multiple props objects together. Event handlers are chained,
27
+ * classNames are combined, and ids are deduplicated - different ids
28
+ * will trigger a side-effect and re-render components hooked up with `useId`.
29
+ * For all other props, the last prop object overrides all previous ones.
30
+ * @param args - Multiple sets of props to merge together.
31
+ */
32
+ function mergeAttributes(...args) {
33
+ // Start with a base clone of the first argument. This is a lot faster than starting
34
+ // with an empty object and adding properties as we go.
35
+ const result = { ...args[0] };
36
+ for (let i = 1; i < args.length; i++) {
37
+ const props = args[i];
38
+ for (const key in props) {
39
+ const a = result[key];
40
+ const b = props[key];
41
+ // Chain events
42
+ if (typeof a === "function" &&
43
+ typeof b === "function" &&
44
+ // This is a lot faster than a regex.
45
+ key[0] === "o" &&
46
+ key[1] === "n" &&
47
+ key.charCodeAt(2) >= /* 'A' */ 65 &&
48
+ key.charCodeAt(2) <= /* 'Z' */ 90) {
49
+ result[key] = chain(a, b);
50
+ }
51
+ else if (key === "style" &&
52
+ typeof a === "object" &&
53
+ typeof b === "object") {
54
+ result[key] = { ...b, ...a };
55
+ }
56
+ else {
57
+ result[key] = b !== undefined ? b : a;
58
+ }
59
+ }
60
+ }
61
+ return result;
62
+ }
63
+ //# sourceMappingURL=mergeAttributes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeAttributes.js","sourceRoot":"","sources":["../../src/mergeAttributes.ts"],"names":[],"mappings":";AAAA,uDAAuD;;AA+CvD,0CAoCC;AAjFD;;;;;;;;;;GAUG;AAEH,SAAS,KAAK,CAAC,GAAG,SAAgB;IAChC,OAAO,CAAC,GAAG,IAAW,EAAE,EAAE;QACxB,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACj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BAAM,CAAC;gBACN,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACxC,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAA4C,CAAC;AACtD,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nfunction chain(...callbacks: any[]): (...args: any[]) => void {\n return (...args: any[]) => {\n for (const callback of callbacks) {\n if (typeof callback === \"function\") {\n callback(...args);\n }\n }\n };\n}\n\ntype Props = Record<string, any>;\n\ntype PropsArg = Props | null | undefined;\n\n// taken from: https://stackoverflow.com/questions/51603250/typescript-3-parameter-list-intersection-type/51604379#51604379\ntype TupleTypes<T> = { [P in keyof T]: T[P] } extends { [key: number]: infer V }\n ? NullToObject<V>\n : never;\ntype NullToObject<T> = T extends null | undefined ? object : T;\n\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (\n k: infer I\n) => void\n ? I\n : never;\n\n/**\n * Merges multiple props objects together. Event handlers are chained,\n * classNames are combined, and ids are deduplicated - different ids\n * will trigger a side-effect and re-render components hooked up with `useId`.\n * For all other props, the last prop object overrides all previous ones.\n * @param args - Multiple sets of props to merge together.\n */\nexport function mergeAttributes<T extends PropsArg[]>(\n ...args: T\n): UnionToIntersection<TupleTypes<T>> {\n // Start with a base clone of the first argument. This is a lot faster than starting\n // with an empty object and adding properties as we go.\n const result: Props = { ...args[0] };\n for (let i = 1; i < args.length; i++) {\n const props = args[i];\n for (const key in props) {\n const a = result[key];\n const b = props[key];\n\n // Chain events\n if (\n typeof a === \"function\" &&\n typeof b === \"function\" &&\n // This is a lot faster than a regex.\n key[0] === \"o\" &&\n key[1] === \"n\" &&\n key.charCodeAt(2) >= /* 'A' */ 65 &&\n key.charCodeAt(2) <= /* 'Z' */ 90\n ) {\n result[key] = chain(a, b);\n } else if (\n key === \"style\" &&\n typeof a === \"object\" &&\n typeof b === \"object\"\n ) {\n result[key] = { ...b, ...a };\n } else {\n result[key] = b !== undefined ? b : a;\n }\n }\n }\n\n return result as UnionToIntersection<TupleTypes<T>>;\n}\n"]}
@@ -0,0 +1,52 @@
1
+ export interface MoveResult {
2
+ /** Props to spread on the target element. */
3
+ moveProps: {
4
+ onPointerDown: (e: PointerEvent) => void;
5
+ onKeyDown: (e: KeyboardEvent) => void;
6
+ };
7
+ }
8
+ type PointerType = "mouse" | "pen" | "touch" | "keyboard" | "virtual";
9
+ interface BaseMoveEvent {
10
+ /** The pointer type that triggered the move event. */
11
+ pointerType: PointerType;
12
+ /** Whether the shift keyboard modifier was held during the move event. */
13
+ shiftKey: boolean;
14
+ /** Whether the ctrl keyboard modifier was held during the move event. */
15
+ ctrlKey: boolean;
16
+ /** Whether the meta keyboard modifier was held during the move event. */
17
+ metaKey: boolean;
18
+ /** Whether the alt keyboard modifier was held during the move event. */
19
+ altKey: boolean;
20
+ }
21
+ interface MoveStartEvent extends BaseMoveEvent {
22
+ /** The type of move event being fired. */
23
+ type: "movestart";
24
+ }
25
+ interface MoveMoveEvent extends BaseMoveEvent {
26
+ /** The type of move event being fired. */
27
+ type: "move";
28
+ /** The amount moved in the X direction since the last event. */
29
+ deltaX: number;
30
+ /** The amount moved in the Y direction since the last event. */
31
+ deltaY: number;
32
+ }
33
+ interface MoveEndEvent extends BaseMoveEvent {
34
+ /** The type of move event being fired. */
35
+ type: "moveend";
36
+ }
37
+ export interface MoveEvents {
38
+ /** Handler that is called when a move interaction starts. */
39
+ onMoveStart?: (e: MoveStartEvent) => void;
40
+ /** Handler that is called when the element is moved. */
41
+ onMove?: (e: MoveMoveEvent) => void;
42
+ /** Handler that is called when a move interaction ends. */
43
+ onMoveEnd?: (e: MoveEndEvent) => void;
44
+ }
45
+ /**
46
+ * Handles move interactions across mouse, touch, and keyboard, including dragging with
47
+ * the mouse or touch, and using the arrow keys. Normalizes behavior across browsers and
48
+ * platforms, and ignores emulated mouse events on touch devices.
49
+ */
50
+ export declare function move(props: MoveEvents): MoveResult;
51
+ export {};
52
+ //# sourceMappingURL=move.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"move.d.ts","sourceRoot":"","sources":["../../src/move.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACzB,6CAA6C;IAC7C,SAAS,EAAE;QACT,aAAa,EAAE,CAAC,CAAC,EAAE,YAAY,KAAK,IAAI,CAAC;QACzC,SAAS,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;KACvC,CAAC;CACH;AASD,KAAK,WAAW,GAAG,OAAO,GAAG,KAAK,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,CAAC;AAEtE,UAAU,aAAa;IACrB,sDAAsD;IACtD,WAAW,EAAE,WAAW,CAAC;IACzB,0EAA0E;IAC1E,QAAQ,EAAE,OAAO,CAAC;IAClB,yEAAyE;IACzE,OAAO,EAAE,OAAO,CAAC;IACjB,yEAAyE;IACzE,OAAO,EAAE,OAAO,CAAC;IACjB,wEAAwE;IACxE,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,UAAU,cAAe,SAAQ,aAAa;IAC5C,0CAA0C;IAC1C,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,UAAU,aAAc,SAAQ,aAAa;IAC3C,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,MAAM,EAAE,MAAM,CAAC;IACf,gEAAgE;IAChE,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,YAAa,SAAQ,aAAa;IAC1C,0CAA0C;IAC1C,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,6DAA6D;IAC7D,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,IAAI,CAAC;IAC1C,wDAAwD;IACxD,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IACpC,2DAA2D;IAC3D,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,YAAY,KAAK,IAAI,CAAC;CACvC;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAgJlD"}
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ // import {disableTextSelection, restoreTextSelection} from './textSelection';
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.move = move;
5
+ /**
6
+ * Handles move interactions across mouse, touch, and keyboard, including dragging with
7
+ * the mouse or touch, and using the arrow keys. Normalizes behavior across browsers and
8
+ * platforms, and ignores emulated mouse events on touch devices.
9
+ */
10
+ function move(props) {
11
+ const { onMoveStart, onMove: onMoveProp, onMoveEnd } = props;
12
+ const state = { didMove: false, lastPosition: null, id: null };
13
+ const onMove = (originalEvent, pointerType, deltaX, deltaY) => {
14
+ if (deltaX === 0 && deltaY === 0) {
15
+ return;
16
+ }
17
+ if (!state.didMove) {
18
+ state.didMove = true;
19
+ onMoveStart?.({
20
+ type: "movestart",
21
+ pointerType,
22
+ shiftKey: originalEvent.shiftKey,
23
+ metaKey: originalEvent.metaKey,
24
+ ctrlKey: originalEvent.ctrlKey,
25
+ altKey: originalEvent.altKey,
26
+ });
27
+ }
28
+ onMoveProp?.({
29
+ type: "move",
30
+ pointerType,
31
+ deltaX: deltaX,
32
+ deltaY: deltaY,
33
+ shiftKey: originalEvent.shiftKey,
34
+ metaKey: originalEvent.metaKey,
35
+ ctrlKey: originalEvent.ctrlKey,
36
+ altKey: originalEvent.altKey,
37
+ });
38
+ };
39
+ const end = (originalEvent, pointerType) => {
40
+ // restoreTextSelection();
41
+ if (state.didMove) {
42
+ onMoveEnd?.({
43
+ type: "moveend",
44
+ pointerType,
45
+ shiftKey: originalEvent.shiftKey,
46
+ metaKey: originalEvent.metaKey,
47
+ ctrlKey: originalEvent.ctrlKey,
48
+ altKey: originalEvent.altKey,
49
+ });
50
+ }
51
+ };
52
+ const moveProps = {};
53
+ const start = () => {
54
+ // disableTextSelection();
55
+ state.didMove = false;
56
+ };
57
+ const onPointerMove = (e) => {
58
+ if (e.pointerId === state.id) {
59
+ const pointerType = (e.pointerType || "mouse");
60
+ // Problems with PointerEvent#movementX/movementY:
61
+ // 1. it is always 0 on macOS Safari.
62
+ // 2. On Chrome Android, it's scaled by devicePixelRatio, but not on Chrome macOS
63
+ onMove(e, pointerType, e.pageX - (state.lastPosition?.pageX ?? 0), e.pageY - (state.lastPosition?.pageY ?? 0));
64
+ state.lastPosition = { pageX: e.pageX, pageY: e.pageY };
65
+ }
66
+ };
67
+ const onPointerUp = (e) => {
68
+ if (e.pointerId === state.id) {
69
+ const pointerType = (e.pointerType || "mouse");
70
+ end(e, pointerType);
71
+ state.id = null;
72
+ window.removeEventListener("pointermove", onPointerMove, false);
73
+ window.removeEventListener("pointerup", onPointerUp, false);
74
+ window.removeEventListener("pointercancel", onPointerUp, false);
75
+ }
76
+ };
77
+ moveProps.onPointerDown = (e) => {
78
+ if (e.button === 0 && state.id == null) {
79
+ start();
80
+ e.stopPropagation();
81
+ e.preventDefault();
82
+ state.lastPosition = { pageX: e.pageX, pageY: e.pageY };
83
+ state.id = e.pointerId;
84
+ window.addEventListener("pointermove", onPointerMove, false);
85
+ window.addEventListener("pointerup", onPointerUp, false);
86
+ window.addEventListener("pointercancel", onPointerUp, false);
87
+ }
88
+ };
89
+ const triggerKeyboardMove = (e, deltaX, deltaY) => {
90
+ start();
91
+ onMove(e, "keyboard", deltaX, deltaY);
92
+ end(e, "keyboard");
93
+ };
94
+ moveProps.onKeyDown = (e) => {
95
+ switch (e.key) {
96
+ case "Left":
97
+ case "ArrowLeft":
98
+ e.preventDefault();
99
+ e.stopPropagation();
100
+ triggerKeyboardMove(e, -1, 0);
101
+ break;
102
+ case "Right":
103
+ case "ArrowRight":
104
+ e.preventDefault();
105
+ e.stopPropagation();
106
+ triggerKeyboardMove(e, 1, 0);
107
+ break;
108
+ case "Up":
109
+ case "ArrowUp":
110
+ e.preventDefault();
111
+ e.stopPropagation();
112
+ triggerKeyboardMove(e, 0, -1);
113
+ break;
114
+ case "Down":
115
+ case "ArrowDown":
116
+ e.preventDefault();
117
+ e.stopPropagation();
118
+ triggerKeyboardMove(e, 0, 1);
119
+ break;
120
+ }
121
+ };
122
+ return { moveProps: moveProps };
123
+ }
124
+ //# sourceMappingURL=move.js.map