Skip to content

Commit

Permalink
fix: two widget should share the same lib
Browse files Browse the repository at this point in the history
  • Loading branch information
linonetwo committed Feb 21, 2023
1 parent aeb6ef3 commit de84647
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"url": "https://github.com/tiddly-gittly/tw-example-plugin",
"tsFiles": [
"src/widgets/utils/initEditor.ts",
"src/widgets/supertag-form/index.ts",
"src/widgets/json-editor-form/index.ts"
],
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.info
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"description": "Auto generate input form on a tiddler by simply adding a SuperTag to it. Create a SuperTag by compositing existing TraitTags.",
"core-version": ">=5.1.22",
"plugin-type": "plugin",
"version": "0.1.1",
"version": "0.1.2",
"list": "readme"
}
6 changes: 6 additions & 0 deletions src/type.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/* eslint-disable @typescript-eslint/ban-types */

declare module '$:/plugins/linonetwo/super-tag/widgets/supertag-form/index.js' {}
declare module '$:/plugins/linonetwo/super-tag/utils/initEditor.js' {
import type { JSONSchema4 } from 'json-schema';
import type { ITiddlerFields } from 'tiddlywiki';
import type * as JSONEditor from '@json-editor/json-editor';
export function initEditor(fullSchema: JSONSchema4, tiddlerFields: ITiddlerFields, editorElement: HTMLDivElement): JSONEditor.JSONEditor<unknown> | undefined;
}

declare module '@json-editor/json-editor' {
// copy from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/json-editor/index.d.ts
Expand Down
4 changes: 1 addition & 3 deletions src/widgets/json-editor-form/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { widget as Widget } from '$:/core/modules/widgets/widget.js';
import type * as JSONEditor from '@json-editor/json-editor';

import components from '$:/plugins/linonetwo/super-tag/widgets/supertag-form/index.js';
import { initEditor } from '../supertag-form/initEditor';
import { initEditor } from '$:/plugins/linonetwo/super-tag/utils/initEditor.js';
import { formOnChange } from '../utils/formOnChange';
import { getFullSchemaFromFilter } from '../utils/getFullSchema';

Expand All @@ -21,8 +21,6 @@ class JSONEditorFormWidget extends SupertagFormWidget {
this.execute();
const filterToGetJSONSchema = this.getAttribute('filter') ?? '[all[current]tags[]tags[]] :filter[tags[]match[$:/SuperTag/TraitTag]] :and[get[schema]]';
const currentTiddlerTitle = this.getAttribute('tiddler') ?? this.getVariable('currentTiddler');
// DEBUG: console currentTiddlerTitle
console.log(`currentTiddlerTitle`, currentTiddlerTitle);
this.currentTiddlerTitle = currentTiddlerTitle;
this.filterToGetJSONSchema = filterToGetJSONSchema;

Expand Down
2 changes: 1 addition & 1 deletion src/widgets/supertag-form/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import './spectre-min.scss';
import 'spectre.css/dist/spectre-icons.css';
import './style.css';
import { widget as Widget } from '$:/core/modules/widgets/widget.js';
import { initEditor } from './initEditor';
import { initEditor } from '$:/plugins/linonetwo/super-tag/utils/initEditor.js';
import { formOnChange } from '../utils/formOnChange';
import { getFullSchemaFromCurrentTiddler } from '../utils/getFullSchema';

Expand Down
5 changes: 5 additions & 0 deletions src/widgets/utils/initEditor.js.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
creator: LinOnetwo
title: $:/plugins/linonetwo/super-tag/utils/initEditor.js
type: application/javascript
module-type: library
hide-body: yes
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as JSONEditor from '@json-editor/json-editor';
import type { ITiddlerFields } from 'tiddlywiki';
import type { JSONSchema4 } from 'json-schema';
import type { initEditor as IInitEditor } from '$:/plugins/linonetwo/super-tag/utils/initEditor.js';

export function initEditor(fullSchema: JSONSchema4, tiddlerFields: ITiddlerFields, editorElement: HTMLDivElement): JSONEditor.JSONEditor<unknown> | undefined {
function initEditor(fullSchema: JSONSchema4, tiddlerFields: ITiddlerFields, editorElement: HTMLDivElement): JSONEditor.JSONEditor<unknown> | undefined {
return new JSONEditor.JSONEditor(editorElement, {
schema: fullSchema,
theme: 'spectre',
Expand All @@ -14,3 +15,6 @@ export function initEditor(fullSchema: JSONSchema4, tiddlerFields: ITiddlerField
use_default_values: true,
});
}

declare const exports: Record<string, typeof IInitEditor>;
exports.initEditor = initEditor;

0 comments on commit de84647

Please sign in to comment.