From de84647b73d8d85752d34ba6dda480e7a98d3e82 Mon Sep 17 00:00:00 2001 From: linonetwo Date: Wed, 22 Feb 2023 01:54:31 +0800 Subject: [PATCH] fix: two widget should share the same lib --- package.json | 1 + src/plugin.info | 2 +- src/type.d.ts | 6 ++++++ src/widgets/json-editor-form/index.ts | 4 +--- src/widgets/supertag-form/index.ts | 2 +- src/widgets/utils/initEditor.js.meta | 5 +++++ src/widgets/{supertag-form => utils}/initEditor.ts | 6 +++++- 7 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 src/widgets/utils/initEditor.js.meta rename src/widgets/{supertag-form => utils}/initEditor.ts (55%) diff --git a/package.json b/package.json index 69b307d..74e9736 100644 --- a/package.json +++ b/package.json @@ -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" ], diff --git a/src/plugin.info b/src/plugin.info index 3f91a50..ee57434 100644 --- a/src/plugin.info +++ b/src/plugin.info @@ -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" } \ No newline at end of file diff --git a/src/type.d.ts b/src/type.d.ts index 2a832d8..814363f 100644 --- a/src/type.d.ts +++ b/src/type.d.ts @@ -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 | undefined; +} declare module '@json-editor/json-editor' { // copy from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/json-editor/index.d.ts diff --git a/src/widgets/json-editor-form/index.ts b/src/widgets/json-editor-form/index.ts index f2da383..2f94771 100644 --- a/src/widgets/json-editor-form/index.ts +++ b/src/widgets/json-editor-form/index.ts @@ -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'; @@ -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; diff --git a/src/widgets/supertag-form/index.ts b/src/widgets/supertag-form/index.ts index 628bac2..63990ce 100644 --- a/src/widgets/supertag-form/index.ts +++ b/src/widgets/supertag-form/index.ts @@ -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'; diff --git a/src/widgets/utils/initEditor.js.meta b/src/widgets/utils/initEditor.js.meta new file mode 100644 index 0000000..dab81f3 --- /dev/null +++ b/src/widgets/utils/initEditor.js.meta @@ -0,0 +1,5 @@ +creator: LinOnetwo +title: $:/plugins/linonetwo/super-tag/utils/initEditor.js +type: application/javascript +module-type: library +hide-body: yes \ No newline at end of file diff --git a/src/widgets/supertag-form/initEditor.ts b/src/widgets/utils/initEditor.ts similarity index 55% rename from src/widgets/supertag-form/initEditor.ts rename to src/widgets/utils/initEditor.ts index 94f5bc2..f8fbff9 100644 --- a/src/widgets/supertag-form/initEditor.ts +++ b/src/widgets/utils/initEditor.ts @@ -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 | undefined { +function initEditor(fullSchema: JSONSchema4, tiddlerFields: ITiddlerFields, editorElement: HTMLDivElement): JSONEditor.JSONEditor | undefined { return new JSONEditor.JSONEditor(editorElement, { schema: fullSchema, theme: 'spectre', @@ -14,3 +15,6 @@ export function initEditor(fullSchema: JSONSchema4, tiddlerFields: ITiddlerField use_default_values: true, }); } + +declare const exports: Record; +exports.initEditor = initEditor;