browser-extension-settings 0.3.0 → 0.3.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/lib/index.ts CHANGED
@@ -3,6 +3,6 @@ export {
3
3
  showSettings,
4
4
  hideSettings,
5
5
  getSettingsValue,
6
- saveSattingsValues,
7
- resetSattingsValues,
6
+ saveSettingsValues,
7
+ resetSettingsValues,
8
8
  } from "./settings"
package/lib/settings.ts CHANGED
@@ -46,6 +46,7 @@ type SettingsTable = Record<
46
46
 
47
47
  type SettingsSwitchItem = {
48
48
  title: string
49
+ icon?: string
49
50
  defaultValue: boolean
50
51
  type?: "switch"
51
52
  group?: number
@@ -53,6 +54,7 @@ type SettingsSwitchItem = {
53
54
 
54
55
  type SettingsInputItem = {
55
56
  title: string
57
+ icon?: string
56
58
  defaultValue: string
57
59
  placeholder?: string
58
60
  type: string
@@ -61,6 +63,7 @@ type SettingsInputItem = {
61
63
 
62
64
  type SettingsActionItem = {
63
65
  title: string
66
+ icon?: string
64
67
  type: string
65
68
  onclick?: () => void
66
69
  url?: string
@@ -70,6 +73,7 @@ type SettingsActionItem = {
70
73
 
71
74
  type SettingsTipItem = {
72
75
  title: string
76
+ icon?: string
73
77
  type: string
74
78
  tipContent: string
75
79
  group?: number
@@ -108,7 +112,7 @@ async function getSettings() {
108
112
  )
109
113
  }
110
114
 
111
- async function saveSattingsValue(key: string, value: any) {
115
+ async function saveSettingsValue(key: string, value: any) {
112
116
  const settings = await getSettings()
113
117
  settings[key] =
114
118
  settingsTable[key] && settingsTable[key].defaultValue === value
@@ -118,11 +122,11 @@ async function saveSattingsValue(key: string, value: any) {
118
122
  await setValue(storageKey, settings)
119
123
  }
120
124
 
121
- export async function resetSattingsValues() {
125
+ export async function resetSettingsValues() {
122
126
  await setValue(storageKey, {})
123
127
  }
124
128
 
125
- export async function saveSattingsValues(
129
+ export async function saveSettingsValues(
126
130
  values: Record<string, boolean | string | undefined>
127
131
  ) {
128
132
  const settings = await getSettings()
@@ -324,11 +328,11 @@ function createSettingsElement() {
324
328
  // console.log(key, item, type, group)
325
329
  switch (type) {
326
330
  case "switch": {
327
- const switchOption = createSwitchOption(item.title, {
331
+ const switchOption = createSwitchOption(item.icon, item.title, {
328
332
  async onchange(event: Event) {
329
333
  const checkbox = event.target as HTMLInputElement
330
334
  if (checkbox) {
331
- await saveSattingsValue(key, checkbox.checked)
335
+ await saveSettingsValue(key, checkbox.checked)
332
336
  }
333
337
  },
334
338
  })
@@ -357,7 +361,7 @@ function createSettingsElement() {
357
361
 
358
362
  timeoutId = setTimeout(async () => {
359
363
  if (textArea) {
360
- await saveSattingsValue(key, textArea.value.trim())
364
+ await saveSettingsValue(key, textArea.value.trim())
361
365
  }
362
366
  }, 100)
363
367
  },
package/lib/style.scss CHANGED
@@ -224,8 +224,14 @@
224
224
  border-top: none;
225
225
  }
226
226
 
227
+ .switch_option > img {
228
+ width: 24px;
229
+ height: 24px;
230
+ margin-right: 10px;
231
+ }
227
232
  .switch_option > span {
228
233
  margin-right: 10px;
234
+ flex-grow: 1;
229
235
  }
230
236
 
231
237
  .option_groups .bes_tip {
package/lib/switch.ts CHANGED
@@ -29,8 +29,26 @@ export function createSwitch(options = {} as SwichOptions): HTMLElement {
29
29
  export function createSwitchOption(
30
30
  text: string,
31
31
  options: SwichOptions
32
+ ): HTMLElement
33
+ export function createSwitchOption(
34
+ icon: string | undefined,
35
+ text: string,
36
+ options: SwichOptions
37
+ ): HTMLElement
38
+ export function createSwitchOption(
39
+ icon: string,
40
+ text: string | SwichOptions,
41
+ options?: SwichOptions
32
42
  ): HTMLElement {
43
+ if (typeof text !== "string") {
44
+ return createSwitchOption(undefined, icon, text)
45
+ }
46
+
33
47
  const div = createElement("div", { class: "switch_option" })
48
+ if (icon) {
49
+ addElement(div, "img", { src: icon })
50
+ }
51
+
34
52
  addElement(div, "span", { textContent: text })
35
53
  div.append(createSwitch(options))
36
54
  return div
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browser-extension-settings",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Settings module for developing browser extensions and userscripts",
5
5
  "type": "module",
6
6
  "main": "./lib/index.ts",