@prosekit/lit 0.1.7 → 0.1.8

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.
@@ -229,6 +229,11 @@ export declare const blockComponentStyles: CSSResult;
229
229
  */
230
230
  export declare const boundary: HTMLElement | undefined;
231
231
 
232
+ export declare function calcResize(position: 'top' | 'right' | 'bottom' | 'left' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right', w: number, h: number, dx: number, dy: number, aspectRatio: number | null | undefined): [w: number, h: number];
233
+
234
+ /**
235
+ * @internal
236
+ */
232
237
  export declare class ComboBox extends Popover {
233
238
  /**
234
239
  * @hidden
@@ -284,6 +289,9 @@ export declare const comboBoxContext: {
284
289
  __context__: ComboBoxContext;
285
290
  };
286
291
 
292
+ /**
293
+ * @internal
294
+ */
287
295
  export declare class ComboBoxInput extends LightElement {
288
296
  /**
289
297
  * @hidden
@@ -308,10 +316,16 @@ export declare class ComboBoxInput extends LightElement {
308
316
  render(): TemplateResult<1>;
309
317
  }
310
318
 
319
+ /**
320
+ * @internal
321
+ */
311
322
  export declare interface ComboBoxInputProps {
312
323
  placeholder?: string;
313
324
  }
314
325
 
326
+ /**
327
+ * @internal
328
+ */
315
329
  declare class ComboBoxItem extends LightElement {
316
330
  /**
317
331
  * @hidden
@@ -341,12 +355,18 @@ declare class ComboBoxItem extends LightElement {
341
355
  export { ComboBoxItem }
342
356
  export { ComboBoxItem as ComboBoxItem_alias_1 }
343
357
 
358
+ /**
359
+ * @internal
360
+ */
344
361
  declare type ComboBoxItemProps = {
345
362
  onSelect?: VoidFunction;
346
363
  };
347
364
  export { ComboBoxItemProps }
348
365
  export { ComboBoxItemProps as ComboBoxItemProps_alias_1 }
349
366
 
367
+ /**
368
+ * @internal
369
+ */
350
370
  declare class ComboBoxList extends LightElement {
351
371
  private comboBoxContext;
352
372
  connectedCallback(): void;
@@ -354,12 +374,18 @@ declare class ComboBoxList extends LightElement {
354
374
  export { ComboBoxList }
355
375
  export { ComboBoxList as ComboBoxList_alias_1 }
356
376
 
377
+ /**
378
+ * @internal
379
+ */
357
380
  declare type ComboBoxListProps = {
358
381
  lang?: string;
359
382
  };
360
383
  export { ComboBoxListProps }
361
384
  export { ComboBoxListProps as ComboBoxListProps_alias_1 }
362
385
 
386
+ /**
387
+ * @internal
388
+ */
363
389
  export declare interface ComboBoxProps extends PopoverProps {
364
390
  onDismiss?: VoidFunction;
365
391
  }
@@ -474,6 +500,8 @@ export declare function isComboBoxItem(element?: Element | null): element is Com
474
500
 
475
501
  export declare function isComboBoxList(element?: Element | null): element is ComboBoxList;
476
502
 
503
+ export declare function isFinitePositiveNumber(value: unknown): value is number;
504
+
477
505
  export declare function isInCodeBlock(selection: Selection_2): boolean | undefined;
478
506
 
479
507
  export declare class LightElement extends LitElement {
@@ -669,6 +697,9 @@ export declare interface PopoverProps {
669
697
  autoUpdateOptions?: AutoUpdateOptions;
670
698
  }
671
699
 
700
+ /**
701
+ * @internal
702
+ */
672
703
  export declare const propNames: readonly [];
673
704
 
674
705
  declare const propNames_2: readonly ["value", "onSelect"];
@@ -679,28 +710,195 @@ declare const propNames_3: readonly ["editor"];
679
710
  export { propNames_3 as propNames_alias_3 }
680
711
  export { propNames_3 as propNames_alias_4 }
681
712
 
713
+ /**
714
+ * @internal
715
+ */
682
716
  declare const propNames_4: readonly ["onSelect"];
683
717
  export { propNames_4 as propNames_alias_8 }
684
718
  export { propNames_4 as propNames_alias_9 }
685
719
 
720
+ /**
721
+ * @internal
722
+ */
686
723
  declare const propNames_5: never[];
687
724
  export { propNames_5 as propNames_alias_10 }
688
725
  export { propNames_5 as propNames_alias_11 }
689
726
 
727
+ /**
728
+ * @internal
729
+ */
730
+ declare const propNames_6: readonly ["width", "height", "aspectRatio", "onSizeChangeStart", "onSizeChange", "onSizeChangeEnd"];
731
+ export { propNames_6 as propNames_alias_14 }
732
+ export { propNames_6 as propNames_alias_15 }
733
+
734
+ /**
735
+ * @internal
736
+ */
737
+ declare const propNames_7: readonly [];
738
+ export { propNames_7 as propNames_alias_16 }
739
+ export { propNames_7 as propNames_alias_17 }
740
+
690
741
  export declare const propNames_alias_12: readonly ["editor", "popoverOptions"];
691
742
 
692
743
  export declare const propNames_alias_13: readonly ["active", "reference", "options", "autoUpdate", "autoUpdateOptions"];
693
744
 
694
745
  export declare const propNames_alias_5: readonly ["editor", "regex", "popoverOptions"];
695
746
 
747
+ /**
748
+ * @internal
749
+ */
696
750
  export declare const propNames_alias_6: readonly ["onDismiss"];
697
751
 
752
+ /**
753
+ * @internal
754
+ */
698
755
  export declare const propNames_alias_7: readonly ["placeholder"];
699
756
 
700
757
  export declare function queryClosestAutocompleteItem(element?: Element | null): AutocompleteItem | null;
701
758
 
702
759
  export declare function queryClosestComboBoxItem(element?: Element | null): ComboBoxItem | null;
703
760
 
761
+ /**
762
+ * @public
763
+ */
764
+ declare class Resizable extends LightElement implements Partial<ResizableProps> {
765
+ /**
766
+ * @hidden
767
+ */
768
+ static properties: {
769
+ width: {
770
+ attribute: false;
771
+ };
772
+ height: {
773
+ attribute: false;
774
+ };
775
+ aspectRatio: {
776
+ attribute: false;
777
+ };
778
+ onResize: {
779
+ attribute: false;
780
+ };
781
+ onResizeEnd: {
782
+ attribute: false;
783
+ };
784
+ resizing: {
785
+ attribute: string;
786
+ type: BooleanConstructor;
787
+ reflect: true;
788
+ };
789
+ };
790
+ width?: number | string;
791
+ height?: number | string;
792
+ aspectRatio?: number;
793
+ resizing?: boolean;
794
+ onSizeChangeStart?: (size: {
795
+ width: number;
796
+ height: number;
797
+ }) => void;
798
+ onSizeChange?: (size: {
799
+ width: number;
800
+ height: number;
801
+ }) => void | {
802
+ width?: number | string;
803
+ height?: number | string;
804
+ };
805
+ onSizeChangeEnd?: (size: {
806
+ width: number;
807
+ height: number;
808
+ }) => void;
809
+ private context;
810
+ private startWidth;
811
+ private startHeight;
812
+ private handleResizeStart;
813
+ private handleResize;
814
+ private handleResizeEnd;
815
+ private updateStyle;
816
+ /**
817
+ * @hidden
818
+ */
819
+ connectedCallback(): void;
820
+ /**
821
+ * @hidden
822
+ */
823
+ protected updated(changedProperties: PropertyValues<this>): void;
824
+ }
825
+ export { Resizable }
826
+ export { Resizable as Resizable_alias_1 }
827
+
828
+ /**
829
+ * @internal
830
+ */
831
+ export declare interface ResizableContext {
832
+ onResizeStart: () => readonly [
833
+ width: number,
834
+ height: number,
835
+ aspectRatio: number
836
+ ];
837
+ onResize: (width: number, height: number) => void;
838
+ onResizeEnd: () => void;
839
+ }
840
+
841
+ /**
842
+ * @internal
843
+ */
844
+ export declare const resizableContext: {
845
+ __context__: ResizableContext;
846
+ };
847
+
848
+ /**
849
+ * @public
850
+ */
851
+ declare class ResizableHandle extends LightElement implements Partial<ResizableHandleProps> {
852
+ private context;
853
+ /**
854
+ * @hidden
855
+ */
856
+ static properties: {
857
+ position: {
858
+ attribute: false;
859
+ };
860
+ };
861
+ position?: ResizableHandleProps['position'];
862
+ connectedCallback(): void;
863
+ }
864
+ export { ResizableHandle }
865
+ export { ResizableHandle as ResizableHandle_alias_1 }
866
+
867
+ /**
868
+ * @internal
869
+ */
870
+ declare type ResizableHandleProps = {
871
+ position: 'top' | 'right' | 'bottom' | 'left' | 'top-left' | 'top-right' | 'bottom-right' | 'bottom-left';
872
+ };
873
+ export { ResizableHandleProps }
874
+ export { ResizableHandleProps as ResizableHandleProps_alias_1 }
875
+
876
+ /**
877
+ * @public
878
+ */
879
+ declare interface ResizableProps {
880
+ width?: string | number;
881
+ height?: string | number;
882
+ aspectRatio?: number;
883
+ onSizeChangeStart?: (size: {
884
+ width: number;
885
+ height: number;
886
+ }) => void;
887
+ onSizeChange?: (size: {
888
+ width: number;
889
+ height: number;
890
+ }) => void | {
891
+ width?: number | string;
892
+ height?: number | string;
893
+ };
894
+ onSizeChangeEnd?: (size: {
895
+ width: number;
896
+ height: number;
897
+ }) => void;
898
+ }
899
+ export { ResizableProps }
900
+ export { ResizableProps as ResizableProps_alias_1 }
901
+
704
902
  /** Rounds a value to the nearest device pixel ratio. */
705
903
  export declare function roundByDPR(value: number): number;
706
904
 
@@ -0,0 +1,9 @@
1
+ // src/components/resizable/context.ts
2
+ import { createContext } from "@lit/context";
3
+ var resizableContext = createContext(
4
+ "prosekit-resizable-context"
5
+ );
6
+
7
+ export {
8
+ resizableContext
9
+ };
@@ -0,0 +1,3 @@
1
+ export { ResizableHandle_alias_1 as ResizableHandle } from './_tsup-dts-rollup';
2
+ export { ResizableHandleProps_alias_1 as ResizableHandleProps } from './_tsup-dts-rollup';
3
+ export { propNames_alias_17 as propNames } from './_tsup-dts-rollup';
@@ -0,0 +1,159 @@
1
+ import {
2
+ resizableContext
3
+ } from "./chunk-WEUGKLVB.js";
4
+ import {
5
+ LightElement,
6
+ defineCustomElement
7
+ } from "./chunk-S32IZIQF.js";
8
+
9
+ // src/components/resizable-handle/component.ts
10
+ import { ContextConsumer } from "@lit/context";
11
+
12
+ // src/utils/is-finite-positive-number.ts
13
+ function isFinitePositiveNumber(value) {
14
+ return typeof value === "number" && Number.isFinite(value) && value > 0;
15
+ }
16
+
17
+ // src/components/resizable-handle/calc-resize.ts
18
+ function calcResize(position, w, h, dx, dy, aspectRatio) {
19
+ aspectRatio = aspectRatio ? aspectRatio : w / h;
20
+ aspectRatio = isFinitePositiveNumber(aspectRatio) ? aspectRatio : 1;
21
+ switch (position) {
22
+ case "bottom-right":
23
+ return calcBottomRightResize(w, h, dx, dy, aspectRatio);
24
+ case "bottom-left":
25
+ return calcBottomLeftResize(w, h, dx, dy, aspectRatio);
26
+ case "top-right":
27
+ return calcTopRightResize(w, h, dx, dy, aspectRatio);
28
+ case "top-left":
29
+ return calcTopLeftResize(w, h, dx, dy, aspectRatio);
30
+ case "top":
31
+ return calcTopResize(w, h, dx, dy, aspectRatio);
32
+ case "right":
33
+ return calcRightResize(w, h, dx, dy, aspectRatio);
34
+ case "bottom":
35
+ return calcBottomResize(w, h, dx, dy, aspectRatio);
36
+ case "left":
37
+ return calcLeftResize(w, h, dx, dy, aspectRatio);
38
+ default:
39
+ throw new RangeError(`Invalid position: ${position}`);
40
+ }
41
+ }
42
+ var calcBottomRightResize = (w, h, dx, dy, r) => {
43
+ w += dx;
44
+ h += dy;
45
+ const sum = w + h;
46
+ h = sum / (r + 1);
47
+ w = sum - h;
48
+ return [w, h];
49
+ };
50
+ var calcBottomLeftResize = (w, h, dx, dy, r) => {
51
+ w -= dx;
52
+ h += dy;
53
+ const sum = w + h;
54
+ h = sum / (r + 1);
55
+ w = sum - h;
56
+ return [w, h];
57
+ };
58
+ var calcTopRightResize = (w, h, dx, dy, r) => {
59
+ w += dx;
60
+ h -= dy;
61
+ const sum = w + h;
62
+ h = sum / (r + 1);
63
+ w = sum - h;
64
+ return [w, h];
65
+ };
66
+ var calcTopLeftResize = (w, h, dx, dy, r) => {
67
+ w -= dx;
68
+ h -= dy;
69
+ const sum = w + h;
70
+ h = sum / (r + 1);
71
+ w = sum - h;
72
+ return [w, h];
73
+ };
74
+ var calcTopResize = (w, h, dx, dy, r) => {
75
+ h -= dy;
76
+ w = h * r;
77
+ return [w, h];
78
+ };
79
+ var calcRightResize = (w, h, dx, dy, r) => {
80
+ w += dx;
81
+ h = w / r;
82
+ return [w, h];
83
+ };
84
+ var calcBottomResize = (w, h, dx, dy, r) => {
85
+ h += dy;
86
+ w = h * r;
87
+ return [w, h];
88
+ };
89
+ var calcLeftResize = (w, h, dx, dy, r) => {
90
+ w -= dx;
91
+ h = w / r;
92
+ return [w, h];
93
+ };
94
+
95
+ // src/components/resizable-handle/component.ts
96
+ var propNames = [];
97
+ var ResizableHandle = class extends LightElement {
98
+ constructor() {
99
+ super(...arguments);
100
+ this.context = new ContextConsumer(this, {
101
+ context: resizableContext
102
+ });
103
+ }
104
+ connectedCallback() {
105
+ super.connectedCallback();
106
+ let startX = 0;
107
+ let startY = 0;
108
+ let width = 0;
109
+ let height = 0;
110
+ let aspectRatio = 1;
111
+ const handlePointerMove = (event) => {
112
+ var _a;
113
+ event.preventDefault();
114
+ const dx = event.x - startX;
115
+ const dy = event.y - startY;
116
+ const [w, h] = calcResize(
117
+ this.position || "bottom-right",
118
+ width,
119
+ height,
120
+ dx,
121
+ dy,
122
+ aspectRatio
123
+ );
124
+ (_a = this.context.value) == null ? void 0 : _a.onResize(w, h);
125
+ };
126
+ const handlePointerDown = (event) => {
127
+ var _a;
128
+ event.preventDefault();
129
+ startX = event.x;
130
+ startY = event.y;
131
+ const size = (_a = this.context.value) == null ? void 0 : _a.onResizeStart();
132
+ if (size) {
133
+ ;
134
+ [width, height, aspectRatio] = size;
135
+ }
136
+ this.ownerDocument.addEventListener("pointermove", handlePointerMove);
137
+ this.ownerDocument.addEventListener("pointerup", handlePointerUp);
138
+ };
139
+ const handlePointerUp = (event) => {
140
+ var _a;
141
+ event.preventDefault();
142
+ (_a = this.context.value) == null ? void 0 : _a.onResizeEnd();
143
+ this.ownerDocument.removeEventListener("pointermove", handlePointerMove);
144
+ this.ownerDocument.removeEventListener("pointerup", handlePointerUp);
145
+ };
146
+ this.addEventListener("pointerdown", handlePointerDown);
147
+ }
148
+ };
149
+ /**
150
+ * @hidden
151
+ */
152
+ ResizableHandle.properties = {
153
+ position: { attribute: false }
154
+ };
155
+ defineCustomElement("prosekit-resizable-handle", ResizableHandle);
156
+ export {
157
+ ResizableHandle,
158
+ propNames
159
+ };
@@ -0,0 +1,3 @@
1
+ export { Resizable_alias_1 as Resizable } from './_tsup-dts-rollup';
2
+ export { propNames_alias_15 as propNames } from './_tsup-dts-rollup';
3
+ export { ResizableProps_alias_1 as ResizableProps } from './_tsup-dts-rollup';
@@ -0,0 +1,107 @@
1
+ import {
2
+ resizableContext
3
+ } from "./chunk-WEUGKLVB.js";
4
+ import {
5
+ LightElement,
6
+ defineCustomElement
7
+ } from "./chunk-S32IZIQF.js";
8
+
9
+ // src/components/resizable/component.ts
10
+ import { ContextProvider } from "@lit/context";
11
+ var propNames = [
12
+ "width",
13
+ "height",
14
+ "aspectRatio",
15
+ "onSizeChangeStart",
16
+ "onSizeChange",
17
+ "onSizeChangeEnd"
18
+ ];
19
+ var Resizable = class extends LightElement {
20
+ constructor() {
21
+ super(...arguments);
22
+ this.context = new ContextProvider(this, {
23
+ context: resizableContext,
24
+ initialValue: {
25
+ onResizeStart: () => this.handleResizeStart(),
26
+ onResize: (w, h) => this.handleResize(w, h),
27
+ onResizeEnd: () => this.handleResizeEnd()
28
+ }
29
+ });
30
+ this.startWidth = 0;
31
+ this.startHeight = 0;
32
+ }
33
+ handleResizeStart() {
34
+ var _a, _b;
35
+ const { width, height } = this.getBoundingClientRect();
36
+ this.startWidth = width;
37
+ this.startHeight = height;
38
+ (_a = this.onSizeChangeStart) == null ? void 0 : _a.call(this, { width, height });
39
+ this.resizing = true;
40
+ return [width, height, (_b = this.aspectRatio) != null ? _b : width / height];
41
+ }
42
+ handleResize(width, height) {
43
+ var _a, _b, _c;
44
+ const output = (_a = this.onSizeChange) == null ? void 0 : _a.call(this, { width, height });
45
+ this.width = (_b = output == null ? void 0 : output.width) != null ? _b : width;
46
+ this.height = (_c = output == null ? void 0 : output.height) != null ? _c : height;
47
+ }
48
+ handleResizeEnd() {
49
+ var _a;
50
+ const { width, height } = this.getBoundingClientRect();
51
+ this.resizing = false;
52
+ (_a = this.onSizeChangeEnd) == null ? void 0 : _a.call(this, { width, height });
53
+ }
54
+ updateStyle() {
55
+ const w = this.width;
56
+ const h = this.height;
57
+ const r = this.aspectRatio;
58
+ if (w != null && w !== "" && Number.isFinite(w)) {
59
+ this.style.width = typeof w === "number" ? `${w}px` : w;
60
+ } else {
61
+ this.style.width = "";
62
+ }
63
+ if (h != null && h !== "" && Number.isFinite(h)) {
64
+ this.style.height = typeof h === "number" ? `${h}px` : h;
65
+ } else {
66
+ this.style.height = "";
67
+ }
68
+ if (r && Number.isFinite(r)) {
69
+ this.style.aspectRatio = `${r}`;
70
+ if (this.style.width && this.startWidth >= this.startHeight && r >= 1) {
71
+ this.style.height = "auto";
72
+ } else if (this.style.height && this.startWidth <= this.startHeight && r <= 1) {
73
+ this.style.width = "auto";
74
+ }
75
+ }
76
+ }
77
+ /**
78
+ * @hidden
79
+ */
80
+ connectedCallback() {
81
+ super.connectedCallback();
82
+ this.updateStyle();
83
+ }
84
+ /**
85
+ * @hidden
86
+ */
87
+ updated(changedProperties) {
88
+ super.updated(changedProperties);
89
+ this.updateStyle();
90
+ }
91
+ };
92
+ /**
93
+ * @hidden
94
+ */
95
+ Resizable.properties = {
96
+ width: { attribute: false },
97
+ height: { attribute: false },
98
+ aspectRatio: { attribute: false },
99
+ onResize: { attribute: false },
100
+ onResizeEnd: { attribute: false },
101
+ resizing: { attribute: "data-resizing", type: Boolean, reflect: true }
102
+ };
103
+ defineCustomElement("prosekit-resizable", Resizable);
104
+ export {
105
+ Resizable,
106
+ propNames
107
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/lit",
3
3
  "type": "module",
4
- "version": "0.1.7",
4
+ "version": "0.1.8",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -79,16 +79,26 @@
79
79
  "types": "./dist/prosekit-lit-popover.d.ts",
80
80
  "import": "./dist/prosekit-lit-popover.js",
81
81
  "default": "./dist/prosekit-lit-popover.js"
82
+ },
83
+ "./resizable": {
84
+ "types": "./dist/prosekit-lit-resizable.d.ts",
85
+ "import": "./dist/prosekit-lit-resizable.js",
86
+ "default": "./dist/prosekit-lit-resizable.js"
87
+ },
88
+ "./resizable-handle": {
89
+ "types": "./dist/prosekit-lit-resizable-handle.d.ts",
90
+ "import": "./dist/prosekit-lit-resizable-handle.js",
91
+ "default": "./dist/prosekit-lit-resizable-handle.js"
82
92
  }
83
93
  },
84
94
  "files": [
85
95
  "dist"
86
96
  ],
87
97
  "dependencies": {
88
- "@floating-ui/dom": "^1.5.3",
98
+ "@floating-ui/dom": "^1.5.4",
89
99
  "@lit/context": "^1.1.0",
90
100
  "@prosekit/core": "^0.2.2",
91
- "@prosekit/extensions": "^0.2.1",
101
+ "@prosekit/extensions": "^0.2.2",
92
102
  "@prosekit/pm": "^0.1.1",
93
103
  "@superhuman/command-score": "^0.5.0",
94
104
  "lit": "^3.1.0"
@@ -98,7 +108,7 @@
98
108
  "minify-literals": "^1.0.8",
99
109
  "tsup": "^8.0.1",
100
110
  "typescript": "^5.3.3",
101
- "vitest": "^1.1.1"
111
+ "vitest": "^1.1.3"
102
112
  },
103
113
  "scripts": {
104
114
  "build:tsup": "tsup",
@@ -139,6 +149,12 @@
139
149
  ],
140
150
  "popover": [
141
151
  "./dist/prosekit-lit-popover.d.ts"
152
+ ],
153
+ "resizable": [
154
+ "./dist/prosekit-lit-resizable.d.ts"
155
+ ],
156
+ "resizable-handle": [
157
+ "./dist/prosekit-lit-resizable-handle.d.ts"
142
158
  ]
143
159
  }
144
160
  }