0.6.3 • Published 2 months ago

tw-react v0.6.3

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

TiddlyWiki React

What’s your opinion about using ReactJS in the plugin? Sometimes it is inevitable to use ReactJS in the widget, for example, JSONSchemaForm.

See Website for documentation.

Usage

Add this to a type.d.ts file to your src/ folder:

declare module '$:/plugins/linonetwo/tw-react/widget.js' {
  import { IReactWidgetConstructor } from 'tw-react';
  const widget: IReactWidgetConstructor;
}

or in tsconfig.json add:

    "typeRoots" : ["node_modules/@types", "node_modules/tw5-typed", "node_modules/tw-react/dist/lib"],

Products

  1. WhiteBoard plugin
  2. Demo of a new WYSIWYG editor: slate-write (unstable alpha stage)
  3. FlowTiwi - a Multi-column draggable resizable sidebar (beta release)
  4. Smart Form plugin - beta release - Display different form based on the tag you add

When installing these plugins from TiddlyWiki-CPL: TiddlyWiki world of Google App Store! , this React plugin will be automatically installed as a dependency. So you probably don't need to install this manyally.

(You can also drag __plugins_linonetwo_tw-react.json from Release · tiddly-gittly/tw-react · GitHub. But Don't drag them from above demo sites. Because the ReactJS plugin from those demosite is of dev mode, so size is much larger than the one in the CPL and Github release!)

Trouble shotting

React is undefined

You may need import React from 'react'; on the top of jsx file, even you are in react 17+ and not using this variable...

My css is not loading

See things in your dist/plugins/xxx/yyy, is there a zzz.css file?

Then you will need to create a zzz.css.meta file in your src folder:

title: $:/plugins/linonetwo/flowtiwi-sidebar/flowtiwi-sidebar.css
tags: $:/tags/Stylesheet
type: text/css

ReferenceError: window is not defined

You may have this error when booting nodejs wiki:

Error executing boot module $:/plugins/linonetwo/tw-whiteboard/widget.js: {}

$:/plugins/linonetwo/tw-whiteboard/widget.js:29527
var AY = window.matchMedia ? window.matchMedia("(prefers-color-scheme: dark)").matches : false;
         ^

ReferenceError: window is not defined
    at $:/plugins/linonetwo/tw-whiteboard/widget.js:29527:10
    at Script.runInContext (node:vm:139:12)
    at Script.runInNewContext (node:vm:144:17)

This is because in nodejs context, there are no window object.

You need to only execute your script in browser, like the example in slate-write:

/* eslint-disable @typescript-eslint/no-unsafe-assignment */
(function slateWriteWidgetIIFE() {
  // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
  if (!$tw.browser) {
    return;
  }
  // separate the widget from the exports here, so we can skip the require of react code if `!$tw.browser`. Those ts code will error if loaded in the nodejs side.
  const components = require('$:/plugins/linonetwo/slate-write/components/index.js');
  const { widget } = components;
  /* eslint-disable @typescript-eslint/no-unsafe-member-access */
  exports.slateWrite = widget;
  // fix `Undefined widget 'edit-slateWrite'`
  exports['edit-slateWrite'] = widget;
})();

While export the widget from another file:

// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
exports.widget = SlateWriteWidget;
0.6.3

2 months ago

0.5.7

10 months ago

0.5.9

10 months ago

0.5.4

11 months ago

0.6.2

10 months ago

0.5.3

11 months ago

0.5.6

10 months ago

0.5.5

10 months ago

0.5.0

11 months ago

0.6.1

10 months ago

0.5.2

11 months ago

0.6.0

10 months ago

0.5.1

11 months ago

0.4.6

1 year ago

0.3.10

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.3.9

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.8

2 years ago

0.3.7

2 years ago

0.3.1

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.0.10

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.2.6

2 years ago

0.1.7

2 years ago

0.2.9

2 years ago

0.2.3

2 years ago

0.1.4

2 years ago

0.2.2

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago