[TWX] Pretty shadow tid titles

66 views
Skip to first unread message

Mat

unread,
Sep 17, 2018, 6:55:28 AM9/17/18
to TiddlyWikiDev
The overall point with this idea is to make it easier to create tiddlers. It loosely describes a UI and a workflow but starts with an observation about the current way a plugin is defined.

...


In another thread PMario explained the reason why plugins appear like so:

{
   
"tiddlers": {
       
"$:/plugin/TWaddle/Foo/Bar": {
           
"title": "$:/plugin/TWaddle/Foo/Bar"
       
},

...

...i.e the title of the shadow tids are always repeated twice - first one apparently being an index that is only temporarily used. 

I'm about to propose a change to this but I assume this is very much ingrained in the current core so this is why I label this thread "TWX" i.e a hypothetical future version of TW.

So, I'm thinking that plugins in TWX are somewhat similar in struture then maybe that index can be more actively used as a path to allow for pretty shadow titles. Soemthing like:

{
   
"tiddlers": {
       
"$:/plugin/TWaddle/Foo/": {
           
"title": "Bar"
       
},
...

We would thus use name spaces in a more explicit way by separating the titles. For example, when creating tiddlers that are supposed to become shadow tids, the workflow could be like so: 

To create a plugin, the used creates a tiddler and "marks" it as a plugin (perhaps by selecting a type : plugin). This makes the tiddler use a special tiddler template with plugin specific fields like "version"etc.

To create to-be-shadow-tids, the user creates a new tiddler and in edit mode selects that it belongs to a specific plugin. The user can then use a pretty title because the system can treat the plugin title as a prefix.

In the plugin code, e.g the syntax "./pretty" can be used to refer to fellow shadow tids.

So, the plugin tiddlers actual names are really the long not-pretty titles, so they are not likely in name-conflicts. But the user doesn't have to face these not-pretty titles all the time.

...

Off topic: this gives me an idea for a really nice UI to create plugins: In a tiddler, select type:plugin to get a table (in view mode) to fill with plugin data (version, list, description etc) as well as a [+] button to create tiddlers that are supposed to be shadow tids. Finally at bottom of this tiddler, is a button to "Package plugin", wihch converts everything to a plugin with shadow tids. This is similar to the wonderful Tinka plugin packer but with an even simpler to use UI.


<:-)



PMario

unread,
Sep 17, 2018, 7:00:05 AM9/17/18
to tiddly...@googlegroups.com
Hi,

The following structue is invalid and will result in a RSOD.

{
 
"tiddlers": {
 
"$:/plugin/TWaddle/Foo/": {
 
"title": "Bar"
 
},

 
"$:/plugin/TWaddle/Foo/": {
 
"title": "xxxxxx"

 
},

-m

...

PMario

unread,
Sep 17, 2018, 7:02:13 AM9/17/18
to TiddlyWikiDev
Hi,

The important thing is. plugins are only containers. The tiddlers are expanded into shadow tiddlers and then they are executed. That means even if you use a prefix and "short-name" you still end up with the long name for every tiddler.

-m

Mat

unread,
Sep 17, 2018, 7:12:01 AM9/17/18
to TiddlyWikiDev
PMario wrote:
The following structue is invalid and will result in a RSOD. 


Is that a limitation caused by TW or is it something more fundamental e.g to json? I must assume the former so/but in TWX anything is possible ;-)


<:-)




Mat

unread,
Sep 17, 2018, 7:20:42 AM9/17/18
to TiddlyWikiDev

The important thing is. plugins are only containers. The tiddlers are expanded into shadow tiddlers and then they are executed. That means even if you use a prefix and "short-name" you still end up with the long name for every tiddler. 

Yes, the idea is however that users don't have to face this in the same way:

To create the title, the user (could) select the prefix and he types the pretty name in what appears to be the title field but it could really be a temporary field that, when tiddler is saved, merges the prefix with what he wrote.

And in view mode, any prefix matching a plugin title is hidden. Kind of like the $:/ prefix is manipulated to be gray.


Considering that TW is designed to be hacked, this puts extra demands on UI/UX also for backend stuff. We want it user friendly but $:/This/Is/Scary  ;-)

<:-)


PMario

unread,
Sep 18, 2018, 3:45:47 AM9/18/18
to TiddlyWikiDev
On Monday, September 17, 2018 at 1:20:42 PM UTC+2, Mat wrote:
....
And in view mode, any prefix matching a plugin title is hidden. Kind of like the $:/ prefix is manipulated to be gray.

You know, that I'm not a big fan of "hidden information". For me it seems they always create confusion. Toning down some parts of a title should be OK, but that doesn't solve the problem that we need namespaces.
 
Considering that TW is designed to be hacked, this puts extra demands on UI/UX also for backend stuff. We want it user friendly but $:/This/Is/Scary  ;-)

IMO it's not, if it is explained in a sensible way.

-mario

PMario

unread,
Sep 18, 2018, 4:34:56 AM9/18/18
to TiddlyWikiDev
Examples here are simplified.

It will get techy, but I tried to "go slow" ;)

On Monday, September 17, 2018 at 1:12:01 PM UTC+2, Mat wrote:
...
Is that a limitation caused by TW or is it something more fundamental e.g to json?

JSON means JavaScript Object Notation. .. In js an object is a memory-container. .. The sign for an object is {}

eg: creating a tiddler object looks like this:

var tiddler = {}; // will create an empty object.

To add different elements we can use the "variable dot-notation"

tiddler.title = "New Tiddler"
tiddler.created = ...
tiddler.modified =
tiddler. ...
 
As you can see, it's not possible to use the same name for 2 different memory elements.

eg:

tiddler.title = "test";
tiddler.title = "New Tiddler";

The last one executed would win. That's why object elements need to have unique names!

Since objects are "omnipresent" in JS the browser access routines are highly optimized and accessing an existing element by name should be by far the fastest possible way to access memory.

That's why TW uses this mechanism to manage the internal tiddler store [1], which is named wiki: wiki = {}

The JSON representation looks something like this

"wiki" : {
  "New Tiddler": {
    "fields": {
      "title": "New Tiddler",
      "created": DATE object
      "modified": DATE object
      "tags": [] // array
      // and so on
    }
  },
  "test": {
    "fields": {
      "title": "test",
      "created": DATE object
      "modified": DATE object
      "tags": [] // array
      // and so on
    }
  },
}

So if I would want to access the content of the "test" tiddler, I would write it like this:

var testTiddler = wiki.test;         

// Since spaces are not allowed in JS variable names "New Tiddler" can be accessed like this:

var newTiddler = wiki["New Tiddler"]

// Accessing variables like this is considered performant. 

Performance is the main reason, why tiddler titles have to be unique. They are "container-names".

That fields.title is the same as the container name is a coincidence (It makes it easier for human programmers :). This is an implementation detail. It can _not_ be exploited! Software that "mis-uses" implementation details will fail, since the implementation can and will change over time!

I must assume the former so/but in TWX anything is possible ;-)

The JS object mechanism is probably here to stay :)

have fun!
-mario

[1] You can see the TW store

 - if you open tiddlywiki.com,
 - open the dev-console: F12,
 - select the "console" tab and insert:

$tw.wiki.getTiddler("HelloThere");
[ENTER] // Will open the HelloThere object

$tw.wiki.getTiddlers(); // Will show them all.

If you click the output, it can be expanded ...

PMario

unread,
Sep 18, 2018, 4:47:33 AM9/18/18
to TiddlyWikiDev
For everyone who is interested in JS basics. One of the best written books I know about JS is:


Written by Marijn Haverbeke, which is also the author of codemirror editor.

There are links to the PDF, e-book, ... version in the footer of the page.

If you want to support the author, then consider to buy a printed version, or even better

support the development of the new codemirror version: https://codemirror.net/6/

have fun!

Reply all
Reply to author
Forward
0 new messages