Skip to content

Commit

Permalink
fix: translate supertag widget
Browse files Browse the repository at this point in the history
  • Loading branch information
linonetwo committed May 6, 2024
1 parent 7cc7cec commit d7b01b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/super-tag/widgets/utils/getFullSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export function getFullSchemaFromCurrentTiddler(currentTiddlerTitle: string) {
return { fullSchema, tiddlerFields };
}

/**
* Used by `json-editor-form` widget.
* For `supertag-form` widget, see `getFullSchemaFromCurrentTiddler`.
*/
export function getFullSchemaFromFilter(filter: string, currentTiddlerTitle: string, parentWidget: Widget) {
const jsonSchemas = $tw.wiki
.filterTiddlers(filter, parentWidget)
Expand Down
13 changes: 7 additions & 6 deletions src/super-tag/widgets/utils/getTraits.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ITiddlerFields } from 'tiddlywiki';
import type { JSONSchema4 } from 'json-schema';
import type { ITiddlerFields } from 'tiddlywiki';
import { translateSchema } from './translateSchema';

export interface ITraitTagData {
Expand All @@ -23,14 +23,16 @@ export function getSuperTagTraits(currentTiddlerTitle: string): ISuperTagData[]
const potentialTraitTiddler = $tw.wiki.getTiddler(traitTitle);
if (potentialTraitTiddler?.fields?.tags?.some((tag) => tag === '$:/SuperTag/TraitTag') !== true) return undefined;
// now it is confirmed to be a trait tag
let { title, schema } = potentialTraitTiddler.fields;
if (typeof schema !== 'string') return undefined;
let { title, schema: schemaString } = potentialTraitTiddler.fields;
if (typeof schemaString !== 'string') return undefined;
let schema: JSONSchema4;
try {
schema = JSON.parse(schema);
schema = JSON.parse(schemaString) as JSONSchema4;
} catch (error) {
console.error(`TraitTag ${title} has invalid schema, error: ${(error as Error).message}`);
return undefined;
}
schema = translateSchema(schema);
// if (typeof uiSchema !== 'string') return undefined;
// try {
// uiSchema = JSON.parse(uiSchema);
Expand All @@ -42,8 +44,7 @@ export function getSuperTagTraits(currentTiddlerTitle: string): ISuperTagData[]
schema,
} as ITraitTagData;
})
.filter((item): item is ITraitTagData => item !== undefined)
.map(translateSchema);
.filter((item): item is ITraitTagData => item !== undefined);
if (traits.length === 0) return undefined;

return {
Expand Down

0 comments on commit d7b01b6

Please sign in to comment.