Skip to content

Commit

Permalink
Merge pull request #248 from lane711/feature/wysiwyg-editor
Browse files Browse the repository at this point in the history
Feature/wysiwyg editor
  • Loading branch information
lane711 authored Mar 20, 2024
2 parents 165bb2f + 21910cc commit f191bd5
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/cms/api/forms.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { getTestingContext } from '../util/testing';
import { getForm } from './forms';

const ctx = getTestingContext();

it('form tests', () => {
// describe('form should render test boxes', async () => {
// const form = await getForm(ctx, 'posts');
// expect(form).toBeNull();
// });
});
25 changes: 25 additions & 0 deletions src/cms/api/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,31 @@ export function getForm(ctx: AppContext, table) {
}
]
};
} else if (formField.metaType == 'ckeditor') {
const c = formField;
formField = {
label: c.label || c.key,
editor: 'ckeditor',
customClass: 'pl-4 pr-4',
tableView: true,
key: c.key,
type: 'textarea',
input: true,
isUploadEnabled: false
};
} else if (formField.metaType == 'quill') {
const c = formField;
formField = {
label: c.label || c.key,
editor: 'quill',
customClass: 'pl-4 pr-4',
tableView: true,
key: c.key,
type: 'textarea',
rows: 3,
input: true,
isUploadEnabled: false
};
}
formFields.push(formField);
}
Expand Down
27 changes: 25 additions & 2 deletions src/cms/util/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,30 @@ import { drizzle } from 'drizzle-orm/d1';
import { createUser } from '../auth/lucia';
import { getD1DataByTable } from '../data/d1-data';

export async function createUserAndGetToken(app, ctx, email= '[email protected]', password = 'password123', role = 'admin') {
export async function getTestingContext() {
const { __D1_BETA__D1DATA, KVDATA } = getMiniflareBindings();

const toJson = function (json) {
return json;
};

const ctx = {
env: { KVDATA: KVDATA, D1DATA: __D1_BETA__D1DATA },
json: toJson,
user: { id: 'fromtest' },
_var: { user: { userId: 'abc123' } }
};

return ctx;
}

export async function createUserAndGetToken(
app,
ctx,
email = '[email protected]',
password = 'password123',
role = 'admin'
) {
await createUserTestTables(ctx);

//TODO: create user properly using the lucia api so that the user keys data in populated
Expand Down Expand Up @@ -42,7 +65,7 @@ export async function createUserAndGetToken(app, ctx, email= '[email protected]', password
expect(res.status).toBe(200);
let body = await res.json();
expect(body.bearer.length).toBeGreaterThan(10);
return {id: result.user.userId, token:body.bearer};
return { id: result.user.userId, token: body.bearer };
}

export async function createUserTestTables(ctx) {
Expand Down
9 changes: 9 additions & 0 deletions src/db/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ export interface ApiConfig {
type: 'file' | 'file[]';
bucket: (ctx: AppContext) => R2Bucket;
path?: string | ((ctx: AppContext) => string);
}
| {
type: 'password';
}
| {
type: 'ckeditor';
}
| {
type: 'quill';
};
};
}
Expand Down
3 changes: 3 additions & 0 deletions src/db/schema/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,8 @@ export const fields: ApiConfig['fields'] = {
},
tags: {
type: 'string[]'
},
body: {
type: 'ckeditor'
}
};

0 comments on commit f191bd5

Please sign in to comment.