ui-thing 0.0.22 → 0.0.24

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.
@@ -1,217 +1,217 @@
1
- export const DEFINE_SHORTCUT = `import { logicAnd, logicNot } from "@vueuse/math";
2
- import { computed, ref } from "vue";
3
- import type { ComputedRef, WatchSource } from "vue";
4
-
5
- export interface ShortcutConfig {
6
- handler: Function;
7
- usingInput?: string | boolean;
8
- whenever?: WatchSource<Boolean>[];
9
- }
10
-
11
- export interface ShortcutsConfig {
12
- [key: string]: ShortcutConfig | Function;
13
- }
14
-
15
- export interface ShortcutsOptions {
16
- chainDelay?: number;
17
- }
18
-
19
- interface Shortcut {
20
- handler: Function;
21
- condition: ComputedRef<Boolean>;
22
- chained: boolean;
23
- // KeyboardEvent attributes
24
- key: string;
25
- ctrlKey: boolean;
26
- metaKey: boolean;
27
- shiftKey: boolean;
28
- altKey: boolean;
29
- // code?: string
30
- // keyCode?: number
31
- }
32
-
33
- export const defineShortcuts = (config: ShortcutsConfig, options: ShortcutsOptions = {}) => {
34
- const { macOS, usingInput } = useShortcuts();
35
-
36
- let shortcuts: Shortcut[] = [];
37
-
38
- const chainedInputs = ref<any[]>([]);
39
- const clearChainedInput = () => {
40
- chainedInputs.value.splice(0, chainedInputs.value.length);
41
- };
42
- const debouncedClearChainedInput = useDebounceFn(clearChainedInput, options.chainDelay ?? 800);
43
-
44
- const onKeyDown = (e: KeyboardEvent) => {
45
- // Input autocomplete triggers a keydown event
46
- if (!e.key) {
47
- return;
48
- }
49
-
50
- const alphabeticalKey = /^[a-z]{1}$/i.test(e.key);
51
-
52
- let chainedKey;
53
- chainedInputs.value.push(e.key);
54
- // try matching a chained shortcut
55
- if (chainedInputs.value.length >= 2) {
56
- chainedKey = chainedInputs.value.slice(-2).join("-");
57
-
58
- for (const shortcut of shortcuts.filter((s) => s.chained)) {
59
- if (shortcut.key !== chainedKey) {
60
- continue;
61
- }
62
-
63
- if (shortcut.condition.value) {
64
- e.preventDefault();
65
- shortcut.handler();
66
- }
67
- clearChainedInput();
68
- return;
69
- }
70
- }
71
-
72
- // try matching a standard shortcut
73
- for (const shortcut of shortcuts.filter((s) => !s.chained)) {
74
- if (e.key.toLowerCase() !== shortcut.key) {
75
- continue;
76
- }
77
- if (e.metaKey !== shortcut.metaKey) {
78
- continue;
79
- }
80
- if (e.ctrlKey !== shortcut.ctrlKey) {
81
- continue;
82
- }
83
- // shift modifier is only checked in combination with alphabetical keys
84
- // (shift with non-alphabetical keys would change the key)
85
- if (alphabeticalKey && e.shiftKey !== shortcut.shiftKey) {
86
- continue;
87
- }
88
- // alt modifier changes the combined key anyways
89
- // if (e.altKey !== shortcut.altKey) { continue }
90
-
91
- if (shortcut.condition.value) {
92
- e.preventDefault();
93
- shortcut.handler();
94
- }
95
- clearChainedInput();
96
- return;
97
- }
98
-
99
- debouncedClearChainedInput();
100
- };
101
-
102
- // Map config to full detailled shortcuts
103
- shortcuts = Object.entries(config)
104
- .map(([key, shortcutConfig]) => {
105
- if (!shortcutConfig) {
106
- return null;
107
- }
108
-
109
- // Parse key and modifiers
110
- let shortcut: Partial<Shortcut>;
111
-
112
- if (key.includes("-") && key.includes("_")) {
113
- console.trace("[Shortcut] Invalid key");
114
- return null;
115
- }
116
-
117
- const chained = key.includes("-");
118
- if (chained) {
119
- shortcut = {
120
- key: key.toLowerCase(),
121
- metaKey: false,
122
- ctrlKey: false,
123
- shiftKey: false,
124
- altKey: false,
125
- };
126
- } else {
127
- const keySplit = key
128
- .toLowerCase()
129
- .split("_")
130
- .map((k) => k);
131
- shortcut = {
132
- key: keySplit.filter((k) => !["meta", "ctrl", "shift", "alt"].includes(k)).join("_"),
133
- metaKey: keySplit.includes("meta"),
134
- ctrlKey: keySplit.includes("ctrl"),
135
- shiftKey: keySplit.includes("shift"),
136
- altKey: keySplit.includes("alt"),
137
- };
138
- }
139
- shortcut.chained = chained;
140
-
141
- // Convert Meta to Ctrl for non-MacOS
142
- if (!macOS.value && shortcut.metaKey && !shortcut.ctrlKey) {
143
- shortcut.metaKey = false;
144
- shortcut.ctrlKey = true;
145
- }
146
-
147
- // Retrieve handler function
148
- if (typeof shortcutConfig === "function") {
149
- shortcut.handler = shortcutConfig;
150
- } else if (typeof shortcutConfig === "object") {
151
- shortcut = { ...shortcut, handler: shortcutConfig.handler };
152
- }
153
-
154
- if (!shortcut.handler) {
155
- console.trace("[Shortcut] Invalid value");
156
- return null;
157
- }
158
-
159
- // Create shortcut computed
160
- const conditions: ComputedRef<Boolean>[] = [];
161
- if (!(shortcutConfig as ShortcutConfig).usingInput) {
162
- conditions.push(logicNot(usingInput));
163
- } else if (typeof (shortcutConfig as ShortcutConfig).usingInput === "string") {
164
- conditions.push(
165
- computed(() => usingInput.value === (shortcutConfig as ShortcutConfig).usingInput)
166
- );
167
- }
168
- shortcut.condition = logicAnd(
169
- ...conditions,
170
- ...((shortcutConfig as ShortcutConfig).whenever || [])
171
- );
172
-
173
- return shortcut as Shortcut;
174
- })
175
- .filter(Boolean) as Shortcut[];
176
-
177
- useEventListener("keydown", onKeyDown);
178
- };
179
- `;
180
-
181
- export const USE_SHORTCUTS = `export const _useShortcuts = () => {
182
- const macOS = computed(
183
- () =>
184
- process.client && navigator && navigator.userAgent && navigator.userAgent.match(/Macintosh;/)
185
- );
186
-
187
- const metaSymbol = ref(" ");
188
-
189
- const activeElement = useActiveElement();
190
- const usingInput = computed(() => {
191
- const usingInput = !!(
192
- activeElement.value?.tagName === "INPUT" ||
193
- activeElement.value?.tagName === "TEXTAREA" ||
194
- activeElement.value?.contentEditable === "true"
195
- );
196
-
197
- if (usingInput) {
198
- return ((activeElement.value as any)?.name as string) || true;
199
- }
200
-
201
- return false;
202
- });
203
-
204
- onMounted(() => {
205
- metaSymbol.value = macOS.value ? "⌘" : "Ctrl";
206
- });
207
-
208
- return {
209
- macOS,
210
- metaSymbol,
211
- activeElement,
212
- usingInput,
213
- };
214
- };
215
-
216
- export const useShortcuts = createSharedComposable(_useShortcuts);
217
- `;
1
+ export const DEFINE_SHORTCUT = `import { logicAnd, logicNot } from "@vueuse/math";
2
+ import { computed, ref } from "vue";
3
+ import type { ComputedRef, WatchSource } from "vue";
4
+
5
+ export interface ShortcutConfig {
6
+ handler: Function;
7
+ usingInput?: string | boolean;
8
+ whenever?: WatchSource<Boolean>[];
9
+ }
10
+
11
+ export interface ShortcutsConfig {
12
+ [key: string]: ShortcutConfig | Function;
13
+ }
14
+
15
+ export interface ShortcutsOptions {
16
+ chainDelay?: number;
17
+ }
18
+
19
+ interface Shortcut {
20
+ handler: Function;
21
+ condition: ComputedRef<Boolean>;
22
+ chained: boolean;
23
+ // KeyboardEvent attributes
24
+ key: string;
25
+ ctrlKey: boolean;
26
+ metaKey: boolean;
27
+ shiftKey: boolean;
28
+ altKey: boolean;
29
+ // code?: string
30
+ // keyCode?: number
31
+ }
32
+
33
+ export const defineShortcuts = (config: ShortcutsConfig, options: ShortcutsOptions = {}) => {
34
+ const { macOS, usingInput } = useShortcuts();
35
+
36
+ let shortcuts: Shortcut[] = [];
37
+
38
+ const chainedInputs = ref<any[]>([]);
39
+ const clearChainedInput = () => {
40
+ chainedInputs.value.splice(0, chainedInputs.value.length);
41
+ };
42
+ const debouncedClearChainedInput = useDebounceFn(clearChainedInput, options.chainDelay ?? 800);
43
+
44
+ const onKeyDown = (e: KeyboardEvent) => {
45
+ // Input autocomplete triggers a keydown event
46
+ if (!e.key) {
47
+ return;
48
+ }
49
+
50
+ const alphabeticalKey = /^[a-z]{1}$/i.test(e.key);
51
+
52
+ let chainedKey;
53
+ chainedInputs.value.push(e.key);
54
+ // try matching a chained shortcut
55
+ if (chainedInputs.value.length >= 2) {
56
+ chainedKey = chainedInputs.value.slice(-2).join("-");
57
+
58
+ for (const shortcut of shortcuts.filter((s) => s.chained)) {
59
+ if (shortcut.key !== chainedKey) {
60
+ continue;
61
+ }
62
+
63
+ if (shortcut.condition.value) {
64
+ e.preventDefault();
65
+ shortcut.handler();
66
+ }
67
+ clearChainedInput();
68
+ return;
69
+ }
70
+ }
71
+
72
+ // try matching a standard shortcut
73
+ for (const shortcut of shortcuts.filter((s) => !s.chained)) {
74
+ if (e.key.toLowerCase() !== shortcut.key) {
75
+ continue;
76
+ }
77
+ if (e.metaKey !== shortcut.metaKey) {
78
+ continue;
79
+ }
80
+ if (e.ctrlKey !== shortcut.ctrlKey) {
81
+ continue;
82
+ }
83
+ // shift modifier is only checked in combination with alphabetical keys
84
+ // (shift with non-alphabetical keys would change the key)
85
+ if (alphabeticalKey && e.shiftKey !== shortcut.shiftKey) {
86
+ continue;
87
+ }
88
+ // alt modifier changes the combined key anyways
89
+ // if (e.altKey !== shortcut.altKey) { continue }
90
+
91
+ if (shortcut.condition.value) {
92
+ e.preventDefault();
93
+ shortcut.handler();
94
+ }
95
+ clearChainedInput();
96
+ return;
97
+ }
98
+
99
+ debouncedClearChainedInput();
100
+ };
101
+
102
+ // Map config to full detailled shortcuts
103
+ shortcuts = Object.entries(config)
104
+ .map(([key, shortcutConfig]) => {
105
+ if (!shortcutConfig) {
106
+ return null;
107
+ }
108
+
109
+ // Parse key and modifiers
110
+ let shortcut: Partial<Shortcut>;
111
+
112
+ if (key.includes("-") && key.includes("_")) {
113
+ console.trace("[Shortcut] Invalid key");
114
+ return null;
115
+ }
116
+
117
+ const chained = key.includes("-");
118
+ if (chained) {
119
+ shortcut = {
120
+ key: key.toLowerCase(),
121
+ metaKey: false,
122
+ ctrlKey: false,
123
+ shiftKey: false,
124
+ altKey: false,
125
+ };
126
+ } else {
127
+ const keySplit = key
128
+ .toLowerCase()
129
+ .split("_")
130
+ .map((k) => k);
131
+ shortcut = {
132
+ key: keySplit.filter((k) => !["meta", "ctrl", "shift", "alt"].includes(k)).join("_"),
133
+ metaKey: keySplit.includes("meta"),
134
+ ctrlKey: keySplit.includes("ctrl"),
135
+ shiftKey: keySplit.includes("shift"),
136
+ altKey: keySplit.includes("alt"),
137
+ };
138
+ }
139
+ shortcut.chained = chained;
140
+
141
+ // Convert Meta to Ctrl for non-MacOS
142
+ if (!macOS.value && shortcut.metaKey && !shortcut.ctrlKey) {
143
+ shortcut.metaKey = false;
144
+ shortcut.ctrlKey = true;
145
+ }
146
+
147
+ // Retrieve handler function
148
+ if (typeof shortcutConfig === "function") {
149
+ shortcut.handler = shortcutConfig;
150
+ } else if (typeof shortcutConfig === "object") {
151
+ shortcut = { ...shortcut, handler: shortcutConfig.handler };
152
+ }
153
+
154
+ if (!shortcut.handler) {
155
+ console.trace("[Shortcut] Invalid value");
156
+ return null;
157
+ }
158
+
159
+ // Create shortcut computed
160
+ const conditions: ComputedRef<Boolean>[] = [];
161
+ if (!(shortcutConfig as ShortcutConfig).usingInput) {
162
+ conditions.push(logicNot(usingInput));
163
+ } else if (typeof (shortcutConfig as ShortcutConfig).usingInput === "string") {
164
+ conditions.push(
165
+ computed(() => usingInput.value === (shortcutConfig as ShortcutConfig).usingInput)
166
+ );
167
+ }
168
+ shortcut.condition = logicAnd(
169
+ ...conditions,
170
+ ...((shortcutConfig as ShortcutConfig).whenever || [])
171
+ );
172
+
173
+ return shortcut as Shortcut;
174
+ })
175
+ .filter(Boolean) as Shortcut[];
176
+
177
+ useEventListener("keydown", onKeyDown);
178
+ };
179
+ `;
180
+
181
+ export const USE_SHORTCUTS = `export const _useShortcuts = () => {
182
+ const macOS = computed(
183
+ () =>
184
+ process.client && navigator && navigator.userAgent && navigator.userAgent.match(/Macintosh;/)
185
+ );
186
+
187
+ const metaSymbol = ref(" ");
188
+
189
+ const activeElement = useActiveElement();
190
+ const usingInput = computed(() => {
191
+ const usingInput = !!(
192
+ activeElement.value?.tagName === "INPUT" ||
193
+ activeElement.value?.tagName === "TEXTAREA" ||
194
+ activeElement.value?.contentEditable === "true"
195
+ );
196
+
197
+ if (usingInput) {
198
+ return ((activeElement.value as any)?.name as string) || true;
199
+ }
200
+
201
+ return false;
202
+ });
203
+
204
+ onMounted(() => {
205
+ metaSymbol.value = macOS.value ? "⌘" : "Ctrl";
206
+ });
207
+
208
+ return {
209
+ macOS,
210
+ metaSymbol,
211
+ activeElement,
212
+ usingInput,
213
+ };
214
+ };
215
+
216
+ export const useShortcuts = createSharedComposable(_useShortcuts);
217
+ `;
package/src/types.ts CHANGED
@@ -15,9 +15,9 @@ export type InitOptions = { force?: boolean };
15
15
  export type Component = {
16
16
  name: string;
17
17
  value: string;
18
- deps: string[];
19
- devDeps: string[];
20
- nuxtModules: string[];
18
+ deps?: string[];
19
+ devDeps?: string[];
20
+ nuxtModules?: string[];
21
21
  instructions?: string[];
22
22
  files: Composable[];
23
23
  utils: Composable[];
@@ -1,8 +1,8 @@
1
- import axios from "axios";
2
-
3
- import { Component } from "../types";
4
-
5
- export const fetchComponents = async () => {
6
- const { data } = await axios.get<Component[]>("https://ui-thing.behonbaker.com/api/components");
7
- return data;
8
- };
1
+ import axios from "axios";
2
+
3
+ import { Component } from "../types";
4
+
5
+ export const fetchComponents = async () => {
6
+ const { data } = await axios.get<Component[]>("https://ui-thing.behonbaker.com/api/components");
7
+ return data;
8
+ };
@@ -1,7 +1,28 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
1
3
  import { execa } from "execa";
2
4
  import _ from "lodash";
3
5
  import ora from "ora";
4
6
 
7
+ function checkPackageJson() {
8
+ const packageJsonPath = path.join(process.cwd(), "package.json");
9
+ let scriptExists = false;
10
+
11
+ // Check if package.json file exists
12
+ if (fs.existsSync(packageJsonPath)) {
13
+ // Read the package.json file
14
+ const packageJsonContent = fs.readFileSync(packageJsonPath, "utf-8");
15
+ const packageJson = JSON.parse(packageJsonContent);
16
+
17
+ // Check if "postinstall" script is defined
18
+ const postinstallScript = packageJson.scripts?.postinstall;
19
+ if (postinstallScript) {
20
+ scriptExists = true;
21
+ }
22
+ }
23
+ return scriptExists;
24
+ }
25
+
5
26
  export const installPackages = async (
6
27
  packageManager: string,
7
28
  deps?: string[] | string,
@@ -22,7 +43,13 @@ export const installPackages = async (
22
43
  if (!_.isUndefined(devDeps) && !_.isEmpty(devDeps)) {
23
44
  await execa(packageManager, [packageManager === "yarn" ? "add" : "install", "-D", ...devDeps]);
24
45
  }
25
- await execa(packageManager, ["run", "postinstall"]);
46
+
47
+ // Check if package.json file exists
48
+ if (checkPackageJson()) {
49
+ // we should check to see if there is a postinstall script and run it
50
+ depsSpinner.text = "Running postinstall script...";
51
+ await execa(packageManager, ["run", "postinstall"]);
52
+ }
26
53
 
27
54
  depsSpinner.succeed("Installed dependencies!");
28
55
  };
@@ -1,19 +1,19 @@
1
- import ora from "ora";
2
- import prompts from "prompts";
3
-
4
- import allComponents from "../comps";
5
- import { Component } from "../types";
6
-
7
- export const promptUserForComponents = async (): Promise<string[]> => {
8
- const { components } = await prompts({
9
- type: "autocompleteMultiselect",
10
- name: "components",
11
- message: "Select the components you want to add",
12
- choices: allComponents.map((c: Component) => ({ title: c.name, value: c.value })),
13
- onRender(kleur) {
14
- // @ts-ignore
15
- this.msg = kleur.bgCyan(" Choose components ") + " Select the components you want to add";
16
- },
17
- });
18
- return components;
19
- };
1
+ import ora from "ora";
2
+ import prompts from "prompts";
3
+
4
+ import allComponents from "../comps";
5
+ import { Component } from "../types";
6
+
7
+ export const promptUserForComponents = async (): Promise<string[]> => {
8
+ const { components } = await prompts({
9
+ type: "autocompleteMultiselect",
10
+ name: "components",
11
+ message: "Select the components you want to add",
12
+ choices: allComponents.map((c: Component) => ({ title: c.name, value: c.value })),
13
+ onRender(kleur) {
14
+ // @ts-ignore
15
+ this.msg = kleur.bgCyan(" Choose components ") + " Select the components you want to add";
16
+ },
17
+ });
18
+ return components;
19
+ };