@destyler/switch 0.1.0 → 0.2.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.
@@ -80,8 +80,7 @@ function connect(state, send, normalize) {
80
80
  },
81
81
  onClick(event) {
82
82
  if (disabled) return;
83
- const target = getEventTarget(event);
84
- if (target === dom.getHiddenInputEl(state.context)) event.stopPropagation();
83
+ if (getEventTarget(event) === dom.getHiddenInputEl(state.context)) event.stopPropagation();
85
84
  }
86
85
  });
87
86
  },
@@ -125,12 +124,11 @@ function connect(state, send, normalize) {
125
124
  "value": state.context.value,
126
125
  "style": visuallyHiddenStyle,
127
126
  onFocus() {
128
- const focusVisible$1 = isFocusVisible();
129
127
  send({
130
128
  type: "CONTEXT.SET",
131
129
  context: {
132
130
  focused: true,
133
- focusVisible: focusVisible$1
131
+ focusVisible: isFocusVisible()
134
132
  }
135
133
  });
136
134
  },
@@ -172,7 +170,6 @@ const set = { checked: (ctx, checked) => {
172
170
  invoke.change(ctx);
173
171
  } };
174
172
  function machine(userContext) {
175
- const ctx = compact(userContext);
176
173
  return createMachine({
177
174
  id: "switch",
178
175
  initial: "ready",
@@ -181,11 +178,11 @@ function machine(userContext) {
181
178
  label: "switch",
182
179
  value: "on",
183
180
  disabled: false,
184
- ...ctx,
181
+ ...compact(userContext),
185
182
  fieldsetDisabled: false,
186
183
  focusVisible: false
187
184
  },
188
- computed: { isDisabled: (ctx$1) => ctx$1.disabled || ctx$1.fieldsetDisabled },
185
+ computed: { isDisabled: (ctx) => ctx.disabled || ctx.fieldsetDisabled },
189
186
  watch: {
190
187
  disabled: "removeFocusIfNeeded",
191
188
  checked: "syncInputElement"
@@ -210,25 +207,25 @@ function machine(userContext) {
210
207
  }, {
211
208
  guards: { isTrusted: (_ctx, evt) => !!evt.isTrusted },
212
209
  activities: {
213
- trackPressEvent(ctx$1) {
214
- if (ctx$1.isDisabled) return;
210
+ trackPressEvent(ctx) {
211
+ if (ctx.isDisabled) return;
215
212
  return trackPress({
216
- pointerNode: dom.getRootEl(ctx$1),
217
- keyboardNode: dom.getHiddenInputEl(ctx$1),
213
+ pointerNode: dom.getRootEl(ctx),
214
+ keyboardNode: dom.getHiddenInputEl(ctx),
218
215
  isValidKey: (event) => event.key === " ",
219
- onPress: () => ctx$1.active = false,
220
- onPressStart: () => ctx$1.active = true,
221
- onPressEnd: () => ctx$1.active = false
216
+ onPress: () => ctx.active = false,
217
+ onPressStart: () => ctx.active = true,
218
+ onPressEnd: () => ctx.active = false
222
219
  });
223
220
  },
224
- trackFocusVisible(ctx$1) {
225
- if (ctx$1.isDisabled) return;
226
- return trackFocusVisible({ root: dom.getRootNode(ctx$1) });
221
+ trackFocusVisible(ctx) {
222
+ if (ctx.isDisabled) return;
223
+ return trackFocusVisible({ root: dom.getRootNode(ctx) });
227
224
  },
228
- trackFormControlState(ctx$1, _evt, { send, initialContext }) {
229
- return trackFormControl(dom.getHiddenInputEl(ctx$1), {
225
+ trackFormControlState(ctx, _evt, { send, initialContext }) {
226
+ return trackFormControl(dom.getHiddenInputEl(ctx), {
230
227
  onFieldsetDisabledChange(disabled) {
231
- ctx$1.fieldsetDisabled = disabled;
228
+ ctx.fieldsetDisabled = disabled;
232
229
  },
233
230
  onFormReset() {
234
231
  send({
@@ -241,26 +238,25 @@ function machine(userContext) {
241
238
  }
242
239
  },
243
240
  actions: {
244
- setContext(ctx$1, evt) {
245
- Object.assign(ctx$1, evt.context);
241
+ setContext(ctx, evt) {
242
+ Object.assign(ctx, evt.context);
246
243
  },
247
- syncInputElement(ctx$1) {
248
- const inputEl = dom.getHiddenInputEl(ctx$1);
244
+ syncInputElement(ctx) {
245
+ const inputEl = dom.getHiddenInputEl(ctx);
249
246
  if (!inputEl) return;
250
- inputEl.checked = !!ctx$1.checked;
247
+ inputEl.checked = !!ctx.checked;
251
248
  },
252
- removeFocusIfNeeded(ctx$1) {
253
- if (ctx$1.disabled && ctx$1.focused) ctx$1.focused = false;
249
+ removeFocusIfNeeded(ctx) {
250
+ if (ctx.disabled && ctx.focused) ctx.focused = false;
254
251
  },
255
- setChecked(ctx$1, evt) {
256
- set.checked(ctx$1, evt.checked);
252
+ setChecked(ctx, evt) {
253
+ set.checked(ctx, evt.checked);
257
254
  },
258
- toggleChecked(ctx$1, _evt) {
259
- set.checked(ctx$1, !ctx$1.checked);
255
+ toggleChecked(ctx, _evt) {
256
+ set.checked(ctx, !ctx.checked);
260
257
  },
261
- dispatchChangeEvent(ctx$1) {
262
- const inputEl = dom.getHiddenInputEl(ctx$1);
263
- dispatchInputCheckedEvent(inputEl, { checked: ctx$1.checked });
258
+ dispatchChangeEvent(ctx) {
259
+ dispatchInputCheckedEvent(dom.getHiddenInputEl(ctx), { checked: ctx.checked });
264
260
  }
265
261
  }
266
262
  });
package/package.json CHANGED
@@ -1,27 +1,36 @@
1
1
  {
2
2
  "name": "@destyler/switch",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.2.0",
5
5
  "description": "A control that allows the user to toggle between checked and not checked.",
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/switch"
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/focus-visible": "0.1.0",
21
- "@destyler/dom": "0.1.0",
22
- "@destyler/types": "0.1.0",
23
- "@destyler/utils": "0.1.0",
24
- "@destyler/xstate": "0.1.0"
25
+ "@destyler/dom": "0.2.0",
26
+ "@destyler/anatomy": "0.2.0",
27
+ "@destyler/types": "0.2.0",
28
+ "@destyler/xstate": "0.2.0",
29
+ "@destyler/focus-visible": "0.2.0",
30
+ "@destyler/utils": "0.2.0"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
25
34
  },
26
35
  "scripts": {
27
36
  "clear": "rimraf ./dist",
File without changes