@supermousejs/states 2.3.0 → 2.4.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.
- package/README.md +20 -23
- package/dist/index.d.ts +12 -3
- package/dist/index.mjs +33 -29
- package/dist/index.umd.js +1 -1
- package/package.json +9 -4
- package/CHANGELOG.md +0 -90
- package/meta.json +0 -31
- package/src/index.ts +0 -99
- package/tsconfig.json +0 -4
- package/vite.config.ts +0 -23
package/README.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# @supermousejs/states
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
Useful for creating complex interaction modes (e.g. "View" mode vs "Edit" mode).
|
|
3
|
+
Logic controller that enables/disables other plugins based on hover attributes
|
|
5
4
|
|
|
6
5
|
## Installation
|
|
7
6
|
|
|
@@ -9,38 +8,36 @@ Useful for creating complex interaction modes (e.g. "View" mode vs "Edit" mode).
|
|
|
9
8
|
pnpm add @supermousejs/states
|
|
10
9
|
```
|
|
11
10
|
|
|
12
|
-
##
|
|
11
|
+
## States
|
|
12
|
+
|
|
13
|
+
Logic controller that enables/disables other plugins based on hover attributes. The plugin names listed in `default` and `states` must match the registered `plugin.name` values you use in your app.
|
|
14
|
+
|
|
15
|
+
### Usage
|
|
13
16
|
|
|
14
17
|
```ts
|
|
15
18
|
import { Supermouse } from "@supermousejs/core";
|
|
16
19
|
import { States } from "@supermousejs/states";
|
|
17
|
-
|
|
18
20
|
const app = new Supermouse();
|
|
19
|
-
|
|
20
|
-
// Define your plugins normally (names are required)
|
|
21
|
-
app.use(Dot({ name: "dot" }));
|
|
22
|
-
app.use(Ring({ name: "ring" }));
|
|
23
|
-
app.use(Text({ name: "text" }));
|
|
24
|
-
|
|
25
|
-
// Configure states
|
|
26
|
-
app.use(
|
|
27
|
-
States({
|
|
28
|
-
default: ["dot"], // Plugins active by default
|
|
29
|
-
states: {
|
|
30
|
-
hover: ["dot", "ring"],
|
|
31
|
-
info: ["text"]
|
|
32
|
-
}
|
|
33
|
-
})
|
|
34
|
-
);
|
|
21
|
+
app.use(States({ default: ['dot'], states: { 'hover': ['ring'] } }));
|
|
35
22
|
```
|
|
36
23
|
|
|
37
|
-
|
|
24
|
+
### HTML Example
|
|
38
25
|
|
|
39
26
|
```html
|
|
40
|
-
<div data-supermouse-state="hover">
|
|
41
|
-
<
|
|
27
|
+
<div data-supermouse-state="hover">
|
|
28
|
+
<span class="dot"></span>
|
|
29
|
+
<span class="ring"></span>
|
|
30
|
+
</div>
|
|
42
31
|
```
|
|
43
32
|
|
|
33
|
+
### Options
|
|
34
|
+
|
|
35
|
+
| Name | Type | Default | Description |
|
|
36
|
+
| --- | --- | --- | --- |
|
|
37
|
+
| default | string[] | [] | List of plugin names active by default. |
|
|
38
|
+
| states | Record<string, string[]> | {} | Map of state names to lists of active plugins. |
|
|
39
|
+
| attribute | string | 'data-supermouse-state' | DOM attribute to trigger state changes. |
|
|
40
|
+
|
|
44
41
|
## Documentation
|
|
45
42
|
|
|
46
43
|
Full documentation and interactive playground available at [supermouse](https://supermouse.js.org) or [check out the repo](https://github.com/Whitestar14/supermouse-js).
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
import { SupermousePlugin } from '../packages/core/src';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* State machine plugin.
|
|
5
|
+
*
|
|
6
|
+
* Hovers over `[data-supermouse-state="foo"]` enable the plugin list
|
|
7
|
+
* registered for `"foo"`. Everything else falls back to `default`.
|
|
8
|
+
*
|
|
9
|
+
* Install this **after** all plugins it manages, or initialization will
|
|
10
|
+
* miss plugins that haven't been registered yet.
|
|
11
|
+
*/
|
|
3
12
|
export declare const States: (options: StatesOptions) => SupermousePlugin;
|
|
4
13
|
|
|
5
14
|
export declare interface StatesOptions {
|
|
6
15
|
name?: string;
|
|
7
16
|
isEnabled?: boolean;
|
|
8
|
-
/**
|
|
17
|
+
/** Plugins active when no state attribute is hovered. */
|
|
9
18
|
default: string[];
|
|
10
|
-
/** Map of state names to
|
|
19
|
+
/** Map of state names to plugin names to enable. */
|
|
11
20
|
states: Record<string, string[]>;
|
|
12
|
-
/**
|
|
21
|
+
/** Attribute that triggers a state change. */
|
|
13
22
|
attribute?: string;
|
|
14
23
|
}
|
|
15
24
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,41 +1,45 @@
|
|
|
1
|
-
import { definePlugin as
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
Object.values(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
let c = "default", d = !1;
|
|
8
|
-
return f(
|
|
1
|
+
import { definePlugin as g } from "@supermousejs/utils";
|
|
2
|
+
const E = (e) => {
|
|
3
|
+
const u = e.attribute ?? "data-supermouse-state", d = new Set(e.default), r = /* @__PURE__ */ new Set();
|
|
4
|
+
Object.values(e.states).forEach((t) => t.forEach((a) => r.add(a))), e.default.forEach((t) => r.add(t));
|
|
5
|
+
let f = "__UNINITIALIZED__";
|
|
6
|
+
return g(
|
|
9
7
|
{
|
|
10
8
|
name: "states",
|
|
11
|
-
// High priority: Run BEFORE visual plugins so they know if they are enabled/disabled this frame
|
|
12
9
|
priority: -999,
|
|
13
|
-
install(
|
|
14
|
-
|
|
10
|
+
install(t) {
|
|
11
|
+
t.registerHoverTarget(`[${u}]`);
|
|
15
12
|
},
|
|
16
|
-
update(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const t = l.getAttribute(r);
|
|
26
|
-
t && a.states[t] && (s = t);
|
|
13
|
+
update(t) {
|
|
14
|
+
const a = t.state.hoverTarget;
|
|
15
|
+
let n = "default";
|
|
16
|
+
if (a) {
|
|
17
|
+
const s = a.closest(`[${u}]`);
|
|
18
|
+
if (s) {
|
|
19
|
+
const l = s.getAttribute(u);
|
|
20
|
+
l && e.states[l] && (n = l);
|
|
21
|
+
}
|
|
27
22
|
}
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
if (n === f) return;
|
|
24
|
+
const o = n === "default" ? e.default : e.states[n];
|
|
25
|
+
for (const s of r) {
|
|
26
|
+
const l = t.getPlugin(s);
|
|
27
|
+
if (!l) continue;
|
|
28
|
+
const i = o.includes(s), c = l.isEnabled !== !1;
|
|
29
|
+
i && !c && t.enablePlugin(s), !i && c && t.disablePlugin(s);
|
|
30
|
+
}
|
|
31
|
+
f = n;
|
|
32
|
+
},
|
|
33
|
+
destroy(t) {
|
|
34
|
+
for (const a of r) {
|
|
35
|
+
const n = t.getPlugin(a);
|
|
36
|
+
n && d.has(a) && n.isEnabled === !1 && t.enablePlugin(a);
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
},
|
|
36
|
-
|
|
40
|
+
e
|
|
37
41
|
);
|
|
38
42
|
};
|
|
39
43
|
export {
|
|
40
|
-
|
|
44
|
+
E as States
|
|
41
45
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(u,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("@supermousejs/utils")):typeof define=="function"&&define.amd?define(["exports","@supermousejs/utils"],l):(u=typeof globalThis<"u"?globalThis:u||self,l(u.SupermouseStates={},u.SupermouseUtils))})(this,(function(u,l){"use strict";const g=t=>{const r=t.attribute??"data-supermouse-state",m=new Set(t.default),f=new Set;Object.values(t.states).forEach(e=>e.forEach(s=>f.add(s))),t.default.forEach(e=>f.add(e));let d="__UNINITIALIZED__";return l.definePlugin({name:"states",priority:-999,install(e){e.registerHoverTarget(`[${r}]`)},update(e){const s=e.state.hoverTarget;let n="default";if(s){const a=s.closest(`[${r}]`);if(a){const i=a.getAttribute(r);i&&t.states[i]&&(n=i)}}if(n===d)return;const S=n==="default"?t.default:t.states[n];for(const a of f){const i=e.getPlugin(a);if(!i)continue;const o=S.includes(a),c=i.isEnabled!==!1;o&&!c&&e.enablePlugin(a),!o&&c&&e.disablePlugin(a)}d=n},destroy(e){for(const s of f){const n=e.getPlugin(s);n&&m.has(s)&&n.isEnabled===!1&&e.enablePlugin(s)}}},t)};u.States=g,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supermousejs/states",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"main": "dist/index.umd.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"description": "Logic controller that enables/disables other plugins based on hover attributes",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
7
12
|
"author": "O.S David",
|
|
8
13
|
"url": "https://github.com/Whitestar14/supermouse-js",
|
|
9
14
|
"license": "MIT",
|
|
10
15
|
"dependencies": {
|
|
11
|
-
"@supermousejs/utils": "2.
|
|
16
|
+
"@supermousejs/utils": "2.4.0"
|
|
12
17
|
},
|
|
13
18
|
"devDependencies": {
|
|
14
|
-
"@supermousejs/core": "2.
|
|
19
|
+
"@supermousejs/core": "2.4.0"
|
|
15
20
|
},
|
|
16
21
|
"peerDependencies": {
|
|
17
|
-
"@supermousejs/core": "2.
|
|
22
|
+
"@supermousejs/core": "2.4.0"
|
|
18
23
|
},
|
|
19
24
|
"repository": {
|
|
20
25
|
"type": "git",
|
package/CHANGELOG.md
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
# @supermousejs/states
|
|
2
|
-
|
|
3
|
-
## 2.3.0
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- Updated dependencies [f6f44b2]
|
|
8
|
-
- @supermousejs/core@2.2.0
|
|
9
|
-
- @supermousejs/utils@2.3.0
|
|
10
|
-
|
|
11
|
-
## 2.2.0
|
|
12
|
-
|
|
13
|
-
### Patch Changes
|
|
14
|
-
|
|
15
|
-
- 6d70c18: remove legacy package and update supermouse domain in readme
|
|
16
|
-
- 14fb5b6: Updated tsconfig to be reference-compliant with core, utils and zoetrope when required
|
|
17
|
-
- Updated dependencies [6d70c18]
|
|
18
|
-
- Updated dependencies [2590af3]
|
|
19
|
-
- Updated dependencies [14fb5b6]
|
|
20
|
-
- Updated dependencies [9fe1a7b]
|
|
21
|
-
- Updated dependencies [9fa6ece]
|
|
22
|
-
- @supermousejs/core@2.1.0
|
|
23
|
-
- @supermousejs/utils@2.2.0
|
|
24
|
-
|
|
25
|
-
## 2.1.1
|
|
26
|
-
|
|
27
|
-
### Patch Changes
|
|
28
|
-
|
|
29
|
-
- 67f771b: Add relevant npm metadata to package.json file
|
|
30
|
-
- Updated dependencies [67f771b]
|
|
31
|
-
- @supermousejs/utils@2.1.1
|
|
32
|
-
- @supermousejs/core@2.0.5
|
|
33
|
-
|
|
34
|
-
## 2.1.0
|
|
35
|
-
|
|
36
|
-
### Minor Changes
|
|
37
|
-
|
|
38
|
-
- 0a1652d: fixed build architecture and updated plugin metadata
|
|
39
|
-
|
|
40
|
-
### Patch Changes
|
|
41
|
-
|
|
42
|
-
- Updated dependencies [0a1652d]
|
|
43
|
-
- @supermousejs/utils@2.1.0
|
|
44
|
-
|
|
45
|
-
## 2.0.4
|
|
46
|
-
|
|
47
|
-
### Patch Changes
|
|
48
|
-
|
|
49
|
-
- 993dc67: Updated supemousejs packages with proper author, license and url descriptors to repo
|
|
50
|
-
- Updated dependencies [993dc67]
|
|
51
|
-
- @supermousejs/utils@2.0.4
|
|
52
|
-
- @supermousejs/core@2.0.4
|
|
53
|
-
|
|
54
|
-
## 2.0.3
|
|
55
|
-
|
|
56
|
-
### Patch Changes
|
|
57
|
-
|
|
58
|
-
- Updated dependencies
|
|
59
|
-
- @supermousejs/core@2.0.3
|
|
60
|
-
- @supermousejs/utils@2.0.3
|
|
61
|
-
|
|
62
|
-
## 2.0.2
|
|
63
|
-
|
|
64
|
-
### Patch Changes
|
|
65
|
-
|
|
66
|
-
- ae219a0: Update READMEs with correct link to documentation
|
|
67
|
-
- Updated dependencies [ae219a0]
|
|
68
|
-
- @supermousejs/utils@2.0.2
|
|
69
|
-
- @supermousejs/core@2.0.2
|
|
70
|
-
|
|
71
|
-
## 2.0.1
|
|
72
|
-
|
|
73
|
-
### Patch Changes
|
|
74
|
-
|
|
75
|
-
- Add minimal README.md files to packages
|
|
76
|
-
- Updated dependencies
|
|
77
|
-
- @supermousejs/utils@2.0.1
|
|
78
|
-
- @supermousejs/core@2.0.1
|
|
79
|
-
|
|
80
|
-
## 2.0.0
|
|
81
|
-
|
|
82
|
-
### Major Changes
|
|
83
|
-
|
|
84
|
-
- Initial v2.0.0 release
|
|
85
|
-
|
|
86
|
-
### Patch Changes
|
|
87
|
-
|
|
88
|
-
- Updated dependencies
|
|
89
|
-
- @supermousejs/utils@2.0.0
|
|
90
|
-
- @supermousejs/core@2.0.0
|
package/meta.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"id": "states",
|
|
3
|
-
"name": "States",
|
|
4
|
-
"package": "@supermousejs/states",
|
|
5
|
-
"description": "Logic controller that enables/disables other plugins based on hover attributes.",
|
|
6
|
-
"code": "app.use(States({ default: ['dot'], states: { 'hover': ['ring'] } }));",
|
|
7
|
-
"icon": "context",
|
|
8
|
-
"options": [
|
|
9
|
-
{
|
|
10
|
-
"name": "default",
|
|
11
|
-
"type": "string[]",
|
|
12
|
-
"default": "[]",
|
|
13
|
-
"description": "List of plugin names active by default.",
|
|
14
|
-
"reactive": false
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
"name": "states",
|
|
18
|
-
"type": "Record<string, string[]>",
|
|
19
|
-
"default": "{}",
|
|
20
|
-
"description": "Map of state names to lists of active plugins.",
|
|
21
|
-
"reactive": false
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
"name": "attribute",
|
|
25
|
-
"type": "string",
|
|
26
|
-
"default": "'data-supermouse-state'",
|
|
27
|
-
"description": "DOM attribute to trigger state changes.",
|
|
28
|
-
"reactive": false
|
|
29
|
-
}
|
|
30
|
-
]
|
|
31
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import type { Supermouse } from "@supermousejs/core";
|
|
2
|
-
import { definePlugin } from "@supermousejs/utils";
|
|
3
|
-
|
|
4
|
-
export interface StatesOptions {
|
|
5
|
-
name?: string;
|
|
6
|
-
isEnabled?: boolean;
|
|
7
|
-
/** The default state (active when nothing else is hovered). */
|
|
8
|
-
default: string[];
|
|
9
|
-
/** Map of state names to lists of plugin names to enable. */
|
|
10
|
-
states: Record<string, string[]>;
|
|
11
|
-
/** CSS selector attribute to trigger state change. Default 'data-supermouse-state'. */
|
|
12
|
-
attribute?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const States = (options: StatesOptions) => {
|
|
16
|
-
const attr = options.attribute || "data-supermouse-state";
|
|
17
|
-
|
|
18
|
-
// Cache the relationships for fast lookups
|
|
19
|
-
const allManagedPlugins = new Set<string>(); // All plugins mentioned in 'states'
|
|
20
|
-
const defaultPlugins = new Set(options.default);
|
|
21
|
-
|
|
22
|
-
// Populate the set of managed plugins (excluding defaults for now)
|
|
23
|
-
Object.values(options.states).forEach((list) => {
|
|
24
|
-
list.forEach((p) => allManagedPlugins.add(p));
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
let currentState = "default";
|
|
28
|
-
let hasInitialized = false;
|
|
29
|
-
|
|
30
|
-
return definePlugin(
|
|
31
|
-
{
|
|
32
|
-
name: "states",
|
|
33
|
-
// High priority: Run BEFORE visual plugins so they know if they are enabled/disabled this frame
|
|
34
|
-
priority: -999,
|
|
35
|
-
|
|
36
|
-
install(app: Supermouse) {
|
|
37
|
-
// Register the trigger attribute
|
|
38
|
-
app.registerHoverTarget(`[${attr}]`);
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
update(app: Supermouse) {
|
|
42
|
-
// --- INITIALIZATION STEP ---
|
|
43
|
-
// We do this in the first update tick to ensure all other plugins
|
|
44
|
-
// have been registered via .use(), regardless of order.
|
|
45
|
-
if (!hasInitialized) {
|
|
46
|
-
// 1. Disable all "Special State" plugins initially
|
|
47
|
-
allManagedPlugins.forEach((name) => {
|
|
48
|
-
if (!defaultPlugins.has(name)) {
|
|
49
|
-
app.disablePlugin(name);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// 2. Ensure default plugins are enabled
|
|
54
|
-
defaultPlugins.forEach((name) => {
|
|
55
|
-
app.enablePlugin(name);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
hasInitialized = true;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// --- STANDARD LOGIC ---
|
|
62
|
-
const target = app.state.hoverTarget;
|
|
63
|
-
let nextState = "default";
|
|
64
|
-
|
|
65
|
-
// 1. Determine Desired State
|
|
66
|
-
if (target && target.hasAttribute(attr)) {
|
|
67
|
-
const val = target.getAttribute(attr);
|
|
68
|
-
if (val && options.states[val]) {
|
|
69
|
-
nextState = val;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// 2. Switch State (Only if changed)
|
|
74
|
-
if (nextState !== currentState) {
|
|
75
|
-
// A. Determine which plugins should be active
|
|
76
|
-
const activePlugins =
|
|
77
|
-
nextState === "default" ? options.default : options.states[nextState];
|
|
78
|
-
|
|
79
|
-
// B. Apply changes
|
|
80
|
-
// Note: We combine default + managed to ensure we cover everyone involved
|
|
81
|
-
const involved = new Set([...defaultPlugins, ...allManagedPlugins]);
|
|
82
|
-
|
|
83
|
-
involved.forEach((pluginName) => {
|
|
84
|
-
const shouldBeActive = activePlugins.includes(pluginName);
|
|
85
|
-
|
|
86
|
-
if (shouldBeActive) {
|
|
87
|
-
app.enablePlugin(pluginName);
|
|
88
|
-
} else {
|
|
89
|
-
app.disablePlugin(pluginName);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
currentState = nextState;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
options
|
|
98
|
-
);
|
|
99
|
-
};
|
package/tsconfig.json
DELETED
package/vite.config.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "vite";
|
|
2
|
-
import dts from "vite-plugin-dts";
|
|
3
|
-
import path from "path";
|
|
4
|
-
|
|
5
|
-
export default defineConfig({
|
|
6
|
-
build: {
|
|
7
|
-
lib: {
|
|
8
|
-
entry: path.resolve(__dirname, "src/index.ts"),
|
|
9
|
-
name: "SupermouseStates",
|
|
10
|
-
fileName: (format) => (format === "es" ? "index.mjs" : "index.umd.js")
|
|
11
|
-
},
|
|
12
|
-
rollupOptions: {
|
|
13
|
-
external: ["@supermousejs/core", "@supermousejs/utils"],
|
|
14
|
-
output: {
|
|
15
|
-
globals: {
|
|
16
|
-
"@supermousejs/core": "SupermouseCore",
|
|
17
|
-
"@supermousejs/utils": "SupermouseUtils"
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
plugins: [dts({ rollupTypes: true })]
|
|
23
|
-
});
|