@cocreate/position 1.16.0 → 2.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.
package/CONTRIBUTING.md CHANGED
@@ -1,19 +1,19 @@
1
1
  # Contributing to CoCreate-position
2
2
 
3
- This project is work of [many contributors](https://github.com/CoCreate-app/CoCreate-position/graphs/contributors).
4
- You're encouraged to submit [pull requests](https://github.com/CoCreate-app/CoCreate-position/pulls),
5
- [propose features and discuss issues](https://github.com/CoCreate-app/CoCreate-position/issues).
3
+ This project is work of [many contributors](https://github.com/CoCreateJS/position/graphs/contributors).
4
+ You're encouraged to submit [pull requests](https://github.com/CoCreateJS/position/pulls),
5
+ [propose features and discuss issues](https://github.com/CoCreateJS/position/issues).
6
6
 
7
7
  In the examples below, substitute your Github username for `contributor` in URLs.
8
8
 
9
9
  ## Fork the Project
10
10
 
11
- Fork the [project on Github](https://github.com/CoCreate-app/CoCreate-position) and check out your copy.
11
+ Fork the [project on Github](https://github.com/CoCreateJS/position) and check out your copy.
12
12
 
13
13
  ```
14
14
  git position https://github.com/contributor/CoCreate-position.git
15
15
  cd CoCreate-position
16
- git remote add upstream https://gitlab.com/cocreatejs/CoCreate-position.git
16
+ git remote add upstream https://github.com/CoCreateJS/position.git
17
17
  ```
18
18
 
19
19
  ## Create a Topic Branch
@@ -75,7 +75,7 @@ git push origin my-feature-branch
75
75
 
76
76
  ## Make a Pull Request
77
77
 
78
- Go to [https://github.com/CoCreate-app/CoCreate-position](https://github.com/CoCreate-app/CoCreate-position) and select your feature branch.
78
+ Go to [https://github.com/CoCreateJS/position](https://github.com/CoCreateJS/position) and select your feature branch.
79
79
  Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.
80
80
 
81
81
  ## Rebase
package/README.md CHANGED
@@ -1,85 +1,210 @@
1
- # CoCreate-position
2
-
3
- Make any element draggable and movable. Customizable via HTML5 attributes or Javascript, great for creating moveable popups, alerts, etc. Take it for a spin in our [playground!](https://cocreate.app/docs/position)
4
-
5
- ![minified](https://img.badgesize.io/https://cdn.cocreate.app/position/latest/CoCreate-position.min.js?style=flat-square&label=minified&color=orange)
6
- ![gzip](https://img.badgesize.io/https://cdn.cocreate.app/position/latest/CoCreate-position.min.js?compression=gzip&style=flat-square&label=gzip&color=yellow)
7
- ![brotli](https://img.badgesize.io/https://cdn.cocreate.app/position/latest/CoCreate-position.min.js?compression=brotli&style=flat-square&label=brotli)
8
- ![GitHub latest release](https://img.shields.io/github/v/release/CoCreate-app/CoCreate-position?style=flat-square)
9
- ![License](https://img.shields.io/github/license/CoCreate-app/CoCreate-position?style=flat-square)
10
- ![Hiring](https://img.shields.io/static/v1?style=flat-square&label=&message=Hiring&color=blueviolet)
11
-
12
- ![CoCreate-position](https://cdn.cocreate.app/docs/CoCreate-position.gif)
13
-
14
- ## [Docs & Demo](https://cocreate.app/docs/position)
15
-
16
- For a complete guide and working demo refer to the [doumentation](https://cocreate.app/docs/position)
17
-
18
- ## CDN
19
-
20
- ```html
21
- <script src="https://cdn.cocreate.app/position/latest/CoCreate-position.min.js"></script>
22
- ```
23
-
24
- ```html
25
- <script src="https://cdn.cocreate.app/position/latest/CoCreate-position.min.css"></script>
26
- ```
27
-
28
- ## NPM
29
-
30
- ```shell
31
- $ npm i @cocreate/position
32
- ```
33
-
34
- ## yarn
35
-
36
- ```shell
37
- $ yarn install @cocreate/position
38
- ```
39
-
40
- # Table of Contents
41
-
42
- - [Table of Contents](#table-of-contents)
43
- - [Announcements](#announcements)
44
- - [Roadmap](#roadmap)
45
- - [How to Contribute](#how-to-contribute)
46
- - [About](#about)
47
- - [License](#license)
48
-
49
- <a name="announcements"></a>
50
-
51
- # Announcements
52
-
53
- All updates to this library are documented in our [CHANGELOG](https://github.com/CoCreate-app/CoCreate-position/blob/master/CHANGELOG.md) and [releases](https://github.com/CoCreate-app/CoCreate-position/releases). You may also subscribe to email for releases and breaking changes.
54
-
55
- <a name="roadmap"></a>
56
-
57
- # Roadmap
58
-
59
- If you are interested in the future direction of this project, please take a look at our open [issues](https://github.com/CoCreate-app/CoCreate-position/issues) and [pull requests](https://github.com/CoCreate-app/CoCreate-position/pulls). We would love to hear your feedback.
60
-
61
- <a name="about"></a>
62
-
63
- # About
64
-
65
- CoCreate-position is guided and supported by the CoCreate Developer Experience Team.
66
-
67
- Please Email the Developer Experience Team [here](mailto:develop@cocreate.app) in case of any queries.
68
-
69
- CoCreate-position is maintained and funded by CoCreate. The names and logos for CoCreate are trademarks of CoCreate, LLC.
70
-
71
- <a name="contribute"></a>
72
-
73
- # How to Contribute
74
-
75
- We encourage contribution to our libraries (you might even score some nifty swag), please see our [CONTRIBUTING](https://github.com/CoCreate-app/CoCreate-position/blob/master/CONTRIBUTING.md) guide for details.
76
-
77
- We want this library to be community-driven, and CoCreate led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create [issues](https://github.com/CoCreate-app/CoCreate-position/issues) and [pull requests](https://github.com/CoCreate-app/CoCreate-position/pulls) or merely upvote or comment on existing issues or pull requests.
78
-
79
- We appreciate your continued support, thank you!
80
-
81
-
82
- <a name="license"></a>
83
- # License
84
-
85
- [The MIT License (MIT)](https://github.com/CoCreate-app/CoCreate-position/blob/master/LICENSE)
1
+ # CoCreate Position
2
+
3
+ Declarative DOM positioning, dragging, snapping, and drag-and-drop for web
4
+ interfaces. Configure interactions with HTML attributes, or use the positioning
5
+ API from JavaScript. Position loads its drag, snap, and placement features on
6
+ demand when their attributes are used.
7
+
8
+ [Documentation and demo](https://CoCreateJS.com/docs/position) ·
9
+ [GitHub repository](https://github.com/CoCreateJS/position)
10
+
11
+ ![Minified size](https://img.badgesize.io/https://cdn.CoCreateJS.com/position/latest/CoCreate-position.min.js?style=flat-square&label=minified&color=orange)
12
+ ![Gzip size](https://img.badgesize.io/https://cdn.CoCreateJS.com/position/latest/CoCreate-position.min.js?compression=gzip&style=flat-square&label=gzip&color=yellow)
13
+ ![GitHub release](https://img.shields.io/github/v/release/CoCreateJS/position?style=flat-square)
14
+ ![License](https://img.shields.io/github/license/CoCreateJS/position?style=flat-square)
15
+
16
+ ![CoCreate Position demo](https://cdn.CoCreateJS.com/docs/CoCreate-position.gif)
17
+
18
+ ## Install
19
+
20
+ ### CDN
21
+
22
+ ```html
23
+ <link rel="stylesheet" href="https://cdn.CoCreateJS.com/position/latest/CoCreate-position.min.css">
24
+ <script src="https://cdn.CoCreateJS.com/position/latest/CoCreate-position.min.js"></script>
25
+ ```
26
+
27
+ ### npm
28
+
29
+ ```sh
30
+ npm install @cocreate/position
31
+ ```
32
+
33
+ ### Yarn
34
+
35
+ ```sh
36
+ yarn add @cocreate/position
37
+ ```
38
+
39
+ The JavaScript entry imports Position's stylesheet. If your bundler extracts
40
+ CSS, make sure the generated stylesheet is included in your page.
41
+
42
+ ## Overlay a box on a target
43
+
44
+ Use `position-query` to select the target and `position-element` to select the
45
+ overlay box. `position-events` lists the events that update the box; listeners
46
+ are attached directly to the element carrying these attributes:
47
+
48
+ ```html
49
+ <button
50
+ position-events="click"
51
+ position-query="$this"
52
+ position-element="$top #target-box">
53
+ Show target box
54
+ </button>
55
+
56
+ <div id="target-box" class="target-box" hidden></div>
57
+ ```
58
+
59
+ Position sets the box's `left`, `top`, `width`, and `height` to match the
60
+ queried target. It includes the target's margins. The box is shown and hidden
61
+ with the native `hidden` attribute; Position does not set `display`. Style the
62
+ box with CSS and give it `position: fixed` or `position: absolute` so its
63
+ coordinates apply.
64
+
65
+ By default, the box matches the target element. Set `position-box="text"` to
66
+ size it to the target's complete rendered text, including wrapped lines:
67
+
68
+ ```html
69
+ <div
70
+ position-events="mouseover, mousemove, mouseout"
71
+ position-query="*:hover[]"
72
+ position-element="$top #text-box"
73
+ position-box="text">
74
+ <h2>A heading to inspect</h2>
75
+ <p>The text box follows all rendered lines.</p>
76
+ </div>
77
+
78
+ <div id="text-box" class="target-box" hidden></div>
79
+ ```
80
+
81
+ Set `box-sizing: border-box` when the overlay's outside edges should match the
82
+ measured box. Other CSS, including borders, padding, and child controls, can
83
+ style or extend the overlay.
84
+
85
+ When the box is shown, its `position` object exposes the active trigger, event,
86
+ query matches, target, and measured box. Relayed iframe events keep both the
87
+ inner event target and the iframe relay target available:
88
+
89
+ ```js
90
+ toolbar.position.trigger; // element with position-query and position-events
91
+ toolbar.position.event.target; // original target, including inside an iframe
92
+ toolbar.position.event.relayTarget; // iframe element, when relayed
93
+ toolbar.position.element; // active matched element or selection range
94
+ toolbar.position.queryElements; // all query matches
95
+ toolbar.position.box.rect; // { top, right, bottom, left, width, height, x, y }
96
+ ```
97
+
98
+ Events relay from same-origin iframe documents through the iframe element, so a
99
+ position query element that contains the iframe can listen on its own event
100
+ path just as it would for content in the same document. Cross-origin iframe
101
+ contents remain subject to browser security boundaries.
102
+
103
+ For a text selection inside a same-origin iframe, listen to the relayed native
104
+ `selectionchange` event and query `$selection`:
105
+
106
+ ```html
107
+ <div
108
+ position-events="selectionchange"
109
+ position-query="iframe $selection"
110
+ position-element="$top #selection-box"
111
+ position-box="text"></div>
112
+ ```
113
+
114
+ The target box also receives a JavaScript `position` API when initialized:
115
+
116
+ ```js
117
+ box.position.place(anchor, { box: "text" });
118
+ box.position.unplace();
119
+ ```
120
+
121
+ ## Drag elements
122
+
123
+ Add `draggable` to let a user move an element directly:
124
+
125
+ ```html
126
+ <div draggable>Drag me</div>
127
+ ```
128
+
129
+ For scoped move or clone operations, put the source query and drop query on a
130
+ shared container. A `clonable-query` takes precedence if both source queries
131
+ match:
132
+
133
+ ```html
134
+ <section
135
+ draggable-query=".card[]"
136
+ clonable-query=".copy-card[]"
137
+ droppable-query=".board[]"
138
+ >
139
+ <div class="board">Drop zone</div>
140
+ <article class="card">Move this card</article>
141
+ <article class="copy-card">Clone this card</article>
142
+ </section>
143
+ ```
144
+
145
+ `draggable-query` moves the matching source; `clonable-query` leaves the source
146
+ in place and inserts a deep clone. If the pointer is not over a matching drop
147
+ target, the operation is canceled. Drop targets can be selected across
148
+ same-origin iframe documents using CoCreate query operators.
149
+
150
+ `draggable-value` and `clonable-value` let a source provide a custom drop value.
151
+ Position inserts an element value as an element and a string value as HTML. A
152
+ custom `draggable-value` is removed from its source after a successful drop;
153
+ `clonable-value` leaves its source in place.
154
+
155
+ ## Auto-scroll while dragging
156
+
157
+ Active drags automatically scroll when the pointer enters the visible top or
158
+ bottom edge of a scrollable container. No additional attributes are required.
159
+ The auto-scroll module loads on the first confirmed drag, and continues
160
+ scrolling while the pointer stays at the edge, even without further movement.
161
+
162
+ The edge zone is up to 48 pixels deep. Speed increases toward the edge, up to
163
+ 800 CSS pixels per second. Nested containers scroll from the inside outward;
164
+ an outer container takes over at an inner container's limit when the pointer
165
+ is also near its edge. Viewport scrolling and same-origin iframe drop
166
+ containers use the same behavior.
167
+
168
+ Drop references, insertion markers, and drag previews refresh after scrolling.
169
+ Scrolling stops when the pointer leaves the edge, the drag ends or is canceled,
170
+ the window loses focus, or the dragged element is removed.
171
+
172
+ ## Snap to containers and inspect insertion points
173
+
174
+ Use `snappable-query` to select snap destinations independently of
175
+ `droppable-query`:
176
+
177
+ ```html
178
+ <div draggable snappable-query="$top .snap-area[]">Drag into a snap area</div>
179
+ <div class="snap-area"></div>
180
+ ```
181
+
182
+ After a successful snap, the moved element receives the `snapped` attribute.
183
+ For drag-and-drop insertion feedback, add `position-reference` to the source
184
+ scope. Position emits `element-position-reference` with a `detail.reference`
185
+ object containing the hovered element, container, insertion position, pointer
186
+ coordinates, and owning document. The active drop container temporarily
187
+ receives `droppable`; a `position-marker` preview shows the insertion point.
188
+
189
+ During dragging, Position applies `position-moving` to a moved element or
190
+ `position-cloning` to a clone source. The pointer-following preview uses
191
+ `position-moving-preview`. These classes and the marker can be styled by the
192
+ application; default styles are included in the package CSS.
193
+
194
+ The current hovered node is also exposed as `document.hoveredElement` and
195
+ `document.documentElement.hoveredElement`. For same-origin iframe targets, the
196
+ frame document exposes its inner hovered node, while the parent document
197
+ continues to expose the iframe element.
198
+
199
+ ## Links
200
+
201
+ - [Documentation and demo](https://CoCreateJS.com/docs/position)
202
+ - [Changelog](https://github.com/CoCreateJS/position/blob/main/CHANGELOG.md)
203
+ - [Issues](https://github.com/CoCreateJS/position/issues)
204
+ - [Contributing](https://github.com/CoCreateJS/position/blob/main/CONTRIBUTING.md)
205
+ - [MIT license](https://github.com/CoCreateJS/position/blob/main/LICENSE)
206
+
207
+ ## About
208
+
209
+ CoCreate Position is maintained by [CoCreate](https://CoCreateJS.com). Questions
210
+ can be sent to [develop@CoCreateJS.com](mailto:develop@CoCreateJS.com).