@witchcraft/layout 0.0.7 → 0.1.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/README.md CHANGED
@@ -42,38 +42,39 @@ export {}
42
42
 
43
43
  ```
44
44
 
45
- Or if using zod, you can do something like this. Note that you will need to create/extend `zLayoutWindow/Frame` or use `zLayoutWindow/FramePassthrough` to allow for extra properties. All zod types have been made `strict` where possible as it's easy to accidentally use the wrong type and loose properties silently otherwise.
46
-
45
+ Or if using zod, you can do something like this. Note that you will need to create/extend `zLayoutWindow/Frame` or use `zLayoutWindow/FrameLoose` to allow for extra properties. They also use a basic `z.uuid()`, if you need something more specific you'll have to extend the type.
47
46
  ```ts
48
- import { zLayoutFramePassthrough, layoutCreate } from "@witchcraft/layout"
47
+ import { zLayoutFrameLoose, layoutCreate } from "@witchcraft/layout"
49
48
  import { z } from "zod"
50
49
 
51
50
  // we remove the id to set the discriminated union, then add it back,
52
51
  // otherwise this doesn't work
53
52
  export const zAppFrame = z.discriminatedUnion("type", [
54
- zLayoutFramePassthrough.extend({
53
+ zLayoutFrameLoose.extend({
55
54
  type: z.literal("contentA"),
56
55
  content: z.object({
57
56
  id: z.optional(z.uuid()),
58
57
  }),
59
58
  }),
60
- zLayoutFramePassthrough.extend({
59
+ zLayoutFrameLoose.extend({
61
60
  type: z.literal("contentB"),
62
61
  content: z.object({
63
62
  someOtherKey: z.optional(z.uuid()),
64
63
  }),
65
64
  }),
66
65
  ]).and(z.object({
67
- id: z.uuid(),
66
+ id: z.uuidv4(), // here we can specify a specific uuid type
68
67
  }))
69
68
 
69
+
70
70
  declare module "@witchcraft/layout" {
71
71
  interface Register {
72
- // Register the type
72
+ // Register the type, this allows importing the type from the package, while also allowing the types to be extended
73
73
  ExtendedLayoutFrame: z.infer<typeof zAppFrame>
74
74
  }
75
75
  }
76
76
  ```
77
+ Note that `zFrameId` and `zWinId` are different as they also support constants (`zFrameIdConstants` and `zWindowIdConstants`).
77
78
 
78
79
  ## Basics
79
80
 
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@witchcraft/layout",
3
3
  "configKey": "witchcraftLayout",
4
- "version": "0.0.7",
4
+ "version": "0.1.1",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { defineNuxtModule, createResolver, addComponentsDir, addTemplate } from '@nuxt/kit';
2
2
  export * from '../dist/runtime/index.js';
3
3
 
4
- const module = defineNuxtModule({
4
+ const module$1 = defineNuxtModule({
5
5
  meta: {
6
6
  name: "@witchcraft/layout",
7
7
  configKey: "witchcraftLayout"
@@ -23,4 +23,4 @@ const module = defineNuxtModule({
23
23
  }
24
24
  });
25
25
 
26
- export { module as default };
26
+ export { module$1 as default };
@@ -127,7 +127,7 @@ export declare const zLayoutFrame: z.ZodObject<{
127
127
  x: z.ZodNumber;
128
128
  y: z.ZodNumber;
129
129
  }, z.core.$loose>;
130
- export declare const zLayoutFramePassthrough: z.ZodObject<{
130
+ export declare const zLayoutFrameLoose: z.ZodObject<{
131
131
  id: z.ZodUUID;
132
132
  width: z.ZodNumber;
133
133
  height: z.ZodNumber;
@@ -167,8 +167,8 @@ export declare const zLayoutWindow: z.ZodObject<{
167
167
  pxHeight: z.ZodNumber;
168
168
  pxX: z.ZodNumber;
169
169
  pxY: z.ZodNumber;
170
- }, z.core.$strict>;
171
- export declare const zLayoutWindowPassthrough: z.ZodObject<{
170
+ }, z.core.$strip>;
171
+ export declare const zLayoutWindowLoose: z.ZodObject<{
172
172
  id: z.ZodUUID;
173
173
  activeFrame: z.ZodOptional<z.ZodString>;
174
174
  frames: z.ZodRecord<z.ZodString, z.ZodObject<{
@@ -182,7 +182,7 @@ export declare const zLayoutWindowPassthrough: z.ZodObject<{
182
182
  pxHeight: z.ZodNumber;
183
183
  pxX: z.ZodNumber;
184
184
  pxY: z.ZodNumber;
185
- }, z.core.$strip>;
185
+ }, z.core.$loose>;
186
186
  export type BaseLayoutWindow = {
187
187
  id: WindowId;
188
188
  activeFrame?: string;
@@ -204,7 +204,7 @@ export declare const zWorkspace: z.ZodObject<{
204
204
  y: z.ZodNumber;
205
205
  }, z.core.$loose>>;
206
206
  }, z.core.$strict>;
207
- export declare const zWorkspacePassthrough: z.ZodObject<{
207
+ export declare const zWorkspaceLoose: z.ZodObject<{
208
208
  activeFrame: z.ZodOptional<z.ZodString>;
209
209
  frames: z.ZodRecord<z.ZodString, z.ZodObject<{
210
210
  id: z.ZodUUID;
@@ -231,8 +231,8 @@ export declare const zLayout: z.ZodObject<{
231
231
  pxHeight: z.ZodNumber;
232
232
  pxX: z.ZodNumber;
233
233
  pxY: z.ZodNumber;
234
- }, z.core.$strict>>;
235
- }, z.core.$strict>;
234
+ }, z.core.$strip>>;
235
+ }, z.core.$strip>;
236
236
  export declare const zInitializedLayout: z.ZodObject<{
237
237
  activeWindow: z.ZodNonOptional<z.ZodOptional<z.ZodString>>;
238
238
  windows: z.ZodRecord<z.ZodString, z.ZodObject<{
@@ -249,8 +249,8 @@ export declare const zInitializedLayout: z.ZodObject<{
249
249
  pxHeight: z.ZodNumber;
250
250
  pxX: z.ZodNumber;
251
251
  pxY: z.ZodNumber;
252
- }, z.core.$strict>>;
253
- }, z.core.$strict>;
252
+ }, z.core.$strip>>;
253
+ }, z.core.$strip>;
254
254
  export type Layout = ExtendedLayout & {
255
255
  activeWindow?: string;
256
256
  windows: LayoutWindows;
@@ -381,9 +381,8 @@ export declare const LAYOUT_ERROR: {
381
381
  CANT_CLOSE_WITHOUT_FORCE: "CANT_CLOSE_WITHOUT_FORCE";
382
382
  };
383
383
  export type LayoutError = EnumLike<typeof LAYOUT_ERROR>;
384
- export type AllErrors = LayoutError;
385
- export type ErrorInfo<T extends AllErrors> = AllErrorsInfo[T] extends undefined ? never : AllErrorsInfo[T];
386
- type AllErrorsInfo = {
384
+ export type LayoutErrorInfo<T extends LayoutError> = LayoutErrorsInfo[T] extends undefined ? never : LayoutErrorsInfo[T];
385
+ export type LayoutErrorsInfo = {
387
386
  [LAYOUT_ERROR.INVALID_ID]: {
388
387
  id: string | undefined;
389
388
  };
@@ -431,7 +430,7 @@ export declare const zWindowCreate: z.ZodObject<{
431
430
  x: z.ZodNumber;
432
431
  y: z.ZodNumber;
433
432
  }, z.core.$loose>>>;
434
- }, z.core.$strip>;
433
+ }, z.core.$loose>;
435
434
  export declare const zLayoutCreate: z.ZodObject<{
436
435
  activeWindow: z.ZodOptional<z.ZodString>;
437
436
  windows: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
@@ -448,7 +447,7 @@ export declare const zLayoutCreate: z.ZodObject<{
448
447
  pxHeight: z.ZodNumber;
449
448
  pxX: z.ZodNumber;
450
449
  pxY: z.ZodNumber;
451
- }, z.core.$strict>>>;
450
+ }, z.core.$strip>>>;
452
451
  }, z.core.$loose>;
453
452
  export declare const zFrameCreate: z.ZodObject<{
454
453
  id: z.ZodOptional<z.ZodUUID>;
@@ -44,22 +44,22 @@ export const zBaseSquare = zSize.extend(zPos.shape);
44
44
  export const zLayoutFrame = z.looseObject({
45
45
  id: z.uuid()
46
46
  }).extend(zBaseSquare.shape);
47
- export const zLayoutFramePassthrough = zLayoutFrame.passthrough();
47
+ export const zLayoutFrameLoose = zLayoutFrame.loose();
48
48
  const baseLayoutWindow = z.object({
49
49
  id: z.uuid(),
50
50
  activeFrame: z.string().optional(),
51
51
  frames: z.record(z.string(), zLayoutFrame)
52
52
  }).extend(zPxSize.shape).extend(zPxPos.shape);
53
- export const zLayoutWindow = baseLayoutWindow.strict();
54
- export const zLayoutWindowPassthrough = baseLayoutWindow;
53
+ export const zLayoutWindow = baseLayoutWindow;
54
+ export const zLayoutWindowLoose = baseLayoutWindow.loose();
55
55
  const baseWorkspace = zLayoutWindow.pick({ activeFrame: true, frames: true });
56
56
  export const zWorkspace = baseWorkspace.strict();
57
- export const zWorkspacePassthrough = zWorkspace.passthrough();
58
- const baseLayout = z.looseObject({
57
+ export const zWorkspaceLoose = zWorkspace.loose();
58
+ const baseLayout = z.object({
59
59
  activeWindow: z.string().optional(),
60
60
  windows: z.record(z.string(), zLayoutWindow)
61
61
  });
62
- export const zLayout = baseLayout.strict();
62
+ export const zLayout = baseLayout;
63
63
  export const zInitializedLayout = zLayout.required({
64
64
  activeWindow: true
65
65
  }).refine((layout) => {
@@ -107,8 +107,8 @@ export const LAYOUT_ERROR = enumFromArray([
107
107
  "CANT_SPLIT_FRAME_TOO_SMALL",
108
108
  "CANT_CLOSE_WITHOUT_FORCE"
109
109
  ]);
110
- export const zWindowCreate = zLayoutWindowPassthrough.partial({ id: true, pxWidth: true, pxHeight: true, pxX: true, pxY: true }).extend({ frames: zLayoutWindow.shape.frames.optional() });
111
- export const zLayoutCreate = baseLayout.extend({
110
+ export const zWindowCreate = zLayoutWindowLoose.partial({ id: true, pxWidth: true, pxHeight: true, pxX: true, pxY: true }).extend({ frames: zLayoutWindow.shape.frames.optional() });
111
+ export const zLayoutCreate = baseLayout.loose().extend({
112
112
  windows: zLayout.shape.windows.optional()
113
113
  });
114
114
  export const zFrameCreate = zLayoutFrame.partial({
@@ -1,9 +1,9 @@
1
- import type { AllErrors, ErrorInfo } from "../types/index.js";
1
+ import type { LayoutError, LayoutErrorInfo } from "../types/index.js";
2
2
  /**
3
3
  * Creates a known error that extends the base Error with some extra information.
4
4
  * All the variables used to create the error message are stored in it's info property so we can easily re-craft error messages for users.
5
5
  */
6
- export declare class KnownError<T extends AllErrors = AllErrors, TInfo extends ErrorInfo<T> = ErrorInfo<T>> extends Error {
6
+ export declare class KnownError<T extends LayoutError = LayoutError, TInfo extends LayoutErrorInfo<T> = LayoutErrorInfo<T>> extends Error {
7
7
  code: T;
8
8
  info: TInfo;
9
9
  constructor(code: T, str: string, info: TInfo);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@witchcraft/layout",
3
3
  "description": "Headless layout manager.",
4
- "version": "0.0.7",
4
+ "version": "0.1.1",
5
5
  "main": "./dist/runtime/index.js",
6
6
  "type": "module",
7
7
  "sideEffects": false,
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "peerDependencies": {
36
36
  "@witchcraft/nuxt-utils": "^0.3.6",
37
- "@witchcraft/ui": "^0.3.7"
37
+ "@witchcraft/ui": "^0.3.13"
38
38
  },
39
39
  "peerDependenciesMeta": {
40
40
  "@witchcraft/ui": {
@@ -61,7 +61,7 @@
61
61
  "@vitejs/plugin-vue": "^6.0.1",
62
62
  "@vitest/coverage-c8": "^0.33.0",
63
63
  "@witchcraft/nuxt-utils": "^0.3.6",
64
- "@witchcraft/ui": "^0.3.7",
64
+ "@witchcraft/ui": "^0.3.13",
65
65
  "concurrently": "^9.2.1",
66
66
  "cross-env": "^10.0.0",
67
67
  "fast-glob": "^3.3.3",
@@ -69,7 +69,7 @@
69
69
  "husky": "^9.1.7",
70
70
  "indexit": "2.1.0-beta.3",
71
71
  "madge": "^8.0.0",
72
- "nuxt": "^4.1.2",
72
+ "nuxt": "^4.2.1",
73
73
  "onchange": "^7.1.0",
74
74
  "semantic-release": "^24.2.8",
75
75
  "tailwindcss": "^4.1.12",
@@ -113,7 +113,7 @@ export const zLayoutFrame = z.looseObject({
113
113
  id: z.uuid()
114
114
  }).extend(zBaseSquare.shape)
115
115
 
116
- export const zLayoutFramePassthrough = zLayoutFrame.passthrough()
116
+ export const zLayoutFrameLoose = zLayoutFrame.loose()
117
117
 
118
118
  export interface Register {
119
119
  }
@@ -135,8 +135,8 @@ const baseLayoutWindow = z.object({
135
135
  }).extend(zPxSize.shape)
136
136
  .extend(zPxPos.shape)
137
137
 
138
- export const zLayoutWindow = baseLayoutWindow.strict()
139
- export const zLayoutWindowPassthrough = baseLayoutWindow
138
+ export const zLayoutWindow = baseLayoutWindow
139
+ export const zLayoutWindowLoose = baseLayoutWindow.loose()
140
140
  // types are re-declared so that if they are extended, the types are still correct
141
141
 
142
142
  export type BaseLayoutWindow = {
@@ -153,16 +153,16 @@ export type LayoutWindows = Record<string, LayoutWindow>
153
153
 
154
154
  const baseWorkspace = zLayoutWindow.pick({ activeFrame: true, frames: true })
155
155
  export const zWorkspace = baseWorkspace.strict()
156
- export const zWorkspacePassthrough = zWorkspace.passthrough()
156
+ export const zWorkspaceLoose = zWorkspace.loose()
157
157
 
158
158
  export type Workspace = Pick<LayoutWindow, "activeFrame" | "frames"> & ExtendedWorkspace
159
159
 
160
- const baseLayout = z.looseObject({
160
+ const baseLayout = z.object({
161
161
  activeWindow: z.string().optional(),
162
162
  windows: z.record(z.string(), zLayoutWindow)
163
163
  })
164
164
 
165
- export const zLayout = baseLayout.strict()
165
+ export const zLayout = baseLayout
166
166
 
167
167
  export const zInitializedLayout = zLayout.required({
168
168
  activeWindow: true
@@ -234,11 +234,9 @@ export const LAYOUT_ERROR = enumFromArray([
234
234
 
235
235
  export type LayoutError = EnumLike<typeof LAYOUT_ERROR>
236
236
 
237
- export type AllErrors = LayoutError
237
+ export type LayoutErrorInfo<T extends LayoutError> = LayoutErrorsInfo[T] extends undefined ? never : LayoutErrorsInfo[T]
238
238
 
239
- export type ErrorInfo<T extends AllErrors> = AllErrorsInfo[T] extends undefined ? never : AllErrorsInfo[T]
240
-
241
- type AllErrorsInfo = {
239
+ export type LayoutErrorsInfo = {
242
240
  [LAYOUT_ERROR.INVALID_ID]: {
243
241
  id: string | undefined
244
242
  }
@@ -275,11 +273,11 @@ type AllErrorsInfo = {
275
273
  // todo rename to toOpposite
276
274
  export type HasOpposite = Direction | EdgeSide | ExtendedDirection | ExtendedEdgeSide | keyof Point | keyof Size
277
275
 
278
- export const zWindowCreate = zLayoutWindowPassthrough
276
+ export const zWindowCreate = zLayoutWindowLoose
279
277
  .partial({ id: true, pxWidth: true, pxHeight: true, pxX: true, pxY: true })
280
278
  .extend({ frames: zLayoutWindow.shape.frames.optional() })
281
279
 
282
- export const zLayoutCreate = baseLayout
280
+ export const zLayoutCreate = baseLayout.loose()
283
281
  .extend({
284
282
  windows: zLayout.shape.windows.optional()
285
283
  })
@@ -1,12 +1,12 @@
1
- import type { AllErrors, ErrorInfo } from "../types/index.js"
1
+ import type { LayoutError, LayoutErrorInfo } from "../types/index.js"
2
2
 
3
3
  /**
4
4
  * Creates a known error that extends the base Error with some extra information.
5
5
  * All the variables used to create the error message are stored in it's info property so we can easily re-craft error messages for users.
6
6
  */
7
7
  export class KnownError<
8
- T extends AllErrors = AllErrors,
9
- TInfo extends ErrorInfo<T> = ErrorInfo<T>
8
+ T extends LayoutError = LayoutError,
9
+ TInfo extends LayoutErrorInfo<T> = LayoutErrorInfo<T>
10
10
  > extends Error {
11
11
  code: T
12
12