@verbb/plugin-kit-core 2.0.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +46 -0
  4. package/dist/eslint/config.base.js +222 -0
  5. package/dist/eslint/config.react-hooks.js +45 -0
  6. package/dist/eslint/config.react-typescript.js +9 -0
  7. package/dist/eslint/config.react.js +10 -0
  8. package/dist/eslint/config.typescript-only.js +30 -0
  9. package/dist/eslint/config.typescript.js +7 -0
  10. package/dist/eslint/config.vite-react.js +5 -0
  11. package/dist/host/hostBridge.d.ts +40 -0
  12. package/dist/host/hostBridge.d.ts.map +1 -0
  13. package/dist/host/index.d.ts +3 -0
  14. package/dist/host/index.d.ts.map +1 -0
  15. package/dist/host/portal.d.ts +18 -0
  16. package/dist/host/portal.d.ts.map +1 -0
  17. package/dist/index.d.ts +3 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/plugin-kit-core.es.js +464 -0
  20. package/dist/plugin-kit-core.es.js.map +1 -0
  21. package/dist/plugin-kit-core.umd.js +528 -0
  22. package/dist/plugin-kit-core.umd.js.map +1 -0
  23. package/dist/prettier/config.mjs +10 -0
  24. package/dist/utils/collections.d.ts +79 -0
  25. package/dist/utils/collections.d.ts.map +1 -0
  26. package/dist/utils/forms.d.ts +27 -0
  27. package/dist/utils/forms.d.ts.map +1 -0
  28. package/dist/utils/handle.d.ts +17 -0
  29. package/dist/utils/handle.d.ts.map +1 -0
  30. package/dist/utils/index.d.ts +8 -0
  31. package/dist/utils/index.d.ts.map +1 -0
  32. package/dist/utils/markdown.d.ts +30 -0
  33. package/dist/utils/markdown.d.ts.map +1 -0
  34. package/dist/utils/promises.d.ts +13 -0
  35. package/dist/utils/promises.d.ts.map +1 -0
  36. package/dist/utils/query.d.ts +3 -0
  37. package/dist/utils/query.d.ts.map +1 -0
  38. package/dist/utils/string.d.ts +16 -0
  39. package/dist/utils/string.d.ts.map +1 -0
  40. package/package.json +57 -0
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Collections utility for managing client-side collections of models
3
+ */
4
+ /**
5
+ * Generates a unique client-side ID string
6
+ * @param {string} [prefix='client'] - Optional prefix for the generated ID
7
+ * @returns {string} A unique ID string in the format: prefix_timestamp_randomString
8
+ */
9
+ export declare const generateId: (prefix?: string) => string;
10
+ /**
11
+ * Normalize a collection by adding _id to each item that doesn't have one
12
+ * @param {Array} collection - Array of items
13
+ * @returns {Array} - Normalized collection with _id on each item
14
+ */
15
+ export declare const normalizeCollection: (collection?: any[]) => any[];
16
+ /**
17
+ * Create a new collection item
18
+ * @param {Object} itemData - Initial data for the new item
19
+ * @returns {Object} - The new item
20
+ */
21
+ export declare const createItem: (itemData?: any) => any;
22
+ /**
23
+ * Duplicate an existing item in a collection
24
+ * @param {Array} collection - Current collection
25
+ * @param {Object} item - Item to duplicate
26
+ * @param {Function} transformCallback - Optional callback to transform the duplicated item
27
+ * @returns {Object} - Updated collection with duplicated item
28
+ */
29
+ export declare const duplicateItem: (collection: any[] | undefined, item: any, transformCallback?: ((item: any) => any) | null) => any[];
30
+ /**
31
+ * Delete a item from a collection
32
+ * @param {Array} collection - Current collection
33
+ * @param {Object} item - Item to delete
34
+ * @returns {Object} - Updated collection without the deleted item
35
+ */
36
+ export declare const deleteItem: (collection: any[] | undefined, itemToDelete: any) => any[];
37
+ /**
38
+ * Update an item in a collection
39
+ * @param {Array} collection - Current collection
40
+ * @param {Object} item - Item to update
41
+ * @param {Object} updates - Updates to apply to the item
42
+ * @returns {Object} - Updated collection with updated item
43
+ */
44
+ export declare const updateItem: (collection: any[] | undefined, itemToUpdate: any, updates: any) => any[];
45
+ /**
46
+ * Move an item to a new position in a collection
47
+ * @param {Array} collection - Current collection
48
+ * @param {Object} fromItem - Item to move
49
+ * @param {Object} toItem - Item to move to (insert before this item)
50
+ * @returns {Array} - Updated collection with moved item
51
+ */
52
+ export declare const moveItem: (collection: any[] | undefined, fromItem: any, toItem: any) => any[];
53
+ /**
54
+ * Find an item in a collection by _id
55
+ * @param {Array} collection - Collection to search
56
+ * @param {string} _id - Client-side ID to find
57
+ * @returns {Object|null} - Found model or null
58
+ */
59
+ export declare const findItemById: (collection: any[] | undefined, _id: string) => any | null;
60
+ /**
61
+ * Get all items that have server-side IDs (existing items)
62
+ * @param {Array} collection - Collection to filter
63
+ * @returns {Array} - Items with server-side IDs
64
+ */
65
+ export declare const getExistingItems: (collection?: any[]) => any[];
66
+ /**
67
+ * Get all items that don't have server-side IDs (new items)
68
+ * @param {Array} collection - Collection to filter
69
+ * @returns {Array} - Items without server-side IDs
70
+ */
71
+ export declare const getNewItems: (collection?: any[]) => any[];
72
+ export declare const findRecursive: <T = any>(items: T[], predicate: (item: T) => boolean, optionsKey?: string) => T | null;
73
+ /**
74
+ * Creates a deep clone of a value using JSON serialization
75
+ * @param {any} value - The value to clone
76
+ * @returns {any} A deep clone of the input value, or undefined if input is undefined
77
+ */
78
+ export declare const clone: <T>(value: T) => T | undefined;
79
+ //# sourceMappingURL=collections.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../../src/utils/collections.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,eAAiB,KAAG,MAE9C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,aAAY,GAAG,EAAO,KAAG,GAAG,EAa/D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,WAAU,GAAQ,KAAG,GAK/C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GAAI,YAAY,GAAG,EAAE,YAAK,EAAE,MAAM,GAAG,EAAE,oBAAmB,CAAC,CAAC,IAAI,EAAE,GAAG,KAAK,GAAG,CAAC,GAAG,IAAW,KAAG,GAAG,EAY3H,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,YAAY,GAAG,EAAE,YAAK,EAAE,cAAc,GAAG,KAAG,GAAG,EAEzE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GAAI,YAAY,GAAG,EAAE,YAAK,EAAE,cAAc,GAAG,EAAE,SAAS,GAAG,KAAG,GAAG,EAYvF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,YAAY,GAAG,EAAE,YAAK,EAAE,UAAU,GAAG,EAAE,QAAQ,GAAG,KAAG,GAAG,EAiBhF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,YAAY,GAAG,EAAE,YAAK,EAAE,KAAK,MAAM,KAAG,GAAG,GAAG,IAExE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,aAAY,GAAG,EAAO,KAAG,GAAG,EAE5D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,aAAY,GAAG,EAAO,KAAG,GAAG,EAEvD,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,CAAC,GAAG,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,EAAE,mBAAsB,KAAG,CAAC,GAAG,IAkBhH,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,KAAK,GAAa,CAAC,EAAE,OAAO,CAAC,KAAG,CAAC,GAAG,SAMhD,CAAC"}
@@ -0,0 +1,27 @@
1
+ interface ErrorContent {
2
+ heading: string;
3
+ text: string;
4
+ trace: string;
5
+ traceAsString: string;
6
+ traceAsArray: string[];
7
+ }
8
+ interface ServerError {
9
+ response?: {
10
+ statusText?: string;
11
+ data?: {
12
+ message?: string;
13
+ error?: string;
14
+ file?: string;
15
+ line?: string;
16
+ trace?: Array<{
17
+ file?: string;
18
+ line?: string;
19
+ }>;
20
+ };
21
+ };
22
+ message?: string;
23
+ stack?: string;
24
+ }
25
+ export declare const getErrorMessage: (error: ServerError, maxTraceLines?: number) => ErrorContent;
26
+ export {};
27
+ //# sourceMappingURL=forms.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forms.d.ts","sourceRoot":"","sources":["../../src/utils/forms.ts"],"names":[],"mappings":"AAAA,UAAU,YAAY;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,UAAU,WAAW;IACjB,QAAQ,CAAC,EAAE;QACP,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,IAAI,CAAC,EAAE;YACH,OAAO,CAAC,EAAE,MAAM,CAAC;YACjB,KAAK,CAAC,EAAE,MAAM,CAAC;YACf,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,KAAK,CAAC,EAAE,KAAK,CAAC;gBACV,IAAI,CAAC,EAAE,MAAM,CAAC;gBACd,IAAI,CAAC,EAAE,MAAM,CAAC;aACjB,CAAC,CAAC;SACN,CAAC;KACL,CAAC;IACF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AA6ED,eAAO,MAAM,eAAe,GAAY,OAAO,WAAW,EAAE,gBAAe,MAAU,KAAG,YAUvF,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Resolve dynamic reserved handles from other field values (e.g. a sibling field whose
3
+ * value would collide once slugified).
4
+ */
5
+ export declare const getDynamicReservedHandles: (values: Record<string, unknown>, reservedFieldValues?: string[]) => string[];
6
+ /**
7
+ * Generate a unique handle from a human-readable source value, honouring reserved handles
8
+ * (static + dynamically derived from other field values) and an optional max length.
9
+ */
10
+ export declare const buildUniqueHandleFromSource: ({ sourceValue, values, reservedHandles, reservedFieldValues, maxLength, }: {
11
+ sourceValue: unknown;
12
+ values?: Record<string, unknown>;
13
+ reservedHandles?: string[];
14
+ reservedFieldValues?: string[];
15
+ maxLength?: number;
16
+ }) => string;
17
+ //# sourceMappingURL=handle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../../src/utils/handle.ts"],"names":[],"mappings":"AAkCA;;;GAGG;AACH,eAAO,MAAM,yBAAyB,GAClC,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,sBAAqB,MAAM,EAAO,KACnC,MAAM,EAgBR,CAAC;AAsDF;;;GAGG;AACH,eAAO,MAAM,2BAA2B,GAAI,2EAMzC;IACC,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB,KAAG,MAMH,CAAC"}
@@ -0,0 +1,8 @@
1
+ export * from './collections';
2
+ export * from './forms';
3
+ export * from './handle';
4
+ export * from './markdown';
5
+ export * from './promises';
6
+ export * from './query';
7
+ export * from './string';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Initialize markdown-it instance with secure defaults and common options
3
+ * - HTML is disabled for security
4
+ * - Links are auto-detected
5
+ * - Typography features like smart quotes are enabled
6
+ * - Line breaks are converted to <br> tags
7
+ */
8
+ declare const md: any;
9
+ /**
10
+ * Renders markdown content as block-level HTML
11
+ * Includes block elements like headers, paragraphs, lists etc.
12
+ *
13
+ * @param content - The markdown string to render
14
+ * @returns Rendered HTML string, or empty string if no content provided
15
+ */
16
+ export declare const renderMarkdown: (content: string) => string;
17
+ /**
18
+ * Renders markdown content as inline HTML only
19
+ * Excludes block-level elements, only processes inline markdown syntax
20
+ *
21
+ * @param content - The markdown string to render
22
+ * @returns Rendered HTML string, or empty string if no content provided
23
+ */
24
+ export declare const renderInlineMarkdown: (content: string) => string;
25
+ /**
26
+ * Export the configured markdown-it instance for direct usage
27
+ * Allows access to the full markdown-it API if needed
28
+ */
29
+ export { md };
30
+ //# sourceMappingURL=markdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/utils/markdown.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,QAAA,MAAM,EAAE,KAKN,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,KAAG,MAIhD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAAI,SAAS,MAAM,KAAG,MAItD,CAAC;AAEF;;;GAGG;AACH,OAAO,EAAE,EAAE,EAAE,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Creates a function that ensures a promise takes at least a minimum amount of time to resolve
3
+ *
4
+ * @param ms - The minimum time in milliseconds that the promise should take
5
+ * @returns A function that wraps a promise or promise-returning function
6
+ * @example
7
+ * ```ts
8
+ * const slowFetch = takeAtLeast(1000)(fetch('https://api.example.com'));
9
+ * // Will take at least 1 second even if the fetch is faster
10
+ * ```
11
+ */
12
+ export declare const takeAtLeast: (ms: number) => <T>(promiseOrFn: Promise<T> | (() => Promise<T>)) => Promise<T>;
13
+ //# sourceMappingURL=promises.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promises.d.ts","sourceRoot":"","sources":["../../src/utils/promises.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW,GAAY,IAAI,MAAM,MAQzB,CAAC,EAAE,aAAa,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CAc/E,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare const getQueryParam: (key: string) => string | null;
2
+ export declare const setQueryParam: (key: string, value: string) => void;
3
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/utils/query.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,IAGpD,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,KAAK,MAAM,EAAE,OAAO,MAAM,KAAG,IAI1D,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Convert a string to a handle format
3
+ * @param {string} sourceValue - The source string to convert
4
+ * @param {string} handleCasing - The casing format ('camelCase', 'pascal', 'snake', 'kebab')
5
+ * @param {boolean} allowNonAlphaStart - Whether to allow non-alphabetic characters at the start
6
+ * @returns {string} The generated handle
7
+ */
8
+ export declare const generateHandle: (sourceValue: string, handleCasing?: string, allowNonAlphaStart?: boolean) => string;
9
+ /**
10
+ * Find a unique handle by checking against reserved handles and adding suffixes
11
+ * @param {string} baseHandle - The base handle to check
12
+ * @param {Array} allReservedHandles - Array of all reserved handles to check against (static + dynamic)
13
+ * @returns {string} A unique handle
14
+ */
15
+ export declare const findUniqueHandle: (baseHandle: string, allReservedHandles?: string[]) => string;
16
+ //# sourceMappingURL=string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/utils/string.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,GAAY,aAAa,MAAM,EAAE,eAAc,MAAoB,EAAE,qBAAoB,OAAe,KAAG,MAyCrI,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,YAAY,MAAM,EAAE,qBAAoB,MAAM,EAAO,KAAG,MAaxF,CAAC"}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@verbb/plugin-kit-core",
3
+ "version": "2.0.0",
4
+ "type": "module",
5
+ "main": "dist/plugin-kit-core.es.js",
6
+ "module": "dist/plugin-kit-core.es.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "CHANGELOG.md",
11
+ "LICENSE.md"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/verbb/plugin-kit.git",
16
+ "directory": "plugin-kit-core"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/verbb/plugin-kit/issues"
20
+ },
21
+ "homepage": "https://docs.verbb.io/plugin-kit",
22
+ "engines": {
23
+ "node": ">=20.0.0"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/plugin-kit-core.es.js"
32
+ },
33
+ "./eslint/*": "./dist/eslint/*",
34
+ "./prettier/*": "./dist/prettier/*",
35
+ "./package.json": "./package.json"
36
+ },
37
+ "scripts": {
38
+ "build": "vite build",
39
+ "dev": "vite build --watch",
40
+ "lint": "eslint ."
41
+ },
42
+ "license": "MIT",
43
+ "dependencies": {
44
+ "@eslint/js": "^10.0.1",
45
+ "@typescript-eslint/eslint-plugin": "^8.59.0",
46
+ "@typescript-eslint/parser": "^8.59.0",
47
+ "eslint-plugin-react-hooks": "^7.1.1",
48
+ "globals": "^17.5.0",
49
+ "markdown-it": "^14.1.1"
50
+ },
51
+ "devDependencies": {
52
+ "eslint": "^10.2.1",
53
+ "typescript": "^6.0.3",
54
+ "vite": "^8.0.10",
55
+ "vite-plugin-dts": "^4.5.4"
56
+ }
57
+ }