@ainsleydev/payload-helper 0.0.8 → 0.0.9

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 (66) hide show
  1. package/dist/cli/bin.d.ts +2 -0
  2. package/dist/cli/bin.js +17 -0
  3. package/dist/cli/bin.js.map +1 -0
  4. package/dist/cli/types.d.ts +4 -0
  5. package/dist/cli/types.js +34 -0
  6. package/dist/cli/types.js.map +1 -0
  7. package/dist/collections/Media.d.ts +10 -0
  8. package/dist/collections/Media.js +150 -0
  9. package/dist/collections/Media.js.map +1 -0
  10. package/dist/collections/Redirects.d.ts +10 -0
  11. package/dist/collections/Redirects.js +72 -0
  12. package/dist/collections/Redirects.js.map +1 -0
  13. package/dist/common/SEO.d.ts +6 -0
  14. package/dist/common/SEO.js +45 -0
  15. package/dist/common/SEO.js.map +1 -0
  16. package/dist/endpoints/slug.d.ts +7 -0
  17. package/dist/endpoints/slug.js +38 -0
  18. package/dist/endpoints/slug.js.map +1 -0
  19. package/dist/globals/Navigation.d.ts +28 -0
  20. package/dist/globals/Navigation.js +138 -0
  21. package/dist/globals/Navigation.js.map +1 -0
  22. package/dist/globals/Settings.d.ts +10 -0
  23. package/dist/globals/Settings.js +346 -0
  24. package/dist/globals/Settings.js.map +1 -0
  25. package/dist/globals/countries.d.ts +1 -0
  26. package/dist/globals/countries.js +198 -0
  27. package/dist/globals/countries.js.map +1 -0
  28. package/dist/globals/locales.d.ts +7 -0
  29. package/dist/globals/locales.js +2664 -0
  30. package/dist/globals/locales.js.map +1 -0
  31. package/dist/index.d.ts +9 -0
  32. package/dist/index.js +23 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/plugin/schema.d.ts +21 -0
  35. package/dist/plugin/schema.js +239 -0
  36. package/dist/plugin/schema.js.map +1 -0
  37. package/dist/seed/down.d.ts +13 -0
  38. package/dist/seed/down.js +35 -0
  39. package/dist/seed/down.js.map +1 -0
  40. package/dist/seed/seed.d.ts +31 -0
  41. package/dist/seed/seed.js +58 -0
  42. package/dist/seed/seed.js.map +1 -0
  43. package/dist/seed/types.d.ts +125 -0
  44. package/dist/seed/types.js +3 -0
  45. package/dist/seed/types.js.map +1 -0
  46. package/dist/seed/up.d.ts +23 -0
  47. package/dist/seed/up.js +55 -0
  48. package/dist/seed/up.js.map +1 -0
  49. package/dist/types.d.ts +10 -0
  50. package/dist/types.js +4 -0
  51. package/dist/types.js.map +1 -0
  52. package/dist/util/env.d.ts +12 -0
  53. package/dist/util/env.js +75 -0
  54. package/dist/util/env.js.map +1 -0
  55. package/dist/util/fields.d.ts +7 -0
  56. package/dist/util/fields.js +12 -0
  57. package/dist/util/fields.js.map +1 -0
  58. package/dist/util/lexical.d.ts +15 -0
  59. package/dist/util/lexical.js +115 -0
  60. package/dist/util/lexical.js.map +1 -0
  61. package/dist/util/lexical.test.js +21 -0
  62. package/dist/util/lexical.test.js.map +1 -0
  63. package/dist/util/validation.d.ts +2 -0
  64. package/dist/util/validation.js +23 -0
  65. package/dist/util/validation.js.map +1 -0
  66. package/package.json +2 -2
@@ -0,0 +1,58 @@
1
+ import dotenv from 'dotenv';
2
+ import { commitTransaction, getPayload, initTransaction, killTransaction } from 'payload';
3
+ import { importConfig } from 'payload/node';
4
+ import { down } from './down.js';
5
+ import { up } from './up.js';
6
+ export var DBAdapter;
7
+ (function(DBAdapter) {
8
+ DBAdapter["Postgres"] = "postgres";
9
+ })(DBAdapter || (DBAdapter = {}));
10
+ /**
11
+ * Seeds the database with initial data.
12
+ *
13
+ * @param opts - The options for seeding.
14
+ * @returns A promise that resolves when the seeding is complete.
15
+ */ export const seed = (opts)=>{
16
+ const fn = async ()=>{
17
+ dotenv.config({
18
+ path: opts.envPath
19
+ });
20
+ for (const fn of [
21
+ down,
22
+ up
23
+ ]){
24
+ if (fn === down) {
25
+ process.env.PAYLOAD_DROP_DATABASE = 'true';
26
+ } else {
27
+ delete process.env.PAYLOAD_DROP_DATABASE; // Ensure it is not set for other functions
28
+ }
29
+ const config = await importConfig(opts.configPath);
30
+ const payload = await getPayload({
31
+ config
32
+ });
33
+ const req = {
34
+ payload
35
+ };
36
+ await initTransaction(req);
37
+ try {
38
+ await fn({
39
+ payload,
40
+ req,
41
+ seeder: opts.seeder
42
+ });
43
+ payload.logger.info('Seed complete');
44
+ await commitTransaction(req);
45
+ } catch (err) {
46
+ const message = err instanceof Error ? err.message : 'Unknown error';
47
+ payload.logger.error(`Seed failed: ${message}`);
48
+ await killTransaction(req);
49
+ }
50
+ }
51
+ };
52
+ fn().then(()=>process.exit(0)).catch((e)=>{
53
+ console.error(e);
54
+ process.exit(1);
55
+ });
56
+ };
57
+
58
+ //# sourceMappingURL=seed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/seed/seed.ts"],"sourcesContent":["import dotenv from 'dotenv';\nimport {\n\ttype Payload,\n\ttype PayloadRequest,\n\tcommitTransaction,\n\tgetPayload,\n\tinitTransaction,\n\tkillTransaction,\n} from 'payload';\nimport { importConfig } from 'payload/node';\nimport { down } from './down.js';\nimport { up } from './up.js';\n\n/**\n * A function that seeds the database with initial data.\n */\nexport type Seeder = (args: { payload: Payload; req: PayloadRequest }) => Promise<void>;\n\n/**\n * Options for the seed function.\n * Note: You must use path.resolve for the paths, i.e. path.resolve(__dirname, 'path/to/file')\n */\nexport type SeedOptions = {\n\tenvPath: string;\n\tconfigPath: string;\n\tdbAdapter: DBAdapter;\n\tseeder: Seeder;\n};\n\n/**\n * The database adapter to use, which will remove and recreate the database.\n */\nexport enum DBAdapter {\n\tPostgres = 'postgres',\n}\n\n/**\n * Seeds the database with initial data.\n *\n * @param opts - The options for seeding.\n * @returns A promise that resolves when the seeding is complete.\n */\nexport const seed = (opts: SeedOptions) => {\n\tconst fn = async () => {\n\t\tdotenv.config({\n\t\t\tpath: opts.envPath,\n\t\t});\n\n\t\tfor (const fn of [down, up]) {\n\t\t\tif (fn === down) {\n\t\t\t\tprocess.env.PAYLOAD_DROP_DATABASE = 'true';\n\t\t\t} else {\n\t\t\t\tdelete process.env.PAYLOAD_DROP_DATABASE; // Ensure it is not set for other functions\n\t\t\t}\n\n\t\t\tconst config = await importConfig(opts.configPath);\n\t\t\tconst payload = await getPayload({ config });\n\t\t\tconst req = { payload } as PayloadRequest;\n\n\t\t\tawait initTransaction(req);\n\n\t\t\ttry {\n\t\t\t\tawait fn({ payload, req, seeder: opts.seeder });\n\t\t\t\tpayload.logger.info('Seed complete');\n\t\t\t\tawait commitTransaction(req);\n\t\t\t} catch (err) {\n\t\t\t\tconst message = err instanceof Error ? err.message : 'Unknown error';\n\t\t\t\tpayload.logger.error(`Seed failed: ${message}`);\n\t\t\t\tawait killTransaction(req);\n\t\t\t}\n\t\t}\n\t};\n\n\tfn()\n\t\t.then(() => process.exit(0))\n\t\t.catch((e) => {\n\t\t\tconsole.error(e);\n\t\t\tprocess.exit(1);\n\t\t});\n};\n"],"names":["dotenv","commitTransaction","getPayload","initTransaction","killTransaction","importConfig","down","up","DBAdapter","seed","opts","fn","config","path","envPath","process","env","PAYLOAD_DROP_DATABASE","configPath","payload","req","seeder","logger","info","err","message","Error","error","then","exit","catch","e","console"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,SAGCC,iBAAiB,EACjBC,UAAU,EACVC,eAAe,EACfC,eAAe,QACT,UAAU;AACjB,SAASC,YAAY,QAAQ,eAAe;AAC5C,SAASC,IAAI,QAAQ,YAAY;AACjC,SAASC,EAAE,QAAQ,UAAU;;UAqBjBC;;GAAAA,cAAAA;AAIZ;;;;;CAKC,GACD,OAAO,MAAMC,OAAO,CAACC;IACpB,MAAMC,KAAK;QACVX,OAAOY,MAAM,CAAC;YACbC,MAAMH,KAAKI,OAAO;QACnB;QAEA,KAAK,MAAMH,MAAM;YAACL;YAAMC;SAAG,CAAE;YAC5B,IAAII,OAAOL,MAAM;gBAChBS,QAAQC,GAAG,CAACC,qBAAqB,GAAG;YACrC,OAAO;gBACN,OAAOF,QAAQC,GAAG,CAACC,qBAAqB,EAAE,2CAA2C;YACtF;YAEA,MAAML,SAAS,MAAMP,aAAaK,KAAKQ,UAAU;YACjD,MAAMC,UAAU,MAAMjB,WAAW;gBAAEU;YAAO;YAC1C,MAAMQ,MAAM;gBAAED;YAAQ;YAEtB,MAAMhB,gBAAgBiB;YAEtB,IAAI;gBACH,MAAMT,GAAG;oBAAEQ;oBAASC;oBAAKC,QAAQX,KAAKW,MAAM;gBAAC;gBAC7CF,QAAQG,MAAM,CAACC,IAAI,CAAC;gBACpB,MAAMtB,kBAAkBmB;YACzB,EAAE,OAAOI,KAAK;gBACb,MAAMC,UAAUD,eAAeE,QAAQF,IAAIC,OAAO,GAAG;gBACrDN,QAAQG,MAAM,CAACK,KAAK,CAAC,CAAC,aAAa,EAAEF,QAAQ,CAAC;gBAC9C,MAAMrB,gBAAgBgB;YACvB;QACD;IACD;IAEAT,KACEiB,IAAI,CAAC,IAAMb,QAAQc,IAAI,CAAC,IACxBC,KAAK,CAAC,CAACC;QACPC,QAAQL,KAAK,CAACI;QACdhB,QAAQc,IAAI,CAAC;IACd;AACF,EAAE"}
@@ -0,0 +1,125 @@
1
+ export interface MediaSeed {
2
+ path: string;
3
+ alt: string;
4
+ caption?: string;
5
+ }
6
+ export interface Media {
7
+ id: number;
8
+ alt: string;
9
+ caption?: {
10
+ root: {
11
+ type: string;
12
+ children: {
13
+ type: string;
14
+ version: number;
15
+ [k: string]: unknown;
16
+ }[];
17
+ direction: ('ltr' | 'rtl') | null;
18
+ format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | '';
19
+ indent: number;
20
+ version: number;
21
+ };
22
+ [k: string]: unknown;
23
+ } | null;
24
+ updatedAt: string;
25
+ createdAt: string;
26
+ url?: string | null;
27
+ thumbnailURL?: string | null;
28
+ filename?: string | null;
29
+ mimeType?: string | null;
30
+ filesize?: number | null;
31
+ width?: number | null;
32
+ height?: number | null;
33
+ focalX?: number | null;
34
+ focalY?: number | null;
35
+ sizes?: {
36
+ webp?: {
37
+ url?: string | null;
38
+ width?: number | null;
39
+ height?: number | null;
40
+ mimeType?: string | null;
41
+ filesize?: number | null;
42
+ filename?: string | null;
43
+ };
44
+ avif?: {
45
+ url?: string | null;
46
+ width?: number | null;
47
+ height?: number | null;
48
+ mimeType?: string | null;
49
+ filesize?: number | null;
50
+ filename?: string | null;
51
+ };
52
+ thumbnail?: {
53
+ url?: string | null;
54
+ width?: number | null;
55
+ height?: number | null;
56
+ mimeType?: string | null;
57
+ filesize?: number | null;
58
+ filename?: string | null;
59
+ };
60
+ thumbnail_webp?: {
61
+ url?: string | null;
62
+ width?: number | null;
63
+ height?: number | null;
64
+ mimeType?: string | null;
65
+ filesize?: number | null;
66
+ filename?: string | null;
67
+ };
68
+ thumbnail_avif?: {
69
+ url?: string | null;
70
+ width?: number | null;
71
+ height?: number | null;
72
+ mimeType?: string | null;
73
+ filesize?: number | null;
74
+ filename?: string | null;
75
+ };
76
+ mobile?: {
77
+ url?: string | null;
78
+ width?: number | null;
79
+ height?: number | null;
80
+ mimeType?: string | null;
81
+ filesize?: number | null;
82
+ filename?: string | null;
83
+ };
84
+ mobile_webp?: {
85
+ url?: string | null;
86
+ width?: number | null;
87
+ height?: number | null;
88
+ mimeType?: string | null;
89
+ filesize?: number | null;
90
+ filename?: string | null;
91
+ };
92
+ mobile_avif?: {
93
+ url?: string | null;
94
+ width?: number | null;
95
+ height?: number | null;
96
+ mimeType?: string | null;
97
+ filesize?: number | null;
98
+ filename?: string | null;
99
+ };
100
+ tablet?: {
101
+ url?: string | null;
102
+ width?: number | null;
103
+ height?: number | null;
104
+ mimeType?: string | null;
105
+ filesize?: number | null;
106
+ filename?: string | null;
107
+ };
108
+ tablet_webp?: {
109
+ url?: string | null;
110
+ width?: number | null;
111
+ height?: number | null;
112
+ mimeType?: string | null;
113
+ filesize?: number | null;
114
+ filename?: string | null;
115
+ };
116
+ tablet_avif?: {
117
+ url?: string | null;
118
+ width?: number | null;
119
+ height?: number | null;
120
+ mimeType?: string | null;
121
+ filesize?: number | null;
122
+ filename?: string | null;
123
+ };
124
+ };
125
+ }
@@ -0,0 +1,3 @@
1
+ export { };
2
+
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/seed/types.ts"],"sourcesContent":["export interface MediaSeed {\n\tpath: string;\n\talt: string;\n\tcaption?: string;\n}\n\nexport interface Media {\n\tid: number;\n\talt: string;\n\tcaption?: {\n\t\troot: {\n\t\t\ttype: string;\n\t\t\tchildren: {\n\t\t\t\ttype: string;\n\t\t\t\tversion: number;\n\t\t\t\t[k: string]: unknown;\n\t\t\t}[];\n\t\t\tdirection: ('ltr' | 'rtl') | null;\n\t\t\tformat: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | '';\n\t\t\tindent: number;\n\t\t\tversion: number;\n\t\t};\n\t\t[k: string]: unknown;\n\t} | null;\n\tupdatedAt: string;\n\tcreatedAt: string;\n\turl?: string | null;\n\tthumbnailURL?: string | null;\n\tfilename?: string | null;\n\tmimeType?: string | null;\n\tfilesize?: number | null;\n\twidth?: number | null;\n\theight?: number | null;\n\tfocalX?: number | null;\n\tfocalY?: number | null;\n\tsizes?: {\n\t\twebp?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t\tavif?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t\tthumbnail?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t\tthumbnail_webp?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t\tthumbnail_avif?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t\tmobile?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t\tmobile_webp?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t\tmobile_avif?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t\ttablet?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t\ttablet_webp?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t\ttablet_avif?: {\n\t\t\turl?: string | null;\n\t\t\twidth?: number | null;\n\t\t\theight?: number | null;\n\t\t\tmimeType?: string | null;\n\t\t\tfilesize?: number | null;\n\t\t\tfilename?: string | null;\n\t\t};\n\t};\n}\n"],"names":[],"mappings":"AAMA,WAuHC"}
@@ -0,0 +1,23 @@
1
+ import type { Payload, PayloadRequest } from 'payload';
2
+ import type { Seeder } from './seed.js';
3
+ import type { Media, MediaSeed } from './types.js';
4
+ /**
5
+ *
6
+ * @param req
7
+ * @param payload
8
+ * @param dirname
9
+ * @param media
10
+ */
11
+ export declare const uploadMedia: (req: PayloadRequest, payload: Payload, dirname: string, media: MediaSeed) => Promise<Media>;
12
+ /**
13
+ * Up script to create tables and seed data.
14
+ *
15
+ * @param payload
16
+ * @param req
17
+ * @param seeder
18
+ */
19
+ export declare const up: ({ payload, req, seeder, }: {
20
+ payload: Payload;
21
+ req: PayloadRequest;
22
+ seeder: Seeder;
23
+ }) => Promise<void>;
@@ -0,0 +1,55 @@
1
+ import path from 'node:path';
2
+ import { getFileByPath } from 'payload';
3
+ import { htmlToLexical } from '../util/lexical.js';
4
+ /**
5
+ *
6
+ * @param req
7
+ * @param payload
8
+ * @param dirname
9
+ * @param media
10
+ */ export const uploadMedia = async (req, payload, dirname, media)=>{
11
+ try {
12
+ const image = await getFileByPath(path.resolve(dirname, media.path));
13
+ const caption = media.caption ? await htmlToLexical(media.caption) : null;
14
+ return await payload.create({
15
+ collection: 'media',
16
+ file: image,
17
+ data: {
18
+ alt: media.alt,
19
+ caption: caption
20
+ },
21
+ req
22
+ });
23
+ } catch (error) {
24
+ payload.logger.error(`Uploading media: ${error}`);
25
+ throw error;
26
+ }
27
+ };
28
+ /**
29
+ * Up script to create tables and seed data.
30
+ *
31
+ * @param payload
32
+ * @param req
33
+ * @param seeder
34
+ */ export const up = async ({ payload, req, seeder })=>{
35
+ payload.logger.info('Running up script');
36
+ await payload.init({
37
+ config: payload.config
38
+ });
39
+ // Creating new tables
40
+ payload.logger.info('Creating indexes...');
41
+ try {
42
+ if (payload.db.init) {
43
+ await payload.db.init();
44
+ }
45
+ } catch (error) {
46
+ payload.logger.error(`Creating database: ${error}`);
47
+ return;
48
+ }
49
+ await seeder({
50
+ payload,
51
+ req
52
+ });
53
+ };
54
+
55
+ //# sourceMappingURL=up.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/seed/up.ts"],"sourcesContent":["import path from 'node:path';\nimport type { Payload, PayloadRequest } from 'payload';\nimport { getFileByPath } from 'payload';\nimport { htmlToLexical } from '../util/lexical.js';\nimport type { Seeder } from './seed.js';\nimport type { Media, MediaSeed } from './types.js';\n\n/**\n *\n * @param req\n * @param payload\n * @param dirname\n * @param media\n */\nexport const uploadMedia = async (\n\treq: PayloadRequest,\n\tpayload: Payload,\n\tdirname: string,\n\tmedia: MediaSeed,\n): Promise<Media> => {\n\ttry {\n\t\tconst image = await getFileByPath(path.resolve(dirname, media.path));\n\t\tconst caption = media.caption ? await htmlToLexical(media.caption) : null;\n\n\t\treturn (await payload.create({\n\t\t\tcollection: 'media',\n\t\t\tfile: image,\n\t\t\tdata: {\n\t\t\t\talt: media.alt,\n\t\t\t\tcaption: caption,\n\t\t\t},\n\t\t\treq,\n\t\t})) as unknown as Media;\n\t} catch (error) {\n\t\tpayload.logger.error(`Uploading media: ${error}`);\n\t\tthrow error;\n\t}\n};\n\n/**\n * Up script to create tables and seed data.\n *\n * @param payload\n * @param req\n * @param seeder\n */\nexport const up = async ({\n\tpayload,\n\treq,\n\tseeder,\n}: {\n\tpayload: Payload;\n\treq: PayloadRequest;\n\tseeder: Seeder;\n}): Promise<void> => {\n\tpayload.logger.info('Running up script');\n\n\tawait payload.init({\n\t\tconfig: payload.config,\n\t});\n\n\t// Creating new tables\n\tpayload.logger.info('Creating indexes...');\n\ttry {\n\t\tif (payload.db.init) {\n\t\t\tawait payload.db.init();\n\t\t}\n\t} catch (error) {\n\t\tpayload.logger.error(`Creating database: ${error}`);\n\t\treturn;\n\t}\n\n\tawait seeder({ payload, req });\n};\n"],"names":["path","getFileByPath","htmlToLexical","uploadMedia","req","payload","dirname","media","image","resolve","caption","create","collection","file","data","alt","error","logger","up","seeder","info","init","config","db"],"mappings":"AAAA,OAAOA,UAAU,YAAY;AAE7B,SAASC,aAAa,QAAQ,UAAU;AACxC,SAASC,aAAa,QAAQ,qBAAqB;AAInD;;;;;;CAMC,GACD,OAAO,MAAMC,cAAc,OAC1BC,KACAC,SACAC,SACAC;IAEA,IAAI;QACH,MAAMC,QAAQ,MAAMP,cAAcD,KAAKS,OAAO,CAACH,SAASC,MAAMP,IAAI;QAClE,MAAMU,UAAUH,MAAMG,OAAO,GAAG,MAAMR,cAAcK,MAAMG,OAAO,IAAI;QAErE,OAAQ,MAAML,QAAQM,MAAM,CAAC;YAC5BC,YAAY;YACZC,MAAML;YACNM,MAAM;gBACLC,KAAKR,MAAMQ,GAAG;gBACdL,SAASA;YACV;YACAN;QACD;IACD,EAAE,OAAOY,OAAO;QACfX,QAAQY,MAAM,CAACD,KAAK,CAAC,CAAC,iBAAiB,EAAEA,MAAM,CAAC;QAChD,MAAMA;IACP;AACD,EAAE;AAEF;;;;;;CAMC,GACD,OAAO,MAAME,KAAK,OAAO,EACxBb,OAAO,EACPD,GAAG,EACHe,MAAM,EAKN;IACAd,QAAQY,MAAM,CAACG,IAAI,CAAC;IAEpB,MAAMf,QAAQgB,IAAI,CAAC;QAClBC,QAAQjB,QAAQiB,MAAM;IACvB;IAEA,sBAAsB;IACtBjB,QAAQY,MAAM,CAACG,IAAI,CAAC;IACpB,IAAI;QACH,IAAIf,QAAQkB,EAAE,CAACF,IAAI,EAAE;YACpB,MAAMhB,QAAQkB,EAAE,CAACF,IAAI;QACtB;IACD,EAAE,OAAOL,OAAO;QACfX,QAAQY,MAAM,CAACD,KAAK,CAAC,CAAC,mBAAmB,EAAEA,MAAM,CAAC;QAClD;IACD;IAEA,MAAMG,OAAO;QAAEd;QAASD;IAAI;AAC7B,EAAE"}
@@ -0,0 +1,10 @@
1
+ import type { GlobalConfig, Tab } from 'payload';
2
+ export type SettingsConfig = {
3
+ additionalTabs?: Tab[];
4
+ override: (args: {
5
+ config: GlobalConfig;
6
+ }) => GlobalConfig;
7
+ };
8
+ export type PayloadHelperPluginConfig = {
9
+ settings?: SettingsConfig;
10
+ };
package/dist/types.js ADDED
@@ -0,0 +1,4 @@
1
+ // import type { SEOPluginConfig } from "@payloadcms/plugin-seo/types";
2
+ export { };
3
+
4
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["// import type { SEOPluginConfig } from \"@payloadcms/plugin-seo/types\";\nimport type { GlobalConfig, Tab } from 'payload';\n\nexport type SettingsConfig = {\n\tadditionalTabs?: Tab[];\n\toverride: (args: {\n\t\tconfig: GlobalConfig;\n\t}) => GlobalConfig;\n};\nexport type PayloadHelperPluginConfig = {\n\tsettings?: SettingsConfig;\n\t// seo?: (args: {\n\t// \tconfig: SEOPluginConfig;\n\t// }) => SEOPluginConfig;\n};\n"],"names":[],"mappings":"AAAA,uEAAuE;AASvE,WAKE"}
@@ -0,0 +1,12 @@
1
+ declare function envFn<T>(key: string, defaultValue: T): string | T;
2
+ declare const env: typeof envFn & {
3
+ isProduction: boolean;
4
+ int(key: string, defaultValue?: number): number | undefined;
5
+ float(key: string, defaultValue?: number): number | undefined;
6
+ bool(key: string, defaultValue?: boolean): boolean | undefined;
7
+ json(key: string, defaultValue?: object): any;
8
+ array(key: string, defaultValue?: string[]): string[] | undefined;
9
+ date(key: string, defaultValue?: Date): Date | undefined;
10
+ oneOf(key: string, expectedValues?: unknown[], defaultValue?: unknown): unknown;
11
+ };
12
+ export default env;
@@ -0,0 +1,75 @@
1
+ function hasKey(key) {
2
+ return Object.prototype.hasOwnProperty.call(process.env, key);
3
+ }
4
+ function envFn(key, defaultValue) {
5
+ return hasKey(key) ? process.env[key] : defaultValue;
6
+ }
7
+ function getKey(key) {
8
+ return process.env[key] ?? '';
9
+ }
10
+ const utils = {
11
+ isProduction: getKey('NODE_ENV') === 'production',
12
+ int (key, defaultValue) {
13
+ if (!hasKey(key)) {
14
+ return defaultValue;
15
+ }
16
+ return Number.parseInt(getKey(key), 10);
17
+ },
18
+ float (key, defaultValue) {
19
+ if (!hasKey(key)) {
20
+ return defaultValue;
21
+ }
22
+ return Number.parseFloat(getKey(key));
23
+ },
24
+ bool (key, defaultValue) {
25
+ if (!hasKey(key)) {
26
+ return defaultValue;
27
+ }
28
+ return getKey(key) === 'true';
29
+ },
30
+ json (key, defaultValue) {
31
+ if (!hasKey(key)) {
32
+ return defaultValue;
33
+ }
34
+ try {
35
+ return JSON.parse(getKey(key));
36
+ } catch (error) {
37
+ if (error instanceof Error) {
38
+ throw new Error(`Invalid json environment variable ${key}: ${error.message}`);
39
+ }
40
+ throw error;
41
+ }
42
+ },
43
+ array (key, defaultValue) {
44
+ if (!hasKey(key)) {
45
+ return defaultValue;
46
+ }
47
+ let value = getKey(key);
48
+ if (value.startsWith('[') && value.endsWith(']')) {
49
+ value = value.substring(1, value.length - 1);
50
+ }
51
+ return value.split(',').map((v)=>{
52
+ return v.trim().replace(/^"(.*)"$/, '$1');
53
+ });
54
+ },
55
+ date (key, defaultValue) {
56
+ if (!hasKey(key)) {
57
+ return defaultValue;
58
+ }
59
+ return new Date(getKey(key));
60
+ },
61
+ oneOf (key, expectedValues, defaultValue) {
62
+ if (!expectedValues) {
63
+ throw new Error('env.oneOf requires expectedValues');
64
+ }
65
+ if (defaultValue && !expectedValues.includes(defaultValue)) {
66
+ throw new Error('env.oneOf requires defaultValue to be included in expectedValues');
67
+ }
68
+ const rawValue = envFn(key, defaultValue);
69
+ return expectedValues.includes(rawValue) ? rawValue : defaultValue;
70
+ }
71
+ };
72
+ const env = Object.assign(envFn, utils);
73
+ export default env;
74
+
75
+ //# sourceMappingURL=env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/env.ts"],"sourcesContent":["function hasKey(key: string): boolean {\n\treturn Object.prototype.hasOwnProperty.call(process.env, key);\n}\n\nfunction envFn<T>(key: string, defaultValue: T): string | T {\n\treturn hasKey(key) ? (process.env[key] as string) : defaultValue;\n}\n\nfunction getKey(key: string): string {\n\treturn process.env[key] ?? '';\n}\n\nconst utils = {\n\tisProduction: getKey('NODE_ENV') === 'production',\n\n\tint(key: string, defaultValue?: number): number | undefined {\n\t\tif (!hasKey(key)) {\n\t\t\treturn defaultValue;\n\t\t}\n\n\t\treturn Number.parseInt(getKey(key), 10);\n\t},\n\n\tfloat(key: string, defaultValue?: number): number | undefined {\n\t\tif (!hasKey(key)) {\n\t\t\treturn defaultValue;\n\t\t}\n\n\t\treturn Number.parseFloat(getKey(key));\n\t},\n\n\tbool(key: string, defaultValue?: boolean): boolean | undefined {\n\t\tif (!hasKey(key)) {\n\t\t\treturn defaultValue;\n\t\t}\n\n\t\treturn getKey(key) === 'true';\n\t},\n\n\tjson(key: string, defaultValue?: object) {\n\t\tif (!hasKey(key)) {\n\t\t\treturn defaultValue;\n\t\t}\n\n\t\ttry {\n\t\t\treturn JSON.parse(getKey(key));\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error) {\n\t\t\t\tthrow new Error(`Invalid json environment variable ${key}: ${error.message}`);\n\t\t\t}\n\n\t\t\tthrow error;\n\t\t}\n\t},\n\n\tarray(key: string, defaultValue?: string[]): string[] | undefined {\n\t\tif (!hasKey(key)) {\n\t\t\treturn defaultValue;\n\t\t}\n\n\t\tlet value = getKey(key);\n\n\t\tif (value.startsWith('[') && value.endsWith(']')) {\n\t\t\tvalue = value.substring(1, value.length - 1);\n\t\t}\n\n\t\treturn value.split(',').map((v) => {\n\t\t\treturn v.trim().replace(/^\"(.*)\"$/, '$1');\n\t\t});\n\t},\n\n\tdate(key: string, defaultValue?: Date): Date | undefined {\n\t\tif (!hasKey(key)) {\n\t\t\treturn defaultValue;\n\t\t}\n\n\t\treturn new Date(getKey(key));\n\t},\n\n\toneOf(key: string, expectedValues?: unknown[], defaultValue?: unknown) {\n\t\tif (!expectedValues) {\n\t\t\tthrow new Error('env.oneOf requires expectedValues');\n\t\t}\n\n\t\tif (defaultValue && !expectedValues.includes(defaultValue)) {\n\t\t\tthrow new Error('env.oneOf requires defaultValue to be included in expectedValues');\n\t\t}\n\n\t\tconst rawValue = envFn(key, defaultValue);\n\t\treturn expectedValues.includes(rawValue) ? rawValue : defaultValue;\n\t},\n};\n\nconst env = Object.assign(envFn, utils);\n\nexport default env;\n"],"names":["hasKey","key","Object","prototype","hasOwnProperty","call","process","env","envFn","defaultValue","getKey","utils","isProduction","int","Number","parseInt","float","parseFloat","bool","json","JSON","parse","error","Error","message","array","value","startsWith","endsWith","substring","length","split","map","v","trim","replace","date","Date","oneOf","expectedValues","includes","rawValue","assign"],"mappings":"AAAA,SAASA,OAAOC,GAAW;IAC1B,OAAOC,OAAOC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACC,QAAQC,GAAG,EAAEN;AAC1D;AAEA,SAASO,MAASP,GAAW,EAAEQ,YAAe;IAC7C,OAAOT,OAAOC,OAAQK,QAAQC,GAAG,CAACN,IAAI,GAAcQ;AACrD;AAEA,SAASC,OAAOT,GAAW;IAC1B,OAAOK,QAAQC,GAAG,CAACN,IAAI,IAAI;AAC5B;AAEA,MAAMU,QAAQ;IACbC,cAAcF,OAAO,gBAAgB;IAErCG,KAAIZ,GAAW,EAAEQ,YAAqB;QACrC,IAAI,CAACT,OAAOC,MAAM;YACjB,OAAOQ;QACR;QAEA,OAAOK,OAAOC,QAAQ,CAACL,OAAOT,MAAM;IACrC;IAEAe,OAAMf,GAAW,EAAEQ,YAAqB;QACvC,IAAI,CAACT,OAAOC,MAAM;YACjB,OAAOQ;QACR;QAEA,OAAOK,OAAOG,UAAU,CAACP,OAAOT;IACjC;IAEAiB,MAAKjB,GAAW,EAAEQ,YAAsB;QACvC,IAAI,CAACT,OAAOC,MAAM;YACjB,OAAOQ;QACR;QAEA,OAAOC,OAAOT,SAAS;IACxB;IAEAkB,MAAKlB,GAAW,EAAEQ,YAAqB;QACtC,IAAI,CAACT,OAAOC,MAAM;YACjB,OAAOQ;QACR;QAEA,IAAI;YACH,OAAOW,KAAKC,KAAK,CAACX,OAAOT;QAC1B,EAAE,OAAOqB,OAAO;YACf,IAAIA,iBAAiBC,OAAO;gBAC3B,MAAM,IAAIA,MAAM,CAAC,kCAAkC,EAAEtB,IAAI,EAAE,EAAEqB,MAAME,OAAO,CAAC,CAAC;YAC7E;YAEA,MAAMF;QACP;IACD;IAEAG,OAAMxB,GAAW,EAAEQ,YAAuB;QACzC,IAAI,CAACT,OAAOC,MAAM;YACjB,OAAOQ;QACR;QAEA,IAAIiB,QAAQhB,OAAOT;QAEnB,IAAIyB,MAAMC,UAAU,CAAC,QAAQD,MAAME,QAAQ,CAAC,MAAM;YACjDF,QAAQA,MAAMG,SAAS,CAAC,GAAGH,MAAMI,MAAM,GAAG;QAC3C;QAEA,OAAOJ,MAAMK,KAAK,CAAC,KAAKC,GAAG,CAAC,CAACC;YAC5B,OAAOA,EAAEC,IAAI,GAAGC,OAAO,CAAC,YAAY;QACrC;IACD;IAEAC,MAAKnC,GAAW,EAAEQ,YAAmB;QACpC,IAAI,CAACT,OAAOC,MAAM;YACjB,OAAOQ;QACR;QAEA,OAAO,IAAI4B,KAAK3B,OAAOT;IACxB;IAEAqC,OAAMrC,GAAW,EAAEsC,cAA0B,EAAE9B,YAAsB;QACpE,IAAI,CAAC8B,gBAAgB;YACpB,MAAM,IAAIhB,MAAM;QACjB;QAEA,IAAId,gBAAgB,CAAC8B,eAAeC,QAAQ,CAAC/B,eAAe;YAC3D,MAAM,IAAIc,MAAM;QACjB;QAEA,MAAMkB,WAAWjC,MAAMP,KAAKQ;QAC5B,OAAO8B,eAAeC,QAAQ,CAACC,YAAYA,WAAWhC;IACvD;AACD;AAEA,MAAMF,MAAML,OAAOwC,MAAM,CAAClC,OAAOG;AAEjC,eAAeJ,IAAI"}
@@ -0,0 +1,7 @@
1
+ import type { Field } from 'payload';
2
+ /**
3
+ * Determines if a Payload field has a name property.
4
+ *
5
+ * @param field
6
+ */
7
+ export declare const fieldHasName: (field: Field) => boolean;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Determines if a Payload field has a name property.
3
+ *
4
+ * @param field
5
+ */ export const fieldHasName = (field)=>{
6
+ if (field.type === 'ui') {
7
+ return false;
8
+ }
9
+ return field.type !== 'tabs' && field.type !== 'row' && field.type !== 'collapsible';
10
+ };
11
+
12
+ //# sourceMappingURL=fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/fields.ts"],"sourcesContent":["import type { Field } from 'payload';\n\n/**\n * Determines if a Payload field has a name property.\n *\n * @param field\n */\nexport const fieldHasName = (field: Field): boolean => {\n\tif (field.type === 'ui') {\n\t\treturn false;\n\t}\n\treturn field.type !== 'tabs' && field.type !== 'row' && field.type !== 'collapsible';\n};\n"],"names":["fieldHasName","field","type"],"mappings":"AAEA;;;;CAIC,GACD,OAAO,MAAMA,eAAe,CAACC;IAC5B,IAAIA,MAAMC,IAAI,KAAK,MAAM;QACxB,OAAO;IACR;IACA,OAAOD,MAAMC,IAAI,KAAK,UAAUD,MAAMC,IAAI,KAAK,SAASD,MAAMC,IAAI,KAAK;AACxE,EAAE"}
@@ -0,0 +1,15 @@
1
+ import type { SerializedEditorState } from 'lexical';
2
+ /**
3
+ * Converts an HTML string to a Lexical editor state.
4
+ *
5
+ * @param {string} html - The HTML string to convert.
6
+ * @returns {SerializedEditorState} The serialized editor state.
7
+ */
8
+ export declare const htmlToLexical: (html: string) => SerializedEditorState;
9
+ /**
10
+ * Converts a Lexical editor state to an HTML string.
11
+ *
12
+ * @param {SerializedEditorState} json - The serialized editor state to convert.
13
+ * @returns {string} The HTML string.
14
+ */
15
+ export declare const lexicalToHtml: (json: SerializedEditorState) => string;
@@ -0,0 +1,115 @@
1
+ import { createHeadlessEditor } from '@lexical/headless';
2
+ import { $generateHtmlFromNodes, $generateNodesFromDOM } from '@lexical/html';
3
+ import { sqliteAdapter } from '@payloadcms/db-sqlite';
4
+ import { defaultEditorConfig, getEnabledNodes, lexicalEditor, sanitizeServerEditorConfig } from '@payloadcms/richtext-lexical';
5
+ import { JSDOM } from 'jsdom';
6
+ import { $getRoot, $getSelection } from 'lexical';
7
+ import { buildConfig, getPayload } from 'payload';
8
+ const loadEditor = async ()=>{
9
+ const config = {
10
+ secret: 'testing',
11
+ editor: lexicalEditor({
12
+ admin: {
13
+ hideGutter: false
14
+ }
15
+ }),
16
+ db: sqliteAdapter({
17
+ client: {
18
+ url: 'file:./local.db'
19
+ }
20
+ })
21
+ };
22
+ const instance = await getPayload({
23
+ config: buildConfig(config)
24
+ });
25
+ const editorConfig = await sanitizeServerEditorConfig(defaultEditorConfig, instance.config);
26
+ return createHeadlessEditor({
27
+ nodes: getEnabledNodes({
28
+ editorConfig
29
+ })
30
+ });
31
+ };
32
+ /**
33
+ * Converts an HTML string to a Lexical editor state.
34
+ *
35
+ * @param {string} html - The HTML string to convert.
36
+ * @returns {SerializedEditorState} The serialized editor state.
37
+ */ export const htmlToLexical = (html)=>{
38
+ const editor = createHeadlessEditor({
39
+ nodes: [],
40
+ onError: (error)=>{
41
+ console.error(error);
42
+ }
43
+ });
44
+ editor.update(()=>{
45
+ // In a headless environment you can use a package such as JSDom to parse the HTML string.
46
+ const dom = new JSDOM(`<!DOCTYPE html><body>${html}</body>`);
47
+ // Once you have the DOM instance it's easy to generate LexicalNodes.
48
+ const nodes = $generateNodesFromDOM(editor, dom.window.document);
49
+ // Select the root
50
+ $getRoot().select();
51
+ // Insert them at a selection.
52
+ const selection = $getSelection();
53
+ console.log('Generated nodes: ', nodes);
54
+ if (selection) selection.insertNodes(nodes);
55
+ }, {
56
+ discrete: true
57
+ });
58
+ return editor.getEditorState().toJSON();
59
+ // let state = {};
60
+ //
61
+ // loadEditor().then((editor) => {
62
+ // editor.update(
63
+ // () => {
64
+ // // In a headless environment you can use a package such as JSDom to parse the HTML string.
65
+ // const dom = new JSDOM(`<!DOCTYPE html><body>${html}</body>`);
66
+ //
67
+ // // Once you have the DOM instance it's easy to generate LexicalNodes.
68
+ // const nodes = $generateNodesFromDOM(editor, dom.window.document);
69
+ //
70
+ // // Select the root
71
+ // $getRoot().select();
72
+ //
73
+ // // Insert them at a selection.
74
+ // const selection = $getSelection();
75
+ //
76
+ // if (selection) selection.insertNodes(nodes);
77
+ // },
78
+ // { discrete: true },
79
+ // );
80
+ //
81
+ // state = editor.getEditorState().toJSON();
82
+ // });
83
+ //
84
+ // return state as SerializedEditorState;
85
+ };
86
+ /**
87
+ * Converts a Lexical editor state to an HTML string.
88
+ *
89
+ * @param {SerializedEditorState} json - The serialized editor state to convert.
90
+ * @returns {string} The HTML string.
91
+ */ export const lexicalToHtml = (json)=>{
92
+ const editor = createHeadlessEditor({
93
+ nodes: [],
94
+ onError: (error)=>{
95
+ console.error(error);
96
+ }
97
+ });
98
+ // Initialize a JSDOM instance
99
+ const dom = new JSDOM('');
100
+ // @ts-ignore
101
+ globalThis.window = dom.window;
102
+ globalThis.document = dom.window.document;
103
+ editor.update(()=>{
104
+ const editorState = editor.parseEditorState(json);
105
+ editor.setEditorState(editorState);
106
+ });
107
+ // Convert the editor state to HTML
108
+ let html = '';
109
+ editor.getEditorState().read(()=>{
110
+ html = $generateHtmlFromNodes(editor);
111
+ });
112
+ return html;
113
+ };
114
+
115
+ //# sourceMappingURL=lexical.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/lexical.ts"],"sourcesContent":["import { createHeadlessEditor } from '@lexical/headless';\nimport { $generateHtmlFromNodes, $generateNodesFromDOM } from '@lexical/html';\nimport { sqliteAdapter } from '@payloadcms/db-sqlite';\nimport {\n\tdefaultEditorConfig,\n\tgetEnabledNodes,\n\tlexicalEditor,\n\tsanitizeServerEditorConfig,\n} from '@payloadcms/richtext-lexical';\nimport { JSDOM } from 'jsdom';\nimport { $getRoot, $getSelection, type LexicalEditor } from 'lexical';\nimport type { SerializedEditorState } from 'lexical';\nimport { buildConfig, getPayload } from 'payload';\nimport { importWithoutClientFiles } from 'payload/node';\n\nconst loadEditor = async (): Promise<LexicalEditor> => {\n\tconst config = {\n\t\tsecret: 'testing',\n\t\teditor: lexicalEditor({\n\t\t\tadmin: {\n\t\t\t\thideGutter: false,\n\t\t\t},\n\t\t}),\n\t\tdb: sqliteAdapter({\n\t\t\tclient: {\n\t\t\t\turl: 'file:./local.db',\n\t\t\t},\n\t\t}),\n\t};\n\n\tconst instance = await getPayload({\n\t\tconfig: buildConfig(config),\n\t});\n\n\tconst editorConfig = await sanitizeServerEditorConfig(defaultEditorConfig, instance.config);\n\n\treturn createHeadlessEditor({\n\t\tnodes: getEnabledNodes({\n\t\t\teditorConfig,\n\t\t}),\n\t});\n};\n\n/**\n * Converts an HTML string to a Lexical editor state.\n *\n * @param {string} html - The HTML string to convert.\n * @returns {SerializedEditorState} The serialized editor state.\n */\nexport const htmlToLexical = (html: string): SerializedEditorState => {\n\tconst editor = createHeadlessEditor({\n\t\tnodes: [],\n\t\tonError: (error) => {\n\t\t\tconsole.error(error);\n\t\t},\n\t});\n\n\teditor.update(\n\t\t() => {\n\t\t\t// In a headless environment you can use a package such as JSDom to parse the HTML string.\n\t\t\tconst dom = new JSDOM(`<!DOCTYPE html><body>${html}</body>`);\n\n\t\t\t// Once you have the DOM instance it's easy to generate LexicalNodes.\n\t\t\tconst nodes = $generateNodesFromDOM(editor, dom.window.document);\n\n\t\t\t// Select the root\n\t\t\t$getRoot().select();\n\n\t\t\t// Insert them at a selection.\n\t\t\tconst selection = $getSelection();\n\n\t\t\tconsole.log('Generated nodes: ', nodes);\n\n\t\t\tif (selection) selection.insertNodes(nodes);\n\t\t},\n\t\t{ discrete: true },\n\t);\n\n\treturn editor.getEditorState().toJSON();\n\n\t// let state = {};\n\t//\n\t// loadEditor().then((editor) => {\n\t// \teditor.update(\n\t// \t\t() => {\n\t// \t\t\t// In a headless environment you can use a package such as JSDom to parse the HTML string.\n\t// \t\t\tconst dom = new JSDOM(`<!DOCTYPE html><body>${html}</body>`);\n\t//\n\t// \t\t\t// Once you have the DOM instance it's easy to generate LexicalNodes.\n\t// \t\t\tconst nodes = $generateNodesFromDOM(editor, dom.window.document);\n\t//\n\t// \t\t\t// Select the root\n\t// \t\t\t$getRoot().select();\n\t//\n\t// \t\t\t// Insert them at a selection.\n\t// \t\t\tconst selection = $getSelection();\n\t//\n\t// \t\t\tif (selection) selection.insertNodes(nodes);\n\t// \t\t},\n\t// \t\t{ discrete: true },\n\t// \t);\n\t//\n\t// \tstate = editor.getEditorState().toJSON();\n\t// });\n\t//\n\t// return state as SerializedEditorState;\n};\n\n/**\n * Converts a Lexical editor state to an HTML string.\n *\n * @param {SerializedEditorState} json - The serialized editor state to convert.\n * @returns {string} The HTML string.\n */\nexport const lexicalToHtml = (json: SerializedEditorState): string => {\n\tconst editor = createHeadlessEditor({\n\t\tnodes: [],\n\t\tonError: (error) => {\n\t\t\tconsole.error(error);\n\t\t},\n\t});\n\n\t// Initialize a JSDOM instance\n\tconst dom = new JSDOM('');\n\n\t// @ts-ignore\n\tglobalThis.window = dom.window;\n\tglobalThis.document = dom.window.document;\n\n\teditor.update(() => {\n\t\tconst editorState = editor.parseEditorState(json);\n\t\teditor.setEditorState(editorState);\n\t});\n\n\t// Convert the editor state to HTML\n\tlet html = '';\n\teditor.getEditorState().read(() => {\n\t\thtml = $generateHtmlFromNodes(editor);\n\t});\n\n\treturn html;\n};\n"],"names":["createHeadlessEditor","$generateHtmlFromNodes","$generateNodesFromDOM","sqliteAdapter","defaultEditorConfig","getEnabledNodes","lexicalEditor","sanitizeServerEditorConfig","JSDOM","$getRoot","$getSelection","buildConfig","getPayload","loadEditor","config","secret","editor","admin","hideGutter","db","client","url","instance","editorConfig","nodes","htmlToLexical","html","onError","error","console","update","dom","window","document","select","selection","log","insertNodes","discrete","getEditorState","toJSON","lexicalToHtml","json","globalThis","editorState","parseEditorState","setEditorState","read"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,oBAAoB;AACzD,SAASC,sBAAsB,EAAEC,qBAAqB,QAAQ,gBAAgB;AAC9E,SAASC,aAAa,QAAQ,wBAAwB;AACtD,SACCC,mBAAmB,EACnBC,eAAe,EACfC,aAAa,EACbC,0BAA0B,QACpB,+BAA+B;AACtC,SAASC,KAAK,QAAQ,QAAQ;AAC9B,SAASC,QAAQ,EAAEC,aAAa,QAA4B,UAAU;AAEtE,SAASC,WAAW,EAAEC,UAAU,QAAQ,UAAU;AAGlD,MAAMC,aAAa;IAClB,MAAMC,SAAS;QACdC,QAAQ;QACRC,QAAQV,cAAc;YACrBW,OAAO;gBACNC,YAAY;YACb;QACD;QACAC,IAAIhB,cAAc;YACjBiB,QAAQ;gBACPC,KAAK;YACN;QACD;IACD;IAEA,MAAMC,WAAW,MAAMV,WAAW;QACjCE,QAAQH,YAAYG;IACrB;IAEA,MAAMS,eAAe,MAAMhB,2BAA2BH,qBAAqBkB,SAASR,MAAM;IAE1F,OAAOd,qBAAqB;QAC3BwB,OAAOnB,gBAAgB;YACtBkB;QACD;IACD;AACD;AAEA;;;;;CAKC,GACD,OAAO,MAAME,gBAAgB,CAACC;IAC7B,MAAMV,SAAShB,qBAAqB;QACnCwB,OAAO,EAAE;QACTG,SAAS,CAACC;YACTC,QAAQD,KAAK,CAACA;QACf;IACD;IAEAZ,OAAOc,MAAM,CACZ;QACC,0FAA0F;QAC1F,MAAMC,MAAM,IAAIvB,MAAM,CAAC,qBAAqB,EAAEkB,KAAK,OAAO,CAAC;QAE3D,qEAAqE;QACrE,MAAMF,QAAQtB,sBAAsBc,QAAQe,IAAIC,MAAM,CAACC,QAAQ;QAE/D,kBAAkB;QAClBxB,WAAWyB,MAAM;QAEjB,8BAA8B;QAC9B,MAAMC,YAAYzB;QAElBmB,QAAQO,GAAG,CAAC,qBAAqBZ;QAEjC,IAAIW,WAAWA,UAAUE,WAAW,CAACb;IACtC,GACA;QAAEc,UAAU;IAAK;IAGlB,OAAOtB,OAAOuB,cAAc,GAAGC,MAAM;AAErC,kBAAkB;AAClB,EAAE;AACF,kCAAkC;AAClC,kBAAkB;AAClB,YAAY;AACZ,gGAAgG;AAChG,mEAAmE;AACnE,EAAE;AACF,2EAA2E;AAC3E,uEAAuE;AACvE,EAAE;AACF,wBAAwB;AACxB,0BAA0B;AAC1B,EAAE;AACF,oCAAoC;AACpC,wCAAwC;AACxC,EAAE;AACF,kDAAkD;AAClD,OAAO;AACP,wBAAwB;AACxB,MAAM;AACN,EAAE;AACF,6CAA6C;AAC7C,MAAM;AACN,EAAE;AACF,yCAAyC;AAC1C,EAAE;AAEF;;;;;CAKC,GACD,OAAO,MAAMC,gBAAgB,CAACC;IAC7B,MAAM1B,SAAShB,qBAAqB;QACnCwB,OAAO,EAAE;QACTG,SAAS,CAACC;YACTC,QAAQD,KAAK,CAACA;QACf;IACD;IAEA,8BAA8B;IAC9B,MAAMG,MAAM,IAAIvB,MAAM;IAEtB,aAAa;IACbmC,WAAWX,MAAM,GAAGD,IAAIC,MAAM;IAC9BW,WAAWV,QAAQ,GAAGF,IAAIC,MAAM,CAACC,QAAQ;IAEzCjB,OAAOc,MAAM,CAAC;QACb,MAAMc,cAAc5B,OAAO6B,gBAAgB,CAACH;QAC5C1B,OAAO8B,cAAc,CAACF;IACvB;IAEA,mCAAmC;IACnC,IAAIlB,OAAO;IACXV,OAAOuB,cAAc,GAAGQ,IAAI,CAAC;QAC5BrB,OAAOzB,uBAAuBe;IAC/B;IAEA,OAAOU;AACR,EAAE"}
@@ -0,0 +1,21 @@
1
+ import { htmlToLexical } from './lexical';
2
+ describe('htmlToLexical', ()=>{
3
+ it('should convert an HTML string to a Lexical editor state', ()=>{
4
+ const html = '<p>Hello, world!</p>';
5
+ const editorState = htmlToLexical(html);
6
+ expect(editorState).toEqual({
7
+ nodes: [
8
+ {
9
+ type: 'paragraph',
10
+ children: [
11
+ {
12
+ text: 'Hello, world!'
13
+ }
14
+ ]
15
+ }
16
+ ]
17
+ });
18
+ });
19
+ });
20
+
21
+ //# sourceMappingURL=lexical.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/lexical.test.ts"],"sourcesContent":["import { htmlToLexical } from './lexical';\n\ndescribe('htmlToLexical', () => {\n\tit('should convert an HTML string to a Lexical editor state', () => {\n\t\tconst html = '<p>Hello, world!</p>';\n\t\tconst editorState = htmlToLexical(html);\n\n\t\texpect(editorState).toEqual({\n\t\t\tnodes: [\n\t\t\t\t{\n\t\t\t\t\ttype: 'paragraph',\n\t\t\t\t\tchildren: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttext: 'Hello, world!',\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t],\n\t\t});\n\t});\n});\n"],"names":["htmlToLexical","describe","it","html","editorState","expect","toEqual","nodes","type","children","text"],"mappings":"AAAA,SAASA,aAAa,QAAQ,YAAY;AAE1CC,SAAS,iBAAiB;IACzBC,GAAG,2DAA2D;QAC7D,MAAMC,OAAO;QACb,MAAMC,cAAcJ,cAAcG;QAElCE,OAAOD,aAAaE,OAAO,CAAC;YAC3BC,OAAO;gBACN;oBACCC,MAAM;oBACNC,UAAU;wBACT;4BACCC,MAAM;wBACP;qBACA;gBACF;aACA;QACF;IACD;AACD"}
@@ -0,0 +1,2 @@
1
+ export declare const validateURL: (value: string) => Promise<true | "Please enter a valid URL">;
2
+ export declare const validatePostcode: (value: string) => Promise<true | "Invalid postcode format">;
@@ -0,0 +1,23 @@
1
+ export const validateURL = async (value)=>{
2
+ if (!value) {
3
+ return true;
4
+ }
5
+ try {
6
+ new URL(value);
7
+ return true;
8
+ } catch (error) {
9
+ return 'Please enter a valid URL';
10
+ }
11
+ };
12
+ export const validatePostcode = async (value)=>{
13
+ if (!value) {
14
+ return true;
15
+ }
16
+ const postcodeRegex = /^[A-Z]{1,2}\d[A-Z\d]? ?\d[A-Z]{2}$/i;
17
+ if (!postcodeRegex.test(value)) {
18
+ return 'Invalid postcode format';
19
+ }
20
+ return true;
21
+ };
22
+
23
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/util/validation.ts"],"sourcesContent":["export const validateURL = async (value: string) => {\n\tif (!value) {\n\t\treturn true;\n\t}\n\ttry {\n\t\tnew URL(value);\n\t\treturn true;\n\t} catch (error) {\n\t\treturn 'Please enter a valid URL';\n\t}\n};\n\nexport const validatePostcode = async (value: string) => {\n\tif (!value) {\n\t\treturn true;\n\t}\n\tconst postcodeRegex = /^[A-Z]{1,2}\\d[A-Z\\d]? ?\\d[A-Z]{2}$/i;\n\tif (!postcodeRegex.test(value)) {\n\t\treturn 'Invalid postcode format';\n\t}\n\treturn true;\n};\n"],"names":["validateURL","value","URL","error","validatePostcode","postcodeRegex","test"],"mappings":"AAAA,OAAO,MAAMA,cAAc,OAAOC;IACjC,IAAI,CAACA,OAAO;QACX,OAAO;IACR;IACA,IAAI;QACH,IAAIC,IAAID;QACR,OAAO;IACR,EAAE,OAAOE,OAAO;QACf,OAAO;IACR;AACD,EAAE;AAEF,OAAO,MAAMC,mBAAmB,OAAOH;IACtC,IAAI,CAACA,OAAO;QACX,OAAO;IACR;IACA,MAAMI,gBAAgB;IACtB,IAAI,CAACA,cAAcC,IAAI,CAACL,QAAQ;QAC/B,OAAO;IACR;IACA,OAAO;AACR,EAAE"}