@destyler/toggle 0.1.0 → 0.2.0-beta.5

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.
@@ -15,8 +15,7 @@ const dom = createScope({
15
15
  getItemId: (ctx, value) => ctx.ids?.item?.(value) ?? `toggle:${ctx.id}:${value}`,
16
16
  getRootEl: (ctx) => dom.getById(ctx, dom.getRootId(ctx)),
17
17
  getElements: (ctx) => {
18
- const ownerId = CSS.escape(dom.getRootId(ctx));
19
- const selector = `[data-ownedby='${ownerId}']:not([data-disabled])`;
18
+ const selector = `[data-ownedby='${CSS.escape(dom.getRootId(ctx))}']:not([data-disabled])`;
20
19
  return queryAll(dom.getRootEl(ctx), selector);
21
20
  },
22
21
  getFirstEl: (ctx) => first(dom.getElements(ctx)),
@@ -67,8 +66,7 @@ function connect(state, send, normalize) {
67
66
  },
68
67
  onFocus(event) {
69
68
  if (disabled) return;
70
- const evt = event.nativeEvent || event;
71
- if (!isSelfTarget(evt) || !!state.context.isClickFocus || state.context.isTabbingBackward) return;
69
+ if (!isSelfTarget(event.nativeEvent || event) || !!state.context.isClickFocus || state.context.isTabbingBackward) return;
72
70
  send("ROOT.FOCUS");
73
71
  },
74
72
  onBlur() {
@@ -116,7 +114,7 @@ function connect(state, send, normalize) {
116
114
  if (event.defaultPrevented) return;
117
115
  if (!isSelfTarget(event)) return;
118
116
  if (itemState.disabled) return;
119
- const keyMap = {
117
+ const exec = {
120
118
  Tab(event$1) {
121
119
  const isShiftTab = event$1.shiftKey;
122
120
  send({
@@ -148,8 +146,7 @@ function connect(state, send, normalize) {
148
146
  if (!rovingFocus) return;
149
147
  send("TOGGLE.FOCUS_LAST");
150
148
  }
151
- };
152
- const exec = keyMap[getEventKey(event)];
149
+ }[getEventKey(event)];
153
150
  if (exec) {
154
151
  exec(event);
155
152
  if (event.key !== "Tab") event.preventDefault();
@@ -172,7 +169,6 @@ const set = { value(ctx, value) {
172
169
  invoke.change(ctx);
173
170
  } };
174
171
  function machine(userContext) {
175
- const ctx = compact(userContext);
176
172
  return createMachine({
177
173
  id: "toggle-group",
178
174
  initial: "idle",
@@ -182,13 +178,13 @@ function machine(userContext) {
182
178
  orientation: "horizontal",
183
179
  rovingFocus: true,
184
180
  loopFocus: true,
185
- ...ctx,
181
+ ...compact(userContext),
186
182
  focusedId: null,
187
183
  isTabbingBackward: false,
188
184
  isClickFocus: false,
189
185
  isWithinToolbar: false
190
186
  },
191
- computed: { currentLoopFocus: (ctx$1) => ctx$1.loopFocus && !ctx$1.isWithinToolbar },
187
+ computed: { currentLoopFocus: (ctx) => ctx.loopFocus && !ctx.isWithinToolbar },
192
188
  entry: ["checkIfWithinToolbar"],
193
189
  on: {
194
190
  "VALUE.SET": { actions: ["setValue"] },
@@ -225,59 +221,58 @@ function machine(userContext) {
225
221
  }
226
222
  }, {
227
223
  guards: {
228
- isClickFocus: (ctx$1) => ctx$1.isClickFocus,
229
- isTabbingBackward: (ctx$1) => ctx$1.isTabbingBackward
224
+ isClickFocus: (ctx) => ctx.isClickFocus,
225
+ isTabbingBackward: (ctx) => ctx.isTabbingBackward
230
226
  },
231
227
  actions: {
232
- setIsTabbingBackward(ctx$1) {
233
- ctx$1.isTabbingBackward = true;
228
+ setIsTabbingBackward(ctx) {
229
+ ctx.isTabbingBackward = true;
234
230
  },
235
- clearIsTabbingBackward(ctx$1) {
236
- ctx$1.isTabbingBackward = false;
231
+ clearIsTabbingBackward(ctx) {
232
+ ctx.isTabbingBackward = false;
237
233
  },
238
- setClickFocus(ctx$1) {
239
- ctx$1.isClickFocus = true;
234
+ setClickFocus(ctx) {
235
+ ctx.isClickFocus = true;
240
236
  },
241
- clearClickFocus(ctx$1) {
242
- ctx$1.isClickFocus = false;
237
+ clearClickFocus(ctx) {
238
+ ctx.isClickFocus = false;
243
239
  },
244
- checkIfWithinToolbar(ctx$1) {
245
- const closestToolbar = dom.getRootEl(ctx$1)?.closest("[role=toolbar]");
246
- ctx$1.isWithinToolbar = !!closestToolbar;
240
+ checkIfWithinToolbar(ctx) {
241
+ ctx.isWithinToolbar = !!dom.getRootEl(ctx)?.closest("[role=toolbar]");
247
242
  },
248
- setFocusedId(ctx$1, evt) {
249
- ctx$1.focusedId = evt.id;
243
+ setFocusedId(ctx, evt) {
244
+ ctx.focusedId = evt.id;
250
245
  },
251
- clearFocusedId(ctx$1) {
252
- ctx$1.focusedId = null;
246
+ clearFocusedId(ctx) {
247
+ ctx.focusedId = null;
253
248
  },
254
- setValue(ctx$1, evt) {
249
+ setValue(ctx, evt) {
255
250
  if (!evt.value) return;
256
- let next = Array.from(ctx$1.value);
257
- if (ctx$1.multiple) next = next.includes(evt.value) ? remove(next, evt.value) : add(next, evt.value);
258
- else next = isEqual(ctx$1.value, [evt.value]) ? [] : [evt.value];
259
- set.value(ctx$1, next);
251
+ let next = Array.from(ctx.value);
252
+ if (ctx.multiple) next = next.includes(evt.value) ? remove(next, evt.value) : add(next, evt.value);
253
+ else next = isEqual(ctx.value, [evt.value]) ? [] : [evt.value];
254
+ set.value(ctx, next);
260
255
  },
261
- focusNextToggle(ctx$1) {
256
+ focusNextToggle(ctx) {
262
257
  raf(() => {
263
- if (!ctx$1.focusedId) return;
264
- dom.getNextEl(ctx$1, ctx$1.focusedId)?.focus({ preventScroll: true });
258
+ if (!ctx.focusedId) return;
259
+ dom.getNextEl(ctx, ctx.focusedId)?.focus({ preventScroll: true });
265
260
  });
266
261
  },
267
- focusPrevToggle(ctx$1) {
262
+ focusPrevToggle(ctx) {
268
263
  raf(() => {
269
- if (!ctx$1.focusedId) return;
270
- dom.getPrevEl(ctx$1, ctx$1.focusedId)?.focus({ preventScroll: true });
264
+ if (!ctx.focusedId) return;
265
+ dom.getPrevEl(ctx, ctx.focusedId)?.focus({ preventScroll: true });
271
266
  });
272
267
  },
273
- focusFirstToggle(ctx$1) {
268
+ focusFirstToggle(ctx) {
274
269
  raf(() => {
275
- dom.getFirstEl(ctx$1)?.focus({ preventScroll: true });
270
+ dom.getFirstEl(ctx)?.focus({ preventScroll: true });
276
271
  });
277
272
  },
278
- focusLastToggle(ctx$1) {
273
+ focusLastToggle(ctx) {
279
274
  raf(() => {
280
- dom.getLastEl(ctx$1)?.focus({ preventScroll: true });
275
+ dom.getLastEl(ctx)?.focus({ preventScroll: true });
281
276
  });
282
277
  }
283
278
  }
package/package.json CHANGED
@@ -1,26 +1,35 @@
1
1
  {
2
2
  "name": "@destyler/toggle",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.2.0-beta.5",
5
5
  "description": "A two-state button that can be either on or off.",
6
6
  "author": "Elone Hoo <elonehoo@gmail.com>",
7
7
  "license": "MIT",
8
+ "homepage": "https://github.com/destyler/destyler",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/destyler/destyler.git",
12
+ "directory": "packages/components/toggle"
13
+ },
8
14
  "exports": {
9
- ".": "./dist/index.js"
15
+ ".": "./dist/index.mjs"
10
16
  },
11
- "main": "dist/index.js",
12
- "module": "dist/index.js",
13
- "types": "dist/index.d.ts",
17
+ "main": "dist/index.mjs",
18
+ "module": "dist/index.mjs",
19
+ "types": "dist/index.d.mts",
14
20
  "files": [
15
21
  "*.d.ts",
16
22
  "dist"
17
23
  ],
18
24
  "dependencies": {
19
- "@destyler/anatomy": "0.1.0",
20
- "@destyler/dom": "0.1.0",
21
- "@destyler/utils": "0.1.0",
22
- "@destyler/xstate": "0.1.0",
23
- "@destyler/types": "0.1.0"
25
+ "@destyler/anatomy": "0.2.0-beta.5",
26
+ "@destyler/types": "0.2.0-beta.5",
27
+ "@destyler/dom": "0.2.0-beta.5",
28
+ "@destyler/utils": "0.2.0-beta.5",
29
+ "@destyler/xstate": "0.2.0-beta.5"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
24
33
  },
25
34
  "scripts": {
26
35
  "clear": "rimraf ./dist",
File without changes